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