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
= STOPPED_BY_WATCHPOINT (*ws
);
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 ())
2716 && gdbarch_in_function_epilogue_p (current_gdbarch
, read_pc ()))
2717 return WP_VALUE_NOT_CHANGED
;
2718 if (fr
&& within_current_scope
)
2719 /* If we end up stopping, the current frame will get selected
2720 in normal_stop. So this call to select_frame won't affect
2725 if (within_current_scope
)
2727 /* We use value_{,free_to_}mark because it could be a
2728 *long* time before we return to the command level and
2729 call free_all_values. We can't call free_all_values because
2730 we might be in the middle of evaluating a function call. */
2732 struct value
*mark
= value_mark ();
2733 struct value
*new_val
;
2735 fetch_watchpoint_value (b
->exp
, &new_val
, NULL
, NULL
);
2736 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
2737 || (b
->val
!= NULL
&& !value_equal (b
->val
, new_val
)))
2739 if (new_val
!= NULL
)
2741 release_value (new_val
);
2742 value_free_to_mark (mark
);
2744 bs
->old_val
= b
->val
;
2747 /* We will stop here */
2748 return WP_VALUE_CHANGED
;
2752 /* Nothing changed, don't do anything. */
2753 value_free_to_mark (mark
);
2754 /* We won't stop here */
2755 return WP_VALUE_NOT_CHANGED
;
2760 /* This seems like the only logical thing to do because
2761 if we temporarily ignored the watchpoint, then when
2762 we reenter the block in which it is valid it contains
2763 garbage (in the case of a function, it may have two
2764 garbage values, one before and one after the prologue).
2765 So we can't even detect the first assignment to it and
2766 watch after that (since the garbage may or may not equal
2767 the first value assigned). */
2768 /* We print all the stop information in print_it_typical(), but
2769 in this case, by the time we call print_it_typical() this bp
2770 will be deleted already. So we have no choice but print the
2771 information here. */
2772 if (ui_out_is_mi_like_p (uiout
))
2774 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
2775 ui_out_text (uiout
, "\nWatchpoint ");
2776 ui_out_field_int (uiout
, "wpnum", b
->number
);
2777 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2778 which its expression is valid.\n");
2780 if (b
->related_breakpoint
)
2781 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2782 b
->disposition
= disp_del_at_next_stop
;
2788 /* Return true if it looks like target has stopped due to hitting
2789 breakpoint location BL. This function does not check if we
2790 should stop, only if BL explains the stop. */
2792 bpstat_check_location (const struct bp_location
*bl
, CORE_ADDR bp_addr
)
2794 struct breakpoint
*b
= bl
->owner
;
2796 if (b
->type
!= bp_watchpoint
2797 && b
->type
!= bp_hardware_watchpoint
2798 && b
->type
!= bp_read_watchpoint
2799 && b
->type
!= bp_access_watchpoint
2800 && b
->type
!= bp_hardware_breakpoint
2801 && b
->type
!= bp_catchpoint
) /* a non-watchpoint bp */
2803 if (bl
->address
!= bp_addr
) /* address doesn't match */
2805 if (overlay_debugging
/* unmapped overlay section */
2806 && section_is_overlay (bl
->section
)
2807 && !section_is_mapped (bl
->section
))
2811 /* Continuable hardware watchpoints are treated as non-existent if the
2812 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2813 some data address). Otherwise gdb won't stop on a break instruction
2814 in the code (not from a breakpoint) when a hardware watchpoint has
2815 been defined. Also skip watchpoints which we know did not trigger
2816 (did not match the data address). */
2818 if ((b
->type
== bp_hardware_watchpoint
2819 || b
->type
== bp_read_watchpoint
2820 || b
->type
== bp_access_watchpoint
)
2821 && b
->watchpoint_triggered
== watch_triggered_no
)
2824 if (b
->type
== bp_hardware_breakpoint
)
2826 if (bl
->address
!= bp_addr
)
2828 if (overlay_debugging
/* unmapped overlay section */
2829 && section_is_overlay (bl
->section
)
2830 && !section_is_mapped (bl
->section
))
2834 if (b
->type
== bp_catchpoint
)
2836 gdb_assert (b
->ops
!= NULL
&& b
->ops
->breakpoint_hit
!= NULL
);
2837 if (!b
->ops
->breakpoint_hit (b
))
2844 /* If BS refers to a watchpoint, determine if the watched values
2845 has actually changed, and we should stop. If not, set BS->stop
2848 bpstat_check_watchpoint (bpstat bs
)
2850 const struct bp_location
*bl
= bs
->breakpoint_at
;
2851 struct breakpoint
*b
= bl
->owner
;
2853 if (b
->type
== bp_watchpoint
2854 || b
->type
== bp_read_watchpoint
2855 || b
->type
== bp_access_watchpoint
2856 || b
->type
== bp_hardware_watchpoint
)
2860 int must_check_value
= 0;
2862 if (b
->type
== bp_watchpoint
)
2863 /* For a software watchpoint, we must always check the
2865 must_check_value
= 1;
2866 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
2867 /* We have a hardware watchpoint (read, write, or access)
2868 and the target earlier reported an address watched by
2870 must_check_value
= 1;
2871 else if (b
->watchpoint_triggered
== watch_triggered_unknown
2872 && b
->type
== bp_hardware_watchpoint
)
2873 /* We were stopped by a hardware watchpoint, but the target could
2874 not report the data address. We must check the watchpoint's
2875 value. Access and read watchpoints are out of luck; without
2876 a data address, we can't figure it out. */
2877 must_check_value
= 1;
2879 if (must_check_value
)
2881 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2883 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2884 int e
= catch_errors (watchpoint_check
, bs
, message
,
2886 do_cleanups (cleanups
);
2890 /* We've already printed what needs to be printed. */
2891 bs
->print_it
= print_it_done
;
2894 case WP_VALUE_CHANGED
:
2895 if (b
->type
== bp_read_watchpoint
)
2897 /* Don't stop: read watchpoints shouldn't fire if
2898 the value has changed. This is for targets
2899 which cannot set read-only watchpoints. */
2900 bs
->print_it
= print_it_noop
;
2904 case WP_VALUE_NOT_CHANGED
:
2905 if (b
->type
== bp_hardware_watchpoint
2906 || b
->type
== bp_watchpoint
)
2908 /* Don't stop: write watchpoints shouldn't fire if
2909 the value hasn't changed. */
2910 bs
->print_it
= print_it_noop
;
2918 /* Error from catch_errors. */
2919 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
2920 if (b
->related_breakpoint
)
2921 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2922 b
->disposition
= disp_del_at_next_stop
;
2923 /* We've already printed what needs to be printed. */
2924 bs
->print_it
= print_it_done
;
2928 else /* must_check_value == 0 */
2930 /* This is a case where some watchpoint(s) triggered, but
2931 not at the address of this watchpoint, or else no
2932 watchpoint triggered after all. So don't print
2933 anything for this watchpoint. */
2934 bs
->print_it
= print_it_noop
;
2941 /* Check conditions (condition proper, frame, thread and ignore count)
2942 of breakpoint referred to by BS. If we should not stop for this
2943 breakpoint, set BS->stop to 0. */
2945 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
2947 int thread_id
= pid_to_thread_id (ptid
);
2948 const struct bp_location
*bl
= bs
->breakpoint_at
;
2949 struct breakpoint
*b
= bl
->owner
;
2951 if (frame_id_p (b
->frame_id
)
2952 && !frame_id_eq (b
->frame_id
, get_frame_id (get_current_frame ())))
2956 int value_is_zero
= 0;
2958 /* If this is a scope breakpoint, mark the associated
2959 watchpoint as triggered so that we will handle the
2960 out-of-scope event. We'll get to the watchpoint next
2962 if (b
->type
== bp_watchpoint_scope
)
2963 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
2965 if (bl
->cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
2967 /* We use value_mark and value_free_to_mark because it could
2968 be a long time before we return to the command level and
2969 call free_all_values. We can't call free_all_values
2970 because we might be in the middle of evaluating a
2972 struct value
*mark
= value_mark ();
2974 /* Need to select the frame, with all that implies
2975 so that the conditions will have the right context. */
2976 select_frame (get_current_frame ());
2978 = catch_errors (breakpoint_cond_eval
, (bl
->cond
),
2979 "Error in testing breakpoint condition:\n",
2981 /* FIXME-someday, should give breakpoint # */
2982 value_free_to_mark (mark
);
2984 if (bl
->cond
&& value_is_zero
)
2988 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
2992 else if (b
->ignore_count
> 0)
2995 annotate_ignore_count_change ();
2997 /* Increase the hit count even though we don't
3005 /* Get a bpstat associated with having just stopped at address
3006 BP_ADDR in thread PTID.
3008 Determine whether we stopped at a breakpoint, etc, or whether we
3009 don't understand this stop. Result is a chain of bpstat's such that:
3011 if we don't understand the stop, the result is a null pointer.
3013 if we understand why we stopped, the result is not null.
3015 Each element of the chain refers to a particular breakpoint or
3016 watchpoint at which we have stopped. (We may have stopped for
3017 several reasons concurrently.)
3019 Each element of the chain has valid next, breakpoint_at,
3020 commands, FIXME??? fields. */
3023 bpstat_stop_status (CORE_ADDR bp_addr
, ptid_t ptid
)
3025 struct breakpoint
*b
= NULL
;
3026 const struct bp_location
*bl
;
3027 struct bp_location
*loc
;
3028 /* Root of the chain of bpstat's */
3029 struct bpstats root_bs
[1];
3030 /* Pointer to the last thing in the chain currently. */
3031 bpstat bs
= root_bs
;
3033 int need_remove_insert
;
3035 ALL_BP_LOCATIONS (bl
)
3039 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
3042 /* For hardware watchpoints, we look only at the first location.
3043 The watchpoint_check function will work on entire expression,
3044 not the individual locations. For read watchopints, the
3045 watchpoints_triggered function have checked all locations
3048 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
3051 if (!bpstat_check_location (bl
, bp_addr
))
3054 /* Come here if it's a watchpoint, or if the break address matches */
3056 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
3058 /* Assume we stop. Should we find watchpoint that is not actually
3059 triggered, or if condition of breakpoint is false, we'll reset
3064 bpstat_check_watchpoint (bs
);
3068 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
3069 /* We do not stop for these. */
3072 bpstat_check_breakpoint_conditions (bs
, ptid
);
3078 /* We will stop here */
3079 if (b
->disposition
== disp_disable
)
3081 if (b
->enable_state
!= bp_permanent
)
3082 b
->enable_state
= bp_disabled
;
3083 update_global_location_list (0);
3087 bs
->commands
= b
->commands
;
3089 (strcmp ("silent", bs
->commands
->line
) == 0
3090 || (xdb_commands
&& strcmp ("Q", bs
->commands
->line
) == 0)))
3092 bs
->commands
= bs
->commands
->next
;
3095 bs
->commands
= copy_command_lines (bs
->commands
);
3098 /* Print nothing for this entry if we dont stop or if we dont print. */
3099 if (bs
->stop
== 0 || bs
->print
== 0)
3100 bs
->print_it
= print_it_noop
;
3103 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
3105 if (loc
->address
== bp_addr
)
3107 bs
= bpstat_alloc (loc
, bs
);
3108 /* For hits of moribund locations, we should just proceed. */
3111 bs
->print_it
= print_it_noop
;
3115 bs
->next
= NULL
; /* Terminate the chain */
3116 bs
= root_bs
->next
; /* Re-grab the head of the chain */
3118 /* If we aren't stopping, the value of some hardware watchpoint may
3119 not have changed, but the intermediate memory locations we are
3120 watching may have. Don't bother if we're stopping; this will get
3122 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3126 need_remove_insert
= 0;
3128 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3130 && bs
->breakpoint_at
->owner
3131 && (bs
->breakpoint_at
->owner
->type
== bp_hardware_watchpoint
3132 || bs
->breakpoint_at
->owner
->type
== bp_read_watchpoint
3133 || bs
->breakpoint_at
->owner
->type
== bp_access_watchpoint
))
3135 /* remove/insert can invalidate bs->breakpoint_at, if this
3136 location is no longer used by the watchpoint. Prevent
3137 further code from trying to use it. */
3138 bs
->breakpoint_at
= NULL
;
3139 need_remove_insert
= 1;
3142 if (need_remove_insert
)
3144 remove_breakpoints ();
3145 insert_breakpoints ();
3148 return root_bs
->next
;
3151 /* Tell what to do about this bpstat. */
3153 bpstat_what (bpstat bs
)
3155 /* Classify each bpstat as one of the following. */
3158 /* This bpstat element has no effect on the main_action. */
3161 /* There was a watchpoint, stop but don't print. */
3164 /* There was a watchpoint, stop and print. */
3167 /* There was a breakpoint but we're not stopping. */
3170 /* There was a breakpoint, stop but don't print. */
3173 /* There was a breakpoint, stop and print. */
3176 /* We hit the longjmp breakpoint. */
3179 /* We hit the longjmp_resume breakpoint. */
3182 /* We hit the step_resume breakpoint. */
3185 /* We hit the shared library event breakpoint. */
3188 /* This is just used to count how many enums there are. */
3192 /* Here is the table which drives this routine. So that we can
3193 format it pretty, we define some abbreviations for the
3194 enum bpstat_what codes. */
3195 #define kc BPSTAT_WHAT_KEEP_CHECKING
3196 #define ss BPSTAT_WHAT_STOP_SILENT
3197 #define sn BPSTAT_WHAT_STOP_NOISY
3198 #define sgl BPSTAT_WHAT_SINGLE
3199 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3200 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3201 #define sr BPSTAT_WHAT_STEP_RESUME
3202 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3204 /* "Can't happen." Might want to print an error message.
3205 abort() is not out of the question, but chances are GDB is just
3206 a bit confused, not unusable. */
3207 #define err BPSTAT_WHAT_STOP_NOISY
3209 /* Given an old action and a class, come up with a new action. */
3210 /* One interesting property of this table is that wp_silent is the same
3211 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3212 after stopping, the check for whether to step over a breakpoint
3213 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3214 reference to how we stopped. We retain separate wp_silent and
3215 bp_silent codes in case we want to change that someday.
3217 Another possibly interesting property of this table is that
3218 there's a partial ordering, priority-like, of the actions. Once
3219 you've decided that some action is appropriate, you'll never go
3220 back and decide something of a lower priority is better. The
3223 kc < clr sgl shl slr sn sr ss
3224 sgl < shl slr sn sr ss
3225 slr < err shl sn sr ss
3226 clr < err shl sn sr ss
3232 What I think this means is that we don't need a damned table
3233 here. If you just put the rows and columns in the right order,
3234 it'd look awfully regular. We could simply walk the bpstat list
3235 and choose the highest priority action we find, with a little
3236 logic to handle the 'err' cases. */
3238 /* step_resume entries: a step resume breakpoint overrides another
3239 breakpoint of signal handling (see comment in wait_for_inferior
3240 at where we set the step_resume breakpoint). */
3242 static const enum bpstat_what_main_action
3243 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
3246 /* kc ss sn sgl slr clr sr shl
3249 {kc
, ss
, sn
, sgl
, slr
, clr
, sr
, shl
},
3251 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
},
3253 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
},
3255 {sgl
, ss
, sn
, sgl
, slr
, slr
, sr
, shl
},
3257 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
},
3259 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
},
3261 {slr
, ss
, sn
, slr
, slr
, err
, sr
, shl
},
3263 {clr
, ss
, sn
, err
, err
, err
, sr
, shl
},
3265 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
3267 {shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
}
3280 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3281 struct bpstat_what retval
;
3283 retval
.call_dummy
= 0;
3284 for (; bs
!= NULL
; bs
= bs
->next
)
3286 enum class bs_class
= no_effect
;
3287 if (bs
->breakpoint_at
== NULL
)
3288 /* I suspect this can happen if it was a momentary breakpoint
3289 which has since been deleted. */
3291 if (bs
->breakpoint_at
->owner
== NULL
)
3292 bs_class
= bp_nostop
;
3294 switch (bs
->breakpoint_at
->owner
->type
)
3300 case bp_hardware_breakpoint
:
3306 bs_class
= bp_noisy
;
3308 bs_class
= bp_silent
;
3311 bs_class
= bp_nostop
;
3314 case bp_hardware_watchpoint
:
3315 case bp_read_watchpoint
:
3316 case bp_access_watchpoint
:
3320 bs_class
= wp_noisy
;
3322 bs_class
= wp_silent
;
3325 /* There was a watchpoint, but we're not stopping.
3326 This requires no further action. */
3327 bs_class
= no_effect
;
3330 bs_class
= long_jump
;
3332 case bp_longjmp_resume
:
3333 bs_class
= long_resume
;
3335 case bp_step_resume
:
3338 bs_class
= step_resume
;
3341 /* It is for the wrong frame. */
3342 bs_class
= bp_nostop
;
3344 case bp_watchpoint_scope
:
3345 bs_class
= bp_nostop
;
3347 case bp_shlib_event
:
3348 bs_class
= shlib_event
;
3350 case bp_thread_event
:
3351 case bp_overlay_event
:
3352 bs_class
= bp_nostop
;
3358 bs_class
= bp_noisy
;
3360 bs_class
= bp_silent
;
3363 /* There was a catchpoint, but we're not stopping.
3364 This requires no further action. */
3365 bs_class
= no_effect
;
3368 /* Make sure the action is stop (silent or noisy),
3369 so infrun.c pops the dummy frame. */
3370 bs_class
= bp_silent
;
3371 retval
.call_dummy
= 1;
3374 /* Tracepoint hits should not be reported back to GDB, and
3375 if one got through somehow, it should have been filtered
3377 internal_error (__FILE__
, __LINE__
,
3378 _("bpstat_what: bp_tracepoint encountered"));
3381 current_action
= table
[(int) bs_class
][(int) current_action
];
3383 retval
.main_action
= current_action
;
3387 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3388 without hardware support). This isn't related to a specific bpstat,
3389 just to things like whether watchpoints are set. */
3392 bpstat_should_step (void)
3394 struct breakpoint
*b
;
3396 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
3403 static void print_breakpoint_location (struct breakpoint
*b
,
3404 struct bp_location
*loc
,
3406 struct ui_stream
*stb
)
3411 = find_pc_sect_function (loc
->address
, loc
->section
);
3414 ui_out_text (uiout
, "in ");
3415 ui_out_field_string (uiout
, "func",
3416 SYMBOL_PRINT_NAME (sym
));
3417 ui_out_wrap_hint (uiout
, wrap_indent
);
3418 ui_out_text (uiout
, " at ");
3420 ui_out_field_string (uiout
, "file", b
->source_file
);
3421 ui_out_text (uiout
, ":");
3423 if (ui_out_is_mi_like_p (uiout
))
3425 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
3426 char *fullname
= symtab_to_fullname (sal
.symtab
);
3429 ui_out_field_string (uiout
, "fullname", fullname
);
3432 ui_out_field_int (uiout
, "line", b
->line_number
);
3436 ui_out_field_string (uiout
, "pending", b
->addr_string
);
3440 print_address_symbolic (loc
->address
, stb
->stream
, demangle
, "");
3441 ui_out_field_stream (uiout
, "at", stb
);
3445 /* Print B to gdb_stdout. */
3447 print_one_breakpoint_location (struct breakpoint
*b
,
3448 struct bp_location
*loc
,
3450 CORE_ADDR
*last_addr
)
3452 struct command_line
*l
;
3454 struct ep_type_description
3459 static struct ep_type_description bptypes
[] =
3461 {bp_none
, "?deleted?"},
3462 {bp_breakpoint
, "breakpoint"},
3463 {bp_hardware_breakpoint
, "hw breakpoint"},
3464 {bp_until
, "until"},
3465 {bp_finish
, "finish"},
3466 {bp_watchpoint
, "watchpoint"},
3467 {bp_hardware_watchpoint
, "hw watchpoint"},
3468 {bp_read_watchpoint
, "read watchpoint"},
3469 {bp_access_watchpoint
, "acc watchpoint"},
3470 {bp_longjmp
, "longjmp"},
3471 {bp_longjmp_resume
, "longjmp resume"},
3472 {bp_step_resume
, "step resume"},
3473 {bp_watchpoint_scope
, "watchpoint scope"},
3474 {bp_call_dummy
, "call dummy"},
3475 {bp_shlib_event
, "shlib events"},
3476 {bp_thread_event
, "thread events"},
3477 {bp_overlay_event
, "overlay events"},
3478 {bp_catchpoint
, "catchpoint"},
3479 {bp_tracepoint
, "tracepoint"},
3482 static char bpenables
[] = "nynny";
3483 char wrap_indent
[80];
3484 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3485 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3486 struct cleanup
*bkpt_chain
;
3488 int header_of_multiple
= 0;
3489 int part_of_multiple
= (loc
!= NULL
);
3490 struct value_print_options opts
;
3492 get_user_print_options (&opts
);
3494 gdb_assert (!loc
|| loc_number
!= 0);
3495 /* See comment in print_one_breakpoint concerning
3496 treatment of breakpoints with single disabled
3500 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
3501 header_of_multiple
= 1;
3506 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3510 if (part_of_multiple
)
3513 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
3514 ui_out_field_string (uiout
, "number", formatted
);
3519 ui_out_field_int (uiout
, "number", b
->number
);
3524 if (part_of_multiple
)
3525 ui_out_field_skip (uiout
, "type");
3528 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
3529 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3530 internal_error (__FILE__
, __LINE__
,
3531 _("bptypes table does not describe type #%d."),
3533 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3538 if (part_of_multiple
)
3539 ui_out_field_skip (uiout
, "disp");
3541 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3546 if (part_of_multiple
)
3547 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
3549 ui_out_field_fmt (uiout
, "enabled", "%c",
3550 bpenables
[(int) b
->enable_state
]);
3551 ui_out_spaces (uiout
, 2);
3555 strcpy (wrap_indent
, " ");
3556 if (opts
.addressprint
)
3558 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3559 strcat (wrap_indent
, " ");
3561 strcat (wrap_indent
, " ");
3564 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3566 /* Although the print_one can possibly print
3567 all locations, calling it here is not likely
3568 to get any nice result. So, make sure there's
3569 just one location. */
3570 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
3571 b
->ops
->print_one (b
, last_addr
);
3577 internal_error (__FILE__
, __LINE__
,
3578 _("print_one_breakpoint: bp_none encountered\n"));
3582 case bp_hardware_watchpoint
:
3583 case bp_read_watchpoint
:
3584 case bp_access_watchpoint
:
3585 /* Field 4, the address, is omitted (which makes the columns
3586 not line up too nicely with the headers, but the effect
3587 is relatively readable). */
3588 if (opts
.addressprint
)
3589 ui_out_field_skip (uiout
, "addr");
3591 ui_out_field_string (uiout
, "what", b
->exp_string
);
3595 case bp_hardware_breakpoint
:
3599 case bp_longjmp_resume
:
3600 case bp_step_resume
:
3601 case bp_watchpoint_scope
:
3603 case bp_shlib_event
:
3604 case bp_thread_event
:
3605 case bp_overlay_event
:
3607 if (opts
.addressprint
)
3610 if (header_of_multiple
)
3611 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
3612 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
3613 ui_out_field_string (uiout
, "addr", "<PENDING>");
3615 ui_out_field_core_addr (uiout
, "addr", loc
->address
);
3618 if (!header_of_multiple
)
3619 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
3621 *last_addr
= b
->loc
->address
;
3625 if (!part_of_multiple
)
3627 if (b
->thread
!= -1)
3629 /* FIXME: This seems to be redundant and lost here; see the
3630 "stop only in" line a little further down. */
3631 ui_out_text (uiout
, " thread ");
3632 ui_out_field_int (uiout
, "thread", b
->thread
);
3634 else if (b
->task
!= 0)
3636 ui_out_text (uiout
, " task ");
3637 ui_out_field_int (uiout
, "task", b
->task
);
3641 ui_out_text (uiout
, "\n");
3643 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
3646 ui_out_text (uiout
, "\tstop only in stack frame at ");
3647 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3649 ui_out_field_core_addr (uiout
, "frame", b
->frame_id
.stack_addr
);
3650 ui_out_text (uiout
, "\n");
3653 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
3655 /* We do not print the condition for Ada exception catchpoints
3656 because the condition is an internal implementation detail
3657 that we do not want to expose to the user. */
3659 if (b
->type
== bp_tracepoint
)
3660 ui_out_text (uiout
, "\ttrace only if ");
3662 ui_out_text (uiout
, "\tstop only if ");
3663 ui_out_field_string (uiout
, "cond", b
->cond_string
);
3664 ui_out_text (uiout
, "\n");
3667 if (!part_of_multiple
&& b
->thread
!= -1)
3669 /* FIXME should make an annotation for this */
3670 ui_out_text (uiout
, "\tstop only in thread ");
3671 ui_out_field_int (uiout
, "thread", b
->thread
);
3672 ui_out_text (uiout
, "\n");
3675 if (!part_of_multiple
&& b
->hit_count
)
3677 /* FIXME should make an annotation for this */
3678 if (ep_is_catchpoint (b
))
3679 ui_out_text (uiout
, "\tcatchpoint");
3681 ui_out_text (uiout
, "\tbreakpoint");
3682 ui_out_text (uiout
, " already hit ");
3683 ui_out_field_int (uiout
, "times", b
->hit_count
);
3684 if (b
->hit_count
== 1)
3685 ui_out_text (uiout
, " time\n");
3687 ui_out_text (uiout
, " times\n");
3690 /* Output the count also if it is zero, but only if this is
3691 mi. FIXME: Should have a better test for this. */
3692 if (ui_out_is_mi_like_p (uiout
))
3693 if (!part_of_multiple
&& b
->hit_count
== 0)
3694 ui_out_field_int (uiout
, "times", b
->hit_count
);
3696 if (!part_of_multiple
&& b
->ignore_count
)
3699 ui_out_text (uiout
, "\tignore next ");
3700 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3701 ui_out_text (uiout
, " hits\n");
3704 if (!part_of_multiple
&& (l
= b
->commands
))
3706 struct cleanup
*script_chain
;
3709 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3710 print_command_lines (uiout
, l
, 4);
3711 do_cleanups (script_chain
);
3714 if (!part_of_multiple
&& b
->pass_count
)
3716 annotate_field (10);
3717 ui_out_text (uiout
, "\tpass count ");
3718 ui_out_field_int (uiout
, "pass", b
->pass_count
);
3719 ui_out_text (uiout
, " \n");
3722 if (!part_of_multiple
&& b
->step_count
)
3724 annotate_field (11);
3725 ui_out_text (uiout
, "\tstep count ");
3726 ui_out_field_int (uiout
, "step", b
->step_count
);
3727 ui_out_text (uiout
, " \n");
3730 if (!part_of_multiple
&& b
->actions
)
3732 struct action_line
*action
;
3733 annotate_field (12);
3734 for (action
= b
->actions
; action
; action
= action
->next
)
3736 ui_out_text (uiout
, " A\t");
3737 ui_out_text (uiout
, action
->action
);
3738 ui_out_text (uiout
, "\n");
3742 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
3745 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
3746 else if (b
->exp_string
)
3747 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
3750 do_cleanups (bkpt_chain
);
3751 do_cleanups (old_chain
);
3755 print_one_breakpoint (struct breakpoint
*b
,
3756 CORE_ADDR
*last_addr
)
3758 print_one_breakpoint_location (b
, NULL
, 0, last_addr
);
3760 /* If this breakpoint has custom print function,
3761 it's already printed. Otherwise, print individual
3762 locations, if any. */
3763 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
3765 /* If breakpoint has a single location that is
3766 disabled, we print it as if it had
3767 several locations, since otherwise it's hard to
3768 represent "breakpoint enabled, location disabled"
3770 Note that while hardware watchpoints have
3771 several locations internally, that's no a property
3774 && !is_hardware_watchpoint (b
)
3775 && (b
->loc
->next
|| !b
->loc
->enabled
)
3776 && !ui_out_is_mi_like_p (uiout
))
3778 struct bp_location
*loc
;
3780 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
3781 print_one_breakpoint_location (b
, loc
, n
, last_addr
);
3787 struct captured_breakpoint_query_args
3793 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3795 struct captured_breakpoint_query_args
*args
= data
;
3796 struct breakpoint
*b
;
3797 CORE_ADDR dummy_addr
= 0;
3800 if (args
->bnum
== b
->number
)
3802 print_one_breakpoint (b
, &dummy_addr
);
3810 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
3812 struct captured_breakpoint_query_args args
;
3814 /* For the moment we don't trust print_one_breakpoint() to not throw
3816 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
3817 error_message
, RETURN_MASK_ALL
) < 0)
3823 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3824 catchpoints, et.al.). */
3827 user_settable_breakpoint (const struct breakpoint
*b
)
3829 return (b
->type
== bp_breakpoint
3830 || b
->type
== bp_catchpoint
3831 || b
->type
== bp_hardware_breakpoint
3832 || b
->type
== bp_tracepoint
3833 || b
->type
== bp_watchpoint
3834 || b
->type
== bp_read_watchpoint
3835 || b
->type
== bp_access_watchpoint
3836 || b
->type
== bp_hardware_watchpoint
);
3839 /* Print information on user settable breakpoint (watchpoint, etc)
3840 number BNUM. If BNUM is -1 print all user settable breakpoints.
3841 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3844 breakpoint_1 (int bnum
, int allflag
)
3846 struct breakpoint
*b
;
3847 CORE_ADDR last_addr
= (CORE_ADDR
) -1;
3848 int nr_printable_breakpoints
;
3849 struct cleanup
*bkpttbl_chain
;
3850 struct value_print_options opts
;
3852 get_user_print_options (&opts
);
3854 /* Compute the number of rows in the table. */
3855 nr_printable_breakpoints
= 0;
3858 || bnum
== b
->number
)
3860 if (allflag
|| user_settable_breakpoint (b
))
3861 nr_printable_breakpoints
++;
3864 if (opts
.addressprint
)
3866 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
3870 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
3873 if (nr_printable_breakpoints
> 0)
3874 annotate_breakpoints_headers ();
3875 if (nr_printable_breakpoints
> 0)
3877 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
3878 if (nr_printable_breakpoints
> 0)
3880 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
3881 if (nr_printable_breakpoints
> 0)
3883 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
3884 if (nr_printable_breakpoints
> 0)
3886 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
3887 if (opts
.addressprint
)
3889 if (nr_printable_breakpoints
> 0)
3891 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3892 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
3894 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
3896 if (nr_printable_breakpoints
> 0)
3898 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
3899 ui_out_table_body (uiout
);
3900 if (nr_printable_breakpoints
> 0)
3901 annotate_breakpoints_table ();
3905 || bnum
== b
->number
)
3907 /* We only print out user settable breakpoints unless the
3909 if (allflag
|| user_settable_breakpoint (b
))
3910 print_one_breakpoint (b
, &last_addr
);
3913 do_cleanups (bkpttbl_chain
);
3915 if (nr_printable_breakpoints
== 0)
3918 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
3920 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
3925 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3926 that a comparison of an unsigned with -1 is always false. */
3927 if (last_addr
!= (CORE_ADDR
) -1 && !server_command
)
3928 set_next_address (current_gdbarch
, last_addr
);
3931 /* FIXME? Should this be moved up so that it is only called when
3932 there have been breakpoints? */
3933 annotate_breakpoints_table_end ();
3937 breakpoints_info (char *bnum_exp
, int from_tty
)
3942 bnum
= parse_and_eval_long (bnum_exp
);
3944 breakpoint_1 (bnum
, 0);
3948 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
3953 bnum
= parse_and_eval_long (bnum_exp
);
3955 breakpoint_1 (bnum
, 1);
3959 breakpoint_has_pc (struct breakpoint
*b
,
3960 CORE_ADDR pc
, struct obj_section
*section
)
3962 struct bp_location
*bl
= b
->loc
;
3963 for (; bl
; bl
= bl
->next
)
3965 if (bl
->address
== pc
3966 && (!overlay_debugging
|| bl
->section
== section
))
3972 /* Print a message describing any breakpoints set at PC. */
3975 describe_other_breakpoints (CORE_ADDR pc
, struct obj_section
*section
,
3979 struct breakpoint
*b
;
3982 others
+= breakpoint_has_pc (b
, pc
, section
);
3986 printf_filtered (_("Note: breakpoint "));
3987 else /* if (others == ???) */
3988 printf_filtered (_("Note: breakpoints "));
3990 if (breakpoint_has_pc (b
, pc
, section
))
3993 printf_filtered ("%d", b
->number
);
3994 if (b
->thread
== -1 && thread
!= -1)
3995 printf_filtered (" (all threads)");
3996 else if (b
->thread
!= -1)
3997 printf_filtered (" (thread %d)", b
->thread
);
3998 printf_filtered ("%s%s ",
3999 ((b
->enable_state
== bp_disabled
||
4000 b
->enable_state
== bp_call_disabled
)
4002 : b
->enable_state
== bp_permanent
4006 : ((others
== 1) ? " and" : ""));
4008 printf_filtered (_("also set at pc "));
4009 fputs_filtered (paddress (pc
), gdb_stdout
);
4010 printf_filtered (".\n");
4014 /* Set the default place to put a breakpoint
4015 for the `break' command with no arguments. */
4018 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
4021 default_breakpoint_valid
= valid
;
4022 default_breakpoint_address
= addr
;
4023 default_breakpoint_symtab
= symtab
;
4024 default_breakpoint_line
= line
;
4027 /* Return true iff it is meaningful to use the address member of
4028 BPT. For some breakpoint types, the address member is irrelevant
4029 and it makes no sense to attempt to compare it to other addresses
4030 (or use it for any other purpose either).
4032 More specifically, each of the following breakpoint types will always
4033 have a zero valued address and we don't want check_duplicates() to mark
4034 breakpoints of any of these types to be a duplicate of an actual
4035 breakpoint at address zero:
4038 bp_hardware_watchpoint
4040 bp_access_watchpoint
4044 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
4046 enum bptype type
= bpt
->type
;
4048 return (type
!= bp_watchpoint
4049 && type
!= bp_hardware_watchpoint
4050 && type
!= bp_read_watchpoint
4051 && type
!= bp_access_watchpoint
4052 && type
!= bp_catchpoint
);
4055 /* Rescan breakpoints at the same address and section as BPT,
4056 marking the first one as "first" and any others as "duplicates".
4057 This is so that the bpt instruction is only inserted once.
4058 If we have a permanent breakpoint at the same place as BPT, make
4059 that one the official one, and the rest as duplicates. */
4062 check_duplicates_for (CORE_ADDR address
, struct obj_section
*section
)
4064 struct bp_location
*b
;
4066 struct bp_location
*perm_bp
= 0;
4068 ALL_BP_LOCATIONS (b
)
4069 if (b
->owner
->enable_state
!= bp_disabled
4070 && b
->owner
->enable_state
!= bp_call_disabled
4072 && !b
->shlib_disabled
4073 && b
->address
== address
/* address / overlay match */
4074 && (!overlay_debugging
|| b
->section
== section
)
4075 && breakpoint_address_is_meaningful (b
->owner
))
4077 /* Have we found a permanent breakpoint? */
4078 if (b
->owner
->enable_state
== bp_permanent
)
4085 b
->duplicate
= count
> 1;
4088 /* If we found a permanent breakpoint at this address, go over the
4089 list again and declare all the other breakpoints there (except
4090 other permanent breakpoints) to be the duplicates. */
4093 perm_bp
->duplicate
= 0;
4095 /* Permanent breakpoint should always be inserted. */
4096 if (! perm_bp
->inserted
)
4097 internal_error (__FILE__
, __LINE__
,
4098 _("allegedly permanent breakpoint is not "
4099 "actually inserted"));
4101 ALL_BP_LOCATIONS (b
)
4104 if (b
->owner
->enable_state
!= bp_permanent
4105 && b
->owner
->enable_state
!= bp_disabled
4106 && b
->owner
->enable_state
!= bp_call_disabled
4107 && b
->enabled
&& !b
->shlib_disabled
4108 && b
->address
== address
/* address / overlay match */
4109 && (!overlay_debugging
|| b
->section
== section
)
4110 && breakpoint_address_is_meaningful (b
->owner
))
4113 internal_error (__FILE__
, __LINE__
,
4114 _("another breakpoint was inserted on top of "
4115 "a permanent breakpoint"));
4124 check_duplicates (struct breakpoint
*bpt
)
4126 struct bp_location
*bl
= bpt
->loc
;
4128 if (! breakpoint_address_is_meaningful (bpt
))
4131 for (; bl
; bl
= bl
->next
)
4132 check_duplicates_for (bl
->address
, bl
->section
);
4136 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
4137 int bnum
, int have_bnum
)
4142 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
4143 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
4145 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4146 bnum
, astr1
, astr2
);
4148 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
4151 /* Adjust a breakpoint's address to account for architectural constraints
4152 on breakpoint placement. Return the adjusted address. Note: Very
4153 few targets require this kind of adjustment. For most targets,
4154 this function is simply the identity function. */
4157 adjust_breakpoint_address (CORE_ADDR bpaddr
, enum bptype bptype
)
4159 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch
))
4161 /* Very few targets need any kind of breakpoint adjustment. */
4164 else if (bptype
== bp_watchpoint
4165 || bptype
== bp_hardware_watchpoint
4166 || bptype
== bp_read_watchpoint
4167 || bptype
== bp_access_watchpoint
4168 || bptype
== bp_catchpoint
)
4170 /* Watchpoints and the various bp_catch_* eventpoints should not
4171 have their addresses modified. */
4176 CORE_ADDR adjusted_bpaddr
;
4178 /* Some targets have architectural constraints on the placement
4179 of breakpoint instructions. Obtain the adjusted address. */
4180 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (current_gdbarch
,
4183 /* An adjusted breakpoint address can significantly alter
4184 a user's expectations. Print a warning if an adjustment
4186 if (adjusted_bpaddr
!= bpaddr
)
4187 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
4189 return adjusted_bpaddr
;
4193 /* Allocate a struct bp_location. */
4195 static struct bp_location
*
4196 allocate_bp_location (struct breakpoint
*bpt
)
4198 struct bp_location
*loc
, *loc_p
;
4200 loc
= xmalloc (sizeof (struct bp_location
));
4201 memset (loc
, 0, sizeof (*loc
));
4205 loc
->shlib_disabled
= 0;
4215 case bp_longjmp_resume
:
4216 case bp_step_resume
:
4217 case bp_watchpoint_scope
:
4219 case bp_shlib_event
:
4220 case bp_thread_event
:
4221 case bp_overlay_event
:
4222 loc
->loc_type
= bp_loc_software_breakpoint
;
4224 case bp_hardware_breakpoint
:
4225 loc
->loc_type
= bp_loc_hardware_breakpoint
;
4227 case bp_hardware_watchpoint
:
4228 case bp_read_watchpoint
:
4229 case bp_access_watchpoint
:
4230 loc
->loc_type
= bp_loc_hardware_watchpoint
;
4234 loc
->loc_type
= bp_loc_other
;
4237 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
4243 static void free_bp_location (struct bp_location
*loc
)
4248 if (loc
->function_name
)
4249 xfree (loc
->function_name
);
4254 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4255 that has type BPTYPE and has no locations as yet. */
4257 static struct breakpoint
*
4258 set_raw_breakpoint_without_location (enum bptype bptype
)
4260 struct breakpoint
*b
, *b1
;
4262 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
4263 memset (b
, 0, sizeof (*b
));
4266 b
->language
= current_language
->la_language
;
4267 b
->input_radix
= input_radix
;
4269 b
->enable_state
= bp_enabled
;
4272 b
->ignore_count
= 0;
4274 b
->frame_id
= null_frame_id
;
4275 b
->forked_inferior_pid
= null_ptid
;
4276 b
->exec_pathname
= NULL
;
4278 b
->condition_not_parsed
= 0;
4280 /* Add this breakpoint to the end of the chain
4281 so that a list of breakpoints will come out in order
4282 of increasing numbers. */
4284 b1
= breakpoint_chain
;
4286 breakpoint_chain
= b
;
4296 /* Initialize loc->function_name. */
4298 set_breakpoint_location_function (struct bp_location
*loc
)
4300 if (loc
->owner
->type
== bp_breakpoint
4301 || loc
->owner
->type
== bp_hardware_breakpoint
4302 || loc
->owner
->type
== bp_tracepoint
)
4304 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
4306 if (loc
->function_name
)
4307 loc
->function_name
= xstrdup (loc
->function_name
);
4311 /* set_raw_breakpoint is a low level routine for allocating and
4312 partially initializing a breakpoint of type BPTYPE. The newly
4313 created breakpoint's address, section, source file name, and line
4314 number are provided by SAL. The newly created and partially
4315 initialized breakpoint is added to the breakpoint chain and
4316 is also returned as the value of this function.
4318 It is expected that the caller will complete the initialization of
4319 the newly created breakpoint struct as well as output any status
4320 information regarding the creation of a new breakpoint. In
4321 particular, set_raw_breakpoint does NOT set the breakpoint
4322 number! Care should be taken to not allow an error to occur
4323 prior to completing the initialization of the breakpoint. If this
4324 should happen, a bogus breakpoint will be left on the chain. */
4327 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
4329 struct breakpoint
*b
= set_raw_breakpoint_without_location (bptype
);
4330 CORE_ADDR adjusted_address
;
4332 /* Adjust the breakpoint's address prior to allocating a location.
4333 Once we call allocate_bp_location(), that mostly uninitialized
4334 location will be placed on the location chain. Adjustment of the
4335 breakpoint may cause target_read_memory() to be called and we do
4336 not want its scan of the location chain to find a breakpoint and
4337 location that's only been partially initialized. */
4338 adjusted_address
= adjust_breakpoint_address (sal
.pc
, b
->type
);
4340 b
->loc
= allocate_bp_location (b
);
4341 b
->loc
->requested_address
= sal
.pc
;
4342 b
->loc
->address
= adjusted_address
;
4344 if (sal
.symtab
== NULL
)
4345 b
->source_file
= NULL
;
4347 b
->source_file
= savestring (sal
.symtab
->filename
,
4348 strlen (sal
.symtab
->filename
));
4349 b
->loc
->section
= sal
.section
;
4350 b
->line_number
= sal
.line
;
4352 set_breakpoint_location_function (b
->loc
);
4354 breakpoints_changed ();
4360 /* Note that the breakpoint object B describes a permanent breakpoint
4361 instruction, hard-wired into the inferior's code. */
4363 make_breakpoint_permanent (struct breakpoint
*b
)
4365 struct bp_location
*bl
;
4366 b
->enable_state
= bp_permanent
;
4368 /* By definition, permanent breakpoints are already present in the code.
4369 Mark all locations as inserted. For now, make_breakpoint_permanent
4370 is called in just one place, so it's hard to say if it's reasonable
4371 to have permanent breakpoint with multiple locations or not,
4372 but it's easy to implmement. */
4373 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
4377 static struct breakpoint
*
4378 create_internal_breakpoint (CORE_ADDR address
, enum bptype type
)
4380 static int internal_breakpoint_number
= -1;
4381 struct symtab_and_line sal
;
4382 struct breakpoint
*b
;
4384 init_sal (&sal
); /* initialize to zeroes */
4387 sal
.section
= find_pc_overlay (sal
.pc
);
4389 b
= set_raw_breakpoint (sal
, type
);
4390 b
->number
= internal_breakpoint_number
--;
4391 b
->disposition
= disp_donttouch
;
4398 create_longjmp_breakpoint (char *func_name
)
4400 struct minimal_symbol
*m
;
4402 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4404 set_momentary_breakpoint_at_pc (SYMBOL_VALUE_ADDRESS (m
), bp_longjmp
);
4405 update_global_location_list (1);
4408 /* Call this routine when stepping and nexting to enable a breakpoint
4409 if we do a longjmp(). When we hit that breakpoint, call
4410 set_longjmp_resume_breakpoint() to figure out where we are going. */
4413 set_longjmp_breakpoint (void)
4415 if (gdbarch_get_longjmp_target_p (current_gdbarch
))
4417 create_longjmp_breakpoint ("longjmp");
4418 create_longjmp_breakpoint ("_longjmp");
4419 create_longjmp_breakpoint ("siglongjmp");
4420 create_longjmp_breakpoint ("_siglongjmp");
4424 /* Delete all longjmp breakpoints from THREAD. */
4426 delete_longjmp_breakpoint (int thread
)
4428 struct breakpoint
*b
, *temp
;
4430 ALL_BREAKPOINTS_SAFE (b
, temp
)
4431 if (b
->type
== bp_longjmp
)
4433 if (b
->thread
== thread
)
4434 delete_breakpoint (b
);
4439 create_overlay_event_breakpoint_1 (char *func_name
, struct objfile
*objfile
)
4441 struct breakpoint
*b
;
4442 struct minimal_symbol
*m
;
4444 if ((m
= lookup_minimal_symbol_text (func_name
, objfile
)) == NULL
)
4447 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
),
4449 b
->addr_string
= xstrdup (func_name
);
4451 if (overlay_debugging
== ovly_auto
)
4453 b
->enable_state
= bp_enabled
;
4454 overlay_events_enabled
= 1;
4458 b
->enable_state
= bp_disabled
;
4459 overlay_events_enabled
= 0;
4461 update_global_location_list (1);
4465 create_overlay_event_breakpoint (char *func_name
)
4467 struct objfile
*objfile
;
4468 ALL_OBJFILES (objfile
)
4469 create_overlay_event_breakpoint_1 (func_name
, objfile
);
4473 enable_overlay_breakpoints (void)
4475 struct breakpoint
*b
;
4478 if (b
->type
== bp_overlay_event
)
4480 b
->enable_state
= bp_enabled
;
4481 update_global_location_list (1);
4482 overlay_events_enabled
= 1;
4487 disable_overlay_breakpoints (void)
4489 struct breakpoint
*b
;
4492 if (b
->type
== bp_overlay_event
)
4494 b
->enable_state
= bp_disabled
;
4495 update_global_location_list (0);
4496 overlay_events_enabled
= 0;
4501 create_thread_event_breakpoint (CORE_ADDR address
)
4503 struct breakpoint
*b
;
4505 b
= create_internal_breakpoint (address
, bp_thread_event
);
4507 b
->enable_state
= bp_enabled
;
4508 /* addr_string has to be used or breakpoint_re_set will delete me. */
4509 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
4511 update_global_location_list_nothrow (1);
4517 remove_thread_event_breakpoints (void)
4519 struct breakpoint
*b
, *temp
;
4521 ALL_BREAKPOINTS_SAFE (b
, temp
)
4522 if (b
->type
== bp_thread_event
)
4523 delete_breakpoint (b
);
4526 struct captured_parse_breakpoint_args
4529 struct symtabs_and_lines
*sals_p
;
4530 char ***addr_string_p
;
4534 struct lang_and_radix
4542 remove_solib_event_breakpoints (void)
4544 struct breakpoint
*b
, *temp
;
4546 ALL_BREAKPOINTS_SAFE (b
, temp
)
4547 if (b
->type
== bp_shlib_event
)
4548 delete_breakpoint (b
);
4552 create_solib_event_breakpoint (CORE_ADDR address
)
4554 struct breakpoint
*b
;
4556 b
= create_internal_breakpoint (address
, bp_shlib_event
);
4557 update_global_location_list_nothrow (1);
4561 /* Disable any breakpoints that are on code in shared libraries. Only
4562 apply to enabled breakpoints, disabled ones can just stay disabled. */
4565 disable_breakpoints_in_shlibs (void)
4567 struct bp_location
*loc
;
4569 ALL_BP_LOCATIONS (loc
)
4571 struct breakpoint
*b
= loc
->owner
;
4572 /* We apply the check to all breakpoints, including disabled
4573 for those with loc->duplicate set. This is so that when breakpoint
4574 becomes enabled, or the duplicate is removed, gdb will try to insert
4575 all breakpoints. If we don't set shlib_disabled here, we'll try
4576 to insert those breakpoints and fail. */
4577 if (((b
->type
== bp_breakpoint
)
4578 || (b
->type
== bp_hardware_breakpoint
)
4579 || (b
->type
== bp_tracepoint
))
4580 && !loc
->shlib_disabled
4582 && PC_SOLIB (loc
->address
)
4584 && solib_name_from_address (loc
->address
)
4588 loc
->shlib_disabled
= 1;
4593 /* Disable any breakpoints that are in in an unloaded shared library. Only
4594 apply to enabled breakpoints, disabled ones can just stay disabled. */
4597 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
4599 struct bp_location
*loc
;
4600 int disabled_shlib_breaks
= 0;
4602 /* SunOS a.out shared libraries are always mapped, so do not
4603 disable breakpoints; they will only be reported as unloaded
4604 through clear_solib when GDB discards its shared library
4605 list. See clear_solib for more information. */
4606 if (exec_bfd
!= NULL
4607 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
4610 ALL_BP_LOCATIONS (loc
)
4612 struct breakpoint
*b
= loc
->owner
;
4613 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
4614 || loc
->loc_type
== bp_loc_software_breakpoint
)
4615 && !loc
->shlib_disabled
4616 && (b
->type
== bp_breakpoint
|| b
->type
== bp_hardware_breakpoint
)
4617 && solib_contains_address_p (solib
, loc
->address
))
4619 loc
->shlib_disabled
= 1;
4620 /* At this point, we cannot rely on remove_breakpoint
4621 succeeding so we must mark the breakpoint as not inserted
4622 to prevent future errors occurring in remove_breakpoints. */
4624 if (!disabled_shlib_breaks
)
4626 target_terminal_ours_for_output ();
4627 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4630 disabled_shlib_breaks
= 1;
4635 /* FORK & VFORK catchpoints. */
4637 /* Implement the "insert" breakpoint_ops method for fork catchpoints. */
4640 insert_catch_fork (struct breakpoint
*b
)
4642 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
4645 /* Implement the "remove" breakpoint_ops method for fork catchpoints. */
4648 remove_catch_fork (struct breakpoint
*b
)
4650 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
4653 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
4657 breakpoint_hit_catch_fork (struct breakpoint
*b
)
4659 return inferior_has_forked (inferior_ptid
, &b
->forked_inferior_pid
);
4662 /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */
4664 static enum print_stop_action
4665 print_it_catch_fork (struct breakpoint
*b
)
4667 annotate_catchpoint (b
->number
);
4668 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
4669 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
4670 return PRINT_SRC_AND_LOC
;
4673 /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */
4676 print_one_catch_fork (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
4678 struct value_print_options opts
;
4680 get_user_print_options (&opts
);
4682 /* Field 4, the address, is omitted (which makes the columns
4683 not line up too nicely with the headers, but the effect
4684 is relatively readable). */
4685 if (opts
.addressprint
)
4686 ui_out_field_skip (uiout
, "addr");
4688 ui_out_text (uiout
, "fork");
4689 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
4691 ui_out_text (uiout
, ", process ");
4692 ui_out_field_int (uiout
, "what",
4693 ptid_get_pid (b
->forked_inferior_pid
));
4694 ui_out_spaces (uiout
, 1);
4698 /* Implement the "print_mention" breakpoint_ops method for fork
4702 print_mention_catch_fork (struct breakpoint
*b
)
4704 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
4707 /* The breakpoint_ops structure to be used in fork catchpoints. */
4709 static struct breakpoint_ops catch_fork_breakpoint_ops
=
4713 breakpoint_hit_catch_fork
,
4714 print_it_catch_fork
,
4715 print_one_catch_fork
,
4716 print_mention_catch_fork
4719 /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */
4722 insert_catch_vfork (struct breakpoint
*b
)
4724 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
4727 /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */
4730 remove_catch_vfork (struct breakpoint
*b
)
4732 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
4735 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
4739 breakpoint_hit_catch_vfork (struct breakpoint
*b
)
4741 return inferior_has_vforked (inferior_ptid
, &b
->forked_inferior_pid
);
4744 /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */
4746 static enum print_stop_action
4747 print_it_catch_vfork (struct breakpoint
*b
)
4749 annotate_catchpoint (b
->number
);
4750 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
4751 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
4752 return PRINT_SRC_AND_LOC
;
4755 /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */
4758 print_one_catch_vfork (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
4760 struct value_print_options opts
;
4762 get_user_print_options (&opts
);
4763 /* Field 4, the address, is omitted (which makes the columns
4764 not line up too nicely with the headers, but the effect
4765 is relatively readable). */
4766 if (opts
.addressprint
)
4767 ui_out_field_skip (uiout
, "addr");
4769 ui_out_text (uiout
, "vfork");
4770 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
4772 ui_out_text (uiout
, ", process ");
4773 ui_out_field_int (uiout
, "what",
4774 ptid_get_pid (b
->forked_inferior_pid
));
4775 ui_out_spaces (uiout
, 1);
4779 /* Implement the "print_mention" breakpoint_ops method for vfork
4783 print_mention_catch_vfork (struct breakpoint
*b
)
4785 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
4788 /* The breakpoint_ops structure to be used in vfork catchpoints. */
4790 static struct breakpoint_ops catch_vfork_breakpoint_ops
=
4794 breakpoint_hit_catch_vfork
,
4795 print_it_catch_vfork
,
4796 print_one_catch_vfork
,
4797 print_mention_catch_vfork
4800 /* Create a new breakpoint of the bp_catchpoint kind and return it.
4802 If TEMPFLAG is non-zero, then make the breakpoint temporary.
4803 If COND_STRING is not NULL, then store it in the breakpoint.
4804 OPS, if not NULL, is the breakpoint_ops structure associated
4805 to the catchpoint. */
4807 static struct breakpoint
*
4808 create_catchpoint (int tempflag
, char *cond_string
,
4809 struct breakpoint_ops
*ops
)
4811 struct symtab_and_line sal
;
4812 struct breakpoint
*b
;
4819 b
= set_raw_breakpoint (sal
, bp_catchpoint
);
4820 set_breakpoint_count (breakpoint_count
+ 1);
4821 b
->number
= breakpoint_count
;
4823 b
->cond_string
= (cond_string
== NULL
) ?
4824 NULL
: savestring (cond_string
, strlen (cond_string
));
4826 b
->addr_string
= NULL
;
4827 b
->enable_state
= bp_enabled
;
4828 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4832 update_global_location_list (1);
4838 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4839 struct breakpoint_ops
*ops
)
4841 struct breakpoint
*b
= create_catchpoint (tempflag
, cond_string
, ops
);
4843 /* FIXME: We should put this information in a breakpoint private data
4845 b
->forked_inferior_pid
= null_ptid
;
4848 /* Exec catchpoints. */
4851 insert_catch_exec (struct breakpoint
*b
)
4853 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
4857 remove_catch_exec (struct breakpoint
*b
)
4859 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
4863 breakpoint_hit_catch_exec (struct breakpoint
*b
)
4865 return inferior_has_execd (inferior_ptid
, &b
->exec_pathname
);
4868 static enum print_stop_action
4869 print_it_catch_exec (struct breakpoint
*b
)
4871 annotate_catchpoint (b
->number
);
4872 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b
->number
,
4874 return PRINT_SRC_AND_LOC
;
4878 print_one_catch_exec (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
4880 struct value_print_options opts
;
4882 get_user_print_options (&opts
);
4884 /* Field 4, the address, is omitted (which makes the columns
4885 not line up too nicely with the headers, but the effect
4886 is relatively readable). */
4887 if (opts
.addressprint
)
4888 ui_out_field_skip (uiout
, "addr");
4890 ui_out_text (uiout
, "exec");
4891 if (b
->exec_pathname
!= NULL
)
4893 ui_out_text (uiout
, ", program \"");
4894 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
4895 ui_out_text (uiout
, "\" ");
4900 print_mention_catch_exec (struct breakpoint
*b
)
4902 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
4905 static struct breakpoint_ops catch_exec_breakpoint_ops
=
4909 breakpoint_hit_catch_exec
,
4910 print_it_catch_exec
,
4911 print_one_catch_exec
,
4912 print_mention_catch_exec
4916 hw_breakpoint_used_count (void)
4918 struct breakpoint
*b
;
4923 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
4931 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4933 struct breakpoint
*b
;
4936 *other_type_used
= 0;
4939 if (breakpoint_enabled (b
))
4941 if (b
->type
== type
)
4943 else if ((b
->type
== bp_hardware_watchpoint
||
4944 b
->type
== bp_read_watchpoint
||
4945 b
->type
== bp_access_watchpoint
))
4946 *other_type_used
= 1;
4953 disable_watchpoints_before_interactive_call_start (void)
4955 struct breakpoint
*b
;
4959 if (((b
->type
== bp_watchpoint
)
4960 || (b
->type
== bp_hardware_watchpoint
)
4961 || (b
->type
== bp_read_watchpoint
)
4962 || (b
->type
== bp_access_watchpoint
))
4963 && breakpoint_enabled (b
))
4965 b
->enable_state
= bp_call_disabled
;
4966 update_global_location_list (0);
4972 enable_watchpoints_after_interactive_call_stop (void)
4974 struct breakpoint
*b
;
4978 if (((b
->type
== bp_watchpoint
)
4979 || (b
->type
== bp_hardware_watchpoint
)
4980 || (b
->type
== bp_read_watchpoint
)
4981 || (b
->type
== bp_access_watchpoint
))
4982 && (b
->enable_state
== bp_call_disabled
))
4984 b
->enable_state
= bp_enabled
;
4985 update_global_location_list (1);
4991 /* Set a breakpoint that will evaporate an end of command
4992 at address specified by SAL.
4993 Restrict it to frame FRAME if FRAME is nonzero. */
4996 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_id frame_id
,
4999 struct breakpoint
*b
;
5000 b
= set_raw_breakpoint (sal
, type
);
5001 b
->enable_state
= bp_enabled
;
5002 b
->disposition
= disp_donttouch
;
5003 b
->frame_id
= frame_id
;
5005 /* If we're debugging a multi-threaded program, then we
5006 want momentary breakpoints to be active in only a
5007 single thread of control. */
5008 if (in_thread_list (inferior_ptid
))
5009 b
->thread
= pid_to_thread_id (inferior_ptid
);
5011 update_global_location_list_nothrow (1);
5017 set_momentary_breakpoint_at_pc (CORE_ADDR pc
, enum bptype type
)
5019 struct symtab_and_line sal
;
5021 sal
= find_pc_line (pc
, 0);
5023 sal
.section
= find_pc_overlay (pc
);
5024 sal
.explicit_pc
= 1;
5026 return set_momentary_breakpoint (sal
, null_frame_id
, type
);
5030 /* Tell the user we have just set a breakpoint B. */
5033 mention (struct breakpoint
*b
)
5036 struct cleanup
*ui_out_chain
;
5037 struct value_print_options opts
;
5039 get_user_print_options (&opts
);
5041 /* FIXME: This is misplaced; mention() is called by things (like
5042 hitting a watchpoint) other than breakpoint creation. It should
5043 be possible to clean this up and at the same time replace the
5044 random calls to breakpoint_changed with this hook. */
5045 observer_notify_breakpoint_created (b
->number
);
5047 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
5048 b
->ops
->print_mention (b
);
5053 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
5056 ui_out_text (uiout
, "Watchpoint ");
5057 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
5058 ui_out_field_int (uiout
, "number", b
->number
);
5059 ui_out_text (uiout
, ": ");
5060 ui_out_field_string (uiout
, "exp", b
->exp_string
);
5061 do_cleanups (ui_out_chain
);
5063 case bp_hardware_watchpoint
:
5064 ui_out_text (uiout
, "Hardware watchpoint ");
5065 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
5066 ui_out_field_int (uiout
, "number", b
->number
);
5067 ui_out_text (uiout
, ": ");
5068 ui_out_field_string (uiout
, "exp", b
->exp_string
);
5069 do_cleanups (ui_out_chain
);
5071 case bp_read_watchpoint
:
5072 ui_out_text (uiout
, "Hardware read watchpoint ");
5073 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
5074 ui_out_field_int (uiout
, "number", b
->number
);
5075 ui_out_text (uiout
, ": ");
5076 ui_out_field_string (uiout
, "exp", b
->exp_string
);
5077 do_cleanups (ui_out_chain
);
5079 case bp_access_watchpoint
:
5080 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
5081 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
5082 ui_out_field_int (uiout
, "number", b
->number
);
5083 ui_out_text (uiout
, ": ");
5084 ui_out_field_string (uiout
, "exp", b
->exp_string
);
5085 do_cleanups (ui_out_chain
);
5088 if (ui_out_is_mi_like_p (uiout
))
5093 if (b
->disposition
== disp_del
)
5094 printf_filtered (_("Temporary breakpoint"));
5096 printf_filtered (_("Breakpoint"));
5097 printf_filtered (_(" %d"), b
->number
);
5100 case bp_hardware_breakpoint
:
5101 if (ui_out_is_mi_like_p (uiout
))
5106 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
5110 if (ui_out_is_mi_like_p (uiout
))
5115 printf_filtered (_("Tracepoint"));
5116 printf_filtered (_(" %d"), b
->number
);
5123 case bp_longjmp_resume
:
5124 case bp_step_resume
:
5126 case bp_watchpoint_scope
:
5127 case bp_shlib_event
:
5128 case bp_thread_event
:
5129 case bp_overlay_event
:
5135 /* i18n: cagney/2005-02-11: Below needs to be merged into a
5139 printf_filtered (_(" (%s) pending."), b
->addr_string
);
5143 if (opts
.addressprint
|| b
->source_file
== NULL
)
5145 printf_filtered (" at ");
5146 fputs_filtered (paddress (b
->loc
->address
), gdb_stdout
);
5149 printf_filtered (": file %s, line %d.",
5150 b
->source_file
, b
->line_number
);
5154 struct bp_location
*loc
= b
->loc
;
5156 for (; loc
; loc
= loc
->next
)
5158 printf_filtered (" (%d locations)", n
);
5163 if (ui_out_is_mi_like_p (uiout
))
5165 printf_filtered ("\n");
5169 static struct bp_location
*
5170 add_location_to_breakpoint (struct breakpoint
*b
,
5171 const struct symtab_and_line
*sal
)
5173 struct bp_location
*loc
, **tmp
;
5175 loc
= allocate_bp_location (b
);
5176 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
5179 loc
->requested_address
= sal
->pc
;
5180 loc
->address
= adjust_breakpoint_address (loc
->requested_address
, b
->type
);
5181 loc
->section
= sal
->section
;
5183 set_breakpoint_location_function (loc
);
5188 /* Return 1 if LOC is pointing to a permanent breakpoint,
5189 return 0 otherwise. */
5192 bp_loc_is_permanent (struct bp_location
*loc
)
5196 const gdb_byte
*brk
;
5197 gdb_byte
*target_mem
;
5198 struct cleanup
*cleanup
;
5201 gdb_assert (loc
!= NULL
);
5203 addr
= loc
->address
;
5204 brk
= gdbarch_breakpoint_from_pc (current_gdbarch
, &addr
, &len
);
5206 /* Software breakpoints unsupported? */
5210 target_mem
= alloca (len
);
5212 /* Enable the automatic memory restoration from breakpoints while
5213 we read the memory. Otherwise we could say about our temporary
5214 breakpoints they are permanent. */
5215 cleanup
= make_show_memory_breakpoints_cleanup (0);
5217 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
5218 && memcmp (target_mem
, brk
, len
) == 0)
5221 do_cleanups (cleanup
);
5228 /* Create a breakpoint with SAL as location. Use ADDR_STRING
5229 as textual description of the location, and COND_STRING
5230 as condition expression. */
5233 create_breakpoint (struct symtabs_and_lines sals
, char *addr_string
,
5235 enum bptype type
, enum bpdisp disposition
,
5236 int thread
, int task
, int ignore_count
,
5237 struct breakpoint_ops
*ops
, int from_tty
, int enabled
)
5239 struct breakpoint
*b
= NULL
;
5242 if (type
== bp_hardware_breakpoint
)
5244 int i
= hw_breakpoint_used_count ();
5245 int target_resources_ok
=
5246 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
5248 if (target_resources_ok
== 0)
5249 error (_("No hardware breakpoint support in the target."));
5250 else if (target_resources_ok
< 0)
5251 error (_("Hardware breakpoints used exceeds limit."));
5254 for (i
= 0; i
< sals
.nelts
; ++i
)
5256 struct symtab_and_line sal
= sals
.sals
[i
];
5257 struct bp_location
*loc
;
5260 describe_other_breakpoints (sal
.pc
, sal
.section
, thread
);
5264 b
= set_raw_breakpoint (sal
, type
);
5265 set_breakpoint_count (breakpoint_count
+ 1);
5266 b
->number
= breakpoint_count
;
5270 b
->cond_string
= cond_string
;
5271 b
->ignore_count
= ignore_count
;
5272 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
5273 b
->disposition
= disposition
;
5279 loc
= add_location_to_breakpoint (b
, &sal
);
5282 if (bp_loc_is_permanent (loc
))
5283 make_breakpoint_permanent (b
);
5287 char *arg
= b
->cond_string
;
5288 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
5290 error (_("Garbage %s follows condition"), arg
);
5295 b
->addr_string
= addr_string
;
5297 /* addr_string has to be used or breakpoint_re_set will delete
5299 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
5305 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
5306 elements to fill the void space. */
5308 remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
5310 int i
= index_to_remove
+1;
5311 int last_index
= sal
->nelts
-1;
5313 for (;i
<= last_index
; ++i
)
5314 sal
->sals
[i
-1] = sal
->sals
[i
];
5319 /* If appropriate, obtains all sals that correspond
5320 to the same file and line as SAL. This is done
5321 only if SAL does not have explicit PC and has
5322 line and file information. If we got just a single
5323 expanded sal, return the original.
5325 Otherwise, if SAL.explicit_line is not set, filter out
5326 all sals for which the name of enclosing function
5327 is different from SAL. This makes sure that if we have
5328 breakpoint originally set in template instantiation, say
5329 foo<int>(), we won't expand SAL to locations at the same
5330 line in all existing instantiations of 'foo'.
5333 static struct symtabs_and_lines
5334 expand_line_sal_maybe (struct symtab_and_line sal
)
5336 struct symtabs_and_lines expanded
;
5337 CORE_ADDR original_pc
= sal
.pc
;
5338 char *original_function
= NULL
;
5342 /* If we have explicit pc, don't expand.
5343 If we have no line number, we can't expand. */
5344 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
5347 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5348 expanded
.sals
[0] = sal
;
5353 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
5355 expanded
= expand_line_sal (sal
);
5356 if (expanded
.nelts
== 1)
5358 /* We had one sal, we got one sal. Without futher
5359 processing, just return the original sal. */
5360 xfree (expanded
.sals
);
5362 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5363 sal
.pc
= original_pc
;
5364 expanded
.sals
[0] = sal
;
5368 if (!sal
.explicit_line
)
5370 CORE_ADDR func_addr
, func_end
;
5371 for (i
= 0; i
< expanded
.nelts
; ++i
)
5373 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
5374 char *this_function
;
5375 if (find_pc_partial_function (pc
, &this_function
,
5376 &func_addr
, &func_end
))
5378 if (this_function
&&
5379 strcmp (this_function
, original_function
) != 0)
5381 remove_sal (&expanded
, i
);
5384 else if (func_addr
== pc
)
5386 /* We're at beginning of a function, and should
5388 struct symbol
*sym
= find_pc_function (pc
);
5390 expanded
.sals
[i
] = find_function_start_sal (sym
, 1);
5393 = gdbarch_skip_prologue (current_gdbarch
, pc
);
5400 if (expanded
.nelts
<= 1)
5402 /* This is un ugly workaround. If we get zero
5403 expanded sals then something is really wrong.
5404 Fix that by returnign the original sal. */
5405 xfree (expanded
.sals
);
5407 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5408 sal
.pc
= original_pc
;
5409 expanded
.sals
[0] = sal
;
5416 for (i
= 0; i
< expanded
.nelts
; ++i
)
5417 if (expanded
.sals
[i
].pc
== original_pc
)
5428 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5429 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5430 value. COND_STRING, if not NULL, specified the condition to be
5431 used for all breakpoints. Essentially the only case where
5432 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
5433 function. In that case, it's still not possible to specify
5434 separate conditions for different overloaded functions, so
5435 we take just a single condition string.
5437 NOTE: If the function succeeds, the caller is expected to cleanup
5438 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
5439 array contents). If the function fails (error() is called), the
5440 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5441 COND and SALS arrays and each of those arrays contents. */
5444 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
5446 enum bptype type
, enum bpdisp disposition
,
5447 int thread
, int task
, int ignore_count
,
5448 struct breakpoint_ops
*ops
, int from_tty
,
5452 for (i
= 0; i
< sals
.nelts
; ++i
)
5454 struct symtabs_and_lines expanded
=
5455 expand_line_sal_maybe (sals
.sals
[i
]);
5457 create_breakpoint (expanded
, addr_string
[i
],
5458 cond_string
, type
, disposition
,
5459 thread
, task
, ignore_count
, ops
, from_tty
, enabled
);
5462 update_global_location_list (1);
5465 /* Parse ARG which is assumed to be a SAL specification possibly
5466 followed by conditionals. On return, SALS contains an array of SAL
5467 addresses found. ADDR_STRING contains a vector of (canonical)
5468 address strings. ARG points to the end of the SAL. */
5471 parse_breakpoint_sals (char **address
,
5472 struct symtabs_and_lines
*sals
,
5473 char ***addr_string
,
5476 char *addr_start
= *address
;
5477 *addr_string
= NULL
;
5478 /* If no arg given, or if first arg is 'if ', use the default
5480 if ((*address
) == NULL
5481 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
5483 if (default_breakpoint_valid
)
5485 struct symtab_and_line sal
;
5486 init_sal (&sal
); /* initialize to zeroes */
5487 sals
->sals
= (struct symtab_and_line
*)
5488 xmalloc (sizeof (struct symtab_and_line
));
5489 sal
.pc
= default_breakpoint_address
;
5490 sal
.line
= default_breakpoint_line
;
5491 sal
.symtab
= default_breakpoint_symtab
;
5492 sal
.section
= find_pc_overlay (sal
.pc
);
5493 sals
->sals
[0] = sal
;
5497 error (_("No default breakpoint address now."));
5501 /* Force almost all breakpoints to be in terms of the
5502 current_source_symtab (which is decode_line_1's default). This
5503 should produce the results we want almost all of the time while
5504 leaving default_breakpoint_* alone.
5505 ObjC: However, don't match an Objective-C method name which
5506 may have a '+' or '-' succeeded by a '[' */
5508 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
5510 if (default_breakpoint_valid
5512 || ((strchr ("+-", (*address
)[0]) != NULL
)
5513 && ((*address
)[1] != '['))))
5514 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
5515 default_breakpoint_line
, addr_string
,
5518 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
5519 addr_string
, not_found_ptr
);
5521 /* For any SAL that didn't have a canonical string, fill one in. */
5522 if (sals
->nelts
> 0 && *addr_string
== NULL
)
5523 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
5524 if (addr_start
!= (*address
))
5527 for (i
= 0; i
< sals
->nelts
; i
++)
5529 /* Add the string if not present. */
5530 if ((*addr_string
)[i
] == NULL
)
5531 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
5537 /* Convert each SAL into a real PC. Verify that the PC can be
5538 inserted as a breakpoint. If it can't throw an error. */
5541 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
5545 for (i
= 0; i
< sals
->nelts
; i
++)
5546 resolve_sal_pc (&sals
->sals
[i
]);
5550 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
5552 struct captured_parse_breakpoint_args
*args
= data
;
5554 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
5555 args
->not_found_ptr
);
5558 /* Given TOK, a string specification of condition and thread, as
5559 accepted by the 'break' command, extract the condition
5560 string and thread number and set *COND_STRING and *THREAD.
5561 PC identifies the context at which the condition should be parsed.
5562 If no condition is found, *COND_STRING is set to NULL.
5563 If no thread is found, *THREAD is set to -1. */
5565 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
5566 char **cond_string
, int *thread
, int *task
)
5568 *cond_string
= NULL
;
5574 char *cond_start
= NULL
;
5575 char *cond_end
= NULL
;
5576 while (*tok
== ' ' || *tok
== '\t')
5581 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5584 toklen
= end_tok
- tok
;
5586 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5588 struct expression
*expr
;
5590 tok
= cond_start
= end_tok
+ 1;
5591 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
5594 *cond_string
= savestring (cond_start
,
5595 cond_end
- cond_start
);
5597 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5603 *thread
= strtol (tok
, &tok
, 0);
5605 error (_("Junk after thread keyword."));
5606 if (!valid_thread_id (*thread
))
5607 error (_("Unknown thread %d."), *thread
);
5609 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
5615 *task
= strtol (tok
, &tok
, 0);
5617 error (_("Junk after task keyword."));
5618 if (!valid_task_id (*task
))
5619 error (_("Unknown task %d\n"), *task
);
5622 error (_("Junk at end of arguments."));
5626 /* Set a breakpoint. This function is shared between
5627 CLI and MI functions for setting a breakpoint.
5628 This function has two major modes of operations,
5629 selected by the PARSE_CONDITION_AND_THREAD parameter.
5630 If non-zero, the function will parse arg, extracting
5631 breakpoint location, address and thread. Otherwise,
5632 ARG is just the location of breakpoint, with condition
5633 and thread specified by the COND_STRING and THREAD
5637 break_command_really (char *arg
, char *cond_string
, int thread
,
5638 int parse_condition_and_thread
,
5639 int tempflag
, int hardwareflag
, int traceflag
,
5641 enum auto_boolean pending_break_support
,
5642 struct breakpoint_ops
*ops
,
5646 struct gdb_exception e
;
5647 struct symtabs_and_lines sals
;
5648 struct symtab_and_line pending_sal
;
5651 char *addr_start
= arg
;
5653 struct cleanup
*old_chain
;
5654 struct cleanup
*breakpoint_chain
= NULL
;
5655 struct captured_parse_breakpoint_args parse_args
;
5659 enum bptype type_wanted
;
5666 parse_args
.arg_p
= &arg
;
5667 parse_args
.sals_p
= &sals
;
5668 parse_args
.addr_string_p
= &addr_string
;
5669 parse_args
.not_found_ptr
= ¬_found
;
5671 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
5672 &parse_args
, RETURN_MASK_ALL
);
5674 /* If caller is interested in rc value from parse, set value. */
5678 throw_exception (e
);
5682 case NOT_FOUND_ERROR
:
5684 /* If pending breakpoint support is turned off, throw
5687 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
5688 throw_exception (e
);
5690 exception_print (gdb_stderr
, e
);
5692 /* If pending breakpoint support is auto query and the user
5693 selects no, then simply return the error code. */
5694 if (pending_break_support
== AUTO_BOOLEAN_AUTO
&&
5695 !nquery ("Make breakpoint pending on future shared library load? "))
5698 /* At this point, either the user was queried about setting
5699 a pending breakpoint and selected yes, or pending
5700 breakpoint behavior is on and thus a pending breakpoint
5701 is defaulted on behalf of the user. */
5702 copy_arg
= xstrdup (addr_start
);
5703 addr_string
= ©_arg
;
5705 sals
.sals
= &pending_sal
;
5710 throw_exception (e
);
5717 /* Create a chain of things that always need to be cleaned up. */
5718 old_chain
= make_cleanup (null_cleanup
, 0);
5722 /* Make sure that all storage allocated to SALS gets freed. */
5723 make_cleanup (xfree
, sals
.sals
);
5725 /* Cleanup the addr_string array but not its contents. */
5726 make_cleanup (xfree
, addr_string
);
5729 /* ----------------------------- SNIP -----------------------------
5730 Anything added to the cleanup chain beyond this point is assumed
5731 to be part of a breakpoint. If the breakpoint create succeeds
5732 then the memory is not reclaimed. */
5733 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5735 /* Mark the contents of the addr_string for cleanup. These go on
5736 the breakpoint_chain and only occure if the breakpoint create
5738 for (i
= 0; i
< sals
.nelts
; i
++)
5740 if (addr_string
[i
] != NULL
)
5741 make_cleanup (xfree
, addr_string
[i
]);
5744 /* Resolve all line numbers to PC's and verify that the addresses
5745 are ok for the target. */
5747 breakpoint_sals_to_pc (&sals
, addr_start
);
5749 type_wanted
= (traceflag
5751 : (hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
));
5753 /* Verify that condition can be parsed, before setting any
5754 breakpoints. Allocate a separate condition expression for each
5758 if (parse_condition_and_thread
)
5760 /* Here we only parse 'arg' to separate condition
5761 from thread number, so parsing in context of first
5762 sal is OK. When setting the breakpoint we'll
5763 re-parse it in context of each sal. */
5766 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
,
5769 make_cleanup (xfree
, cond_string
);
5773 /* Create a private copy of condition string. */
5776 cond_string
= xstrdup (cond_string
);
5777 make_cleanup (xfree
, cond_string
);
5780 create_breakpoints (sals
, addr_string
, cond_string
, type_wanted
,
5781 tempflag
? disp_del
: disp_donttouch
,
5782 thread
, task
, ignore_count
, ops
, from_tty
, enabled
);
5786 struct symtab_and_line sal
= {0};
5787 struct breakpoint
*b
;
5789 make_cleanup (xfree
, copy_arg
);
5791 b
= set_raw_breakpoint_without_location (type_wanted
);
5792 set_breakpoint_count (breakpoint_count
+ 1);
5793 b
->number
= breakpoint_count
;
5795 b
->addr_string
= addr_string
[0];
5796 b
->cond_string
= NULL
;
5797 b
->ignore_count
= ignore_count
;
5798 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
5799 b
->condition_not_parsed
= 1;
5801 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
5803 update_global_location_list (1);
5808 warning (_("Multiple breakpoints were set.\n"
5809 "Use the \"delete\" command to delete unwanted breakpoints."));
5810 /* That's it. Discard the cleanups for data inserted into the
5812 discard_cleanups (breakpoint_chain
);
5813 /* But cleanup everything else. */
5814 do_cleanups (old_chain
);
5817 /* Set a breakpoint.
5818 ARG is a string describing breakpoint address,
5819 condition, and thread.
5820 FLAG specifies if a breakpoint is hardware on,
5821 and if breakpoint is temporary, using BP_HARDWARE_FLAG
5825 break_command_1 (char *arg
, int flag
, int from_tty
)
5827 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
5828 int tempflag
= flag
& BP_TEMPFLAG
;
5830 break_command_really (arg
,
5831 NULL
, 0, 1 /* parse arg */,
5832 tempflag
, hardwareflag
, 0 /* traceflag */,
5833 0 /* Ignore count */,
5834 pending_break_support
,
5835 NULL
/* breakpoint_ops */,
5842 set_breakpoint (char *address
, char *condition
,
5843 int hardwareflag
, int tempflag
,
5844 int thread
, int ignore_count
,
5845 int pending
, int enabled
)
5847 break_command_really (address
, condition
, thread
,
5848 0 /* condition and thread are valid. */,
5849 tempflag
, hardwareflag
, 0 /* traceflag */,
5852 ? AUTO_BOOLEAN_TRUE
: AUTO_BOOLEAN_FALSE
,
5856 /* Adjust SAL to the first instruction past the function prologue.
5857 The end of the prologue is determined using the line table from
5858 the debugging information.
5860 If SAL is already past the prologue, then do nothing. */
5863 skip_prologue_sal (struct symtab_and_line
*sal
)
5865 struct symbol
*sym
= find_pc_function (sal
->pc
);
5866 struct symtab_and_line start_sal
;
5871 start_sal
= find_function_start_sal (sym
, 1);
5872 if (sal
->pc
< start_sal
.pc
)
5876 /* Helper function for break_command_1 and disassemble_command. */
5879 resolve_sal_pc (struct symtab_and_line
*sal
)
5883 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
5885 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
5886 error (_("No line %d in file \"%s\"."),
5887 sal
->line
, sal
->symtab
->filename
);
5890 /* If this SAL corresponds to a breakpoint inserted using
5891 a line number, then skip the function prologue if necessary. */
5892 if (sal
->explicit_line
)
5894 /* Preserve the original line number. */
5895 int saved_line
= sal
->line
;
5896 skip_prologue_sal (sal
);
5897 sal
->line
= saved_line
;
5901 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
5903 struct blockvector
*bv
;
5907 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
5910 sym
= block_linkage_function (b
);
5913 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
5914 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
5918 /* It really is worthwhile to have the section, so we'll just
5919 have to look harder. This case can be executed if we have
5920 line numbers but no functions (as can happen in assembly
5923 struct minimal_symbol
*msym
;
5925 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5927 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
5934 break_command (char *arg
, int from_tty
)
5936 break_command_1 (arg
, 0, from_tty
);
5940 tbreak_command (char *arg
, int from_tty
)
5942 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5946 hbreak_command (char *arg
, int from_tty
)
5948 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
5952 thbreak_command (char *arg
, int from_tty
)
5954 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
5958 stop_command (char *arg
, int from_tty
)
5960 printf_filtered (_("Specify the type of breakpoint to set.\n\
5961 Usage: stop in <function | address>\n\
5962 stop at <line>\n"));
5966 stopin_command (char *arg
, int from_tty
)
5970 if (arg
== (char *) NULL
)
5972 else if (*arg
!= '*')
5977 /* look for a ':'. If this is a line number specification, then
5978 say it is bad, otherwise, it should be an address or
5979 function/method name */
5980 while (*argptr
&& !hasColon
)
5982 hasColon
= (*argptr
== ':');
5987 badInput
= (*argptr
!= ':'); /* Not a class::method */
5989 badInput
= isdigit (*arg
); /* a simple line number */
5993 printf_filtered (_("Usage: stop in <function | address>\n"));
5995 break_command_1 (arg
, 0, from_tty
);
5999 stopat_command (char *arg
, int from_tty
)
6003 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
6010 /* look for a ':'. If there is a '::' then get out, otherwise
6011 it is probably a line number. */
6012 while (*argptr
&& !hasColon
)
6014 hasColon
= (*argptr
== ':');
6019 badInput
= (*argptr
== ':'); /* we have class::method */
6021 badInput
= !isdigit (*arg
); /* not a line number */
6025 printf_filtered (_("Usage: stop at <line>\n"));
6027 break_command_1 (arg
, 0, from_tty
);
6030 /* accessflag: hw_write: watch write,
6031 hw_read: watch read,
6032 hw_access: watch access (read or write) */
6034 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
6036 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
6037 struct symtab_and_line sal
;
6038 struct expression
*exp
;
6039 struct block
*exp_valid_block
;
6040 struct value
*val
, *mark
;
6041 struct frame_info
*frame
;
6042 struct frame_info
*prev_frame
= NULL
;
6043 char *exp_start
= NULL
;
6044 char *exp_end
= NULL
;
6045 char *tok
, *id_tok_start
, *end_tok
;
6047 char *cond_start
= NULL
;
6048 char *cond_end
= NULL
;
6049 struct expression
*cond
= NULL
;
6050 int i
, other_type_used
, target_resources_ok
= 0;
6051 enum bptype bp_type
;
6055 init_sal (&sal
); /* initialize to zeroes */
6057 /* Make sure that we actually have parameters to parse. */
6058 if (arg
!= NULL
&& arg
[0] != '\0')
6060 toklen
= strlen (arg
); /* Size of argument list. */
6062 /* Points tok to the end of the argument list. */
6063 tok
= arg
+ toklen
- 1;
6065 /* Go backwards in the parameters list. Skip the last parameter.
6066 If we're expecting a 'thread <thread_num>' parameter, this should
6067 be the thread identifier. */
6068 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
6070 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
6073 /* Points end_tok to the beginning of the last token. */
6074 id_tok_start
= tok
+ 1;
6076 /* Go backwards in the parameters list. Skip one more parameter.
6077 If we're expecting a 'thread <thread_num>' parameter, we should
6078 reach a "thread" token. */
6079 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
6084 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
6087 /* Move the pointer forward to skip the whitespace and
6088 calculate the length of the token. */
6090 toklen
= end_tok
- tok
;
6092 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
6094 /* At this point we've found a "thread" token, which means
6095 the user is trying to set a watchpoint that triggers
6096 only in a specific thread. */
6099 /* Extract the thread ID from the next token. */
6100 thread
= strtol (id_tok_start
, &endp
, 0);
6102 /* Check if the user provided a valid numeric value for the
6104 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
6105 error (_("Invalid thread ID specification %s."), id_tok_start
);
6107 /* Check if the thread actually exists. */
6108 if (!valid_thread_id (thread
))
6109 error (_("Unknown thread %d."), thread
);
6111 /* Truncate the string and get rid of the thread <thread_num>
6112 parameter before the parameter list is parsed by the
6113 evaluate_expression() function. */
6118 /* Parse the rest of the arguments. */
6119 innermost_block
= NULL
;
6121 exp
= parse_exp_1 (&arg
, 0, 0);
6123 /* Remove trailing whitespace from the expression before saving it.
6124 This makes the eventual display of the expression string a bit
6126 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
6129 exp_valid_block
= innermost_block
;
6130 mark
= value_mark ();
6131 fetch_watchpoint_value (exp
, &val
, NULL
, NULL
);
6133 release_value (val
);
6136 while (*tok
== ' ' || *tok
== '\t')
6140 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
6143 toklen
= end_tok
- tok
;
6144 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
6146 tok
= cond_start
= end_tok
+ 1;
6147 cond
= parse_exp_1 (&tok
, 0, 0);
6151 error (_("Junk at end of command."));
6153 if (accessflag
== hw_read
)
6154 bp_type
= bp_read_watchpoint
;
6155 else if (accessflag
== hw_access
)
6156 bp_type
= bp_access_watchpoint
;
6158 bp_type
= bp_hardware_watchpoint
;
6160 mem_cnt
= can_use_hardware_watchpoint (val
);
6161 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
6162 error (_("Expression cannot be implemented with read/access watchpoint."));
6165 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
6166 target_resources_ok
=
6167 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
6169 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
6170 error (_("Target does not support this type of hardware watchpoint."));
6172 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
6173 error (_("Target can only support one kind of HW watchpoint at a time."));
6176 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
6177 watchpoint could not be set. */
6178 if (!mem_cnt
|| target_resources_ok
<= 0)
6179 bp_type
= bp_watchpoint
;
6181 frame
= block_innermost_frame (exp_valid_block
);
6183 prev_frame
= get_prev_frame (frame
);
6187 /* If the expression is "local", then set up a "watchpoint scope"
6188 breakpoint at the point where we've left the scope of the watchpoint
6189 expression. Create the scope breakpoint before the watchpoint, so
6190 that we will encounter it first in bpstat_stop_status. */
6191 if (innermost_block
&& prev_frame
)
6193 scope_breakpoint
= create_internal_breakpoint (get_frame_pc (prev_frame
),
6194 bp_watchpoint_scope
);
6196 scope_breakpoint
->enable_state
= bp_enabled
;
6198 /* Automatically delete the breakpoint when it hits. */
6199 scope_breakpoint
->disposition
= disp_del
;
6201 /* Only break in the proper frame (help with recursion). */
6202 scope_breakpoint
->frame_id
= get_frame_id (prev_frame
);
6204 /* Set the address at which we will stop. */
6205 scope_breakpoint
->loc
->requested_address
6206 = get_frame_pc (prev_frame
);
6207 scope_breakpoint
->loc
->address
6208 = adjust_breakpoint_address (scope_breakpoint
->loc
->requested_address
,
6209 scope_breakpoint
->type
);
6212 /* Now set up the breakpoint. */
6213 b
= set_raw_breakpoint (sal
, bp_type
);
6214 set_breakpoint_count (breakpoint_count
+ 1);
6215 b
->number
= breakpoint_count
;
6217 b
->disposition
= disp_donttouch
;
6219 b
->exp_valid_block
= exp_valid_block
;
6220 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
6223 b
->loc
->cond
= cond
;
6225 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
6230 b
->watchpoint_frame
= get_frame_id (frame
);
6232 b
->watchpoint_frame
= null_frame_id
;
6234 if (scope_breakpoint
!= NULL
)
6236 /* The scope breakpoint is related to the watchpoint. We will
6237 need to act on them together. */
6238 b
->related_breakpoint
= scope_breakpoint
;
6239 scope_breakpoint
->related_breakpoint
= b
;
6242 value_free_to_mark (mark
);
6244 update_global_location_list (1);
6247 /* Return count of locations need to be watched and can be handled
6248 in hardware. If the watchpoint can not be handled
6249 in hardware return zero. */
6252 can_use_hardware_watchpoint (struct value
*v
)
6254 int found_memory_cnt
= 0;
6255 struct value
*head
= v
;
6257 /* Did the user specifically forbid us to use hardware watchpoints? */
6258 if (!can_use_hw_watchpoints
)
6261 /* Make sure that the value of the expression depends only upon
6262 memory contents, and values computed from them within GDB. If we
6263 find any register references or function calls, we can't use a
6264 hardware watchpoint.
6266 The idea here is that evaluating an expression generates a series
6267 of values, one holding the value of every subexpression. (The
6268 expression a*b+c has five subexpressions: a, b, a*b, c, and
6269 a*b+c.) GDB's values hold almost enough information to establish
6270 the criteria given above --- they identify memory lvalues,
6271 register lvalues, computed values, etcetera. So we can evaluate
6272 the expression, and then scan the chain of values that leaves
6273 behind to decide whether we can detect any possible change to the
6274 expression's final value using only hardware watchpoints.
6276 However, I don't think that the values returned by inferior
6277 function calls are special in any way. So this function may not
6278 notice that an expression involving an inferior function call
6279 can't be watched with hardware watchpoints. FIXME. */
6280 for (; v
; v
= value_next (v
))
6282 if (VALUE_LVAL (v
) == lval_memory
)
6285 /* A lazy memory lvalue is one that GDB never needed to fetch;
6286 we either just used its address (e.g., `a' in `a.b') or
6287 we never needed it at all (e.g., `a' in `a,b'). */
6291 /* Ahh, memory we actually used! Check if we can cover
6292 it with hardware watchpoints. */
6293 struct type
*vtype
= check_typedef (value_type (v
));
6295 /* We only watch structs and arrays if user asked for it
6296 explicitly, never if they just happen to appear in a
6297 middle of some value chain. */
6299 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
6300 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
6302 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
6303 int len
= TYPE_LENGTH (value_type (v
));
6305 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
6312 else if (VALUE_LVAL (v
) != not_lval
6313 && deprecated_value_modifiable (v
) == 0)
6314 return 0; /* ??? What does this represent? */
6315 else if (VALUE_LVAL (v
) == lval_register
)
6316 return 0; /* cannot watch a register with a HW watchpoint */
6319 /* The expression itself looks suitable for using a hardware
6320 watchpoint, but give the target machine a chance to reject it. */
6321 return found_memory_cnt
;
6325 watch_command_wrapper (char *arg
, int from_tty
)
6327 watch_command (arg
, from_tty
);
6331 watch_command (char *arg
, int from_tty
)
6333 watch_command_1 (arg
, hw_write
, from_tty
);
6337 rwatch_command_wrapper (char *arg
, int from_tty
)
6339 rwatch_command (arg
, from_tty
);
6343 rwatch_command (char *arg
, int from_tty
)
6345 watch_command_1 (arg
, hw_read
, from_tty
);
6349 awatch_command_wrapper (char *arg
, int from_tty
)
6351 awatch_command (arg
, from_tty
);
6355 awatch_command (char *arg
, int from_tty
)
6357 watch_command_1 (arg
, hw_access
, from_tty
);
6361 /* Helper routines for the until_command routine in infcmd.c. Here
6362 because it uses the mechanisms of breakpoints. */
6364 struct until_break_command_continuation_args
6366 struct breakpoint
*breakpoint
;
6367 struct breakpoint
*breakpoint2
;
6370 /* This function is called by fetch_inferior_event via the
6371 cmd_continuation pointer, to complete the until command. It takes
6372 care of cleaning up the temporary breakpoints set up by the until
6375 until_break_command_continuation (void *arg
)
6377 struct until_break_command_continuation_args
*a
= arg
;
6379 delete_breakpoint (a
->breakpoint
);
6381 delete_breakpoint (a
->breakpoint2
);
6385 until_break_command (char *arg
, int from_tty
, int anywhere
)
6387 struct symtabs_and_lines sals
;
6388 struct symtab_and_line sal
;
6389 struct frame_info
*frame
= get_selected_frame (NULL
);
6390 struct frame_info
*prev_frame
= get_prev_frame (frame
);
6391 struct breakpoint
*breakpoint
;
6392 struct breakpoint
*breakpoint2
= NULL
;
6393 struct cleanup
*old_chain
;
6395 clear_proceed_status ();
6397 /* Set a breakpoint where the user wants it and at return from
6400 if (default_breakpoint_valid
)
6401 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
6402 default_breakpoint_line
, (char ***) NULL
, NULL
);
6404 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
6405 0, (char ***) NULL
, NULL
);
6407 if (sals
.nelts
!= 1)
6408 error (_("Couldn't get information on specified line."));
6411 xfree (sals
.sals
); /* malloc'd, so freed */
6414 error (_("Junk at end of arguments."));
6416 resolve_sal_pc (&sal
);
6419 /* If the user told us to continue until a specified location,
6420 we don't specify a frame at which we need to stop. */
6421 breakpoint
= set_momentary_breakpoint (sal
, null_frame_id
, bp_until
);
6423 /* Otherwise, specify the current frame, because we want to stop only
6424 at the very same frame. */
6425 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (frame
),
6428 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
6430 /* Keep within the current frame, or in frames called by the current
6434 sal
= find_pc_line (get_frame_pc (prev_frame
), 0);
6435 sal
.pc
= get_frame_pc (prev_frame
);
6436 breakpoint2
= set_momentary_breakpoint (sal
, get_frame_id (prev_frame
),
6438 make_cleanup_delete_breakpoint (breakpoint2
);
6441 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
6443 /* If we are running asynchronously, and proceed call above has actually
6444 managed to start the target, arrange for breakpoints to be
6445 deleted when the target stops. Otherwise, we're already stopped and
6446 delete breakpoints via cleanup chain. */
6448 if (target_can_async_p () && is_running (inferior_ptid
))
6450 struct until_break_command_continuation_args
*args
;
6451 args
= xmalloc (sizeof (*args
));
6453 args
->breakpoint
= breakpoint
;
6454 args
->breakpoint2
= breakpoint2
;
6456 discard_cleanups (old_chain
);
6457 add_continuation (inferior_thread (),
6458 until_break_command_continuation
, args
,
6462 do_cleanups (old_chain
);
6466 ep_skip_leading_whitespace (char **s
)
6468 if ((s
== NULL
) || (*s
== NULL
))
6470 while (isspace (**s
))
6474 /* This function attempts to parse an optional "if <cond>" clause
6475 from the arg string. If one is not found, it returns NULL.
6477 Else, it returns a pointer to the condition string. (It does not
6478 attempt to evaluate the string against a particular block.) And,
6479 it updates arg to point to the first character following the parsed
6480 if clause in the arg string. */
6483 ep_parse_optional_if_clause (char **arg
)
6487 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
6490 /* Skip the "if" keyword. */
6493 /* Skip any extra leading whitespace, and record the start of the
6494 condition string. */
6495 ep_skip_leading_whitespace (arg
);
6498 /* Assume that the condition occupies the remainder of the arg string. */
6499 (*arg
) += strlen (cond_string
);
6504 /* This function attempts to parse an optional filename from the arg
6505 string. If one is not found, it returns NULL.
6507 Else, it returns a pointer to the parsed filename. (This function
6508 makes no attempt to verify that a file of that name exists, or is
6509 accessible.) And, it updates arg to point to the first character
6510 following the parsed filename in the arg string.
6512 Note that clients needing to preserve the returned filename for
6513 future access should copy it to their own buffers. */
6515 ep_parse_optional_filename (char **arg
)
6517 static char filename
[1024];
6522 if ((*arg_p
== '\0') || isspace (*arg_p
))
6540 /* Commands to deal with catching events, such as signals, exceptions,
6541 process start/exit, etc. */
6545 catch_fork_temporary
, catch_vfork_temporary
,
6546 catch_fork_permanent
, catch_vfork_permanent
6551 catch_fork_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6553 char *cond_string
= NULL
;
6554 catch_fork_kind fork_kind
;
6557 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
6558 tempflag
= (fork_kind
== catch_fork_temporary
6559 || fork_kind
== catch_vfork_temporary
);
6563 ep_skip_leading_whitespace (&arg
);
6565 /* The allowed syntax is:
6567 catch [v]fork if <cond>
6569 First, check if there's an if clause. */
6570 cond_string
= ep_parse_optional_if_clause (&arg
);
6572 if ((*arg
!= '\0') && !isspace (*arg
))
6573 error (_("Junk at end of arguments."));
6575 /* If this target supports it, create a fork or vfork catchpoint
6576 and enable reporting of such events. */
6579 case catch_fork_temporary
:
6580 case catch_fork_permanent
:
6581 create_fork_vfork_event_catchpoint (tempflag
, cond_string
,
6582 &catch_fork_breakpoint_ops
);
6584 case catch_vfork_temporary
:
6585 case catch_vfork_permanent
:
6586 create_fork_vfork_event_catchpoint (tempflag
, cond_string
,
6587 &catch_vfork_breakpoint_ops
);
6590 error (_("unsupported or unknown fork kind; cannot catch it"));
6596 catch_exec_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6599 char *cond_string
= NULL
;
6601 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6605 ep_skip_leading_whitespace (&arg
);
6607 /* The allowed syntax is:
6609 catch exec if <cond>
6611 First, check if there's an if clause. */
6612 cond_string
= ep_parse_optional_if_clause (&arg
);
6614 if ((*arg
!= '\0') && !isspace (*arg
))
6615 error (_("Junk at end of arguments."));
6617 /* If this target supports it, create an exec catchpoint
6618 and enable reporting of such events. */
6619 create_catchpoint (tempflag
, cond_string
, &catch_exec_breakpoint_ops
);
6622 static enum print_stop_action
6623 print_exception_catchpoint (struct breakpoint
*b
)
6625 int bp_temp
, bp_throw
;
6627 annotate_catchpoint (b
->number
);
6629 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
6630 if (b
->loc
->address
!= b
->loc
->requested_address
)
6631 breakpoint_adjustment_warning (b
->loc
->requested_address
,
6634 bp_temp
= b
->loc
->owner
->disposition
== disp_del
;
6636 bp_temp
? "Temporary catchpoint "
6638 if (!ui_out_is_mi_like_p (uiout
))
6639 ui_out_field_int (uiout
, "bkptno", b
->number
);
6641 bp_throw
? " (exception thrown), "
6642 : " (exception caught), ");
6643 if (ui_out_is_mi_like_p (uiout
))
6645 ui_out_field_string (uiout
, "reason",
6646 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
6647 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6648 ui_out_field_int (uiout
, "bkptno", b
->number
);
6650 return PRINT_SRC_AND_LOC
;
6654 print_one_exception_catchpoint (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
6656 struct value_print_options opts
;
6657 get_user_print_options (&opts
);
6658 if (opts
.addressprint
)
6661 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
6662 ui_out_field_string (uiout
, "addr", "<PENDING>");
6664 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
6668 *last_addr
= b
->loc
->address
;
6669 if (strstr (b
->addr_string
, "throw") != NULL
)
6670 ui_out_field_string (uiout
, "what", "exception throw");
6672 ui_out_field_string (uiout
, "what", "exception catch");
6676 print_mention_exception_catchpoint (struct breakpoint
*b
)
6681 bp_temp
= b
->loc
->owner
->disposition
== disp_del
;
6682 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
6683 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
6684 : _("Catchpoint "));
6685 ui_out_field_int (uiout
, "bkptno", b
->number
);
6686 ui_out_text (uiout
, bp_throw
? _(" (throw)")
6690 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6693 NULL
, /* breakpoint_hit */
6694 print_exception_catchpoint
,
6695 print_one_exception_catchpoint
,
6696 print_mention_exception_catchpoint
6700 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6701 enum exception_event_kind ex_event
, int from_tty
)
6703 char *trigger_func_name
;
6705 if (ex_event
== EX_EVENT_CATCH
)
6706 trigger_func_name
= "__cxa_begin_catch";
6708 trigger_func_name
= "__cxa_throw";
6710 break_command_really (trigger_func_name
, cond_string
, -1,
6711 0 /* condition and thread are valid. */,
6714 AUTO_BOOLEAN_TRUE
/* pending */,
6715 &gnu_v3_exception_catchpoint_ops
, from_tty
,
6721 /* Deal with "catch catch" and "catch throw" commands */
6724 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6725 int tempflag
, int from_tty
)
6727 char *cond_string
= NULL
;
6728 struct symtab_and_line
*sal
= NULL
;
6732 ep_skip_leading_whitespace (&arg
);
6734 cond_string
= ep_parse_optional_if_clause (&arg
);
6736 if ((*arg
!= '\0') && !isspace (*arg
))
6737 error (_("Junk at end of arguments."));
6739 if ((ex_event
!= EX_EVENT_THROW
) &&
6740 (ex_event
!= EX_EVENT_CATCH
))
6741 error (_("Unsupported or unknown exception event; cannot catch it"));
6743 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
6746 warning (_("Unsupported with this platform/compiler combination."));
6749 /* Implementation of "catch catch" command. */
6752 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6754 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6755 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
6758 /* Implementation of "catch throw" command. */
6761 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6763 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6764 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
6767 /* Create a breakpoint struct for Ada exception catchpoints. */
6770 create_ada_exception_breakpoint (struct symtab_and_line sal
,
6774 struct expression
*cond
,
6775 struct breakpoint_ops
*ops
,
6779 struct breakpoint
*b
;
6783 describe_other_breakpoints (sal
.pc
, sal
.section
, -1);
6784 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
6785 version for exception catchpoints, because two catchpoints
6786 used for different exception names will use the same address.
6787 In this case, a "breakpoint ... also set at..." warning is
6788 unproductive. Besides. the warning phrasing is also a bit
6789 inapropriate, we should use the word catchpoint, and tell
6790 the user what type of catchpoint it is. The above is good
6791 enough for now, though. */
6794 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6795 set_breakpoint_count (breakpoint_count
+ 1);
6797 b
->enable_state
= bp_enabled
;
6798 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6799 b
->number
= breakpoint_count
;
6800 b
->ignore_count
= 0;
6801 b
->loc
->cond
= cond
;
6802 b
->addr_string
= addr_string
;
6803 b
->language
= language_ada
;
6804 b
->cond_string
= cond_string
;
6805 b
->exp_string
= exp_string
;
6810 update_global_location_list (1);
6813 /* Implement the "catch exception" command. */
6816 catch_ada_exception_command (char *arg
, int from_tty
,
6817 struct cmd_list_element
*command
)
6820 struct symtab_and_line sal
;
6822 char *addr_string
= NULL
;
6823 char *exp_string
= NULL
;
6824 char *cond_string
= NULL
;
6825 struct expression
*cond
= NULL
;
6826 struct breakpoint_ops
*ops
= NULL
;
6828 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6832 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
6833 &cond_string
, &cond
, &ops
);
6834 create_ada_exception_breakpoint (sal
, addr_string
, exp_string
,
6835 cond_string
, cond
, ops
, tempflag
,
6839 /* Implement the "catch assert" command. */
6842 catch_assert_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6845 struct symtab_and_line sal
;
6846 char *addr_string
= NULL
;
6847 struct breakpoint_ops
*ops
= NULL
;
6849 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6853 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
6854 create_ada_exception_breakpoint (sal
, addr_string
, NULL
, NULL
, NULL
, ops
,
6855 tempflag
, from_tty
);
6859 catch_command (char *arg
, int from_tty
)
6861 error (_("Catch requires an event name."));
6866 tcatch_command (char *arg
, int from_tty
)
6868 error (_("Catch requires an event name."));
6871 /* Delete breakpoints by address or line. */
6874 clear_command (char *arg
, int from_tty
)
6876 struct breakpoint
*b
;
6877 VEC(breakpoint_p
) *found
= 0;
6880 struct symtabs_and_lines sals
;
6881 struct symtab_and_line sal
;
6886 sals
= decode_line_spec (arg
, 1);
6891 sals
.sals
= (struct symtab_and_line
*)
6892 xmalloc (sizeof (struct symtab_and_line
));
6893 make_cleanup (xfree
, sals
.sals
);
6894 init_sal (&sal
); /* initialize to zeroes */
6895 sal
.line
= default_breakpoint_line
;
6896 sal
.symtab
= default_breakpoint_symtab
;
6897 sal
.pc
= default_breakpoint_address
;
6898 if (sal
.symtab
== 0)
6899 error (_("No source file specified."));
6907 /* We don't call resolve_sal_pc here. That's not
6908 as bad as it seems, because all existing breakpoints
6909 typically have both file/line and pc set. So, if
6910 clear is given file/line, we can match this to existing
6911 breakpoint without obtaining pc at all.
6913 We only support clearing given the address explicitly
6914 present in breakpoint table. Say, we've set breakpoint
6915 at file:line. There were several PC values for that file:line,
6916 due to optimization, all in one block.
6917 We've picked one PC value. If "clear" is issued with another
6918 PC corresponding to the same file:line, the breakpoint won't
6919 be cleared. We probably can still clear the breakpoint, but
6920 since the other PC value is never presented to user, user
6921 can only find it by guessing, and it does not seem important
6924 /* For each line spec given, delete bps which correspond
6925 to it. Do it in two passes, solely to preserve the current
6926 behavior that from_tty is forced true if we delete more than
6930 for (i
= 0; i
< sals
.nelts
; i
++)
6932 /* If exact pc given, clear bpts at that pc.
6933 If line given (pc == 0), clear all bpts on specified line.
6934 If defaulting, clear all bpts on default line
6937 defaulting sal.pc != 0 tests to do
6942 1 0 <can't happen> */
6946 /* Find all matching breakpoints and add them to
6951 /* Are we going to delete b? */
6952 if (b
->type
!= bp_none
6953 && b
->type
!= bp_watchpoint
6954 && b
->type
!= bp_hardware_watchpoint
6955 && b
->type
!= bp_read_watchpoint
6956 && b
->type
!= bp_access_watchpoint
)
6958 struct bp_location
*loc
= b
->loc
;
6959 for (; loc
; loc
= loc
->next
)
6961 int pc_match
= sal
.pc
6962 && (loc
->address
== sal
.pc
)
6963 && (!section_is_overlay (loc
->section
)
6964 || loc
->section
== sal
.section
);
6965 int line_match
= ((default_match
|| (0 == sal
.pc
))
6966 && b
->source_file
!= NULL
6967 && sal
.symtab
!= NULL
6968 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
6969 && b
->line_number
== sal
.line
);
6970 if (pc_match
|| line_match
)
6979 VEC_safe_push(breakpoint_p
, found
, b
);
6982 /* Now go thru the 'found' chain and delete them. */
6983 if (VEC_empty(breakpoint_p
, found
))
6986 error (_("No breakpoint at %s."), arg
);
6988 error (_("No breakpoint at this line."));
6991 if (VEC_length(breakpoint_p
, found
) > 1)
6992 from_tty
= 1; /* Always report if deleted more than one */
6995 if (VEC_length(breakpoint_p
, found
) == 1)
6996 printf_unfiltered (_("Deleted breakpoint "));
6998 printf_unfiltered (_("Deleted breakpoints "));
7000 breakpoints_changed ();
7002 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
7005 printf_unfiltered ("%d ", b
->number
);
7006 delete_breakpoint (b
);
7009 putchar_unfiltered ('\n');
7012 /* Delete breakpoint in BS if they are `delete' breakpoints and
7013 all breakpoints that are marked for deletion, whether hit or not.
7014 This is called after any breakpoint is hit, or after errors. */
7017 breakpoint_auto_delete (bpstat bs
)
7019 struct breakpoint
*b
, *temp
;
7021 for (; bs
; bs
= bs
->next
)
7022 if (bs
->breakpoint_at
7023 && bs
->breakpoint_at
->owner
7024 && bs
->breakpoint_at
->owner
->disposition
== disp_del
7026 delete_breakpoint (bs
->breakpoint_at
->owner
);
7028 ALL_BREAKPOINTS_SAFE (b
, temp
)
7030 if (b
->disposition
== disp_del_at_next_stop
)
7031 delete_breakpoint (b
);
7035 /* A cleanup function which destroys a vector. */
7038 do_vec_free (void *p
)
7040 VEC(bp_location_p
) **vec
= p
;
7042 VEC_free (bp_location_p
, *vec
);
7045 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
7046 into the inferior, only remove already-inserted locations that no
7047 longer should be inserted. Functions that delete a breakpoint or
7048 breakpoints should pass false, so that deleting a breakpoint
7049 doesn't have the side effect of inserting the locations of other
7050 breakpoints that are marked not-inserted, but should_be_inserted
7051 returns true on them.
7053 This behaviour is useful is situations close to tear-down -- e.g.,
7054 after an exec, while the target still has execution, but breakpoint
7055 shadows of the previous executable image should *NOT* be restored
7056 to the new image; or before detaching, where the target still has
7057 execution and wants to delete breakpoints from GDB's lists, and all
7058 breakpoints had already been removed from the inferior. */
7061 update_global_location_list (int should_insert
)
7063 struct breakpoint
*b
;
7064 struct bp_location
**next
= &bp_location_chain
;
7065 struct bp_location
*loc
;
7066 struct bp_location
*loc2
;
7067 VEC(bp_location_p
) *old_locations
= NULL
;
7070 struct cleanup
*cleanups
;
7072 cleanups
= make_cleanup (do_vec_free
, &old_locations
);
7073 /* Store old locations for future reference. */
7074 for (loc
= bp_location_chain
; loc
; loc
= loc
->global_next
)
7075 VEC_safe_push (bp_location_p
, old_locations
, loc
);
7077 bp_location_chain
= NULL
;
7080 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
7083 next
= &(loc
->global_next
);
7088 /* Identify bp_location instances that are no longer present in the new
7089 list, and therefore should be freed. Note that it's not necessary that
7090 those locations should be removed from inferior -- if there's another
7091 location at the same address (previously marked as duplicate),
7092 we don't need to remove/insert the location. */
7093 for (ix
= 0; VEC_iterate(bp_location_p
, old_locations
, ix
, loc
); ++ix
)
7095 /* Tells if 'loc' is found amoung the new locations. If not, we
7097 int found_object
= 0;
7098 /* Tells if the location should remain inserted in the target. */
7099 int keep_in_target
= 0;
7101 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
7108 /* If this location is no longer present, and inserted, look if there's
7109 maybe a new location at the same address. If so, mark that one
7110 inserted, and don't remove this one. This is needed so that we
7111 don't have a time window where a breakpoint at certain location is not
7116 /* If the location is inserted now, we might have to remove it. */
7118 if (found_object
&& should_be_inserted (loc
))
7120 /* The location is still present in the location list, and still
7121 should be inserted. Don't do anything. */
7126 /* The location is either no longer present, or got disabled.
7127 See if there's another location at the same address, in which
7128 case we don't need to remove this one from the target. */
7129 if (breakpoint_address_is_meaningful (loc
->owner
))
7130 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
7132 /* For the sake of should_insert_location. The
7133 call to check_duplicates will fix up this later. */
7134 loc2
->duplicate
= 0;
7135 if (should_be_inserted (loc2
)
7136 && loc2
!= loc
&& loc2
->address
== loc
->address
)
7139 loc2
->target_info
= loc
->target_info
;
7146 if (!keep_in_target
)
7148 if (remove_breakpoint (loc
, mark_uninserted
))
7150 /* This is just about all we can do. We could keep this
7151 location on the global list, and try to remove it next
7152 time, but there's no particular reason why we will
7155 Note that at this point, loc->owner is still valid,
7156 as delete_breakpoint frees the breakpoint only
7157 after calling us. */
7158 printf_filtered (_("warning: Error removing breakpoint %d\n"),
7159 loc
->owner
->number
);
7167 if (removed
&& non_stop
)
7169 /* This location was removed from the targets. In non-stop mode,
7170 a race condition is possible where we've removed a breakpoint,
7171 but stop events for that breakpoint are already queued and will
7172 arrive later. To suppress spurious SIGTRAPs reported to user,
7173 we keep this breakpoint location for a bit, and will retire it
7174 after we see 3 * thread_count events.
7175 The theory here is that reporting of events should,
7176 "on the average", be fair, so after that many event we'll see
7177 events from all threads that have anything of interest, and no
7178 longer need to keep this breakpoint. This is just a
7179 heuristic, but if it's wrong, we'll report unexpected SIGTRAP,
7180 which is usability issue, but not a correctness problem. */
7181 loc
->events_till_retirement
= 3 * (thread_count () + 1);
7184 VEC_safe_push (bp_location_p
, moribund_locations
, loc
);
7187 free_bp_location (loc
);
7193 check_duplicates (b
);
7196 if (breakpoints_always_inserted_mode () && should_insert
7197 && (target_has_execution
7198 || (gdbarch_has_global_solist (target_gdbarch
)
7199 && target_supports_multi_process ())))
7200 insert_breakpoint_locations ();
7202 do_cleanups (cleanups
);
7206 breakpoint_retire_moribund (void)
7208 struct bp_location
*loc
;
7211 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
7212 if (--(loc
->events_till_retirement
) == 0)
7214 free_bp_location (loc
);
7215 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
7221 update_global_location_list_nothrow (int inserting
)
7223 struct gdb_exception e
;
7224 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7225 update_global_location_list (inserting
);
7228 /* Clear BPT from a BPS. */
7230 bpstat_remove_breakpoint (bpstat bps
, struct breakpoint
*bpt
)
7233 for (bs
= bps
; bs
; bs
= bs
->next
)
7234 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
7236 bs
->breakpoint_at
= NULL
;
7238 /* bs->commands will be freed later. */
7242 /* Callback for iterate_over_threads. */
7244 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
7246 struct breakpoint
*bpt
= data
;
7247 bpstat_remove_breakpoint (th
->stop_bpstat
, bpt
);
7251 /* Delete a breakpoint and clean up all traces of it in the data
7255 delete_breakpoint (struct breakpoint
*bpt
)
7257 struct breakpoint
*b
;
7258 struct bp_location
*loc
, *next
;
7260 gdb_assert (bpt
!= NULL
);
7262 /* Has this bp already been deleted? This can happen because multiple
7263 lists can hold pointers to bp's. bpstat lists are especial culprits.
7265 One example of this happening is a watchpoint's scope bp. When the
7266 scope bp triggers, we notice that the watchpoint is out of scope, and
7267 delete it. We also delete its scope bp. But the scope bp is marked
7268 "auto-deleting", and is already on a bpstat. That bpstat is then
7269 checked for auto-deleting bp's, which are deleted.
7271 A real solution to this problem might involve reference counts in bp's,
7272 and/or giving them pointers back to their referencing bpstat's, and
7273 teaching delete_breakpoint to only free a bp's storage when no more
7274 references were extent. A cheaper bandaid was chosen. */
7275 if (bpt
->type
== bp_none
)
7278 observer_notify_breakpoint_deleted (bpt
->number
);
7280 if (breakpoint_chain
== bpt
)
7281 breakpoint_chain
= bpt
->next
;
7286 b
->next
= bpt
->next
;
7290 free_command_lines (&bpt
->commands
);
7291 if (bpt
->cond_string
!= NULL
)
7292 xfree (bpt
->cond_string
);
7293 if (bpt
->addr_string
!= NULL
)
7294 xfree (bpt
->addr_string
);
7295 if (bpt
->exp
!= NULL
)
7297 if (bpt
->exp_string
!= NULL
)
7298 xfree (bpt
->exp_string
);
7299 if (bpt
->val
!= NULL
)
7300 value_free (bpt
->val
);
7301 if (bpt
->source_file
!= NULL
)
7302 xfree (bpt
->source_file
);
7303 if (bpt
->exec_pathname
!= NULL
)
7304 xfree (bpt
->exec_pathname
);
7306 /* Be sure no bpstat's are pointing at it after it's been freed. */
7307 /* FIXME, how can we find all bpstat's?
7308 We just check stop_bpstat for now. Note that we cannot just
7309 remove bpstats pointing at bpt from the stop_bpstat list
7310 entirely, as breakpoint commands are associated with the bpstat;
7311 if we remove it here, then the later call to
7312 bpstat_do_actions (&stop_bpstat);
7313 in event-top.c won't do anything, and temporary breakpoints
7314 with commands won't work. */
7316 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
7318 /* Now that breakpoint is removed from breakpoint
7319 list, update the global location list. This
7320 will remove locations that used to belong to
7321 this breakpoint. Do this before freeing
7322 the breakpoint itself, since remove_breakpoint
7323 looks at location's owner. It might be better
7324 design to have location completely self-contained,
7325 but it's not the case now. */
7326 update_global_location_list (0);
7329 /* On the chance that someone will soon try again to delete this same
7330 bp, we mark it as deleted before freeing its storage. */
7331 bpt
->type
= bp_none
;
7337 do_delete_breakpoint_cleanup (void *b
)
7339 delete_breakpoint (b
);
7343 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
7345 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
7349 delete_command (char *arg
, int from_tty
)
7351 struct breakpoint
*b
, *temp
;
7357 int breaks_to_delete
= 0;
7359 /* Delete all breakpoints if no argument.
7360 Do not delete internal or call-dummy breakpoints, these
7361 have to be deleted with an explicit breakpoint number argument. */
7364 if (b
->type
!= bp_call_dummy
&&
7365 b
->type
!= bp_shlib_event
&&
7366 b
->type
!= bp_thread_event
&&
7367 b
->type
!= bp_overlay_event
&&
7370 breaks_to_delete
= 1;
7375 /* Ask user only if there are some breakpoints to delete. */
7377 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
7379 ALL_BREAKPOINTS_SAFE (b
, temp
)
7381 if (b
->type
!= bp_call_dummy
&&
7382 b
->type
!= bp_shlib_event
&&
7383 b
->type
!= bp_thread_event
&&
7384 b
->type
!= bp_overlay_event
&&
7386 delete_breakpoint (b
);
7391 map_breakpoint_numbers (arg
, delete_breakpoint
);
7395 all_locations_are_pending (struct bp_location
*loc
)
7397 for (; loc
; loc
= loc
->next
)
7398 if (!loc
->shlib_disabled
)
7403 /* Subroutine of update_breakpoint_locations to simplify it.
7404 Return non-zero if multiple fns in list LOC have the same name.
7405 Null names are ignored. */
7408 ambiguous_names_p (struct bp_location
*loc
)
7410 struct bp_location
*l
;
7411 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
7412 (int (*) (const void *, const void *)) streq
,
7413 NULL
, xcalloc
, xfree
);
7415 for (l
= loc
; l
!= NULL
; l
= l
->next
)
7418 const char *name
= l
->function_name
;
7420 /* Allow for some names to be NULL, ignore them. */
7424 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
7426 /* NOTE: We can assume slot != NULL here because xcalloc never returns
7441 update_breakpoint_locations (struct breakpoint
*b
,
7442 struct symtabs_and_lines sals
)
7446 struct bp_location
*existing_locations
= b
->loc
;
7448 /* If there's no new locations, and all existing locations
7449 are pending, don't do anything. This optimizes
7450 the common case where all locations are in the same
7451 shared library, that was unloaded. We'd like to
7452 retain the location, so that when the library
7453 is loaded again, we don't loose the enabled/disabled
7454 status of the individual locations. */
7455 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
7460 for (i
= 0; i
< sals
.nelts
; ++i
)
7462 struct bp_location
*new_loc
=
7463 add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
7465 /* Reparse conditions, they might contain references to the
7467 if (b
->cond_string
!= NULL
)
7469 struct gdb_exception e
;
7472 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7474 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
7479 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
7480 b
->number
, e
.message
);
7481 new_loc
->enabled
= 0;
7485 if (b
->source_file
!= NULL
)
7486 xfree (b
->source_file
);
7487 if (sals
.sals
[i
].symtab
== NULL
)
7488 b
->source_file
= NULL
;
7491 savestring (sals
.sals
[i
].symtab
->filename
,
7492 strlen (sals
.sals
[i
].symtab
->filename
));
7494 if (b
->line_number
== 0)
7495 b
->line_number
= sals
.sals
[i
].line
;
7498 /* Update locations of permanent breakpoints. */
7499 if (b
->enable_state
== bp_permanent
)
7500 make_breakpoint_permanent (b
);
7502 /* If possible, carry over 'disable' status from existing breakpoints. */
7504 struct bp_location
*e
= existing_locations
;
7505 /* If there are multiple breakpoints with the same function name,
7506 e.g. for inline functions, comparing function names won't work.
7507 Instead compare pc addresses; this is just a heuristic as things
7508 may have moved, but in practice it gives the correct answer
7509 often enough until a better solution is found. */
7510 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
7512 for (; e
; e
= e
->next
)
7514 if (!e
->enabled
&& e
->function_name
)
7516 struct bp_location
*l
= b
->loc
;
7517 if (have_ambiguous_names
)
7519 for (; l
; l
= l
->next
)
7520 if (e
->address
== l
->address
)
7528 for (; l
; l
= l
->next
)
7529 if (l
->function_name
7530 && strcmp (e
->function_name
, l
->function_name
) == 0)
7540 update_global_location_list (1);
7544 /* Reset a breakpoint given it's struct breakpoint * BINT.
7545 The value we return ends up being the return value from catch_errors.
7546 Unused in this case. */
7549 breakpoint_re_set_one (void *bint
)
7551 /* get past catch_errs */
7552 struct breakpoint
*b
= (struct breakpoint
*) bint
;
7556 int *not_found_ptr
= ¬_found
;
7557 struct symtabs_and_lines sals
= {};
7558 struct symtabs_and_lines expanded
;
7560 enum enable_state save_enable
;
7561 struct gdb_exception e
;
7562 struct cleanup
*cleanups
;
7567 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7571 case bp_hardware_breakpoint
:
7573 if (b
->addr_string
== NULL
)
7575 /* Anything without a string can't be re-set. */
7576 delete_breakpoint (b
);
7580 set_language (b
->language
);
7581 input_radix
= b
->input_radix
;
7583 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7585 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
7590 int not_found_and_ok
= 0;
7591 /* For pending breakpoints, it's expected that parsing
7592 will fail until the right shared library is loaded.
7593 User has already told to create pending breakpoints and
7594 don't need extra messages. If breakpoint is in bp_shlib_disabled
7595 state, then user already saw the message about that breakpoint
7596 being disabled, and don't want to see more errors. */
7598 && (b
->condition_not_parsed
7599 || (b
->loc
&& b
->loc
->shlib_disabled
)
7600 || b
->enable_state
== bp_disabled
))
7601 not_found_and_ok
= 1;
7603 if (!not_found_and_ok
)
7605 /* We surely don't want to warn about the same breakpoint
7606 10 times. One solution, implemented here, is disable
7607 the breakpoint on error. Another solution would be to
7608 have separate 'warning emitted' flag. Since this
7609 happens only when a binary has changed, I don't know
7610 which approach is better. */
7611 b
->enable_state
= bp_disabled
;
7612 throw_exception (e
);
7619 gdb_assert (sals
.nelts
== 1);
7620 resolve_sal_pc (&sals
.sals
[0]);
7621 if (b
->condition_not_parsed
&& s
&& s
[0])
7623 char *cond_string
= 0;
7627 find_condition_and_thread (s
, sals
.sals
[0].pc
,
7628 &cond_string
, &thread
, &task
);
7630 b
->cond_string
= cond_string
;
7633 b
->condition_not_parsed
= 0;
7635 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
7636 cleanups
= make_cleanup (xfree
, sals
.sals
);
7637 update_breakpoint_locations (b
, expanded
);
7638 do_cleanups (cleanups
);
7642 case bp_hardware_watchpoint
:
7643 case bp_read_watchpoint
:
7644 case bp_access_watchpoint
:
7645 /* Watchpoint can be either on expression using entirely global variables,
7646 or it can be on local variables.
7648 Watchpoints of the first kind are never auto-deleted, and even persist
7649 across program restarts. Since they can use variables from shared
7650 libraries, we need to reparse expression as libraries are loaded
7653 Watchpoints on local variables can also change meaning as result
7654 of solib event. For example, if a watchpoint uses both a local and
7655 a global variables in expression, it's a local watchpoint, but
7656 unloading of a shared library will make the expression invalid.
7657 This is not a very common use case, but we still re-evaluate
7658 expression, to avoid surprises to the user.
7660 Note that for local watchpoints, we re-evaluate it only if
7661 watchpoints frame id is still valid. If it's not, it means
7662 the watchpoint is out of scope and will be deleted soon. In fact,
7663 I'm not sure we'll ever be called in this case.
7665 If a local watchpoint's frame id is still valid, then
7666 b->exp_valid_block is likewise valid, and we can safely use it.
7668 Don't do anything about disabled watchpoints, since they will
7669 be reevaluated again when enabled. */
7670 update_watchpoint (b
, 1 /* reparse */);
7672 /* We needn't really do anything to reset these, since the mask
7673 that requests them is unaffected by e.g., new libraries being
7679 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
7681 /* Delete overlay event breakpoints; they will be reset later by
7682 breakpoint_re_set. */
7683 case bp_overlay_event
:
7684 delete_breakpoint (b
);
7687 /* This breakpoint is special, it's set up when the inferior
7688 starts and we really don't want to touch it. */
7689 case bp_shlib_event
:
7691 /* Like bp_shlib_event, this breakpoint type is special.
7692 Once it is set up, we do not want to touch it. */
7693 case bp_thread_event
:
7695 /* Keep temporary breakpoints, which can be encountered when we step
7696 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7697 Otherwise these should have been blown away via the cleanup chain
7698 or by breakpoint_init_inferior when we rerun the executable. */
7701 case bp_watchpoint_scope
:
7703 case bp_step_resume
:
7705 case bp_longjmp_resume
:
7712 /* Re-set all breakpoints after symbols have been re-loaded. */
7714 breakpoint_re_set (void)
7716 struct breakpoint
*b
, *temp
;
7717 enum language save_language
;
7718 int save_input_radix
;
7720 save_language
= current_language
->la_language
;
7721 save_input_radix
= input_radix
;
7722 ALL_BREAKPOINTS_SAFE (b
, temp
)
7724 /* Format possible error msg */
7725 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
7727 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
7728 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
7729 do_cleanups (cleanups
);
7731 set_language (save_language
);
7732 input_radix
= save_input_radix
;
7734 create_overlay_event_breakpoint ("_ovly_debug_event");
7737 /* Reset the thread number of this breakpoint:
7739 - If the breakpoint is for all threads, leave it as-is.
7740 - Else, reset it to the current thread for inferior_ptid. */
7742 breakpoint_re_set_thread (struct breakpoint
*b
)
7744 if (b
->thread
!= -1)
7746 if (in_thread_list (inferior_ptid
))
7747 b
->thread
= pid_to_thread_id (inferior_ptid
);
7751 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7752 If from_tty is nonzero, it prints a message to that effect,
7753 which ends with a period (no newline). */
7756 set_ignore_count (int bptnum
, int count
, int from_tty
)
7758 struct breakpoint
*b
;
7764 if (b
->number
== bptnum
)
7766 b
->ignore_count
= count
;
7770 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7772 else if (count
== 1)
7773 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7776 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7779 breakpoints_changed ();
7780 observer_notify_breakpoint_modified (b
->number
);
7784 error (_("No breakpoint number %d."), bptnum
);
7788 make_breakpoint_silent (struct breakpoint
*b
)
7790 /* Silence the breakpoint. */
7794 /* Command to set ignore-count of breakpoint N to COUNT. */
7797 ignore_command (char *args
, int from_tty
)
7803 error_no_arg (_("a breakpoint number"));
7805 num
= get_number (&p
);
7807 error (_("bad breakpoint number: '%s'"), args
);
7809 error (_("Second argument (specified ignore-count) is missing."));
7811 set_ignore_count (num
,
7812 longest_to_int (value_as_long (parse_and_eval (p
))),
7815 printf_filtered ("\n");
7818 /* Call FUNCTION on each of the breakpoints
7819 whose numbers are given in ARGS. */
7822 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7827 struct breakpoint
*b
, *tmp
;
7831 error_no_arg (_("one or more breakpoint numbers"));
7838 num
= get_number_or_range (&p1
);
7841 warning (_("bad breakpoint number at or near '%s'"), p
);
7845 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7846 if (b
->number
== num
)
7848 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7851 if (related_breakpoint
)
7852 function (related_breakpoint
);
7856 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
7862 static struct bp_location
*
7863 find_location_by_number (char *number
)
7865 char *dot
= strchr (number
, '.');
7869 struct breakpoint
*b
;
7870 struct bp_location
*loc
;
7875 bp_num
= get_number_or_range (&p1
);
7877 error (_("Bad breakpoint number '%s'"), number
);
7880 if (b
->number
== bp_num
)
7885 if (!b
|| b
->number
!= bp_num
)
7886 error (_("Bad breakpoint number '%s'"), number
);
7889 loc_num
= get_number_or_range (&p1
);
7891 error (_("Bad breakpoint location number '%s'"), number
);
7895 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
7898 error (_("Bad breakpoint location number '%s'"), dot
+1);
7904 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7905 If from_tty is nonzero, it prints a message to that effect,
7906 which ends with a period (no newline). */
7909 disable_breakpoint (struct breakpoint
*bpt
)
7911 /* Never disable a watchpoint scope breakpoint; we want to
7912 hit them when we leave scope so we can delete both the
7913 watchpoint and its scope breakpoint at that time. */
7914 if (bpt
->type
== bp_watchpoint_scope
)
7917 /* You can't disable permanent breakpoints. */
7918 if (bpt
->enable_state
== bp_permanent
)
7921 bpt
->enable_state
= bp_disabled
;
7923 update_global_location_list (0);
7925 observer_notify_breakpoint_modified (bpt
->number
);
7929 disable_command (char *args
, int from_tty
)
7931 struct breakpoint
*bpt
;
7933 ALL_BREAKPOINTS (bpt
)
7937 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
7943 case bp_hardware_breakpoint
:
7945 case bp_hardware_watchpoint
:
7946 case bp_read_watchpoint
:
7947 case bp_access_watchpoint
:
7948 disable_breakpoint (bpt
);
7952 else if (strchr (args
, '.'))
7954 struct bp_location
*loc
= find_location_by_number (args
);
7957 update_global_location_list (0);
7960 map_breakpoint_numbers (args
, disable_breakpoint
);
7964 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
7966 int target_resources_ok
, other_type_used
;
7969 if (bpt
->type
== bp_hardware_breakpoint
)
7972 i
= hw_breakpoint_used_count ();
7973 target_resources_ok
=
7974 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
7976 if (target_resources_ok
== 0)
7977 error (_("No hardware breakpoint support in the target."));
7978 else if (target_resources_ok
< 0)
7979 error (_("Hardware breakpoints used exceeds limit."));
7982 if (bpt
->type
== bp_watchpoint
||
7983 bpt
->type
== bp_hardware_watchpoint
||
7984 bpt
->type
== bp_read_watchpoint
||
7985 bpt
->type
== bp_access_watchpoint
)
7987 struct gdb_exception e
;
7989 TRY_CATCH (e
, RETURN_MASK_ALL
)
7991 update_watchpoint (bpt
, 1 /* reparse */);
7995 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
8001 if (bpt
->enable_state
!= bp_permanent
)
8002 bpt
->enable_state
= bp_enabled
;
8003 bpt
->disposition
= disposition
;
8004 update_global_location_list (1);
8005 breakpoints_changed ();
8007 observer_notify_breakpoint_modified (bpt
->number
);
8012 enable_breakpoint (struct breakpoint
*bpt
)
8014 do_enable_breakpoint (bpt
, bpt
->disposition
);
8017 /* The enable command enables the specified breakpoints (or all defined
8018 breakpoints) so they once again become (or continue to be) effective
8019 in stopping the inferior. */
8022 enable_command (char *args
, int from_tty
)
8024 struct breakpoint
*bpt
;
8026 ALL_BREAKPOINTS (bpt
)
8030 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
8036 case bp_hardware_breakpoint
:
8038 case bp_hardware_watchpoint
:
8039 case bp_read_watchpoint
:
8040 case bp_access_watchpoint
:
8041 enable_breakpoint (bpt
);
8045 else if (strchr (args
, '.'))
8047 struct bp_location
*loc
= find_location_by_number (args
);
8050 update_global_location_list (1);
8053 map_breakpoint_numbers (args
, enable_breakpoint
);
8057 enable_once_breakpoint (struct breakpoint
*bpt
)
8059 do_enable_breakpoint (bpt
, disp_disable
);
8063 enable_once_command (char *args
, int from_tty
)
8065 map_breakpoint_numbers (args
, enable_once_breakpoint
);
8069 enable_delete_breakpoint (struct breakpoint
*bpt
)
8071 do_enable_breakpoint (bpt
, disp_del
);
8075 enable_delete_command (char *args
, int from_tty
)
8077 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
8081 set_breakpoint_cmd (char *args
, int from_tty
)
8086 show_breakpoint_cmd (char *args
, int from_tty
)
8090 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
8092 struct symtabs_and_lines
8093 decode_line_spec_1 (char *string
, int funfirstline
)
8095 struct symtabs_and_lines sals
;
8097 error (_("Empty line specification."));
8098 if (default_breakpoint_valid
)
8099 sals
= decode_line_1 (&string
, funfirstline
,
8100 default_breakpoint_symtab
,
8101 default_breakpoint_line
,
8102 (char ***) NULL
, NULL
);
8104 sals
= decode_line_1 (&string
, funfirstline
,
8105 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
8107 error (_("Junk at end of line specification: %s"), string
);
8111 /* Create and insert a raw software breakpoint at PC. Return an
8112 identifier, which should be used to remove the breakpoint later.
8113 In general, places which call this should be using something on the
8114 breakpoint chain instead; this function should be eliminated
8118 deprecated_insert_raw_breakpoint (CORE_ADDR pc
)
8120 struct bp_target_info
*bp_tgt
;
8122 bp_tgt
= xmalloc (sizeof (struct bp_target_info
));
8123 memset (bp_tgt
, 0, sizeof (struct bp_target_info
));
8125 bp_tgt
->placed_address
= pc
;
8126 if (target_insert_breakpoint (bp_tgt
) != 0)
8128 /* Could not insert the breakpoint. */
8136 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
8139 deprecated_remove_raw_breakpoint (void *bp
)
8141 struct bp_target_info
*bp_tgt
= bp
;
8144 ret
= target_remove_breakpoint (bp_tgt
);
8150 /* One (or perhaps two) breakpoints used for software single stepping. */
8152 static void *single_step_breakpoints
[2];
8154 /* Create and insert a breakpoint for software single step. */
8157 insert_single_step_breakpoint (CORE_ADDR next_pc
)
8161 if (single_step_breakpoints
[0] == NULL
)
8162 bpt_p
= &single_step_breakpoints
[0];
8165 gdb_assert (single_step_breakpoints
[1] == NULL
);
8166 bpt_p
= &single_step_breakpoints
[1];
8169 /* NOTE drow/2006-04-11: A future improvement to this function would be
8170 to only create the breakpoints once, and actually put them on the
8171 breakpoint chain. That would let us use set_raw_breakpoint. We could
8172 adjust the addresses each time they were needed. Doing this requires
8173 corresponding changes elsewhere where single step breakpoints are
8174 handled, however. So, for now, we use this. */
8176 *bpt_p
= deprecated_insert_raw_breakpoint (next_pc
);
8178 error (_("Could not insert single-step breakpoint at 0x%s"),
8179 paddr_nz (next_pc
));
8182 /* Remove and delete any breakpoints used for software single step. */
8185 remove_single_step_breakpoints (void)
8187 gdb_assert (single_step_breakpoints
[0] != NULL
);
8189 /* See insert_single_step_breakpoint for more about this deprecated
8191 deprecated_remove_raw_breakpoint (single_step_breakpoints
[0]);
8192 single_step_breakpoints
[0] = NULL
;
8194 if (single_step_breakpoints
[1] != NULL
)
8196 deprecated_remove_raw_breakpoint (single_step_breakpoints
[1]);
8197 single_step_breakpoints
[1] = NULL
;
8201 /* Check whether a software single-step breakpoint is inserted at PC. */
8204 single_step_breakpoint_inserted_here_p (CORE_ADDR pc
)
8208 for (i
= 0; i
< 2; i
++)
8210 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
8211 if (bp_tgt
&& bp_tgt
->placed_address
== pc
)
8218 /* Tracepoint-specific operations. */
8220 /* Set tracepoint count to NUM. */
8222 set_tracepoint_count (int num
)
8224 tracepoint_count
= num
;
8225 set_internalvar (lookup_internalvar ("tpnum"),
8226 value_from_longest (builtin_type_int32
, (LONGEST
) num
));
8230 trace_command (char *arg
, int from_tty
)
8232 break_command_really (arg
,
8233 NULL
, 0, 1 /* parse arg */,
8234 0 /* tempflag */, 0 /* hardwareflag */,
8236 0 /* Ignore count */,
8237 pending_break_support
,
8241 set_tracepoint_count (breakpoint_count
);
8244 /* Print information on tracepoint number TPNUM_EXP, or all if
8248 tracepoints_info (char *tpnum_exp
, int from_tty
)
8250 struct breakpoint
*b
;
8251 int tps_to_list
= 0;
8253 /* In the no-arguments case, say "No tracepoints" if none found. */
8266 ui_out_message (uiout
, 0, "No tracepoints.\n");
8271 /* Otherwise be the same as "info break". */
8272 breakpoints_info (tpnum_exp
, from_tty
);
8275 /* The 'enable trace' command enables tracepoints.
8276 Not supported by all targets. */
8278 enable_trace_command (char *args
, int from_tty
)
8280 enable_command (args
, from_tty
);
8283 /* The 'disable trace' command disables tracepoints.
8284 Not supported by all targets. */
8286 disable_trace_command (char *args
, int from_tty
)
8288 disable_command (args
, from_tty
);
8291 /* Remove a tracepoint (or all if no argument) */
8293 delete_trace_command (char *arg
, int from_tty
)
8295 struct breakpoint
*b
, *temp
;
8301 int breaks_to_delete
= 0;
8303 /* Delete all breakpoints if no argument.
8304 Do not delete internal or call-dummy breakpoints, these
8305 have to be deleted with an explicit breakpoint number argument. */
8310 breaks_to_delete
= 1;
8315 /* Ask user only if there are some breakpoints to delete. */
8317 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
8319 ALL_BREAKPOINTS_SAFE (b
, temp
)
8321 if (b
->type
== bp_tracepoint
&&
8323 delete_breakpoint (b
);
8328 map_breakpoint_numbers (arg
, delete_breakpoint
);
8331 /* Set passcount for tracepoint.
8333 First command argument is passcount, second is tracepoint number.
8334 If tracepoint number omitted, apply to most recently defined.
8335 Also accepts special argument "all". */
8338 trace_pass_command (char *args
, int from_tty
)
8340 struct breakpoint
*t1
= (struct breakpoint
*) -1, *t2
;
8344 if (args
== 0 || *args
== 0)
8345 error (_("passcount command requires an argument (count + optional TP num)"));
8347 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
8349 while (*args
&& isspace ((int) *args
))
8352 if (*args
&& strncasecmp (args
, "all", 3) == 0)
8354 args
+= 3; /* Skip special argument "all". */
8357 error (_("Junk at end of arguments."));
8360 t1
= get_tracepoint_by_number (&args
, 1, 1);
8366 ALL_TRACEPOINTS (t2
)
8367 if (t1
== (struct breakpoint
*) -1 || t1
== t2
)
8369 t2
->pass_count
= count
;
8370 observer_notify_tracepoint_modified (t2
->number
);
8372 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
8376 t1
= get_tracepoint_by_number (&args
, 1, 0);
8383 get_tracepoint (int num
)
8385 struct breakpoint
*t
;
8388 if (t
->number
== num
)
8394 /* Utility: parse a tracepoint number and look it up in the list.
8395 If MULTI_P is true, there might be a range of tracepoints in ARG.
8396 if OPTIONAL_P is true, then if the argument is missing, the most
8397 recent tracepoint (tracepoint_count) is returned. */
8399 get_tracepoint_by_number (char **arg
, int multi_p
, int optional_p
)
8401 extern int tracepoint_count
;
8402 struct breakpoint
*t
;
8404 char *instring
= arg
== NULL
? NULL
: *arg
;
8406 if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
8409 tpnum
= tracepoint_count
;
8411 error_no_arg (_("tracepoint number"));
8414 tpnum
= multi_p
? get_number_or_range (arg
) : get_number (arg
);
8418 if (instring
&& *instring
)
8419 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
8422 printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n"));
8427 if (t
->number
== tpnum
)
8432 /* FIXME: if we are in the middle of a range we don't want to give
8433 a message. The current interface to get_number_or_range doesn't
8434 allow us to discover this. */
8435 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
8439 /* save-tracepoints command */
8441 tracepoint_save_command (char *args
, int from_tty
)
8443 struct breakpoint
*tp
;
8445 struct action_line
*line
;
8447 char *i1
= " ", *i2
= " ";
8448 char *indent
, *actionline
, *pathname
;
8450 struct cleanup
*cleanup
;
8452 if (args
== 0 || *args
== 0)
8453 error (_("Argument required (file name in which to save tracepoints)"));
8455 /* See if we have anything to save. */
8456 ALL_TRACEPOINTS (tp
)
8463 warning (_("save-tracepoints: no tracepoints to save."));
8467 pathname
= tilde_expand (args
);
8468 cleanup
= make_cleanup (xfree
, pathname
);
8469 if (!(fp
= fopen (pathname
, "w")))
8470 error (_("Unable to open file '%s' for saving tracepoints (%s)"),
8471 args
, safe_strerror (errno
));
8472 make_cleanup_fclose (fp
);
8474 ALL_TRACEPOINTS (tp
)
8476 if (tp
->addr_string
)
8477 fprintf (fp
, "trace %s\n", tp
->addr_string
);
8480 sprintf_vma (tmp
, tp
->loc
->address
);
8481 fprintf (fp
, "trace *0x%s\n", tmp
);
8485 fprintf (fp
, " passcount %d\n", tp
->pass_count
);
8489 fprintf (fp
, " actions\n");
8491 for (line
= tp
->actions
; line
; line
= line
->next
)
8493 struct cmd_list_element
*cmd
;
8495 QUIT
; /* allow user to bail out with ^C */
8496 actionline
= line
->action
;
8497 while (isspace ((int) *actionline
))
8500 fprintf (fp
, "%s%s\n", indent
, actionline
);
8501 if (*actionline
!= '#') /* skip for comment lines */
8503 cmd
= lookup_cmd (&actionline
, cmdlist
, "", -1, 1);
8505 error (_("Bad action list item: %s"), actionline
);
8506 if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
8508 else if (cmd_cfunc_eq (cmd
, end_actions_pseudocommand
))
8514 do_cleanups (cleanup
);
8516 printf_filtered (_("Tracepoints saved to file '%s'.\n"), args
);
8520 /* Create a vector of all tracepoints. */
8525 VEC(breakpoint_p
) *tp_vec
= 0;
8526 struct breakpoint
*tp
;
8528 ALL_TRACEPOINTS (tp
)
8530 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
8537 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
8538 It is defined as a macro to prevent duplication.
8539 COMMAND should be a string constant containing the name of the command. */
8540 #define BREAK_ARGS_HELP(command) \
8541 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
8542 LOCATION may be a line number, function name, or \"*\" and an address.\n\
8543 If a line number is specified, break at start of code for that line.\n\
8544 If a function is specified, break at start of code for that function.\n\
8545 If an address is specified, break at that exact address.\n\
8546 With no LOCATION, uses current execution address of selected stack frame.\n\
8547 This is useful for breaking on return to a stack frame.\n\
8549 THREADNUM is the number from \"info threads\".\n\
8550 CONDITION is a boolean expression.\n\
8552 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
8554 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
8556 /* List of subcommands for "catch". */
8557 static struct cmd_list_element
*catch_cmdlist
;
8559 /* List of subcommands for "tcatch". */
8560 static struct cmd_list_element
*tcatch_cmdlist
;
8562 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
8563 lists, and pass some additional user data to the command function. */
8565 add_catch_command (char *name
, char *docstring
,
8566 void (*sfunc
) (char *args
, int from_tty
,
8567 struct cmd_list_element
*command
),
8568 void *user_data_catch
,
8569 void *user_data_tcatch
)
8571 struct cmd_list_element
*command
;
8573 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
8575 set_cmd_sfunc (command
, sfunc
);
8576 set_cmd_context (command
, user_data_catch
);
8578 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
8580 set_cmd_sfunc (command
, sfunc
);
8581 set_cmd_context (command
, user_data_tcatch
);
8585 _initialize_breakpoint (void)
8587 static struct cmd_list_element
*breakpoint_set_cmdlist
;
8588 static struct cmd_list_element
*breakpoint_show_cmdlist
;
8589 struct cmd_list_element
*c
;
8591 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
8593 breakpoint_chain
= 0;
8594 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
8595 before a breakpoint is set. */
8596 breakpoint_count
= 0;
8598 tracepoint_count
= 0;
8600 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
8601 Set ignore-count of breakpoint number N to COUNT.\n\
8602 Usage is `ignore N COUNT'."));
8604 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
8606 add_com ("commands", class_breakpoint
, commands_command
, _("\
8607 Set commands to be executed when a breakpoint is hit.\n\
8608 Give breakpoint number as argument after \"commands\".\n\
8609 With no argument, the targeted breakpoint is the last one set.\n\
8610 The commands themselves follow starting on the next line.\n\
8611 Type a line containing \"end\" to indicate the end of them.\n\
8612 Give \"silent\" as the first line to make the breakpoint silent;\n\
8613 then no output is printed when it is hit, except what the commands print."));
8615 add_com ("condition", class_breakpoint
, condition_command
, _("\
8616 Specify breakpoint number N to break only if COND is true.\n\
8617 Usage is `condition N COND', where N is an integer and COND is an\n\
8618 expression to be evaluated whenever breakpoint N is reached."));
8620 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
8621 Set a temporary breakpoint.\n\
8622 Like \"break\" except the breakpoint is only temporary,\n\
8623 so it will be deleted when hit. Equivalent to \"break\" followed\n\
8624 by using \"enable delete\" on the breakpoint number.\n\
8626 BREAK_ARGS_HELP ("tbreak")));
8627 set_cmd_completer (c
, location_completer
);
8629 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
8630 Set a hardware assisted breakpoint.\n\
8631 Like \"break\" except the breakpoint requires hardware support,\n\
8632 some target hardware may not have this support.\n\
8634 BREAK_ARGS_HELP ("hbreak")));
8635 set_cmd_completer (c
, location_completer
);
8637 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
8638 Set a temporary hardware assisted breakpoint.\n\
8639 Like \"hbreak\" except the breakpoint is only temporary,\n\
8640 so it will be deleted when hit.\n\
8642 BREAK_ARGS_HELP ("thbreak")));
8643 set_cmd_completer (c
, location_completer
);
8645 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
8646 Enable some breakpoints.\n\
8647 Give breakpoint numbers (separated by spaces) as arguments.\n\
8648 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8649 This is used to cancel the effect of the \"disable\" command.\n\
8650 With a subcommand you can enable temporarily."),
8651 &enablelist
, "enable ", 1, &cmdlist
);
8653 add_com ("ab", class_breakpoint
, enable_command
, _("\
8654 Enable some breakpoints.\n\
8655 Give breakpoint numbers (separated by spaces) as arguments.\n\
8656 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8657 This is used to cancel the effect of the \"disable\" command.\n\
8658 With a subcommand you can enable temporarily."));
8660 add_com_alias ("en", "enable", class_breakpoint
, 1);
8662 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
8663 Enable some breakpoints.\n\
8664 Give breakpoint numbers (separated by spaces) as arguments.\n\
8665 This is used to cancel the effect of the \"disable\" command.\n\
8666 May be abbreviated to simply \"enable\".\n"),
8667 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
8669 add_cmd ("once", no_class
, enable_once_command
, _("\
8670 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8671 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8674 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8675 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8676 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8679 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8680 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8681 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8684 add_cmd ("once", no_class
, enable_once_command
, _("\
8685 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8686 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8689 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
8690 Disable some breakpoints.\n\
8691 Arguments are breakpoint numbers with spaces in between.\n\
8692 To disable all breakpoints, give no argument.\n\
8693 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8694 &disablelist
, "disable ", 1, &cmdlist
);
8695 add_com_alias ("dis", "disable", class_breakpoint
, 1);
8696 add_com_alias ("disa", "disable", class_breakpoint
, 1);
8698 add_com ("sb", class_breakpoint
, disable_command
, _("\
8699 Disable some breakpoints.\n\
8700 Arguments are breakpoint numbers with spaces in between.\n\
8701 To disable all breakpoints, give no argument.\n\
8702 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8704 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
8705 Disable some breakpoints.\n\
8706 Arguments are breakpoint numbers with spaces in between.\n\
8707 To disable all breakpoints, give no argument.\n\
8708 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8709 This command may be abbreviated \"disable\"."),
8712 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
8713 Delete some breakpoints or auto-display expressions.\n\
8714 Arguments are breakpoint numbers with spaces in between.\n\
8715 To delete all breakpoints, give no argument.\n\
8717 Also a prefix command for deletion of other GDB objects.\n\
8718 The \"unset\" command is also an alias for \"delete\"."),
8719 &deletelist
, "delete ", 1, &cmdlist
);
8720 add_com_alias ("d", "delete", class_breakpoint
, 1);
8721 add_com_alias ("del", "delete", class_breakpoint
, 1);
8723 add_com ("db", class_breakpoint
, delete_command
, _("\
8724 Delete some breakpoints.\n\
8725 Arguments are breakpoint numbers with spaces in between.\n\
8726 To delete all breakpoints, give no argument.\n"));
8728 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
8729 Delete some breakpoints or auto-display expressions.\n\
8730 Arguments are breakpoint numbers with spaces in between.\n\
8731 To delete all breakpoints, give no argument.\n\
8732 This command may be abbreviated \"delete\"."),
8735 add_com ("clear", class_breakpoint
, clear_command
, _("\
8736 Clear breakpoint at specified line or function.\n\
8737 Argument may be line number, function name, or \"*\" and an address.\n\
8738 If line number is specified, all breakpoints in that line are cleared.\n\
8739 If function is specified, breakpoints at beginning of function are cleared.\n\
8740 If an address is specified, breakpoints at that address are cleared.\n\
8742 With no argument, clears all breakpoints in the line that the selected frame\n\
8745 See also the \"delete\" command which clears breakpoints by number."));
8747 c
= add_com ("break", class_breakpoint
, break_command
, _("\
8748 Set breakpoint at specified line or function.\n"
8749 BREAK_ARGS_HELP ("break")));
8750 set_cmd_completer (c
, location_completer
);
8752 add_com_alias ("b", "break", class_run
, 1);
8753 add_com_alias ("br", "break", class_run
, 1);
8754 add_com_alias ("bre", "break", class_run
, 1);
8755 add_com_alias ("brea", "break", class_run
, 1);
8759 add_com_alias ("ba", "break", class_breakpoint
, 1);
8760 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
8765 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
8766 Break in function/address or break at a line in the current file."),
8767 &stoplist
, "stop ", 1, &cmdlist
);
8768 add_cmd ("in", class_breakpoint
, stopin_command
,
8769 _("Break in function or address."), &stoplist
);
8770 add_cmd ("at", class_breakpoint
, stopat_command
,
8771 _("Break at a line in the current file."), &stoplist
);
8772 add_com ("status", class_info
, breakpoints_info
, _("\
8773 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8774 The \"Type\" column indicates one of:\n\
8775 \tbreakpoint - normal breakpoint\n\
8776 \twatchpoint - watchpoint\n\
8777 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8778 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8779 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8780 address and file/line number respectively.\n\
8782 Convenience variable \"$_\" and default examine address for \"x\"\n\
8783 are set to the address of the last breakpoint listed unless the command\n\
8784 is prefixed with \"server \".\n\n\
8785 Convenience variable \"$bpnum\" contains the number of the last\n\
8789 add_info ("breakpoints", breakpoints_info
, _("\
8790 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8791 The \"Type\" column indicates one of:\n\
8792 \tbreakpoint - normal breakpoint\n\
8793 \twatchpoint - watchpoint\n\
8794 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8795 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8796 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8797 address and file/line number respectively.\n\
8799 Convenience variable \"$_\" and default examine address for \"x\"\n\
8800 are set to the address of the last breakpoint listed unless the command\n\
8801 is prefixed with \"server \".\n\n\
8802 Convenience variable \"$bpnum\" contains the number of the last\n\
8806 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
8807 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8808 The \"Type\" column indicates one of:\n\
8809 \tbreakpoint - normal breakpoint\n\
8810 \twatchpoint - watchpoint\n\
8811 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8812 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8813 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8814 address and file/line number respectively.\n\
8816 Convenience variable \"$_\" and default examine address for \"x\"\n\
8817 are set to the address of the last breakpoint listed unless the command\n\
8818 is prefixed with \"server \".\n\n\
8819 Convenience variable \"$bpnum\" contains the number of the last\n\
8822 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
8823 Status of all breakpoints, or breakpoint number NUMBER.\n\
8824 The \"Type\" column indicates one of:\n\
8825 \tbreakpoint - normal breakpoint\n\
8826 \twatchpoint - watchpoint\n\
8827 \tlongjmp - internal breakpoint used to step through longjmp()\n\
8828 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8829 \tuntil - internal breakpoint used by the \"until\" command\n\
8830 \tfinish - internal breakpoint used by the \"finish\" command\n\
8831 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8832 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8833 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8834 address and file/line number respectively.\n\
8836 Convenience variable \"$_\" and default examine address for \"x\"\n\
8837 are set to the address of the last breakpoint listed unless the command\n\
8838 is prefixed with \"server \".\n\n\
8839 Convenience variable \"$bpnum\" contains the number of the last\n\
8841 &maintenanceinfolist
);
8843 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
8844 Set catchpoints to catch events."),
8845 &catch_cmdlist
, "catch ",
8846 0/*allow-unknown*/, &cmdlist
);
8848 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
8849 Set temporary catchpoints to catch events."),
8850 &tcatch_cmdlist
, "tcatch ",
8851 0/*allow-unknown*/, &cmdlist
);
8853 /* Add catch and tcatch sub-commands. */
8854 add_catch_command ("catch", _("\
8855 Catch an exception, when caught.\n\
8856 With an argument, catch only exceptions with the given name."),
8857 catch_catch_command
,
8860 add_catch_command ("throw", _("\
8861 Catch an exception, when thrown.\n\
8862 With an argument, catch only exceptions with the given name."),
8863 catch_throw_command
,
8866 add_catch_command ("fork", _("Catch calls to fork."),
8867 catch_fork_command_1
,
8868 (void *) (uintptr_t) catch_fork_permanent
,
8869 (void *) (uintptr_t) catch_fork_temporary
);
8870 add_catch_command ("vfork", _("Catch calls to vfork."),
8871 catch_fork_command_1
,
8872 (void *) (uintptr_t) catch_vfork_permanent
,
8873 (void *) (uintptr_t) catch_vfork_temporary
);
8874 add_catch_command ("exec", _("Catch calls to exec."),
8875 catch_exec_command_1
,
8878 add_catch_command ("exception", _("\
8879 Catch Ada exceptions, when raised.\n\
8880 With an argument, catch only exceptions with the given name."),
8881 catch_ada_exception_command
,
8884 add_catch_command ("assert", _("\
8885 Catch failed Ada assertions, when raised.\n\
8886 With an argument, catch only exceptions with the given name."),
8887 catch_assert_command
,
8891 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
8892 Set a watchpoint for an expression.\n\
8893 A watchpoint stops execution of your program whenever the value of\n\
8894 an expression changes."));
8895 set_cmd_completer (c
, expression_completer
);
8897 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
8898 Set a read watchpoint for an expression.\n\
8899 A watchpoint stops execution of your program whenever the value of\n\
8900 an expression is read."));
8901 set_cmd_completer (c
, expression_completer
);
8903 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
8904 Set a watchpoint for an expression.\n\
8905 A watchpoint stops execution of your program whenever the value of\n\
8906 an expression is either read or written."));
8907 set_cmd_completer (c
, expression_completer
);
8909 add_info ("watchpoints", breakpoints_info
,
8910 _("Synonym for ``info breakpoints''."));
8913 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8914 respond to changes - contrary to the description. */
8915 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
8916 &can_use_hw_watchpoints
, _("\
8917 Set debugger's willingness to use watchpoint hardware."), _("\
8918 Show debugger's willingness to use watchpoint hardware."), _("\
8919 If zero, gdb will not use hardware for new watchpoints, even if\n\
8920 such is available. (However, any hardware watchpoints that were\n\
8921 created before setting this to nonzero, will continue to use watchpoint\n\
8924 show_can_use_hw_watchpoints
,
8925 &setlist
, &showlist
);
8927 can_use_hw_watchpoints
= 1;
8929 /* Tracepoint manipulation commands. */
8931 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
8932 Set a tracepoint at specified line or function.\n\
8934 BREAK_ARGS_HELP ("trace") "\n\
8935 Do \"help tracepoints\" for info on other tracepoint commands."));
8936 set_cmd_completer (c
, location_completer
);
8938 add_com_alias ("tp", "trace", class_alias
, 0);
8939 add_com_alias ("tr", "trace", class_alias
, 1);
8940 add_com_alias ("tra", "trace", class_alias
, 1);
8941 add_com_alias ("trac", "trace", class_alias
, 1);
8943 add_info ("tracepoints", tracepoints_info
, _("\
8944 Status of tracepoints, or tracepoint number NUMBER.\n\
8945 Convenience variable \"$tpnum\" contains the number of the\n\
8946 last tracepoint set."));
8948 add_info_alias ("tp", "tracepoints", 1);
8950 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
8951 Delete specified tracepoints.\n\
8952 Arguments are tracepoint numbers, separated by spaces.\n\
8953 No argument means delete all tracepoints."),
8956 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
8957 Disable specified tracepoints.\n\
8958 Arguments are tracepoint numbers, separated by spaces.\n\
8959 No argument means disable all tracepoints."),
8961 deprecate_cmd (c
, "disable");
8963 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
8964 Enable specified tracepoints.\n\
8965 Arguments are tracepoint numbers, separated by spaces.\n\
8966 No argument means enable all tracepoints."),
8968 deprecate_cmd (c
, "enable");
8970 add_com ("passcount", class_trace
, trace_pass_command
, _("\
8971 Set the passcount for a tracepoint.\n\
8972 The trace will end when the tracepoint has been passed 'count' times.\n\
8973 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
8974 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
8976 c
= add_com ("save-tracepoints", class_trace
, tracepoint_save_command
, _("\
8977 Save current tracepoint definitions as a script.\n\
8978 Use the 'source' command in another debug session to restore them."));
8979 set_cmd_completer (c
, filename_completer
);
8981 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
8982 Breakpoint specific settings\n\
8983 Configure various breakpoint-specific variables such as\n\
8984 pending breakpoint behavior"),
8985 &breakpoint_set_cmdlist
, "set breakpoint ",
8986 0/*allow-unknown*/, &setlist
);
8987 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
8988 Breakpoint specific settings\n\
8989 Configure various breakpoint-specific variables such as\n\
8990 pending breakpoint behavior"),
8991 &breakpoint_show_cmdlist
, "show breakpoint ",
8992 0/*allow-unknown*/, &showlist
);
8994 add_setshow_auto_boolean_cmd ("pending", no_class
,
8995 &pending_break_support
, _("\
8996 Set debugger's behavior regarding pending breakpoints."), _("\
8997 Show debugger's behavior regarding pending breakpoints."), _("\
8998 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8999 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
9000 an error. If auto, an unrecognized breakpoint location results in a\n\
9001 user-query to see if a pending breakpoint should be created."),
9003 show_pending_break_support
,
9004 &breakpoint_set_cmdlist
,
9005 &breakpoint_show_cmdlist
);
9007 pending_break_support
= AUTO_BOOLEAN_AUTO
;
9009 add_setshow_boolean_cmd ("auto-hw", no_class
,
9010 &automatic_hardware_breakpoints
, _("\
9011 Set automatic usage of hardware breakpoints."), _("\
9012 Show automatic usage of hardware breakpoints."), _("\
9013 If set, the debugger will automatically use hardware breakpoints for\n\
9014 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
9015 a warning will be emitted for such breakpoints."),
9017 show_automatic_hardware_breakpoints
,
9018 &breakpoint_set_cmdlist
,
9019 &breakpoint_show_cmdlist
);
9021 add_setshow_enum_cmd ("always-inserted", class_support
,
9022 always_inserted_enums
, &always_inserted_mode
, _("\
9023 Set mode for inserting breakpoints."), _("\
9024 Show mode for inserting breakpoints."), _("\
9025 When this mode is off, breakpoints are inserted in inferior when it is\n\
9026 resumed, and removed when execution stops. When this mode is on,\n\
9027 breakpoints are inserted immediately and removed only when the user\n\
9028 deletes the breakpoint. When this mode is auto (which is the default),\n\
9029 the behaviour depends on the non-stop setting (see help set non-stop).\n\
9030 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
9031 behaves as if always-inserted mode is on; if gdb is controlling the\n\
9032 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
9034 &show_always_inserted_mode
,
9035 &breakpoint_set_cmdlist
,
9036 &breakpoint_show_cmdlist
);
9038 automatic_hardware_breakpoints
= 1;
9040 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);