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