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 #include "gdb_stdint.h"
65 /* Prototypes for local functions. */
67 static void until_break_command_continuation (struct continuation_arg *arg,
70 static void catch_command_1 (char *, int, int);
72 static void enable_delete_command (char *, int);
74 static void enable_delete_breakpoint (struct breakpoint *);
76 static void enable_once_command (char *, int);
78 static void enable_once_breakpoint (struct breakpoint *);
80 static void disable_command (char *, int);
82 static void enable_command (char *, int);
84 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint *));
86 static void ignore_command (char *, int);
88 static int breakpoint_re_set_one (void *);
90 static void clear_command (char *, int);
92 static void catch_command (char *, int);
94 static void watch_command (char *, int);
96 static int can_use_hardware_watchpoint (struct value *);
98 static void break_command_1 (char *, int, int);
100 static void mention (struct breakpoint *);
102 struct breakpoint *set_raw_breakpoint (struct symtab_and_line, enum bptype);
104 static void check_duplicates (struct breakpoint *);
106 static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
108 static CORE_ADDR adjust_breakpoint_address (CORE_ADDR bpaddr,
111 static void describe_other_breakpoints (CORE_ADDR, asection *, int);
113 static void breakpoints_info (char *, int);
115 static void breakpoint_1 (int, int);
117 static bpstat bpstat_alloc (const struct bp_location *, bpstat);
119 static int breakpoint_cond_eval (void *);
121 static void cleanup_executing_breakpoints (void *);
123 static void commands_command (char *, int);
125 static void condition_command (char *, int);
127 static int get_number_trailer (char **, int);
129 void set_breakpoint_count (int);
138 static int remove_breakpoint (struct bp_location *, insertion_state_t);
140 static enum print_stop_action print_it_typical (bpstat);
142 static enum print_stop_action print_bp_stop_message (bpstat bs);
144 static int watchpoint_check (void *);
146 static void maintenance_info_breakpoints (char *, int);
148 static void create_overlay_event_breakpoint (char *);
150 static int hw_breakpoint_used_count (void);
152 static int hw_watchpoint_used_count (enum bptype, int *);
154 static void hbreak_command (char *, int);
156 static void thbreak_command (char *, int);
158 static void watch_command_1 (char *, int, int);
160 static void rwatch_command (char *, int);
162 static void awatch_command (char *, int);
164 static void do_enable_breakpoint (struct breakpoint *, enum bpdisp);
166 static void create_fork_vfork_event_catchpoint (int tempflag,
168 enum bptype bp_kind);
170 static void stop_command (char *arg, int from_tty);
172 static void stopin_command (char *arg, int from_tty);
174 static void stopat_command (char *arg, int from_tty);
176 static char *ep_find_event_name_end (char *arg);
178 static char *ep_parse_optional_if_clause (char **arg);
180 static char *ep_parse_optional_filename (char **arg);
182 static void catch_exception_command_1 (enum exception_event_kind ex_event,
183 char *arg, int tempflag, int from_tty);
185 static void tcatch_command (char *arg, int from_tty);
187 static void ep_skip_leading_whitespace (char **s);
189 static int single_step_breakpoint_inserted_here_p (CORE_ADDR pc);
191 static void free_bp_location (struct bp_location *loc);
193 static void mark_breakpoints_out (void);
195 static struct bp_location *
196 allocate_bp_location (struct breakpoint *bpt, enum bptype bp_type);
198 static void update_global_location_list (void);
200 static void update_global_location_list_nothrow (void);
202 static int is_hardware_watchpoint (struct breakpoint *bpt);
204 static void insert_breakpoint_locations (void);
207 bpdisp_text (enum bpdisp disp)
209 /* NOTE: the following values are a part of MI protocol and represent
210 values of 'disp' field returned when inferior stops at a breakpoint. */
211 static char *bpdisps[] = {"del", "dstp", "dis", "keep"};
212 return bpdisps[(int) disp];
215 /* Prototypes for exported functions. */
216 /* If FALSE, gdb will not use hardware support for watchpoints, even
217 if such is available. */
218 static int can_use_hw_watchpoints;
221 show_can_use_hw_watchpoints (struct ui_file *file, int from_tty,
222 struct cmd_list_element *c,
225 fprintf_filtered (file, _("\
226 Debugger's willingness to use watchpoint hardware is %s.\n"),
230 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
231 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
232 for unrecognized breakpoint locations.
233 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
234 static enum auto_boolean pending_break_support;
236 show_pending_break_support (struct ui_file *file, int from_tty,
237 struct cmd_list_element *c,
240 fprintf_filtered (file, _("\
241 Debugger's behavior regarding pending breakpoints is %s.\n"),
245 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
246 set with "break" but falling in read-only memory.
247 If 0, gdb will warn about such breakpoints, but won't automatically
248 use hardware breakpoints. */
249 static int automatic_hardware_breakpoints;
251 show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty,
252 struct cmd_list_element *c,
255 fprintf_filtered (file, _("\
256 Automatic usage of hardware breakpoints is %s.\n"),
260 /* If 1, gdb will keep breakpoints inserted even as inferior is stopped,
261 and immediately insert any new breakpoints. If 0, gdb will insert
262 breakpoints into inferior only when resuming it, and will remove
263 breakpoints upon stop. */
264 static int always_inserted_mode = 0;
266 show_always_inserted_mode (struct ui_file *file, int from_tty,
267 struct cmd_list_element *c, const char *value)
269 fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), value);
273 void _initialize_breakpoint (void);
275 extern int addressprint; /* Print machine addresses? */
277 /* Are we executing breakpoint commands? */
278 static int executing_breakpoint_commands;
280 /* Are overlay event breakpoints enabled? */
281 static int overlay_events_enabled;
283 /* Walk the following statement or block through all breakpoints.
284 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
287 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
289 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
290 for (B = breakpoint_chain; \
291 B ? (TMP=B->next, 1): 0; \
294 /* Similar iterators for the low-level breakpoints. */
296 #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->global_next)
298 #define ALL_BP_LOCATIONS_SAFE(B,TMP) \
299 for (B = bp_location_chain; \
300 B ? (TMP=B->global_next, 1): 0; \
303 /* True if breakpoint hit counts should be displayed in breakpoint info. */
305 int show_breakpoint_hit_counts = 1;
307 /* Chains of all breakpoints defined. */
309 struct breakpoint *breakpoint_chain;
311 struct bp_location *bp_location_chain;
313 /* Number of last breakpoint made. */
315 int breakpoint_count;
317 /* This function returns a pointer to the string representation of the
318 pathname of the dynamically-linked library that has just been
321 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
322 or undefined results are guaranteed.
324 This string's contents are only valid immediately after the
325 inferior has stopped in the dynamic linker hook, and becomes
326 invalid as soon as the inferior is continued. Clients should make
327 a copy of this string if they wish to continue the inferior and
328 then access the string. */
330 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
331 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
334 /* This function returns a pointer to the string representation of the
335 pathname of the dynamically-linked library that has just been
338 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
339 TRUE, or undefined results are guaranteed.
341 This string's contents are only valid immediately after the
342 inferior has stopped in the dynamic linker hook, and becomes
343 invalid as soon as the inferior is continued. Clients should make
344 a copy of this string if they wish to continue the inferior and
345 then access the string. */
347 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
348 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
351 /* This function is called by the "catch load" command. It allows the
352 debugger to be notified by the dynamic linker when a specified
353 library file (or any library file, if filename is NULL) is loaded. */
355 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
356 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
357 error (_("catch of library loads not yet implemented on this platform"))
360 /* This function is called by the "catch unload" command. It allows
361 the debugger to be notified by the dynamic linker when a specified
362 library file (or any library file, if filename is NULL) is
365 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
366 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid, tempflag, filename, cond_string) \
367 error (_("catch of library unloads not yet implemented on this platform"))
370 /* Return whether a breakpoint is an active enabled breakpoint. */
372 breakpoint_enabled (struct breakpoint *b)
374 return (b->enable_state == bp_enabled);
377 /* Set breakpoint count to NUM. */
380 set_breakpoint_count (int num)
382 breakpoint_count = num;
383 set_internalvar (lookup_internalvar ("bpnum"),
384 value_from_longest (builtin_type_int, (LONGEST) num));
387 /* Used in run_command to zero the hit count when a new run starts. */
390 clear_breakpoint_hit_counts (void)
392 struct breakpoint *b;
398 /* Default address, symtab and line to put a breakpoint at
399 for "break" command with no arg.
400 if default_breakpoint_valid is zero, the other three are
401 not valid, and "break" with no arg is an error.
403 This set by print_stack_frame, which calls set_default_breakpoint. */
405 int default_breakpoint_valid;
406 CORE_ADDR default_breakpoint_address;
407 struct symtab *default_breakpoint_symtab;
408 int default_breakpoint_line;
410 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
411 Advance *PP after the string and any trailing whitespace.
413 Currently the string can either be a number or "$" followed by the name
414 of a convenience variable. Making it an expression wouldn't work well
415 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
417 If the string is a NULL pointer, that denotes the last breakpoint.
419 TRAILER is a character which can be found after the number; most
420 commonly this is `-'. If you don't want a trailer, use \0. */
422 get_number_trailer (char **pp, int trailer)
424 int retval = 0; /* default */
428 /* Empty line means refer to the last breakpoint. */
429 return breakpoint_count;
432 /* Make a copy of the name, so we can null-terminate it
433 to pass to lookup_internalvar(). */
438 while (isalnum (*p) || *p == '_')
440 varname = (char *) alloca (p - start + 1);
441 strncpy (varname, start, p - start);
442 varname[p - start] = '\0';
443 val = value_of_internalvar (lookup_internalvar (varname));
444 if (TYPE_CODE (value_type (val)) == TYPE_CODE_INT)
445 retval = (int) value_as_long (val);
448 printf_filtered (_("Convenience variable must have integer value.\n"));
456 while (*p >= '0' && *p <= '9')
459 /* There is no number here. (e.g. "cond a == b"). */
461 /* Skip non-numeric token */
462 while (*p && !isspace((int) *p))
464 /* Return zero, which caller must interpret as error. */
470 if (!(isspace (*p) || *p == '\0' || *p == trailer))
472 /* Trailing junk: return 0 and let caller print error msg. */
473 while (!(isspace (*p) || *p == '\0' || *p == trailer))
484 /* Like get_number_trailer, but don't allow a trailer. */
486 get_number (char **pp)
488 return get_number_trailer (pp, '\0');
491 /* Parse a number or a range.
492 * A number will be of the form handled by get_number.
493 * A range will be of the form <number1> - <number2>, and
494 * will represent all the integers between number1 and number2,
497 * While processing a range, this fuction is called iteratively;
498 * At each call it will return the next value in the range.
500 * At the beginning of parsing a range, the char pointer PP will
501 * be advanced past <number1> and left pointing at the '-' token.
502 * Subsequent calls will not advance the pointer until the range
503 * is completed. The call that completes the range will advance
504 * pointer PP past <number2>.
508 get_number_or_range (char **pp)
510 static int last_retval, end_value;
511 static char *end_ptr;
512 static int in_range = 0;
516 /* Default case: pp is pointing either to a solo number,
517 or to the first number of a range. */
518 last_retval = get_number_trailer (pp, '-');
523 /* This is the start of a range (<number1> - <number2>).
524 Skip the '-', parse and remember the second number,
525 and also remember the end of the final token. */
529 while (isspace ((int) *end_ptr))
530 end_ptr++; /* skip white space */
531 end_value = get_number (temp);
532 if (end_value < last_retval)
534 error (_("inverted range"));
536 else if (end_value == last_retval)
538 /* degenerate range (number1 == number2). Advance the
539 token pointer so that the range will be treated as a
548 error (_("negative value"));
551 /* pp points to the '-' that betokens a range. All
552 number-parsing has already been done. Return the next
553 integer value (one greater than the saved previous value).
554 Do not advance the token pointer 'pp' until the end of range
557 if (++last_retval == end_value)
559 /* End of range reached; advance token pointer. */
569 /* condition N EXP -- set break condition of breakpoint N to EXP. */
572 condition_command (char *arg, int from_tty)
574 struct breakpoint *b;
579 error_no_arg (_("breakpoint number"));
582 bnum = get_number (&p);
584 error (_("Bad breakpoint argument: '%s'"), arg);
587 if (b->number == bnum)
589 struct bp_location *loc = b->loc;
590 for (; loc; loc = loc->next)
598 if (b->cond_string != NULL)
599 xfree (b->cond_string);
603 b->cond_string = NULL;
605 printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum);
610 /* I don't know if it matters whether this is the string the user
611 typed in or the decompiled expression. */
612 b->cond_string = savestring (arg, strlen (arg));
613 b->condition_not_parsed = 0;
614 for (loc = b->loc; loc; loc = loc->next)
618 parse_exp_1 (&arg, block_for_pc (loc->address), 0);
620 error (_("Junk at end of expression"));
623 breakpoints_changed ();
624 breakpoint_modify_event (b->number);
628 error (_("No breakpoint number %d."), bnum);
632 commands_command (char *arg, int from_tty)
634 struct breakpoint *b;
637 struct command_line *l;
639 /* If we allowed this, we would have problems with when to
640 free the storage, if we change the commands currently
643 if (executing_breakpoint_commands)
644 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
647 bnum = get_number (&p);
650 error (_("Unexpected extra arguments following breakpoint number."));
653 if (b->number == bnum)
655 char *tmpbuf = xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
657 struct cleanup *cleanups = make_cleanup (xfree, tmpbuf);
658 l = read_command_lines (tmpbuf, from_tty);
659 do_cleanups (cleanups);
660 free_command_lines (&b->commands);
662 breakpoints_changed ();
663 breakpoint_modify_event (b->number);
666 error (_("No breakpoint number %d."), bnum);
669 /* Like commands_command, but instead of reading the commands from
670 input stream, takes them from an already parsed command structure.
672 This is used by cli-script.c to DTRT with breakpoint commands
673 that are part of if and while bodies. */
674 enum command_control_type
675 commands_from_control_command (char *arg, struct command_line *cmd)
677 struct breakpoint *b;
681 /* If we allowed this, we would have problems with when to
682 free the storage, if we change the commands currently
685 if (executing_breakpoint_commands)
686 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
688 /* An empty string for the breakpoint number means the last
689 breakpoint, but get_number expects a NULL pointer. */
694 bnum = get_number (&p);
697 error (_("Unexpected extra arguments following breakpoint number."));
700 if (b->number == bnum)
702 free_command_lines (&b->commands);
703 if (cmd->body_count != 1)
704 error (_("Invalid \"commands\" block structure."));
705 /* We need to copy the commands because if/while will free the
706 list after it finishes execution. */
707 b->commands = copy_command_lines (cmd->body_list[0]);
708 breakpoints_changed ();
709 breakpoint_modify_event (b->number);
710 return simple_control;
712 error (_("No breakpoint number %d."), bnum);
715 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
716 by replacing any memory breakpoints with their shadowed contents. */
719 breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len)
721 struct bp_location *b;
722 CORE_ADDR bp_addr = 0;
728 if (b->owner->type == bp_none)
729 warning (_("reading through apparently deleted breakpoint #%d?"),
732 if (b->loc_type != bp_loc_software_breakpoint)
736 /* Addresses and length of the part of the breakpoint that
738 bp_addr = b->target_info.placed_address;
739 bp_size = b->target_info.shadow_len;
741 /* bp isn't valid, or doesn't shadow memory. */
744 if (bp_addr + bp_size <= memaddr)
745 /* The breakpoint is entirely before the chunk of memory we
749 if (bp_addr >= memaddr + len)
750 /* The breakpoint is entirely after the chunk of memory we are
754 /* Offset within shadow_contents. */
755 if (bp_addr < memaddr)
757 /* Only copy the second part of the breakpoint. */
758 bp_size -= memaddr - bp_addr;
759 bptoffset = memaddr - bp_addr;
763 if (bp_addr + bp_size > memaddr + len)
765 /* Only copy the first part of the breakpoint. */
766 bp_size -= (bp_addr + bp_size) - (memaddr + len);
769 memcpy (buf + bp_addr - memaddr,
770 b->target_info.shadow_contents + bptoffset, bp_size);
775 /* A wrapper function for inserting catchpoints. */
777 insert_catchpoint (struct ui_out *uo, void *args)
779 struct breakpoint *b = (struct breakpoint *) args;
785 target_insert_fork_catchpoint (PIDGET (inferior_ptid));
788 target_insert_vfork_catchpoint (PIDGET (inferior_ptid));
791 target_insert_exec_catchpoint (PIDGET (inferior_ptid));
794 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
800 is_hardware_watchpoint (struct breakpoint *bpt)
802 return (bpt->type == bp_hardware_watchpoint
803 || bpt->type == bp_read_watchpoint
804 || bpt->type == bp_access_watchpoint);
807 /* Find the current value of a watchpoint on EXP. Return the value in
808 *VALP and *RESULTP and the chain of intermediate and final values
809 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
812 If an error occurs while evaluating the expression, *RESULTP will
813 be set to NULL. *RESULTP may be a lazy value, if the result could
814 not be read from memory. It is used to determine whether a value
815 is user-specified (we should watch the whole value) or intermediate
816 (we should watch only the bit used to locate the final value).
818 If the final value, or any intermediate value, could not be read
819 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
820 set to any referenced values. *VALP will never be a lazy value.
821 This is the value which we store in struct breakpoint.
823 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
824 value chain. The caller must free the values individually. If
825 VAL_CHAIN is NULL, all generated values will be left on the value
829 fetch_watchpoint_value (struct expression *exp, struct value **valp,
830 struct value **resultp, struct value **val_chain)
832 struct value *mark, *new_mark, *result;
840 /* Evaluate the expression. */
841 mark = value_mark ();
843 gdb_evaluate_expression (exp, &result);
844 new_mark = value_mark ();
845 if (mark == new_mark)
850 /* Make sure it's not lazy, so that after the target stops again we
851 have a non-lazy previous value to compare with. */
853 && (!value_lazy (result) || gdb_value_fetch_lazy (result)))
858 /* Return the chain of intermediate values. We use this to
859 decide which addresses to watch. */
860 *val_chain = new_mark;
861 value_release_to_mark (mark);
865 /* Assuming that B is a hardware watchpoint:
866 - Reparse watchpoint expression, is REPARSE is non-zero
867 - Evaluate expression and store the result in B->val
868 - Update the list of values that must be watched in B->loc.
870 If the watchpoint is disabled, do nothing. If this is
871 local watchpoint that is out of scope, delete it. */
873 update_watchpoint (struct breakpoint *b, int reparse)
875 int within_current_scope;
876 struct frame_id saved_frame_id;
877 struct bp_location *loc;
880 /* We don't free locations. They are stored in
881 bp_location_chain and update_global_locations will
882 eventually delete them and remove breakpoints if
886 if (b->disposition == disp_del_at_next_stop)
889 /* Save the current frame's ID so we can restore it after
890 evaluating the watchpoint expression on its own frame. */
891 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
892 took a frame parameter, so that we didn't have to change the
894 saved_frame_id = get_frame_id (get_selected_frame (NULL));
896 /* Determine if the watchpoint is within scope. */
897 if (b->exp_valid_block == NULL)
898 within_current_scope = 1;
901 struct frame_info *fi;
902 fi = frame_find_by_id (b->watchpoint_frame);
903 within_current_scope = (fi != NULL);
904 if (within_current_scope)
908 if (within_current_scope && reparse)
917 b->exp = parse_exp_1 (&s, b->exp_valid_block, 0);
918 /* If the meaning of expression itself changed, the old value is
919 no longer relevant. We don't want to report a watchpoint hit
920 to the user when the old value and the new value may actually
921 be completely different objects. */
927 /* If we failed to parse the expression, for example because
928 it refers to a global variable in a not-yet-loaded shared library,
929 don't try to insert watchpoint. We don't automatically delete
930 such watchpoint, though, since failure to parse expression
931 is different from out-of-scope watchpoint. */
932 if (within_current_scope && b->exp)
934 struct value *val_chain, *v, *result, *next;
936 fetch_watchpoint_value (b->exp, &v, &result, &val_chain);
938 /* Avoid setting b->val if it's already set. The meaning of
939 b->val is 'the last value' user saw, and we should update
940 it only if we reported that last value to user. As it
941 happens, the code that reports it updates b->val directly. */
948 /* Look at each value on the value chain. */
949 for (v = val_chain; v; v = next)
951 /* If it's a memory location, and GDB actually needed
952 its contents to evaluate the expression, then we
953 must watch it. If the first value returned is
954 still lazy, that means an error occurred reading it;
955 watch it anyway in case it becomes readable. */
956 if (VALUE_LVAL (v) == lval_memory
957 && (v == val_chain || ! value_lazy (v)))
959 struct type *vtype = check_typedef (value_type (v));
961 /* We only watch structs and arrays if user asked
962 for it explicitly, never if they just happen to
963 appear in the middle of some value chain. */
965 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
966 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
970 struct bp_location *loc, **tmp;
972 addr = VALUE_ADDRESS (v) + value_offset (v);
973 len = TYPE_LENGTH (value_type (v));
975 if (b->type == bp_read_watchpoint)
977 else if (b->type == bp_access_watchpoint)
980 loc = allocate_bp_location (b, bp_hardware_watchpoint);
981 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
986 loc->watchpoint_type = type;
990 next = value_next (v);
995 /* We just regenerated the list of breakpoint locations.
996 The new location does not have its condition field set to anything
997 and therefore, we must always reparse the cond_string, independently
998 of the value of the reparse flag. */
999 if (b->cond_string != NULL)
1001 char *s = b->cond_string;
1002 b->loc->cond = parse_exp_1 (&s, b->exp_valid_block, 0);
1005 else if (!within_current_scope)
1007 printf_filtered (_("\
1008 Hardware watchpoint %d deleted because the program has left the block \n\
1009 in which its expression is valid.\n"),
1011 if (b->related_breakpoint)
1012 b->related_breakpoint->disposition = disp_del_at_next_stop;
1013 b->disposition = disp_del_at_next_stop;
1016 /* Restore the selected frame. */
1017 select_frame (frame_find_by_id (saved_frame_id));
1021 /* Returns 1 iff breakpoint location should be
1022 inserted in the inferior. */
1024 should_be_inserted (struct bp_location *bpt)
1026 if (!breakpoint_enabled (bpt->owner))
1029 if (bpt->owner->disposition == disp_del_at_next_stop)
1032 if (!bpt->enabled || bpt->shlib_disabled || bpt->duplicate)
1038 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
1039 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
1040 PROCESS_WARNING, and HW_BREAKPOINT_ERROR are used to report problems.
1042 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1043 method for each breakpoint or catchpoint type. */
1045 insert_bp_location (struct bp_location *bpt,
1046 struct ui_file *tmp_error_stream,
1047 int *disabled_breaks, int *process_warning,
1048 int *hw_breakpoint_error)
1052 if (!should_be_inserted (bpt) || bpt->inserted)
1055 /* Initialize the target-specific information. */
1056 memset (&bpt->target_info, 0, sizeof (bpt->target_info));
1057 bpt->target_info.placed_address = bpt->address;
1059 if (bpt->loc_type == bp_loc_software_breakpoint
1060 || bpt->loc_type == bp_loc_hardware_breakpoint)
1062 if (bpt->owner->type != bp_hardware_breakpoint)
1064 /* If the explicitly specified breakpoint type
1065 is not hardware breakpoint, check the memory map to see
1066 if the breakpoint address is in read only memory or not.
1067 Two important cases are:
1068 - location type is not hardware breakpoint, memory
1069 is readonly. We change the type of the location to
1070 hardware breakpoint.
1071 - location type is hardware breakpoint, memory is read-write.
1072 This means we've previously made the location hardware one, but
1073 then the memory map changed, so we undo.
1075 When breakpoints are removed, remove_breakpoints will
1076 use location types we've just set here, the only possible
1077 problem is that memory map has changed during running program,
1078 but it's not going to work anyway with current gdb. */
1079 struct mem_region *mr
1080 = lookup_mem_region (bpt->target_info.placed_address);
1084 if (automatic_hardware_breakpoints)
1087 enum bp_loc_type new_type;
1089 if (mr->attrib.mode != MEM_RW)
1090 new_type = bp_loc_hardware_breakpoint;
1092 new_type = bp_loc_software_breakpoint;
1094 if (new_type != bpt->loc_type)
1096 static int said = 0;
1097 bpt->loc_type = new_type;
1100 fprintf_filtered (gdb_stdout, _("\
1101 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1106 else if (bpt->loc_type == bp_loc_software_breakpoint
1107 && mr->attrib.mode != MEM_RW)
1108 warning (_("cannot set software breakpoint at readonly address %s"),
1109 paddr (bpt->address));
1113 /* First check to see if we have to handle an overlay. */
1114 if (overlay_debugging == ovly_off
1115 || bpt->section == NULL
1116 || !(section_is_overlay (bpt->section)))
1118 /* No overlay handling: just set the breakpoint. */
1120 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1121 val = target_insert_hw_breakpoint (&bpt->target_info);
1123 val = target_insert_breakpoint (&bpt->target_info);
1127 /* This breakpoint is in an overlay section.
1128 Shall we set a breakpoint at the LMA? */
1129 if (!overlay_events_enabled)
1131 /* Yes -- overlay event support is not active,
1132 so we must try to set a breakpoint at the LMA.
1133 This will not work for a hardware breakpoint. */
1134 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1135 warning (_("hardware breakpoint %d not supported in overlay!"),
1136 bpt->owner->number);
1139 CORE_ADDR addr = overlay_unmapped_address (bpt->address,
1141 /* Set a software (trap) breakpoint at the LMA. */
1142 bpt->overlay_target_info = bpt->target_info;
1143 bpt->overlay_target_info.placed_address = addr;
1144 val = target_insert_breakpoint (&bpt->overlay_target_info);
1146 fprintf_unfiltered (tmp_error_stream,
1147 "Overlay breakpoint %d failed: in ROM?",
1148 bpt->owner->number);
1151 /* Shall we set a breakpoint at the VMA? */
1152 if (section_is_mapped (bpt->section))
1154 /* Yes. This overlay section is mapped into memory. */
1155 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1156 val = target_insert_hw_breakpoint (&bpt->target_info);
1158 val = target_insert_breakpoint (&bpt->target_info);
1162 /* No. This breakpoint will not be inserted.
1163 No error, but do not mark the bp as 'inserted'. */
1170 /* Can't set the breakpoint. */
1171 if (solib_address (bpt->address))
1173 /* See also: disable_breakpoints_in_shlibs. */
1175 bpt->shlib_disabled = 1;
1176 if (!*disabled_breaks)
1178 fprintf_unfiltered (tmp_error_stream,
1179 "Cannot insert breakpoint %d.\n",
1180 bpt->owner->number);
1181 fprintf_unfiltered (tmp_error_stream,
1182 "Temporarily disabling shared library breakpoints:\n");
1184 *disabled_breaks = 1;
1185 fprintf_unfiltered (tmp_error_stream,
1186 "breakpoint #%d\n", bpt->owner->number);
1190 #ifdef ONE_PROCESS_WRITETEXT
1191 *process_warning = 1;
1193 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1195 *hw_breakpoint_error = 1;
1196 fprintf_unfiltered (tmp_error_stream,
1197 "Cannot insert hardware breakpoint %d.\n",
1198 bpt->owner->number);
1202 fprintf_unfiltered (tmp_error_stream,
1203 "Cannot insert breakpoint %d.\n",
1204 bpt->owner->number);
1205 fprintf_filtered (tmp_error_stream,
1206 "Error accessing memory address ");
1207 fputs_filtered (paddress (bpt->address), tmp_error_stream);
1208 fprintf_filtered (tmp_error_stream, ": %s.\n",
1209 safe_strerror (val));
1220 else if (bpt->loc_type == bp_loc_hardware_watchpoint
1221 /* NOTE drow/2003-09-08: This state only exists for removing
1222 watchpoints. It's not clear that it's necessary... */
1223 && bpt->owner->disposition != disp_del_at_next_stop)
1225 val = target_insert_watchpoint (bpt->address,
1227 bpt->watchpoint_type);
1228 bpt->inserted = (val != -1);
1231 else if (bpt->owner->type == bp_catch_fork
1232 || bpt->owner->type == bp_catch_vfork
1233 || bpt->owner->type == bp_catch_exec)
1235 struct gdb_exception e = catch_exception (uiout, insert_catchpoint,
1236 bpt->owner, RETURN_MASK_ERROR);
1237 exception_fprintf (gdb_stderr, e, "warning: inserting catchpoint %d: ",
1238 bpt->owner->number);
1240 bpt->owner->enable_state = bp_disabled;
1244 /* We've already printed an error message if there was a problem
1245 inserting this catchpoint, and we've disabled the catchpoint,
1246 so just return success. */
1253 /* Make sure all breakpoints are inserted in inferior.
1254 Throws exception on any error.
1255 A breakpoint that is already inserted won't be inserted
1256 again, so calling this function twice is safe. */
1258 insert_breakpoints (void)
1260 struct breakpoint *bpt;
1262 ALL_BREAKPOINTS (bpt)
1263 if (is_hardware_watchpoint (bpt))
1264 update_watchpoint (bpt, 0 /* don't reparse. */);
1266 update_global_location_list ();
1268 if (!always_inserted_mode && target_has_execution)
1269 /* update_global_location_list does not insert breakpoints
1270 when always_inserted_mode is not enabled. Explicitly
1272 insert_breakpoint_locations ();
1275 /* insert_breakpoints is used when starting or continuing the program.
1276 remove_breakpoints is used when the program stops.
1277 Both return zero if successful,
1278 or an `errno' value if could not write the inferior. */
1281 insert_breakpoint_locations (void)
1283 struct breakpoint *bpt;
1284 struct bp_location *b, *temp;
1287 int disabled_breaks = 0;
1288 int hw_breakpoint_error = 0;
1289 int process_warning = 0;
1291 struct ui_file *tmp_error_stream = mem_fileopen ();
1292 make_cleanup_ui_file_delete (tmp_error_stream);
1294 /* Explicitly mark the warning -- this will only be printed if
1295 there was an error. */
1296 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
1298 ALL_BP_LOCATIONS_SAFE (b, temp)
1300 if (!should_be_inserted (b) || b->inserted)
1303 /* There is no point inserting thread-specific breakpoints if the
1304 thread no longer exists. */
1305 if (b->owner->thread != -1
1306 && !valid_thread_id (b->owner->thread))
1309 val = insert_bp_location (b, tmp_error_stream,
1310 &disabled_breaks, &process_warning,
1311 &hw_breakpoint_error);
1316 /* If we failed to insert all locations of a watchpoint,
1317 remove them, as half-inserted watchpoint is of limited use. */
1318 ALL_BREAKPOINTS (bpt)
1320 int some_failed = 0;
1321 struct bp_location *loc;
1323 if (!is_hardware_watchpoint (bpt))
1326 if (bpt->enable_state != bp_enabled)
1329 if (bpt->disposition == disp_del_at_next_stop)
1332 for (loc = bpt->loc; loc; loc = loc->next)
1340 for (loc = bpt->loc; loc; loc = loc->next)
1342 remove_breakpoint (loc, mark_uninserted);
1344 hw_breakpoint_error = 1;
1345 fprintf_unfiltered (tmp_error_stream,
1346 "Could not insert hardware watchpoint %d.\n",
1354 /* If a hardware breakpoint or watchpoint was inserted, add a
1355 message about possibly exhausted resources. */
1356 if (hw_breakpoint_error)
1358 fprintf_unfiltered (tmp_error_stream,
1359 "Could not insert hardware breakpoints:\n\
1360 You may have requested too many hardware breakpoints/watchpoints.\n");
1362 #ifdef ONE_PROCESS_WRITETEXT
1363 if (process_warning)
1364 fprintf_unfiltered (tmp_error_stream,
1365 "The same program may be running in another process.");
1367 target_terminal_ours_for_output ();
1368 error_stream (tmp_error_stream);
1373 remove_breakpoints (void)
1375 struct bp_location *b;
1378 ALL_BP_LOCATIONS (b)
1382 val = remove_breakpoint (b, mark_uninserted);
1391 remove_hw_watchpoints (void)
1393 struct bp_location *b;
1396 ALL_BP_LOCATIONS (b)
1398 if (b->inserted && b->loc_type == bp_loc_hardware_watchpoint)
1400 val = remove_breakpoint (b, mark_uninserted);
1409 reattach_breakpoints (int pid)
1411 struct bp_location *b;
1413 struct cleanup *old_chain = save_inferior_ptid ();
1414 struct ui_file *tmp_error_stream = mem_fileopen ();
1415 int dummy1 = 0, dummy2 = 0, dummy3 = 0;
1417 make_cleanup_ui_file_delete (tmp_error_stream);
1419 inferior_ptid = pid_to_ptid (pid);
1420 ALL_BP_LOCATIONS (b)
1425 val = insert_bp_location (b, tmp_error_stream,
1426 &dummy1, &dummy2, &dummy3);
1429 do_cleanups (old_chain);
1434 do_cleanups (old_chain);
1439 restore_always_inserted_mode (void *p)
1441 always_inserted_mode = (uintptr_t) p;
1445 update_breakpoints_after_exec (void)
1447 struct breakpoint *b;
1448 struct breakpoint *temp;
1449 struct cleanup *cleanup;
1451 /* Doing this first prevents the badness of having delete_breakpoint()
1452 write a breakpoint's current "shadow contents" to lift the bp. That
1453 shadow is NOT valid after an exec()! */
1454 mark_breakpoints_out ();
1456 /* The binary we used to debug is now gone, and we're updating
1457 breakpoints for the new binary. Until we're done, we should not
1458 try to insert breakpoints. */
1459 cleanup = make_cleanup (restore_always_inserted_mode,
1460 (void *) (uintptr_t) always_inserted_mode);
1461 always_inserted_mode = 0;
1463 ALL_BREAKPOINTS_SAFE (b, temp)
1465 /* Solib breakpoints must be explicitly reset after an exec(). */
1466 if (b->type == bp_shlib_event)
1468 delete_breakpoint (b);
1472 /* Thread event breakpoints must be set anew after an exec(),
1473 as must overlay event breakpoints. */
1474 if (b->type == bp_thread_event || b->type == bp_overlay_event)
1476 delete_breakpoint (b);
1480 /* Step-resume breakpoints are meaningless after an exec(). */
1481 if (b->type == bp_step_resume)
1483 delete_breakpoint (b);
1487 /* Longjmp and longjmp-resume breakpoints are also meaningless
1489 if (b->type == bp_longjmp || b->type == bp_longjmp_resume)
1491 delete_breakpoint (b);
1495 /* Don't delete an exec catchpoint, because else the inferior
1496 won't stop when it ought!
1498 Similarly, we probably ought to keep vfork catchpoints, 'cause
1499 on this target, we may not be able to stop when the vfork is
1500 seen, but only when the subsequent exec is seen. (And because
1501 deleting fork catchpoints here but not vfork catchpoints will
1502 seem mysterious to users, keep those too.) */
1503 if ((b->type == bp_catch_exec) ||
1504 (b->type == bp_catch_vfork) ||
1505 (b->type == bp_catch_fork))
1510 /* bp_finish is a special case. The only way we ought to be able
1511 to see one of these when an exec() has happened, is if the user
1512 caught a vfork, and then said "finish". Ordinarily a finish just
1513 carries them to the call-site of the current callee, by setting
1514 a temporary bp there and resuming. But in this case, the finish
1515 will carry them entirely through the vfork & exec.
1517 We don't want to allow a bp_finish to remain inserted now. But
1518 we can't safely delete it, 'cause finish_command has a handle to
1519 the bp on a bpstat, and will later want to delete it. There's a
1520 chance (and I've seen it happen) that if we delete the bp_finish
1521 here, that its storage will get reused by the time finish_command
1522 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1523 We really must allow finish_command to delete a bp_finish.
1525 In the absense of a general solution for the "how do we know
1526 it's safe to delete something others may have handles to?"
1527 problem, what we'll do here is just uninsert the bp_finish, and
1528 let finish_command delete it.
1530 (We know the bp_finish is "doomed" in the sense that it's
1531 momentary, and will be deleted as soon as finish_command sees
1532 the inferior stopped. So it doesn't matter that the bp's
1533 address is probably bogus in the new a.out, unlike e.g., the
1534 solib breakpoints.) */
1536 if (b->type == bp_finish)
1541 /* Without a symbolic address, we have little hope of the
1542 pre-exec() address meaning the same thing in the post-exec()
1544 if (b->addr_string == NULL)
1546 delete_breakpoint (b);
1550 /* FIXME what about longjmp breakpoints? Re-create them here? */
1551 create_overlay_event_breakpoint ("_ovly_debug_event");
1552 do_cleanups (cleanup);
1556 detach_breakpoints (int pid)
1558 struct bp_location *b;
1560 struct cleanup *old_chain = save_inferior_ptid ();
1562 if (pid == PIDGET (inferior_ptid))
1563 error (_("Cannot detach breakpoints of inferior_ptid"));
1565 /* Set inferior_ptid; remove_breakpoint uses this global. */
1566 inferior_ptid = pid_to_ptid (pid);
1567 ALL_BP_LOCATIONS (b)
1571 val = remove_breakpoint (b, mark_inserted);
1574 do_cleanups (old_chain);
1579 do_cleanups (old_chain);
1584 remove_breakpoint (struct bp_location *b, insertion_state_t is)
1588 if (b->owner->enable_state == bp_permanent)
1589 /* Permanent breakpoints cannot be inserted or removed. */
1592 /* The type of none suggests that owner is actually deleted.
1593 This should not ever happen. */
1594 gdb_assert (b->owner->type != bp_none);
1596 if (b->loc_type == bp_loc_software_breakpoint
1597 || b->loc_type == bp_loc_hardware_breakpoint)
1599 /* "Normal" instruction breakpoint: either the standard
1600 trap-instruction bp (bp_breakpoint), or a
1601 bp_hardware_breakpoint. */
1603 /* First check to see if we have to handle an overlay. */
1604 if (overlay_debugging == ovly_off
1605 || b->section == NULL
1606 || !(section_is_overlay (b->section)))
1608 /* No overlay handling: just remove the breakpoint. */
1610 if (b->loc_type == bp_loc_hardware_breakpoint)
1611 val = target_remove_hw_breakpoint (&b->target_info);
1613 val = target_remove_breakpoint (&b->target_info);
1617 /* This breakpoint is in an overlay section.
1618 Did we set a breakpoint at the LMA? */
1619 if (!overlay_events_enabled)
1621 /* Yes -- overlay event support is not active, so we
1622 should have set a breakpoint at the LMA. Remove it.
1624 /* Ignore any failures: if the LMA is in ROM, we will
1625 have already warned when we failed to insert it. */
1626 if (b->loc_type == bp_loc_hardware_breakpoint)
1627 target_remove_hw_breakpoint (&b->overlay_target_info);
1629 target_remove_breakpoint (&b->overlay_target_info);
1631 /* Did we set a breakpoint at the VMA?
1632 If so, we will have marked the breakpoint 'inserted'. */
1635 /* Yes -- remove it. Previously we did not bother to
1636 remove the breakpoint if the section had been
1637 unmapped, but let's not rely on that being safe. We
1638 don't know what the overlay manager might do. */
1639 if (b->loc_type == bp_loc_hardware_breakpoint)
1640 val = target_remove_hw_breakpoint (&b->target_info);
1642 /* However, we should remove *software* breakpoints only
1643 if the section is still mapped, or else we overwrite
1644 wrong code with the saved shadow contents. */
1645 else if (section_is_mapped (b->section))
1646 val = target_remove_breakpoint (&b->target_info);
1652 /* No -- not inserted, so no need to remove. No error. */
1658 b->inserted = (is == mark_inserted);
1660 else if (b->loc_type == bp_loc_hardware_watchpoint)
1665 b->inserted = (is == mark_inserted);
1666 val = target_remove_watchpoint (b->address, b->length,
1667 b->watchpoint_type);
1669 /* Failure to remove any of the hardware watchpoints comes here. */
1670 if ((is == mark_uninserted) && (b->inserted))
1671 warning (_("Could not remove hardware watchpoint %d."),
1674 else if ((b->owner->type == bp_catch_fork ||
1675 b->owner->type == bp_catch_vfork ||
1676 b->owner->type == bp_catch_exec)
1677 && breakpoint_enabled (b->owner)
1681 switch (b->owner->type)
1684 val = target_remove_fork_catchpoint (PIDGET (inferior_ptid));
1686 case bp_catch_vfork:
1687 val = target_remove_vfork_catchpoint (PIDGET (inferior_ptid));
1690 val = target_remove_exec_catchpoint (PIDGET (inferior_ptid));
1693 warning (_("Internal error, %s line %d."), __FILE__, __LINE__);
1698 b->inserted = (is == mark_inserted);
1704 /* Clear the "inserted" flag in all breakpoints. */
1707 mark_breakpoints_out (void)
1709 struct bp_location *bpt;
1711 ALL_BP_LOCATIONS (bpt)
1715 /* Clear the "inserted" flag in all breakpoints and delete any
1716 breakpoints which should go away between runs of the program.
1718 Plus other such housekeeping that has to be done for breakpoints
1721 Note: this function gets called at the end of a run (by
1722 generic_mourn_inferior) and when a run begins (by
1723 init_wait_for_inferior). */
1728 breakpoint_init_inferior (enum inf_context context)
1730 struct breakpoint *b, *temp;
1731 struct bp_location *bpt;
1733 ALL_BP_LOCATIONS (bpt)
1736 ALL_BREAKPOINTS_SAFE (b, temp)
1741 case bp_watchpoint_scope:
1743 /* If the call dummy breakpoint is at the entry point it will
1744 cause problems when the inferior is rerun, so we better
1747 Also get rid of scope breakpoints. */
1748 delete_breakpoint (b);
1752 case bp_hardware_watchpoint:
1753 case bp_read_watchpoint:
1754 case bp_access_watchpoint:
1756 /* Likewise for watchpoints on local expressions. */
1757 if (b->exp_valid_block != NULL)
1758 delete_breakpoint (b);
1759 else if (context == inf_starting)
1761 /* Reset val field to force reread of starting value
1762 in insert_breakpoints. */
1764 value_free (b->val);
1775 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1776 exists at PC. It returns ordinary_breakpoint_here if it's an
1777 ordinary breakpoint, or permanent_breakpoint_here if it's a
1778 permanent breakpoint.
1779 - When continuing from a location with an ordinary breakpoint, we
1780 actually single step once before calling insert_breakpoints.
1781 - When continuing from a localion with a permanent breakpoint, we
1782 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1783 the target, to advance the PC past the breakpoint. */
1785 enum breakpoint_here
1786 breakpoint_here_p (CORE_ADDR pc)
1788 const struct bp_location *bpt;
1789 int any_breakpoint_here = 0;
1791 ALL_BP_LOCATIONS (bpt)
1793 if (bpt->loc_type != bp_loc_software_breakpoint
1794 && bpt->loc_type != bp_loc_hardware_breakpoint)
1797 if ((breakpoint_enabled (bpt->owner)
1798 || bpt->owner->enable_state == bp_permanent)
1799 && bpt->address == pc) /* bp is enabled and matches pc */
1801 if (overlay_debugging
1802 && section_is_overlay (bpt->section)
1803 && !section_is_mapped (bpt->section))
1804 continue; /* unmapped overlay -- can't be a match */
1805 else if (bpt->owner->enable_state == bp_permanent)
1806 return permanent_breakpoint_here;
1808 any_breakpoint_here = 1;
1812 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
1816 /* Returns non-zero if there's a breakpoint inserted at PC, which is
1817 inserted using regular breakpoint_chain/bp_location_chain mechanism.
1818 This does not check for single-step breakpoints, which are
1819 inserted and removed using direct target manipulation. */
1822 regular_breakpoint_inserted_here_p (CORE_ADDR pc)
1824 const struct bp_location *bpt;
1826 ALL_BP_LOCATIONS (bpt)
1828 if (bpt->loc_type != bp_loc_software_breakpoint
1829 && bpt->loc_type != bp_loc_hardware_breakpoint)
1833 && bpt->address == pc) /* bp is inserted and matches pc */
1835 if (overlay_debugging
1836 && section_is_overlay (bpt->section)
1837 && !section_is_mapped (bpt->section))
1838 continue; /* unmapped overlay -- can't be a match */
1846 /* Returns non-zero iff there's either regular breakpoint
1847 or a single step breakpoint inserted at PC. */
1850 breakpoint_inserted_here_p (CORE_ADDR pc)
1852 if (regular_breakpoint_inserted_here_p (pc))
1855 if (single_step_breakpoint_inserted_here_p (pc))
1861 /* This function returns non-zero iff there is a software breakpoint
1865 software_breakpoint_inserted_here_p (CORE_ADDR pc)
1867 const struct bp_location *bpt;
1868 int any_breakpoint_here = 0;
1870 ALL_BP_LOCATIONS (bpt)
1872 if (bpt->loc_type != bp_loc_software_breakpoint)
1876 && bpt->address == pc) /* bp is enabled and matches pc */
1878 if (overlay_debugging
1879 && section_is_overlay (bpt->section)
1880 && !section_is_mapped (bpt->section))
1881 continue; /* unmapped overlay -- can't be a match */
1887 /* Also check for software single-step breakpoints. */
1888 if (single_step_breakpoint_inserted_here_p (pc))
1894 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
1895 PC is valid for process/thread PTID. */
1898 breakpoint_thread_match (CORE_ADDR pc, ptid_t ptid)
1900 const struct bp_location *bpt;
1903 thread = pid_to_thread_id (ptid);
1905 ALL_BP_LOCATIONS (bpt)
1907 if (bpt->loc_type != bp_loc_software_breakpoint
1908 && bpt->loc_type != bp_loc_hardware_breakpoint)
1911 if ((breakpoint_enabled (bpt->owner)
1912 || bpt->owner->enable_state == bp_permanent)
1913 && bpt->address == pc
1914 && (bpt->owner->thread == -1 || bpt->owner->thread == thread))
1916 if (overlay_debugging
1917 && section_is_overlay (bpt->section)
1918 && !section_is_mapped (bpt->section))
1919 continue; /* unmapped overlay -- can't be a match */
1929 /* bpstat stuff. External routines' interfaces are documented
1933 ep_is_catchpoint (struct breakpoint *ep)
1936 (ep->type == bp_catch_load)
1937 || (ep->type == bp_catch_unload)
1938 || (ep->type == bp_catch_fork)
1939 || (ep->type == bp_catch_vfork)
1940 || (ep->type == bp_catch_exec);
1942 /* ??rehrauer: Add more kinds here, as are implemented... */
1946 ep_is_shlib_catchpoint (struct breakpoint *ep)
1949 (ep->type == bp_catch_load)
1950 || (ep->type == bp_catch_unload);
1954 bpstat_free (bpstat bs)
1956 if (bs->old_val != NULL)
1957 value_free (bs->old_val);
1958 free_command_lines (&bs->commands);
1962 /* Clear a bpstat so that it says we are not at any breakpoint.
1963 Also free any storage that is part of a bpstat. */
1966 bpstat_clear (bpstat *bsp)
1983 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1984 is part of the bpstat is copied as well. */
1987 bpstat_copy (bpstat bs)
1991 bpstat retval = NULL;
1996 for (; bs != NULL; bs = bs->next)
1998 tmp = (bpstat) xmalloc (sizeof (*tmp));
1999 memcpy (tmp, bs, sizeof (*tmp));
2000 if (bs->commands != NULL)
2001 tmp->commands = copy_command_lines (bs->commands);
2002 if (bs->old_val != NULL)
2003 tmp->old_val = value_copy (bs->old_val);
2006 /* This is the first thing in the chain. */
2016 /* Find the bpstat associated with this breakpoint */
2019 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
2024 for (; bsp != NULL; bsp = bsp->next)
2026 if (bsp->breakpoint_at && bsp->breakpoint_at->owner == breakpoint)
2032 /* Find a step_resume breakpoint associated with this bpstat.
2033 (If there are multiple step_resume bp's on the list, this function
2034 will arbitrarily pick one.)
2036 It is an error to use this function if BPSTAT doesn't contain a
2037 step_resume breakpoint.
2039 See wait_for_inferior's use of this function. */
2041 bpstat_find_step_resume_breakpoint (bpstat bsp)
2045 gdb_assert (bsp != NULL);
2047 current_thread = pid_to_thread_id (inferior_ptid);
2049 for (; bsp != NULL; bsp = bsp->next)
2051 if ((bsp->breakpoint_at != NULL) &&
2052 (bsp->breakpoint_at->owner->type == bp_step_resume) &&
2053 (bsp->breakpoint_at->owner->thread == current_thread ||
2054 bsp->breakpoint_at->owner->thread == -1))
2055 return bsp->breakpoint_at->owner;
2058 internal_error (__FILE__, __LINE__, _("No step_resume breakpoint found."));
2062 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2063 at. *BSP upon return is a bpstat which points to the remaining
2064 breakpoints stopped at (but which is not guaranteed to be good for
2065 anything but further calls to bpstat_num).
2066 Return 0 if passed a bpstat which does not indicate any breakpoints.
2067 Return -1 if stopped at a breakpoint that has been deleted since
2069 Return 1 otherwise. */
2072 bpstat_num (bpstat *bsp, int *num)
2074 struct breakpoint *b;
2077 return 0; /* No more breakpoint values */
2079 /* We assume we'll never have several bpstats that
2080 correspond to a single breakpoint -- otherwise,
2081 this function might return the same number more
2082 than once and this will look ugly. */
2083 b = (*bsp)->breakpoint_at ? (*bsp)->breakpoint_at->owner : NULL;
2084 *bsp = (*bsp)->next;
2086 return -1; /* breakpoint that's been deleted since */
2088 *num = b->number; /* We have its number */
2092 /* Modify BS so that the actions will not be performed. */
2095 bpstat_clear_actions (bpstat bs)
2097 for (; bs != NULL; bs = bs->next)
2099 free_command_lines (&bs->commands);
2100 if (bs->old_val != NULL)
2102 value_free (bs->old_val);
2108 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2110 cleanup_executing_breakpoints (void *ignore)
2112 executing_breakpoint_commands = 0;
2115 /* Execute all the commands associated with all the breakpoints at this
2116 location. Any of these commands could cause the process to proceed
2117 beyond this point, etc. We look out for such changes by checking
2118 the global "breakpoint_proceeded" after each command. */
2121 bpstat_do_actions (bpstat *bsp)
2124 struct cleanup *old_chain;
2126 /* Avoid endless recursion if a `source' command is contained
2128 if (executing_breakpoint_commands)
2131 executing_breakpoint_commands = 1;
2132 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
2135 /* Note that (as of this writing), our callers all appear to
2136 be passing us the address of global stop_bpstat. And, if
2137 our calls to execute_control_command cause the inferior to
2138 proceed, that global (and hence, *bsp) will change.
2140 We must be careful to not touch *bsp unless the inferior
2141 has not proceeded. */
2143 /* This pointer will iterate over the list of bpstat's. */
2146 breakpoint_proceeded = 0;
2147 for (; bs != NULL; bs = bs->next)
2149 struct command_line *cmd;
2150 struct cleanup *this_cmd_tree_chain;
2152 /* Take ownership of the BSP's command tree, if it has one.
2154 The command tree could legitimately contain commands like
2155 'step' and 'next', which call clear_proceed_status, which
2156 frees stop_bpstat's command tree. To make sure this doesn't
2157 free the tree we're executing out from under us, we need to
2158 take ownership of the tree ourselves. Since a given bpstat's
2159 commands are only executed once, we don't need to copy it; we
2160 can clear the pointer in the bpstat, and make sure we free
2161 the tree when we're done. */
2164 this_cmd_tree_chain = make_cleanup_free_command_lines (&cmd);
2168 execute_control_command (cmd);
2170 if (breakpoint_proceeded)
2176 /* We can free this command tree now. */
2177 do_cleanups (this_cmd_tree_chain);
2179 if (breakpoint_proceeded)
2181 if (target_can_async_p ())
2182 /* If we are in async mode, then the target might
2183 be still running, not stopped at any breakpoint,
2184 so nothing for us to do here -- just return to
2188 /* In sync mode, when execute_control_command returns
2189 we're already standing on the next breakpoint.
2190 Breakpoint commands for that stop were not run,
2191 since execute_command does not run breakpoint
2192 commands -- only command_line_handler does, but
2193 that one is not involved in execution of breakpoint
2194 commands. So, we can now execute breakpoint commands.
2195 There's an implicit assumption that we're called with
2196 stop_bpstat, so our parameter is the new bpstat to
2198 It should be noted that making execute_command do
2199 bpstat actions is not an option -- in this case we'll
2200 have recursive invocation of bpstat for each breakpoint
2201 with a command, and can easily blow up GDB stack. */
2205 do_cleanups (old_chain);
2208 /* Print out the (old or new) value associated with a watchpoint. */
2211 watchpoint_value_print (struct value *val, struct ui_file *stream)
2214 fprintf_unfiltered (stream, _("<unreadable>"));
2216 value_print (val, stream, 0, Val_pretty_default);
2219 /* This is the normal print function for a bpstat. In the future,
2220 much of this logic could (should?) be moved to bpstat_stop_status,
2221 by having it set different print_it values.
2223 Current scheme: When we stop, bpstat_print() is called. It loops
2224 through the bpstat list of things causing this stop, calling the
2225 print_bp_stop_message function on each one. The behavior of the
2226 print_bp_stop_message function depends on the print_it field of
2227 bpstat. If such field so indicates, call this function here.
2229 Return values from this routine (ultimately used by bpstat_print()
2230 and normal_stop() to decide what to do):
2231 PRINT_NOTHING: Means we already printed all we needed to print,
2232 don't print anything else.
2233 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2234 that something to be followed by a location.
2235 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2236 that something to be followed by a location.
2237 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2240 static enum print_stop_action
2241 print_it_typical (bpstat bs)
2243 struct cleanup *old_chain, *ui_out_chain;
2244 struct breakpoint *b;
2245 const struct bp_location *bl;
2246 struct ui_stream *stb;
2248 stb = ui_out_stream_new (uiout);
2249 old_chain = make_cleanup_ui_out_stream_delete (stb);
2250 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2251 which has since been deleted. */
2252 if (bs->breakpoint_at == NULL)
2253 return PRINT_UNKNOWN;
2254 bl = bs->breakpoint_at;
2260 case bp_hardware_breakpoint:
2261 bp_temp = bs->breakpoint_at->owner->disposition == disp_del;
2262 if (bl->address != bl->requested_address)
2263 breakpoint_adjustment_warning (bl->requested_address,
2266 annotate_breakpoint (b->number);
2268 ui_out_text (uiout, "\nTemporary breakpoint ");
2270 ui_out_text (uiout, "\nBreakpoint ");
2271 if (ui_out_is_mi_like_p (uiout))
2273 ui_out_field_string (uiout, "reason",
2274 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
2275 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
2277 ui_out_field_int (uiout, "bkptno", b->number);
2278 ui_out_text (uiout, ", ");
2279 return PRINT_SRC_AND_LOC;
2282 case bp_shlib_event:
2283 /* Did we stop because the user set the stop_on_solib_events
2284 variable? (If so, we report this as a generic, "Stopped due
2285 to shlib event" message.) */
2286 printf_filtered (_("Stopped due to shared library event\n"));
2287 return PRINT_NOTHING;
2290 case bp_thread_event:
2291 /* Not sure how we will get here.
2292 GDB should not stop for these breakpoints. */
2293 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2294 return PRINT_NOTHING;
2297 case bp_overlay_event:
2298 /* By analogy with the thread event, GDB should not stop for these. */
2299 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2300 return PRINT_NOTHING;
2304 annotate_catchpoint (b->number);
2305 printf_filtered (_("\nCatchpoint %d (loaded %s), "),
2307 b->triggered_dll_pathname);
2308 return PRINT_SRC_AND_LOC;
2311 case bp_catch_unload:
2312 annotate_catchpoint (b->number);
2313 printf_filtered (_("\nCatchpoint %d (unloaded %s), "),
2315 b->triggered_dll_pathname);
2316 return PRINT_SRC_AND_LOC;
2320 annotate_catchpoint (b->number);
2321 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
2323 b->forked_inferior_pid);
2324 return PRINT_SRC_AND_LOC;
2327 case bp_catch_vfork:
2328 annotate_catchpoint (b->number);
2329 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
2331 b->forked_inferior_pid);
2332 return PRINT_SRC_AND_LOC;
2336 annotate_catchpoint (b->number);
2337 printf_filtered (_("\nCatchpoint %d (exec'd %s), "),
2340 return PRINT_SRC_AND_LOC;
2344 case bp_hardware_watchpoint:
2345 annotate_watchpoint (b->number);
2346 if (ui_out_is_mi_like_p (uiout))
2349 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
2351 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2352 ui_out_text (uiout, "\nOld value = ");
2353 watchpoint_value_print (bs->old_val, stb->stream);
2354 ui_out_field_stream (uiout, "old", stb);
2355 ui_out_text (uiout, "\nNew value = ");
2356 watchpoint_value_print (b->val, stb->stream);
2357 ui_out_field_stream (uiout, "new", stb);
2358 do_cleanups (ui_out_chain);
2359 ui_out_text (uiout, "\n");
2360 /* More than one watchpoint may have been triggered. */
2361 return PRINT_UNKNOWN;
2364 case bp_read_watchpoint:
2365 if (ui_out_is_mi_like_p (uiout))
2368 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
2370 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2371 ui_out_text (uiout, "\nValue = ");
2372 watchpoint_value_print (b->val, stb->stream);
2373 ui_out_field_stream (uiout, "value", stb);
2374 do_cleanups (ui_out_chain);
2375 ui_out_text (uiout, "\n");
2376 return PRINT_UNKNOWN;
2379 case bp_access_watchpoint:
2380 if (bs->old_val != NULL)
2382 annotate_watchpoint (b->number);
2383 if (ui_out_is_mi_like_p (uiout))
2386 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
2388 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2389 ui_out_text (uiout, "\nOld value = ");
2390 watchpoint_value_print (bs->old_val, stb->stream);
2391 ui_out_field_stream (uiout, "old", stb);
2392 ui_out_text (uiout, "\nNew value = ");
2397 if (ui_out_is_mi_like_p (uiout))
2400 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
2401 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2402 ui_out_text (uiout, "\nValue = ");
2404 watchpoint_value_print (b->val, stb->stream);
2405 ui_out_field_stream (uiout, "new", stb);
2406 do_cleanups (ui_out_chain);
2407 ui_out_text (uiout, "\n");
2408 return PRINT_UNKNOWN;
2411 /* Fall through, we don't deal with these types of breakpoints
2415 if (ui_out_is_mi_like_p (uiout))
2418 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED));
2419 return PRINT_UNKNOWN;
2423 if (ui_out_is_mi_like_p (uiout))
2426 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED));
2427 return PRINT_UNKNOWN;
2432 case bp_longjmp_resume:
2433 case bp_step_resume:
2434 case bp_watchpoint_scope:
2437 return PRINT_UNKNOWN;
2441 /* Generic routine for printing messages indicating why we
2442 stopped. The behavior of this function depends on the value
2443 'print_it' in the bpstat structure. Under some circumstances we
2444 may decide not to print anything here and delegate the task to
2447 static enum print_stop_action
2448 print_bp_stop_message (bpstat bs)
2450 switch (bs->print_it)
2453 /* Nothing should be printed for this bpstat entry. */
2454 return PRINT_UNKNOWN;
2458 /* We still want to print the frame, but we already printed the
2459 relevant messages. */
2460 return PRINT_SRC_AND_LOC;
2463 case print_it_normal:
2465 const struct bp_location *bl = bs->breakpoint_at;
2466 struct breakpoint *b = bl ? bl->owner : NULL;
2468 /* Normal case. Call the breakpoint's print_it method, or
2469 print_it_typical. */
2470 /* FIXME: how breakpoint can ever be NULL here? */
2471 if (b != NULL && b->ops != NULL && b->ops->print_it != NULL)
2472 return b->ops->print_it (b);
2474 return print_it_typical (bs);
2479 internal_error (__FILE__, __LINE__,
2480 _("print_bp_stop_message: unrecognized enum value"));
2485 /* Print a message indicating what happened. This is called from
2486 normal_stop(). The input to this routine is the head of the bpstat
2487 list - a list of the eventpoints that caused this stop. This
2488 routine calls the generic print routine for printing a message
2489 about reasons for stopping. This will print (for example) the
2490 "Breakpoint n," part of the output. The return value of this
2493 PRINT_UNKNOWN: Means we printed nothing
2494 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2495 code to print the location. An example is
2496 "Breakpoint 1, " which should be followed by
2498 PRINT_SRC_ONLY: Means we printed something, but there is no need
2499 to also print the location part of the message.
2500 An example is the catch/throw messages, which
2501 don't require a location appended to the end.
2502 PRINT_NOTHING: We have done some printing and we don't need any
2503 further info to be printed.*/
2505 enum print_stop_action
2506 bpstat_print (bpstat bs)
2510 /* Maybe another breakpoint in the chain caused us to stop.
2511 (Currently all watchpoints go on the bpstat whether hit or not.
2512 That probably could (should) be changed, provided care is taken
2513 with respect to bpstat_explains_signal). */
2514 for (; bs; bs = bs->next)
2516 val = print_bp_stop_message (bs);
2517 if (val == PRINT_SRC_ONLY
2518 || val == PRINT_SRC_AND_LOC
2519 || val == PRINT_NOTHING)
2523 /* We reached the end of the chain, or we got a null BS to start
2524 with and nothing was printed. */
2525 return PRINT_UNKNOWN;
2528 /* Evaluate the expression EXP and return 1 if value is zero.
2529 This is used inside a catch_errors to evaluate the breakpoint condition.
2530 The argument is a "struct expression *" that has been cast to char * to
2531 make it pass through catch_errors. */
2534 breakpoint_cond_eval (void *exp)
2536 struct value *mark = value_mark ();
2537 int i = !value_true (evaluate_expression ((struct expression *) exp));
2538 value_free_to_mark (mark);
2542 /* Allocate a new bpstat and chain it to the current one. */
2545 bpstat_alloc (const struct bp_location *bl, bpstat cbs /* Current "bs" value */ )
2549 bs = (bpstat) xmalloc (sizeof (*bs));
2551 bs->breakpoint_at = bl;
2552 /* If the condition is false, etc., don't do the commands. */
2553 bs->commands = NULL;
2555 bs->print_it = print_it_normal;
2559 /* The target has stopped with waitstatus WS. Check if any hardware
2560 watchpoints have triggered, according to the target. */
2563 watchpoints_triggered (struct target_waitstatus *ws)
2565 int stopped_by_watchpoint = STOPPED_BY_WATCHPOINT (*ws);
2567 struct breakpoint *b;
2569 if (!stopped_by_watchpoint)
2571 /* We were not stopped by a watchpoint. Mark all watchpoints
2572 as not triggered. */
2574 if (b->type == bp_hardware_watchpoint
2575 || b->type == bp_read_watchpoint
2576 || b->type == bp_access_watchpoint)
2577 b->watchpoint_triggered = watch_triggered_no;
2582 if (!target_stopped_data_address (¤t_target, &addr))
2584 /* We were stopped by a watchpoint, but we don't know where.
2585 Mark all watchpoints as unknown. */
2587 if (b->type == bp_hardware_watchpoint
2588 || b->type == bp_read_watchpoint
2589 || b->type == bp_access_watchpoint)
2590 b->watchpoint_triggered = watch_triggered_unknown;
2592 return stopped_by_watchpoint;
2595 /* The target could report the data address. Mark watchpoints
2596 affected by this data address as triggered, and all others as not
2600 if (b->type == bp_hardware_watchpoint
2601 || b->type == bp_read_watchpoint
2602 || b->type == bp_access_watchpoint)
2604 struct bp_location *loc;
2607 b->watchpoint_triggered = watch_triggered_no;
2608 for (loc = b->loc; loc; loc = loc->next)
2609 /* Exact match not required. Within range is
2611 if (target_watchpoint_addr_within_range (¤t_target,
2615 b->watchpoint_triggered = watch_triggered_yes;
2623 /* Possible return values for watchpoint_check (this can't be an enum
2624 because of check_errors). */
2625 /* The watchpoint has been deleted. */
2626 #define WP_DELETED 1
2627 /* The value has changed. */
2628 #define WP_VALUE_CHANGED 2
2629 /* The value has not changed. */
2630 #define WP_VALUE_NOT_CHANGED 3
2632 #define BP_TEMPFLAG 1
2633 #define BP_HARDWAREFLAG 2
2635 /* Check watchpoint condition. */
2638 watchpoint_check (void *p)
2640 bpstat bs = (bpstat) p;
2641 struct breakpoint *b;
2642 struct frame_info *fr;
2643 int within_current_scope;
2645 b = bs->breakpoint_at->owner;
2647 if (b->exp_valid_block == NULL)
2648 within_current_scope = 1;
2651 /* There is no current frame at this moment. If we're going to have
2652 any chance of handling watchpoints on local variables, we'll need
2653 the frame chain (so we can determine if we're in scope). */
2654 reinit_frame_cache ();
2655 fr = frame_find_by_id (b->watchpoint_frame);
2656 within_current_scope = (fr != NULL);
2658 /* If we've gotten confused in the unwinder, we might have
2659 returned a frame that can't describe this variable. */
2660 if (within_current_scope
2661 && block_function (b->exp_valid_block) != get_frame_function (fr))
2662 within_current_scope = 0;
2664 /* in_function_epilogue_p() returns a non-zero value if we're still
2665 in the function but the stack frame has already been invalidated.
2666 Since we can't rely on the values of local variables after the
2667 stack has been destroyed, we are treating the watchpoint in that
2668 state as `not changed' without further checking.
2670 vinschen/2003-09-04: The former implementation left out the case
2671 that the watchpoint frame couldn't be found by frame_find_by_id()
2672 because the current PC is currently in an epilogue. Calling
2673 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2674 if ((!within_current_scope || fr == get_current_frame ())
2675 && gdbarch_in_function_epilogue_p (current_gdbarch, read_pc ()))
2676 return WP_VALUE_NOT_CHANGED;
2677 if (fr && within_current_scope)
2678 /* If we end up stopping, the current frame will get selected
2679 in normal_stop. So this call to select_frame won't affect
2684 if (within_current_scope)
2686 /* We use value_{,free_to_}mark because it could be a
2687 *long* time before we return to the command level and
2688 call free_all_values. We can't call free_all_values because
2689 we might be in the middle of evaluating a function call. */
2691 struct value *mark = value_mark ();
2692 struct value *new_val;
2694 fetch_watchpoint_value (b->exp, &new_val, NULL, NULL);
2695 if ((b->val != NULL) != (new_val != NULL)
2696 || (b->val != NULL && !value_equal (b->val, new_val)))
2698 if (new_val != NULL)
2700 release_value (new_val);
2701 value_free_to_mark (mark);
2703 bs->old_val = b->val;
2706 /* We will stop here */
2707 return WP_VALUE_CHANGED;
2711 /* Nothing changed, don't do anything. */
2712 value_free_to_mark (mark);
2713 /* We won't stop here */
2714 return WP_VALUE_NOT_CHANGED;
2719 /* This seems like the only logical thing to do because
2720 if we temporarily ignored the watchpoint, then when
2721 we reenter the block in which it is valid it contains
2722 garbage (in the case of a function, it may have two
2723 garbage values, one before and one after the prologue).
2724 So we can't even detect the first assignment to it and
2725 watch after that (since the garbage may or may not equal
2726 the first value assigned). */
2727 /* We print all the stop information in print_it_typical(), but
2728 in this case, by the time we call print_it_typical() this bp
2729 will be deleted already. So we have no choice but print the
2730 information here. */
2731 if (ui_out_is_mi_like_p (uiout))
2733 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
2734 ui_out_text (uiout, "\nWatchpoint ");
2735 ui_out_field_int (uiout, "wpnum", b->number);
2736 ui_out_text (uiout, " deleted because the program has left the block in\n\
2737 which its expression is valid.\n");
2739 if (b->related_breakpoint)
2740 b->related_breakpoint->disposition = disp_del_at_next_stop;
2741 b->disposition = disp_del_at_next_stop;
2747 /* Return true if it looks like target has stopped due to hitting
2748 breakpoint location BL. This function does not check if we
2749 should stop, only if BL explains the stop. */
2751 bpstat_check_location (const struct bp_location *bl, CORE_ADDR bp_addr)
2753 struct breakpoint *b = bl->owner;
2755 if (b->type != bp_watchpoint
2756 && b->type != bp_hardware_watchpoint
2757 && b->type != bp_read_watchpoint
2758 && b->type != bp_access_watchpoint
2759 && b->type != bp_hardware_breakpoint
2760 && b->type != bp_catch_fork
2761 && b->type != bp_catch_vfork
2762 && b->type != bp_catch_exec) /* a non-watchpoint bp */
2764 if (bl->address != bp_addr) /* address doesn't match */
2766 if (overlay_debugging /* unmapped overlay section */
2767 && section_is_overlay (bl->section)
2768 && !section_is_mapped (bl->section))
2772 /* Continuable hardware watchpoints are treated as non-existent if the
2773 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2774 some data address). Otherwise gdb won't stop on a break instruction
2775 in the code (not from a breakpoint) when a hardware watchpoint has
2776 been defined. Also skip watchpoints which we know did not trigger
2777 (did not match the data address). */
2779 if ((b->type == bp_hardware_watchpoint
2780 || b->type == bp_read_watchpoint
2781 || b->type == bp_access_watchpoint)
2782 && b->watchpoint_triggered == watch_triggered_no)
2785 if (b->type == bp_hardware_breakpoint)
2787 if (bl->address != bp_addr)
2789 if (overlay_debugging /* unmapped overlay section */
2790 && section_is_overlay (bl->section)
2791 && !section_is_mapped (bl->section))
2795 /* Is this a catchpoint of a load or unload? If so, did we
2796 get a load or unload of the specified library? If not,
2798 if ((b->type == bp_catch_load)
2799 #if defined(SOLIB_HAVE_LOAD_EVENT)
2800 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid))
2801 || ((b->dll_pathname != NULL)
2802 && (strcmp (b->dll_pathname,
2803 SOLIB_LOADED_LIBRARY_PATHNAME (
2804 PIDGET (inferior_ptid)))
2810 if ((b->type == bp_catch_unload)
2811 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2812 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid))
2813 || ((b->dll_pathname != NULL)
2814 && (strcmp (b->dll_pathname,
2815 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2816 PIDGET (inferior_ptid)))
2822 if ((b->type == bp_catch_fork)
2823 && !inferior_has_forked (PIDGET (inferior_ptid),
2824 &b->forked_inferior_pid))
2827 if ((b->type == bp_catch_vfork)
2828 && !inferior_has_vforked (PIDGET (inferior_ptid),
2829 &b->forked_inferior_pid))
2832 if ((b->type == bp_catch_exec)
2833 && !inferior_has_execd (PIDGET (inferior_ptid), &b->exec_pathname))
2839 /* If BS refers to a watchpoint, determine if the watched values
2840 has actually changed, and we should stop. If not, set BS->stop
2843 bpstat_check_watchpoint (bpstat bs)
2845 const struct bp_location *bl = bs->breakpoint_at;
2846 struct breakpoint *b = bl->owner;
2848 if (b->type == bp_watchpoint
2849 || b->type == bp_read_watchpoint
2850 || b->type == bp_access_watchpoint
2851 || b->type == bp_hardware_watchpoint)
2855 int must_check_value = 0;
2857 if (b->type == bp_watchpoint)
2858 /* For a software watchpoint, we must always check the
2860 must_check_value = 1;
2861 else if (b->watchpoint_triggered == watch_triggered_yes)
2862 /* We have a hardware watchpoint (read, write, or access)
2863 and the target earlier reported an address watched by
2865 must_check_value = 1;
2866 else if (b->watchpoint_triggered == watch_triggered_unknown
2867 && b->type == bp_hardware_watchpoint)
2868 /* We were stopped by a hardware watchpoint, but the target could
2869 not report the data address. We must check the watchpoint's
2870 value. Access and read watchpoints are out of luck; without
2871 a data address, we can't figure it out. */
2872 must_check_value = 1;
2874 if (must_check_value)
2876 char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n",
2878 struct cleanup *cleanups = make_cleanup (xfree, message);
2879 int e = catch_errors (watchpoint_check, bs, message,
2881 do_cleanups (cleanups);
2885 /* We've already printed what needs to be printed. */
2886 bs->print_it = print_it_done;
2889 case WP_VALUE_CHANGED:
2890 if (b->type == bp_read_watchpoint)
2892 /* Don't stop: read watchpoints shouldn't fire if
2893 the value has changed. This is for targets
2894 which cannot set read-only watchpoints. */
2895 bs->print_it = print_it_noop;
2899 case WP_VALUE_NOT_CHANGED:
2900 if (b->type == bp_hardware_watchpoint
2901 || b->type == bp_watchpoint)
2903 /* Don't stop: write watchpoints shouldn't fire if
2904 the value hasn't changed. */
2905 bs->print_it = print_it_noop;
2913 /* Error from catch_errors. */
2914 printf_filtered (_("Watchpoint %d deleted.\n"), b->number);
2915 if (b->related_breakpoint)
2916 b->related_breakpoint->disposition = disp_del_at_next_stop;
2917 b->disposition = disp_del_at_next_stop;
2918 /* We've already printed what needs to be printed. */
2919 bs->print_it = print_it_done;
2923 else /* must_check_value == 0 */
2925 /* This is a case where some watchpoint(s) triggered, but
2926 not at the address of this watchpoint, or else no
2927 watchpoint triggered after all. So don't print
2928 anything for this watchpoint. */
2929 bs->print_it = print_it_noop;
2936 /* Check conditions (condition proper, frame, thread and ignore count)
2937 of breakpoint referred to by BS. If we should not stop for this
2938 breakpoint, set BS->stop to 0. */
2940 bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
2942 int thread_id = pid_to_thread_id (ptid);
2943 const struct bp_location *bl = bs->breakpoint_at;
2944 struct breakpoint *b = bl->owner;
2946 if (frame_id_p (b->frame_id)
2947 && !frame_id_eq (b->frame_id, get_frame_id (get_current_frame ())))
2951 int value_is_zero = 0;
2953 /* If this is a scope breakpoint, mark the associated
2954 watchpoint as triggered so that we will handle the
2955 out-of-scope event. We'll get to the watchpoint next
2957 if (b->type == bp_watchpoint_scope)
2958 b->related_breakpoint->watchpoint_triggered = watch_triggered_yes;
2960 if (bl->cond && bl->owner->disposition != disp_del_at_next_stop)
2962 /* Need to select the frame, with all that implies
2963 so that the conditions will have the right context. */
2964 select_frame (get_current_frame ());
2966 = catch_errors (breakpoint_cond_eval, (bl->cond),
2967 "Error in testing breakpoint condition:\n",
2969 /* FIXME-someday, should give breakpoint # */
2972 if (bl->cond && value_is_zero)
2976 else if (b->thread != -1 && b->thread != thread_id)
2980 else if (b->ignore_count > 0)
2983 annotate_ignore_count_change ();
2985 /* Increase the hit count even though we don't
2993 /* Get a bpstat associated with having just stopped at address
2994 BP_ADDR in thread PTID.
2996 Determine whether we stopped at a breakpoint, etc, or whether we
2997 don't understand this stop. Result is a chain of bpstat's such that:
2999 if we don't understand the stop, the result is a null pointer.
3001 if we understand why we stopped, the result is not null.
3003 Each element of the chain refers to a particular breakpoint or
3004 watchpoint at which we have stopped. (We may have stopped for
3005 several reasons concurrently.)
3007 Each element of the chain has valid next, breakpoint_at,
3008 commands, FIXME??? fields. */
3011 bpstat_stop_status (CORE_ADDR bp_addr, ptid_t ptid)
3013 struct breakpoint *b = NULL;
3014 const struct bp_location *bl;
3015 /* Root of the chain of bpstat's */
3016 struct bpstats root_bs[1];
3017 /* Pointer to the last thing in the chain currently. */
3018 bpstat bs = root_bs;
3020 ALL_BP_LOCATIONS (bl)
3024 if (!breakpoint_enabled (b) && b->enable_state != bp_permanent)
3027 /* For hardware watchpoints, we look only at the first location.
3028 The watchpoint_check function will work on entire expression,
3029 not the individual locations. For read watchopints, the
3030 watchpoints_triggered function have checked all locations
3033 if (b->type == bp_hardware_watchpoint && bl != b->loc)
3036 if (!bpstat_check_location (bl, bp_addr))
3039 /* Come here if it's a watchpoint, or if the break address matches */
3041 bs = bpstat_alloc (bl, bs); /* Alloc a bpstat to explain stop */
3043 /* Assume we stop. Should we find watchpoint that is not actually
3044 triggered, or if condition of breakpoint is false, we'll reset
3049 bpstat_check_watchpoint (bs);
3053 if (b->type == bp_thread_event || b->type == bp_overlay_event)
3054 /* We do not stop for these. */
3057 bpstat_check_breakpoint_conditions (bs, ptid);
3063 /* We will stop here */
3064 if (b->disposition == disp_disable)
3066 b->enable_state = bp_disabled;
3067 update_global_location_list ();
3071 bs->commands = b->commands;
3073 (strcmp ("silent", bs->commands->line) == 0
3074 || (xdb_commands && strcmp ("Q", bs->commands->line) == 0)))
3076 bs->commands = bs->commands->next;
3079 bs->commands = copy_command_lines (bs->commands);
3082 /* Print nothing for this entry if we dont stop or if we dont print. */
3083 if (bs->stop == 0 || bs->print == 0)
3084 bs->print_it = print_it_noop;
3087 bs->next = NULL; /* Terminate the chain */
3088 bs = root_bs->next; /* Re-grab the head of the chain */
3090 /* If we aren't stopping, the value of some hardware watchpoint may
3091 not have changed, but the intermediate memory locations we are
3092 watching may have. Don't bother if we're stopping; this will get
3094 for (bs = root_bs->next; bs != NULL; bs = bs->next)
3099 for (bs = root_bs->next; bs != NULL; bs = bs->next)
3101 && (bs->breakpoint_at->owner->type == bp_hardware_watchpoint
3102 || bs->breakpoint_at->owner->type == bp_read_watchpoint
3103 || bs->breakpoint_at->owner->type == bp_access_watchpoint))
3105 /* remove/insert can invalidate bs->breakpoint_at, if this
3106 location is no longer used by the watchpoint. Prevent
3107 further code from trying to use it. */
3108 bs->breakpoint_at = NULL;
3109 remove_breakpoints ();
3110 insert_breakpoints ();
3114 return root_bs->next;
3117 /* Tell what to do about this bpstat. */
3119 bpstat_what (bpstat bs)
3121 /* Classify each bpstat as one of the following. */
3124 /* This bpstat element has no effect on the main_action. */
3127 /* There was a watchpoint, stop but don't print. */
3130 /* There was a watchpoint, stop and print. */
3133 /* There was a breakpoint but we're not stopping. */
3136 /* There was a breakpoint, stop but don't print. */
3139 /* There was a breakpoint, stop and print. */
3142 /* We hit the longjmp breakpoint. */
3145 /* We hit the longjmp_resume breakpoint. */
3148 /* We hit the step_resume breakpoint. */
3151 /* We hit the shared library event breakpoint. */
3154 /* We caught a shared library event. */
3157 /* This is just used to count how many enums there are. */
3161 /* Here is the table which drives this routine. So that we can
3162 format it pretty, we define some abbreviations for the
3163 enum bpstat_what codes. */
3164 #define kc BPSTAT_WHAT_KEEP_CHECKING
3165 #define ss BPSTAT_WHAT_STOP_SILENT
3166 #define sn BPSTAT_WHAT_STOP_NOISY
3167 #define sgl BPSTAT_WHAT_SINGLE
3168 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3169 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3170 #define sr BPSTAT_WHAT_STEP_RESUME
3171 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3172 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
3174 /* "Can't happen." Might want to print an error message.
3175 abort() is not out of the question, but chances are GDB is just
3176 a bit confused, not unusable. */
3177 #define err BPSTAT_WHAT_STOP_NOISY
3179 /* Given an old action and a class, come up with a new action. */
3180 /* One interesting property of this table is that wp_silent is the same
3181 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3182 after stopping, the check for whether to step over a breakpoint
3183 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3184 reference to how we stopped. We retain separate wp_silent and
3185 bp_silent codes in case we want to change that someday.
3187 Another possibly interesting property of this table is that
3188 there's a partial ordering, priority-like, of the actions. Once
3189 you've decided that some action is appropriate, you'll never go
3190 back and decide something of a lower priority is better. The
3193 kc < clr sgl shl shlr slr sn sr ss
3194 sgl < shl shlr slr sn sr ss
3195 slr < err shl shlr sn sr ss
3196 clr < err shl shlr sn sr ss
3203 What I think this means is that we don't need a damned table
3204 here. If you just put the rows and columns in the right order,
3205 it'd look awfully regular. We could simply walk the bpstat list
3206 and choose the highest priority action we find, with a little
3207 logic to handle the 'err' cases. */
3209 /* step_resume entries: a step resume breakpoint overrides another
3210 breakpoint of signal handling (see comment in wait_for_inferior
3211 at where we set the step_resume breakpoint). */
3213 static const enum bpstat_what_main_action
3214 table[(int) class_last][(int) BPSTAT_WHAT_LAST] =
3217 /* kc ss sn sgl slr clr sr shl shlr
3220 {kc, ss, sn, sgl, slr, clr, sr, shl, shlr},
3222 {ss, ss, sn, ss, ss, ss, sr, shl, shlr},
3224 {sn, sn, sn, sn, sn, sn, sr, shl, shlr},
3226 {sgl, ss, sn, sgl, slr, slr, sr, shl, shlr},
3228 {ss, ss, sn, ss, ss, ss, sr, shl, shlr},
3230 {sn, sn, sn, sn, sn, sn, sr, shl, shlr},
3232 {slr, ss, sn, slr, slr, err, sr, shl, shlr},
3234 {clr, ss, sn, err, err, err, sr, shl, shlr},
3236 {sr, sr, sr, sr, sr, sr, sr, sr, sr},
3238 {shl, shl, shl, shl, shl, shl, sr, shl, shlr},
3240 {shlr, shlr, shlr, shlr, shlr, shlr, sr, shlr, shlr}
3254 enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
3255 struct bpstat_what retval;
3257 retval.call_dummy = 0;
3258 for (; bs != NULL; bs = bs->next)
3260 enum class bs_class = no_effect;
3261 if (bs->breakpoint_at == NULL)
3262 /* I suspect this can happen if it was a momentary breakpoint
3263 which has since been deleted. */
3265 switch (bs->breakpoint_at->owner->type)
3271 case bp_hardware_breakpoint:
3277 bs_class = bp_noisy;
3279 bs_class = bp_silent;
3282 bs_class = bp_nostop;
3285 case bp_hardware_watchpoint:
3286 case bp_read_watchpoint:
3287 case bp_access_watchpoint:
3291 bs_class = wp_noisy;
3293 bs_class = wp_silent;
3296 /* There was a watchpoint, but we're not stopping.
3297 This requires no further action. */
3298 bs_class = no_effect;
3301 bs_class = long_jump;
3303 case bp_longjmp_resume:
3304 bs_class = long_resume;
3306 case bp_step_resume:
3309 bs_class = step_resume;
3312 /* It is for the wrong frame. */
3313 bs_class = bp_nostop;
3315 case bp_watchpoint_scope:
3316 bs_class = bp_nostop;
3318 case bp_shlib_event:
3319 bs_class = shlib_event;
3321 case bp_thread_event:
3322 case bp_overlay_event:
3323 bs_class = bp_nostop;
3326 case bp_catch_unload:
3327 /* Only if this catchpoint triggered should we cause the
3328 step-out-of-dld behaviour. Otherwise, we ignore this
3331 bs_class = catch_shlib_event;
3333 bs_class = no_effect;
3336 case bp_catch_vfork:
3341 bs_class = bp_noisy;
3343 bs_class = bp_silent;
3346 /* There was a catchpoint, but we're not stopping.
3347 This requires no further action. */
3348 bs_class = no_effect;
3351 /* Make sure the action is stop (silent or noisy),
3352 so infrun.c pops the dummy frame. */
3353 bs_class = bp_silent;
3354 retval.call_dummy = 1;
3357 current_action = table[(int) bs_class][(int) current_action];
3359 retval.main_action = current_action;
3363 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3364 without hardware support). This isn't related to a specific bpstat,
3365 just to things like whether watchpoints are set. */
3368 bpstat_should_step (void)
3370 struct breakpoint *b;
3372 if (breakpoint_enabled (b) && b->type == bp_watchpoint)
3379 /* Given a bpstat that records zero or more triggered eventpoints, this
3380 function returns another bpstat which contains only the catchpoints
3381 on that first list, if any. */
3383 bpstat_get_triggered_catchpoints (bpstat ep_list, bpstat *cp_list)
3385 struct bpstats root_bs[1];
3386 bpstat bs = root_bs;
3387 struct breakpoint *ep;
3390 bpstat_clear (cp_list);
3391 root_bs->next = NULL;
3393 for (; ep_list != NULL; ep_list = ep_list->next)
3395 /* Is this eventpoint a catchpoint? If not, ignore it. */
3396 ep = ep_list->breakpoint_at->owner;
3399 if ((ep->type != bp_catch_load) &&
3400 (ep->type != bp_catch_unload))
3401 /* pai: (temp) ADD fork/vfork here!! */
3404 /* Yes; add it to the list. */
3405 bs = bpstat_alloc (ep_list->breakpoint_at, bs);
3410 #if defined(SOLIB_ADD)
3411 /* Also, for each triggered catchpoint, tag it with the name of
3412 the library that caused this trigger. (We copy the name now,
3413 because it's only guaranteed to be available NOW, when the
3414 catchpoint triggers. Clients who may wish to know the name
3415 later must get it from the catchpoint itself.) */
3416 if (ep->triggered_dll_pathname != NULL)
3417 xfree (ep->triggered_dll_pathname);
3418 if (ep->type == bp_catch_load)
3419 dll_pathname = SOLIB_LOADED_LIBRARY_PATHNAME (
3420 PIDGET (inferior_ptid));
3422 dll_pathname = SOLIB_UNLOADED_LIBRARY_PATHNAME (
3423 PIDGET (inferior_ptid));
3425 dll_pathname = NULL;
3429 ep->triggered_dll_pathname = (char *)
3430 xmalloc (strlen (dll_pathname) + 1);
3431 strcpy (ep->triggered_dll_pathname, dll_pathname);
3434 ep->triggered_dll_pathname = NULL;
3440 static void print_breakpoint_location (struct breakpoint *b,
3441 struct bp_location *loc,
3443 struct ui_stream *stb)
3448 = find_pc_sect_function (loc->address, loc->section);
3451 ui_out_text (uiout, "in ");
3452 ui_out_field_string (uiout, "func",
3453 SYMBOL_PRINT_NAME (sym));
3454 ui_out_wrap_hint (uiout, wrap_indent);
3455 ui_out_text (uiout, " at ");
3457 ui_out_field_string (uiout, "file", b->source_file);
3458 ui_out_text (uiout, ":");
3460 if (ui_out_is_mi_like_p (uiout))
3462 struct symtab_and_line sal = find_pc_line (loc->address, 0);
3463 char *fullname = symtab_to_fullname (sal.symtab);
3466 ui_out_field_string (uiout, "fullname", fullname);
3469 ui_out_field_int (uiout, "line", b->line_number);
3473 ui_out_field_string (uiout, "pending", b->addr_string);
3477 print_address_symbolic (loc->address, stb->stream, demangle, "");
3478 ui_out_field_stream (uiout, "at", stb);
3482 /* Print B to gdb_stdout. */
3484 print_one_breakpoint_location (struct breakpoint *b,
3485 struct bp_location *loc,
3487 CORE_ADDR *last_addr)
3489 struct command_line *l;
3491 struct ep_type_description
3496 static struct ep_type_description bptypes[] =
3498 {bp_none, "?deleted?"},
3499 {bp_breakpoint, "breakpoint"},
3500 {bp_hardware_breakpoint, "hw breakpoint"},
3501 {bp_until, "until"},
3502 {bp_finish, "finish"},
3503 {bp_watchpoint, "watchpoint"},
3504 {bp_hardware_watchpoint, "hw watchpoint"},
3505 {bp_read_watchpoint, "read watchpoint"},
3506 {bp_access_watchpoint, "acc watchpoint"},
3507 {bp_longjmp, "longjmp"},
3508 {bp_longjmp_resume, "longjmp resume"},
3509 {bp_step_resume, "step resume"},
3510 {bp_watchpoint_scope, "watchpoint scope"},
3511 {bp_call_dummy, "call dummy"},
3512 {bp_shlib_event, "shlib events"},
3513 {bp_thread_event, "thread events"},
3514 {bp_overlay_event, "overlay events"},
3515 {bp_catch_load, "catch load"},
3516 {bp_catch_unload, "catch unload"},
3517 {bp_catch_fork, "catch fork"},
3518 {bp_catch_vfork, "catch vfork"},
3519 {bp_catch_exec, "catch exec"}
3522 static char bpenables[] = "nynny";
3523 char wrap_indent[80];
3524 struct ui_stream *stb = ui_out_stream_new (uiout);
3525 struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb);
3526 struct cleanup *bkpt_chain;
3528 int header_of_multiple = 0;
3529 int part_of_multiple = (loc != NULL);
3531 gdb_assert (!loc || loc_number != 0);
3532 /* See comment in print_one_breakpoint concerning
3533 treatment of breakpoints with single disabled
3537 && (b->loc->next != NULL || !b->loc->enabled)))
3538 header_of_multiple = 1;
3543 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
3547 if (part_of_multiple)
3550 formatted = xstrprintf ("%d.%d", b->number, loc_number);
3551 ui_out_field_string (uiout, "number", formatted);
3556 ui_out_field_int (uiout, "number", b->number);
3561 if (part_of_multiple)
3562 ui_out_field_skip (uiout, "type");
3565 if (((int) b->type >= (sizeof (bptypes) / sizeof (bptypes[0])))
3566 || ((int) b->type != bptypes[(int) b->type].type))
3567 internal_error (__FILE__, __LINE__,
3568 _("bptypes table does not describe type #%d."),
3570 ui_out_field_string (uiout, "type", bptypes[(int) b->type].description);
3575 if (part_of_multiple)
3576 ui_out_field_skip (uiout, "disp");
3578 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
3583 if (part_of_multiple)
3584 ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n");
3586 ui_out_field_fmt (uiout, "enabled", "%c",
3587 bpenables[(int) b->enable_state]);
3588 ui_out_spaces (uiout, 2);
3592 strcpy (wrap_indent, " ");
3595 if (gdbarch_addr_bit (current_gdbarch) <= 32)
3596 strcat (wrap_indent, " ");
3598 strcat (wrap_indent, " ");
3601 if (b->ops != NULL && b->ops->print_one != NULL)
3603 /* Although the print_one can possibly print
3604 all locations, calling it here is not likely
3605 to get any nice result. So, make sure there's
3606 just one location. */
3607 gdb_assert (b->loc == NULL || b->loc->next == NULL);
3608 b->ops->print_one (b, last_addr);
3614 internal_error (__FILE__, __LINE__,
3615 _("print_one_breakpoint: bp_none encountered\n"));
3619 case bp_hardware_watchpoint:
3620 case bp_read_watchpoint:
3621 case bp_access_watchpoint:
3622 /* Field 4, the address, is omitted (which makes the columns
3623 not line up too nicely with the headers, but the effect
3624 is relatively readable). */
3626 ui_out_field_skip (uiout, "addr");
3628 print_expression (b->exp, stb->stream);
3629 ui_out_field_stream (uiout, "what", stb);
3633 case bp_catch_unload:
3634 /* Field 4, the address, is omitted (which makes the columns
3635 not line up too nicely with the headers, but the effect
3636 is relatively readable). */
3638 ui_out_field_skip (uiout, "addr");
3640 if (b->dll_pathname == NULL)
3642 ui_out_field_string (uiout, "what", "<any library>");
3643 ui_out_spaces (uiout, 1);
3647 ui_out_text (uiout, "library \"");
3648 ui_out_field_string (uiout, "what", b->dll_pathname);
3649 ui_out_text (uiout, "\" ");
3654 case bp_catch_vfork:
3655 /* Field 4, the address, is omitted (which makes the columns
3656 not line up too nicely with the headers, but the effect
3657 is relatively readable). */
3659 ui_out_field_skip (uiout, "addr");
3661 if (b->forked_inferior_pid != 0)
3663 ui_out_text (uiout, "process ");
3664 ui_out_field_int (uiout, "what", b->forked_inferior_pid);
3665 ui_out_spaces (uiout, 1);
3670 /* Field 4, the address, is omitted (which makes the columns
3671 not line up too nicely with the headers, but the effect
3672 is relatively readable). */
3674 ui_out_field_skip (uiout, "addr");
3676 if (b->exec_pathname != NULL)
3678 ui_out_text (uiout, "program \"");
3679 ui_out_field_string (uiout, "what", b->exec_pathname);
3680 ui_out_text (uiout, "\" ");
3685 case bp_hardware_breakpoint:
3689 case bp_longjmp_resume:
3690 case bp_step_resume:
3691 case bp_watchpoint_scope:
3693 case bp_shlib_event:
3694 case bp_thread_event:
3695 case bp_overlay_event:
3699 if (header_of_multiple)
3700 ui_out_field_string (uiout, "addr", "<MULTIPLE>");
3701 else if (b->loc == NULL || loc->shlib_disabled)
3702 ui_out_field_string (uiout, "addr", "<PENDING>");
3704 ui_out_field_core_addr (uiout, "addr", loc->address);
3707 if (!header_of_multiple)
3708 print_breakpoint_location (b, loc, wrap_indent, stb);
3710 *last_addr = b->loc->address;
3714 if (!part_of_multiple && b->thread != -1)
3716 /* FIXME: This seems to be redundant and lost here; see the
3717 "stop only in" line a little further down. */
3718 ui_out_text (uiout, " thread ");
3719 ui_out_field_int (uiout, "thread", b->thread);
3722 ui_out_text (uiout, "\n");
3724 if (part_of_multiple && frame_id_p (b->frame_id))
3727 ui_out_text (uiout, "\tstop only in stack frame at ");
3728 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3730 ui_out_field_core_addr (uiout, "frame", b->frame_id.stack_addr);
3731 ui_out_text (uiout, "\n");
3734 if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b))
3736 /* We do not print the condition for Ada exception catchpoints
3737 because the condition is an internal implementation detail
3738 that we do not want to expose to the user. */
3740 ui_out_text (uiout, "\tstop only if ");
3741 ui_out_field_string (uiout, "cond", b->cond_string);
3742 ui_out_text (uiout, "\n");
3745 if (!part_of_multiple && b->thread != -1)
3747 /* FIXME should make an annotation for this */
3748 ui_out_text (uiout, "\tstop only in thread ");
3749 ui_out_field_int (uiout, "thread", b->thread);
3750 ui_out_text (uiout, "\n");
3753 if (!part_of_multiple && show_breakpoint_hit_counts && b->hit_count)
3755 /* FIXME should make an annotation for this */
3756 if (ep_is_catchpoint (b))
3757 ui_out_text (uiout, "\tcatchpoint");
3759 ui_out_text (uiout, "\tbreakpoint");
3760 ui_out_text (uiout, " already hit ");
3761 ui_out_field_int (uiout, "times", b->hit_count);
3762 if (b->hit_count == 1)
3763 ui_out_text (uiout, " time\n");
3765 ui_out_text (uiout, " times\n");
3768 /* Output the count also if it is zero, but only if this is
3769 mi. FIXME: Should have a better test for this. */
3770 if (ui_out_is_mi_like_p (uiout))
3771 if (!part_of_multiple && show_breakpoint_hit_counts && b->hit_count == 0)
3772 ui_out_field_int (uiout, "times", b->hit_count);
3774 if (!part_of_multiple && b->ignore_count)
3777 ui_out_text (uiout, "\tignore next ");
3778 ui_out_field_int (uiout, "ignore", b->ignore_count);
3779 ui_out_text (uiout, " hits\n");
3782 if (!part_of_multiple && (l = b->commands))
3784 struct cleanup *script_chain;
3787 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
3788 print_command_lines (uiout, l, 4);
3789 do_cleanups (script_chain);
3792 if (ui_out_is_mi_like_p (uiout) && !part_of_multiple)
3795 ui_out_field_string (uiout, "original-location", b->addr_string);
3796 else if (b->exp_string)
3797 ui_out_field_string (uiout, "original-location", b->exp_string);
3800 do_cleanups (bkpt_chain);
3801 do_cleanups (old_chain);
3805 print_one_breakpoint (struct breakpoint *b,
3806 CORE_ADDR *last_addr)
3808 print_one_breakpoint_location (b, NULL, 0, last_addr);
3810 /* If this breakpoint has custom print function,
3811 it's already printed. Otherwise, print individual
3812 locations, if any. */
3813 if (b->ops == NULL || b->ops->print_one == NULL)
3815 /* If breakpoint has a single location that is
3816 disabled, we print it as if it had
3817 several locations, since otherwise it's hard to
3818 represent "breakpoint enabled, location disabled"
3820 Note that while hardware watchpoints have
3821 several locations internally, that's no a property
3824 && !is_hardware_watchpoint (b)
3825 && (b->loc->next || !b->loc->enabled)
3826 && !ui_out_is_mi_like_p (uiout))
3828 struct bp_location *loc;
3830 for (loc = b->loc; loc; loc = loc->next, ++n)
3831 print_one_breakpoint_location (b, loc, n, last_addr);
3837 struct captured_breakpoint_query_args
3843 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
3845 struct captured_breakpoint_query_args *args = data;
3846 struct breakpoint *b;
3847 CORE_ADDR dummy_addr = 0;
3850 if (args->bnum == b->number)
3852 print_one_breakpoint (b, &dummy_addr);
3860 gdb_breakpoint_query (struct ui_out *uiout, int bnum, char **error_message)
3862 struct captured_breakpoint_query_args args;
3864 /* For the moment we don't trust print_one_breakpoint() to not throw
3866 if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args,
3867 error_message, RETURN_MASK_ALL) < 0)
3873 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3874 catchpoints, et.al.). */
3877 user_settable_breakpoint (const struct breakpoint *b)
3879 return (b->type == bp_breakpoint
3880 || b->type == bp_catch_load
3881 || b->type == bp_catch_unload
3882 || b->type == bp_catch_fork
3883 || b->type == bp_catch_vfork
3884 || b->type == bp_catch_exec
3885 || b->type == bp_hardware_breakpoint
3886 || b->type == bp_watchpoint
3887 || b->type == bp_read_watchpoint
3888 || b->type == bp_access_watchpoint
3889 || b->type == bp_hardware_watchpoint);
3892 /* Print information on user settable breakpoint (watchpoint, etc)
3893 number BNUM. If BNUM is -1 print all user settable breakpoints.
3894 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3897 breakpoint_1 (int bnum, int allflag)
3899 struct breakpoint *b;
3900 CORE_ADDR last_addr = (CORE_ADDR) -1;
3901 int nr_printable_breakpoints;
3902 struct cleanup *bkpttbl_chain;
3904 /* Compute the number of rows in the table. */
3905 nr_printable_breakpoints = 0;
3908 || bnum == b->number)
3910 if (allflag || user_settable_breakpoint (b))
3911 nr_printable_breakpoints++;
3916 = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints,
3920 = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints,
3923 if (nr_printable_breakpoints > 0)
3924 annotate_breakpoints_headers ();
3925 if (nr_printable_breakpoints > 0)
3927 ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */
3928 if (nr_printable_breakpoints > 0)
3930 ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */
3931 if (nr_printable_breakpoints > 0)
3933 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
3934 if (nr_printable_breakpoints > 0)
3936 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
3939 if (nr_printable_breakpoints > 0)
3941 if (gdbarch_addr_bit (current_gdbarch) <= 32)
3942 ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */
3944 ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */
3946 if (nr_printable_breakpoints > 0)
3948 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
3949 ui_out_table_body (uiout);
3950 if (nr_printable_breakpoints > 0)
3951 annotate_breakpoints_table ();
3955 || bnum == b->number)
3957 /* We only print out user settable breakpoints unless the
3959 if (allflag || user_settable_breakpoint (b))
3960 print_one_breakpoint (b, &last_addr);
3963 do_cleanups (bkpttbl_chain);
3965 if (nr_printable_breakpoints == 0)
3968 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
3970 ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n",
3975 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3976 that a comparison of an unsigned with -1 is always false. */
3977 if (last_addr != (CORE_ADDR) -1 && !server_command)
3978 set_next_address (last_addr);
3981 /* FIXME? Should this be moved up so that it is only called when
3982 there have been breakpoints? */
3983 annotate_breakpoints_table_end ();
3987 breakpoints_info (char *bnum_exp, int from_tty)
3992 bnum = parse_and_eval_long (bnum_exp);
3994 breakpoint_1 (bnum, 0);
3998 maintenance_info_breakpoints (char *bnum_exp, int from_tty)
4003 bnum = parse_and_eval_long (bnum_exp);
4005 breakpoint_1 (bnum, 1);
4009 breakpoint_has_pc (struct breakpoint *b, CORE_ADDR pc, asection *section)
4011 struct bp_location *bl = b->loc;
4012 for (; bl; bl = bl->next)
4014 if (bl->address == pc
4015 && (!overlay_debugging || bl->section == section))
4021 /* Print a message describing any breakpoints set at PC. */
4024 describe_other_breakpoints (CORE_ADDR pc, asection *section, int thread)
4027 struct breakpoint *b;
4030 others += breakpoint_has_pc (b, pc, section);
4034 printf_filtered (_("Note: breakpoint "));
4035 else /* if (others == ???) */
4036 printf_filtered (_("Note: breakpoints "));
4038 if (breakpoint_has_pc (b, pc, section))
4041 printf_filtered ("%d", b->number);
4042 if (b->thread == -1 && thread != -1)
4043 printf_filtered (" (all threads)");
4044 else if (b->thread != -1)
4045 printf_filtered (" (thread %d)", b->thread);
4046 printf_filtered ("%s%s ",
4047 ((b->enable_state == bp_disabled ||
4048 b->enable_state == bp_call_disabled)
4050 : b->enable_state == bp_permanent
4054 : ((others == 1) ? " and" : ""));
4056 printf_filtered (_("also set at pc "));
4057 fputs_filtered (paddress (pc), gdb_stdout);
4058 printf_filtered (".\n");
4062 /* Set the default place to put a breakpoint
4063 for the `break' command with no arguments. */
4066 set_default_breakpoint (int valid, CORE_ADDR addr, struct symtab *symtab,
4069 default_breakpoint_valid = valid;
4070 default_breakpoint_address = addr;
4071 default_breakpoint_symtab = symtab;
4072 default_breakpoint_line = line;
4075 /* Return true iff it is meaningful to use the address member of
4076 BPT. For some breakpoint types, the address member is irrelevant
4077 and it makes no sense to attempt to compare it to other addresses
4078 (or use it for any other purpose either).
4080 More specifically, each of the following breakpoint types will always
4081 have a zero valued address and we don't want check_duplicates() to mark
4082 breakpoints of any of these types to be a duplicate of an actual
4083 breakpoint at address zero:
4086 bp_hardware_watchpoint
4088 bp_access_watchpoint
4094 breakpoint_address_is_meaningful (struct breakpoint *bpt)
4096 enum bptype type = bpt->type;
4098 return (type != bp_watchpoint
4099 && type != bp_hardware_watchpoint
4100 && type != bp_read_watchpoint
4101 && type != bp_access_watchpoint
4102 && type != bp_catch_exec
4103 && type != bp_catch_fork
4104 && type != bp_catch_vfork);
4107 /* Rescan breakpoints at the same address and section as BPT,
4108 marking the first one as "first" and any others as "duplicates".
4109 This is so that the bpt instruction is only inserted once.
4110 If we have a permanent breakpoint at the same place as BPT, make
4111 that one the official one, and the rest as duplicates. */
4114 check_duplicates_for (CORE_ADDR address, asection *section)
4116 struct bp_location *b;
4118 struct bp_location *perm_bp = 0;
4120 ALL_BP_LOCATIONS (b)
4121 if (b->owner->enable_state != bp_disabled
4122 && b->owner->enable_state != bp_call_disabled
4124 && !b->shlib_disabled
4125 && b->address == address /* address / overlay match */
4126 && (!overlay_debugging || b->section == section)
4127 && breakpoint_address_is_meaningful (b->owner))
4129 /* Have we found a permanent breakpoint? */
4130 if (b->owner->enable_state == bp_permanent)
4137 b->duplicate = count > 1;
4140 /* If we found a permanent breakpoint at this address, go over the
4141 list again and declare all the other breakpoints there to be the
4145 perm_bp->duplicate = 0;
4147 /* Permanent breakpoint should always be inserted. */
4148 if (! perm_bp->inserted)
4149 internal_error (__FILE__, __LINE__,
4150 _("allegedly permanent breakpoint is not "
4151 "actually inserted"));
4153 ALL_BP_LOCATIONS (b)
4156 if (b->owner->enable_state != bp_disabled
4157 && b->owner->enable_state != bp_call_disabled
4158 && b->enabled && !b->shlib_disabled
4159 && b->address == address /* address / overlay match */
4160 && (!overlay_debugging || b->section == section)
4161 && breakpoint_address_is_meaningful (b->owner))
4164 internal_error (__FILE__, __LINE__,
4165 _("another breakpoint was inserted on top of "
4166 "a permanent breakpoint"));
4175 check_duplicates (struct breakpoint *bpt)
4177 struct bp_location *bl = bpt->loc;
4179 if (! breakpoint_address_is_meaningful (bpt))
4182 for (; bl; bl = bl->next)
4183 check_duplicates_for (bl->address, bl->section);
4187 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
4188 int bnum, int have_bnum)
4193 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
4194 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
4196 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4197 bnum, astr1, astr2);
4199 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
4202 /* Adjust a breakpoint's address to account for architectural constraints
4203 on breakpoint placement. Return the adjusted address. Note: Very
4204 few targets require this kind of adjustment. For most targets,
4205 this function is simply the identity function. */
4208 adjust_breakpoint_address (CORE_ADDR bpaddr, enum bptype bptype)
4210 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch))
4212 /* Very few targets need any kind of breakpoint adjustment. */
4215 else if (bptype == bp_watchpoint
4216 || bptype == bp_hardware_watchpoint
4217 || bptype == bp_read_watchpoint
4218 || bptype == bp_access_watchpoint
4219 || bptype == bp_catch_fork
4220 || bptype == bp_catch_vfork
4221 || bptype == bp_catch_exec)
4223 /* Watchpoints and the various bp_catch_* eventpoints should not
4224 have their addresses modified. */
4229 CORE_ADDR adjusted_bpaddr;
4231 /* Some targets have architectural constraints on the placement
4232 of breakpoint instructions. Obtain the adjusted address. */
4233 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (current_gdbarch,
4236 /* An adjusted breakpoint address can significantly alter
4237 a user's expectations. Print a warning if an adjustment
4239 if (adjusted_bpaddr != bpaddr)
4240 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
4242 return adjusted_bpaddr;
4246 /* Allocate a struct bp_location. */
4248 static struct bp_location *
4249 allocate_bp_location (struct breakpoint *bpt, enum bptype bp_type)
4251 struct bp_location *loc, *loc_p;
4253 loc = xmalloc (sizeof (struct bp_location));
4254 memset (loc, 0, sizeof (*loc));
4258 loc->shlib_disabled = 0;
4267 case bp_longjmp_resume:
4268 case bp_step_resume:
4269 case bp_watchpoint_scope:
4271 case bp_shlib_event:
4272 case bp_thread_event:
4273 case bp_overlay_event:
4275 case bp_catch_unload:
4276 loc->loc_type = bp_loc_software_breakpoint;
4278 case bp_hardware_breakpoint:
4279 loc->loc_type = bp_loc_hardware_breakpoint;
4281 case bp_hardware_watchpoint:
4282 case bp_read_watchpoint:
4283 case bp_access_watchpoint:
4284 loc->loc_type = bp_loc_hardware_watchpoint;
4288 case bp_catch_vfork:
4290 loc->loc_type = bp_loc_other;
4293 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
4299 static void free_bp_location (struct bp_location *loc)
4304 if (loc->function_name)
4305 xfree (loc->function_name);
4310 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4311 that has type BPTYPE and has no locations as yet. */
4313 static struct breakpoint *
4314 set_raw_breakpoint_without_location (enum bptype bptype)
4316 struct breakpoint *b, *b1;
4318 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
4319 memset (b, 0, sizeof (*b));
4322 b->language = current_language->la_language;
4323 b->input_radix = input_radix;
4325 b->enable_state = bp_enabled;
4328 b->ignore_count = 0;
4330 b->frame_id = null_frame_id;
4331 b->dll_pathname = NULL;
4332 b->triggered_dll_pathname = NULL;
4333 b->forked_inferior_pid = 0;
4334 b->exec_pathname = NULL;
4336 b->condition_not_parsed = 0;
4338 /* Add this breakpoint to the end of the chain
4339 so that a list of breakpoints will come out in order
4340 of increasing numbers. */
4342 b1 = breakpoint_chain;
4344 breakpoint_chain = b;
4354 /* Initialize loc->function_name. */
4356 set_breakpoint_location_function (struct bp_location *loc)
4358 if (loc->owner->type == bp_breakpoint
4359 || loc->owner->type == bp_hardware_breakpoint)
4361 find_pc_partial_function (loc->address, &(loc->function_name),
4363 if (loc->function_name)
4364 loc->function_name = xstrdup (loc->function_name);
4368 /* set_raw_breakpoint is a low level routine for allocating and
4369 partially initializing a breakpoint of type BPTYPE. The newly
4370 created breakpoint's address, section, source file name, and line
4371 number are provided by SAL. The newly created and partially
4372 initialized breakpoint is added to the breakpoint chain and
4373 is also returned as the value of this function.
4375 It is expected that the caller will complete the initialization of
4376 the newly created breakpoint struct as well as output any status
4377 information regarding the creation of a new breakpoint. In
4378 particular, set_raw_breakpoint does NOT set the breakpoint
4379 number! Care should be taken to not allow an error to occur
4380 prior to completing the initialization of the breakpoint. If this
4381 should happen, a bogus breakpoint will be left on the chain. */
4384 set_raw_breakpoint (struct symtab_and_line sal, enum bptype bptype)
4386 struct breakpoint *b = set_raw_breakpoint_without_location (bptype);
4387 CORE_ADDR adjusted_address;
4389 /* Adjust the breakpoint's address prior to allocating a location.
4390 Once we call allocate_bp_location(), that mostly uninitialized
4391 location will be placed on the location chain. Adjustment of the
4392 breakpoint may cause target_read_memory() to be called and we do
4393 not want its scan of the location chain to find a breakpoint and
4394 location that's only been partially initialized. */
4395 adjusted_address = adjust_breakpoint_address (sal.pc, bptype);
4397 b->loc = allocate_bp_location (b, bptype);
4398 b->loc->requested_address = sal.pc;
4399 b->loc->address = adjusted_address;
4401 if (sal.symtab == NULL)
4402 b->source_file = NULL;
4404 b->source_file = savestring (sal.symtab->filename,
4405 strlen (sal.symtab->filename));
4406 b->loc->section = sal.section;
4407 b->line_number = sal.line;
4409 set_breakpoint_location_function (b->loc);
4411 breakpoints_changed ();
4417 /* Note that the breakpoint object B describes a permanent breakpoint
4418 instruction, hard-wired into the inferior's code. */
4420 make_breakpoint_permanent (struct breakpoint *b)
4422 struct bp_location *bl;
4423 b->enable_state = bp_permanent;
4425 /* By definition, permanent breakpoints are already present in the code.
4426 Mark all locations as inserted. For now, make_breakpoint_permanent
4427 is called in just one place, so it's hard to say if it's reasonable
4428 to have permanent breakpoint with multiple locations or not,
4429 but it's easy to implmement. */
4430 for (bl = b->loc; bl; bl = bl->next)
4434 static struct breakpoint *
4435 create_internal_breakpoint (CORE_ADDR address, enum bptype type)
4437 static int internal_breakpoint_number = -1;
4438 struct symtab_and_line sal;
4439 struct breakpoint *b;
4441 init_sal (&sal); /* initialize to zeroes */
4444 sal.section = find_pc_overlay (sal.pc);
4446 b = set_raw_breakpoint (sal, type);
4447 b->number = internal_breakpoint_number--;
4448 b->disposition = disp_donttouch;
4455 create_longjmp_breakpoint (char *func_name)
4457 struct breakpoint *b;
4458 struct minimal_symbol *m;
4460 if ((m = lookup_minimal_symbol_text (func_name, NULL)) == NULL)
4462 set_momentary_breakpoint_at_pc (SYMBOL_VALUE_ADDRESS (m), bp_longjmp);
4463 update_global_location_list ();
4466 /* Call this routine when stepping and nexting to enable a breakpoint
4467 if we do a longjmp(). When we hit that breakpoint, call
4468 set_longjmp_resume_breakpoint() to figure out where we are going. */
4471 set_longjmp_breakpoint (void)
4473 struct breakpoint *b;
4475 if (gdbarch_get_longjmp_target_p (current_gdbarch))
4477 create_longjmp_breakpoint ("longjmp");
4478 create_longjmp_breakpoint ("_longjmp");
4479 create_longjmp_breakpoint ("siglongjmp");
4480 create_longjmp_breakpoint ("_siglongjmp");
4484 /* Delete all longjmp breakpoints from THREAD. */
4486 delete_longjmp_breakpoint (int thread)
4488 struct breakpoint *b, *temp;
4490 ALL_BREAKPOINTS_SAFE (b, temp)
4491 if (b->type == bp_longjmp)
4493 if (b->thread == thread)
4494 delete_breakpoint (b);
4499 create_overlay_event_breakpoint (char *func_name)
4501 struct breakpoint *b;
4502 struct minimal_symbol *m;
4504 if ((m = lookup_minimal_symbol_text (func_name, NULL)) == NULL)
4507 b = create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m),
4509 b->addr_string = xstrdup (func_name);
4511 if (overlay_debugging == ovly_auto)
4513 b->enable_state = bp_enabled;
4514 overlay_events_enabled = 1;
4518 b->enable_state = bp_disabled;
4519 overlay_events_enabled = 0;
4521 update_global_location_list ();
4525 enable_overlay_breakpoints (void)
4527 struct breakpoint *b;
4530 if (b->type == bp_overlay_event)
4532 b->enable_state = bp_enabled;
4533 update_global_location_list ();
4534 overlay_events_enabled = 1;
4539 disable_overlay_breakpoints (void)
4541 struct breakpoint *b;
4544 if (b->type == bp_overlay_event)
4546 b->enable_state = bp_disabled;
4547 update_global_location_list ();
4548 overlay_events_enabled = 0;
4553 create_thread_event_breakpoint (CORE_ADDR address)
4555 struct breakpoint *b;
4557 b = create_internal_breakpoint (address, bp_thread_event);
4559 b->enable_state = bp_enabled;
4560 /* addr_string has to be used or breakpoint_re_set will delete me. */
4561 b->addr_string = xstrprintf ("*0x%s", paddr (b->loc->address));
4563 update_global_location_list_nothrow ();
4569 remove_thread_event_breakpoints (void)
4571 struct breakpoint *b, *temp;
4573 ALL_BREAKPOINTS_SAFE (b, temp)
4574 if (b->type == bp_thread_event)
4575 delete_breakpoint (b);
4578 struct captured_parse_breakpoint_args
4581 struct symtabs_and_lines *sals_p;
4582 char ***addr_string_p;
4586 struct lang_and_radix
4594 remove_solib_event_breakpoints (void)
4596 struct breakpoint *b, *temp;
4598 ALL_BREAKPOINTS_SAFE (b, temp)
4599 if (b->type == bp_shlib_event)
4600 delete_breakpoint (b);
4604 create_solib_event_breakpoint (CORE_ADDR address)
4606 struct breakpoint *b;
4608 b = create_internal_breakpoint (address, bp_shlib_event);
4609 update_global_location_list_nothrow ();
4613 /* Disable any breakpoints that are on code in shared libraries. Only
4614 apply to enabled breakpoints, disabled ones can just stay disabled. */
4617 disable_breakpoints_in_shlibs (void)
4619 struct bp_location *loc;
4620 int disabled_shlib_breaks = 0;
4622 ALL_BP_LOCATIONS (loc)
4624 struct breakpoint *b = loc->owner;
4625 /* We apply the check to all breakpoints, including disabled
4626 for those with loc->duplicate set. This is so that when breakpoint
4627 becomes enabled, or the duplicate is removed, gdb will try to insert
4628 all breakpoints. If we don't set shlib_disabled here, we'll try
4629 to insert those breakpoints and fail. */
4630 if (((b->type == bp_breakpoint) || (b->type == bp_hardware_breakpoint))
4631 && !loc->shlib_disabled
4633 && PC_SOLIB (loc->address)
4635 && solib_address (loc->address)
4639 loc->shlib_disabled = 1;
4644 /* Disable any breakpoints that are in in an unloaded shared library. Only
4645 apply to enabled breakpoints, disabled ones can just stay disabled. */
4648 disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
4650 struct bp_location *loc;
4651 int disabled_shlib_breaks = 0;
4653 ALL_BP_LOCATIONS (loc)
4655 struct breakpoint *b = loc->owner;
4656 if ((loc->loc_type == bp_loc_hardware_breakpoint
4657 || loc->loc_type == bp_loc_software_breakpoint)
4658 && !loc->shlib_disabled)
4661 char *so_name = PC_SOLIB (loc->address);
4663 char *so_name = solib_address (loc->address);
4665 if (so_name && !strcmp (so_name, solib->so_name))
4667 loc->shlib_disabled = 1;
4668 /* At this point, we cannot rely on remove_breakpoint
4669 succeeding so we must mark the breakpoint as not inserted
4670 to prevent future errors occurring in remove_breakpoints. */
4672 if (!disabled_shlib_breaks)
4674 target_terminal_ours_for_output ();
4675 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4678 disabled_shlib_breaks = 1;
4685 create_fork_vfork_event_catchpoint (int tempflag, char *cond_string,
4686 enum bptype bp_kind)
4688 struct symtab_and_line sal;
4689 struct breakpoint *b;
4690 int thread = -1; /* All threads. */
4697 b = set_raw_breakpoint (sal, bp_kind);
4698 set_breakpoint_count (breakpoint_count + 1);
4699 b->number = breakpoint_count;
4700 b->cond_string = (cond_string == NULL) ?
4701 NULL : savestring (cond_string, strlen (cond_string));
4703 b->addr_string = NULL;
4704 b->enable_state = bp_enabled;
4705 b->disposition = tempflag ? disp_del : disp_donttouch;
4706 b->forked_inferior_pid = 0;
4707 update_global_location_list ();
4714 create_fork_event_catchpoint (int tempflag, char *cond_string)
4716 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_fork);
4720 create_vfork_event_catchpoint (int tempflag, char *cond_string)
4722 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_vfork);
4726 create_exec_event_catchpoint (int tempflag, char *cond_string)
4728 struct symtab_and_line sal;
4729 struct breakpoint *b;
4730 int thread = -1; /* All threads. */
4737 b = set_raw_breakpoint (sal, bp_catch_exec);
4738 set_breakpoint_count (breakpoint_count + 1);
4739 b->number = breakpoint_count;
4740 b->cond_string = (cond_string == NULL) ?
4741 NULL : savestring (cond_string, strlen (cond_string));
4743 b->addr_string = NULL;
4744 b->enable_state = bp_enabled;
4745 b->disposition = tempflag ? disp_del : disp_donttouch;
4746 update_global_location_list ();
4752 hw_breakpoint_used_count (void)
4754 struct breakpoint *b;
4759 if (b->type == bp_hardware_breakpoint && b->enable_state == bp_enabled)
4767 hw_watchpoint_used_count (enum bptype type, int *other_type_used)
4769 struct breakpoint *b;
4772 *other_type_used = 0;
4775 if (breakpoint_enabled (b))
4777 if (b->type == type)
4779 else if ((b->type == bp_hardware_watchpoint ||
4780 b->type == bp_read_watchpoint ||
4781 b->type == bp_access_watchpoint))
4782 *other_type_used = 1;
4789 disable_watchpoints_before_interactive_call_start (void)
4791 struct breakpoint *b;
4795 if (((b->type == bp_watchpoint)
4796 || (b->type == bp_hardware_watchpoint)
4797 || (b->type == bp_read_watchpoint)
4798 || (b->type == bp_access_watchpoint))
4799 && breakpoint_enabled (b))
4801 b->enable_state = bp_call_disabled;
4802 update_global_location_list ();
4808 enable_watchpoints_after_interactive_call_stop (void)
4810 struct breakpoint *b;
4814 if (((b->type == bp_watchpoint)
4815 || (b->type == bp_hardware_watchpoint)
4816 || (b->type == bp_read_watchpoint)
4817 || (b->type == bp_access_watchpoint))
4818 && (b->enable_state == bp_call_disabled))
4820 b->enable_state = bp_enabled;
4821 update_global_location_list ();
4827 /* Set a breakpoint that will evaporate an end of command
4828 at address specified by SAL.
4829 Restrict it to frame FRAME if FRAME is nonzero. */
4832 set_momentary_breakpoint (struct symtab_and_line sal, struct frame_id frame_id,
4835 struct breakpoint *b;
4836 b = set_raw_breakpoint (sal, type);
4837 b->enable_state = bp_enabled;
4838 b->disposition = disp_donttouch;
4839 b->frame_id = frame_id;
4841 /* If we're debugging a multi-threaded program, then we
4842 want momentary breakpoints to be active in only a
4843 single thread of control. */
4844 if (in_thread_list (inferior_ptid))
4845 b->thread = pid_to_thread_id (inferior_ptid);
4847 update_global_location_list_nothrow ();
4853 set_momentary_breakpoint_at_pc (CORE_ADDR pc, enum bptype type)
4855 struct symtab_and_line sal;
4857 sal = find_pc_line (pc, 0);
4859 sal.section = find_pc_overlay (pc);
4860 sal.explicit_pc = 1;
4862 return set_momentary_breakpoint (sal, null_frame_id, type);
4866 /* Tell the user we have just set a breakpoint B. */
4869 mention (struct breakpoint *b)
4872 struct cleanup *old_chain, *ui_out_chain;
4873 struct ui_stream *stb;
4875 stb = ui_out_stream_new (uiout);
4876 old_chain = make_cleanup_ui_out_stream_delete (stb);
4878 /* FIXME: This is misplaced; mention() is called by things (like
4879 hitting a watchpoint) other than breakpoint creation. It should
4880 be possible to clean this up and at the same time replace the
4881 random calls to breakpoint_changed with this hook, as has already
4882 been done for deprecated_delete_breakpoint_hook and so on. */
4883 if (deprecated_create_breakpoint_hook)
4884 deprecated_create_breakpoint_hook (b);
4885 breakpoint_create_event (b->number);
4887 if (b->ops != NULL && b->ops->print_mention != NULL)
4888 b->ops->print_mention (b);
4893 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b->number);
4896 ui_out_text (uiout, "Watchpoint ");
4897 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
4898 ui_out_field_int (uiout, "number", b->number);
4899 ui_out_text (uiout, ": ");
4900 print_expression (b->exp, stb->stream);
4901 ui_out_field_stream (uiout, "exp", stb);
4902 do_cleanups (ui_out_chain);
4904 case bp_hardware_watchpoint:
4905 ui_out_text (uiout, "Hardware watchpoint ");
4906 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
4907 ui_out_field_int (uiout, "number", b->number);
4908 ui_out_text (uiout, ": ");
4909 print_expression (b->exp, stb->stream);
4910 ui_out_field_stream (uiout, "exp", stb);
4911 do_cleanups (ui_out_chain);
4913 case bp_read_watchpoint:
4914 ui_out_text (uiout, "Hardware read watchpoint ");
4915 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
4916 ui_out_field_int (uiout, "number", b->number);
4917 ui_out_text (uiout, ": ");
4918 print_expression (b->exp, stb->stream);
4919 ui_out_field_stream (uiout, "exp", stb);
4920 do_cleanups (ui_out_chain);
4922 case bp_access_watchpoint:
4923 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
4924 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
4925 ui_out_field_int (uiout, "number", b->number);
4926 ui_out_text (uiout, ": ");
4927 print_expression (b->exp, stb->stream);
4928 ui_out_field_stream (uiout, "exp", stb);
4929 do_cleanups (ui_out_chain);
4932 if (ui_out_is_mi_like_p (uiout))
4937 if (b->disposition == disp_del)
4938 printf_filtered (_("Temporary breakpoint"));
4940 printf_filtered (_("Breakpoint"));
4941 printf_filtered (_(" %d"), b->number);
4944 case bp_hardware_breakpoint:
4945 if (ui_out_is_mi_like_p (uiout))
4950 printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
4954 case bp_catch_unload:
4955 printf_filtered (_("Catchpoint %d (%s %s)"),
4957 (b->type == bp_catch_load) ? "load" : "unload",
4958 (b->dll_pathname != NULL) ?
4959 b->dll_pathname : "<any library>");
4962 case bp_catch_vfork:
4963 printf_filtered (_("Catchpoint %d (%s)"),
4965 (b->type == bp_catch_fork) ? "fork" : "vfork");
4968 printf_filtered (_("Catchpoint %d (exec)"),
4975 case bp_longjmp_resume:
4976 case bp_step_resume:
4978 case bp_watchpoint_scope:
4979 case bp_shlib_event:
4980 case bp_thread_event:
4981 case bp_overlay_event:
4987 /* i18n: cagney/2005-02-11: Below needs to be merged into a
4991 printf_filtered (_(" (%s) pending."), b->addr_string);
4995 if (addressprint || b->source_file == NULL)
4997 printf_filtered (" at ");
4998 fputs_filtered (paddress (b->loc->address), gdb_stdout);
5001 printf_filtered (": file %s, line %d.",
5002 b->source_file, b->line_number);
5006 struct bp_location *loc = b->loc;
5008 for (; loc; loc = loc->next)
5010 printf_filtered (" (%d locations)", n);
5015 do_cleanups (old_chain);
5016 if (ui_out_is_mi_like_p (uiout))
5018 printf_filtered ("\n");
5022 static struct bp_location *
5023 add_location_to_breakpoint (struct breakpoint *b, enum bptype bptype,
5024 const struct symtab_and_line *sal)
5026 struct bp_location *loc, **tmp;
5028 loc = allocate_bp_location (b, bptype);
5029 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
5032 loc->requested_address = sal->pc;
5033 loc->address = adjust_breakpoint_address (loc->requested_address,
5035 loc->section = sal->section;
5037 set_breakpoint_location_function (loc);
5041 /* Create a breakpoint with SAL as location. Use ADDR_STRING
5042 as textual description of the location, and COND_STRING
5043 as condition expression. */
5046 create_breakpoint (struct symtabs_and_lines sals, char *addr_string,
5048 enum bptype type, enum bpdisp disposition,
5049 int thread, int ignore_count,
5050 struct breakpoint_ops *ops, int from_tty)
5052 struct breakpoint *b = NULL;
5055 if (type == bp_hardware_breakpoint)
5057 int i = hw_breakpoint_used_count ();
5058 int target_resources_ok =
5059 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
5061 if (target_resources_ok == 0)
5062 error (_("No hardware breakpoint support in the target."));
5063 else if (target_resources_ok < 0)
5064 error (_("Hardware breakpoints used exceeds limit."));
5067 for (i = 0; i < sals.nelts; ++i)
5069 struct symtab_and_line sal = sals.sals[i];
5070 struct bp_location *loc;
5073 describe_other_breakpoints (sal.pc, sal.section, thread);
5077 b = set_raw_breakpoint (sal, type);
5078 set_breakpoint_count (breakpoint_count + 1);
5079 b->number = breakpoint_count;
5082 b->cond_string = cond_string;
5083 b->ignore_count = ignore_count;
5084 b->enable_state = bp_enabled;
5085 b->disposition = disposition;
5091 loc = add_location_to_breakpoint (b, type, &sal);
5096 char *arg = b->cond_string;
5097 loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0);
5099 error (_("Garbage %s follows condition"), arg);
5104 b->addr_string = addr_string;
5106 /* addr_string has to be used or breakpoint_re_set will delete
5108 b->addr_string = xstrprintf ("*0x%s", paddr (b->loc->address));
5114 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
5115 elements to fill the void space. */
5116 static void remove_sal (struct symtabs_and_lines *sal, int index_to_remove)
5118 int i = index_to_remove+1;
5119 int last_index = sal->nelts-1;
5121 for (;i <= last_index; ++i)
5122 sal->sals[i-1] = sal->sals[i];
5127 /* If appropriate, obtains all sals that correspond
5128 to the same file and line as SAL. This is done
5129 only if SAL does not have explicit PC and has
5130 line and file information. If we got just a single
5131 expanded sal, return the original.
5133 Otherwise, if SAL.explicit_line is not set, filter out
5134 all sals for which the name of enclosing function
5135 is different from SAL. This makes sure that if we have
5136 breakpoint originally set in template instantiation, say
5137 foo<int>(), we won't expand SAL to locations at the same
5138 line in all existing instantiations of 'foo'.
5141 struct symtabs_and_lines
5142 expand_line_sal_maybe (struct symtab_and_line sal)
5144 struct symtabs_and_lines expanded;
5145 CORE_ADDR original_pc = sal.pc;
5146 char *original_function = NULL;
5150 /* If we have explicit pc, don't expand.
5151 If we have no line number, we can't expand. */
5152 if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL)
5155 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
5156 expanded.sals[0] = sal;
5161 find_pc_partial_function (original_pc, &original_function, NULL, NULL);
5163 expanded = expand_line_sal (sal);
5164 if (expanded.nelts == 1)
5166 /* We had one sal, we got one sal. Without futher
5167 processing, just return the original sal. */
5168 xfree (expanded.sals);
5170 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
5171 sal.pc = original_pc;
5172 expanded.sals[0] = sal;
5176 if (!sal.explicit_line)
5178 CORE_ADDR func_addr, func_end;
5179 for (i = 0; i < expanded.nelts; ++i)
5181 CORE_ADDR pc = expanded.sals[i].pc;
5182 char *this_function;
5183 if (find_pc_partial_function (pc, &this_function,
5184 &func_addr, &func_end))
5186 if (this_function &&
5187 strcmp (this_function, original_function) != 0)
5189 remove_sal (&expanded, i);
5192 else if (func_addr == pc)
5194 /* We're at beginning of a function, and should
5196 struct symbol *sym = find_pc_function (pc);
5198 expanded.sals[i] = find_function_start_sal (sym, 1);
5201 = gdbarch_skip_prologue (current_gdbarch, pc);
5208 if (expanded.nelts <= 1)
5210 /* This is un ugly workaround. If we get zero
5211 expanded sals then something is really wrong.
5212 Fix that by returnign the original sal. */
5213 xfree (expanded.sals);
5215 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
5216 sal.pc = original_pc;
5217 expanded.sals[0] = sal;
5224 for (i = 0; i < expanded.nelts; ++i)
5225 if (expanded.sals[i].pc == original_pc)
5236 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5237 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5238 value. COND_STRING, if not NULL, specified the condition to be
5239 used for all breakpoints. Essentially the only case where
5240 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
5241 function. In that case, it's still not possible to specify
5242 separate conditions for different overloaded functions, so
5243 we take just a single condition string.
5245 NOTE: If the function succeeds, the caller is expected to cleanup
5246 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
5247 array contents). If the function fails (error() is called), the
5248 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5249 COND and SALS arrays and each of those arrays contents. */
5252 create_breakpoints (struct symtabs_and_lines sals, char **addr_string,
5254 enum bptype type, enum bpdisp disposition,
5255 int thread, int ignore_count,
5256 struct breakpoint_ops *ops, int from_tty)
5259 for (i = 0; i < sals.nelts; ++i)
5261 struct symtabs_and_lines expanded =
5262 expand_line_sal_maybe (sals.sals[i]);
5264 create_breakpoint (expanded, addr_string[i],
5265 cond_string, type, disposition,
5266 thread, ignore_count, ops, from_tty);
5269 update_global_location_list ();
5272 /* Parse ARG which is assumed to be a SAL specification possibly
5273 followed by conditionals. On return, SALS contains an array of SAL
5274 addresses found. ADDR_STRING contains a vector of (canonical)
5275 address strings. ARG points to the end of the SAL. */
5278 parse_breakpoint_sals (char **address,
5279 struct symtabs_and_lines *sals,
5280 char ***addr_string,
5283 char *addr_start = *address;
5284 *addr_string = NULL;
5285 /* If no arg given, or if first arg is 'if ', use the default
5287 if ((*address) == NULL
5288 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
5290 if (default_breakpoint_valid)
5292 struct symtab_and_line sal;
5293 init_sal (&sal); /* initialize to zeroes */
5294 sals->sals = (struct symtab_and_line *)
5295 xmalloc (sizeof (struct symtab_and_line));
5296 sal.pc = default_breakpoint_address;
5297 sal.line = default_breakpoint_line;
5298 sal.symtab = default_breakpoint_symtab;
5299 sal.section = find_pc_overlay (sal.pc);
5300 sals->sals[0] = sal;
5304 error (_("No default breakpoint address now."));
5308 /* Force almost all breakpoints to be in terms of the
5309 current_source_symtab (which is decode_line_1's default). This
5310 should produce the results we want almost all of the time while
5311 leaving default_breakpoint_* alone.
5312 ObjC: However, don't match an Objective-C method name which
5313 may have a '+' or '-' succeeded by a '[' */
5315 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
5317 if (default_breakpoint_valid
5319 || ((strchr ("+-", (*address)[0]) != NULL)
5320 && ((*address)[1] != '['))))
5321 *sals = decode_line_1 (address, 1, default_breakpoint_symtab,
5322 default_breakpoint_line, addr_string,
5325 *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0,
5326 addr_string, not_found_ptr);
5328 /* For any SAL that didn't have a canonical string, fill one in. */
5329 if (sals->nelts > 0 && *addr_string == NULL)
5330 *addr_string = xcalloc (sals->nelts, sizeof (char **));
5331 if (addr_start != (*address))
5334 for (i = 0; i < sals->nelts; i++)
5336 /* Add the string if not present. */
5337 if ((*addr_string)[i] == NULL)
5338 (*addr_string)[i] = savestring (addr_start, (*address) - addr_start);
5344 /* Convert each SAL into a real PC. Verify that the PC can be
5345 inserted as a breakpoint. If it can't throw an error. */
5348 breakpoint_sals_to_pc (struct symtabs_and_lines *sals,
5352 for (i = 0; i < sals->nelts; i++)
5353 resolve_sal_pc (&sals->sals[i]);
5357 do_captured_parse_breakpoint (struct ui_out *ui, void *data)
5359 struct captured_parse_breakpoint_args *args = data;
5361 parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p,
5362 args->not_found_ptr);
5365 /* Given TOK, a string specification of condition and thread, as
5366 accepted by the 'break' command, extract the condition
5367 string and thread number and set *COND_STRING and *THREAD.
5368 PC identifies the context at which the condition should be parsed.
5369 If no condition is found, *COND_STRING is set to NULL.
5370 If no thread is found, *THREAD is set to -1. */
5372 find_condition_and_thread (char *tok, CORE_ADDR pc,
5373 char **cond_string, int *thread)
5375 *cond_string = NULL;
5381 char *cond_start = NULL;
5382 char *cond_end = NULL;
5383 while (*tok == ' ' || *tok == '\t')
5388 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
5391 toklen = end_tok - tok;
5393 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
5395 tok = cond_start = end_tok + 1;
5396 parse_exp_1 (&tok, block_for_pc (pc), 0);
5398 *cond_string = savestring (cond_start,
5399 cond_end - cond_start);
5401 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
5407 *thread = strtol (tok, &tok, 0);
5409 error (_("Junk after thread keyword."));
5410 if (!valid_thread_id (*thread))
5411 error (_("Unknown thread %d."), *thread);
5414 error (_("Junk at end of arguments."));
5418 /* Set a breakpoint. This function is shared between
5419 CLI and MI functions for setting a breakpoint.
5420 This function has two major modes of operations,
5421 selected by the PARSE_CONDITION_AND_THREAD parameter.
5422 If non-zero, the function will parse arg, extracting
5423 breakpoint location, address and thread. Otherwise,
5424 ARG is just the location of breakpoint, with condition
5425 and thread specified by the COND_STRING and THREAD
5429 break_command_really (char *arg, char *cond_string, int thread,
5430 int parse_condition_and_thread,
5431 int tempflag, int hardwareflag,
5433 enum auto_boolean pending_break_support,
5434 struct breakpoint_ops *ops,
5437 struct gdb_exception e;
5438 struct symtabs_and_lines sals;
5439 struct symtab_and_line pending_sal;
5442 char *addr_start = arg;
5444 struct cleanup *old_chain;
5445 struct cleanup *breakpoint_chain = NULL;
5446 struct captured_parse_breakpoint_args parse_args;
5455 parse_args.arg_p = &arg;
5456 parse_args.sals_p = &sals;
5457 parse_args.addr_string_p = &addr_string;
5458 parse_args.not_found_ptr = ¬_found;
5460 e = catch_exception (uiout, do_captured_parse_breakpoint,
5461 &parse_args, RETURN_MASK_ALL);
5463 /* If caller is interested in rc value from parse, set value. */
5467 throw_exception (e);
5471 case NOT_FOUND_ERROR:
5473 /* If pending breakpoint support is turned off, throw
5476 if (pending_break_support == AUTO_BOOLEAN_FALSE)
5477 throw_exception (e);
5479 exception_print (gdb_stderr, e);
5481 /* If pending breakpoint support is auto query and the user
5482 selects no, then simply return the error code. */
5483 if (pending_break_support == AUTO_BOOLEAN_AUTO &&
5484 !nquery ("Make breakpoint pending on future shared library load? "))
5487 /* At this point, either the user was queried about setting
5488 a pending breakpoint and selected yes, or pending
5489 breakpoint behavior is on and thus a pending breakpoint
5490 is defaulted on behalf of the user. */
5491 copy_arg = xstrdup (addr_start);
5492 addr_string = ©_arg;
5494 sals.sals = &pending_sal;
5499 throw_exception (e);
5506 /* Create a chain of things that always need to be cleaned up. */
5507 old_chain = make_cleanup (null_cleanup, 0);
5511 /* Make sure that all storage allocated to SALS gets freed. */
5512 make_cleanup (xfree, sals.sals);
5514 /* Cleanup the addr_string array but not its contents. */
5515 make_cleanup (xfree, addr_string);
5518 /* ----------------------------- SNIP -----------------------------
5519 Anything added to the cleanup chain beyond this point is assumed
5520 to be part of a breakpoint. If the breakpoint create succeeds
5521 then the memory is not reclaimed. */
5522 breakpoint_chain = make_cleanup (null_cleanup, 0);
5524 /* Mark the contents of the addr_string for cleanup. These go on
5525 the breakpoint_chain and only occure if the breakpoint create
5527 for (i = 0; i < sals.nelts; i++)
5529 if (addr_string[i] != NULL)
5530 make_cleanup (xfree, addr_string[i]);
5533 /* Resolve all line numbers to PC's and verify that the addresses
5534 are ok for the target. */
5536 breakpoint_sals_to_pc (&sals, addr_start);
5538 /* Verify that condition can be parsed, before setting any
5539 breakpoints. Allocate a separate condition expression for each
5543 if (parse_condition_and_thread)
5545 /* Here we only parse 'arg' to separate condition
5546 from thread number, so parsing in context of first
5547 sal is OK. When setting the breakpoint we'll
5548 re-parse it in context of each sal. */
5551 find_condition_and_thread (arg, sals.sals[0].pc, &cond_string, &thread);
5553 make_cleanup (xfree, cond_string);
5557 /* Create a private copy of condition string. */
5560 cond_string = xstrdup (cond_string);
5561 make_cleanup (xfree, cond_string);
5564 create_breakpoints (sals, addr_string, cond_string,
5565 hardwareflag ? bp_hardware_breakpoint
5567 tempflag ? disp_del : disp_donttouch,
5568 thread, ignore_count, ops, from_tty);
5572 struct symtab_and_line sal = {0};
5573 struct breakpoint *b;
5575 make_cleanup (xfree, copy_arg);
5577 b = set_raw_breakpoint_without_location (hardwareflag
5578 ? bp_hardware_breakpoint
5580 set_breakpoint_count (breakpoint_count + 1);
5581 b->number = breakpoint_count;
5583 b->addr_string = addr_string[0];
5584 b->cond_string = NULL;
5585 b->ignore_count = ignore_count;
5586 b->disposition = tempflag ? disp_del : disp_donttouch;
5587 b->condition_not_parsed = 1;
5590 update_global_location_list ();
5595 warning (_("Multiple breakpoints were set.\n"
5596 "Use the \"delete\" command to delete unwanted breakpoints."));
5597 /* That's it. Discard the cleanups for data inserted into the
5599 discard_cleanups (breakpoint_chain);
5600 /* But cleanup everything else. */
5601 do_cleanups (old_chain);
5604 /* Set a breakpoint.
5605 ARG is a string describing breakpoint address,
5606 condition, and thread.
5607 FLAG specifies if a breakpoint is hardware on,
5608 and if breakpoint is temporary, using BP_HARDWARE_FLAG
5612 break_command_1 (char *arg, int flag, int from_tty)
5614 int hardwareflag = flag & BP_HARDWAREFLAG;
5615 int tempflag = flag & BP_TEMPFLAG;
5617 break_command_really (arg,
5618 NULL, 0, 1 /* parse arg */,
5619 tempflag, hardwareflag,
5620 0 /* Ignore count */,
5621 pending_break_support,
5622 NULL /* breakpoint_ops */,
5628 set_breakpoint (char *address, char *condition,
5629 int hardwareflag, int tempflag,
5630 int thread, int ignore_count,
5633 break_command_really (address, condition, thread,
5634 0 /* condition and thread are valid. */,
5635 tempflag, hardwareflag,
5638 ? AUTO_BOOLEAN_TRUE : AUTO_BOOLEAN_FALSE,
5642 /* Adjust SAL to the first instruction past the function prologue.
5643 The end of the prologue is determined using the line table from
5644 the debugging information.
5646 If SAL is already past the prologue, then do nothing. */
5649 skip_prologue_sal (struct symtab_and_line *sal)
5651 struct symbol *sym = find_pc_function (sal->pc);
5652 struct symtab_and_line start_sal;
5657 start_sal = find_function_start_sal (sym, 1);
5658 if (sal->pc < start_sal.pc)
5662 /* Helper function for break_command_1 and disassemble_command. */
5665 resolve_sal_pc (struct symtab_and_line *sal)
5669 if (sal->pc == 0 && sal->symtab != NULL)
5671 if (!find_line_pc (sal->symtab, sal->line, &pc))
5672 error (_("No line %d in file \"%s\"."),
5673 sal->line, sal->symtab->filename);
5676 /* If this SAL corresponds to a breakpoint inserted using
5677 a line number, then skip the function prologue if necessary. */
5678 if (sal->explicit_line)
5679 skip_prologue_sal (sal);
5682 if (sal->section == 0 && sal->symtab != NULL)
5684 struct blockvector *bv;
5688 bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab);
5691 sym = block_function (b);
5694 fixup_symbol_section (sym, sal->symtab->objfile);
5695 sal->section = SYMBOL_BFD_SECTION (sym);
5699 /* It really is worthwhile to have the section, so we'll just
5700 have to look harder. This case can be executed if we have
5701 line numbers but no functions (as can happen in assembly
5704 struct minimal_symbol *msym;
5706 msym = lookup_minimal_symbol_by_pc (sal->pc);
5708 sal->section = SYMBOL_BFD_SECTION (msym);
5715 break_command (char *arg, int from_tty)
5717 break_command_1 (arg, 0, from_tty);
5721 tbreak_command (char *arg, int from_tty)
5723 break_command_1 (arg, BP_TEMPFLAG, from_tty);
5727 hbreak_command (char *arg, int from_tty)
5729 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
5733 thbreak_command (char *arg, int from_tty)
5735 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
5739 stop_command (char *arg, int from_tty)
5741 printf_filtered (_("Specify the type of breakpoint to set.\n\
5742 Usage: stop in <function | address>\n\
5743 stop at <line>\n"));
5747 stopin_command (char *arg, int from_tty)
5751 if (arg == (char *) NULL)
5753 else if (*arg != '*')
5758 /* look for a ':'. If this is a line number specification, then
5759 say it is bad, otherwise, it should be an address or
5760 function/method name */
5761 while (*argptr && !hasColon)
5763 hasColon = (*argptr == ':');
5768 badInput = (*argptr != ':'); /* Not a class::method */
5770 badInput = isdigit (*arg); /* a simple line number */
5774 printf_filtered (_("Usage: stop in <function | address>\n"));
5776 break_command_1 (arg, 0, from_tty);
5780 stopat_command (char *arg, int from_tty)
5784 if (arg == (char *) NULL || *arg == '*') /* no line number */
5791 /* look for a ':'. If there is a '::' then get out, otherwise
5792 it is probably a line number. */
5793 while (*argptr && !hasColon)
5795 hasColon = (*argptr == ':');
5800 badInput = (*argptr == ':'); /* we have class::method */
5802 badInput = !isdigit (*arg); /* not a line number */
5806 printf_filtered (_("Usage: stop at <line>\n"));
5808 break_command_1 (arg, 0, from_tty);
5811 /* accessflag: hw_write: watch write,
5812 hw_read: watch read,
5813 hw_access: watch access (read or write) */
5815 watch_command_1 (char *arg, int accessflag, int from_tty)
5817 struct breakpoint *b, *scope_breakpoint = NULL;
5818 struct symtab_and_line sal;
5819 struct expression *exp;
5820 struct block *exp_valid_block;
5821 struct value *val, *mark;
5822 struct frame_info *frame;
5823 struct frame_info *prev_frame = NULL;
5824 char *exp_start = NULL;
5825 char *exp_end = NULL;
5826 char *tok, *id_tok_start, *end_tok;
5828 char *cond_start = NULL;
5829 char *cond_end = NULL;
5830 struct expression *cond = NULL;
5831 int i, other_type_used, target_resources_ok = 0;
5832 enum bptype bp_type;
5836 init_sal (&sal); /* initialize to zeroes */
5838 /* Make sure that we actually have parameters to parse. */
5839 if (arg != NULL && arg[0] != '\0')
5841 toklen = strlen (arg); /* Size of argument list. */
5843 /* Points tok to the end of the argument list. */
5844 tok = arg + toklen - 1;
5846 /* Go backwards in the parameters list. Skip the last parameter.
5847 If we're expecting a 'thread <thread_num>' parameter, this should
5848 be the thread identifier. */
5849 while (tok > arg && (*tok == ' ' || *tok == '\t'))
5851 while (tok > arg && (*tok != ' ' && *tok != '\t'))
5854 /* Points end_tok to the beginning of the last token. */
5855 id_tok_start = tok + 1;
5857 /* Go backwards in the parameters list. Skip one more parameter.
5858 If we're expecting a 'thread <thread_num>' parameter, we should
5859 reach a "thread" token. */
5860 while (tok > arg && (*tok == ' ' || *tok == '\t'))
5865 while (tok > arg && (*tok != ' ' && *tok != '\t'))
5868 /* Move the pointer forward to skip the whitespace and
5869 calculate the length of the token. */
5871 toklen = end_tok - tok;
5873 if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
5875 /* At this point we've found a "thread" token, which means
5876 the user is trying to set a watchpoint that triggers
5877 only in a specific thread. */
5880 /* Extract the thread ID from the next token. */
5881 thread = strtol (id_tok_start, &endp, 0);
5883 /* Check if the user provided a valid numeric value for the
5885 if (*endp != ' ' && *endp != '\t' && *endp != '\0')
5886 error (_("Invalid thread ID specification %s."), id_tok_start);
5888 /* Check if the thread actually exists. */
5889 if (!valid_thread_id (thread))
5890 error (_("Unknown thread %d."), thread);
5892 /* Truncate the string and get rid of the thread <thread_num>
5893 parameter before the parameter list is parsed by the
5894 evaluate_expression() function. */
5899 /* Parse the rest of the arguments. */
5900 innermost_block = NULL;
5902 exp = parse_exp_1 (&arg, 0, 0);
5904 exp_valid_block = innermost_block;
5905 mark = value_mark ();
5906 fetch_watchpoint_value (exp, &val, NULL, NULL);
5908 release_value (val);
5911 while (*tok == ' ' || *tok == '\t')
5915 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
5918 toklen = end_tok - tok;
5919 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
5921 tok = cond_start = end_tok + 1;
5922 cond = parse_exp_1 (&tok, 0, 0);
5926 error (_("Junk at end of command."));
5928 if (accessflag == hw_read)
5929 bp_type = bp_read_watchpoint;
5930 else if (accessflag == hw_access)
5931 bp_type = bp_access_watchpoint;
5933 bp_type = bp_hardware_watchpoint;
5935 mem_cnt = can_use_hardware_watchpoint (val);
5936 if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
5937 error (_("Expression cannot be implemented with read/access watchpoint."));
5940 i = hw_watchpoint_used_count (bp_type, &other_type_used);
5941 target_resources_ok =
5942 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type, i + mem_cnt,
5944 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
5945 error (_("Target does not support this type of hardware watchpoint."));
5947 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
5948 error (_("Target can only support one kind of HW watchpoint at a time."));
5951 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5952 watchpoint could not be set. */
5953 if (!mem_cnt || target_resources_ok <= 0)
5954 bp_type = bp_watchpoint;
5956 frame = block_innermost_frame (exp_valid_block);
5958 prev_frame = get_prev_frame (frame);
5962 /* If the expression is "local", then set up a "watchpoint scope"
5963 breakpoint at the point where we've left the scope of the watchpoint
5964 expression. Create the scope breakpoint before the watchpoint, so
5965 that we will encounter it first in bpstat_stop_status. */
5966 if (innermost_block && prev_frame)
5968 scope_breakpoint = create_internal_breakpoint (get_frame_pc (prev_frame),
5969 bp_watchpoint_scope);
5971 scope_breakpoint->enable_state = bp_enabled;
5973 /* Automatically delete the breakpoint when it hits. */
5974 scope_breakpoint->disposition = disp_del;
5976 /* Only break in the proper frame (help with recursion). */
5977 scope_breakpoint->frame_id = get_frame_id (prev_frame);
5979 /* Set the address at which we will stop. */
5980 scope_breakpoint->loc->requested_address
5981 = get_frame_pc (prev_frame);
5982 scope_breakpoint->loc->address
5983 = adjust_breakpoint_address (scope_breakpoint->loc->requested_address,
5984 scope_breakpoint->type);
5987 /* Now set up the breakpoint. */
5988 b = set_raw_breakpoint (sal, bp_type);
5989 set_breakpoint_count (breakpoint_count + 1);
5990 b->number = breakpoint_count;
5992 b->disposition = disp_donttouch;
5994 b->exp_valid_block = exp_valid_block;
5995 b->exp_string = savestring (exp_start, exp_end - exp_start);
5998 b->loc->cond = cond;
6000 b->cond_string = savestring (cond_start, cond_end - cond_start);
6005 b->watchpoint_frame = get_frame_id (frame);
6007 b->watchpoint_frame = null_frame_id;
6009 if (scope_breakpoint != NULL)
6011 /* The scope breakpoint is related to the watchpoint. We will
6012 need to act on them together. */
6013 b->related_breakpoint = scope_breakpoint;
6014 scope_breakpoint->related_breakpoint = b;
6017 value_free_to_mark (mark);
6019 update_global_location_list ();
6022 /* Return count of locations need to be watched and can be handled
6023 in hardware. If the watchpoint can not be handled
6024 in hardware return zero. */
6027 can_use_hardware_watchpoint (struct value *v)
6029 int found_memory_cnt = 0;
6030 struct value *head = v;
6032 /* Did the user specifically forbid us to use hardware watchpoints? */
6033 if (!can_use_hw_watchpoints)
6036 /* Make sure that the value of the expression depends only upon
6037 memory contents, and values computed from them within GDB. If we
6038 find any register references or function calls, we can't use a
6039 hardware watchpoint.
6041 The idea here is that evaluating an expression generates a series
6042 of values, one holding the value of every subexpression. (The
6043 expression a*b+c has five subexpressions: a, b, a*b, c, and
6044 a*b+c.) GDB's values hold almost enough information to establish
6045 the criteria given above --- they identify memory lvalues,
6046 register lvalues, computed values, etcetera. So we can evaluate
6047 the expression, and then scan the chain of values that leaves
6048 behind to decide whether we can detect any possible change to the
6049 expression's final value using only hardware watchpoints.
6051 However, I don't think that the values returned by inferior
6052 function calls are special in any way. So this function may not
6053 notice that an expression involving an inferior function call
6054 can't be watched with hardware watchpoints. FIXME. */
6055 for (; v; v = value_next (v))
6057 if (VALUE_LVAL (v) == lval_memory)
6060 /* A lazy memory lvalue is one that GDB never needed to fetch;
6061 we either just used its address (e.g., `a' in `a.b') or
6062 we never needed it at all (e.g., `a' in `a,b'). */
6066 /* Ahh, memory we actually used! Check if we can cover
6067 it with hardware watchpoints. */
6068 struct type *vtype = check_typedef (value_type (v));
6070 /* We only watch structs and arrays if user asked for it
6071 explicitly, never if they just happen to appear in a
6072 middle of some value chain. */
6074 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
6075 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
6077 CORE_ADDR vaddr = VALUE_ADDRESS (v) + value_offset (v);
6078 int len = TYPE_LENGTH (value_type (v));
6080 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr, len))
6087 else if (VALUE_LVAL (v) != not_lval
6088 && deprecated_value_modifiable (v) == 0)
6089 return 0; /* ??? What does this represent? */
6090 else if (VALUE_LVAL (v) == lval_register)
6091 return 0; /* cannot watch a register with a HW watchpoint */
6094 /* The expression itself looks suitable for using a hardware
6095 watchpoint, but give the target machine a chance to reject it. */
6096 return found_memory_cnt;
6100 watch_command_wrapper (char *arg, int from_tty)
6102 watch_command (arg, from_tty);
6106 watch_command (char *arg, int from_tty)
6108 watch_command_1 (arg, hw_write, from_tty);
6112 rwatch_command_wrapper (char *arg, int from_tty)
6114 rwatch_command (arg, from_tty);
6118 rwatch_command (char *arg, int from_tty)
6120 watch_command_1 (arg, hw_read, from_tty);
6124 awatch_command_wrapper (char *arg, int from_tty)
6126 awatch_command (arg, from_tty);
6130 awatch_command (char *arg, int from_tty)
6132 watch_command_1 (arg, hw_access, from_tty);
6136 /* Helper routines for the until_command routine in infcmd.c. Here
6137 because it uses the mechanisms of breakpoints. */
6139 /* This function is called by fetch_inferior_event via the
6140 cmd_continuation pointer, to complete the until command. It takes
6141 care of cleaning up the temporary breakpoints set up by the until
6144 until_break_command_continuation (struct continuation_arg *arg, int error)
6146 delete_breakpoint ((struct breakpoint *)(arg->data.pointer));
6148 delete_breakpoint ((struct breakpoint *)(arg->next->data.pointer));
6152 until_break_command (char *arg, int from_tty, int anywhere)
6154 struct symtabs_and_lines sals;
6155 struct symtab_and_line sal;
6156 struct frame_info *frame = get_selected_frame (NULL);
6157 struct frame_info *prev_frame = get_prev_frame (frame);
6158 struct breakpoint *breakpoint;
6159 struct breakpoint *breakpoint2 = NULL;
6160 struct cleanup *old_chain;
6161 struct continuation_arg *arg1;
6162 struct continuation_arg *arg2;
6165 clear_proceed_status ();
6167 /* Set a breakpoint where the user wants it and at return from
6170 if (default_breakpoint_valid)
6171 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
6172 default_breakpoint_line, (char ***) NULL, NULL);
6174 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL,
6175 0, (char ***) NULL, NULL);
6177 if (sals.nelts != 1)
6178 error (_("Couldn't get information on specified line."));
6181 xfree (sals.sals); /* malloc'd, so freed */
6184 error (_("Junk at end of arguments."));
6186 resolve_sal_pc (&sal);
6189 /* If the user told us to continue until a specified location,
6190 we don't specify a frame at which we need to stop. */
6191 breakpoint = set_momentary_breakpoint (sal, null_frame_id, bp_until);
6193 /* Otherwise, specify the current frame, because we want to stop only
6194 at the very same frame. */
6195 breakpoint = set_momentary_breakpoint (sal, get_frame_id (frame),
6198 old_chain = make_cleanup_delete_breakpoint (breakpoint);
6200 /* Keep within the current frame, or in frames called by the current
6204 sal = find_pc_line (get_frame_pc (prev_frame), 0);
6205 sal.pc = get_frame_pc (prev_frame);
6206 breakpoint2 = set_momentary_breakpoint (sal, get_frame_id (prev_frame),
6208 make_cleanup_delete_breakpoint (breakpoint2);
6211 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
6213 /* If we are running asynchronously, and proceed call above has actually
6214 managed to start the target, arrange for breakpoints to be
6215 deleted when the target stops. Otherwise, we're already stopped and
6216 delete breakpoints via cleanup chain. */
6218 if (target_can_async_p () && target_executing)
6221 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
6223 arg1->data.pointer = breakpoint;
6227 arg2 = (struct continuation_arg *)
6228 xmalloc ( sizeof (struct continuation_arg));
6230 arg2->data.pointer = breakpoint2;
6234 discard_cleanups (old_chain);
6235 add_continuation (until_break_command_continuation, arg1);
6238 do_cleanups (old_chain);
6242 ep_skip_leading_whitespace (char **s)
6244 if ((s == NULL) || (*s == NULL))
6246 while (isspace (**s))
6250 /* This function examines a string, and attempts to find a token
6251 that might be an event name in the leading characters. If a
6252 possible match is found, a pointer to the last character of
6253 the token is returned. Else, NULL is returned. */
6256 ep_find_event_name_end (char *arg)
6259 char *event_name_end = NULL;
6261 /* If we could depend upon the presense of strrpbrk, we'd use that... */
6265 /* We break out of the loop when we find a token delimiter.
6266 Basically, we're looking for alphanumerics and underscores;
6267 anything else delimites the token. */
6270 if (!isalnum (*s) && (*s != '_'))
6276 return event_name_end;
6280 /* This function attempts to parse an optional "if <cond>" clause
6281 from the arg string. If one is not found, it returns NULL.
6283 Else, it returns a pointer to the condition string. (It does not
6284 attempt to evaluate the string against a particular block.) And,
6285 it updates arg to point to the first character following the parsed
6286 if clause in the arg string. */
6289 ep_parse_optional_if_clause (char **arg)
6293 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
6296 /* Skip the "if" keyword. */
6299 /* Skip any extra leading whitespace, and record the start of the
6300 condition string. */
6301 ep_skip_leading_whitespace (arg);
6304 /* Assume that the condition occupies the remainder of the arg string. */
6305 (*arg) += strlen (cond_string);
6310 /* This function attempts to parse an optional filename from the arg
6311 string. If one is not found, it returns NULL.
6313 Else, it returns a pointer to the parsed filename. (This function
6314 makes no attempt to verify that a file of that name exists, or is
6315 accessible.) And, it updates arg to point to the first character
6316 following the parsed filename in the arg string.
6318 Note that clients needing to preserve the returned filename for
6319 future access should copy it to their own buffers. */
6321 ep_parse_optional_filename (char **arg)
6323 static char filename[1024];
6328 if ((*arg_p == '\0') || isspace (*arg_p))
6346 /* Commands to deal with catching events, such as signals, exceptions,
6347 process start/exit, etc. */
6351 catch_fork, catch_vfork
6356 catch_fork_command_1 (catch_fork_kind fork_kind, char *arg, int tempflag,
6359 char *cond_string = NULL;
6361 ep_skip_leading_whitespace (&arg);
6363 /* The allowed syntax is:
6365 catch [v]fork if <cond>
6367 First, check if there's an if clause. */
6368 cond_string = ep_parse_optional_if_clause (&arg);
6370 if ((*arg != '\0') && !isspace (*arg))
6371 error (_("Junk at end of arguments."));
6373 /* If this target supports it, create a fork or vfork catchpoint
6374 and enable reporting of such events. */
6378 create_fork_event_catchpoint (tempflag, cond_string);
6381 create_vfork_event_catchpoint (tempflag, cond_string);
6384 error (_("unsupported or unknown fork kind; cannot catch it"));
6390 catch_exec_command_1 (char *arg, int tempflag, int from_tty)
6392 char *cond_string = NULL;
6394 ep_skip_leading_whitespace (&arg);
6396 /* The allowed syntax is:
6398 catch exec if <cond>
6400 First, check if there's an if clause. */
6401 cond_string = ep_parse_optional_if_clause (&arg);
6403 if ((*arg != '\0') && !isspace (*arg))
6404 error (_("Junk at end of arguments."));
6406 /* If this target supports it, create an exec catchpoint
6407 and enable reporting of such events. */
6408 create_exec_event_catchpoint (tempflag, cond_string);
6412 catch_load_command_1 (char *arg, int tempflag, int from_tty)
6414 char *dll_pathname = NULL;
6415 char *cond_string = NULL;
6417 ep_skip_leading_whitespace (&arg);
6419 /* The allowed syntax is:
6421 catch load if <cond>
6422 catch load <filename>
6423 catch load <filename> if <cond>
6425 The user is not allowed to specify the <filename> after an
6428 We'll ignore the pathological case of a file named "if".
6430 First, check if there's an if clause. If so, then there
6431 cannot be a filename. */
6432 cond_string = ep_parse_optional_if_clause (&arg);
6434 /* If there was an if clause, then there cannot be a filename.
6435 Else, there might be a filename and an if clause. */
6436 if (cond_string == NULL)
6438 dll_pathname = ep_parse_optional_filename (&arg);
6439 ep_skip_leading_whitespace (&arg);
6440 cond_string = ep_parse_optional_if_clause (&arg);
6443 if ((*arg != '\0') && !isspace (*arg))
6444 error (_("Junk at end of arguments."));
6446 /* Create a load breakpoint that only triggers when a load of
6447 the specified dll (or any dll, if no pathname was specified)
6449 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid), tempflag,
6450 dll_pathname, cond_string);
6454 catch_unload_command_1 (char *arg, int tempflag, int from_tty)
6456 char *dll_pathname = NULL;
6457 char *cond_string = NULL;
6459 ep_skip_leading_whitespace (&arg);
6461 /* The allowed syntax is:
6463 catch unload if <cond>
6464 catch unload <filename>
6465 catch unload <filename> if <cond>
6467 The user is not allowed to specify the <filename> after an
6470 We'll ignore the pathological case of a file named "if".
6472 First, check if there's an if clause. If so, then there
6473 cannot be a filename. */
6474 cond_string = ep_parse_optional_if_clause (&arg);
6476 /* If there was an if clause, then there cannot be a filename.
6477 Else, there might be a filename and an if clause. */
6478 if (cond_string == NULL)
6480 dll_pathname = ep_parse_optional_filename (&arg);
6481 ep_skip_leading_whitespace (&arg);
6482 cond_string = ep_parse_optional_if_clause (&arg);
6485 if ((*arg != '\0') && !isspace (*arg))
6486 error (_("Junk at end of arguments."));
6488 /* Create an unload breakpoint that only triggers when an unload of
6489 the specified dll (or any dll, if no pathname was specified)
6491 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid), tempflag,
6492 dll_pathname, cond_string);
6495 static enum print_stop_action
6496 print_exception_catchpoint (struct breakpoint *b)
6498 int bp_temp, bp_throw;
6500 annotate_catchpoint (b->number);
6502 bp_throw = strstr (b->addr_string, "throw") != NULL;
6503 if (b->loc->address != b->loc->requested_address)
6504 breakpoint_adjustment_warning (b->loc->requested_address,
6507 bp_temp = b->loc->owner->disposition == disp_del;
6509 bp_temp ? "Temporary catchpoint "
6511 if (!ui_out_is_mi_like_p (uiout))
6512 ui_out_field_int (uiout, "bkptno", b->number);
6514 bp_throw ? " (thrown), "
6516 if (ui_out_is_mi_like_p (uiout))
6518 ui_out_field_string (uiout, "reason",
6519 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
6520 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
6521 ui_out_field_int (uiout, "bkptno", b->number);
6523 return PRINT_SRC_AND_LOC;
6527 print_one_exception_catchpoint (struct breakpoint *b, CORE_ADDR *last_addr)
6532 if (b->loc == NULL || b->loc->shlib_disabled)
6533 ui_out_field_string (uiout, "addr", "<PENDING>");
6535 ui_out_field_core_addr (uiout, "addr", b->loc->address);
6539 *last_addr = b->loc->address;
6540 if (strstr (b->addr_string, "throw") != NULL)
6541 ui_out_field_string (uiout, "what", "exception throw");
6543 ui_out_field_string (uiout, "what", "exception catch");
6547 print_mention_exception_catchpoint (struct breakpoint *b)
6552 bp_temp = b->loc->owner->disposition == disp_del;
6553 bp_throw = strstr (b->addr_string, "throw") != NULL;
6554 ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ")
6555 : _("Catchpoint "));
6556 ui_out_field_int (uiout, "bkptno", b->number);
6557 ui_out_text (uiout, bp_throw ? _(" (throw)")
6561 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = {
6562 print_exception_catchpoint,
6563 print_one_exception_catchpoint,
6564 print_mention_exception_catchpoint
6568 handle_gnu_v3_exceptions (int tempflag, char *cond_string,
6569 enum exception_event_kind ex_event, int from_tty)
6571 char *trigger_func_name;
6573 if (ex_event == EX_EVENT_CATCH)
6574 trigger_func_name = "__cxa_begin_catch";
6576 trigger_func_name = "__cxa_throw";
6578 break_command_really (trigger_func_name, cond_string, -1,
6579 0 /* condition and thread are valid. */,
6582 AUTO_BOOLEAN_TRUE /* pending */,
6583 &gnu_v3_exception_catchpoint_ops, from_tty);
6588 /* Deal with "catch catch" and "catch throw" commands */
6591 catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
6592 int tempflag, int from_tty)
6594 char *cond_string = NULL;
6595 struct symtab_and_line *sal = NULL;
6597 ep_skip_leading_whitespace (&arg);
6599 cond_string = ep_parse_optional_if_clause (&arg);
6601 if ((*arg != '\0') && !isspace (*arg))
6602 error (_("Junk at end of arguments."));
6604 if ((ex_event != EX_EVENT_THROW) &&
6605 (ex_event != EX_EVENT_CATCH))
6606 error (_("Unsupported or unknown exception event; cannot catch it"));
6608 if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty))
6611 warning (_("Unsupported with this platform/compiler combination."));
6614 /* Create a breakpoint struct for Ada exception catchpoints. */
6617 create_ada_exception_breakpoint (struct symtab_and_line sal,
6621 struct expression *cond,
6622 struct breakpoint_ops *ops,
6626 struct breakpoint *b;
6630 describe_other_breakpoints (sal.pc, sal.section, -1);
6631 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
6632 version for exception catchpoints, because two catchpoints
6633 used for different exception names will use the same address.
6634 In this case, a "breakpoint ... also set at..." warning is
6635 unproductive. Besides. the warning phrasing is also a bit
6636 inapropriate, we should use the word catchpoint, and tell
6637 the user what type of catchpoint it is. The above is good
6638 enough for now, though. */
6641 b = set_raw_breakpoint (sal, bp_breakpoint);
6642 set_breakpoint_count (breakpoint_count + 1);
6644 b->enable_state = bp_enabled;
6645 b->disposition = tempflag ? disp_del : disp_donttouch;
6646 b->number = breakpoint_count;
6647 b->ignore_count = 0;
6648 b->loc->cond = cond;
6649 b->addr_string = addr_string;
6650 b->language = language_ada;
6651 b->cond_string = cond_string;
6652 b->exp_string = exp_string;
6657 update_global_location_list ();
6660 /* Implement the "catch exception" command. */
6663 catch_ada_exception_command (char *arg, int tempflag, int from_tty)
6665 struct symtab_and_line sal;
6667 char *addr_string = NULL;
6668 char *exp_string = NULL;
6669 char *cond_string = NULL;
6670 struct expression *cond = NULL;
6671 struct breakpoint_ops *ops = NULL;
6673 sal = ada_decode_exception_location (arg, &addr_string, &exp_string,
6674 &cond_string, &cond, &ops);
6675 create_ada_exception_breakpoint (sal, addr_string, exp_string,
6676 cond_string, cond, ops, tempflag,
6680 /* Implement the "catch assert" command. */
6683 catch_assert_command (char *arg, int tempflag, int from_tty)
6685 struct symtab_and_line sal;
6686 char *addr_string = NULL;
6687 struct breakpoint_ops *ops = NULL;
6689 sal = ada_decode_assert_location (arg, &addr_string, &ops);
6690 create_ada_exception_breakpoint (sal, addr_string, NULL, NULL, NULL, ops,
6691 tempflag, from_tty);
6695 catch_command_1 (char *arg, int tempflag, int from_tty)
6698 /* The first argument may be an event name, such as "start" or "load".
6699 If so, then handle it as such. If it doesn't match an event name,
6700 then attempt to interpret it as an exception name. (This latter is
6701 the v4.16-and-earlier GDB meaning of the "catch" command.)
6703 First, try to find the bounds of what might be an event name. */
6704 char *arg1_start = arg;
6708 if (arg1_start == NULL)
6710 /* Old behaviour was to use pre-v-4.16 syntax */
6711 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6713 /* Now, this is not allowed */
6714 error (_("Catch requires an event name."));
6717 arg1_end = ep_find_event_name_end (arg1_start);
6718 if (arg1_end == NULL)
6719 error (_("catch requires an event"));
6720 arg1_length = arg1_end + 1 - arg1_start;
6722 /* Try to match what we found against known event names. */
6723 if (strncmp (arg1_start, "signal", arg1_length) == 0)
6725 error (_("Catch of signal not yet implemented"));
6727 else if (strncmp (arg1_start, "catch", arg1_length) == 0)
6729 catch_exception_command_1 (EX_EVENT_CATCH, arg1_end + 1,
6730 tempflag, from_tty);
6732 else if (strncmp (arg1_start, "throw", arg1_length) == 0)
6734 catch_exception_command_1 (EX_EVENT_THROW, arg1_end + 1,
6735 tempflag, from_tty);
6737 else if (strncmp (arg1_start, "thread_start", arg1_length) == 0)
6739 error (_("Catch of thread_start not yet implemented"));
6741 else if (strncmp (arg1_start, "thread_exit", arg1_length) == 0)
6743 error (_("Catch of thread_exit not yet implemented"));
6745 else if (strncmp (arg1_start, "thread_join", arg1_length) == 0)
6747 error (_("Catch of thread_join not yet implemented"));
6749 else if (strncmp (arg1_start, "start", arg1_length) == 0)
6751 error (_("Catch of start not yet implemented"));
6753 else if (strncmp (arg1_start, "exit", arg1_length) == 0)
6755 error (_("Catch of exit not yet implemented"));
6757 else if (strncmp (arg1_start, "fork", arg1_length) == 0)
6759 catch_fork_command_1 (catch_fork, arg1_end + 1, tempflag, from_tty);
6761 else if (strncmp (arg1_start, "vfork", arg1_length) == 0)
6763 catch_fork_command_1 (catch_vfork, arg1_end + 1, tempflag, from_tty);
6765 else if (strncmp (arg1_start, "exec", arg1_length) == 0)
6767 catch_exec_command_1 (arg1_end + 1, tempflag, from_tty);
6769 else if (strncmp (arg1_start, "load", arg1_length) == 0)
6771 catch_load_command_1 (arg1_end + 1, tempflag, from_tty);
6773 else if (strncmp (arg1_start, "unload", arg1_length) == 0)
6775 catch_unload_command_1 (arg1_end + 1, tempflag, from_tty);
6777 else if (strncmp (arg1_start, "stop", arg1_length) == 0)
6779 error (_("Catch of stop not yet implemented"));
6781 else if (strncmp (arg1_start, "exception", arg1_length) == 0)
6783 catch_ada_exception_command (arg1_end + 1, tempflag, from_tty);
6786 else if (strncmp (arg1_start, "assert", arg1_length) == 0)
6788 catch_assert_command (arg1_end + 1, tempflag, from_tty);
6791 /* This doesn't appear to be an event name */
6795 /* Pre-v.4.16 behaviour was to treat the argument
6796 as the name of an exception */
6797 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6798 /* Now this is not allowed */
6799 error (_("Unknown event kind specified for catch"));
6805 catch_command (char *arg, int from_tty)
6807 catch_command_1 (arg, 0, from_tty);
6812 tcatch_command (char *arg, int from_tty)
6814 catch_command_1 (arg, 1, from_tty);
6817 /* Delete breakpoints by address or line. */
6820 clear_command (char *arg, int from_tty)
6822 struct breakpoint *b;
6823 VEC(breakpoint_p) *found = 0;
6826 struct symtabs_and_lines sals;
6827 struct symtab_and_line sal;
6832 sals = decode_line_spec (arg, 1);
6837 sals.sals = (struct symtab_and_line *)
6838 xmalloc (sizeof (struct symtab_and_line));
6839 make_cleanup (xfree, sals.sals);
6840 init_sal (&sal); /* initialize to zeroes */
6841 sal.line = default_breakpoint_line;
6842 sal.symtab = default_breakpoint_symtab;
6843 sal.pc = default_breakpoint_address;
6844 if (sal.symtab == 0)
6845 error (_("No source file specified."));
6853 /* We don't call resolve_sal_pc here. That's not
6854 as bad as it seems, because all existing breakpoints
6855 typically have both file/line and pc set. So, if
6856 clear is given file/line, we can match this to existing
6857 breakpoint without obtaining pc at all.
6859 We only support clearing given the address explicitly
6860 present in breakpoint table. Say, we've set breakpoint
6861 at file:line. There were several PC values for that file:line,
6862 due to optimization, all in one block.
6863 We've picked one PC value. If "clear" is issued with another
6864 PC corresponding to the same file:line, the breakpoint won't
6865 be cleared. We probably can still clear the breakpoint, but
6866 since the other PC value is never presented to user, user
6867 can only find it by guessing, and it does not seem important
6870 /* For each line spec given, delete bps which correspond
6871 to it. Do it in two passes, solely to preserve the current
6872 behavior that from_tty is forced true if we delete more than
6876 for (i = 0; i < sals.nelts; i++)
6878 /* If exact pc given, clear bpts at that pc.
6879 If line given (pc == 0), clear all bpts on specified line.
6880 If defaulting, clear all bpts on default line
6883 defaulting sal.pc != 0 tests to do
6888 1 0 <can't happen> */
6892 /* Find all matching breakpoints and add them to
6897 /* Are we going to delete b? */
6898 if (b->type != bp_none
6899 && b->type != bp_watchpoint
6900 && b->type != bp_hardware_watchpoint
6901 && b->type != bp_read_watchpoint
6902 && b->type != bp_access_watchpoint)
6904 struct bp_location *loc = b->loc;
6905 for (; loc; loc = loc->next)
6907 int pc_match = sal.pc
6908 && (loc->address == sal.pc)
6909 && (!section_is_overlay (loc->section)
6910 || loc->section == sal.section);
6911 int line_match = ((default_match || (0 == sal.pc))
6912 && b->source_file != NULL
6913 && sal.symtab != NULL
6914 && strcmp (b->source_file, sal.symtab->filename) == 0
6915 && b->line_number == sal.line);
6916 if (pc_match || line_match)
6925 VEC_safe_push(breakpoint_p, found, b);
6928 /* Now go thru the 'found' chain and delete them. */
6929 if (VEC_empty(breakpoint_p, found))
6932 error (_("No breakpoint at %s."), arg);
6934 error (_("No breakpoint at this line."));
6937 if (VEC_length(breakpoint_p, found) > 1)
6938 from_tty = 1; /* Always report if deleted more than one */
6941 if (VEC_length(breakpoint_p, found) == 1)
6942 printf_unfiltered (_("Deleted breakpoint "));
6944 printf_unfiltered (_("Deleted breakpoints "));
6946 breakpoints_changed ();
6948 for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++)
6951 printf_unfiltered ("%d ", b->number);
6952 delete_breakpoint (b);
6955 putchar_unfiltered ('\n');
6958 /* Delete breakpoint in BS if they are `delete' breakpoints and
6959 all breakpoints that are marked for deletion, whether hit or not.
6960 This is called after any breakpoint is hit, or after errors. */
6963 breakpoint_auto_delete (bpstat bs)
6965 struct breakpoint *b, *temp;
6967 for (; bs; bs = bs->next)
6968 if (bs->breakpoint_at && bs->breakpoint_at->owner->disposition == disp_del
6970 delete_breakpoint (bs->breakpoint_at->owner);
6972 ALL_BREAKPOINTS_SAFE (b, temp)
6974 if (b->disposition == disp_del_at_next_stop)
6975 delete_breakpoint (b);
6980 update_global_location_list (void)
6982 struct breakpoint *b;
6983 struct bp_location **next = &bp_location_chain;
6984 struct bp_location *loc;
6985 struct bp_location *loc2;
6986 struct gdb_exception e;
6987 VEC(bp_location_p) *old_locations = NULL;
6991 /* Store old locations for future reference. */
6992 for (loc = bp_location_chain; loc; loc = loc->global_next)
6993 VEC_safe_push (bp_location_p, old_locations, loc);
6995 bp_location_chain = NULL;
6998 for (loc = b->loc; loc; loc = loc->next)
7001 next = &(loc->global_next);
7006 /* Identify bp_location instances that are no longer present in the new
7007 list, and therefore should be freed. Note that it's not necessary that
7008 those locations should be removed from inferior -- if there's another
7009 location at the same address (previously marked as duplicate),
7010 we don't need to remove/insert the location. */
7011 for (ix = 0; VEC_iterate(bp_location_p, old_locations, ix, loc); ++ix)
7013 /* Tells if 'loc' is found amoung the new locations. If not, we
7015 int found_object = 0;
7016 for (loc2 = bp_location_chain; loc2; loc2 = loc2->global_next)
7023 /* If this location is no longer present, and inserted, look if there's
7024 maybe a new location at the same address. If so, mark that one
7025 inserted, and don't remove this one. This is needed so that we
7026 don't have a time window where a breakpoint at certain location is not
7031 /* If the location is inserted now, we might have to remove it. */
7034 if (found_object && should_be_inserted (loc))
7036 /* The location is still present in the location list, and still
7037 should be inserted. Don't do anything. */
7042 /* The location is either no longer present, or got disabled.
7043 See if there's another location at the same address, in which
7044 case we don't need to remove this one from the target. */
7045 if (breakpoint_address_is_meaningful (loc->owner))
7046 for (loc2 = bp_location_chain; loc2; loc2 = loc2->global_next)
7048 /* For the sake of should_insert_location. The
7049 call to check_duplicates will fix up this later. */
7050 loc2->duplicate = 0;
7051 if (should_be_inserted (loc2)
7052 && loc2 != loc && loc2->address == loc->address)
7055 loc2->target_info = loc->target_info;
7063 if (remove_breakpoint (loc, mark_uninserted))
7065 /* This is just about all we can do. We could keep this
7066 location on the global list, and try to remove it next
7067 time, but there's no particular reason why we will
7070 Note that at this point, loc->owner is still valid,
7071 as delete_breakpoint frees the breakpoint only
7072 after calling us. */
7073 printf_filtered (_("warning: Error removing breakpoint %d\n"),
7074 loc->owner->number);
7079 free_bp_location (loc);
7084 check_duplicates (b);
7087 if (always_inserted_mode && target_has_execution)
7088 insert_breakpoint_locations ();
7092 update_global_location_list_nothrow (void)
7094 struct gdb_exception e;
7095 TRY_CATCH (e, RETURN_MASK_ERROR)
7096 update_global_location_list ();
7099 /* Delete a breakpoint and clean up all traces of it in the data
7103 delete_breakpoint (struct breakpoint *bpt)
7105 struct breakpoint *b;
7107 struct bp_location *loc, *next;
7109 gdb_assert (bpt != NULL);
7111 /* Has this bp already been deleted? This can happen because multiple
7112 lists can hold pointers to bp's. bpstat lists are especial culprits.
7114 One example of this happening is a watchpoint's scope bp. When the
7115 scope bp triggers, we notice that the watchpoint is out of scope, and
7116 delete it. We also delete its scope bp. But the scope bp is marked
7117 "auto-deleting", and is already on a bpstat. That bpstat is then
7118 checked for auto-deleting bp's, which are deleted.
7120 A real solution to this problem might involve reference counts in bp's,
7121 and/or giving them pointers back to their referencing bpstat's, and
7122 teaching delete_breakpoint to only free a bp's storage when no more
7123 references were extent. A cheaper bandaid was chosen. */
7124 if (bpt->type == bp_none)
7127 if (deprecated_delete_breakpoint_hook)
7128 deprecated_delete_breakpoint_hook (bpt);
7129 breakpoint_delete_event (bpt->number);
7131 if (breakpoint_chain == bpt)
7132 breakpoint_chain = bpt->next;
7137 b->next = bpt->next;
7141 free_command_lines (&bpt->commands);
7142 if (bpt->cond_string != NULL)
7143 xfree (bpt->cond_string);
7144 if (bpt->addr_string != NULL)
7145 xfree (bpt->addr_string);
7146 if (bpt->exp != NULL)
7148 if (bpt->exp_string != NULL)
7149 xfree (bpt->exp_string);
7150 if (bpt->val != NULL)
7151 value_free (bpt->val);
7152 if (bpt->source_file != NULL)
7153 xfree (bpt->source_file);
7154 if (bpt->dll_pathname != NULL)
7155 xfree (bpt->dll_pathname);
7156 if (bpt->triggered_dll_pathname != NULL)
7157 xfree (bpt->triggered_dll_pathname);
7158 if (bpt->exec_pathname != NULL)
7159 xfree (bpt->exec_pathname);
7161 /* Be sure no bpstat's are pointing at it after it's been freed. */
7162 /* FIXME, how can we find all bpstat's?
7163 We just check stop_bpstat for now. Note that we cannot just
7164 remove bpstats pointing at bpt from the stop_bpstat list
7165 entirely, as breakpoint commands are associated with the bpstat;
7166 if we remove it here, then the later call to
7167 bpstat_do_actions (&stop_bpstat);
7168 in event-top.c won't do anything, and temporary breakpoints
7169 with commands won't work. */
7170 for (bs = stop_bpstat; bs; bs = bs->next)
7171 if (bs->breakpoint_at && bs->breakpoint_at->owner == bpt)
7173 bs->breakpoint_at = NULL;
7175 /* bs->commands will be freed later. */
7178 /* Now that breakpoint is removed from breakpoint
7179 list, update the global location list. This
7180 will remove locations that used to belong to
7181 this breakpoint. Do this before freeing
7182 the breakpoint itself, since remove_breakpoint
7183 looks at location's owner. It might be better
7184 design to have location completely self-contained,
7185 but it's not the case now. */
7186 update_global_location_list ();
7189 /* On the chance that someone will soon try again to delete this same
7190 bp, we mark it as deleted before freeing its storage. */
7191 bpt->type = bp_none;
7197 do_delete_breakpoint_cleanup (void *b)
7199 delete_breakpoint (b);
7203 make_cleanup_delete_breakpoint (struct breakpoint *b)
7205 return make_cleanup (do_delete_breakpoint_cleanup, b);
7209 delete_command (char *arg, int from_tty)
7211 struct breakpoint *b, *temp;
7217 int breaks_to_delete = 0;
7219 /* Delete all breakpoints if no argument.
7220 Do not delete internal or call-dummy breakpoints, these
7221 have to be deleted with an explicit breakpoint number argument. */
7224 if (b->type != bp_call_dummy &&
7225 b->type != bp_shlib_event &&
7226 b->type != bp_thread_event &&
7227 b->type != bp_overlay_event &&
7230 breaks_to_delete = 1;
7235 /* Ask user only if there are some breakpoints to delete. */
7237 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
7239 ALL_BREAKPOINTS_SAFE (b, temp)
7241 if (b->type != bp_call_dummy &&
7242 b->type != bp_shlib_event &&
7243 b->type != bp_thread_event &&
7244 b->type != bp_overlay_event &&
7246 delete_breakpoint (b);
7251 map_breakpoint_numbers (arg, delete_breakpoint);
7255 all_locations_are_pending (struct bp_location *loc)
7257 for (; loc; loc = loc->next)
7258 if (!loc->shlib_disabled)
7263 /* Subroutine of update_breakpoint_locations to simplify it.
7264 Return non-zero if multiple fns in list LOC have the same name.
7265 Null names are ignored. */
7268 ambiguous_names_p (struct bp_location *loc)
7270 struct bp_location *l;
7271 htab_t htab = htab_create_alloc (13, htab_hash_string,
7272 (int (*) (const void *, const void *)) streq,
7273 NULL, xcalloc, xfree);
7275 for (l = loc; l != NULL; l = l->next)
7278 const char *name = l->function_name;
7280 /* Allow for some names to be NULL, ignore them. */
7284 slot = (const char **) htab_find_slot (htab, (const void *) name,
7286 /* NOTE: We can assume slot != NULL here because xcalloc never returns
7301 update_breakpoint_locations (struct breakpoint *b,
7302 struct symtabs_and_lines sals)
7306 struct bp_location *existing_locations = b->loc;
7308 /* If there's no new locations, and all existing locations
7309 are pending, don't do anything. This optimizes
7310 the common case where all locations are in the same
7311 shared library, that was unloaded. We'd like to
7312 retain the location, so that when the library
7313 is loaded again, we don't loose the enabled/disabled
7314 status of the individual locations. */
7315 if (all_locations_are_pending (existing_locations) && sals.nelts == 0)
7320 for (i = 0; i < sals.nelts; ++i)
7322 struct bp_location *new_loc =
7323 add_location_to_breakpoint (b, b->type, &(sals.sals[i]));
7325 /* Reparse conditions, they might contain references to the
7327 if (b->cond_string != NULL)
7329 struct gdb_exception e;
7332 TRY_CATCH (e, RETURN_MASK_ERROR)
7334 new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc),
7339 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
7340 b->number, e.message);
7341 new_loc->enabled = 0;
7345 if (b->source_file != NULL)
7346 xfree (b->source_file);
7347 if (sals.sals[i].symtab == NULL)
7348 b->source_file = NULL;
7351 savestring (sals.sals[i].symtab->filename,
7352 strlen (sals.sals[i].symtab->filename));
7354 if (b->line_number == 0)
7355 b->line_number = sals.sals[i].line;
7358 /* If possible, carry over 'disable' status from existing breakpoints. */
7360 struct bp_location *e = existing_locations;
7361 /* If there are multiple breakpoints with the same function name,
7362 e.g. for inline functions, comparing function names won't work.
7363 Instead compare pc addresses; this is just a heuristic as things
7364 may have moved, but in practice it gives the correct answer
7365 often enough until a better solution is found. */
7366 int have_ambiguous_names = ambiguous_names_p (b->loc);
7368 for (; e; e = e->next)
7370 if (!e->enabled && e->function_name)
7372 struct bp_location *l = b->loc;
7373 if (have_ambiguous_names)
7375 for (; l; l = l->next)
7376 if (e->address == l->address)
7384 for (; l; l = l->next)
7385 if (l->function_name
7386 && strcmp (e->function_name, l->function_name) == 0)
7396 update_global_location_list ();
7400 /* Reset a breakpoint given it's struct breakpoint * BINT.
7401 The value we return ends up being the return value from catch_errors.
7402 Unused in this case. */
7405 breakpoint_re_set_one (void *bint)
7407 /* get past catch_errs */
7408 struct breakpoint *b = (struct breakpoint *) bint;
7412 int *not_found_ptr = ¬_found;
7413 struct symtabs_and_lines sals = {};
7414 struct symtabs_and_lines expanded;
7416 enum enable_state save_enable;
7417 struct gdb_exception e;
7423 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7427 case bp_hardware_breakpoint:
7429 case bp_catch_unload:
7430 if (b->addr_string == NULL)
7432 /* Anything without a string can't be re-set. */
7433 delete_breakpoint (b);
7437 set_language (b->language);
7438 input_radix = b->input_radix;
7440 TRY_CATCH (e, RETURN_MASK_ERROR)
7442 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL,
7447 int not_found_and_ok = 0;
7448 /* For pending breakpoints, it's expected that parsing
7449 will fail until the right shared library is loaded.
7450 User has already told to create pending breakpoints and
7451 don't need extra messages. If breakpoint is in bp_shlib_disabled
7452 state, then user already saw the message about that breakpoint
7453 being disabled, and don't want to see more errors. */
7455 && (b->condition_not_parsed
7456 || (b->loc && b->loc->shlib_disabled)
7457 || b->enable_state == bp_disabled))
7458 not_found_and_ok = 1;
7460 if (!not_found_and_ok)
7462 /* We surely don't want to warn about the same breakpoint
7463 10 times. One solution, implemented here, is disable
7464 the breakpoint on error. Another solution would be to
7465 have separate 'warning emitted' flag. Since this
7466 happens only when a binary has changed, I don't know
7467 which approach is better. */
7468 b->enable_state = bp_disabled;
7469 throw_exception (e);
7476 gdb_assert (sals.nelts == 1);
7477 resolve_sal_pc (&sals.sals[0]);
7478 if (b->condition_not_parsed && s && s[0])
7480 char *cond_string = 0;
7482 find_condition_and_thread (s, sals.sals[0].pc,
7483 &cond_string, &thread);
7485 b->cond_string = cond_string;
7487 b->condition_not_parsed = 0;
7489 expanded = expand_line_sal_maybe (sals.sals[0]);
7490 update_breakpoint_locations (b, expanded);
7496 case bp_hardware_watchpoint:
7497 case bp_read_watchpoint:
7498 case bp_access_watchpoint:
7499 /* Watchpoint can be either on expression using entirely global variables,
7500 or it can be on local variables.
7502 Watchpoints of the first kind are never auto-deleted, and even persist
7503 across program restarts. Since they can use variables from shared
7504 libraries, we need to reparse expression as libraries are loaded
7507 Watchpoints on local variables can also change meaning as result
7508 of solib event. For example, if a watchpoint uses both a local and
7509 a global variables in expression, it's a local watchpoint, but
7510 unloading of a shared library will make the expression invalid.
7511 This is not a very common use case, but we still re-evaluate
7512 expression, to avoid surprises to the user.
7514 Note that for local watchpoints, we re-evaluate it only if
7515 watchpoints frame id is still valid. If it's not, it means
7516 the watchpoint is out of scope and will be deleted soon. In fact,
7517 I'm not sure we'll ever be called in this case.
7519 If a local watchpoint's frame id is still valid, then
7520 b->exp_valid_block is likewise valid, and we can safely use it.
7522 Don't do anything about disabled watchpoints, since they will
7523 be reevaluated again when enabled. */
7524 update_watchpoint (b, 1 /* reparse */);
7526 /* We needn't really do anything to reset these, since the mask
7527 that requests them is unaffected by e.g., new libraries being
7530 case bp_catch_vfork:
7535 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type);
7537 /* Delete overlay event breakpoints; they will be reset later by
7538 breakpoint_re_set. */
7539 case bp_overlay_event:
7540 delete_breakpoint (b);
7543 /* This breakpoint is special, it's set up when the inferior
7544 starts and we really don't want to touch it. */
7545 case bp_shlib_event:
7547 /* Like bp_shlib_event, this breakpoint type is special.
7548 Once it is set up, we do not want to touch it. */
7549 case bp_thread_event:
7551 /* Keep temporary breakpoints, which can be encountered when we step
7552 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7553 Otherwise these should have been blown away via the cleanup chain
7554 or by breakpoint_init_inferior when we rerun the executable. */
7557 case bp_watchpoint_scope:
7559 case bp_step_resume:
7561 case bp_longjmp_resume:
7568 /* Re-set all breakpoints after symbols have been re-loaded. */
7570 breakpoint_re_set (void)
7572 struct breakpoint *b, *temp;
7573 enum language save_language;
7574 int save_input_radix;
7576 save_language = current_language->la_language;
7577 save_input_radix = input_radix;
7578 ALL_BREAKPOINTS_SAFE (b, temp)
7580 /* Format possible error msg */
7581 char *message = xstrprintf ("Error in re-setting breakpoint %d: ",
7583 struct cleanup *cleanups = make_cleanup (xfree, message);
7584 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
7585 do_cleanups (cleanups);
7587 set_language (save_language);
7588 input_radix = save_input_radix;
7590 create_overlay_event_breakpoint ("_ovly_debug_event");
7593 /* Reset the thread number of this breakpoint:
7595 - If the breakpoint is for all threads, leave it as-is.
7596 - Else, reset it to the current thread for inferior_ptid. */
7598 breakpoint_re_set_thread (struct breakpoint *b)
7600 if (b->thread != -1)
7602 if (in_thread_list (inferior_ptid))
7603 b->thread = pid_to_thread_id (inferior_ptid);
7607 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7608 If from_tty is nonzero, it prints a message to that effect,
7609 which ends with a period (no newline). */
7612 set_ignore_count (int bptnum, int count, int from_tty)
7614 struct breakpoint *b;
7620 if (b->number == bptnum)
7622 b->ignore_count = count;
7626 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7628 else if (count == 1)
7629 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7632 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7635 breakpoints_changed ();
7636 breakpoint_modify_event (b->number);
7640 error (_("No breakpoint number %d."), bptnum);
7643 /* Clear the ignore counts of all breakpoints. */
7645 breakpoint_clear_ignore_counts (void)
7647 struct breakpoint *b;
7650 b->ignore_count = 0;
7653 /* Command to set ignore-count of breakpoint N to COUNT. */
7656 ignore_command (char *args, int from_tty)
7662 error_no_arg (_("a breakpoint number"));
7664 num = get_number (&p);
7666 error (_("bad breakpoint number: '%s'"), args);
7668 error (_("Second argument (specified ignore-count) is missing."));
7670 set_ignore_count (num,
7671 longest_to_int (value_as_long (parse_and_eval (p))),
7674 printf_filtered ("\n");
7677 /* Call FUNCTION on each of the breakpoints
7678 whose numbers are given in ARGS. */
7681 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *))
7686 struct breakpoint *b, *tmp;
7690 error_no_arg (_("one or more breakpoint numbers"));
7697 num = get_number_or_range (&p1);
7700 warning (_("bad breakpoint number at or near '%s'"), p);
7704 ALL_BREAKPOINTS_SAFE (b, tmp)
7705 if (b->number == num)
7707 struct breakpoint *related_breakpoint = b->related_breakpoint;
7710 if (related_breakpoint)
7711 function (related_breakpoint);
7715 printf_unfiltered (_("No breakpoint number %d.\n"), num);
7721 static struct bp_location *
7722 find_location_by_number (char *number)
7724 char *dot = strchr (number, '.');
7728 struct breakpoint *b;
7729 struct bp_location *loc;
7734 bp_num = get_number_or_range (&p1);
7736 error (_("Bad breakpoint number '%s'"), number);
7739 if (b->number == bp_num)
7744 if (!b || b->number != bp_num)
7745 error (_("Bad breakpoint number '%s'"), number);
7748 loc_num = get_number_or_range (&p1);
7750 error (_("Bad breakpoint location number '%s'"), number);
7754 for (;loc_num && loc; --loc_num, loc = loc->next)
7757 error (_("Bad breakpoint location number '%s'"), dot+1);
7763 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7764 If from_tty is nonzero, it prints a message to that effect,
7765 which ends with a period (no newline). */
7768 disable_breakpoint (struct breakpoint *bpt)
7770 /* Never disable a watchpoint scope breakpoint; we want to
7771 hit them when we leave scope so we can delete both the
7772 watchpoint and its scope breakpoint at that time. */
7773 if (bpt->type == bp_watchpoint_scope)
7776 /* You can't disable permanent breakpoints. */
7777 if (bpt->enable_state == bp_permanent)
7780 bpt->enable_state = bp_disabled;
7782 update_global_location_list ();
7784 if (deprecated_modify_breakpoint_hook)
7785 deprecated_modify_breakpoint_hook (bpt);
7786 breakpoint_modify_event (bpt->number);
7790 disable_command (char *args, int from_tty)
7792 struct breakpoint *bpt;
7794 ALL_BREAKPOINTS (bpt)
7798 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
7803 case bp_catch_unload:
7805 case bp_catch_vfork:
7807 case bp_hardware_breakpoint:
7809 case bp_hardware_watchpoint:
7810 case bp_read_watchpoint:
7811 case bp_access_watchpoint:
7812 disable_breakpoint (bpt);
7816 else if (strchr (args, '.'))
7818 struct bp_location *loc = find_location_by_number (args);
7821 update_global_location_list ();
7824 map_breakpoint_numbers (args, disable_breakpoint);
7828 do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition)
7830 int target_resources_ok, other_type_used;
7833 if (bpt->type == bp_hardware_breakpoint)
7836 i = hw_breakpoint_used_count ();
7837 target_resources_ok =
7838 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
7840 if (target_resources_ok == 0)
7841 error (_("No hardware breakpoint support in the target."));
7842 else if (target_resources_ok < 0)
7843 error (_("Hardware breakpoints used exceeds limit."));
7846 if (bpt->type == bp_watchpoint ||
7847 bpt->type == bp_hardware_watchpoint ||
7848 bpt->type == bp_read_watchpoint ||
7849 bpt->type == bp_access_watchpoint)
7851 struct frame_id saved_frame_id;
7853 saved_frame_id = get_frame_id (get_selected_frame (NULL));
7854 if (bpt->exp_valid_block != NULL)
7856 struct frame_info *fr =
7857 fr = frame_find_by_id (bpt->watchpoint_frame);
7860 printf_filtered (_("\
7861 Cannot enable watchpoint %d because the block in which its expression\n\
7862 is valid is not currently in scope.\n"), bpt->number);
7869 value_free (bpt->val);
7870 mark = value_mark ();
7871 fetch_watchpoint_value (bpt->exp, &bpt->val, NULL, NULL);
7873 release_value (bpt->val);
7876 if (bpt->type == bp_hardware_watchpoint ||
7877 bpt->type == bp_read_watchpoint ||
7878 bpt->type == bp_access_watchpoint)
7880 int i = hw_watchpoint_used_count (bpt->type, &other_type_used);
7881 int mem_cnt = can_use_hardware_watchpoint (bpt->val);
7883 /* Hack around 'unused var' error for some targets here */
7884 (void) mem_cnt, (void) i;
7885 target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7886 bpt->type, i + mem_cnt, other_type_used);
7887 /* we can consider of type is bp_hardware_watchpoint, convert to
7888 bp_watchpoint in the following condition */
7889 if (target_resources_ok < 0)
7891 printf_filtered (_("\
7892 Cannot enable watchpoint %d because target watch resources\n\
7893 have been allocated for other watchpoints.\n"), bpt->number);
7894 value_free_to_mark (mark);
7899 select_frame (frame_find_by_id (saved_frame_id));
7900 value_free_to_mark (mark);
7903 if (bpt->enable_state != bp_permanent)
7904 bpt->enable_state = bp_enabled;
7905 bpt->disposition = disposition;
7906 update_global_location_list ();
7907 breakpoints_changed ();
7909 if (deprecated_modify_breakpoint_hook)
7910 deprecated_modify_breakpoint_hook (bpt);
7911 breakpoint_modify_event (bpt->number);
7916 enable_breakpoint (struct breakpoint *bpt)
7918 do_enable_breakpoint (bpt, bpt->disposition);
7921 /* The enable command enables the specified breakpoints (or all defined
7922 breakpoints) so they once again become (or continue to be) effective
7923 in stopping the inferior. */
7926 enable_command (char *args, int from_tty)
7928 struct breakpoint *bpt;
7930 ALL_BREAKPOINTS (bpt)
7934 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
7939 case bp_catch_unload:
7941 case bp_catch_vfork:
7943 case bp_hardware_breakpoint:
7945 case bp_hardware_watchpoint:
7946 case bp_read_watchpoint:
7947 case bp_access_watchpoint:
7948 enable_breakpoint (bpt);
7952 else if (strchr (args, '.'))
7954 struct bp_location *loc = find_location_by_number (args);
7957 update_global_location_list ();
7960 map_breakpoint_numbers (args, enable_breakpoint);
7964 enable_once_breakpoint (struct breakpoint *bpt)
7966 do_enable_breakpoint (bpt, disp_disable);
7970 enable_once_command (char *args, int from_tty)
7972 map_breakpoint_numbers (args, enable_once_breakpoint);
7976 enable_delete_breakpoint (struct breakpoint *bpt)
7978 do_enable_breakpoint (bpt, disp_del);
7982 enable_delete_command (char *args, int from_tty)
7984 map_breakpoint_numbers (args, enable_delete_breakpoint);
7988 set_breakpoint_cmd (char *args, int from_tty)
7993 show_breakpoint_cmd (char *args, int from_tty)
7997 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7999 struct symtabs_and_lines
8000 decode_line_spec_1 (char *string, int funfirstline)
8002 struct symtabs_and_lines sals;
8004 error (_("Empty line specification."));
8005 if (default_breakpoint_valid)
8006 sals = decode_line_1 (&string, funfirstline,
8007 default_breakpoint_symtab,
8008 default_breakpoint_line,
8009 (char ***) NULL, NULL);
8011 sals = decode_line_1 (&string, funfirstline,
8012 (struct symtab *) NULL, 0, (char ***) NULL, NULL);
8014 error (_("Junk at end of line specification: %s"), string);
8018 /* Create and insert a raw software breakpoint at PC. Return an
8019 identifier, which should be used to remove the breakpoint later.
8020 In general, places which call this should be using something on the
8021 breakpoint chain instead; this function should be eliminated
8025 deprecated_insert_raw_breakpoint (CORE_ADDR pc)
8027 struct bp_target_info *bp_tgt;
8029 bp_tgt = xmalloc (sizeof (struct bp_target_info));
8030 memset (bp_tgt, 0, sizeof (struct bp_target_info));
8032 bp_tgt->placed_address = pc;
8033 if (target_insert_breakpoint (bp_tgt) != 0)
8035 /* Could not insert the breakpoint. */
8043 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
8046 deprecated_remove_raw_breakpoint (void *bp)
8048 struct bp_target_info *bp_tgt = bp;
8051 ret = target_remove_breakpoint (bp_tgt);
8057 /* One (or perhaps two) breakpoints used for software single stepping. */
8059 static void *single_step_breakpoints[2];
8061 /* Create and insert a breakpoint for software single step. */
8064 insert_single_step_breakpoint (CORE_ADDR next_pc)
8068 if (single_step_breakpoints[0] == NULL)
8069 bpt_p = &single_step_breakpoints[0];
8072 gdb_assert (single_step_breakpoints[1] == NULL);
8073 bpt_p = &single_step_breakpoints[1];
8076 /* NOTE drow/2006-04-11: A future improvement to this function would be
8077 to only create the breakpoints once, and actually put them on the
8078 breakpoint chain. That would let us use set_raw_breakpoint. We could
8079 adjust the addresses each time they were needed. Doing this requires
8080 corresponding changes elsewhere where single step breakpoints are
8081 handled, however. So, for now, we use this. */
8083 *bpt_p = deprecated_insert_raw_breakpoint (next_pc);
8085 error (_("Could not insert single-step breakpoint at 0x%s"),
8086 paddr_nz (next_pc));
8089 /* Remove and delete any breakpoints used for software single step. */
8092 remove_single_step_breakpoints (void)
8094 gdb_assert (single_step_breakpoints[0] != NULL);
8096 /* See insert_single_step_breakpoint for more about this deprecated
8098 deprecated_remove_raw_breakpoint (single_step_breakpoints[0]);
8099 single_step_breakpoints[0] = NULL;
8101 if (single_step_breakpoints[1] != NULL)
8103 deprecated_remove_raw_breakpoint (single_step_breakpoints[1]);
8104 single_step_breakpoints[1] = NULL;
8108 /* Check whether a software single-step breakpoint is inserted at PC. */
8111 single_step_breakpoint_inserted_here_p (CORE_ADDR pc)
8115 for (i = 0; i < 2; i++)
8117 struct bp_target_info *bp_tgt = single_step_breakpoints[i];
8118 if (bp_tgt && bp_tgt->placed_address == pc)
8125 int breakpoints_always_inserted_mode (void)
8127 return always_inserted_mode;
8131 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
8132 It is defined as a macro to prevent duplication.
8133 COMMAND should be a string constant containing the name of the command. */
8134 #define BREAK_ARGS_HELP(command) \
8135 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
8136 LOCATION may be a line number, function name, or \"*\" and an address.\n\
8137 If a line number is specified, break at start of code for that line.\n\
8138 If a function is specified, break at start of code for that function.\n\
8139 If an address is specified, break at that exact address.\n\
8140 With no LOCATION, uses current execution address of selected stack frame.\n\
8141 This is useful for breaking on return to a stack frame.\n\
8143 THREADNUM is the number from \"info threads\".\n\
8144 CONDITION is a boolean expression.\n\
8146 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
8148 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
8151 _initialize_breakpoint (void)
8153 static struct cmd_list_element *breakpoint_set_cmdlist;
8154 static struct cmd_list_element *breakpoint_show_cmdlist;
8155 struct cmd_list_element *c;
8157 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
8159 breakpoint_chain = 0;
8160 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
8161 before a breakpoint is set. */
8162 breakpoint_count = 0;
8164 add_com ("ignore", class_breakpoint, ignore_command, _("\
8165 Set ignore-count of breakpoint number N to COUNT.\n\
8166 Usage is `ignore N COUNT'."));
8168 add_com_alias ("bc", "ignore", class_breakpoint, 1);
8170 add_com ("commands", class_breakpoint, commands_command, _("\
8171 Set commands to be executed when a breakpoint is hit.\n\
8172 Give breakpoint number as argument after \"commands\".\n\
8173 With no argument, the targeted breakpoint is the last one set.\n\
8174 The commands themselves follow starting on the next line.\n\
8175 Type a line containing \"end\" to indicate the end of them.\n\
8176 Give \"silent\" as the first line to make the breakpoint silent;\n\
8177 then no output is printed when it is hit, except what the commands print."));
8179 add_com ("condition", class_breakpoint, condition_command, _("\
8180 Specify breakpoint number N to break only if COND is true.\n\
8181 Usage is `condition N COND', where N is an integer and COND is an\n\
8182 expression to be evaluated whenever breakpoint N is reached."));
8184 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
8185 Set a temporary breakpoint.\n\
8186 Like \"break\" except the breakpoint is only temporary,\n\
8187 so it will be deleted when hit. Equivalent to \"break\" followed\n\
8188 by using \"enable delete\" on the breakpoint number.\n\
8190 BREAK_ARGS_HELP ("tbreak")));
8191 set_cmd_completer (c, location_completer);
8193 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
8194 Set a hardware assisted breakpoint.\n\
8195 Like \"break\" except the breakpoint requires hardware support,\n\
8196 some target hardware may not have this support.\n\
8198 BREAK_ARGS_HELP ("hbreak")));
8199 set_cmd_completer (c, location_completer);
8201 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
8202 Set a temporary hardware assisted breakpoint.\n\
8203 Like \"hbreak\" except the breakpoint is only temporary,\n\
8204 so it will be deleted when hit.\n\
8206 BREAK_ARGS_HELP ("thbreak")));
8207 set_cmd_completer (c, location_completer);
8209 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
8210 Enable some breakpoints.\n\
8211 Give breakpoint numbers (separated by spaces) as arguments.\n\
8212 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8213 This is used to cancel the effect of the \"disable\" command.\n\
8214 With a subcommand you can enable temporarily."),
8215 &enablelist, "enable ", 1, &cmdlist);
8217 add_com ("ab", class_breakpoint, enable_command, _("\
8218 Enable some breakpoints.\n\
8219 Give breakpoint numbers (separated by spaces) as arguments.\n\
8220 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8221 This is used to cancel the effect of the \"disable\" command.\n\
8222 With a subcommand you can enable temporarily."));
8224 add_com_alias ("en", "enable", class_breakpoint, 1);
8226 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
8227 Enable some breakpoints.\n\
8228 Give breakpoint numbers (separated by spaces) as arguments.\n\
8229 This is used to cancel the effect of the \"disable\" command.\n\
8230 May be abbreviated to simply \"enable\".\n"),
8231 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
8233 add_cmd ("once", no_class, enable_once_command, _("\
8234 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8235 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8238 add_cmd ("delete", no_class, enable_delete_command, _("\
8239 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8240 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8243 add_cmd ("delete", no_class, enable_delete_command, _("\
8244 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8245 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8248 add_cmd ("once", no_class, enable_once_command, _("\
8249 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8250 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8253 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
8254 Disable some breakpoints.\n\
8255 Arguments are breakpoint numbers with spaces in between.\n\
8256 To disable all breakpoints, give no argument.\n\
8257 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8258 &disablelist, "disable ", 1, &cmdlist);
8259 add_com_alias ("dis", "disable", class_breakpoint, 1);
8260 add_com_alias ("disa", "disable", class_breakpoint, 1);
8262 add_com ("sb", class_breakpoint, disable_command, _("\
8263 Disable some breakpoints.\n\
8264 Arguments are breakpoint numbers with spaces in between.\n\
8265 To disable all breakpoints, give no argument.\n\
8266 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8268 add_cmd ("breakpoints", class_alias, disable_command, _("\
8269 Disable some breakpoints.\n\
8270 Arguments are breakpoint numbers with spaces in between.\n\
8271 To disable all breakpoints, give no argument.\n\
8272 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8273 This command may be abbreviated \"disable\"."),
8276 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
8277 Delete some breakpoints or auto-display expressions.\n\
8278 Arguments are breakpoint numbers with spaces in between.\n\
8279 To delete all breakpoints, give no argument.\n\
8281 Also a prefix command for deletion of other GDB objects.\n\
8282 The \"unset\" command is also an alias for \"delete\"."),
8283 &deletelist, "delete ", 1, &cmdlist);
8284 add_com_alias ("d", "delete", class_breakpoint, 1);
8285 add_com_alias ("del", "delete", class_breakpoint, 1);
8287 add_com ("db", class_breakpoint, delete_command, _("\
8288 Delete some breakpoints.\n\
8289 Arguments are breakpoint numbers with spaces in between.\n\
8290 To delete all breakpoints, give no argument.\n"));
8292 add_cmd ("breakpoints", class_alias, delete_command, _("\
8293 Delete some breakpoints or auto-display expressions.\n\
8294 Arguments are breakpoint numbers with spaces in between.\n\
8295 To delete all breakpoints, give no argument.\n\
8296 This command may be abbreviated \"delete\"."),
8299 add_com ("clear", class_breakpoint, clear_command, _("\
8300 Clear breakpoint at specified line or function.\n\
8301 Argument may be line number, function name, or \"*\" and an address.\n\
8302 If line number is specified, all breakpoints in that line are cleared.\n\
8303 If function is specified, breakpoints at beginning of function are cleared.\n\
8304 If an address is specified, breakpoints at that address are cleared.\n\
8306 With no argument, clears all breakpoints in the line that the selected frame\n\
8309 See also the \"delete\" command which clears breakpoints by number."));
8311 c = add_com ("break", class_breakpoint, break_command, _("\
8312 Set breakpoint at specified line or function.\n"
8313 BREAK_ARGS_HELP ("break")));
8314 set_cmd_completer (c, location_completer);
8316 add_com_alias ("b", "break", class_run, 1);
8317 add_com_alias ("br", "break", class_run, 1);
8318 add_com_alias ("bre", "break", class_run, 1);
8319 add_com_alias ("brea", "break", class_run, 1);
8323 add_com_alias ("ba", "break", class_breakpoint, 1);
8324 add_com_alias ("bu", "ubreak", class_breakpoint, 1);
8329 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
8330 Break in function/address or break at a line in the current file."),
8331 &stoplist, "stop ", 1, &cmdlist);
8332 add_cmd ("in", class_breakpoint, stopin_command,
8333 _("Break in function or address."), &stoplist);
8334 add_cmd ("at", class_breakpoint, stopat_command,
8335 _("Break at a line in the current file."), &stoplist);
8336 add_com ("status", class_info, breakpoints_info, _("\
8337 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8338 The \"Type\" column indicates one of:\n\
8339 \tbreakpoint - normal breakpoint\n\
8340 \twatchpoint - watchpoint\n\
8341 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8342 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8343 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8344 address and file/line number respectively.\n\
8346 Convenience variable \"$_\" and default examine address for \"x\"\n\
8347 are set to the address of the last breakpoint listed unless the command\n\
8348 is prefixed with \"server \".\n\n\
8349 Convenience variable \"$bpnum\" contains the number of the last\n\
8353 add_info ("breakpoints", breakpoints_info, _("\
8354 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8355 The \"Type\" column indicates one of:\n\
8356 \tbreakpoint - normal breakpoint\n\
8357 \twatchpoint - watchpoint\n\
8358 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8359 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8360 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8361 address and file/line number respectively.\n\
8363 Convenience variable \"$_\" and default examine address for \"x\"\n\
8364 are set to the address of the last breakpoint listed unless the command\n\
8365 is prefixed with \"server \".\n\n\
8366 Convenience variable \"$bpnum\" contains the number of the last\n\
8370 add_com ("lb", class_breakpoint, breakpoints_info, _("\
8371 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8372 The \"Type\" column indicates one of:\n\
8373 \tbreakpoint - normal breakpoint\n\
8374 \twatchpoint - watchpoint\n\
8375 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8376 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8377 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8378 address and file/line number respectively.\n\
8380 Convenience variable \"$_\" and default examine address for \"x\"\n\
8381 are set to the address of the last breakpoint listed unless the command\n\
8382 is prefixed with \"server \".\n\n\
8383 Convenience variable \"$bpnum\" contains the number of the last\n\
8386 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
8387 Status of all breakpoints, or breakpoint number NUMBER.\n\
8388 The \"Type\" column indicates one of:\n\
8389 \tbreakpoint - normal breakpoint\n\
8390 \twatchpoint - watchpoint\n\
8391 \tlongjmp - internal breakpoint used to step through longjmp()\n\
8392 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8393 \tuntil - internal breakpoint used by the \"until\" command\n\
8394 \tfinish - internal breakpoint used by the \"finish\" command\n\
8395 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8396 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8397 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8398 address and file/line number respectively.\n\
8400 Convenience variable \"$_\" and default examine address for \"x\"\n\
8401 are set to the address of the last breakpoint listed unless the command\n\
8402 is prefixed with \"server \".\n\n\
8403 Convenience variable \"$bpnum\" contains the number of the last\n\
8405 &maintenanceinfolist);
8407 add_com ("catch", class_breakpoint, catch_command, _("\
8408 Set catchpoints to catch events.\n\
8409 Raised signals may be caught:\n\
8410 \tcatch signal - all signals\n\
8411 \tcatch signal <signame> - a particular signal\n\
8412 Raised exceptions may be caught:\n\
8413 \tcatch throw - all exceptions, when thrown\n\
8414 \tcatch throw <exceptname> - a particular exception, when thrown\n\
8415 \tcatch catch - all exceptions, when caught\n\
8416 \tcatch catch <exceptname> - a particular exception, when caught\n\
8417 Thread or process events may be caught:\n\
8418 \tcatch thread_start - any threads, just after creation\n\
8419 \tcatch thread_exit - any threads, just before expiration\n\
8420 \tcatch thread_join - any threads, just after joins\n\
8421 Process events may be caught:\n\
8422 \tcatch start - any processes, just after creation\n\
8423 \tcatch exit - any processes, just before expiration\n\
8424 \tcatch fork - calls to fork()\n\
8425 \tcatch vfork - calls to vfork()\n\
8426 \tcatch exec - calls to exec()\n\
8427 Dynamically-linked library events may be caught:\n\
8428 \tcatch load - loads of any library\n\
8429 \tcatch load <libname> - loads of a particular library\n\
8430 \tcatch unload - unloads of any library\n\
8431 \tcatch unload <libname> - unloads of a particular library\n\
8432 The act of your program's execution stopping may also be caught:\n\
8434 C++ exceptions may be caught:\n\
8435 \tcatch throw - all exceptions, when thrown\n\
8436 \tcatch catch - all exceptions, when caught\n\
8437 Ada exceptions may be caught:\n\
8438 \tcatch exception - all exceptions, when raised\n\
8439 \tcatch exception <name> - a particular exception, when raised\n\
8440 \tcatch exception unhandled - all unhandled exceptions, when raised\n\
8441 \tcatch assert - all failed assertions, when raised\n\
8443 Do \"help set follow-fork-mode\" for info on debugging your program\n\
8444 after a fork or vfork is caught.\n\n\
8445 Do \"help breakpoints\" for info on other commands dealing with breakpoints."));
8447 add_com ("tcatch", class_breakpoint, tcatch_command, _("\
8448 Set temporary catchpoints to catch events.\n\
8449 Args like \"catch\" command.\n\
8450 Like \"catch\" except the catchpoint is only temporary,\n\
8451 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
8452 by using \"enable delete\" on the catchpoint number."));
8454 c = add_com ("watch", class_breakpoint, watch_command, _("\
8455 Set a watchpoint for an expression.\n\
8456 A watchpoint stops execution of your program whenever the value of\n\
8457 an expression changes."));
8458 set_cmd_completer (c, location_completer);
8460 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
8461 Set a read watchpoint for an expression.\n\
8462 A watchpoint stops execution of your program whenever the value of\n\
8463 an expression is read."));
8464 set_cmd_completer (c, location_completer);
8466 c = add_com ("awatch", class_breakpoint, awatch_command, _("\
8467 Set a watchpoint for an expression.\n\
8468 A watchpoint stops execution of your program whenever the value of\n\
8469 an expression is either read or written."));
8470 set_cmd_completer (c, location_completer);
8472 add_info ("watchpoints", breakpoints_info,
8473 _("Synonym for ``info breakpoints''."));
8476 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8477 respond to changes - contrary to the description. */
8478 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
8479 &can_use_hw_watchpoints, _("\
8480 Set debugger's willingness to use watchpoint hardware."), _("\
8481 Show debugger's willingness to use watchpoint hardware."), _("\
8482 If zero, gdb will not use hardware for new watchpoints, even if\n\
8483 such is available. (However, any hardware watchpoints that were\n\
8484 created before setting this to nonzero, will continue to use watchpoint\n\
8487 show_can_use_hw_watchpoints,
8488 &setlist, &showlist);
8490 can_use_hw_watchpoints = 1;
8492 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
8493 Breakpoint specific settings\n\
8494 Configure various breakpoint-specific variables such as\n\
8495 pending breakpoint behavior"),
8496 &breakpoint_set_cmdlist, "set breakpoint ",
8497 0/*allow-unknown*/, &setlist);
8498 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
8499 Breakpoint specific settings\n\
8500 Configure various breakpoint-specific variables such as\n\
8501 pending breakpoint behavior"),
8502 &breakpoint_show_cmdlist, "show breakpoint ",
8503 0/*allow-unknown*/, &showlist);
8505 add_setshow_auto_boolean_cmd ("pending", no_class,
8506 &pending_break_support, _("\
8507 Set debugger's behavior regarding pending breakpoints."), _("\
8508 Show debugger's behavior regarding pending breakpoints."), _("\
8509 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8510 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8511 an error. If auto, an unrecognized breakpoint location results in a\n\
8512 user-query to see if a pending breakpoint should be created."),
8514 show_pending_break_support,
8515 &breakpoint_set_cmdlist,
8516 &breakpoint_show_cmdlist);
8518 pending_break_support = AUTO_BOOLEAN_AUTO;
8520 add_setshow_boolean_cmd ("auto-hw", no_class,
8521 &automatic_hardware_breakpoints, _("\
8522 Set automatic usage of hardware breakpoints."), _("\
8523 Show automatic usage of hardware breakpoints."), _("\
8524 If set, the debugger will automatically use hardware breakpoints for\n\
8525 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
8526 a warning will be emitted for such breakpoints."),
8528 show_automatic_hardware_breakpoints,
8529 &breakpoint_set_cmdlist,
8530 &breakpoint_show_cmdlist);
8532 add_setshow_boolean_cmd ("always-inserted", class_support,
8533 &always_inserted_mode, _("\
8534 Set mode for inserting breakpoints."), _("\
8535 Show mode for inserting breakpoints."), _("\
8536 When this mode is off (which is the default), breakpoints are inserted in\n\
8537 inferior when it is resumed, and removed when execution stops. When this\n\
8538 mode is on, breakpoints are inserted immediately and removed only when\n\
8539 the user deletes the breakpoint."),
8541 &show_always_inserted_mode,
8542 &breakpoint_set_cmdlist,
8543 &breakpoint_show_cmdlist);
8545 automatic_hardware_breakpoints = 1;