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