1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
5 2008 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 3 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, see <http://www.gnu.org/licenses/>. */
27 #include "breakpoint.h"
29 #include "expression.h"
35 #include "gdbthread.h"
38 #include "gdb_string.h"
45 #include "completer.h"
48 #include "cli/cli-script.h"
49 #include "gdb_assert.h"
54 #include "exceptions.h"
61 #include "mi/mi-common.h"
63 /* Arguments to pass as context to some catch command handlers. */
64 #define CATCH_PERMANENT ((void *) (uintptr_t) 0)
65 #define CATCH_TEMPORARY ((void *) (uintptr_t) 1)
67 /* Prototypes for local functions. */
69 static void enable_delete_command (char *, int);
71 static void enable_delete_breakpoint (struct breakpoint *);
73 static void enable_once_command (char *, int);
75 static void enable_once_breakpoint (struct breakpoint *);
77 static void disable_command (char *, int);
79 static void enable_command (char *, int);
81 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint *));
83 static void ignore_command (char *, int);
85 static int breakpoint_re_set_one (void *);
87 static void clear_command (char *, int);
89 static void catch_command (char *, int);
91 static void watch_command (char *, int);
93 static int can_use_hardware_watchpoint (struct value *);
95 static void break_command_1 (char *, int, int);
97 static void mention (struct breakpoint *);
99 struct breakpoint *set_raw_breakpoint (struct symtab_and_line, enum bptype);
101 static void check_duplicates (struct breakpoint *);
103 static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
105 static CORE_ADDR adjust_breakpoint_address (CORE_ADDR bpaddr,
108 static void describe_other_breakpoints (CORE_ADDR, struct obj_section *, int);
110 static void breakpoints_info (char *, int);
112 static void breakpoint_1 (int, int);
114 static bpstat bpstat_alloc (const struct bp_location *, bpstat);
116 static int breakpoint_cond_eval (void *);
118 static void cleanup_executing_breakpoints (void *);
120 static void commands_command (char *, int);
122 static void condition_command (char *, int);
124 static int get_number_trailer (char **, int);
126 void set_breakpoint_count (int);
135 static int remove_breakpoint (struct bp_location *, insertion_state_t);
137 static enum print_stop_action print_it_typical (bpstat);
139 static enum print_stop_action print_bp_stop_message (bpstat bs);
141 static int watchpoint_check (void *);
143 static void maintenance_info_breakpoints (char *, int);
145 static void create_overlay_event_breakpoint (char *);
147 static int hw_breakpoint_used_count (void);
149 static int hw_watchpoint_used_count (enum bptype, int *);
151 static void hbreak_command (char *, int);
153 static void thbreak_command (char *, int);
155 static void watch_command_1 (char *, int, int);
157 static void rwatch_command (char *, int);
159 static void awatch_command (char *, int);
161 static void do_enable_breakpoint (struct breakpoint *, enum bpdisp);
163 static void stop_command (char *arg, int from_tty);
165 static void stopin_command (char *arg, int from_tty);
167 static void stopat_command (char *arg, int from_tty);
169 static char *ep_parse_optional_if_clause (char **arg);
171 static char *ep_parse_optional_filename (char **arg);
173 static void catch_exception_command_1 (enum exception_event_kind ex_event,
174 char *arg, int tempflag, int from_tty);
176 static void tcatch_command (char *arg, int from_tty);
178 static void ep_skip_leading_whitespace (char **s);
180 static int single_step_breakpoint_inserted_here_p (CORE_ADDR pc);
182 static void free_bp_location (struct bp_location *loc);
184 static struct bp_location *
185 allocate_bp_location (struct breakpoint *bpt, enum bptype bp_type);
187 static void update_global_location_list (int);
189 static void update_global_location_list_nothrow (int);
191 static int is_hardware_watchpoint (struct breakpoint *bpt);
193 static void insert_breakpoint_locations (void);
196 bpdisp_text (enum bpdisp disp)
198 /* NOTE: the following values are a part of MI protocol and represent
199 values of 'disp' field returned when inferior stops at a breakpoint. */
200 static char *bpdisps[] = {"del", "dstp", "dis", "keep"};
201 return bpdisps[(int) disp];
204 /* Prototypes for exported functions. */
205 /* If FALSE, gdb will not use hardware support for watchpoints, even
206 if such is available. */
207 static int can_use_hw_watchpoints;
210 show_can_use_hw_watchpoints (struct ui_file *file, int from_tty,
211 struct cmd_list_element *c,
214 fprintf_filtered (file, _("\
215 Debugger's willingness to use watchpoint hardware is %s.\n"),
219 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
220 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
221 for unrecognized breakpoint locations.
222 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
223 static enum auto_boolean pending_break_support;
225 show_pending_break_support (struct ui_file *file, int from_tty,
226 struct cmd_list_element *c,
229 fprintf_filtered (file, _("\
230 Debugger's behavior regarding pending breakpoints is %s.\n"),
234 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
235 set with "break" but falling in read-only memory.
236 If 0, gdb will warn about such breakpoints, but won't automatically
237 use hardware breakpoints. */
238 static int automatic_hardware_breakpoints;
240 show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty,
241 struct cmd_list_element *c,
244 fprintf_filtered (file, _("\
245 Automatic usage of hardware breakpoints is %s.\n"),
249 /* If on, gdb will keep breakpoints inserted even as inferior is
250 stopped, and immediately insert any new breakpoints. If off, gdb
251 will insert breakpoints into inferior only when resuming it, and
252 will remove breakpoints upon stop. If auto, GDB will behave as ON
253 if in non-stop mode, and as OFF if all-stop mode.*/
255 static const char always_inserted_auto[] = "auto";
256 static const char always_inserted_on[] = "on";
257 static const char always_inserted_off[] = "off";
258 static const char *always_inserted_enums[] = {
259 always_inserted_auto,
264 static const char *always_inserted_mode = always_inserted_auto;
266 show_always_inserted_mode (struct ui_file *file, int from_tty,
267 struct cmd_list_element *c, const char *value)
269 if (always_inserted_mode == always_inserted_auto)
270 fprintf_filtered (file, _("\
271 Always inserted breakpoint mode is %s (currently %s).\n"),
273 breakpoints_always_inserted_mode () ? "on" : "off");
275 fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), value);
279 breakpoints_always_inserted_mode (void)
281 return (always_inserted_mode == always_inserted_on
282 || (always_inserted_mode == always_inserted_auto && non_stop));
285 void _initialize_breakpoint (void);
287 /* Are we executing breakpoint commands? */
288 static int executing_breakpoint_commands;
290 /* Are overlay event breakpoints enabled? */
291 static int overlay_events_enabled;
293 /* Walk the following statement or block through all breakpoints.
294 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
297 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
299 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
300 for (B = breakpoint_chain; \
301 B ? (TMP=B->next, 1): 0; \
304 /* Similar iterators for the low-level breakpoints. */
306 #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->global_next)
308 #define ALL_BP_LOCATIONS_SAFE(B,TMP) \
309 for (B = bp_location_chain; \
310 B ? (TMP=B->global_next, 1): 0; \
313 /* Chains of all breakpoints defined. */
315 struct breakpoint *breakpoint_chain;
317 struct bp_location *bp_location_chain;
319 /* The locations that no longer correspond to any breakpoint,
320 unlinked from bp_location_chain, but for which a hit
321 may still be reported by a target. */
322 VEC(bp_location_p) *moribund_locations = NULL;
324 /* Number of last breakpoint made. */
326 int breakpoint_count;
328 /* This function returns a pointer to the string representation of the
329 pathname of the dynamically-linked library that has just been
332 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
333 or undefined results are guaranteed.
335 This string's contents are only valid immediately after the
336 inferior has stopped in the dynamic linker hook, and becomes
337 invalid as soon as the inferior is continued. Clients should make
338 a copy of this string if they wish to continue the inferior and
339 then access the string. */
341 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
342 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
345 /* This function returns a pointer to the string representation of the
346 pathname of the dynamically-linked library that has just been
349 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
350 TRUE, or undefined results are guaranteed.
352 This string's contents are only valid immediately after the
353 inferior has stopped in the dynamic linker hook, and becomes
354 invalid as soon as the inferior is continued. Clients should make
355 a copy of this string if they wish to continue the inferior and
356 then access the string. */
358 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
359 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
362 /* This function is called by the "catch load" command. It allows the
363 debugger to be notified by the dynamic linker when a specified
364 library file (or any library file, if filename is NULL) is loaded. */
366 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
367 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
368 error (_("catch of library loads not yet implemented on this platform"))
371 /* This function is called by the "catch unload" command. It allows
372 the debugger to be notified by the dynamic linker when a specified
373 library file (or any library file, if filename is NULL) is
376 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
377 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid, tempflag, filename, cond_string) \
378 error (_("catch of library unloads not yet implemented on this platform"))
381 /* Return whether a breakpoint is an active enabled breakpoint. */
383 breakpoint_enabled (struct breakpoint *b)
385 return (b->enable_state == bp_enabled);
388 /* Set breakpoint count to NUM. */
391 set_breakpoint_count (int num)
393 breakpoint_count = num;
394 set_internalvar (lookup_internalvar ("bpnum"),
395 value_from_longest (builtin_type_int32, (LONGEST) num));
398 /* Used in run_command to zero the hit count when a new run starts. */
401 clear_breakpoint_hit_counts (void)
403 struct breakpoint *b;
409 /* Default address, symtab and line to put a breakpoint at
410 for "break" command with no arg.
411 if default_breakpoint_valid is zero, the other three are
412 not valid, and "break" with no arg is an error.
414 This set by print_stack_frame, which calls set_default_breakpoint. */
416 int default_breakpoint_valid;
417 CORE_ADDR default_breakpoint_address;
418 struct symtab *default_breakpoint_symtab;
419 int default_breakpoint_line;
421 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
422 Advance *PP after the string and any trailing whitespace.
424 Currently the string can either be a number or "$" followed by the name
425 of a convenience variable. Making it an expression wouldn't work well
426 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
428 If the string is a NULL pointer, that denotes the last breakpoint.
430 TRAILER is a character which can be found after the number; most
431 commonly this is `-'. If you don't want a trailer, use \0. */
433 get_number_trailer (char **pp, int trailer)
435 int retval = 0; /* default */
439 /* Empty line means refer to the last breakpoint. */
440 return breakpoint_count;
443 /* Make a copy of the name, so we can null-terminate it
444 to pass to lookup_internalvar(). */
449 while (isalnum (*p) || *p == '_')
451 varname = (char *) alloca (p - start + 1);
452 strncpy (varname, start, p - start);
453 varname[p - start] = '\0';
454 val = value_of_internalvar (lookup_internalvar (varname));
455 if (TYPE_CODE (value_type (val)) == TYPE_CODE_INT)
456 retval = (int) value_as_long (val);
459 printf_filtered (_("Convenience variable must have integer value.\n"));
467 while (*p >= '0' && *p <= '9')
470 /* There is no number here. (e.g. "cond a == b"). */
472 /* Skip non-numeric token */
473 while (*p && !isspace((int) *p))
475 /* Return zero, which caller must interpret as error. */
481 if (!(isspace (*p) || *p == '\0' || *p == trailer))
483 /* Trailing junk: return 0 and let caller print error msg. */
484 while (!(isspace (*p) || *p == '\0' || *p == trailer))
495 /* Like get_number_trailer, but don't allow a trailer. */
497 get_number (char **pp)
499 return get_number_trailer (pp, '\0');
502 /* Parse a number or a range.
503 * A number will be of the form handled by get_number.
504 * A range will be of the form <number1> - <number2>, and
505 * will represent all the integers between number1 and number2,
508 * While processing a range, this fuction is called iteratively;
509 * At each call it will return the next value in the range.
511 * At the beginning of parsing a range, the char pointer PP will
512 * be advanced past <number1> and left pointing at the '-' token.
513 * Subsequent calls will not advance the pointer until the range
514 * is completed. The call that completes the range will advance
515 * pointer PP past <number2>.
519 get_number_or_range (char **pp)
521 static int last_retval, end_value;
522 static char *end_ptr;
523 static int in_range = 0;
527 /* Default case: pp is pointing either to a solo number,
528 or to the first number of a range. */
529 last_retval = get_number_trailer (pp, '-');
534 /* This is the start of a range (<number1> - <number2>).
535 Skip the '-', parse and remember the second number,
536 and also remember the end of the final token. */
540 while (isspace ((int) *end_ptr))
541 end_ptr++; /* skip white space */
542 end_value = get_number (temp);
543 if (end_value < last_retval)
545 error (_("inverted range"));
547 else if (end_value == last_retval)
549 /* degenerate range (number1 == number2). Advance the
550 token pointer so that the range will be treated as a
559 error (_("negative value"));
562 /* pp points to the '-' that betokens a range. All
563 number-parsing has already been done. Return the next
564 integer value (one greater than the saved previous value).
565 Do not advance the token pointer 'pp' until the end of range
568 if (++last_retval == end_value)
570 /* End of range reached; advance token pointer. */
580 /* condition N EXP -- set break condition of breakpoint N to EXP. */
583 condition_command (char *arg, int from_tty)
585 struct breakpoint *b;
590 error_no_arg (_("breakpoint number"));
593 bnum = get_number (&p);
595 error (_("Bad breakpoint argument: '%s'"), arg);
598 if (b->number == bnum)
600 struct bp_location *loc = b->loc;
601 for (; loc; loc = loc->next)
609 if (b->cond_string != NULL)
610 xfree (b->cond_string);
614 b->cond_string = NULL;
616 printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum);
621 /* I don't know if it matters whether this is the string the user
622 typed in or the decompiled expression. */
623 b->cond_string = savestring (arg, strlen (arg));
624 b->condition_not_parsed = 0;
625 for (loc = b->loc; loc; loc = loc->next)
629 parse_exp_1 (&arg, block_for_pc (loc->address), 0);
631 error (_("Junk at end of expression"));
634 breakpoints_changed ();
635 observer_notify_breakpoint_modified (b->number);
639 error (_("No breakpoint number %d."), bnum);
643 commands_command (char *arg, int from_tty)
645 struct breakpoint *b;
648 struct command_line *l;
650 /* If we allowed this, we would have problems with when to
651 free the storage, if we change the commands currently
654 if (executing_breakpoint_commands)
655 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
658 bnum = get_number (&p);
661 error (_("Unexpected extra arguments following breakpoint number."));
664 if (b->number == bnum)
666 char *tmpbuf = xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
668 struct cleanup *cleanups = make_cleanup (xfree, tmpbuf);
669 l = read_command_lines (tmpbuf, from_tty, 1);
670 do_cleanups (cleanups);
671 free_command_lines (&b->commands);
673 breakpoints_changed ();
674 observer_notify_breakpoint_modified (b->number);
677 error (_("No breakpoint number %d."), bnum);
680 /* Like commands_command, but instead of reading the commands from
681 input stream, takes them from an already parsed command structure.
683 This is used by cli-script.c to DTRT with breakpoint commands
684 that are part of if and while bodies. */
685 enum command_control_type
686 commands_from_control_command (char *arg, struct command_line *cmd)
688 struct breakpoint *b;
692 /* If we allowed this, we would have problems with when to
693 free the storage, if we change the commands currently
696 if (executing_breakpoint_commands)
697 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
699 /* An empty string for the breakpoint number means the last
700 breakpoint, but get_number expects a NULL pointer. */
705 bnum = get_number (&p);
708 error (_("Unexpected extra arguments following breakpoint number."));
711 if (b->number == bnum)
713 free_command_lines (&b->commands);
714 if (cmd->body_count != 1)
715 error (_("Invalid \"commands\" block structure."));
716 /* We need to copy the commands because if/while will free the
717 list after it finishes execution. */
718 b->commands = copy_command_lines (cmd->body_list[0]);
719 breakpoints_changed ();
720 observer_notify_breakpoint_modified (b->number);
721 return simple_control;
723 error (_("No breakpoint number %d."), bnum);
726 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
727 by replacing any memory breakpoints with their shadowed contents. */
730 breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len)
732 struct bp_location *b;
733 CORE_ADDR bp_addr = 0;
739 if (b->owner->type == bp_none)
740 warning (_("reading through apparently deleted breakpoint #%d?"),
743 if (b->loc_type != bp_loc_software_breakpoint)
747 /* Addresses and length of the part of the breakpoint that
749 bp_addr = b->target_info.placed_address;
750 bp_size = b->target_info.shadow_len;
752 /* bp isn't valid, or doesn't shadow memory. */
755 if (bp_addr + bp_size <= memaddr)
756 /* The breakpoint is entirely before the chunk of memory we
760 if (bp_addr >= memaddr + len)
761 /* The breakpoint is entirely after the chunk of memory we are
765 /* Offset within shadow_contents. */
766 if (bp_addr < memaddr)
768 /* Only copy the second part of the breakpoint. */
769 bp_size -= memaddr - bp_addr;
770 bptoffset = memaddr - bp_addr;
774 if (bp_addr + bp_size > memaddr + len)
776 /* Only copy the first part of the breakpoint. */
777 bp_size -= (bp_addr + bp_size) - (memaddr + len);
780 memcpy (buf + bp_addr - memaddr,
781 b->target_info.shadow_contents + bptoffset, bp_size);
786 /* A wrapper function for inserting catchpoints. */
788 insert_catchpoint (struct ui_out *uo, void *args)
790 struct breakpoint *b = (struct breakpoint *) args;
796 gdb_assert (b->ops != NULL && b->ops->insert != NULL);
800 target_insert_exec_catchpoint (PIDGET (inferior_ptid));
803 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
809 is_hardware_watchpoint (struct breakpoint *bpt)
811 return (bpt->type == bp_hardware_watchpoint
812 || bpt->type == bp_read_watchpoint
813 || bpt->type == bp_access_watchpoint);
816 /* Find the current value of a watchpoint on EXP. Return the value in
817 *VALP and *RESULTP and the chain of intermediate and final values
818 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
821 If an error occurs while evaluating the expression, *RESULTP will
822 be set to NULL. *RESULTP may be a lazy value, if the result could
823 not be read from memory. It is used to determine whether a value
824 is user-specified (we should watch the whole value) or intermediate
825 (we should watch only the bit used to locate the final value).
827 If the final value, or any intermediate value, could not be read
828 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
829 set to any referenced values. *VALP will never be a lazy value.
830 This is the value which we store in struct breakpoint.
832 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
833 value chain. The caller must free the values individually. If
834 VAL_CHAIN is NULL, all generated values will be left on the value
838 fetch_watchpoint_value (struct expression *exp, struct value **valp,
839 struct value **resultp, struct value **val_chain)
841 struct value *mark, *new_mark, *result;
849 /* Evaluate the expression. */
850 mark = value_mark ();
852 gdb_evaluate_expression (exp, &result);
853 new_mark = value_mark ();
854 if (mark == new_mark)
859 /* Make sure it's not lazy, so that after the target stops again we
860 have a non-lazy previous value to compare with. */
862 && (!value_lazy (result) || gdb_value_fetch_lazy (result)))
867 /* Return the chain of intermediate values. We use this to
868 decide which addresses to watch. */
869 *val_chain = new_mark;
870 value_release_to_mark (mark);
874 /* Assuming that B is a hardware watchpoint:
875 - Reparse watchpoint expression, is REPARSE is non-zero
876 - Evaluate expression and store the result in B->val
877 - Update the list of values that must be watched in B->loc.
879 If the watchpoint is disabled, do nothing. If this is
880 local watchpoint that is out of scope, delete it. */
882 update_watchpoint (struct breakpoint *b, int reparse)
884 int within_current_scope;
885 struct frame_id saved_frame_id;
886 struct bp_location *loc;
889 /* We don't free locations. They are stored in
890 bp_location_chain and update_global_locations will
891 eventually delete them and remove breakpoints if
895 if (b->disposition == disp_del_at_next_stop)
898 /* Save the current frame's ID so we can restore it after
899 evaluating the watchpoint expression on its own frame. */
900 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
901 took a frame parameter, so that we didn't have to change the
903 saved_frame_id = get_frame_id (get_selected_frame (NULL));
905 /* Determine if the watchpoint is within scope. */
906 if (b->exp_valid_block == NULL)
907 within_current_scope = 1;
910 struct frame_info *fi;
911 fi = frame_find_by_id (b->watchpoint_frame);
912 within_current_scope = (fi != NULL);
913 if (within_current_scope)
917 if (within_current_scope && reparse)
926 b->exp = parse_exp_1 (&s, b->exp_valid_block, 0);
927 /* If the meaning of expression itself changed, the old value is
928 no longer relevant. We don't want to report a watchpoint hit
929 to the user when the old value and the new value may actually
930 be completely different objects. */
936 /* If we failed to parse the expression, for example because
937 it refers to a global variable in a not-yet-loaded shared library,
938 don't try to insert watchpoint. We don't automatically delete
939 such watchpoint, though, since failure to parse expression
940 is different from out-of-scope watchpoint. */
941 if (within_current_scope && b->exp)
943 struct value *val_chain, *v, *result, *next;
945 fetch_watchpoint_value (b->exp, &v, &result, &val_chain);
947 /* Avoid setting b->val if it's already set. The meaning of
948 b->val is 'the last value' user saw, and we should update
949 it only if we reported that last value to user. As it
950 happens, the code that reports it updates b->val directly. */
957 /* Look at each value on the value chain. */
958 for (v = val_chain; v; v = next)
960 /* If it's a memory location, and GDB actually needed
961 its contents to evaluate the expression, then we
962 must watch it. If the first value returned is
963 still lazy, that means an error occurred reading it;
964 watch it anyway in case it becomes readable. */
965 if (VALUE_LVAL (v) == lval_memory
966 && (v == val_chain || ! value_lazy (v)))
968 struct type *vtype = check_typedef (value_type (v));
970 /* We only watch structs and arrays if user asked
971 for it explicitly, never if they just happen to
972 appear in the middle of some value chain. */
974 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
975 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
979 struct bp_location *loc, **tmp;
981 addr = VALUE_ADDRESS (v) + value_offset (v);
982 len = TYPE_LENGTH (value_type (v));
984 if (b->type == bp_read_watchpoint)
986 else if (b->type == bp_access_watchpoint)
989 loc = allocate_bp_location (b, bp_hardware_watchpoint);
990 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
995 loc->watchpoint_type = type;
999 next = value_next (v);
1004 /* We just regenerated the list of breakpoint locations.
1005 The new location does not have its condition field set to anything
1006 and therefore, we must always reparse the cond_string, independently
1007 of the value of the reparse flag. */
1008 if (b->cond_string != NULL)
1010 char *s = b->cond_string;
1011 b->loc->cond = parse_exp_1 (&s, b->exp_valid_block, 0);
1014 else if (!within_current_scope)
1016 printf_filtered (_("\
1017 Hardware watchpoint %d deleted because the program has left the block \n\
1018 in which its expression is valid.\n"),
1020 if (b->related_breakpoint)
1021 b->related_breakpoint->disposition = disp_del_at_next_stop;
1022 b->disposition = disp_del_at_next_stop;
1025 /* Restore the selected frame. */
1026 select_frame (frame_find_by_id (saved_frame_id));
1030 /* Returns 1 iff breakpoint location should be
1031 inserted in the inferior. */
1033 should_be_inserted (struct bp_location *bpt)
1035 if (!breakpoint_enabled (bpt->owner))
1038 if (bpt->owner->disposition == disp_del_at_next_stop)
1041 if (!bpt->enabled || bpt->shlib_disabled || bpt->duplicate)
1047 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
1048 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
1049 PROCESS_WARNING, and HW_BREAKPOINT_ERROR are used to report problems.
1051 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1052 method for each breakpoint or catchpoint type. */
1054 insert_bp_location (struct bp_location *bpt,
1055 struct ui_file *tmp_error_stream,
1056 int *disabled_breaks, int *process_warning,
1057 int *hw_breakpoint_error)
1061 if (!should_be_inserted (bpt) || bpt->inserted)
1064 /* Initialize the target-specific information. */
1065 memset (&bpt->target_info, 0, sizeof (bpt->target_info));
1066 bpt->target_info.placed_address = bpt->address;
1068 if (bpt->loc_type == bp_loc_software_breakpoint
1069 || bpt->loc_type == bp_loc_hardware_breakpoint)
1071 if (bpt->owner->type != bp_hardware_breakpoint)
1073 /* If the explicitly specified breakpoint type
1074 is not hardware breakpoint, check the memory map to see
1075 if the breakpoint address is in read only memory or not.
1076 Two important cases are:
1077 - location type is not hardware breakpoint, memory
1078 is readonly. We change the type of the location to
1079 hardware breakpoint.
1080 - location type is hardware breakpoint, memory is read-write.
1081 This means we've previously made the location hardware one, but
1082 then the memory map changed, so we undo.
1084 When breakpoints are removed, remove_breakpoints will
1085 use location types we've just set here, the only possible
1086 problem is that memory map has changed during running program,
1087 but it's not going to work anyway with current gdb. */
1088 struct mem_region *mr
1089 = lookup_mem_region (bpt->target_info.placed_address);
1093 if (automatic_hardware_breakpoints)
1096 enum bp_loc_type new_type;
1098 if (mr->attrib.mode != MEM_RW)
1099 new_type = bp_loc_hardware_breakpoint;
1101 new_type = bp_loc_software_breakpoint;
1103 if (new_type != bpt->loc_type)
1105 static int said = 0;
1106 bpt->loc_type = new_type;
1109 fprintf_filtered (gdb_stdout, _("\
1110 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1115 else if (bpt->loc_type == bp_loc_software_breakpoint
1116 && mr->attrib.mode != MEM_RW)
1117 warning (_("cannot set software breakpoint at readonly address %s"),
1118 paddr (bpt->address));
1122 /* First check to see if we have to handle an overlay. */
1123 if (overlay_debugging == ovly_off
1124 || bpt->section == NULL
1125 || !(section_is_overlay (bpt->section)))
1127 /* No overlay handling: just set the breakpoint. */
1129 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1130 val = target_insert_hw_breakpoint (&bpt->target_info);
1132 val = target_insert_breakpoint (&bpt->target_info);
1136 /* This breakpoint is in an overlay section.
1137 Shall we set a breakpoint at the LMA? */
1138 if (!overlay_events_enabled)
1140 /* Yes -- overlay event support is not active,
1141 so we must try to set a breakpoint at the LMA.
1142 This will not work for a hardware breakpoint. */
1143 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1144 warning (_("hardware breakpoint %d not supported in overlay!"),
1145 bpt->owner->number);
1148 CORE_ADDR addr = overlay_unmapped_address (bpt->address,
1150 /* Set a software (trap) breakpoint at the LMA. */
1151 bpt->overlay_target_info = bpt->target_info;
1152 bpt->overlay_target_info.placed_address = addr;
1153 val = target_insert_breakpoint (&bpt->overlay_target_info);
1155 fprintf_unfiltered (tmp_error_stream,
1156 "Overlay breakpoint %d failed: in ROM?",
1157 bpt->owner->number);
1160 /* Shall we set a breakpoint at the VMA? */
1161 if (section_is_mapped (bpt->section))
1163 /* Yes. This overlay section is mapped into memory. */
1164 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1165 val = target_insert_hw_breakpoint (&bpt->target_info);
1167 val = target_insert_breakpoint (&bpt->target_info);
1171 /* No. This breakpoint will not be inserted.
1172 No error, but do not mark the bp as 'inserted'. */
1179 /* Can't set the breakpoint. */
1180 if (solib_address (bpt->address))
1182 /* See also: disable_breakpoints_in_shlibs. */
1184 bpt->shlib_disabled = 1;
1185 if (!*disabled_breaks)
1187 fprintf_unfiltered (tmp_error_stream,
1188 "Cannot insert breakpoint %d.\n",
1189 bpt->owner->number);
1190 fprintf_unfiltered (tmp_error_stream,
1191 "Temporarily disabling shared library breakpoints:\n");
1193 *disabled_breaks = 1;
1194 fprintf_unfiltered (tmp_error_stream,
1195 "breakpoint #%d\n", bpt->owner->number);
1199 #ifdef ONE_PROCESS_WRITETEXT
1200 *process_warning = 1;
1202 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1204 *hw_breakpoint_error = 1;
1205 fprintf_unfiltered (tmp_error_stream,
1206 "Cannot insert hardware breakpoint %d.\n",
1207 bpt->owner->number);
1211 fprintf_unfiltered (tmp_error_stream,
1212 "Cannot insert breakpoint %d.\n",
1213 bpt->owner->number);
1214 fprintf_filtered (tmp_error_stream,
1215 "Error accessing memory address ");
1216 fputs_filtered (paddress (bpt->address), tmp_error_stream);
1217 fprintf_filtered (tmp_error_stream, ": %s.\n",
1218 safe_strerror (val));
1229 else if (bpt->loc_type == bp_loc_hardware_watchpoint
1230 /* NOTE drow/2003-09-08: This state only exists for removing
1231 watchpoints. It's not clear that it's necessary... */
1232 && bpt->owner->disposition != disp_del_at_next_stop)
1234 val = target_insert_watchpoint (bpt->address,
1236 bpt->watchpoint_type);
1237 bpt->inserted = (val != -1);
1240 else if (bpt->owner->type == bp_catchpoint
1241 || bpt->owner->type == bp_catch_exec)
1243 struct gdb_exception e = catch_exception (uiout, insert_catchpoint,
1244 bpt->owner, RETURN_MASK_ERROR);
1245 exception_fprintf (gdb_stderr, e, "warning: inserting catchpoint %d: ",
1246 bpt->owner->number);
1248 bpt->owner->enable_state = bp_disabled;
1252 /* We've already printed an error message if there was a problem
1253 inserting this catchpoint, and we've disabled the catchpoint,
1254 so just return success. */
1261 /* Make sure all breakpoints are inserted in inferior.
1262 Throws exception on any error.
1263 A breakpoint that is already inserted won't be inserted
1264 again, so calling this function twice is safe. */
1266 insert_breakpoints (void)
1268 struct breakpoint *bpt;
1270 ALL_BREAKPOINTS (bpt)
1271 if (is_hardware_watchpoint (bpt))
1272 update_watchpoint (bpt, 0 /* don't reparse. */);
1274 update_global_location_list (1);
1276 if (!breakpoints_always_inserted_mode () && target_has_execution)
1277 /* update_global_location_list does not insert breakpoints
1278 when always_inserted_mode is not enabled. Explicitly
1280 insert_breakpoint_locations ();
1283 /* insert_breakpoints is used when starting or continuing the program.
1284 remove_breakpoints is used when the program stops.
1285 Both return zero if successful,
1286 or an `errno' value if could not write the inferior. */
1289 insert_breakpoint_locations (void)
1291 struct breakpoint *bpt;
1292 struct bp_location *b, *temp;
1295 int disabled_breaks = 0;
1296 int hw_breakpoint_error = 0;
1297 int process_warning = 0;
1299 struct ui_file *tmp_error_stream = mem_fileopen ();
1300 make_cleanup_ui_file_delete (tmp_error_stream);
1302 /* Explicitly mark the warning -- this will only be printed if
1303 there was an error. */
1304 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
1306 ALL_BP_LOCATIONS_SAFE (b, temp)
1308 if (!should_be_inserted (b) || b->inserted)
1311 /* There is no point inserting thread-specific breakpoints if the
1312 thread no longer exists. */
1313 if (b->owner->thread != -1
1314 && !valid_thread_id (b->owner->thread))
1317 val = insert_bp_location (b, tmp_error_stream,
1318 &disabled_breaks, &process_warning,
1319 &hw_breakpoint_error);
1324 /* If we failed to insert all locations of a watchpoint,
1325 remove them, as half-inserted watchpoint is of limited use. */
1326 ALL_BREAKPOINTS (bpt)
1328 int some_failed = 0;
1329 struct bp_location *loc;
1331 if (!is_hardware_watchpoint (bpt))
1334 if (!breakpoint_enabled (bpt))
1337 if (bpt->disposition == disp_del_at_next_stop)
1340 for (loc = bpt->loc; loc; loc = loc->next)
1348 for (loc = bpt->loc; loc; loc = loc->next)
1350 remove_breakpoint (loc, mark_uninserted);
1352 hw_breakpoint_error = 1;
1353 fprintf_unfiltered (tmp_error_stream,
1354 "Could not insert hardware watchpoint %d.\n",
1362 /* If a hardware breakpoint or watchpoint was inserted, add a
1363 message about possibly exhausted resources. */
1364 if (hw_breakpoint_error)
1366 fprintf_unfiltered (tmp_error_stream,
1367 "Could not insert hardware breakpoints:\n\
1368 You may have requested too many hardware breakpoints/watchpoints.\n");
1370 #ifdef ONE_PROCESS_WRITETEXT
1371 if (process_warning)
1372 fprintf_unfiltered (tmp_error_stream,
1373 "The same program may be running in another process.");
1375 target_terminal_ours_for_output ();
1376 error_stream (tmp_error_stream);
1381 remove_breakpoints (void)
1383 struct bp_location *b;
1386 ALL_BP_LOCATIONS (b)
1390 val = remove_breakpoint (b, mark_uninserted);
1399 remove_hw_watchpoints (void)
1401 struct bp_location *b;
1404 ALL_BP_LOCATIONS (b)
1406 if (b->inserted && b->loc_type == bp_loc_hardware_watchpoint)
1408 val = remove_breakpoint (b, mark_uninserted);
1417 reattach_breakpoints (int pid)
1419 struct bp_location *b;
1421 struct cleanup *old_chain = save_inferior_ptid ();
1422 struct ui_file *tmp_error_stream = mem_fileopen ();
1423 int dummy1 = 0, dummy2 = 0, dummy3 = 0;
1425 make_cleanup_ui_file_delete (tmp_error_stream);
1427 inferior_ptid = pid_to_ptid (pid);
1428 ALL_BP_LOCATIONS (b)
1433 val = insert_bp_location (b, tmp_error_stream,
1434 &dummy1, &dummy2, &dummy3);
1437 do_cleanups (old_chain);
1442 do_cleanups (old_chain);
1447 update_breakpoints_after_exec (void)
1449 struct breakpoint *b;
1450 struct breakpoint *temp;
1451 struct bp_location *bploc;
1453 /* We're about to delete breakpoints from GDB's lists. If the
1454 INSERTED flag is true, GDB will try to lift the breakpoints by
1455 writing the breakpoints' "shadow contents" back into memory. The
1456 "shadow contents" are NOT valid after an exec, so GDB should not
1457 do that. Instead, the target is responsible from marking
1458 breakpoints out as soon as it detects an exec. We don't do that
1459 here instead, because there may be other attempts to delete
1460 breakpoints after detecting an exec and before reaching here. */
1461 ALL_BP_LOCATIONS (bploc)
1462 gdb_assert (!bploc->inserted);
1464 ALL_BREAKPOINTS_SAFE (b, temp)
1466 /* Solib breakpoints must be explicitly reset after an exec(). */
1467 if (b->type == bp_shlib_event)
1469 delete_breakpoint (b);
1473 /* Thread event breakpoints must be set anew after an exec(),
1474 as must overlay event breakpoints. */
1475 if (b->type == bp_thread_event || b->type == bp_overlay_event)
1477 delete_breakpoint (b);
1481 /* Step-resume breakpoints are meaningless after an exec(). */
1482 if (b->type == bp_step_resume)
1484 delete_breakpoint (b);
1488 /* Longjmp and longjmp-resume breakpoints are also meaningless
1490 if (b->type == bp_longjmp || b->type == bp_longjmp_resume)
1492 delete_breakpoint (b);
1496 if (b->type == bp_catchpoint)
1498 /* For now, none of the bp_catchpoint breakpoints need to
1499 do anything at this point. In the future, if some of
1500 the catchpoints need to something, we will need to add
1501 a new method, and call this method from here. */
1505 /* Don't delete an exec catchpoint, because else the inferior
1506 won't stop when it ought! */
1507 if (b->type == bp_catch_exec)
1512 /* bp_finish is a special case. The only way we ought to be able
1513 to see one of these when an exec() has happened, is if the user
1514 caught a vfork, and then said "finish". Ordinarily a finish just
1515 carries them to the call-site of the current callee, by setting
1516 a temporary bp there and resuming. But in this case, the finish
1517 will carry them entirely through the vfork & exec.
1519 We don't want to allow a bp_finish to remain inserted now. But
1520 we can't safely delete it, 'cause finish_command has a handle to
1521 the bp on a bpstat, and will later want to delete it. There's a
1522 chance (and I've seen it happen) that if we delete the bp_finish
1523 here, that its storage will get reused by the time finish_command
1524 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1525 We really must allow finish_command to delete a bp_finish.
1527 In the absense of a general solution for the "how do we know
1528 it's safe to delete something others may have handles to?"
1529 problem, what we'll do here is just uninsert the bp_finish, and
1530 let finish_command delete it.
1532 (We know the bp_finish is "doomed" in the sense that it's
1533 momentary, and will be deleted as soon as finish_command sees
1534 the inferior stopped. So it doesn't matter that the bp's
1535 address is probably bogus in the new a.out, unlike e.g., the
1536 solib breakpoints.) */
1538 if (b->type == bp_finish)
1543 /* Without a symbolic address, we have little hope of the
1544 pre-exec() address meaning the same thing in the post-exec()
1546 if (b->addr_string == NULL)
1548 delete_breakpoint (b);
1552 /* FIXME what about longjmp breakpoints? Re-create them here? */
1553 create_overlay_event_breakpoint ("_ovly_debug_event");
1557 detach_breakpoints (int pid)
1559 struct bp_location *b;
1561 struct cleanup *old_chain = save_inferior_ptid ();
1563 if (pid == PIDGET (inferior_ptid))
1564 error (_("Cannot detach breakpoints of inferior_ptid"));
1566 /* Set inferior_ptid; remove_breakpoint uses this global. */
1567 inferior_ptid = pid_to_ptid (pid);
1568 ALL_BP_LOCATIONS (b)
1572 val = remove_breakpoint (b, mark_inserted);
1575 do_cleanups (old_chain);
1580 do_cleanups (old_chain);
1585 remove_breakpoint (struct bp_location *b, insertion_state_t is)
1589 if (b->owner->enable_state == bp_permanent)
1590 /* Permanent breakpoints cannot be inserted or removed. */
1593 /* The type of none suggests that owner is actually deleted.
1594 This should not ever happen. */
1595 gdb_assert (b->owner->type != bp_none);
1597 if (b->loc_type == bp_loc_software_breakpoint
1598 || b->loc_type == bp_loc_hardware_breakpoint)
1600 /* "Normal" instruction breakpoint: either the standard
1601 trap-instruction bp (bp_breakpoint), or a
1602 bp_hardware_breakpoint. */
1604 /* First check to see if we have to handle an overlay. */
1605 if (overlay_debugging == ovly_off
1606 || b->section == NULL
1607 || !(section_is_overlay (b->section)))
1609 /* No overlay handling: just remove the breakpoint. */
1611 if (b->loc_type == bp_loc_hardware_breakpoint)
1612 val = target_remove_hw_breakpoint (&b->target_info);
1614 val = target_remove_breakpoint (&b->target_info);
1618 /* This breakpoint is in an overlay section.
1619 Did we set a breakpoint at the LMA? */
1620 if (!overlay_events_enabled)
1622 /* Yes -- overlay event support is not active, so we
1623 should have set a breakpoint at the LMA. Remove it.
1625 /* Ignore any failures: if the LMA is in ROM, we will
1626 have already warned when we failed to insert it. */
1627 if (b->loc_type == bp_loc_hardware_breakpoint)
1628 target_remove_hw_breakpoint (&b->overlay_target_info);
1630 target_remove_breakpoint (&b->overlay_target_info);
1632 /* Did we set a breakpoint at the VMA?
1633 If so, we will have marked the breakpoint 'inserted'. */
1636 /* Yes -- remove it. Previously we did not bother to
1637 remove the breakpoint if the section had been
1638 unmapped, but let's not rely on that being safe. We
1639 don't know what the overlay manager might do. */
1640 if (b->loc_type == bp_loc_hardware_breakpoint)
1641 val = target_remove_hw_breakpoint (&b->target_info);
1643 /* However, we should remove *software* breakpoints only
1644 if the section is still mapped, or else we overwrite
1645 wrong code with the saved shadow contents. */
1646 else if (section_is_mapped (b->section))
1647 val = target_remove_breakpoint (&b->target_info);
1653 /* No -- not inserted, so no need to remove. No error. */
1658 /* In some cases, we might not be able to remove a breakpoint
1659 in a shared library that has already been removed, but we
1660 have not yet processed the shlib unload event. */
1661 if (val && solib_address (b->address))
1666 b->inserted = (is == mark_inserted);
1668 else if (b->loc_type == bp_loc_hardware_watchpoint)
1673 b->inserted = (is == mark_inserted);
1674 val = target_remove_watchpoint (b->address, b->length,
1675 b->watchpoint_type);
1677 /* Failure to remove any of the hardware watchpoints comes here. */
1678 if ((is == mark_uninserted) && (b->inserted))
1679 warning (_("Could not remove hardware watchpoint %d."),
1682 else if (b->owner->type == bp_catchpoint
1683 && breakpoint_enabled (b->owner)
1686 gdb_assert (b->owner->ops != NULL && b->owner->ops->remove != NULL);
1688 val = b->owner->ops->remove (b->owner);
1691 b->inserted = (is == mark_inserted);
1693 else if (b->owner->type == bp_catch_exec
1694 && breakpoint_enabled (b->owner)
1698 switch (b->owner->type)
1701 val = target_remove_exec_catchpoint (PIDGET (inferior_ptid));
1704 warning (_("Internal error, %s line %d."), __FILE__, __LINE__);
1709 b->inserted = (is == mark_inserted);
1715 /* Clear the "inserted" flag in all breakpoints. */
1718 mark_breakpoints_out (void)
1720 struct bp_location *bpt;
1722 ALL_BP_LOCATIONS (bpt)
1726 /* Clear the "inserted" flag in all breakpoints and delete any
1727 breakpoints which should go away between runs of the program.
1729 Plus other such housekeeping that has to be done for breakpoints
1732 Note: this function gets called at the end of a run (by
1733 generic_mourn_inferior) and when a run begins (by
1734 init_wait_for_inferior). */
1739 breakpoint_init_inferior (enum inf_context context)
1741 struct breakpoint *b, *temp;
1742 struct bp_location *bpt;
1745 ALL_BP_LOCATIONS (bpt)
1746 if (bpt->owner->enable_state != bp_permanent)
1749 ALL_BREAKPOINTS_SAFE (b, temp)
1754 case bp_watchpoint_scope:
1756 /* If the call dummy breakpoint is at the entry point it will
1757 cause problems when the inferior is rerun, so we better
1760 Also get rid of scope breakpoints. */
1761 delete_breakpoint (b);
1765 case bp_hardware_watchpoint:
1766 case bp_read_watchpoint:
1767 case bp_access_watchpoint:
1769 /* Likewise for watchpoints on local expressions. */
1770 if (b->exp_valid_block != NULL)
1771 delete_breakpoint (b);
1772 else if (context == inf_starting)
1774 /* Reset val field to force reread of starting value
1775 in insert_breakpoints. */
1777 value_free (b->val);
1787 /* Get rid of the moribund locations. */
1788 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bpt); ++ix)
1789 free_bp_location (bpt);
1790 VEC_free (bp_location_p, moribund_locations);
1793 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1794 exists at PC. It returns ordinary_breakpoint_here if it's an
1795 ordinary breakpoint, or permanent_breakpoint_here if it's a
1796 permanent breakpoint.
1797 - When continuing from a location with an ordinary breakpoint, we
1798 actually single step once before calling insert_breakpoints.
1799 - When continuing from a localion with a permanent breakpoint, we
1800 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1801 the target, to advance the PC past the breakpoint. */
1803 enum breakpoint_here
1804 breakpoint_here_p (CORE_ADDR pc)
1806 const struct bp_location *bpt;
1807 int any_breakpoint_here = 0;
1809 ALL_BP_LOCATIONS (bpt)
1811 if (bpt->loc_type != bp_loc_software_breakpoint
1812 && bpt->loc_type != bp_loc_hardware_breakpoint)
1815 if ((breakpoint_enabled (bpt->owner)
1816 || bpt->owner->enable_state == bp_permanent)
1817 && bpt->address == pc) /* bp is enabled and matches pc */
1819 if (overlay_debugging
1820 && section_is_overlay (bpt->section)
1821 && !section_is_mapped (bpt->section))
1822 continue; /* unmapped overlay -- can't be a match */
1823 else if (bpt->owner->enable_state == bp_permanent)
1824 return permanent_breakpoint_here;
1826 any_breakpoint_here = 1;
1830 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
1833 /* Return true if there's a moribund breakpoint at PC. */
1836 moribund_breakpoint_here_p (CORE_ADDR pc)
1838 struct bp_location *loc;
1841 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
1842 if (loc->address == pc)
1848 /* Returns non-zero if there's a breakpoint inserted at PC, which is
1849 inserted using regular breakpoint_chain/bp_location_chain mechanism.
1850 This does not check for single-step breakpoints, which are
1851 inserted and removed using direct target manipulation. */
1854 regular_breakpoint_inserted_here_p (CORE_ADDR pc)
1856 const struct bp_location *bpt;
1858 ALL_BP_LOCATIONS (bpt)
1860 if (bpt->loc_type != bp_loc_software_breakpoint
1861 && bpt->loc_type != bp_loc_hardware_breakpoint)
1865 && bpt->address == pc) /* bp is inserted and matches pc */
1867 if (overlay_debugging
1868 && section_is_overlay (bpt->section)
1869 && !section_is_mapped (bpt->section))
1870 continue; /* unmapped overlay -- can't be a match */
1878 /* Returns non-zero iff there's either regular breakpoint
1879 or a single step breakpoint inserted at PC. */
1882 breakpoint_inserted_here_p (CORE_ADDR pc)
1884 if (regular_breakpoint_inserted_here_p (pc))
1887 if (single_step_breakpoint_inserted_here_p (pc))
1893 /* This function returns non-zero iff there is a software breakpoint
1897 software_breakpoint_inserted_here_p (CORE_ADDR pc)
1899 const struct bp_location *bpt;
1900 int any_breakpoint_here = 0;
1902 ALL_BP_LOCATIONS (bpt)
1904 if (bpt->loc_type != bp_loc_software_breakpoint)
1908 && bpt->address == pc) /* bp is enabled and matches pc */
1910 if (overlay_debugging
1911 && section_is_overlay (bpt->section)
1912 && !section_is_mapped (bpt->section))
1913 continue; /* unmapped overlay -- can't be a match */
1919 /* Also check for software single-step breakpoints. */
1920 if (single_step_breakpoint_inserted_here_p (pc))
1926 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
1927 PC is valid for process/thread PTID. */
1930 breakpoint_thread_match (CORE_ADDR pc, ptid_t ptid)
1932 const struct bp_location *bpt;
1935 thread = pid_to_thread_id (ptid);
1937 ALL_BP_LOCATIONS (bpt)
1939 if (bpt->loc_type != bp_loc_software_breakpoint
1940 && bpt->loc_type != bp_loc_hardware_breakpoint)
1943 if ((breakpoint_enabled (bpt->owner)
1944 || bpt->owner->enable_state == bp_permanent)
1945 && bpt->address == pc
1946 && (bpt->owner->thread == -1 || bpt->owner->thread == thread))
1948 if (overlay_debugging
1949 && section_is_overlay (bpt->section)
1950 && !section_is_mapped (bpt->section))
1951 continue; /* unmapped overlay -- can't be a match */
1961 /* bpstat stuff. External routines' interfaces are documented
1965 ep_is_catchpoint (struct breakpoint *ep)
1967 return (ep->type == bp_catchpoint)
1968 || (ep->type == bp_catch_load)
1969 || (ep->type == bp_catch_unload)
1970 || (ep->type == bp_catch_exec);
1972 /* ??rehrauer: Add more kinds here, as are implemented... */
1976 ep_is_shlib_catchpoint (struct breakpoint *ep)
1979 (ep->type == bp_catch_load)
1980 || (ep->type == bp_catch_unload);
1984 bpstat_free (bpstat bs)
1986 if (bs->old_val != NULL)
1987 value_free (bs->old_val);
1988 free_command_lines (&bs->commands);
1992 /* Clear a bpstat so that it says we are not at any breakpoint.
1993 Also free any storage that is part of a bpstat. */
1996 bpstat_clear (bpstat *bsp)
2013 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
2014 is part of the bpstat is copied as well. */
2017 bpstat_copy (bpstat bs)
2021 bpstat retval = NULL;
2026 for (; bs != NULL; bs = bs->next)
2028 tmp = (bpstat) xmalloc (sizeof (*tmp));
2029 memcpy (tmp, bs, sizeof (*tmp));
2030 if (bs->commands != NULL)
2031 tmp->commands = copy_command_lines (bs->commands);
2032 if (bs->old_val != NULL)
2034 tmp->old_val = value_copy (bs->old_val);
2035 release_value (tmp->old_val);
2039 /* This is the first thing in the chain. */
2049 /* Find the bpstat associated with this breakpoint */
2052 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
2057 for (; bsp != NULL; bsp = bsp->next)
2059 if (bsp->breakpoint_at && bsp->breakpoint_at->owner == breakpoint)
2065 /* Find a step_resume breakpoint associated with this bpstat.
2066 (If there are multiple step_resume bp's on the list, this function
2067 will arbitrarily pick one.)
2069 It is an error to use this function if BPSTAT doesn't contain a
2070 step_resume breakpoint.
2072 See wait_for_inferior's use of this function. */
2074 bpstat_find_step_resume_breakpoint (bpstat bsp)
2078 gdb_assert (bsp != NULL);
2080 current_thread = pid_to_thread_id (inferior_ptid);
2082 for (; bsp != NULL; bsp = bsp->next)
2084 if ((bsp->breakpoint_at != NULL) &&
2085 (bsp->breakpoint_at->owner->type == bp_step_resume) &&
2086 (bsp->breakpoint_at->owner->thread == current_thread ||
2087 bsp->breakpoint_at->owner->thread == -1))
2088 return bsp->breakpoint_at->owner;
2091 internal_error (__FILE__, __LINE__, _("No step_resume breakpoint found."));
2095 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2096 at. *BSP upon return is a bpstat which points to the remaining
2097 breakpoints stopped at (but which is not guaranteed to be good for
2098 anything but further calls to bpstat_num).
2099 Return 0 if passed a bpstat which does not indicate any breakpoints.
2100 Return -1 if stopped at a breakpoint that has been deleted since
2102 Return 1 otherwise. */
2105 bpstat_num (bpstat *bsp, int *num)
2107 struct breakpoint *b;
2110 return 0; /* No more breakpoint values */
2112 /* We assume we'll never have several bpstats that
2113 correspond to a single breakpoint -- otherwise,
2114 this function might return the same number more
2115 than once and this will look ugly. */
2116 b = (*bsp)->breakpoint_at ? (*bsp)->breakpoint_at->owner : NULL;
2117 *bsp = (*bsp)->next;
2119 return -1; /* breakpoint that's been deleted since */
2121 *num = b->number; /* We have its number */
2125 /* Modify BS so that the actions will not be performed. */
2128 bpstat_clear_actions (bpstat bs)
2130 for (; bs != NULL; bs = bs->next)
2132 free_command_lines (&bs->commands);
2133 if (bs->old_val != NULL)
2135 value_free (bs->old_val);
2141 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2143 cleanup_executing_breakpoints (void *ignore)
2145 executing_breakpoint_commands = 0;
2148 /* Execute all the commands associated with all the breakpoints at this
2149 location. Any of these commands could cause the process to proceed
2150 beyond this point, etc. We look out for such changes by checking
2151 the global "breakpoint_proceeded" after each command.
2153 Returns true if a breakpoint command resumed the inferior. In that
2154 case, it is the caller's responsibility to recall it again with the
2155 bpstat of the current thread. */
2158 bpstat_do_actions_1 (bpstat *bsp)
2161 struct cleanup *old_chain;
2164 /* Avoid endless recursion if a `source' command is contained
2166 if (executing_breakpoint_commands)
2169 executing_breakpoint_commands = 1;
2170 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
2172 /* This pointer will iterate over the list of bpstat's. */
2175 breakpoint_proceeded = 0;
2176 for (; bs != NULL; bs = bs->next)
2178 struct command_line *cmd;
2179 struct cleanup *this_cmd_tree_chain;
2181 /* Take ownership of the BSP's command tree, if it has one.
2183 The command tree could legitimately contain commands like
2184 'step' and 'next', which call clear_proceed_status, which
2185 frees stop_bpstat's command tree. To make sure this doesn't
2186 free the tree we're executing out from under us, we need to
2187 take ownership of the tree ourselves. Since a given bpstat's
2188 commands are only executed once, we don't need to copy it; we
2189 can clear the pointer in the bpstat, and make sure we free
2190 the tree when we're done. */
2193 this_cmd_tree_chain = make_cleanup_free_command_lines (&cmd);
2197 execute_control_command (cmd);
2199 if (breakpoint_proceeded)
2205 /* We can free this command tree now. */
2206 do_cleanups (this_cmd_tree_chain);
2208 if (breakpoint_proceeded)
2210 if (target_can_async_p ())
2211 /* If we are in async mode, then the target might be still
2212 running, not stopped at any breakpoint, so nothing for
2213 us to do here -- just return to the event loop. */
2216 /* In sync mode, when execute_control_command returns
2217 we're already standing on the next breakpoint.
2218 Breakpoint commands for that stop were not run, since
2219 execute_command does not run breakpoint commands --
2220 only command_line_handler does, but that one is not
2221 involved in execution of breakpoint commands. So, we
2222 can now execute breakpoint commands. It should be
2223 noted that making execute_command do bpstat actions is
2224 not an option -- in this case we'll have recursive
2225 invocation of bpstat for each breakpoint with a
2226 command, and can easily blow up GDB stack. Instead, we
2227 return true, which will trigger the caller to recall us
2228 with the new stop_bpstat. */
2233 do_cleanups (old_chain);
2238 bpstat_do_actions (void)
2240 /* Do any commands attached to breakpoint we are stopped at. */
2241 while (!ptid_equal (inferior_ptid, null_ptid)
2242 && target_has_execution
2243 && !is_exited (inferior_ptid)
2244 && !is_executing (inferior_ptid))
2245 /* Since in sync mode, bpstat_do_actions may resume the inferior,
2246 and only return when it is stopped at the next breakpoint, we
2247 keep doing breakpoint actions until it returns false to
2248 indicate the inferior was not resumed. */
2249 if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat))
2253 /* Print out the (old or new) value associated with a watchpoint. */
2256 watchpoint_value_print (struct value *val, struct ui_file *stream)
2259 fprintf_unfiltered (stream, _("<unreadable>"));
2262 struct value_print_options opts;
2263 get_user_print_options (&opts);
2264 value_print (val, stream, &opts);
2268 /* This is the normal print function for a bpstat. In the future,
2269 much of this logic could (should?) be moved to bpstat_stop_status,
2270 by having it set different print_it values.
2272 Current scheme: When we stop, bpstat_print() is called. It loops
2273 through the bpstat list of things causing this stop, calling the
2274 print_bp_stop_message function on each one. The behavior of the
2275 print_bp_stop_message function depends on the print_it field of
2276 bpstat. If such field so indicates, call this function here.
2278 Return values from this routine (ultimately used by bpstat_print()
2279 and normal_stop() to decide what to do):
2280 PRINT_NOTHING: Means we already printed all we needed to print,
2281 don't print anything else.
2282 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2283 that something to be followed by a location.
2284 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2285 that something to be followed by a location.
2286 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2289 static enum print_stop_action
2290 print_it_typical (bpstat bs)
2292 struct cleanup *old_chain, *ui_out_chain;
2293 struct breakpoint *b;
2294 const struct bp_location *bl;
2295 struct ui_stream *stb;
2297 stb = ui_out_stream_new (uiout);
2298 old_chain = make_cleanup_ui_out_stream_delete (stb);
2299 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2300 which has since been deleted. */
2301 if (bs->breakpoint_at == NULL)
2302 return PRINT_UNKNOWN;
2303 bl = bs->breakpoint_at;
2309 case bp_hardware_breakpoint:
2310 bp_temp = bs->breakpoint_at->owner->disposition == disp_del;
2311 if (bl->address != bl->requested_address)
2312 breakpoint_adjustment_warning (bl->requested_address,
2315 annotate_breakpoint (b->number);
2317 ui_out_text (uiout, "\nTemporary breakpoint ");
2319 ui_out_text (uiout, "\nBreakpoint ");
2320 if (ui_out_is_mi_like_p (uiout))
2322 ui_out_field_string (uiout, "reason",
2323 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
2324 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
2326 ui_out_field_int (uiout, "bkptno", b->number);
2327 ui_out_text (uiout, ", ");
2328 return PRINT_SRC_AND_LOC;
2331 case bp_shlib_event:
2332 /* Did we stop because the user set the stop_on_solib_events
2333 variable? (If so, we report this as a generic, "Stopped due
2334 to shlib event" message.) */
2335 printf_filtered (_("Stopped due to shared library event\n"));
2336 return PRINT_NOTHING;
2339 case bp_thread_event:
2340 /* Not sure how we will get here.
2341 GDB should not stop for these breakpoints. */
2342 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2343 return PRINT_NOTHING;
2346 case bp_overlay_event:
2347 /* By analogy with the thread event, GDB should not stop for these. */
2348 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2349 return PRINT_NOTHING;
2353 annotate_catchpoint (b->number);
2354 printf_filtered (_("\nCatchpoint %d (loaded %s), "),
2356 b->triggered_dll_pathname);
2357 return PRINT_SRC_AND_LOC;
2360 case bp_catch_unload:
2361 annotate_catchpoint (b->number);
2362 printf_filtered (_("\nCatchpoint %d (unloaded %s), "),
2364 b->triggered_dll_pathname);
2365 return PRINT_SRC_AND_LOC;
2369 annotate_catchpoint (b->number);
2370 printf_filtered (_("\nCatchpoint %d (exec'd %s), "),
2373 return PRINT_SRC_AND_LOC;
2377 case bp_hardware_watchpoint:
2378 annotate_watchpoint (b->number);
2379 if (ui_out_is_mi_like_p (uiout))
2382 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
2384 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2385 ui_out_text (uiout, "\nOld value = ");
2386 watchpoint_value_print (bs->old_val, stb->stream);
2387 ui_out_field_stream (uiout, "old", stb);
2388 ui_out_text (uiout, "\nNew value = ");
2389 watchpoint_value_print (b->val, stb->stream);
2390 ui_out_field_stream (uiout, "new", stb);
2391 do_cleanups (ui_out_chain);
2392 ui_out_text (uiout, "\n");
2393 /* More than one watchpoint may have been triggered. */
2394 return PRINT_UNKNOWN;
2397 case bp_read_watchpoint:
2398 if (ui_out_is_mi_like_p (uiout))
2401 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
2403 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2404 ui_out_text (uiout, "\nValue = ");
2405 watchpoint_value_print (b->val, stb->stream);
2406 ui_out_field_stream (uiout, "value", stb);
2407 do_cleanups (ui_out_chain);
2408 ui_out_text (uiout, "\n");
2409 return PRINT_UNKNOWN;
2412 case bp_access_watchpoint:
2413 if (bs->old_val != NULL)
2415 annotate_watchpoint (b->number);
2416 if (ui_out_is_mi_like_p (uiout))
2419 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
2421 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2422 ui_out_text (uiout, "\nOld value = ");
2423 watchpoint_value_print (bs->old_val, stb->stream);
2424 ui_out_field_stream (uiout, "old", stb);
2425 ui_out_text (uiout, "\nNew value = ");
2430 if (ui_out_is_mi_like_p (uiout))
2433 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
2434 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2435 ui_out_text (uiout, "\nValue = ");
2437 watchpoint_value_print (b->val, stb->stream);
2438 ui_out_field_stream (uiout, "new", stb);
2439 do_cleanups (ui_out_chain);
2440 ui_out_text (uiout, "\n");
2441 return PRINT_UNKNOWN;
2444 /* Fall through, we don't deal with these types of breakpoints
2448 if (ui_out_is_mi_like_p (uiout))
2451 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED));
2452 return PRINT_UNKNOWN;
2456 if (ui_out_is_mi_like_p (uiout))
2459 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED));
2460 return PRINT_UNKNOWN;
2465 case bp_longjmp_resume:
2466 case bp_step_resume:
2467 case bp_watchpoint_scope:
2470 return PRINT_UNKNOWN;
2474 /* Generic routine for printing messages indicating why we
2475 stopped. The behavior of this function depends on the value
2476 'print_it' in the bpstat structure. Under some circumstances we
2477 may decide not to print anything here and delegate the task to
2480 static enum print_stop_action
2481 print_bp_stop_message (bpstat bs)
2483 switch (bs->print_it)
2486 /* Nothing should be printed for this bpstat entry. */
2487 return PRINT_UNKNOWN;
2491 /* We still want to print the frame, but we already printed the
2492 relevant messages. */
2493 return PRINT_SRC_AND_LOC;
2496 case print_it_normal:
2498 const struct bp_location *bl = bs->breakpoint_at;
2499 struct breakpoint *b = bl ? bl->owner : NULL;
2501 /* Normal case. Call the breakpoint's print_it method, or
2502 print_it_typical. */
2503 /* FIXME: how breakpoint can ever be NULL here? */
2504 if (b != NULL && b->ops != NULL && b->ops->print_it != NULL)
2505 return b->ops->print_it (b);
2507 return print_it_typical (bs);
2512 internal_error (__FILE__, __LINE__,
2513 _("print_bp_stop_message: unrecognized enum value"));
2518 /* Print a message indicating what happened. This is called from
2519 normal_stop(). The input to this routine is the head of the bpstat
2520 list - a list of the eventpoints that caused this stop. This
2521 routine calls the generic print routine for printing a message
2522 about reasons for stopping. This will print (for example) the
2523 "Breakpoint n," part of the output. The return value of this
2526 PRINT_UNKNOWN: Means we printed nothing
2527 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2528 code to print the location. An example is
2529 "Breakpoint 1, " which should be followed by
2531 PRINT_SRC_ONLY: Means we printed something, but there is no need
2532 to also print the location part of the message.
2533 An example is the catch/throw messages, which
2534 don't require a location appended to the end.
2535 PRINT_NOTHING: We have done some printing and we don't need any
2536 further info to be printed.*/
2538 enum print_stop_action
2539 bpstat_print (bpstat bs)
2543 /* Maybe another breakpoint in the chain caused us to stop.
2544 (Currently all watchpoints go on the bpstat whether hit or not.
2545 That probably could (should) be changed, provided care is taken
2546 with respect to bpstat_explains_signal). */
2547 for (; bs; bs = bs->next)
2549 val = print_bp_stop_message (bs);
2550 if (val == PRINT_SRC_ONLY
2551 || val == PRINT_SRC_AND_LOC
2552 || val == PRINT_NOTHING)
2556 /* We reached the end of the chain, or we got a null BS to start
2557 with and nothing was printed. */
2558 return PRINT_UNKNOWN;
2561 /* Evaluate the expression EXP and return 1 if value is zero.
2562 This is used inside a catch_errors to evaluate the breakpoint condition.
2563 The argument is a "struct expression *" that has been cast to char * to
2564 make it pass through catch_errors. */
2567 breakpoint_cond_eval (void *exp)
2569 struct value *mark = value_mark ();
2570 int i = !value_true (evaluate_expression ((struct expression *) exp));
2571 value_free_to_mark (mark);
2575 /* Allocate a new bpstat and chain it to the current one. */
2578 bpstat_alloc (const struct bp_location *bl, bpstat cbs /* Current "bs" value */ )
2582 bs = (bpstat) xmalloc (sizeof (*bs));
2584 bs->breakpoint_at = bl;
2585 /* If the condition is false, etc., don't do the commands. */
2586 bs->commands = NULL;
2588 bs->print_it = print_it_normal;
2592 /* The target has stopped with waitstatus WS. Check if any hardware
2593 watchpoints have triggered, according to the target. */
2596 watchpoints_triggered (struct target_waitstatus *ws)
2598 int stopped_by_watchpoint = STOPPED_BY_WATCHPOINT (*ws);
2600 struct breakpoint *b;
2602 if (!stopped_by_watchpoint)
2604 /* We were not stopped by a watchpoint. Mark all watchpoints
2605 as not triggered. */
2607 if (b->type == bp_hardware_watchpoint
2608 || b->type == bp_read_watchpoint
2609 || b->type == bp_access_watchpoint)
2610 b->watchpoint_triggered = watch_triggered_no;
2615 if (!target_stopped_data_address (¤t_target, &addr))
2617 /* We were stopped by a watchpoint, but we don't know where.
2618 Mark all watchpoints as unknown. */
2620 if (b->type == bp_hardware_watchpoint
2621 || b->type == bp_read_watchpoint
2622 || b->type == bp_access_watchpoint)
2623 b->watchpoint_triggered = watch_triggered_unknown;
2625 return stopped_by_watchpoint;
2628 /* The target could report the data address. Mark watchpoints
2629 affected by this data address as triggered, and all others as not
2633 if (b->type == bp_hardware_watchpoint
2634 || b->type == bp_read_watchpoint
2635 || b->type == bp_access_watchpoint)
2637 struct bp_location *loc;
2640 b->watchpoint_triggered = watch_triggered_no;
2641 for (loc = b->loc; loc; loc = loc->next)
2642 /* Exact match not required. Within range is
2644 if (target_watchpoint_addr_within_range (¤t_target,
2648 b->watchpoint_triggered = watch_triggered_yes;
2656 /* Possible return values for watchpoint_check (this can't be an enum
2657 because of check_errors). */
2658 /* The watchpoint has been deleted. */
2659 #define WP_DELETED 1
2660 /* The value has changed. */
2661 #define WP_VALUE_CHANGED 2
2662 /* The value has not changed. */
2663 #define WP_VALUE_NOT_CHANGED 3
2665 #define BP_TEMPFLAG 1
2666 #define BP_HARDWAREFLAG 2
2668 /* Check watchpoint condition. */
2671 watchpoint_check (void *p)
2673 bpstat bs = (bpstat) p;
2674 struct breakpoint *b;
2675 struct frame_info *fr;
2676 int within_current_scope;
2678 b = bs->breakpoint_at->owner;
2680 if (b->exp_valid_block == NULL)
2681 within_current_scope = 1;
2684 /* There is no current frame at this moment. If we're going to have
2685 any chance of handling watchpoints on local variables, we'll need
2686 the frame chain (so we can determine if we're in scope). */
2687 reinit_frame_cache ();
2688 fr = frame_find_by_id (b->watchpoint_frame);
2689 within_current_scope = (fr != NULL);
2691 /* If we've gotten confused in the unwinder, we might have
2692 returned a frame that can't describe this variable. */
2693 if (within_current_scope
2694 && (block_linkage_function (b->exp_valid_block)
2695 != get_frame_function (fr)))
2696 within_current_scope = 0;
2698 /* in_function_epilogue_p() returns a non-zero value if we're still
2699 in the function but the stack frame has already been invalidated.
2700 Since we can't rely on the values of local variables after the
2701 stack has been destroyed, we are treating the watchpoint in that
2702 state as `not changed' without further checking.
2704 vinschen/2003-09-04: The former implementation left out the case
2705 that the watchpoint frame couldn't be found by frame_find_by_id()
2706 because the current PC is currently in an epilogue. Calling
2707 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2708 if ((!within_current_scope || fr == get_current_frame ())
2709 && gdbarch_in_function_epilogue_p (current_gdbarch, read_pc ()))
2710 return WP_VALUE_NOT_CHANGED;
2711 if (fr && within_current_scope)
2712 /* If we end up stopping, the current frame will get selected
2713 in normal_stop. So this call to select_frame won't affect
2718 if (within_current_scope)
2720 /* We use value_{,free_to_}mark because it could be a
2721 *long* time before we return to the command level and
2722 call free_all_values. We can't call free_all_values because
2723 we might be in the middle of evaluating a function call. */
2725 struct value *mark = value_mark ();
2726 struct value *new_val;
2728 fetch_watchpoint_value (b->exp, &new_val, NULL, NULL);
2729 if ((b->val != NULL) != (new_val != NULL)
2730 || (b->val != NULL && !value_equal (b->val, new_val)))
2732 if (new_val != NULL)
2734 release_value (new_val);
2735 value_free_to_mark (mark);
2737 bs->old_val = b->val;
2740 /* We will stop here */
2741 return WP_VALUE_CHANGED;
2745 /* Nothing changed, don't do anything. */
2746 value_free_to_mark (mark);
2747 /* We won't stop here */
2748 return WP_VALUE_NOT_CHANGED;
2753 /* This seems like the only logical thing to do because
2754 if we temporarily ignored the watchpoint, then when
2755 we reenter the block in which it is valid it contains
2756 garbage (in the case of a function, it may have two
2757 garbage values, one before and one after the prologue).
2758 So we can't even detect the first assignment to it and
2759 watch after that (since the garbage may or may not equal
2760 the first value assigned). */
2761 /* We print all the stop information in print_it_typical(), but
2762 in this case, by the time we call print_it_typical() this bp
2763 will be deleted already. So we have no choice but print the
2764 information here. */
2765 if (ui_out_is_mi_like_p (uiout))
2767 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
2768 ui_out_text (uiout, "\nWatchpoint ");
2769 ui_out_field_int (uiout, "wpnum", b->number);
2770 ui_out_text (uiout, " deleted because the program has left the block in\n\
2771 which its expression is valid.\n");
2773 if (b->related_breakpoint)
2774 b->related_breakpoint->disposition = disp_del_at_next_stop;
2775 b->disposition = disp_del_at_next_stop;
2781 /* Return true if it looks like target has stopped due to hitting
2782 breakpoint location BL. This function does not check if we
2783 should stop, only if BL explains the stop. */
2785 bpstat_check_location (const struct bp_location *bl, CORE_ADDR bp_addr)
2787 struct breakpoint *b = bl->owner;
2789 if (b->type != bp_watchpoint
2790 && b->type != bp_hardware_watchpoint
2791 && b->type != bp_read_watchpoint
2792 && b->type != bp_access_watchpoint
2793 && b->type != bp_hardware_breakpoint
2794 && b->type != bp_catchpoint
2795 && b->type != bp_catch_exec) /* a non-watchpoint bp */
2797 if (bl->address != bp_addr) /* address doesn't match */
2799 if (overlay_debugging /* unmapped overlay section */
2800 && section_is_overlay (bl->section)
2801 && !section_is_mapped (bl->section))
2805 /* Continuable hardware watchpoints are treated as non-existent if the
2806 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2807 some data address). Otherwise gdb won't stop on a break instruction
2808 in the code (not from a breakpoint) when a hardware watchpoint has
2809 been defined. Also skip watchpoints which we know did not trigger
2810 (did not match the data address). */
2812 if ((b->type == bp_hardware_watchpoint
2813 || b->type == bp_read_watchpoint
2814 || b->type == bp_access_watchpoint)
2815 && b->watchpoint_triggered == watch_triggered_no)
2818 if (b->type == bp_hardware_breakpoint)
2820 if (bl->address != bp_addr)
2822 if (overlay_debugging /* unmapped overlay section */
2823 && section_is_overlay (bl->section)
2824 && !section_is_mapped (bl->section))
2828 /* Is this a catchpoint of a load or unload? If so, did we
2829 get a load or unload of the specified library? If not,
2831 if ((b->type == bp_catch_load)
2832 #if defined(SOLIB_HAVE_LOAD_EVENT)
2833 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid))
2834 || ((b->dll_pathname != NULL)
2835 && (strcmp (b->dll_pathname,
2836 SOLIB_LOADED_LIBRARY_PATHNAME (
2837 PIDGET (inferior_ptid)))
2843 if ((b->type == bp_catch_unload)
2844 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2845 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid))
2846 || ((b->dll_pathname != NULL)
2847 && (strcmp (b->dll_pathname,
2848 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2849 PIDGET (inferior_ptid)))
2855 if (b->type == bp_catchpoint)
2857 gdb_assert (b->ops != NULL && b->ops->breakpoint_hit != NULL);
2858 if (!b->ops->breakpoint_hit (b))
2862 if ((b->type == bp_catch_exec)
2863 && !inferior_has_execd (inferior_ptid, &b->exec_pathname))
2869 /* If BS refers to a watchpoint, determine if the watched values
2870 has actually changed, and we should stop. If not, set BS->stop
2873 bpstat_check_watchpoint (bpstat bs)
2875 const struct bp_location *bl = bs->breakpoint_at;
2876 struct breakpoint *b = bl->owner;
2878 if (b->type == bp_watchpoint
2879 || b->type == bp_read_watchpoint
2880 || b->type == bp_access_watchpoint
2881 || b->type == bp_hardware_watchpoint)
2885 int must_check_value = 0;
2887 if (b->type == bp_watchpoint)
2888 /* For a software watchpoint, we must always check the
2890 must_check_value = 1;
2891 else if (b->watchpoint_triggered == watch_triggered_yes)
2892 /* We have a hardware watchpoint (read, write, or access)
2893 and the target earlier reported an address watched by
2895 must_check_value = 1;
2896 else if (b->watchpoint_triggered == watch_triggered_unknown
2897 && b->type == bp_hardware_watchpoint)
2898 /* We were stopped by a hardware watchpoint, but the target could
2899 not report the data address. We must check the watchpoint's
2900 value. Access and read watchpoints are out of luck; without
2901 a data address, we can't figure it out. */
2902 must_check_value = 1;
2904 if (must_check_value)
2906 char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n",
2908 struct cleanup *cleanups = make_cleanup (xfree, message);
2909 int e = catch_errors (watchpoint_check, bs, message,
2911 do_cleanups (cleanups);
2915 /* We've already printed what needs to be printed. */
2916 bs->print_it = print_it_done;
2919 case WP_VALUE_CHANGED:
2920 if (b->type == bp_read_watchpoint)
2922 /* Don't stop: read watchpoints shouldn't fire if
2923 the value has changed. This is for targets
2924 which cannot set read-only watchpoints. */
2925 bs->print_it = print_it_noop;
2929 case WP_VALUE_NOT_CHANGED:
2930 if (b->type == bp_hardware_watchpoint
2931 || b->type == bp_watchpoint)
2933 /* Don't stop: write watchpoints shouldn't fire if
2934 the value hasn't changed. */
2935 bs->print_it = print_it_noop;
2943 /* Error from catch_errors. */
2944 printf_filtered (_("Watchpoint %d deleted.\n"), b->number);
2945 if (b->related_breakpoint)
2946 b->related_breakpoint->disposition = disp_del_at_next_stop;
2947 b->disposition = disp_del_at_next_stop;
2948 /* We've already printed what needs to be printed. */
2949 bs->print_it = print_it_done;
2953 else /* must_check_value == 0 */
2955 /* This is a case where some watchpoint(s) triggered, but
2956 not at the address of this watchpoint, or else no
2957 watchpoint triggered after all. So don't print
2958 anything for this watchpoint. */
2959 bs->print_it = print_it_noop;
2966 /* Check conditions (condition proper, frame, thread and ignore count)
2967 of breakpoint referred to by BS. If we should not stop for this
2968 breakpoint, set BS->stop to 0. */
2970 bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
2972 int thread_id = pid_to_thread_id (ptid);
2973 const struct bp_location *bl = bs->breakpoint_at;
2974 struct breakpoint *b = bl->owner;
2976 if (frame_id_p (b->frame_id)
2977 && !frame_id_eq (b->frame_id, get_frame_id (get_current_frame ())))
2981 int value_is_zero = 0;
2983 /* If this is a scope breakpoint, mark the associated
2984 watchpoint as triggered so that we will handle the
2985 out-of-scope event. We'll get to the watchpoint next
2987 if (b->type == bp_watchpoint_scope)
2988 b->related_breakpoint->watchpoint_triggered = watch_triggered_yes;
2990 if (bl->cond && bl->owner->disposition != disp_del_at_next_stop)
2992 /* Need to select the frame, with all that implies
2993 so that the conditions will have the right context. */
2994 select_frame (get_current_frame ());
2996 = catch_errors (breakpoint_cond_eval, (bl->cond),
2997 "Error in testing breakpoint condition:\n",
2999 /* FIXME-someday, should give breakpoint # */
3002 if (bl->cond && value_is_zero)
3006 else if (b->thread != -1 && b->thread != thread_id)
3010 else if (b->ignore_count > 0)
3013 annotate_ignore_count_change ();
3015 /* Increase the hit count even though we don't
3023 /* Get a bpstat associated with having just stopped at address
3024 BP_ADDR in thread PTID.
3026 Determine whether we stopped at a breakpoint, etc, or whether we
3027 don't understand this stop. Result is a chain of bpstat's such that:
3029 if we don't understand the stop, the result is a null pointer.
3031 if we understand why we stopped, the result is not null.
3033 Each element of the chain refers to a particular breakpoint or
3034 watchpoint at which we have stopped. (We may have stopped for
3035 several reasons concurrently.)
3037 Each element of the chain has valid next, breakpoint_at,
3038 commands, FIXME??? fields. */
3041 bpstat_stop_status (CORE_ADDR bp_addr, ptid_t ptid)
3043 struct breakpoint *b = NULL;
3044 const struct bp_location *bl;
3045 struct bp_location *loc;
3046 /* Root of the chain of bpstat's */
3047 struct bpstats root_bs[1];
3048 /* Pointer to the last thing in the chain currently. */
3049 bpstat bs = root_bs;
3051 int need_remove_insert;
3053 ALL_BP_LOCATIONS (bl)
3057 if (!breakpoint_enabled (b) && b->enable_state != bp_permanent)
3060 /* For hardware watchpoints, we look only at the first location.
3061 The watchpoint_check function will work on entire expression,
3062 not the individual locations. For read watchopints, the
3063 watchpoints_triggered function have checked all locations
3066 if (b->type == bp_hardware_watchpoint && bl != b->loc)
3069 if (!bpstat_check_location (bl, bp_addr))
3072 /* Come here if it's a watchpoint, or if the break address matches */
3074 bs = bpstat_alloc (bl, bs); /* Alloc a bpstat to explain stop */
3076 /* Assume we stop. Should we find watchpoint that is not actually
3077 triggered, or if condition of breakpoint is false, we'll reset
3082 bpstat_check_watchpoint (bs);
3086 if (b->type == bp_thread_event || b->type == bp_overlay_event)
3087 /* We do not stop for these. */
3090 bpstat_check_breakpoint_conditions (bs, ptid);
3096 /* We will stop here */
3097 if (b->disposition == disp_disable)
3099 if (b->enable_state != bp_permanent)
3100 b->enable_state = bp_disabled;
3101 update_global_location_list (0);
3105 bs->commands = b->commands;
3107 (strcmp ("silent", bs->commands->line) == 0
3108 || (xdb_commands && strcmp ("Q", bs->commands->line) == 0)))
3110 bs->commands = bs->commands->next;
3113 bs->commands = copy_command_lines (bs->commands);
3116 /* Print nothing for this entry if we dont stop or if we dont print. */
3117 if (bs->stop == 0 || bs->print == 0)
3118 bs->print_it = print_it_noop;
3121 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
3123 if (loc->address == bp_addr)
3125 bs = bpstat_alloc (loc, bs);
3126 /* For hits of moribund locations, we should just proceed. */
3129 bs->print_it = print_it_noop;
3133 bs->next = NULL; /* Terminate the chain */
3134 bs = root_bs->next; /* Re-grab the head of the chain */
3136 /* If we aren't stopping, the value of some hardware watchpoint may
3137 not have changed, but the intermediate memory locations we are
3138 watching may have. Don't bother if we're stopping; this will get
3140 for (bs = root_bs->next; bs != NULL; bs = bs->next)
3144 need_remove_insert = 0;
3146 for (bs = root_bs->next; bs != NULL; bs = bs->next)
3148 && bs->breakpoint_at->owner
3149 && (bs->breakpoint_at->owner->type == bp_hardware_watchpoint
3150 || bs->breakpoint_at->owner->type == bp_read_watchpoint
3151 || bs->breakpoint_at->owner->type == bp_access_watchpoint))
3153 /* remove/insert can invalidate bs->breakpoint_at, if this
3154 location is no longer used by the watchpoint. Prevent
3155 further code from trying to use it. */
3156 bs->breakpoint_at = NULL;
3157 need_remove_insert = 1;
3160 if (need_remove_insert)
3162 remove_breakpoints ();
3163 insert_breakpoints ();
3166 return root_bs->next;
3169 /* Tell what to do about this bpstat. */
3171 bpstat_what (bpstat bs)
3173 /* Classify each bpstat as one of the following. */
3176 /* This bpstat element has no effect on the main_action. */
3179 /* There was a watchpoint, stop but don't print. */
3182 /* There was a watchpoint, stop and print. */
3185 /* There was a breakpoint but we're not stopping. */
3188 /* There was a breakpoint, stop but don't print. */
3191 /* There was a breakpoint, stop and print. */
3194 /* We hit the longjmp breakpoint. */
3197 /* We hit the longjmp_resume breakpoint. */
3200 /* We hit the step_resume breakpoint. */
3203 /* We hit the shared library event breakpoint. */
3206 /* We caught a shared library event. */
3209 /* This is just used to count how many enums there are. */
3213 /* Here is the table which drives this routine. So that we can
3214 format it pretty, we define some abbreviations for the
3215 enum bpstat_what codes. */
3216 #define kc BPSTAT_WHAT_KEEP_CHECKING
3217 #define ss BPSTAT_WHAT_STOP_SILENT
3218 #define sn BPSTAT_WHAT_STOP_NOISY
3219 #define sgl BPSTAT_WHAT_SINGLE
3220 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3221 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3222 #define sr BPSTAT_WHAT_STEP_RESUME
3223 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3224 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
3226 /* "Can't happen." Might want to print an error message.
3227 abort() is not out of the question, but chances are GDB is just
3228 a bit confused, not unusable. */
3229 #define err BPSTAT_WHAT_STOP_NOISY
3231 /* Given an old action and a class, come up with a new action. */
3232 /* One interesting property of this table is that wp_silent is the same
3233 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3234 after stopping, the check for whether to step over a breakpoint
3235 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3236 reference to how we stopped. We retain separate wp_silent and
3237 bp_silent codes in case we want to change that someday.
3239 Another possibly interesting property of this table is that
3240 there's a partial ordering, priority-like, of the actions. Once
3241 you've decided that some action is appropriate, you'll never go
3242 back and decide something of a lower priority is better. The
3245 kc < clr sgl shl shlr slr sn sr ss
3246 sgl < shl shlr slr sn sr ss
3247 slr < err shl shlr sn sr ss
3248 clr < err shl shlr sn sr ss
3255 What I think this means is that we don't need a damned table
3256 here. If you just put the rows and columns in the right order,
3257 it'd look awfully regular. We could simply walk the bpstat list
3258 and choose the highest priority action we find, with a little
3259 logic to handle the 'err' cases. */
3261 /* step_resume entries: a step resume breakpoint overrides another
3262 breakpoint of signal handling (see comment in wait_for_inferior
3263 at where we set the step_resume breakpoint). */
3265 static const enum bpstat_what_main_action
3266 table[(int) class_last][(int) BPSTAT_WHAT_LAST] =
3269 /* kc ss sn sgl slr clr sr shl shlr
3272 {kc, ss, sn, sgl, slr, clr, sr, shl, shlr},
3274 {ss, ss, sn, ss, ss, ss, sr, shl, shlr},
3276 {sn, sn, sn, sn, sn, sn, sr, shl, shlr},
3278 {sgl, ss, sn, sgl, slr, slr, sr, shl, shlr},
3280 {ss, ss, sn, ss, ss, ss, sr, shl, shlr},
3282 {sn, sn, sn, sn, sn, sn, sr, shl, shlr},
3284 {slr, ss, sn, slr, slr, err, sr, shl, shlr},
3286 {clr, ss, sn, err, err, err, sr, shl, shlr},
3288 {sr, sr, sr, sr, sr, sr, sr, sr, sr},
3290 {shl, shl, shl, shl, shl, shl, sr, shl, shlr},
3292 {shlr, shlr, shlr, shlr, shlr, shlr, sr, shlr, shlr}
3306 enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
3307 struct bpstat_what retval;
3309 retval.call_dummy = 0;
3310 for (; bs != NULL; bs = bs->next)
3312 enum class bs_class = no_effect;
3313 if (bs->breakpoint_at == NULL)
3314 /* I suspect this can happen if it was a momentary breakpoint
3315 which has since been deleted. */
3317 if (bs->breakpoint_at->owner == NULL)
3318 bs_class = bp_nostop;
3320 switch (bs->breakpoint_at->owner->type)
3326 case bp_hardware_breakpoint:
3332 bs_class = bp_noisy;
3334 bs_class = bp_silent;
3337 bs_class = bp_nostop;
3340 case bp_hardware_watchpoint:
3341 case bp_read_watchpoint:
3342 case bp_access_watchpoint:
3346 bs_class = wp_noisy;
3348 bs_class = wp_silent;
3351 /* There was a watchpoint, but we're not stopping.
3352 This requires no further action. */
3353 bs_class = no_effect;
3356 bs_class = long_jump;
3358 case bp_longjmp_resume:
3359 bs_class = long_resume;
3361 case bp_step_resume:
3364 bs_class = step_resume;
3367 /* It is for the wrong frame. */
3368 bs_class = bp_nostop;
3370 case bp_watchpoint_scope:
3371 bs_class = bp_nostop;
3373 case bp_shlib_event:
3374 bs_class = shlib_event;
3376 case bp_thread_event:
3377 case bp_overlay_event:
3378 bs_class = bp_nostop;
3381 case bp_catch_unload:
3382 /* Only if this catchpoint triggered should we cause the
3383 step-out-of-dld behaviour. Otherwise, we ignore this
3386 bs_class = catch_shlib_event;
3388 bs_class = no_effect;
3395 bs_class = bp_noisy;
3397 bs_class = bp_silent;
3400 /* There was a catchpoint, but we're not stopping.
3401 This requires no further action. */
3402 bs_class = no_effect;
3405 /* Make sure the action is stop (silent or noisy),
3406 so infrun.c pops the dummy frame. */
3407 bs_class = bp_silent;
3408 retval.call_dummy = 1;
3411 current_action = table[(int) bs_class][(int) current_action];
3413 retval.main_action = current_action;
3417 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3418 without hardware support). This isn't related to a specific bpstat,
3419 just to things like whether watchpoints are set. */
3422 bpstat_should_step (void)
3424 struct breakpoint *b;
3426 if (breakpoint_enabled (b) && b->type == bp_watchpoint)
3433 /* Given a bpstat that records zero or more triggered eventpoints, this
3434 function returns another bpstat which contains only the catchpoints
3435 on that first list, if any. */
3437 bpstat_get_triggered_catchpoints (bpstat ep_list, bpstat *cp_list)
3439 struct bpstats root_bs[1];
3440 bpstat bs = root_bs;
3441 struct breakpoint *ep;
3444 bpstat_clear (cp_list);
3445 root_bs->next = NULL;
3447 for (; ep_list != NULL; ep_list = ep_list->next)
3449 /* Is this eventpoint a catchpoint? If not, ignore it. */
3450 ep = ep_list->breakpoint_at->owner;
3453 if ((ep->type != bp_catch_load) &&
3454 (ep->type != bp_catch_unload))
3455 /* pai: (temp) ADD fork/vfork here!! */
3458 /* Yes; add it to the list. */
3459 bs = bpstat_alloc (ep_list->breakpoint_at, bs);
3464 #if defined(SOLIB_ADD)
3465 /* Also, for each triggered catchpoint, tag it with the name of
3466 the library that caused this trigger. (We copy the name now,
3467 because it's only guaranteed to be available NOW, when the
3468 catchpoint triggers. Clients who may wish to know the name
3469 later must get it from the catchpoint itself.) */
3470 if (ep->triggered_dll_pathname != NULL)
3471 xfree (ep->triggered_dll_pathname);
3472 if (ep->type == bp_catch_load)
3473 dll_pathname = SOLIB_LOADED_LIBRARY_PATHNAME (
3474 PIDGET (inferior_ptid));
3476 dll_pathname = SOLIB_UNLOADED_LIBRARY_PATHNAME (
3477 PIDGET (inferior_ptid));
3479 dll_pathname = NULL;
3483 ep->triggered_dll_pathname = (char *)
3484 xmalloc (strlen (dll_pathname) + 1);
3485 strcpy (ep->triggered_dll_pathname, dll_pathname);
3488 ep->triggered_dll_pathname = NULL;
3494 static void print_breakpoint_location (struct breakpoint *b,
3495 struct bp_location *loc,
3497 struct ui_stream *stb)
3502 = find_pc_sect_function (loc->address, loc->section);
3505 ui_out_text (uiout, "in ");
3506 ui_out_field_string (uiout, "func",
3507 SYMBOL_PRINT_NAME (sym));
3508 ui_out_wrap_hint (uiout, wrap_indent);
3509 ui_out_text (uiout, " at ");
3511 ui_out_field_string (uiout, "file", b->source_file);
3512 ui_out_text (uiout, ":");
3514 if (ui_out_is_mi_like_p (uiout))
3516 struct symtab_and_line sal = find_pc_line (loc->address, 0);
3517 char *fullname = symtab_to_fullname (sal.symtab);
3520 ui_out_field_string (uiout, "fullname", fullname);
3523 ui_out_field_int (uiout, "line", b->line_number);
3527 ui_out_field_string (uiout, "pending", b->addr_string);
3531 print_address_symbolic (loc->address, stb->stream, demangle, "");
3532 ui_out_field_stream (uiout, "at", stb);
3536 /* Print B to gdb_stdout. */
3538 print_one_breakpoint_location (struct breakpoint *b,
3539 struct bp_location *loc,
3541 CORE_ADDR *last_addr)
3543 struct command_line *l;
3545 struct ep_type_description
3550 static struct ep_type_description bptypes[] =
3552 {bp_none, "?deleted?"},
3553 {bp_breakpoint, "breakpoint"},
3554 {bp_hardware_breakpoint, "hw breakpoint"},
3555 {bp_until, "until"},
3556 {bp_finish, "finish"},
3557 {bp_watchpoint, "watchpoint"},
3558 {bp_hardware_watchpoint, "hw watchpoint"},
3559 {bp_read_watchpoint, "read watchpoint"},
3560 {bp_access_watchpoint, "acc watchpoint"},
3561 {bp_longjmp, "longjmp"},
3562 {bp_longjmp_resume, "longjmp resume"},
3563 {bp_step_resume, "step resume"},
3564 {bp_watchpoint_scope, "watchpoint scope"},
3565 {bp_call_dummy, "call dummy"},
3566 {bp_shlib_event, "shlib events"},
3567 {bp_thread_event, "thread events"},
3568 {bp_overlay_event, "overlay events"},
3569 {bp_catchpoint, "catchpoint"},
3570 {bp_catch_load, "catch load"},
3571 {bp_catch_unload, "catch unload"},
3572 {bp_catch_exec, "catch exec"}
3575 static char bpenables[] = "nynny";
3576 char wrap_indent[80];
3577 struct ui_stream *stb = ui_out_stream_new (uiout);
3578 struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb);
3579 struct cleanup *bkpt_chain;
3581 int header_of_multiple = 0;
3582 int part_of_multiple = (loc != NULL);
3583 struct value_print_options opts;
3585 get_user_print_options (&opts);
3587 gdb_assert (!loc || loc_number != 0);
3588 /* See comment in print_one_breakpoint concerning
3589 treatment of breakpoints with single disabled
3593 && (b->loc->next != NULL || !b->loc->enabled)))
3594 header_of_multiple = 1;
3599 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
3603 if (part_of_multiple)
3606 formatted = xstrprintf ("%d.%d", b->number, loc_number);
3607 ui_out_field_string (uiout, "number", formatted);
3612 ui_out_field_int (uiout, "number", b->number);
3617 if (part_of_multiple)
3618 ui_out_field_skip (uiout, "type");
3621 if (((int) b->type >= (sizeof (bptypes) / sizeof (bptypes[0])))
3622 || ((int) b->type != bptypes[(int) b->type].type))
3623 internal_error (__FILE__, __LINE__,
3624 _("bptypes table does not describe type #%d."),
3626 ui_out_field_string (uiout, "type", bptypes[(int) b->type].description);
3631 if (part_of_multiple)
3632 ui_out_field_skip (uiout, "disp");
3634 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
3639 if (part_of_multiple)
3640 ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n");
3642 ui_out_field_fmt (uiout, "enabled", "%c",
3643 bpenables[(int) b->enable_state]);
3644 ui_out_spaces (uiout, 2);
3648 strcpy (wrap_indent, " ");
3649 if (opts.addressprint)
3651 if (gdbarch_addr_bit (current_gdbarch) <= 32)
3652 strcat (wrap_indent, " ");
3654 strcat (wrap_indent, " ");
3657 if (b->ops != NULL && b->ops->print_one != NULL)
3659 /* Although the print_one can possibly print
3660 all locations, calling it here is not likely
3661 to get any nice result. So, make sure there's
3662 just one location. */
3663 gdb_assert (b->loc == NULL || b->loc->next == NULL);
3664 b->ops->print_one (b, last_addr);
3670 internal_error (__FILE__, __LINE__,
3671 _("print_one_breakpoint: bp_none encountered\n"));
3675 case bp_hardware_watchpoint:
3676 case bp_read_watchpoint:
3677 case bp_access_watchpoint:
3678 /* Field 4, the address, is omitted (which makes the columns
3679 not line up too nicely with the headers, but the effect
3680 is relatively readable). */
3681 if (opts.addressprint)
3682 ui_out_field_skip (uiout, "addr");
3684 print_expression (b->exp, stb->stream);
3685 ui_out_field_stream (uiout, "what", stb);
3689 case bp_catch_unload:
3690 /* Field 4, the address, is omitted (which makes the columns
3691 not line up too nicely with the headers, but the effect
3692 is relatively readable). */
3693 if (opts.addressprint)
3694 ui_out_field_skip (uiout, "addr");
3696 if (b->dll_pathname == NULL)
3698 ui_out_field_string (uiout, "what", "<any library>");
3699 ui_out_spaces (uiout, 1);
3703 ui_out_text (uiout, "library \"");
3704 ui_out_field_string (uiout, "what", b->dll_pathname);
3705 ui_out_text (uiout, "\" ");
3710 /* Field 4, the address, is omitted (which makes the columns
3711 not line up too nicely with the headers, but the effect
3712 is relatively readable). */
3713 if (opts.addressprint)
3714 ui_out_field_skip (uiout, "addr");
3716 if (b->exec_pathname != NULL)
3718 ui_out_text (uiout, "program \"");
3719 ui_out_field_string (uiout, "what", b->exec_pathname);
3720 ui_out_text (uiout, "\" ");
3725 case bp_hardware_breakpoint:
3729 case bp_longjmp_resume:
3730 case bp_step_resume:
3731 case bp_watchpoint_scope:
3733 case bp_shlib_event:
3734 case bp_thread_event:
3735 case bp_overlay_event:
3736 if (opts.addressprint)
3739 if (header_of_multiple)
3740 ui_out_field_string (uiout, "addr", "<MULTIPLE>");
3741 else if (b->loc == NULL || loc->shlib_disabled)
3742 ui_out_field_string (uiout, "addr", "<PENDING>");
3744 ui_out_field_core_addr (uiout, "addr", loc->address);
3747 if (!header_of_multiple)
3748 print_breakpoint_location (b, loc, wrap_indent, stb);
3750 *last_addr = b->loc->address;
3754 if (!part_of_multiple && b->thread != -1)
3756 /* FIXME: This seems to be redundant and lost here; see the
3757 "stop only in" line a little further down. */
3758 ui_out_text (uiout, " thread ");
3759 ui_out_field_int (uiout, "thread", b->thread);
3762 ui_out_text (uiout, "\n");
3764 if (part_of_multiple && frame_id_p (b->frame_id))
3767 ui_out_text (uiout, "\tstop only in stack frame at ");
3768 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3770 ui_out_field_core_addr (uiout, "frame", b->frame_id.stack_addr);
3771 ui_out_text (uiout, "\n");
3774 if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b))
3776 /* We do not print the condition for Ada exception catchpoints
3777 because the condition is an internal implementation detail
3778 that we do not want to expose to the user. */
3780 ui_out_text (uiout, "\tstop only if ");
3781 ui_out_field_string (uiout, "cond", b->cond_string);
3782 ui_out_text (uiout, "\n");
3785 if (!part_of_multiple && b->thread != -1)
3787 /* FIXME should make an annotation for this */
3788 ui_out_text (uiout, "\tstop only in thread ");
3789 ui_out_field_int (uiout, "thread", b->thread);
3790 ui_out_text (uiout, "\n");
3793 if (!part_of_multiple && b->hit_count)
3795 /* FIXME should make an annotation for this */
3796 if (ep_is_catchpoint (b))
3797 ui_out_text (uiout, "\tcatchpoint");
3799 ui_out_text (uiout, "\tbreakpoint");
3800 ui_out_text (uiout, " already hit ");
3801 ui_out_field_int (uiout, "times", b->hit_count);
3802 if (b->hit_count == 1)
3803 ui_out_text (uiout, " time\n");
3805 ui_out_text (uiout, " times\n");
3808 /* Output the count also if it is zero, but only if this is
3809 mi. FIXME: Should have a better test for this. */
3810 if (ui_out_is_mi_like_p (uiout))
3811 if (!part_of_multiple && b->hit_count == 0)
3812 ui_out_field_int (uiout, "times", b->hit_count);
3814 if (!part_of_multiple && b->ignore_count)
3817 ui_out_text (uiout, "\tignore next ");
3818 ui_out_field_int (uiout, "ignore", b->ignore_count);
3819 ui_out_text (uiout, " hits\n");
3822 if (!part_of_multiple && (l = b->commands))
3824 struct cleanup *script_chain;
3827 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
3828 print_command_lines (uiout, l, 4);
3829 do_cleanups (script_chain);
3832 if (ui_out_is_mi_like_p (uiout) && !part_of_multiple)
3835 ui_out_field_string (uiout, "original-location", b->addr_string);
3836 else if (b->exp_string)
3837 ui_out_field_string (uiout, "original-location", b->exp_string);
3840 do_cleanups (bkpt_chain);
3841 do_cleanups (old_chain);
3845 print_one_breakpoint (struct breakpoint *b,
3846 CORE_ADDR *last_addr)
3848 print_one_breakpoint_location (b, NULL, 0, last_addr);
3850 /* If this breakpoint has custom print function,
3851 it's already printed. Otherwise, print individual
3852 locations, if any. */
3853 if (b->ops == NULL || b->ops->print_one == NULL)
3855 /* If breakpoint has a single location that is
3856 disabled, we print it as if it had
3857 several locations, since otherwise it's hard to
3858 represent "breakpoint enabled, location disabled"
3860 Note that while hardware watchpoints have
3861 several locations internally, that's no a property
3864 && !is_hardware_watchpoint (b)
3865 && (b->loc->next || !b->loc->enabled)
3866 && !ui_out_is_mi_like_p (uiout))
3868 struct bp_location *loc;
3870 for (loc = b->loc; loc; loc = loc->next, ++n)
3871 print_one_breakpoint_location (b, loc, n, last_addr);
3877 struct captured_breakpoint_query_args
3883 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
3885 struct captured_breakpoint_query_args *args = data;
3886 struct breakpoint *b;
3887 CORE_ADDR dummy_addr = 0;
3890 if (args->bnum == b->number)
3892 print_one_breakpoint (b, &dummy_addr);
3900 gdb_breakpoint_query (struct ui_out *uiout, int bnum, char **error_message)
3902 struct captured_breakpoint_query_args args;
3904 /* For the moment we don't trust print_one_breakpoint() to not throw
3906 if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args,
3907 error_message, RETURN_MASK_ALL) < 0)
3913 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3914 catchpoints, et.al.). */
3917 user_settable_breakpoint (const struct breakpoint *b)
3919 return (b->type == bp_breakpoint
3920 || b->type == bp_catchpoint
3921 || b->type == bp_catch_load
3922 || b->type == bp_catch_unload
3923 || b->type == bp_catch_exec
3924 || b->type == bp_hardware_breakpoint
3925 || b->type == bp_watchpoint
3926 || b->type == bp_read_watchpoint
3927 || b->type == bp_access_watchpoint
3928 || b->type == bp_hardware_watchpoint);
3931 /* Print information on user settable breakpoint (watchpoint, etc)
3932 number BNUM. If BNUM is -1 print all user settable breakpoints.
3933 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3936 breakpoint_1 (int bnum, int allflag)
3938 struct breakpoint *b;
3939 CORE_ADDR last_addr = (CORE_ADDR) -1;
3940 int nr_printable_breakpoints;
3941 struct cleanup *bkpttbl_chain;
3942 struct value_print_options opts;
3944 get_user_print_options (&opts);
3946 /* Compute the number of rows in the table. */
3947 nr_printable_breakpoints = 0;
3950 || bnum == b->number)
3952 if (allflag || user_settable_breakpoint (b))
3953 nr_printable_breakpoints++;
3956 if (opts.addressprint)
3958 = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints,
3962 = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints,
3965 if (nr_printable_breakpoints > 0)
3966 annotate_breakpoints_headers ();
3967 if (nr_printable_breakpoints > 0)
3969 ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */
3970 if (nr_printable_breakpoints > 0)
3972 ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */
3973 if (nr_printable_breakpoints > 0)
3975 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
3976 if (nr_printable_breakpoints > 0)
3978 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
3979 if (opts.addressprint)
3981 if (nr_printable_breakpoints > 0)
3983 if (gdbarch_addr_bit (current_gdbarch) <= 32)
3984 ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */
3986 ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */
3988 if (nr_printable_breakpoints > 0)
3990 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
3991 ui_out_table_body (uiout);
3992 if (nr_printable_breakpoints > 0)
3993 annotate_breakpoints_table ();
3997 || bnum == b->number)
3999 /* We only print out user settable breakpoints unless the
4001 if (allflag || user_settable_breakpoint (b))
4002 print_one_breakpoint (b, &last_addr);
4005 do_cleanups (bkpttbl_chain);
4007 if (nr_printable_breakpoints == 0)
4010 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
4012 ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n",
4017 /* Compare against (CORE_ADDR)-1 in case some compiler decides
4018 that a comparison of an unsigned with -1 is always false. */
4019 if (last_addr != (CORE_ADDR) -1 && !server_command)
4020 set_next_address (current_gdbarch, last_addr);
4023 /* FIXME? Should this be moved up so that it is only called when
4024 there have been breakpoints? */
4025 annotate_breakpoints_table_end ();
4029 breakpoints_info (char *bnum_exp, int from_tty)
4034 bnum = parse_and_eval_long (bnum_exp);
4036 breakpoint_1 (bnum, 0);
4040 maintenance_info_breakpoints (char *bnum_exp, int from_tty)
4045 bnum = parse_and_eval_long (bnum_exp);
4047 breakpoint_1 (bnum, 1);
4051 breakpoint_has_pc (struct breakpoint *b,
4052 CORE_ADDR pc, struct obj_section *section)
4054 struct bp_location *bl = b->loc;
4055 for (; bl; bl = bl->next)
4057 if (bl->address == pc
4058 && (!overlay_debugging || bl->section == section))
4064 /* Print a message describing any breakpoints set at PC. */
4067 describe_other_breakpoints (CORE_ADDR pc, struct obj_section *section,
4071 struct breakpoint *b;
4074 others += breakpoint_has_pc (b, pc, section);
4078 printf_filtered (_("Note: breakpoint "));
4079 else /* if (others == ???) */
4080 printf_filtered (_("Note: breakpoints "));
4082 if (breakpoint_has_pc (b, pc, section))
4085 printf_filtered ("%d", b->number);
4086 if (b->thread == -1 && thread != -1)
4087 printf_filtered (" (all threads)");
4088 else if (b->thread != -1)
4089 printf_filtered (" (thread %d)", b->thread);
4090 printf_filtered ("%s%s ",
4091 ((b->enable_state == bp_disabled ||
4092 b->enable_state == bp_call_disabled)
4094 : b->enable_state == bp_permanent
4098 : ((others == 1) ? " and" : ""));
4100 printf_filtered (_("also set at pc "));
4101 fputs_filtered (paddress (pc), gdb_stdout);
4102 printf_filtered (".\n");
4106 /* Set the default place to put a breakpoint
4107 for the `break' command with no arguments. */
4110 set_default_breakpoint (int valid, CORE_ADDR addr, struct symtab *symtab,
4113 default_breakpoint_valid = valid;
4114 default_breakpoint_address = addr;
4115 default_breakpoint_symtab = symtab;
4116 default_breakpoint_line = line;
4119 /* Return true iff it is meaningful to use the address member of
4120 BPT. For some breakpoint types, the address member is irrelevant
4121 and it makes no sense to attempt to compare it to other addresses
4122 (or use it for any other purpose either).
4124 More specifically, each of the following breakpoint types will always
4125 have a zero valued address and we don't want check_duplicates() to mark
4126 breakpoints of any of these types to be a duplicate of an actual
4127 breakpoint at address zero:
4130 bp_hardware_watchpoint
4132 bp_access_watchpoint
4137 breakpoint_address_is_meaningful (struct breakpoint *bpt)
4139 enum bptype type = bpt->type;
4141 return (type != bp_watchpoint
4142 && type != bp_hardware_watchpoint
4143 && type != bp_read_watchpoint
4144 && type != bp_access_watchpoint
4145 && type != bp_catchpoint
4146 && type != bp_catch_exec);
4149 /* Rescan breakpoints at the same address and section as BPT,
4150 marking the first one as "first" and any others as "duplicates".
4151 This is so that the bpt instruction is only inserted once.
4152 If we have a permanent breakpoint at the same place as BPT, make
4153 that one the official one, and the rest as duplicates. */
4156 check_duplicates_for (CORE_ADDR address, struct obj_section *section)
4158 struct bp_location *b;
4160 struct bp_location *perm_bp = 0;
4162 ALL_BP_LOCATIONS (b)
4163 if (b->owner->enable_state != bp_disabled
4164 && b->owner->enable_state != bp_call_disabled
4166 && !b->shlib_disabled
4167 && b->address == address /* address / overlay match */
4168 && (!overlay_debugging || b->section == section)
4169 && breakpoint_address_is_meaningful (b->owner))
4171 /* Have we found a permanent breakpoint? */
4172 if (b->owner->enable_state == bp_permanent)
4179 b->duplicate = count > 1;
4182 /* If we found a permanent breakpoint at this address, go over the
4183 list again and declare all the other breakpoints there to be the
4187 perm_bp->duplicate = 0;
4189 /* Permanent breakpoint should always be inserted. */
4190 if (! perm_bp->inserted)
4191 internal_error (__FILE__, __LINE__,
4192 _("allegedly permanent breakpoint is not "
4193 "actually inserted"));
4195 ALL_BP_LOCATIONS (b)
4198 if (b->owner->enable_state != bp_disabled
4199 && b->owner->enable_state != bp_call_disabled
4200 && b->enabled && !b->shlib_disabled
4201 && b->address == address /* address / overlay match */
4202 && (!overlay_debugging || b->section == section)
4203 && breakpoint_address_is_meaningful (b->owner))
4206 internal_error (__FILE__, __LINE__,
4207 _("another breakpoint was inserted on top of "
4208 "a permanent breakpoint"));
4217 check_duplicates (struct breakpoint *bpt)
4219 struct bp_location *bl = bpt->loc;
4221 if (! breakpoint_address_is_meaningful (bpt))
4224 for (; bl; bl = bl->next)
4225 check_duplicates_for (bl->address, bl->section);
4229 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
4230 int bnum, int have_bnum)
4235 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
4236 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
4238 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4239 bnum, astr1, astr2);
4241 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
4244 /* Adjust a breakpoint's address to account for architectural constraints
4245 on breakpoint placement. Return the adjusted address. Note: Very
4246 few targets require this kind of adjustment. For most targets,
4247 this function is simply the identity function. */
4250 adjust_breakpoint_address (CORE_ADDR bpaddr, enum bptype bptype)
4252 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch))
4254 /* Very few targets need any kind of breakpoint adjustment. */
4257 else if (bptype == bp_watchpoint
4258 || bptype == bp_hardware_watchpoint
4259 || bptype == bp_read_watchpoint
4260 || bptype == bp_access_watchpoint
4261 || bptype == bp_catchpoint
4262 || bptype == bp_catch_exec)
4264 /* Watchpoints and the various bp_catch_* eventpoints should not
4265 have their addresses modified. */
4270 CORE_ADDR adjusted_bpaddr;
4272 /* Some targets have architectural constraints on the placement
4273 of breakpoint instructions. Obtain the adjusted address. */
4274 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (current_gdbarch,
4277 /* An adjusted breakpoint address can significantly alter
4278 a user's expectations. Print a warning if an adjustment
4280 if (adjusted_bpaddr != bpaddr)
4281 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
4283 return adjusted_bpaddr;
4287 /* Allocate a struct bp_location. */
4289 static struct bp_location *
4290 allocate_bp_location (struct breakpoint *bpt, enum bptype bp_type)
4292 struct bp_location *loc, *loc_p;
4294 loc = xmalloc (sizeof (struct bp_location));
4295 memset (loc, 0, sizeof (*loc));
4299 loc->shlib_disabled = 0;
4308 case bp_longjmp_resume:
4309 case bp_step_resume:
4310 case bp_watchpoint_scope:
4312 case bp_shlib_event:
4313 case bp_thread_event:
4314 case bp_overlay_event:
4316 case bp_catch_unload:
4317 loc->loc_type = bp_loc_software_breakpoint;
4319 case bp_hardware_breakpoint:
4320 loc->loc_type = bp_loc_hardware_breakpoint;
4322 case bp_hardware_watchpoint:
4323 case bp_read_watchpoint:
4324 case bp_access_watchpoint:
4325 loc->loc_type = bp_loc_hardware_watchpoint;
4330 loc->loc_type = bp_loc_other;
4333 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
4339 static void free_bp_location (struct bp_location *loc)
4344 if (loc->function_name)
4345 xfree (loc->function_name);
4350 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4351 that has type BPTYPE and has no locations as yet. */
4353 static struct breakpoint *
4354 set_raw_breakpoint_without_location (enum bptype bptype)
4356 struct breakpoint *b, *b1;
4358 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
4359 memset (b, 0, sizeof (*b));
4362 b->language = current_language->la_language;
4363 b->input_radix = input_radix;
4365 b->enable_state = bp_enabled;
4368 b->ignore_count = 0;
4370 b->frame_id = null_frame_id;
4371 b->dll_pathname = NULL;
4372 b->triggered_dll_pathname = NULL;
4373 b->forked_inferior_pid = null_ptid;
4374 b->exec_pathname = NULL;
4376 b->condition_not_parsed = 0;
4378 /* Add this breakpoint to the end of the chain
4379 so that a list of breakpoints will come out in order
4380 of increasing numbers. */
4382 b1 = breakpoint_chain;
4384 breakpoint_chain = b;
4394 /* Initialize loc->function_name. */
4396 set_breakpoint_location_function (struct bp_location *loc)
4398 if (loc->owner->type == bp_breakpoint
4399 || loc->owner->type == bp_hardware_breakpoint)
4401 find_pc_partial_function (loc->address, &(loc->function_name),
4403 if (loc->function_name)
4404 loc->function_name = xstrdup (loc->function_name);
4408 /* set_raw_breakpoint is a low level routine for allocating and
4409 partially initializing a breakpoint of type BPTYPE. The newly
4410 created breakpoint's address, section, source file name, and line
4411 number are provided by SAL. The newly created and partially
4412 initialized breakpoint is added to the breakpoint chain and
4413 is also returned as the value of this function.
4415 It is expected that the caller will complete the initialization of
4416 the newly created breakpoint struct as well as output any status
4417 information regarding the creation of a new breakpoint. In
4418 particular, set_raw_breakpoint does NOT set the breakpoint
4419 number! Care should be taken to not allow an error to occur
4420 prior to completing the initialization of the breakpoint. If this
4421 should happen, a bogus breakpoint will be left on the chain. */
4424 set_raw_breakpoint (struct symtab_and_line sal, enum bptype bptype)
4426 struct breakpoint *b = set_raw_breakpoint_without_location (bptype);
4427 CORE_ADDR adjusted_address;
4429 /* Adjust the breakpoint's address prior to allocating a location.
4430 Once we call allocate_bp_location(), that mostly uninitialized
4431 location will be placed on the location chain. Adjustment of the
4432 breakpoint may cause target_read_memory() to be called and we do
4433 not want its scan of the location chain to find a breakpoint and
4434 location that's only been partially initialized. */
4435 adjusted_address = adjust_breakpoint_address (sal.pc, bptype);
4437 b->loc = allocate_bp_location (b, bptype);
4438 b->loc->requested_address = sal.pc;
4439 b->loc->address = adjusted_address;
4441 if (sal.symtab == NULL)
4442 b->source_file = NULL;
4444 b->source_file = savestring (sal.symtab->filename,
4445 strlen (sal.symtab->filename));
4446 b->loc->section = sal.section;
4447 b->line_number = sal.line;
4449 set_breakpoint_location_function (b->loc);
4451 breakpoints_changed ();
4457 /* Note that the breakpoint object B describes a permanent breakpoint
4458 instruction, hard-wired into the inferior's code. */
4460 make_breakpoint_permanent (struct breakpoint *b)
4462 struct bp_location *bl;
4463 b->enable_state = bp_permanent;
4465 /* By definition, permanent breakpoints are already present in the code.
4466 Mark all locations as inserted. For now, make_breakpoint_permanent
4467 is called in just one place, so it's hard to say if it's reasonable
4468 to have permanent breakpoint with multiple locations or not,
4469 but it's easy to implmement. */
4470 for (bl = b->loc; bl; bl = bl->next)
4474 static struct breakpoint *
4475 create_internal_breakpoint (CORE_ADDR address, enum bptype type)
4477 static int internal_breakpoint_number = -1;
4478 struct symtab_and_line sal;
4479 struct breakpoint *b;
4481 init_sal (&sal); /* initialize to zeroes */
4484 sal.section = find_pc_overlay (sal.pc);
4486 b = set_raw_breakpoint (sal, type);
4487 b->number = internal_breakpoint_number--;
4488 b->disposition = disp_donttouch;
4495 create_longjmp_breakpoint (char *func_name)
4497 struct minimal_symbol *m;
4499 if ((m = lookup_minimal_symbol_text (func_name, NULL)) == NULL)
4501 set_momentary_breakpoint_at_pc (SYMBOL_VALUE_ADDRESS (m), bp_longjmp);
4502 update_global_location_list (1);
4505 /* Call this routine when stepping and nexting to enable a breakpoint
4506 if we do a longjmp(). When we hit that breakpoint, call
4507 set_longjmp_resume_breakpoint() to figure out where we are going. */
4510 set_longjmp_breakpoint (void)
4512 if (gdbarch_get_longjmp_target_p (current_gdbarch))
4514 create_longjmp_breakpoint ("longjmp");
4515 create_longjmp_breakpoint ("_longjmp");
4516 create_longjmp_breakpoint ("siglongjmp");
4517 create_longjmp_breakpoint ("_siglongjmp");
4521 /* Delete all longjmp breakpoints from THREAD. */
4523 delete_longjmp_breakpoint (int thread)
4525 struct breakpoint *b, *temp;
4527 ALL_BREAKPOINTS_SAFE (b, temp)
4528 if (b->type == bp_longjmp)
4530 if (b->thread == thread)
4531 delete_breakpoint (b);
4536 create_overlay_event_breakpoint_1 (char *func_name, struct objfile *objfile)
4538 struct breakpoint *b;
4539 struct minimal_symbol *m;
4541 if ((m = lookup_minimal_symbol_text (func_name, objfile)) == NULL)
4544 b = create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m),
4546 b->addr_string = xstrdup (func_name);
4548 if (overlay_debugging == ovly_auto)
4550 b->enable_state = bp_enabled;
4551 overlay_events_enabled = 1;
4555 b->enable_state = bp_disabled;
4556 overlay_events_enabled = 0;
4558 update_global_location_list (1);
4562 create_overlay_event_breakpoint (char *func_name)
4564 struct objfile *objfile;
4565 ALL_OBJFILES (objfile)
4566 create_overlay_event_breakpoint_1 (func_name, objfile);
4570 enable_overlay_breakpoints (void)
4572 struct breakpoint *b;
4575 if (b->type == bp_overlay_event)
4577 b->enable_state = bp_enabled;
4578 update_global_location_list (1);
4579 overlay_events_enabled = 1;
4584 disable_overlay_breakpoints (void)
4586 struct breakpoint *b;
4589 if (b->type == bp_overlay_event)
4591 b->enable_state = bp_disabled;
4592 update_global_location_list (0);
4593 overlay_events_enabled = 0;
4598 create_thread_event_breakpoint (CORE_ADDR address)
4600 struct breakpoint *b;
4602 b = create_internal_breakpoint (address, bp_thread_event);
4604 b->enable_state = bp_enabled;
4605 /* addr_string has to be used or breakpoint_re_set will delete me. */
4606 b->addr_string = xstrprintf ("*0x%s", paddr (b->loc->address));
4608 update_global_location_list_nothrow (1);
4614 remove_thread_event_breakpoints (void)
4616 struct breakpoint *b, *temp;
4618 ALL_BREAKPOINTS_SAFE (b, temp)
4619 if (b->type == bp_thread_event)
4620 delete_breakpoint (b);
4623 struct captured_parse_breakpoint_args
4626 struct symtabs_and_lines *sals_p;
4627 char ***addr_string_p;
4631 struct lang_and_radix
4639 remove_solib_event_breakpoints (void)
4641 struct breakpoint *b, *temp;
4643 ALL_BREAKPOINTS_SAFE (b, temp)
4644 if (b->type == bp_shlib_event)
4645 delete_breakpoint (b);
4649 create_solib_event_breakpoint (CORE_ADDR address)
4651 struct breakpoint *b;
4653 b = create_internal_breakpoint (address, bp_shlib_event);
4654 update_global_location_list_nothrow (1);
4658 /* Disable any breakpoints that are on code in shared libraries. Only
4659 apply to enabled breakpoints, disabled ones can just stay disabled. */
4662 disable_breakpoints_in_shlibs (void)
4664 struct bp_location *loc;
4665 int disabled_shlib_breaks = 0;
4667 ALL_BP_LOCATIONS (loc)
4669 struct breakpoint *b = loc->owner;
4670 /* We apply the check to all breakpoints, including disabled
4671 for those with loc->duplicate set. This is so that when breakpoint
4672 becomes enabled, or the duplicate is removed, gdb will try to insert
4673 all breakpoints. If we don't set shlib_disabled here, we'll try
4674 to insert those breakpoints and fail. */
4675 if (((b->type == bp_breakpoint) || (b->type == bp_hardware_breakpoint))
4676 && !loc->shlib_disabled
4678 && PC_SOLIB (loc->address)
4680 && solib_address (loc->address)
4684 loc->shlib_disabled = 1;
4689 /* Disable any breakpoints that are in in an unloaded shared library. Only
4690 apply to enabled breakpoints, disabled ones can just stay disabled. */
4693 disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
4695 struct bp_location *loc;
4696 int disabled_shlib_breaks = 0;
4698 ALL_BP_LOCATIONS (loc)
4700 struct breakpoint *b = loc->owner;
4701 if ((loc->loc_type == bp_loc_hardware_breakpoint
4702 || loc->loc_type == bp_loc_software_breakpoint)
4703 && !loc->shlib_disabled)
4706 char *so_name = PC_SOLIB (loc->address);
4708 char *so_name = solib_address (loc->address);
4710 if (so_name && !strcmp (so_name, solib->so_name))
4712 loc->shlib_disabled = 1;
4713 /* At this point, we cannot rely on remove_breakpoint
4714 succeeding so we must mark the breakpoint as not inserted
4715 to prevent future errors occurring in remove_breakpoints. */
4717 if (!disabled_shlib_breaks)
4719 target_terminal_ours_for_output ();
4720 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4723 disabled_shlib_breaks = 1;
4729 /* FORK & VFORK catchpoints. */
4731 /* Implement the "insert" breakpoint_ops method for fork catchpoints. */
4734 insert_catch_fork (struct breakpoint *b)
4736 target_insert_fork_catchpoint (PIDGET (inferior_ptid));
4739 /* Implement the "remove" breakpoint_ops method for fork catchpoints. */
4742 remove_catch_fork (struct breakpoint *b)
4744 return target_remove_fork_catchpoint (PIDGET (inferior_ptid));
4747 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
4751 breakpoint_hit_catch_fork (struct breakpoint *b)
4753 return inferior_has_forked (inferior_ptid, &b->forked_inferior_pid);
4756 /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */
4758 static enum print_stop_action
4759 print_it_catch_fork (struct breakpoint *b)
4761 annotate_catchpoint (b->number);
4762 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
4763 b->number, ptid_get_pid (b->forked_inferior_pid));
4764 return PRINT_SRC_AND_LOC;
4767 /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */
4770 print_one_catch_fork (struct breakpoint *b, CORE_ADDR *last_addr)
4772 struct value_print_options opts;
4774 get_user_print_options (&opts);
4776 /* Field 4, the address, is omitted (which makes the columns
4777 not line up too nicely with the headers, but the effect
4778 is relatively readable). */
4779 if (opts.addressprint)
4780 ui_out_field_skip (uiout, "addr");
4782 ui_out_text (uiout, "fork");
4783 if (!ptid_equal (b->forked_inferior_pid, null_ptid))
4785 ui_out_text (uiout, ", process ");
4786 ui_out_field_int (uiout, "what",
4787 ptid_get_pid (b->forked_inferior_pid));
4788 ui_out_spaces (uiout, 1);
4792 /* Implement the "print_mention" breakpoint_ops method for fork
4796 print_mention_catch_fork (struct breakpoint *b)
4798 printf_filtered (_("Catchpoint %d (fork)"), b->number);
4801 /* The breakpoint_ops structure to be used in fork catchpoints. */
4803 static struct breakpoint_ops catch_fork_breakpoint_ops =
4807 breakpoint_hit_catch_fork,
4808 print_it_catch_fork,
4809 print_one_catch_fork,
4810 print_mention_catch_fork
4813 /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */
4816 insert_catch_vfork (struct breakpoint *b)
4818 target_insert_vfork_catchpoint (PIDGET (inferior_ptid));
4821 /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */
4824 remove_catch_vfork (struct breakpoint *b)
4826 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid));
4829 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
4833 breakpoint_hit_catch_vfork (struct breakpoint *b)
4835 return inferior_has_vforked (inferior_ptid, &b->forked_inferior_pid);
4838 /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */
4840 static enum print_stop_action
4841 print_it_catch_vfork (struct breakpoint *b)
4843 annotate_catchpoint (b->number);
4844 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
4845 b->number, ptid_get_pid (b->forked_inferior_pid));
4846 return PRINT_SRC_AND_LOC;
4849 /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */
4852 print_one_catch_vfork (struct breakpoint *b, CORE_ADDR *last_addr)
4854 struct value_print_options opts;
4856 get_user_print_options (&opts);
4857 /* Field 4, the address, is omitted (which makes the columns
4858 not line up too nicely with the headers, but the effect
4859 is relatively readable). */
4860 if (opts.addressprint)
4861 ui_out_field_skip (uiout, "addr");
4863 ui_out_text (uiout, "vfork");
4864 if (!ptid_equal (b->forked_inferior_pid, null_ptid))
4866 ui_out_text (uiout, ", process ");
4867 ui_out_field_int (uiout, "what",
4868 ptid_get_pid (b->forked_inferior_pid));
4869 ui_out_spaces (uiout, 1);
4873 /* Implement the "print_mention" breakpoint_ops method for vfork
4877 print_mention_catch_vfork (struct breakpoint *b)
4879 printf_filtered (_("Catchpoint %d (vfork)"), b->number);
4882 /* The breakpoint_ops structure to be used in vfork catchpoints. */
4884 static struct breakpoint_ops catch_vfork_breakpoint_ops =
4888 breakpoint_hit_catch_vfork,
4889 print_it_catch_vfork,
4890 print_one_catch_vfork,
4891 print_mention_catch_vfork
4894 /* Create a new breakpoint of the bp_catchpoint kind and return it.
4896 If TEMPFLAG is non-zero, then make the breakpoint temporary.
4897 If COND_STRING is not NULL, then store it in the breakpoint.
4898 OPS, if not NULL, is the breakpoint_ops structure associated
4899 to the catchpoint. */
4901 static struct breakpoint *
4902 create_catchpoint (int tempflag, char *cond_string,
4903 struct breakpoint_ops *ops)
4905 struct symtab_and_line sal;
4906 struct breakpoint *b;
4913 b = set_raw_breakpoint (sal, bp_catchpoint);
4914 set_breakpoint_count (breakpoint_count + 1);
4915 b->number = breakpoint_count;
4917 b->cond_string = (cond_string == NULL) ?
4918 NULL : savestring (cond_string, strlen (cond_string));
4920 b->addr_string = NULL;
4921 b->enable_state = bp_enabled;
4922 b->disposition = tempflag ? disp_del : disp_donttouch;
4926 update_global_location_list (1);
4932 create_fork_vfork_event_catchpoint (int tempflag, char *cond_string,
4933 struct breakpoint_ops *ops)
4935 struct breakpoint *b = create_catchpoint (tempflag, cond_string, ops);
4937 /* FIXME: We should put this information in a breakpoint private data
4939 b->forked_inferior_pid = null_ptid;
4943 create_exec_event_catchpoint (int tempflag, char *cond_string)
4945 struct symtab_and_line sal;
4946 struct breakpoint *b;
4947 int thread = -1; /* All threads. */
4954 b = set_raw_breakpoint (sal, bp_catch_exec);
4955 set_breakpoint_count (breakpoint_count + 1);
4956 b->number = breakpoint_count;
4957 b->cond_string = (cond_string == NULL) ?
4958 NULL : savestring (cond_string, strlen (cond_string));
4960 b->addr_string = NULL;
4961 b->enable_state = bp_enabled;
4962 b->disposition = tempflag ? disp_del : disp_donttouch;
4963 update_global_location_list (1);
4969 hw_breakpoint_used_count (void)
4971 struct breakpoint *b;
4976 if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b))
4984 hw_watchpoint_used_count (enum bptype type, int *other_type_used)
4986 struct breakpoint *b;
4989 *other_type_used = 0;
4992 if (breakpoint_enabled (b))
4994 if (b->type == type)
4996 else if ((b->type == bp_hardware_watchpoint ||
4997 b->type == bp_read_watchpoint ||
4998 b->type == bp_access_watchpoint))
4999 *other_type_used = 1;
5006 disable_watchpoints_before_interactive_call_start (void)
5008 struct breakpoint *b;
5012 if (((b->type == bp_watchpoint)
5013 || (b->type == bp_hardware_watchpoint)
5014 || (b->type == bp_read_watchpoint)
5015 || (b->type == bp_access_watchpoint))
5016 && breakpoint_enabled (b))
5018 b->enable_state = bp_call_disabled;
5019 update_global_location_list (0);
5025 enable_watchpoints_after_interactive_call_stop (void)
5027 struct breakpoint *b;
5031 if (((b->type == bp_watchpoint)
5032 || (b->type == bp_hardware_watchpoint)
5033 || (b->type == bp_read_watchpoint)
5034 || (b->type == bp_access_watchpoint))
5035 && (b->enable_state == bp_call_disabled))
5037 b->enable_state = bp_enabled;
5038 update_global_location_list (1);
5044 /* Set a breakpoint that will evaporate an end of command
5045 at address specified by SAL.
5046 Restrict it to frame FRAME if FRAME is nonzero. */
5049 set_momentary_breakpoint (struct symtab_and_line sal, struct frame_id frame_id,
5052 struct breakpoint *b;
5053 b = set_raw_breakpoint (sal, type);
5054 b->enable_state = bp_enabled;
5055 b->disposition = disp_donttouch;
5056 b->frame_id = frame_id;
5058 /* If we're debugging a multi-threaded program, then we
5059 want momentary breakpoints to be active in only a
5060 single thread of control. */
5061 if (in_thread_list (inferior_ptid))
5062 b->thread = pid_to_thread_id (inferior_ptid);
5064 update_global_location_list_nothrow (1);
5070 set_momentary_breakpoint_at_pc (CORE_ADDR pc, enum bptype type)
5072 struct symtab_and_line sal;
5074 sal = find_pc_line (pc, 0);
5076 sal.section = find_pc_overlay (pc);
5077 sal.explicit_pc = 1;
5079 return set_momentary_breakpoint (sal, null_frame_id, type);
5083 /* Tell the user we have just set a breakpoint B. */
5086 mention (struct breakpoint *b)
5089 struct cleanup *old_chain, *ui_out_chain;
5090 struct ui_stream *stb;
5091 struct value_print_options opts;
5093 get_user_print_options (&opts);
5095 stb = ui_out_stream_new (uiout);
5096 old_chain = make_cleanup_ui_out_stream_delete (stb);
5098 /* FIXME: This is misplaced; mention() is called by things (like
5099 hitting a watchpoint) other than breakpoint creation. It should
5100 be possible to clean this up and at the same time replace the
5101 random calls to breakpoint_changed with this hook. */
5102 observer_notify_breakpoint_created (b->number);
5104 if (b->ops != NULL && b->ops->print_mention != NULL)
5105 b->ops->print_mention (b);
5110 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b->number);
5113 ui_out_text (uiout, "Watchpoint ");
5114 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
5115 ui_out_field_int (uiout, "number", b->number);
5116 ui_out_text (uiout, ": ");
5117 print_expression (b->exp, stb->stream);
5118 ui_out_field_stream (uiout, "exp", stb);
5119 do_cleanups (ui_out_chain);
5121 case bp_hardware_watchpoint:
5122 ui_out_text (uiout, "Hardware watchpoint ");
5123 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
5124 ui_out_field_int (uiout, "number", b->number);
5125 ui_out_text (uiout, ": ");
5126 print_expression (b->exp, stb->stream);
5127 ui_out_field_stream (uiout, "exp", stb);
5128 do_cleanups (ui_out_chain);
5130 case bp_read_watchpoint:
5131 ui_out_text (uiout, "Hardware read watchpoint ");
5132 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
5133 ui_out_field_int (uiout, "number", b->number);
5134 ui_out_text (uiout, ": ");
5135 print_expression (b->exp, stb->stream);
5136 ui_out_field_stream (uiout, "exp", stb);
5137 do_cleanups (ui_out_chain);
5139 case bp_access_watchpoint:
5140 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
5141 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
5142 ui_out_field_int (uiout, "number", b->number);
5143 ui_out_text (uiout, ": ");
5144 print_expression (b->exp, stb->stream);
5145 ui_out_field_stream (uiout, "exp", stb);
5146 do_cleanups (ui_out_chain);
5149 if (ui_out_is_mi_like_p (uiout))
5154 if (b->disposition == disp_del)
5155 printf_filtered (_("Temporary breakpoint"));
5157 printf_filtered (_("Breakpoint"));
5158 printf_filtered (_(" %d"), b->number);
5161 case bp_hardware_breakpoint:
5162 if (ui_out_is_mi_like_p (uiout))
5167 printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
5171 case bp_catch_unload:
5172 printf_filtered (_("Catchpoint %d (%s %s)"),
5174 (b->type == bp_catch_load) ? "load" : "unload",
5175 (b->dll_pathname != NULL) ?
5176 b->dll_pathname : "<any library>");
5179 printf_filtered (_("Catchpoint %d (exec)"),
5186 case bp_longjmp_resume:
5187 case bp_step_resume:
5189 case bp_watchpoint_scope:
5190 case bp_shlib_event:
5191 case bp_thread_event:
5192 case bp_overlay_event:
5198 /* i18n: cagney/2005-02-11: Below needs to be merged into a
5202 printf_filtered (_(" (%s) pending."), b->addr_string);
5206 if (opts.addressprint || b->source_file == NULL)
5208 printf_filtered (" at ");
5209 fputs_filtered (paddress (b->loc->address), gdb_stdout);
5212 printf_filtered (": file %s, line %d.",
5213 b->source_file, b->line_number);
5217 struct bp_location *loc = b->loc;
5219 for (; loc; loc = loc->next)
5221 printf_filtered (" (%d locations)", n);
5226 do_cleanups (old_chain);
5227 if (ui_out_is_mi_like_p (uiout))
5229 printf_filtered ("\n");
5233 static struct bp_location *
5234 add_location_to_breakpoint (struct breakpoint *b, enum bptype bptype,
5235 const struct symtab_and_line *sal)
5237 struct bp_location *loc, **tmp;
5239 loc = allocate_bp_location (b, bptype);
5240 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
5243 loc->requested_address = sal->pc;
5244 loc->address = adjust_breakpoint_address (loc->requested_address,
5246 loc->section = sal->section;
5248 set_breakpoint_location_function (loc);
5253 /* Return 1 if LOC is pointing to a permanent breakpoint,
5254 return 0 otherwise. */
5257 bp_loc_is_permanent (struct bp_location *loc)
5261 const gdb_byte *brk;
5262 gdb_byte *target_mem;
5264 gdb_assert (loc != NULL);
5266 addr = loc->address;
5267 brk = gdbarch_breakpoint_from_pc (current_gdbarch, &addr, &len);
5269 target_mem = alloca (len);
5271 if (target_read_memory (loc->address, target_mem, len) == 0
5272 && memcmp (target_mem, brk, len) == 0)
5280 /* Create a breakpoint with SAL as location. Use ADDR_STRING
5281 as textual description of the location, and COND_STRING
5282 as condition expression. */
5285 create_breakpoint (struct symtabs_and_lines sals, char *addr_string,
5287 enum bptype type, enum bpdisp disposition,
5288 int thread, int ignore_count,
5289 struct breakpoint_ops *ops, int from_tty)
5291 struct breakpoint *b = NULL;
5294 if (type == bp_hardware_breakpoint)
5296 int i = hw_breakpoint_used_count ();
5297 int target_resources_ok =
5298 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
5300 if (target_resources_ok == 0)
5301 error (_("No hardware breakpoint support in the target."));
5302 else if (target_resources_ok < 0)
5303 error (_("Hardware breakpoints used exceeds limit."));
5306 for (i = 0; i < sals.nelts; ++i)
5308 struct symtab_and_line sal = sals.sals[i];
5309 struct bp_location *loc;
5312 describe_other_breakpoints (sal.pc, sal.section, thread);
5316 b = set_raw_breakpoint (sal, type);
5317 set_breakpoint_count (breakpoint_count + 1);
5318 b->number = breakpoint_count;
5321 b->cond_string = cond_string;
5322 b->ignore_count = ignore_count;
5323 b->enable_state = bp_enabled;
5324 b->disposition = disposition;
5330 loc = add_location_to_breakpoint (b, type, &sal);
5333 if (bp_loc_is_permanent (loc))
5334 make_breakpoint_permanent (b);
5338 char *arg = b->cond_string;
5339 loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0);
5341 error (_("Garbage %s follows condition"), arg);
5346 b->addr_string = addr_string;
5348 /* addr_string has to be used or breakpoint_re_set will delete
5350 b->addr_string = xstrprintf ("*0x%s", paddr (b->loc->address));
5356 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
5357 elements to fill the void space. */
5358 static void remove_sal (struct symtabs_and_lines *sal, int index_to_remove)
5360 int i = index_to_remove+1;
5361 int last_index = sal->nelts-1;
5363 for (;i <= last_index; ++i)
5364 sal->sals[i-1] = sal->sals[i];
5369 /* If appropriate, obtains all sals that correspond
5370 to the same file and line as SAL. This is done
5371 only if SAL does not have explicit PC and has
5372 line and file information. If we got just a single
5373 expanded sal, return the original.
5375 Otherwise, if SAL.explicit_line is not set, filter out
5376 all sals for which the name of enclosing function
5377 is different from SAL. This makes sure that if we have
5378 breakpoint originally set in template instantiation, say
5379 foo<int>(), we won't expand SAL to locations at the same
5380 line in all existing instantiations of 'foo'.
5383 struct symtabs_and_lines
5384 expand_line_sal_maybe (struct symtab_and_line sal)
5386 struct symtabs_and_lines expanded;
5387 CORE_ADDR original_pc = sal.pc;
5388 char *original_function = NULL;
5392 /* If we have explicit pc, don't expand.
5393 If we have no line number, we can't expand. */
5394 if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL)
5397 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
5398 expanded.sals[0] = sal;
5403 find_pc_partial_function (original_pc, &original_function, NULL, NULL);
5405 expanded = expand_line_sal (sal);
5406 if (expanded.nelts == 1)
5408 /* We had one sal, we got one sal. Without futher
5409 processing, just return the original sal. */
5410 xfree (expanded.sals);
5412 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
5413 sal.pc = original_pc;
5414 expanded.sals[0] = sal;
5418 if (!sal.explicit_line)
5420 CORE_ADDR func_addr, func_end;
5421 for (i = 0; i < expanded.nelts; ++i)
5423 CORE_ADDR pc = expanded.sals[i].pc;
5424 char *this_function;
5425 if (find_pc_partial_function (pc, &this_function,
5426 &func_addr, &func_end))
5428 if (this_function &&
5429 strcmp (this_function, original_function) != 0)
5431 remove_sal (&expanded, i);
5434 else if (func_addr == pc)
5436 /* We're at beginning of a function, and should
5438 struct symbol *sym = find_pc_function (pc);
5440 expanded.sals[i] = find_function_start_sal (sym, 1);
5443 = gdbarch_skip_prologue (current_gdbarch, pc);
5450 if (expanded.nelts <= 1)
5452 /* This is un ugly workaround. If we get zero
5453 expanded sals then something is really wrong.
5454 Fix that by returnign the original sal. */
5455 xfree (expanded.sals);
5457 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
5458 sal.pc = original_pc;
5459 expanded.sals[0] = sal;
5466 for (i = 0; i < expanded.nelts; ++i)
5467 if (expanded.sals[i].pc == original_pc)
5478 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5479 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5480 value. COND_STRING, if not NULL, specified the condition to be
5481 used for all breakpoints. Essentially the only case where
5482 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
5483 function. In that case, it's still not possible to specify
5484 separate conditions for different overloaded functions, so
5485 we take just a single condition string.
5487 NOTE: If the function succeeds, the caller is expected to cleanup
5488 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
5489 array contents). If the function fails (error() is called), the
5490 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5491 COND and SALS arrays and each of those arrays contents. */
5494 create_breakpoints (struct symtabs_and_lines sals, char **addr_string,
5496 enum bptype type, enum bpdisp disposition,
5497 int thread, int ignore_count,
5498 struct breakpoint_ops *ops, int from_tty)
5501 for (i = 0; i < sals.nelts; ++i)
5503 struct symtabs_and_lines expanded =
5504 expand_line_sal_maybe (sals.sals[i]);
5506 create_breakpoint (expanded, addr_string[i],
5507 cond_string, type, disposition,
5508 thread, ignore_count, ops, from_tty);
5511 update_global_location_list (1);
5514 /* Parse ARG which is assumed to be a SAL specification possibly
5515 followed by conditionals. On return, SALS contains an array of SAL
5516 addresses found. ADDR_STRING contains a vector of (canonical)
5517 address strings. ARG points to the end of the SAL. */
5520 parse_breakpoint_sals (char **address,
5521 struct symtabs_and_lines *sals,
5522 char ***addr_string,
5525 char *addr_start = *address;
5526 *addr_string = NULL;
5527 /* If no arg given, or if first arg is 'if ', use the default
5529 if ((*address) == NULL
5530 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
5532 if (default_breakpoint_valid)
5534 struct symtab_and_line sal;
5535 init_sal (&sal); /* initialize to zeroes */
5536 sals->sals = (struct symtab_and_line *)
5537 xmalloc (sizeof (struct symtab_and_line));
5538 sal.pc = default_breakpoint_address;
5539 sal.line = default_breakpoint_line;
5540 sal.symtab = default_breakpoint_symtab;
5541 sal.section = find_pc_overlay (sal.pc);
5542 sals->sals[0] = sal;
5546 error (_("No default breakpoint address now."));
5550 /* Force almost all breakpoints to be in terms of the
5551 current_source_symtab (which is decode_line_1's default). This
5552 should produce the results we want almost all of the time while
5553 leaving default_breakpoint_* alone.
5554 ObjC: However, don't match an Objective-C method name which
5555 may have a '+' or '-' succeeded by a '[' */
5557 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
5559 if (default_breakpoint_valid
5561 || ((strchr ("+-", (*address)[0]) != NULL)
5562 && ((*address)[1] != '['))))
5563 *sals = decode_line_1 (address, 1, default_breakpoint_symtab,
5564 default_breakpoint_line, addr_string,
5567 *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0,
5568 addr_string, not_found_ptr);
5570 /* For any SAL that didn't have a canonical string, fill one in. */
5571 if (sals->nelts > 0 && *addr_string == NULL)
5572 *addr_string = xcalloc (sals->nelts, sizeof (char **));
5573 if (addr_start != (*address))
5576 for (i = 0; i < sals->nelts; i++)
5578 /* Add the string if not present. */
5579 if ((*addr_string)[i] == NULL)
5580 (*addr_string)[i] = savestring (addr_start, (*address) - addr_start);
5586 /* Convert each SAL into a real PC. Verify that the PC can be
5587 inserted as a breakpoint. If it can't throw an error. */
5590 breakpoint_sals_to_pc (struct symtabs_and_lines *sals,
5594 for (i = 0; i < sals->nelts; i++)
5595 resolve_sal_pc (&sals->sals[i]);
5599 do_captured_parse_breakpoint (struct ui_out *ui, void *data)
5601 struct captured_parse_breakpoint_args *args = data;
5603 parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p,
5604 args->not_found_ptr);
5607 /* Given TOK, a string specification of condition and thread, as
5608 accepted by the 'break' command, extract the condition
5609 string and thread number and set *COND_STRING and *THREAD.
5610 PC identifies the context at which the condition should be parsed.
5611 If no condition is found, *COND_STRING is set to NULL.
5612 If no thread is found, *THREAD is set to -1. */
5614 find_condition_and_thread (char *tok, CORE_ADDR pc,
5615 char **cond_string, int *thread)
5617 *cond_string = NULL;
5623 char *cond_start = NULL;
5624 char *cond_end = NULL;
5625 while (*tok == ' ' || *tok == '\t')
5630 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
5633 toklen = end_tok - tok;
5635 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
5637 tok = cond_start = end_tok + 1;
5638 parse_exp_1 (&tok, block_for_pc (pc), 0);
5640 *cond_string = savestring (cond_start,
5641 cond_end - cond_start);
5643 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
5649 *thread = strtol (tok, &tok, 0);
5651 error (_("Junk after thread keyword."));
5652 if (!valid_thread_id (*thread))
5653 error (_("Unknown thread %d."), *thread);
5656 error (_("Junk at end of arguments."));
5660 /* Set a breakpoint. This function is shared between
5661 CLI and MI functions for setting a breakpoint.
5662 This function has two major modes of operations,
5663 selected by the PARSE_CONDITION_AND_THREAD parameter.
5664 If non-zero, the function will parse arg, extracting
5665 breakpoint location, address and thread. Otherwise,
5666 ARG is just the location of breakpoint, with condition
5667 and thread specified by the COND_STRING and THREAD
5671 break_command_really (char *arg, char *cond_string, int thread,
5672 int parse_condition_and_thread,
5673 int tempflag, int hardwareflag,
5675 enum auto_boolean pending_break_support,
5676 struct breakpoint_ops *ops,
5679 struct gdb_exception e;
5680 struct symtabs_and_lines sals;
5681 struct symtab_and_line pending_sal;
5684 char *addr_start = arg;
5686 struct cleanup *old_chain;
5687 struct cleanup *breakpoint_chain = NULL;
5688 struct captured_parse_breakpoint_args parse_args;
5697 parse_args.arg_p = &arg;
5698 parse_args.sals_p = &sals;
5699 parse_args.addr_string_p = &addr_string;
5700 parse_args.not_found_ptr = ¬_found;
5702 e = catch_exception (uiout, do_captured_parse_breakpoint,
5703 &parse_args, RETURN_MASK_ALL);
5705 /* If caller is interested in rc value from parse, set value. */
5709 throw_exception (e);
5713 case NOT_FOUND_ERROR:
5715 /* If pending breakpoint support is turned off, throw
5718 if (pending_break_support == AUTO_BOOLEAN_FALSE)
5719 throw_exception (e);
5721 exception_print (gdb_stderr, e);
5723 /* If pending breakpoint support is auto query and the user
5724 selects no, then simply return the error code. */
5725 if (pending_break_support == AUTO_BOOLEAN_AUTO &&
5726 !nquery ("Make breakpoint pending on future shared library load? "))
5729 /* At this point, either the user was queried about setting
5730 a pending breakpoint and selected yes, or pending
5731 breakpoint behavior is on and thus a pending breakpoint
5732 is defaulted on behalf of the user. */
5733 copy_arg = xstrdup (addr_start);
5734 addr_string = ©_arg;
5736 sals.sals = &pending_sal;
5741 throw_exception (e);
5748 /* Create a chain of things that always need to be cleaned up. */
5749 old_chain = make_cleanup (null_cleanup, 0);
5753 /* Make sure that all storage allocated to SALS gets freed. */
5754 make_cleanup (xfree, sals.sals);
5756 /* Cleanup the addr_string array but not its contents. */
5757 make_cleanup (xfree, addr_string);
5760 /* ----------------------------- SNIP -----------------------------
5761 Anything added to the cleanup chain beyond this point is assumed
5762 to be part of a breakpoint. If the breakpoint create succeeds
5763 then the memory is not reclaimed. */
5764 breakpoint_chain = make_cleanup (null_cleanup, 0);
5766 /* Mark the contents of the addr_string for cleanup. These go on
5767 the breakpoint_chain and only occure if the breakpoint create
5769 for (i = 0; i < sals.nelts; i++)
5771 if (addr_string[i] != NULL)
5772 make_cleanup (xfree, addr_string[i]);
5775 /* Resolve all line numbers to PC's and verify that the addresses
5776 are ok for the target. */
5778 breakpoint_sals_to_pc (&sals, addr_start);
5780 /* Verify that condition can be parsed, before setting any
5781 breakpoints. Allocate a separate condition expression for each
5785 if (parse_condition_and_thread)
5787 /* Here we only parse 'arg' to separate condition
5788 from thread number, so parsing in context of first
5789 sal is OK. When setting the breakpoint we'll
5790 re-parse it in context of each sal. */
5793 find_condition_and_thread (arg, sals.sals[0].pc, &cond_string, &thread);
5795 make_cleanup (xfree, cond_string);
5799 /* Create a private copy of condition string. */
5802 cond_string = xstrdup (cond_string);
5803 make_cleanup (xfree, cond_string);
5806 create_breakpoints (sals, addr_string, cond_string,
5807 hardwareflag ? bp_hardware_breakpoint
5809 tempflag ? disp_del : disp_donttouch,
5810 thread, ignore_count, ops, from_tty);
5814 struct symtab_and_line sal = {0};
5815 struct breakpoint *b;
5817 make_cleanup (xfree, copy_arg);
5819 b = set_raw_breakpoint_without_location (hardwareflag
5820 ? bp_hardware_breakpoint
5822 set_breakpoint_count (breakpoint_count + 1);
5823 b->number = breakpoint_count;
5825 b->addr_string = addr_string[0];
5826 b->cond_string = NULL;
5827 b->ignore_count = ignore_count;
5828 b->disposition = tempflag ? disp_del : disp_donttouch;
5829 b->condition_not_parsed = 1;
5832 update_global_location_list (1);
5837 warning (_("Multiple breakpoints were set.\n"
5838 "Use the \"delete\" command to delete unwanted breakpoints."));
5839 /* That's it. Discard the cleanups for data inserted into the
5841 discard_cleanups (breakpoint_chain);
5842 /* But cleanup everything else. */
5843 do_cleanups (old_chain);
5846 /* Set a breakpoint.
5847 ARG is a string describing breakpoint address,
5848 condition, and thread.
5849 FLAG specifies if a breakpoint is hardware on,
5850 and if breakpoint is temporary, using BP_HARDWARE_FLAG
5854 break_command_1 (char *arg, int flag, int from_tty)
5856 int hardwareflag = flag & BP_HARDWAREFLAG;
5857 int tempflag = flag & BP_TEMPFLAG;
5859 break_command_really (arg,
5860 NULL, 0, 1 /* parse arg */,
5861 tempflag, hardwareflag,
5862 0 /* Ignore count */,
5863 pending_break_support,
5864 NULL /* breakpoint_ops */,
5870 set_breakpoint (char *address, char *condition,
5871 int hardwareflag, int tempflag,
5872 int thread, int ignore_count,
5875 break_command_really (address, condition, thread,
5876 0 /* condition and thread are valid. */,
5877 tempflag, hardwareflag,
5880 ? AUTO_BOOLEAN_TRUE : AUTO_BOOLEAN_FALSE,
5884 /* Adjust SAL to the first instruction past the function prologue.
5885 The end of the prologue is determined using the line table from
5886 the debugging information.
5888 If SAL is already past the prologue, then do nothing. */
5891 skip_prologue_sal (struct symtab_and_line *sal)
5893 struct symbol *sym = find_pc_function (sal->pc);
5894 struct symtab_and_line start_sal;
5899 start_sal = find_function_start_sal (sym, 1);
5900 if (sal->pc < start_sal.pc)
5904 /* Helper function for break_command_1 and disassemble_command. */
5907 resolve_sal_pc (struct symtab_and_line *sal)
5911 if (sal->pc == 0 && sal->symtab != NULL)
5913 if (!find_line_pc (sal->symtab, sal->line, &pc))
5914 error (_("No line %d in file \"%s\"."),
5915 sal->line, sal->symtab->filename);
5918 /* If this SAL corresponds to a breakpoint inserted using
5919 a line number, then skip the function prologue if necessary. */
5920 if (sal->explicit_line)
5921 skip_prologue_sal (sal);
5924 if (sal->section == 0 && sal->symtab != NULL)
5926 struct blockvector *bv;
5930 bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab);
5933 sym = block_linkage_function (b);
5936 fixup_symbol_section (sym, sal->symtab->objfile);
5937 sal->section = SYMBOL_OBJ_SECTION (sym);
5941 /* It really is worthwhile to have the section, so we'll just
5942 have to look harder. This case can be executed if we have
5943 line numbers but no functions (as can happen in assembly
5946 struct minimal_symbol *msym;
5948 msym = lookup_minimal_symbol_by_pc (sal->pc);
5950 sal->section = SYMBOL_OBJ_SECTION (msym);
5957 break_command (char *arg, int from_tty)
5959 break_command_1 (arg, 0, from_tty);
5963 tbreak_command (char *arg, int from_tty)
5965 break_command_1 (arg, BP_TEMPFLAG, from_tty);
5969 hbreak_command (char *arg, int from_tty)
5971 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
5975 thbreak_command (char *arg, int from_tty)
5977 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
5981 stop_command (char *arg, int from_tty)
5983 printf_filtered (_("Specify the type of breakpoint to set.\n\
5984 Usage: stop in <function | address>\n\
5985 stop at <line>\n"));
5989 stopin_command (char *arg, int from_tty)
5993 if (arg == (char *) NULL)
5995 else if (*arg != '*')
6000 /* look for a ':'. If this is a line number specification, then
6001 say it is bad, otherwise, it should be an address or
6002 function/method name */
6003 while (*argptr && !hasColon)
6005 hasColon = (*argptr == ':');
6010 badInput = (*argptr != ':'); /* Not a class::method */
6012 badInput = isdigit (*arg); /* a simple line number */
6016 printf_filtered (_("Usage: stop in <function | address>\n"));
6018 break_command_1 (arg, 0, from_tty);
6022 stopat_command (char *arg, int from_tty)
6026 if (arg == (char *) NULL || *arg == '*') /* no line number */
6033 /* look for a ':'. If there is a '::' then get out, otherwise
6034 it is probably a line number. */
6035 while (*argptr && !hasColon)
6037 hasColon = (*argptr == ':');
6042 badInput = (*argptr == ':'); /* we have class::method */
6044 badInput = !isdigit (*arg); /* not a line number */
6048 printf_filtered (_("Usage: stop at <line>\n"));
6050 break_command_1 (arg, 0, from_tty);
6053 /* accessflag: hw_write: watch write,
6054 hw_read: watch read,
6055 hw_access: watch access (read or write) */
6057 watch_command_1 (char *arg, int accessflag, int from_tty)
6059 struct breakpoint *b, *scope_breakpoint = NULL;
6060 struct symtab_and_line sal;
6061 struct expression *exp;
6062 struct block *exp_valid_block;
6063 struct value *val, *mark;
6064 struct frame_info *frame;
6065 struct frame_info *prev_frame = NULL;
6066 char *exp_start = NULL;
6067 char *exp_end = NULL;
6068 char *tok, *id_tok_start, *end_tok;
6070 char *cond_start = NULL;
6071 char *cond_end = NULL;
6072 struct expression *cond = NULL;
6073 int i, other_type_used, target_resources_ok = 0;
6074 enum bptype bp_type;
6078 init_sal (&sal); /* initialize to zeroes */
6080 /* Make sure that we actually have parameters to parse. */
6081 if (arg != NULL && arg[0] != '\0')
6083 toklen = strlen (arg); /* Size of argument list. */
6085 /* Points tok to the end of the argument list. */
6086 tok = arg + toklen - 1;
6088 /* Go backwards in the parameters list. Skip the last parameter.
6089 If we're expecting a 'thread <thread_num>' parameter, this should
6090 be the thread identifier. */
6091 while (tok > arg && (*tok == ' ' || *tok == '\t'))
6093 while (tok > arg && (*tok != ' ' && *tok != '\t'))
6096 /* Points end_tok to the beginning of the last token. */
6097 id_tok_start = tok + 1;
6099 /* Go backwards in the parameters list. Skip one more parameter.
6100 If we're expecting a 'thread <thread_num>' parameter, we should
6101 reach a "thread" token. */
6102 while (tok > arg && (*tok == ' ' || *tok == '\t'))
6107 while (tok > arg && (*tok != ' ' && *tok != '\t'))
6110 /* Move the pointer forward to skip the whitespace and
6111 calculate the length of the token. */
6113 toklen = end_tok - tok;
6115 if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
6117 /* At this point we've found a "thread" token, which means
6118 the user is trying to set a watchpoint that triggers
6119 only in a specific thread. */
6122 /* Extract the thread ID from the next token. */
6123 thread = strtol (id_tok_start, &endp, 0);
6125 /* Check if the user provided a valid numeric value for the
6127 if (*endp != ' ' && *endp != '\t' && *endp != '\0')
6128 error (_("Invalid thread ID specification %s."), id_tok_start);
6130 /* Check if the thread actually exists. */
6131 if (!valid_thread_id (thread))
6132 error (_("Unknown thread %d."), thread);
6134 /* Truncate the string and get rid of the thread <thread_num>
6135 parameter before the parameter list is parsed by the
6136 evaluate_expression() function. */
6141 /* Parse the rest of the arguments. */
6142 innermost_block = NULL;
6144 exp = parse_exp_1 (&arg, 0, 0);
6146 exp_valid_block = innermost_block;
6147 mark = value_mark ();
6148 fetch_watchpoint_value (exp, &val, NULL, NULL);
6150 release_value (val);
6153 while (*tok == ' ' || *tok == '\t')
6157 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
6160 toklen = end_tok - tok;
6161 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
6163 tok = cond_start = end_tok + 1;
6164 cond = parse_exp_1 (&tok, 0, 0);
6168 error (_("Junk at end of command."));
6170 if (accessflag == hw_read)
6171 bp_type = bp_read_watchpoint;
6172 else if (accessflag == hw_access)
6173 bp_type = bp_access_watchpoint;
6175 bp_type = bp_hardware_watchpoint;
6177 mem_cnt = can_use_hardware_watchpoint (val);
6178 if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
6179 error (_("Expression cannot be implemented with read/access watchpoint."));
6182 i = hw_watchpoint_used_count (bp_type, &other_type_used);
6183 target_resources_ok =
6184 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type, i + mem_cnt,
6186 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
6187 error (_("Target does not support this type of hardware watchpoint."));
6189 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
6190 error (_("Target can only support one kind of HW watchpoint at a time."));
6193 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
6194 watchpoint could not be set. */
6195 if (!mem_cnt || target_resources_ok <= 0)
6196 bp_type = bp_watchpoint;
6198 frame = block_innermost_frame (exp_valid_block);
6200 prev_frame = get_prev_frame (frame);
6204 /* If the expression is "local", then set up a "watchpoint scope"
6205 breakpoint at the point where we've left the scope of the watchpoint
6206 expression. Create the scope breakpoint before the watchpoint, so
6207 that we will encounter it first in bpstat_stop_status. */
6208 if (innermost_block && prev_frame)
6210 scope_breakpoint = create_internal_breakpoint (get_frame_pc (prev_frame),
6211 bp_watchpoint_scope);
6213 scope_breakpoint->enable_state = bp_enabled;
6215 /* Automatically delete the breakpoint when it hits. */
6216 scope_breakpoint->disposition = disp_del;
6218 /* Only break in the proper frame (help with recursion). */
6219 scope_breakpoint->frame_id = get_frame_id (prev_frame);
6221 /* Set the address at which we will stop. */
6222 scope_breakpoint->loc->requested_address
6223 = get_frame_pc (prev_frame);
6224 scope_breakpoint->loc->address
6225 = adjust_breakpoint_address (scope_breakpoint->loc->requested_address,
6226 scope_breakpoint->type);
6229 /* Now set up the breakpoint. */
6230 b = set_raw_breakpoint (sal, bp_type);
6231 set_breakpoint_count (breakpoint_count + 1);
6232 b->number = breakpoint_count;
6234 b->disposition = disp_donttouch;
6236 b->exp_valid_block = exp_valid_block;
6237 b->exp_string = savestring (exp_start, exp_end - exp_start);
6240 b->loc->cond = cond;
6242 b->cond_string = savestring (cond_start, cond_end - cond_start);
6247 b->watchpoint_frame = get_frame_id (frame);
6249 b->watchpoint_frame = null_frame_id;
6251 if (scope_breakpoint != NULL)
6253 /* The scope breakpoint is related to the watchpoint. We will
6254 need to act on them together. */
6255 b->related_breakpoint = scope_breakpoint;
6256 scope_breakpoint->related_breakpoint = b;
6259 value_free_to_mark (mark);
6261 update_global_location_list (1);
6264 /* Return count of locations need to be watched and can be handled
6265 in hardware. If the watchpoint can not be handled
6266 in hardware return zero. */
6269 can_use_hardware_watchpoint (struct value *v)
6271 int found_memory_cnt = 0;
6272 struct value *head = v;
6274 /* Did the user specifically forbid us to use hardware watchpoints? */
6275 if (!can_use_hw_watchpoints)
6278 /* Make sure that the value of the expression depends only upon
6279 memory contents, and values computed from them within GDB. If we
6280 find any register references or function calls, we can't use a
6281 hardware watchpoint.
6283 The idea here is that evaluating an expression generates a series
6284 of values, one holding the value of every subexpression. (The
6285 expression a*b+c has five subexpressions: a, b, a*b, c, and
6286 a*b+c.) GDB's values hold almost enough information to establish
6287 the criteria given above --- they identify memory lvalues,
6288 register lvalues, computed values, etcetera. So we can evaluate
6289 the expression, and then scan the chain of values that leaves
6290 behind to decide whether we can detect any possible change to the
6291 expression's final value using only hardware watchpoints.
6293 However, I don't think that the values returned by inferior
6294 function calls are special in any way. So this function may not
6295 notice that an expression involving an inferior function call
6296 can't be watched with hardware watchpoints. FIXME. */
6297 for (; v; v = value_next (v))
6299 if (VALUE_LVAL (v) == lval_memory)
6302 /* A lazy memory lvalue is one that GDB never needed to fetch;
6303 we either just used its address (e.g., `a' in `a.b') or
6304 we never needed it at all (e.g., `a' in `a,b'). */
6308 /* Ahh, memory we actually used! Check if we can cover
6309 it with hardware watchpoints. */
6310 struct type *vtype = check_typedef (value_type (v));
6312 /* We only watch structs and arrays if user asked for it
6313 explicitly, never if they just happen to appear in a
6314 middle of some value chain. */
6316 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
6317 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
6319 CORE_ADDR vaddr = VALUE_ADDRESS (v) + value_offset (v);
6320 int len = TYPE_LENGTH (value_type (v));
6322 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr, len))
6329 else if (VALUE_LVAL (v) != not_lval
6330 && deprecated_value_modifiable (v) == 0)
6331 return 0; /* ??? What does this represent? */
6332 else if (VALUE_LVAL (v) == lval_register)
6333 return 0; /* cannot watch a register with a HW watchpoint */
6336 /* The expression itself looks suitable for using a hardware
6337 watchpoint, but give the target machine a chance to reject it. */
6338 return found_memory_cnt;
6342 watch_command_wrapper (char *arg, int from_tty)
6344 watch_command (arg, from_tty);
6348 watch_command (char *arg, int from_tty)
6350 watch_command_1 (arg, hw_write, from_tty);
6354 rwatch_command_wrapper (char *arg, int from_tty)
6356 rwatch_command (arg, from_tty);
6360 rwatch_command (char *arg, int from_tty)
6362 watch_command_1 (arg, hw_read, from_tty);
6366 awatch_command_wrapper (char *arg, int from_tty)
6368 awatch_command (arg, from_tty);
6372 awatch_command (char *arg, int from_tty)
6374 watch_command_1 (arg, hw_access, from_tty);
6378 /* Helper routines for the until_command routine in infcmd.c. Here
6379 because it uses the mechanisms of breakpoints. */
6381 struct until_break_command_continuation_args
6383 struct breakpoint *breakpoint;
6384 struct breakpoint *breakpoint2;
6387 /* This function is called by fetch_inferior_event via the
6388 cmd_continuation pointer, to complete the until command. It takes
6389 care of cleaning up the temporary breakpoints set up by the until
6392 until_break_command_continuation (void *arg)
6394 struct until_break_command_continuation_args *a = arg;
6396 delete_breakpoint (a->breakpoint);
6398 delete_breakpoint (a->breakpoint2);
6402 until_break_command (char *arg, int from_tty, int anywhere)
6404 struct symtabs_and_lines sals;
6405 struct symtab_and_line sal;
6406 struct frame_info *frame = get_selected_frame (NULL);
6407 struct frame_info *prev_frame = get_prev_frame (frame);
6408 struct breakpoint *breakpoint;
6409 struct breakpoint *breakpoint2 = NULL;
6410 struct cleanup *old_chain;
6412 clear_proceed_status ();
6414 /* Set a breakpoint where the user wants it and at return from
6417 if (default_breakpoint_valid)
6418 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
6419 default_breakpoint_line, (char ***) NULL, NULL);
6421 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL,
6422 0, (char ***) NULL, NULL);
6424 if (sals.nelts != 1)
6425 error (_("Couldn't get information on specified line."));
6428 xfree (sals.sals); /* malloc'd, so freed */
6431 error (_("Junk at end of arguments."));
6433 resolve_sal_pc (&sal);
6436 /* If the user told us to continue until a specified location,
6437 we don't specify a frame at which we need to stop. */
6438 breakpoint = set_momentary_breakpoint (sal, null_frame_id, bp_until);
6440 /* Otherwise, specify the current frame, because we want to stop only
6441 at the very same frame. */
6442 breakpoint = set_momentary_breakpoint (sal, get_frame_id (frame),
6445 old_chain = make_cleanup_delete_breakpoint (breakpoint);
6447 /* Keep within the current frame, or in frames called by the current
6451 sal = find_pc_line (get_frame_pc (prev_frame), 0);
6452 sal.pc = get_frame_pc (prev_frame);
6453 breakpoint2 = set_momentary_breakpoint (sal, get_frame_id (prev_frame),
6455 make_cleanup_delete_breakpoint (breakpoint2);
6458 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
6460 /* If we are running asynchronously, and proceed call above has actually
6461 managed to start the target, arrange for breakpoints to be
6462 deleted when the target stops. Otherwise, we're already stopped and
6463 delete breakpoints via cleanup chain. */
6465 if (target_can_async_p () && is_running (inferior_ptid))
6467 struct until_break_command_continuation_args *args;
6468 args = xmalloc (sizeof (*args));
6470 args->breakpoint = breakpoint;
6471 args->breakpoint2 = breakpoint2;
6473 discard_cleanups (old_chain);
6474 add_continuation (inferior_thread (),
6475 until_break_command_continuation, args,
6479 do_cleanups (old_chain);
6483 ep_skip_leading_whitespace (char **s)
6485 if ((s == NULL) || (*s == NULL))
6487 while (isspace (**s))
6491 /* This function attempts to parse an optional "if <cond>" clause
6492 from the arg string. If one is not found, it returns NULL.
6494 Else, it returns a pointer to the condition string. (It does not
6495 attempt to evaluate the string against a particular block.) And,
6496 it updates arg to point to the first character following the parsed
6497 if clause in the arg string. */
6500 ep_parse_optional_if_clause (char **arg)
6504 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
6507 /* Skip the "if" keyword. */
6510 /* Skip any extra leading whitespace, and record the start of the
6511 condition string. */
6512 ep_skip_leading_whitespace (arg);
6515 /* Assume that the condition occupies the remainder of the arg string. */
6516 (*arg) += strlen (cond_string);
6521 /* This function attempts to parse an optional filename from the arg
6522 string. If one is not found, it returns NULL.
6524 Else, it returns a pointer to the parsed filename. (This function
6525 makes no attempt to verify that a file of that name exists, or is
6526 accessible.) And, it updates arg to point to the first character
6527 following the parsed filename in the arg string.
6529 Note that clients needing to preserve the returned filename for
6530 future access should copy it to their own buffers. */
6532 ep_parse_optional_filename (char **arg)
6534 static char filename[1024];
6539 if ((*arg_p == '\0') || isspace (*arg_p))
6557 /* Commands to deal with catching events, such as signals, exceptions,
6558 process start/exit, etc. */
6562 catch_fork_temporary, catch_vfork_temporary,
6563 catch_fork_permanent, catch_vfork_permanent
6568 catch_fork_command_1 (char *arg, int from_tty, struct cmd_list_element *command)
6570 char *cond_string = NULL;
6571 catch_fork_kind fork_kind;
6574 fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command);
6575 tempflag = (fork_kind == catch_fork_temporary
6576 || fork_kind == catch_vfork_temporary);
6580 ep_skip_leading_whitespace (&arg);
6582 /* The allowed syntax is:
6584 catch [v]fork if <cond>
6586 First, check if there's an if clause. */
6587 cond_string = ep_parse_optional_if_clause (&arg);
6589 if ((*arg != '\0') && !isspace (*arg))
6590 error (_("Junk at end of arguments."));
6592 /* If this target supports it, create a fork or vfork catchpoint
6593 and enable reporting of such events. */
6596 case catch_fork_temporary:
6597 case catch_fork_permanent:
6598 create_fork_vfork_event_catchpoint (tempflag, cond_string,
6599 &catch_fork_breakpoint_ops);
6601 case catch_vfork_temporary:
6602 case catch_vfork_permanent:
6603 create_fork_vfork_event_catchpoint (tempflag, cond_string,
6604 &catch_vfork_breakpoint_ops);
6607 error (_("unsupported or unknown fork kind; cannot catch it"));
6613 catch_exec_command_1 (char *arg, int from_tty, struct cmd_list_element *command)
6616 char *cond_string = NULL;
6618 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
6622 ep_skip_leading_whitespace (&arg);
6624 /* The allowed syntax is:
6626 catch exec if <cond>
6628 First, check if there's an if clause. */
6629 cond_string = ep_parse_optional_if_clause (&arg);
6631 if ((*arg != '\0') && !isspace (*arg))
6632 error (_("Junk at end of arguments."));
6634 /* If this target supports it, create an exec catchpoint
6635 and enable reporting of such events. */
6636 create_exec_event_catchpoint (tempflag, cond_string);
6640 catch_load_command_1 (char *arg, int from_tty, struct cmd_list_element *command)
6643 char *dll_pathname = NULL;
6644 char *cond_string = NULL;
6646 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
6650 ep_skip_leading_whitespace (&arg);
6652 /* The allowed syntax is:
6654 catch load if <cond>
6655 catch load <filename>
6656 catch load <filename> if <cond>
6658 The user is not allowed to specify the <filename> after an
6661 We'll ignore the pathological case of a file named "if".
6663 First, check if there's an if clause. If so, then there
6664 cannot be a filename. */
6665 cond_string = ep_parse_optional_if_clause (&arg);
6667 /* If there was an if clause, then there cannot be a filename.
6668 Else, there might be a filename and an if clause. */
6669 if (cond_string == NULL)
6671 dll_pathname = ep_parse_optional_filename (&arg);
6672 ep_skip_leading_whitespace (&arg);
6673 cond_string = ep_parse_optional_if_clause (&arg);
6676 if ((*arg != '\0') && !isspace (*arg))
6677 error (_("Junk at end of arguments."));
6679 /* Create a load breakpoint that only triggers when a load of
6680 the specified dll (or any dll, if no pathname was specified)
6682 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid), tempflag,
6683 dll_pathname, cond_string);
6687 catch_unload_command_1 (char *arg, int from_tty,
6688 struct cmd_list_element *command)
6691 char *dll_pathname = NULL;
6692 char *cond_string = NULL;
6694 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
6698 ep_skip_leading_whitespace (&arg);
6700 /* The allowed syntax is:
6702 catch unload if <cond>
6703 catch unload <filename>
6704 catch unload <filename> if <cond>
6706 The user is not allowed to specify the <filename> after an
6709 We'll ignore the pathological case of a file named "if".
6711 First, check if there's an if clause. If so, then there
6712 cannot be a filename. */
6713 cond_string = ep_parse_optional_if_clause (&arg);
6715 /* If there was an if clause, then there cannot be a filename.
6716 Else, there might be a filename and an if clause. */
6717 if (cond_string == NULL)
6719 dll_pathname = ep_parse_optional_filename (&arg);
6720 ep_skip_leading_whitespace (&arg);
6721 cond_string = ep_parse_optional_if_clause (&arg);
6724 if ((*arg != '\0') && !isspace (*arg))
6725 error (_("Junk at end of arguments."));
6727 /* Create an unload breakpoint that only triggers when an unload of
6728 the specified dll (or any dll, if no pathname was specified)
6730 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid), tempflag,
6731 dll_pathname, cond_string);
6734 static enum print_stop_action
6735 print_exception_catchpoint (struct breakpoint *b)
6737 int bp_temp, bp_throw;
6739 annotate_catchpoint (b->number);
6741 bp_throw = strstr (b->addr_string, "throw") != NULL;
6742 if (b->loc->address != b->loc->requested_address)
6743 breakpoint_adjustment_warning (b->loc->requested_address,
6746 bp_temp = b->loc->owner->disposition == disp_del;
6748 bp_temp ? "Temporary catchpoint "
6750 if (!ui_out_is_mi_like_p (uiout))
6751 ui_out_field_int (uiout, "bkptno", b->number);
6753 bp_throw ? " (exception thrown), "
6754 : " (exception caught), ");
6755 if (ui_out_is_mi_like_p (uiout))
6757 ui_out_field_string (uiout, "reason",
6758 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
6759 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
6760 ui_out_field_int (uiout, "bkptno", b->number);
6762 return PRINT_SRC_AND_LOC;
6766 print_one_exception_catchpoint (struct breakpoint *b, CORE_ADDR *last_addr)
6768 struct value_print_options opts;
6769 get_user_print_options (&opts);
6770 if (opts.addressprint)
6773 if (b->loc == NULL || b->loc->shlib_disabled)
6774 ui_out_field_string (uiout, "addr", "<PENDING>");
6776 ui_out_field_core_addr (uiout, "addr", b->loc->address);
6780 *last_addr = b->loc->address;
6781 if (strstr (b->addr_string, "throw") != NULL)
6782 ui_out_field_string (uiout, "what", "exception throw");
6784 ui_out_field_string (uiout, "what", "exception catch");
6788 print_mention_exception_catchpoint (struct breakpoint *b)
6793 bp_temp = b->loc->owner->disposition == disp_del;
6794 bp_throw = strstr (b->addr_string, "throw") != NULL;
6795 ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ")
6796 : _("Catchpoint "));
6797 ui_out_field_int (uiout, "bkptno", b->number);
6798 ui_out_text (uiout, bp_throw ? _(" (throw)")
6802 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = {
6805 NULL, /* breakpoint_hit */
6806 print_exception_catchpoint,
6807 print_one_exception_catchpoint,
6808 print_mention_exception_catchpoint
6812 handle_gnu_v3_exceptions (int tempflag, char *cond_string,
6813 enum exception_event_kind ex_event, int from_tty)
6815 char *trigger_func_name;
6817 if (ex_event == EX_EVENT_CATCH)
6818 trigger_func_name = "__cxa_begin_catch";
6820 trigger_func_name = "__cxa_throw";
6822 break_command_really (trigger_func_name, cond_string, -1,
6823 0 /* condition and thread are valid. */,
6826 AUTO_BOOLEAN_TRUE /* pending */,
6827 &gnu_v3_exception_catchpoint_ops, from_tty);
6832 /* Deal with "catch catch" and "catch throw" commands */
6835 catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
6836 int tempflag, int from_tty)
6838 char *cond_string = NULL;
6839 struct symtab_and_line *sal = NULL;
6843 ep_skip_leading_whitespace (&arg);
6845 cond_string = ep_parse_optional_if_clause (&arg);
6847 if ((*arg != '\0') && !isspace (*arg))
6848 error (_("Junk at end of arguments."));
6850 if ((ex_event != EX_EVENT_THROW) &&
6851 (ex_event != EX_EVENT_CATCH))
6852 error (_("Unsupported or unknown exception event; cannot catch it"));
6854 if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty))
6857 warning (_("Unsupported with this platform/compiler combination."));
6860 /* Implementation of "catch catch" command. */
6863 catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command)
6865 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
6866 catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty);
6869 /* Implementation of "catch throw" command. */
6872 catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command)
6874 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
6875 catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty);
6878 /* Create a breakpoint struct for Ada exception catchpoints. */
6881 create_ada_exception_breakpoint (struct symtab_and_line sal,
6885 struct expression *cond,
6886 struct breakpoint_ops *ops,
6890 struct breakpoint *b;
6894 describe_other_breakpoints (sal.pc, sal.section, -1);
6895 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
6896 version for exception catchpoints, because two catchpoints
6897 used for different exception names will use the same address.
6898 In this case, a "breakpoint ... also set at..." warning is
6899 unproductive. Besides. the warning phrasing is also a bit
6900 inapropriate, we should use the word catchpoint, and tell
6901 the user what type of catchpoint it is. The above is good
6902 enough for now, though. */
6905 b = set_raw_breakpoint (sal, bp_breakpoint);
6906 set_breakpoint_count (breakpoint_count + 1);
6908 b->enable_state = bp_enabled;
6909 b->disposition = tempflag ? disp_del : disp_donttouch;
6910 b->number = breakpoint_count;
6911 b->ignore_count = 0;
6912 b->loc->cond = cond;
6913 b->addr_string = addr_string;
6914 b->language = language_ada;
6915 b->cond_string = cond_string;
6916 b->exp_string = exp_string;
6921 update_global_location_list (1);
6924 /* Implement the "catch exception" command. */
6927 catch_ada_exception_command (char *arg, int from_tty,
6928 struct cmd_list_element *command)
6931 struct symtab_and_line sal;
6933 char *addr_string = NULL;
6934 char *exp_string = NULL;
6935 char *cond_string = NULL;
6936 struct expression *cond = NULL;
6937 struct breakpoint_ops *ops = NULL;
6939 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
6943 sal = ada_decode_exception_location (arg, &addr_string, &exp_string,
6944 &cond_string, &cond, &ops);
6945 create_ada_exception_breakpoint (sal, addr_string, exp_string,
6946 cond_string, cond, ops, tempflag,
6950 /* Implement the "catch assert" command. */
6953 catch_assert_command (char *arg, int from_tty, struct cmd_list_element *command)
6956 struct symtab_and_line sal;
6957 char *addr_string = NULL;
6958 struct breakpoint_ops *ops = NULL;
6960 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
6964 sal = ada_decode_assert_location (arg, &addr_string, &ops);
6965 create_ada_exception_breakpoint (sal, addr_string, NULL, NULL, NULL, ops,
6966 tempflag, from_tty);
6970 catch_command (char *arg, int from_tty)
6972 error (_("Catch requires an event name."));
6977 tcatch_command (char *arg, int from_tty)
6979 error (_("Catch requires an event name."));
6982 /* Delete breakpoints by address or line. */
6985 clear_command (char *arg, int from_tty)
6987 struct breakpoint *b;
6988 VEC(breakpoint_p) *found = 0;
6991 struct symtabs_and_lines sals;
6992 struct symtab_and_line sal;
6997 sals = decode_line_spec (arg, 1);
7002 sals.sals = (struct symtab_and_line *)
7003 xmalloc (sizeof (struct symtab_and_line));
7004 make_cleanup (xfree, sals.sals);
7005 init_sal (&sal); /* initialize to zeroes */
7006 sal.line = default_breakpoint_line;
7007 sal.symtab = default_breakpoint_symtab;
7008 sal.pc = default_breakpoint_address;
7009 if (sal.symtab == 0)
7010 error (_("No source file specified."));
7018 /* We don't call resolve_sal_pc here. That's not
7019 as bad as it seems, because all existing breakpoints
7020 typically have both file/line and pc set. So, if
7021 clear is given file/line, we can match this to existing
7022 breakpoint without obtaining pc at all.
7024 We only support clearing given the address explicitly
7025 present in breakpoint table. Say, we've set breakpoint
7026 at file:line. There were several PC values for that file:line,
7027 due to optimization, all in one block.
7028 We've picked one PC value. If "clear" is issued with another
7029 PC corresponding to the same file:line, the breakpoint won't
7030 be cleared. We probably can still clear the breakpoint, but
7031 since the other PC value is never presented to user, user
7032 can only find it by guessing, and it does not seem important
7035 /* For each line spec given, delete bps which correspond
7036 to it. Do it in two passes, solely to preserve the current
7037 behavior that from_tty is forced true if we delete more than
7041 for (i = 0; i < sals.nelts; i++)
7043 /* If exact pc given, clear bpts at that pc.
7044 If line given (pc == 0), clear all bpts on specified line.
7045 If defaulting, clear all bpts on default line
7048 defaulting sal.pc != 0 tests to do
7053 1 0 <can't happen> */
7057 /* Find all matching breakpoints and add them to
7062 /* Are we going to delete b? */
7063 if (b->type != bp_none
7064 && b->type != bp_watchpoint
7065 && b->type != bp_hardware_watchpoint
7066 && b->type != bp_read_watchpoint
7067 && b->type != bp_access_watchpoint)
7069 struct bp_location *loc = b->loc;
7070 for (; loc; loc = loc->next)
7072 int pc_match = sal.pc
7073 && (loc->address == sal.pc)
7074 && (!section_is_overlay (loc->section)
7075 || loc->section == sal.section);
7076 int line_match = ((default_match || (0 == sal.pc))
7077 && b->source_file != NULL
7078 && sal.symtab != NULL
7079 && strcmp (b->source_file, sal.symtab->filename) == 0
7080 && b->line_number == sal.line);
7081 if (pc_match || line_match)
7090 VEC_safe_push(breakpoint_p, found, b);
7093 /* Now go thru the 'found' chain and delete them. */
7094 if (VEC_empty(breakpoint_p, found))
7097 error (_("No breakpoint at %s."), arg);
7099 error (_("No breakpoint at this line."));
7102 if (VEC_length(breakpoint_p, found) > 1)
7103 from_tty = 1; /* Always report if deleted more than one */
7106 if (VEC_length(breakpoint_p, found) == 1)
7107 printf_unfiltered (_("Deleted breakpoint "));
7109 printf_unfiltered (_("Deleted breakpoints "));
7111 breakpoints_changed ();
7113 for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++)
7116 printf_unfiltered ("%d ", b->number);
7117 delete_breakpoint (b);
7120 putchar_unfiltered ('\n');
7123 /* Delete breakpoint in BS if they are `delete' breakpoints and
7124 all breakpoints that are marked for deletion, whether hit or not.
7125 This is called after any breakpoint is hit, or after errors. */
7128 breakpoint_auto_delete (bpstat bs)
7130 struct breakpoint *b, *temp;
7132 for (; bs; bs = bs->next)
7133 if (bs->breakpoint_at
7134 && bs->breakpoint_at->owner
7135 && bs->breakpoint_at->owner->disposition == disp_del
7137 delete_breakpoint (bs->breakpoint_at->owner);
7139 ALL_BREAKPOINTS_SAFE (b, temp)
7141 if (b->disposition == disp_del_at_next_stop)
7142 delete_breakpoint (b);
7146 /* If SHOULD_INSERT is true, do not insert any breakpoint locations
7147 into the inferior, only remove already-inserted locations that no
7148 longer should be inserted. Functions that delete a breakpoint or
7149 breakpoints should pass false, so that deleting a breakpoint
7150 doesn't have the side effect of inserting the locations of other
7151 breakpoints that are marked not-inserted, but should_be_inserted
7152 returns true on them.
7154 This behaviour is useful is situations close to tear-down -- e.g.,
7155 after an exec, while the target still has execution, but breakpoint
7156 shadows of the previous executable image should *NOT* be restored
7157 to the new image; or before detaching, where the target still has
7158 execution and wants to delete breakpoints from GDB's lists, and all
7159 breakpoints had already been removed from the inferior. */
7162 update_global_location_list (int should_insert)
7164 struct breakpoint *b;
7165 struct bp_location **next = &bp_location_chain;
7166 struct bp_location *loc;
7167 struct bp_location *loc2;
7168 struct gdb_exception e;
7169 VEC(bp_location_p) *old_locations = NULL;
7173 /* Store old locations for future reference. */
7174 for (loc = bp_location_chain; loc; loc = loc->global_next)
7175 VEC_safe_push (bp_location_p, old_locations, loc);
7177 bp_location_chain = NULL;
7180 for (loc = b->loc; loc; loc = loc->next)
7183 next = &(loc->global_next);
7188 /* Identify bp_location instances that are no longer present in the new
7189 list, and therefore should be freed. Note that it's not necessary that
7190 those locations should be removed from inferior -- if there's another
7191 location at the same address (previously marked as duplicate),
7192 we don't need to remove/insert the location. */
7193 for (ix = 0; VEC_iterate(bp_location_p, old_locations, ix, loc); ++ix)
7195 /* Tells if 'loc' is found amoung the new locations. If not, we
7197 int found_object = 0;
7198 /* Tells if the location should remain inserted in the target. */
7199 int keep_in_target = 0;
7201 for (loc2 = bp_location_chain; loc2; loc2 = loc2->global_next)
7208 /* If this location is no longer present, and inserted, look if there's
7209 maybe a new location at the same address. If so, mark that one
7210 inserted, and don't remove this one. This is needed so that we
7211 don't have a time window where a breakpoint at certain location is not
7216 /* If the location is inserted now, we might have to remove it. */
7218 if (found_object && should_be_inserted (loc))
7220 /* The location is still present in the location list, and still
7221 should be inserted. Don't do anything. */
7226 /* The location is either no longer present, or got disabled.
7227 See if there's another location at the same address, in which
7228 case we don't need to remove this one from the target. */
7229 if (breakpoint_address_is_meaningful (loc->owner))
7230 for (loc2 = bp_location_chain; loc2; loc2 = loc2->global_next)
7232 /* For the sake of should_insert_location. The
7233 call to check_duplicates will fix up this later. */
7234 loc2->duplicate = 0;
7235 if (should_be_inserted (loc2)
7236 && loc2 != loc && loc2->address == loc->address)
7239 loc2->target_info = loc->target_info;
7246 if (!keep_in_target)
7248 if (remove_breakpoint (loc, mark_uninserted))
7250 /* This is just about all we can do. We could keep this
7251 location on the global list, and try to remove it next
7252 time, but there's no particular reason why we will
7255 Note that at this point, loc->owner is still valid,
7256 as delete_breakpoint frees the breakpoint only
7257 after calling us. */
7258 printf_filtered (_("warning: Error removing breakpoint %d\n"),
7259 loc->owner->number);
7267 if (removed && non_stop)
7269 /* This location was removed from the targets. In non-stop mode,
7270 a race condition is possible where we've removed a breakpoint,
7271 but stop events for that breakpoint are already queued and will
7272 arrive later. To suppress spurious SIGTRAPs reported to user,
7273 we keep this breakpoint location for a bit, and will retire it
7274 after we see 3 * thread_count events.
7275 The theory here is that reporting of events should,
7276 "on the average", be fair, so after that many event we'll see
7277 events from all threads that have anything of interest, and no
7278 longer need to keep this breakpoint. This is just a
7279 heuristic, but if it's wrong, we'll report unexpected SIGTRAP,
7280 which is usability issue, but not a correctness problem. */
7281 loc->events_till_retirement = 3 * (thread_count () + 1);
7284 VEC_safe_push (bp_location_p, moribund_locations, loc);
7287 free_bp_location (loc);
7293 check_duplicates (b);
7296 if (breakpoints_always_inserted_mode ()
7298 && target_has_execution)
7299 insert_breakpoint_locations ();
7303 breakpoint_retire_moribund (void)
7305 struct bp_location *loc;
7308 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
7309 if (--(loc->events_till_retirement) == 0)
7311 free_bp_location (loc);
7312 VEC_unordered_remove (bp_location_p, moribund_locations, ix);
7318 update_global_location_list_nothrow (int inserting)
7320 struct gdb_exception e;
7321 TRY_CATCH (e, RETURN_MASK_ERROR)
7322 update_global_location_list (inserting);
7325 /* Clear BPT from a BPS. */
7327 bpstat_remove_breakpoint (bpstat bps, struct breakpoint *bpt)
7330 for (bs = bps; bs; bs = bs->next)
7331 if (bs->breakpoint_at && bs->breakpoint_at->owner == bpt)
7333 bs->breakpoint_at = NULL;
7335 /* bs->commands will be freed later. */
7339 /* Callback for iterate_over_threads. */
7341 bpstat_remove_breakpoint_callback (struct thread_info *th, void *data)
7343 struct breakpoint *bpt = data;
7344 bpstat_remove_breakpoint (th->stop_bpstat, bpt);
7348 /* Delete a breakpoint and clean up all traces of it in the data
7352 delete_breakpoint (struct breakpoint *bpt)
7354 struct breakpoint *b;
7355 struct bp_location *loc, *next;
7357 gdb_assert (bpt != NULL);
7359 /* Has this bp already been deleted? This can happen because multiple
7360 lists can hold pointers to bp's. bpstat lists are especial culprits.
7362 One example of this happening is a watchpoint's scope bp. When the
7363 scope bp triggers, we notice that the watchpoint is out of scope, and
7364 delete it. We also delete its scope bp. But the scope bp is marked
7365 "auto-deleting", and is already on a bpstat. That bpstat is then
7366 checked for auto-deleting bp's, which are deleted.
7368 A real solution to this problem might involve reference counts in bp's,
7369 and/or giving them pointers back to their referencing bpstat's, and
7370 teaching delete_breakpoint to only free a bp's storage when no more
7371 references were extent. A cheaper bandaid was chosen. */
7372 if (bpt->type == bp_none)
7375 observer_notify_breakpoint_deleted (bpt->number);
7377 if (breakpoint_chain == bpt)
7378 breakpoint_chain = bpt->next;
7383 b->next = bpt->next;
7387 free_command_lines (&bpt->commands);
7388 if (bpt->cond_string != NULL)
7389 xfree (bpt->cond_string);
7390 if (bpt->addr_string != NULL)
7391 xfree (bpt->addr_string);
7392 if (bpt->exp != NULL)
7394 if (bpt->exp_string != NULL)
7395 xfree (bpt->exp_string);
7396 if (bpt->val != NULL)
7397 value_free (bpt->val);
7398 if (bpt->source_file != NULL)
7399 xfree (bpt->source_file);
7400 if (bpt->dll_pathname != NULL)
7401 xfree (bpt->dll_pathname);
7402 if (bpt->triggered_dll_pathname != NULL)
7403 xfree (bpt->triggered_dll_pathname);
7404 if (bpt->exec_pathname != NULL)
7405 xfree (bpt->exec_pathname);
7407 /* Be sure no bpstat's are pointing at it after it's been freed. */
7408 /* FIXME, how can we find all bpstat's?
7409 We just check stop_bpstat for now. Note that we cannot just
7410 remove bpstats pointing at bpt from the stop_bpstat list
7411 entirely, as breakpoint commands are associated with the bpstat;
7412 if we remove it here, then the later call to
7413 bpstat_do_actions (&stop_bpstat);
7414 in event-top.c won't do anything, and temporary breakpoints
7415 with commands won't work. */
7417 iterate_over_threads (bpstat_remove_breakpoint_callback, bpt);
7419 /* Now that breakpoint is removed from breakpoint
7420 list, update the global location list. This
7421 will remove locations that used to belong to
7422 this breakpoint. Do this before freeing
7423 the breakpoint itself, since remove_breakpoint
7424 looks at location's owner. It might be better
7425 design to have location completely self-contained,
7426 but it's not the case now. */
7427 update_global_location_list (0);
7430 /* On the chance that someone will soon try again to delete this same
7431 bp, we mark it as deleted before freeing its storage. */
7432 bpt->type = bp_none;
7438 do_delete_breakpoint_cleanup (void *b)
7440 delete_breakpoint (b);
7444 make_cleanup_delete_breakpoint (struct breakpoint *b)
7446 return make_cleanup (do_delete_breakpoint_cleanup, b);
7450 delete_command (char *arg, int from_tty)
7452 struct breakpoint *b, *temp;
7458 int breaks_to_delete = 0;
7460 /* Delete all breakpoints if no argument.
7461 Do not delete internal or call-dummy breakpoints, these
7462 have to be deleted with an explicit breakpoint number argument. */
7465 if (b->type != bp_call_dummy &&
7466 b->type != bp_shlib_event &&
7467 b->type != bp_thread_event &&
7468 b->type != bp_overlay_event &&
7471 breaks_to_delete = 1;
7476 /* Ask user only if there are some breakpoints to delete. */
7478 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
7480 ALL_BREAKPOINTS_SAFE (b, temp)
7482 if (b->type != bp_call_dummy &&
7483 b->type != bp_shlib_event &&
7484 b->type != bp_thread_event &&
7485 b->type != bp_overlay_event &&
7487 delete_breakpoint (b);
7492 map_breakpoint_numbers (arg, delete_breakpoint);
7496 all_locations_are_pending (struct bp_location *loc)
7498 for (; loc; loc = loc->next)
7499 if (!loc->shlib_disabled)
7504 /* Subroutine of update_breakpoint_locations to simplify it.
7505 Return non-zero if multiple fns in list LOC have the same name.
7506 Null names are ignored. */
7509 ambiguous_names_p (struct bp_location *loc)
7511 struct bp_location *l;
7512 htab_t htab = htab_create_alloc (13, htab_hash_string,
7513 (int (*) (const void *, const void *)) streq,
7514 NULL, xcalloc, xfree);
7516 for (l = loc; l != NULL; l = l->next)
7519 const char *name = l->function_name;
7521 /* Allow for some names to be NULL, ignore them. */
7525 slot = (const char **) htab_find_slot (htab, (const void *) name,
7527 /* NOTE: We can assume slot != NULL here because xcalloc never returns
7542 update_breakpoint_locations (struct breakpoint *b,
7543 struct symtabs_and_lines sals)
7547 struct bp_location *existing_locations = b->loc;
7549 /* If there's no new locations, and all existing locations
7550 are pending, don't do anything. This optimizes
7551 the common case where all locations are in the same
7552 shared library, that was unloaded. We'd like to
7553 retain the location, so that when the library
7554 is loaded again, we don't loose the enabled/disabled
7555 status of the individual locations. */
7556 if (all_locations_are_pending (existing_locations) && sals.nelts == 0)
7561 for (i = 0; i < sals.nelts; ++i)
7563 struct bp_location *new_loc =
7564 add_location_to_breakpoint (b, b->type, &(sals.sals[i]));
7566 /* Reparse conditions, they might contain references to the
7568 if (b->cond_string != NULL)
7570 struct gdb_exception e;
7573 TRY_CATCH (e, RETURN_MASK_ERROR)
7575 new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc),
7580 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
7581 b->number, e.message);
7582 new_loc->enabled = 0;
7586 if (b->source_file != NULL)
7587 xfree (b->source_file);
7588 if (sals.sals[i].symtab == NULL)
7589 b->source_file = NULL;
7592 savestring (sals.sals[i].symtab->filename,
7593 strlen (sals.sals[i].symtab->filename));
7595 if (b->line_number == 0)
7596 b->line_number = sals.sals[i].line;
7599 /* Update locations of permanent breakpoints. */
7600 if (b->enable_state == bp_permanent)
7601 make_breakpoint_permanent (b);
7603 /* If possible, carry over 'disable' status from existing breakpoints. */
7605 struct bp_location *e = existing_locations;
7606 /* If there are multiple breakpoints with the same function name,
7607 e.g. for inline functions, comparing function names won't work.
7608 Instead compare pc addresses; this is just a heuristic as things
7609 may have moved, but in practice it gives the correct answer
7610 often enough until a better solution is found. */
7611 int have_ambiguous_names = ambiguous_names_p (b->loc);
7613 for (; e; e = e->next)
7615 if (!e->enabled && e->function_name)
7617 struct bp_location *l = b->loc;
7618 if (have_ambiguous_names)
7620 for (; l; l = l->next)
7621 if (e->address == l->address)
7629 for (; l; l = l->next)
7630 if (l->function_name
7631 && strcmp (e->function_name, l->function_name) == 0)
7641 update_global_location_list (1);
7645 /* Reset a breakpoint given it's struct breakpoint * BINT.
7646 The value we return ends up being the return value from catch_errors.
7647 Unused in this case. */
7650 breakpoint_re_set_one (void *bint)
7652 /* get past catch_errs */
7653 struct breakpoint *b = (struct breakpoint *) bint;
7657 int *not_found_ptr = ¬_found;
7658 struct symtabs_and_lines sals = {};
7659 struct symtabs_and_lines expanded;
7661 enum enable_state save_enable;
7662 struct gdb_exception e;
7668 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7672 case bp_hardware_breakpoint:
7674 case bp_catch_unload:
7675 if (b->addr_string == NULL)
7677 /* Anything without a string can't be re-set. */
7678 delete_breakpoint (b);
7682 set_language (b->language);
7683 input_radix = b->input_radix;
7685 TRY_CATCH (e, RETURN_MASK_ERROR)
7687 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL,
7692 int not_found_and_ok = 0;
7693 /* For pending breakpoints, it's expected that parsing
7694 will fail until the right shared library is loaded.
7695 User has already told to create pending breakpoints and
7696 don't need extra messages. If breakpoint is in bp_shlib_disabled
7697 state, then user already saw the message about that breakpoint
7698 being disabled, and don't want to see more errors. */
7700 && (b->condition_not_parsed
7701 || (b->loc && b->loc->shlib_disabled)
7702 || b->enable_state == bp_disabled))
7703 not_found_and_ok = 1;
7705 if (!not_found_and_ok)
7707 /* We surely don't want to warn about the same breakpoint
7708 10 times. One solution, implemented here, is disable
7709 the breakpoint on error. Another solution would be to
7710 have separate 'warning emitted' flag. Since this
7711 happens only when a binary has changed, I don't know
7712 which approach is better. */
7713 b->enable_state = bp_disabled;
7714 throw_exception (e);
7721 gdb_assert (sals.nelts == 1);
7722 resolve_sal_pc (&sals.sals[0]);
7723 if (b->condition_not_parsed && s && s[0])
7725 char *cond_string = 0;
7727 find_condition_and_thread (s, sals.sals[0].pc,
7728 &cond_string, &thread);
7730 b->cond_string = cond_string;
7732 b->condition_not_parsed = 0;
7734 expanded = expand_line_sal_maybe (sals.sals[0]);
7735 update_breakpoint_locations (b, expanded);
7741 case bp_hardware_watchpoint:
7742 case bp_read_watchpoint:
7743 case bp_access_watchpoint:
7744 /* Watchpoint can be either on expression using entirely global variables,
7745 or it can be on local variables.
7747 Watchpoints of the first kind are never auto-deleted, and even persist
7748 across program restarts. Since they can use variables from shared
7749 libraries, we need to reparse expression as libraries are loaded
7752 Watchpoints on local variables can also change meaning as result
7753 of solib event. For example, if a watchpoint uses both a local and
7754 a global variables in expression, it's a local watchpoint, but
7755 unloading of a shared library will make the expression invalid.
7756 This is not a very common use case, but we still re-evaluate
7757 expression, to avoid surprises to the user.
7759 Note that for local watchpoints, we re-evaluate it only if
7760 watchpoints frame id is still valid. If it's not, it means
7761 the watchpoint is out of scope and will be deleted soon. In fact,
7762 I'm not sure we'll ever be called in this case.
7764 If a local watchpoint's frame id is still valid, then
7765 b->exp_valid_block is likewise valid, and we can safely use it.
7767 Don't do anything about disabled watchpoints, since they will
7768 be reevaluated again when enabled. */
7769 update_watchpoint (b, 1 /* reparse */);
7771 /* We needn't really do anything to reset these, since the mask
7772 that requests them is unaffected by e.g., new libraries being
7779 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type);
7781 /* Delete overlay event breakpoints; they will be reset later by
7782 breakpoint_re_set. */
7783 case bp_overlay_event:
7784 delete_breakpoint (b);
7787 /* This breakpoint is special, it's set up when the inferior
7788 starts and we really don't want to touch it. */
7789 case bp_shlib_event:
7791 /* Like bp_shlib_event, this breakpoint type is special.
7792 Once it is set up, we do not want to touch it. */
7793 case bp_thread_event:
7795 /* Keep temporary breakpoints, which can be encountered when we step
7796 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7797 Otherwise these should have been blown away via the cleanup chain
7798 or by breakpoint_init_inferior when we rerun the executable. */
7801 case bp_watchpoint_scope:
7803 case bp_step_resume:
7805 case bp_longjmp_resume:
7812 /* Re-set all breakpoints after symbols have been re-loaded. */
7814 breakpoint_re_set (void)
7816 struct breakpoint *b, *temp;
7817 enum language save_language;
7818 int save_input_radix;
7820 save_language = current_language->la_language;
7821 save_input_radix = input_radix;
7822 ALL_BREAKPOINTS_SAFE (b, temp)
7824 /* Format possible error msg */
7825 char *message = xstrprintf ("Error in re-setting breakpoint %d: ",
7827 struct cleanup *cleanups = make_cleanup (xfree, message);
7828 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
7829 do_cleanups (cleanups);
7831 set_language (save_language);
7832 input_radix = save_input_radix;
7834 create_overlay_event_breakpoint ("_ovly_debug_event");
7837 /* Reset the thread number of this breakpoint:
7839 - If the breakpoint is for all threads, leave it as-is.
7840 - Else, reset it to the current thread for inferior_ptid. */
7842 breakpoint_re_set_thread (struct breakpoint *b)
7844 if (b->thread != -1)
7846 if (in_thread_list (inferior_ptid))
7847 b->thread = pid_to_thread_id (inferior_ptid);
7851 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7852 If from_tty is nonzero, it prints a message to that effect,
7853 which ends with a period (no newline). */
7856 set_ignore_count (int bptnum, int count, int from_tty)
7858 struct breakpoint *b;
7864 if (b->number == bptnum)
7866 b->ignore_count = count;
7870 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7872 else if (count == 1)
7873 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7876 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7879 breakpoints_changed ();
7880 observer_notify_breakpoint_modified (b->number);
7884 error (_("No breakpoint number %d."), bptnum);
7888 make_breakpoint_silent (struct breakpoint *b)
7890 /* Silence the breakpoint. */
7894 /* Command to set ignore-count of breakpoint N to COUNT. */
7897 ignore_command (char *args, int from_tty)
7903 error_no_arg (_("a breakpoint number"));
7905 num = get_number (&p);
7907 error (_("bad breakpoint number: '%s'"), args);
7909 error (_("Second argument (specified ignore-count) is missing."));
7911 set_ignore_count (num,
7912 longest_to_int (value_as_long (parse_and_eval (p))),
7915 printf_filtered ("\n");
7918 /* Call FUNCTION on each of the breakpoints
7919 whose numbers are given in ARGS. */
7922 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *))
7927 struct breakpoint *b, *tmp;
7931 error_no_arg (_("one or more breakpoint numbers"));
7938 num = get_number_or_range (&p1);
7941 warning (_("bad breakpoint number at or near '%s'"), p);
7945 ALL_BREAKPOINTS_SAFE (b, tmp)
7946 if (b->number == num)
7948 struct breakpoint *related_breakpoint = b->related_breakpoint;
7951 if (related_breakpoint)
7952 function (related_breakpoint);
7956 printf_unfiltered (_("No breakpoint number %d.\n"), num);
7962 static struct bp_location *
7963 find_location_by_number (char *number)
7965 char *dot = strchr (number, '.');
7969 struct breakpoint *b;
7970 struct bp_location *loc;
7975 bp_num = get_number_or_range (&p1);
7977 error (_("Bad breakpoint number '%s'"), number);
7980 if (b->number == bp_num)
7985 if (!b || b->number != bp_num)
7986 error (_("Bad breakpoint number '%s'"), number);
7989 loc_num = get_number_or_range (&p1);
7991 error (_("Bad breakpoint location number '%s'"), number);
7995 for (;loc_num && loc; --loc_num, loc = loc->next)
7998 error (_("Bad breakpoint location number '%s'"), dot+1);
8004 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
8005 If from_tty is nonzero, it prints a message to that effect,
8006 which ends with a period (no newline). */
8009 disable_breakpoint (struct breakpoint *bpt)
8011 /* Never disable a watchpoint scope breakpoint; we want to
8012 hit them when we leave scope so we can delete both the
8013 watchpoint and its scope breakpoint at that time. */
8014 if (bpt->type == bp_watchpoint_scope)
8017 /* You can't disable permanent breakpoints. */
8018 if (bpt->enable_state == bp_permanent)
8021 bpt->enable_state = bp_disabled;
8023 update_global_location_list (0);
8025 observer_notify_breakpoint_modified (bpt->number);
8029 disable_command (char *args, int from_tty)
8031 struct breakpoint *bpt;
8033 ALL_BREAKPOINTS (bpt)
8037 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
8043 case bp_catch_unload:
8045 case bp_hardware_breakpoint:
8047 case bp_hardware_watchpoint:
8048 case bp_read_watchpoint:
8049 case bp_access_watchpoint:
8050 disable_breakpoint (bpt);
8054 else if (strchr (args, '.'))
8056 struct bp_location *loc = find_location_by_number (args);
8059 update_global_location_list (0);
8062 map_breakpoint_numbers (args, disable_breakpoint);
8066 do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition)
8068 int target_resources_ok, other_type_used;
8071 if (bpt->type == bp_hardware_breakpoint)
8074 i = hw_breakpoint_used_count ();
8075 target_resources_ok =
8076 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
8078 if (target_resources_ok == 0)
8079 error (_("No hardware breakpoint support in the target."));
8080 else if (target_resources_ok < 0)
8081 error (_("Hardware breakpoints used exceeds limit."));
8084 if (bpt->type == bp_watchpoint ||
8085 bpt->type == bp_hardware_watchpoint ||
8086 bpt->type == bp_read_watchpoint ||
8087 bpt->type == bp_access_watchpoint)
8089 struct frame_id saved_frame_id;
8091 saved_frame_id = get_frame_id (get_selected_frame (NULL));
8092 if (bpt->exp_valid_block != NULL)
8094 struct frame_info *fr =
8095 fr = frame_find_by_id (bpt->watchpoint_frame);
8098 printf_filtered (_("\
8099 Cannot enable watchpoint %d because the block in which its expression\n\
8100 is valid is not currently in scope.\n"), bpt->number);
8107 value_free (bpt->val);
8108 mark = value_mark ();
8109 fetch_watchpoint_value (bpt->exp, &bpt->val, NULL, NULL);
8111 release_value (bpt->val);
8114 if (bpt->type == bp_hardware_watchpoint ||
8115 bpt->type == bp_read_watchpoint ||
8116 bpt->type == bp_access_watchpoint)
8118 int i = hw_watchpoint_used_count (bpt->type, &other_type_used);
8119 int mem_cnt = can_use_hardware_watchpoint (bpt->val);
8121 /* Hack around 'unused var' error for some targets here */
8122 (void) mem_cnt, (void) i;
8123 target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT (
8124 bpt->type, i + mem_cnt, other_type_used);
8125 /* we can consider of type is bp_hardware_watchpoint, convert to
8126 bp_watchpoint in the following condition */
8127 if (target_resources_ok < 0)
8129 printf_filtered (_("\
8130 Cannot enable watchpoint %d because target watch resources\n\
8131 have been allocated for other watchpoints.\n"), bpt->number);
8132 value_free_to_mark (mark);
8137 select_frame (frame_find_by_id (saved_frame_id));
8138 value_free_to_mark (mark);
8141 if (bpt->enable_state != bp_permanent)
8142 bpt->enable_state = bp_enabled;
8143 bpt->disposition = disposition;
8144 update_global_location_list (1);
8145 breakpoints_changed ();
8147 observer_notify_breakpoint_modified (bpt->number);
8152 enable_breakpoint (struct breakpoint *bpt)
8154 do_enable_breakpoint (bpt, bpt->disposition);
8157 /* The enable command enables the specified breakpoints (or all defined
8158 breakpoints) so they once again become (or continue to be) effective
8159 in stopping the inferior. */
8162 enable_command (char *args, int from_tty)
8164 struct breakpoint *bpt;
8166 ALL_BREAKPOINTS (bpt)
8170 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
8176 case bp_catch_unload:
8178 case bp_hardware_breakpoint:
8180 case bp_hardware_watchpoint:
8181 case bp_read_watchpoint:
8182 case bp_access_watchpoint:
8183 enable_breakpoint (bpt);
8187 else if (strchr (args, '.'))
8189 struct bp_location *loc = find_location_by_number (args);
8192 update_global_location_list (1);
8195 map_breakpoint_numbers (args, enable_breakpoint);
8199 enable_once_breakpoint (struct breakpoint *bpt)
8201 do_enable_breakpoint (bpt, disp_disable);
8205 enable_once_command (char *args, int from_tty)
8207 map_breakpoint_numbers (args, enable_once_breakpoint);
8211 enable_delete_breakpoint (struct breakpoint *bpt)
8213 do_enable_breakpoint (bpt, disp_del);
8217 enable_delete_command (char *args, int from_tty)
8219 map_breakpoint_numbers (args, enable_delete_breakpoint);
8223 set_breakpoint_cmd (char *args, int from_tty)
8228 show_breakpoint_cmd (char *args, int from_tty)
8232 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
8234 struct symtabs_and_lines
8235 decode_line_spec_1 (char *string, int funfirstline)
8237 struct symtabs_and_lines sals;
8239 error (_("Empty line specification."));
8240 if (default_breakpoint_valid)
8241 sals = decode_line_1 (&string, funfirstline,
8242 default_breakpoint_symtab,
8243 default_breakpoint_line,
8244 (char ***) NULL, NULL);
8246 sals = decode_line_1 (&string, funfirstline,
8247 (struct symtab *) NULL, 0, (char ***) NULL, NULL);
8249 error (_("Junk at end of line specification: %s"), string);
8253 /* Create and insert a raw software breakpoint at PC. Return an
8254 identifier, which should be used to remove the breakpoint later.
8255 In general, places which call this should be using something on the
8256 breakpoint chain instead; this function should be eliminated
8260 deprecated_insert_raw_breakpoint (CORE_ADDR pc)
8262 struct bp_target_info *bp_tgt;
8264 bp_tgt = xmalloc (sizeof (struct bp_target_info));
8265 memset (bp_tgt, 0, sizeof (struct bp_target_info));
8267 bp_tgt->placed_address = pc;
8268 if (target_insert_breakpoint (bp_tgt) != 0)
8270 /* Could not insert the breakpoint. */
8278 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
8281 deprecated_remove_raw_breakpoint (void *bp)
8283 struct bp_target_info *bp_tgt = bp;
8286 ret = target_remove_breakpoint (bp_tgt);
8292 /* One (or perhaps two) breakpoints used for software single stepping. */
8294 static void *single_step_breakpoints[2];
8296 /* Create and insert a breakpoint for software single step. */
8299 insert_single_step_breakpoint (CORE_ADDR next_pc)
8303 if (single_step_breakpoints[0] == NULL)
8304 bpt_p = &single_step_breakpoints[0];
8307 gdb_assert (single_step_breakpoints[1] == NULL);
8308 bpt_p = &single_step_breakpoints[1];
8311 /* NOTE drow/2006-04-11: A future improvement to this function would be
8312 to only create the breakpoints once, and actually put them on the
8313 breakpoint chain. That would let us use set_raw_breakpoint. We could
8314 adjust the addresses each time they were needed. Doing this requires
8315 corresponding changes elsewhere where single step breakpoints are
8316 handled, however. So, for now, we use this. */
8318 *bpt_p = deprecated_insert_raw_breakpoint (next_pc);
8320 error (_("Could not insert single-step breakpoint at 0x%s"),
8321 paddr_nz (next_pc));
8324 /* Remove and delete any breakpoints used for software single step. */
8327 remove_single_step_breakpoints (void)
8329 gdb_assert (single_step_breakpoints[0] != NULL);
8331 /* See insert_single_step_breakpoint for more about this deprecated
8333 deprecated_remove_raw_breakpoint (single_step_breakpoints[0]);
8334 single_step_breakpoints[0] = NULL;
8336 if (single_step_breakpoints[1] != NULL)
8338 deprecated_remove_raw_breakpoint (single_step_breakpoints[1]);
8339 single_step_breakpoints[1] = NULL;
8343 /* Check whether a software single-step breakpoint is inserted at PC. */
8346 single_step_breakpoint_inserted_here_p (CORE_ADDR pc)
8350 for (i = 0; i < 2; i++)
8352 struct bp_target_info *bp_tgt = single_step_breakpoints[i];
8353 if (bp_tgt && bp_tgt->placed_address == pc)
8361 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
8362 It is defined as a macro to prevent duplication.
8363 COMMAND should be a string constant containing the name of the command. */
8364 #define BREAK_ARGS_HELP(command) \
8365 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
8366 LOCATION may be a line number, function name, or \"*\" and an address.\n\
8367 If a line number is specified, break at start of code for that line.\n\
8368 If a function is specified, break at start of code for that function.\n\
8369 If an address is specified, break at that exact address.\n\
8370 With no LOCATION, uses current execution address of selected stack frame.\n\
8371 This is useful for breaking on return to a stack frame.\n\
8373 THREADNUM is the number from \"info threads\".\n\
8374 CONDITION is a boolean expression.\n\
8376 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
8378 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
8380 /* List of subcommands for "catch". */
8381 static struct cmd_list_element *catch_cmdlist;
8383 /* List of subcommands for "tcatch". */
8384 static struct cmd_list_element *tcatch_cmdlist;
8386 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
8387 lists, and pass some additional user data to the command function. */
8389 add_catch_command (char *name, char *docstring,
8390 void (*sfunc) (char *args, int from_tty,
8391 struct cmd_list_element *command),
8392 void *user_data_catch,
8393 void *user_data_tcatch)
8395 struct cmd_list_element *command;
8397 command = add_cmd (name, class_breakpoint, NULL, docstring,
8399 set_cmd_sfunc (command, sfunc);
8400 set_cmd_context (command, user_data_catch);
8402 command = add_cmd (name, class_breakpoint, NULL, docstring,
8404 set_cmd_sfunc (command, sfunc);
8405 set_cmd_context (command, user_data_tcatch);
8409 _initialize_breakpoint (void)
8411 static struct cmd_list_element *breakpoint_set_cmdlist;
8412 static struct cmd_list_element *breakpoint_show_cmdlist;
8413 struct cmd_list_element *c;
8415 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
8417 breakpoint_chain = 0;
8418 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
8419 before a breakpoint is set. */
8420 breakpoint_count = 0;
8422 add_com ("ignore", class_breakpoint, ignore_command, _("\
8423 Set ignore-count of breakpoint number N to COUNT.\n\
8424 Usage is `ignore N COUNT'."));
8426 add_com_alias ("bc", "ignore", class_breakpoint, 1);
8428 add_com ("commands", class_breakpoint, commands_command, _("\
8429 Set commands to be executed when a breakpoint is hit.\n\
8430 Give breakpoint number as argument after \"commands\".\n\
8431 With no argument, the targeted breakpoint is the last one set.\n\
8432 The commands themselves follow starting on the next line.\n\
8433 Type a line containing \"end\" to indicate the end of them.\n\
8434 Give \"silent\" as the first line to make the breakpoint silent;\n\
8435 then no output is printed when it is hit, except what the commands print."));
8437 add_com ("condition", class_breakpoint, condition_command, _("\
8438 Specify breakpoint number N to break only if COND is true.\n\
8439 Usage is `condition N COND', where N is an integer and COND is an\n\
8440 expression to be evaluated whenever breakpoint N is reached."));
8442 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
8443 Set a temporary breakpoint.\n\
8444 Like \"break\" except the breakpoint is only temporary,\n\
8445 so it will be deleted when hit. Equivalent to \"break\" followed\n\
8446 by using \"enable delete\" on the breakpoint number.\n\
8448 BREAK_ARGS_HELP ("tbreak")));
8449 set_cmd_completer (c, location_completer);
8451 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
8452 Set a hardware assisted breakpoint.\n\
8453 Like \"break\" except the breakpoint requires hardware support,\n\
8454 some target hardware may not have this support.\n\
8456 BREAK_ARGS_HELP ("hbreak")));
8457 set_cmd_completer (c, location_completer);
8459 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
8460 Set a temporary hardware assisted breakpoint.\n\
8461 Like \"hbreak\" except the breakpoint is only temporary,\n\
8462 so it will be deleted when hit.\n\
8464 BREAK_ARGS_HELP ("thbreak")));
8465 set_cmd_completer (c, location_completer);
8467 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
8468 Enable some breakpoints.\n\
8469 Give breakpoint numbers (separated by spaces) as arguments.\n\
8470 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8471 This is used to cancel the effect of the \"disable\" command.\n\
8472 With a subcommand you can enable temporarily."),
8473 &enablelist, "enable ", 1, &cmdlist);
8475 add_com ("ab", class_breakpoint, enable_command, _("\
8476 Enable some breakpoints.\n\
8477 Give breakpoint numbers (separated by spaces) as arguments.\n\
8478 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8479 This is used to cancel the effect of the \"disable\" command.\n\
8480 With a subcommand you can enable temporarily."));
8482 add_com_alias ("en", "enable", class_breakpoint, 1);
8484 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
8485 Enable some breakpoints.\n\
8486 Give breakpoint numbers (separated by spaces) as arguments.\n\
8487 This is used to cancel the effect of the \"disable\" command.\n\
8488 May be abbreviated to simply \"enable\".\n"),
8489 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
8491 add_cmd ("once", no_class, enable_once_command, _("\
8492 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8493 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8496 add_cmd ("delete", no_class, enable_delete_command, _("\
8497 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8498 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8501 add_cmd ("delete", no_class, enable_delete_command, _("\
8502 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8503 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8506 add_cmd ("once", no_class, enable_once_command, _("\
8507 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8508 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8511 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
8512 Disable some breakpoints.\n\
8513 Arguments are breakpoint numbers with spaces in between.\n\
8514 To disable all breakpoints, give no argument.\n\
8515 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8516 &disablelist, "disable ", 1, &cmdlist);
8517 add_com_alias ("dis", "disable", class_breakpoint, 1);
8518 add_com_alias ("disa", "disable", class_breakpoint, 1);
8520 add_com ("sb", class_breakpoint, disable_command, _("\
8521 Disable some breakpoints.\n\
8522 Arguments are breakpoint numbers with spaces in between.\n\
8523 To disable all breakpoints, give no argument.\n\
8524 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8526 add_cmd ("breakpoints", class_alias, disable_command, _("\
8527 Disable some breakpoints.\n\
8528 Arguments are breakpoint numbers with spaces in between.\n\
8529 To disable all breakpoints, give no argument.\n\
8530 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8531 This command may be abbreviated \"disable\"."),
8534 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
8535 Delete some breakpoints or auto-display expressions.\n\
8536 Arguments are breakpoint numbers with spaces in between.\n\
8537 To delete all breakpoints, give no argument.\n\
8539 Also a prefix command for deletion of other GDB objects.\n\
8540 The \"unset\" command is also an alias for \"delete\"."),
8541 &deletelist, "delete ", 1, &cmdlist);
8542 add_com_alias ("d", "delete", class_breakpoint, 1);
8543 add_com_alias ("del", "delete", class_breakpoint, 1);
8545 add_com ("db", class_breakpoint, delete_command, _("\
8546 Delete some breakpoints.\n\
8547 Arguments are breakpoint numbers with spaces in between.\n\
8548 To delete all breakpoints, give no argument.\n"));
8550 add_cmd ("breakpoints", class_alias, delete_command, _("\
8551 Delete some breakpoints or auto-display expressions.\n\
8552 Arguments are breakpoint numbers with spaces in between.\n\
8553 To delete all breakpoints, give no argument.\n\
8554 This command may be abbreviated \"delete\"."),
8557 add_com ("clear", class_breakpoint, clear_command, _("\
8558 Clear breakpoint at specified line or function.\n\
8559 Argument may be line number, function name, or \"*\" and an address.\n\
8560 If line number is specified, all breakpoints in that line are cleared.\n\
8561 If function is specified, breakpoints at beginning of function are cleared.\n\
8562 If an address is specified, breakpoints at that address are cleared.\n\
8564 With no argument, clears all breakpoints in the line that the selected frame\n\
8567 See also the \"delete\" command which clears breakpoints by number."));
8569 c = add_com ("break", class_breakpoint, break_command, _("\
8570 Set breakpoint at specified line or function.\n"
8571 BREAK_ARGS_HELP ("break")));
8572 set_cmd_completer (c, location_completer);
8574 add_com_alias ("b", "break", class_run, 1);
8575 add_com_alias ("br", "break", class_run, 1);
8576 add_com_alias ("bre", "break", class_run, 1);
8577 add_com_alias ("brea", "break", class_run, 1);
8581 add_com_alias ("ba", "break", class_breakpoint, 1);
8582 add_com_alias ("bu", "ubreak", class_breakpoint, 1);
8587 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
8588 Break in function/address or break at a line in the current file."),
8589 &stoplist, "stop ", 1, &cmdlist);
8590 add_cmd ("in", class_breakpoint, stopin_command,
8591 _("Break in function or address."), &stoplist);
8592 add_cmd ("at", class_breakpoint, stopat_command,
8593 _("Break at a line in the current file."), &stoplist);
8594 add_com ("status", class_info, breakpoints_info, _("\
8595 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8596 The \"Type\" column indicates one of:\n\
8597 \tbreakpoint - normal breakpoint\n\
8598 \twatchpoint - watchpoint\n\
8599 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8600 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8601 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8602 address and file/line number respectively.\n\
8604 Convenience variable \"$_\" and default examine address for \"x\"\n\
8605 are set to the address of the last breakpoint listed unless the command\n\
8606 is prefixed with \"server \".\n\n\
8607 Convenience variable \"$bpnum\" contains the number of the last\n\
8611 add_info ("breakpoints", breakpoints_info, _("\
8612 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8613 The \"Type\" column indicates one of:\n\
8614 \tbreakpoint - normal breakpoint\n\
8615 \twatchpoint - watchpoint\n\
8616 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8617 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8618 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8619 address and file/line number respectively.\n\
8621 Convenience variable \"$_\" and default examine address for \"x\"\n\
8622 are set to the address of the last breakpoint listed unless the command\n\
8623 is prefixed with \"server \".\n\n\
8624 Convenience variable \"$bpnum\" contains the number of the last\n\
8628 add_com ("lb", class_breakpoint, breakpoints_info, _("\
8629 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8630 The \"Type\" column indicates one of:\n\
8631 \tbreakpoint - normal breakpoint\n\
8632 \twatchpoint - watchpoint\n\
8633 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8634 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8635 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8636 address and file/line number respectively.\n\
8638 Convenience variable \"$_\" and default examine address for \"x\"\n\
8639 are set to the address of the last breakpoint listed unless the command\n\
8640 is prefixed with \"server \".\n\n\
8641 Convenience variable \"$bpnum\" contains the number of the last\n\
8644 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
8645 Status of all breakpoints, or breakpoint number NUMBER.\n\
8646 The \"Type\" column indicates one of:\n\
8647 \tbreakpoint - normal breakpoint\n\
8648 \twatchpoint - watchpoint\n\
8649 \tlongjmp - internal breakpoint used to step through longjmp()\n\
8650 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8651 \tuntil - internal breakpoint used by the \"until\" command\n\
8652 \tfinish - internal breakpoint used by the \"finish\" command\n\
8653 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8654 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8655 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8656 address and file/line number respectively.\n\
8658 Convenience variable \"$_\" and default examine address for \"x\"\n\
8659 are set to the address of the last breakpoint listed unless the command\n\
8660 is prefixed with \"server \".\n\n\
8661 Convenience variable \"$bpnum\" contains the number of the last\n\
8663 &maintenanceinfolist);
8665 add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\
8666 Set catchpoints to catch events."),
8667 &catch_cmdlist, "catch ",
8668 0/*allow-unknown*/, &cmdlist);
8670 add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\
8671 Set temporary catchpoints to catch events."),
8672 &tcatch_cmdlist, "tcatch ",
8673 0/*allow-unknown*/, &cmdlist);
8675 /* Add catch and tcatch sub-commands. */
8676 add_catch_command ("catch", _("\
8677 Catch an exception, when caught.\n\
8678 With an argument, catch only exceptions with the given name."),
8679 catch_catch_command,
8682 add_catch_command ("throw", _("\
8683 Catch an exception, when thrown.\n\
8684 With an argument, catch only exceptions with the given name."),
8685 catch_throw_command,
8688 add_catch_command ("fork", _("Catch calls to fork."),
8689 catch_fork_command_1,
8690 (void *) (uintptr_t) catch_fork_permanent,
8691 (void *) (uintptr_t) catch_fork_temporary);
8692 add_catch_command ("vfork", _("Catch calls to vfork."),
8693 catch_fork_command_1,
8694 (void *) (uintptr_t) catch_vfork_permanent,
8695 (void *) (uintptr_t) catch_vfork_temporary);
8696 add_catch_command ("exec", _("Catch calls to exec."),
8697 catch_exec_command_1,
8700 add_catch_command ("load", _("\
8701 Catch library loads.\n\
8702 With an argument, catch only loads of that library."),
8703 catch_load_command_1,
8706 add_catch_command ("unload", _("\
8707 Catch library unloads.\n\
8708 With an argument, catch only unloads of that library."),
8709 catch_unload_command_1,
8712 add_catch_command ("exception", _("\
8713 Catch Ada exceptions, when raised.\n\
8714 With an argument, catch only exceptions with the given name."),
8715 catch_ada_exception_command,
8718 add_catch_command ("assert", _("\
8719 Catch failed Ada assertions, when raised.\n\
8720 With an argument, catch only exceptions with the given name."),
8721 catch_assert_command,
8725 c = add_com ("watch", class_breakpoint, watch_command, _("\
8726 Set a watchpoint for an expression.\n\
8727 A watchpoint stops execution of your program whenever the value of\n\
8728 an expression changes."));
8729 set_cmd_completer (c, expression_completer);
8731 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
8732 Set a read watchpoint for an expression.\n\
8733 A watchpoint stops execution of your program whenever the value of\n\
8734 an expression is read."));
8735 set_cmd_completer (c, expression_completer);
8737 c = add_com ("awatch", class_breakpoint, awatch_command, _("\
8738 Set a watchpoint for an expression.\n\
8739 A watchpoint stops execution of your program whenever the value of\n\
8740 an expression is either read or written."));
8741 set_cmd_completer (c, expression_completer);
8743 add_info ("watchpoints", breakpoints_info,
8744 _("Synonym for ``info breakpoints''."));
8747 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8748 respond to changes - contrary to the description. */
8749 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
8750 &can_use_hw_watchpoints, _("\
8751 Set debugger's willingness to use watchpoint hardware."), _("\
8752 Show debugger's willingness to use watchpoint hardware."), _("\
8753 If zero, gdb will not use hardware for new watchpoints, even if\n\
8754 such is available. (However, any hardware watchpoints that were\n\
8755 created before setting this to nonzero, will continue to use watchpoint\n\
8758 show_can_use_hw_watchpoints,
8759 &setlist, &showlist);
8761 can_use_hw_watchpoints = 1;
8763 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
8764 Breakpoint specific settings\n\
8765 Configure various breakpoint-specific variables such as\n\
8766 pending breakpoint behavior"),
8767 &breakpoint_set_cmdlist, "set breakpoint ",
8768 0/*allow-unknown*/, &setlist);
8769 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
8770 Breakpoint specific settings\n\
8771 Configure various breakpoint-specific variables such as\n\
8772 pending breakpoint behavior"),
8773 &breakpoint_show_cmdlist, "show breakpoint ",
8774 0/*allow-unknown*/, &showlist);
8776 add_setshow_auto_boolean_cmd ("pending", no_class,
8777 &pending_break_support, _("\
8778 Set debugger's behavior regarding pending breakpoints."), _("\
8779 Show debugger's behavior regarding pending breakpoints."), _("\
8780 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8781 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8782 an error. If auto, an unrecognized breakpoint location results in a\n\
8783 user-query to see if a pending breakpoint should be created."),
8785 show_pending_break_support,
8786 &breakpoint_set_cmdlist,
8787 &breakpoint_show_cmdlist);
8789 pending_break_support = AUTO_BOOLEAN_AUTO;
8791 add_setshow_boolean_cmd ("auto-hw", no_class,
8792 &automatic_hardware_breakpoints, _("\
8793 Set automatic usage of hardware breakpoints."), _("\
8794 Show automatic usage of hardware breakpoints."), _("\
8795 If set, the debugger will automatically use hardware breakpoints for\n\
8796 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
8797 a warning will be emitted for such breakpoints."),
8799 show_automatic_hardware_breakpoints,
8800 &breakpoint_set_cmdlist,
8801 &breakpoint_show_cmdlist);
8803 add_setshow_enum_cmd ("always-inserted", class_support,
8804 always_inserted_enums, &always_inserted_mode, _("\
8805 Set mode for inserting breakpoints."), _("\
8806 Show mode for inserting breakpoints."), _("\
8807 When this mode is off, breakpoints are inserted in inferior when it is\n\
8808 resumed, and removed when execution stops. When this mode is on,\n\
8809 breakpoints are inserted immediately and removed only when the user\n\
8810 deletes the breakpoint. When this mode is auto (which is the default),\n\
8811 the behaviour depends on the non-stop setting (see help set non-stop).\n\
8812 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
8813 behaves as if always-inserted mode is on; if gdb is controlling the\n\
8814 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
8816 &show_always_inserted_mode,
8817 &breakpoint_set_cmdlist,
8818 &breakpoint_show_cmdlist);
8820 automatic_hardware_breakpoints = 1;