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