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