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