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, 2009 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/>. */
23 #include "arch-utils.h"
28 #include "breakpoint.h"
29 #include "tracepoint.h"
31 #include "expression.h"
37 #include "gdbthread.h"
40 #include "gdb_string.h"
47 #include "completer.h"
50 #include "cli/cli-script.h"
51 #include "gdb_assert.h"
56 #include "exceptions.h"
63 #include "xml-syscall.h"
65 /* readline include files */
66 #include "readline/readline.h"
67 #include "readline/history.h"
69 /* readline defines this. */
72 #include "mi/mi-common.h"
74 /* Arguments to pass as context to some catch command handlers. */
75 #define CATCH_PERMANENT ((void *) (uintptr_t) 0)
76 #define CATCH_TEMPORARY ((void *) (uintptr_t) 1)
78 /* Prototypes for local functions. */
80 static void enable_delete_command (char *, int);
82 static void enable_delete_breakpoint (struct breakpoint *);
84 static void enable_once_command (char *, int);
86 static void enable_once_breakpoint (struct breakpoint *);
88 static void disable_command (char *, int);
90 static void enable_command (char *, int);
92 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint *));
94 static void ignore_command (char *, int);
96 static int breakpoint_re_set_one (void *);
98 static void clear_command (char *, int);
100 static void catch_command (char *, int);
102 static void watch_command (char *, int);
104 static int can_use_hardware_watchpoint (struct value *);
106 static void break_command_1 (char *, int, int);
108 static void mention (struct breakpoint *);
110 /* This function is used in gdbtk sources and thus can not be made static. */
111 struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch,
112 struct symtab_and_line,
115 static void check_duplicates (struct breakpoint *);
117 static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
119 static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch,
123 static void describe_other_breakpoints (struct gdbarch *,
124 struct program_space *, CORE_ADDR,
125 struct obj_section *, int);
127 static int breakpoint_address_match (struct address_space *aspace1,
129 struct address_space *aspace2,
132 static void breakpoints_info (char *, int);
134 static void breakpoint_1 (int, int);
136 static bpstat bpstat_alloc (const struct bp_location *, bpstat);
138 static int breakpoint_cond_eval (void *);
140 static void cleanup_executing_breakpoints (void *);
142 static void commands_command (char *, int);
144 static void condition_command (char *, int);
146 static int get_number_trailer (char **, int);
148 void set_breakpoint_count (int);
157 static int remove_breakpoint (struct bp_location *, insertion_state_t);
158 static int remove_breakpoint_1 (struct bp_location *, insertion_state_t);
160 static enum print_stop_action print_it_typical (bpstat);
162 static enum print_stop_action print_bp_stop_message (bpstat bs);
164 static int watchpoint_check (void *);
166 static void maintenance_info_breakpoints (char *, int);
168 static int hw_breakpoint_used_count (void);
170 static int hw_watchpoint_used_count (enum bptype, int *);
172 static void hbreak_command (char *, int);
174 static void thbreak_command (char *, int);
176 static void watch_command_1 (char *, int, int);
178 static void rwatch_command (char *, int);
180 static void awatch_command (char *, int);
182 static void do_enable_breakpoint (struct breakpoint *, enum bpdisp);
184 static void stop_command (char *arg, int from_tty);
186 static void stopin_command (char *arg, int from_tty);
188 static void stopat_command (char *arg, int from_tty);
190 static char *ep_parse_optional_if_clause (char **arg);
192 static char *ep_parse_optional_filename (char **arg);
194 static void catch_exception_command_1 (enum exception_event_kind ex_event,
195 char *arg, int tempflag, int from_tty);
197 static void tcatch_command (char *arg, int from_tty);
199 static void ep_skip_leading_whitespace (char **s);
201 static int single_step_breakpoint_inserted_here_p (struct address_space *,
204 static void free_bp_location (struct bp_location *loc);
206 static struct bp_location *allocate_bp_location (struct breakpoint *bpt);
208 static void update_global_location_list (int);
210 static void update_global_location_list_nothrow (int);
212 static int is_hardware_watchpoint (struct breakpoint *bpt);
214 static void insert_breakpoint_locations (void);
216 static int syscall_catchpoint_p (struct breakpoint *b);
218 static void tracepoints_info (char *, int);
220 static void delete_trace_command (char *, int);
222 static void enable_trace_command (char *, int);
224 static void disable_trace_command (char *, int);
226 static void trace_pass_command (char *, int);
228 static void skip_prologue_sal (struct symtab_and_line *sal);
231 /* Flag indicating that a command has proceeded the inferior past the
232 current breakpoint. */
234 static int breakpoint_proceeded;
237 bpdisp_text (enum bpdisp disp)
239 /* NOTE: the following values are a part of MI protocol and represent
240 values of 'disp' field returned when inferior stops at a breakpoint. */
241 static char *bpdisps[] = {"del", "dstp", "dis", "keep"};
242 return bpdisps[(int) disp];
245 /* Prototypes for exported functions. */
246 /* If FALSE, gdb will not use hardware support for watchpoints, even
247 if such is available. */
248 static int can_use_hw_watchpoints;
251 show_can_use_hw_watchpoints (struct ui_file *file, int from_tty,
252 struct cmd_list_element *c,
255 fprintf_filtered (file, _("\
256 Debugger's willingness to use watchpoint hardware is %s.\n"),
260 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
261 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
262 for unrecognized breakpoint locations.
263 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
264 static enum auto_boolean pending_break_support;
266 show_pending_break_support (struct ui_file *file, int from_tty,
267 struct cmd_list_element *c,
270 fprintf_filtered (file, _("\
271 Debugger's behavior regarding pending breakpoints is %s.\n"),
275 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
276 set with "break" but falling in read-only memory.
277 If 0, gdb will warn about such breakpoints, but won't automatically
278 use hardware breakpoints. */
279 static int automatic_hardware_breakpoints;
281 show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty,
282 struct cmd_list_element *c,
285 fprintf_filtered (file, _("\
286 Automatic usage of hardware breakpoints is %s.\n"),
290 /* If on, gdb will keep breakpoints inserted even as inferior is
291 stopped, and immediately insert any new breakpoints. If off, gdb
292 will insert breakpoints into inferior only when resuming it, and
293 will remove breakpoints upon stop. If auto, GDB will behave as ON
294 if in non-stop mode, and as OFF if all-stop mode.*/
296 static const char always_inserted_auto[] = "auto";
297 static const char always_inserted_on[] = "on";
298 static const char always_inserted_off[] = "off";
299 static const char *always_inserted_enums[] = {
300 always_inserted_auto,
305 static const char *always_inserted_mode = always_inserted_auto;
307 show_always_inserted_mode (struct ui_file *file, int from_tty,
308 struct cmd_list_element *c, const char *value)
310 if (always_inserted_mode == always_inserted_auto)
311 fprintf_filtered (file, _("\
312 Always inserted breakpoint mode is %s (currently %s).\n"),
314 breakpoints_always_inserted_mode () ? "on" : "off");
316 fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), value);
320 breakpoints_always_inserted_mode (void)
322 return (always_inserted_mode == always_inserted_on
323 || (always_inserted_mode == always_inserted_auto && non_stop));
326 void _initialize_breakpoint (void);
328 /* Are we executing breakpoint commands? */
329 static int executing_breakpoint_commands;
331 /* Are overlay event breakpoints enabled? */
332 static int overlay_events_enabled;
334 /* Walk the following statement or block through all breakpoints.
335 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
338 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
340 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
341 for (B = breakpoint_chain; \
342 B ? (TMP=B->next, 1): 0; \
345 /* Similar iterators for the low-level breakpoints. */
347 #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->global_next)
349 #define ALL_BP_LOCATIONS_SAFE(B,TMP) \
350 for (B = bp_location_chain; \
351 B ? (TMP=B->global_next, 1): 0; \
354 /* Iterator for tracepoints only. */
356 #define ALL_TRACEPOINTS(B) \
357 for (B = breakpoint_chain; B; B = B->next) \
358 if ((B)->type == bp_tracepoint)
360 /* Chains of all breakpoints defined. */
362 struct breakpoint *breakpoint_chain;
364 struct bp_location *bp_location_chain;
366 /* The locations that no longer correspond to any breakpoint,
367 unlinked from bp_location_chain, but for which a hit
368 may still be reported by a target. */
369 VEC(bp_location_p) *moribund_locations = NULL;
371 /* Number of last breakpoint made. */
373 int breakpoint_count;
375 /* Number of last tracepoint made. */
377 int tracepoint_count;
379 /* Return whether a breakpoint is an active enabled breakpoint. */
381 breakpoint_enabled (struct breakpoint *b)
383 return (b->enable_state == bp_enabled);
386 /* Set breakpoint count to NUM. */
389 set_breakpoint_count (int num)
391 breakpoint_count = num;
392 set_internalvar_integer (lookup_internalvar ("bpnum"), num);
395 /* Used in run_command to zero the hit count when a new run starts. */
398 clear_breakpoint_hit_counts (void)
400 struct breakpoint *b;
406 /* Default address, symtab and line to put a breakpoint at
407 for "break" command with no arg.
408 if default_breakpoint_valid is zero, the other three are
409 not valid, and "break" with no arg is an error.
411 This set by print_stack_frame, which calls set_default_breakpoint. */
413 int default_breakpoint_valid;
414 CORE_ADDR default_breakpoint_address;
415 struct symtab *default_breakpoint_symtab;
416 int default_breakpoint_line;
417 struct program_space *default_breakpoint_pspace;
420 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
421 Advance *PP after the string and any trailing whitespace.
423 Currently the string can either be a number or "$" followed by the name
424 of a convenience variable. Making it an expression wouldn't work well
425 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
427 If the string is a NULL pointer, that denotes the last breakpoint.
429 TRAILER is a character which can be found after the number; most
430 commonly this is `-'. If you don't want a trailer, use \0. */
432 get_number_trailer (char **pp, int trailer)
434 int retval = 0; /* default */
438 /* Empty line means refer to the last breakpoint. */
439 return breakpoint_count;
442 /* Make a copy of the name, so we can null-terminate it
443 to pass to lookup_internalvar(). */
448 while (isalnum (*p) || *p == '_')
450 varname = (char *) alloca (p - start + 1);
451 strncpy (varname, start, p - start);
452 varname[p - start] = '\0';
453 if (get_internalvar_integer (lookup_internalvar (varname), &val))
457 printf_filtered (_("Convenience variable must have integer value.\n"));
465 while (*p >= '0' && *p <= '9')
468 /* There is no number here. (e.g. "cond a == b"). */
470 /* Skip non-numeric token */
471 while (*p && !isspace((int) *p))
473 /* Return zero, which caller must interpret as error. */
479 if (!(isspace (*p) || *p == '\0' || *p == trailer))
481 /* Trailing junk: return 0 and let caller print error msg. */
482 while (!(isspace (*p) || *p == '\0' || *p == trailer))
493 /* Like get_number_trailer, but don't allow a trailer. */
495 get_number (char **pp)
497 return get_number_trailer (pp, '\0');
500 /* Parse a number or a range.
501 * A number will be of the form handled by get_number.
502 * A range will be of the form <number1> - <number2>, and
503 * will represent all the integers between number1 and number2,
506 * While processing a range, this fuction is called iteratively;
507 * At each call it will return the next value in the range.
509 * At the beginning of parsing a range, the char pointer PP will
510 * be advanced past <number1> and left pointing at the '-' token.
511 * Subsequent calls will not advance the pointer until the range
512 * is completed. The call that completes the range will advance
513 * pointer PP past <number2>.
517 get_number_or_range (char **pp)
519 static int last_retval, end_value;
520 static char *end_ptr;
521 static int in_range = 0;
525 /* Default case: pp is pointing either to a solo number,
526 or to the first number of a range. */
527 last_retval = get_number_trailer (pp, '-');
532 /* This is the start of a range (<number1> - <number2>).
533 Skip the '-', parse and remember the second number,
534 and also remember the end of the final token. */
538 while (isspace ((int) *end_ptr))
539 end_ptr++; /* skip white space */
540 end_value = get_number (temp);
541 if (end_value < last_retval)
543 error (_("inverted range"));
545 else if (end_value == last_retval)
547 /* degenerate range (number1 == number2). Advance the
548 token pointer so that the range will be treated as a
557 error (_("negative value"));
560 /* pp points to the '-' that betokens a range. All
561 number-parsing has already been done. Return the next
562 integer value (one greater than the saved previous value).
563 Do not advance the token pointer 'pp' until the end of range
566 if (++last_retval == end_value)
568 /* End of range reached; advance token pointer. */
576 /* Return the breakpoint with the specified number, or NULL
577 if the number does not refer to an existing breakpoint. */
580 get_breakpoint (int num)
582 struct breakpoint *b;
585 if (b->number == num)
592 /* condition N EXP -- set break condition of breakpoint N to EXP. */
595 condition_command (char *arg, int from_tty)
597 struct breakpoint *b;
602 error_no_arg (_("breakpoint number"));
605 bnum = get_number (&p);
607 error (_("Bad breakpoint argument: '%s'"), arg);
610 if (b->number == bnum)
612 struct bp_location *loc = b->loc;
613 for (; loc; loc = loc->next)
621 if (b->cond_string != NULL)
622 xfree (b->cond_string);
626 b->cond_string = NULL;
628 printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum);
633 /* I don't know if it matters whether this is the string the user
634 typed in or the decompiled expression. */
635 b->cond_string = xstrdup (arg);
636 b->condition_not_parsed = 0;
637 for (loc = b->loc; loc; loc = loc->next)
641 parse_exp_1 (&arg, block_for_pc (loc->address), 0);
643 error (_("Junk at end of expression"));
646 breakpoints_changed ();
647 observer_notify_breakpoint_modified (b->number);
651 error (_("No breakpoint number %d."), bnum);
654 /* Set the command list of B to COMMANDS. */
657 breakpoint_set_commands (struct breakpoint *b, struct command_line *commands)
659 free_command_lines (&b->commands);
660 b->commands = commands;
661 breakpoints_changed ();
662 observer_notify_breakpoint_modified (b->number);
666 commands_command (char *arg, int from_tty)
668 struct breakpoint *b;
671 struct command_line *l;
673 /* If we allowed this, we would have problems with when to
674 free the storage, if we change the commands currently
677 if (executing_breakpoint_commands)
678 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
681 bnum = get_number (&p);
684 error (_("Unexpected extra arguments following breakpoint number."));
687 if (b->number == bnum)
689 char *tmpbuf = xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
691 struct cleanup *cleanups = make_cleanup (xfree, tmpbuf);
692 l = read_command_lines (tmpbuf, from_tty, 1);
693 do_cleanups (cleanups);
694 breakpoint_set_commands (b, l);
697 error (_("No breakpoint number %d."), bnum);
700 /* Like commands_command, but instead of reading the commands from
701 input stream, takes them from an already parsed command structure.
703 This is used by cli-script.c to DTRT with breakpoint commands
704 that are part of if and while bodies. */
705 enum command_control_type
706 commands_from_control_command (char *arg, struct command_line *cmd)
708 struct breakpoint *b;
712 /* If we allowed this, we would have problems with when to
713 free the storage, if we change the commands currently
716 if (executing_breakpoint_commands)
717 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
719 /* An empty string for the breakpoint number means the last
720 breakpoint, but get_number expects a NULL pointer. */
725 bnum = get_number (&p);
728 error (_("Unexpected extra arguments following breakpoint number."));
731 if (b->number == bnum)
733 free_command_lines (&b->commands);
734 if (cmd->body_count != 1)
735 error (_("Invalid \"commands\" block structure."));
736 /* We need to copy the commands because if/while will free the
737 list after it finishes execution. */
738 b->commands = copy_command_lines (cmd->body_list[0]);
739 breakpoints_changed ();
740 observer_notify_breakpoint_modified (b->number);
741 return simple_control;
743 error (_("No breakpoint number %d."), bnum);
746 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
747 by replacing any memory breakpoints with their shadowed contents. */
750 breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len)
752 struct bp_location *b;
753 CORE_ADDR bp_addr = 0;
759 if (b->owner->type == bp_none)
760 warning (_("reading through apparently deleted breakpoint #%d?"),
763 if (b->loc_type != bp_loc_software_breakpoint)
767 if (!breakpoint_address_match (b->target_info.placed_address_space, 0,
768 current_program_space->aspace, 0))
771 /* Addresses and length of the part of the breakpoint that
773 bp_addr = b->target_info.placed_address;
774 bp_size = b->target_info.shadow_len;
776 /* bp isn't valid, or doesn't shadow memory. */
779 if (bp_addr + bp_size <= memaddr)
780 /* The breakpoint is entirely before the chunk of memory we
784 if (bp_addr >= memaddr + len)
785 /* The breakpoint is entirely after the chunk of memory we are
789 /* Offset within shadow_contents. */
790 if (bp_addr < memaddr)
792 /* Only copy the second part of the breakpoint. */
793 bp_size -= memaddr - bp_addr;
794 bptoffset = memaddr - bp_addr;
798 if (bp_addr + bp_size > memaddr + len)
800 /* Only copy the first part of the breakpoint. */
801 bp_size -= (bp_addr + bp_size) - (memaddr + len);
804 memcpy (buf + bp_addr - memaddr,
805 b->target_info.shadow_contents + bptoffset, bp_size);
810 /* A wrapper function for inserting catchpoints. */
812 insert_catchpoint (struct ui_out *uo, void *args)
814 struct breakpoint *b = (struct breakpoint *) args;
817 gdb_assert (b->type == bp_catchpoint);
818 gdb_assert (b->ops != NULL && b->ops->insert != NULL);
824 is_hardware_watchpoint (struct breakpoint *bpt)
826 return (bpt->type == bp_hardware_watchpoint
827 || bpt->type == bp_read_watchpoint
828 || bpt->type == bp_access_watchpoint);
831 /* Find the current value of a watchpoint on EXP. Return the value in
832 *VALP and *RESULTP and the chain of intermediate and final values
833 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
836 If a memory error occurs while evaluating the expression, *RESULTP will
837 be set to NULL. *RESULTP may be a lazy value, if the result could
838 not be read from memory. It is used to determine whether a value
839 is user-specified (we should watch the whole value) or intermediate
840 (we should watch only the bit used to locate the final value).
842 If the final value, or any intermediate value, could not be read
843 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
844 set to any referenced values. *VALP will never be a lazy value.
845 This is the value which we store in struct breakpoint.
847 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
848 value chain. The caller must free the values individually. If
849 VAL_CHAIN is NULL, all generated values will be left on the value
853 fetch_watchpoint_value (struct expression *exp, struct value **valp,
854 struct value **resultp, struct value **val_chain)
856 struct value *mark, *new_mark, *result;
857 volatile struct gdb_exception ex;
865 /* Evaluate the expression. */
866 mark = value_mark ();
869 TRY_CATCH (ex, RETURN_MASK_ALL)
871 result = evaluate_expression (exp);
875 /* Ignore memory errors, we want watchpoints pointing at
876 inaccessible memory to still be created; otherwise, throw the
877 error to some higher catcher. */
883 throw_exception (ex);
888 new_mark = value_mark ();
889 if (mark == new_mark)
894 /* Make sure it's not lazy, so that after the target stops again we
895 have a non-lazy previous value to compare with. */
897 && (!value_lazy (result) || gdb_value_fetch_lazy (result)))
902 /* Return the chain of intermediate values. We use this to
903 decide which addresses to watch. */
904 *val_chain = new_mark;
905 value_release_to_mark (mark);
909 /* Assuming that B is a watchpoint:
910 - Reparse watchpoint expression, if REPARSE is non-zero
911 - Evaluate expression and store the result in B->val
912 - Evaluate the condition if there is one, and store the result
914 - Update the list of values that must be watched in B->loc.
916 If the watchpoint disposition is disp_del_at_next_stop, then do nothing.
917 If this is local watchpoint that is out of scope, delete it. */
919 update_watchpoint (struct breakpoint *b, int reparse)
921 int within_current_scope;
922 struct frame_id saved_frame_id;
923 struct bp_location *loc;
925 struct program_space *frame_pspace;
927 /* We don't free locations. They are stored in bp_location_chain and
928 update_global_locations will eventually delete them and remove
929 breakpoints if needed. */
932 if (b->disposition == disp_del_at_next_stop)
935 /* Save the current frame's ID so we can restore it after
936 evaluating the watchpoint expression on its own frame. */
937 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
938 took a frame parameter, so that we didn't have to change the
940 saved_frame_id = get_frame_id (get_selected_frame (NULL));
942 /* Determine if the watchpoint is within scope. */
943 if (b->exp_valid_block == NULL)
944 within_current_scope = 1;
947 struct frame_info *fi;
948 fi = frame_find_by_id (b->watchpoint_frame);
949 within_current_scope = (fi != NULL);
950 if (within_current_scope)
954 frame_pspace = get_frame_program_space (get_selected_frame (NULL));
956 if (within_current_scope && reparse)
965 b->exp = parse_exp_1 (&s, b->exp_valid_block, 0);
966 /* If the meaning of expression itself changed, the old value is
967 no longer relevant. We don't want to report a watchpoint hit
968 to the user when the old value and the new value may actually
969 be completely different objects. */
975 /* If we failed to parse the expression, for example because
976 it refers to a global variable in a not-yet-loaded shared library,
977 don't try to insert watchpoint. We don't automatically delete
978 such watchpoint, though, since failure to parse expression
979 is different from out-of-scope watchpoint. */
980 if (within_current_scope && b->exp)
982 struct value *val_chain, *v, *result, *next;
984 fetch_watchpoint_value (b->exp, &v, &result, &val_chain);
986 /* Avoid setting b->val if it's already set. The meaning of
987 b->val is 'the last value' user saw, and we should update
988 it only if we reported that last value to user. As it
989 happens, the code that reports it updates b->val directly. */
996 /* Change the type of breakpoint between hardware assisted or an
997 ordinary watchpoint depending on the hardware support and free
998 hardware slots. REPARSE is set when the inferior is started. */
999 if ((b->type == bp_watchpoint || b->type == bp_hardware_watchpoint)
1002 int i, mem_cnt, other_type_used;
1004 i = hw_watchpoint_used_count (bp_hardware_watchpoint,
1006 mem_cnt = can_use_hardware_watchpoint (val_chain);
1009 b->type = bp_watchpoint;
1012 int target_resources_ok = target_can_use_hardware_watchpoint
1013 (bp_hardware_watchpoint, i + mem_cnt, other_type_used);
1014 if (target_resources_ok <= 0)
1015 b->type = bp_watchpoint;
1017 b->type = bp_hardware_watchpoint;
1021 /* Look at each value on the value chain. */
1022 for (v = val_chain; v; v = next)
1024 /* If it's a memory location, and GDB actually needed
1025 its contents to evaluate the expression, then we
1026 must watch it. If the first value returned is
1027 still lazy, that means an error occurred reading it;
1028 watch it anyway in case it becomes readable. */
1029 if (VALUE_LVAL (v) == lval_memory
1030 && (v == val_chain || ! value_lazy (v)))
1032 struct type *vtype = check_typedef (value_type (v));
1034 /* We only watch structs and arrays if user asked
1035 for it explicitly, never if they just happen to
1036 appear in the middle of some value chain. */
1038 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1039 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1043 struct bp_location *loc, **tmp;
1045 addr = value_address (v);
1046 len = TYPE_LENGTH (value_type (v));
1048 if (b->type == bp_read_watchpoint)
1050 else if (b->type == bp_access_watchpoint)
1053 loc = allocate_bp_location (b);
1054 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
1057 loc->gdbarch = get_type_arch (value_type (v));
1059 loc->pspace = frame_pspace;
1060 loc->address = addr;
1062 loc->watchpoint_type = type;
1066 next = value_next (v);
1071 /* We just regenerated the list of breakpoint locations.
1072 The new location does not have its condition field set to anything
1073 and therefore, we must always reparse the cond_string, independently
1074 of the value of the reparse flag. */
1075 if (b->cond_string != NULL)
1077 char *s = b->cond_string;
1078 b->loc->cond = parse_exp_1 (&s, b->exp_valid_block, 0);
1081 else if (!within_current_scope)
1083 printf_filtered (_("\
1084 Watchpoint %d deleted because the program has left the block \n\
1085 in which its expression is valid.\n"),
1087 if (b->related_breakpoint)
1088 b->related_breakpoint->disposition = disp_del_at_next_stop;
1089 b->disposition = disp_del_at_next_stop;
1092 /* Restore the selected frame. */
1093 select_frame (frame_find_by_id (saved_frame_id));
1097 /* Returns 1 iff breakpoint location should be
1098 inserted in the inferior. */
1100 should_be_inserted (struct bp_location *bpt)
1102 if (!breakpoint_enabled (bpt->owner))
1105 if (bpt->owner->disposition == disp_del_at_next_stop)
1108 if (!bpt->enabled || bpt->shlib_disabled || bpt->duplicate)
1111 /* Tracepoints are inserted by the target at a time of its choosing,
1113 if (bpt->owner->type == bp_tracepoint)
1119 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
1120 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
1121 and HW_BREAKPOINT_ERROR are used to report problems.
1123 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1124 method for each breakpoint or catchpoint type. */
1126 insert_bp_location (struct bp_location *bpt,
1127 struct ui_file *tmp_error_stream,
1128 int *disabled_breaks,
1129 int *hw_breakpoint_error)
1133 if (!should_be_inserted (bpt) || bpt->inserted)
1136 /* Initialize the target-specific information. */
1137 memset (&bpt->target_info, 0, sizeof (bpt->target_info));
1138 bpt->target_info.placed_address = bpt->address;
1139 bpt->target_info.placed_address_space = bpt->pspace->aspace;
1141 if (bpt->loc_type == bp_loc_software_breakpoint
1142 || bpt->loc_type == bp_loc_hardware_breakpoint)
1144 if (bpt->owner->type != bp_hardware_breakpoint)
1146 /* If the explicitly specified breakpoint type
1147 is not hardware breakpoint, check the memory map to see
1148 if the breakpoint address is in read only memory or not.
1149 Two important cases are:
1150 - location type is not hardware breakpoint, memory
1151 is readonly. We change the type of the location to
1152 hardware breakpoint.
1153 - location type is hardware breakpoint, memory is read-write.
1154 This means we've previously made the location hardware one, but
1155 then the memory map changed, so we undo.
1157 When breakpoints are removed, remove_breakpoints will
1158 use location types we've just set here, the only possible
1159 problem is that memory map has changed during running program,
1160 but it's not going to work anyway with current gdb. */
1161 struct mem_region *mr
1162 = lookup_mem_region (bpt->target_info.placed_address);
1166 if (automatic_hardware_breakpoints)
1169 enum bp_loc_type new_type;
1171 if (mr->attrib.mode != MEM_RW)
1172 new_type = bp_loc_hardware_breakpoint;
1174 new_type = bp_loc_software_breakpoint;
1176 if (new_type != bpt->loc_type)
1178 static int said = 0;
1179 bpt->loc_type = new_type;
1182 fprintf_filtered (gdb_stdout, _("\
1183 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1188 else if (bpt->loc_type == bp_loc_software_breakpoint
1189 && mr->attrib.mode != MEM_RW)
1190 warning (_("cannot set software breakpoint at readonly address %s"),
1191 paddress (bpt->gdbarch, bpt->address));
1195 /* First check to see if we have to handle an overlay. */
1196 if (overlay_debugging == ovly_off
1197 || bpt->section == NULL
1198 || !(section_is_overlay (bpt->section)))
1200 /* No overlay handling: just set the breakpoint. */
1202 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1203 val = target_insert_hw_breakpoint (bpt->gdbarch,
1206 val = target_insert_breakpoint (bpt->gdbarch,
1211 /* This breakpoint is in an overlay section.
1212 Shall we set a breakpoint at the LMA? */
1213 if (!overlay_events_enabled)
1215 /* Yes -- overlay event support is not active,
1216 so we must try to set a breakpoint at the LMA.
1217 This will not work for a hardware breakpoint. */
1218 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1219 warning (_("hardware breakpoint %d not supported in overlay!"),
1220 bpt->owner->number);
1223 CORE_ADDR addr = overlay_unmapped_address (bpt->address,
1225 /* Set a software (trap) breakpoint at the LMA. */
1226 bpt->overlay_target_info = bpt->target_info;
1227 bpt->overlay_target_info.placed_address = addr;
1228 val = target_insert_breakpoint (bpt->gdbarch,
1229 &bpt->overlay_target_info);
1231 fprintf_unfiltered (tmp_error_stream,
1232 "Overlay breakpoint %d failed: in ROM?\n",
1233 bpt->owner->number);
1236 /* Shall we set a breakpoint at the VMA? */
1237 if (section_is_mapped (bpt->section))
1239 /* Yes. This overlay section is mapped into memory. */
1240 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1241 val = target_insert_hw_breakpoint (bpt->gdbarch,
1244 val = target_insert_breakpoint (bpt->gdbarch,
1249 /* No. This breakpoint will not be inserted.
1250 No error, but do not mark the bp as 'inserted'. */
1257 /* Can't set the breakpoint. */
1258 if (solib_name_from_address (bpt->pspace, bpt->address))
1260 /* See also: disable_breakpoints_in_shlibs. */
1262 bpt->shlib_disabled = 1;
1263 if (!*disabled_breaks)
1265 fprintf_unfiltered (tmp_error_stream,
1266 "Cannot insert breakpoint %d.\n",
1267 bpt->owner->number);
1268 fprintf_unfiltered (tmp_error_stream,
1269 "Temporarily disabling shared library breakpoints:\n");
1271 *disabled_breaks = 1;
1272 fprintf_unfiltered (tmp_error_stream,
1273 "breakpoint #%d\n", bpt->owner->number);
1277 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1279 *hw_breakpoint_error = 1;
1280 fprintf_unfiltered (tmp_error_stream,
1281 "Cannot insert hardware breakpoint %d.\n",
1282 bpt->owner->number);
1286 fprintf_unfiltered (tmp_error_stream,
1287 "Cannot insert breakpoint %d.\n",
1288 bpt->owner->number);
1289 fprintf_filtered (tmp_error_stream,
1290 "Error accessing memory address ");
1291 fputs_filtered (paddress (bpt->gdbarch, bpt->address),
1293 fprintf_filtered (tmp_error_stream, ": %s.\n",
1294 safe_strerror (val));
1305 else if (bpt->loc_type == bp_loc_hardware_watchpoint
1306 /* NOTE drow/2003-09-08: This state only exists for removing
1307 watchpoints. It's not clear that it's necessary... */
1308 && bpt->owner->disposition != disp_del_at_next_stop)
1310 val = target_insert_watchpoint (bpt->address,
1312 bpt->watchpoint_type);
1313 bpt->inserted = (val != -1);
1316 else if (bpt->owner->type == bp_catchpoint)
1318 struct gdb_exception e = catch_exception (uiout, insert_catchpoint,
1319 bpt->owner, RETURN_MASK_ERROR);
1320 exception_fprintf (gdb_stderr, e, "warning: inserting catchpoint %d: ",
1321 bpt->owner->number);
1323 bpt->owner->enable_state = bp_disabled;
1327 /* We've already printed an error message if there was a problem
1328 inserting this catchpoint, and we've disabled the catchpoint,
1329 so just return success. */
1336 /* This function is called when program space PSPACE is about to be
1337 deleted. It takes care of updating breakpoints to not reference
1341 breakpoint_program_space_exit (struct program_space *pspace)
1343 struct breakpoint *b, *b_temp;
1344 struct bp_location *loc, *loc_temp;
1346 /* Remove any breakpoint that was set through this program space. */
1347 ALL_BREAKPOINTS_SAFE (b, b_temp)
1349 if (b->pspace == pspace)
1350 delete_breakpoint (b);
1353 /* Breakpoints set through other program spaces could have locations
1354 bound to PSPACE as well. Remove those. */
1355 ALL_BP_LOCATIONS_SAFE (loc, loc_temp)
1357 struct bp_location *tmp;
1359 if (loc->pspace == pspace)
1361 if (loc->owner->loc == loc)
1362 loc->owner->loc = loc->next;
1364 for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next)
1365 if (tmp->next == loc)
1367 tmp->next = loc->next;
1373 /* Now update the global location list to permanently delete the
1374 removed locations above. */
1375 update_global_location_list (0);
1378 /* Make sure all breakpoints are inserted in inferior.
1379 Throws exception on any error.
1380 A breakpoint that is already inserted won't be inserted
1381 again, so calling this function twice is safe. */
1383 insert_breakpoints (void)
1385 struct breakpoint *bpt;
1387 ALL_BREAKPOINTS (bpt)
1388 if (is_hardware_watchpoint (bpt))
1389 update_watchpoint (bpt, 0 /* don't reparse. */);
1391 update_global_location_list (1);
1393 /* update_global_location_list does not insert breakpoints when
1394 always_inserted_mode is not enabled. Explicitly insert them
1396 if (!breakpoints_always_inserted_mode ())
1397 insert_breakpoint_locations ();
1400 /* insert_breakpoints is used when starting or continuing the program.
1401 remove_breakpoints is used when the program stops.
1402 Both return zero if successful,
1403 or an `errno' value if could not write the inferior. */
1406 insert_breakpoint_locations (void)
1408 struct breakpoint *bpt;
1409 struct bp_location *b, *temp;
1412 int disabled_breaks = 0;
1413 int hw_breakpoint_error = 0;
1415 struct ui_file *tmp_error_stream = mem_fileopen ();
1416 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
1418 /* Explicitly mark the warning -- this will only be printed if
1419 there was an error. */
1420 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
1422 save_current_space_and_thread ();
1424 ALL_BP_LOCATIONS_SAFE (b, temp)
1426 struct thread_info *tp;
1427 CORE_ADDR last_addr;
1429 if (!should_be_inserted (b) || b->inserted)
1432 /* There is no point inserting thread-specific breakpoints if the
1433 thread no longer exists. */
1434 if (b->owner->thread != -1
1435 && !valid_thread_id (b->owner->thread))
1438 switch_to_program_space_and_thread (b->pspace);
1440 /* For targets that support global breakpoints, there's no need
1441 to select an inferior to insert breakpoint to. In fact, even
1442 if we aren't attached to any process yet, we should still
1443 insert breakpoints. */
1444 if (!gdbarch_has_global_breakpoints (target_gdbarch)
1445 && ptid_equal (inferior_ptid, null_ptid))
1448 if (!ptid_equal (inferior_ptid, null_ptid))
1450 struct inferior *inf = current_inferior ();
1451 if (inf->waiting_for_vfork_done)
1453 /* This is set when we're attached to the parent of the
1454 vfork, and have detached from the child. The child
1455 is running free, and we expect it to do an exec or
1456 exit, at which point the OS makes the parent
1457 schedulable again (and the target reports that the
1458 vfork is done). Until the child is done with the
1459 shared memory region, do not insert breakpoints in
1460 parent, otherwise the child could still trip on the
1461 parent's breakpoints. Since the parent is blocked
1462 anyway, it won't miss any breakpoint. */
1467 val = insert_bp_location (b, tmp_error_stream,
1469 &hw_breakpoint_error);
1474 /* If we failed to insert all locations of a watchpoint,
1475 remove them, as half-inserted watchpoint is of limited use. */
1476 ALL_BREAKPOINTS (bpt)
1478 int some_failed = 0;
1479 struct bp_location *loc;
1481 if (!is_hardware_watchpoint (bpt))
1484 if (!breakpoint_enabled (bpt))
1487 if (bpt->disposition == disp_del_at_next_stop)
1490 for (loc = bpt->loc; loc; loc = loc->next)
1498 for (loc = bpt->loc; loc; loc = loc->next)
1500 remove_breakpoint (loc, mark_uninserted);
1502 hw_breakpoint_error = 1;
1503 fprintf_unfiltered (tmp_error_stream,
1504 "Could not insert hardware watchpoint %d.\n",
1512 /* If a hardware breakpoint or watchpoint was inserted, add a
1513 message about possibly exhausted resources. */
1514 if (hw_breakpoint_error)
1516 fprintf_unfiltered (tmp_error_stream,
1517 "Could not insert hardware breakpoints:\n\
1518 You may have requested too many hardware breakpoints/watchpoints.\n");
1520 target_terminal_ours_for_output ();
1521 error_stream (tmp_error_stream);
1524 do_cleanups (cleanups);
1528 remove_breakpoints (void)
1530 struct bp_location *b;
1533 ALL_BP_LOCATIONS (b)
1536 val |= remove_breakpoint (b, mark_uninserted);
1541 /* Remove breakpoints of process PID. */
1544 remove_breakpoints_pid (int pid)
1546 struct bp_location *b;
1548 struct inferior *inf = find_inferior_pid (pid);
1550 ALL_BP_LOCATIONS (b)
1552 if (b->pspace != inf->pspace)
1557 val = remove_breakpoint (b, mark_uninserted);
1566 remove_hw_watchpoints (void)
1568 struct bp_location *b;
1571 ALL_BP_LOCATIONS (b)
1573 if (b->inserted && b->loc_type == bp_loc_hardware_watchpoint)
1574 val |= remove_breakpoint (b, mark_uninserted);
1580 reattach_breakpoints (int pid)
1582 struct cleanup *old_chain;
1583 struct bp_location *b;
1585 struct ui_file *tmp_error_stream = mem_fileopen ();
1586 int dummy1 = 0, dummy2 = 0;
1587 struct inferior *inf;
1588 struct thread_info *tp;
1590 tp = any_live_thread_of_process (pid);
1594 inf = find_inferior_pid (pid);
1595 old_chain = save_inferior_ptid ();
1597 inferior_ptid = tp->ptid;
1599 make_cleanup_ui_file_delete (tmp_error_stream);
1601 ALL_BP_LOCATIONS (b)
1603 if (b->pspace != inf->pspace)
1609 val = insert_bp_location (b, tmp_error_stream,
1613 do_cleanups (old_chain);
1618 do_cleanups (old_chain);
1622 static int internal_breakpoint_number = -1;
1624 static struct breakpoint *
1625 create_internal_breakpoint (struct gdbarch *gdbarch,
1626 CORE_ADDR address, enum bptype type)
1628 struct symtab_and_line sal;
1629 struct breakpoint *b;
1631 init_sal (&sal); /* initialize to zeroes */
1634 sal.section = find_pc_overlay (sal.pc);
1635 sal.pspace = current_program_space;
1637 b = set_raw_breakpoint (gdbarch, sal, type);
1638 b->number = internal_breakpoint_number--;
1639 b->disposition = disp_donttouch;
1645 create_overlay_event_breakpoint (char *func_name)
1647 struct objfile *objfile;
1649 ALL_OBJFILES (objfile)
1651 struct breakpoint *b;
1652 struct minimal_symbol *m;
1654 m = lookup_minimal_symbol_text (func_name, objfile);
1658 b = create_internal_breakpoint (get_objfile_arch (objfile),
1659 SYMBOL_VALUE_ADDRESS (m),
1661 b->addr_string = xstrdup (func_name);
1663 if (overlay_debugging == ovly_auto)
1665 b->enable_state = bp_enabled;
1666 overlay_events_enabled = 1;
1670 b->enable_state = bp_disabled;
1671 overlay_events_enabled = 0;
1674 update_global_location_list (1);
1678 create_longjmp_master_breakpoint (char *func_name)
1680 struct program_space *pspace;
1681 struct objfile *objfile;
1682 struct cleanup *old_chain;
1684 old_chain = save_current_program_space ();
1686 ALL_PSPACES (pspace)
1687 ALL_OBJFILES (objfile)
1689 struct breakpoint *b;
1690 struct minimal_symbol *m;
1692 if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile)))
1695 set_current_program_space (pspace);
1697 m = lookup_minimal_symbol_text (func_name, objfile);
1701 b = create_internal_breakpoint (get_objfile_arch (objfile),
1702 SYMBOL_VALUE_ADDRESS (m),
1704 b->addr_string = xstrdup (func_name);
1705 b->enable_state = bp_disabled;
1707 update_global_location_list (1);
1709 do_cleanups (old_chain);
1713 update_breakpoints_after_exec (void)
1715 struct breakpoint *b;
1716 struct breakpoint *temp;
1717 struct bp_location *bploc;
1719 /* We're about to delete breakpoints from GDB's lists. If the
1720 INSERTED flag is true, GDB will try to lift the breakpoints by
1721 writing the breakpoints' "shadow contents" back into memory. The
1722 "shadow contents" are NOT valid after an exec, so GDB should not
1723 do that. Instead, the target is responsible from marking
1724 breakpoints out as soon as it detects an exec. We don't do that
1725 here instead, because there may be other attempts to delete
1726 breakpoints after detecting an exec and before reaching here. */
1727 ALL_BP_LOCATIONS (bploc)
1728 if (bploc->pspace == current_program_space)
1729 gdb_assert (!bploc->inserted);
1731 ALL_BREAKPOINTS_SAFE (b, temp)
1733 if (b->pspace != current_program_space)
1736 /* Solib breakpoints must be explicitly reset after an exec(). */
1737 if (b->type == bp_shlib_event)
1739 delete_breakpoint (b);
1743 /* JIT breakpoints must be explicitly reset after an exec(). */
1744 if (b->type == bp_jit_event)
1746 delete_breakpoint (b);
1750 /* Thread event breakpoints must be set anew after an exec(),
1751 as must overlay event and longjmp master breakpoints. */
1752 if (b->type == bp_thread_event || b->type == bp_overlay_event
1753 || b->type == bp_longjmp_master)
1755 delete_breakpoint (b);
1759 /* Step-resume breakpoints are meaningless after an exec(). */
1760 if (b->type == bp_step_resume)
1762 delete_breakpoint (b);
1766 /* Longjmp and longjmp-resume breakpoints are also meaningless
1768 if (b->type == bp_longjmp || b->type == bp_longjmp_resume)
1770 delete_breakpoint (b);
1774 if (b->type == bp_catchpoint)
1776 /* For now, none of the bp_catchpoint breakpoints need to
1777 do anything at this point. In the future, if some of
1778 the catchpoints need to something, we will need to add
1779 a new method, and call this method from here. */
1783 /* bp_finish is a special case. The only way we ought to be able
1784 to see one of these when an exec() has happened, is if the user
1785 caught a vfork, and then said "finish". Ordinarily a finish just
1786 carries them to the call-site of the current callee, by setting
1787 a temporary bp there and resuming. But in this case, the finish
1788 will carry them entirely through the vfork & exec.
1790 We don't want to allow a bp_finish to remain inserted now. But
1791 we can't safely delete it, 'cause finish_command has a handle to
1792 the bp on a bpstat, and will later want to delete it. There's a
1793 chance (and I've seen it happen) that if we delete the bp_finish
1794 here, that its storage will get reused by the time finish_command
1795 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1796 We really must allow finish_command to delete a bp_finish.
1798 In the absense of a general solution for the "how do we know
1799 it's safe to delete something others may have handles to?"
1800 problem, what we'll do here is just uninsert the bp_finish, and
1801 let finish_command delete it.
1803 (We know the bp_finish is "doomed" in the sense that it's
1804 momentary, and will be deleted as soon as finish_command sees
1805 the inferior stopped. So it doesn't matter that the bp's
1806 address is probably bogus in the new a.out, unlike e.g., the
1807 solib breakpoints.) */
1809 if (b->type == bp_finish)
1814 /* Without a symbolic address, we have little hope of the
1815 pre-exec() address meaning the same thing in the post-exec()
1817 if (b->addr_string == NULL)
1819 delete_breakpoint (b);
1823 /* FIXME what about longjmp breakpoints? Re-create them here? */
1824 create_overlay_event_breakpoint ("_ovly_debug_event");
1825 create_longjmp_master_breakpoint ("longjmp");
1826 create_longjmp_master_breakpoint ("_longjmp");
1827 create_longjmp_master_breakpoint ("siglongjmp");
1828 create_longjmp_master_breakpoint ("_siglongjmp");
1832 detach_breakpoints (int pid)
1834 struct bp_location *b;
1836 struct cleanup *old_chain = save_inferior_ptid ();
1837 struct inferior *inf = current_inferior ();
1839 if (pid == PIDGET (inferior_ptid))
1840 error (_("Cannot detach breakpoints of inferior_ptid"));
1842 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
1843 inferior_ptid = pid_to_ptid (pid);
1844 ALL_BP_LOCATIONS (b)
1846 if (b->pspace != inf->pspace)
1850 val |= remove_breakpoint_1 (b, mark_inserted);
1852 do_cleanups (old_chain);
1856 /* Remove the breakpoint location B from the current address space.
1857 Note that this is used to detach breakpoints from a child fork.
1858 When we get here, the child isn't in the inferior list, and neither
1859 do we have objects to represent its address space --- we should
1860 *not* look at b->pspace->aspace here. */
1863 remove_breakpoint_1 (struct bp_location *b, insertion_state_t is)
1866 struct cleanup *old_chain;
1868 if (b->owner->enable_state == bp_permanent)
1869 /* Permanent breakpoints cannot be inserted or removed. */
1872 /* The type of none suggests that owner is actually deleted.
1873 This should not ever happen. */
1874 gdb_assert (b->owner->type != bp_none);
1876 if (b->loc_type == bp_loc_software_breakpoint
1877 || b->loc_type == bp_loc_hardware_breakpoint)
1879 /* "Normal" instruction breakpoint: either the standard
1880 trap-instruction bp (bp_breakpoint), or a
1881 bp_hardware_breakpoint. */
1883 /* First check to see if we have to handle an overlay. */
1884 if (overlay_debugging == ovly_off
1885 || b->section == NULL
1886 || !(section_is_overlay (b->section)))
1888 /* No overlay handling: just remove the breakpoint. */
1890 if (b->loc_type == bp_loc_hardware_breakpoint)
1891 val = target_remove_hw_breakpoint (b->gdbarch, &b->target_info);
1893 val = target_remove_breakpoint (b->gdbarch, &b->target_info);
1897 /* This breakpoint is in an overlay section.
1898 Did we set a breakpoint at the LMA? */
1899 if (!overlay_events_enabled)
1901 /* Yes -- overlay event support is not active, so we
1902 should have set a breakpoint at the LMA. Remove it.
1904 /* Ignore any failures: if the LMA is in ROM, we will
1905 have already warned when we failed to insert it. */
1906 if (b->loc_type == bp_loc_hardware_breakpoint)
1907 target_remove_hw_breakpoint (b->gdbarch,
1908 &b->overlay_target_info);
1910 target_remove_breakpoint (b->gdbarch,
1911 &b->overlay_target_info);
1913 /* Did we set a breakpoint at the VMA?
1914 If so, we will have marked the breakpoint 'inserted'. */
1917 /* Yes -- remove it. Previously we did not bother to
1918 remove the breakpoint if the section had been
1919 unmapped, but let's not rely on that being safe. We
1920 don't know what the overlay manager might do. */
1921 if (b->loc_type == bp_loc_hardware_breakpoint)
1922 val = target_remove_hw_breakpoint (b->gdbarch,
1925 /* However, we should remove *software* breakpoints only
1926 if the section is still mapped, or else we overwrite
1927 wrong code with the saved shadow contents. */
1928 else if (section_is_mapped (b->section))
1929 val = target_remove_breakpoint (b->gdbarch,
1936 /* No -- not inserted, so no need to remove. No error. */
1941 /* In some cases, we might not be able to remove a breakpoint
1942 in a shared library that has already been removed, but we
1943 have not yet processed the shlib unload event. */
1944 if (val && solib_name_from_address (b->pspace, b->address))
1949 b->inserted = (is == mark_inserted);
1951 else if (b->loc_type == bp_loc_hardware_watchpoint)
1956 b->inserted = (is == mark_inserted);
1957 val = target_remove_watchpoint (b->address, b->length,
1958 b->watchpoint_type);
1960 /* Failure to remove any of the hardware watchpoints comes here. */
1961 if ((is == mark_uninserted) && (b->inserted))
1962 warning (_("Could not remove hardware watchpoint %d."),
1965 else if (b->owner->type == bp_catchpoint
1966 && breakpoint_enabled (b->owner)
1969 gdb_assert (b->owner->ops != NULL && b->owner->ops->remove != NULL);
1971 val = b->owner->ops->remove (b->owner);
1974 b->inserted = (is == mark_inserted);
1981 remove_breakpoint (struct bp_location *b, insertion_state_t is)
1984 struct cleanup *old_chain;
1986 if (b->owner->enable_state == bp_permanent)
1987 /* Permanent breakpoints cannot be inserted or removed. */
1990 /* The type of none suggests that owner is actually deleted.
1991 This should not ever happen. */
1992 gdb_assert (b->owner->type != bp_none);
1994 old_chain = save_current_space_and_thread ();
1996 switch_to_program_space_and_thread (b->pspace);
1998 ret = remove_breakpoint_1 (b, is);
2000 do_cleanups (old_chain);
2004 /* Clear the "inserted" flag in all breakpoints. */
2007 mark_breakpoints_out (void)
2009 struct bp_location *bpt;
2011 ALL_BP_LOCATIONS (bpt)
2012 if (bpt->pspace == current_program_space)
2016 /* Clear the "inserted" flag in all breakpoints and delete any
2017 breakpoints which should go away between runs of the program.
2019 Plus other such housekeeping that has to be done for breakpoints
2022 Note: this function gets called at the end of a run (by
2023 generic_mourn_inferior) and when a run begins (by
2024 init_wait_for_inferior). */
2029 breakpoint_init_inferior (enum inf_context context)
2031 struct breakpoint *b, *temp;
2032 struct bp_location *bpt;
2034 struct program_space *pspace = current_program_space;
2036 /* If breakpoint locations are shared across processes, then there's
2038 if (gdbarch_has_global_breakpoints (target_gdbarch))
2041 ALL_BP_LOCATIONS (bpt)
2043 if (bpt->pspace == pspace
2044 && bpt->owner->enable_state != bp_permanent)
2048 ALL_BREAKPOINTS_SAFE (b, temp)
2050 if (b->loc && b->loc->pspace != pspace)
2056 case bp_watchpoint_scope:
2058 /* If the call dummy breakpoint is at the entry point it will
2059 cause problems when the inferior is rerun, so we better
2062 Also get rid of scope breakpoints. */
2063 delete_breakpoint (b);
2067 case bp_hardware_watchpoint:
2068 case bp_read_watchpoint:
2069 case bp_access_watchpoint:
2071 /* Likewise for watchpoints on local expressions. */
2072 if (b->exp_valid_block != NULL)
2073 delete_breakpoint (b);
2074 else if (context == inf_starting)
2076 /* Reset val field to force reread of starting value
2077 in insert_breakpoints. */
2079 value_free (b->val);
2089 /* Get rid of the moribund locations. */
2090 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bpt); ++ix)
2091 free_bp_location (bpt);
2092 VEC_free (bp_location_p, moribund_locations);
2095 /* These functions concern about actual breakpoints inserted in the
2096 target --- to e.g. check if we need to do decr_pc adjustment or if
2097 we need to hop over the bkpt --- so we check for address space
2098 match, not program space. */
2100 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
2101 exists at PC. It returns ordinary_breakpoint_here if it's an
2102 ordinary breakpoint, or permanent_breakpoint_here if it's a
2103 permanent breakpoint.
2104 - When continuing from a location with an ordinary breakpoint, we
2105 actually single step once before calling insert_breakpoints.
2106 - When continuing from a localion with a permanent breakpoint, we
2107 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
2108 the target, to advance the PC past the breakpoint. */
2110 enum breakpoint_here
2111 breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
2113 const struct bp_location *bpt;
2114 int any_breakpoint_here = 0;
2116 ALL_BP_LOCATIONS (bpt)
2118 if (bpt->loc_type != bp_loc_software_breakpoint
2119 && bpt->loc_type != bp_loc_hardware_breakpoint)
2122 if ((breakpoint_enabled (bpt->owner)
2123 || bpt->owner->enable_state == bp_permanent)
2124 && breakpoint_address_match (bpt->pspace->aspace, bpt->address,
2127 if (overlay_debugging
2128 && section_is_overlay (bpt->section)
2129 && !section_is_mapped (bpt->section))
2130 continue; /* unmapped overlay -- can't be a match */
2131 else if (bpt->owner->enable_state == bp_permanent)
2132 return permanent_breakpoint_here;
2134 any_breakpoint_here = 1;
2138 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
2141 /* Return true if there's a moribund breakpoint at PC. */
2144 moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
2146 struct bp_location *loc;
2149 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
2150 if (breakpoint_address_match (loc->pspace->aspace, loc->address,
2157 /* Returns non-zero if there's a breakpoint inserted at PC, which is
2158 inserted using regular breakpoint_chain/bp_location_chain mechanism.
2159 This does not check for single-step breakpoints, which are
2160 inserted and removed using direct target manipulation. */
2163 regular_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
2165 const struct bp_location *bpt;
2167 ALL_BP_LOCATIONS (bpt)
2169 if (bpt->loc_type != bp_loc_software_breakpoint
2170 && bpt->loc_type != bp_loc_hardware_breakpoint)
2174 && breakpoint_address_match (bpt->pspace->aspace, bpt->address,
2177 if (overlay_debugging
2178 && section_is_overlay (bpt->section)
2179 && !section_is_mapped (bpt->section))
2180 continue; /* unmapped overlay -- can't be a match */
2188 /* Returns non-zero iff there's either regular breakpoint
2189 or a single step breakpoint inserted at PC. */
2192 breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
2194 if (regular_breakpoint_inserted_here_p (aspace, pc))
2197 if (single_step_breakpoint_inserted_here_p (aspace, pc))
2203 /* This function returns non-zero iff there is a software breakpoint
2207 software_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
2209 const struct bp_location *bpt;
2210 int any_breakpoint_here = 0;
2212 ALL_BP_LOCATIONS (bpt)
2214 if (bpt->loc_type != bp_loc_software_breakpoint)
2218 && breakpoint_address_match (bpt->pspace->aspace, bpt->address,
2221 if (overlay_debugging
2222 && section_is_overlay (bpt->section)
2223 && !section_is_mapped (bpt->section))
2224 continue; /* unmapped overlay -- can't be a match */
2230 /* Also check for software single-step breakpoints. */
2231 if (single_step_breakpoint_inserted_here_p (aspace, pc))
2237 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
2238 PC is valid for process/thread PTID. */
2241 breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc,
2244 const struct bp_location *bpt;
2245 /* The thread and task IDs associated to PTID, computed lazily. */
2249 ALL_BP_LOCATIONS (bpt)
2251 if (bpt->loc_type != bp_loc_software_breakpoint
2252 && bpt->loc_type != bp_loc_hardware_breakpoint)
2255 if (!breakpoint_enabled (bpt->owner)
2256 && bpt->owner->enable_state != bp_permanent)
2259 if (!breakpoint_address_match (bpt->pspace->aspace, bpt->address,
2263 if (bpt->owner->thread != -1)
2265 /* This is a thread-specific breakpoint. Check that ptid
2266 matches that thread. If thread hasn't been computed yet,
2267 it is now time to do so. */
2269 thread = pid_to_thread_id (ptid);
2270 if (bpt->owner->thread != thread)
2274 if (bpt->owner->task != 0)
2276 /* This is a task-specific breakpoint. Check that ptid
2277 matches that task. If task hasn't been computed yet,
2278 it is now time to do so. */
2280 task = ada_get_task_number (ptid);
2281 if (bpt->owner->task != task)
2285 if (overlay_debugging
2286 && section_is_overlay (bpt->section)
2287 && !section_is_mapped (bpt->section))
2288 continue; /* unmapped overlay -- can't be a match */
2297 /* bpstat stuff. External routines' interfaces are documented
2301 ep_is_catchpoint (struct breakpoint *ep)
2303 return (ep->type == bp_catchpoint);
2307 bpstat_free (bpstat bs)
2309 if (bs->old_val != NULL)
2310 value_free (bs->old_val);
2311 free_command_lines (&bs->commands);
2315 /* Clear a bpstat so that it says we are not at any breakpoint.
2316 Also free any storage that is part of a bpstat. */
2319 bpstat_clear (bpstat *bsp)
2336 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
2337 is part of the bpstat is copied as well. */
2340 bpstat_copy (bpstat bs)
2344 bpstat retval = NULL;
2349 for (; bs != NULL; bs = bs->next)
2351 tmp = (bpstat) xmalloc (sizeof (*tmp));
2352 memcpy (tmp, bs, sizeof (*tmp));
2353 if (bs->commands != NULL)
2354 tmp->commands = copy_command_lines (bs->commands);
2355 if (bs->old_val != NULL)
2357 tmp->old_val = value_copy (bs->old_val);
2358 release_value (tmp->old_val);
2362 /* This is the first thing in the chain. */
2372 /* Find the bpstat associated with this breakpoint */
2375 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
2380 for (; bsp != NULL; bsp = bsp->next)
2382 if (bsp->breakpoint_at && bsp->breakpoint_at->owner == breakpoint)
2388 /* Find a step_resume breakpoint associated with this bpstat.
2389 (If there are multiple step_resume bp's on the list, this function
2390 will arbitrarily pick one.)
2392 It is an error to use this function if BPSTAT doesn't contain a
2393 step_resume breakpoint.
2395 See wait_for_inferior's use of this function. */
2397 bpstat_find_step_resume_breakpoint (bpstat bsp)
2401 gdb_assert (bsp != NULL);
2403 current_thread = pid_to_thread_id (inferior_ptid);
2405 for (; bsp != NULL; bsp = bsp->next)
2407 if ((bsp->breakpoint_at != NULL)
2408 && (bsp->breakpoint_at->owner->type == bp_step_resume)
2409 && (bsp->breakpoint_at->owner->thread == current_thread
2410 || bsp->breakpoint_at->owner->thread == -1))
2411 return bsp->breakpoint_at->owner;
2414 internal_error (__FILE__, __LINE__, _("No step_resume breakpoint found."));
2418 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2419 at. *BSP upon return is a bpstat which points to the remaining
2420 breakpoints stopped at (but which is not guaranteed to be good for
2421 anything but further calls to bpstat_num).
2422 Return 0 if passed a bpstat which does not indicate any breakpoints.
2423 Return -1 if stopped at a breakpoint that has been deleted since
2425 Return 1 otherwise. */
2428 bpstat_num (bpstat *bsp, int *num)
2430 struct breakpoint *b;
2433 return 0; /* No more breakpoint values */
2435 /* We assume we'll never have several bpstats that
2436 correspond to a single breakpoint -- otherwise,
2437 this function might return the same number more
2438 than once and this will look ugly. */
2439 b = (*bsp)->breakpoint_at ? (*bsp)->breakpoint_at->owner : NULL;
2440 *bsp = (*bsp)->next;
2442 return -1; /* breakpoint that's been deleted since */
2444 *num = b->number; /* We have its number */
2448 /* Modify BS so that the actions will not be performed. */
2451 bpstat_clear_actions (bpstat bs)
2453 for (; bs != NULL; bs = bs->next)
2455 free_command_lines (&bs->commands);
2456 if (bs->old_val != NULL)
2458 value_free (bs->old_val);
2464 /* Called when a command is about to proceed the inferior. */
2467 breakpoint_about_to_proceed (void)
2469 if (!ptid_equal (inferior_ptid, null_ptid))
2471 struct thread_info *tp = inferior_thread ();
2473 /* Allow inferior function calls in breakpoint commands to not
2474 interrupt the command list. When the call finishes
2475 successfully, the inferior will be standing at the same
2476 breakpoint as if nothing happened. */
2481 breakpoint_proceeded = 1;
2484 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2486 cleanup_executing_breakpoints (void *ignore)
2488 executing_breakpoint_commands = 0;
2491 /* Execute all the commands associated with all the breakpoints at this
2492 location. Any of these commands could cause the process to proceed
2493 beyond this point, etc. We look out for such changes by checking
2494 the global "breakpoint_proceeded" after each command.
2496 Returns true if a breakpoint command resumed the inferior. In that
2497 case, it is the caller's responsibility to recall it again with the
2498 bpstat of the current thread. */
2501 bpstat_do_actions_1 (bpstat *bsp)
2504 struct cleanup *old_chain;
2507 /* Avoid endless recursion if a `source' command is contained
2509 if (executing_breakpoint_commands)
2512 executing_breakpoint_commands = 1;
2513 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
2515 /* This pointer will iterate over the list of bpstat's. */
2518 breakpoint_proceeded = 0;
2519 for (; bs != NULL; bs = bs->next)
2521 struct command_line *cmd;
2522 struct cleanup *this_cmd_tree_chain;
2524 /* Take ownership of the BSP's command tree, if it has one.
2526 The command tree could legitimately contain commands like
2527 'step' and 'next', which call clear_proceed_status, which
2528 frees stop_bpstat's command tree. To make sure this doesn't
2529 free the tree we're executing out from under us, we need to
2530 take ownership of the tree ourselves. Since a given bpstat's
2531 commands are only executed once, we don't need to copy it; we
2532 can clear the pointer in the bpstat, and make sure we free
2533 the tree when we're done. */
2536 this_cmd_tree_chain = make_cleanup_free_command_lines (&cmd);
2540 execute_control_command (cmd);
2542 if (breakpoint_proceeded)
2548 /* We can free this command tree now. */
2549 do_cleanups (this_cmd_tree_chain);
2551 if (breakpoint_proceeded)
2553 if (target_can_async_p ())
2554 /* If we are in async mode, then the target might be still
2555 running, not stopped at any breakpoint, so nothing for
2556 us to do here -- just return to the event loop. */
2559 /* In sync mode, when execute_control_command returns
2560 we're already standing on the next breakpoint.
2561 Breakpoint commands for that stop were not run, since
2562 execute_command does not run breakpoint commands --
2563 only command_line_handler does, but that one is not
2564 involved in execution of breakpoint commands. So, we
2565 can now execute breakpoint commands. It should be
2566 noted that making execute_command do bpstat actions is
2567 not an option -- in this case we'll have recursive
2568 invocation of bpstat for each breakpoint with a
2569 command, and can easily blow up GDB stack. Instead, we
2570 return true, which will trigger the caller to recall us
2571 with the new stop_bpstat. */
2576 do_cleanups (old_chain);
2581 bpstat_do_actions (void)
2583 /* Do any commands attached to breakpoint we are stopped at. */
2584 while (!ptid_equal (inferior_ptid, null_ptid)
2585 && target_has_execution
2586 && !is_exited (inferior_ptid)
2587 && !is_executing (inferior_ptid))
2588 /* Since in sync mode, bpstat_do_actions may resume the inferior,
2589 and only return when it is stopped at the next breakpoint, we
2590 keep doing breakpoint actions until it returns false to
2591 indicate the inferior was not resumed. */
2592 if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat))
2596 /* Print out the (old or new) value associated with a watchpoint. */
2599 watchpoint_value_print (struct value *val, struct ui_file *stream)
2602 fprintf_unfiltered (stream, _("<unreadable>"));
2605 struct value_print_options opts;
2606 get_user_print_options (&opts);
2607 value_print (val, stream, &opts);
2611 /* This is the normal print function for a bpstat. In the future,
2612 much of this logic could (should?) be moved to bpstat_stop_status,
2613 by having it set different print_it values.
2615 Current scheme: When we stop, bpstat_print() is called. It loops
2616 through the bpstat list of things causing this stop, calling the
2617 print_bp_stop_message function on each one. The behavior of the
2618 print_bp_stop_message function depends on the print_it field of
2619 bpstat. If such field so indicates, call this function here.
2621 Return values from this routine (ultimately used by bpstat_print()
2622 and normal_stop() to decide what to do):
2623 PRINT_NOTHING: Means we already printed all we needed to print,
2624 don't print anything else.
2625 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2626 that something to be followed by a location.
2627 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2628 that something to be followed by a location.
2629 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2632 static enum print_stop_action
2633 print_it_typical (bpstat bs)
2635 struct cleanup *old_chain;
2636 struct breakpoint *b;
2637 const struct bp_location *bl;
2638 struct ui_stream *stb;
2640 enum print_stop_action result;
2642 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2643 which has since been deleted. */
2644 if (bs->breakpoint_at == NULL)
2645 return PRINT_UNKNOWN;
2646 bl = bs->breakpoint_at;
2649 stb = ui_out_stream_new (uiout);
2650 old_chain = make_cleanup_ui_out_stream_delete (stb);
2655 case bp_hardware_breakpoint:
2656 bp_temp = bs->breakpoint_at->owner->disposition == disp_del;
2657 if (bl->address != bl->requested_address)
2658 breakpoint_adjustment_warning (bl->requested_address,
2661 annotate_breakpoint (b->number);
2663 ui_out_text (uiout, "\nTemporary breakpoint ");
2665 ui_out_text (uiout, "\nBreakpoint ");
2666 if (ui_out_is_mi_like_p (uiout))
2668 ui_out_field_string (uiout, "reason",
2669 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
2670 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
2672 ui_out_field_int (uiout, "bkptno", b->number);
2673 ui_out_text (uiout, ", ");
2674 result = PRINT_SRC_AND_LOC;
2677 case bp_shlib_event:
2678 /* Did we stop because the user set the stop_on_solib_events
2679 variable? (If so, we report this as a generic, "Stopped due
2680 to shlib event" message.) */
2681 printf_filtered (_("Stopped due to shared library event\n"));
2682 result = PRINT_NOTHING;
2685 case bp_thread_event:
2686 /* Not sure how we will get here.
2687 GDB should not stop for these breakpoints. */
2688 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2689 result = PRINT_NOTHING;
2692 case bp_overlay_event:
2693 /* By analogy with the thread event, GDB should not stop for these. */
2694 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2695 result = PRINT_NOTHING;
2698 case bp_longjmp_master:
2699 /* These should never be enabled. */
2700 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
2701 result = PRINT_NOTHING;
2705 case bp_hardware_watchpoint:
2706 annotate_watchpoint (b->number);
2707 if (ui_out_is_mi_like_p (uiout))
2710 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
2712 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2713 ui_out_text (uiout, "\nOld value = ");
2714 watchpoint_value_print (bs->old_val, stb->stream);
2715 ui_out_field_stream (uiout, "old", stb);
2716 ui_out_text (uiout, "\nNew value = ");
2717 watchpoint_value_print (b->val, stb->stream);
2718 ui_out_field_stream (uiout, "new", stb);
2719 ui_out_text (uiout, "\n");
2720 /* More than one watchpoint may have been triggered. */
2721 result = PRINT_UNKNOWN;
2724 case bp_read_watchpoint:
2725 if (ui_out_is_mi_like_p (uiout))
2728 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
2730 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2731 ui_out_text (uiout, "\nValue = ");
2732 watchpoint_value_print (b->val, stb->stream);
2733 ui_out_field_stream (uiout, "value", stb);
2734 ui_out_text (uiout, "\n");
2735 result = PRINT_UNKNOWN;
2738 case bp_access_watchpoint:
2739 if (bs->old_val != NULL)
2741 annotate_watchpoint (b->number);
2742 if (ui_out_is_mi_like_p (uiout))
2745 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
2747 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2748 ui_out_text (uiout, "\nOld value = ");
2749 watchpoint_value_print (bs->old_val, stb->stream);
2750 ui_out_field_stream (uiout, "old", stb);
2751 ui_out_text (uiout, "\nNew value = ");
2756 if (ui_out_is_mi_like_p (uiout))
2759 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
2760 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2761 ui_out_text (uiout, "\nValue = ");
2763 watchpoint_value_print (b->val, stb->stream);
2764 ui_out_field_stream (uiout, "new", stb);
2765 ui_out_text (uiout, "\n");
2766 result = PRINT_UNKNOWN;
2769 /* Fall through, we don't deal with these types of breakpoints
2773 if (ui_out_is_mi_like_p (uiout))
2776 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED));
2777 result = PRINT_UNKNOWN;
2781 if (ui_out_is_mi_like_p (uiout))
2784 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED));
2785 result = PRINT_UNKNOWN;
2790 case bp_longjmp_resume:
2791 case bp_step_resume:
2792 case bp_watchpoint_scope:
2797 result = PRINT_UNKNOWN;
2801 do_cleanups (old_chain);
2805 /* Generic routine for printing messages indicating why we
2806 stopped. The behavior of this function depends on the value
2807 'print_it' in the bpstat structure. Under some circumstances we
2808 may decide not to print anything here and delegate the task to
2811 static enum print_stop_action
2812 print_bp_stop_message (bpstat bs)
2814 switch (bs->print_it)
2817 /* Nothing should be printed for this bpstat entry. */
2818 return PRINT_UNKNOWN;
2822 /* We still want to print the frame, but we already printed the
2823 relevant messages. */
2824 return PRINT_SRC_AND_LOC;
2827 case print_it_normal:
2829 const struct bp_location *bl = bs->breakpoint_at;
2830 struct breakpoint *b = bl ? bl->owner : NULL;
2832 /* Normal case. Call the breakpoint's print_it method, or
2833 print_it_typical. */
2834 /* FIXME: how breakpoint can ever be NULL here? */
2835 if (b != NULL && b->ops != NULL && b->ops->print_it != NULL)
2836 return b->ops->print_it (b);
2838 return print_it_typical (bs);
2843 internal_error (__FILE__, __LINE__,
2844 _("print_bp_stop_message: unrecognized enum value"));
2849 /* Print a message indicating what happened. This is called from
2850 normal_stop(). The input to this routine is the head of the bpstat
2851 list - a list of the eventpoints that caused this stop. This
2852 routine calls the generic print routine for printing a message
2853 about reasons for stopping. This will print (for example) the
2854 "Breakpoint n," part of the output. The return value of this
2857 PRINT_UNKNOWN: Means we printed nothing
2858 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2859 code to print the location. An example is
2860 "Breakpoint 1, " which should be followed by
2862 PRINT_SRC_ONLY: Means we printed something, but there is no need
2863 to also print the location part of the message.
2864 An example is the catch/throw messages, which
2865 don't require a location appended to the end.
2866 PRINT_NOTHING: We have done some printing and we don't need any
2867 further info to be printed.*/
2869 enum print_stop_action
2870 bpstat_print (bpstat bs)
2874 /* Maybe another breakpoint in the chain caused us to stop.
2875 (Currently all watchpoints go on the bpstat whether hit or not.
2876 That probably could (should) be changed, provided care is taken
2877 with respect to bpstat_explains_signal). */
2878 for (; bs; bs = bs->next)
2880 val = print_bp_stop_message (bs);
2881 if (val == PRINT_SRC_ONLY
2882 || val == PRINT_SRC_AND_LOC
2883 || val == PRINT_NOTHING)
2887 /* We reached the end of the chain, or we got a null BS to start
2888 with and nothing was printed. */
2889 return PRINT_UNKNOWN;
2892 /* Evaluate the expression EXP and return 1 if value is zero.
2893 This is used inside a catch_errors to evaluate the breakpoint condition.
2894 The argument is a "struct expression *" that has been cast to char * to
2895 make it pass through catch_errors. */
2898 breakpoint_cond_eval (void *exp)
2900 struct value *mark = value_mark ();
2901 int i = !value_true (evaluate_expression ((struct expression *) exp));
2902 value_free_to_mark (mark);
2906 /* Allocate a new bpstat and chain it to the current one. */
2909 bpstat_alloc (const struct bp_location *bl, bpstat cbs /* Current "bs" value */ )
2913 bs = (bpstat) xmalloc (sizeof (*bs));
2915 bs->breakpoint_at = bl;
2916 /* If the condition is false, etc., don't do the commands. */
2917 bs->commands = NULL;
2919 bs->print_it = print_it_normal;
2923 /* The target has stopped with waitstatus WS. Check if any hardware
2924 watchpoints have triggered, according to the target. */
2927 watchpoints_triggered (struct target_waitstatus *ws)
2929 int stopped_by_watchpoint = target_stopped_by_watchpoint ();
2931 struct breakpoint *b;
2933 if (!stopped_by_watchpoint)
2935 /* We were not stopped by a watchpoint. Mark all watchpoints
2936 as not triggered. */
2938 if (b->type == bp_hardware_watchpoint
2939 || b->type == bp_read_watchpoint
2940 || b->type == bp_access_watchpoint)
2941 b->watchpoint_triggered = watch_triggered_no;
2946 if (!target_stopped_data_address (¤t_target, &addr))
2948 /* We were stopped by a watchpoint, but we don't know where.
2949 Mark all watchpoints as unknown. */
2951 if (b->type == bp_hardware_watchpoint
2952 || b->type == bp_read_watchpoint
2953 || b->type == bp_access_watchpoint)
2954 b->watchpoint_triggered = watch_triggered_unknown;
2956 return stopped_by_watchpoint;
2959 /* The target could report the data address. Mark watchpoints
2960 affected by this data address as triggered, and all others as not
2964 if (b->type == bp_hardware_watchpoint
2965 || b->type == bp_read_watchpoint
2966 || b->type == bp_access_watchpoint)
2968 struct bp_location *loc;
2971 b->watchpoint_triggered = watch_triggered_no;
2972 for (loc = b->loc; loc; loc = loc->next)
2973 /* Exact match not required. Within range is
2975 if (target_watchpoint_addr_within_range (¤t_target,
2979 b->watchpoint_triggered = watch_triggered_yes;
2987 /* Possible return values for watchpoint_check (this can't be an enum
2988 because of check_errors). */
2989 /* The watchpoint has been deleted. */
2990 #define WP_DELETED 1
2991 /* The value has changed. */
2992 #define WP_VALUE_CHANGED 2
2993 /* The value has not changed. */
2994 #define WP_VALUE_NOT_CHANGED 3
2996 #define BP_TEMPFLAG 1
2997 #define BP_HARDWAREFLAG 2
2999 /* Check watchpoint condition. */
3002 watchpoint_check (void *p)
3004 bpstat bs = (bpstat) p;
3005 struct breakpoint *b;
3006 struct frame_info *fr;
3007 int within_current_scope;
3009 b = bs->breakpoint_at->owner;
3011 if (b->exp_valid_block == NULL)
3012 within_current_scope = 1;
3015 struct frame_info *frame = get_current_frame ();
3016 struct gdbarch *frame_arch = get_frame_arch (frame);
3017 CORE_ADDR frame_pc = get_frame_pc (frame);
3019 fr = frame_find_by_id (b->watchpoint_frame);
3020 within_current_scope = (fr != NULL);
3022 /* If we've gotten confused in the unwinder, we might have
3023 returned a frame that can't describe this variable. */
3024 if (within_current_scope)
3026 struct symbol *function;
3028 function = get_frame_function (fr);
3029 if (function == NULL
3030 || !contained_in (b->exp_valid_block,
3031 SYMBOL_BLOCK_VALUE (function)))
3032 within_current_scope = 0;
3035 /* in_function_epilogue_p() returns a non-zero value if we're still
3036 in the function but the stack frame has already been invalidated.
3037 Since we can't rely on the values of local variables after the
3038 stack has been destroyed, we are treating the watchpoint in that
3039 state as `not changed' without further checking. Don't mark
3040 watchpoints as changed if the current frame is in an epilogue -
3041 even if they are in some other frame, our view of the stack
3042 is likely to be wrong. */
3043 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
3044 return WP_VALUE_NOT_CHANGED;
3046 if (within_current_scope)
3047 /* If we end up stopping, the current frame will get selected
3048 in normal_stop. So this call to select_frame won't affect
3053 if (within_current_scope)
3055 /* We use value_{,free_to_}mark because it could be a
3056 *long* time before we return to the command level and
3057 call free_all_values. We can't call free_all_values because
3058 we might be in the middle of evaluating a function call. */
3060 struct value *mark = value_mark ();
3061 struct value *new_val;
3063 fetch_watchpoint_value (b->exp, &new_val, NULL, NULL);
3064 if ((b->val != NULL) != (new_val != NULL)
3065 || (b->val != NULL && !value_equal (b->val, new_val)))
3067 if (new_val != NULL)
3069 release_value (new_val);
3070 value_free_to_mark (mark);
3072 bs->old_val = b->val;
3075 /* We will stop here */
3076 return WP_VALUE_CHANGED;
3080 /* Nothing changed, don't do anything. */
3081 value_free_to_mark (mark);
3082 /* We won't stop here */
3083 return WP_VALUE_NOT_CHANGED;
3088 /* This seems like the only logical thing to do because
3089 if we temporarily ignored the watchpoint, then when
3090 we reenter the block in which it is valid it contains
3091 garbage (in the case of a function, it may have two
3092 garbage values, one before and one after the prologue).
3093 So we can't even detect the first assignment to it and
3094 watch after that (since the garbage may or may not equal
3095 the first value assigned). */
3096 /* We print all the stop information in print_it_typical(), but
3097 in this case, by the time we call print_it_typical() this bp
3098 will be deleted already. So we have no choice but print the
3099 information here. */
3100 if (ui_out_is_mi_like_p (uiout))
3102 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
3103 ui_out_text (uiout, "\nWatchpoint ");
3104 ui_out_field_int (uiout, "wpnum", b->number);
3105 ui_out_text (uiout, " deleted because the program has left the block in\n\
3106 which its expression is valid.\n");
3108 if (b->related_breakpoint)
3109 b->related_breakpoint->disposition = disp_del_at_next_stop;
3110 b->disposition = disp_del_at_next_stop;
3116 /* Return true if it looks like target has stopped due to hitting
3117 breakpoint location BL. This function does not check if we
3118 should stop, only if BL explains the stop. */
3120 bpstat_check_location (const struct bp_location *bl,
3121 struct address_space *aspace, CORE_ADDR bp_addr)
3123 struct breakpoint *b = bl->owner;
3125 if (b->type != bp_watchpoint
3126 && b->type != bp_hardware_watchpoint
3127 && b->type != bp_read_watchpoint
3128 && b->type != bp_access_watchpoint
3129 && b->type != bp_hardware_breakpoint
3130 && b->type != bp_catchpoint) /* a non-watchpoint bp */
3132 if (!breakpoint_address_match (bl->pspace->aspace, bl->address,
3135 if (overlay_debugging /* unmapped overlay section */
3136 && section_is_overlay (bl->section)
3137 && !section_is_mapped (bl->section))
3141 /* Continuable hardware watchpoints are treated as non-existent if the
3142 reason we stopped wasn't a hardware watchpoint (we didn't stop on
3143 some data address). Otherwise gdb won't stop on a break instruction
3144 in the code (not from a breakpoint) when a hardware watchpoint has
3145 been defined. Also skip watchpoints which we know did not trigger
3146 (did not match the data address). */
3148 if ((b->type == bp_hardware_watchpoint
3149 || b->type == bp_read_watchpoint
3150 || b->type == bp_access_watchpoint)
3151 && b->watchpoint_triggered == watch_triggered_no)
3154 if (b->type == bp_hardware_breakpoint)
3156 if (bl->address != bp_addr)
3158 if (overlay_debugging /* unmapped overlay section */
3159 && section_is_overlay (bl->section)
3160 && !section_is_mapped (bl->section))
3164 if (b->type == bp_catchpoint)
3166 gdb_assert (b->ops != NULL && b->ops->breakpoint_hit != NULL);
3167 if (!b->ops->breakpoint_hit (b))
3174 /* If BS refers to a watchpoint, determine if the watched values
3175 has actually changed, and we should stop. If not, set BS->stop
3178 bpstat_check_watchpoint (bpstat bs)
3180 const struct bp_location *bl = bs->breakpoint_at;
3181 struct breakpoint *b = bl->owner;
3183 if (b->type == bp_watchpoint
3184 || b->type == bp_read_watchpoint
3185 || b->type == bp_access_watchpoint
3186 || b->type == bp_hardware_watchpoint)
3190 int must_check_value = 0;
3192 if (b->type == bp_watchpoint)
3193 /* For a software watchpoint, we must always check the
3195 must_check_value = 1;
3196 else if (b->watchpoint_triggered == watch_triggered_yes)
3197 /* We have a hardware watchpoint (read, write, or access)
3198 and the target earlier reported an address watched by
3200 must_check_value = 1;
3201 else if (b->watchpoint_triggered == watch_triggered_unknown
3202 && b->type == bp_hardware_watchpoint)
3203 /* We were stopped by a hardware watchpoint, but the target could
3204 not report the data address. We must check the watchpoint's
3205 value. Access and read watchpoints are out of luck; without
3206 a data address, we can't figure it out. */
3207 must_check_value = 1;
3209 if (must_check_value)
3211 char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n",
3213 struct cleanup *cleanups = make_cleanup (xfree, message);
3214 int e = catch_errors (watchpoint_check, bs, message,
3216 do_cleanups (cleanups);
3220 /* We've already printed what needs to be printed. */
3221 bs->print_it = print_it_done;
3224 case WP_VALUE_CHANGED:
3225 if (b->type == bp_read_watchpoint)
3227 /* Don't stop: read watchpoints shouldn't fire if
3228 the value has changed. This is for targets
3229 which cannot set read-only watchpoints. */
3230 bs->print_it = print_it_noop;
3234 case WP_VALUE_NOT_CHANGED:
3235 if (b->type == bp_hardware_watchpoint
3236 || b->type == bp_watchpoint)
3238 /* Don't stop: write watchpoints shouldn't fire if
3239 the value hasn't changed. */
3240 bs->print_it = print_it_noop;
3248 /* Error from catch_errors. */
3249 printf_filtered (_("Watchpoint %d deleted.\n"), b->number);
3250 if (b->related_breakpoint)
3251 b->related_breakpoint->disposition = disp_del_at_next_stop;
3252 b->disposition = disp_del_at_next_stop;
3253 /* We've already printed what needs to be printed. */
3254 bs->print_it = print_it_done;
3258 else /* must_check_value == 0 */
3260 /* This is a case where some watchpoint(s) triggered, but
3261 not at the address of this watchpoint, or else no
3262 watchpoint triggered after all. So don't print
3263 anything for this watchpoint. */
3264 bs->print_it = print_it_noop;
3271 /* Check conditions (condition proper, frame, thread and ignore count)
3272 of breakpoint referred to by BS. If we should not stop for this
3273 breakpoint, set BS->stop to 0. */
3275 bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
3277 int thread_id = pid_to_thread_id (ptid);
3278 const struct bp_location *bl = bs->breakpoint_at;
3279 struct breakpoint *b = bl->owner;
3281 if (frame_id_p (b->frame_id)
3282 && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ())))
3286 int value_is_zero = 0;
3288 /* If this is a scope breakpoint, mark the associated
3289 watchpoint as triggered so that we will handle the
3290 out-of-scope event. We'll get to the watchpoint next
3292 if (b->type == bp_watchpoint_scope)
3293 b->related_breakpoint->watchpoint_triggered = watch_triggered_yes;
3295 if (bl->cond && bl->owner->disposition != disp_del_at_next_stop)
3297 /* We use value_mark and value_free_to_mark because it could
3298 be a long time before we return to the command level and
3299 call free_all_values. We can't call free_all_values
3300 because we might be in the middle of evaluating a
3302 struct value *mark = value_mark ();
3304 /* Need to select the frame, with all that implies so that
3305 the conditions will have the right context. Because we
3306 use the frame, we will not see an inlined function's
3307 variables when we arrive at a breakpoint at the start
3308 of the inlined function; the current frame will be the
3310 select_frame (get_current_frame ());
3312 = catch_errors (breakpoint_cond_eval, (bl->cond),
3313 "Error in testing breakpoint condition:\n",
3315 /* FIXME-someday, should give breakpoint # */
3316 value_free_to_mark (mark);
3318 if (bl->cond && value_is_zero)
3322 else if (b->thread != -1 && b->thread != thread_id)
3326 else if (b->ignore_count > 0)
3329 annotate_ignore_count_change ();
3331 /* Increase the hit count even though we don't
3339 /* Get a bpstat associated with having just stopped at address
3340 BP_ADDR in thread PTID.
3342 Determine whether we stopped at a breakpoint, etc, or whether we
3343 don't understand this stop. Result is a chain of bpstat's such that:
3345 if we don't understand the stop, the result is a null pointer.
3347 if we understand why we stopped, the result is not null.
3349 Each element of the chain refers to a particular breakpoint or
3350 watchpoint at which we have stopped. (We may have stopped for
3351 several reasons concurrently.)
3353 Each element of the chain has valid next, breakpoint_at,
3354 commands, FIXME??? fields. */
3357 bpstat_stop_status (struct address_space *aspace,
3358 CORE_ADDR bp_addr, ptid_t ptid)
3360 struct breakpoint *b = NULL;
3361 const struct bp_location *bl;
3362 struct bp_location *loc;
3363 /* Root of the chain of bpstat's */
3364 struct bpstats root_bs[1];
3365 /* Pointer to the last thing in the chain currently. */
3366 bpstat bs = root_bs;
3368 int need_remove_insert;
3370 ALL_BP_LOCATIONS (bl)
3374 if (!breakpoint_enabled (b) && b->enable_state != bp_permanent)
3377 /* For hardware watchpoints, we look only at the first location.
3378 The watchpoint_check function will work on entire expression,
3379 not the individual locations. For read watchopints, the
3380 watchpoints_triggered function have checked all locations
3383 if (b->type == bp_hardware_watchpoint && bl != b->loc)
3386 if (!bpstat_check_location (bl, aspace, bp_addr))
3389 /* Come here if it's a watchpoint, or if the break address matches */
3391 bs = bpstat_alloc (bl, bs); /* Alloc a bpstat to explain stop */
3393 /* Assume we stop. Should we find watchpoint that is not actually
3394 triggered, or if condition of breakpoint is false, we'll reset
3399 bpstat_check_watchpoint (bs);
3403 if (b->type == bp_thread_event || b->type == bp_overlay_event
3404 || b->type == bp_longjmp_master)
3405 /* We do not stop for these. */
3408 bpstat_check_breakpoint_conditions (bs, ptid);
3414 /* We will stop here */
3415 if (b->disposition == disp_disable)
3417 if (b->enable_state != bp_permanent)
3418 b->enable_state = bp_disabled;
3419 update_global_location_list (0);
3423 bs->commands = b->commands;
3425 && (strcmp ("silent", bs->commands->line) == 0
3426 || (xdb_commands && strcmp ("Q", bs->commands->line) == 0)))
3428 bs->commands = bs->commands->next;
3431 bs->commands = copy_command_lines (bs->commands);
3434 /* Print nothing for this entry if we dont stop or if we dont print. */
3435 if (bs->stop == 0 || bs->print == 0)
3436 bs->print_it = print_it_noop;
3439 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
3441 if (breakpoint_address_match (loc->pspace->aspace, loc->address,
3444 bs = bpstat_alloc (loc, bs);
3445 /* For hits of moribund locations, we should just proceed. */
3448 bs->print_it = print_it_noop;
3452 bs->next = NULL; /* Terminate the chain */
3453 bs = root_bs->next; /* Re-grab the head of the chain */
3455 /* If we aren't stopping, the value of some hardware watchpoint may
3456 not have changed, but the intermediate memory locations we are
3457 watching may have. Don't bother if we're stopping; this will get
3459 for (bs = root_bs->next; bs != NULL; bs = bs->next)
3463 need_remove_insert = 0;
3465 for (bs = root_bs->next; bs != NULL; bs = bs->next)
3467 && bs->breakpoint_at->owner
3468 && (bs->breakpoint_at->owner->type == bp_hardware_watchpoint
3469 || bs->breakpoint_at->owner->type == bp_read_watchpoint
3470 || bs->breakpoint_at->owner->type == bp_access_watchpoint))
3472 /* remove/insert can invalidate bs->breakpoint_at, if this
3473 location is no longer used by the watchpoint. Prevent
3474 further code from trying to use it. */
3475 bs->breakpoint_at = NULL;
3476 need_remove_insert = 1;
3479 if (need_remove_insert)
3481 remove_breakpoints ();
3482 insert_breakpoints ();
3485 return root_bs->next;
3488 /* Tell what to do about this bpstat. */
3490 bpstat_what (bpstat bs)
3492 /* Classify each bpstat as one of the following. */
3495 /* This bpstat element has no effect on the main_action. */
3498 /* There was a watchpoint, stop but don't print. */
3501 /* There was a watchpoint, stop and print. */
3504 /* There was a breakpoint but we're not stopping. */
3507 /* There was a breakpoint, stop but don't print. */
3510 /* There was a breakpoint, stop and print. */
3513 /* We hit the longjmp breakpoint. */
3516 /* We hit the longjmp_resume breakpoint. */
3519 /* We hit the step_resume breakpoint. */
3522 /* We hit the shared library event breakpoint. */
3525 /* We hit the jit event breakpoint. */
3528 /* This is just used to count how many enums there are. */
3532 /* Here is the table which drives this routine. So that we can
3533 format it pretty, we define some abbreviations for the
3534 enum bpstat_what codes. */
3535 #define kc BPSTAT_WHAT_KEEP_CHECKING
3536 #define ss BPSTAT_WHAT_STOP_SILENT
3537 #define sn BPSTAT_WHAT_STOP_NOISY
3538 #define sgl BPSTAT_WHAT_SINGLE
3539 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3540 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3541 #define sr BPSTAT_WHAT_STEP_RESUME
3542 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3543 #define jit BPSTAT_WHAT_CHECK_JIT
3545 /* "Can't happen." Might want to print an error message.
3546 abort() is not out of the question, but chances are GDB is just
3547 a bit confused, not unusable. */
3548 #define err BPSTAT_WHAT_STOP_NOISY
3550 /* Given an old action and a class, come up with a new action. */
3551 /* One interesting property of this table is that wp_silent is the same
3552 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3553 after stopping, the check for whether to step over a breakpoint
3554 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3555 reference to how we stopped. We retain separate wp_silent and
3556 bp_silent codes in case we want to change that someday.
3558 Another possibly interesting property of this table is that
3559 there's a partial ordering, priority-like, of the actions. Once
3560 you've decided that some action is appropriate, you'll never go
3561 back and decide something of a lower priority is better. The
3564 kc < jit clr sgl shl slr sn sr ss
3565 sgl < jit shl slr sn sr ss
3566 slr < jit err shl sn sr ss
3567 clr < jit err shl sn sr ss
3574 What I think this means is that we don't need a damned table
3575 here. If you just put the rows and columns in the right order,
3576 it'd look awfully regular. We could simply walk the bpstat list
3577 and choose the highest priority action we find, with a little
3578 logic to handle the 'err' cases. */
3580 /* step_resume entries: a step resume breakpoint overrides another
3581 breakpoint of signal handling (see comment in wait_for_inferior
3582 at where we set the step_resume breakpoint). */
3584 static const enum bpstat_what_main_action
3585 table[(int) class_last][(int) BPSTAT_WHAT_LAST] =
3588 /* kc ss sn sgl slr clr sr shl jit */
3589 /* no_effect */ {kc, ss, sn, sgl, slr, clr, sr, shl, jit},
3590 /* wp_silent */ {ss, ss, sn, ss, ss, ss, sr, shl, jit},
3591 /* wp_noisy */ {sn, sn, sn, sn, sn, sn, sr, shl, jit},
3592 /* bp_nostop */ {sgl, ss, sn, sgl, slr, slr, sr, shl, jit},
3593 /* bp_silent */ {ss, ss, sn, ss, ss, ss, sr, shl, jit},
3594 /* bp_noisy */ {sn, sn, sn, sn, sn, sn, sr, shl, jit},
3595 /* long_jump */ {slr, ss, sn, slr, slr, err, sr, shl, jit},
3596 /* long_resume */ {clr, ss, sn, err, err, err, sr, shl, jit},
3597 /* step_resume */ {sr, sr, sr, sr, sr, sr, sr, sr, sr },
3598 /* shlib */ {shl, shl, shl, shl, shl, shl, sr, shl, shl},
3599 /* jit_event */ {jit, jit, jit, jit, jit, jit, sr, jit, jit}
3613 enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
3614 struct bpstat_what retval;
3616 retval.call_dummy = 0;
3617 for (; bs != NULL; bs = bs->next)
3619 enum class bs_class = no_effect;
3620 if (bs->breakpoint_at == NULL)
3621 /* I suspect this can happen if it was a momentary breakpoint
3622 which has since been deleted. */
3624 if (bs->breakpoint_at->owner == NULL)
3625 bs_class = bp_nostop;
3627 switch (bs->breakpoint_at->owner->type)
3633 case bp_hardware_breakpoint:
3639 bs_class = bp_noisy;
3641 bs_class = bp_silent;
3644 bs_class = bp_nostop;
3647 case bp_hardware_watchpoint:
3648 case bp_read_watchpoint:
3649 case bp_access_watchpoint:
3653 bs_class = wp_noisy;
3655 bs_class = wp_silent;
3658 /* There was a watchpoint, but we're not stopping.
3659 This requires no further action. */
3660 bs_class = no_effect;
3663 bs_class = long_jump;
3665 case bp_longjmp_resume:
3666 bs_class = long_resume;
3668 case bp_step_resume:
3671 bs_class = step_resume;
3674 /* It is for the wrong frame. */
3675 bs_class = bp_nostop;
3677 case bp_watchpoint_scope:
3678 bs_class = bp_nostop;
3680 case bp_shlib_event:
3681 bs_class = shlib_event;
3684 bs_class = jit_event;
3686 case bp_thread_event:
3687 case bp_overlay_event:
3688 case bp_longjmp_master:
3689 bs_class = bp_nostop;
3695 bs_class = bp_noisy;
3697 bs_class = bp_silent;
3700 /* There was a catchpoint, but we're not stopping.
3701 This requires no further action. */
3702 bs_class = no_effect;
3705 /* Make sure the action is stop (silent or noisy),
3706 so infrun.c pops the dummy frame. */
3707 bs_class = bp_silent;
3708 retval.call_dummy = 1;
3711 /* Tracepoint hits should not be reported back to GDB, and
3712 if one got through somehow, it should have been filtered
3714 internal_error (__FILE__, __LINE__,
3715 _("bpstat_what: bp_tracepoint encountered"));
3718 current_action = table[(int) bs_class][(int) current_action];
3720 retval.main_action = current_action;
3724 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3725 without hardware support). This isn't related to a specific bpstat,
3726 just to things like whether watchpoints are set. */
3729 bpstat_should_step (void)
3731 struct breakpoint *b;
3733 if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL)
3740 static void print_breakpoint_location (struct breakpoint *b,
3741 struct bp_location *loc,
3743 struct ui_stream *stb)
3745 struct cleanup *old_chain = save_current_program_space ();
3748 set_current_program_space (loc->pspace);
3753 = find_pc_sect_function (loc->address, loc->section);
3756 ui_out_text (uiout, "in ");
3757 ui_out_field_string (uiout, "func",
3758 SYMBOL_PRINT_NAME (sym));
3759 ui_out_wrap_hint (uiout, wrap_indent);
3760 ui_out_text (uiout, " at ");
3762 ui_out_field_string (uiout, "file", b->source_file);
3763 ui_out_text (uiout, ":");
3765 if (ui_out_is_mi_like_p (uiout))
3767 struct symtab_and_line sal = find_pc_line (loc->address, 0);
3768 char *fullname = symtab_to_fullname (sal.symtab);
3771 ui_out_field_string (uiout, "fullname", fullname);
3774 ui_out_field_int (uiout, "line", b->line_number);
3778 ui_out_field_string (uiout, "pending", b->addr_string);
3782 print_address_symbolic (loc->address, stb->stream, demangle, "");
3783 ui_out_field_stream (uiout, "at", stb);
3786 do_cleanups (old_chain);
3789 /* Print B to gdb_stdout. */
3791 print_one_breakpoint_location (struct breakpoint *b,
3792 struct bp_location *loc,
3794 struct bp_location **last_loc,
3795 int print_address_bits,
3798 struct command_line *l;
3800 struct ep_type_description
3805 static struct ep_type_description bptypes[] =
3807 {bp_none, "?deleted?"},
3808 {bp_breakpoint, "breakpoint"},
3809 {bp_hardware_breakpoint, "hw breakpoint"},
3810 {bp_until, "until"},
3811 {bp_finish, "finish"},
3812 {bp_watchpoint, "watchpoint"},
3813 {bp_hardware_watchpoint, "hw watchpoint"},
3814 {bp_read_watchpoint, "read watchpoint"},
3815 {bp_access_watchpoint, "acc watchpoint"},
3816 {bp_longjmp, "longjmp"},
3817 {bp_longjmp_resume, "longjmp resume"},
3818 {bp_step_resume, "step resume"},
3819 {bp_watchpoint_scope, "watchpoint scope"},
3820 {bp_call_dummy, "call dummy"},
3821 {bp_shlib_event, "shlib events"},
3822 {bp_thread_event, "thread events"},
3823 {bp_overlay_event, "overlay events"},
3824 {bp_longjmp_master, "longjmp master"},
3825 {bp_catchpoint, "catchpoint"},
3826 {bp_tracepoint, "tracepoint"},
3827 {bp_jit_event, "jit events"},
3830 static char bpenables[] = "nynny";
3831 char wrap_indent[80];
3832 struct ui_stream *stb = ui_out_stream_new (uiout);
3833 struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb);
3834 struct cleanup *bkpt_chain;
3836 int header_of_multiple = 0;
3837 int part_of_multiple = (loc != NULL);
3838 struct value_print_options opts;
3840 get_user_print_options (&opts);
3842 gdb_assert (!loc || loc_number != 0);
3843 /* See comment in print_one_breakpoint concerning
3844 treatment of breakpoints with single disabled
3848 && (b->loc->next != NULL || !b->loc->enabled)))
3849 header_of_multiple = 1;
3854 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
3858 if (part_of_multiple)
3861 formatted = xstrprintf ("%d.%d", b->number, loc_number);
3862 ui_out_field_string (uiout, "number", formatted);
3867 ui_out_field_int (uiout, "number", b->number);
3872 if (part_of_multiple)
3873 ui_out_field_skip (uiout, "type");
3876 if (((int) b->type >= (sizeof (bptypes) / sizeof (bptypes[0])))
3877 || ((int) b->type != bptypes[(int) b->type].type))
3878 internal_error (__FILE__, __LINE__,
3879 _("bptypes table does not describe type #%d."),
3881 ui_out_field_string (uiout, "type", bptypes[(int) b->type].description);
3886 if (part_of_multiple)
3887 ui_out_field_skip (uiout, "disp");
3889 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
3894 if (part_of_multiple)
3895 ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n");
3897 ui_out_field_fmt (uiout, "enabled", "%c",
3898 bpenables[(int) b->enable_state]);
3899 ui_out_spaces (uiout, 2);
3903 strcpy (wrap_indent, " ");
3904 if (opts.addressprint)
3906 if (print_address_bits <= 32)
3907 strcat (wrap_indent, " ");
3909 strcat (wrap_indent, " ");
3912 if (b->ops != NULL && b->ops->print_one != NULL)
3914 /* Although the print_one can possibly print
3915 all locations, calling it here is not likely
3916 to get any nice result. So, make sure there's
3917 just one location. */
3918 gdb_assert (b->loc == NULL || b->loc->next == NULL);
3919 b->ops->print_one (b, last_loc);
3925 internal_error (__FILE__, __LINE__,
3926 _("print_one_breakpoint: bp_none encountered\n"));
3930 case bp_hardware_watchpoint:
3931 case bp_read_watchpoint:
3932 case bp_access_watchpoint:
3933 /* Field 4, the address, is omitted (which makes the columns
3934 not line up too nicely with the headers, but the effect
3935 is relatively readable). */
3936 if (opts.addressprint)
3937 ui_out_field_skip (uiout, "addr");
3939 ui_out_field_string (uiout, "what", b->exp_string);
3943 case bp_hardware_breakpoint:
3947 case bp_longjmp_resume:
3948 case bp_step_resume:
3949 case bp_watchpoint_scope:
3951 case bp_shlib_event:
3952 case bp_thread_event:
3953 case bp_overlay_event:
3954 case bp_longjmp_master:
3957 if (opts.addressprint)
3960 if (header_of_multiple)
3961 ui_out_field_string (uiout, "addr", "<MULTIPLE>");
3962 else if (b->loc == NULL || loc->shlib_disabled)
3963 ui_out_field_string (uiout, "addr", "<PENDING>");
3965 ui_out_field_core_addr (uiout, "addr",
3966 loc->gdbarch, loc->address);
3969 if (!header_of_multiple)
3970 print_breakpoint_location (b, loc, wrap_indent, stb);
3977 /* For backward compatibility, don't display inferiors unless there
3980 && !header_of_multiple
3982 || (!gdbarch_has_global_breakpoints (target_gdbarch)
3983 && (number_of_program_spaces () > 1
3984 || number_of_inferiors () > 1)
3985 && loc->owner->type != bp_catchpoint)))
3987 struct inferior *inf;
3990 for (inf = inferior_list; inf != NULL; inf = inf->next)
3992 if (inf->pspace == loc->pspace)
3997 ui_out_text (uiout, " inf ");
4000 ui_out_text (uiout, ", ");
4001 ui_out_text (uiout, plongest (inf->num));
4006 if (!part_of_multiple)
4008 if (b->thread != -1)
4010 /* FIXME: This seems to be redundant and lost here; see the
4011 "stop only in" line a little further down. */
4012 ui_out_text (uiout, " thread ");
4013 ui_out_field_int (uiout, "thread", b->thread);
4015 else if (b->task != 0)
4017 ui_out_text (uiout, " task ");
4018 ui_out_field_int (uiout, "task", b->task);
4022 ui_out_text (uiout, "\n");
4024 if (part_of_multiple && frame_id_p (b->frame_id))
4027 ui_out_text (uiout, "\tstop only in stack frame at ");
4028 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
4030 ui_out_field_core_addr (uiout, "frame",
4031 b->gdbarch, b->frame_id.stack_addr);
4032 ui_out_text (uiout, "\n");
4035 if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b))
4037 /* We do not print the condition for Ada exception catchpoints
4038 because the condition is an internal implementation detail
4039 that we do not want to expose to the user. */
4041 if (b->type == bp_tracepoint)
4042 ui_out_text (uiout, "\ttrace only if ");
4044 ui_out_text (uiout, "\tstop only if ");
4045 ui_out_field_string (uiout, "cond", b->cond_string);
4046 ui_out_text (uiout, "\n");
4049 if (!part_of_multiple && b->thread != -1)
4051 /* FIXME should make an annotation for this */
4052 ui_out_text (uiout, "\tstop only in thread ");
4053 ui_out_field_int (uiout, "thread", b->thread);
4054 ui_out_text (uiout, "\n");
4057 if (!part_of_multiple && b->hit_count)
4059 /* FIXME should make an annotation for this */
4060 if (ep_is_catchpoint (b))
4061 ui_out_text (uiout, "\tcatchpoint");
4063 ui_out_text (uiout, "\tbreakpoint");
4064 ui_out_text (uiout, " already hit ");
4065 ui_out_field_int (uiout, "times", b->hit_count);
4066 if (b->hit_count == 1)
4067 ui_out_text (uiout, " time\n");
4069 ui_out_text (uiout, " times\n");
4072 /* Output the count also if it is zero, but only if this is
4073 mi. FIXME: Should have a better test for this. */
4074 if (ui_out_is_mi_like_p (uiout))
4075 if (!part_of_multiple && b->hit_count == 0)
4076 ui_out_field_int (uiout, "times", b->hit_count);
4078 if (!part_of_multiple && b->ignore_count)
4081 ui_out_text (uiout, "\tignore next ");
4082 ui_out_field_int (uiout, "ignore", b->ignore_count);
4083 ui_out_text (uiout, " hits\n");
4087 if (!part_of_multiple && l)
4089 struct cleanup *script_chain;
4092 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
4093 print_command_lines (uiout, l, 4);
4094 do_cleanups (script_chain);
4097 if (!part_of_multiple && b->pass_count)
4099 annotate_field (10);
4100 ui_out_text (uiout, "\tpass count ");
4101 ui_out_field_int (uiout, "pass", b->pass_count);
4102 ui_out_text (uiout, " \n");
4105 if (!part_of_multiple && b->step_count)
4107 annotate_field (11);
4108 ui_out_text (uiout, "\tstep count ");
4109 ui_out_field_int (uiout, "step", b->step_count);
4110 ui_out_text (uiout, " \n");
4113 if (!part_of_multiple && b->actions)
4115 struct action_line *action;
4116 annotate_field (12);
4117 for (action = b->actions; action; action = action->next)
4119 ui_out_text (uiout, " A\t");
4120 ui_out_text (uiout, action->action);
4121 ui_out_text (uiout, "\n");
4125 if (ui_out_is_mi_like_p (uiout) && !part_of_multiple)
4128 ui_out_field_string (uiout, "original-location", b->addr_string);
4129 else if (b->exp_string)
4130 ui_out_field_string (uiout, "original-location", b->exp_string);
4133 do_cleanups (bkpt_chain);
4134 do_cleanups (old_chain);
4138 print_one_breakpoint (struct breakpoint *b,
4139 struct bp_location **last_loc, int print_address_bits,
4142 print_one_breakpoint_location (b, NULL, 0, last_loc,
4143 print_address_bits, allflag);
4145 /* If this breakpoint has custom print function,
4146 it's already printed. Otherwise, print individual
4147 locations, if any. */
4148 if (b->ops == NULL || b->ops->print_one == NULL)
4150 /* If breakpoint has a single location that is
4151 disabled, we print it as if it had
4152 several locations, since otherwise it's hard to
4153 represent "breakpoint enabled, location disabled"
4155 Note that while hardware watchpoints have
4156 several locations internally, that's no a property
4159 && !is_hardware_watchpoint (b)
4160 && (b->loc->next || !b->loc->enabled)
4161 && !ui_out_is_mi_like_p (uiout))
4163 struct bp_location *loc;
4165 for (loc = b->loc; loc; loc = loc->next, ++n)
4166 print_one_breakpoint_location (b, loc, n, last_loc,
4167 print_address_bits, allflag);
4173 breakpoint_address_bits (struct breakpoint *b)
4175 int print_address_bits = 0;
4176 struct bp_location *loc;
4178 for (loc = b->loc; loc; loc = loc->next)
4180 int addr_bit = gdbarch_addr_bit (b->gdbarch);
4181 if (addr_bit > print_address_bits)
4182 print_address_bits = addr_bit;
4185 return print_address_bits;
4188 struct captured_breakpoint_query_args
4194 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
4196 struct captured_breakpoint_query_args *args = data;
4197 struct breakpoint *b;
4198 struct bp_location *dummy_loc = NULL;
4201 if (args->bnum == b->number)
4203 int print_address_bits = breakpoint_address_bits (b);
4204 print_one_breakpoint (b, &dummy_loc, print_address_bits, 0);
4212 gdb_breakpoint_query (struct ui_out *uiout, int bnum, char **error_message)
4214 struct captured_breakpoint_query_args args;
4216 /* For the moment we don't trust print_one_breakpoint() to not throw
4218 if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args,
4219 error_message, RETURN_MASK_ALL) < 0)
4225 /* Return non-zero if B is user settable (breakpoints, watchpoints,
4226 catchpoints, et.al.). */
4229 user_settable_breakpoint (const struct breakpoint *b)
4231 return (b->type == bp_breakpoint
4232 || b->type == bp_catchpoint
4233 || b->type == bp_hardware_breakpoint
4234 || b->type == bp_tracepoint
4235 || b->type == bp_watchpoint
4236 || b->type == bp_read_watchpoint
4237 || b->type == bp_access_watchpoint
4238 || b->type == bp_hardware_watchpoint);
4241 /* Print information on user settable breakpoint (watchpoint, etc)
4242 number BNUM. If BNUM is -1 print all user settable breakpoints.
4243 If ALLFLAG is non-zero, include non- user settable breakpoints. */
4246 breakpoint_1 (int bnum, int allflag)
4248 struct breakpoint *b;
4249 struct bp_location *last_loc = NULL;
4250 int nr_printable_breakpoints;
4251 struct cleanup *bkpttbl_chain;
4252 struct value_print_options opts;
4253 int print_address_bits = 0;
4255 get_user_print_options (&opts);
4257 /* Compute the number of rows in the table, as well as the
4258 size required for address fields. */
4259 nr_printable_breakpoints = 0;
4262 || bnum == b->number)
4264 if (allflag || user_settable_breakpoint (b))
4266 int addr_bit = breakpoint_address_bits (b);
4267 if (addr_bit > print_address_bits)
4268 print_address_bits = addr_bit;
4270 nr_printable_breakpoints++;
4274 if (opts.addressprint)
4276 = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints,
4280 = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints,
4283 if (nr_printable_breakpoints > 0)
4284 annotate_breakpoints_headers ();
4285 if (nr_printable_breakpoints > 0)
4287 ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */
4288 if (nr_printable_breakpoints > 0)
4290 ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */
4291 if (nr_printable_breakpoints > 0)
4293 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
4294 if (nr_printable_breakpoints > 0)
4296 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
4297 if (opts.addressprint)
4299 if (nr_printable_breakpoints > 0)
4301 if (print_address_bits <= 32)
4302 ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */
4304 ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */
4306 if (nr_printable_breakpoints > 0)
4308 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
4309 ui_out_table_body (uiout);
4310 if (nr_printable_breakpoints > 0)
4311 annotate_breakpoints_table ();
4315 || bnum == b->number)
4317 /* We only print out user settable breakpoints unless the
4319 if (allflag || user_settable_breakpoint (b))
4320 print_one_breakpoint (b, &last_loc, print_address_bits, allflag);
4323 do_cleanups (bkpttbl_chain);
4325 if (nr_printable_breakpoints == 0)
4328 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
4330 ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n",
4335 if (last_loc && !server_command)
4336 set_next_address (last_loc->gdbarch, last_loc->address);
4339 /* FIXME? Should this be moved up so that it is only called when
4340 there have been breakpoints? */
4341 annotate_breakpoints_table_end ();
4345 breakpoints_info (char *bnum_exp, int from_tty)
4350 bnum = parse_and_eval_long (bnum_exp);
4352 breakpoint_1 (bnum, 0);
4356 maintenance_info_breakpoints (char *bnum_exp, int from_tty)
4361 bnum = parse_and_eval_long (bnum_exp);
4363 breakpoint_1 (bnum, 1);
4367 breakpoint_has_pc (struct breakpoint *b,
4368 struct program_space *pspace,
4369 CORE_ADDR pc, struct obj_section *section)
4371 struct bp_location *bl = b->loc;
4372 for (; bl; bl = bl->next)
4374 if (bl->pspace == pspace
4375 && bl->address == pc
4376 && (!overlay_debugging || bl->section == section))
4382 /* Print a message describing any breakpoints set at PC. This
4383 concerns with logical breakpoints, so we match program spaces, not
4387 describe_other_breakpoints (struct gdbarch *gdbarch,
4388 struct program_space *pspace, CORE_ADDR pc,
4389 struct obj_section *section, int thread)
4392 struct breakpoint *b;
4395 others += breakpoint_has_pc (b, pspace, pc, section);
4399 printf_filtered (_("Note: breakpoint "));
4400 else /* if (others == ???) */
4401 printf_filtered (_("Note: breakpoints "));
4403 if (breakpoint_has_pc (b, pspace, pc, section))
4406 printf_filtered ("%d", b->number);
4407 if (b->thread == -1 && thread != -1)
4408 printf_filtered (" (all threads)");
4409 else if (b->thread != -1)
4410 printf_filtered (" (thread %d)", b->thread);
4411 printf_filtered ("%s%s ",
4412 ((b->enable_state == bp_disabled
4413 || b->enable_state == bp_call_disabled
4414 || b->enable_state == bp_startup_disabled)
4416 : b->enable_state == bp_permanent
4420 : ((others == 1) ? " and" : ""));
4422 printf_filtered (_("also set at pc "));
4423 fputs_filtered (paddress (gdbarch, pc), gdb_stdout);
4424 printf_filtered (".\n");
4428 /* Set the default place to put a breakpoint
4429 for the `break' command with no arguments. */
4432 set_default_breakpoint (int valid, struct program_space *pspace,
4433 CORE_ADDR addr, struct symtab *symtab,
4436 default_breakpoint_valid = valid;
4437 default_breakpoint_pspace = pspace;
4438 default_breakpoint_address = addr;
4439 default_breakpoint_symtab = symtab;
4440 default_breakpoint_line = line;
4443 /* Return true iff it is meaningful to use the address member of
4444 BPT. For some breakpoint types, the address member is irrelevant
4445 and it makes no sense to attempt to compare it to other addresses
4446 (or use it for any other purpose either).
4448 More specifically, each of the following breakpoint types will always
4449 have a zero valued address and we don't want check_duplicates() to mark
4450 breakpoints of any of these types to be a duplicate of an actual
4451 breakpoint at address zero:
4454 bp_hardware_watchpoint
4456 bp_access_watchpoint
4460 breakpoint_address_is_meaningful (struct breakpoint *bpt)
4462 enum bptype type = bpt->type;
4464 return (type != bp_watchpoint
4465 && type != bp_hardware_watchpoint
4466 && type != bp_read_watchpoint
4467 && type != bp_access_watchpoint
4468 && type != bp_catchpoint);
4471 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
4472 same breakpoint location. In most targets, this can only be true
4473 if ASPACE1 matches ASPACE2. On targets that have global
4474 breakpoints, the address space doesn't really matter. */
4477 breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1,
4478 struct address_space *aspace2, CORE_ADDR addr2)
4480 return ((gdbarch_has_global_breakpoints (target_gdbarch)
4481 || aspace1 == aspace2)
4485 /* Rescan breakpoints at the same address and section as BPT,
4486 marking the first one as "first" and any others as "duplicates".
4487 This is so that the bpt instruction is only inserted once.
4488 If we have a permanent breakpoint at the same place as BPT, make
4489 that one the official one, and the rest as duplicates. */
4492 check_duplicates_for (struct address_space *aspace,
4494 struct obj_section *section)
4496 struct bp_location *b;
4498 struct bp_location *perm_bp = 0;
4500 ALL_BP_LOCATIONS (b)
4501 if (b->owner->enable_state != bp_disabled
4502 && b->owner->enable_state != bp_call_disabled
4503 && b->owner->enable_state != bp_startup_disabled
4505 && !b->shlib_disabled
4506 && (!overlay_debugging || b->section == section)
4507 && breakpoint_address_is_meaningful (b->owner)
4508 && breakpoint_address_match (b->pspace->aspace, b->address,
4511 /* Have we found a permanent breakpoint? */
4512 if (b->owner->enable_state == bp_permanent)
4519 b->duplicate = count > 1;
4522 /* If we found a permanent breakpoint at this address, go over the
4523 list again and declare all the other breakpoints there (except
4524 other permanent breakpoints) to be the duplicates. */
4527 perm_bp->duplicate = 0;
4529 /* Permanent breakpoint should always be inserted. */
4530 if (! perm_bp->inserted)
4531 internal_error (__FILE__, __LINE__,
4532 _("allegedly permanent breakpoint is not "
4533 "actually inserted"));
4535 ALL_BP_LOCATIONS (b)
4538 if (b->owner->enable_state != bp_permanent
4539 && b->owner->enable_state != bp_disabled
4540 && b->owner->enable_state != bp_call_disabled
4541 && b->owner->enable_state != bp_startup_disabled
4542 && b->enabled && !b->shlib_disabled
4543 && breakpoint_address_is_meaningful (b->owner)
4544 && breakpoint_address_match (b->pspace->aspace, b->address,
4546 && (!overlay_debugging || b->section == section))
4549 internal_error (__FILE__, __LINE__,
4550 _("another breakpoint was inserted on top of "
4551 "a permanent breakpoint"));
4560 check_duplicates (struct breakpoint *bpt)
4562 struct bp_location *bl = bpt->loc;
4564 if (! breakpoint_address_is_meaningful (bpt))
4567 for (; bl; bl = bl->next)
4568 check_duplicates_for (bl->pspace->aspace, bl->address, bl->section);
4572 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
4573 int bnum, int have_bnum)
4578 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
4579 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
4581 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4582 bnum, astr1, astr2);
4584 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
4587 /* Adjust a breakpoint's address to account for architectural constraints
4588 on breakpoint placement. Return the adjusted address. Note: Very
4589 few targets require this kind of adjustment. For most targets,
4590 this function is simply the identity function. */
4593 adjust_breakpoint_address (struct gdbarch *gdbarch,
4594 CORE_ADDR bpaddr, enum bptype bptype)
4596 if (!gdbarch_adjust_breakpoint_address_p (gdbarch))
4598 /* Very few targets need any kind of breakpoint adjustment. */
4601 else if (bptype == bp_watchpoint
4602 || bptype == bp_hardware_watchpoint
4603 || bptype == bp_read_watchpoint
4604 || bptype == bp_access_watchpoint
4605 || bptype == bp_catchpoint)
4607 /* Watchpoints and the various bp_catch_* eventpoints should not
4608 have their addresses modified. */
4613 CORE_ADDR adjusted_bpaddr;
4615 /* Some targets have architectural constraints on the placement
4616 of breakpoint instructions. Obtain the adjusted address. */
4617 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr);
4619 /* An adjusted breakpoint address can significantly alter
4620 a user's expectations. Print a warning if an adjustment
4622 if (adjusted_bpaddr != bpaddr)
4623 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
4625 return adjusted_bpaddr;
4629 /* Allocate a struct bp_location. */
4631 static struct bp_location *
4632 allocate_bp_location (struct breakpoint *bpt)
4634 struct bp_location *loc, *loc_p;
4636 loc = xmalloc (sizeof (struct bp_location));
4637 memset (loc, 0, sizeof (*loc));
4641 loc->shlib_disabled = 0;
4651 case bp_longjmp_resume:
4652 case bp_step_resume:
4653 case bp_watchpoint_scope:
4655 case bp_shlib_event:
4656 case bp_thread_event:
4657 case bp_overlay_event:
4659 case bp_longjmp_master:
4660 loc->loc_type = bp_loc_software_breakpoint;
4662 case bp_hardware_breakpoint:
4663 loc->loc_type = bp_loc_hardware_breakpoint;
4665 case bp_hardware_watchpoint:
4666 case bp_read_watchpoint:
4667 case bp_access_watchpoint:
4668 loc->loc_type = bp_loc_hardware_watchpoint;
4672 loc->loc_type = bp_loc_other;
4675 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
4681 static void free_bp_location (struct bp_location *loc)
4686 if (loc->function_name)
4687 xfree (loc->function_name);
4692 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4693 that has type BPTYPE and has no locations as yet. */
4694 /* This function is used in gdbtk sources and thus can not be made static. */
4696 static struct breakpoint *
4697 set_raw_breakpoint_without_location (struct gdbarch *gdbarch,
4700 struct breakpoint *b, *b1;
4702 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
4703 memset (b, 0, sizeof (*b));
4706 b->gdbarch = gdbarch;
4707 b->language = current_language->la_language;
4708 b->input_radix = input_radix;
4710 b->enable_state = bp_enabled;
4713 b->ignore_count = 0;
4715 b->frame_id = null_frame_id;
4716 b->forked_inferior_pid = null_ptid;
4717 b->exec_pathname = NULL;
4718 b->syscalls_to_be_caught = NULL;
4720 b->condition_not_parsed = 0;
4722 /* Add this breakpoint to the end of the chain
4723 so that a list of breakpoints will come out in order
4724 of increasing numbers. */
4726 b1 = breakpoint_chain;
4728 breakpoint_chain = b;
4738 /* Initialize loc->function_name. */
4740 set_breakpoint_location_function (struct bp_location *loc)
4742 if (loc->owner->type == bp_breakpoint
4743 || loc->owner->type == bp_hardware_breakpoint
4744 || loc->owner->type == bp_tracepoint)
4746 find_pc_partial_function (loc->address, &(loc->function_name),
4748 if (loc->function_name)
4749 loc->function_name = xstrdup (loc->function_name);
4753 /* Attempt to determine architecture of location identified by SAL. */
4754 static struct gdbarch *
4755 get_sal_arch (struct symtab_and_line sal)
4758 return get_objfile_arch (sal.section->objfile);
4760 return get_objfile_arch (sal.symtab->objfile);
4765 /* set_raw_breakpoint is a low level routine for allocating and
4766 partially initializing a breakpoint of type BPTYPE. The newly
4767 created breakpoint's address, section, source file name, and line
4768 number are provided by SAL. The newly created and partially
4769 initialized breakpoint is added to the breakpoint chain and
4770 is also returned as the value of this function.
4772 It is expected that the caller will complete the initialization of
4773 the newly created breakpoint struct as well as output any status
4774 information regarding the creation of a new breakpoint. In
4775 particular, set_raw_breakpoint does NOT set the breakpoint
4776 number! Care should be taken to not allow an error to occur
4777 prior to completing the initialization of the breakpoint. If this
4778 should happen, a bogus breakpoint will be left on the chain. */
4781 set_raw_breakpoint (struct gdbarch *gdbarch,
4782 struct symtab_and_line sal, enum bptype bptype)
4784 struct breakpoint *b = set_raw_breakpoint_without_location (gdbarch, bptype);
4785 CORE_ADDR adjusted_address;
4786 struct gdbarch *loc_gdbarch;
4788 loc_gdbarch = get_sal_arch (sal);
4790 loc_gdbarch = b->gdbarch;
4792 if (bptype != bp_catchpoint)
4793 gdb_assert (sal.pspace != NULL);
4795 /* Adjust the breakpoint's address prior to allocating a location.
4796 Once we call allocate_bp_location(), that mostly uninitialized
4797 location will be placed on the location chain. Adjustment of the
4798 breakpoint may cause target_read_memory() to be called and we do
4799 not want its scan of the location chain to find a breakpoint and
4800 location that's only been partially initialized. */
4801 adjusted_address = adjust_breakpoint_address (loc_gdbarch, sal.pc, b->type);
4803 b->loc = allocate_bp_location (b);
4804 b->loc->gdbarch = loc_gdbarch;
4805 b->loc->requested_address = sal.pc;
4806 b->loc->address = adjusted_address;
4807 b->loc->pspace = sal.pspace;
4809 /* Store the program space that was used to set the breakpoint, for
4810 breakpoint resetting. */
4811 b->pspace = sal.pspace;
4813 if (sal.symtab == NULL)
4814 b->source_file = NULL;
4816 b->source_file = xstrdup (sal.symtab->filename);
4817 b->loc->section = sal.section;
4818 b->line_number = sal.line;
4820 set_breakpoint_location_function (b->loc);
4822 breakpoints_changed ();
4828 /* Note that the breakpoint object B describes a permanent breakpoint
4829 instruction, hard-wired into the inferior's code. */
4831 make_breakpoint_permanent (struct breakpoint *b)
4833 struct bp_location *bl;
4834 b->enable_state = bp_permanent;
4836 /* By definition, permanent breakpoints are already present in the code.
4837 Mark all locations as inserted. For now, make_breakpoint_permanent
4838 is called in just one place, so it's hard to say if it's reasonable
4839 to have permanent breakpoint with multiple locations or not,
4840 but it's easy to implmement. */
4841 for (bl = b->loc; bl; bl = bl->next)
4845 /* Call this routine when stepping and nexting to enable a breakpoint
4846 if we do a longjmp() in THREAD. When we hit that breakpoint, call
4847 set_longjmp_resume_breakpoint() to figure out where we are going. */
4850 set_longjmp_breakpoint (int thread)
4852 struct breakpoint *b, *temp;
4854 /* To avoid having to rescan all objfile symbols at every step,
4855 we maintain a list of continually-inserted but always disabled
4856 longjmp "master" breakpoints. Here, we simply create momentary
4857 clones of those and enable them for the requested thread. */
4858 ALL_BREAKPOINTS_SAFE (b, temp)
4859 if (b->pspace == current_program_space
4860 && b->type == bp_longjmp_master)
4862 struct breakpoint *clone = clone_momentary_breakpoint (b);
4863 clone->type = bp_longjmp;
4864 clone->thread = thread;
4868 /* Delete all longjmp breakpoints from THREAD. */
4870 delete_longjmp_breakpoint (int thread)
4872 struct breakpoint *b, *temp;
4874 ALL_BREAKPOINTS_SAFE (b, temp)
4875 if (b->type == bp_longjmp)
4877 if (b->thread == thread)
4878 delete_breakpoint (b);
4883 enable_overlay_breakpoints (void)
4885 struct breakpoint *b;
4888 if (b->type == bp_overlay_event)
4890 b->enable_state = bp_enabled;
4891 update_global_location_list (1);
4892 overlay_events_enabled = 1;
4897 disable_overlay_breakpoints (void)
4899 struct breakpoint *b;
4902 if (b->type == bp_overlay_event)
4904 b->enable_state = bp_disabled;
4905 update_global_location_list (0);
4906 overlay_events_enabled = 0;
4911 create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
4913 struct breakpoint *b;
4915 b = create_internal_breakpoint (gdbarch, address, bp_thread_event);
4917 b->enable_state = bp_enabled;
4918 /* addr_string has to be used or breakpoint_re_set will delete me. */
4920 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
4922 update_global_location_list_nothrow (1);
4928 remove_thread_event_breakpoints (void)
4930 struct breakpoint *b, *temp;
4932 ALL_BREAKPOINTS_SAFE (b, temp)
4933 if (b->type == bp_thread_event
4934 && b->loc->pspace == current_program_space)
4935 delete_breakpoint (b);
4938 struct captured_parse_breakpoint_args
4941 struct symtabs_and_lines *sals_p;
4942 char ***addr_string_p;
4946 struct lang_and_radix
4952 /* Create a breakpoint for JIT code registration and unregistration. */
4955 create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
4957 struct breakpoint *b;
4959 b = create_internal_breakpoint (gdbarch, address, bp_jit_event);
4960 update_global_location_list_nothrow (1);
4965 remove_solib_event_breakpoints (void)
4967 struct breakpoint *b, *temp;
4969 ALL_BREAKPOINTS_SAFE (b, temp)
4970 if (b->type == bp_shlib_event
4971 && b->loc->pspace == current_program_space)
4972 delete_breakpoint (b);
4976 create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
4978 struct breakpoint *b;
4980 b = create_internal_breakpoint (gdbarch, address, bp_shlib_event);
4981 update_global_location_list_nothrow (1);
4985 /* Disable any breakpoints that are on code in shared libraries. Only
4986 apply to enabled breakpoints, disabled ones can just stay disabled. */
4989 disable_breakpoints_in_shlibs (void)
4991 struct bp_location *loc;
4993 ALL_BP_LOCATIONS (loc)
4995 struct breakpoint *b = loc->owner;
4996 /* We apply the check to all breakpoints, including disabled
4997 for those with loc->duplicate set. This is so that when breakpoint
4998 becomes enabled, or the duplicate is removed, gdb will try to insert
4999 all breakpoints. If we don't set shlib_disabled here, we'll try
5000 to insert those breakpoints and fail. */
5001 if (((b->type == bp_breakpoint)
5002 || (b->type == bp_hardware_breakpoint)
5003 || (b->type == bp_tracepoint))
5004 && loc->pspace == current_program_space
5005 && !loc->shlib_disabled
5007 && PC_SOLIB (loc->address)
5009 && solib_name_from_address (loc->pspace, loc->address)
5013 loc->shlib_disabled = 1;
5018 /* Disable any breakpoints that are in in an unloaded shared library. Only
5019 apply to enabled breakpoints, disabled ones can just stay disabled. */
5022 disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
5024 struct bp_location *loc;
5025 int disabled_shlib_breaks = 0;
5027 /* SunOS a.out shared libraries are always mapped, so do not
5028 disable breakpoints; they will only be reported as unloaded
5029 through clear_solib when GDB discards its shared library
5030 list. See clear_solib for more information. */
5031 if (exec_bfd != NULL
5032 && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour)
5035 ALL_BP_LOCATIONS (loc)
5037 struct breakpoint *b = loc->owner;
5038 if ((loc->loc_type == bp_loc_hardware_breakpoint
5039 || loc->loc_type == bp_loc_software_breakpoint)
5040 && solib->pspace == loc->pspace
5041 && !loc->shlib_disabled
5042 && (b->type == bp_breakpoint || b->type == bp_hardware_breakpoint)
5043 && solib_contains_address_p (solib, loc->address))
5045 loc->shlib_disabled = 1;
5046 /* At this point, we cannot rely on remove_breakpoint
5047 succeeding so we must mark the breakpoint as not inserted
5048 to prevent future errors occurring in remove_breakpoints. */
5050 if (!disabled_shlib_breaks)
5052 target_terminal_ours_for_output ();
5053 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
5056 disabled_shlib_breaks = 1;
5061 /* FORK & VFORK catchpoints. */
5063 /* Implement the "insert" breakpoint_ops method for fork catchpoints. */
5066 insert_catch_fork (struct breakpoint *b)
5068 target_insert_fork_catchpoint (PIDGET (inferior_ptid));
5071 /* Implement the "remove" breakpoint_ops method for fork catchpoints. */
5074 remove_catch_fork (struct breakpoint *b)
5076 return target_remove_fork_catchpoint (PIDGET (inferior_ptid));
5079 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
5083 breakpoint_hit_catch_fork (struct breakpoint *b)
5085 return inferior_has_forked (inferior_ptid, &b->forked_inferior_pid);
5088 /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */
5090 static enum print_stop_action
5091 print_it_catch_fork (struct breakpoint *b)
5093 annotate_catchpoint (b->number);
5094 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
5095 b->number, ptid_get_pid (b->forked_inferior_pid));
5096 return PRINT_SRC_AND_LOC;
5099 /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */
5102 print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc)
5104 struct value_print_options opts;
5106 get_user_print_options (&opts);
5108 /* Field 4, the address, is omitted (which makes the columns
5109 not line up too nicely with the headers, but the effect
5110 is relatively readable). */
5111 if (opts.addressprint)
5112 ui_out_field_skip (uiout, "addr");
5114 ui_out_text (uiout, "fork");
5115 if (!ptid_equal (b->forked_inferior_pid, null_ptid))
5117 ui_out_text (uiout, ", process ");
5118 ui_out_field_int (uiout, "what",
5119 ptid_get_pid (b->forked_inferior_pid));
5120 ui_out_spaces (uiout, 1);
5124 /* Implement the "print_mention" breakpoint_ops method for fork
5128 print_mention_catch_fork (struct breakpoint *b)
5130 printf_filtered (_("Catchpoint %d (fork)"), b->number);
5133 /* The breakpoint_ops structure to be used in fork catchpoints. */
5135 static struct breakpoint_ops catch_fork_breakpoint_ops =
5139 breakpoint_hit_catch_fork,
5140 print_it_catch_fork,
5141 print_one_catch_fork,
5142 print_mention_catch_fork
5145 /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */
5148 insert_catch_vfork (struct breakpoint *b)
5150 target_insert_vfork_catchpoint (PIDGET (inferior_ptid));
5153 /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */
5156 remove_catch_vfork (struct breakpoint *b)
5158 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid));
5161 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
5165 breakpoint_hit_catch_vfork (struct breakpoint *b)
5167 return inferior_has_vforked (inferior_ptid, &b->forked_inferior_pid);
5170 /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */
5172 static enum print_stop_action
5173 print_it_catch_vfork (struct breakpoint *b)
5175 annotate_catchpoint (b->number);
5176 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
5177 b->number, ptid_get_pid (b->forked_inferior_pid));
5178 return PRINT_SRC_AND_LOC;
5181 /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */
5184 print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc)
5186 struct value_print_options opts;
5188 get_user_print_options (&opts);
5189 /* Field 4, the address, is omitted (which makes the columns
5190 not line up too nicely with the headers, but the effect
5191 is relatively readable). */
5192 if (opts.addressprint)
5193 ui_out_field_skip (uiout, "addr");
5195 ui_out_text (uiout, "vfork");
5196 if (!ptid_equal (b->forked_inferior_pid, null_ptid))
5198 ui_out_text (uiout, ", process ");
5199 ui_out_field_int (uiout, "what",
5200 ptid_get_pid (b->forked_inferior_pid));
5201 ui_out_spaces (uiout, 1);
5205 /* Implement the "print_mention" breakpoint_ops method for vfork
5209 print_mention_catch_vfork (struct breakpoint *b)
5211 printf_filtered (_("Catchpoint %d (vfork)"), b->number);
5214 /* The breakpoint_ops structure to be used in vfork catchpoints. */
5216 static struct breakpoint_ops catch_vfork_breakpoint_ops =
5220 breakpoint_hit_catch_vfork,
5221 print_it_catch_vfork,
5222 print_one_catch_vfork,
5223 print_mention_catch_vfork
5226 /* Implement the "insert" breakpoint_ops method for syscall
5230 insert_catch_syscall (struct breakpoint *b)
5232 struct inferior *inf = current_inferior ();
5234 ++inf->total_syscalls_count;
5235 if (!b->syscalls_to_be_caught)
5236 ++inf->any_syscall_count;
5241 VEC_iterate (int, b->syscalls_to_be_caught, i, iter);
5245 if (iter >= VEC_length (int, inf->syscalls_counts))
5247 int old_size = VEC_length (int, inf->syscalls_counts);
5248 uintptr_t vec_addr_offset = old_size * ((uintptr_t) sizeof (int));
5250 VEC_safe_grow (int, inf->syscalls_counts, iter + 1);
5251 vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) +
5253 memset ((void *) vec_addr, 0,
5254 (iter + 1 - old_size) * sizeof (int));
5256 elem = VEC_index (int, inf->syscalls_counts, iter);
5257 VEC_replace (int, inf->syscalls_counts, iter, ++elem);
5261 target_set_syscall_catchpoint (PIDGET (inferior_ptid),
5262 inf->total_syscalls_count != 0,
5263 inf->any_syscall_count,
5264 VEC_length (int, inf->syscalls_counts),
5265 VEC_address (int, inf->syscalls_counts));
5268 /* Implement the "remove" breakpoint_ops method for syscall
5272 remove_catch_syscall (struct breakpoint *b)
5274 struct inferior *inf = current_inferior ();
5276 --inf->total_syscalls_count;
5277 if (!b->syscalls_to_be_caught)
5278 --inf->any_syscall_count;
5283 VEC_iterate (int, b->syscalls_to_be_caught, i, iter);
5287 if (iter >= VEC_length (int, inf->syscalls_counts))
5288 /* Shouldn't happen. */
5290 elem = VEC_index (int, inf->syscalls_counts, iter);
5291 VEC_replace (int, inf->syscalls_counts, iter, --elem);
5295 return target_set_syscall_catchpoint (PIDGET (inferior_ptid),
5296 inf->total_syscalls_count != 0,
5297 inf->any_syscall_count,
5298 VEC_length (int, inf->syscalls_counts),
5299 VEC_address (int, inf->syscalls_counts));
5302 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
5306 breakpoint_hit_catch_syscall (struct breakpoint *b)
5308 /* We must check if we are catching specific syscalls in this breakpoint.
5309 If we are, then we must guarantee that the called syscall is the same
5310 syscall we are catching. */
5311 int syscall_number = 0;
5313 if (!inferior_has_called_syscall (inferior_ptid, &syscall_number))
5316 /* Now, checking if the syscall is the same. */
5317 if (b->syscalls_to_be_caught)
5321 VEC_iterate (int, b->syscalls_to_be_caught, i, iter);
5323 if (syscall_number == iter)
5333 /* Implement the "print_it" breakpoint_ops method for syscall
5336 static enum print_stop_action
5337 print_it_catch_syscall (struct breakpoint *b)
5339 /* These are needed because we want to know in which state a
5340 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
5341 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
5342 must print "called syscall" or "returned from syscall". */
5344 struct target_waitstatus last;
5346 struct cleanup *old_chain;
5349 get_last_target_status (&ptid, &last);
5351 get_syscall_by_number (last.value.syscall_number, &s);
5353 annotate_catchpoint (b->number);
5356 syscall_id = xstrprintf ("%d", last.value.syscall_number);
5358 syscall_id = xstrprintf ("'%s'", s.name);
5360 old_chain = make_cleanup (xfree, syscall_id);
5362 if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY)
5363 printf_filtered (_("\nCatchpoint %d (call to syscall %s), "),
5364 b->number, syscall_id);
5365 else if (last.kind == TARGET_WAITKIND_SYSCALL_RETURN)
5366 printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "),
5367 b->number, syscall_id);
5369 do_cleanups (old_chain);
5371 return PRINT_SRC_AND_LOC;
5374 /* Implement the "print_one" breakpoint_ops method for syscall
5378 print_one_catch_syscall (struct breakpoint *b,
5379 struct bp_location **last_loc)
5381 struct value_print_options opts;
5383 get_user_print_options (&opts);
5384 /* Field 4, the address, is omitted (which makes the columns
5385 not line up too nicely with the headers, but the effect
5386 is relatively readable). */
5387 if (opts.addressprint)
5388 ui_out_field_skip (uiout, "addr");
5391 if (b->syscalls_to_be_caught
5392 && VEC_length (int, b->syscalls_to_be_caught) > 1)
5393 ui_out_text (uiout, "syscalls \"");
5395 ui_out_text (uiout, "syscall \"");
5397 if (b->syscalls_to_be_caught)
5400 char *text = xstrprintf ("%s", "");
5402 VEC_iterate (int, b->syscalls_to_be_caught, i, iter);
5407 get_syscall_by_number (iter, &s);
5410 text = xstrprintf ("%s%s, ", text, s.name);
5412 text = xstrprintf ("%s%d, ", text, iter);
5414 /* We have to xfree the last 'text' (now stored at 'x')
5415 because xstrprintf dinamically allocates new space for it
5419 /* Remove the last comma. */
5420 text[strlen (text) - 2] = '\0';
5421 ui_out_field_string (uiout, "what", text);
5424 ui_out_field_string (uiout, "what", "<any syscall>");
5425 ui_out_text (uiout, "\" ");
5428 /* Implement the "print_mention" breakpoint_ops method for syscall
5432 print_mention_catch_syscall (struct breakpoint *b)
5434 if (b->syscalls_to_be_caught)
5438 if (VEC_length (int, b->syscalls_to_be_caught) > 1)
5439 printf_filtered (_("Catchpoint %d (syscalls"), b->number);
5441 printf_filtered (_("Catchpoint %d (syscall"), b->number);
5444 VEC_iterate (int, b->syscalls_to_be_caught, i, iter);
5448 get_syscall_by_number (iter, &s);
5451 printf_filtered (" '%s' [%d]", s.name, s.number);
5453 printf_filtered (" %d", s.number);
5455 printf_filtered (")");
5458 printf_filtered (_("Catchpoint %d (any syscall)"),
5462 /* The breakpoint_ops structure to be used in syscall catchpoints. */
5464 static struct breakpoint_ops catch_syscall_breakpoint_ops =
5466 insert_catch_syscall,
5467 remove_catch_syscall,
5468 breakpoint_hit_catch_syscall,
5469 print_it_catch_syscall,
5470 print_one_catch_syscall,
5471 print_mention_catch_syscall
5474 /* Returns non-zero if 'b' is a syscall catchpoint. */
5477 syscall_catchpoint_p (struct breakpoint *b)
5479 return (b->ops == &catch_syscall_breakpoint_ops);
5482 /* Create a new breakpoint of the bp_catchpoint kind and return it,
5483 but does NOT mention it nor update the global location list.
5484 This is useful if you need to fill more fields in the
5485 struct breakpoint before calling mention.
5487 If TEMPFLAG is non-zero, then make the breakpoint temporary.
5488 If COND_STRING is not NULL, then store it in the breakpoint.
5489 OPS, if not NULL, is the breakpoint_ops structure associated
5490 to the catchpoint. */
5492 static struct breakpoint *
5493 create_catchpoint_without_mention (struct gdbarch *gdbarch, int tempflag,
5495 struct breakpoint_ops *ops)
5497 struct symtab_and_line sal;
5498 struct breakpoint *b;
5501 sal.pspace = current_program_space;
5503 b = set_raw_breakpoint (gdbarch, sal, bp_catchpoint);
5504 set_breakpoint_count (breakpoint_count + 1);
5505 b->number = breakpoint_count;
5507 b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string);
5509 b->addr_string = NULL;
5510 b->enable_state = bp_enabled;
5511 b->disposition = tempflag ? disp_del : disp_donttouch;
5517 /* Create a new breakpoint of the bp_catchpoint kind and return it.
5519 If TEMPFLAG is non-zero, then make the breakpoint temporary.
5520 If COND_STRING is not NULL, then store it in the breakpoint.
5521 OPS, if not NULL, is the breakpoint_ops structure associated
5522 to the catchpoint. */
5524 static struct breakpoint *
5525 create_catchpoint (struct gdbarch *gdbarch, int tempflag,
5526 char *cond_string, struct breakpoint_ops *ops)
5528 struct breakpoint *b =
5529 create_catchpoint_without_mention (gdbarch, tempflag, cond_string, ops);
5532 update_global_location_list (1);
5538 create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch,
5539 int tempflag, char *cond_string,
5540 struct breakpoint_ops *ops)
5542 struct breakpoint *b
5543 = create_catchpoint (gdbarch, tempflag, cond_string, ops);
5545 /* FIXME: We should put this information in a breakpoint private data
5547 b->forked_inferior_pid = null_ptid;
5550 /* Exec catchpoints. */
5553 insert_catch_exec (struct breakpoint *b)
5555 target_insert_exec_catchpoint (PIDGET (inferior_ptid));
5559 remove_catch_exec (struct breakpoint *b)
5561 return target_remove_exec_catchpoint (PIDGET (inferior_ptid));
5565 breakpoint_hit_catch_exec (struct breakpoint *b)
5567 return inferior_has_execd (inferior_ptid, &b->exec_pathname);
5570 static enum print_stop_action
5571 print_it_catch_exec (struct breakpoint *b)
5573 annotate_catchpoint (b->number);
5574 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number,
5576 return PRINT_SRC_AND_LOC;
5580 print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc)
5582 struct value_print_options opts;
5584 get_user_print_options (&opts);
5586 /* Field 4, the address, is omitted (which makes the columns
5587 not line up too nicely with the headers, but the effect
5588 is relatively readable). */
5589 if (opts.addressprint)
5590 ui_out_field_skip (uiout, "addr");
5592 ui_out_text (uiout, "exec");
5593 if (b->exec_pathname != NULL)
5595 ui_out_text (uiout, ", program \"");
5596 ui_out_field_string (uiout, "what", b->exec_pathname);
5597 ui_out_text (uiout, "\" ");
5602 print_mention_catch_exec (struct breakpoint *b)
5604 printf_filtered (_("Catchpoint %d (exec)"), b->number);
5607 static struct breakpoint_ops catch_exec_breakpoint_ops =
5611 breakpoint_hit_catch_exec,
5612 print_it_catch_exec,
5613 print_one_catch_exec,
5614 print_mention_catch_exec
5618 create_syscall_event_catchpoint (int tempflag, VEC(int) *filter,
5619 struct breakpoint_ops *ops)
5621 struct gdbarch *gdbarch = get_current_arch ();
5622 struct breakpoint *b =
5623 create_catchpoint_without_mention (gdbarch, tempflag, NULL, ops);
5625 b->syscalls_to_be_caught = filter;
5627 /* Now, we have to mention the breakpoint and update the global
5630 update_global_location_list (1);
5634 hw_breakpoint_used_count (void)
5636 struct breakpoint *b;
5641 if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b))
5649 hw_watchpoint_used_count (enum bptype type, int *other_type_used)
5651 struct breakpoint *b;
5654 *other_type_used = 0;
5657 if (breakpoint_enabled (b))
5659 if (b->type == type)
5661 else if ((b->type == bp_hardware_watchpoint
5662 || b->type == bp_read_watchpoint
5663 || b->type == bp_access_watchpoint))
5664 *other_type_used = 1;
5671 disable_watchpoints_before_interactive_call_start (void)
5673 struct breakpoint *b;
5677 if (((b->type == bp_watchpoint)
5678 || (b->type == bp_hardware_watchpoint)
5679 || (b->type == bp_read_watchpoint)
5680 || (b->type == bp_access_watchpoint))
5681 && breakpoint_enabled (b))
5683 b->enable_state = bp_call_disabled;
5684 update_global_location_list (0);
5690 enable_watchpoints_after_interactive_call_stop (void)
5692 struct breakpoint *b;
5696 if (((b->type == bp_watchpoint)
5697 || (b->type == bp_hardware_watchpoint)
5698 || (b->type == bp_read_watchpoint)
5699 || (b->type == bp_access_watchpoint))
5700 && (b->enable_state == bp_call_disabled))
5702 b->enable_state = bp_enabled;
5703 update_global_location_list (1);
5709 disable_breakpoints_before_startup (void)
5711 struct breakpoint *b;
5716 if (b->pspace != current_program_space)
5719 if ((b->type == bp_breakpoint
5720 || b->type == bp_hardware_breakpoint)
5721 && breakpoint_enabled (b))
5723 b->enable_state = bp_startup_disabled;
5729 update_global_location_list (0);
5731 current_program_space->executing_startup = 1;
5735 enable_breakpoints_after_startup (void)
5737 struct breakpoint *b;
5740 current_program_space->executing_startup = 0;
5744 if (b->pspace != current_program_space)
5747 if ((b->type == bp_breakpoint
5748 || b->type == bp_hardware_breakpoint)
5749 && b->enable_state == bp_startup_disabled)
5751 b->enable_state = bp_enabled;
5757 breakpoint_re_set ();
5761 /* Set a breakpoint that will evaporate an end of command
5762 at address specified by SAL.
5763 Restrict it to frame FRAME if FRAME is nonzero. */
5766 set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal,
5767 struct frame_id frame_id, enum bptype type)
5769 struct breakpoint *b;
5771 /* If FRAME_ID is valid, it should be a real frame, not an inlined
5773 gdb_assert (!frame_id_inlined_p (frame_id));
5775 b = set_raw_breakpoint (gdbarch, sal, type);
5776 b->enable_state = bp_enabled;
5777 b->disposition = disp_donttouch;
5778 b->frame_id = frame_id;
5780 /* If we're debugging a multi-threaded program, then we
5781 want momentary breakpoints to be active in only a
5782 single thread of control. */
5783 if (in_thread_list (inferior_ptid))
5784 b->thread = pid_to_thread_id (inferior_ptid);
5786 update_global_location_list_nothrow (1);
5791 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
5795 clone_momentary_breakpoint (struct breakpoint *orig)
5797 struct breakpoint *copy;
5799 /* If there's nothing to clone, then return nothing. */
5803 copy = set_raw_breakpoint_without_location (orig->gdbarch, orig->type);
5804 copy->loc = allocate_bp_location (copy);
5805 set_breakpoint_location_function (copy->loc);
5807 copy->loc->gdbarch = orig->loc->gdbarch;
5808 copy->loc->requested_address = orig->loc->requested_address;
5809 copy->loc->address = orig->loc->address;
5810 copy->loc->section = orig->loc->section;
5811 copy->loc->pspace = orig->loc->pspace;
5813 if (orig->source_file == NULL)
5814 copy->source_file = NULL;
5816 copy->source_file = xstrdup (orig->source_file);
5818 copy->line_number = orig->line_number;
5819 copy->frame_id = orig->frame_id;
5820 copy->thread = orig->thread;
5821 copy->pspace = orig->pspace;
5823 copy->enable_state = bp_enabled;
5824 copy->disposition = disp_donttouch;
5825 copy->number = internal_breakpoint_number--;
5827 update_global_location_list_nothrow (0);
5832 set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc,
5835 struct symtab_and_line sal;
5837 sal = find_pc_line (pc, 0);
5839 sal.section = find_pc_overlay (pc);
5840 sal.explicit_pc = 1;
5842 return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type);
5846 /* Tell the user we have just set a breakpoint B. */
5849 mention (struct breakpoint *b)
5852 struct cleanup *ui_out_chain;
5853 struct value_print_options opts;
5855 get_user_print_options (&opts);
5857 /* FIXME: This is misplaced; mention() is called by things (like
5858 hitting a watchpoint) other than breakpoint creation. It should
5859 be possible to clean this up and at the same time replace the
5860 random calls to breakpoint_changed with this hook. */
5861 observer_notify_breakpoint_created (b->number);
5863 if (b->ops != NULL && b->ops->print_mention != NULL)
5864 b->ops->print_mention (b);
5869 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b->number);
5872 ui_out_text (uiout, "Watchpoint ");
5873 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
5874 ui_out_field_int (uiout, "number", b->number);
5875 ui_out_text (uiout, ": ");
5876 ui_out_field_string (uiout, "exp", b->exp_string);
5877 do_cleanups (ui_out_chain);
5879 case bp_hardware_watchpoint:
5880 ui_out_text (uiout, "Hardware watchpoint ");
5881 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
5882 ui_out_field_int (uiout, "number", b->number);
5883 ui_out_text (uiout, ": ");
5884 ui_out_field_string (uiout, "exp", b->exp_string);
5885 do_cleanups (ui_out_chain);
5887 case bp_read_watchpoint:
5888 ui_out_text (uiout, "Hardware read watchpoint ");
5889 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
5890 ui_out_field_int (uiout, "number", b->number);
5891 ui_out_text (uiout, ": ");
5892 ui_out_field_string (uiout, "exp", b->exp_string);
5893 do_cleanups (ui_out_chain);
5895 case bp_access_watchpoint:
5896 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
5897 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
5898 ui_out_field_int (uiout, "number", b->number);
5899 ui_out_text (uiout, ": ");
5900 ui_out_field_string (uiout, "exp", b->exp_string);
5901 do_cleanups (ui_out_chain);
5904 if (ui_out_is_mi_like_p (uiout))
5909 if (b->disposition == disp_del)
5910 printf_filtered (_("Temporary breakpoint"));
5912 printf_filtered (_("Breakpoint"));
5913 printf_filtered (_(" %d"), b->number);
5916 case bp_hardware_breakpoint:
5917 if (ui_out_is_mi_like_p (uiout))
5922 printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
5926 if (ui_out_is_mi_like_p (uiout))
5931 printf_filtered (_("Tracepoint"));
5932 printf_filtered (_(" %d"), b->number);
5939 case bp_longjmp_resume:
5940 case bp_step_resume:
5942 case bp_watchpoint_scope:
5943 case bp_shlib_event:
5944 case bp_thread_event:
5945 case bp_overlay_event:
5947 case bp_longjmp_master:
5953 /* i18n: cagney/2005-02-11: Below needs to be merged into a
5957 printf_filtered (_(" (%s) pending."), b->addr_string);
5961 if (opts.addressprint || b->source_file == NULL)
5963 printf_filtered (" at ");
5964 fputs_filtered (paddress (b->loc->gdbarch, b->loc->address),
5968 printf_filtered (": file %s, line %d.",
5969 b->source_file, b->line_number);
5973 struct bp_location *loc = b->loc;
5975 for (; loc; loc = loc->next)
5977 printf_filtered (" (%d locations)", n);
5982 if (ui_out_is_mi_like_p (uiout))
5984 printf_filtered ("\n");
5988 static struct bp_location *
5989 add_location_to_breakpoint (struct breakpoint *b,
5990 const struct symtab_and_line *sal)
5992 struct bp_location *loc, **tmp;
5994 loc = allocate_bp_location (b);
5995 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
5998 loc->gdbarch = get_sal_arch (*sal);
6000 loc->gdbarch = b->gdbarch;
6001 loc->requested_address = sal->pc;
6002 loc->address = adjust_breakpoint_address (loc->gdbarch,
6003 loc->requested_address, b->type);
6004 loc->pspace = sal->pspace;
6005 gdb_assert (loc->pspace != NULL);
6006 loc->section = sal->section;
6008 set_breakpoint_location_function (loc);
6013 /* Return 1 if LOC is pointing to a permanent breakpoint,
6014 return 0 otherwise. */
6017 bp_loc_is_permanent (struct bp_location *loc)
6021 const gdb_byte *brk;
6022 gdb_byte *target_mem;
6023 struct cleanup *cleanup;
6026 gdb_assert (loc != NULL);
6028 addr = loc->address;
6029 brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len);
6031 /* Software breakpoints unsupported? */
6035 target_mem = alloca (len);
6037 /* Enable the automatic memory restoration from breakpoints while
6038 we read the memory. Otherwise we could say about our temporary
6039 breakpoints they are permanent. */
6040 cleanup = save_current_space_and_thread ();
6042 switch_to_program_space_and_thread (loc->pspace);
6043 make_show_memory_breakpoints_cleanup (0);
6045 if (target_read_memory (loc->address, target_mem, len) == 0
6046 && memcmp (target_mem, brk, len) == 0)
6049 do_cleanups (cleanup);
6056 /* Create a breakpoint with SAL as location. Use ADDR_STRING
6057 as textual description of the location, and COND_STRING
6058 as condition expression. */
6061 create_breakpoint (struct gdbarch *gdbarch,
6062 struct symtabs_and_lines sals, char *addr_string,
6064 enum bptype type, enum bpdisp disposition,
6065 int thread, int task, int ignore_count,
6066 struct breakpoint_ops *ops, int from_tty, int enabled)
6068 struct breakpoint *b = NULL;
6071 if (type == bp_hardware_breakpoint)
6073 int i = hw_breakpoint_used_count ();
6074 int target_resources_ok =
6075 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
6077 if (target_resources_ok == 0)
6078 error (_("No hardware breakpoint support in the target."));
6079 else if (target_resources_ok < 0)
6080 error (_("Hardware breakpoints used exceeds limit."));
6083 gdb_assert (sals.nelts > 0);
6085 for (i = 0; i < sals.nelts; ++i)
6087 struct symtab_and_line sal = sals.sals[i];
6088 struct bp_location *loc;
6092 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
6094 loc_gdbarch = gdbarch;
6096 describe_other_breakpoints (loc_gdbarch,
6097 sal.pspace, sal.pc, sal.section, thread);
6102 b = set_raw_breakpoint (gdbarch, sal, type);
6103 set_breakpoint_count (breakpoint_count + 1);
6104 b->number = breakpoint_count;
6108 b->cond_string = cond_string;
6109 b->ignore_count = ignore_count;
6110 b->enable_state = enabled ? bp_enabled : bp_disabled;
6111 b->disposition = disposition;
6113 b->pspace = sals.sals[0].pspace;
6115 if (enabled && b->pspace->executing_startup
6116 && (b->type == bp_breakpoint
6117 || b->type == bp_hardware_breakpoint))
6118 b->enable_state = bp_startup_disabled;
6124 loc = add_location_to_breakpoint (b, &sal);
6127 if (bp_loc_is_permanent (loc))
6128 make_breakpoint_permanent (b);
6132 char *arg = b->cond_string;
6133 loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0);
6135 error (_("Garbage %s follows condition"), arg);
6140 b->addr_string = addr_string;
6142 /* addr_string has to be used or breakpoint_re_set will delete
6145 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
6151 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
6152 elements to fill the void space. */
6154 remove_sal (struct symtabs_and_lines *sal, int index_to_remove)
6156 int i = index_to_remove+1;
6157 int last_index = sal->nelts-1;
6159 for (;i <= last_index; ++i)
6160 sal->sals[i-1] = sal->sals[i];
6165 /* If appropriate, obtains all sals that correspond to the same file
6166 and line as SAL, in all program spaces. Users debugging with IDEs,
6167 will want to set a breakpoint at foo.c:line, and not really care
6168 about program spaces. This is done only if SAL does not have
6169 explicit PC and has line and file information. If we got just a
6170 single expanded sal, return the original.
6172 Otherwise, if SAL.explicit_line is not set, filter out all sals for
6173 which the name of enclosing function is different from SAL. This
6174 makes sure that if we have breakpoint originally set in template
6175 instantiation, say foo<int>(), we won't expand SAL to locations at
6176 the same line in all existing instantiations of 'foo'. */
6178 static struct symtabs_and_lines
6179 expand_line_sal_maybe (struct symtab_and_line sal)
6181 struct symtabs_and_lines expanded;
6182 CORE_ADDR original_pc = sal.pc;
6183 char *original_function = NULL;
6186 struct cleanup *old_chain;
6188 /* If we have explicit pc, don't expand.
6189 If we have no line number, we can't expand. */
6190 if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL)
6193 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
6194 expanded.sals[0] = sal;
6200 old_chain = save_current_space_and_thread ();
6202 switch_to_program_space_and_thread (sal.pspace);
6204 find_pc_partial_function (original_pc, &original_function, NULL, NULL);
6206 /* Note that expand_line_sal visits *all* program spaces. */
6207 expanded = expand_line_sal (sal);
6209 if (expanded.nelts == 1)
6211 /* We had one sal, we got one sal. Without futher
6212 processing, just return the original sal. */
6213 xfree (expanded.sals);
6215 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
6216 sal.pc = original_pc;
6217 expanded.sals[0] = sal;
6218 do_cleanups (old_chain);
6222 if (!sal.explicit_line)
6224 CORE_ADDR func_addr, func_end;
6225 for (i = 0; i < expanded.nelts; ++i)
6227 CORE_ADDR pc = expanded.sals[i].pc;
6228 char *this_function;
6230 /* We need to switch threads as well since we're about to
6232 switch_to_program_space_and_thread (expanded.sals[i].pspace);
6234 if (find_pc_partial_function (pc, &this_function,
6235 &func_addr, &func_end))
6238 && strcmp (this_function, original_function) != 0)
6240 remove_sal (&expanded, i);
6243 else if (func_addr == pc)
6245 /* We're at beginning of a function, and should
6247 struct symbol *sym = find_pc_function (pc);
6249 expanded.sals[i] = find_function_start_sal (sym, 1);
6252 /* Since find_pc_partial_function returned true,
6253 we should really always find the section here. */
6254 struct obj_section *section = find_pc_section (pc);
6257 struct gdbarch *gdbarch
6258 = get_objfile_arch (section->objfile);
6260 = gdbarch_skip_prologue (gdbarch, pc);
6269 for (i = 0; i < expanded.nelts; ++i)
6271 /* If this SAL corresponds to a breakpoint inserted using a
6272 line number, then skip the function prologue if necessary. */
6273 skip_prologue_sal (&expanded.sals[i]);
6277 do_cleanups (old_chain);
6279 if (expanded.nelts <= 1)
6281 /* This is un ugly workaround. If we get zero
6282 expanded sals then something is really wrong.
6283 Fix that by returnign the original sal. */
6284 xfree (expanded.sals);
6286 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
6287 sal.pc = original_pc;
6288 expanded.sals[0] = sal;
6295 for (i = 0; i < expanded.nelts; ++i)
6296 if (expanded.sals[i].pc == original_pc)
6307 /* Add SALS.nelts breakpoints to the breakpoint table. For each
6308 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
6309 value. COND_STRING, if not NULL, specified the condition to be
6310 used for all breakpoints. Essentially the only case where
6311 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
6312 function. In that case, it's still not possible to specify
6313 separate conditions for different overloaded functions, so
6314 we take just a single condition string.
6316 NOTE: If the function succeeds, the caller is expected to cleanup
6317 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
6318 array contents). If the function fails (error() is called), the
6319 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
6320 COND and SALS arrays and each of those arrays contents. */
6323 create_breakpoints (struct gdbarch *gdbarch,
6324 struct symtabs_and_lines sals, char **addr_string,
6326 enum bptype type, enum bpdisp disposition,
6327 int thread, int task, int ignore_count,
6328 struct breakpoint_ops *ops, int from_tty,
6332 for (i = 0; i < sals.nelts; ++i)
6334 struct symtabs_and_lines expanded =
6335 expand_line_sal_maybe (sals.sals[i]);
6337 create_breakpoint (gdbarch, expanded, addr_string[i],
6338 cond_string, type, disposition,
6339 thread, task, ignore_count, ops, from_tty, enabled);
6343 /* Parse ARG which is assumed to be a SAL specification possibly
6344 followed by conditionals. On return, SALS contains an array of SAL
6345 addresses found. ADDR_STRING contains a vector of (canonical)
6346 address strings. ARG points to the end of the SAL. */
6349 parse_breakpoint_sals (char **address,
6350 struct symtabs_and_lines *sals,
6351 char ***addr_string,
6354 char *addr_start = *address;
6355 *addr_string = NULL;
6356 /* If no arg given, or if first arg is 'if ', use the default
6358 if ((*address) == NULL
6359 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
6361 if (default_breakpoint_valid)
6363 struct symtab_and_line sal;
6364 init_sal (&sal); /* initialize to zeroes */
6365 sals->sals = (struct symtab_and_line *)
6366 xmalloc (sizeof (struct symtab_and_line));
6367 sal.pc = default_breakpoint_address;
6368 sal.line = default_breakpoint_line;
6369 sal.symtab = default_breakpoint_symtab;
6370 sal.pspace = default_breakpoint_pspace;
6371 sal.section = find_pc_overlay (sal.pc);
6373 /* "break" without arguments is equivalent to "break *PC" where PC is
6374 the default_breakpoint_address. So make sure to set
6375 sal.explicit_pc to prevent GDB from trying to expand the list of
6376 sals to include all other instances with the same symtab and line.
6378 sal.explicit_pc = 1;
6380 sals->sals[0] = sal;
6384 error (_("No default breakpoint address now."));
6388 /* Force almost all breakpoints to be in terms of the
6389 current_source_symtab (which is decode_line_1's default). This
6390 should produce the results we want almost all of the time while
6391 leaving default_breakpoint_* alone.
6392 ObjC: However, don't match an Objective-C method name which
6393 may have a '+' or '-' succeeded by a '[' */
6395 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
6397 if (default_breakpoint_valid
6399 || ((strchr ("+-", (*address)[0]) != NULL)
6400 && ((*address)[1] != '['))))
6401 *sals = decode_line_1 (address, 1, default_breakpoint_symtab,
6402 default_breakpoint_line, addr_string,
6405 *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0,
6406 addr_string, not_found_ptr);
6408 /* For any SAL that didn't have a canonical string, fill one in. */
6409 if (sals->nelts > 0 && *addr_string == NULL)
6410 *addr_string = xcalloc (sals->nelts, sizeof (char **));
6411 if (addr_start != (*address))
6414 for (i = 0; i < sals->nelts; i++)
6416 /* Add the string if not present. */
6417 if ((*addr_string)[i] == NULL)
6418 (*addr_string)[i] = savestring (addr_start, (*address) - addr_start);
6424 /* Convert each SAL into a real PC. Verify that the PC can be
6425 inserted as a breakpoint. If it can't throw an error. */
6428 breakpoint_sals_to_pc (struct symtabs_and_lines *sals,
6432 for (i = 0; i < sals->nelts; i++)
6433 resolve_sal_pc (&sals->sals[i]);
6437 do_captured_parse_breakpoint (struct ui_out *ui, void *data)
6439 struct captured_parse_breakpoint_args *args = data;
6441 parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p,
6442 args->not_found_ptr);
6445 /* Given TOK, a string specification of condition and thread, as
6446 accepted by the 'break' command, extract the condition
6447 string and thread number and set *COND_STRING and *THREAD.
6448 PC identifies the context at which the condition should be parsed.
6449 If no condition is found, *COND_STRING is set to NULL.
6450 If no thread is found, *THREAD is set to -1. */
6452 find_condition_and_thread (char *tok, CORE_ADDR pc,
6453 char **cond_string, int *thread, int *task)
6455 *cond_string = NULL;
6461 char *cond_start = NULL;
6462 char *cond_end = NULL;
6463 while (*tok == ' ' || *tok == '\t')
6468 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
6471 toklen = end_tok - tok;
6473 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
6475 struct expression *expr;
6477 tok = cond_start = end_tok + 1;
6478 expr = parse_exp_1 (&tok, block_for_pc (pc), 0);
6481 *cond_string = savestring (cond_start,
6482 cond_end - cond_start);
6484 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
6490 *thread = strtol (tok, &tok, 0);
6492 error (_("Junk after thread keyword."));
6493 if (!valid_thread_id (*thread))
6494 error (_("Unknown thread %d."), *thread);
6496 else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0)
6502 *task = strtol (tok, &tok, 0);
6504 error (_("Junk after task keyword."));
6505 if (!valid_task_id (*task))
6506 error (_("Unknown task %d\n"), *task);
6509 error (_("Junk at end of arguments."));
6513 /* Set a breakpoint. This function is shared between
6514 CLI and MI functions for setting a breakpoint.
6515 This function has two major modes of operations,
6516 selected by the PARSE_CONDITION_AND_THREAD parameter.
6517 If non-zero, the function will parse arg, extracting
6518 breakpoint location, address and thread. Otherwise,
6519 ARG is just the location of breakpoint, with condition
6520 and thread specified by the COND_STRING and THREAD
6524 break_command_really (struct gdbarch *gdbarch,
6525 char *arg, char *cond_string, int thread,
6526 int parse_condition_and_thread,
6527 int tempflag, int hardwareflag, int traceflag,
6529 enum auto_boolean pending_break_support,
6530 struct breakpoint_ops *ops,
6534 struct gdb_exception e;
6535 struct symtabs_and_lines sals;
6536 struct symtab_and_line pending_sal;
6539 char *addr_start = arg;
6541 struct cleanup *old_chain;
6542 struct cleanup *bkpt_chain = NULL;
6543 struct captured_parse_breakpoint_args parse_args;
6547 enum bptype type_wanted;
6554 parse_args.arg_p = &arg;
6555 parse_args.sals_p = &sals;
6556 parse_args.addr_string_p = &addr_string;
6557 parse_args.not_found_ptr = ¬_found;
6559 e = catch_exception (uiout, do_captured_parse_breakpoint,
6560 &parse_args, RETURN_MASK_ALL);
6562 /* If caller is interested in rc value from parse, set value. */
6566 throw_exception (e);
6570 case NOT_FOUND_ERROR:
6572 /* If pending breakpoint support is turned off, throw
6575 if (pending_break_support == AUTO_BOOLEAN_FALSE)
6576 throw_exception (e);
6578 exception_print (gdb_stderr, e);
6580 /* If pending breakpoint support is auto query and the user
6581 selects no, then simply return the error code. */
6582 if (pending_break_support == AUTO_BOOLEAN_AUTO
6583 && !nquery ("Make breakpoint pending on future shared library load? "))
6586 /* At this point, either the user was queried about setting
6587 a pending breakpoint and selected yes, or pending
6588 breakpoint behavior is on and thus a pending breakpoint
6589 is defaulted on behalf of the user. */
6590 copy_arg = xstrdup (addr_start);
6591 addr_string = ©_arg;
6593 sals.sals = &pending_sal;
6598 throw_exception (e);
6605 /* Create a chain of things that always need to be cleaned up. */
6606 old_chain = make_cleanup (null_cleanup, 0);
6610 /* Make sure that all storage allocated to SALS gets freed. */
6611 make_cleanup (xfree, sals.sals);
6613 /* Cleanup the addr_string array but not its contents. */
6614 make_cleanup (xfree, addr_string);
6617 /* ----------------------------- SNIP -----------------------------
6618 Anything added to the cleanup chain beyond this point is assumed
6619 to be part of a breakpoint. If the breakpoint create succeeds
6620 then the memory is not reclaimed. */
6621 bkpt_chain = make_cleanup (null_cleanup, 0);
6623 /* Mark the contents of the addr_string for cleanup. These go on
6624 the bkpt_chain and only occur if the breakpoint create fails. */
6625 for (i = 0; i < sals.nelts; i++)
6627 if (addr_string[i] != NULL)
6628 make_cleanup (xfree, addr_string[i]);
6631 /* Resolve all line numbers to PC's and verify that the addresses
6632 are ok for the target. */
6634 breakpoint_sals_to_pc (&sals, addr_start);
6636 type_wanted = (traceflag
6638 : (hardwareflag ? bp_hardware_breakpoint : bp_breakpoint));
6640 /* Verify that condition can be parsed, before setting any
6641 breakpoints. Allocate a separate condition expression for each
6645 if (parse_condition_and_thread)
6647 /* Here we only parse 'arg' to separate condition
6648 from thread number, so parsing in context of first
6649 sal is OK. When setting the breakpoint we'll
6650 re-parse it in context of each sal. */
6653 find_condition_and_thread (arg, sals.sals[0].pc, &cond_string,
6656 make_cleanup (xfree, cond_string);
6660 /* Create a private copy of condition string. */
6663 cond_string = xstrdup (cond_string);
6664 make_cleanup (xfree, cond_string);
6667 create_breakpoints (gdbarch, sals, addr_string, cond_string, type_wanted,
6668 tempflag ? disp_del : disp_donttouch,
6669 thread, task, ignore_count, ops, from_tty, enabled);
6673 struct symtab_and_line sal = {0};
6674 struct breakpoint *b;
6676 make_cleanup (xfree, copy_arg);
6678 b = set_raw_breakpoint_without_location (gdbarch, type_wanted);
6679 set_breakpoint_count (breakpoint_count + 1);
6680 b->number = breakpoint_count;
6682 b->addr_string = addr_string[0];
6683 b->cond_string = NULL;
6684 b->ignore_count = ignore_count;
6685 b->disposition = tempflag ? disp_del : disp_donttouch;
6686 b->condition_not_parsed = 1;
6688 b->enable_state = enabled ? bp_enabled : bp_disabled;
6689 b->pspace = current_program_space;
6691 if (enabled && b->pspace->executing_startup
6692 && (b->type == bp_breakpoint
6693 || b->type == bp_hardware_breakpoint))
6694 b->enable_state = bp_startup_disabled;
6700 warning (_("Multiple breakpoints were set.\n"
6701 "Use the \"delete\" command to delete unwanted breakpoints."));
6702 /* That's it. Discard the cleanups for data inserted into the
6704 discard_cleanups (bkpt_chain);
6705 /* But cleanup everything else. */
6706 do_cleanups (old_chain);
6708 /* error call may happen here - have BKPT_CHAIN already discarded. */
6709 update_global_location_list (1);
6712 /* Set a breakpoint.
6713 ARG is a string describing breakpoint address,
6714 condition, and thread.
6715 FLAG specifies if a breakpoint is hardware on,
6716 and if breakpoint is temporary, using BP_HARDWARE_FLAG
6720 break_command_1 (char *arg, int flag, int from_tty)
6722 int hardwareflag = flag & BP_HARDWAREFLAG;
6723 int tempflag = flag & BP_TEMPFLAG;
6725 break_command_really (get_current_arch (),
6727 NULL, 0, 1 /* parse arg */,
6728 tempflag, hardwareflag, 0 /* traceflag */,
6729 0 /* Ignore count */,
6730 pending_break_support,
6731 NULL /* breakpoint_ops */,
6738 set_breakpoint (struct gdbarch *gdbarch,
6739 char *address, char *condition,
6740 int hardwareflag, int tempflag,
6741 int thread, int ignore_count,
6742 int pending, int enabled)
6744 break_command_really (gdbarch,
6745 address, condition, thread,
6746 0 /* condition and thread are valid. */,
6747 tempflag, hardwareflag, 0 /* traceflag */,
6750 ? AUTO_BOOLEAN_TRUE : AUTO_BOOLEAN_FALSE,
6754 /* Adjust SAL to the first instruction past the function prologue.
6755 The end of the prologue is determined using the line table from
6756 the debugging information. explicit_pc and explicit_line are
6759 If SAL is already past the prologue, then do nothing. */
6762 skip_prologue_sal (struct symtab_and_line *sal)
6765 struct symtab_and_line start_sal;
6766 struct cleanup *old_chain;
6768 old_chain = save_current_space_and_thread ();
6770 sym = find_pc_function (sal->pc);
6773 start_sal = find_function_start_sal (sym, 1);
6774 if (sal->pc < start_sal.pc)
6776 start_sal.explicit_line = sal->explicit_line;
6777 start_sal.explicit_pc = sal->explicit_pc;
6782 do_cleanups (old_chain);
6785 /* Helper function for break_command_1 and disassemble_command. */
6788 resolve_sal_pc (struct symtab_and_line *sal)
6792 if (sal->pc == 0 && sal->symtab != NULL)
6794 if (!find_line_pc (sal->symtab, sal->line, &pc))
6795 error (_("No line %d in file \"%s\"."),
6796 sal->line, sal->symtab->filename);
6799 /* If this SAL corresponds to a breakpoint inserted using
6800 a line number, then skip the function prologue if necessary. */
6801 if (sal->explicit_line)
6803 /* Preserve the original line number. */
6804 int saved_line = sal->line;
6805 skip_prologue_sal (sal);
6806 sal->line = saved_line;
6810 if (sal->section == 0 && sal->symtab != NULL)
6812 struct blockvector *bv;
6816 bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab);
6819 sym = block_linkage_function (b);
6822 fixup_symbol_section (sym, sal->symtab->objfile);
6823 sal->section = SYMBOL_OBJ_SECTION (sym);
6827 /* It really is worthwhile to have the section, so we'll just
6828 have to look harder. This case can be executed if we have
6829 line numbers but no functions (as can happen in assembly
6832 struct minimal_symbol *msym;
6833 struct cleanup *old_chain = save_current_space_and_thread ();
6835 switch_to_program_space_and_thread (sal->pspace);
6837 msym = lookup_minimal_symbol_by_pc (sal->pc);
6839 sal->section = SYMBOL_OBJ_SECTION (msym);
6841 do_cleanups (old_chain);
6848 break_command (char *arg, int from_tty)
6850 break_command_1 (arg, 0, from_tty);
6854 tbreak_command (char *arg, int from_tty)
6856 break_command_1 (arg, BP_TEMPFLAG, from_tty);
6860 hbreak_command (char *arg, int from_tty)
6862 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
6866 thbreak_command (char *arg, int from_tty)
6868 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
6872 stop_command (char *arg, int from_tty)
6874 printf_filtered (_("Specify the type of breakpoint to set.\n\
6875 Usage: stop in <function | address>\n\
6876 stop at <line>\n"));
6880 stopin_command (char *arg, int from_tty)
6884 if (arg == (char *) NULL)
6886 else if (*arg != '*')
6891 /* look for a ':'. If this is a line number specification, then
6892 say it is bad, otherwise, it should be an address or
6893 function/method name */
6894 while (*argptr && !hasColon)
6896 hasColon = (*argptr == ':');
6901 badInput = (*argptr != ':'); /* Not a class::method */
6903 badInput = isdigit (*arg); /* a simple line number */
6907 printf_filtered (_("Usage: stop in <function | address>\n"));
6909 break_command_1 (arg, 0, from_tty);
6913 stopat_command (char *arg, int from_tty)
6917 if (arg == (char *) NULL || *arg == '*') /* no line number */
6924 /* look for a ':'. If there is a '::' then get out, otherwise
6925 it is probably a line number. */
6926 while (*argptr && !hasColon)
6928 hasColon = (*argptr == ':');
6933 badInput = (*argptr == ':'); /* we have class::method */
6935 badInput = !isdigit (*arg); /* not a line number */
6939 printf_filtered (_("Usage: stop at <line>\n"));
6941 break_command_1 (arg, 0, from_tty);
6944 /* accessflag: hw_write: watch write,
6945 hw_read: watch read,
6946 hw_access: watch access (read or write) */
6948 watch_command_1 (char *arg, int accessflag, int from_tty)
6950 struct gdbarch *gdbarch = get_current_arch ();
6951 struct breakpoint *b, *scope_breakpoint = NULL;
6952 struct symtab_and_line sal;
6953 struct expression *exp;
6954 struct block *exp_valid_block;
6955 struct value *val, *mark;
6956 struct frame_info *frame;
6957 char *exp_start = NULL;
6958 char *exp_end = NULL;
6959 char *tok, *id_tok_start, *end_tok;
6961 char *cond_start = NULL;
6962 char *cond_end = NULL;
6963 struct expression *cond = NULL;
6964 int i, other_type_used, target_resources_ok = 0;
6965 enum bptype bp_type;
6969 init_sal (&sal); /* initialize to zeroes */
6971 /* Make sure that we actually have parameters to parse. */
6972 if (arg != NULL && arg[0] != '\0')
6974 toklen = strlen (arg); /* Size of argument list. */
6976 /* Points tok to the end of the argument list. */
6977 tok = arg + toklen - 1;
6979 /* Go backwards in the parameters list. Skip the last parameter.
6980 If we're expecting a 'thread <thread_num>' parameter, this should
6981 be the thread identifier. */
6982 while (tok > arg && (*tok == ' ' || *tok == '\t'))
6984 while (tok > arg && (*tok != ' ' && *tok != '\t'))
6987 /* Points end_tok to the beginning of the last token. */
6988 id_tok_start = tok + 1;
6990 /* Go backwards in the parameters list. Skip one more parameter.
6991 If we're expecting a 'thread <thread_num>' parameter, we should
6992 reach a "thread" token. */
6993 while (tok > arg && (*tok == ' ' || *tok == '\t'))
6998 while (tok > arg && (*tok != ' ' && *tok != '\t'))
7001 /* Move the pointer forward to skip the whitespace and
7002 calculate the length of the token. */
7004 toklen = end_tok - tok;
7006 if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
7008 /* At this point we've found a "thread" token, which means
7009 the user is trying to set a watchpoint that triggers
7010 only in a specific thread. */
7013 /* Extract the thread ID from the next token. */
7014 thread = strtol (id_tok_start, &endp, 0);
7016 /* Check if the user provided a valid numeric value for the
7018 if (*endp != ' ' && *endp != '\t' && *endp != '\0')
7019 error (_("Invalid thread ID specification %s."), id_tok_start);
7021 /* Check if the thread actually exists. */
7022 if (!valid_thread_id (thread))
7023 error (_("Unknown thread %d."), thread);
7025 /* Truncate the string and get rid of the thread <thread_num>
7026 parameter before the parameter list is parsed by the
7027 evaluate_expression() function. */
7032 sal.pspace = current_program_space;
7034 /* Parse the rest of the arguments. */
7035 innermost_block = NULL;
7037 exp = parse_exp_1 (&arg, 0, 0);
7039 /* Remove trailing whitespace from the expression before saving it.
7040 This makes the eventual display of the expression string a bit
7042 while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t'))
7045 exp_valid_block = innermost_block;
7046 mark = value_mark ();
7047 fetch_watchpoint_value (exp, &val, NULL, NULL);
7049 release_value (val);
7052 while (*tok == ' ' || *tok == '\t')
7056 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
7059 toklen = end_tok - tok;
7060 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
7062 tok = cond_start = end_tok + 1;
7063 cond = parse_exp_1 (&tok, 0, 0);
7067 error (_("Junk at end of command."));
7069 if (accessflag == hw_read)
7070 bp_type = bp_read_watchpoint;
7071 else if (accessflag == hw_access)
7072 bp_type = bp_access_watchpoint;
7074 bp_type = bp_hardware_watchpoint;
7076 mem_cnt = can_use_hardware_watchpoint (val);
7077 if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
7078 error (_("Expression cannot be implemented with read/access watchpoint."));
7081 i = hw_watchpoint_used_count (bp_type, &other_type_used);
7082 target_resources_ok =
7083 target_can_use_hardware_watchpoint (bp_type, i + mem_cnt,
7085 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
7086 error (_("Target does not support this type of hardware watchpoint."));
7088 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
7089 error (_("Target can only support one kind of HW watchpoint at a time."));
7092 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
7093 watchpoint could not be set. */
7094 if (!mem_cnt || target_resources_ok <= 0)
7095 bp_type = bp_watchpoint;
7097 frame = block_innermost_frame (exp_valid_block);
7099 /* If the expression is "local", then set up a "watchpoint scope"
7100 breakpoint at the point where we've left the scope of the watchpoint
7101 expression. Create the scope breakpoint before the watchpoint, so
7102 that we will encounter it first in bpstat_stop_status. */
7103 if (innermost_block && frame)
7105 if (frame_id_p (frame_unwind_caller_id (frame)))
7108 = create_internal_breakpoint (frame_unwind_caller_arch (frame),
7109 frame_unwind_caller_pc (frame),
7110 bp_watchpoint_scope);
7112 scope_breakpoint->enable_state = bp_enabled;
7114 /* Automatically delete the breakpoint when it hits. */
7115 scope_breakpoint->disposition = disp_del;
7117 /* Only break in the proper frame (help with recursion). */
7118 scope_breakpoint->frame_id = frame_unwind_caller_id (frame);
7120 /* Set the address at which we will stop. */
7121 scope_breakpoint->loc->gdbarch
7122 = frame_unwind_caller_arch (frame);
7123 scope_breakpoint->loc->requested_address
7124 = frame_unwind_caller_pc (frame);
7125 scope_breakpoint->loc->address
7126 = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch,
7127 scope_breakpoint->loc->requested_address,
7128 scope_breakpoint->type);
7132 /* Now set up the breakpoint. */
7133 b = set_raw_breakpoint (gdbarch, sal, bp_type);
7134 set_breakpoint_count (breakpoint_count + 1);
7135 b->number = breakpoint_count;
7137 b->disposition = disp_donttouch;
7139 b->exp_valid_block = exp_valid_block;
7140 b->exp_string = savestring (exp_start, exp_end - exp_start);
7143 b->loc->cond = cond;
7145 b->cond_string = savestring (cond_start, cond_end - cond_start);
7150 b->watchpoint_frame = get_frame_id (frame);
7152 b->watchpoint_frame = null_frame_id;
7154 if (scope_breakpoint != NULL)
7156 /* The scope breakpoint is related to the watchpoint. We will
7157 need to act on them together. */
7158 b->related_breakpoint = scope_breakpoint;
7159 scope_breakpoint->related_breakpoint = b;
7162 value_free_to_mark (mark);
7164 update_global_location_list (1);
7167 /* Return count of locations need to be watched and can be handled
7168 in hardware. If the watchpoint can not be handled
7169 in hardware return zero. */
7172 can_use_hardware_watchpoint (struct value *v)
7174 int found_memory_cnt = 0;
7175 struct value *head = v;
7177 /* Did the user specifically forbid us to use hardware watchpoints? */
7178 if (!can_use_hw_watchpoints)
7181 /* Make sure that the value of the expression depends only upon
7182 memory contents, and values computed from them within GDB. If we
7183 find any register references or function calls, we can't use a
7184 hardware watchpoint.
7186 The idea here is that evaluating an expression generates a series
7187 of values, one holding the value of every subexpression. (The
7188 expression a*b+c has five subexpressions: a, b, a*b, c, and
7189 a*b+c.) GDB's values hold almost enough information to establish
7190 the criteria given above --- they identify memory lvalues,
7191 register lvalues, computed values, etcetera. So we can evaluate
7192 the expression, and then scan the chain of values that leaves
7193 behind to decide whether we can detect any possible change to the
7194 expression's final value using only hardware watchpoints.
7196 However, I don't think that the values returned by inferior
7197 function calls are special in any way. So this function may not
7198 notice that an expression involving an inferior function call
7199 can't be watched with hardware watchpoints. FIXME. */
7200 for (; v; v = value_next (v))
7202 if (VALUE_LVAL (v) == lval_memory)
7205 /* A lazy memory lvalue is one that GDB never needed to fetch;
7206 we either just used its address (e.g., `a' in `a.b') or
7207 we never needed it at all (e.g., `a' in `a,b'). */
7211 /* Ahh, memory we actually used! Check if we can cover
7212 it with hardware watchpoints. */
7213 struct type *vtype = check_typedef (value_type (v));
7215 /* We only watch structs and arrays if user asked for it
7216 explicitly, never if they just happen to appear in a
7217 middle of some value chain. */
7219 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
7220 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
7222 CORE_ADDR vaddr = value_address (v);
7223 int len = TYPE_LENGTH (value_type (v));
7225 if (!target_region_ok_for_hw_watchpoint (vaddr, len))
7232 else if (VALUE_LVAL (v) != not_lval
7233 && deprecated_value_modifiable (v) == 0)
7234 return 0; /* ??? What does this represent? */
7235 else if (VALUE_LVAL (v) == lval_register)
7236 return 0; /* cannot watch a register with a HW watchpoint */
7239 /* The expression itself looks suitable for using a hardware
7240 watchpoint, but give the target machine a chance to reject it. */
7241 return found_memory_cnt;
7245 watch_command_wrapper (char *arg, int from_tty)
7247 watch_command (arg, from_tty);
7251 watch_command (char *arg, int from_tty)
7253 watch_command_1 (arg, hw_write, from_tty);
7257 rwatch_command_wrapper (char *arg, int from_tty)
7259 rwatch_command (arg, from_tty);
7263 rwatch_command (char *arg, int from_tty)
7265 watch_command_1 (arg, hw_read, from_tty);
7269 awatch_command_wrapper (char *arg, int from_tty)
7271 awatch_command (arg, from_tty);
7275 awatch_command (char *arg, int from_tty)
7277 watch_command_1 (arg, hw_access, from_tty);
7281 /* Helper routines for the until_command routine in infcmd.c. Here
7282 because it uses the mechanisms of breakpoints. */
7284 struct until_break_command_continuation_args
7286 struct breakpoint *breakpoint;
7287 struct breakpoint *breakpoint2;
7290 /* This function is called by fetch_inferior_event via the
7291 cmd_continuation pointer, to complete the until command. It takes
7292 care of cleaning up the temporary breakpoints set up by the until
7295 until_break_command_continuation (void *arg)
7297 struct until_break_command_continuation_args *a = arg;
7299 delete_breakpoint (a->breakpoint);
7301 delete_breakpoint (a->breakpoint2);
7305 until_break_command (char *arg, int from_tty, int anywhere)
7307 struct symtabs_and_lines sals;
7308 struct symtab_and_line sal;
7309 struct frame_info *frame = get_selected_frame (NULL);
7310 struct breakpoint *breakpoint;
7311 struct breakpoint *breakpoint2 = NULL;
7312 struct cleanup *old_chain;
7314 clear_proceed_status ();
7316 /* Set a breakpoint where the user wants it and at return from
7319 if (default_breakpoint_valid)
7320 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
7321 default_breakpoint_line, (char ***) NULL, NULL);
7323 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL,
7324 0, (char ***) NULL, NULL);
7326 if (sals.nelts != 1)
7327 error (_("Couldn't get information on specified line."));
7330 xfree (sals.sals); /* malloc'd, so freed */
7333 error (_("Junk at end of arguments."));
7335 resolve_sal_pc (&sal);
7338 /* If the user told us to continue until a specified location,
7339 we don't specify a frame at which we need to stop. */
7340 breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal,
7341 null_frame_id, bp_until);
7343 /* Otherwise, specify the selected frame, because we want to stop only
7344 at the very same frame. */
7345 breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal,
7346 get_stack_frame_id (frame),
7349 old_chain = make_cleanup_delete_breakpoint (breakpoint);
7351 /* Keep within the current frame, or in frames called by the current
7354 if (frame_id_p (frame_unwind_caller_id (frame)))
7356 sal = find_pc_line (frame_unwind_caller_pc (frame), 0);
7357 sal.pc = frame_unwind_caller_pc (frame);
7358 breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame),
7360 frame_unwind_caller_id (frame),
7362 make_cleanup_delete_breakpoint (breakpoint2);
7365 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
7367 /* If we are running asynchronously, and proceed call above has actually
7368 managed to start the target, arrange for breakpoints to be
7369 deleted when the target stops. Otherwise, we're already stopped and
7370 delete breakpoints via cleanup chain. */
7372 if (target_can_async_p () && is_running (inferior_ptid))
7374 struct until_break_command_continuation_args *args;
7375 args = xmalloc (sizeof (*args));
7377 args->breakpoint = breakpoint;
7378 args->breakpoint2 = breakpoint2;
7380 discard_cleanups (old_chain);
7381 add_continuation (inferior_thread (),
7382 until_break_command_continuation, args,
7386 do_cleanups (old_chain);
7390 ep_skip_leading_whitespace (char **s)
7392 if ((s == NULL) || (*s == NULL))
7394 while (isspace (**s))
7398 /* This function attempts to parse an optional "if <cond>" clause
7399 from the arg string. If one is not found, it returns NULL.
7401 Else, it returns a pointer to the condition string. (It does not
7402 attempt to evaluate the string against a particular block.) And,
7403 it updates arg to point to the first character following the parsed
7404 if clause in the arg string. */
7407 ep_parse_optional_if_clause (char **arg)
7411 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
7414 /* Skip the "if" keyword. */
7417 /* Skip any extra leading whitespace, and record the start of the
7418 condition string. */
7419 ep_skip_leading_whitespace (arg);
7422 /* Assume that the condition occupies the remainder of the arg string. */
7423 (*arg) += strlen (cond_string);
7428 /* This function attempts to parse an optional filename from the arg
7429 string. If one is not found, it returns NULL.
7431 Else, it returns a pointer to the parsed filename. (This function
7432 makes no attempt to verify that a file of that name exists, or is
7433 accessible.) And, it updates arg to point to the first character
7434 following the parsed filename in the arg string.
7436 Note that clients needing to preserve the returned filename for
7437 future access should copy it to their own buffers. */
7439 ep_parse_optional_filename (char **arg)
7441 static char filename[1024];
7446 if ((*arg_p == '\0') || isspace (*arg_p))
7464 /* Commands to deal with catching events, such as signals, exceptions,
7465 process start/exit, etc. */
7469 catch_fork_temporary, catch_vfork_temporary,
7470 catch_fork_permanent, catch_vfork_permanent
7475 catch_fork_command_1 (char *arg, int from_tty, struct cmd_list_element *command)
7477 struct gdbarch *gdbarch = get_current_arch ();
7478 char *cond_string = NULL;
7479 catch_fork_kind fork_kind;
7482 fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command);
7483 tempflag = (fork_kind == catch_fork_temporary
7484 || fork_kind == catch_vfork_temporary);
7488 ep_skip_leading_whitespace (&arg);
7490 /* The allowed syntax is:
7492 catch [v]fork if <cond>
7494 First, check if there's an if clause. */
7495 cond_string = ep_parse_optional_if_clause (&arg);
7497 if ((*arg != '\0') && !isspace (*arg))
7498 error (_("Junk at end of arguments."));
7500 /* If this target supports it, create a fork or vfork catchpoint
7501 and enable reporting of such events. */
7504 case catch_fork_temporary:
7505 case catch_fork_permanent:
7506 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
7507 &catch_fork_breakpoint_ops);
7509 case catch_vfork_temporary:
7510 case catch_vfork_permanent:
7511 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
7512 &catch_vfork_breakpoint_ops);
7515 error (_("unsupported or unknown fork kind; cannot catch it"));
7521 catch_exec_command_1 (char *arg, int from_tty, struct cmd_list_element *command)
7523 struct gdbarch *gdbarch = get_current_arch ();
7525 char *cond_string = NULL;
7527 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
7531 ep_skip_leading_whitespace (&arg);
7533 /* The allowed syntax is:
7535 catch exec if <cond>
7537 First, check if there's an if clause. */
7538 cond_string = ep_parse_optional_if_clause (&arg);
7540 if ((*arg != '\0') && !isspace (*arg))
7541 error (_("Junk at end of arguments."));
7543 /* If this target supports it, create an exec catchpoint
7544 and enable reporting of such events. */
7545 create_catchpoint (gdbarch, tempflag, cond_string,
7546 &catch_exec_breakpoint_ops);
7549 static enum print_stop_action
7550 print_exception_catchpoint (struct breakpoint *b)
7552 int bp_temp, bp_throw;
7554 annotate_catchpoint (b->number);
7556 bp_throw = strstr (b->addr_string, "throw") != NULL;
7557 if (b->loc->address != b->loc->requested_address)
7558 breakpoint_adjustment_warning (b->loc->requested_address,
7561 bp_temp = b->disposition == disp_del;
7563 bp_temp ? "Temporary catchpoint "
7565 if (!ui_out_is_mi_like_p (uiout))
7566 ui_out_field_int (uiout, "bkptno", b->number);
7568 bp_throw ? " (exception thrown), "
7569 : " (exception caught), ");
7570 if (ui_out_is_mi_like_p (uiout))
7572 ui_out_field_string (uiout, "reason",
7573 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
7574 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
7575 ui_out_field_int (uiout, "bkptno", b->number);
7577 return PRINT_SRC_AND_LOC;
7581 print_one_exception_catchpoint (struct breakpoint *b, struct bp_location **last_loc)
7583 struct value_print_options opts;
7584 get_user_print_options (&opts);
7585 if (opts.addressprint)
7588 if (b->loc == NULL || b->loc->shlib_disabled)
7589 ui_out_field_string (uiout, "addr", "<PENDING>");
7591 ui_out_field_core_addr (uiout, "addr",
7592 b->loc->gdbarch, b->loc->address);
7597 if (strstr (b->addr_string, "throw") != NULL)
7598 ui_out_field_string (uiout, "what", "exception throw");
7600 ui_out_field_string (uiout, "what", "exception catch");
7604 print_mention_exception_catchpoint (struct breakpoint *b)
7609 bp_temp = b->disposition == disp_del;
7610 bp_throw = strstr (b->addr_string, "throw") != NULL;
7611 ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ")
7612 : _("Catchpoint "));
7613 ui_out_field_int (uiout, "bkptno", b->number);
7614 ui_out_text (uiout, bp_throw ? _(" (throw)")
7618 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = {
7621 NULL, /* breakpoint_hit */
7622 print_exception_catchpoint,
7623 print_one_exception_catchpoint,
7624 print_mention_exception_catchpoint
7628 handle_gnu_v3_exceptions (int tempflag, char *cond_string,
7629 enum exception_event_kind ex_event, int from_tty)
7631 char *trigger_func_name;
7633 if (ex_event == EX_EVENT_CATCH)
7634 trigger_func_name = "__cxa_begin_catch";
7636 trigger_func_name = "__cxa_throw";
7638 break_command_really (get_current_arch (),
7639 trigger_func_name, cond_string, -1,
7640 0 /* condition and thread are valid. */,
7643 AUTO_BOOLEAN_TRUE /* pending */,
7644 &gnu_v3_exception_catchpoint_ops, from_tty,
7650 /* Deal with "catch catch" and "catch throw" commands */
7653 catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
7654 int tempflag, int from_tty)
7656 char *cond_string = NULL;
7657 struct symtab_and_line *sal = NULL;
7661 ep_skip_leading_whitespace (&arg);
7663 cond_string = ep_parse_optional_if_clause (&arg);
7665 if ((*arg != '\0') && !isspace (*arg))
7666 error (_("Junk at end of arguments."));
7668 if (ex_event != EX_EVENT_THROW
7669 && ex_event != EX_EVENT_CATCH)
7670 error (_("Unsupported or unknown exception event; cannot catch it"));
7672 if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty))
7675 warning (_("Unsupported with this platform/compiler combination."));
7678 /* Implementation of "catch catch" command. */
7681 catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command)
7683 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
7684 catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty);
7687 /* Implementation of "catch throw" command. */
7690 catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command)
7692 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
7693 catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty);
7696 /* Create a breakpoint struct for Ada exception catchpoints. */
7699 create_ada_exception_breakpoint (struct gdbarch *gdbarch,
7700 struct symtab_and_line sal,
7704 struct expression *cond,
7705 struct breakpoint_ops *ops,
7709 struct breakpoint *b;
7713 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
7715 loc_gdbarch = gdbarch;
7717 describe_other_breakpoints (loc_gdbarch,
7718 sal.pspace, sal.pc, sal.section, -1);
7719 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
7720 version for exception catchpoints, because two catchpoints
7721 used for different exception names will use the same address.
7722 In this case, a "breakpoint ... also set at..." warning is
7723 unproductive. Besides. the warning phrasing is also a bit
7724 inapropriate, we should use the word catchpoint, and tell
7725 the user what type of catchpoint it is. The above is good
7726 enough for now, though. */
7729 b = set_raw_breakpoint (gdbarch, sal, bp_breakpoint);
7730 set_breakpoint_count (breakpoint_count + 1);
7732 b->enable_state = bp_enabled;
7733 b->disposition = tempflag ? disp_del : disp_donttouch;
7734 b->number = breakpoint_count;
7735 b->ignore_count = 0;
7736 b->loc->cond = cond;
7737 b->addr_string = addr_string;
7738 b->language = language_ada;
7739 b->cond_string = cond_string;
7740 b->exp_string = exp_string;
7745 update_global_location_list (1);
7748 /* Implement the "catch exception" command. */
7751 catch_ada_exception_command (char *arg, int from_tty,
7752 struct cmd_list_element *command)
7754 struct gdbarch *gdbarch = get_current_arch ();
7756 struct symtab_and_line sal;
7758 char *addr_string = NULL;
7759 char *exp_string = NULL;
7760 char *cond_string = NULL;
7761 struct expression *cond = NULL;
7762 struct breakpoint_ops *ops = NULL;
7764 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
7768 sal = ada_decode_exception_location (arg, &addr_string, &exp_string,
7769 &cond_string, &cond, &ops);
7770 create_ada_exception_breakpoint (gdbarch, sal, addr_string, exp_string,
7771 cond_string, cond, ops, tempflag,
7775 /* Cleanup function for a syscall filter list. */
7777 clean_up_filters (void *arg)
7779 VEC(int) *iter = *(VEC(int) **) arg;
7780 VEC_free (int, iter);
7783 /* Splits the argument using space as delimiter. Returns an xmalloc'd
7784 filter list, or NULL if no filtering is required. */
7786 catch_syscall_split_args (char *arg)
7788 VEC(int) *result = NULL;
7789 struct cleanup *cleanup = make_cleanup (clean_up_filters, &result);
7791 while (*arg != '\0')
7793 int i, syscall_number;
7798 /* Skip whitespace. */
7799 while (isspace (*arg))
7802 for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i)
7803 cur_name[i] = arg[i];
7807 /* Check if the user provided a syscall name or a number. */
7808 syscall_number = (int) strtol (cur_name, &endptr, 0);
7809 if (*endptr == '\0')
7811 get_syscall_by_number (syscall_number, &s);
7814 /* We can issue just a warning, but still create the catchpoint.
7815 This is because, even not knowing the syscall name that
7816 this number represents, we can still try to catch the syscall
7818 warning (_("The number '%d' does not represent a known syscall."),
7823 /* We have a name. Let's check if it's valid and convert it
7825 get_syscall_by_name (cur_name, &s);
7827 if (s.number == UNKNOWN_SYSCALL)
7828 /* Here we have to issue an error instead of a warning, because
7829 GDB cannot do anything useful if there's no syscall number to
7831 error (_("Unknown syscall name '%s'."), cur_name);
7834 /* Ok, it's valid. */
7835 VEC_safe_push (int, result, s.number);
7838 discard_cleanups (cleanup);
7842 /* Implement the "catch syscall" command. */
7845 catch_syscall_command_1 (char *arg, int from_tty, struct cmd_list_element *command)
7850 struct gdbarch *gdbarch = get_current_arch ();
7852 /* Checking if the feature if supported. */
7853 if (gdbarch_get_syscall_number_p (gdbarch) == 0)
7854 error (_("The feature 'catch syscall' is not supported on \
7855 this architeture yet."));
7857 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
7859 ep_skip_leading_whitespace (&arg);
7861 /* We need to do this first "dummy" translation in order
7862 to get the syscall XML file loaded or, most important,
7863 to display a warning to the user if there's no XML file
7864 for his/her architecture. */
7865 get_syscall_by_number (0, &s);
7867 /* The allowed syntax is:
7869 catch syscall <name | number> [<name | number> ... <name | number>]
7871 Let's check if there's a syscall name. */
7874 filter = catch_syscall_split_args (arg);
7878 create_syscall_event_catchpoint (tempflag, filter,
7879 &catch_syscall_breakpoint_ops);
7882 /* Implement the "catch assert" command. */
7885 catch_assert_command (char *arg, int from_tty, struct cmd_list_element *command)
7887 struct gdbarch *gdbarch = get_current_arch ();
7889 struct symtab_and_line sal;
7890 char *addr_string = NULL;
7891 struct breakpoint_ops *ops = NULL;
7893 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
7897 sal = ada_decode_assert_location (arg, &addr_string, &ops);
7898 create_ada_exception_breakpoint (gdbarch, sal, addr_string, NULL, NULL, NULL,
7899 ops, tempflag, from_tty);
7903 catch_command (char *arg, int from_tty)
7905 error (_("Catch requires an event name."));
7910 tcatch_command (char *arg, int from_tty)
7912 error (_("Catch requires an event name."));
7915 /* Delete breakpoints by address or line. */
7918 clear_command (char *arg, int from_tty)
7920 struct breakpoint *b;
7921 VEC(breakpoint_p) *found = 0;
7924 struct symtabs_and_lines sals;
7925 struct symtab_and_line sal;
7930 sals = decode_line_spec (arg, 1);
7935 sals.sals = (struct symtab_and_line *)
7936 xmalloc (sizeof (struct symtab_and_line));
7937 make_cleanup (xfree, sals.sals);
7938 init_sal (&sal); /* initialize to zeroes */
7939 sal.line = default_breakpoint_line;
7940 sal.symtab = default_breakpoint_symtab;
7941 sal.pc = default_breakpoint_address;
7942 sal.pspace = default_breakpoint_pspace;
7943 if (sal.symtab == 0)
7944 error (_("No source file specified."));
7952 /* We don't call resolve_sal_pc here. That's not
7953 as bad as it seems, because all existing breakpoints
7954 typically have both file/line and pc set. So, if
7955 clear is given file/line, we can match this to existing
7956 breakpoint without obtaining pc at all.
7958 We only support clearing given the address explicitly
7959 present in breakpoint table. Say, we've set breakpoint
7960 at file:line. There were several PC values for that file:line,
7961 due to optimization, all in one block.
7962 We've picked one PC value. If "clear" is issued with another
7963 PC corresponding to the same file:line, the breakpoint won't
7964 be cleared. We probably can still clear the breakpoint, but
7965 since the other PC value is never presented to user, user
7966 can only find it by guessing, and it does not seem important
7969 /* For each line spec given, delete bps which correspond
7970 to it. Do it in two passes, solely to preserve the current
7971 behavior that from_tty is forced true if we delete more than
7975 for (i = 0; i < sals.nelts; i++)
7977 /* If exact pc given, clear bpts at that pc.
7978 If line given (pc == 0), clear all bpts on specified line.
7979 If defaulting, clear all bpts on default line
7982 defaulting sal.pc != 0 tests to do
7987 1 0 <can't happen> */
7991 /* Find all matching breakpoints and add them to
7996 /* Are we going to delete b? */
7997 if (b->type != bp_none
7998 && b->type != bp_watchpoint
7999 && b->type != bp_hardware_watchpoint
8000 && b->type != bp_read_watchpoint
8001 && b->type != bp_access_watchpoint)
8003 struct bp_location *loc = b->loc;
8004 for (; loc; loc = loc->next)
8006 int pc_match = sal.pc
8007 && (loc->pspace == sal.pspace)
8008 && (loc->address == sal.pc)
8009 && (!section_is_overlay (loc->section)
8010 || loc->section == sal.section);
8011 int line_match = ((default_match || (0 == sal.pc))
8012 && b->source_file != NULL
8013 && sal.symtab != NULL
8014 && sal.pspace == loc->pspace
8015 && strcmp (b->source_file, sal.symtab->filename) == 0
8016 && b->line_number == sal.line);
8017 if (pc_match || line_match)
8026 VEC_safe_push(breakpoint_p, found, b);
8029 /* Now go thru the 'found' chain and delete them. */
8030 if (VEC_empty(breakpoint_p, found))
8033 error (_("No breakpoint at %s."), arg);
8035 error (_("No breakpoint at this line."));
8038 if (VEC_length(breakpoint_p, found) > 1)
8039 from_tty = 1; /* Always report if deleted more than one */
8042 if (VEC_length(breakpoint_p, found) == 1)
8043 printf_unfiltered (_("Deleted breakpoint "));
8045 printf_unfiltered (_("Deleted breakpoints "));
8047 breakpoints_changed ();
8049 for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++)
8052 printf_unfiltered ("%d ", b->number);
8053 delete_breakpoint (b);
8056 putchar_unfiltered ('\n');
8059 /* Delete breakpoint in BS if they are `delete' breakpoints and
8060 all breakpoints that are marked for deletion, whether hit or not.
8061 This is called after any breakpoint is hit, or after errors. */
8064 breakpoint_auto_delete (bpstat bs)
8066 struct breakpoint *b, *temp;
8068 for (; bs; bs = bs->next)
8069 if (bs->breakpoint_at
8070 && bs->breakpoint_at->owner
8071 && bs->breakpoint_at->owner->disposition == disp_del
8073 delete_breakpoint (bs->breakpoint_at->owner);
8075 ALL_BREAKPOINTS_SAFE (b, temp)
8077 if (b->disposition == disp_del_at_next_stop)
8078 delete_breakpoint (b);
8082 /* A cleanup function which destroys a vector. */
8085 do_vec_free (void *p)
8087 VEC(bp_location_p) **vec = p;
8089 VEC_free (bp_location_p, *vec);
8092 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
8093 into the inferior, only remove already-inserted locations that no
8094 longer should be inserted. Functions that delete a breakpoint or
8095 breakpoints should pass false, so that deleting a breakpoint
8096 doesn't have the side effect of inserting the locations of other
8097 breakpoints that are marked not-inserted, but should_be_inserted
8098 returns true on them.
8100 This behaviour is useful is situations close to tear-down -- e.g.,
8101 after an exec, while the target still has execution, but breakpoint
8102 shadows of the previous executable image should *NOT* be restored
8103 to the new image; or before detaching, where the target still has
8104 execution and wants to delete breakpoints from GDB's lists, and all
8105 breakpoints had already been removed from the inferior. */
8108 update_global_location_list (int should_insert)
8110 struct breakpoint *b;
8111 struct bp_location **next = &bp_location_chain;
8112 struct bp_location *loc;
8113 struct bp_location *loc2;
8114 VEC(bp_location_p) *old_locations = NULL;
8117 struct cleanup *cleanups;
8119 cleanups = make_cleanup (do_vec_free, &old_locations);
8120 /* Store old locations for future reference. */
8121 for (loc = bp_location_chain; loc; loc = loc->global_next)
8122 VEC_safe_push (bp_location_p, old_locations, loc);
8124 bp_location_chain = NULL;
8127 for (loc = b->loc; loc; loc = loc->next)
8130 next = &(loc->global_next);
8135 /* Identify bp_location instances that are no longer present in the new
8136 list, and therefore should be freed. Note that it's not necessary that
8137 those locations should be removed from inferior -- if there's another
8138 location at the same address (previously marked as duplicate),
8139 we don't need to remove/insert the location. */
8140 for (ix = 0; VEC_iterate(bp_location_p, old_locations, ix, loc); ++ix)
8142 /* Tells if 'loc' is found amoung the new locations. If not, we
8144 int found_object = 0;
8145 /* Tells if the location should remain inserted in the target. */
8146 int keep_in_target = 0;
8148 for (loc2 = bp_location_chain; loc2; loc2 = loc2->global_next)
8155 /* If this location is no longer present, and inserted, look if there's
8156 maybe a new location at the same address. If so, mark that one
8157 inserted, and don't remove this one. This is needed so that we
8158 don't have a time window where a breakpoint at certain location is not
8163 /* If the location is inserted now, we might have to remove it. */
8165 if (found_object && should_be_inserted (loc))
8167 /* The location is still present in the location list, and still
8168 should be inserted. Don't do anything. */
8173 /* The location is either no longer present, or got disabled.
8174 See if there's another location at the same address, in which
8175 case we don't need to remove this one from the target. */
8176 if (breakpoint_address_is_meaningful (loc->owner))
8177 for (loc2 = bp_location_chain; loc2; loc2 = loc2->global_next)
8179 /* For the sake of should_insert_location. The
8180 call to check_duplicates will fix up this later. */
8181 loc2->duplicate = 0;
8182 if (should_be_inserted (loc2)
8184 && breakpoint_address_match (loc2->pspace->aspace,
8186 loc->pspace->aspace,
8190 loc2->target_info = loc->target_info;
8197 if (!keep_in_target)
8199 if (remove_breakpoint (loc, mark_uninserted))
8201 /* This is just about all we can do. We could keep this
8202 location on the global list, and try to remove it next
8203 time, but there's no particular reason why we will
8206 Note that at this point, loc->owner is still valid,
8207 as delete_breakpoint frees the breakpoint only
8208 after calling us. */
8209 printf_filtered (_("warning: Error removing breakpoint %d\n"),
8210 loc->owner->number);
8218 if (removed && non_stop)
8220 /* This location was removed from the targets. In non-stop mode,
8221 a race condition is possible where we've removed a breakpoint,
8222 but stop events for that breakpoint are already queued and will
8223 arrive later. To suppress spurious SIGTRAPs reported to user,
8224 we keep this breakpoint location for a bit, and will retire it
8225 after we see 3 * thread_count events.
8226 The theory here is that reporting of events should,
8227 "on the average", be fair, so after that many event we'll see
8228 events from all threads that have anything of interest, and no
8229 longer need to keep this breakpoint. This is just a
8230 heuristic, but if it's wrong, we'll report unexpected SIGTRAP,
8231 which is usability issue, but not a correctness problem. */
8232 loc->events_till_retirement = 3 * (thread_count () + 1);
8235 VEC_safe_push (bp_location_p, moribund_locations, loc);
8238 free_bp_location (loc);
8244 check_duplicates (b);
8247 if (breakpoints_always_inserted_mode () && should_insert
8248 && (have_live_inferiors ()
8249 || (gdbarch_has_global_breakpoints (target_gdbarch))))
8250 insert_breakpoint_locations ();
8252 do_cleanups (cleanups);
8256 breakpoint_retire_moribund (void)
8258 struct bp_location *loc;
8261 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
8262 if (--(loc->events_till_retirement) == 0)
8264 free_bp_location (loc);
8265 VEC_unordered_remove (bp_location_p, moribund_locations, ix);
8271 update_global_location_list_nothrow (int inserting)
8273 struct gdb_exception e;
8274 TRY_CATCH (e, RETURN_MASK_ERROR)
8275 update_global_location_list (inserting);
8278 /* Clear BPT from a BPS. */
8280 bpstat_remove_breakpoint (bpstat bps, struct breakpoint *bpt)
8283 for (bs = bps; bs; bs = bs->next)
8284 if (bs->breakpoint_at && bs->breakpoint_at->owner == bpt)
8286 bs->breakpoint_at = NULL;
8288 /* bs->commands will be freed later. */
8292 /* Callback for iterate_over_threads. */
8294 bpstat_remove_breakpoint_callback (struct thread_info *th, void *data)
8296 struct breakpoint *bpt = data;
8297 bpstat_remove_breakpoint (th->stop_bpstat, bpt);
8301 /* Delete a breakpoint and clean up all traces of it in the data
8305 delete_breakpoint (struct breakpoint *bpt)
8307 struct breakpoint *b;
8308 struct bp_location *loc, *next;
8310 gdb_assert (bpt != NULL);
8312 /* Has this bp already been deleted? This can happen because multiple
8313 lists can hold pointers to bp's. bpstat lists are especial culprits.
8315 One example of this happening is a watchpoint's scope bp. When the
8316 scope bp triggers, we notice that the watchpoint is out of scope, and
8317 delete it. We also delete its scope bp. But the scope bp is marked
8318 "auto-deleting", and is already on a bpstat. That bpstat is then
8319 checked for auto-deleting bp's, which are deleted.
8321 A real solution to this problem might involve reference counts in bp's,
8322 and/or giving them pointers back to their referencing bpstat's, and
8323 teaching delete_breakpoint to only free a bp's storage when no more
8324 references were extent. A cheaper bandaid was chosen. */
8325 if (bpt->type == bp_none)
8328 observer_notify_breakpoint_deleted (bpt->number);
8330 if (breakpoint_chain == bpt)
8331 breakpoint_chain = bpt->next;
8336 b->next = bpt->next;
8340 free_command_lines (&bpt->commands);
8341 if (bpt->cond_string != NULL)
8342 xfree (bpt->cond_string);
8343 if (bpt->addr_string != NULL)
8344 xfree (bpt->addr_string);
8345 if (bpt->exp != NULL)
8347 if (bpt->exp_string != NULL)
8348 xfree (bpt->exp_string);
8349 if (bpt->val != NULL)
8350 value_free (bpt->val);
8351 if (bpt->source_file != NULL)
8352 xfree (bpt->source_file);
8353 if (bpt->exec_pathname != NULL)
8354 xfree (bpt->exec_pathname);
8355 clean_up_filters (&bpt->syscalls_to_be_caught);
8357 /* Be sure no bpstat's are pointing at it after it's been freed. */
8358 /* FIXME, how can we find all bpstat's?
8359 We just check stop_bpstat for now. Note that we cannot just
8360 remove bpstats pointing at bpt from the stop_bpstat list
8361 entirely, as breakpoint commands are associated with the bpstat;
8362 if we remove it here, then the later call to
8363 bpstat_do_actions (&stop_bpstat);
8364 in event-top.c won't do anything, and temporary breakpoints
8365 with commands won't work. */
8367 iterate_over_threads (bpstat_remove_breakpoint_callback, bpt);
8369 /* Now that breakpoint is removed from breakpoint
8370 list, update the global location list. This
8371 will remove locations that used to belong to
8372 this breakpoint. Do this before freeing
8373 the breakpoint itself, since remove_breakpoint
8374 looks at location's owner. It might be better
8375 design to have location completely self-contained,
8376 but it's not the case now. */
8377 update_global_location_list (0);
8380 /* On the chance that someone will soon try again to delete this same
8381 bp, we mark it as deleted before freeing its storage. */
8382 bpt->type = bp_none;
8388 do_delete_breakpoint_cleanup (void *b)
8390 delete_breakpoint (b);
8394 make_cleanup_delete_breakpoint (struct breakpoint *b)
8396 return make_cleanup (do_delete_breakpoint_cleanup, b);
8400 delete_command (char *arg, int from_tty)
8402 struct breakpoint *b, *temp;
8408 int breaks_to_delete = 0;
8410 /* Delete all breakpoints if no argument.
8411 Do not delete internal or call-dummy breakpoints, these
8412 have to be deleted with an explicit breakpoint number argument. */
8415 if (b->type != bp_call_dummy
8416 && b->type != bp_shlib_event
8417 && b->type != bp_jit_event
8418 && b->type != bp_thread_event
8419 && b->type != bp_overlay_event
8420 && b->type != bp_longjmp_master
8423 breaks_to_delete = 1;
8428 /* Ask user only if there are some breakpoints to delete. */
8430 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
8432 ALL_BREAKPOINTS_SAFE (b, temp)
8434 if (b->type != bp_call_dummy
8435 && b->type != bp_shlib_event
8436 && b->type != bp_thread_event
8437 && b->type != bp_jit_event
8438 && b->type != bp_overlay_event
8439 && b->type != bp_longjmp_master
8441 delete_breakpoint (b);
8446 map_breakpoint_numbers (arg, delete_breakpoint);
8450 all_locations_are_pending (struct bp_location *loc)
8452 for (; loc; loc = loc->next)
8453 if (!loc->shlib_disabled)
8458 /* Subroutine of update_breakpoint_locations to simplify it.
8459 Return non-zero if multiple fns in list LOC have the same name.
8460 Null names are ignored. */
8463 ambiguous_names_p (struct bp_location *loc)
8465 struct bp_location *l;
8466 htab_t htab = htab_create_alloc (13, htab_hash_string,
8467 (int (*) (const void *, const void *)) streq,
8468 NULL, xcalloc, xfree);
8470 for (l = loc; l != NULL; l = l->next)
8473 const char *name = l->function_name;
8475 /* Allow for some names to be NULL, ignore them. */
8479 slot = (const char **) htab_find_slot (htab, (const void *) name,
8481 /* NOTE: We can assume slot != NULL here because xcalloc never returns
8496 update_breakpoint_locations (struct breakpoint *b,
8497 struct symtabs_and_lines sals)
8501 struct bp_location *existing_locations = b->loc;
8503 /* If there's no new locations, and all existing locations
8504 are pending, don't do anything. This optimizes
8505 the common case where all locations are in the same
8506 shared library, that was unloaded. We'd like to
8507 retain the location, so that when the library
8508 is loaded again, we don't loose the enabled/disabled
8509 status of the individual locations. */
8510 if (all_locations_are_pending (existing_locations) && sals.nelts == 0)
8515 for (i = 0; i < sals.nelts; ++i)
8517 struct bp_location *new_loc =
8518 add_location_to_breakpoint (b, &(sals.sals[i]));
8520 /* Reparse conditions, they might contain references to the
8522 if (b->cond_string != NULL)
8524 struct gdb_exception e;
8527 TRY_CATCH (e, RETURN_MASK_ERROR)
8529 new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc),
8534 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
8535 b->number, e.message);
8536 new_loc->enabled = 0;
8540 if (b->source_file != NULL)
8541 xfree (b->source_file);
8542 if (sals.sals[i].symtab == NULL)
8543 b->source_file = NULL;
8545 b->source_file = xstrdup (sals.sals[i].symtab->filename);
8547 if (b->line_number == 0)
8548 b->line_number = sals.sals[i].line;
8551 /* Update locations of permanent breakpoints. */
8552 if (b->enable_state == bp_permanent)
8553 make_breakpoint_permanent (b);
8555 /* If possible, carry over 'disable' status from existing breakpoints. */
8557 struct bp_location *e = existing_locations;
8558 /* If there are multiple breakpoints with the same function name,
8559 e.g. for inline functions, comparing function names won't work.
8560 Instead compare pc addresses; this is just a heuristic as things
8561 may have moved, but in practice it gives the correct answer
8562 often enough until a better solution is found. */
8563 int have_ambiguous_names = ambiguous_names_p (b->loc);
8565 for (; e; e = e->next)
8567 if (!e->enabled && e->function_name)
8569 struct bp_location *l = b->loc;
8570 if (have_ambiguous_names)
8572 for (; l; l = l->next)
8573 if (breakpoint_address_match (e->pspace->aspace, e->address,
8574 l->pspace->aspace, l->address))
8582 for (; l; l = l->next)
8583 if (l->function_name
8584 && strcmp (e->function_name, l->function_name) == 0)
8594 update_global_location_list (1);
8598 /* Reset a breakpoint given it's struct breakpoint * BINT.
8599 The value we return ends up being the return value from catch_errors.
8600 Unused in this case. */
8603 breakpoint_re_set_one (void *bint)
8605 /* get past catch_errs */
8606 struct breakpoint *b = (struct breakpoint *) bint;
8610 int *not_found_ptr = ¬_found;
8611 struct symtabs_and_lines sals = {0};
8612 struct symtabs_and_lines expanded = {0};
8614 enum enable_state save_enable;
8615 struct gdb_exception e;
8616 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
8621 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
8625 case bp_hardware_breakpoint:
8627 /* Do not attempt to re-set breakpoints disabled during startup. */
8628 if (b->enable_state == bp_startup_disabled)
8631 if (b->addr_string == NULL)
8633 /* Anything without a string can't be re-set. */
8634 delete_breakpoint (b);
8638 set_language (b->language);
8639 input_radix = b->input_radix;
8642 save_current_space_and_thread ();
8643 switch_to_program_space_and_thread (b->pspace);
8645 TRY_CATCH (e, RETURN_MASK_ERROR)
8647 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL,
8652 int not_found_and_ok = 0;
8653 /* For pending breakpoints, it's expected that parsing
8654 will fail until the right shared library is loaded.
8655 User has already told to create pending breakpoints and
8656 don't need extra messages. If breakpoint is in bp_shlib_disabled
8657 state, then user already saw the message about that breakpoint
8658 being disabled, and don't want to see more errors. */
8660 && (b->condition_not_parsed
8661 || (b->loc && b->loc->shlib_disabled)
8662 || b->enable_state == bp_disabled))
8663 not_found_and_ok = 1;
8665 if (!not_found_and_ok)
8667 /* We surely don't want to warn about the same breakpoint
8668 10 times. One solution, implemented here, is disable
8669 the breakpoint on error. Another solution would be to
8670 have separate 'warning emitted' flag. Since this
8671 happens only when a binary has changed, I don't know
8672 which approach is better. */
8673 b->enable_state = bp_disabled;
8674 throw_exception (e);
8680 gdb_assert (sals.nelts == 1);
8682 resolve_sal_pc (&sals.sals[0]);
8683 if (b->condition_not_parsed && s && s[0])
8685 char *cond_string = 0;
8689 find_condition_and_thread (s, sals.sals[0].pc,
8690 &cond_string, &thread, &task);
8692 b->cond_string = cond_string;
8695 b->condition_not_parsed = 0;
8698 expanded = expand_line_sal_maybe (sals.sals[0]);
8701 make_cleanup (xfree, sals.sals);
8702 update_breakpoint_locations (b, expanded);
8706 case bp_hardware_watchpoint:
8707 case bp_read_watchpoint:
8708 case bp_access_watchpoint:
8709 /* Watchpoint can be either on expression using entirely global variables,
8710 or it can be on local variables.
8712 Watchpoints of the first kind are never auto-deleted, and even persist
8713 across program restarts. Since they can use variables from shared
8714 libraries, we need to reparse expression as libraries are loaded
8717 Watchpoints on local variables can also change meaning as result
8718 of solib event. For example, if a watchpoint uses both a local and
8719 a global variables in expression, it's a local watchpoint, but
8720 unloading of a shared library will make the expression invalid.
8721 This is not a very common use case, but we still re-evaluate
8722 expression, to avoid surprises to the user.
8724 Note that for local watchpoints, we re-evaluate it only if
8725 watchpoints frame id is still valid. If it's not, it means
8726 the watchpoint is out of scope and will be deleted soon. In fact,
8727 I'm not sure we'll ever be called in this case.
8729 If a local watchpoint's frame id is still valid, then
8730 b->exp_valid_block is likewise valid, and we can safely use it.
8732 Don't do anything about disabled watchpoints, since they will
8733 be reevaluated again when enabled. */
8734 update_watchpoint (b, 1 /* reparse */);
8736 /* We needn't really do anything to reset these, since the mask
8737 that requests them is unaffected by e.g., new libraries being
8743 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type);
8745 /* Delete overlay event and longjmp master breakpoints; they will be
8746 reset later by breakpoint_re_set. */
8747 case bp_overlay_event:
8748 case bp_longjmp_master:
8749 delete_breakpoint (b);
8752 /* This breakpoint is special, it's set up when the inferior
8753 starts and we really don't want to touch it. */
8754 case bp_shlib_event:
8756 /* Like bp_shlib_event, this breakpoint type is special.
8757 Once it is set up, we do not want to touch it. */
8758 case bp_thread_event:
8760 /* Keep temporary breakpoints, which can be encountered when we step
8761 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
8762 Otherwise these should have been blown away via the cleanup chain
8763 or by breakpoint_init_inferior when we rerun the executable. */
8766 case bp_watchpoint_scope:
8768 case bp_step_resume:
8770 case bp_longjmp_resume:
8775 do_cleanups (cleanups);
8779 /* Re-set all breakpoints after symbols have been re-loaded. */
8781 breakpoint_re_set (void)
8783 struct breakpoint *b, *temp;
8784 enum language save_language;
8785 int save_input_radix;
8786 struct cleanup *old_chain;
8788 save_language = current_language->la_language;
8789 save_input_radix = input_radix;
8790 old_chain = save_current_program_space ();
8792 ALL_BREAKPOINTS_SAFE (b, temp)
8794 /* Format possible error msg */
8795 char *message = xstrprintf ("Error in re-setting breakpoint %d: ",
8797 struct cleanup *cleanups = make_cleanup (xfree, message);
8798 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
8799 do_cleanups (cleanups);
8801 set_language (save_language);
8802 input_radix = save_input_radix;
8804 jit_breakpoint_re_set ();
8806 do_cleanups (old_chain);
8808 create_overlay_event_breakpoint ("_ovly_debug_event");
8809 create_longjmp_master_breakpoint ("longjmp");
8810 create_longjmp_master_breakpoint ("_longjmp");
8811 create_longjmp_master_breakpoint ("siglongjmp");
8812 create_longjmp_master_breakpoint ("_siglongjmp");
8815 /* Reset the thread number of this breakpoint:
8817 - If the breakpoint is for all threads, leave it as-is.
8818 - Else, reset it to the current thread for inferior_ptid. */
8820 breakpoint_re_set_thread (struct breakpoint *b)
8822 if (b->thread != -1)
8824 if (in_thread_list (inferior_ptid))
8825 b->thread = pid_to_thread_id (inferior_ptid);
8827 /* We're being called after following a fork. The new fork is
8828 selected as current, and unless this was a vfork will have a
8829 different program space from the original thread. Reset that
8831 b->loc->pspace = current_program_space;
8835 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
8836 If from_tty is nonzero, it prints a message to that effect,
8837 which ends with a period (no newline). */
8840 set_ignore_count (int bptnum, int count, int from_tty)
8842 struct breakpoint *b;
8848 if (b->number == bptnum)
8850 b->ignore_count = count;
8854 printf_filtered (_("Will stop next time breakpoint %d is reached."),
8856 else if (count == 1)
8857 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
8860 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
8863 breakpoints_changed ();
8864 observer_notify_breakpoint_modified (b->number);
8868 error (_("No breakpoint number %d."), bptnum);
8872 make_breakpoint_silent (struct breakpoint *b)
8874 /* Silence the breakpoint. */
8878 /* Command to set ignore-count of breakpoint N to COUNT. */
8881 ignore_command (char *args, int from_tty)
8887 error_no_arg (_("a breakpoint number"));
8889 num = get_number (&p);
8891 error (_("bad breakpoint number: '%s'"), args);
8893 error (_("Second argument (specified ignore-count) is missing."));
8895 set_ignore_count (num,
8896 longest_to_int (value_as_long (parse_and_eval (p))),
8899 printf_filtered ("\n");
8902 /* Call FUNCTION on each of the breakpoints
8903 whose numbers are given in ARGS. */
8906 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *))
8911 struct breakpoint *b, *tmp;
8915 error_no_arg (_("one or more breakpoint numbers"));
8922 num = get_number_or_range (&p1);
8925 warning (_("bad breakpoint number at or near '%s'"), p);
8929 ALL_BREAKPOINTS_SAFE (b, tmp)
8930 if (b->number == num)
8932 struct breakpoint *related_breakpoint = b->related_breakpoint;
8935 if (related_breakpoint)
8936 function (related_breakpoint);
8940 printf_unfiltered (_("No breakpoint number %d.\n"), num);
8946 static struct bp_location *
8947 find_location_by_number (char *number)
8949 char *dot = strchr (number, '.');
8953 struct breakpoint *b;
8954 struct bp_location *loc;
8959 bp_num = get_number_or_range (&p1);
8961 error (_("Bad breakpoint number '%s'"), number);
8964 if (b->number == bp_num)
8969 if (!b || b->number != bp_num)
8970 error (_("Bad breakpoint number '%s'"), number);
8973 loc_num = get_number_or_range (&p1);
8975 error (_("Bad breakpoint location number '%s'"), number);
8979 for (;loc_num && loc; --loc_num, loc = loc->next)
8982 error (_("Bad breakpoint location number '%s'"), dot+1);
8988 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
8989 If from_tty is nonzero, it prints a message to that effect,
8990 which ends with a period (no newline). */
8993 disable_breakpoint (struct breakpoint *bpt)
8995 /* Never disable a watchpoint scope breakpoint; we want to
8996 hit them when we leave scope so we can delete both the
8997 watchpoint and its scope breakpoint at that time. */
8998 if (bpt->type == bp_watchpoint_scope)
9001 /* You can't disable permanent breakpoints. */
9002 if (bpt->enable_state == bp_permanent)
9005 bpt->enable_state = bp_disabled;
9007 update_global_location_list (0);
9009 observer_notify_breakpoint_modified (bpt->number);
9013 disable_command (char *args, int from_tty)
9015 struct breakpoint *bpt;
9017 ALL_BREAKPOINTS (bpt)
9021 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
9027 case bp_hardware_breakpoint:
9029 case bp_hardware_watchpoint:
9030 case bp_read_watchpoint:
9031 case bp_access_watchpoint:
9032 disable_breakpoint (bpt);
9036 else if (strchr (args, '.'))
9038 struct bp_location *loc = find_location_by_number (args);
9041 update_global_location_list (0);
9044 map_breakpoint_numbers (args, disable_breakpoint);
9048 do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition)
9050 int target_resources_ok, other_type_used;
9053 if (bpt->type == bp_hardware_breakpoint)
9056 i = hw_breakpoint_used_count ();
9057 target_resources_ok =
9058 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
9060 if (target_resources_ok == 0)
9061 error (_("No hardware breakpoint support in the target."));
9062 else if (target_resources_ok < 0)
9063 error (_("Hardware breakpoints used exceeds limit."));
9066 if (bpt->type == bp_watchpoint
9067 || bpt->type == bp_hardware_watchpoint
9068 || bpt->type == bp_read_watchpoint
9069 || bpt->type == bp_access_watchpoint)
9071 struct gdb_exception e;
9073 TRY_CATCH (e, RETURN_MASK_ALL)
9075 update_watchpoint (bpt, 1 /* reparse */);
9079 exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "),
9085 if (bpt->enable_state != bp_permanent)
9086 bpt->enable_state = bp_enabled;
9087 bpt->disposition = disposition;
9088 update_global_location_list (1);
9089 breakpoints_changed ();
9091 observer_notify_breakpoint_modified (bpt->number);
9096 enable_breakpoint (struct breakpoint *bpt)
9098 do_enable_breakpoint (bpt, bpt->disposition);
9101 /* The enable command enables the specified breakpoints (or all defined
9102 breakpoints) so they once again become (or continue to be) effective
9103 in stopping the inferior. */
9106 enable_command (char *args, int from_tty)
9108 struct breakpoint *bpt;
9110 ALL_BREAKPOINTS (bpt)
9114 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
9120 case bp_hardware_breakpoint:
9122 case bp_hardware_watchpoint:
9123 case bp_read_watchpoint:
9124 case bp_access_watchpoint:
9125 enable_breakpoint (bpt);
9129 else if (strchr (args, '.'))
9131 struct bp_location *loc = find_location_by_number (args);
9134 update_global_location_list (1);
9137 map_breakpoint_numbers (args, enable_breakpoint);
9141 enable_once_breakpoint (struct breakpoint *bpt)
9143 do_enable_breakpoint (bpt, disp_disable);
9147 enable_once_command (char *args, int from_tty)
9149 map_breakpoint_numbers (args, enable_once_breakpoint);
9153 enable_delete_breakpoint (struct breakpoint *bpt)
9155 do_enable_breakpoint (bpt, disp_del);
9159 enable_delete_command (char *args, int from_tty)
9161 map_breakpoint_numbers (args, enable_delete_breakpoint);
9165 set_breakpoint_cmd (char *args, int from_tty)
9170 show_breakpoint_cmd (char *args, int from_tty)
9174 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
9176 struct symtabs_and_lines
9177 decode_line_spec_1 (char *string, int funfirstline)
9179 struct symtabs_and_lines sals;
9181 error (_("Empty line specification."));
9182 if (default_breakpoint_valid)
9183 sals = decode_line_1 (&string, funfirstline,
9184 default_breakpoint_symtab,
9185 default_breakpoint_line,
9186 (char ***) NULL, NULL);
9188 sals = decode_line_1 (&string, funfirstline,
9189 (struct symtab *) NULL, 0, (char ***) NULL, NULL);
9191 error (_("Junk at end of line specification: %s"), string);
9195 /* Create and insert a raw software breakpoint at PC. Return an
9196 identifier, which should be used to remove the breakpoint later.
9197 In general, places which call this should be using something on the
9198 breakpoint chain instead; this function should be eliminated
9202 deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch,
9203 struct address_space *aspace, CORE_ADDR pc)
9205 struct bp_target_info *bp_tgt;
9207 bp_tgt = XZALLOC (struct bp_target_info);
9209 bp_tgt->placed_address_space = aspace;
9210 bp_tgt->placed_address = pc;
9212 if (target_insert_breakpoint (gdbarch, bp_tgt) != 0)
9214 /* Could not insert the breakpoint. */
9222 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
9225 deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp)
9227 struct bp_target_info *bp_tgt = bp;
9230 ret = target_remove_breakpoint (gdbarch, bp_tgt);
9236 /* One (or perhaps two) breakpoints used for software single stepping. */
9238 static void *single_step_breakpoints[2];
9239 static struct gdbarch *single_step_gdbarch[2];
9241 /* Create and insert a breakpoint for software single step. */
9244 insert_single_step_breakpoint (struct gdbarch *gdbarch,
9245 struct address_space *aspace, CORE_ADDR next_pc)
9249 if (single_step_breakpoints[0] == NULL)
9251 bpt_p = &single_step_breakpoints[0];
9252 single_step_gdbarch[0] = gdbarch;
9256 gdb_assert (single_step_breakpoints[1] == NULL);
9257 bpt_p = &single_step_breakpoints[1];
9258 single_step_gdbarch[1] = gdbarch;
9261 /* NOTE drow/2006-04-11: A future improvement to this function would be
9262 to only create the breakpoints once, and actually put them on the
9263 breakpoint chain. That would let us use set_raw_breakpoint. We could
9264 adjust the addresses each time they were needed. Doing this requires
9265 corresponding changes elsewhere where single step breakpoints are
9266 handled, however. So, for now, we use this. */
9268 *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc);
9270 error (_("Could not insert single-step breakpoint at %s"),
9271 paddress (gdbarch, next_pc));
9274 /* Remove and delete any breakpoints used for software single step. */
9277 remove_single_step_breakpoints (void)
9279 gdb_assert (single_step_breakpoints[0] != NULL);
9281 /* See insert_single_step_breakpoint for more about this deprecated
9283 deprecated_remove_raw_breakpoint (single_step_gdbarch[0],
9284 single_step_breakpoints[0]);
9285 single_step_gdbarch[0] = NULL;
9286 single_step_breakpoints[0] = NULL;
9288 if (single_step_breakpoints[1] != NULL)
9290 deprecated_remove_raw_breakpoint (single_step_gdbarch[1],
9291 single_step_breakpoints[1]);
9292 single_step_gdbarch[1] = NULL;
9293 single_step_breakpoints[1] = NULL;
9297 /* Check whether a software single-step breakpoint is inserted at PC. */
9300 single_step_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
9304 for (i = 0; i < 2; i++)
9306 struct bp_target_info *bp_tgt = single_step_breakpoints[i];
9308 && breakpoint_address_match (bp_tgt->placed_address_space,
9309 bp_tgt->placed_address,
9317 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
9318 non-zero otherwise. */
9320 is_syscall_catchpoint_enabled (struct breakpoint *bp)
9322 if (syscall_catchpoint_p (bp)
9323 && bp->enable_state != bp_disabled
9324 && bp->enable_state != bp_call_disabled)
9331 catch_syscall_enabled (void)
9333 struct inferior *inf = current_inferior ();
9335 return inf->total_syscalls_count != 0;
9339 catching_syscall_number (int syscall_number)
9341 struct breakpoint *bp;
9343 ALL_BREAKPOINTS (bp)
9344 if (is_syscall_catchpoint_enabled (bp))
9346 if (bp->syscalls_to_be_caught)
9350 VEC_iterate (int, bp->syscalls_to_be_caught, i, iter);
9352 if (syscall_number == iter)
9362 /* Complete syscall names. Used by "catch syscall". */
9364 catch_syscall_completer (struct cmd_list_element *cmd,
9365 char *text, char *word)
9367 const char **list = get_syscall_names ();
9368 return (list == NULL) ? NULL : complete_on_enum (list, text, word);
9371 /* Tracepoint-specific operations. */
9373 /* Set tracepoint count to NUM. */
9375 set_tracepoint_count (int num)
9377 tracepoint_count = num;
9378 set_internalvar_integer (lookup_internalvar ("tpnum"), num);
9382 trace_command (char *arg, int from_tty)
9384 break_command_really (get_current_arch (),
9386 NULL, 0, 1 /* parse arg */,
9387 0 /* tempflag */, 0 /* hardwareflag */,
9389 0 /* Ignore count */,
9390 pending_break_support,
9394 set_tracepoint_count (breakpoint_count);
9397 /* Print information on tracepoint number TPNUM_EXP, or all if
9401 tracepoints_info (char *tpnum_exp, int from_tty)
9403 struct breakpoint *b;
9404 int tps_to_list = 0;
9406 /* In the no-arguments case, say "No tracepoints" if none found. */
9419 ui_out_message (uiout, 0, "No tracepoints.\n");
9424 /* Otherwise be the same as "info break". */
9425 breakpoints_info (tpnum_exp, from_tty);
9428 /* The 'enable trace' command enables tracepoints.
9429 Not supported by all targets. */
9431 enable_trace_command (char *args, int from_tty)
9433 enable_command (args, from_tty);
9436 /* The 'disable trace' command disables tracepoints.
9437 Not supported by all targets. */
9439 disable_trace_command (char *args, int from_tty)
9441 disable_command (args, from_tty);
9444 /* Remove a tracepoint (or all if no argument) */
9446 delete_trace_command (char *arg, int from_tty)
9448 struct breakpoint *b, *temp;
9454 int breaks_to_delete = 0;
9456 /* Delete all breakpoints if no argument.
9457 Do not delete internal or call-dummy breakpoints, these
9458 have to be deleted with an explicit breakpoint number argument. */
9463 breaks_to_delete = 1;
9468 /* Ask user only if there are some breakpoints to delete. */
9470 || (breaks_to_delete && query (_("Delete all tracepoints? "))))
9472 ALL_BREAKPOINTS_SAFE (b, temp)
9474 if (b->type == bp_tracepoint
9476 delete_breakpoint (b);
9481 map_breakpoint_numbers (arg, delete_breakpoint);
9484 /* Set passcount for tracepoint.
9486 First command argument is passcount, second is tracepoint number.
9487 If tracepoint number omitted, apply to most recently defined.
9488 Also accepts special argument "all". */
9491 trace_pass_command (char *args, int from_tty)
9493 struct breakpoint *t1 = (struct breakpoint *) -1, *t2;
9497 if (args == 0 || *args == 0)
9498 error (_("passcount command requires an argument (count + optional TP num)"));
9500 count = strtoul (args, &args, 10); /* Count comes first, then TP num. */
9502 while (*args && isspace ((int) *args))
9505 if (*args && strncasecmp (args, "all", 3) == 0)
9507 args += 3; /* Skip special argument "all". */
9510 error (_("Junk at end of arguments."));
9513 t1 = get_tracepoint_by_number (&args, 1, 1);
9519 ALL_TRACEPOINTS (t2)
9520 if (t1 == (struct breakpoint *) -1 || t1 == t2)
9522 t2->pass_count = count;
9523 observer_notify_tracepoint_modified (t2->number);
9525 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
9529 t1 = get_tracepoint_by_number (&args, 1, 0);
9536 get_tracepoint (int num)
9538 struct breakpoint *t;
9541 if (t->number == num)
9547 /* Utility: parse a tracepoint number and look it up in the list.
9548 If MULTI_P is true, there might be a range of tracepoints in ARG.
9549 if OPTIONAL_P is true, then if the argument is missing, the most
9550 recent tracepoint (tracepoint_count) is returned. */
9552 get_tracepoint_by_number (char **arg, int multi_p, int optional_p)
9554 extern int tracepoint_count;
9555 struct breakpoint *t;
9557 char *instring = arg == NULL ? NULL : *arg;
9559 if (arg == NULL || *arg == NULL || ! **arg)
9562 tpnum = tracepoint_count;
9564 error_no_arg (_("tracepoint number"));
9567 tpnum = multi_p ? get_number_or_range (arg) : get_number (arg);
9571 if (instring && *instring)
9572 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
9575 printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n"));
9580 if (t->number == tpnum)
9585 /* FIXME: if we are in the middle of a range we don't want to give
9586 a message. The current interface to get_number_or_range doesn't
9587 allow us to discover this. */
9588 printf_unfiltered ("No tracepoint number %d.\n", tpnum);
9592 /* save-tracepoints command */
9594 tracepoint_save_command (char *args, int from_tty)
9596 struct breakpoint *tp;
9598 struct action_line *line;
9600 char *i1 = " ", *i2 = " ";
9601 char *indent, *actionline, *pathname;
9603 struct cleanup *cleanup;
9605 if (args == 0 || *args == 0)
9606 error (_("Argument required (file name in which to save tracepoints)"));
9608 /* See if we have anything to save. */
9609 ALL_TRACEPOINTS (tp)
9616 warning (_("save-tracepoints: no tracepoints to save."));
9620 pathname = tilde_expand (args);
9621 cleanup = make_cleanup (xfree, pathname);
9622 fp = fopen (pathname, "w");
9624 error (_("Unable to open file '%s' for saving tracepoints (%s)"),
9625 args, safe_strerror (errno));
9626 make_cleanup_fclose (fp);
9628 ALL_TRACEPOINTS (tp)
9630 if (tp->addr_string)
9631 fprintf (fp, "trace %s\n", tp->addr_string);
9634 sprintf_vma (tmp, tp->loc->address);
9635 fprintf (fp, "trace *0x%s\n", tmp);
9639 fprintf (fp, " passcount %d\n", tp->pass_count);
9643 fprintf (fp, " actions\n");
9645 for (line = tp->actions; line; line = line->next)
9647 struct cmd_list_element *cmd;
9649 QUIT; /* allow user to bail out with ^C */
9650 actionline = line->action;
9651 while (isspace ((int) *actionline))
9654 fprintf (fp, "%s%s\n", indent, actionline);
9655 if (*actionline != '#') /* skip for comment lines */
9657 cmd = lookup_cmd (&actionline, cmdlist, "", -1, 1);
9659 error (_("Bad action list item: %s"), actionline);
9660 if (cmd_cfunc_eq (cmd, while_stepping_pseudocommand))
9662 else if (cmd_cfunc_eq (cmd, end_actions_pseudocommand))
9668 do_cleanups (cleanup);
9670 printf_filtered (_("Tracepoints saved to file '%s'.\n"), args);
9674 /* Create a vector of all tracepoints. */
9679 VEC(breakpoint_p) *tp_vec = 0;
9680 struct breakpoint *tp;
9682 ALL_TRACEPOINTS (tp)
9684 VEC_safe_push (breakpoint_p, tp_vec, tp);
9691 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
9692 It is defined as a macro to prevent duplication.
9693 COMMAND should be a string constant containing the name of the command. */
9694 #define BREAK_ARGS_HELP(command) \
9695 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
9696 LOCATION may be a line number, function name, or \"*\" and an address.\n\
9697 If a line number is specified, break at start of code for that line.\n\
9698 If a function is specified, break at start of code for that function.\n\
9699 If an address is specified, break at that exact address.\n\
9700 With no LOCATION, uses current execution address of selected stack frame.\n\
9701 This is useful for breaking on return to a stack frame.\n\
9703 THREADNUM is the number from \"info threads\".\n\
9704 CONDITION is a boolean expression.\n\
9706 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
9708 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
9710 /* List of subcommands for "catch". */
9711 static struct cmd_list_element *catch_cmdlist;
9713 /* List of subcommands for "tcatch". */
9714 static struct cmd_list_element *tcatch_cmdlist;
9716 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
9717 lists, and pass some additional user data to the command function. */
9719 add_catch_command (char *name, char *docstring,
9720 void (*sfunc) (char *args, int from_tty,
9721 struct cmd_list_element *command),
9722 char **(*completer) (struct cmd_list_element *cmd,
9723 char *text, char *word),
9724 void *user_data_catch,
9725 void *user_data_tcatch)
9727 struct cmd_list_element *command;
9729 command = add_cmd (name, class_breakpoint, NULL, docstring,
9731 set_cmd_sfunc (command, sfunc);
9732 set_cmd_context (command, user_data_catch);
9733 set_cmd_completer (command, completer);
9735 command = add_cmd (name, class_breakpoint, NULL, docstring,
9737 set_cmd_sfunc (command, sfunc);
9738 set_cmd_context (command, user_data_tcatch);
9739 set_cmd_completer (command, completer);
9743 clear_syscall_counts (int pid)
9745 struct inferior *inf = find_inferior_pid (pid);
9747 inf->total_syscalls_count = 0;
9748 inf->any_syscall_count = 0;
9749 VEC_free (int, inf->syscalls_counts);
9753 _initialize_breakpoint (void)
9755 static struct cmd_list_element *breakpoint_set_cmdlist;
9756 static struct cmd_list_element *breakpoint_show_cmdlist;
9757 struct cmd_list_element *c;
9759 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
9760 observer_attach_inferior_exit (clear_syscall_counts);
9762 breakpoint_chain = 0;
9763 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
9764 before a breakpoint is set. */
9765 breakpoint_count = 0;
9767 tracepoint_count = 0;
9769 add_com ("ignore", class_breakpoint, ignore_command, _("\
9770 Set ignore-count of breakpoint number N to COUNT.\n\
9771 Usage is `ignore N COUNT'."));
9773 add_com_alias ("bc", "ignore", class_breakpoint, 1);
9775 add_com ("commands", class_breakpoint, commands_command, _("\
9776 Set commands to be executed when a breakpoint is hit.\n\
9777 Give breakpoint number as argument after \"commands\".\n\
9778 With no argument, the targeted breakpoint is the last one set.\n\
9779 The commands themselves follow starting on the next line.\n\
9780 Type a line containing \"end\" to indicate the end of them.\n\
9781 Give \"silent\" as the first line to make the breakpoint silent;\n\
9782 then no output is printed when it is hit, except what the commands print."));
9784 add_com ("condition", class_breakpoint, condition_command, _("\
9785 Specify breakpoint number N to break only if COND is true.\n\
9786 Usage is `condition N COND', where N is an integer and COND is an\n\
9787 expression to be evaluated whenever breakpoint N is reached."));
9789 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
9790 Set a temporary breakpoint.\n\
9791 Like \"break\" except the breakpoint is only temporary,\n\
9792 so it will be deleted when hit. Equivalent to \"break\" followed\n\
9793 by using \"enable delete\" on the breakpoint number.\n\
9795 BREAK_ARGS_HELP ("tbreak")));
9796 set_cmd_completer (c, location_completer);
9798 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
9799 Set a hardware assisted breakpoint.\n\
9800 Like \"break\" except the breakpoint requires hardware support,\n\
9801 some target hardware may not have this support.\n\
9803 BREAK_ARGS_HELP ("hbreak")));
9804 set_cmd_completer (c, location_completer);
9806 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
9807 Set a temporary hardware assisted breakpoint.\n\
9808 Like \"hbreak\" except the breakpoint is only temporary,\n\
9809 so it will be deleted when hit.\n\
9811 BREAK_ARGS_HELP ("thbreak")));
9812 set_cmd_completer (c, location_completer);
9814 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
9815 Enable some breakpoints.\n\
9816 Give breakpoint numbers (separated by spaces) as arguments.\n\
9817 With no subcommand, breakpoints are enabled until you command otherwise.\n\
9818 This is used to cancel the effect of the \"disable\" command.\n\
9819 With a subcommand you can enable temporarily."),
9820 &enablelist, "enable ", 1, &cmdlist);
9822 add_com ("ab", class_breakpoint, enable_command, _("\
9823 Enable some breakpoints.\n\
9824 Give breakpoint numbers (separated by spaces) as arguments.\n\
9825 With no subcommand, breakpoints are enabled until you command otherwise.\n\
9826 This is used to cancel the effect of the \"disable\" command.\n\
9827 With a subcommand you can enable temporarily."));
9829 add_com_alias ("en", "enable", class_breakpoint, 1);
9831 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
9832 Enable some breakpoints.\n\
9833 Give breakpoint numbers (separated by spaces) as arguments.\n\
9834 This is used to cancel the effect of the \"disable\" command.\n\
9835 May be abbreviated to simply \"enable\".\n"),
9836 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
9838 add_cmd ("once", no_class, enable_once_command, _("\
9839 Enable breakpoints for one hit. Give breakpoint numbers.\n\
9840 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
9843 add_cmd ("delete", no_class, enable_delete_command, _("\
9844 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
9845 If a breakpoint is hit while enabled in this fashion, it is deleted."),
9848 add_cmd ("delete", no_class, enable_delete_command, _("\
9849 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
9850 If a breakpoint is hit while enabled in this fashion, it is deleted."),
9853 add_cmd ("once", no_class, enable_once_command, _("\
9854 Enable breakpoints for one hit. Give breakpoint numbers.\n\
9855 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
9858 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
9859 Disable some breakpoints.\n\
9860 Arguments are breakpoint numbers with spaces in between.\n\
9861 To disable all breakpoints, give no argument.\n\
9862 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
9863 &disablelist, "disable ", 1, &cmdlist);
9864 add_com_alias ("dis", "disable", class_breakpoint, 1);
9865 add_com_alias ("disa", "disable", class_breakpoint, 1);
9867 add_com ("sb", class_breakpoint, disable_command, _("\
9868 Disable some breakpoints.\n\
9869 Arguments are breakpoint numbers with spaces in between.\n\
9870 To disable all breakpoints, give no argument.\n\
9871 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
9873 add_cmd ("breakpoints", class_alias, disable_command, _("\
9874 Disable some breakpoints.\n\
9875 Arguments are breakpoint numbers with spaces in between.\n\
9876 To disable all breakpoints, give no argument.\n\
9877 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
9878 This command may be abbreviated \"disable\"."),
9881 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
9882 Delete some breakpoints or auto-display expressions.\n\
9883 Arguments are breakpoint numbers with spaces in between.\n\
9884 To delete all breakpoints, give no argument.\n\
9886 Also a prefix command for deletion of other GDB objects.\n\
9887 The \"unset\" command is also an alias for \"delete\"."),
9888 &deletelist, "delete ", 1, &cmdlist);
9889 add_com_alias ("d", "delete", class_breakpoint, 1);
9890 add_com_alias ("del", "delete", class_breakpoint, 1);
9892 add_com ("db", class_breakpoint, delete_command, _("\
9893 Delete some breakpoints.\n\
9894 Arguments are breakpoint numbers with spaces in between.\n\
9895 To delete all breakpoints, give no argument.\n"));
9897 add_cmd ("breakpoints", class_alias, delete_command, _("\
9898 Delete some breakpoints or auto-display expressions.\n\
9899 Arguments are breakpoint numbers with spaces in between.\n\
9900 To delete all breakpoints, give no argument.\n\
9901 This command may be abbreviated \"delete\"."),
9904 add_com ("clear", class_breakpoint, clear_command, _("\
9905 Clear breakpoint at specified line or function.\n\
9906 Argument may be line number, function name, or \"*\" and an address.\n\
9907 If line number is specified, all breakpoints in that line are cleared.\n\
9908 If function is specified, breakpoints at beginning of function are cleared.\n\
9909 If an address is specified, breakpoints at that address are cleared.\n\
9911 With no argument, clears all breakpoints in the line that the selected frame\n\
9914 See also the \"delete\" command which clears breakpoints by number."));
9916 c = add_com ("break", class_breakpoint, break_command, _("\
9917 Set breakpoint at specified line or function.\n"
9918 BREAK_ARGS_HELP ("break")));
9919 set_cmd_completer (c, location_completer);
9921 add_com_alias ("b", "break", class_run, 1);
9922 add_com_alias ("br", "break", class_run, 1);
9923 add_com_alias ("bre", "break", class_run, 1);
9924 add_com_alias ("brea", "break", class_run, 1);
9927 add_com_alias ("ba", "break", class_breakpoint, 1);
9931 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
9932 Break in function/address or break at a line in the current file."),
9933 &stoplist, "stop ", 1, &cmdlist);
9934 add_cmd ("in", class_breakpoint, stopin_command,
9935 _("Break in function or address."), &stoplist);
9936 add_cmd ("at", class_breakpoint, stopat_command,
9937 _("Break at a line in the current file."), &stoplist);
9938 add_com ("status", class_info, breakpoints_info, _("\
9939 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
9940 The \"Type\" column indicates one of:\n\
9941 \tbreakpoint - normal breakpoint\n\
9942 \twatchpoint - watchpoint\n\
9943 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
9944 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
9945 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
9946 address and file/line number respectively.\n\
9948 Convenience variable \"$_\" and default examine address for \"x\"\n\
9949 are set to the address of the last breakpoint listed unless the command\n\
9950 is prefixed with \"server \".\n\n\
9951 Convenience variable \"$bpnum\" contains the number of the last\n\
9955 add_info ("breakpoints", breakpoints_info, _("\
9956 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
9957 The \"Type\" column indicates one of:\n\
9958 \tbreakpoint - normal breakpoint\n\
9959 \twatchpoint - watchpoint\n\
9960 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
9961 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
9962 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
9963 address and file/line number respectively.\n\
9965 Convenience variable \"$_\" and default examine address for \"x\"\n\
9966 are set to the address of the last breakpoint listed unless the command\n\
9967 is prefixed with \"server \".\n\n\
9968 Convenience variable \"$bpnum\" contains the number of the last\n\
9972 add_com ("lb", class_breakpoint, breakpoints_info, _("\
9973 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
9974 The \"Type\" column indicates one of:\n\
9975 \tbreakpoint - normal breakpoint\n\
9976 \twatchpoint - watchpoint\n\
9977 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
9978 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
9979 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
9980 address and file/line number respectively.\n\
9982 Convenience variable \"$_\" and default examine address for \"x\"\n\
9983 are set to the address of the last breakpoint listed unless the command\n\
9984 is prefixed with \"server \".\n\n\
9985 Convenience variable \"$bpnum\" contains the number of the last\n\
9988 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
9989 Status of all breakpoints, or breakpoint number NUMBER.\n\
9990 The \"Type\" column indicates one of:\n\
9991 \tbreakpoint - normal breakpoint\n\
9992 \twatchpoint - watchpoint\n\
9993 \tlongjmp - internal breakpoint used to step through longjmp()\n\
9994 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
9995 \tuntil - internal breakpoint used by the \"until\" command\n\
9996 \tfinish - internal breakpoint used by the \"finish\" command\n\
9997 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
9998 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
9999 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
10000 address and file/line number respectively.\n\
10002 Convenience variable \"$_\" and default examine address for \"x\"\n\
10003 are set to the address of the last breakpoint listed unless the command\n\
10004 is prefixed with \"server \".\n\n\
10005 Convenience variable \"$bpnum\" contains the number of the last\n\
10007 &maintenanceinfolist);
10009 add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\
10010 Set catchpoints to catch events."),
10011 &catch_cmdlist, "catch ",
10012 0/*allow-unknown*/, &cmdlist);
10014 add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\
10015 Set temporary catchpoints to catch events."),
10016 &tcatch_cmdlist, "tcatch ",
10017 0/*allow-unknown*/, &cmdlist);
10019 /* Add catch and tcatch sub-commands. */
10020 add_catch_command ("catch", _("\
10021 Catch an exception, when caught.\n\
10022 With an argument, catch only exceptions with the given name."),
10023 catch_catch_command,
10027 add_catch_command ("throw", _("\
10028 Catch an exception, when thrown.\n\
10029 With an argument, catch only exceptions with the given name."),
10030 catch_throw_command,
10034 add_catch_command ("fork", _("Catch calls to fork."),
10035 catch_fork_command_1,
10037 (void *) (uintptr_t) catch_fork_permanent,
10038 (void *) (uintptr_t) catch_fork_temporary);
10039 add_catch_command ("vfork", _("Catch calls to vfork."),
10040 catch_fork_command_1,
10042 (void *) (uintptr_t) catch_vfork_permanent,
10043 (void *) (uintptr_t) catch_vfork_temporary);
10044 add_catch_command ("exec", _("Catch calls to exec."),
10045 catch_exec_command_1,
10049 add_catch_command ("syscall", _("\
10050 Catch system calls by their names and/or numbers.\n\
10051 Arguments say which system calls to catch. If no arguments\n\
10052 are given, every system call will be caught.\n\
10053 Arguments, if given, should be one or more system call names\n\
10054 (if your system supports that), or system call numbers."),
10055 catch_syscall_command_1,
10056 catch_syscall_completer,
10059 add_catch_command ("exception", _("\
10060 Catch Ada exceptions, when raised.\n\
10061 With an argument, catch only exceptions with the given name."),
10062 catch_ada_exception_command,
10066 add_catch_command ("assert", _("\
10067 Catch failed Ada assertions, when raised.\n\
10068 With an argument, catch only exceptions with the given name."),
10069 catch_assert_command,
10074 c = add_com ("watch", class_breakpoint, watch_command, _("\
10075 Set a watchpoint for an expression.\n\
10076 A watchpoint stops execution of your program whenever the value of\n\
10077 an expression changes."));
10078 set_cmd_completer (c, expression_completer);
10080 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
10081 Set a read watchpoint for an expression.\n\
10082 A watchpoint stops execution of your program whenever the value of\n\
10083 an expression is read."));
10084 set_cmd_completer (c, expression_completer);
10086 c = add_com ("awatch", class_breakpoint, awatch_command, _("\
10087 Set a watchpoint for an expression.\n\
10088 A watchpoint stops execution of your program whenever the value of\n\
10089 an expression is either read or written."));
10090 set_cmd_completer (c, expression_completer);
10092 add_info ("watchpoints", breakpoints_info,
10093 _("Synonym for ``info breakpoints''."));
10096 /* XXX: cagney/2005-02-23: This should be a boolean, and should
10097 respond to changes - contrary to the description. */
10098 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
10099 &can_use_hw_watchpoints, _("\
10100 Set debugger's willingness to use watchpoint hardware."), _("\
10101 Show debugger's willingness to use watchpoint hardware."), _("\
10102 If zero, gdb will not use hardware for new watchpoints, even if\n\
10103 such is available. (However, any hardware watchpoints that were\n\
10104 created before setting this to nonzero, will continue to use watchpoint\n\
10107 show_can_use_hw_watchpoints,
10108 &setlist, &showlist);
10110 can_use_hw_watchpoints = 1;
10112 /* Tracepoint manipulation commands. */
10114 c = add_com ("trace", class_breakpoint, trace_command, _("\
10115 Set a tracepoint at specified line or function.\n\
10117 BREAK_ARGS_HELP ("trace") "\n\
10118 Do \"help tracepoints\" for info on other tracepoint commands."));
10119 set_cmd_completer (c, location_completer);
10121 add_com_alias ("tp", "trace", class_alias, 0);
10122 add_com_alias ("tr", "trace", class_alias, 1);
10123 add_com_alias ("tra", "trace", class_alias, 1);
10124 add_com_alias ("trac", "trace", class_alias, 1);
10126 add_info ("tracepoints", tracepoints_info, _("\
10127 Status of tracepoints, or tracepoint number NUMBER.\n\
10128 Convenience variable \"$tpnum\" contains the number of the\n\
10129 last tracepoint set."));
10131 add_info_alias ("tp", "tracepoints", 1);
10133 add_cmd ("tracepoints", class_trace, delete_trace_command, _("\
10134 Delete specified tracepoints.\n\
10135 Arguments are tracepoint numbers, separated by spaces.\n\
10136 No argument means delete all tracepoints."),
10139 c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\
10140 Disable specified tracepoints.\n\
10141 Arguments are tracepoint numbers, separated by spaces.\n\
10142 No argument means disable all tracepoints."),
10144 deprecate_cmd (c, "disable");
10146 c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\
10147 Enable specified tracepoints.\n\
10148 Arguments are tracepoint numbers, separated by spaces.\n\
10149 No argument means enable all tracepoints."),
10151 deprecate_cmd (c, "enable");
10153 add_com ("passcount", class_trace, trace_pass_command, _("\
10154 Set the passcount for a tracepoint.\n\
10155 The trace will end when the tracepoint has been passed 'count' times.\n\
10156 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
10157 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
10159 c = add_com ("save-tracepoints", class_trace, tracepoint_save_command, _("\
10160 Save current tracepoint definitions as a script.\n\
10161 Use the 'source' command in another debug session to restore them."));
10162 set_cmd_completer (c, filename_completer);
10164 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
10165 Breakpoint specific settings\n\
10166 Configure various breakpoint-specific variables such as\n\
10167 pending breakpoint behavior"),
10168 &breakpoint_set_cmdlist, "set breakpoint ",
10169 0/*allow-unknown*/, &setlist);
10170 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
10171 Breakpoint specific settings\n\
10172 Configure various breakpoint-specific variables such as\n\
10173 pending breakpoint behavior"),
10174 &breakpoint_show_cmdlist, "show breakpoint ",
10175 0/*allow-unknown*/, &showlist);
10177 add_setshow_auto_boolean_cmd ("pending", no_class,
10178 &pending_break_support, _("\
10179 Set debugger's behavior regarding pending breakpoints."), _("\
10180 Show debugger's behavior regarding pending breakpoints."), _("\
10181 If on, an unrecognized breakpoint location will cause gdb to create a\n\
10182 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
10183 an error. If auto, an unrecognized breakpoint location results in a\n\
10184 user-query to see if a pending breakpoint should be created."),
10186 show_pending_break_support,
10187 &breakpoint_set_cmdlist,
10188 &breakpoint_show_cmdlist);
10190 pending_break_support = AUTO_BOOLEAN_AUTO;
10192 add_setshow_boolean_cmd ("auto-hw", no_class,
10193 &automatic_hardware_breakpoints, _("\
10194 Set automatic usage of hardware breakpoints."), _("\
10195 Show automatic usage of hardware breakpoints."), _("\
10196 If set, the debugger will automatically use hardware breakpoints for\n\
10197 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
10198 a warning will be emitted for such breakpoints."),
10200 show_automatic_hardware_breakpoints,
10201 &breakpoint_set_cmdlist,
10202 &breakpoint_show_cmdlist);
10204 add_setshow_enum_cmd ("always-inserted", class_support,
10205 always_inserted_enums, &always_inserted_mode, _("\
10206 Set mode for inserting breakpoints."), _("\
10207 Show mode for inserting breakpoints."), _("\
10208 When this mode is off, breakpoints are inserted in inferior when it is\n\
10209 resumed, and removed when execution stops. When this mode is on,\n\
10210 breakpoints are inserted immediately and removed only when the user\n\
10211 deletes the breakpoint. When this mode is auto (which is the default),\n\
10212 the behaviour depends on the non-stop setting (see help set non-stop).\n\
10213 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
10214 behaves as if always-inserted mode is on; if gdb is controlling the\n\
10215 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
10217 &show_always_inserted_mode,
10218 &breakpoint_set_cmdlist,
10219 &breakpoint_show_cmdlist);
10221 automatic_hardware_breakpoints = 1;
10223 observer_attach_about_to_proceed (breakpoint_about_to_proceed);