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