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