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