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