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