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