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