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