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"
60 #include "gdb-events.h"
61 #include "mi/mi-common.h"
63 /* Prototypes for local functions. */
65 static void until_break_command_continuation (struct continuation_arg *arg);
67 static void catch_command_1 (char *, int, int);
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, asection *, 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);
143 enum exception_event_kind kind;
146 args_for_catchpoint_enable;
148 static int watchpoint_check (void *);
150 static void maintenance_info_breakpoints (char *, int);
152 static void create_longjmp_breakpoint (char *);
154 static void create_overlay_event_breakpoint (char *);
156 static int hw_breakpoint_used_count (void);
158 static int hw_watchpoint_used_count (enum bptype, int *);
160 static void hbreak_command (char *, int);
162 static void thbreak_command (char *, int);
164 static void watch_command_1 (char *, int, int);
166 static void rwatch_command (char *, int);
168 static void awatch_command (char *, int);
170 static void do_enable_breakpoint (struct breakpoint *, enum bpdisp);
172 static void create_fork_vfork_event_catchpoint (int tempflag,
174 enum bptype bp_kind);
176 static void stop_command (char *arg, int from_tty);
178 static void stopin_command (char *arg, int from_tty);
180 static void stopat_command (char *arg, int from_tty);
182 static char *ep_find_event_name_end (char *arg);
184 static char *ep_parse_optional_if_clause (char **arg);
186 static char *ep_parse_optional_filename (char **arg);
188 static void create_exception_catchpoint (int tempflag, char *cond_string,
189 enum exception_event_kind ex_event,
190 struct symtab_and_line *sal);
192 static void catch_exception_command_1 (enum exception_event_kind ex_event,
193 char *arg, int tempflag, int from_tty);
195 static void tcatch_command (char *arg, int from_tty);
197 static void ep_skip_leading_whitespace (char **s);
199 static int single_step_breakpoint_inserted_here_p (CORE_ADDR pc);
201 static void free_bp_location (struct bp_location *loc);
203 static void mark_breakpoints_out (void);
205 static struct bp_location *
206 allocate_bp_location (struct breakpoint *bpt, enum bptype bp_type);
209 unlink_locations_from_global_list (struct breakpoint *bpt);
212 is_hardware_watchpoint (struct breakpoint *bpt);
215 bpdisp_text (enum bpdisp disp)
217 /* NOTE: the following values are a part of MI protocol and represent
218 values of 'disp' field returned when inferior stops at a breakpoint. */
219 static char *bpdisps[] = {"del", "dstp", "dis", "keep"};
220 return bpdisps[(int) disp];
223 /* Prototypes for exported functions. */
224 /* If FALSE, gdb will not use hardware support for watchpoints, even
225 if such is available. */
226 static int can_use_hw_watchpoints;
229 show_can_use_hw_watchpoints (struct ui_file *file, int from_tty,
230 struct cmd_list_element *c,
233 fprintf_filtered (file, _("\
234 Debugger's willingness to use watchpoint hardware is %s.\n"),
238 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
239 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
240 for unrecognized breakpoint locations.
241 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
242 static enum auto_boolean pending_break_support;
244 show_pending_break_support (struct ui_file *file, int from_tty,
245 struct cmd_list_element *c,
248 fprintf_filtered (file, _("\
249 Debugger's behavior regarding pending breakpoints is %s.\n"),
253 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
254 set with "break" but falling in read-only memory.
255 If 0, gdb will warn about such breakpoints, but won't automatically
256 use hardware breakpoints. */
257 static int automatic_hardware_breakpoints;
259 show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty,
260 struct cmd_list_element *c,
263 fprintf_filtered (file, _("\
264 Automatic usage of hardware breakpoints is %s.\n"),
269 void _initialize_breakpoint (void);
271 extern int addressprint; /* Print machine addresses? */
273 /* Are we executing breakpoint commands? */
274 static int executing_breakpoint_commands;
276 /* Are overlay event breakpoints enabled? */
277 static int overlay_events_enabled;
279 /* Walk the following statement or block through all breakpoints.
280 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
283 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
285 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
286 for (B = breakpoint_chain; \
287 B ? (TMP=B->next, 1): 0; \
290 /* Similar iterators for the low-level breakpoints. */
292 #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->global_next)
294 #define ALL_BP_LOCATIONS_SAFE(B,TMP) \
295 for (B = bp_location_chain; \
296 B ? (TMP=B->global_next, 1): 0; \
299 /* True if breakpoint hit counts should be displayed in breakpoint info. */
301 int show_breakpoint_hit_counts = 1;
303 /* Chains of all breakpoints defined. */
305 struct breakpoint *breakpoint_chain;
307 struct bp_location *bp_location_chain;
309 /* Number of last breakpoint made. */
311 int breakpoint_count;
313 /* Pointer to current exception event record */
314 static struct exception_event_record *current_exception_event;
316 /* This function returns a pointer to the string representation of the
317 pathname of the dynamically-linked library that has just been
320 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
321 or undefined results are guaranteed.
323 This string's contents are only valid immediately after the
324 inferior has stopped in the dynamic linker hook, and becomes
325 invalid as soon as the inferior is continued. Clients should make
326 a copy of this string if they wish to continue the inferior and
327 then access the string. */
329 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
330 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
333 /* This function returns a pointer to the string representation of the
334 pathname of the dynamically-linked library that has just been
337 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
338 TRUE, or undefined results are guaranteed.
340 This string's contents are only valid immediately after the
341 inferior has stopped in the dynamic linker hook, and becomes
342 invalid as soon as the inferior is continued. Clients should make
343 a copy of this string if they wish to continue the inferior and
344 then access the string. */
346 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
347 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
350 /* This function is called by the "catch load" command. It allows the
351 debugger to be notified by the dynamic linker when a specified
352 library file (or any library file, if filename is NULL) is loaded. */
354 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
355 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
356 error (_("catch of library loads not yet implemented on this platform"))
359 /* This function is called by the "catch unload" command. It allows
360 the debugger to be notified by the dynamic linker when a specified
361 library file (or any library file, if filename is NULL) is
364 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
365 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid, tempflag, filename, cond_string) \
366 error (_("catch of library unloads not yet implemented on this platform"))
369 /* Return whether a breakpoint is an active enabled breakpoint. */
371 breakpoint_enabled (struct breakpoint *b)
373 return (b->enable_state == bp_enabled);
376 /* Set breakpoint count to NUM. */
379 set_breakpoint_count (int num)
381 breakpoint_count = num;
382 set_internalvar (lookup_internalvar ("bpnum"),
383 value_from_longest (builtin_type_int, (LONGEST) num));
386 /* Used in run_command to zero the hit count when a new run starts. */
389 clear_breakpoint_hit_counts (void)
391 struct breakpoint *b;
397 /* Default address, symtab and line to put a breakpoint at
398 for "break" command with no arg.
399 if default_breakpoint_valid is zero, the other three are
400 not valid, and "break" with no arg is an error.
402 This set by print_stack_frame, which calls set_default_breakpoint. */
404 int default_breakpoint_valid;
405 CORE_ADDR default_breakpoint_address;
406 struct symtab *default_breakpoint_symtab;
407 int default_breakpoint_line;
409 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
410 Advance *PP after the string and any trailing whitespace.
412 Currently the string can either be a number or "$" followed by the name
413 of a convenience variable. Making it an expression wouldn't work well
414 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
416 If the string is a NULL pointer, that denotes the last breakpoint.
418 TRAILER is a character which can be found after the number; most
419 commonly this is `-'. If you don't want a trailer, use \0. */
421 get_number_trailer (char **pp, int trailer)
423 int retval = 0; /* default */
427 /* Empty line means refer to the last breakpoint. */
428 return breakpoint_count;
431 /* Make a copy of the name, so we can null-terminate it
432 to pass to lookup_internalvar(). */
437 while (isalnum (*p) || *p == '_')
439 varname = (char *) alloca (p - start + 1);
440 strncpy (varname, start, p - start);
441 varname[p - start] = '\0';
442 val = value_of_internalvar (lookup_internalvar (varname));
443 if (TYPE_CODE (value_type (val)) == TYPE_CODE_INT)
444 retval = (int) value_as_long (val);
447 printf_filtered (_("Convenience variable must have integer value.\n"));
455 while (*p >= '0' && *p <= '9')
458 /* There is no number here. (e.g. "cond a == b"). */
460 /* Skip non-numeric token */
461 while (*p && !isspace((int) *p))
463 /* Return zero, which caller must interpret as error. */
469 if (!(isspace (*p) || *p == '\0' || *p == trailer))
471 /* Trailing junk: return 0 and let caller print error msg. */
472 while (!(isspace (*p) || *p == '\0' || *p == trailer))
483 /* Like get_number_trailer, but don't allow a trailer. */
485 get_number (char **pp)
487 return get_number_trailer (pp, '\0');
490 /* Parse a number or a range.
491 * A number will be of the form handled by get_number.
492 * A range will be of the form <number1> - <number2>, and
493 * will represent all the integers between number1 and number2,
496 * While processing a range, this fuction is called iteratively;
497 * At each call it will return the next value in the range.
499 * At the beginning of parsing a range, the char pointer PP will
500 * be advanced past <number1> and left pointing at the '-' token.
501 * Subsequent calls will not advance the pointer until the range
502 * is completed. The call that completes the range will advance
503 * pointer PP past <number2>.
507 get_number_or_range (char **pp)
509 static int last_retval, end_value;
510 static char *end_ptr;
511 static int in_range = 0;
515 /* Default case: pp is pointing either to a solo number,
516 or to the first number of a range. */
517 last_retval = get_number_trailer (pp, '-');
522 /* This is the start of a range (<number1> - <number2>).
523 Skip the '-', parse and remember the second number,
524 and also remember the end of the final token. */
528 while (isspace ((int) *end_ptr))
529 end_ptr++; /* skip white space */
530 end_value = get_number (temp);
531 if (end_value < last_retval)
533 error (_("inverted range"));
535 else if (end_value == last_retval)
537 /* degenerate range (number1 == number2). Advance the
538 token pointer so that the range will be treated as a
547 error (_("negative value"));
550 /* pp points to the '-' that betokens a range. All
551 number-parsing has already been done. Return the next
552 integer value (one greater than the saved previous value).
553 Do not advance the token pointer 'pp' until the end of range
556 if (++last_retval == end_value)
558 /* End of range reached; advance token pointer. */
568 /* condition N EXP -- set break condition of breakpoint N to EXP. */
571 condition_command (char *arg, int from_tty)
573 struct breakpoint *b;
578 error_no_arg (_("breakpoint number"));
581 bnum = get_number (&p);
583 error (_("Bad breakpoint argument: '%s'"), arg);
586 if (b->number == bnum)
588 struct bp_location *loc = b->loc;
589 for (; loc; loc = loc->next)
597 if (b->cond_string != NULL)
598 xfree (b->cond_string);
602 b->cond_string = NULL;
604 printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum);
609 /* I don't know if it matters whether this is the string the user
610 typed in or the decompiled expression. */
611 b->cond_string = savestring (arg, strlen (arg));
612 b->condition_not_parsed = 0;
613 for (loc = b->loc; loc; loc = loc->next)
616 loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0);
618 error (_("Junk at end of expression"));
621 breakpoints_changed ();
622 breakpoint_modify_event (b->number);
626 error (_("No breakpoint number %d."), bnum);
630 commands_command (char *arg, int from_tty)
632 struct breakpoint *b;
635 struct command_line *l;
637 /* If we allowed this, we would have problems with when to
638 free the storage, if we change the commands currently
641 if (executing_breakpoint_commands)
642 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
645 bnum = get_number (&p);
648 error (_("Unexpected extra arguments following breakpoint number."));
651 if (b->number == bnum)
653 char *tmpbuf = xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
655 struct cleanup *cleanups = make_cleanup (xfree, tmpbuf);
656 l = read_command_lines (tmpbuf, from_tty);
657 do_cleanups (cleanups);
658 free_command_lines (&b->commands);
660 breakpoints_changed ();
661 breakpoint_modify_event (b->number);
664 error (_("No breakpoint number %d."), bnum);
667 /* Like commands_command, but instead of reading the commands from
668 input stream, takes them from an already parsed command structure.
670 This is used by cli-script.c to DTRT with breakpoint commands
671 that are part of if and while bodies. */
672 enum command_control_type
673 commands_from_control_command (char *arg, struct command_line *cmd)
675 struct breakpoint *b;
679 /* If we allowed this, we would have problems with when to
680 free the storage, if we change the commands currently
683 if (executing_breakpoint_commands)
684 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
686 /* An empty string for the breakpoint number means the last
687 breakpoint, but get_number expects a NULL pointer. */
692 bnum = get_number (&p);
695 error (_("Unexpected extra arguments following breakpoint number."));
698 if (b->number == bnum)
700 free_command_lines (&b->commands);
701 if (cmd->body_count != 1)
702 error (_("Invalid \"commands\" block structure."));
703 /* We need to copy the commands because if/while will free the
704 list after it finishes execution. */
705 b->commands = copy_command_lines (cmd->body_list[0]);
706 breakpoints_changed ();
707 breakpoint_modify_event (b->number);
708 return simple_control;
710 error (_("No breakpoint number %d."), bnum);
713 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
714 by replacing any memory breakpoints with their shadowed contents. */
717 breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len)
719 struct bp_location *b;
720 CORE_ADDR bp_addr = 0;
726 if (b->owner->type == bp_none)
727 warning (_("reading through apparently deleted breakpoint #%d?"),
730 if (b->loc_type != bp_loc_software_breakpoint)
734 /* Addresses and length of the part of the breakpoint that
736 bp_addr = b->target_info.placed_address;
737 bp_size = b->target_info.shadow_len;
739 /* bp isn't valid, or doesn't shadow memory. */
742 if (bp_addr + bp_size <= memaddr)
743 /* The breakpoint is entirely before the chunk of memory we
747 if (bp_addr >= memaddr + len)
748 /* The breakpoint is entirely after the chunk of memory we are
752 /* Offset within shadow_contents. */
753 if (bp_addr < memaddr)
755 /* Only copy the second part of the breakpoint. */
756 bp_size -= memaddr - bp_addr;
757 bptoffset = memaddr - bp_addr;
761 if (bp_addr + bp_size > memaddr + len)
763 /* Only copy the first part of the breakpoint. */
764 bp_size -= (bp_addr + bp_size) - (memaddr + len);
767 memcpy (buf + bp_addr - memaddr,
768 b->target_info.shadow_contents + bptoffset, bp_size);
773 /* A wrapper function for inserting catchpoints. */
775 insert_catchpoint (struct ui_out *uo, void *args)
777 struct breakpoint *b = (struct breakpoint *) args;
783 target_insert_fork_catchpoint (PIDGET (inferior_ptid));
786 target_insert_vfork_catchpoint (PIDGET (inferior_ptid));
789 target_insert_exec_catchpoint (PIDGET (inferior_ptid));
792 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
798 is_hardware_watchpoint (struct breakpoint *bpt)
800 return (bpt->type == bp_hardware_watchpoint
801 || bpt->type == bp_read_watchpoint
802 || bpt->type == bp_access_watchpoint);
805 /* Find the current value of a watchpoint on EXP. Return the value in
806 *VALP and *RESULTP and the chain of intermediate and final values
807 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
810 If an error occurs while evaluating the expression, *RESULTP will
811 be set to NULL. *RESULTP may be a lazy value, if the result could
812 not be read from memory. It is used to determine whether a value
813 is user-specified (we should watch the whole value) or intermediate
814 (we should watch only the bit used to locate the final value).
816 If the final value, or any intermediate value, could not be read
817 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
818 set to any referenced values. *VALP will never be a lazy value.
819 This is the value which we store in struct breakpoint.
821 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
822 value chain. The caller must free the values individually. If
823 VAL_CHAIN is NULL, all generated values will be left on the value
827 fetch_watchpoint_value (struct expression *exp, struct value **valp,
828 struct value **resultp, struct value **val_chain)
830 struct value *mark, *new_mark, *result;
838 /* Evaluate the expression. */
839 mark = value_mark ();
841 gdb_evaluate_expression (exp, &result);
842 new_mark = value_mark ();
843 if (mark == new_mark)
848 /* Make sure it's not lazy, so that after the target stops again we
849 have a non-lazy previous value to compare with. */
851 && (!value_lazy (result) || gdb_value_fetch_lazy (result)))
856 /* Return the chain of intermediate values. We use this to
857 decide which addresses to watch. */
858 *val_chain = new_mark;
859 value_release_to_mark (mark);
863 /* Assuming that B is a hardware watchpoint:
864 - Reparse watchpoint expression, is REPARSE is non-zero
865 - Evaluate expression and store the result in B->val
866 - Update the list of values that must be watched in B->loc.
868 If the watchpoint is disabled, do nothing. If this is
869 local watchpoint that is out of scope, delete it. */
871 update_watchpoint (struct breakpoint *b, int reparse)
873 int within_current_scope;
874 struct frame_id saved_frame_id;
875 struct bp_location *loc;
878 unlink_locations_from_global_list (b);
879 for (loc = b->loc; loc;)
881 struct bp_location *loc_next = loc->next;
882 remove_breakpoint (loc, mark_uninserted);
888 if (b->disposition == disp_del_at_next_stop)
891 /* Save the current frame's ID so we can restore it after
892 evaluating the watchpoint expression on its own frame. */
893 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
894 took a frame parameter, so that we didn't have to change the
896 saved_frame_id = get_frame_id (get_selected_frame (NULL));
898 /* Determine if the watchpoint is within scope. */
899 if (b->exp_valid_block == NULL)
900 within_current_scope = 1;
903 struct frame_info *fi;
904 fi = frame_find_by_id (b->watchpoint_frame);
905 within_current_scope = (fi != NULL);
906 if (within_current_scope)
910 if (within_current_scope && reparse)
919 b->exp = parse_exp_1 (&s, b->exp_valid_block, 0);
920 /* If the meaning of expression itself changed, the old value is
921 no longer relevant. We don't want to report a watchpoint hit
922 to the user when the old value and the new value may actually
923 be completely different objects. */
929 /* If we failed to parse the expression, for example because
930 it refers to a global variable in a not-yet-loaded shared library,
931 don't try to insert watchpoint. We don't automatically delete
932 such watchpoint, though, since failure to parse expression
933 is different from out-of-scope watchpoint. */
934 if (within_current_scope && b->exp)
936 struct value *val_chain, *v, *result, *next;
938 fetch_watchpoint_value (b->exp, &v, &result, &val_chain);
940 /* Avoid setting b->val if it's already set. The meaning of
941 b->val is 'the last value' user saw, and we should update
942 it only if we reported that last value to user. As it
943 happens, the code that reports it updates b->val directly. */
950 /* Look at each value on the value chain. */
951 for (v = val_chain; v; v = next)
953 /* If it's a memory location, and GDB actually needed
954 its contents to evaluate the expression, then we
955 must watch it. If the first value returned is
956 still lazy, that means an error occurred reading it;
957 watch it anyway in case it becomes readable. */
958 if (VALUE_LVAL (v) == lval_memory
959 && (v == val_chain || ! value_lazy (v)))
961 struct type *vtype = check_typedef (value_type (v));
963 /* We only watch structs and arrays if user asked
964 for it explicitly, never if they just happen to
965 appear in the middle of some value chain. */
967 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
968 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
972 struct bp_location *loc, **tmp;
974 addr = VALUE_ADDRESS (v) + value_offset (v);
975 len = TYPE_LENGTH (value_type (v));
977 if (b->type == bp_read_watchpoint)
979 else if (b->type == bp_access_watchpoint)
982 loc = allocate_bp_location (b, bp_hardware_watchpoint);
983 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
988 loc->watchpoint_type = type;
992 next = value_next (v);
997 if (reparse && b->cond_string != NULL)
999 char *s = b->cond_string;
1002 xfree (b->loc->cond);
1003 b->loc->cond = NULL;
1005 b->loc->cond = parse_exp_1 (&s, b->exp_valid_block, 0);
1008 else if (!within_current_scope)
1010 printf_filtered (_("\
1011 Hardware watchpoint %d deleted because the program has left the block \n\
1012 in which its expression is valid.\n"),
1014 if (b->related_breakpoint)
1015 b->related_breakpoint->disposition = disp_del_at_next_stop;
1016 b->disposition = disp_del_at_next_stop;
1019 /* Restore the selected frame. */
1020 select_frame (frame_find_by_id (saved_frame_id));
1024 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
1025 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
1026 PROCESS_WARNING, and HW_BREAKPOINT_ERROR are used to report problems.
1028 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1029 method for each breakpoint or catchpoint type. */
1031 insert_bp_location (struct bp_location *bpt,
1032 struct ui_file *tmp_error_stream,
1033 int *disabled_breaks, int *process_warning,
1034 int *hw_breakpoint_error)
1038 if (!breakpoint_enabled (bpt->owner))
1041 if (!bpt->enabled || bpt->shlib_disabled || bpt->inserted || bpt->duplicate)
1044 /* Initialize the target-specific information. */
1045 memset (&bpt->target_info, 0, sizeof (bpt->target_info));
1046 bpt->target_info.placed_address = bpt->address;
1048 if (bpt->loc_type == bp_loc_software_breakpoint
1049 || bpt->loc_type == bp_loc_hardware_breakpoint)
1051 if (bpt->owner->type != bp_hardware_breakpoint)
1053 /* If the explicitly specified breakpoint type
1054 is not hardware breakpoint, check the memory map to see
1055 if the breakpoint address is in read only memory or not.
1056 Two important cases are:
1057 - location type is not hardware breakpoint, memory
1058 is readonly. We change the type of the location to
1059 hardware breakpoint.
1060 - location type is hardware breakpoint, memory is read-write.
1061 This means we've previously made the location hardware one, but
1062 then the memory map changed, so we undo.
1064 When breakpoints are removed, remove_breakpoints will
1065 use location types we've just set here, the only possible
1066 problem is that memory map has changed during running program,
1067 but it's not going to work anyway with current gdb. */
1068 struct mem_region *mr
1069 = lookup_mem_region (bpt->target_info.placed_address);
1073 if (automatic_hardware_breakpoints)
1076 enum bp_loc_type new_type;
1078 if (mr->attrib.mode != MEM_RW)
1079 new_type = bp_loc_hardware_breakpoint;
1081 new_type = bp_loc_software_breakpoint;
1083 if (new_type != bpt->loc_type)
1085 static int said = 0;
1086 bpt->loc_type = new_type;
1089 fprintf_filtered (gdb_stdout, _("\
1090 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1095 else if (bpt->loc_type == bp_loc_software_breakpoint
1096 && mr->attrib.mode != MEM_RW)
1097 warning (_("cannot set software breakpoint at readonly address %s"),
1098 paddr (bpt->address));
1102 /* First check to see if we have to handle an overlay. */
1103 if (overlay_debugging == ovly_off
1104 || bpt->section == NULL
1105 || !(section_is_overlay (bpt->section)))
1107 /* No overlay handling: just set the breakpoint. */
1109 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1110 val = target_insert_hw_breakpoint (&bpt->target_info);
1112 val = target_insert_breakpoint (&bpt->target_info);
1116 /* This breakpoint is in an overlay section.
1117 Shall we set a breakpoint at the LMA? */
1118 if (!overlay_events_enabled)
1120 /* Yes -- overlay event support is not active,
1121 so we must try to set a breakpoint at the LMA.
1122 This will not work for a hardware breakpoint. */
1123 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1124 warning (_("hardware breakpoint %d not supported in overlay!"),
1125 bpt->owner->number);
1128 CORE_ADDR addr = overlay_unmapped_address (bpt->address,
1130 /* Set a software (trap) breakpoint at the LMA. */
1131 bpt->overlay_target_info = bpt->target_info;
1132 bpt->overlay_target_info.placed_address = addr;
1133 val = target_insert_breakpoint (&bpt->overlay_target_info);
1135 fprintf_unfiltered (tmp_error_stream,
1136 "Overlay breakpoint %d failed: in ROM?",
1137 bpt->owner->number);
1140 /* Shall we set a breakpoint at the VMA? */
1141 if (section_is_mapped (bpt->section))
1143 /* Yes. This overlay section is mapped into memory. */
1144 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1145 val = target_insert_hw_breakpoint (&bpt->target_info);
1147 val = target_insert_breakpoint (&bpt->target_info);
1151 /* No. This breakpoint will not be inserted.
1152 No error, but do not mark the bp as 'inserted'. */
1159 /* Can't set the breakpoint. */
1160 if (solib_address (bpt->address))
1162 /* See also: disable_breakpoints_in_shlibs. */
1164 bpt->shlib_disabled = 1;
1165 if (!*disabled_breaks)
1167 fprintf_unfiltered (tmp_error_stream,
1168 "Cannot insert breakpoint %d.\n",
1169 bpt->owner->number);
1170 fprintf_unfiltered (tmp_error_stream,
1171 "Temporarily disabling shared library breakpoints:\n");
1173 *disabled_breaks = 1;
1174 fprintf_unfiltered (tmp_error_stream,
1175 "breakpoint #%d\n", bpt->owner->number);
1179 #ifdef ONE_PROCESS_WRITETEXT
1180 *process_warning = 1;
1182 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1184 *hw_breakpoint_error = 1;
1185 fprintf_unfiltered (tmp_error_stream,
1186 "Cannot insert hardware breakpoint %d.\n",
1187 bpt->owner->number);
1191 fprintf_unfiltered (tmp_error_stream,
1192 "Cannot insert breakpoint %d.\n",
1193 bpt->owner->number);
1194 fprintf_filtered (tmp_error_stream,
1195 "Error accessing memory address ");
1196 fputs_filtered (paddress (bpt->address), tmp_error_stream);
1197 fprintf_filtered (tmp_error_stream, ": %s.\n",
1198 safe_strerror (val));
1209 else if (bpt->loc_type == bp_loc_hardware_watchpoint
1210 /* NOTE drow/2003-09-08: This state only exists for removing
1211 watchpoints. It's not clear that it's necessary... */
1212 && bpt->owner->disposition != disp_del_at_next_stop)
1214 val = target_insert_watchpoint (bpt->address,
1216 bpt->watchpoint_type);
1217 bpt->inserted = (val != -1);
1220 else if (bpt->owner->type == bp_catch_fork
1221 || bpt->owner->type == bp_catch_vfork
1222 || bpt->owner->type == bp_catch_exec)
1224 struct gdb_exception e = catch_exception (uiout, insert_catchpoint,
1225 bpt->owner, RETURN_MASK_ERROR);
1226 exception_fprintf (gdb_stderr, e, "warning: inserting catchpoint %d: ",
1227 bpt->owner->number);
1229 bpt->owner->enable_state = bp_disabled;
1233 /* We've already printed an error message if there was a problem
1234 inserting this catchpoint, and we've disabled the catchpoint,
1235 so just return success. */
1242 /* insert_breakpoints is used when starting or continuing the program.
1243 remove_breakpoints is used when the program stops.
1244 Both return zero if successful,
1245 or an `errno' value if could not write the inferior. */
1248 insert_breakpoints (void)
1250 struct breakpoint *bpt;
1251 struct bp_location *b, *temp;
1254 int disabled_breaks = 0;
1255 int hw_breakpoint_error = 0;
1256 int process_warning = 0;
1258 struct ui_file *tmp_error_stream = mem_fileopen ();
1259 make_cleanup_ui_file_delete (tmp_error_stream);
1261 /* Explicitly mark the warning -- this will only be printed if
1262 there was an error. */
1263 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
1265 ALL_BREAKPOINTS (bpt)
1266 if (is_hardware_watchpoint (bpt))
1267 update_watchpoint (bpt, 0 /* don't reparse */);
1269 ALL_BP_LOCATIONS_SAFE (b, temp)
1271 if (!breakpoint_enabled (b->owner))
1274 /* There is no point inserting thread-specific breakpoints if the
1275 thread no longer exists. */
1276 if (b->owner->thread != -1
1277 && !valid_thread_id (b->owner->thread))
1280 val = insert_bp_location (b, tmp_error_stream,
1281 &disabled_breaks, &process_warning,
1282 &hw_breakpoint_error);
1287 /* If we failed to insert all locations of a watchpoint,
1288 remove them, as half-inserted watchpoint is of limited use. */
1289 ALL_BREAKPOINTS (bpt)
1291 int some_failed = 0;
1292 struct bp_location *loc;
1294 if (!is_hardware_watchpoint (bpt))
1297 if (bpt->enable_state != bp_enabled)
1300 for (loc = bpt->loc; loc; loc = loc->next)
1308 for (loc = bpt->loc; loc; loc = loc->next)
1310 remove_breakpoint (loc, mark_uninserted);
1312 hw_breakpoint_error = 1;
1313 fprintf_unfiltered (tmp_error_stream,
1314 "Could not insert hardware watchpoint %d.\n",
1322 /* If a hardware breakpoint or watchpoint was inserted, add a
1323 message about possibly exhausted resources. */
1324 if (hw_breakpoint_error)
1326 fprintf_unfiltered (tmp_error_stream,
1327 "Could not insert hardware breakpoints:\n\
1328 You may have requested too many hardware breakpoints/watchpoints.\n");
1330 #ifdef ONE_PROCESS_WRITETEXT
1331 if (process_warning)
1332 fprintf_unfiltered (tmp_error_stream,
1333 "The same program may be running in another process.");
1335 target_terminal_ours_for_output ();
1336 error_stream (tmp_error_stream);
1341 remove_breakpoints (void)
1343 struct bp_location *b;
1346 ALL_BP_LOCATIONS (b)
1350 val = remove_breakpoint (b, mark_uninserted);
1359 remove_hw_watchpoints (void)
1361 struct bp_location *b;
1364 ALL_BP_LOCATIONS (b)
1366 if (b->inserted && b->loc_type == bp_loc_hardware_watchpoint)
1368 val = remove_breakpoint (b, mark_uninserted);
1377 reattach_breakpoints (int pid)
1379 struct bp_location *b;
1381 struct cleanup *old_chain = save_inferior_ptid ();
1382 struct ui_file *tmp_error_stream = mem_fileopen ();
1383 int dummy1 = 0, dummy2 = 0, dummy3 = 0;
1385 make_cleanup_ui_file_delete (tmp_error_stream);
1387 inferior_ptid = pid_to_ptid (pid);
1388 ALL_BP_LOCATIONS (b)
1393 val = insert_bp_location (b, tmp_error_stream,
1394 &dummy1, &dummy2, &dummy3);
1397 do_cleanups (old_chain);
1402 do_cleanups (old_chain);
1407 update_breakpoints_after_exec (void)
1409 struct breakpoint *b;
1410 struct breakpoint *temp;
1412 /* Doing this first prevents the badness of having delete_breakpoint()
1413 write a breakpoint's current "shadow contents" to lift the bp. That
1414 shadow is NOT valid after an exec()! */
1415 mark_breakpoints_out ();
1417 ALL_BREAKPOINTS_SAFE (b, temp)
1419 /* Solib breakpoints must be explicitly reset after an exec(). */
1420 if (b->type == bp_shlib_event)
1422 delete_breakpoint (b);
1426 /* Thread event breakpoints must be set anew after an exec(),
1427 as must overlay event breakpoints. */
1428 if (b->type == bp_thread_event || b->type == bp_overlay_event)
1430 delete_breakpoint (b);
1434 /* Step-resume breakpoints are meaningless after an exec(). */
1435 if (b->type == bp_step_resume)
1437 delete_breakpoint (b);
1441 /* Don't delete an exec catchpoint, because else the inferior
1442 won't stop when it ought!
1444 Similarly, we probably ought to keep vfork catchpoints, 'cause
1445 on this target, we may not be able to stop when the vfork is
1446 seen, but only when the subsequent exec is seen. (And because
1447 deleting fork catchpoints here but not vfork catchpoints will
1448 seem mysterious to users, keep those too.) */
1449 if ((b->type == bp_catch_exec) ||
1450 (b->type == bp_catch_vfork) ||
1451 (b->type == bp_catch_fork))
1456 /* bp_finish is a special case. The only way we ought to be able
1457 to see one of these when an exec() has happened, is if the user
1458 caught a vfork, and then said "finish". Ordinarily a finish just
1459 carries them to the call-site of the current callee, by setting
1460 a temporary bp there and resuming. But in this case, the finish
1461 will carry them entirely through the vfork & exec.
1463 We don't want to allow a bp_finish to remain inserted now. But
1464 we can't safely delete it, 'cause finish_command has a handle to
1465 the bp on a bpstat, and will later want to delete it. There's a
1466 chance (and I've seen it happen) that if we delete the bp_finish
1467 here, that its storage will get reused by the time finish_command
1468 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1469 We really must allow finish_command to delete a bp_finish.
1471 In the absense of a general solution for the "how do we know
1472 it's safe to delete something others may have handles to?"
1473 problem, what we'll do here is just uninsert the bp_finish, and
1474 let finish_command delete it.
1476 (We know the bp_finish is "doomed" in the sense that it's
1477 momentary, and will be deleted as soon as finish_command sees
1478 the inferior stopped. So it doesn't matter that the bp's
1479 address is probably bogus in the new a.out, unlike e.g., the
1480 solib breakpoints.) */
1482 if (b->type == bp_finish)
1487 /* Without a symbolic address, we have little hope of the
1488 pre-exec() address meaning the same thing in the post-exec()
1490 if (b->addr_string == NULL)
1492 delete_breakpoint (b);
1496 /* FIXME what about longjmp breakpoints? Re-create them here? */
1497 create_overlay_event_breakpoint ("_ovly_debug_event");
1501 detach_breakpoints (int pid)
1503 struct bp_location *b;
1505 struct cleanup *old_chain = save_inferior_ptid ();
1507 if (pid == PIDGET (inferior_ptid))
1508 error (_("Cannot detach breakpoints of inferior_ptid"));
1510 /* Set inferior_ptid; remove_breakpoint uses this global. */
1511 inferior_ptid = pid_to_ptid (pid);
1512 ALL_BP_LOCATIONS (b)
1516 val = remove_breakpoint (b, mark_inserted);
1519 do_cleanups (old_chain);
1524 do_cleanups (old_chain);
1529 remove_breakpoint (struct bp_location *b, insertion_state_t is)
1533 if (b->owner->enable_state == bp_permanent)
1534 /* Permanent breakpoints cannot be inserted or removed. */
1537 if (b->owner->type == bp_none)
1538 warning (_("attempted to remove apparently deleted breakpoint #%d?"),
1541 if (b->loc_type == bp_loc_software_breakpoint
1542 || b->loc_type == bp_loc_hardware_breakpoint)
1544 /* "Normal" instruction breakpoint: either the standard
1545 trap-instruction bp (bp_breakpoint), or a
1546 bp_hardware_breakpoint. */
1548 /* First check to see if we have to handle an overlay. */
1549 if (overlay_debugging == ovly_off
1550 || b->section == NULL
1551 || !(section_is_overlay (b->section)))
1553 /* No overlay handling: just remove the breakpoint. */
1555 if (b->loc_type == bp_loc_hardware_breakpoint)
1556 val = target_remove_hw_breakpoint (&b->target_info);
1558 val = target_remove_breakpoint (&b->target_info);
1562 /* This breakpoint is in an overlay section.
1563 Did we set a breakpoint at the LMA? */
1564 if (!overlay_events_enabled)
1566 /* Yes -- overlay event support is not active, so we
1567 should have set a breakpoint at the LMA. Remove it.
1569 /* Ignore any failures: if the LMA is in ROM, we will
1570 have already warned when we failed to insert it. */
1571 if (b->loc_type == bp_loc_hardware_breakpoint)
1572 target_remove_hw_breakpoint (&b->overlay_target_info);
1574 target_remove_breakpoint (&b->overlay_target_info);
1576 /* Did we set a breakpoint at the VMA?
1577 If so, we will have marked the breakpoint 'inserted'. */
1580 /* Yes -- remove it. Previously we did not bother to
1581 remove the breakpoint if the section had been
1582 unmapped, but let's not rely on that being safe. We
1583 don't know what the overlay manager might do. */
1584 if (b->loc_type == bp_loc_hardware_breakpoint)
1585 val = target_remove_hw_breakpoint (&b->target_info);
1587 /* However, we should remove *software* breakpoints only
1588 if the section is still mapped, or else we overwrite
1589 wrong code with the saved shadow contents. */
1590 else if (section_is_mapped (b->section))
1591 val = target_remove_breakpoint (&b->target_info);
1597 /* No -- not inserted, so no need to remove. No error. */
1603 b->inserted = (is == mark_inserted);
1605 else if (b->loc_type == bp_loc_hardware_watchpoint)
1610 b->inserted = (is == mark_inserted);
1611 val = target_remove_watchpoint (b->address, b->length,
1612 b->watchpoint_type);
1614 /* Failure to remove any of the hardware watchpoints comes here. */
1615 if ((is == mark_uninserted) && (b->inserted))
1616 warning (_("Could not remove hardware watchpoint %d."),
1619 else if ((b->owner->type == bp_catch_fork ||
1620 b->owner->type == bp_catch_vfork ||
1621 b->owner->type == bp_catch_exec)
1622 && breakpoint_enabled (b->owner)
1626 switch (b->owner->type)
1629 val = target_remove_fork_catchpoint (PIDGET (inferior_ptid));
1631 case bp_catch_vfork:
1632 val = target_remove_vfork_catchpoint (PIDGET (inferior_ptid));
1635 val = target_remove_exec_catchpoint (PIDGET (inferior_ptid));
1638 warning (_("Internal error, %s line %d."), __FILE__, __LINE__);
1643 b->inserted = (is == mark_inserted);
1649 /* Clear the "inserted" flag in all breakpoints. */
1652 mark_breakpoints_out (void)
1654 struct bp_location *bpt;
1656 ALL_BP_LOCATIONS (bpt)
1660 /* Clear the "inserted" flag in all breakpoints and delete any
1661 breakpoints which should go away between runs of the program.
1663 Plus other such housekeeping that has to be done for breakpoints
1666 Note: this function gets called at the end of a run (by
1667 generic_mourn_inferior) and when a run begins (by
1668 init_wait_for_inferior). */
1673 breakpoint_init_inferior (enum inf_context context)
1675 struct breakpoint *b, *temp;
1676 struct bp_location *bpt;
1678 ALL_BP_LOCATIONS (bpt)
1681 ALL_BREAKPOINTS_SAFE (b, temp)
1686 case bp_watchpoint_scope:
1688 /* If the call dummy breakpoint is at the entry point it will
1689 cause problems when the inferior is rerun, so we better
1692 Also get rid of scope breakpoints. */
1693 delete_breakpoint (b);
1697 case bp_hardware_watchpoint:
1698 case bp_read_watchpoint:
1699 case bp_access_watchpoint:
1701 /* Likewise for watchpoints on local expressions. */
1702 if (b->exp_valid_block != NULL)
1703 delete_breakpoint (b);
1704 else if (context == inf_starting)
1706 /* Reset val field to force reread of starting value
1707 in insert_breakpoints. */
1709 value_free (b->val);
1720 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1721 exists at PC. It returns ordinary_breakpoint_here if it's an
1722 ordinary breakpoint, or permanent_breakpoint_here if it's a
1723 permanent breakpoint.
1724 - When continuing from a location with an ordinary breakpoint, we
1725 actually single step once before calling insert_breakpoints.
1726 - When continuing from a localion with a permanent breakpoint, we
1727 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1728 the target, to advance the PC past the breakpoint. */
1730 enum breakpoint_here
1731 breakpoint_here_p (CORE_ADDR pc)
1733 const struct bp_location *bpt;
1734 int any_breakpoint_here = 0;
1736 ALL_BP_LOCATIONS (bpt)
1738 if (bpt->loc_type != bp_loc_software_breakpoint
1739 && bpt->loc_type != bp_loc_hardware_breakpoint)
1742 if ((breakpoint_enabled (bpt->owner)
1743 || bpt->owner->enable_state == bp_permanent)
1744 && bpt->address == pc) /* bp is enabled and matches pc */
1746 if (overlay_debugging
1747 && section_is_overlay (bpt->section)
1748 && !section_is_mapped (bpt->section))
1749 continue; /* unmapped overlay -- can't be a match */
1750 else if (bpt->owner->enable_state == bp_permanent)
1751 return permanent_breakpoint_here;
1753 any_breakpoint_here = 1;
1757 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
1761 /* Returns non-zero if there's a breakpoint inserted at PC, which is
1762 inserted using regular breakpoint_chain/bp_location_chain mechanism.
1763 This does not check for single-step breakpoints, which are
1764 inserted and removed using direct target manipulation. */
1767 regular_breakpoint_inserted_here_p (CORE_ADDR pc)
1769 const struct bp_location *bpt;
1771 ALL_BP_LOCATIONS (bpt)
1773 if (bpt->loc_type != bp_loc_software_breakpoint
1774 && bpt->loc_type != bp_loc_hardware_breakpoint)
1778 && bpt->address == pc) /* bp is inserted and matches pc */
1780 if (overlay_debugging
1781 && section_is_overlay (bpt->section)
1782 && !section_is_mapped (bpt->section))
1783 continue; /* unmapped overlay -- can't be a match */
1791 /* Returns non-zero iff there's either regular breakpoint
1792 or a single step breakpoint inserted at PC. */
1795 breakpoint_inserted_here_p (CORE_ADDR pc)
1797 if (regular_breakpoint_inserted_here_p (pc))
1800 if (single_step_breakpoint_inserted_here_p (pc))
1806 /* This function returns non-zero iff there is a software breakpoint
1810 software_breakpoint_inserted_here_p (CORE_ADDR pc)
1812 const struct bp_location *bpt;
1813 int any_breakpoint_here = 0;
1815 ALL_BP_LOCATIONS (bpt)
1817 if (bpt->loc_type != bp_loc_software_breakpoint)
1821 && bpt->address == pc) /* bp is enabled and matches pc */
1823 if (overlay_debugging
1824 && section_is_overlay (bpt->section)
1825 && !section_is_mapped (bpt->section))
1826 continue; /* unmapped overlay -- can't be a match */
1832 /* Also check for software single-step breakpoints. */
1833 if (single_step_breakpoint_inserted_here_p (pc))
1839 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
1840 PC is valid for process/thread PTID. */
1843 breakpoint_thread_match (CORE_ADDR pc, ptid_t ptid)
1845 const struct bp_location *bpt;
1848 thread = pid_to_thread_id (ptid);
1850 ALL_BP_LOCATIONS (bpt)
1852 if (bpt->loc_type != bp_loc_software_breakpoint
1853 && bpt->loc_type != bp_loc_hardware_breakpoint)
1856 if ((breakpoint_enabled (bpt->owner)
1857 || bpt->owner->enable_state == bp_permanent)
1858 && bpt->address == pc
1859 && (bpt->owner->thread == -1 || bpt->owner->thread == thread))
1861 if (overlay_debugging
1862 && section_is_overlay (bpt->section)
1863 && !section_is_mapped (bpt->section))
1864 continue; /* unmapped overlay -- can't be a match */
1874 /* bpstat stuff. External routines' interfaces are documented
1878 ep_is_catchpoint (struct breakpoint *ep)
1881 (ep->type == bp_catch_load)
1882 || (ep->type == bp_catch_unload)
1883 || (ep->type == bp_catch_fork)
1884 || (ep->type == bp_catch_vfork)
1885 || (ep->type == bp_catch_exec);
1887 /* ??rehrauer: Add more kinds here, as are implemented... */
1891 ep_is_shlib_catchpoint (struct breakpoint *ep)
1894 (ep->type == bp_catch_load)
1895 || (ep->type == bp_catch_unload);
1899 bpstat_free (bpstat bs)
1901 if (bs->old_val != NULL)
1902 value_free (bs->old_val);
1903 free_command_lines (&bs->commands);
1907 /* Clear a bpstat so that it says we are not at any breakpoint.
1908 Also free any storage that is part of a bpstat. */
1911 bpstat_clear (bpstat *bsp)
1928 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1929 is part of the bpstat is copied as well. */
1932 bpstat_copy (bpstat bs)
1936 bpstat retval = NULL;
1941 for (; bs != NULL; bs = bs->next)
1943 tmp = (bpstat) xmalloc (sizeof (*tmp));
1944 memcpy (tmp, bs, sizeof (*tmp));
1945 if (bs->commands != NULL)
1946 tmp->commands = copy_command_lines (bs->commands);
1947 if (bs->old_val != NULL)
1948 tmp->old_val = value_copy (bs->old_val);
1951 /* This is the first thing in the chain. */
1961 /* Find the bpstat associated with this breakpoint */
1964 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
1969 for (; bsp != NULL; bsp = bsp->next)
1971 if (bsp->breakpoint_at && bsp->breakpoint_at->owner == breakpoint)
1977 /* Find a step_resume breakpoint associated with this bpstat.
1978 (If there are multiple step_resume bp's on the list, this function
1979 will arbitrarily pick one.)
1981 It is an error to use this function if BPSTAT doesn't contain a
1982 step_resume breakpoint.
1984 See wait_for_inferior's use of this function. */
1986 bpstat_find_step_resume_breakpoint (bpstat bsp)
1990 gdb_assert (bsp != NULL);
1992 current_thread = pid_to_thread_id (inferior_ptid);
1994 for (; bsp != NULL; bsp = bsp->next)
1996 if ((bsp->breakpoint_at != NULL) &&
1997 (bsp->breakpoint_at->owner->type == bp_step_resume) &&
1998 (bsp->breakpoint_at->owner->thread == current_thread ||
1999 bsp->breakpoint_at->owner->thread == -1))
2000 return bsp->breakpoint_at->owner;
2003 internal_error (__FILE__, __LINE__, _("No step_resume breakpoint found."));
2007 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2008 at. *BSP upon return is a bpstat which points to the remaining
2009 breakpoints stopped at (but which is not guaranteed to be good for
2010 anything but further calls to bpstat_num).
2011 Return 0 if passed a bpstat which does not indicate any breakpoints.
2012 Return -1 if stopped at a breakpoint that has been deleted since
2014 Return 1 otherwise. */
2017 bpstat_num (bpstat *bsp, int *num)
2019 struct breakpoint *b;
2022 return 0; /* No more breakpoint values */
2024 /* We assume we'll never have several bpstats that
2025 correspond to a single breakpoint -- otherwise,
2026 this function might return the same number more
2027 than once and this will look ugly. */
2028 b = (*bsp)->breakpoint_at ? (*bsp)->breakpoint_at->owner : NULL;
2029 *bsp = (*bsp)->next;
2031 return -1; /* breakpoint that's been deleted since */
2033 *num = b->number; /* We have its number */
2037 /* Modify BS so that the actions will not be performed. */
2040 bpstat_clear_actions (bpstat bs)
2042 for (; bs != NULL; bs = bs->next)
2044 free_command_lines (&bs->commands);
2045 if (bs->old_val != NULL)
2047 value_free (bs->old_val);
2053 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2055 cleanup_executing_breakpoints (void *ignore)
2057 executing_breakpoint_commands = 0;
2060 /* Execute all the commands associated with all the breakpoints at this
2061 location. Any of these commands could cause the process to proceed
2062 beyond this point, etc. We look out for such changes by checking
2063 the global "breakpoint_proceeded" after each command. */
2066 bpstat_do_actions (bpstat *bsp)
2069 struct cleanup *old_chain;
2071 /* Avoid endless recursion if a `source' command is contained
2073 if (executing_breakpoint_commands)
2076 executing_breakpoint_commands = 1;
2077 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
2080 /* Note that (as of this writing), our callers all appear to
2081 be passing us the address of global stop_bpstat. And, if
2082 our calls to execute_control_command cause the inferior to
2083 proceed, that global (and hence, *bsp) will change.
2085 We must be careful to not touch *bsp unless the inferior
2086 has not proceeded. */
2088 /* This pointer will iterate over the list of bpstat's. */
2091 breakpoint_proceeded = 0;
2092 for (; bs != NULL; bs = bs->next)
2094 struct command_line *cmd;
2095 struct cleanup *this_cmd_tree_chain;
2097 /* Take ownership of the BSP's command tree, if it has one.
2099 The command tree could legitimately contain commands like
2100 'step' and 'next', which call clear_proceed_status, which
2101 frees stop_bpstat's command tree. To make sure this doesn't
2102 free the tree we're executing out from under us, we need to
2103 take ownership of the tree ourselves. Since a given bpstat's
2104 commands are only executed once, we don't need to copy it; we
2105 can clear the pointer in the bpstat, and make sure we free
2106 the tree when we're done. */
2109 this_cmd_tree_chain = make_cleanup_free_command_lines (&cmd);
2113 execute_control_command (cmd);
2115 if (breakpoint_proceeded)
2121 /* We can free this command tree now. */
2122 do_cleanups (this_cmd_tree_chain);
2124 if (breakpoint_proceeded)
2126 if (target_can_async_p ())
2127 /* If we are in async mode, then the target might
2128 be still running, not stopped at any breakpoint,
2129 so nothing for us to do here -- just return to
2133 /* In sync mode, when execute_control_command returns
2134 we're already standing on the next breakpoint.
2135 Breakpoint commands for that stop were not run,
2136 since execute_command does not run breakpoint
2137 commands -- only command_line_handler does, but
2138 that one is not involved in execution of breakpoint
2139 commands. So, we can now execute breakpoint commands.
2140 There's an implicit assumption that we're called with
2141 stop_bpstat, so our parameter is the new bpstat to
2143 It should be noted that making execute_command do
2144 bpstat actions is not an option -- in this case we'll
2145 have recursive invocation of bpstat for each breakpoint
2146 with a command, and can easily blow up GDB stack. */
2150 do_cleanups (old_chain);
2153 /* Print out the (old or new) value associated with a watchpoint. */
2156 watchpoint_value_print (struct value *val, struct ui_file *stream)
2159 fprintf_unfiltered (stream, _("<unreadable>"));
2161 value_print (val, stream, 0, Val_pretty_default);
2164 /* This is the normal print function for a bpstat. In the future,
2165 much of this logic could (should?) be moved to bpstat_stop_status,
2166 by having it set different print_it values.
2168 Current scheme: When we stop, bpstat_print() is called. It loops
2169 through the bpstat list of things causing this stop, calling the
2170 print_bp_stop_message function on each one. The behavior of the
2171 print_bp_stop_message function depends on the print_it field of
2172 bpstat. If such field so indicates, call this function here.
2174 Return values from this routine (ultimately used by bpstat_print()
2175 and normal_stop() to decide what to do):
2176 PRINT_NOTHING: Means we already printed all we needed to print,
2177 don't print anything else.
2178 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2179 that something to be followed by a location.
2180 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2181 that something to be followed by a location.
2182 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2185 static enum print_stop_action
2186 print_it_typical (bpstat bs)
2188 struct cleanup *old_chain, *ui_out_chain;
2189 struct breakpoint *b;
2190 const struct bp_location *bl;
2191 struct ui_stream *stb;
2193 stb = ui_out_stream_new (uiout);
2194 old_chain = make_cleanup_ui_out_stream_delete (stb);
2195 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2196 which has since been deleted. */
2197 if (bs->breakpoint_at == NULL)
2198 return PRINT_UNKNOWN;
2199 bl = bs->breakpoint_at;
2205 case bp_hardware_breakpoint:
2206 bp_temp = bs->breakpoint_at->owner->disposition == disp_del;
2207 if (bl->address != bl->requested_address)
2208 breakpoint_adjustment_warning (bl->requested_address,
2211 annotate_breakpoint (b->number);
2213 ui_out_text (uiout, "\nTemporary breakpoint ");
2215 ui_out_text (uiout, "\nBreakpoint ");
2216 if (ui_out_is_mi_like_p (uiout))
2218 ui_out_field_string (uiout, "reason",
2219 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
2220 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
2222 ui_out_field_int (uiout, "bkptno", b->number);
2223 ui_out_text (uiout, ", ");
2224 return PRINT_SRC_AND_LOC;
2227 case bp_shlib_event:
2228 /* Did we stop because the user set the stop_on_solib_events
2229 variable? (If so, we report this as a generic, "Stopped due
2230 to shlib event" message.) */
2231 printf_filtered (_("Stopped due to shared library event\n"));
2232 return PRINT_NOTHING;
2235 case bp_thread_event:
2236 /* Not sure how we will get here.
2237 GDB should not stop for these breakpoints. */
2238 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2239 return PRINT_NOTHING;
2242 case bp_overlay_event:
2243 /* By analogy with the thread event, GDB should not stop for these. */
2244 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2245 return PRINT_NOTHING;
2249 annotate_catchpoint (b->number);
2250 printf_filtered (_("\nCatchpoint %d (loaded %s), "),
2252 b->triggered_dll_pathname);
2253 return PRINT_SRC_AND_LOC;
2256 case bp_catch_unload:
2257 annotate_catchpoint (b->number);
2258 printf_filtered (_("\nCatchpoint %d (unloaded %s), "),
2260 b->triggered_dll_pathname);
2261 return PRINT_SRC_AND_LOC;
2265 annotate_catchpoint (b->number);
2266 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
2268 b->forked_inferior_pid);
2269 return PRINT_SRC_AND_LOC;
2272 case bp_catch_vfork:
2273 annotate_catchpoint (b->number);
2274 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
2276 b->forked_inferior_pid);
2277 return PRINT_SRC_AND_LOC;
2281 annotate_catchpoint (b->number);
2282 printf_filtered (_("\nCatchpoint %d (exec'd %s), "),
2285 return PRINT_SRC_AND_LOC;
2289 case bp_hardware_watchpoint:
2290 annotate_watchpoint (b->number);
2291 if (ui_out_is_mi_like_p (uiout))
2294 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
2296 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2297 ui_out_text (uiout, "\nOld value = ");
2298 watchpoint_value_print (bs->old_val, stb->stream);
2299 ui_out_field_stream (uiout, "old", stb);
2300 ui_out_text (uiout, "\nNew value = ");
2301 watchpoint_value_print (b->val, stb->stream);
2302 ui_out_field_stream (uiout, "new", stb);
2303 do_cleanups (ui_out_chain);
2304 ui_out_text (uiout, "\n");
2305 /* More than one watchpoint may have been triggered. */
2306 return PRINT_UNKNOWN;
2309 case bp_read_watchpoint:
2310 if (ui_out_is_mi_like_p (uiout))
2313 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
2315 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2316 ui_out_text (uiout, "\nValue = ");
2317 watchpoint_value_print (b->val, stb->stream);
2318 ui_out_field_stream (uiout, "value", stb);
2319 do_cleanups (ui_out_chain);
2320 ui_out_text (uiout, "\n");
2321 return PRINT_UNKNOWN;
2324 case bp_access_watchpoint:
2325 if (bs->old_val != NULL)
2327 annotate_watchpoint (b->number);
2328 if (ui_out_is_mi_like_p (uiout))
2331 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
2333 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2334 ui_out_text (uiout, "\nOld value = ");
2335 watchpoint_value_print (bs->old_val, stb->stream);
2336 ui_out_field_stream (uiout, "old", stb);
2337 ui_out_text (uiout, "\nNew value = ");
2342 if (ui_out_is_mi_like_p (uiout))
2345 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
2346 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2347 ui_out_text (uiout, "\nValue = ");
2349 watchpoint_value_print (b->val, stb->stream);
2350 ui_out_field_stream (uiout, "new", stb);
2351 do_cleanups (ui_out_chain);
2352 ui_out_text (uiout, "\n");
2353 return PRINT_UNKNOWN;
2356 /* Fall through, we don't deal with these types of breakpoints
2360 if (ui_out_is_mi_like_p (uiout))
2363 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED));
2364 return PRINT_UNKNOWN;
2368 if (ui_out_is_mi_like_p (uiout))
2371 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED));
2372 return PRINT_UNKNOWN;
2377 case bp_longjmp_resume:
2378 case bp_step_resume:
2379 case bp_watchpoint_scope:
2382 return PRINT_UNKNOWN;
2386 /* Generic routine for printing messages indicating why we
2387 stopped. The behavior of this function depends on the value
2388 'print_it' in the bpstat structure. Under some circumstances we
2389 may decide not to print anything here and delegate the task to
2392 static enum print_stop_action
2393 print_bp_stop_message (bpstat bs)
2395 switch (bs->print_it)
2398 /* Nothing should be printed for this bpstat entry. */
2399 return PRINT_UNKNOWN;
2403 /* We still want to print the frame, but we already printed the
2404 relevant messages. */
2405 return PRINT_SRC_AND_LOC;
2408 case print_it_normal:
2410 const struct bp_location *bl = bs->breakpoint_at;
2411 struct breakpoint *b = bl ? bl->owner : NULL;
2413 /* Normal case. Call the breakpoint's print_it method, or
2414 print_it_typical. */
2415 /* FIXME: how breakpoint can ever be NULL here? */
2416 if (b != NULL && b->ops != NULL && b->ops->print_it != NULL)
2417 return b->ops->print_it (b);
2419 return print_it_typical (bs);
2424 internal_error (__FILE__, __LINE__,
2425 _("print_bp_stop_message: unrecognized enum value"));
2430 /* Print a message indicating what happened. This is called from
2431 normal_stop(). The input to this routine is the head of the bpstat
2432 list - a list of the eventpoints that caused this stop. This
2433 routine calls the generic print routine for printing a message
2434 about reasons for stopping. This will print (for example) the
2435 "Breakpoint n," part of the output. The return value of this
2438 PRINT_UNKNOWN: Means we printed nothing
2439 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2440 code to print the location. An example is
2441 "Breakpoint 1, " which should be followed by
2443 PRINT_SRC_ONLY: Means we printed something, but there is no need
2444 to also print the location part of the message.
2445 An example is the catch/throw messages, which
2446 don't require a location appended to the end.
2447 PRINT_NOTHING: We have done some printing and we don't need any
2448 further info to be printed.*/
2450 enum print_stop_action
2451 bpstat_print (bpstat bs)
2455 /* Maybe another breakpoint in the chain caused us to stop.
2456 (Currently all watchpoints go on the bpstat whether hit or not.
2457 That probably could (should) be changed, provided care is taken
2458 with respect to bpstat_explains_signal). */
2459 for (; bs; bs = bs->next)
2461 val = print_bp_stop_message (bs);
2462 if (val == PRINT_SRC_ONLY
2463 || val == PRINT_SRC_AND_LOC
2464 || val == PRINT_NOTHING)
2468 /* We reached the end of the chain, or we got a null BS to start
2469 with and nothing was printed. */
2470 return PRINT_UNKNOWN;
2473 /* Evaluate the expression EXP and return 1 if value is zero.
2474 This is used inside a catch_errors to evaluate the breakpoint condition.
2475 The argument is a "struct expression *" that has been cast to char * to
2476 make it pass through catch_errors. */
2479 breakpoint_cond_eval (void *exp)
2481 struct value *mark = value_mark ();
2482 int i = !value_true (evaluate_expression ((struct expression *) exp));
2483 value_free_to_mark (mark);
2487 /* Allocate a new bpstat and chain it to the current one. */
2490 bpstat_alloc (const struct bp_location *bl, bpstat cbs /* Current "bs" value */ )
2494 bs = (bpstat) xmalloc (sizeof (*bs));
2496 bs->breakpoint_at = bl;
2497 /* If the condition is false, etc., don't do the commands. */
2498 bs->commands = NULL;
2500 bs->print_it = print_it_normal;
2504 /* The target has stopped with waitstatus WS. Check if any hardware
2505 watchpoints have triggered, according to the target. */
2508 watchpoints_triggered (struct target_waitstatus *ws)
2510 int stopped_by_watchpoint = STOPPED_BY_WATCHPOINT (*ws);
2512 struct breakpoint *b;
2514 if (!stopped_by_watchpoint)
2516 /* We were not stopped by a watchpoint. Mark all watchpoints
2517 as not triggered. */
2519 if (b->type == bp_hardware_watchpoint
2520 || b->type == bp_read_watchpoint
2521 || b->type == bp_access_watchpoint)
2522 b->watchpoint_triggered = watch_triggered_no;
2527 if (!target_stopped_data_address (¤t_target, &addr))
2529 /* We were stopped by a watchpoint, but we don't know where.
2530 Mark all watchpoints as unknown. */
2532 if (b->type == bp_hardware_watchpoint
2533 || b->type == bp_read_watchpoint
2534 || b->type == bp_access_watchpoint)
2535 b->watchpoint_triggered = watch_triggered_unknown;
2537 return stopped_by_watchpoint;
2540 /* The target could report the data address. Mark watchpoints
2541 affected by this data address as triggered, and all others as not
2545 if (b->type == bp_hardware_watchpoint
2546 || b->type == bp_read_watchpoint
2547 || b->type == bp_access_watchpoint)
2549 struct bp_location *loc;
2552 b->watchpoint_triggered = watch_triggered_no;
2553 for (loc = b->loc; loc; loc = loc->next)
2554 /* Exact match not required. Within range is
2556 if (addr >= loc->address
2557 && addr < loc->address + loc->length)
2559 b->watchpoint_triggered = watch_triggered_yes;
2567 /* Possible return values for watchpoint_check (this can't be an enum
2568 because of check_errors). */
2569 /* The watchpoint has been deleted. */
2570 #define WP_DELETED 1
2571 /* The value has changed. */
2572 #define WP_VALUE_CHANGED 2
2573 /* The value has not changed. */
2574 #define WP_VALUE_NOT_CHANGED 3
2576 #define BP_TEMPFLAG 1
2577 #define BP_HARDWAREFLAG 2
2579 /* Check watchpoint condition. */
2582 watchpoint_check (void *p)
2584 bpstat bs = (bpstat) p;
2585 struct breakpoint *b;
2586 struct frame_info *fr;
2587 int within_current_scope;
2589 b = bs->breakpoint_at->owner;
2591 if (b->exp_valid_block == NULL)
2592 within_current_scope = 1;
2595 /* There is no current frame at this moment. If we're going to have
2596 any chance of handling watchpoints on local variables, we'll need
2597 the frame chain (so we can determine if we're in scope). */
2598 reinit_frame_cache ();
2599 fr = frame_find_by_id (b->watchpoint_frame);
2600 within_current_scope = (fr != NULL);
2602 /* If we've gotten confused in the unwinder, we might have
2603 returned a frame that can't describe this variable. */
2604 if (within_current_scope
2605 && block_function (b->exp_valid_block) != get_frame_function (fr))
2606 within_current_scope = 0;
2608 /* in_function_epilogue_p() returns a non-zero value if we're still
2609 in the function but the stack frame has already been invalidated.
2610 Since we can't rely on the values of local variables after the
2611 stack has been destroyed, we are treating the watchpoint in that
2612 state as `not changed' without further checking.
2614 vinschen/2003-09-04: The former implementation left out the case
2615 that the watchpoint frame couldn't be found by frame_find_by_id()
2616 because the current PC is currently in an epilogue. Calling
2617 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2618 if ((!within_current_scope || fr == get_current_frame ())
2619 && gdbarch_in_function_epilogue_p (current_gdbarch, read_pc ()))
2620 return WP_VALUE_NOT_CHANGED;
2621 if (fr && within_current_scope)
2622 /* If we end up stopping, the current frame will get selected
2623 in normal_stop. So this call to select_frame won't affect
2628 if (within_current_scope)
2630 /* We use value_{,free_to_}mark because it could be a
2631 *long* time before we return to the command level and
2632 call free_all_values. We can't call free_all_values because
2633 we might be in the middle of evaluating a function call. */
2635 struct value *mark = value_mark ();
2636 struct value *new_val;
2638 fetch_watchpoint_value (b->exp, &new_val, NULL, NULL);
2639 if ((b->val != NULL) != (new_val != NULL)
2640 || (b->val != NULL && !value_equal (b->val, new_val)))
2642 if (new_val != NULL)
2644 release_value (new_val);
2645 value_free_to_mark (mark);
2647 bs->old_val = b->val;
2650 /* We will stop here */
2651 return WP_VALUE_CHANGED;
2655 /* Nothing changed, don't do anything. */
2656 value_free_to_mark (mark);
2657 /* We won't stop here */
2658 return WP_VALUE_NOT_CHANGED;
2663 /* This seems like the only logical thing to do because
2664 if we temporarily ignored the watchpoint, then when
2665 we reenter the block in which it is valid it contains
2666 garbage (in the case of a function, it may have two
2667 garbage values, one before and one after the prologue).
2668 So we can't even detect the first assignment to it and
2669 watch after that (since the garbage may or may not equal
2670 the first value assigned). */
2671 /* We print all the stop information in print_it_typical(), but
2672 in this case, by the time we call print_it_typical() this bp
2673 will be deleted already. So we have no choice but print the
2674 information here. */
2675 if (ui_out_is_mi_like_p (uiout))
2677 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
2678 ui_out_text (uiout, "\nWatchpoint ");
2679 ui_out_field_int (uiout, "wpnum", b->number);
2680 ui_out_text (uiout, " deleted because the program has left the block in\n\
2681 which its expression is valid.\n");
2683 if (b->related_breakpoint)
2684 b->related_breakpoint->disposition = disp_del_at_next_stop;
2685 b->disposition = disp_del_at_next_stop;
2691 /* Get a bpstat associated with having just stopped at address
2692 BP_ADDR in thread PTID.
2694 Determine whether we stopped at a breakpoint, etc, or whether we
2695 don't understand this stop. Result is a chain of bpstat's such that:
2697 if we don't understand the stop, the result is a null pointer.
2699 if we understand why we stopped, the result is not null.
2701 Each element of the chain refers to a particular breakpoint or
2702 watchpoint at which we have stopped. (We may have stopped for
2703 several reasons concurrently.)
2705 Each element of the chain has valid next, breakpoint_at,
2706 commands, FIXME??? fields. */
2709 bpstat_stop_status (CORE_ADDR bp_addr, ptid_t ptid)
2711 struct breakpoint *b = NULL;
2712 const struct bp_location *bl;
2713 /* Root of the chain of bpstat's */
2714 struct bpstats root_bs[1];
2715 /* Pointer to the last thing in the chain currently. */
2716 bpstat bs = root_bs;
2717 int thread_id = pid_to_thread_id (ptid);
2719 ALL_BP_LOCATIONS (bl)
2723 if (!breakpoint_enabled (b) && b->enable_state != bp_permanent)
2726 if (b->type != bp_watchpoint
2727 && b->type != bp_hardware_watchpoint
2728 && b->type != bp_read_watchpoint
2729 && b->type != bp_access_watchpoint
2730 && b->type != bp_hardware_breakpoint
2731 && b->type != bp_catch_fork
2732 && b->type != bp_catch_vfork
2733 && b->type != bp_catch_exec) /* a non-watchpoint bp */
2735 if (bl->address != bp_addr) /* address doesn't match */
2737 if (overlay_debugging /* unmapped overlay section */
2738 && section_is_overlay (bl->section)
2739 && !section_is_mapped (bl->section))
2743 /* Continuable hardware watchpoints are treated as non-existent if the
2744 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2745 some data address). Otherwise gdb won't stop on a break instruction
2746 in the code (not from a breakpoint) when a hardware watchpoint has
2747 been defined. Also skip watchpoints which we know did not trigger
2748 (did not match the data address). */
2750 if ((b->type == bp_hardware_watchpoint
2751 || b->type == bp_read_watchpoint
2752 || b->type == bp_access_watchpoint)
2753 && b->watchpoint_triggered == watch_triggered_no)
2756 if (b->type == bp_hardware_breakpoint)
2758 if (bl->address != bp_addr)
2760 if (overlay_debugging /* unmapped overlay section */
2761 && section_is_overlay (bl->section)
2762 && !section_is_mapped (bl->section))
2766 /* Is this a catchpoint of a load or unload? If so, did we
2767 get a load or unload of the specified library? If not,
2769 if ((b->type == bp_catch_load)
2770 #if defined(SOLIB_HAVE_LOAD_EVENT)
2771 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid))
2772 || ((b->dll_pathname != NULL)
2773 && (strcmp (b->dll_pathname,
2774 SOLIB_LOADED_LIBRARY_PATHNAME (
2775 PIDGET (inferior_ptid)))
2781 if ((b->type == bp_catch_unload)
2782 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2783 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid))
2784 || ((b->dll_pathname != NULL)
2785 && (strcmp (b->dll_pathname,
2786 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2787 PIDGET (inferior_ptid)))
2793 if ((b->type == bp_catch_fork)
2794 && !inferior_has_forked (PIDGET (inferior_ptid),
2795 &b->forked_inferior_pid))
2798 if ((b->type == bp_catch_vfork)
2799 && !inferior_has_vforked (PIDGET (inferior_ptid),
2800 &b->forked_inferior_pid))
2803 if ((b->type == bp_catch_exec)
2804 && !inferior_has_execd (PIDGET (inferior_ptid), &b->exec_pathname))
2807 /* For hardware watchpoints, we look only at the first location.
2808 The watchpoint_check function will work on entire expression,
2809 not the individual locations. For read watchopints, the
2810 watchpoints_triggered function have checked all locations
2813 if (b->type == bp_hardware_watchpoint && bl != b->loc)
2816 /* Come here if it's a watchpoint, or if the break address matches */
2818 bs = bpstat_alloc (bl, bs); /* Alloc a bpstat to explain stop */
2820 /* Watchpoints may change this, if not found to have triggered. */
2824 if (b->type == bp_watchpoint
2825 || b->type == bp_read_watchpoint
2826 || b->type == bp_access_watchpoint
2827 || b->type == bp_hardware_watchpoint)
2831 int must_check_value = 0;
2833 if (b->type == bp_watchpoint)
2834 /* For a software watchpoint, we must always check the
2836 must_check_value = 1;
2837 else if (b->watchpoint_triggered == watch_triggered_yes)
2838 /* We have a hardware watchpoint (read, write, or access)
2839 and the target earlier reported an address watched by
2841 must_check_value = 1;
2842 else if (b->watchpoint_triggered == watch_triggered_unknown
2843 && b->type == bp_hardware_watchpoint)
2844 /* We were stopped by a hardware watchpoint, but the target could
2845 not report the data address. We must check the watchpoint's
2846 value. Access and read watchpoints are out of luck; without
2847 a data address, we can't figure it out. */
2848 must_check_value = 1;
2850 if (must_check_value)
2852 char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n",
2854 struct cleanup *cleanups = make_cleanup (xfree, message);
2855 int e = catch_errors (watchpoint_check, bs, message,
2857 do_cleanups (cleanups);
2861 /* We've already printed what needs to be printed. */
2862 bs->print_it = print_it_done;
2865 case WP_VALUE_CHANGED:
2866 if (b->type == bp_read_watchpoint)
2868 /* Don't stop: read watchpoints shouldn't fire if
2869 the value has changed. This is for targets
2870 which cannot set read-only watchpoints. */
2871 bs->print_it = print_it_noop;
2877 case WP_VALUE_NOT_CHANGED:
2878 if (b->type == bp_hardware_watchpoint
2879 || b->type == bp_watchpoint)
2881 /* Don't stop: write watchpoints shouldn't fire if
2882 the value hasn't changed. */
2883 bs->print_it = print_it_noop;
2893 /* Error from catch_errors. */
2894 printf_filtered (_("Watchpoint %d deleted.\n"), b->number);
2895 if (b->related_breakpoint)
2896 b->related_breakpoint->disposition = disp_del_at_next_stop;
2897 b->disposition = disp_del_at_next_stop;
2898 /* We've already printed what needs to be printed. */
2899 bs->print_it = print_it_done;
2903 else /* must_check_value == 0 */
2905 /* This is a case where some watchpoint(s) triggered, but
2906 not at the address of this watchpoint, or else no
2907 watchpoint triggered after all. So don't print
2908 anything for this watchpoint. */
2909 bs->print_it = print_it_noop;
2916 /* By definition, an encountered breakpoint is a triggered
2921 if (frame_id_p (b->frame_id)
2922 && !frame_id_eq (b->frame_id, get_frame_id (get_current_frame ())))
2926 int value_is_zero = 0;
2928 /* If this is a scope breakpoint, mark the associated
2929 watchpoint as triggered so that we will handle the
2930 out-of-scope event. We'll get to the watchpoint next
2932 if (b->type == bp_watchpoint_scope)
2933 b->related_breakpoint->watchpoint_triggered = watch_triggered_yes;
2935 if (bl->cond && bl->owner->disposition != disp_del_at_next_stop)
2937 /* Need to select the frame, with all that implies
2938 so that the conditions will have the right context. */
2939 select_frame (get_current_frame ());
2941 = catch_errors (breakpoint_cond_eval, (bl->cond),
2942 "Error in testing breakpoint condition:\n",
2944 /* FIXME-someday, should give breakpoint # */
2947 if (bl->cond && value_is_zero)
2950 /* Don't consider this a hit. */
2953 else if (b->thread != -1 && b->thread != thread_id)
2956 /* Don't consider this a hit. */
2959 else if (b->ignore_count > 0)
2962 annotate_ignore_count_change ();
2965 else if (b->type == bp_thread_event || b->type == bp_overlay_event)
2966 /* We do not stop for these. */
2970 /* We will stop here */
2971 if (b->disposition == disp_disable)
2972 b->enable_state = bp_disabled;
2975 bs->commands = b->commands;
2977 (strcmp ("silent", bs->commands->line) == 0
2978 || (xdb_commands && strcmp ("Q", bs->commands->line) == 0)))
2980 bs->commands = bs->commands->next;
2983 bs->commands = copy_command_lines (bs->commands);
2986 /* Print nothing for this entry if we dont stop or if we dont print. */
2987 if (bs->stop == 0 || bs->print == 0)
2988 bs->print_it = print_it_noop;
2991 bs->next = NULL; /* Terminate the chain */
2992 bs = root_bs->next; /* Re-grab the head of the chain */
2994 /* If we aren't stopping, the value of some hardware watchpoint may
2995 not have changed, but the intermediate memory locations we are
2996 watching may have. Don't bother if we're stopping; this will get
2998 for (bs = root_bs->next; bs != NULL; bs = bs->next)
3003 for (bs = root_bs->next; bs != NULL; bs = bs->next)
3005 && (bs->breakpoint_at->owner->type == bp_hardware_watchpoint
3006 || bs->breakpoint_at->owner->type == bp_read_watchpoint
3007 || bs->breakpoint_at->owner->type == bp_access_watchpoint))
3009 /* remove/insert can invalidate bs->breakpoint_at, if this
3010 location is no longer used by the watchpoint. Prevent
3011 further code from trying to use it. */
3012 bs->breakpoint_at = NULL;
3013 remove_breakpoints ();
3014 insert_breakpoints ();
3018 return root_bs->next;
3021 /* Tell what to do about this bpstat. */
3023 bpstat_what (bpstat bs)
3025 /* Classify each bpstat as one of the following. */
3028 /* This bpstat element has no effect on the main_action. */
3031 /* There was a watchpoint, stop but don't print. */
3034 /* There was a watchpoint, stop and print. */
3037 /* There was a breakpoint but we're not stopping. */
3040 /* There was a breakpoint, stop but don't print. */
3043 /* There was a breakpoint, stop and print. */
3046 /* We hit the longjmp breakpoint. */
3049 /* We hit the longjmp_resume breakpoint. */
3052 /* We hit the step_resume breakpoint. */
3055 /* We hit the shared library event breakpoint. */
3058 /* We caught a shared library event. */
3061 /* This is just used to count how many enums there are. */
3065 /* Here is the table which drives this routine. So that we can
3066 format it pretty, we define some abbreviations for the
3067 enum bpstat_what codes. */
3068 #define kc BPSTAT_WHAT_KEEP_CHECKING
3069 #define ss BPSTAT_WHAT_STOP_SILENT
3070 #define sn BPSTAT_WHAT_STOP_NOISY
3071 #define sgl BPSTAT_WHAT_SINGLE
3072 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3073 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3074 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
3075 #define sr BPSTAT_WHAT_STEP_RESUME
3076 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3077 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
3079 /* "Can't happen." Might want to print an error message.
3080 abort() is not out of the question, but chances are GDB is just
3081 a bit confused, not unusable. */
3082 #define err BPSTAT_WHAT_STOP_NOISY
3084 /* Given an old action and a class, come up with a new action. */
3085 /* One interesting property of this table is that wp_silent is the same
3086 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3087 after stopping, the check for whether to step over a breakpoint
3088 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3089 reference to how we stopped. We retain separate wp_silent and
3090 bp_silent codes in case we want to change that someday.
3092 Another possibly interesting property of this table is that
3093 there's a partial ordering, priority-like, of the actions. Once
3094 you've decided that some action is appropriate, you'll never go
3095 back and decide something of a lower priority is better. The
3098 kc < clr sgl shl shlr slr sn sr ss
3099 sgl < clrs shl shlr slr sn sr ss
3100 slr < err shl shlr sn sr ss
3101 clr < clrs err shl shlr sn sr ss
3102 clrs < err shl shlr sn sr ss
3109 What I think this means is that we don't need a damned table
3110 here. If you just put the rows and columns in the right order,
3111 it'd look awfully regular. We could simply walk the bpstat list
3112 and choose the highest priority action we find, with a little
3113 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
3114 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
3115 is messy anyway). */
3117 /* step_resume entries: a step resume breakpoint overrides another
3118 breakpoint of signal handling (see comment in wait_for_inferior
3119 at where we set the step_resume breakpoint). */
3121 static const enum bpstat_what_main_action
3122 table[(int) class_last][(int) BPSTAT_WHAT_LAST] =
3125 /* kc ss sn sgl slr clr clrs sr shl shlr
3128 {kc, ss, sn, sgl, slr, clr, clrs, sr, shl, shlr},
3130 {ss, ss, sn, ss, ss, ss, ss, sr, shl, shlr},
3132 {sn, sn, sn, sn, sn, sn, sn, sr, shl, shlr},
3134 {sgl, ss, sn, sgl, slr, clrs, clrs, sr, shl, shlr},
3136 {ss, ss, sn, ss, ss, ss, ss, sr, shl, shlr},
3138 {sn, sn, sn, sn, sn, sn, sn, sr, shl, shlr},
3140 {slr, ss, sn, slr, slr, err, err, sr, shl, shlr},
3142 {clr, ss, sn, clrs, err, err, err, sr, shl, shlr},
3144 {sr, sr, sr, sr, sr, sr, sr, sr, sr, sr},
3146 {shl, shl, shl, shl, shl, shl, shl, sr, shl, shlr},
3148 {shlr, shlr, shlr, shlr, shlr, shlr, shlr, sr, shlr, shlr}
3163 enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
3164 struct bpstat_what retval;
3166 retval.call_dummy = 0;
3167 for (; bs != NULL; bs = bs->next)
3169 enum class bs_class = no_effect;
3170 if (bs->breakpoint_at == NULL)
3171 /* I suspect this can happen if it was a momentary breakpoint
3172 which has since been deleted. */
3174 switch (bs->breakpoint_at->owner->type)
3180 case bp_hardware_breakpoint:
3186 bs_class = bp_noisy;
3188 bs_class = bp_silent;
3191 bs_class = bp_nostop;
3194 case bp_hardware_watchpoint:
3195 case bp_read_watchpoint:
3196 case bp_access_watchpoint:
3200 bs_class = wp_noisy;
3202 bs_class = wp_silent;
3205 /* There was a watchpoint, but we're not stopping.
3206 This requires no further action. */
3207 bs_class = no_effect;
3210 bs_class = long_jump;
3212 case bp_longjmp_resume:
3213 bs_class = long_resume;
3215 case bp_step_resume:
3218 bs_class = step_resume;
3221 /* It is for the wrong frame. */
3222 bs_class = bp_nostop;
3224 case bp_watchpoint_scope:
3225 bs_class = bp_nostop;
3227 case bp_shlib_event:
3228 bs_class = shlib_event;
3230 case bp_thread_event:
3231 case bp_overlay_event:
3232 bs_class = bp_nostop;
3235 case bp_catch_unload:
3236 /* Only if this catchpoint triggered should we cause the
3237 step-out-of-dld behaviour. Otherwise, we ignore this
3240 bs_class = catch_shlib_event;
3242 bs_class = no_effect;
3245 case bp_catch_vfork:
3250 bs_class = bp_noisy;
3252 bs_class = bp_silent;
3255 /* There was a catchpoint, but we're not stopping.
3256 This requires no further action. */
3257 bs_class = no_effect;
3260 /* Make sure the action is stop (silent or noisy),
3261 so infrun.c pops the dummy frame. */
3262 bs_class = bp_silent;
3263 retval.call_dummy = 1;
3266 current_action = table[(int) bs_class][(int) current_action];
3268 retval.main_action = current_action;
3272 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3273 without hardware support). This isn't related to a specific bpstat,
3274 just to things like whether watchpoints are set. */
3277 bpstat_should_step (void)
3279 struct breakpoint *b;
3281 if (breakpoint_enabled (b) && b->type == bp_watchpoint)
3288 /* Given a bpstat that records zero or more triggered eventpoints, this
3289 function returns another bpstat which contains only the catchpoints
3290 on that first list, if any. */
3292 bpstat_get_triggered_catchpoints (bpstat ep_list, bpstat *cp_list)
3294 struct bpstats root_bs[1];
3295 bpstat bs = root_bs;
3296 struct breakpoint *ep;
3299 bpstat_clear (cp_list);
3300 root_bs->next = NULL;
3302 for (; ep_list != NULL; ep_list = ep_list->next)
3304 /* Is this eventpoint a catchpoint? If not, ignore it. */
3305 ep = ep_list->breakpoint_at->owner;
3308 if ((ep->type != bp_catch_load) &&
3309 (ep->type != bp_catch_unload))
3310 /* pai: (temp) ADD fork/vfork here!! */
3313 /* Yes; add it to the list. */
3314 bs = bpstat_alloc (ep_list->breakpoint_at, bs);
3319 #if defined(SOLIB_ADD)
3320 /* Also, for each triggered catchpoint, tag it with the name of
3321 the library that caused this trigger. (We copy the name now,
3322 because it's only guaranteed to be available NOW, when the
3323 catchpoint triggers. Clients who may wish to know the name
3324 later must get it from the catchpoint itself.) */
3325 if (ep->triggered_dll_pathname != NULL)
3326 xfree (ep->triggered_dll_pathname);
3327 if (ep->type == bp_catch_load)
3328 dll_pathname = SOLIB_LOADED_LIBRARY_PATHNAME (
3329 PIDGET (inferior_ptid));
3331 dll_pathname = SOLIB_UNLOADED_LIBRARY_PATHNAME (
3332 PIDGET (inferior_ptid));
3334 dll_pathname = NULL;
3338 ep->triggered_dll_pathname = (char *)
3339 xmalloc (strlen (dll_pathname) + 1);
3340 strcpy (ep->triggered_dll_pathname, dll_pathname);
3343 ep->triggered_dll_pathname = NULL;
3349 static void print_breakpoint_location (struct breakpoint *b,
3350 struct bp_location *loc,
3352 struct ui_stream *stb)
3357 = find_pc_sect_function (loc->address, loc->section);
3360 ui_out_text (uiout, "in ");
3361 ui_out_field_string (uiout, "func",
3362 SYMBOL_PRINT_NAME (sym));
3363 ui_out_wrap_hint (uiout, wrap_indent);
3364 ui_out_text (uiout, " at ");
3366 ui_out_field_string (uiout, "file", b->source_file);
3367 ui_out_text (uiout, ":");
3369 if (ui_out_is_mi_like_p (uiout))
3371 struct symtab_and_line sal = find_pc_line (loc->address, 0);
3372 char *fullname = symtab_to_fullname (sal.symtab);
3375 ui_out_field_string (uiout, "fullname", fullname);
3378 ui_out_field_int (uiout, "line", b->line_number);
3382 ui_out_field_string (uiout, "pending", b->addr_string);
3386 print_address_symbolic (loc->address, stb->stream, demangle, "");
3387 ui_out_field_stream (uiout, "at", stb);
3391 /* Print B to gdb_stdout. */
3393 print_one_breakpoint_location (struct breakpoint *b,
3394 struct bp_location *loc,
3396 CORE_ADDR *last_addr)
3398 struct command_line *l;
3400 struct ep_type_description
3405 static struct ep_type_description bptypes[] =
3407 {bp_none, "?deleted?"},
3408 {bp_breakpoint, "breakpoint"},
3409 {bp_hardware_breakpoint, "hw breakpoint"},
3410 {bp_until, "until"},
3411 {bp_finish, "finish"},
3412 {bp_watchpoint, "watchpoint"},
3413 {bp_hardware_watchpoint, "hw watchpoint"},
3414 {bp_read_watchpoint, "read watchpoint"},
3415 {bp_access_watchpoint, "acc watchpoint"},
3416 {bp_longjmp, "longjmp"},
3417 {bp_longjmp_resume, "longjmp resume"},
3418 {bp_step_resume, "step resume"},
3419 {bp_watchpoint_scope, "watchpoint scope"},
3420 {bp_call_dummy, "call dummy"},
3421 {bp_shlib_event, "shlib events"},
3422 {bp_thread_event, "thread events"},
3423 {bp_overlay_event, "overlay events"},
3424 {bp_catch_load, "catch load"},
3425 {bp_catch_unload, "catch unload"},
3426 {bp_catch_fork, "catch fork"},
3427 {bp_catch_vfork, "catch vfork"},
3428 {bp_catch_exec, "catch exec"}
3431 static char bpenables[] = "nynny";
3432 char wrap_indent[80];
3433 struct ui_stream *stb = ui_out_stream_new (uiout);
3434 struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb);
3435 struct cleanup *bkpt_chain;
3437 int header_of_multiple = 0;
3438 int part_of_multiple = (loc != NULL);
3440 gdb_assert (!loc || loc_number != 0);
3441 /* See comment in print_one_breakpoint concerning
3442 treatment of breakpoints with single disabled
3446 && (b->loc->next != NULL || !b->loc->enabled)))
3447 header_of_multiple = 1;
3452 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
3456 if (part_of_multiple)
3459 formatted = xstrprintf ("%d.%d", b->number, loc_number);
3460 ui_out_field_string (uiout, "number", formatted);
3465 ui_out_field_int (uiout, "number", b->number);
3470 if (part_of_multiple)
3471 ui_out_field_skip (uiout, "type");
3474 if (((int) b->type >= (sizeof (bptypes) / sizeof (bptypes[0])))
3475 || ((int) b->type != bptypes[(int) b->type].type))
3476 internal_error (__FILE__, __LINE__,
3477 _("bptypes table does not describe type #%d."),
3479 ui_out_field_string (uiout, "type", bptypes[(int) b->type].description);
3484 if (part_of_multiple)
3485 ui_out_field_skip (uiout, "disp");
3487 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
3492 if (part_of_multiple)
3493 ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n");
3495 ui_out_field_fmt (uiout, "enabled", "%c",
3496 bpenables[(int) b->enable_state]);
3497 ui_out_spaces (uiout, 2);
3501 strcpy (wrap_indent, " ");
3504 if (gdbarch_addr_bit (current_gdbarch) <= 32)
3505 strcat (wrap_indent, " ");
3507 strcat (wrap_indent, " ");
3510 if (b->ops != NULL && b->ops->print_one != NULL)
3512 /* Although the print_one can possibly print
3513 all locations, calling it here is not likely
3514 to get any nice result. So, make sure there's
3515 just one location. */
3516 gdb_assert (b->loc == NULL || b->loc->next == NULL);
3517 b->ops->print_one (b, last_addr);
3523 internal_error (__FILE__, __LINE__,
3524 _("print_one_breakpoint: bp_none encountered\n"));
3528 case bp_hardware_watchpoint:
3529 case bp_read_watchpoint:
3530 case bp_access_watchpoint:
3531 /* Field 4, the address, is omitted (which makes the columns
3532 not line up too nicely with the headers, but the effect
3533 is relatively readable). */
3535 ui_out_field_skip (uiout, "addr");
3537 print_expression (b->exp, stb->stream);
3538 ui_out_field_stream (uiout, "what", stb);
3542 case bp_catch_unload:
3543 /* Field 4, the address, is omitted (which makes the columns
3544 not line up too nicely with the headers, but the effect
3545 is relatively readable). */
3547 ui_out_field_skip (uiout, "addr");
3549 if (b->dll_pathname == NULL)
3551 ui_out_field_string (uiout, "what", "<any library>");
3552 ui_out_spaces (uiout, 1);
3556 ui_out_text (uiout, "library \"");
3557 ui_out_field_string (uiout, "what", b->dll_pathname);
3558 ui_out_text (uiout, "\" ");
3563 case bp_catch_vfork:
3564 /* Field 4, the address, is omitted (which makes the columns
3565 not line up too nicely with the headers, but the effect
3566 is relatively readable). */
3568 ui_out_field_skip (uiout, "addr");
3570 if (b->forked_inferior_pid != 0)
3572 ui_out_text (uiout, "process ");
3573 ui_out_field_int (uiout, "what", b->forked_inferior_pid);
3574 ui_out_spaces (uiout, 1);
3579 /* Field 4, the address, is omitted (which makes the columns
3580 not line up too nicely with the headers, but the effect
3581 is relatively readable). */
3583 ui_out_field_skip (uiout, "addr");
3585 if (b->exec_pathname != NULL)
3587 ui_out_text (uiout, "program \"");
3588 ui_out_field_string (uiout, "what", b->exec_pathname);
3589 ui_out_text (uiout, "\" ");
3594 case bp_hardware_breakpoint:
3598 case bp_longjmp_resume:
3599 case bp_step_resume:
3600 case bp_watchpoint_scope:
3602 case bp_shlib_event:
3603 case bp_thread_event:
3604 case bp_overlay_event:
3608 if (header_of_multiple)
3609 ui_out_field_string (uiout, "addr", "<MULTIPLE>");
3610 else if (b->loc == NULL || loc->shlib_disabled)
3611 ui_out_field_string (uiout, "addr", "<PENDING>");
3613 ui_out_field_core_addr (uiout, "addr", loc->address);
3616 if (!header_of_multiple)
3617 print_breakpoint_location (b, loc, wrap_indent, stb);
3619 *last_addr = b->loc->address;
3623 if (!part_of_multiple && b->thread != -1)
3625 /* FIXME: This seems to be redundant and lost here; see the
3626 "stop only in" line a little further down. */
3627 ui_out_text (uiout, " thread ");
3628 ui_out_field_int (uiout, "thread", b->thread);
3631 ui_out_text (uiout, "\n");
3633 if (part_of_multiple && frame_id_p (b->frame_id))
3636 ui_out_text (uiout, "\tstop only in stack frame at ");
3637 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3639 ui_out_field_core_addr (uiout, "frame", b->frame_id.stack_addr);
3640 ui_out_text (uiout, "\n");
3643 if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b))
3645 /* We do not print the condition for Ada exception catchpoints
3646 because the condition is an internal implementation detail
3647 that we do not want to expose to the user. */
3649 ui_out_text (uiout, "\tstop only if ");
3650 ui_out_field_string (uiout, "cond", b->cond_string);
3651 ui_out_text (uiout, "\n");
3654 if (!part_of_multiple && b->thread != -1)
3656 /* FIXME should make an annotation for this */
3657 ui_out_text (uiout, "\tstop only in thread ");
3658 ui_out_field_int (uiout, "thread", b->thread);
3659 ui_out_text (uiout, "\n");
3662 if (!part_of_multiple && show_breakpoint_hit_counts && b->hit_count)
3664 /* FIXME should make an annotation for this */
3665 if (ep_is_catchpoint (b))
3666 ui_out_text (uiout, "\tcatchpoint");
3668 ui_out_text (uiout, "\tbreakpoint");
3669 ui_out_text (uiout, " already hit ");
3670 ui_out_field_int (uiout, "times", b->hit_count);
3671 if (b->hit_count == 1)
3672 ui_out_text (uiout, " time\n");
3674 ui_out_text (uiout, " times\n");
3677 /* Output the count also if it is zero, but only if this is
3678 mi. FIXME: Should have a better test for this. */
3679 if (ui_out_is_mi_like_p (uiout))
3680 if (!part_of_multiple && show_breakpoint_hit_counts && b->hit_count == 0)
3681 ui_out_field_int (uiout, "times", b->hit_count);
3683 if (!part_of_multiple && b->ignore_count)
3686 ui_out_text (uiout, "\tignore next ");
3687 ui_out_field_int (uiout, "ignore", b->ignore_count);
3688 ui_out_text (uiout, " hits\n");
3691 if (!part_of_multiple && (l = b->commands))
3693 struct cleanup *script_chain;
3696 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
3697 print_command_lines (uiout, l, 4);
3698 do_cleanups (script_chain);
3700 do_cleanups (bkpt_chain);
3701 do_cleanups (old_chain);
3705 print_one_breakpoint (struct breakpoint *b,
3706 CORE_ADDR *last_addr)
3708 print_one_breakpoint_location (b, NULL, 0, last_addr);
3710 /* If this breakpoint has custom print function,
3711 it's already printed. Otherwise, print individual
3712 locations, if any. */
3713 if (b->ops == NULL || b->ops->print_one == NULL)
3715 /* If breakpoint has a single location that is
3716 disabled, we print it as if it had
3717 several locations, since otherwise it's hard to
3718 represent "breakpoint enabled, location disabled"
3720 Note that while hardware watchpoints have
3721 several locations internally, that's no a property
3724 && !is_hardware_watchpoint (b)
3725 && (b->loc->next || !b->loc->enabled)
3726 && !ui_out_is_mi_like_p (uiout))
3728 struct bp_location *loc;
3730 for (loc = b->loc; loc; loc = loc->next, ++n)
3731 print_one_breakpoint_location (b, loc, n, last_addr);
3737 struct captured_breakpoint_query_args
3743 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
3745 struct captured_breakpoint_query_args *args = data;
3746 struct breakpoint *b;
3747 CORE_ADDR dummy_addr = 0;
3750 if (args->bnum == b->number)
3752 print_one_breakpoint (b, &dummy_addr);
3760 gdb_breakpoint_query (struct ui_out *uiout, int bnum, char **error_message)
3762 struct captured_breakpoint_query_args args;
3764 /* For the moment we don't trust print_one_breakpoint() to not throw
3766 if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args,
3767 error_message, RETURN_MASK_ALL) < 0)
3773 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3774 catchpoints, et.al.). */
3777 user_settable_breakpoint (const struct breakpoint *b)
3779 return (b->type == bp_breakpoint
3780 || b->type == bp_catch_load
3781 || b->type == bp_catch_unload
3782 || b->type == bp_catch_fork
3783 || b->type == bp_catch_vfork
3784 || b->type == bp_catch_exec
3785 || b->type == bp_hardware_breakpoint
3786 || b->type == bp_watchpoint
3787 || b->type == bp_read_watchpoint
3788 || b->type == bp_access_watchpoint
3789 || b->type == bp_hardware_watchpoint);
3792 /* Print information on user settable breakpoint (watchpoint, etc)
3793 number BNUM. If BNUM is -1 print all user settable breakpoints.
3794 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3797 breakpoint_1 (int bnum, int allflag)
3799 struct breakpoint *b;
3800 CORE_ADDR last_addr = (CORE_ADDR) -1;
3801 int nr_printable_breakpoints;
3802 struct cleanup *bkpttbl_chain;
3804 /* Compute the number of rows in the table. */
3805 nr_printable_breakpoints = 0;
3808 || bnum == b->number)
3810 if (allflag || user_settable_breakpoint (b))
3811 nr_printable_breakpoints++;
3816 = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints,
3820 = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints,
3823 if (nr_printable_breakpoints > 0)
3824 annotate_breakpoints_headers ();
3825 if (nr_printable_breakpoints > 0)
3827 ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */
3828 if (nr_printable_breakpoints > 0)
3830 ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */
3831 if (nr_printable_breakpoints > 0)
3833 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
3834 if (nr_printable_breakpoints > 0)
3836 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
3839 if (nr_printable_breakpoints > 0)
3841 if (gdbarch_addr_bit (current_gdbarch) <= 32)
3842 ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */
3844 ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */
3846 if (nr_printable_breakpoints > 0)
3848 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
3849 ui_out_table_body (uiout);
3850 if (nr_printable_breakpoints > 0)
3851 annotate_breakpoints_table ();
3855 || bnum == b->number)
3857 /* We only print out user settable breakpoints unless the
3859 if (allflag || user_settable_breakpoint (b))
3860 print_one_breakpoint (b, &last_addr);
3863 do_cleanups (bkpttbl_chain);
3865 if (nr_printable_breakpoints == 0)
3868 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
3870 ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n",
3875 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3876 that a comparison of an unsigned with -1 is always false. */
3877 if (last_addr != (CORE_ADDR) -1 && !server_command)
3878 set_next_address (last_addr);
3881 /* FIXME? Should this be moved up so that it is only called when
3882 there have been breakpoints? */
3883 annotate_breakpoints_table_end ();
3887 breakpoints_info (char *bnum_exp, int from_tty)
3892 bnum = parse_and_eval_long (bnum_exp);
3894 breakpoint_1 (bnum, 0);
3898 maintenance_info_breakpoints (char *bnum_exp, int from_tty)
3903 bnum = parse_and_eval_long (bnum_exp);
3905 breakpoint_1 (bnum, 1);
3909 breakpoint_has_pc (struct breakpoint *b, CORE_ADDR pc, asection *section)
3911 struct bp_location *bl = b->loc;
3912 for (; bl; bl = bl->next)
3914 if (bl->address == pc
3915 && (!overlay_debugging || bl->section == section))
3921 /* Print a message describing any breakpoints set at PC. */
3924 describe_other_breakpoints (CORE_ADDR pc, asection *section, int thread)
3927 struct breakpoint *b;
3930 others += breakpoint_has_pc (b, pc, section);
3934 printf_filtered (_("Note: breakpoint "));
3935 else /* if (others == ???) */
3936 printf_filtered (_("Note: breakpoints "));
3938 if (breakpoint_has_pc (b, pc, section))
3941 printf_filtered ("%d", b->number);
3942 if (b->thread == -1 && thread != -1)
3943 printf_filtered (" (all threads)");
3944 else if (b->thread != -1)
3945 printf_filtered (" (thread %d)", b->thread);
3946 printf_filtered ("%s%s ",
3947 ((b->enable_state == bp_disabled ||
3948 b->enable_state == bp_call_disabled)
3950 : b->enable_state == bp_permanent
3954 : ((others == 1) ? " and" : ""));
3956 printf_filtered (_("also set at pc "));
3957 fputs_filtered (paddress (pc), gdb_stdout);
3958 printf_filtered (".\n");
3962 /* Set the default place to put a breakpoint
3963 for the `break' command with no arguments. */
3966 set_default_breakpoint (int valid, CORE_ADDR addr, struct symtab *symtab,
3969 default_breakpoint_valid = valid;
3970 default_breakpoint_address = addr;
3971 default_breakpoint_symtab = symtab;
3972 default_breakpoint_line = line;
3975 /* Return true iff it is meaningful to use the address member of
3976 BPT. For some breakpoint types, the address member is irrelevant
3977 and it makes no sense to attempt to compare it to other addresses
3978 (or use it for any other purpose either).
3980 More specifically, each of the following breakpoint types will always
3981 have a zero valued address and we don't want check_duplicates() to mark
3982 breakpoints of any of these types to be a duplicate of an actual
3983 breakpoint at address zero:
3986 bp_hardware_watchpoint
3988 bp_access_watchpoint
3995 breakpoint_address_is_meaningful (struct breakpoint *bpt)
3997 enum bptype type = bpt->type;
3999 return (type != bp_watchpoint
4000 && type != bp_hardware_watchpoint
4001 && type != bp_read_watchpoint
4002 && type != bp_access_watchpoint
4003 && type != bp_catch_exec
4004 && type != bp_longjmp_resume
4005 && type != bp_catch_fork
4006 && type != bp_catch_vfork);
4009 /* Rescan breakpoints at the same address and section as BPT,
4010 marking the first one as "first" and any others as "duplicates".
4011 This is so that the bpt instruction is only inserted once.
4012 If we have a permanent breakpoint at the same place as BPT, make
4013 that one the official one, and the rest as duplicates. */
4016 check_duplicates_for (CORE_ADDR address, asection *section)
4018 struct bp_location *b;
4020 struct bp_location *perm_bp = 0;
4022 ALL_BP_LOCATIONS (b)
4023 if (b->owner->enable_state != bp_disabled
4024 && b->owner->enable_state != bp_call_disabled
4026 && !b->shlib_disabled
4027 && b->address == address /* address / overlay match */
4028 && (!overlay_debugging || b->section == section)
4029 && breakpoint_address_is_meaningful (b->owner))
4031 /* Have we found a permanent breakpoint? */
4032 if (b->owner->enable_state == bp_permanent)
4039 b->duplicate = count > 1;
4042 /* If we found a permanent breakpoint at this address, go over the
4043 list again and declare all the other breakpoints there to be the
4047 perm_bp->duplicate = 0;
4049 /* Permanent breakpoint should always be inserted. */
4050 if (! perm_bp->inserted)
4051 internal_error (__FILE__, __LINE__,
4052 _("allegedly permanent breakpoint is not "
4053 "actually inserted"));
4055 ALL_BP_LOCATIONS (b)
4058 if (b->owner->enable_state != bp_disabled
4059 && b->owner->enable_state != bp_call_disabled
4060 && b->enabled && !b->shlib_disabled
4061 && b->address == address /* address / overlay match */
4062 && (!overlay_debugging || b->section == section)
4063 && breakpoint_address_is_meaningful (b->owner))
4066 internal_error (__FILE__, __LINE__,
4067 _("another breakpoint was inserted on top of "
4068 "a permanent breakpoint"));
4077 check_duplicates (struct breakpoint *bpt)
4079 struct bp_location *bl = bpt->loc;
4081 if (! breakpoint_address_is_meaningful (bpt))
4084 for (; bl; bl = bl->next)
4085 check_duplicates_for (bl->address, bl->section);
4089 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
4090 int bnum, int have_bnum)
4095 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
4096 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
4098 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4099 bnum, astr1, astr2);
4101 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
4104 /* Adjust a breakpoint's address to account for architectural constraints
4105 on breakpoint placement. Return the adjusted address. Note: Very
4106 few targets require this kind of adjustment. For most targets,
4107 this function is simply the identity function. */
4110 adjust_breakpoint_address (CORE_ADDR bpaddr, enum bptype bptype)
4112 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch))
4114 /* Very few targets need any kind of breakpoint adjustment. */
4117 else if (bptype == bp_watchpoint
4118 || bptype == bp_hardware_watchpoint
4119 || bptype == bp_read_watchpoint
4120 || bptype == bp_access_watchpoint
4121 || bptype == bp_catch_fork
4122 || bptype == bp_catch_vfork
4123 || bptype == bp_catch_exec)
4125 /* Watchpoints and the various bp_catch_* eventpoints should not
4126 have their addresses modified. */
4131 CORE_ADDR adjusted_bpaddr;
4133 /* Some targets have architectural constraints on the placement
4134 of breakpoint instructions. Obtain the adjusted address. */
4135 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (current_gdbarch,
4138 /* An adjusted breakpoint address can significantly alter
4139 a user's expectations. Print a warning if an adjustment
4141 if (adjusted_bpaddr != bpaddr)
4142 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
4144 return adjusted_bpaddr;
4148 /* Allocate a struct bp_location. */
4150 static struct bp_location *
4151 allocate_bp_location (struct breakpoint *bpt, enum bptype bp_type)
4153 struct bp_location *loc, *loc_p;
4155 loc = xmalloc (sizeof (struct bp_location));
4156 memset (loc, 0, sizeof (*loc));
4160 loc->shlib_disabled = 0;
4169 case bp_longjmp_resume:
4170 case bp_step_resume:
4171 case bp_watchpoint_scope:
4173 case bp_shlib_event:
4174 case bp_thread_event:
4175 case bp_overlay_event:
4177 case bp_catch_unload:
4178 loc->loc_type = bp_loc_software_breakpoint;
4180 case bp_hardware_breakpoint:
4181 loc->loc_type = bp_loc_hardware_breakpoint;
4183 case bp_hardware_watchpoint:
4184 case bp_read_watchpoint:
4185 case bp_access_watchpoint:
4186 loc->loc_type = bp_loc_hardware_watchpoint;
4190 case bp_catch_vfork:
4192 loc->loc_type = bp_loc_other;
4195 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
4198 /* Add this breakpoint to the end of the chain. */
4200 loc_p = bp_location_chain;
4202 bp_location_chain = loc;
4205 while (loc_p->global_next)
4206 loc_p = loc_p->global_next;
4207 loc_p->global_next = loc;
4213 static void free_bp_location (struct bp_location *loc)
4220 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4221 that has type BPTYPE and has no locations as yet. */
4223 static struct breakpoint *
4224 set_raw_breakpoint_without_location (enum bptype bptype)
4226 struct breakpoint *b, *b1;
4228 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
4229 memset (b, 0, sizeof (*b));
4232 b->language = current_language->la_language;
4233 b->input_radix = input_radix;
4235 b->enable_state = bp_enabled;
4238 b->ignore_count = 0;
4240 b->frame_id = null_frame_id;
4241 b->dll_pathname = NULL;
4242 b->triggered_dll_pathname = NULL;
4243 b->forked_inferior_pid = 0;
4244 b->exec_pathname = NULL;
4246 b->condition_not_parsed = 0;
4248 /* Add this breakpoint to the end of the chain
4249 so that a list of breakpoints will come out in order
4250 of increasing numbers. */
4252 b1 = breakpoint_chain;
4254 breakpoint_chain = b;
4264 /* Initialize loc->function_name. */
4266 set_breakpoint_location_function (struct bp_location *loc)
4268 if (loc->owner->type == bp_breakpoint
4269 || loc->owner->type == bp_hardware_breakpoint)
4271 find_pc_partial_function (loc->address, &(loc->function_name),
4273 if (loc->function_name)
4274 loc->function_name = xstrdup (loc->function_name);
4278 /* set_raw_breakpoint is a low level routine for allocating and
4279 partially initializing a breakpoint of type BPTYPE. The newly
4280 created breakpoint's address, section, source file name, and line
4281 number are provided by SAL. The newly created and partially
4282 initialized breakpoint is added to the breakpoint chain and
4283 is also returned as the value of this function.
4285 It is expected that the caller will complete the initialization of
4286 the newly created breakpoint struct as well as output any status
4287 information regarding the creation of a new breakpoint. In
4288 particular, set_raw_breakpoint does NOT set the breakpoint
4289 number! Care should be taken to not allow an error to occur
4290 prior to completing the initialization of the breakpoint. If this
4291 should happen, a bogus breakpoint will be left on the chain. */
4294 set_raw_breakpoint (struct symtab_and_line sal, enum bptype bptype)
4296 struct breakpoint *b = set_raw_breakpoint_without_location (bptype);
4297 CORE_ADDR adjusted_address;
4299 /* Adjust the breakpoint's address prior to allocating a location.
4300 Once we call allocate_bp_location(), that mostly uninitialized
4301 location will be placed on the location chain. Adjustment of the
4302 breakpoint may cause target_read_memory() to be called and we do
4303 not want its scan of the location chain to find a breakpoint and
4304 location that's only been partially initialized. */
4305 adjusted_address = adjust_breakpoint_address (sal.pc, bptype);
4307 b->loc = allocate_bp_location (b, bptype);
4308 b->loc->requested_address = sal.pc;
4309 b->loc->address = adjusted_address;
4311 if (sal.symtab == NULL)
4312 b->source_file = NULL;
4314 b->source_file = savestring (sal.symtab->filename,
4315 strlen (sal.symtab->filename));
4316 b->loc->section = sal.section;
4317 b->line_number = sal.line;
4319 set_breakpoint_location_function (b->loc);
4321 check_duplicates (b);
4322 breakpoints_changed ();
4328 /* Note that the breakpoint object B describes a permanent breakpoint
4329 instruction, hard-wired into the inferior's code. */
4331 make_breakpoint_permanent (struct breakpoint *b)
4333 struct bp_location *bl;
4334 b->enable_state = bp_permanent;
4336 /* By definition, permanent breakpoints are already present in the code.
4337 Mark all locations as inserted. For now, make_breakpoint_permanent
4338 is called in just one place, so it's hard to say if it's reasonable
4339 to have permanent breakpoint with multiple locations or not,
4340 but it's easy to implmement. */
4341 for (bl = b->loc; bl; bl = bl->next)
4345 static struct breakpoint *
4346 create_internal_breakpoint (CORE_ADDR address, enum bptype type)
4348 static int internal_breakpoint_number = -1;
4349 struct symtab_and_line sal;
4350 struct breakpoint *b;
4352 init_sal (&sal); /* initialize to zeroes */
4355 sal.section = find_pc_overlay (sal.pc);
4357 b = set_raw_breakpoint (sal, type);
4358 b->number = internal_breakpoint_number--;
4359 b->disposition = disp_donttouch;
4366 create_longjmp_breakpoint (char *func_name)
4368 struct breakpoint *b;
4369 struct minimal_symbol *m;
4371 if (func_name == NULL)
4372 b = create_internal_breakpoint (0, bp_longjmp_resume);
4375 if ((m = lookup_minimal_symbol_text (func_name, NULL)) == NULL)
4378 b = create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m), bp_longjmp);
4381 b->enable_state = bp_disabled;
4384 b->addr_string = xstrdup (func_name);
4387 /* Call this routine when stepping and nexting to enable a breakpoint
4388 if we do a longjmp(). When we hit that breakpoint, call
4389 set_longjmp_resume_breakpoint() to figure out where we are going. */
4392 enable_longjmp_breakpoint (void)
4394 struct breakpoint *b;
4397 if (b->type == bp_longjmp)
4399 b->enable_state = bp_enabled;
4400 check_duplicates (b);
4405 disable_longjmp_breakpoint (void)
4407 struct breakpoint *b;
4410 if (b->type == bp_longjmp
4411 || b->type == bp_longjmp_resume)
4413 b->enable_state = bp_disabled;
4414 check_duplicates (b);
4419 create_overlay_event_breakpoint (char *func_name)
4421 struct breakpoint *b;
4422 struct minimal_symbol *m;
4424 if ((m = lookup_minimal_symbol_text (func_name, NULL)) == NULL)
4427 b = create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m),
4429 b->addr_string = xstrdup (func_name);
4431 if (overlay_debugging == ovly_auto)
4433 b->enable_state = bp_enabled;
4434 overlay_events_enabled = 1;
4438 b->enable_state = bp_disabled;
4439 overlay_events_enabled = 0;
4444 enable_overlay_breakpoints (void)
4446 struct breakpoint *b;
4449 if (b->type == bp_overlay_event)
4451 b->enable_state = bp_enabled;
4452 check_duplicates (b);
4453 overlay_events_enabled = 1;
4458 disable_overlay_breakpoints (void)
4460 struct breakpoint *b;
4463 if (b->type == bp_overlay_event)
4465 b->enable_state = bp_disabled;
4466 check_duplicates (b);
4467 overlay_events_enabled = 0;
4472 create_thread_event_breakpoint (CORE_ADDR address)
4474 struct breakpoint *b;
4476 b = create_internal_breakpoint (address, bp_thread_event);
4478 b->enable_state = bp_enabled;
4479 /* addr_string has to be used or breakpoint_re_set will delete me. */
4480 b->addr_string = xstrprintf ("*0x%s", paddr (b->loc->address));
4486 remove_thread_event_breakpoints (void)
4488 struct breakpoint *b, *temp;
4490 ALL_BREAKPOINTS_SAFE (b, temp)
4491 if (b->type == bp_thread_event)
4492 delete_breakpoint (b);
4495 struct captured_parse_breakpoint_args
4498 struct symtabs_and_lines *sals_p;
4499 char ***addr_string_p;
4503 struct lang_and_radix
4511 remove_solib_event_breakpoints (void)
4513 struct breakpoint *b, *temp;
4515 ALL_BREAKPOINTS_SAFE (b, temp)
4516 if (b->type == bp_shlib_event)
4517 delete_breakpoint (b);
4521 create_solib_event_breakpoint (CORE_ADDR address)
4523 struct breakpoint *b;
4525 b = create_internal_breakpoint (address, bp_shlib_event);
4529 /* Disable any breakpoints that are on code in shared libraries. Only
4530 apply to enabled breakpoints, disabled ones can just stay disabled. */
4533 disable_breakpoints_in_shlibs (void)
4535 struct bp_location *loc;
4536 int disabled_shlib_breaks = 0;
4538 ALL_BP_LOCATIONS (loc)
4540 struct breakpoint *b = loc->owner;
4541 /* We apply the check to all breakpoints, including disabled
4542 for those with loc->duplicate set. This is so that when breakpoint
4543 becomes enabled, or the duplicate is removed, gdb will try to insert
4544 all breakpoints. If we don't set shlib_disabled here, we'll try
4545 to insert those breakpoints and fail. */
4546 if (((b->type == bp_breakpoint) || (b->type == bp_hardware_breakpoint))
4547 && !loc->shlib_disabled
4549 && PC_SOLIB (loc->address)
4551 && solib_address (loc->address)
4555 loc->shlib_disabled = 1;
4560 /* Disable any breakpoints that are in in an unloaded shared library. Only
4561 apply to enabled breakpoints, disabled ones can just stay disabled. */
4564 disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
4566 struct bp_location *loc;
4567 int disabled_shlib_breaks = 0;
4569 ALL_BP_LOCATIONS (loc)
4571 struct breakpoint *b = loc->owner;
4572 if ((loc->loc_type == bp_loc_hardware_breakpoint
4573 || loc->loc_type == bp_loc_software_breakpoint)
4574 && !loc->shlib_disabled)
4577 char *so_name = PC_SOLIB (loc->address);
4579 char *so_name = solib_address (loc->address);
4581 if (so_name && !strcmp (so_name, solib->so_name))
4583 loc->shlib_disabled = 1;
4584 /* At this point, we cannot rely on remove_breakpoint
4585 succeeding so we must mark the breakpoint as not inserted
4586 to prevent future errors occurring in remove_breakpoints. */
4588 if (!disabled_shlib_breaks)
4590 target_terminal_ours_for_output ();
4591 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4594 disabled_shlib_breaks = 1;
4601 create_fork_vfork_event_catchpoint (int tempflag, char *cond_string,
4602 enum bptype bp_kind)
4604 struct symtab_and_line sal;
4605 struct breakpoint *b;
4606 int thread = -1; /* All threads. */
4613 b = set_raw_breakpoint (sal, bp_kind);
4614 set_breakpoint_count (breakpoint_count + 1);
4615 b->number = breakpoint_count;
4616 b->cond_string = (cond_string == NULL) ?
4617 NULL : savestring (cond_string, strlen (cond_string));
4619 b->addr_string = NULL;
4620 b->enable_state = bp_enabled;
4621 b->disposition = tempflag ? disp_del : disp_donttouch;
4622 b->forked_inferior_pid = 0;
4628 create_fork_event_catchpoint (int tempflag, char *cond_string)
4630 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_fork);
4634 create_vfork_event_catchpoint (int tempflag, char *cond_string)
4636 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_vfork);
4640 create_exec_event_catchpoint (int tempflag, char *cond_string)
4642 struct symtab_and_line sal;
4643 struct breakpoint *b;
4644 int thread = -1; /* All threads. */
4651 b = set_raw_breakpoint (sal, bp_catch_exec);
4652 set_breakpoint_count (breakpoint_count + 1);
4653 b->number = breakpoint_count;
4654 b->cond_string = (cond_string == NULL) ?
4655 NULL : savestring (cond_string, strlen (cond_string));
4657 b->addr_string = NULL;
4658 b->enable_state = bp_enabled;
4659 b->disposition = tempflag ? disp_del : disp_donttouch;
4665 hw_breakpoint_used_count (void)
4667 struct breakpoint *b;
4672 if (b->type == bp_hardware_breakpoint && b->enable_state == bp_enabled)
4680 hw_watchpoint_used_count (enum bptype type, int *other_type_used)
4682 struct breakpoint *b;
4685 *other_type_used = 0;
4688 if (breakpoint_enabled (b))
4690 if (b->type == type)
4692 else if ((b->type == bp_hardware_watchpoint ||
4693 b->type == bp_read_watchpoint ||
4694 b->type == bp_access_watchpoint))
4695 *other_type_used = 1;
4701 /* Call this after hitting the longjmp() breakpoint. Use this to set
4702 a new breakpoint at the target of the jmp_buf.
4704 FIXME - This ought to be done by setting a temporary breakpoint
4705 that gets deleted automatically... */
4708 set_longjmp_resume_breakpoint (CORE_ADDR pc, struct frame_id frame_id)
4710 struct breakpoint *b;
4713 if (b->type == bp_longjmp_resume)
4715 b->loc->requested_address = pc;
4716 b->loc->address = adjust_breakpoint_address (b->loc->requested_address,
4718 b->enable_state = bp_enabled;
4719 b->frame_id = frame_id;
4720 check_duplicates (b);
4726 disable_watchpoints_before_interactive_call_start (void)
4728 struct breakpoint *b;
4732 if (((b->type == bp_watchpoint)
4733 || (b->type == bp_hardware_watchpoint)
4734 || (b->type == bp_read_watchpoint)
4735 || (b->type == bp_access_watchpoint))
4736 && breakpoint_enabled (b))
4738 b->enable_state = bp_call_disabled;
4739 check_duplicates (b);
4745 enable_watchpoints_after_interactive_call_stop (void)
4747 struct breakpoint *b;
4751 if (((b->type == bp_watchpoint)
4752 || (b->type == bp_hardware_watchpoint)
4753 || (b->type == bp_read_watchpoint)
4754 || (b->type == bp_access_watchpoint))
4755 && (b->enable_state == bp_call_disabled))
4757 b->enable_state = bp_enabled;
4758 check_duplicates (b);
4764 /* Set a breakpoint that will evaporate an end of command
4765 at address specified by SAL.
4766 Restrict it to frame FRAME if FRAME is nonzero. */
4769 set_momentary_breakpoint (struct symtab_and_line sal, struct frame_id frame_id,
4772 struct breakpoint *b;
4773 b = set_raw_breakpoint (sal, type);
4774 b->enable_state = bp_enabled;
4775 b->disposition = disp_donttouch;
4776 b->frame_id = frame_id;
4778 /* If we're debugging a multi-threaded program, then we
4779 want momentary breakpoints to be active in only a
4780 single thread of control. */
4781 if (in_thread_list (inferior_ptid))
4782 b->thread = pid_to_thread_id (inferior_ptid);
4788 /* Tell the user we have just set a breakpoint B. */
4791 mention (struct breakpoint *b)
4794 struct cleanup *old_chain, *ui_out_chain;
4795 struct ui_stream *stb;
4797 stb = ui_out_stream_new (uiout);
4798 old_chain = make_cleanup_ui_out_stream_delete (stb);
4800 /* FIXME: This is misplaced; mention() is called by things (like
4801 hitting a watchpoint) other than breakpoint creation. It should
4802 be possible to clean this up and at the same time replace the
4803 random calls to breakpoint_changed with this hook, as has already
4804 been done for deprecated_delete_breakpoint_hook and so on. */
4805 if (deprecated_create_breakpoint_hook)
4806 deprecated_create_breakpoint_hook (b);
4807 breakpoint_create_event (b->number);
4809 if (b->ops != NULL && b->ops->print_mention != NULL)
4810 b->ops->print_mention (b);
4815 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b->number);
4818 ui_out_text (uiout, "Watchpoint ");
4819 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
4820 ui_out_field_int (uiout, "number", b->number);
4821 ui_out_text (uiout, ": ");
4822 print_expression (b->exp, stb->stream);
4823 ui_out_field_stream (uiout, "exp", stb);
4824 do_cleanups (ui_out_chain);
4826 case bp_hardware_watchpoint:
4827 ui_out_text (uiout, "Hardware watchpoint ");
4828 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
4829 ui_out_field_int (uiout, "number", b->number);
4830 ui_out_text (uiout, ": ");
4831 print_expression (b->exp, stb->stream);
4832 ui_out_field_stream (uiout, "exp", stb);
4833 do_cleanups (ui_out_chain);
4835 case bp_read_watchpoint:
4836 ui_out_text (uiout, "Hardware read watchpoint ");
4837 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
4838 ui_out_field_int (uiout, "number", b->number);
4839 ui_out_text (uiout, ": ");
4840 print_expression (b->exp, stb->stream);
4841 ui_out_field_stream (uiout, "exp", stb);
4842 do_cleanups (ui_out_chain);
4844 case bp_access_watchpoint:
4845 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
4846 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
4847 ui_out_field_int (uiout, "number", b->number);
4848 ui_out_text (uiout, ": ");
4849 print_expression (b->exp, stb->stream);
4850 ui_out_field_stream (uiout, "exp", stb);
4851 do_cleanups (ui_out_chain);
4854 if (ui_out_is_mi_like_p (uiout))
4859 if (b->disposition == disp_del)
4860 printf_filtered (_("Temporary breakpoint"));
4862 printf_filtered (_("Breakpoint"));
4863 printf_filtered (_(" %d"), b->number);
4866 case bp_hardware_breakpoint:
4867 if (ui_out_is_mi_like_p (uiout))
4872 printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
4876 case bp_catch_unload:
4877 printf_filtered (_("Catchpoint %d (%s %s)"),
4879 (b->type == bp_catch_load) ? "load" : "unload",
4880 (b->dll_pathname != NULL) ?
4881 b->dll_pathname : "<any library>");
4884 case bp_catch_vfork:
4885 printf_filtered (_("Catchpoint %d (%s)"),
4887 (b->type == bp_catch_fork) ? "fork" : "vfork");
4890 printf_filtered (_("Catchpoint %d (exec)"),
4897 case bp_longjmp_resume:
4898 case bp_step_resume:
4900 case bp_watchpoint_scope:
4901 case bp_shlib_event:
4902 case bp_thread_event:
4903 case bp_overlay_event:
4909 /* i18n: cagney/2005-02-11: Below needs to be merged into a
4913 printf_filtered (_(" (%s) pending."), b->addr_string);
4917 if (addressprint || b->source_file == NULL)
4919 printf_filtered (" at ");
4920 fputs_filtered (paddress (b->loc->address), gdb_stdout);
4923 printf_filtered (": file %s, line %d.",
4924 b->source_file, b->line_number);
4928 struct bp_location *loc = b->loc;
4930 for (; loc; loc = loc->next)
4932 printf_filtered (" (%d locations)", n);
4937 do_cleanups (old_chain);
4938 if (ui_out_is_mi_like_p (uiout))
4940 printf_filtered ("\n");
4944 static struct bp_location *
4945 add_location_to_breakpoint (struct breakpoint *b, enum bptype bptype,
4946 const struct symtab_and_line *sal)
4948 struct bp_location *loc, **tmp;
4950 loc = allocate_bp_location (b, bptype);
4951 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
4954 loc->requested_address = sal->pc;
4955 loc->address = adjust_breakpoint_address (loc->requested_address,
4957 loc->section = sal->section;
4959 set_breakpoint_location_function (loc);
4963 /* Create a breakpoint with SAL as location. Use ADDR_STRING
4964 as textual description of the location, and COND_STRING
4965 as condition expression. */
4968 create_breakpoint (struct symtabs_and_lines sals, char *addr_string,
4970 enum bptype type, enum bpdisp disposition,
4971 int thread, int ignore_count, int from_tty)
4973 struct breakpoint *b = NULL;
4976 if (type == bp_hardware_breakpoint)
4978 int i = hw_breakpoint_used_count ();
4979 int target_resources_ok =
4980 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
4982 if (target_resources_ok == 0)
4983 error (_("No hardware breakpoint support in the target."));
4984 else if (target_resources_ok < 0)
4985 error (_("Hardware breakpoints used exceeds limit."));
4988 for (i = 0; i < sals.nelts; ++i)
4990 struct symtab_and_line sal = sals.sals[i];
4991 struct bp_location *loc;
4994 describe_other_breakpoints (sal.pc, sal.section, thread);
4998 b = set_raw_breakpoint (sal, type);
4999 set_breakpoint_count (breakpoint_count + 1);
5000 b->number = breakpoint_count;
5003 b->cond_string = cond_string;
5004 b->ignore_count = ignore_count;
5005 b->enable_state = bp_enabled;
5006 b->disposition = disposition;
5012 loc = add_location_to_breakpoint (b, type, &sal);
5017 char *arg = b->cond_string;
5018 loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0);
5020 error (_("Garbage %s follows condition"), arg);
5025 b->addr_string = addr_string;
5027 /* addr_string has to be used or breakpoint_re_set will delete
5029 b->addr_string = xstrprintf ("*0x%s", paddr (b->loc->address));
5034 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
5035 elements to fill the void space. */
5036 static void remove_sal (struct symtabs_and_lines *sal, int index_to_remove)
5038 int i = index_to_remove+1;
5039 int last_index = sal->nelts-1;
5041 for (;i <= last_index; ++i)
5042 sal->sals[i-1] = sal->sals[i];
5047 /* If appropriate, obtains all sals that correspond
5048 to the same file and line as SAL. This is done
5049 only if SAL does not have explicit PC and has
5050 line and file information. If we got just a single
5051 expanded sal, return the original.
5053 Otherwise, if SAL.explicit_line is not set, filter out
5054 all sals for which the name of enclosing function
5055 is different from SAL. This makes sure that if we have
5056 breakpoint originally set in template instantiation, say
5057 foo<int>(), we won't expand SAL to locations at the same
5058 line in all existing instantiations of 'foo'.
5061 struct symtabs_and_lines
5062 expand_line_sal_maybe (struct symtab_and_line sal)
5064 struct symtabs_and_lines expanded;
5065 CORE_ADDR original_pc = sal.pc;
5066 char *original_function = NULL;
5070 /* If we have explicit pc, don't expand.
5071 If we have no line number, we can't expand. */
5072 if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL)
5075 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
5076 expanded.sals[0] = sal;
5081 find_pc_partial_function (original_pc, &original_function, NULL, NULL);
5083 expanded = expand_line_sal (sal);
5084 if (expanded.nelts == 1)
5086 /* We had one sal, we got one sal. Without futher
5087 processing, just return the original sal. */
5088 xfree (expanded.sals);
5090 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
5091 sal.pc = original_pc;
5092 expanded.sals[0] = sal;
5096 if (!sal.explicit_line)
5098 CORE_ADDR func_addr, func_end;
5099 for (i = 0; i < expanded.nelts; ++i)
5101 CORE_ADDR pc = expanded.sals[i].pc;
5102 char *this_function;
5103 if (find_pc_partial_function (pc, &this_function,
5104 &func_addr, &func_end))
5106 if (this_function &&
5107 strcmp (this_function, original_function) != 0)
5109 remove_sal (&expanded, i);
5112 else if (func_addr == pc)
5114 /* We're at beginning of a function, and should
5116 struct symbol *sym = find_pc_function (pc);
5118 expanded.sals[i] = find_function_start_sal (sym, 1);
5121 = gdbarch_skip_prologue (current_gdbarch, pc);
5128 if (expanded.nelts <= 1)
5130 /* This is un ugly workaround. If we get zero
5131 expanded sals then something is really wrong.
5132 Fix that by returnign the original sal. */
5133 xfree (expanded.sals);
5135 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
5136 sal.pc = original_pc;
5137 expanded.sals[0] = sal;
5144 for (i = 0; i < expanded.nelts; ++i)
5145 if (expanded.sals[i].pc == original_pc)
5156 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5157 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5158 value. COND_STRING, if not NULL, specified the condition to be
5159 used for all breakpoints. Essentially the only case where
5160 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
5161 function. In that case, it's still not possible to specify
5162 separate conditions for different overloaded functions, so
5163 we take just a single condition string.
5165 NOTE: If the function succeeds, the caller is expected to cleanup
5166 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
5167 array contents). If the function fails (error() is called), the
5168 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5169 COND and SALS arrays and each of those arrays contents. */
5172 create_breakpoints (struct symtabs_and_lines sals, char **addr_string,
5174 enum bptype type, enum bpdisp disposition,
5175 int thread, int ignore_count, int from_tty)
5178 for (i = 0; i < sals.nelts; ++i)
5180 struct symtabs_and_lines expanded =
5181 expand_line_sal_maybe (sals.sals[i]);
5183 create_breakpoint (expanded, addr_string[i],
5184 cond_string, type, disposition,
5185 thread, ignore_count, from_tty);
5189 /* Parse ARG which is assumed to be a SAL specification possibly
5190 followed by conditionals. On return, SALS contains an array of SAL
5191 addresses found. ADDR_STRING contains a vector of (canonical)
5192 address strings. ARG points to the end of the SAL. */
5195 parse_breakpoint_sals (char **address,
5196 struct symtabs_and_lines *sals,
5197 char ***addr_string,
5200 char *addr_start = *address;
5201 *addr_string = NULL;
5202 /* If no arg given, or if first arg is 'if ', use the default
5204 if ((*address) == NULL
5205 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
5207 if (default_breakpoint_valid)
5209 struct symtab_and_line sal;
5210 init_sal (&sal); /* initialize to zeroes */
5211 sals->sals = (struct symtab_and_line *)
5212 xmalloc (sizeof (struct symtab_and_line));
5213 sal.pc = default_breakpoint_address;
5214 sal.line = default_breakpoint_line;
5215 sal.symtab = default_breakpoint_symtab;
5216 sal.section = find_pc_overlay (sal.pc);
5217 sals->sals[0] = sal;
5221 error (_("No default breakpoint address now."));
5225 /* Force almost all breakpoints to be in terms of the
5226 current_source_symtab (which is decode_line_1's default). This
5227 should produce the results we want almost all of the time while
5228 leaving default_breakpoint_* alone.
5229 ObjC: However, don't match an Objective-C method name which
5230 may have a '+' or '-' succeeded by a '[' */
5232 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
5234 if (default_breakpoint_valid
5236 || ((strchr ("+-", (*address)[0]) != NULL)
5237 && ((*address)[1] != '['))))
5238 *sals = decode_line_1 (address, 1, default_breakpoint_symtab,
5239 default_breakpoint_line, addr_string,
5242 *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0,
5243 addr_string, not_found_ptr);
5245 /* For any SAL that didn't have a canonical string, fill one in. */
5246 if (sals->nelts > 0 && *addr_string == NULL)
5247 *addr_string = xcalloc (sals->nelts, sizeof (char **));
5248 if (addr_start != (*address))
5251 for (i = 0; i < sals->nelts; i++)
5253 /* Add the string if not present. */
5254 if ((*addr_string)[i] == NULL)
5255 (*addr_string)[i] = savestring (addr_start, (*address) - addr_start);
5261 /* Convert each SAL into a real PC. Verify that the PC can be
5262 inserted as a breakpoint. If it can't throw an error. */
5265 breakpoint_sals_to_pc (struct symtabs_and_lines *sals,
5269 for (i = 0; i < sals->nelts; i++)
5270 resolve_sal_pc (&sals->sals[i]);
5274 do_captured_parse_breakpoint (struct ui_out *ui, void *data)
5276 struct captured_parse_breakpoint_args *args = data;
5278 parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p,
5279 args->not_found_ptr);
5282 /* Given TOK, a string specification of condition and thread, as
5283 accepted by the 'break' command, extract the condition
5284 string and thread number and set *COND_STRING and *THREAD.
5285 PC identifies the context at which the condition should be parsed.
5286 If no condition is found, *COND_STRING is set to NULL.
5287 If no thread is found, *THREAD is set to -1. */
5289 find_condition_and_thread (char *tok, CORE_ADDR pc,
5290 char **cond_string, int *thread)
5292 *cond_string = NULL;
5298 char *cond_start = NULL;
5299 char *cond_end = NULL;
5300 while (*tok == ' ' || *tok == '\t')
5305 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
5308 toklen = end_tok - tok;
5310 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
5312 tok = cond_start = end_tok + 1;
5313 parse_exp_1 (&tok, block_for_pc (pc), 0);
5315 *cond_string = savestring (cond_start,
5316 cond_end - cond_start);
5318 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
5324 *thread = strtol (tok, &tok, 0);
5326 error (_("Junk after thread keyword."));
5327 if (!valid_thread_id (*thread))
5328 error (_("Unknown thread %d."), *thread);
5331 error (_("Junk at end of arguments."));
5335 /* Set a breakpoint. This function is shared between
5336 CLI and MI functions for setting a breakpoint.
5337 This function has two major modes of operations,
5338 selected by the PARSE_CONDITION_AND_THREAD parameter.
5339 If non-zero, the function will parse arg, extracting
5340 breakpoint location, address and thread. Otherwise,
5341 ARG is just the location of breakpoint, with condition
5342 and thread specified by the COND_STRING and THREAD
5346 break_command_really (char *arg, char *cond_string, int thread,
5347 int parse_condition_and_thread,
5348 int tempflag, int hardwareflag,
5350 enum auto_boolean pending_break_support,
5353 struct gdb_exception e;
5354 struct symtabs_and_lines sals;
5355 struct symtab_and_line pending_sal;
5358 char *addr_start = arg;
5360 struct cleanup *old_chain;
5361 struct cleanup *breakpoint_chain = NULL;
5362 struct captured_parse_breakpoint_args parse_args;
5371 parse_args.arg_p = &arg;
5372 parse_args.sals_p = &sals;
5373 parse_args.addr_string_p = &addr_string;
5374 parse_args.not_found_ptr = ¬_found;
5376 e = catch_exception (uiout, do_captured_parse_breakpoint,
5377 &parse_args, RETURN_MASK_ALL);
5379 /* If caller is interested in rc value from parse, set value. */
5383 throw_exception (e);
5387 case NOT_FOUND_ERROR:
5389 /* If pending breakpoint support is turned off, throw
5392 if (pending_break_support == AUTO_BOOLEAN_FALSE)
5393 throw_exception (e);
5395 exception_print (gdb_stderr, e);
5397 /* If pending breakpoint support is auto query and the user
5398 selects no, then simply return the error code. */
5399 if (pending_break_support == AUTO_BOOLEAN_AUTO &&
5400 !nquery ("Make breakpoint pending on future shared library load? "))
5403 /* At this point, either the user was queried about setting
5404 a pending breakpoint and selected yes, or pending
5405 breakpoint behavior is on and thus a pending breakpoint
5406 is defaulted on behalf of the user. */
5407 copy_arg = xstrdup (addr_start);
5408 addr_string = ©_arg;
5410 sals.sals = &pending_sal;
5415 throw_exception (e);
5422 /* Create a chain of things that always need to be cleaned up. */
5423 old_chain = make_cleanup (null_cleanup, 0);
5427 /* Make sure that all storage allocated to SALS gets freed. */
5428 make_cleanup (xfree, sals.sals);
5430 /* Cleanup the addr_string array but not its contents. */
5431 make_cleanup (xfree, addr_string);
5434 /* ----------------------------- SNIP -----------------------------
5435 Anything added to the cleanup chain beyond this point is assumed
5436 to be part of a breakpoint. If the breakpoint create succeeds
5437 then the memory is not reclaimed. */
5438 breakpoint_chain = make_cleanup (null_cleanup, 0);
5440 /* Mark the contents of the addr_string for cleanup. These go on
5441 the breakpoint_chain and only occure if the breakpoint create
5443 for (i = 0; i < sals.nelts; i++)
5445 if (addr_string[i] != NULL)
5446 make_cleanup (xfree, addr_string[i]);
5449 /* Resolve all line numbers to PC's and verify that the addresses
5450 are ok for the target. */
5452 breakpoint_sals_to_pc (&sals, addr_start);
5454 /* Verify that condition can be parsed, before setting any
5455 breakpoints. Allocate a separate condition expression for each
5459 if (parse_condition_and_thread)
5461 /* Here we only parse 'arg' to separate condition
5462 from thread number, so parsing in context of first
5463 sal is OK. When setting the breakpoint we'll
5464 re-parse it in context of each sal. */
5467 find_condition_and_thread (arg, sals.sals[0].pc, &cond_string, &thread);
5469 make_cleanup (xfree, cond_string);
5473 /* Create a private copy of condition string. */
5476 cond_string = xstrdup (cond_string);
5477 make_cleanup (xfree, cond_string);
5480 create_breakpoints (sals, addr_string, cond_string,
5481 hardwareflag ? bp_hardware_breakpoint
5483 tempflag ? disp_del : disp_donttouch,
5484 thread, ignore_count, from_tty);
5488 struct symtab_and_line sal = {0};
5489 struct breakpoint *b;
5491 make_cleanup (xfree, copy_arg);
5493 b = set_raw_breakpoint_without_location (hardwareflag
5494 ? bp_hardware_breakpoint
5496 set_breakpoint_count (breakpoint_count + 1);
5497 b->number = breakpoint_count;
5499 b->addr_string = addr_string[0];
5500 b->cond_string = NULL;
5501 b->ignore_count = ignore_count;
5502 b->disposition = tempflag ? disp_del : disp_donttouch;
5503 b->condition_not_parsed = 1;
5508 warning (_("Multiple breakpoints were set.\n"
5509 "Use the \"delete\" command to delete unwanted breakpoints."));
5510 /* That's it. Discard the cleanups for data inserted into the
5512 discard_cleanups (breakpoint_chain);
5513 /* But cleanup everything else. */
5514 do_cleanups (old_chain);
5517 /* Set a breakpoint.
5518 ARG is a string describing breakpoint address,
5519 condition, and thread.
5520 FLAG specifies if a breakpoint is hardware on,
5521 and if breakpoint is temporary, using BP_HARDWARE_FLAG
5525 break_command_1 (char *arg, int flag, int from_tty)
5527 int hardwareflag = flag & BP_HARDWAREFLAG;
5528 int tempflag = flag & BP_TEMPFLAG;
5530 break_command_really (arg,
5531 NULL, 0, 1 /* parse arg */,
5532 tempflag, hardwareflag,
5533 0 /* Ignore count */,
5534 pending_break_support, from_tty);
5539 set_breakpoint (char *address, char *condition,
5540 int hardwareflag, int tempflag,
5541 int thread, int ignore_count,
5544 break_command_really (address, condition, thread,
5545 0 /* condition and thread are valid. */,
5546 tempflag, hardwareflag,
5549 ? AUTO_BOOLEAN_TRUE : AUTO_BOOLEAN_FALSE,
5553 /* Adjust SAL to the first instruction past the function prologue.
5554 The end of the prologue is determined using the line table from
5555 the debugging information.
5557 If SAL is already past the prologue, then do nothing. */
5560 skip_prologue_sal (struct symtab_and_line *sal)
5562 struct symbol *sym = find_pc_function (sal->pc);
5563 struct symtab_and_line start_sal;
5568 start_sal = find_function_start_sal (sym, 1);
5569 if (sal->pc < start_sal.pc)
5573 /* Helper function for break_command_1 and disassemble_command. */
5576 resolve_sal_pc (struct symtab_and_line *sal)
5580 if (sal->pc == 0 && sal->symtab != NULL)
5582 if (!find_line_pc (sal->symtab, sal->line, &pc))
5583 error (_("No line %d in file \"%s\"."),
5584 sal->line, sal->symtab->filename);
5587 /* If this SAL corresponds to a breakpoint inserted using
5588 a line number, then skip the function prologue if necessary. */
5589 if (sal->explicit_line)
5590 skip_prologue_sal (sal);
5593 if (sal->section == 0 && sal->symtab != NULL)
5595 struct blockvector *bv;
5599 bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab);
5602 sym = block_function (b);
5605 fixup_symbol_section (sym, sal->symtab->objfile);
5606 sal->section = SYMBOL_BFD_SECTION (sym);
5610 /* It really is worthwhile to have the section, so we'll just
5611 have to look harder. This case can be executed if we have
5612 line numbers but no functions (as can happen in assembly
5615 struct minimal_symbol *msym;
5617 msym = lookup_minimal_symbol_by_pc (sal->pc);
5619 sal->section = SYMBOL_BFD_SECTION (msym);
5626 break_command (char *arg, int from_tty)
5628 break_command_1 (arg, 0, from_tty);
5632 tbreak_command (char *arg, int from_tty)
5634 break_command_1 (arg, BP_TEMPFLAG, from_tty);
5638 hbreak_command (char *arg, int from_tty)
5640 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
5644 thbreak_command (char *arg, int from_tty)
5646 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
5650 stop_command (char *arg, int from_tty)
5652 printf_filtered (_("Specify the type of breakpoint to set.\n\
5653 Usage: stop in <function | address>\n\
5654 stop at <line>\n"));
5658 stopin_command (char *arg, int from_tty)
5662 if (arg == (char *) NULL)
5664 else if (*arg != '*')
5669 /* look for a ':'. If this is a line number specification, then
5670 say it is bad, otherwise, it should be an address or
5671 function/method name */
5672 while (*argptr && !hasColon)
5674 hasColon = (*argptr == ':');
5679 badInput = (*argptr != ':'); /* Not a class::method */
5681 badInput = isdigit (*arg); /* a simple line number */
5685 printf_filtered (_("Usage: stop in <function | address>\n"));
5687 break_command_1 (arg, 0, from_tty);
5691 stopat_command (char *arg, int from_tty)
5695 if (arg == (char *) NULL || *arg == '*') /* no line number */
5702 /* look for a ':'. If there is a '::' then get out, otherwise
5703 it is probably a line number. */
5704 while (*argptr && !hasColon)
5706 hasColon = (*argptr == ':');
5711 badInput = (*argptr == ':'); /* we have class::method */
5713 badInput = !isdigit (*arg); /* not a line number */
5717 printf_filtered (_("Usage: stop at <line>\n"));
5719 break_command_1 (arg, 0, from_tty);
5722 /* accessflag: hw_write: watch write,
5723 hw_read: watch read,
5724 hw_access: watch access (read or write) */
5726 watch_command_1 (char *arg, int accessflag, int from_tty)
5728 struct breakpoint *b, *scope_breakpoint = NULL;
5729 struct symtab_and_line sal;
5730 struct expression *exp;
5731 struct block *exp_valid_block;
5732 struct value *val, *mark;
5733 struct frame_info *frame;
5734 struct frame_info *prev_frame = NULL;
5735 char *exp_start = NULL;
5736 char *exp_end = NULL;
5737 char *tok, *id_tok_start, *end_tok;
5739 char *cond_start = NULL;
5740 char *cond_end = NULL;
5741 struct expression *cond = NULL;
5742 int i, other_type_used, target_resources_ok = 0;
5743 enum bptype bp_type;
5747 init_sal (&sal); /* initialize to zeroes */
5749 /* Make sure that we actually have parameters to parse. */
5750 if (arg != NULL && arg[0] != '\0')
5752 toklen = strlen (arg); /* Size of argument list. */
5754 /* Points tok to the end of the argument list. */
5755 tok = arg + toklen - 1;
5757 /* Go backwards in the parameters list. Skip the last parameter.
5758 If we're expecting a 'thread <thread_num>' parameter, this should
5759 be the thread identifier. */
5760 while (tok > arg && (*tok == ' ' || *tok == '\t'))
5762 while (tok > arg && (*tok != ' ' && *tok != '\t'))
5765 /* Points end_tok to the beginning of the last token. */
5766 id_tok_start = tok + 1;
5768 /* Go backwards in the parameters list. Skip one more parameter.
5769 If we're expecting a 'thread <thread_num>' parameter, we should
5770 reach a "thread" token. */
5771 while (tok > arg && (*tok == ' ' || *tok == '\t'))
5776 while (tok > arg && (*tok != ' ' && *tok != '\t'))
5779 /* Move the pointer forward to skip the whitespace and
5780 calculate the length of the token. */
5782 toklen = end_tok - tok;
5784 if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
5786 /* At this point we've found a "thread" token, which means
5787 the user is trying to set a watchpoint that triggers
5788 only in a specific thread. */
5791 /* Extract the thread ID from the next token. */
5792 thread = strtol (id_tok_start, &endp, 0);
5794 /* Check if the user provided a valid numeric value for the
5796 if (*endp != ' ' && *endp != '\t' && *endp != '\0')
5797 error (_("Invalid thread ID specification %s."), id_tok_start);
5799 /* Check if the thread actually exists. */
5800 if (!valid_thread_id (thread))
5801 error (_("Unknown thread %d."), thread);
5803 /* Truncate the string and get rid of the thread <thread_num>
5804 parameter before the parameter list is parsed by the
5805 evaluate_expression() function. */
5810 /* Parse the rest of the arguments. */
5811 innermost_block = NULL;
5813 exp = parse_exp_1 (&arg, 0, 0);
5815 exp_valid_block = innermost_block;
5816 mark = value_mark ();
5817 fetch_watchpoint_value (exp, &val, NULL, NULL);
5819 release_value (val);
5822 while (*tok == ' ' || *tok == '\t')
5826 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
5829 toklen = end_tok - tok;
5830 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
5832 tok = cond_start = end_tok + 1;
5833 cond = parse_exp_1 (&tok, 0, 0);
5837 error (_("Junk at end of command."));
5839 if (accessflag == hw_read)
5840 bp_type = bp_read_watchpoint;
5841 else if (accessflag == hw_access)
5842 bp_type = bp_access_watchpoint;
5844 bp_type = bp_hardware_watchpoint;
5846 mem_cnt = can_use_hardware_watchpoint (val);
5847 if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
5848 error (_("Expression cannot be implemented with read/access watchpoint."));
5851 i = hw_watchpoint_used_count (bp_type, &other_type_used);
5852 target_resources_ok =
5853 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type, i + mem_cnt,
5855 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
5856 error (_("Target does not support this type of hardware watchpoint."));
5858 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
5859 error (_("Target can only support one kind of HW watchpoint at a time."));
5862 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5863 watchpoint could not be set. */
5864 if (!mem_cnt || target_resources_ok <= 0)
5865 bp_type = bp_watchpoint;
5867 frame = block_innermost_frame (exp_valid_block);
5869 prev_frame = get_prev_frame (frame);
5873 /* If the expression is "local", then set up a "watchpoint scope"
5874 breakpoint at the point where we've left the scope of the watchpoint
5875 expression. Create the scope breakpoint before the watchpoint, so
5876 that we will encounter it first in bpstat_stop_status. */
5877 if (innermost_block && prev_frame)
5879 scope_breakpoint = create_internal_breakpoint (get_frame_pc (prev_frame),
5880 bp_watchpoint_scope);
5882 scope_breakpoint->enable_state = bp_enabled;
5884 /* Automatically delete the breakpoint when it hits. */
5885 scope_breakpoint->disposition = disp_del;
5887 /* Only break in the proper frame (help with recursion). */
5888 scope_breakpoint->frame_id = get_frame_id (prev_frame);
5890 /* Set the address at which we will stop. */
5891 scope_breakpoint->loc->requested_address
5892 = get_frame_pc (prev_frame);
5893 scope_breakpoint->loc->address
5894 = adjust_breakpoint_address (scope_breakpoint->loc->requested_address,
5895 scope_breakpoint->type);
5898 /* Now set up the breakpoint. */
5899 b = set_raw_breakpoint (sal, bp_type);
5900 set_breakpoint_count (breakpoint_count + 1);
5901 b->number = breakpoint_count;
5903 b->disposition = disp_donttouch;
5905 b->exp_valid_block = exp_valid_block;
5906 b->exp_string = savestring (exp_start, exp_end - exp_start);
5909 b->loc->cond = cond;
5911 b->cond_string = savestring (cond_start, cond_end - cond_start);
5916 b->watchpoint_frame = get_frame_id (frame);
5918 b->watchpoint_frame = null_frame_id;
5920 if (scope_breakpoint != NULL)
5922 /* The scope breakpoint is related to the watchpoint. We will
5923 need to act on them together. */
5924 b->related_breakpoint = scope_breakpoint;
5925 scope_breakpoint->related_breakpoint = b;
5928 value_free_to_mark (mark);
5932 /* Return count of locations need to be watched and can be handled
5933 in hardware. If the watchpoint can not be handled
5934 in hardware return zero. */
5937 can_use_hardware_watchpoint (struct value *v)
5939 int found_memory_cnt = 0;
5940 struct value *head = v;
5942 /* Did the user specifically forbid us to use hardware watchpoints? */
5943 if (!can_use_hw_watchpoints)
5946 /* Make sure that the value of the expression depends only upon
5947 memory contents, and values computed from them within GDB. If we
5948 find any register references or function calls, we can't use a
5949 hardware watchpoint.
5951 The idea here is that evaluating an expression generates a series
5952 of values, one holding the value of every subexpression. (The
5953 expression a*b+c has five subexpressions: a, b, a*b, c, and
5954 a*b+c.) GDB's values hold almost enough information to establish
5955 the criteria given above --- they identify memory lvalues,
5956 register lvalues, computed values, etcetera. So we can evaluate
5957 the expression, and then scan the chain of values that leaves
5958 behind to decide whether we can detect any possible change to the
5959 expression's final value using only hardware watchpoints.
5961 However, I don't think that the values returned by inferior
5962 function calls are special in any way. So this function may not
5963 notice that an expression involving an inferior function call
5964 can't be watched with hardware watchpoints. FIXME. */
5965 for (; v; v = value_next (v))
5967 if (VALUE_LVAL (v) == lval_memory)
5970 /* A lazy memory lvalue is one that GDB never needed to fetch;
5971 we either just used its address (e.g., `a' in `a.b') or
5972 we never needed it at all (e.g., `a' in `a,b'). */
5976 /* Ahh, memory we actually used! Check if we can cover
5977 it with hardware watchpoints. */
5978 struct type *vtype = check_typedef (value_type (v));
5980 /* We only watch structs and arrays if user asked for it
5981 explicitly, never if they just happen to appear in a
5982 middle of some value chain. */
5984 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
5985 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
5987 CORE_ADDR vaddr = VALUE_ADDRESS (v) + value_offset (v);
5988 int len = TYPE_LENGTH (value_type (v));
5990 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr, len))
5997 else if (VALUE_LVAL (v) != not_lval
5998 && deprecated_value_modifiable (v) == 0)
5999 return 0; /* ??? What does this represent? */
6000 else if (VALUE_LVAL (v) == lval_register)
6001 return 0; /* cannot watch a register with a HW watchpoint */
6004 /* The expression itself looks suitable for using a hardware
6005 watchpoint, but give the target machine a chance to reject it. */
6006 return found_memory_cnt;
6010 watch_command_wrapper (char *arg, int from_tty)
6012 watch_command (arg, from_tty);
6016 watch_command (char *arg, int from_tty)
6018 watch_command_1 (arg, hw_write, from_tty);
6022 rwatch_command_wrapper (char *arg, int from_tty)
6024 rwatch_command (arg, from_tty);
6028 rwatch_command (char *arg, int from_tty)
6030 watch_command_1 (arg, hw_read, from_tty);
6034 awatch_command_wrapper (char *arg, int from_tty)
6036 awatch_command (arg, from_tty);
6040 awatch_command (char *arg, int from_tty)
6042 watch_command_1 (arg, hw_access, from_tty);
6046 /* Helper routines for the until_command routine in infcmd.c. Here
6047 because it uses the mechanisms of breakpoints. */
6049 /* This function is called by fetch_inferior_event via the
6050 cmd_continuation pointer, to complete the until command. It takes
6051 care of cleaning up the temporary breakpoints set up by the until
6054 until_break_command_continuation (struct continuation_arg *arg)
6056 struct cleanup *cleanups;
6058 cleanups = (struct cleanup *) arg->data.pointer;
6059 do_exec_cleanups (cleanups);
6063 until_break_command (char *arg, int from_tty, int anywhere)
6065 struct symtabs_and_lines sals;
6066 struct symtab_and_line sal;
6067 struct frame_info *frame = get_selected_frame (NULL);
6068 struct frame_info *prev_frame = get_prev_frame (frame);
6069 struct breakpoint *breakpoint;
6070 struct cleanup *old_chain;
6071 struct continuation_arg *arg1;
6074 clear_proceed_status ();
6076 /* Set a breakpoint where the user wants it and at return from
6079 if (default_breakpoint_valid)
6080 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
6081 default_breakpoint_line, (char ***) NULL, NULL);
6083 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL,
6084 0, (char ***) NULL, NULL);
6086 if (sals.nelts != 1)
6087 error (_("Couldn't get information on specified line."));
6090 xfree (sals.sals); /* malloc'd, so freed */
6093 error (_("Junk at end of arguments."));
6095 resolve_sal_pc (&sal);
6098 /* If the user told us to continue until a specified location,
6099 we don't specify a frame at which we need to stop. */
6100 breakpoint = set_momentary_breakpoint (sal, null_frame_id, bp_until);
6102 /* Otherwise, specify the current frame, because we want to stop only
6103 at the very same frame. */
6104 breakpoint = set_momentary_breakpoint (sal, get_frame_id (frame),
6107 if (!target_can_async_p ())
6108 old_chain = make_cleanup_delete_breakpoint (breakpoint);
6110 old_chain = make_exec_cleanup_delete_breakpoint (breakpoint);
6112 /* If we are running asynchronously, and the target supports async
6113 execution, we are not waiting for the target to stop, in the call
6114 tp proceed, below. This means that we cannot delete the
6115 brekpoints until the target has actually stopped. The only place
6116 where we get a chance to do that is in fetch_inferior_event, so
6117 we must set things up for that. */
6119 if (target_can_async_p ())
6121 /* In this case the arg for the continuation is just the point
6122 in the exec_cleanups chain from where to start doing
6123 cleanups, because all the continuation does is the cleanups in
6124 the exec_cleanup_chain. */
6126 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
6128 arg1->data.pointer = old_chain;
6130 add_continuation (until_break_command_continuation, arg1);
6133 /* Keep within the current frame, or in frames called by the current
6137 sal = find_pc_line (get_frame_pc (prev_frame), 0);
6138 sal.pc = get_frame_pc (prev_frame);
6139 breakpoint = set_momentary_breakpoint (sal, get_frame_id (prev_frame),
6141 if (!target_can_async_p ())
6142 make_cleanup_delete_breakpoint (breakpoint);
6144 make_exec_cleanup_delete_breakpoint (breakpoint);
6147 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
6148 /* Do the cleanups now, anly if we are not running asynchronously,
6149 of if we are, but the target is still synchronous. */
6150 if (!target_can_async_p ())
6151 do_cleanups (old_chain);
6155 ep_skip_leading_whitespace (char **s)
6157 if ((s == NULL) || (*s == NULL))
6159 while (isspace (**s))
6163 /* This function examines a string, and attempts to find a token
6164 that might be an event name in the leading characters. If a
6165 possible match is found, a pointer to the last character of
6166 the token is returned. Else, NULL is returned. */
6169 ep_find_event_name_end (char *arg)
6172 char *event_name_end = NULL;
6174 /* If we could depend upon the presense of strrpbrk, we'd use that... */
6178 /* We break out of the loop when we find a token delimiter.
6179 Basically, we're looking for alphanumerics and underscores;
6180 anything else delimites the token. */
6183 if (!isalnum (*s) && (*s != '_'))
6189 return event_name_end;
6193 /* This function attempts to parse an optional "if <cond>" clause
6194 from the arg string. If one is not found, it returns NULL.
6196 Else, it returns a pointer to the condition string. (It does not
6197 attempt to evaluate the string against a particular block.) And,
6198 it updates arg to point to the first character following the parsed
6199 if clause in the arg string. */
6202 ep_parse_optional_if_clause (char **arg)
6206 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
6209 /* Skip the "if" keyword. */
6212 /* Skip any extra leading whitespace, and record the start of the
6213 condition string. */
6214 ep_skip_leading_whitespace (arg);
6217 /* Assume that the condition occupies the remainder of the arg string. */
6218 (*arg) += strlen (cond_string);
6223 /* This function attempts to parse an optional filename from the arg
6224 string. If one is not found, it returns NULL.
6226 Else, it returns a pointer to the parsed filename. (This function
6227 makes no attempt to verify that a file of that name exists, or is
6228 accessible.) And, it updates arg to point to the first character
6229 following the parsed filename in the arg string.
6231 Note that clients needing to preserve the returned filename for
6232 future access should copy it to their own buffers. */
6234 ep_parse_optional_filename (char **arg)
6236 static char filename[1024];
6241 if ((*arg_p == '\0') || isspace (*arg_p))
6259 /* Commands to deal with catching events, such as signals, exceptions,
6260 process start/exit, etc. */
6264 catch_fork, catch_vfork
6269 catch_fork_command_1 (catch_fork_kind fork_kind, char *arg, int tempflag,
6272 char *cond_string = NULL;
6274 ep_skip_leading_whitespace (&arg);
6276 /* The allowed syntax is:
6278 catch [v]fork if <cond>
6280 First, check if there's an if clause. */
6281 cond_string = ep_parse_optional_if_clause (&arg);
6283 if ((*arg != '\0') && !isspace (*arg))
6284 error (_("Junk at end of arguments."));
6286 /* If this target supports it, create a fork or vfork catchpoint
6287 and enable reporting of such events. */
6291 create_fork_event_catchpoint (tempflag, cond_string);
6294 create_vfork_event_catchpoint (tempflag, cond_string);
6297 error (_("unsupported or unknown fork kind; cannot catch it"));
6303 catch_exec_command_1 (char *arg, int tempflag, int from_tty)
6305 char *cond_string = NULL;
6307 ep_skip_leading_whitespace (&arg);
6309 /* The allowed syntax is:
6311 catch exec if <cond>
6313 First, check if there's an if clause. */
6314 cond_string = ep_parse_optional_if_clause (&arg);
6316 if ((*arg != '\0') && !isspace (*arg))
6317 error (_("Junk at end of arguments."));
6319 /* If this target supports it, create an exec catchpoint
6320 and enable reporting of such events. */
6321 create_exec_event_catchpoint (tempflag, cond_string);
6325 catch_load_command_1 (char *arg, int tempflag, int from_tty)
6327 char *dll_pathname = NULL;
6328 char *cond_string = NULL;
6330 ep_skip_leading_whitespace (&arg);
6332 /* The allowed syntax is:
6334 catch load if <cond>
6335 catch load <filename>
6336 catch load <filename> if <cond>
6338 The user is not allowed to specify the <filename> after an
6341 We'll ignore the pathological case of a file named "if".
6343 First, check if there's an if clause. If so, then there
6344 cannot be a filename. */
6345 cond_string = ep_parse_optional_if_clause (&arg);
6347 /* If there was an if clause, then there cannot be a filename.
6348 Else, there might be a filename and an if clause. */
6349 if (cond_string == NULL)
6351 dll_pathname = ep_parse_optional_filename (&arg);
6352 ep_skip_leading_whitespace (&arg);
6353 cond_string = ep_parse_optional_if_clause (&arg);
6356 if ((*arg != '\0') && !isspace (*arg))
6357 error (_("Junk at end of arguments."));
6359 /* Create a load breakpoint that only triggers when a load of
6360 the specified dll (or any dll, if no pathname was specified)
6362 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid), tempflag,
6363 dll_pathname, cond_string);
6367 catch_unload_command_1 (char *arg, int tempflag, int from_tty)
6369 char *dll_pathname = NULL;
6370 char *cond_string = NULL;
6372 ep_skip_leading_whitespace (&arg);
6374 /* The allowed syntax is:
6376 catch unload if <cond>
6377 catch unload <filename>
6378 catch unload <filename> if <cond>
6380 The user is not allowed to specify the <filename> after an
6383 We'll ignore the pathological case of a file named "if".
6385 First, check if there's an if clause. If so, then there
6386 cannot be a filename. */
6387 cond_string = ep_parse_optional_if_clause (&arg);
6389 /* If there was an if clause, then there cannot be a filename.
6390 Else, there might be a filename and an if clause. */
6391 if (cond_string == NULL)
6393 dll_pathname = ep_parse_optional_filename (&arg);
6394 ep_skip_leading_whitespace (&arg);
6395 cond_string = ep_parse_optional_if_clause (&arg);
6398 if ((*arg != '\0') && !isspace (*arg))
6399 error (_("Junk at end of arguments."));
6401 /* Create an unload breakpoint that only triggers when an unload of
6402 the specified dll (or any dll, if no pathname was specified)
6404 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid), tempflag,
6405 dll_pathname, cond_string);
6408 static enum print_stop_action
6409 print_exception_catchpoint (struct breakpoint *b)
6411 annotate_catchpoint (b->number);
6413 if (strstr (b->addr_string, "throw") != NULL)
6414 printf_filtered (_("\nCatchpoint %d (exception thrown)\n"),
6417 printf_filtered (_("\nCatchpoint %d (exception caught)\n"),
6420 return PRINT_SRC_AND_LOC;
6424 print_one_exception_catchpoint (struct breakpoint *b, CORE_ADDR *last_addr)
6429 ui_out_field_core_addr (uiout, "addr", b->loc->address);
6432 *last_addr = b->loc->address;
6433 if (strstr (b->addr_string, "throw") != NULL)
6434 ui_out_field_string (uiout, "what", "exception throw");
6436 ui_out_field_string (uiout, "what", "exception catch");
6440 print_mention_exception_catchpoint (struct breakpoint *b)
6442 if (strstr (b->addr_string, "throw") != NULL)
6443 printf_filtered (_("Catchpoint %d (throw)"), b->number);
6445 printf_filtered (_("Catchpoint %d (catch)"), b->number);
6448 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = {
6449 print_exception_catchpoint,
6450 print_one_exception_catchpoint,
6451 print_mention_exception_catchpoint
6455 handle_gnu_v3_exceptions (int tempflag, char *cond_string,
6456 enum exception_event_kind ex_event, int from_tty)
6458 char *trigger_func_name, *nameptr;
6459 struct symtabs_and_lines sals;
6460 struct breakpoint *b;
6462 if (ex_event == EX_EVENT_CATCH)
6463 trigger_func_name = xstrdup ("__cxa_begin_catch");
6465 trigger_func_name = xstrdup ("__cxa_throw");
6467 nameptr = trigger_func_name;
6468 sals = decode_line_1 (&nameptr, 1, NULL, 0, NULL, NULL);
6469 if (sals.nelts == 0)
6471 xfree (trigger_func_name);
6475 b = set_raw_breakpoint (sals.sals[0], bp_breakpoint);
6476 set_breakpoint_count (breakpoint_count + 1);
6477 b->number = breakpoint_count;
6478 b->cond_string = (cond_string == NULL) ?
6479 NULL : savestring (cond_string, strlen (cond_string));
6481 b->addr_string = trigger_func_name;
6482 b->enable_state = bp_enabled;
6483 b->disposition = tempflag ? disp_del : disp_donttouch;
6484 b->ops = &gnu_v3_exception_catchpoint_ops;
6491 /* Deal with "catch catch" and "catch throw" commands */
6494 catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
6495 int tempflag, int from_tty)
6497 char *cond_string = NULL;
6498 struct symtab_and_line *sal = NULL;
6500 ep_skip_leading_whitespace (&arg);
6502 cond_string = ep_parse_optional_if_clause (&arg);
6504 if ((*arg != '\0') && !isspace (*arg))
6505 error (_("Junk at end of arguments."));
6507 if ((ex_event != EX_EVENT_THROW) &&
6508 (ex_event != EX_EVENT_CATCH))
6509 error (_("Unsupported or unknown exception event; cannot catch it"));
6511 if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty))
6514 warning (_("Unsupported with this platform/compiler combination."));
6517 /* Create a breakpoint struct for Ada exception catchpoints. */
6520 create_ada_exception_breakpoint (struct symtab_and_line sal,
6524 struct expression *cond,
6525 struct breakpoint_ops *ops,
6529 struct breakpoint *b;
6533 describe_other_breakpoints (sal.pc, sal.section, -1);
6534 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
6535 version for exception catchpoints, because two catchpoints
6536 used for different exception names will use the same address.
6537 In this case, a "breakpoint ... also set at..." warning is
6538 unproductive. Besides. the warning phrasing is also a bit
6539 inapropriate, we should use the word catchpoint, and tell
6540 the user what type of catchpoint it is. The above is good
6541 enough for now, though. */
6544 b = set_raw_breakpoint (sal, bp_breakpoint);
6545 set_breakpoint_count (breakpoint_count + 1);
6547 b->enable_state = bp_enabled;
6548 b->disposition = tempflag ? disp_del : disp_donttouch;
6549 b->number = breakpoint_count;
6550 b->ignore_count = 0;
6551 b->loc->cond = cond;
6552 b->addr_string = addr_string;
6553 b->language = language_ada;
6554 b->cond_string = cond_string;
6555 b->exp_string = exp_string;
6562 /* Implement the "catch exception" command. */
6565 catch_ada_exception_command (char *arg, int tempflag, int from_tty)
6567 struct symtab_and_line sal;
6569 char *addr_string = NULL;
6570 char *exp_string = NULL;
6571 char *cond_string = NULL;
6572 struct expression *cond = NULL;
6573 struct breakpoint_ops *ops = NULL;
6575 sal = ada_decode_exception_location (arg, &addr_string, &exp_string,
6576 &cond_string, &cond, &ops);
6577 create_ada_exception_breakpoint (sal, addr_string, exp_string,
6578 cond_string, cond, ops, tempflag,
6582 /* Implement the "catch assert" command. */
6585 catch_assert_command (char *arg, int tempflag, int from_tty)
6587 struct symtab_and_line sal;
6588 char *addr_string = NULL;
6589 struct breakpoint_ops *ops = NULL;
6591 sal = ada_decode_assert_location (arg, &addr_string, &ops);
6592 create_ada_exception_breakpoint (sal, addr_string, NULL, NULL, NULL, ops,
6593 tempflag, from_tty);
6597 catch_command_1 (char *arg, int tempflag, int from_tty)
6600 /* The first argument may be an event name, such as "start" or "load".
6601 If so, then handle it as such. If it doesn't match an event name,
6602 then attempt to interpret it as an exception name. (This latter is
6603 the v4.16-and-earlier GDB meaning of the "catch" command.)
6605 First, try to find the bounds of what might be an event name. */
6606 char *arg1_start = arg;
6610 if (arg1_start == NULL)
6612 /* Old behaviour was to use pre-v-4.16 syntax */
6613 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6615 /* Now, this is not allowed */
6616 error (_("Catch requires an event name."));
6619 arg1_end = ep_find_event_name_end (arg1_start);
6620 if (arg1_end == NULL)
6621 error (_("catch requires an event"));
6622 arg1_length = arg1_end + 1 - arg1_start;
6624 /* Try to match what we found against known event names. */
6625 if (strncmp (arg1_start, "signal", arg1_length) == 0)
6627 error (_("Catch of signal not yet implemented"));
6629 else if (strncmp (arg1_start, "catch", arg1_length) == 0)
6631 catch_exception_command_1 (EX_EVENT_CATCH, arg1_end + 1,
6632 tempflag, from_tty);
6634 else if (strncmp (arg1_start, "throw", arg1_length) == 0)
6636 catch_exception_command_1 (EX_EVENT_THROW, arg1_end + 1,
6637 tempflag, from_tty);
6639 else if (strncmp (arg1_start, "thread_start", arg1_length) == 0)
6641 error (_("Catch of thread_start not yet implemented"));
6643 else if (strncmp (arg1_start, "thread_exit", arg1_length) == 0)
6645 error (_("Catch of thread_exit not yet implemented"));
6647 else if (strncmp (arg1_start, "thread_join", arg1_length) == 0)
6649 error (_("Catch of thread_join not yet implemented"));
6651 else if (strncmp (arg1_start, "start", arg1_length) == 0)
6653 error (_("Catch of start not yet implemented"));
6655 else if (strncmp (arg1_start, "exit", arg1_length) == 0)
6657 error (_("Catch of exit not yet implemented"));
6659 else if (strncmp (arg1_start, "fork", arg1_length) == 0)
6661 catch_fork_command_1 (catch_fork, arg1_end + 1, tempflag, from_tty);
6663 else if (strncmp (arg1_start, "vfork", arg1_length) == 0)
6665 catch_fork_command_1 (catch_vfork, arg1_end + 1, tempflag, from_tty);
6667 else if (strncmp (arg1_start, "exec", arg1_length) == 0)
6669 catch_exec_command_1 (arg1_end + 1, tempflag, from_tty);
6671 else if (strncmp (arg1_start, "load", arg1_length) == 0)
6673 catch_load_command_1 (arg1_end + 1, tempflag, from_tty);
6675 else if (strncmp (arg1_start, "unload", arg1_length) == 0)
6677 catch_unload_command_1 (arg1_end + 1, tempflag, from_tty);
6679 else if (strncmp (arg1_start, "stop", arg1_length) == 0)
6681 error (_("Catch of stop not yet implemented"));
6683 else if (strncmp (arg1_start, "exception", arg1_length) == 0)
6685 catch_ada_exception_command (arg1_end + 1, tempflag, from_tty);
6688 else if (strncmp (arg1_start, "assert", arg1_length) == 0)
6690 catch_assert_command (arg1_end + 1, tempflag, from_tty);
6693 /* This doesn't appear to be an event name */
6697 /* Pre-v.4.16 behaviour was to treat the argument
6698 as the name of an exception */
6699 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6700 /* Now this is not allowed */
6701 error (_("Unknown event kind specified for catch"));
6707 catch_command (char *arg, int from_tty)
6709 catch_command_1 (arg, 0, from_tty);
6714 tcatch_command (char *arg, int from_tty)
6716 catch_command_1 (arg, 1, from_tty);
6719 /* Delete breakpoints by address or line. */
6722 clear_command (char *arg, int from_tty)
6724 struct breakpoint *b;
6725 VEC(breakpoint_p) *found = 0;
6728 struct symtabs_and_lines sals;
6729 struct symtab_and_line sal;
6734 sals = decode_line_spec (arg, 1);
6739 sals.sals = (struct symtab_and_line *)
6740 xmalloc (sizeof (struct symtab_and_line));
6741 make_cleanup (xfree, sals.sals);
6742 init_sal (&sal); /* initialize to zeroes */
6743 sal.line = default_breakpoint_line;
6744 sal.symtab = default_breakpoint_symtab;
6745 sal.pc = default_breakpoint_address;
6746 if (sal.symtab == 0)
6747 error (_("No source file specified."));
6755 /* We don't call resolve_sal_pc here. That's not
6756 as bad as it seems, because all existing breakpoints
6757 typically have both file/line and pc set. So, if
6758 clear is given file/line, we can match this to existing
6759 breakpoint without obtaining pc at all.
6761 We only support clearing given the address explicitly
6762 present in breakpoint table. Say, we've set breakpoint
6763 at file:line. There were several PC values for that file:line,
6764 due to optimization, all in one block.
6765 We've picked one PC value. If "clear" is issued with another
6766 PC corresponding to the same file:line, the breakpoint won't
6767 be cleared. We probably can still clear the breakpoint, but
6768 since the other PC value is never presented to user, user
6769 can only find it by guessing, and it does not seem important
6772 /* For each line spec given, delete bps which correspond
6773 to it. Do it in two passes, solely to preserve the current
6774 behavior that from_tty is forced true if we delete more than
6778 for (i = 0; i < sals.nelts; i++)
6780 /* If exact pc given, clear bpts at that pc.
6781 If line given (pc == 0), clear all bpts on specified line.
6782 If defaulting, clear all bpts on default line
6785 defaulting sal.pc != 0 tests to do
6790 1 0 <can't happen> */
6794 /* Find all matching breakpoints and add them to
6799 /* Are we going to delete b? */
6800 if (b->type != bp_none
6801 && b->type != bp_watchpoint
6802 && b->type != bp_hardware_watchpoint
6803 && b->type != bp_read_watchpoint
6804 && b->type != bp_access_watchpoint)
6806 struct bp_location *loc = b->loc;
6807 for (; loc; loc = loc->next)
6809 int pc_match = sal.pc
6810 && (loc->address == sal.pc)
6811 && (!section_is_overlay (loc->section)
6812 || loc->section == sal.section);
6813 int line_match = ((default_match || (0 == sal.pc))
6814 && b->source_file != NULL
6815 && sal.symtab != NULL
6816 && strcmp (b->source_file, sal.symtab->filename) == 0
6817 && b->line_number == sal.line);
6818 if (pc_match || line_match)
6827 VEC_safe_push(breakpoint_p, found, b);
6830 /* Now go thru the 'found' chain and delete them. */
6831 if (VEC_empty(breakpoint_p, found))
6834 error (_("No breakpoint at %s."), arg);
6836 error (_("No breakpoint at this line."));
6839 if (VEC_length(breakpoint_p, found) > 1)
6840 from_tty = 1; /* Always report if deleted more than one */
6843 if (VEC_length(breakpoint_p, found) == 1)
6844 printf_unfiltered (_("Deleted breakpoint "));
6846 printf_unfiltered (_("Deleted breakpoints "));
6848 breakpoints_changed ();
6850 for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++)
6853 printf_unfiltered ("%d ", b->number);
6854 delete_breakpoint (b);
6857 putchar_unfiltered ('\n');
6860 /* Delete breakpoint in BS if they are `delete' breakpoints and
6861 all breakpoints that are marked for deletion, whether hit or not.
6862 This is called after any breakpoint is hit, or after errors. */
6865 breakpoint_auto_delete (bpstat bs)
6867 struct breakpoint *b, *temp;
6869 for (; bs; bs = bs->next)
6870 if (bs->breakpoint_at && bs->breakpoint_at->owner->disposition == disp_del
6872 delete_breakpoint (bs->breakpoint_at->owner);
6874 ALL_BREAKPOINTS_SAFE (b, temp)
6876 if (b->disposition == disp_del_at_next_stop)
6877 delete_breakpoint (b);
6881 /* Remove locations of breakpoint BPT from
6882 the global list of breakpoint locations. */
6885 unlink_locations_from_global_list (struct breakpoint *bpt)
6887 /* This code assumes that the locations
6888 of a breakpoint are found in the global list
6889 in the same order, but not necessary adjacent. */
6890 struct bp_location **tmp = &bp_location_chain;
6891 struct bp_location *here = bpt->loc;
6896 for (; *tmp && here;)
6900 *tmp = here->global_next;
6905 tmp = &((*tmp)->global_next);
6910 /* Delete a breakpoint and clean up all traces of it in the data
6914 delete_breakpoint (struct breakpoint *bpt)
6916 struct breakpoint *b;
6918 struct bp_location *loc;
6920 gdb_assert (bpt != NULL);
6922 /* Has this bp already been deleted? This can happen because multiple
6923 lists can hold pointers to bp's. bpstat lists are especial culprits.
6925 One example of this happening is a watchpoint's scope bp. When the
6926 scope bp triggers, we notice that the watchpoint is out of scope, and
6927 delete it. We also delete its scope bp. But the scope bp is marked
6928 "auto-deleting", and is already on a bpstat. That bpstat is then
6929 checked for auto-deleting bp's, which are deleted.
6931 A real solution to this problem might involve reference counts in bp's,
6932 and/or giving them pointers back to their referencing bpstat's, and
6933 teaching delete_breakpoint to only free a bp's storage when no more
6934 references were extent. A cheaper bandaid was chosen. */
6935 if (bpt->type == bp_none)
6938 if (deprecated_delete_breakpoint_hook)
6939 deprecated_delete_breakpoint_hook (bpt);
6940 breakpoint_delete_event (bpt->number);
6942 for (loc = bpt->loc; loc; loc = loc->next)
6945 remove_breakpoint (loc, mark_inserted);
6950 if (loc->function_name)
6951 xfree (loc->function_name);
6954 if (breakpoint_chain == bpt)
6955 breakpoint_chain = bpt->next;
6960 b->next = bpt->next;
6964 unlink_locations_from_global_list (bpt);
6966 check_duplicates (bpt);
6968 if (bpt->type != bp_hardware_watchpoint
6969 && bpt->type != bp_read_watchpoint
6970 && bpt->type != bp_access_watchpoint
6971 && bpt->type != bp_catch_fork
6972 && bpt->type != bp_catch_vfork
6973 && bpt->type != bp_catch_exec)
6974 for (loc = bpt->loc; loc; loc = loc->next)
6976 /* If this breakpoint location was inserted, and there is
6977 another breakpoint at the same address, we need to
6978 insert the other breakpoint. */
6981 struct bp_location *loc2;
6982 ALL_BP_LOCATIONS (loc2)
6983 if (loc2->address == loc->address
6984 && loc2->section == loc->section
6986 && loc2->owner->enable_state != bp_disabled
6988 && !loc2->shlib_disabled
6989 && loc2->owner->enable_state != bp_call_disabled)
6993 /* We should never reach this point if there is a permanent
6994 breakpoint at the same address as the one being deleted.
6995 If there is a permanent breakpoint somewhere, it should
6996 always be the only one inserted. */
6997 if (loc2->owner->enable_state == bp_permanent)
6998 internal_error (__FILE__, __LINE__,
6999 _("another breakpoint was inserted on top of "
7000 "a permanent breakpoint"));
7002 memset (&loc2->target_info, 0, sizeof (loc2->target_info));
7003 loc2->target_info.placed_address = loc2->address;
7004 if (b->type == bp_hardware_breakpoint)
7005 val = target_insert_hw_breakpoint (&loc2->target_info);
7007 val = target_insert_breakpoint (&loc2->target_info);
7009 /* If there was an error in the insert, print a message, then stop execution. */
7012 struct ui_file *tmp_error_stream = mem_fileopen ();
7013 make_cleanup_ui_file_delete (tmp_error_stream);
7016 if (b->type == bp_hardware_breakpoint)
7018 fprintf_unfiltered (tmp_error_stream,
7019 "Cannot insert hardware breakpoint %d.\n"
7020 "You may have requested too many hardware breakpoints.\n",
7025 fprintf_unfiltered (tmp_error_stream, "Cannot insert breakpoint %d.\n", b->number);
7026 fprintf_filtered (tmp_error_stream, "Error accessing memory address ");
7027 fputs_filtered (paddress (loc2->address),
7029 fprintf_filtered (tmp_error_stream, ": %s.\n",
7030 safe_strerror (val));
7033 fprintf_unfiltered (tmp_error_stream,"The same program may be running in another process.");
7034 target_terminal_ours_for_output ();
7035 error_stream(tmp_error_stream);
7043 free_command_lines (&bpt->commands);
7044 if (bpt->cond_string != NULL)
7045 xfree (bpt->cond_string);
7046 if (bpt->addr_string != NULL)
7047 xfree (bpt->addr_string);
7048 if (bpt->exp != NULL)
7050 if (bpt->exp_string != NULL)
7051 xfree (bpt->exp_string);
7052 if (bpt->val != NULL)
7053 value_free (bpt->val);
7054 if (bpt->source_file != NULL)
7055 xfree (bpt->source_file);
7056 if (bpt->dll_pathname != NULL)
7057 xfree (bpt->dll_pathname);
7058 if (bpt->triggered_dll_pathname != NULL)
7059 xfree (bpt->triggered_dll_pathname);
7060 if (bpt->exec_pathname != NULL)
7061 xfree (bpt->exec_pathname);
7063 /* Be sure no bpstat's are pointing at it after it's been freed. */
7064 /* FIXME, how can we find all bpstat's?
7065 We just check stop_bpstat for now. Note that we cannot just
7066 remove bpstats pointing at bpt from the stop_bpstat list
7067 entirely, as breakpoint commands are associated with the bpstat;
7068 if we remove it here, then the later call to
7069 bpstat_do_actions (&stop_bpstat);
7070 in event-top.c won't do anything, and temporary breakpoints
7071 with commands won't work. */
7072 for (bs = stop_bpstat; bs; bs = bs->next)
7073 if (bs->breakpoint_at && bs->breakpoint_at->owner == bpt)
7075 bs->breakpoint_at = NULL;
7077 /* bs->commands will be freed later. */
7079 /* On the chance that someone will soon try again to delete this same
7080 bp, we mark it as deleted before freeing its storage. */
7081 bpt->type = bp_none;
7083 for (loc = bpt->loc; loc;)
7085 struct bp_location *loc_next = loc->next;
7093 do_delete_breakpoint_cleanup (void *b)
7095 delete_breakpoint (b);
7099 make_cleanup_delete_breakpoint (struct breakpoint *b)
7101 return make_cleanup (do_delete_breakpoint_cleanup, b);
7105 make_exec_cleanup_delete_breakpoint (struct breakpoint *b)
7107 return make_exec_cleanup (do_delete_breakpoint_cleanup, b);
7111 delete_command (char *arg, int from_tty)
7113 struct breakpoint *b, *temp;
7119 int breaks_to_delete = 0;
7121 /* Delete all breakpoints if no argument.
7122 Do not delete internal or call-dummy breakpoints, these
7123 have to be deleted with an explicit breakpoint number argument. */
7126 if (b->type != bp_call_dummy &&
7127 b->type != bp_shlib_event &&
7128 b->type != bp_thread_event &&
7129 b->type != bp_overlay_event &&
7132 breaks_to_delete = 1;
7137 /* Ask user only if there are some breakpoints to delete. */
7139 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
7141 ALL_BREAKPOINTS_SAFE (b, temp)
7143 if (b->type != bp_call_dummy &&
7144 b->type != bp_shlib_event &&
7145 b->type != bp_thread_event &&
7146 b->type != bp_overlay_event &&
7148 delete_breakpoint (b);
7153 map_breakpoint_numbers (arg, delete_breakpoint);
7157 all_locations_are_pending (struct bp_location *loc)
7159 for (; loc; loc = loc->next)
7160 if (!loc->shlib_disabled)
7165 /* Subroutine of update_breakpoint_locations to simplify it.
7166 Return non-zero if multiple fns in list LOC have the same name.
7167 Null names are ignored. */
7170 ambiguous_names_p (struct bp_location *loc)
7172 struct bp_location *l;
7173 htab_t htab = htab_create_alloc (13, htab_hash_string,
7174 (int (*) (const void *, const void *)) streq,
7175 NULL, xcalloc, xfree);
7177 for (l = loc; l != NULL; l = l->next)
7180 const char *name = l->function_name;
7182 /* Allow for some names to be NULL, ignore them. */
7186 slot = (const char **) htab_find_slot (htab, (const void *) name,
7188 /* NOTE: We can assume slot != NULL here because xcalloc never returns
7203 update_breakpoint_locations (struct breakpoint *b,
7204 struct symtabs_and_lines sals)
7208 struct bp_location *existing_locations = b->loc;
7210 /* If there's no new locations, and all existing locations
7211 are pending, don't do anything. This optimizes
7212 the common case where all locations are in the same
7213 shared library, that was unloaded. We'd like to
7214 retain the location, so that when the library
7215 is loaded again, we don't loose the enabled/disabled
7216 status of the individual locations. */
7217 if (all_locations_are_pending (existing_locations) && sals.nelts == 0)
7220 unlink_locations_from_global_list (b);
7223 for (i = 0; i < sals.nelts; ++i)
7225 struct bp_location *new_loc =
7226 add_location_to_breakpoint (b, b->type, &(sals.sals[i]));
7228 /* Reparse conditions, they might contain references to the
7230 if (b->cond_string != NULL)
7232 struct gdb_exception e;
7235 TRY_CATCH (e, RETURN_MASK_ERROR)
7237 new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc),
7242 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
7243 b->number, e.message);
7244 new_loc->enabled = 0;
7248 if (b->source_file != NULL)
7249 xfree (b->source_file);
7250 if (sals.sals[i].symtab == NULL)
7251 b->source_file = NULL;
7254 savestring (sals.sals[i].symtab->filename,
7255 strlen (sals.sals[i].symtab->filename));
7257 if (b->line_number == 0)
7258 b->line_number = sals.sals[i].line;
7261 /* If possible, carry over 'disable' status from existing breakpoints. */
7263 struct bp_location *e = existing_locations;
7264 /* If there are multiple breakpoints with the same function name,
7265 e.g. for inline functions, comparing function names won't work.
7266 Instead compare pc addresses; this is just a heuristic as things
7267 may have moved, but in practice it gives the correct answer
7268 often enough until a better solution is found. */
7269 int have_ambiguous_names = ambiguous_names_p (b->loc);
7271 for (; e; e = e->next)
7273 if (!e->enabled && e->function_name)
7275 struct bp_location *l = b->loc;
7276 if (have_ambiguous_names)
7278 for (; l; l = l->next)
7279 if (e->address == l->address)
7287 for (; l; l = l->next)
7288 if (l->function_name
7289 && strcmp (e->function_name, l->function_name) == 0)
7299 while (existing_locations)
7301 struct bp_location *next = existing_locations->next;
7302 free_bp_location (existing_locations);
7303 existing_locations = next;
7308 /* Reset a breakpoint given it's struct breakpoint * BINT.
7309 The value we return ends up being the return value from catch_errors.
7310 Unused in this case. */
7313 breakpoint_re_set_one (void *bint)
7315 /* get past catch_errs */
7316 struct breakpoint *b = (struct breakpoint *) bint;
7320 int *not_found_ptr = ¬_found;
7321 struct symtabs_and_lines sals = {};
7322 struct symtabs_and_lines expanded;
7324 enum enable_state save_enable;
7325 struct gdb_exception e;
7331 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7335 case bp_hardware_breakpoint:
7337 case bp_catch_unload:
7338 if (b->addr_string == NULL)
7340 /* Anything without a string can't be re-set. */
7341 delete_breakpoint (b);
7345 set_language (b->language);
7346 input_radix = b->input_radix;
7348 TRY_CATCH (e, RETURN_MASK_ERROR)
7350 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL,
7355 int not_found_and_ok = 0;
7356 /* For pending breakpoints, it's expected that parsing
7357 will fail until the right shared library is loaded.
7358 User has already told to create pending breakpoints and
7359 don't need extra messages. If breakpoint is in bp_shlib_disabled
7360 state, then user already saw the message about that breakpoint
7361 being disabled, and don't want to see more errors. */
7363 && (b->condition_not_parsed
7364 || (b->loc && b->loc->shlib_disabled)
7365 || b->enable_state == bp_disabled))
7366 not_found_and_ok = 1;
7368 if (!not_found_and_ok)
7370 /* We surely don't want to warn about the same breakpoint
7371 10 times. One solution, implemented here, is disable
7372 the breakpoint on error. Another solution would be to
7373 have separate 'warning emitted' flag. Since this
7374 happens only when a binary has changed, I don't know
7375 which approach is better. */
7376 b->enable_state = bp_disabled;
7377 throw_exception (e);
7384 gdb_assert (sals.nelts == 1);
7385 resolve_sal_pc (&sals.sals[0]);
7386 if (b->condition_not_parsed && s && s[0])
7388 char *cond_string = 0;
7390 find_condition_and_thread (s, sals.sals[0].pc,
7391 &cond_string, &thread);
7393 b->cond_string = cond_string;
7395 b->condition_not_parsed = 0;
7397 expanded = expand_line_sal_maybe (sals.sals[0]);
7398 update_breakpoint_locations (b, expanded);
7400 /* Now that this is re-enabled, check_duplicates
7402 check_duplicates (b);
7408 case bp_hardware_watchpoint:
7409 case bp_read_watchpoint:
7410 case bp_access_watchpoint:
7411 /* Watchpoint can be either on expression using entirely global variables,
7412 or it can be on local variables.
7414 Watchpoints of the first kind are never auto-deleted, and even persist
7415 across program restarts. Since they can use variables from shared
7416 libraries, we need to reparse expression as libraries are loaded
7419 Watchpoints on local variables can also change meaning as result
7420 of solib event. For example, if a watchpoint uses both a local and
7421 a global variables in expression, it's a local watchpoint, but
7422 unloading of a shared library will make the expression invalid.
7423 This is not a very common use case, but we still re-evaluate
7424 expression, to avoid surprises to the user.
7426 Note that for local watchpoints, we re-evaluate it only if
7427 watchpoints frame id is still valid. If it's not, it means
7428 the watchpoint is out of scope and will be deleted soon. In fact,
7429 I'm not sure we'll ever be called in this case.
7431 If a local watchpoint's frame id is still valid, then
7432 b->exp_valid_block is likewise valid, and we can safely use it.
7434 Don't do anything about disabled watchpoints, since they will
7435 be reevaluated again when enabled. */
7436 update_watchpoint (b, 1 /* reparse */);
7438 /* We needn't really do anything to reset these, since the mask
7439 that requests them is unaffected by e.g., new libraries being
7442 case bp_catch_vfork:
7447 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type);
7449 /* Delete longjmp and overlay event breakpoints; they will be
7450 reset later by breakpoint_re_set. */
7452 case bp_longjmp_resume:
7453 case bp_overlay_event:
7454 delete_breakpoint (b);
7457 /* This breakpoint is special, it's set up when the inferior
7458 starts and we really don't want to touch it. */
7459 case bp_shlib_event:
7461 /* Like bp_shlib_event, this breakpoint type is special.
7462 Once it is set up, we do not want to touch it. */
7463 case bp_thread_event:
7465 /* Keep temporary breakpoints, which can be encountered when we step
7466 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7467 Otherwise these should have been blown away via the cleanup chain
7468 or by breakpoint_init_inferior when we rerun the executable. */
7471 case bp_watchpoint_scope:
7473 case bp_step_resume:
7480 /* Re-set all breakpoints after symbols have been re-loaded. */
7482 breakpoint_re_set (void)
7484 struct breakpoint *b, *temp;
7485 enum language save_language;
7486 int save_input_radix;
7488 save_language = current_language->la_language;
7489 save_input_radix = input_radix;
7490 ALL_BREAKPOINTS_SAFE (b, temp)
7492 /* Format possible error msg */
7493 char *message = xstrprintf ("Error in re-setting breakpoint %d: ",
7495 struct cleanup *cleanups = make_cleanup (xfree, message);
7496 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
7497 do_cleanups (cleanups);
7499 set_language (save_language);
7500 input_radix = save_input_radix;
7502 if (gdbarch_get_longjmp_target_p (current_gdbarch))
7504 create_longjmp_breakpoint ("longjmp");
7505 create_longjmp_breakpoint ("_longjmp");
7506 create_longjmp_breakpoint ("siglongjmp");
7507 create_longjmp_breakpoint ("_siglongjmp");
7508 create_longjmp_breakpoint (NULL);
7511 create_overlay_event_breakpoint ("_ovly_debug_event");
7514 /* Reset the thread number of this breakpoint:
7516 - If the breakpoint is for all threads, leave it as-is.
7517 - Else, reset it to the current thread for inferior_ptid. */
7519 breakpoint_re_set_thread (struct breakpoint *b)
7521 if (b->thread != -1)
7523 if (in_thread_list (inferior_ptid))
7524 b->thread = pid_to_thread_id (inferior_ptid);
7528 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7529 If from_tty is nonzero, it prints a message to that effect,
7530 which ends with a period (no newline). */
7533 set_ignore_count (int bptnum, int count, int from_tty)
7535 struct breakpoint *b;
7541 if (b->number == bptnum)
7543 b->ignore_count = count;
7547 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7549 else if (count == 1)
7550 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7553 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7556 breakpoints_changed ();
7557 breakpoint_modify_event (b->number);
7561 error (_("No breakpoint number %d."), bptnum);
7564 /* Clear the ignore counts of all breakpoints. */
7566 breakpoint_clear_ignore_counts (void)
7568 struct breakpoint *b;
7571 b->ignore_count = 0;
7574 /* Command to set ignore-count of breakpoint N to COUNT. */
7577 ignore_command (char *args, int from_tty)
7583 error_no_arg (_("a breakpoint number"));
7585 num = get_number (&p);
7587 error (_("bad breakpoint number: '%s'"), args);
7589 error (_("Second argument (specified ignore-count) is missing."));
7591 set_ignore_count (num,
7592 longest_to_int (value_as_long (parse_and_eval (p))),
7595 printf_filtered ("\n");
7598 /* Call FUNCTION on each of the breakpoints
7599 whose numbers are given in ARGS. */
7602 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *))
7607 struct breakpoint *b, *tmp;
7611 error_no_arg (_("one or more breakpoint numbers"));
7618 num = get_number_or_range (&p1);
7621 warning (_("bad breakpoint number at or near '%s'"), p);
7625 ALL_BREAKPOINTS_SAFE (b, tmp)
7626 if (b->number == num)
7628 struct breakpoint *related_breakpoint = b->related_breakpoint;
7631 if (related_breakpoint)
7632 function (related_breakpoint);
7636 printf_unfiltered (_("No breakpoint number %d.\n"), num);
7642 static struct bp_location *
7643 find_location_by_number (char *number)
7645 char *dot = strchr (number, '.');
7649 struct breakpoint *b;
7650 struct bp_location *loc;
7655 bp_num = get_number_or_range (&p1);
7657 error (_("Bad breakpoint number '%s'"), number);
7660 if (b->number == bp_num)
7665 if (!b || b->number != bp_num)
7666 error (_("Bad breakpoint number '%s'"), number);
7669 loc_num = get_number_or_range (&p1);
7671 error (_("Bad breakpoint location number '%s'"), number);
7675 for (;loc_num && loc; --loc_num, loc = loc->next)
7678 error (_("Bad breakpoint location number '%s'"), dot+1);
7684 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7685 If from_tty is nonzero, it prints a message to that effect,
7686 which ends with a period (no newline). */
7689 disable_breakpoint (struct breakpoint *bpt)
7691 /* Never disable a watchpoint scope breakpoint; we want to
7692 hit them when we leave scope so we can delete both the
7693 watchpoint and its scope breakpoint at that time. */
7694 if (bpt->type == bp_watchpoint_scope)
7697 /* You can't disable permanent breakpoints. */
7698 if (bpt->enable_state == bp_permanent)
7701 bpt->enable_state = bp_disabled;
7703 check_duplicates (bpt);
7705 if (deprecated_modify_breakpoint_hook)
7706 deprecated_modify_breakpoint_hook (bpt);
7707 breakpoint_modify_event (bpt->number);
7711 disable_command (char *args, int from_tty)
7713 struct breakpoint *bpt;
7715 ALL_BREAKPOINTS (bpt)
7719 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
7724 case bp_catch_unload:
7726 case bp_catch_vfork:
7728 case bp_hardware_breakpoint:
7730 case bp_hardware_watchpoint:
7731 case bp_read_watchpoint:
7732 case bp_access_watchpoint:
7733 disable_breakpoint (bpt);
7737 else if (strchr (args, '.'))
7739 struct bp_location *loc = find_location_by_number (args);
7742 check_duplicates (loc->owner);
7745 map_breakpoint_numbers (args, disable_breakpoint);
7749 do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition)
7751 int target_resources_ok, other_type_used;
7754 if (bpt->type == bp_hardware_breakpoint)
7757 i = hw_breakpoint_used_count ();
7758 target_resources_ok =
7759 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
7761 if (target_resources_ok == 0)
7762 error (_("No hardware breakpoint support in the target."));
7763 else if (target_resources_ok < 0)
7764 error (_("Hardware breakpoints used exceeds limit."));
7767 if (bpt->type == bp_watchpoint ||
7768 bpt->type == bp_hardware_watchpoint ||
7769 bpt->type == bp_read_watchpoint ||
7770 bpt->type == bp_access_watchpoint)
7772 struct frame_id saved_frame_id;
7774 saved_frame_id = get_frame_id (get_selected_frame (NULL));
7775 if (bpt->exp_valid_block != NULL)
7777 struct frame_info *fr =
7778 fr = frame_find_by_id (bpt->watchpoint_frame);
7781 printf_filtered (_("\
7782 Cannot enable watchpoint %d because the block in which its expression\n\
7783 is valid is not currently in scope.\n"), bpt->number);
7790 value_free (bpt->val);
7791 mark = value_mark ();
7792 fetch_watchpoint_value (bpt->exp, &bpt->val, NULL, NULL);
7794 release_value (bpt->val);
7797 if (bpt->type == bp_hardware_watchpoint ||
7798 bpt->type == bp_read_watchpoint ||
7799 bpt->type == bp_access_watchpoint)
7801 int i = hw_watchpoint_used_count (bpt->type, &other_type_used);
7802 int mem_cnt = can_use_hardware_watchpoint (bpt->val);
7804 /* Hack around 'unused var' error for some targets here */
7805 (void) mem_cnt, (void) i;
7806 target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7807 bpt->type, i + mem_cnt, other_type_used);
7808 /* we can consider of type is bp_hardware_watchpoint, convert to
7809 bp_watchpoint in the following condition */
7810 if (target_resources_ok < 0)
7812 printf_filtered (_("\
7813 Cannot enable watchpoint %d because target watch resources\n\
7814 have been allocated for other watchpoints.\n"), bpt->number);
7815 value_free_to_mark (mark);
7820 select_frame (frame_find_by_id (saved_frame_id));
7821 value_free_to_mark (mark);
7824 if (bpt->enable_state != bp_permanent)
7825 bpt->enable_state = bp_enabled;
7826 bpt->disposition = disposition;
7827 check_duplicates (bpt);
7828 breakpoints_changed ();
7830 if (deprecated_modify_breakpoint_hook)
7831 deprecated_modify_breakpoint_hook (bpt);
7832 breakpoint_modify_event (bpt->number);
7837 enable_breakpoint (struct breakpoint *bpt)
7839 do_enable_breakpoint (bpt, bpt->disposition);
7842 /* The enable command enables the specified breakpoints (or all defined
7843 breakpoints) so they once again become (or continue to be) effective
7844 in stopping the inferior. */
7847 enable_command (char *args, int from_tty)
7849 struct breakpoint *bpt;
7851 ALL_BREAKPOINTS (bpt)
7855 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
7860 case bp_catch_unload:
7862 case bp_catch_vfork:
7864 case bp_hardware_breakpoint:
7866 case bp_hardware_watchpoint:
7867 case bp_read_watchpoint:
7868 case bp_access_watchpoint:
7869 enable_breakpoint (bpt);
7873 else if (strchr (args, '.'))
7875 struct bp_location *loc = find_location_by_number (args);
7878 check_duplicates (loc->owner);
7881 map_breakpoint_numbers (args, enable_breakpoint);
7885 enable_once_breakpoint (struct breakpoint *bpt)
7887 do_enable_breakpoint (bpt, disp_disable);
7891 enable_once_command (char *args, int from_tty)
7893 map_breakpoint_numbers (args, enable_once_breakpoint);
7897 enable_delete_breakpoint (struct breakpoint *bpt)
7899 do_enable_breakpoint (bpt, disp_del);
7903 enable_delete_command (char *args, int from_tty)
7905 map_breakpoint_numbers (args, enable_delete_breakpoint);
7909 set_breakpoint_cmd (char *args, int from_tty)
7914 show_breakpoint_cmd (char *args, int from_tty)
7918 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7920 struct symtabs_and_lines
7921 decode_line_spec_1 (char *string, int funfirstline)
7923 struct symtabs_and_lines sals;
7925 error (_("Empty line specification."));
7926 if (default_breakpoint_valid)
7927 sals = decode_line_1 (&string, funfirstline,
7928 default_breakpoint_symtab,
7929 default_breakpoint_line,
7930 (char ***) NULL, NULL);
7932 sals = decode_line_1 (&string, funfirstline,
7933 (struct symtab *) NULL, 0, (char ***) NULL, NULL);
7935 error (_("Junk at end of line specification: %s"), string);
7939 /* Create and insert a raw software breakpoint at PC. Return an
7940 identifier, which should be used to remove the breakpoint later.
7941 In general, places which call this should be using something on the
7942 breakpoint chain instead; this function should be eliminated
7946 deprecated_insert_raw_breakpoint (CORE_ADDR pc)
7948 struct bp_target_info *bp_tgt;
7950 bp_tgt = xmalloc (sizeof (struct bp_target_info));
7951 memset (bp_tgt, 0, sizeof (struct bp_target_info));
7953 bp_tgt->placed_address = pc;
7954 if (target_insert_breakpoint (bp_tgt) != 0)
7956 /* Could not insert the breakpoint. */
7964 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
7967 deprecated_remove_raw_breakpoint (void *bp)
7969 struct bp_target_info *bp_tgt = bp;
7972 ret = target_remove_breakpoint (bp_tgt);
7978 /* One (or perhaps two) breakpoints used for software single stepping. */
7980 static void *single_step_breakpoints[2];
7982 /* Create and insert a breakpoint for software single step. */
7985 insert_single_step_breakpoint (CORE_ADDR next_pc)
7989 if (single_step_breakpoints[0] == NULL)
7990 bpt_p = &single_step_breakpoints[0];
7993 gdb_assert (single_step_breakpoints[1] == NULL);
7994 bpt_p = &single_step_breakpoints[1];
7997 /* NOTE drow/2006-04-11: A future improvement to this function would be
7998 to only create the breakpoints once, and actually put them on the
7999 breakpoint chain. That would let us use set_raw_breakpoint. We could
8000 adjust the addresses each time they were needed. Doing this requires
8001 corresponding changes elsewhere where single step breakpoints are
8002 handled, however. So, for now, we use this. */
8004 *bpt_p = deprecated_insert_raw_breakpoint (next_pc);
8006 error (_("Could not insert single-step breakpoint at 0x%s"),
8007 paddr_nz (next_pc));
8010 /* Remove and delete any breakpoints used for software single step. */
8013 remove_single_step_breakpoints (void)
8015 gdb_assert (single_step_breakpoints[0] != NULL);
8017 /* See insert_single_step_breakpoint for more about this deprecated
8019 deprecated_remove_raw_breakpoint (single_step_breakpoints[0]);
8020 single_step_breakpoints[0] = NULL;
8022 if (single_step_breakpoints[1] != NULL)
8024 deprecated_remove_raw_breakpoint (single_step_breakpoints[1]);
8025 single_step_breakpoints[1] = NULL;
8029 /* Check whether a software single-step breakpoint is inserted at PC. */
8032 single_step_breakpoint_inserted_here_p (CORE_ADDR pc)
8036 for (i = 0; i < 2; i++)
8038 struct bp_target_info *bp_tgt = single_step_breakpoints[i];
8039 if (bp_tgt && bp_tgt->placed_address == pc)
8047 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
8048 It is defined as a macro to prevent duplication.
8049 COMMAND should be a string constant containing the name of the command. */
8050 #define BREAK_ARGS_HELP(command) \
8051 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
8052 LOCATION may be a line number, function name, or \"*\" and an address.\n\
8053 If a line number is specified, break at start of code for that line.\n\
8054 If a function is specified, break at start of code for that function.\n\
8055 If an address is specified, break at that exact address.\n\
8056 With no LOCATION, uses current execution address of selected stack frame.\n\
8057 This is useful for breaking on return to a stack frame.\n\
8059 THREADNUM is the number from \"info threads\".\n\
8060 CONDITION is a boolean expression.\n\
8062 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
8064 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
8067 _initialize_breakpoint (void)
8069 static struct cmd_list_element *breakpoint_set_cmdlist;
8070 static struct cmd_list_element *breakpoint_show_cmdlist;
8071 struct cmd_list_element *c;
8073 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
8075 breakpoint_chain = 0;
8076 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
8077 before a breakpoint is set. */
8078 breakpoint_count = 0;
8080 add_com ("ignore", class_breakpoint, ignore_command, _("\
8081 Set ignore-count of breakpoint number N to COUNT.\n\
8082 Usage is `ignore N COUNT'."));
8084 add_com_alias ("bc", "ignore", class_breakpoint, 1);
8086 add_com ("commands", class_breakpoint, commands_command, _("\
8087 Set commands to be executed when a breakpoint is hit.\n\
8088 Give breakpoint number as argument after \"commands\".\n\
8089 With no argument, the targeted breakpoint is the last one set.\n\
8090 The commands themselves follow starting on the next line.\n\
8091 Type a line containing \"end\" to indicate the end of them.\n\
8092 Give \"silent\" as the first line to make the breakpoint silent;\n\
8093 then no output is printed when it is hit, except what the commands print."));
8095 add_com ("condition", class_breakpoint, condition_command, _("\
8096 Specify breakpoint number N to break only if COND is true.\n\
8097 Usage is `condition N COND', where N is an integer and COND is an\n\
8098 expression to be evaluated whenever breakpoint N is reached."));
8100 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
8101 Set a temporary breakpoint.\n\
8102 Like \"break\" except the breakpoint is only temporary,\n\
8103 so it will be deleted when hit. Equivalent to \"break\" followed\n\
8104 by using \"enable delete\" on the breakpoint number.\n\
8106 BREAK_ARGS_HELP ("tbreak")));
8107 set_cmd_completer (c, location_completer);
8109 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
8110 Set a hardware assisted breakpoint.\n\
8111 Like \"break\" except the breakpoint requires hardware support,\n\
8112 some target hardware may not have this support.\n\
8114 BREAK_ARGS_HELP ("hbreak")));
8115 set_cmd_completer (c, location_completer);
8117 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
8118 Set a temporary hardware assisted breakpoint.\n\
8119 Like \"hbreak\" except the breakpoint is only temporary,\n\
8120 so it will be deleted when hit.\n\
8122 BREAK_ARGS_HELP ("thbreak")));
8123 set_cmd_completer (c, location_completer);
8125 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
8126 Enable some breakpoints.\n\
8127 Give breakpoint numbers (separated by spaces) as arguments.\n\
8128 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8129 This is used to cancel the effect of the \"disable\" command.\n\
8130 With a subcommand you can enable temporarily."),
8131 &enablelist, "enable ", 1, &cmdlist);
8133 add_com ("ab", class_breakpoint, enable_command, _("\
8134 Enable some breakpoints.\n\
8135 Give breakpoint numbers (separated by spaces) as arguments.\n\
8136 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8137 This is used to cancel the effect of the \"disable\" command.\n\
8138 With a subcommand you can enable temporarily."));
8140 add_com_alias ("en", "enable", class_breakpoint, 1);
8142 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
8143 Enable some breakpoints.\n\
8144 Give breakpoint numbers (separated by spaces) as arguments.\n\
8145 This is used to cancel the effect of the \"disable\" command.\n\
8146 May be abbreviated to simply \"enable\".\n"),
8147 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
8149 add_cmd ("once", no_class, enable_once_command, _("\
8150 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8151 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8154 add_cmd ("delete", no_class, enable_delete_command, _("\
8155 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8156 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8159 add_cmd ("delete", no_class, enable_delete_command, _("\
8160 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8161 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8164 add_cmd ("once", no_class, enable_once_command, _("\
8165 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8166 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8169 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
8170 Disable some breakpoints.\n\
8171 Arguments are breakpoint numbers with spaces in between.\n\
8172 To disable all breakpoints, give no argument.\n\
8173 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8174 &disablelist, "disable ", 1, &cmdlist);
8175 add_com_alias ("dis", "disable", class_breakpoint, 1);
8176 add_com_alias ("disa", "disable", class_breakpoint, 1);
8178 add_com ("sb", class_breakpoint, disable_command, _("\
8179 Disable some breakpoints.\n\
8180 Arguments are breakpoint numbers with spaces in between.\n\
8181 To disable all breakpoints, give no argument.\n\
8182 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8184 add_cmd ("breakpoints", class_alias, disable_command, _("\
8185 Disable some breakpoints.\n\
8186 Arguments are breakpoint numbers with spaces in between.\n\
8187 To disable all breakpoints, give no argument.\n\
8188 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8189 This command may be abbreviated \"disable\"."),
8192 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
8193 Delete some breakpoints or auto-display expressions.\n\
8194 Arguments are breakpoint numbers with spaces in between.\n\
8195 To delete all breakpoints, give no argument.\n\
8197 Also a prefix command for deletion of other GDB objects.\n\
8198 The \"unset\" command is also an alias for \"delete\"."),
8199 &deletelist, "delete ", 1, &cmdlist);
8200 add_com_alias ("d", "delete", class_breakpoint, 1);
8201 add_com_alias ("del", "delete", class_breakpoint, 1);
8203 add_com ("db", class_breakpoint, delete_command, _("\
8204 Delete some breakpoints.\n\
8205 Arguments are breakpoint numbers with spaces in between.\n\
8206 To delete all breakpoints, give no argument.\n"));
8208 add_cmd ("breakpoints", class_alias, delete_command, _("\
8209 Delete some breakpoints or auto-display expressions.\n\
8210 Arguments are breakpoint numbers with spaces in between.\n\
8211 To delete all breakpoints, give no argument.\n\
8212 This command may be abbreviated \"delete\"."),
8215 add_com ("clear", class_breakpoint, clear_command, _("\
8216 Clear breakpoint at specified line or function.\n\
8217 Argument may be line number, function name, or \"*\" and an address.\n\
8218 If line number is specified, all breakpoints in that line are cleared.\n\
8219 If function is specified, breakpoints at beginning of function are cleared.\n\
8220 If an address is specified, breakpoints at that address are cleared.\n\
8222 With no argument, clears all breakpoints in the line that the selected frame\n\
8225 See also the \"delete\" command which clears breakpoints by number."));
8227 c = add_com ("break", class_breakpoint, break_command, _("\
8228 Set breakpoint at specified line or function.\n"
8229 BREAK_ARGS_HELP ("break")));
8230 set_cmd_completer (c, location_completer);
8232 add_com_alias ("b", "break", class_run, 1);
8233 add_com_alias ("br", "break", class_run, 1);
8234 add_com_alias ("bre", "break", class_run, 1);
8235 add_com_alias ("brea", "break", class_run, 1);
8239 add_com_alias ("ba", "break", class_breakpoint, 1);
8240 add_com_alias ("bu", "ubreak", class_breakpoint, 1);
8245 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
8246 Break in function/address or break at a line in the current file."),
8247 &stoplist, "stop ", 1, &cmdlist);
8248 add_cmd ("in", class_breakpoint, stopin_command,
8249 _("Break in function or address."), &stoplist);
8250 add_cmd ("at", class_breakpoint, stopat_command,
8251 _("Break at a line in the current file."), &stoplist);
8252 add_com ("status", class_info, breakpoints_info, _("\
8253 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8254 The \"Type\" column indicates one of:\n\
8255 \tbreakpoint - normal breakpoint\n\
8256 \twatchpoint - watchpoint\n\
8257 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8258 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8259 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8260 address and file/line number respectively.\n\
8262 Convenience variable \"$_\" and default examine address for \"x\"\n\
8263 are set to the address of the last breakpoint listed unless the command\n\
8264 is prefixed with \"server \".\n\n\
8265 Convenience variable \"$bpnum\" contains the number of the last\n\
8269 add_info ("breakpoints", breakpoints_info, _("\
8270 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8271 The \"Type\" column indicates one of:\n\
8272 \tbreakpoint - normal breakpoint\n\
8273 \twatchpoint - watchpoint\n\
8274 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8275 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8276 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8277 address and file/line number respectively.\n\
8279 Convenience variable \"$_\" and default examine address for \"x\"\n\
8280 are set to the address of the last breakpoint listed unless the command\n\
8281 is prefixed with \"server \".\n\n\
8282 Convenience variable \"$bpnum\" contains the number of the last\n\
8286 add_com ("lb", class_breakpoint, breakpoints_info, _("\
8287 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8288 The \"Type\" column indicates one of:\n\
8289 \tbreakpoint - normal breakpoint\n\
8290 \twatchpoint - watchpoint\n\
8291 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8292 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8293 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8294 address and file/line number respectively.\n\
8296 Convenience variable \"$_\" and default examine address for \"x\"\n\
8297 are set to the address of the last breakpoint listed unless the command\n\
8298 is prefixed with \"server \".\n\n\
8299 Convenience variable \"$bpnum\" contains the number of the last\n\
8302 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
8303 Status of all breakpoints, or breakpoint number NUMBER.\n\
8304 The \"Type\" column indicates one of:\n\
8305 \tbreakpoint - normal breakpoint\n\
8306 \twatchpoint - watchpoint\n\
8307 \tlongjmp - internal breakpoint used to step through longjmp()\n\
8308 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8309 \tuntil - internal breakpoint used by the \"until\" command\n\
8310 \tfinish - internal breakpoint used by the \"finish\" command\n\
8311 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8312 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8313 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8314 address and file/line number respectively.\n\
8316 Convenience variable \"$_\" and default examine address for \"x\"\n\
8317 are set to the address of the last breakpoint listed unless the command\n\
8318 is prefixed with \"server \".\n\n\
8319 Convenience variable \"$bpnum\" contains the number of the last\n\
8321 &maintenanceinfolist);
8323 add_com ("catch", class_breakpoint, catch_command, _("\
8324 Set catchpoints to catch events.\n\
8325 Raised signals may be caught:\n\
8326 \tcatch signal - all signals\n\
8327 \tcatch signal <signame> - a particular signal\n\
8328 Raised exceptions may be caught:\n\
8329 \tcatch throw - all exceptions, when thrown\n\
8330 \tcatch throw <exceptname> - a particular exception, when thrown\n\
8331 \tcatch catch - all exceptions, when caught\n\
8332 \tcatch catch <exceptname> - a particular exception, when caught\n\
8333 Thread or process events may be caught:\n\
8334 \tcatch thread_start - any threads, just after creation\n\
8335 \tcatch thread_exit - any threads, just before expiration\n\
8336 \tcatch thread_join - any threads, just after joins\n\
8337 Process events may be caught:\n\
8338 \tcatch start - any processes, just after creation\n\
8339 \tcatch exit - any processes, just before expiration\n\
8340 \tcatch fork - calls to fork()\n\
8341 \tcatch vfork - calls to vfork()\n\
8342 \tcatch exec - calls to exec()\n\
8343 Dynamically-linked library events may be caught:\n\
8344 \tcatch load - loads of any library\n\
8345 \tcatch load <libname> - loads of a particular library\n\
8346 \tcatch unload - unloads of any library\n\
8347 \tcatch unload <libname> - unloads of a particular library\n\
8348 The act of your program's execution stopping may also be caught:\n\
8350 C++ exceptions may be caught:\n\
8351 \tcatch throw - all exceptions, when thrown\n\
8352 \tcatch catch - all exceptions, when caught\n\
8353 Ada exceptions may be caught:\n\
8354 \tcatch exception - all exceptions, when raised\n\
8355 \tcatch exception <name> - a particular exception, when raised\n\
8356 \tcatch exception unhandled - all unhandled exceptions, when raised\n\
8357 \tcatch assert - all failed assertions, when raised\n\
8359 Do \"help set follow-fork-mode\" for info on debugging your program\n\
8360 after a fork or vfork is caught.\n\n\
8361 Do \"help breakpoints\" for info on other commands dealing with breakpoints."));
8363 add_com ("tcatch", class_breakpoint, tcatch_command, _("\
8364 Set temporary catchpoints to catch events.\n\
8365 Args like \"catch\" command.\n\
8366 Like \"catch\" except the catchpoint is only temporary,\n\
8367 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
8368 by using \"enable delete\" on the catchpoint number."));
8370 c = add_com ("watch", class_breakpoint, watch_command, _("\
8371 Set a watchpoint for an expression.\n\
8372 A watchpoint stops execution of your program whenever the value of\n\
8373 an expression changes."));
8374 set_cmd_completer (c, location_completer);
8376 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
8377 Set a read watchpoint for an expression.\n\
8378 A watchpoint stops execution of your program whenever the value of\n\
8379 an expression is read."));
8380 set_cmd_completer (c, location_completer);
8382 c = add_com ("awatch", class_breakpoint, awatch_command, _("\
8383 Set a watchpoint for an expression.\n\
8384 A watchpoint stops execution of your program whenever the value of\n\
8385 an expression is either read or written."));
8386 set_cmd_completer (c, location_completer);
8388 add_info ("watchpoints", breakpoints_info,
8389 _("Synonym for ``info breakpoints''."));
8392 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8393 respond to changes - contrary to the description. */
8394 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
8395 &can_use_hw_watchpoints, _("\
8396 Set debugger's willingness to use watchpoint hardware."), _("\
8397 Show debugger's willingness to use watchpoint hardware."), _("\
8398 If zero, gdb will not use hardware for new watchpoints, even if\n\
8399 such is available. (However, any hardware watchpoints that were\n\
8400 created before setting this to nonzero, will continue to use watchpoint\n\
8403 show_can_use_hw_watchpoints,
8404 &setlist, &showlist);
8406 can_use_hw_watchpoints = 1;
8408 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
8409 Breakpoint specific settings\n\
8410 Configure various breakpoint-specific variables such as\n\
8411 pending breakpoint behavior"),
8412 &breakpoint_set_cmdlist, "set breakpoint ",
8413 0/*allow-unknown*/, &setlist);
8414 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
8415 Breakpoint specific settings\n\
8416 Configure various breakpoint-specific variables such as\n\
8417 pending breakpoint behavior"),
8418 &breakpoint_show_cmdlist, "show breakpoint ",
8419 0/*allow-unknown*/, &showlist);
8421 add_setshow_auto_boolean_cmd ("pending", no_class,
8422 &pending_break_support, _("\
8423 Set debugger's behavior regarding pending breakpoints."), _("\
8424 Show debugger's behavior regarding pending breakpoints."), _("\
8425 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8426 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8427 an error. If auto, an unrecognized breakpoint location results in a\n\
8428 user-query to see if a pending breakpoint should be created."),
8430 show_pending_break_support,
8431 &breakpoint_set_cmdlist,
8432 &breakpoint_show_cmdlist);
8434 pending_break_support = AUTO_BOOLEAN_AUTO;
8436 add_setshow_boolean_cmd ("auto-hw", no_class,
8437 &automatic_hardware_breakpoints, _("\
8438 Set automatic usage of hardware breakpoints."), _("\
8439 Show automatic usage of hardware breakpoints."), _("\
8440 If set, the debugger will automatically use hardware breakpoints for\n\
8441 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
8442 a warning will be emitted for such breakpoints."),
8444 show_automatic_hardware_breakpoints,
8445 &breakpoint_set_cmdlist,
8446 &breakpoint_show_cmdlist);
8448 automatic_hardware_breakpoints = 1;