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