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