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