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