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