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, 2004, 2005
5 Free Software Foundation, Inc.
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"
54 #include "exceptions.h"
56 #include "gdb-events.h"
58 /* Prototypes for local functions. */
60 static void until_break_command_continuation (struct continuation_arg *arg);
62 static void catch_command_1 (char *, int, int);
64 static void enable_delete_command (char *, int);
66 static void enable_delete_breakpoint (struct breakpoint *);
68 static void enable_once_command (char *, int);
70 static void enable_once_breakpoint (struct breakpoint *);
72 static void disable_command (char *, int);
74 static void enable_command (char *, int);
76 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint *));
78 static void ignore_command (char *, int);
80 static int breakpoint_re_set_one (void *);
82 static void clear_command (char *, int);
84 static void catch_command (char *, int);
86 static void watch_command (char *, int);
88 static int can_use_hardware_watchpoint (struct value *);
90 static int break_command_1 (char *, int, int, struct breakpoint *);
92 static void mention (struct breakpoint *);
94 struct breakpoint *set_raw_breakpoint (struct symtab_and_line, enum bptype);
96 static void check_duplicates (struct breakpoint *);
98 static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
100 static CORE_ADDR adjust_breakpoint_address (CORE_ADDR bpaddr,
103 static void describe_other_breakpoints (CORE_ADDR, asection *);
105 static void breakpoints_info (char *, int);
107 static void breakpoint_1 (int, int);
109 static bpstat bpstat_alloc (struct breakpoint *, bpstat);
111 static int breakpoint_cond_eval (void *);
113 static void cleanup_executing_breakpoints (void *);
115 static void commands_command (char *, int);
117 static void condition_command (char *, int);
119 static int get_number_trailer (char **, int);
121 void set_breakpoint_count (int);
130 static int remove_breakpoint (struct bp_location *, insertion_state_t);
132 static enum print_stop_action print_it_typical (bpstat);
134 static enum print_stop_action print_bp_stop_message (bpstat bs);
138 enum exception_event_kind kind;
141 args_for_catchpoint_enable;
143 static int watchpoint_check (void *);
145 static int cover_target_enable_exception_callback (void *);
147 static void maintenance_info_breakpoints (char *, int);
149 static void create_longjmp_breakpoint (char *);
151 static void create_overlay_event_breakpoint (char *);
153 static int hw_breakpoint_used_count (void);
155 static int hw_watchpoint_used_count (enum bptype, int *);
157 static void hbreak_command (char *, int);
159 static void thbreak_command (char *, int);
161 static void watch_command_1 (char *, int, int);
163 static void rwatch_command (char *, int);
165 static void awatch_command (char *, int);
167 static void do_enable_breakpoint (struct breakpoint *, enum bpdisp);
169 static void solib_load_unload_1 (char *hookname,
172 char *cond_string, enum bptype bp_kind);
174 static void create_fork_vfork_event_catchpoint (int tempflag,
176 enum bptype bp_kind);
178 static void stop_command (char *arg, int from_tty);
180 static void stopin_command (char *arg, int from_tty);
182 static void stopat_command (char *arg, int from_tty);
184 static char *ep_find_event_name_end (char *arg);
186 static char *ep_parse_optional_if_clause (char **arg);
188 static char *ep_parse_optional_filename (char **arg);
190 static void create_exception_catchpoint (int tempflag, char *cond_string,
191 enum exception_event_kind ex_event,
192 struct symtab_and_line *sal);
194 static void catch_exception_command_1 (enum exception_event_kind ex_event,
195 char *arg, int tempflag, int from_tty);
197 static void tcatch_command (char *arg, int from_tty);
199 static void ep_skip_leading_whitespace (char **s);
201 /* Prototypes for exported functions. */
203 /* If FALSE, gdb will not use hardware support for watchpoints, even
204 if such is available. */
205 static int can_use_hw_watchpoints;
207 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
208 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
209 for unrecognized breakpoint locations.
210 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
211 static enum auto_boolean pending_break_support;
213 void _initialize_breakpoint (void);
215 extern int addressprint; /* Print machine addresses? */
217 /* Are we executing breakpoint commands? */
218 static int executing_breakpoint_commands;
220 /* Are overlay event breakpoints enabled? */
221 static int overlay_events_enabled;
223 /* Walk the following statement or block through all breakpoints.
224 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
227 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
229 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
230 for (B = breakpoint_chain; \
231 B ? (TMP=B->next, 1): 0; \
234 /* Similar iterators for the low-level breakpoints. */
236 #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->next)
238 #define ALL_BP_LOCATIONS_SAFE(B,TMP) \
239 for (B = bp_location_chain; \
240 B ? (TMP=B->next, 1): 0; \
243 /* True if breakpoint hit counts should be displayed in breakpoint info. */
245 int show_breakpoint_hit_counts = 1;
247 /* Chains of all breakpoints defined. */
249 struct breakpoint *breakpoint_chain;
251 struct bp_location *bp_location_chain;
253 /* Number of last breakpoint made. */
255 int breakpoint_count;
257 /* Pointer to current exception event record */
258 static struct exception_event_record *current_exception_event;
260 /* Indicator of whether exception catchpoints should be nuked between
261 runs of a program. */
262 int deprecated_exception_catchpoints_are_fragile = 0;
264 /* Indicator of when exception catchpoints set-up should be
265 reinitialized -- e.g. when program is re-run. */
266 int deprecated_exception_support_initialized = 0;
268 /* This function returns a pointer to the string representation of the
269 pathname of the dynamically-linked library that has just been
272 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
273 or undefined results are guaranteed.
275 This string's contents are only valid immediately after the
276 inferior has stopped in the dynamic linker hook, and becomes
277 invalid as soon as the inferior is continued. Clients should make
278 a copy of this string if they wish to continue the inferior and
279 then access the string. */
281 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
282 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
285 /* This function returns a pointer to the string representation of the
286 pathname of the dynamically-linked library that has just been
289 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
290 TRUE, or undefined results are guaranteed.
292 This string's contents are only valid immediately after the
293 inferior has stopped in the dynamic linker hook, and becomes
294 invalid as soon as the inferior is continued. Clients should make
295 a copy of this string if they wish to continue the inferior and
296 then access the string. */
298 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
299 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
302 /* This function is called by the "catch load" command. It allows the
303 debugger to be notified by the dynamic linker when a specified
304 library file (or any library file, if filename is NULL) is loaded. */
306 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
307 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
308 error ("catch of library loads not yet implemented on this platform")
311 /* This function is called by the "catch unload" command. It allows
312 the debugger to be notified by the dynamic linker when a specified
313 library file (or any library file, if filename is NULL) is
316 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
317 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid, tempflag, filename, cond_string) \
318 error ("catch of library unloads not yet implemented on this platform")
321 /* Return whether a breakpoint is an active enabled breakpoint. */
323 breakpoint_enabled (struct breakpoint *b)
325 return (b->enable_state == bp_enabled && !b->pending);
328 /* Set breakpoint count to NUM. */
331 set_breakpoint_count (int num)
333 breakpoint_count = num;
334 set_internalvar (lookup_internalvar ("bpnum"),
335 value_from_longest (builtin_type_int, (LONGEST) num));
338 /* Used in run_command to zero the hit count when a new run starts. */
341 clear_breakpoint_hit_counts (void)
343 struct breakpoint *b;
349 /* Default address, symtab and line to put a breakpoint at
350 for "break" command with no arg.
351 if default_breakpoint_valid is zero, the other three are
352 not valid, and "break" with no arg is an error.
354 This set by print_stack_frame, which calls set_default_breakpoint. */
356 int default_breakpoint_valid;
357 CORE_ADDR default_breakpoint_address;
358 struct symtab *default_breakpoint_symtab;
359 int default_breakpoint_line;
361 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
362 Advance *PP after the string and any trailing whitespace.
364 Currently the string can either be a number or "$" followed by the name
365 of a convenience variable. Making it an expression wouldn't work well
366 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
368 TRAILER is a character which can be found after the number; most
369 commonly this is `-'. If you don't want a trailer, use \0. */
371 get_number_trailer (char **pp, int trailer)
373 int retval = 0; /* default */
377 /* Empty line means refer to the last breakpoint. */
378 return breakpoint_count;
381 /* Make a copy of the name, so we can null-terminate it
382 to pass to lookup_internalvar(). */
387 while (isalnum (*p) || *p == '_')
389 varname = (char *) alloca (p - start + 1);
390 strncpy (varname, start, p - start);
391 varname[p - start] = '\0';
392 val = value_of_internalvar (lookup_internalvar (varname));
393 if (TYPE_CODE (value_type (val)) == TYPE_CODE_INT)
394 retval = (int) value_as_long (val);
397 printf_filtered ("Convenience variable must have integer value.\n");
405 while (*p >= '0' && *p <= '9')
408 /* There is no number here. (e.g. "cond a == b"). */
410 /* Skip non-numeric token */
411 while (*p && !isspace((int) *p))
413 /* Return zero, which caller must interpret as error. */
419 if (!(isspace (*p) || *p == '\0' || *p == trailer))
421 /* Trailing junk: return 0 and let caller print error msg. */
422 while (!(isspace (*p) || *p == '\0' || *p == trailer))
433 /* Like get_number_trailer, but don't allow a trailer. */
435 get_number (char **pp)
437 return get_number_trailer (pp, '\0');
440 /* Parse a number or a range.
441 * A number will be of the form handled by get_number.
442 * A range will be of the form <number1> - <number2>, and
443 * will represent all the integers between number1 and number2,
446 * While processing a range, this fuction is called iteratively;
447 * At each call it will return the next value in the range.
449 * At the beginning of parsing a range, the char pointer PP will
450 * be advanced past <number1> and left pointing at the '-' token.
451 * Subsequent calls will not advance the pointer until the range
452 * is completed. The call that completes the range will advance
453 * pointer PP past <number2>.
457 get_number_or_range (char **pp)
459 static int last_retval, end_value;
460 static char *end_ptr;
461 static int in_range = 0;
465 /* Default case: pp is pointing either to a solo number,
466 or to the first number of a range. */
467 last_retval = get_number_trailer (pp, '-');
472 /* This is the start of a range (<number1> - <number2>).
473 Skip the '-', parse and remember the second number,
474 and also remember the end of the final token. */
478 while (isspace ((int) *end_ptr))
479 end_ptr++; /* skip white space */
480 end_value = get_number (temp);
481 if (end_value < last_retval)
483 error ("inverted range");
485 else if (end_value == last_retval)
487 /* degenerate range (number1 == number2). Advance the
488 token pointer so that the range will be treated as a
497 error ("negative value");
500 /* pp points to the '-' that betokens a range. All
501 number-parsing has already been done. Return the next
502 integer value (one greater than the saved previous value).
503 Do not advance the token pointer 'pp' until the end of range
506 if (++last_retval == end_value)
508 /* End of range reached; advance token pointer. */
518 /* condition N EXP -- set break condition of breakpoint N to EXP. */
521 condition_command (char *arg, int from_tty)
523 struct breakpoint *b;
528 error_no_arg ("breakpoint number");
531 bnum = get_number (&p);
533 error ("Bad breakpoint argument: '%s'", arg);
536 if (b->number == bnum)
543 if (b->cond_string != NULL)
544 xfree (b->cond_string);
549 b->cond_string = NULL;
551 printf_filtered ("Breakpoint %d now unconditional.\n", bnum);
556 /* I don't know if it matters whether this is the string the user
557 typed in or the decompiled expression. */
558 b->cond_string = savestring (arg, strlen (arg));
561 b->cond = parse_exp_1 (&arg, block_for_pc (b->loc->address), 0);
563 error ("Junk at end of expression");
566 breakpoints_changed ();
567 breakpoint_modify_event (b->number);
571 error ("No breakpoint number %d.", bnum);
575 commands_command (char *arg, int from_tty)
577 struct breakpoint *b;
580 struct command_line *l;
582 /* If we allowed this, we would have problems with when to
583 free the storage, if we change the commands currently
586 if (executing_breakpoint_commands)
587 error ("Can't use the \"commands\" command among a breakpoint's commands.");
590 bnum = get_number (&p);
593 error ("Unexpected extra arguments following breakpoint number.");
596 if (b->number == bnum)
598 char *tmpbuf = xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
600 struct cleanup *cleanups = make_cleanup (xfree, tmpbuf);
601 l = read_command_lines (tmpbuf, from_tty);
602 do_cleanups (cleanups);
603 free_command_lines (&b->commands);
605 breakpoints_changed ();
606 breakpoint_modify_event (b->number);
609 error ("No breakpoint number %d.", bnum);
612 /* Like target_read_memory() but if breakpoints are inserted, return
613 the shadow contents instead of the breakpoints themselves.
615 Read "memory data" from whatever target or inferior we have.
616 Returns zero if successful, errno value if not. EIO is used
617 for address out of bounds. If breakpoints are inserted, returns
618 shadow contents, not the breakpoints themselves. From breakpoint.c. */
621 deprecated_read_memory_nobpt (CORE_ADDR memaddr, char *myaddr, unsigned len)
624 struct bp_location *b;
625 CORE_ADDR bp_addr = 0;
628 if (BREAKPOINT_FROM_PC (&bp_addr, &bp_size) == NULL)
629 /* No breakpoints on this machine. */
630 return target_read_memory (memaddr, myaddr, len);
634 if (b->owner->type == bp_none)
635 warning ("reading through apparently deleted breakpoint #%d?",
638 if (b->loc_type != bp_loc_software_breakpoint)
642 /* Addresses and length of the part of the breakpoint that
644 /* XXXX The m68k, sh and h8300 have different local and remote
645 breakpoint values. BREAKPOINT_FROM_PC still manages to
646 correctly determine the breakpoints memory address and size
647 for these targets. */
648 bp_addr = b->address;
650 if (BREAKPOINT_FROM_PC (&bp_addr, &bp_size) == NULL)
655 if (bp_addr + bp_size <= memaddr)
656 /* The breakpoint is entirely before the chunk of memory we
659 if (bp_addr >= memaddr + len)
660 /* The breakpoint is entirely after the chunk of memory we are
663 /* Copy the breakpoint from the shadow contents, and recurse for
664 the things before and after. */
666 /* Offset within shadow_contents. */
669 if (bp_addr < memaddr)
671 /* Only copy the second part of the breakpoint. */
672 bp_size -= memaddr - bp_addr;
673 bptoffset = memaddr - bp_addr;
677 if (bp_addr + bp_size > memaddr + len)
679 /* Only copy the first part of the breakpoint. */
680 bp_size -= (bp_addr + bp_size) - (memaddr + len);
683 memcpy (myaddr + bp_addr - memaddr,
684 b->shadow_contents + bptoffset, bp_size);
686 if (bp_addr > memaddr)
688 /* Copy the section of memory before the breakpoint. */
689 status = deprecated_read_memory_nobpt (memaddr, myaddr, bp_addr - memaddr);
694 if (bp_addr + bp_size < memaddr + len)
696 /* Copy the section of memory after the breakpoint. */
697 status = deprecated_read_memory_nobpt (bp_addr + bp_size,
698 myaddr + bp_addr + bp_size - memaddr,
699 memaddr + len - (bp_addr + bp_size));
706 /* Nothing overlaps. Just call read_memory_noerr. */
707 return target_read_memory (memaddr, myaddr, len);
711 /* A wrapper function for inserting catchpoints. */
713 insert_catchpoint (struct ui_out *uo, void *args)
715 struct breakpoint *b = (struct breakpoint *) args;
721 val = target_insert_fork_catchpoint (PIDGET (inferior_ptid));
724 val = target_insert_vfork_catchpoint (PIDGET (inferior_ptid));
727 val = target_insert_exec_catchpoint (PIDGET (inferior_ptid));
730 internal_error (__FILE__, __LINE__, "unknown breakpoint type");
735 throw_reason (RETURN_ERROR);
738 /* Helper routine: free the value chain for a breakpoint (watchpoint). */
740 static void free_valchain (struct bp_location *b)
745 /* Free the saved value chain. We will construct a new one
746 the next time the watchpoint is inserted. */
747 for (v = b->owner->val_chain; v; v = n)
752 b->owner->val_chain = NULL;
755 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
756 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
757 PROCESS_WARNING, and HW_BREAKPOINT_ERROR are used to report problems.
759 NOTE drow/2003-09-09: This routine could be broken down to an object-style
760 method for each breakpoint or catchpoint type. */
762 insert_bp_location (struct bp_location *bpt,
763 struct ui_file *tmp_error_stream,
764 int *disabled_breaks, int *process_warning,
765 int *hw_breakpoint_error)
769 /* Permanent breakpoints cannot be inserted or removed. Disabled
770 breakpoints should not be inserted. */
771 if (!breakpoint_enabled (bpt->owner))
774 if (bpt->inserted || bpt->duplicate)
777 if (bpt->loc_type == bp_loc_software_breakpoint
778 || bpt->loc_type == bp_loc_hardware_breakpoint)
780 /* First check to see if we have to handle an overlay. */
781 if (overlay_debugging == ovly_off
782 || bpt->section == NULL
783 || !(section_is_overlay (bpt->section)))
785 /* No overlay handling: just set the breakpoint. */
787 if (bpt->loc_type == bp_loc_hardware_breakpoint)
788 val = target_insert_hw_breakpoint (bpt->address,
789 bpt->shadow_contents);
791 val = target_insert_breakpoint (bpt->address,
792 bpt->shadow_contents);
796 /* This breakpoint is in an overlay section.
797 Shall we set a breakpoint at the LMA? */
798 if (!overlay_events_enabled)
800 /* Yes -- overlay event support is not active,
801 so we must try to set a breakpoint at the LMA.
802 This will not work for a hardware breakpoint. */
803 if (bpt->loc_type == bp_loc_hardware_breakpoint)
804 warning ("hardware breakpoint %d not supported in overlay!\n",
808 CORE_ADDR addr = overlay_unmapped_address (bpt->address,
810 /* Set a software (trap) breakpoint at the LMA. */
811 val = target_insert_breakpoint (addr, bpt->shadow_contents);
813 fprintf_unfiltered (tmp_error_stream,
814 "Overlay breakpoint %d failed: in ROM?",
818 /* Shall we set a breakpoint at the VMA? */
819 if (section_is_mapped (bpt->section))
821 /* Yes. This overlay section is mapped into memory. */
822 if (bpt->loc_type == bp_loc_hardware_breakpoint)
823 val = target_insert_hw_breakpoint (bpt->address,
824 bpt->shadow_contents);
826 val = target_insert_breakpoint (bpt->address,
827 bpt->shadow_contents);
831 /* No. This breakpoint will not be inserted.
832 No error, but do not mark the bp as 'inserted'. */
839 /* Can't set the breakpoint. */
840 #if defined (DISABLE_UNSETTABLE_BREAK)
841 if (DISABLE_UNSETTABLE_BREAK (bpt->address))
843 /* See also: disable_breakpoints_in_shlibs. */
845 bpt->owner->enable_state = bp_shlib_disabled;
846 if (!*disabled_breaks)
848 fprintf_unfiltered (tmp_error_stream,
849 "Cannot insert breakpoint %d.\n",
851 fprintf_unfiltered (tmp_error_stream,
852 "Temporarily disabling shared library breakpoints:\n");
854 *disabled_breaks = 1;
855 fprintf_unfiltered (tmp_error_stream,
856 "breakpoint #%d\n", bpt->owner->number);
861 #ifdef ONE_PROCESS_WRITETEXT
862 *process_warning = 1;
864 if (bpt->loc_type == bp_loc_hardware_breakpoint)
866 *hw_breakpoint_error = 1;
867 fprintf_unfiltered (tmp_error_stream,
868 "Cannot insert hardware breakpoint %d.\n",
873 fprintf_unfiltered (tmp_error_stream,
874 "Cannot insert breakpoint %d.\n",
876 fprintf_filtered (tmp_error_stream,
877 "Error accessing memory address ");
878 print_address_numeric (bpt->address, 1, tmp_error_stream);
879 fprintf_filtered (tmp_error_stream, ": %s.\n",
880 safe_strerror (val));
891 else if (bpt->loc_type == bp_loc_hardware_watchpoint
892 /* NOTE drow/2003-09-08: This state only exists for removing
893 watchpoints. It's not clear that it's necessary... */
894 && bpt->owner->disposition != disp_del_at_next_stop)
896 /* FIXME drow/2003-09-08: This code sets multiple hardware watchpoints
897 based on the expression. Ideally this should happen at a higher level,
898 and there should be one bp_location for each computed address we
899 must watch. As soon as a many-to-one mapping is available I'll
902 int within_current_scope;
903 struct value *mark = value_mark ();
905 struct frame_id saved_frame_id;
907 /* Save the current frame's ID so we can restore it after
908 evaluating the watchpoint expression on its own frame. */
909 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
910 took a frame parameter, so that we didn't have to change the
912 saved_frame_id = get_frame_id (deprecated_selected_frame);
914 /* Determine if the watchpoint is within scope. */
915 if (bpt->owner->exp_valid_block == NULL)
916 within_current_scope = 1;
919 struct frame_info *fi;
920 fi = frame_find_by_id (bpt->owner->watchpoint_frame);
921 within_current_scope = (fi != NULL);
922 if (within_current_scope)
926 if (within_current_scope)
930 /* Evaluate the expression and cut the chain of values
931 produced off from the value chain.
933 Make sure the value returned isn't lazy; we use
934 laziness to determine what memory GDB actually needed
935 in order to compute the value of the expression. */
936 v = evaluate_expression (bpt->owner->exp);
938 value_release_to_mark (mark);
940 bpt->owner->val_chain = v;
943 /* Look at each value on the value chain. */
944 for (; v; v = v->next)
946 /* If it's a memory location, and GDB actually needed
947 its contents to evaluate the expression, then we
949 if (VALUE_LVAL (v) == lval_memory
952 struct type *vtype = check_typedef (value_type (v));
954 /* We only watch structs and arrays if user asked
955 for it explicitly, never if they just happen to
956 appear in the middle of some value chain. */
957 if (v == bpt->owner->val_chain
958 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
959 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
964 addr = VALUE_ADDRESS (v) + value_offset (v);
965 len = TYPE_LENGTH (value_type (v));
967 if (bpt->owner->type == bp_read_watchpoint)
969 else if (bpt->owner->type == bp_access_watchpoint)
972 val = target_insert_watchpoint (addr, len, type);
975 /* Don't exit the loop, try to insert
976 every value on the value chain. That's
977 because we will be removing all the
978 watches below, and removing a
979 watchpoint we didn't insert could have
987 /* Failure to insert a watchpoint on any memory value in the
988 value chain brings us here. */
991 remove_breakpoint (bpt, mark_uninserted);
992 *hw_breakpoint_error = 1;
993 fprintf_unfiltered (tmp_error_stream,
994 "Could not insert hardware watchpoint %d.\n",
1001 printf_filtered ("Hardware watchpoint %d deleted ", bpt->owner->number);
1002 printf_filtered ("because the program has left the block \n");
1003 printf_filtered ("in which its expression is valid.\n");
1004 if (bpt->owner->related_breakpoint)
1005 bpt->owner->related_breakpoint->disposition = disp_del_at_next_stop;
1006 bpt->owner->disposition = disp_del_at_next_stop;
1009 /* Restore the selected frame. */
1010 select_frame (frame_find_by_id (saved_frame_id));
1015 else if (ep_is_exception_catchpoint (bpt->owner))
1017 /* FIXME drow/2003-09-09: This code sets both a catchpoint and a
1018 breakpoint. Once again, it would be better if this was represented
1019 as two bp_locations. */
1021 /* If we get here, we must have a callback mechanism for exception
1022 events -- with g++ style embedded label support, we insert
1023 ordinary breakpoints and not catchpoints. */
1024 val = target_insert_breakpoint (bpt->address, bpt->shadow_contents);
1027 /* Couldn't set breakpoint for some reason */
1028 fprintf_unfiltered (tmp_error_stream,
1029 "Cannot insert catchpoint %d; disabling it.\n",
1030 bpt->owner->number);
1031 fprintf_filtered (tmp_error_stream,
1032 "Error accessing memory address ");
1033 print_address_numeric (bpt->address, 1, tmp_error_stream);
1034 fprintf_filtered (tmp_error_stream, ": %s.\n",
1035 safe_strerror (val));
1036 bpt->owner->enable_state = bp_disabled;
1040 /* Bp set, now make sure callbacks are enabled */
1041 /* Format possible error msg */
1042 char *message = xstrprintf ("Error inserting catchpoint %d:\n",
1043 bpt->owner->number);
1044 struct cleanup *cleanups = make_cleanup (xfree, message);
1046 args_for_catchpoint_enable args;
1047 args.kind = bpt->owner->type == bp_catch_catch ?
1048 EX_EVENT_CATCH : EX_EVENT_THROW;
1050 val = catch_errors (cover_target_enable_exception_callback,
1051 &args, message, RETURN_MASK_ALL);
1052 do_cleanups (cleanups);
1053 if (val != 0 && val != -1)
1056 /* Check if something went wrong; val == 0 can be ignored */
1059 /* something went wrong */
1060 fprintf_unfiltered (tmp_error_stream,
1061 "Cannot insert catchpoint %d; disabling it.\n",
1062 bpt->owner->number);
1063 bpt->owner->enable_state = bp_disabled;
1070 else if (bpt->owner->type == bp_catch_fork
1071 || bpt->owner->type == bp_catch_vfork
1072 || bpt->owner->type == bp_catch_exec)
1074 struct exception e = catch_exception (uiout, insert_catchpoint,
1075 bpt->owner, RETURN_MASK_ERROR);
1076 exception_fprintf (gdb_stderr, e, "warning: inserting catchpoint %d: ",
1077 bpt->owner->number);
1079 bpt->owner->enable_state = bp_disabled;
1083 /* We've already printed an error message if there was a problem
1084 inserting this catchpoint, and we've disabled the catchpoint,
1085 so just return success. */
1092 /* insert_breakpoints is used when starting or continuing the program.
1093 remove_breakpoints is used when the program stops.
1094 Both return zero if successful,
1095 or an `errno' value if could not write the inferior. */
1098 insert_breakpoints (void)
1100 struct bp_location *b, *temp;
1101 int return_val = 0; /* return success code. */
1103 int disabled_breaks = 0;
1104 int hw_breakpoint_error = 0;
1105 int process_warning = 0;
1107 struct ui_file *tmp_error_stream = mem_fileopen ();
1108 make_cleanup_ui_file_delete (tmp_error_stream);
1110 /* Explicitly mark the warning -- this will only be printed if
1111 there was an error. */
1112 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
1114 ALL_BP_LOCATIONS_SAFE (b, temp)
1116 /* Permanent breakpoints cannot be inserted or removed. Disabled
1117 breakpoints should not be inserted. */
1118 if (!breakpoint_enabled (b->owner))
1121 /* FIXME drow/2003-10-07: This code should be pushed elsewhere when
1122 hardware watchpoints are split into multiple loc breakpoints. */
1123 if ((b->loc_type == bp_loc_hardware_watchpoint
1124 || b->owner->type == bp_watchpoint) && !b->owner->val)
1127 val = evaluate_expression (b->owner->exp);
1128 release_value (val);
1129 if (VALUE_LAZY (val))
1130 value_fetch_lazy (val);
1131 b->owner->val = val;
1134 val = insert_bp_location (b, tmp_error_stream,
1135 &disabled_breaks, &process_warning,
1136 &hw_breakpoint_error);
1143 /* If a hardware breakpoint or watchpoint was inserted, add a
1144 message about possibly exhausted resources. */
1145 if (hw_breakpoint_error)
1147 fprintf_unfiltered (tmp_error_stream,
1148 "Could not insert hardware breakpoints:\n\
1149 You may have requested too many hardware breakpoints/watchpoints.\n");
1151 #ifdef ONE_PROCESS_WRITETEXT
1152 if (process_warning)
1153 fprintf_unfiltered (tmp_error_stream,
1154 "The same program may be running in another process.");
1156 target_terminal_ours_for_output ();
1157 error_stream (tmp_error_stream);
1163 remove_breakpoints (void)
1165 struct bp_location *b;
1168 ALL_BP_LOCATIONS (b)
1172 val = remove_breakpoint (b, mark_uninserted);
1181 remove_hw_watchpoints (void)
1183 struct bp_location *b;
1186 ALL_BP_LOCATIONS (b)
1188 if (b->inserted && b->loc_type == bp_loc_hardware_watchpoint)
1190 val = remove_breakpoint (b, mark_uninserted);
1199 reattach_breakpoints (int pid)
1201 struct bp_location *b;
1203 struct cleanup *old_chain = save_inferior_ptid ();
1205 /* Set inferior_ptid; remove_breakpoint uses this global. */
1206 inferior_ptid = pid_to_ptid (pid);
1207 ALL_BP_LOCATIONS (b)
1211 remove_breakpoint (b, mark_inserted);
1212 if (b->loc_type == bp_loc_hardware_breakpoint)
1213 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
1215 val = target_insert_breakpoint (b->address, b->shadow_contents);
1216 /* FIXME drow/2003-10-07: This doesn't handle any other kinds of
1217 breakpoints. It's wrong for watchpoints, for example. */
1220 do_cleanups (old_chain);
1225 do_cleanups (old_chain);
1230 update_breakpoints_after_exec (void)
1232 struct breakpoint *b;
1233 struct breakpoint *temp;
1235 /* Doing this first prevents the badness of having delete_breakpoint()
1236 write a breakpoint's current "shadow contents" to lift the bp. That
1237 shadow is NOT valid after an exec()! */
1238 mark_breakpoints_out ();
1240 ALL_BREAKPOINTS_SAFE (b, temp)
1242 /* Solib breakpoints must be explicitly reset after an exec(). */
1243 if (b->type == bp_shlib_event)
1245 delete_breakpoint (b);
1249 /* Thread event breakpoints must be set anew after an exec(),
1250 as must overlay event breakpoints. */
1251 if (b->type == bp_thread_event || b->type == bp_overlay_event)
1253 delete_breakpoint (b);
1257 /* Step-resume breakpoints are meaningless after an exec(). */
1258 if (b->type == bp_step_resume)
1260 delete_breakpoint (b);
1264 /* Ditto the sigtramp handler breakpoints. */
1265 if (b->type == bp_through_sigtramp)
1267 delete_breakpoint (b);
1271 /* Ditto the exception-handling catchpoints. */
1272 if ((b->type == bp_catch_catch) || (b->type == bp_catch_throw))
1274 delete_breakpoint (b);
1278 /* Don't delete an exec catchpoint, because else the inferior
1279 won't stop when it ought!
1281 Similarly, we probably ought to keep vfork catchpoints, 'cause
1282 on this target, we may not be able to stop when the vfork is
1283 seen, but only when the subsequent exec is seen. (And because
1284 deleting fork catchpoints here but not vfork catchpoints will
1285 seem mysterious to users, keep those too.)
1287 ??rehrauer: Let's hope that merely clearing out this catchpoint's
1288 target address field, if any, is sufficient to have it be reset
1289 automagically. Certainly on HP-UX that's true.
1291 Jim Blandy <jimb@redhat.com>: Actually, zero is a perfectly
1292 valid code address on some platforms (like the mn10300
1293 simulators). We shouldn't assign any special interpretation to
1294 a breakpoint with a zero address. And in fact, GDB doesn't ---
1295 I can't see what that comment above is talking about. As far
1296 as I can tell, setting the address of a
1297 bp_catch_exec/bp_catch_vfork/bp_catch_fork breakpoint to zero
1298 is meaningless, since those are implemented with HP-UX kernel
1299 hackery, not by storing breakpoint instructions somewhere. */
1300 if ((b->type == bp_catch_exec) ||
1301 (b->type == bp_catch_vfork) ||
1302 (b->type == bp_catch_fork))
1304 b->loc->address = (CORE_ADDR) NULL;
1308 /* bp_finish is a special case. The only way we ought to be able
1309 to see one of these when an exec() has happened, is if the user
1310 caught a vfork, and then said "finish". Ordinarily a finish just
1311 carries them to the call-site of the current callee, by setting
1312 a temporary bp there and resuming. But in this case, the finish
1313 will carry them entirely through the vfork & exec.
1315 We don't want to allow a bp_finish to remain inserted now. But
1316 we can't safely delete it, 'cause finish_command has a handle to
1317 the bp on a bpstat, and will later want to delete it. There's a
1318 chance (and I've seen it happen) that if we delete the bp_finish
1319 here, that its storage will get reused by the time finish_command
1320 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1321 We really must allow finish_command to delete a bp_finish.
1323 In the absense of a general solution for the "how do we know
1324 it's safe to delete something others may have handles to?"
1325 problem, what we'll do here is just uninsert the bp_finish, and
1326 let finish_command delete it.
1328 (We know the bp_finish is "doomed" in the sense that it's
1329 momentary, and will be deleted as soon as finish_command sees
1330 the inferior stopped. So it doesn't matter that the bp's
1331 address is probably bogus in the new a.out, unlike e.g., the
1332 solib breakpoints.) */
1334 if (b->type == bp_finish)
1339 /* Without a symbolic address, we have little hope of the
1340 pre-exec() address meaning the same thing in the post-exec()
1342 if (b->addr_string == NULL)
1344 delete_breakpoint (b);
1348 /* If this breakpoint has survived the above battery of checks, then
1349 it must have a symbolic address. Be sure that it gets reevaluated
1350 to a target address, rather than reusing the old evaluation.
1352 Jim Blandy <jimb@redhat.com>: As explained above in the comment
1353 for bp_catch_exec and friends, I'm pretty sure this is entirely
1354 unnecessary. A call to breakpoint_re_set_one always recomputes
1355 the breakpoint's address from scratch, or deletes it if it can't.
1356 So I think this assignment could be deleted without effect. */
1357 b->loc->address = (CORE_ADDR) NULL;
1359 /* FIXME what about longjmp breakpoints? Re-create them here? */
1360 create_overlay_event_breakpoint ("_ovly_debug_event");
1364 detach_breakpoints (int pid)
1366 struct bp_location *b;
1368 struct cleanup *old_chain = save_inferior_ptid ();
1370 if (pid == PIDGET (inferior_ptid))
1371 error ("Cannot detach breakpoints of inferior_ptid");
1373 /* Set inferior_ptid; remove_breakpoint uses this global. */
1374 inferior_ptid = pid_to_ptid (pid);
1375 ALL_BP_LOCATIONS (b)
1379 val = remove_breakpoint (b, mark_inserted);
1382 do_cleanups (old_chain);
1387 do_cleanups (old_chain);
1392 remove_breakpoint (struct bp_location *b, insertion_state_t is)
1396 if (b->owner->enable_state == bp_permanent)
1397 /* Permanent breakpoints cannot be inserted or removed. */
1400 if (b->owner->type == bp_none)
1401 warning ("attempted to remove apparently deleted breakpoint #%d?",
1404 if (b->loc_type == bp_loc_software_breakpoint
1405 || b->loc_type == bp_loc_hardware_breakpoint)
1407 /* "Normal" instruction breakpoint: either the standard
1408 trap-instruction bp (bp_breakpoint), or a
1409 bp_hardware_breakpoint. */
1411 /* First check to see if we have to handle an overlay. */
1412 if (overlay_debugging == ovly_off
1413 || b->section == NULL
1414 || !(section_is_overlay (b->section)))
1416 /* No overlay handling: just remove the breakpoint. */
1418 if (b->loc_type == bp_loc_hardware_breakpoint)
1419 val = target_remove_hw_breakpoint (b->address,
1420 b->shadow_contents);
1422 val = target_remove_breakpoint (b->address, b->shadow_contents);
1426 /* This breakpoint is in an overlay section.
1427 Did we set a breakpoint at the LMA? */
1428 if (!overlay_events_enabled)
1430 /* Yes -- overlay event support is not active, so we
1431 should have set a breakpoint at the LMA. Remove it.
1433 CORE_ADDR addr = overlay_unmapped_address (b->address,
1435 /* Ignore any failures: if the LMA is in ROM, we will
1436 have already warned when we failed to insert it. */
1437 if (b->loc_type == bp_loc_hardware_breakpoint)
1438 target_remove_hw_breakpoint (addr, b->shadow_contents);
1440 target_remove_breakpoint (addr, b->shadow_contents);
1442 /* Did we set a breakpoint at the VMA?
1443 If so, we will have marked the breakpoint 'inserted'. */
1446 /* Yes -- remove it. Previously we did not bother to
1447 remove the breakpoint if the section had been
1448 unmapped, but let's not rely on that being safe. We
1449 don't know what the overlay manager might do. */
1450 if (b->loc_type == bp_loc_hardware_breakpoint)
1451 val = target_remove_hw_breakpoint (b->address,
1452 b->shadow_contents);
1454 val = target_remove_breakpoint (b->address,
1455 b->shadow_contents);
1459 /* No -- not inserted, so no need to remove. No error. */
1465 b->inserted = (is == mark_inserted);
1467 else if (b->loc_type == bp_loc_hardware_watchpoint
1468 && breakpoint_enabled (b->owner)
1474 b->inserted = (is == mark_inserted);
1475 /* Walk down the saved value chain. */
1476 for (v = b->owner->val_chain; v; v = v->next)
1478 /* For each memory reference remove the watchpoint
1480 if (VALUE_LVAL (v) == lval_memory
1481 && ! VALUE_LAZY (v))
1483 struct type *vtype = check_typedef (value_type (v));
1485 if (v == b->owner->val_chain
1486 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1487 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1492 addr = VALUE_ADDRESS (v) + value_offset (v);
1493 len = TYPE_LENGTH (value_type (v));
1495 if (b->owner->type == bp_read_watchpoint)
1497 else if (b->owner->type == bp_access_watchpoint)
1500 val = target_remove_watchpoint (addr, len, type);
1507 /* Failure to remove any of the hardware watchpoints comes here. */
1508 if ((is == mark_uninserted) && (b->inserted))
1509 warning ("Could not remove hardware watchpoint %d.",
1512 else if ((b->owner->type == bp_catch_fork ||
1513 b->owner->type == bp_catch_vfork ||
1514 b->owner->type == bp_catch_exec)
1515 && breakpoint_enabled (b->owner)
1519 switch (b->owner->type)
1522 val = target_remove_fork_catchpoint (PIDGET (inferior_ptid));
1524 case bp_catch_vfork:
1525 val = target_remove_vfork_catchpoint (PIDGET (inferior_ptid));
1528 val = target_remove_exec_catchpoint (PIDGET (inferior_ptid));
1531 warning ("Internal error, %s line %d.", __FILE__, __LINE__);
1536 b->inserted = (is == mark_inserted);
1538 else if ((b->owner->type == bp_catch_catch ||
1539 b->owner->type == bp_catch_throw)
1540 && breakpoint_enabled (b->owner)
1544 val = target_remove_breakpoint (b->address, b->shadow_contents);
1547 b->inserted = (is == mark_inserted);
1549 else if (ep_is_exception_catchpoint (b->owner)
1550 && b->inserted /* sometimes previous insert doesn't happen */
1551 && breakpoint_enabled (b->owner)
1555 val = target_remove_breakpoint (b->address, b->shadow_contents);
1559 b->inserted = (is == mark_inserted);
1565 /* Clear the "inserted" flag in all breakpoints. */
1568 mark_breakpoints_out (void)
1570 struct bp_location *bpt;
1572 ALL_BP_LOCATIONS (bpt)
1576 /* Clear the "inserted" flag in all breakpoints and delete any
1577 breakpoints which should go away between runs of the program.
1579 Plus other such housekeeping that has to be done for breakpoints
1582 Note: this function gets called at the end of a run (by
1583 generic_mourn_inferior) and when a run begins (by
1584 init_wait_for_inferior). */
1589 breakpoint_init_inferior (enum inf_context context)
1591 struct breakpoint *b, *temp;
1592 struct bp_location *bpt;
1593 static int warning_needed = 0;
1595 ALL_BP_LOCATIONS (bpt)
1598 ALL_BREAKPOINTS_SAFE (b, temp)
1603 case bp_watchpoint_scope:
1605 /* If the call dummy breakpoint is at the entry point it will
1606 cause problems when the inferior is rerun, so we better
1609 Also get rid of scope breakpoints. */
1610 delete_breakpoint (b);
1614 case bp_hardware_watchpoint:
1615 case bp_read_watchpoint:
1616 case bp_access_watchpoint:
1618 /* Likewise for watchpoints on local expressions. */
1619 if (b->exp_valid_block != NULL)
1620 delete_breakpoint (b);
1621 if (context == inf_starting)
1623 /* Reset val field to force reread of starting value
1624 in insert_breakpoints. */
1626 value_free (b->val);
1631 /* Likewise for exception catchpoints in dynamic-linked
1632 executables where required */
1633 if (ep_is_exception_catchpoint (b)
1634 && deprecated_exception_catchpoints_are_fragile)
1637 delete_breakpoint (b);
1643 if (deprecated_exception_catchpoints_are_fragile)
1644 deprecated_exception_support_initialized = 0;
1646 /* Don't issue the warning unless it's really needed... */
1647 if (warning_needed && (context != inf_exited))
1649 warning ("Exception catchpoints from last run were deleted.");
1650 warning ("You must reinsert them explicitly.");
1655 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1656 exists at PC. It returns ordinary_breakpoint_here if it's an
1657 ordinary breakpoint, or permanent_breakpoint_here if it's a
1658 permanent breakpoint.
1659 - When continuing from a location with an ordinary breakpoint, we
1660 actually single step once before calling insert_breakpoints.
1661 - When continuing from a localion with a permanent breakpoint, we
1662 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1663 the target, to advance the PC past the breakpoint. */
1665 enum breakpoint_here
1666 breakpoint_here_p (CORE_ADDR pc)
1668 struct bp_location *bpt;
1669 int any_breakpoint_here = 0;
1671 ALL_BP_LOCATIONS (bpt)
1673 if (bpt->loc_type != bp_loc_software_breakpoint
1674 && bpt->loc_type != bp_loc_hardware_breakpoint)
1677 if ((breakpoint_enabled (bpt->owner)
1678 || bpt->owner->enable_state == bp_permanent)
1679 && bpt->address == pc) /* bp is enabled and matches pc */
1681 if (overlay_debugging
1682 && section_is_overlay (bpt->section)
1683 && !section_is_mapped (bpt->section))
1684 continue; /* unmapped overlay -- can't be a match */
1685 else if (bpt->owner->enable_state == bp_permanent)
1686 return permanent_breakpoint_here;
1688 any_breakpoint_here = 1;
1692 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
1696 /* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(),
1697 but it only returns true if there is actually a breakpoint inserted
1701 breakpoint_inserted_here_p (CORE_ADDR pc)
1703 struct bp_location *bpt;
1705 ALL_BP_LOCATIONS (bpt)
1707 if (bpt->loc_type != bp_loc_software_breakpoint
1708 && bpt->loc_type != bp_loc_hardware_breakpoint)
1712 && bpt->address == pc) /* bp is inserted and matches pc */
1714 if (overlay_debugging
1715 && section_is_overlay (bpt->section)
1716 && !section_is_mapped (bpt->section))
1717 continue; /* unmapped overlay -- can't be a match */
1726 /* This function returns non-zero iff there is a software breakpoint
1730 software_breakpoint_inserted_here_p (CORE_ADDR pc)
1732 struct bp_location *bpt;
1733 int any_breakpoint_here = 0;
1735 ALL_BP_LOCATIONS (bpt)
1737 if (bpt->loc_type != bp_loc_software_breakpoint)
1740 if ((breakpoint_enabled (bpt->owner)
1741 || bpt->owner->enable_state == bp_permanent)
1743 && bpt->address == pc) /* bp is enabled and matches pc */
1745 if (overlay_debugging
1746 && section_is_overlay (bpt->section)
1747 && !section_is_mapped (bpt->section))
1748 continue; /* unmapped overlay -- can't be a match */
1757 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
1758 PC is valid for process/thread PTID. */
1761 breakpoint_thread_match (CORE_ADDR pc, ptid_t ptid)
1763 struct bp_location *bpt;
1766 thread = pid_to_thread_id (ptid);
1768 ALL_BP_LOCATIONS (bpt)
1770 if (bpt->loc_type != bp_loc_software_breakpoint
1771 && bpt->loc_type != bp_loc_hardware_breakpoint)
1774 if ((breakpoint_enabled (bpt->owner)
1775 || bpt->owner->enable_state == bp_permanent)
1776 && bpt->address == pc
1777 && (bpt->owner->thread == -1 || bpt->owner->thread == thread))
1779 if (overlay_debugging
1780 && section_is_overlay (bpt->section)
1781 && !section_is_mapped (bpt->section))
1782 continue; /* unmapped overlay -- can't be a match */
1792 /* bpstat stuff. External routines' interfaces are documented
1796 ep_is_catchpoint (struct breakpoint *ep)
1799 (ep->type == bp_catch_load)
1800 || (ep->type == bp_catch_unload)
1801 || (ep->type == bp_catch_fork)
1802 || (ep->type == bp_catch_vfork)
1803 || (ep->type == bp_catch_exec)
1804 || (ep->type == bp_catch_catch)
1805 || (ep->type == bp_catch_throw);
1807 /* ??rehrauer: Add more kinds here, as are implemented... */
1811 ep_is_shlib_catchpoint (struct breakpoint *ep)
1814 (ep->type == bp_catch_load)
1815 || (ep->type == bp_catch_unload);
1819 ep_is_exception_catchpoint (struct breakpoint *ep)
1822 (ep->type == bp_catch_catch)
1823 || (ep->type == bp_catch_throw);
1826 /* Clear a bpstat so that it says we are not at any breakpoint.
1827 Also free any storage that is part of a bpstat. */
1830 bpstat_clear (bpstat *bsp)
1841 if (p->old_val != NULL)
1842 value_free (p->old_val);
1843 free_command_lines (&p->commands);
1850 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1851 is part of the bpstat is copied as well. */
1854 bpstat_copy (bpstat bs)
1858 bpstat retval = NULL;
1863 for (; bs != NULL; bs = bs->next)
1865 tmp = (bpstat) xmalloc (sizeof (*tmp));
1866 memcpy (tmp, bs, sizeof (*tmp));
1867 if (bs->commands != NULL)
1868 tmp->commands = copy_command_lines (bs->commands);
1869 if (bs->old_val != NULL)
1870 tmp->old_val = value_copy (bs->old_val);
1873 /* This is the first thing in the chain. */
1883 /* Find the bpstat associated with this breakpoint */
1886 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
1891 for (; bsp != NULL; bsp = bsp->next)
1893 if (bsp->breakpoint_at == breakpoint)
1899 /* Find a step_resume breakpoint associated with this bpstat.
1900 (If there are multiple step_resume bp's on the list, this function
1901 will arbitrarily pick one.)
1903 It is an error to use this function if BPSTAT doesn't contain a
1904 step_resume breakpoint.
1906 See wait_for_inferior's use of this function. */
1908 bpstat_find_step_resume_breakpoint (bpstat bsp)
1913 error ("Internal error (bpstat_find_step_resume_breakpoint)");
1915 current_thread = pid_to_thread_id (inferior_ptid);
1917 for (; bsp != NULL; bsp = bsp->next)
1919 if ((bsp->breakpoint_at != NULL) &&
1920 (bsp->breakpoint_at->type == bp_step_resume) &&
1921 (bsp->breakpoint_at->thread == current_thread ||
1922 bsp->breakpoint_at->thread == -1))
1923 return bsp->breakpoint_at;
1926 error ("Internal error (no step_resume breakpoint found)");
1930 /* Return the breakpoint number of the first breakpoint we are stopped
1931 at. *BSP upon return is a bpstat which points to the remaining
1932 breakpoints stopped at (but which is not guaranteed to be good for
1933 anything but further calls to bpstat_num).
1934 Return 0 if passed a bpstat which does not indicate any breakpoints. */
1937 bpstat_num (bpstat *bsp)
1939 struct breakpoint *b;
1942 return 0; /* No more breakpoint values */
1945 b = (*bsp)->breakpoint_at;
1946 *bsp = (*bsp)->next;
1948 return -1; /* breakpoint that's been deleted since */
1950 return b->number; /* We have its number */
1954 /* Modify BS so that the actions will not be performed. */
1957 bpstat_clear_actions (bpstat bs)
1959 for (; bs != NULL; bs = bs->next)
1961 free_command_lines (&bs->commands);
1962 if (bs->old_val != NULL)
1964 value_free (bs->old_val);
1970 /* Stub for cleaning up our state if we error-out of a breakpoint command */
1972 cleanup_executing_breakpoints (void *ignore)
1974 executing_breakpoint_commands = 0;
1977 /* Execute all the commands associated with all the breakpoints at this
1978 location. Any of these commands could cause the process to proceed
1979 beyond this point, etc. We look out for such changes by checking
1980 the global "breakpoint_proceeded" after each command. */
1983 bpstat_do_actions (bpstat *bsp)
1986 struct cleanup *old_chain;
1988 /* Avoid endless recursion if a `source' command is contained
1990 if (executing_breakpoint_commands)
1993 executing_breakpoint_commands = 1;
1994 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
1997 /* Note that (as of this writing), our callers all appear to
1998 be passing us the address of global stop_bpstat. And, if
1999 our calls to execute_control_command cause the inferior to
2000 proceed, that global (and hence, *bsp) will change.
2002 We must be careful to not touch *bsp unless the inferior
2003 has not proceeded. */
2005 /* This pointer will iterate over the list of bpstat's. */
2008 breakpoint_proceeded = 0;
2009 for (; bs != NULL; bs = bs->next)
2011 struct command_line *cmd;
2012 struct cleanup *this_cmd_tree_chain;
2014 /* Take ownership of the BSP's command tree, if it has one.
2016 The command tree could legitimately contain commands like
2017 'step' and 'next', which call clear_proceed_status, which
2018 frees stop_bpstat's command tree. To make sure this doesn't
2019 free the tree we're executing out from under us, we need to
2020 take ownership of the tree ourselves. Since a given bpstat's
2021 commands are only executed once, we don't need to copy it; we
2022 can clear the pointer in the bpstat, and make sure we free
2023 the tree when we're done. */
2026 this_cmd_tree_chain = make_cleanup_free_command_lines (&cmd);
2030 execute_control_command (cmd);
2032 if (breakpoint_proceeded)
2038 /* We can free this command tree now. */
2039 do_cleanups (this_cmd_tree_chain);
2041 if (breakpoint_proceeded)
2042 /* The inferior is proceeded by the command; bomb out now.
2043 The bpstat chain has been blown away by wait_for_inferior.
2044 But since execution has stopped again, there is a new bpstat
2045 to look at, so start over. */
2048 do_cleanups (old_chain);
2051 /* This is the normal print function for a bpstat. In the future,
2052 much of this logic could (should?) be moved to bpstat_stop_status,
2053 by having it set different print_it values.
2055 Current scheme: When we stop, bpstat_print() is called. It loops
2056 through the bpstat list of things causing this stop, calling the
2057 print_bp_stop_message function on each one. The behavior of the
2058 print_bp_stop_message function depends on the print_it field of
2059 bpstat. If such field so indicates, call this function here.
2061 Return values from this routine (ultimately used by bpstat_print()
2062 and normal_stop() to decide what to do):
2063 PRINT_NOTHING: Means we already printed all we needed to print,
2064 don't print anything else.
2065 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2066 that something to be followed by a location.
2067 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2068 that something to be followed by a location.
2069 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2072 static enum print_stop_action
2073 print_it_typical (bpstat bs)
2075 struct cleanup *old_chain, *ui_out_chain;
2076 struct ui_stream *stb;
2077 stb = ui_out_stream_new (uiout);
2078 old_chain = make_cleanup_ui_out_stream_delete (stb);
2079 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2080 which has since been deleted. */
2081 if (bs->breakpoint_at == NULL)
2082 return PRINT_UNKNOWN;
2084 switch (bs->breakpoint_at->type)
2087 case bp_hardware_breakpoint:
2088 if (bs->breakpoint_at->loc->address != bs->breakpoint_at->loc->requested_address)
2089 breakpoint_adjustment_warning (bs->breakpoint_at->loc->requested_address,
2090 bs->breakpoint_at->loc->address,
2091 bs->breakpoint_at->number, 1);
2092 annotate_breakpoint (bs->breakpoint_at->number);
2093 ui_out_text (uiout, "\nBreakpoint ");
2094 if (ui_out_is_mi_like_p (uiout))
2095 ui_out_field_string (uiout, "reason", "breakpoint-hit");
2096 ui_out_field_int (uiout, "bkptno", bs->breakpoint_at->number);
2097 ui_out_text (uiout, ", ");
2098 return PRINT_SRC_AND_LOC;
2101 case bp_shlib_event:
2102 /* Did we stop because the user set the stop_on_solib_events
2103 variable? (If so, we report this as a generic, "Stopped due
2104 to shlib event" message.) */
2105 printf_filtered ("Stopped due to shared library event\n");
2106 return PRINT_NOTHING;
2109 case bp_thread_event:
2110 /* Not sure how we will get here.
2111 GDB should not stop for these breakpoints. */
2112 printf_filtered ("Thread Event Breakpoint: gdb should not stop!\n");
2113 return PRINT_NOTHING;
2116 case bp_overlay_event:
2117 /* By analogy with the thread event, GDB should not stop for these. */
2118 printf_filtered ("Overlay Event Breakpoint: gdb should not stop!\n");
2119 return PRINT_NOTHING;
2123 annotate_catchpoint (bs->breakpoint_at->number);
2124 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
2125 printf_filtered ("loaded");
2126 printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname);
2127 return PRINT_SRC_AND_LOC;
2130 case bp_catch_unload:
2131 annotate_catchpoint (bs->breakpoint_at->number);
2132 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
2133 printf_filtered ("unloaded");
2134 printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname);
2135 return PRINT_SRC_AND_LOC;
2139 annotate_catchpoint (bs->breakpoint_at->number);
2140 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
2141 printf_filtered ("forked");
2142 printf_filtered (" process %d), ",
2143 bs->breakpoint_at->forked_inferior_pid);
2144 return PRINT_SRC_AND_LOC;
2147 case bp_catch_vfork:
2148 annotate_catchpoint (bs->breakpoint_at->number);
2149 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
2150 printf_filtered ("vforked");
2151 printf_filtered (" process %d), ",
2152 bs->breakpoint_at->forked_inferior_pid);
2153 return PRINT_SRC_AND_LOC;
2157 annotate_catchpoint (bs->breakpoint_at->number);
2158 printf_filtered ("\nCatchpoint %d (exec'd %s), ",
2159 bs->breakpoint_at->number,
2160 bs->breakpoint_at->exec_pathname);
2161 return PRINT_SRC_AND_LOC;
2164 case bp_catch_catch:
2165 if (current_exception_event &&
2166 (CURRENT_EXCEPTION_KIND == EX_EVENT_CATCH))
2168 annotate_catchpoint (bs->breakpoint_at->number);
2169 printf_filtered ("\nCatchpoint %d (exception caught), ",
2170 bs->breakpoint_at->number);
2171 printf_filtered ("throw location ");
2172 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
2173 printf_filtered ("%s:%d",
2174 CURRENT_EXCEPTION_THROW_FILE,
2175 CURRENT_EXCEPTION_THROW_LINE);
2177 printf_filtered ("unknown");
2179 printf_filtered (", catch location ");
2180 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
2181 printf_filtered ("%s:%d",
2182 CURRENT_EXCEPTION_CATCH_FILE,
2183 CURRENT_EXCEPTION_CATCH_LINE);
2185 printf_filtered ("unknown");
2187 printf_filtered ("\n");
2188 /* don't bother to print location frame info */
2189 return PRINT_SRC_ONLY;
2193 /* really throw, some other bpstat will handle it */
2194 return PRINT_UNKNOWN;
2198 case bp_catch_throw:
2199 if (current_exception_event &&
2200 (CURRENT_EXCEPTION_KIND == EX_EVENT_THROW))
2202 annotate_catchpoint (bs->breakpoint_at->number);
2203 printf_filtered ("\nCatchpoint %d (exception thrown), ",
2204 bs->breakpoint_at->number);
2205 printf_filtered ("throw location ");
2206 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
2207 printf_filtered ("%s:%d",
2208 CURRENT_EXCEPTION_THROW_FILE,
2209 CURRENT_EXCEPTION_THROW_LINE);
2211 printf_filtered ("unknown");
2213 printf_filtered (", catch location ");
2214 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
2215 printf_filtered ("%s:%d",
2216 CURRENT_EXCEPTION_CATCH_FILE,
2217 CURRENT_EXCEPTION_CATCH_LINE);
2219 printf_filtered ("unknown");
2221 printf_filtered ("\n");
2222 /* don't bother to print location frame info */
2223 return PRINT_SRC_ONLY;
2227 /* really catch, some other bpstat will handle it */
2228 return PRINT_UNKNOWN;
2233 case bp_hardware_watchpoint:
2234 if (bs->old_val != NULL)
2236 annotate_watchpoint (bs->breakpoint_at->number);
2237 if (ui_out_is_mi_like_p (uiout))
2238 ui_out_field_string (uiout, "reason", "watchpoint-trigger");
2239 mention (bs->breakpoint_at);
2240 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2241 ui_out_text (uiout, "\nOld value = ");
2242 value_print (bs->old_val, stb->stream, 0, Val_pretty_default);
2243 ui_out_field_stream (uiout, "old", stb);
2244 ui_out_text (uiout, "\nNew value = ");
2245 value_print (bs->breakpoint_at->val, stb->stream, 0, Val_pretty_default);
2246 ui_out_field_stream (uiout, "new", stb);
2247 do_cleanups (ui_out_chain);
2248 ui_out_text (uiout, "\n");
2249 value_free (bs->old_val);
2252 /* More than one watchpoint may have been triggered. */
2253 return PRINT_UNKNOWN;
2256 case bp_read_watchpoint:
2257 if (ui_out_is_mi_like_p (uiout))
2258 ui_out_field_string (uiout, "reason", "read-watchpoint-trigger");
2259 mention (bs->breakpoint_at);
2260 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2261 ui_out_text (uiout, "\nValue = ");
2262 value_print (bs->breakpoint_at->val, stb->stream, 0, Val_pretty_default);
2263 ui_out_field_stream (uiout, "value", stb);
2264 do_cleanups (ui_out_chain);
2265 ui_out_text (uiout, "\n");
2266 return PRINT_UNKNOWN;
2269 case bp_access_watchpoint:
2270 if (bs->old_val != NULL)
2272 annotate_watchpoint (bs->breakpoint_at->number);
2273 if (ui_out_is_mi_like_p (uiout))
2274 ui_out_field_string (uiout, "reason", "access-watchpoint-trigger");
2275 mention (bs->breakpoint_at);
2276 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2277 ui_out_text (uiout, "\nOld value = ");
2278 value_print (bs->old_val, stb->stream, 0, Val_pretty_default);
2279 ui_out_field_stream (uiout, "old", stb);
2280 value_free (bs->old_val);
2282 ui_out_text (uiout, "\nNew value = ");
2286 mention (bs->breakpoint_at);
2287 if (ui_out_is_mi_like_p (uiout))
2288 ui_out_field_string (uiout, "reason", "access-watchpoint-trigger");
2289 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2290 ui_out_text (uiout, "\nValue = ");
2292 value_print (bs->breakpoint_at->val, stb->stream, 0,Val_pretty_default);
2293 ui_out_field_stream (uiout, "new", stb);
2294 do_cleanups (ui_out_chain);
2295 ui_out_text (uiout, "\n");
2296 return PRINT_UNKNOWN;
2299 /* Fall through, we don't deal with these types of breakpoints
2303 if (ui_out_is_mi_like_p (uiout))
2304 ui_out_field_string (uiout, "reason", "function-finished");
2305 return PRINT_UNKNOWN;
2309 if (ui_out_is_mi_like_p (uiout))
2310 ui_out_field_string (uiout, "reason", "location-reached");
2311 return PRINT_UNKNOWN;
2316 case bp_longjmp_resume:
2317 case bp_step_resume:
2318 case bp_through_sigtramp:
2319 case bp_watchpoint_scope:
2322 return PRINT_UNKNOWN;
2326 /* Generic routine for printing messages indicating why we
2327 stopped. The behavior of this function depends on the value
2328 'print_it' in the bpstat structure. Under some circumstances we
2329 may decide not to print anything here and delegate the task to
2332 static enum print_stop_action
2333 print_bp_stop_message (bpstat bs)
2335 switch (bs->print_it)
2338 /* Nothing should be printed for this bpstat entry. */
2339 return PRINT_UNKNOWN;
2343 /* We still want to print the frame, but we already printed the
2344 relevant messages. */
2345 return PRINT_SRC_AND_LOC;
2348 case print_it_normal:
2349 /* Normal case. Call the breakpoint's print_it method, or
2350 print_it_typical. */
2351 if (bs->breakpoint_at != NULL && bs->breakpoint_at->ops != NULL
2352 && bs->breakpoint_at->ops->print_it != NULL)
2353 return bs->breakpoint_at->ops->print_it (bs->breakpoint_at);
2355 return print_it_typical (bs);
2359 internal_error (__FILE__, __LINE__,
2360 "print_bp_stop_message: unrecognized enum value");
2365 /* Print a message indicating what happened. This is called from
2366 normal_stop(). The input to this routine is the head of the bpstat
2367 list - a list of the eventpoints that caused this stop. This
2368 routine calls the generic print routine for printing a message
2369 about reasons for stopping. This will print (for example) the
2370 "Breakpoint n," part of the output. The return value of this
2373 PRINT_UNKNOWN: Means we printed nothing
2374 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2375 code to print the location. An example is
2376 "Breakpoint 1, " which should be followed by
2378 PRINT_SRC_ONLY: Means we printed something, but there is no need
2379 to also print the location part of the message.
2380 An example is the catch/throw messages, which
2381 don't require a location appended to the end.
2382 PRINT_NOTHING: We have done some printing and we don't need any
2383 further info to be printed.*/
2385 enum print_stop_action
2386 bpstat_print (bpstat bs)
2390 /* Maybe another breakpoint in the chain caused us to stop.
2391 (Currently all watchpoints go on the bpstat whether hit or not.
2392 That probably could (should) be changed, provided care is taken
2393 with respect to bpstat_explains_signal). */
2394 for (; bs; bs = bs->next)
2396 val = print_bp_stop_message (bs);
2397 if (val == PRINT_SRC_ONLY
2398 || val == PRINT_SRC_AND_LOC
2399 || val == PRINT_NOTHING)
2403 /* We reached the end of the chain, or we got a null BS to start
2404 with and nothing was printed. */
2405 return PRINT_UNKNOWN;
2408 /* Evaluate the expression EXP and return 1 if value is zero.
2409 This is used inside a catch_errors to evaluate the breakpoint condition.
2410 The argument is a "struct expression *" that has been cast to char * to
2411 make it pass through catch_errors. */
2414 breakpoint_cond_eval (void *exp)
2416 struct value *mark = value_mark ();
2417 int i = !value_true (evaluate_expression ((struct expression *) exp));
2418 value_free_to_mark (mark);
2422 /* Allocate a new bpstat and chain it to the current one. */
2425 bpstat_alloc (struct breakpoint *b, bpstat cbs /* Current "bs" value */ )
2429 bs = (bpstat) xmalloc (sizeof (*bs));
2431 bs->breakpoint_at = b;
2432 /* If the condition is false, etc., don't do the commands. */
2433 bs->commands = NULL;
2435 bs->print_it = print_it_normal;
2439 /* Possible return values for watchpoint_check (this can't be an enum
2440 because of check_errors). */
2441 /* The watchpoint has been deleted. */
2442 #define WP_DELETED 1
2443 /* The value has changed. */
2444 #define WP_VALUE_CHANGED 2
2445 /* The value has not changed. */
2446 #define WP_VALUE_NOT_CHANGED 3
2448 #define BP_TEMPFLAG 1
2449 #define BP_HARDWAREFLAG 2
2451 /* Check watchpoint condition. */
2454 watchpoint_check (void *p)
2456 bpstat bs = (bpstat) p;
2457 struct breakpoint *b;
2458 struct frame_info *fr;
2459 int within_current_scope;
2461 b = bs->breakpoint_at;
2463 if (b->exp_valid_block == NULL)
2464 within_current_scope = 1;
2467 /* There is no current frame at this moment. If we're going to have
2468 any chance of handling watchpoints on local variables, we'll need
2469 the frame chain (so we can determine if we're in scope). */
2470 reinit_frame_cache ();
2471 fr = frame_find_by_id (b->watchpoint_frame);
2472 within_current_scope = (fr != NULL);
2473 /* in_function_epilogue_p() returns a non-zero value if we're still
2474 in the function but the stack frame has already been invalidated.
2475 Since we can't rely on the values of local variables after the
2476 stack has been destroyed, we are treating the watchpoint in that
2477 state as `not changed' without further checking.
2479 vinschen/2003-09-04: The former implementation left out the case
2480 that the watchpoint frame couldn't be found by frame_find_by_id()
2481 because the current PC is currently in an epilogue. Calling
2482 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2483 if ((!within_current_scope || fr == get_current_frame ())
2484 && gdbarch_in_function_epilogue_p (current_gdbarch, read_pc ()))
2485 return WP_VALUE_NOT_CHANGED;
2486 if (fr && within_current_scope)
2487 /* If we end up stopping, the current frame will get selected
2488 in normal_stop. So this call to select_frame won't affect
2493 if (within_current_scope)
2495 /* We use value_{,free_to_}mark because it could be a
2496 *long* time before we return to the command level and
2497 call free_all_values. We can't call free_all_values because
2498 we might be in the middle of evaluating a function call. */
2500 struct value *mark = value_mark ();
2501 struct value *new_val = evaluate_expression (bs->breakpoint_at->exp);
2502 if (!value_equal (b->val, new_val))
2504 release_value (new_val);
2505 value_free_to_mark (mark);
2506 bs->old_val = b->val;
2508 /* We will stop here */
2509 return WP_VALUE_CHANGED;
2513 /* Nothing changed, don't do anything. */
2514 value_free_to_mark (mark);
2515 /* We won't stop here */
2516 return WP_VALUE_NOT_CHANGED;
2521 /* This seems like the only logical thing to do because
2522 if we temporarily ignored the watchpoint, then when
2523 we reenter the block in which it is valid it contains
2524 garbage (in the case of a function, it may have two
2525 garbage values, one before and one after the prologue).
2526 So we can't even detect the first assignment to it and
2527 watch after that (since the garbage may or may not equal
2528 the first value assigned). */
2529 /* We print all the stop information in print_it_typical(), but
2530 in this case, by the time we call print_it_typical() this bp
2531 will be deleted already. So we have no choice but print the
2532 information here. */
2533 if (ui_out_is_mi_like_p (uiout))
2534 ui_out_field_string (uiout, "reason", "watchpoint-scope");
2535 ui_out_text (uiout, "\nWatchpoint ");
2536 ui_out_field_int (uiout, "wpnum", bs->breakpoint_at->number);
2537 ui_out_text (uiout, " deleted because the program has left the block in\n\
2538 which its expression is valid.\n");
2540 if (b->related_breakpoint)
2541 b->related_breakpoint->disposition = disp_del_at_next_stop;
2542 b->disposition = disp_del_at_next_stop;
2548 /* Get a bpstat associated with having just stopped at address
2549 BP_ADDR in thread PTID. STOPPED_BY_WATCHPOINT is 1 if the
2550 target thinks we stopped due to a hardware watchpoint, 0 if we
2551 know we did not trigger a hardware watchpoint, and -1 if we do not know. */
2553 /* Determine whether we stopped at a breakpoint, etc, or whether we
2554 don't understand this stop. Result is a chain of bpstat's such that:
2556 if we don't understand the stop, the result is a null pointer.
2558 if we understand why we stopped, the result is not null.
2560 Each element of the chain refers to a particular breakpoint or
2561 watchpoint at which we have stopped. (We may have stopped for
2562 several reasons concurrently.)
2564 Each element of the chain has valid next, breakpoint_at,
2565 commands, FIXME??? fields. */
2568 bpstat_stop_status (CORE_ADDR bp_addr, ptid_t ptid, int stopped_by_watchpoint)
2570 struct breakpoint *b, *temp;
2571 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2572 int real_breakpoint = 0;
2573 /* Root of the chain of bpstat's */
2574 struct bpstats root_bs[1];
2575 /* Pointer to the last thing in the chain currently. */
2576 bpstat bs = root_bs;
2577 int thread_id = pid_to_thread_id (ptid);
2579 ALL_BREAKPOINTS_SAFE (b, temp)
2581 if (!breakpoint_enabled (b) && b->enable_state != bp_permanent)
2584 if (b->type != bp_watchpoint
2585 && b->type != bp_hardware_watchpoint
2586 && b->type != bp_read_watchpoint
2587 && b->type != bp_access_watchpoint
2588 && b->type != bp_hardware_breakpoint
2589 && b->type != bp_catch_fork
2590 && b->type != bp_catch_vfork
2591 && b->type != bp_catch_exec
2592 && b->type != bp_catch_catch
2593 && b->type != bp_catch_throw) /* a non-watchpoint bp */
2595 if (b->loc->address != bp_addr) /* address doesn't match */
2597 if (overlay_debugging /* unmapped overlay section */
2598 && section_is_overlay (b->loc->section)
2599 && !section_is_mapped (b->loc->section))
2603 /* Continuable hardware watchpoints are treated as non-existent if the
2604 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2605 some data address). Otherwise gdb won't stop on a break instruction
2606 in the code (not from a breakpoint) when a hardware watchpoint has
2609 if ((b->type == bp_hardware_watchpoint
2610 || b->type == bp_read_watchpoint
2611 || b->type == bp_access_watchpoint)
2612 && !stopped_by_watchpoint)
2615 if (b->type == bp_hardware_breakpoint)
2617 if (b->loc->address != bp_addr)
2619 if (overlay_debugging /* unmapped overlay section */
2620 && section_is_overlay (b->loc->section)
2621 && !section_is_mapped (b->loc->section))
2625 /* Is this a catchpoint of a load or unload? If so, did we
2626 get a load or unload of the specified library? If not,
2628 if ((b->type == bp_catch_load)
2629 #if defined(SOLIB_HAVE_LOAD_EVENT)
2630 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid))
2631 || ((b->dll_pathname != NULL)
2632 && (strcmp (b->dll_pathname,
2633 SOLIB_LOADED_LIBRARY_PATHNAME (
2634 PIDGET (inferior_ptid)))
2640 if ((b->type == bp_catch_unload)
2641 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2642 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid))
2643 || ((b->dll_pathname != NULL)
2644 && (strcmp (b->dll_pathname,
2645 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2646 PIDGET (inferior_ptid)))
2652 if ((b->type == bp_catch_fork)
2653 && !inferior_has_forked (PIDGET (inferior_ptid),
2654 &b->forked_inferior_pid))
2657 if ((b->type == bp_catch_vfork)
2658 && !inferior_has_vforked (PIDGET (inferior_ptid),
2659 &b->forked_inferior_pid))
2662 if ((b->type == bp_catch_exec)
2663 && !inferior_has_execd (PIDGET (inferior_ptid), &b->exec_pathname))
2666 if (ep_is_exception_catchpoint (b) &&
2667 !(current_exception_event = target_get_current_exception_event ()))
2670 /* Come here if it's a watchpoint, or if the break address matches */
2672 bs = bpstat_alloc (b, bs); /* Alloc a bpstat to explain stop */
2674 /* Watchpoints may change this, if not found to have triggered. */
2678 if (b->type == bp_watchpoint ||
2679 b->type == bp_hardware_watchpoint)
2681 char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n",
2683 struct cleanup *cleanups = make_cleanup (xfree, message);
2684 int e = catch_errors (watchpoint_check, bs, message,
2686 do_cleanups (cleanups);
2690 /* We've already printed what needs to be printed. */
2691 /* Actually this is superfluous, because by the time we
2692 call print_it_typical() the wp will be already deleted,
2693 and the function will return immediately. */
2694 bs->print_it = print_it_done;
2697 case WP_VALUE_CHANGED:
2701 case WP_VALUE_NOT_CHANGED:
2703 bs->print_it = print_it_noop;
2710 /* Error from catch_errors. */
2711 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2712 if (b->related_breakpoint)
2713 b->related_breakpoint->disposition = disp_del_at_next_stop;
2714 b->disposition = disp_del_at_next_stop;
2715 /* We've already printed what needs to be printed. */
2716 bs->print_it = print_it_done;
2722 else if (b->type == bp_read_watchpoint ||
2723 b->type == bp_access_watchpoint)
2729 if (!target_stopped_data_address (¤t_target, &addr))
2731 for (v = b->val_chain; v; v = v->next)
2733 if (VALUE_LVAL (v) == lval_memory
2734 && ! VALUE_LAZY (v))
2736 struct type *vtype = check_typedef (value_type (v));
2738 if (v == b->val_chain
2739 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
2740 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
2744 vaddr = VALUE_ADDRESS (v) + value_offset (v);
2745 /* Exact match not required. Within range is
2747 if (addr >= vaddr &&
2748 addr < vaddr + TYPE_LENGTH (value_type (v)))
2755 char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n",
2757 struct cleanup *cleanups = make_cleanup (xfree, message);
2758 int e = catch_errors (watchpoint_check, bs, message,
2760 do_cleanups (cleanups);
2764 /* We've already printed what needs to be printed. */
2765 bs->print_it = print_it_done;
2768 case WP_VALUE_CHANGED:
2769 if (b->type == bp_read_watchpoint)
2771 /* Don't stop: read watchpoints shouldn't fire if
2772 the value has changed. This is for targets
2773 which cannot set read-only watchpoints. */
2774 bs->print_it = print_it_noop;
2780 case WP_VALUE_NOT_CHANGED:
2787 /* Error from catch_errors. */
2788 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2789 if (b->related_breakpoint)
2790 b->related_breakpoint->disposition = disp_del_at_next_stop;
2791 b->disposition = disp_del_at_next_stop;
2792 /* We've already printed what needs to be printed. */
2793 bs->print_it = print_it_done;
2797 else /* found == 0 */
2799 /* This is a case where some watchpoint(s) triggered,
2800 but not at the address of this watchpoint (FOUND
2801 was left zero). So don't print anything for this
2803 bs->print_it = print_it_noop;
2810 /* By definition, an encountered breakpoint is a triggered
2814 real_breakpoint = 1;
2817 if (frame_id_p (b->frame_id)
2818 && !frame_id_eq (b->frame_id, get_frame_id (get_current_frame ())))
2822 int value_is_zero = 0;
2826 /* Need to select the frame, with all that implies
2827 so that the conditions will have the right context. */
2828 select_frame (get_current_frame ());
2830 = catch_errors (breakpoint_cond_eval, (b->cond),
2831 "Error in testing breakpoint condition:\n",
2833 /* FIXME-someday, should give breakpoint # */
2836 if (b->cond && value_is_zero)
2839 /* Don't consider this a hit. */
2842 else if (b->thread != -1 && b->thread != thread_id)
2845 /* Don't consider this a hit. */
2848 else if (b->ignore_count > 0)
2851 annotate_ignore_count_change ();
2856 /* We will stop here */
2857 if (b->disposition == disp_disable)
2858 b->enable_state = bp_disabled;
2861 bs->commands = b->commands;
2863 (strcmp ("silent", bs->commands->line) == 0
2864 || (xdb_commands && strcmp ("Q", bs->commands->line) == 0)))
2866 bs->commands = bs->commands->next;
2869 bs->commands = copy_command_lines (bs->commands);
2872 /* Print nothing for this entry if we dont stop or if we dont print. */
2873 if (bs->stop == 0 || bs->print == 0)
2874 bs->print_it = print_it_noop;
2877 bs->next = NULL; /* Terminate the chain */
2878 bs = root_bs->next; /* Re-grab the head of the chain */
2880 /* The value of a hardware watchpoint hasn't changed, but the
2881 intermediate memory locations we are watching may have. */
2882 if (bs && !bs->stop &&
2883 (bs->breakpoint_at->type == bp_hardware_watchpoint ||
2884 bs->breakpoint_at->type == bp_read_watchpoint ||
2885 bs->breakpoint_at->type == bp_access_watchpoint))
2887 remove_breakpoints ();
2888 insert_breakpoints ();
2893 /* Tell what to do about this bpstat. */
2895 bpstat_what (bpstat bs)
2897 /* Classify each bpstat as one of the following. */
2900 /* This bpstat element has no effect on the main_action. */
2903 /* There was a watchpoint, stop but don't print. */
2906 /* There was a watchpoint, stop and print. */
2909 /* There was a breakpoint but we're not stopping. */
2912 /* There was a breakpoint, stop but don't print. */
2915 /* There was a breakpoint, stop and print. */
2918 /* We hit the longjmp breakpoint. */
2921 /* We hit the longjmp_resume breakpoint. */
2924 /* We hit the step_resume breakpoint. */
2927 /* We hit the through_sigtramp breakpoint. */
2930 /* We hit the shared library event breakpoint. */
2933 /* We caught a shared library event. */
2936 /* This is just used to count how many enums there are. */
2940 /* Here is the table which drives this routine. So that we can
2941 format it pretty, we define some abbreviations for the
2942 enum bpstat_what codes. */
2943 #define kc BPSTAT_WHAT_KEEP_CHECKING
2944 #define ss BPSTAT_WHAT_STOP_SILENT
2945 #define sn BPSTAT_WHAT_STOP_NOISY
2946 #define sgl BPSTAT_WHAT_SINGLE
2947 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
2948 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
2949 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
2950 #define sr BPSTAT_WHAT_STEP_RESUME
2951 #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
2952 #define shl BPSTAT_WHAT_CHECK_SHLIBS
2953 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
2955 /* "Can't happen." Might want to print an error message.
2956 abort() is not out of the question, but chances are GDB is just
2957 a bit confused, not unusable. */
2958 #define err BPSTAT_WHAT_STOP_NOISY
2960 /* Given an old action and a class, come up with a new action. */
2961 /* One interesting property of this table is that wp_silent is the same
2962 as bp_silent and wp_noisy is the same as bp_noisy. That is because
2963 after stopping, the check for whether to step over a breakpoint
2964 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
2965 reference to how we stopped. We retain separate wp_silent and
2966 bp_silent codes in case we want to change that someday.
2968 Another possibly interesting property of this table is that
2969 there's a partial ordering, priority-like, of the actions. Once
2970 you've decided that some action is appropriate, you'll never go
2971 back and decide something of a lower priority is better. The
2974 kc < clr sgl shl shlr slr sn sr ss ts
2975 sgl < clrs shl shlr slr sn sr ss ts
2976 slr < err shl shlr sn sr ss ts
2977 clr < clrs err shl shlr sn sr ss ts
2978 clrs < err shl shlr sn sr ss ts
2979 ss < shl shlr sn sr ts
2986 What I think this means is that we don't need a damned table
2987 here. If you just put the rows and columns in the right order,
2988 it'd look awfully regular. We could simply walk the bpstat list
2989 and choose the highest priority action we find, with a little
2990 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
2991 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
2992 is messy anyway). */
2994 /* step_resume entries: a step resume breakpoint overrides another
2995 breakpoint of signal handling (see comment in wait_for_inferior
2996 at where we set the step_resume breakpoint). */
2997 /* We handle the through_sigtramp_breakpoint the same way; having both
2998 one of those and a step_resume_breakpoint is probably very rare (?). */
3000 static const enum bpstat_what_main_action
3001 table[(int) class_last][(int) BPSTAT_WHAT_LAST] =
3004 /* kc ss sn sgl slr clr clrs sr ts shl shlr
3007 {kc, ss, sn, sgl, slr, clr, clrs, sr, ts, shl, shlr},
3009 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
3011 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
3013 {sgl, ss, sn, sgl, slr, clrs, clrs, sr, ts, shl, shlr},
3015 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
3017 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
3019 {slr, ss, sn, slr, slr, err, err, sr, ts, shl, shlr},
3021 {clr, ss, sn, clrs, err, err, err, sr, ts, shl, shlr},
3023 {sr, sr, sr, sr, sr, sr, sr, sr, ts, shl, shlr},
3025 {ts, ts, ts, ts, ts, ts, ts, ts, ts, shl, shlr},
3027 {shl, shl, shl, shl, shl, shl, shl, shl, ts, shl, shlr},
3029 {shlr, shlr, shlr, shlr, shlr, shlr, shlr, shlr, ts, shlr, shlr}
3044 enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
3045 struct bpstat_what retval;
3047 retval.call_dummy = 0;
3048 for (; bs != NULL; bs = bs->next)
3050 enum class bs_class = no_effect;
3051 if (bs->breakpoint_at == NULL)
3052 /* I suspect this can happen if it was a momentary breakpoint
3053 which has since been deleted. */
3055 switch (bs->breakpoint_at->type)
3061 case bp_hardware_breakpoint:
3067 bs_class = bp_noisy;
3069 bs_class = bp_silent;
3072 bs_class = bp_nostop;
3075 case bp_hardware_watchpoint:
3076 case bp_read_watchpoint:
3077 case bp_access_watchpoint:
3081 bs_class = wp_noisy;
3083 bs_class = wp_silent;
3086 /* There was a watchpoint, but we're not stopping.
3087 This requires no further action. */
3088 bs_class = no_effect;
3091 bs_class = long_jump;
3093 case bp_longjmp_resume:
3094 bs_class = long_resume;
3096 case bp_step_resume:
3099 bs_class = step_resume;
3102 /* It is for the wrong frame. */
3103 bs_class = bp_nostop;
3105 case bp_through_sigtramp:
3106 bs_class = through_sig;
3108 case bp_watchpoint_scope:
3109 bs_class = bp_nostop;
3111 case bp_shlib_event:
3112 bs_class = shlib_event;
3114 case bp_thread_event:
3115 case bp_overlay_event:
3116 bs_class = bp_nostop;
3119 case bp_catch_unload:
3120 /* Only if this catchpoint triggered should we cause the
3121 step-out-of-dld behaviour. Otherwise, we ignore this
3124 bs_class = catch_shlib_event;
3126 bs_class = no_effect;
3129 case bp_catch_vfork:
3134 bs_class = bp_noisy;
3136 bs_class = bp_silent;
3139 /* There was a catchpoint, but we're not stopping.
3140 This requires no further action. */
3141 bs_class = no_effect;
3143 case bp_catch_catch:
3144 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_CATCH)
3145 bs_class = bp_nostop;
3147 bs_class = bs->print ? bp_noisy : bp_silent;
3149 case bp_catch_throw:
3150 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_THROW)
3151 bs_class = bp_nostop;
3153 bs_class = bs->print ? bp_noisy : bp_silent;
3156 /* Make sure the action is stop (silent or noisy),
3157 so infrun.c pops the dummy frame. */
3158 bs_class = bp_silent;
3159 retval.call_dummy = 1;
3162 current_action = table[(int) bs_class][(int) current_action];
3164 retval.main_action = current_action;
3168 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3169 without hardware support). This isn't related to a specific bpstat,
3170 just to things like whether watchpoints are set. */
3173 bpstat_should_step (void)
3175 struct breakpoint *b;
3177 if (breakpoint_enabled (b) && b->type == bp_watchpoint)
3182 /* Nonzero if there are enabled hardware watchpoints. */
3184 bpstat_have_active_hw_watchpoints (void)
3186 struct bp_location *bpt;
3187 ALL_BP_LOCATIONS (bpt)
3188 if (breakpoint_enabled (bpt->owner)
3190 && bpt->loc_type == bp_loc_hardware_watchpoint)
3196 /* Given a bpstat that records zero or more triggered eventpoints, this
3197 function returns another bpstat which contains only the catchpoints
3198 on that first list, if any. */
3200 bpstat_get_triggered_catchpoints (bpstat ep_list, bpstat *cp_list)
3202 struct bpstats root_bs[1];
3203 bpstat bs = root_bs;
3204 struct breakpoint *ep;
3207 bpstat_clear (cp_list);
3208 root_bs->next = NULL;
3210 for (; ep_list != NULL; ep_list = ep_list->next)
3212 /* Is this eventpoint a catchpoint? If not, ignore it. */
3213 ep = ep_list->breakpoint_at;
3216 if ((ep->type != bp_catch_load) &&
3217 (ep->type != bp_catch_unload) &&
3218 (ep->type != bp_catch_catch) &&
3219 (ep->type != bp_catch_throw))
3220 /* pai: (temp) ADD fork/vfork here!! */
3223 /* Yes; add it to the list. */
3224 bs = bpstat_alloc (ep, bs);
3229 #if defined(SOLIB_ADD)
3230 /* Also, for each triggered catchpoint, tag it with the name of
3231 the library that caused this trigger. (We copy the name now,
3232 because it's only guaranteed to be available NOW, when the
3233 catchpoint triggers. Clients who may wish to know the name
3234 later must get it from the catchpoint itself.) */
3235 if (ep->triggered_dll_pathname != NULL)
3236 xfree (ep->triggered_dll_pathname);
3237 if (ep->type == bp_catch_load)
3238 dll_pathname = SOLIB_LOADED_LIBRARY_PATHNAME (
3239 PIDGET (inferior_ptid));
3241 dll_pathname = SOLIB_UNLOADED_LIBRARY_PATHNAME (
3242 PIDGET (inferior_ptid));
3244 dll_pathname = NULL;
3248 ep->triggered_dll_pathname = (char *)
3249 xmalloc (strlen (dll_pathname) + 1);
3250 strcpy (ep->triggered_dll_pathname, dll_pathname);
3253 ep->triggered_dll_pathname = NULL;
3259 /* Print B to gdb_stdout. */
3261 print_one_breakpoint (struct breakpoint *b,
3262 CORE_ADDR *last_addr)
3264 struct command_line *l;
3266 struct ep_type_description
3271 static struct ep_type_description bptypes[] =
3273 {bp_none, "?deleted?"},
3274 {bp_breakpoint, "breakpoint"},
3275 {bp_hardware_breakpoint, "hw breakpoint"},
3276 {bp_until, "until"},
3277 {bp_finish, "finish"},
3278 {bp_watchpoint, "watchpoint"},
3279 {bp_hardware_watchpoint, "hw watchpoint"},
3280 {bp_read_watchpoint, "read watchpoint"},
3281 {bp_access_watchpoint, "acc watchpoint"},
3282 {bp_longjmp, "longjmp"},
3283 {bp_longjmp_resume, "longjmp resume"},
3284 {bp_step_resume, "step resume"},
3285 {bp_through_sigtramp, "sigtramp"},
3286 {bp_watchpoint_scope, "watchpoint scope"},
3287 {bp_call_dummy, "call dummy"},
3288 {bp_shlib_event, "shlib events"},
3289 {bp_thread_event, "thread events"},
3290 {bp_overlay_event, "overlay events"},
3291 {bp_catch_load, "catch load"},
3292 {bp_catch_unload, "catch unload"},
3293 {bp_catch_fork, "catch fork"},
3294 {bp_catch_vfork, "catch vfork"},
3295 {bp_catch_exec, "catch exec"},
3296 {bp_catch_catch, "catch catch"},
3297 {bp_catch_throw, "catch throw"}
3300 static char *bpdisps[] =
3301 {"del", "dstp", "dis", "keep"};
3302 static char bpenables[] = "nynny";
3303 char wrap_indent[80];
3304 struct ui_stream *stb = ui_out_stream_new (uiout);
3305 struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb);
3306 struct cleanup *bkpt_chain;
3309 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
3313 ui_out_field_int (uiout, "number", b->number);
3317 if (((int) b->type > (sizeof (bptypes) / sizeof (bptypes[0])))
3318 || ((int) b->type != bptypes[(int) b->type].type))
3319 internal_error (__FILE__, __LINE__,
3320 "bptypes table does not describe type #%d.",
3322 ui_out_field_string (uiout, "type", bptypes[(int) b->type].description);
3326 ui_out_field_string (uiout, "disp", bpdisps[(int) b->disposition]);
3330 ui_out_field_fmt (uiout, "enabled", "%c", bpenables[(int) b->enable_state]);
3331 ui_out_spaces (uiout, 2);
3334 strcpy (wrap_indent, " ");
3337 if (TARGET_ADDR_BIT <= 32)
3338 strcat (wrap_indent, " ");
3340 strcat (wrap_indent, " ");
3343 if (b->ops != NULL && b->ops->print_one != NULL)
3344 b->ops->print_one (b, last_addr);
3349 internal_error (__FILE__, __LINE__,
3350 "print_one_breakpoint: bp_none encountered\n");
3354 case bp_hardware_watchpoint:
3355 case bp_read_watchpoint:
3356 case bp_access_watchpoint:
3357 /* Field 4, the address, is omitted (which makes the columns
3358 not line up too nicely with the headers, but the effect
3359 is relatively readable). */
3361 ui_out_field_skip (uiout, "addr");
3363 print_expression (b->exp, stb->stream);
3364 ui_out_field_stream (uiout, "what", stb);
3368 case bp_catch_unload:
3369 /* Field 4, the address, is omitted (which makes the columns
3370 not line up too nicely with the headers, but the effect
3371 is relatively readable). */
3373 ui_out_field_skip (uiout, "addr");
3375 if (b->dll_pathname == NULL)
3377 ui_out_field_string (uiout, "what", "<any library>");
3378 ui_out_spaces (uiout, 1);
3382 ui_out_text (uiout, "library \"");
3383 ui_out_field_string (uiout, "what", b->dll_pathname);
3384 ui_out_text (uiout, "\" ");
3389 case bp_catch_vfork:
3390 /* Field 4, the address, is omitted (which makes the columns
3391 not line up too nicely with the headers, but the effect
3392 is relatively readable). */
3394 ui_out_field_skip (uiout, "addr");
3396 if (b->forked_inferior_pid != 0)
3398 ui_out_text (uiout, "process ");
3399 ui_out_field_int (uiout, "what", b->forked_inferior_pid);
3400 ui_out_spaces (uiout, 1);
3404 /* Field 4, the address, is omitted (which makes the columns
3405 not line up too nicely with the headers, but the effect
3406 is relatively readable). */
3408 ui_out_field_skip (uiout, "addr");
3410 if (b->exec_pathname != NULL)
3412 ui_out_text (uiout, "program \"");
3413 ui_out_field_string (uiout, "what", b->exec_pathname);
3414 ui_out_text (uiout, "\" ");
3418 case bp_catch_catch:
3419 /* Field 4, the address, is omitted (which makes the columns
3420 not line up too nicely with the headers, but the effect
3421 is relatively readable). */
3423 ui_out_field_skip (uiout, "addr");
3425 ui_out_field_string (uiout, "what", "exception catch");
3426 ui_out_spaces (uiout, 1);
3429 case bp_catch_throw:
3430 /* Field 4, the address, is omitted (which makes the columns
3431 not line up too nicely with the headers, but the effect
3432 is relatively readable). */
3434 ui_out_field_skip (uiout, "addr");
3436 ui_out_field_string (uiout, "what", "exception throw");
3437 ui_out_spaces (uiout, 1);
3441 case bp_hardware_breakpoint:
3445 case bp_longjmp_resume:
3446 case bp_step_resume:
3447 case bp_through_sigtramp:
3448 case bp_watchpoint_scope:
3450 case bp_shlib_event:
3451 case bp_thread_event:
3452 case bp_overlay_event:
3457 ui_out_field_string (uiout, "addr", "<PENDING>");
3459 ui_out_field_core_addr (uiout, "addr", b->loc->address);
3462 *last_addr = b->loc->address;
3465 sym = find_pc_sect_function (b->loc->address, b->loc->section);
3468 ui_out_text (uiout, "in ");
3469 ui_out_field_string (uiout, "func",
3470 SYMBOL_PRINT_NAME (sym));
3471 ui_out_wrap_hint (uiout, wrap_indent);
3472 ui_out_text (uiout, " at ");
3474 ui_out_field_string (uiout, "file", b->source_file);
3475 ui_out_text (uiout, ":");
3476 ui_out_field_int (uiout, "line", b->line_number);
3478 else if (b->pending)
3480 ui_out_field_string (uiout, "pending", b->addr_string);
3484 print_address_symbolic (b->loc->address, stb->stream, demangle, "");
3485 ui_out_field_stream (uiout, "at", stb);
3490 if (b->thread != -1)
3492 /* FIXME: This seems to be redundant and lost here; see the
3493 "stop only in" line a little further down. */
3494 ui_out_text (uiout, " thread ");
3495 ui_out_field_int (uiout, "thread", b->thread);
3498 ui_out_text (uiout, "\n");
3500 if (frame_id_p (b->frame_id))
3503 ui_out_text (uiout, "\tstop only in stack frame at ");
3504 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3506 ui_out_field_core_addr (uiout, "frame", b->frame_id.stack_addr);
3507 ui_out_text (uiout, "\n");
3513 ui_out_text (uiout, "\tstop only if ");
3514 print_expression (b->cond, stb->stream);
3515 ui_out_field_stream (uiout, "cond", stb);
3516 ui_out_text (uiout, "\n");
3519 if (b->pending && b->cond_string)
3522 ui_out_text (uiout, "\tstop only if ");
3523 ui_out_field_string (uiout, "cond", b->cond_string);
3524 ui_out_text (uiout, "\n");
3527 if (b->thread != -1)
3529 /* FIXME should make an annotation for this */
3530 ui_out_text (uiout, "\tstop only in thread ");
3531 ui_out_field_int (uiout, "thread", b->thread);
3532 ui_out_text (uiout, "\n");
3535 if (show_breakpoint_hit_counts && b->hit_count)
3537 /* FIXME should make an annotation for this */
3538 if (ep_is_catchpoint (b))
3539 ui_out_text (uiout, "\tcatchpoint");
3541 ui_out_text (uiout, "\tbreakpoint");
3542 ui_out_text (uiout, " already hit ");
3543 ui_out_field_int (uiout, "times", b->hit_count);
3544 if (b->hit_count == 1)
3545 ui_out_text (uiout, " time\n");
3547 ui_out_text (uiout, " times\n");
3550 /* Output the count also if it is zero, but only if this is
3551 mi. FIXME: Should have a better test for this. */
3552 if (ui_out_is_mi_like_p (uiout))
3553 if (show_breakpoint_hit_counts && b->hit_count == 0)
3554 ui_out_field_int (uiout, "times", b->hit_count);
3556 if (b->ignore_count)
3559 ui_out_text (uiout, "\tignore next ");
3560 ui_out_field_int (uiout, "ignore", b->ignore_count);
3561 ui_out_text (uiout, " hits\n");
3564 if ((l = b->commands))
3566 struct cleanup *script_chain;
3569 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
3570 print_command_lines (uiout, l, 4);
3571 do_cleanups (script_chain);
3573 do_cleanups (bkpt_chain);
3574 do_cleanups (old_chain);
3577 struct captured_breakpoint_query_args
3583 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
3585 struct captured_breakpoint_query_args *args = data;
3586 struct breakpoint *b;
3587 CORE_ADDR dummy_addr = 0;
3590 if (args->bnum == b->number)
3592 print_one_breakpoint (b, &dummy_addr);
3600 gdb_breakpoint_query (struct ui_out *uiout, int bnum, char **error_message)
3602 struct captured_breakpoint_query_args args;
3604 /* For the moment we don't trust print_one_breakpoint() to not throw
3606 return catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args,
3607 NULL, error_message, RETURN_MASK_ALL);
3610 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3611 catchpoints, et.al.). */
3614 user_settable_breakpoint (const struct breakpoint *b)
3616 return (b->type == bp_breakpoint
3617 || b->type == bp_catch_load
3618 || b->type == bp_catch_unload
3619 || b->type == bp_catch_fork
3620 || b->type == bp_catch_vfork
3621 || b->type == bp_catch_exec
3622 || b->type == bp_catch_catch
3623 || b->type == bp_catch_throw
3624 || b->type == bp_hardware_breakpoint
3625 || b->type == bp_watchpoint
3626 || b->type == bp_read_watchpoint
3627 || b->type == bp_access_watchpoint
3628 || b->type == bp_hardware_watchpoint);
3631 /* Print information on user settable breakpoint (watchpoint, etc)
3632 number BNUM. If BNUM is -1 print all user settable breakpoints.
3633 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3636 breakpoint_1 (int bnum, int allflag)
3638 struct breakpoint *b;
3639 CORE_ADDR last_addr = (CORE_ADDR) -1;
3640 int nr_printable_breakpoints;
3641 struct cleanup *bkpttbl_chain;
3643 /* Compute the number of rows in the table. */
3644 nr_printable_breakpoints = 0;
3647 || bnum == b->number)
3649 if (allflag || user_settable_breakpoint (b))
3650 nr_printable_breakpoints++;
3655 = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints,
3659 = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints,
3662 if (nr_printable_breakpoints > 0)
3663 annotate_breakpoints_headers ();
3664 if (nr_printable_breakpoints > 0)
3666 ui_out_table_header (uiout, 3, ui_left, "number", "Num"); /* 1 */
3667 if (nr_printable_breakpoints > 0)
3669 ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */
3670 if (nr_printable_breakpoints > 0)
3672 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
3673 if (nr_printable_breakpoints > 0)
3675 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
3678 if (nr_printable_breakpoints > 0)
3680 if (TARGET_ADDR_BIT <= 32)
3681 ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */
3683 ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */
3685 if (nr_printable_breakpoints > 0)
3687 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
3688 ui_out_table_body (uiout);
3689 if (nr_printable_breakpoints > 0)
3690 annotate_breakpoints_table ();
3694 || bnum == b->number)
3696 /* We only print out user settable breakpoints unless the
3698 if (allflag || user_settable_breakpoint (b))
3699 print_one_breakpoint (b, &last_addr);
3702 do_cleanups (bkpttbl_chain);
3704 if (nr_printable_breakpoints == 0)
3707 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
3709 ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n",
3714 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3715 that a comparison of an unsigned with -1 is always false. */
3716 if (last_addr != (CORE_ADDR) -1)
3717 set_next_address (last_addr);
3720 /* FIXME? Should this be moved up so that it is only called when
3721 there have been breakpoints? */
3722 annotate_breakpoints_table_end ();
3726 breakpoints_info (char *bnum_exp, int from_tty)
3731 bnum = parse_and_eval_long (bnum_exp);
3733 breakpoint_1 (bnum, 0);
3737 maintenance_info_breakpoints (char *bnum_exp, int from_tty)
3742 bnum = parse_and_eval_long (bnum_exp);
3744 breakpoint_1 (bnum, 1);
3747 /* Print a message describing any breakpoints set at PC. */
3750 describe_other_breakpoints (CORE_ADDR pc, asection *section)
3753 struct breakpoint *b;
3756 if (b->loc->address == pc) /* address match / overlay match */
3757 if (!b->pending && (!overlay_debugging || b->loc->section == section))
3761 printf_filtered ("Note: breakpoint%s ", (others > 1) ? "s" : "");
3763 if (b->loc->address == pc) /* address match / overlay match */
3764 if (!b->pending && (!overlay_debugging || b->loc->section == section))
3767 printf_filtered ("%d%s%s ",
3769 ((b->enable_state == bp_disabled ||
3770 b->enable_state == bp_shlib_disabled ||
3771 b->enable_state == bp_call_disabled)
3773 : b->enable_state == bp_permanent
3777 : ((others == 1) ? " and" : ""));
3779 printf_filtered ("also set at pc ");
3780 print_address_numeric (pc, 1, gdb_stdout);
3781 printf_filtered (".\n");
3785 /* Set the default place to put a breakpoint
3786 for the `break' command with no arguments. */
3789 set_default_breakpoint (int valid, CORE_ADDR addr, struct symtab *symtab,
3792 default_breakpoint_valid = valid;
3793 default_breakpoint_address = addr;
3794 default_breakpoint_symtab = symtab;
3795 default_breakpoint_line = line;
3798 /* Return true iff it is meaningful to use the address member of
3799 BPT. For some breakpoint types, the address member is irrelevant
3800 and it makes no sense to attempt to compare it to other addresses
3801 (or use it for any other purpose either).
3803 More specifically, each of the following breakpoint types will always
3804 have a zero valued address and we don't want check_duplicates() to mark
3805 breakpoints of any of these types to be a duplicate of an actual
3806 breakpoint at address zero:
3809 bp_hardware_watchpoint
3811 bp_access_watchpoint
3818 breakpoint_address_is_meaningful (struct breakpoint *bpt)
3820 enum bptype type = bpt->type;
3822 return (type != bp_watchpoint
3823 && type != bp_hardware_watchpoint
3824 && type != bp_read_watchpoint
3825 && type != bp_access_watchpoint
3826 && type != bp_catch_exec
3827 && type != bp_longjmp_resume
3828 && type != bp_catch_fork
3829 && type != bp_catch_vfork);
3832 /* Rescan breakpoints at the same address and section as BPT,
3833 marking the first one as "first" and any others as "duplicates".
3834 This is so that the bpt instruction is only inserted once.
3835 If we have a permanent breakpoint at the same place as BPT, make
3836 that one the official one, and the rest as duplicates. */
3839 check_duplicates (struct breakpoint *bpt)
3841 struct bp_location *b;
3843 struct bp_location *perm_bp = 0;
3844 CORE_ADDR address = bpt->loc->address;
3845 asection *section = bpt->loc->section;
3847 if (! breakpoint_address_is_meaningful (bpt))
3850 ALL_BP_LOCATIONS (b)
3851 if (b->owner->enable_state != bp_disabled
3852 && b->owner->enable_state != bp_shlib_disabled
3853 && !b->owner->pending
3854 && b->owner->enable_state != bp_call_disabled
3855 && b->address == address /* address / overlay match */
3856 && (!overlay_debugging || b->section == section)
3857 && breakpoint_address_is_meaningful (b->owner))
3859 /* Have we found a permanent breakpoint? */
3860 if (b->owner->enable_state == bp_permanent)
3867 b->duplicate = count > 1;
3870 /* If we found a permanent breakpoint at this address, go over the
3871 list again and declare all the other breakpoints there to be the
3875 perm_bp->duplicate = 0;
3877 /* Permanent breakpoint should always be inserted. */
3878 if (! perm_bp->inserted)
3879 internal_error (__FILE__, __LINE__,
3880 "allegedly permanent breakpoint is not "
3881 "actually inserted");
3883 ALL_BP_LOCATIONS (b)
3886 if (b->owner->enable_state != bp_disabled
3887 && b->owner->enable_state != bp_shlib_disabled
3888 && !b->owner->pending
3889 && b->owner->enable_state != bp_call_disabled
3890 && b->address == address /* address / overlay match */
3891 && (!overlay_debugging || b->section == section)
3892 && breakpoint_address_is_meaningful (b->owner))
3895 internal_error (__FILE__, __LINE__,
3896 "another breakpoint was inserted on top of "
3897 "a permanent breakpoint");
3906 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
3907 int bnum, int have_bnum)
3912 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
3913 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
3915 warning ("Breakpoint %d address previously adjusted from %s to %s.",
3916 bnum, astr1, astr2);
3918 warning ("Breakpoint address adjusted from %s to %s.", astr1, astr2);
3921 /* Adjust a breakpoint's address to account for architectural constraints
3922 on breakpoint placement. Return the adjusted address. Note: Very
3923 few targets require this kind of adjustment. For most targets,
3924 this function is simply the identity function. */
3927 adjust_breakpoint_address (CORE_ADDR bpaddr, enum bptype bptype)
3929 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch))
3931 /* Very few targets need any kind of breakpoint adjustment. */
3934 else if (bptype == bp_watchpoint
3935 || bptype == bp_hardware_watchpoint
3936 || bptype == bp_read_watchpoint
3937 || bptype == bp_access_watchpoint
3938 || bptype == bp_catch_fork
3939 || bptype == bp_catch_vfork
3940 || bptype == bp_catch_exec)
3942 /* Watchpoints and the various bp_catch_* eventpoints should not
3943 have their addresses modified. */
3948 CORE_ADDR adjusted_bpaddr;
3950 /* Some targets have architectural constraints on the placement
3951 of breakpoint instructions. Obtain the adjusted address. */
3952 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (current_gdbarch,
3955 /* An adjusted breakpoint address can significantly alter
3956 a user's expectations. Print a warning if an adjustment
3958 if (adjusted_bpaddr != bpaddr)
3959 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
3961 return adjusted_bpaddr;
3965 /* Allocate a struct bp_location. */
3967 static struct bp_location *
3968 allocate_bp_location (struct breakpoint *bpt, enum bptype bp_type)
3970 struct bp_location *loc, *loc_p;
3972 loc = xmalloc (sizeof (struct bp_location));
3973 memset (loc, 0, sizeof (*loc));
3983 case bp_longjmp_resume:
3984 case bp_step_resume:
3985 case bp_through_sigtramp:
3986 case bp_watchpoint_scope:
3988 case bp_shlib_event:
3989 case bp_thread_event:
3990 case bp_overlay_event:
3992 case bp_catch_unload:
3993 loc->loc_type = bp_loc_software_breakpoint;
3995 case bp_hardware_breakpoint:
3996 loc->loc_type = bp_loc_hardware_breakpoint;
3998 case bp_hardware_watchpoint:
3999 case bp_read_watchpoint:
4000 case bp_access_watchpoint:
4001 loc->loc_type = bp_loc_hardware_watchpoint;
4005 case bp_catch_vfork:
4007 case bp_catch_catch:
4008 case bp_catch_throw:
4009 loc->loc_type = bp_loc_other;
4012 internal_error (__FILE__, __LINE__, "unknown breakpoint type");
4015 /* Add this breakpoint to the end of the chain. */
4017 loc_p = bp_location_chain;
4019 bp_location_chain = loc;
4023 loc_p = loc_p->next;
4030 /* set_raw_breakpoint() is a low level routine for allocating and
4031 partially initializing a breakpoint of type BPTYPE. The newly
4032 created breakpoint's address, section, source file name, and line
4033 number are provided by SAL. The newly created and partially
4034 initialized breakpoint is added to the breakpoint chain and
4035 is also returned as the value of this function.
4037 It is expected that the caller will complete the initialization of
4038 the newly created breakpoint struct as well as output any status
4039 information regarding the creation of a new breakpoint. In
4040 particular, set_raw_breakpoint() does NOT set the breakpoint
4041 number! Care should be taken to not allow an error() to occur
4042 prior to completing the initialization of the breakpoint. If this
4043 should happen, a bogus breakpoint will be left on the chain. */
4046 set_raw_breakpoint (struct symtab_and_line sal, enum bptype bptype)
4048 struct breakpoint *b, *b1;
4050 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
4051 memset (b, 0, sizeof (*b));
4052 b->loc = allocate_bp_location (b, bptype);
4053 b->loc->requested_address = sal.pc;
4054 b->loc->address = adjust_breakpoint_address (b->loc->requested_address,
4056 if (sal.symtab == NULL)
4057 b->source_file = NULL;
4059 b->source_file = savestring (sal.symtab->filename,
4060 strlen (sal.symtab->filename));
4061 b->loc->section = sal.section;
4063 b->language = current_language->la_language;
4064 b->input_radix = input_radix;
4066 b->line_number = sal.line;
4067 b->enable_state = bp_enabled;
4070 b->ignore_count = 0;
4072 b->frame_id = null_frame_id;
4073 b->dll_pathname = NULL;
4074 b->triggered_dll_pathname = NULL;
4075 b->forked_inferior_pid = 0;
4076 b->exec_pathname = NULL;
4080 /* Add this breakpoint to the end of the chain
4081 so that a list of breakpoints will come out in order
4082 of increasing numbers. */
4084 b1 = breakpoint_chain;
4086 breakpoint_chain = b;
4094 check_duplicates (b);
4095 breakpoints_changed ();
4101 /* Note that the breakpoint object B describes a permanent breakpoint
4102 instruction, hard-wired into the inferior's code. */
4104 make_breakpoint_permanent (struct breakpoint *b)
4106 b->enable_state = bp_permanent;
4108 /* By definition, permanent breakpoints are already present in the code. */
4109 b->loc->inserted = 1;
4112 static struct breakpoint *
4113 create_internal_breakpoint (CORE_ADDR address, enum bptype type)
4115 static int internal_breakpoint_number = -1;
4116 struct symtab_and_line sal;
4117 struct breakpoint *b;
4119 init_sal (&sal); /* initialize to zeroes */
4122 sal.section = find_pc_overlay (sal.pc);
4124 b = set_raw_breakpoint (sal, type);
4125 b->number = internal_breakpoint_number--;
4126 b->disposition = disp_donttouch;
4133 create_longjmp_breakpoint (char *func_name)
4135 struct breakpoint *b;
4136 struct minimal_symbol *m;
4138 if (func_name == NULL)
4139 b = create_internal_breakpoint (0, bp_longjmp_resume);
4142 if ((m = lookup_minimal_symbol_text (func_name, NULL)) == NULL)
4145 b = create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m), bp_longjmp);
4148 b->enable_state = bp_disabled;
4151 b->addr_string = xstrdup (func_name);
4154 /* Call this routine when stepping and nexting to enable a breakpoint
4155 if we do a longjmp(). When we hit that breakpoint, call
4156 set_longjmp_resume_breakpoint() to figure out where we are going. */
4159 enable_longjmp_breakpoint (void)
4161 struct breakpoint *b;
4164 if (b->type == bp_longjmp)
4166 b->enable_state = bp_enabled;
4167 check_duplicates (b);
4172 disable_longjmp_breakpoint (void)
4174 struct breakpoint *b;
4177 if (b->type == bp_longjmp
4178 || b->type == bp_longjmp_resume)
4180 b->enable_state = bp_disabled;
4181 check_duplicates (b);
4186 create_overlay_event_breakpoint (char *func_name)
4188 struct breakpoint *b;
4189 struct minimal_symbol *m;
4191 if ((m = lookup_minimal_symbol_text (func_name, NULL)) == NULL)
4194 b = create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m),
4196 b->addr_string = xstrdup (func_name);
4198 if (overlay_debugging == ovly_auto)
4200 b->enable_state = bp_enabled;
4201 overlay_events_enabled = 1;
4205 b->enable_state = bp_disabled;
4206 overlay_events_enabled = 0;
4211 enable_overlay_breakpoints (void)
4213 struct breakpoint *b;
4216 if (b->type == bp_overlay_event)
4218 b->enable_state = bp_enabled;
4219 check_duplicates (b);
4220 overlay_events_enabled = 1;
4225 disable_overlay_breakpoints (void)
4227 struct breakpoint *b;
4230 if (b->type == bp_overlay_event)
4232 b->enable_state = bp_disabled;
4233 check_duplicates (b);
4234 overlay_events_enabled = 0;
4239 create_thread_event_breakpoint (CORE_ADDR address)
4241 struct breakpoint *b;
4243 b = create_internal_breakpoint (address, bp_thread_event);
4245 b->enable_state = bp_enabled;
4246 /* addr_string has to be used or breakpoint_re_set will delete me. */
4247 b->addr_string = xstrprintf ("*0x%s", paddr (b->loc->address));
4253 remove_thread_event_breakpoints (void)
4255 struct breakpoint *b, *temp;
4257 ALL_BREAKPOINTS_SAFE (b, temp)
4258 if (b->type == bp_thread_event)
4259 delete_breakpoint (b);
4262 struct captured_parse_breakpoint_args
4265 struct symtabs_and_lines *sals_p;
4266 char ***addr_string_p;
4270 struct lang_and_radix
4276 /* Cleanup helper routine to restore the current language and
4279 do_restore_lang_radix_cleanup (void *old)
4281 struct lang_and_radix *p = old;
4282 set_language (p->lang);
4283 input_radix = p->radix;
4286 /* Try and resolve a pending breakpoint. */
4288 resolve_pending_breakpoint (struct breakpoint *b)
4290 /* Try and reparse the breakpoint in case the shared library
4292 struct symtabs_and_lines sals;
4293 struct symtab_and_line pending_sal;
4294 char **cond_string = (char **) NULL;
4295 char *copy_arg = b->addr_string;
4300 struct ui_file *old_gdb_stderr;
4301 struct lang_and_radix old_lr;
4302 struct cleanup *old_chain;
4304 /* Set language, input-radix, then reissue breakpoint command.
4305 Ensure the language and input-radix are restored afterwards. */
4306 old_lr.lang = current_language->la_language;
4307 old_lr.radix = input_radix;
4308 old_chain = make_cleanup (do_restore_lang_radix_cleanup, &old_lr);
4310 set_language (b->language);
4311 input_radix = b->input_radix;
4312 rc = break_command_1 (b->addr_string, b->flag, b->from_tty, b);
4314 if (rc == GDB_RC_OK)
4315 /* Pending breakpoint has been resolved. */
4316 printf_filtered ("Pending breakpoint \"%s\" resolved\n", b->addr_string);
4318 do_cleanups (old_chain);
4324 remove_solib_event_breakpoints (void)
4326 struct breakpoint *b, *temp;
4328 ALL_BREAKPOINTS_SAFE (b, temp)
4329 if (b->type == bp_shlib_event)
4330 delete_breakpoint (b);
4334 create_solib_event_breakpoint (CORE_ADDR address)
4336 struct breakpoint *b;
4338 b = create_internal_breakpoint (address, bp_shlib_event);
4342 /* Disable any breakpoints that are on code in shared libraries. Only
4343 apply to enabled breakpoints, disabled ones can just stay disabled. */
4346 disable_breakpoints_in_shlibs (int silent)
4348 struct breakpoint *b;
4349 int disabled_shlib_breaks = 0;
4351 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
4354 #if defined (PC_SOLIB)
4355 if (((b->type == bp_breakpoint) ||
4356 (b->type == bp_hardware_breakpoint)) &&
4357 breakpoint_enabled (b) &&
4358 !b->loc->duplicate &&
4359 PC_SOLIB (b->loc->address))
4361 b->enable_state = bp_shlib_disabled;
4364 if (!disabled_shlib_breaks)
4366 target_terminal_ours_for_output ();
4367 warning ("Temporarily disabling shared library breakpoints:");
4369 disabled_shlib_breaks = 1;
4370 warning ("breakpoint #%d ", b->number);
4377 /* Disable any breakpoints that are in in an unloaded shared library. Only
4378 apply to enabled breakpoints, disabled ones can just stay disabled. */
4381 disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
4383 struct breakpoint *b;
4384 int disabled_shlib_breaks = 0;
4386 #if defined (PC_SOLIB)
4387 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
4390 if ((b->loc->loc_type == bp_loc_hardware_breakpoint
4391 || b->loc->loc_type == bp_loc_software_breakpoint)
4392 && breakpoint_enabled (b)
4393 && !b->loc->duplicate)
4395 char *so_name = PC_SOLIB (b->loc->address);
4397 && !strcmp (so_name, solib->so_name))
4399 b->enable_state = bp_shlib_disabled;
4400 /* At this point, we cannot rely on remove_breakpoint
4401 succeeding so we must mark the breakpoint as not inserted
4402 to prevent future errors occurring in remove_breakpoints. */
4403 b->loc->inserted = 0;
4404 if (!disabled_shlib_breaks)
4406 target_terminal_ours_for_output ();
4407 warning ("Temporarily disabling breakpoints for unloaded shared library \"%s\"",
4410 disabled_shlib_breaks = 1;
4417 /* Try to reenable any breakpoints in shared libraries. */
4419 re_enable_breakpoints_in_shlibs (void)
4421 struct breakpoint *b, *tmp;
4423 ALL_BREAKPOINTS_SAFE (b, tmp)
4425 if (b->enable_state == bp_shlib_disabled)
4429 /* Do not reenable the breakpoint if the shared library
4430 is still not mapped in. */
4431 lib = PC_SOLIB (b->loc->address);
4432 if (lib != NULL && target_read_memory (b->loc->address, buf, 1) == 0)
4433 b->enable_state = bp_enabled;
4435 else if (b->pending && (b->enable_state == bp_enabled))
4437 if (resolve_pending_breakpoint (b) == GDB_RC_OK)
4438 delete_breakpoint (b);
4446 solib_load_unload_1 (char *hookname, int tempflag, char *dll_pathname,
4447 char *cond_string, enum bptype bp_kind)
4449 struct breakpoint *b;
4450 struct symtabs_and_lines sals;
4451 struct cleanup *old_chain;
4452 struct cleanup *canonical_strings_chain = NULL;
4453 char *addr_start = hookname;
4454 char *addr_end = NULL;
4455 char **canonical = (char **) NULL;
4456 int thread = -1; /* All threads. */
4458 /* Set a breakpoint on the specified hook. */
4459 sals = decode_line_1 (&hookname, 1, (struct symtab *) NULL,
4460 0, &canonical, NULL);
4461 addr_end = hookname;
4463 if (sals.nelts == 0)
4465 warning ("Unable to set a breakpoint on dynamic linker callback.");
4466 warning ("Suggest linking with /opt/langtools/lib/end.o.");
4467 warning ("GDB will be unable to track shl_load/shl_unload calls");
4470 if (sals.nelts != 1)
4472 warning ("Unable to set unique breakpoint on dynamic linker callback.");
4473 warning ("GDB will be unable to track shl_load/shl_unload calls");
4477 /* Make sure that all storage allocated in decode_line_1 gets freed
4478 in case the following errors out. */
4479 old_chain = make_cleanup (xfree, sals.sals);
4480 if (canonical != (char **) NULL)
4482 make_cleanup (xfree, canonical);
4483 canonical_strings_chain = make_cleanup (null_cleanup, 0);
4484 if (canonical[0] != NULL)
4485 make_cleanup (xfree, canonical[0]);
4488 resolve_sal_pc (&sals.sals[0]);
4490 /* Remove the canonical strings from the cleanup, they are needed below. */
4491 if (canonical != (char **) NULL)
4492 discard_cleanups (canonical_strings_chain);
4494 b = set_raw_breakpoint (sals.sals[0], bp_kind);
4495 set_breakpoint_count (breakpoint_count + 1);
4496 b->number = breakpoint_count;
4498 b->cond_string = (cond_string == NULL) ?
4499 NULL : savestring (cond_string, strlen (cond_string));
4502 if (canonical != (char **) NULL && canonical[0] != NULL)
4503 b->addr_string = canonical[0];
4504 else if (addr_start)
4505 b->addr_string = savestring (addr_start, addr_end - addr_start);
4507 b->enable_state = bp_enabled;
4508 b->disposition = tempflag ? disp_del : disp_donttouch;
4510 if (dll_pathname == NULL)
4511 b->dll_pathname = NULL;
4514 b->dll_pathname = (char *) xmalloc (strlen (dll_pathname) + 1);
4515 strcpy (b->dll_pathname, dll_pathname);
4519 do_cleanups (old_chain);
4523 create_solib_load_event_breakpoint (char *hookname, int tempflag,
4524 char *dll_pathname, char *cond_string)
4526 solib_load_unload_1 (hookname, tempflag, dll_pathname,
4527 cond_string, bp_catch_load);
4531 create_solib_unload_event_breakpoint (char *hookname, int tempflag,
4532 char *dll_pathname, char *cond_string)
4534 solib_load_unload_1 (hookname, tempflag, dll_pathname,
4535 cond_string, bp_catch_unload);
4539 create_fork_vfork_event_catchpoint (int tempflag, char *cond_string,
4540 enum bptype bp_kind)
4542 struct symtab_and_line sal;
4543 struct breakpoint *b;
4544 int thread = -1; /* All threads. */
4551 b = set_raw_breakpoint (sal, bp_kind);
4552 set_breakpoint_count (breakpoint_count + 1);
4553 b->number = breakpoint_count;
4555 b->cond_string = (cond_string == NULL) ?
4556 NULL : savestring (cond_string, strlen (cond_string));
4558 b->addr_string = NULL;
4559 b->enable_state = bp_enabled;
4560 b->disposition = tempflag ? disp_del : disp_donttouch;
4561 b->forked_inferior_pid = 0;
4567 create_fork_event_catchpoint (int tempflag, char *cond_string)
4569 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_fork);
4573 create_vfork_event_catchpoint (int tempflag, char *cond_string)
4575 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_vfork);
4579 create_exec_event_catchpoint (int tempflag, char *cond_string)
4581 struct symtab_and_line sal;
4582 struct breakpoint *b;
4583 int thread = -1; /* All threads. */
4590 b = set_raw_breakpoint (sal, bp_catch_exec);
4591 set_breakpoint_count (breakpoint_count + 1);
4592 b->number = breakpoint_count;
4594 b->cond_string = (cond_string == NULL) ?
4595 NULL : savestring (cond_string, strlen (cond_string));
4597 b->addr_string = NULL;
4598 b->enable_state = bp_enabled;
4599 b->disposition = tempflag ? disp_del : disp_donttouch;
4605 hw_breakpoint_used_count (void)
4607 struct breakpoint *b;
4612 if (b->type == bp_hardware_breakpoint && b->enable_state == bp_enabled)
4620 hw_watchpoint_used_count (enum bptype type, int *other_type_used)
4622 struct breakpoint *b;
4625 *other_type_used = 0;
4628 if (breakpoint_enabled (b))
4630 if (b->type == type)
4632 else if ((b->type == bp_hardware_watchpoint ||
4633 b->type == bp_read_watchpoint ||
4634 b->type == bp_access_watchpoint))
4635 *other_type_used = 1;
4641 /* Call this after hitting the longjmp() breakpoint. Use this to set
4642 a new breakpoint at the target of the jmp_buf.
4644 FIXME - This ought to be done by setting a temporary breakpoint
4645 that gets deleted automatically... */
4648 set_longjmp_resume_breakpoint (CORE_ADDR pc, struct frame_id frame_id)
4650 struct breakpoint *b;
4653 if (b->type == bp_longjmp_resume)
4655 b->loc->requested_address = pc;
4656 b->loc->address = adjust_breakpoint_address (b->loc->requested_address,
4658 b->enable_state = bp_enabled;
4659 b->frame_id = frame_id;
4660 check_duplicates (b);
4666 disable_watchpoints_before_interactive_call_start (void)
4668 struct breakpoint *b;
4672 if (((b->type == bp_watchpoint)
4673 || (b->type == bp_hardware_watchpoint)
4674 || (b->type == bp_read_watchpoint)
4675 || (b->type == bp_access_watchpoint)
4676 || ep_is_exception_catchpoint (b))
4677 && breakpoint_enabled (b))
4679 b->enable_state = bp_call_disabled;
4680 check_duplicates (b);
4686 enable_watchpoints_after_interactive_call_stop (void)
4688 struct breakpoint *b;
4692 if (((b->type == bp_watchpoint)
4693 || (b->type == bp_hardware_watchpoint)
4694 || (b->type == bp_read_watchpoint)
4695 || (b->type == bp_access_watchpoint)
4696 || ep_is_exception_catchpoint (b))
4697 && (b->enable_state == bp_call_disabled))
4699 b->enable_state = bp_enabled;
4700 check_duplicates (b);
4706 /* Set a breakpoint that will evaporate an end of command
4707 at address specified by SAL.
4708 Restrict it to frame FRAME if FRAME is nonzero. */
4711 set_momentary_breakpoint (struct symtab_and_line sal, struct frame_id frame_id,
4714 struct breakpoint *b;
4715 b = set_raw_breakpoint (sal, type);
4716 b->enable_state = bp_enabled;
4717 b->disposition = disp_donttouch;
4718 b->frame_id = frame_id;
4720 /* If we're debugging a multi-threaded program, then we
4721 want momentary breakpoints to be active in only a
4722 single thread of control. */
4723 if (in_thread_list (inferior_ptid))
4724 b->thread = pid_to_thread_id (inferior_ptid);
4730 /* Tell the user we have just set a breakpoint B. */
4733 mention (struct breakpoint *b)
4736 struct cleanup *old_chain, *ui_out_chain;
4737 struct ui_stream *stb;
4739 stb = ui_out_stream_new (uiout);
4740 old_chain = make_cleanup_ui_out_stream_delete (stb);
4742 /* FIXME: This is misplaced; mention() is called by things (like
4743 hitting a watchpoint) other than breakpoint creation. It should
4744 be possible to clean this up and at the same time replace the
4745 random calls to breakpoint_changed with this hook, as has already
4746 been done for deprecated_delete_breakpoint_hook and so on. */
4747 if (deprecated_create_breakpoint_hook)
4748 deprecated_create_breakpoint_hook (b);
4749 breakpoint_create_event (b->number);
4751 if (b->ops != NULL && b->ops->print_mention != NULL)
4752 b->ops->print_mention (b);
4757 printf_filtered ("(apparently deleted?) Eventpoint %d: ", b->number);
4760 ui_out_text (uiout, "Watchpoint ");
4761 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
4762 ui_out_field_int (uiout, "number", b->number);
4763 ui_out_text (uiout, ": ");
4764 print_expression (b->exp, stb->stream);
4765 ui_out_field_stream (uiout, "exp", stb);
4766 do_cleanups (ui_out_chain);
4768 case bp_hardware_watchpoint:
4769 ui_out_text (uiout, "Hardware watchpoint ");
4770 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
4771 ui_out_field_int (uiout, "number", b->number);
4772 ui_out_text (uiout, ": ");
4773 print_expression (b->exp, stb->stream);
4774 ui_out_field_stream (uiout, "exp", stb);
4775 do_cleanups (ui_out_chain);
4777 case bp_read_watchpoint:
4778 ui_out_text (uiout, "Hardware read watchpoint ");
4779 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
4780 ui_out_field_int (uiout, "number", b->number);
4781 ui_out_text (uiout, ": ");
4782 print_expression (b->exp, stb->stream);
4783 ui_out_field_stream (uiout, "exp", stb);
4784 do_cleanups (ui_out_chain);
4786 case bp_access_watchpoint:
4787 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
4788 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
4789 ui_out_field_int (uiout, "number", b->number);
4790 ui_out_text (uiout, ": ");
4791 print_expression (b->exp, stb->stream);
4792 ui_out_field_stream (uiout, "exp", stb);
4793 do_cleanups (ui_out_chain);
4796 if (ui_out_is_mi_like_p (uiout))
4801 printf_filtered ("Breakpoint %d", b->number);
4804 case bp_hardware_breakpoint:
4805 if (ui_out_is_mi_like_p (uiout))
4810 printf_filtered ("Hardware assisted breakpoint %d", b->number);
4814 case bp_catch_unload:
4815 printf_filtered ("Catchpoint %d (%s %s)",
4817 (b->type == bp_catch_load) ? "load" : "unload",
4818 (b->dll_pathname != NULL) ?
4819 b->dll_pathname : "<any library>");
4822 case bp_catch_vfork:
4823 printf_filtered ("Catchpoint %d (%s)",
4825 (b->type == bp_catch_fork) ? "fork" : "vfork");
4828 printf_filtered ("Catchpoint %d (exec)",
4831 case bp_catch_catch:
4832 case bp_catch_throw:
4833 printf_filtered ("Catchpoint %d (%s)",
4835 (b->type == bp_catch_catch) ? "catch" : "throw");
4841 case bp_longjmp_resume:
4842 case bp_step_resume:
4843 case bp_through_sigtramp:
4845 case bp_watchpoint_scope:
4846 case bp_shlib_event:
4847 case bp_thread_event:
4848 case bp_overlay_event:
4856 printf_filtered (" (%s) pending.", b->addr_string);
4860 if (addressprint || b->source_file == NULL)
4862 printf_filtered (" at ");
4863 print_address_numeric (b->loc->address, 1, gdb_stdout);
4866 printf_filtered (": file %s, line %d.",
4867 b->source_file, b->line_number);
4870 do_cleanups (old_chain);
4871 if (ui_out_is_mi_like_p (uiout))
4873 printf_filtered ("\n");
4877 /* Add SALS.nelts breakpoints to the breakpoint table. For each
4878 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i],
4879 COND[i] and COND_STRING[i] values.
4881 The parameter PENDING_BP points to a pending breakpoint that is
4882 the basis of the breakpoints currently being created. The pending
4883 breakpoint may contain a separate condition string or commands
4884 that were added after the initial pending breakpoint was created.
4886 NOTE: If the function succeeds, the caller is expected to cleanup
4887 the arrays ADDR_STRING, COND_STRING, COND and SALS (but not the
4888 array contents). If the function fails (error() is called), the
4889 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
4890 COND and SALS arrays and each of those arrays contents. */
4893 create_breakpoints (struct symtabs_and_lines sals, char **addr_string,
4894 struct expression **cond, char **cond_string,
4895 enum bptype type, enum bpdisp disposition,
4896 int thread, int ignore_count, int from_tty,
4897 struct breakpoint *pending_bp)
4899 if (type == bp_hardware_breakpoint)
4901 int i = hw_breakpoint_used_count ();
4902 int target_resources_ok =
4903 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
4905 if (target_resources_ok == 0)
4906 error ("No hardware breakpoint support in the target.");
4907 else if (target_resources_ok < 0)
4908 error ("Hardware breakpoints used exceeds limit.");
4911 /* Now set all the breakpoints. */
4914 for (i = 0; i < sals.nelts; i++)
4916 struct breakpoint *b;
4917 struct symtab_and_line sal = sals.sals[i];
4920 describe_other_breakpoints (sal.pc, sal.section);
4922 b = set_raw_breakpoint (sal, type);
4923 set_breakpoint_count (breakpoint_count + 1);
4924 b->number = breakpoint_count;
4928 b->addr_string = addr_string[i];
4930 /* addr_string has to be used or breakpoint_re_set will delete
4932 b->addr_string = xstrprintf ("*0x%s", paddr (b->loc->address));
4933 b->cond_string = cond_string[i];
4934 b->ignore_count = ignore_count;
4935 b->enable_state = bp_enabled;
4936 b->disposition = disposition;
4937 /* If resolving a pending breakpoint, a check must be made to see if
4938 the user has specified a new condition or commands for the
4939 breakpoint. A new condition will override any condition that was
4940 initially specified with the initial breakpoint command. */
4944 if (pending_bp->cond_string)
4946 arg = pending_bp->cond_string;
4947 b->cond_string = savestring (arg, strlen (arg));
4948 b->cond = parse_exp_1 (&arg, block_for_pc (b->loc->address), 0);
4950 error ("Junk at end of pending breakpoint condition expression");
4952 /* If there are commands associated with the breakpoint, they should
4954 if (pending_bp->commands)
4955 b->commands = copy_command_lines (pending_bp->commands);
4957 /* We have to copy over the ignore_count and thread as well. */
4958 b->ignore_count = pending_bp->ignore_count;
4959 b->thread = pending_bp->thread;
4966 /* Parse ARG which is assumed to be a SAL specification possibly
4967 followed by conditionals. On return, SALS contains an array of SAL
4968 addresses found. ADDR_STRING contains a vector of (canonical)
4969 address strings. ARG points to the end of the SAL. */
4972 parse_breakpoint_sals (char **address,
4973 struct symtabs_and_lines *sals,
4974 char ***addr_string,
4977 char *addr_start = *address;
4978 *addr_string = NULL;
4979 /* If no arg given, or if first arg is 'if ', use the default
4981 if ((*address) == NULL
4982 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
4984 if (default_breakpoint_valid)
4986 struct symtab_and_line sal;
4987 init_sal (&sal); /* initialize to zeroes */
4988 sals->sals = (struct symtab_and_line *)
4989 xmalloc (sizeof (struct symtab_and_line));
4990 sal.pc = default_breakpoint_address;
4991 sal.line = default_breakpoint_line;
4992 sal.symtab = default_breakpoint_symtab;
4993 sal.section = find_pc_overlay (sal.pc);
4994 sals->sals[0] = sal;
4998 error ("No default breakpoint address now.");
5002 /* Force almost all breakpoints to be in terms of the
5003 current_source_symtab (which is decode_line_1's default). This
5004 should produce the results we want almost all of the time while
5005 leaving default_breakpoint_* alone.
5006 ObjC: However, don't match an Objective-C method name which
5007 may have a '+' or '-' succeeded by a '[' */
5009 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
5011 if (default_breakpoint_valid
5013 || ((strchr ("+-", (*address)[0]) != NULL)
5014 && ((*address)[1] != '['))))
5015 *sals = decode_line_1 (address, 1, default_breakpoint_symtab,
5016 default_breakpoint_line, addr_string,
5019 *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0,
5020 addr_string, not_found_ptr);
5022 /* For any SAL that didn't have a canonical string, fill one in. */
5023 if (sals->nelts > 0 && *addr_string == NULL)
5024 *addr_string = xcalloc (sals->nelts, sizeof (char **));
5025 if (addr_start != (*address))
5028 for (i = 0; i < sals->nelts; i++)
5030 /* Add the string if not present. */
5031 if ((*addr_string)[i] == NULL)
5032 (*addr_string)[i] = savestring (addr_start, (*address) - addr_start);
5038 /* Convert each SAL into a real PC. Verify that the PC can be
5039 inserted as a breakpoint. If it can't throw an error. */
5042 breakpoint_sals_to_pc (struct symtabs_and_lines *sals,
5046 for (i = 0; i < sals->nelts; i++)
5048 resolve_sal_pc (&sals->sals[i]);
5050 /* It's possible for the PC to be nonzero, but still an illegal
5051 value on some targets.
5053 For example, on HP-UX if you start gdb, and before running the
5054 inferior you try to set a breakpoint on a shared library function
5055 "foo" where the inferior doesn't call "foo" directly but does
5056 pass its address to another function call, then we do find a
5057 minimal symbol for the "foo", but it's address is invalid.
5058 (Appears to be an index into a table that the loader sets up
5059 when the inferior is run.)
5061 Give the target a chance to bless sals.sals[i].pc before we
5062 try to make a breakpoint for it. */
5063 #ifdef DEPRECATED_PC_REQUIRES_RUN_BEFORE_USE
5064 if (DEPRECATED_PC_REQUIRES_RUN_BEFORE_USE (sals->sals[i].pc))
5066 if (address == NULL)
5067 error ("Cannot break without a running program.");
5069 error ("Cannot break on %s without a running program.",
5077 do_captured_parse_breakpoint (struct ui_out *ui, void *data)
5079 struct captured_parse_breakpoint_args *args = data;
5081 parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p,
5082 args->not_found_ptr);
5085 /* Set a breakpoint according to ARG (function, linenum or *address)
5086 flag: first bit : 0 non-temporary, 1 temporary.
5087 second bit : 0 normal breakpoint, 1 hardware breakpoint.
5089 PENDING_BP is non-NULL when this function is being called to resolve
5090 a pending breakpoint. */
5093 break_command_1 (char *arg, int flag, int from_tty, struct breakpoint *pending_bp)
5096 int tempflag, hardwareflag;
5097 struct symtabs_and_lines sals;
5098 struct expression **cond = 0;
5099 struct symtab_and_line pending_sal;
5100 char **cond_string = (char **) NULL;
5103 char *addr_start = arg;
5105 struct cleanup *old_chain;
5106 struct cleanup *breakpoint_chain = NULL;
5107 struct captured_parse_breakpoint_args parse_args;
5111 int ignore_count = 0;
5114 hardwareflag = flag & BP_HARDWAREFLAG;
5115 tempflag = flag & BP_TEMPFLAG;
5121 parse_args.arg_p = &arg;
5122 parse_args.sals_p = &sals;
5123 parse_args.addr_string_p = &addr_string;
5124 parse_args.not_found_ptr = ¬_found;
5126 e = catch_exception (uiout, do_captured_parse_breakpoint,
5127 &parse_args, RETURN_MASK_ALL);
5129 /* If caller is interested in rc value from parse, set value. */
5133 exception_print (gdb_stderr, e);
5138 case NOT_FOUND_ERROR:
5139 /* If called to resolve pending breakpoint, just return
5144 exception_print (gdb_stderr, e);
5146 /* If pending breakpoint support is turned off, throw
5149 if (pending_break_support == AUTO_BOOLEAN_FALSE)
5150 throw_reason (RETURN_ERROR);
5152 /* If pending breakpoint support is auto query and the user
5153 selects no, then simply return the error code. */
5154 if (pending_break_support == AUTO_BOOLEAN_AUTO &&
5155 !nquery ("Make breakpoint pending on future shared library load? "))
5158 /* At this point, either the user was queried about setting
5159 a pending breakpoint and selected yes, or pending
5160 breakpoint behavior is on and thus a pending breakpoint
5161 is defaulted on behalf of the user. */
5162 copy_arg = xstrdup (addr_start);
5163 addr_string = ©_arg;
5165 sals.sals = &pending_sal;
5170 exception_print (gdb_stderr, e);
5178 /* Create a chain of things that always need to be cleaned up. */
5179 old_chain = make_cleanup (null_cleanup, 0);
5183 /* Make sure that all storage allocated to SALS gets freed. */
5184 make_cleanup (xfree, sals.sals);
5186 /* Cleanup the addr_string array but not its contents. */
5187 make_cleanup (xfree, addr_string);
5190 /* Allocate space for all the cond expressions. */
5191 cond = xcalloc (sals.nelts, sizeof (struct expression *));
5192 make_cleanup (xfree, cond);
5194 /* Allocate space for all the cond strings. */
5195 cond_string = xcalloc (sals.nelts, sizeof (char **));
5196 make_cleanup (xfree, cond_string);
5198 /* ----------------------------- SNIP -----------------------------
5199 Anything added to the cleanup chain beyond this point is assumed
5200 to be part of a breakpoint. If the breakpoint create succeeds
5201 then the memory is not reclaimed. */
5202 breakpoint_chain = make_cleanup (null_cleanup, 0);
5204 /* Mark the contents of the addr_string for cleanup. These go on
5205 the breakpoint_chain and only occure if the breakpoint create
5207 for (i = 0; i < sals.nelts; i++)
5209 if (addr_string[i] != NULL)
5210 make_cleanup (xfree, addr_string[i]);
5213 /* Resolve all line numbers to PC's and verify that the addresses
5214 are ok for the target. */
5216 breakpoint_sals_to_pc (&sals, addr_start);
5218 /* Verify that condition can be parsed, before setting any
5219 breakpoints. Allocate a separate condition expression for each
5221 thread = -1; /* No specific thread yet */
5224 for (i = 0; i < sals.nelts; i++)
5231 char *cond_start = NULL;
5232 char *cond_end = NULL;
5233 while (*tok == ' ' || *tok == '\t')
5238 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
5241 toklen = end_tok - tok;
5243 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
5245 tok = cond_start = end_tok + 1;
5246 cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc),
5248 make_cleanup (xfree, cond[i]);
5250 cond_string[i] = savestring (cond_start,
5251 cond_end - cond_start);
5252 make_cleanup (xfree, cond_string[i]);
5254 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
5260 thread = strtol (tok, &tok, 0);
5262 error ("Junk after thread keyword.");
5263 if (!valid_thread_id (thread))
5264 error ("Unknown thread %d\n", thread);
5267 error ("Junk at end of arguments.");
5270 create_breakpoints (sals, addr_string, cond, cond_string,
5271 hardwareflag ? bp_hardware_breakpoint
5273 tempflag ? disp_del : disp_donttouch,
5274 thread, ignore_count, from_tty,
5279 struct symtab_and_line sal;
5280 struct breakpoint *b;
5285 make_cleanup (xfree, copy_arg);
5287 b = set_raw_breakpoint (sal, hardwareflag ? bp_hardware_breakpoint
5289 set_breakpoint_count (breakpoint_count + 1);
5290 b->number = breakpoint_count;
5293 b->addr_string = *addr_string;
5294 b->cond_string = *cond_string;
5295 b->ignore_count = ignore_count;
5297 b->disposition = tempflag ? disp_del : disp_donttouch;
5298 b->from_tty = from_tty;
5305 warning ("Multiple breakpoints were set.");
5306 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
5308 /* That's it. Discard the cleanups for data inserted into the
5310 discard_cleanups (breakpoint_chain);
5311 /* But cleanup everything else. */
5312 do_cleanups (old_chain);
5317 /* Set a breakpoint of TYPE/DISPOSITION according to ARG (function,
5318 linenum or *address) with COND and IGNORE_COUNT. */
5320 struct captured_breakpoint_args
5331 do_captured_breakpoint (struct ui_out *uiout, void *data)
5333 struct captured_breakpoint_args *args = data;
5334 struct symtabs_and_lines sals;
5335 struct expression **cond;
5336 struct cleanup *old_chain;
5337 struct cleanup *breakpoint_chain = NULL;
5344 /* Parse the source and lines spec. Delay check that the expression
5345 didn't contain trailing garbage until after cleanups are in
5349 address_end = args->address;
5351 parse_breakpoint_sals (&address_end, &sals, &addr_string, 0);
5356 /* Create a chain of things at always need to be cleaned up. */
5357 old_chain = make_cleanup (null_cleanup, 0);
5359 /* Always have a addr_string array, even if it is empty. */
5360 make_cleanup (xfree, addr_string);
5362 /* Make sure that all storage allocated to SALS gets freed. */
5363 make_cleanup (xfree, sals.sals);
5365 /* Allocate space for all the cond expressions. */
5366 cond = xcalloc (sals.nelts, sizeof (struct expression *));
5367 make_cleanup (xfree, cond);
5369 /* Allocate space for all the cond strings. */
5370 cond_string = xcalloc (sals.nelts, sizeof (char **));
5371 make_cleanup (xfree, cond_string);
5373 /* ----------------------------- SNIP -----------------------------
5374 Anything added to the cleanup chain beyond this point is assumed
5375 to be part of a breakpoint. If the breakpoint create goes
5376 through then that memory is not cleaned up. */
5377 breakpoint_chain = make_cleanup (null_cleanup, 0);
5379 /* Mark the contents of the addr_string for cleanup. These go on
5380 the breakpoint_chain and only occure if the breakpoint create
5382 for (i = 0; i < sals.nelts; i++)
5384 if (addr_string[i] != NULL)
5385 make_cleanup (xfree, addr_string[i]);
5388 /* Wait until now before checking for garbage at the end of the
5389 address. That way cleanups can take care of freeing any
5391 if (*address_end != '\0')
5392 error ("Garbage %s following breakpoint address", address_end);
5394 /* Resolve all line numbers to PC's. */
5395 breakpoint_sals_to_pc (&sals, args->address);
5397 /* Verify that conditions can be parsed, before setting any
5399 for (i = 0; i < sals.nelts; i++)
5401 if (args->condition != NULL)
5403 char *tok = args->condition;
5404 cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
5406 error ("Garbage %s follows condition", tok);
5407 make_cleanup (xfree, cond[i]);
5408 cond_string[i] = xstrdup (args->condition);
5412 create_breakpoints (sals, addr_string, cond, cond_string,
5413 args->hardwareflag ? bp_hardware_breakpoint : bp_breakpoint,
5414 args->tempflag ? disp_del : disp_donttouch,
5415 args->thread, args->ignore_count, 0/*from-tty*/,
5416 NULL/*pending_bp*/);
5418 /* That's it. Discard the cleanups for data inserted into the
5420 discard_cleanups (breakpoint_chain);
5421 /* But cleanup everything else. */
5422 do_cleanups (old_chain);
5427 gdb_breakpoint (char *address, char *condition,
5428 int hardwareflag, int tempflag,
5429 int thread, int ignore_count,
5430 char **error_message)
5432 struct captured_breakpoint_args args;
5433 args.address = address;
5434 args.condition = condition;
5435 args.hardwareflag = hardwareflag;
5436 args.tempflag = tempflag;
5437 args.thread = thread;
5438 args.ignore_count = ignore_count;
5439 return catch_exceptions_with_msg (uiout, do_captured_breakpoint, &args,
5440 NULL, error_message, RETURN_MASK_ALL);
5444 /* Helper function for break_command_1 and disassemble_command. */
5447 resolve_sal_pc (struct symtab_and_line *sal)
5451 if (sal->pc == 0 && sal->symtab != NULL)
5453 if (!find_line_pc (sal->symtab, sal->line, &pc))
5454 error ("No line %d in file \"%s\".",
5455 sal->line, sal->symtab->filename);
5459 if (sal->section == 0 && sal->symtab != NULL)
5461 struct blockvector *bv;
5466 bv = blockvector_for_pc_sect (sal->pc, 0, &index, sal->symtab);
5469 b = BLOCKVECTOR_BLOCK (bv, index);
5470 sym = block_function (b);
5473 fixup_symbol_section (sym, sal->symtab->objfile);
5474 sal->section = SYMBOL_BFD_SECTION (sym);
5478 /* It really is worthwhile to have the section, so we'll just
5479 have to look harder. This case can be executed if we have
5480 line numbers but no functions (as can happen in assembly
5483 struct minimal_symbol *msym;
5485 msym = lookup_minimal_symbol_by_pc (sal->pc);
5487 sal->section = SYMBOL_BFD_SECTION (msym);
5494 break_command (char *arg, int from_tty)
5496 break_command_1 (arg, 0, from_tty, NULL);
5500 tbreak_command (char *arg, int from_tty)
5502 break_command_1 (arg, BP_TEMPFLAG, from_tty, NULL);
5506 hbreak_command (char *arg, int from_tty)
5508 break_command_1 (arg, BP_HARDWAREFLAG, from_tty, NULL);
5512 thbreak_command (char *arg, int from_tty)
5514 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty, NULL);
5518 stop_command (char *arg, int from_tty)
5520 printf_filtered ("Specify the type of breakpoint to set.\n\
5521 Usage: stop in <function | address>\n\
5526 stopin_command (char *arg, int from_tty)
5530 if (arg == (char *) NULL)
5532 else if (*arg != '*')
5537 /* look for a ':'. If this is a line number specification, then
5538 say it is bad, otherwise, it should be an address or
5539 function/method name */
5540 while (*argptr && !hasColon)
5542 hasColon = (*argptr == ':');
5547 badInput = (*argptr != ':'); /* Not a class::method */
5549 badInput = isdigit (*arg); /* a simple line number */
5553 printf_filtered ("Usage: stop in <function | address>\n");
5555 break_command_1 (arg, 0, from_tty, NULL);
5559 stopat_command (char *arg, int from_tty)
5563 if (arg == (char *) NULL || *arg == '*') /* no line number */
5570 /* look for a ':'. If there is a '::' then get out, otherwise
5571 it is probably a line number. */
5572 while (*argptr && !hasColon)
5574 hasColon = (*argptr == ':');
5579 badInput = (*argptr == ':'); /* we have class::method */
5581 badInput = !isdigit (*arg); /* not a line number */
5585 printf_filtered ("Usage: stop at <line>\n");
5587 break_command_1 (arg, 0, from_tty, NULL);
5590 /* accessflag: hw_write: watch write,
5591 hw_read: watch read,
5592 hw_access: watch access (read or write) */
5594 watch_command_1 (char *arg, int accessflag, int from_tty)
5596 struct breakpoint *b;
5597 struct symtab_and_line sal;
5598 struct expression *exp;
5599 struct block *exp_valid_block;
5600 struct value *val, *mark;
5601 struct frame_info *frame;
5602 struct frame_info *prev_frame = NULL;
5603 char *exp_start = NULL;
5604 char *exp_end = NULL;
5605 char *tok, *end_tok;
5607 char *cond_start = NULL;
5608 char *cond_end = NULL;
5609 struct expression *cond = NULL;
5610 int i, other_type_used, target_resources_ok = 0;
5611 enum bptype bp_type;
5614 init_sal (&sal); /* initialize to zeroes */
5616 /* Parse arguments. */
5617 innermost_block = NULL;
5619 exp = parse_exp_1 (&arg, 0, 0);
5621 exp_valid_block = innermost_block;
5622 mark = value_mark ();
5623 val = evaluate_expression (exp);
5624 release_value (val);
5625 if (VALUE_LAZY (val))
5626 value_fetch_lazy (val);
5629 while (*tok == ' ' || *tok == '\t')
5633 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
5636 toklen = end_tok - tok;
5637 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
5639 tok = cond_start = end_tok + 1;
5640 cond = parse_exp_1 (&tok, 0, 0);
5644 error ("Junk at end of command.");
5646 if (accessflag == hw_read)
5647 bp_type = bp_read_watchpoint;
5648 else if (accessflag == hw_access)
5649 bp_type = bp_access_watchpoint;
5651 bp_type = bp_hardware_watchpoint;
5653 mem_cnt = can_use_hardware_watchpoint (val);
5654 if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
5655 error ("Expression cannot be implemented with read/access watchpoint.");
5658 i = hw_watchpoint_used_count (bp_type, &other_type_used);
5659 target_resources_ok =
5660 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type, i + mem_cnt,
5662 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
5663 error ("Target does not support this type of hardware watchpoint.");
5665 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
5666 error ("Target can only support one kind of HW watchpoint at a time.");
5669 #if defined(HPUXHPPA)
5670 /* On HP-UX if you set a h/w
5671 watchpoint before the "run" command, the inferior dies with a e.g.,
5672 SIGILL once you start it. I initially believed this was due to a
5673 bad interaction between page protection traps and the initial
5674 startup sequence by the dynamic linker.
5676 However, I tried avoiding that by having HP-UX's implementation of
5677 TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_ptid
5678 yet, which forced slow watches before a "run" or "attach", and it
5679 still fails somewhere in the startup code.
5681 Until I figure out what's happening, I'm disallowing watches altogether
5682 before the "run" or "attach" command. We'll tell the user they must
5683 set watches after getting the program started. */
5684 if (!target_has_execution)
5686 warning ("can't do that without a running program; try \"break main\", \"run\" first");
5689 #endif /* HPUXHPPA */
5691 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5692 watchpoint could not be set. */
5693 if (!mem_cnt || target_resources_ok <= 0)
5694 bp_type = bp_watchpoint;
5696 /* Now set up the breakpoint. */
5697 b = set_raw_breakpoint (sal, bp_type);
5698 set_breakpoint_count (breakpoint_count + 1);
5699 b->number = breakpoint_count;
5700 b->disposition = disp_donttouch;
5702 b->exp_valid_block = exp_valid_block;
5703 b->exp_string = savestring (exp_start, exp_end - exp_start);
5707 b->cond_string = savestring (cond_start, cond_end - cond_start);
5711 frame = block_innermost_frame (exp_valid_block);
5714 prev_frame = get_prev_frame (frame);
5715 b->watchpoint_frame = get_frame_id (frame);
5719 memset (&b->watchpoint_frame, 0, sizeof (b->watchpoint_frame));
5722 /* If the expression is "local", then set up a "watchpoint scope"
5723 breakpoint at the point where we've left the scope of the watchpoint
5725 if (innermost_block)
5729 struct breakpoint *scope_breakpoint;
5730 scope_breakpoint = create_internal_breakpoint (get_frame_pc (prev_frame),
5731 bp_watchpoint_scope);
5733 scope_breakpoint->enable_state = bp_enabled;
5735 /* Automatically delete the breakpoint when it hits. */
5736 scope_breakpoint->disposition = disp_del;
5738 /* Only break in the proper frame (help with recursion). */
5739 scope_breakpoint->frame_id = get_frame_id (prev_frame);
5741 /* Set the address at which we will stop. */
5742 scope_breakpoint->loc->requested_address
5743 = get_frame_pc (prev_frame);
5744 scope_breakpoint->loc->address
5745 = adjust_breakpoint_address (scope_breakpoint->loc->requested_address,
5746 scope_breakpoint->type);
5748 /* The scope breakpoint is related to the watchpoint. We
5749 will need to act on them together. */
5750 b->related_breakpoint = scope_breakpoint;
5753 value_free_to_mark (mark);
5757 /* Return count of locations need to be watched and can be handled
5758 in hardware. If the watchpoint can not be handled
5759 in hardware return zero. */
5761 #if !defined(TARGET_REGION_OK_FOR_HW_WATCHPOINT)
5762 #define TARGET_REGION_OK_FOR_HW_WATCHPOINT(ADDR,LEN) \
5763 (TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(LEN))
5767 can_use_hardware_watchpoint (struct value *v)
5769 int found_memory_cnt = 0;
5770 struct value *head = v;
5772 /* Did the user specifically forbid us to use hardware watchpoints? */
5773 if (!can_use_hw_watchpoints)
5776 /* Make sure that the value of the expression depends only upon
5777 memory contents, and values computed from them within GDB. If we
5778 find any register references or function calls, we can't use a
5779 hardware watchpoint.
5781 The idea here is that evaluating an expression generates a series
5782 of values, one holding the value of every subexpression. (The
5783 expression a*b+c has five subexpressions: a, b, a*b, c, and
5784 a*b+c.) GDB's values hold almost enough information to establish
5785 the criteria given above --- they identify memory lvalues,
5786 register lvalues, computed values, etcetera. So we can evaluate
5787 the expression, and then scan the chain of values that leaves
5788 behind to decide whether we can detect any possible change to the
5789 expression's final value using only hardware watchpoints.
5791 However, I don't think that the values returned by inferior
5792 function calls are special in any way. So this function may not
5793 notice that an expression involving an inferior function call
5794 can't be watched with hardware watchpoints. FIXME. */
5795 for (; v; v = v->next)
5797 if (VALUE_LVAL (v) == lval_memory)
5800 /* A lazy memory lvalue is one that GDB never needed to fetch;
5801 we either just used its address (e.g., `a' in `a.b') or
5802 we never needed it at all (e.g., `a' in `a,b'). */
5806 /* Ahh, memory we actually used! Check if we can cover
5807 it with hardware watchpoints. */
5808 struct type *vtype = check_typedef (value_type (v));
5810 /* We only watch structs and arrays if user asked for it
5811 explicitly, never if they just happen to appear in a
5812 middle of some value chain. */
5814 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
5815 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
5817 CORE_ADDR vaddr = VALUE_ADDRESS (v) + value_offset (v);
5818 int len = TYPE_LENGTH (value_type (v));
5820 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr, len))
5827 else if (v->lval != not_lval && v->modifiable == 0)
5828 return 0; /* ??? What does this represent? */
5829 else if (v->lval == lval_register)
5830 return 0; /* cannot watch a register with a HW watchpoint */
5833 /* The expression itself looks suitable for using a hardware
5834 watchpoint, but give the target machine a chance to reject it. */
5835 return found_memory_cnt;
5839 watch_command_wrapper (char *arg, int from_tty)
5841 watch_command (arg, from_tty);
5845 watch_command (char *arg, int from_tty)
5847 watch_command_1 (arg, hw_write, from_tty);
5851 rwatch_command_wrapper (char *arg, int from_tty)
5853 rwatch_command (arg, from_tty);
5857 rwatch_command (char *arg, int from_tty)
5859 watch_command_1 (arg, hw_read, from_tty);
5863 awatch_command_wrapper (char *arg, int from_tty)
5865 awatch_command (arg, from_tty);
5869 awatch_command (char *arg, int from_tty)
5871 watch_command_1 (arg, hw_access, from_tty);
5875 /* Helper routines for the until_command routine in infcmd.c. Here
5876 because it uses the mechanisms of breakpoints. */
5878 /* This function is called by fetch_inferior_event via the
5879 cmd_continuation pointer, to complete the until command. It takes
5880 care of cleaning up the temporary breakpoints set up by the until
5883 until_break_command_continuation (struct continuation_arg *arg)
5885 struct cleanup *cleanups;
5887 cleanups = (struct cleanup *) arg->data.pointer;
5888 do_exec_cleanups (cleanups);
5892 until_break_command (char *arg, int from_tty, int anywhere)
5894 struct symtabs_and_lines sals;
5895 struct symtab_and_line sal;
5896 struct frame_info *prev_frame = get_prev_frame (deprecated_selected_frame);
5897 struct breakpoint *breakpoint;
5898 struct cleanup *old_chain;
5899 struct continuation_arg *arg1;
5902 clear_proceed_status ();
5904 /* Set a breakpoint where the user wants it and at return from
5907 if (default_breakpoint_valid)
5908 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
5909 default_breakpoint_line, (char ***) NULL, NULL);
5911 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL,
5912 0, (char ***) NULL, NULL);
5914 if (sals.nelts != 1)
5915 error ("Couldn't get information on specified line.");
5918 xfree (sals.sals); /* malloc'd, so freed */
5921 error ("Junk at end of arguments.");
5923 resolve_sal_pc (&sal);
5926 /* If the user told us to continue until a specified location,
5927 we don't specify a frame at which we need to stop. */
5928 breakpoint = set_momentary_breakpoint (sal, null_frame_id, bp_until);
5930 /* Otherwise, specify the current frame, because we want to stop only
5931 at the very same frame. */
5932 breakpoint = set_momentary_breakpoint (sal,
5933 get_frame_id (deprecated_selected_frame),
5936 if (!target_can_async_p ())
5937 old_chain = make_cleanup_delete_breakpoint (breakpoint);
5939 old_chain = make_exec_cleanup_delete_breakpoint (breakpoint);
5941 /* If we are running asynchronously, and the target supports async
5942 execution, we are not waiting for the target to stop, in the call
5943 tp proceed, below. This means that we cannot delete the
5944 brekpoints until the target has actually stopped. The only place
5945 where we get a chance to do that is in fetch_inferior_event, so
5946 we must set things up for that. */
5948 if (target_can_async_p ())
5950 /* In this case the arg for the continuation is just the point
5951 in the exec_cleanups chain from where to start doing
5952 cleanups, because all the continuation does is the cleanups in
5953 the exec_cleanup_chain. */
5955 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
5957 arg1->data.pointer = old_chain;
5959 add_continuation (until_break_command_continuation, arg1);
5962 /* Keep within the current frame, or in frames called by the current
5966 sal = find_pc_line (get_frame_pc (prev_frame), 0);
5967 sal.pc = get_frame_pc (prev_frame);
5968 breakpoint = set_momentary_breakpoint (sal, get_frame_id (prev_frame),
5970 if (!target_can_async_p ())
5971 make_cleanup_delete_breakpoint (breakpoint);
5973 make_exec_cleanup_delete_breakpoint (breakpoint);
5976 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
5977 /* Do the cleanups now, anly if we are not running asynchronously,
5978 of if we are, but the target is still synchronous. */
5979 if (!target_can_async_p ())
5980 do_cleanups (old_chain);
5984 ep_skip_leading_whitespace (char **s)
5986 if ((s == NULL) || (*s == NULL))
5988 while (isspace (**s))
5992 /* This function examines a string, and attempts to find a token
5993 that might be an event name in the leading characters. If a
5994 possible match is found, a pointer to the last character of
5995 the token is returned. Else, NULL is returned. */
5998 ep_find_event_name_end (char *arg)
6001 char *event_name_end = NULL;
6003 /* If we could depend upon the presense of strrpbrk, we'd use that... */
6007 /* We break out of the loop when we find a token delimiter.
6008 Basically, we're looking for alphanumerics and underscores;
6009 anything else delimites the token. */
6012 if (!isalnum (*s) && (*s != '_'))
6018 return event_name_end;
6022 /* This function attempts to parse an optional "if <cond>" clause
6023 from the arg string. If one is not found, it returns NULL.
6025 Else, it returns a pointer to the condition string. (It does not
6026 attempt to evaluate the string against a particular block.) And,
6027 it updates arg to point to the first character following the parsed
6028 if clause in the arg string. */
6031 ep_parse_optional_if_clause (char **arg)
6035 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
6038 /* Skip the "if" keyword. */
6041 /* Skip any extra leading whitespace, and record the start of the
6042 condition string. */
6043 ep_skip_leading_whitespace (arg);
6046 /* Assume that the condition occupies the remainder of the arg string. */
6047 (*arg) += strlen (cond_string);
6052 /* This function attempts to parse an optional filename from the arg
6053 string. If one is not found, it returns NULL.
6055 Else, it returns a pointer to the parsed filename. (This function
6056 makes no attempt to verify that a file of that name exists, or is
6057 accessible.) And, it updates arg to point to the first character
6058 following the parsed filename in the arg string.
6060 Note that clients needing to preserve the returned filename for
6061 future access should copy it to their own buffers. */
6063 ep_parse_optional_filename (char **arg)
6065 static char filename[1024];
6070 if ((*arg_p == '\0') || isspace (*arg_p))
6088 /* Commands to deal with catching events, such as signals, exceptions,
6089 process start/exit, etc. */
6093 catch_fork, catch_vfork
6098 catch_fork_command_1 (catch_fork_kind fork_kind, char *arg, int tempflag,
6101 char *cond_string = NULL;
6103 ep_skip_leading_whitespace (&arg);
6105 /* The allowed syntax is:
6107 catch [v]fork if <cond>
6109 First, check if there's an if clause. */
6110 cond_string = ep_parse_optional_if_clause (&arg);
6112 if ((*arg != '\0') && !isspace (*arg))
6113 error ("Junk at end of arguments.");
6115 /* If this target supports it, create a fork or vfork catchpoint
6116 and enable reporting of such events. */
6120 create_fork_event_catchpoint (tempflag, cond_string);
6123 create_vfork_event_catchpoint (tempflag, cond_string);
6126 error ("unsupported or unknown fork kind; cannot catch it");
6132 catch_exec_command_1 (char *arg, int tempflag, int from_tty)
6134 char *cond_string = NULL;
6136 ep_skip_leading_whitespace (&arg);
6138 /* The allowed syntax is:
6140 catch exec if <cond>
6142 First, check if there's an if clause. */
6143 cond_string = ep_parse_optional_if_clause (&arg);
6145 if ((*arg != '\0') && !isspace (*arg))
6146 error ("Junk at end of arguments.");
6148 /* If this target supports it, create an exec catchpoint
6149 and enable reporting of such events. */
6150 create_exec_event_catchpoint (tempflag, cond_string);
6154 catch_load_command_1 (char *arg, int tempflag, int from_tty)
6156 char *dll_pathname = NULL;
6157 char *cond_string = NULL;
6159 ep_skip_leading_whitespace (&arg);
6161 /* The allowed syntax is:
6163 catch load if <cond>
6164 catch load <filename>
6165 catch load <filename> if <cond>
6167 The user is not allowed to specify the <filename> after an
6170 We'll ignore the pathological case of a file named "if".
6172 First, check if there's an if clause. If so, then there
6173 cannot be a filename. */
6174 cond_string = ep_parse_optional_if_clause (&arg);
6176 /* If there was an if clause, then there cannot be a filename.
6177 Else, there might be a filename and an if clause. */
6178 if (cond_string == NULL)
6180 dll_pathname = ep_parse_optional_filename (&arg);
6181 ep_skip_leading_whitespace (&arg);
6182 cond_string = ep_parse_optional_if_clause (&arg);
6185 if ((*arg != '\0') && !isspace (*arg))
6186 error ("Junk at end of arguments.");
6188 /* Create a load breakpoint that only triggers when a load of
6189 the specified dll (or any dll, if no pathname was specified)
6191 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid), tempflag,
6192 dll_pathname, cond_string);
6196 catch_unload_command_1 (char *arg, int tempflag, int from_tty)
6198 char *dll_pathname = NULL;
6199 char *cond_string = NULL;
6201 ep_skip_leading_whitespace (&arg);
6203 /* The allowed syntax is:
6205 catch unload if <cond>
6206 catch unload <filename>
6207 catch unload <filename> if <cond>
6209 The user is not allowed to specify the <filename> after an
6212 We'll ignore the pathological case of a file named "if".
6214 First, check if there's an if clause. If so, then there
6215 cannot be a filename. */
6216 cond_string = ep_parse_optional_if_clause (&arg);
6218 /* If there was an if clause, then there cannot be a filename.
6219 Else, there might be a filename and an if clause. */
6220 if (cond_string == NULL)
6222 dll_pathname = ep_parse_optional_filename (&arg);
6223 ep_skip_leading_whitespace (&arg);
6224 cond_string = ep_parse_optional_if_clause (&arg);
6227 if ((*arg != '\0') && !isspace (*arg))
6228 error ("Junk at end of arguments.");
6230 /* Create an unload breakpoint that only triggers when an unload of
6231 the specified dll (or any dll, if no pathname was specified)
6233 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid), tempflag,
6234 dll_pathname, cond_string);
6237 /* Commands to deal with catching exceptions. */
6239 /* Set a breakpoint at the specified callback routine for an
6240 exception event callback */
6243 create_exception_catchpoint (int tempflag, char *cond_string,
6244 enum exception_event_kind ex_event,
6245 struct symtab_and_line *sal)
6247 struct breakpoint *b;
6248 int thread = -1; /* All threads. */
6251 if (!sal) /* no exception support? */
6256 case EX_EVENT_THROW:
6257 bptype = bp_catch_throw;
6259 case EX_EVENT_CATCH:
6260 bptype = bp_catch_catch;
6262 default: /* error condition */
6263 error ("Internal error -- invalid catchpoint kind");
6266 b = set_raw_breakpoint (*sal, bptype);
6267 set_breakpoint_count (breakpoint_count + 1);
6268 b->number = breakpoint_count;
6270 b->cond_string = (cond_string == NULL) ?
6271 NULL : savestring (cond_string, strlen (cond_string));
6273 b->addr_string = NULL;
6274 b->enable_state = bp_enabled;
6275 b->disposition = tempflag ? disp_del : disp_donttouch;
6279 static enum print_stop_action
6280 print_exception_catchpoint (struct breakpoint *b)
6282 annotate_catchpoint (b->number);
6284 if (strstr (b->addr_string, "throw") != NULL)
6285 printf_filtered ("\nCatchpoint %d (exception thrown)\n",
6288 printf_filtered ("\nCatchpoint %d (exception caught)\n",
6291 return PRINT_SRC_AND_LOC;
6295 print_one_exception_catchpoint (struct breakpoint *b, CORE_ADDR *last_addr)
6300 ui_out_field_core_addr (uiout, "addr", b->loc->address);
6303 *last_addr = b->loc->address;
6304 if (strstr (b->addr_string, "throw") != NULL)
6305 ui_out_field_string (uiout, "what", "exception throw");
6307 ui_out_field_string (uiout, "what", "exception catch");
6311 print_mention_exception_catchpoint (struct breakpoint *b)
6313 if (strstr (b->addr_string, "throw") != NULL)
6314 printf_filtered ("Catchpoint %d (throw)", b->number);
6316 printf_filtered ("Catchpoint %d (catch)", b->number);
6319 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = {
6320 print_exception_catchpoint,
6321 print_one_exception_catchpoint,
6322 print_mention_exception_catchpoint
6326 handle_gnu_v3_exceptions (int tempflag, char *cond_string,
6327 enum exception_event_kind ex_event, int from_tty)
6329 char *trigger_func_name, *nameptr;
6330 struct symtabs_and_lines sals;
6331 struct breakpoint *b;
6333 if (ex_event == EX_EVENT_CATCH)
6334 trigger_func_name = xstrdup ("__cxa_begin_catch");
6336 trigger_func_name = xstrdup ("__cxa_throw");
6338 nameptr = trigger_func_name;
6339 sals = decode_line_1 (&nameptr, 1, NULL, 0, NULL, NULL);
6340 if (sals.nelts == 0)
6342 xfree (trigger_func_name);
6346 b = set_raw_breakpoint (sals.sals[0], bp_breakpoint);
6347 set_breakpoint_count (breakpoint_count + 1);
6348 b->number = breakpoint_count;
6350 b->cond_string = (cond_string == NULL) ?
6351 NULL : savestring (cond_string, strlen (cond_string));
6353 b->addr_string = trigger_func_name;
6354 b->enable_state = bp_enabled;
6355 b->disposition = tempflag ? disp_del : disp_donttouch;
6356 b->ops = &gnu_v3_exception_catchpoint_ops;
6363 /* Deal with "catch catch" and "catch throw" commands */
6366 catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
6367 int tempflag, int from_tty)
6369 char *cond_string = NULL;
6370 struct symtab_and_line *sal = NULL;
6372 ep_skip_leading_whitespace (&arg);
6374 cond_string = ep_parse_optional_if_clause (&arg);
6376 if ((*arg != '\0') && !isspace (*arg))
6377 error ("Junk at end of arguments.");
6379 if ((ex_event != EX_EVENT_THROW) &&
6380 (ex_event != EX_EVENT_CATCH))
6381 error ("Unsupported or unknown exception event; cannot catch it");
6383 if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty))
6386 /* See if we can find a callback routine */
6387 sal = target_enable_exception_callback (ex_event, 1);
6391 /* We have callbacks from the runtime system for exceptions.
6392 Set a breakpoint on the sal found, if no errors */
6393 if (sal != (struct symtab_and_line *) -1)
6394 create_exception_catchpoint (tempflag, cond_string, ex_event, sal);
6396 return; /* something went wrong with setting up callbacks */
6399 warning ("Unsupported with this platform/compiler combination.");
6402 /* Cover routine to allow wrapping target_enable_exception_catchpoints
6403 inside a catch_errors */
6406 cover_target_enable_exception_callback (void *arg)
6408 args_for_catchpoint_enable *args = arg;
6409 struct symtab_and_line *sal;
6410 sal = target_enable_exception_callback (args->kind, args->enable_p);
6413 else if (sal == (struct symtab_and_line *) -1)
6416 return 1; /*is valid */
6420 catch_command_1 (char *arg, int tempflag, int from_tty)
6423 /* The first argument may be an event name, such as "start" or "load".
6424 If so, then handle it as such. If it doesn't match an event name,
6425 then attempt to interpret it as an exception name. (This latter is
6426 the v4.16-and-earlier GDB meaning of the "catch" command.)
6428 First, try to find the bounds of what might be an event name. */
6429 char *arg1_start = arg;
6433 if (arg1_start == NULL)
6435 /* Old behaviour was to use pre-v-4.16 syntax */
6436 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6438 /* Now, this is not allowed */
6439 error ("Catch requires an event name.");
6442 arg1_end = ep_find_event_name_end (arg1_start);
6443 if (arg1_end == NULL)
6444 error ("catch requires an event");
6445 arg1_length = arg1_end + 1 - arg1_start;
6447 /* Try to match what we found against known event names. */
6448 if (strncmp (arg1_start, "signal", arg1_length) == 0)
6450 error ("Catch of signal not yet implemented");
6452 else if (strncmp (arg1_start, "catch", arg1_length) == 0)
6454 catch_exception_command_1 (EX_EVENT_CATCH, arg1_end + 1,
6455 tempflag, from_tty);
6457 else if (strncmp (arg1_start, "throw", arg1_length) == 0)
6459 catch_exception_command_1 (EX_EVENT_THROW, arg1_end + 1,
6460 tempflag, from_tty);
6462 else if (strncmp (arg1_start, "thread_start", arg1_length) == 0)
6464 error ("Catch of thread_start not yet implemented");
6466 else if (strncmp (arg1_start, "thread_exit", arg1_length) == 0)
6468 error ("Catch of thread_exit not yet implemented");
6470 else if (strncmp (arg1_start, "thread_join", arg1_length) == 0)
6472 error ("Catch of thread_join not yet implemented");
6474 else if (strncmp (arg1_start, "start", arg1_length) == 0)
6476 error ("Catch of start not yet implemented");
6478 else if (strncmp (arg1_start, "exit", arg1_length) == 0)
6480 error ("Catch of exit not yet implemented");
6482 else if (strncmp (arg1_start, "fork", arg1_length) == 0)
6484 catch_fork_command_1 (catch_fork, arg1_end + 1, tempflag, from_tty);
6486 else if (strncmp (arg1_start, "vfork", arg1_length) == 0)
6488 catch_fork_command_1 (catch_vfork, arg1_end + 1, tempflag, from_tty);
6490 else if (strncmp (arg1_start, "exec", arg1_length) == 0)
6492 catch_exec_command_1 (arg1_end + 1, tempflag, from_tty);
6494 else if (strncmp (arg1_start, "load", arg1_length) == 0)
6496 catch_load_command_1 (arg1_end + 1, tempflag, from_tty);
6498 else if (strncmp (arg1_start, "unload", arg1_length) == 0)
6500 catch_unload_command_1 (arg1_end + 1, tempflag, from_tty);
6502 else if (strncmp (arg1_start, "stop", arg1_length) == 0)
6504 error ("Catch of stop not yet implemented");
6507 /* This doesn't appear to be an event name */
6511 /* Pre-v.4.16 behaviour was to treat the argument
6512 as the name of an exception */
6513 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6514 /* Now this is not allowed */
6515 error ("Unknown event kind specified for catch");
6520 /* Used by the gui, could be made a worker for other things. */
6523 set_breakpoint_sal (struct symtab_and_line sal)
6525 struct breakpoint *b;
6526 b = set_raw_breakpoint (sal, bp_breakpoint);
6527 set_breakpoint_count (breakpoint_count + 1);
6528 b->number = breakpoint_count;
6535 catch_command (char *arg, int from_tty)
6537 catch_command_1 (arg, 0, from_tty);
6542 tcatch_command (char *arg, int from_tty)
6544 catch_command_1 (arg, 1, from_tty);
6547 /* Delete breakpoints by address or line. */
6550 clear_command (char *arg, int from_tty)
6552 struct breakpoint *b, *tmp, *prev, *found;
6554 struct symtabs_and_lines sals;
6555 struct symtab_and_line sal;
6560 sals = decode_line_spec (arg, 1);
6565 sals.sals = (struct symtab_and_line *)
6566 xmalloc (sizeof (struct symtab_and_line));
6567 make_cleanup (xfree, sals.sals);
6568 init_sal (&sal); /* initialize to zeroes */
6569 sal.line = default_breakpoint_line;
6570 sal.symtab = default_breakpoint_symtab;
6571 sal.pc = default_breakpoint_address;
6572 if (sal.symtab == 0)
6573 error ("No source file specified.");
6581 /* For each line spec given, delete bps which correspond
6582 to it. Do it in two passes, solely to preserve the current
6583 behavior that from_tty is forced true if we delete more than
6587 for (i = 0; i < sals.nelts; i++)
6589 /* If exact pc given, clear bpts at that pc.
6590 If line given (pc == 0), clear all bpts on specified line.
6591 If defaulting, clear all bpts on default line
6594 defaulting sal.pc != 0 tests to do
6599 1 0 <can't happen> */
6604 /* Find all matching breakpoints, remove them from the
6605 breakpoint chain, and add them to the 'found' chain. */
6606 ALL_BREAKPOINTS_SAFE (b, tmp)
6608 /* Are we going to delete b? */
6609 if (b->type != bp_none
6610 && b->type != bp_watchpoint
6611 && b->type != bp_hardware_watchpoint
6612 && b->type != bp_read_watchpoint
6613 && b->type != bp_access_watchpoint
6614 /* Not if b is a watchpoint of any sort... */
6615 && (((sal.pc && (b->loc->address == sal.pc))
6616 && (!section_is_overlay (b->loc->section)
6617 || b->loc->section == sal.section))
6618 /* Yes, if sal.pc matches b (modulo overlays). */
6619 || ((default_match || (0 == sal.pc))
6620 && b->source_file != NULL
6621 && sal.symtab != NULL
6622 && strcmp (b->source_file, sal.symtab->filename) == 0
6623 && b->line_number == sal.line)))
6624 /* Yes, if sal source file and line matches b. */
6626 /* Remove it from breakpoint_chain... */
6627 if (b == breakpoint_chain)
6629 /* b is at the head of the list */
6630 breakpoint_chain = b->next;
6634 prev->next = b->next;
6636 /* And add it to 'found' chain. */
6642 /* Keep b, and keep a pointer to it. */
6647 /* Now go thru the 'found' chain and delete them. */
6651 error ("No breakpoint at %s.", arg);
6653 error ("No breakpoint at this line.");
6657 from_tty = 1; /* Always report if deleted more than one */
6659 printf_unfiltered ("Deleted breakpoint%s ", found->next ? "s" : "");
6660 breakpoints_changed ();
6664 printf_unfiltered ("%d ", found->number);
6666 delete_breakpoint (found);
6670 putchar_unfiltered ('\n');
6673 /* Delete breakpoint in BS if they are `delete' breakpoints and
6674 all breakpoints that are marked for deletion, whether hit or not.
6675 This is called after any breakpoint is hit, or after errors. */
6678 breakpoint_auto_delete (bpstat bs)
6680 struct breakpoint *b, *temp;
6682 for (; bs; bs = bs->next)
6683 if (bs->breakpoint_at && bs->breakpoint_at->disposition == disp_del
6685 delete_breakpoint (bs->breakpoint_at);
6687 ALL_BREAKPOINTS_SAFE (b, temp)
6689 if (b->disposition == disp_del_at_next_stop)
6690 delete_breakpoint (b);
6694 /* Delete a breakpoint and clean up all traces of it in the data
6698 delete_breakpoint (struct breakpoint *bpt)
6700 struct breakpoint *b;
6702 struct bp_location *loc;
6705 error ("Internal error (attempted to delete a NULL breakpoint)");
6708 /* Has this bp already been deleted? This can happen because multiple
6709 lists can hold pointers to bp's. bpstat lists are especial culprits.
6711 One example of this happening is a watchpoint's scope bp. When the
6712 scope bp triggers, we notice that the watchpoint is out of scope, and
6713 delete it. We also delete its scope bp. But the scope bp is marked
6714 "auto-deleting", and is already on a bpstat. That bpstat is then
6715 checked for auto-deleting bp's, which are deleted.
6717 A real solution to this problem might involve reference counts in bp's,
6718 and/or giving them pointers back to their referencing bpstat's, and
6719 teaching delete_breakpoint to only free a bp's storage when no more
6720 references were extent. A cheaper bandaid was chosen. */
6721 if (bpt->type == bp_none)
6724 if (deprecated_delete_breakpoint_hook)
6725 deprecated_delete_breakpoint_hook (bpt);
6726 breakpoint_delete_event (bpt->number);
6728 if (bpt->loc->inserted)
6729 remove_breakpoint (bpt->loc, mark_inserted);
6731 free_valchain (bpt->loc);
6733 if (breakpoint_chain == bpt)
6734 breakpoint_chain = bpt->next;
6736 if (bp_location_chain == bpt->loc)
6737 bp_location_chain = bpt->loc->next;
6739 /* If we have callback-style exception catchpoints, don't go through
6740 the adjustments to the C++ runtime library etc. if the inferior
6741 isn't actually running. target_enable_exception_callback for a
6742 null target ops vector gives an undesirable error message, so we
6743 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
6744 exceptions are supported in this way, it's OK for now. FIXME */
6745 if (ep_is_exception_catchpoint (bpt) && target_has_execution)
6747 /* Format possible error msg */
6748 char *message = xstrprintf ("Error in deleting catchpoint %d:\n",
6750 struct cleanup *cleanups = make_cleanup (xfree, message);
6751 args_for_catchpoint_enable args;
6752 args.kind = bpt->type == bp_catch_catch ?
6753 EX_EVENT_CATCH : EX_EVENT_THROW;
6755 catch_errors (cover_target_enable_exception_callback, &args,
6756 message, RETURN_MASK_ALL);
6757 do_cleanups (cleanups);
6764 b->next = bpt->next;
6768 ALL_BP_LOCATIONS (loc)
6769 if (loc->next == bpt->loc)
6771 loc->next = bpt->loc->next;
6775 check_duplicates (bpt);
6776 /* If this breakpoint was inserted, and there is another breakpoint
6777 at the same address, we need to insert the other breakpoint. */
6778 if (bpt->loc->inserted
6779 && bpt->type != bp_hardware_watchpoint
6780 && bpt->type != bp_read_watchpoint
6781 && bpt->type != bp_access_watchpoint
6782 && bpt->type != bp_catch_fork
6783 && bpt->type != bp_catch_vfork
6784 && bpt->type != bp_catch_exec)
6787 if (b->loc->address == bpt->loc->address
6788 && b->loc->section == bpt->loc->section
6789 && !b->loc->duplicate
6790 && b->enable_state != bp_disabled
6791 && b->enable_state != bp_shlib_disabled
6793 && b->enable_state != bp_call_disabled)
6797 /* We should never reach this point if there is a permanent
6798 breakpoint at the same address as the one being deleted.
6799 If there is a permanent breakpoint somewhere, it should
6800 always be the only one inserted. */
6801 if (b->enable_state == bp_permanent)
6802 internal_error (__FILE__, __LINE__,
6803 "another breakpoint was inserted on top of "
6804 "a permanent breakpoint");
6806 if (b->type == bp_hardware_breakpoint)
6807 val = target_insert_hw_breakpoint (b->loc->address, b->loc->shadow_contents);
6809 val = target_insert_breakpoint (b->loc->address, b->loc->shadow_contents);
6811 /* If there was an error in the insert, print a message, then stop execution. */
6814 struct ui_file *tmp_error_stream = mem_fileopen ();
6815 make_cleanup_ui_file_delete (tmp_error_stream);
6818 if (b->type == bp_hardware_breakpoint)
6820 fprintf_unfiltered (tmp_error_stream,
6821 "Cannot insert hardware breakpoint %d.\n"
6822 "You may have requested too many hardware breakpoints.\n",
6827 fprintf_unfiltered (tmp_error_stream, "Cannot insert breakpoint %d.\n", b->number);
6828 fprintf_filtered (tmp_error_stream, "Error accessing memory address ");
6829 print_address_numeric (b->loc->address, 1, tmp_error_stream);
6830 fprintf_filtered (tmp_error_stream, ": %s.\n",
6831 safe_strerror (val));
6834 fprintf_unfiltered (tmp_error_stream,"The same program may be running in another process.");
6835 target_terminal_ours_for_output ();
6836 error_stream(tmp_error_stream);
6839 b->loc->inserted = 1;
6843 free_command_lines (&bpt->commands);
6846 if (bpt->cond_string != NULL)
6847 xfree (bpt->cond_string);
6848 if (bpt->addr_string != NULL)
6849 xfree (bpt->addr_string);
6850 if (bpt->exp != NULL)
6852 if (bpt->exp_string != NULL)
6853 xfree (bpt->exp_string);
6854 if (bpt->val != NULL)
6855 value_free (bpt->val);
6856 if (bpt->source_file != NULL)
6857 xfree (bpt->source_file);
6858 if (bpt->dll_pathname != NULL)
6859 xfree (bpt->dll_pathname);
6860 if (bpt->triggered_dll_pathname != NULL)
6861 xfree (bpt->triggered_dll_pathname);
6862 if (bpt->exec_pathname != NULL)
6863 xfree (bpt->exec_pathname);
6865 /* Be sure no bpstat's are pointing at it after it's been freed. */
6866 /* FIXME, how can we find all bpstat's?
6867 We just check stop_bpstat for now. */
6868 for (bs = stop_bpstat; bs; bs = bs->next)
6869 if (bs->breakpoint_at == bpt)
6871 bs->breakpoint_at = NULL;
6873 /* bs->commands will be freed later. */
6875 /* On the chance that someone will soon try again to delete this same
6876 bp, we mark it as deleted before freeing its storage. */
6877 bpt->type = bp_none;
6884 do_delete_breakpoint_cleanup (void *b)
6886 delete_breakpoint (b);
6890 make_cleanup_delete_breakpoint (struct breakpoint *b)
6892 return make_cleanup (do_delete_breakpoint_cleanup, b);
6896 make_exec_cleanup_delete_breakpoint (struct breakpoint *b)
6898 return make_exec_cleanup (do_delete_breakpoint_cleanup, b);
6902 delete_command (char *arg, int from_tty)
6904 struct breakpoint *b, *temp;
6910 int breaks_to_delete = 0;
6912 /* Delete all breakpoints if no argument.
6913 Do not delete internal or call-dummy breakpoints, these
6914 have to be deleted with an explicit breakpoint number argument. */
6917 if (b->type != bp_call_dummy &&
6918 b->type != bp_shlib_event &&
6919 b->type != bp_thread_event &&
6920 b->type != bp_overlay_event &&
6922 breaks_to_delete = 1;
6925 /* Ask user only if there are some breakpoints to delete. */
6927 || (breaks_to_delete && query ("Delete all breakpoints? ")))
6929 ALL_BREAKPOINTS_SAFE (b, temp)
6931 if (b->type != bp_call_dummy &&
6932 b->type != bp_shlib_event &&
6933 b->type != bp_thread_event &&
6934 b->type != bp_overlay_event &&
6936 delete_breakpoint (b);
6941 map_breakpoint_numbers (arg, delete_breakpoint);
6944 /* Reset a breakpoint given it's struct breakpoint * BINT.
6945 The value we return ends up being the return value from catch_errors.
6946 Unused in this case. */
6949 breakpoint_re_set_one (void *bint)
6951 /* get past catch_errs */
6952 struct breakpoint *b = (struct breakpoint *) bint;
6956 int *not_found_ptr = NULL;
6957 struct symtabs_and_lines sals;
6959 enum enable_state save_enable;
6964 warning ("attempted to reset apparently deleted breakpoint #%d?",
6968 case bp_hardware_breakpoint:
6970 case bp_catch_unload:
6971 if (b->addr_string == NULL)
6973 /* Anything without a string can't be re-set. */
6974 delete_breakpoint (b);
6977 /* HACK: cagney/2001-11-11: kettenis/2001-11-11: MarkK wrote:
6979 ``And a hack it is, although Apple's Darwin version of GDB
6980 contains an almost identical hack to implement a "future
6981 break" command. It seems to work in many real world cases,
6982 but it is easy to come up with a test case where the patch
6983 doesn't help at all.''
6985 ``It seems that the way GDB implements breakpoints - in -
6986 shared - libraries was designed for a.out shared library
6987 systems (SunOS 4) where shared libraries were loaded at a
6988 fixed address in memory. Since ELF shared libraries can (and
6989 will) be loaded at any address in memory, things break.
6990 Fixing this is not trivial. Therefore, I'm not sure whether
6991 we should add this hack to the branch only. I cannot
6992 guarantee that things will be fixed on the trunk in the near
6995 In case we have a problem, disable this breakpoint. We'll
6996 restore its status if we succeed. Don't disable a
6997 shlib_disabled breakpoint though. There's a fair chance we
6998 can't re-set it if the shared library it's in hasn't been
7004 save_enable = b->enable_state;
7005 if (b->enable_state != bp_shlib_disabled)
7006 b->enable_state = bp_disabled;
7008 /* If resetting a shlib-disabled breakpoint, we don't want to
7009 see an error message if it is not found since we will expect
7010 this to occur until the shared library is finally reloaded.
7011 We accomplish this by giving decode_line_1 a pointer to use
7012 for silent notification that the symbol is not found. */
7013 not_found_ptr = ¬_found;
7015 set_language (b->language);
7016 input_radix = b->input_radix;
7018 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL,
7020 for (i = 0; i < sals.nelts; i++)
7022 resolve_sal_pc (&sals.sals[i]);
7024 /* Reparse conditions, they might contain references to the
7026 if (b->cond_string != NULL)
7032 /* Avoid re-freeing b->exp if an error during the call
7036 b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0);
7039 /* We need to re-set the breakpoint if the address changes... */
7040 if (b->loc->address != sals.sals[i].pc
7041 /* ...or new and old breakpoints both have source files, and
7042 the source file name or the line number changes... */
7043 || (b->source_file != NULL
7044 && sals.sals[i].symtab != NULL
7045 && (strcmp (b->source_file, sals.sals[i].symtab->filename) != 0
7046 || b->line_number != sals.sals[i].line)
7048 /* ...or we switch between having a source file and not having
7050 || ((b->source_file == NULL) != (sals.sals[i].symtab == NULL))
7053 if (b->source_file != NULL)
7054 xfree (b->source_file);
7055 if (sals.sals[i].symtab == NULL)
7056 b->source_file = NULL;
7059 savestring (sals.sals[i].symtab->filename,
7060 strlen (sals.sals[i].symtab->filename));
7061 b->line_number = sals.sals[i].line;
7062 b->loc->requested_address = sals.sals[i].pc;
7064 = adjust_breakpoint_address (b->loc->requested_address,
7067 /* Used to check for duplicates here, but that can
7068 cause trouble, as it doesn't check for disabled
7073 /* Might be better to do this just once per breakpoint_re_set,
7074 rather than once for every breakpoint. */
7075 breakpoints_changed ();
7077 b->loc->section = sals.sals[i].section;
7078 b->enable_state = save_enable; /* Restore it, this worked. */
7081 /* Now that this is re-enabled, check_duplicates
7083 check_duplicates (b);
7090 case bp_hardware_watchpoint:
7091 case bp_read_watchpoint:
7092 case bp_access_watchpoint:
7093 innermost_block = NULL;
7094 /* The issue arises of what context to evaluate this in. The
7095 same one as when it was set, but what does that mean when
7096 symbols have been re-read? We could save the filename and
7097 functionname, but if the context is more local than that, the
7098 best we could do would be something like how many levels deep
7099 and which index at that particular level, but that's going to
7100 be less stable than filenames or function names. */
7102 /* So for now, just use a global context. */
7106 /* Avoid re-freeing b->exp if an error during the call to
7107 parse_expression. */
7110 b->exp = parse_expression (b->exp_string);
7111 b->exp_valid_block = innermost_block;
7112 mark = value_mark ();
7115 value_free (b->val);
7116 /* Avoid re-freeing b->val if an error during the call to
7117 evaluate_expression. */
7120 b->val = evaluate_expression (b->exp);
7121 release_value (b->val);
7122 if (VALUE_LAZY (b->val) && breakpoint_enabled (b))
7123 value_fetch_lazy (b->val);
7125 if (b->cond_string != NULL)
7131 /* Avoid re-freeing b->exp if an error during the call
7135 b->cond = parse_exp_1 (&s, (struct block *) 0, 0);
7137 if (breakpoint_enabled (b))
7139 value_free_to_mark (mark);
7141 case bp_catch_catch:
7142 case bp_catch_throw:
7144 /* We needn't really do anything to reset these, since the mask
7145 that requests them is unaffected by e.g., new libraries being
7148 case bp_catch_vfork:
7153 printf_filtered ("Deleting unknown breakpoint type %d\n", b->type);
7155 /* Delete longjmp and overlay event breakpoints; they will be
7156 reset later by breakpoint_re_set. */
7158 case bp_longjmp_resume:
7159 case bp_overlay_event:
7160 delete_breakpoint (b);
7163 /* This breakpoint is special, it's set up when the inferior
7164 starts and we really don't want to touch it. */
7165 case bp_shlib_event:
7167 /* Like bp_shlib_event, this breakpoint type is special.
7168 Once it is set up, we do not want to touch it. */
7169 case bp_thread_event:
7171 /* Keep temporary breakpoints, which can be encountered when we step
7172 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7173 Otherwise these should have been blown away via the cleanup chain
7174 or by breakpoint_init_inferior when we rerun the executable. */
7177 case bp_watchpoint_scope:
7179 case bp_step_resume:
7186 /* Re-set all breakpoints after symbols have been re-loaded. */
7188 breakpoint_re_set (void)
7190 struct breakpoint *b, *temp;
7191 enum language save_language;
7192 int save_input_radix;
7194 save_language = current_language->la_language;
7195 save_input_radix = input_radix;
7196 ALL_BREAKPOINTS_SAFE (b, temp)
7198 /* Format possible error msg */
7199 char *message = xstrprintf ("Error in re-setting breakpoint %d:\n",
7201 struct cleanup *cleanups = make_cleanup (xfree, message);
7202 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
7203 do_cleanups (cleanups);
7205 set_language (save_language);
7206 input_radix = save_input_radix;
7208 if (GET_LONGJMP_TARGET_P ())
7210 create_longjmp_breakpoint ("longjmp");
7211 create_longjmp_breakpoint ("_longjmp");
7212 create_longjmp_breakpoint ("siglongjmp");
7213 create_longjmp_breakpoint ("_siglongjmp");
7214 create_longjmp_breakpoint (NULL);
7217 create_overlay_event_breakpoint ("_ovly_debug_event");
7220 /* Reset the thread number of this breakpoint:
7222 - If the breakpoint is for all threads, leave it as-is.
7223 - Else, reset it to the current thread for inferior_ptid. */
7225 breakpoint_re_set_thread (struct breakpoint *b)
7227 if (b->thread != -1)
7229 if (in_thread_list (inferior_ptid))
7230 b->thread = pid_to_thread_id (inferior_ptid);
7234 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7235 If from_tty is nonzero, it prints a message to that effect,
7236 which ends with a period (no newline). */
7239 set_ignore_count (int bptnum, int count, int from_tty)
7241 struct breakpoint *b;
7247 if (b->number == bptnum)
7249 b->ignore_count = count;
7253 printf_filtered ("Will stop next time breakpoint %d is reached.",
7255 else if (count == 1)
7256 printf_filtered ("Will ignore next crossing of breakpoint %d.",
7259 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
7262 breakpoints_changed ();
7263 breakpoint_modify_event (b->number);
7267 error ("No breakpoint number %d.", bptnum);
7270 /* Clear the ignore counts of all breakpoints. */
7272 breakpoint_clear_ignore_counts (void)
7274 struct breakpoint *b;
7277 b->ignore_count = 0;
7280 /* Command to set ignore-count of breakpoint N to COUNT. */
7283 ignore_command (char *args, int from_tty)
7289 error_no_arg ("a breakpoint number");
7291 num = get_number (&p);
7293 error ("bad breakpoint number: '%s'", args);
7295 error ("Second argument (specified ignore-count) is missing.");
7297 set_ignore_count (num,
7298 longest_to_int (value_as_long (parse_and_eval (p))),
7301 printf_filtered ("\n");
7304 /* Call FUNCTION on each of the breakpoints
7305 whose numbers are given in ARGS. */
7308 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *))
7313 struct breakpoint *b, *tmp;
7317 error_no_arg ("one or more breakpoint numbers");
7324 num = get_number_or_range (&p1);
7327 warning ("bad breakpoint number at or near '%s'", p);
7331 ALL_BREAKPOINTS_SAFE (b, tmp)
7332 if (b->number == num)
7334 struct breakpoint *related_breakpoint = b->related_breakpoint;
7337 if (related_breakpoint)
7338 function (related_breakpoint);
7342 printf_unfiltered ("No breakpoint number %d.\n", num);
7348 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7349 If from_tty is nonzero, it prints a message to that effect,
7350 which ends with a period (no newline). */
7353 disable_breakpoint (struct breakpoint *bpt)
7355 /* Never disable a watchpoint scope breakpoint; we want to
7356 hit them when we leave scope so we can delete both the
7357 watchpoint and its scope breakpoint at that time. */
7358 if (bpt->type == bp_watchpoint_scope)
7361 /* You can't disable permanent breakpoints. */
7362 if (bpt->enable_state == bp_permanent)
7365 bpt->enable_state = bp_disabled;
7367 check_duplicates (bpt);
7369 if (deprecated_modify_breakpoint_hook)
7370 deprecated_modify_breakpoint_hook (bpt);
7371 breakpoint_modify_event (bpt->number);
7375 disable_command (char *args, int from_tty)
7377 struct breakpoint *bpt;
7379 ALL_BREAKPOINTS (bpt)
7383 warning ("attempted to disable apparently deleted breakpoint #%d?",
7388 case bp_catch_unload:
7390 case bp_catch_vfork:
7392 case bp_catch_catch:
7393 case bp_catch_throw:
7394 case bp_hardware_breakpoint:
7396 case bp_hardware_watchpoint:
7397 case bp_read_watchpoint:
7398 case bp_access_watchpoint:
7399 disable_breakpoint (bpt);
7404 map_breakpoint_numbers (args, disable_breakpoint);
7408 do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition)
7410 int target_resources_ok, other_type_used;
7413 if (bpt->type == bp_hardware_breakpoint)
7416 i = hw_breakpoint_used_count ();
7417 target_resources_ok =
7418 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
7420 if (target_resources_ok == 0)
7421 error ("No hardware breakpoint support in the target.");
7422 else if (target_resources_ok < 0)
7423 error ("Hardware breakpoints used exceeds limit.");
7428 if (bpt->enable_state != bp_enabled)
7430 /* When enabling a pending breakpoint, we need to check if the breakpoint
7431 is resolvable since shared libraries could have been loaded
7432 after the breakpoint was disabled. */
7433 breakpoints_changed ();
7434 if (resolve_pending_breakpoint (bpt) == GDB_RC_OK)
7436 delete_breakpoint (bpt);
7439 bpt->enable_state = bp_enabled;
7440 bpt->disposition = disposition;
7443 else /* Not a pending breakpoint. */
7445 if (bpt->enable_state != bp_permanent)
7446 bpt->enable_state = bp_enabled;
7447 bpt->disposition = disposition;
7448 check_duplicates (bpt);
7449 breakpoints_changed ();
7451 if (bpt->type == bp_watchpoint ||
7452 bpt->type == bp_hardware_watchpoint ||
7453 bpt->type == bp_read_watchpoint ||
7454 bpt->type == bp_access_watchpoint)
7456 struct frame_id saved_frame_id;
7458 saved_frame_id = get_frame_id (get_selected_frame (NULL));
7459 if (bpt->exp_valid_block != NULL)
7461 struct frame_info *fr =
7462 fr = frame_find_by_id (bpt->watchpoint_frame);
7466 Cannot enable watchpoint %d because the block in which its expression\n\
7467 is valid is not currently in scope.\n", bpt->number);
7468 bpt->enable_state = bp_disabled;
7474 value_free (bpt->val);
7475 mark = value_mark ();
7476 bpt->val = evaluate_expression (bpt->exp);
7477 release_value (bpt->val);
7478 if (VALUE_LAZY (bpt->val))
7479 value_fetch_lazy (bpt->val);
7481 if (bpt->type == bp_hardware_watchpoint ||
7482 bpt->type == bp_read_watchpoint ||
7483 bpt->type == bp_access_watchpoint)
7485 int i = hw_watchpoint_used_count (bpt->type, &other_type_used);
7486 int mem_cnt = can_use_hardware_watchpoint (bpt->val);
7488 /* Hack around 'unused var' error for some targets here */
7490 target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7491 bpt->type, i + mem_cnt, other_type_used);
7492 /* we can consider of type is bp_hardware_watchpoint, convert to
7493 bp_watchpoint in the following condition */
7494 if (target_resources_ok < 0)
7497 Cannot enable watchpoint %d because target watch resources\n\
7498 have been allocated for other watchpoints.\n", bpt->number);
7499 bpt->enable_state = bp_disabled;
7500 value_free_to_mark (mark);
7505 select_frame (frame_find_by_id (saved_frame_id));
7506 value_free_to_mark (mark);
7510 if (deprecated_modify_breakpoint_hook)
7511 deprecated_modify_breakpoint_hook (bpt);
7512 breakpoint_modify_event (bpt->number);
7516 enable_breakpoint (struct breakpoint *bpt)
7518 do_enable_breakpoint (bpt, bpt->disposition);
7521 /* The enable command enables the specified breakpoints (or all defined
7522 breakpoints) so they once again become (or continue to be) effective
7523 in stopping the inferior. */
7526 enable_command (char *args, int from_tty)
7528 struct breakpoint *bpt;
7530 ALL_BREAKPOINTS (bpt)
7534 warning ("attempted to enable apparently deleted breakpoint #%d?",
7539 case bp_catch_unload:
7541 case bp_catch_vfork:
7543 case bp_catch_catch:
7544 case bp_catch_throw:
7545 case bp_hardware_breakpoint:
7547 case bp_hardware_watchpoint:
7548 case bp_read_watchpoint:
7549 case bp_access_watchpoint:
7550 enable_breakpoint (bpt);
7555 map_breakpoint_numbers (args, enable_breakpoint);
7559 enable_once_breakpoint (struct breakpoint *bpt)
7561 do_enable_breakpoint (bpt, disp_disable);
7565 enable_once_command (char *args, int from_tty)
7567 map_breakpoint_numbers (args, enable_once_breakpoint);
7571 enable_delete_breakpoint (struct breakpoint *bpt)
7573 do_enable_breakpoint (bpt, disp_del);
7577 enable_delete_command (char *args, int from_tty)
7579 map_breakpoint_numbers (args, enable_delete_breakpoint);
7583 set_breakpoint_cmd (char *args, int from_tty)
7588 show_breakpoint_cmd (char *args, int from_tty)
7592 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7594 struct symtabs_and_lines
7595 decode_line_spec_1 (char *string, int funfirstline)
7597 struct symtabs_and_lines sals;
7599 error ("Empty line specification.");
7600 if (default_breakpoint_valid)
7601 sals = decode_line_1 (&string, funfirstline,
7602 default_breakpoint_symtab,
7603 default_breakpoint_line,
7604 (char ***) NULL, NULL);
7606 sals = decode_line_1 (&string, funfirstline,
7607 (struct symtab *) NULL, 0, (char ***) NULL, NULL);
7609 error ("Junk at end of line specification: %s", string);
7614 _initialize_breakpoint (void)
7616 static struct cmd_list_element *breakpoint_set_cmdlist;
7617 static struct cmd_list_element *breakpoint_show_cmdlist;
7618 struct cmd_list_element *c;
7621 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
7624 breakpoint_chain = 0;
7625 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
7626 before a breakpoint is set. */
7627 breakpoint_count = 0;
7629 add_com ("ignore", class_breakpoint, ignore_command,
7630 "Set ignore-count of breakpoint number N to COUNT.\n\
7631 Usage is `ignore N COUNT'.");
7633 add_com_alias ("bc", "ignore", class_breakpoint, 1);
7635 add_com ("commands", class_breakpoint, commands_command,
7636 "Set commands to be executed when a breakpoint is hit.\n\
7637 Give breakpoint number as argument after \"commands\".\n\
7638 With no argument, the targeted breakpoint is the last one set.\n\
7639 The commands themselves follow starting on the next line.\n\
7640 Type a line containing \"end\" to indicate the end of them.\n\
7641 Give \"silent\" as the first line to make the breakpoint silent;\n\
7642 then no output is printed when it is hit, except what the commands print.");
7644 add_com ("condition", class_breakpoint, condition_command,
7645 "Specify breakpoint number N to break only if COND is true.\n\
7646 Usage is `condition N COND', where N is an integer and COND is an\n\
7647 expression to be evaluated whenever breakpoint N is reached.");
7649 c = add_com ("tbreak", class_breakpoint, tbreak_command,
7650 "Set a temporary breakpoint. Args like \"break\" command.\n\
7651 Like \"break\" except the breakpoint is only temporary,\n\
7652 so it will be deleted when hit. Equivalent to \"break\" followed\n\
7653 by using \"enable delete\" on the breakpoint number.");
7654 set_cmd_completer (c, location_completer);
7656 c = add_com ("hbreak", class_breakpoint, hbreak_command,
7657 "Set a hardware assisted breakpoint. Args like \"break\" command.\n\
7658 Like \"break\" except the breakpoint requires hardware support,\n\
7659 some target hardware may not have this support.");
7660 set_cmd_completer (c, location_completer);
7662 c = add_com ("thbreak", class_breakpoint, thbreak_command,
7663 "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\
7664 Like \"hbreak\" except the breakpoint is only temporary,\n\
7665 so it will be deleted when hit.");
7666 set_cmd_completer (c, location_completer);
7668 add_prefix_cmd ("enable", class_breakpoint, enable_command,
7669 "Enable some breakpoints.\n\
7670 Give breakpoint numbers (separated by spaces) as arguments.\n\
7671 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7672 This is used to cancel the effect of the \"disable\" command.\n\
7673 With a subcommand you can enable temporarily.",
7674 &enablelist, "enable ", 1, &cmdlist);
7676 add_com ("ab", class_breakpoint, enable_command,
7677 "Enable some breakpoints.\n\
7678 Give breakpoint numbers (separated by spaces) as arguments.\n\
7679 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7680 This is used to cancel the effect of the \"disable\" command.\n\
7681 With a subcommand you can enable temporarily.");
7683 add_com_alias ("en", "enable", class_breakpoint, 1);
7685 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command,
7686 "Enable some breakpoints.\n\
7687 Give breakpoint numbers (separated by spaces) as arguments.\n\
7688 This is used to cancel the effect of the \"disable\" command.\n\
7689 May be abbreviated to simply \"enable\".\n",
7690 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
7692 add_cmd ("once", no_class, enable_once_command,
7693 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7694 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7697 add_cmd ("delete", no_class, enable_delete_command,
7698 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7699 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7702 add_cmd ("delete", no_class, enable_delete_command,
7703 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7704 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7707 add_cmd ("once", no_class, enable_once_command,
7708 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7709 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7712 add_prefix_cmd ("disable", class_breakpoint, disable_command,
7713 "Disable some breakpoints.\n\
7714 Arguments are breakpoint numbers with spaces in between.\n\
7715 To disable all breakpoints, give no argument.\n\
7716 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
7717 &disablelist, "disable ", 1, &cmdlist);
7718 add_com_alias ("dis", "disable", class_breakpoint, 1);
7719 add_com_alias ("disa", "disable", class_breakpoint, 1);
7721 add_com ("sb", class_breakpoint, disable_command,
7722 "Disable some breakpoints.\n\
7723 Arguments are breakpoint numbers with spaces in between.\n\
7724 To disable all breakpoints, give no argument.\n\
7725 A disabled breakpoint is not forgotten, but has no effect until reenabled.");
7727 add_cmd ("breakpoints", class_alias, disable_command,
7728 "Disable some breakpoints.\n\
7729 Arguments are breakpoint numbers with spaces in between.\n\
7730 To disable all breakpoints, give no argument.\n\
7731 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
7732 This command may be abbreviated \"disable\".",
7735 add_prefix_cmd ("delete", class_breakpoint, delete_command,
7736 "Delete some breakpoints or auto-display expressions.\n\
7737 Arguments are breakpoint numbers with spaces in between.\n\
7738 To delete all breakpoints, give no argument.\n\
7740 Also a prefix command for deletion of other GDB objects.\n\
7741 The \"unset\" command is also an alias for \"delete\".",
7742 &deletelist, "delete ", 1, &cmdlist);
7743 add_com_alias ("d", "delete", class_breakpoint, 1);
7745 add_com ("db", class_breakpoint, delete_command,
7746 "Delete some breakpoints.\n\
7747 Arguments are breakpoint numbers with spaces in between.\n\
7748 To delete all breakpoints, give no argument.\n");
7750 add_cmd ("breakpoints", class_alias, delete_command,
7751 "Delete some breakpoints or auto-display expressions.\n\
7752 Arguments are breakpoint numbers with spaces in between.\n\
7753 To delete all breakpoints, give no argument.\n\
7754 This command may be abbreviated \"delete\".",
7757 add_com ("clear", class_breakpoint, clear_command,
7758 concat ("Clear breakpoint at specified line or function.\n\
7759 Argument may be line number, function name, or \"*\" and an address.\n\
7760 If line number is specified, all breakpoints in that line are cleared.\n\
7761 If function is specified, breakpoints at beginning of function are cleared.\n\
7762 If an address is specified, breakpoints at that address are cleared.\n\n",
7763 "With no argument, clears all breakpoints in the line that the selected frame\n\
7766 See also the \"delete\" command which clears breakpoints by number.", NULL));
7768 c = add_com ("break", class_breakpoint, break_command,
7769 concat ("Set breakpoint at specified line or function.\n\
7770 Argument may be line number, function name, or \"*\" and an address.\n\
7771 If line number is specified, break at start of code for that line.\n\
7772 If function is specified, break at start of code for that function.\n\
7773 If an address is specified, break at that exact address.\n",
7774 "With no arg, uses current execution address of selected stack frame.\n\
7775 This is useful for breaking on return to a stack frame.\n\
7777 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7779 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL));
7780 set_cmd_completer (c, location_completer);
7782 add_com_alias ("b", "break", class_run, 1);
7783 add_com_alias ("br", "break", class_run, 1);
7784 add_com_alias ("bre", "break", class_run, 1);
7785 add_com_alias ("brea", "break", class_run, 1);
7789 add_com_alias ("ba", "break", class_breakpoint, 1);
7790 add_com_alias ("bu", "ubreak", class_breakpoint, 1);
7795 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command,
7796 "Break in function/address or break at a line in the current file.",
7797 &stoplist, "stop ", 1, &cmdlist);
7798 add_cmd ("in", class_breakpoint, stopin_command,
7799 "Break in function or address.\n", &stoplist);
7800 add_cmd ("at", class_breakpoint, stopat_command,
7801 "Break at a line in the current file.\n", &stoplist);
7802 add_com ("status", class_info, breakpoints_info,
7803 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7804 The \"Type\" column indicates one of:\n\
7805 \tbreakpoint - normal breakpoint\n\
7806 \twatchpoint - watchpoint\n\
7807 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7808 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7809 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7810 address and file/line number respectively.\n\n",
7811 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7812 are set to the address of the last breakpoint listed.\n\n\
7813 Convenience variable \"$bpnum\" contains the number of the last\n\
7814 breakpoint set.", NULL));
7817 add_info ("breakpoints", breakpoints_info,
7818 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7819 The \"Type\" column indicates one of:\n\
7820 \tbreakpoint - normal breakpoint\n\
7821 \twatchpoint - watchpoint\n\
7822 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7823 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7824 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7825 address and file/line number respectively.\n\n",
7826 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7827 are set to the address of the last breakpoint listed.\n\n\
7828 Convenience variable \"$bpnum\" contains the number of the last\n\
7829 breakpoint set.", NULL));
7832 add_com ("lb", class_breakpoint, breakpoints_info,
7833 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7834 The \"Type\" column indicates one of:\n\
7835 \tbreakpoint - normal breakpoint\n\
7836 \twatchpoint - watchpoint\n\
7837 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7838 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7839 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7840 address and file/line number respectively.\n\n",
7841 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7842 are set to the address of the last breakpoint listed.\n\n\
7843 Convenience variable \"$bpnum\" contains the number of the last\n\
7844 breakpoint set.", NULL));
7846 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints,
7847 concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\
7848 The \"Type\" column indicates one of:\n\
7849 \tbreakpoint - normal breakpoint\n\
7850 \twatchpoint - watchpoint\n\
7851 \tlongjmp - internal breakpoint used to step through longjmp()\n\
7852 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
7853 \tuntil - internal breakpoint used by the \"until\" command\n\
7854 \tfinish - internal breakpoint used by the \"finish\" command\n",
7855 "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7856 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7857 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7858 address and file/line number respectively.\n\n",
7859 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7860 are set to the address of the last breakpoint listed.\n\n\
7861 Convenience variable \"$bpnum\" contains the number of the last\n\
7862 breakpoint set.", NULL),
7863 &maintenanceinfolist);
7865 add_com ("catch", class_breakpoint, catch_command,
7866 "Set catchpoints to catch events.\n\
7867 Raised signals may be caught:\n\
7868 \tcatch signal - all signals\n\
7869 \tcatch signal <signame> - a particular signal\n\
7870 Raised exceptions may be caught:\n\
7871 \tcatch throw - all exceptions, when thrown\n\
7872 \tcatch throw <exceptname> - a particular exception, when thrown\n\
7873 \tcatch catch - all exceptions, when caught\n\
7874 \tcatch catch <exceptname> - a particular exception, when caught\n\
7875 Thread or process events may be caught:\n\
7876 \tcatch thread_start - any threads, just after creation\n\
7877 \tcatch thread_exit - any threads, just before expiration\n\
7878 \tcatch thread_join - any threads, just after joins\n\
7879 Process events may be caught:\n\
7880 \tcatch start - any processes, just after creation\n\
7881 \tcatch exit - any processes, just before expiration\n\
7882 \tcatch fork - calls to fork()\n\
7883 \tcatch vfork - calls to vfork()\n\
7884 \tcatch exec - calls to exec()\n\
7885 Dynamically-linked library events may be caught:\n\
7886 \tcatch load - loads of any library\n\
7887 \tcatch load <libname> - loads of a particular library\n\
7888 \tcatch unload - unloads of any library\n\
7889 \tcatch unload <libname> - unloads of a particular library\n\
7890 The act of your program's execution stopping may also be caught:\n\
7892 C++ exceptions may be caught:\n\
7893 \tcatch throw - all exceptions, when thrown\n\
7894 \tcatch catch - all exceptions, when caught\n\
7896 Do \"help set follow-fork-mode\" for info on debugging your program\n\
7897 after a fork or vfork is caught.\n\n\
7898 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
7900 add_com ("tcatch", class_breakpoint, tcatch_command,
7901 "Set temporary catchpoints to catch events.\n\
7902 Args like \"catch\" command.\n\
7903 Like \"catch\" except the catchpoint is only temporary,\n\
7904 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
7905 by using \"enable delete\" on the catchpoint number.");
7907 c = add_com ("watch", class_breakpoint, watch_command,
7908 "Set a watchpoint for an expression.\n\
7909 A watchpoint stops execution of your program whenever the value of\n\
7910 an expression changes.");
7911 set_cmd_completer (c, location_completer);
7913 c = add_com ("rwatch", class_breakpoint, rwatch_command,
7914 "Set a read watchpoint for an expression.\n\
7915 A watchpoint stops execution of your program whenever the value of\n\
7916 an expression is read.");
7917 set_cmd_completer (c, location_completer);
7919 c = add_com ("awatch", class_breakpoint, awatch_command,
7920 "Set a watchpoint for an expression.\n\
7921 A watchpoint stops execution of your program whenever the value of\n\
7922 an expression is either read or written.");
7923 set_cmd_completer (c, location_completer);
7925 add_info ("watchpoints", breakpoints_info,
7926 "Synonym for ``info breakpoints''.");
7929 c = add_set_cmd ("can-use-hw-watchpoints", class_support, var_zinteger,
7930 (char *) &can_use_hw_watchpoints,
7931 "Set debugger's willingness to use watchpoint hardware.\n\
7932 If zero, gdb will not use hardware for new watchpoints, even if\n\
7933 such is available. (However, any hardware watchpoints that were\n\
7934 created before setting this to nonzero, will continue to use watchpoint\n\
7937 deprecated_add_show_from_set (c, &showlist);
7939 can_use_hw_watchpoints = 1;
7941 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, "\
7942 Breakpoint specific settings\n\
7943 Configure various breakpoint-specific variables such as\n\
7944 pending breakpoint behavior",
7945 &breakpoint_set_cmdlist, "set breakpoint ",
7946 0/*allow-unknown*/, &setlist);
7947 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, "\
7948 Breakpoint specific settings\n\
7949 Configure various breakpoint-specific variables such as\n\
7950 pending breakpoint behavior",
7951 &breakpoint_show_cmdlist, "show breakpoint ",
7952 0/*allow-unknown*/, &showlist);
7954 add_setshow_auto_boolean_cmd ("pending", no_class, &pending_break_support, "\
7955 Set debugger's behavior regarding pending breakpoints.", "\
7956 Show debugger's behavior regarding pending breakpoints.", "\
7957 If on, an unrecognized breakpoint location will cause gdb to create a\n\
7958 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
7959 an error. If auto, an unrecognized breakpoint location results in a\n\
7960 user-query to see if a pending breakpoint should be created.", "\
7961 Debugger's behavior regarding pending breakpoints is %s.",
7963 &breakpoint_set_cmdlist,
7964 &breakpoint_show_cmdlist);
7966 pending_break_support = AUTO_BOOLEAN_AUTO;