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