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