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 a low-level "breakpoint" of some type. BPT is the breakpoint.
745 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
746 PROCESS_WARNING, and HW_BREAKPOINT_ERROR are used to report problems.
748 NOTE drow/2003-09-09: This routine could be broken down to an object-style
749 method for each breakpoint or catchpoint type. */
751 insert_bp_location (struct bp_location *bpt,
752 struct ui_file *tmp_error_stream,
753 int *disabled_breaks, int *process_warning,
754 int *hw_breakpoint_error)
758 /* Permanent breakpoints cannot be inserted or removed. Disabled
759 breakpoints should not be inserted. */
760 if (bpt->owner->enable_state != bp_enabled)
763 if (bpt->inserted || bpt->duplicate)
766 if (bpt->loc_type == bp_loc_software_breakpoint
767 || bpt->loc_type == bp_loc_hardware_breakpoint)
769 /* First check to see if we have to handle an overlay. */
770 if (overlay_debugging == ovly_off
771 || bpt->section == NULL
772 || !(section_is_overlay (bpt->section)))
774 /* No overlay handling: just set the breakpoint. */
776 if (bpt->loc_type == bp_loc_hardware_breakpoint)
777 val = target_insert_hw_breakpoint (bpt->address,
778 bpt->shadow_contents);
780 val = target_insert_breakpoint (bpt->address,
781 bpt->shadow_contents);
785 /* This breakpoint is in an overlay section.
786 Shall we set a breakpoint at the LMA? */
787 if (!overlay_events_enabled)
789 /* Yes -- overlay event support is not active,
790 so we must try to set a breakpoint at the LMA.
791 This will not work for a hardware breakpoint. */
792 if (bpt->loc_type == bp_loc_hardware_breakpoint)
793 warning ("hardware breakpoint %d not supported in overlay!\n",
797 CORE_ADDR addr = overlay_unmapped_address (bpt->address,
799 /* Set a software (trap) breakpoint at the LMA. */
800 val = target_insert_breakpoint (addr, bpt->shadow_contents);
802 fprintf_unfiltered (tmp_error_stream,
803 "Overlay breakpoint %d failed: in ROM?",
807 /* Shall we set a breakpoint at the VMA? */
808 if (section_is_mapped (bpt->section))
810 /* Yes. This overlay section is mapped into memory. */
811 if (bpt->loc_type == bp_loc_hardware_breakpoint)
812 val = target_insert_hw_breakpoint (bpt->address,
813 bpt->shadow_contents);
815 val = target_insert_breakpoint (bpt->address,
816 bpt->shadow_contents);
820 /* No. This breakpoint will not be inserted.
821 No error, but do not mark the bp as 'inserted'. */
828 /* Can't set the breakpoint. */
829 #if defined (DISABLE_UNSETTABLE_BREAK)
830 if (DISABLE_UNSETTABLE_BREAK (bpt->address))
832 /* See also: disable_breakpoints_in_shlibs. */
834 bpt->owner->enable_state = bp_shlib_disabled;
835 if (!*disabled_breaks)
837 fprintf_unfiltered (tmp_error_stream,
838 "Cannot insert breakpoint %d.\n",
840 fprintf_unfiltered (tmp_error_stream,
841 "Temporarily disabling shared library breakpoints:\n");
843 *disabled_breaks = 1;
844 fprintf_unfiltered (tmp_error_stream,
845 "breakpoint #%d\n", bpt->owner->number);
850 #ifdef ONE_PROCESS_WRITETEXT
851 *process_warning = 1;
853 if (bpt->loc_type == bp_loc_hardware_breakpoint)
855 *hw_breakpoint_error = 1;
856 fprintf_unfiltered (tmp_error_stream,
857 "Cannot insert hardware breakpoint %d.\n",
862 fprintf_unfiltered (tmp_error_stream,
863 "Cannot insert breakpoint %d.\n",
865 fprintf_filtered (tmp_error_stream,
866 "Error accessing memory address ");
867 print_address_numeric (bpt->address, 1, tmp_error_stream);
868 fprintf_filtered (tmp_error_stream, ": %s.\n",
869 safe_strerror (val));
880 else if (bpt->loc_type == bp_loc_hardware_watchpoint
881 /* NOTE drow/2003-09-08: This state only exists for removing
882 watchpoints. It's not clear that it's necessary... */
883 && bpt->owner->disposition != disp_del_at_next_stop)
885 /* FIXME drow/2003-09-08: This code sets multiple hardware watchpoints
886 based on the expression. Ideally this should happen at a higher level,
887 and there should be one bp_location for each computed address we
888 must watch. As soon as a many-to-one mapping is available I'll
891 struct frame_info *saved_frame;
892 int saved_level, within_current_scope;
893 struct value *mark = value_mark ();
896 /* Save the current frame and level so we can restore it after
897 evaluating the watchpoint expression on its own frame. */
898 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
899 took a frame parameter, so that we didn't have to change the
901 saved_frame = deprecated_selected_frame;
902 saved_level = frame_relative_level (deprecated_selected_frame);
904 /* Determine if the watchpoint is within scope. */
905 if (bpt->owner->exp_valid_block == NULL)
906 within_current_scope = 1;
909 struct frame_info *fi;
910 fi = frame_find_by_id (bpt->owner->watchpoint_frame);
911 within_current_scope = (fi != NULL);
912 if (within_current_scope)
916 if (within_current_scope)
918 /* Evaluate the expression and cut the chain of values
919 produced off from the value chain.
921 Make sure the value returned isn't lazy; we use
922 laziness to determine what memory GDB actually needed
923 in order to compute the value of the expression. */
924 v = evaluate_expression (bpt->owner->exp);
926 value_release_to_mark (mark);
928 bpt->owner->val_chain = v;
931 /* Look at each value on the value chain. */
932 for (; v; v = v->next)
934 /* If it's a memory location, and GDB actually needed
935 its contents to evaluate the expression, then we
937 if (VALUE_LVAL (v) == lval_memory
940 struct type *vtype = check_typedef (VALUE_TYPE (v));
942 /* We only watch structs and arrays if user asked
943 for it explicitly, never if they just happen to
944 appear in the middle of some value chain. */
945 if (v == bpt->owner->val_chain
946 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
947 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
952 addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
953 len = TYPE_LENGTH (VALUE_TYPE (v));
955 if (bpt->owner->type == bp_read_watchpoint)
957 else if (bpt->owner->type == bp_access_watchpoint)
960 val = target_insert_watchpoint (addr, len, type);
963 /* Don't exit the loop, try to insert
964 every value on the value chain. That's
965 because we will be removing all the
966 watches below, and removing a
967 watchpoint we didn't insert could have
975 /* Failure to insert a watchpoint on any memory value in the
976 value chain brings us here. */
979 remove_breakpoint (bpt->owner, mark_uninserted);
980 *hw_breakpoint_error = 1;
981 fprintf_unfiltered (tmp_error_stream,
982 "Could not insert hardware watchpoint %d.\n",
989 printf_filtered ("Hardware watchpoint %d deleted ", bpt->owner->number);
990 printf_filtered ("because the program has left the block \n");
991 printf_filtered ("in which its expression is valid.\n");
992 if (bpt->owner->related_breakpoint)
993 bpt->owner->related_breakpoint->disposition = disp_del_at_next_stop;
994 bpt->owner->disposition = disp_del_at_next_stop;
997 /* Restore the frame and level. */
998 if (saved_frame != deprecated_selected_frame
999 || saved_level != frame_relative_level (deprecated_selected_frame))
1000 select_frame (saved_frame);
1005 else if (ep_is_exception_catchpoint (bpt->owner))
1007 /* FIXME drow/2003-09-09: This code sets both a catchpoint and a
1008 breakpoint. Once again, it would be better if this was represented
1009 as two bp_locations. */
1011 /* If we get here, we must have a callback mechanism for exception
1012 events -- with g++ style embedded label support, we insert
1013 ordinary breakpoints and not catchpoints. */
1014 val = target_insert_breakpoint (bpt->address, bpt->shadow_contents);
1017 /* Couldn't set breakpoint for some reason */
1018 fprintf_unfiltered (tmp_error_stream,
1019 "Cannot insert catchpoint %d; disabling it.\n",
1020 bpt->owner->number);
1021 fprintf_filtered (tmp_error_stream,
1022 "Error accessing memory address ");
1023 print_address_numeric (bpt->address, 1, tmp_error_stream);
1024 fprintf_filtered (tmp_error_stream, ": %s.\n",
1025 safe_strerror (val));
1026 bpt->owner->enable_state = bp_disabled;
1030 /* Bp set, now make sure callbacks are enabled */
1031 /* Format possible error msg */
1032 char *message = xstrprintf ("Error inserting catchpoint %d:\n",
1033 bpt->owner->number);
1034 struct cleanup *cleanups = make_cleanup (xfree, message);
1036 args_for_catchpoint_enable args;
1037 args.kind = bpt->owner->type == bp_catch_catch ?
1038 EX_EVENT_CATCH : EX_EVENT_THROW;
1040 val = catch_errors (cover_target_enable_exception_callback,
1041 &args, message, RETURN_MASK_ALL);
1042 do_cleanups (cleanups);
1043 if (val != 0 && val != -1)
1046 /* Check if something went wrong; val == 0 can be ignored */
1049 /* something went wrong */
1050 fprintf_unfiltered (tmp_error_stream,
1051 "Cannot insert catchpoint %d; disabling it.\n",
1052 bpt->owner->number);
1053 bpt->owner->enable_state = bp_disabled;
1060 else if (bpt->owner->type == bp_catch_fork
1061 || bpt->owner->type == bp_catch_vfork
1062 || bpt->owner->type == bp_catch_exec)
1064 char *prefix = xstrprintf ("warning: inserting catchpoint %d: ",
1065 bpt->owner->number);
1066 struct cleanup *cleanups = make_cleanup (xfree, prefix);
1067 val = catch_exceptions (uiout, insert_catchpoint, bpt->owner, prefix,
1069 do_cleanups (cleanups);
1071 bpt->owner->enable_state = bp_disabled;
1080 /* insert_breakpoints is used when starting or continuing the program.
1081 remove_breakpoints is used when the program stops.
1082 Both return zero if successful,
1083 or an `errno' value if could not write the inferior. */
1086 insert_breakpoints (void)
1088 struct bp_location *b, *temp;
1089 int return_val = 0; /* return success code. */
1091 int disabled_breaks = 0;
1092 int hw_breakpoint_error = 0;
1093 int process_warning = 0;
1095 struct ui_file *tmp_error_stream = mem_fileopen ();
1096 make_cleanup_ui_file_delete (tmp_error_stream);
1098 /* Explicitly mark the warning -- this will only be printed if
1099 there was an error. */
1100 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
1102 ALL_BP_LOCATIONS_SAFE (b, temp)
1104 /* Permanent breakpoints cannot be inserted or removed. Disabled
1105 breakpoints should not be inserted. */
1106 if (b->owner->enable_state != bp_enabled)
1109 /* FIXME drow/2003-10-07: This code should be pushed elsewhere when
1110 hardware watchpoints are split into multiple loc breakpoints. */
1111 if ((b->loc_type == bp_loc_hardware_watchpoint
1112 || b->owner->type == bp_watchpoint) && !b->owner->val)
1115 val = evaluate_expression (b->owner->exp);
1116 release_value (val);
1117 if (VALUE_LAZY (val))
1118 value_fetch_lazy (val);
1119 b->owner->val = val;
1122 val = insert_bp_location (b, tmp_error_stream,
1123 &disabled_breaks, &process_warning,
1124 &hw_breakpoint_error);
1131 /* If a hardware breakpoint or watchpoint was inserted, add a
1132 message about possibly exhausted resources. */
1133 if (hw_breakpoint_error)
1135 fprintf_unfiltered (tmp_error_stream,
1136 "Could not insert hardware breakpoints:\n\
1137 You may have requested too many hardware breakpoints/watchpoints.\n");
1139 #ifdef ONE_PROCESS_WRITETEXT
1140 if (process_warning)
1141 fprintf_unfiltered (tmp_error_stream,
1142 "The same program may be running in another process.");
1144 target_terminal_ours_for_output ();
1145 error_stream (tmp_error_stream);
1151 remove_breakpoints (void)
1153 struct breakpoint *b;
1158 if (b->loc->inserted)
1160 val = remove_breakpoint (b, mark_uninserted);
1169 remove_hw_watchpoints (void)
1171 struct breakpoint *b;
1176 if (b->loc->inserted
1177 && (b->type == bp_hardware_watchpoint
1178 || b->type == bp_read_watchpoint
1179 || b->type == bp_access_watchpoint))
1181 val = remove_breakpoint (b, mark_uninserted);
1190 reattach_breakpoints (int pid)
1192 struct breakpoint *b;
1194 struct cleanup *old_chain = save_inferior_ptid ();
1196 /* Set inferior_ptid; remove_breakpoint uses this global. */
1197 inferior_ptid = pid_to_ptid (pid);
1200 if (b->loc->inserted)
1202 remove_breakpoint (b, mark_inserted);
1203 if (b->type == bp_hardware_breakpoint)
1204 val = target_insert_hw_breakpoint (b->loc->address, b->loc->shadow_contents);
1206 val = target_insert_breakpoint (b->loc->address, b->loc->shadow_contents);
1209 do_cleanups (old_chain);
1214 do_cleanups (old_chain);
1219 update_breakpoints_after_exec (void)
1221 struct breakpoint *b;
1222 struct breakpoint *temp;
1224 /* Doing this first prevents the badness of having delete_breakpoint()
1225 write a breakpoint's current "shadow contents" to lift the bp. That
1226 shadow is NOT valid after an exec()! */
1227 mark_breakpoints_out ();
1229 ALL_BREAKPOINTS_SAFE (b, temp)
1231 /* Solib breakpoints must be explicitly reset after an exec(). */
1232 if (b->type == bp_shlib_event)
1234 delete_breakpoint (b);
1238 /* Thread event breakpoints must be set anew after an exec(),
1239 as must overlay event breakpoints. */
1240 if (b->type == bp_thread_event || b->type == bp_overlay_event)
1242 delete_breakpoint (b);
1246 /* Step-resume breakpoints are meaningless after an exec(). */
1247 if (b->type == bp_step_resume)
1249 delete_breakpoint (b);
1253 /* Ditto the sigtramp handler breakpoints. */
1254 if (b->type == bp_through_sigtramp)
1256 delete_breakpoint (b);
1260 /* Ditto the exception-handling catchpoints. */
1261 if ((b->type == bp_catch_catch) || (b->type == bp_catch_throw))
1263 delete_breakpoint (b);
1267 /* Don't delete an exec catchpoint, because else the inferior
1268 won't stop when it ought!
1270 Similarly, we probably ought to keep vfork catchpoints, 'cause
1271 on this target, we may not be able to stop when the vfork is
1272 seen, but only when the subsequent exec is seen. (And because
1273 deleting fork catchpoints here but not vfork catchpoints will
1274 seem mysterious to users, keep those too.)
1276 ??rehrauer: Let's hope that merely clearing out this catchpoint's
1277 target address field, if any, is sufficient to have it be reset
1278 automagically. Certainly on HP-UX that's true.
1280 Jim Blandy <jimb@redhat.com>: Actually, zero is a perfectly
1281 valid code address on some platforms (like the mn10300
1282 simulators). We shouldn't assign any special interpretation to
1283 a breakpoint with a zero address. And in fact, GDB doesn't ---
1284 I can't see what that comment above is talking about. As far
1285 as I can tell, setting the address of a
1286 bp_catch_exec/bp_catch_vfork/bp_catch_fork breakpoint to zero
1287 is meaningless, since those are implemented with HP-UX kernel
1288 hackery, not by storing breakpoint instructions somewhere. */
1289 if ((b->type == bp_catch_exec) ||
1290 (b->type == bp_catch_vfork) ||
1291 (b->type == bp_catch_fork))
1293 b->loc->address = (CORE_ADDR) NULL;
1297 /* bp_finish is a special case. The only way we ought to be able
1298 to see one of these when an exec() has happened, is if the user
1299 caught a vfork, and then said "finish". Ordinarily a finish just
1300 carries them to the call-site of the current callee, by setting
1301 a temporary bp there and resuming. But in this case, the finish
1302 will carry them entirely through the vfork & exec.
1304 We don't want to allow a bp_finish to remain inserted now. But
1305 we can't safely delete it, 'cause finish_command has a handle to
1306 the bp on a bpstat, and will later want to delete it. There's a
1307 chance (and I've seen it happen) that if we delete the bp_finish
1308 here, that its storage will get reused by the time finish_command
1309 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1310 We really must allow finish_command to delete a bp_finish.
1312 In the absense of a general solution for the "how do we know
1313 it's safe to delete something others may have handles to?"
1314 problem, what we'll do here is just uninsert the bp_finish, and
1315 let finish_command delete it.
1317 (We know the bp_finish is "doomed" in the sense that it's
1318 momentary, and will be deleted as soon as finish_command sees
1319 the inferior stopped. So it doesn't matter that the bp's
1320 address is probably bogus in the new a.out, unlike e.g., the
1321 solib breakpoints.) */
1323 if (b->type == bp_finish)
1328 /* Without a symbolic address, we have little hope of the
1329 pre-exec() address meaning the same thing in the post-exec()
1331 if (b->addr_string == NULL)
1333 delete_breakpoint (b);
1337 /* If this breakpoint has survived the above battery of checks, then
1338 it must have a symbolic address. Be sure that it gets reevaluated
1339 to a target address, rather than reusing the old evaluation.
1341 Jim Blandy <jimb@redhat.com>: As explained above in the comment
1342 for bp_catch_exec and friends, I'm pretty sure this is entirely
1343 unnecessary. A call to breakpoint_re_set_one always recomputes
1344 the breakpoint's address from scratch, or deletes it if it can't.
1345 So I think this assignment could be deleted without effect. */
1346 b->loc->address = (CORE_ADDR) NULL;
1348 /* FIXME what about longjmp breakpoints? Re-create them here? */
1349 create_overlay_event_breakpoint ("_ovly_debug_event");
1353 detach_breakpoints (int pid)
1355 struct breakpoint *b;
1357 struct cleanup *old_chain = save_inferior_ptid ();
1359 if (pid == PIDGET (inferior_ptid))
1360 error ("Cannot detach breakpoints of inferior_ptid");
1362 /* Set inferior_ptid; remove_breakpoint uses this global. */
1363 inferior_ptid = pid_to_ptid (pid);
1366 if (b->loc->inserted)
1368 val = remove_breakpoint (b, mark_inserted);
1371 do_cleanups (old_chain);
1376 do_cleanups (old_chain);
1381 remove_breakpoint (struct breakpoint *b, insertion_state_t is)
1385 if (b->enable_state == bp_permanent)
1386 /* Permanent breakpoints cannot be inserted or removed. */
1389 if (b->type == bp_none)
1390 warning ("attempted to remove apparently deleted breakpoint #%d?",
1393 if (b->type != bp_watchpoint
1394 && b->type != bp_hardware_watchpoint
1395 && b->type != bp_read_watchpoint
1396 && b->type != bp_access_watchpoint
1397 && b->type != bp_catch_fork
1398 && b->type != bp_catch_vfork
1399 && b->type != bp_catch_exec
1400 && b->type != bp_catch_catch
1401 && b->type != bp_catch_throw)
1403 /* "Normal" instruction breakpoint: either the standard
1404 trap-instruction bp (bp_breakpoint), or a
1405 bp_hardware_breakpoint. */
1407 /* First check to see if we have to handle an overlay. */
1408 if (overlay_debugging == ovly_off
1409 || b->loc->section == NULL
1410 || !(section_is_overlay (b->loc->section)))
1412 /* No overlay handling: just remove the breakpoint. */
1414 if (b->type == bp_hardware_breakpoint)
1415 val = target_remove_hw_breakpoint (b->loc->address,
1416 b->loc->shadow_contents);
1418 val = target_remove_breakpoint (b->loc->address, b->loc->shadow_contents);
1422 /* This breakpoint is in an overlay section.
1423 Did we set a breakpoint at the LMA? */
1424 if (!overlay_events_enabled)
1426 /* Yes -- overlay event support is not active, so we
1427 should have set a breakpoint at the LMA. Remove it.
1429 CORE_ADDR addr = overlay_unmapped_address (b->loc->address,
1431 /* Ignore any failures: if the LMA is in ROM, we will
1432 have already warned when we failed to insert it. */
1433 if (b->type != bp_hardware_breakpoint)
1434 target_remove_hw_breakpoint (addr, b->loc->shadow_contents);
1436 target_remove_breakpoint (addr, b->loc->shadow_contents);
1438 /* Did we set a breakpoint at the VMA?
1439 If so, we will have marked the breakpoint 'inserted'. */
1440 if (b->loc->inserted)
1442 /* Yes -- remove it. Previously we did not bother to
1443 remove the breakpoint if the section had been
1444 unmapped, but let's not rely on that being safe. We
1445 don't know what the overlay manager might do. */
1446 if (b->type == bp_hardware_breakpoint)
1447 val = target_remove_hw_breakpoint (b->loc->address,
1448 b->loc->shadow_contents);
1450 val = target_remove_breakpoint (b->loc->address,
1451 b->loc->shadow_contents);
1455 /* No -- not inserted, so no need to remove. No error. */
1461 b->loc->inserted = (is == mark_inserted);
1463 else if ((b->type == bp_hardware_watchpoint ||
1464 b->type == bp_read_watchpoint ||
1465 b->type == bp_access_watchpoint)
1466 && b->enable_state == bp_enabled
1467 && !b->loc->duplicate)
1472 b->loc->inserted = (is == mark_inserted);
1473 /* Walk down the saved value chain. */
1474 for (v = b->val_chain; v; v = v->next)
1476 /* For each memory reference remove the watchpoint
1478 if (VALUE_LVAL (v) == lval_memory
1479 && ! VALUE_LAZY (v))
1481 struct type *vtype = check_typedef (VALUE_TYPE (v));
1483 if (v == b->val_chain
1484 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1485 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1490 addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
1491 len = TYPE_LENGTH (VALUE_TYPE (v));
1493 if (b->type == bp_read_watchpoint)
1495 else if (b->type == bp_access_watchpoint)
1498 val = target_remove_watchpoint (addr, len, type);
1500 b->loc->inserted = 1;
1505 /* Failure to remove any of the hardware watchpoints comes here. */
1506 if ((is == mark_uninserted) && (b->loc->inserted))
1507 warning ("Could not remove hardware watchpoint %d.",
1510 /* Free the saved value chain. We will construct a new one
1511 the next time the watchpoint is inserted. */
1512 for (v = b->val_chain; v; v = n)
1517 b->val_chain = NULL;
1519 else if ((b->type == bp_catch_fork ||
1520 b->type == bp_catch_vfork ||
1521 b->type == bp_catch_exec)
1522 && b->enable_state == bp_enabled
1523 && !b->loc->duplicate)
1529 val = target_remove_fork_catchpoint (PIDGET (inferior_ptid));
1531 case bp_catch_vfork:
1532 val = target_remove_vfork_catchpoint (PIDGET (inferior_ptid));
1535 val = target_remove_exec_catchpoint (PIDGET (inferior_ptid));
1538 warning ("Internal error, %s line %d.", __FILE__, __LINE__);
1543 b->loc->inserted = (is == mark_inserted);
1545 else if ((b->type == bp_catch_catch ||
1546 b->type == bp_catch_throw)
1547 && b->enable_state == bp_enabled
1548 && !b->loc->duplicate)
1551 val = target_remove_breakpoint (b->loc->address, b->loc->shadow_contents);
1554 b->loc->inserted = (is == mark_inserted);
1556 else if (ep_is_exception_catchpoint (b)
1557 && b->loc->inserted /* sometimes previous insert doesn't happen */
1558 && b->enable_state == bp_enabled
1559 && !b->loc->duplicate)
1562 val = target_remove_breakpoint (b->loc->address, b->loc->shadow_contents);
1566 b->loc->inserted = (is == mark_inserted);
1572 /* Clear the "inserted" flag in all breakpoints. */
1575 mark_breakpoints_out (void)
1577 struct breakpoint *b;
1580 b->loc->inserted = 0;
1583 /* Clear the "inserted" flag in all breakpoints and delete any
1584 breakpoints which should go away between runs of the program.
1586 Plus other such housekeeping that has to be done for breakpoints
1589 Note: this function gets called at the end of a run (by
1590 generic_mourn_inferior) and when a run begins (by
1591 init_wait_for_inferior). */
1596 breakpoint_init_inferior (enum inf_context context)
1598 struct breakpoint *b, *temp;
1599 static int warning_needed = 0;
1601 ALL_BREAKPOINTS_SAFE (b, temp)
1603 b->loc->inserted = 0;
1608 case bp_watchpoint_scope:
1610 /* If the call dummy breakpoint is at the entry point it will
1611 cause problems when the inferior is rerun, so we better
1614 Also get rid of scope breakpoints. */
1615 delete_breakpoint (b);
1619 case bp_hardware_watchpoint:
1620 case bp_read_watchpoint:
1621 case bp_access_watchpoint:
1623 /* Likewise for watchpoints on local expressions. */
1624 if (b->exp_valid_block != NULL)
1625 delete_breakpoint (b);
1626 if (context == inf_starting)
1628 /* Reset val field to force reread of starting value
1629 in insert_breakpoints. */
1631 value_free (b->val);
1636 /* Likewise for exception catchpoints in dynamic-linked
1637 executables where required */
1638 if (ep_is_exception_catchpoint (b) &&
1639 exception_catchpoints_are_fragile)
1642 delete_breakpoint (b);
1648 if (exception_catchpoints_are_fragile)
1649 exception_support_initialized = 0;
1651 /* Don't issue the warning unless it's really needed... */
1652 if (warning_needed && (context != inf_exited))
1654 warning ("Exception catchpoints from last run were deleted.");
1655 warning ("You must reinsert them explicitly.");
1660 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1661 exists at PC. It returns ordinary_breakpoint_here if it's an
1662 ordinary breakpoint, or permanent_breakpoint_here if it's a
1663 permanent breakpoint.
1664 - When continuing from a location with an ordinary breakpoint, we
1665 actually single step once before calling insert_breakpoints.
1666 - When continuing from a localion with a permanent breakpoint, we
1667 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1668 the target, to advance the PC past the breakpoint. */
1670 enum breakpoint_here
1671 breakpoint_here_p (CORE_ADDR pc)
1673 struct breakpoint *b;
1674 int any_breakpoint_here = 0;
1677 if ((b->enable_state == bp_enabled
1678 || b->enable_state == bp_permanent)
1679 && b->loc->address == pc) /* bp is enabled and matches pc */
1681 if (overlay_debugging
1682 && section_is_overlay (b->loc->section)
1683 && !section_is_mapped (b->loc->section))
1684 continue; /* unmapped overlay -- can't be a match */
1685 else if (b->enable_state == bp_permanent)
1686 return permanent_breakpoint_here;
1688 any_breakpoint_here = 1;
1691 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
1695 /* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(),
1696 but it only returns true if there is actually a breakpoint inserted
1700 breakpoint_inserted_here_p (CORE_ADDR pc)
1702 struct breakpoint *b;
1705 if (b->loc->inserted
1706 && b->loc->address == pc) /* bp is inserted and matches pc */
1708 if (overlay_debugging
1709 && section_is_overlay (b->loc->section)
1710 && !section_is_mapped (b->loc->section))
1711 continue; /* unmapped overlay -- can't be a match */
1719 /* Return nonzero if FRAME is a dummy frame. We can't use
1720 DEPRECATED_PC_IN_CALL_DUMMY because figuring out the saved SP would
1721 take too much time, at least using frame_register() on the 68k.
1722 This means that for this function to work right a port must use the
1723 bp_call_dummy breakpoint. */
1726 deprecated_frame_in_dummy (struct frame_info *frame)
1728 struct breakpoint *b;
1730 /* This function is used by two files: get_frame_type(), after first
1731 checking that !DEPRECATED_USE_GENERIC_DUMMY_FRAMES; and
1732 sparc-tdep.c, which doesn't yet use generic dummy frames anyway. */
1733 gdb_assert (!DEPRECATED_USE_GENERIC_DUMMY_FRAMES);
1737 if (b->type == bp_call_dummy
1738 && frame_id_eq (b->frame_id, get_frame_id (frame))
1739 /* We need to check the PC as well as the frame on the sparc,
1740 for signals.exp in the testsuite. */
1741 && (get_frame_pc (frame)
1743 - DEPRECATED_SIZEOF_CALL_DUMMY_WORDS / sizeof (LONGEST) * DEPRECATED_REGISTER_SIZE))
1744 && get_frame_pc (frame) <= b->loc->address)
1750 /* breakpoint_thread_match (PC, PID) returns true if the breakpoint at
1751 PC is valid for process/thread PID. */
1754 breakpoint_thread_match (CORE_ADDR pc, ptid_t ptid)
1756 struct breakpoint *b;
1759 thread = pid_to_thread_id (ptid);
1762 if (b->enable_state != bp_disabled
1763 && b->enable_state != bp_shlib_disabled
1764 && b->enable_state != bp_call_disabled
1765 && b->loc->address == pc
1766 && (b->thread == -1 || b->thread == thread))
1768 if (overlay_debugging
1769 && section_is_overlay (b->loc->section)
1770 && !section_is_mapped (b->loc->section))
1771 continue; /* unmapped overlay -- can't be a match */
1780 /* bpstat stuff. External routines' interfaces are documented
1784 ep_is_catchpoint (struct breakpoint *ep)
1787 (ep->type == bp_catch_load)
1788 || (ep->type == bp_catch_unload)
1789 || (ep->type == bp_catch_fork)
1790 || (ep->type == bp_catch_vfork)
1791 || (ep->type == bp_catch_exec)
1792 || (ep->type == bp_catch_catch)
1793 || (ep->type == bp_catch_throw);
1795 /* ??rehrauer: Add more kinds here, as are implemented... */
1799 ep_is_shlib_catchpoint (struct breakpoint *ep)
1802 (ep->type == bp_catch_load)
1803 || (ep->type == bp_catch_unload);
1807 ep_is_exception_catchpoint (struct breakpoint *ep)
1810 (ep->type == bp_catch_catch)
1811 || (ep->type == bp_catch_throw);
1814 /* Clear a bpstat so that it says we are not at any breakpoint.
1815 Also free any storage that is part of a bpstat. */
1818 bpstat_clear (bpstat *bsp)
1829 if (p->old_val != NULL)
1830 value_free (p->old_val);
1831 free_command_lines (&p->commands);
1838 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1839 is part of the bpstat is copied as well. */
1842 bpstat_copy (bpstat bs)
1846 bpstat retval = NULL;
1851 for (; bs != NULL; bs = bs->next)
1853 tmp = (bpstat) xmalloc (sizeof (*tmp));
1854 memcpy (tmp, bs, sizeof (*tmp));
1855 if (bs->commands != NULL)
1856 tmp->commands = copy_command_lines (bs->commands);
1857 if (bs->old_val != NULL)
1858 tmp->old_val = value_copy (bs->old_val);
1861 /* This is the first thing in the chain. */
1871 /* Find the bpstat associated with this breakpoint */
1874 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
1879 for (; bsp != NULL; bsp = bsp->next)
1881 if (bsp->breakpoint_at == breakpoint)
1887 /* Find a step_resume breakpoint associated with this bpstat.
1888 (If there are multiple step_resume bp's on the list, this function
1889 will arbitrarily pick one.)
1891 It is an error to use this function if BPSTAT doesn't contain a
1892 step_resume breakpoint.
1894 See wait_for_inferior's use of this function. */
1896 bpstat_find_step_resume_breakpoint (bpstat bsp)
1901 error ("Internal error (bpstat_find_step_resume_breakpoint)");
1903 current_thread = pid_to_thread_id (inferior_ptid);
1905 for (; bsp != NULL; bsp = bsp->next)
1907 if ((bsp->breakpoint_at != NULL) &&
1908 (bsp->breakpoint_at->type == bp_step_resume) &&
1909 (bsp->breakpoint_at->thread == current_thread ||
1910 bsp->breakpoint_at->thread == -1))
1911 return bsp->breakpoint_at;
1914 error ("Internal error (no step_resume breakpoint found)");
1918 /* Return the breakpoint number of the first breakpoint we are stopped
1919 at. *BSP upon return is a bpstat which points to the remaining
1920 breakpoints stopped at (but which is not guaranteed to be good for
1921 anything but further calls to bpstat_num).
1922 Return 0 if passed a bpstat which does not indicate any breakpoints. */
1925 bpstat_num (bpstat *bsp)
1927 struct breakpoint *b;
1930 return 0; /* No more breakpoint values */
1933 b = (*bsp)->breakpoint_at;
1934 *bsp = (*bsp)->next;
1936 return -1; /* breakpoint that's been deleted since */
1938 return b->number; /* We have its number */
1942 /* Modify BS so that the actions will not be performed. */
1945 bpstat_clear_actions (bpstat bs)
1947 for (; bs != NULL; bs = bs->next)
1949 free_command_lines (&bs->commands);
1950 if (bs->old_val != NULL)
1952 value_free (bs->old_val);
1958 /* Stub for cleaning up our state if we error-out of a breakpoint command */
1960 cleanup_executing_breakpoints (void *ignore)
1962 executing_breakpoint_commands = 0;
1965 /* Execute all the commands associated with all the breakpoints at this
1966 location. Any of these commands could cause the process to proceed
1967 beyond this point, etc. We look out for such changes by checking
1968 the global "breakpoint_proceeded" after each command. */
1971 bpstat_do_actions (bpstat *bsp)
1974 struct cleanup *old_chain;
1975 struct command_line *cmd;
1977 /* Avoid endless recursion if a `source' command is contained
1979 if (executing_breakpoint_commands)
1982 executing_breakpoint_commands = 1;
1983 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
1986 /* Note that (as of this writing), our callers all appear to
1987 be passing us the address of global stop_bpstat. And, if
1988 our calls to execute_control_command cause the inferior to
1989 proceed, that global (and hence, *bsp) will change.
1991 We must be careful to not touch *bsp unless the inferior
1992 has not proceeded. */
1994 /* This pointer will iterate over the list of bpstat's. */
1997 breakpoint_proceeded = 0;
1998 for (; bs != NULL; bs = bs->next)
2003 execute_control_command (cmd);
2005 if (breakpoint_proceeded)
2010 if (breakpoint_proceeded)
2011 /* The inferior is proceeded by the command; bomb out now.
2012 The bpstat chain has been blown away by wait_for_inferior.
2013 But since execution has stopped again, there is a new bpstat
2014 to look at, so start over. */
2017 free_command_lines (&bs->commands);
2019 do_cleanups (old_chain);
2022 /* This is the normal print function for a bpstat. In the future,
2023 much of this logic could (should?) be moved to bpstat_stop_status,
2024 by having it set different print_it values.
2026 Current scheme: When we stop, bpstat_print() is called. It loops
2027 through the bpstat list of things causing this stop, calling the
2028 print_bp_stop_message function on each one. The behavior of the
2029 print_bp_stop_message function depends on the print_it field of
2030 bpstat. If such field so indicates, call this function here.
2032 Return values from this routine (ultimately used by bpstat_print()
2033 and normal_stop() to decide what to do):
2034 PRINT_NOTHING: Means we already printed all we needed to print,
2035 don't print anything else.
2036 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2037 that something to be followed by a location.
2038 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2039 that something to be followed by a location.
2040 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2043 static enum print_stop_action
2044 print_it_typical (bpstat bs)
2046 struct cleanup *old_chain, *ui_out_chain;
2047 struct ui_stream *stb;
2048 stb = ui_out_stream_new (uiout);
2049 old_chain = make_cleanup_ui_out_stream_delete (stb);
2050 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2051 which has since been deleted. */
2052 if (bs->breakpoint_at == NULL)
2053 return PRINT_UNKNOWN;
2055 switch (bs->breakpoint_at->type)
2058 case bp_hardware_breakpoint:
2059 if (bs->breakpoint_at->loc->address != bs->breakpoint_at->loc->requested_address)
2060 breakpoint_adjustment_warning (bs->breakpoint_at->loc->requested_address,
2061 bs->breakpoint_at->loc->address,
2062 bs->breakpoint_at->number, 1);
2063 annotate_breakpoint (bs->breakpoint_at->number);
2064 ui_out_text (uiout, "\nBreakpoint ");
2065 if (ui_out_is_mi_like_p (uiout))
2066 ui_out_field_string (uiout, "reason", "breakpoint-hit");
2067 ui_out_field_int (uiout, "bkptno", bs->breakpoint_at->number);
2068 ui_out_text (uiout, ", ");
2069 return PRINT_SRC_AND_LOC;
2072 case bp_shlib_event:
2073 /* Did we stop because the user set the stop_on_solib_events
2074 variable? (If so, we report this as a generic, "Stopped due
2075 to shlib event" message.) */
2076 printf_filtered ("Stopped due to shared library event\n");
2077 return PRINT_NOTHING;
2080 case bp_thread_event:
2081 /* Not sure how we will get here.
2082 GDB should not stop for these breakpoints. */
2083 printf_filtered ("Thread Event Breakpoint: gdb should not stop!\n");
2084 return PRINT_NOTHING;
2087 case bp_overlay_event:
2088 /* By analogy with the thread event, GDB should not stop for these. */
2089 printf_filtered ("Overlay Event Breakpoint: gdb should not stop!\n");
2090 return PRINT_NOTHING;
2094 annotate_catchpoint (bs->breakpoint_at->number);
2095 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
2096 printf_filtered ("loaded");
2097 printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname);
2098 return PRINT_SRC_AND_LOC;
2101 case bp_catch_unload:
2102 annotate_catchpoint (bs->breakpoint_at->number);
2103 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
2104 printf_filtered ("unloaded");
2105 printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname);
2106 return PRINT_SRC_AND_LOC;
2110 annotate_catchpoint (bs->breakpoint_at->number);
2111 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
2112 printf_filtered ("forked");
2113 printf_filtered (" process %d), ",
2114 bs->breakpoint_at->forked_inferior_pid);
2115 return PRINT_SRC_AND_LOC;
2118 case bp_catch_vfork:
2119 annotate_catchpoint (bs->breakpoint_at->number);
2120 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
2121 printf_filtered ("vforked");
2122 printf_filtered (" process %d), ",
2123 bs->breakpoint_at->forked_inferior_pid);
2124 return PRINT_SRC_AND_LOC;
2128 annotate_catchpoint (bs->breakpoint_at->number);
2129 printf_filtered ("\nCatchpoint %d (exec'd %s), ",
2130 bs->breakpoint_at->number,
2131 bs->breakpoint_at->exec_pathname);
2132 return PRINT_SRC_AND_LOC;
2135 case bp_catch_catch:
2136 if (current_exception_event &&
2137 (CURRENT_EXCEPTION_KIND == EX_EVENT_CATCH))
2139 annotate_catchpoint (bs->breakpoint_at->number);
2140 printf_filtered ("\nCatchpoint %d (exception caught), ",
2141 bs->breakpoint_at->number);
2142 printf_filtered ("throw location ");
2143 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
2144 printf_filtered ("%s:%d",
2145 CURRENT_EXCEPTION_THROW_FILE,
2146 CURRENT_EXCEPTION_THROW_LINE);
2148 printf_filtered ("unknown");
2150 printf_filtered (", catch location ");
2151 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
2152 printf_filtered ("%s:%d",
2153 CURRENT_EXCEPTION_CATCH_FILE,
2154 CURRENT_EXCEPTION_CATCH_LINE);
2156 printf_filtered ("unknown");
2158 printf_filtered ("\n");
2159 /* don't bother to print location frame info */
2160 return PRINT_SRC_ONLY;
2164 /* really throw, some other bpstat will handle it */
2165 return PRINT_UNKNOWN;
2169 case bp_catch_throw:
2170 if (current_exception_event &&
2171 (CURRENT_EXCEPTION_KIND == EX_EVENT_THROW))
2173 annotate_catchpoint (bs->breakpoint_at->number);
2174 printf_filtered ("\nCatchpoint %d (exception thrown), ",
2175 bs->breakpoint_at->number);
2176 printf_filtered ("throw location ");
2177 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
2178 printf_filtered ("%s:%d",
2179 CURRENT_EXCEPTION_THROW_FILE,
2180 CURRENT_EXCEPTION_THROW_LINE);
2182 printf_filtered ("unknown");
2184 printf_filtered (", catch location ");
2185 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
2186 printf_filtered ("%s:%d",
2187 CURRENT_EXCEPTION_CATCH_FILE,
2188 CURRENT_EXCEPTION_CATCH_LINE);
2190 printf_filtered ("unknown");
2192 printf_filtered ("\n");
2193 /* don't bother to print location frame info */
2194 return PRINT_SRC_ONLY;
2198 /* really catch, some other bpstat will handle it */
2199 return PRINT_UNKNOWN;
2204 case bp_hardware_watchpoint:
2205 if (bs->old_val != NULL)
2207 annotate_watchpoint (bs->breakpoint_at->number);
2208 if (ui_out_is_mi_like_p (uiout))
2209 ui_out_field_string (uiout, "reason", "watchpoint-trigger");
2210 mention (bs->breakpoint_at);
2211 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2212 ui_out_text (uiout, "\nOld value = ");
2213 value_print (bs->old_val, stb->stream, 0, Val_pretty_default);
2214 ui_out_field_stream (uiout, "old", stb);
2215 ui_out_text (uiout, "\nNew value = ");
2216 value_print (bs->breakpoint_at->val, stb->stream, 0, Val_pretty_default);
2217 ui_out_field_stream (uiout, "new", stb);
2218 do_cleanups (ui_out_chain);
2219 ui_out_text (uiout, "\n");
2220 value_free (bs->old_val);
2223 /* More than one watchpoint may have been triggered. */
2224 return PRINT_UNKNOWN;
2227 case bp_read_watchpoint:
2228 if (ui_out_is_mi_like_p (uiout))
2229 ui_out_field_string (uiout, "reason", "read-watchpoint-trigger");
2230 mention (bs->breakpoint_at);
2231 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2232 ui_out_text (uiout, "\nValue = ");
2233 value_print (bs->breakpoint_at->val, stb->stream, 0, Val_pretty_default);
2234 ui_out_field_stream (uiout, "value", stb);
2235 do_cleanups (ui_out_chain);
2236 ui_out_text (uiout, "\n");
2237 return PRINT_UNKNOWN;
2240 case bp_access_watchpoint:
2241 if (bs->old_val != NULL)
2243 annotate_watchpoint (bs->breakpoint_at->number);
2244 if (ui_out_is_mi_like_p (uiout))
2245 ui_out_field_string (uiout, "reason", "access-watchpoint-trigger");
2246 mention (bs->breakpoint_at);
2247 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2248 ui_out_text (uiout, "\nOld value = ");
2249 value_print (bs->old_val, stb->stream, 0, Val_pretty_default);
2250 ui_out_field_stream (uiout, "old", stb);
2251 value_free (bs->old_val);
2253 ui_out_text (uiout, "\nNew value = ");
2257 mention (bs->breakpoint_at);
2258 if (ui_out_is_mi_like_p (uiout))
2259 ui_out_field_string (uiout, "reason", "access-watchpoint-trigger");
2260 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2261 ui_out_text (uiout, "\nValue = ");
2263 value_print (bs->breakpoint_at->val, stb->stream, 0,Val_pretty_default);
2264 ui_out_field_stream (uiout, "new", stb);
2265 do_cleanups (ui_out_chain);
2266 ui_out_text (uiout, "\n");
2267 return PRINT_UNKNOWN;
2270 /* Fall through, we don't deal with these types of breakpoints
2274 if (ui_out_is_mi_like_p (uiout))
2275 ui_out_field_string (uiout, "reason", "function-finished");
2276 return PRINT_UNKNOWN;
2280 if (ui_out_is_mi_like_p (uiout))
2281 ui_out_field_string (uiout, "reason", "location-reached");
2282 return PRINT_UNKNOWN;
2287 case bp_longjmp_resume:
2288 case bp_step_resume:
2289 case bp_through_sigtramp:
2290 case bp_watchpoint_scope:
2293 return PRINT_UNKNOWN;
2297 /* Generic routine for printing messages indicating why we
2298 stopped. The behavior of this function depends on the value
2299 'print_it' in the bpstat structure. Under some circumstances we
2300 may decide not to print anything here and delegate the task to
2303 static enum print_stop_action
2304 print_bp_stop_message (bpstat bs)
2306 switch (bs->print_it)
2309 /* Nothing should be printed for this bpstat entry. */
2310 return PRINT_UNKNOWN;
2314 /* We still want to print the frame, but we already printed the
2315 relevant messages. */
2316 return PRINT_SRC_AND_LOC;
2319 case print_it_normal:
2320 /* Normal case. Call the breakpoint's print_it method, or
2321 print_it_typical. */
2322 if (bs->breakpoint_at != NULL && bs->breakpoint_at->ops != NULL
2323 && bs->breakpoint_at->ops->print_it != NULL)
2324 return bs->breakpoint_at->ops->print_it (bs->breakpoint_at);
2326 return print_it_typical (bs);
2330 internal_error (__FILE__, __LINE__,
2331 "print_bp_stop_message: unrecognized enum value");
2336 /* Print a message indicating what happened. This is called from
2337 normal_stop(). The input to this routine is the head of the bpstat
2338 list - a list of the eventpoints that caused this stop. This
2339 routine calls the generic print routine for printing a message
2340 about reasons for stopping. This will print (for example) the
2341 "Breakpoint n," part of the output. The return value of this
2344 PRINT_UNKNOWN: Means we printed nothing
2345 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2346 code to print the location. An example is
2347 "Breakpoint 1, " which should be followed by
2349 PRINT_SRC_ONLY: Means we printed something, but there is no need
2350 to also print the location part of the message.
2351 An example is the catch/throw messages, which
2352 don't require a location appended to the end.
2353 PRINT_NOTHING: We have done some printing and we don't need any
2354 further info to be printed.*/
2356 enum print_stop_action
2357 bpstat_print (bpstat bs)
2361 /* Maybe another breakpoint in the chain caused us to stop.
2362 (Currently all watchpoints go on the bpstat whether hit or not.
2363 That probably could (should) be changed, provided care is taken
2364 with respect to bpstat_explains_signal). */
2365 for (; bs; bs = bs->next)
2367 val = print_bp_stop_message (bs);
2368 if (val == PRINT_SRC_ONLY
2369 || val == PRINT_SRC_AND_LOC
2370 || val == PRINT_NOTHING)
2374 /* We reached the end of the chain, or we got a null BS to start
2375 with and nothing was printed. */
2376 return PRINT_UNKNOWN;
2379 /* Evaluate the expression EXP and return 1 if value is zero.
2380 This is used inside a catch_errors to evaluate the breakpoint condition.
2381 The argument is a "struct expression *" that has been cast to char * to
2382 make it pass through catch_errors. */
2385 breakpoint_cond_eval (void *exp)
2387 struct value *mark = value_mark ();
2388 int i = !value_true (evaluate_expression ((struct expression *) exp));
2389 value_free_to_mark (mark);
2393 /* Allocate a new bpstat and chain it to the current one. */
2396 bpstat_alloc (struct breakpoint *b, bpstat cbs /* Current "bs" value */ )
2400 bs = (bpstat) xmalloc (sizeof (*bs));
2402 bs->breakpoint_at = b;
2403 /* If the condition is false, etc., don't do the commands. */
2404 bs->commands = NULL;
2406 bs->print_it = print_it_normal;
2410 /* Possible return values for watchpoint_check (this can't be an enum
2411 because of check_errors). */
2412 /* The watchpoint has been deleted. */
2413 #define WP_DELETED 1
2414 /* The value has changed. */
2415 #define WP_VALUE_CHANGED 2
2416 /* The value has not changed. */
2417 #define WP_VALUE_NOT_CHANGED 3
2419 #define BP_TEMPFLAG 1
2420 #define BP_HARDWAREFLAG 2
2422 /* Check watchpoint condition. */
2425 watchpoint_check (void *p)
2427 bpstat bs = (bpstat) p;
2428 struct breakpoint *b;
2429 struct frame_info *fr;
2430 int within_current_scope;
2432 struct frame_id current_frame_id;
2435 b = bs->breakpoint_at;
2437 if (b->exp_valid_block == NULL)
2438 within_current_scope = 1;
2441 /* There is no current frame at this moment. If we're going to have
2442 any chance of handling watchpoints on local variables, we'll need
2443 the frame chain (so we can determine if we're in scope). */
2444 reinit_frame_cache ();
2445 fr = frame_find_by_id (b->watchpoint_frame);
2446 within_current_scope = (fr != NULL);
2447 /* in_function_epilogue_p() returns a non-zero value if we're still
2448 in the function but the stack frame has already been invalidated.
2449 Since we can't rely on the values of local variables after the
2450 stack has been destroyed, we are treating the watchpoint in that
2451 state as `not changed' without further checking.
2453 vinschen/2003-09-04: The former implementation left out the case
2454 that the watchpoint frame couldn't be found by frame_find_by_id()
2455 because the current PC is currently in an epilogue. Calling
2456 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2457 if ((!within_current_scope || fr == get_current_frame ())
2458 && gdbarch_in_function_epilogue_p (current_gdbarch, read_pc ()))
2459 return WP_VALUE_NOT_CHANGED;
2460 if (fr && within_current_scope)
2461 /* If we end up stopping, the current frame will get selected
2462 in normal_stop. So this call to select_frame won't affect
2467 if (within_current_scope)
2469 /* We use value_{,free_to_}mark because it could be a
2470 *long* time before we return to the command level and
2471 call free_all_values. We can't call free_all_values because
2472 we might be in the middle of evaluating a function call. */
2474 struct value *mark = value_mark ();
2475 struct value *new_val = evaluate_expression (bs->breakpoint_at->exp);
2476 if (!value_equal (b->val, new_val))
2478 release_value (new_val);
2479 value_free_to_mark (mark);
2480 bs->old_val = b->val;
2482 /* We will stop here */
2483 return WP_VALUE_CHANGED;
2487 /* Nothing changed, don't do anything. */
2488 value_free_to_mark (mark);
2489 /* We won't stop here */
2490 return WP_VALUE_NOT_CHANGED;
2495 /* This seems like the only logical thing to do because
2496 if we temporarily ignored the watchpoint, then when
2497 we reenter the block in which it is valid it contains
2498 garbage (in the case of a function, it may have two
2499 garbage values, one before and one after the prologue).
2500 So we can't even detect the first assignment to it and
2501 watch after that (since the garbage may or may not equal
2502 the first value assigned). */
2503 /* We print all the stop information in print_it_typical(), but
2504 in this case, by the time we call print_it_typical() this bp
2505 will be deleted already. So we have no choice but print the
2506 information here. */
2507 if (ui_out_is_mi_like_p (uiout))
2508 ui_out_field_string (uiout, "reason", "watchpoint-scope");
2509 ui_out_text (uiout, "\nWatchpoint ");
2510 ui_out_field_int (uiout, "wpnum", bs->breakpoint_at->number);
2511 ui_out_text (uiout, " deleted because the program has left the block in\n\
2512 which its expression is valid.\n");
2514 if (b->related_breakpoint)
2515 b->related_breakpoint->disposition = disp_del_at_next_stop;
2516 b->disposition = disp_del_at_next_stop;
2522 /* Get a bpstat associated with having just stopped at address *PC
2523 and frame address CORE_ADDRESS. Update *PC to point at the
2524 breakpoint (if we hit a breakpoint). NOT_A_SW_BREAKPOINT is nonzero
2525 if this is known to not be a real breakpoint (it could still be a
2526 watchpoint, though). */
2528 /* Determine whether we stopped at a breakpoint, etc, or whether we
2529 don't understand this stop. Result is a chain of bpstat's such that:
2531 if we don't understand the stop, the result is a null pointer.
2533 if we understand why we stopped, the result is not null.
2535 Each element of the chain refers to a particular breakpoint or
2536 watchpoint at which we have stopped. (We may have stopped for
2537 several reasons concurrently.)
2539 Each element of the chain has valid next, breakpoint_at,
2540 commands, FIXME??? fields. */
2543 bpstat_stop_status (CORE_ADDR *pc, int not_a_sw_breakpoint)
2545 struct breakpoint *b, *temp;
2547 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2548 int real_breakpoint = 0;
2549 /* Root of the chain of bpstat's */
2550 struct bpstats root_bs[1];
2551 /* Pointer to the last thing in the chain currently. */
2552 bpstat bs = root_bs;
2554 /* Get the address where the breakpoint would have been. The
2555 "not_a_sw_breakpoint" argument is meant to distinguish between a
2556 breakpoint trap event and a trace/singlestep trap event. For a
2557 trace/singlestep trap event, we would not want to subtract
2558 DECR_PC_AFTER_BREAK from the PC. */
2560 bp_addr = *pc - (not_a_sw_breakpoint ? 0 : DECR_PC_AFTER_BREAK);
2562 ALL_BREAKPOINTS_SAFE (b, temp)
2564 if (b->enable_state == bp_disabled
2565 || b->enable_state == bp_shlib_disabled
2566 || b->enable_state == bp_call_disabled)
2569 if (b->type != bp_watchpoint
2570 && b->type != bp_hardware_watchpoint
2571 && b->type != bp_read_watchpoint
2572 && b->type != bp_access_watchpoint
2573 && b->type != bp_hardware_breakpoint
2574 && b->type != bp_catch_fork
2575 && b->type != bp_catch_vfork
2576 && b->type != bp_catch_exec
2577 && b->type != bp_catch_catch
2578 && b->type != bp_catch_throw) /* a non-watchpoint bp */
2580 if (b->loc->address != bp_addr) /* address doesn't match */
2582 if (overlay_debugging /* unmapped overlay section */
2583 && section_is_overlay (b->loc->section)
2584 && !section_is_mapped (b->loc->section))
2588 if (b->type == bp_hardware_breakpoint)
2590 if (b->loc->address != (*pc - DECR_PC_AFTER_HW_BREAK))
2592 if (overlay_debugging /* unmapped overlay section */
2593 && section_is_overlay (b->loc->section)
2594 && !section_is_mapped (b->loc->section))
2598 /* Is this a catchpoint of a load or unload? If so, did we
2599 get a load or unload of the specified library? If not,
2601 if ((b->type == bp_catch_load)
2602 #if defined(SOLIB_HAVE_LOAD_EVENT)
2603 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid))
2604 || ((b->dll_pathname != NULL)
2605 && (strcmp (b->dll_pathname,
2606 SOLIB_LOADED_LIBRARY_PATHNAME (
2607 PIDGET (inferior_ptid)))
2613 if ((b->type == bp_catch_unload)
2614 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2615 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid))
2616 || ((b->dll_pathname != NULL)
2617 && (strcmp (b->dll_pathname,
2618 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2619 PIDGET (inferior_ptid)))
2625 if ((b->type == bp_catch_fork)
2626 && !inferior_has_forked (PIDGET (inferior_ptid),
2627 &b->forked_inferior_pid))
2630 if ((b->type == bp_catch_vfork)
2631 && !inferior_has_vforked (PIDGET (inferior_ptid),
2632 &b->forked_inferior_pid))
2635 if ((b->type == bp_catch_exec)
2636 && !inferior_has_execd (PIDGET (inferior_ptid), &b->exec_pathname))
2639 if (ep_is_exception_catchpoint (b) &&
2640 !(current_exception_event = target_get_current_exception_event ()))
2643 /* Come here if it's a watchpoint, or if the break address matches */
2645 bs = bpstat_alloc (b, bs); /* Alloc a bpstat to explain stop */
2647 /* Watchpoints may change this, if not found to have triggered. */
2651 if (b->type == bp_watchpoint ||
2652 b->type == bp_hardware_watchpoint)
2654 char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n",
2656 struct cleanup *cleanups = make_cleanup (xfree, message);
2657 int e = catch_errors (watchpoint_check, bs, message,
2659 do_cleanups (cleanups);
2663 /* We've already printed what needs to be printed. */
2664 /* Actually this is superfluous, because by the time we
2665 call print_it_typical() the wp will be already deleted,
2666 and the function will return immediately. */
2667 bs->print_it = print_it_done;
2670 case WP_VALUE_CHANGED:
2674 case WP_VALUE_NOT_CHANGED:
2676 bs->print_it = print_it_noop;
2683 /* Error from catch_errors. */
2684 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2685 if (b->related_breakpoint)
2686 b->related_breakpoint->disposition = disp_del_at_next_stop;
2687 b->disposition = disp_del_at_next_stop;
2688 /* We've already printed what needs to be printed. */
2689 bs->print_it = print_it_done;
2695 else if (b->type == bp_read_watchpoint ||
2696 b->type == bp_access_watchpoint)
2702 addr = target_stopped_data_address ();
2705 for (v = b->val_chain; v; v = v->next)
2707 if (VALUE_LVAL (v) == lval_memory
2708 && ! VALUE_LAZY (v))
2710 struct type *vtype = check_typedef (VALUE_TYPE (v));
2712 if (v == b->val_chain
2713 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
2714 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
2718 vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
2719 /* Exact match not required. Within range is
2721 if (addr >= vaddr &&
2722 addr < vaddr + TYPE_LENGTH (VALUE_TYPE (v)))
2729 char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n",
2731 struct cleanup *cleanups = make_cleanup (xfree, message);
2732 int e = catch_errors (watchpoint_check, bs, message,
2734 do_cleanups (cleanups);
2738 /* We've already printed what needs to be printed. */
2739 bs->print_it = print_it_done;
2742 case WP_VALUE_CHANGED:
2743 if (b->type == bp_read_watchpoint)
2745 /* Don't stop: read watchpoints shouldn't fire if
2746 the value has changed. This is for targets
2747 which cannot set read-only watchpoints. */
2748 bs->print_it = print_it_noop;
2754 case WP_VALUE_NOT_CHANGED:
2761 /* Error from catch_errors. */
2762 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2763 if (b->related_breakpoint)
2764 b->related_breakpoint->disposition = disp_del_at_next_stop;
2765 b->disposition = disp_del_at_next_stop;
2766 /* We've already printed what needs to be printed. */
2767 bs->print_it = print_it_done;
2771 else /* found == 0 */
2773 /* This is a case where some watchpoint(s) triggered,
2774 but not at the address of this watchpoint (FOUND
2775 was left zero). So don't print anything for this
2777 bs->print_it = print_it_noop;
2784 /* By definition, an encountered breakpoint is a triggered
2788 real_breakpoint = 1;
2791 if (frame_id_p (b->frame_id)
2792 && !frame_id_eq (b->frame_id, get_frame_id (get_current_frame ())))
2796 int value_is_zero = 0;
2800 /* Need to select the frame, with all that implies
2801 so that the conditions will have the right context. */
2802 select_frame (get_current_frame ());
2804 = catch_errors (breakpoint_cond_eval, (b->cond),
2805 "Error in testing breakpoint condition:\n",
2807 /* FIXME-someday, should give breakpoint # */
2810 if (b->cond && value_is_zero)
2813 /* Don't consider this a hit. */
2816 else if (b->ignore_count > 0)
2819 annotate_ignore_count_change ();
2824 /* We will stop here */
2825 if (b->disposition == disp_disable)
2826 b->enable_state = bp_disabled;
2829 bs->commands = b->commands;
2831 (STREQ ("silent", bs->commands->line) ||
2832 (xdb_commands && STREQ ("Q", bs->commands->line))))
2834 bs->commands = bs->commands->next;
2837 bs->commands = copy_command_lines (bs->commands);
2840 /* Print nothing for this entry if we dont stop or if we dont print. */
2841 if (bs->stop == 0 || bs->print == 0)
2842 bs->print_it = print_it_noop;
2845 bs->next = NULL; /* Terminate the chain */
2846 bs = root_bs->next; /* Re-grab the head of the chain */
2848 if (real_breakpoint && bs)
2850 if (bs->breakpoint_at->type == bp_hardware_breakpoint)
2852 if (DECR_PC_AFTER_HW_BREAK != 0)
2854 *pc = *pc - DECR_PC_AFTER_HW_BREAK;
2860 if (DECR_PC_AFTER_BREAK != 0 || must_shift_inst_regs)
2863 #if defined (SHIFT_INST_REGS)
2865 #else /* No SHIFT_INST_REGS. */
2867 #endif /* No SHIFT_INST_REGS. */
2872 /* The value of a hardware watchpoint hasn't changed, but the
2873 intermediate memory locations we are watching may have. */
2874 if (bs && !bs->stop &&
2875 (bs->breakpoint_at->type == bp_hardware_watchpoint ||
2876 bs->breakpoint_at->type == bp_read_watchpoint ||
2877 bs->breakpoint_at->type == bp_access_watchpoint))
2879 remove_breakpoints ();
2880 insert_breakpoints ();
2885 /* Tell what to do about this bpstat. */
2887 bpstat_what (bpstat bs)
2889 /* Classify each bpstat as one of the following. */
2892 /* This bpstat element has no effect on the main_action. */
2895 /* There was a watchpoint, stop but don't print. */
2898 /* There was a watchpoint, stop and print. */
2901 /* There was a breakpoint but we're not stopping. */
2904 /* There was a breakpoint, stop but don't print. */
2907 /* There was a breakpoint, stop and print. */
2910 /* We hit the longjmp breakpoint. */
2913 /* We hit the longjmp_resume breakpoint. */
2916 /* We hit the step_resume breakpoint. */
2919 /* We hit the through_sigtramp breakpoint. */
2922 /* We hit the shared library event breakpoint. */
2925 /* We caught a shared library event. */
2928 /* This is just used to count how many enums there are. */
2932 /* Here is the table which drives this routine. So that we can
2933 format it pretty, we define some abbreviations for the
2934 enum bpstat_what codes. */
2935 #define kc BPSTAT_WHAT_KEEP_CHECKING
2936 #define ss BPSTAT_WHAT_STOP_SILENT
2937 #define sn BPSTAT_WHAT_STOP_NOISY
2938 #define sgl BPSTAT_WHAT_SINGLE
2939 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
2940 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
2941 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
2942 #define sr BPSTAT_WHAT_STEP_RESUME
2943 #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
2944 #define shl BPSTAT_WHAT_CHECK_SHLIBS
2945 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
2947 /* "Can't happen." Might want to print an error message.
2948 abort() is not out of the question, but chances are GDB is just
2949 a bit confused, not unusable. */
2950 #define err BPSTAT_WHAT_STOP_NOISY
2952 /* Given an old action and a class, come up with a new action. */
2953 /* One interesting property of this table is that wp_silent is the same
2954 as bp_silent and wp_noisy is the same as bp_noisy. That is because
2955 after stopping, the check for whether to step over a breakpoint
2956 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
2957 reference to how we stopped. We retain separate wp_silent and
2958 bp_silent codes in case we want to change that someday.
2960 Another possibly interesting property of this table is that
2961 there's a partial ordering, priority-like, of the actions. Once
2962 you've decided that some action is appropriate, you'll never go
2963 back and decide something of a lower priority is better. The
2966 kc < clr sgl shl shlr slr sn sr ss ts
2967 sgl < clrs shl shlr slr sn sr ss ts
2968 slr < err shl shlr sn sr ss ts
2969 clr < clrs err shl shlr sn sr ss ts
2970 clrs < err shl shlr sn sr ss ts
2971 ss < shl shlr sn sr ts
2978 What I think this means is that we don't need a damned table
2979 here. If you just put the rows and columns in the right order,
2980 it'd look awfully regular. We could simply walk the bpstat list
2981 and choose the highest priority action we find, with a little
2982 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
2983 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
2984 is messy anyway). */
2986 /* step_resume entries: a step resume breakpoint overrides another
2987 breakpoint of signal handling (see comment in wait_for_inferior
2988 at first PC_IN_SIGTRAMP where we set the step_resume breakpoint). */
2989 /* We handle the through_sigtramp_breakpoint the same way; having both
2990 one of those and a step_resume_breakpoint is probably very rare (?). */
2992 static const enum bpstat_what_main_action
2993 table[(int) class_last][(int) BPSTAT_WHAT_LAST] =
2996 /* kc ss sn sgl slr clr clrs sr ts shl shlr
2999 {kc, ss, sn, sgl, slr, clr, clrs, sr, ts, shl, shlr},
3001 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
3003 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
3005 {sgl, ss, sn, sgl, slr, clrs, clrs, sr, ts, shl, shlr},
3007 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
3009 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
3011 {slr, ss, sn, slr, slr, err, err, sr, ts, shl, shlr},
3013 {clr, ss, sn, clrs, err, err, err, sr, ts, shl, shlr},
3015 {sr, sr, sr, sr, sr, sr, sr, sr, ts, shl, shlr},
3017 {ts, ts, ts, ts, ts, ts, ts, ts, ts, shl, shlr},
3019 {shl, shl, shl, shl, shl, shl, shl, shl, ts, shl, shlr},
3021 {shlr, shlr, shlr, shlr, shlr, shlr, shlr, shlr, ts, shlr, shlr}
3036 enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
3037 struct bpstat_what retval;
3039 retval.call_dummy = 0;
3040 for (; bs != NULL; bs = bs->next)
3042 enum class bs_class = no_effect;
3043 if (bs->breakpoint_at == NULL)
3044 /* I suspect this can happen if it was a momentary breakpoint
3045 which has since been deleted. */
3047 switch (bs->breakpoint_at->type)
3053 case bp_hardware_breakpoint:
3059 bs_class = bp_noisy;
3061 bs_class = bp_silent;
3064 bs_class = bp_nostop;
3067 case bp_hardware_watchpoint:
3068 case bp_read_watchpoint:
3069 case bp_access_watchpoint:
3073 bs_class = wp_noisy;
3075 bs_class = wp_silent;
3078 /* There was a watchpoint, but we're not stopping.
3079 This requires no further action. */
3080 bs_class = no_effect;
3083 bs_class = long_jump;
3085 case bp_longjmp_resume:
3086 bs_class = long_resume;
3088 case bp_step_resume:
3091 bs_class = step_resume;
3094 /* It is for the wrong frame. */
3095 bs_class = bp_nostop;
3097 case bp_through_sigtramp:
3098 bs_class = through_sig;
3100 case bp_watchpoint_scope:
3101 bs_class = bp_nostop;
3103 case bp_shlib_event:
3104 bs_class = shlib_event;
3106 case bp_thread_event:
3107 case bp_overlay_event:
3108 bs_class = bp_nostop;
3111 case bp_catch_unload:
3112 /* Only if this catchpoint triggered should we cause the
3113 step-out-of-dld behaviour. Otherwise, we ignore this
3116 bs_class = catch_shlib_event;
3118 bs_class = no_effect;
3121 case bp_catch_vfork:
3126 bs_class = bp_noisy;
3128 bs_class = bp_silent;
3131 /* There was a catchpoint, but we're not stopping.
3132 This requires no further action. */
3133 bs_class = no_effect;
3135 case bp_catch_catch:
3136 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_CATCH)
3137 bs_class = bp_nostop;
3139 bs_class = bs->print ? bp_noisy : bp_silent;
3141 case bp_catch_throw:
3142 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_THROW)
3143 bs_class = bp_nostop;
3145 bs_class = bs->print ? bp_noisy : bp_silent;
3148 /* Make sure the action is stop (silent or noisy),
3149 so infrun.c pops the dummy frame. */
3150 bs_class = bp_silent;
3151 retval.call_dummy = 1;
3154 current_action = table[(int) bs_class][(int) current_action];
3156 retval.main_action = current_action;
3160 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3161 without hardware support). This isn't related to a specific bpstat,
3162 just to things like whether watchpoints are set. */
3165 bpstat_should_step (void)
3167 struct breakpoint *b;
3169 if (b->enable_state == bp_enabled && b->type == bp_watchpoint)
3174 /* Nonzero if there are enabled hardware watchpoints. */
3176 bpstat_have_active_hw_watchpoints (void)
3178 struct breakpoint *b;
3180 if ((b->enable_state == bp_enabled) &&
3181 (b->loc->inserted) &&
3182 ((b->type == bp_hardware_watchpoint) ||
3183 (b->type == bp_read_watchpoint) ||
3184 (b->type == bp_access_watchpoint)))
3190 /* Given a bpstat that records zero or more triggered eventpoints, this
3191 function returns another bpstat which contains only the catchpoints
3192 on that first list, if any. */
3194 bpstat_get_triggered_catchpoints (bpstat ep_list, bpstat *cp_list)
3196 struct bpstats root_bs[1];
3197 bpstat bs = root_bs;
3198 struct breakpoint *ep;
3201 bpstat_clear (cp_list);
3202 root_bs->next = NULL;
3204 for (; ep_list != NULL; ep_list = ep_list->next)
3206 /* Is this eventpoint a catchpoint? If not, ignore it. */
3207 ep = ep_list->breakpoint_at;
3210 if ((ep->type != bp_catch_load) &&
3211 (ep->type != bp_catch_unload) &&
3212 (ep->type != bp_catch_catch) &&
3213 (ep->type != bp_catch_throw))
3214 /* pai: (temp) ADD fork/vfork here!! */
3217 /* Yes; add it to the list. */
3218 bs = bpstat_alloc (ep, bs);
3223 #if defined(SOLIB_ADD)
3224 /* Also, for each triggered catchpoint, tag it with the name of
3225 the library that caused this trigger. (We copy the name now,
3226 because it's only guaranteed to be available NOW, when the
3227 catchpoint triggers. Clients who may wish to know the name
3228 later must get it from the catchpoint itself.) */
3229 if (ep->triggered_dll_pathname != NULL)
3230 xfree (ep->triggered_dll_pathname);
3231 if (ep->type == bp_catch_load)
3232 dll_pathname = SOLIB_LOADED_LIBRARY_PATHNAME (
3233 PIDGET (inferior_ptid));
3235 dll_pathname = SOLIB_UNLOADED_LIBRARY_PATHNAME (
3236 PIDGET (inferior_ptid));
3238 dll_pathname = NULL;
3242 ep->triggered_dll_pathname = (char *)
3243 xmalloc (strlen (dll_pathname) + 1);
3244 strcpy (ep->triggered_dll_pathname, dll_pathname);
3247 ep->triggered_dll_pathname = NULL;
3253 /* Print B to gdb_stdout. */
3255 print_one_breakpoint (struct breakpoint *b,
3256 CORE_ADDR *last_addr)
3258 struct command_line *l;
3260 struct ep_type_description
3265 static struct ep_type_description bptypes[] =
3267 {bp_none, "?deleted?"},
3268 {bp_breakpoint, "breakpoint"},
3269 {bp_hardware_breakpoint, "hw breakpoint"},
3270 {bp_until, "until"},
3271 {bp_finish, "finish"},
3272 {bp_watchpoint, "watchpoint"},
3273 {bp_hardware_watchpoint, "hw watchpoint"},
3274 {bp_read_watchpoint, "read watchpoint"},
3275 {bp_access_watchpoint, "acc watchpoint"},
3276 {bp_longjmp, "longjmp"},
3277 {bp_longjmp_resume, "longjmp resume"},
3278 {bp_step_resume, "step resume"},
3279 {bp_through_sigtramp, "sigtramp"},
3280 {bp_watchpoint_scope, "watchpoint scope"},
3281 {bp_call_dummy, "call dummy"},
3282 {bp_shlib_event, "shlib events"},
3283 {bp_thread_event, "thread events"},
3284 {bp_overlay_event, "overlay events"},
3285 {bp_catch_load, "catch load"},
3286 {bp_catch_unload, "catch unload"},
3287 {bp_catch_fork, "catch fork"},
3288 {bp_catch_vfork, "catch vfork"},
3289 {bp_catch_exec, "catch exec"},
3290 {bp_catch_catch, "catch catch"},
3291 {bp_catch_throw, "catch throw"}
3294 static char *bpdisps[] =
3295 {"del", "dstp", "dis", "keep"};
3296 static char bpenables[] = "nynny";
3297 char wrap_indent[80];
3298 struct ui_stream *stb = ui_out_stream_new (uiout);
3299 struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb);
3300 struct cleanup *bkpt_chain;
3303 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
3307 ui_out_field_int (uiout, "number", b->number);
3311 if (((int) b->type > (sizeof (bptypes) / sizeof (bptypes[0])))
3312 || ((int) b->type != bptypes[(int) b->type].type))
3313 internal_error (__FILE__, __LINE__,
3314 "bptypes table does not describe type #%d.",
3316 ui_out_field_string (uiout, "type", bptypes[(int) b->type].description);
3320 ui_out_field_string (uiout, "disp", bpdisps[(int) b->disposition]);
3324 ui_out_field_fmt (uiout, "enabled", "%c", bpenables[(int) b->enable_state]);
3325 ui_out_spaces (uiout, 2);
3328 strcpy (wrap_indent, " ");
3331 if (TARGET_ADDR_BIT <= 32)
3332 strcat (wrap_indent, " ");
3334 strcat (wrap_indent, " ");
3337 if (b->ops != NULL && b->ops->print_one != NULL)
3338 b->ops->print_one (b, last_addr);
3343 internal_error (__FILE__, __LINE__,
3344 "print_one_breakpoint: bp_none encountered\n");
3348 case bp_hardware_watchpoint:
3349 case bp_read_watchpoint:
3350 case bp_access_watchpoint:
3351 /* Field 4, the address, is omitted (which makes the columns
3352 not line up too nicely with the headers, but the effect
3353 is relatively readable). */
3355 ui_out_field_skip (uiout, "addr");
3357 print_expression (b->exp, stb->stream);
3358 ui_out_field_stream (uiout, "what", stb);
3362 case bp_catch_unload:
3363 /* Field 4, the address, is omitted (which makes the columns
3364 not line up too nicely with the headers, but the effect
3365 is relatively readable). */
3367 ui_out_field_skip (uiout, "addr");
3369 if (b->dll_pathname == NULL)
3371 ui_out_field_string (uiout, "what", "<any library>");
3372 ui_out_spaces (uiout, 1);
3376 ui_out_text (uiout, "library \"");
3377 ui_out_field_string (uiout, "what", b->dll_pathname);
3378 ui_out_text (uiout, "\" ");
3383 case bp_catch_vfork:
3384 /* Field 4, the address, is omitted (which makes the columns
3385 not line up too nicely with the headers, but the effect
3386 is relatively readable). */
3388 ui_out_field_skip (uiout, "addr");
3390 if (b->forked_inferior_pid != 0)
3392 ui_out_text (uiout, "process ");
3393 ui_out_field_int (uiout, "what", b->forked_inferior_pid);
3394 ui_out_spaces (uiout, 1);
3398 /* Field 4, the address, is omitted (which makes the columns
3399 not line up too nicely with the headers, but the effect
3400 is relatively readable). */
3402 ui_out_field_skip (uiout, "addr");
3404 if (b->exec_pathname != NULL)
3406 ui_out_text (uiout, "program \"");
3407 ui_out_field_string (uiout, "what", b->exec_pathname);
3408 ui_out_text (uiout, "\" ");
3412 case bp_catch_catch:
3413 /* Field 4, the address, is omitted (which makes the columns
3414 not line up too nicely with the headers, but the effect
3415 is relatively readable). */
3417 ui_out_field_skip (uiout, "addr");
3419 ui_out_field_string (uiout, "what", "exception catch");
3420 ui_out_spaces (uiout, 1);
3423 case bp_catch_throw:
3424 /* Field 4, the address, is omitted (which makes the columns
3425 not line up too nicely with the headers, but the effect
3426 is relatively readable). */
3428 ui_out_field_skip (uiout, "addr");
3430 ui_out_field_string (uiout, "what", "exception throw");
3431 ui_out_spaces (uiout, 1);
3435 case bp_hardware_breakpoint:
3439 case bp_longjmp_resume:
3440 case bp_step_resume:
3441 case bp_through_sigtramp:
3442 case bp_watchpoint_scope:
3444 case bp_shlib_event:
3445 case bp_thread_event:
3446 case bp_overlay_event:
3450 ui_out_field_core_addr (uiout, "addr", b->loc->address);
3453 *last_addr = b->loc->address;
3456 sym = find_pc_sect_function (b->loc->address, b->loc->section);
3459 ui_out_text (uiout, "in ");
3460 ui_out_field_string (uiout, "func",
3461 SYMBOL_PRINT_NAME (sym));
3462 ui_out_wrap_hint (uiout, wrap_indent);
3463 ui_out_text (uiout, " at ");
3465 ui_out_field_string (uiout, "file", b->source_file);
3466 ui_out_text (uiout, ":");
3467 ui_out_field_int (uiout, "line", b->line_number);
3471 print_address_symbolic (b->loc->address, stb->stream, demangle, "");
3472 ui_out_field_stream (uiout, "at", stb);
3477 if (b->thread != -1)
3479 /* FIXME: This seems to be redundant and lost here; see the
3480 "stop only in" line a little further down. */
3481 ui_out_text (uiout, " thread ");
3482 ui_out_field_int (uiout, "thread", b->thread);
3485 ui_out_text (uiout, "\n");
3487 if (frame_id_p (b->frame_id))
3490 ui_out_text (uiout, "\tstop only in stack frame at ");
3491 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3493 ui_out_field_core_addr (uiout, "frame", b->frame_id.stack_addr);
3494 ui_out_text (uiout, "\n");
3500 ui_out_text (uiout, "\tstop only if ");
3501 print_expression (b->cond, stb->stream);
3502 ui_out_field_stream (uiout, "cond", stb);
3503 ui_out_text (uiout, "\n");
3506 if (b->thread != -1)
3508 /* FIXME should make an annotation for this */
3509 ui_out_text (uiout, "\tstop only in thread ");
3510 ui_out_field_int (uiout, "thread", b->thread);
3511 ui_out_text (uiout, "\n");
3514 if (show_breakpoint_hit_counts && b->hit_count)
3516 /* FIXME should make an annotation for this */
3517 if (ep_is_catchpoint (b))
3518 ui_out_text (uiout, "\tcatchpoint");
3520 ui_out_text (uiout, "\tbreakpoint");
3521 ui_out_text (uiout, " already hit ");
3522 ui_out_field_int (uiout, "times", b->hit_count);
3523 if (b->hit_count == 1)
3524 ui_out_text (uiout, " time\n");
3526 ui_out_text (uiout, " times\n");
3529 /* Output the count also if it is zero, but only if this is
3530 mi. FIXME: Should have a better test for this. */
3531 if (ui_out_is_mi_like_p (uiout))
3532 if (show_breakpoint_hit_counts && b->hit_count == 0)
3533 ui_out_field_int (uiout, "times", b->hit_count);
3535 if (b->ignore_count)
3538 ui_out_text (uiout, "\tignore next ");
3539 ui_out_field_int (uiout, "ignore", b->ignore_count);
3540 ui_out_text (uiout, " hits\n");
3543 if ((l = b->commands))
3545 struct cleanup *script_chain;
3548 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
3549 print_command_lines (uiout, l, 4);
3550 do_cleanups (script_chain);
3552 do_cleanups (bkpt_chain);
3553 do_cleanups (old_chain);
3556 struct captured_breakpoint_query_args
3562 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
3564 struct captured_breakpoint_query_args *args = data;
3565 struct breakpoint *b;
3566 CORE_ADDR dummy_addr = 0;
3569 if (args->bnum == b->number)
3571 print_one_breakpoint (b, &dummy_addr);
3579 gdb_breakpoint_query (struct ui_out *uiout, int bnum)
3581 struct captured_breakpoint_query_args args;
3583 /* For the moment we don't trust print_one_breakpoint() to not throw
3585 return catch_exceptions (uiout, do_captured_breakpoint_query, &args,
3586 NULL, RETURN_MASK_ALL);
3589 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3590 catchpoints, et.al.). */
3593 user_settable_breakpoint (const struct breakpoint *b)
3595 return (b->type == bp_breakpoint
3596 || b->type == bp_catch_load
3597 || b->type == bp_catch_unload
3598 || b->type == bp_catch_fork
3599 || b->type == bp_catch_vfork
3600 || b->type == bp_catch_exec
3601 || b->type == bp_catch_catch
3602 || b->type == bp_catch_throw
3603 || b->type == bp_hardware_breakpoint
3604 || b->type == bp_watchpoint
3605 || b->type == bp_read_watchpoint
3606 || b->type == bp_access_watchpoint
3607 || b->type == bp_hardware_watchpoint);
3610 /* Print information on user settable breakpoint (watchpoint, etc)
3611 number BNUM. If BNUM is -1 print all user settable breakpoints.
3612 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3615 breakpoint_1 (int bnum, int allflag)
3617 struct breakpoint *b;
3618 CORE_ADDR last_addr = (CORE_ADDR) -1;
3619 int nr_printable_breakpoints;
3620 struct cleanup *bkpttbl_chain;
3622 /* Compute the number of rows in the table. */
3623 nr_printable_breakpoints = 0;
3626 || bnum == b->number)
3628 if (allflag || user_settable_breakpoint (b))
3629 nr_printable_breakpoints++;
3634 = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints,
3638 = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints,
3641 if (nr_printable_breakpoints > 0)
3642 annotate_breakpoints_headers ();
3643 if (nr_printable_breakpoints > 0)
3645 ui_out_table_header (uiout, 3, ui_left, "number", "Num"); /* 1 */
3646 if (nr_printable_breakpoints > 0)
3648 ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */
3649 if (nr_printable_breakpoints > 0)
3651 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
3652 if (nr_printable_breakpoints > 0)
3654 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
3657 if (nr_printable_breakpoints > 0)
3659 if (TARGET_ADDR_BIT <= 32)
3660 ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */
3662 ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */
3664 if (nr_printable_breakpoints > 0)
3666 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
3667 ui_out_table_body (uiout);
3668 if (nr_printable_breakpoints > 0)
3669 annotate_breakpoints_table ();
3673 || bnum == b->number)
3675 /* We only print out user settable breakpoints unless the
3677 if (allflag || user_settable_breakpoint (b))
3678 print_one_breakpoint (b, &last_addr);
3681 do_cleanups (bkpttbl_chain);
3683 if (nr_printable_breakpoints == 0)
3686 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
3688 ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n",
3693 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3694 that a comparison of an unsigned with -1 is always false. */
3695 if (last_addr != (CORE_ADDR) -1)
3696 set_next_address (last_addr);
3699 /* FIXME? Should this be moved up so that it is only called when
3700 there have been breakpoints? */
3701 annotate_breakpoints_table_end ();
3705 breakpoints_info (char *bnum_exp, int from_tty)
3710 bnum = parse_and_eval_long (bnum_exp);
3712 breakpoint_1 (bnum, 0);
3716 maintenance_info_breakpoints (char *bnum_exp, int from_tty)
3721 bnum = parse_and_eval_long (bnum_exp);
3723 breakpoint_1 (bnum, 1);
3726 /* Print a message describing any breakpoints set at PC. */
3729 describe_other_breakpoints (CORE_ADDR pc, asection *section)
3732 struct breakpoint *b;
3735 if (b->loc->address == pc) /* address match / overlay match */
3736 if (!overlay_debugging || b->loc->section == section)
3740 printf_filtered ("Note: breakpoint%s ", (others > 1) ? "s" : "");
3742 if (b->loc->address == pc) /* address match / overlay match */
3743 if (!overlay_debugging || b->loc->section == section)
3746 printf_filtered ("%d%s%s ",
3748 ((b->enable_state == bp_disabled ||
3749 b->enable_state == bp_shlib_disabled ||
3750 b->enable_state == bp_call_disabled)
3752 : b->enable_state == bp_permanent
3756 : ((others == 1) ? " and" : ""));
3758 printf_filtered ("also set at pc ");
3759 print_address_numeric (pc, 1, gdb_stdout);
3760 printf_filtered (".\n");
3764 /* Set the default place to put a breakpoint
3765 for the `break' command with no arguments. */
3768 set_default_breakpoint (int valid, CORE_ADDR addr, struct symtab *symtab,
3771 default_breakpoint_valid = valid;
3772 default_breakpoint_address = addr;
3773 default_breakpoint_symtab = symtab;
3774 default_breakpoint_line = line;
3777 /* Return true iff it is meaningful to use the address member of
3778 BPT. For some breakpoint types, the address member is irrelevant
3779 and it makes no sense to attempt to compare it to other addresses
3780 (or use it for any other purpose either).
3782 More specifically, each of the following breakpoint types will always
3783 have a zero valued address and we don't want check_duplicates() to mark
3784 breakpoints of any of these types to be a duplicate of an actual
3785 breakpoint at address zero:
3788 bp_hardware_watchpoint
3790 bp_access_watchpoint
3797 breakpoint_address_is_meaningful (struct breakpoint *bpt)
3799 enum bptype type = bpt->type;
3801 return (type != bp_watchpoint
3802 && type != bp_hardware_watchpoint
3803 && type != bp_read_watchpoint
3804 && type != bp_access_watchpoint
3805 && type != bp_catch_exec
3806 && type != bp_longjmp_resume
3807 && type != bp_catch_fork
3808 && type != bp_catch_vfork);
3811 /* Rescan breakpoints at the same address and section as BPT,
3812 marking the first one as "first" and any others as "duplicates".
3813 This is so that the bpt instruction is only inserted once.
3814 If we have a permanent breakpoint at the same place as BPT, make
3815 that one the official one, and the rest as duplicates. */
3818 check_duplicates (struct breakpoint *bpt)
3820 struct breakpoint *b;
3822 struct breakpoint *perm_bp = 0;
3823 CORE_ADDR address = bpt->loc->address;
3824 asection *section = bpt->loc->section;
3826 if (! breakpoint_address_is_meaningful (bpt))
3830 if (b->enable_state != bp_disabled
3831 && b->enable_state != bp_shlib_disabled
3832 && b->enable_state != bp_call_disabled
3833 && b->loc->address == address /* address / overlay match */
3834 && (!overlay_debugging || b->loc->section == section)
3835 && breakpoint_address_is_meaningful (b))
3837 /* Have we found a permanent breakpoint? */
3838 if (b->enable_state == bp_permanent)
3845 b->loc->duplicate = count > 1;
3848 /* If we found a permanent breakpoint at this address, go over the
3849 list again and declare all the other breakpoints there to be the
3853 perm_bp->loc->duplicate = 0;
3855 /* Permanent breakpoint should always be inserted. */
3856 if (! perm_bp->loc->inserted)
3857 internal_error (__FILE__, __LINE__,
3858 "allegedly permanent breakpoint is not "
3859 "actually inserted");
3864 if (b->loc->inserted)
3865 internal_error (__FILE__, __LINE__,
3866 "another breakpoint was inserted on top of "
3867 "a permanent breakpoint");
3869 if (b->enable_state != bp_disabled
3870 && b->enable_state != bp_shlib_disabled
3871 && b->enable_state != bp_call_disabled
3872 && b->loc->address == address /* address / overlay match */
3873 && (!overlay_debugging || b->loc->section == section)
3874 && breakpoint_address_is_meaningful (b))
3875 b->loc->duplicate = 1;
3881 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
3882 int bnum, int have_bnum)
3887 strcpy (astr1, local_hex_string_custom ((unsigned long) from_addr, "08l"));
3888 strcpy (astr2, local_hex_string_custom ((unsigned long) to_addr, "08l"));
3890 warning ("Breakpoint %d address previously adjusted from %s to %s.",
3891 bnum, astr1, astr2);
3893 warning ("Breakpoint address adjusted from %s to %s.", astr1, astr2);
3896 /* Adjust a breakpoint's address to account for architectural constraints
3897 on breakpoint placement. Return the adjusted address. Note: Very
3898 few targets require this kind of adjustment. For most targets,
3899 this function is simply the identity function. */
3902 adjust_breakpoint_address (CORE_ADDR bpaddr)
3904 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch))
3906 /* Very few targets need any kind of breakpoint adjustment. */
3911 CORE_ADDR adjusted_bpaddr;
3913 /* Some targets have architectural constraints on the placement
3914 of breakpoint instructions. Obtain the adjusted address. */
3915 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (current_gdbarch,
3918 /* An adjusted breakpoint address can significantly alter
3919 a user's expectations. Print a warning if an adjustment
3921 if (adjusted_bpaddr != bpaddr)
3922 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
3924 return adjusted_bpaddr;
3928 /* Allocate a struct bp_location. */
3930 struct bp_location *
3931 allocate_bp_location (struct breakpoint *bpt, enum bptype bp_type)
3933 struct bp_location *loc, *loc_p;
3935 loc = xmalloc (sizeof (struct bp_location));
3936 memset (loc, 0, sizeof (*loc));
3946 case bp_longjmp_resume:
3947 case bp_step_resume:
3948 case bp_through_sigtramp:
3949 case bp_watchpoint_scope:
3951 case bp_shlib_event:
3952 case bp_thread_event:
3953 case bp_overlay_event:
3955 case bp_catch_unload:
3956 loc->loc_type = bp_loc_software_breakpoint;
3958 case bp_hardware_breakpoint:
3959 loc->loc_type = bp_loc_hardware_breakpoint;
3961 case bp_hardware_watchpoint:
3962 case bp_read_watchpoint:
3963 case bp_access_watchpoint:
3964 loc->loc_type = bp_loc_hardware_watchpoint;
3968 case bp_catch_vfork:
3970 case bp_catch_catch:
3971 case bp_catch_throw:
3972 loc->loc_type = bp_loc_other;
3975 internal_error (__FILE__, __LINE__, "unknown breakpoint type");
3978 /* Add this breakpoint to the end of the chain. */
3980 loc_p = bp_location_chain;
3982 bp_location_chain = loc;
3986 loc_p = loc_p->next;
3993 /* set_raw_breakpoint() is a low level routine for allocating and
3994 partially initializing a breakpoint of type BPTYPE. The newly
3995 created breakpoint's address, section, source file name, and line
3996 number are provided by SAL. The newly created and partially
3997 initialized breakpoint is added to the breakpoint chain and
3998 is also returned as the value of this function.
4000 It is expected that the caller will complete the initialization of
4001 the newly created breakpoint struct as well as output any status
4002 information regarding the creation of a new breakpoint. In
4003 particular, set_raw_breakpoint() does NOT set the breakpoint
4004 number! Care should be taken to not allow an error() to occur
4005 prior to completing the initialization of the breakpoint. If this
4006 should happen, a bogus breakpoint will be left on the chain. */
4009 set_raw_breakpoint (struct symtab_and_line sal, enum bptype bptype)
4011 struct breakpoint *b, *b1;
4013 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
4014 memset (b, 0, sizeof (*b));
4015 b->loc = allocate_bp_location (b, bptype);
4016 b->loc->requested_address = sal.pc;
4017 b->loc->address = adjust_breakpoint_address (b->loc->requested_address);
4018 if (sal.symtab == NULL)
4019 b->source_file = NULL;
4021 b->source_file = savestring (sal.symtab->filename,
4022 strlen (sal.symtab->filename));
4023 b->loc->section = sal.section;
4025 b->language = current_language->la_language;
4026 b->input_radix = input_radix;
4028 b->line_number = sal.line;
4029 b->enable_state = bp_enabled;
4032 b->ignore_count = 0;
4034 b->frame_id = null_frame_id;
4035 b->dll_pathname = NULL;
4036 b->triggered_dll_pathname = NULL;
4037 b->forked_inferior_pid = 0;
4038 b->exec_pathname = NULL;
4041 /* Add this breakpoint to the end of the chain
4042 so that a list of breakpoints will come out in order
4043 of increasing numbers. */
4045 b1 = breakpoint_chain;
4047 breakpoint_chain = b;
4055 check_duplicates (b);
4056 breakpoints_changed ();
4062 /* Note that the breakpoint object B describes a permanent breakpoint
4063 instruction, hard-wired into the inferior's code. */
4065 make_breakpoint_permanent (struct breakpoint *b)
4067 b->enable_state = bp_permanent;
4069 /* By definition, permanent breakpoints are already present in the code. */
4070 b->loc->inserted = 1;
4073 static struct breakpoint *
4074 create_internal_breakpoint (CORE_ADDR address, enum bptype type)
4076 static int internal_breakpoint_number = -1;
4077 struct symtab_and_line sal;
4078 struct breakpoint *b;
4080 init_sal (&sal); /* initialize to zeroes */
4083 sal.section = find_pc_overlay (sal.pc);
4085 b = set_raw_breakpoint (sal, type);
4086 b->number = internal_breakpoint_number--;
4087 b->disposition = disp_donttouch;
4094 create_longjmp_breakpoint (char *func_name)
4096 struct breakpoint *b;
4097 struct minimal_symbol *m;
4099 if (func_name == NULL)
4100 b = create_internal_breakpoint (0, bp_longjmp_resume);
4103 if ((m = lookup_minimal_symbol_text (func_name, NULL)) == NULL)
4106 b = create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m), bp_longjmp);
4109 b->enable_state = bp_disabled;
4112 b->addr_string = xstrdup (func_name);
4115 /* Call this routine when stepping and nexting to enable a breakpoint
4116 if we do a longjmp(). When we hit that breakpoint, call
4117 set_longjmp_resume_breakpoint() to figure out where we are going. */
4120 enable_longjmp_breakpoint (void)
4122 struct breakpoint *b;
4125 if (b->type == bp_longjmp)
4127 b->enable_state = bp_enabled;
4128 check_duplicates (b);
4133 disable_longjmp_breakpoint (void)
4135 struct breakpoint *b;
4138 if (b->type == bp_longjmp
4139 || b->type == bp_longjmp_resume)
4141 b->enable_state = bp_disabled;
4142 check_duplicates (b);
4147 create_overlay_event_breakpoint (char *func_name)
4149 struct breakpoint *b;
4150 struct minimal_symbol *m;
4152 if ((m = lookup_minimal_symbol_text (func_name, NULL)) == NULL)
4155 b = create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m),
4157 b->addr_string = xstrdup (func_name);
4159 if (overlay_debugging == ovly_auto)
4161 b->enable_state = bp_enabled;
4162 overlay_events_enabled = 1;
4166 b->enable_state = bp_disabled;
4167 overlay_events_enabled = 0;
4172 enable_overlay_breakpoints (void)
4174 struct breakpoint *b;
4177 if (b->type == bp_overlay_event)
4179 b->enable_state = bp_enabled;
4180 check_duplicates (b);
4181 overlay_events_enabled = 1;
4186 disable_overlay_breakpoints (void)
4188 struct breakpoint *b;
4191 if (b->type == bp_overlay_event)
4193 b->enable_state = bp_disabled;
4194 check_duplicates (b);
4195 overlay_events_enabled = 0;
4200 create_thread_event_breakpoint (CORE_ADDR address)
4202 struct breakpoint *b;
4204 b = create_internal_breakpoint (address, bp_thread_event);
4206 b->enable_state = bp_enabled;
4207 /* addr_string has to be used or breakpoint_re_set will delete me. */
4208 xasprintf (&b->addr_string, "*0x%s", paddr (b->loc->address));
4214 remove_thread_event_breakpoints (void)
4216 struct breakpoint *b, *temp;
4218 ALL_BREAKPOINTS_SAFE (b, temp)
4219 if (b->type == bp_thread_event)
4220 delete_breakpoint (b);
4225 remove_solib_event_breakpoints (void)
4227 struct breakpoint *b, *temp;
4229 ALL_BREAKPOINTS_SAFE (b, temp)
4230 if (b->type == bp_shlib_event)
4231 delete_breakpoint (b);
4235 create_solib_event_breakpoint (CORE_ADDR address)
4237 struct breakpoint *b;
4239 b = create_internal_breakpoint (address, bp_shlib_event);
4243 /* Disable any breakpoints that are on code in shared libraries. Only
4244 apply to enabled breakpoints, disabled ones can just stay disabled. */
4247 disable_breakpoints_in_shlibs (int silent)
4249 struct breakpoint *b;
4250 int disabled_shlib_breaks = 0;
4252 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
4255 #if defined (PC_SOLIB)
4256 if (((b->type == bp_breakpoint) ||
4257 (b->type == bp_hardware_breakpoint)) &&
4258 b->enable_state == bp_enabled &&
4259 !b->loc->duplicate &&
4260 PC_SOLIB (b->loc->address))
4262 b->enable_state = bp_shlib_disabled;
4265 if (!disabled_shlib_breaks)
4267 target_terminal_ours_for_output ();
4268 warning ("Temporarily disabling shared library breakpoints:");
4270 disabled_shlib_breaks = 1;
4271 warning ("breakpoint #%d ", b->number);
4278 /* Try to reenable any breakpoints in shared libraries. */
4280 re_enable_breakpoints_in_shlibs (void)
4282 struct breakpoint *b;
4285 if (b->enable_state == bp_shlib_disabled)
4289 /* Do not reenable the breakpoint if the shared library
4290 is still not mapped in. */
4291 if (target_read_memory (b->loc->address, buf, 1) == 0)
4292 b->enable_state = bp_enabled;
4299 solib_load_unload_1 (char *hookname, int tempflag, char *dll_pathname,
4300 char *cond_string, enum bptype bp_kind)
4302 struct breakpoint *b;
4303 struct symtabs_and_lines sals;
4304 struct cleanup *old_chain;
4305 struct cleanup *canonical_strings_chain = NULL;
4306 char *addr_start = hookname;
4307 char *addr_end = NULL;
4308 char **canonical = (char **) NULL;
4309 int thread = -1; /* All threads. */
4311 /* Set a breakpoint on the specified hook. */
4312 sals = decode_line_1 (&hookname, 1, (struct symtab *) NULL, 0, &canonical);
4313 addr_end = hookname;
4315 if (sals.nelts == 0)
4317 warning ("Unable to set a breakpoint on dynamic linker callback.");
4318 warning ("Suggest linking with /opt/langtools/lib/end.o.");
4319 warning ("GDB will be unable to track shl_load/shl_unload calls");
4322 if (sals.nelts != 1)
4324 warning ("Unable to set unique breakpoint on dynamic linker callback.");
4325 warning ("GDB will be unable to track shl_load/shl_unload calls");
4329 /* Make sure that all storage allocated in decode_line_1 gets freed
4330 in case the following errors out. */
4331 old_chain = make_cleanup (xfree, sals.sals);
4332 if (canonical != (char **) NULL)
4334 make_cleanup (xfree, canonical);
4335 canonical_strings_chain = make_cleanup (null_cleanup, 0);
4336 if (canonical[0] != NULL)
4337 make_cleanup (xfree, canonical[0]);
4340 resolve_sal_pc (&sals.sals[0]);
4342 /* Remove the canonical strings from the cleanup, they are needed below. */
4343 if (canonical != (char **) NULL)
4344 discard_cleanups (canonical_strings_chain);
4346 b = set_raw_breakpoint (sals.sals[0], bp_kind);
4347 set_breakpoint_count (breakpoint_count + 1);
4348 b->number = breakpoint_count;
4350 b->cond_string = (cond_string == NULL) ?
4351 NULL : savestring (cond_string, strlen (cond_string));
4354 if (canonical != (char **) NULL && canonical[0] != NULL)
4355 b->addr_string = canonical[0];
4356 else if (addr_start)
4357 b->addr_string = savestring (addr_start, addr_end - addr_start);
4359 b->enable_state = bp_enabled;
4360 b->disposition = tempflag ? disp_del : disp_donttouch;
4362 if (dll_pathname == NULL)
4363 b->dll_pathname = NULL;
4366 b->dll_pathname = (char *) xmalloc (strlen (dll_pathname) + 1);
4367 strcpy (b->dll_pathname, dll_pathname);
4371 do_cleanups (old_chain);
4375 create_solib_load_event_breakpoint (char *hookname, int tempflag,
4376 char *dll_pathname, char *cond_string)
4378 solib_load_unload_1 (hookname, tempflag, dll_pathname,
4379 cond_string, bp_catch_load);
4383 create_solib_unload_event_breakpoint (char *hookname, int tempflag,
4384 char *dll_pathname, char *cond_string)
4386 solib_load_unload_1 (hookname,tempflag, dll_pathname,
4387 cond_string, bp_catch_unload);
4391 create_fork_vfork_event_catchpoint (int tempflag, char *cond_string,
4392 enum bptype bp_kind)
4394 struct symtab_and_line sal;
4395 struct breakpoint *b;
4396 int thread = -1; /* All threads. */
4403 b = set_raw_breakpoint (sal, bp_kind);
4404 set_breakpoint_count (breakpoint_count + 1);
4405 b->number = breakpoint_count;
4407 b->cond_string = (cond_string == NULL) ?
4408 NULL : savestring (cond_string, strlen (cond_string));
4410 b->addr_string = NULL;
4411 b->enable_state = bp_enabled;
4412 b->disposition = tempflag ? disp_del : disp_donttouch;
4413 b->forked_inferior_pid = 0;
4419 create_fork_event_catchpoint (int tempflag, char *cond_string)
4421 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_fork);
4425 create_vfork_event_catchpoint (int tempflag, char *cond_string)
4427 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_vfork);
4431 create_exec_event_catchpoint (int tempflag, char *cond_string)
4433 struct symtab_and_line sal;
4434 struct breakpoint *b;
4435 int thread = -1; /* All threads. */
4442 b = set_raw_breakpoint (sal, bp_catch_exec);
4443 set_breakpoint_count (breakpoint_count + 1);
4444 b->number = breakpoint_count;
4446 b->cond_string = (cond_string == NULL) ?
4447 NULL : savestring (cond_string, strlen (cond_string));
4449 b->addr_string = NULL;
4450 b->enable_state = bp_enabled;
4451 b->disposition = tempflag ? disp_del : disp_donttouch;
4457 hw_breakpoint_used_count (void)
4459 struct breakpoint *b;
4464 if (b->type == bp_hardware_breakpoint && b->enable_state == bp_enabled)
4472 hw_watchpoint_used_count (enum bptype type, int *other_type_used)
4474 struct breakpoint *b;
4477 *other_type_used = 0;
4480 if (b->enable_state == bp_enabled)
4482 if (b->type == type)
4484 else if ((b->type == bp_hardware_watchpoint ||
4485 b->type == bp_read_watchpoint ||
4486 b->type == bp_access_watchpoint)
4487 && b->enable_state == bp_enabled)
4488 *other_type_used = 1;
4494 /* Call this after hitting the longjmp() breakpoint. Use this to set
4495 a new breakpoint at the target of the jmp_buf.
4497 FIXME - This ought to be done by setting a temporary breakpoint
4498 that gets deleted automatically... */
4501 set_longjmp_resume_breakpoint (CORE_ADDR pc, struct frame_id frame_id)
4503 struct breakpoint *b;
4506 if (b->type == bp_longjmp_resume)
4508 b->loc->requested_address = pc;
4509 b->loc->address = adjust_breakpoint_address (b->loc->requested_address);
4510 b->enable_state = bp_enabled;
4511 b->frame_id = frame_id;
4512 check_duplicates (b);
4518 disable_watchpoints_before_interactive_call_start (void)
4520 struct breakpoint *b;
4524 if (((b->type == bp_watchpoint)
4525 || (b->type == bp_hardware_watchpoint)
4526 || (b->type == bp_read_watchpoint)
4527 || (b->type == bp_access_watchpoint)
4528 || ep_is_exception_catchpoint (b))
4529 && (b->enable_state == bp_enabled))
4531 b->enable_state = bp_call_disabled;
4532 check_duplicates (b);
4538 enable_watchpoints_after_interactive_call_stop (void)
4540 struct breakpoint *b;
4544 if (((b->type == bp_watchpoint)
4545 || (b->type == bp_hardware_watchpoint)
4546 || (b->type == bp_read_watchpoint)
4547 || (b->type == bp_access_watchpoint)
4548 || ep_is_exception_catchpoint (b))
4549 && (b->enable_state == bp_call_disabled))
4551 b->enable_state = bp_enabled;
4552 check_duplicates (b);
4558 /* Set a breakpoint that will evaporate an end of command
4559 at address specified by SAL.
4560 Restrict it to frame FRAME if FRAME is nonzero. */
4563 set_momentary_breakpoint (struct symtab_and_line sal, struct frame_id frame_id,
4566 struct breakpoint *b;
4567 b = set_raw_breakpoint (sal, type);
4568 b->enable_state = bp_enabled;
4569 b->disposition = disp_donttouch;
4570 b->frame_id = frame_id;
4572 /* If we're debugging a multi-threaded program, then we
4573 want momentary breakpoints to be active in only a
4574 single thread of control. */
4575 if (in_thread_list (inferior_ptid))
4576 b->thread = pid_to_thread_id (inferior_ptid);
4582 /* Tell the user we have just set a breakpoint B. */
4585 mention (struct breakpoint *b)
4588 struct cleanup *old_chain, *ui_out_chain;
4589 struct ui_stream *stb;
4591 stb = ui_out_stream_new (uiout);
4592 old_chain = make_cleanup_ui_out_stream_delete (stb);
4594 /* FIXME: This is misplaced; mention() is called by things (like hitting a
4595 watchpoint) other than breakpoint creation. It should be possible to
4596 clean this up and at the same time replace the random calls to
4597 breakpoint_changed with this hook, as has already been done for
4598 delete_breakpoint_hook and so on. */
4599 if (create_breakpoint_hook)
4600 create_breakpoint_hook (b);
4601 breakpoint_create_event (b->number);
4603 if (b->ops != NULL && b->ops->print_mention != NULL)
4604 b->ops->print_mention (b);
4609 printf_filtered ("(apparently deleted?) Eventpoint %d: ", b->number);
4612 ui_out_text (uiout, "Watchpoint ");
4613 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
4614 ui_out_field_int (uiout, "number", b->number);
4615 ui_out_text (uiout, ": ");
4616 print_expression (b->exp, stb->stream);
4617 ui_out_field_stream (uiout, "exp", stb);
4618 do_cleanups (ui_out_chain);
4620 case bp_hardware_watchpoint:
4621 ui_out_text (uiout, "Hardware watchpoint ");
4622 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
4623 ui_out_field_int (uiout, "number", b->number);
4624 ui_out_text (uiout, ": ");
4625 print_expression (b->exp, stb->stream);
4626 ui_out_field_stream (uiout, "exp", stb);
4627 do_cleanups (ui_out_chain);
4629 case bp_read_watchpoint:
4630 ui_out_text (uiout, "Hardware read watchpoint ");
4631 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
4632 ui_out_field_int (uiout, "number", b->number);
4633 ui_out_text (uiout, ": ");
4634 print_expression (b->exp, stb->stream);
4635 ui_out_field_stream (uiout, "exp", stb);
4636 do_cleanups (ui_out_chain);
4638 case bp_access_watchpoint:
4639 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
4640 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
4641 ui_out_field_int (uiout, "number", b->number);
4642 ui_out_text (uiout, ": ");
4643 print_expression (b->exp, stb->stream);
4644 ui_out_field_stream (uiout, "exp", stb);
4645 do_cleanups (ui_out_chain);
4648 if (ui_out_is_mi_like_p (uiout))
4653 printf_filtered ("Breakpoint %d", b->number);
4656 case bp_hardware_breakpoint:
4657 if (ui_out_is_mi_like_p (uiout))
4662 printf_filtered ("Hardware assisted breakpoint %d", b->number);
4666 case bp_catch_unload:
4667 printf_filtered ("Catchpoint %d (%s %s)",
4669 (b->type == bp_catch_load) ? "load" : "unload",
4670 (b->dll_pathname != NULL) ?
4671 b->dll_pathname : "<any library>");
4674 case bp_catch_vfork:
4675 printf_filtered ("Catchpoint %d (%s)",
4677 (b->type == bp_catch_fork) ? "fork" : "vfork");
4680 printf_filtered ("Catchpoint %d (exec)",
4683 case bp_catch_catch:
4684 case bp_catch_throw:
4685 printf_filtered ("Catchpoint %d (%s)",
4687 (b->type == bp_catch_catch) ? "catch" : "throw");
4693 case bp_longjmp_resume:
4694 case bp_step_resume:
4695 case bp_through_sigtramp:
4697 case bp_watchpoint_scope:
4698 case bp_shlib_event:
4699 case bp_thread_event:
4700 case bp_overlay_event:
4706 if (addressprint || b->source_file == NULL)
4708 printf_filtered (" at ");
4709 print_address_numeric (b->loc->address, 1, gdb_stdout);
4712 printf_filtered (": file %s, line %d.",
4713 b->source_file, b->line_number);
4715 do_cleanups (old_chain);
4716 if (ui_out_is_mi_like_p (uiout))
4718 printf_filtered ("\n");
4722 /* Add SALS.nelts breakpoints to the breakpoint table. For each
4723 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i],
4724 COND[i] and COND_STRING[i] values.
4726 NOTE: If the function succeeds, the caller is expected to cleanup
4727 the arrays ADDR_STRING, COND_STRING, COND and SALS (but not the
4728 array contents). If the function fails (error() is called), the
4729 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
4730 COND and SALS arrays and each of those arrays contents. */
4733 create_breakpoints (struct symtabs_and_lines sals, char **addr_string,
4734 struct expression **cond, char **cond_string,
4735 enum bptype type, enum bpdisp disposition,
4736 int thread, int ignore_count, int from_tty)
4738 if (type == bp_hardware_breakpoint)
4740 int i = hw_breakpoint_used_count ();
4741 int target_resources_ok =
4742 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
4744 if (target_resources_ok == 0)
4745 error ("No hardware breakpoint support in the target.");
4746 else if (target_resources_ok < 0)
4747 error ("Hardware breakpoints used exceeds limit.");
4750 /* Now set all the breakpoints. */
4753 for (i = 0; i < sals.nelts; i++)
4755 struct breakpoint *b;
4756 struct symtab_and_line sal = sals.sals[i];
4759 describe_other_breakpoints (sal.pc, sal.section);
4761 b = set_raw_breakpoint (sal, type);
4762 set_breakpoint_count (breakpoint_count + 1);
4763 b->number = breakpoint_count;
4767 b->addr_string = addr_string[i];
4769 /* addr_string has to be used or breakpoint_re_set will delete
4771 xasprintf (&b->addr_string, "*0x%s", paddr (b->loc->address));
4772 b->cond_string = cond_string[i];
4773 b->ignore_count = ignore_count;
4774 b->enable_state = bp_enabled;
4775 b->disposition = disposition;
4781 /* Parse ARG which is assumed to be a SAL specification possibly
4782 followed by conditionals. On return, SALS contains an array of SAL
4783 addresses found. ADDR_STRING contains a vector of (canonical)
4784 address strings. ARG points to the end of the SAL. */
4787 parse_breakpoint_sals (char **address,
4788 struct symtabs_and_lines *sals,
4789 char ***addr_string)
4791 char *addr_start = *address;
4792 *addr_string = NULL;
4793 /* If no arg given, or if first arg is 'if ', use the default
4795 if ((*address) == NULL
4796 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
4798 if (default_breakpoint_valid)
4800 struct symtab_and_line sal;
4801 init_sal (&sal); /* initialize to zeroes */
4802 sals->sals = (struct symtab_and_line *)
4803 xmalloc (sizeof (struct symtab_and_line));
4804 sal.pc = default_breakpoint_address;
4805 sal.line = default_breakpoint_line;
4806 sal.symtab = default_breakpoint_symtab;
4807 sal.section = find_pc_overlay (sal.pc);
4808 sals->sals[0] = sal;
4812 error ("No default breakpoint address now.");
4816 /* Force almost all breakpoints to be in terms of the
4817 current_source_symtab (which is decode_line_1's default). This
4818 should produce the results we want almost all of the time while
4819 leaving default_breakpoint_* alone.
4820 ObjC: However, don't match an Objective-C method name which
4821 may have a '+' or '-' succeeded by a '[' */
4823 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
4825 if (default_breakpoint_valid
4827 || ((strchr ("+-", (*address)[0]) != NULL)
4828 && ((*address)[1] != '['))))
4829 *sals = decode_line_1 (address, 1, default_breakpoint_symtab,
4830 default_breakpoint_line, addr_string);
4832 *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, addr_string);
4834 /* For any SAL that didn't have a canonical string, fill one in. */
4835 if (sals->nelts > 0 && *addr_string == NULL)
4836 *addr_string = xcalloc (sals->nelts, sizeof (char **));
4837 if (addr_start != (*address))
4840 for (i = 0; i < sals->nelts; i++)
4842 /* Add the string if not present. */
4843 if ((*addr_string)[i] == NULL)
4844 (*addr_string)[i] = savestring (addr_start, (*address) - addr_start);
4850 /* Convert each SAL into a real PC. Verify that the PC can be
4851 inserted as a breakpoint. If it can't throw an error. */
4854 breakpoint_sals_to_pc (struct symtabs_and_lines *sals,
4858 for (i = 0; i < sals->nelts; i++)
4860 resolve_sal_pc (&sals->sals[i]);
4862 /* It's possible for the PC to be nonzero, but still an illegal
4863 value on some targets.
4865 For example, on HP-UX if you start gdb, and before running the
4866 inferior you try to set a breakpoint on a shared library function
4867 "foo" where the inferior doesn't call "foo" directly but does
4868 pass its address to another function call, then we do find a
4869 minimal symbol for the "foo", but it's address is invalid.
4870 (Appears to be an index into a table that the loader sets up
4871 when the inferior is run.)
4873 Give the target a chance to bless sals.sals[i].pc before we
4874 try to make a breakpoint for it. */
4875 if (PC_REQUIRES_RUN_BEFORE_USE (sals->sals[i].pc))
4877 if (address == NULL)
4878 error ("Cannot break without a running program.");
4880 error ("Cannot break on %s without a running program.",
4886 /* Set a breakpoint according to ARG (function, linenum or *address)
4887 flag: first bit : 0 non-temporary, 1 temporary.
4888 second bit : 0 normal breakpoint, 1 hardware breakpoint. */
4891 break_command_1 (char *arg, int flag, int from_tty)
4893 int tempflag, hardwareflag;
4894 struct symtabs_and_lines sals;
4895 struct expression **cond = 0;
4896 /* Pointers in arg to the start, and one past the end, of the
4898 char **cond_string = (char **) NULL;
4899 char *addr_start = arg;
4901 struct cleanup *old_chain;
4902 struct cleanup *breakpoint_chain = NULL;
4905 int ignore_count = 0;
4907 hardwareflag = flag & BP_HARDWAREFLAG;
4908 tempflag = flag & BP_TEMPFLAG;
4913 parse_breakpoint_sals (&arg, &sals, &addr_string);
4918 /* Create a chain of things that always need to be cleaned up. */
4919 old_chain = make_cleanup (null_cleanup, 0);
4921 /* Make sure that all storage allocated to SALS gets freed. */
4922 make_cleanup (xfree, sals.sals);
4924 /* Cleanup the addr_string array but not its contents. */
4925 make_cleanup (xfree, addr_string);
4927 /* Allocate space for all the cond expressions. */
4928 cond = xcalloc (sals.nelts, sizeof (struct expression *));
4929 make_cleanup (xfree, cond);
4931 /* Allocate space for all the cond strings. */
4932 cond_string = xcalloc (sals.nelts, sizeof (char **));
4933 make_cleanup (xfree, cond_string);
4935 /* ----------------------------- SNIP -----------------------------
4936 Anything added to the cleanup chain beyond this point is assumed
4937 to be part of a breakpoint. If the breakpoint create succeeds
4938 then the memory is not reclaimed. */
4939 breakpoint_chain = make_cleanup (null_cleanup, 0);
4941 /* Mark the contents of the addr_string for cleanup. These go on
4942 the breakpoint_chain and only occure if the breakpoint create
4944 for (i = 0; i < sals.nelts; i++)
4946 if (addr_string[i] != NULL)
4947 make_cleanup (xfree, addr_string[i]);
4950 /* Resolve all line numbers to PC's and verify that the addresses
4951 are ok for the target. */
4952 breakpoint_sals_to_pc (&sals, addr_start);
4954 /* Verify that condition can be parsed, before setting any
4955 breakpoints. Allocate a separate condition expression for each
4957 thread = -1; /* No specific thread yet */
4958 for (i = 0; i < sals.nelts; i++)
4965 char *cond_start = NULL;
4966 char *cond_end = NULL;
4967 while (*tok == ' ' || *tok == '\t')
4972 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
4975 toklen = end_tok - tok;
4977 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
4979 tok = cond_start = end_tok + 1;
4980 cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
4981 make_cleanup (xfree, cond[i]);
4983 cond_string[i] = savestring (cond_start, cond_end - cond_start);
4984 make_cleanup (xfree, cond_string[i]);
4986 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
4992 thread = strtol (tok, &tok, 0);
4994 error ("Junk after thread keyword.");
4995 if (!valid_thread_id (thread))
4996 error ("Unknown thread %d\n", thread);
4999 error ("Junk at end of arguments.");
5003 create_breakpoints (sals, addr_string, cond, cond_string,
5004 hardwareflag ? bp_hardware_breakpoint : bp_breakpoint,
5005 tempflag ? disp_del : disp_donttouch,
5006 thread, ignore_count, from_tty);
5010 warning ("Multiple breakpoints were set.");
5011 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
5013 /* That's it. Discard the cleanups for data inserted into the
5015 discard_cleanups (breakpoint_chain);
5016 /* But cleanup everything else. */
5017 do_cleanups (old_chain);
5020 /* Set a breakpoint of TYPE/DISPOSITION according to ARG (function,
5021 linenum or *address) with COND and IGNORE_COUNT. */
5023 struct captured_breakpoint_args
5034 do_captured_breakpoint (void *data)
5036 struct captured_breakpoint_args *args = data;
5037 struct symtabs_and_lines sals;
5038 struct expression **cond;
5039 struct cleanup *old_chain;
5040 struct cleanup *breakpoint_chain = NULL;
5047 /* Parse the source and lines spec. Delay check that the expression
5048 didn't contain trailing garbage until after cleanups are in
5052 address_end = args->address;
5054 parse_breakpoint_sals (&address_end, &sals, &addr_string);
5059 /* Create a chain of things at always need to be cleaned up. */
5060 old_chain = make_cleanup (null_cleanup, 0);
5062 /* Always have a addr_string array, even if it is empty. */
5063 make_cleanup (xfree, addr_string);
5065 /* Make sure that all storage allocated to SALS gets freed. */
5066 make_cleanup (xfree, sals.sals);
5068 /* Allocate space for all the cond expressions. */
5069 cond = xcalloc (sals.nelts, sizeof (struct expression *));
5070 make_cleanup (xfree, cond);
5072 /* Allocate space for all the cond strings. */
5073 cond_string = xcalloc (sals.nelts, sizeof (char **));
5074 make_cleanup (xfree, cond_string);
5076 /* ----------------------------- SNIP -----------------------------
5077 Anything added to the cleanup chain beyond this point is assumed
5078 to be part of a breakpoint. If the breakpoint create goes
5079 through then that memory is not cleaned up. */
5080 breakpoint_chain = make_cleanup (null_cleanup, 0);
5082 /* Mark the contents of the addr_string for cleanup. These go on
5083 the breakpoint_chain and only occure if the breakpoint create
5085 for (i = 0; i < sals.nelts; i++)
5087 if (addr_string[i] != NULL)
5088 make_cleanup (xfree, addr_string[i]);
5091 /* Wait until now before checking for garbage at the end of the
5092 address. That way cleanups can take care of freeing any
5094 if (*address_end != '\0')
5095 error ("Garbage %s following breakpoint address", address_end);
5097 /* Resolve all line numbers to PC's. */
5098 breakpoint_sals_to_pc (&sals, args->address);
5100 /* Verify that conditions can be parsed, before setting any
5102 for (i = 0; i < sals.nelts; i++)
5104 if (args->condition != NULL)
5106 char *tok = args->condition;
5107 cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
5109 error ("Garbage %s follows condition", tok);
5110 make_cleanup (xfree, cond[i]);
5111 cond_string[i] = xstrdup (args->condition);
5115 create_breakpoints (sals, addr_string, cond, cond_string,
5116 args->hardwareflag ? bp_hardware_breakpoint : bp_breakpoint,
5117 args->tempflag ? disp_del : disp_donttouch,
5118 args->thread, args->ignore_count, 0/*from-tty*/);
5120 /* That's it. Discard the cleanups for data inserted into the
5122 discard_cleanups (breakpoint_chain);
5123 /* But cleanup everything else. */
5124 do_cleanups (old_chain);
5129 gdb_breakpoint (char *address, char *condition,
5130 int hardwareflag, int tempflag,
5131 int thread, int ignore_count)
5133 struct captured_breakpoint_args args;
5134 args.address = address;
5135 args.condition = condition;
5136 args.hardwareflag = hardwareflag;
5137 args.tempflag = tempflag;
5138 args.thread = thread;
5139 args.ignore_count = ignore_count;
5140 return catch_errors (do_captured_breakpoint, &args,
5141 NULL, RETURN_MASK_ALL);
5146 break_at_finish_at_depth_command_1 (char *arg, int flag, int from_tty)
5148 struct frame_info *frame;
5149 CORE_ADDR low, high, selected_pc = 0;
5150 char *extra_args = NULL;
5152 int extra_args_len = 0, if_arg = 0;
5155 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
5158 if (default_breakpoint_valid)
5160 if (deprecated_selected_frame)
5162 selected_pc = get_frame_pc (deprecated_selected_frame);
5167 error ("No selected frame.");
5170 error ("No default breakpoint address now.");
5174 extra_args = strchr (arg, ' ');
5178 extra_args_len = strlen (extra_args);
5179 level_arg = (char *) xmalloc (extra_args - arg);
5180 strncpy (level_arg, arg, extra_args - arg - 1);
5181 level_arg[extra_args - arg - 1] = '\0';
5185 level_arg = (char *) xmalloc (strlen (arg) + 1);
5186 strcpy (level_arg, arg);
5189 frame = parse_frame_specification (level_arg);
5191 selected_pc = get_frame_pc (frame);
5198 extra_args_len = strlen (arg);
5203 if (find_pc_partial_function (selected_pc, (char **) NULL, &low, &high))
5207 addr_string = xstrprintf ("*0x%s %s", paddr_nz (high), extra_args);
5209 addr_string = xstrprintf ("*0x%s", paddr_nz (high));
5210 break_command_1 (addr_string, flag, from_tty);
5211 xfree (addr_string);
5214 error ("No function contains the specified address");
5217 error ("Unable to set breakpoint at procedure exit");
5222 break_at_finish_command_1 (char *arg, int flag, int from_tty)
5224 char *addr_string, *break_string, *beg_addr_string;
5225 CORE_ADDR low, high;
5226 struct symtabs_and_lines sals;
5227 struct symtab_and_line sal;
5228 struct cleanup *old_chain;
5229 char *extra_args = NULL;
5230 int extra_args_len = 0;
5234 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
5236 if (default_breakpoint_valid)
5238 if (deprecated_selected_frame)
5240 addr_string = xstrprintf ("*0x%s",
5241 paddr_nz (get_frame_pc (deprecated_selected_frame)));
5246 error ("No selected frame.");
5249 error ("No default breakpoint address now.");
5253 addr_string = (char *) xmalloc (strlen (arg) + 1);
5254 strcpy (addr_string, arg);
5260 extra_args_len = strlen (arg);
5264 /* get the stuff after the function name or address */
5265 extra_args = strchr (arg, ' ');
5269 extra_args_len = strlen (extra_args);
5276 beg_addr_string = addr_string;
5277 sals = decode_line_1 (&addr_string, 1, (struct symtab *) NULL, 0,
5280 xfree (beg_addr_string);
5281 old_chain = make_cleanup (xfree, sals.sals);
5282 for (i = 0; (i < sals.nelts); i++)
5285 if (find_pc_partial_function (sal.pc, (char **) NULL, &low, &high))
5289 break_string = xstrprintf ("*0x%s %s", paddr_nz (high),
5292 break_string = xstrprintf ("*0x%s", paddr_nz (high));
5293 break_command_1 (break_string, flag, from_tty);
5294 xfree (break_string);
5297 error ("No function contains the specified address");
5301 warning ("Multiple breakpoints were set.\n");
5302 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
5304 do_cleanups (old_chain);
5308 /* Helper function for break_command_1 and disassemble_command. */
5311 resolve_sal_pc (struct symtab_and_line *sal)
5315 if (sal->pc == 0 && sal->symtab != NULL)
5317 if (!find_line_pc (sal->symtab, sal->line, &pc))
5318 error ("No line %d in file \"%s\".",
5319 sal->line, sal->symtab->filename);
5323 if (sal->section == 0 && sal->symtab != NULL)
5325 struct blockvector *bv;
5330 bv = blockvector_for_pc_sect (sal->pc, 0, &index, sal->symtab);
5333 b = BLOCKVECTOR_BLOCK (bv, index);
5334 sym = block_function (b);
5337 fixup_symbol_section (sym, sal->symtab->objfile);
5338 sal->section = SYMBOL_BFD_SECTION (sym);
5342 /* It really is worthwhile to have the section, so we'll just
5343 have to look harder. This case can be executed if we have
5344 line numbers but no functions (as can happen in assembly
5347 struct minimal_symbol *msym;
5349 msym = lookup_minimal_symbol_by_pc (sal->pc);
5351 sal->section = SYMBOL_BFD_SECTION (msym);
5358 break_command (char *arg, int from_tty)
5360 break_command_1 (arg, 0, from_tty);
5364 break_at_finish_command (char *arg, int from_tty)
5366 break_at_finish_command_1 (arg, 0, from_tty);
5370 break_at_finish_at_depth_command (char *arg, int from_tty)
5372 break_at_finish_at_depth_command_1 (arg, 0, from_tty);
5376 tbreak_command (char *arg, int from_tty)
5378 break_command_1 (arg, BP_TEMPFLAG, from_tty);
5382 tbreak_at_finish_command (char *arg, int from_tty)
5384 break_at_finish_command_1 (arg, BP_TEMPFLAG, from_tty);
5388 hbreak_command (char *arg, int from_tty)
5390 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
5394 thbreak_command (char *arg, int from_tty)
5396 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
5400 stop_command (char *arg, int from_tty)
5402 printf_filtered ("Specify the type of breakpoint to set.\n\
5403 Usage: stop in <function | address>\n\
5408 stopin_command (char *arg, int from_tty)
5412 if (arg == (char *) NULL)
5414 else if (*arg != '*')
5419 /* look for a ':'. If this is a line number specification, then
5420 say it is bad, otherwise, it should be an address or
5421 function/method name */
5422 while (*argptr && !hasColon)
5424 hasColon = (*argptr == ':');
5429 badInput = (*argptr != ':'); /* Not a class::method */
5431 badInput = isdigit (*arg); /* a simple line number */
5435 printf_filtered ("Usage: stop in <function | address>\n");
5437 break_command_1 (arg, 0, from_tty);
5441 stopat_command (char *arg, int from_tty)
5445 if (arg == (char *) NULL || *arg == '*') /* no line number */
5452 /* look for a ':'. If there is a '::' then get out, otherwise
5453 it is probably a line number. */
5454 while (*argptr && !hasColon)
5456 hasColon = (*argptr == ':');
5461 badInput = (*argptr == ':'); /* we have class::method */
5463 badInput = !isdigit (*arg); /* not a line number */
5467 printf_filtered ("Usage: stop at <line>\n");
5469 break_command_1 (arg, 0, from_tty);
5472 /* accessflag: hw_write: watch write,
5473 hw_read: watch read,
5474 hw_access: watch access (read or write) */
5476 watch_command_1 (char *arg, int accessflag, int from_tty)
5478 struct breakpoint *b;
5479 struct symtab_and_line sal;
5480 struct expression *exp;
5481 struct block *exp_valid_block;
5482 struct value *val, *mark;
5483 struct frame_info *frame;
5484 struct frame_info *prev_frame = NULL;
5485 char *exp_start = NULL;
5486 char *exp_end = NULL;
5487 char *tok, *end_tok;
5489 char *cond_start = NULL;
5490 char *cond_end = NULL;
5491 struct expression *cond = NULL;
5492 int i, other_type_used, target_resources_ok = 0;
5493 enum bptype bp_type;
5496 init_sal (&sal); /* initialize to zeroes */
5498 /* Parse arguments. */
5499 innermost_block = NULL;
5501 exp = parse_exp_1 (&arg, 0, 0);
5503 exp_valid_block = innermost_block;
5504 mark = value_mark ();
5505 val = evaluate_expression (exp);
5506 release_value (val);
5507 if (VALUE_LAZY (val))
5508 value_fetch_lazy (val);
5511 while (*tok == ' ' || *tok == '\t')
5515 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
5518 toklen = end_tok - tok;
5519 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
5521 tok = cond_start = end_tok + 1;
5522 cond = parse_exp_1 (&tok, 0, 0);
5526 error ("Junk at end of command.");
5528 if (accessflag == hw_read)
5529 bp_type = bp_read_watchpoint;
5530 else if (accessflag == hw_access)
5531 bp_type = bp_access_watchpoint;
5533 bp_type = bp_hardware_watchpoint;
5535 mem_cnt = can_use_hardware_watchpoint (val);
5536 if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
5537 error ("Expression cannot be implemented with read/access watchpoint.");
5540 i = hw_watchpoint_used_count (bp_type, &other_type_used);
5541 target_resources_ok =
5542 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type, i + mem_cnt,
5544 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
5545 error ("Target does not support this type of hardware watchpoint.");
5547 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
5548 error ("Target can only support one kind of HW watchpoint at a time.");
5551 #if defined(HPUXHPPA)
5552 /* On HP-UX if you set a h/w
5553 watchpoint before the "run" command, the inferior dies with a e.g.,
5554 SIGILL once you start it. I initially believed this was due to a
5555 bad interaction between page protection traps and the initial
5556 startup sequence by the dynamic linker.
5558 However, I tried avoiding that by having HP-UX's implementation of
5559 TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_ptid
5560 yet, which forced slow watches before a "run" or "attach", and it
5561 still fails somewhere in the startup code.
5563 Until I figure out what's happening, I'm disallowing watches altogether
5564 before the "run" or "attach" command. We'll tell the user they must
5565 set watches after getting the program started. */
5566 if (!target_has_execution)
5568 warning ("can't do that without a running program; try \"break main\", \"run\" first");
5571 #endif /* HPUXHPPA */
5573 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5574 watchpoint could not be set. */
5575 if (!mem_cnt || target_resources_ok <= 0)
5576 bp_type = bp_watchpoint;
5578 /* Now set up the breakpoint. */
5579 b = set_raw_breakpoint (sal, bp_type);
5580 set_breakpoint_count (breakpoint_count + 1);
5581 b->number = breakpoint_count;
5582 b->disposition = disp_donttouch;
5584 b->exp_valid_block = exp_valid_block;
5585 b->exp_string = savestring (exp_start, exp_end - exp_start);
5589 b->cond_string = savestring (cond_start, cond_end - cond_start);
5593 frame = block_innermost_frame (exp_valid_block);
5596 prev_frame = get_prev_frame (frame);
5597 b->watchpoint_frame = get_frame_id (frame);
5601 memset (&b->watchpoint_frame, 0, sizeof (b->watchpoint_frame));
5604 /* If the expression is "local", then set up a "watchpoint scope"
5605 breakpoint at the point where we've left the scope of the watchpoint
5607 if (innermost_block)
5611 struct breakpoint *scope_breakpoint;
5612 scope_breakpoint = create_internal_breakpoint (get_frame_pc (prev_frame),
5613 bp_watchpoint_scope);
5615 scope_breakpoint->enable_state = bp_enabled;
5617 /* Automatically delete the breakpoint when it hits. */
5618 scope_breakpoint->disposition = disp_del;
5620 /* Only break in the proper frame (help with recursion). */
5621 scope_breakpoint->frame_id = get_frame_id (prev_frame);
5623 /* Set the address at which we will stop. */
5624 scope_breakpoint->loc->requested_address
5625 = get_frame_pc (prev_frame);
5626 scope_breakpoint->loc->address
5627 = adjust_breakpoint_address (scope_breakpoint->loc->requested_address);
5629 /* The scope breakpoint is related to the watchpoint. We
5630 will need to act on them together. */
5631 b->related_breakpoint = scope_breakpoint;
5634 value_free_to_mark (mark);
5638 /* Return count of locations need to be watched and can be handled
5639 in hardware. If the watchpoint can not be handled
5640 in hardware return zero. */
5642 #if !defined(TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT)
5643 #define TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(BYTE_SIZE) \
5644 ((BYTE_SIZE) <= (DEPRECATED_REGISTER_SIZE))
5647 #if !defined(TARGET_REGION_OK_FOR_HW_WATCHPOINT)
5648 #define TARGET_REGION_OK_FOR_HW_WATCHPOINT(ADDR,LEN) \
5649 (TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(LEN))
5653 can_use_hardware_watchpoint (struct value *v)
5655 int found_memory_cnt = 0;
5656 struct value *head = v;
5658 /* Did the user specifically forbid us to use hardware watchpoints? */
5659 if (!can_use_hw_watchpoints)
5662 /* Make sure that the value of the expression depends only upon
5663 memory contents, and values computed from them within GDB. If we
5664 find any register references or function calls, we can't use a
5665 hardware watchpoint.
5667 The idea here is that evaluating an expression generates a series
5668 of values, one holding the value of every subexpression. (The
5669 expression a*b+c has five subexpressions: a, b, a*b, c, and
5670 a*b+c.) GDB's values hold almost enough information to establish
5671 the criteria given above --- they identify memory lvalues,
5672 register lvalues, computed values, etcetera. So we can evaluate
5673 the expression, and then scan the chain of values that leaves
5674 behind to decide whether we can detect any possible change to the
5675 expression's final value using only hardware watchpoints.
5677 However, I don't think that the values returned by inferior
5678 function calls are special in any way. So this function may not
5679 notice that an expression involving an inferior function call
5680 can't be watched with hardware watchpoints. FIXME. */
5681 for (; v; v = v->next)
5683 if (VALUE_LVAL (v) == lval_memory)
5686 /* A lazy memory lvalue is one that GDB never needed to fetch;
5687 we either just used its address (e.g., `a' in `a.b') or
5688 we never needed it at all (e.g., `a' in `a,b'). */
5692 /* Ahh, memory we actually used! Check if we can cover
5693 it with hardware watchpoints. */
5694 struct type *vtype = check_typedef (VALUE_TYPE (v));
5696 /* We only watch structs and arrays if user asked for it
5697 explicitly, never if they just happen to appear in a
5698 middle of some value chain. */
5700 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
5701 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
5703 CORE_ADDR vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
5704 int len = TYPE_LENGTH (VALUE_TYPE (v));
5706 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr, len))
5713 else if (v->lval != not_lval && v->modifiable == 0)
5714 return 0; /* ??? What does this represent? */
5715 else if (v->lval == lval_register)
5716 return 0; /* cannot watch a register with a HW watchpoint */
5719 /* The expression itself looks suitable for using a hardware
5720 watchpoint, but give the target machine a chance to reject it. */
5721 return found_memory_cnt;
5725 watch_command_wrapper (char *arg, int from_tty)
5727 watch_command (arg, from_tty);
5731 watch_command (char *arg, int from_tty)
5733 watch_command_1 (arg, hw_write, from_tty);
5737 rwatch_command_wrapper (char *arg, int from_tty)
5739 rwatch_command (arg, from_tty);
5743 rwatch_command (char *arg, int from_tty)
5745 watch_command_1 (arg, hw_read, from_tty);
5749 awatch_command_wrapper (char *arg, int from_tty)
5751 awatch_command (arg, from_tty);
5755 awatch_command (char *arg, int from_tty)
5757 watch_command_1 (arg, hw_access, from_tty);
5761 /* Helper routines for the until_command routine in infcmd.c. Here
5762 because it uses the mechanisms of breakpoints. */
5764 /* This function is called by fetch_inferior_event via the
5765 cmd_continuation pointer, to complete the until command. It takes
5766 care of cleaning up the temporary breakpoints set up by the until
5769 until_break_command_continuation (struct continuation_arg *arg)
5771 struct cleanup *cleanups;
5773 cleanups = (struct cleanup *) arg->data.pointer;
5774 do_exec_cleanups (cleanups);
5778 until_break_command (char *arg, int from_tty, int anywhere)
5780 struct symtabs_and_lines sals;
5781 struct symtab_and_line sal;
5782 struct frame_info *prev_frame = get_prev_frame (deprecated_selected_frame);
5783 struct breakpoint *breakpoint;
5784 struct cleanup *old_chain;
5785 struct continuation_arg *arg1;
5788 clear_proceed_status ();
5790 /* Set a breakpoint where the user wants it and at return from
5793 if (default_breakpoint_valid)
5794 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
5795 default_breakpoint_line, (char ***) NULL);
5797 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL,
5798 0, (char ***) NULL);
5800 if (sals.nelts != 1)
5801 error ("Couldn't get information on specified line.");
5804 xfree (sals.sals); /* malloc'd, so freed */
5807 error ("Junk at end of arguments.");
5809 resolve_sal_pc (&sal);
5812 /* If the user told us to continue until a specified location,
5813 we don't specify a frame at which we need to stop. */
5814 breakpoint = set_momentary_breakpoint (sal, null_frame_id, bp_until);
5816 /* Otherwise, specify the current frame, because we want to stop only
5817 at the very same frame. */
5818 breakpoint = set_momentary_breakpoint (sal,
5819 get_frame_id (deprecated_selected_frame),
5822 if (!event_loop_p || !target_can_async_p ())
5823 old_chain = make_cleanup_delete_breakpoint (breakpoint);
5825 old_chain = make_exec_cleanup_delete_breakpoint (breakpoint);
5827 /* If we are running asynchronously, and the target supports async
5828 execution, we are not waiting for the target to stop, in the call
5829 tp proceed, below. This means that we cannot delete the
5830 brekpoints until the target has actually stopped. The only place
5831 where we get a chance to do that is in fetch_inferior_event, so
5832 we must set things up for that. */
5834 if (event_loop_p && target_can_async_p ())
5836 /* In this case the arg for the continuation is just the point
5837 in the exec_cleanups chain from where to start doing
5838 cleanups, because all the continuation does is the cleanups in
5839 the exec_cleanup_chain. */
5841 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
5843 arg1->data.pointer = old_chain;
5845 add_continuation (until_break_command_continuation, arg1);
5848 /* Keep within the current frame, or in frames called by the current
5852 sal = find_pc_line (get_frame_pc (prev_frame), 0);
5853 sal.pc = get_frame_pc (prev_frame);
5854 breakpoint = set_momentary_breakpoint (sal, get_frame_id (prev_frame),
5856 if (!event_loop_p || !target_can_async_p ())
5857 make_cleanup_delete_breakpoint (breakpoint);
5859 make_exec_cleanup_delete_breakpoint (breakpoint);
5862 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
5863 /* Do the cleanups now, anly if we are not running asynchronously,
5864 of if we are, but the target is still synchronous. */
5865 if (!event_loop_p || !target_can_async_p ())
5866 do_cleanups (old_chain);
5870 /* These aren't used; I don't konw what they were for. */
5871 /* Set a breakpoint at the catch clause for NAME. */
5873 catch_breakpoint (char *name)
5878 disable_catch_breakpoint (void)
5883 delete_catch_breakpoint (void)
5888 enable_catch_breakpoint (void)
5894 ep_skip_leading_whitespace (char **s)
5896 if ((s == NULL) || (*s == NULL))
5898 while (isspace (**s))
5902 /* This function examines a string, and attempts to find a token
5903 that might be an event name in the leading characters. If a
5904 possible match is found, a pointer to the last character of
5905 the token is returned. Else, NULL is returned. */
5908 ep_find_event_name_end (char *arg)
5911 char *event_name_end = NULL;
5913 /* If we could depend upon the presense of strrpbrk, we'd use that... */
5917 /* We break out of the loop when we find a token delimiter.
5918 Basically, we're looking for alphanumerics and underscores;
5919 anything else delimites the token. */
5922 if (!isalnum (*s) && (*s != '_'))
5928 return event_name_end;
5932 /* This function attempts to parse an optional "if <cond>" clause
5933 from the arg string. If one is not found, it returns NULL.
5935 Else, it returns a pointer to the condition string. (It does not
5936 attempt to evaluate the string against a particular block.) And,
5937 it updates arg to point to the first character following the parsed
5938 if clause in the arg string. */
5941 ep_parse_optional_if_clause (char **arg)
5945 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
5948 /* Skip the "if" keyword. */
5951 /* Skip any extra leading whitespace, and record the start of the
5952 condition string. */
5953 ep_skip_leading_whitespace (arg);
5956 /* Assume that the condition occupies the remainder of the arg string. */
5957 (*arg) += strlen (cond_string);
5962 /* This function attempts to parse an optional filename from the arg
5963 string. If one is not found, it returns NULL.
5965 Else, it returns a pointer to the parsed filename. (This function
5966 makes no attempt to verify that a file of that name exists, or is
5967 accessible.) And, it updates arg to point to the first character
5968 following the parsed filename in the arg string.
5970 Note that clients needing to preserve the returned filename for
5971 future access should copy it to their own buffers. */
5973 ep_parse_optional_filename (char **arg)
5975 static char filename[1024];
5980 if ((*arg_p == '\0') || isspace (*arg_p))
5998 /* Commands to deal with catching events, such as signals, exceptions,
5999 process start/exit, etc. */
6003 catch_fork, catch_vfork
6007 #if defined(CHILD_INSERT_FORK_CATCHPOINT) || defined(CHILD_INSERT_VFORK_CATCHPOINT)
6008 static void catch_fork_command_1 (catch_fork_kind fork_kind,
6009 char *arg, int tempflag, int from_tty);
6012 catch_fork_command_1 (catch_fork_kind fork_kind, char *arg, int tempflag,
6015 char *cond_string = NULL;
6017 ep_skip_leading_whitespace (&arg);
6019 /* The allowed syntax is:
6021 catch [v]fork if <cond>
6023 First, check if there's an if clause. */
6024 cond_string = ep_parse_optional_if_clause (&arg);
6026 if ((*arg != '\0') && !isspace (*arg))
6027 error ("Junk at end of arguments.");
6029 /* If this target supports it, create a fork or vfork catchpoint
6030 and enable reporting of such events. */
6034 create_fork_event_catchpoint (tempflag, cond_string);
6037 create_vfork_event_catchpoint (tempflag, cond_string);
6040 error ("unsupported or unknown fork kind; cannot catch it");
6046 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
6048 catch_exec_command_1 (char *arg, int tempflag, int from_tty)
6050 char *cond_string = NULL;
6052 ep_skip_leading_whitespace (&arg);
6054 /* The allowed syntax is:
6056 catch exec if <cond>
6058 First, check if there's an if clause. */
6059 cond_string = ep_parse_optional_if_clause (&arg);
6061 if ((*arg != '\0') && !isspace (*arg))
6062 error ("Junk at end of arguments.");
6064 /* If this target supports it, create an exec catchpoint
6065 and enable reporting of such events. */
6066 create_exec_event_catchpoint (tempflag, cond_string);
6070 #if defined(SOLIB_ADD)
6072 catch_load_command_1 (char *arg, int tempflag, int from_tty)
6074 char *dll_pathname = NULL;
6075 char *cond_string = NULL;
6077 ep_skip_leading_whitespace (&arg);
6079 /* The allowed syntax is:
6081 catch load if <cond>
6082 catch load <filename>
6083 catch load <filename> if <cond>
6085 The user is not allowed to specify the <filename> after an
6088 We'll ignore the pathological case of a file named "if".
6090 First, check if there's an if clause. If so, then there
6091 cannot be a filename. */
6092 cond_string = ep_parse_optional_if_clause (&arg);
6094 /* If there was an if clause, then there cannot be a filename.
6095 Else, there might be a filename and an if clause. */
6096 if (cond_string == NULL)
6098 dll_pathname = ep_parse_optional_filename (&arg);
6099 ep_skip_leading_whitespace (&arg);
6100 cond_string = ep_parse_optional_if_clause (&arg);
6103 if ((*arg != '\0') && !isspace (*arg))
6104 error ("Junk at end of arguments.");
6106 /* Create a load breakpoint that only triggers when a load of
6107 the specified dll (or any dll, if no pathname was specified)
6109 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid), tempflag,
6110 dll_pathname, cond_string);
6114 catch_unload_command_1 (char *arg, int tempflag, int from_tty)
6116 char *dll_pathname = NULL;
6117 char *cond_string = NULL;
6119 ep_skip_leading_whitespace (&arg);
6121 /* The allowed syntax is:
6123 catch unload if <cond>
6124 catch unload <filename>
6125 catch unload <filename> if <cond>
6127 The user is not allowed to specify the <filename> after an
6130 We'll ignore the pathological case of a file named "if".
6132 First, check if there's an if clause. If so, then there
6133 cannot be a filename. */
6134 cond_string = ep_parse_optional_if_clause (&arg);
6136 /* If there was an if clause, then there cannot be a filename.
6137 Else, there might be a filename and an if clause. */
6138 if (cond_string == NULL)
6140 dll_pathname = ep_parse_optional_filename (&arg);
6141 ep_skip_leading_whitespace (&arg);
6142 cond_string = ep_parse_optional_if_clause (&arg);
6145 if ((*arg != '\0') && !isspace (*arg))
6146 error ("Junk at end of arguments.");
6148 /* Create an unload breakpoint that only triggers when an unload of
6149 the specified dll (or any dll, if no pathname was specified)
6151 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid), tempflag,
6152 dll_pathname, cond_string);
6154 #endif /* SOLIB_ADD */
6156 /* Commands to deal with catching exceptions. */
6158 /* Set a breakpoint at the specified callback routine for an
6159 exception event callback */
6162 create_exception_catchpoint (int tempflag, char *cond_string,
6163 enum exception_event_kind ex_event,
6164 struct symtab_and_line *sal)
6166 struct breakpoint *b;
6167 int thread = -1; /* All threads. */
6170 if (!sal) /* no exception support? */
6175 case EX_EVENT_THROW:
6176 bptype = bp_catch_throw;
6178 case EX_EVENT_CATCH:
6179 bptype = bp_catch_catch;
6181 default: /* error condition */
6182 error ("Internal error -- invalid catchpoint kind");
6185 b = set_raw_breakpoint (*sal, bptype);
6186 set_breakpoint_count (breakpoint_count + 1);
6187 b->number = breakpoint_count;
6189 b->cond_string = (cond_string == NULL) ?
6190 NULL : savestring (cond_string, strlen (cond_string));
6192 b->addr_string = NULL;
6193 b->enable_state = bp_enabled;
6194 b->disposition = tempflag ? disp_del : disp_donttouch;
6198 static enum print_stop_action
6199 print_exception_catchpoint (struct breakpoint *b)
6201 annotate_catchpoint (b->number);
6203 if (strstr (b->addr_string, "throw") != NULL)
6204 printf_filtered ("\nCatchpoint %d (exception thrown)\n",
6207 printf_filtered ("\nCatchpoint %d (exception caught)\n",
6210 return PRINT_SRC_AND_LOC;
6214 print_one_exception_catchpoint (struct breakpoint *b, CORE_ADDR *last_addr)
6219 ui_out_field_core_addr (uiout, "addr", b->loc->address);
6222 *last_addr = b->loc->address;
6223 if (strstr (b->addr_string, "throw") != NULL)
6224 ui_out_field_string (uiout, "what", "exception throw");
6226 ui_out_field_string (uiout, "what", "exception catch");
6230 print_mention_exception_catchpoint (struct breakpoint *b)
6232 if (strstr (b->addr_string, "throw") != NULL)
6233 printf_filtered ("Catchpoint %d (throw)", b->number);
6235 printf_filtered ("Catchpoint %d (catch)", b->number);
6238 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = {
6239 print_exception_catchpoint,
6240 print_one_exception_catchpoint,
6241 print_mention_exception_catchpoint
6245 handle_gnu_v3_exceptions (int tempflag, char *cond_string,
6246 enum exception_event_kind ex_event, int from_tty)
6248 char *trigger_func_name, *nameptr;
6249 struct symtabs_and_lines sals;
6250 struct breakpoint *b;
6252 if (ex_event == EX_EVENT_CATCH)
6253 trigger_func_name = xstrdup ("__cxa_begin_catch");
6255 trigger_func_name = xstrdup ("__cxa_throw");
6257 nameptr = trigger_func_name;
6258 sals = decode_line_1 (&nameptr, 1, NULL, 0, NULL);
6259 if (sals.nelts == 0)
6261 xfree (trigger_func_name);
6265 b = set_raw_breakpoint (sals.sals[0], bp_breakpoint);
6266 set_breakpoint_count (breakpoint_count + 1);
6267 b->number = breakpoint_count;
6269 b->cond_string = (cond_string == NULL) ?
6270 NULL : savestring (cond_string, strlen (cond_string));
6272 b->addr_string = trigger_func_name;
6273 b->enable_state = bp_enabled;
6274 b->disposition = tempflag ? disp_del : disp_donttouch;
6275 b->ops = &gnu_v3_exception_catchpoint_ops;
6282 /* Deal with "catch catch" and "catch throw" commands */
6285 catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
6286 int tempflag, int from_tty)
6288 char *cond_string = NULL;
6289 struct symtab_and_line *sal = NULL;
6291 ep_skip_leading_whitespace (&arg);
6293 cond_string = ep_parse_optional_if_clause (&arg);
6295 if ((*arg != '\0') && !isspace (*arg))
6296 error ("Junk at end of arguments.");
6298 if ((ex_event != EX_EVENT_THROW) &&
6299 (ex_event != EX_EVENT_CATCH))
6300 error ("Unsupported or unknown exception event; cannot catch it");
6302 if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty))
6305 /* See if we can find a callback routine */
6306 sal = target_enable_exception_callback (ex_event, 1);
6310 /* We have callbacks from the runtime system for exceptions.
6311 Set a breakpoint on the sal found, if no errors */
6312 if (sal != (struct symtab_and_line *) -1)
6313 create_exception_catchpoint (tempflag, cond_string, ex_event, sal);
6315 return; /* something went wrong with setting up callbacks */
6318 warning ("Unsupported with this platform/compiler combination.");
6321 /* Cover routine to allow wrapping target_enable_exception_catchpoints
6322 inside a catch_errors */
6325 cover_target_enable_exception_callback (void *arg)
6327 args_for_catchpoint_enable *args = arg;
6328 struct symtab_and_line *sal;
6329 sal = target_enable_exception_callback (args->kind, args->enable_p);
6332 else if (sal == (struct symtab_and_line *) -1)
6335 return 1; /*is valid */
6339 catch_command_1 (char *arg, int tempflag, int from_tty)
6342 /* The first argument may be an event name, such as "start" or "load".
6343 If so, then handle it as such. If it doesn't match an event name,
6344 then attempt to interpret it as an exception name. (This latter is
6345 the v4.16-and-earlier GDB meaning of the "catch" command.)
6347 First, try to find the bounds of what might be an event name. */
6348 char *arg1_start = arg;
6352 if (arg1_start == NULL)
6354 /* Old behaviour was to use pre-v-4.16 syntax */
6355 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6357 /* Now, this is not allowed */
6358 error ("Catch requires an event name.");
6361 arg1_end = ep_find_event_name_end (arg1_start);
6362 if (arg1_end == NULL)
6363 error ("catch requires an event");
6364 arg1_length = arg1_end + 1 - arg1_start;
6366 /* Try to match what we found against known event names. */
6367 if (strncmp (arg1_start, "signal", arg1_length) == 0)
6369 error ("Catch of signal not yet implemented");
6371 else if (strncmp (arg1_start, "catch", arg1_length) == 0)
6373 catch_exception_command_1 (EX_EVENT_CATCH, arg1_end + 1,
6374 tempflag, from_tty);
6376 else if (strncmp (arg1_start, "throw", arg1_length) == 0)
6378 catch_exception_command_1 (EX_EVENT_THROW, arg1_end + 1,
6379 tempflag, from_tty);
6381 else if (strncmp (arg1_start, "thread_start", arg1_length) == 0)
6383 error ("Catch of thread_start not yet implemented");
6385 else if (strncmp (arg1_start, "thread_exit", arg1_length) == 0)
6387 error ("Catch of thread_exit not yet implemented");
6389 else if (strncmp (arg1_start, "thread_join", arg1_length) == 0)
6391 error ("Catch of thread_join not yet implemented");
6393 else if (strncmp (arg1_start, "start", arg1_length) == 0)
6395 error ("Catch of start not yet implemented");
6397 else if (strncmp (arg1_start, "exit", arg1_length) == 0)
6399 error ("Catch of exit not yet implemented");
6401 else if (strncmp (arg1_start, "fork", arg1_length) == 0)
6403 #if defined(CHILD_INSERT_FORK_CATCHPOINT)
6404 catch_fork_command_1 (catch_fork, arg1_end + 1, tempflag, from_tty);
6406 error ("Catch of fork not yet implemented");
6409 else if (strncmp (arg1_start, "vfork", arg1_length) == 0)
6411 #if defined(CHILD_INSERT_VFORK_CATCHPOINT)
6412 catch_fork_command_1 (catch_vfork, arg1_end + 1, tempflag, from_tty);
6414 error ("Catch of vfork not yet implemented");
6417 else if (strncmp (arg1_start, "exec", arg1_length) == 0)
6419 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
6420 catch_exec_command_1 (arg1_end + 1, tempflag, from_tty);
6422 error ("Catch of exec not yet implemented");
6425 else if (strncmp (arg1_start, "load", arg1_length) == 0)
6427 #if defined(SOLIB_ADD)
6428 catch_load_command_1 (arg1_end + 1, tempflag, from_tty);
6430 error ("Catch of load not implemented");
6433 else if (strncmp (arg1_start, "unload", arg1_length) == 0)
6435 #if defined(SOLIB_ADD)
6436 catch_unload_command_1 (arg1_end + 1, tempflag, from_tty);
6438 error ("Catch of load not implemented");
6441 else if (strncmp (arg1_start, "stop", arg1_length) == 0)
6443 error ("Catch of stop not yet implemented");
6446 /* This doesn't appear to be an event name */
6450 /* Pre-v.4.16 behaviour was to treat the argument
6451 as the name of an exception */
6452 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6453 /* Now this is not allowed */
6454 error ("Unknown event kind specified for catch");
6459 /* Used by the gui, could be made a worker for other things. */
6462 set_breakpoint_sal (struct symtab_and_line sal)
6464 struct breakpoint *b;
6465 b = set_raw_breakpoint (sal, bp_breakpoint);
6466 set_breakpoint_count (breakpoint_count + 1);
6467 b->number = breakpoint_count;
6474 /* These aren't used; I don't know what they were for. */
6475 /* Disable breakpoints on all catch clauses described in ARGS. */
6477 disable_catch (char *args)
6479 /* Map the disable command to catch clauses described in ARGS. */
6482 /* Enable breakpoints on all catch clauses described in ARGS. */
6484 enable_catch (char *args)
6486 /* Map the disable command to catch clauses described in ARGS. */
6489 /* Delete breakpoints on all catch clauses in the active scope. */
6491 delete_catch (char *args)
6493 /* Map the delete command to catch clauses described in ARGS. */
6498 catch_command (char *arg, int from_tty)
6500 catch_command_1 (arg, 0, from_tty);
6505 tcatch_command (char *arg, int from_tty)
6507 catch_command_1 (arg, 1, from_tty);
6510 /* Delete breakpoints by address or line. */
6513 clear_command (char *arg, int from_tty)
6515 struct breakpoint *b, *tmp, *prev, *found;
6517 struct symtabs_and_lines sals;
6518 struct symtab_and_line sal;
6523 sals = decode_line_spec (arg, 1);
6528 sals.sals = (struct symtab_and_line *)
6529 xmalloc (sizeof (struct symtab_and_line));
6530 make_cleanup (xfree, sals.sals);
6531 init_sal (&sal); /* initialize to zeroes */
6532 sal.line = default_breakpoint_line;
6533 sal.symtab = default_breakpoint_symtab;
6534 sal.pc = default_breakpoint_address;
6535 if (sal.symtab == 0)
6536 error ("No source file specified.");
6544 /* For each line spec given, delete bps which correspond
6545 to it. Do it in two passes, solely to preserve the current
6546 behavior that from_tty is forced true if we delete more than
6550 for (i = 0; i < sals.nelts; i++)
6552 /* If exact pc given, clear bpts at that pc.
6553 If line given (pc == 0), clear all bpts on specified line.
6554 If defaulting, clear all bpts on default line
6557 defaulting sal.pc != 0 tests to do
6562 1 0 <can't happen> */
6567 /* Find all matching breakpoints, remove them from the
6568 breakpoint chain, and add them to the 'found' chain. */
6569 ALL_BREAKPOINTS_SAFE (b, tmp)
6571 /* Are we going to delete b? */
6572 if (b->type != bp_none
6573 && b->type != bp_watchpoint
6574 && b->type != bp_hardware_watchpoint
6575 && b->type != bp_read_watchpoint
6576 && b->type != bp_access_watchpoint
6577 /* Not if b is a watchpoint of any sort... */
6578 && (((sal.pc && (b->loc->address == sal.pc))
6579 && (!section_is_overlay (b->loc->section)
6580 || b->loc->section == sal.section))
6581 /* Yes, if sal.pc matches b (modulo overlays). */
6582 || ((default_match || (0 == sal.pc))
6583 && b->source_file != NULL
6584 && sal.symtab != NULL
6585 && STREQ (b->source_file, sal.symtab->filename)
6586 && b->line_number == sal.line)))
6587 /* Yes, if sal source file and line matches b. */
6589 /* Remove it from breakpoint_chain... */
6590 if (b == breakpoint_chain)
6592 /* b is at the head of the list */
6593 breakpoint_chain = b->next;
6597 prev->next = b->next;
6599 /* And add it to 'found' chain. */
6605 /* Keep b, and keep a pointer to it. */
6610 /* Now go thru the 'found' chain and delete them. */
6614 error ("No breakpoint at %s.", arg);
6616 error ("No breakpoint at this line.");
6620 from_tty = 1; /* Always report if deleted more than one */
6622 printf_unfiltered ("Deleted breakpoint%s ", found->next ? "s" : "");
6623 breakpoints_changed ();
6627 printf_unfiltered ("%d ", found->number);
6629 delete_breakpoint (found);
6633 putchar_unfiltered ('\n');
6636 /* Delete breakpoint in BS if they are `delete' breakpoints and
6637 all breakpoints that are marked for deletion, whether hit or not.
6638 This is called after any breakpoint is hit, or after errors. */
6641 breakpoint_auto_delete (bpstat bs)
6643 struct breakpoint *b, *temp;
6645 for (; bs; bs = bs->next)
6646 if (bs->breakpoint_at && bs->breakpoint_at->disposition == disp_del
6648 delete_breakpoint (bs->breakpoint_at);
6650 ALL_BREAKPOINTS_SAFE (b, temp)
6652 if (b->disposition == disp_del_at_next_stop)
6653 delete_breakpoint (b);
6657 /* Delete a breakpoint and clean up all traces of it in the data
6661 delete_breakpoint (struct breakpoint *bpt)
6663 struct breakpoint *b;
6665 struct bp_location *loc;
6668 error ("Internal error (attempted to delete a NULL breakpoint)");
6671 /* Has this bp already been deleted? This can happen because multiple
6672 lists can hold pointers to bp's. bpstat lists are especial culprits.
6674 One example of this happening is a watchpoint's scope bp. When the
6675 scope bp triggers, we notice that the watchpoint is out of scope, and
6676 delete it. We also delete its scope bp. But the scope bp is marked
6677 "auto-deleting", and is already on a bpstat. That bpstat is then
6678 checked for auto-deleting bp's, which are deleted.
6680 A real solution to this problem might involve reference counts in bp's,
6681 and/or giving them pointers back to their referencing bpstat's, and
6682 teaching delete_breakpoint to only free a bp's storage when no more
6683 references were extent. A cheaper bandaid was chosen. */
6684 if (bpt->type == bp_none)
6687 if (delete_breakpoint_hook)
6688 delete_breakpoint_hook (bpt);
6689 breakpoint_delete_event (bpt->number);
6691 if (bpt->loc->inserted)
6692 remove_breakpoint (bpt, mark_inserted);
6694 if (breakpoint_chain == bpt)
6695 breakpoint_chain = bpt->next;
6697 if (bp_location_chain == bpt->loc)
6698 bp_location_chain = bpt->loc->next;
6700 /* If we have callback-style exception catchpoints, don't go through
6701 the adjustments to the C++ runtime library etc. if the inferior
6702 isn't actually running. target_enable_exception_callback for a
6703 null target ops vector gives an undesirable error message, so we
6704 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
6705 exceptions are supported in this way, it's OK for now. FIXME */
6706 if (ep_is_exception_catchpoint (bpt) && target_has_execution)
6708 /* Format possible error msg */
6709 char *message = xstrprintf ("Error in deleting catchpoint %d:\n",
6711 struct cleanup *cleanups = make_cleanup (xfree, message);
6712 args_for_catchpoint_enable args;
6713 args.kind = bpt->type == bp_catch_catch ?
6714 EX_EVENT_CATCH : EX_EVENT_THROW;
6716 catch_errors (cover_target_enable_exception_callback, &args,
6717 message, RETURN_MASK_ALL);
6718 do_cleanups (cleanups);
6725 b->next = bpt->next;
6729 ALL_BP_LOCATIONS (loc)
6730 if (loc->next == bpt->loc)
6732 loc->next = bpt->loc->next;
6736 check_duplicates (bpt);
6737 /* If this breakpoint was inserted, and there is another breakpoint
6738 at the same address, we need to insert the other breakpoint. */
6739 if (bpt->loc->inserted
6740 && bpt->type != bp_hardware_watchpoint
6741 && bpt->type != bp_read_watchpoint
6742 && bpt->type != bp_access_watchpoint
6743 && bpt->type != bp_catch_fork
6744 && bpt->type != bp_catch_vfork
6745 && bpt->type != bp_catch_exec)
6748 if (b->loc->address == bpt->loc->address
6749 && b->loc->section == bpt->loc->section
6750 && !b->loc->duplicate
6751 && b->enable_state != bp_disabled
6752 && b->enable_state != bp_shlib_disabled
6753 && b->enable_state != bp_call_disabled)
6757 /* We should never reach this point if there is a permanent
6758 breakpoint at the same address as the one being deleted.
6759 If there is a permanent breakpoint somewhere, it should
6760 always be the only one inserted. */
6761 if (b->enable_state == bp_permanent)
6762 internal_error (__FILE__, __LINE__,
6763 "another breakpoint was inserted on top of "
6764 "a permanent breakpoint");
6766 if (b->type == bp_hardware_breakpoint)
6767 val = target_insert_hw_breakpoint (b->loc->address, b->loc->shadow_contents);
6769 val = target_insert_breakpoint (b->loc->address, b->loc->shadow_contents);
6771 /* If there was an error in the insert, print a message, then stop execution. */
6774 struct ui_file *tmp_error_stream = mem_fileopen ();
6775 make_cleanup_ui_file_delete (tmp_error_stream);
6778 if (b->type == bp_hardware_breakpoint)
6780 fprintf_unfiltered (tmp_error_stream,
6781 "Cannot insert hardware breakpoint %d.\n"
6782 "You may have requested too many hardware breakpoints.\n",
6787 fprintf_unfiltered (tmp_error_stream, "Cannot insert breakpoint %d.\n", b->number);
6788 fprintf_filtered (tmp_error_stream, "Error accessing memory address ");
6789 print_address_numeric (b->loc->address, 1, tmp_error_stream);
6790 fprintf_filtered (tmp_error_stream, ": %s.\n",
6791 safe_strerror (val));
6794 fprintf_unfiltered (tmp_error_stream,"The same program may be running in another process.");
6795 target_terminal_ours_for_output ();
6796 error_stream(tmp_error_stream);
6799 b->loc->inserted = 1;
6803 free_command_lines (&bpt->commands);
6806 if (bpt->cond_string != NULL)
6807 xfree (bpt->cond_string);
6808 if (bpt->addr_string != NULL)
6809 xfree (bpt->addr_string);
6810 if (bpt->exp != NULL)
6812 if (bpt->exp_string != NULL)
6813 xfree (bpt->exp_string);
6814 if (bpt->val != NULL)
6815 value_free (bpt->val);
6816 if (bpt->source_file != NULL)
6817 xfree (bpt->source_file);
6818 if (bpt->dll_pathname != NULL)
6819 xfree (bpt->dll_pathname);
6820 if (bpt->triggered_dll_pathname != NULL)
6821 xfree (bpt->triggered_dll_pathname);
6822 if (bpt->exec_pathname != NULL)
6823 xfree (bpt->exec_pathname);
6825 /* Be sure no bpstat's are pointing at it after it's been freed. */
6826 /* FIXME, how can we find all bpstat's?
6827 We just check stop_bpstat for now. */
6828 for (bs = stop_bpstat; bs; bs = bs->next)
6829 if (bs->breakpoint_at == bpt)
6831 bs->breakpoint_at = NULL;
6833 /* bs->commands will be freed later. */
6835 /* On the chance that someone will soon try again to delete this same
6836 bp, we mark it as deleted before freeing its storage. */
6837 bpt->type = bp_none;
6844 do_delete_breakpoint_cleanup (void *b)
6846 delete_breakpoint (b);
6850 make_cleanup_delete_breakpoint (struct breakpoint *b)
6852 return make_cleanup (do_delete_breakpoint_cleanup, b);
6856 make_exec_cleanup_delete_breakpoint (struct breakpoint *b)
6858 return make_exec_cleanup (do_delete_breakpoint_cleanup, b);
6862 delete_command (char *arg, int from_tty)
6864 struct breakpoint *b, *temp;
6870 int breaks_to_delete = 0;
6872 /* Delete all breakpoints if no argument.
6873 Do not delete internal or call-dummy breakpoints, these
6874 have to be deleted with an explicit breakpoint number argument. */
6877 if (b->type != bp_call_dummy &&
6878 b->type != bp_shlib_event &&
6879 b->type != bp_thread_event &&
6880 b->type != bp_overlay_event &&
6882 breaks_to_delete = 1;
6885 /* Ask user only if there are some breakpoints to delete. */
6887 || (breaks_to_delete && query ("Delete all breakpoints? ")))
6889 ALL_BREAKPOINTS_SAFE (b, temp)
6891 if (b->type != bp_call_dummy &&
6892 b->type != bp_shlib_event &&
6893 b->type != bp_thread_event &&
6894 b->type != bp_overlay_event &&
6896 delete_breakpoint (b);
6901 map_breakpoint_numbers (arg, delete_breakpoint);
6904 /* Reset a breakpoint given it's struct breakpoint * BINT.
6905 The value we return ends up being the return value from catch_errors.
6906 Unused in this case. */
6909 breakpoint_re_set_one (void *bint)
6911 /* get past catch_errs */
6912 struct breakpoint *b = (struct breakpoint *) bint;
6915 struct symtabs_and_lines sals;
6917 enum enable_state save_enable;
6922 warning ("attempted to reset apparently deleted breakpoint #%d?",
6926 case bp_hardware_breakpoint:
6928 case bp_catch_unload:
6929 if (b->addr_string == NULL)
6931 /* Anything without a string can't be re-set. */
6932 delete_breakpoint (b);
6935 /* HACK: cagney/2001-11-11: kettenis/2001-11-11: MarkK wrote:
6937 ``And a hack it is, although Apple's Darwin version of GDB
6938 contains an almost identical hack to implement a "future
6939 break" command. It seems to work in many real world cases,
6940 but it is easy to come up with a test case where the patch
6941 doesn't help at all.''
6943 ``It seems that the way GDB implements breakpoints - in -
6944 shared - libraries was designed for a.out shared library
6945 systems (SunOS 4) where shared libraries were loaded at a
6946 fixed address in memory. Since ELF shared libraries can (and
6947 will) be loaded at any address in memory, things break.
6948 Fixing this is not trivial. Therefore, I'm not sure whether
6949 we should add this hack to the branch only. I cannot
6950 guarantee that things will be fixed on the trunk in the near
6953 In case we have a problem, disable this breakpoint. We'll
6954 restore its status if we succeed. Don't disable a
6955 shlib_disabled breakpoint though. There's a fair chance we
6956 can't re-set it if the shared library it's in hasn't been
6958 save_enable = b->enable_state;
6959 if (b->enable_state != bp_shlib_disabled)
6960 b->enable_state = bp_disabled;
6962 set_language (b->language);
6963 input_radix = b->input_radix;
6965 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL);
6966 for (i = 0; i < sals.nelts; i++)
6968 resolve_sal_pc (&sals.sals[i]);
6970 /* Reparse conditions, they might contain references to the
6972 if (b->cond_string != NULL)
6977 b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0);
6980 /* We need to re-set the breakpoint if the address changes... */
6981 if (b->loc->address != sals.sals[i].pc
6982 /* ...or new and old breakpoints both have source files, and
6983 the source file name or the line number changes... */
6984 || (b->source_file != NULL
6985 && sals.sals[i].symtab != NULL
6986 && (!STREQ (b->source_file, sals.sals[i].symtab->filename)
6987 || b->line_number != sals.sals[i].line)
6989 /* ...or we switch between having a source file and not having
6991 || ((b->source_file == NULL) != (sals.sals[i].symtab == NULL))
6994 if (b->source_file != NULL)
6995 xfree (b->source_file);
6996 if (sals.sals[i].symtab == NULL)
6997 b->source_file = NULL;
7000 savestring (sals.sals[i].symtab->filename,
7001 strlen (sals.sals[i].symtab->filename));
7002 b->line_number = sals.sals[i].line;
7003 b->loc->requested_address = sals.sals[i].pc;
7005 = adjust_breakpoint_address (b->loc->requested_address);
7007 /* Used to check for duplicates here, but that can
7008 cause trouble, as it doesn't check for disabled
7013 /* Might be better to do this just once per breakpoint_re_set,
7014 rather than once for every breakpoint. */
7015 breakpoints_changed ();
7017 b->loc->section = sals.sals[i].section;
7018 b->enable_state = save_enable; /* Restore it, this worked. */
7021 /* Now that this is re-enabled, check_duplicates
7023 check_duplicates (b);
7030 case bp_hardware_watchpoint:
7031 case bp_read_watchpoint:
7032 case bp_access_watchpoint:
7033 innermost_block = NULL;
7034 /* The issue arises of what context to evaluate this in. The
7035 same one as when it was set, but what does that mean when
7036 symbols have been re-read? We could save the filename and
7037 functionname, but if the context is more local than that, the
7038 best we could do would be something like how many levels deep
7039 and which index at that particular level, but that's going to
7040 be less stable than filenames or function names. */
7042 /* So for now, just use a global context. */
7045 b->exp = parse_expression (b->exp_string);
7046 b->exp_valid_block = innermost_block;
7047 mark = value_mark ();
7049 value_free (b->val);
7050 b->val = evaluate_expression (b->exp);
7051 release_value (b->val);
7052 if (VALUE_LAZY (b->val) && b->enable_state == bp_enabled)
7053 value_fetch_lazy (b->val);
7055 if (b->cond_string != NULL)
7060 b->cond = parse_exp_1 (&s, (struct block *) 0, 0);
7062 if (b->enable_state == bp_enabled)
7064 value_free_to_mark (mark);
7066 case bp_catch_catch:
7067 case bp_catch_throw:
7069 /* We needn't really do anything to reset these, since the mask
7070 that requests them is unaffected by e.g., new libraries being
7073 case bp_catch_vfork:
7078 printf_filtered ("Deleting unknown breakpoint type %d\n", b->type);
7080 /* Delete longjmp and overlay event breakpoints; they will be
7081 reset later by breakpoint_re_set. */
7083 case bp_longjmp_resume:
7084 case bp_overlay_event:
7085 delete_breakpoint (b);
7088 /* This breakpoint is special, it's set up when the inferior
7089 starts and we really don't want to touch it. */
7090 case bp_shlib_event:
7092 /* Like bp_shlib_event, this breakpoint type is special.
7093 Once it is set up, we do not want to touch it. */
7094 case bp_thread_event:
7096 /* Keep temporary breakpoints, which can be encountered when we step
7097 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7098 Otherwise these should have been blown away via the cleanup chain
7099 or by breakpoint_init_inferior when we rerun the executable. */
7102 case bp_watchpoint_scope:
7104 case bp_step_resume:
7111 /* Re-set all breakpoints after symbols have been re-loaded. */
7113 breakpoint_re_set (void)
7115 struct breakpoint *b, *temp;
7116 enum language save_language;
7117 int save_input_radix;
7119 save_language = current_language->la_language;
7120 save_input_radix = input_radix;
7121 ALL_BREAKPOINTS_SAFE (b, temp)
7123 /* Format possible error msg */
7124 char *message = xstrprintf ("Error in re-setting breakpoint %d:\n",
7126 struct cleanup *cleanups = make_cleanup (xfree, message);
7127 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
7128 do_cleanups (cleanups);
7130 set_language (save_language);
7131 input_radix = save_input_radix;
7133 if (GET_LONGJMP_TARGET_P ())
7135 create_longjmp_breakpoint ("longjmp");
7136 create_longjmp_breakpoint ("_longjmp");
7137 create_longjmp_breakpoint ("siglongjmp");
7138 create_longjmp_breakpoint ("_siglongjmp");
7139 create_longjmp_breakpoint (NULL);
7142 create_overlay_event_breakpoint ("_ovly_debug_event");
7145 /* Reset the thread number of this breakpoint:
7147 - If the breakpoint is for all threads, leave it as-is.
7148 - Else, reset it to the current thread for inferior_ptid. */
7150 breakpoint_re_set_thread (struct breakpoint *b)
7152 if (b->thread != -1)
7154 if (in_thread_list (inferior_ptid))
7155 b->thread = pid_to_thread_id (inferior_ptid);
7159 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7160 If from_tty is nonzero, it prints a message to that effect,
7161 which ends with a period (no newline). */
7164 set_ignore_count (int bptnum, int count, int from_tty)
7166 struct breakpoint *b;
7172 if (b->number == bptnum)
7174 b->ignore_count = count;
7178 printf_filtered ("Will stop next time breakpoint %d is reached.",
7180 else if (count == 1)
7181 printf_filtered ("Will ignore next crossing of breakpoint %d.",
7184 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
7187 breakpoints_changed ();
7188 breakpoint_modify_event (b->number);
7192 error ("No breakpoint number %d.", bptnum);
7195 /* Clear the ignore counts of all breakpoints. */
7197 breakpoint_clear_ignore_counts (void)
7199 struct breakpoint *b;
7202 b->ignore_count = 0;
7205 /* Command to set ignore-count of breakpoint N to COUNT. */
7208 ignore_command (char *args, int from_tty)
7214 error_no_arg ("a breakpoint number");
7216 num = get_number (&p);
7218 error ("bad breakpoint number: '%s'", args);
7220 error ("Second argument (specified ignore-count) is missing.");
7222 set_ignore_count (num,
7223 longest_to_int (value_as_long (parse_and_eval (p))),
7226 printf_filtered ("\n");
7229 /* Call FUNCTION on each of the breakpoints
7230 whose numbers are given in ARGS. */
7233 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *))
7238 struct breakpoint *b, *tmp;
7242 error_no_arg ("one or more breakpoint numbers");
7249 num = get_number_or_range (&p1);
7252 warning ("bad breakpoint number at or near '%s'", p);
7256 ALL_BREAKPOINTS_SAFE (b, tmp)
7257 if (b->number == num)
7259 struct breakpoint *related_breakpoint = b->related_breakpoint;
7262 if (related_breakpoint)
7263 function (related_breakpoint);
7267 printf_unfiltered ("No breakpoint number %d.\n", num);
7273 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7274 If from_tty is nonzero, it prints a message to that effect,
7275 which ends with a period (no newline). */
7278 disable_breakpoint (struct breakpoint *bpt)
7280 /* Never disable a watchpoint scope breakpoint; we want to
7281 hit them when we leave scope so we can delete both the
7282 watchpoint and its scope breakpoint at that time. */
7283 if (bpt->type == bp_watchpoint_scope)
7286 /* You can't disable permanent breakpoints. */
7287 if (bpt->enable_state == bp_permanent)
7290 bpt->enable_state = bp_disabled;
7292 check_duplicates (bpt);
7294 if (modify_breakpoint_hook)
7295 modify_breakpoint_hook (bpt);
7296 breakpoint_modify_event (bpt->number);
7300 disable_command (char *args, int from_tty)
7302 struct breakpoint *bpt;
7304 ALL_BREAKPOINTS (bpt)
7308 warning ("attempted to disable apparently deleted breakpoint #%d?",
7313 case bp_catch_unload:
7315 case bp_catch_vfork:
7317 case bp_catch_catch:
7318 case bp_catch_throw:
7319 case bp_hardware_breakpoint:
7321 case bp_hardware_watchpoint:
7322 case bp_read_watchpoint:
7323 case bp_access_watchpoint:
7324 disable_breakpoint (bpt);
7329 map_breakpoint_numbers (args, disable_breakpoint);
7333 do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition)
7335 struct frame_info *save_selected_frame = NULL;
7336 int save_selected_frame_level = -1;
7337 int target_resources_ok, other_type_used;
7340 if (bpt->type == bp_hardware_breakpoint)
7343 i = hw_breakpoint_used_count ();
7344 target_resources_ok =
7345 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
7347 if (target_resources_ok == 0)
7348 error ("No hardware breakpoint support in the target.");
7349 else if (target_resources_ok < 0)
7350 error ("Hardware breakpoints used exceeds limit.");
7353 if (bpt->enable_state != bp_permanent)
7354 bpt->enable_state = bp_enabled;
7355 bpt->disposition = disposition;
7356 check_duplicates (bpt);
7357 breakpoints_changed ();
7359 if (bpt->type == bp_watchpoint ||
7360 bpt->type == bp_hardware_watchpoint ||
7361 bpt->type == bp_read_watchpoint ||
7362 bpt->type == bp_access_watchpoint)
7364 if (bpt->exp_valid_block != NULL)
7366 struct frame_info *fr =
7367 fr = frame_find_by_id (bpt->watchpoint_frame);
7371 Cannot enable watchpoint %d because the block in which its expression\n\
7372 is valid is not currently in scope.\n", bpt->number);
7373 bpt->enable_state = bp_disabled;
7377 save_selected_frame = deprecated_selected_frame;
7378 save_selected_frame_level = frame_relative_level (deprecated_selected_frame);
7382 value_free (bpt->val);
7383 mark = value_mark ();
7384 bpt->val = evaluate_expression (bpt->exp);
7385 release_value (bpt->val);
7386 if (VALUE_LAZY (bpt->val))
7387 value_fetch_lazy (bpt->val);
7389 if (bpt->type == bp_hardware_watchpoint ||
7390 bpt->type == bp_read_watchpoint ||
7391 bpt->type == bp_access_watchpoint)
7393 int i = hw_watchpoint_used_count (bpt->type, &other_type_used);
7394 int mem_cnt = can_use_hardware_watchpoint (bpt->val);
7396 /* Hack around 'unused var' error for some targets here */
7398 target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7399 bpt->type, i + mem_cnt, other_type_used);
7400 /* we can consider of type is bp_hardware_watchpoint, convert to
7401 bp_watchpoint in the following condition */
7402 if (target_resources_ok < 0)
7405 Cannot enable watchpoint %d because target watch resources\n\
7406 have been allocated for other watchpoints.\n", bpt->number);
7407 bpt->enable_state = bp_disabled;
7408 value_free_to_mark (mark);
7413 if (save_selected_frame_level >= 0)
7414 select_frame (save_selected_frame);
7415 value_free_to_mark (mark);
7417 if (modify_breakpoint_hook)
7418 modify_breakpoint_hook (bpt);
7419 breakpoint_modify_event (bpt->number);
7423 enable_breakpoint (struct breakpoint *bpt)
7425 do_enable_breakpoint (bpt, bpt->disposition);
7428 /* The enable command enables the specified breakpoints (or all defined
7429 breakpoints) so they once again become (or continue to be) effective
7430 in stopping the inferior. */
7433 enable_command (char *args, int from_tty)
7435 struct breakpoint *bpt;
7437 ALL_BREAKPOINTS (bpt)
7441 warning ("attempted to enable apparently deleted breakpoint #%d?",
7446 case bp_catch_unload:
7448 case bp_catch_vfork:
7450 case bp_catch_catch:
7451 case bp_catch_throw:
7452 case bp_hardware_breakpoint:
7454 case bp_hardware_watchpoint:
7455 case bp_read_watchpoint:
7456 case bp_access_watchpoint:
7457 enable_breakpoint (bpt);
7462 map_breakpoint_numbers (args, enable_breakpoint);
7466 enable_once_breakpoint (struct breakpoint *bpt)
7468 do_enable_breakpoint (bpt, disp_disable);
7472 enable_once_command (char *args, int from_tty)
7474 map_breakpoint_numbers (args, enable_once_breakpoint);
7478 enable_delete_breakpoint (struct breakpoint *bpt)
7480 do_enable_breakpoint (bpt, disp_del);
7484 enable_delete_command (char *args, int from_tty)
7486 map_breakpoint_numbers (args, enable_delete_breakpoint);
7489 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7491 struct symtabs_and_lines
7492 decode_line_spec_1 (char *string, int funfirstline)
7494 struct symtabs_and_lines sals;
7496 error ("Empty line specification.");
7497 if (default_breakpoint_valid)
7498 sals = decode_line_1 (&string, funfirstline,
7499 default_breakpoint_symtab,
7500 default_breakpoint_line,
7503 sals = decode_line_1 (&string, funfirstline,
7504 (struct symtab *) NULL, 0, (char ***) NULL);
7506 error ("Junk at end of line specification: %s", string);
7511 _initialize_breakpoint (void)
7513 struct cmd_list_element *c;
7515 breakpoint_chain = 0;
7516 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
7517 before a breakpoint is set. */
7518 breakpoint_count = 0;
7520 add_com ("ignore", class_breakpoint, ignore_command,
7521 "Set ignore-count of breakpoint number N to COUNT.\n\
7522 Usage is `ignore N COUNT'.");
7524 add_com_alias ("bc", "ignore", class_breakpoint, 1);
7526 add_com ("commands", class_breakpoint, commands_command,
7527 "Set commands to be executed when a breakpoint is hit.\n\
7528 Give breakpoint number as argument after \"commands\".\n\
7529 With no argument, the targeted breakpoint is the last one set.\n\
7530 The commands themselves follow starting on the next line.\n\
7531 Type a line containing \"end\" to indicate the end of them.\n\
7532 Give \"silent\" as the first line to make the breakpoint silent;\n\
7533 then no output is printed when it is hit, except what the commands print.");
7535 add_com ("condition", class_breakpoint, condition_command,
7536 "Specify breakpoint number N to break only if COND is true.\n\
7537 Usage is `condition N COND', where N is an integer and COND is an\n\
7538 expression to be evaluated whenever breakpoint N is reached.");
7540 c = add_com ("tbreak", class_breakpoint, tbreak_command,
7541 "Set a temporary breakpoint. Args like \"break\" command.\n\
7542 Like \"break\" except the breakpoint is only temporary,\n\
7543 so it will be deleted when hit. Equivalent to \"break\" followed\n\
7544 by using \"enable delete\" on the breakpoint number.");
7545 set_cmd_completer (c, location_completer);
7547 c = add_com ("hbreak", class_breakpoint, hbreak_command,
7548 "Set a hardware assisted breakpoint. Args like \"break\" command.\n\
7549 Like \"break\" except the breakpoint requires hardware support,\n\
7550 some target hardware may not have this support.");
7551 set_cmd_completer (c, location_completer);
7553 c = add_com ("thbreak", class_breakpoint, thbreak_command,
7554 "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\
7555 Like \"hbreak\" except the breakpoint is only temporary,\n\
7556 so it will be deleted when hit.");
7557 set_cmd_completer (c, location_completer);
7559 add_prefix_cmd ("enable", class_breakpoint, enable_command,
7560 "Enable some breakpoints.\n\
7561 Give breakpoint numbers (separated by spaces) as arguments.\n\
7562 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7563 This is used to cancel the effect of the \"disable\" command.\n\
7564 With a subcommand you can enable temporarily.",
7565 &enablelist, "enable ", 1, &cmdlist);
7567 add_com ("ab", class_breakpoint, enable_command,
7568 "Enable some breakpoints.\n\
7569 Give breakpoint numbers (separated by spaces) as arguments.\n\
7570 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7571 This is used to cancel the effect of the \"disable\" command.\n\
7572 With a subcommand you can enable temporarily.");
7574 add_com_alias ("en", "enable", class_breakpoint, 1);
7576 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command,
7577 "Enable some breakpoints.\n\
7578 Give breakpoint numbers (separated by spaces) as arguments.\n\
7579 This is used to cancel the effect of the \"disable\" command.\n\
7580 May be abbreviated to simply \"enable\".\n",
7581 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
7583 add_cmd ("once", no_class, enable_once_command,
7584 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7585 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7588 add_cmd ("delete", no_class, enable_delete_command,
7589 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7590 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7593 add_cmd ("delete", no_class, enable_delete_command,
7594 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7595 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7598 add_cmd ("once", no_class, enable_once_command,
7599 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7600 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7603 add_prefix_cmd ("disable", class_breakpoint, disable_command,
7604 "Disable some breakpoints.\n\
7605 Arguments are breakpoint numbers with spaces in between.\n\
7606 To disable all breakpoints, give no argument.\n\
7607 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
7608 &disablelist, "disable ", 1, &cmdlist);
7609 add_com_alias ("dis", "disable", class_breakpoint, 1);
7610 add_com_alias ("disa", "disable", class_breakpoint, 1);
7612 add_com ("sb", class_breakpoint, disable_command,
7613 "Disable some breakpoints.\n\
7614 Arguments are breakpoint numbers with spaces in between.\n\
7615 To disable all breakpoints, give no argument.\n\
7616 A disabled breakpoint is not forgotten, but has no effect until reenabled.");
7618 add_cmd ("breakpoints", class_alias, disable_command,
7619 "Disable some breakpoints.\n\
7620 Arguments are breakpoint numbers with spaces in between.\n\
7621 To disable all breakpoints, give no argument.\n\
7622 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
7623 This command may be abbreviated \"disable\".",
7626 add_prefix_cmd ("delete", class_breakpoint, delete_command,
7627 "Delete some breakpoints or auto-display expressions.\n\
7628 Arguments are breakpoint numbers with spaces in between.\n\
7629 To delete all breakpoints, give no argument.\n\
7631 Also a prefix command for deletion of other GDB objects.\n\
7632 The \"unset\" command is also an alias for \"delete\".",
7633 &deletelist, "delete ", 1, &cmdlist);
7634 add_com_alias ("d", "delete", class_breakpoint, 1);
7636 add_com ("db", class_breakpoint, delete_command,
7637 "Delete some breakpoints.\n\
7638 Arguments are breakpoint numbers with spaces in between.\n\
7639 To delete all breakpoints, give no argument.\n");
7641 add_cmd ("breakpoints", class_alias, delete_command,
7642 "Delete some breakpoints or auto-display expressions.\n\
7643 Arguments are breakpoint numbers with spaces in between.\n\
7644 To delete all breakpoints, give no argument.\n\
7645 This command may be abbreviated \"delete\".",
7648 add_com ("clear", class_breakpoint, clear_command,
7649 concat ("Clear breakpoint at specified line or function.\n\
7650 Argument may be line number, function name, or \"*\" and an address.\n\
7651 If line number is specified, all breakpoints in that line are cleared.\n\
7652 If function is specified, breakpoints at beginning of function are cleared.\n\
7653 If an address is specified, breakpoints at that address are cleared.\n\n",
7654 "With no argument, clears all breakpoints in the line that the selected frame\n\
7657 See also the \"delete\" command which clears breakpoints by number.", NULL));
7659 c = add_com ("break", class_breakpoint, break_command,
7660 concat ("Set breakpoint at specified line or function.\n\
7661 Argument may be line number, function name, or \"*\" and an address.\n\
7662 If line number is specified, break at start of code for that line.\n\
7663 If function is specified, break at start of code for that function.\n\
7664 If an address is specified, break at that exact address.\n",
7665 "With no arg, uses current execution address of selected stack frame.\n\
7666 This is useful for breaking on return to a stack frame.\n\
7668 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7670 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL));
7671 set_cmd_completer (c, location_completer);
7673 add_com_alias ("b", "break", class_run, 1);
7674 add_com_alias ("br", "break", class_run, 1);
7675 add_com_alias ("bre", "break", class_run, 1);
7676 add_com_alias ("brea", "break", class_run, 1);
7680 add_com_alias ("ba", "break", class_breakpoint, 1);
7681 add_com_alias ("bu", "ubreak", class_breakpoint, 1);
7686 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command,
7687 "Break in function/address or break at a line in the current file.",
7688 &stoplist, "stop ", 1, &cmdlist);
7689 add_cmd ("in", class_breakpoint, stopin_command,
7690 "Break in function or address.\n", &stoplist);
7691 add_cmd ("at", class_breakpoint, stopat_command,
7692 "Break at a line in the current file.\n", &stoplist);
7693 add_com ("status", class_info, breakpoints_info,
7694 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7695 The \"Type\" column indicates one of:\n\
7696 \tbreakpoint - normal breakpoint\n\
7697 \twatchpoint - watchpoint\n\
7698 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7699 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7700 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7701 address and file/line number respectively.\n\n",
7702 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7703 are set to the address of the last breakpoint listed.\n\n\
7704 Convenience variable \"$bpnum\" contains the number of the last\n\
7705 breakpoint set.", NULL));
7708 add_info ("breakpoints", breakpoints_info,
7709 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7710 The \"Type\" column indicates one of:\n\
7711 \tbreakpoint - normal breakpoint\n\
7712 \twatchpoint - watchpoint\n\
7713 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7714 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7715 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7716 address and file/line number respectively.\n\n",
7717 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7718 are set to the address of the last breakpoint listed.\n\n\
7719 Convenience variable \"$bpnum\" contains the number of the last\n\
7720 breakpoint set.", NULL));
7723 add_com ("lb", class_breakpoint, breakpoints_info,
7724 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7725 The \"Type\" column indicates one of:\n\
7726 \tbreakpoint - normal breakpoint\n\
7727 \twatchpoint - watchpoint\n\
7728 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7729 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7730 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7731 address and file/line number respectively.\n\n",
7732 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7733 are set to the address of the last breakpoint listed.\n\n\
7734 Convenience variable \"$bpnum\" contains the number of the last\n\
7735 breakpoint set.", NULL));
7737 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints,
7738 concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\
7739 The \"Type\" column indicates one of:\n\
7740 \tbreakpoint - normal breakpoint\n\
7741 \twatchpoint - watchpoint\n\
7742 \tlongjmp - internal breakpoint used to step through longjmp()\n\
7743 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
7744 \tuntil - internal breakpoint used by the \"until\" command\n\
7745 \tfinish - internal breakpoint used by the \"finish\" command\n",
7746 "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7747 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7748 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7749 address and file/line number respectively.\n\n",
7750 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7751 are set to the address of the last breakpoint listed.\n\n\
7752 Convenience variable \"$bpnum\" contains the number of the last\n\
7753 breakpoint set.", NULL),
7754 &maintenanceinfolist);
7756 add_com ("catch", class_breakpoint, catch_command,
7757 "Set catchpoints to catch events.\n\
7758 Raised signals may be caught:\n\
7759 \tcatch signal - all signals\n\
7760 \tcatch signal <signame> - a particular signal\n\
7761 Raised exceptions may be caught:\n\
7762 \tcatch throw - all exceptions, when thrown\n\
7763 \tcatch throw <exceptname> - a particular exception, when thrown\n\
7764 \tcatch catch - all exceptions, when caught\n\
7765 \tcatch catch <exceptname> - a particular exception, when caught\n\
7766 Thread or process events may be caught:\n\
7767 \tcatch thread_start - any threads, just after creation\n\
7768 \tcatch thread_exit - any threads, just before expiration\n\
7769 \tcatch thread_join - any threads, just after joins\n\
7770 Process events may be caught:\n\
7771 \tcatch start - any processes, just after creation\n\
7772 \tcatch exit - any processes, just before expiration\n\
7773 \tcatch fork - calls to fork()\n\
7774 \tcatch vfork - calls to vfork()\n\
7775 \tcatch exec - calls to exec()\n\
7776 Dynamically-linked library events may be caught:\n\
7777 \tcatch load - loads of any library\n\
7778 \tcatch load <libname> - loads of a particular library\n\
7779 \tcatch unload - unloads of any library\n\
7780 \tcatch unload <libname> - unloads of a particular library\n\
7781 The act of your program's execution stopping may also be caught:\n\
7783 C++ exceptions may be caught:\n\
7784 \tcatch throw - all exceptions, when thrown\n\
7785 \tcatch catch - all exceptions, when caught\n\
7787 Do \"help set follow-fork-mode\" for info on debugging your program\n\
7788 after a fork or vfork is caught.\n\n\
7789 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
7791 add_com ("tcatch", class_breakpoint, tcatch_command,
7792 "Set temporary catchpoints to catch events.\n\
7793 Args like \"catch\" command.\n\
7794 Like \"catch\" except the catchpoint is only temporary,\n\
7795 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
7796 by using \"enable delete\" on the catchpoint number.");
7798 c = add_com ("watch", class_breakpoint, watch_command,
7799 "Set a watchpoint for an expression.\n\
7800 A watchpoint stops execution of your program whenever the value of\n\
7801 an expression changes.");
7802 set_cmd_completer (c, location_completer);
7804 c = add_com ("rwatch", class_breakpoint, rwatch_command,
7805 "Set a read watchpoint for an expression.\n\
7806 A watchpoint stops execution of your program whenever the value of\n\
7807 an expression is read.");
7808 set_cmd_completer (c, location_completer);
7810 c = add_com ("awatch", class_breakpoint, awatch_command,
7811 "Set a watchpoint for an expression.\n\
7812 A watchpoint stops execution of your program whenever the value of\n\
7813 an expression is either read or written.");
7814 set_cmd_completer (c, location_completer);
7816 add_info ("watchpoints", breakpoints_info,
7817 "Synonym for ``info breakpoints''.");
7820 c = add_set_cmd ("can-use-hw-watchpoints", class_support, var_zinteger,
7821 (char *) &can_use_hw_watchpoints,
7822 "Set debugger's willingness to use watchpoint hardware.\n\
7823 If zero, gdb will not use hardware for new watchpoints, even if\n\
7824 such is available. (However, any hardware watchpoints that were\n\
7825 created before setting this to nonzero, will continue to use watchpoint\n\
7828 add_show_from_set (c, &showlist);
7830 can_use_hw_watchpoints = 1;