Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Everything about breakpoints, for GDB. |
8926118c | 2 | |
6aba47ca | 3 | Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, |
9b254dd1 DJ |
4 | 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, |
5 | 2008 Free Software Foundation, Inc. | |
c906108c | 6 | |
c5aa993b | 7 | This file is part of GDB. |
c906108c | 8 | |
c5aa993b JM |
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 | |
a9762ec7 | 11 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 12 | (at your option) any later version. |
c906108c | 13 | |
c5aa993b JM |
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. | |
c906108c | 18 | |
c5aa993b | 19 | You should have received a copy of the GNU General Public License |
a9762ec7 | 20 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
21 | |
22 | #include "defs.h" | |
23 | #include <ctype.h> | |
776592bf | 24 | #include "hashtab.h" |
c906108c SS |
25 | #include "symtab.h" |
26 | #include "frame.h" | |
27 | #include "breakpoint.h" | |
28 | #include "gdbtypes.h" | |
29 | #include "expression.h" | |
30 | #include "gdbcore.h" | |
31 | #include "gdbcmd.h" | |
32 | #include "value.h" | |
33 | #include "command.h" | |
34 | #include "inferior.h" | |
35 | #include "gdbthread.h" | |
36 | #include "target.h" | |
37 | #include "language.h" | |
38 | #include "gdb_string.h" | |
39 | #include "demangle.h" | |
40 | #include "annotate.h" | |
41 | #include "symfile.h" | |
42 | #include "objfiles.h" | |
0378c332 | 43 | #include "source.h" |
c5f0f3d0 | 44 | #include "linespec.h" |
c94fdfd0 | 45 | #include "completer.h" |
5b7f31a4 | 46 | #include "gdb.h" |
8b93c638 | 47 | #include "ui-out.h" |
e1507482 | 48 | #include "cli/cli-script.h" |
0225421b | 49 | #include "gdb_assert.h" |
fe898f56 | 50 | #include "block.h" |
a77053c2 | 51 | #include "solib.h" |
84acb35a JJ |
52 | #include "solist.h" |
53 | #include "observer.h" | |
60250e8b | 54 | #include "exceptions.h" |
765dc015 | 55 | #include "memattr.h" |
f7f9143b | 56 | #include "ada-lang.h" |
d1aa2f50 | 57 | #include "top.h" |
fa4727a6 | 58 | #include "wrapper.h" |
79a45b7d | 59 | #include "valprint.h" |
c906108c | 60 | |
034dad6f | 61 | #include "mi/mi-common.h" |
104c1213 | 62 | |
44feb3ce TT |
63 | /* Arguments to pass as context to some catch command handlers. */ |
64 | #define CATCH_PERMANENT ((void *) (uintptr_t) 0) | |
65 | #define CATCH_TEMPORARY ((void *) (uintptr_t) 1) | |
c906108c | 66 | |
44feb3ce | 67 | /* Prototypes for local functions. */ |
c906108c | 68 | |
a14ed312 | 69 | static void enable_delete_command (char *, int); |
c906108c | 70 | |
a14ed312 | 71 | static void enable_delete_breakpoint (struct breakpoint *); |
c906108c | 72 | |
a14ed312 | 73 | static void enable_once_command (char *, int); |
c906108c | 74 | |
a14ed312 | 75 | static void enable_once_breakpoint (struct breakpoint *); |
c906108c | 76 | |
a14ed312 | 77 | static void disable_command (char *, int); |
c906108c | 78 | |
a14ed312 | 79 | static void enable_command (char *, int); |
c906108c | 80 | |
a14ed312 | 81 | static void map_breakpoint_numbers (char *, void (*)(struct breakpoint *)); |
c906108c | 82 | |
a14ed312 | 83 | static void ignore_command (char *, int); |
c906108c | 84 | |
4efb68b1 | 85 | static int breakpoint_re_set_one (void *); |
c906108c | 86 | |
a14ed312 | 87 | static void clear_command (char *, int); |
c906108c | 88 | |
a14ed312 | 89 | static void catch_command (char *, int); |
c906108c | 90 | |
a14ed312 | 91 | static void watch_command (char *, int); |
c906108c | 92 | |
a14ed312 | 93 | static int can_use_hardware_watchpoint (struct value *); |
c906108c | 94 | |
98deb0da | 95 | static void break_command_1 (char *, int, int); |
c906108c | 96 | |
a14ed312 | 97 | static void mention (struct breakpoint *); |
c906108c | 98 | |
4d28f7a8 | 99 | struct breakpoint *set_raw_breakpoint (struct symtab_and_line, enum bptype); |
c906108c | 100 | |
9f60f21b | 101 | static void check_duplicates (struct breakpoint *); |
c906108c | 102 | |
76897487 KB |
103 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
104 | ||
88f7da05 KB |
105 | static CORE_ADDR adjust_breakpoint_address (CORE_ADDR bpaddr, |
106 | enum bptype bptype); | |
76897487 | 107 | |
714835d5 | 108 | static void describe_other_breakpoints (CORE_ADDR, struct obj_section *, int); |
c906108c | 109 | |
a14ed312 | 110 | static void breakpoints_info (char *, int); |
c906108c | 111 | |
a14ed312 | 112 | static void breakpoint_1 (int, int); |
c906108c | 113 | |
89f9893c | 114 | static bpstat bpstat_alloc (const struct bp_location *, bpstat); |
c906108c | 115 | |
4efb68b1 | 116 | static int breakpoint_cond_eval (void *); |
c906108c | 117 | |
4efb68b1 | 118 | static void cleanup_executing_breakpoints (void *); |
c906108c | 119 | |
a14ed312 | 120 | static void commands_command (char *, int); |
c906108c | 121 | |
a14ed312 | 122 | static void condition_command (char *, int); |
c906108c | 123 | |
a14ed312 | 124 | static int get_number_trailer (char **, int); |
c906108c | 125 | |
a14ed312 | 126 | void set_breakpoint_count (int); |
c906108c | 127 | |
c5aa993b JM |
128 | typedef enum |
129 | { | |
130 | mark_inserted, | |
131 | mark_uninserted | |
132 | } | |
133 | insertion_state_t; | |
c906108c | 134 | |
0bde7532 | 135 | static int remove_breakpoint (struct bp_location *, insertion_state_t); |
c906108c | 136 | |
a14ed312 | 137 | static enum print_stop_action print_it_typical (bpstat); |
e514a9d6 JM |
138 | |
139 | static enum print_stop_action print_bp_stop_message (bpstat bs); | |
c906108c | 140 | |
4efb68b1 | 141 | static int watchpoint_check (void *); |
c906108c | 142 | |
a14ed312 | 143 | static void maintenance_info_breakpoints (char *, int); |
c906108c | 144 | |
1900040c MS |
145 | static void create_overlay_event_breakpoint (char *); |
146 | ||
a14ed312 | 147 | static int hw_breakpoint_used_count (void); |
c906108c | 148 | |
a14ed312 | 149 | static int hw_watchpoint_used_count (enum bptype, int *); |
c906108c | 150 | |
a14ed312 | 151 | static void hbreak_command (char *, int); |
c906108c | 152 | |
a14ed312 | 153 | static void thbreak_command (char *, int); |
c906108c | 154 | |
a14ed312 | 155 | static void watch_command_1 (char *, int, int); |
c906108c | 156 | |
a14ed312 | 157 | static void rwatch_command (char *, int); |
c906108c | 158 | |
a14ed312 | 159 | static void awatch_command (char *, int); |
c906108c | 160 | |
a14ed312 | 161 | static void do_enable_breakpoint (struct breakpoint *, enum bpdisp); |
c906108c | 162 | |
a14ed312 | 163 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 164 | |
a14ed312 | 165 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 166 | |
a14ed312 | 167 | static void stopat_command (char *arg, int from_tty); |
7a292a7a | 168 | |
a14ed312 | 169 | static char *ep_parse_optional_if_clause (char **arg); |
7a292a7a | 170 | |
a14ed312 | 171 | static char *ep_parse_optional_filename (char **arg); |
7a292a7a | 172 | |
d85310f7 MS |
173 | static void catch_exception_command_1 (enum exception_event_kind ex_event, |
174 | char *arg, int tempflag, int from_tty); | |
7a292a7a | 175 | |
a14ed312 | 176 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 177 | |
a14ed312 | 178 | static void ep_skip_leading_whitespace (char **s); |
7a292a7a | 179 | |
1aafd4da UW |
180 | static int single_step_breakpoint_inserted_here_p (CORE_ADDR pc); |
181 | ||
fe3f5fa8 VP |
182 | static void free_bp_location (struct bp_location *loc); |
183 | ||
39d61571 | 184 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 185 | |
b60e7edf | 186 | static void update_global_location_list (int); |
a5606eee | 187 | |
b60e7edf | 188 | static void update_global_location_list_nothrow (int); |
74960c60 VP |
189 | |
190 | static int is_hardware_watchpoint (struct breakpoint *bpt); | |
191 | ||
192 | static void insert_breakpoint_locations (void); | |
a5606eee | 193 | |
2cec12e5 AR |
194 | static const char * |
195 | bpdisp_text (enum bpdisp disp) | |
196 | { | |
197 | /* NOTE: the following values are a part of MI protocol and represent | |
198 | values of 'disp' field returned when inferior stops at a breakpoint. */ | |
199 | static char *bpdisps[] = {"del", "dstp", "dis", "keep"}; | |
200 | return bpdisps[(int) disp]; | |
201 | } | |
c906108c | 202 | |
2cec12e5 | 203 | /* Prototypes for exported functions. */ |
c906108c SS |
204 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
205 | if such is available. */ | |
206 | static int can_use_hw_watchpoints; | |
207 | ||
920d2a44 AC |
208 | static void |
209 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
210 | struct cmd_list_element *c, | |
211 | const char *value) | |
212 | { | |
213 | fprintf_filtered (file, _("\ | |
214 | Debugger's willingness to use watchpoint hardware is %s.\n"), | |
215 | value); | |
216 | } | |
217 | ||
fa8d40ab JJ |
218 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
219 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
220 | for unrecognized breakpoint locations. | |
221 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ | |
222 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
223 | static void |
224 | show_pending_break_support (struct ui_file *file, int from_tty, | |
225 | struct cmd_list_element *c, | |
226 | const char *value) | |
227 | { | |
228 | fprintf_filtered (file, _("\ | |
229 | Debugger's behavior regarding pending breakpoints is %s.\n"), | |
230 | value); | |
231 | } | |
fa8d40ab | 232 | |
765dc015 VP |
233 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
234 | set with "break" but falling in read-only memory. | |
235 | If 0, gdb will warn about such breakpoints, but won't automatically | |
236 | use hardware breakpoints. */ | |
237 | static int automatic_hardware_breakpoints; | |
238 | static void | |
239 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
240 | struct cmd_list_element *c, | |
241 | const char *value) | |
242 | { | |
243 | fprintf_filtered (file, _("\ | |
244 | Automatic usage of hardware breakpoints is %s.\n"), | |
245 | value); | |
246 | } | |
247 | ||
33e5cbd6 PA |
248 | /* If on, gdb will keep breakpoints inserted even as inferior is |
249 | stopped, and immediately insert any new breakpoints. If off, gdb | |
250 | will insert breakpoints into inferior only when resuming it, and | |
251 | will remove breakpoints upon stop. If auto, GDB will behave as ON | |
252 | if in non-stop mode, and as OFF if all-stop mode.*/ | |
253 | ||
254 | static const char always_inserted_auto[] = "auto"; | |
255 | static const char always_inserted_on[] = "on"; | |
256 | static const char always_inserted_off[] = "off"; | |
257 | static const char *always_inserted_enums[] = { | |
258 | always_inserted_auto, | |
259 | always_inserted_off, | |
260 | always_inserted_on, | |
261 | NULL | |
262 | }; | |
263 | static const char *always_inserted_mode = always_inserted_auto; | |
264 | static void | |
74960c60 | 265 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 266 | struct cmd_list_element *c, const char *value) |
74960c60 | 267 | { |
33e5cbd6 PA |
268 | if (always_inserted_mode == always_inserted_auto) |
269 | fprintf_filtered (file, _("\ | |
270 | Always inserted breakpoint mode is %s (currently %s).\n"), | |
271 | value, | |
272 | breakpoints_always_inserted_mode () ? "on" : "off"); | |
273 | else | |
274 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), value); | |
74960c60 VP |
275 | } |
276 | ||
33e5cbd6 PA |
277 | int |
278 | breakpoints_always_inserted_mode (void) | |
279 | { | |
280 | return (always_inserted_mode == always_inserted_on | |
281 | || (always_inserted_mode == always_inserted_auto && non_stop)); | |
282 | } | |
765dc015 | 283 | |
a14ed312 | 284 | void _initialize_breakpoint (void); |
c906108c | 285 | |
c906108c SS |
286 | /* Are we executing breakpoint commands? */ |
287 | static int executing_breakpoint_commands; | |
288 | ||
c02f5703 MS |
289 | /* Are overlay event breakpoints enabled? */ |
290 | static int overlay_events_enabled; | |
291 | ||
c906108c SS |
292 | /* Walk the following statement or block through all breakpoints. |
293 | ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current | |
294 | breakpoint. */ | |
295 | ||
5c44784c | 296 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 297 | |
5c44784c JM |
298 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
299 | for (B = breakpoint_chain; \ | |
300 | B ? (TMP=B->next, 1): 0; \ | |
301 | B = TMP) | |
c906108c | 302 | |
7cc221ef DJ |
303 | /* Similar iterators for the low-level breakpoints. */ |
304 | ||
0d381245 | 305 | #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->global_next) |
7cc221ef DJ |
306 | |
307 | #define ALL_BP_LOCATIONS_SAFE(B,TMP) \ | |
308 | for (B = bp_location_chain; \ | |
0d381245 | 309 | B ? (TMP=B->global_next, 1): 0; \ |
7cc221ef DJ |
310 | B = TMP) |
311 | ||
7cc221ef | 312 | /* Chains of all breakpoints defined. */ |
c906108c SS |
313 | |
314 | struct breakpoint *breakpoint_chain; | |
315 | ||
7cc221ef DJ |
316 | struct bp_location *bp_location_chain; |
317 | ||
20874c92 VP |
318 | /* The locations that no longer correspond to any breakpoint, |
319 | unlinked from bp_location_chain, but for which a hit | |
320 | may still be reported by a target. */ | |
321 | VEC(bp_location_p) *moribund_locations = NULL; | |
322 | ||
c906108c SS |
323 | /* Number of last breakpoint made. */ |
324 | ||
325 | int breakpoint_count; | |
326 | ||
468d015d JJ |
327 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
328 | static int | |
329 | breakpoint_enabled (struct breakpoint *b) | |
330 | { | |
0d381245 | 331 | return (b->enable_state == bp_enabled); |
468d015d JJ |
332 | } |
333 | ||
c906108c SS |
334 | /* Set breakpoint count to NUM. */ |
335 | ||
336 | void | |
fba45db2 | 337 | set_breakpoint_count (int num) |
c906108c SS |
338 | { |
339 | breakpoint_count = num; | |
340 | set_internalvar (lookup_internalvar ("bpnum"), | |
8b9b9e1a | 341 | value_from_longest (builtin_type_int32, (LONGEST) num)); |
c906108c SS |
342 | } |
343 | ||
344 | /* Used in run_command to zero the hit count when a new run starts. */ | |
345 | ||
346 | void | |
fba45db2 | 347 | clear_breakpoint_hit_counts (void) |
c906108c SS |
348 | { |
349 | struct breakpoint *b; | |
350 | ||
351 | ALL_BREAKPOINTS (b) | |
352 | b->hit_count = 0; | |
353 | } | |
354 | ||
355 | /* Default address, symtab and line to put a breakpoint at | |
356 | for "break" command with no arg. | |
357 | if default_breakpoint_valid is zero, the other three are | |
358 | not valid, and "break" with no arg is an error. | |
359 | ||
360 | This set by print_stack_frame, which calls set_default_breakpoint. */ | |
361 | ||
362 | int default_breakpoint_valid; | |
363 | CORE_ADDR default_breakpoint_address; | |
364 | struct symtab *default_breakpoint_symtab; | |
365 | int default_breakpoint_line; | |
366 | \f | |
367 | /* *PP is a string denoting a breakpoint. Get the number of the breakpoint. | |
368 | Advance *PP after the string and any trailing whitespace. | |
369 | ||
370 | Currently the string can either be a number or "$" followed by the name | |
371 | of a convenience variable. Making it an expression wouldn't work well | |
5c44784c | 372 | for map_breakpoint_numbers (e.g. "4 + 5 + 6"). |
40c03ae8 EZ |
373 | |
374 | If the string is a NULL pointer, that denotes the last breakpoint. | |
5c44784c JM |
375 | |
376 | TRAILER is a character which can be found after the number; most | |
377 | commonly this is `-'. If you don't want a trailer, use \0. */ | |
c906108c | 378 | static int |
fba45db2 | 379 | get_number_trailer (char **pp, int trailer) |
c906108c | 380 | { |
5c44784c | 381 | int retval = 0; /* default */ |
c906108c SS |
382 | char *p = *pp; |
383 | ||
384 | if (p == NULL) | |
385 | /* Empty line means refer to the last breakpoint. */ | |
386 | return breakpoint_count; | |
387 | else if (*p == '$') | |
388 | { | |
389 | /* Make a copy of the name, so we can null-terminate it | |
c5aa993b | 390 | to pass to lookup_internalvar(). */ |
c906108c SS |
391 | char *varname; |
392 | char *start = ++p; | |
278cd55f | 393 | struct value *val; |
c906108c SS |
394 | |
395 | while (isalnum (*p) || *p == '_') | |
396 | p++; | |
397 | varname = (char *) alloca (p - start + 1); | |
398 | strncpy (varname, start, p - start); | |
399 | varname[p - start] = '\0'; | |
400 | val = value_of_internalvar (lookup_internalvar (varname)); | |
df407dfe | 401 | if (TYPE_CODE (value_type (val)) == TYPE_CODE_INT) |
5c44784c JM |
402 | retval = (int) value_as_long (val); |
403 | else | |
404 | { | |
a3f17187 | 405 | printf_filtered (_("Convenience variable must have integer value.\n")); |
5c44784c JM |
406 | retval = 0; |
407 | } | |
c906108c SS |
408 | } |
409 | else | |
410 | { | |
411 | if (*p == '-') | |
412 | ++p; | |
413 | while (*p >= '0' && *p <= '9') | |
414 | ++p; | |
415 | if (p == *pp) | |
416 | /* There is no number here. (e.g. "cond a == b"). */ | |
5c44784c JM |
417 | { |
418 | /* Skip non-numeric token */ | |
419 | while (*p && !isspace((int) *p)) | |
420 | ++p; | |
421 | /* Return zero, which caller must interpret as error. */ | |
422 | retval = 0; | |
423 | } | |
424 | else | |
425 | retval = atoi (*pp); | |
426 | } | |
427 | if (!(isspace (*p) || *p == '\0' || *p == trailer)) | |
428 | { | |
429 | /* Trailing junk: return 0 and let caller print error msg. */ | |
430 | while (!(isspace (*p) || *p == '\0' || *p == trailer)) | |
431 | ++p; | |
432 | retval = 0; | |
c906108c | 433 | } |
c906108c SS |
434 | while (isspace (*p)) |
435 | p++; | |
436 | *pp = p; | |
437 | return retval; | |
438 | } | |
5c44784c | 439 | |
11cf8741 | 440 | |
5c44784c JM |
441 | /* Like get_number_trailer, but don't allow a trailer. */ |
442 | int | |
fba45db2 | 443 | get_number (char **pp) |
5c44784c JM |
444 | { |
445 | return get_number_trailer (pp, '\0'); | |
446 | } | |
447 | ||
448 | /* Parse a number or a range. | |
449 | * A number will be of the form handled by get_number. | |
450 | * A range will be of the form <number1> - <number2>, and | |
451 | * will represent all the integers between number1 and number2, | |
452 | * inclusive. | |
453 | * | |
454 | * While processing a range, this fuction is called iteratively; | |
455 | * At each call it will return the next value in the range. | |
456 | * | |
457 | * At the beginning of parsing a range, the char pointer PP will | |
458 | * be advanced past <number1> and left pointing at the '-' token. | |
459 | * Subsequent calls will not advance the pointer until the range | |
460 | * is completed. The call that completes the range will advance | |
461 | * pointer PP past <number2>. | |
462 | */ | |
463 | ||
464 | int | |
fba45db2 | 465 | get_number_or_range (char **pp) |
5c44784c JM |
466 | { |
467 | static int last_retval, end_value; | |
468 | static char *end_ptr; | |
469 | static int in_range = 0; | |
470 | ||
471 | if (**pp != '-') | |
472 | { | |
473 | /* Default case: pp is pointing either to a solo number, | |
474 | or to the first number of a range. */ | |
475 | last_retval = get_number_trailer (pp, '-'); | |
476 | if (**pp == '-') | |
477 | { | |
478 | char **temp; | |
479 | ||
480 | /* This is the start of a range (<number1> - <number2>). | |
481 | Skip the '-', parse and remember the second number, | |
482 | and also remember the end of the final token. */ | |
483 | ||
484 | temp = &end_ptr; | |
485 | end_ptr = *pp + 1; | |
486 | while (isspace ((int) *end_ptr)) | |
487 | end_ptr++; /* skip white space */ | |
488 | end_value = get_number (temp); | |
489 | if (end_value < last_retval) | |
490 | { | |
8a3fe4f8 | 491 | error (_("inverted range")); |
5c44784c JM |
492 | } |
493 | else if (end_value == last_retval) | |
494 | { | |
495 | /* degenerate range (number1 == number2). Advance the | |
496 | token pointer so that the range will be treated as a | |
497 | single number. */ | |
498 | *pp = end_ptr; | |
499 | } | |
500 | else | |
501 | in_range = 1; | |
502 | } | |
503 | } | |
504 | else if (! in_range) | |
8a3fe4f8 | 505 | error (_("negative value")); |
5c44784c JM |
506 | else |
507 | { | |
508 | /* pp points to the '-' that betokens a range. All | |
509 | number-parsing has already been done. Return the next | |
510 | integer value (one greater than the saved previous value). | |
511 | Do not advance the token pointer 'pp' until the end of range | |
512 | is reached. */ | |
513 | ||
514 | if (++last_retval == end_value) | |
515 | { | |
516 | /* End of range reached; advance token pointer. */ | |
517 | *pp = end_ptr; | |
518 | in_range = 0; | |
519 | } | |
520 | } | |
521 | return last_retval; | |
522 | } | |
523 | ||
524 | ||
c906108c SS |
525 | \f |
526 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ | |
527 | ||
528 | static void | |
fba45db2 | 529 | condition_command (char *arg, int from_tty) |
c906108c | 530 | { |
52f0bd74 | 531 | struct breakpoint *b; |
c906108c | 532 | char *p; |
52f0bd74 | 533 | int bnum; |
c906108c SS |
534 | |
535 | if (arg == 0) | |
e2e0b3e5 | 536 | error_no_arg (_("breakpoint number")); |
c906108c SS |
537 | |
538 | p = arg; | |
539 | bnum = get_number (&p); | |
5c44784c | 540 | if (bnum == 0) |
8a3fe4f8 | 541 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
542 | |
543 | ALL_BREAKPOINTS (b) | |
544 | if (b->number == bnum) | |
2f069f6f JB |
545 | { |
546 | struct bp_location *loc = b->loc; | |
547 | for (; loc; loc = loc->next) | |
548 | { | |
549 | if (loc->cond) | |
550 | { | |
551 | xfree (loc->cond); | |
552 | loc->cond = 0; | |
553 | } | |
554 | } | |
555 | if (b->cond_string != NULL) | |
556 | xfree (b->cond_string); | |
c906108c | 557 | |
2f069f6f JB |
558 | if (*p == 0) |
559 | { | |
560 | b->cond_string = NULL; | |
561 | if (from_tty) | |
562 | printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum); | |
563 | } | |
564 | else | |
565 | { | |
566 | arg = p; | |
567 | /* I don't know if it matters whether this is the string the user | |
568 | typed in or the decompiled expression. */ | |
569 | b->cond_string = savestring (arg, strlen (arg)); | |
570 | b->condition_not_parsed = 0; | |
571 | for (loc = b->loc; loc; loc = loc->next) | |
572 | { | |
573 | arg = p; | |
574 | loc->cond = | |
575 | parse_exp_1 (&arg, block_for_pc (loc->address), 0); | |
576 | if (*arg) | |
577 | error (_("Junk at end of expression")); | |
578 | } | |
579 | } | |
580 | breakpoints_changed (); | |
383f836e | 581 | observer_notify_breakpoint_modified (b->number); |
2f069f6f JB |
582 | return; |
583 | } | |
c906108c | 584 | |
8a3fe4f8 | 585 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
586 | } |
587 | ||
c906108c | 588 | static void |
fba45db2 | 589 | commands_command (char *arg, int from_tty) |
c906108c | 590 | { |
52f0bd74 | 591 | struct breakpoint *b; |
c906108c | 592 | char *p; |
52f0bd74 | 593 | int bnum; |
c906108c SS |
594 | struct command_line *l; |
595 | ||
596 | /* If we allowed this, we would have problems with when to | |
597 | free the storage, if we change the commands currently | |
598 | being read from. */ | |
599 | ||
600 | if (executing_breakpoint_commands) | |
8a3fe4f8 | 601 | error (_("Can't use the \"commands\" command among a breakpoint's commands.")); |
c906108c SS |
602 | |
603 | p = arg; | |
604 | bnum = get_number (&p); | |
5c44784c | 605 | |
c906108c | 606 | if (p && *p) |
8a3fe4f8 | 607 | error (_("Unexpected extra arguments following breakpoint number.")); |
c5aa993b | 608 | |
c906108c SS |
609 | ALL_BREAKPOINTS (b) |
610 | if (b->number == bnum) | |
9ebf4acf AC |
611 | { |
612 | char *tmpbuf = xstrprintf ("Type commands for when breakpoint %d is hit, one per line.", | |
613 | bnum); | |
614 | struct cleanup *cleanups = make_cleanup (xfree, tmpbuf); | |
311a4e6b | 615 | l = read_command_lines (tmpbuf, from_tty, 1); |
9ebf4acf AC |
616 | do_cleanups (cleanups); |
617 | free_command_lines (&b->commands); | |
618 | b->commands = l; | |
619 | breakpoints_changed (); | |
383f836e | 620 | observer_notify_breakpoint_modified (b->number); |
9ebf4acf | 621 | return; |
c5aa993b | 622 | } |
8a3fe4f8 | 623 | error (_("No breakpoint number %d."), bnum); |
c906108c | 624 | } |
40c03ae8 EZ |
625 | |
626 | /* Like commands_command, but instead of reading the commands from | |
627 | input stream, takes them from an already parsed command structure. | |
628 | ||
629 | This is used by cli-script.c to DTRT with breakpoint commands | |
630 | that are part of if and while bodies. */ | |
631 | enum command_control_type | |
632 | commands_from_control_command (char *arg, struct command_line *cmd) | |
633 | { | |
634 | struct breakpoint *b; | |
635 | char *p; | |
636 | int bnum; | |
637 | ||
638 | /* If we allowed this, we would have problems with when to | |
639 | free the storage, if we change the commands currently | |
640 | being read from. */ | |
641 | ||
642 | if (executing_breakpoint_commands) | |
643 | error (_("Can't use the \"commands\" command among a breakpoint's commands.")); | |
644 | ||
645 | /* An empty string for the breakpoint number means the last | |
646 | breakpoint, but get_number expects a NULL pointer. */ | |
647 | if (arg && !*arg) | |
648 | p = NULL; | |
649 | else | |
650 | p = arg; | |
651 | bnum = get_number (&p); | |
652 | ||
653 | if (p && *p) | |
654 | error (_("Unexpected extra arguments following breakpoint number.")); | |
655 | ||
656 | ALL_BREAKPOINTS (b) | |
657 | if (b->number == bnum) | |
658 | { | |
659 | free_command_lines (&b->commands); | |
660 | if (cmd->body_count != 1) | |
661 | error (_("Invalid \"commands\" block structure.")); | |
662 | /* We need to copy the commands because if/while will free the | |
663 | list after it finishes execution. */ | |
664 | b->commands = copy_command_lines (cmd->body_list[0]); | |
665 | breakpoints_changed (); | |
383f836e | 666 | observer_notify_breakpoint_modified (b->number); |
40c03ae8 | 667 | return simple_control; |
2f069f6f | 668 | } |
40c03ae8 EZ |
669 | error (_("No breakpoint number %d."), bnum); |
670 | } | |
c906108c | 671 | \f |
8defab1a DJ |
672 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
673 | by replacing any memory breakpoints with their shadowed contents. */ | |
c906108c | 674 | |
8defab1a DJ |
675 | void |
676 | breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len) | |
c906108c | 677 | { |
8defab1a | 678 | struct bp_location *b; |
c906108c SS |
679 | CORE_ADDR bp_addr = 0; |
680 | int bp_size = 0; | |
8defab1a | 681 | int bptoffset = 0; |
c5aa993b | 682 | |
ffce0d52 | 683 | ALL_BP_LOCATIONS (b) |
c5aa993b | 684 | { |
ffce0d52 | 685 | if (b->owner->type == bp_none) |
8a3fe4f8 | 686 | warning (_("reading through apparently deleted breakpoint #%d?"), |
ffce0d52 DJ |
687 | b->owner->number); |
688 | ||
689 | if (b->loc_type != bp_loc_software_breakpoint) | |
c5aa993b | 690 | continue; |
ffce0d52 | 691 | if (!b->inserted) |
c5aa993b JM |
692 | continue; |
693 | /* Addresses and length of the part of the breakpoint that | |
694 | we need to copy. */ | |
8181d85f DJ |
695 | bp_addr = b->target_info.placed_address; |
696 | bp_size = b->target_info.shadow_len; | |
c5aa993b | 697 | if (bp_size == 0) |
8181d85f | 698 | /* bp isn't valid, or doesn't shadow memory. */ |
c5aa993b | 699 | continue; |
8defab1a | 700 | |
c5aa993b JM |
701 | if (bp_addr + bp_size <= memaddr) |
702 | /* The breakpoint is entirely before the chunk of memory we | |
703 | are reading. */ | |
704 | continue; | |
8defab1a | 705 | |
c5aa993b JM |
706 | if (bp_addr >= memaddr + len) |
707 | /* The breakpoint is entirely after the chunk of memory we are | |
708 | reading. */ | |
709 | continue; | |
c5aa993b | 710 | |
8defab1a DJ |
711 | /* Offset within shadow_contents. */ |
712 | if (bp_addr < memaddr) | |
713 | { | |
714 | /* Only copy the second part of the breakpoint. */ | |
715 | bp_size -= memaddr - bp_addr; | |
716 | bptoffset = memaddr - bp_addr; | |
717 | bp_addr = memaddr; | |
718 | } | |
c5aa993b | 719 | |
8defab1a DJ |
720 | if (bp_addr + bp_size > memaddr + len) |
721 | { | |
722 | /* Only copy the first part of the breakpoint. */ | |
723 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
724 | } | |
c5aa993b | 725 | |
8defab1a DJ |
726 | memcpy (buf + bp_addr - memaddr, |
727 | b->target_info.shadow_contents + bptoffset, bp_size); | |
c5aa993b | 728 | } |
c906108c | 729 | } |
c906108c | 730 | \f |
c5aa993b | 731 | |
687595f9 | 732 | /* A wrapper function for inserting catchpoints. */ |
9cbc821d | 733 | static void |
687595f9 DJ |
734 | insert_catchpoint (struct ui_out *uo, void *args) |
735 | { | |
736 | struct breakpoint *b = (struct breakpoint *) args; | |
737 | int val = -1; | |
738 | ||
fe798b75 JB |
739 | gdb_assert (b->type == bp_catchpoint); |
740 | gdb_assert (b->ops != NULL && b->ops->insert != NULL); | |
741 | ||
742 | b->ops->insert (b); | |
687595f9 DJ |
743 | } |
744 | ||
a5606eee VP |
745 | static int |
746 | is_hardware_watchpoint (struct breakpoint *bpt) | |
747 | { | |
748 | return (bpt->type == bp_hardware_watchpoint | |
749 | || bpt->type == bp_read_watchpoint | |
750 | || bpt->type == bp_access_watchpoint); | |
751 | } | |
7270d8f2 | 752 | |
fa4727a6 DJ |
753 | /* Find the current value of a watchpoint on EXP. Return the value in |
754 | *VALP and *RESULTP and the chain of intermediate and final values | |
755 | in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does | |
756 | not need them. | |
757 | ||
ccc57cf9 | 758 | If a memory error occurs while evaluating the expression, *RESULTP will |
fa4727a6 DJ |
759 | be set to NULL. *RESULTP may be a lazy value, if the result could |
760 | not be read from memory. It is used to determine whether a value | |
761 | is user-specified (we should watch the whole value) or intermediate | |
762 | (we should watch only the bit used to locate the final value). | |
763 | ||
764 | If the final value, or any intermediate value, could not be read | |
765 | from memory, *VALP will be set to NULL. *VAL_CHAIN will still be | |
766 | set to any referenced values. *VALP will never be a lazy value. | |
767 | This is the value which we store in struct breakpoint. | |
768 | ||
769 | If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the | |
770 | value chain. The caller must free the values individually. If | |
771 | VAL_CHAIN is NULL, all generated values will be left on the value | |
772 | chain. */ | |
773 | ||
774 | static void | |
775 | fetch_watchpoint_value (struct expression *exp, struct value **valp, | |
776 | struct value **resultp, struct value **val_chain) | |
777 | { | |
778 | struct value *mark, *new_mark, *result; | |
ccc57cf9 | 779 | volatile struct gdb_exception ex; |
fa4727a6 DJ |
780 | |
781 | *valp = NULL; | |
782 | if (resultp) | |
783 | *resultp = NULL; | |
784 | if (val_chain) | |
785 | *val_chain = NULL; | |
786 | ||
787 | /* Evaluate the expression. */ | |
788 | mark = value_mark (); | |
789 | result = NULL; | |
ccc57cf9 PA |
790 | |
791 | TRY_CATCH (ex, RETURN_MASK_ALL) | |
792 | { | |
793 | result = evaluate_expression (exp); | |
794 | } | |
795 | if (ex.reason < 0) | |
796 | { | |
797 | /* Ignore memory errors, we want watchpoints pointing at | |
798 | inaccessible memory to still be created; otherwise, throw the | |
799 | error to some higher catcher. */ | |
800 | switch (ex.error) | |
801 | { | |
802 | case MEMORY_ERROR: | |
803 | break; | |
804 | default: | |
805 | throw_exception (ex); | |
806 | break; | |
807 | } | |
808 | } | |
809 | ||
fa4727a6 DJ |
810 | new_mark = value_mark (); |
811 | if (mark == new_mark) | |
812 | return; | |
813 | if (resultp) | |
814 | *resultp = result; | |
815 | ||
816 | /* Make sure it's not lazy, so that after the target stops again we | |
817 | have a non-lazy previous value to compare with. */ | |
818 | if (result != NULL | |
819 | && (!value_lazy (result) || gdb_value_fetch_lazy (result))) | |
820 | *valp = result; | |
821 | ||
822 | if (val_chain) | |
823 | { | |
824 | /* Return the chain of intermediate values. We use this to | |
825 | decide which addresses to watch. */ | |
826 | *val_chain = new_mark; | |
827 | value_release_to_mark (mark); | |
828 | } | |
829 | } | |
830 | ||
567e1b4e JB |
831 | /* Assuming that B is a watchpoint: |
832 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 833 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
834 | - Evaluate the condition if there is one, and store the result |
835 | in b->loc->cond. | |
a5606eee VP |
836 | - Update the list of values that must be watched in B->loc. |
837 | ||
838 | If the watchpoint is disabled, do nothing. If this is | |
839 | local watchpoint that is out of scope, delete it. */ | |
b40ce68a | 840 | static void |
a5606eee | 841 | update_watchpoint (struct breakpoint *b, int reparse) |
7270d8f2 | 842 | { |
a5606eee | 843 | int within_current_scope; |
a5606eee VP |
844 | struct frame_id saved_frame_id; |
845 | struct bp_location *loc; | |
846 | bpstat bs; | |
847 | ||
567e1b4e JB |
848 | /* We don't free locations. They are stored in bp_location_chain and |
849 | update_global_locations will eventually delete them and remove | |
850 | breakpoints if needed. */ | |
a5606eee VP |
851 | b->loc = NULL; |
852 | ||
853 | if (b->disposition == disp_del_at_next_stop) | |
854 | return; | |
855 | ||
856 | /* Save the current frame's ID so we can restore it after | |
857 | evaluating the watchpoint expression on its own frame. */ | |
858 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
859 | took a frame parameter, so that we didn't have to change the | |
860 | selected frame. */ | |
861 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
862 | ||
863 | /* Determine if the watchpoint is within scope. */ | |
864 | if (b->exp_valid_block == NULL) | |
865 | within_current_scope = 1; | |
866 | else | |
867 | { | |
868 | struct frame_info *fi; | |
869 | fi = frame_find_by_id (b->watchpoint_frame); | |
870 | within_current_scope = (fi != NULL); | |
871 | if (within_current_scope) | |
872 | select_frame (fi); | |
873 | } | |
874 | ||
875 | if (within_current_scope && reparse) | |
876 | { | |
877 | char *s; | |
878 | if (b->exp) | |
879 | { | |
880 | xfree (b->exp); | |
881 | b->exp = NULL; | |
882 | } | |
883 | s = b->exp_string; | |
884 | b->exp = parse_exp_1 (&s, b->exp_valid_block, 0); | |
885 | /* If the meaning of expression itself changed, the old value is | |
886 | no longer relevant. We don't want to report a watchpoint hit | |
887 | to the user when the old value and the new value may actually | |
888 | be completely different objects. */ | |
889 | value_free (b->val); | |
fa4727a6 DJ |
890 | b->val = NULL; |
891 | b->val_valid = 0; | |
a5606eee | 892 | } |
a5606eee VP |
893 | |
894 | /* If we failed to parse the expression, for example because | |
895 | it refers to a global variable in a not-yet-loaded shared library, | |
896 | don't try to insert watchpoint. We don't automatically delete | |
897 | such watchpoint, though, since failure to parse expression | |
898 | is different from out-of-scope watchpoint. */ | |
899 | if (within_current_scope && b->exp) | |
900 | { | |
fa4727a6 | 901 | struct value *val_chain, *v, *result, *next; |
a5606eee | 902 | |
fa4727a6 | 903 | fetch_watchpoint_value (b->exp, &v, &result, &val_chain); |
a5606eee | 904 | |
a5606eee VP |
905 | /* Avoid setting b->val if it's already set. The meaning of |
906 | b->val is 'the last value' user saw, and we should update | |
907 | it only if we reported that last value to user. As it | |
908 | happens, the code that reports it updates b->val directly. */ | |
fa4727a6 DJ |
909 | if (!b->val_valid) |
910 | { | |
911 | b->val = v; | |
912 | b->val_valid = 1; | |
913 | } | |
a5606eee | 914 | |
db2ad4c3 JK |
915 | /* Change the type of breakpoint between hardware assisted or an |
916 | ordinary watchpoint depending on the hardware support and free | |
917 | hardware slots. REPARSE is set when the inferior is started. */ | |
918 | if ((b->type == bp_watchpoint || b->type == bp_hardware_watchpoint) | |
919 | && reparse) | |
920 | { | |
ca2d49e8 | 921 | int i, mem_cnt, other_type_used; |
db2ad4c3 JK |
922 | |
923 | i = hw_watchpoint_used_count (bp_hardware_watchpoint, | |
924 | &other_type_used); | |
925 | mem_cnt = can_use_hardware_watchpoint (val_chain); | |
926 | ||
ca2d49e8 | 927 | if (!mem_cnt) |
db2ad4c3 JK |
928 | b->type = bp_watchpoint; |
929 | else | |
ca2d49e8 SL |
930 | { |
931 | int target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT | |
932 | (bp_hardware_watchpoint, i + mem_cnt, other_type_used); | |
933 | if (target_resources_ok <= 0) | |
934 | b->type = bp_watchpoint; | |
935 | else | |
936 | b->type = bp_hardware_watchpoint; | |
937 | } | |
db2ad4c3 JK |
938 | } |
939 | ||
a5606eee | 940 | /* Look at each value on the value chain. */ |
fa4727a6 | 941 | for (v = val_chain; v; v = next) |
a5606eee VP |
942 | { |
943 | /* If it's a memory location, and GDB actually needed | |
944 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
945 | must watch it. If the first value returned is |
946 | still lazy, that means an error occurred reading it; | |
947 | watch it anyway in case it becomes readable. */ | |
a5606eee | 948 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 949 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
950 | { |
951 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 952 | |
a5606eee VP |
953 | /* We only watch structs and arrays if user asked |
954 | for it explicitly, never if they just happen to | |
955 | appear in the middle of some value chain. */ | |
fa4727a6 | 956 | if (v == result |
a5606eee VP |
957 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
958 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
959 | { | |
960 | CORE_ADDR addr; | |
961 | int len, type; | |
962 | struct bp_location *loc, **tmp; | |
963 | ||
964 | addr = VALUE_ADDRESS (v) + value_offset (v); | |
965 | len = TYPE_LENGTH (value_type (v)); | |
966 | type = hw_write; | |
967 | if (b->type == bp_read_watchpoint) | |
968 | type = hw_read; | |
969 | else if (b->type == bp_access_watchpoint) | |
970 | type = hw_access; | |
971 | ||
39d61571 | 972 | loc = allocate_bp_location (b); |
a5606eee VP |
973 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
974 | ; | |
975 | *tmp = loc; | |
976 | loc->address = addr; | |
977 | loc->length = len; | |
978 | loc->watchpoint_type = type; | |
979 | } | |
980 | } | |
981 | ||
982 | next = value_next (v); | |
983 | if (v != b->val) | |
984 | value_free (v); | |
985 | } | |
986 | ||
2ec93238 MK |
987 | /* We just regenerated the list of breakpoint locations. |
988 | The new location does not have its condition field set to anything | |
989 | and therefore, we must always reparse the cond_string, independently | |
990 | of the value of the reparse flag. */ | |
991 | if (b->cond_string != NULL) | |
a5606eee VP |
992 | { |
993 | char *s = b->cond_string; | |
a5606eee VP |
994 | b->loc->cond = parse_exp_1 (&s, b->exp_valid_block, 0); |
995 | } | |
996 | } | |
997 | else if (!within_current_scope) | |
7270d8f2 | 998 | { |
a5606eee | 999 | printf_filtered (_("\ |
567e1b4e | 1000 | Watchpoint %d deleted because the program has left the block \n\ |
a5606eee VP |
1001 | in which its expression is valid.\n"), |
1002 | b->number); | |
1003 | if (b->related_breakpoint) | |
1004 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1005 | b->disposition = disp_del_at_next_stop; | |
7270d8f2 | 1006 | } |
a5606eee VP |
1007 | |
1008 | /* Restore the selected frame. */ | |
1009 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
1010 | } |
1011 | ||
a5606eee | 1012 | |
74960c60 VP |
1013 | /* Returns 1 iff breakpoint location should be |
1014 | inserted in the inferior. */ | |
1015 | static int | |
1016 | should_be_inserted (struct bp_location *bpt) | |
1017 | { | |
1018 | if (!breakpoint_enabled (bpt->owner)) | |
1019 | return 0; | |
1020 | ||
1021 | if (bpt->owner->disposition == disp_del_at_next_stop) | |
1022 | return 0; | |
1023 | ||
1024 | if (!bpt->enabled || bpt->shlib_disabled || bpt->duplicate) | |
1025 | return 0; | |
1026 | ||
1027 | return 1; | |
1028 | } | |
1029 | ||
879bfdc2 DJ |
1030 | /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint. |
1031 | Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS, | |
1032 | PROCESS_WARNING, and HW_BREAKPOINT_ERROR are used to report problems. | |
1033 | ||
1034 | NOTE drow/2003-09-09: This routine could be broken down to an object-style | |
1035 | method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 1036 | static int |
879bfdc2 | 1037 | insert_bp_location (struct bp_location *bpt, |
26bb91f3 DJ |
1038 | struct ui_file *tmp_error_stream, |
1039 | int *disabled_breaks, int *process_warning, | |
1040 | int *hw_breakpoint_error) | |
879bfdc2 DJ |
1041 | { |
1042 | int val = 0; | |
1043 | ||
74960c60 | 1044 | if (!should_be_inserted (bpt) || bpt->inserted) |
879bfdc2 DJ |
1045 | return 0; |
1046 | ||
8181d85f DJ |
1047 | /* Initialize the target-specific information. */ |
1048 | memset (&bpt->target_info, 0, sizeof (bpt->target_info)); | |
1049 | bpt->target_info.placed_address = bpt->address; | |
1050 | ||
879bfdc2 DJ |
1051 | if (bpt->loc_type == bp_loc_software_breakpoint |
1052 | || bpt->loc_type == bp_loc_hardware_breakpoint) | |
1053 | { | |
765dc015 VP |
1054 | if (bpt->owner->type != bp_hardware_breakpoint) |
1055 | { | |
1056 | /* If the explicitly specified breakpoint type | |
1057 | is not hardware breakpoint, check the memory map to see | |
1058 | if the breakpoint address is in read only memory or not. | |
1059 | Two important cases are: | |
1060 | - location type is not hardware breakpoint, memory | |
1061 | is readonly. We change the type of the location to | |
1062 | hardware breakpoint. | |
1063 | - location type is hardware breakpoint, memory is read-write. | |
1064 | This means we've previously made the location hardware one, but | |
1065 | then the memory map changed, so we undo. | |
1066 | ||
1067 | When breakpoints are removed, remove_breakpoints will | |
1068 | use location types we've just set here, the only possible | |
1069 | problem is that memory map has changed during running program, | |
1070 | but it's not going to work anyway with current gdb. */ | |
1071 | struct mem_region *mr | |
1072 | = lookup_mem_region (bpt->target_info.placed_address); | |
1073 | ||
1074 | if (mr) | |
1075 | { | |
1076 | if (automatic_hardware_breakpoints) | |
1077 | { | |
1078 | int changed = 0; | |
1079 | enum bp_loc_type new_type; | |
1080 | ||
1081 | if (mr->attrib.mode != MEM_RW) | |
1082 | new_type = bp_loc_hardware_breakpoint; | |
1083 | else | |
1084 | new_type = bp_loc_software_breakpoint; | |
1085 | ||
1086 | if (new_type != bpt->loc_type) | |
1087 | { | |
1088 | static int said = 0; | |
1089 | bpt->loc_type = new_type; | |
1090 | if (!said) | |
1091 | { | |
1092 | fprintf_filtered (gdb_stdout, _("\ | |
0767c96d | 1093 | Note: automatically using hardware breakpoints for read-only addresses.\n")); |
765dc015 VP |
1094 | said = 1; |
1095 | } | |
1096 | } | |
1097 | } | |
1098 | else if (bpt->loc_type == bp_loc_software_breakpoint | |
1099 | && mr->attrib.mode != MEM_RW) | |
1100 | warning (_("cannot set software breakpoint at readonly address %s"), | |
1101 | paddr (bpt->address)); | |
1102 | } | |
1103 | } | |
1104 | ||
879bfdc2 DJ |
1105 | /* First check to see if we have to handle an overlay. */ |
1106 | if (overlay_debugging == ovly_off | |
1107 | || bpt->section == NULL | |
1108 | || !(section_is_overlay (bpt->section))) | |
1109 | { | |
1110 | /* No overlay handling: just set the breakpoint. */ | |
1111 | ||
1112 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
8181d85f | 1113 | val = target_insert_hw_breakpoint (&bpt->target_info); |
879bfdc2 | 1114 | else |
8181d85f | 1115 | val = target_insert_breakpoint (&bpt->target_info); |
879bfdc2 DJ |
1116 | } |
1117 | else | |
1118 | { | |
1119 | /* This breakpoint is in an overlay section. | |
1120 | Shall we set a breakpoint at the LMA? */ | |
1121 | if (!overlay_events_enabled) | |
1122 | { | |
1123 | /* Yes -- overlay event support is not active, | |
1124 | so we must try to set a breakpoint at the LMA. | |
1125 | This will not work for a hardware breakpoint. */ | |
1126 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
8a3fe4f8 | 1127 | warning (_("hardware breakpoint %d not supported in overlay!"), |
879bfdc2 DJ |
1128 | bpt->owner->number); |
1129 | else | |
1130 | { | |
1131 | CORE_ADDR addr = overlay_unmapped_address (bpt->address, | |
1132 | bpt->section); | |
1133 | /* Set a software (trap) breakpoint at the LMA. */ | |
8181d85f DJ |
1134 | bpt->overlay_target_info = bpt->target_info; |
1135 | bpt->overlay_target_info.placed_address = addr; | |
1136 | val = target_insert_breakpoint (&bpt->overlay_target_info); | |
879bfdc2 DJ |
1137 | if (val != 0) |
1138 | fprintf_unfiltered (tmp_error_stream, | |
1139 | "Overlay breakpoint %d failed: in ROM?", | |
1140 | bpt->owner->number); | |
1141 | } | |
1142 | } | |
1143 | /* Shall we set a breakpoint at the VMA? */ | |
1144 | if (section_is_mapped (bpt->section)) | |
1145 | { | |
1146 | /* Yes. This overlay section is mapped into memory. */ | |
1147 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
8181d85f | 1148 | val = target_insert_hw_breakpoint (&bpt->target_info); |
879bfdc2 | 1149 | else |
8181d85f | 1150 | val = target_insert_breakpoint (&bpt->target_info); |
879bfdc2 DJ |
1151 | } |
1152 | else | |
1153 | { | |
1154 | /* No. This breakpoint will not be inserted. | |
1155 | No error, but do not mark the bp as 'inserted'. */ | |
1156 | return 0; | |
1157 | } | |
1158 | } | |
1159 | ||
1160 | if (val) | |
1161 | { | |
1162 | /* Can't set the breakpoint. */ | |
9bbf65bb | 1163 | if (solib_address (bpt->address)) |
879bfdc2 DJ |
1164 | { |
1165 | /* See also: disable_breakpoints_in_shlibs. */ | |
1166 | val = 0; | |
0d381245 | 1167 | bpt->shlib_disabled = 1; |
879bfdc2 DJ |
1168 | if (!*disabled_breaks) |
1169 | { | |
1170 | fprintf_unfiltered (tmp_error_stream, | |
1171 | "Cannot insert breakpoint %d.\n", | |
1172 | bpt->owner->number); | |
1173 | fprintf_unfiltered (tmp_error_stream, | |
1174 | "Temporarily disabling shared library breakpoints:\n"); | |
1175 | } | |
1176 | *disabled_breaks = 1; | |
1177 | fprintf_unfiltered (tmp_error_stream, | |
1178 | "breakpoint #%d\n", bpt->owner->number); | |
1179 | } | |
1180 | else | |
879bfdc2 DJ |
1181 | { |
1182 | #ifdef ONE_PROCESS_WRITETEXT | |
1183 | *process_warning = 1; | |
1184 | #endif | |
1185 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
1186 | { | |
1187 | *hw_breakpoint_error = 1; | |
1188 | fprintf_unfiltered (tmp_error_stream, | |
1189 | "Cannot insert hardware breakpoint %d.\n", | |
1190 | bpt->owner->number); | |
1191 | } | |
1192 | else | |
1193 | { | |
1194 | fprintf_unfiltered (tmp_error_stream, | |
1195 | "Cannot insert breakpoint %d.\n", | |
1196 | bpt->owner->number); | |
1197 | fprintf_filtered (tmp_error_stream, | |
1198 | "Error accessing memory address "); | |
ed49a04f | 1199 | fputs_filtered (paddress (bpt->address), tmp_error_stream); |
879bfdc2 DJ |
1200 | fprintf_filtered (tmp_error_stream, ": %s.\n", |
1201 | safe_strerror (val)); | |
1202 | } | |
1203 | ||
1204 | } | |
1205 | } | |
1206 | else | |
1207 | bpt->inserted = 1; | |
1208 | ||
1209 | return val; | |
1210 | } | |
1211 | ||
1212 | else if (bpt->loc_type == bp_loc_hardware_watchpoint | |
1213 | /* NOTE drow/2003-09-08: This state only exists for removing | |
1214 | watchpoints. It's not clear that it's necessary... */ | |
1215 | && bpt->owner->disposition != disp_del_at_next_stop) | |
1216 | { | |
a5606eee VP |
1217 | val = target_insert_watchpoint (bpt->address, |
1218 | bpt->length, | |
1219 | bpt->watchpoint_type); | |
1220 | bpt->inserted = (val != -1); | |
879bfdc2 DJ |
1221 | } |
1222 | ||
fe798b75 | 1223 | else if (bpt->owner->type == bp_catchpoint) |
879bfdc2 | 1224 | { |
71fff37b AC |
1225 | struct gdb_exception e = catch_exception (uiout, insert_catchpoint, |
1226 | bpt->owner, RETURN_MASK_ERROR); | |
9cbc821d AC |
1227 | exception_fprintf (gdb_stderr, e, "warning: inserting catchpoint %d: ", |
1228 | bpt->owner->number); | |
1229 | if (e.reason < 0) | |
879bfdc2 DJ |
1230 | bpt->owner->enable_state = bp_disabled; |
1231 | else | |
1232 | bpt->inserted = 1; | |
1640b821 DJ |
1233 | |
1234 | /* We've already printed an error message if there was a problem | |
1235 | inserting this catchpoint, and we've disabled the catchpoint, | |
1236 | so just return success. */ | |
1237 | return 0; | |
879bfdc2 DJ |
1238 | } |
1239 | ||
1240 | return 0; | |
1241 | } | |
1242 | ||
74960c60 VP |
1243 | /* Make sure all breakpoints are inserted in inferior. |
1244 | Throws exception on any error. | |
1245 | A breakpoint that is already inserted won't be inserted | |
1246 | again, so calling this function twice is safe. */ | |
1247 | void | |
1248 | insert_breakpoints (void) | |
1249 | { | |
1250 | struct breakpoint *bpt; | |
1251 | ||
1252 | ALL_BREAKPOINTS (bpt) | |
1253 | if (is_hardware_watchpoint (bpt)) | |
1254 | update_watchpoint (bpt, 0 /* don't reparse. */); | |
1255 | ||
b60e7edf | 1256 | update_global_location_list (1); |
74960c60 | 1257 | |
50c71eaf PA |
1258 | if (!breakpoints_always_inserted_mode () |
1259 | && (target_has_execution | |
1260 | || (gdbarch_has_global_solist (target_gdbarch) | |
1261 | && target_supports_multi_process ()))) | |
74960c60 VP |
1262 | /* update_global_location_list does not insert breakpoints |
1263 | when always_inserted_mode is not enabled. Explicitly | |
1264 | insert them now. */ | |
1265 | insert_breakpoint_locations (); | |
1266 | } | |
1267 | ||
c906108c SS |
1268 | /* insert_breakpoints is used when starting or continuing the program. |
1269 | remove_breakpoints is used when the program stops. | |
1270 | Both return zero if successful, | |
1271 | or an `errno' value if could not write the inferior. */ | |
1272 | ||
74960c60 VP |
1273 | static void |
1274 | insert_breakpoint_locations (void) | |
c906108c | 1275 | { |
a5606eee | 1276 | struct breakpoint *bpt; |
879bfdc2 | 1277 | struct bp_location *b, *temp; |
e236ba44 | 1278 | int error = 0; |
c906108c SS |
1279 | int val = 0; |
1280 | int disabled_breaks = 0; | |
81d0cc19 GS |
1281 | int hw_breakpoint_error = 0; |
1282 | int process_warning = 0; | |
c906108c | 1283 | |
81d0cc19 GS |
1284 | struct ui_file *tmp_error_stream = mem_fileopen (); |
1285 | make_cleanup_ui_file_delete (tmp_error_stream); | |
74960c60 | 1286 | |
81d0cc19 GS |
1287 | /* Explicitly mark the warning -- this will only be printed if |
1288 | there was an error. */ | |
1289 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
a5606eee | 1290 | |
879bfdc2 DJ |
1291 | ALL_BP_LOCATIONS_SAFE (b, temp) |
1292 | { | |
74960c60 | 1293 | if (!should_be_inserted (b) || b->inserted) |
879bfdc2 DJ |
1294 | continue; |
1295 | ||
f365de73 AS |
1296 | /* There is no point inserting thread-specific breakpoints if the |
1297 | thread no longer exists. */ | |
1298 | if (b->owner->thread != -1 | |
1299 | && !valid_thread_id (b->owner->thread)) | |
1300 | continue; | |
1301 | ||
879bfdc2 DJ |
1302 | val = insert_bp_location (b, tmp_error_stream, |
1303 | &disabled_breaks, &process_warning, | |
1304 | &hw_breakpoint_error); | |
1305 | if (val) | |
e236ba44 | 1306 | error = val; |
879bfdc2 | 1307 | } |
c906108c | 1308 | |
a5606eee VP |
1309 | /* If we failed to insert all locations of a watchpoint, |
1310 | remove them, as half-inserted watchpoint is of limited use. */ | |
1311 | ALL_BREAKPOINTS (bpt) | |
1312 | { | |
1313 | int some_failed = 0; | |
1314 | struct bp_location *loc; | |
1315 | ||
1316 | if (!is_hardware_watchpoint (bpt)) | |
1317 | continue; | |
1318 | ||
d6b74ac4 | 1319 | if (!breakpoint_enabled (bpt)) |
a5606eee | 1320 | continue; |
74960c60 VP |
1321 | |
1322 | if (bpt->disposition == disp_del_at_next_stop) | |
1323 | continue; | |
a5606eee VP |
1324 | |
1325 | for (loc = bpt->loc; loc; loc = loc->next) | |
1326 | if (!loc->inserted) | |
1327 | { | |
1328 | some_failed = 1; | |
1329 | break; | |
1330 | } | |
1331 | if (some_failed) | |
1332 | { | |
1333 | for (loc = bpt->loc; loc; loc = loc->next) | |
1334 | if (loc->inserted) | |
1335 | remove_breakpoint (loc, mark_uninserted); | |
1336 | ||
1337 | hw_breakpoint_error = 1; | |
1338 | fprintf_unfiltered (tmp_error_stream, | |
1339 | "Could not insert hardware watchpoint %d.\n", | |
1340 | bpt->number); | |
1341 | error = -1; | |
1342 | } | |
1343 | } | |
1344 | ||
e236ba44 | 1345 | if (error) |
81d0cc19 GS |
1346 | { |
1347 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
1348 | message about possibly exhausted resources. */ | |
879bfdc2 | 1349 | if (hw_breakpoint_error) |
81d0cc19 | 1350 | { |
c6510018 MS |
1351 | fprintf_unfiltered (tmp_error_stream, |
1352 | "Could not insert hardware breakpoints:\n\ | |
1353 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 1354 | } |
c6510018 | 1355 | #ifdef ONE_PROCESS_WRITETEXT |
81d0cc19 | 1356 | if (process_warning) |
c6510018 MS |
1357 | fprintf_unfiltered (tmp_error_stream, |
1358 | "The same program may be running in another process."); | |
1359 | #endif | |
81d0cc19 GS |
1360 | target_terminal_ours_for_output (); |
1361 | error_stream (tmp_error_stream); | |
1362 | } | |
c906108c SS |
1363 | } |
1364 | ||
c906108c | 1365 | int |
fba45db2 | 1366 | remove_breakpoints (void) |
c906108c | 1367 | { |
0bde7532 | 1368 | struct bp_location *b; |
c906108c SS |
1369 | int val; |
1370 | ||
0bde7532 | 1371 | ALL_BP_LOCATIONS (b) |
c5aa993b | 1372 | { |
0bde7532 | 1373 | if (b->inserted) |
c5aa993b JM |
1374 | { |
1375 | val = remove_breakpoint (b, mark_uninserted); | |
1376 | if (val != 0) | |
1377 | return val; | |
1378 | } | |
1379 | } | |
c906108c SS |
1380 | return 0; |
1381 | } | |
1382 | ||
692590c1 | 1383 | int |
80ce1ecb | 1384 | remove_hw_watchpoints (void) |
692590c1 | 1385 | { |
0bde7532 | 1386 | struct bp_location *b; |
692590c1 MS |
1387 | int val; |
1388 | ||
0bde7532 | 1389 | ALL_BP_LOCATIONS (b) |
692590c1 | 1390 | { |
0bde7532 | 1391 | if (b->inserted && b->loc_type == bp_loc_hardware_watchpoint) |
692590c1 MS |
1392 | { |
1393 | val = remove_breakpoint (b, mark_uninserted); | |
1394 | if (val != 0) | |
1395 | return val; | |
1396 | } | |
1397 | } | |
1398 | return 0; | |
1399 | } | |
1400 | ||
c906108c | 1401 | int |
fba45db2 | 1402 | reattach_breakpoints (int pid) |
c906108c | 1403 | { |
0bde7532 | 1404 | struct bp_location *b; |
c906108c | 1405 | int val; |
ce696e05 | 1406 | struct cleanup *old_chain = save_inferior_ptid (); |
a4954f26 DJ |
1407 | struct ui_file *tmp_error_stream = mem_fileopen (); |
1408 | int dummy1 = 0, dummy2 = 0, dummy3 = 0; | |
1409 | ||
1410 | make_cleanup_ui_file_delete (tmp_error_stream); | |
c906108c | 1411 | |
ce696e05 | 1412 | inferior_ptid = pid_to_ptid (pid); |
0bde7532 | 1413 | ALL_BP_LOCATIONS (b) |
c5aa993b | 1414 | { |
0bde7532 | 1415 | if (b->inserted) |
c5aa993b | 1416 | { |
a4954f26 DJ |
1417 | b->inserted = 0; |
1418 | val = insert_bp_location (b, tmp_error_stream, | |
1419 | &dummy1, &dummy2, &dummy3); | |
c5aa993b JM |
1420 | if (val != 0) |
1421 | { | |
ce696e05 | 1422 | do_cleanups (old_chain); |
c5aa993b JM |
1423 | return val; |
1424 | } | |
1425 | } | |
1426 | } | |
ce696e05 | 1427 | do_cleanups (old_chain); |
c906108c SS |
1428 | return 0; |
1429 | } | |
1430 | ||
1431 | void | |
fba45db2 | 1432 | update_breakpoints_after_exec (void) |
c906108c | 1433 | { |
c5aa993b JM |
1434 | struct breakpoint *b; |
1435 | struct breakpoint *temp; | |
25b22b0a | 1436 | struct bp_location *bploc; |
c906108c | 1437 | |
25b22b0a PA |
1438 | /* We're about to delete breakpoints from GDB's lists. If the |
1439 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
1440 | writing the breakpoints' "shadow contents" back into memory. The | |
1441 | "shadow contents" are NOT valid after an exec, so GDB should not | |
1442 | do that. Instead, the target is responsible from marking | |
1443 | breakpoints out as soon as it detects an exec. We don't do that | |
1444 | here instead, because there may be other attempts to delete | |
1445 | breakpoints after detecting an exec and before reaching here. */ | |
1446 | ALL_BP_LOCATIONS (bploc) | |
1447 | gdb_assert (!bploc->inserted); | |
c906108c SS |
1448 | |
1449 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b JM |
1450 | { |
1451 | /* Solib breakpoints must be explicitly reset after an exec(). */ | |
1452 | if (b->type == bp_shlib_event) | |
1453 | { | |
1454 | delete_breakpoint (b); | |
1455 | continue; | |
1456 | } | |
c906108c | 1457 | |
1900040c MS |
1458 | /* Thread event breakpoints must be set anew after an exec(), |
1459 | as must overlay event breakpoints. */ | |
1460 | if (b->type == bp_thread_event || b->type == bp_overlay_event) | |
c4093a6a JM |
1461 | { |
1462 | delete_breakpoint (b); | |
1463 | continue; | |
1464 | } | |
1465 | ||
c5aa993b JM |
1466 | /* Step-resume breakpoints are meaningless after an exec(). */ |
1467 | if (b->type == bp_step_resume) | |
1468 | { | |
1469 | delete_breakpoint (b); | |
1470 | continue; | |
1471 | } | |
1472 | ||
611c83ae PA |
1473 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
1474 | after an exec. */ | |
1475 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume) | |
1476 | { | |
1477 | delete_breakpoint (b); | |
1478 | continue; | |
1479 | } | |
1480 | ||
ce78b96d JB |
1481 | if (b->type == bp_catchpoint) |
1482 | { | |
1483 | /* For now, none of the bp_catchpoint breakpoints need to | |
1484 | do anything at this point. In the future, if some of | |
1485 | the catchpoints need to something, we will need to add | |
1486 | a new method, and call this method from here. */ | |
1487 | continue; | |
1488 | } | |
1489 | ||
c5aa993b JM |
1490 | /* bp_finish is a special case. The only way we ought to be able |
1491 | to see one of these when an exec() has happened, is if the user | |
1492 | caught a vfork, and then said "finish". Ordinarily a finish just | |
1493 | carries them to the call-site of the current callee, by setting | |
1494 | a temporary bp there and resuming. But in this case, the finish | |
1495 | will carry them entirely through the vfork & exec. | |
1496 | ||
1497 | We don't want to allow a bp_finish to remain inserted now. But | |
1498 | we can't safely delete it, 'cause finish_command has a handle to | |
1499 | the bp on a bpstat, and will later want to delete it. There's a | |
1500 | chance (and I've seen it happen) that if we delete the bp_finish | |
1501 | here, that its storage will get reused by the time finish_command | |
1502 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
1503 | We really must allow finish_command to delete a bp_finish. | |
1504 | ||
53a5351d JM |
1505 | In the absense of a general solution for the "how do we know |
1506 | it's safe to delete something others may have handles to?" | |
1507 | problem, what we'll do here is just uninsert the bp_finish, and | |
1508 | let finish_command delete it. | |
1509 | ||
1510 | (We know the bp_finish is "doomed" in the sense that it's | |
1511 | momentary, and will be deleted as soon as finish_command sees | |
1512 | the inferior stopped. So it doesn't matter that the bp's | |
1513 | address is probably bogus in the new a.out, unlike e.g., the | |
1514 | solib breakpoints.) */ | |
c5aa993b | 1515 | |
c5aa993b JM |
1516 | if (b->type == bp_finish) |
1517 | { | |
1518 | continue; | |
1519 | } | |
1520 | ||
1521 | /* Without a symbolic address, we have little hope of the | |
1522 | pre-exec() address meaning the same thing in the post-exec() | |
1523 | a.out. */ | |
1524 | if (b->addr_string == NULL) | |
1525 | { | |
1526 | delete_breakpoint (b); | |
1527 | continue; | |
1528 | } | |
c5aa993b | 1529 | } |
1900040c MS |
1530 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
1531 | create_overlay_event_breakpoint ("_ovly_debug_event"); | |
c906108c SS |
1532 | } |
1533 | ||
1534 | int | |
fba45db2 | 1535 | detach_breakpoints (int pid) |
c906108c | 1536 | { |
0bde7532 | 1537 | struct bp_location *b; |
c906108c | 1538 | int val; |
ce696e05 | 1539 | struct cleanup *old_chain = save_inferior_ptid (); |
c5aa993b | 1540 | |
39f77062 | 1541 | if (pid == PIDGET (inferior_ptid)) |
8a3fe4f8 | 1542 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 1543 | |
ce696e05 KB |
1544 | /* Set inferior_ptid; remove_breakpoint uses this global. */ |
1545 | inferior_ptid = pid_to_ptid (pid); | |
0bde7532 | 1546 | ALL_BP_LOCATIONS (b) |
c5aa993b | 1547 | { |
0bde7532 | 1548 | if (b->inserted) |
c5aa993b JM |
1549 | { |
1550 | val = remove_breakpoint (b, mark_inserted); | |
1551 | if (val != 0) | |
1552 | { | |
ce696e05 | 1553 | do_cleanups (old_chain); |
c5aa993b JM |
1554 | return val; |
1555 | } | |
1556 | } | |
1557 | } | |
ce696e05 | 1558 | do_cleanups (old_chain); |
c906108c SS |
1559 | return 0; |
1560 | } | |
1561 | ||
1562 | static int | |
0bde7532 | 1563 | remove_breakpoint (struct bp_location *b, insertion_state_t is) |
c906108c SS |
1564 | { |
1565 | int val; | |
c5aa993b | 1566 | |
0bde7532 | 1567 | if (b->owner->enable_state == bp_permanent) |
c2c6d25f JM |
1568 | /* Permanent breakpoints cannot be inserted or removed. */ |
1569 | return 0; | |
1570 | ||
74960c60 VP |
1571 | /* The type of none suggests that owner is actually deleted. |
1572 | This should not ever happen. */ | |
1573 | gdb_assert (b->owner->type != bp_none); | |
0bde7532 DJ |
1574 | |
1575 | if (b->loc_type == bp_loc_software_breakpoint | |
1576 | || b->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 1577 | { |
c02f5703 MS |
1578 | /* "Normal" instruction breakpoint: either the standard |
1579 | trap-instruction bp (bp_breakpoint), or a | |
1580 | bp_hardware_breakpoint. */ | |
1581 | ||
1582 | /* First check to see if we have to handle an overlay. */ | |
1583 | if (overlay_debugging == ovly_off | |
0bde7532 DJ |
1584 | || b->section == NULL |
1585 | || !(section_is_overlay (b->section))) | |
c02f5703 MS |
1586 | { |
1587 | /* No overlay handling: just remove the breakpoint. */ | |
1588 | ||
0bde7532 | 1589 | if (b->loc_type == bp_loc_hardware_breakpoint) |
8181d85f | 1590 | val = target_remove_hw_breakpoint (&b->target_info); |
c02f5703 | 1591 | else |
8181d85f | 1592 | val = target_remove_breakpoint (&b->target_info); |
c02f5703 | 1593 | } |
c906108c SS |
1594 | else |
1595 | { | |
c02f5703 MS |
1596 | /* This breakpoint is in an overlay section. |
1597 | Did we set a breakpoint at the LMA? */ | |
1598 | if (!overlay_events_enabled) | |
1599 | { | |
1600 | /* Yes -- overlay event support is not active, so we | |
1601 | should have set a breakpoint at the LMA. Remove it. | |
1602 | */ | |
c02f5703 MS |
1603 | /* Ignore any failures: if the LMA is in ROM, we will |
1604 | have already warned when we failed to insert it. */ | |
0bde7532 | 1605 | if (b->loc_type == bp_loc_hardware_breakpoint) |
8181d85f | 1606 | target_remove_hw_breakpoint (&b->overlay_target_info); |
c02f5703 | 1607 | else |
8181d85f | 1608 | target_remove_breakpoint (&b->overlay_target_info); |
c02f5703 MS |
1609 | } |
1610 | /* Did we set a breakpoint at the VMA? | |
1611 | If so, we will have marked the breakpoint 'inserted'. */ | |
0bde7532 | 1612 | if (b->inserted) |
c906108c | 1613 | { |
c02f5703 MS |
1614 | /* Yes -- remove it. Previously we did not bother to |
1615 | remove the breakpoint if the section had been | |
1616 | unmapped, but let's not rely on that being safe. We | |
1617 | don't know what the overlay manager might do. */ | |
0bde7532 | 1618 | if (b->loc_type == bp_loc_hardware_breakpoint) |
8181d85f | 1619 | val = target_remove_hw_breakpoint (&b->target_info); |
aa67235e UW |
1620 | |
1621 | /* However, we should remove *software* breakpoints only | |
1622 | if the section is still mapped, or else we overwrite | |
1623 | wrong code with the saved shadow contents. */ | |
1624 | else if (section_is_mapped (b->section)) | |
8181d85f | 1625 | val = target_remove_breakpoint (&b->target_info); |
aa67235e UW |
1626 | else |
1627 | val = 0; | |
c906108c | 1628 | } |
c02f5703 MS |
1629 | else |
1630 | { | |
1631 | /* No -- not inserted, so no need to remove. No error. */ | |
1632 | val = 0; | |
1633 | } | |
c906108c | 1634 | } |
879d1e6b UW |
1635 | |
1636 | /* In some cases, we might not be able to remove a breakpoint | |
1637 | in a shared library that has already been removed, but we | |
1638 | have not yet processed the shlib unload event. */ | |
1639 | if (val && solib_address (b->address)) | |
1640 | val = 0; | |
1641 | ||
c906108c SS |
1642 | if (val) |
1643 | return val; | |
0bde7532 | 1644 | b->inserted = (is == mark_inserted); |
c906108c | 1645 | } |
a5606eee | 1646 | else if (b->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 1647 | { |
278cd55f AC |
1648 | struct value *v; |
1649 | struct value *n; | |
c5aa993b | 1650 | |
0bde7532 | 1651 | b->inserted = (is == mark_inserted); |
a5606eee VP |
1652 | val = target_remove_watchpoint (b->address, b->length, |
1653 | b->watchpoint_type); | |
2e70b7b9 | 1654 | |
c906108c | 1655 | /* Failure to remove any of the hardware watchpoints comes here. */ |
0bde7532 | 1656 | if ((is == mark_uninserted) && (b->inserted)) |
8a3fe4f8 | 1657 | warning (_("Could not remove hardware watchpoint %d."), |
0bde7532 | 1658 | b->owner->number); |
c906108c | 1659 | } |
ce78b96d JB |
1660 | else if (b->owner->type == bp_catchpoint |
1661 | && breakpoint_enabled (b->owner) | |
1662 | && !b->duplicate) | |
1663 | { | |
1664 | gdb_assert (b->owner->ops != NULL && b->owner->ops->remove != NULL); | |
1665 | ||
1666 | val = b->owner->ops->remove (b->owner); | |
1667 | if (val) | |
1668 | return val; | |
1669 | b->inserted = (is == mark_inserted); | |
1670 | } | |
c906108c SS |
1671 | |
1672 | return 0; | |
1673 | } | |
1674 | ||
1675 | /* Clear the "inserted" flag in all breakpoints. */ | |
1676 | ||
25b22b0a | 1677 | void |
fba45db2 | 1678 | mark_breakpoints_out (void) |
c906108c | 1679 | { |
075f6582 | 1680 | struct bp_location *bpt; |
c906108c | 1681 | |
075f6582 DJ |
1682 | ALL_BP_LOCATIONS (bpt) |
1683 | bpt->inserted = 0; | |
c906108c SS |
1684 | } |
1685 | ||
53a5351d JM |
1686 | /* Clear the "inserted" flag in all breakpoints and delete any |
1687 | breakpoints which should go away between runs of the program. | |
c906108c SS |
1688 | |
1689 | Plus other such housekeeping that has to be done for breakpoints | |
1690 | between runs. | |
1691 | ||
53a5351d JM |
1692 | Note: this function gets called at the end of a run (by |
1693 | generic_mourn_inferior) and when a run begins (by | |
1694 | init_wait_for_inferior). */ | |
c906108c SS |
1695 | |
1696 | ||
1697 | ||
1698 | void | |
fba45db2 | 1699 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 1700 | { |
52f0bd74 | 1701 | struct breakpoint *b, *temp; |
075f6582 | 1702 | struct bp_location *bpt; |
1c5cfe86 | 1703 | int ix; |
c906108c | 1704 | |
50c71eaf PA |
1705 | /* If breakpoint locations are shared across processes, then there's |
1706 | nothing to do. */ | |
1707 | if (gdbarch_has_global_solist (target_gdbarch)) | |
1708 | return; | |
1709 | ||
075f6582 | 1710 | ALL_BP_LOCATIONS (bpt) |
514f746b AR |
1711 | if (bpt->owner->enable_state != bp_permanent) |
1712 | bpt->inserted = 0; | |
075f6582 | 1713 | |
c906108c | 1714 | ALL_BREAKPOINTS_SAFE (b, temp) |
c5aa993b | 1715 | { |
c5aa993b JM |
1716 | switch (b->type) |
1717 | { | |
1718 | case bp_call_dummy: | |
1719 | case bp_watchpoint_scope: | |
c906108c | 1720 | |
c5aa993b JM |
1721 | /* If the call dummy breakpoint is at the entry point it will |
1722 | cause problems when the inferior is rerun, so we better | |
1723 | get rid of it. | |
c906108c | 1724 | |
c5aa993b JM |
1725 | Also get rid of scope breakpoints. */ |
1726 | delete_breakpoint (b); | |
1727 | break; | |
c906108c | 1728 | |
c5aa993b JM |
1729 | case bp_watchpoint: |
1730 | case bp_hardware_watchpoint: | |
1731 | case bp_read_watchpoint: | |
1732 | case bp_access_watchpoint: | |
c906108c | 1733 | |
c5aa993b JM |
1734 | /* Likewise for watchpoints on local expressions. */ |
1735 | if (b->exp_valid_block != NULL) | |
1736 | delete_breakpoint (b); | |
967af18d | 1737 | else if (context == inf_starting) |
c860120c PM |
1738 | { |
1739 | /* Reset val field to force reread of starting value | |
1740 | in insert_breakpoints. */ | |
1741 | if (b->val) | |
1742 | value_free (b->val); | |
1743 | b->val = NULL; | |
fa4727a6 | 1744 | b->val_valid = 0; |
c860120c | 1745 | } |
c5aa993b JM |
1746 | break; |
1747 | default: | |
c5aa993b JM |
1748 | break; |
1749 | } | |
1750 | } | |
1c5cfe86 PA |
1751 | |
1752 | /* Get rid of the moribund locations. */ | |
1753 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bpt); ++ix) | |
1754 | free_bp_location (bpt); | |
1755 | VEC_free (bp_location_p, moribund_locations); | |
c906108c SS |
1756 | } |
1757 | ||
c2c6d25f JM |
1758 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
1759 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
1760 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
1761 | permanent breakpoint. | |
1762 | - When continuing from a location with an ordinary breakpoint, we | |
1763 | actually single step once before calling insert_breakpoints. | |
1764 | - When continuing from a localion with a permanent breakpoint, we | |
1765 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by | |
1766 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 1767 | |
c2c6d25f | 1768 | enum breakpoint_here |
fba45db2 | 1769 | breakpoint_here_p (CORE_ADDR pc) |
c906108c | 1770 | { |
89f9893c | 1771 | const struct bp_location *bpt; |
c2c6d25f | 1772 | int any_breakpoint_here = 0; |
c906108c | 1773 | |
075f6582 DJ |
1774 | ALL_BP_LOCATIONS (bpt) |
1775 | { | |
1776 | if (bpt->loc_type != bp_loc_software_breakpoint | |
1777 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
1778 | continue; | |
1779 | ||
468d015d | 1780 | if ((breakpoint_enabled (bpt->owner) |
075f6582 DJ |
1781 | || bpt->owner->enable_state == bp_permanent) |
1782 | && bpt->address == pc) /* bp is enabled and matches pc */ | |
1783 | { | |
1784 | if (overlay_debugging | |
1785 | && section_is_overlay (bpt->section) | |
1786 | && !section_is_mapped (bpt->section)) | |
1787 | continue; /* unmapped overlay -- can't be a match */ | |
1788 | else if (bpt->owner->enable_state == bp_permanent) | |
1789 | return permanent_breakpoint_here; | |
1790 | else | |
1791 | any_breakpoint_here = 1; | |
1792 | } | |
1793 | } | |
c906108c | 1794 | |
c2c6d25f | 1795 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
1796 | } |
1797 | ||
1c5cfe86 PA |
1798 | /* Return true if there's a moribund breakpoint at PC. */ |
1799 | ||
1800 | int | |
1801 | moribund_breakpoint_here_p (CORE_ADDR pc) | |
1802 | { | |
1803 | struct bp_location *loc; | |
1804 | int ix; | |
1805 | ||
1806 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
1807 | if (loc->address == pc) | |
1808 | return 1; | |
1809 | ||
1810 | return 0; | |
1811 | } | |
c2c6d25f | 1812 | |
c36b740a VP |
1813 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
1814 | inserted using regular breakpoint_chain/bp_location_chain mechanism. | |
1815 | This does not check for single-step breakpoints, which are | |
1816 | inserted and removed using direct target manipulation. */ | |
c906108c SS |
1817 | |
1818 | int | |
c36b740a | 1819 | regular_breakpoint_inserted_here_p (CORE_ADDR pc) |
c906108c | 1820 | { |
89f9893c | 1821 | const struct bp_location *bpt; |
c906108c | 1822 | |
075f6582 | 1823 | ALL_BP_LOCATIONS (bpt) |
c5aa993b | 1824 | { |
075f6582 DJ |
1825 | if (bpt->loc_type != bp_loc_software_breakpoint |
1826 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
1827 | continue; | |
1828 | ||
1829 | if (bpt->inserted | |
1830 | && bpt->address == pc) /* bp is inserted and matches pc */ | |
1831 | { | |
1832 | if (overlay_debugging | |
1833 | && section_is_overlay (bpt->section) | |
1834 | && !section_is_mapped (bpt->section)) | |
1835 | continue; /* unmapped overlay -- can't be a match */ | |
1836 | else | |
1837 | return 1; | |
1838 | } | |
c5aa993b | 1839 | } |
c36b740a VP |
1840 | return 0; |
1841 | } | |
1842 | ||
1843 | /* Returns non-zero iff there's either regular breakpoint | |
1844 | or a single step breakpoint inserted at PC. */ | |
1845 | ||
1846 | int | |
1847 | breakpoint_inserted_here_p (CORE_ADDR pc) | |
1848 | { | |
1849 | if (regular_breakpoint_inserted_here_p (pc)) | |
1850 | return 1; | |
c906108c | 1851 | |
1aafd4da UW |
1852 | if (single_step_breakpoint_inserted_here_p (pc)) |
1853 | return 1; | |
1854 | ||
c906108c SS |
1855 | return 0; |
1856 | } | |
1857 | ||
4fa8626c DJ |
1858 | /* This function returns non-zero iff there is a software breakpoint |
1859 | inserted at PC. */ | |
1860 | ||
1861 | int | |
1862 | software_breakpoint_inserted_here_p (CORE_ADDR pc) | |
1863 | { | |
89f9893c | 1864 | const struct bp_location *bpt; |
4fa8626c DJ |
1865 | int any_breakpoint_here = 0; |
1866 | ||
1867 | ALL_BP_LOCATIONS (bpt) | |
1868 | { | |
1869 | if (bpt->loc_type != bp_loc_software_breakpoint) | |
1870 | continue; | |
1871 | ||
0d381245 | 1872 | if (bpt->inserted |
4fa8626c DJ |
1873 | && bpt->address == pc) /* bp is enabled and matches pc */ |
1874 | { | |
1875 | if (overlay_debugging | |
1876 | && section_is_overlay (bpt->section) | |
1877 | && !section_is_mapped (bpt->section)) | |
1878 | continue; /* unmapped overlay -- can't be a match */ | |
1879 | else | |
1880 | return 1; | |
1881 | } | |
1882 | } | |
1883 | ||
1aafd4da UW |
1884 | /* Also check for software single-step breakpoints. */ |
1885 | if (single_step_breakpoint_inserted_here_p (pc)) | |
1886 | return 1; | |
1887 | ||
4fa8626c DJ |
1888 | return 0; |
1889 | } | |
1890 | ||
075f6582 DJ |
1891 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
1892 | PC is valid for process/thread PTID. */ | |
c906108c SS |
1893 | |
1894 | int | |
39f77062 | 1895 | breakpoint_thread_match (CORE_ADDR pc, ptid_t ptid) |
c906108c | 1896 | { |
89f9893c | 1897 | const struct bp_location *bpt; |
c906108c SS |
1898 | int thread; |
1899 | ||
39f77062 | 1900 | thread = pid_to_thread_id (ptid); |
c906108c | 1901 | |
075f6582 | 1902 | ALL_BP_LOCATIONS (bpt) |
c5aa993b | 1903 | { |
075f6582 DJ |
1904 | if (bpt->loc_type != bp_loc_software_breakpoint |
1905 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
1906 | continue; | |
1907 | ||
468d015d | 1908 | if ((breakpoint_enabled (bpt->owner) |
075f6582 DJ |
1909 | || bpt->owner->enable_state == bp_permanent) |
1910 | && bpt->address == pc | |
1911 | && (bpt->owner->thread == -1 || bpt->owner->thread == thread)) | |
1912 | { | |
1913 | if (overlay_debugging | |
1914 | && section_is_overlay (bpt->section) | |
1915 | && !section_is_mapped (bpt->section)) | |
1916 | continue; /* unmapped overlay -- can't be a match */ | |
1917 | else | |
1918 | return 1; | |
1919 | } | |
c5aa993b | 1920 | } |
c906108c SS |
1921 | |
1922 | return 0; | |
1923 | } | |
c906108c | 1924 | \f |
c5aa993b | 1925 | |
c906108c SS |
1926 | /* bpstat stuff. External routines' interfaces are documented |
1927 | in breakpoint.h. */ | |
1928 | ||
1929 | int | |
fba45db2 | 1930 | ep_is_catchpoint (struct breakpoint *ep) |
c906108c | 1931 | { |
533be4dd | 1932 | return (ep->type == bp_catchpoint); |
c906108c SS |
1933 | } |
1934 | ||
198757a8 VP |
1935 | void |
1936 | bpstat_free (bpstat bs) | |
1937 | { | |
1938 | if (bs->old_val != NULL) | |
1939 | value_free (bs->old_val); | |
1940 | free_command_lines (&bs->commands); | |
1941 | xfree (bs); | |
1942 | } | |
1943 | ||
c906108c SS |
1944 | /* Clear a bpstat so that it says we are not at any breakpoint. |
1945 | Also free any storage that is part of a bpstat. */ | |
1946 | ||
1947 | void | |
fba45db2 | 1948 | bpstat_clear (bpstat *bsp) |
c906108c SS |
1949 | { |
1950 | bpstat p; | |
1951 | bpstat q; | |
1952 | ||
1953 | if (bsp == 0) | |
1954 | return; | |
1955 | p = *bsp; | |
1956 | while (p != NULL) | |
1957 | { | |
1958 | q = p->next; | |
198757a8 | 1959 | bpstat_free (p); |
c906108c SS |
1960 | p = q; |
1961 | } | |
1962 | *bsp = NULL; | |
1963 | } | |
1964 | ||
1965 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
1966 | is part of the bpstat is copied as well. */ | |
1967 | ||
1968 | bpstat | |
fba45db2 | 1969 | bpstat_copy (bpstat bs) |
c906108c SS |
1970 | { |
1971 | bpstat p = NULL; | |
1972 | bpstat tmp; | |
1973 | bpstat retval = NULL; | |
1974 | ||
1975 | if (bs == NULL) | |
1976 | return bs; | |
1977 | ||
1978 | for (; bs != NULL; bs = bs->next) | |
1979 | { | |
1980 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
1981 | memcpy (tmp, bs, sizeof (*tmp)); | |
31cc81e9 DJ |
1982 | if (bs->commands != NULL) |
1983 | tmp->commands = copy_command_lines (bs->commands); | |
1984 | if (bs->old_val != NULL) | |
3c3185ac JK |
1985 | { |
1986 | tmp->old_val = value_copy (bs->old_val); | |
1987 | release_value (tmp->old_val); | |
1988 | } | |
31cc81e9 | 1989 | |
c906108c SS |
1990 | if (p == NULL) |
1991 | /* This is the first thing in the chain. */ | |
1992 | retval = tmp; | |
1993 | else | |
1994 | p->next = tmp; | |
1995 | p = tmp; | |
1996 | } | |
1997 | p->next = NULL; | |
1998 | return retval; | |
1999 | } | |
2000 | ||
2001 | /* Find the bpstat associated with this breakpoint */ | |
2002 | ||
2003 | bpstat | |
fba45db2 | 2004 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 2005 | { |
c5aa993b JM |
2006 | if (bsp == NULL) |
2007 | return NULL; | |
c906108c | 2008 | |
c5aa993b JM |
2009 | for (; bsp != NULL; bsp = bsp->next) |
2010 | { | |
4f8d1dc6 | 2011 | if (bsp->breakpoint_at && bsp->breakpoint_at->owner == breakpoint) |
c5aa993b JM |
2012 | return bsp; |
2013 | } | |
c906108c SS |
2014 | return NULL; |
2015 | } | |
2016 | ||
2017 | /* Find a step_resume breakpoint associated with this bpstat. | |
2018 | (If there are multiple step_resume bp's on the list, this function | |
2019 | will arbitrarily pick one.) | |
2020 | ||
2021 | It is an error to use this function if BPSTAT doesn't contain a | |
2022 | step_resume breakpoint. | |
2023 | ||
2024 | See wait_for_inferior's use of this function. */ | |
2025 | struct breakpoint * | |
fba45db2 | 2026 | bpstat_find_step_resume_breakpoint (bpstat bsp) |
c906108c | 2027 | { |
8601f500 MS |
2028 | int current_thread; |
2029 | ||
8a3fe4f8 | 2030 | gdb_assert (bsp != NULL); |
c906108c | 2031 | |
8601f500 MS |
2032 | current_thread = pid_to_thread_id (inferior_ptid); |
2033 | ||
c906108c SS |
2034 | for (; bsp != NULL; bsp = bsp->next) |
2035 | { | |
2036 | if ((bsp->breakpoint_at != NULL) && | |
4f8d1dc6 VP |
2037 | (bsp->breakpoint_at->owner->type == bp_step_resume) && |
2038 | (bsp->breakpoint_at->owner->thread == current_thread || | |
2039 | bsp->breakpoint_at->owner->thread == -1)) | |
2040 | return bsp->breakpoint_at->owner; | |
c906108c SS |
2041 | } |
2042 | ||
8a3fe4f8 | 2043 | internal_error (__FILE__, __LINE__, _("No step_resume breakpoint found.")); |
c906108c SS |
2044 | } |
2045 | ||
2046 | ||
8671a17b | 2047 | /* Put in *NUM the breakpoint number of the first breakpoint we are stopped |
c906108c SS |
2048 | at. *BSP upon return is a bpstat which points to the remaining |
2049 | breakpoints stopped at (but which is not guaranteed to be good for | |
2050 | anything but further calls to bpstat_num). | |
8671a17b PA |
2051 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
2052 | Return -1 if stopped at a breakpoint that has been deleted since | |
2053 | we set it. | |
2054 | Return 1 otherwise. */ | |
c906108c SS |
2055 | |
2056 | int | |
8671a17b | 2057 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
2058 | { |
2059 | struct breakpoint *b; | |
2060 | ||
2061 | if ((*bsp) == NULL) | |
2062 | return 0; /* No more breakpoint values */ | |
8671a17b | 2063 | |
4f8d1dc6 VP |
2064 | /* We assume we'll never have several bpstats that |
2065 | correspond to a single breakpoint -- otherwise, | |
2066 | this function might return the same number more | |
2067 | than once and this will look ugly. */ | |
2068 | b = (*bsp)->breakpoint_at ? (*bsp)->breakpoint_at->owner : NULL; | |
8671a17b PA |
2069 | *bsp = (*bsp)->next; |
2070 | if (b == NULL) | |
2071 | return -1; /* breakpoint that's been deleted since */ | |
2072 | ||
2073 | *num = b->number; /* We have its number */ | |
2074 | return 1; | |
c906108c SS |
2075 | } |
2076 | ||
2077 | /* Modify BS so that the actions will not be performed. */ | |
2078 | ||
2079 | void | |
fba45db2 | 2080 | bpstat_clear_actions (bpstat bs) |
c906108c SS |
2081 | { |
2082 | for (; bs != NULL; bs = bs->next) | |
2083 | { | |
c2b8ed2c | 2084 | free_command_lines (&bs->commands); |
c906108c SS |
2085 | if (bs->old_val != NULL) |
2086 | { | |
2087 | value_free (bs->old_val); | |
2088 | bs->old_val = NULL; | |
2089 | } | |
2090 | } | |
2091 | } | |
2092 | ||
2093 | /* Stub for cleaning up our state if we error-out of a breakpoint command */ | |
c906108c | 2094 | static void |
4efb68b1 | 2095 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
2096 | { |
2097 | executing_breakpoint_commands = 0; | |
2098 | } | |
2099 | ||
2100 | /* Execute all the commands associated with all the breakpoints at this | |
2101 | location. Any of these commands could cause the process to proceed | |
2102 | beyond this point, etc. We look out for such changes by checking | |
347bddb7 | 2103 | the global "breakpoint_proceeded" after each command. |
c906108c | 2104 | |
347bddb7 PA |
2105 | Returns true if a breakpoint command resumed the inferior. In that |
2106 | case, it is the caller's responsibility to recall it again with the | |
2107 | bpstat of the current thread. */ | |
2108 | ||
2109 | static int | |
2110 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
2111 | { |
2112 | bpstat bs; | |
2113 | struct cleanup *old_chain; | |
347bddb7 | 2114 | int again = 0; |
c906108c SS |
2115 | |
2116 | /* Avoid endless recursion if a `source' command is contained | |
2117 | in bs->commands. */ | |
2118 | if (executing_breakpoint_commands) | |
347bddb7 | 2119 | return 0; |
c906108c SS |
2120 | |
2121 | executing_breakpoint_commands = 1; | |
2122 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
2123 | ||
c906108c SS |
2124 | /* This pointer will iterate over the list of bpstat's. */ |
2125 | bs = *bsp; | |
2126 | ||
2127 | breakpoint_proceeded = 0; | |
2128 | for (; bs != NULL; bs = bs->next) | |
2129 | { | |
6c50ab1c JB |
2130 | struct command_line *cmd; |
2131 | struct cleanup *this_cmd_tree_chain; | |
2132 | ||
2133 | /* Take ownership of the BSP's command tree, if it has one. | |
2134 | ||
2135 | The command tree could legitimately contain commands like | |
2136 | 'step' and 'next', which call clear_proceed_status, which | |
2137 | frees stop_bpstat's command tree. To make sure this doesn't | |
2138 | free the tree we're executing out from under us, we need to | |
2139 | take ownership of the tree ourselves. Since a given bpstat's | |
2140 | commands are only executed once, we don't need to copy it; we | |
2141 | can clear the pointer in the bpstat, and make sure we free | |
2142 | the tree when we're done. */ | |
c906108c | 2143 | cmd = bs->commands; |
6c50ab1c JB |
2144 | bs->commands = 0; |
2145 | this_cmd_tree_chain = make_cleanup_free_command_lines (&cmd); | |
2146 | ||
c906108c SS |
2147 | while (cmd != NULL) |
2148 | { | |
2149 | execute_control_command (cmd); | |
2150 | ||
2151 | if (breakpoint_proceeded) | |
2152 | break; | |
2153 | else | |
2154 | cmd = cmd->next; | |
2155 | } | |
6c50ab1c JB |
2156 | |
2157 | /* We can free this command tree now. */ | |
2158 | do_cleanups (this_cmd_tree_chain); | |
2159 | ||
c906108c | 2160 | if (breakpoint_proceeded) |
32c1e744 VP |
2161 | { |
2162 | if (target_can_async_p ()) | |
347bddb7 PA |
2163 | /* If we are in async mode, then the target might be still |
2164 | running, not stopped at any breakpoint, so nothing for | |
2165 | us to do here -- just return to the event loop. */ | |
2166 | ; | |
32c1e744 VP |
2167 | else |
2168 | /* In sync mode, when execute_control_command returns | |
2169 | we're already standing on the next breakpoint. | |
347bddb7 PA |
2170 | Breakpoint commands for that stop were not run, since |
2171 | execute_command does not run breakpoint commands -- | |
2172 | only command_line_handler does, but that one is not | |
2173 | involved in execution of breakpoint commands. So, we | |
2174 | can now execute breakpoint commands. It should be | |
2175 | noted that making execute_command do bpstat actions is | |
2176 | not an option -- in this case we'll have recursive | |
2177 | invocation of bpstat for each breakpoint with a | |
2178 | command, and can easily blow up GDB stack. Instead, we | |
2179 | return true, which will trigger the caller to recall us | |
2180 | with the new stop_bpstat. */ | |
2181 | again = 1; | |
2182 | break; | |
32c1e744 | 2183 | } |
c906108c | 2184 | } |
c2b8ed2c | 2185 | do_cleanups (old_chain); |
347bddb7 PA |
2186 | return again; |
2187 | } | |
2188 | ||
2189 | void | |
2190 | bpstat_do_actions (void) | |
2191 | { | |
2192 | /* Do any commands attached to breakpoint we are stopped at. */ | |
2193 | while (!ptid_equal (inferior_ptid, null_ptid) | |
2194 | && target_has_execution | |
2195 | && !is_exited (inferior_ptid) | |
2196 | && !is_executing (inferior_ptid)) | |
2197 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
2198 | and only return when it is stopped at the next breakpoint, we | |
2199 | keep doing breakpoint actions until it returns false to | |
2200 | indicate the inferior was not resumed. */ | |
2201 | if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat)) | |
2202 | break; | |
c906108c SS |
2203 | } |
2204 | ||
fa4727a6 DJ |
2205 | /* Print out the (old or new) value associated with a watchpoint. */ |
2206 | ||
2207 | static void | |
2208 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
2209 | { | |
2210 | if (val == NULL) | |
2211 | fprintf_unfiltered (stream, _("<unreadable>")); | |
2212 | else | |
79a45b7d TT |
2213 | { |
2214 | struct value_print_options opts; | |
2215 | get_user_print_options (&opts); | |
2216 | value_print (val, stream, &opts); | |
2217 | } | |
fa4727a6 DJ |
2218 | } |
2219 | ||
e514a9d6 | 2220 | /* This is the normal print function for a bpstat. In the future, |
c906108c | 2221 | much of this logic could (should?) be moved to bpstat_stop_status, |
e514a9d6 JM |
2222 | by having it set different print_it values. |
2223 | ||
2224 | Current scheme: When we stop, bpstat_print() is called. It loops | |
2225 | through the bpstat list of things causing this stop, calling the | |
2226 | print_bp_stop_message function on each one. The behavior of the | |
2227 | print_bp_stop_message function depends on the print_it field of | |
2228 | bpstat. If such field so indicates, call this function here. | |
2229 | ||
2230 | Return values from this routine (ultimately used by bpstat_print() | |
2231 | and normal_stop() to decide what to do): | |
2232 | PRINT_NOTHING: Means we already printed all we needed to print, | |
2233 | don't print anything else. | |
2234 | PRINT_SRC_ONLY: Means we printed something, and we do *not* desire | |
2235 | that something to be followed by a location. | |
2236 | PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire | |
2237 | that something to be followed by a location. | |
2238 | PRINT_UNKNOWN: Means we printed nothing or we need to do some more | |
2239 | analysis. */ | |
c906108c | 2240 | |
917317f4 | 2241 | static enum print_stop_action |
fba45db2 | 2242 | print_it_typical (bpstat bs) |
c906108c | 2243 | { |
3b31d625 | 2244 | struct cleanup *old_chain, *ui_out_chain; |
4f8d1dc6 | 2245 | struct breakpoint *b; |
89f9893c | 2246 | const struct bp_location *bl; |
8b93c638 | 2247 | struct ui_stream *stb; |
2cec12e5 | 2248 | int bp_temp = 0; |
8b93c638 | 2249 | stb = ui_out_stream_new (uiout); |
b02eeafb | 2250 | old_chain = make_cleanup_ui_out_stream_delete (stb); |
c906108c SS |
2251 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
2252 | which has since been deleted. */ | |
e514a9d6 | 2253 | if (bs->breakpoint_at == NULL) |
917317f4 | 2254 | return PRINT_UNKNOWN; |
0d381245 VP |
2255 | bl = bs->breakpoint_at; |
2256 | b = bl->owner; | |
c906108c | 2257 | |
4f8d1dc6 | 2258 | switch (b->type) |
c906108c | 2259 | { |
e514a9d6 JM |
2260 | case bp_breakpoint: |
2261 | case bp_hardware_breakpoint: | |
2cec12e5 | 2262 | bp_temp = bs->breakpoint_at->owner->disposition == disp_del; |
0d381245 VP |
2263 | if (bl->address != bl->requested_address) |
2264 | breakpoint_adjustment_warning (bl->requested_address, | |
2265 | bl->address, | |
4f8d1dc6 VP |
2266 | b->number, 1); |
2267 | annotate_breakpoint (b->number); | |
2cec12e5 AR |
2268 | if (bp_temp) |
2269 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
2270 | else | |
2271 | ui_out_text (uiout, "\nBreakpoint "); | |
9dc5e2a9 | 2272 | if (ui_out_is_mi_like_p (uiout)) |
2cec12e5 AR |
2273 | { |
2274 | ui_out_field_string (uiout, "reason", | |
2275 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
2276 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
2277 | } | |
4f8d1dc6 | 2278 | ui_out_field_int (uiout, "bkptno", b->number); |
8b93c638 JM |
2279 | ui_out_text (uiout, ", "); |
2280 | return PRINT_SRC_AND_LOC; | |
e514a9d6 JM |
2281 | break; |
2282 | ||
2283 | case bp_shlib_event: | |
917317f4 JM |
2284 | /* Did we stop because the user set the stop_on_solib_events |
2285 | variable? (If so, we report this as a generic, "Stopped due | |
2286 | to shlib event" message.) */ | |
a3f17187 | 2287 | printf_filtered (_("Stopped due to shared library event\n")); |
e514a9d6 JM |
2288 | return PRINT_NOTHING; |
2289 | break; | |
2290 | ||
c4093a6a JM |
2291 | case bp_thread_event: |
2292 | /* Not sure how we will get here. | |
2293 | GDB should not stop for these breakpoints. */ | |
a3f17187 | 2294 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); |
c4093a6a JM |
2295 | return PRINT_NOTHING; |
2296 | break; | |
2297 | ||
1900040c MS |
2298 | case bp_overlay_event: |
2299 | /* By analogy with the thread event, GDB should not stop for these. */ | |
a3f17187 | 2300 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); |
1900040c MS |
2301 | return PRINT_NOTHING; |
2302 | break; | |
2303 | ||
e514a9d6 JM |
2304 | case bp_watchpoint: |
2305 | case bp_hardware_watchpoint: | |
fa4727a6 DJ |
2306 | annotate_watchpoint (b->number); |
2307 | if (ui_out_is_mi_like_p (uiout)) | |
2308 | ui_out_field_string | |
2309 | (uiout, "reason", | |
2310 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
2311 | mention (b); | |
2312 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
2313 | ui_out_text (uiout, "\nOld value = "); | |
2314 | watchpoint_value_print (bs->old_val, stb->stream); | |
2315 | ui_out_field_stream (uiout, "old", stb); | |
2316 | ui_out_text (uiout, "\nNew value = "); | |
2317 | watchpoint_value_print (b->val, stb->stream); | |
2318 | ui_out_field_stream (uiout, "new", stb); | |
2319 | do_cleanups (ui_out_chain); | |
2320 | ui_out_text (uiout, "\n"); | |
e514a9d6 JM |
2321 | /* More than one watchpoint may have been triggered. */ |
2322 | return PRINT_UNKNOWN; | |
2323 | break; | |
2324 | ||
2325 | case bp_read_watchpoint: | |
9dc5e2a9 | 2326 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2327 | ui_out_field_string |
2328 | (uiout, "reason", | |
2329 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 2330 | mention (b); |
3b31d625 | 2331 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 2332 | ui_out_text (uiout, "\nValue = "); |
fa4727a6 | 2333 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 2334 | ui_out_field_stream (uiout, "value", stb); |
3b31d625 | 2335 | do_cleanups (ui_out_chain); |
8b93c638 | 2336 | ui_out_text (uiout, "\n"); |
917317f4 | 2337 | return PRINT_UNKNOWN; |
e514a9d6 JM |
2338 | break; |
2339 | ||
2340 | case bp_access_watchpoint: | |
fa4727a6 | 2341 | if (bs->old_val != NULL) |
8b93c638 | 2342 | { |
4f8d1dc6 | 2343 | annotate_watchpoint (b->number); |
9dc5e2a9 | 2344 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2345 | ui_out_field_string |
2346 | (uiout, "reason", | |
2347 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 2348 | mention (b); |
3b31d625 | 2349 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 2350 | ui_out_text (uiout, "\nOld value = "); |
fa4727a6 | 2351 | watchpoint_value_print (bs->old_val, stb->stream); |
8b93c638 | 2352 | ui_out_field_stream (uiout, "old", stb); |
8b93c638 JM |
2353 | ui_out_text (uiout, "\nNew value = "); |
2354 | } | |
2355 | else | |
2356 | { | |
4f8d1dc6 | 2357 | mention (b); |
9dc5e2a9 | 2358 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2359 | ui_out_field_string |
2360 | (uiout, "reason", | |
2361 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
3b31d625 | 2362 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 JM |
2363 | ui_out_text (uiout, "\nValue = "); |
2364 | } | |
fa4727a6 | 2365 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 2366 | ui_out_field_stream (uiout, "new", stb); |
3b31d625 | 2367 | do_cleanups (ui_out_chain); |
8b93c638 | 2368 | ui_out_text (uiout, "\n"); |
917317f4 | 2369 | return PRINT_UNKNOWN; |
e514a9d6 | 2370 | break; |
4ce44c66 | 2371 | |
e514a9d6 JM |
2372 | /* Fall through, we don't deal with these types of breakpoints |
2373 | here. */ | |
2374 | ||
11cf8741 | 2375 | case bp_finish: |
9dc5e2a9 | 2376 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2377 | ui_out_field_string |
2378 | (uiout, "reason", | |
2379 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
8b93c638 JM |
2380 | return PRINT_UNKNOWN; |
2381 | break; | |
2382 | ||
e514a9d6 | 2383 | case bp_until: |
9dc5e2a9 | 2384 | if (ui_out_is_mi_like_p (uiout)) |
1fbc2a49 NR |
2385 | ui_out_field_string |
2386 | (uiout, "reason", | |
2387 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
8b93c638 JM |
2388 | return PRINT_UNKNOWN; |
2389 | break; | |
2390 | ||
c2d11a7d | 2391 | case bp_none: |
e514a9d6 JM |
2392 | case bp_longjmp: |
2393 | case bp_longjmp_resume: | |
2394 | case bp_step_resume: | |
e514a9d6 JM |
2395 | case bp_watchpoint_scope: |
2396 | case bp_call_dummy: | |
2397 | default: | |
2398 | return PRINT_UNKNOWN; | |
2399 | } | |
2400 | } | |
2401 | ||
2402 | /* Generic routine for printing messages indicating why we | |
2403 | stopped. The behavior of this function depends on the value | |
2404 | 'print_it' in the bpstat structure. Under some circumstances we | |
2405 | may decide not to print anything here and delegate the task to | |
2406 | normal_stop(). */ | |
2407 | ||
2408 | static enum print_stop_action | |
2409 | print_bp_stop_message (bpstat bs) | |
2410 | { | |
2411 | switch (bs->print_it) | |
2412 | { | |
2413 | case print_it_noop: | |
2414 | /* Nothing should be printed for this bpstat entry. */ | |
2415 | return PRINT_UNKNOWN; | |
2416 | break; | |
2417 | ||
2418 | case print_it_done: | |
2419 | /* We still want to print the frame, but we already printed the | |
2420 | relevant messages. */ | |
2421 | return PRINT_SRC_AND_LOC; | |
2422 | break; | |
2423 | ||
2424 | case print_it_normal: | |
4f8d1dc6 | 2425 | { |
89f9893c | 2426 | const struct bp_location *bl = bs->breakpoint_at; |
4f8d1dc6 VP |
2427 | struct breakpoint *b = bl ? bl->owner : NULL; |
2428 | ||
2429 | /* Normal case. Call the breakpoint's print_it method, or | |
2430 | print_it_typical. */ | |
2431 | /* FIXME: how breakpoint can ever be NULL here? */ | |
2432 | if (b != NULL && b->ops != NULL && b->ops->print_it != NULL) | |
2433 | return b->ops->print_it (b); | |
2434 | else | |
2435 | return print_it_typical (bs); | |
2436 | } | |
2437 | break; | |
3086aeae | 2438 | |
e514a9d6 | 2439 | default: |
8e65ff28 | 2440 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 2441 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 2442 | break; |
c906108c | 2443 | } |
c906108c SS |
2444 | } |
2445 | ||
e514a9d6 JM |
2446 | /* Print a message indicating what happened. This is called from |
2447 | normal_stop(). The input to this routine is the head of the bpstat | |
2448 | list - a list of the eventpoints that caused this stop. This | |
2449 | routine calls the generic print routine for printing a message | |
2450 | about reasons for stopping. This will print (for example) the | |
2451 | "Breakpoint n," part of the output. The return value of this | |
2452 | routine is one of: | |
c906108c | 2453 | |
917317f4 JM |
2454 | PRINT_UNKNOWN: Means we printed nothing |
2455 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent | |
c5aa993b JM |
2456 | code to print the location. An example is |
2457 | "Breakpoint 1, " which should be followed by | |
2458 | the location. | |
917317f4 | 2459 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
2460 | to also print the location part of the message. |
2461 | An example is the catch/throw messages, which | |
917317f4 JM |
2462 | don't require a location appended to the end. |
2463 | PRINT_NOTHING: We have done some printing and we don't need any | |
2464 | further info to be printed.*/ | |
c906108c | 2465 | |
917317f4 | 2466 | enum print_stop_action |
fba45db2 | 2467 | bpstat_print (bpstat bs) |
c906108c SS |
2468 | { |
2469 | int val; | |
c5aa993b | 2470 | |
c906108c | 2471 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
2472 | (Currently all watchpoints go on the bpstat whether hit or not. |
2473 | That probably could (should) be changed, provided care is taken | |
c906108c | 2474 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
2475 | for (; bs; bs = bs->next) |
2476 | { | |
2477 | val = print_bp_stop_message (bs); | |
2478 | if (val == PRINT_SRC_ONLY | |
2479 | || val == PRINT_SRC_AND_LOC | |
2480 | || val == PRINT_NOTHING) | |
2481 | return val; | |
2482 | } | |
c906108c | 2483 | |
e514a9d6 JM |
2484 | /* We reached the end of the chain, or we got a null BS to start |
2485 | with and nothing was printed. */ | |
917317f4 | 2486 | return PRINT_UNKNOWN; |
c906108c SS |
2487 | } |
2488 | ||
2489 | /* Evaluate the expression EXP and return 1 if value is zero. | |
2490 | This is used inside a catch_errors to evaluate the breakpoint condition. | |
2491 | The argument is a "struct expression *" that has been cast to char * to | |
2492 | make it pass through catch_errors. */ | |
2493 | ||
2494 | static int | |
4efb68b1 | 2495 | breakpoint_cond_eval (void *exp) |
c906108c | 2496 | { |
278cd55f | 2497 | struct value *mark = value_mark (); |
c5aa993b | 2498 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
c906108c SS |
2499 | value_free_to_mark (mark); |
2500 | return i; | |
2501 | } | |
2502 | ||
2503 | /* Allocate a new bpstat and chain it to the current one. */ | |
2504 | ||
2505 | static bpstat | |
89f9893c | 2506 | bpstat_alloc (const struct bp_location *bl, bpstat cbs /* Current "bs" value */ ) |
c906108c SS |
2507 | { |
2508 | bpstat bs; | |
2509 | ||
2510 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
2511 | cbs->next = bs; | |
4f8d1dc6 | 2512 | bs->breakpoint_at = bl; |
c906108c SS |
2513 | /* If the condition is false, etc., don't do the commands. */ |
2514 | bs->commands = NULL; | |
2515 | bs->old_val = NULL; | |
2516 | bs->print_it = print_it_normal; | |
2517 | return bs; | |
2518 | } | |
2519 | \f | |
d983da9c DJ |
2520 | /* The target has stopped with waitstatus WS. Check if any hardware |
2521 | watchpoints have triggered, according to the target. */ | |
2522 | ||
2523 | int | |
2524 | watchpoints_triggered (struct target_waitstatus *ws) | |
2525 | { | |
2526 | int stopped_by_watchpoint = STOPPED_BY_WATCHPOINT (*ws); | |
2527 | CORE_ADDR addr; | |
2528 | struct breakpoint *b; | |
2529 | ||
2530 | if (!stopped_by_watchpoint) | |
2531 | { | |
2532 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
2533 | as not triggered. */ | |
2534 | ALL_BREAKPOINTS (b) | |
2535 | if (b->type == bp_hardware_watchpoint | |
2536 | || b->type == bp_read_watchpoint | |
2537 | || b->type == bp_access_watchpoint) | |
2538 | b->watchpoint_triggered = watch_triggered_no; | |
2539 | ||
2540 | return 0; | |
2541 | } | |
2542 | ||
2543 | if (!target_stopped_data_address (¤t_target, &addr)) | |
2544 | { | |
2545 | /* We were stopped by a watchpoint, but we don't know where. | |
2546 | Mark all watchpoints as unknown. */ | |
2547 | ALL_BREAKPOINTS (b) | |
2548 | if (b->type == bp_hardware_watchpoint | |
2549 | || b->type == bp_read_watchpoint | |
2550 | || b->type == bp_access_watchpoint) | |
2551 | b->watchpoint_triggered = watch_triggered_unknown; | |
2552 | ||
2553 | return stopped_by_watchpoint; | |
2554 | } | |
2555 | ||
2556 | /* The target could report the data address. Mark watchpoints | |
2557 | affected by this data address as triggered, and all others as not | |
2558 | triggered. */ | |
2559 | ||
2560 | ALL_BREAKPOINTS (b) | |
2561 | if (b->type == bp_hardware_watchpoint | |
2562 | || b->type == bp_read_watchpoint | |
2563 | || b->type == bp_access_watchpoint) | |
2564 | { | |
a5606eee | 2565 | struct bp_location *loc; |
d983da9c DJ |
2566 | struct value *v; |
2567 | ||
2568 | b->watchpoint_triggered = watch_triggered_no; | |
a5606eee VP |
2569 | for (loc = b->loc; loc; loc = loc->next) |
2570 | /* Exact match not required. Within range is | |
2571 | sufficient. */ | |
5009afc5 AS |
2572 | if (target_watchpoint_addr_within_range (¤t_target, |
2573 | addr, loc->address, | |
2574 | loc->length)) | |
a5606eee VP |
2575 | { |
2576 | b->watchpoint_triggered = watch_triggered_yes; | |
2577 | break; | |
2578 | } | |
d983da9c DJ |
2579 | } |
2580 | ||
2581 | return 1; | |
2582 | } | |
2583 | ||
c906108c SS |
2584 | /* Possible return values for watchpoint_check (this can't be an enum |
2585 | because of check_errors). */ | |
2586 | /* The watchpoint has been deleted. */ | |
2587 | #define WP_DELETED 1 | |
2588 | /* The value has changed. */ | |
2589 | #define WP_VALUE_CHANGED 2 | |
2590 | /* The value has not changed. */ | |
2591 | #define WP_VALUE_NOT_CHANGED 3 | |
2592 | ||
2593 | #define BP_TEMPFLAG 1 | |
2594 | #define BP_HARDWAREFLAG 2 | |
2595 | ||
2596 | /* Check watchpoint condition. */ | |
2597 | ||
2598 | static int | |
4efb68b1 | 2599 | watchpoint_check (void *p) |
c906108c SS |
2600 | { |
2601 | bpstat bs = (bpstat) p; | |
2602 | struct breakpoint *b; | |
2603 | struct frame_info *fr; | |
2604 | int within_current_scope; | |
2605 | ||
4f8d1dc6 | 2606 | b = bs->breakpoint_at->owner; |
c906108c SS |
2607 | |
2608 | if (b->exp_valid_block == NULL) | |
2609 | within_current_scope = 1; | |
2610 | else | |
2611 | { | |
2612 | /* There is no current frame at this moment. If we're going to have | |
c5aa993b JM |
2613 | any chance of handling watchpoints on local variables, we'll need |
2614 | the frame chain (so we can determine if we're in scope). */ | |
2615 | reinit_frame_cache (); | |
101dcfbe | 2616 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 2617 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
2618 | |
2619 | /* If we've gotten confused in the unwinder, we might have | |
2620 | returned a frame that can't describe this variable. */ | |
2621 | if (within_current_scope | |
7f0df278 DJ |
2622 | && (block_linkage_function (b->exp_valid_block) |
2623 | != get_frame_function (fr))) | |
69fbadd5 DJ |
2624 | within_current_scope = 0; |
2625 | ||
c12260ac CV |
2626 | /* in_function_epilogue_p() returns a non-zero value if we're still |
2627 | in the function but the stack frame has already been invalidated. | |
2628 | Since we can't rely on the values of local variables after the | |
2629 | stack has been destroyed, we are treating the watchpoint in that | |
a957e642 CV |
2630 | state as `not changed' without further checking. |
2631 | ||
2632 | vinschen/2003-09-04: The former implementation left out the case | |
2633 | that the watchpoint frame couldn't be found by frame_find_by_id() | |
2634 | because the current PC is currently in an epilogue. Calling | |
2635 | gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */ | |
a6fbcf2f | 2636 | if ((!within_current_scope || fr == get_current_frame ()) |
c12260ac CV |
2637 | && gdbarch_in_function_epilogue_p (current_gdbarch, read_pc ())) |
2638 | return WP_VALUE_NOT_CHANGED; | |
a6fbcf2f | 2639 | if (fr && within_current_scope) |
c906108c SS |
2640 | /* If we end up stopping, the current frame will get selected |
2641 | in normal_stop. So this call to select_frame won't affect | |
2642 | the user. */ | |
0f7d239c | 2643 | select_frame (fr); |
c906108c | 2644 | } |
c5aa993b | 2645 | |
c906108c SS |
2646 | if (within_current_scope) |
2647 | { | |
2648 | /* We use value_{,free_to_}mark because it could be a | |
2649 | *long* time before we return to the command level and | |
c5aa993b JM |
2650 | call free_all_values. We can't call free_all_values because |
2651 | we might be in the middle of evaluating a function call. */ | |
c906108c | 2652 | |
278cd55f | 2653 | struct value *mark = value_mark (); |
fa4727a6 DJ |
2654 | struct value *new_val; |
2655 | ||
2656 | fetch_watchpoint_value (b->exp, &new_val, NULL, NULL); | |
2657 | if ((b->val != NULL) != (new_val != NULL) | |
2658 | || (b->val != NULL && !value_equal (b->val, new_val))) | |
c906108c | 2659 | { |
fa4727a6 DJ |
2660 | if (new_val != NULL) |
2661 | { | |
2662 | release_value (new_val); | |
2663 | value_free_to_mark (mark); | |
2664 | } | |
c906108c SS |
2665 | bs->old_val = b->val; |
2666 | b->val = new_val; | |
fa4727a6 | 2667 | b->val_valid = 1; |
c906108c SS |
2668 | /* We will stop here */ |
2669 | return WP_VALUE_CHANGED; | |
2670 | } | |
2671 | else | |
2672 | { | |
2673 | /* Nothing changed, don't do anything. */ | |
2674 | value_free_to_mark (mark); | |
2675 | /* We won't stop here */ | |
2676 | return WP_VALUE_NOT_CHANGED; | |
2677 | } | |
2678 | } | |
2679 | else | |
2680 | { | |
2681 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
2682 | if we temporarily ignored the watchpoint, then when |
2683 | we reenter the block in which it is valid it contains | |
2684 | garbage (in the case of a function, it may have two | |
2685 | garbage values, one before and one after the prologue). | |
2686 | So we can't even detect the first assignment to it and | |
2687 | watch after that (since the garbage may or may not equal | |
2688 | the first value assigned). */ | |
4ce44c66 JM |
2689 | /* We print all the stop information in print_it_typical(), but |
2690 | in this case, by the time we call print_it_typical() this bp | |
2691 | will be deleted already. So we have no choice but print the | |
2692 | information here. */ | |
9dc5e2a9 | 2693 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2694 | ui_out_field_string |
2695 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 2696 | ui_out_text (uiout, "\nWatchpoint "); |
4f8d1dc6 | 2697 | ui_out_field_int (uiout, "wpnum", b->number); |
8b93c638 JM |
2698 | ui_out_text (uiout, " deleted because the program has left the block in\n\ |
2699 | which its expression is valid.\n"); | |
4ce44c66 | 2700 | |
c906108c | 2701 | if (b->related_breakpoint) |
b5de0fa7 EZ |
2702 | b->related_breakpoint->disposition = disp_del_at_next_stop; |
2703 | b->disposition = disp_del_at_next_stop; | |
c906108c SS |
2704 | |
2705 | return WP_DELETED; | |
2706 | } | |
2707 | } | |
2708 | ||
18a18393 VP |
2709 | /* Return true if it looks like target has stopped due to hitting |
2710 | breakpoint location BL. This function does not check if we | |
2711 | should stop, only if BL explains the stop. */ | |
2712 | static int | |
2713 | bpstat_check_location (const struct bp_location *bl, CORE_ADDR bp_addr) | |
2714 | { | |
2715 | struct breakpoint *b = bl->owner; | |
2716 | ||
2717 | if (b->type != bp_watchpoint | |
2718 | && b->type != bp_hardware_watchpoint | |
2719 | && b->type != bp_read_watchpoint | |
2720 | && b->type != bp_access_watchpoint | |
2721 | && b->type != bp_hardware_breakpoint | |
fe798b75 | 2722 | && b->type != bp_catchpoint) /* a non-watchpoint bp */ |
18a18393 VP |
2723 | { |
2724 | if (bl->address != bp_addr) /* address doesn't match */ | |
2725 | return 0; | |
2726 | if (overlay_debugging /* unmapped overlay section */ | |
2727 | && section_is_overlay (bl->section) | |
2728 | && !section_is_mapped (bl->section)) | |
2729 | return 0; | |
2730 | } | |
2731 | ||
2732 | /* Continuable hardware watchpoints are treated as non-existent if the | |
2733 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
2734 | some data address). Otherwise gdb won't stop on a break instruction | |
2735 | in the code (not from a breakpoint) when a hardware watchpoint has | |
2736 | been defined. Also skip watchpoints which we know did not trigger | |
2737 | (did not match the data address). */ | |
2738 | ||
2739 | if ((b->type == bp_hardware_watchpoint | |
2740 | || b->type == bp_read_watchpoint | |
2741 | || b->type == bp_access_watchpoint) | |
2742 | && b->watchpoint_triggered == watch_triggered_no) | |
2743 | return 0; | |
2744 | ||
2745 | if (b->type == bp_hardware_breakpoint) | |
2746 | { | |
2747 | if (bl->address != bp_addr) | |
2748 | return 0; | |
2749 | if (overlay_debugging /* unmapped overlay section */ | |
2750 | && section_is_overlay (bl->section) | |
2751 | && !section_is_mapped (bl->section)) | |
2752 | return 0; | |
2753 | } | |
ce78b96d | 2754 | |
ce78b96d JB |
2755 | if (b->type == bp_catchpoint) |
2756 | { | |
2757 | gdb_assert (b->ops != NULL && b->ops->breakpoint_hit != NULL); | |
2758 | if (!b->ops->breakpoint_hit (b)) | |
2759 | return 0; | |
2760 | } | |
2761 | ||
18a18393 VP |
2762 | return 1; |
2763 | } | |
2764 | ||
2765 | /* If BS refers to a watchpoint, determine if the watched values | |
2766 | has actually changed, and we should stop. If not, set BS->stop | |
2767 | to 0. */ | |
2768 | static void | |
2769 | bpstat_check_watchpoint (bpstat bs) | |
2770 | { | |
2771 | const struct bp_location *bl = bs->breakpoint_at; | |
2772 | struct breakpoint *b = bl->owner; | |
2773 | ||
2774 | if (b->type == bp_watchpoint | |
2775 | || b->type == bp_read_watchpoint | |
2776 | || b->type == bp_access_watchpoint | |
2777 | || b->type == bp_hardware_watchpoint) | |
2778 | { | |
2779 | CORE_ADDR addr; | |
2780 | struct value *v; | |
2781 | int must_check_value = 0; | |
2782 | ||
2783 | if (b->type == bp_watchpoint) | |
2784 | /* For a software watchpoint, we must always check the | |
2785 | watched value. */ | |
2786 | must_check_value = 1; | |
2787 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
2788 | /* We have a hardware watchpoint (read, write, or access) | |
2789 | and the target earlier reported an address watched by | |
2790 | this watchpoint. */ | |
2791 | must_check_value = 1; | |
2792 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
2793 | && b->type == bp_hardware_watchpoint) | |
2794 | /* We were stopped by a hardware watchpoint, but the target could | |
2795 | not report the data address. We must check the watchpoint's | |
2796 | value. Access and read watchpoints are out of luck; without | |
2797 | a data address, we can't figure it out. */ | |
2798 | must_check_value = 1; | |
2799 | ||
2800 | if (must_check_value) | |
2801 | { | |
2802 | char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
2803 | b->number); | |
2804 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
2805 | int e = catch_errors (watchpoint_check, bs, message, | |
2806 | RETURN_MASK_ALL); | |
2807 | do_cleanups (cleanups); | |
2808 | switch (e) | |
2809 | { | |
2810 | case WP_DELETED: | |
2811 | /* We've already printed what needs to be printed. */ | |
2812 | bs->print_it = print_it_done; | |
2813 | /* Stop. */ | |
2814 | break; | |
2815 | case WP_VALUE_CHANGED: | |
2816 | if (b->type == bp_read_watchpoint) | |
2817 | { | |
2818 | /* Don't stop: read watchpoints shouldn't fire if | |
2819 | the value has changed. This is for targets | |
2820 | which cannot set read-only watchpoints. */ | |
2821 | bs->print_it = print_it_noop; | |
2822 | bs->stop = 0; | |
2823 | } | |
2824 | break; | |
2825 | case WP_VALUE_NOT_CHANGED: | |
2826 | if (b->type == bp_hardware_watchpoint | |
2827 | || b->type == bp_watchpoint) | |
2828 | { | |
2829 | /* Don't stop: write watchpoints shouldn't fire if | |
2830 | the value hasn't changed. */ | |
2831 | bs->print_it = print_it_noop; | |
2832 | bs->stop = 0; | |
2833 | } | |
2834 | /* Stop. */ | |
2835 | break; | |
2836 | default: | |
2837 | /* Can't happen. */ | |
2838 | case 0: | |
2839 | /* Error from catch_errors. */ | |
2840 | printf_filtered (_("Watchpoint %d deleted.\n"), b->number); | |
2841 | if (b->related_breakpoint) | |
2842 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
2843 | b->disposition = disp_del_at_next_stop; | |
2844 | /* We've already printed what needs to be printed. */ | |
2845 | bs->print_it = print_it_done; | |
2846 | break; | |
2847 | } | |
2848 | } | |
2849 | else /* must_check_value == 0 */ | |
2850 | { | |
2851 | /* This is a case where some watchpoint(s) triggered, but | |
2852 | not at the address of this watchpoint, or else no | |
2853 | watchpoint triggered after all. So don't print | |
2854 | anything for this watchpoint. */ | |
2855 | bs->print_it = print_it_noop; | |
2856 | bs->stop = 0; | |
2857 | } | |
2858 | } | |
2859 | } | |
2860 | ||
2861 | ||
2862 | /* Check conditions (condition proper, frame, thread and ignore count) | |
2863 | of breakpoint referred to by BS. If we should not stop for this | |
2864 | breakpoint, set BS->stop to 0. */ | |
2865 | static void | |
2866 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
2867 | { | |
2868 | int thread_id = pid_to_thread_id (ptid); | |
2869 | const struct bp_location *bl = bs->breakpoint_at; | |
2870 | struct breakpoint *b = bl->owner; | |
2871 | ||
2872 | if (frame_id_p (b->frame_id) | |
2873 | && !frame_id_eq (b->frame_id, get_frame_id (get_current_frame ()))) | |
2874 | bs->stop = 0; | |
2875 | else if (bs->stop) | |
2876 | { | |
2877 | int value_is_zero = 0; | |
2878 | ||
2879 | /* If this is a scope breakpoint, mark the associated | |
2880 | watchpoint as triggered so that we will handle the | |
2881 | out-of-scope event. We'll get to the watchpoint next | |
2882 | iteration. */ | |
2883 | if (b->type == bp_watchpoint_scope) | |
2884 | b->related_breakpoint->watchpoint_triggered = watch_triggered_yes; | |
2885 | ||
2886 | if (bl->cond && bl->owner->disposition != disp_del_at_next_stop) | |
2887 | { | |
2888 | /* Need to select the frame, with all that implies | |
2889 | so that the conditions will have the right context. */ | |
2890 | select_frame (get_current_frame ()); | |
2891 | value_is_zero | |
2892 | = catch_errors (breakpoint_cond_eval, (bl->cond), | |
2893 | "Error in testing breakpoint condition:\n", | |
2894 | RETURN_MASK_ALL); | |
2895 | /* FIXME-someday, should give breakpoint # */ | |
2896 | free_all_values (); | |
2897 | } | |
2898 | if (bl->cond && value_is_zero) | |
2899 | { | |
2900 | bs->stop = 0; | |
2901 | } | |
2902 | else if (b->thread != -1 && b->thread != thread_id) | |
2903 | { | |
2904 | bs->stop = 0; | |
2905 | } | |
2906 | else if (b->ignore_count > 0) | |
2907 | { | |
2908 | b->ignore_count--; | |
2909 | annotate_ignore_count_change (); | |
2910 | bs->stop = 0; | |
2911 | /* Increase the hit count even though we don't | |
2912 | stop. */ | |
2913 | ++(b->hit_count); | |
2914 | } | |
2915 | } | |
2916 | } | |
2917 | ||
2918 | ||
9709f61c | 2919 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 2920 | BP_ADDR in thread PTID. |
c906108c | 2921 | |
d983da9c | 2922 | Determine whether we stopped at a breakpoint, etc, or whether we |
c906108c SS |
2923 | don't understand this stop. Result is a chain of bpstat's such that: |
2924 | ||
c5aa993b | 2925 | if we don't understand the stop, the result is a null pointer. |
c906108c | 2926 | |
c5aa993b | 2927 | if we understand why we stopped, the result is not null. |
c906108c | 2928 | |
c5aa993b JM |
2929 | Each element of the chain refers to a particular breakpoint or |
2930 | watchpoint at which we have stopped. (We may have stopped for | |
2931 | several reasons concurrently.) | |
c906108c | 2932 | |
c5aa993b JM |
2933 | Each element of the chain has valid next, breakpoint_at, |
2934 | commands, FIXME??? fields. */ | |
c906108c SS |
2935 | |
2936 | bpstat | |
d983da9c | 2937 | bpstat_stop_status (CORE_ADDR bp_addr, ptid_t ptid) |
c906108c | 2938 | { |
0d381245 | 2939 | struct breakpoint *b = NULL; |
89f9893c | 2940 | const struct bp_location *bl; |
20874c92 | 2941 | struct bp_location *loc; |
c906108c SS |
2942 | /* Root of the chain of bpstat's */ |
2943 | struct bpstats root_bs[1]; | |
2944 | /* Pointer to the last thing in the chain currently. */ | |
2945 | bpstat bs = root_bs; | |
20874c92 | 2946 | int ix; |
d832cb68 | 2947 | int need_remove_insert; |
c906108c | 2948 | |
0d381245 | 2949 | ALL_BP_LOCATIONS (bl) |
c5aa993b | 2950 | { |
0d381245 VP |
2951 | b = bl->owner; |
2952 | gdb_assert (b); | |
468d015d | 2953 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) |
c5aa993b JM |
2954 | continue; |
2955 | ||
a5606eee VP |
2956 | /* For hardware watchpoints, we look only at the first location. |
2957 | The watchpoint_check function will work on entire expression, | |
2958 | not the individual locations. For read watchopints, the | |
2959 | watchpoints_triggered function have checked all locations | |
2960 | alrea | |
2961 | */ | |
2962 | if (b->type == bp_hardware_watchpoint && bl != b->loc) | |
2963 | continue; | |
2964 | ||
18a18393 VP |
2965 | if (!bpstat_check_location (bl, bp_addr)) |
2966 | continue; | |
2967 | ||
c5aa993b JM |
2968 | /* Come here if it's a watchpoint, or if the break address matches */ |
2969 | ||
0d381245 | 2970 | bs = bpstat_alloc (bl, bs); /* Alloc a bpstat to explain stop */ |
c5aa993b | 2971 | |
18a18393 VP |
2972 | /* Assume we stop. Should we find watchpoint that is not actually |
2973 | triggered, or if condition of breakpoint is false, we'll reset | |
2974 | 'stop' to 0. */ | |
c5aa993b JM |
2975 | bs->stop = 1; |
2976 | bs->print = 1; | |
2977 | ||
18a18393 VP |
2978 | bpstat_check_watchpoint (bs); |
2979 | if (!bs->stop) | |
2980 | continue; | |
c5aa993b | 2981 | |
18a18393 VP |
2982 | if (b->type == bp_thread_event || b->type == bp_overlay_event) |
2983 | /* We do not stop for these. */ | |
c5aa993b JM |
2984 | bs->stop = 0; |
2985 | else | |
18a18393 VP |
2986 | bpstat_check_breakpoint_conditions (bs, ptid); |
2987 | ||
2988 | if (bs->stop) | |
c5aa993b | 2989 | { |
18a18393 | 2990 | ++(b->hit_count); |
d983da9c | 2991 | |
18a18393 VP |
2992 | /* We will stop here */ |
2993 | if (b->disposition == disp_disable) | |
c5aa993b | 2994 | { |
514f746b AR |
2995 | if (b->enable_state != bp_permanent) |
2996 | b->enable_state = bp_disabled; | |
b60e7edf | 2997 | update_global_location_list (0); |
c5aa993b | 2998 | } |
18a18393 VP |
2999 | if (b->silent) |
3000 | bs->print = 0; | |
3001 | bs->commands = b->commands; | |
3002 | if (bs->commands && | |
3003 | (strcmp ("silent", bs->commands->line) == 0 | |
3004 | || (xdb_commands && strcmp ("Q", bs->commands->line) == 0))) | |
c5aa993b | 3005 | { |
18a18393 VP |
3006 | bs->commands = bs->commands->next; |
3007 | bs->print = 0; | |
c5aa993b | 3008 | } |
18a18393 | 3009 | bs->commands = copy_command_lines (bs->commands); |
c5aa993b | 3010 | } |
18a18393 | 3011 | |
c5aa993b JM |
3012 | /* Print nothing for this entry if we dont stop or if we dont print. */ |
3013 | if (bs->stop == 0 || bs->print == 0) | |
3014 | bs->print_it = print_it_noop; | |
3015 | } | |
c906108c | 3016 | |
20874c92 VP |
3017 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
3018 | { | |
3019 | if (loc->address == bp_addr) | |
3020 | { | |
3021 | bs = bpstat_alloc (loc, bs); | |
3022 | /* For hits of moribund locations, we should just proceed. */ | |
3023 | bs->stop = 0; | |
3024 | bs->print = 0; | |
3025 | bs->print_it = print_it_noop; | |
3026 | } | |
3027 | } | |
3028 | ||
c906108c SS |
3029 | bs->next = NULL; /* Terminate the chain */ |
3030 | bs = root_bs->next; /* Re-grab the head of the chain */ | |
3031 | ||
d983da9c DJ |
3032 | /* If we aren't stopping, the value of some hardware watchpoint may |
3033 | not have changed, but the intermediate memory locations we are | |
3034 | watching may have. Don't bother if we're stopping; this will get | |
3035 | done later. */ | |
3036 | for (bs = root_bs->next; bs != NULL; bs = bs->next) | |
3037 | if (bs->stop) | |
3038 | break; | |
3039 | ||
d832cb68 | 3040 | need_remove_insert = 0; |
d983da9c DJ |
3041 | if (bs == NULL) |
3042 | for (bs = root_bs->next; bs != NULL; bs = bs->next) | |
3043 | if (!bs->stop | |
20874c92 | 3044 | && bs->breakpoint_at->owner |
d983da9c DJ |
3045 | && (bs->breakpoint_at->owner->type == bp_hardware_watchpoint |
3046 | || bs->breakpoint_at->owner->type == bp_read_watchpoint | |
3047 | || bs->breakpoint_at->owner->type == bp_access_watchpoint)) | |
3048 | { | |
a5606eee VP |
3049 | /* remove/insert can invalidate bs->breakpoint_at, if this |
3050 | location is no longer used by the watchpoint. Prevent | |
3051 | further code from trying to use it. */ | |
3052 | bs->breakpoint_at = NULL; | |
d832cb68 | 3053 | need_remove_insert = 1; |
d983da9c DJ |
3054 | } |
3055 | ||
d832cb68 DD |
3056 | if (need_remove_insert) |
3057 | { | |
3058 | remove_breakpoints (); | |
3059 | insert_breakpoints (); | |
3060 | } | |
3061 | ||
d983da9c | 3062 | return root_bs->next; |
c906108c SS |
3063 | } |
3064 | \f | |
3065 | /* Tell what to do about this bpstat. */ | |
3066 | struct bpstat_what | |
fba45db2 | 3067 | bpstat_what (bpstat bs) |
c906108c SS |
3068 | { |
3069 | /* Classify each bpstat as one of the following. */ | |
c5aa993b JM |
3070 | enum class |
3071 | { | |
3072 | /* This bpstat element has no effect on the main_action. */ | |
3073 | no_effect = 0, | |
3074 | ||
3075 | /* There was a watchpoint, stop but don't print. */ | |
3076 | wp_silent, | |
c906108c | 3077 | |
c5aa993b JM |
3078 | /* There was a watchpoint, stop and print. */ |
3079 | wp_noisy, | |
c906108c | 3080 | |
c5aa993b JM |
3081 | /* There was a breakpoint but we're not stopping. */ |
3082 | bp_nostop, | |
c906108c | 3083 | |
c5aa993b JM |
3084 | /* There was a breakpoint, stop but don't print. */ |
3085 | bp_silent, | |
c906108c | 3086 | |
c5aa993b JM |
3087 | /* There was a breakpoint, stop and print. */ |
3088 | bp_noisy, | |
c906108c | 3089 | |
c5aa993b JM |
3090 | /* We hit the longjmp breakpoint. */ |
3091 | long_jump, | |
c906108c | 3092 | |
c5aa993b JM |
3093 | /* We hit the longjmp_resume breakpoint. */ |
3094 | long_resume, | |
c906108c | 3095 | |
c5aa993b JM |
3096 | /* We hit the step_resume breakpoint. */ |
3097 | step_resume, | |
c906108c | 3098 | |
c5aa993b JM |
3099 | /* We hit the shared library event breakpoint. */ |
3100 | shlib_event, | |
c906108c | 3101 | |
c5aa993b JM |
3102 | /* This is just used to count how many enums there are. */ |
3103 | class_last | |
c906108c SS |
3104 | }; |
3105 | ||
3106 | /* Here is the table which drives this routine. So that we can | |
3107 | format it pretty, we define some abbreviations for the | |
3108 | enum bpstat_what codes. */ | |
3109 | #define kc BPSTAT_WHAT_KEEP_CHECKING | |
3110 | #define ss BPSTAT_WHAT_STOP_SILENT | |
3111 | #define sn BPSTAT_WHAT_STOP_NOISY | |
3112 | #define sgl BPSTAT_WHAT_SINGLE | |
3113 | #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME | |
3114 | #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME | |
c906108c | 3115 | #define sr BPSTAT_WHAT_STEP_RESUME |
c906108c | 3116 | #define shl BPSTAT_WHAT_CHECK_SHLIBS |
c906108c SS |
3117 | |
3118 | /* "Can't happen." Might want to print an error message. | |
3119 | abort() is not out of the question, but chances are GDB is just | |
3120 | a bit confused, not unusable. */ | |
3121 | #define err BPSTAT_WHAT_STOP_NOISY | |
3122 | ||
3123 | /* Given an old action and a class, come up with a new action. */ | |
3124 | /* One interesting property of this table is that wp_silent is the same | |
3125 | as bp_silent and wp_noisy is the same as bp_noisy. That is because | |
3126 | after stopping, the check for whether to step over a breakpoint | |
3127 | (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without | |
53a5351d JM |
3128 | reference to how we stopped. We retain separate wp_silent and |
3129 | bp_silent codes in case we want to change that someday. | |
43ff13b4 JM |
3130 | |
3131 | Another possibly interesting property of this table is that | |
3132 | there's a partial ordering, priority-like, of the actions. Once | |
3133 | you've decided that some action is appropriate, you'll never go | |
3134 | back and decide something of a lower priority is better. The | |
3135 | ordering is: | |
3136 | ||
d81191fc JB |
3137 | kc < clr sgl shl slr sn sr ss |
3138 | sgl < shl slr sn sr ss | |
3139 | slr < err shl sn sr ss | |
3140 | clr < err shl sn sr ss | |
3141 | ss < shl sn sr | |
3142 | sn < shl sr | |
3143 | shl < sr | |
4d5b2cd7 | 3144 | sr < |
c5aa993b | 3145 | |
43ff13b4 JM |
3146 | What I think this means is that we don't need a damned table |
3147 | here. If you just put the rows and columns in the right order, | |
3148 | it'd look awfully regular. We could simply walk the bpstat list | |
3149 | and choose the highest priority action we find, with a little | |
78b6a731 | 3150 | logic to handle the 'err' cases. */ |
c906108c SS |
3151 | |
3152 | /* step_resume entries: a step resume breakpoint overrides another | |
3153 | breakpoint of signal handling (see comment in wait_for_inferior | |
fcf70625 | 3154 | at where we set the step_resume breakpoint). */ |
c906108c SS |
3155 | |
3156 | static const enum bpstat_what_main_action | |
c5aa993b JM |
3157 | table[(int) class_last][(int) BPSTAT_WHAT_LAST] = |
3158 | { | |
3159 | /* old action */ | |
d81191fc | 3160 | /* kc ss sn sgl slr clr sr shl |
c5aa993b JM |
3161 | */ |
3162 | /*no_effect */ | |
d81191fc | 3163 | {kc, ss, sn, sgl, slr, clr, sr, shl}, |
c5aa993b | 3164 | /*wp_silent */ |
d81191fc | 3165 | {ss, ss, sn, ss, ss, ss, sr, shl}, |
c5aa993b | 3166 | /*wp_noisy */ |
d81191fc | 3167 | {sn, sn, sn, sn, sn, sn, sr, shl}, |
c5aa993b | 3168 | /*bp_nostop */ |
d81191fc | 3169 | {sgl, ss, sn, sgl, slr, slr, sr, shl}, |
c5aa993b | 3170 | /*bp_silent */ |
d81191fc | 3171 | {ss, ss, sn, ss, ss, ss, sr, shl}, |
c5aa993b | 3172 | /*bp_noisy */ |
d81191fc | 3173 | {sn, sn, sn, sn, sn, sn, sr, shl}, |
c5aa993b | 3174 | /*long_jump */ |
d81191fc | 3175 | {slr, ss, sn, slr, slr, err, sr, shl}, |
c5aa993b | 3176 | /*long_resume */ |
d81191fc | 3177 | {clr, ss, sn, err, err, err, sr, shl}, |
c5aa993b | 3178 | /*step_resume */ |
d81191fc | 3179 | {sr, sr, sr, sr, sr, sr, sr, sr}, |
c5aa993b | 3180 | /*shlib */ |
d81191fc | 3181 | {shl, shl, shl, shl, shl, shl, sr, shl} |
c5aa993b | 3182 | }; |
c906108c SS |
3183 | |
3184 | #undef kc | |
3185 | #undef ss | |
3186 | #undef sn | |
3187 | #undef sgl | |
3188 | #undef slr | |
3189 | #undef clr | |
c906108c SS |
3190 | #undef err |
3191 | #undef sr | |
3192 | #undef ts | |
3193 | #undef shl | |
c906108c SS |
3194 | enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING; |
3195 | struct bpstat_what retval; | |
3196 | ||
3197 | retval.call_dummy = 0; | |
3198 | for (; bs != NULL; bs = bs->next) | |
3199 | { | |
3200 | enum class bs_class = no_effect; | |
3201 | if (bs->breakpoint_at == NULL) | |
3202 | /* I suspect this can happen if it was a momentary breakpoint | |
3203 | which has since been deleted. */ | |
3204 | continue; | |
20874c92 VP |
3205 | if (bs->breakpoint_at->owner == NULL) |
3206 | bs_class = bp_nostop; | |
3207 | else | |
4f8d1dc6 | 3208 | switch (bs->breakpoint_at->owner->type) |
c906108c SS |
3209 | { |
3210 | case bp_none: | |
3211 | continue; | |
3212 | ||
3213 | case bp_breakpoint: | |
3214 | case bp_hardware_breakpoint: | |
3215 | case bp_until: | |
3216 | case bp_finish: | |
3217 | if (bs->stop) | |
3218 | { | |
3219 | if (bs->print) | |
3220 | bs_class = bp_noisy; | |
3221 | else | |
3222 | bs_class = bp_silent; | |
3223 | } | |
3224 | else | |
3225 | bs_class = bp_nostop; | |
3226 | break; | |
3227 | case bp_watchpoint: | |
3228 | case bp_hardware_watchpoint: | |
3229 | case bp_read_watchpoint: | |
3230 | case bp_access_watchpoint: | |
3231 | if (bs->stop) | |
3232 | { | |
3233 | if (bs->print) | |
3234 | bs_class = wp_noisy; | |
3235 | else | |
3236 | bs_class = wp_silent; | |
3237 | } | |
3238 | else | |
53a5351d JM |
3239 | /* There was a watchpoint, but we're not stopping. |
3240 | This requires no further action. */ | |
c906108c SS |
3241 | bs_class = no_effect; |
3242 | break; | |
3243 | case bp_longjmp: | |
3244 | bs_class = long_jump; | |
3245 | break; | |
3246 | case bp_longjmp_resume: | |
3247 | bs_class = long_resume; | |
3248 | break; | |
3249 | case bp_step_resume: | |
3250 | if (bs->stop) | |
3251 | { | |
3252 | bs_class = step_resume; | |
3253 | } | |
3254 | else | |
3255 | /* It is for the wrong frame. */ | |
3256 | bs_class = bp_nostop; | |
3257 | break; | |
c906108c SS |
3258 | case bp_watchpoint_scope: |
3259 | bs_class = bp_nostop; | |
3260 | break; | |
c5aa993b JM |
3261 | case bp_shlib_event: |
3262 | bs_class = shlib_event; | |
3263 | break; | |
c4093a6a | 3264 | case bp_thread_event: |
1900040c | 3265 | case bp_overlay_event: |
c4093a6a JM |
3266 | bs_class = bp_nostop; |
3267 | break; | |
ce78b96d | 3268 | case bp_catchpoint: |
c5aa993b JM |
3269 | if (bs->stop) |
3270 | { | |
3271 | if (bs->print) | |
3272 | bs_class = bp_noisy; | |
3273 | else | |
3274 | bs_class = bp_silent; | |
3275 | } | |
3276 | else | |
53a5351d JM |
3277 | /* There was a catchpoint, but we're not stopping. |
3278 | This requires no further action. */ | |
c5aa993b JM |
3279 | bs_class = no_effect; |
3280 | break; | |
c906108c | 3281 | case bp_call_dummy: |
53a5351d JM |
3282 | /* Make sure the action is stop (silent or noisy), |
3283 | so infrun.c pops the dummy frame. */ | |
c906108c SS |
3284 | bs_class = bp_silent; |
3285 | retval.call_dummy = 1; | |
3286 | break; | |
3287 | } | |
c5aa993b | 3288 | current_action = table[(int) bs_class][(int) current_action]; |
c906108c SS |
3289 | } |
3290 | retval.main_action = current_action; | |
3291 | return retval; | |
3292 | } | |
3293 | ||
3294 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
3295 | without hardware support). This isn't related to a specific bpstat, | |
3296 | just to things like whether watchpoints are set. */ | |
3297 | ||
c5aa993b | 3298 | int |
fba45db2 | 3299 | bpstat_should_step (void) |
c906108c SS |
3300 | { |
3301 | struct breakpoint *b; | |
3302 | ALL_BREAKPOINTS (b) | |
468d015d | 3303 | if (breakpoint_enabled (b) && b->type == bp_watchpoint) |
3172dc30 | 3304 | return 1; |
c906108c SS |
3305 | return 0; |
3306 | } | |
3307 | ||
c906108c | 3308 | \f |
c5aa993b | 3309 | |
0d381245 VP |
3310 | static void print_breakpoint_location (struct breakpoint *b, |
3311 | struct bp_location *loc, | |
3312 | char *wrap_indent, | |
3313 | struct ui_stream *stb) | |
3314 | { | |
3315 | if (b->source_file) | |
3316 | { | |
3317 | struct symbol *sym | |
3318 | = find_pc_sect_function (loc->address, loc->section); | |
3319 | if (sym) | |
3320 | { | |
3321 | ui_out_text (uiout, "in "); | |
3322 | ui_out_field_string (uiout, "func", | |
3323 | SYMBOL_PRINT_NAME (sym)); | |
3324 | ui_out_wrap_hint (uiout, wrap_indent); | |
3325 | ui_out_text (uiout, " at "); | |
3326 | } | |
3327 | ui_out_field_string (uiout, "file", b->source_file); | |
3328 | ui_out_text (uiout, ":"); | |
3329 | ||
3330 | if (ui_out_is_mi_like_p (uiout)) | |
3331 | { | |
3332 | struct symtab_and_line sal = find_pc_line (loc->address, 0); | |
3333 | char *fullname = symtab_to_fullname (sal.symtab); | |
3334 | ||
3335 | if (fullname) | |
3336 | ui_out_field_string (uiout, "fullname", fullname); | |
3337 | } | |
3338 | ||
3339 | ui_out_field_int (uiout, "line", b->line_number); | |
3340 | } | |
3341 | else if (!b->loc) | |
3342 | { | |
3343 | ui_out_field_string (uiout, "pending", b->addr_string); | |
3344 | } | |
3345 | else | |
3346 | { | |
3347 | print_address_symbolic (loc->address, stb->stream, demangle, ""); | |
3348 | ui_out_field_stream (uiout, "at", stb); | |
3349 | } | |
3350 | } | |
3351 | ||
c4093a6a | 3352 | /* Print B to gdb_stdout. */ |
c906108c | 3353 | static void |
0d381245 VP |
3354 | print_one_breakpoint_location (struct breakpoint *b, |
3355 | struct bp_location *loc, | |
3356 | int loc_number, | |
3357 | CORE_ADDR *last_addr) | |
c906108c | 3358 | { |
52f0bd74 AC |
3359 | struct command_line *l; |
3360 | struct symbol *sym; | |
c4093a6a JM |
3361 | struct ep_type_description |
3362 | { | |
3363 | enum bptype type; | |
3364 | char *description; | |
3365 | }; | |
3366 | static struct ep_type_description bptypes[] = | |
c906108c | 3367 | { |
c5aa993b JM |
3368 | {bp_none, "?deleted?"}, |
3369 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 3370 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
3371 | {bp_until, "until"}, |
3372 | {bp_finish, "finish"}, | |
3373 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 3374 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
3375 | {bp_read_watchpoint, "read watchpoint"}, |
3376 | {bp_access_watchpoint, "acc watchpoint"}, | |
3377 | {bp_longjmp, "longjmp"}, | |
3378 | {bp_longjmp_resume, "longjmp resume"}, | |
3379 | {bp_step_resume, "step resume"}, | |
c5aa993b JM |
3380 | {bp_watchpoint_scope, "watchpoint scope"}, |
3381 | {bp_call_dummy, "call dummy"}, | |
3382 | {bp_shlib_event, "shlib events"}, | |
c4093a6a | 3383 | {bp_thread_event, "thread events"}, |
1900040c | 3384 | {bp_overlay_event, "overlay events"}, |
ce78b96d | 3385 | {bp_catchpoint, "catchpoint"}, |
c5aa993b | 3386 | }; |
c4093a6a | 3387 | |
c2c6d25f | 3388 | static char bpenables[] = "nynny"; |
c906108c | 3389 | char wrap_indent[80]; |
8b93c638 JM |
3390 | struct ui_stream *stb = ui_out_stream_new (uiout); |
3391 | struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb); | |
3b31d625 | 3392 | struct cleanup *bkpt_chain; |
c906108c | 3393 | |
0d381245 VP |
3394 | int header_of_multiple = 0; |
3395 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
3396 | struct value_print_options opts; |
3397 | ||
3398 | get_user_print_options (&opts); | |
0d381245 VP |
3399 | |
3400 | gdb_assert (!loc || loc_number != 0); | |
3401 | /* See comment in print_one_breakpoint concerning | |
3402 | treatment of breakpoints with single disabled | |
3403 | location. */ | |
3404 | if (loc == NULL | |
3405 | && (b->loc != NULL | |
3406 | && (b->loc->next != NULL || !b->loc->enabled))) | |
3407 | header_of_multiple = 1; | |
3408 | if (loc == NULL) | |
3409 | loc = b->loc; | |
3410 | ||
c4093a6a | 3411 | annotate_record (); |
3b31d625 | 3412 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); |
c4093a6a JM |
3413 | |
3414 | /* 1 */ | |
3415 | annotate_field (0); | |
0d381245 VP |
3416 | if (part_of_multiple) |
3417 | { | |
3418 | char *formatted; | |
0c6773c1 | 3419 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
3420 | ui_out_field_string (uiout, "number", formatted); |
3421 | xfree (formatted); | |
3422 | } | |
3423 | else | |
3424 | { | |
3425 | ui_out_field_int (uiout, "number", b->number); | |
3426 | } | |
c4093a6a JM |
3427 | |
3428 | /* 2 */ | |
3429 | annotate_field (1); | |
0d381245 VP |
3430 | if (part_of_multiple) |
3431 | ui_out_field_skip (uiout, "type"); | |
3432 | else | |
3433 | { | |
3434 | if (((int) b->type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
3435 | || ((int) b->type != bptypes[(int) b->type].type)) | |
3436 | internal_error (__FILE__, __LINE__, | |
3437 | _("bptypes table does not describe type #%d."), | |
3438 | (int) b->type); | |
3439 | ui_out_field_string (uiout, "type", bptypes[(int) b->type].description); | |
3440 | } | |
c4093a6a JM |
3441 | |
3442 | /* 3 */ | |
3443 | annotate_field (2); | |
0d381245 VP |
3444 | if (part_of_multiple) |
3445 | ui_out_field_skip (uiout, "disp"); | |
3446 | else | |
2cec12e5 | 3447 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 3448 | |
c4093a6a JM |
3449 | |
3450 | /* 4 */ | |
3451 | annotate_field (3); | |
0d381245 | 3452 | if (part_of_multiple) |
54e52265 | 3453 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 3454 | else |
54e52265 VP |
3455 | ui_out_field_fmt (uiout, "enabled", "%c", |
3456 | bpenables[(int) b->enable_state]); | |
3457 | ui_out_spaces (uiout, 2); | |
0d381245 | 3458 | |
c4093a6a JM |
3459 | |
3460 | /* 5 and 6 */ | |
3461 | strcpy (wrap_indent, " "); | |
79a45b7d | 3462 | if (opts.addressprint) |
75ac9d7b | 3463 | { |
17a912b6 | 3464 | if (gdbarch_addr_bit (current_gdbarch) <= 32) |
75ac9d7b MS |
3465 | strcat (wrap_indent, " "); |
3466 | else | |
3467 | strcat (wrap_indent, " "); | |
3468 | } | |
c906108c | 3469 | |
3086aeae | 3470 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 VP |
3471 | { |
3472 | /* Although the print_one can possibly print | |
3473 | all locations, calling it here is not likely | |
3474 | to get any nice result. So, make sure there's | |
3475 | just one location. */ | |
3476 | gdb_assert (b->loc == NULL || b->loc->next == NULL); | |
3477 | b->ops->print_one (b, last_addr); | |
3478 | } | |
3086aeae DJ |
3479 | else |
3480 | switch (b->type) | |
3481 | { | |
3482 | case bp_none: | |
3483 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 3484 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 3485 | break; |
c906108c | 3486 | |
3086aeae DJ |
3487 | case bp_watchpoint: |
3488 | case bp_hardware_watchpoint: | |
3489 | case bp_read_watchpoint: | |
3490 | case bp_access_watchpoint: | |
3491 | /* Field 4, the address, is omitted (which makes the columns | |
3492 | not line up too nicely with the headers, but the effect | |
3493 | is relatively readable). */ | |
79a45b7d | 3494 | if (opts.addressprint) |
3086aeae DJ |
3495 | ui_out_field_skip (uiout, "addr"); |
3496 | annotate_field (5); | |
3497 | print_expression (b->exp, stb->stream); | |
3498 | ui_out_field_stream (uiout, "what", stb); | |
3499 | break; | |
3500 | ||
3086aeae DJ |
3501 | case bp_breakpoint: |
3502 | case bp_hardware_breakpoint: | |
3503 | case bp_until: | |
3504 | case bp_finish: | |
3505 | case bp_longjmp: | |
3506 | case bp_longjmp_resume: | |
3507 | case bp_step_resume: | |
3086aeae DJ |
3508 | case bp_watchpoint_scope: |
3509 | case bp_call_dummy: | |
3510 | case bp_shlib_event: | |
3511 | case bp_thread_event: | |
3512 | case bp_overlay_event: | |
79a45b7d | 3513 | if (opts.addressprint) |
3086aeae DJ |
3514 | { |
3515 | annotate_field (4); | |
54e52265 | 3516 | if (header_of_multiple) |
0d381245 | 3517 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 3518 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 3519 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 3520 | else |
0d381245 | 3521 | ui_out_field_core_addr (uiout, "addr", loc->address); |
3086aeae DJ |
3522 | } |
3523 | annotate_field (5); | |
0d381245 VP |
3524 | if (!header_of_multiple) |
3525 | print_breakpoint_location (b, loc, wrap_indent, stb); | |
3526 | if (b->loc) | |
3527 | *last_addr = b->loc->address; | |
3086aeae DJ |
3528 | break; |
3529 | } | |
c906108c | 3530 | |
0d381245 | 3531 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 3532 | { |
8b93c638 JM |
3533 | /* FIXME: This seems to be redundant and lost here; see the |
3534 | "stop only in" line a little further down. */ | |
3535 | ui_out_text (uiout, " thread "); | |
3536 | ui_out_field_int (uiout, "thread", b->thread); | |
c4093a6a JM |
3537 | } |
3538 | ||
8b93c638 | 3539 | ui_out_text (uiout, "\n"); |
c4093a6a | 3540 | |
0d381245 | 3541 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
3542 | { |
3543 | annotate_field (6); | |
8b93c638 | 3544 | ui_out_text (uiout, "\tstop only in stack frame at "); |
818dd999 AC |
3545 | /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside |
3546 | the frame ID. */ | |
d0a55772 | 3547 | ui_out_field_core_addr (uiout, "frame", b->frame_id.stack_addr); |
8b93c638 | 3548 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
3549 | } |
3550 | ||
0d381245 | 3551 | if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b)) |
c4093a6a | 3552 | { |
f7f9143b JB |
3553 | /* We do not print the condition for Ada exception catchpoints |
3554 | because the condition is an internal implementation detail | |
3555 | that we do not want to expose to the user. */ | |
c4093a6a | 3556 | annotate_field (7); |
8b93c638 | 3557 | ui_out_text (uiout, "\tstop only if "); |
0101ce28 JJ |
3558 | ui_out_field_string (uiout, "cond", b->cond_string); |
3559 | ui_out_text (uiout, "\n"); | |
3560 | } | |
3561 | ||
0d381245 | 3562 | if (!part_of_multiple && b->thread != -1) |
c4093a6a JM |
3563 | { |
3564 | /* FIXME should make an annotation for this */ | |
8b93c638 JM |
3565 | ui_out_text (uiout, "\tstop only in thread "); |
3566 | ui_out_field_int (uiout, "thread", b->thread); | |
3567 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
3568 | } |
3569 | ||
63c715c6 | 3570 | if (!part_of_multiple && b->hit_count) |
c4093a6a JM |
3571 | { |
3572 | /* FIXME should make an annotation for this */ | |
8b93c638 JM |
3573 | if (ep_is_catchpoint (b)) |
3574 | ui_out_text (uiout, "\tcatchpoint"); | |
3575 | else | |
3576 | ui_out_text (uiout, "\tbreakpoint"); | |
3577 | ui_out_text (uiout, " already hit "); | |
3578 | ui_out_field_int (uiout, "times", b->hit_count); | |
3579 | if (b->hit_count == 1) | |
3580 | ui_out_text (uiout, " time\n"); | |
3581 | else | |
3582 | ui_out_text (uiout, " times\n"); | |
c4093a6a JM |
3583 | } |
3584 | ||
fb40c209 AC |
3585 | /* Output the count also if it is zero, but only if this is |
3586 | mi. FIXME: Should have a better test for this. */ | |
9dc5e2a9 | 3587 | if (ui_out_is_mi_like_p (uiout)) |
63c715c6 | 3588 | if (!part_of_multiple && b->hit_count == 0) |
fb40c209 | 3589 | ui_out_field_int (uiout, "times", b->hit_count); |
8b93c638 | 3590 | |
0d381245 | 3591 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
3592 | { |
3593 | annotate_field (8); | |
8b93c638 JM |
3594 | ui_out_text (uiout, "\tignore next "); |
3595 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
3596 | ui_out_text (uiout, " hits\n"); | |
c4093a6a JM |
3597 | } |
3598 | ||
0d381245 | 3599 | if (!part_of_multiple && (l = b->commands)) |
c4093a6a | 3600 | { |
3b31d625 EZ |
3601 | struct cleanup *script_chain; |
3602 | ||
c4093a6a | 3603 | annotate_field (9); |
3b31d625 | 3604 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 3605 | print_command_lines (uiout, l, 4); |
3b31d625 | 3606 | do_cleanups (script_chain); |
c4093a6a | 3607 | } |
d24317b4 VP |
3608 | |
3609 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) | |
3610 | { | |
3611 | if (b->addr_string) | |
3612 | ui_out_field_string (uiout, "original-location", b->addr_string); | |
3613 | else if (b->exp_string) | |
3614 | ui_out_field_string (uiout, "original-location", b->exp_string); | |
3615 | } | |
3616 | ||
3b31d625 | 3617 | do_cleanups (bkpt_chain); |
8b93c638 | 3618 | do_cleanups (old_chain); |
c4093a6a | 3619 | } |
c5aa993b | 3620 | |
0d381245 VP |
3621 | static void |
3622 | print_one_breakpoint (struct breakpoint *b, | |
3623 | CORE_ADDR *last_addr) | |
3624 | { | |
3625 | print_one_breakpoint_location (b, NULL, 0, last_addr); | |
3626 | ||
3627 | /* If this breakpoint has custom print function, | |
3628 | it's already printed. Otherwise, print individual | |
3629 | locations, if any. */ | |
3630 | if (b->ops == NULL || b->ops->print_one == NULL) | |
3631 | { | |
3632 | /* If breakpoint has a single location that is | |
3633 | disabled, we print it as if it had | |
3634 | several locations, since otherwise it's hard to | |
3635 | represent "breakpoint enabled, location disabled" | |
a5606eee VP |
3636 | situation. |
3637 | Note that while hardware watchpoints have | |
3638 | several locations internally, that's no a property | |
3639 | exposed to user. */ | |
0d381245 | 3640 | if (b->loc |
a5606eee | 3641 | && !is_hardware_watchpoint (b) |
0d381245 | 3642 | && (b->loc->next || !b->loc->enabled) |
a5606eee | 3643 | && !ui_out_is_mi_like_p (uiout)) |
0d381245 VP |
3644 | { |
3645 | struct bp_location *loc; | |
3646 | int n = 1; | |
3647 | for (loc = b->loc; loc; loc = loc->next, ++n) | |
3648 | print_one_breakpoint_location (b, loc, n, last_addr); | |
3649 | } | |
3650 | } | |
3651 | } | |
3652 | ||
3653 | ||
c4093a6a JM |
3654 | struct captured_breakpoint_query_args |
3655 | { | |
3656 | int bnum; | |
3657 | }; | |
c5aa993b | 3658 | |
c4093a6a | 3659 | static int |
2b65245e | 3660 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
3661 | { |
3662 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 3663 | struct breakpoint *b; |
c4093a6a JM |
3664 | CORE_ADDR dummy_addr = 0; |
3665 | ALL_BREAKPOINTS (b) | |
3666 | { | |
3667 | if (args->bnum == b->number) | |
c5aa993b | 3668 | { |
c4093a6a JM |
3669 | print_one_breakpoint (b, &dummy_addr); |
3670 | return GDB_RC_OK; | |
c5aa993b | 3671 | } |
c4093a6a JM |
3672 | } |
3673 | return GDB_RC_NONE; | |
3674 | } | |
c5aa993b | 3675 | |
c4093a6a | 3676 | enum gdb_rc |
ce43223b | 3677 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, char **error_message) |
c4093a6a JM |
3678 | { |
3679 | struct captured_breakpoint_query_args args; | |
3680 | args.bnum = bnum; | |
3681 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
3682 | an error. */ | |
b0b13bb4 DJ |
3683 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
3684 | error_message, RETURN_MASK_ALL) < 0) | |
3685 | return GDB_RC_FAIL; | |
3686 | else | |
3687 | return GDB_RC_OK; | |
c4093a6a | 3688 | } |
c5aa993b | 3689 | |
7f3b0473 AC |
3690 | /* Return non-zero if B is user settable (breakpoints, watchpoints, |
3691 | catchpoints, et.al.). */ | |
3692 | ||
3693 | static int | |
3694 | user_settable_breakpoint (const struct breakpoint *b) | |
3695 | { | |
3696 | return (b->type == bp_breakpoint | |
ce78b96d | 3697 | || b->type == bp_catchpoint |
7f3b0473 AC |
3698 | || b->type == bp_hardware_breakpoint |
3699 | || b->type == bp_watchpoint | |
3700 | || b->type == bp_read_watchpoint | |
3701 | || b->type == bp_access_watchpoint | |
3702 | || b->type == bp_hardware_watchpoint); | |
3703 | } | |
3704 | ||
3705 | /* Print information on user settable breakpoint (watchpoint, etc) | |
3706 | number BNUM. If BNUM is -1 print all user settable breakpoints. | |
3707 | If ALLFLAG is non-zero, include non- user settable breakpoints. */ | |
c906108c | 3708 | |
c4093a6a | 3709 | static void |
fba45db2 | 3710 | breakpoint_1 (int bnum, int allflag) |
c4093a6a | 3711 | { |
52f0bd74 | 3712 | struct breakpoint *b; |
c4093a6a | 3713 | CORE_ADDR last_addr = (CORE_ADDR) -1; |
7f3b0473 | 3714 | int nr_printable_breakpoints; |
3b31d625 | 3715 | struct cleanup *bkpttbl_chain; |
79a45b7d | 3716 | struct value_print_options opts; |
c4093a6a | 3717 | |
79a45b7d TT |
3718 | get_user_print_options (&opts); |
3719 | ||
7f3b0473 AC |
3720 | /* Compute the number of rows in the table. */ |
3721 | nr_printable_breakpoints = 0; | |
3722 | ALL_BREAKPOINTS (b) | |
3723 | if (bnum == -1 | |
3724 | || bnum == b->number) | |
3725 | { | |
3726 | if (allflag || user_settable_breakpoint (b)) | |
3727 | nr_printable_breakpoints++; | |
3728 | } | |
3729 | ||
79a45b7d | 3730 | if (opts.addressprint) |
3b31d625 EZ |
3731 | bkpttbl_chain |
3732 | = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints, | |
3733 | "BreakpointTable"); | |
8b93c638 | 3734 | else |
3b31d625 EZ |
3735 | bkpttbl_chain |
3736 | = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints, | |
3737 | "BreakpointTable"); | |
8b93c638 | 3738 | |
7f3b0473 | 3739 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
3740 | annotate_breakpoints_headers (); |
3741 | if (nr_printable_breakpoints > 0) | |
3742 | annotate_field (0); | |
0d381245 | 3743 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
3744 | if (nr_printable_breakpoints > 0) |
3745 | annotate_field (1); | |
3746 | ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */ | |
3747 | if (nr_printable_breakpoints > 0) | |
3748 | annotate_field (2); | |
3749 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ | |
3750 | if (nr_printable_breakpoints > 0) | |
3751 | annotate_field (3); | |
54e52265 | 3752 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 3753 | if (opts.addressprint) |
7f3b0473 | 3754 | { |
d7faa9e7 AC |
3755 | if (nr_printable_breakpoints > 0) |
3756 | annotate_field (4); | |
17a912b6 | 3757 | if (gdbarch_addr_bit (current_gdbarch) <= 32) |
b25959ec | 3758 | ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */ |
7f3b0473 | 3759 | else |
b25959ec | 3760 | ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */ |
7f3b0473 | 3761 | } |
d7faa9e7 AC |
3762 | if (nr_printable_breakpoints > 0) |
3763 | annotate_field (5); | |
3764 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
3765 | ui_out_table_body (uiout); | |
3766 | if (nr_printable_breakpoints > 0) | |
3767 | annotate_breakpoints_table (); | |
7f3b0473 | 3768 | |
c4093a6a JM |
3769 | ALL_BREAKPOINTS (b) |
3770 | if (bnum == -1 | |
3771 | || bnum == b->number) | |
3772 | { | |
3773 | /* We only print out user settable breakpoints unless the | |
3774 | allflag is set. */ | |
7f3b0473 AC |
3775 | if (allflag || user_settable_breakpoint (b)) |
3776 | print_one_breakpoint (b, &last_addr); | |
c4093a6a JM |
3777 | } |
3778 | ||
3b31d625 | 3779 | do_cleanups (bkpttbl_chain); |
698384cd | 3780 | |
7f3b0473 | 3781 | if (nr_printable_breakpoints == 0) |
c906108c | 3782 | { |
8b93c638 JM |
3783 | if (bnum == -1) |
3784 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); | |
3785 | else | |
3786 | ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n", | |
3787 | bnum); | |
c906108c SS |
3788 | } |
3789 | else | |
c4093a6a JM |
3790 | { |
3791 | /* Compare against (CORE_ADDR)-1 in case some compiler decides | |
3792 | that a comparison of an unsigned with -1 is always false. */ | |
d1aa2f50 | 3793 | if (last_addr != (CORE_ADDR) -1 && !server_command) |
8b9b9e1a | 3794 | set_next_address (current_gdbarch, last_addr); |
c4093a6a | 3795 | } |
c906108c | 3796 | |
c4093a6a JM |
3797 | /* FIXME? Should this be moved up so that it is only called when |
3798 | there have been breakpoints? */ | |
c906108c SS |
3799 | annotate_breakpoints_table_end (); |
3800 | } | |
3801 | ||
c906108c | 3802 | static void |
fba45db2 | 3803 | breakpoints_info (char *bnum_exp, int from_tty) |
c906108c SS |
3804 | { |
3805 | int bnum = -1; | |
3806 | ||
3807 | if (bnum_exp) | |
bb518678 | 3808 | bnum = parse_and_eval_long (bnum_exp); |
c906108c SS |
3809 | |
3810 | breakpoint_1 (bnum, 0); | |
3811 | } | |
3812 | ||
7a292a7a | 3813 | static void |
fba45db2 | 3814 | maintenance_info_breakpoints (char *bnum_exp, int from_tty) |
c906108c SS |
3815 | { |
3816 | int bnum = -1; | |
3817 | ||
3818 | if (bnum_exp) | |
bb518678 | 3819 | bnum = parse_and_eval_long (bnum_exp); |
c906108c SS |
3820 | |
3821 | breakpoint_1 (bnum, 1); | |
3822 | } | |
3823 | ||
0d381245 | 3824 | static int |
714835d5 UW |
3825 | breakpoint_has_pc (struct breakpoint *b, |
3826 | CORE_ADDR pc, struct obj_section *section) | |
0d381245 VP |
3827 | { |
3828 | struct bp_location *bl = b->loc; | |
3829 | for (; bl; bl = bl->next) | |
3830 | { | |
3831 | if (bl->address == pc | |
3832 | && (!overlay_debugging || bl->section == section)) | |
3833 | return 1; | |
3834 | } | |
3835 | return 0; | |
3836 | } | |
3837 | ||
c906108c SS |
3838 | /* Print a message describing any breakpoints set at PC. */ |
3839 | ||
3840 | static void | |
714835d5 UW |
3841 | describe_other_breakpoints (CORE_ADDR pc, struct obj_section *section, |
3842 | int thread) | |
c906108c | 3843 | { |
52f0bd74 AC |
3844 | int others = 0; |
3845 | struct breakpoint *b; | |
c906108c SS |
3846 | |
3847 | ALL_BREAKPOINTS (b) | |
0d381245 | 3848 | others += breakpoint_has_pc (b, pc, section); |
c906108c SS |
3849 | if (others > 0) |
3850 | { | |
a3f17187 AC |
3851 | if (others == 1) |
3852 | printf_filtered (_("Note: breakpoint ")); | |
3853 | else /* if (others == ???) */ | |
3854 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 3855 | ALL_BREAKPOINTS (b) |
0d381245 VP |
3856 | if (breakpoint_has_pc (b, pc, section)) |
3857 | { | |
3858 | others--; | |
3859 | printf_filtered ("%d", b->number); | |
3860 | if (b->thread == -1 && thread != -1) | |
3861 | printf_filtered (" (all threads)"); | |
3862 | else if (b->thread != -1) | |
3863 | printf_filtered (" (thread %d)", b->thread); | |
3864 | printf_filtered ("%s%s ", | |
3865 | ((b->enable_state == bp_disabled || | |
3866 | b->enable_state == bp_call_disabled) | |
3867 | ? " (disabled)" | |
3868 | : b->enable_state == bp_permanent | |
3869 | ? " (permanent)" | |
3870 | : ""), | |
3871 | (others > 1) ? "," | |
3872 | : ((others == 1) ? " and" : "")); | |
3873 | } | |
a3f17187 | 3874 | printf_filtered (_("also set at pc ")); |
ed49a04f | 3875 | fputs_filtered (paddress (pc), gdb_stdout); |
c906108c SS |
3876 | printf_filtered (".\n"); |
3877 | } | |
3878 | } | |
3879 | \f | |
3880 | /* Set the default place to put a breakpoint | |
3881 | for the `break' command with no arguments. */ | |
3882 | ||
3883 | void | |
fba45db2 KB |
3884 | set_default_breakpoint (int valid, CORE_ADDR addr, struct symtab *symtab, |
3885 | int line) | |
c906108c SS |
3886 | { |
3887 | default_breakpoint_valid = valid; | |
3888 | default_breakpoint_address = addr; | |
3889 | default_breakpoint_symtab = symtab; | |
3890 | default_breakpoint_line = line; | |
3891 | } | |
3892 | ||
e4f237da KB |
3893 | /* Return true iff it is meaningful to use the address member of |
3894 | BPT. For some breakpoint types, the address member is irrelevant | |
3895 | and it makes no sense to attempt to compare it to other addresses | |
3896 | (or use it for any other purpose either). | |
3897 | ||
3898 | More specifically, each of the following breakpoint types will always | |
3899 | have a zero valued address and we don't want check_duplicates() to mark | |
3900 | breakpoints of any of these types to be a duplicate of an actual | |
3901 | breakpoint at address zero: | |
3902 | ||
3903 | bp_watchpoint | |
3904 | bp_hardware_watchpoint | |
3905 | bp_read_watchpoint | |
3906 | bp_access_watchpoint | |
fe798b75 | 3907 | bp_catchpoint */ |
e4f237da KB |
3908 | |
3909 | static int | |
3910 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
3911 | { | |
3912 | enum bptype type = bpt->type; | |
3913 | ||
3914 | return (type != bp_watchpoint | |
3915 | && type != bp_hardware_watchpoint | |
3916 | && type != bp_read_watchpoint | |
3917 | && type != bp_access_watchpoint | |
fe798b75 | 3918 | && type != bp_catchpoint); |
e4f237da KB |
3919 | } |
3920 | ||
9f60f21b | 3921 | /* Rescan breakpoints at the same address and section as BPT, |
c906108c | 3922 | marking the first one as "first" and any others as "duplicates". |
c2c6d25f | 3923 | This is so that the bpt instruction is only inserted once. |
9f60f21b JB |
3924 | If we have a permanent breakpoint at the same place as BPT, make |
3925 | that one the official one, and the rest as duplicates. */ | |
c906108c SS |
3926 | |
3927 | static void | |
714835d5 | 3928 | check_duplicates_for (CORE_ADDR address, struct obj_section *section) |
c906108c | 3929 | { |
075f6582 | 3930 | struct bp_location *b; |
52f0bd74 | 3931 | int count = 0; |
075f6582 | 3932 | struct bp_location *perm_bp = 0; |
c906108c | 3933 | |
075f6582 DJ |
3934 | ALL_BP_LOCATIONS (b) |
3935 | if (b->owner->enable_state != bp_disabled | |
075f6582 | 3936 | && b->owner->enable_state != bp_call_disabled |
0d381245 VP |
3937 | && b->enabled |
3938 | && !b->shlib_disabled | |
075f6582 DJ |
3939 | && b->address == address /* address / overlay match */ |
3940 | && (!overlay_debugging || b->section == section) | |
3941 | && breakpoint_address_is_meaningful (b->owner)) | |
c5aa993b | 3942 | { |
c2c6d25f | 3943 | /* Have we found a permanent breakpoint? */ |
075f6582 | 3944 | if (b->owner->enable_state == bp_permanent) |
c2c6d25f JM |
3945 | { |
3946 | perm_bp = b; | |
3947 | break; | |
3948 | } | |
3949 | ||
c5aa993b | 3950 | count++; |
075f6582 | 3951 | b->duplicate = count > 1; |
c5aa993b | 3952 | } |
c2c6d25f JM |
3953 | |
3954 | /* If we found a permanent breakpoint at this address, go over the | |
3955 | list again and declare all the other breakpoints there to be the | |
3956 | duplicates. */ | |
3957 | if (perm_bp) | |
3958 | { | |
075f6582 | 3959 | perm_bp->duplicate = 0; |
c2c6d25f JM |
3960 | |
3961 | /* Permanent breakpoint should always be inserted. */ | |
075f6582 | 3962 | if (! perm_bp->inserted) |
8e65ff28 | 3963 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 AC |
3964 | _("allegedly permanent breakpoint is not " |
3965 | "actually inserted")); | |
c2c6d25f | 3966 | |
075f6582 | 3967 | ALL_BP_LOCATIONS (b) |
c2c6d25f JM |
3968 | if (b != perm_bp) |
3969 | { | |
075f6582 | 3970 | if (b->owner->enable_state != bp_disabled |
075f6582 | 3971 | && b->owner->enable_state != bp_call_disabled |
0d381245 | 3972 | && b->enabled && !b->shlib_disabled |
075f6582 DJ |
3973 | && b->address == address /* address / overlay match */ |
3974 | && (!overlay_debugging || b->section == section) | |
3975 | && breakpoint_address_is_meaningful (b->owner)) | |
3976 | { | |
3977 | if (b->inserted) | |
3978 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 AC |
3979 | _("another breakpoint was inserted on top of " |
3980 | "a permanent breakpoint")); | |
075f6582 DJ |
3981 | |
3982 | b->duplicate = 1; | |
3983 | } | |
c2c6d25f JM |
3984 | } |
3985 | } | |
c906108c SS |
3986 | } |
3987 | ||
0d381245 VP |
3988 | static void |
3989 | check_duplicates (struct breakpoint *bpt) | |
3990 | { | |
3991 | struct bp_location *bl = bpt->loc; | |
3992 | ||
3993 | if (! breakpoint_address_is_meaningful (bpt)) | |
3994 | return; | |
3995 | ||
3996 | for (; bl; bl = bl->next) | |
3997 | check_duplicates_for (bl->address, bl->section); | |
3998 | } | |
3999 | ||
76897487 KB |
4000 | static void |
4001 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
4002 | int bnum, int have_bnum) | |
4003 | { | |
4004 | char astr1[40]; | |
4005 | char astr2[40]; | |
4006 | ||
bb599908 PH |
4007 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
4008 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 4009 | if (have_bnum) |
8a3fe4f8 | 4010 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
4011 | bnum, astr1, astr2); |
4012 | else | |
8a3fe4f8 | 4013 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
4014 | } |
4015 | ||
4016 | /* Adjust a breakpoint's address to account for architectural constraints | |
4017 | on breakpoint placement. Return the adjusted address. Note: Very | |
4018 | few targets require this kind of adjustment. For most targets, | |
4019 | this function is simply the identity function. */ | |
4020 | ||
4021 | static CORE_ADDR | |
88f7da05 | 4022 | adjust_breakpoint_address (CORE_ADDR bpaddr, enum bptype bptype) |
76897487 KB |
4023 | { |
4024 | if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch)) | |
4025 | { | |
4026 | /* Very few targets need any kind of breakpoint adjustment. */ | |
4027 | return bpaddr; | |
4028 | } | |
88f7da05 KB |
4029 | else if (bptype == bp_watchpoint |
4030 | || bptype == bp_hardware_watchpoint | |
4031 | || bptype == bp_read_watchpoint | |
4032 | || bptype == bp_access_watchpoint | |
fe798b75 | 4033 | || bptype == bp_catchpoint) |
88f7da05 KB |
4034 | { |
4035 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
4036 | have their addresses modified. */ | |
4037 | return bpaddr; | |
4038 | } | |
76897487 KB |
4039 | else |
4040 | { | |
4041 | CORE_ADDR adjusted_bpaddr; | |
4042 | ||
4043 | /* Some targets have architectural constraints on the placement | |
4044 | of breakpoint instructions. Obtain the adjusted address. */ | |
4045 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (current_gdbarch, | |
4046 | bpaddr); | |
4047 | ||
4048 | /* An adjusted breakpoint address can significantly alter | |
4049 | a user's expectations. Print a warning if an adjustment | |
4050 | is required. */ | |
4051 | if (adjusted_bpaddr != bpaddr) | |
4052 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
4053 | ||
4054 | return adjusted_bpaddr; | |
4055 | } | |
4056 | } | |
4057 | ||
7cc221ef DJ |
4058 | /* Allocate a struct bp_location. */ |
4059 | ||
26bb91f3 | 4060 | static struct bp_location * |
39d61571 | 4061 | allocate_bp_location (struct breakpoint *bpt) |
7cc221ef DJ |
4062 | { |
4063 | struct bp_location *loc, *loc_p; | |
4064 | ||
4065 | loc = xmalloc (sizeof (struct bp_location)); | |
4066 | memset (loc, 0, sizeof (*loc)); | |
4067 | ||
e049a4b5 | 4068 | loc->owner = bpt; |
511a6cd4 | 4069 | loc->cond = NULL; |
0d381245 VP |
4070 | loc->shlib_disabled = 0; |
4071 | loc->enabled = 1; | |
e049a4b5 | 4072 | |
39d61571 | 4073 | switch (bpt->type) |
e049a4b5 DJ |
4074 | { |
4075 | case bp_breakpoint: | |
4076 | case bp_until: | |
4077 | case bp_finish: | |
4078 | case bp_longjmp: | |
4079 | case bp_longjmp_resume: | |
4080 | case bp_step_resume: | |
e049a4b5 DJ |
4081 | case bp_watchpoint_scope: |
4082 | case bp_call_dummy: | |
4083 | case bp_shlib_event: | |
4084 | case bp_thread_event: | |
4085 | case bp_overlay_event: | |
e049a4b5 DJ |
4086 | loc->loc_type = bp_loc_software_breakpoint; |
4087 | break; | |
4088 | case bp_hardware_breakpoint: | |
4089 | loc->loc_type = bp_loc_hardware_breakpoint; | |
4090 | break; | |
4091 | case bp_hardware_watchpoint: | |
4092 | case bp_read_watchpoint: | |
4093 | case bp_access_watchpoint: | |
4094 | loc->loc_type = bp_loc_hardware_watchpoint; | |
4095 | break; | |
4096 | case bp_watchpoint: | |
ce78b96d | 4097 | case bp_catchpoint: |
e049a4b5 DJ |
4098 | loc->loc_type = bp_loc_other; |
4099 | break; | |
4100 | default: | |
e2e0b3e5 | 4101 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
4102 | } |
4103 | ||
7cc221ef DJ |
4104 | return loc; |
4105 | } | |
4106 | ||
fe3f5fa8 VP |
4107 | static void free_bp_location (struct bp_location *loc) |
4108 | { | |
4109 | if (loc->cond) | |
4110 | xfree (loc->cond); | |
74960c60 VP |
4111 | |
4112 | if (loc->function_name) | |
4113 | xfree (loc->function_name); | |
4114 | ||
fe3f5fa8 VP |
4115 | xfree (loc); |
4116 | } | |
4117 | ||
0d381245 VP |
4118 | /* Helper to set_raw_breakpoint below. Creates a breakpoint |
4119 | that has type BPTYPE and has no locations as yet. */ | |
c906108c | 4120 | |
c40e75cd | 4121 | static struct breakpoint * |
0d381245 | 4122 | set_raw_breakpoint_without_location (enum bptype bptype) |
c906108c | 4123 | { |
52f0bd74 | 4124 | struct breakpoint *b, *b1; |
c906108c SS |
4125 | |
4126 | b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint)); | |
4127 | memset (b, 0, sizeof (*b)); | |
2219d63c | 4128 | |
4d28f7a8 | 4129 | b->type = bptype; |
c906108c SS |
4130 | b->language = current_language->la_language; |
4131 | b->input_radix = input_radix; | |
4132 | b->thread = -1; | |
b5de0fa7 | 4133 | b->enable_state = bp_enabled; |
c906108c SS |
4134 | b->next = 0; |
4135 | b->silent = 0; | |
4136 | b->ignore_count = 0; | |
4137 | b->commands = NULL; | |
818dd999 | 4138 | b->frame_id = null_frame_id; |
3a3e9ee3 | 4139 | b->forked_inferior_pid = null_ptid; |
c906108c | 4140 | b->exec_pathname = NULL; |
3086aeae | 4141 | b->ops = NULL; |
0d381245 | 4142 | b->condition_not_parsed = 0; |
c906108c SS |
4143 | |
4144 | /* Add this breakpoint to the end of the chain | |
4145 | so that a list of breakpoints will come out in order | |
4146 | of increasing numbers. */ | |
4147 | ||
4148 | b1 = breakpoint_chain; | |
4149 | if (b1 == 0) | |
4150 | breakpoint_chain = b; | |
4151 | else | |
4152 | { | |
4153 | while (b1->next) | |
4154 | b1 = b1->next; | |
4155 | b1->next = b; | |
4156 | } | |
0d381245 VP |
4157 | return b; |
4158 | } | |
4159 | ||
4160 | /* Initialize loc->function_name. */ | |
4161 | static void | |
4162 | set_breakpoint_location_function (struct bp_location *loc) | |
4163 | { | |
4164 | if (loc->owner->type == bp_breakpoint | |
4165 | || loc->owner->type == bp_hardware_breakpoint) | |
4166 | { | |
4167 | find_pc_partial_function (loc->address, &(loc->function_name), | |
4168 | NULL, NULL); | |
4169 | if (loc->function_name) | |
4170 | loc->function_name = xstrdup (loc->function_name); | |
4171 | } | |
4172 | } | |
4173 | ||
4174 | /* set_raw_breakpoint is a low level routine for allocating and | |
4175 | partially initializing a breakpoint of type BPTYPE. The newly | |
4176 | created breakpoint's address, section, source file name, and line | |
4177 | number are provided by SAL. The newly created and partially | |
4178 | initialized breakpoint is added to the breakpoint chain and | |
4179 | is also returned as the value of this function. | |
4180 | ||
4181 | It is expected that the caller will complete the initialization of | |
4182 | the newly created breakpoint struct as well as output any status | |
4183 | information regarding the creation of a new breakpoint. In | |
4184 | particular, set_raw_breakpoint does NOT set the breakpoint | |
4185 | number! Care should be taken to not allow an error to occur | |
4186 | prior to completing the initialization of the breakpoint. If this | |
4187 | should happen, a bogus breakpoint will be left on the chain. */ | |
4188 | ||
4189 | struct breakpoint * | |
4190 | set_raw_breakpoint (struct symtab_and_line sal, enum bptype bptype) | |
4191 | { | |
4192 | struct breakpoint *b = set_raw_breakpoint_without_location (bptype); | |
4193 | CORE_ADDR adjusted_address; | |
4194 | ||
4195 | /* Adjust the breakpoint's address prior to allocating a location. | |
4196 | Once we call allocate_bp_location(), that mostly uninitialized | |
4197 | location will be placed on the location chain. Adjustment of the | |
8defab1a | 4198 | breakpoint may cause target_read_memory() to be called and we do |
0d381245 VP |
4199 | not want its scan of the location chain to find a breakpoint and |
4200 | location that's only been partially initialized. */ | |
39d61571 | 4201 | adjusted_address = adjust_breakpoint_address (sal.pc, b->type); |
0d381245 | 4202 | |
39d61571 | 4203 | b->loc = allocate_bp_location (b); |
0d381245 VP |
4204 | b->loc->requested_address = sal.pc; |
4205 | b->loc->address = adjusted_address; | |
4206 | ||
4207 | if (sal.symtab == NULL) | |
4208 | b->source_file = NULL; | |
4209 | else | |
4210 | b->source_file = savestring (sal.symtab->filename, | |
4211 | strlen (sal.symtab->filename)); | |
4212 | b->loc->section = sal.section; | |
4213 | b->line_number = sal.line; | |
4214 | ||
4215 | set_breakpoint_location_function (b->loc); | |
c906108c | 4216 | |
c906108c SS |
4217 | breakpoints_changed (); |
4218 | ||
4219 | return b; | |
4220 | } | |
4221 | ||
c2c6d25f JM |
4222 | |
4223 | /* Note that the breakpoint object B describes a permanent breakpoint | |
4224 | instruction, hard-wired into the inferior's code. */ | |
4225 | void | |
4226 | make_breakpoint_permanent (struct breakpoint *b) | |
4227 | { | |
0d381245 | 4228 | struct bp_location *bl; |
b5de0fa7 | 4229 | b->enable_state = bp_permanent; |
c2c6d25f | 4230 | |
0d381245 VP |
4231 | /* By definition, permanent breakpoints are already present in the code. |
4232 | Mark all locations as inserted. For now, make_breakpoint_permanent | |
4233 | is called in just one place, so it's hard to say if it's reasonable | |
4234 | to have permanent breakpoint with multiple locations or not, | |
4235 | but it's easy to implmement. */ | |
4236 | for (bl = b->loc; bl; bl = bl->next) | |
4237 | bl->inserted = 1; | |
c2c6d25f JM |
4238 | } |
4239 | ||
1900040c MS |
4240 | static struct breakpoint * |
4241 | create_internal_breakpoint (CORE_ADDR address, enum bptype type) | |
4242 | { | |
4243 | static int internal_breakpoint_number = -1; | |
4244 | struct symtab_and_line sal; | |
4245 | struct breakpoint *b; | |
4246 | ||
fe39c653 | 4247 | init_sal (&sal); /* initialize to zeroes */ |
1900040c MS |
4248 | |
4249 | sal.pc = address; | |
4250 | sal.section = find_pc_overlay (sal.pc); | |
4251 | ||
4252 | b = set_raw_breakpoint (sal, type); | |
4253 | b->number = internal_breakpoint_number--; | |
4254 | b->disposition = disp_donttouch; | |
4255 | ||
4256 | return b; | |
4257 | } | |
4258 | ||
c906108c SS |
4259 | |
4260 | static void | |
fba45db2 | 4261 | create_longjmp_breakpoint (char *func_name) |
c906108c | 4262 | { |
1900040c | 4263 | struct minimal_symbol *m; |
c906108c | 4264 | |
611c83ae PA |
4265 | if ((m = lookup_minimal_symbol_text (func_name, NULL)) == NULL) |
4266 | return; | |
4267 | set_momentary_breakpoint_at_pc (SYMBOL_VALUE_ADDRESS (m), bp_longjmp); | |
b60e7edf | 4268 | update_global_location_list (1); |
c906108c SS |
4269 | } |
4270 | ||
53a5351d JM |
4271 | /* Call this routine when stepping and nexting to enable a breakpoint |
4272 | if we do a longjmp(). When we hit that breakpoint, call | |
c906108c SS |
4273 | set_longjmp_resume_breakpoint() to figure out where we are going. */ |
4274 | ||
4275 | void | |
611c83ae | 4276 | set_longjmp_breakpoint (void) |
c906108c | 4277 | { |
611c83ae | 4278 | if (gdbarch_get_longjmp_target_p (current_gdbarch)) |
c5aa993b | 4279 | { |
611c83ae PA |
4280 | create_longjmp_breakpoint ("longjmp"); |
4281 | create_longjmp_breakpoint ("_longjmp"); | |
4282 | create_longjmp_breakpoint ("siglongjmp"); | |
4283 | create_longjmp_breakpoint ("_siglongjmp"); | |
c5aa993b | 4284 | } |
c906108c SS |
4285 | } |
4286 | ||
611c83ae | 4287 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 4288 | void |
611c83ae | 4289 | delete_longjmp_breakpoint (int thread) |
c906108c | 4290 | { |
611c83ae | 4291 | struct breakpoint *b, *temp; |
c906108c | 4292 | |
611c83ae PA |
4293 | ALL_BREAKPOINTS_SAFE (b, temp) |
4294 | if (b->type == bp_longjmp) | |
4295 | { | |
4296 | if (b->thread == thread) | |
4297 | delete_breakpoint (b); | |
4298 | } | |
c906108c SS |
4299 | } |
4300 | ||
1900040c | 4301 | static void |
25db0f1b | 4302 | create_overlay_event_breakpoint_1 (char *func_name, struct objfile *objfile) |
1900040c MS |
4303 | { |
4304 | struct breakpoint *b; | |
4305 | struct minimal_symbol *m; | |
4306 | ||
25db0f1b | 4307 | if ((m = lookup_minimal_symbol_text (func_name, objfile)) == NULL) |
1900040c MS |
4308 | return; |
4309 | ||
4310 | b = create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m), | |
4311 | bp_overlay_event); | |
4312 | b->addr_string = xstrdup (func_name); | |
4313 | ||
4314 | if (overlay_debugging == ovly_auto) | |
c02f5703 MS |
4315 | { |
4316 | b->enable_state = bp_enabled; | |
4317 | overlay_events_enabled = 1; | |
4318 | } | |
1900040c | 4319 | else |
c02f5703 MS |
4320 | { |
4321 | b->enable_state = bp_disabled; | |
4322 | overlay_events_enabled = 0; | |
4323 | } | |
b60e7edf | 4324 | update_global_location_list (1); |
1900040c MS |
4325 | } |
4326 | ||
25db0f1b UW |
4327 | static void |
4328 | create_overlay_event_breakpoint (char *func_name) | |
4329 | { | |
4330 | struct objfile *objfile; | |
4331 | ALL_OBJFILES (objfile) | |
4332 | create_overlay_event_breakpoint_1 (func_name, objfile); | |
4333 | } | |
4334 | ||
1900040c MS |
4335 | void |
4336 | enable_overlay_breakpoints (void) | |
4337 | { | |
52f0bd74 | 4338 | struct breakpoint *b; |
1900040c MS |
4339 | |
4340 | ALL_BREAKPOINTS (b) | |
4341 | if (b->type == bp_overlay_event) | |
4342 | { | |
4343 | b->enable_state = bp_enabled; | |
b60e7edf | 4344 | update_global_location_list (1); |
c02f5703 | 4345 | overlay_events_enabled = 1; |
1900040c MS |
4346 | } |
4347 | } | |
4348 | ||
4349 | void | |
4350 | disable_overlay_breakpoints (void) | |
4351 | { | |
52f0bd74 | 4352 | struct breakpoint *b; |
1900040c MS |
4353 | |
4354 | ALL_BREAKPOINTS (b) | |
4355 | if (b->type == bp_overlay_event) | |
4356 | { | |
4357 | b->enable_state = bp_disabled; | |
b60e7edf | 4358 | update_global_location_list (0); |
c02f5703 | 4359 | overlay_events_enabled = 0; |
1900040c MS |
4360 | } |
4361 | } | |
4362 | ||
c4093a6a | 4363 | struct breakpoint * |
fba45db2 | 4364 | create_thread_event_breakpoint (CORE_ADDR address) |
c4093a6a JM |
4365 | { |
4366 | struct breakpoint *b; | |
c4093a6a | 4367 | |
1900040c | 4368 | b = create_internal_breakpoint (address, bp_thread_event); |
c4093a6a | 4369 | |
b5de0fa7 | 4370 | b->enable_state = bp_enabled; |
c4093a6a | 4371 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
b435e160 | 4372 | b->addr_string = xstrprintf ("*0x%s", paddr (b->loc->address)); |
c4093a6a | 4373 | |
b60e7edf | 4374 | update_global_location_list_nothrow (1); |
74960c60 | 4375 | |
c4093a6a JM |
4376 | return b; |
4377 | } | |
4378 | ||
4379 | void | |
4380 | remove_thread_event_breakpoints (void) | |
4381 | { | |
4382 | struct breakpoint *b, *temp; | |
4383 | ||
4384 | ALL_BREAKPOINTS_SAFE (b, temp) | |
4385 | if (b->type == bp_thread_event) | |
4386 | delete_breakpoint (b); | |
4387 | } | |
4388 | ||
0101ce28 JJ |
4389 | struct captured_parse_breakpoint_args |
4390 | { | |
4391 | char **arg_p; | |
4392 | struct symtabs_and_lines *sals_p; | |
4393 | char ***addr_string_p; | |
4394 | int *not_found_ptr; | |
4395 | }; | |
4396 | ||
4397 | struct lang_and_radix | |
4398 | { | |
4399 | enum language lang; | |
4400 | int radix; | |
4401 | }; | |
4402 | ||
0101ce28 | 4403 | |
cae688ec JJ |
4404 | void |
4405 | remove_solib_event_breakpoints (void) | |
4406 | { | |
4407 | struct breakpoint *b, *temp; | |
4408 | ||
4409 | ALL_BREAKPOINTS_SAFE (b, temp) | |
4410 | if (b->type == bp_shlib_event) | |
4411 | delete_breakpoint (b); | |
4412 | } | |
4413 | ||
4414 | struct breakpoint * | |
4415 | create_solib_event_breakpoint (CORE_ADDR address) | |
4416 | { | |
4417 | struct breakpoint *b; | |
4418 | ||
4419 | b = create_internal_breakpoint (address, bp_shlib_event); | |
b60e7edf | 4420 | update_global_location_list_nothrow (1); |
cae688ec JJ |
4421 | return b; |
4422 | } | |
4423 | ||
4424 | /* Disable any breakpoints that are on code in shared libraries. Only | |
4425 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
4426 | ||
4427 | void | |
cb851954 | 4428 | disable_breakpoints_in_shlibs (void) |
cae688ec | 4429 | { |
0d381245 | 4430 | struct bp_location *loc; |
cae688ec JJ |
4431 | int disabled_shlib_breaks = 0; |
4432 | ||
0d381245 | 4433 | ALL_BP_LOCATIONS (loc) |
cae688ec | 4434 | { |
0d381245 VP |
4435 | struct breakpoint *b = loc->owner; |
4436 | /* We apply the check to all breakpoints, including disabled | |
4437 | for those with loc->duplicate set. This is so that when breakpoint | |
4438 | becomes enabled, or the duplicate is removed, gdb will try to insert | |
4439 | all breakpoints. If we don't set shlib_disabled here, we'll try | |
4440 | to insert those breakpoints and fail. */ | |
a77053c2 | 4441 | if (((b->type == bp_breakpoint) || (b->type == bp_hardware_breakpoint)) |
0d381245 | 4442 | && !loc->shlib_disabled |
a77053c2 | 4443 | #ifdef PC_SOLIB |
0d381245 | 4444 | && PC_SOLIB (loc->address) |
a77053c2 | 4445 | #else |
0d381245 | 4446 | && solib_address (loc->address) |
a77053c2 MK |
4447 | #endif |
4448 | ) | |
0d381245 VP |
4449 | { |
4450 | loc->shlib_disabled = 1; | |
4451 | } | |
cae688ec JJ |
4452 | } |
4453 | } | |
4454 | ||
84acb35a JJ |
4455 | /* Disable any breakpoints that are in in an unloaded shared library. Only |
4456 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
4457 | ||
75149521 | 4458 | static void |
84acb35a JJ |
4459 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
4460 | { | |
0d381245 | 4461 | struct bp_location *loc; |
84acb35a JJ |
4462 | int disabled_shlib_breaks = 0; |
4463 | ||
0d381245 | 4464 | ALL_BP_LOCATIONS (loc) |
84acb35a | 4465 | { |
0d381245 VP |
4466 | struct breakpoint *b = loc->owner; |
4467 | if ((loc->loc_type == bp_loc_hardware_breakpoint | |
4468 | || loc->loc_type == bp_loc_software_breakpoint) | |
4469 | && !loc->shlib_disabled) | |
84acb35a | 4470 | { |
a77053c2 | 4471 | #ifdef PC_SOLIB |
0d381245 | 4472 | char *so_name = PC_SOLIB (loc->address); |
a77053c2 | 4473 | #else |
0d381245 | 4474 | char *so_name = solib_address (loc->address); |
a77053c2 MK |
4475 | #endif |
4476 | if (so_name && !strcmp (so_name, solib->so_name)) | |
84acb35a | 4477 | { |
0d381245 | 4478 | loc->shlib_disabled = 1; |
84acb35a JJ |
4479 | /* At this point, we cannot rely on remove_breakpoint |
4480 | succeeding so we must mark the breakpoint as not inserted | |
4481 | to prevent future errors occurring in remove_breakpoints. */ | |
0d381245 | 4482 | loc->inserted = 0; |
84acb35a JJ |
4483 | if (!disabled_shlib_breaks) |
4484 | { | |
4485 | target_terminal_ours_for_output (); | |
8a3fe4f8 | 4486 | warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""), |
84acb35a JJ |
4487 | so_name); |
4488 | } | |
4489 | disabled_shlib_breaks = 1; | |
4490 | } | |
4491 | } | |
4492 | } | |
84acb35a JJ |
4493 | } |
4494 | ||
ce78b96d JB |
4495 | /* FORK & VFORK catchpoints. */ |
4496 | ||
4497 | /* Implement the "insert" breakpoint_ops method for fork catchpoints. */ | |
4498 | ||
c906108c | 4499 | static void |
ce78b96d JB |
4500 | insert_catch_fork (struct breakpoint *b) |
4501 | { | |
4502 | target_insert_fork_catchpoint (PIDGET (inferior_ptid)); | |
4503 | } | |
4504 | ||
4505 | /* Implement the "remove" breakpoint_ops method for fork catchpoints. */ | |
4506 | ||
4507 | static int | |
4508 | remove_catch_fork (struct breakpoint *b) | |
4509 | { | |
4510 | return target_remove_fork_catchpoint (PIDGET (inferior_ptid)); | |
4511 | } | |
4512 | ||
4513 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
4514 | catchpoints. */ | |
4515 | ||
4516 | static int | |
4517 | breakpoint_hit_catch_fork (struct breakpoint *b) | |
4518 | { | |
4519 | return inferior_has_forked (inferior_ptid, &b->forked_inferior_pid); | |
4520 | } | |
4521 | ||
4522 | /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */ | |
4523 | ||
4524 | static enum print_stop_action | |
4525 | print_it_catch_fork (struct breakpoint *b) | |
4526 | { | |
4527 | annotate_catchpoint (b->number); | |
4528 | printf_filtered (_("\nCatchpoint %d (forked process %d), "), | |
4529 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
4530 | return PRINT_SRC_AND_LOC; | |
4531 | } | |
4532 | ||
4533 | /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */ | |
4534 | ||
4535 | static void | |
4536 | print_one_catch_fork (struct breakpoint *b, CORE_ADDR *last_addr) | |
4537 | { | |
79a45b7d TT |
4538 | struct value_print_options opts; |
4539 | ||
4540 | get_user_print_options (&opts); | |
4541 | ||
ce78b96d JB |
4542 | /* Field 4, the address, is omitted (which makes the columns |
4543 | not line up too nicely with the headers, but the effect | |
4544 | is relatively readable). */ | |
79a45b7d | 4545 | if (opts.addressprint) |
ce78b96d JB |
4546 | ui_out_field_skip (uiout, "addr"); |
4547 | annotate_field (5); | |
4548 | ui_out_text (uiout, "fork"); | |
4549 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
4550 | { | |
4551 | ui_out_text (uiout, ", process "); | |
4552 | ui_out_field_int (uiout, "what", | |
4553 | ptid_get_pid (b->forked_inferior_pid)); | |
4554 | ui_out_spaces (uiout, 1); | |
4555 | } | |
4556 | } | |
4557 | ||
4558 | /* Implement the "print_mention" breakpoint_ops method for fork | |
4559 | catchpoints. */ | |
4560 | ||
4561 | static void | |
4562 | print_mention_catch_fork (struct breakpoint *b) | |
4563 | { | |
4564 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
4565 | } | |
4566 | ||
4567 | /* The breakpoint_ops structure to be used in fork catchpoints. */ | |
4568 | ||
4569 | static struct breakpoint_ops catch_fork_breakpoint_ops = | |
4570 | { | |
4571 | insert_catch_fork, | |
4572 | remove_catch_fork, | |
4573 | breakpoint_hit_catch_fork, | |
4574 | print_it_catch_fork, | |
4575 | print_one_catch_fork, | |
4576 | print_mention_catch_fork | |
4577 | }; | |
4578 | ||
4579 | /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */ | |
4580 | ||
4581 | static void | |
4582 | insert_catch_vfork (struct breakpoint *b) | |
4583 | { | |
4584 | target_insert_vfork_catchpoint (PIDGET (inferior_ptid)); | |
4585 | } | |
4586 | ||
4587 | /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */ | |
4588 | ||
4589 | static int | |
4590 | remove_catch_vfork (struct breakpoint *b) | |
4591 | { | |
4592 | return target_remove_vfork_catchpoint (PIDGET (inferior_ptid)); | |
4593 | } | |
4594 | ||
4595 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
4596 | catchpoints. */ | |
4597 | ||
4598 | static int | |
4599 | breakpoint_hit_catch_vfork (struct breakpoint *b) | |
4600 | { | |
4601 | return inferior_has_vforked (inferior_ptid, &b->forked_inferior_pid); | |
4602 | } | |
4603 | ||
4604 | /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */ | |
4605 | ||
4606 | static enum print_stop_action | |
4607 | print_it_catch_vfork (struct breakpoint *b) | |
4608 | { | |
4609 | annotate_catchpoint (b->number); | |
4610 | printf_filtered (_("\nCatchpoint %d (vforked process %d), "), | |
4611 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
4612 | return PRINT_SRC_AND_LOC; | |
4613 | } | |
4614 | ||
4615 | /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */ | |
4616 | ||
4617 | static void | |
4618 | print_one_catch_vfork (struct breakpoint *b, CORE_ADDR *last_addr) | |
4619 | { | |
79a45b7d TT |
4620 | struct value_print_options opts; |
4621 | ||
4622 | get_user_print_options (&opts); | |
ce78b96d JB |
4623 | /* Field 4, the address, is omitted (which makes the columns |
4624 | not line up too nicely with the headers, but the effect | |
4625 | is relatively readable). */ | |
79a45b7d | 4626 | if (opts.addressprint) |
ce78b96d JB |
4627 | ui_out_field_skip (uiout, "addr"); |
4628 | annotate_field (5); | |
4629 | ui_out_text (uiout, "vfork"); | |
4630 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
4631 | { | |
4632 | ui_out_text (uiout, ", process "); | |
4633 | ui_out_field_int (uiout, "what", | |
4634 | ptid_get_pid (b->forked_inferior_pid)); | |
4635 | ui_out_spaces (uiout, 1); | |
4636 | } | |
4637 | } | |
4638 | ||
4639 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
4640 | catchpoints. */ | |
4641 | ||
4642 | static void | |
4643 | print_mention_catch_vfork (struct breakpoint *b) | |
4644 | { | |
4645 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
4646 | } | |
4647 | ||
4648 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ | |
4649 | ||
4650 | static struct breakpoint_ops catch_vfork_breakpoint_ops = | |
4651 | { | |
4652 | insert_catch_vfork, | |
4653 | remove_catch_vfork, | |
4654 | breakpoint_hit_catch_vfork, | |
4655 | print_it_catch_vfork, | |
4656 | print_one_catch_vfork, | |
4657 | print_mention_catch_vfork | |
4658 | }; | |
4659 | ||
4660 | /* Create a new breakpoint of the bp_catchpoint kind and return it. | |
4661 | ||
4662 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
4663 | If COND_STRING is not NULL, then store it in the breakpoint. | |
4664 | OPS, if not NULL, is the breakpoint_ops structure associated | |
4665 | to the catchpoint. */ | |
4666 | ||
4667 | static struct breakpoint * | |
4668 | create_catchpoint (int tempflag, char *cond_string, | |
4669 | struct breakpoint_ops *ops) | |
c906108c | 4670 | { |
c5aa993b JM |
4671 | struct symtab_and_line sal; |
4672 | struct breakpoint *b; | |
c5aa993b | 4673 | |
fe39c653 | 4674 | init_sal (&sal); |
c906108c SS |
4675 | sal.pc = 0; |
4676 | sal.symtab = NULL; | |
4677 | sal.line = 0; | |
c5aa993b | 4678 | |
ce78b96d | 4679 | b = set_raw_breakpoint (sal, bp_catchpoint); |
c906108c SS |
4680 | set_breakpoint_count (breakpoint_count + 1); |
4681 | b->number = breakpoint_count; | |
ce78b96d | 4682 | |
53a5351d JM |
4683 | b->cond_string = (cond_string == NULL) ? |
4684 | NULL : savestring (cond_string, strlen (cond_string)); | |
ce78b96d | 4685 | b->thread = -1; |
c906108c | 4686 | b->addr_string = NULL; |
b5de0fa7 EZ |
4687 | b->enable_state = bp_enabled; |
4688 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
ce78b96d | 4689 | b->ops = ops; |
c5aa993b | 4690 | |
c906108c | 4691 | mention (b); |
ce78b96d | 4692 | update_global_location_list (1); |
c906108c | 4693 | |
ce78b96d | 4694 | return b; |
c906108c | 4695 | } |
c5aa993b | 4696 | |
9b70b993 | 4697 | static void |
ce78b96d JB |
4698 | create_fork_vfork_event_catchpoint (int tempflag, char *cond_string, |
4699 | struct breakpoint_ops *ops) | |
c906108c | 4700 | { |
ce78b96d JB |
4701 | struct breakpoint *b = create_catchpoint (tempflag, cond_string, ops); |
4702 | ||
4703 | /* FIXME: We should put this information in a breakpoint private data | |
4704 | area. */ | |
4705 | b->forked_inferior_pid = null_ptid; | |
c906108c SS |
4706 | } |
4707 | ||
fe798b75 JB |
4708 | /* Exec catchpoints. */ |
4709 | ||
9b70b993 | 4710 | static void |
fe798b75 | 4711 | insert_catch_exec (struct breakpoint *b) |
c906108c | 4712 | { |
fe798b75 JB |
4713 | target_insert_exec_catchpoint (PIDGET (inferior_ptid)); |
4714 | } | |
c906108c | 4715 | |
fe798b75 JB |
4716 | static int |
4717 | remove_catch_exec (struct breakpoint *b) | |
4718 | { | |
4719 | return target_remove_exec_catchpoint (PIDGET (inferior_ptid)); | |
4720 | } | |
c906108c | 4721 | |
fe798b75 JB |
4722 | static int |
4723 | breakpoint_hit_catch_exec (struct breakpoint *b) | |
4724 | { | |
4725 | return inferior_has_execd (inferior_ptid, &b->exec_pathname); | |
4726 | } | |
c906108c | 4727 | |
fe798b75 JB |
4728 | static enum print_stop_action |
4729 | print_it_catch_exec (struct breakpoint *b) | |
4730 | { | |
4731 | annotate_catchpoint (b->number); | |
4732 | printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number, | |
4733 | b->exec_pathname); | |
4734 | return PRINT_SRC_AND_LOC; | |
c906108c SS |
4735 | } |
4736 | ||
fe798b75 JB |
4737 | static void |
4738 | print_one_catch_exec (struct breakpoint *b, CORE_ADDR *last_addr) | |
4739 | { | |
4740 | struct value_print_options opts; | |
4741 | ||
4742 | get_user_print_options (&opts); | |
4743 | ||
4744 | /* Field 4, the address, is omitted (which makes the columns | |
4745 | not line up too nicely with the headers, but the effect | |
4746 | is relatively readable). */ | |
4747 | if (opts.addressprint) | |
4748 | ui_out_field_skip (uiout, "addr"); | |
4749 | annotate_field (5); | |
4750 | ui_out_text (uiout, "exec"); | |
4751 | if (b->exec_pathname != NULL) | |
4752 | { | |
4753 | ui_out_text (uiout, ", program \""); | |
4754 | ui_out_field_string (uiout, "what", b->exec_pathname); | |
4755 | ui_out_text (uiout, "\" "); | |
4756 | } | |
4757 | } | |
4758 | ||
4759 | static void | |
4760 | print_mention_catch_exec (struct breakpoint *b) | |
4761 | { | |
4762 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
4763 | } | |
4764 | ||
4765 | static struct breakpoint_ops catch_exec_breakpoint_ops = | |
4766 | { | |
4767 | insert_catch_exec, | |
4768 | remove_catch_exec, | |
4769 | breakpoint_hit_catch_exec, | |
4770 | print_it_catch_exec, | |
4771 | print_one_catch_exec, | |
4772 | print_mention_catch_exec | |
4773 | }; | |
4774 | ||
c906108c | 4775 | static int |
fba45db2 | 4776 | hw_breakpoint_used_count (void) |
c906108c | 4777 | { |
52f0bd74 | 4778 | struct breakpoint *b; |
c906108c SS |
4779 | int i = 0; |
4780 | ||
4781 | ALL_BREAKPOINTS (b) | |
c5aa993b | 4782 | { |
d6b74ac4 | 4783 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
c5aa993b JM |
4784 | i++; |
4785 | } | |
c906108c SS |
4786 | |
4787 | return i; | |
4788 | } | |
4789 | ||
4790 | static int | |
fba45db2 | 4791 | hw_watchpoint_used_count (enum bptype type, int *other_type_used) |
c906108c | 4792 | { |
52f0bd74 | 4793 | struct breakpoint *b; |
c906108c SS |
4794 | int i = 0; |
4795 | ||
4796 | *other_type_used = 0; | |
4797 | ALL_BREAKPOINTS (b) | |
c5aa993b | 4798 | { |
468d015d | 4799 | if (breakpoint_enabled (b)) |
c5aa993b JM |
4800 | { |
4801 | if (b->type == type) | |
4802 | i++; | |
4803 | else if ((b->type == bp_hardware_watchpoint || | |
4804 | b->type == bp_read_watchpoint || | |
468d015d | 4805 | b->type == bp_access_watchpoint)) |
c5aa993b JM |
4806 | *other_type_used = 1; |
4807 | } | |
4808 | } | |
c906108c SS |
4809 | return i; |
4810 | } | |
4811 | ||
c906108c | 4812 | void |
fba45db2 | 4813 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 4814 | { |
c5aa993b | 4815 | struct breakpoint *b; |
c906108c SS |
4816 | |
4817 | ALL_BREAKPOINTS (b) | |
c5aa993b JM |
4818 | { |
4819 | if (((b->type == bp_watchpoint) | |
4820 | || (b->type == bp_hardware_watchpoint) | |
4821 | || (b->type == bp_read_watchpoint) | |
dfdfb3ca | 4822 | || (b->type == bp_access_watchpoint)) |
468d015d | 4823 | && breakpoint_enabled (b)) |
c5aa993b | 4824 | { |
b5de0fa7 | 4825 | b->enable_state = bp_call_disabled; |
b60e7edf | 4826 | update_global_location_list (0); |
c5aa993b JM |
4827 | } |
4828 | } | |
c906108c SS |
4829 | } |
4830 | ||
4831 | void | |
fba45db2 | 4832 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 4833 | { |
c5aa993b | 4834 | struct breakpoint *b; |
c906108c SS |
4835 | |
4836 | ALL_BREAKPOINTS (b) | |
c5aa993b JM |
4837 | { |
4838 | if (((b->type == bp_watchpoint) | |
4839 | || (b->type == bp_hardware_watchpoint) | |
4840 | || (b->type == bp_read_watchpoint) | |
dfdfb3ca | 4841 | || (b->type == bp_access_watchpoint)) |
b5de0fa7 | 4842 | && (b->enable_state == bp_call_disabled)) |
c5aa993b | 4843 | { |
b5de0fa7 | 4844 | b->enable_state = bp_enabled; |
b60e7edf | 4845 | update_global_location_list (1); |
c5aa993b JM |
4846 | } |
4847 | } | |
c906108c SS |
4848 | } |
4849 | ||
4850 | ||
4851 | /* Set a breakpoint that will evaporate an end of command | |
4852 | at address specified by SAL. | |
4853 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
4854 | ||
4855 | struct breakpoint * | |
818dd999 | 4856 | set_momentary_breakpoint (struct symtab_and_line sal, struct frame_id frame_id, |
fba45db2 | 4857 | enum bptype type) |
c906108c | 4858 | { |
52f0bd74 | 4859 | struct breakpoint *b; |
4d28f7a8 | 4860 | b = set_raw_breakpoint (sal, type); |
b5de0fa7 EZ |
4861 | b->enable_state = bp_enabled; |
4862 | b->disposition = disp_donttouch; | |
818dd999 | 4863 | b->frame_id = frame_id; |
c906108c SS |
4864 | |
4865 | /* If we're debugging a multi-threaded program, then we | |
4866 | want momentary breakpoints to be active in only a | |
4867 | single thread of control. */ | |
39f77062 KB |
4868 | if (in_thread_list (inferior_ptid)) |
4869 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 4870 | |
b60e7edf | 4871 | update_global_location_list_nothrow (1); |
74960c60 | 4872 | |
c906108c SS |
4873 | return b; |
4874 | } | |
611c83ae PA |
4875 | |
4876 | struct breakpoint * | |
4877 | set_momentary_breakpoint_at_pc (CORE_ADDR pc, enum bptype type) | |
4878 | { | |
4879 | struct symtab_and_line sal; | |
4880 | ||
4881 | sal = find_pc_line (pc, 0); | |
4882 | sal.pc = pc; | |
4883 | sal.section = find_pc_overlay (pc); | |
4884 | sal.explicit_pc = 1; | |
4885 | ||
4886 | return set_momentary_breakpoint (sal, null_frame_id, type); | |
4887 | } | |
c906108c | 4888 | \f |
c5aa993b | 4889 | |
c906108c SS |
4890 | /* Tell the user we have just set a breakpoint B. */ |
4891 | ||
4892 | static void | |
fba45db2 | 4893 | mention (struct breakpoint *b) |
c906108c SS |
4894 | { |
4895 | int say_where = 0; | |
3b31d625 | 4896 | struct cleanup *old_chain, *ui_out_chain; |
8b93c638 | 4897 | struct ui_stream *stb; |
79a45b7d TT |
4898 | struct value_print_options opts; |
4899 | ||
4900 | get_user_print_options (&opts); | |
8b93c638 JM |
4901 | |
4902 | stb = ui_out_stream_new (uiout); | |
b02eeafb | 4903 | old_chain = make_cleanup_ui_out_stream_delete (stb); |
c906108c | 4904 | |
9a4105ab AC |
4905 | /* FIXME: This is misplaced; mention() is called by things (like |
4906 | hitting a watchpoint) other than breakpoint creation. It should | |
4907 | be possible to clean this up and at the same time replace the | |
7f4b89d1 | 4908 | random calls to breakpoint_changed with this hook. */ |
383f836e | 4909 | observer_notify_breakpoint_created (b->number); |
c906108c | 4910 | |
3086aeae DJ |
4911 | if (b->ops != NULL && b->ops->print_mention != NULL) |
4912 | b->ops->print_mention (b); | |
4913 | else | |
4914 | switch (b->type) | |
4915 | { | |
4916 | case bp_none: | |
a3f17187 | 4917 | printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b->number); |
3086aeae DJ |
4918 | break; |
4919 | case bp_watchpoint: | |
4920 | ui_out_text (uiout, "Watchpoint "); | |
4921 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
4922 | ui_out_field_int (uiout, "number", b->number); | |
4923 | ui_out_text (uiout, ": "); | |
4924 | print_expression (b->exp, stb->stream); | |
4925 | ui_out_field_stream (uiout, "exp", stb); | |
4926 | do_cleanups (ui_out_chain); | |
4927 | break; | |
4928 | case bp_hardware_watchpoint: | |
4929 | ui_out_text (uiout, "Hardware watchpoint "); | |
4930 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
4931 | ui_out_field_int (uiout, "number", b->number); | |
4932 | ui_out_text (uiout, ": "); | |
4933 | print_expression (b->exp, stb->stream); | |
4934 | ui_out_field_stream (uiout, "exp", stb); | |
4935 | do_cleanups (ui_out_chain); | |
4936 | break; | |
4937 | case bp_read_watchpoint: | |
4938 | ui_out_text (uiout, "Hardware read watchpoint "); | |
4939 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
4940 | ui_out_field_int (uiout, "number", b->number); | |
4941 | ui_out_text (uiout, ": "); | |
4942 | print_expression (b->exp, stb->stream); | |
4943 | ui_out_field_stream (uiout, "exp", stb); | |
4944 | do_cleanups (ui_out_chain); | |
4945 | break; | |
4946 | case bp_access_watchpoint: | |
4947 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
4948 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
4949 | ui_out_field_int (uiout, "number", b->number); | |
4950 | ui_out_text (uiout, ": "); | |
4951 | print_expression (b->exp, stb->stream); | |
4952 | ui_out_field_stream (uiout, "exp", stb); | |
4953 | do_cleanups (ui_out_chain); | |
4954 | break; | |
4955 | case bp_breakpoint: | |
4956 | if (ui_out_is_mi_like_p (uiout)) | |
4957 | { | |
4958 | say_where = 0; | |
4959 | break; | |
4960 | } | |
2cec12e5 AR |
4961 | if (b->disposition == disp_del) |
4962 | printf_filtered (_("Temporary breakpoint")); | |
4963 | else | |
4964 | printf_filtered (_("Breakpoint")); | |
4965 | printf_filtered (_(" %d"), b->number); | |
3086aeae DJ |
4966 | say_where = 1; |
4967 | break; | |
4968 | case bp_hardware_breakpoint: | |
4969 | if (ui_out_is_mi_like_p (uiout)) | |
4970 | { | |
4971 | say_where = 0; | |
4972 | break; | |
4973 | } | |
a3f17187 | 4974 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); |
3086aeae DJ |
4975 | say_where = 1; |
4976 | break; | |
3086aeae DJ |
4977 | |
4978 | case bp_until: | |
4979 | case bp_finish: | |
4980 | case bp_longjmp: | |
4981 | case bp_longjmp_resume: | |
4982 | case bp_step_resume: | |
3086aeae DJ |
4983 | case bp_call_dummy: |
4984 | case bp_watchpoint_scope: | |
4985 | case bp_shlib_event: | |
4986 | case bp_thread_event: | |
4987 | case bp_overlay_event: | |
4988 | break; | |
4989 | } | |
c906108c | 4990 | |
c906108c SS |
4991 | if (say_where) |
4992 | { | |
a3f17187 AC |
4993 | /* i18n: cagney/2005-02-11: Below needs to be merged into a |
4994 | single string. */ | |
0d381245 | 4995 | if (b->loc == NULL) |
c906108c | 4996 | { |
a3f17187 | 4997 | printf_filtered (_(" (%s) pending."), b->addr_string); |
0101ce28 JJ |
4998 | } |
4999 | else | |
5000 | { | |
79a45b7d | 5001 | if (opts.addressprint || b->source_file == NULL) |
0101ce28 JJ |
5002 | { |
5003 | printf_filtered (" at "); | |
ed49a04f | 5004 | fputs_filtered (paddress (b->loc->address), gdb_stdout); |
0101ce28 JJ |
5005 | } |
5006 | if (b->source_file) | |
5007 | printf_filtered (": file %s, line %d.", | |
5008 | b->source_file, b->line_number); | |
0d381245 VP |
5009 | |
5010 | if (b->loc->next) | |
5011 | { | |
5012 | struct bp_location *loc = b->loc; | |
5013 | int n = 0; | |
5014 | for (; loc; loc = loc->next) | |
5015 | ++n; | |
5016 | printf_filtered (" (%d locations)", n); | |
5017 | } | |
5018 | ||
c906108c | 5019 | } |
c906108c | 5020 | } |
8b93c638 | 5021 | do_cleanups (old_chain); |
9dc5e2a9 | 5022 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 5023 | return; |
c906108c SS |
5024 | printf_filtered ("\n"); |
5025 | } | |
c906108c | 5026 | \f |
c5aa993b | 5027 | |
0d381245 | 5028 | static struct bp_location * |
39d61571 | 5029 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
5030 | const struct symtab_and_line *sal) |
5031 | { | |
5032 | struct bp_location *loc, **tmp; | |
5033 | ||
39d61571 | 5034 | loc = allocate_bp_location (b); |
0d381245 VP |
5035 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
5036 | ; | |
5037 | *tmp = loc; | |
5038 | loc->requested_address = sal->pc; | |
39d61571 | 5039 | loc->address = adjust_breakpoint_address (loc->requested_address, b->type); |
0d381245 VP |
5040 | loc->section = sal->section; |
5041 | ||
5042 | set_breakpoint_location_function (loc); | |
5043 | return loc; | |
5044 | } | |
514f746b AR |
5045 | \f |
5046 | ||
5047 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
5048 | return 0 otherwise. */ | |
5049 | ||
5050 | static int | |
5051 | bp_loc_is_permanent (struct bp_location *loc) | |
5052 | { | |
5053 | int len; | |
5054 | CORE_ADDR addr; | |
5055 | const gdb_byte *brk; | |
5056 | gdb_byte *target_mem; | |
939c61fa JK |
5057 | struct cleanup *cleanup; |
5058 | int retval = 0; | |
514f746b AR |
5059 | |
5060 | gdb_assert (loc != NULL); | |
5061 | ||
5062 | addr = loc->address; | |
5063 | brk = gdbarch_breakpoint_from_pc (current_gdbarch, &addr, &len); | |
5064 | ||
939c61fa JK |
5065 | /* Software breakpoints unsupported? */ |
5066 | if (brk == NULL) | |
5067 | return 0; | |
5068 | ||
514f746b AR |
5069 | target_mem = alloca (len); |
5070 | ||
939c61fa JK |
5071 | /* Enable the automatic memory restoration from breakpoints while |
5072 | we read the memory. Otherwise we could say about our temporary | |
5073 | breakpoints they are permanent. */ | |
5074 | cleanup = make_show_memory_breakpoints_cleanup (0); | |
5075 | ||
514f746b AR |
5076 | if (target_read_memory (loc->address, target_mem, len) == 0 |
5077 | && memcmp (target_mem, brk, len) == 0) | |
939c61fa | 5078 | retval = 1; |
514f746b | 5079 | |
939c61fa JK |
5080 | do_cleanups (cleanup); |
5081 | ||
5082 | return retval; | |
514f746b AR |
5083 | } |
5084 | ||
5085 | ||
c3f6f71d | 5086 | |
018d34a4 VP |
5087 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
5088 | as textual description of the location, and COND_STRING | |
db107f19 | 5089 | as condition expression. */ |
018d34a4 VP |
5090 | |
5091 | static void | |
0d381245 | 5092 | create_breakpoint (struct symtabs_and_lines sals, char *addr_string, |
018d34a4 VP |
5093 | char *cond_string, |
5094 | enum bptype type, enum bpdisp disposition, | |
604133b5 AR |
5095 | int thread, int ignore_count, |
5096 | struct breakpoint_ops *ops, int from_tty) | |
018d34a4 | 5097 | { |
0d381245 VP |
5098 | struct breakpoint *b = NULL; |
5099 | int i; | |
018d34a4 VP |
5100 | |
5101 | if (type == bp_hardware_breakpoint) | |
5102 | { | |
5103 | int i = hw_breakpoint_used_count (); | |
5104 | int target_resources_ok = | |
5105 | TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint, | |
5106 | i + 1, 0); | |
5107 | if (target_resources_ok == 0) | |
5108 | error (_("No hardware breakpoint support in the target.")); | |
5109 | else if (target_resources_ok < 0) | |
5110 | error (_("Hardware breakpoints used exceeds limit.")); | |
5111 | } | |
5112 | ||
0d381245 VP |
5113 | for (i = 0; i < sals.nelts; ++i) |
5114 | { | |
5115 | struct symtab_and_line sal = sals.sals[i]; | |
5116 | struct bp_location *loc; | |
5117 | ||
5118 | if (from_tty) | |
5119 | describe_other_breakpoints (sal.pc, sal.section, thread); | |
5120 | ||
5121 | if (i == 0) | |
5122 | { | |
5123 | b = set_raw_breakpoint (sal, type); | |
5124 | set_breakpoint_count (breakpoint_count + 1); | |
5125 | b->number = breakpoint_count; | |
5126 | b->thread = thread; | |
018d34a4 | 5127 | |
0d381245 VP |
5128 | b->cond_string = cond_string; |
5129 | b->ignore_count = ignore_count; | |
5130 | b->enable_state = bp_enabled; | |
5131 | b->disposition = disposition; | |
018d34a4 | 5132 | |
0d381245 VP |
5133 | loc = b->loc; |
5134 | } | |
5135 | else | |
018d34a4 | 5136 | { |
39d61571 | 5137 | loc = add_location_to_breakpoint (b, &sal); |
0d381245 VP |
5138 | } |
5139 | ||
514f746b AR |
5140 | if (bp_loc_is_permanent (loc)) |
5141 | make_breakpoint_permanent (b); | |
5142 | ||
0d381245 VP |
5143 | if (b->cond_string) |
5144 | { | |
5145 | char *arg = b->cond_string; | |
d32a6982 | 5146 | loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0); |
0d381245 | 5147 | if (*arg) |
db107f19 | 5148 | error (_("Garbage %s follows condition"), arg); |
018d34a4 | 5149 | } |
0d381245 | 5150 | } |
018d34a4 VP |
5151 | |
5152 | if (addr_string) | |
5153 | b->addr_string = addr_string; | |
5154 | else | |
5155 | /* addr_string has to be used or breakpoint_re_set will delete | |
5156 | me. */ | |
5157 | b->addr_string = xstrprintf ("*0x%s", paddr (b->loc->address)); | |
5158 | ||
604133b5 | 5159 | b->ops = ops; |
018d34a4 VP |
5160 | mention (b); |
5161 | } | |
5162 | ||
ed0616c6 VP |
5163 | /* Remove element at INDEX_TO_REMOVE from SAL, shifting other |
5164 | elements to fill the void space. */ | |
5165 | static void remove_sal (struct symtabs_and_lines *sal, int index_to_remove) | |
5166 | { | |
5167 | int i = index_to_remove+1; | |
5168 | int last_index = sal->nelts-1; | |
5169 | ||
5170 | for (;i <= last_index; ++i) | |
5171 | sal->sals[i-1] = sal->sals[i]; | |
5172 | ||
5173 | --(sal->nelts); | |
5174 | } | |
5175 | ||
5176 | /* If appropriate, obtains all sals that correspond | |
5177 | to the same file and line as SAL. This is done | |
5178 | only if SAL does not have explicit PC and has | |
5179 | line and file information. If we got just a single | |
5180 | expanded sal, return the original. | |
5181 | ||
5182 | Otherwise, if SAL.explicit_line is not set, filter out | |
5183 | all sals for which the name of enclosing function | |
5184 | is different from SAL. This makes sure that if we have | |
5185 | breakpoint originally set in template instantiation, say | |
5186 | foo<int>(), we won't expand SAL to locations at the same | |
5187 | line in all existing instantiations of 'foo'. | |
5188 | ||
5189 | */ | |
5190 | struct symtabs_and_lines | |
5191 | expand_line_sal_maybe (struct symtab_and_line sal) | |
5192 | { | |
5193 | struct symtabs_and_lines expanded; | |
5194 | CORE_ADDR original_pc = sal.pc; | |
5195 | char *original_function = NULL; | |
5196 | int found; | |
5197 | int i; | |
5198 | ||
5199 | /* If we have explicit pc, don't expand. | |
5200 | If we have no line number, we can't expand. */ | |
5201 | if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL) | |
5202 | { | |
5203 | expanded.nelts = 1; | |
5204 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
5205 | expanded.sals[0] = sal; | |
5206 | return expanded; | |
5207 | } | |
5208 | ||
5209 | sal.pc = 0; | |
5210 | find_pc_partial_function (original_pc, &original_function, NULL, NULL); | |
5211 | ||
5212 | expanded = expand_line_sal (sal); | |
5213 | if (expanded.nelts == 1) | |
5214 | { | |
5215 | /* We had one sal, we got one sal. Without futher | |
5216 | processing, just return the original sal. */ | |
5217 | xfree (expanded.sals); | |
5218 | expanded.nelts = 1; | |
5219 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
5220 | sal.pc = original_pc; | |
5221 | expanded.sals[0] = sal; | |
5222 | return expanded; | |
5223 | } | |
5224 | ||
5225 | if (!sal.explicit_line) | |
5226 | { | |
5227 | CORE_ADDR func_addr, func_end; | |
5228 | for (i = 0; i < expanded.nelts; ++i) | |
5229 | { | |
5230 | CORE_ADDR pc = expanded.sals[i].pc; | |
5231 | char *this_function; | |
5232 | if (find_pc_partial_function (pc, &this_function, | |
5233 | &func_addr, &func_end)) | |
5234 | { | |
5235 | if (this_function && | |
5236 | strcmp (this_function, original_function) != 0) | |
5237 | { | |
5238 | remove_sal (&expanded, i); | |
5239 | --i; | |
5240 | } | |
5241 | else if (func_addr == pc) | |
5242 | { | |
5243 | /* We're at beginning of a function, and should | |
5244 | skip prologue. */ | |
5245 | struct symbol *sym = find_pc_function (pc); | |
5246 | if (sym) | |
5247 | expanded.sals[i] = find_function_start_sal (sym, 1); | |
5248 | else | |
5249 | expanded.sals[i].pc | |
5250 | = gdbarch_skip_prologue (current_gdbarch, pc); | |
5251 | } | |
5252 | } | |
5253 | } | |
5254 | } | |
5255 | ||
5256 | ||
5257 | if (expanded.nelts <= 1) | |
5258 | { | |
5259 | /* This is un ugly workaround. If we get zero | |
5260 | expanded sals then something is really wrong. | |
5261 | Fix that by returnign the original sal. */ | |
5262 | xfree (expanded.sals); | |
5263 | expanded.nelts = 1; | |
5264 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
5265 | sal.pc = original_pc; | |
5266 | expanded.sals[0] = sal; | |
5267 | return expanded; | |
5268 | } | |
5269 | ||
5270 | if (original_pc) | |
5271 | { | |
5272 | found = 0; | |
5273 | for (i = 0; i < expanded.nelts; ++i) | |
5274 | if (expanded.sals[i].pc == original_pc) | |
5275 | { | |
5276 | found = 1; | |
5277 | break; | |
5278 | } | |
5279 | gdb_assert (found); | |
5280 | } | |
5281 | ||
5282 | return expanded; | |
5283 | } | |
5284 | ||
018d34a4 VP |
5285 | /* Add SALS.nelts breakpoints to the breakpoint table. For each |
5286 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
5287 | value. COND_STRING, if not NULL, specified the condition to be | |
5288 | used for all breakpoints. Essentially the only case where | |
5289 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
5290 | function. In that case, it's still not possible to specify | |
5291 | separate conditions for different overloaded functions, so | |
5292 | we take just a single condition string. | |
5293 | ||
c3f6f71d | 5294 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 5295 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
5296 | array contents). If the function fails (error() is called), the |
5297 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
5298 | COND and SALS arrays and each of those arrays contents. */ | |
c906108c SS |
5299 | |
5300 | static void | |
c3f6f71d | 5301 | create_breakpoints (struct symtabs_and_lines sals, char **addr_string, |
018d34a4 | 5302 | char *cond_string, |
c3f6f71d | 5303 | enum bptype type, enum bpdisp disposition, |
604133b5 AR |
5304 | int thread, int ignore_count, |
5305 | struct breakpoint_ops *ops, int from_tty) | |
c906108c | 5306 | { |
018d34a4 VP |
5307 | int i; |
5308 | for (i = 0; i < sals.nelts; ++i) | |
c3f6f71d | 5309 | { |
ed0616c6 VP |
5310 | struct symtabs_and_lines expanded = |
5311 | expand_line_sal_maybe (sals.sals[i]); | |
0d381245 | 5312 | |
ed0616c6 | 5313 | create_breakpoint (expanded, addr_string[i], |
018d34a4 | 5314 | cond_string, type, disposition, |
604133b5 | 5315 | thread, ignore_count, ops, from_tty); |
c3f6f71d | 5316 | } |
74960c60 | 5317 | |
b60e7edf | 5318 | update_global_location_list (1); |
c3f6f71d | 5319 | } |
c906108c | 5320 | |
c3f6f71d JM |
5321 | /* Parse ARG which is assumed to be a SAL specification possibly |
5322 | followed by conditionals. On return, SALS contains an array of SAL | |
5323 | addresses found. ADDR_STRING contains a vector of (canonical) | |
5324 | address strings. ARG points to the end of the SAL. */ | |
c906108c | 5325 | |
b9362cc7 | 5326 | static void |
c3f6f71d JM |
5327 | parse_breakpoint_sals (char **address, |
5328 | struct symtabs_and_lines *sals, | |
0101ce28 JJ |
5329 | char ***addr_string, |
5330 | int *not_found_ptr) | |
c3f6f71d JM |
5331 | { |
5332 | char *addr_start = *address; | |
5333 | *addr_string = NULL; | |
5334 | /* If no arg given, or if first arg is 'if ', use the default | |
5335 | breakpoint. */ | |
5336 | if ((*address) == NULL | |
5337 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c SS |
5338 | { |
5339 | if (default_breakpoint_valid) | |
5340 | { | |
c3f6f71d | 5341 | struct symtab_and_line sal; |
fe39c653 | 5342 | init_sal (&sal); /* initialize to zeroes */ |
c3f6f71d | 5343 | sals->sals = (struct symtab_and_line *) |
c906108c SS |
5344 | xmalloc (sizeof (struct symtab_and_line)); |
5345 | sal.pc = default_breakpoint_address; | |
5346 | sal.line = default_breakpoint_line; | |
5347 | sal.symtab = default_breakpoint_symtab; | |
c5aa993b | 5348 | sal.section = find_pc_overlay (sal.pc); |
c3f6f71d JM |
5349 | sals->sals[0] = sal; |
5350 | sals->nelts = 1; | |
c906108c SS |
5351 | } |
5352 | else | |
8a3fe4f8 | 5353 | error (_("No default breakpoint address now.")); |
c906108c SS |
5354 | } |
5355 | else | |
5356 | { | |
c906108c | 5357 | /* Force almost all breakpoints to be in terms of the |
c5aa993b JM |
5358 | current_source_symtab (which is decode_line_1's default). This |
5359 | should produce the results we want almost all of the time while | |
1aeae86e AF |
5360 | leaving default_breakpoint_* alone. |
5361 | ObjC: However, don't match an Objective-C method name which | |
5362 | may have a '+' or '-' succeeded by a '[' */ | |
0378c332 | 5363 | |
c214a6fd | 5364 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
0378c332 | 5365 | |
c906108c | 5366 | if (default_breakpoint_valid |
0378c332 | 5367 | && (!cursal.symtab |
1aeae86e AF |
5368 | || ((strchr ("+-", (*address)[0]) != NULL) |
5369 | && ((*address)[1] != '[')))) | |
c3f6f71d | 5370 | *sals = decode_line_1 (address, 1, default_breakpoint_symtab, |
0101ce28 JJ |
5371 | default_breakpoint_line, addr_string, |
5372 | not_found_ptr); | |
c906108c | 5373 | else |
0101ce28 JJ |
5374 | *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, |
5375 | addr_string, not_found_ptr); | |
c906108c | 5376 | } |
c3f6f71d JM |
5377 | /* For any SAL that didn't have a canonical string, fill one in. */ |
5378 | if (sals->nelts > 0 && *addr_string == NULL) | |
5379 | *addr_string = xcalloc (sals->nelts, sizeof (char **)); | |
5380 | if (addr_start != (*address)) | |
c906108c | 5381 | { |
c3f6f71d JM |
5382 | int i; |
5383 | for (i = 0; i < sals->nelts; i++) | |
c906108c | 5384 | { |
c3f6f71d JM |
5385 | /* Add the string if not present. */ |
5386 | if ((*addr_string)[i] == NULL) | |
5387 | (*addr_string)[i] = savestring (addr_start, (*address) - addr_start); | |
c906108c SS |
5388 | } |
5389 | } | |
c3f6f71d | 5390 | } |
c906108c | 5391 | |
c906108c | 5392 | |
c3f6f71d JM |
5393 | /* Convert each SAL into a real PC. Verify that the PC can be |
5394 | inserted as a breakpoint. If it can't throw an error. */ | |
c906108c | 5395 | |
b9362cc7 | 5396 | static void |
c3f6f71d JM |
5397 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals, |
5398 | char *address) | |
5399 | { | |
5400 | int i; | |
5401 | for (i = 0; i < sals->nelts; i++) | |
ee53e872 | 5402 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
5403 | } |
5404 | ||
05ff989b | 5405 | static void |
0101ce28 JJ |
5406 | do_captured_parse_breakpoint (struct ui_out *ui, void *data) |
5407 | { | |
5408 | struct captured_parse_breakpoint_args *args = data; | |
5409 | ||
5410 | parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p, | |
5411 | args->not_found_ptr); | |
0101ce28 JJ |
5412 | } |
5413 | ||
018d34a4 VP |
5414 | /* Given TOK, a string specification of condition and thread, as |
5415 | accepted by the 'break' command, extract the condition | |
5416 | string and thread number and set *COND_STRING and *THREAD. | |
5417 | PC identifies the context at which the condition should be parsed. | |
5418 | If no condition is found, *COND_STRING is set to NULL. | |
5419 | If no thread is found, *THREAD is set to -1. */ | |
5420 | static void | |
5421 | find_condition_and_thread (char *tok, CORE_ADDR pc, | |
5422 | char **cond_string, int *thread) | |
5423 | { | |
5424 | *cond_string = NULL; | |
5425 | *thread = -1; | |
5426 | while (tok && *tok) | |
5427 | { | |
5428 | char *end_tok; | |
5429 | int toklen; | |
5430 | char *cond_start = NULL; | |
5431 | char *cond_end = NULL; | |
5432 | while (*tok == ' ' || *tok == '\t') | |
5433 | tok++; | |
5434 | ||
5435 | end_tok = tok; | |
5436 | ||
5437 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
5438 | end_tok++; | |
5439 | ||
5440 | toklen = end_tok - tok; | |
5441 | ||
5442 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
5443 | { | |
5444 | tok = cond_start = end_tok + 1; | |
5445 | parse_exp_1 (&tok, block_for_pc (pc), 0); | |
5446 | cond_end = tok; | |
5447 | *cond_string = savestring (cond_start, | |
5448 | cond_end - cond_start); | |
5449 | } | |
5450 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
5451 | { | |
5452 | char *tmptok; | |
5453 | ||
5454 | tok = end_tok + 1; | |
5455 | tmptok = tok; | |
5456 | *thread = strtol (tok, &tok, 0); | |
5457 | if (tok == tmptok) | |
5458 | error (_("Junk after thread keyword.")); | |
5459 | if (!valid_thread_id (*thread)) | |
5460 | error (_("Unknown thread %d."), *thread); | |
5461 | } | |
5462 | else | |
5463 | error (_("Junk at end of arguments.")); | |
5464 | } | |
5465 | } | |
5466 | ||
72b2ff0e VP |
5467 | /* Set a breakpoint. This function is shared between |
5468 | CLI and MI functions for setting a breakpoint. | |
5469 | This function has two major modes of operations, | |
5470 | selected by the PARSE_CONDITION_AND_THREAD parameter. | |
5471 | If non-zero, the function will parse arg, extracting | |
5472 | breakpoint location, address and thread. Otherwise, | |
5473 | ARG is just the location of breakpoint, with condition | |
5474 | and thread specified by the COND_STRING and THREAD | |
5475 | parameters. */ | |
0101ce28 | 5476 | |
98deb0da | 5477 | static void |
72b2ff0e | 5478 | break_command_really (char *arg, char *cond_string, int thread, |
60c46647 VP |
5479 | int parse_condition_and_thread, |
5480 | int tempflag, int hardwareflag, | |
5481 | int ignore_count, | |
5482 | enum auto_boolean pending_break_support, | |
604133b5 | 5483 | struct breakpoint_ops *ops, |
60c46647 | 5484 | int from_tty) |
c3f6f71d | 5485 | { |
71fff37b | 5486 | struct gdb_exception e; |
c3f6f71d | 5487 | struct symtabs_and_lines sals; |
0101ce28 | 5488 | struct symtab_and_line pending_sal; |
0101ce28 JJ |
5489 | char *copy_arg; |
5490 | char *err_msg; | |
c3f6f71d JM |
5491 | char *addr_start = arg; |
5492 | char **addr_string; | |
5493 | struct cleanup *old_chain; | |
5494 | struct cleanup *breakpoint_chain = NULL; | |
0101ce28 | 5495 | struct captured_parse_breakpoint_args parse_args; |
05ff989b | 5496 | int i; |
0101ce28 | 5497 | int pending = 0; |
0101ce28 | 5498 | int not_found = 0; |
c3f6f71d | 5499 | |
c3f6f71d JM |
5500 | sals.sals = NULL; |
5501 | sals.nelts = 0; | |
5502 | addr_string = NULL; | |
c3f6f71d | 5503 | |
0101ce28 JJ |
5504 | parse_args.arg_p = &arg; |
5505 | parse_args.sals_p = &sals; | |
5506 | parse_args.addr_string_p = &addr_string; | |
5507 | parse_args.not_found_ptr = ¬_found; | |
5508 | ||
05ff989b AC |
5509 | e = catch_exception (uiout, do_captured_parse_breakpoint, |
5510 | &parse_args, RETURN_MASK_ALL); | |
0101ce28 JJ |
5511 | |
5512 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 5513 | switch (e.reason) |
0101ce28 | 5514 | { |
05ff989b | 5515 | case RETURN_QUIT: |
98deb0da | 5516 | throw_exception (e); |
05ff989b AC |
5517 | case RETURN_ERROR: |
5518 | switch (e.error) | |
0101ce28 | 5519 | { |
05ff989b | 5520 | case NOT_FOUND_ERROR: |
0101ce28 | 5521 | |
05ff989b AC |
5522 | /* If pending breakpoint support is turned off, throw |
5523 | error. */ | |
fa8d40ab JJ |
5524 | |
5525 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
5526 | throw_exception (e); |
5527 | ||
5528 | exception_print (gdb_stderr, e); | |
fa8d40ab | 5529 | |
05ff989b AC |
5530 | /* If pending breakpoint support is auto query and the user |
5531 | selects no, then simply return the error code. */ | |
fa8d40ab JJ |
5532 | if (pending_break_support == AUTO_BOOLEAN_AUTO && |
5533 | !nquery ("Make breakpoint pending on future shared library load? ")) | |
98deb0da | 5534 | return; |
fa8d40ab | 5535 | |
05ff989b AC |
5536 | /* At this point, either the user was queried about setting |
5537 | a pending breakpoint and selected yes, or pending | |
5538 | breakpoint behavior is on and thus a pending breakpoint | |
5539 | is defaulted on behalf of the user. */ | |
0101ce28 JJ |
5540 | copy_arg = xstrdup (addr_start); |
5541 | addr_string = ©_arg; | |
5542 | sals.nelts = 1; | |
5543 | sals.sals = &pending_sal; | |
5544 | pending_sal.pc = 0; | |
5545 | pending = 1; | |
05ff989b AC |
5546 | break; |
5547 | default: | |
98deb0da | 5548 | throw_exception (e); |
0101ce28 | 5549 | } |
05ff989b AC |
5550 | default: |
5551 | if (!sals.nelts) | |
98deb0da | 5552 | return; |
0101ce28 | 5553 | } |
c3f6f71d JM |
5554 | |
5555 | /* Create a chain of things that always need to be cleaned up. */ | |
5556 | old_chain = make_cleanup (null_cleanup, 0); | |
5557 | ||
0101ce28 JJ |
5558 | if (!pending) |
5559 | { | |
5560 | /* Make sure that all storage allocated to SALS gets freed. */ | |
5561 | make_cleanup (xfree, sals.sals); | |
5562 | ||
5563 | /* Cleanup the addr_string array but not its contents. */ | |
5564 | make_cleanup (xfree, addr_string); | |
5565 | } | |
c3f6f71d | 5566 | |
c3f6f71d JM |
5567 | /* ----------------------------- SNIP ----------------------------- |
5568 | Anything added to the cleanup chain beyond this point is assumed | |
5569 | to be part of a breakpoint. If the breakpoint create succeeds | |
5570 | then the memory is not reclaimed. */ | |
5571 | breakpoint_chain = make_cleanup (null_cleanup, 0); | |
5572 | ||
5573 | /* Mark the contents of the addr_string for cleanup. These go on | |
5574 | the breakpoint_chain and only occure if the breakpoint create | |
5575 | fails. */ | |
5576 | for (i = 0; i < sals.nelts; i++) | |
5577 | { | |
5578 | if (addr_string[i] != NULL) | |
b8c9b27d | 5579 | make_cleanup (xfree, addr_string[i]); |
c3f6f71d JM |
5580 | } |
5581 | ||
5582 | /* Resolve all line numbers to PC's and verify that the addresses | |
5583 | are ok for the target. */ | |
0101ce28 JJ |
5584 | if (!pending) |
5585 | breakpoint_sals_to_pc (&sals, addr_start); | |
c3f6f71d JM |
5586 | |
5587 | /* Verify that condition can be parsed, before setting any | |
5588 | breakpoints. Allocate a separate condition expression for each | |
5589 | breakpoint. */ | |
0101ce28 | 5590 | if (!pending) |
c3f6f71d | 5591 | { |
2f069f6f | 5592 | if (parse_condition_and_thread) |
72b2ff0e VP |
5593 | { |
5594 | /* Here we only parse 'arg' to separate condition | |
5595 | from thread number, so parsing in context of first | |
5596 | sal is OK. When setting the breakpoint we'll | |
5597 | re-parse it in context of each sal. */ | |
5598 | cond_string = NULL; | |
5599 | thread = -1; | |
5600 | find_condition_and_thread (arg, sals.sals[0].pc, &cond_string, &thread); | |
5601 | if (cond_string) | |
5602 | make_cleanup (xfree, cond_string); | |
5603 | } | |
2f069f6f | 5604 | else |
72b2ff0e VP |
5605 | { |
5606 | /* Create a private copy of condition string. */ | |
5607 | if (cond_string) | |
5608 | { | |
5609 | cond_string = xstrdup (cond_string); | |
5610 | make_cleanup (xfree, cond_string); | |
5611 | } | |
5612 | } | |
018d34a4 | 5613 | create_breakpoints (sals, addr_string, cond_string, |
0101ce28 JJ |
5614 | hardwareflag ? bp_hardware_breakpoint |
5615 | : bp_breakpoint, | |
5616 | tempflag ? disp_del : disp_donttouch, | |
604133b5 | 5617 | thread, ignore_count, ops, from_tty); |
c906108c | 5618 | } |
0101ce28 JJ |
5619 | else |
5620 | { | |
fe3f5fa8 | 5621 | struct symtab_and_line sal = {0}; |
0101ce28 JJ |
5622 | struct breakpoint *b; |
5623 | ||
0101ce28 JJ |
5624 | make_cleanup (xfree, copy_arg); |
5625 | ||
0d381245 VP |
5626 | b = set_raw_breakpoint_without_location (hardwareflag |
5627 | ? bp_hardware_breakpoint | |
5628 | : bp_breakpoint); | |
0101ce28 JJ |
5629 | set_breakpoint_count (breakpoint_count + 1); |
5630 | b->number = breakpoint_count; | |
72b2ff0e | 5631 | b->thread = -1; |
018d34a4 | 5632 | b->addr_string = addr_string[0]; |
72b2ff0e | 5633 | b->cond_string = NULL; |
0101ce28 | 5634 | b->ignore_count = ignore_count; |
0101ce28 | 5635 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 5636 | b->condition_not_parsed = 1; |
604133b5 | 5637 | b->ops = ops; |
74960c60 | 5638 | |
b60e7edf | 5639 | update_global_location_list (1); |
0101ce28 JJ |
5640 | mention (b); |
5641 | } | |
5642 | ||
c3f6f71d | 5643 | if (sals.nelts > 1) |
8a3fe4f8 AC |
5644 | warning (_("Multiple breakpoints were set.\n" |
5645 | "Use the \"delete\" command to delete unwanted breakpoints.")); | |
c3f6f71d JM |
5646 | /* That's it. Discard the cleanups for data inserted into the |
5647 | breakpoint. */ | |
5648 | discard_cleanups (breakpoint_chain); | |
5649 | /* But cleanup everything else. */ | |
5650 | do_cleanups (old_chain); | |
5651 | } | |
c906108c | 5652 | |
72b2ff0e VP |
5653 | /* Set a breakpoint. |
5654 | ARG is a string describing breakpoint address, | |
5655 | condition, and thread. | |
5656 | FLAG specifies if a breakpoint is hardware on, | |
5657 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
5658 | and BP_TEMPFLAG. */ | |
5659 | ||
98deb0da | 5660 | static void |
72b2ff0e | 5661 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 5662 | { |
72b2ff0e VP |
5663 | int hardwareflag = flag & BP_HARDWAREFLAG; |
5664 | int tempflag = flag & BP_TEMPFLAG; | |
c3f6f71d | 5665 | |
98deb0da VP |
5666 | break_command_really (arg, |
5667 | NULL, 0, 1 /* parse arg */, | |
5668 | tempflag, hardwareflag, | |
5669 | 0 /* Ignore count */, | |
604133b5 AR |
5670 | pending_break_support, |
5671 | NULL /* breakpoint_ops */, | |
5672 | from_tty); | |
c906108c SS |
5673 | } |
5674 | ||
72b2ff0e | 5675 | |
98deb0da VP |
5676 | void |
5677 | set_breakpoint (char *address, char *condition, | |
c3f6f71d | 5678 | int hardwareflag, int tempflag, |
ce43223b | 5679 | int thread, int ignore_count, |
98deb0da | 5680 | int pending) |
c3f6f71d | 5681 | { |
98deb0da VP |
5682 | break_command_really (address, condition, thread, |
5683 | 0 /* condition and thread are valid. */, | |
5684 | tempflag, hardwareflag, | |
5685 | ignore_count, | |
5686 | pending | |
5687 | ? AUTO_BOOLEAN_TRUE : AUTO_BOOLEAN_FALSE, | |
604133b5 | 5688 | NULL, 0); |
c3f6f71d JM |
5689 | } |
5690 | ||
6a048695 JB |
5691 | /* Adjust SAL to the first instruction past the function prologue. |
5692 | The end of the prologue is determined using the line table from | |
5693 | the debugging information. | |
5694 | ||
5695 | If SAL is already past the prologue, then do nothing. */ | |
5696 | ||
5697 | static void | |
5698 | skip_prologue_sal (struct symtab_and_line *sal) | |
5699 | { | |
5700 | struct symbol *sym = find_pc_function (sal->pc); | |
5701 | struct symtab_and_line start_sal; | |
5702 | ||
5703 | if (sym == NULL) | |
5704 | return; | |
5705 | ||
5706 | start_sal = find_function_start_sal (sym, 1); | |
5707 | if (sal->pc < start_sal.pc) | |
5708 | *sal = start_sal; | |
5709 | } | |
c3f6f71d | 5710 | |
c906108c SS |
5711 | /* Helper function for break_command_1 and disassemble_command. */ |
5712 | ||
5713 | void | |
fba45db2 | 5714 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
5715 | { |
5716 | CORE_ADDR pc; | |
5717 | ||
5718 | if (sal->pc == 0 && sal->symtab != NULL) | |
5719 | { | |
5720 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 5721 | error (_("No line %d in file \"%s\"."), |
c906108c SS |
5722 | sal->line, sal->symtab->filename); |
5723 | sal->pc = pc; | |
6a048695 JB |
5724 | |
5725 | /* If this SAL corresponds to a breakpoint inserted using | |
5726 | a line number, then skip the function prologue if necessary. */ | |
5727 | if (sal->explicit_line) | |
5728 | skip_prologue_sal (sal); | |
c906108c SS |
5729 | } |
5730 | ||
5731 | if (sal->section == 0 && sal->symtab != NULL) | |
5732 | { | |
5733 | struct blockvector *bv; | |
c5aa993b JM |
5734 | struct block *b; |
5735 | struct symbol *sym; | |
c906108c | 5736 | |
801e3a5b | 5737 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
5738 | if (bv != NULL) |
5739 | { | |
7f0df278 | 5740 | sym = block_linkage_function (b); |
c906108c SS |
5741 | if (sym != NULL) |
5742 | { | |
5743 | fixup_symbol_section (sym, sal->symtab->objfile); | |
714835d5 | 5744 | sal->section = SYMBOL_OBJ_SECTION (sym); |
c906108c SS |
5745 | } |
5746 | else | |
5747 | { | |
5748 | /* It really is worthwhile to have the section, so we'll just | |
c5aa993b JM |
5749 | have to look harder. This case can be executed if we have |
5750 | line numbers but no functions (as can happen in assembly | |
5751 | source). */ | |
c906108c | 5752 | |
c5aa993b | 5753 | struct minimal_symbol *msym; |
c906108c SS |
5754 | |
5755 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
5756 | if (msym) | |
714835d5 | 5757 | sal->section = SYMBOL_OBJ_SECTION (msym); |
c906108c SS |
5758 | } |
5759 | } | |
5760 | } | |
5761 | } | |
5762 | ||
5763 | void | |
fba45db2 | 5764 | break_command (char *arg, int from_tty) |
c906108c | 5765 | { |
db107f19 | 5766 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
5767 | } |
5768 | ||
c906108c | 5769 | void |
fba45db2 | 5770 | tbreak_command (char *arg, int from_tty) |
c906108c | 5771 | { |
db107f19 | 5772 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
5773 | } |
5774 | ||
c906108c | 5775 | static void |
fba45db2 | 5776 | hbreak_command (char *arg, int from_tty) |
c906108c | 5777 | { |
db107f19 | 5778 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
5779 | } |
5780 | ||
5781 | static void | |
fba45db2 | 5782 | thbreak_command (char *arg, int from_tty) |
c906108c | 5783 | { |
db107f19 | 5784 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
5785 | } |
5786 | ||
5787 | static void | |
fba45db2 | 5788 | stop_command (char *arg, int from_tty) |
c906108c | 5789 | { |
a3f17187 | 5790 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 5791 | Usage: stop in <function | address>\n\ |
a3f17187 | 5792 | stop at <line>\n")); |
c906108c SS |
5793 | } |
5794 | ||
5795 | static void | |
fba45db2 | 5796 | stopin_command (char *arg, int from_tty) |
c906108c SS |
5797 | { |
5798 | int badInput = 0; | |
5799 | ||
c5aa993b | 5800 | if (arg == (char *) NULL) |
c906108c SS |
5801 | badInput = 1; |
5802 | else if (*arg != '*') | |
5803 | { | |
5804 | char *argptr = arg; | |
5805 | int hasColon = 0; | |
5806 | ||
53a5351d JM |
5807 | /* look for a ':'. If this is a line number specification, then |
5808 | say it is bad, otherwise, it should be an address or | |
5809 | function/method name */ | |
c906108c | 5810 | while (*argptr && !hasColon) |
c5aa993b JM |
5811 | { |
5812 | hasColon = (*argptr == ':'); | |
5813 | argptr++; | |
5814 | } | |
c906108c SS |
5815 | |
5816 | if (hasColon) | |
c5aa993b | 5817 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 5818 | else |
c5aa993b | 5819 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
5820 | } |
5821 | ||
5822 | if (badInput) | |
a3f17187 | 5823 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 5824 | else |
db107f19 | 5825 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
5826 | } |
5827 | ||
5828 | static void | |
fba45db2 | 5829 | stopat_command (char *arg, int from_tty) |
c906108c SS |
5830 | { |
5831 | int badInput = 0; | |
5832 | ||
c5aa993b | 5833 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
5834 | badInput = 1; |
5835 | else | |
5836 | { | |
5837 | char *argptr = arg; | |
5838 | int hasColon = 0; | |
5839 | ||
5840 | /* look for a ':'. If there is a '::' then get out, otherwise | |
c5aa993b | 5841 | it is probably a line number. */ |
c906108c | 5842 | while (*argptr && !hasColon) |
c5aa993b JM |
5843 | { |
5844 | hasColon = (*argptr == ':'); | |
5845 | argptr++; | |
5846 | } | |
c906108c SS |
5847 | |
5848 | if (hasColon) | |
c5aa993b | 5849 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 5850 | else |
c5aa993b | 5851 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
5852 | } |
5853 | ||
5854 | if (badInput) | |
a3f17187 | 5855 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 5856 | else |
db107f19 | 5857 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
5858 | } |
5859 | ||
53a5351d JM |
5860 | /* accessflag: hw_write: watch write, |
5861 | hw_read: watch read, | |
5862 | hw_access: watch access (read or write) */ | |
c906108c | 5863 | static void |
fba45db2 | 5864 | watch_command_1 (char *arg, int accessflag, int from_tty) |
c906108c | 5865 | { |
d983da9c | 5866 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c SS |
5867 | struct symtab_and_line sal; |
5868 | struct expression *exp; | |
5869 | struct block *exp_valid_block; | |
5870 | struct value *val, *mark; | |
5871 | struct frame_info *frame; | |
5872 | struct frame_info *prev_frame = NULL; | |
5873 | char *exp_start = NULL; | |
5874 | char *exp_end = NULL; | |
37e4754d | 5875 | char *tok, *id_tok_start, *end_tok; |
c906108c SS |
5876 | int toklen; |
5877 | char *cond_start = NULL; | |
5878 | char *cond_end = NULL; | |
5879 | struct expression *cond = NULL; | |
5880 | int i, other_type_used, target_resources_ok = 0; | |
5881 | enum bptype bp_type; | |
5882 | int mem_cnt = 0; | |
37e4754d | 5883 | int thread = -1; |
c906108c | 5884 | |
fe39c653 | 5885 | init_sal (&sal); /* initialize to zeroes */ |
c5aa993b | 5886 | |
37e4754d LM |
5887 | /* Make sure that we actually have parameters to parse. */ |
5888 | if (arg != NULL && arg[0] != '\0') | |
5889 | { | |
5890 | toklen = strlen (arg); /* Size of argument list. */ | |
5891 | ||
5892 | /* Points tok to the end of the argument list. */ | |
5893 | tok = arg + toklen - 1; | |
5894 | ||
5895 | /* Go backwards in the parameters list. Skip the last parameter. | |
5896 | If we're expecting a 'thread <thread_num>' parameter, this should | |
5897 | be the thread identifier. */ | |
5898 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
5899 | tok--; | |
5900 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
5901 | tok--; | |
5902 | ||
5903 | /* Points end_tok to the beginning of the last token. */ | |
5904 | id_tok_start = tok + 1; | |
5905 | ||
5906 | /* Go backwards in the parameters list. Skip one more parameter. | |
5907 | If we're expecting a 'thread <thread_num>' parameter, we should | |
5908 | reach a "thread" token. */ | |
5909 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
5910 | tok--; | |
5911 | ||
5912 | end_tok = tok; | |
5913 | ||
5914 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
5915 | tok--; | |
5916 | ||
5917 | /* Move the pointer forward to skip the whitespace and | |
5918 | calculate the length of the token. */ | |
5919 | tok++; | |
5920 | toklen = end_tok - tok; | |
5921 | ||
5922 | if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
5923 | { | |
5924 | /* At this point we've found a "thread" token, which means | |
5925 | the user is trying to set a watchpoint that triggers | |
5926 | only in a specific thread. */ | |
5927 | char *endp; | |
5928 | ||
5929 | /* Extract the thread ID from the next token. */ | |
5930 | thread = strtol (id_tok_start, &endp, 0); | |
5931 | ||
5932 | /* Check if the user provided a valid numeric value for the | |
5933 | thread ID. */ | |
5934 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
5935 | error (_("Invalid thread ID specification %s."), id_tok_start); | |
5936 | ||
5937 | /* Check if the thread actually exists. */ | |
5938 | if (!valid_thread_id (thread)) | |
5939 | error (_("Unknown thread %d."), thread); | |
5940 | ||
5941 | /* Truncate the string and get rid of the thread <thread_num> | |
5942 | parameter before the parameter list is parsed by the | |
5943 | evaluate_expression() function. */ | |
5944 | *tok = '\0'; | |
5945 | } | |
5946 | } | |
5947 | ||
5948 | /* Parse the rest of the arguments. */ | |
c906108c SS |
5949 | innermost_block = NULL; |
5950 | exp_start = arg; | |
5951 | exp = parse_exp_1 (&arg, 0, 0); | |
5952 | exp_end = arg; | |
5953 | exp_valid_block = innermost_block; | |
5954 | mark = value_mark (); | |
fa4727a6 DJ |
5955 | fetch_watchpoint_value (exp, &val, NULL, NULL); |
5956 | if (val != NULL) | |
5957 | release_value (val); | |
c906108c SS |
5958 | |
5959 | tok = arg; | |
5960 | while (*tok == ' ' || *tok == '\t') | |
5961 | tok++; | |
5962 | end_tok = tok; | |
5963 | ||
5964 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
5965 | end_tok++; | |
5966 | ||
5967 | toklen = end_tok - tok; | |
5968 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
5969 | { | |
5970 | tok = cond_start = end_tok + 1; | |
5971 | cond = parse_exp_1 (&tok, 0, 0); | |
5972 | cond_end = tok; | |
5973 | } | |
5974 | if (*tok) | |
8a3fe4f8 | 5975 | error (_("Junk at end of command.")); |
c906108c | 5976 | |
53a5351d | 5977 | if (accessflag == hw_read) |
c5aa993b | 5978 | bp_type = bp_read_watchpoint; |
53a5351d | 5979 | else if (accessflag == hw_access) |
c5aa993b JM |
5980 | bp_type = bp_access_watchpoint; |
5981 | else | |
5982 | bp_type = bp_hardware_watchpoint; | |
c906108c SS |
5983 | |
5984 | mem_cnt = can_use_hardware_watchpoint (val); | |
5985 | if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint) | |
8a3fe4f8 | 5986 | error (_("Expression cannot be implemented with read/access watchpoint.")); |
c5aa993b JM |
5987 | if (mem_cnt != 0) |
5988 | { | |
5989 | i = hw_watchpoint_used_count (bp_type, &other_type_used); | |
53a5351d JM |
5990 | target_resources_ok = |
5991 | TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type, i + mem_cnt, | |
5992 | other_type_used); | |
c5aa993b | 5993 | if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint) |
8a3fe4f8 | 5994 | error (_("Target does not support this type of hardware watchpoint.")); |
53a5351d | 5995 | |
c5aa993b | 5996 | if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint) |
8a3fe4f8 | 5997 | error (_("Target can only support one kind of HW watchpoint at a time.")); |
c5aa993b | 5998 | } |
c906108c | 5999 | |
4d28f7a8 KB |
6000 | /* Change the type of breakpoint to an ordinary watchpoint if a hardware |
6001 | watchpoint could not be set. */ | |
6002 | if (!mem_cnt || target_resources_ok <= 0) | |
6003 | bp_type = bp_watchpoint; | |
6004 | ||
d983da9c DJ |
6005 | frame = block_innermost_frame (exp_valid_block); |
6006 | if (frame) | |
6007 | prev_frame = get_prev_frame (frame); | |
6008 | else | |
6009 | prev_frame = NULL; | |
6010 | ||
6011 | /* If the expression is "local", then set up a "watchpoint scope" | |
6012 | breakpoint at the point where we've left the scope of the watchpoint | |
6013 | expression. Create the scope breakpoint before the watchpoint, so | |
6014 | that we will encounter it first in bpstat_stop_status. */ | |
6015 | if (innermost_block && prev_frame) | |
6016 | { | |
6017 | scope_breakpoint = create_internal_breakpoint (get_frame_pc (prev_frame), | |
6018 | bp_watchpoint_scope); | |
6019 | ||
6020 | scope_breakpoint->enable_state = bp_enabled; | |
6021 | ||
6022 | /* Automatically delete the breakpoint when it hits. */ | |
6023 | scope_breakpoint->disposition = disp_del; | |
6024 | ||
6025 | /* Only break in the proper frame (help with recursion). */ | |
6026 | scope_breakpoint->frame_id = get_frame_id (prev_frame); | |
6027 | ||
6028 | /* Set the address at which we will stop. */ | |
6029 | scope_breakpoint->loc->requested_address | |
6030 | = get_frame_pc (prev_frame); | |
6031 | scope_breakpoint->loc->address | |
6032 | = adjust_breakpoint_address (scope_breakpoint->loc->requested_address, | |
6033 | scope_breakpoint->type); | |
6034 | } | |
6035 | ||
c906108c | 6036 | /* Now set up the breakpoint. */ |
4d28f7a8 | 6037 | b = set_raw_breakpoint (sal, bp_type); |
c906108c SS |
6038 | set_breakpoint_count (breakpoint_count + 1); |
6039 | b->number = breakpoint_count; | |
37e4754d | 6040 | b->thread = thread; |
b5de0fa7 | 6041 | b->disposition = disp_donttouch; |
c906108c SS |
6042 | b->exp = exp; |
6043 | b->exp_valid_block = exp_valid_block; | |
6044 | b->exp_string = savestring (exp_start, exp_end - exp_start); | |
6045 | b->val = val; | |
fa4727a6 | 6046 | b->val_valid = 1; |
511a6cd4 | 6047 | b->loc->cond = cond; |
c906108c SS |
6048 | if (cond_start) |
6049 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
6050 | else | |
6051 | b->cond_string = 0; | |
c5aa993b | 6052 | |
c906108c | 6053 | if (frame) |
d983da9c | 6054 | b->watchpoint_frame = get_frame_id (frame); |
c906108c | 6055 | else |
35a487f1 | 6056 | b->watchpoint_frame = null_frame_id; |
c906108c | 6057 | |
d983da9c | 6058 | if (scope_breakpoint != NULL) |
c906108c | 6059 | { |
d983da9c DJ |
6060 | /* The scope breakpoint is related to the watchpoint. We will |
6061 | need to act on them together. */ | |
6062 | b->related_breakpoint = scope_breakpoint; | |
6063 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 6064 | } |
d983da9c | 6065 | |
c906108c SS |
6066 | value_free_to_mark (mark); |
6067 | mention (b); | |
b60e7edf | 6068 | update_global_location_list (1); |
c906108c SS |
6069 | } |
6070 | ||
6071 | /* Return count of locations need to be watched and can be handled | |
6072 | in hardware. If the watchpoint can not be handled | |
6073 | in hardware return zero. */ | |
6074 | ||
c906108c | 6075 | static int |
fba45db2 | 6076 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
6077 | { |
6078 | int found_memory_cnt = 0; | |
2e70b7b9 | 6079 | struct value *head = v; |
c906108c SS |
6080 | |
6081 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 6082 | if (!can_use_hw_watchpoints) |
c906108c | 6083 | return 0; |
c5aa993b | 6084 | |
5c44784c JM |
6085 | /* Make sure that the value of the expression depends only upon |
6086 | memory contents, and values computed from them within GDB. If we | |
6087 | find any register references or function calls, we can't use a | |
6088 | hardware watchpoint. | |
6089 | ||
6090 | The idea here is that evaluating an expression generates a series | |
6091 | of values, one holding the value of every subexpression. (The | |
6092 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
6093 | a*b+c.) GDB's values hold almost enough information to establish | |
6094 | the criteria given above --- they identify memory lvalues, | |
6095 | register lvalues, computed values, etcetera. So we can evaluate | |
6096 | the expression, and then scan the chain of values that leaves | |
6097 | behind to decide whether we can detect any possible change to the | |
6098 | expression's final value using only hardware watchpoints. | |
6099 | ||
6100 | However, I don't think that the values returned by inferior | |
6101 | function calls are special in any way. So this function may not | |
6102 | notice that an expression involving an inferior function call | |
6103 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 6104 | for (; v; v = value_next (v)) |
c906108c | 6105 | { |
5c44784c | 6106 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 6107 | { |
d69fe07e | 6108 | if (value_lazy (v)) |
5c44784c JM |
6109 | /* A lazy memory lvalue is one that GDB never needed to fetch; |
6110 | we either just used its address (e.g., `a' in `a.b') or | |
6111 | we never needed it at all (e.g., `a' in `a,b'). */ | |
6112 | ; | |
53a5351d | 6113 | else |
5c44784c JM |
6114 | { |
6115 | /* Ahh, memory we actually used! Check if we can cover | |
6116 | it with hardware watchpoints. */ | |
df407dfe | 6117 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
6118 | |
6119 | /* We only watch structs and arrays if user asked for it | |
6120 | explicitly, never if they just happen to appear in a | |
6121 | middle of some value chain. */ | |
6122 | if (v == head | |
6123 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
6124 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
6125 | { | |
df407dfe AC |
6126 | CORE_ADDR vaddr = VALUE_ADDRESS (v) + value_offset (v); |
6127 | int len = TYPE_LENGTH (value_type (v)); | |
2e70b7b9 MS |
6128 | |
6129 | if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr, len)) | |
6130 | return 0; | |
6131 | else | |
6132 | found_memory_cnt++; | |
6133 | } | |
5c44784c | 6134 | } |
c5aa993b | 6135 | } |
5086187c AC |
6136 | else if (VALUE_LVAL (v) != not_lval |
6137 | && deprecated_value_modifiable (v) == 0) | |
53a5351d | 6138 | return 0; /* ??? What does this represent? */ |
5086187c | 6139 | else if (VALUE_LVAL (v) == lval_register) |
53a5351d | 6140 | return 0; /* cannot watch a register with a HW watchpoint */ |
c906108c SS |
6141 | } |
6142 | ||
6143 | /* The expression itself looks suitable for using a hardware | |
6144 | watchpoint, but give the target machine a chance to reject it. */ | |
6145 | return found_memory_cnt; | |
6146 | } | |
6147 | ||
8b93c638 | 6148 | void |
fba45db2 | 6149 | watch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
6150 | { |
6151 | watch_command (arg, from_tty); | |
6152 | } | |
8926118c | 6153 | |
c5aa993b | 6154 | static void |
fba45db2 | 6155 | watch_command (char *arg, int from_tty) |
c906108c | 6156 | { |
53a5351d | 6157 | watch_command_1 (arg, hw_write, from_tty); |
c906108c SS |
6158 | } |
6159 | ||
8b93c638 | 6160 | void |
fba45db2 | 6161 | rwatch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
6162 | { |
6163 | rwatch_command (arg, from_tty); | |
6164 | } | |
8926118c | 6165 | |
c5aa993b | 6166 | static void |
fba45db2 | 6167 | rwatch_command (char *arg, int from_tty) |
c906108c | 6168 | { |
53a5351d | 6169 | watch_command_1 (arg, hw_read, from_tty); |
c906108c SS |
6170 | } |
6171 | ||
8b93c638 | 6172 | void |
fba45db2 | 6173 | awatch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
6174 | { |
6175 | awatch_command (arg, from_tty); | |
6176 | } | |
8926118c | 6177 | |
c5aa993b | 6178 | static void |
fba45db2 | 6179 | awatch_command (char *arg, int from_tty) |
c906108c | 6180 | { |
53a5351d | 6181 | watch_command_1 (arg, hw_access, from_tty); |
c906108c | 6182 | } |
c906108c | 6183 | \f |
c5aa993b | 6184 | |
43ff13b4 | 6185 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
6186 | because it uses the mechanisms of breakpoints. */ |
6187 | ||
bfec99b2 PA |
6188 | struct until_break_command_continuation_args |
6189 | { | |
6190 | struct breakpoint *breakpoint; | |
6191 | struct breakpoint *breakpoint2; | |
6192 | }; | |
6193 | ||
43ff13b4 JM |
6194 | /* This function is called by fetch_inferior_event via the |
6195 | cmd_continuation pointer, to complete the until command. It takes | |
6196 | care of cleaning up the temporary breakpoints set up by the until | |
6197 | command. */ | |
c2c6d25f | 6198 | static void |
604ead4a | 6199 | until_break_command_continuation (void *arg) |
43ff13b4 | 6200 | { |
bfec99b2 PA |
6201 | struct until_break_command_continuation_args *a = arg; |
6202 | ||
6203 | delete_breakpoint (a->breakpoint); | |
6204 | if (a->breakpoint2) | |
6205 | delete_breakpoint (a->breakpoint2); | |
43ff13b4 JM |
6206 | } |
6207 | ||
c906108c | 6208 | void |
ae66c1fc | 6209 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
6210 | { |
6211 | struct symtabs_and_lines sals; | |
6212 | struct symtab_and_line sal; | |
206415a3 DJ |
6213 | struct frame_info *frame = get_selected_frame (NULL); |
6214 | struct frame_info *prev_frame = get_prev_frame (frame); | |
c906108c | 6215 | struct breakpoint *breakpoint; |
f107f563 | 6216 | struct breakpoint *breakpoint2 = NULL; |
c906108c SS |
6217 | struct cleanup *old_chain; |
6218 | ||
6219 | clear_proceed_status (); | |
6220 | ||
6221 | /* Set a breakpoint where the user wants it and at return from | |
6222 | this function */ | |
c5aa993b | 6223 | |
c906108c SS |
6224 | if (default_breakpoint_valid) |
6225 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, | |
68219205 | 6226 | default_breakpoint_line, (char ***) NULL, NULL); |
c906108c | 6227 | else |
53a5351d | 6228 | sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, |
68219205 | 6229 | 0, (char ***) NULL, NULL); |
c5aa993b | 6230 | |
c906108c | 6231 | if (sals.nelts != 1) |
8a3fe4f8 | 6232 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 6233 | |
c906108c | 6234 | sal = sals.sals[0]; |
b8c9b27d | 6235 | xfree (sals.sals); /* malloc'd, so freed */ |
c5aa993b | 6236 | |
c906108c | 6237 | if (*arg) |
8a3fe4f8 | 6238 | error (_("Junk at end of arguments.")); |
c5aa993b | 6239 | |
c906108c | 6240 | resolve_sal_pc (&sal); |
c5aa993b | 6241 | |
ae66c1fc EZ |
6242 | if (anywhere) |
6243 | /* If the user told us to continue until a specified location, | |
6244 | we don't specify a frame at which we need to stop. */ | |
6245 | breakpoint = set_momentary_breakpoint (sal, null_frame_id, bp_until); | |
6246 | else | |
6247 | /* Otherwise, specify the current frame, because we want to stop only | |
6248 | at the very same frame. */ | |
206415a3 | 6249 | breakpoint = set_momentary_breakpoint (sal, get_frame_id (frame), |
ae66c1fc | 6250 | bp_until); |
c5aa993b | 6251 | |
f107f563 | 6252 | old_chain = make_cleanup_delete_breakpoint (breakpoint); |
c906108c | 6253 | |
ae66c1fc EZ |
6254 | /* Keep within the current frame, or in frames called by the current |
6255 | one. */ | |
c906108c SS |
6256 | if (prev_frame) |
6257 | { | |
30f7db39 AC |
6258 | sal = find_pc_line (get_frame_pc (prev_frame), 0); |
6259 | sal.pc = get_frame_pc (prev_frame); | |
f107f563 VP |
6260 | breakpoint2 = set_momentary_breakpoint (sal, get_frame_id (prev_frame), |
6261 | bp_until); | |
6262 | make_cleanup_delete_breakpoint (breakpoint2); | |
c906108c | 6263 | } |
c5aa993b | 6264 | |
c906108c | 6265 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
f107f563 VP |
6266 | |
6267 | /* If we are running asynchronously, and proceed call above has actually | |
6268 | managed to start the target, arrange for breakpoints to be | |
6269 | deleted when the target stops. Otherwise, we're already stopped and | |
6270 | delete breakpoints via cleanup chain. */ | |
6271 | ||
8ea051c5 | 6272 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 6273 | { |
bfec99b2 PA |
6274 | struct until_break_command_continuation_args *args; |
6275 | args = xmalloc (sizeof (*args)); | |
f107f563 | 6276 | |
bfec99b2 PA |
6277 | args->breakpoint = breakpoint; |
6278 | args->breakpoint2 = breakpoint2; | |
f107f563 VP |
6279 | |
6280 | discard_cleanups (old_chain); | |
95e54da7 PA |
6281 | add_continuation (inferior_thread (), |
6282 | until_break_command_continuation, args, | |
604ead4a | 6283 | xfree); |
f107f563 VP |
6284 | } |
6285 | else | |
c5aa993b | 6286 | do_cleanups (old_chain); |
c906108c | 6287 | } |
ae66c1fc | 6288 | |
c906108c | 6289 | static void |
fba45db2 | 6290 | ep_skip_leading_whitespace (char **s) |
c906108c | 6291 | { |
c5aa993b JM |
6292 | if ((s == NULL) || (*s == NULL)) |
6293 | return; | |
6294 | while (isspace (**s)) | |
6295 | *s += 1; | |
c906108c | 6296 | } |
c5aa993b | 6297 | |
c906108c SS |
6298 | /* This function attempts to parse an optional "if <cond>" clause |
6299 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 6300 | |
c906108c SS |
6301 | Else, it returns a pointer to the condition string. (It does not |
6302 | attempt to evaluate the string against a particular block.) And, | |
6303 | it updates arg to point to the first character following the parsed | |
6304 | if clause in the arg string. */ | |
53a5351d | 6305 | |
c906108c | 6306 | static char * |
fba45db2 | 6307 | ep_parse_optional_if_clause (char **arg) |
c906108c | 6308 | { |
c5aa993b JM |
6309 | char *cond_string; |
6310 | ||
6311 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 6312 | return NULL; |
c5aa993b | 6313 | |
c906108c SS |
6314 | /* Skip the "if" keyword. */ |
6315 | (*arg) += 2; | |
c5aa993b | 6316 | |
c906108c SS |
6317 | /* Skip any extra leading whitespace, and record the start of the |
6318 | condition string. */ | |
6319 | ep_skip_leading_whitespace (arg); | |
6320 | cond_string = *arg; | |
c5aa993b | 6321 | |
c906108c SS |
6322 | /* Assume that the condition occupies the remainder of the arg string. */ |
6323 | (*arg) += strlen (cond_string); | |
c5aa993b | 6324 | |
c906108c SS |
6325 | return cond_string; |
6326 | } | |
c5aa993b | 6327 | |
c906108c SS |
6328 | /* This function attempts to parse an optional filename from the arg |
6329 | string. If one is not found, it returns NULL. | |
c5aa993b | 6330 | |
c906108c SS |
6331 | Else, it returns a pointer to the parsed filename. (This function |
6332 | makes no attempt to verify that a file of that name exists, or is | |
6333 | accessible.) And, it updates arg to point to the first character | |
6334 | following the parsed filename in the arg string. | |
c5aa993b | 6335 | |
c906108c SS |
6336 | Note that clients needing to preserve the returned filename for |
6337 | future access should copy it to their own buffers. */ | |
6338 | static char * | |
fba45db2 | 6339 | ep_parse_optional_filename (char **arg) |
c906108c | 6340 | { |
c5aa993b JM |
6341 | static char filename[1024]; |
6342 | char *arg_p = *arg; | |
6343 | int i; | |
6344 | char c; | |
6345 | ||
c906108c SS |
6346 | if ((*arg_p == '\0') || isspace (*arg_p)) |
6347 | return NULL; | |
c5aa993b JM |
6348 | |
6349 | for (i = 0;; i++) | |
c906108c SS |
6350 | { |
6351 | c = *arg_p; | |
6352 | if (isspace (c)) | |
c5aa993b | 6353 | c = '\0'; |
c906108c SS |
6354 | filename[i] = c; |
6355 | if (c == '\0') | |
c5aa993b | 6356 | break; |
c906108c SS |
6357 | arg_p++; |
6358 | } | |
6359 | *arg = arg_p; | |
c5aa993b | 6360 | |
c906108c SS |
6361 | return filename; |
6362 | } | |
c5aa993b | 6363 | |
c906108c SS |
6364 | /* Commands to deal with catching events, such as signals, exceptions, |
6365 | process start/exit, etc. */ | |
c5aa993b JM |
6366 | |
6367 | typedef enum | |
6368 | { | |
44feb3ce TT |
6369 | catch_fork_temporary, catch_vfork_temporary, |
6370 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
6371 | } |
6372 | catch_fork_kind; | |
6373 | ||
c906108c | 6374 | static void |
44feb3ce | 6375 | catch_fork_command_1 (char *arg, int from_tty, struct cmd_list_element *command) |
c906108c | 6376 | { |
c5aa993b | 6377 | char *cond_string = NULL; |
44feb3ce TT |
6378 | catch_fork_kind fork_kind; |
6379 | int tempflag; | |
6380 | ||
6381 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
6382 | tempflag = (fork_kind == catch_fork_temporary | |
6383 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 6384 | |
44feb3ce TT |
6385 | if (!arg) |
6386 | arg = ""; | |
c906108c | 6387 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 6388 | |
c906108c | 6389 | /* The allowed syntax is: |
c5aa993b JM |
6390 | catch [v]fork |
6391 | catch [v]fork if <cond> | |
6392 | ||
c906108c SS |
6393 | First, check if there's an if clause. */ |
6394 | cond_string = ep_parse_optional_if_clause (&arg); | |
c5aa993b | 6395 | |
c906108c | 6396 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 6397 | error (_("Junk at end of arguments.")); |
c5aa993b | 6398 | |
c906108c SS |
6399 | /* If this target supports it, create a fork or vfork catchpoint |
6400 | and enable reporting of such events. */ | |
c5aa993b JM |
6401 | switch (fork_kind) |
6402 | { | |
44feb3ce TT |
6403 | case catch_fork_temporary: |
6404 | case catch_fork_permanent: | |
ce78b96d JB |
6405 | create_fork_vfork_event_catchpoint (tempflag, cond_string, |
6406 | &catch_fork_breakpoint_ops); | |
c906108c | 6407 | break; |
44feb3ce TT |
6408 | case catch_vfork_temporary: |
6409 | case catch_vfork_permanent: | |
ce78b96d JB |
6410 | create_fork_vfork_event_catchpoint (tempflag, cond_string, |
6411 | &catch_vfork_breakpoint_ops); | |
c906108c | 6412 | break; |
c5aa993b | 6413 | default: |
8a3fe4f8 | 6414 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 6415 | break; |
c5aa993b | 6416 | } |
c906108c SS |
6417 | } |
6418 | ||
6419 | static void | |
44feb3ce | 6420 | catch_exec_command_1 (char *arg, int from_tty, struct cmd_list_element *command) |
c906108c | 6421 | { |
44feb3ce | 6422 | int tempflag; |
c5aa993b | 6423 | char *cond_string = NULL; |
c906108c | 6424 | |
44feb3ce TT |
6425 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
6426 | ||
6427 | if (!arg) | |
6428 | arg = ""; | |
c906108c SS |
6429 | ep_skip_leading_whitespace (&arg); |
6430 | ||
6431 | /* The allowed syntax is: | |
c5aa993b JM |
6432 | catch exec |
6433 | catch exec if <cond> | |
c906108c SS |
6434 | |
6435 | First, check if there's an if clause. */ | |
6436 | cond_string = ep_parse_optional_if_clause (&arg); | |
6437 | ||
6438 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 6439 | error (_("Junk at end of arguments.")); |
c906108c SS |
6440 | |
6441 | /* If this target supports it, create an exec catchpoint | |
6442 | and enable reporting of such events. */ | |
fe798b75 | 6443 | create_catchpoint (tempflag, cond_string, &catch_exec_breakpoint_ops); |
c906108c | 6444 | } |
c5aa993b | 6445 | |
3086aeae DJ |
6446 | static enum print_stop_action |
6447 | print_exception_catchpoint (struct breakpoint *b) | |
6448 | { | |
ade92717 | 6449 | int bp_temp, bp_throw; |
3086aeae | 6450 | |
ade92717 | 6451 | annotate_catchpoint (b->number); |
3086aeae | 6452 | |
ade92717 AR |
6453 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
6454 | if (b->loc->address != b->loc->requested_address) | |
6455 | breakpoint_adjustment_warning (b->loc->requested_address, | |
6456 | b->loc->address, | |
6457 | b->number, 1); | |
6458 | bp_temp = b->loc->owner->disposition == disp_del; | |
6459 | ui_out_text (uiout, | |
6460 | bp_temp ? "Temporary catchpoint " | |
6461 | : "Catchpoint "); | |
6462 | if (!ui_out_is_mi_like_p (uiout)) | |
6463 | ui_out_field_int (uiout, "bkptno", b->number); | |
6464 | ui_out_text (uiout, | |
c0b37c48 AR |
6465 | bp_throw ? " (exception thrown), " |
6466 | : " (exception caught), "); | |
ade92717 AR |
6467 | if (ui_out_is_mi_like_p (uiout)) |
6468 | { | |
6469 | ui_out_field_string (uiout, "reason", | |
6470 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
6471 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
6472 | ui_out_field_int (uiout, "bkptno", b->number); | |
6473 | } | |
3086aeae DJ |
6474 | return PRINT_SRC_AND_LOC; |
6475 | } | |
6476 | ||
6477 | static void | |
6478 | print_one_exception_catchpoint (struct breakpoint *b, CORE_ADDR *last_addr) | |
6479 | { | |
79a45b7d TT |
6480 | struct value_print_options opts; |
6481 | get_user_print_options (&opts); | |
6482 | if (opts.addressprint) | |
3086aeae DJ |
6483 | { |
6484 | annotate_field (4); | |
604133b5 AR |
6485 | if (b->loc == NULL || b->loc->shlib_disabled) |
6486 | ui_out_field_string (uiout, "addr", "<PENDING>"); | |
6487 | else | |
6488 | ui_out_field_core_addr (uiout, "addr", b->loc->address); | |
3086aeae DJ |
6489 | } |
6490 | annotate_field (5); | |
604133b5 AR |
6491 | if (b->loc) |
6492 | *last_addr = b->loc->address; | |
3086aeae DJ |
6493 | if (strstr (b->addr_string, "throw") != NULL) |
6494 | ui_out_field_string (uiout, "what", "exception throw"); | |
6495 | else | |
6496 | ui_out_field_string (uiout, "what", "exception catch"); | |
6497 | } | |
6498 | ||
6499 | static void | |
6500 | print_mention_exception_catchpoint (struct breakpoint *b) | |
6501 | { | |
ade92717 AR |
6502 | int bp_temp; |
6503 | int bp_throw; | |
6504 | ||
6505 | bp_temp = b->loc->owner->disposition == disp_del; | |
6506 | bp_throw = strstr (b->addr_string, "throw") != NULL; | |
6507 | ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ") | |
6508 | : _("Catchpoint ")); | |
6509 | ui_out_field_int (uiout, "bkptno", b->number); | |
6510 | ui_out_text (uiout, bp_throw ? _(" (throw)") | |
6511 | : _(" (catch)")); | |
3086aeae DJ |
6512 | } |
6513 | ||
6514 | static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = { | |
ce78b96d JB |
6515 | NULL, /* insert */ |
6516 | NULL, /* remove */ | |
6517 | NULL, /* breakpoint_hit */ | |
3086aeae DJ |
6518 | print_exception_catchpoint, |
6519 | print_one_exception_catchpoint, | |
6520 | print_mention_exception_catchpoint | |
6521 | }; | |
6522 | ||
6523 | static int | |
6524 | handle_gnu_v3_exceptions (int tempflag, char *cond_string, | |
6525 | enum exception_event_kind ex_event, int from_tty) | |
6526 | { | |
604133b5 AR |
6527 | char *trigger_func_name; |
6528 | ||
3086aeae | 6529 | if (ex_event == EX_EVENT_CATCH) |
604133b5 | 6530 | trigger_func_name = "__cxa_begin_catch"; |
3086aeae | 6531 | else |
604133b5 | 6532 | trigger_func_name = "__cxa_throw"; |
3086aeae | 6533 | |
604133b5 AR |
6534 | break_command_really (trigger_func_name, cond_string, -1, |
6535 | 0 /* condition and thread are valid. */, | |
ade92717 | 6536 | tempflag, 0, |
604133b5 AR |
6537 | 0, |
6538 | AUTO_BOOLEAN_TRUE /* pending */, | |
6539 | &gnu_v3_exception_catchpoint_ops, from_tty); | |
3086aeae | 6540 | |
3086aeae DJ |
6541 | return 1; |
6542 | } | |
6543 | ||
c5aa993b | 6544 | /* Deal with "catch catch" and "catch throw" commands */ |
c906108c SS |
6545 | |
6546 | static void | |
fba45db2 KB |
6547 | catch_exception_command_1 (enum exception_event_kind ex_event, char *arg, |
6548 | int tempflag, int from_tty) | |
c906108c | 6549 | { |
c5aa993b JM |
6550 | char *cond_string = NULL; |
6551 | struct symtab_and_line *sal = NULL; | |
6552 | ||
44feb3ce TT |
6553 | if (!arg) |
6554 | arg = ""; | |
c906108c | 6555 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 6556 | |
c906108c SS |
6557 | cond_string = ep_parse_optional_if_clause (&arg); |
6558 | ||
6559 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 6560 | error (_("Junk at end of arguments.")); |
c906108c SS |
6561 | |
6562 | if ((ex_event != EX_EVENT_THROW) && | |
6563 | (ex_event != EX_EVENT_CATCH)) | |
8a3fe4f8 | 6564 | error (_("Unsupported or unknown exception event; cannot catch it")); |
c906108c | 6565 | |
3086aeae DJ |
6566 | if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty)) |
6567 | return; | |
6568 | ||
8a3fe4f8 | 6569 | warning (_("Unsupported with this platform/compiler combination.")); |
c906108c SS |
6570 | } |
6571 | ||
44feb3ce TT |
6572 | /* Implementation of "catch catch" command. */ |
6573 | ||
6574 | static void | |
6575 | catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command) | |
6576 | { | |
6577 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
6578 | catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty); | |
6579 | } | |
6580 | ||
6581 | /* Implementation of "catch throw" command. */ | |
6582 | ||
6583 | static void | |
6584 | catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command) | |
6585 | { | |
6586 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
6587 | catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty); | |
6588 | } | |
6589 | ||
f7f9143b JB |
6590 | /* Create a breakpoint struct for Ada exception catchpoints. */ |
6591 | ||
6592 | static void | |
6593 | create_ada_exception_breakpoint (struct symtab_and_line sal, | |
6594 | char *addr_string, | |
6595 | char *exp_string, | |
6596 | char *cond_string, | |
6597 | struct expression *cond, | |
6598 | struct breakpoint_ops *ops, | |
6599 | int tempflag, | |
6600 | int from_tty) | |
6601 | { | |
6602 | struct breakpoint *b; | |
6603 | ||
6604 | if (from_tty) | |
6605 | { | |
6606 | describe_other_breakpoints (sal.pc, sal.section, -1); | |
6607 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special | |
6608 | version for exception catchpoints, because two catchpoints | |
6609 | used for different exception names will use the same address. | |
6610 | In this case, a "breakpoint ... also set at..." warning is | |
6611 | unproductive. Besides. the warning phrasing is also a bit | |
6612 | inapropriate, we should use the word catchpoint, and tell | |
6613 | the user what type of catchpoint it is. The above is good | |
6614 | enough for now, though. */ | |
6615 | } | |
6616 | ||
6617 | b = set_raw_breakpoint (sal, bp_breakpoint); | |
6618 | set_breakpoint_count (breakpoint_count + 1); | |
6619 | ||
6620 | b->enable_state = bp_enabled; | |
6621 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
6622 | b->number = breakpoint_count; | |
6623 | b->ignore_count = 0; | |
511a6cd4 | 6624 | b->loc->cond = cond; |
f7f9143b JB |
6625 | b->addr_string = addr_string; |
6626 | b->language = language_ada; | |
6627 | b->cond_string = cond_string; | |
6628 | b->exp_string = exp_string; | |
6629 | b->thread = -1; | |
6630 | b->ops = ops; | |
f7f9143b JB |
6631 | |
6632 | mention (b); | |
b60e7edf | 6633 | update_global_location_list (1); |
f7f9143b JB |
6634 | } |
6635 | ||
6636 | /* Implement the "catch exception" command. */ | |
6637 | ||
6638 | static void | |
44feb3ce TT |
6639 | catch_ada_exception_command (char *arg, int from_tty, |
6640 | struct cmd_list_element *command) | |
f7f9143b | 6641 | { |
44feb3ce | 6642 | int tempflag; |
f7f9143b JB |
6643 | struct symtab_and_line sal; |
6644 | enum bptype type; | |
6645 | char *addr_string = NULL; | |
6646 | char *exp_string = NULL; | |
6647 | char *cond_string = NULL; | |
6648 | struct expression *cond = NULL; | |
6649 | struct breakpoint_ops *ops = NULL; | |
6650 | ||
44feb3ce TT |
6651 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
6652 | ||
6653 | if (!arg) | |
6654 | arg = ""; | |
f7f9143b JB |
6655 | sal = ada_decode_exception_location (arg, &addr_string, &exp_string, |
6656 | &cond_string, &cond, &ops); | |
6657 | create_ada_exception_breakpoint (sal, addr_string, exp_string, | |
6658 | cond_string, cond, ops, tempflag, | |
6659 | from_tty); | |
6660 | } | |
6661 | ||
6662 | /* Implement the "catch assert" command. */ | |
6663 | ||
6664 | static void | |
44feb3ce | 6665 | catch_assert_command (char *arg, int from_tty, struct cmd_list_element *command) |
f7f9143b | 6666 | { |
44feb3ce | 6667 | int tempflag; |
f7f9143b JB |
6668 | struct symtab_and_line sal; |
6669 | char *addr_string = NULL; | |
6670 | struct breakpoint_ops *ops = NULL; | |
6671 | ||
44feb3ce TT |
6672 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
6673 | ||
6674 | if (!arg) | |
6675 | arg = ""; | |
f7f9143b JB |
6676 | sal = ada_decode_assert_location (arg, &addr_string, &ops); |
6677 | create_ada_exception_breakpoint (sal, addr_string, NULL, NULL, NULL, ops, | |
6678 | tempflag, from_tty); | |
6679 | } | |
6680 | ||
c906108c | 6681 | static void |
fba45db2 | 6682 | catch_command (char *arg, int from_tty) |
c906108c | 6683 | { |
44feb3ce | 6684 | error (_("Catch requires an event name.")); |
c906108c SS |
6685 | } |
6686 | \f | |
6687 | ||
6688 | static void | |
fba45db2 | 6689 | tcatch_command (char *arg, int from_tty) |
c906108c | 6690 | { |
44feb3ce | 6691 | error (_("Catch requires an event name.")); |
c906108c SS |
6692 | } |
6693 | ||
80f8a6eb | 6694 | /* Delete breakpoints by address or line. */ |
c906108c SS |
6695 | |
6696 | static void | |
fba45db2 | 6697 | clear_command (char *arg, int from_tty) |
c906108c | 6698 | { |
d6e956e5 VP |
6699 | struct breakpoint *b; |
6700 | VEC(breakpoint_p) *found = 0; | |
6701 | int ix; | |
c906108c SS |
6702 | int default_match; |
6703 | struct symtabs_and_lines sals; | |
6704 | struct symtab_and_line sal; | |
c906108c SS |
6705 | int i; |
6706 | ||
6707 | if (arg) | |
6708 | { | |
6709 | sals = decode_line_spec (arg, 1); | |
6710 | default_match = 0; | |
6711 | } | |
6712 | else | |
6713 | { | |
c5aa993b | 6714 | sals.sals = (struct symtab_and_line *) |
c906108c | 6715 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 6716 | make_cleanup (xfree, sals.sals); |
fe39c653 | 6717 | init_sal (&sal); /* initialize to zeroes */ |
c906108c SS |
6718 | sal.line = default_breakpoint_line; |
6719 | sal.symtab = default_breakpoint_symtab; | |
6720 | sal.pc = default_breakpoint_address; | |
6721 | if (sal.symtab == 0) | |
8a3fe4f8 | 6722 | error (_("No source file specified.")); |
c906108c SS |
6723 | |
6724 | sals.sals[0] = sal; | |
6725 | sals.nelts = 1; | |
6726 | ||
6727 | default_match = 1; | |
6728 | } | |
6729 | ||
ed0616c6 VP |
6730 | /* We don't call resolve_sal_pc here. That's not |
6731 | as bad as it seems, because all existing breakpoints | |
6732 | typically have both file/line and pc set. So, if | |
6733 | clear is given file/line, we can match this to existing | |
6734 | breakpoint without obtaining pc at all. | |
6735 | ||
6736 | We only support clearing given the address explicitly | |
6737 | present in breakpoint table. Say, we've set breakpoint | |
6738 | at file:line. There were several PC values for that file:line, | |
6739 | due to optimization, all in one block. | |
6740 | We've picked one PC value. If "clear" is issued with another | |
6741 | PC corresponding to the same file:line, the breakpoint won't | |
6742 | be cleared. We probably can still clear the breakpoint, but | |
6743 | since the other PC value is never presented to user, user | |
6744 | can only find it by guessing, and it does not seem important | |
6745 | to support that. */ | |
6746 | ||
c906108c | 6747 | /* For each line spec given, delete bps which correspond |
80f8a6eb MS |
6748 | to it. Do it in two passes, solely to preserve the current |
6749 | behavior that from_tty is forced true if we delete more than | |
6750 | one breakpoint. */ | |
c906108c | 6751 | |
80f8a6eb | 6752 | found = NULL; |
c906108c SS |
6753 | for (i = 0; i < sals.nelts; i++) |
6754 | { | |
6755 | /* If exact pc given, clear bpts at that pc. | |
c5aa993b JM |
6756 | If line given (pc == 0), clear all bpts on specified line. |
6757 | If defaulting, clear all bpts on default line | |
c906108c | 6758 | or at default pc. |
c5aa993b JM |
6759 | |
6760 | defaulting sal.pc != 0 tests to do | |
6761 | ||
6762 | 0 1 pc | |
6763 | 1 1 pc _and_ line | |
6764 | 0 0 line | |
6765 | 1 0 <can't happen> */ | |
c906108c SS |
6766 | |
6767 | sal = sals.sals[i]; | |
c906108c | 6768 | |
d6e956e5 VP |
6769 | /* Find all matching breakpoints and add them to |
6770 | 'found'. */ | |
6771 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6772 | { |
0d381245 | 6773 | int match = 0; |
80f8a6eb MS |
6774 | /* Are we going to delete b? */ |
6775 | if (b->type != bp_none | |
6776 | && b->type != bp_watchpoint | |
6777 | && b->type != bp_hardware_watchpoint | |
6778 | && b->type != bp_read_watchpoint | |
0d381245 VP |
6779 | && b->type != bp_access_watchpoint) |
6780 | { | |
6781 | struct bp_location *loc = b->loc; | |
6782 | for (; loc; loc = loc->next) | |
6783 | { | |
6784 | int pc_match = sal.pc | |
6785 | && (loc->address == sal.pc) | |
6786 | && (!section_is_overlay (loc->section) | |
6787 | || loc->section == sal.section); | |
6788 | int line_match = ((default_match || (0 == sal.pc)) | |
6789 | && b->source_file != NULL | |
6790 | && sal.symtab != NULL | |
6791 | && strcmp (b->source_file, sal.symtab->filename) == 0 | |
6792 | && b->line_number == sal.line); | |
6793 | if (pc_match || line_match) | |
6794 | { | |
6795 | match = 1; | |
6796 | break; | |
6797 | } | |
6798 | } | |
6799 | } | |
6800 | ||
6801 | if (match) | |
d6e956e5 | 6802 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 6803 | } |
80f8a6eb MS |
6804 | } |
6805 | /* Now go thru the 'found' chain and delete them. */ | |
d6e956e5 | 6806 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
6807 | { |
6808 | if (arg) | |
8a3fe4f8 | 6809 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 6810 | else |
8a3fe4f8 | 6811 | error (_("No breakpoint at this line.")); |
80f8a6eb | 6812 | } |
c906108c | 6813 | |
d6e956e5 | 6814 | if (VEC_length(breakpoint_p, found) > 1) |
80f8a6eb MS |
6815 | from_tty = 1; /* Always report if deleted more than one */ |
6816 | if (from_tty) | |
a3f17187 | 6817 | { |
d6e956e5 | 6818 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
6819 | printf_unfiltered (_("Deleted breakpoint ")); |
6820 | else | |
6821 | printf_unfiltered (_("Deleted breakpoints ")); | |
6822 | } | |
80f8a6eb | 6823 | breakpoints_changed (); |
d6e956e5 VP |
6824 | |
6825 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 6826 | { |
c5aa993b | 6827 | if (from_tty) |
d6e956e5 VP |
6828 | printf_unfiltered ("%d ", b->number); |
6829 | delete_breakpoint (b); | |
c906108c | 6830 | } |
80f8a6eb MS |
6831 | if (from_tty) |
6832 | putchar_unfiltered ('\n'); | |
c906108c SS |
6833 | } |
6834 | \f | |
6835 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
6836 | all breakpoints that are marked for deletion, whether hit or not. | |
6837 | This is called after any breakpoint is hit, or after errors. */ | |
6838 | ||
6839 | void | |
fba45db2 | 6840 | breakpoint_auto_delete (bpstat bs) |
c906108c SS |
6841 | { |
6842 | struct breakpoint *b, *temp; | |
6843 | ||
6844 | for (; bs; bs = bs->next) | |
20874c92 VP |
6845 | if (bs->breakpoint_at |
6846 | && bs->breakpoint_at->owner | |
6847 | && bs->breakpoint_at->owner->disposition == disp_del | |
c906108c | 6848 | && bs->stop) |
4f8d1dc6 | 6849 | delete_breakpoint (bs->breakpoint_at->owner); |
c906108c SS |
6850 | |
6851 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b | 6852 | { |
b5de0fa7 | 6853 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
6854 | delete_breakpoint (b); |
6855 | } | |
c906108c SS |
6856 | } |
6857 | ||
4cd9bd08 | 6858 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
b60e7edf PA |
6859 | into the inferior, only remove already-inserted locations that no |
6860 | longer should be inserted. Functions that delete a breakpoint or | |
6861 | breakpoints should pass false, so that deleting a breakpoint | |
6862 | doesn't have the side effect of inserting the locations of other | |
6863 | breakpoints that are marked not-inserted, but should_be_inserted | |
6864 | returns true on them. | |
6865 | ||
6866 | This behaviour is useful is situations close to tear-down -- e.g., | |
6867 | after an exec, while the target still has execution, but breakpoint | |
6868 | shadows of the previous executable image should *NOT* be restored | |
6869 | to the new image; or before detaching, where the target still has | |
6870 | execution and wants to delete breakpoints from GDB's lists, and all | |
6871 | breakpoints had already been removed from the inferior. */ | |
6872 | ||
0d381245 | 6873 | static void |
b60e7edf | 6874 | update_global_location_list (int should_insert) |
0d381245 | 6875 | { |
74960c60 VP |
6876 | struct breakpoint *b; |
6877 | struct bp_location **next = &bp_location_chain; | |
6878 | struct bp_location *loc; | |
6879 | struct bp_location *loc2; | |
6880 | struct gdb_exception e; | |
6881 | VEC(bp_location_p) *old_locations = NULL; | |
6882 | int ret; | |
6883 | int ix; | |
6884 | ||
6885 | /* Store old locations for future reference. */ | |
6886 | for (loc = bp_location_chain; loc; loc = loc->global_next) | |
6887 | VEC_safe_push (bp_location_p, old_locations, loc); | |
0d381245 | 6888 | |
74960c60 VP |
6889 | bp_location_chain = NULL; |
6890 | ALL_BREAKPOINTS (b) | |
0d381245 | 6891 | { |
74960c60 | 6892 | for (loc = b->loc; loc; loc = loc->next) |
0d381245 | 6893 | { |
74960c60 VP |
6894 | *next = loc; |
6895 | next = &(loc->global_next); | |
6896 | *next = NULL; | |
0d381245 | 6897 | } |
74960c60 VP |
6898 | } |
6899 | ||
6900 | /* Identify bp_location instances that are no longer present in the new | |
6901 | list, and therefore should be freed. Note that it's not necessary that | |
6902 | those locations should be removed from inferior -- if there's another | |
6903 | location at the same address (previously marked as duplicate), | |
6904 | we don't need to remove/insert the location. */ | |
6905 | for (ix = 0; VEC_iterate(bp_location_p, old_locations, ix, loc); ++ix) | |
6906 | { | |
6907 | /* Tells if 'loc' is found amoung the new locations. If not, we | |
6908 | have to free it. */ | |
6909 | int found_object = 0; | |
20874c92 VP |
6910 | /* Tells if the location should remain inserted in the target. */ |
6911 | int keep_in_target = 0; | |
6912 | int removed = 0; | |
74960c60 VP |
6913 | for (loc2 = bp_location_chain; loc2; loc2 = loc2->global_next) |
6914 | if (loc2 == loc) | |
6915 | { | |
6916 | found_object = 1; | |
6917 | break; | |
6918 | } | |
6919 | ||
6920 | /* If this location is no longer present, and inserted, look if there's | |
6921 | maybe a new location at the same address. If so, mark that one | |
6922 | inserted, and don't remove this one. This is needed so that we | |
6923 | don't have a time window where a breakpoint at certain location is not | |
6924 | inserted. */ | |
6925 | ||
6926 | if (loc->inserted) | |
0d381245 | 6927 | { |
74960c60 | 6928 | /* If the location is inserted now, we might have to remove it. */ |
74960c60 VP |
6929 | |
6930 | if (found_object && should_be_inserted (loc)) | |
6931 | { | |
6932 | /* The location is still present in the location list, and still | |
6933 | should be inserted. Don't do anything. */ | |
20874c92 | 6934 | keep_in_target = 1; |
74960c60 VP |
6935 | } |
6936 | else | |
6937 | { | |
6938 | /* The location is either no longer present, or got disabled. | |
6939 | See if there's another location at the same address, in which | |
6940 | case we don't need to remove this one from the target. */ | |
6941 | if (breakpoint_address_is_meaningful (loc->owner)) | |
6942 | for (loc2 = bp_location_chain; loc2; loc2 = loc2->global_next) | |
6943 | { | |
6944 | /* For the sake of should_insert_location. The | |
6945 | call to check_duplicates will fix up this later. */ | |
6946 | loc2->duplicate = 0; | |
6947 | if (should_be_inserted (loc2) | |
6948 | && loc2 != loc && loc2->address == loc->address) | |
6949 | { | |
6950 | loc2->inserted = 1; | |
6951 | loc2->target_info = loc->target_info; | |
20874c92 | 6952 | keep_in_target = 1; |
74960c60 VP |
6953 | break; |
6954 | } | |
6955 | } | |
6956 | } | |
6957 | ||
20874c92 VP |
6958 | if (!keep_in_target) |
6959 | { | |
6960 | if (remove_breakpoint (loc, mark_uninserted)) | |
6961 | { | |
6962 | /* This is just about all we can do. We could keep this | |
6963 | location on the global list, and try to remove it next | |
6964 | time, but there's no particular reason why we will | |
6965 | succeed next time. | |
6966 | ||
6967 | Note that at this point, loc->owner is still valid, | |
6968 | as delete_breakpoint frees the breakpoint only | |
6969 | after calling us. */ | |
6970 | printf_filtered (_("warning: Error removing breakpoint %d\n"), | |
6971 | loc->owner->number); | |
6972 | } | |
6973 | removed = 1; | |
6974 | } | |
0d381245 | 6975 | } |
74960c60 VP |
6976 | |
6977 | if (!found_object) | |
1c5cfe86 PA |
6978 | { |
6979 | if (removed && non_stop) | |
20874c92 VP |
6980 | { |
6981 | /* This location was removed from the targets. In non-stop mode, | |
6982 | a race condition is possible where we've removed a breakpoint, | |
6983 | but stop events for that breakpoint are already queued and will | |
6984 | arrive later. To suppress spurious SIGTRAPs reported to user, | |
6985 | we keep this breakpoint location for a bit, and will retire it | |
6986 | after we see 3 * thread_count events. | |
1c5cfe86 | 6987 | The theory here is that reporting of events should, |
20874c92 VP |
6988 | "on the average", be fair, so after that many event we'll see |
6989 | events from all threads that have anything of interest, and no | |
1c5cfe86 | 6990 | longer need to keep this breakpoint. This is just a |
20874c92 | 6991 | heuristic, but if it's wrong, we'll report unexpected SIGTRAP, |
1c5cfe86 | 6992 | which is usability issue, but not a correctness problem. */ |
20874c92 VP |
6993 | loc->events_till_retirement = 3 * (thread_count () + 1); |
6994 | loc->owner = NULL; | |
20874c92 | 6995 | |
1c5cfe86 PA |
6996 | VEC_safe_push (bp_location_p, moribund_locations, loc); |
6997 | } | |
6998 | else | |
6999 | free_bp_location (loc); | |
20874c92 | 7000 | } |
74960c60 | 7001 | } |
1c5cfe86 | 7002 | |
74960c60 VP |
7003 | ALL_BREAKPOINTS (b) |
7004 | { | |
7005 | check_duplicates (b); | |
0d381245 | 7006 | } |
74960c60 | 7007 | |
50c71eaf PA |
7008 | if (breakpoints_always_inserted_mode () && should_insert |
7009 | && (target_has_execution | |
7010 | || (gdbarch_has_global_solist (target_gdbarch) | |
7011 | && target_supports_multi_process ()))) | |
74960c60 VP |
7012 | insert_breakpoint_locations (); |
7013 | } | |
7014 | ||
20874c92 VP |
7015 | void |
7016 | breakpoint_retire_moribund (void) | |
7017 | { | |
7018 | struct bp_location *loc; | |
7019 | int ix; | |
7020 | ||
7021 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
7022 | if (--(loc->events_till_retirement) == 0) | |
7023 | { | |
7024 | free_bp_location (loc); | |
7025 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
7026 | --ix; | |
7027 | } | |
7028 | } | |
7029 | ||
74960c60 | 7030 | static void |
b60e7edf | 7031 | update_global_location_list_nothrow (int inserting) |
74960c60 VP |
7032 | { |
7033 | struct gdb_exception e; | |
7034 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
b60e7edf | 7035 | update_global_location_list (inserting); |
0d381245 VP |
7036 | } |
7037 | ||
a474d7c2 PA |
7038 | /* Clear BPT from a BPS. */ |
7039 | static void | |
7040 | bpstat_remove_breakpoint (bpstat bps, struct breakpoint *bpt) | |
7041 | { | |
7042 | bpstat bs; | |
7043 | for (bs = bps; bs; bs = bs->next) | |
7044 | if (bs->breakpoint_at && bs->breakpoint_at->owner == bpt) | |
7045 | { | |
7046 | bs->breakpoint_at = NULL; | |
7047 | bs->old_val = NULL; | |
7048 | /* bs->commands will be freed later. */ | |
7049 | } | |
7050 | } | |
7051 | ||
7052 | /* Callback for iterate_over_threads. */ | |
7053 | static int | |
7054 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
7055 | { | |
7056 | struct breakpoint *bpt = data; | |
7057 | bpstat_remove_breakpoint (th->stop_bpstat, bpt); | |
7058 | return 0; | |
7059 | } | |
7060 | ||
53a5351d JM |
7061 | /* Delete a breakpoint and clean up all traces of it in the data |
7062 | structures. */ | |
c906108c SS |
7063 | |
7064 | void | |
fba45db2 | 7065 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 7066 | { |
52f0bd74 | 7067 | struct breakpoint *b; |
74960c60 | 7068 | struct bp_location *loc, *next; |
c906108c | 7069 | |
8a3fe4f8 | 7070 | gdb_assert (bpt != NULL); |
c906108c SS |
7071 | |
7072 | /* Has this bp already been deleted? This can happen because multiple | |
7073 | lists can hold pointers to bp's. bpstat lists are especial culprits. | |
7074 | ||
7075 | One example of this happening is a watchpoint's scope bp. When the | |
7076 | scope bp triggers, we notice that the watchpoint is out of scope, and | |
7077 | delete it. We also delete its scope bp. But the scope bp is marked | |
7078 | "auto-deleting", and is already on a bpstat. That bpstat is then | |
7079 | checked for auto-deleting bp's, which are deleted. | |
7080 | ||
7081 | A real solution to this problem might involve reference counts in bp's, | |
7082 | and/or giving them pointers back to their referencing bpstat's, and | |
7083 | teaching delete_breakpoint to only free a bp's storage when no more | |
1272ad14 | 7084 | references were extent. A cheaper bandaid was chosen. */ |
c906108c SS |
7085 | if (bpt->type == bp_none) |
7086 | return; | |
7087 | ||
383f836e | 7088 | observer_notify_breakpoint_deleted (bpt->number); |
c906108c | 7089 | |
c906108c SS |
7090 | if (breakpoint_chain == bpt) |
7091 | breakpoint_chain = bpt->next; | |
7092 | ||
c906108c SS |
7093 | ALL_BREAKPOINTS (b) |
7094 | if (b->next == bpt) | |
c5aa993b JM |
7095 | { |
7096 | b->next = bpt->next; | |
7097 | break; | |
7098 | } | |
c906108c | 7099 | |
c906108c | 7100 | free_command_lines (&bpt->commands); |
c906108c | 7101 | if (bpt->cond_string != NULL) |
b8c9b27d | 7102 | xfree (bpt->cond_string); |
c906108c | 7103 | if (bpt->addr_string != NULL) |
b8c9b27d | 7104 | xfree (bpt->addr_string); |
c906108c | 7105 | if (bpt->exp != NULL) |
b8c9b27d | 7106 | xfree (bpt->exp); |
c906108c | 7107 | if (bpt->exp_string != NULL) |
b8c9b27d | 7108 | xfree (bpt->exp_string); |
c906108c SS |
7109 | if (bpt->val != NULL) |
7110 | value_free (bpt->val); | |
7111 | if (bpt->source_file != NULL) | |
b8c9b27d | 7112 | xfree (bpt->source_file); |
c906108c | 7113 | if (bpt->exec_pathname != NULL) |
b8c9b27d | 7114 | xfree (bpt->exec_pathname); |
c906108c SS |
7115 | |
7116 | /* Be sure no bpstat's are pointing at it after it's been freed. */ | |
7117 | /* FIXME, how can we find all bpstat's? | |
198757a8 VP |
7118 | We just check stop_bpstat for now. Note that we cannot just |
7119 | remove bpstats pointing at bpt from the stop_bpstat list | |
7120 | entirely, as breakpoint commands are associated with the bpstat; | |
7121 | if we remove it here, then the later call to | |
7122 | bpstat_do_actions (&stop_bpstat); | |
7123 | in event-top.c won't do anything, and temporary breakpoints | |
7124 | with commands won't work. */ | |
a474d7c2 | 7125 | |
a474d7c2 | 7126 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); |
74960c60 VP |
7127 | |
7128 | /* Now that breakpoint is removed from breakpoint | |
7129 | list, update the global location list. This | |
7130 | will remove locations that used to belong to | |
7131 | this breakpoint. Do this before freeing | |
7132 | the breakpoint itself, since remove_breakpoint | |
7133 | looks at location's owner. It might be better | |
7134 | design to have location completely self-contained, | |
7135 | but it's not the case now. */ | |
b60e7edf | 7136 | update_global_location_list (0); |
74960c60 VP |
7137 | |
7138 | ||
c906108c SS |
7139 | /* On the chance that someone will soon try again to delete this same |
7140 | bp, we mark it as deleted before freeing its storage. */ | |
7141 | bpt->type = bp_none; | |
7142 | ||
b8c9b27d | 7143 | xfree (bpt); |
c906108c SS |
7144 | } |
7145 | ||
4d6140d9 AC |
7146 | static void |
7147 | do_delete_breakpoint_cleanup (void *b) | |
7148 | { | |
7149 | delete_breakpoint (b); | |
7150 | } | |
7151 | ||
7152 | struct cleanup * | |
7153 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
7154 | { | |
7155 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
7156 | } | |
7157 | ||
c906108c | 7158 | void |
fba45db2 | 7159 | delete_command (char *arg, int from_tty) |
c906108c SS |
7160 | { |
7161 | struct breakpoint *b, *temp; | |
7162 | ||
ea9365bb TT |
7163 | dont_repeat (); |
7164 | ||
c906108c SS |
7165 | if (arg == 0) |
7166 | { | |
7167 | int breaks_to_delete = 0; | |
7168 | ||
7169 | /* Delete all breakpoints if no argument. | |
c5aa993b JM |
7170 | Do not delete internal or call-dummy breakpoints, these |
7171 | have to be deleted with an explicit breakpoint number argument. */ | |
7172 | ALL_BREAKPOINTS (b) | |
7173 | { | |
7174 | if (b->type != bp_call_dummy && | |
7175 | b->type != bp_shlib_event && | |
c4093a6a | 7176 | b->type != bp_thread_event && |
1900040c | 7177 | b->type != bp_overlay_event && |
c5aa993b | 7178 | b->number >= 0) |
973d738b DJ |
7179 | { |
7180 | breaks_to_delete = 1; | |
7181 | break; | |
7182 | } | |
c5aa993b | 7183 | } |
c906108c SS |
7184 | |
7185 | /* Ask user only if there are some breakpoints to delete. */ | |
7186 | if (!from_tty | |
e2e0b3e5 | 7187 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 7188 | { |
c5aa993b JM |
7189 | ALL_BREAKPOINTS_SAFE (b, temp) |
7190 | { | |
7191 | if (b->type != bp_call_dummy && | |
7192 | b->type != bp_shlib_event && | |
c4093a6a | 7193 | b->type != bp_thread_event && |
1900040c | 7194 | b->type != bp_overlay_event && |
c5aa993b JM |
7195 | b->number >= 0) |
7196 | delete_breakpoint (b); | |
7197 | } | |
c906108c SS |
7198 | } |
7199 | } | |
7200 | else | |
7201 | map_breakpoint_numbers (arg, delete_breakpoint); | |
7202 | } | |
7203 | ||
0d381245 VP |
7204 | static int |
7205 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 7206 | { |
0d381245 VP |
7207 | for (; loc; loc = loc->next) |
7208 | if (!loc->shlib_disabled) | |
7209 | return 0; | |
7210 | return 1; | |
fe3f5fa8 VP |
7211 | } |
7212 | ||
776592bf DE |
7213 | /* Subroutine of update_breakpoint_locations to simplify it. |
7214 | Return non-zero if multiple fns in list LOC have the same name. | |
7215 | Null names are ignored. */ | |
7216 | ||
7217 | static int | |
7218 | ambiguous_names_p (struct bp_location *loc) | |
7219 | { | |
7220 | struct bp_location *l; | |
7221 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
7222 | (int (*) (const void *, const void *)) streq, | |
7223 | NULL, xcalloc, xfree); | |
7224 | ||
7225 | for (l = loc; l != NULL; l = l->next) | |
7226 | { | |
7227 | const char **slot; | |
7228 | const char *name = l->function_name; | |
7229 | ||
7230 | /* Allow for some names to be NULL, ignore them. */ | |
7231 | if (name == NULL) | |
7232 | continue; | |
7233 | ||
7234 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
7235 | INSERT); | |
7236 | /* NOTE: We can assume slot != NULL here because xcalloc never returns | |
7237 | NULL. */ | |
7238 | if (*slot != NULL) | |
7239 | { | |
7240 | htab_delete (htab); | |
7241 | return 1; | |
7242 | } | |
7243 | *slot = name; | |
7244 | } | |
7245 | ||
7246 | htab_delete (htab); | |
7247 | return 0; | |
7248 | } | |
7249 | ||
fe3f5fa8 | 7250 | static void |
0d381245 VP |
7251 | update_breakpoint_locations (struct breakpoint *b, |
7252 | struct symtabs_and_lines sals) | |
fe3f5fa8 VP |
7253 | { |
7254 | int i; | |
7255 | char *s; | |
0d381245 VP |
7256 | struct bp_location *existing_locations = b->loc; |
7257 | ||
7258 | /* If there's no new locations, and all existing locations | |
7259 | are pending, don't do anything. This optimizes | |
7260 | the common case where all locations are in the same | |
7261 | shared library, that was unloaded. We'd like to | |
7262 | retain the location, so that when the library | |
7263 | is loaded again, we don't loose the enabled/disabled | |
7264 | status of the individual locations. */ | |
7265 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) | |
fe3f5fa8 VP |
7266 | return; |
7267 | ||
fe3f5fa8 VP |
7268 | b->loc = NULL; |
7269 | ||
0d381245 | 7270 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 7271 | { |
0d381245 | 7272 | struct bp_location *new_loc = |
39d61571 | 7273 | add_location_to_breakpoint (b, &(sals.sals[i])); |
fe3f5fa8 | 7274 | |
0d381245 VP |
7275 | /* Reparse conditions, they might contain references to the |
7276 | old symtab. */ | |
7277 | if (b->cond_string != NULL) | |
7278 | { | |
7279 | struct gdb_exception e; | |
fe3f5fa8 | 7280 | |
0d381245 VP |
7281 | s = b->cond_string; |
7282 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
7283 | { | |
7284 | new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), | |
7285 | 0); | |
7286 | } | |
7287 | if (e.reason < 0) | |
7288 | { | |
7289 | warning (_("failed to reevaluate condition for breakpoint %d: %s"), | |
7290 | b->number, e.message); | |
7291 | new_loc->enabled = 0; | |
7292 | } | |
7293 | } | |
fe3f5fa8 | 7294 | |
0d381245 VP |
7295 | if (b->source_file != NULL) |
7296 | xfree (b->source_file); | |
7297 | if (sals.sals[i].symtab == NULL) | |
7298 | b->source_file = NULL; | |
7299 | else | |
7300 | b->source_file = | |
7301 | savestring (sals.sals[i].symtab->filename, | |
7302 | strlen (sals.sals[i].symtab->filename)); | |
fe3f5fa8 | 7303 | |
0d381245 VP |
7304 | if (b->line_number == 0) |
7305 | b->line_number = sals.sals[i].line; | |
7306 | } | |
fe3f5fa8 | 7307 | |
514f746b AR |
7308 | /* Update locations of permanent breakpoints. */ |
7309 | if (b->enable_state == bp_permanent) | |
7310 | make_breakpoint_permanent (b); | |
7311 | ||
0d381245 VP |
7312 | /* If possible, carry over 'disable' status from existing breakpoints. */ |
7313 | { | |
7314 | struct bp_location *e = existing_locations; | |
776592bf DE |
7315 | /* If there are multiple breakpoints with the same function name, |
7316 | e.g. for inline functions, comparing function names won't work. | |
7317 | Instead compare pc addresses; this is just a heuristic as things | |
7318 | may have moved, but in practice it gives the correct answer | |
7319 | often enough until a better solution is found. */ | |
7320 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
7321 | ||
0d381245 VP |
7322 | for (; e; e = e->next) |
7323 | { | |
7324 | if (!e->enabled && e->function_name) | |
7325 | { | |
7326 | struct bp_location *l = b->loc; | |
776592bf DE |
7327 | if (have_ambiguous_names) |
7328 | { | |
7329 | for (; l; l = l->next) | |
7330 | if (e->address == l->address) | |
7331 | { | |
7332 | l->enabled = 0; | |
7333 | break; | |
7334 | } | |
7335 | } | |
7336 | else | |
7337 | { | |
7338 | for (; l; l = l->next) | |
7339 | if (l->function_name | |
7340 | && strcmp (e->function_name, l->function_name) == 0) | |
7341 | { | |
7342 | l->enabled = 0; | |
7343 | break; | |
7344 | } | |
7345 | } | |
0d381245 VP |
7346 | } |
7347 | } | |
7348 | } | |
fe3f5fa8 | 7349 | |
b60e7edf | 7350 | update_global_location_list (1); |
fe3f5fa8 VP |
7351 | } |
7352 | ||
7353 | ||
c906108c SS |
7354 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
7355 | The value we return ends up being the return value from catch_errors. | |
7356 | Unused in this case. */ | |
7357 | ||
7358 | static int | |
4efb68b1 | 7359 | breakpoint_re_set_one (void *bint) |
c906108c | 7360 | { |
53a5351d JM |
7361 | /* get past catch_errs */ |
7362 | struct breakpoint *b = (struct breakpoint *) bint; | |
c906108c SS |
7363 | struct value *mark; |
7364 | int i; | |
fe3f5fa8 VP |
7365 | int not_found = 0; |
7366 | int *not_found_ptr = ¬_found; | |
7367 | struct symtabs_and_lines sals = {}; | |
ed0616c6 | 7368 | struct symtabs_and_lines expanded; |
c906108c | 7369 | char *s; |
b5de0fa7 | 7370 | enum enable_state save_enable; |
fe3f5fa8 VP |
7371 | struct gdb_exception e; |
7372 | ||
c906108c SS |
7373 | |
7374 | switch (b->type) | |
7375 | { | |
7376 | case bp_none: | |
8a3fe4f8 | 7377 | warning (_("attempted to reset apparently deleted breakpoint #%d?"), |
53a5351d | 7378 | b->number); |
c906108c SS |
7379 | return 0; |
7380 | case bp_breakpoint: | |
7381 | case bp_hardware_breakpoint: | |
c906108c SS |
7382 | if (b->addr_string == NULL) |
7383 | { | |
7384 | /* Anything without a string can't be re-set. */ | |
7385 | delete_breakpoint (b); | |
7386 | return 0; | |
7387 | } | |
c906108c SS |
7388 | |
7389 | set_language (b->language); | |
7390 | input_radix = b->input_radix; | |
7391 | s = b->addr_string; | |
fe3f5fa8 | 7392 | TRY_CATCH (e, RETURN_MASK_ERROR) |
c906108c | 7393 | { |
fe3f5fa8 VP |
7394 | sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL, |
7395 | not_found_ptr); | |
7396 | } | |
7397 | if (e.reason < 0) | |
7398 | { | |
7399 | int not_found_and_ok = 0; | |
7400 | /* For pending breakpoints, it's expected that parsing | |
7401 | will fail until the right shared library is loaded. | |
7402 | User has already told to create pending breakpoints and | |
7403 | don't need extra messages. If breakpoint is in bp_shlib_disabled | |
7404 | state, then user already saw the message about that breakpoint | |
7405 | being disabled, and don't want to see more errors. */ | |
0d381245 VP |
7406 | if (not_found |
7407 | && (b->condition_not_parsed | |
7408 | || (b->loc && b->loc->shlib_disabled) | |
7409 | || b->enable_state == bp_disabled)) | |
fe3f5fa8 VP |
7410 | not_found_and_ok = 1; |
7411 | ||
7412 | if (!not_found_and_ok) | |
c906108c | 7413 | { |
fe3f5fa8 VP |
7414 | /* We surely don't want to warn about the same breakpoint |
7415 | 10 times. One solution, implemented here, is disable | |
7416 | the breakpoint on error. Another solution would be to | |
7417 | have separate 'warning emitted' flag. Since this | |
7418 | happens only when a binary has changed, I don't know | |
7419 | which approach is better. */ | |
7420 | b->enable_state = bp_disabled; | |
7421 | throw_exception (e); | |
c906108c | 7422 | } |
fe3f5fa8 | 7423 | } |
c906108c | 7424 | |
fe3f5fa8 VP |
7425 | if (not_found) |
7426 | break; | |
7427 | ||
7428 | gdb_assert (sals.nelts == 1); | |
7429 | resolve_sal_pc (&sals.sals[0]); | |
0d381245 | 7430 | if (b->condition_not_parsed && s && s[0]) |
fe3f5fa8 VP |
7431 | { |
7432 | char *cond_string = 0; | |
7433 | int thread = -1; | |
7434 | find_condition_and_thread (s, sals.sals[0].pc, | |
7435 | &cond_string, &thread); | |
7436 | if (cond_string) | |
7437 | b->cond_string = cond_string; | |
7438 | b->thread = thread; | |
0d381245 | 7439 | b->condition_not_parsed = 0; |
fe3f5fa8 | 7440 | } |
ed0616c6 VP |
7441 | expanded = expand_line_sal_maybe (sals.sals[0]); |
7442 | update_breakpoint_locations (b, expanded); | |
0d381245 | 7443 | |
b8c9b27d | 7444 | xfree (sals.sals); |
c906108c SS |
7445 | break; |
7446 | ||
7447 | case bp_watchpoint: | |
7448 | case bp_hardware_watchpoint: | |
7449 | case bp_read_watchpoint: | |
7450 | case bp_access_watchpoint: | |
0b3de036 VP |
7451 | /* Watchpoint can be either on expression using entirely global variables, |
7452 | or it can be on local variables. | |
7453 | ||
7454 | Watchpoints of the first kind are never auto-deleted, and even persist | |
7455 | across program restarts. Since they can use variables from shared | |
7456 | libraries, we need to reparse expression as libraries are loaded | |
7457 | and unloaded. | |
7458 | ||
7459 | Watchpoints on local variables can also change meaning as result | |
7460 | of solib event. For example, if a watchpoint uses both a local and | |
7461 | a global variables in expression, it's a local watchpoint, but | |
7462 | unloading of a shared library will make the expression invalid. | |
7463 | This is not a very common use case, but we still re-evaluate | |
7464 | expression, to avoid surprises to the user. | |
7465 | ||
7466 | Note that for local watchpoints, we re-evaluate it only if | |
7467 | watchpoints frame id is still valid. If it's not, it means | |
7468 | the watchpoint is out of scope and will be deleted soon. In fact, | |
7469 | I'm not sure we'll ever be called in this case. | |
7470 | ||
7471 | If a local watchpoint's frame id is still valid, then | |
7472 | b->exp_valid_block is likewise valid, and we can safely use it. | |
7473 | ||
7474 | Don't do anything about disabled watchpoints, since they will | |
7475 | be reevaluated again when enabled. */ | |
a5606eee | 7476 | update_watchpoint (b, 1 /* reparse */); |
c906108c | 7477 | break; |
c5aa993b JM |
7478 | /* We needn't really do anything to reset these, since the mask |
7479 | that requests them is unaffected by e.g., new libraries being | |
7480 | loaded. */ | |
ce78b96d | 7481 | case bp_catchpoint: |
c906108c | 7482 | break; |
c5aa993b | 7483 | |
c906108c | 7484 | default: |
a3f17187 | 7485 | printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type); |
c906108c | 7486 | /* fall through */ |
611c83ae PA |
7487 | /* Delete overlay event breakpoints; they will be reset later by |
7488 | breakpoint_re_set. */ | |
1900040c | 7489 | case bp_overlay_event: |
c906108c SS |
7490 | delete_breakpoint (b); |
7491 | break; | |
7492 | ||
c5aa993b JM |
7493 | /* This breakpoint is special, it's set up when the inferior |
7494 | starts and we really don't want to touch it. */ | |
c906108c SS |
7495 | case bp_shlib_event: |
7496 | ||
c4093a6a JM |
7497 | /* Like bp_shlib_event, this breakpoint type is special. |
7498 | Once it is set up, we do not want to touch it. */ | |
7499 | case bp_thread_event: | |
7500 | ||
c5aa993b JM |
7501 | /* Keep temporary breakpoints, which can be encountered when we step |
7502 | over a dlopen call and SOLIB_ADD is resetting the breakpoints. | |
7503 | Otherwise these should have been blown away via the cleanup chain | |
7504 | or by breakpoint_init_inferior when we rerun the executable. */ | |
c906108c SS |
7505 | case bp_until: |
7506 | case bp_finish: | |
7507 | case bp_watchpoint_scope: | |
7508 | case bp_call_dummy: | |
7509 | case bp_step_resume: | |
611c83ae PA |
7510 | case bp_longjmp: |
7511 | case bp_longjmp_resume: | |
c906108c SS |
7512 | break; |
7513 | } | |
7514 | ||
7515 | return 0; | |
7516 | } | |
7517 | ||
7518 | /* Re-set all breakpoints after symbols have been re-loaded. */ | |
7519 | void | |
fba45db2 | 7520 | breakpoint_re_set (void) |
c906108c SS |
7521 | { |
7522 | struct breakpoint *b, *temp; | |
7523 | enum language save_language; | |
7524 | int save_input_radix; | |
c5aa993b | 7525 | |
c906108c SS |
7526 | save_language = current_language->la_language; |
7527 | save_input_radix = input_radix; | |
7528 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b | 7529 | { |
53a5351d | 7530 | /* Format possible error msg */ |
fe3f5fa8 | 7531 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
7532 | b->number); |
7533 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 7534 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 7535 | do_cleanups (cleanups); |
c5aa993b | 7536 | } |
c906108c SS |
7537 | set_language (save_language); |
7538 | input_radix = save_input_radix; | |
1900040c MS |
7539 | |
7540 | create_overlay_event_breakpoint ("_ovly_debug_event"); | |
c906108c SS |
7541 | } |
7542 | \f | |
c906108c SS |
7543 | /* Reset the thread number of this breakpoint: |
7544 | ||
7545 | - If the breakpoint is for all threads, leave it as-is. | |
39f77062 | 7546 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 7547 | void |
fba45db2 | 7548 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
7549 | { |
7550 | if (b->thread != -1) | |
7551 | { | |
39f77062 KB |
7552 | if (in_thread_list (inferior_ptid)) |
7553 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c SS |
7554 | } |
7555 | } | |
7556 | ||
03ac34d5 MS |
7557 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
7558 | If from_tty is nonzero, it prints a message to that effect, | |
7559 | which ends with a period (no newline). */ | |
7560 | ||
c906108c | 7561 | void |
fba45db2 | 7562 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 7563 | { |
52f0bd74 | 7564 | struct breakpoint *b; |
c906108c SS |
7565 | |
7566 | if (count < 0) | |
7567 | count = 0; | |
7568 | ||
7569 | ALL_BREAKPOINTS (b) | |
7570 | if (b->number == bptnum) | |
c5aa993b JM |
7571 | { |
7572 | b->ignore_count = count; | |
221ea385 KS |
7573 | if (from_tty) |
7574 | { | |
7575 | if (count == 0) | |
a3f17187 | 7576 | printf_filtered (_("Will stop next time breakpoint %d is reached."), |
221ea385 KS |
7577 | bptnum); |
7578 | else if (count == 1) | |
a3f17187 | 7579 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
7580 | bptnum); |
7581 | else | |
a3f17187 | 7582 | printf_filtered (_("Will ignore next %d crossings of breakpoint %d."), |
221ea385 KS |
7583 | count, bptnum); |
7584 | } | |
c5aa993b | 7585 | breakpoints_changed (); |
383f836e | 7586 | observer_notify_breakpoint_modified (b->number); |
c5aa993b JM |
7587 | return; |
7588 | } | |
c906108c | 7589 | |
8a3fe4f8 | 7590 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
7591 | } |
7592 | ||
b2175913 MS |
7593 | void |
7594 | make_breakpoint_silent (struct breakpoint *b) | |
7595 | { | |
7596 | /* Silence the breakpoint. */ | |
7597 | b->silent = 1; | |
7598 | } | |
7599 | ||
c906108c SS |
7600 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
7601 | ||
7602 | static void | |
fba45db2 | 7603 | ignore_command (char *args, int from_tty) |
c906108c SS |
7604 | { |
7605 | char *p = args; | |
52f0bd74 | 7606 | int num; |
c906108c SS |
7607 | |
7608 | if (p == 0) | |
e2e0b3e5 | 7609 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 7610 | |
c906108c | 7611 | num = get_number (&p); |
5c44784c | 7612 | if (num == 0) |
8a3fe4f8 | 7613 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 7614 | if (*p == 0) |
8a3fe4f8 | 7615 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
7616 | |
7617 | set_ignore_count (num, | |
7618 | longest_to_int (value_as_long (parse_and_eval (p))), | |
7619 | from_tty); | |
221ea385 KS |
7620 | if (from_tty) |
7621 | printf_filtered ("\n"); | |
c906108c SS |
7622 | } |
7623 | \f | |
7624 | /* Call FUNCTION on each of the breakpoints | |
7625 | whose numbers are given in ARGS. */ | |
7626 | ||
7627 | static void | |
831662b3 | 7628 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *)) |
c906108c | 7629 | { |
52f0bd74 | 7630 | char *p = args; |
c906108c | 7631 | char *p1; |
52f0bd74 AC |
7632 | int num; |
7633 | struct breakpoint *b, *tmp; | |
11cf8741 | 7634 | int match; |
c906108c SS |
7635 | |
7636 | if (p == 0) | |
e2e0b3e5 | 7637 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c SS |
7638 | |
7639 | while (*p) | |
7640 | { | |
11cf8741 | 7641 | match = 0; |
c906108c | 7642 | p1 = p; |
c5aa993b | 7643 | |
5c44784c JM |
7644 | num = get_number_or_range (&p1); |
7645 | if (num == 0) | |
c5aa993b | 7646 | { |
8a3fe4f8 | 7647 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
7648 | } |
7649 | else | |
7650 | { | |
7651 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
7652 | if (b->number == num) | |
7653 | { | |
7654 | struct breakpoint *related_breakpoint = b->related_breakpoint; | |
11cf8741 | 7655 | match = 1; |
5c44784c JM |
7656 | function (b); |
7657 | if (related_breakpoint) | |
7658 | function (related_breakpoint); | |
11cf8741 | 7659 | break; |
5c44784c | 7660 | } |
11cf8741 | 7661 | if (match == 0) |
a3f17187 | 7662 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 7663 | } |
c906108c SS |
7664 | p = p1; |
7665 | } | |
7666 | } | |
7667 | ||
0d381245 VP |
7668 | static struct bp_location * |
7669 | find_location_by_number (char *number) | |
7670 | { | |
7671 | char *dot = strchr (number, '.'); | |
7672 | char *p1; | |
7673 | int bp_num; | |
7674 | int loc_num; | |
7675 | struct breakpoint *b; | |
7676 | struct bp_location *loc; | |
7677 | ||
7678 | *dot = '\0'; | |
7679 | ||
7680 | p1 = number; | |
7681 | bp_num = get_number_or_range (&p1); | |
7682 | if (bp_num == 0) | |
7683 | error (_("Bad breakpoint number '%s'"), number); | |
7684 | ||
7685 | ALL_BREAKPOINTS (b) | |
7686 | if (b->number == bp_num) | |
7687 | { | |
7688 | break; | |
7689 | } | |
7690 | ||
7691 | if (!b || b->number != bp_num) | |
7692 | error (_("Bad breakpoint number '%s'"), number); | |
7693 | ||
7694 | p1 = dot+1; | |
7695 | loc_num = get_number_or_range (&p1); | |
7696 | if (loc_num == 0) | |
7697 | error (_("Bad breakpoint location number '%s'"), number); | |
7698 | ||
7699 | --loc_num; | |
7700 | loc = b->loc; | |
7701 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
7702 | ; | |
7703 | if (!loc) | |
7704 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
7705 | ||
7706 | return loc; | |
7707 | } | |
7708 | ||
7709 | ||
1900040c MS |
7710 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
7711 | If from_tty is nonzero, it prints a message to that effect, | |
7712 | which ends with a period (no newline). */ | |
7713 | ||
c906108c | 7714 | void |
fba45db2 | 7715 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
7716 | { |
7717 | /* Never disable a watchpoint scope breakpoint; we want to | |
7718 | hit them when we leave scope so we can delete both the | |
7719 | watchpoint and its scope breakpoint at that time. */ | |
7720 | if (bpt->type == bp_watchpoint_scope) | |
7721 | return; | |
7722 | ||
c2c6d25f | 7723 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 7724 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
7725 | return; |
7726 | ||
b5de0fa7 | 7727 | bpt->enable_state = bp_disabled; |
c906108c | 7728 | |
b60e7edf | 7729 | update_global_location_list (0); |
c906108c | 7730 | |
383f836e | 7731 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
7732 | } |
7733 | ||
c906108c | 7734 | static void |
fba45db2 | 7735 | disable_command (char *args, int from_tty) |
c906108c | 7736 | { |
52f0bd74 | 7737 | struct breakpoint *bpt; |
c906108c SS |
7738 | if (args == 0) |
7739 | ALL_BREAKPOINTS (bpt) | |
7740 | switch (bpt->type) | |
c5aa993b JM |
7741 | { |
7742 | case bp_none: | |
8a3fe4f8 | 7743 | warning (_("attempted to disable apparently deleted breakpoint #%d?"), |
53a5351d | 7744 | bpt->number); |
c5aa993b JM |
7745 | continue; |
7746 | case bp_breakpoint: | |
ce78b96d | 7747 | case bp_catchpoint: |
c5aa993b JM |
7748 | case bp_hardware_breakpoint: |
7749 | case bp_watchpoint: | |
7750 | case bp_hardware_watchpoint: | |
7751 | case bp_read_watchpoint: | |
7752 | case bp_access_watchpoint: | |
7753 | disable_breakpoint (bpt); | |
7754 | default: | |
7755 | continue; | |
7756 | } | |
0d381245 VP |
7757 | else if (strchr (args, '.')) |
7758 | { | |
7759 | struct bp_location *loc = find_location_by_number (args); | |
7760 | if (loc) | |
7761 | loc->enabled = 0; | |
b60e7edf | 7762 | update_global_location_list (0); |
0d381245 | 7763 | } |
c906108c SS |
7764 | else |
7765 | map_breakpoint_numbers (args, disable_breakpoint); | |
7766 | } | |
7767 | ||
7768 | static void | |
fba45db2 | 7769 | do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition) |
c906108c | 7770 | { |
c906108c SS |
7771 | int target_resources_ok, other_type_used; |
7772 | struct value *mark; | |
7773 | ||
7774 | if (bpt->type == bp_hardware_breakpoint) | |
7775 | { | |
7776 | int i; | |
c5aa993b | 7777 | i = hw_breakpoint_used_count (); |
53a5351d JM |
7778 | target_resources_ok = |
7779 | TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint, | |
7780 | i + 1, 0); | |
c906108c | 7781 | if (target_resources_ok == 0) |
8a3fe4f8 | 7782 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 7783 | else if (target_resources_ok < 0) |
8a3fe4f8 | 7784 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
7785 | } |
7786 | ||
fe3f5fa8 VP |
7787 | if (bpt->type == bp_watchpoint || |
7788 | bpt->type == bp_hardware_watchpoint || | |
7789 | bpt->type == bp_read_watchpoint || | |
7790 | bpt->type == bp_access_watchpoint) | |
c906108c | 7791 | { |
fe3f5fa8 VP |
7792 | struct frame_id saved_frame_id; |
7793 | ||
7794 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
7795 | if (bpt->exp_valid_block != NULL) | |
c906108c | 7796 | { |
fe3f5fa8 VP |
7797 | struct frame_info *fr = |
7798 | fr = frame_find_by_id (bpt->watchpoint_frame); | |
7799 | if (fr == NULL) | |
c906108c | 7800 | { |
fe3f5fa8 VP |
7801 | printf_filtered (_("\ |
7802 | Cannot enable watchpoint %d because the block in which its expression\n\ | |
7803 | is valid is not currently in scope.\n"), bpt->number); | |
c906108c SS |
7804 | return; |
7805 | } | |
fe3f5fa8 | 7806 | select_frame (fr); |
c906108c | 7807 | } |
0101ce28 | 7808 | |
b4c291bb KH |
7809 | if (bpt->val) |
7810 | value_free (bpt->val); | |
fe3f5fa8 | 7811 | mark = value_mark (); |
fa4727a6 DJ |
7812 | fetch_watchpoint_value (bpt->exp, &bpt->val, NULL, NULL); |
7813 | if (bpt->val) | |
7814 | release_value (bpt->val); | |
7815 | bpt->val_valid = 1; | |
7816 | ||
fe3f5fa8 VP |
7817 | if (bpt->type == bp_hardware_watchpoint || |
7818 | bpt->type == bp_read_watchpoint || | |
c5aa993b JM |
7819 | bpt->type == bp_access_watchpoint) |
7820 | { | |
fe3f5fa8 VP |
7821 | int i = hw_watchpoint_used_count (bpt->type, &other_type_used); |
7822 | int mem_cnt = can_use_hardware_watchpoint (bpt->val); | |
0101ce28 | 7823 | |
fe3f5fa8 VP |
7824 | /* Hack around 'unused var' error for some targets here */ |
7825 | (void) mem_cnt, (void) i; | |
7826 | target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT ( | |
7827 | bpt->type, i + mem_cnt, other_type_used); | |
7828 | /* we can consider of type is bp_hardware_watchpoint, convert to | |
7829 | bp_watchpoint in the following condition */ | |
7830 | if (target_resources_ok < 0) | |
c5aa993b | 7831 | { |
fe3f5fa8 | 7832 | printf_filtered (_("\ |
c906108c | 7833 | Cannot enable watchpoint %d because target watch resources\n\ |
a3f17187 | 7834 | have been allocated for other watchpoints.\n"), bpt->number); |
fe3f5fa8 VP |
7835 | value_free_to_mark (mark); |
7836 | return; | |
c5aa993b JM |
7837 | } |
7838 | } | |
fe3f5fa8 VP |
7839 | |
7840 | select_frame (frame_find_by_id (saved_frame_id)); | |
7841 | value_free_to_mark (mark); | |
c906108c | 7842 | } |
0101ce28 | 7843 | |
b4c291bb KH |
7844 | if (bpt->enable_state != bp_permanent) |
7845 | bpt->enable_state = bp_enabled; | |
7846 | bpt->disposition = disposition; | |
b60e7edf | 7847 | update_global_location_list (1); |
b4c291bb KH |
7848 | breakpoints_changed (); |
7849 | ||
383f836e | 7850 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
7851 | } |
7852 | ||
fe3f5fa8 | 7853 | |
c906108c | 7854 | void |
fba45db2 | 7855 | enable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
7856 | { |
7857 | do_enable_breakpoint (bpt, bpt->disposition); | |
7858 | } | |
7859 | ||
7860 | /* The enable command enables the specified breakpoints (or all defined | |
7861 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 7862 | in stopping the inferior. */ |
c906108c | 7863 | |
c906108c | 7864 | static void |
fba45db2 | 7865 | enable_command (char *args, int from_tty) |
c906108c | 7866 | { |
52f0bd74 | 7867 | struct breakpoint *bpt; |
c906108c SS |
7868 | if (args == 0) |
7869 | ALL_BREAKPOINTS (bpt) | |
7870 | switch (bpt->type) | |
c5aa993b JM |
7871 | { |
7872 | case bp_none: | |
8a3fe4f8 | 7873 | warning (_("attempted to enable apparently deleted breakpoint #%d?"), |
53a5351d | 7874 | bpt->number); |
c5aa993b JM |
7875 | continue; |
7876 | case bp_breakpoint: | |
ce78b96d | 7877 | case bp_catchpoint: |
c5aa993b JM |
7878 | case bp_hardware_breakpoint: |
7879 | case bp_watchpoint: | |
7880 | case bp_hardware_watchpoint: | |
7881 | case bp_read_watchpoint: | |
7882 | case bp_access_watchpoint: | |
7883 | enable_breakpoint (bpt); | |
7884 | default: | |
7885 | continue; | |
7886 | } | |
0d381245 VP |
7887 | else if (strchr (args, '.')) |
7888 | { | |
7889 | struct bp_location *loc = find_location_by_number (args); | |
7890 | if (loc) | |
7891 | loc->enabled = 1; | |
b60e7edf | 7892 | update_global_location_list (1); |
0d381245 | 7893 | } |
c906108c SS |
7894 | else |
7895 | map_breakpoint_numbers (args, enable_breakpoint); | |
7896 | } | |
7897 | ||
7898 | static void | |
fba45db2 | 7899 | enable_once_breakpoint (struct breakpoint *bpt) |
c906108c | 7900 | { |
b5de0fa7 | 7901 | do_enable_breakpoint (bpt, disp_disable); |
c906108c SS |
7902 | } |
7903 | ||
c906108c | 7904 | static void |
fba45db2 | 7905 | enable_once_command (char *args, int from_tty) |
c906108c SS |
7906 | { |
7907 | map_breakpoint_numbers (args, enable_once_breakpoint); | |
7908 | } | |
7909 | ||
7910 | static void | |
fba45db2 | 7911 | enable_delete_breakpoint (struct breakpoint *bpt) |
c906108c | 7912 | { |
b5de0fa7 | 7913 | do_enable_breakpoint (bpt, disp_del); |
c906108c SS |
7914 | } |
7915 | ||
c906108c | 7916 | static void |
fba45db2 | 7917 | enable_delete_command (char *args, int from_tty) |
c906108c SS |
7918 | { |
7919 | map_breakpoint_numbers (args, enable_delete_breakpoint); | |
7920 | } | |
7921 | \f | |
fa8d40ab JJ |
7922 | static void |
7923 | set_breakpoint_cmd (char *args, int from_tty) | |
7924 | { | |
7925 | } | |
7926 | ||
7927 | static void | |
7928 | show_breakpoint_cmd (char *args, int from_tty) | |
7929 | { | |
7930 | } | |
7931 | ||
c906108c SS |
7932 | /* Use default_breakpoint_'s, or nothing if they aren't valid. */ |
7933 | ||
7934 | struct symtabs_and_lines | |
fba45db2 | 7935 | decode_line_spec_1 (char *string, int funfirstline) |
c906108c SS |
7936 | { |
7937 | struct symtabs_and_lines sals; | |
7938 | if (string == 0) | |
8a3fe4f8 | 7939 | error (_("Empty line specification.")); |
c906108c SS |
7940 | if (default_breakpoint_valid) |
7941 | sals = decode_line_1 (&string, funfirstline, | |
53a5351d JM |
7942 | default_breakpoint_symtab, |
7943 | default_breakpoint_line, | |
68219205 | 7944 | (char ***) NULL, NULL); |
c906108c SS |
7945 | else |
7946 | sals = decode_line_1 (&string, funfirstline, | |
68219205 | 7947 | (struct symtab *) NULL, 0, (char ***) NULL, NULL); |
c906108c | 7948 | if (*string) |
8a3fe4f8 | 7949 | error (_("Junk at end of line specification: %s"), string); |
c906108c SS |
7950 | return sals; |
7951 | } | |
8181d85f DJ |
7952 | |
7953 | /* Create and insert a raw software breakpoint at PC. Return an | |
7954 | identifier, which should be used to remove the breakpoint later. | |
7955 | In general, places which call this should be using something on the | |
7956 | breakpoint chain instead; this function should be eliminated | |
7957 | someday. */ | |
7958 | ||
7959 | void * | |
7960 | deprecated_insert_raw_breakpoint (CORE_ADDR pc) | |
7961 | { | |
7962 | struct bp_target_info *bp_tgt; | |
7963 | ||
7964 | bp_tgt = xmalloc (sizeof (struct bp_target_info)); | |
7965 | memset (bp_tgt, 0, sizeof (struct bp_target_info)); | |
7966 | ||
7967 | bp_tgt->placed_address = pc; | |
7968 | if (target_insert_breakpoint (bp_tgt) != 0) | |
7969 | { | |
7970 | /* Could not insert the breakpoint. */ | |
7971 | xfree (bp_tgt); | |
7972 | return NULL; | |
7973 | } | |
7974 | ||
7975 | return bp_tgt; | |
7976 | } | |
7977 | ||
7978 | /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */ | |
7979 | ||
7980 | int | |
7981 | deprecated_remove_raw_breakpoint (void *bp) | |
7982 | { | |
7983 | struct bp_target_info *bp_tgt = bp; | |
7984 | int ret; | |
7985 | ||
7986 | ret = target_remove_breakpoint (bp_tgt); | |
7987 | xfree (bp_tgt); | |
7988 | ||
7989 | return ret; | |
7990 | } | |
7991 | ||
7992 | /* One (or perhaps two) breakpoints used for software single stepping. */ | |
7993 | ||
7994 | static void *single_step_breakpoints[2]; | |
7995 | ||
7996 | /* Create and insert a breakpoint for software single step. */ | |
7997 | ||
7998 | void | |
7999 | insert_single_step_breakpoint (CORE_ADDR next_pc) | |
8000 | { | |
8001 | void **bpt_p; | |
8002 | ||
8003 | if (single_step_breakpoints[0] == NULL) | |
8004 | bpt_p = &single_step_breakpoints[0]; | |
8005 | else | |
8006 | { | |
8007 | gdb_assert (single_step_breakpoints[1] == NULL); | |
8008 | bpt_p = &single_step_breakpoints[1]; | |
8009 | } | |
8010 | ||
8011 | /* NOTE drow/2006-04-11: A future improvement to this function would be | |
8012 | to only create the breakpoints once, and actually put them on the | |
8013 | breakpoint chain. That would let us use set_raw_breakpoint. We could | |
8014 | adjust the addresses each time they were needed. Doing this requires | |
8015 | corresponding changes elsewhere where single step breakpoints are | |
8016 | handled, however. So, for now, we use this. */ | |
8017 | ||
8018 | *bpt_p = deprecated_insert_raw_breakpoint (next_pc); | |
8019 | if (*bpt_p == NULL) | |
1893a4c0 | 8020 | error (_("Could not insert single-step breakpoint at 0x%s"), |
8181d85f DJ |
8021 | paddr_nz (next_pc)); |
8022 | } | |
8023 | ||
8024 | /* Remove and delete any breakpoints used for software single step. */ | |
8025 | ||
8026 | void | |
8027 | remove_single_step_breakpoints (void) | |
8028 | { | |
8029 | gdb_assert (single_step_breakpoints[0] != NULL); | |
8030 | ||
8031 | /* See insert_single_step_breakpoint for more about this deprecated | |
8032 | call. */ | |
8033 | deprecated_remove_raw_breakpoint (single_step_breakpoints[0]); | |
8034 | single_step_breakpoints[0] = NULL; | |
8035 | ||
8036 | if (single_step_breakpoints[1] != NULL) | |
8037 | { | |
8038 | deprecated_remove_raw_breakpoint (single_step_breakpoints[1]); | |
8039 | single_step_breakpoints[1] = NULL; | |
8040 | } | |
8041 | } | |
8042 | ||
1aafd4da UW |
8043 | /* Check whether a software single-step breakpoint is inserted at PC. */ |
8044 | ||
8045 | static int | |
8046 | single_step_breakpoint_inserted_here_p (CORE_ADDR pc) | |
8047 | { | |
8048 | int i; | |
8049 | ||
8050 | for (i = 0; i < 2; i++) | |
8051 | { | |
8052 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
8053 | if (bp_tgt && bp_tgt->placed_address == pc) | |
8054 | return 1; | |
8055 | } | |
8056 | ||
8057 | return 0; | |
8058 | } | |
8059 | ||
c906108c | 8060 | \f |
31e2b00f AS |
8061 | /* This help string is used for the break, hbreak, tbreak and thbreak commands. |
8062 | It is defined as a macro to prevent duplication. | |
8063 | COMMAND should be a string constant containing the name of the command. */ | |
8064 | #define BREAK_ARGS_HELP(command) \ | |
8065 | command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\ | |
8066 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ | |
8067 | If a line number is specified, break at start of code for that line.\n\ | |
8068 | If a function is specified, break at start of code for that function.\n\ | |
8069 | If an address is specified, break at that exact address.\n\ | |
8070 | With no LOCATION, uses current execution address of selected stack frame.\n\ | |
8071 | This is useful for breaking on return to a stack frame.\n\ | |
8072 | \n\ | |
8073 | THREADNUM is the number from \"info threads\".\n\ | |
8074 | CONDITION is a boolean expression.\n\ | |
8075 | \n\ | |
8076 | Multiple breakpoints at one place are permitted, and useful if conditional.\n\ | |
8077 | \n\ | |
8078 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
8079 | ||
44feb3ce TT |
8080 | /* List of subcommands for "catch". */ |
8081 | static struct cmd_list_element *catch_cmdlist; | |
8082 | ||
8083 | /* List of subcommands for "tcatch". */ | |
8084 | static struct cmd_list_element *tcatch_cmdlist; | |
8085 | ||
8086 | /* Like add_cmd, but add the command to both the "catch" and "tcatch" | |
8087 | lists, and pass some additional user data to the command function. */ | |
8088 | static void | |
8089 | add_catch_command (char *name, char *docstring, | |
8090 | void (*sfunc) (char *args, int from_tty, | |
8091 | struct cmd_list_element *command), | |
8092 | void *user_data_catch, | |
8093 | void *user_data_tcatch) | |
8094 | { | |
8095 | struct cmd_list_element *command; | |
8096 | ||
8097 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
8098 | &catch_cmdlist); | |
8099 | set_cmd_sfunc (command, sfunc); | |
8100 | set_cmd_context (command, user_data_catch); | |
8101 | ||
8102 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
8103 | &tcatch_cmdlist); | |
8104 | set_cmd_sfunc (command, sfunc); | |
8105 | set_cmd_context (command, user_data_tcatch); | |
8106 | } | |
8107 | ||
c906108c | 8108 | void |
fba45db2 | 8109 | _initialize_breakpoint (void) |
c906108c | 8110 | { |
fa8d40ab JJ |
8111 | static struct cmd_list_element *breakpoint_set_cmdlist; |
8112 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
c906108c SS |
8113 | struct cmd_list_element *c; |
8114 | ||
84acb35a | 8115 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
84acb35a | 8116 | |
c906108c SS |
8117 | breakpoint_chain = 0; |
8118 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
8119 | before a breakpoint is set. */ | |
8120 | breakpoint_count = 0; | |
8121 | ||
1bedd215 AC |
8122 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
8123 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
8124 | Usage is `ignore N COUNT'.")); | |
c906108c | 8125 | if (xdb_commands) |
c5aa993b | 8126 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 8127 | |
1bedd215 AC |
8128 | add_com ("commands", class_breakpoint, commands_command, _("\ |
8129 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
8130 | Give breakpoint number as argument after \"commands\".\n\ |
8131 | With no argument, the targeted breakpoint is the last one set.\n\ | |
8132 | The commands themselves follow starting on the next line.\n\ | |
8133 | Type a line containing \"end\" to indicate the end of them.\n\ | |
8134 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 8135 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 8136 | |
1bedd215 AC |
8137 | add_com ("condition", class_breakpoint, condition_command, _("\ |
8138 | Specify breakpoint number N to break only if COND is true.\n\ | |
c906108c | 8139 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 8140 | expression to be evaluated whenever breakpoint N is reached.")); |
c906108c | 8141 | |
1bedd215 | 8142 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 8143 | Set a temporary breakpoint.\n\ |
c906108c SS |
8144 | Like \"break\" except the breakpoint is only temporary,\n\ |
8145 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
8146 | by using \"enable delete\" on the breakpoint number.\n\ |
8147 | \n" | |
8148 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 8149 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 8150 | |
1bedd215 | 8151 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
31e2b00f | 8152 | Set a hardware assisted breakpoint.\n\ |
c906108c | 8153 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
8154 | some target hardware may not have this support.\n\ |
8155 | \n" | |
8156 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 8157 | set_cmd_completer (c, location_completer); |
c906108c | 8158 | |
1bedd215 | 8159 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 8160 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 8161 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
8162 | so it will be deleted when hit.\n\ |
8163 | \n" | |
8164 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 8165 | set_cmd_completer (c, location_completer); |
c906108c | 8166 | |
1bedd215 AC |
8167 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
8168 | Enable some breakpoints.\n\ | |
c906108c SS |
8169 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
8170 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
8171 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 8172 | With a subcommand you can enable temporarily."), |
c906108c SS |
8173 | &enablelist, "enable ", 1, &cmdlist); |
8174 | if (xdb_commands) | |
1bedd215 AC |
8175 | add_com ("ab", class_breakpoint, enable_command, _("\ |
8176 | Enable some breakpoints.\n\ | |
c906108c SS |
8177 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
8178 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
8179 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 8180 | With a subcommand you can enable temporarily.")); |
c906108c SS |
8181 | |
8182 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
8183 | ||
1bedd215 AC |
8184 | add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
8185 | Enable some breakpoints.\n\ | |
c906108c SS |
8186 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
8187 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 8188 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 8189 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 8190 | |
1a966eab AC |
8191 | add_cmd ("once", no_class, enable_once_command, _("\ |
8192 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
8193 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
8194 | &enablebreaklist); |
8195 | ||
1a966eab AC |
8196 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
8197 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
8198 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
8199 | &enablebreaklist); |
8200 | ||
1a966eab AC |
8201 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
8202 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
8203 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
8204 | &enablelist); |
8205 | ||
1a966eab AC |
8206 | add_cmd ("once", no_class, enable_once_command, _("\ |
8207 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
8208 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
8209 | &enablelist); |
8210 | ||
1bedd215 AC |
8211 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
8212 | Disable some breakpoints.\n\ | |
c906108c SS |
8213 | Arguments are breakpoint numbers with spaces in between.\n\ |
8214 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 8215 | A disabled breakpoint is not forgotten, but has no effect until reenabled."), |
c906108c SS |
8216 | &disablelist, "disable ", 1, &cmdlist); |
8217 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
8218 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
8219 | if (xdb_commands) | |
1bedd215 AC |
8220 | add_com ("sb", class_breakpoint, disable_command, _("\ |
8221 | Disable some breakpoints.\n\ | |
c906108c SS |
8222 | Arguments are breakpoint numbers with spaces in between.\n\ |
8223 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 8224 | A disabled breakpoint is not forgotten, but has no effect until reenabled.")); |
c906108c | 8225 | |
1a966eab AC |
8226 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
8227 | Disable some breakpoints.\n\ | |
c906108c SS |
8228 | Arguments are breakpoint numbers with spaces in between.\n\ |
8229 | To disable all breakpoints, give no argument.\n\ | |
8230 | A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\ | |
1a966eab | 8231 | This command may be abbreviated \"disable\"."), |
c906108c SS |
8232 | &disablelist); |
8233 | ||
1bedd215 AC |
8234 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
8235 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
8236 | Arguments are breakpoint numbers with spaces in between.\n\ |
8237 | To delete all breakpoints, give no argument.\n\ | |
8238 | \n\ | |
8239 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 8240 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
8241 | &deletelist, "delete ", 1, &cmdlist); |
8242 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 8243 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 8244 | if (xdb_commands) |
1bedd215 AC |
8245 | add_com ("db", class_breakpoint, delete_command, _("\ |
8246 | Delete some breakpoints.\n\ | |
c906108c | 8247 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 8248 | To delete all breakpoints, give no argument.\n")); |
c906108c | 8249 | |
1a966eab AC |
8250 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
8251 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
8252 | Arguments are breakpoint numbers with spaces in between.\n\ |
8253 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 8254 | This command may be abbreviated \"delete\"."), |
c906108c SS |
8255 | &deletelist); |
8256 | ||
1bedd215 AC |
8257 | add_com ("clear", class_breakpoint, clear_command, _("\ |
8258 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
8259 | Argument may be line number, function name, or \"*\" and an address.\n\ |
8260 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
8261 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
8262 | If an address is specified, breakpoints at that address are cleared.\n\ |
8263 | \n\ | |
8264 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
8265 | is executing in.\n\ |
8266 | \n\ | |
1bedd215 | 8267 | See also the \"delete\" command which clears breakpoints by number.")); |
c906108c | 8268 | |
1bedd215 | 8269 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
8270 | Set breakpoint at specified line or function.\n" |
8271 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 8272 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 8273 | |
c906108c SS |
8274 | add_com_alias ("b", "break", class_run, 1); |
8275 | add_com_alias ("br", "break", class_run, 1); | |
8276 | add_com_alias ("bre", "break", class_run, 1); | |
8277 | add_com_alias ("brea", "break", class_run, 1); | |
8278 | ||
502fd408 | 8279 | if (xdb_commands) |
c906108c SS |
8280 | { |
8281 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
8282 | add_com_alias ("bu", "ubreak", class_breakpoint, 1); | |
c906108c SS |
8283 | } |
8284 | ||
8285 | if (dbx_commands) | |
8286 | { | |
1bedd215 AC |
8287 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
8288 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
8289 | &stoplist, "stop ", 1, &cmdlist); |
8290 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 8291 | _("Break in function or address."), &stoplist); |
c5aa993b | 8292 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 8293 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
8294 | add_com ("status", class_info, breakpoints_info, _("\ |
8295 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
8296 | The \"Type\" column indicates one of:\n\ |
8297 | \tbreakpoint - normal breakpoint\n\ | |
8298 | \twatchpoint - watchpoint\n\ | |
8299 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
8300 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
8301 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
8302 | address and file/line number respectively.\n\ |
8303 | \n\ | |
8304 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
8305 | are set to the address of the last breakpoint listed unless the command\n\ |
8306 | is prefixed with \"server \".\n\n\ | |
c906108c | 8307 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 8308 | breakpoint set.")); |
c906108c SS |
8309 | } |
8310 | ||
1bedd215 AC |
8311 | add_info ("breakpoints", breakpoints_info, _("\ |
8312 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
8313 | The \"Type\" column indicates one of:\n\ |
8314 | \tbreakpoint - normal breakpoint\n\ | |
8315 | \twatchpoint - watchpoint\n\ | |
8316 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
8317 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
8318 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
8319 | address and file/line number respectively.\n\ |
8320 | \n\ | |
8321 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
8322 | are set to the address of the last breakpoint listed unless the command\n\ |
8323 | is prefixed with \"server \".\n\n\ | |
c906108c | 8324 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 8325 | breakpoint set.")); |
c906108c SS |
8326 | |
8327 | if (xdb_commands) | |
1bedd215 AC |
8328 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
8329 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
8330 | The \"Type\" column indicates one of:\n\ |
8331 | \tbreakpoint - normal breakpoint\n\ | |
8332 | \twatchpoint - watchpoint\n\ | |
8333 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
8334 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
8335 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
8336 | address and file/line number respectively.\n\ |
8337 | \n\ | |
8338 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
8339 | are set to the address of the last breakpoint listed unless the command\n\ |
8340 | is prefixed with \"server \".\n\n\ | |
c906108c | 8341 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 8342 | breakpoint set.")); |
c906108c | 8343 | |
1a966eab AC |
8344 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
8345 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
8346 | The \"Type\" column indicates one of:\n\ |
8347 | \tbreakpoint - normal breakpoint\n\ | |
8348 | \twatchpoint - watchpoint\n\ | |
8349 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
8350 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
8351 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
8352 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
8353 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
8354 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
8355 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
8356 | address and file/line number respectively.\n\ |
8357 | \n\ | |
8358 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
8359 | are set to the address of the last breakpoint listed unless the command\n\ |
8360 | is prefixed with \"server \".\n\n\ | |
c906108c | 8361 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 8362 | breakpoint set."), |
c906108c SS |
8363 | &maintenanceinfolist); |
8364 | ||
44feb3ce TT |
8365 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
8366 | Set catchpoints to catch events."), | |
8367 | &catch_cmdlist, "catch ", | |
8368 | 0/*allow-unknown*/, &cmdlist); | |
8369 | ||
8370 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
8371 | Set temporary catchpoints to catch events."), | |
8372 | &tcatch_cmdlist, "tcatch ", | |
8373 | 0/*allow-unknown*/, &cmdlist); | |
8374 | ||
8375 | /* Add catch and tcatch sub-commands. */ | |
8376 | add_catch_command ("catch", _("\ | |
8377 | Catch an exception, when caught.\n\ | |
8378 | With an argument, catch only exceptions with the given name."), | |
8379 | catch_catch_command, | |
8380 | CATCH_PERMANENT, | |
8381 | CATCH_TEMPORARY); | |
8382 | add_catch_command ("throw", _("\ | |
8383 | Catch an exception, when thrown.\n\ | |
8384 | With an argument, catch only exceptions with the given name."), | |
8385 | catch_throw_command, | |
8386 | CATCH_PERMANENT, | |
8387 | CATCH_TEMPORARY); | |
8388 | add_catch_command ("fork", _("Catch calls to fork."), | |
8389 | catch_fork_command_1, | |
8390 | (void *) (uintptr_t) catch_fork_permanent, | |
8391 | (void *) (uintptr_t) catch_fork_temporary); | |
8392 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
8393 | catch_fork_command_1, | |
8394 | (void *) (uintptr_t) catch_vfork_permanent, | |
8395 | (void *) (uintptr_t) catch_vfork_temporary); | |
8396 | add_catch_command ("exec", _("Catch calls to exec."), | |
8397 | catch_exec_command_1, | |
8398 | CATCH_PERMANENT, | |
8399 | CATCH_TEMPORARY); | |
44feb3ce TT |
8400 | add_catch_command ("exception", _("\ |
8401 | Catch Ada exceptions, when raised.\n\ | |
8402 | With an argument, catch only exceptions with the given name."), | |
8403 | catch_ada_exception_command, | |
8404 | CATCH_PERMANENT, | |
8405 | CATCH_TEMPORARY); | |
8406 | add_catch_command ("assert", _("\ | |
8407 | Catch failed Ada assertions, when raised.\n\ | |
8408 | With an argument, catch only exceptions with the given name."), | |
8409 | catch_assert_command, | |
8410 | CATCH_PERMANENT, | |
8411 | CATCH_TEMPORARY); | |
c5aa993b | 8412 | |
1bedd215 AC |
8413 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
8414 | Set a watchpoint for an expression.\n\ | |
c906108c | 8415 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 8416 | an expression changes.")); |
65d12d83 | 8417 | set_cmd_completer (c, expression_completer); |
c906108c | 8418 | |
1bedd215 AC |
8419 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
8420 | Set a read watchpoint for an expression.\n\ | |
c906108c | 8421 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 8422 | an expression is read.")); |
65d12d83 | 8423 | set_cmd_completer (c, expression_completer); |
c906108c | 8424 | |
1bedd215 AC |
8425 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
8426 | Set a watchpoint for an expression.\n\ | |
c906108c | 8427 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 8428 | an expression is either read or written.")); |
65d12d83 | 8429 | set_cmd_completer (c, expression_completer); |
c906108c SS |
8430 | |
8431 | add_info ("watchpoints", breakpoints_info, | |
1bedd215 | 8432 | _("Synonym for ``info breakpoints''.")); |
c906108c SS |
8433 | |
8434 | ||
920d2a44 AC |
8435 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
8436 | respond to changes - contrary to the description. */ | |
85c07804 AC |
8437 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
8438 | &can_use_hw_watchpoints, _("\ | |
8439 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
8440 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
8441 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
8442 | such is available. (However, any hardware watchpoints that were\n\ | |
8443 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
8444 | hardware.)"), |
8445 | NULL, | |
920d2a44 | 8446 | show_can_use_hw_watchpoints, |
85c07804 | 8447 | &setlist, &showlist); |
c906108c SS |
8448 | |
8449 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 8450 | |
1bedd215 | 8451 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
8452 | Breakpoint specific settings\n\ |
8453 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 8454 | pending breakpoint behavior"), |
fa8d40ab JJ |
8455 | &breakpoint_set_cmdlist, "set breakpoint ", |
8456 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 8457 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
8458 | Breakpoint specific settings\n\ |
8459 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 8460 | pending breakpoint behavior"), |
fa8d40ab JJ |
8461 | &breakpoint_show_cmdlist, "show breakpoint ", |
8462 | 0/*allow-unknown*/, &showlist); | |
8463 | ||
7915a72c AC |
8464 | add_setshow_auto_boolean_cmd ("pending", no_class, |
8465 | &pending_break_support, _("\ | |
8466 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
8467 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
8468 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
8469 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
8470 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 8471 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 8472 | NULL, |
920d2a44 | 8473 | show_pending_break_support, |
6e1d7d6c AC |
8474 | &breakpoint_set_cmdlist, |
8475 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
8476 | |
8477 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
8478 | |
8479 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
8480 | &automatic_hardware_breakpoints, _("\ | |
8481 | Set automatic usage of hardware breakpoints."), _("\ | |
8482 | Show automatic usage of hardware breakpoints."), _("\ | |
8483 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
8484 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
8485 | a warning will be emitted for such breakpoints."), | |
8486 | NULL, | |
8487 | show_automatic_hardware_breakpoints, | |
8488 | &breakpoint_set_cmdlist, | |
8489 | &breakpoint_show_cmdlist); | |
74960c60 | 8490 | |
33e5cbd6 PA |
8491 | add_setshow_enum_cmd ("always-inserted", class_support, |
8492 | always_inserted_enums, &always_inserted_mode, _("\ | |
74960c60 VP |
8493 | Set mode for inserting breakpoints."), _("\ |
8494 | Show mode for inserting breakpoints."), _("\ | |
33e5cbd6 PA |
8495 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
8496 | resumed, and removed when execution stops. When this mode is on,\n\ | |
8497 | breakpoints are inserted immediately and removed only when the user\n\ | |
8498 | deletes the breakpoint. When this mode is auto (which is the default),\n\ | |
8499 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ | |
8500 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ | |
8501 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ | |
8502 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), | |
74960c60 VP |
8503 | NULL, |
8504 | &show_always_inserted_mode, | |
8505 | &breakpoint_set_cmdlist, | |
8506 | &breakpoint_show_cmdlist); | |
765dc015 VP |
8507 | |
8508 | automatic_hardware_breakpoints = 1; | |
c906108c | 8509 | } |