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