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