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