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