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/>. */
27 #include "breakpoint.h"
28 #include "tracepoint.h"
30 #include "expression.h"
36 #include "gdbthread.h"
39 #include "gdb_string.h"
46 #include "completer.h"
49 #include "cli/cli-script.h"
50 #include "gdb_assert.h"
55 #include "exceptions.h"
62 /* readline include files */
63 #include "readline/readline.h"
64 #include "readline/history.h"
66 /* readline defines this. */
69 #include "mi/mi-common.h"
71 /* Arguments to pass as context to some catch command handlers. */
72 #define CATCH_PERMANENT ((void *) (uintptr_t) 0)
73 #define CATCH_TEMPORARY ((void *) (uintptr_t) 1)
75 /* Prototypes for local functions. */
77 static void enable_delete_command (char *, int);
79 static void enable_delete_breakpoint (struct breakpoint *);
81 static void enable_once_command (char *, int);
83 static void enable_once_breakpoint (struct breakpoint *);
85 static void disable_command (char *, int);
87 static void enable_command (char *, int);
89 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint *));
91 static void ignore_command (char *, int);
93 static int breakpoint_re_set_one (void *);
95 static void clear_command (char *, int);
97 static void catch_command (char *, int);
99 static void watch_command (char *, int);
101 static int can_use_hardware_watchpoint (struct value *);
103 static void break_command_1 (char *, int, int);
105 static void mention (struct breakpoint *);
107 struct breakpoint *set_raw_breakpoint (struct symtab_and_line, enum bptype);
109 static void check_duplicates (struct breakpoint *);
111 static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
113 static CORE_ADDR adjust_breakpoint_address (CORE_ADDR bpaddr,
116 static void describe_other_breakpoints (CORE_ADDR, struct obj_section *, int);
118 static void breakpoints_info (char *, int);
120 static void breakpoint_1 (int, int);
122 static bpstat bpstat_alloc (const struct bp_location *, bpstat);
124 static int breakpoint_cond_eval (void *);
126 static void cleanup_executing_breakpoints (void *);
128 static void commands_command (char *, int);
130 static void condition_command (char *, int);
132 static int get_number_trailer (char **, int);
134 void set_breakpoint_count (int);
143 static int remove_breakpoint (struct bp_location *, insertion_state_t);
145 static enum print_stop_action print_it_typical (bpstat);
147 static enum print_stop_action print_bp_stop_message (bpstat bs);
149 static int watchpoint_check (void *);
151 static void maintenance_info_breakpoints (char *, int);
153 static void create_overlay_event_breakpoint (char *);
155 static int hw_breakpoint_used_count (void);
157 static int hw_watchpoint_used_count (enum bptype, int *);
159 static void hbreak_command (char *, int);
161 static void thbreak_command (char *, int);
163 static void watch_command_1 (char *, int, int);
165 static void rwatch_command (char *, int);
167 static void awatch_command (char *, int);
169 static void do_enable_breakpoint (struct breakpoint *, enum bpdisp);
171 static void stop_command (char *arg, int from_tty);
173 static void stopin_command (char *arg, int from_tty);
175 static void stopat_command (char *arg, int from_tty);
177 static char *ep_parse_optional_if_clause (char **arg);
179 static char *ep_parse_optional_filename (char **arg);
181 static void catch_exception_command_1 (enum exception_event_kind ex_event,
182 char *arg, int tempflag, int from_tty);
184 static void tcatch_command (char *arg, int from_tty);
186 static void ep_skip_leading_whitespace (char **s);
188 static int single_step_breakpoint_inserted_here_p (CORE_ADDR pc);
190 static void free_bp_location (struct bp_location *loc);
192 static struct bp_location *allocate_bp_location (struct breakpoint *bpt);
194 static void update_global_location_list (int);
196 static void update_global_location_list_nothrow (int);
198 static int is_hardware_watchpoint (struct breakpoint *bpt);
200 static void insert_breakpoint_locations (void);
202 static void tracepoints_info (char *, int);
204 static void delete_trace_command (char *, int);
206 static void enable_trace_command (char *, int);
208 static void disable_trace_command (char *, int);
210 static void trace_pass_command (char *, int);
212 /* Flag indicating that a command has proceeded the inferior past the
213 current breakpoint. */
215 static int breakpoint_proceeded;
218 bpdisp_text (enum bpdisp disp)
220 /* NOTE: the following values are a part of MI protocol and represent
221 values of 'disp' field returned when inferior stops at a breakpoint. */
222 static char *bpdisps[] = {"del", "dstp", "dis", "keep"};
223 return bpdisps[(int) disp];
226 /* Prototypes for exported functions. */
227 /* If FALSE, gdb will not use hardware support for watchpoints, even
228 if such is available. */
229 static int can_use_hw_watchpoints;
232 show_can_use_hw_watchpoints (struct ui_file *file, int from_tty,
233 struct cmd_list_element *c,
236 fprintf_filtered (file, _("\
237 Debugger's willingness to use watchpoint hardware is %s.\n"),
241 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
242 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
243 for unrecognized breakpoint locations.
244 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
245 static enum auto_boolean pending_break_support;
247 show_pending_break_support (struct ui_file *file, int from_tty,
248 struct cmd_list_element *c,
251 fprintf_filtered (file, _("\
252 Debugger's behavior regarding pending breakpoints is %s.\n"),
256 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
257 set with "break" but falling in read-only memory.
258 If 0, gdb will warn about such breakpoints, but won't automatically
259 use hardware breakpoints. */
260 static int automatic_hardware_breakpoints;
262 show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty,
263 struct cmd_list_element *c,
266 fprintf_filtered (file, _("\
267 Automatic usage of hardware breakpoints is %s.\n"),
271 /* If on, gdb will keep breakpoints inserted even as inferior is
272 stopped, and immediately insert any new breakpoints. If off, gdb
273 will insert breakpoints into inferior only when resuming it, and
274 will remove breakpoints upon stop. If auto, GDB will behave as ON
275 if in non-stop mode, and as OFF if all-stop mode.*/
277 static const char always_inserted_auto[] = "auto";
278 static const char always_inserted_on[] = "on";
279 static const char always_inserted_off[] = "off";
280 static const char *always_inserted_enums[] = {
281 always_inserted_auto,
286 static const char *always_inserted_mode = always_inserted_auto;
288 show_always_inserted_mode (struct ui_file *file, int from_tty,
289 struct cmd_list_element *c, const char *value)
291 if (always_inserted_mode == always_inserted_auto)
292 fprintf_filtered (file, _("\
293 Always inserted breakpoint mode is %s (currently %s).\n"),
295 breakpoints_always_inserted_mode () ? "on" : "off");
297 fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), value);
301 breakpoints_always_inserted_mode (void)
303 return (always_inserted_mode == always_inserted_on
304 || (always_inserted_mode == always_inserted_auto && non_stop));
307 void _initialize_breakpoint (void);
309 /* Are we executing breakpoint commands? */
310 static int executing_breakpoint_commands;
312 /* Are overlay event breakpoints enabled? */
313 static int overlay_events_enabled;
315 /* Walk the following statement or block through all breakpoints.
316 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
319 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
321 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
322 for (B = breakpoint_chain; \
323 B ? (TMP=B->next, 1): 0; \
326 /* Similar iterators for the low-level breakpoints. */
328 #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->global_next)
330 #define ALL_BP_LOCATIONS_SAFE(B,TMP) \
331 for (B = bp_location_chain; \
332 B ? (TMP=B->global_next, 1): 0; \
335 /* Iterator for tracepoints only. */
337 #define ALL_TRACEPOINTS(B) \
338 for (B = breakpoint_chain; B; B = B->next) \
339 if ((B)->type == bp_tracepoint)
341 /* Chains of all breakpoints defined. */
343 struct breakpoint *breakpoint_chain;
345 struct bp_location *bp_location_chain;
347 /* The locations that no longer correspond to any breakpoint,
348 unlinked from bp_location_chain, but for which a hit
349 may still be reported by a target. */
350 VEC(bp_location_p) *moribund_locations = NULL;
352 /* Number of last breakpoint made. */
354 int breakpoint_count;
356 /* Number of last tracepoint made. */
358 int tracepoint_count;
360 /* Return whether a breakpoint is an active enabled breakpoint. */
362 breakpoint_enabled (struct breakpoint *b)
364 return (b->enable_state == bp_enabled);
367 /* Set breakpoint count to NUM. */
370 set_breakpoint_count (int num)
372 breakpoint_count = num;
373 set_internalvar (lookup_internalvar ("bpnum"),
374 value_from_longest (builtin_type_int32, (LONGEST) num));
377 /* Used in run_command to zero the hit count when a new run starts. */
380 clear_breakpoint_hit_counts (void)
382 struct breakpoint *b;
388 /* Default address, symtab and line to put a breakpoint at
389 for "break" command with no arg.
390 if default_breakpoint_valid is zero, the other three are
391 not valid, and "break" with no arg is an error.
393 This set by print_stack_frame, which calls set_default_breakpoint. */
395 int default_breakpoint_valid;
396 CORE_ADDR default_breakpoint_address;
397 struct symtab *default_breakpoint_symtab;
398 int default_breakpoint_line;
400 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
401 Advance *PP after the string and any trailing whitespace.
403 Currently the string can either be a number or "$" followed by the name
404 of a convenience variable. Making it an expression wouldn't work well
405 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
407 If the string is a NULL pointer, that denotes the last breakpoint.
409 TRAILER is a character which can be found after the number; most
410 commonly this is `-'. If you don't want a trailer, use \0. */
412 get_number_trailer (char **pp, int trailer)
414 int retval = 0; /* default */
418 /* Empty line means refer to the last breakpoint. */
419 return breakpoint_count;
422 /* Make a copy of the name, so we can null-terminate it
423 to pass to lookup_internalvar(). */
428 while (isalnum (*p) || *p == '_')
430 varname = (char *) alloca (p - start + 1);
431 strncpy (varname, start, p - start);
432 varname[p - start] = '\0';
433 val = value_of_internalvar (lookup_internalvar (varname));
434 if (TYPE_CODE (value_type (val)) == TYPE_CODE_INT)
435 retval = (int) value_as_long (val);
438 printf_filtered (_("Convenience variable must have integer value.\n"));
446 while (*p >= '0' && *p <= '9')
449 /* There is no number here. (e.g. "cond a == b"). */
451 /* Skip non-numeric token */
452 while (*p && !isspace((int) *p))
454 /* Return zero, which caller must interpret as error. */
460 if (!(isspace (*p) || *p == '\0' || *p == trailer))
462 /* Trailing junk: return 0 and let caller print error msg. */
463 while (!(isspace (*p) || *p == '\0' || *p == trailer))
474 /* Like get_number_trailer, but don't allow a trailer. */
476 get_number (char **pp)
478 return get_number_trailer (pp, '\0');
481 /* Parse a number or a range.
482 * A number will be of the form handled by get_number.
483 * A range will be of the form <number1> - <number2>, and
484 * will represent all the integers between number1 and number2,
487 * While processing a range, this fuction is called iteratively;
488 * At each call it will return the next value in the range.
490 * At the beginning of parsing a range, the char pointer PP will
491 * be advanced past <number1> and left pointing at the '-' token.
492 * Subsequent calls will not advance the pointer until the range
493 * is completed. The call that completes the range will advance
494 * pointer PP past <number2>.
498 get_number_or_range (char **pp)
500 static int last_retval, end_value;
501 static char *end_ptr;
502 static int in_range = 0;
506 /* Default case: pp is pointing either to a solo number,
507 or to the first number of a range. */
508 last_retval = get_number_trailer (pp, '-');
513 /* This is the start of a range (<number1> - <number2>).
514 Skip the '-', parse and remember the second number,
515 and also remember the end of the final token. */
519 while (isspace ((int) *end_ptr))
520 end_ptr++; /* skip white space */
521 end_value = get_number (temp);
522 if (end_value < last_retval)
524 error (_("inverted range"));
526 else if (end_value == last_retval)
528 /* degenerate range (number1 == number2). Advance the
529 token pointer so that the range will be treated as a
538 error (_("negative value"));
541 /* pp points to the '-' that betokens a range. All
542 number-parsing has already been done. Return the next
543 integer value (one greater than the saved previous value).
544 Do not advance the token pointer 'pp' until the end of range
547 if (++last_retval == end_value)
549 /* End of range reached; advance token pointer. */
559 /* condition N EXP -- set break condition of breakpoint N to EXP. */
562 condition_command (char *arg, int from_tty)
564 struct breakpoint *b;
569 error_no_arg (_("breakpoint number"));
572 bnum = get_number (&p);
574 error (_("Bad breakpoint argument: '%s'"), arg);
577 if (b->number == bnum)
579 struct bp_location *loc = b->loc;
580 for (; loc; loc = loc->next)
588 if (b->cond_string != NULL)
589 xfree (b->cond_string);
593 b->cond_string = NULL;
595 printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum);
600 /* I don't know if it matters whether this is the string the user
601 typed in or the decompiled expression. */
602 b->cond_string = savestring (arg, strlen (arg));
603 b->condition_not_parsed = 0;
604 for (loc = b->loc; loc; loc = loc->next)
608 parse_exp_1 (&arg, block_for_pc (loc->address), 0);
610 error (_("Junk at end of expression"));
613 breakpoints_changed ();
614 observer_notify_breakpoint_modified (b->number);
618 error (_("No breakpoint number %d."), bnum);
622 commands_command (char *arg, int from_tty)
624 struct breakpoint *b;
627 struct command_line *l;
629 /* If we allowed this, we would have problems with when to
630 free the storage, if we change the commands currently
633 if (executing_breakpoint_commands)
634 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
637 bnum = get_number (&p);
640 error (_("Unexpected extra arguments following breakpoint number."));
643 if (b->number == bnum)
645 char *tmpbuf = xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
647 struct cleanup *cleanups = make_cleanup (xfree, tmpbuf);
648 l = read_command_lines (tmpbuf, from_tty, 1);
649 do_cleanups (cleanups);
650 free_command_lines (&b->commands);
652 breakpoints_changed ();
653 observer_notify_breakpoint_modified (b->number);
656 error (_("No breakpoint number %d."), bnum);
659 /* Like commands_command, but instead of reading the commands from
660 input stream, takes them from an already parsed command structure.
662 This is used by cli-script.c to DTRT with breakpoint commands
663 that are part of if and while bodies. */
664 enum command_control_type
665 commands_from_control_command (char *arg, struct command_line *cmd)
667 struct breakpoint *b;
671 /* If we allowed this, we would have problems with when to
672 free the storage, if we change the commands currently
675 if (executing_breakpoint_commands)
676 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
678 /* An empty string for the breakpoint number means the last
679 breakpoint, but get_number expects a NULL pointer. */
684 bnum = get_number (&p);
687 error (_("Unexpected extra arguments following breakpoint number."));
690 if (b->number == bnum)
692 free_command_lines (&b->commands);
693 if (cmd->body_count != 1)
694 error (_("Invalid \"commands\" block structure."));
695 /* We need to copy the commands because if/while will free the
696 list after it finishes execution. */
697 b->commands = copy_command_lines (cmd->body_list[0]);
698 breakpoints_changed ();
699 observer_notify_breakpoint_modified (b->number);
700 return simple_control;
702 error (_("No breakpoint number %d."), bnum);
705 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
706 by replacing any memory breakpoints with their shadowed contents. */
709 breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len)
711 struct bp_location *b;
712 CORE_ADDR bp_addr = 0;
718 if (b->owner->type == bp_none)
719 warning (_("reading through apparently deleted breakpoint #%d?"),
722 if (b->loc_type != bp_loc_software_breakpoint)
726 /* Addresses and length of the part of the breakpoint that
728 bp_addr = b->target_info.placed_address;
729 bp_size = b->target_info.shadow_len;
731 /* bp isn't valid, or doesn't shadow memory. */
734 if (bp_addr + bp_size <= memaddr)
735 /* The breakpoint is entirely before the chunk of memory we
739 if (bp_addr >= memaddr + len)
740 /* The breakpoint is entirely after the chunk of memory we are
744 /* Offset within shadow_contents. */
745 if (bp_addr < memaddr)
747 /* Only copy the second part of the breakpoint. */
748 bp_size -= memaddr - bp_addr;
749 bptoffset = memaddr - bp_addr;
753 if (bp_addr + bp_size > memaddr + len)
755 /* Only copy the first part of the breakpoint. */
756 bp_size -= (bp_addr + bp_size) - (memaddr + len);
759 memcpy (buf + bp_addr - memaddr,
760 b->target_info.shadow_contents + bptoffset, bp_size);
765 /* A wrapper function for inserting catchpoints. */
767 insert_catchpoint (struct ui_out *uo, void *args)
769 struct breakpoint *b = (struct breakpoint *) args;
772 gdb_assert (b->type == bp_catchpoint);
773 gdb_assert (b->ops != NULL && b->ops->insert != NULL);
779 is_hardware_watchpoint (struct breakpoint *bpt)
781 return (bpt->type == bp_hardware_watchpoint
782 || bpt->type == bp_read_watchpoint
783 || bpt->type == bp_access_watchpoint);
786 /* Find the current value of a watchpoint on EXP. Return the value in
787 *VALP and *RESULTP and the chain of intermediate and final values
788 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
791 If a memory error occurs while evaluating the expression, *RESULTP will
792 be set to NULL. *RESULTP may be a lazy value, if the result could
793 not be read from memory. It is used to determine whether a value
794 is user-specified (we should watch the whole value) or intermediate
795 (we should watch only the bit used to locate the final value).
797 If the final value, or any intermediate value, could not be read
798 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
799 set to any referenced values. *VALP will never be a lazy value.
800 This is the value which we store in struct breakpoint.
802 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
803 value chain. The caller must free the values individually. If
804 VAL_CHAIN is NULL, all generated values will be left on the value
808 fetch_watchpoint_value (struct expression *exp, struct value **valp,
809 struct value **resultp, struct value **val_chain)
811 struct value *mark, *new_mark, *result;
812 volatile struct gdb_exception ex;
820 /* Evaluate the expression. */
821 mark = value_mark ();
824 TRY_CATCH (ex, RETURN_MASK_ALL)
826 result = evaluate_expression (exp);
830 /* Ignore memory errors, we want watchpoints pointing at
831 inaccessible memory to still be created; otherwise, throw the
832 error to some higher catcher. */
838 throw_exception (ex);
843 new_mark = value_mark ();
844 if (mark == new_mark)
849 /* Make sure it's not lazy, so that after the target stops again we
850 have a non-lazy previous value to compare with. */
852 && (!value_lazy (result) || gdb_value_fetch_lazy (result)))
857 /* Return the chain of intermediate values. We use this to
858 decide which addresses to watch. */
859 *val_chain = new_mark;
860 value_release_to_mark (mark);
864 /* Assuming that B is a watchpoint:
865 - Reparse watchpoint expression, if REPARSE is non-zero
866 - Evaluate expression and store the result in B->val
867 - Evaluate the condition if there is one, and store the result
869 - Update the list of values that must be watched in B->loc.
871 If the watchpoint disposition is disp_del_at_next_stop, then do nothing.
872 If this is local watchpoint that is out of scope, delete it. */
874 update_watchpoint (struct breakpoint *b, int reparse)
876 int within_current_scope;
877 struct frame_id saved_frame_id;
878 struct bp_location *loc;
881 /* We don't free locations. They are stored in bp_location_chain and
882 update_global_locations will eventually delete them and remove
883 breakpoints if needed. */
886 if (b->disposition == disp_del_at_next_stop)
889 /* Save the current frame's ID so we can restore it after
890 evaluating the watchpoint expression on its own frame. */
891 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
892 took a frame parameter, so that we didn't have to change the
894 saved_frame_id = get_frame_id (get_selected_frame (NULL));
896 /* Determine if the watchpoint is within scope. */
897 if (b->exp_valid_block == NULL)
898 within_current_scope = 1;
901 struct frame_info *fi;
902 fi = frame_find_by_id (b->watchpoint_frame);
903 within_current_scope = (fi != NULL);
904 if (within_current_scope)
908 if (within_current_scope && reparse)
917 b->exp = parse_exp_1 (&s, b->exp_valid_block, 0);
918 /* If the meaning of expression itself changed, the old value is
919 no longer relevant. We don't want to report a watchpoint hit
920 to the user when the old value and the new value may actually
921 be completely different objects. */
927 /* If we failed to parse the expression, for example because
928 it refers to a global variable in a not-yet-loaded shared library,
929 don't try to insert watchpoint. We don't automatically delete
930 such watchpoint, though, since failure to parse expression
931 is different from out-of-scope watchpoint. */
932 if (within_current_scope && b->exp)
934 struct value *val_chain, *v, *result, *next;
936 fetch_watchpoint_value (b->exp, &v, &result, &val_chain);
938 /* Avoid setting b->val if it's already set. The meaning of
939 b->val is 'the last value' user saw, and we should update
940 it only if we reported that last value to user. As it
941 happens, the code that reports it updates b->val directly. */
948 /* Change the type of breakpoint between hardware assisted or an
949 ordinary watchpoint depending on the hardware support and free
950 hardware slots. REPARSE is set when the inferior is started. */
951 if ((b->type == bp_watchpoint || b->type == bp_hardware_watchpoint)
954 int i, mem_cnt, other_type_used;
956 i = hw_watchpoint_used_count (bp_hardware_watchpoint,
958 mem_cnt = can_use_hardware_watchpoint (val_chain);
961 b->type = bp_watchpoint;
964 int target_resources_ok = target_can_use_hardware_watchpoint
965 (bp_hardware_watchpoint, i + mem_cnt, other_type_used);
966 if (target_resources_ok <= 0)
967 b->type = bp_watchpoint;
969 b->type = bp_hardware_watchpoint;
973 /* Look at each value on the value chain. */
974 for (v = val_chain; v; v = next)
976 /* If it's a memory location, and GDB actually needed
977 its contents to evaluate the expression, then we
978 must watch it. If the first value returned is
979 still lazy, that means an error occurred reading it;
980 watch it anyway in case it becomes readable. */
981 if (VALUE_LVAL (v) == lval_memory
982 && (v == val_chain || ! value_lazy (v)))
984 struct type *vtype = check_typedef (value_type (v));
986 /* We only watch structs and arrays if user asked
987 for it explicitly, never if they just happen to
988 appear in the middle of some value chain. */
990 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
991 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
995 struct bp_location *loc, **tmp;
997 addr = VALUE_ADDRESS (v) + value_offset (v);
998 len = TYPE_LENGTH (value_type (v));
1000 if (b->type == bp_read_watchpoint)
1002 else if (b->type == bp_access_watchpoint)
1005 loc = allocate_bp_location (b);
1006 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
1009 loc->address = addr;
1011 loc->watchpoint_type = type;
1015 next = value_next (v);
1020 /* We just regenerated the list of breakpoint locations.
1021 The new location does not have its condition field set to anything
1022 and therefore, we must always reparse the cond_string, independently
1023 of the value of the reparse flag. */
1024 if (b->cond_string != NULL)
1026 char *s = b->cond_string;
1027 b->loc->cond = parse_exp_1 (&s, b->exp_valid_block, 0);
1030 else if (!within_current_scope)
1032 printf_filtered (_("\
1033 Watchpoint %d deleted because the program has left the block \n\
1034 in which its expression is valid.\n"),
1036 if (b->related_breakpoint)
1037 b->related_breakpoint->disposition = disp_del_at_next_stop;
1038 b->disposition = disp_del_at_next_stop;
1041 /* Restore the selected frame. */
1042 select_frame (frame_find_by_id (saved_frame_id));
1046 /* Returns 1 iff breakpoint location should be
1047 inserted in the inferior. */
1049 should_be_inserted (struct bp_location *bpt)
1051 if (!breakpoint_enabled (bpt->owner))
1054 if (bpt->owner->disposition == disp_del_at_next_stop)
1057 if (!bpt->enabled || bpt->shlib_disabled || bpt->duplicate)
1060 /* Tracepoints are inserted by the target at a time of its choosing,
1062 if (bpt->owner->type == bp_tracepoint)
1068 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
1069 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
1070 and HW_BREAKPOINT_ERROR are used to report problems.
1072 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1073 method for each breakpoint or catchpoint type. */
1075 insert_bp_location (struct bp_location *bpt,
1076 struct ui_file *tmp_error_stream,
1077 int *disabled_breaks,
1078 int *hw_breakpoint_error)
1082 if (!should_be_inserted (bpt) || bpt->inserted)
1085 /* Initialize the target-specific information. */
1086 memset (&bpt->target_info, 0, sizeof (bpt->target_info));
1087 bpt->target_info.placed_address = bpt->address;
1089 if (bpt->loc_type == bp_loc_software_breakpoint
1090 || bpt->loc_type == bp_loc_hardware_breakpoint)
1092 if (bpt->owner->type != bp_hardware_breakpoint)
1094 /* If the explicitly specified breakpoint type
1095 is not hardware breakpoint, check the memory map to see
1096 if the breakpoint address is in read only memory or not.
1097 Two important cases are:
1098 - location type is not hardware breakpoint, memory
1099 is readonly. We change the type of the location to
1100 hardware breakpoint.
1101 - location type is hardware breakpoint, memory is read-write.
1102 This means we've previously made the location hardware one, but
1103 then the memory map changed, so we undo.
1105 When breakpoints are removed, remove_breakpoints will
1106 use location types we've just set here, the only possible
1107 problem is that memory map has changed during running program,
1108 but it's not going to work anyway with current gdb. */
1109 struct mem_region *mr
1110 = lookup_mem_region (bpt->target_info.placed_address);
1114 if (automatic_hardware_breakpoints)
1117 enum bp_loc_type new_type;
1119 if (mr->attrib.mode != MEM_RW)
1120 new_type = bp_loc_hardware_breakpoint;
1122 new_type = bp_loc_software_breakpoint;
1124 if (new_type != bpt->loc_type)
1126 static int said = 0;
1127 bpt->loc_type = new_type;
1130 fprintf_filtered (gdb_stdout, _("\
1131 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1136 else if (bpt->loc_type == bp_loc_software_breakpoint
1137 && mr->attrib.mode != MEM_RW)
1138 warning (_("cannot set software breakpoint at readonly address %s"),
1139 paddr (bpt->address));
1143 /* First check to see if we have to handle an overlay. */
1144 if (overlay_debugging == ovly_off
1145 || bpt->section == NULL
1146 || !(section_is_overlay (bpt->section)))
1148 /* No overlay handling: just set the breakpoint. */
1150 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1151 val = target_insert_hw_breakpoint (&bpt->target_info);
1153 val = target_insert_breakpoint (&bpt->target_info);
1157 /* This breakpoint is in an overlay section.
1158 Shall we set a breakpoint at the LMA? */
1159 if (!overlay_events_enabled)
1161 /* Yes -- overlay event support is not active,
1162 so we must try to set a breakpoint at the LMA.
1163 This will not work for a hardware breakpoint. */
1164 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1165 warning (_("hardware breakpoint %d not supported in overlay!"),
1166 bpt->owner->number);
1169 CORE_ADDR addr = overlay_unmapped_address (bpt->address,
1171 /* Set a software (trap) breakpoint at the LMA. */
1172 bpt->overlay_target_info = bpt->target_info;
1173 bpt->overlay_target_info.placed_address = addr;
1174 val = target_insert_breakpoint (&bpt->overlay_target_info);
1176 fprintf_unfiltered (tmp_error_stream,
1177 "Overlay breakpoint %d failed: in ROM?\n",
1178 bpt->owner->number);
1181 /* Shall we set a breakpoint at the VMA? */
1182 if (section_is_mapped (bpt->section))
1184 /* Yes. This overlay section is mapped into memory. */
1185 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1186 val = target_insert_hw_breakpoint (&bpt->target_info);
1188 val = target_insert_breakpoint (&bpt->target_info);
1192 /* No. This breakpoint will not be inserted.
1193 No error, but do not mark the bp as 'inserted'. */
1200 /* Can't set the breakpoint. */
1201 if (solib_name_from_address (bpt->address))
1203 /* See also: disable_breakpoints_in_shlibs. */
1205 bpt->shlib_disabled = 1;
1206 if (!*disabled_breaks)
1208 fprintf_unfiltered (tmp_error_stream,
1209 "Cannot insert breakpoint %d.\n",
1210 bpt->owner->number);
1211 fprintf_unfiltered (tmp_error_stream,
1212 "Temporarily disabling shared library breakpoints:\n");
1214 *disabled_breaks = 1;
1215 fprintf_unfiltered (tmp_error_stream,
1216 "breakpoint #%d\n", bpt->owner->number);
1220 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1222 *hw_breakpoint_error = 1;
1223 fprintf_unfiltered (tmp_error_stream,
1224 "Cannot insert hardware breakpoint %d.\n",
1225 bpt->owner->number);
1229 fprintf_unfiltered (tmp_error_stream,
1230 "Cannot insert breakpoint %d.\n",
1231 bpt->owner->number);
1232 fprintf_filtered (tmp_error_stream,
1233 "Error accessing memory address ");
1234 fputs_filtered (paddress (bpt->address), tmp_error_stream);
1235 fprintf_filtered (tmp_error_stream, ": %s.\n",
1236 safe_strerror (val));
1247 else if (bpt->loc_type == bp_loc_hardware_watchpoint
1248 /* NOTE drow/2003-09-08: This state only exists for removing
1249 watchpoints. It's not clear that it's necessary... */
1250 && bpt->owner->disposition != disp_del_at_next_stop)
1252 val = target_insert_watchpoint (bpt->address,
1254 bpt->watchpoint_type);
1255 bpt->inserted = (val != -1);
1258 else if (bpt->owner->type == bp_catchpoint)
1260 struct gdb_exception e = catch_exception (uiout, insert_catchpoint,
1261 bpt->owner, RETURN_MASK_ERROR);
1262 exception_fprintf (gdb_stderr, e, "warning: inserting catchpoint %d: ",
1263 bpt->owner->number);
1265 bpt->owner->enable_state = bp_disabled;
1269 /* We've already printed an error message if there was a problem
1270 inserting this catchpoint, and we've disabled the catchpoint,
1271 so just return success. */
1278 /* Make sure all breakpoints are inserted in inferior.
1279 Throws exception on any error.
1280 A breakpoint that is already inserted won't be inserted
1281 again, so calling this function twice is safe. */
1283 insert_breakpoints (void)
1285 struct breakpoint *bpt;
1287 ALL_BREAKPOINTS (bpt)
1288 if (is_hardware_watchpoint (bpt))
1289 update_watchpoint (bpt, 0 /* don't reparse. */);
1291 update_global_location_list (1);
1293 if (!breakpoints_always_inserted_mode ()
1294 && (target_has_execution
1295 || (gdbarch_has_global_solist (target_gdbarch)
1296 && target_supports_multi_process ())))
1297 /* update_global_location_list does not insert breakpoints
1298 when always_inserted_mode is not enabled. Explicitly
1300 insert_breakpoint_locations ();
1303 /* insert_breakpoints is used when starting or continuing the program.
1304 remove_breakpoints is used when the program stops.
1305 Both return zero if successful,
1306 or an `errno' value if could not write the inferior. */
1309 insert_breakpoint_locations (void)
1311 struct breakpoint *bpt;
1312 struct bp_location *b, *temp;
1315 int disabled_breaks = 0;
1316 int hw_breakpoint_error = 0;
1318 struct ui_file *tmp_error_stream = mem_fileopen ();
1319 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
1321 /* Explicitly mark the warning -- this will only be printed if
1322 there was an error. */
1323 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
1325 ALL_BP_LOCATIONS_SAFE (b, temp)
1327 if (!should_be_inserted (b) || b->inserted)
1330 /* There is no point inserting thread-specific breakpoints if the
1331 thread no longer exists. */
1332 if (b->owner->thread != -1
1333 && !valid_thread_id (b->owner->thread))
1336 val = insert_bp_location (b, tmp_error_stream,
1338 &hw_breakpoint_error);
1343 /* If we failed to insert all locations of a watchpoint,
1344 remove them, as half-inserted watchpoint is of limited use. */
1345 ALL_BREAKPOINTS (bpt)
1347 int some_failed = 0;
1348 struct bp_location *loc;
1350 if (!is_hardware_watchpoint (bpt))
1353 if (!breakpoint_enabled (bpt))
1356 if (bpt->disposition == disp_del_at_next_stop)
1359 for (loc = bpt->loc; loc; loc = loc->next)
1367 for (loc = bpt->loc; loc; loc = loc->next)
1369 remove_breakpoint (loc, mark_uninserted);
1371 hw_breakpoint_error = 1;
1372 fprintf_unfiltered (tmp_error_stream,
1373 "Could not insert hardware watchpoint %d.\n",
1381 /* If a hardware breakpoint or watchpoint was inserted, add a
1382 message about possibly exhausted resources. */
1383 if (hw_breakpoint_error)
1385 fprintf_unfiltered (tmp_error_stream,
1386 "Could not insert hardware breakpoints:\n\
1387 You may have requested too many hardware breakpoints/watchpoints.\n");
1389 target_terminal_ours_for_output ();
1390 error_stream (tmp_error_stream);
1393 do_cleanups (cleanups);
1397 remove_breakpoints (void)
1399 struct bp_location *b;
1402 ALL_BP_LOCATIONS (b)
1406 val = remove_breakpoint (b, mark_uninserted);
1415 remove_hw_watchpoints (void)
1417 struct bp_location *b;
1420 ALL_BP_LOCATIONS (b)
1422 if (b->inserted && b->loc_type == bp_loc_hardware_watchpoint)
1424 val = remove_breakpoint (b, mark_uninserted);
1433 reattach_breakpoints (int pid)
1435 struct bp_location *b;
1437 struct cleanup *old_chain = save_inferior_ptid ();
1438 struct ui_file *tmp_error_stream = mem_fileopen ();
1439 int dummy1 = 0, dummy2 = 0;
1441 make_cleanup_ui_file_delete (tmp_error_stream);
1443 inferior_ptid = pid_to_ptid (pid);
1444 ALL_BP_LOCATIONS (b)
1449 val = insert_bp_location (b, tmp_error_stream,
1453 do_cleanups (old_chain);
1458 do_cleanups (old_chain);
1463 update_breakpoints_after_exec (void)
1465 struct breakpoint *b;
1466 struct breakpoint *temp;
1467 struct bp_location *bploc;
1469 /* We're about to delete breakpoints from GDB's lists. If the
1470 INSERTED flag is true, GDB will try to lift the breakpoints by
1471 writing the breakpoints' "shadow contents" back into memory. The
1472 "shadow contents" are NOT valid after an exec, so GDB should not
1473 do that. Instead, the target is responsible from marking
1474 breakpoints out as soon as it detects an exec. We don't do that
1475 here instead, because there may be other attempts to delete
1476 breakpoints after detecting an exec and before reaching here. */
1477 ALL_BP_LOCATIONS (bploc)
1478 gdb_assert (!bploc->inserted);
1480 ALL_BREAKPOINTS_SAFE (b, temp)
1482 /* Solib breakpoints must be explicitly reset after an exec(). */
1483 if (b->type == bp_shlib_event)
1485 delete_breakpoint (b);
1489 /* Thread event breakpoints must be set anew after an exec(),
1490 as must overlay event breakpoints. */
1491 if (b->type == bp_thread_event || b->type == bp_overlay_event)
1493 delete_breakpoint (b);
1497 /* Step-resume breakpoints are meaningless after an exec(). */
1498 if (b->type == bp_step_resume)
1500 delete_breakpoint (b);
1504 /* Longjmp and longjmp-resume breakpoints are also meaningless
1506 if (b->type == bp_longjmp || b->type == bp_longjmp_resume)
1508 delete_breakpoint (b);
1512 if (b->type == bp_catchpoint)
1514 /* For now, none of the bp_catchpoint breakpoints need to
1515 do anything at this point. In the future, if some of
1516 the catchpoints need to something, we will need to add
1517 a new method, and call this method from here. */
1521 /* bp_finish is a special case. The only way we ought to be able
1522 to see one of these when an exec() has happened, is if the user
1523 caught a vfork, and then said "finish". Ordinarily a finish just
1524 carries them to the call-site of the current callee, by setting
1525 a temporary bp there and resuming. But in this case, the finish
1526 will carry them entirely through the vfork & exec.
1528 We don't want to allow a bp_finish to remain inserted now. But
1529 we can't safely delete it, 'cause finish_command has a handle to
1530 the bp on a bpstat, and will later want to delete it. There's a
1531 chance (and I've seen it happen) that if we delete the bp_finish
1532 here, that its storage will get reused by the time finish_command
1533 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1534 We really must allow finish_command to delete a bp_finish.
1536 In the absense of a general solution for the "how do we know
1537 it's safe to delete something others may have handles to?"
1538 problem, what we'll do here is just uninsert the bp_finish, and
1539 let finish_command delete it.
1541 (We know the bp_finish is "doomed" in the sense that it's
1542 momentary, and will be deleted as soon as finish_command sees
1543 the inferior stopped. So it doesn't matter that the bp's
1544 address is probably bogus in the new a.out, unlike e.g., the
1545 solib breakpoints.) */
1547 if (b->type == bp_finish)
1552 /* Without a symbolic address, we have little hope of the
1553 pre-exec() address meaning the same thing in the post-exec()
1555 if (b->addr_string == NULL)
1557 delete_breakpoint (b);
1561 /* FIXME what about longjmp breakpoints? Re-create them here? */
1562 create_overlay_event_breakpoint ("_ovly_debug_event");
1566 detach_breakpoints (int pid)
1568 struct bp_location *b;
1570 struct cleanup *old_chain = save_inferior_ptid ();
1572 if (pid == PIDGET (inferior_ptid))
1573 error (_("Cannot detach breakpoints of inferior_ptid"));
1575 /* Set inferior_ptid; remove_breakpoint uses this global. */
1576 inferior_ptid = pid_to_ptid (pid);
1577 ALL_BP_LOCATIONS (b)
1581 val = remove_breakpoint (b, mark_inserted);
1584 do_cleanups (old_chain);
1589 do_cleanups (old_chain);
1594 remove_breakpoint (struct bp_location *b, insertion_state_t is)
1598 if (b->owner->enable_state == bp_permanent)
1599 /* Permanent breakpoints cannot be inserted or removed. */
1602 /* The type of none suggests that owner is actually deleted.
1603 This should not ever happen. */
1604 gdb_assert (b->owner->type != bp_none);
1606 if (b->loc_type == bp_loc_software_breakpoint
1607 || b->loc_type == bp_loc_hardware_breakpoint)
1609 /* "Normal" instruction breakpoint: either the standard
1610 trap-instruction bp (bp_breakpoint), or a
1611 bp_hardware_breakpoint. */
1613 /* First check to see if we have to handle an overlay. */
1614 if (overlay_debugging == ovly_off
1615 || b->section == NULL
1616 || !(section_is_overlay (b->section)))
1618 /* No overlay handling: just remove the breakpoint. */
1620 if (b->loc_type == bp_loc_hardware_breakpoint)
1621 val = target_remove_hw_breakpoint (&b->target_info);
1623 val = target_remove_breakpoint (&b->target_info);
1627 /* This breakpoint is in an overlay section.
1628 Did we set a breakpoint at the LMA? */
1629 if (!overlay_events_enabled)
1631 /* Yes -- overlay event support is not active, so we
1632 should have set a breakpoint at the LMA. Remove it.
1634 /* Ignore any failures: if the LMA is in ROM, we will
1635 have already warned when we failed to insert it. */
1636 if (b->loc_type == bp_loc_hardware_breakpoint)
1637 target_remove_hw_breakpoint (&b->overlay_target_info);
1639 target_remove_breakpoint (&b->overlay_target_info);
1641 /* Did we set a breakpoint at the VMA?
1642 If so, we will have marked the breakpoint 'inserted'. */
1645 /* Yes -- remove it. Previously we did not bother to
1646 remove the breakpoint if the section had been
1647 unmapped, but let's not rely on that being safe. We
1648 don't know what the overlay manager might do. */
1649 if (b->loc_type == bp_loc_hardware_breakpoint)
1650 val = target_remove_hw_breakpoint (&b->target_info);
1652 /* However, we should remove *software* breakpoints only
1653 if the section is still mapped, or else we overwrite
1654 wrong code with the saved shadow contents. */
1655 else if (section_is_mapped (b->section))
1656 val = target_remove_breakpoint (&b->target_info);
1662 /* No -- not inserted, so no need to remove. No error. */
1667 /* In some cases, we might not be able to remove a breakpoint
1668 in a shared library that has already been removed, but we
1669 have not yet processed the shlib unload event. */
1670 if (val && solib_name_from_address (b->address))
1675 b->inserted = (is == mark_inserted);
1677 else if (b->loc_type == bp_loc_hardware_watchpoint)
1682 b->inserted = (is == mark_inserted);
1683 val = target_remove_watchpoint (b->address, b->length,
1684 b->watchpoint_type);
1686 /* Failure to remove any of the hardware watchpoints comes here. */
1687 if ((is == mark_uninserted) && (b->inserted))
1688 warning (_("Could not remove hardware watchpoint %d."),
1691 else if (b->owner->type == bp_catchpoint
1692 && breakpoint_enabled (b->owner)
1695 gdb_assert (b->owner->ops != NULL && b->owner->ops->remove != NULL);
1697 val = b->owner->ops->remove (b->owner);
1700 b->inserted = (is == mark_inserted);
1706 /* Clear the "inserted" flag in all breakpoints. */
1709 mark_breakpoints_out (void)
1711 struct bp_location *bpt;
1713 ALL_BP_LOCATIONS (bpt)
1717 /* Clear the "inserted" flag in all breakpoints and delete any
1718 breakpoints which should go away between runs of the program.
1720 Plus other such housekeeping that has to be done for breakpoints
1723 Note: this function gets called at the end of a run (by
1724 generic_mourn_inferior) and when a run begins (by
1725 init_wait_for_inferior). */
1730 breakpoint_init_inferior (enum inf_context context)
1732 struct breakpoint *b, *temp;
1733 struct bp_location *bpt;
1736 /* If breakpoint locations are shared across processes, then there's
1738 if (gdbarch_has_global_solist (target_gdbarch))
1741 ALL_BP_LOCATIONS (bpt)
1742 if (bpt->owner->enable_state != bp_permanent)
1745 ALL_BREAKPOINTS_SAFE (b, temp)
1750 case bp_watchpoint_scope:
1752 /* If the call dummy breakpoint is at the entry point it will
1753 cause problems when the inferior is rerun, so we better
1756 Also get rid of scope breakpoints. */
1757 delete_breakpoint (b);
1761 case bp_hardware_watchpoint:
1762 case bp_read_watchpoint:
1763 case bp_access_watchpoint:
1765 /* Likewise for watchpoints on local expressions. */
1766 if (b->exp_valid_block != NULL)
1767 delete_breakpoint (b);
1768 else if (context == inf_starting)
1770 /* Reset val field to force reread of starting value
1771 in insert_breakpoints. */
1773 value_free (b->val);
1783 /* Get rid of the moribund locations. */
1784 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bpt); ++ix)
1785 free_bp_location (bpt);
1786 VEC_free (bp_location_p, moribund_locations);
1789 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1790 exists at PC. It returns ordinary_breakpoint_here if it's an
1791 ordinary breakpoint, or permanent_breakpoint_here if it's a
1792 permanent breakpoint.
1793 - When continuing from a location with an ordinary breakpoint, we
1794 actually single step once before calling insert_breakpoints.
1795 - When continuing from a localion with a permanent breakpoint, we
1796 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1797 the target, to advance the PC past the breakpoint. */
1799 enum breakpoint_here
1800 breakpoint_here_p (CORE_ADDR pc)
1802 const struct bp_location *bpt;
1803 int any_breakpoint_here = 0;
1805 ALL_BP_LOCATIONS (bpt)
1807 if (bpt->loc_type != bp_loc_software_breakpoint
1808 && bpt->loc_type != bp_loc_hardware_breakpoint)
1811 if ((breakpoint_enabled (bpt->owner)
1812 || bpt->owner->enable_state == bp_permanent)
1813 && bpt->address == pc) /* bp is enabled and matches pc */
1815 if (overlay_debugging
1816 && section_is_overlay (bpt->section)
1817 && !section_is_mapped (bpt->section))
1818 continue; /* unmapped overlay -- can't be a match */
1819 else if (bpt->owner->enable_state == bp_permanent)
1820 return permanent_breakpoint_here;
1822 any_breakpoint_here = 1;
1826 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
1829 /* Return true if there's a moribund breakpoint at PC. */
1832 moribund_breakpoint_here_p (CORE_ADDR pc)
1834 struct bp_location *loc;
1837 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
1838 if (loc->address == pc)
1844 /* Returns non-zero if there's a breakpoint inserted at PC, which is
1845 inserted using regular breakpoint_chain/bp_location_chain mechanism.
1846 This does not check for single-step breakpoints, which are
1847 inserted and removed using direct target manipulation. */
1850 regular_breakpoint_inserted_here_p (CORE_ADDR pc)
1852 const struct bp_location *bpt;
1854 ALL_BP_LOCATIONS (bpt)
1856 if (bpt->loc_type != bp_loc_software_breakpoint
1857 && bpt->loc_type != bp_loc_hardware_breakpoint)
1861 && bpt->address == pc) /* bp is inserted and matches pc */
1863 if (overlay_debugging
1864 && section_is_overlay (bpt->section)
1865 && !section_is_mapped (bpt->section))
1866 continue; /* unmapped overlay -- can't be a match */
1874 /* Returns non-zero iff there's either regular breakpoint
1875 or a single step breakpoint inserted at PC. */
1878 breakpoint_inserted_here_p (CORE_ADDR pc)
1880 if (regular_breakpoint_inserted_here_p (pc))
1883 if (single_step_breakpoint_inserted_here_p (pc))
1889 /* This function returns non-zero iff there is a software breakpoint
1893 software_breakpoint_inserted_here_p (CORE_ADDR pc)
1895 const struct bp_location *bpt;
1896 int any_breakpoint_here = 0;
1898 ALL_BP_LOCATIONS (bpt)
1900 if (bpt->loc_type != bp_loc_software_breakpoint)
1904 && bpt->address == pc) /* bp is enabled and matches pc */
1906 if (overlay_debugging
1907 && section_is_overlay (bpt->section)
1908 && !section_is_mapped (bpt->section))
1909 continue; /* unmapped overlay -- can't be a match */
1915 /* Also check for software single-step breakpoints. */
1916 if (single_step_breakpoint_inserted_here_p (pc))
1922 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
1923 PC is valid for process/thread PTID. */
1926 breakpoint_thread_match (CORE_ADDR pc, ptid_t ptid)
1928 const struct bp_location *bpt;
1929 /* The thread and task IDs associated to PTID, computed lazily. */
1933 ALL_BP_LOCATIONS (bpt)
1935 if (bpt->loc_type != bp_loc_software_breakpoint
1936 && bpt->loc_type != bp_loc_hardware_breakpoint)
1939 if (!breakpoint_enabled (bpt->owner)
1940 && bpt->owner->enable_state != bp_permanent)
1943 if (bpt->address != pc)
1946 if (bpt->owner->thread != -1)
1948 /* This is a thread-specific breakpoint. Check that ptid
1949 matches that thread. If thread hasn't been computed yet,
1950 it is now time to do so. */
1952 thread = pid_to_thread_id (ptid);
1953 if (bpt->owner->thread != thread)
1957 if (bpt->owner->task != 0)
1959 /* This is a task-specific breakpoint. Check that ptid
1960 matches that task. If task hasn't been computed yet,
1961 it is now time to do so. */
1963 task = ada_get_task_number (ptid);
1964 if (bpt->owner->task != task)
1968 if (overlay_debugging
1969 && section_is_overlay (bpt->section)
1970 && !section_is_mapped (bpt->section))
1971 continue; /* unmapped overlay -- can't be a match */
1980 /* bpstat stuff. External routines' interfaces are documented
1984 ep_is_catchpoint (struct breakpoint *ep)
1986 return (ep->type == bp_catchpoint);
1990 bpstat_free (bpstat bs)
1992 if (bs->old_val != NULL)
1993 value_free (bs->old_val);
1994 free_command_lines (&bs->commands);
1998 /* Clear a bpstat so that it says we are not at any breakpoint.
1999 Also free any storage that is part of a bpstat. */
2002 bpstat_clear (bpstat *bsp)
2019 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
2020 is part of the bpstat is copied as well. */
2023 bpstat_copy (bpstat bs)
2027 bpstat retval = NULL;
2032 for (; bs != NULL; bs = bs->next)
2034 tmp = (bpstat) xmalloc (sizeof (*tmp));
2035 memcpy (tmp, bs, sizeof (*tmp));
2036 if (bs->commands != NULL)
2037 tmp->commands = copy_command_lines (bs->commands);
2038 if (bs->old_val != NULL)
2040 tmp->old_val = value_copy (bs->old_val);
2041 release_value (tmp->old_val);
2045 /* This is the first thing in the chain. */
2055 /* Find the bpstat associated with this breakpoint */
2058 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
2063 for (; bsp != NULL; bsp = bsp->next)
2065 if (bsp->breakpoint_at && bsp->breakpoint_at->owner == breakpoint)
2071 /* Find a step_resume breakpoint associated with this bpstat.
2072 (If there are multiple step_resume bp's on the list, this function
2073 will arbitrarily pick one.)
2075 It is an error to use this function if BPSTAT doesn't contain a
2076 step_resume breakpoint.
2078 See wait_for_inferior's use of this function. */
2080 bpstat_find_step_resume_breakpoint (bpstat bsp)
2084 gdb_assert (bsp != NULL);
2086 current_thread = pid_to_thread_id (inferior_ptid);
2088 for (; bsp != NULL; bsp = bsp->next)
2090 if ((bsp->breakpoint_at != NULL) &&
2091 (bsp->breakpoint_at->owner->type == bp_step_resume) &&
2092 (bsp->breakpoint_at->owner->thread == current_thread ||
2093 bsp->breakpoint_at->owner->thread == -1))
2094 return bsp->breakpoint_at->owner;
2097 internal_error (__FILE__, __LINE__, _("No step_resume breakpoint found."));
2101 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2102 at. *BSP upon return is a bpstat which points to the remaining
2103 breakpoints stopped at (but which is not guaranteed to be good for
2104 anything but further calls to bpstat_num).
2105 Return 0 if passed a bpstat which does not indicate any breakpoints.
2106 Return -1 if stopped at a breakpoint that has been deleted since
2108 Return 1 otherwise. */
2111 bpstat_num (bpstat *bsp, int *num)
2113 struct breakpoint *b;
2116 return 0; /* No more breakpoint values */
2118 /* We assume we'll never have several bpstats that
2119 correspond to a single breakpoint -- otherwise,
2120 this function might return the same number more
2121 than once and this will look ugly. */
2122 b = (*bsp)->breakpoint_at ? (*bsp)->breakpoint_at->owner : NULL;
2123 *bsp = (*bsp)->next;
2125 return -1; /* breakpoint that's been deleted since */
2127 *num = b->number; /* We have its number */
2131 /* Modify BS so that the actions will not be performed. */
2134 bpstat_clear_actions (bpstat bs)
2136 for (; bs != NULL; bs = bs->next)
2138 free_command_lines (&bs->commands);
2139 if (bs->old_val != NULL)
2141 value_free (bs->old_val);
2147 /* Called when a command is about to proceed the inferior. */
2150 breakpoint_about_to_proceed (void)
2152 if (!ptid_equal (inferior_ptid, null_ptid))
2154 struct thread_info *tp = inferior_thread ();
2156 /* Allow inferior function calls in breakpoint commands to not
2157 interrupt the command list. When the call finishes
2158 successfully, the inferior will be standing at the same
2159 breakpoint as if nothing happened. */
2164 breakpoint_proceeded = 1;
2167 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2169 cleanup_executing_breakpoints (void *ignore)
2171 executing_breakpoint_commands = 0;
2174 /* Execute all the commands associated with all the breakpoints at this
2175 location. Any of these commands could cause the process to proceed
2176 beyond this point, etc. We look out for such changes by checking
2177 the global "breakpoint_proceeded" after each command.
2179 Returns true if a breakpoint command resumed the inferior. In that
2180 case, it is the caller's responsibility to recall it again with the
2181 bpstat of the current thread. */
2184 bpstat_do_actions_1 (bpstat *bsp)
2187 struct cleanup *old_chain;
2190 /* Avoid endless recursion if a `source' command is contained
2192 if (executing_breakpoint_commands)
2195 executing_breakpoint_commands = 1;
2196 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
2198 /* This pointer will iterate over the list of bpstat's. */
2201 breakpoint_proceeded = 0;
2202 for (; bs != NULL; bs = bs->next)
2204 struct command_line *cmd;
2205 struct cleanup *this_cmd_tree_chain;
2207 /* Take ownership of the BSP's command tree, if it has one.
2209 The command tree could legitimately contain commands like
2210 'step' and 'next', which call clear_proceed_status, which
2211 frees stop_bpstat's command tree. To make sure this doesn't
2212 free the tree we're executing out from under us, we need to
2213 take ownership of the tree ourselves. Since a given bpstat's
2214 commands are only executed once, we don't need to copy it; we
2215 can clear the pointer in the bpstat, and make sure we free
2216 the tree when we're done. */
2219 this_cmd_tree_chain = make_cleanup_free_command_lines (&cmd);
2223 execute_control_command (cmd);
2225 if (breakpoint_proceeded)
2231 /* We can free this command tree now. */
2232 do_cleanups (this_cmd_tree_chain);
2234 if (breakpoint_proceeded)
2236 if (target_can_async_p ())
2237 /* If we are in async mode, then the target might be still
2238 running, not stopped at any breakpoint, so nothing for
2239 us to do here -- just return to the event loop. */
2242 /* In sync mode, when execute_control_command returns
2243 we're already standing on the next breakpoint.
2244 Breakpoint commands for that stop were not run, since
2245 execute_command does not run breakpoint commands --
2246 only command_line_handler does, but that one is not
2247 involved in execution of breakpoint commands. So, we
2248 can now execute breakpoint commands. It should be
2249 noted that making execute_command do bpstat actions is
2250 not an option -- in this case we'll have recursive
2251 invocation of bpstat for each breakpoint with a
2252 command, and can easily blow up GDB stack. Instead, we
2253 return true, which will trigger the caller to recall us
2254 with the new stop_bpstat. */
2259 do_cleanups (old_chain);
2264 bpstat_do_actions (void)
2266 /* Do any commands attached to breakpoint we are stopped at. */
2267 while (!ptid_equal (inferior_ptid, null_ptid)
2268 && target_has_execution
2269 && !is_exited (inferior_ptid)
2270 && !is_executing (inferior_ptid))
2271 /* Since in sync mode, bpstat_do_actions may resume the inferior,
2272 and only return when it is stopped at the next breakpoint, we
2273 keep doing breakpoint actions until it returns false to
2274 indicate the inferior was not resumed. */
2275 if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat))
2279 /* Print out the (old or new) value associated with a watchpoint. */
2282 watchpoint_value_print (struct value *val, struct ui_file *stream)
2285 fprintf_unfiltered (stream, _("<unreadable>"));
2288 struct value_print_options opts;
2289 get_user_print_options (&opts);
2290 value_print (val, stream, &opts);
2294 /* This is the normal print function for a bpstat. In the future,
2295 much of this logic could (should?) be moved to bpstat_stop_status,
2296 by having it set different print_it values.
2298 Current scheme: When we stop, bpstat_print() is called. It loops
2299 through the bpstat list of things causing this stop, calling the
2300 print_bp_stop_message function on each one. The behavior of the
2301 print_bp_stop_message function depends on the print_it field of
2302 bpstat. If such field so indicates, call this function here.
2304 Return values from this routine (ultimately used by bpstat_print()
2305 and normal_stop() to decide what to do):
2306 PRINT_NOTHING: Means we already printed all we needed to print,
2307 don't print anything else.
2308 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2309 that something to be followed by a location.
2310 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2311 that something to be followed by a location.
2312 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2315 static enum print_stop_action
2316 print_it_typical (bpstat bs)
2318 struct cleanup *old_chain;
2319 struct breakpoint *b;
2320 const struct bp_location *bl;
2321 struct ui_stream *stb;
2323 enum print_stop_action result;
2325 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2326 which has since been deleted. */
2327 if (bs->breakpoint_at == NULL)
2328 return PRINT_UNKNOWN;
2329 bl = bs->breakpoint_at;
2332 stb = ui_out_stream_new (uiout);
2333 old_chain = make_cleanup_ui_out_stream_delete (stb);
2338 case bp_hardware_breakpoint:
2339 bp_temp = bs->breakpoint_at->owner->disposition == disp_del;
2340 if (bl->address != bl->requested_address)
2341 breakpoint_adjustment_warning (bl->requested_address,
2344 annotate_breakpoint (b->number);
2346 ui_out_text (uiout, "\nTemporary breakpoint ");
2348 ui_out_text (uiout, "\nBreakpoint ");
2349 if (ui_out_is_mi_like_p (uiout))
2351 ui_out_field_string (uiout, "reason",
2352 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
2353 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
2355 ui_out_field_int (uiout, "bkptno", b->number);
2356 ui_out_text (uiout, ", ");
2357 result = PRINT_SRC_AND_LOC;
2360 case bp_shlib_event:
2361 /* Did we stop because the user set the stop_on_solib_events
2362 variable? (If so, we report this as a generic, "Stopped due
2363 to shlib event" message.) */
2364 printf_filtered (_("Stopped due to shared library event\n"));
2365 result = PRINT_NOTHING;
2368 case bp_thread_event:
2369 /* Not sure how we will get here.
2370 GDB should not stop for these breakpoints. */
2371 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2372 result = PRINT_NOTHING;
2375 case bp_overlay_event:
2376 /* By analogy with the thread event, GDB should not stop for these. */
2377 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2378 result = PRINT_NOTHING;
2382 case bp_hardware_watchpoint:
2383 annotate_watchpoint (b->number);
2384 if (ui_out_is_mi_like_p (uiout))
2387 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
2389 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2390 ui_out_text (uiout, "\nOld value = ");
2391 watchpoint_value_print (bs->old_val, stb->stream);
2392 ui_out_field_stream (uiout, "old", stb);
2393 ui_out_text (uiout, "\nNew value = ");
2394 watchpoint_value_print (b->val, stb->stream);
2395 ui_out_field_stream (uiout, "new", stb);
2396 ui_out_text (uiout, "\n");
2397 /* More than one watchpoint may have been triggered. */
2398 result = PRINT_UNKNOWN;
2401 case bp_read_watchpoint:
2402 if (ui_out_is_mi_like_p (uiout))
2405 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
2407 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2408 ui_out_text (uiout, "\nValue = ");
2409 watchpoint_value_print (b->val, stb->stream);
2410 ui_out_field_stream (uiout, "value", stb);
2411 ui_out_text (uiout, "\n");
2412 result = PRINT_UNKNOWN;
2415 case bp_access_watchpoint:
2416 if (bs->old_val != NULL)
2418 annotate_watchpoint (b->number);
2419 if (ui_out_is_mi_like_p (uiout))
2422 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
2424 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2425 ui_out_text (uiout, "\nOld value = ");
2426 watchpoint_value_print (bs->old_val, stb->stream);
2427 ui_out_field_stream (uiout, "old", stb);
2428 ui_out_text (uiout, "\nNew value = ");
2433 if (ui_out_is_mi_like_p (uiout))
2436 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
2437 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2438 ui_out_text (uiout, "\nValue = ");
2440 watchpoint_value_print (b->val, stb->stream);
2441 ui_out_field_stream (uiout, "new", stb);
2442 ui_out_text (uiout, "\n");
2443 result = PRINT_UNKNOWN;
2446 /* Fall through, we don't deal with these types of breakpoints
2450 if (ui_out_is_mi_like_p (uiout))
2453 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED));
2454 result = PRINT_UNKNOWN;
2458 if (ui_out_is_mi_like_p (uiout))
2461 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED));
2462 result = PRINT_UNKNOWN;
2467 case bp_longjmp_resume:
2468 case bp_step_resume:
2469 case bp_watchpoint_scope:
2473 result = PRINT_UNKNOWN;
2477 do_cleanups (old_chain);
2481 /* Generic routine for printing messages indicating why we
2482 stopped. The behavior of this function depends on the value
2483 'print_it' in the bpstat structure. Under some circumstances we
2484 may decide not to print anything here and delegate the task to
2487 static enum print_stop_action
2488 print_bp_stop_message (bpstat bs)
2490 switch (bs->print_it)
2493 /* Nothing should be printed for this bpstat entry. */
2494 return PRINT_UNKNOWN;
2498 /* We still want to print the frame, but we already printed the
2499 relevant messages. */
2500 return PRINT_SRC_AND_LOC;
2503 case print_it_normal:
2505 const struct bp_location *bl = bs->breakpoint_at;
2506 struct breakpoint *b = bl ? bl->owner : NULL;
2508 /* Normal case. Call the breakpoint's print_it method, or
2509 print_it_typical. */
2510 /* FIXME: how breakpoint can ever be NULL here? */
2511 if (b != NULL && b->ops != NULL && b->ops->print_it != NULL)
2512 return b->ops->print_it (b);
2514 return print_it_typical (bs);
2519 internal_error (__FILE__, __LINE__,
2520 _("print_bp_stop_message: unrecognized enum value"));
2525 /* Print a message indicating what happened. This is called from
2526 normal_stop(). The input to this routine is the head of the bpstat
2527 list - a list of the eventpoints that caused this stop. This
2528 routine calls the generic print routine for printing a message
2529 about reasons for stopping. This will print (for example) the
2530 "Breakpoint n," part of the output. The return value of this
2533 PRINT_UNKNOWN: Means we printed nothing
2534 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2535 code to print the location. An example is
2536 "Breakpoint 1, " which should be followed by
2538 PRINT_SRC_ONLY: Means we printed something, but there is no need
2539 to also print the location part of the message.
2540 An example is the catch/throw messages, which
2541 don't require a location appended to the end.
2542 PRINT_NOTHING: We have done some printing and we don't need any
2543 further info to be printed.*/
2545 enum print_stop_action
2546 bpstat_print (bpstat bs)
2550 /* Maybe another breakpoint in the chain caused us to stop.
2551 (Currently all watchpoints go on the bpstat whether hit or not.
2552 That probably could (should) be changed, provided care is taken
2553 with respect to bpstat_explains_signal). */
2554 for (; bs; bs = bs->next)
2556 val = print_bp_stop_message (bs);
2557 if (val == PRINT_SRC_ONLY
2558 || val == PRINT_SRC_AND_LOC
2559 || val == PRINT_NOTHING)
2563 /* We reached the end of the chain, or we got a null BS to start
2564 with and nothing was printed. */
2565 return PRINT_UNKNOWN;
2568 /* Evaluate the expression EXP and return 1 if value is zero.
2569 This is used inside a catch_errors to evaluate the breakpoint condition.
2570 The argument is a "struct expression *" that has been cast to char * to
2571 make it pass through catch_errors. */
2574 breakpoint_cond_eval (void *exp)
2576 struct value *mark = value_mark ();
2577 int i = !value_true (evaluate_expression ((struct expression *) exp));
2578 value_free_to_mark (mark);
2582 /* Allocate a new bpstat and chain it to the current one. */
2585 bpstat_alloc (const struct bp_location *bl, bpstat cbs /* Current "bs" value */ )
2589 bs = (bpstat) xmalloc (sizeof (*bs));
2591 bs->breakpoint_at = bl;
2592 /* If the condition is false, etc., don't do the commands. */
2593 bs->commands = NULL;
2595 bs->print_it = print_it_normal;
2599 /* The target has stopped with waitstatus WS. Check if any hardware
2600 watchpoints have triggered, according to the target. */
2603 watchpoints_triggered (struct target_waitstatus *ws)
2605 int stopped_by_watchpoint = target_stopped_by_watchpoint ();
2607 struct breakpoint *b;
2609 if (!stopped_by_watchpoint)
2611 /* We were not stopped by a watchpoint. Mark all watchpoints
2612 as not triggered. */
2614 if (b->type == bp_hardware_watchpoint
2615 || b->type == bp_read_watchpoint
2616 || b->type == bp_access_watchpoint)
2617 b->watchpoint_triggered = watch_triggered_no;
2622 if (!target_stopped_data_address (¤t_target, &addr))
2624 /* We were stopped by a watchpoint, but we don't know where.
2625 Mark all watchpoints as unknown. */
2627 if (b->type == bp_hardware_watchpoint
2628 || b->type == bp_read_watchpoint
2629 || b->type == bp_access_watchpoint)
2630 b->watchpoint_triggered = watch_triggered_unknown;
2632 return stopped_by_watchpoint;
2635 /* The target could report the data address. Mark watchpoints
2636 affected by this data address as triggered, and all others as not
2640 if (b->type == bp_hardware_watchpoint
2641 || b->type == bp_read_watchpoint
2642 || b->type == bp_access_watchpoint)
2644 struct bp_location *loc;
2647 b->watchpoint_triggered = watch_triggered_no;
2648 for (loc = b->loc; loc; loc = loc->next)
2649 /* Exact match not required. Within range is
2651 if (target_watchpoint_addr_within_range (¤t_target,
2655 b->watchpoint_triggered = watch_triggered_yes;
2663 /* Possible return values for watchpoint_check (this can't be an enum
2664 because of check_errors). */
2665 /* The watchpoint has been deleted. */
2666 #define WP_DELETED 1
2667 /* The value has changed. */
2668 #define WP_VALUE_CHANGED 2
2669 /* The value has not changed. */
2670 #define WP_VALUE_NOT_CHANGED 3
2672 #define BP_TEMPFLAG 1
2673 #define BP_HARDWAREFLAG 2
2675 /* Check watchpoint condition. */
2678 watchpoint_check (void *p)
2680 bpstat bs = (bpstat) p;
2681 struct breakpoint *b;
2682 struct frame_info *fr;
2683 int within_current_scope;
2685 b = bs->breakpoint_at->owner;
2687 if (b->exp_valid_block == NULL)
2688 within_current_scope = 1;
2691 /* There is no current frame at this moment. If we're going to have
2692 any chance of handling watchpoints on local variables, we'll need
2693 the frame chain (so we can determine if we're in scope). */
2694 reinit_frame_cache ();
2695 fr = frame_find_by_id (b->watchpoint_frame);
2696 within_current_scope = (fr != NULL);
2698 /* If we've gotten confused in the unwinder, we might have
2699 returned a frame that can't describe this variable. */
2700 if (within_current_scope
2701 && (block_linkage_function (b->exp_valid_block)
2702 != get_frame_function (fr)))
2703 within_current_scope = 0;
2705 /* in_function_epilogue_p() returns a non-zero value if we're still
2706 in the function but the stack frame has already been invalidated.
2707 Since we can't rely on the values of local variables after the
2708 stack has been destroyed, we are treating the watchpoint in that
2709 state as `not changed' without further checking.
2711 vinschen/2003-09-04: The former implementation left out the case
2712 that the watchpoint frame couldn't be found by frame_find_by_id()
2713 because the current PC is currently in an epilogue. Calling
2714 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2715 if (!within_current_scope || fr == get_current_frame ())
2717 struct frame_info *frame = get_current_frame ();
2718 struct gdbarch *frame_arch = get_frame_arch (frame);
2719 CORE_ADDR frame_pc = get_frame_pc (frame);
2721 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
2722 return WP_VALUE_NOT_CHANGED;
2724 if (fr && within_current_scope)
2725 /* If we end up stopping, the current frame will get selected
2726 in normal_stop. So this call to select_frame won't affect
2731 if (within_current_scope)
2733 /* We use value_{,free_to_}mark because it could be a
2734 *long* time before we return to the command level and
2735 call free_all_values. We can't call free_all_values because
2736 we might be in the middle of evaluating a function call. */
2738 struct value *mark = value_mark ();
2739 struct value *new_val;
2741 fetch_watchpoint_value (b->exp, &new_val, NULL, NULL);
2742 if ((b->val != NULL) != (new_val != NULL)
2743 || (b->val != NULL && !value_equal (b->val, new_val)))
2745 if (new_val != NULL)
2747 release_value (new_val);
2748 value_free_to_mark (mark);
2750 bs->old_val = b->val;
2753 /* We will stop here */
2754 return WP_VALUE_CHANGED;
2758 /* Nothing changed, don't do anything. */
2759 value_free_to_mark (mark);
2760 /* We won't stop here */
2761 return WP_VALUE_NOT_CHANGED;
2766 /* This seems like the only logical thing to do because
2767 if we temporarily ignored the watchpoint, then when
2768 we reenter the block in which it is valid it contains
2769 garbage (in the case of a function, it may have two
2770 garbage values, one before and one after the prologue).
2771 So we can't even detect the first assignment to it and
2772 watch after that (since the garbage may or may not equal
2773 the first value assigned). */
2774 /* We print all the stop information in print_it_typical(), but
2775 in this case, by the time we call print_it_typical() this bp
2776 will be deleted already. So we have no choice but print the
2777 information here. */
2778 if (ui_out_is_mi_like_p (uiout))
2780 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
2781 ui_out_text (uiout, "\nWatchpoint ");
2782 ui_out_field_int (uiout, "wpnum", b->number);
2783 ui_out_text (uiout, " deleted because the program has left the block in\n\
2784 which its expression is valid.\n");
2786 if (b->related_breakpoint)
2787 b->related_breakpoint->disposition = disp_del_at_next_stop;
2788 b->disposition = disp_del_at_next_stop;
2794 /* Return true if it looks like target has stopped due to hitting
2795 breakpoint location BL. This function does not check if we
2796 should stop, only if BL explains the stop. */
2798 bpstat_check_location (const struct bp_location *bl, CORE_ADDR bp_addr)
2800 struct breakpoint *b = bl->owner;
2802 if (b->type != bp_watchpoint
2803 && b->type != bp_hardware_watchpoint
2804 && b->type != bp_read_watchpoint
2805 && b->type != bp_access_watchpoint
2806 && b->type != bp_hardware_breakpoint
2807 && b->type != bp_catchpoint) /* a non-watchpoint bp */
2809 if (bl->address != bp_addr) /* address doesn't match */
2811 if (overlay_debugging /* unmapped overlay section */
2812 && section_is_overlay (bl->section)
2813 && !section_is_mapped (bl->section))
2817 /* Continuable hardware watchpoints are treated as non-existent if the
2818 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2819 some data address). Otherwise gdb won't stop on a break instruction
2820 in the code (not from a breakpoint) when a hardware watchpoint has
2821 been defined. Also skip watchpoints which we know did not trigger
2822 (did not match the data address). */
2824 if ((b->type == bp_hardware_watchpoint
2825 || b->type == bp_read_watchpoint
2826 || b->type == bp_access_watchpoint)
2827 && b->watchpoint_triggered == watch_triggered_no)
2830 if (b->type == bp_hardware_breakpoint)
2832 if (bl->address != bp_addr)
2834 if (overlay_debugging /* unmapped overlay section */
2835 && section_is_overlay (bl->section)
2836 && !section_is_mapped (bl->section))
2840 if (b->type == bp_catchpoint)
2842 gdb_assert (b->ops != NULL && b->ops->breakpoint_hit != NULL);
2843 if (!b->ops->breakpoint_hit (b))
2850 /* If BS refers to a watchpoint, determine if the watched values
2851 has actually changed, and we should stop. If not, set BS->stop
2854 bpstat_check_watchpoint (bpstat bs)
2856 const struct bp_location *bl = bs->breakpoint_at;
2857 struct breakpoint *b = bl->owner;
2859 if (b->type == bp_watchpoint
2860 || b->type == bp_read_watchpoint
2861 || b->type == bp_access_watchpoint
2862 || b->type == bp_hardware_watchpoint)
2866 int must_check_value = 0;
2868 if (b->type == bp_watchpoint)
2869 /* For a software watchpoint, we must always check the
2871 must_check_value = 1;
2872 else if (b->watchpoint_triggered == watch_triggered_yes)
2873 /* We have a hardware watchpoint (read, write, or access)
2874 and the target earlier reported an address watched by
2876 must_check_value = 1;
2877 else if (b->watchpoint_triggered == watch_triggered_unknown
2878 && b->type == bp_hardware_watchpoint)
2879 /* We were stopped by a hardware watchpoint, but the target could
2880 not report the data address. We must check the watchpoint's
2881 value. Access and read watchpoints are out of luck; without
2882 a data address, we can't figure it out. */
2883 must_check_value = 1;
2885 if (must_check_value)
2887 char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n",
2889 struct cleanup *cleanups = make_cleanup (xfree, message);
2890 int e = catch_errors (watchpoint_check, bs, message,
2892 do_cleanups (cleanups);
2896 /* We've already printed what needs to be printed. */
2897 bs->print_it = print_it_done;
2900 case WP_VALUE_CHANGED:
2901 if (b->type == bp_read_watchpoint)
2903 /* Don't stop: read watchpoints shouldn't fire if
2904 the value has changed. This is for targets
2905 which cannot set read-only watchpoints. */
2906 bs->print_it = print_it_noop;
2910 case WP_VALUE_NOT_CHANGED:
2911 if (b->type == bp_hardware_watchpoint
2912 || b->type == bp_watchpoint)
2914 /* Don't stop: write watchpoints shouldn't fire if
2915 the value hasn't changed. */
2916 bs->print_it = print_it_noop;
2924 /* Error from catch_errors. */
2925 printf_filtered (_("Watchpoint %d deleted.\n"), b->number);
2926 if (b->related_breakpoint)
2927 b->related_breakpoint->disposition = disp_del_at_next_stop;
2928 b->disposition = disp_del_at_next_stop;
2929 /* We've already printed what needs to be printed. */
2930 bs->print_it = print_it_done;
2934 else /* must_check_value == 0 */
2936 /* This is a case where some watchpoint(s) triggered, but
2937 not at the address of this watchpoint, or else no
2938 watchpoint triggered after all. So don't print
2939 anything for this watchpoint. */
2940 bs->print_it = print_it_noop;
2947 /* Check conditions (condition proper, frame, thread and ignore count)
2948 of breakpoint referred to by BS. If we should not stop for this
2949 breakpoint, set BS->stop to 0. */
2951 bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
2953 int thread_id = pid_to_thread_id (ptid);
2954 const struct bp_location *bl = bs->breakpoint_at;
2955 struct breakpoint *b = bl->owner;
2957 if (frame_id_p (b->frame_id)
2958 && !frame_id_eq (b->frame_id, get_frame_id (get_current_frame ())))
2962 int value_is_zero = 0;
2964 /* If this is a scope breakpoint, mark the associated
2965 watchpoint as triggered so that we will handle the
2966 out-of-scope event. We'll get to the watchpoint next
2968 if (b->type == bp_watchpoint_scope)
2969 b->related_breakpoint->watchpoint_triggered = watch_triggered_yes;
2971 if (bl->cond && bl->owner->disposition != disp_del_at_next_stop)
2973 /* We use value_mark and value_free_to_mark because it could
2974 be a long time before we return to the command level and
2975 call free_all_values. We can't call free_all_values
2976 because we might be in the middle of evaluating a
2978 struct value *mark = value_mark ();
2980 /* Need to select the frame, with all that implies
2981 so that the conditions will have the right context. */
2982 select_frame (get_current_frame ());
2984 = catch_errors (breakpoint_cond_eval, (bl->cond),
2985 "Error in testing breakpoint condition:\n",
2987 /* FIXME-someday, should give breakpoint # */
2988 value_free_to_mark (mark);
2990 if (bl->cond && value_is_zero)
2994 else if (b->thread != -1 && b->thread != thread_id)
2998 else if (b->ignore_count > 0)
3001 annotate_ignore_count_change ();
3003 /* Increase the hit count even though we don't
3011 /* Get a bpstat associated with having just stopped at address
3012 BP_ADDR in thread PTID.
3014 Determine whether we stopped at a breakpoint, etc, or whether we
3015 don't understand this stop. Result is a chain of bpstat's such that:
3017 if we don't understand the stop, the result is a null pointer.
3019 if we understand why we stopped, the result is not null.
3021 Each element of the chain refers to a particular breakpoint or
3022 watchpoint at which we have stopped. (We may have stopped for
3023 several reasons concurrently.)
3025 Each element of the chain has valid next, breakpoint_at,
3026 commands, FIXME??? fields. */
3029 bpstat_stop_status (CORE_ADDR bp_addr, ptid_t ptid)
3031 struct breakpoint *b = NULL;
3032 const struct bp_location *bl;
3033 struct bp_location *loc;
3034 /* Root of the chain of bpstat's */
3035 struct bpstats root_bs[1];
3036 /* Pointer to the last thing in the chain currently. */
3037 bpstat bs = root_bs;
3039 int need_remove_insert;
3041 ALL_BP_LOCATIONS (bl)
3045 if (!breakpoint_enabled (b) && b->enable_state != bp_permanent)
3048 /* For hardware watchpoints, we look only at the first location.
3049 The watchpoint_check function will work on entire expression,
3050 not the individual locations. For read watchopints, the
3051 watchpoints_triggered function have checked all locations
3054 if (b->type == bp_hardware_watchpoint && bl != b->loc)
3057 if (!bpstat_check_location (bl, bp_addr))
3060 /* Come here if it's a watchpoint, or if the break address matches */
3062 bs = bpstat_alloc (bl, bs); /* Alloc a bpstat to explain stop */
3064 /* Assume we stop. Should we find watchpoint that is not actually
3065 triggered, or if condition of breakpoint is false, we'll reset
3070 bpstat_check_watchpoint (bs);
3074 if (b->type == bp_thread_event || b->type == bp_overlay_event)
3075 /* We do not stop for these. */
3078 bpstat_check_breakpoint_conditions (bs, ptid);
3084 /* We will stop here */
3085 if (b->disposition == disp_disable)
3087 if (b->enable_state != bp_permanent)
3088 b->enable_state = bp_disabled;
3089 update_global_location_list (0);
3093 bs->commands = b->commands;
3095 (strcmp ("silent", bs->commands->line) == 0
3096 || (xdb_commands && strcmp ("Q", bs->commands->line) == 0)))
3098 bs->commands = bs->commands->next;
3101 bs->commands = copy_command_lines (bs->commands);
3104 /* Print nothing for this entry if we dont stop or if we dont print. */
3105 if (bs->stop == 0 || bs->print == 0)
3106 bs->print_it = print_it_noop;
3109 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
3111 if (loc->address == bp_addr)
3113 bs = bpstat_alloc (loc, bs);
3114 /* For hits of moribund locations, we should just proceed. */
3117 bs->print_it = print_it_noop;
3121 bs->next = NULL; /* Terminate the chain */
3122 bs = root_bs->next; /* Re-grab the head of the chain */
3124 /* If we aren't stopping, the value of some hardware watchpoint may
3125 not have changed, but the intermediate memory locations we are
3126 watching may have. Don't bother if we're stopping; this will get
3128 for (bs = root_bs->next; bs != NULL; bs = bs->next)
3132 need_remove_insert = 0;
3134 for (bs = root_bs->next; bs != NULL; bs = bs->next)
3136 && bs->breakpoint_at->owner
3137 && (bs->breakpoint_at->owner->type == bp_hardware_watchpoint
3138 || bs->breakpoint_at->owner->type == bp_read_watchpoint
3139 || bs->breakpoint_at->owner->type == bp_access_watchpoint))
3141 /* remove/insert can invalidate bs->breakpoint_at, if this
3142 location is no longer used by the watchpoint. Prevent
3143 further code from trying to use it. */
3144 bs->breakpoint_at = NULL;
3145 need_remove_insert = 1;
3148 if (need_remove_insert)
3150 remove_breakpoints ();
3151 insert_breakpoints ();
3154 return root_bs->next;
3157 /* Tell what to do about this bpstat. */
3159 bpstat_what (bpstat bs)
3161 /* Classify each bpstat as one of the following. */
3164 /* This bpstat element has no effect on the main_action. */
3167 /* There was a watchpoint, stop but don't print. */
3170 /* There was a watchpoint, stop and print. */
3173 /* There was a breakpoint but we're not stopping. */
3176 /* There was a breakpoint, stop but don't print. */
3179 /* There was a breakpoint, stop and print. */
3182 /* We hit the longjmp breakpoint. */
3185 /* We hit the longjmp_resume breakpoint. */
3188 /* We hit the step_resume breakpoint. */
3191 /* We hit the shared library event breakpoint. */
3194 /* This is just used to count how many enums there are. */
3198 /* Here is the table which drives this routine. So that we can
3199 format it pretty, we define some abbreviations for the
3200 enum bpstat_what codes. */
3201 #define kc BPSTAT_WHAT_KEEP_CHECKING
3202 #define ss BPSTAT_WHAT_STOP_SILENT
3203 #define sn BPSTAT_WHAT_STOP_NOISY
3204 #define sgl BPSTAT_WHAT_SINGLE
3205 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3206 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3207 #define sr BPSTAT_WHAT_STEP_RESUME
3208 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3210 /* "Can't happen." Might want to print an error message.
3211 abort() is not out of the question, but chances are GDB is just
3212 a bit confused, not unusable. */
3213 #define err BPSTAT_WHAT_STOP_NOISY
3215 /* Given an old action and a class, come up with a new action. */
3216 /* One interesting property of this table is that wp_silent is the same
3217 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3218 after stopping, the check for whether to step over a breakpoint
3219 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3220 reference to how we stopped. We retain separate wp_silent and
3221 bp_silent codes in case we want to change that someday.
3223 Another possibly interesting property of this table is that
3224 there's a partial ordering, priority-like, of the actions. Once
3225 you've decided that some action is appropriate, you'll never go
3226 back and decide something of a lower priority is better. The
3229 kc < clr sgl shl slr sn sr ss
3230 sgl < shl slr sn sr ss
3231 slr < err shl sn sr ss
3232 clr < err shl sn sr ss
3238 What I think this means is that we don't need a damned table
3239 here. If you just put the rows and columns in the right order,
3240 it'd look awfully regular. We could simply walk the bpstat list
3241 and choose the highest priority action we find, with a little
3242 logic to handle the 'err' cases. */
3244 /* step_resume entries: a step resume breakpoint overrides another
3245 breakpoint of signal handling (see comment in wait_for_inferior
3246 at where we set the step_resume breakpoint). */
3248 static const enum bpstat_what_main_action
3249 table[(int) class_last][(int) BPSTAT_WHAT_LAST] =
3252 /* kc ss sn sgl slr clr sr shl
3255 {kc, ss, sn, sgl, slr, clr, sr, shl},
3257 {ss, ss, sn, ss, ss, ss, sr, shl},
3259 {sn, sn, sn, sn, sn, sn, sr, shl},
3261 {sgl, ss, sn, sgl, slr, slr, sr, shl},
3263 {ss, ss, sn, ss, ss, ss, sr, shl},
3265 {sn, sn, sn, sn, sn, sn, sr, shl},
3267 {slr, ss, sn, slr, slr, err, sr, shl},
3269 {clr, ss, sn, err, err, err, sr, shl},
3271 {sr, sr, sr, sr, sr, sr, sr, sr},
3273 {shl, shl, shl, shl, shl, shl, sr, shl}
3286 enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
3287 struct bpstat_what retval;
3289 retval.call_dummy = 0;
3290 for (; bs != NULL; bs = bs->next)
3292 enum class bs_class = no_effect;
3293 if (bs->breakpoint_at == NULL)
3294 /* I suspect this can happen if it was a momentary breakpoint
3295 which has since been deleted. */
3297 if (bs->breakpoint_at->owner == NULL)
3298 bs_class = bp_nostop;
3300 switch (bs->breakpoint_at->owner->type)
3306 case bp_hardware_breakpoint:
3312 bs_class = bp_noisy;
3314 bs_class = bp_silent;
3317 bs_class = bp_nostop;
3320 case bp_hardware_watchpoint:
3321 case bp_read_watchpoint:
3322 case bp_access_watchpoint:
3326 bs_class = wp_noisy;
3328 bs_class = wp_silent;
3331 /* There was a watchpoint, but we're not stopping.
3332 This requires no further action. */
3333 bs_class = no_effect;
3336 bs_class = long_jump;
3338 case bp_longjmp_resume:
3339 bs_class = long_resume;
3341 case bp_step_resume:
3344 bs_class = step_resume;
3347 /* It is for the wrong frame. */
3348 bs_class = bp_nostop;
3350 case bp_watchpoint_scope:
3351 bs_class = bp_nostop;
3353 case bp_shlib_event:
3354 bs_class = shlib_event;
3356 case bp_thread_event:
3357 case bp_overlay_event:
3358 bs_class = bp_nostop;
3364 bs_class = bp_noisy;
3366 bs_class = bp_silent;
3369 /* There was a catchpoint, but we're not stopping.
3370 This requires no further action. */
3371 bs_class = no_effect;
3374 /* Make sure the action is stop (silent or noisy),
3375 so infrun.c pops the dummy frame. */
3376 bs_class = bp_silent;
3377 retval.call_dummy = 1;
3380 /* Tracepoint hits should not be reported back to GDB, and
3381 if one got through somehow, it should have been filtered
3383 internal_error (__FILE__, __LINE__,
3384 _("bpstat_what: bp_tracepoint encountered"));
3387 current_action = table[(int) bs_class][(int) current_action];
3389 retval.main_action = current_action;
3393 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3394 without hardware support). This isn't related to a specific bpstat,
3395 just to things like whether watchpoints are set. */
3398 bpstat_should_step (void)
3400 struct breakpoint *b;
3402 if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL)
3409 static void print_breakpoint_location (struct breakpoint *b,
3410 struct bp_location *loc,
3412 struct ui_stream *stb)
3417 = find_pc_sect_function (loc->address, loc->section);
3420 ui_out_text (uiout, "in ");
3421 ui_out_field_string (uiout, "func",
3422 SYMBOL_PRINT_NAME (sym));
3423 ui_out_wrap_hint (uiout, wrap_indent);
3424 ui_out_text (uiout, " at ");
3426 ui_out_field_string (uiout, "file", b->source_file);
3427 ui_out_text (uiout, ":");
3429 if (ui_out_is_mi_like_p (uiout))
3431 struct symtab_and_line sal = find_pc_line (loc->address, 0);
3432 char *fullname = symtab_to_fullname (sal.symtab);
3435 ui_out_field_string (uiout, "fullname", fullname);
3438 ui_out_field_int (uiout, "line", b->line_number);
3442 ui_out_field_string (uiout, "pending", b->addr_string);
3446 print_address_symbolic (loc->address, stb->stream, demangle, "");
3447 ui_out_field_stream (uiout, "at", stb);
3451 /* Print B to gdb_stdout. */
3453 print_one_breakpoint_location (struct breakpoint *b,
3454 struct bp_location *loc,
3456 CORE_ADDR *last_addr)
3458 struct command_line *l;
3460 struct ep_type_description
3465 static struct ep_type_description bptypes[] =
3467 {bp_none, "?deleted?"},
3468 {bp_breakpoint, "breakpoint"},
3469 {bp_hardware_breakpoint, "hw breakpoint"},
3470 {bp_until, "until"},
3471 {bp_finish, "finish"},
3472 {bp_watchpoint, "watchpoint"},
3473 {bp_hardware_watchpoint, "hw watchpoint"},
3474 {bp_read_watchpoint, "read watchpoint"},
3475 {bp_access_watchpoint, "acc watchpoint"},
3476 {bp_longjmp, "longjmp"},
3477 {bp_longjmp_resume, "longjmp resume"},
3478 {bp_step_resume, "step resume"},
3479 {bp_watchpoint_scope, "watchpoint scope"},
3480 {bp_call_dummy, "call dummy"},
3481 {bp_shlib_event, "shlib events"},
3482 {bp_thread_event, "thread events"},
3483 {bp_overlay_event, "overlay events"},
3484 {bp_catchpoint, "catchpoint"},
3485 {bp_tracepoint, "tracepoint"},
3488 static char bpenables[] = "nynny";
3489 char wrap_indent[80];
3490 struct ui_stream *stb = ui_out_stream_new (uiout);
3491 struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb);
3492 struct cleanup *bkpt_chain;
3494 int header_of_multiple = 0;
3495 int part_of_multiple = (loc != NULL);
3496 struct value_print_options opts;
3498 get_user_print_options (&opts);
3500 gdb_assert (!loc || loc_number != 0);
3501 /* See comment in print_one_breakpoint concerning
3502 treatment of breakpoints with single disabled
3506 && (b->loc->next != NULL || !b->loc->enabled)))
3507 header_of_multiple = 1;
3512 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
3516 if (part_of_multiple)
3519 formatted = xstrprintf ("%d.%d", b->number, loc_number);
3520 ui_out_field_string (uiout, "number", formatted);
3525 ui_out_field_int (uiout, "number", b->number);
3530 if (part_of_multiple)
3531 ui_out_field_skip (uiout, "type");
3534 if (((int) b->type >= (sizeof (bptypes) / sizeof (bptypes[0])))
3535 || ((int) b->type != bptypes[(int) b->type].type))
3536 internal_error (__FILE__, __LINE__,
3537 _("bptypes table does not describe type #%d."),
3539 ui_out_field_string (uiout, "type", bptypes[(int) b->type].description);
3544 if (part_of_multiple)
3545 ui_out_field_skip (uiout, "disp");
3547 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
3552 if (part_of_multiple)
3553 ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n");
3555 ui_out_field_fmt (uiout, "enabled", "%c",
3556 bpenables[(int) b->enable_state]);
3557 ui_out_spaces (uiout, 2);
3561 strcpy (wrap_indent, " ");
3562 if (opts.addressprint)
3564 if (gdbarch_addr_bit (current_gdbarch) <= 32)
3565 strcat (wrap_indent, " ");
3567 strcat (wrap_indent, " ");
3570 if (b->ops != NULL && b->ops->print_one != NULL)
3572 /* Although the print_one can possibly print
3573 all locations, calling it here is not likely
3574 to get any nice result. So, make sure there's
3575 just one location. */
3576 gdb_assert (b->loc == NULL || b->loc->next == NULL);
3577 b->ops->print_one (b, last_addr);
3583 internal_error (__FILE__, __LINE__,
3584 _("print_one_breakpoint: bp_none encountered\n"));
3588 case bp_hardware_watchpoint:
3589 case bp_read_watchpoint:
3590 case bp_access_watchpoint:
3591 /* Field 4, the address, is omitted (which makes the columns
3592 not line up too nicely with the headers, but the effect
3593 is relatively readable). */
3594 if (opts.addressprint)
3595 ui_out_field_skip (uiout, "addr");
3597 ui_out_field_string (uiout, "what", b->exp_string);
3601 case bp_hardware_breakpoint:
3605 case bp_longjmp_resume:
3606 case bp_step_resume:
3607 case bp_watchpoint_scope:
3609 case bp_shlib_event:
3610 case bp_thread_event:
3611 case bp_overlay_event:
3613 if (opts.addressprint)
3616 if (header_of_multiple)
3617 ui_out_field_string (uiout, "addr", "<MULTIPLE>");
3618 else if (b->loc == NULL || loc->shlib_disabled)
3619 ui_out_field_string (uiout, "addr", "<PENDING>");
3621 ui_out_field_core_addr (uiout, "addr", loc->address);
3624 if (!header_of_multiple)
3625 print_breakpoint_location (b, loc, wrap_indent, stb);
3627 *last_addr = b->loc->address;
3631 if (!part_of_multiple)
3633 if (b->thread != -1)
3635 /* FIXME: This seems to be redundant and lost here; see the
3636 "stop only in" line a little further down. */
3637 ui_out_text (uiout, " thread ");
3638 ui_out_field_int (uiout, "thread", b->thread);
3640 else if (b->task != 0)
3642 ui_out_text (uiout, " task ");
3643 ui_out_field_int (uiout, "task", b->task);
3647 ui_out_text (uiout, "\n");
3649 if (part_of_multiple && frame_id_p (b->frame_id))
3652 ui_out_text (uiout, "\tstop only in stack frame at ");
3653 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3655 ui_out_field_core_addr (uiout, "frame", b->frame_id.stack_addr);
3656 ui_out_text (uiout, "\n");
3659 if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b))
3661 /* We do not print the condition for Ada exception catchpoints
3662 because the condition is an internal implementation detail
3663 that we do not want to expose to the user. */
3665 if (b->type == bp_tracepoint)
3666 ui_out_text (uiout, "\ttrace only if ");
3668 ui_out_text (uiout, "\tstop only if ");
3669 ui_out_field_string (uiout, "cond", b->cond_string);
3670 ui_out_text (uiout, "\n");
3673 if (!part_of_multiple && b->thread != -1)
3675 /* FIXME should make an annotation for this */
3676 ui_out_text (uiout, "\tstop only in thread ");
3677 ui_out_field_int (uiout, "thread", b->thread);
3678 ui_out_text (uiout, "\n");
3681 if (!part_of_multiple && b->hit_count)
3683 /* FIXME should make an annotation for this */
3684 if (ep_is_catchpoint (b))
3685 ui_out_text (uiout, "\tcatchpoint");
3687 ui_out_text (uiout, "\tbreakpoint");
3688 ui_out_text (uiout, " already hit ");
3689 ui_out_field_int (uiout, "times", b->hit_count);
3690 if (b->hit_count == 1)
3691 ui_out_text (uiout, " time\n");
3693 ui_out_text (uiout, " times\n");
3696 /* Output the count also if it is zero, but only if this is
3697 mi. FIXME: Should have a better test for this. */
3698 if (ui_out_is_mi_like_p (uiout))
3699 if (!part_of_multiple && b->hit_count == 0)
3700 ui_out_field_int (uiout, "times", b->hit_count);
3702 if (!part_of_multiple && b->ignore_count)
3705 ui_out_text (uiout, "\tignore next ");
3706 ui_out_field_int (uiout, "ignore", b->ignore_count);
3707 ui_out_text (uiout, " hits\n");
3710 if (!part_of_multiple && (l = b->commands))
3712 struct cleanup *script_chain;
3715 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
3716 print_command_lines (uiout, l, 4);
3717 do_cleanups (script_chain);
3720 if (!part_of_multiple && b->pass_count)
3722 annotate_field (10);
3723 ui_out_text (uiout, "\tpass count ");
3724 ui_out_field_int (uiout, "pass", b->pass_count);
3725 ui_out_text (uiout, " \n");
3728 if (!part_of_multiple && b->step_count)
3730 annotate_field (11);
3731 ui_out_text (uiout, "\tstep count ");
3732 ui_out_field_int (uiout, "step", b->step_count);
3733 ui_out_text (uiout, " \n");
3736 if (!part_of_multiple && b->actions)
3738 struct action_line *action;
3739 annotate_field (12);
3740 for (action = b->actions; action; action = action->next)
3742 ui_out_text (uiout, " A\t");
3743 ui_out_text (uiout, action->action);
3744 ui_out_text (uiout, "\n");
3748 if (ui_out_is_mi_like_p (uiout) && !part_of_multiple)
3751 ui_out_field_string (uiout, "original-location", b->addr_string);
3752 else if (b->exp_string)
3753 ui_out_field_string (uiout, "original-location", b->exp_string);
3756 do_cleanups (bkpt_chain);
3757 do_cleanups (old_chain);
3761 print_one_breakpoint (struct breakpoint *b,
3762 CORE_ADDR *last_addr)
3764 print_one_breakpoint_location (b, NULL, 0, last_addr);
3766 /* If this breakpoint has custom print function,
3767 it's already printed. Otherwise, print individual
3768 locations, if any. */
3769 if (b->ops == NULL || b->ops->print_one == NULL)
3771 /* If breakpoint has a single location that is
3772 disabled, we print it as if it had
3773 several locations, since otherwise it's hard to
3774 represent "breakpoint enabled, location disabled"
3776 Note that while hardware watchpoints have
3777 several locations internally, that's no a property
3780 && !is_hardware_watchpoint (b)
3781 && (b->loc->next || !b->loc->enabled)
3782 && !ui_out_is_mi_like_p (uiout))
3784 struct bp_location *loc;
3786 for (loc = b->loc; loc; loc = loc->next, ++n)
3787 print_one_breakpoint_location (b, loc, n, last_addr);
3793 struct captured_breakpoint_query_args
3799 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
3801 struct captured_breakpoint_query_args *args = data;
3802 struct breakpoint *b;
3803 CORE_ADDR dummy_addr = 0;
3806 if (args->bnum == b->number)
3808 print_one_breakpoint (b, &dummy_addr);
3816 gdb_breakpoint_query (struct ui_out *uiout, int bnum, char **error_message)
3818 struct captured_breakpoint_query_args args;
3820 /* For the moment we don't trust print_one_breakpoint() to not throw
3822 if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args,
3823 error_message, RETURN_MASK_ALL) < 0)
3829 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3830 catchpoints, et.al.). */
3833 user_settable_breakpoint (const struct breakpoint *b)
3835 return (b->type == bp_breakpoint
3836 || b->type == bp_catchpoint
3837 || b->type == bp_hardware_breakpoint
3838 || b->type == bp_tracepoint
3839 || b->type == bp_watchpoint
3840 || b->type == bp_read_watchpoint
3841 || b->type == bp_access_watchpoint
3842 || b->type == bp_hardware_watchpoint);
3845 /* Print information on user settable breakpoint (watchpoint, etc)
3846 number BNUM. If BNUM is -1 print all user settable breakpoints.
3847 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3850 breakpoint_1 (int bnum, int allflag)
3852 struct breakpoint *b;
3853 CORE_ADDR last_addr = (CORE_ADDR) -1;
3854 int nr_printable_breakpoints;
3855 struct cleanup *bkpttbl_chain;
3856 struct value_print_options opts;
3858 get_user_print_options (&opts);
3860 /* Compute the number of rows in the table. */
3861 nr_printable_breakpoints = 0;
3864 || bnum == b->number)
3866 if (allflag || user_settable_breakpoint (b))
3867 nr_printable_breakpoints++;
3870 if (opts.addressprint)
3872 = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints,
3876 = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints,
3879 if (nr_printable_breakpoints > 0)
3880 annotate_breakpoints_headers ();
3881 if (nr_printable_breakpoints > 0)
3883 ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */
3884 if (nr_printable_breakpoints > 0)
3886 ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */
3887 if (nr_printable_breakpoints > 0)
3889 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
3890 if (nr_printable_breakpoints > 0)
3892 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
3893 if (opts.addressprint)
3895 if (nr_printable_breakpoints > 0)
3897 if (gdbarch_addr_bit (current_gdbarch) <= 32)
3898 ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */
3900 ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */
3902 if (nr_printable_breakpoints > 0)
3904 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
3905 ui_out_table_body (uiout);
3906 if (nr_printable_breakpoints > 0)
3907 annotate_breakpoints_table ();
3911 || bnum == b->number)
3913 /* We only print out user settable breakpoints unless the
3915 if (allflag || user_settable_breakpoint (b))
3916 print_one_breakpoint (b, &last_addr);
3919 do_cleanups (bkpttbl_chain);
3921 if (nr_printable_breakpoints == 0)
3924 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
3926 ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n",
3931 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3932 that a comparison of an unsigned with -1 is always false. */
3933 if (last_addr != (CORE_ADDR) -1 && !server_command)
3934 set_next_address (current_gdbarch, last_addr);
3937 /* FIXME? Should this be moved up so that it is only called when
3938 there have been breakpoints? */
3939 annotate_breakpoints_table_end ();
3943 breakpoints_info (char *bnum_exp, int from_tty)
3948 bnum = parse_and_eval_long (bnum_exp);
3950 breakpoint_1 (bnum, 0);
3954 maintenance_info_breakpoints (char *bnum_exp, int from_tty)
3959 bnum = parse_and_eval_long (bnum_exp);
3961 breakpoint_1 (bnum, 1);
3965 breakpoint_has_pc (struct breakpoint *b,
3966 CORE_ADDR pc, struct obj_section *section)
3968 struct bp_location *bl = b->loc;
3969 for (; bl; bl = bl->next)
3971 if (bl->address == pc
3972 && (!overlay_debugging || bl->section == section))
3978 /* Print a message describing any breakpoints set at PC. */
3981 describe_other_breakpoints (CORE_ADDR pc, struct obj_section *section,
3985 struct breakpoint *b;
3988 others += breakpoint_has_pc (b, pc, section);
3992 printf_filtered (_("Note: breakpoint "));
3993 else /* if (others == ???) */
3994 printf_filtered (_("Note: breakpoints "));
3996 if (breakpoint_has_pc (b, pc, section))
3999 printf_filtered ("%d", b->number);
4000 if (b->thread == -1 && thread != -1)
4001 printf_filtered (" (all threads)");
4002 else if (b->thread != -1)
4003 printf_filtered (" (thread %d)", b->thread);
4004 printf_filtered ("%s%s ",
4005 ((b->enable_state == bp_disabled ||
4006 b->enable_state == bp_call_disabled)
4008 : b->enable_state == bp_permanent
4012 : ((others == 1) ? " and" : ""));
4014 printf_filtered (_("also set at pc "));
4015 fputs_filtered (paddress (pc), gdb_stdout);
4016 printf_filtered (".\n");
4020 /* Set the default place to put a breakpoint
4021 for the `break' command with no arguments. */
4024 set_default_breakpoint (int valid, CORE_ADDR addr, struct symtab *symtab,
4027 default_breakpoint_valid = valid;
4028 default_breakpoint_address = addr;
4029 default_breakpoint_symtab = symtab;
4030 default_breakpoint_line = line;
4033 /* Return true iff it is meaningful to use the address member of
4034 BPT. For some breakpoint types, the address member is irrelevant
4035 and it makes no sense to attempt to compare it to other addresses
4036 (or use it for any other purpose either).
4038 More specifically, each of the following breakpoint types will always
4039 have a zero valued address and we don't want check_duplicates() to mark
4040 breakpoints of any of these types to be a duplicate of an actual
4041 breakpoint at address zero:
4044 bp_hardware_watchpoint
4046 bp_access_watchpoint
4050 breakpoint_address_is_meaningful (struct breakpoint *bpt)
4052 enum bptype type = bpt->type;
4054 return (type != bp_watchpoint
4055 && type != bp_hardware_watchpoint
4056 && type != bp_read_watchpoint
4057 && type != bp_access_watchpoint
4058 && type != bp_catchpoint);
4061 /* Rescan breakpoints at the same address and section as BPT,
4062 marking the first one as "first" and any others as "duplicates".
4063 This is so that the bpt instruction is only inserted once.
4064 If we have a permanent breakpoint at the same place as BPT, make
4065 that one the official one, and the rest as duplicates. */
4068 check_duplicates_for (CORE_ADDR address, struct obj_section *section)
4070 struct bp_location *b;
4072 struct bp_location *perm_bp = 0;
4074 ALL_BP_LOCATIONS (b)
4075 if (b->owner->enable_state != bp_disabled
4076 && b->owner->enable_state != bp_call_disabled
4078 && !b->shlib_disabled
4079 && b->address == address /* address / overlay match */
4080 && (!overlay_debugging || b->section == section)
4081 && breakpoint_address_is_meaningful (b->owner))
4083 /* Have we found a permanent breakpoint? */
4084 if (b->owner->enable_state == bp_permanent)
4091 b->duplicate = count > 1;
4094 /* If we found a permanent breakpoint at this address, go over the
4095 list again and declare all the other breakpoints there (except
4096 other permanent breakpoints) to be the duplicates. */
4099 perm_bp->duplicate = 0;
4101 /* Permanent breakpoint should always be inserted. */
4102 if (! perm_bp->inserted)
4103 internal_error (__FILE__, __LINE__,
4104 _("allegedly permanent breakpoint is not "
4105 "actually inserted"));
4107 ALL_BP_LOCATIONS (b)
4110 if (b->owner->enable_state != bp_permanent
4111 && b->owner->enable_state != bp_disabled
4112 && b->owner->enable_state != bp_call_disabled
4113 && b->enabled && !b->shlib_disabled
4114 && b->address == address /* address / overlay match */
4115 && (!overlay_debugging || b->section == section)
4116 && breakpoint_address_is_meaningful (b->owner))
4119 internal_error (__FILE__, __LINE__,
4120 _("another breakpoint was inserted on top of "
4121 "a permanent breakpoint"));
4130 check_duplicates (struct breakpoint *bpt)
4132 struct bp_location *bl = bpt->loc;
4134 if (! breakpoint_address_is_meaningful (bpt))
4137 for (; bl; bl = bl->next)
4138 check_duplicates_for (bl->address, bl->section);
4142 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
4143 int bnum, int have_bnum)
4148 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
4149 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
4151 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4152 bnum, astr1, astr2);
4154 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
4157 /* Adjust a breakpoint's address to account for architectural constraints
4158 on breakpoint placement. Return the adjusted address. Note: Very
4159 few targets require this kind of adjustment. For most targets,
4160 this function is simply the identity function. */
4163 adjust_breakpoint_address (CORE_ADDR bpaddr, enum bptype bptype)
4165 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch))
4167 /* Very few targets need any kind of breakpoint adjustment. */
4170 else if (bptype == bp_watchpoint
4171 || bptype == bp_hardware_watchpoint
4172 || bptype == bp_read_watchpoint
4173 || bptype == bp_access_watchpoint
4174 || bptype == bp_catchpoint)
4176 /* Watchpoints and the various bp_catch_* eventpoints should not
4177 have their addresses modified. */
4182 CORE_ADDR adjusted_bpaddr;
4184 /* Some targets have architectural constraints on the placement
4185 of breakpoint instructions. Obtain the adjusted address. */
4186 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (current_gdbarch,
4189 /* An adjusted breakpoint address can significantly alter
4190 a user's expectations. Print a warning if an adjustment
4192 if (adjusted_bpaddr != bpaddr)
4193 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
4195 return adjusted_bpaddr;
4199 /* Allocate a struct bp_location. */
4201 static struct bp_location *
4202 allocate_bp_location (struct breakpoint *bpt)
4204 struct bp_location *loc, *loc_p;
4206 loc = xmalloc (sizeof (struct bp_location));
4207 memset (loc, 0, sizeof (*loc));
4211 loc->shlib_disabled = 0;
4221 case bp_longjmp_resume:
4222 case bp_step_resume:
4223 case bp_watchpoint_scope:
4225 case bp_shlib_event:
4226 case bp_thread_event:
4227 case bp_overlay_event:
4228 loc->loc_type = bp_loc_software_breakpoint;
4230 case bp_hardware_breakpoint:
4231 loc->loc_type = bp_loc_hardware_breakpoint;
4233 case bp_hardware_watchpoint:
4234 case bp_read_watchpoint:
4235 case bp_access_watchpoint:
4236 loc->loc_type = bp_loc_hardware_watchpoint;
4240 loc->loc_type = bp_loc_other;
4243 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
4249 static void free_bp_location (struct bp_location *loc)
4254 if (loc->function_name)
4255 xfree (loc->function_name);
4260 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4261 that has type BPTYPE and has no locations as yet. */
4263 static struct breakpoint *
4264 set_raw_breakpoint_without_location (enum bptype bptype)
4266 struct breakpoint *b, *b1;
4268 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
4269 memset (b, 0, sizeof (*b));
4272 b->language = current_language->la_language;
4273 b->input_radix = input_radix;
4275 b->enable_state = bp_enabled;
4278 b->ignore_count = 0;
4280 b->frame_id = null_frame_id;
4281 b->forked_inferior_pid = null_ptid;
4282 b->exec_pathname = NULL;
4284 b->condition_not_parsed = 0;
4286 /* Add this breakpoint to the end of the chain
4287 so that a list of breakpoints will come out in order
4288 of increasing numbers. */
4290 b1 = breakpoint_chain;
4292 breakpoint_chain = b;
4302 /* Initialize loc->function_name. */
4304 set_breakpoint_location_function (struct bp_location *loc)
4306 if (loc->owner->type == bp_breakpoint
4307 || loc->owner->type == bp_hardware_breakpoint
4308 || loc->owner->type == bp_tracepoint)
4310 find_pc_partial_function (loc->address, &(loc->function_name),
4312 if (loc->function_name)
4313 loc->function_name = xstrdup (loc->function_name);
4317 /* set_raw_breakpoint is a low level routine for allocating and
4318 partially initializing a breakpoint of type BPTYPE. The newly
4319 created breakpoint's address, section, source file name, and line
4320 number are provided by SAL. The newly created and partially
4321 initialized breakpoint is added to the breakpoint chain and
4322 is also returned as the value of this function.
4324 It is expected that the caller will complete the initialization of
4325 the newly created breakpoint struct as well as output any status
4326 information regarding the creation of a new breakpoint. In
4327 particular, set_raw_breakpoint does NOT set the breakpoint
4328 number! Care should be taken to not allow an error to occur
4329 prior to completing the initialization of the breakpoint. If this
4330 should happen, a bogus breakpoint will be left on the chain. */
4333 set_raw_breakpoint (struct symtab_and_line sal, enum bptype bptype)
4335 struct breakpoint *b = set_raw_breakpoint_without_location (bptype);
4336 CORE_ADDR adjusted_address;
4338 /* Adjust the breakpoint's address prior to allocating a location.
4339 Once we call allocate_bp_location(), that mostly uninitialized
4340 location will be placed on the location chain. Adjustment of the
4341 breakpoint may cause target_read_memory() to be called and we do
4342 not want its scan of the location chain to find a breakpoint and
4343 location that's only been partially initialized. */
4344 adjusted_address = adjust_breakpoint_address (sal.pc, b->type);
4346 b->loc = allocate_bp_location (b);
4347 b->loc->requested_address = sal.pc;
4348 b->loc->address = adjusted_address;
4350 if (sal.symtab == NULL)
4351 b->source_file = NULL;
4353 b->source_file = savestring (sal.symtab->filename,
4354 strlen (sal.symtab->filename));
4355 b->loc->section = sal.section;
4356 b->line_number = sal.line;
4358 set_breakpoint_location_function (b->loc);
4360 breakpoints_changed ();
4366 /* Note that the breakpoint object B describes a permanent breakpoint
4367 instruction, hard-wired into the inferior's code. */
4369 make_breakpoint_permanent (struct breakpoint *b)
4371 struct bp_location *bl;
4372 b->enable_state = bp_permanent;
4374 /* By definition, permanent breakpoints are already present in the code.
4375 Mark all locations as inserted. For now, make_breakpoint_permanent
4376 is called in just one place, so it's hard to say if it's reasonable
4377 to have permanent breakpoint with multiple locations or not,
4378 but it's easy to implmement. */
4379 for (bl = b->loc; bl; bl = bl->next)
4383 static struct breakpoint *
4384 create_internal_breakpoint (CORE_ADDR address, enum bptype type)
4386 static int internal_breakpoint_number = -1;
4387 struct symtab_and_line sal;
4388 struct breakpoint *b;
4390 init_sal (&sal); /* initialize to zeroes */
4393 sal.section = find_pc_overlay (sal.pc);
4395 b = set_raw_breakpoint (sal, type);
4396 b->number = internal_breakpoint_number--;
4397 b->disposition = disp_donttouch;
4404 create_longjmp_breakpoint (char *func_name)
4406 struct minimal_symbol *m;
4408 if ((m = lookup_minimal_symbol_text (func_name, NULL)) == NULL)
4410 set_momentary_breakpoint_at_pc (SYMBOL_VALUE_ADDRESS (m), bp_longjmp);
4411 update_global_location_list (1);
4414 /* Call this routine when stepping and nexting to enable a breakpoint
4415 if we do a longjmp(). When we hit that breakpoint, call
4416 set_longjmp_resume_breakpoint() to figure out where we are going. */
4419 set_longjmp_breakpoint (void)
4421 if (gdbarch_get_longjmp_target_p (current_gdbarch))
4423 create_longjmp_breakpoint ("longjmp");
4424 create_longjmp_breakpoint ("_longjmp");
4425 create_longjmp_breakpoint ("siglongjmp");
4426 create_longjmp_breakpoint ("_siglongjmp");
4430 /* Delete all longjmp breakpoints from THREAD. */
4432 delete_longjmp_breakpoint (int thread)
4434 struct breakpoint *b, *temp;
4436 ALL_BREAKPOINTS_SAFE (b, temp)
4437 if (b->type == bp_longjmp)
4439 if (b->thread == thread)
4440 delete_breakpoint (b);
4445 create_overlay_event_breakpoint_1 (char *func_name, struct objfile *objfile)
4447 struct breakpoint *b;
4448 struct minimal_symbol *m;
4450 if ((m = lookup_minimal_symbol_text (func_name, objfile)) == NULL)
4453 b = create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m),
4455 b->addr_string = xstrdup (func_name);
4457 if (overlay_debugging == ovly_auto)
4459 b->enable_state = bp_enabled;
4460 overlay_events_enabled = 1;
4464 b->enable_state = bp_disabled;
4465 overlay_events_enabled = 0;
4467 update_global_location_list (1);
4471 create_overlay_event_breakpoint (char *func_name)
4473 struct objfile *objfile;
4474 ALL_OBJFILES (objfile)
4475 create_overlay_event_breakpoint_1 (func_name, objfile);
4479 enable_overlay_breakpoints (void)
4481 struct breakpoint *b;
4484 if (b->type == bp_overlay_event)
4486 b->enable_state = bp_enabled;
4487 update_global_location_list (1);
4488 overlay_events_enabled = 1;
4493 disable_overlay_breakpoints (void)
4495 struct breakpoint *b;
4498 if (b->type == bp_overlay_event)
4500 b->enable_state = bp_disabled;
4501 update_global_location_list (0);
4502 overlay_events_enabled = 0;
4507 create_thread_event_breakpoint (CORE_ADDR address)
4509 struct breakpoint *b;
4511 b = create_internal_breakpoint (address, bp_thread_event);
4513 b->enable_state = bp_enabled;
4514 /* addr_string has to be used or breakpoint_re_set will delete me. */
4515 b->addr_string = xstrprintf ("*0x%s", paddr (b->loc->address));
4517 update_global_location_list_nothrow (1);
4523 remove_thread_event_breakpoints (void)
4525 struct breakpoint *b, *temp;
4527 ALL_BREAKPOINTS_SAFE (b, temp)
4528 if (b->type == bp_thread_event)
4529 delete_breakpoint (b);
4532 struct captured_parse_breakpoint_args
4535 struct symtabs_and_lines *sals_p;
4536 char ***addr_string_p;
4540 struct lang_and_radix
4548 remove_solib_event_breakpoints (void)
4550 struct breakpoint *b, *temp;
4552 ALL_BREAKPOINTS_SAFE (b, temp)
4553 if (b->type == bp_shlib_event)
4554 delete_breakpoint (b);
4558 create_solib_event_breakpoint (CORE_ADDR address)
4560 struct breakpoint *b;
4562 b = create_internal_breakpoint (address, bp_shlib_event);
4563 update_global_location_list_nothrow (1);
4567 /* Disable any breakpoints that are on code in shared libraries. Only
4568 apply to enabled breakpoints, disabled ones can just stay disabled. */
4571 disable_breakpoints_in_shlibs (void)
4573 struct bp_location *loc;
4575 ALL_BP_LOCATIONS (loc)
4577 struct breakpoint *b = loc->owner;
4578 /* We apply the check to all breakpoints, including disabled
4579 for those with loc->duplicate set. This is so that when breakpoint
4580 becomes enabled, or the duplicate is removed, gdb will try to insert
4581 all breakpoints. If we don't set shlib_disabled here, we'll try
4582 to insert those breakpoints and fail. */
4583 if (((b->type == bp_breakpoint)
4584 || (b->type == bp_hardware_breakpoint)
4585 || (b->type == bp_tracepoint))
4586 && !loc->shlib_disabled
4588 && PC_SOLIB (loc->address)
4590 && solib_name_from_address (loc->address)
4594 loc->shlib_disabled = 1;
4599 /* Disable any breakpoints that are in in an unloaded shared library. Only
4600 apply to enabled breakpoints, disabled ones can just stay disabled. */
4603 disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
4605 struct bp_location *loc;
4606 int disabled_shlib_breaks = 0;
4608 /* SunOS a.out shared libraries are always mapped, so do not
4609 disable breakpoints; they will only be reported as unloaded
4610 through clear_solib when GDB discards its shared library
4611 list. See clear_solib for more information. */
4612 if (exec_bfd != NULL
4613 && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour)
4616 ALL_BP_LOCATIONS (loc)
4618 struct breakpoint *b = loc->owner;
4619 if ((loc->loc_type == bp_loc_hardware_breakpoint
4620 || loc->loc_type == bp_loc_software_breakpoint)
4621 && !loc->shlib_disabled
4622 && (b->type == bp_breakpoint || b->type == bp_hardware_breakpoint)
4623 && solib_contains_address_p (solib, loc->address))
4625 loc->shlib_disabled = 1;
4626 /* At this point, we cannot rely on remove_breakpoint
4627 succeeding so we must mark the breakpoint as not inserted
4628 to prevent future errors occurring in remove_breakpoints. */
4630 if (!disabled_shlib_breaks)
4632 target_terminal_ours_for_output ();
4633 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4636 disabled_shlib_breaks = 1;
4641 /* FORK & VFORK catchpoints. */
4643 /* Implement the "insert" breakpoint_ops method for fork catchpoints. */
4646 insert_catch_fork (struct breakpoint *b)
4648 target_insert_fork_catchpoint (PIDGET (inferior_ptid));
4651 /* Implement the "remove" breakpoint_ops method for fork catchpoints. */
4654 remove_catch_fork (struct breakpoint *b)
4656 return target_remove_fork_catchpoint (PIDGET (inferior_ptid));
4659 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
4663 breakpoint_hit_catch_fork (struct breakpoint *b)
4665 return inferior_has_forked (inferior_ptid, &b->forked_inferior_pid);
4668 /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */
4670 static enum print_stop_action
4671 print_it_catch_fork (struct breakpoint *b)
4673 annotate_catchpoint (b->number);
4674 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
4675 b->number, ptid_get_pid (b->forked_inferior_pid));
4676 return PRINT_SRC_AND_LOC;
4679 /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */
4682 print_one_catch_fork (struct breakpoint *b, CORE_ADDR *last_addr)
4684 struct value_print_options opts;
4686 get_user_print_options (&opts);
4688 /* Field 4, the address, is omitted (which makes the columns
4689 not line up too nicely with the headers, but the effect
4690 is relatively readable). */
4691 if (opts.addressprint)
4692 ui_out_field_skip (uiout, "addr");
4694 ui_out_text (uiout, "fork");
4695 if (!ptid_equal (b->forked_inferior_pid, null_ptid))
4697 ui_out_text (uiout, ", process ");
4698 ui_out_field_int (uiout, "what",
4699 ptid_get_pid (b->forked_inferior_pid));
4700 ui_out_spaces (uiout, 1);
4704 /* Implement the "print_mention" breakpoint_ops method for fork
4708 print_mention_catch_fork (struct breakpoint *b)
4710 printf_filtered (_("Catchpoint %d (fork)"), b->number);
4713 /* The breakpoint_ops structure to be used in fork catchpoints. */
4715 static struct breakpoint_ops catch_fork_breakpoint_ops =
4719 breakpoint_hit_catch_fork,
4720 print_it_catch_fork,
4721 print_one_catch_fork,
4722 print_mention_catch_fork
4725 /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */
4728 insert_catch_vfork (struct breakpoint *b)
4730 target_insert_vfork_catchpoint (PIDGET (inferior_ptid));
4733 /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */
4736 remove_catch_vfork (struct breakpoint *b)
4738 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid));
4741 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
4745 breakpoint_hit_catch_vfork (struct breakpoint *b)
4747 return inferior_has_vforked (inferior_ptid, &b->forked_inferior_pid);
4750 /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */
4752 static enum print_stop_action
4753 print_it_catch_vfork (struct breakpoint *b)
4755 annotate_catchpoint (b->number);
4756 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
4757 b->number, ptid_get_pid (b->forked_inferior_pid));
4758 return PRINT_SRC_AND_LOC;
4761 /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */
4764 print_one_catch_vfork (struct breakpoint *b, CORE_ADDR *last_addr)
4766 struct value_print_options opts;
4768 get_user_print_options (&opts);
4769 /* Field 4, the address, is omitted (which makes the columns
4770 not line up too nicely with the headers, but the effect
4771 is relatively readable). */
4772 if (opts.addressprint)
4773 ui_out_field_skip (uiout, "addr");
4775 ui_out_text (uiout, "vfork");
4776 if (!ptid_equal (b->forked_inferior_pid, null_ptid))
4778 ui_out_text (uiout, ", process ");
4779 ui_out_field_int (uiout, "what",
4780 ptid_get_pid (b->forked_inferior_pid));
4781 ui_out_spaces (uiout, 1);
4785 /* Implement the "print_mention" breakpoint_ops method for vfork
4789 print_mention_catch_vfork (struct breakpoint *b)
4791 printf_filtered (_("Catchpoint %d (vfork)"), b->number);
4794 /* The breakpoint_ops structure to be used in vfork catchpoints. */
4796 static struct breakpoint_ops catch_vfork_breakpoint_ops =
4800 breakpoint_hit_catch_vfork,
4801 print_it_catch_vfork,
4802 print_one_catch_vfork,
4803 print_mention_catch_vfork
4806 /* Create a new breakpoint of the bp_catchpoint kind and return it.
4808 If TEMPFLAG is non-zero, then make the breakpoint temporary.
4809 If COND_STRING is not NULL, then store it in the breakpoint.
4810 OPS, if not NULL, is the breakpoint_ops structure associated
4811 to the catchpoint. */
4813 static struct breakpoint *
4814 create_catchpoint (int tempflag, char *cond_string,
4815 struct breakpoint_ops *ops)
4817 struct symtab_and_line sal;
4818 struct breakpoint *b;
4825 b = set_raw_breakpoint (sal, bp_catchpoint);
4826 set_breakpoint_count (breakpoint_count + 1);
4827 b->number = breakpoint_count;
4829 b->cond_string = (cond_string == NULL) ?
4830 NULL : savestring (cond_string, strlen (cond_string));
4832 b->addr_string = NULL;
4833 b->enable_state = bp_enabled;
4834 b->disposition = tempflag ? disp_del : disp_donttouch;
4838 update_global_location_list (1);
4844 create_fork_vfork_event_catchpoint (int tempflag, char *cond_string,
4845 struct breakpoint_ops *ops)
4847 struct breakpoint *b = create_catchpoint (tempflag, cond_string, ops);
4849 /* FIXME: We should put this information in a breakpoint private data
4851 b->forked_inferior_pid = null_ptid;
4854 /* Exec catchpoints. */
4857 insert_catch_exec (struct breakpoint *b)
4859 target_insert_exec_catchpoint (PIDGET (inferior_ptid));
4863 remove_catch_exec (struct breakpoint *b)
4865 return target_remove_exec_catchpoint (PIDGET (inferior_ptid));
4869 breakpoint_hit_catch_exec (struct breakpoint *b)
4871 return inferior_has_execd (inferior_ptid, &b->exec_pathname);
4874 static enum print_stop_action
4875 print_it_catch_exec (struct breakpoint *b)
4877 annotate_catchpoint (b->number);
4878 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number,
4880 return PRINT_SRC_AND_LOC;
4884 print_one_catch_exec (struct breakpoint *b, CORE_ADDR *last_addr)
4886 struct value_print_options opts;
4888 get_user_print_options (&opts);
4890 /* Field 4, the address, is omitted (which makes the columns
4891 not line up too nicely with the headers, but the effect
4892 is relatively readable). */
4893 if (opts.addressprint)
4894 ui_out_field_skip (uiout, "addr");
4896 ui_out_text (uiout, "exec");
4897 if (b->exec_pathname != NULL)
4899 ui_out_text (uiout, ", program \"");
4900 ui_out_field_string (uiout, "what", b->exec_pathname);
4901 ui_out_text (uiout, "\" ");
4906 print_mention_catch_exec (struct breakpoint *b)
4908 printf_filtered (_("Catchpoint %d (exec)"), b->number);
4911 static struct breakpoint_ops catch_exec_breakpoint_ops =
4915 breakpoint_hit_catch_exec,
4916 print_it_catch_exec,
4917 print_one_catch_exec,
4918 print_mention_catch_exec
4922 hw_breakpoint_used_count (void)
4924 struct breakpoint *b;
4929 if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b))
4937 hw_watchpoint_used_count (enum bptype type, int *other_type_used)
4939 struct breakpoint *b;
4942 *other_type_used = 0;
4945 if (breakpoint_enabled (b))
4947 if (b->type == type)
4949 else if ((b->type == bp_hardware_watchpoint ||
4950 b->type == bp_read_watchpoint ||
4951 b->type == bp_access_watchpoint))
4952 *other_type_used = 1;
4959 disable_watchpoints_before_interactive_call_start (void)
4961 struct breakpoint *b;
4965 if (((b->type == bp_watchpoint)
4966 || (b->type == bp_hardware_watchpoint)
4967 || (b->type == bp_read_watchpoint)
4968 || (b->type == bp_access_watchpoint))
4969 && breakpoint_enabled (b))
4971 b->enable_state = bp_call_disabled;
4972 update_global_location_list (0);
4978 enable_watchpoints_after_interactive_call_stop (void)
4980 struct breakpoint *b;
4984 if (((b->type == bp_watchpoint)
4985 || (b->type == bp_hardware_watchpoint)
4986 || (b->type == bp_read_watchpoint)
4987 || (b->type == bp_access_watchpoint))
4988 && (b->enable_state == bp_call_disabled))
4990 b->enable_state = bp_enabled;
4991 update_global_location_list (1);
4997 /* Set a breakpoint that will evaporate an end of command
4998 at address specified by SAL.
4999 Restrict it to frame FRAME if FRAME is nonzero. */
5002 set_momentary_breakpoint (struct symtab_and_line sal, struct frame_id frame_id,
5005 struct breakpoint *b;
5006 b = set_raw_breakpoint (sal, type);
5007 b->enable_state = bp_enabled;
5008 b->disposition = disp_donttouch;
5009 b->frame_id = frame_id;
5011 /* If we're debugging a multi-threaded program, then we
5012 want momentary breakpoints to be active in only a
5013 single thread of control. */
5014 if (in_thread_list (inferior_ptid))
5015 b->thread = pid_to_thread_id (inferior_ptid);
5017 update_global_location_list_nothrow (1);
5023 set_momentary_breakpoint_at_pc (CORE_ADDR pc, enum bptype type)
5025 struct symtab_and_line sal;
5027 sal = find_pc_line (pc, 0);
5029 sal.section = find_pc_overlay (pc);
5030 sal.explicit_pc = 1;
5032 return set_momentary_breakpoint (sal, null_frame_id, type);
5036 /* Tell the user we have just set a breakpoint B. */
5039 mention (struct breakpoint *b)
5042 struct cleanup *ui_out_chain;
5043 struct value_print_options opts;
5045 get_user_print_options (&opts);
5047 /* FIXME: This is misplaced; mention() is called by things (like
5048 hitting a watchpoint) other than breakpoint creation. It should
5049 be possible to clean this up and at the same time replace the
5050 random calls to breakpoint_changed with this hook. */
5051 observer_notify_breakpoint_created (b->number);
5053 if (b->ops != NULL && b->ops->print_mention != NULL)
5054 b->ops->print_mention (b);
5059 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b->number);
5062 ui_out_text (uiout, "Watchpoint ");
5063 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
5064 ui_out_field_int (uiout, "number", b->number);
5065 ui_out_text (uiout, ": ");
5066 ui_out_field_string (uiout, "exp", b->exp_string);
5067 do_cleanups (ui_out_chain);
5069 case bp_hardware_watchpoint:
5070 ui_out_text (uiout, "Hardware watchpoint ");
5071 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
5072 ui_out_field_int (uiout, "number", b->number);
5073 ui_out_text (uiout, ": ");
5074 ui_out_field_string (uiout, "exp", b->exp_string);
5075 do_cleanups (ui_out_chain);
5077 case bp_read_watchpoint:
5078 ui_out_text (uiout, "Hardware read watchpoint ");
5079 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
5080 ui_out_field_int (uiout, "number", b->number);
5081 ui_out_text (uiout, ": ");
5082 ui_out_field_string (uiout, "exp", b->exp_string);
5083 do_cleanups (ui_out_chain);
5085 case bp_access_watchpoint:
5086 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
5087 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
5088 ui_out_field_int (uiout, "number", b->number);
5089 ui_out_text (uiout, ": ");
5090 ui_out_field_string (uiout, "exp", b->exp_string);
5091 do_cleanups (ui_out_chain);
5094 if (ui_out_is_mi_like_p (uiout))
5099 if (b->disposition == disp_del)
5100 printf_filtered (_("Temporary breakpoint"));
5102 printf_filtered (_("Breakpoint"));
5103 printf_filtered (_(" %d"), b->number);
5106 case bp_hardware_breakpoint:
5107 if (ui_out_is_mi_like_p (uiout))
5112 printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
5116 if (ui_out_is_mi_like_p (uiout))
5121 printf_filtered (_("Tracepoint"));
5122 printf_filtered (_(" %d"), b->number);
5129 case bp_longjmp_resume:
5130 case bp_step_resume:
5132 case bp_watchpoint_scope:
5133 case bp_shlib_event:
5134 case bp_thread_event:
5135 case bp_overlay_event:
5141 /* i18n: cagney/2005-02-11: Below needs to be merged into a
5145 printf_filtered (_(" (%s) pending."), b->addr_string);
5149 if (opts.addressprint || b->source_file == NULL)
5151 printf_filtered (" at ");
5152 fputs_filtered (paddress (b->loc->address), gdb_stdout);
5155 printf_filtered (": file %s, line %d.",
5156 b->source_file, b->line_number);
5160 struct bp_location *loc = b->loc;
5162 for (; loc; loc = loc->next)
5164 printf_filtered (" (%d locations)", n);
5169 if (ui_out_is_mi_like_p (uiout))
5171 printf_filtered ("\n");
5175 static struct bp_location *
5176 add_location_to_breakpoint (struct breakpoint *b,
5177 const struct symtab_and_line *sal)
5179 struct bp_location *loc, **tmp;
5181 loc = allocate_bp_location (b);
5182 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
5185 loc->requested_address = sal->pc;
5186 loc->address = adjust_breakpoint_address (loc->requested_address, b->type);
5187 loc->section = sal->section;
5189 set_breakpoint_location_function (loc);
5194 /* Return 1 if LOC is pointing to a permanent breakpoint,
5195 return 0 otherwise. */
5198 bp_loc_is_permanent (struct bp_location *loc)
5202 const gdb_byte *brk;
5203 gdb_byte *target_mem;
5204 struct cleanup *cleanup;
5207 gdb_assert (loc != NULL);
5209 addr = loc->address;
5210 brk = gdbarch_breakpoint_from_pc (current_gdbarch, &addr, &len);
5212 /* Software breakpoints unsupported? */
5216 target_mem = alloca (len);
5218 /* Enable the automatic memory restoration from breakpoints while
5219 we read the memory. Otherwise we could say about our temporary
5220 breakpoints they are permanent. */
5221 cleanup = make_show_memory_breakpoints_cleanup (0);
5223 if (target_read_memory (loc->address, target_mem, len) == 0
5224 && memcmp (target_mem, brk, len) == 0)
5227 do_cleanups (cleanup);
5234 /* Create a breakpoint with SAL as location. Use ADDR_STRING
5235 as textual description of the location, and COND_STRING
5236 as condition expression. */
5239 create_breakpoint (struct symtabs_and_lines sals, char *addr_string,
5241 enum bptype type, enum bpdisp disposition,
5242 int thread, int task, int ignore_count,
5243 struct breakpoint_ops *ops, int from_tty, int enabled)
5245 struct breakpoint *b = NULL;
5248 if (type == bp_hardware_breakpoint)
5250 int i = hw_breakpoint_used_count ();
5251 int target_resources_ok =
5252 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
5254 if (target_resources_ok == 0)
5255 error (_("No hardware breakpoint support in the target."));
5256 else if (target_resources_ok < 0)
5257 error (_("Hardware breakpoints used exceeds limit."));
5260 for (i = 0; i < sals.nelts; ++i)
5262 struct symtab_and_line sal = sals.sals[i];
5263 struct bp_location *loc;
5266 describe_other_breakpoints (sal.pc, sal.section, thread);
5270 b = set_raw_breakpoint (sal, type);
5271 set_breakpoint_count (breakpoint_count + 1);
5272 b->number = breakpoint_count;
5276 b->cond_string = cond_string;
5277 b->ignore_count = ignore_count;
5278 b->enable_state = enabled ? bp_enabled : bp_disabled;
5279 b->disposition = disposition;
5285 loc = add_location_to_breakpoint (b, &sal);
5288 if (bp_loc_is_permanent (loc))
5289 make_breakpoint_permanent (b);
5293 char *arg = b->cond_string;
5294 loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0);
5296 error (_("Garbage %s follows condition"), arg);
5301 b->addr_string = addr_string;
5303 /* addr_string has to be used or breakpoint_re_set will delete
5305 b->addr_string = xstrprintf ("*0x%s", paddr (b->loc->address));
5311 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
5312 elements to fill the void space. */
5314 remove_sal (struct symtabs_and_lines *sal, int index_to_remove)
5316 int i = index_to_remove+1;
5317 int last_index = sal->nelts-1;
5319 for (;i <= last_index; ++i)
5320 sal->sals[i-1] = sal->sals[i];
5325 /* If appropriate, obtains all sals that correspond
5326 to the same file and line as SAL. This is done
5327 only if SAL does not have explicit PC and has
5328 line and file information. If we got just a single
5329 expanded sal, return the original.
5331 Otherwise, if SAL.explicit_line is not set, filter out
5332 all sals for which the name of enclosing function
5333 is different from SAL. This makes sure that if we have
5334 breakpoint originally set in template instantiation, say
5335 foo<int>(), we won't expand SAL to locations at the same
5336 line in all existing instantiations of 'foo'.
5339 static struct symtabs_and_lines
5340 expand_line_sal_maybe (struct symtab_and_line sal)
5342 struct symtabs_and_lines expanded;
5343 CORE_ADDR original_pc = sal.pc;
5344 char *original_function = NULL;
5348 /* If we have explicit pc, don't expand.
5349 If we have no line number, we can't expand. */
5350 if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL)
5353 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
5354 expanded.sals[0] = sal;
5359 find_pc_partial_function (original_pc, &original_function, NULL, NULL);
5361 expanded = expand_line_sal (sal);
5362 if (expanded.nelts == 1)
5364 /* We had one sal, we got one sal. Without futher
5365 processing, just return the original sal. */
5366 xfree (expanded.sals);
5368 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
5369 sal.pc = original_pc;
5370 expanded.sals[0] = sal;
5374 if (!sal.explicit_line)
5376 CORE_ADDR func_addr, func_end;
5377 for (i = 0; i < expanded.nelts; ++i)
5379 CORE_ADDR pc = expanded.sals[i].pc;
5380 char *this_function;
5381 if (find_pc_partial_function (pc, &this_function,
5382 &func_addr, &func_end))
5384 if (this_function &&
5385 strcmp (this_function, original_function) != 0)
5387 remove_sal (&expanded, i);
5390 else if (func_addr == pc)
5392 /* We're at beginning of a function, and should
5394 struct symbol *sym = find_pc_function (pc);
5396 expanded.sals[i] = find_function_start_sal (sym, 1);
5399 = gdbarch_skip_prologue (current_gdbarch, pc);
5406 if (expanded.nelts <= 1)
5408 /* This is un ugly workaround. If we get zero
5409 expanded sals then something is really wrong.
5410 Fix that by returnign the original sal. */
5411 xfree (expanded.sals);
5413 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
5414 sal.pc = original_pc;
5415 expanded.sals[0] = sal;
5422 for (i = 0; i < expanded.nelts; ++i)
5423 if (expanded.sals[i].pc == original_pc)
5434 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5435 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5436 value. COND_STRING, if not NULL, specified the condition to be
5437 used for all breakpoints. Essentially the only case where
5438 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
5439 function. In that case, it's still not possible to specify
5440 separate conditions for different overloaded functions, so
5441 we take just a single condition string.
5443 NOTE: If the function succeeds, the caller is expected to cleanup
5444 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
5445 array contents). If the function fails (error() is called), the
5446 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5447 COND and SALS arrays and each of those arrays contents. */
5450 create_breakpoints (struct symtabs_and_lines sals, char **addr_string,
5452 enum bptype type, enum bpdisp disposition,
5453 int thread, int task, int ignore_count,
5454 struct breakpoint_ops *ops, int from_tty,
5458 for (i = 0; i < sals.nelts; ++i)
5460 struct symtabs_and_lines expanded =
5461 expand_line_sal_maybe (sals.sals[i]);
5463 create_breakpoint (expanded, addr_string[i],
5464 cond_string, type, disposition,
5465 thread, task, ignore_count, ops, from_tty, enabled);
5469 /* Parse ARG which is assumed to be a SAL specification possibly
5470 followed by conditionals. On return, SALS contains an array of SAL
5471 addresses found. ADDR_STRING contains a vector of (canonical)
5472 address strings. ARG points to the end of the SAL. */
5475 parse_breakpoint_sals (char **address,
5476 struct symtabs_and_lines *sals,
5477 char ***addr_string,
5480 char *addr_start = *address;
5481 *addr_string = NULL;
5482 /* If no arg given, or if first arg is 'if ', use the default
5484 if ((*address) == NULL
5485 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
5487 if (default_breakpoint_valid)
5489 struct symtab_and_line sal;
5490 init_sal (&sal); /* initialize to zeroes */
5491 sals->sals = (struct symtab_and_line *)
5492 xmalloc (sizeof (struct symtab_and_line));
5493 sal.pc = default_breakpoint_address;
5494 sal.line = default_breakpoint_line;
5495 sal.symtab = default_breakpoint_symtab;
5496 sal.section = find_pc_overlay (sal.pc);
5498 /* "break" without arguments is equivalent to "break *PC" where PC is
5499 the default_breakpoint_address. So make sure to set
5500 sal.explicit_pc to prevent GDB from trying to expand the list of
5501 sals to include all other instances with the same symtab and line.
5503 sal.explicit_pc = 1;
5505 sals->sals[0] = sal;
5509 error (_("No default breakpoint address now."));
5513 /* Force almost all breakpoints to be in terms of the
5514 current_source_symtab (which is decode_line_1's default). This
5515 should produce the results we want almost all of the time while
5516 leaving default_breakpoint_* alone.
5517 ObjC: However, don't match an Objective-C method name which
5518 may have a '+' or '-' succeeded by a '[' */
5520 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
5522 if (default_breakpoint_valid
5524 || ((strchr ("+-", (*address)[0]) != NULL)
5525 && ((*address)[1] != '['))))
5526 *sals = decode_line_1 (address, 1, default_breakpoint_symtab,
5527 default_breakpoint_line, addr_string,
5530 *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0,
5531 addr_string, not_found_ptr);
5533 /* For any SAL that didn't have a canonical string, fill one in. */
5534 if (sals->nelts > 0 && *addr_string == NULL)
5535 *addr_string = xcalloc (sals->nelts, sizeof (char **));
5536 if (addr_start != (*address))
5539 for (i = 0; i < sals->nelts; i++)
5541 /* Add the string if not present. */
5542 if ((*addr_string)[i] == NULL)
5543 (*addr_string)[i] = savestring (addr_start, (*address) - addr_start);
5549 /* Convert each SAL into a real PC. Verify that the PC can be
5550 inserted as a breakpoint. If it can't throw an error. */
5553 breakpoint_sals_to_pc (struct symtabs_and_lines *sals,
5557 for (i = 0; i < sals->nelts; i++)
5558 resolve_sal_pc (&sals->sals[i]);
5562 do_captured_parse_breakpoint (struct ui_out *ui, void *data)
5564 struct captured_parse_breakpoint_args *args = data;
5566 parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p,
5567 args->not_found_ptr);
5570 /* Given TOK, a string specification of condition and thread, as
5571 accepted by the 'break' command, extract the condition
5572 string and thread number and set *COND_STRING and *THREAD.
5573 PC identifies the context at which the condition should be parsed.
5574 If no condition is found, *COND_STRING is set to NULL.
5575 If no thread is found, *THREAD is set to -1. */
5577 find_condition_and_thread (char *tok, CORE_ADDR pc,
5578 char **cond_string, int *thread, int *task)
5580 *cond_string = NULL;
5586 char *cond_start = NULL;
5587 char *cond_end = NULL;
5588 while (*tok == ' ' || *tok == '\t')
5593 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
5596 toklen = end_tok - tok;
5598 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
5600 struct expression *expr;
5602 tok = cond_start = end_tok + 1;
5603 expr = parse_exp_1 (&tok, block_for_pc (pc), 0);
5606 *cond_string = savestring (cond_start,
5607 cond_end - cond_start);
5609 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
5615 *thread = strtol (tok, &tok, 0);
5617 error (_("Junk after thread keyword."));
5618 if (!valid_thread_id (*thread))
5619 error (_("Unknown thread %d."), *thread);
5621 else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0)
5627 *task = strtol (tok, &tok, 0);
5629 error (_("Junk after task keyword."));
5630 if (!valid_task_id (*task))
5631 error (_("Unknown task %d\n"), *task);
5634 error (_("Junk at end of arguments."));
5638 /* Set a breakpoint. This function is shared between
5639 CLI and MI functions for setting a breakpoint.
5640 This function has two major modes of operations,
5641 selected by the PARSE_CONDITION_AND_THREAD parameter.
5642 If non-zero, the function will parse arg, extracting
5643 breakpoint location, address and thread. Otherwise,
5644 ARG is just the location of breakpoint, with condition
5645 and thread specified by the COND_STRING and THREAD
5649 break_command_really (char *arg, char *cond_string, int thread,
5650 int parse_condition_and_thread,
5651 int tempflag, int hardwareflag, int traceflag,
5653 enum auto_boolean pending_break_support,
5654 struct breakpoint_ops *ops,
5658 struct gdb_exception e;
5659 struct symtabs_and_lines sals;
5660 struct symtab_and_line pending_sal;
5663 char *addr_start = arg;
5665 struct cleanup *old_chain;
5666 struct cleanup *breakpoint_chain = NULL;
5667 struct captured_parse_breakpoint_args parse_args;
5671 enum bptype type_wanted;
5678 parse_args.arg_p = &arg;
5679 parse_args.sals_p = &sals;
5680 parse_args.addr_string_p = &addr_string;
5681 parse_args.not_found_ptr = ¬_found;
5683 e = catch_exception (uiout, do_captured_parse_breakpoint,
5684 &parse_args, RETURN_MASK_ALL);
5686 /* If caller is interested in rc value from parse, set value. */
5690 throw_exception (e);
5694 case NOT_FOUND_ERROR:
5696 /* If pending breakpoint support is turned off, throw
5699 if (pending_break_support == AUTO_BOOLEAN_FALSE)
5700 throw_exception (e);
5702 exception_print (gdb_stderr, e);
5704 /* If pending breakpoint support is auto query and the user
5705 selects no, then simply return the error code. */
5706 if (pending_break_support == AUTO_BOOLEAN_AUTO &&
5707 !nquery ("Make breakpoint pending on future shared library load? "))
5710 /* At this point, either the user was queried about setting
5711 a pending breakpoint and selected yes, or pending
5712 breakpoint behavior is on and thus a pending breakpoint
5713 is defaulted on behalf of the user. */
5714 copy_arg = xstrdup (addr_start);
5715 addr_string = ©_arg;
5717 sals.sals = &pending_sal;
5722 throw_exception (e);
5729 /* Create a chain of things that always need to be cleaned up. */
5730 old_chain = make_cleanup (null_cleanup, 0);
5734 /* Make sure that all storage allocated to SALS gets freed. */
5735 make_cleanup (xfree, sals.sals);
5737 /* Cleanup the addr_string array but not its contents. */
5738 make_cleanup (xfree, addr_string);
5741 /* ----------------------------- SNIP -----------------------------
5742 Anything added to the cleanup chain beyond this point is assumed
5743 to be part of a breakpoint. If the breakpoint create succeeds
5744 then the memory is not reclaimed. */
5745 breakpoint_chain = make_cleanup (null_cleanup, 0);
5747 /* Mark the contents of the addr_string for cleanup. These go on
5748 the breakpoint_chain and only occure if the breakpoint create
5750 for (i = 0; i < sals.nelts; i++)
5752 if (addr_string[i] != NULL)
5753 make_cleanup (xfree, addr_string[i]);
5756 /* Resolve all line numbers to PC's and verify that the addresses
5757 are ok for the target. */
5759 breakpoint_sals_to_pc (&sals, addr_start);
5761 type_wanted = (traceflag
5763 : (hardwareflag ? bp_hardware_breakpoint : bp_breakpoint));
5765 /* Verify that condition can be parsed, before setting any
5766 breakpoints. Allocate a separate condition expression for each
5770 if (parse_condition_and_thread)
5772 /* Here we only parse 'arg' to separate condition
5773 from thread number, so parsing in context of first
5774 sal is OK. When setting the breakpoint we'll
5775 re-parse it in context of each sal. */
5778 find_condition_and_thread (arg, sals.sals[0].pc, &cond_string,
5781 make_cleanup (xfree, cond_string);
5785 /* Create a private copy of condition string. */
5788 cond_string = xstrdup (cond_string);
5789 make_cleanup (xfree, cond_string);
5792 create_breakpoints (sals, addr_string, cond_string, type_wanted,
5793 tempflag ? disp_del : disp_donttouch,
5794 thread, task, ignore_count, ops, from_tty, enabled);
5798 struct symtab_and_line sal = {0};
5799 struct breakpoint *b;
5801 make_cleanup (xfree, copy_arg);
5803 b = set_raw_breakpoint_without_location (type_wanted);
5804 set_breakpoint_count (breakpoint_count + 1);
5805 b->number = breakpoint_count;
5807 b->addr_string = addr_string[0];
5808 b->cond_string = NULL;
5809 b->ignore_count = ignore_count;
5810 b->disposition = tempflag ? disp_del : disp_donttouch;
5811 b->condition_not_parsed = 1;
5813 b->enable_state = enabled ? bp_enabled : bp_disabled;
5819 warning (_("Multiple breakpoints were set.\n"
5820 "Use the \"delete\" command to delete unwanted breakpoints."));
5821 /* That's it. Discard the cleanups for data inserted into the
5823 discard_cleanups (breakpoint_chain);
5824 /* But cleanup everything else. */
5825 do_cleanups (old_chain);
5827 /* error call may happen here - have BREAKPOINT_CHAIN already discarded. */
5828 update_global_location_list (1);
5831 /* Set a breakpoint.
5832 ARG is a string describing breakpoint address,
5833 condition, and thread.
5834 FLAG specifies if a breakpoint is hardware on,
5835 and if breakpoint is temporary, using BP_HARDWARE_FLAG
5839 break_command_1 (char *arg, int flag, int from_tty)
5841 int hardwareflag = flag & BP_HARDWAREFLAG;
5842 int tempflag = flag & BP_TEMPFLAG;
5844 break_command_really (arg,
5845 NULL, 0, 1 /* parse arg */,
5846 tempflag, hardwareflag, 0 /* traceflag */,
5847 0 /* Ignore count */,
5848 pending_break_support,
5849 NULL /* breakpoint_ops */,
5856 set_breakpoint (char *address, char *condition,
5857 int hardwareflag, int tempflag,
5858 int thread, int ignore_count,
5859 int pending, int enabled)
5861 break_command_really (address, condition, thread,
5862 0 /* condition and thread are valid. */,
5863 tempflag, hardwareflag, 0 /* traceflag */,
5866 ? AUTO_BOOLEAN_TRUE : AUTO_BOOLEAN_FALSE,
5870 /* Adjust SAL to the first instruction past the function prologue.
5871 The end of the prologue is determined using the line table from
5872 the debugging information.
5874 If SAL is already past the prologue, then do nothing. */
5877 skip_prologue_sal (struct symtab_and_line *sal)
5879 struct symbol *sym = find_pc_function (sal->pc);
5880 struct symtab_and_line start_sal;
5885 start_sal = find_function_start_sal (sym, 1);
5886 if (sal->pc < start_sal.pc)
5890 /* Helper function for break_command_1 and disassemble_command. */
5893 resolve_sal_pc (struct symtab_and_line *sal)
5897 if (sal->pc == 0 && sal->symtab != NULL)
5899 if (!find_line_pc (sal->symtab, sal->line, &pc))
5900 error (_("No line %d in file \"%s\"."),
5901 sal->line, sal->symtab->filename);
5904 /* If this SAL corresponds to a breakpoint inserted using
5905 a line number, then skip the function prologue if necessary. */
5906 if (sal->explicit_line)
5908 /* Preserve the original line number. */
5909 int saved_line = sal->line;
5910 skip_prologue_sal (sal);
5911 sal->line = saved_line;
5915 if (sal->section == 0 && sal->symtab != NULL)
5917 struct blockvector *bv;
5921 bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab);
5924 sym = block_linkage_function (b);
5927 fixup_symbol_section (sym, sal->symtab->objfile);
5928 sal->section = SYMBOL_OBJ_SECTION (sym);
5932 /* It really is worthwhile to have the section, so we'll just
5933 have to look harder. This case can be executed if we have
5934 line numbers but no functions (as can happen in assembly
5937 struct minimal_symbol *msym;
5939 msym = lookup_minimal_symbol_by_pc (sal->pc);
5941 sal->section = SYMBOL_OBJ_SECTION (msym);
5948 break_command (char *arg, int from_tty)
5950 break_command_1 (arg, 0, from_tty);
5954 tbreak_command (char *arg, int from_tty)
5956 break_command_1 (arg, BP_TEMPFLAG, from_tty);
5960 hbreak_command (char *arg, int from_tty)
5962 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
5966 thbreak_command (char *arg, int from_tty)
5968 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
5972 stop_command (char *arg, int from_tty)
5974 printf_filtered (_("Specify the type of breakpoint to set.\n\
5975 Usage: stop in <function | address>\n\
5976 stop at <line>\n"));
5980 stopin_command (char *arg, int from_tty)
5984 if (arg == (char *) NULL)
5986 else if (*arg != '*')
5991 /* look for a ':'. If this is a line number specification, then
5992 say it is bad, otherwise, it should be an address or
5993 function/method name */
5994 while (*argptr && !hasColon)
5996 hasColon = (*argptr == ':');
6001 badInput = (*argptr != ':'); /* Not a class::method */
6003 badInput = isdigit (*arg); /* a simple line number */
6007 printf_filtered (_("Usage: stop in <function | address>\n"));
6009 break_command_1 (arg, 0, from_tty);
6013 stopat_command (char *arg, int from_tty)
6017 if (arg == (char *) NULL || *arg == '*') /* no line number */
6024 /* look for a ':'. If there is a '::' then get out, otherwise
6025 it is probably a line number. */
6026 while (*argptr && !hasColon)
6028 hasColon = (*argptr == ':');
6033 badInput = (*argptr == ':'); /* we have class::method */
6035 badInput = !isdigit (*arg); /* not a line number */
6039 printf_filtered (_("Usage: stop at <line>\n"));
6041 break_command_1 (arg, 0, from_tty);
6044 /* accessflag: hw_write: watch write,
6045 hw_read: watch read,
6046 hw_access: watch access (read or write) */
6048 watch_command_1 (char *arg, int accessflag, int from_tty)
6050 struct breakpoint *b, *scope_breakpoint = NULL;
6051 struct symtab_and_line sal;
6052 struct expression *exp;
6053 struct block *exp_valid_block;
6054 struct value *val, *mark;
6055 struct frame_info *frame;
6056 struct frame_info *prev_frame = NULL;
6057 char *exp_start = NULL;
6058 char *exp_end = NULL;
6059 char *tok, *id_tok_start, *end_tok;
6061 char *cond_start = NULL;
6062 char *cond_end = NULL;
6063 struct expression *cond = NULL;
6064 int i, other_type_used, target_resources_ok = 0;
6065 enum bptype bp_type;
6069 init_sal (&sal); /* initialize to zeroes */
6071 /* Make sure that we actually have parameters to parse. */
6072 if (arg != NULL && arg[0] != '\0')
6074 toklen = strlen (arg); /* Size of argument list. */
6076 /* Points tok to the end of the argument list. */
6077 tok = arg + toklen - 1;
6079 /* Go backwards in the parameters list. Skip the last parameter.
6080 If we're expecting a 'thread <thread_num>' parameter, this should
6081 be the thread identifier. */
6082 while (tok > arg && (*tok == ' ' || *tok == '\t'))
6084 while (tok > arg && (*tok != ' ' && *tok != '\t'))
6087 /* Points end_tok to the beginning of the last token. */
6088 id_tok_start = tok + 1;
6090 /* Go backwards in the parameters list. Skip one more parameter.
6091 If we're expecting a 'thread <thread_num>' parameter, we should
6092 reach a "thread" token. */
6093 while (tok > arg && (*tok == ' ' || *tok == '\t'))
6098 while (tok > arg && (*tok != ' ' && *tok != '\t'))
6101 /* Move the pointer forward to skip the whitespace and
6102 calculate the length of the token. */
6104 toklen = end_tok - tok;
6106 if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
6108 /* At this point we've found a "thread" token, which means
6109 the user is trying to set a watchpoint that triggers
6110 only in a specific thread. */
6113 /* Extract the thread ID from the next token. */
6114 thread = strtol (id_tok_start, &endp, 0);
6116 /* Check if the user provided a valid numeric value for the
6118 if (*endp != ' ' && *endp != '\t' && *endp != '\0')
6119 error (_("Invalid thread ID specification %s."), id_tok_start);
6121 /* Check if the thread actually exists. */
6122 if (!valid_thread_id (thread))
6123 error (_("Unknown thread %d."), thread);
6125 /* Truncate the string and get rid of the thread <thread_num>
6126 parameter before the parameter list is parsed by the
6127 evaluate_expression() function. */
6132 /* Parse the rest of the arguments. */
6133 innermost_block = NULL;
6135 exp = parse_exp_1 (&arg, 0, 0);
6137 /* Remove trailing whitespace from the expression before saving it.
6138 This makes the eventual display of the expression string a bit
6140 while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t'))
6143 exp_valid_block = innermost_block;
6144 mark = value_mark ();
6145 fetch_watchpoint_value (exp, &val, NULL, NULL);
6147 release_value (val);
6150 while (*tok == ' ' || *tok == '\t')
6154 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
6157 toklen = end_tok - tok;
6158 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
6160 tok = cond_start = end_tok + 1;
6161 cond = parse_exp_1 (&tok, 0, 0);
6165 error (_("Junk at end of command."));
6167 if (accessflag == hw_read)
6168 bp_type = bp_read_watchpoint;
6169 else if (accessflag == hw_access)
6170 bp_type = bp_access_watchpoint;
6172 bp_type = bp_hardware_watchpoint;
6174 mem_cnt = can_use_hardware_watchpoint (val);
6175 if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
6176 error (_("Expression cannot be implemented with read/access watchpoint."));
6179 i = hw_watchpoint_used_count (bp_type, &other_type_used);
6180 target_resources_ok =
6181 target_can_use_hardware_watchpoint (bp_type, i + mem_cnt,
6183 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
6184 error (_("Target does not support this type of hardware watchpoint."));
6186 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
6187 error (_("Target can only support one kind of HW watchpoint at a time."));
6190 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
6191 watchpoint could not be set. */
6192 if (!mem_cnt || target_resources_ok <= 0)
6193 bp_type = bp_watchpoint;
6195 frame = block_innermost_frame (exp_valid_block);
6197 prev_frame = get_prev_frame (frame);
6201 /* If the expression is "local", then set up a "watchpoint scope"
6202 breakpoint at the point where we've left the scope of the watchpoint
6203 expression. Create the scope breakpoint before the watchpoint, so
6204 that we will encounter it first in bpstat_stop_status. */
6205 if (innermost_block && prev_frame)
6207 scope_breakpoint = create_internal_breakpoint (get_frame_pc (prev_frame),
6208 bp_watchpoint_scope);
6210 scope_breakpoint->enable_state = bp_enabled;
6212 /* Automatically delete the breakpoint when it hits. */
6213 scope_breakpoint->disposition = disp_del;
6215 /* Only break in the proper frame (help with recursion). */
6216 scope_breakpoint->frame_id = get_frame_id (prev_frame);
6218 /* Set the address at which we will stop. */
6219 scope_breakpoint->loc->requested_address
6220 = get_frame_pc (prev_frame);
6221 scope_breakpoint->loc->address
6222 = adjust_breakpoint_address (scope_breakpoint->loc->requested_address,
6223 scope_breakpoint->type);
6226 /* Now set up the breakpoint. */
6227 b = set_raw_breakpoint (sal, bp_type);
6228 set_breakpoint_count (breakpoint_count + 1);
6229 b->number = breakpoint_count;
6231 b->disposition = disp_donttouch;
6233 b->exp_valid_block = exp_valid_block;
6234 b->exp_string = savestring (exp_start, exp_end - exp_start);
6237 b->loc->cond = cond;
6239 b->cond_string = savestring (cond_start, cond_end - cond_start);
6244 b->watchpoint_frame = get_frame_id (frame);
6246 b->watchpoint_frame = null_frame_id;
6248 if (scope_breakpoint != NULL)
6250 /* The scope breakpoint is related to the watchpoint. We will
6251 need to act on them together. */
6252 b->related_breakpoint = scope_breakpoint;
6253 scope_breakpoint->related_breakpoint = b;
6256 value_free_to_mark (mark);
6258 update_global_location_list (1);
6261 /* Return count of locations need to be watched and can be handled
6262 in hardware. If the watchpoint can not be handled
6263 in hardware return zero. */
6266 can_use_hardware_watchpoint (struct value *v)
6268 int found_memory_cnt = 0;
6269 struct value *head = v;
6271 /* Did the user specifically forbid us to use hardware watchpoints? */
6272 if (!can_use_hw_watchpoints)
6275 /* Make sure that the value of the expression depends only upon
6276 memory contents, and values computed from them within GDB. If we
6277 find any register references or function calls, we can't use a
6278 hardware watchpoint.
6280 The idea here is that evaluating an expression generates a series
6281 of values, one holding the value of every subexpression. (The
6282 expression a*b+c has five subexpressions: a, b, a*b, c, and
6283 a*b+c.) GDB's values hold almost enough information to establish
6284 the criteria given above --- they identify memory lvalues,
6285 register lvalues, computed values, etcetera. So we can evaluate
6286 the expression, and then scan the chain of values that leaves
6287 behind to decide whether we can detect any possible change to the
6288 expression's final value using only hardware watchpoints.
6290 However, I don't think that the values returned by inferior
6291 function calls are special in any way. So this function may not
6292 notice that an expression involving an inferior function call
6293 can't be watched with hardware watchpoints. FIXME. */
6294 for (; v; v = value_next (v))
6296 if (VALUE_LVAL (v) == lval_memory)
6299 /* A lazy memory lvalue is one that GDB never needed to fetch;
6300 we either just used its address (e.g., `a' in `a.b') or
6301 we never needed it at all (e.g., `a' in `a,b'). */
6305 /* Ahh, memory we actually used! Check if we can cover
6306 it with hardware watchpoints. */
6307 struct type *vtype = check_typedef (value_type (v));
6309 /* We only watch structs and arrays if user asked for it
6310 explicitly, never if they just happen to appear in a
6311 middle of some value chain. */
6313 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
6314 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
6316 CORE_ADDR vaddr = VALUE_ADDRESS (v) + value_offset (v);
6317 int len = TYPE_LENGTH (value_type (v));
6319 if (!target_region_ok_for_hw_watchpoint (vaddr, len))
6326 else if (VALUE_LVAL (v) != not_lval
6327 && deprecated_value_modifiable (v) == 0)
6328 return 0; /* ??? What does this represent? */
6329 else if (VALUE_LVAL (v) == lval_register)
6330 return 0; /* cannot watch a register with a HW watchpoint */
6333 /* The expression itself looks suitable for using a hardware
6334 watchpoint, but give the target machine a chance to reject it. */
6335 return found_memory_cnt;
6339 watch_command_wrapper (char *arg, int from_tty)
6341 watch_command (arg, from_tty);
6345 watch_command (char *arg, int from_tty)
6347 watch_command_1 (arg, hw_write, from_tty);
6351 rwatch_command_wrapper (char *arg, int from_tty)
6353 rwatch_command (arg, from_tty);
6357 rwatch_command (char *arg, int from_tty)
6359 watch_command_1 (arg, hw_read, from_tty);
6363 awatch_command_wrapper (char *arg, int from_tty)
6365 awatch_command (arg, from_tty);
6369 awatch_command (char *arg, int from_tty)
6371 watch_command_1 (arg, hw_access, from_tty);
6375 /* Helper routines for the until_command routine in infcmd.c. Here
6376 because it uses the mechanisms of breakpoints. */
6378 struct until_break_command_continuation_args
6380 struct breakpoint *breakpoint;
6381 struct breakpoint *breakpoint2;
6384 /* This function is called by fetch_inferior_event via the
6385 cmd_continuation pointer, to complete the until command. It takes
6386 care of cleaning up the temporary breakpoints set up by the until
6389 until_break_command_continuation (void *arg)
6391 struct until_break_command_continuation_args *a = arg;
6393 delete_breakpoint (a->breakpoint);
6395 delete_breakpoint (a->breakpoint2);
6399 until_break_command (char *arg, int from_tty, int anywhere)
6401 struct symtabs_and_lines sals;
6402 struct symtab_and_line sal;
6403 struct frame_info *frame = get_selected_frame (NULL);
6404 struct frame_info *prev_frame = get_prev_frame (frame);
6405 struct breakpoint *breakpoint;
6406 struct breakpoint *breakpoint2 = NULL;
6407 struct cleanup *old_chain;
6409 clear_proceed_status ();
6411 /* Set a breakpoint where the user wants it and at return from
6414 if (default_breakpoint_valid)
6415 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
6416 default_breakpoint_line, (char ***) NULL, NULL);
6418 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL,
6419 0, (char ***) NULL, NULL);
6421 if (sals.nelts != 1)
6422 error (_("Couldn't get information on specified line."));
6425 xfree (sals.sals); /* malloc'd, so freed */
6428 error (_("Junk at end of arguments."));
6430 resolve_sal_pc (&sal);
6433 /* If the user told us to continue until a specified location,
6434 we don't specify a frame at which we need to stop. */
6435 breakpoint = set_momentary_breakpoint (sal, null_frame_id, bp_until);
6437 /* Otherwise, specify the current frame, because we want to stop only
6438 at the very same frame. */
6439 breakpoint = set_momentary_breakpoint (sal, get_frame_id (frame),
6442 old_chain = make_cleanup_delete_breakpoint (breakpoint);
6444 /* Keep within the current frame, or in frames called by the current
6448 sal = find_pc_line (get_frame_pc (prev_frame), 0);
6449 sal.pc = get_frame_pc (prev_frame);
6450 breakpoint2 = set_momentary_breakpoint (sal, get_frame_id (prev_frame),
6452 make_cleanup_delete_breakpoint (breakpoint2);
6455 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
6457 /* If we are running asynchronously, and proceed call above has actually
6458 managed to start the target, arrange for breakpoints to be
6459 deleted when the target stops. Otherwise, we're already stopped and
6460 delete breakpoints via cleanup chain. */
6462 if (target_can_async_p () && is_running (inferior_ptid))
6464 struct until_break_command_continuation_args *args;
6465 args = xmalloc (sizeof (*args));
6467 args->breakpoint = breakpoint;
6468 args->breakpoint2 = breakpoint2;
6470 discard_cleanups (old_chain);
6471 add_continuation (inferior_thread (),
6472 until_break_command_continuation, args,
6476 do_cleanups (old_chain);
6480 ep_skip_leading_whitespace (char **s)
6482 if ((s == NULL) || (*s == NULL))
6484 while (isspace (**s))
6488 /* This function attempts to parse an optional "if <cond>" clause
6489 from the arg string. If one is not found, it returns NULL.
6491 Else, it returns a pointer to the condition string. (It does not
6492 attempt to evaluate the string against a particular block.) And,
6493 it updates arg to point to the first character following the parsed
6494 if clause in the arg string. */
6497 ep_parse_optional_if_clause (char **arg)
6501 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
6504 /* Skip the "if" keyword. */
6507 /* Skip any extra leading whitespace, and record the start of the
6508 condition string. */
6509 ep_skip_leading_whitespace (arg);
6512 /* Assume that the condition occupies the remainder of the arg string. */
6513 (*arg) += strlen (cond_string);
6518 /* This function attempts to parse an optional filename from the arg
6519 string. If one is not found, it returns NULL.
6521 Else, it returns a pointer to the parsed filename. (This function
6522 makes no attempt to verify that a file of that name exists, or is
6523 accessible.) And, it updates arg to point to the first character
6524 following the parsed filename in the arg string.
6526 Note that clients needing to preserve the returned filename for
6527 future access should copy it to their own buffers. */
6529 ep_parse_optional_filename (char **arg)
6531 static char filename[1024];
6536 if ((*arg_p == '\0') || isspace (*arg_p))
6554 /* Commands to deal with catching events, such as signals, exceptions,
6555 process start/exit, etc. */
6559 catch_fork_temporary, catch_vfork_temporary,
6560 catch_fork_permanent, catch_vfork_permanent
6565 catch_fork_command_1 (char *arg, int from_tty, struct cmd_list_element *command)
6567 char *cond_string = NULL;
6568 catch_fork_kind fork_kind;
6571 fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command);
6572 tempflag = (fork_kind == catch_fork_temporary
6573 || fork_kind == catch_vfork_temporary);
6577 ep_skip_leading_whitespace (&arg);
6579 /* The allowed syntax is:
6581 catch [v]fork if <cond>
6583 First, check if there's an if clause. */
6584 cond_string = ep_parse_optional_if_clause (&arg);
6586 if ((*arg != '\0') && !isspace (*arg))
6587 error (_("Junk at end of arguments."));
6589 /* If this target supports it, create a fork or vfork catchpoint
6590 and enable reporting of such events. */
6593 case catch_fork_temporary:
6594 case catch_fork_permanent:
6595 create_fork_vfork_event_catchpoint (tempflag, cond_string,
6596 &catch_fork_breakpoint_ops);
6598 case catch_vfork_temporary:
6599 case catch_vfork_permanent:
6600 create_fork_vfork_event_catchpoint (tempflag, cond_string,
6601 &catch_vfork_breakpoint_ops);
6604 error (_("unsupported or unknown fork kind; cannot catch it"));
6610 catch_exec_command_1 (char *arg, int from_tty, struct cmd_list_element *command)
6613 char *cond_string = NULL;
6615 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
6619 ep_skip_leading_whitespace (&arg);
6621 /* The allowed syntax is:
6623 catch exec if <cond>
6625 First, check if there's an if clause. */
6626 cond_string = ep_parse_optional_if_clause (&arg);
6628 if ((*arg != '\0') && !isspace (*arg))
6629 error (_("Junk at end of arguments."));
6631 /* If this target supports it, create an exec catchpoint
6632 and enable reporting of such events. */
6633 create_catchpoint (tempflag, cond_string, &catch_exec_breakpoint_ops);
6636 static enum print_stop_action
6637 print_exception_catchpoint (struct breakpoint *b)
6639 int bp_temp, bp_throw;
6641 annotate_catchpoint (b->number);
6643 bp_throw = strstr (b->addr_string, "throw") != NULL;
6644 if (b->loc->address != b->loc->requested_address)
6645 breakpoint_adjustment_warning (b->loc->requested_address,
6648 bp_temp = b->disposition == disp_del;
6650 bp_temp ? "Temporary catchpoint "
6652 if (!ui_out_is_mi_like_p (uiout))
6653 ui_out_field_int (uiout, "bkptno", b->number);
6655 bp_throw ? " (exception thrown), "
6656 : " (exception caught), ");
6657 if (ui_out_is_mi_like_p (uiout))
6659 ui_out_field_string (uiout, "reason",
6660 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
6661 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
6662 ui_out_field_int (uiout, "bkptno", b->number);
6664 return PRINT_SRC_AND_LOC;
6668 print_one_exception_catchpoint (struct breakpoint *b, CORE_ADDR *last_addr)
6670 struct value_print_options opts;
6671 get_user_print_options (&opts);
6672 if (opts.addressprint)
6675 if (b->loc == NULL || b->loc->shlib_disabled)
6676 ui_out_field_string (uiout, "addr", "<PENDING>");
6678 ui_out_field_core_addr (uiout, "addr", b->loc->address);
6682 *last_addr = b->loc->address;
6683 if (strstr (b->addr_string, "throw") != NULL)
6684 ui_out_field_string (uiout, "what", "exception throw");
6686 ui_out_field_string (uiout, "what", "exception catch");
6690 print_mention_exception_catchpoint (struct breakpoint *b)
6695 bp_temp = b->disposition == disp_del;
6696 bp_throw = strstr (b->addr_string, "throw") != NULL;
6697 ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ")
6698 : _("Catchpoint "));
6699 ui_out_field_int (uiout, "bkptno", b->number);
6700 ui_out_text (uiout, bp_throw ? _(" (throw)")
6704 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = {
6707 NULL, /* breakpoint_hit */
6708 print_exception_catchpoint,
6709 print_one_exception_catchpoint,
6710 print_mention_exception_catchpoint
6714 handle_gnu_v3_exceptions (int tempflag, char *cond_string,
6715 enum exception_event_kind ex_event, int from_tty)
6717 char *trigger_func_name;
6719 if (ex_event == EX_EVENT_CATCH)
6720 trigger_func_name = "__cxa_begin_catch";
6722 trigger_func_name = "__cxa_throw";
6724 break_command_really (trigger_func_name, cond_string, -1,
6725 0 /* condition and thread are valid. */,
6728 AUTO_BOOLEAN_TRUE /* pending */,
6729 &gnu_v3_exception_catchpoint_ops, from_tty,
6735 /* Deal with "catch catch" and "catch throw" commands */
6738 catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
6739 int tempflag, int from_tty)
6741 char *cond_string = NULL;
6742 struct symtab_and_line *sal = NULL;
6746 ep_skip_leading_whitespace (&arg);
6748 cond_string = ep_parse_optional_if_clause (&arg);
6750 if ((*arg != '\0') && !isspace (*arg))
6751 error (_("Junk at end of arguments."));
6753 if ((ex_event != EX_EVENT_THROW) &&
6754 (ex_event != EX_EVENT_CATCH))
6755 error (_("Unsupported or unknown exception event; cannot catch it"));
6757 if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty))
6760 warning (_("Unsupported with this platform/compiler combination."));
6763 /* Implementation of "catch catch" command. */
6766 catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command)
6768 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
6769 catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty);
6772 /* Implementation of "catch throw" command. */
6775 catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command)
6777 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
6778 catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty);
6781 /* Create a breakpoint struct for Ada exception catchpoints. */
6784 create_ada_exception_breakpoint (struct symtab_and_line sal,
6788 struct expression *cond,
6789 struct breakpoint_ops *ops,
6793 struct breakpoint *b;
6797 describe_other_breakpoints (sal.pc, sal.section, -1);
6798 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
6799 version for exception catchpoints, because two catchpoints
6800 used for different exception names will use the same address.
6801 In this case, a "breakpoint ... also set at..." warning is
6802 unproductive. Besides. the warning phrasing is also a bit
6803 inapropriate, we should use the word catchpoint, and tell
6804 the user what type of catchpoint it is. The above is good
6805 enough for now, though. */
6808 b = set_raw_breakpoint (sal, bp_breakpoint);
6809 set_breakpoint_count (breakpoint_count + 1);
6811 b->enable_state = bp_enabled;
6812 b->disposition = tempflag ? disp_del : disp_donttouch;
6813 b->number = breakpoint_count;
6814 b->ignore_count = 0;
6815 b->loc->cond = cond;
6816 b->addr_string = addr_string;
6817 b->language = language_ada;
6818 b->cond_string = cond_string;
6819 b->exp_string = exp_string;
6824 update_global_location_list (1);
6827 /* Implement the "catch exception" command. */
6830 catch_ada_exception_command (char *arg, int from_tty,
6831 struct cmd_list_element *command)
6834 struct symtab_and_line sal;
6836 char *addr_string = NULL;
6837 char *exp_string = NULL;
6838 char *cond_string = NULL;
6839 struct expression *cond = NULL;
6840 struct breakpoint_ops *ops = NULL;
6842 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
6846 sal = ada_decode_exception_location (arg, &addr_string, &exp_string,
6847 &cond_string, &cond, &ops);
6848 create_ada_exception_breakpoint (sal, addr_string, exp_string,
6849 cond_string, cond, ops, tempflag,
6853 /* Implement the "catch assert" command. */
6856 catch_assert_command (char *arg, int from_tty, struct cmd_list_element *command)
6859 struct symtab_and_line sal;
6860 char *addr_string = NULL;
6861 struct breakpoint_ops *ops = NULL;
6863 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
6867 sal = ada_decode_assert_location (arg, &addr_string, &ops);
6868 create_ada_exception_breakpoint (sal, addr_string, NULL, NULL, NULL, ops,
6869 tempflag, from_tty);
6873 catch_command (char *arg, int from_tty)
6875 error (_("Catch requires an event name."));
6880 tcatch_command (char *arg, int from_tty)
6882 error (_("Catch requires an event name."));
6885 /* Delete breakpoints by address or line. */
6888 clear_command (char *arg, int from_tty)
6890 struct breakpoint *b;
6891 VEC(breakpoint_p) *found = 0;
6894 struct symtabs_and_lines sals;
6895 struct symtab_and_line sal;
6900 sals = decode_line_spec (arg, 1);
6905 sals.sals = (struct symtab_and_line *)
6906 xmalloc (sizeof (struct symtab_and_line));
6907 make_cleanup (xfree, sals.sals);
6908 init_sal (&sal); /* initialize to zeroes */
6909 sal.line = default_breakpoint_line;
6910 sal.symtab = default_breakpoint_symtab;
6911 sal.pc = default_breakpoint_address;
6912 if (sal.symtab == 0)
6913 error (_("No source file specified."));
6921 /* We don't call resolve_sal_pc here. That's not
6922 as bad as it seems, because all existing breakpoints
6923 typically have both file/line and pc set. So, if
6924 clear is given file/line, we can match this to existing
6925 breakpoint without obtaining pc at all.
6927 We only support clearing given the address explicitly
6928 present in breakpoint table. Say, we've set breakpoint
6929 at file:line. There were several PC values for that file:line,
6930 due to optimization, all in one block.
6931 We've picked one PC value. If "clear" is issued with another
6932 PC corresponding to the same file:line, the breakpoint won't
6933 be cleared. We probably can still clear the breakpoint, but
6934 since the other PC value is never presented to user, user
6935 can only find it by guessing, and it does not seem important
6938 /* For each line spec given, delete bps which correspond
6939 to it. Do it in two passes, solely to preserve the current
6940 behavior that from_tty is forced true if we delete more than
6944 for (i = 0; i < sals.nelts; i++)
6946 /* If exact pc given, clear bpts at that pc.
6947 If line given (pc == 0), clear all bpts on specified line.
6948 If defaulting, clear all bpts on default line
6951 defaulting sal.pc != 0 tests to do
6956 1 0 <can't happen> */
6960 /* Find all matching breakpoints and add them to
6965 /* Are we going to delete b? */
6966 if (b->type != bp_none
6967 && b->type != bp_watchpoint
6968 && b->type != bp_hardware_watchpoint
6969 && b->type != bp_read_watchpoint
6970 && b->type != bp_access_watchpoint)
6972 struct bp_location *loc = b->loc;
6973 for (; loc; loc = loc->next)
6975 int pc_match = sal.pc
6976 && (loc->address == sal.pc)
6977 && (!section_is_overlay (loc->section)
6978 || loc->section == sal.section);
6979 int line_match = ((default_match || (0 == sal.pc))
6980 && b->source_file != NULL
6981 && sal.symtab != NULL
6982 && strcmp (b->source_file, sal.symtab->filename) == 0
6983 && b->line_number == sal.line);
6984 if (pc_match || line_match)
6993 VEC_safe_push(breakpoint_p, found, b);
6996 /* Now go thru the 'found' chain and delete them. */
6997 if (VEC_empty(breakpoint_p, found))
7000 error (_("No breakpoint at %s."), arg);
7002 error (_("No breakpoint at this line."));
7005 if (VEC_length(breakpoint_p, found) > 1)
7006 from_tty = 1; /* Always report if deleted more than one */
7009 if (VEC_length(breakpoint_p, found) == 1)
7010 printf_unfiltered (_("Deleted breakpoint "));
7012 printf_unfiltered (_("Deleted breakpoints "));
7014 breakpoints_changed ();
7016 for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++)
7019 printf_unfiltered ("%d ", b->number);
7020 delete_breakpoint (b);
7023 putchar_unfiltered ('\n');
7026 /* Delete breakpoint in BS if they are `delete' breakpoints and
7027 all breakpoints that are marked for deletion, whether hit or not.
7028 This is called after any breakpoint is hit, or after errors. */
7031 breakpoint_auto_delete (bpstat bs)
7033 struct breakpoint *b, *temp;
7035 for (; bs; bs = bs->next)
7036 if (bs->breakpoint_at
7037 && bs->breakpoint_at->owner
7038 && bs->breakpoint_at->owner->disposition == disp_del
7040 delete_breakpoint (bs->breakpoint_at->owner);
7042 ALL_BREAKPOINTS_SAFE (b, temp)
7044 if (b->disposition == disp_del_at_next_stop)
7045 delete_breakpoint (b);
7049 /* A cleanup function which destroys a vector. */
7052 do_vec_free (void *p)
7054 VEC(bp_location_p) **vec = p;
7056 VEC_free (bp_location_p, *vec);
7059 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
7060 into the inferior, only remove already-inserted locations that no
7061 longer should be inserted. Functions that delete a breakpoint or
7062 breakpoints should pass false, so that deleting a breakpoint
7063 doesn't have the side effect of inserting the locations of other
7064 breakpoints that are marked not-inserted, but should_be_inserted
7065 returns true on them.
7067 This behaviour is useful is situations close to tear-down -- e.g.,
7068 after an exec, while the target still has execution, but breakpoint
7069 shadows of the previous executable image should *NOT* be restored
7070 to the new image; or before detaching, where the target still has
7071 execution and wants to delete breakpoints from GDB's lists, and all
7072 breakpoints had already been removed from the inferior. */
7075 update_global_location_list (int should_insert)
7077 struct breakpoint *b;
7078 struct bp_location **next = &bp_location_chain;
7079 struct bp_location *loc;
7080 struct bp_location *loc2;
7081 VEC(bp_location_p) *old_locations = NULL;
7084 struct cleanup *cleanups;
7086 cleanups = make_cleanup (do_vec_free, &old_locations);
7087 /* Store old locations for future reference. */
7088 for (loc = bp_location_chain; loc; loc = loc->global_next)
7089 VEC_safe_push (bp_location_p, old_locations, loc);
7091 bp_location_chain = NULL;
7094 for (loc = b->loc; loc; loc = loc->next)
7097 next = &(loc->global_next);
7102 /* Identify bp_location instances that are no longer present in the new
7103 list, and therefore should be freed. Note that it's not necessary that
7104 those locations should be removed from inferior -- if there's another
7105 location at the same address (previously marked as duplicate),
7106 we don't need to remove/insert the location. */
7107 for (ix = 0; VEC_iterate(bp_location_p, old_locations, ix, loc); ++ix)
7109 /* Tells if 'loc' is found amoung the new locations. If not, we
7111 int found_object = 0;
7112 /* Tells if the location should remain inserted in the target. */
7113 int keep_in_target = 0;
7115 for (loc2 = bp_location_chain; loc2; loc2 = loc2->global_next)
7122 /* If this location is no longer present, and inserted, look if there's
7123 maybe a new location at the same address. If so, mark that one
7124 inserted, and don't remove this one. This is needed so that we
7125 don't have a time window where a breakpoint at certain location is not
7130 /* If the location is inserted now, we might have to remove it. */
7132 if (found_object && should_be_inserted (loc))
7134 /* The location is still present in the location list, and still
7135 should be inserted. Don't do anything. */
7140 /* The location is either no longer present, or got disabled.
7141 See if there's another location at the same address, in which
7142 case we don't need to remove this one from the target. */
7143 if (breakpoint_address_is_meaningful (loc->owner))
7144 for (loc2 = bp_location_chain; loc2; loc2 = loc2->global_next)
7146 /* For the sake of should_insert_location. The
7147 call to check_duplicates will fix up this later. */
7148 loc2->duplicate = 0;
7149 if (should_be_inserted (loc2)
7150 && loc2 != loc && loc2->address == loc->address)
7153 loc2->target_info = loc->target_info;
7160 if (!keep_in_target)
7162 if (remove_breakpoint (loc, mark_uninserted))
7164 /* This is just about all we can do. We could keep this
7165 location on the global list, and try to remove it next
7166 time, but there's no particular reason why we will
7169 Note that at this point, loc->owner is still valid,
7170 as delete_breakpoint frees the breakpoint only
7171 after calling us. */
7172 printf_filtered (_("warning: Error removing breakpoint %d\n"),
7173 loc->owner->number);
7181 if (removed && non_stop)
7183 /* This location was removed from the targets. In non-stop mode,
7184 a race condition is possible where we've removed a breakpoint,
7185 but stop events for that breakpoint are already queued and will
7186 arrive later. To suppress spurious SIGTRAPs reported to user,
7187 we keep this breakpoint location for a bit, and will retire it
7188 after we see 3 * thread_count events.
7189 The theory here is that reporting of events should,
7190 "on the average", be fair, so after that many event we'll see
7191 events from all threads that have anything of interest, and no
7192 longer need to keep this breakpoint. This is just a
7193 heuristic, but if it's wrong, we'll report unexpected SIGTRAP,
7194 which is usability issue, but not a correctness problem. */
7195 loc->events_till_retirement = 3 * (thread_count () + 1);
7198 VEC_safe_push (bp_location_p, moribund_locations, loc);
7201 free_bp_location (loc);
7207 check_duplicates (b);
7210 if (breakpoints_always_inserted_mode () && should_insert
7211 && (target_has_execution
7212 || (gdbarch_has_global_solist (target_gdbarch)
7213 && target_supports_multi_process ())))
7214 insert_breakpoint_locations ();
7216 do_cleanups (cleanups);
7220 breakpoint_retire_moribund (void)
7222 struct bp_location *loc;
7225 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
7226 if (--(loc->events_till_retirement) == 0)
7228 free_bp_location (loc);
7229 VEC_unordered_remove (bp_location_p, moribund_locations, ix);
7235 update_global_location_list_nothrow (int inserting)
7237 struct gdb_exception e;
7238 TRY_CATCH (e, RETURN_MASK_ERROR)
7239 update_global_location_list (inserting);
7242 /* Clear BPT from a BPS. */
7244 bpstat_remove_breakpoint (bpstat bps, struct breakpoint *bpt)
7247 for (bs = bps; bs; bs = bs->next)
7248 if (bs->breakpoint_at && bs->breakpoint_at->owner == bpt)
7250 bs->breakpoint_at = NULL;
7252 /* bs->commands will be freed later. */
7256 /* Callback for iterate_over_threads. */
7258 bpstat_remove_breakpoint_callback (struct thread_info *th, void *data)
7260 struct breakpoint *bpt = data;
7261 bpstat_remove_breakpoint (th->stop_bpstat, bpt);
7265 /* Delete a breakpoint and clean up all traces of it in the data
7269 delete_breakpoint (struct breakpoint *bpt)
7271 struct breakpoint *b;
7272 struct bp_location *loc, *next;
7274 gdb_assert (bpt != NULL);
7276 /* Has this bp already been deleted? This can happen because multiple
7277 lists can hold pointers to bp's. bpstat lists are especial culprits.
7279 One example of this happening is a watchpoint's scope bp. When the
7280 scope bp triggers, we notice that the watchpoint is out of scope, and
7281 delete it. We also delete its scope bp. But the scope bp is marked
7282 "auto-deleting", and is already on a bpstat. That bpstat is then
7283 checked for auto-deleting bp's, which are deleted.
7285 A real solution to this problem might involve reference counts in bp's,
7286 and/or giving them pointers back to their referencing bpstat's, and
7287 teaching delete_breakpoint to only free a bp's storage when no more
7288 references were extent. A cheaper bandaid was chosen. */
7289 if (bpt->type == bp_none)
7292 observer_notify_breakpoint_deleted (bpt->number);
7294 if (breakpoint_chain == bpt)
7295 breakpoint_chain = bpt->next;
7300 b->next = bpt->next;
7304 free_command_lines (&bpt->commands);
7305 if (bpt->cond_string != NULL)
7306 xfree (bpt->cond_string);
7307 if (bpt->addr_string != NULL)
7308 xfree (bpt->addr_string);
7309 if (bpt->exp != NULL)
7311 if (bpt->exp_string != NULL)
7312 xfree (bpt->exp_string);
7313 if (bpt->val != NULL)
7314 value_free (bpt->val);
7315 if (bpt->source_file != NULL)
7316 xfree (bpt->source_file);
7317 if (bpt->exec_pathname != NULL)
7318 xfree (bpt->exec_pathname);
7320 /* Be sure no bpstat's are pointing at it after it's been freed. */
7321 /* FIXME, how can we find all bpstat's?
7322 We just check stop_bpstat for now. Note that we cannot just
7323 remove bpstats pointing at bpt from the stop_bpstat list
7324 entirely, as breakpoint commands are associated with the bpstat;
7325 if we remove it here, then the later call to
7326 bpstat_do_actions (&stop_bpstat);
7327 in event-top.c won't do anything, and temporary breakpoints
7328 with commands won't work. */
7330 iterate_over_threads (bpstat_remove_breakpoint_callback, bpt);
7332 /* Now that breakpoint is removed from breakpoint
7333 list, update the global location list. This
7334 will remove locations that used to belong to
7335 this breakpoint. Do this before freeing
7336 the breakpoint itself, since remove_breakpoint
7337 looks at location's owner. It might be better
7338 design to have location completely self-contained,
7339 but it's not the case now. */
7340 update_global_location_list (0);
7343 /* On the chance that someone will soon try again to delete this same
7344 bp, we mark it as deleted before freeing its storage. */
7345 bpt->type = bp_none;
7351 do_delete_breakpoint_cleanup (void *b)
7353 delete_breakpoint (b);
7357 make_cleanup_delete_breakpoint (struct breakpoint *b)
7359 return make_cleanup (do_delete_breakpoint_cleanup, b);
7363 delete_command (char *arg, int from_tty)
7365 struct breakpoint *b, *temp;
7371 int breaks_to_delete = 0;
7373 /* Delete all breakpoints if no argument.
7374 Do not delete internal or call-dummy breakpoints, these
7375 have to be deleted with an explicit breakpoint number argument. */
7378 if (b->type != bp_call_dummy &&
7379 b->type != bp_shlib_event &&
7380 b->type != bp_thread_event &&
7381 b->type != bp_overlay_event &&
7384 breaks_to_delete = 1;
7389 /* Ask user only if there are some breakpoints to delete. */
7391 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
7393 ALL_BREAKPOINTS_SAFE (b, temp)
7395 if (b->type != bp_call_dummy &&
7396 b->type != bp_shlib_event &&
7397 b->type != bp_thread_event &&
7398 b->type != bp_overlay_event &&
7400 delete_breakpoint (b);
7405 map_breakpoint_numbers (arg, delete_breakpoint);
7409 all_locations_are_pending (struct bp_location *loc)
7411 for (; loc; loc = loc->next)
7412 if (!loc->shlib_disabled)
7417 /* Subroutine of update_breakpoint_locations to simplify it.
7418 Return non-zero if multiple fns in list LOC have the same name.
7419 Null names are ignored. */
7422 ambiguous_names_p (struct bp_location *loc)
7424 struct bp_location *l;
7425 htab_t htab = htab_create_alloc (13, htab_hash_string,
7426 (int (*) (const void *, const void *)) streq,
7427 NULL, xcalloc, xfree);
7429 for (l = loc; l != NULL; l = l->next)
7432 const char *name = l->function_name;
7434 /* Allow for some names to be NULL, ignore them. */
7438 slot = (const char **) htab_find_slot (htab, (const void *) name,
7440 /* NOTE: We can assume slot != NULL here because xcalloc never returns
7455 update_breakpoint_locations (struct breakpoint *b,
7456 struct symtabs_and_lines sals)
7460 struct bp_location *existing_locations = b->loc;
7462 /* If there's no new locations, and all existing locations
7463 are pending, don't do anything. This optimizes
7464 the common case where all locations are in the same
7465 shared library, that was unloaded. We'd like to
7466 retain the location, so that when the library
7467 is loaded again, we don't loose the enabled/disabled
7468 status of the individual locations. */
7469 if (all_locations_are_pending (existing_locations) && sals.nelts == 0)
7474 for (i = 0; i < sals.nelts; ++i)
7476 struct bp_location *new_loc =
7477 add_location_to_breakpoint (b, &(sals.sals[i]));
7479 /* Reparse conditions, they might contain references to the
7481 if (b->cond_string != NULL)
7483 struct gdb_exception e;
7486 TRY_CATCH (e, RETURN_MASK_ERROR)
7488 new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc),
7493 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
7494 b->number, e.message);
7495 new_loc->enabled = 0;
7499 if (b->source_file != NULL)
7500 xfree (b->source_file);
7501 if (sals.sals[i].symtab == NULL)
7502 b->source_file = NULL;
7505 savestring (sals.sals[i].symtab->filename,
7506 strlen (sals.sals[i].symtab->filename));
7508 if (b->line_number == 0)
7509 b->line_number = sals.sals[i].line;
7512 /* Update locations of permanent breakpoints. */
7513 if (b->enable_state == bp_permanent)
7514 make_breakpoint_permanent (b);
7516 /* If possible, carry over 'disable' status from existing breakpoints. */
7518 struct bp_location *e = existing_locations;
7519 /* If there are multiple breakpoints with the same function name,
7520 e.g. for inline functions, comparing function names won't work.
7521 Instead compare pc addresses; this is just a heuristic as things
7522 may have moved, but in practice it gives the correct answer
7523 often enough until a better solution is found. */
7524 int have_ambiguous_names = ambiguous_names_p (b->loc);
7526 for (; e; e = e->next)
7528 if (!e->enabled && e->function_name)
7530 struct bp_location *l = b->loc;
7531 if (have_ambiguous_names)
7533 for (; l; l = l->next)
7534 if (e->address == l->address)
7542 for (; l; l = l->next)
7543 if (l->function_name
7544 && strcmp (e->function_name, l->function_name) == 0)
7554 update_global_location_list (1);
7558 /* Reset a breakpoint given it's struct breakpoint * BINT.
7559 The value we return ends up being the return value from catch_errors.
7560 Unused in this case. */
7563 breakpoint_re_set_one (void *bint)
7565 /* get past catch_errs */
7566 struct breakpoint *b = (struct breakpoint *) bint;
7570 int *not_found_ptr = ¬_found;
7571 struct symtabs_and_lines sals = {};
7572 struct symtabs_and_lines expanded;
7574 enum enable_state save_enable;
7575 struct gdb_exception e;
7576 struct cleanup *cleanups;
7581 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7585 case bp_hardware_breakpoint:
7587 if (b->addr_string == NULL)
7589 /* Anything without a string can't be re-set. */
7590 delete_breakpoint (b);
7594 set_language (b->language);
7595 input_radix = b->input_radix;
7597 TRY_CATCH (e, RETURN_MASK_ERROR)
7599 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL,
7604 int not_found_and_ok = 0;
7605 /* For pending breakpoints, it's expected that parsing
7606 will fail until the right shared library is loaded.
7607 User has already told to create pending breakpoints and
7608 don't need extra messages. If breakpoint is in bp_shlib_disabled
7609 state, then user already saw the message about that breakpoint
7610 being disabled, and don't want to see more errors. */
7612 && (b->condition_not_parsed
7613 || (b->loc && b->loc->shlib_disabled)
7614 || b->enable_state == bp_disabled))
7615 not_found_and_ok = 1;
7617 if (!not_found_and_ok)
7619 /* We surely don't want to warn about the same breakpoint
7620 10 times. One solution, implemented here, is disable
7621 the breakpoint on error. Another solution would be to
7622 have separate 'warning emitted' flag. Since this
7623 happens only when a binary has changed, I don't know
7624 which approach is better. */
7625 b->enable_state = bp_disabled;
7626 throw_exception (e);
7633 gdb_assert (sals.nelts == 1);
7634 resolve_sal_pc (&sals.sals[0]);
7635 if (b->condition_not_parsed && s && s[0])
7637 char *cond_string = 0;
7641 find_condition_and_thread (s, sals.sals[0].pc,
7642 &cond_string, &thread, &task);
7644 b->cond_string = cond_string;
7647 b->condition_not_parsed = 0;
7649 expanded = expand_line_sal_maybe (sals.sals[0]);
7650 cleanups = make_cleanup (xfree, sals.sals);
7651 update_breakpoint_locations (b, expanded);
7652 do_cleanups (cleanups);
7656 case bp_hardware_watchpoint:
7657 case bp_read_watchpoint:
7658 case bp_access_watchpoint:
7659 /* Watchpoint can be either on expression using entirely global variables,
7660 or it can be on local variables.
7662 Watchpoints of the first kind are never auto-deleted, and even persist
7663 across program restarts. Since they can use variables from shared
7664 libraries, we need to reparse expression as libraries are loaded
7667 Watchpoints on local variables can also change meaning as result
7668 of solib event. For example, if a watchpoint uses both a local and
7669 a global variables in expression, it's a local watchpoint, but
7670 unloading of a shared library will make the expression invalid.
7671 This is not a very common use case, but we still re-evaluate
7672 expression, to avoid surprises to the user.
7674 Note that for local watchpoints, we re-evaluate it only if
7675 watchpoints frame id is still valid. If it's not, it means
7676 the watchpoint is out of scope and will be deleted soon. In fact,
7677 I'm not sure we'll ever be called in this case.
7679 If a local watchpoint's frame id is still valid, then
7680 b->exp_valid_block is likewise valid, and we can safely use it.
7682 Don't do anything about disabled watchpoints, since they will
7683 be reevaluated again when enabled. */
7684 update_watchpoint (b, 1 /* reparse */);
7686 /* We needn't really do anything to reset these, since the mask
7687 that requests them is unaffected by e.g., new libraries being
7693 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type);
7695 /* Delete overlay event breakpoints; they will be reset later by
7696 breakpoint_re_set. */
7697 case bp_overlay_event:
7698 delete_breakpoint (b);
7701 /* This breakpoint is special, it's set up when the inferior
7702 starts and we really don't want to touch it. */
7703 case bp_shlib_event:
7705 /* Like bp_shlib_event, this breakpoint type is special.
7706 Once it is set up, we do not want to touch it. */
7707 case bp_thread_event:
7709 /* Keep temporary breakpoints, which can be encountered when we step
7710 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7711 Otherwise these should have been blown away via the cleanup chain
7712 or by breakpoint_init_inferior when we rerun the executable. */
7715 case bp_watchpoint_scope:
7717 case bp_step_resume:
7719 case bp_longjmp_resume:
7726 /* Re-set all breakpoints after symbols have been re-loaded. */
7728 breakpoint_re_set (void)
7730 struct breakpoint *b, *temp;
7731 enum language save_language;
7732 int save_input_radix;
7734 save_language = current_language->la_language;
7735 save_input_radix = input_radix;
7736 ALL_BREAKPOINTS_SAFE (b, temp)
7738 /* Format possible error msg */
7739 char *message = xstrprintf ("Error in re-setting breakpoint %d: ",
7741 struct cleanup *cleanups = make_cleanup (xfree, message);
7742 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
7743 do_cleanups (cleanups);
7745 set_language (save_language);
7746 input_radix = save_input_radix;
7748 create_overlay_event_breakpoint ("_ovly_debug_event");
7751 /* Reset the thread number of this breakpoint:
7753 - If the breakpoint is for all threads, leave it as-is.
7754 - Else, reset it to the current thread for inferior_ptid. */
7756 breakpoint_re_set_thread (struct breakpoint *b)
7758 if (b->thread != -1)
7760 if (in_thread_list (inferior_ptid))
7761 b->thread = pid_to_thread_id (inferior_ptid);
7765 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7766 If from_tty is nonzero, it prints a message to that effect,
7767 which ends with a period (no newline). */
7770 set_ignore_count (int bptnum, int count, int from_tty)
7772 struct breakpoint *b;
7778 if (b->number == bptnum)
7780 b->ignore_count = count;
7784 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7786 else if (count == 1)
7787 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7790 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7793 breakpoints_changed ();
7794 observer_notify_breakpoint_modified (b->number);
7798 error (_("No breakpoint number %d."), bptnum);
7802 make_breakpoint_silent (struct breakpoint *b)
7804 /* Silence the breakpoint. */
7808 /* Command to set ignore-count of breakpoint N to COUNT. */
7811 ignore_command (char *args, int from_tty)
7817 error_no_arg (_("a breakpoint number"));
7819 num = get_number (&p);
7821 error (_("bad breakpoint number: '%s'"), args);
7823 error (_("Second argument (specified ignore-count) is missing."));
7825 set_ignore_count (num,
7826 longest_to_int (value_as_long (parse_and_eval (p))),
7829 printf_filtered ("\n");
7832 /* Call FUNCTION on each of the breakpoints
7833 whose numbers are given in ARGS. */
7836 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *))
7841 struct breakpoint *b, *tmp;
7845 error_no_arg (_("one or more breakpoint numbers"));
7852 num = get_number_or_range (&p1);
7855 warning (_("bad breakpoint number at or near '%s'"), p);
7859 ALL_BREAKPOINTS_SAFE (b, tmp)
7860 if (b->number == num)
7862 struct breakpoint *related_breakpoint = b->related_breakpoint;
7865 if (related_breakpoint)
7866 function (related_breakpoint);
7870 printf_unfiltered (_("No breakpoint number %d.\n"), num);
7876 static struct bp_location *
7877 find_location_by_number (char *number)
7879 char *dot = strchr (number, '.');
7883 struct breakpoint *b;
7884 struct bp_location *loc;
7889 bp_num = get_number_or_range (&p1);
7891 error (_("Bad breakpoint number '%s'"), number);
7894 if (b->number == bp_num)
7899 if (!b || b->number != bp_num)
7900 error (_("Bad breakpoint number '%s'"), number);
7903 loc_num = get_number_or_range (&p1);
7905 error (_("Bad breakpoint location number '%s'"), number);
7909 for (;loc_num && loc; --loc_num, loc = loc->next)
7912 error (_("Bad breakpoint location number '%s'"), dot+1);
7918 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7919 If from_tty is nonzero, it prints a message to that effect,
7920 which ends with a period (no newline). */
7923 disable_breakpoint (struct breakpoint *bpt)
7925 /* Never disable a watchpoint scope breakpoint; we want to
7926 hit them when we leave scope so we can delete both the
7927 watchpoint and its scope breakpoint at that time. */
7928 if (bpt->type == bp_watchpoint_scope)
7931 /* You can't disable permanent breakpoints. */
7932 if (bpt->enable_state == bp_permanent)
7935 bpt->enable_state = bp_disabled;
7937 update_global_location_list (0);
7939 observer_notify_breakpoint_modified (bpt->number);
7943 disable_command (char *args, int from_tty)
7945 struct breakpoint *bpt;
7947 ALL_BREAKPOINTS (bpt)
7951 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
7957 case bp_hardware_breakpoint:
7959 case bp_hardware_watchpoint:
7960 case bp_read_watchpoint:
7961 case bp_access_watchpoint:
7962 disable_breakpoint (bpt);
7966 else if (strchr (args, '.'))
7968 struct bp_location *loc = find_location_by_number (args);
7971 update_global_location_list (0);
7974 map_breakpoint_numbers (args, disable_breakpoint);
7978 do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition)
7980 int target_resources_ok, other_type_used;
7983 if (bpt->type == bp_hardware_breakpoint)
7986 i = hw_breakpoint_used_count ();
7987 target_resources_ok =
7988 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
7990 if (target_resources_ok == 0)
7991 error (_("No hardware breakpoint support in the target."));
7992 else if (target_resources_ok < 0)
7993 error (_("Hardware breakpoints used exceeds limit."));
7996 if (bpt->type == bp_watchpoint ||
7997 bpt->type == bp_hardware_watchpoint ||
7998 bpt->type == bp_read_watchpoint ||
7999 bpt->type == bp_access_watchpoint)
8001 struct gdb_exception e;
8003 TRY_CATCH (e, RETURN_MASK_ALL)
8005 update_watchpoint (bpt, 1 /* reparse */);
8009 exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "),
8015 if (bpt->enable_state != bp_permanent)
8016 bpt->enable_state = bp_enabled;
8017 bpt->disposition = disposition;
8018 update_global_location_list (1);
8019 breakpoints_changed ();
8021 observer_notify_breakpoint_modified (bpt->number);
8026 enable_breakpoint (struct breakpoint *bpt)
8028 do_enable_breakpoint (bpt, bpt->disposition);
8031 /* The enable command enables the specified breakpoints (or all defined
8032 breakpoints) so they once again become (or continue to be) effective
8033 in stopping the inferior. */
8036 enable_command (char *args, int from_tty)
8038 struct breakpoint *bpt;
8040 ALL_BREAKPOINTS (bpt)
8044 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
8050 case bp_hardware_breakpoint:
8052 case bp_hardware_watchpoint:
8053 case bp_read_watchpoint:
8054 case bp_access_watchpoint:
8055 enable_breakpoint (bpt);
8059 else if (strchr (args, '.'))
8061 struct bp_location *loc = find_location_by_number (args);
8064 update_global_location_list (1);
8067 map_breakpoint_numbers (args, enable_breakpoint);
8071 enable_once_breakpoint (struct breakpoint *bpt)
8073 do_enable_breakpoint (bpt, disp_disable);
8077 enable_once_command (char *args, int from_tty)
8079 map_breakpoint_numbers (args, enable_once_breakpoint);
8083 enable_delete_breakpoint (struct breakpoint *bpt)
8085 do_enable_breakpoint (bpt, disp_del);
8089 enable_delete_command (char *args, int from_tty)
8091 map_breakpoint_numbers (args, enable_delete_breakpoint);
8095 set_breakpoint_cmd (char *args, int from_tty)
8100 show_breakpoint_cmd (char *args, int from_tty)
8104 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
8106 struct symtabs_and_lines
8107 decode_line_spec_1 (char *string, int funfirstline)
8109 struct symtabs_and_lines sals;
8111 error (_("Empty line specification."));
8112 if (default_breakpoint_valid)
8113 sals = decode_line_1 (&string, funfirstline,
8114 default_breakpoint_symtab,
8115 default_breakpoint_line,
8116 (char ***) NULL, NULL);
8118 sals = decode_line_1 (&string, funfirstline,
8119 (struct symtab *) NULL, 0, (char ***) NULL, NULL);
8121 error (_("Junk at end of line specification: %s"), string);
8125 /* Create and insert a raw software breakpoint at PC. Return an
8126 identifier, which should be used to remove the breakpoint later.
8127 In general, places which call this should be using something on the
8128 breakpoint chain instead; this function should be eliminated
8132 deprecated_insert_raw_breakpoint (CORE_ADDR pc)
8134 struct bp_target_info *bp_tgt;
8136 bp_tgt = xmalloc (sizeof (struct bp_target_info));
8137 memset (bp_tgt, 0, sizeof (struct bp_target_info));
8139 bp_tgt->placed_address = pc;
8140 if (target_insert_breakpoint (bp_tgt) != 0)
8142 /* Could not insert the breakpoint. */
8150 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
8153 deprecated_remove_raw_breakpoint (void *bp)
8155 struct bp_target_info *bp_tgt = bp;
8158 ret = target_remove_breakpoint (bp_tgt);
8164 /* One (or perhaps two) breakpoints used for software single stepping. */
8166 static void *single_step_breakpoints[2];
8168 /* Create and insert a breakpoint for software single step. */
8171 insert_single_step_breakpoint (CORE_ADDR next_pc)
8175 if (single_step_breakpoints[0] == NULL)
8176 bpt_p = &single_step_breakpoints[0];
8179 gdb_assert (single_step_breakpoints[1] == NULL);
8180 bpt_p = &single_step_breakpoints[1];
8183 /* NOTE drow/2006-04-11: A future improvement to this function would be
8184 to only create the breakpoints once, and actually put them on the
8185 breakpoint chain. That would let us use set_raw_breakpoint. We could
8186 adjust the addresses each time they were needed. Doing this requires
8187 corresponding changes elsewhere where single step breakpoints are
8188 handled, however. So, for now, we use this. */
8190 *bpt_p = deprecated_insert_raw_breakpoint (next_pc);
8192 error (_("Could not insert single-step breakpoint at 0x%s"),
8193 paddr_nz (next_pc));
8196 /* Remove and delete any breakpoints used for software single step. */
8199 remove_single_step_breakpoints (void)
8201 gdb_assert (single_step_breakpoints[0] != NULL);
8203 /* See insert_single_step_breakpoint for more about this deprecated
8205 deprecated_remove_raw_breakpoint (single_step_breakpoints[0]);
8206 single_step_breakpoints[0] = NULL;
8208 if (single_step_breakpoints[1] != NULL)
8210 deprecated_remove_raw_breakpoint (single_step_breakpoints[1]);
8211 single_step_breakpoints[1] = NULL;
8215 /* Check whether a software single-step breakpoint is inserted at PC. */
8218 single_step_breakpoint_inserted_here_p (CORE_ADDR pc)
8222 for (i = 0; i < 2; i++)
8224 struct bp_target_info *bp_tgt = single_step_breakpoints[i];
8225 if (bp_tgt && bp_tgt->placed_address == pc)
8232 /* Tracepoint-specific operations. */
8234 /* Set tracepoint count to NUM. */
8236 set_tracepoint_count (int num)
8238 tracepoint_count = num;
8239 set_internalvar (lookup_internalvar ("tpnum"),
8240 value_from_longest (builtin_type_int32, (LONGEST) num));
8244 trace_command (char *arg, int from_tty)
8246 break_command_really (arg,
8247 NULL, 0, 1 /* parse arg */,
8248 0 /* tempflag */, 0 /* hardwareflag */,
8250 0 /* Ignore count */,
8251 pending_break_support,
8255 set_tracepoint_count (breakpoint_count);
8258 /* Print information on tracepoint number TPNUM_EXP, or all if
8262 tracepoints_info (char *tpnum_exp, int from_tty)
8264 struct breakpoint *b;
8265 int tps_to_list = 0;
8267 /* In the no-arguments case, say "No tracepoints" if none found. */
8280 ui_out_message (uiout, 0, "No tracepoints.\n");
8285 /* Otherwise be the same as "info break". */
8286 breakpoints_info (tpnum_exp, from_tty);
8289 /* The 'enable trace' command enables tracepoints.
8290 Not supported by all targets. */
8292 enable_trace_command (char *args, int from_tty)
8294 enable_command (args, from_tty);
8297 /* The 'disable trace' command disables tracepoints.
8298 Not supported by all targets. */
8300 disable_trace_command (char *args, int from_tty)
8302 disable_command (args, from_tty);
8305 /* Remove a tracepoint (or all if no argument) */
8307 delete_trace_command (char *arg, int from_tty)
8309 struct breakpoint *b, *temp;
8315 int breaks_to_delete = 0;
8317 /* Delete all breakpoints if no argument.
8318 Do not delete internal or call-dummy breakpoints, these
8319 have to be deleted with an explicit breakpoint number argument. */
8324 breaks_to_delete = 1;
8329 /* Ask user only if there are some breakpoints to delete. */
8331 || (breaks_to_delete && query (_("Delete all tracepoints? "))))
8333 ALL_BREAKPOINTS_SAFE (b, temp)
8335 if (b->type == bp_tracepoint &&
8337 delete_breakpoint (b);
8342 map_breakpoint_numbers (arg, delete_breakpoint);
8345 /* Set passcount for tracepoint.
8347 First command argument is passcount, second is tracepoint number.
8348 If tracepoint number omitted, apply to most recently defined.
8349 Also accepts special argument "all". */
8352 trace_pass_command (char *args, int from_tty)
8354 struct breakpoint *t1 = (struct breakpoint *) -1, *t2;
8358 if (args == 0 || *args == 0)
8359 error (_("passcount command requires an argument (count + optional TP num)"));
8361 count = strtoul (args, &args, 10); /* Count comes first, then TP num. */
8363 while (*args && isspace ((int) *args))
8366 if (*args && strncasecmp (args, "all", 3) == 0)
8368 args += 3; /* Skip special argument "all". */
8371 error (_("Junk at end of arguments."));
8374 t1 = get_tracepoint_by_number (&args, 1, 1);
8380 ALL_TRACEPOINTS (t2)
8381 if (t1 == (struct breakpoint *) -1 || t1 == t2)
8383 t2->pass_count = count;
8384 observer_notify_tracepoint_modified (t2->number);
8386 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
8390 t1 = get_tracepoint_by_number (&args, 1, 0);
8397 get_tracepoint (int num)
8399 struct breakpoint *t;
8402 if (t->number == num)
8408 /* Utility: parse a tracepoint number and look it up in the list.
8409 If MULTI_P is true, there might be a range of tracepoints in ARG.
8410 if OPTIONAL_P is true, then if the argument is missing, the most
8411 recent tracepoint (tracepoint_count) is returned. */
8413 get_tracepoint_by_number (char **arg, int multi_p, int optional_p)
8415 extern int tracepoint_count;
8416 struct breakpoint *t;
8418 char *instring = arg == NULL ? NULL : *arg;
8420 if (arg == NULL || *arg == NULL || ! **arg)
8423 tpnum = tracepoint_count;
8425 error_no_arg (_("tracepoint number"));
8428 tpnum = multi_p ? get_number_or_range (arg) : get_number (arg);
8432 if (instring && *instring)
8433 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
8436 printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n"));
8441 if (t->number == tpnum)
8446 /* FIXME: if we are in the middle of a range we don't want to give
8447 a message. The current interface to get_number_or_range doesn't
8448 allow us to discover this. */
8449 printf_unfiltered ("No tracepoint number %d.\n", tpnum);
8453 /* save-tracepoints command */
8455 tracepoint_save_command (char *args, int from_tty)
8457 struct breakpoint *tp;
8459 struct action_line *line;
8461 char *i1 = " ", *i2 = " ";
8462 char *indent, *actionline, *pathname;
8464 struct cleanup *cleanup;
8466 if (args == 0 || *args == 0)
8467 error (_("Argument required (file name in which to save tracepoints)"));
8469 /* See if we have anything to save. */
8470 ALL_TRACEPOINTS (tp)
8477 warning (_("save-tracepoints: no tracepoints to save."));
8481 pathname = tilde_expand (args);
8482 cleanup = make_cleanup (xfree, pathname);
8483 if (!(fp = fopen (pathname, "w")))
8484 error (_("Unable to open file '%s' for saving tracepoints (%s)"),
8485 args, safe_strerror (errno));
8486 make_cleanup_fclose (fp);
8488 ALL_TRACEPOINTS (tp)
8490 if (tp->addr_string)
8491 fprintf (fp, "trace %s\n", tp->addr_string);
8494 sprintf_vma (tmp, tp->loc->address);
8495 fprintf (fp, "trace *0x%s\n", tmp);
8499 fprintf (fp, " passcount %d\n", tp->pass_count);
8503 fprintf (fp, " actions\n");
8505 for (line = tp->actions; line; line = line->next)
8507 struct cmd_list_element *cmd;
8509 QUIT; /* allow user to bail out with ^C */
8510 actionline = line->action;
8511 while (isspace ((int) *actionline))
8514 fprintf (fp, "%s%s\n", indent, actionline);
8515 if (*actionline != '#') /* skip for comment lines */
8517 cmd = lookup_cmd (&actionline, cmdlist, "", -1, 1);
8519 error (_("Bad action list item: %s"), actionline);
8520 if (cmd_cfunc_eq (cmd, while_stepping_pseudocommand))
8522 else if (cmd_cfunc_eq (cmd, end_actions_pseudocommand))
8528 do_cleanups (cleanup);
8530 printf_filtered (_("Tracepoints saved to file '%s'.\n"), args);
8534 /* Create a vector of all tracepoints. */
8539 VEC(breakpoint_p) *tp_vec = 0;
8540 struct breakpoint *tp;
8542 ALL_TRACEPOINTS (tp)
8544 VEC_safe_push (breakpoint_p, tp_vec, tp);
8551 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
8552 It is defined as a macro to prevent duplication.
8553 COMMAND should be a string constant containing the name of the command. */
8554 #define BREAK_ARGS_HELP(command) \
8555 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
8556 LOCATION may be a line number, function name, or \"*\" and an address.\n\
8557 If a line number is specified, break at start of code for that line.\n\
8558 If a function is specified, break at start of code for that function.\n\
8559 If an address is specified, break at that exact address.\n\
8560 With no LOCATION, uses current execution address of selected stack frame.\n\
8561 This is useful for breaking on return to a stack frame.\n\
8563 THREADNUM is the number from \"info threads\".\n\
8564 CONDITION is a boolean expression.\n\
8566 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
8568 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
8570 /* List of subcommands for "catch". */
8571 static struct cmd_list_element *catch_cmdlist;
8573 /* List of subcommands for "tcatch". */
8574 static struct cmd_list_element *tcatch_cmdlist;
8576 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
8577 lists, and pass some additional user data to the command function. */
8579 add_catch_command (char *name, char *docstring,
8580 void (*sfunc) (char *args, int from_tty,
8581 struct cmd_list_element *command),
8582 void *user_data_catch,
8583 void *user_data_tcatch)
8585 struct cmd_list_element *command;
8587 command = add_cmd (name, class_breakpoint, NULL, docstring,
8589 set_cmd_sfunc (command, sfunc);
8590 set_cmd_context (command, user_data_catch);
8592 command = add_cmd (name, class_breakpoint, NULL, docstring,
8594 set_cmd_sfunc (command, sfunc);
8595 set_cmd_context (command, user_data_tcatch);
8599 _initialize_breakpoint (void)
8601 static struct cmd_list_element *breakpoint_set_cmdlist;
8602 static struct cmd_list_element *breakpoint_show_cmdlist;
8603 struct cmd_list_element *c;
8605 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
8607 breakpoint_chain = 0;
8608 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
8609 before a breakpoint is set. */
8610 breakpoint_count = 0;
8612 tracepoint_count = 0;
8614 add_com ("ignore", class_breakpoint, ignore_command, _("\
8615 Set ignore-count of breakpoint number N to COUNT.\n\
8616 Usage is `ignore N COUNT'."));
8618 add_com_alias ("bc", "ignore", class_breakpoint, 1);
8620 add_com ("commands", class_breakpoint, commands_command, _("\
8621 Set commands to be executed when a breakpoint is hit.\n\
8622 Give breakpoint number as argument after \"commands\".\n\
8623 With no argument, the targeted breakpoint is the last one set.\n\
8624 The commands themselves follow starting on the next line.\n\
8625 Type a line containing \"end\" to indicate the end of them.\n\
8626 Give \"silent\" as the first line to make the breakpoint silent;\n\
8627 then no output is printed when it is hit, except what the commands print."));
8629 add_com ("condition", class_breakpoint, condition_command, _("\
8630 Specify breakpoint number N to break only if COND is true.\n\
8631 Usage is `condition N COND', where N is an integer and COND is an\n\
8632 expression to be evaluated whenever breakpoint N is reached."));
8634 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
8635 Set a temporary breakpoint.\n\
8636 Like \"break\" except the breakpoint is only temporary,\n\
8637 so it will be deleted when hit. Equivalent to \"break\" followed\n\
8638 by using \"enable delete\" on the breakpoint number.\n\
8640 BREAK_ARGS_HELP ("tbreak")));
8641 set_cmd_completer (c, location_completer);
8643 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
8644 Set a hardware assisted breakpoint.\n\
8645 Like \"break\" except the breakpoint requires hardware support,\n\
8646 some target hardware may not have this support.\n\
8648 BREAK_ARGS_HELP ("hbreak")));
8649 set_cmd_completer (c, location_completer);
8651 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
8652 Set a temporary hardware assisted breakpoint.\n\
8653 Like \"hbreak\" except the breakpoint is only temporary,\n\
8654 so it will be deleted when hit.\n\
8656 BREAK_ARGS_HELP ("thbreak")));
8657 set_cmd_completer (c, location_completer);
8659 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
8660 Enable some breakpoints.\n\
8661 Give breakpoint numbers (separated by spaces) as arguments.\n\
8662 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8663 This is used to cancel the effect of the \"disable\" command.\n\
8664 With a subcommand you can enable temporarily."),
8665 &enablelist, "enable ", 1, &cmdlist);
8667 add_com ("ab", class_breakpoint, enable_command, _("\
8668 Enable some breakpoints.\n\
8669 Give breakpoint numbers (separated by spaces) as arguments.\n\
8670 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8671 This is used to cancel the effect of the \"disable\" command.\n\
8672 With a subcommand you can enable temporarily."));
8674 add_com_alias ("en", "enable", class_breakpoint, 1);
8676 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
8677 Enable some breakpoints.\n\
8678 Give breakpoint numbers (separated by spaces) as arguments.\n\
8679 This is used to cancel the effect of the \"disable\" command.\n\
8680 May be abbreviated to simply \"enable\".\n"),
8681 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
8683 add_cmd ("once", no_class, enable_once_command, _("\
8684 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8685 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8688 add_cmd ("delete", no_class, enable_delete_command, _("\
8689 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8690 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8693 add_cmd ("delete", no_class, enable_delete_command, _("\
8694 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8695 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8698 add_cmd ("once", no_class, enable_once_command, _("\
8699 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8700 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8703 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
8704 Disable some breakpoints.\n\
8705 Arguments are breakpoint numbers with spaces in between.\n\
8706 To disable all breakpoints, give no argument.\n\
8707 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8708 &disablelist, "disable ", 1, &cmdlist);
8709 add_com_alias ("dis", "disable", class_breakpoint, 1);
8710 add_com_alias ("disa", "disable", class_breakpoint, 1);
8712 add_com ("sb", class_breakpoint, disable_command, _("\
8713 Disable some breakpoints.\n\
8714 Arguments are breakpoint numbers with spaces in between.\n\
8715 To disable all breakpoints, give no argument.\n\
8716 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8718 add_cmd ("breakpoints", class_alias, disable_command, _("\
8719 Disable some breakpoints.\n\
8720 Arguments are breakpoint numbers with spaces in between.\n\
8721 To disable all breakpoints, give no argument.\n\
8722 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8723 This command may be abbreviated \"disable\"."),
8726 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
8727 Delete some breakpoints or auto-display expressions.\n\
8728 Arguments are breakpoint numbers with spaces in between.\n\
8729 To delete all breakpoints, give no argument.\n\
8731 Also a prefix command for deletion of other GDB objects.\n\
8732 The \"unset\" command is also an alias for \"delete\"."),
8733 &deletelist, "delete ", 1, &cmdlist);
8734 add_com_alias ("d", "delete", class_breakpoint, 1);
8735 add_com_alias ("del", "delete", class_breakpoint, 1);
8737 add_com ("db", class_breakpoint, delete_command, _("\
8738 Delete some breakpoints.\n\
8739 Arguments are breakpoint numbers with spaces in between.\n\
8740 To delete all breakpoints, give no argument.\n"));
8742 add_cmd ("breakpoints", class_alias, delete_command, _("\
8743 Delete some breakpoints or auto-display expressions.\n\
8744 Arguments are breakpoint numbers with spaces in between.\n\
8745 To delete all breakpoints, give no argument.\n\
8746 This command may be abbreviated \"delete\"."),
8749 add_com ("clear", class_breakpoint, clear_command, _("\
8750 Clear breakpoint at specified line or function.\n\
8751 Argument may be line number, function name, or \"*\" and an address.\n\
8752 If line number is specified, all breakpoints in that line are cleared.\n\
8753 If function is specified, breakpoints at beginning of function are cleared.\n\
8754 If an address is specified, breakpoints at that address are cleared.\n\
8756 With no argument, clears all breakpoints in the line that the selected frame\n\
8759 See also the \"delete\" command which clears breakpoints by number."));
8761 c = add_com ("break", class_breakpoint, break_command, _("\
8762 Set breakpoint at specified line or function.\n"
8763 BREAK_ARGS_HELP ("break")));
8764 set_cmd_completer (c, location_completer);
8766 add_com_alias ("b", "break", class_run, 1);
8767 add_com_alias ("br", "break", class_run, 1);
8768 add_com_alias ("bre", "break", class_run, 1);
8769 add_com_alias ("brea", "break", class_run, 1);
8773 add_com_alias ("ba", "break", class_breakpoint, 1);
8774 add_com_alias ("bu", "ubreak", class_breakpoint, 1);
8779 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
8780 Break in function/address or break at a line in the current file."),
8781 &stoplist, "stop ", 1, &cmdlist);
8782 add_cmd ("in", class_breakpoint, stopin_command,
8783 _("Break in function or address."), &stoplist);
8784 add_cmd ("at", class_breakpoint, stopat_command,
8785 _("Break at a line in the current file."), &stoplist);
8786 add_com ("status", class_info, breakpoints_info, _("\
8787 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8788 The \"Type\" column indicates one of:\n\
8789 \tbreakpoint - normal breakpoint\n\
8790 \twatchpoint - watchpoint\n\
8791 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8792 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8793 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8794 address and file/line number respectively.\n\
8796 Convenience variable \"$_\" and default examine address for \"x\"\n\
8797 are set to the address of the last breakpoint listed unless the command\n\
8798 is prefixed with \"server \".\n\n\
8799 Convenience variable \"$bpnum\" contains the number of the last\n\
8803 add_info ("breakpoints", breakpoints_info, _("\
8804 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8805 The \"Type\" column indicates one of:\n\
8806 \tbreakpoint - normal breakpoint\n\
8807 \twatchpoint - watchpoint\n\
8808 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8809 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8810 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8811 address and file/line number respectively.\n\
8813 Convenience variable \"$_\" and default examine address for \"x\"\n\
8814 are set to the address of the last breakpoint listed unless the command\n\
8815 is prefixed with \"server \".\n\n\
8816 Convenience variable \"$bpnum\" contains the number of the last\n\
8820 add_com ("lb", class_breakpoint, breakpoints_info, _("\
8821 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8822 The \"Type\" column indicates one of:\n\
8823 \tbreakpoint - normal breakpoint\n\
8824 \twatchpoint - watchpoint\n\
8825 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8826 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8827 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8828 address and file/line number respectively.\n\
8830 Convenience variable \"$_\" and default examine address for \"x\"\n\
8831 are set to the address of the last breakpoint listed unless the command\n\
8832 is prefixed with \"server \".\n\n\
8833 Convenience variable \"$bpnum\" contains the number of the last\n\
8836 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
8837 Status of all breakpoints, or breakpoint number NUMBER.\n\
8838 The \"Type\" column indicates one of:\n\
8839 \tbreakpoint - normal breakpoint\n\
8840 \twatchpoint - watchpoint\n\
8841 \tlongjmp - internal breakpoint used to step through longjmp()\n\
8842 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8843 \tuntil - internal breakpoint used by the \"until\" command\n\
8844 \tfinish - internal breakpoint used by the \"finish\" command\n\
8845 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8846 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8847 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8848 address and file/line number respectively.\n\
8850 Convenience variable \"$_\" and default examine address for \"x\"\n\
8851 are set to the address of the last breakpoint listed unless the command\n\
8852 is prefixed with \"server \".\n\n\
8853 Convenience variable \"$bpnum\" contains the number of the last\n\
8855 &maintenanceinfolist);
8857 add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\
8858 Set catchpoints to catch events."),
8859 &catch_cmdlist, "catch ",
8860 0/*allow-unknown*/, &cmdlist);
8862 add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\
8863 Set temporary catchpoints to catch events."),
8864 &tcatch_cmdlist, "tcatch ",
8865 0/*allow-unknown*/, &cmdlist);
8867 /* Add catch and tcatch sub-commands. */
8868 add_catch_command ("catch", _("\
8869 Catch an exception, when caught.\n\
8870 With an argument, catch only exceptions with the given name."),
8871 catch_catch_command,
8874 add_catch_command ("throw", _("\
8875 Catch an exception, when thrown.\n\
8876 With an argument, catch only exceptions with the given name."),
8877 catch_throw_command,
8880 add_catch_command ("fork", _("Catch calls to fork."),
8881 catch_fork_command_1,
8882 (void *) (uintptr_t) catch_fork_permanent,
8883 (void *) (uintptr_t) catch_fork_temporary);
8884 add_catch_command ("vfork", _("Catch calls to vfork."),
8885 catch_fork_command_1,
8886 (void *) (uintptr_t) catch_vfork_permanent,
8887 (void *) (uintptr_t) catch_vfork_temporary);
8888 add_catch_command ("exec", _("Catch calls to exec."),
8889 catch_exec_command_1,
8892 add_catch_command ("exception", _("\
8893 Catch Ada exceptions, when raised.\n\
8894 With an argument, catch only exceptions with the given name."),
8895 catch_ada_exception_command,
8898 add_catch_command ("assert", _("\
8899 Catch failed Ada assertions, when raised.\n\
8900 With an argument, catch only exceptions with the given name."),
8901 catch_assert_command,
8905 c = add_com ("watch", class_breakpoint, watch_command, _("\
8906 Set a watchpoint for an expression.\n\
8907 A watchpoint stops execution of your program whenever the value of\n\
8908 an expression changes."));
8909 set_cmd_completer (c, expression_completer);
8911 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
8912 Set a read watchpoint for an expression.\n\
8913 A watchpoint stops execution of your program whenever the value of\n\
8914 an expression is read."));
8915 set_cmd_completer (c, expression_completer);
8917 c = add_com ("awatch", class_breakpoint, awatch_command, _("\
8918 Set a watchpoint for an expression.\n\
8919 A watchpoint stops execution of your program whenever the value of\n\
8920 an expression is either read or written."));
8921 set_cmd_completer (c, expression_completer);
8923 add_info ("watchpoints", breakpoints_info,
8924 _("Synonym for ``info breakpoints''."));
8927 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8928 respond to changes - contrary to the description. */
8929 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
8930 &can_use_hw_watchpoints, _("\
8931 Set debugger's willingness to use watchpoint hardware."), _("\
8932 Show debugger's willingness to use watchpoint hardware."), _("\
8933 If zero, gdb will not use hardware for new watchpoints, even if\n\
8934 such is available. (However, any hardware watchpoints that were\n\
8935 created before setting this to nonzero, will continue to use watchpoint\n\
8938 show_can_use_hw_watchpoints,
8939 &setlist, &showlist);
8941 can_use_hw_watchpoints = 1;
8943 /* Tracepoint manipulation commands. */
8945 c = add_com ("trace", class_breakpoint, trace_command, _("\
8946 Set a tracepoint at specified line or function.\n\
8948 BREAK_ARGS_HELP ("trace") "\n\
8949 Do \"help tracepoints\" for info on other tracepoint commands."));
8950 set_cmd_completer (c, location_completer);
8952 add_com_alias ("tp", "trace", class_alias, 0);
8953 add_com_alias ("tr", "trace", class_alias, 1);
8954 add_com_alias ("tra", "trace", class_alias, 1);
8955 add_com_alias ("trac", "trace", class_alias, 1);
8957 add_info ("tracepoints", tracepoints_info, _("\
8958 Status of tracepoints, or tracepoint number NUMBER.\n\
8959 Convenience variable \"$tpnum\" contains the number of the\n\
8960 last tracepoint set."));
8962 add_info_alias ("tp", "tracepoints", 1);
8964 add_cmd ("tracepoints", class_trace, delete_trace_command, _("\
8965 Delete specified tracepoints.\n\
8966 Arguments are tracepoint numbers, separated by spaces.\n\
8967 No argument means delete all tracepoints."),
8970 c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\
8971 Disable specified tracepoints.\n\
8972 Arguments are tracepoint numbers, separated by spaces.\n\
8973 No argument means disable all tracepoints."),
8975 deprecate_cmd (c, "disable");
8977 c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\
8978 Enable specified tracepoints.\n\
8979 Arguments are tracepoint numbers, separated by spaces.\n\
8980 No argument means enable all tracepoints."),
8982 deprecate_cmd (c, "enable");
8984 add_com ("passcount", class_trace, trace_pass_command, _("\
8985 Set the passcount for a tracepoint.\n\
8986 The trace will end when the tracepoint has been passed 'count' times.\n\
8987 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
8988 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
8990 c = add_com ("save-tracepoints", class_trace, tracepoint_save_command, _("\
8991 Save current tracepoint definitions as a script.\n\
8992 Use the 'source' command in another debug session to restore them."));
8993 set_cmd_completer (c, filename_completer);
8995 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
8996 Breakpoint specific settings\n\
8997 Configure various breakpoint-specific variables such as\n\
8998 pending breakpoint behavior"),
8999 &breakpoint_set_cmdlist, "set breakpoint ",
9000 0/*allow-unknown*/, &setlist);
9001 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
9002 Breakpoint specific settings\n\
9003 Configure various breakpoint-specific variables such as\n\
9004 pending breakpoint behavior"),
9005 &breakpoint_show_cmdlist, "show breakpoint ",
9006 0/*allow-unknown*/, &showlist);
9008 add_setshow_auto_boolean_cmd ("pending", no_class,
9009 &pending_break_support, _("\
9010 Set debugger's behavior regarding pending breakpoints."), _("\
9011 Show debugger's behavior regarding pending breakpoints."), _("\
9012 If on, an unrecognized breakpoint location will cause gdb to create a\n\
9013 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
9014 an error. If auto, an unrecognized breakpoint location results in a\n\
9015 user-query to see if a pending breakpoint should be created."),
9017 show_pending_break_support,
9018 &breakpoint_set_cmdlist,
9019 &breakpoint_show_cmdlist);
9021 pending_break_support = AUTO_BOOLEAN_AUTO;
9023 add_setshow_boolean_cmd ("auto-hw", no_class,
9024 &automatic_hardware_breakpoints, _("\
9025 Set automatic usage of hardware breakpoints."), _("\
9026 Show automatic usage of hardware breakpoints."), _("\
9027 If set, the debugger will automatically use hardware breakpoints for\n\
9028 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
9029 a warning will be emitted for such breakpoints."),
9031 show_automatic_hardware_breakpoints,
9032 &breakpoint_set_cmdlist,
9033 &breakpoint_show_cmdlist);
9035 add_setshow_enum_cmd ("always-inserted", class_support,
9036 always_inserted_enums, &always_inserted_mode, _("\
9037 Set mode for inserting breakpoints."), _("\
9038 Show mode for inserting breakpoints."), _("\
9039 When this mode is off, breakpoints are inserted in inferior when it is\n\
9040 resumed, and removed when execution stops. When this mode is on,\n\
9041 breakpoints are inserted immediately and removed only when the user\n\
9042 deletes the breakpoint. When this mode is auto (which is the default),\n\
9043 the behaviour depends on the non-stop setting (see help set non-stop).\n\
9044 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
9045 behaves as if always-inserted mode is on; if gdb is controlling the\n\
9046 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
9048 &show_always_inserted_mode,
9049 &breakpoint_set_cmdlist,
9050 &breakpoint_show_cmdlist);
9052 automatic_hardware_breakpoints = 1;
9054 observer_attach_about_to_proceed (breakpoint_about_to_proceed);