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