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