Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Everything about breakpoints, for GDB. |
8926118c | 2 | |
6aba47ca | 3 | Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, |
9b254dd1 | 4 | 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, |
0fb0cc75 | 5 | 2008, 2009 Free Software Foundation, Inc. |
c906108c | 6 | |
c5aa993b | 7 | This file is part of GDB. |
c906108c | 8 | |
c5aa993b JM |
9 | This program is free software; you can redistribute it and/or modify |
10 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 11 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 12 | (at your option) any later version. |
c906108c | 13 | |
c5aa993b JM |
14 | This program is distributed in the hope that it will be useful, |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
c906108c | 18 | |
c5aa993b | 19 | You should have received a copy of the GNU General Public License |
a9762ec7 | 20 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
21 | |
22 | #include "defs.h" | |
a6d9a66e | 23 | #include "arch-utils.h" |
c906108c | 24 | #include <ctype.h> |
776592bf | 25 | #include "hashtab.h" |
c906108c SS |
26 | #include "symtab.h" |
27 | #include "frame.h" | |
28 | #include "breakpoint.h" | |
1042e4c0 | 29 | #include "tracepoint.h" |
c906108c SS |
30 | #include "gdbtypes.h" |
31 | #include "expression.h" | |
32 | #include "gdbcore.h" | |
33 | #include "gdbcmd.h" | |
34 | #include "value.h" | |
35 | #include "command.h" | |
36 | #include "inferior.h" | |
37 | #include "gdbthread.h" | |
38 | #include "target.h" | |
39 | #include "language.h" | |
40 | #include "gdb_string.h" | |
41 | #include "demangle.h" | |
42 | #include "annotate.h" | |
43 | #include "symfile.h" | |
44 | #include "objfiles.h" | |
0378c332 | 45 | #include "source.h" |
c5f0f3d0 | 46 | #include "linespec.h" |
c94fdfd0 | 47 | #include "completer.h" |
5b7f31a4 | 48 | #include "gdb.h" |
8b93c638 | 49 | #include "ui-out.h" |
e1507482 | 50 | #include "cli/cli-script.h" |
0225421b | 51 | #include "gdb_assert.h" |
fe898f56 | 52 | #include "block.h" |
a77053c2 | 53 | #include "solib.h" |
84acb35a JJ |
54 | #include "solist.h" |
55 | #include "observer.h" | |
60250e8b | 56 | #include "exceptions.h" |
765dc015 | 57 | #include "memattr.h" |
f7f9143b | 58 | #include "ada-lang.h" |
d1aa2f50 | 59 | #include "top.h" |
fa4727a6 | 60 | #include "wrapper.h" |
79a45b7d | 61 | #include "valprint.h" |
c906108c | 62 | |
1042e4c0 SS |
63 | /* readline include files */ |
64 | #include "readline/readline.h" | |
65 | #include "readline/history.h" | |
66 | ||
67 | /* readline defines this. */ | |
68 | #undef savestring | |
69 | ||
034dad6f | 70 | #include "mi/mi-common.h" |
104c1213 | 71 | |
44feb3ce TT |
72 | /* Arguments to pass as context to some catch command handlers. */ |
73 | #define CATCH_PERMANENT ((void *) (uintptr_t) 0) | |
74 | #define CATCH_TEMPORARY ((void *) (uintptr_t) 1) | |
c906108c | 75 | |
44feb3ce | 76 | /* Prototypes for local functions. */ |
c906108c | 77 | |
a14ed312 | 78 | static void enable_delete_command (char *, int); |
c906108c | 79 | |
a14ed312 | 80 | static void enable_delete_breakpoint (struct breakpoint *); |
c906108c | 81 | |
a14ed312 | 82 | static void enable_once_command (char *, int); |
c906108c | 83 | |
a14ed312 | 84 | static void enable_once_breakpoint (struct breakpoint *); |
c906108c | 85 | |
a14ed312 | 86 | static void disable_command (char *, int); |
c906108c | 87 | |
a14ed312 | 88 | static void enable_command (char *, int); |
c906108c | 89 | |
a14ed312 | 90 | static void map_breakpoint_numbers (char *, void (*)(struct breakpoint *)); |
c906108c | 91 | |
a14ed312 | 92 | static void ignore_command (char *, int); |
c906108c | 93 | |
4efb68b1 | 94 | static int breakpoint_re_set_one (void *); |
c906108c | 95 | |
a14ed312 | 96 | static void clear_command (char *, int); |
c906108c | 97 | |
a14ed312 | 98 | static void catch_command (char *, int); |
c906108c | 99 | |
a14ed312 | 100 | static void watch_command (char *, int); |
c906108c | 101 | |
a14ed312 | 102 | static int can_use_hardware_watchpoint (struct value *); |
c906108c | 103 | |
98deb0da | 104 | static void break_command_1 (char *, int, int); |
c906108c | 105 | |
a14ed312 | 106 | static void mention (struct breakpoint *); |
c906108c | 107 | |
a6d9a66e UW |
108 | static struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
109 | struct symtab_and_line, | |
110 | enum bptype); | |
c906108c | 111 | |
9f60f21b | 112 | static void check_duplicates (struct breakpoint *); |
c906108c | 113 | |
76897487 KB |
114 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
115 | ||
a6d9a66e UW |
116 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
117 | CORE_ADDR bpaddr, | |
88f7da05 | 118 | enum bptype bptype); |
76897487 | 119 | |
714835d5 | 120 | static void describe_other_breakpoints (CORE_ADDR, struct obj_section *, int); |
c906108c | 121 | |
a14ed312 | 122 | static void breakpoints_info (char *, int); |
c906108c | 123 | |
a14ed312 | 124 | static void breakpoint_1 (int, int); |
c906108c | 125 | |
89f9893c | 126 | static bpstat bpstat_alloc (const struct bp_location *, bpstat); |
c906108c | 127 | |
4efb68b1 | 128 | static int breakpoint_cond_eval (void *); |
c906108c | 129 | |
4efb68b1 | 130 | static void cleanup_executing_breakpoints (void *); |
c906108c | 131 | |
a14ed312 | 132 | static void commands_command (char *, int); |
c906108c | 133 | |
a14ed312 | 134 | static void condition_command (char *, int); |
c906108c | 135 | |
a14ed312 | 136 | static int get_number_trailer (char **, int); |
c906108c | 137 | |
a14ed312 | 138 | void set_breakpoint_count (int); |
c906108c | 139 | |
c5aa993b JM |
140 | typedef enum |
141 | { | |
142 | mark_inserted, | |
143 | mark_uninserted | |
144 | } | |
145 | insertion_state_t; | |
c906108c | 146 | |
0bde7532 | 147 | static int remove_breakpoint (struct bp_location *, insertion_state_t); |
c906108c | 148 | |
a14ed312 | 149 | static enum print_stop_action print_it_typical (bpstat); |
e514a9d6 JM |
150 | |
151 | static enum print_stop_action print_bp_stop_message (bpstat bs); | |
c906108c | 152 | |
4efb68b1 | 153 | static int watchpoint_check (void *); |
c906108c | 154 | |
a14ed312 | 155 | static void maintenance_info_breakpoints (char *, int); |
c906108c | 156 | |
a14ed312 | 157 | static int hw_breakpoint_used_count (void); |
c906108c | 158 | |
a14ed312 | 159 | static int hw_watchpoint_used_count (enum bptype, int *); |
c906108c | 160 | |
a14ed312 | 161 | static void hbreak_command (char *, int); |
c906108c | 162 | |
a14ed312 | 163 | static void thbreak_command (char *, int); |
c906108c | 164 | |
a14ed312 | 165 | static void watch_command_1 (char *, int, int); |
c906108c | 166 | |
a14ed312 | 167 | static void rwatch_command (char *, int); |
c906108c | 168 | |
a14ed312 | 169 | static void awatch_command (char *, int); |
c906108c | 170 | |
a14ed312 | 171 | static void do_enable_breakpoint (struct breakpoint *, enum bpdisp); |
c906108c | 172 | |
a14ed312 | 173 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 174 | |
a14ed312 | 175 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 176 | |
a14ed312 | 177 | static void stopat_command (char *arg, int from_tty); |
7a292a7a | 178 | |
a14ed312 | 179 | static char *ep_parse_optional_if_clause (char **arg); |
7a292a7a | 180 | |
a14ed312 | 181 | static char *ep_parse_optional_filename (char **arg); |
7a292a7a | 182 | |
d85310f7 MS |
183 | static void catch_exception_command_1 (enum exception_event_kind ex_event, |
184 | char *arg, int tempflag, int from_tty); | |
7a292a7a | 185 | |
a14ed312 | 186 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 187 | |
a14ed312 | 188 | static void ep_skip_leading_whitespace (char **s); |
7a292a7a | 189 | |
1aafd4da UW |
190 | static int single_step_breakpoint_inserted_here_p (CORE_ADDR pc); |
191 | ||
fe3f5fa8 VP |
192 | static void free_bp_location (struct bp_location *loc); |
193 | ||
39d61571 | 194 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 195 | |
b60e7edf | 196 | static void update_global_location_list (int); |
a5606eee | 197 | |
b60e7edf | 198 | static void update_global_location_list_nothrow (int); |
74960c60 VP |
199 | |
200 | static int is_hardware_watchpoint (struct breakpoint *bpt); | |
201 | ||
202 | static void insert_breakpoint_locations (void); | |
a5606eee | 203 | |
1042e4c0 SS |
204 | static void tracepoints_info (char *, int); |
205 | ||
206 | static void delete_trace_command (char *, int); | |
207 | ||
208 | static void enable_trace_command (char *, int); | |
209 | ||
210 | static void disable_trace_command (char *, int); | |
211 | ||
212 | static void trace_pass_command (char *, int); | |
213 | ||
3daf8fe5 JG |
214 | static void skip_prologue_sal (struct symtab_and_line *sal); |
215 | ||
216 | ||
f3b1572e PA |
217 | /* Flag indicating that a command has proceeded the inferior past the |
218 | current breakpoint. */ | |
219 | ||
220 | static int breakpoint_proceeded; | |
221 | ||
2cec12e5 AR |
222 | static const char * |
223 | bpdisp_text (enum bpdisp disp) | |
224 | { | |
225 | /* NOTE: the following values are a part of MI protocol and represent | |
226 | values of 'disp' field returned when inferior stops at a breakpoint. */ | |
227 | static char *bpdisps[] = {"del", "dstp", "dis", "keep"}; | |
228 | return bpdisps[(int) disp]; | |
229 | } | |
c906108c | 230 | |
2cec12e5 | 231 | /* Prototypes for exported functions. */ |
c906108c SS |
232 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
233 | if such is available. */ | |
234 | static int can_use_hw_watchpoints; | |
235 | ||
920d2a44 AC |
236 | static void |
237 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
238 | struct cmd_list_element *c, | |
239 | const char *value) | |
240 | { | |
241 | fprintf_filtered (file, _("\ | |
242 | Debugger's willingness to use watchpoint hardware is %s.\n"), | |
243 | value); | |
244 | } | |
245 | ||
fa8d40ab JJ |
246 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
247 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
248 | for unrecognized breakpoint locations. | |
249 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ | |
250 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
251 | static void |
252 | show_pending_break_support (struct ui_file *file, int from_tty, | |
253 | struct cmd_list_element *c, | |
254 | const char *value) | |
255 | { | |
256 | fprintf_filtered (file, _("\ | |
257 | Debugger's behavior regarding pending breakpoints is %s.\n"), | |
258 | value); | |
259 | } | |
fa8d40ab | 260 | |
765dc015 VP |
261 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
262 | set with "break" but falling in read-only memory. | |
263 | If 0, gdb will warn about such breakpoints, but won't automatically | |
264 | use hardware breakpoints. */ | |
265 | static int automatic_hardware_breakpoints; | |
266 | static void | |
267 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
268 | struct cmd_list_element *c, | |
269 | const char *value) | |
270 | { | |
271 | fprintf_filtered (file, _("\ | |
272 | Automatic usage of hardware breakpoints is %s.\n"), | |
273 | value); | |
274 | } | |
275 | ||
33e5cbd6 PA |
276 | /* If on, gdb will keep breakpoints inserted even as inferior is |
277 | stopped, and immediately insert any new breakpoints. If off, gdb | |
278 | will insert breakpoints into inferior only when resuming it, and | |
279 | will remove breakpoints upon stop. If auto, GDB will behave as ON | |
280 | if in non-stop mode, and as OFF if all-stop mode.*/ | |
281 | ||
282 | static const char always_inserted_auto[] = "auto"; | |
283 | static const char always_inserted_on[] = "on"; | |
284 | static const char always_inserted_off[] = "off"; | |
285 | static const char *always_inserted_enums[] = { | |
286 | always_inserted_auto, | |
287 | always_inserted_off, | |
288 | always_inserted_on, | |
289 | NULL | |
290 | }; | |
291 | static const char *always_inserted_mode = always_inserted_auto; | |
292 | static void | |
74960c60 | 293 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 294 | struct cmd_list_element *c, const char *value) |
74960c60 | 295 | { |
33e5cbd6 PA |
296 | if (always_inserted_mode == always_inserted_auto) |
297 | fprintf_filtered (file, _("\ | |
298 | Always inserted breakpoint mode is %s (currently %s).\n"), | |
299 | value, | |
300 | breakpoints_always_inserted_mode () ? "on" : "off"); | |
301 | else | |
302 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), value); | |
74960c60 VP |
303 | } |
304 | ||
33e5cbd6 PA |
305 | int |
306 | breakpoints_always_inserted_mode (void) | |
307 | { | |
308 | return (always_inserted_mode == always_inserted_on | |
309 | || (always_inserted_mode == always_inserted_auto && non_stop)); | |
310 | } | |
765dc015 | 311 | |
a14ed312 | 312 | void _initialize_breakpoint (void); |
c906108c | 313 | |
c906108c SS |
314 | /* Are we executing breakpoint commands? */ |
315 | static int executing_breakpoint_commands; | |
316 | ||
c02f5703 MS |
317 | /* Are overlay event breakpoints enabled? */ |
318 | static int overlay_events_enabled; | |
319 | ||
c906108c SS |
320 | /* Walk the following statement or block through all breakpoints. |
321 | ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current | |
322 | breakpoint. */ | |
323 | ||
5c44784c | 324 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 325 | |
5c44784c JM |
326 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
327 | for (B = breakpoint_chain; \ | |
328 | B ? (TMP=B->next, 1): 0; \ | |
329 | B = TMP) | |
c906108c | 330 | |
7cc221ef DJ |
331 | /* Similar iterators for the low-level breakpoints. */ |
332 | ||
0d381245 | 333 | #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->global_next) |
7cc221ef DJ |
334 | |
335 | #define ALL_BP_LOCATIONS_SAFE(B,TMP) \ | |
336 | for (B = bp_location_chain; \ | |
0d381245 | 337 | B ? (TMP=B->global_next, 1): 0; \ |
7cc221ef DJ |
338 | B = TMP) |
339 | ||
1042e4c0 SS |
340 | /* Iterator for tracepoints only. */ |
341 | ||
342 | #define ALL_TRACEPOINTS(B) \ | |
343 | for (B = breakpoint_chain; B; B = B->next) \ | |
344 | if ((B)->type == bp_tracepoint) | |
345 | ||
7cc221ef | 346 | /* Chains of all breakpoints defined. */ |
c906108c SS |
347 | |
348 | struct breakpoint *breakpoint_chain; | |
349 | ||
7cc221ef DJ |
350 | struct bp_location *bp_location_chain; |
351 | ||
20874c92 VP |
352 | /* The locations that no longer correspond to any breakpoint, |
353 | unlinked from bp_location_chain, but for which a hit | |
354 | may still be reported by a target. */ | |
355 | VEC(bp_location_p) *moribund_locations = NULL; | |
356 | ||
c906108c SS |
357 | /* Number of last breakpoint made. */ |
358 | ||
359 | int breakpoint_count; | |
360 | ||
1042e4c0 SS |
361 | /* Number of last tracepoint made. */ |
362 | ||
363 | int tracepoint_count; | |
364 | ||
468d015d JJ |
365 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
366 | static int | |
367 | breakpoint_enabled (struct breakpoint *b) | |
368 | { | |
0d381245 | 369 | return (b->enable_state == bp_enabled); |
468d015d JJ |
370 | } |
371 | ||
c906108c SS |
372 | /* Set breakpoint count to NUM. */ |
373 | ||
374 | void | |
fba45db2 | 375 | set_breakpoint_count (int num) |
c906108c SS |
376 | { |
377 | breakpoint_count = num; | |
4fa62494 | 378 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
379 | } |
380 | ||
381 | /* Used in run_command to zero the hit count when a new run starts. */ | |
382 | ||
383 | void | |
fba45db2 | 384 | clear_breakpoint_hit_counts (void) |
c906108c SS |
385 | { |
386 | struct breakpoint *b; | |
387 | ||
388 | ALL_BREAKPOINTS (b) | |
389 | b->hit_count = 0; | |
390 | } | |
391 | ||
392 | /* Default address, symtab and line to put a breakpoint at | |
393 | for "break" command with no arg. | |
394 | if default_breakpoint_valid is zero, the other three are | |
395 | not valid, and "break" with no arg is an error. | |
396 | ||
397 | This set by print_stack_frame, which calls set_default_breakpoint. */ | |
398 | ||
399 | int default_breakpoint_valid; | |
400 | CORE_ADDR default_breakpoint_address; | |
401 | struct symtab *default_breakpoint_symtab; | |
402 | int default_breakpoint_line; | |
403 | \f | |
404 | /* *PP is a string denoting a breakpoint. Get the number of the breakpoint. | |
405 | Advance *PP after the string and any trailing whitespace. | |
406 | ||
407 | Currently the string can either be a number or "$" followed by the name | |
408 | of a convenience variable. Making it an expression wouldn't work well | |
5c44784c | 409 | for map_breakpoint_numbers (e.g. "4 + 5 + 6"). |
40c03ae8 EZ |
410 | |
411 | If the string is a NULL pointer, that denotes the last breakpoint. | |
5c44784c JM |
412 | |
413 | TRAILER is a character which can be found after the number; most | |
414 | commonly this is `-'. If you don't want a trailer, use \0. */ | |
c906108c | 415 | static int |
fba45db2 | 416 | get_number_trailer (char **pp, int trailer) |
c906108c | 417 | { |
5c44784c | 418 | int retval = 0; /* default */ |
c906108c SS |
419 | char *p = *pp; |
420 | ||
421 | if (p == NULL) | |
422 | /* Empty line means refer to the last breakpoint. */ | |
423 | return breakpoint_count; | |
424 | else if (*p == '$') | |
425 | { | |
426 | /* Make a copy of the name, so we can null-terminate it | |
c5aa993b | 427 | to pass to lookup_internalvar(). */ |
c906108c SS |
428 | char *varname; |
429 | char *start = ++p; | |
4fa62494 | 430 | LONGEST val; |
c906108c SS |
431 | |
432 | while (isalnum (*p) || *p == '_') | |
433 | p++; | |
434 | varname = (char *) alloca (p - start + 1); | |
435 | strncpy (varname, start, p - start); | |
436 | varname[p - start] = '\0'; | |
4fa62494 UW |
437 | if (get_internalvar_integer (lookup_internalvar (varname), &val)) |
438 | retval = (int) val; | |
5c44784c JM |
439 | else |
440 | { | |
a3f17187 | 441 | printf_filtered (_("Convenience variable must have integer value.\n")); |
5c44784c JM |
442 | retval = 0; |
443 | } | |
c906108c SS |
444 | } |
445 | else | |
446 | { | |
447 | if (*p == '-') | |
448 | ++p; | |
449 | while (*p >= '0' && *p <= '9') | |
450 | ++p; | |
451 | if (p == *pp) | |
452 | /* There is no number here. (e.g. "cond a == b"). */ | |
5c44784c JM |
453 | { |
454 | /* Skip non-numeric token */ | |
455 | while (*p && !isspace((int) *p)) | |
456 | ++p; | |
457 | /* Return zero, which caller must interpret as error. */ | |
458 | retval = 0; | |
459 | } | |
460 | else | |
461 | retval = atoi (*pp); | |
462 | } | |
463 | if (!(isspace (*p) || *p == '\0' || *p == trailer)) | |
464 | { | |
465 | /* Trailing junk: return 0 and let caller print error msg. */ | |
466 | while (!(isspace (*p) || *p == '\0' || *p == trailer)) | |
467 | ++p; | |
468 | retval = 0; | |
c906108c | 469 | } |
c906108c SS |
470 | while (isspace (*p)) |
471 | p++; | |
472 | *pp = p; | |
473 | return retval; | |
474 | } | |
5c44784c | 475 | |
11cf8741 | 476 | |
5c44784c JM |
477 | /* Like get_number_trailer, but don't allow a trailer. */ |
478 | int | |
fba45db2 | 479 | get_number (char **pp) |
5c44784c JM |
480 | { |
481 | return get_number_trailer (pp, '\0'); | |
482 | } | |
483 | ||
484 | /* Parse a number or a range. | |
485 | * A number will be of the form handled by get_number. | |
486 | * A range will be of the form <number1> - <number2>, and | |
487 | * will represent all the integers between number1 and number2, | |
488 | * inclusive. | |
489 | * | |
490 | * While processing a range, this fuction is called iteratively; | |
491 | * At each call it will return the next value in the range. | |
492 | * | |
493 | * At the beginning of parsing a range, the char pointer PP will | |
494 | * be advanced past <number1> and left pointing at the '-' token. | |
495 | * Subsequent calls will not advance the pointer until the range | |
496 | * is completed. The call that completes the range will advance | |
497 | * pointer PP past <number2>. | |
498 | */ | |
499 | ||
500 | int | |
fba45db2 | 501 | get_number_or_range (char **pp) |
5c44784c JM |
502 | { |
503 | static int last_retval, end_value; | |
504 | static char *end_ptr; | |
505 | static int in_range = 0; | |
506 | ||
507 | if (**pp != '-') | |
508 | { | |
509 | /* Default case: pp is pointing either to a solo number, | |
510 | or to the first number of a range. */ | |
511 | last_retval = get_number_trailer (pp, '-'); | |
512 | if (**pp == '-') | |
513 | { | |
514 | char **temp; | |
515 | ||
516 | /* This is the start of a range (<number1> - <number2>). | |
517 | Skip the '-', parse and remember the second number, | |
518 | and also remember the end of the final token. */ | |
519 | ||
520 | temp = &end_ptr; | |
521 | end_ptr = *pp + 1; | |
522 | while (isspace ((int) *end_ptr)) | |
523 | end_ptr++; /* skip white space */ | |
524 | end_value = get_number (temp); | |
525 | if (end_value < last_retval) | |
526 | { | |
8a3fe4f8 | 527 | error (_("inverted range")); |
5c44784c JM |
528 | } |
529 | else if (end_value == last_retval) | |
530 | { | |
531 | /* degenerate range (number1 == number2). Advance the | |
532 | token pointer so that the range will be treated as a | |
533 | single number. */ | |
534 | *pp = end_ptr; | |
535 | } | |
536 | else | |
537 | in_range = 1; | |
538 | } | |
539 | } | |
540 | else if (! in_range) | |
8a3fe4f8 | 541 | error (_("negative value")); |
5c44784c JM |
542 | else |
543 | { | |
544 | /* pp points to the '-' that betokens a range. All | |
545 | number-parsing has already been done. Return the next | |
546 | integer value (one greater than the saved previous value). | |
547 | Do not advance the token pointer 'pp' until the end of range | |
548 | is reached. */ | |
549 | ||
550 | if (++last_retval == end_value) | |
551 | { | |
552 | /* End of range reached; advance token pointer. */ | |
553 | *pp = end_ptr; | |
554 | in_range = 0; | |
555 | } | |
556 | } | |
557 | return last_retval; | |
558 | } | |
559 | ||
560 | ||
c906108c SS |
561 | \f |
562 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ | |
563 | ||
564 | static void | |
fba45db2 | 565 | condition_command (char *arg, int from_tty) |
c906108c | 566 | { |
52f0bd74 | 567 | struct breakpoint *b; |
c906108c | 568 | char *p; |
52f0bd74 | 569 | int bnum; |
c906108c SS |
570 | |
571 | if (arg == 0) | |
e2e0b3e5 | 572 | error_no_arg (_("breakpoint number")); |
c906108c SS |
573 | |
574 | p = arg; | |
575 | bnum = get_number (&p); | |
5c44784c | 576 | if (bnum == 0) |
8a3fe4f8 | 577 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
578 | |
579 | ALL_BREAKPOINTS (b) | |
580 | if (b->number == bnum) | |
2f069f6f JB |
581 | { |
582 | struct bp_location *loc = b->loc; | |
583 | for (; loc; loc = loc->next) | |
584 | { | |
585 | if (loc->cond) | |
586 | { | |
587 | xfree (loc->cond); | |
588 | loc->cond = 0; | |
589 | } | |
590 | } | |
591 | if (b->cond_string != NULL) | |
592 | xfree (b->cond_string); | |
c906108c | 593 | |
2f069f6f JB |
594 | if (*p == 0) |
595 | { | |
596 | b->cond_string = NULL; | |
597 | if (from_tty) | |
598 | printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum); | |
599 | } | |
600 | else | |
601 | { | |
602 | arg = p; | |
603 | /* I don't know if it matters whether this is the string the user | |
604 | typed in or the decompiled expression. */ | |
1b36a34b | 605 | b->cond_string = xstrdup (arg); |
2f069f6f JB |
606 | b->condition_not_parsed = 0; |
607 | for (loc = b->loc; loc; loc = loc->next) | |
608 | { | |
609 | arg = p; | |
610 | loc->cond = | |
611 | parse_exp_1 (&arg, block_for_pc (loc->address), 0); | |
612 | if (*arg) | |
613 | error (_("Junk at end of expression")); | |
614 | } | |
615 | } | |
616 | breakpoints_changed (); | |
383f836e | 617 | observer_notify_breakpoint_modified (b->number); |
2f069f6f JB |
618 | return; |
619 | } | |
c906108c | 620 | |
8a3fe4f8 | 621 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
622 | } |
623 | ||
c906108c | 624 | static void |
fba45db2 | 625 | commands_command (char *arg, int from_tty) |
c906108c | 626 | { |
52f0bd74 | 627 | struct breakpoint *b; |
c906108c | 628 | char *p; |
52f0bd74 | 629 | int bnum; |
c906108c SS |
630 | struct command_line *l; |
631 | ||
632 | /* If we allowed this, we would have problems with when to | |
633 | free the storage, if we change the commands currently | |
634 | being read from. */ | |
635 | ||
636 | if (executing_breakpoint_commands) | |
8a3fe4f8 | 637 | error (_("Can't use the \"commands\" command among a breakpoint's commands.")); |
c906108c SS |
638 | |
639 | p = arg; | |
640 | bnum = get_number (&p); | |
5c44784c | 641 | |
c906108c | 642 | if (p && *p) |
8a3fe4f8 | 643 | error (_("Unexpected extra arguments following breakpoint number.")); |
c5aa993b | 644 | |
c906108c SS |
645 | ALL_BREAKPOINTS (b) |
646 | if (b->number == bnum) | |
9ebf4acf AC |
647 | { |
648 | char *tmpbuf = xstrprintf ("Type commands for when breakpoint %d is hit, one per line.", | |
649 | bnum); | |
650 | struct cleanup *cleanups = make_cleanup (xfree, tmpbuf); | |
311a4e6b | 651 | l = read_command_lines (tmpbuf, from_tty, 1); |
9ebf4acf AC |
652 | do_cleanups (cleanups); |
653 | free_command_lines (&b->commands); | |
654 | b->commands = l; | |
655 | breakpoints_changed (); | |
383f836e | 656 | observer_notify_breakpoint_modified (b->number); |
9ebf4acf | 657 | return; |
c5aa993b | 658 | } |
8a3fe4f8 | 659 | error (_("No breakpoint number %d."), bnum); |
c906108c | 660 | } |
40c03ae8 EZ |
661 | |
662 | /* Like commands_command, but instead of reading the commands from | |
663 | input stream, takes them from an already parsed command structure. | |
664 | ||
665 | This is used by cli-script.c to DTRT with breakpoint commands | |
666 | that are part of if and while bodies. */ | |
667 | enum command_control_type | |
668 | commands_from_control_command (char *arg, struct command_line *cmd) | |
669 | { | |
670 | struct breakpoint *b; | |
671 | char *p; | |
672 | int bnum; | |
673 | ||
674 | /* If we allowed this, we would have problems with when to | |
675 | free the storage, if we change the commands currently | |
676 | being read from. */ | |
677 | ||
678 | if (executing_breakpoint_commands) | |
679 | error (_("Can't use the \"commands\" command among a breakpoint's commands.")); | |
680 | ||
681 | /* An empty string for the breakpoint number means the last | |
682 | breakpoint, but get_number expects a NULL pointer. */ | |
683 | if (arg && !*arg) | |
684 | p = NULL; | |
685 | else | |
686 | p = arg; | |
687 | bnum = get_number (&p); | |
688 | ||
689 | if (p && *p) | |
690 | error (_("Unexpected extra arguments following breakpoint number.")); | |
691 | ||
692 | ALL_BREAKPOINTS (b) | |
693 | if (b->number == bnum) | |
694 | { | |
695 | free_command_lines (&b->commands); | |
696 | if (cmd->body_count != 1) | |
697 | error (_("Invalid \"commands\" block structure.")); | |
698 | /* We need to copy the commands because if/while will free the | |
699 | list after it finishes execution. */ | |
700 | b->commands = copy_command_lines (cmd->body_list[0]); | |
701 | breakpoints_changed (); | |
383f836e | 702 | observer_notify_breakpoint_modified (b->number); |
40c03ae8 | 703 | return simple_control; |
2f069f6f | 704 | } |
40c03ae8 EZ |
705 | error (_("No breakpoint number %d."), bnum); |
706 | } | |
c906108c | 707 | \f |
8defab1a DJ |
708 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
709 | by replacing any memory breakpoints with their shadowed contents. */ | |
c906108c | 710 | |
8defab1a DJ |
711 | void |
712 | breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len) | |
c906108c | 713 | { |
8defab1a | 714 | struct bp_location *b; |
c906108c SS |
715 | CORE_ADDR bp_addr = 0; |
716 | int bp_size = 0; | |
8defab1a | 717 | int bptoffset = 0; |
c5aa993b | 718 | |
ffce0d52 | 719 | ALL_BP_LOCATIONS (b) |
c5aa993b | 720 | { |
ffce0d52 | 721 | if (b->owner->type == bp_none) |
8a3fe4f8 | 722 | warning (_("reading through apparently deleted breakpoint #%d?"), |
ffce0d52 DJ |
723 | b->owner->number); |
724 | ||
725 | if (b->loc_type != bp_loc_software_breakpoint) | |
c5aa993b | 726 | continue; |
ffce0d52 | 727 | if (!b->inserted) |
c5aa993b JM |
728 | continue; |
729 | /* Addresses and length of the part of the breakpoint that | |
730 | we need to copy. */ | |
8181d85f DJ |
731 | bp_addr = b->target_info.placed_address; |
732 | bp_size = b->target_info.shadow_len; | |
c5aa993b | 733 | if (bp_size == 0) |
8181d85f | 734 | /* bp isn't valid, or doesn't shadow memory. */ |
c5aa993b | 735 | continue; |
8defab1a | 736 | |
c5aa993b JM |
737 | if (bp_addr + bp_size <= memaddr) |
738 | /* The breakpoint is entirely before the chunk of memory we | |
739 | are reading. */ | |
740 | continue; | |
8defab1a | 741 | |
c5aa993b JM |
742 | if (bp_addr >= memaddr + len) |
743 | /* The breakpoint is entirely after the chunk of memory we are | |
744 | reading. */ | |
745 | continue; | |
c5aa993b | 746 | |
8defab1a DJ |
747 | /* Offset within shadow_contents. */ |
748 | if (bp_addr < memaddr) | |
749 | { | |
750 | /* Only copy the second part of the breakpoint. */ | |
751 | bp_size -= memaddr - bp_addr; | |
752 | bptoffset = memaddr - bp_addr; | |
753 | bp_addr = memaddr; | |
754 | } | |
c5aa993b | 755 | |
8defab1a DJ |
756 | if (bp_addr + bp_size > memaddr + len) |
757 | { | |
758 | /* Only copy the first part of the breakpoint. */ | |
759 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
760 | } | |
c5aa993b | 761 | |
8defab1a DJ |
762 | memcpy (buf + bp_addr - memaddr, |
763 | b->target_info.shadow_contents + bptoffset, bp_size); | |
c5aa993b | 764 | } |
c906108c | 765 | } |
c906108c | 766 | \f |
c5aa993b | 767 | |
687595f9 | 768 | /* A wrapper function for inserting catchpoints. */ |
9cbc821d | 769 | static void |
687595f9 DJ |
770 | insert_catchpoint (struct ui_out *uo, void *args) |
771 | { | |
772 | struct breakpoint *b = (struct breakpoint *) args; | |
773 | int val = -1; | |
774 | ||
fe798b75 JB |
775 | gdb_assert (b->type == bp_catchpoint); |
776 | gdb_assert (b->ops != NULL && b->ops->insert != NULL); | |
777 | ||
778 | b->ops->insert (b); | |
687595f9 DJ |
779 | } |
780 | ||
a5606eee VP |
781 | static int |
782 | is_hardware_watchpoint (struct breakpoint *bpt) | |
783 | { | |
784 | return (bpt->type == bp_hardware_watchpoint | |
785 | || bpt->type == bp_read_watchpoint | |
786 | || bpt->type == bp_access_watchpoint); | |
787 | } | |
7270d8f2 | 788 | |
fa4727a6 DJ |
789 | /* Find the current value of a watchpoint on EXP. Return the value in |
790 | *VALP and *RESULTP and the chain of intermediate and final values | |
791 | in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does | |
792 | not need them. | |
793 | ||
ccc57cf9 | 794 | If a memory error occurs while evaluating the expression, *RESULTP will |
fa4727a6 DJ |
795 | be set to NULL. *RESULTP may be a lazy value, if the result could |
796 | not be read from memory. It is used to determine whether a value | |
797 | is user-specified (we should watch the whole value) or intermediate | |
798 | (we should watch only the bit used to locate the final value). | |
799 | ||
800 | If the final value, or any intermediate value, could not be read | |
801 | from memory, *VALP will be set to NULL. *VAL_CHAIN will still be | |
802 | set to any referenced values. *VALP will never be a lazy value. | |
803 | This is the value which we store in struct breakpoint. | |
804 | ||
805 | If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the | |
806 | value chain. The caller must free the values individually. If | |
807 | VAL_CHAIN is NULL, all generated values will be left on the value | |
808 | chain. */ | |
809 | ||
810 | static void | |
811 | fetch_watchpoint_value (struct expression *exp, struct value **valp, | |
812 | struct value **resultp, struct value **val_chain) | |
813 | { | |
814 | struct value *mark, *new_mark, *result; | |
ccc57cf9 | 815 | volatile struct gdb_exception ex; |
fa4727a6 DJ |
816 | |
817 | *valp = NULL; | |
818 | if (resultp) | |
819 | *resultp = NULL; | |
820 | if (val_chain) | |
821 | *val_chain = NULL; | |
822 | ||
823 | /* Evaluate the expression. */ | |
824 | mark = value_mark (); | |
825 | result = NULL; | |
ccc57cf9 PA |
826 | |
827 | TRY_CATCH (ex, RETURN_MASK_ALL) | |
828 | { | |
829 | result = evaluate_expression (exp); | |
830 | } | |
831 | if (ex.reason < 0) | |
832 | { | |
833 | /* Ignore memory errors, we want watchpoints pointing at | |
834 | inaccessible memory to still be created; otherwise, throw the | |
835 | error to some higher catcher. */ | |
836 | switch (ex.error) | |
837 | { | |
838 | case MEMORY_ERROR: | |
839 | break; | |
840 | default: | |
841 | throw_exception (ex); | |
842 | break; | |
843 | } | |
844 | } | |
845 | ||
fa4727a6 DJ |
846 | new_mark = value_mark (); |
847 | if (mark == new_mark) | |
848 | return; | |
849 | if (resultp) | |
850 | *resultp = result; | |
851 | ||
852 | /* Make sure it's not lazy, so that after the target stops again we | |
853 | have a non-lazy previous value to compare with. */ | |
854 | if (result != NULL | |
855 | && (!value_lazy (result) || gdb_value_fetch_lazy (result))) | |
856 | *valp = result; | |
857 | ||
858 | if (val_chain) | |
859 | { | |
860 | /* Return the chain of intermediate values. We use this to | |
861 | decide which addresses to watch. */ | |
862 | *val_chain = new_mark; | |
863 | value_release_to_mark (mark); | |
864 | } | |
865 | } | |
866 | ||
567e1b4e JB |
867 | /* Assuming that B is a watchpoint: |
868 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 869 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
870 | - Evaluate the condition if there is one, and store the result |
871 | in b->loc->cond. | |
a5606eee VP |
872 | - Update the list of values that must be watched in B->loc. |
873 | ||
bfa149ac JB |
874 | If the watchpoint disposition is disp_del_at_next_stop, then do nothing. |
875 | If this is local watchpoint that is out of scope, delete it. */ | |
b40ce68a | 876 | static void |
a5606eee | 877 | update_watchpoint (struct breakpoint *b, int reparse) |
7270d8f2 | 878 | { |
a5606eee | 879 | int within_current_scope; |
a5606eee VP |
880 | struct frame_id saved_frame_id; |
881 | struct bp_location *loc; | |
882 | bpstat bs; | |
883 | ||
567e1b4e JB |
884 | /* We don't free locations. They are stored in bp_location_chain and |
885 | update_global_locations will eventually delete them and remove | |
886 | breakpoints if needed. */ | |
a5606eee VP |
887 | b->loc = NULL; |
888 | ||
889 | if (b->disposition == disp_del_at_next_stop) | |
890 | return; | |
891 | ||
892 | /* Save the current frame's ID so we can restore it after | |
893 | evaluating the watchpoint expression on its own frame. */ | |
894 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
895 | took a frame parameter, so that we didn't have to change the | |
896 | selected frame. */ | |
897 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
898 | ||
899 | /* Determine if the watchpoint is within scope. */ | |
900 | if (b->exp_valid_block == NULL) | |
901 | within_current_scope = 1; | |
902 | else | |
903 | { | |
904 | struct frame_info *fi; | |
905 | fi = frame_find_by_id (b->watchpoint_frame); | |
906 | within_current_scope = (fi != NULL); | |
907 | if (within_current_scope) | |
908 | select_frame (fi); | |
909 | } | |
910 | ||
911 | if (within_current_scope && reparse) | |
912 | { | |
913 | char *s; | |
914 | if (b->exp) | |
915 | { | |
916 | xfree (b->exp); | |
917 | b->exp = NULL; | |
918 | } | |
919 | s = b->exp_string; | |
920 | b->exp = parse_exp_1 (&s, b->exp_valid_block, 0); | |
921 | /* If the meaning of expression itself changed, the old value is | |
922 | no longer relevant. We don't want to report a watchpoint hit | |
923 | to the user when the old value and the new value may actually | |
924 | be completely different objects. */ | |
925 | value_free (b->val); | |
fa4727a6 DJ |
926 | b->val = NULL; |
927 | b->val_valid = 0; | |
a5606eee | 928 | } |
a5606eee VP |
929 | |
930 | /* If we failed to parse the expression, for example because | |
931 | it refers to a global variable in a not-yet-loaded shared library, | |
932 | don't try to insert watchpoint. We don't automatically delete | |
933 | such watchpoint, though, since failure to parse expression | |
934 | is different from out-of-scope watchpoint. */ | |
935 | if (within_current_scope && b->exp) | |
936 | { | |
fa4727a6 | 937 | struct value *val_chain, *v, *result, *next; |
a5606eee | 938 | |
fa4727a6 | 939 | fetch_watchpoint_value (b->exp, &v, &result, &val_chain); |
a5606eee | 940 | |
a5606eee VP |
941 | /* Avoid setting b->val if it's already set. The meaning of |
942 | b->val is 'the last value' user saw, and we should update | |
943 | it only if we reported that last value to user. As it | |
944 | happens, the code that reports it updates b->val directly. */ | |
fa4727a6 DJ |
945 | if (!b->val_valid) |
946 | { | |
947 | b->val = v; | |
948 | b->val_valid = 1; | |
949 | } | |
a5606eee | 950 | |
db2ad4c3 JK |
951 | /* Change the type of breakpoint between hardware assisted or an |
952 | ordinary watchpoint depending on the hardware support and free | |
953 | hardware slots. REPARSE is set when the inferior is started. */ | |
954 | if ((b->type == bp_watchpoint || b->type == bp_hardware_watchpoint) | |
955 | && reparse) | |
956 | { | |
ca2d49e8 | 957 | int i, mem_cnt, other_type_used; |
db2ad4c3 JK |
958 | |
959 | i = hw_watchpoint_used_count (bp_hardware_watchpoint, | |
960 | &other_type_used); | |
961 | mem_cnt = can_use_hardware_watchpoint (val_chain); | |
962 | ||
ca2d49e8 | 963 | if (!mem_cnt) |
db2ad4c3 JK |
964 | b->type = bp_watchpoint; |
965 | else | |
ca2d49e8 | 966 | { |
d92524f1 | 967 | int target_resources_ok = target_can_use_hardware_watchpoint |
ca2d49e8 SL |
968 | (bp_hardware_watchpoint, i + mem_cnt, other_type_used); |
969 | if (target_resources_ok <= 0) | |
970 | b->type = bp_watchpoint; | |
971 | else | |
972 | b->type = bp_hardware_watchpoint; | |
973 | } | |
db2ad4c3 JK |
974 | } |
975 | ||
a5606eee | 976 | /* Look at each value on the value chain. */ |
fa4727a6 | 977 | for (v = val_chain; v; v = next) |
a5606eee VP |
978 | { |
979 | /* If it's a memory location, and GDB actually needed | |
980 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
981 | must watch it. If the first value returned is |
982 | still lazy, that means an error occurred reading it; | |
983 | watch it anyway in case it becomes readable. */ | |
a5606eee | 984 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 985 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
986 | { |
987 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 988 | |
a5606eee VP |
989 | /* We only watch structs and arrays if user asked |
990 | for it explicitly, never if they just happen to | |
991 | appear in the middle of some value chain. */ | |
fa4727a6 | 992 | if (v == result |
a5606eee VP |
993 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
994 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
995 | { | |
996 | CORE_ADDR addr; | |
997 | int len, type; | |
998 | struct bp_location *loc, **tmp; | |
999 | ||
42ae5230 | 1000 | addr = value_address (v); |
a5606eee VP |
1001 | len = TYPE_LENGTH (value_type (v)); |
1002 | type = hw_write; | |
1003 | if (b->type == bp_read_watchpoint) | |
1004 | type = hw_read; | |
1005 | else if (b->type == bp_access_watchpoint) | |
1006 | type = hw_access; | |
1007 | ||
39d61571 | 1008 | loc = allocate_bp_location (b); |
a5606eee VP |
1009 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
1010 | ; | |
1011 | *tmp = loc; | |
a6d9a66e | 1012 | loc->gdbarch = get_type_arch (value_type (v)); |
a5606eee VP |
1013 | loc->address = addr; |
1014 | loc->length = len; | |
1015 | loc->watchpoint_type = type; | |
1016 | } | |
1017 | } | |
1018 | ||
1019 | next = value_next (v); | |
1020 | if (v != b->val) | |
1021 | value_free (v); | |
1022 | } | |
1023 | ||
2ec93238 MK |
1024 | /* We just regenerated the list of breakpoint locations. |
1025 | The new location does not have its condition field set to anything | |
1026 | and therefore, we must always reparse the cond_string, independently | |
1027 | of the value of the reparse flag. */ | |
1028 | if (b->cond_string != NULL) | |
a5606eee VP |
1029 | { |
1030 | char *s = b->cond_string; | |
a5606eee VP |
1031 | b->loc->cond = parse_exp_1 (&s, b->exp_valid_block, 0); |
1032 | } | |
1033 | } | |
1034 | else if (!within_current_scope) | |
7270d8f2 | 1035 | { |
a5606eee | 1036 | printf_filtered (_("\ |
567e1b4e | 1037 | Watchpoint %d deleted because the program has left the block \n\ |
a5606eee VP |
1038 | in which its expression is valid.\n"), |
1039 | b->number); | |
1040 | if (b->related_breakpoint) | |
1041 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1042 | b->disposition = disp_del_at_next_stop; | |
7270d8f2 | 1043 | } |
a5606eee VP |
1044 | |
1045 | /* Restore the selected frame. */ | |
1046 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
1047 | } |
1048 | ||
a5606eee | 1049 | |
74960c60 VP |
1050 | /* Returns 1 iff breakpoint location should be |
1051 | inserted in the inferior. */ | |
1052 | static int | |
1053 | should_be_inserted (struct bp_location *bpt) | |
1054 | { | |
1055 | if (!breakpoint_enabled (bpt->owner)) | |
1056 | return 0; | |
1057 | ||
1058 | if (bpt->owner->disposition == disp_del_at_next_stop) | |
1059 | return 0; | |
1060 | ||
1061 | if (!bpt->enabled || bpt->shlib_disabled || bpt->duplicate) | |
1062 | return 0; | |
1063 | ||
1042e4c0 SS |
1064 | /* Tracepoints are inserted by the target at a time of its choosing, |
1065 | not by us. */ | |
1066 | if (bpt->owner->type == bp_tracepoint) | |
1067 | return 0; | |
1068 | ||
74960c60 VP |
1069 | return 1; |
1070 | } | |
1071 | ||
879bfdc2 DJ |
1072 | /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint. |
1073 | Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS, | |
fa3a767f | 1074 | and HW_BREAKPOINT_ERROR are used to report problems. |
879bfdc2 DJ |
1075 | |
1076 | NOTE drow/2003-09-09: This routine could be broken down to an object-style | |
1077 | method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 1078 | static int |
879bfdc2 | 1079 | insert_bp_location (struct bp_location *bpt, |
26bb91f3 | 1080 | struct ui_file *tmp_error_stream, |
fa3a767f | 1081 | int *disabled_breaks, |
26bb91f3 | 1082 | int *hw_breakpoint_error) |
879bfdc2 DJ |
1083 | { |
1084 | int val = 0; | |
1085 | ||
74960c60 | 1086 | if (!should_be_inserted (bpt) || bpt->inserted) |
879bfdc2 DJ |
1087 | return 0; |
1088 | ||
8181d85f DJ |
1089 | /* Initialize the target-specific information. */ |
1090 | memset (&bpt->target_info, 0, sizeof (bpt->target_info)); | |
1091 | bpt->target_info.placed_address = bpt->address; | |
1092 | ||
879bfdc2 DJ |
1093 | if (bpt->loc_type == bp_loc_software_breakpoint |
1094 | || bpt->loc_type == bp_loc_hardware_breakpoint) | |
1095 | { | |
765dc015 VP |
1096 | if (bpt->owner->type != bp_hardware_breakpoint) |
1097 | { | |
1098 | /* If the explicitly specified breakpoint type | |
1099 | is not hardware breakpoint, check the memory map to see | |
1100 | if the breakpoint address is in read only memory or not. | |
1101 | Two important cases are: | |
1102 | - location type is not hardware breakpoint, memory | |
1103 | is readonly. We change the type of the location to | |
1104 | hardware breakpoint. | |
1105 | - location type is hardware breakpoint, memory is read-write. | |
1106 | This means we've previously made the location hardware one, but | |
1107 | then the memory map changed, so we undo. | |
1108 | ||
1109 | When breakpoints are removed, remove_breakpoints will | |
1110 | use location types we've just set here, the only possible | |
1111 | problem is that memory map has changed during running program, | |
1112 | but it's not going to work anyway with current gdb. */ | |
1113 | struct mem_region *mr | |
1114 | = lookup_mem_region (bpt->target_info.placed_address); | |
1115 | ||
1116 | if (mr) | |
1117 | { | |
1118 | if (automatic_hardware_breakpoints) | |
1119 | { | |
1120 | int changed = 0; | |
1121 | enum bp_loc_type new_type; | |
1122 | ||
1123 | if (mr->attrib.mode != MEM_RW) | |
1124 | new_type = bp_loc_hardware_breakpoint; | |
1125 | else | |
1126 | new_type = bp_loc_software_breakpoint; | |
1127 | ||
1128 | if (new_type != bpt->loc_type) | |
1129 | { | |
1130 | static int said = 0; | |
1131 | bpt->loc_type = new_type; | |
1132 | if (!said) | |
1133 | { | |
1134 | fprintf_filtered (gdb_stdout, _("\ | |
0767c96d | 1135 | Note: automatically using hardware breakpoints for read-only addresses.\n")); |
765dc015 VP |
1136 | said = 1; |
1137 | } | |
1138 | } | |
1139 | } | |
1140 | else if (bpt->loc_type == bp_loc_software_breakpoint | |
1141 | && mr->attrib.mode != MEM_RW) | |
1142 | warning (_("cannot set software breakpoint at readonly address %s"), | |
1143 | paddr (bpt->address)); | |
1144 | } | |
1145 | } | |
1146 | ||
879bfdc2 DJ |
1147 | /* First check to see if we have to handle an overlay. */ |
1148 | if (overlay_debugging == ovly_off | |
1149 | || bpt->section == NULL | |
1150 | || !(section_is_overlay (bpt->section))) | |
1151 | { | |
1152 | /* No overlay handling: just set the breakpoint. */ | |
1153 | ||
1154 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
a6d9a66e UW |
1155 | val = target_insert_hw_breakpoint (bpt->gdbarch, |
1156 | &bpt->target_info); | |
879bfdc2 | 1157 | else |
a6d9a66e UW |
1158 | val = target_insert_breakpoint (bpt->gdbarch, |
1159 | &bpt->target_info); | |
879bfdc2 DJ |
1160 | } |
1161 | else | |
1162 | { | |
1163 | /* This breakpoint is in an overlay section. | |
1164 | Shall we set a breakpoint at the LMA? */ | |
1165 | if (!overlay_events_enabled) | |
1166 | { | |
1167 | /* Yes -- overlay event support is not active, | |
1168 | so we must try to set a breakpoint at the LMA. | |
1169 | This will not work for a hardware breakpoint. */ | |
1170 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
8a3fe4f8 | 1171 | warning (_("hardware breakpoint %d not supported in overlay!"), |
879bfdc2 DJ |
1172 | bpt->owner->number); |
1173 | else | |
1174 | { | |
1175 | CORE_ADDR addr = overlay_unmapped_address (bpt->address, | |
1176 | bpt->section); | |
1177 | /* Set a software (trap) breakpoint at the LMA. */ | |
8181d85f DJ |
1178 | bpt->overlay_target_info = bpt->target_info; |
1179 | bpt->overlay_target_info.placed_address = addr; | |
a6d9a66e UW |
1180 | val = target_insert_breakpoint (bpt->gdbarch, |
1181 | &bpt->overlay_target_info); | |
879bfdc2 | 1182 | if (val != 0) |
99361f52 DE |
1183 | fprintf_unfiltered (tmp_error_stream, |
1184 | "Overlay breakpoint %d failed: in ROM?\n", | |
879bfdc2 DJ |
1185 | bpt->owner->number); |
1186 | } | |
1187 | } | |
1188 | /* Shall we set a breakpoint at the VMA? */ | |
1189 | if (section_is_mapped (bpt->section)) | |
1190 | { | |
1191 | /* Yes. This overlay section is mapped into memory. */ | |
1192 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
a6d9a66e UW |
1193 | val = target_insert_hw_breakpoint (bpt->gdbarch, |
1194 | &bpt->target_info); | |
879bfdc2 | 1195 | else |
a6d9a66e UW |
1196 | val = target_insert_breakpoint (bpt->gdbarch, |
1197 | &bpt->target_info); | |
879bfdc2 DJ |
1198 | } |
1199 | else | |
1200 | { | |
1201 | /* No. This breakpoint will not be inserted. | |
1202 | No error, but do not mark the bp as 'inserted'. */ | |
1203 | return 0; | |
1204 | } | |
1205 | } | |
1206 | ||
1207 | if (val) | |
1208 | { | |
1209 | /* Can't set the breakpoint. */ | |
f5c9a895 | 1210 | if (solib_name_from_address (bpt->address)) |
879bfdc2 DJ |
1211 | { |
1212 | /* See also: disable_breakpoints_in_shlibs. */ | |
1213 | val = 0; | |
0d381245 | 1214 | bpt->shlib_disabled = 1; |
879bfdc2 DJ |
1215 | if (!*disabled_breaks) |
1216 | { | |
1217 | fprintf_unfiltered (tmp_error_stream, | |
1218 | "Cannot insert breakpoint %d.\n", | |
1219 | bpt->owner->number); | |
1220 | fprintf_unfiltered (tmp_error_stream, | |
1221 | "Temporarily disabling shared library breakpoints:\n"); | |
1222 | } | |
1223 | *disabled_breaks = 1; | |
1224 | fprintf_unfiltered (tmp_error_stream, | |
1225 | "breakpoint #%d\n", bpt->owner->number); | |
1226 | } | |
1227 | else | |
879bfdc2 | 1228 | { |
879bfdc2 DJ |
1229 | if (bpt->loc_type == bp_loc_hardware_breakpoint) |
1230 | { | |
1231 | *hw_breakpoint_error = 1; | |
1232 | fprintf_unfiltered (tmp_error_stream, | |
1233 | "Cannot insert hardware breakpoint %d.\n", | |
1234 | bpt->owner->number); | |
1235 | } | |
1236 | else | |
1237 | { | |
1238 | fprintf_unfiltered (tmp_error_stream, | |
1239 | "Cannot insert breakpoint %d.\n", | |
1240 | bpt->owner->number); | |
1241 | fprintf_filtered (tmp_error_stream, | |
1242 | "Error accessing memory address "); | |
ed49a04f | 1243 | fputs_filtered (paddress (bpt->address), tmp_error_stream); |
879bfdc2 DJ |
1244 | fprintf_filtered (tmp_error_stream, ": %s.\n", |
1245 | safe_strerror (val)); | |
1246 | } | |
1247 | ||
1248 | } | |
1249 | } | |
1250 | else | |
1251 | bpt->inserted = 1; | |
1252 | ||
1253 | return val; | |
1254 | } | |
1255 | ||
1256 | else if (bpt->loc_type == bp_loc_hardware_watchpoint | |
1257 | /* NOTE drow/2003-09-08: This state only exists for removing | |
1258 | watchpoints. It's not clear that it's necessary... */ | |
1259 | && bpt->owner->disposition != disp_del_at_next_stop) | |
1260 | { | |
a5606eee VP |
1261 | val = target_insert_watchpoint (bpt->address, |
1262 | bpt->length, | |
1263 | bpt->watchpoint_type); | |
1264 | bpt->inserted = (val != -1); | |
879bfdc2 DJ |
1265 | } |
1266 | ||
fe798b75 | 1267 | else if (bpt->owner->type == bp_catchpoint) |
879bfdc2 | 1268 | { |
71fff37b AC |
1269 | struct gdb_exception e = catch_exception (uiout, insert_catchpoint, |
1270 | bpt->owner, RETURN_MASK_ERROR); | |
9cbc821d AC |
1271 | exception_fprintf (gdb_stderr, e, "warning: inserting catchpoint %d: ", |
1272 | bpt->owner->number); | |
1273 | if (e.reason < 0) | |
879bfdc2 DJ |
1274 | bpt->owner->enable_state = bp_disabled; |
1275 | else | |
1276 | bpt->inserted = 1; | |
1640b821 DJ |
1277 | |
1278 | /* We've already printed an error message if there was a problem | |
1279 | inserting this catchpoint, and we've disabled the catchpoint, | |
1280 | so just return success. */ | |
1281 | return 0; | |
879bfdc2 DJ |
1282 | } |
1283 | ||
1284 | return 0; | |
1285 | } | |
1286 | ||
74960c60 VP |
1287 | /* Make sure all breakpoints are inserted in inferior. |
1288 | Throws exception on any error. | |
1289 | A breakpoint that is already inserted won't be inserted | |
1290 | again, so calling this function twice is safe. */ | |
1291 | void | |
1292 | insert_breakpoints (void) | |
1293 | { | |
1294 | struct breakpoint *bpt; | |
1295 | ||
1296 | ALL_BREAKPOINTS (bpt) | |
1297 | if (is_hardware_watchpoint (bpt)) | |
1298 | update_watchpoint (bpt, 0 /* don't reparse. */); | |
1299 | ||
b60e7edf | 1300 | update_global_location_list (1); |
74960c60 | 1301 | |
c35b1492 PA |
1302 | /* update_global_location_list does not insert breakpoints when |
1303 | always_inserted_mode is not enabled. Explicitly insert them | |
1304 | now. */ | |
1305 | if (!breakpoints_always_inserted_mode ()) | |
74960c60 VP |
1306 | insert_breakpoint_locations (); |
1307 | } | |
1308 | ||
c906108c SS |
1309 | /* insert_breakpoints is used when starting or continuing the program. |
1310 | remove_breakpoints is used when the program stops. | |
1311 | Both return zero if successful, | |
1312 | or an `errno' value if could not write the inferior. */ | |
1313 | ||
74960c60 VP |
1314 | static void |
1315 | insert_breakpoint_locations (void) | |
c906108c | 1316 | { |
a5606eee | 1317 | struct breakpoint *bpt; |
879bfdc2 | 1318 | struct bp_location *b, *temp; |
e236ba44 | 1319 | int error = 0; |
c906108c SS |
1320 | int val = 0; |
1321 | int disabled_breaks = 0; | |
81d0cc19 | 1322 | int hw_breakpoint_error = 0; |
c906108c | 1323 | |
81d0cc19 | 1324 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 1325 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 1326 | |
81d0cc19 GS |
1327 | /* Explicitly mark the warning -- this will only be printed if |
1328 | there was an error. */ | |
1329 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
a5606eee | 1330 | |
879bfdc2 DJ |
1331 | ALL_BP_LOCATIONS_SAFE (b, temp) |
1332 | { | |
74960c60 | 1333 | if (!should_be_inserted (b) || b->inserted) |
879bfdc2 DJ |
1334 | continue; |
1335 | ||
f365de73 AS |
1336 | /* There is no point inserting thread-specific breakpoints if the |
1337 | thread no longer exists. */ | |
1338 | if (b->owner->thread != -1 | |
1339 | && !valid_thread_id (b->owner->thread)) | |
1340 | continue; | |
1341 | ||
879bfdc2 | 1342 | val = insert_bp_location (b, tmp_error_stream, |
fa3a767f | 1343 | &disabled_breaks, |
879bfdc2 DJ |
1344 | &hw_breakpoint_error); |
1345 | if (val) | |
e236ba44 | 1346 | error = val; |
879bfdc2 | 1347 | } |
c906108c | 1348 | |
a5606eee VP |
1349 | /* If we failed to insert all locations of a watchpoint, |
1350 | remove them, as half-inserted watchpoint is of limited use. */ | |
1351 | ALL_BREAKPOINTS (bpt) | |
1352 | { | |
1353 | int some_failed = 0; | |
1354 | struct bp_location *loc; | |
1355 | ||
1356 | if (!is_hardware_watchpoint (bpt)) | |
1357 | continue; | |
1358 | ||
d6b74ac4 | 1359 | if (!breakpoint_enabled (bpt)) |
a5606eee | 1360 | continue; |
74960c60 VP |
1361 | |
1362 | if (bpt->disposition == disp_del_at_next_stop) | |
1363 | continue; | |
a5606eee VP |
1364 | |
1365 | for (loc = bpt->loc; loc; loc = loc->next) | |
1366 | if (!loc->inserted) | |
1367 | { | |
1368 | some_failed = 1; | |
1369 | break; | |
1370 | } | |
1371 | if (some_failed) | |
1372 | { | |
1373 | for (loc = bpt->loc; loc; loc = loc->next) | |
1374 | if (loc->inserted) | |
1375 | remove_breakpoint (loc, mark_uninserted); | |
1376 | ||
1377 | hw_breakpoint_error = 1; | |
1378 | fprintf_unfiltered (tmp_error_stream, | |
1379 | "Could not insert hardware watchpoint %d.\n", | |
1380 | bpt->number); | |
1381 | error = -1; | |
1382 | } | |
1383 | } | |
1384 | ||
e236ba44 | 1385 | if (error) |
81d0cc19 GS |
1386 | { |
1387 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
1388 | message about possibly exhausted resources. */ | |
879bfdc2 | 1389 | if (hw_breakpoint_error) |
81d0cc19 | 1390 | { |
c6510018 MS |
1391 | fprintf_unfiltered (tmp_error_stream, |
1392 | "Could not insert hardware breakpoints:\n\ | |
1393 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 1394 | } |
81d0cc19 GS |
1395 | target_terminal_ours_for_output (); |
1396 | error_stream (tmp_error_stream); | |
1397 | } | |
f7545552 TT |
1398 | |
1399 | do_cleanups (cleanups); | |
c906108c SS |
1400 | } |
1401 | ||
c906108c | 1402 | int |
fba45db2 | 1403 | remove_breakpoints (void) |
c906108c | 1404 | { |
0bde7532 | 1405 | struct bp_location *b; |
c906108c SS |
1406 | int val; |
1407 | ||
0bde7532 | 1408 | ALL_BP_LOCATIONS (b) |
c5aa993b | 1409 | { |
0bde7532 | 1410 | if (b->inserted) |
c5aa993b JM |
1411 | { |
1412 | val = remove_breakpoint (b, mark_uninserted); | |
1413 | if (val != 0) | |
1414 | return val; | |
1415 | } | |
1416 | } | |
c906108c SS |
1417 | return 0; |
1418 | } | |
1419 | ||
692590c1 | 1420 | int |
80ce1ecb | 1421 | remove_hw_watchpoints (void) |
692590c1 | 1422 | { |
0bde7532 | 1423 | struct bp_location *b; |
692590c1 MS |
1424 | int val; |
1425 | ||
0bde7532 | 1426 | ALL_BP_LOCATIONS (b) |
692590c1 | 1427 | { |
0bde7532 | 1428 | if (b->inserted && b->loc_type == bp_loc_hardware_watchpoint) |
692590c1 MS |
1429 | { |
1430 | val = remove_breakpoint (b, mark_uninserted); | |
1431 | if (val != 0) | |
1432 | return val; | |
1433 | } | |
1434 | } | |
1435 | return 0; | |
1436 | } | |
1437 | ||
c906108c | 1438 | int |
fba45db2 | 1439 | reattach_breakpoints (int pid) |
c906108c | 1440 | { |
0bde7532 | 1441 | struct bp_location *b; |
c906108c | 1442 | int val; |
ce696e05 | 1443 | struct cleanup *old_chain = save_inferior_ptid (); |
a4954f26 | 1444 | struct ui_file *tmp_error_stream = mem_fileopen (); |
fa3a767f | 1445 | int dummy1 = 0, dummy2 = 0; |
a4954f26 DJ |
1446 | |
1447 | make_cleanup_ui_file_delete (tmp_error_stream); | |
c906108c | 1448 | |
ce696e05 | 1449 | inferior_ptid = pid_to_ptid (pid); |
0bde7532 | 1450 | ALL_BP_LOCATIONS (b) |
c5aa993b | 1451 | { |
0bde7532 | 1452 | if (b->inserted) |
c5aa993b | 1453 | { |
a4954f26 DJ |
1454 | b->inserted = 0; |
1455 | val = insert_bp_location (b, tmp_error_stream, | |
fa3a767f | 1456 | &dummy1, &dummy2); |
c5aa993b JM |
1457 | if (val != 0) |
1458 | { | |
ce696e05 | 1459 | do_cleanups (old_chain); |
c5aa993b JM |
1460 | return val; |
1461 | } | |
1462 | } | |
1463 | } | |
ce696e05 | 1464 | do_cleanups (old_chain); |
c906108c SS |
1465 | return 0; |
1466 | } | |
1467 | ||
e58b0e63 PA |
1468 | static int internal_breakpoint_number = -1; |
1469 | ||
e62c965a | 1470 | static struct breakpoint * |
a6d9a66e UW |
1471 | create_internal_breakpoint (struct gdbarch *gdbarch, |
1472 | CORE_ADDR address, enum bptype type) | |
e62c965a | 1473 | { |
e62c965a PP |
1474 | struct symtab_and_line sal; |
1475 | struct breakpoint *b; | |
1476 | ||
1477 | init_sal (&sal); /* initialize to zeroes */ | |
1478 | ||
1479 | sal.pc = address; | |
1480 | sal.section = find_pc_overlay (sal.pc); | |
1481 | ||
a6d9a66e | 1482 | b = set_raw_breakpoint (gdbarch, sal, type); |
e62c965a PP |
1483 | b->number = internal_breakpoint_number--; |
1484 | b->disposition = disp_donttouch; | |
1485 | ||
1486 | return b; | |
1487 | } | |
1488 | ||
1489 | static void | |
69de3c6a | 1490 | create_overlay_event_breakpoint (char *func_name) |
e62c965a | 1491 | { |
69de3c6a | 1492 | struct objfile *objfile; |
e62c965a | 1493 | |
69de3c6a PP |
1494 | ALL_OBJFILES (objfile) |
1495 | { | |
1496 | struct breakpoint *b; | |
1497 | struct minimal_symbol *m; | |
1498 | ||
1499 | m = lookup_minimal_symbol_text (func_name, objfile); | |
1500 | if (m == NULL) | |
1501 | continue; | |
e62c965a | 1502 | |
a6d9a66e UW |
1503 | b = create_internal_breakpoint (get_objfile_arch (objfile), |
1504 | SYMBOL_VALUE_ADDRESS (m), | |
69de3c6a PP |
1505 | bp_overlay_event); |
1506 | b->addr_string = xstrdup (func_name); | |
e62c965a | 1507 | |
69de3c6a PP |
1508 | if (overlay_debugging == ovly_auto) |
1509 | { | |
1510 | b->enable_state = bp_enabled; | |
1511 | overlay_events_enabled = 1; | |
1512 | } | |
1513 | else | |
1514 | { | |
1515 | b->enable_state = bp_disabled; | |
1516 | overlay_events_enabled = 0; | |
1517 | } | |
e62c965a PP |
1518 | } |
1519 | update_global_location_list (1); | |
1520 | } | |
1521 | ||
0fd8e87f UW |
1522 | static void |
1523 | create_longjmp_master_breakpoint (char *func_name) | |
1524 | { | |
1525 | struct objfile *objfile; | |
1526 | ||
1527 | ALL_OBJFILES (objfile) | |
1528 | { | |
1529 | struct breakpoint *b; | |
1530 | struct minimal_symbol *m; | |
1531 | ||
1532 | if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile))) | |
1533 | continue; | |
1534 | ||
1535 | m = lookup_minimal_symbol_text (func_name, objfile); | |
1536 | if (m == NULL) | |
1537 | continue; | |
1538 | ||
a6d9a66e UW |
1539 | b = create_internal_breakpoint (get_objfile_arch (objfile), |
1540 | SYMBOL_VALUE_ADDRESS (m), | |
0fd8e87f UW |
1541 | bp_longjmp_master); |
1542 | b->addr_string = xstrdup (func_name); | |
1543 | b->enable_state = bp_disabled; | |
1544 | } | |
1545 | update_global_location_list (1); | |
1546 | } | |
1547 | ||
c906108c | 1548 | void |
fba45db2 | 1549 | update_breakpoints_after_exec (void) |
c906108c | 1550 | { |
c5aa993b JM |
1551 | struct breakpoint *b; |
1552 | struct breakpoint *temp; | |
25b22b0a | 1553 | struct bp_location *bploc; |
c906108c | 1554 | |
25b22b0a PA |
1555 | /* We're about to delete breakpoints from GDB's lists. If the |
1556 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
1557 | writing the breakpoints' "shadow contents" back into memory. The | |
1558 | "shadow contents" are NOT valid after an exec, so GDB should not | |
1559 | do that. Instead, the target is responsible from marking | |
1560 | breakpoints out as soon as it detects an exec. We don't do that | |
1561 | here instead, because there may be other attempts to delete | |
1562 | breakpoints after detecting an exec and before reaching here. */ | |
1563 | ALL_BP_LOCATIONS (bploc) | |
1564 | gdb_assert (!bploc->inserted); | |
c906108c SS |
1565 | |
1566 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b JM |
1567 | { |
1568 | /* Solib breakpoints must be explicitly reset after an exec(). */ | |
1569 | if (b->type == bp_shlib_event) | |
1570 | { | |
1571 | delete_breakpoint (b); | |
1572 | continue; | |
1573 | } | |
c906108c | 1574 | |
1900040c | 1575 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
1576 | as must overlay event and longjmp master breakpoints. */ |
1577 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
1578 | || b->type == bp_longjmp_master) | |
c4093a6a JM |
1579 | { |
1580 | delete_breakpoint (b); | |
1581 | continue; | |
1582 | } | |
1583 | ||
c5aa993b JM |
1584 | /* Step-resume breakpoints are meaningless after an exec(). */ |
1585 | if (b->type == bp_step_resume) | |
1586 | { | |
1587 | delete_breakpoint (b); | |
1588 | continue; | |
1589 | } | |
1590 | ||
611c83ae PA |
1591 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
1592 | after an exec. */ | |
1593 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume) | |
1594 | { | |
1595 | delete_breakpoint (b); | |
1596 | continue; | |
1597 | } | |
1598 | ||
ce78b96d JB |
1599 | if (b->type == bp_catchpoint) |
1600 | { | |
1601 | /* For now, none of the bp_catchpoint breakpoints need to | |
1602 | do anything at this point. In the future, if some of | |
1603 | the catchpoints need to something, we will need to add | |
1604 | a new method, and call this method from here. */ | |
1605 | continue; | |
1606 | } | |
1607 | ||
c5aa993b JM |
1608 | /* bp_finish is a special case. The only way we ought to be able |
1609 | to see one of these when an exec() has happened, is if the user | |
1610 | caught a vfork, and then said "finish". Ordinarily a finish just | |
1611 | carries them to the call-site of the current callee, by setting | |
1612 | a temporary bp there and resuming. But in this case, the finish | |
1613 | will carry them entirely through the vfork & exec. | |
1614 | ||
1615 | We don't want to allow a bp_finish to remain inserted now. But | |
1616 | we can't safely delete it, 'cause finish_command has a handle to | |
1617 | the bp on a bpstat, and will later want to delete it. There's a | |
1618 | chance (and I've seen it happen) that if we delete the bp_finish | |
1619 | here, that its storage will get reused by the time finish_command | |
1620 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
1621 | We really must allow finish_command to delete a bp_finish. | |
1622 | ||
53a5351d JM |
1623 | In the absense of a general solution for the "how do we know |
1624 | it's safe to delete something others may have handles to?" | |
1625 | problem, what we'll do here is just uninsert the bp_finish, and | |
1626 | let finish_command delete it. | |
1627 | ||
1628 | (We know the bp_finish is "doomed" in the sense that it's | |
1629 | momentary, and will be deleted as soon as finish_command sees | |
1630 | the inferior stopped. So it doesn't matter that the bp's | |
1631 | address is probably bogus in the new a.out, unlike e.g., the | |
1632 | solib breakpoints.) */ | |
c5aa993b | 1633 | |
c5aa993b JM |
1634 | if (b->type == bp_finish) |
1635 | { | |
1636 | continue; | |
1637 | } | |
1638 | ||
1639 | /* Without a symbolic address, we have little hope of the | |
1640 | pre-exec() address meaning the same thing in the post-exec() | |
1641 | a.out. */ | |
1642 | if (b->addr_string == NULL) | |
1643 | { | |
1644 | delete_breakpoint (b); | |
1645 | continue; | |
1646 | } | |
c5aa993b | 1647 | } |
1900040c | 1648 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
69de3c6a | 1649 | create_overlay_event_breakpoint ("_ovly_debug_event"); |
0fd8e87f UW |
1650 | create_longjmp_master_breakpoint ("longjmp"); |
1651 | create_longjmp_master_breakpoint ("_longjmp"); | |
1652 | create_longjmp_master_breakpoint ("siglongjmp"); | |
1653 | create_longjmp_master_breakpoint ("_siglongjmp"); | |
c906108c SS |
1654 | } |
1655 | ||
1656 | int | |
fba45db2 | 1657 | detach_breakpoints (int pid) |
c906108c | 1658 | { |
0bde7532 | 1659 | struct bp_location *b; |
c906108c | 1660 | int val; |
ce696e05 | 1661 | struct cleanup *old_chain = save_inferior_ptid (); |
c5aa993b | 1662 | |
39f77062 | 1663 | if (pid == PIDGET (inferior_ptid)) |
8a3fe4f8 | 1664 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 1665 | |
ce696e05 KB |
1666 | /* Set inferior_ptid; remove_breakpoint uses this global. */ |
1667 | inferior_ptid = pid_to_ptid (pid); | |
0bde7532 | 1668 | ALL_BP_LOCATIONS (b) |
c5aa993b | 1669 | { |
0bde7532 | 1670 | if (b->inserted) |
c5aa993b JM |
1671 | { |
1672 | val = remove_breakpoint (b, mark_inserted); | |
1673 | if (val != 0) | |
1674 | { | |
ce696e05 | 1675 | do_cleanups (old_chain); |
c5aa993b JM |
1676 | return val; |
1677 | } | |
1678 | } | |
1679 | } | |
ce696e05 | 1680 | do_cleanups (old_chain); |
c906108c SS |
1681 | return 0; |
1682 | } | |
1683 | ||
1684 | static int | |
0bde7532 | 1685 | remove_breakpoint (struct bp_location *b, insertion_state_t is) |
c906108c SS |
1686 | { |
1687 | int val; | |
c5aa993b | 1688 | |
0bde7532 | 1689 | if (b->owner->enable_state == bp_permanent) |
c2c6d25f JM |
1690 | /* Permanent breakpoints cannot be inserted or removed. */ |
1691 | return 0; | |
1692 | ||
74960c60 VP |
1693 | /* The type of none suggests that owner is actually deleted. |
1694 | This should not ever happen. */ | |
1695 | gdb_assert (b->owner->type != bp_none); | |
0bde7532 DJ |
1696 | |
1697 | if (b->loc_type == bp_loc_software_breakpoint | |
1698 | || b->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 1699 | { |
c02f5703 MS |
1700 | /* "Normal" instruction breakpoint: either the standard |
1701 | trap-instruction bp (bp_breakpoint), or a | |
1702 | bp_hardware_breakpoint. */ | |
1703 | ||
1704 | /* First check to see if we have to handle an overlay. */ | |
1705 | if (overlay_debugging == ovly_off | |
0bde7532 DJ |
1706 | || b->section == NULL |
1707 | || !(section_is_overlay (b->section))) | |
c02f5703 MS |
1708 | { |
1709 | /* No overlay handling: just remove the breakpoint. */ | |
1710 | ||
0bde7532 | 1711 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e | 1712 | val = target_remove_hw_breakpoint (b->gdbarch, &b->target_info); |
c02f5703 | 1713 | else |
a6d9a66e | 1714 | val = target_remove_breakpoint (b->gdbarch, &b->target_info); |
c02f5703 | 1715 | } |
c906108c SS |
1716 | else |
1717 | { | |
c02f5703 MS |
1718 | /* This breakpoint is in an overlay section. |
1719 | Did we set a breakpoint at the LMA? */ | |
1720 | if (!overlay_events_enabled) | |
1721 | { | |
1722 | /* Yes -- overlay event support is not active, so we | |
1723 | should have set a breakpoint at the LMA. Remove it. | |
1724 | */ | |
c02f5703 MS |
1725 | /* Ignore any failures: if the LMA is in ROM, we will |
1726 | have already warned when we failed to insert it. */ | |
0bde7532 | 1727 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e UW |
1728 | target_remove_hw_breakpoint (b->gdbarch, |
1729 | &b->overlay_target_info); | |
c02f5703 | 1730 | else |
a6d9a66e UW |
1731 | target_remove_breakpoint (b->gdbarch, |
1732 | &b->overlay_target_info); | |
c02f5703 MS |
1733 | } |
1734 | /* Did we set a breakpoint at the VMA? | |
1735 | If so, we will have marked the breakpoint 'inserted'. */ | |
0bde7532 | 1736 | if (b->inserted) |
c906108c | 1737 | { |
c02f5703 MS |
1738 | /* Yes -- remove it. Previously we did not bother to |
1739 | remove the breakpoint if the section had been | |
1740 | unmapped, but let's not rely on that being safe. We | |
1741 | don't know what the overlay manager might do. */ | |
0bde7532 | 1742 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e UW |
1743 | val = target_remove_hw_breakpoint (b->gdbarch, |
1744 | &b->target_info); | |
aa67235e UW |
1745 | |
1746 | /* However, we should remove *software* breakpoints only | |
1747 | if the section is still mapped, or else we overwrite | |
1748 | wrong code with the saved shadow contents. */ | |
1749 | else if (section_is_mapped (b->section)) | |
a6d9a66e UW |
1750 | val = target_remove_breakpoint (b->gdbarch, |
1751 | &b->target_info); | |
aa67235e UW |
1752 | else |
1753 | val = 0; | |
c906108c | 1754 | } |
c02f5703 MS |
1755 | else |
1756 | { | |
1757 | /* No -- not inserted, so no need to remove. No error. */ | |
1758 | val = 0; | |
1759 | } | |
c906108c | 1760 | } |
879d1e6b UW |
1761 | |
1762 | /* In some cases, we might not be able to remove a breakpoint | |
1763 | in a shared library that has already been removed, but we | |
1764 | have not yet processed the shlib unload event. */ | |
f5c9a895 | 1765 | if (val && solib_name_from_address (b->address)) |
879d1e6b UW |
1766 | val = 0; |
1767 | ||
c906108c SS |
1768 | if (val) |
1769 | return val; | |
0bde7532 | 1770 | b->inserted = (is == mark_inserted); |
c906108c | 1771 | } |
a5606eee | 1772 | else if (b->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 1773 | { |
278cd55f AC |
1774 | struct value *v; |
1775 | struct value *n; | |
c5aa993b | 1776 | |
0bde7532 | 1777 | b->inserted = (is == mark_inserted); |
a5606eee VP |
1778 | val = target_remove_watchpoint (b->address, b->length, |
1779 | b->watchpoint_type); | |
2e70b7b9 | 1780 | |
c906108c | 1781 | /* Failure to remove any of the hardware watchpoints comes here. */ |
0bde7532 | 1782 | if ((is == mark_uninserted) && (b->inserted)) |
8a3fe4f8 | 1783 | warning (_("Could not remove hardware watchpoint %d."), |
0bde7532 | 1784 | b->owner->number); |
c906108c | 1785 | } |
ce78b96d JB |
1786 | else if (b->owner->type == bp_catchpoint |
1787 | && breakpoint_enabled (b->owner) | |
1788 | && !b->duplicate) | |
1789 | { | |
1790 | gdb_assert (b->owner->ops != NULL && b->owner->ops->remove != NULL); | |
1791 | ||
1792 | val = b->owner->ops->remove (b->owner); | |
1793 | if (val) | |
1794 | return val; | |
1795 | b->inserted = (is == mark_inserted); | |
1796 | } | |
c906108c SS |
1797 | |
1798 | return 0; | |
1799 | } | |
1800 | ||
1801 | /* Clear the "inserted" flag in all breakpoints. */ | |
1802 | ||
25b22b0a | 1803 | void |
fba45db2 | 1804 | mark_breakpoints_out (void) |
c906108c | 1805 | { |
075f6582 | 1806 | struct bp_location *bpt; |
c906108c | 1807 | |
075f6582 DJ |
1808 | ALL_BP_LOCATIONS (bpt) |
1809 | bpt->inserted = 0; | |
c906108c SS |
1810 | } |
1811 | ||
53a5351d JM |
1812 | /* Clear the "inserted" flag in all breakpoints and delete any |
1813 | breakpoints which should go away between runs of the program. | |
c906108c SS |
1814 | |
1815 | Plus other such housekeeping that has to be done for breakpoints | |
1816 | between runs. | |
1817 | ||
53a5351d JM |
1818 | Note: this function gets called at the end of a run (by |
1819 | generic_mourn_inferior) and when a run begins (by | |
1820 | init_wait_for_inferior). */ | |
c906108c SS |
1821 | |
1822 | ||
1823 | ||
1824 | void | |
fba45db2 | 1825 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 1826 | { |
52f0bd74 | 1827 | struct breakpoint *b, *temp; |
075f6582 | 1828 | struct bp_location *bpt; |
1c5cfe86 | 1829 | int ix; |
c906108c | 1830 | |
50c71eaf PA |
1831 | /* If breakpoint locations are shared across processes, then there's |
1832 | nothing to do. */ | |
2567c7d9 | 1833 | if (gdbarch_has_global_breakpoints (target_gdbarch)) |
50c71eaf PA |
1834 | return; |
1835 | ||
075f6582 | 1836 | ALL_BP_LOCATIONS (bpt) |
514f746b AR |
1837 | if (bpt->owner->enable_state != bp_permanent) |
1838 | bpt->inserted = 0; | |
075f6582 | 1839 | |
c906108c | 1840 | ALL_BREAKPOINTS_SAFE (b, temp) |
c5aa993b | 1841 | { |
c5aa993b JM |
1842 | switch (b->type) |
1843 | { | |
1844 | case bp_call_dummy: | |
1845 | case bp_watchpoint_scope: | |
c906108c | 1846 | |
c5aa993b JM |
1847 | /* If the call dummy breakpoint is at the entry point it will |
1848 | cause problems when the inferior is rerun, so we better | |
1849 | get rid of it. | |
c906108c | 1850 | |
c5aa993b JM |
1851 | Also get rid of scope breakpoints. */ |
1852 | delete_breakpoint (b); | |
1853 | break; | |
c906108c | 1854 | |
c5aa993b JM |
1855 | case bp_watchpoint: |
1856 | case bp_hardware_watchpoint: | |
1857 | case bp_read_watchpoint: | |
1858 | case bp_access_watchpoint: | |
c906108c | 1859 | |
c5aa993b JM |
1860 | /* Likewise for watchpoints on local expressions. */ |
1861 | if (b->exp_valid_block != NULL) | |
1862 | delete_breakpoint (b); | |
967af18d | 1863 | else if (context == inf_starting) |
c860120c PM |
1864 | { |
1865 | /* Reset val field to force reread of starting value | |
1866 | in insert_breakpoints. */ | |
1867 | if (b->val) | |
1868 | value_free (b->val); | |
1869 | b->val = NULL; | |
fa4727a6 | 1870 | b->val_valid = 0; |
c860120c | 1871 | } |
c5aa993b JM |
1872 | break; |
1873 | default: | |
c5aa993b JM |
1874 | break; |
1875 | } | |
1876 | } | |
1c5cfe86 PA |
1877 | |
1878 | /* Get rid of the moribund locations. */ | |
1879 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bpt); ++ix) | |
1880 | free_bp_location (bpt); | |
1881 | VEC_free (bp_location_p, moribund_locations); | |
c906108c SS |
1882 | } |
1883 | ||
c2c6d25f JM |
1884 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
1885 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
1886 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
1887 | permanent breakpoint. | |
1888 | - When continuing from a location with an ordinary breakpoint, we | |
1889 | actually single step once before calling insert_breakpoints. | |
1890 | - When continuing from a localion with a permanent breakpoint, we | |
1891 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by | |
1892 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 1893 | |
c2c6d25f | 1894 | enum breakpoint_here |
fba45db2 | 1895 | breakpoint_here_p (CORE_ADDR pc) |
c906108c | 1896 | { |
89f9893c | 1897 | const struct bp_location *bpt; |
c2c6d25f | 1898 | int any_breakpoint_here = 0; |
c906108c | 1899 | |
075f6582 DJ |
1900 | ALL_BP_LOCATIONS (bpt) |
1901 | { | |
1902 | if (bpt->loc_type != bp_loc_software_breakpoint | |
1903 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
1904 | continue; | |
1905 | ||
468d015d | 1906 | if ((breakpoint_enabled (bpt->owner) |
075f6582 DJ |
1907 | || bpt->owner->enable_state == bp_permanent) |
1908 | && bpt->address == pc) /* bp is enabled and matches pc */ | |
1909 | { | |
1910 | if (overlay_debugging | |
1911 | && section_is_overlay (bpt->section) | |
1912 | && !section_is_mapped (bpt->section)) | |
1913 | continue; /* unmapped overlay -- can't be a match */ | |
1914 | else if (bpt->owner->enable_state == bp_permanent) | |
1915 | return permanent_breakpoint_here; | |
1916 | else | |
1917 | any_breakpoint_here = 1; | |
1918 | } | |
1919 | } | |
c906108c | 1920 | |
c2c6d25f | 1921 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
1922 | } |
1923 | ||
1c5cfe86 PA |
1924 | /* Return true if there's a moribund breakpoint at PC. */ |
1925 | ||
1926 | int | |
1927 | moribund_breakpoint_here_p (CORE_ADDR pc) | |
1928 | { | |
1929 | struct bp_location *loc; | |
1930 | int ix; | |
1931 | ||
1932 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
1933 | if (loc->address == pc) | |
1934 | return 1; | |
1935 | ||
1936 | return 0; | |
1937 | } | |
c2c6d25f | 1938 | |
c36b740a VP |
1939 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
1940 | inserted using regular breakpoint_chain/bp_location_chain mechanism. | |
1941 | This does not check for single-step breakpoints, which are | |
1942 | inserted and removed using direct target manipulation. */ | |
c906108c SS |
1943 | |
1944 | int | |
c36b740a | 1945 | regular_breakpoint_inserted_here_p (CORE_ADDR pc) |
c906108c | 1946 | { |
89f9893c | 1947 | const struct bp_location *bpt; |
c906108c | 1948 | |
075f6582 | 1949 | ALL_BP_LOCATIONS (bpt) |
c5aa993b | 1950 | { |
075f6582 DJ |
1951 | if (bpt->loc_type != bp_loc_software_breakpoint |
1952 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
1953 | continue; | |
1954 | ||
1955 | if (bpt->inserted | |
1956 | && bpt->address == pc) /* bp is inserted and matches pc */ | |
1957 | { | |
1958 | if (overlay_debugging | |
1959 | && section_is_overlay (bpt->section) | |
1960 | && !section_is_mapped (bpt->section)) | |
1961 | continue; /* unmapped overlay -- can't be a match */ | |
1962 | else | |
1963 | return 1; | |
1964 | } | |
c5aa993b | 1965 | } |
c36b740a VP |
1966 | return 0; |
1967 | } | |
1968 | ||
1969 | /* Returns non-zero iff there's either regular breakpoint | |
1970 | or a single step breakpoint inserted at PC. */ | |
1971 | ||
1972 | int | |
1973 | breakpoint_inserted_here_p (CORE_ADDR pc) | |
1974 | { | |
1975 | if (regular_breakpoint_inserted_here_p (pc)) | |
1976 | return 1; | |
c906108c | 1977 | |
1aafd4da UW |
1978 | if (single_step_breakpoint_inserted_here_p (pc)) |
1979 | return 1; | |
1980 | ||
c906108c SS |
1981 | return 0; |
1982 | } | |
1983 | ||
4fa8626c DJ |
1984 | /* This function returns non-zero iff there is a software breakpoint |
1985 | inserted at PC. */ | |
1986 | ||
1987 | int | |
1988 | software_breakpoint_inserted_here_p (CORE_ADDR pc) | |
1989 | { | |
89f9893c | 1990 | const struct bp_location *bpt; |
4fa8626c DJ |
1991 | int any_breakpoint_here = 0; |
1992 | ||
1993 | ALL_BP_LOCATIONS (bpt) | |
1994 | { | |
1995 | if (bpt->loc_type != bp_loc_software_breakpoint) | |
1996 | continue; | |
1997 | ||
0d381245 | 1998 | if (bpt->inserted |
4fa8626c DJ |
1999 | && bpt->address == pc) /* bp is enabled and matches pc */ |
2000 | { | |
2001 | if (overlay_debugging | |
2002 | && section_is_overlay (bpt->section) | |
2003 | && !section_is_mapped (bpt->section)) | |
2004 | continue; /* unmapped overlay -- can't be a match */ | |
2005 | else | |
2006 | return 1; | |
2007 | } | |
2008 | } | |
2009 | ||
1aafd4da UW |
2010 | /* Also check for software single-step breakpoints. */ |
2011 | if (single_step_breakpoint_inserted_here_p (pc)) | |
2012 | return 1; | |
2013 | ||
4fa8626c DJ |
2014 | return 0; |
2015 | } | |
2016 | ||
075f6582 DJ |
2017 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
2018 | PC is valid for process/thread PTID. */ | |
c906108c SS |
2019 | |
2020 | int | |
39f77062 | 2021 | breakpoint_thread_match (CORE_ADDR pc, ptid_t ptid) |
c906108c | 2022 | { |
89f9893c | 2023 | const struct bp_location *bpt; |
4a306c9a | 2024 | /* The thread and task IDs associated to PTID, computed lazily. */ |
a6f1cd96 | 2025 | int thread = -1; |
4a306c9a | 2026 | int task = 0; |
a6f1cd96 | 2027 | |
075f6582 | 2028 | ALL_BP_LOCATIONS (bpt) |
c5aa993b | 2029 | { |
075f6582 DJ |
2030 | if (bpt->loc_type != bp_loc_software_breakpoint |
2031 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
2032 | continue; | |
2033 | ||
a6f1cd96 JB |
2034 | if (!breakpoint_enabled (bpt->owner) |
2035 | && bpt->owner->enable_state != bp_permanent) | |
2036 | continue; | |
2037 | ||
2038 | if (bpt->address != pc) | |
2039 | continue; | |
2040 | ||
2041 | if (bpt->owner->thread != -1) | |
075f6582 | 2042 | { |
a6f1cd96 JB |
2043 | /* This is a thread-specific breakpoint. Check that ptid |
2044 | matches that thread. If thread hasn't been computed yet, | |
2045 | it is now time to do so. */ | |
2046 | if (thread == -1) | |
2047 | thread = pid_to_thread_id (ptid); | |
2048 | if (bpt->owner->thread != thread) | |
2049 | continue; | |
075f6582 | 2050 | } |
a6f1cd96 | 2051 | |
4a306c9a JB |
2052 | if (bpt->owner->task != 0) |
2053 | { | |
2054 | /* This is a task-specific breakpoint. Check that ptid | |
2055 | matches that task. If task hasn't been computed yet, | |
2056 | it is now time to do so. */ | |
2057 | if (task == 0) | |
2058 | task = ada_get_task_number (ptid); | |
2059 | if (bpt->owner->task != task) | |
2060 | continue; | |
2061 | } | |
2062 | ||
a6f1cd96 JB |
2063 | if (overlay_debugging |
2064 | && section_is_overlay (bpt->section) | |
2065 | && !section_is_mapped (bpt->section)) | |
2066 | continue; /* unmapped overlay -- can't be a match */ | |
2067 | ||
2068 | return 1; | |
c5aa993b | 2069 | } |
c906108c SS |
2070 | |
2071 | return 0; | |
2072 | } | |
c906108c | 2073 | \f |
c5aa993b | 2074 | |
c906108c SS |
2075 | /* bpstat stuff. External routines' interfaces are documented |
2076 | in breakpoint.h. */ | |
2077 | ||
2078 | int | |
fba45db2 | 2079 | ep_is_catchpoint (struct breakpoint *ep) |
c906108c | 2080 | { |
533be4dd | 2081 | return (ep->type == bp_catchpoint); |
c906108c SS |
2082 | } |
2083 | ||
198757a8 VP |
2084 | void |
2085 | bpstat_free (bpstat bs) | |
2086 | { | |
2087 | if (bs->old_val != NULL) | |
2088 | value_free (bs->old_val); | |
2089 | free_command_lines (&bs->commands); | |
2090 | xfree (bs); | |
2091 | } | |
2092 | ||
c906108c SS |
2093 | /* Clear a bpstat so that it says we are not at any breakpoint. |
2094 | Also free any storage that is part of a bpstat. */ | |
2095 | ||
2096 | void | |
fba45db2 | 2097 | bpstat_clear (bpstat *bsp) |
c906108c SS |
2098 | { |
2099 | bpstat p; | |
2100 | bpstat q; | |
2101 | ||
2102 | if (bsp == 0) | |
2103 | return; | |
2104 | p = *bsp; | |
2105 | while (p != NULL) | |
2106 | { | |
2107 | q = p->next; | |
198757a8 | 2108 | bpstat_free (p); |
c906108c SS |
2109 | p = q; |
2110 | } | |
2111 | *bsp = NULL; | |
2112 | } | |
2113 | ||
2114 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
2115 | is part of the bpstat is copied as well. */ | |
2116 | ||
2117 | bpstat | |
fba45db2 | 2118 | bpstat_copy (bpstat bs) |
c906108c SS |
2119 | { |
2120 | bpstat p = NULL; | |
2121 | bpstat tmp; | |
2122 | bpstat retval = NULL; | |
2123 | ||
2124 | if (bs == NULL) | |
2125 | return bs; | |
2126 | ||
2127 | for (; bs != NULL; bs = bs->next) | |
2128 | { | |
2129 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
2130 | memcpy (tmp, bs, sizeof (*tmp)); | |
31cc81e9 DJ |
2131 | if (bs->commands != NULL) |
2132 | tmp->commands = copy_command_lines (bs->commands); | |
2133 | if (bs->old_val != NULL) | |
3c3185ac JK |
2134 | { |
2135 | tmp->old_val = value_copy (bs->old_val); | |
2136 | release_value (tmp->old_val); | |
2137 | } | |
31cc81e9 | 2138 | |
c906108c SS |
2139 | if (p == NULL) |
2140 | /* This is the first thing in the chain. */ | |
2141 | retval = tmp; | |
2142 | else | |
2143 | p->next = tmp; | |
2144 | p = tmp; | |
2145 | } | |
2146 | p->next = NULL; | |
2147 | return retval; | |
2148 | } | |
2149 | ||
2150 | /* Find the bpstat associated with this breakpoint */ | |
2151 | ||
2152 | bpstat | |
fba45db2 | 2153 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 2154 | { |
c5aa993b JM |
2155 | if (bsp == NULL) |
2156 | return NULL; | |
c906108c | 2157 | |
c5aa993b JM |
2158 | for (; bsp != NULL; bsp = bsp->next) |
2159 | { | |
4f8d1dc6 | 2160 | if (bsp->breakpoint_at && bsp->breakpoint_at->owner == breakpoint) |
c5aa993b JM |
2161 | return bsp; |
2162 | } | |
c906108c SS |
2163 | return NULL; |
2164 | } | |
2165 | ||
2166 | /* Find a step_resume breakpoint associated with this bpstat. | |
2167 | (If there are multiple step_resume bp's on the list, this function | |
2168 | will arbitrarily pick one.) | |
2169 | ||
2170 | It is an error to use this function if BPSTAT doesn't contain a | |
2171 | step_resume breakpoint. | |
2172 | ||
2173 | See wait_for_inferior's use of this function. */ | |
2174 | struct breakpoint * | |
fba45db2 | 2175 | bpstat_find_step_resume_breakpoint (bpstat bsp) |
c906108c | 2176 | { |
8601f500 MS |
2177 | int current_thread; |
2178 | ||
8a3fe4f8 | 2179 | gdb_assert (bsp != NULL); |
c906108c | 2180 | |
8601f500 MS |
2181 | current_thread = pid_to_thread_id (inferior_ptid); |
2182 | ||
c906108c SS |
2183 | for (; bsp != NULL; bsp = bsp->next) |
2184 | { | |
059fb39f PM |
2185 | if ((bsp->breakpoint_at != NULL) |
2186 | && (bsp->breakpoint_at->owner->type == bp_step_resume) | |
2187 | && (bsp->breakpoint_at->owner->thread == current_thread | |
2188 | || bsp->breakpoint_at->owner->thread == -1)) | |
4f8d1dc6 | 2189 | return bsp->breakpoint_at->owner; |
c906108c SS |
2190 | } |
2191 | ||
8a3fe4f8 | 2192 | internal_error (__FILE__, __LINE__, _("No step_resume breakpoint found.")); |
c906108c SS |
2193 | } |
2194 | ||
2195 | ||
8671a17b | 2196 | /* Put in *NUM the breakpoint number of the first breakpoint we are stopped |
c906108c SS |
2197 | at. *BSP upon return is a bpstat which points to the remaining |
2198 | breakpoints stopped at (but which is not guaranteed to be good for | |
2199 | anything but further calls to bpstat_num). | |
8671a17b PA |
2200 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
2201 | Return -1 if stopped at a breakpoint that has been deleted since | |
2202 | we set it. | |
2203 | Return 1 otherwise. */ | |
c906108c SS |
2204 | |
2205 | int | |
8671a17b | 2206 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
2207 | { |
2208 | struct breakpoint *b; | |
2209 | ||
2210 | if ((*bsp) == NULL) | |
2211 | return 0; /* No more breakpoint values */ | |
8671a17b | 2212 | |
4f8d1dc6 VP |
2213 | /* We assume we'll never have several bpstats that |
2214 | correspond to a single breakpoint -- otherwise, | |
2215 | this function might return the same number more | |
2216 | than once and this will look ugly. */ | |
2217 | b = (*bsp)->breakpoint_at ? (*bsp)->breakpoint_at->owner : NULL; | |
8671a17b PA |
2218 | *bsp = (*bsp)->next; |
2219 | if (b == NULL) | |
2220 | return -1; /* breakpoint that's been deleted since */ | |
2221 | ||
2222 | *num = b->number; /* We have its number */ | |
2223 | return 1; | |
c906108c SS |
2224 | } |
2225 | ||
2226 | /* Modify BS so that the actions will not be performed. */ | |
2227 | ||
2228 | void | |
fba45db2 | 2229 | bpstat_clear_actions (bpstat bs) |
c906108c SS |
2230 | { |
2231 | for (; bs != NULL; bs = bs->next) | |
2232 | { | |
c2b8ed2c | 2233 | free_command_lines (&bs->commands); |
c906108c SS |
2234 | if (bs->old_val != NULL) |
2235 | { | |
2236 | value_free (bs->old_val); | |
2237 | bs->old_val = NULL; | |
2238 | } | |
2239 | } | |
2240 | } | |
2241 | ||
f3b1572e PA |
2242 | /* Called when a command is about to proceed the inferior. */ |
2243 | ||
2244 | static void | |
2245 | breakpoint_about_to_proceed (void) | |
2246 | { | |
2247 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
2248 | { | |
2249 | struct thread_info *tp = inferior_thread (); | |
2250 | ||
2251 | /* Allow inferior function calls in breakpoint commands to not | |
2252 | interrupt the command list. When the call finishes | |
2253 | successfully, the inferior will be standing at the same | |
2254 | breakpoint as if nothing happened. */ | |
2255 | if (tp->in_infcall) | |
2256 | return; | |
2257 | } | |
2258 | ||
2259 | breakpoint_proceeded = 1; | |
2260 | } | |
2261 | ||
c906108c | 2262 | /* Stub for cleaning up our state if we error-out of a breakpoint command */ |
c906108c | 2263 | static void |
4efb68b1 | 2264 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
2265 | { |
2266 | executing_breakpoint_commands = 0; | |
2267 | } | |
2268 | ||
2269 | /* Execute all the commands associated with all the breakpoints at this | |
2270 | location. Any of these commands could cause the process to proceed | |
2271 | beyond this point, etc. We look out for such changes by checking | |
347bddb7 | 2272 | the global "breakpoint_proceeded" after each command. |
c906108c | 2273 | |
347bddb7 PA |
2274 | Returns true if a breakpoint command resumed the inferior. In that |
2275 | case, it is the caller's responsibility to recall it again with the | |
2276 | bpstat of the current thread. */ | |
2277 | ||
2278 | static int | |
2279 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
2280 | { |
2281 | bpstat bs; | |
2282 | struct cleanup *old_chain; | |
347bddb7 | 2283 | int again = 0; |
c906108c SS |
2284 | |
2285 | /* Avoid endless recursion if a `source' command is contained | |
2286 | in bs->commands. */ | |
2287 | if (executing_breakpoint_commands) | |
347bddb7 | 2288 | return 0; |
c906108c SS |
2289 | |
2290 | executing_breakpoint_commands = 1; | |
2291 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
2292 | ||
c906108c SS |
2293 | /* This pointer will iterate over the list of bpstat's. */ |
2294 | bs = *bsp; | |
2295 | ||
2296 | breakpoint_proceeded = 0; | |
2297 | for (; bs != NULL; bs = bs->next) | |
2298 | { | |
6c50ab1c JB |
2299 | struct command_line *cmd; |
2300 | struct cleanup *this_cmd_tree_chain; | |
2301 | ||
2302 | /* Take ownership of the BSP's command tree, if it has one. | |
2303 | ||
2304 | The command tree could legitimately contain commands like | |
2305 | 'step' and 'next', which call clear_proceed_status, which | |
2306 | frees stop_bpstat's command tree. To make sure this doesn't | |
2307 | free the tree we're executing out from under us, we need to | |
2308 | take ownership of the tree ourselves. Since a given bpstat's | |
2309 | commands are only executed once, we don't need to copy it; we | |
2310 | can clear the pointer in the bpstat, and make sure we free | |
2311 | the tree when we're done. */ | |
c906108c | 2312 | cmd = bs->commands; |
6c50ab1c JB |
2313 | bs->commands = 0; |
2314 | this_cmd_tree_chain = make_cleanup_free_command_lines (&cmd); | |
2315 | ||
c906108c SS |
2316 | while (cmd != NULL) |
2317 | { | |
2318 | execute_control_command (cmd); | |
2319 | ||
2320 | if (breakpoint_proceeded) | |
2321 | break; | |
2322 | else | |
2323 | cmd = cmd->next; | |
2324 | } | |
6c50ab1c JB |
2325 | |
2326 | /* We can free this command tree now. */ | |
2327 | do_cleanups (this_cmd_tree_chain); | |
2328 | ||
c906108c | 2329 | if (breakpoint_proceeded) |
32c1e744 VP |
2330 | { |
2331 | if (target_can_async_p ()) | |
347bddb7 PA |
2332 | /* If we are in async mode, then the target might be still |
2333 | running, not stopped at any breakpoint, so nothing for | |
2334 | us to do here -- just return to the event loop. */ | |
2335 | ; | |
32c1e744 VP |
2336 | else |
2337 | /* In sync mode, when execute_control_command returns | |
2338 | we're already standing on the next breakpoint. | |
347bddb7 PA |
2339 | Breakpoint commands for that stop were not run, since |
2340 | execute_command does not run breakpoint commands -- | |
2341 | only command_line_handler does, but that one is not | |
2342 | involved in execution of breakpoint commands. So, we | |
2343 | can now execute breakpoint commands. It should be | |
2344 | noted that making execute_command do bpstat actions is | |
2345 | not an option -- in this case we'll have recursive | |
2346 | invocation of bpstat for each breakpoint with a | |
2347 | command, and can easily blow up GDB stack. Instead, we | |
2348 | return true, which will trigger the caller to recall us | |
2349 | with the new stop_bpstat. */ | |
2350 | again = 1; | |
2351 | break; | |
32c1e744 | 2352 | } |
c906108c | 2353 | } |
c2b8ed2c | 2354 | do_cleanups (old_chain); |
347bddb7 PA |
2355 | return again; |
2356 | } | |
2357 | ||
2358 | void | |
2359 | bpstat_do_actions (void) | |
2360 | { | |
2361 | /* Do any commands attached to breakpoint we are stopped at. */ | |
2362 | while (!ptid_equal (inferior_ptid, null_ptid) | |
2363 | && target_has_execution | |
2364 | && !is_exited (inferior_ptid) | |
2365 | && !is_executing (inferior_ptid)) | |
2366 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
2367 | and only return when it is stopped at the next breakpoint, we | |
2368 | keep doing breakpoint actions until it returns false to | |
2369 | indicate the inferior was not resumed. */ | |
2370 | if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat)) | |
2371 | break; | |
c906108c SS |
2372 | } |
2373 | ||
fa4727a6 DJ |
2374 | /* Print out the (old or new) value associated with a watchpoint. */ |
2375 | ||
2376 | static void | |
2377 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
2378 | { | |
2379 | if (val == NULL) | |
2380 | fprintf_unfiltered (stream, _("<unreadable>")); | |
2381 | else | |
79a45b7d TT |
2382 | { |
2383 | struct value_print_options opts; | |
2384 | get_user_print_options (&opts); | |
2385 | value_print (val, stream, &opts); | |
2386 | } | |
fa4727a6 DJ |
2387 | } |
2388 | ||
e514a9d6 | 2389 | /* This is the normal print function for a bpstat. In the future, |
c906108c | 2390 | much of this logic could (should?) be moved to bpstat_stop_status, |
e514a9d6 JM |
2391 | by having it set different print_it values. |
2392 | ||
2393 | Current scheme: When we stop, bpstat_print() is called. It loops | |
2394 | through the bpstat list of things causing this stop, calling the | |
2395 | print_bp_stop_message function on each one. The behavior of the | |
2396 | print_bp_stop_message function depends on the print_it field of | |
2397 | bpstat. If such field so indicates, call this function here. | |
2398 | ||
2399 | Return values from this routine (ultimately used by bpstat_print() | |
2400 | and normal_stop() to decide what to do): | |
2401 | PRINT_NOTHING: Means we already printed all we needed to print, | |
2402 | don't print anything else. | |
2403 | PRINT_SRC_ONLY: Means we printed something, and we do *not* desire | |
2404 | that something to be followed by a location. | |
2405 | PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire | |
2406 | that something to be followed by a location. | |
2407 | PRINT_UNKNOWN: Means we printed nothing or we need to do some more | |
2408 | analysis. */ | |
c906108c | 2409 | |
917317f4 | 2410 | static enum print_stop_action |
fba45db2 | 2411 | print_it_typical (bpstat bs) |
c906108c | 2412 | { |
f7545552 | 2413 | struct cleanup *old_chain; |
4f8d1dc6 | 2414 | struct breakpoint *b; |
89f9893c | 2415 | const struct bp_location *bl; |
8b93c638 | 2416 | struct ui_stream *stb; |
f7545552 TT |
2417 | int bp_temp = 0; |
2418 | enum print_stop_action result; | |
2419 | ||
c906108c SS |
2420 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
2421 | which has since been deleted. */ | |
e514a9d6 | 2422 | if (bs->breakpoint_at == NULL) |
917317f4 | 2423 | return PRINT_UNKNOWN; |
0d381245 VP |
2424 | bl = bs->breakpoint_at; |
2425 | b = bl->owner; | |
c906108c | 2426 | |
f7545552 TT |
2427 | stb = ui_out_stream_new (uiout); |
2428 | old_chain = make_cleanup_ui_out_stream_delete (stb); | |
2429 | ||
4f8d1dc6 | 2430 | switch (b->type) |
c906108c | 2431 | { |
e514a9d6 JM |
2432 | case bp_breakpoint: |
2433 | case bp_hardware_breakpoint: | |
2cec12e5 | 2434 | bp_temp = bs->breakpoint_at->owner->disposition == disp_del; |
0d381245 VP |
2435 | if (bl->address != bl->requested_address) |
2436 | breakpoint_adjustment_warning (bl->requested_address, | |
2437 | bl->address, | |
4f8d1dc6 VP |
2438 | b->number, 1); |
2439 | annotate_breakpoint (b->number); | |
2cec12e5 AR |
2440 | if (bp_temp) |
2441 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
2442 | else | |
2443 | ui_out_text (uiout, "\nBreakpoint "); | |
9dc5e2a9 | 2444 | if (ui_out_is_mi_like_p (uiout)) |
2cec12e5 AR |
2445 | { |
2446 | ui_out_field_string (uiout, "reason", | |
2447 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
2448 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
2449 | } | |
4f8d1dc6 | 2450 | ui_out_field_int (uiout, "bkptno", b->number); |
8b93c638 | 2451 | ui_out_text (uiout, ", "); |
f7545552 | 2452 | result = PRINT_SRC_AND_LOC; |
e514a9d6 JM |
2453 | break; |
2454 | ||
2455 | case bp_shlib_event: | |
917317f4 JM |
2456 | /* Did we stop because the user set the stop_on_solib_events |
2457 | variable? (If so, we report this as a generic, "Stopped due | |
2458 | to shlib event" message.) */ | |
a3f17187 | 2459 | printf_filtered (_("Stopped due to shared library event\n")); |
f7545552 | 2460 | result = PRINT_NOTHING; |
e514a9d6 JM |
2461 | break; |
2462 | ||
c4093a6a JM |
2463 | case bp_thread_event: |
2464 | /* Not sure how we will get here. | |
2465 | GDB should not stop for these breakpoints. */ | |
a3f17187 | 2466 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 2467 | result = PRINT_NOTHING; |
c4093a6a JM |
2468 | break; |
2469 | ||
1900040c MS |
2470 | case bp_overlay_event: |
2471 | /* By analogy with the thread event, GDB should not stop for these. */ | |
a3f17187 | 2472 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 2473 | result = PRINT_NOTHING; |
1900040c MS |
2474 | break; |
2475 | ||
0fd8e87f UW |
2476 | case bp_longjmp_master: |
2477 | /* These should never be enabled. */ | |
2478 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
2479 | result = PRINT_NOTHING; | |
2480 | break; | |
2481 | ||
e514a9d6 JM |
2482 | case bp_watchpoint: |
2483 | case bp_hardware_watchpoint: | |
fa4727a6 DJ |
2484 | annotate_watchpoint (b->number); |
2485 | if (ui_out_is_mi_like_p (uiout)) | |
2486 | ui_out_field_string | |
2487 | (uiout, "reason", | |
2488 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
2489 | mention (b); | |
f7545552 | 2490 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
fa4727a6 DJ |
2491 | ui_out_text (uiout, "\nOld value = "); |
2492 | watchpoint_value_print (bs->old_val, stb->stream); | |
2493 | ui_out_field_stream (uiout, "old", stb); | |
2494 | ui_out_text (uiout, "\nNew value = "); | |
2495 | watchpoint_value_print (b->val, stb->stream); | |
2496 | ui_out_field_stream (uiout, "new", stb); | |
fa4727a6 | 2497 | ui_out_text (uiout, "\n"); |
e514a9d6 | 2498 | /* More than one watchpoint may have been triggered. */ |
f7545552 | 2499 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
2500 | break; |
2501 | ||
2502 | case bp_read_watchpoint: | |
9dc5e2a9 | 2503 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2504 | ui_out_field_string |
2505 | (uiout, "reason", | |
2506 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 2507 | mention (b); |
f7545552 | 2508 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 2509 | ui_out_text (uiout, "\nValue = "); |
fa4727a6 | 2510 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 2511 | ui_out_field_stream (uiout, "value", stb); |
8b93c638 | 2512 | ui_out_text (uiout, "\n"); |
f7545552 | 2513 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
2514 | break; |
2515 | ||
2516 | case bp_access_watchpoint: | |
fa4727a6 | 2517 | if (bs->old_val != NULL) |
8b93c638 | 2518 | { |
4f8d1dc6 | 2519 | annotate_watchpoint (b->number); |
9dc5e2a9 | 2520 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2521 | ui_out_field_string |
2522 | (uiout, "reason", | |
2523 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 2524 | mention (b); |
f7545552 | 2525 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 2526 | ui_out_text (uiout, "\nOld value = "); |
fa4727a6 | 2527 | watchpoint_value_print (bs->old_val, stb->stream); |
8b93c638 | 2528 | ui_out_field_stream (uiout, "old", stb); |
8b93c638 JM |
2529 | ui_out_text (uiout, "\nNew value = "); |
2530 | } | |
2531 | else | |
2532 | { | |
4f8d1dc6 | 2533 | mention (b); |
9dc5e2a9 | 2534 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2535 | ui_out_field_string |
2536 | (uiout, "reason", | |
2537 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
f7545552 | 2538 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 JM |
2539 | ui_out_text (uiout, "\nValue = "); |
2540 | } | |
fa4727a6 | 2541 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 2542 | ui_out_field_stream (uiout, "new", stb); |
8b93c638 | 2543 | ui_out_text (uiout, "\n"); |
f7545552 | 2544 | result = PRINT_UNKNOWN; |
e514a9d6 | 2545 | break; |
4ce44c66 | 2546 | |
e514a9d6 JM |
2547 | /* Fall through, we don't deal with these types of breakpoints |
2548 | here. */ | |
2549 | ||
11cf8741 | 2550 | case bp_finish: |
9dc5e2a9 | 2551 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2552 | ui_out_field_string |
2553 | (uiout, "reason", | |
2554 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
f7545552 | 2555 | result = PRINT_UNKNOWN; |
8b93c638 JM |
2556 | break; |
2557 | ||
e514a9d6 | 2558 | case bp_until: |
9dc5e2a9 | 2559 | if (ui_out_is_mi_like_p (uiout)) |
1fbc2a49 NR |
2560 | ui_out_field_string |
2561 | (uiout, "reason", | |
2562 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
f7545552 | 2563 | result = PRINT_UNKNOWN; |
8b93c638 JM |
2564 | break; |
2565 | ||
c2d11a7d | 2566 | case bp_none: |
e514a9d6 JM |
2567 | case bp_longjmp: |
2568 | case bp_longjmp_resume: | |
2569 | case bp_step_resume: | |
e514a9d6 JM |
2570 | case bp_watchpoint_scope: |
2571 | case bp_call_dummy: | |
1042e4c0 | 2572 | case bp_tracepoint: |
e514a9d6 | 2573 | default: |
f7545552 TT |
2574 | result = PRINT_UNKNOWN; |
2575 | break; | |
e514a9d6 | 2576 | } |
f7545552 TT |
2577 | |
2578 | do_cleanups (old_chain); | |
2579 | return result; | |
e514a9d6 JM |
2580 | } |
2581 | ||
2582 | /* Generic routine for printing messages indicating why we | |
2583 | stopped. The behavior of this function depends on the value | |
2584 | 'print_it' in the bpstat structure. Under some circumstances we | |
2585 | may decide not to print anything here and delegate the task to | |
2586 | normal_stop(). */ | |
2587 | ||
2588 | static enum print_stop_action | |
2589 | print_bp_stop_message (bpstat bs) | |
2590 | { | |
2591 | switch (bs->print_it) | |
2592 | { | |
2593 | case print_it_noop: | |
2594 | /* Nothing should be printed for this bpstat entry. */ | |
2595 | return PRINT_UNKNOWN; | |
2596 | break; | |
2597 | ||
2598 | case print_it_done: | |
2599 | /* We still want to print the frame, but we already printed the | |
2600 | relevant messages. */ | |
2601 | return PRINT_SRC_AND_LOC; | |
2602 | break; | |
2603 | ||
2604 | case print_it_normal: | |
4f8d1dc6 | 2605 | { |
89f9893c | 2606 | const struct bp_location *bl = bs->breakpoint_at; |
4f8d1dc6 VP |
2607 | struct breakpoint *b = bl ? bl->owner : NULL; |
2608 | ||
2609 | /* Normal case. Call the breakpoint's print_it method, or | |
2610 | print_it_typical. */ | |
2611 | /* FIXME: how breakpoint can ever be NULL here? */ | |
2612 | if (b != NULL && b->ops != NULL && b->ops->print_it != NULL) | |
2613 | return b->ops->print_it (b); | |
2614 | else | |
2615 | return print_it_typical (bs); | |
2616 | } | |
2617 | break; | |
3086aeae | 2618 | |
e514a9d6 | 2619 | default: |
8e65ff28 | 2620 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 2621 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 2622 | break; |
c906108c | 2623 | } |
c906108c SS |
2624 | } |
2625 | ||
e514a9d6 JM |
2626 | /* Print a message indicating what happened. This is called from |
2627 | normal_stop(). The input to this routine is the head of the bpstat | |
2628 | list - a list of the eventpoints that caused this stop. This | |
2629 | routine calls the generic print routine for printing a message | |
2630 | about reasons for stopping. This will print (for example) the | |
2631 | "Breakpoint n," part of the output. The return value of this | |
2632 | routine is one of: | |
c906108c | 2633 | |
917317f4 JM |
2634 | PRINT_UNKNOWN: Means we printed nothing |
2635 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent | |
c5aa993b JM |
2636 | code to print the location. An example is |
2637 | "Breakpoint 1, " which should be followed by | |
2638 | the location. | |
917317f4 | 2639 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
2640 | to also print the location part of the message. |
2641 | An example is the catch/throw messages, which | |
917317f4 JM |
2642 | don't require a location appended to the end. |
2643 | PRINT_NOTHING: We have done some printing and we don't need any | |
2644 | further info to be printed.*/ | |
c906108c | 2645 | |
917317f4 | 2646 | enum print_stop_action |
fba45db2 | 2647 | bpstat_print (bpstat bs) |
c906108c SS |
2648 | { |
2649 | int val; | |
c5aa993b | 2650 | |
c906108c | 2651 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
2652 | (Currently all watchpoints go on the bpstat whether hit or not. |
2653 | That probably could (should) be changed, provided care is taken | |
c906108c | 2654 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
2655 | for (; bs; bs = bs->next) |
2656 | { | |
2657 | val = print_bp_stop_message (bs); | |
2658 | if (val == PRINT_SRC_ONLY | |
2659 | || val == PRINT_SRC_AND_LOC | |
2660 | || val == PRINT_NOTHING) | |
2661 | return val; | |
2662 | } | |
c906108c | 2663 | |
e514a9d6 JM |
2664 | /* We reached the end of the chain, or we got a null BS to start |
2665 | with and nothing was printed. */ | |
917317f4 | 2666 | return PRINT_UNKNOWN; |
c906108c SS |
2667 | } |
2668 | ||
2669 | /* Evaluate the expression EXP and return 1 if value is zero. | |
2670 | This is used inside a catch_errors to evaluate the breakpoint condition. | |
2671 | The argument is a "struct expression *" that has been cast to char * to | |
2672 | make it pass through catch_errors. */ | |
2673 | ||
2674 | static int | |
4efb68b1 | 2675 | breakpoint_cond_eval (void *exp) |
c906108c | 2676 | { |
278cd55f | 2677 | struct value *mark = value_mark (); |
c5aa993b | 2678 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
c906108c SS |
2679 | value_free_to_mark (mark); |
2680 | return i; | |
2681 | } | |
2682 | ||
2683 | /* Allocate a new bpstat and chain it to the current one. */ | |
2684 | ||
2685 | static bpstat | |
89f9893c | 2686 | bpstat_alloc (const struct bp_location *bl, bpstat cbs /* Current "bs" value */ ) |
c906108c SS |
2687 | { |
2688 | bpstat bs; | |
2689 | ||
2690 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
2691 | cbs->next = bs; | |
4f8d1dc6 | 2692 | bs->breakpoint_at = bl; |
c906108c SS |
2693 | /* If the condition is false, etc., don't do the commands. */ |
2694 | bs->commands = NULL; | |
2695 | bs->old_val = NULL; | |
2696 | bs->print_it = print_it_normal; | |
2697 | return bs; | |
2698 | } | |
2699 | \f | |
d983da9c DJ |
2700 | /* The target has stopped with waitstatus WS. Check if any hardware |
2701 | watchpoints have triggered, according to the target. */ | |
2702 | ||
2703 | int | |
2704 | watchpoints_triggered (struct target_waitstatus *ws) | |
2705 | { | |
d92524f1 | 2706 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
2707 | CORE_ADDR addr; |
2708 | struct breakpoint *b; | |
2709 | ||
2710 | if (!stopped_by_watchpoint) | |
2711 | { | |
2712 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
2713 | as not triggered. */ | |
2714 | ALL_BREAKPOINTS (b) | |
2715 | if (b->type == bp_hardware_watchpoint | |
2716 | || b->type == bp_read_watchpoint | |
2717 | || b->type == bp_access_watchpoint) | |
2718 | b->watchpoint_triggered = watch_triggered_no; | |
2719 | ||
2720 | return 0; | |
2721 | } | |
2722 | ||
2723 | if (!target_stopped_data_address (¤t_target, &addr)) | |
2724 | { | |
2725 | /* We were stopped by a watchpoint, but we don't know where. | |
2726 | Mark all watchpoints as unknown. */ | |
2727 | ALL_BREAKPOINTS (b) | |
2728 | if (b->type == bp_hardware_watchpoint | |
2729 | || b->type == bp_read_watchpoint | |
2730 | || b->type == bp_access_watchpoint) | |
2731 | b->watchpoint_triggered = watch_triggered_unknown; | |
2732 | ||
2733 | return stopped_by_watchpoint; | |
2734 | } | |
2735 | ||
2736 | /* The target could report the data address. Mark watchpoints | |
2737 | affected by this data address as triggered, and all others as not | |
2738 | triggered. */ | |
2739 | ||
2740 | ALL_BREAKPOINTS (b) | |
2741 | if (b->type == bp_hardware_watchpoint | |
2742 | || b->type == bp_read_watchpoint | |
2743 | || b->type == bp_access_watchpoint) | |
2744 | { | |
a5606eee | 2745 | struct bp_location *loc; |
d983da9c DJ |
2746 | struct value *v; |
2747 | ||
2748 | b->watchpoint_triggered = watch_triggered_no; | |
a5606eee VP |
2749 | for (loc = b->loc; loc; loc = loc->next) |
2750 | /* Exact match not required. Within range is | |
2751 | sufficient. */ | |
5009afc5 AS |
2752 | if (target_watchpoint_addr_within_range (¤t_target, |
2753 | addr, loc->address, | |
2754 | loc->length)) | |
a5606eee VP |
2755 | { |
2756 | b->watchpoint_triggered = watch_triggered_yes; | |
2757 | break; | |
2758 | } | |
d983da9c DJ |
2759 | } |
2760 | ||
2761 | return 1; | |
2762 | } | |
2763 | ||
c906108c SS |
2764 | /* Possible return values for watchpoint_check (this can't be an enum |
2765 | because of check_errors). */ | |
2766 | /* The watchpoint has been deleted. */ | |
2767 | #define WP_DELETED 1 | |
2768 | /* The value has changed. */ | |
2769 | #define WP_VALUE_CHANGED 2 | |
2770 | /* The value has not changed. */ | |
2771 | #define WP_VALUE_NOT_CHANGED 3 | |
2772 | ||
2773 | #define BP_TEMPFLAG 1 | |
2774 | #define BP_HARDWAREFLAG 2 | |
2775 | ||
2776 | /* Check watchpoint condition. */ | |
2777 | ||
2778 | static int | |
4efb68b1 | 2779 | watchpoint_check (void *p) |
c906108c SS |
2780 | { |
2781 | bpstat bs = (bpstat) p; | |
2782 | struct breakpoint *b; | |
2783 | struct frame_info *fr; | |
2784 | int within_current_scope; | |
2785 | ||
4f8d1dc6 | 2786 | b = bs->breakpoint_at->owner; |
c906108c SS |
2787 | |
2788 | if (b->exp_valid_block == NULL) | |
2789 | within_current_scope = 1; | |
2790 | else | |
2791 | { | |
edb3359d DJ |
2792 | struct frame_info *frame = get_current_frame (); |
2793 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
2794 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
2795 | ||
101dcfbe | 2796 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 2797 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
2798 | |
2799 | /* If we've gotten confused in the unwinder, we might have | |
2800 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
2801 | if (within_current_scope) |
2802 | { | |
2803 | struct symbol *function; | |
2804 | ||
2805 | function = get_frame_function (fr); | |
2806 | if (function == NULL | |
2807 | || !contained_in (b->exp_valid_block, | |
2808 | SYMBOL_BLOCK_VALUE (function))) | |
2809 | within_current_scope = 0; | |
2810 | } | |
69fbadd5 | 2811 | |
c12260ac CV |
2812 | /* in_function_epilogue_p() returns a non-zero value if we're still |
2813 | in the function but the stack frame has already been invalidated. | |
2814 | Since we can't rely on the values of local variables after the | |
2815 | stack has been destroyed, we are treating the watchpoint in that | |
edb3359d DJ |
2816 | state as `not changed' without further checking. Don't mark |
2817 | watchpoints as changed if the current frame is in an epilogue - | |
2818 | even if they are in some other frame, our view of the stack | |
2819 | is likely to be wrong. */ | |
2820 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) | |
2821 | return WP_VALUE_NOT_CHANGED; | |
fb14de7b | 2822 | |
edb3359d | 2823 | if (within_current_scope) |
c906108c SS |
2824 | /* If we end up stopping, the current frame will get selected |
2825 | in normal_stop. So this call to select_frame won't affect | |
2826 | the user. */ | |
0f7d239c | 2827 | select_frame (fr); |
c906108c | 2828 | } |
c5aa993b | 2829 | |
c906108c SS |
2830 | if (within_current_scope) |
2831 | { | |
2832 | /* We use value_{,free_to_}mark because it could be a | |
2833 | *long* time before we return to the command level and | |
c5aa993b JM |
2834 | call free_all_values. We can't call free_all_values because |
2835 | we might be in the middle of evaluating a function call. */ | |
c906108c | 2836 | |
278cd55f | 2837 | struct value *mark = value_mark (); |
fa4727a6 DJ |
2838 | struct value *new_val; |
2839 | ||
2840 | fetch_watchpoint_value (b->exp, &new_val, NULL, NULL); | |
2841 | if ((b->val != NULL) != (new_val != NULL) | |
2842 | || (b->val != NULL && !value_equal (b->val, new_val))) | |
c906108c | 2843 | { |
fa4727a6 DJ |
2844 | if (new_val != NULL) |
2845 | { | |
2846 | release_value (new_val); | |
2847 | value_free_to_mark (mark); | |
2848 | } | |
c906108c SS |
2849 | bs->old_val = b->val; |
2850 | b->val = new_val; | |
fa4727a6 | 2851 | b->val_valid = 1; |
c906108c SS |
2852 | /* We will stop here */ |
2853 | return WP_VALUE_CHANGED; | |
2854 | } | |
2855 | else | |
2856 | { | |
2857 | /* Nothing changed, don't do anything. */ | |
2858 | value_free_to_mark (mark); | |
2859 | /* We won't stop here */ | |
2860 | return WP_VALUE_NOT_CHANGED; | |
2861 | } | |
2862 | } | |
2863 | else | |
2864 | { | |
2865 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
2866 | if we temporarily ignored the watchpoint, then when |
2867 | we reenter the block in which it is valid it contains | |
2868 | garbage (in the case of a function, it may have two | |
2869 | garbage values, one before and one after the prologue). | |
2870 | So we can't even detect the first assignment to it and | |
2871 | watch after that (since the garbage may or may not equal | |
2872 | the first value assigned). */ | |
4ce44c66 JM |
2873 | /* We print all the stop information in print_it_typical(), but |
2874 | in this case, by the time we call print_it_typical() this bp | |
2875 | will be deleted already. So we have no choice but print the | |
2876 | information here. */ | |
9dc5e2a9 | 2877 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2878 | ui_out_field_string |
2879 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 2880 | ui_out_text (uiout, "\nWatchpoint "); |
4f8d1dc6 | 2881 | ui_out_field_int (uiout, "wpnum", b->number); |
8b93c638 JM |
2882 | ui_out_text (uiout, " deleted because the program has left the block in\n\ |
2883 | which its expression is valid.\n"); | |
4ce44c66 | 2884 | |
c906108c | 2885 | if (b->related_breakpoint) |
b5de0fa7 EZ |
2886 | b->related_breakpoint->disposition = disp_del_at_next_stop; |
2887 | b->disposition = disp_del_at_next_stop; | |
c906108c SS |
2888 | |
2889 | return WP_DELETED; | |
2890 | } | |
2891 | } | |
2892 | ||
18a18393 VP |
2893 | /* Return true if it looks like target has stopped due to hitting |
2894 | breakpoint location BL. This function does not check if we | |
2895 | should stop, only if BL explains the stop. */ | |
2896 | static int | |
2897 | bpstat_check_location (const struct bp_location *bl, CORE_ADDR bp_addr) | |
2898 | { | |
2899 | struct breakpoint *b = bl->owner; | |
2900 | ||
2901 | if (b->type != bp_watchpoint | |
2902 | && b->type != bp_hardware_watchpoint | |
2903 | && b->type != bp_read_watchpoint | |
2904 | && b->type != bp_access_watchpoint | |
2905 | && b->type != bp_hardware_breakpoint | |
fe798b75 | 2906 | && b->type != bp_catchpoint) /* a non-watchpoint bp */ |
18a18393 VP |
2907 | { |
2908 | if (bl->address != bp_addr) /* address doesn't match */ | |
2909 | return 0; | |
2910 | if (overlay_debugging /* unmapped overlay section */ | |
2911 | && section_is_overlay (bl->section) | |
2912 | && !section_is_mapped (bl->section)) | |
2913 | return 0; | |
2914 | } | |
2915 | ||
2916 | /* Continuable hardware watchpoints are treated as non-existent if the | |
2917 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
2918 | some data address). Otherwise gdb won't stop on a break instruction | |
2919 | in the code (not from a breakpoint) when a hardware watchpoint has | |
2920 | been defined. Also skip watchpoints which we know did not trigger | |
2921 | (did not match the data address). */ | |
2922 | ||
2923 | if ((b->type == bp_hardware_watchpoint | |
2924 | || b->type == bp_read_watchpoint | |
2925 | || b->type == bp_access_watchpoint) | |
2926 | && b->watchpoint_triggered == watch_triggered_no) | |
2927 | return 0; | |
2928 | ||
2929 | if (b->type == bp_hardware_breakpoint) | |
2930 | { | |
2931 | if (bl->address != bp_addr) | |
2932 | return 0; | |
2933 | if (overlay_debugging /* unmapped overlay section */ | |
2934 | && section_is_overlay (bl->section) | |
2935 | && !section_is_mapped (bl->section)) | |
2936 | return 0; | |
2937 | } | |
ce78b96d | 2938 | |
ce78b96d JB |
2939 | if (b->type == bp_catchpoint) |
2940 | { | |
2941 | gdb_assert (b->ops != NULL && b->ops->breakpoint_hit != NULL); | |
2942 | if (!b->ops->breakpoint_hit (b)) | |
2943 | return 0; | |
2944 | } | |
2945 | ||
18a18393 VP |
2946 | return 1; |
2947 | } | |
2948 | ||
2949 | /* If BS refers to a watchpoint, determine if the watched values | |
2950 | has actually changed, and we should stop. If not, set BS->stop | |
2951 | to 0. */ | |
2952 | static void | |
2953 | bpstat_check_watchpoint (bpstat bs) | |
2954 | { | |
2955 | const struct bp_location *bl = bs->breakpoint_at; | |
2956 | struct breakpoint *b = bl->owner; | |
2957 | ||
2958 | if (b->type == bp_watchpoint | |
2959 | || b->type == bp_read_watchpoint | |
2960 | || b->type == bp_access_watchpoint | |
2961 | || b->type == bp_hardware_watchpoint) | |
2962 | { | |
2963 | CORE_ADDR addr; | |
2964 | struct value *v; | |
2965 | int must_check_value = 0; | |
2966 | ||
2967 | if (b->type == bp_watchpoint) | |
2968 | /* For a software watchpoint, we must always check the | |
2969 | watched value. */ | |
2970 | must_check_value = 1; | |
2971 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
2972 | /* We have a hardware watchpoint (read, write, or access) | |
2973 | and the target earlier reported an address watched by | |
2974 | this watchpoint. */ | |
2975 | must_check_value = 1; | |
2976 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
2977 | && b->type == bp_hardware_watchpoint) | |
2978 | /* We were stopped by a hardware watchpoint, but the target could | |
2979 | not report the data address. We must check the watchpoint's | |
2980 | value. Access and read watchpoints are out of luck; without | |
2981 | a data address, we can't figure it out. */ | |
2982 | must_check_value = 1; | |
2983 | ||
2984 | if (must_check_value) | |
2985 | { | |
2986 | char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
2987 | b->number); | |
2988 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
2989 | int e = catch_errors (watchpoint_check, bs, message, | |
2990 | RETURN_MASK_ALL); | |
2991 | do_cleanups (cleanups); | |
2992 | switch (e) | |
2993 | { | |
2994 | case WP_DELETED: | |
2995 | /* We've already printed what needs to be printed. */ | |
2996 | bs->print_it = print_it_done; | |
2997 | /* Stop. */ | |
2998 | break; | |
2999 | case WP_VALUE_CHANGED: | |
3000 | if (b->type == bp_read_watchpoint) | |
3001 | { | |
3002 | /* Don't stop: read watchpoints shouldn't fire if | |
3003 | the value has changed. This is for targets | |
3004 | which cannot set read-only watchpoints. */ | |
3005 | bs->print_it = print_it_noop; | |
3006 | bs->stop = 0; | |
3007 | } | |
3008 | break; | |
3009 | case WP_VALUE_NOT_CHANGED: | |
3010 | if (b->type == bp_hardware_watchpoint | |
3011 | || b->type == bp_watchpoint) | |
3012 | { | |
3013 | /* Don't stop: write watchpoints shouldn't fire if | |
3014 | the value hasn't changed. */ | |
3015 | bs->print_it = print_it_noop; | |
3016 | bs->stop = 0; | |
3017 | } | |
3018 | /* Stop. */ | |
3019 | break; | |
3020 | default: | |
3021 | /* Can't happen. */ | |
3022 | case 0: | |
3023 | /* Error from catch_errors. */ | |
3024 | printf_filtered (_("Watchpoint %d deleted.\n"), b->number); | |
3025 | if (b->related_breakpoint) | |
3026 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
3027 | b->disposition = disp_del_at_next_stop; | |
3028 | /* We've already printed what needs to be printed. */ | |
3029 | bs->print_it = print_it_done; | |
3030 | break; | |
3031 | } | |
3032 | } | |
3033 | else /* must_check_value == 0 */ | |
3034 | { | |
3035 | /* This is a case where some watchpoint(s) triggered, but | |
3036 | not at the address of this watchpoint, or else no | |
3037 | watchpoint triggered after all. So don't print | |
3038 | anything for this watchpoint. */ | |
3039 | bs->print_it = print_it_noop; | |
3040 | bs->stop = 0; | |
3041 | } | |
3042 | } | |
3043 | } | |
3044 | ||
3045 | ||
3046 | /* Check conditions (condition proper, frame, thread and ignore count) | |
3047 | of breakpoint referred to by BS. If we should not stop for this | |
3048 | breakpoint, set BS->stop to 0. */ | |
3049 | static void | |
3050 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
3051 | { | |
3052 | int thread_id = pid_to_thread_id (ptid); | |
3053 | const struct bp_location *bl = bs->breakpoint_at; | |
3054 | struct breakpoint *b = bl->owner; | |
3055 | ||
3056 | if (frame_id_p (b->frame_id) | |
edb3359d | 3057 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 VP |
3058 | bs->stop = 0; |
3059 | else if (bs->stop) | |
3060 | { | |
3061 | int value_is_zero = 0; | |
3062 | ||
3063 | /* If this is a scope breakpoint, mark the associated | |
3064 | watchpoint as triggered so that we will handle the | |
3065 | out-of-scope event. We'll get to the watchpoint next | |
3066 | iteration. */ | |
3067 | if (b->type == bp_watchpoint_scope) | |
3068 | b->related_breakpoint->watchpoint_triggered = watch_triggered_yes; | |
3069 | ||
3070 | if (bl->cond && bl->owner->disposition != disp_del_at_next_stop) | |
3071 | { | |
c5bc3a77 DJ |
3072 | /* We use value_mark and value_free_to_mark because it could |
3073 | be a long time before we return to the command level and | |
3074 | call free_all_values. We can't call free_all_values | |
3075 | because we might be in the middle of evaluating a | |
3076 | function call. */ | |
3077 | struct value *mark = value_mark (); | |
3078 | ||
edb3359d DJ |
3079 | /* Need to select the frame, with all that implies so that |
3080 | the conditions will have the right context. Because we | |
3081 | use the frame, we will not see an inlined function's | |
3082 | variables when we arrive at a breakpoint at the start | |
3083 | of the inlined function; the current frame will be the | |
3084 | call site. */ | |
18a18393 VP |
3085 | select_frame (get_current_frame ()); |
3086 | value_is_zero | |
3087 | = catch_errors (breakpoint_cond_eval, (bl->cond), | |
3088 | "Error in testing breakpoint condition:\n", | |
3089 | RETURN_MASK_ALL); | |
3090 | /* FIXME-someday, should give breakpoint # */ | |
c5bc3a77 | 3091 | value_free_to_mark (mark); |
18a18393 VP |
3092 | } |
3093 | if (bl->cond && value_is_zero) | |
3094 | { | |
3095 | bs->stop = 0; | |
3096 | } | |
3097 | else if (b->thread != -1 && b->thread != thread_id) | |
3098 | { | |
3099 | bs->stop = 0; | |
3100 | } | |
3101 | else if (b->ignore_count > 0) | |
3102 | { | |
3103 | b->ignore_count--; | |
3104 | annotate_ignore_count_change (); | |
3105 | bs->stop = 0; | |
3106 | /* Increase the hit count even though we don't | |
3107 | stop. */ | |
3108 | ++(b->hit_count); | |
3109 | } | |
3110 | } | |
3111 | } | |
3112 | ||
3113 | ||
9709f61c | 3114 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 3115 | BP_ADDR in thread PTID. |
c906108c | 3116 | |
d983da9c | 3117 | Determine whether we stopped at a breakpoint, etc, or whether we |
c906108c SS |
3118 | don't understand this stop. Result is a chain of bpstat's such that: |
3119 | ||
c5aa993b | 3120 | if we don't understand the stop, the result is a null pointer. |
c906108c | 3121 | |
c5aa993b | 3122 | if we understand why we stopped, the result is not null. |
c906108c | 3123 | |
c5aa993b JM |
3124 | Each element of the chain refers to a particular breakpoint or |
3125 | watchpoint at which we have stopped. (We may have stopped for | |
3126 | several reasons concurrently.) | |
c906108c | 3127 | |
c5aa993b JM |
3128 | Each element of the chain has valid next, breakpoint_at, |
3129 | commands, FIXME??? fields. */ | |
c906108c SS |
3130 | |
3131 | bpstat | |
d983da9c | 3132 | bpstat_stop_status (CORE_ADDR bp_addr, ptid_t ptid) |
c906108c | 3133 | { |
0d381245 | 3134 | struct breakpoint *b = NULL; |
89f9893c | 3135 | const struct bp_location *bl; |
20874c92 | 3136 | struct bp_location *loc; |
c906108c SS |
3137 | /* Root of the chain of bpstat's */ |
3138 | struct bpstats root_bs[1]; | |
3139 | /* Pointer to the last thing in the chain currently. */ | |
3140 | bpstat bs = root_bs; | |
20874c92 | 3141 | int ix; |
d832cb68 | 3142 | int need_remove_insert; |
c906108c | 3143 | |
0d381245 | 3144 | ALL_BP_LOCATIONS (bl) |
c5aa993b | 3145 | { |
0d381245 VP |
3146 | b = bl->owner; |
3147 | gdb_assert (b); | |
468d015d | 3148 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) |
c5aa993b JM |
3149 | continue; |
3150 | ||
a5606eee VP |
3151 | /* For hardware watchpoints, we look only at the first location. |
3152 | The watchpoint_check function will work on entire expression, | |
3153 | not the individual locations. For read watchopints, the | |
3154 | watchpoints_triggered function have checked all locations | |
3155 | alrea | |
3156 | */ | |
3157 | if (b->type == bp_hardware_watchpoint && bl != b->loc) | |
3158 | continue; | |
3159 | ||
18a18393 VP |
3160 | if (!bpstat_check_location (bl, bp_addr)) |
3161 | continue; | |
3162 | ||
c5aa993b JM |
3163 | /* Come here if it's a watchpoint, or if the break address matches */ |
3164 | ||
0d381245 | 3165 | bs = bpstat_alloc (bl, bs); /* Alloc a bpstat to explain stop */ |
c5aa993b | 3166 | |
18a18393 VP |
3167 | /* Assume we stop. Should we find watchpoint that is not actually |
3168 | triggered, or if condition of breakpoint is false, we'll reset | |
3169 | 'stop' to 0. */ | |
c5aa993b JM |
3170 | bs->stop = 1; |
3171 | bs->print = 1; | |
3172 | ||
18a18393 VP |
3173 | bpstat_check_watchpoint (bs); |
3174 | if (!bs->stop) | |
3175 | continue; | |
c5aa993b | 3176 | |
0fd8e87f UW |
3177 | if (b->type == bp_thread_event || b->type == bp_overlay_event |
3178 | || b->type == bp_longjmp_master) | |
18a18393 | 3179 | /* We do not stop for these. */ |
c5aa993b JM |
3180 | bs->stop = 0; |
3181 | else | |
18a18393 VP |
3182 | bpstat_check_breakpoint_conditions (bs, ptid); |
3183 | ||
3184 | if (bs->stop) | |
c5aa993b | 3185 | { |
18a18393 | 3186 | ++(b->hit_count); |
d983da9c | 3187 | |
18a18393 VP |
3188 | /* We will stop here */ |
3189 | if (b->disposition == disp_disable) | |
c5aa993b | 3190 | { |
514f746b AR |
3191 | if (b->enable_state != bp_permanent) |
3192 | b->enable_state = bp_disabled; | |
b60e7edf | 3193 | update_global_location_list (0); |
c5aa993b | 3194 | } |
18a18393 VP |
3195 | if (b->silent) |
3196 | bs->print = 0; | |
3197 | bs->commands = b->commands; | |
059fb39f PM |
3198 | if (bs->commands |
3199 | && (strcmp ("silent", bs->commands->line) == 0 | |
3200 | || (xdb_commands && strcmp ("Q", bs->commands->line) == 0))) | |
c5aa993b | 3201 | { |
18a18393 VP |
3202 | bs->commands = bs->commands->next; |
3203 | bs->print = 0; | |
c5aa993b | 3204 | } |
18a18393 | 3205 | bs->commands = copy_command_lines (bs->commands); |
c5aa993b | 3206 | } |
18a18393 | 3207 | |
c5aa993b JM |
3208 | /* Print nothing for this entry if we dont stop or if we dont print. */ |
3209 | if (bs->stop == 0 || bs->print == 0) | |
3210 | bs->print_it = print_it_noop; | |
3211 | } | |
c906108c | 3212 | |
20874c92 VP |
3213 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
3214 | { | |
3215 | if (loc->address == bp_addr) | |
3216 | { | |
3217 | bs = bpstat_alloc (loc, bs); | |
3218 | /* For hits of moribund locations, we should just proceed. */ | |
3219 | bs->stop = 0; | |
3220 | bs->print = 0; | |
3221 | bs->print_it = print_it_noop; | |
3222 | } | |
3223 | } | |
3224 | ||
c906108c SS |
3225 | bs->next = NULL; /* Terminate the chain */ |
3226 | bs = root_bs->next; /* Re-grab the head of the chain */ | |
3227 | ||
d983da9c DJ |
3228 | /* If we aren't stopping, the value of some hardware watchpoint may |
3229 | not have changed, but the intermediate memory locations we are | |
3230 | watching may have. Don't bother if we're stopping; this will get | |
3231 | done later. */ | |
3232 | for (bs = root_bs->next; bs != NULL; bs = bs->next) | |
3233 | if (bs->stop) | |
3234 | break; | |
3235 | ||
d832cb68 | 3236 | need_remove_insert = 0; |
d983da9c DJ |
3237 | if (bs == NULL) |
3238 | for (bs = root_bs->next; bs != NULL; bs = bs->next) | |
3239 | if (!bs->stop | |
20874c92 | 3240 | && bs->breakpoint_at->owner |
d983da9c DJ |
3241 | && (bs->breakpoint_at->owner->type == bp_hardware_watchpoint |
3242 | || bs->breakpoint_at->owner->type == bp_read_watchpoint | |
3243 | || bs->breakpoint_at->owner->type == bp_access_watchpoint)) | |
3244 | { | |
a5606eee VP |
3245 | /* remove/insert can invalidate bs->breakpoint_at, if this |
3246 | location is no longer used by the watchpoint. Prevent | |
3247 | further code from trying to use it. */ | |
3248 | bs->breakpoint_at = NULL; | |
d832cb68 | 3249 | need_remove_insert = 1; |
d983da9c DJ |
3250 | } |
3251 | ||
d832cb68 DD |
3252 | if (need_remove_insert) |
3253 | { | |
3254 | remove_breakpoints (); | |
3255 | insert_breakpoints (); | |
3256 | } | |
3257 | ||
d983da9c | 3258 | return root_bs->next; |
c906108c SS |
3259 | } |
3260 | \f | |
3261 | /* Tell what to do about this bpstat. */ | |
3262 | struct bpstat_what | |
fba45db2 | 3263 | bpstat_what (bpstat bs) |
c906108c SS |
3264 | { |
3265 | /* Classify each bpstat as one of the following. */ | |
c5aa993b JM |
3266 | enum class |
3267 | { | |
3268 | /* This bpstat element has no effect on the main_action. */ | |
3269 | no_effect = 0, | |
3270 | ||
3271 | /* There was a watchpoint, stop but don't print. */ | |
3272 | wp_silent, | |
c906108c | 3273 | |
c5aa993b JM |
3274 | /* There was a watchpoint, stop and print. */ |
3275 | wp_noisy, | |
c906108c | 3276 | |
c5aa993b JM |
3277 | /* There was a breakpoint but we're not stopping. */ |
3278 | bp_nostop, | |
c906108c | 3279 | |
c5aa993b JM |
3280 | /* There was a breakpoint, stop but don't print. */ |
3281 | bp_silent, | |
c906108c | 3282 | |
c5aa993b JM |
3283 | /* There was a breakpoint, stop and print. */ |
3284 | bp_noisy, | |
c906108c | 3285 | |
c5aa993b JM |
3286 | /* We hit the longjmp breakpoint. */ |
3287 | long_jump, | |
c906108c | 3288 | |
c5aa993b JM |
3289 | /* We hit the longjmp_resume breakpoint. */ |
3290 | long_resume, | |
c906108c | 3291 | |
c5aa993b JM |
3292 | /* We hit the step_resume breakpoint. */ |
3293 | step_resume, | |
c906108c | 3294 | |
c5aa993b JM |
3295 | /* We hit the shared library event breakpoint. */ |
3296 | shlib_event, | |
c906108c | 3297 | |
c5aa993b JM |
3298 | /* This is just used to count how many enums there are. */ |
3299 | class_last | |
c906108c SS |
3300 | }; |
3301 | ||
3302 | /* Here is the table which drives this routine. So that we can | |
3303 | format it pretty, we define some abbreviations for the | |
3304 | enum bpstat_what codes. */ | |
3305 | #define kc BPSTAT_WHAT_KEEP_CHECKING | |
3306 | #define ss BPSTAT_WHAT_STOP_SILENT | |
3307 | #define sn BPSTAT_WHAT_STOP_NOISY | |
3308 | #define sgl BPSTAT_WHAT_SINGLE | |
3309 | #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME | |
3310 | #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME | |
c906108c | 3311 | #define sr BPSTAT_WHAT_STEP_RESUME |
c906108c | 3312 | #define shl BPSTAT_WHAT_CHECK_SHLIBS |
c906108c SS |
3313 | |
3314 | /* "Can't happen." Might want to print an error message. | |
3315 | abort() is not out of the question, but chances are GDB is just | |
3316 | a bit confused, not unusable. */ | |
3317 | #define err BPSTAT_WHAT_STOP_NOISY | |
3318 | ||
3319 | /* Given an old action and a class, come up with a new action. */ | |
3320 | /* One interesting property of this table is that wp_silent is the same | |
3321 | as bp_silent and wp_noisy is the same as bp_noisy. That is because | |
3322 | after stopping, the check for whether to step over a breakpoint | |
3323 | (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without | |
53a5351d JM |
3324 | reference to how we stopped. We retain separate wp_silent and |
3325 | bp_silent codes in case we want to change that someday. | |
43ff13b4 JM |
3326 | |
3327 | Another possibly interesting property of this table is that | |
3328 | there's a partial ordering, priority-like, of the actions. Once | |
3329 | you've decided that some action is appropriate, you'll never go | |
3330 | back and decide something of a lower priority is better. The | |
3331 | ordering is: | |
3332 | ||
d81191fc JB |
3333 | kc < clr sgl shl slr sn sr ss |
3334 | sgl < shl slr sn sr ss | |
3335 | slr < err shl sn sr ss | |
3336 | clr < err shl sn sr ss | |
3337 | ss < shl sn sr | |
3338 | sn < shl sr | |
3339 | shl < sr | |
4d5b2cd7 | 3340 | sr < |
c5aa993b | 3341 | |
43ff13b4 JM |
3342 | What I think this means is that we don't need a damned table |
3343 | here. If you just put the rows and columns in the right order, | |
3344 | it'd look awfully regular. We could simply walk the bpstat list | |
3345 | and choose the highest priority action we find, with a little | |
78b6a731 | 3346 | logic to handle the 'err' cases. */ |
c906108c SS |
3347 | |
3348 | /* step_resume entries: a step resume breakpoint overrides another | |
3349 | breakpoint of signal handling (see comment in wait_for_inferior | |
fcf70625 | 3350 | at where we set the step_resume breakpoint). */ |
c906108c SS |
3351 | |
3352 | static const enum bpstat_what_main_action | |
c5aa993b JM |
3353 | table[(int) class_last][(int) BPSTAT_WHAT_LAST] = |
3354 | { | |
3355 | /* old action */ | |
d81191fc | 3356 | /* kc ss sn sgl slr clr sr shl |
c5aa993b JM |
3357 | */ |
3358 | /*no_effect */ | |
d81191fc | 3359 | {kc, ss, sn, sgl, slr, clr, sr, shl}, |
c5aa993b | 3360 | /*wp_silent */ |
d81191fc | 3361 | {ss, ss, sn, ss, ss, ss, sr, shl}, |
c5aa993b | 3362 | /*wp_noisy */ |
d81191fc | 3363 | {sn, sn, sn, sn, sn, sn, sr, shl}, |
c5aa993b | 3364 | /*bp_nostop */ |
d81191fc | 3365 | {sgl, ss, sn, sgl, slr, slr, sr, shl}, |
c5aa993b | 3366 | /*bp_silent */ |
d81191fc | 3367 | {ss, ss, sn, ss, ss, ss, sr, shl}, |
c5aa993b | 3368 | /*bp_noisy */ |
d81191fc | 3369 | {sn, sn, sn, sn, sn, sn, sr, shl}, |
c5aa993b | 3370 | /*long_jump */ |
d81191fc | 3371 | {slr, ss, sn, slr, slr, err, sr, shl}, |
c5aa993b | 3372 | /*long_resume */ |
d81191fc | 3373 | {clr, ss, sn, err, err, err, sr, shl}, |
c5aa993b | 3374 | /*step_resume */ |
d81191fc | 3375 | {sr, sr, sr, sr, sr, sr, sr, sr}, |
c5aa993b | 3376 | /*shlib */ |
d81191fc | 3377 | {shl, shl, shl, shl, shl, shl, sr, shl} |
c5aa993b | 3378 | }; |
c906108c SS |
3379 | |
3380 | #undef kc | |
3381 | #undef ss | |
3382 | #undef sn | |
3383 | #undef sgl | |
3384 | #undef slr | |
3385 | #undef clr | |
c906108c SS |
3386 | #undef err |
3387 | #undef sr | |
3388 | #undef ts | |
3389 | #undef shl | |
c906108c SS |
3390 | enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING; |
3391 | struct bpstat_what retval; | |
3392 | ||
3393 | retval.call_dummy = 0; | |
3394 | for (; bs != NULL; bs = bs->next) | |
3395 | { | |
3396 | enum class bs_class = no_effect; | |
3397 | if (bs->breakpoint_at == NULL) | |
3398 | /* I suspect this can happen if it was a momentary breakpoint | |
3399 | which has since been deleted. */ | |
3400 | continue; | |
20874c92 VP |
3401 | if (bs->breakpoint_at->owner == NULL) |
3402 | bs_class = bp_nostop; | |
3403 | else | |
4f8d1dc6 | 3404 | switch (bs->breakpoint_at->owner->type) |
c906108c SS |
3405 | { |
3406 | case bp_none: | |
3407 | continue; | |
3408 | ||
3409 | case bp_breakpoint: | |
3410 | case bp_hardware_breakpoint: | |
3411 | case bp_until: | |
3412 | case bp_finish: | |
3413 | if (bs->stop) | |
3414 | { | |
3415 | if (bs->print) | |
3416 | bs_class = bp_noisy; | |
3417 | else | |
3418 | bs_class = bp_silent; | |
3419 | } | |
3420 | else | |
3421 | bs_class = bp_nostop; | |
3422 | break; | |
3423 | case bp_watchpoint: | |
3424 | case bp_hardware_watchpoint: | |
3425 | case bp_read_watchpoint: | |
3426 | case bp_access_watchpoint: | |
3427 | if (bs->stop) | |
3428 | { | |
3429 | if (bs->print) | |
3430 | bs_class = wp_noisy; | |
3431 | else | |
3432 | bs_class = wp_silent; | |
3433 | } | |
3434 | else | |
53a5351d JM |
3435 | /* There was a watchpoint, but we're not stopping. |
3436 | This requires no further action. */ | |
c906108c SS |
3437 | bs_class = no_effect; |
3438 | break; | |
3439 | case bp_longjmp: | |
3440 | bs_class = long_jump; | |
3441 | break; | |
3442 | case bp_longjmp_resume: | |
3443 | bs_class = long_resume; | |
3444 | break; | |
3445 | case bp_step_resume: | |
3446 | if (bs->stop) | |
3447 | { | |
3448 | bs_class = step_resume; | |
3449 | } | |
3450 | else | |
3451 | /* It is for the wrong frame. */ | |
3452 | bs_class = bp_nostop; | |
3453 | break; | |
c906108c SS |
3454 | case bp_watchpoint_scope: |
3455 | bs_class = bp_nostop; | |
3456 | break; | |
c5aa993b JM |
3457 | case bp_shlib_event: |
3458 | bs_class = shlib_event; | |
3459 | break; | |
c4093a6a | 3460 | case bp_thread_event: |
1900040c | 3461 | case bp_overlay_event: |
0fd8e87f | 3462 | case bp_longjmp_master: |
c4093a6a JM |
3463 | bs_class = bp_nostop; |
3464 | break; | |
ce78b96d | 3465 | case bp_catchpoint: |
c5aa993b JM |
3466 | if (bs->stop) |
3467 | { | |
3468 | if (bs->print) | |
3469 | bs_class = bp_noisy; | |
3470 | else | |
3471 | bs_class = bp_silent; | |
3472 | } | |
3473 | else | |
53a5351d JM |
3474 | /* There was a catchpoint, but we're not stopping. |
3475 | This requires no further action. */ | |
c5aa993b JM |
3476 | bs_class = no_effect; |
3477 | break; | |
c906108c | 3478 | case bp_call_dummy: |
53a5351d JM |
3479 | /* Make sure the action is stop (silent or noisy), |
3480 | so infrun.c pops the dummy frame. */ | |
c906108c SS |
3481 | bs_class = bp_silent; |
3482 | retval.call_dummy = 1; | |
3483 | break; | |
1042e4c0 SS |
3484 | case bp_tracepoint: |
3485 | /* Tracepoint hits should not be reported back to GDB, and | |
3486 | if one got through somehow, it should have been filtered | |
3487 | out already. */ | |
3488 | internal_error (__FILE__, __LINE__, | |
3489 | _("bpstat_what: bp_tracepoint encountered")); | |
3490 | break; | |
c906108c | 3491 | } |
c5aa993b | 3492 | current_action = table[(int) bs_class][(int) current_action]; |
c906108c SS |
3493 | } |
3494 | retval.main_action = current_action; | |
3495 | return retval; | |
3496 | } | |
3497 | ||
3498 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
3499 | without hardware support). This isn't related to a specific bpstat, | |
3500 | just to things like whether watchpoints are set. */ | |
3501 | ||
c5aa993b | 3502 | int |
fba45db2 | 3503 | bpstat_should_step (void) |
c906108c SS |
3504 | { |
3505 | struct breakpoint *b; | |
3506 | ALL_BREAKPOINTS (b) | |
717a8278 | 3507 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 3508 | return 1; |
c906108c SS |
3509 | return 0; |
3510 | } | |
3511 | ||
c906108c | 3512 | \f |
c5aa993b | 3513 | |
0d381245 VP |
3514 | static void print_breakpoint_location (struct breakpoint *b, |
3515 | struct bp_location *loc, | |
3516 | char *wrap_indent, | |
3517 | struct ui_stream *stb) | |
3518 | { | |
3519 | if (b->source_file) | |
3520 | { | |
3521 | struct symbol *sym | |
3522 | = find_pc_sect_function (loc->address, loc->section); | |
3523 | if (sym) | |
3524 | { | |
3525 | ui_out_text (uiout, "in "); | |
3526 | ui_out_field_string (uiout, "func", | |
3527 | SYMBOL_PRINT_NAME (sym)); | |
3528 | ui_out_wrap_hint (uiout, wrap_indent); | |
3529 | ui_out_text (uiout, " at "); | |
3530 | } | |
3531 | ui_out_field_string (uiout, "file", b->source_file); | |
3532 | ui_out_text (uiout, ":"); | |
3533 | ||
3534 | if (ui_out_is_mi_like_p (uiout)) | |
3535 | { | |
3536 | struct symtab_and_line sal = find_pc_line (loc->address, 0); | |
3537 | char *fullname = symtab_to_fullname (sal.symtab); | |
3538 | ||
3539 | if (fullname) | |
3540 | ui_out_field_string (uiout, "fullname", fullname); | |
3541 | } | |
3542 | ||
3543 | ui_out_field_int (uiout, "line", b->line_number); | |
3544 | } | |
3545 | else if (!b->loc) | |
3546 | { | |
3547 | ui_out_field_string (uiout, "pending", b->addr_string); | |
3548 | } | |
3549 | else | |
3550 | { | |
3551 | print_address_symbolic (loc->address, stb->stream, demangle, ""); | |
3552 | ui_out_field_stream (uiout, "at", stb); | |
3553 | } | |
3554 | } | |
3555 | ||
c4093a6a | 3556 | /* Print B to gdb_stdout. */ |
c906108c | 3557 | static void |
0d381245 VP |
3558 | print_one_breakpoint_location (struct breakpoint *b, |
3559 | struct bp_location *loc, | |
3560 | int loc_number, | |
a6d9a66e UW |
3561 | struct bp_location **last_loc, |
3562 | int print_address_bits) | |
c906108c | 3563 | { |
52f0bd74 AC |
3564 | struct command_line *l; |
3565 | struct symbol *sym; | |
c4093a6a JM |
3566 | struct ep_type_description |
3567 | { | |
3568 | enum bptype type; | |
3569 | char *description; | |
3570 | }; | |
3571 | static struct ep_type_description bptypes[] = | |
c906108c | 3572 | { |
c5aa993b JM |
3573 | {bp_none, "?deleted?"}, |
3574 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 3575 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
3576 | {bp_until, "until"}, |
3577 | {bp_finish, "finish"}, | |
3578 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 3579 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
3580 | {bp_read_watchpoint, "read watchpoint"}, |
3581 | {bp_access_watchpoint, "acc watchpoint"}, | |
3582 | {bp_longjmp, "longjmp"}, | |
3583 | {bp_longjmp_resume, "longjmp resume"}, | |
3584 | {bp_step_resume, "step resume"}, | |
c5aa993b JM |
3585 | {bp_watchpoint_scope, "watchpoint scope"}, |
3586 | {bp_call_dummy, "call dummy"}, | |
3587 | {bp_shlib_event, "shlib events"}, | |
c4093a6a | 3588 | {bp_thread_event, "thread events"}, |
1900040c | 3589 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 3590 | {bp_longjmp_master, "longjmp master"}, |
ce78b96d | 3591 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 3592 | {bp_tracepoint, "tracepoint"}, |
c5aa993b | 3593 | }; |
c4093a6a | 3594 | |
c2c6d25f | 3595 | static char bpenables[] = "nynny"; |
c906108c | 3596 | char wrap_indent[80]; |
8b93c638 JM |
3597 | struct ui_stream *stb = ui_out_stream_new (uiout); |
3598 | struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb); | |
3b31d625 | 3599 | struct cleanup *bkpt_chain; |
c906108c | 3600 | |
0d381245 VP |
3601 | int header_of_multiple = 0; |
3602 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
3603 | struct value_print_options opts; |
3604 | ||
3605 | get_user_print_options (&opts); | |
0d381245 VP |
3606 | |
3607 | gdb_assert (!loc || loc_number != 0); | |
3608 | /* See comment in print_one_breakpoint concerning | |
3609 | treatment of breakpoints with single disabled | |
3610 | location. */ | |
3611 | if (loc == NULL | |
3612 | && (b->loc != NULL | |
3613 | && (b->loc->next != NULL || !b->loc->enabled))) | |
3614 | header_of_multiple = 1; | |
3615 | if (loc == NULL) | |
3616 | loc = b->loc; | |
3617 | ||
c4093a6a | 3618 | annotate_record (); |
3b31d625 | 3619 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); |
c4093a6a JM |
3620 | |
3621 | /* 1 */ | |
3622 | annotate_field (0); | |
0d381245 VP |
3623 | if (part_of_multiple) |
3624 | { | |
3625 | char *formatted; | |
0c6773c1 | 3626 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
3627 | ui_out_field_string (uiout, "number", formatted); |
3628 | xfree (formatted); | |
3629 | } | |
3630 | else | |
3631 | { | |
3632 | ui_out_field_int (uiout, "number", b->number); | |
3633 | } | |
c4093a6a JM |
3634 | |
3635 | /* 2 */ | |
3636 | annotate_field (1); | |
0d381245 VP |
3637 | if (part_of_multiple) |
3638 | ui_out_field_skip (uiout, "type"); | |
3639 | else | |
3640 | { | |
3641 | if (((int) b->type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
3642 | || ((int) b->type != bptypes[(int) b->type].type)) | |
3643 | internal_error (__FILE__, __LINE__, | |
3644 | _("bptypes table does not describe type #%d."), | |
3645 | (int) b->type); | |
3646 | ui_out_field_string (uiout, "type", bptypes[(int) b->type].description); | |
3647 | } | |
c4093a6a JM |
3648 | |
3649 | /* 3 */ | |
3650 | annotate_field (2); | |
0d381245 VP |
3651 | if (part_of_multiple) |
3652 | ui_out_field_skip (uiout, "disp"); | |
3653 | else | |
2cec12e5 | 3654 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 3655 | |
c4093a6a JM |
3656 | |
3657 | /* 4 */ | |
3658 | annotate_field (3); | |
0d381245 | 3659 | if (part_of_multiple) |
54e52265 | 3660 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 3661 | else |
54e52265 VP |
3662 | ui_out_field_fmt (uiout, "enabled", "%c", |
3663 | bpenables[(int) b->enable_state]); | |
3664 | ui_out_spaces (uiout, 2); | |
0d381245 | 3665 | |
c4093a6a JM |
3666 | |
3667 | /* 5 and 6 */ | |
3668 | strcpy (wrap_indent, " "); | |
79a45b7d | 3669 | if (opts.addressprint) |
75ac9d7b | 3670 | { |
a6d9a66e | 3671 | if (print_address_bits <= 32) |
75ac9d7b MS |
3672 | strcat (wrap_indent, " "); |
3673 | else | |
3674 | strcat (wrap_indent, " "); | |
3675 | } | |
c906108c | 3676 | |
3086aeae | 3677 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 VP |
3678 | { |
3679 | /* Although the print_one can possibly print | |
3680 | all locations, calling it here is not likely | |
3681 | to get any nice result. So, make sure there's | |
3682 | just one location. */ | |
3683 | gdb_assert (b->loc == NULL || b->loc->next == NULL); | |
a6d9a66e | 3684 | b->ops->print_one (b, last_loc); |
0d381245 | 3685 | } |
3086aeae DJ |
3686 | else |
3687 | switch (b->type) | |
3688 | { | |
3689 | case bp_none: | |
3690 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 3691 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 3692 | break; |
c906108c | 3693 | |
3086aeae DJ |
3694 | case bp_watchpoint: |
3695 | case bp_hardware_watchpoint: | |
3696 | case bp_read_watchpoint: | |
3697 | case bp_access_watchpoint: | |
3698 | /* Field 4, the address, is omitted (which makes the columns | |
3699 | not line up too nicely with the headers, but the effect | |
3700 | is relatively readable). */ | |
79a45b7d | 3701 | if (opts.addressprint) |
3086aeae DJ |
3702 | ui_out_field_skip (uiout, "addr"); |
3703 | annotate_field (5); | |
fa8a61dc | 3704 | ui_out_field_string (uiout, "what", b->exp_string); |
3086aeae DJ |
3705 | break; |
3706 | ||
3086aeae DJ |
3707 | case bp_breakpoint: |
3708 | case bp_hardware_breakpoint: | |
3709 | case bp_until: | |
3710 | case bp_finish: | |
3711 | case bp_longjmp: | |
3712 | case bp_longjmp_resume: | |
3713 | case bp_step_resume: | |
3086aeae DJ |
3714 | case bp_watchpoint_scope: |
3715 | case bp_call_dummy: | |
3716 | case bp_shlib_event: | |
3717 | case bp_thread_event: | |
3718 | case bp_overlay_event: | |
0fd8e87f | 3719 | case bp_longjmp_master: |
1042e4c0 | 3720 | case bp_tracepoint: |
79a45b7d | 3721 | if (opts.addressprint) |
3086aeae DJ |
3722 | { |
3723 | annotate_field (4); | |
54e52265 | 3724 | if (header_of_multiple) |
0d381245 | 3725 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 3726 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 3727 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 3728 | else |
0d381245 | 3729 | ui_out_field_core_addr (uiout, "addr", loc->address); |
3086aeae DJ |
3730 | } |
3731 | annotate_field (5); | |
0d381245 VP |
3732 | if (!header_of_multiple) |
3733 | print_breakpoint_location (b, loc, wrap_indent, stb); | |
3734 | if (b->loc) | |
a6d9a66e | 3735 | *last_loc = b->loc; |
3086aeae DJ |
3736 | break; |
3737 | } | |
c906108c | 3738 | |
4a306c9a | 3739 | if (!part_of_multiple) |
c4093a6a | 3740 | { |
4a306c9a JB |
3741 | if (b->thread != -1) |
3742 | { | |
3743 | /* FIXME: This seems to be redundant and lost here; see the | |
3744 | "stop only in" line a little further down. */ | |
3745 | ui_out_text (uiout, " thread "); | |
3746 | ui_out_field_int (uiout, "thread", b->thread); | |
3747 | } | |
3748 | else if (b->task != 0) | |
3749 | { | |
3750 | ui_out_text (uiout, " task "); | |
3751 | ui_out_field_int (uiout, "task", b->task); | |
3752 | } | |
c4093a6a JM |
3753 | } |
3754 | ||
8b93c638 | 3755 | ui_out_text (uiout, "\n"); |
c4093a6a | 3756 | |
0d381245 | 3757 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
3758 | { |
3759 | annotate_field (6); | |
8b93c638 | 3760 | ui_out_text (uiout, "\tstop only in stack frame at "); |
818dd999 AC |
3761 | /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside |
3762 | the frame ID. */ | |
d0a55772 | 3763 | ui_out_field_core_addr (uiout, "frame", b->frame_id.stack_addr); |
8b93c638 | 3764 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
3765 | } |
3766 | ||
0d381245 | 3767 | if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b)) |
c4093a6a | 3768 | { |
f7f9143b JB |
3769 | /* We do not print the condition for Ada exception catchpoints |
3770 | because the condition is an internal implementation detail | |
3771 | that we do not want to expose to the user. */ | |
c4093a6a | 3772 | annotate_field (7); |
1042e4c0 SS |
3773 | if (b->type == bp_tracepoint) |
3774 | ui_out_text (uiout, "\ttrace only if "); | |
3775 | else | |
3776 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 JJ |
3777 | ui_out_field_string (uiout, "cond", b->cond_string); |
3778 | ui_out_text (uiout, "\n"); | |
3779 | } | |
3780 | ||
0d381245 | 3781 | if (!part_of_multiple && b->thread != -1) |
c4093a6a JM |
3782 | { |
3783 | /* FIXME should make an annotation for this */ | |
8b93c638 JM |
3784 | ui_out_text (uiout, "\tstop only in thread "); |
3785 | ui_out_field_int (uiout, "thread", b->thread); | |
3786 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
3787 | } |
3788 | ||
63c715c6 | 3789 | if (!part_of_multiple && b->hit_count) |
c4093a6a JM |
3790 | { |
3791 | /* FIXME should make an annotation for this */ | |
8b93c638 JM |
3792 | if (ep_is_catchpoint (b)) |
3793 | ui_out_text (uiout, "\tcatchpoint"); | |
3794 | else | |
3795 | ui_out_text (uiout, "\tbreakpoint"); | |
3796 | ui_out_text (uiout, " already hit "); | |
3797 | ui_out_field_int (uiout, "times", b->hit_count); | |
3798 | if (b->hit_count == 1) | |
3799 | ui_out_text (uiout, " time\n"); | |
3800 | else | |
3801 | ui_out_text (uiout, " times\n"); | |
c4093a6a JM |
3802 | } |
3803 | ||
fb40c209 AC |
3804 | /* Output the count also if it is zero, but only if this is |
3805 | mi. FIXME: Should have a better test for this. */ | |
9dc5e2a9 | 3806 | if (ui_out_is_mi_like_p (uiout)) |
63c715c6 | 3807 | if (!part_of_multiple && b->hit_count == 0) |
fb40c209 | 3808 | ui_out_field_int (uiout, "times", b->hit_count); |
8b93c638 | 3809 | |
0d381245 | 3810 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
3811 | { |
3812 | annotate_field (8); | |
8b93c638 JM |
3813 | ui_out_text (uiout, "\tignore next "); |
3814 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
3815 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 3816 | } |
059fb39f PM |
3817 | |
3818 | l = b->commands; | |
3819 | if (!part_of_multiple && l) | |
c4093a6a | 3820 | { |
3b31d625 EZ |
3821 | struct cleanup *script_chain; |
3822 | ||
c4093a6a | 3823 | annotate_field (9); |
3b31d625 | 3824 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 3825 | print_command_lines (uiout, l, 4); |
3b31d625 | 3826 | do_cleanups (script_chain); |
c4093a6a | 3827 | } |
d24317b4 | 3828 | |
1042e4c0 SS |
3829 | if (!part_of_multiple && b->pass_count) |
3830 | { | |
3831 | annotate_field (10); | |
3832 | ui_out_text (uiout, "\tpass count "); | |
3833 | ui_out_field_int (uiout, "pass", b->pass_count); | |
3834 | ui_out_text (uiout, " \n"); | |
3835 | } | |
3836 | ||
3837 | if (!part_of_multiple && b->step_count) | |
3838 | { | |
3839 | annotate_field (11); | |
3840 | ui_out_text (uiout, "\tstep count "); | |
3841 | ui_out_field_int (uiout, "step", b->step_count); | |
3842 | ui_out_text (uiout, " \n"); | |
3843 | } | |
3844 | ||
3845 | if (!part_of_multiple && b->actions) | |
3846 | { | |
3847 | struct action_line *action; | |
3848 | annotate_field (12); | |
3849 | for (action = b->actions; action; action = action->next) | |
3850 | { | |
3851 | ui_out_text (uiout, " A\t"); | |
3852 | ui_out_text (uiout, action->action); | |
3853 | ui_out_text (uiout, "\n"); | |
3854 | } | |
3855 | } | |
3856 | ||
d24317b4 VP |
3857 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
3858 | { | |
3859 | if (b->addr_string) | |
3860 | ui_out_field_string (uiout, "original-location", b->addr_string); | |
3861 | else if (b->exp_string) | |
3862 | ui_out_field_string (uiout, "original-location", b->exp_string); | |
3863 | } | |
3864 | ||
3b31d625 | 3865 | do_cleanups (bkpt_chain); |
8b93c638 | 3866 | do_cleanups (old_chain); |
c4093a6a | 3867 | } |
c5aa993b | 3868 | |
0d381245 VP |
3869 | static void |
3870 | print_one_breakpoint (struct breakpoint *b, | |
a6d9a66e | 3871 | struct bp_location **last_loc, int print_address_bits) |
0d381245 | 3872 | { |
a6d9a66e | 3873 | print_one_breakpoint_location (b, NULL, 0, last_loc, print_address_bits); |
0d381245 VP |
3874 | |
3875 | /* If this breakpoint has custom print function, | |
3876 | it's already printed. Otherwise, print individual | |
3877 | locations, if any. */ | |
3878 | if (b->ops == NULL || b->ops->print_one == NULL) | |
3879 | { | |
3880 | /* If breakpoint has a single location that is | |
3881 | disabled, we print it as if it had | |
3882 | several locations, since otherwise it's hard to | |
3883 | represent "breakpoint enabled, location disabled" | |
a5606eee VP |
3884 | situation. |
3885 | Note that while hardware watchpoints have | |
3886 | several locations internally, that's no a property | |
3887 | exposed to user. */ | |
0d381245 | 3888 | if (b->loc |
a5606eee | 3889 | && !is_hardware_watchpoint (b) |
0d381245 | 3890 | && (b->loc->next || !b->loc->enabled) |
a5606eee | 3891 | && !ui_out_is_mi_like_p (uiout)) |
0d381245 VP |
3892 | { |
3893 | struct bp_location *loc; | |
3894 | int n = 1; | |
3895 | for (loc = b->loc; loc; loc = loc->next, ++n) | |
a6d9a66e UW |
3896 | print_one_breakpoint_location (b, loc, n, last_loc, |
3897 | print_address_bits); | |
0d381245 VP |
3898 | } |
3899 | } | |
3900 | } | |
3901 | ||
a6d9a66e UW |
3902 | static int |
3903 | breakpoint_address_bits (struct breakpoint *b) | |
3904 | { | |
3905 | int print_address_bits = 0; | |
3906 | struct bp_location *loc; | |
3907 | ||
3908 | for (loc = b->loc; loc; loc = loc->next) | |
3909 | { | |
3910 | int addr_bit = gdbarch_addr_bit (b->gdbarch); | |
3911 | if (addr_bit > print_address_bits) | |
3912 | print_address_bits = addr_bit; | |
3913 | } | |
3914 | ||
3915 | return print_address_bits; | |
3916 | } | |
0d381245 | 3917 | |
c4093a6a JM |
3918 | struct captured_breakpoint_query_args |
3919 | { | |
3920 | int bnum; | |
3921 | }; | |
c5aa993b | 3922 | |
c4093a6a | 3923 | static int |
2b65245e | 3924 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
3925 | { |
3926 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 3927 | struct breakpoint *b; |
a6d9a66e | 3928 | struct bp_location *dummy_loc = NULL; |
c4093a6a JM |
3929 | ALL_BREAKPOINTS (b) |
3930 | { | |
3931 | if (args->bnum == b->number) | |
c5aa993b | 3932 | { |
a6d9a66e UW |
3933 | int print_address_bits = breakpoint_address_bits (b); |
3934 | print_one_breakpoint (b, &dummy_loc, print_address_bits); | |
c4093a6a | 3935 | return GDB_RC_OK; |
c5aa993b | 3936 | } |
c4093a6a JM |
3937 | } |
3938 | return GDB_RC_NONE; | |
3939 | } | |
c5aa993b | 3940 | |
c4093a6a | 3941 | enum gdb_rc |
ce43223b | 3942 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, char **error_message) |
c4093a6a JM |
3943 | { |
3944 | struct captured_breakpoint_query_args args; | |
3945 | args.bnum = bnum; | |
3946 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
3947 | an error. */ | |
b0b13bb4 DJ |
3948 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
3949 | error_message, RETURN_MASK_ALL) < 0) | |
3950 | return GDB_RC_FAIL; | |
3951 | else | |
3952 | return GDB_RC_OK; | |
c4093a6a | 3953 | } |
c5aa993b | 3954 | |
7f3b0473 AC |
3955 | /* Return non-zero if B is user settable (breakpoints, watchpoints, |
3956 | catchpoints, et.al.). */ | |
3957 | ||
3958 | static int | |
3959 | user_settable_breakpoint (const struct breakpoint *b) | |
3960 | { | |
3961 | return (b->type == bp_breakpoint | |
ce78b96d | 3962 | || b->type == bp_catchpoint |
7f3b0473 | 3963 | || b->type == bp_hardware_breakpoint |
1042e4c0 | 3964 | || b->type == bp_tracepoint |
7f3b0473 AC |
3965 | || b->type == bp_watchpoint |
3966 | || b->type == bp_read_watchpoint | |
3967 | || b->type == bp_access_watchpoint | |
3968 | || b->type == bp_hardware_watchpoint); | |
3969 | } | |
3970 | ||
3971 | /* Print information on user settable breakpoint (watchpoint, etc) | |
3972 | number BNUM. If BNUM is -1 print all user settable breakpoints. | |
3973 | If ALLFLAG is non-zero, include non- user settable breakpoints. */ | |
c906108c | 3974 | |
c4093a6a | 3975 | static void |
fba45db2 | 3976 | breakpoint_1 (int bnum, int allflag) |
c4093a6a | 3977 | { |
52f0bd74 | 3978 | struct breakpoint *b; |
a6d9a66e | 3979 | struct bp_location *last_loc = NULL; |
7f3b0473 | 3980 | int nr_printable_breakpoints; |
3b31d625 | 3981 | struct cleanup *bkpttbl_chain; |
79a45b7d | 3982 | struct value_print_options opts; |
a6d9a66e | 3983 | int print_address_bits = 0; |
c4093a6a | 3984 | |
79a45b7d TT |
3985 | get_user_print_options (&opts); |
3986 | ||
a6d9a66e UW |
3987 | /* Compute the number of rows in the table, as well as the |
3988 | size required for address fields. */ | |
7f3b0473 AC |
3989 | nr_printable_breakpoints = 0; |
3990 | ALL_BREAKPOINTS (b) | |
3991 | if (bnum == -1 | |
3992 | || bnum == b->number) | |
3993 | { | |
3994 | if (allflag || user_settable_breakpoint (b)) | |
a6d9a66e UW |
3995 | { |
3996 | int addr_bit = breakpoint_address_bits (b); | |
3997 | if (addr_bit > print_address_bits) | |
3998 | print_address_bits = addr_bit; | |
3999 | ||
4000 | nr_printable_breakpoints++; | |
4001 | } | |
7f3b0473 AC |
4002 | } |
4003 | ||
79a45b7d | 4004 | if (opts.addressprint) |
3b31d625 EZ |
4005 | bkpttbl_chain |
4006 | = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints, | |
4007 | "BreakpointTable"); | |
8b93c638 | 4008 | else |
3b31d625 EZ |
4009 | bkpttbl_chain |
4010 | = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints, | |
4011 | "BreakpointTable"); | |
8b93c638 | 4012 | |
7f3b0473 | 4013 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
4014 | annotate_breakpoints_headers (); |
4015 | if (nr_printable_breakpoints > 0) | |
4016 | annotate_field (0); | |
0d381245 | 4017 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
4018 | if (nr_printable_breakpoints > 0) |
4019 | annotate_field (1); | |
4020 | ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */ | |
4021 | if (nr_printable_breakpoints > 0) | |
4022 | annotate_field (2); | |
4023 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ | |
4024 | if (nr_printable_breakpoints > 0) | |
4025 | annotate_field (3); | |
54e52265 | 4026 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 4027 | if (opts.addressprint) |
7f3b0473 | 4028 | { |
d7faa9e7 AC |
4029 | if (nr_printable_breakpoints > 0) |
4030 | annotate_field (4); | |
a6d9a66e | 4031 | if (print_address_bits <= 32) |
b25959ec | 4032 | ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */ |
7f3b0473 | 4033 | else |
b25959ec | 4034 | ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */ |
7f3b0473 | 4035 | } |
d7faa9e7 AC |
4036 | if (nr_printable_breakpoints > 0) |
4037 | annotate_field (5); | |
4038 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
4039 | ui_out_table_body (uiout); | |
4040 | if (nr_printable_breakpoints > 0) | |
4041 | annotate_breakpoints_table (); | |
7f3b0473 | 4042 | |
c4093a6a JM |
4043 | ALL_BREAKPOINTS (b) |
4044 | if (bnum == -1 | |
4045 | || bnum == b->number) | |
4046 | { | |
4047 | /* We only print out user settable breakpoints unless the | |
4048 | allflag is set. */ | |
7f3b0473 | 4049 | if (allflag || user_settable_breakpoint (b)) |
a6d9a66e | 4050 | print_one_breakpoint (b, &last_loc, print_address_bits); |
c4093a6a JM |
4051 | } |
4052 | ||
3b31d625 | 4053 | do_cleanups (bkpttbl_chain); |
698384cd | 4054 | |
7f3b0473 | 4055 | if (nr_printable_breakpoints == 0) |
c906108c | 4056 | { |
8b93c638 JM |
4057 | if (bnum == -1) |
4058 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); | |
4059 | else | |
4060 | ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n", | |
4061 | bnum); | |
c906108c SS |
4062 | } |
4063 | else | |
c4093a6a | 4064 | { |
a6d9a66e UW |
4065 | if (last_loc && !server_command) |
4066 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 4067 | } |
c906108c | 4068 | |
c4093a6a JM |
4069 | /* FIXME? Should this be moved up so that it is only called when |
4070 | there have been breakpoints? */ | |
c906108c SS |
4071 | annotate_breakpoints_table_end (); |
4072 | } | |
4073 | ||
c906108c | 4074 | static void |
fba45db2 | 4075 | breakpoints_info (char *bnum_exp, int from_tty) |
c906108c SS |
4076 | { |
4077 | int bnum = -1; | |
4078 | ||
4079 | if (bnum_exp) | |
bb518678 | 4080 | bnum = parse_and_eval_long (bnum_exp); |
c906108c SS |
4081 | |
4082 | breakpoint_1 (bnum, 0); | |
4083 | } | |
4084 | ||
7a292a7a | 4085 | static void |
fba45db2 | 4086 | maintenance_info_breakpoints (char *bnum_exp, int from_tty) |
c906108c SS |
4087 | { |
4088 | int bnum = -1; | |
4089 | ||
4090 | if (bnum_exp) | |
bb518678 | 4091 | bnum = parse_and_eval_long (bnum_exp); |
c906108c SS |
4092 | |
4093 | breakpoint_1 (bnum, 1); | |
4094 | } | |
4095 | ||
0d381245 | 4096 | static int |
714835d5 UW |
4097 | breakpoint_has_pc (struct breakpoint *b, |
4098 | CORE_ADDR pc, struct obj_section *section) | |
0d381245 VP |
4099 | { |
4100 | struct bp_location *bl = b->loc; | |
4101 | for (; bl; bl = bl->next) | |
4102 | { | |
4103 | if (bl->address == pc | |
4104 | && (!overlay_debugging || bl->section == section)) | |
4105 | return 1; | |
4106 | } | |
4107 | return 0; | |
4108 | } | |
4109 | ||
c906108c SS |
4110 | /* Print a message describing any breakpoints set at PC. */ |
4111 | ||
4112 | static void | |
714835d5 UW |
4113 | describe_other_breakpoints (CORE_ADDR pc, struct obj_section *section, |
4114 | int thread) | |
c906108c | 4115 | { |
52f0bd74 AC |
4116 | int others = 0; |
4117 | struct breakpoint *b; | |
c906108c SS |
4118 | |
4119 | ALL_BREAKPOINTS (b) | |
0d381245 | 4120 | others += breakpoint_has_pc (b, pc, section); |
c906108c SS |
4121 | if (others > 0) |
4122 | { | |
a3f17187 AC |
4123 | if (others == 1) |
4124 | printf_filtered (_("Note: breakpoint ")); | |
4125 | else /* if (others == ???) */ | |
4126 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 4127 | ALL_BREAKPOINTS (b) |
0d381245 VP |
4128 | if (breakpoint_has_pc (b, pc, section)) |
4129 | { | |
4130 | others--; | |
4131 | printf_filtered ("%d", b->number); | |
4132 | if (b->thread == -1 && thread != -1) | |
4133 | printf_filtered (" (all threads)"); | |
4134 | else if (b->thread != -1) | |
4135 | printf_filtered (" (thread %d)", b->thread); | |
4136 | printf_filtered ("%s%s ", | |
059fb39f PM |
4137 | ((b->enable_state == bp_disabled |
4138 | || b->enable_state == bp_call_disabled) | |
0d381245 VP |
4139 | ? " (disabled)" |
4140 | : b->enable_state == bp_permanent | |
4141 | ? " (permanent)" | |
4142 | : ""), | |
4143 | (others > 1) ? "," | |
4144 | : ((others == 1) ? " and" : "")); | |
4145 | } | |
a3f17187 | 4146 | printf_filtered (_("also set at pc ")); |
ed49a04f | 4147 | fputs_filtered (paddress (pc), gdb_stdout); |
c906108c SS |
4148 | printf_filtered (".\n"); |
4149 | } | |
4150 | } | |
4151 | \f | |
4152 | /* Set the default place to put a breakpoint | |
4153 | for the `break' command with no arguments. */ | |
4154 | ||
4155 | void | |
fba45db2 KB |
4156 | set_default_breakpoint (int valid, CORE_ADDR addr, struct symtab *symtab, |
4157 | int line) | |
c906108c SS |
4158 | { |
4159 | default_breakpoint_valid = valid; | |
4160 | default_breakpoint_address = addr; | |
4161 | default_breakpoint_symtab = symtab; | |
4162 | default_breakpoint_line = line; | |
4163 | } | |
4164 | ||
e4f237da KB |
4165 | /* Return true iff it is meaningful to use the address member of |
4166 | BPT. For some breakpoint types, the address member is irrelevant | |
4167 | and it makes no sense to attempt to compare it to other addresses | |
4168 | (or use it for any other purpose either). | |
4169 | ||
4170 | More specifically, each of the following breakpoint types will always | |
4171 | have a zero valued address and we don't want check_duplicates() to mark | |
4172 | breakpoints of any of these types to be a duplicate of an actual | |
4173 | breakpoint at address zero: | |
4174 | ||
4175 | bp_watchpoint | |
4176 | bp_hardware_watchpoint | |
4177 | bp_read_watchpoint | |
4178 | bp_access_watchpoint | |
fe798b75 | 4179 | bp_catchpoint */ |
e4f237da KB |
4180 | |
4181 | static int | |
4182 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
4183 | { | |
4184 | enum bptype type = bpt->type; | |
4185 | ||
4186 | return (type != bp_watchpoint | |
4187 | && type != bp_hardware_watchpoint | |
4188 | && type != bp_read_watchpoint | |
4189 | && type != bp_access_watchpoint | |
fe798b75 | 4190 | && type != bp_catchpoint); |
e4f237da KB |
4191 | } |
4192 | ||
9f60f21b | 4193 | /* Rescan breakpoints at the same address and section as BPT, |
c906108c | 4194 | marking the first one as "first" and any others as "duplicates". |
c2c6d25f | 4195 | This is so that the bpt instruction is only inserted once. |
9f60f21b JB |
4196 | If we have a permanent breakpoint at the same place as BPT, make |
4197 | that one the official one, and the rest as duplicates. */ | |
c906108c SS |
4198 | |
4199 | static void | |
714835d5 | 4200 | check_duplicates_for (CORE_ADDR address, struct obj_section *section) |
c906108c | 4201 | { |
075f6582 | 4202 | struct bp_location *b; |
52f0bd74 | 4203 | int count = 0; |
075f6582 | 4204 | struct bp_location *perm_bp = 0; |
c906108c | 4205 | |
075f6582 DJ |
4206 | ALL_BP_LOCATIONS (b) |
4207 | if (b->owner->enable_state != bp_disabled | |
075f6582 | 4208 | && b->owner->enable_state != bp_call_disabled |
0d381245 VP |
4209 | && b->enabled |
4210 | && !b->shlib_disabled | |
075f6582 DJ |
4211 | && b->address == address /* address / overlay match */ |
4212 | && (!overlay_debugging || b->section == section) | |
4213 | && breakpoint_address_is_meaningful (b->owner)) | |
c5aa993b | 4214 | { |
c2c6d25f | 4215 | /* Have we found a permanent breakpoint? */ |
075f6582 | 4216 | if (b->owner->enable_state == bp_permanent) |
c2c6d25f JM |
4217 | { |
4218 | perm_bp = b; | |
4219 | break; | |
4220 | } | |
4221 | ||
c5aa993b | 4222 | count++; |
075f6582 | 4223 | b->duplicate = count > 1; |
c5aa993b | 4224 | } |
c2c6d25f JM |
4225 | |
4226 | /* If we found a permanent breakpoint at this address, go over the | |
aae64587 PA |
4227 | list again and declare all the other breakpoints there (except |
4228 | other permanent breakpoints) to be the duplicates. */ | |
c2c6d25f JM |
4229 | if (perm_bp) |
4230 | { | |
075f6582 | 4231 | perm_bp->duplicate = 0; |
c2c6d25f JM |
4232 | |
4233 | /* Permanent breakpoint should always be inserted. */ | |
075f6582 | 4234 | if (! perm_bp->inserted) |
8e65ff28 | 4235 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 AC |
4236 | _("allegedly permanent breakpoint is not " |
4237 | "actually inserted")); | |
c2c6d25f | 4238 | |
075f6582 | 4239 | ALL_BP_LOCATIONS (b) |
c2c6d25f JM |
4240 | if (b != perm_bp) |
4241 | { | |
aae64587 PA |
4242 | if (b->owner->enable_state != bp_permanent |
4243 | && b->owner->enable_state != bp_disabled | |
075f6582 | 4244 | && b->owner->enable_state != bp_call_disabled |
0d381245 | 4245 | && b->enabled && !b->shlib_disabled |
075f6582 DJ |
4246 | && b->address == address /* address / overlay match */ |
4247 | && (!overlay_debugging || b->section == section) | |
4248 | && breakpoint_address_is_meaningful (b->owner)) | |
4249 | { | |
4250 | if (b->inserted) | |
4251 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 AC |
4252 | _("another breakpoint was inserted on top of " |
4253 | "a permanent breakpoint")); | |
075f6582 DJ |
4254 | |
4255 | b->duplicate = 1; | |
4256 | } | |
c2c6d25f JM |
4257 | } |
4258 | } | |
c906108c SS |
4259 | } |
4260 | ||
0d381245 VP |
4261 | static void |
4262 | check_duplicates (struct breakpoint *bpt) | |
4263 | { | |
4264 | struct bp_location *bl = bpt->loc; | |
4265 | ||
4266 | if (! breakpoint_address_is_meaningful (bpt)) | |
4267 | return; | |
4268 | ||
4269 | for (; bl; bl = bl->next) | |
4270 | check_duplicates_for (bl->address, bl->section); | |
4271 | } | |
4272 | ||
76897487 KB |
4273 | static void |
4274 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
4275 | int bnum, int have_bnum) | |
4276 | { | |
4277 | char astr1[40]; | |
4278 | char astr2[40]; | |
4279 | ||
bb599908 PH |
4280 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
4281 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 4282 | if (have_bnum) |
8a3fe4f8 | 4283 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
4284 | bnum, astr1, astr2); |
4285 | else | |
8a3fe4f8 | 4286 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
4287 | } |
4288 | ||
4289 | /* Adjust a breakpoint's address to account for architectural constraints | |
4290 | on breakpoint placement. Return the adjusted address. Note: Very | |
4291 | few targets require this kind of adjustment. For most targets, | |
4292 | this function is simply the identity function. */ | |
4293 | ||
4294 | static CORE_ADDR | |
a6d9a66e UW |
4295 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
4296 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 4297 | { |
a6d9a66e | 4298 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
4299 | { |
4300 | /* Very few targets need any kind of breakpoint adjustment. */ | |
4301 | return bpaddr; | |
4302 | } | |
88f7da05 KB |
4303 | else if (bptype == bp_watchpoint |
4304 | || bptype == bp_hardware_watchpoint | |
4305 | || bptype == bp_read_watchpoint | |
4306 | || bptype == bp_access_watchpoint | |
fe798b75 | 4307 | || bptype == bp_catchpoint) |
88f7da05 KB |
4308 | { |
4309 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
4310 | have their addresses modified. */ | |
4311 | return bpaddr; | |
4312 | } | |
76897487 KB |
4313 | else |
4314 | { | |
4315 | CORE_ADDR adjusted_bpaddr; | |
4316 | ||
4317 | /* Some targets have architectural constraints on the placement | |
4318 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 4319 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
4320 | |
4321 | /* An adjusted breakpoint address can significantly alter | |
4322 | a user's expectations. Print a warning if an adjustment | |
4323 | is required. */ | |
4324 | if (adjusted_bpaddr != bpaddr) | |
4325 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
4326 | ||
4327 | return adjusted_bpaddr; | |
4328 | } | |
4329 | } | |
4330 | ||
7cc221ef DJ |
4331 | /* Allocate a struct bp_location. */ |
4332 | ||
26bb91f3 | 4333 | static struct bp_location * |
39d61571 | 4334 | allocate_bp_location (struct breakpoint *bpt) |
7cc221ef DJ |
4335 | { |
4336 | struct bp_location *loc, *loc_p; | |
4337 | ||
4338 | loc = xmalloc (sizeof (struct bp_location)); | |
4339 | memset (loc, 0, sizeof (*loc)); | |
4340 | ||
e049a4b5 | 4341 | loc->owner = bpt; |
511a6cd4 | 4342 | loc->cond = NULL; |
0d381245 VP |
4343 | loc->shlib_disabled = 0; |
4344 | loc->enabled = 1; | |
e049a4b5 | 4345 | |
39d61571 | 4346 | switch (bpt->type) |
e049a4b5 DJ |
4347 | { |
4348 | case bp_breakpoint: | |
1042e4c0 | 4349 | case bp_tracepoint: |
e049a4b5 DJ |
4350 | case bp_until: |
4351 | case bp_finish: | |
4352 | case bp_longjmp: | |
4353 | case bp_longjmp_resume: | |
4354 | case bp_step_resume: | |
e049a4b5 DJ |
4355 | case bp_watchpoint_scope: |
4356 | case bp_call_dummy: | |
4357 | case bp_shlib_event: | |
4358 | case bp_thread_event: | |
4359 | case bp_overlay_event: | |
0fd8e87f | 4360 | case bp_longjmp_master: |
e049a4b5 DJ |
4361 | loc->loc_type = bp_loc_software_breakpoint; |
4362 | break; | |
4363 | case bp_hardware_breakpoint: | |
4364 | loc->loc_type = bp_loc_hardware_breakpoint; | |
4365 | break; | |
4366 | case bp_hardware_watchpoint: | |
4367 | case bp_read_watchpoint: | |
4368 | case bp_access_watchpoint: | |
4369 | loc->loc_type = bp_loc_hardware_watchpoint; | |
4370 | break; | |
4371 | case bp_watchpoint: | |
ce78b96d | 4372 | case bp_catchpoint: |
e049a4b5 DJ |
4373 | loc->loc_type = bp_loc_other; |
4374 | break; | |
4375 | default: | |
e2e0b3e5 | 4376 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
4377 | } |
4378 | ||
7cc221ef DJ |
4379 | return loc; |
4380 | } | |
4381 | ||
fe3f5fa8 VP |
4382 | static void free_bp_location (struct bp_location *loc) |
4383 | { | |
4384 | if (loc->cond) | |
4385 | xfree (loc->cond); | |
74960c60 VP |
4386 | |
4387 | if (loc->function_name) | |
4388 | xfree (loc->function_name); | |
4389 | ||
fe3f5fa8 VP |
4390 | xfree (loc); |
4391 | } | |
4392 | ||
0d381245 VP |
4393 | /* Helper to set_raw_breakpoint below. Creates a breakpoint |
4394 | that has type BPTYPE and has no locations as yet. */ | |
c906108c | 4395 | |
c40e75cd | 4396 | static struct breakpoint * |
a6d9a66e UW |
4397 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, |
4398 | enum bptype bptype) | |
c906108c | 4399 | { |
52f0bd74 | 4400 | struct breakpoint *b, *b1; |
c906108c SS |
4401 | |
4402 | b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint)); | |
4403 | memset (b, 0, sizeof (*b)); | |
2219d63c | 4404 | |
4d28f7a8 | 4405 | b->type = bptype; |
a6d9a66e | 4406 | b->gdbarch = gdbarch; |
c906108c SS |
4407 | b->language = current_language->la_language; |
4408 | b->input_radix = input_radix; | |
4409 | b->thread = -1; | |
b5de0fa7 | 4410 | b->enable_state = bp_enabled; |
c906108c SS |
4411 | b->next = 0; |
4412 | b->silent = 0; | |
4413 | b->ignore_count = 0; | |
4414 | b->commands = NULL; | |
818dd999 | 4415 | b->frame_id = null_frame_id; |
3a3e9ee3 | 4416 | b->forked_inferior_pid = null_ptid; |
c906108c | 4417 | b->exec_pathname = NULL; |
3086aeae | 4418 | b->ops = NULL; |
0d381245 | 4419 | b->condition_not_parsed = 0; |
c906108c SS |
4420 | |
4421 | /* Add this breakpoint to the end of the chain | |
4422 | so that a list of breakpoints will come out in order | |
4423 | of increasing numbers. */ | |
4424 | ||
4425 | b1 = breakpoint_chain; | |
4426 | if (b1 == 0) | |
4427 | breakpoint_chain = b; | |
4428 | else | |
4429 | { | |
4430 | while (b1->next) | |
4431 | b1 = b1->next; | |
4432 | b1->next = b; | |
4433 | } | |
0d381245 VP |
4434 | return b; |
4435 | } | |
4436 | ||
4437 | /* Initialize loc->function_name. */ | |
4438 | static void | |
4439 | set_breakpoint_location_function (struct bp_location *loc) | |
4440 | { | |
4441 | if (loc->owner->type == bp_breakpoint | |
1042e4c0 SS |
4442 | || loc->owner->type == bp_hardware_breakpoint |
4443 | || loc->owner->type == bp_tracepoint) | |
0d381245 VP |
4444 | { |
4445 | find_pc_partial_function (loc->address, &(loc->function_name), | |
4446 | NULL, NULL); | |
4447 | if (loc->function_name) | |
4448 | loc->function_name = xstrdup (loc->function_name); | |
4449 | } | |
4450 | } | |
4451 | ||
a6d9a66e UW |
4452 | /* Attempt to determine architecture of location identified by SAL. */ |
4453 | static struct gdbarch * | |
4454 | get_sal_arch (struct symtab_and_line sal) | |
4455 | { | |
4456 | if (sal.section) | |
4457 | return get_objfile_arch (sal.section->objfile); | |
4458 | if (sal.symtab) | |
4459 | return get_objfile_arch (sal.symtab->objfile); | |
4460 | ||
4461 | return NULL; | |
4462 | } | |
4463 | ||
0d381245 VP |
4464 | /* set_raw_breakpoint is a low level routine for allocating and |
4465 | partially initializing a breakpoint of type BPTYPE. The newly | |
4466 | created breakpoint's address, section, source file name, and line | |
4467 | number are provided by SAL. The newly created and partially | |
4468 | initialized breakpoint is added to the breakpoint chain and | |
4469 | is also returned as the value of this function. | |
4470 | ||
4471 | It is expected that the caller will complete the initialization of | |
4472 | the newly created breakpoint struct as well as output any status | |
4473 | information regarding the creation of a new breakpoint. In | |
4474 | particular, set_raw_breakpoint does NOT set the breakpoint | |
4475 | number! Care should be taken to not allow an error to occur | |
4476 | prior to completing the initialization of the breakpoint. If this | |
4477 | should happen, a bogus breakpoint will be left on the chain. */ | |
4478 | ||
a6d9a66e UW |
4479 | static struct breakpoint * |
4480 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
4481 | struct symtab_and_line sal, enum bptype bptype) | |
0d381245 | 4482 | { |
a6d9a66e | 4483 | struct breakpoint *b = set_raw_breakpoint_without_location (gdbarch, bptype); |
0d381245 | 4484 | CORE_ADDR adjusted_address; |
a6d9a66e UW |
4485 | struct gdbarch *loc_gdbarch; |
4486 | ||
4487 | loc_gdbarch = get_sal_arch (sal); | |
4488 | if (!loc_gdbarch) | |
4489 | loc_gdbarch = b->gdbarch; | |
0d381245 VP |
4490 | |
4491 | /* Adjust the breakpoint's address prior to allocating a location. | |
4492 | Once we call allocate_bp_location(), that mostly uninitialized | |
4493 | location will be placed on the location chain. Adjustment of the | |
8defab1a | 4494 | breakpoint may cause target_read_memory() to be called and we do |
0d381245 VP |
4495 | not want its scan of the location chain to find a breakpoint and |
4496 | location that's only been partially initialized. */ | |
a6d9a66e | 4497 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, sal.pc, b->type); |
0d381245 | 4498 | |
39d61571 | 4499 | b->loc = allocate_bp_location (b); |
a6d9a66e | 4500 | b->loc->gdbarch = loc_gdbarch; |
0d381245 VP |
4501 | b->loc->requested_address = sal.pc; |
4502 | b->loc->address = adjusted_address; | |
4503 | ||
4504 | if (sal.symtab == NULL) | |
4505 | b->source_file = NULL; | |
4506 | else | |
1b36a34b | 4507 | b->source_file = xstrdup (sal.symtab->filename); |
0d381245 VP |
4508 | b->loc->section = sal.section; |
4509 | b->line_number = sal.line; | |
4510 | ||
4511 | set_breakpoint_location_function (b->loc); | |
c906108c | 4512 | |
c906108c SS |
4513 | breakpoints_changed (); |
4514 | ||
4515 | return b; | |
4516 | } | |
4517 | ||
c2c6d25f JM |
4518 | |
4519 | /* Note that the breakpoint object B describes a permanent breakpoint | |
4520 | instruction, hard-wired into the inferior's code. */ | |
4521 | void | |
4522 | make_breakpoint_permanent (struct breakpoint *b) | |
4523 | { | |
0d381245 | 4524 | struct bp_location *bl; |
b5de0fa7 | 4525 | b->enable_state = bp_permanent; |
c2c6d25f | 4526 | |
0d381245 VP |
4527 | /* By definition, permanent breakpoints are already present in the code. |
4528 | Mark all locations as inserted. For now, make_breakpoint_permanent | |
4529 | is called in just one place, so it's hard to say if it's reasonable | |
4530 | to have permanent breakpoint with multiple locations or not, | |
4531 | but it's easy to implmement. */ | |
4532 | for (bl = b->loc; bl; bl = bl->next) | |
4533 | bl->inserted = 1; | |
c2c6d25f JM |
4534 | } |
4535 | ||
53a5351d | 4536 | /* Call this routine when stepping and nexting to enable a breakpoint |
0fd8e87f | 4537 | if we do a longjmp() in THREAD. When we hit that breakpoint, call |
c906108c SS |
4538 | set_longjmp_resume_breakpoint() to figure out where we are going. */ |
4539 | ||
4540 | void | |
0fd8e87f | 4541 | set_longjmp_breakpoint (int thread) |
c906108c | 4542 | { |
0fd8e87f UW |
4543 | struct breakpoint *b, *temp; |
4544 | ||
4545 | /* To avoid having to rescan all objfile symbols at every step, | |
4546 | we maintain a list of continually-inserted but always disabled | |
4547 | longjmp "master" breakpoints. Here, we simply create momentary | |
4548 | clones of those and enable them for the requested thread. */ | |
4549 | ALL_BREAKPOINTS_SAFE (b, temp) | |
4550 | if (b->type == bp_longjmp_master) | |
4551 | { | |
4552 | struct breakpoint *clone = clone_momentary_breakpoint (b); | |
4553 | clone->type = bp_longjmp; | |
4554 | clone->thread = thread; | |
4555 | } | |
c906108c SS |
4556 | } |
4557 | ||
611c83ae | 4558 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 4559 | void |
611c83ae | 4560 | delete_longjmp_breakpoint (int thread) |
c906108c | 4561 | { |
611c83ae | 4562 | struct breakpoint *b, *temp; |
c906108c | 4563 | |
611c83ae PA |
4564 | ALL_BREAKPOINTS_SAFE (b, temp) |
4565 | if (b->type == bp_longjmp) | |
4566 | { | |
4567 | if (b->thread == thread) | |
4568 | delete_breakpoint (b); | |
4569 | } | |
c906108c SS |
4570 | } |
4571 | ||
1900040c MS |
4572 | void |
4573 | enable_overlay_breakpoints (void) | |
4574 | { | |
52f0bd74 | 4575 | struct breakpoint *b; |
1900040c MS |
4576 | |
4577 | ALL_BREAKPOINTS (b) | |
4578 | if (b->type == bp_overlay_event) | |
4579 | { | |
4580 | b->enable_state = bp_enabled; | |
b60e7edf | 4581 | update_global_location_list (1); |
c02f5703 | 4582 | overlay_events_enabled = 1; |
1900040c MS |
4583 | } |
4584 | } | |
4585 | ||
4586 | void | |
4587 | disable_overlay_breakpoints (void) | |
4588 | { | |
52f0bd74 | 4589 | struct breakpoint *b; |
1900040c MS |
4590 | |
4591 | ALL_BREAKPOINTS (b) | |
4592 | if (b->type == bp_overlay_event) | |
4593 | { | |
4594 | b->enable_state = bp_disabled; | |
b60e7edf | 4595 | update_global_location_list (0); |
c02f5703 | 4596 | overlay_events_enabled = 0; |
1900040c MS |
4597 | } |
4598 | } | |
4599 | ||
c4093a6a | 4600 | struct breakpoint * |
a6d9a66e | 4601 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
4602 | { |
4603 | struct breakpoint *b; | |
c4093a6a | 4604 | |
a6d9a66e | 4605 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event); |
c4093a6a | 4606 | |
b5de0fa7 | 4607 | b->enable_state = bp_enabled; |
c4093a6a | 4608 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
b435e160 | 4609 | b->addr_string = xstrprintf ("*0x%s", paddr (b->loc->address)); |
c4093a6a | 4610 | |
b60e7edf | 4611 | update_global_location_list_nothrow (1); |
74960c60 | 4612 | |
c4093a6a JM |
4613 | return b; |
4614 | } | |
4615 | ||
4616 | void | |
4617 | remove_thread_event_breakpoints (void) | |
4618 | { | |
4619 | struct breakpoint *b, *temp; | |
4620 | ||
4621 | ALL_BREAKPOINTS_SAFE (b, temp) | |
4622 | if (b->type == bp_thread_event) | |
4623 | delete_breakpoint (b); | |
4624 | } | |
4625 | ||
0101ce28 JJ |
4626 | struct captured_parse_breakpoint_args |
4627 | { | |
4628 | char **arg_p; | |
4629 | struct symtabs_and_lines *sals_p; | |
4630 | char ***addr_string_p; | |
4631 | int *not_found_ptr; | |
4632 | }; | |
4633 | ||
4634 | struct lang_and_radix | |
4635 | { | |
4636 | enum language lang; | |
4637 | int radix; | |
4638 | }; | |
4639 | ||
0101ce28 | 4640 | |
cae688ec JJ |
4641 | void |
4642 | remove_solib_event_breakpoints (void) | |
4643 | { | |
4644 | struct breakpoint *b, *temp; | |
4645 | ||
4646 | ALL_BREAKPOINTS_SAFE (b, temp) | |
4647 | if (b->type == bp_shlib_event) | |
4648 | delete_breakpoint (b); | |
4649 | } | |
4650 | ||
4651 | struct breakpoint * | |
a6d9a66e | 4652 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
cae688ec JJ |
4653 | { |
4654 | struct breakpoint *b; | |
4655 | ||
a6d9a66e | 4656 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event); |
b60e7edf | 4657 | update_global_location_list_nothrow (1); |
cae688ec JJ |
4658 | return b; |
4659 | } | |
4660 | ||
4661 | /* Disable any breakpoints that are on code in shared libraries. Only | |
4662 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
4663 | ||
4664 | void | |
cb851954 | 4665 | disable_breakpoints_in_shlibs (void) |
cae688ec | 4666 | { |
0d381245 | 4667 | struct bp_location *loc; |
cae688ec | 4668 | |
0d381245 | 4669 | ALL_BP_LOCATIONS (loc) |
cae688ec | 4670 | { |
0d381245 VP |
4671 | struct breakpoint *b = loc->owner; |
4672 | /* We apply the check to all breakpoints, including disabled | |
4673 | for those with loc->duplicate set. This is so that when breakpoint | |
4674 | becomes enabled, or the duplicate is removed, gdb will try to insert | |
4675 | all breakpoints. If we don't set shlib_disabled here, we'll try | |
4676 | to insert those breakpoints and fail. */ | |
1042e4c0 SS |
4677 | if (((b->type == bp_breakpoint) |
4678 | || (b->type == bp_hardware_breakpoint) | |
4679 | || (b->type == bp_tracepoint)) | |
0d381245 | 4680 | && !loc->shlib_disabled |
a77053c2 | 4681 | #ifdef PC_SOLIB |
0d381245 | 4682 | && PC_SOLIB (loc->address) |
a77053c2 | 4683 | #else |
f5c9a895 | 4684 | && solib_name_from_address (loc->address) |
a77053c2 MK |
4685 | #endif |
4686 | ) | |
0d381245 VP |
4687 | { |
4688 | loc->shlib_disabled = 1; | |
4689 | } | |
cae688ec JJ |
4690 | } |
4691 | } | |
4692 | ||
84acb35a JJ |
4693 | /* Disable any breakpoints that are in in an unloaded shared library. Only |
4694 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
4695 | ||
75149521 | 4696 | static void |
84acb35a JJ |
4697 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
4698 | { | |
0d381245 | 4699 | struct bp_location *loc; |
84acb35a JJ |
4700 | int disabled_shlib_breaks = 0; |
4701 | ||
c86cf029 VP |
4702 | /* SunOS a.out shared libraries are always mapped, so do not |
4703 | disable breakpoints; they will only be reported as unloaded | |
4704 | through clear_solib when GDB discards its shared library | |
4705 | list. See clear_solib for more information. */ | |
4706 | if (exec_bfd != NULL | |
4707 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
4708 | return; | |
4709 | ||
0d381245 | 4710 | ALL_BP_LOCATIONS (loc) |
84acb35a | 4711 | { |
0d381245 VP |
4712 | struct breakpoint *b = loc->owner; |
4713 | if ((loc->loc_type == bp_loc_hardware_breakpoint | |
4714 | || loc->loc_type == bp_loc_software_breakpoint) | |
e2dd7057 PP |
4715 | && !loc->shlib_disabled |
4716 | && (b->type == bp_breakpoint || b->type == bp_hardware_breakpoint) | |
4717 | && solib_contains_address_p (solib, loc->address)) | |
84acb35a | 4718 | { |
e2dd7057 PP |
4719 | loc->shlib_disabled = 1; |
4720 | /* At this point, we cannot rely on remove_breakpoint | |
4721 | succeeding so we must mark the breakpoint as not inserted | |
4722 | to prevent future errors occurring in remove_breakpoints. */ | |
4723 | loc->inserted = 0; | |
4724 | if (!disabled_shlib_breaks) | |
4725 | { | |
4726 | target_terminal_ours_for_output (); | |
4727 | warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""), | |
4728 | solib->so_name); | |
84acb35a | 4729 | } |
e2dd7057 | 4730 | disabled_shlib_breaks = 1; |
84acb35a JJ |
4731 | } |
4732 | } | |
84acb35a JJ |
4733 | } |
4734 | ||
ce78b96d JB |
4735 | /* FORK & VFORK catchpoints. */ |
4736 | ||
4737 | /* Implement the "insert" breakpoint_ops method for fork catchpoints. */ | |
4738 | ||
c906108c | 4739 | static void |
ce78b96d JB |
4740 | insert_catch_fork (struct breakpoint *b) |
4741 | { | |
4742 | target_insert_fork_catchpoint (PIDGET (inferior_ptid)); | |
4743 | } | |
4744 | ||
4745 | /* Implement the "remove" breakpoint_ops method for fork catchpoints. */ | |
4746 | ||
4747 | static int | |
4748 | remove_catch_fork (struct breakpoint *b) | |
4749 | { | |
4750 | return target_remove_fork_catchpoint (PIDGET (inferior_ptid)); | |
4751 | } | |
4752 | ||
4753 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
4754 | catchpoints. */ | |
4755 | ||
4756 | static int | |
4757 | breakpoint_hit_catch_fork (struct breakpoint *b) | |
4758 | { | |
4759 | return inferior_has_forked (inferior_ptid, &b->forked_inferior_pid); | |
4760 | } | |
4761 | ||
4762 | /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */ | |
4763 | ||
4764 | static enum print_stop_action | |
4765 | print_it_catch_fork (struct breakpoint *b) | |
4766 | { | |
4767 | annotate_catchpoint (b->number); | |
4768 | printf_filtered (_("\nCatchpoint %d (forked process %d), "), | |
4769 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
4770 | return PRINT_SRC_AND_LOC; | |
4771 | } | |
4772 | ||
4773 | /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */ | |
4774 | ||
4775 | static void | |
a6d9a66e | 4776 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 4777 | { |
79a45b7d TT |
4778 | struct value_print_options opts; |
4779 | ||
4780 | get_user_print_options (&opts); | |
4781 | ||
ce78b96d JB |
4782 | /* Field 4, the address, is omitted (which makes the columns |
4783 | not line up too nicely with the headers, but the effect | |
4784 | is relatively readable). */ | |
79a45b7d | 4785 | if (opts.addressprint) |
ce78b96d JB |
4786 | ui_out_field_skip (uiout, "addr"); |
4787 | annotate_field (5); | |
4788 | ui_out_text (uiout, "fork"); | |
4789 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
4790 | { | |
4791 | ui_out_text (uiout, ", process "); | |
4792 | ui_out_field_int (uiout, "what", | |
4793 | ptid_get_pid (b->forked_inferior_pid)); | |
4794 | ui_out_spaces (uiout, 1); | |
4795 | } | |
4796 | } | |
4797 | ||
4798 | /* Implement the "print_mention" breakpoint_ops method for fork | |
4799 | catchpoints. */ | |
4800 | ||
4801 | static void | |
4802 | print_mention_catch_fork (struct breakpoint *b) | |
4803 | { | |
4804 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
4805 | } | |
4806 | ||
4807 | /* The breakpoint_ops structure to be used in fork catchpoints. */ | |
4808 | ||
4809 | static struct breakpoint_ops catch_fork_breakpoint_ops = | |
4810 | { | |
4811 | insert_catch_fork, | |
4812 | remove_catch_fork, | |
4813 | breakpoint_hit_catch_fork, | |
4814 | print_it_catch_fork, | |
4815 | print_one_catch_fork, | |
4816 | print_mention_catch_fork | |
4817 | }; | |
4818 | ||
4819 | /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */ | |
4820 | ||
4821 | static void | |
4822 | insert_catch_vfork (struct breakpoint *b) | |
4823 | { | |
4824 | target_insert_vfork_catchpoint (PIDGET (inferior_ptid)); | |
4825 | } | |
4826 | ||
4827 | /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */ | |
4828 | ||
4829 | static int | |
4830 | remove_catch_vfork (struct breakpoint *b) | |
4831 | { | |
4832 | return target_remove_vfork_catchpoint (PIDGET (inferior_ptid)); | |
4833 | } | |
4834 | ||
4835 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
4836 | catchpoints. */ | |
4837 | ||
4838 | static int | |
4839 | breakpoint_hit_catch_vfork (struct breakpoint *b) | |
4840 | { | |
4841 | return inferior_has_vforked (inferior_ptid, &b->forked_inferior_pid); | |
4842 | } | |
4843 | ||
4844 | /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */ | |
4845 | ||
4846 | static enum print_stop_action | |
4847 | print_it_catch_vfork (struct breakpoint *b) | |
4848 | { | |
4849 | annotate_catchpoint (b->number); | |
4850 | printf_filtered (_("\nCatchpoint %d (vforked process %d), "), | |
4851 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
4852 | return PRINT_SRC_AND_LOC; | |
4853 | } | |
4854 | ||
4855 | /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */ | |
4856 | ||
4857 | static void | |
a6d9a66e | 4858 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 4859 | { |
79a45b7d TT |
4860 | struct value_print_options opts; |
4861 | ||
4862 | get_user_print_options (&opts); | |
ce78b96d JB |
4863 | /* Field 4, the address, is omitted (which makes the columns |
4864 | not line up too nicely with the headers, but the effect | |
4865 | is relatively readable). */ | |
79a45b7d | 4866 | if (opts.addressprint) |
ce78b96d JB |
4867 | ui_out_field_skip (uiout, "addr"); |
4868 | annotate_field (5); | |
4869 | ui_out_text (uiout, "vfork"); | |
4870 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
4871 | { | |
4872 | ui_out_text (uiout, ", process "); | |
4873 | ui_out_field_int (uiout, "what", | |
4874 | ptid_get_pid (b->forked_inferior_pid)); | |
4875 | ui_out_spaces (uiout, 1); | |
4876 | } | |
4877 | } | |
4878 | ||
4879 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
4880 | catchpoints. */ | |
4881 | ||
4882 | static void | |
4883 | print_mention_catch_vfork (struct breakpoint *b) | |
4884 | { | |
4885 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
4886 | } | |
4887 | ||
4888 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ | |
4889 | ||
4890 | static struct breakpoint_ops catch_vfork_breakpoint_ops = | |
4891 | { | |
4892 | insert_catch_vfork, | |
4893 | remove_catch_vfork, | |
4894 | breakpoint_hit_catch_vfork, | |
4895 | print_it_catch_vfork, | |
4896 | print_one_catch_vfork, | |
4897 | print_mention_catch_vfork | |
4898 | }; | |
4899 | ||
4900 | /* Create a new breakpoint of the bp_catchpoint kind and return it. | |
4901 | ||
4902 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
4903 | If COND_STRING is not NULL, then store it in the breakpoint. | |
4904 | OPS, if not NULL, is the breakpoint_ops structure associated | |
4905 | to the catchpoint. */ | |
4906 | ||
4907 | static struct breakpoint * | |
a6d9a66e UW |
4908 | create_catchpoint (struct gdbarch *gdbarch, int tempflag, |
4909 | char *cond_string, struct breakpoint_ops *ops) | |
c906108c | 4910 | { |
c5aa993b JM |
4911 | struct symtab_and_line sal; |
4912 | struct breakpoint *b; | |
c5aa993b | 4913 | |
fe39c653 | 4914 | init_sal (&sal); |
c906108c SS |
4915 | sal.pc = 0; |
4916 | sal.symtab = NULL; | |
4917 | sal.line = 0; | |
c5aa993b | 4918 | |
a6d9a66e | 4919 | b = set_raw_breakpoint (gdbarch, sal, bp_catchpoint); |
c906108c SS |
4920 | set_breakpoint_count (breakpoint_count + 1); |
4921 | b->number = breakpoint_count; | |
ce78b96d | 4922 | |
1b36a34b | 4923 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
ce78b96d | 4924 | b->thread = -1; |
c906108c | 4925 | b->addr_string = NULL; |
b5de0fa7 EZ |
4926 | b->enable_state = bp_enabled; |
4927 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
ce78b96d | 4928 | b->ops = ops; |
c5aa993b | 4929 | |
c906108c | 4930 | mention (b); |
ce78b96d | 4931 | update_global_location_list (1); |
c906108c | 4932 | |
ce78b96d | 4933 | return b; |
c906108c | 4934 | } |
c5aa993b | 4935 | |
9b70b993 | 4936 | static void |
a6d9a66e UW |
4937 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
4938 | int tempflag, char *cond_string, | |
ce78b96d | 4939 | struct breakpoint_ops *ops) |
c906108c | 4940 | { |
a6d9a66e UW |
4941 | struct breakpoint *b |
4942 | = create_catchpoint (gdbarch, tempflag, cond_string, ops); | |
ce78b96d JB |
4943 | |
4944 | /* FIXME: We should put this information in a breakpoint private data | |
4945 | area. */ | |
4946 | b->forked_inferior_pid = null_ptid; | |
c906108c SS |
4947 | } |
4948 | ||
fe798b75 JB |
4949 | /* Exec catchpoints. */ |
4950 | ||
9b70b993 | 4951 | static void |
fe798b75 | 4952 | insert_catch_exec (struct breakpoint *b) |
c906108c | 4953 | { |
fe798b75 JB |
4954 | target_insert_exec_catchpoint (PIDGET (inferior_ptid)); |
4955 | } | |
c906108c | 4956 | |
fe798b75 JB |
4957 | static int |
4958 | remove_catch_exec (struct breakpoint *b) | |
4959 | { | |
4960 | return target_remove_exec_catchpoint (PIDGET (inferior_ptid)); | |
4961 | } | |
c906108c | 4962 | |
fe798b75 JB |
4963 | static int |
4964 | breakpoint_hit_catch_exec (struct breakpoint *b) | |
4965 | { | |
4966 | return inferior_has_execd (inferior_ptid, &b->exec_pathname); | |
4967 | } | |
c906108c | 4968 | |
fe798b75 JB |
4969 | static enum print_stop_action |
4970 | print_it_catch_exec (struct breakpoint *b) | |
4971 | { | |
4972 | annotate_catchpoint (b->number); | |
4973 | printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number, | |
4974 | b->exec_pathname); | |
4975 | return PRINT_SRC_AND_LOC; | |
c906108c SS |
4976 | } |
4977 | ||
fe798b75 | 4978 | static void |
a6d9a66e | 4979 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 JB |
4980 | { |
4981 | struct value_print_options opts; | |
4982 | ||
4983 | get_user_print_options (&opts); | |
4984 | ||
4985 | /* Field 4, the address, is omitted (which makes the columns | |
4986 | not line up too nicely with the headers, but the effect | |
4987 | is relatively readable). */ | |
4988 | if (opts.addressprint) | |
4989 | ui_out_field_skip (uiout, "addr"); | |
4990 | annotate_field (5); | |
4991 | ui_out_text (uiout, "exec"); | |
4992 | if (b->exec_pathname != NULL) | |
4993 | { | |
4994 | ui_out_text (uiout, ", program \""); | |
4995 | ui_out_field_string (uiout, "what", b->exec_pathname); | |
4996 | ui_out_text (uiout, "\" "); | |
4997 | } | |
4998 | } | |
4999 | ||
5000 | static void | |
5001 | print_mention_catch_exec (struct breakpoint *b) | |
5002 | { | |
5003 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
5004 | } | |
5005 | ||
5006 | static struct breakpoint_ops catch_exec_breakpoint_ops = | |
5007 | { | |
5008 | insert_catch_exec, | |
5009 | remove_catch_exec, | |
5010 | breakpoint_hit_catch_exec, | |
5011 | print_it_catch_exec, | |
5012 | print_one_catch_exec, | |
5013 | print_mention_catch_exec | |
5014 | }; | |
5015 | ||
c906108c | 5016 | static int |
fba45db2 | 5017 | hw_breakpoint_used_count (void) |
c906108c | 5018 | { |
52f0bd74 | 5019 | struct breakpoint *b; |
c906108c SS |
5020 | int i = 0; |
5021 | ||
5022 | ALL_BREAKPOINTS (b) | |
c5aa993b | 5023 | { |
d6b74ac4 | 5024 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
c5aa993b JM |
5025 | i++; |
5026 | } | |
c906108c SS |
5027 | |
5028 | return i; | |
5029 | } | |
5030 | ||
5031 | static int | |
fba45db2 | 5032 | hw_watchpoint_used_count (enum bptype type, int *other_type_used) |
c906108c | 5033 | { |
52f0bd74 | 5034 | struct breakpoint *b; |
c906108c SS |
5035 | int i = 0; |
5036 | ||
5037 | *other_type_used = 0; | |
5038 | ALL_BREAKPOINTS (b) | |
c5aa993b | 5039 | { |
468d015d | 5040 | if (breakpoint_enabled (b)) |
c5aa993b JM |
5041 | { |
5042 | if (b->type == type) | |
5043 | i++; | |
059fb39f PM |
5044 | else if ((b->type == bp_hardware_watchpoint |
5045 | || b->type == bp_read_watchpoint | |
5046 | || b->type == bp_access_watchpoint)) | |
c5aa993b JM |
5047 | *other_type_used = 1; |
5048 | } | |
5049 | } | |
c906108c SS |
5050 | return i; |
5051 | } | |
5052 | ||
c906108c | 5053 | void |
fba45db2 | 5054 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 5055 | { |
c5aa993b | 5056 | struct breakpoint *b; |
c906108c SS |
5057 | |
5058 | ALL_BREAKPOINTS (b) | |
c5aa993b JM |
5059 | { |
5060 | if (((b->type == bp_watchpoint) | |
5061 | || (b->type == bp_hardware_watchpoint) | |
5062 | || (b->type == bp_read_watchpoint) | |
dfdfb3ca | 5063 | || (b->type == bp_access_watchpoint)) |
468d015d | 5064 | && breakpoint_enabled (b)) |
c5aa993b | 5065 | { |
b5de0fa7 | 5066 | b->enable_state = bp_call_disabled; |
b60e7edf | 5067 | update_global_location_list (0); |
c5aa993b JM |
5068 | } |
5069 | } | |
c906108c SS |
5070 | } |
5071 | ||
5072 | void | |
fba45db2 | 5073 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 5074 | { |
c5aa993b | 5075 | struct breakpoint *b; |
c906108c SS |
5076 | |
5077 | ALL_BREAKPOINTS (b) | |
c5aa993b JM |
5078 | { |
5079 | if (((b->type == bp_watchpoint) | |
5080 | || (b->type == bp_hardware_watchpoint) | |
5081 | || (b->type == bp_read_watchpoint) | |
dfdfb3ca | 5082 | || (b->type == bp_access_watchpoint)) |
b5de0fa7 | 5083 | && (b->enable_state == bp_call_disabled)) |
c5aa993b | 5084 | { |
b5de0fa7 | 5085 | b->enable_state = bp_enabled; |
b60e7edf | 5086 | update_global_location_list (1); |
c5aa993b JM |
5087 | } |
5088 | } | |
c906108c SS |
5089 | } |
5090 | ||
5091 | ||
5092 | /* Set a breakpoint that will evaporate an end of command | |
5093 | at address specified by SAL. | |
5094 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
5095 | ||
5096 | struct breakpoint * | |
a6d9a66e UW |
5097 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
5098 | struct frame_id frame_id, enum bptype type) | |
c906108c | 5099 | { |
52f0bd74 | 5100 | struct breakpoint *b; |
edb3359d DJ |
5101 | |
5102 | /* If FRAME_ID is valid, it should be a real frame, not an inlined | |
5103 | one. */ | |
5104 | gdb_assert (!frame_id_inlined_p (frame_id)); | |
5105 | ||
a6d9a66e | 5106 | b = set_raw_breakpoint (gdbarch, sal, type); |
b5de0fa7 EZ |
5107 | b->enable_state = bp_enabled; |
5108 | b->disposition = disp_donttouch; | |
818dd999 | 5109 | b->frame_id = frame_id; |
c906108c SS |
5110 | |
5111 | /* If we're debugging a multi-threaded program, then we | |
5112 | want momentary breakpoints to be active in only a | |
5113 | single thread of control. */ | |
39f77062 KB |
5114 | if (in_thread_list (inferior_ptid)) |
5115 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 5116 | |
b60e7edf | 5117 | update_global_location_list_nothrow (1); |
74960c60 | 5118 | |
c906108c SS |
5119 | return b; |
5120 | } | |
611c83ae | 5121 | |
e58b0e63 PA |
5122 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
5123 | ORIG is NULL. */ | |
5124 | ||
5125 | struct breakpoint * | |
5126 | clone_momentary_breakpoint (struct breakpoint *orig) | |
5127 | { | |
5128 | struct breakpoint *copy; | |
5129 | ||
5130 | /* If there's nothing to clone, then return nothing. */ | |
5131 | if (orig == NULL) | |
5132 | return NULL; | |
5133 | ||
a6d9a66e | 5134 | copy = set_raw_breakpoint_without_location (orig->gdbarch, orig->type); |
e58b0e63 PA |
5135 | copy->loc = allocate_bp_location (copy); |
5136 | set_breakpoint_location_function (copy->loc); | |
5137 | ||
a6d9a66e | 5138 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
5139 | copy->loc->requested_address = orig->loc->requested_address; |
5140 | copy->loc->address = orig->loc->address; | |
5141 | copy->loc->section = orig->loc->section; | |
5142 | ||
5143 | if (orig->source_file == NULL) | |
5144 | copy->source_file = NULL; | |
5145 | else | |
5146 | copy->source_file = xstrdup (orig->source_file); | |
5147 | ||
5148 | copy->line_number = orig->line_number; | |
5149 | copy->frame_id = orig->frame_id; | |
5150 | copy->thread = orig->thread; | |
5151 | ||
5152 | copy->enable_state = bp_enabled; | |
5153 | copy->disposition = disp_donttouch; | |
5154 | copy->number = internal_breakpoint_number--; | |
5155 | ||
5156 | update_global_location_list_nothrow (0); | |
5157 | return copy; | |
5158 | } | |
5159 | ||
611c83ae | 5160 | struct breakpoint * |
a6d9a66e UW |
5161 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
5162 | enum bptype type) | |
611c83ae PA |
5163 | { |
5164 | struct symtab_and_line sal; | |
5165 | ||
5166 | sal = find_pc_line (pc, 0); | |
5167 | sal.pc = pc; | |
5168 | sal.section = find_pc_overlay (pc); | |
5169 | sal.explicit_pc = 1; | |
5170 | ||
a6d9a66e | 5171 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 5172 | } |
c906108c | 5173 | \f |
c5aa993b | 5174 | |
c906108c SS |
5175 | /* Tell the user we have just set a breakpoint B. */ |
5176 | ||
5177 | static void | |
fba45db2 | 5178 | mention (struct breakpoint *b) |
c906108c SS |
5179 | { |
5180 | int say_where = 0; | |
fa8a61dc | 5181 | struct cleanup *ui_out_chain; |
79a45b7d TT |
5182 | struct value_print_options opts; |
5183 | ||
5184 | get_user_print_options (&opts); | |
8b93c638 | 5185 | |
9a4105ab AC |
5186 | /* FIXME: This is misplaced; mention() is called by things (like |
5187 | hitting a watchpoint) other than breakpoint creation. It should | |
5188 | be possible to clean this up and at the same time replace the | |
7f4b89d1 | 5189 | random calls to breakpoint_changed with this hook. */ |
383f836e | 5190 | observer_notify_breakpoint_created (b->number); |
c906108c | 5191 | |
3086aeae DJ |
5192 | if (b->ops != NULL && b->ops->print_mention != NULL) |
5193 | b->ops->print_mention (b); | |
5194 | else | |
5195 | switch (b->type) | |
5196 | { | |
5197 | case bp_none: | |
a3f17187 | 5198 | printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b->number); |
3086aeae DJ |
5199 | break; |
5200 | case bp_watchpoint: | |
5201 | ui_out_text (uiout, "Watchpoint "); | |
5202 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
5203 | ui_out_field_int (uiout, "number", b->number); | |
5204 | ui_out_text (uiout, ": "); | |
fa8a61dc | 5205 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
5206 | do_cleanups (ui_out_chain); |
5207 | break; | |
5208 | case bp_hardware_watchpoint: | |
5209 | ui_out_text (uiout, "Hardware watchpoint "); | |
5210 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
5211 | ui_out_field_int (uiout, "number", b->number); | |
5212 | ui_out_text (uiout, ": "); | |
fa8a61dc | 5213 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
5214 | do_cleanups (ui_out_chain); |
5215 | break; | |
5216 | case bp_read_watchpoint: | |
5217 | ui_out_text (uiout, "Hardware read watchpoint "); | |
5218 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
5219 | ui_out_field_int (uiout, "number", b->number); | |
5220 | ui_out_text (uiout, ": "); | |
fa8a61dc | 5221 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
5222 | do_cleanups (ui_out_chain); |
5223 | break; | |
5224 | case bp_access_watchpoint: | |
5225 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
5226 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
5227 | ui_out_field_int (uiout, "number", b->number); | |
5228 | ui_out_text (uiout, ": "); | |
fa8a61dc | 5229 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
5230 | do_cleanups (ui_out_chain); |
5231 | break; | |
5232 | case bp_breakpoint: | |
5233 | if (ui_out_is_mi_like_p (uiout)) | |
5234 | { | |
5235 | say_where = 0; | |
5236 | break; | |
5237 | } | |
2cec12e5 AR |
5238 | if (b->disposition == disp_del) |
5239 | printf_filtered (_("Temporary breakpoint")); | |
5240 | else | |
5241 | printf_filtered (_("Breakpoint")); | |
5242 | printf_filtered (_(" %d"), b->number); | |
3086aeae DJ |
5243 | say_where = 1; |
5244 | break; | |
5245 | case bp_hardware_breakpoint: | |
5246 | if (ui_out_is_mi_like_p (uiout)) | |
5247 | { | |
5248 | say_where = 0; | |
5249 | break; | |
5250 | } | |
a3f17187 | 5251 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); |
3086aeae DJ |
5252 | say_where = 1; |
5253 | break; | |
1042e4c0 SS |
5254 | case bp_tracepoint: |
5255 | if (ui_out_is_mi_like_p (uiout)) | |
5256 | { | |
5257 | say_where = 0; | |
5258 | break; | |
5259 | } | |
5260 | printf_filtered (_("Tracepoint")); | |
5261 | printf_filtered (_(" %d"), b->number); | |
5262 | say_where = 1; | |
5263 | break; | |
3086aeae DJ |
5264 | |
5265 | case bp_until: | |
5266 | case bp_finish: | |
5267 | case bp_longjmp: | |
5268 | case bp_longjmp_resume: | |
5269 | case bp_step_resume: | |
3086aeae DJ |
5270 | case bp_call_dummy: |
5271 | case bp_watchpoint_scope: | |
5272 | case bp_shlib_event: | |
5273 | case bp_thread_event: | |
5274 | case bp_overlay_event: | |
0fd8e87f | 5275 | case bp_longjmp_master: |
3086aeae DJ |
5276 | break; |
5277 | } | |
c906108c | 5278 | |
c906108c SS |
5279 | if (say_where) |
5280 | { | |
a3f17187 AC |
5281 | /* i18n: cagney/2005-02-11: Below needs to be merged into a |
5282 | single string. */ | |
0d381245 | 5283 | if (b->loc == NULL) |
c906108c | 5284 | { |
a3f17187 | 5285 | printf_filtered (_(" (%s) pending."), b->addr_string); |
0101ce28 JJ |
5286 | } |
5287 | else | |
5288 | { | |
79a45b7d | 5289 | if (opts.addressprint || b->source_file == NULL) |
0101ce28 JJ |
5290 | { |
5291 | printf_filtered (" at "); | |
ed49a04f | 5292 | fputs_filtered (paddress (b->loc->address), gdb_stdout); |
0101ce28 JJ |
5293 | } |
5294 | if (b->source_file) | |
5295 | printf_filtered (": file %s, line %d.", | |
5296 | b->source_file, b->line_number); | |
0d381245 VP |
5297 | |
5298 | if (b->loc->next) | |
5299 | { | |
5300 | struct bp_location *loc = b->loc; | |
5301 | int n = 0; | |
5302 | for (; loc; loc = loc->next) | |
5303 | ++n; | |
5304 | printf_filtered (" (%d locations)", n); | |
5305 | } | |
5306 | ||
c906108c | 5307 | } |
c906108c | 5308 | } |
9dc5e2a9 | 5309 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 5310 | return; |
c906108c SS |
5311 | printf_filtered ("\n"); |
5312 | } | |
c906108c | 5313 | \f |
c5aa993b | 5314 | |
0d381245 | 5315 | static struct bp_location * |
39d61571 | 5316 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
5317 | const struct symtab_and_line *sal) |
5318 | { | |
5319 | struct bp_location *loc, **tmp; | |
5320 | ||
39d61571 | 5321 | loc = allocate_bp_location (b); |
0d381245 VP |
5322 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
5323 | ; | |
5324 | *tmp = loc; | |
a6d9a66e UW |
5325 | loc->gdbarch = get_sal_arch (*sal); |
5326 | if (!loc->gdbarch) | |
5327 | loc->gdbarch = b->gdbarch; | |
0d381245 | 5328 | loc->requested_address = sal->pc; |
a6d9a66e UW |
5329 | loc->address = adjust_breakpoint_address (loc->gdbarch, |
5330 | loc->requested_address, b->type); | |
0d381245 VP |
5331 | loc->section = sal->section; |
5332 | ||
5333 | set_breakpoint_location_function (loc); | |
5334 | return loc; | |
5335 | } | |
514f746b AR |
5336 | \f |
5337 | ||
5338 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
5339 | return 0 otherwise. */ | |
5340 | ||
5341 | static int | |
5342 | bp_loc_is_permanent (struct bp_location *loc) | |
5343 | { | |
5344 | int len; | |
5345 | CORE_ADDR addr; | |
5346 | const gdb_byte *brk; | |
5347 | gdb_byte *target_mem; | |
939c61fa JK |
5348 | struct cleanup *cleanup; |
5349 | int retval = 0; | |
514f746b AR |
5350 | |
5351 | gdb_assert (loc != NULL); | |
5352 | ||
5353 | addr = loc->address; | |
a6d9a66e | 5354 | brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 5355 | |
939c61fa JK |
5356 | /* Software breakpoints unsupported? */ |
5357 | if (brk == NULL) | |
5358 | return 0; | |
5359 | ||
514f746b AR |
5360 | target_mem = alloca (len); |
5361 | ||
939c61fa JK |
5362 | /* Enable the automatic memory restoration from breakpoints while |
5363 | we read the memory. Otherwise we could say about our temporary | |
5364 | breakpoints they are permanent. */ | |
5365 | cleanup = make_show_memory_breakpoints_cleanup (0); | |
5366 | ||
514f746b AR |
5367 | if (target_read_memory (loc->address, target_mem, len) == 0 |
5368 | && memcmp (target_mem, brk, len) == 0) | |
939c61fa | 5369 | retval = 1; |
514f746b | 5370 | |
939c61fa JK |
5371 | do_cleanups (cleanup); |
5372 | ||
5373 | return retval; | |
514f746b AR |
5374 | } |
5375 | ||
5376 | ||
c3f6f71d | 5377 | |
018d34a4 VP |
5378 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
5379 | as textual description of the location, and COND_STRING | |
db107f19 | 5380 | as condition expression. */ |
018d34a4 VP |
5381 | |
5382 | static void | |
a6d9a66e UW |
5383 | create_breakpoint (struct gdbarch *gdbarch, |
5384 | struct symtabs_and_lines sals, char *addr_string, | |
018d34a4 VP |
5385 | char *cond_string, |
5386 | enum bptype type, enum bpdisp disposition, | |
4a306c9a | 5387 | int thread, int task, int ignore_count, |
41447f92 | 5388 | struct breakpoint_ops *ops, int from_tty, int enabled) |
018d34a4 | 5389 | { |
0d381245 VP |
5390 | struct breakpoint *b = NULL; |
5391 | int i; | |
018d34a4 VP |
5392 | |
5393 | if (type == bp_hardware_breakpoint) | |
5394 | { | |
5395 | int i = hw_breakpoint_used_count (); | |
5396 | int target_resources_ok = | |
d92524f1 | 5397 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
018d34a4 VP |
5398 | i + 1, 0); |
5399 | if (target_resources_ok == 0) | |
5400 | error (_("No hardware breakpoint support in the target.")); | |
5401 | else if (target_resources_ok < 0) | |
5402 | error (_("Hardware breakpoints used exceeds limit.")); | |
5403 | } | |
5404 | ||
0d381245 VP |
5405 | for (i = 0; i < sals.nelts; ++i) |
5406 | { | |
5407 | struct symtab_and_line sal = sals.sals[i]; | |
5408 | struct bp_location *loc; | |
5409 | ||
5410 | if (from_tty) | |
5411 | describe_other_breakpoints (sal.pc, sal.section, thread); | |
5412 | ||
5413 | if (i == 0) | |
5414 | { | |
a6d9a66e | 5415 | b = set_raw_breakpoint (gdbarch, sal, type); |
0d381245 VP |
5416 | set_breakpoint_count (breakpoint_count + 1); |
5417 | b->number = breakpoint_count; | |
5418 | b->thread = thread; | |
4a306c9a | 5419 | b->task = task; |
018d34a4 | 5420 | |
0d381245 VP |
5421 | b->cond_string = cond_string; |
5422 | b->ignore_count = ignore_count; | |
41447f92 | 5423 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 5424 | b->disposition = disposition; |
018d34a4 | 5425 | |
0d381245 VP |
5426 | loc = b->loc; |
5427 | } | |
5428 | else | |
018d34a4 | 5429 | { |
39d61571 | 5430 | loc = add_location_to_breakpoint (b, &sal); |
0d381245 VP |
5431 | } |
5432 | ||
514f746b AR |
5433 | if (bp_loc_is_permanent (loc)) |
5434 | make_breakpoint_permanent (b); | |
5435 | ||
0d381245 VP |
5436 | if (b->cond_string) |
5437 | { | |
5438 | char *arg = b->cond_string; | |
d32a6982 | 5439 | loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0); |
0d381245 | 5440 | if (*arg) |
db107f19 | 5441 | error (_("Garbage %s follows condition"), arg); |
018d34a4 | 5442 | } |
0d381245 | 5443 | } |
018d34a4 VP |
5444 | |
5445 | if (addr_string) | |
5446 | b->addr_string = addr_string; | |
5447 | else | |
5448 | /* addr_string has to be used or breakpoint_re_set will delete | |
5449 | me. */ | |
5450 | b->addr_string = xstrprintf ("*0x%s", paddr (b->loc->address)); | |
5451 | ||
604133b5 | 5452 | b->ops = ops; |
018d34a4 VP |
5453 | mention (b); |
5454 | } | |
5455 | ||
ed0616c6 VP |
5456 | /* Remove element at INDEX_TO_REMOVE from SAL, shifting other |
5457 | elements to fill the void space. */ | |
2c0b251b PA |
5458 | static void |
5459 | remove_sal (struct symtabs_and_lines *sal, int index_to_remove) | |
ed0616c6 VP |
5460 | { |
5461 | int i = index_to_remove+1; | |
5462 | int last_index = sal->nelts-1; | |
5463 | ||
5464 | for (;i <= last_index; ++i) | |
5465 | sal->sals[i-1] = sal->sals[i]; | |
5466 | ||
5467 | --(sal->nelts); | |
5468 | } | |
5469 | ||
5470 | /* If appropriate, obtains all sals that correspond | |
5471 | to the same file and line as SAL. This is done | |
5472 | only if SAL does not have explicit PC and has | |
5473 | line and file information. If we got just a single | |
5474 | expanded sal, return the original. | |
5475 | ||
5476 | Otherwise, if SAL.explicit_line is not set, filter out | |
5477 | all sals for which the name of enclosing function | |
5478 | is different from SAL. This makes sure that if we have | |
5479 | breakpoint originally set in template instantiation, say | |
5480 | foo<int>(), we won't expand SAL to locations at the same | |
5481 | line in all existing instantiations of 'foo'. | |
5482 | ||
5483 | */ | |
2c0b251b | 5484 | static struct symtabs_and_lines |
ed0616c6 VP |
5485 | expand_line_sal_maybe (struct symtab_and_line sal) |
5486 | { | |
5487 | struct symtabs_and_lines expanded; | |
5488 | CORE_ADDR original_pc = sal.pc; | |
5489 | char *original_function = NULL; | |
5490 | int found; | |
5491 | int i; | |
5492 | ||
5493 | /* If we have explicit pc, don't expand. | |
5494 | If we have no line number, we can't expand. */ | |
5495 | if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL) | |
5496 | { | |
5497 | expanded.nelts = 1; | |
5498 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
5499 | expanded.sals[0] = sal; | |
5500 | return expanded; | |
5501 | } | |
5502 | ||
5503 | sal.pc = 0; | |
5504 | find_pc_partial_function (original_pc, &original_function, NULL, NULL); | |
5505 | ||
5506 | expanded = expand_line_sal (sal); | |
5507 | if (expanded.nelts == 1) | |
5508 | { | |
5509 | /* We had one sal, we got one sal. Without futher | |
5510 | processing, just return the original sal. */ | |
5511 | xfree (expanded.sals); | |
5512 | expanded.nelts = 1; | |
5513 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
5514 | sal.pc = original_pc; | |
5515 | expanded.sals[0] = sal; | |
5516 | return expanded; | |
5517 | } | |
5518 | ||
5519 | if (!sal.explicit_line) | |
5520 | { | |
5521 | CORE_ADDR func_addr, func_end; | |
5522 | for (i = 0; i < expanded.nelts; ++i) | |
5523 | { | |
5524 | CORE_ADDR pc = expanded.sals[i].pc; | |
5525 | char *this_function; | |
5526 | if (find_pc_partial_function (pc, &this_function, | |
5527 | &func_addr, &func_end)) | |
5528 | { | |
059fb39f PM |
5529 | if (this_function |
5530 | && strcmp (this_function, original_function) != 0) | |
ed0616c6 VP |
5531 | { |
5532 | remove_sal (&expanded, i); | |
5533 | --i; | |
5534 | } | |
5535 | else if (func_addr == pc) | |
5536 | { | |
5537 | /* We're at beginning of a function, and should | |
5538 | skip prologue. */ | |
5539 | struct symbol *sym = find_pc_function (pc); | |
5540 | if (sym) | |
5541 | expanded.sals[i] = find_function_start_sal (sym, 1); | |
5542 | else | |
d80b854b UW |
5543 | { |
5544 | /* Since find_pc_partial_function returned true, | |
5545 | we should really always find the section here. */ | |
5546 | struct obj_section *section = find_pc_section (pc); | |
5547 | if (section) | |
5548 | { | |
5549 | struct gdbarch *gdbarch | |
5550 | = get_objfile_arch (section->objfile); | |
5551 | expanded.sals[i].pc | |
5552 | = gdbarch_skip_prologue (gdbarch, pc); | |
5553 | } | |
5554 | } | |
ed0616c6 VP |
5555 | } |
5556 | } | |
5557 | } | |
5558 | } | |
3daf8fe5 JG |
5559 | else |
5560 | { | |
5561 | for (i = 0; i < expanded.nelts; ++i) | |
5562 | { | |
5563 | /* If this SAL corresponds to a breakpoint inserted using a | |
5564 | line number, then skip the function prologue if necessary. */ | |
5565 | skip_prologue_sal (&expanded.sals[i]); | |
5566 | } | |
5567 | } | |
ed0616c6 VP |
5568 | |
5569 | ||
5570 | if (expanded.nelts <= 1) | |
5571 | { | |
5572 | /* This is un ugly workaround. If we get zero | |
5573 | expanded sals then something is really wrong. | |
5574 | Fix that by returnign the original sal. */ | |
5575 | xfree (expanded.sals); | |
5576 | expanded.nelts = 1; | |
5577 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
5578 | sal.pc = original_pc; | |
5579 | expanded.sals[0] = sal; | |
5580 | return expanded; | |
5581 | } | |
5582 | ||
5583 | if (original_pc) | |
5584 | { | |
5585 | found = 0; | |
5586 | for (i = 0; i < expanded.nelts; ++i) | |
5587 | if (expanded.sals[i].pc == original_pc) | |
5588 | { | |
5589 | found = 1; | |
5590 | break; | |
5591 | } | |
5592 | gdb_assert (found); | |
5593 | } | |
5594 | ||
5595 | return expanded; | |
5596 | } | |
5597 | ||
018d34a4 VP |
5598 | /* Add SALS.nelts breakpoints to the breakpoint table. For each |
5599 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
5600 | value. COND_STRING, if not NULL, specified the condition to be | |
5601 | used for all breakpoints. Essentially the only case where | |
5602 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
5603 | function. In that case, it's still not possible to specify | |
5604 | separate conditions for different overloaded functions, so | |
5605 | we take just a single condition string. | |
5606 | ||
c3f6f71d | 5607 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 5608 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
5609 | array contents). If the function fails (error() is called), the |
5610 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
5611 | COND and SALS arrays and each of those arrays contents. */ | |
c906108c SS |
5612 | |
5613 | static void | |
a6d9a66e UW |
5614 | create_breakpoints (struct gdbarch *gdbarch, |
5615 | struct symtabs_and_lines sals, char **addr_string, | |
018d34a4 | 5616 | char *cond_string, |
c3f6f71d | 5617 | enum bptype type, enum bpdisp disposition, |
4a306c9a | 5618 | int thread, int task, int ignore_count, |
41447f92 VP |
5619 | struct breakpoint_ops *ops, int from_tty, |
5620 | int enabled) | |
c906108c | 5621 | { |
018d34a4 VP |
5622 | int i; |
5623 | for (i = 0; i < sals.nelts; ++i) | |
c3f6f71d | 5624 | { |
ed0616c6 VP |
5625 | struct symtabs_and_lines expanded = |
5626 | expand_line_sal_maybe (sals.sals[i]); | |
0d381245 | 5627 | |
a6d9a66e | 5628 | create_breakpoint (gdbarch, expanded, addr_string[i], |
018d34a4 | 5629 | cond_string, type, disposition, |
4a306c9a | 5630 | thread, task, ignore_count, ops, from_tty, enabled); |
c3f6f71d | 5631 | } |
c3f6f71d | 5632 | } |
c906108c | 5633 | |
c3f6f71d JM |
5634 | /* Parse ARG which is assumed to be a SAL specification possibly |
5635 | followed by conditionals. On return, SALS contains an array of SAL | |
5636 | addresses found. ADDR_STRING contains a vector of (canonical) | |
5637 | address strings. ARG points to the end of the SAL. */ | |
c906108c | 5638 | |
b9362cc7 | 5639 | static void |
c3f6f71d JM |
5640 | parse_breakpoint_sals (char **address, |
5641 | struct symtabs_and_lines *sals, | |
0101ce28 JJ |
5642 | char ***addr_string, |
5643 | int *not_found_ptr) | |
c3f6f71d JM |
5644 | { |
5645 | char *addr_start = *address; | |
5646 | *addr_string = NULL; | |
5647 | /* If no arg given, or if first arg is 'if ', use the default | |
5648 | breakpoint. */ | |
5649 | if ((*address) == NULL | |
5650 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c SS |
5651 | { |
5652 | if (default_breakpoint_valid) | |
5653 | { | |
c3f6f71d | 5654 | struct symtab_and_line sal; |
fe39c653 | 5655 | init_sal (&sal); /* initialize to zeroes */ |
c3f6f71d | 5656 | sals->sals = (struct symtab_and_line *) |
c906108c SS |
5657 | xmalloc (sizeof (struct symtab_and_line)); |
5658 | sal.pc = default_breakpoint_address; | |
5659 | sal.line = default_breakpoint_line; | |
5660 | sal.symtab = default_breakpoint_symtab; | |
c5aa993b | 5661 | sal.section = find_pc_overlay (sal.pc); |
00903456 JK |
5662 | |
5663 | /* "break" without arguments is equivalent to "break *PC" where PC is | |
5664 | the default_breakpoint_address. So make sure to set | |
5665 | sal.explicit_pc to prevent GDB from trying to expand the list of | |
5666 | sals to include all other instances with the same symtab and line. | |
5667 | */ | |
5668 | sal.explicit_pc = 1; | |
5669 | ||
c3f6f71d JM |
5670 | sals->sals[0] = sal; |
5671 | sals->nelts = 1; | |
c906108c SS |
5672 | } |
5673 | else | |
8a3fe4f8 | 5674 | error (_("No default breakpoint address now.")); |
c906108c SS |
5675 | } |
5676 | else | |
5677 | { | |
c906108c | 5678 | /* Force almost all breakpoints to be in terms of the |
c5aa993b JM |
5679 | current_source_symtab (which is decode_line_1's default). This |
5680 | should produce the results we want almost all of the time while | |
1aeae86e AF |
5681 | leaving default_breakpoint_* alone. |
5682 | ObjC: However, don't match an Objective-C method name which | |
5683 | may have a '+' or '-' succeeded by a '[' */ | |
0378c332 | 5684 | |
c214a6fd | 5685 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
0378c332 | 5686 | |
c906108c | 5687 | if (default_breakpoint_valid |
0378c332 | 5688 | && (!cursal.symtab |
1aeae86e AF |
5689 | || ((strchr ("+-", (*address)[0]) != NULL) |
5690 | && ((*address)[1] != '[')))) | |
c3f6f71d | 5691 | *sals = decode_line_1 (address, 1, default_breakpoint_symtab, |
0101ce28 JJ |
5692 | default_breakpoint_line, addr_string, |
5693 | not_found_ptr); | |
c906108c | 5694 | else |
0101ce28 JJ |
5695 | *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, |
5696 | addr_string, not_found_ptr); | |
c906108c | 5697 | } |
c3f6f71d JM |
5698 | /* For any SAL that didn't have a canonical string, fill one in. */ |
5699 | if (sals->nelts > 0 && *addr_string == NULL) | |
5700 | *addr_string = xcalloc (sals->nelts, sizeof (char **)); | |
5701 | if (addr_start != (*address)) | |
c906108c | 5702 | { |
c3f6f71d JM |
5703 | int i; |
5704 | for (i = 0; i < sals->nelts; i++) | |
c906108c | 5705 | { |
c3f6f71d JM |
5706 | /* Add the string if not present. */ |
5707 | if ((*addr_string)[i] == NULL) | |
5708 | (*addr_string)[i] = savestring (addr_start, (*address) - addr_start); | |
c906108c SS |
5709 | } |
5710 | } | |
c3f6f71d | 5711 | } |
c906108c | 5712 | |
c906108c | 5713 | |
c3f6f71d JM |
5714 | /* Convert each SAL into a real PC. Verify that the PC can be |
5715 | inserted as a breakpoint. If it can't throw an error. */ | |
c906108c | 5716 | |
b9362cc7 | 5717 | static void |
c3f6f71d JM |
5718 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals, |
5719 | char *address) | |
5720 | { | |
5721 | int i; | |
5722 | for (i = 0; i < sals->nelts; i++) | |
ee53e872 | 5723 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
5724 | } |
5725 | ||
05ff989b | 5726 | static void |
0101ce28 JJ |
5727 | do_captured_parse_breakpoint (struct ui_out *ui, void *data) |
5728 | { | |
5729 | struct captured_parse_breakpoint_args *args = data; | |
5730 | ||
5731 | parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p, | |
5732 | args->not_found_ptr); | |
0101ce28 JJ |
5733 | } |
5734 | ||
018d34a4 VP |
5735 | /* Given TOK, a string specification of condition and thread, as |
5736 | accepted by the 'break' command, extract the condition | |
5737 | string and thread number and set *COND_STRING and *THREAD. | |
5738 | PC identifies the context at which the condition should be parsed. | |
5739 | If no condition is found, *COND_STRING is set to NULL. | |
5740 | If no thread is found, *THREAD is set to -1. */ | |
5741 | static void | |
5742 | find_condition_and_thread (char *tok, CORE_ADDR pc, | |
4a306c9a | 5743 | char **cond_string, int *thread, int *task) |
018d34a4 VP |
5744 | { |
5745 | *cond_string = NULL; | |
5746 | *thread = -1; | |
5747 | while (tok && *tok) | |
5748 | { | |
5749 | char *end_tok; | |
5750 | int toklen; | |
5751 | char *cond_start = NULL; | |
5752 | char *cond_end = NULL; | |
5753 | while (*tok == ' ' || *tok == '\t') | |
5754 | tok++; | |
5755 | ||
5756 | end_tok = tok; | |
5757 | ||
5758 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
5759 | end_tok++; | |
5760 | ||
5761 | toklen = end_tok - tok; | |
5762 | ||
5763 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
5764 | { | |
f7545552 TT |
5765 | struct expression *expr; |
5766 | ||
018d34a4 | 5767 | tok = cond_start = end_tok + 1; |
f7545552 TT |
5768 | expr = parse_exp_1 (&tok, block_for_pc (pc), 0); |
5769 | xfree (expr); | |
018d34a4 VP |
5770 | cond_end = tok; |
5771 | *cond_string = savestring (cond_start, | |
5772 | cond_end - cond_start); | |
5773 | } | |
5774 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
5775 | { | |
5776 | char *tmptok; | |
5777 | ||
5778 | tok = end_tok + 1; | |
5779 | tmptok = tok; | |
5780 | *thread = strtol (tok, &tok, 0); | |
5781 | if (tok == tmptok) | |
5782 | error (_("Junk after thread keyword.")); | |
5783 | if (!valid_thread_id (*thread)) | |
5784 | error (_("Unknown thread %d."), *thread); | |
5785 | } | |
4a306c9a JB |
5786 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
5787 | { | |
5788 | char *tmptok; | |
5789 | ||
5790 | tok = end_tok + 1; | |
5791 | tmptok = tok; | |
5792 | *task = strtol (tok, &tok, 0); | |
5793 | if (tok == tmptok) | |
5794 | error (_("Junk after task keyword.")); | |
5795 | if (!valid_task_id (*task)) | |
5796 | error (_("Unknown task %d\n"), *task); | |
5797 | } | |
018d34a4 VP |
5798 | else |
5799 | error (_("Junk at end of arguments.")); | |
5800 | } | |
5801 | } | |
5802 | ||
72b2ff0e VP |
5803 | /* Set a breakpoint. This function is shared between |
5804 | CLI and MI functions for setting a breakpoint. | |
5805 | This function has two major modes of operations, | |
5806 | selected by the PARSE_CONDITION_AND_THREAD parameter. | |
5807 | If non-zero, the function will parse arg, extracting | |
5808 | breakpoint location, address and thread. Otherwise, | |
5809 | ARG is just the location of breakpoint, with condition | |
5810 | and thread specified by the COND_STRING and THREAD | |
5811 | parameters. */ | |
0101ce28 | 5812 | |
98deb0da | 5813 | static void |
a6d9a66e UW |
5814 | break_command_really (struct gdbarch *gdbarch, |
5815 | char *arg, char *cond_string, int thread, | |
60c46647 | 5816 | int parse_condition_and_thread, |
1042e4c0 | 5817 | int tempflag, int hardwareflag, int traceflag, |
60c46647 VP |
5818 | int ignore_count, |
5819 | enum auto_boolean pending_break_support, | |
604133b5 | 5820 | struct breakpoint_ops *ops, |
41447f92 VP |
5821 | int from_tty, |
5822 | int enabled) | |
c3f6f71d | 5823 | { |
71fff37b | 5824 | struct gdb_exception e; |
c3f6f71d | 5825 | struct symtabs_and_lines sals; |
0101ce28 | 5826 | struct symtab_and_line pending_sal; |
0101ce28 JJ |
5827 | char *copy_arg; |
5828 | char *err_msg; | |
c3f6f71d JM |
5829 | char *addr_start = arg; |
5830 | char **addr_string; | |
5831 | struct cleanup *old_chain; | |
80c99de1 | 5832 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 5833 | struct captured_parse_breakpoint_args parse_args; |
05ff989b | 5834 | int i; |
0101ce28 | 5835 | int pending = 0; |
0101ce28 | 5836 | int not_found = 0; |
1042e4c0 | 5837 | enum bptype type_wanted; |
4a306c9a | 5838 | int task = 0; |
c3f6f71d | 5839 | |
c3f6f71d JM |
5840 | sals.sals = NULL; |
5841 | sals.nelts = 0; | |
5842 | addr_string = NULL; | |
c3f6f71d | 5843 | |
0101ce28 JJ |
5844 | parse_args.arg_p = &arg; |
5845 | parse_args.sals_p = &sals; | |
5846 | parse_args.addr_string_p = &addr_string; | |
5847 | parse_args.not_found_ptr = ¬_found; | |
5848 | ||
05ff989b AC |
5849 | e = catch_exception (uiout, do_captured_parse_breakpoint, |
5850 | &parse_args, RETURN_MASK_ALL); | |
0101ce28 JJ |
5851 | |
5852 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 5853 | switch (e.reason) |
0101ce28 | 5854 | { |
05ff989b | 5855 | case RETURN_QUIT: |
98deb0da | 5856 | throw_exception (e); |
05ff989b AC |
5857 | case RETURN_ERROR: |
5858 | switch (e.error) | |
0101ce28 | 5859 | { |
05ff989b | 5860 | case NOT_FOUND_ERROR: |
0101ce28 | 5861 | |
05ff989b AC |
5862 | /* If pending breakpoint support is turned off, throw |
5863 | error. */ | |
fa8d40ab JJ |
5864 | |
5865 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
5866 | throw_exception (e); |
5867 | ||
5868 | exception_print (gdb_stderr, e); | |
fa8d40ab | 5869 | |
05ff989b AC |
5870 | /* If pending breakpoint support is auto query and the user |
5871 | selects no, then simply return the error code. */ | |
059fb39f PM |
5872 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
5873 | && !nquery ("Make breakpoint pending on future shared library load? ")) | |
98deb0da | 5874 | return; |
fa8d40ab | 5875 | |
05ff989b AC |
5876 | /* At this point, either the user was queried about setting |
5877 | a pending breakpoint and selected yes, or pending | |
5878 | breakpoint behavior is on and thus a pending breakpoint | |
5879 | is defaulted on behalf of the user. */ | |
0101ce28 JJ |
5880 | copy_arg = xstrdup (addr_start); |
5881 | addr_string = ©_arg; | |
5882 | sals.nelts = 1; | |
5883 | sals.sals = &pending_sal; | |
5884 | pending_sal.pc = 0; | |
5885 | pending = 1; | |
05ff989b AC |
5886 | break; |
5887 | default: | |
98deb0da | 5888 | throw_exception (e); |
0101ce28 | 5889 | } |
05ff989b AC |
5890 | default: |
5891 | if (!sals.nelts) | |
98deb0da | 5892 | return; |
0101ce28 | 5893 | } |
c3f6f71d JM |
5894 | |
5895 | /* Create a chain of things that always need to be cleaned up. */ | |
5896 | old_chain = make_cleanup (null_cleanup, 0); | |
5897 | ||
0101ce28 JJ |
5898 | if (!pending) |
5899 | { | |
5900 | /* Make sure that all storage allocated to SALS gets freed. */ | |
5901 | make_cleanup (xfree, sals.sals); | |
5902 | ||
5903 | /* Cleanup the addr_string array but not its contents. */ | |
5904 | make_cleanup (xfree, addr_string); | |
5905 | } | |
c3f6f71d | 5906 | |
c3f6f71d JM |
5907 | /* ----------------------------- SNIP ----------------------------- |
5908 | Anything added to the cleanup chain beyond this point is assumed | |
5909 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
5910 | then the memory is not reclaimed. */ |
5911 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d JM |
5912 | |
5913 | /* Mark the contents of the addr_string for cleanup. These go on | |
80c99de1 | 5914 | the bkpt_chain and only occur if the breakpoint create fails. */ |
c3f6f71d JM |
5915 | for (i = 0; i < sals.nelts; i++) |
5916 | { | |
5917 | if (addr_string[i] != NULL) | |
b8c9b27d | 5918 | make_cleanup (xfree, addr_string[i]); |
c3f6f71d JM |
5919 | } |
5920 | ||
5921 | /* Resolve all line numbers to PC's and verify that the addresses | |
5922 | are ok for the target. */ | |
0101ce28 JJ |
5923 | if (!pending) |
5924 | breakpoint_sals_to_pc (&sals, addr_start); | |
c3f6f71d | 5925 | |
1042e4c0 SS |
5926 | type_wanted = (traceflag |
5927 | ? bp_tracepoint | |
5928 | : (hardwareflag ? bp_hardware_breakpoint : bp_breakpoint)); | |
5929 | ||
c3f6f71d JM |
5930 | /* Verify that condition can be parsed, before setting any |
5931 | breakpoints. Allocate a separate condition expression for each | |
5932 | breakpoint. */ | |
0101ce28 | 5933 | if (!pending) |
c3f6f71d | 5934 | { |
2f069f6f | 5935 | if (parse_condition_and_thread) |
72b2ff0e VP |
5936 | { |
5937 | /* Here we only parse 'arg' to separate condition | |
5938 | from thread number, so parsing in context of first | |
5939 | sal is OK. When setting the breakpoint we'll | |
5940 | re-parse it in context of each sal. */ | |
5941 | cond_string = NULL; | |
5942 | thread = -1; | |
4a306c9a JB |
5943 | find_condition_and_thread (arg, sals.sals[0].pc, &cond_string, |
5944 | &thread, &task); | |
72b2ff0e VP |
5945 | if (cond_string) |
5946 | make_cleanup (xfree, cond_string); | |
5947 | } | |
2f069f6f | 5948 | else |
72b2ff0e VP |
5949 | { |
5950 | /* Create a private copy of condition string. */ | |
5951 | if (cond_string) | |
5952 | { | |
5953 | cond_string = xstrdup (cond_string); | |
5954 | make_cleanup (xfree, cond_string); | |
5955 | } | |
5956 | } | |
a6d9a66e | 5957 | create_breakpoints (gdbarch, sals, addr_string, cond_string, type_wanted, |
0101ce28 | 5958 | tempflag ? disp_del : disp_donttouch, |
4a306c9a | 5959 | thread, task, ignore_count, ops, from_tty, enabled); |
c906108c | 5960 | } |
0101ce28 JJ |
5961 | else |
5962 | { | |
fe3f5fa8 | 5963 | struct symtab_and_line sal = {0}; |
0101ce28 JJ |
5964 | struct breakpoint *b; |
5965 | ||
0101ce28 JJ |
5966 | make_cleanup (xfree, copy_arg); |
5967 | ||
a6d9a66e | 5968 | b = set_raw_breakpoint_without_location (gdbarch, type_wanted); |
0101ce28 JJ |
5969 | set_breakpoint_count (breakpoint_count + 1); |
5970 | b->number = breakpoint_count; | |
72b2ff0e | 5971 | b->thread = -1; |
018d34a4 | 5972 | b->addr_string = addr_string[0]; |
72b2ff0e | 5973 | b->cond_string = NULL; |
0101ce28 | 5974 | b->ignore_count = ignore_count; |
0101ce28 | 5975 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 5976 | b->condition_not_parsed = 1; |
604133b5 | 5977 | b->ops = ops; |
41447f92 | 5978 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
74960c60 | 5979 | |
0101ce28 JJ |
5980 | mention (b); |
5981 | } | |
5982 | ||
c3f6f71d | 5983 | if (sals.nelts > 1) |
8a3fe4f8 AC |
5984 | warning (_("Multiple breakpoints were set.\n" |
5985 | "Use the \"delete\" command to delete unwanted breakpoints.")); | |
80c99de1 PA |
5986 | /* That's it. Discard the cleanups for data inserted into the |
5987 | breakpoint. */ | |
5988 | discard_cleanups (bkpt_chain); | |
5989 | /* But cleanup everything else. */ | |
c3f6f71d | 5990 | do_cleanups (old_chain); |
217dc9e2 | 5991 | |
80c99de1 | 5992 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
217dc9e2 | 5993 | update_global_location_list (1); |
c3f6f71d | 5994 | } |
c906108c | 5995 | |
72b2ff0e VP |
5996 | /* Set a breakpoint. |
5997 | ARG is a string describing breakpoint address, | |
5998 | condition, and thread. | |
5999 | FLAG specifies if a breakpoint is hardware on, | |
6000 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
6001 | and BP_TEMPFLAG. */ | |
6002 | ||
98deb0da | 6003 | static void |
72b2ff0e | 6004 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 6005 | { |
72b2ff0e VP |
6006 | int hardwareflag = flag & BP_HARDWAREFLAG; |
6007 | int tempflag = flag & BP_TEMPFLAG; | |
c3f6f71d | 6008 | |
a6d9a66e UW |
6009 | break_command_really (get_current_arch (), |
6010 | arg, | |
98deb0da | 6011 | NULL, 0, 1 /* parse arg */, |
1042e4c0 | 6012 | tempflag, hardwareflag, 0 /* traceflag */, |
98deb0da | 6013 | 0 /* Ignore count */, |
604133b5 AR |
6014 | pending_break_support, |
6015 | NULL /* breakpoint_ops */, | |
41447f92 VP |
6016 | from_tty, |
6017 | 1 /* enabled */); | |
c906108c SS |
6018 | } |
6019 | ||
72b2ff0e | 6020 | |
98deb0da | 6021 | void |
a6d9a66e UW |
6022 | set_breakpoint (struct gdbarch *gdbarch, |
6023 | char *address, char *condition, | |
c3f6f71d | 6024 | int hardwareflag, int tempflag, |
ce43223b | 6025 | int thread, int ignore_count, |
41447f92 | 6026 | int pending, int enabled) |
c3f6f71d | 6027 | { |
a6d9a66e UW |
6028 | break_command_really (gdbarch, |
6029 | address, condition, thread, | |
98deb0da | 6030 | 0 /* condition and thread are valid. */, |
1042e4c0 | 6031 | tempflag, hardwareflag, 0 /* traceflag */, |
98deb0da VP |
6032 | ignore_count, |
6033 | pending | |
6034 | ? AUTO_BOOLEAN_TRUE : AUTO_BOOLEAN_FALSE, | |
41447f92 | 6035 | NULL, 0, enabled); |
c3f6f71d JM |
6036 | } |
6037 | ||
6a048695 JB |
6038 | /* Adjust SAL to the first instruction past the function prologue. |
6039 | The end of the prologue is determined using the line table from | |
3daf8fe5 JG |
6040 | the debugging information. explicit_pc and explicit_line are |
6041 | not modified. | |
6a048695 JB |
6042 | |
6043 | If SAL is already past the prologue, then do nothing. */ | |
6044 | ||
6045 | static void | |
6046 | skip_prologue_sal (struct symtab_and_line *sal) | |
6047 | { | |
6048 | struct symbol *sym = find_pc_function (sal->pc); | |
6049 | struct symtab_and_line start_sal; | |
6050 | ||
6051 | if (sym == NULL) | |
6052 | return; | |
6053 | ||
6054 | start_sal = find_function_start_sal (sym, 1); | |
6055 | if (sal->pc < start_sal.pc) | |
3daf8fe5 JG |
6056 | { |
6057 | start_sal.explicit_line = sal->explicit_line; | |
6058 | start_sal.explicit_pc = sal->explicit_pc; | |
6059 | *sal = start_sal; | |
6060 | } | |
6a048695 | 6061 | } |
c3f6f71d | 6062 | |
c906108c SS |
6063 | /* Helper function for break_command_1 and disassemble_command. */ |
6064 | ||
6065 | void | |
fba45db2 | 6066 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
6067 | { |
6068 | CORE_ADDR pc; | |
6069 | ||
6070 | if (sal->pc == 0 && sal->symtab != NULL) | |
6071 | { | |
6072 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 6073 | error (_("No line %d in file \"%s\"."), |
c906108c SS |
6074 | sal->line, sal->symtab->filename); |
6075 | sal->pc = pc; | |
6a048695 JB |
6076 | |
6077 | /* If this SAL corresponds to a breakpoint inserted using | |
6078 | a line number, then skip the function prologue if necessary. */ | |
6079 | if (sal->explicit_line) | |
56ef84b1 TT |
6080 | { |
6081 | /* Preserve the original line number. */ | |
6082 | int saved_line = sal->line; | |
6083 | skip_prologue_sal (sal); | |
6084 | sal->line = saved_line; | |
6085 | } | |
c906108c SS |
6086 | } |
6087 | ||
6088 | if (sal->section == 0 && sal->symtab != NULL) | |
6089 | { | |
6090 | struct blockvector *bv; | |
c5aa993b JM |
6091 | struct block *b; |
6092 | struct symbol *sym; | |
c906108c | 6093 | |
801e3a5b | 6094 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
6095 | if (bv != NULL) |
6096 | { | |
7f0df278 | 6097 | sym = block_linkage_function (b); |
c906108c SS |
6098 | if (sym != NULL) |
6099 | { | |
6100 | fixup_symbol_section (sym, sal->symtab->objfile); | |
714835d5 | 6101 | sal->section = SYMBOL_OBJ_SECTION (sym); |
c906108c SS |
6102 | } |
6103 | else | |
6104 | { | |
6105 | /* It really is worthwhile to have the section, so we'll just | |
c5aa993b JM |
6106 | have to look harder. This case can be executed if we have |
6107 | line numbers but no functions (as can happen in assembly | |
6108 | source). */ | |
c906108c | 6109 | |
c5aa993b | 6110 | struct minimal_symbol *msym; |
c906108c SS |
6111 | |
6112 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
6113 | if (msym) | |
714835d5 | 6114 | sal->section = SYMBOL_OBJ_SECTION (msym); |
c906108c SS |
6115 | } |
6116 | } | |
6117 | } | |
6118 | } | |
6119 | ||
6120 | void | |
fba45db2 | 6121 | break_command (char *arg, int from_tty) |
c906108c | 6122 | { |
db107f19 | 6123 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
6124 | } |
6125 | ||
c906108c | 6126 | void |
fba45db2 | 6127 | tbreak_command (char *arg, int from_tty) |
c906108c | 6128 | { |
db107f19 | 6129 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
6130 | } |
6131 | ||
c906108c | 6132 | static void |
fba45db2 | 6133 | hbreak_command (char *arg, int from_tty) |
c906108c | 6134 | { |
db107f19 | 6135 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
6136 | } |
6137 | ||
6138 | static void | |
fba45db2 | 6139 | thbreak_command (char *arg, int from_tty) |
c906108c | 6140 | { |
db107f19 | 6141 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
6142 | } |
6143 | ||
6144 | static void | |
fba45db2 | 6145 | stop_command (char *arg, int from_tty) |
c906108c | 6146 | { |
a3f17187 | 6147 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 6148 | Usage: stop in <function | address>\n\ |
a3f17187 | 6149 | stop at <line>\n")); |
c906108c SS |
6150 | } |
6151 | ||
6152 | static void | |
fba45db2 | 6153 | stopin_command (char *arg, int from_tty) |
c906108c SS |
6154 | { |
6155 | int badInput = 0; | |
6156 | ||
c5aa993b | 6157 | if (arg == (char *) NULL) |
c906108c SS |
6158 | badInput = 1; |
6159 | else if (*arg != '*') | |
6160 | { | |
6161 | char *argptr = arg; | |
6162 | int hasColon = 0; | |
6163 | ||
53a5351d JM |
6164 | /* look for a ':'. If this is a line number specification, then |
6165 | say it is bad, otherwise, it should be an address or | |
6166 | function/method name */ | |
c906108c | 6167 | while (*argptr && !hasColon) |
c5aa993b JM |
6168 | { |
6169 | hasColon = (*argptr == ':'); | |
6170 | argptr++; | |
6171 | } | |
c906108c SS |
6172 | |
6173 | if (hasColon) | |
c5aa993b | 6174 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 6175 | else |
c5aa993b | 6176 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
6177 | } |
6178 | ||
6179 | if (badInput) | |
a3f17187 | 6180 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 6181 | else |
db107f19 | 6182 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
6183 | } |
6184 | ||
6185 | static void | |
fba45db2 | 6186 | stopat_command (char *arg, int from_tty) |
c906108c SS |
6187 | { |
6188 | int badInput = 0; | |
6189 | ||
c5aa993b | 6190 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
6191 | badInput = 1; |
6192 | else | |
6193 | { | |
6194 | char *argptr = arg; | |
6195 | int hasColon = 0; | |
6196 | ||
6197 | /* look for a ':'. If there is a '::' then get out, otherwise | |
c5aa993b | 6198 | it is probably a line number. */ |
c906108c | 6199 | while (*argptr && !hasColon) |
c5aa993b JM |
6200 | { |
6201 | hasColon = (*argptr == ':'); | |
6202 | argptr++; | |
6203 | } | |
c906108c SS |
6204 | |
6205 | if (hasColon) | |
c5aa993b | 6206 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 6207 | else |
c5aa993b | 6208 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
6209 | } |
6210 | ||
6211 | if (badInput) | |
a3f17187 | 6212 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 6213 | else |
db107f19 | 6214 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
6215 | } |
6216 | ||
53a5351d JM |
6217 | /* accessflag: hw_write: watch write, |
6218 | hw_read: watch read, | |
6219 | hw_access: watch access (read or write) */ | |
c906108c | 6220 | static void |
fba45db2 | 6221 | watch_command_1 (char *arg, int accessflag, int from_tty) |
c906108c | 6222 | { |
a6d9a66e | 6223 | struct gdbarch *gdbarch = get_current_arch (); |
d983da9c | 6224 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c SS |
6225 | struct symtab_and_line sal; |
6226 | struct expression *exp; | |
6227 | struct block *exp_valid_block; | |
6228 | struct value *val, *mark; | |
6229 | struct frame_info *frame; | |
c906108c SS |
6230 | char *exp_start = NULL; |
6231 | char *exp_end = NULL; | |
37e4754d | 6232 | char *tok, *id_tok_start, *end_tok; |
c906108c SS |
6233 | int toklen; |
6234 | char *cond_start = NULL; | |
6235 | char *cond_end = NULL; | |
6236 | struct expression *cond = NULL; | |
6237 | int i, other_type_used, target_resources_ok = 0; | |
6238 | enum bptype bp_type; | |
6239 | int mem_cnt = 0; | |
37e4754d | 6240 | int thread = -1; |
c906108c | 6241 | |
fe39c653 | 6242 | init_sal (&sal); /* initialize to zeroes */ |
c5aa993b | 6243 | |
37e4754d LM |
6244 | /* Make sure that we actually have parameters to parse. */ |
6245 | if (arg != NULL && arg[0] != '\0') | |
6246 | { | |
6247 | toklen = strlen (arg); /* Size of argument list. */ | |
6248 | ||
6249 | /* Points tok to the end of the argument list. */ | |
6250 | tok = arg + toklen - 1; | |
6251 | ||
6252 | /* Go backwards in the parameters list. Skip the last parameter. | |
6253 | If we're expecting a 'thread <thread_num>' parameter, this should | |
6254 | be the thread identifier. */ | |
6255 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
6256 | tok--; | |
6257 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
6258 | tok--; | |
6259 | ||
6260 | /* Points end_tok to the beginning of the last token. */ | |
6261 | id_tok_start = tok + 1; | |
6262 | ||
6263 | /* Go backwards in the parameters list. Skip one more parameter. | |
6264 | If we're expecting a 'thread <thread_num>' parameter, we should | |
6265 | reach a "thread" token. */ | |
6266 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
6267 | tok--; | |
6268 | ||
6269 | end_tok = tok; | |
6270 | ||
6271 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
6272 | tok--; | |
6273 | ||
6274 | /* Move the pointer forward to skip the whitespace and | |
6275 | calculate the length of the token. */ | |
6276 | tok++; | |
6277 | toklen = end_tok - tok; | |
6278 | ||
6279 | if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
6280 | { | |
6281 | /* At this point we've found a "thread" token, which means | |
6282 | the user is trying to set a watchpoint that triggers | |
6283 | only in a specific thread. */ | |
6284 | char *endp; | |
6285 | ||
6286 | /* Extract the thread ID from the next token. */ | |
6287 | thread = strtol (id_tok_start, &endp, 0); | |
6288 | ||
6289 | /* Check if the user provided a valid numeric value for the | |
6290 | thread ID. */ | |
6291 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
6292 | error (_("Invalid thread ID specification %s."), id_tok_start); | |
6293 | ||
6294 | /* Check if the thread actually exists. */ | |
6295 | if (!valid_thread_id (thread)) | |
6296 | error (_("Unknown thread %d."), thread); | |
6297 | ||
6298 | /* Truncate the string and get rid of the thread <thread_num> | |
6299 | parameter before the parameter list is parsed by the | |
6300 | evaluate_expression() function. */ | |
6301 | *tok = '\0'; | |
6302 | } | |
6303 | } | |
6304 | ||
6305 | /* Parse the rest of the arguments. */ | |
c906108c SS |
6306 | innermost_block = NULL; |
6307 | exp_start = arg; | |
6308 | exp = parse_exp_1 (&arg, 0, 0); | |
6309 | exp_end = arg; | |
fa8a61dc TT |
6310 | /* Remove trailing whitespace from the expression before saving it. |
6311 | This makes the eventual display of the expression string a bit | |
6312 | prettier. */ | |
6313 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
6314 | --exp_end; | |
6315 | ||
c906108c SS |
6316 | exp_valid_block = innermost_block; |
6317 | mark = value_mark (); | |
fa4727a6 DJ |
6318 | fetch_watchpoint_value (exp, &val, NULL, NULL); |
6319 | if (val != NULL) | |
6320 | release_value (val); | |
c906108c SS |
6321 | |
6322 | tok = arg; | |
6323 | while (*tok == ' ' || *tok == '\t') | |
6324 | tok++; | |
6325 | end_tok = tok; | |
6326 | ||
6327 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
6328 | end_tok++; | |
6329 | ||
6330 | toklen = end_tok - tok; | |
6331 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
6332 | { | |
6333 | tok = cond_start = end_tok + 1; | |
6334 | cond = parse_exp_1 (&tok, 0, 0); | |
6335 | cond_end = tok; | |
6336 | } | |
6337 | if (*tok) | |
8a3fe4f8 | 6338 | error (_("Junk at end of command.")); |
c906108c | 6339 | |
53a5351d | 6340 | if (accessflag == hw_read) |
c5aa993b | 6341 | bp_type = bp_read_watchpoint; |
53a5351d | 6342 | else if (accessflag == hw_access) |
c5aa993b JM |
6343 | bp_type = bp_access_watchpoint; |
6344 | else | |
6345 | bp_type = bp_hardware_watchpoint; | |
c906108c SS |
6346 | |
6347 | mem_cnt = can_use_hardware_watchpoint (val); | |
6348 | if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint) | |
8a3fe4f8 | 6349 | error (_("Expression cannot be implemented with read/access watchpoint.")); |
c5aa993b JM |
6350 | if (mem_cnt != 0) |
6351 | { | |
6352 | i = hw_watchpoint_used_count (bp_type, &other_type_used); | |
53a5351d | 6353 | target_resources_ok = |
d92524f1 | 6354 | target_can_use_hardware_watchpoint (bp_type, i + mem_cnt, |
53a5351d | 6355 | other_type_used); |
c5aa993b | 6356 | if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint) |
8a3fe4f8 | 6357 | error (_("Target does not support this type of hardware watchpoint.")); |
53a5351d | 6358 | |
c5aa993b | 6359 | if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint) |
8a3fe4f8 | 6360 | error (_("Target can only support one kind of HW watchpoint at a time.")); |
c5aa993b | 6361 | } |
c906108c | 6362 | |
4d28f7a8 KB |
6363 | /* Change the type of breakpoint to an ordinary watchpoint if a hardware |
6364 | watchpoint could not be set. */ | |
6365 | if (!mem_cnt || target_resources_ok <= 0) | |
6366 | bp_type = bp_watchpoint; | |
6367 | ||
d983da9c | 6368 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
6369 | |
6370 | /* If the expression is "local", then set up a "watchpoint scope" | |
6371 | breakpoint at the point where we've left the scope of the watchpoint | |
6372 | expression. Create the scope breakpoint before the watchpoint, so | |
6373 | that we will encounter it first in bpstat_stop_status. */ | |
edb3359d | 6374 | if (innermost_block && frame) |
d983da9c | 6375 | { |
edb3359d DJ |
6376 | if (frame_id_p (frame_unwind_caller_id (frame))) |
6377 | { | |
6378 | scope_breakpoint | |
a6d9a66e UW |
6379 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
6380 | frame_unwind_caller_pc (frame), | |
edb3359d | 6381 | bp_watchpoint_scope); |
d983da9c | 6382 | |
edb3359d | 6383 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 6384 | |
edb3359d DJ |
6385 | /* Automatically delete the breakpoint when it hits. */ |
6386 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 6387 | |
edb3359d DJ |
6388 | /* Only break in the proper frame (help with recursion). */ |
6389 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 6390 | |
edb3359d | 6391 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
6392 | scope_breakpoint->loc->gdbarch |
6393 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
6394 | scope_breakpoint->loc->requested_address |
6395 | = frame_unwind_caller_pc (frame); | |
6396 | scope_breakpoint->loc->address | |
a6d9a66e UW |
6397 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
6398 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
6399 | scope_breakpoint->type); |
6400 | } | |
d983da9c DJ |
6401 | } |
6402 | ||
c906108c | 6403 | /* Now set up the breakpoint. */ |
a6d9a66e | 6404 | b = set_raw_breakpoint (gdbarch, sal, bp_type); |
c906108c SS |
6405 | set_breakpoint_count (breakpoint_count + 1); |
6406 | b->number = breakpoint_count; | |
37e4754d | 6407 | b->thread = thread; |
b5de0fa7 | 6408 | b->disposition = disp_donttouch; |
c906108c SS |
6409 | b->exp = exp; |
6410 | b->exp_valid_block = exp_valid_block; | |
6411 | b->exp_string = savestring (exp_start, exp_end - exp_start); | |
6412 | b->val = val; | |
fa4727a6 | 6413 | b->val_valid = 1; |
511a6cd4 | 6414 | b->loc->cond = cond; |
c906108c SS |
6415 | if (cond_start) |
6416 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
6417 | else | |
6418 | b->cond_string = 0; | |
c5aa993b | 6419 | |
c906108c | 6420 | if (frame) |
d983da9c | 6421 | b->watchpoint_frame = get_frame_id (frame); |
c906108c | 6422 | else |
35a487f1 | 6423 | b->watchpoint_frame = null_frame_id; |
c906108c | 6424 | |
d983da9c | 6425 | if (scope_breakpoint != NULL) |
c906108c | 6426 | { |
d983da9c DJ |
6427 | /* The scope breakpoint is related to the watchpoint. We will |
6428 | need to act on them together. */ | |
6429 | b->related_breakpoint = scope_breakpoint; | |
6430 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 6431 | } |
d983da9c | 6432 | |
c906108c SS |
6433 | value_free_to_mark (mark); |
6434 | mention (b); | |
b60e7edf | 6435 | update_global_location_list (1); |
c906108c SS |
6436 | } |
6437 | ||
6438 | /* Return count of locations need to be watched and can be handled | |
6439 | in hardware. If the watchpoint can not be handled | |
6440 | in hardware return zero. */ | |
6441 | ||
c906108c | 6442 | static int |
fba45db2 | 6443 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
6444 | { |
6445 | int found_memory_cnt = 0; | |
2e70b7b9 | 6446 | struct value *head = v; |
c906108c SS |
6447 | |
6448 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 6449 | if (!can_use_hw_watchpoints) |
c906108c | 6450 | return 0; |
c5aa993b | 6451 | |
5c44784c JM |
6452 | /* Make sure that the value of the expression depends only upon |
6453 | memory contents, and values computed from them within GDB. If we | |
6454 | find any register references or function calls, we can't use a | |
6455 | hardware watchpoint. | |
6456 | ||
6457 | The idea here is that evaluating an expression generates a series | |
6458 | of values, one holding the value of every subexpression. (The | |
6459 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
6460 | a*b+c.) GDB's values hold almost enough information to establish | |
6461 | the criteria given above --- they identify memory lvalues, | |
6462 | register lvalues, computed values, etcetera. So we can evaluate | |
6463 | the expression, and then scan the chain of values that leaves | |
6464 | behind to decide whether we can detect any possible change to the | |
6465 | expression's final value using only hardware watchpoints. | |
6466 | ||
6467 | However, I don't think that the values returned by inferior | |
6468 | function calls are special in any way. So this function may not | |
6469 | notice that an expression involving an inferior function call | |
6470 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 6471 | for (; v; v = value_next (v)) |
c906108c | 6472 | { |
5c44784c | 6473 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 6474 | { |
d69fe07e | 6475 | if (value_lazy (v)) |
5c44784c JM |
6476 | /* A lazy memory lvalue is one that GDB never needed to fetch; |
6477 | we either just used its address (e.g., `a' in `a.b') or | |
6478 | we never needed it at all (e.g., `a' in `a,b'). */ | |
6479 | ; | |
53a5351d | 6480 | else |
5c44784c JM |
6481 | { |
6482 | /* Ahh, memory we actually used! Check if we can cover | |
6483 | it with hardware watchpoints. */ | |
df407dfe | 6484 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
6485 | |
6486 | /* We only watch structs and arrays if user asked for it | |
6487 | explicitly, never if they just happen to appear in a | |
6488 | middle of some value chain. */ | |
6489 | if (v == head | |
6490 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
6491 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
6492 | { | |
42ae5230 | 6493 | CORE_ADDR vaddr = value_address (v); |
df407dfe | 6494 | int len = TYPE_LENGTH (value_type (v)); |
2e70b7b9 | 6495 | |
d92524f1 | 6496 | if (!target_region_ok_for_hw_watchpoint (vaddr, len)) |
2e70b7b9 MS |
6497 | return 0; |
6498 | else | |
6499 | found_memory_cnt++; | |
6500 | } | |
5c44784c | 6501 | } |
c5aa993b | 6502 | } |
5086187c AC |
6503 | else if (VALUE_LVAL (v) != not_lval |
6504 | && deprecated_value_modifiable (v) == 0) | |
53a5351d | 6505 | return 0; /* ??? What does this represent? */ |
5086187c | 6506 | else if (VALUE_LVAL (v) == lval_register) |
53a5351d | 6507 | return 0; /* cannot watch a register with a HW watchpoint */ |
c906108c SS |
6508 | } |
6509 | ||
6510 | /* The expression itself looks suitable for using a hardware | |
6511 | watchpoint, but give the target machine a chance to reject it. */ | |
6512 | return found_memory_cnt; | |
6513 | } | |
6514 | ||
8b93c638 | 6515 | void |
fba45db2 | 6516 | watch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
6517 | { |
6518 | watch_command (arg, from_tty); | |
6519 | } | |
8926118c | 6520 | |
c5aa993b | 6521 | static void |
fba45db2 | 6522 | watch_command (char *arg, int from_tty) |
c906108c | 6523 | { |
53a5351d | 6524 | watch_command_1 (arg, hw_write, from_tty); |
c906108c SS |
6525 | } |
6526 | ||
8b93c638 | 6527 | void |
fba45db2 | 6528 | rwatch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
6529 | { |
6530 | rwatch_command (arg, from_tty); | |
6531 | } | |
8926118c | 6532 | |
c5aa993b | 6533 | static void |
fba45db2 | 6534 | rwatch_command (char *arg, int from_tty) |
c906108c | 6535 | { |
53a5351d | 6536 | watch_command_1 (arg, hw_read, from_tty); |
c906108c SS |
6537 | } |
6538 | ||
8b93c638 | 6539 | void |
fba45db2 | 6540 | awatch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
6541 | { |
6542 | awatch_command (arg, from_tty); | |
6543 | } | |
8926118c | 6544 | |
c5aa993b | 6545 | static void |
fba45db2 | 6546 | awatch_command (char *arg, int from_tty) |
c906108c | 6547 | { |
53a5351d | 6548 | watch_command_1 (arg, hw_access, from_tty); |
c906108c | 6549 | } |
c906108c | 6550 | \f |
c5aa993b | 6551 | |
43ff13b4 | 6552 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
6553 | because it uses the mechanisms of breakpoints. */ |
6554 | ||
bfec99b2 PA |
6555 | struct until_break_command_continuation_args |
6556 | { | |
6557 | struct breakpoint *breakpoint; | |
6558 | struct breakpoint *breakpoint2; | |
6559 | }; | |
6560 | ||
43ff13b4 JM |
6561 | /* This function is called by fetch_inferior_event via the |
6562 | cmd_continuation pointer, to complete the until command. It takes | |
6563 | care of cleaning up the temporary breakpoints set up by the until | |
6564 | command. */ | |
c2c6d25f | 6565 | static void |
604ead4a | 6566 | until_break_command_continuation (void *arg) |
43ff13b4 | 6567 | { |
bfec99b2 PA |
6568 | struct until_break_command_continuation_args *a = arg; |
6569 | ||
6570 | delete_breakpoint (a->breakpoint); | |
6571 | if (a->breakpoint2) | |
6572 | delete_breakpoint (a->breakpoint2); | |
43ff13b4 JM |
6573 | } |
6574 | ||
c906108c | 6575 | void |
ae66c1fc | 6576 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
6577 | { |
6578 | struct symtabs_and_lines sals; | |
6579 | struct symtab_and_line sal; | |
206415a3 | 6580 | struct frame_info *frame = get_selected_frame (NULL); |
c906108c | 6581 | struct breakpoint *breakpoint; |
f107f563 | 6582 | struct breakpoint *breakpoint2 = NULL; |
c906108c SS |
6583 | struct cleanup *old_chain; |
6584 | ||
6585 | clear_proceed_status (); | |
6586 | ||
6587 | /* Set a breakpoint where the user wants it and at return from | |
6588 | this function */ | |
c5aa993b | 6589 | |
c906108c SS |
6590 | if (default_breakpoint_valid) |
6591 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, | |
68219205 | 6592 | default_breakpoint_line, (char ***) NULL, NULL); |
c906108c | 6593 | else |
53a5351d | 6594 | sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, |
68219205 | 6595 | 0, (char ***) NULL, NULL); |
c5aa993b | 6596 | |
c906108c | 6597 | if (sals.nelts != 1) |
8a3fe4f8 | 6598 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 6599 | |
c906108c | 6600 | sal = sals.sals[0]; |
b8c9b27d | 6601 | xfree (sals.sals); /* malloc'd, so freed */ |
c5aa993b | 6602 | |
c906108c | 6603 | if (*arg) |
8a3fe4f8 | 6604 | error (_("Junk at end of arguments.")); |
c5aa993b | 6605 | |
c906108c | 6606 | resolve_sal_pc (&sal); |
c5aa993b | 6607 | |
ae66c1fc EZ |
6608 | if (anywhere) |
6609 | /* If the user told us to continue until a specified location, | |
6610 | we don't specify a frame at which we need to stop. */ | |
a6d9a66e UW |
6611 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
6612 | null_frame_id, bp_until); | |
ae66c1fc | 6613 | else |
edb3359d | 6614 | /* Otherwise, specify the selected frame, because we want to stop only |
ae66c1fc | 6615 | at the very same frame. */ |
a6d9a66e UW |
6616 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
6617 | get_stack_frame_id (frame), | |
ae66c1fc | 6618 | bp_until); |
c5aa993b | 6619 | |
f107f563 | 6620 | old_chain = make_cleanup_delete_breakpoint (breakpoint); |
c906108c | 6621 | |
ae66c1fc EZ |
6622 | /* Keep within the current frame, or in frames called by the current |
6623 | one. */ | |
edb3359d DJ |
6624 | |
6625 | if (frame_id_p (frame_unwind_caller_id (frame))) | |
c906108c | 6626 | { |
edb3359d DJ |
6627 | sal = find_pc_line (frame_unwind_caller_pc (frame), 0); |
6628 | sal.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e UW |
6629 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
6630 | sal, | |
edb3359d | 6631 | frame_unwind_caller_id (frame), |
f107f563 VP |
6632 | bp_until); |
6633 | make_cleanup_delete_breakpoint (breakpoint2); | |
c906108c | 6634 | } |
c5aa993b | 6635 | |
c906108c | 6636 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
f107f563 VP |
6637 | |
6638 | /* If we are running asynchronously, and proceed call above has actually | |
6639 | managed to start the target, arrange for breakpoints to be | |
6640 | deleted when the target stops. Otherwise, we're already stopped and | |
6641 | delete breakpoints via cleanup chain. */ | |
6642 | ||
8ea051c5 | 6643 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 6644 | { |
bfec99b2 PA |
6645 | struct until_break_command_continuation_args *args; |
6646 | args = xmalloc (sizeof (*args)); | |
f107f563 | 6647 | |
bfec99b2 PA |
6648 | args->breakpoint = breakpoint; |
6649 | args->breakpoint2 = breakpoint2; | |
f107f563 VP |
6650 | |
6651 | discard_cleanups (old_chain); | |
95e54da7 PA |
6652 | add_continuation (inferior_thread (), |
6653 | until_break_command_continuation, args, | |
604ead4a | 6654 | xfree); |
f107f563 VP |
6655 | } |
6656 | else | |
c5aa993b | 6657 | do_cleanups (old_chain); |
c906108c | 6658 | } |
ae66c1fc | 6659 | |
c906108c | 6660 | static void |
fba45db2 | 6661 | ep_skip_leading_whitespace (char **s) |
c906108c | 6662 | { |
c5aa993b JM |
6663 | if ((s == NULL) || (*s == NULL)) |
6664 | return; | |
6665 | while (isspace (**s)) | |
6666 | *s += 1; | |
c906108c | 6667 | } |
c5aa993b | 6668 | |
c906108c SS |
6669 | /* This function attempts to parse an optional "if <cond>" clause |
6670 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 6671 | |
c906108c SS |
6672 | Else, it returns a pointer to the condition string. (It does not |
6673 | attempt to evaluate the string against a particular block.) And, | |
6674 | it updates arg to point to the first character following the parsed | |
6675 | if clause in the arg string. */ | |
53a5351d | 6676 | |
c906108c | 6677 | static char * |
fba45db2 | 6678 | ep_parse_optional_if_clause (char **arg) |
c906108c | 6679 | { |
c5aa993b JM |
6680 | char *cond_string; |
6681 | ||
6682 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 6683 | return NULL; |
c5aa993b | 6684 | |
c906108c SS |
6685 | /* Skip the "if" keyword. */ |
6686 | (*arg) += 2; | |
c5aa993b | 6687 | |
c906108c SS |
6688 | /* Skip any extra leading whitespace, and record the start of the |
6689 | condition string. */ | |
6690 | ep_skip_leading_whitespace (arg); | |
6691 | cond_string = *arg; | |
c5aa993b | 6692 | |
c906108c SS |
6693 | /* Assume that the condition occupies the remainder of the arg string. */ |
6694 | (*arg) += strlen (cond_string); | |
c5aa993b | 6695 | |
c906108c SS |
6696 | return cond_string; |
6697 | } | |
c5aa993b | 6698 | |
c906108c SS |
6699 | /* This function attempts to parse an optional filename from the arg |
6700 | string. If one is not found, it returns NULL. | |
c5aa993b | 6701 | |
c906108c SS |
6702 | Else, it returns a pointer to the parsed filename. (This function |
6703 | makes no attempt to verify that a file of that name exists, or is | |
6704 | accessible.) And, it updates arg to point to the first character | |
6705 | following the parsed filename in the arg string. | |
c5aa993b | 6706 | |
c906108c SS |
6707 | Note that clients needing to preserve the returned filename for |
6708 | future access should copy it to their own buffers. */ | |
6709 | static char * | |
fba45db2 | 6710 | ep_parse_optional_filename (char **arg) |
c906108c | 6711 | { |
c5aa993b JM |
6712 | static char filename[1024]; |
6713 | char *arg_p = *arg; | |
6714 | int i; | |
6715 | char c; | |
6716 | ||
c906108c SS |
6717 | if ((*arg_p == '\0') || isspace (*arg_p)) |
6718 | return NULL; | |
c5aa993b JM |
6719 | |
6720 | for (i = 0;; i++) | |
c906108c SS |
6721 | { |
6722 | c = *arg_p; | |
6723 | if (isspace (c)) | |
c5aa993b | 6724 | c = '\0'; |
c906108c SS |
6725 | filename[i] = c; |
6726 | if (c == '\0') | |
c5aa993b | 6727 | break; |
c906108c SS |
6728 | arg_p++; |
6729 | } | |
6730 | *arg = arg_p; | |
c5aa993b | 6731 | |
c906108c SS |
6732 | return filename; |
6733 | } | |
c5aa993b | 6734 | |
c906108c SS |
6735 | /* Commands to deal with catching events, such as signals, exceptions, |
6736 | process start/exit, etc. */ | |
c5aa993b JM |
6737 | |
6738 | typedef enum | |
6739 | { | |
44feb3ce TT |
6740 | catch_fork_temporary, catch_vfork_temporary, |
6741 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
6742 | } |
6743 | catch_fork_kind; | |
6744 | ||
c906108c | 6745 | static void |
44feb3ce | 6746 | catch_fork_command_1 (char *arg, int from_tty, struct cmd_list_element *command) |
c906108c | 6747 | { |
a6d9a66e | 6748 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 6749 | char *cond_string = NULL; |
44feb3ce TT |
6750 | catch_fork_kind fork_kind; |
6751 | int tempflag; | |
6752 | ||
6753 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
6754 | tempflag = (fork_kind == catch_fork_temporary | |
6755 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 6756 | |
44feb3ce TT |
6757 | if (!arg) |
6758 | arg = ""; | |
c906108c | 6759 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 6760 | |
c906108c | 6761 | /* The allowed syntax is: |
c5aa993b JM |
6762 | catch [v]fork |
6763 | catch [v]fork if <cond> | |
6764 | ||
c906108c SS |
6765 | First, check if there's an if clause. */ |
6766 | cond_string = ep_parse_optional_if_clause (&arg); | |
c5aa993b | 6767 | |
c906108c | 6768 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 6769 | error (_("Junk at end of arguments.")); |
c5aa993b | 6770 | |
c906108c SS |
6771 | /* If this target supports it, create a fork or vfork catchpoint |
6772 | and enable reporting of such events. */ | |
c5aa993b JM |
6773 | switch (fork_kind) |
6774 | { | |
44feb3ce TT |
6775 | case catch_fork_temporary: |
6776 | case catch_fork_permanent: | |
a6d9a66e | 6777 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 6778 | &catch_fork_breakpoint_ops); |
c906108c | 6779 | break; |
44feb3ce TT |
6780 | case catch_vfork_temporary: |
6781 | case catch_vfork_permanent: | |
a6d9a66e | 6782 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 6783 | &catch_vfork_breakpoint_ops); |
c906108c | 6784 | break; |
c5aa993b | 6785 | default: |
8a3fe4f8 | 6786 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 6787 | break; |
c5aa993b | 6788 | } |
c906108c SS |
6789 | } |
6790 | ||
6791 | static void | |
44feb3ce | 6792 | catch_exec_command_1 (char *arg, int from_tty, struct cmd_list_element *command) |
c906108c | 6793 | { |
a6d9a66e | 6794 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 6795 | int tempflag; |
c5aa993b | 6796 | char *cond_string = NULL; |
c906108c | 6797 | |
44feb3ce TT |
6798 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
6799 | ||
6800 | if (!arg) | |
6801 | arg = ""; | |
c906108c SS |
6802 | ep_skip_leading_whitespace (&arg); |
6803 | ||
6804 | /* The allowed syntax is: | |
c5aa993b JM |
6805 | catch exec |
6806 | catch exec if <cond> | |
c906108c SS |
6807 | |
6808 | First, check if there's an if clause. */ | |
6809 | cond_string = ep_parse_optional_if_clause (&arg); | |
6810 | ||
6811 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 6812 | error (_("Junk at end of arguments.")); |
c906108c SS |
6813 | |
6814 | /* If this target supports it, create an exec catchpoint | |
6815 | and enable reporting of such events. */ | |
a6d9a66e UW |
6816 | create_catchpoint (gdbarch, tempflag, cond_string, |
6817 | &catch_exec_breakpoint_ops); | |
c906108c | 6818 | } |
c5aa993b | 6819 | |
3086aeae DJ |
6820 | static enum print_stop_action |
6821 | print_exception_catchpoint (struct breakpoint *b) | |
6822 | { | |
ade92717 | 6823 | int bp_temp, bp_throw; |
3086aeae | 6824 | |
ade92717 | 6825 | annotate_catchpoint (b->number); |
3086aeae | 6826 | |
ade92717 AR |
6827 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
6828 | if (b->loc->address != b->loc->requested_address) | |
6829 | breakpoint_adjustment_warning (b->loc->requested_address, | |
6830 | b->loc->address, | |
6831 | b->number, 1); | |
df2b6d2d | 6832 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
6833 | ui_out_text (uiout, |
6834 | bp_temp ? "Temporary catchpoint " | |
6835 | : "Catchpoint "); | |
6836 | if (!ui_out_is_mi_like_p (uiout)) | |
6837 | ui_out_field_int (uiout, "bkptno", b->number); | |
6838 | ui_out_text (uiout, | |
c0b37c48 AR |
6839 | bp_throw ? " (exception thrown), " |
6840 | : " (exception caught), "); | |
ade92717 AR |
6841 | if (ui_out_is_mi_like_p (uiout)) |
6842 | { | |
6843 | ui_out_field_string (uiout, "reason", | |
6844 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
6845 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
6846 | ui_out_field_int (uiout, "bkptno", b->number); | |
6847 | } | |
3086aeae DJ |
6848 | return PRINT_SRC_AND_LOC; |
6849 | } | |
6850 | ||
6851 | static void | |
a6d9a66e | 6852 | print_one_exception_catchpoint (struct breakpoint *b, struct bp_location **last_loc) |
3086aeae | 6853 | { |
79a45b7d TT |
6854 | struct value_print_options opts; |
6855 | get_user_print_options (&opts); | |
6856 | if (opts.addressprint) | |
3086aeae DJ |
6857 | { |
6858 | annotate_field (4); | |
604133b5 AR |
6859 | if (b->loc == NULL || b->loc->shlib_disabled) |
6860 | ui_out_field_string (uiout, "addr", "<PENDING>"); | |
6861 | else | |
6862 | ui_out_field_core_addr (uiout, "addr", b->loc->address); | |
3086aeae DJ |
6863 | } |
6864 | annotate_field (5); | |
604133b5 | 6865 | if (b->loc) |
a6d9a66e | 6866 | *last_loc = b->loc; |
3086aeae DJ |
6867 | if (strstr (b->addr_string, "throw") != NULL) |
6868 | ui_out_field_string (uiout, "what", "exception throw"); | |
6869 | else | |
6870 | ui_out_field_string (uiout, "what", "exception catch"); | |
6871 | } | |
6872 | ||
6873 | static void | |
6874 | print_mention_exception_catchpoint (struct breakpoint *b) | |
6875 | { | |
ade92717 AR |
6876 | int bp_temp; |
6877 | int bp_throw; | |
6878 | ||
df2b6d2d | 6879 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
6880 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
6881 | ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ") | |
6882 | : _("Catchpoint ")); | |
6883 | ui_out_field_int (uiout, "bkptno", b->number); | |
6884 | ui_out_text (uiout, bp_throw ? _(" (throw)") | |
6885 | : _(" (catch)")); | |
3086aeae DJ |
6886 | } |
6887 | ||
6888 | static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = { | |
ce78b96d JB |
6889 | NULL, /* insert */ |
6890 | NULL, /* remove */ | |
6891 | NULL, /* breakpoint_hit */ | |
3086aeae DJ |
6892 | print_exception_catchpoint, |
6893 | print_one_exception_catchpoint, | |
6894 | print_mention_exception_catchpoint | |
6895 | }; | |
6896 | ||
6897 | static int | |
6898 | handle_gnu_v3_exceptions (int tempflag, char *cond_string, | |
6899 | enum exception_event_kind ex_event, int from_tty) | |
6900 | { | |
604133b5 AR |
6901 | char *trigger_func_name; |
6902 | ||
3086aeae | 6903 | if (ex_event == EX_EVENT_CATCH) |
604133b5 | 6904 | trigger_func_name = "__cxa_begin_catch"; |
3086aeae | 6905 | else |
604133b5 | 6906 | trigger_func_name = "__cxa_throw"; |
3086aeae | 6907 | |
a6d9a66e UW |
6908 | break_command_really (get_current_arch (), |
6909 | trigger_func_name, cond_string, -1, | |
604133b5 | 6910 | 0 /* condition and thread are valid. */, |
1042e4c0 | 6911 | tempflag, 0, 0, |
604133b5 AR |
6912 | 0, |
6913 | AUTO_BOOLEAN_TRUE /* pending */, | |
41447f92 VP |
6914 | &gnu_v3_exception_catchpoint_ops, from_tty, |
6915 | 1 /* enabled */); | |
3086aeae | 6916 | |
3086aeae DJ |
6917 | return 1; |
6918 | } | |
6919 | ||
c5aa993b | 6920 | /* Deal with "catch catch" and "catch throw" commands */ |
c906108c SS |
6921 | |
6922 | static void | |
fba45db2 KB |
6923 | catch_exception_command_1 (enum exception_event_kind ex_event, char *arg, |
6924 | int tempflag, int from_tty) | |
c906108c | 6925 | { |
c5aa993b JM |
6926 | char *cond_string = NULL; |
6927 | struct symtab_and_line *sal = NULL; | |
6928 | ||
44feb3ce TT |
6929 | if (!arg) |
6930 | arg = ""; | |
c906108c | 6931 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 6932 | |
c906108c SS |
6933 | cond_string = ep_parse_optional_if_clause (&arg); |
6934 | ||
6935 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 6936 | error (_("Junk at end of arguments.")); |
c906108c | 6937 | |
059fb39f PM |
6938 | if (ex_event != EX_EVENT_THROW |
6939 | && ex_event != EX_EVENT_CATCH) | |
8a3fe4f8 | 6940 | error (_("Unsupported or unknown exception event; cannot catch it")); |
c906108c | 6941 | |
3086aeae DJ |
6942 | if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty)) |
6943 | return; | |
6944 | ||
8a3fe4f8 | 6945 | warning (_("Unsupported with this platform/compiler combination.")); |
c906108c SS |
6946 | } |
6947 | ||
44feb3ce TT |
6948 | /* Implementation of "catch catch" command. */ |
6949 | ||
6950 | static void | |
6951 | catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command) | |
6952 | { | |
6953 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
6954 | catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty); | |
6955 | } | |
6956 | ||
6957 | /* Implementation of "catch throw" command. */ | |
6958 | ||
6959 | static void | |
6960 | catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command) | |
6961 | { | |
6962 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
6963 | catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty); | |
6964 | } | |
6965 | ||
f7f9143b JB |
6966 | /* Create a breakpoint struct for Ada exception catchpoints. */ |
6967 | ||
6968 | static void | |
a6d9a66e UW |
6969 | create_ada_exception_breakpoint (struct gdbarch *gdbarch, |
6970 | struct symtab_and_line sal, | |
f7f9143b JB |
6971 | char *addr_string, |
6972 | char *exp_string, | |
6973 | char *cond_string, | |
6974 | struct expression *cond, | |
6975 | struct breakpoint_ops *ops, | |
6976 | int tempflag, | |
6977 | int from_tty) | |
6978 | { | |
6979 | struct breakpoint *b; | |
6980 | ||
6981 | if (from_tty) | |
6982 | { | |
6983 | describe_other_breakpoints (sal.pc, sal.section, -1); | |
6984 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special | |
6985 | version for exception catchpoints, because two catchpoints | |
6986 | used for different exception names will use the same address. | |
6987 | In this case, a "breakpoint ... also set at..." warning is | |
6988 | unproductive. Besides. the warning phrasing is also a bit | |
6989 | inapropriate, we should use the word catchpoint, and tell | |
6990 | the user what type of catchpoint it is. The above is good | |
6991 | enough for now, though. */ | |
6992 | } | |
6993 | ||
a6d9a66e | 6994 | b = set_raw_breakpoint (gdbarch, sal, bp_breakpoint); |
f7f9143b JB |
6995 | set_breakpoint_count (breakpoint_count + 1); |
6996 | ||
6997 | b->enable_state = bp_enabled; | |
6998 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
6999 | b->number = breakpoint_count; | |
7000 | b->ignore_count = 0; | |
511a6cd4 | 7001 | b->loc->cond = cond; |
f7f9143b JB |
7002 | b->addr_string = addr_string; |
7003 | b->language = language_ada; | |
7004 | b->cond_string = cond_string; | |
7005 | b->exp_string = exp_string; | |
7006 | b->thread = -1; | |
7007 | b->ops = ops; | |
f7f9143b JB |
7008 | |
7009 | mention (b); | |
b60e7edf | 7010 | update_global_location_list (1); |
f7f9143b JB |
7011 | } |
7012 | ||
7013 | /* Implement the "catch exception" command. */ | |
7014 | ||
7015 | static void | |
44feb3ce TT |
7016 | catch_ada_exception_command (char *arg, int from_tty, |
7017 | struct cmd_list_element *command) | |
f7f9143b | 7018 | { |
a6d9a66e | 7019 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 7020 | int tempflag; |
f7f9143b JB |
7021 | struct symtab_and_line sal; |
7022 | enum bptype type; | |
7023 | char *addr_string = NULL; | |
7024 | char *exp_string = NULL; | |
7025 | char *cond_string = NULL; | |
7026 | struct expression *cond = NULL; | |
7027 | struct breakpoint_ops *ops = NULL; | |
7028 | ||
44feb3ce TT |
7029 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
7030 | ||
7031 | if (!arg) | |
7032 | arg = ""; | |
f7f9143b JB |
7033 | sal = ada_decode_exception_location (arg, &addr_string, &exp_string, |
7034 | &cond_string, &cond, &ops); | |
a6d9a66e | 7035 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, exp_string, |
f7f9143b JB |
7036 | cond_string, cond, ops, tempflag, |
7037 | from_tty); | |
7038 | } | |
7039 | ||
7040 | /* Implement the "catch assert" command. */ | |
7041 | ||
7042 | static void | |
44feb3ce | 7043 | catch_assert_command (char *arg, int from_tty, struct cmd_list_element *command) |
f7f9143b | 7044 | { |
a6d9a66e | 7045 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 7046 | int tempflag; |
f7f9143b JB |
7047 | struct symtab_and_line sal; |
7048 | char *addr_string = NULL; | |
7049 | struct breakpoint_ops *ops = NULL; | |
7050 | ||
44feb3ce TT |
7051 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
7052 | ||
7053 | if (!arg) | |
7054 | arg = ""; | |
f7f9143b | 7055 | sal = ada_decode_assert_location (arg, &addr_string, &ops); |
a6d9a66e UW |
7056 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, NULL, NULL, NULL, |
7057 | ops, tempflag, from_tty); | |
f7f9143b JB |
7058 | } |
7059 | ||
c906108c | 7060 | static void |
fba45db2 | 7061 | catch_command (char *arg, int from_tty) |
c906108c | 7062 | { |
44feb3ce | 7063 | error (_("Catch requires an event name.")); |
c906108c SS |
7064 | } |
7065 | \f | |
7066 | ||
7067 | static void | |
fba45db2 | 7068 | tcatch_command (char *arg, int from_tty) |
c906108c | 7069 | { |
44feb3ce | 7070 | error (_("Catch requires an event name.")); |
c906108c SS |
7071 | } |
7072 | ||
80f8a6eb | 7073 | /* Delete breakpoints by address or line. */ |
c906108c SS |
7074 | |
7075 | static void | |
fba45db2 | 7076 | clear_command (char *arg, int from_tty) |
c906108c | 7077 | { |
d6e956e5 VP |
7078 | struct breakpoint *b; |
7079 | VEC(breakpoint_p) *found = 0; | |
7080 | int ix; | |
c906108c SS |
7081 | int default_match; |
7082 | struct symtabs_and_lines sals; | |
7083 | struct symtab_and_line sal; | |
c906108c SS |
7084 | int i; |
7085 | ||
7086 | if (arg) | |
7087 | { | |
7088 | sals = decode_line_spec (arg, 1); | |
7089 | default_match = 0; | |
7090 | } | |
7091 | else | |
7092 | { | |
c5aa993b | 7093 | sals.sals = (struct symtab_and_line *) |
c906108c | 7094 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 7095 | make_cleanup (xfree, sals.sals); |
fe39c653 | 7096 | init_sal (&sal); /* initialize to zeroes */ |
c906108c SS |
7097 | sal.line = default_breakpoint_line; |
7098 | sal.symtab = default_breakpoint_symtab; | |
7099 | sal.pc = default_breakpoint_address; | |
7100 | if (sal.symtab == 0) | |
8a3fe4f8 | 7101 | error (_("No source file specified.")); |
c906108c SS |
7102 | |
7103 | sals.sals[0] = sal; | |
7104 | sals.nelts = 1; | |
7105 | ||
7106 | default_match = 1; | |
7107 | } | |
7108 | ||
ed0616c6 VP |
7109 | /* We don't call resolve_sal_pc here. That's not |
7110 | as bad as it seems, because all existing breakpoints | |
7111 | typically have both file/line and pc set. So, if | |
7112 | clear is given file/line, we can match this to existing | |
7113 | breakpoint without obtaining pc at all. | |
7114 | ||
7115 | We only support clearing given the address explicitly | |
7116 | present in breakpoint table. Say, we've set breakpoint | |
7117 | at file:line. There were several PC values for that file:line, | |
7118 | due to optimization, all in one block. | |
7119 | We've picked one PC value. If "clear" is issued with another | |
7120 | PC corresponding to the same file:line, the breakpoint won't | |
7121 | be cleared. We probably can still clear the breakpoint, but | |
7122 | since the other PC value is never presented to user, user | |
7123 | can only find it by guessing, and it does not seem important | |
7124 | to support that. */ | |
7125 | ||
c906108c | 7126 | /* For each line spec given, delete bps which correspond |
80f8a6eb MS |
7127 | to it. Do it in two passes, solely to preserve the current |
7128 | behavior that from_tty is forced true if we delete more than | |
7129 | one breakpoint. */ | |
c906108c | 7130 | |
80f8a6eb | 7131 | found = NULL; |
c906108c SS |
7132 | for (i = 0; i < sals.nelts; i++) |
7133 | { | |
7134 | /* If exact pc given, clear bpts at that pc. | |
c5aa993b JM |
7135 | If line given (pc == 0), clear all bpts on specified line. |
7136 | If defaulting, clear all bpts on default line | |
c906108c | 7137 | or at default pc. |
c5aa993b JM |
7138 | |
7139 | defaulting sal.pc != 0 tests to do | |
7140 | ||
7141 | 0 1 pc | |
7142 | 1 1 pc _and_ line | |
7143 | 0 0 line | |
7144 | 1 0 <can't happen> */ | |
c906108c SS |
7145 | |
7146 | sal = sals.sals[i]; | |
c906108c | 7147 | |
d6e956e5 VP |
7148 | /* Find all matching breakpoints and add them to |
7149 | 'found'. */ | |
7150 | ALL_BREAKPOINTS (b) | |
c5aa993b | 7151 | { |
0d381245 | 7152 | int match = 0; |
80f8a6eb MS |
7153 | /* Are we going to delete b? */ |
7154 | if (b->type != bp_none | |
7155 | && b->type != bp_watchpoint | |
7156 | && b->type != bp_hardware_watchpoint | |
7157 | && b->type != bp_read_watchpoint | |
0d381245 VP |
7158 | && b->type != bp_access_watchpoint) |
7159 | { | |
7160 | struct bp_location *loc = b->loc; | |
7161 | for (; loc; loc = loc->next) | |
7162 | { | |
7163 | int pc_match = sal.pc | |
7164 | && (loc->address == sal.pc) | |
7165 | && (!section_is_overlay (loc->section) | |
7166 | || loc->section == sal.section); | |
7167 | int line_match = ((default_match || (0 == sal.pc)) | |
7168 | && b->source_file != NULL | |
7169 | && sal.symtab != NULL | |
7170 | && strcmp (b->source_file, sal.symtab->filename) == 0 | |
7171 | && b->line_number == sal.line); | |
7172 | if (pc_match || line_match) | |
7173 | { | |
7174 | match = 1; | |
7175 | break; | |
7176 | } | |
7177 | } | |
7178 | } | |
7179 | ||
7180 | if (match) | |
d6e956e5 | 7181 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 7182 | } |
80f8a6eb MS |
7183 | } |
7184 | /* Now go thru the 'found' chain and delete them. */ | |
d6e956e5 | 7185 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
7186 | { |
7187 | if (arg) | |
8a3fe4f8 | 7188 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 7189 | else |
8a3fe4f8 | 7190 | error (_("No breakpoint at this line.")); |
80f8a6eb | 7191 | } |
c906108c | 7192 | |
d6e956e5 | 7193 | if (VEC_length(breakpoint_p, found) > 1) |
80f8a6eb MS |
7194 | from_tty = 1; /* Always report if deleted more than one */ |
7195 | if (from_tty) | |
a3f17187 | 7196 | { |
d6e956e5 | 7197 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
7198 | printf_unfiltered (_("Deleted breakpoint ")); |
7199 | else | |
7200 | printf_unfiltered (_("Deleted breakpoints ")); | |
7201 | } | |
80f8a6eb | 7202 | breakpoints_changed (); |
d6e956e5 VP |
7203 | |
7204 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 7205 | { |
c5aa993b | 7206 | if (from_tty) |
d6e956e5 VP |
7207 | printf_unfiltered ("%d ", b->number); |
7208 | delete_breakpoint (b); | |
c906108c | 7209 | } |
80f8a6eb MS |
7210 | if (from_tty) |
7211 | putchar_unfiltered ('\n'); | |
c906108c SS |
7212 | } |
7213 | \f | |
7214 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
7215 | all breakpoints that are marked for deletion, whether hit or not. | |
7216 | This is called after any breakpoint is hit, or after errors. */ | |
7217 | ||
7218 | void | |
fba45db2 | 7219 | breakpoint_auto_delete (bpstat bs) |
c906108c SS |
7220 | { |
7221 | struct breakpoint *b, *temp; | |
7222 | ||
7223 | for (; bs; bs = bs->next) | |
20874c92 VP |
7224 | if (bs->breakpoint_at |
7225 | && bs->breakpoint_at->owner | |
7226 | && bs->breakpoint_at->owner->disposition == disp_del | |
c906108c | 7227 | && bs->stop) |
4f8d1dc6 | 7228 | delete_breakpoint (bs->breakpoint_at->owner); |
c906108c SS |
7229 | |
7230 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b | 7231 | { |
b5de0fa7 | 7232 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
7233 | delete_breakpoint (b); |
7234 | } | |
c906108c SS |
7235 | } |
7236 | ||
f7545552 TT |
7237 | /* A cleanup function which destroys a vector. */ |
7238 | ||
7239 | static void | |
7240 | do_vec_free (void *p) | |
7241 | { | |
7242 | VEC(bp_location_p) **vec = p; | |
7243 | if (*vec) | |
7244 | VEC_free (bp_location_p, *vec); | |
7245 | } | |
7246 | ||
4cd9bd08 | 7247 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
b60e7edf PA |
7248 | into the inferior, only remove already-inserted locations that no |
7249 | longer should be inserted. Functions that delete a breakpoint or | |
7250 | breakpoints should pass false, so that deleting a breakpoint | |
7251 | doesn't have the side effect of inserting the locations of other | |
7252 | breakpoints that are marked not-inserted, but should_be_inserted | |
7253 | returns true on them. | |
7254 | ||
7255 | This behaviour is useful is situations close to tear-down -- e.g., | |
7256 | after an exec, while the target still has execution, but breakpoint | |
7257 | shadows of the previous executable image should *NOT* be restored | |
7258 | to the new image; or before detaching, where the target still has | |
7259 | execution and wants to delete breakpoints from GDB's lists, and all | |
7260 | breakpoints had already been removed from the inferior. */ | |
7261 | ||
0d381245 | 7262 | static void |
b60e7edf | 7263 | update_global_location_list (int should_insert) |
0d381245 | 7264 | { |
74960c60 VP |
7265 | struct breakpoint *b; |
7266 | struct bp_location **next = &bp_location_chain; | |
7267 | struct bp_location *loc; | |
7268 | struct bp_location *loc2; | |
74960c60 VP |
7269 | VEC(bp_location_p) *old_locations = NULL; |
7270 | int ret; | |
7271 | int ix; | |
f7545552 TT |
7272 | struct cleanup *cleanups; |
7273 | ||
7274 | cleanups = make_cleanup (do_vec_free, &old_locations); | |
74960c60 VP |
7275 | /* Store old locations for future reference. */ |
7276 | for (loc = bp_location_chain; loc; loc = loc->global_next) | |
7277 | VEC_safe_push (bp_location_p, old_locations, loc); | |
0d381245 | 7278 | |
74960c60 VP |
7279 | bp_location_chain = NULL; |
7280 | ALL_BREAKPOINTS (b) | |
0d381245 | 7281 | { |
74960c60 | 7282 | for (loc = b->loc; loc; loc = loc->next) |
0d381245 | 7283 | { |
74960c60 VP |
7284 | *next = loc; |
7285 | next = &(loc->global_next); | |
7286 | *next = NULL; | |
0d381245 | 7287 | } |
74960c60 VP |
7288 | } |
7289 | ||
7290 | /* Identify bp_location instances that are no longer present in the new | |
7291 | list, and therefore should be freed. Note that it's not necessary that | |
7292 | those locations should be removed from inferior -- if there's another | |
7293 | location at the same address (previously marked as duplicate), | |
7294 | we don't need to remove/insert the location. */ | |
7295 | for (ix = 0; VEC_iterate(bp_location_p, old_locations, ix, loc); ++ix) | |
7296 | { | |
7297 | /* Tells if 'loc' is found amoung the new locations. If not, we | |
7298 | have to free it. */ | |
7299 | int found_object = 0; | |
20874c92 VP |
7300 | /* Tells if the location should remain inserted in the target. */ |
7301 | int keep_in_target = 0; | |
7302 | int removed = 0; | |
74960c60 VP |
7303 | for (loc2 = bp_location_chain; loc2; loc2 = loc2->global_next) |
7304 | if (loc2 == loc) | |
7305 | { | |
7306 | found_object = 1; | |
7307 | break; | |
7308 | } | |
7309 | ||
7310 | /* If this location is no longer present, and inserted, look if there's | |
7311 | maybe a new location at the same address. If so, mark that one | |
7312 | inserted, and don't remove this one. This is needed so that we | |
7313 | don't have a time window where a breakpoint at certain location is not | |
7314 | inserted. */ | |
7315 | ||
7316 | if (loc->inserted) | |
0d381245 | 7317 | { |
74960c60 | 7318 | /* If the location is inserted now, we might have to remove it. */ |
74960c60 VP |
7319 | |
7320 | if (found_object && should_be_inserted (loc)) | |
7321 | { | |
7322 | /* The location is still present in the location list, and still | |
7323 | should be inserted. Don't do anything. */ | |
20874c92 | 7324 | keep_in_target = 1; |
74960c60 VP |
7325 | } |
7326 | else | |
7327 | { | |
7328 | /* The location is either no longer present, or got disabled. | |
7329 | See if there's another location at the same address, in which | |
7330 | case we don't need to remove this one from the target. */ | |
7331 | if (breakpoint_address_is_meaningful (loc->owner)) | |
7332 | for (loc2 = bp_location_chain; loc2; loc2 = loc2->global_next) | |
7333 | { | |
7334 | /* For the sake of should_insert_location. The | |
7335 | call to check_duplicates will fix up this later. */ | |
7336 | loc2->duplicate = 0; | |
7337 | if (should_be_inserted (loc2) | |
7338 | && loc2 != loc && loc2->address == loc->address) | |
7339 | { | |
7340 | loc2->inserted = 1; | |
7341 | loc2->target_info = loc->target_info; | |
20874c92 | 7342 | keep_in_target = 1; |
74960c60 VP |
7343 | break; |
7344 | } | |
7345 | } | |
7346 | } | |
7347 | ||
20874c92 VP |
7348 | if (!keep_in_target) |
7349 | { | |
7350 | if (remove_breakpoint (loc, mark_uninserted)) | |
7351 | { | |
7352 | /* This is just about all we can do. We could keep this | |
7353 | location on the global list, and try to remove it next | |
7354 | time, but there's no particular reason why we will | |
7355 | succeed next time. | |
7356 | ||
7357 | Note that at this point, loc->owner is still valid, | |
7358 | as delete_breakpoint frees the breakpoint only | |
7359 | after calling us. */ | |
7360 | printf_filtered (_("warning: Error removing breakpoint %d\n"), | |
7361 | loc->owner->number); | |
7362 | } | |
7363 | removed = 1; | |
7364 | } | |
0d381245 | 7365 | } |
74960c60 VP |
7366 | |
7367 | if (!found_object) | |
1c5cfe86 PA |
7368 | { |
7369 | if (removed && non_stop) | |
20874c92 VP |
7370 | { |
7371 | /* This location was removed from the targets. In non-stop mode, | |
7372 | a race condition is possible where we've removed a breakpoint, | |
7373 | but stop events for that breakpoint are already queued and will | |
7374 | arrive later. To suppress spurious SIGTRAPs reported to user, | |
7375 | we keep this breakpoint location for a bit, and will retire it | |
7376 | after we see 3 * thread_count events. | |
1c5cfe86 | 7377 | The theory here is that reporting of events should, |
20874c92 VP |
7378 | "on the average", be fair, so after that many event we'll see |
7379 | events from all threads that have anything of interest, and no | |
1c5cfe86 | 7380 | longer need to keep this breakpoint. This is just a |
20874c92 | 7381 | heuristic, but if it's wrong, we'll report unexpected SIGTRAP, |
1c5cfe86 | 7382 | which is usability issue, but not a correctness problem. */ |
20874c92 VP |
7383 | loc->events_till_retirement = 3 * (thread_count () + 1); |
7384 | loc->owner = NULL; | |
20874c92 | 7385 | |
1c5cfe86 PA |
7386 | VEC_safe_push (bp_location_p, moribund_locations, loc); |
7387 | } | |
7388 | else | |
7389 | free_bp_location (loc); | |
20874c92 | 7390 | } |
74960c60 | 7391 | } |
1c5cfe86 | 7392 | |
74960c60 VP |
7393 | ALL_BREAKPOINTS (b) |
7394 | { | |
7395 | check_duplicates (b); | |
0d381245 | 7396 | } |
74960c60 | 7397 | |
50c71eaf | 7398 | if (breakpoints_always_inserted_mode () && should_insert |
c35b1492 | 7399 | && (have_live_inferiors () |
2567c7d9 | 7400 | || (gdbarch_has_global_breakpoints (target_gdbarch)))) |
74960c60 | 7401 | insert_breakpoint_locations (); |
f7545552 TT |
7402 | |
7403 | do_cleanups (cleanups); | |
74960c60 VP |
7404 | } |
7405 | ||
20874c92 VP |
7406 | void |
7407 | breakpoint_retire_moribund (void) | |
7408 | { | |
7409 | struct bp_location *loc; | |
7410 | int ix; | |
7411 | ||
7412 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
7413 | if (--(loc->events_till_retirement) == 0) | |
7414 | { | |
7415 | free_bp_location (loc); | |
7416 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
7417 | --ix; | |
7418 | } | |
7419 | } | |
7420 | ||
74960c60 | 7421 | static void |
b60e7edf | 7422 | update_global_location_list_nothrow (int inserting) |
74960c60 VP |
7423 | { |
7424 | struct gdb_exception e; | |
7425 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
b60e7edf | 7426 | update_global_location_list (inserting); |
0d381245 VP |
7427 | } |
7428 | ||
a474d7c2 PA |
7429 | /* Clear BPT from a BPS. */ |
7430 | static void | |
7431 | bpstat_remove_breakpoint (bpstat bps, struct breakpoint *bpt) | |
7432 | { | |
7433 | bpstat bs; | |
7434 | for (bs = bps; bs; bs = bs->next) | |
7435 | if (bs->breakpoint_at && bs->breakpoint_at->owner == bpt) | |
7436 | { | |
7437 | bs->breakpoint_at = NULL; | |
7438 | bs->old_val = NULL; | |
7439 | /* bs->commands will be freed later. */ | |
7440 | } | |
7441 | } | |
7442 | ||
7443 | /* Callback for iterate_over_threads. */ | |
7444 | static int | |
7445 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
7446 | { | |
7447 | struct breakpoint *bpt = data; | |
7448 | bpstat_remove_breakpoint (th->stop_bpstat, bpt); | |
7449 | return 0; | |
7450 | } | |
7451 | ||
53a5351d JM |
7452 | /* Delete a breakpoint and clean up all traces of it in the data |
7453 | structures. */ | |
c906108c SS |
7454 | |
7455 | void | |
fba45db2 | 7456 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 7457 | { |
52f0bd74 | 7458 | struct breakpoint *b; |
74960c60 | 7459 | struct bp_location *loc, *next; |
c906108c | 7460 | |
8a3fe4f8 | 7461 | gdb_assert (bpt != NULL); |
c906108c SS |
7462 | |
7463 | /* Has this bp already been deleted? This can happen because multiple | |
7464 | lists can hold pointers to bp's. bpstat lists are especial culprits. | |
7465 | ||
7466 | One example of this happening is a watchpoint's scope bp. When the | |
7467 | scope bp triggers, we notice that the watchpoint is out of scope, and | |
7468 | delete it. We also delete its scope bp. But the scope bp is marked | |
7469 | "auto-deleting", and is already on a bpstat. That bpstat is then | |
7470 | checked for auto-deleting bp's, which are deleted. | |
7471 | ||
7472 | A real solution to this problem might involve reference counts in bp's, | |
7473 | and/or giving them pointers back to their referencing bpstat's, and | |
7474 | teaching delete_breakpoint to only free a bp's storage when no more | |
1272ad14 | 7475 | references were extent. A cheaper bandaid was chosen. */ |
c906108c SS |
7476 | if (bpt->type == bp_none) |
7477 | return; | |
7478 | ||
383f836e | 7479 | observer_notify_breakpoint_deleted (bpt->number); |
c906108c | 7480 | |
c906108c SS |
7481 | if (breakpoint_chain == bpt) |
7482 | breakpoint_chain = bpt->next; | |
7483 | ||
c906108c SS |
7484 | ALL_BREAKPOINTS (b) |
7485 | if (b->next == bpt) | |
c5aa993b JM |
7486 | { |
7487 | b->next = bpt->next; | |
7488 | break; | |
7489 | } | |
c906108c | 7490 | |
c906108c | 7491 | free_command_lines (&bpt->commands); |
c906108c | 7492 | if (bpt->cond_string != NULL) |
b8c9b27d | 7493 | xfree (bpt->cond_string); |
c906108c | 7494 | if (bpt->addr_string != NULL) |
b8c9b27d | 7495 | xfree (bpt->addr_string); |
c906108c | 7496 | if (bpt->exp != NULL) |
b8c9b27d | 7497 | xfree (bpt->exp); |
c906108c | 7498 | if (bpt->exp_string != NULL) |
b8c9b27d | 7499 | xfree (bpt->exp_string); |
c906108c SS |
7500 | if (bpt->val != NULL) |
7501 | value_free (bpt->val); | |
7502 | if (bpt->source_file != NULL) | |
b8c9b27d | 7503 | xfree (bpt->source_file); |
c906108c | 7504 | if (bpt->exec_pathname != NULL) |
b8c9b27d | 7505 | xfree (bpt->exec_pathname); |
c906108c SS |
7506 | |
7507 | /* Be sure no bpstat's are pointing at it after it's been freed. */ | |
7508 | /* FIXME, how can we find all bpstat's? | |
198757a8 VP |
7509 | We just check stop_bpstat for now. Note that we cannot just |
7510 | remove bpstats pointing at bpt from the stop_bpstat list | |
7511 | entirely, as breakpoint commands are associated with the bpstat; | |
7512 | if we remove it here, then the later call to | |
7513 | bpstat_do_actions (&stop_bpstat); | |
7514 | in event-top.c won't do anything, and temporary breakpoints | |
7515 | with commands won't work. */ | |
a474d7c2 | 7516 | |
a474d7c2 | 7517 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); |
74960c60 VP |
7518 | |
7519 | /* Now that breakpoint is removed from breakpoint | |
7520 | list, update the global location list. This | |
7521 | will remove locations that used to belong to | |
7522 | this breakpoint. Do this before freeing | |
7523 | the breakpoint itself, since remove_breakpoint | |
7524 | looks at location's owner. It might be better | |
7525 | design to have location completely self-contained, | |
7526 | but it's not the case now. */ | |
b60e7edf | 7527 | update_global_location_list (0); |
74960c60 VP |
7528 | |
7529 | ||
c906108c SS |
7530 | /* On the chance that someone will soon try again to delete this same |
7531 | bp, we mark it as deleted before freeing its storage. */ | |
7532 | bpt->type = bp_none; | |
7533 | ||
b8c9b27d | 7534 | xfree (bpt); |
c906108c SS |
7535 | } |
7536 | ||
4d6140d9 AC |
7537 | static void |
7538 | do_delete_breakpoint_cleanup (void *b) | |
7539 | { | |
7540 | delete_breakpoint (b); | |
7541 | } | |
7542 | ||
7543 | struct cleanup * | |
7544 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
7545 | { | |
7546 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
7547 | } | |
7548 | ||
c906108c | 7549 | void |
fba45db2 | 7550 | delete_command (char *arg, int from_tty) |
c906108c SS |
7551 | { |
7552 | struct breakpoint *b, *temp; | |
7553 | ||
ea9365bb TT |
7554 | dont_repeat (); |
7555 | ||
c906108c SS |
7556 | if (arg == 0) |
7557 | { | |
7558 | int breaks_to_delete = 0; | |
7559 | ||
7560 | /* Delete all breakpoints if no argument. | |
c5aa993b JM |
7561 | Do not delete internal or call-dummy breakpoints, these |
7562 | have to be deleted with an explicit breakpoint number argument. */ | |
7563 | ALL_BREAKPOINTS (b) | |
7564 | { | |
059fb39f PM |
7565 | if (b->type != bp_call_dummy |
7566 | && b->type != bp_shlib_event | |
7567 | && b->type != bp_thread_event | |
7568 | && b->type != bp_overlay_event | |
0fd8e87f | 7569 | && b->type != bp_longjmp_master |
059fb39f | 7570 | && b->number >= 0) |
973d738b DJ |
7571 | { |
7572 | breaks_to_delete = 1; | |
7573 | break; | |
7574 | } | |
c5aa993b | 7575 | } |
c906108c SS |
7576 | |
7577 | /* Ask user only if there are some breakpoints to delete. */ | |
7578 | if (!from_tty | |
e2e0b3e5 | 7579 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 7580 | { |
c5aa993b JM |
7581 | ALL_BREAKPOINTS_SAFE (b, temp) |
7582 | { | |
059fb39f PM |
7583 | if (b->type != bp_call_dummy |
7584 | && b->type != bp_shlib_event | |
7585 | && b->type != bp_thread_event | |
7586 | && b->type != bp_overlay_event | |
0fd8e87f | 7587 | && b->type != bp_longjmp_master |
059fb39f | 7588 | && b->number >= 0) |
c5aa993b JM |
7589 | delete_breakpoint (b); |
7590 | } | |
c906108c SS |
7591 | } |
7592 | } | |
7593 | else | |
7594 | map_breakpoint_numbers (arg, delete_breakpoint); | |
7595 | } | |
7596 | ||
0d381245 VP |
7597 | static int |
7598 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 7599 | { |
0d381245 VP |
7600 | for (; loc; loc = loc->next) |
7601 | if (!loc->shlib_disabled) | |
7602 | return 0; | |
7603 | return 1; | |
fe3f5fa8 VP |
7604 | } |
7605 | ||
776592bf DE |
7606 | /* Subroutine of update_breakpoint_locations to simplify it. |
7607 | Return non-zero if multiple fns in list LOC have the same name. | |
7608 | Null names are ignored. */ | |
7609 | ||
7610 | static int | |
7611 | ambiguous_names_p (struct bp_location *loc) | |
7612 | { | |
7613 | struct bp_location *l; | |
7614 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
7615 | (int (*) (const void *, const void *)) streq, | |
7616 | NULL, xcalloc, xfree); | |
7617 | ||
7618 | for (l = loc; l != NULL; l = l->next) | |
7619 | { | |
7620 | const char **slot; | |
7621 | const char *name = l->function_name; | |
7622 | ||
7623 | /* Allow for some names to be NULL, ignore them. */ | |
7624 | if (name == NULL) | |
7625 | continue; | |
7626 | ||
7627 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
7628 | INSERT); | |
7629 | /* NOTE: We can assume slot != NULL here because xcalloc never returns | |
7630 | NULL. */ | |
7631 | if (*slot != NULL) | |
7632 | { | |
7633 | htab_delete (htab); | |
7634 | return 1; | |
7635 | } | |
7636 | *slot = name; | |
7637 | } | |
7638 | ||
7639 | htab_delete (htab); | |
7640 | return 0; | |
7641 | } | |
7642 | ||
fe3f5fa8 | 7643 | static void |
0d381245 VP |
7644 | update_breakpoint_locations (struct breakpoint *b, |
7645 | struct symtabs_and_lines sals) | |
fe3f5fa8 VP |
7646 | { |
7647 | int i; | |
7648 | char *s; | |
0d381245 VP |
7649 | struct bp_location *existing_locations = b->loc; |
7650 | ||
7651 | /* If there's no new locations, and all existing locations | |
7652 | are pending, don't do anything. This optimizes | |
7653 | the common case where all locations are in the same | |
7654 | shared library, that was unloaded. We'd like to | |
7655 | retain the location, so that when the library | |
7656 | is loaded again, we don't loose the enabled/disabled | |
7657 | status of the individual locations. */ | |
7658 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) | |
fe3f5fa8 VP |
7659 | return; |
7660 | ||
fe3f5fa8 VP |
7661 | b->loc = NULL; |
7662 | ||
0d381245 | 7663 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 7664 | { |
0d381245 | 7665 | struct bp_location *new_loc = |
39d61571 | 7666 | add_location_to_breakpoint (b, &(sals.sals[i])); |
fe3f5fa8 | 7667 | |
0d381245 VP |
7668 | /* Reparse conditions, they might contain references to the |
7669 | old symtab. */ | |
7670 | if (b->cond_string != NULL) | |
7671 | { | |
7672 | struct gdb_exception e; | |
fe3f5fa8 | 7673 | |
0d381245 VP |
7674 | s = b->cond_string; |
7675 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
7676 | { | |
7677 | new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), | |
7678 | 0); | |
7679 | } | |
7680 | if (e.reason < 0) | |
7681 | { | |
7682 | warning (_("failed to reevaluate condition for breakpoint %d: %s"), | |
7683 | b->number, e.message); | |
7684 | new_loc->enabled = 0; | |
7685 | } | |
7686 | } | |
fe3f5fa8 | 7687 | |
0d381245 VP |
7688 | if (b->source_file != NULL) |
7689 | xfree (b->source_file); | |
7690 | if (sals.sals[i].symtab == NULL) | |
7691 | b->source_file = NULL; | |
7692 | else | |
1b36a34b | 7693 | b->source_file = xstrdup (sals.sals[i].symtab->filename); |
fe3f5fa8 | 7694 | |
0d381245 VP |
7695 | if (b->line_number == 0) |
7696 | b->line_number = sals.sals[i].line; | |
7697 | } | |
fe3f5fa8 | 7698 | |
514f746b AR |
7699 | /* Update locations of permanent breakpoints. */ |
7700 | if (b->enable_state == bp_permanent) | |
7701 | make_breakpoint_permanent (b); | |
7702 | ||
0d381245 VP |
7703 | /* If possible, carry over 'disable' status from existing breakpoints. */ |
7704 | { | |
7705 | struct bp_location *e = existing_locations; | |
776592bf DE |
7706 | /* If there are multiple breakpoints with the same function name, |
7707 | e.g. for inline functions, comparing function names won't work. | |
7708 | Instead compare pc addresses; this is just a heuristic as things | |
7709 | may have moved, but in practice it gives the correct answer | |
7710 | often enough until a better solution is found. */ | |
7711 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
7712 | ||
0d381245 VP |
7713 | for (; e; e = e->next) |
7714 | { | |
7715 | if (!e->enabled && e->function_name) | |
7716 | { | |
7717 | struct bp_location *l = b->loc; | |
776592bf DE |
7718 | if (have_ambiguous_names) |
7719 | { | |
7720 | for (; l; l = l->next) | |
7721 | if (e->address == l->address) | |
7722 | { | |
7723 | l->enabled = 0; | |
7724 | break; | |
7725 | } | |
7726 | } | |
7727 | else | |
7728 | { | |
7729 | for (; l; l = l->next) | |
7730 | if (l->function_name | |
7731 | && strcmp (e->function_name, l->function_name) == 0) | |
7732 | { | |
7733 | l->enabled = 0; | |
7734 | break; | |
7735 | } | |
7736 | } | |
0d381245 VP |
7737 | } |
7738 | } | |
7739 | } | |
fe3f5fa8 | 7740 | |
b60e7edf | 7741 | update_global_location_list (1); |
fe3f5fa8 VP |
7742 | } |
7743 | ||
7744 | ||
c906108c SS |
7745 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
7746 | The value we return ends up being the return value from catch_errors. | |
7747 | Unused in this case. */ | |
7748 | ||
7749 | static int | |
4efb68b1 | 7750 | breakpoint_re_set_one (void *bint) |
c906108c | 7751 | { |
53a5351d JM |
7752 | /* get past catch_errs */ |
7753 | struct breakpoint *b = (struct breakpoint *) bint; | |
c906108c SS |
7754 | struct value *mark; |
7755 | int i; | |
fe3f5fa8 VP |
7756 | int not_found = 0; |
7757 | int *not_found_ptr = ¬_found; | |
7758 | struct symtabs_and_lines sals = {}; | |
ed0616c6 | 7759 | struct symtabs_and_lines expanded; |
c906108c | 7760 | char *s; |
b5de0fa7 | 7761 | enum enable_state save_enable; |
fe3f5fa8 | 7762 | struct gdb_exception e; |
f7545552 | 7763 | struct cleanup *cleanups; |
c906108c SS |
7764 | |
7765 | switch (b->type) | |
7766 | { | |
7767 | case bp_none: | |
8a3fe4f8 | 7768 | warning (_("attempted to reset apparently deleted breakpoint #%d?"), |
53a5351d | 7769 | b->number); |
c906108c SS |
7770 | return 0; |
7771 | case bp_breakpoint: | |
7772 | case bp_hardware_breakpoint: | |
1042e4c0 | 7773 | case bp_tracepoint: |
c906108c SS |
7774 | if (b->addr_string == NULL) |
7775 | { | |
7776 | /* Anything without a string can't be re-set. */ | |
7777 | delete_breakpoint (b); | |
7778 | return 0; | |
7779 | } | |
c906108c SS |
7780 | |
7781 | set_language (b->language); | |
7782 | input_radix = b->input_radix; | |
7783 | s = b->addr_string; | |
fe3f5fa8 | 7784 | TRY_CATCH (e, RETURN_MASK_ERROR) |
c906108c | 7785 | { |
fe3f5fa8 VP |
7786 | sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL, |
7787 | not_found_ptr); | |
7788 | } | |
7789 | if (e.reason < 0) | |
7790 | { | |
7791 | int not_found_and_ok = 0; | |
7792 | /* For pending breakpoints, it's expected that parsing | |
7793 | will fail until the right shared library is loaded. | |
7794 | User has already told to create pending breakpoints and | |
7795 | don't need extra messages. If breakpoint is in bp_shlib_disabled | |
7796 | state, then user already saw the message about that breakpoint | |
7797 | being disabled, and don't want to see more errors. */ | |
0d381245 VP |
7798 | if (not_found |
7799 | && (b->condition_not_parsed | |
7800 | || (b->loc && b->loc->shlib_disabled) | |
7801 | || b->enable_state == bp_disabled)) | |
fe3f5fa8 VP |
7802 | not_found_and_ok = 1; |
7803 | ||
7804 | if (!not_found_and_ok) | |
c906108c | 7805 | { |
fe3f5fa8 VP |
7806 | /* We surely don't want to warn about the same breakpoint |
7807 | 10 times. One solution, implemented here, is disable | |
7808 | the breakpoint on error. Another solution would be to | |
7809 | have separate 'warning emitted' flag. Since this | |
7810 | happens only when a binary has changed, I don't know | |
7811 | which approach is better. */ | |
7812 | b->enable_state = bp_disabled; | |
7813 | throw_exception (e); | |
c906108c | 7814 | } |
fe3f5fa8 | 7815 | } |
c906108c | 7816 | |
fe3f5fa8 VP |
7817 | if (not_found) |
7818 | break; | |
7819 | ||
7820 | gdb_assert (sals.nelts == 1); | |
7821 | resolve_sal_pc (&sals.sals[0]); | |
0d381245 | 7822 | if (b->condition_not_parsed && s && s[0]) |
fe3f5fa8 VP |
7823 | { |
7824 | char *cond_string = 0; | |
7825 | int thread = -1; | |
4a306c9a JB |
7826 | int task = 0; |
7827 | ||
fe3f5fa8 | 7828 | find_condition_and_thread (s, sals.sals[0].pc, |
4a306c9a | 7829 | &cond_string, &thread, &task); |
fe3f5fa8 VP |
7830 | if (cond_string) |
7831 | b->cond_string = cond_string; | |
7832 | b->thread = thread; | |
4a306c9a | 7833 | b->task = task; |
0d381245 | 7834 | b->condition_not_parsed = 0; |
fe3f5fa8 | 7835 | } |
ed0616c6 | 7836 | expanded = expand_line_sal_maybe (sals.sals[0]); |
f7545552 | 7837 | cleanups = make_cleanup (xfree, sals.sals); |
ed0616c6 | 7838 | update_breakpoint_locations (b, expanded); |
f7545552 | 7839 | do_cleanups (cleanups); |
c906108c SS |
7840 | break; |
7841 | ||
7842 | case bp_watchpoint: | |
7843 | case bp_hardware_watchpoint: | |
7844 | case bp_read_watchpoint: | |
7845 | case bp_access_watchpoint: | |
0b3de036 VP |
7846 | /* Watchpoint can be either on expression using entirely global variables, |
7847 | or it can be on local variables. | |
7848 | ||
7849 | Watchpoints of the first kind are never auto-deleted, and even persist | |
7850 | across program restarts. Since they can use variables from shared | |
7851 | libraries, we need to reparse expression as libraries are loaded | |
7852 | and unloaded. | |
7853 | ||
7854 | Watchpoints on local variables can also change meaning as result | |
7855 | of solib event. For example, if a watchpoint uses both a local and | |
7856 | a global variables in expression, it's a local watchpoint, but | |
7857 | unloading of a shared library will make the expression invalid. | |
7858 | This is not a very common use case, but we still re-evaluate | |
7859 | expression, to avoid surprises to the user. | |
7860 | ||
7861 | Note that for local watchpoints, we re-evaluate it only if | |
7862 | watchpoints frame id is still valid. If it's not, it means | |
7863 | the watchpoint is out of scope and will be deleted soon. In fact, | |
7864 | I'm not sure we'll ever be called in this case. | |
7865 | ||
7866 | If a local watchpoint's frame id is still valid, then | |
7867 | b->exp_valid_block is likewise valid, and we can safely use it. | |
7868 | ||
7869 | Don't do anything about disabled watchpoints, since they will | |
7870 | be reevaluated again when enabled. */ | |
a5606eee | 7871 | update_watchpoint (b, 1 /* reparse */); |
c906108c | 7872 | break; |
c5aa993b JM |
7873 | /* We needn't really do anything to reset these, since the mask |
7874 | that requests them is unaffected by e.g., new libraries being | |
7875 | loaded. */ | |
ce78b96d | 7876 | case bp_catchpoint: |
c906108c | 7877 | break; |
c5aa993b | 7878 | |
c906108c | 7879 | default: |
a3f17187 | 7880 | printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type); |
c906108c | 7881 | /* fall through */ |
0fd8e87f UW |
7882 | /* Delete overlay event and longjmp master breakpoints; they will be |
7883 | reset later by breakpoint_re_set. */ | |
1900040c | 7884 | case bp_overlay_event: |
0fd8e87f | 7885 | case bp_longjmp_master: |
c906108c SS |
7886 | delete_breakpoint (b); |
7887 | break; | |
7888 | ||
c5aa993b JM |
7889 | /* This breakpoint is special, it's set up when the inferior |
7890 | starts and we really don't want to touch it. */ | |
c906108c SS |
7891 | case bp_shlib_event: |
7892 | ||
c4093a6a JM |
7893 | /* Like bp_shlib_event, this breakpoint type is special. |
7894 | Once it is set up, we do not want to touch it. */ | |
7895 | case bp_thread_event: | |
7896 | ||
c5aa993b JM |
7897 | /* Keep temporary breakpoints, which can be encountered when we step |
7898 | over a dlopen call and SOLIB_ADD is resetting the breakpoints. | |
7899 | Otherwise these should have been blown away via the cleanup chain | |
7900 | or by breakpoint_init_inferior when we rerun the executable. */ | |
c906108c SS |
7901 | case bp_until: |
7902 | case bp_finish: | |
7903 | case bp_watchpoint_scope: | |
7904 | case bp_call_dummy: | |
7905 | case bp_step_resume: | |
611c83ae PA |
7906 | case bp_longjmp: |
7907 | case bp_longjmp_resume: | |
c906108c SS |
7908 | break; |
7909 | } | |
7910 | ||
7911 | return 0; | |
7912 | } | |
7913 | ||
69de3c6a | 7914 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 7915 | void |
69de3c6a | 7916 | breakpoint_re_set (void) |
c906108c SS |
7917 | { |
7918 | struct breakpoint *b, *temp; | |
7919 | enum language save_language; | |
7920 | int save_input_radix; | |
c5aa993b | 7921 | |
c906108c SS |
7922 | save_language = current_language->la_language; |
7923 | save_input_radix = input_radix; | |
7924 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b | 7925 | { |
53a5351d | 7926 | /* Format possible error msg */ |
fe3f5fa8 | 7927 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
7928 | b->number); |
7929 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 7930 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 7931 | do_cleanups (cleanups); |
c5aa993b | 7932 | } |
c906108c SS |
7933 | set_language (save_language); |
7934 | input_radix = save_input_radix; | |
e62c965a | 7935 | |
69de3c6a | 7936 | create_overlay_event_breakpoint ("_ovly_debug_event"); |
0fd8e87f UW |
7937 | create_longjmp_master_breakpoint ("longjmp"); |
7938 | create_longjmp_master_breakpoint ("_longjmp"); | |
7939 | create_longjmp_master_breakpoint ("siglongjmp"); | |
7940 | create_longjmp_master_breakpoint ("_siglongjmp"); | |
c906108c SS |
7941 | } |
7942 | \f | |
c906108c SS |
7943 | /* Reset the thread number of this breakpoint: |
7944 | ||
7945 | - If the breakpoint is for all threads, leave it as-is. | |
39f77062 | 7946 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 7947 | void |
fba45db2 | 7948 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
7949 | { |
7950 | if (b->thread != -1) | |
7951 | { | |
39f77062 KB |
7952 | if (in_thread_list (inferior_ptid)) |
7953 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c SS |
7954 | } |
7955 | } | |
7956 | ||
03ac34d5 MS |
7957 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
7958 | If from_tty is nonzero, it prints a message to that effect, | |
7959 | which ends with a period (no newline). */ | |
7960 | ||
c906108c | 7961 | void |
fba45db2 | 7962 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 7963 | { |
52f0bd74 | 7964 | struct breakpoint *b; |
c906108c SS |
7965 | |
7966 | if (count < 0) | |
7967 | count = 0; | |
7968 | ||
7969 | ALL_BREAKPOINTS (b) | |
7970 | if (b->number == bptnum) | |
c5aa993b JM |
7971 | { |
7972 | b->ignore_count = count; | |
221ea385 KS |
7973 | if (from_tty) |
7974 | { | |
7975 | if (count == 0) | |
a3f17187 | 7976 | printf_filtered (_("Will stop next time breakpoint %d is reached."), |
221ea385 KS |
7977 | bptnum); |
7978 | else if (count == 1) | |
a3f17187 | 7979 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
7980 | bptnum); |
7981 | else | |
a3f17187 | 7982 | printf_filtered (_("Will ignore next %d crossings of breakpoint %d."), |
221ea385 KS |
7983 | count, bptnum); |
7984 | } | |
c5aa993b | 7985 | breakpoints_changed (); |
383f836e | 7986 | observer_notify_breakpoint_modified (b->number); |
c5aa993b JM |
7987 | return; |
7988 | } | |
c906108c | 7989 | |
8a3fe4f8 | 7990 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
7991 | } |
7992 | ||
b2175913 MS |
7993 | void |
7994 | make_breakpoint_silent (struct breakpoint *b) | |
7995 | { | |
7996 | /* Silence the breakpoint. */ | |
7997 | b->silent = 1; | |
7998 | } | |
7999 | ||
c906108c SS |
8000 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
8001 | ||
8002 | static void | |
fba45db2 | 8003 | ignore_command (char *args, int from_tty) |
c906108c SS |
8004 | { |
8005 | char *p = args; | |
52f0bd74 | 8006 | int num; |
c906108c SS |
8007 | |
8008 | if (p == 0) | |
e2e0b3e5 | 8009 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 8010 | |
c906108c | 8011 | num = get_number (&p); |
5c44784c | 8012 | if (num == 0) |
8a3fe4f8 | 8013 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 8014 | if (*p == 0) |
8a3fe4f8 | 8015 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
8016 | |
8017 | set_ignore_count (num, | |
8018 | longest_to_int (value_as_long (parse_and_eval (p))), | |
8019 | from_tty); | |
221ea385 KS |
8020 | if (from_tty) |
8021 | printf_filtered ("\n"); | |
c906108c SS |
8022 | } |
8023 | \f | |
8024 | /* Call FUNCTION on each of the breakpoints | |
8025 | whose numbers are given in ARGS. */ | |
8026 | ||
8027 | static void | |
831662b3 | 8028 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *)) |
c906108c | 8029 | { |
52f0bd74 | 8030 | char *p = args; |
c906108c | 8031 | char *p1; |
52f0bd74 AC |
8032 | int num; |
8033 | struct breakpoint *b, *tmp; | |
11cf8741 | 8034 | int match; |
c906108c SS |
8035 | |
8036 | if (p == 0) | |
e2e0b3e5 | 8037 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c SS |
8038 | |
8039 | while (*p) | |
8040 | { | |
11cf8741 | 8041 | match = 0; |
c906108c | 8042 | p1 = p; |
c5aa993b | 8043 | |
5c44784c JM |
8044 | num = get_number_or_range (&p1); |
8045 | if (num == 0) | |
c5aa993b | 8046 | { |
8a3fe4f8 | 8047 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
8048 | } |
8049 | else | |
8050 | { | |
8051 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
8052 | if (b->number == num) | |
8053 | { | |
8054 | struct breakpoint *related_breakpoint = b->related_breakpoint; | |
11cf8741 | 8055 | match = 1; |
5c44784c JM |
8056 | function (b); |
8057 | if (related_breakpoint) | |
8058 | function (related_breakpoint); | |
11cf8741 | 8059 | break; |
5c44784c | 8060 | } |
11cf8741 | 8061 | if (match == 0) |
a3f17187 | 8062 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 8063 | } |
c906108c SS |
8064 | p = p1; |
8065 | } | |
8066 | } | |
8067 | ||
0d381245 VP |
8068 | static struct bp_location * |
8069 | find_location_by_number (char *number) | |
8070 | { | |
8071 | char *dot = strchr (number, '.'); | |
8072 | char *p1; | |
8073 | int bp_num; | |
8074 | int loc_num; | |
8075 | struct breakpoint *b; | |
8076 | struct bp_location *loc; | |
8077 | ||
8078 | *dot = '\0'; | |
8079 | ||
8080 | p1 = number; | |
8081 | bp_num = get_number_or_range (&p1); | |
8082 | if (bp_num == 0) | |
8083 | error (_("Bad breakpoint number '%s'"), number); | |
8084 | ||
8085 | ALL_BREAKPOINTS (b) | |
8086 | if (b->number == bp_num) | |
8087 | { | |
8088 | break; | |
8089 | } | |
8090 | ||
8091 | if (!b || b->number != bp_num) | |
8092 | error (_("Bad breakpoint number '%s'"), number); | |
8093 | ||
8094 | p1 = dot+1; | |
8095 | loc_num = get_number_or_range (&p1); | |
8096 | if (loc_num == 0) | |
8097 | error (_("Bad breakpoint location number '%s'"), number); | |
8098 | ||
8099 | --loc_num; | |
8100 | loc = b->loc; | |
8101 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
8102 | ; | |
8103 | if (!loc) | |
8104 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
8105 | ||
8106 | return loc; | |
8107 | } | |
8108 | ||
8109 | ||
1900040c MS |
8110 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
8111 | If from_tty is nonzero, it prints a message to that effect, | |
8112 | which ends with a period (no newline). */ | |
8113 | ||
c906108c | 8114 | void |
fba45db2 | 8115 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
8116 | { |
8117 | /* Never disable a watchpoint scope breakpoint; we want to | |
8118 | hit them when we leave scope so we can delete both the | |
8119 | watchpoint and its scope breakpoint at that time. */ | |
8120 | if (bpt->type == bp_watchpoint_scope) | |
8121 | return; | |
8122 | ||
c2c6d25f | 8123 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 8124 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
8125 | return; |
8126 | ||
b5de0fa7 | 8127 | bpt->enable_state = bp_disabled; |
c906108c | 8128 | |
b60e7edf | 8129 | update_global_location_list (0); |
c906108c | 8130 | |
383f836e | 8131 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
8132 | } |
8133 | ||
c906108c | 8134 | static void |
fba45db2 | 8135 | disable_command (char *args, int from_tty) |
c906108c | 8136 | { |
52f0bd74 | 8137 | struct breakpoint *bpt; |
c906108c SS |
8138 | if (args == 0) |
8139 | ALL_BREAKPOINTS (bpt) | |
8140 | switch (bpt->type) | |
c5aa993b JM |
8141 | { |
8142 | case bp_none: | |
8a3fe4f8 | 8143 | warning (_("attempted to disable apparently deleted breakpoint #%d?"), |
53a5351d | 8144 | bpt->number); |
c5aa993b JM |
8145 | continue; |
8146 | case bp_breakpoint: | |
1042e4c0 | 8147 | case bp_tracepoint: |
ce78b96d | 8148 | case bp_catchpoint: |
c5aa993b JM |
8149 | case bp_hardware_breakpoint: |
8150 | case bp_watchpoint: | |
8151 | case bp_hardware_watchpoint: | |
8152 | case bp_read_watchpoint: | |
8153 | case bp_access_watchpoint: | |
8154 | disable_breakpoint (bpt); | |
8155 | default: | |
8156 | continue; | |
8157 | } | |
0d381245 VP |
8158 | else if (strchr (args, '.')) |
8159 | { | |
8160 | struct bp_location *loc = find_location_by_number (args); | |
8161 | if (loc) | |
8162 | loc->enabled = 0; | |
b60e7edf | 8163 | update_global_location_list (0); |
0d381245 | 8164 | } |
c906108c SS |
8165 | else |
8166 | map_breakpoint_numbers (args, disable_breakpoint); | |
8167 | } | |
8168 | ||
8169 | static void | |
fba45db2 | 8170 | do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition) |
c906108c | 8171 | { |
c906108c SS |
8172 | int target_resources_ok, other_type_used; |
8173 | struct value *mark; | |
8174 | ||
8175 | if (bpt->type == bp_hardware_breakpoint) | |
8176 | { | |
8177 | int i; | |
c5aa993b | 8178 | i = hw_breakpoint_used_count (); |
53a5351d | 8179 | target_resources_ok = |
d92524f1 | 8180 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 8181 | i + 1, 0); |
c906108c | 8182 | if (target_resources_ok == 0) |
8a3fe4f8 | 8183 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 8184 | else if (target_resources_ok < 0) |
8a3fe4f8 | 8185 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
8186 | } |
8187 | ||
059fb39f PM |
8188 | if (bpt->type == bp_watchpoint |
8189 | || bpt->type == bp_hardware_watchpoint | |
8190 | || bpt->type == bp_read_watchpoint | |
8191 | || bpt->type == bp_access_watchpoint) | |
c906108c | 8192 | { |
dde02812 ES |
8193 | struct gdb_exception e; |
8194 | ||
8195 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 8196 | { |
dde02812 | 8197 | update_watchpoint (bpt, 1 /* reparse */); |
c906108c | 8198 | } |
dde02812 | 8199 | if (e.reason < 0) |
c5aa993b | 8200 | { |
dde02812 ES |
8201 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
8202 | bpt->number); | |
8203 | return; | |
c5aa993b | 8204 | } |
c906108c | 8205 | } |
0101ce28 | 8206 | |
b4c291bb KH |
8207 | if (bpt->enable_state != bp_permanent) |
8208 | bpt->enable_state = bp_enabled; | |
8209 | bpt->disposition = disposition; | |
b60e7edf | 8210 | update_global_location_list (1); |
b4c291bb KH |
8211 | breakpoints_changed (); |
8212 | ||
383f836e | 8213 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
8214 | } |
8215 | ||
fe3f5fa8 | 8216 | |
c906108c | 8217 | void |
fba45db2 | 8218 | enable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
8219 | { |
8220 | do_enable_breakpoint (bpt, bpt->disposition); | |
8221 | } | |
8222 | ||
8223 | /* The enable command enables the specified breakpoints (or all defined | |
8224 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 8225 | in stopping the inferior. */ |
c906108c | 8226 | |
c906108c | 8227 | static void |
fba45db2 | 8228 | enable_command (char *args, int from_tty) |
c906108c | 8229 | { |
52f0bd74 | 8230 | struct breakpoint *bpt; |
c906108c SS |
8231 | if (args == 0) |
8232 | ALL_BREAKPOINTS (bpt) | |
8233 | switch (bpt->type) | |
c5aa993b JM |
8234 | { |
8235 | case bp_none: | |
8a3fe4f8 | 8236 | warning (_("attempted to enable apparently deleted breakpoint #%d?"), |
53a5351d | 8237 | bpt->number); |
c5aa993b JM |
8238 | continue; |
8239 | case bp_breakpoint: | |
1042e4c0 | 8240 | case bp_tracepoint: |
ce78b96d | 8241 | case bp_catchpoint: |
c5aa993b JM |
8242 | case bp_hardware_breakpoint: |
8243 | case bp_watchpoint: | |
8244 | case bp_hardware_watchpoint: | |
8245 | case bp_read_watchpoint: | |
8246 | case bp_access_watchpoint: | |
8247 | enable_breakpoint (bpt); | |
8248 | default: | |
8249 | continue; | |
8250 | } | |
0d381245 VP |
8251 | else if (strchr (args, '.')) |
8252 | { | |
8253 | struct bp_location *loc = find_location_by_number (args); | |
8254 | if (loc) | |
8255 | loc->enabled = 1; | |
b60e7edf | 8256 | update_global_location_list (1); |
0d381245 | 8257 | } |
c906108c SS |
8258 | else |
8259 | map_breakpoint_numbers (args, enable_breakpoint); | |
8260 | } | |
8261 | ||
8262 | static void | |
fba45db2 | 8263 | enable_once_breakpoint (struct breakpoint *bpt) |
c906108c | 8264 | { |
b5de0fa7 | 8265 | do_enable_breakpoint (bpt, disp_disable); |
c906108c SS |
8266 | } |
8267 | ||
c906108c | 8268 | static void |
fba45db2 | 8269 | enable_once_command (char *args, int from_tty) |
c906108c SS |
8270 | { |
8271 | map_breakpoint_numbers (args, enable_once_breakpoint); | |
8272 | } | |
8273 | ||
8274 | static void | |
fba45db2 | 8275 | enable_delete_breakpoint (struct breakpoint *bpt) |
c906108c | 8276 | { |
b5de0fa7 | 8277 | do_enable_breakpoint (bpt, disp_del); |
c906108c SS |
8278 | } |
8279 | ||
c906108c | 8280 | static void |
fba45db2 | 8281 | enable_delete_command (char *args, int from_tty) |
c906108c SS |
8282 | { |
8283 | map_breakpoint_numbers (args, enable_delete_breakpoint); | |
8284 | } | |
8285 | \f | |
fa8d40ab JJ |
8286 | static void |
8287 | set_breakpoint_cmd (char *args, int from_tty) | |
8288 | { | |
8289 | } | |
8290 | ||
8291 | static void | |
8292 | show_breakpoint_cmd (char *args, int from_tty) | |
8293 | { | |
8294 | } | |
8295 | ||
c906108c SS |
8296 | /* Use default_breakpoint_'s, or nothing if they aren't valid. */ |
8297 | ||
8298 | struct symtabs_and_lines | |
fba45db2 | 8299 | decode_line_spec_1 (char *string, int funfirstline) |
c906108c SS |
8300 | { |
8301 | struct symtabs_and_lines sals; | |
8302 | if (string == 0) | |
8a3fe4f8 | 8303 | error (_("Empty line specification.")); |
c906108c SS |
8304 | if (default_breakpoint_valid) |
8305 | sals = decode_line_1 (&string, funfirstline, | |
53a5351d JM |
8306 | default_breakpoint_symtab, |
8307 | default_breakpoint_line, | |
68219205 | 8308 | (char ***) NULL, NULL); |
c906108c SS |
8309 | else |
8310 | sals = decode_line_1 (&string, funfirstline, | |
68219205 | 8311 | (struct symtab *) NULL, 0, (char ***) NULL, NULL); |
c906108c | 8312 | if (*string) |
8a3fe4f8 | 8313 | error (_("Junk at end of line specification: %s"), string); |
c906108c SS |
8314 | return sals; |
8315 | } | |
8181d85f DJ |
8316 | |
8317 | /* Create and insert a raw software breakpoint at PC. Return an | |
8318 | identifier, which should be used to remove the breakpoint later. | |
8319 | In general, places which call this should be using something on the | |
8320 | breakpoint chain instead; this function should be eliminated | |
8321 | someday. */ | |
8322 | ||
8323 | void * | |
a6d9a66e | 8324 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, CORE_ADDR pc) |
8181d85f DJ |
8325 | { |
8326 | struct bp_target_info *bp_tgt; | |
8327 | ||
8328 | bp_tgt = xmalloc (sizeof (struct bp_target_info)); | |
8329 | memset (bp_tgt, 0, sizeof (struct bp_target_info)); | |
8330 | ||
8331 | bp_tgt->placed_address = pc; | |
a6d9a66e | 8332 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
8181d85f DJ |
8333 | { |
8334 | /* Could not insert the breakpoint. */ | |
8335 | xfree (bp_tgt); | |
8336 | return NULL; | |
8337 | } | |
8338 | ||
8339 | return bp_tgt; | |
8340 | } | |
8341 | ||
8342 | /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */ | |
8343 | ||
8344 | int | |
a6d9a66e | 8345 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
8181d85f DJ |
8346 | { |
8347 | struct bp_target_info *bp_tgt = bp; | |
8348 | int ret; | |
8349 | ||
a6d9a66e | 8350 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
8181d85f DJ |
8351 | xfree (bp_tgt); |
8352 | ||
8353 | return ret; | |
8354 | } | |
8355 | ||
8356 | /* One (or perhaps two) breakpoints used for software single stepping. */ | |
8357 | ||
8358 | static void *single_step_breakpoints[2]; | |
a6d9a66e | 8359 | static struct gdbarch *single_step_gdbarch[2]; |
8181d85f DJ |
8360 | |
8361 | /* Create and insert a breakpoint for software single step. */ | |
8362 | ||
8363 | void | |
a6d9a66e | 8364 | insert_single_step_breakpoint (struct gdbarch *gdbarch, CORE_ADDR next_pc) |
8181d85f DJ |
8365 | { |
8366 | void **bpt_p; | |
8367 | ||
8368 | if (single_step_breakpoints[0] == NULL) | |
a6d9a66e UW |
8369 | { |
8370 | bpt_p = &single_step_breakpoints[0]; | |
8371 | single_step_gdbarch[0] = gdbarch; | |
8372 | } | |
8181d85f DJ |
8373 | else |
8374 | { | |
8375 | gdb_assert (single_step_breakpoints[1] == NULL); | |
8376 | bpt_p = &single_step_breakpoints[1]; | |
a6d9a66e | 8377 | single_step_gdbarch[1] = gdbarch; |
8181d85f DJ |
8378 | } |
8379 | ||
8380 | /* NOTE drow/2006-04-11: A future improvement to this function would be | |
8381 | to only create the breakpoints once, and actually put them on the | |
8382 | breakpoint chain. That would let us use set_raw_breakpoint. We could | |
8383 | adjust the addresses each time they were needed. Doing this requires | |
8384 | corresponding changes elsewhere where single step breakpoints are | |
8385 | handled, however. So, for now, we use this. */ | |
8386 | ||
a6d9a66e | 8387 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, next_pc); |
8181d85f | 8388 | if (*bpt_p == NULL) |
1893a4c0 | 8389 | error (_("Could not insert single-step breakpoint at 0x%s"), |
8181d85f DJ |
8390 | paddr_nz (next_pc)); |
8391 | } | |
8392 | ||
8393 | /* Remove and delete any breakpoints used for software single step. */ | |
8394 | ||
8395 | void | |
8396 | remove_single_step_breakpoints (void) | |
8397 | { | |
8398 | gdb_assert (single_step_breakpoints[0] != NULL); | |
8399 | ||
8400 | /* See insert_single_step_breakpoint for more about this deprecated | |
8401 | call. */ | |
a6d9a66e UW |
8402 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
8403 | single_step_breakpoints[0]); | |
8404 | single_step_gdbarch[0] = NULL; | |
8181d85f DJ |
8405 | single_step_breakpoints[0] = NULL; |
8406 | ||
8407 | if (single_step_breakpoints[1] != NULL) | |
8408 | { | |
a6d9a66e UW |
8409 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
8410 | single_step_breakpoints[1]); | |
8411 | single_step_gdbarch[1] = NULL; | |
8181d85f DJ |
8412 | single_step_breakpoints[1] = NULL; |
8413 | } | |
8414 | } | |
8415 | ||
1aafd4da UW |
8416 | /* Check whether a software single-step breakpoint is inserted at PC. */ |
8417 | ||
8418 | static int | |
8419 | single_step_breakpoint_inserted_here_p (CORE_ADDR pc) | |
8420 | { | |
8421 | int i; | |
8422 | ||
8423 | for (i = 0; i < 2; i++) | |
8424 | { | |
8425 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
8426 | if (bp_tgt && bp_tgt->placed_address == pc) | |
8427 | return 1; | |
8428 | } | |
8429 | ||
8430 | return 0; | |
8431 | } | |
8432 | ||
1042e4c0 SS |
8433 | /* Tracepoint-specific operations. */ |
8434 | ||
8435 | /* Set tracepoint count to NUM. */ | |
8436 | static void | |
8437 | set_tracepoint_count (int num) | |
8438 | { | |
8439 | tracepoint_count = num; | |
4fa62494 | 8440 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
8441 | } |
8442 | ||
8443 | void | |
8444 | trace_command (char *arg, int from_tty) | |
8445 | { | |
a6d9a66e UW |
8446 | break_command_really (get_current_arch (), |
8447 | arg, | |
1042e4c0 SS |
8448 | NULL, 0, 1 /* parse arg */, |
8449 | 0 /* tempflag */, 0 /* hardwareflag */, | |
8450 | 1 /* traceflag */, | |
8451 | 0 /* Ignore count */, | |
8452 | pending_break_support, | |
8453 | NULL, | |
8454 | from_tty, | |
8455 | 1 /* enabled */); | |
8456 | set_tracepoint_count (breakpoint_count); | |
8457 | } | |
8458 | ||
8459 | /* Print information on tracepoint number TPNUM_EXP, or all if | |
8460 | omitted. */ | |
8461 | ||
8462 | static void | |
8463 | tracepoints_info (char *tpnum_exp, int from_tty) | |
8464 | { | |
8465 | struct breakpoint *b; | |
8466 | int tps_to_list = 0; | |
8467 | ||
8468 | /* In the no-arguments case, say "No tracepoints" if none found. */ | |
8469 | if (tpnum_exp == 0) | |
8470 | { | |
8471 | ALL_TRACEPOINTS (b) | |
8472 | { | |
8473 | if (b->number >= 0) | |
8474 | { | |
8475 | tps_to_list = 1; | |
8476 | break; | |
8477 | } | |
8478 | } | |
8479 | if (!tps_to_list) | |
8480 | { | |
8481 | ui_out_message (uiout, 0, "No tracepoints.\n"); | |
8482 | return; | |
8483 | } | |
8484 | } | |
8485 | ||
8486 | /* Otherwise be the same as "info break". */ | |
8487 | breakpoints_info (tpnum_exp, from_tty); | |
8488 | } | |
8489 | ||
8490 | /* The 'enable trace' command enables tracepoints. | |
8491 | Not supported by all targets. */ | |
8492 | static void | |
8493 | enable_trace_command (char *args, int from_tty) | |
8494 | { | |
8495 | enable_command (args, from_tty); | |
8496 | } | |
8497 | ||
8498 | /* The 'disable trace' command disables tracepoints. | |
8499 | Not supported by all targets. */ | |
8500 | static void | |
8501 | disable_trace_command (char *args, int from_tty) | |
8502 | { | |
8503 | disable_command (args, from_tty); | |
8504 | } | |
8505 | ||
8506 | /* Remove a tracepoint (or all if no argument) */ | |
8507 | static void | |
8508 | delete_trace_command (char *arg, int from_tty) | |
8509 | { | |
8510 | struct breakpoint *b, *temp; | |
8511 | ||
8512 | dont_repeat (); | |
8513 | ||
8514 | if (arg == 0) | |
8515 | { | |
8516 | int breaks_to_delete = 0; | |
8517 | ||
8518 | /* Delete all breakpoints if no argument. | |
8519 | Do not delete internal or call-dummy breakpoints, these | |
8520 | have to be deleted with an explicit breakpoint number argument. */ | |
8521 | ALL_TRACEPOINTS (b) | |
8522 | { | |
8523 | if (b->number >= 0) | |
8524 | { | |
8525 | breaks_to_delete = 1; | |
8526 | break; | |
8527 | } | |
8528 | } | |
8529 | ||
8530 | /* Ask user only if there are some breakpoints to delete. */ | |
8531 | if (!from_tty | |
8532 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
8533 | { | |
8534 | ALL_BREAKPOINTS_SAFE (b, temp) | |
8535 | { | |
059fb39f PM |
8536 | if (b->type == bp_tracepoint |
8537 | && b->number >= 0) | |
1042e4c0 SS |
8538 | delete_breakpoint (b); |
8539 | } | |
8540 | } | |
8541 | } | |
8542 | else | |
8543 | map_breakpoint_numbers (arg, delete_breakpoint); | |
8544 | } | |
8545 | ||
8546 | /* Set passcount for tracepoint. | |
8547 | ||
8548 | First command argument is passcount, second is tracepoint number. | |
8549 | If tracepoint number omitted, apply to most recently defined. | |
8550 | Also accepts special argument "all". */ | |
8551 | ||
8552 | static void | |
8553 | trace_pass_command (char *args, int from_tty) | |
8554 | { | |
8555 | struct breakpoint *t1 = (struct breakpoint *) -1, *t2; | |
8556 | unsigned int count; | |
8557 | int all = 0; | |
8558 | ||
8559 | if (args == 0 || *args == 0) | |
8560 | error (_("passcount command requires an argument (count + optional TP num)")); | |
8561 | ||
8562 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ | |
8563 | ||
8564 | while (*args && isspace ((int) *args)) | |
8565 | args++; | |
8566 | ||
8567 | if (*args && strncasecmp (args, "all", 3) == 0) | |
8568 | { | |
8569 | args += 3; /* Skip special argument "all". */ | |
8570 | all = 1; | |
8571 | if (*args) | |
8572 | error (_("Junk at end of arguments.")); | |
8573 | } | |
8574 | else | |
8575 | t1 = get_tracepoint_by_number (&args, 1, 1); | |
8576 | ||
8577 | do | |
8578 | { | |
8579 | if (t1) | |
8580 | { | |
8581 | ALL_TRACEPOINTS (t2) | |
8582 | if (t1 == (struct breakpoint *) -1 || t1 == t2) | |
8583 | { | |
8584 | t2->pass_count = count; | |
8585 | observer_notify_tracepoint_modified (t2->number); | |
8586 | if (from_tty) | |
8587 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
8588 | t2->number, count); | |
8589 | } | |
8590 | if (! all && *args) | |
8591 | t1 = get_tracepoint_by_number (&args, 1, 0); | |
8592 | } | |
8593 | } | |
8594 | while (*args); | |
8595 | } | |
8596 | ||
8597 | struct breakpoint * | |
8598 | get_tracepoint (int num) | |
8599 | { | |
8600 | struct breakpoint *t; | |
8601 | ||
8602 | ALL_TRACEPOINTS (t) | |
8603 | if (t->number == num) | |
8604 | return t; | |
8605 | ||
8606 | return NULL; | |
8607 | } | |
8608 | ||
8609 | /* Utility: parse a tracepoint number and look it up in the list. | |
8610 | If MULTI_P is true, there might be a range of tracepoints in ARG. | |
8611 | if OPTIONAL_P is true, then if the argument is missing, the most | |
8612 | recent tracepoint (tracepoint_count) is returned. */ | |
8613 | struct breakpoint * | |
8614 | get_tracepoint_by_number (char **arg, int multi_p, int optional_p) | |
8615 | { | |
8616 | extern int tracepoint_count; | |
8617 | struct breakpoint *t; | |
8618 | int tpnum; | |
8619 | char *instring = arg == NULL ? NULL : *arg; | |
8620 | ||
8621 | if (arg == NULL || *arg == NULL || ! **arg) | |
8622 | { | |
8623 | if (optional_p) | |
8624 | tpnum = tracepoint_count; | |
8625 | else | |
8626 | error_no_arg (_("tracepoint number")); | |
8627 | } | |
8628 | else | |
8629 | tpnum = multi_p ? get_number_or_range (arg) : get_number (arg); | |
8630 | ||
8631 | if (tpnum <= 0) | |
8632 | { | |
8633 | if (instring && *instring) | |
8634 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
8635 | instring); | |
8636 | else | |
8637 | printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n")); | |
8638 | return NULL; | |
8639 | } | |
8640 | ||
8641 | ALL_TRACEPOINTS (t) | |
8642 | if (t->number == tpnum) | |
8643 | { | |
8644 | return t; | |
8645 | } | |
8646 | ||
8647 | /* FIXME: if we are in the middle of a range we don't want to give | |
8648 | a message. The current interface to get_number_or_range doesn't | |
8649 | allow us to discover this. */ | |
8650 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); | |
8651 | return NULL; | |
8652 | } | |
8653 | ||
8654 | /* save-tracepoints command */ | |
8655 | static void | |
8656 | tracepoint_save_command (char *args, int from_tty) | |
8657 | { | |
8658 | struct breakpoint *tp; | |
8659 | int any_tp = 0; | |
8660 | struct action_line *line; | |
8661 | FILE *fp; | |
8662 | char *i1 = " ", *i2 = " "; | |
8663 | char *indent, *actionline, *pathname; | |
8664 | char tmp[40]; | |
8665 | struct cleanup *cleanup; | |
8666 | ||
8667 | if (args == 0 || *args == 0) | |
8668 | error (_("Argument required (file name in which to save tracepoints)")); | |
8669 | ||
8670 | /* See if we have anything to save. */ | |
8671 | ALL_TRACEPOINTS (tp) | |
8672 | { | |
8673 | any_tp = 1; | |
8674 | break; | |
8675 | } | |
8676 | if (!any_tp) | |
8677 | { | |
8678 | warning (_("save-tracepoints: no tracepoints to save.")); | |
8679 | return; | |
8680 | } | |
8681 | ||
8682 | pathname = tilde_expand (args); | |
8683 | cleanup = make_cleanup (xfree, pathname); | |
059fb39f PM |
8684 | fp = fopen (pathname, "w"); |
8685 | if (!fp) | |
1042e4c0 SS |
8686 | error (_("Unable to open file '%s' for saving tracepoints (%s)"), |
8687 | args, safe_strerror (errno)); | |
8688 | make_cleanup_fclose (fp); | |
8689 | ||
8690 | ALL_TRACEPOINTS (tp) | |
8691 | { | |
8692 | if (tp->addr_string) | |
8693 | fprintf (fp, "trace %s\n", tp->addr_string); | |
8694 | else | |
8695 | { | |
8696 | sprintf_vma (tmp, tp->loc->address); | |
8697 | fprintf (fp, "trace *0x%s\n", tmp); | |
8698 | } | |
8699 | ||
8700 | if (tp->pass_count) | |
8701 | fprintf (fp, " passcount %d\n", tp->pass_count); | |
8702 | ||
8703 | if (tp->actions) | |
8704 | { | |
8705 | fprintf (fp, " actions\n"); | |
8706 | indent = i1; | |
8707 | for (line = tp->actions; line; line = line->next) | |
8708 | { | |
8709 | struct cmd_list_element *cmd; | |
8710 | ||
8711 | QUIT; /* allow user to bail out with ^C */ | |
8712 | actionline = line->action; | |
8713 | while (isspace ((int) *actionline)) | |
8714 | actionline++; | |
8715 | ||
8716 | fprintf (fp, "%s%s\n", indent, actionline); | |
8717 | if (*actionline != '#') /* skip for comment lines */ | |
8718 | { | |
8719 | cmd = lookup_cmd (&actionline, cmdlist, "", -1, 1); | |
8720 | if (cmd == 0) | |
8721 | error (_("Bad action list item: %s"), actionline); | |
8722 | if (cmd_cfunc_eq (cmd, while_stepping_pseudocommand)) | |
8723 | indent = i2; | |
8724 | else if (cmd_cfunc_eq (cmd, end_actions_pseudocommand)) | |
8725 | indent = i1; | |
8726 | } | |
8727 | } | |
8728 | } | |
8729 | } | |
8730 | do_cleanups (cleanup); | |
8731 | if (from_tty) | |
8732 | printf_filtered (_("Tracepoints saved to file '%s'.\n"), args); | |
8733 | return; | |
8734 | } | |
8735 | ||
8736 | /* Create a vector of all tracepoints. */ | |
8737 | ||
8738 | VEC(breakpoint_p) * | |
8739 | all_tracepoints () | |
8740 | { | |
8741 | VEC(breakpoint_p) *tp_vec = 0; | |
8742 | struct breakpoint *tp; | |
8743 | ||
8744 | ALL_TRACEPOINTS (tp) | |
8745 | { | |
8746 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
8747 | } | |
8748 | ||
8749 | return tp_vec; | |
8750 | } | |
8751 | ||
c906108c | 8752 | \f |
31e2b00f AS |
8753 | /* This help string is used for the break, hbreak, tbreak and thbreak commands. |
8754 | It is defined as a macro to prevent duplication. | |
8755 | COMMAND should be a string constant containing the name of the command. */ | |
8756 | #define BREAK_ARGS_HELP(command) \ | |
8757 | command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\ | |
8758 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ | |
8759 | If a line number is specified, break at start of code for that line.\n\ | |
8760 | If a function is specified, break at start of code for that function.\n\ | |
8761 | If an address is specified, break at that exact address.\n\ | |
8762 | With no LOCATION, uses current execution address of selected stack frame.\n\ | |
8763 | This is useful for breaking on return to a stack frame.\n\ | |
8764 | \n\ | |
8765 | THREADNUM is the number from \"info threads\".\n\ | |
8766 | CONDITION is a boolean expression.\n\ | |
8767 | \n\ | |
8768 | Multiple breakpoints at one place are permitted, and useful if conditional.\n\ | |
8769 | \n\ | |
8770 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
8771 | ||
44feb3ce TT |
8772 | /* List of subcommands for "catch". */ |
8773 | static struct cmd_list_element *catch_cmdlist; | |
8774 | ||
8775 | /* List of subcommands for "tcatch". */ | |
8776 | static struct cmd_list_element *tcatch_cmdlist; | |
8777 | ||
8778 | /* Like add_cmd, but add the command to both the "catch" and "tcatch" | |
8779 | lists, and pass some additional user data to the command function. */ | |
8780 | static void | |
8781 | add_catch_command (char *name, char *docstring, | |
8782 | void (*sfunc) (char *args, int from_tty, | |
8783 | struct cmd_list_element *command), | |
8784 | void *user_data_catch, | |
8785 | void *user_data_tcatch) | |
8786 | { | |
8787 | struct cmd_list_element *command; | |
8788 | ||
8789 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
8790 | &catch_cmdlist); | |
8791 | set_cmd_sfunc (command, sfunc); | |
8792 | set_cmd_context (command, user_data_catch); | |
8793 | ||
8794 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
8795 | &tcatch_cmdlist); | |
8796 | set_cmd_sfunc (command, sfunc); | |
8797 | set_cmd_context (command, user_data_tcatch); | |
8798 | } | |
8799 | ||
c906108c | 8800 | void |
fba45db2 | 8801 | _initialize_breakpoint (void) |
c906108c | 8802 | { |
fa8d40ab JJ |
8803 | static struct cmd_list_element *breakpoint_set_cmdlist; |
8804 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
c906108c SS |
8805 | struct cmd_list_element *c; |
8806 | ||
84acb35a | 8807 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
84acb35a | 8808 | |
c906108c SS |
8809 | breakpoint_chain = 0; |
8810 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
8811 | before a breakpoint is set. */ | |
8812 | breakpoint_count = 0; | |
8813 | ||
1042e4c0 SS |
8814 | tracepoint_count = 0; |
8815 | ||
1bedd215 AC |
8816 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
8817 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
8818 | Usage is `ignore N COUNT'.")); | |
c906108c | 8819 | if (xdb_commands) |
c5aa993b | 8820 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 8821 | |
1bedd215 AC |
8822 | add_com ("commands", class_breakpoint, commands_command, _("\ |
8823 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
8824 | Give breakpoint number as argument after \"commands\".\n\ |
8825 | With no argument, the targeted breakpoint is the last one set.\n\ | |
8826 | The commands themselves follow starting on the next line.\n\ | |
8827 | Type a line containing \"end\" to indicate the end of them.\n\ | |
8828 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 8829 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 8830 | |
1bedd215 AC |
8831 | add_com ("condition", class_breakpoint, condition_command, _("\ |
8832 | Specify breakpoint number N to break only if COND is true.\n\ | |
c906108c | 8833 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 8834 | expression to be evaluated whenever breakpoint N is reached.")); |
c906108c | 8835 | |
1bedd215 | 8836 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 8837 | Set a temporary breakpoint.\n\ |
c906108c SS |
8838 | Like \"break\" except the breakpoint is only temporary,\n\ |
8839 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
8840 | by using \"enable delete\" on the breakpoint number.\n\ |
8841 | \n" | |
8842 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 8843 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 8844 | |
1bedd215 | 8845 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
31e2b00f | 8846 | Set a hardware assisted breakpoint.\n\ |
c906108c | 8847 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
8848 | some target hardware may not have this support.\n\ |
8849 | \n" | |
8850 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 8851 | set_cmd_completer (c, location_completer); |
c906108c | 8852 | |
1bedd215 | 8853 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 8854 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 8855 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
8856 | so it will be deleted when hit.\n\ |
8857 | \n" | |
8858 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 8859 | set_cmd_completer (c, location_completer); |
c906108c | 8860 | |
1bedd215 AC |
8861 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
8862 | Enable some breakpoints.\n\ | |
c906108c SS |
8863 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
8864 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
8865 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 8866 | With a subcommand you can enable temporarily."), |
c906108c SS |
8867 | &enablelist, "enable ", 1, &cmdlist); |
8868 | if (xdb_commands) | |
1bedd215 AC |
8869 | add_com ("ab", class_breakpoint, enable_command, _("\ |
8870 | Enable some breakpoints.\n\ | |
c906108c SS |
8871 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
8872 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
8873 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 8874 | With a subcommand you can enable temporarily.")); |
c906108c SS |
8875 | |
8876 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
8877 | ||
1bedd215 AC |
8878 | add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
8879 | Enable some breakpoints.\n\ | |
c906108c SS |
8880 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
8881 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 8882 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 8883 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 8884 | |
1a966eab AC |
8885 | add_cmd ("once", no_class, enable_once_command, _("\ |
8886 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
8887 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
8888 | &enablebreaklist); |
8889 | ||
1a966eab AC |
8890 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
8891 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
8892 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
8893 | &enablebreaklist); |
8894 | ||
1a966eab AC |
8895 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
8896 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
8897 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
8898 | &enablelist); |
8899 | ||
1a966eab AC |
8900 | add_cmd ("once", no_class, enable_once_command, _("\ |
8901 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
8902 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
8903 | &enablelist); |
8904 | ||
1bedd215 AC |
8905 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
8906 | Disable some breakpoints.\n\ | |
c906108c SS |
8907 | Arguments are breakpoint numbers with spaces in between.\n\ |
8908 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 8909 | A disabled breakpoint is not forgotten, but has no effect until reenabled."), |
c906108c SS |
8910 | &disablelist, "disable ", 1, &cmdlist); |
8911 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
8912 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
8913 | if (xdb_commands) | |
1bedd215 AC |
8914 | add_com ("sb", class_breakpoint, disable_command, _("\ |
8915 | Disable some breakpoints.\n\ | |
c906108c SS |
8916 | Arguments are breakpoint numbers with spaces in between.\n\ |
8917 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 8918 | A disabled breakpoint is not forgotten, but has no effect until reenabled.")); |
c906108c | 8919 | |
1a966eab AC |
8920 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
8921 | Disable some breakpoints.\n\ | |
c906108c SS |
8922 | Arguments are breakpoint numbers with spaces in between.\n\ |
8923 | To disable all breakpoints, give no argument.\n\ | |
8924 | A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\ | |
1a966eab | 8925 | This command may be abbreviated \"disable\"."), |
c906108c SS |
8926 | &disablelist); |
8927 | ||
1bedd215 AC |
8928 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
8929 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
8930 | Arguments are breakpoint numbers with spaces in between.\n\ |
8931 | To delete all breakpoints, give no argument.\n\ | |
8932 | \n\ | |
8933 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 8934 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
8935 | &deletelist, "delete ", 1, &cmdlist); |
8936 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 8937 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 8938 | if (xdb_commands) |
1bedd215 AC |
8939 | add_com ("db", class_breakpoint, delete_command, _("\ |
8940 | Delete some breakpoints.\n\ | |
c906108c | 8941 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 8942 | To delete all breakpoints, give no argument.\n")); |
c906108c | 8943 | |
1a966eab AC |
8944 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
8945 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
8946 | Arguments are breakpoint numbers with spaces in between.\n\ |
8947 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 8948 | This command may be abbreviated \"delete\"."), |
c906108c SS |
8949 | &deletelist); |
8950 | ||
1bedd215 AC |
8951 | add_com ("clear", class_breakpoint, clear_command, _("\ |
8952 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
8953 | Argument may be line number, function name, or \"*\" and an address.\n\ |
8954 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
8955 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
8956 | If an address is specified, breakpoints at that address are cleared.\n\ |
8957 | \n\ | |
8958 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
8959 | is executing in.\n\ |
8960 | \n\ | |
1bedd215 | 8961 | See also the \"delete\" command which clears breakpoints by number.")); |
c906108c | 8962 | |
1bedd215 | 8963 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
8964 | Set breakpoint at specified line or function.\n" |
8965 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 8966 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 8967 | |
c906108c SS |
8968 | add_com_alias ("b", "break", class_run, 1); |
8969 | add_com_alias ("br", "break", class_run, 1); | |
8970 | add_com_alias ("bre", "break", class_run, 1); | |
8971 | add_com_alias ("brea", "break", class_run, 1); | |
8972 | ||
7681d515 PM |
8973 | if (xdb_commands) |
8974 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
8975 | |
8976 | if (dbx_commands) | |
8977 | { | |
1bedd215 AC |
8978 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
8979 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
8980 | &stoplist, "stop ", 1, &cmdlist); |
8981 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 8982 | _("Break in function or address."), &stoplist); |
c5aa993b | 8983 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 8984 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
8985 | add_com ("status", class_info, breakpoints_info, _("\ |
8986 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
8987 | The \"Type\" column indicates one of:\n\ |
8988 | \tbreakpoint - normal breakpoint\n\ | |
8989 | \twatchpoint - watchpoint\n\ | |
8990 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
8991 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
8992 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
8993 | address and file/line number respectively.\n\ |
8994 | \n\ | |
8995 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
8996 | are set to the address of the last breakpoint listed unless the command\n\ |
8997 | is prefixed with \"server \".\n\n\ | |
c906108c | 8998 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 8999 | breakpoint set.")); |
c906108c SS |
9000 | } |
9001 | ||
1bedd215 AC |
9002 | add_info ("breakpoints", breakpoints_info, _("\ |
9003 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
9004 | The \"Type\" column indicates one of:\n\ |
9005 | \tbreakpoint - normal breakpoint\n\ | |
9006 | \twatchpoint - watchpoint\n\ | |
9007 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
9008 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
9009 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
9010 | address and file/line number respectively.\n\ |
9011 | \n\ | |
9012 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
9013 | are set to the address of the last breakpoint listed unless the command\n\ |
9014 | is prefixed with \"server \".\n\n\ | |
c906108c | 9015 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 9016 | breakpoint set.")); |
c906108c SS |
9017 | |
9018 | if (xdb_commands) | |
1bedd215 AC |
9019 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
9020 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
9021 | The \"Type\" column indicates one of:\n\ |
9022 | \tbreakpoint - normal breakpoint\n\ | |
9023 | \twatchpoint - watchpoint\n\ | |
9024 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
9025 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
9026 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
9027 | address and file/line number respectively.\n\ |
9028 | \n\ | |
9029 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
9030 | are set to the address of the last breakpoint listed unless the command\n\ |
9031 | is prefixed with \"server \".\n\n\ | |
c906108c | 9032 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 9033 | breakpoint set.")); |
c906108c | 9034 | |
1a966eab AC |
9035 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
9036 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
9037 | The \"Type\" column indicates one of:\n\ |
9038 | \tbreakpoint - normal breakpoint\n\ | |
9039 | \twatchpoint - watchpoint\n\ | |
9040 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
9041 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
9042 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
9043 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
9044 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
9045 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
9046 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
9047 | address and file/line number respectively.\n\ |
9048 | \n\ | |
9049 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
9050 | are set to the address of the last breakpoint listed unless the command\n\ |
9051 | is prefixed with \"server \".\n\n\ | |
c906108c | 9052 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 9053 | breakpoint set."), |
c906108c SS |
9054 | &maintenanceinfolist); |
9055 | ||
44feb3ce TT |
9056 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
9057 | Set catchpoints to catch events."), | |
9058 | &catch_cmdlist, "catch ", | |
9059 | 0/*allow-unknown*/, &cmdlist); | |
9060 | ||
9061 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
9062 | Set temporary catchpoints to catch events."), | |
9063 | &tcatch_cmdlist, "tcatch ", | |
9064 | 0/*allow-unknown*/, &cmdlist); | |
9065 | ||
9066 | /* Add catch and tcatch sub-commands. */ | |
9067 | add_catch_command ("catch", _("\ | |
9068 | Catch an exception, when caught.\n\ | |
9069 | With an argument, catch only exceptions with the given name."), | |
9070 | catch_catch_command, | |
9071 | CATCH_PERMANENT, | |
9072 | CATCH_TEMPORARY); | |
9073 | add_catch_command ("throw", _("\ | |
9074 | Catch an exception, when thrown.\n\ | |
9075 | With an argument, catch only exceptions with the given name."), | |
9076 | catch_throw_command, | |
9077 | CATCH_PERMANENT, | |
9078 | CATCH_TEMPORARY); | |
9079 | add_catch_command ("fork", _("Catch calls to fork."), | |
9080 | catch_fork_command_1, | |
9081 | (void *) (uintptr_t) catch_fork_permanent, | |
9082 | (void *) (uintptr_t) catch_fork_temporary); | |
9083 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
9084 | catch_fork_command_1, | |
9085 | (void *) (uintptr_t) catch_vfork_permanent, | |
9086 | (void *) (uintptr_t) catch_vfork_temporary); | |
9087 | add_catch_command ("exec", _("Catch calls to exec."), | |
9088 | catch_exec_command_1, | |
9089 | CATCH_PERMANENT, | |
9090 | CATCH_TEMPORARY); | |
44feb3ce TT |
9091 | add_catch_command ("exception", _("\ |
9092 | Catch Ada exceptions, when raised.\n\ | |
9093 | With an argument, catch only exceptions with the given name."), | |
9094 | catch_ada_exception_command, | |
9095 | CATCH_PERMANENT, | |
9096 | CATCH_TEMPORARY); | |
9097 | add_catch_command ("assert", _("\ | |
9098 | Catch failed Ada assertions, when raised.\n\ | |
9099 | With an argument, catch only exceptions with the given name."), | |
9100 | catch_assert_command, | |
9101 | CATCH_PERMANENT, | |
9102 | CATCH_TEMPORARY); | |
c5aa993b | 9103 | |
1bedd215 AC |
9104 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
9105 | Set a watchpoint for an expression.\n\ | |
c906108c | 9106 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 9107 | an expression changes.")); |
65d12d83 | 9108 | set_cmd_completer (c, expression_completer); |
c906108c | 9109 | |
1bedd215 AC |
9110 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
9111 | Set a read watchpoint for an expression.\n\ | |
c906108c | 9112 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 9113 | an expression is read.")); |
65d12d83 | 9114 | set_cmd_completer (c, expression_completer); |
c906108c | 9115 | |
1bedd215 AC |
9116 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
9117 | Set a watchpoint for an expression.\n\ | |
c906108c | 9118 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 9119 | an expression is either read or written.")); |
65d12d83 | 9120 | set_cmd_completer (c, expression_completer); |
c906108c SS |
9121 | |
9122 | add_info ("watchpoints", breakpoints_info, | |
1bedd215 | 9123 | _("Synonym for ``info breakpoints''.")); |
c906108c SS |
9124 | |
9125 | ||
920d2a44 AC |
9126 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
9127 | respond to changes - contrary to the description. */ | |
85c07804 AC |
9128 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
9129 | &can_use_hw_watchpoints, _("\ | |
9130 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
9131 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
9132 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
9133 | such is available. (However, any hardware watchpoints that were\n\ | |
9134 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
9135 | hardware.)"), |
9136 | NULL, | |
920d2a44 | 9137 | show_can_use_hw_watchpoints, |
85c07804 | 9138 | &setlist, &showlist); |
c906108c SS |
9139 | |
9140 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 9141 | |
1042e4c0 SS |
9142 | /* Tracepoint manipulation commands. */ |
9143 | ||
9144 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
9145 | Set a tracepoint at specified line or function.\n\ | |
9146 | \n" | |
9147 | BREAK_ARGS_HELP ("trace") "\n\ | |
9148 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
9149 | set_cmd_completer (c, location_completer); | |
9150 | ||
9151 | add_com_alias ("tp", "trace", class_alias, 0); | |
9152 | add_com_alias ("tr", "trace", class_alias, 1); | |
9153 | add_com_alias ("tra", "trace", class_alias, 1); | |
9154 | add_com_alias ("trac", "trace", class_alias, 1); | |
9155 | ||
9156 | add_info ("tracepoints", tracepoints_info, _("\ | |
9157 | Status of tracepoints, or tracepoint number NUMBER.\n\ | |
9158 | Convenience variable \"$tpnum\" contains the number of the\n\ | |
9159 | last tracepoint set.")); | |
9160 | ||
9161 | add_info_alias ("tp", "tracepoints", 1); | |
9162 | ||
9163 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
9164 | Delete specified tracepoints.\n\ | |
9165 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
9166 | No argument means delete all tracepoints."), | |
9167 | &deletelist); | |
9168 | ||
9169 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
9170 | Disable specified tracepoints.\n\ | |
9171 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
9172 | No argument means disable all tracepoints."), | |
9173 | &disablelist); | |
9174 | deprecate_cmd (c, "disable"); | |
9175 | ||
9176 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
9177 | Enable specified tracepoints.\n\ | |
9178 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
9179 | No argument means enable all tracepoints."), | |
9180 | &enablelist); | |
9181 | deprecate_cmd (c, "enable"); | |
9182 | ||
9183 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
9184 | Set the passcount for a tracepoint.\n\ | |
9185 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
9186 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
9187 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
9188 | ||
9189 | c = add_com ("save-tracepoints", class_trace, tracepoint_save_command, _("\ | |
9190 | Save current tracepoint definitions as a script.\n\ | |
9191 | Use the 'source' command in another debug session to restore them.")); | |
9192 | set_cmd_completer (c, filename_completer); | |
9193 | ||
1bedd215 | 9194 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
9195 | Breakpoint specific settings\n\ |
9196 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 9197 | pending breakpoint behavior"), |
fa8d40ab JJ |
9198 | &breakpoint_set_cmdlist, "set breakpoint ", |
9199 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 9200 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
9201 | Breakpoint specific settings\n\ |
9202 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 9203 | pending breakpoint behavior"), |
fa8d40ab JJ |
9204 | &breakpoint_show_cmdlist, "show breakpoint ", |
9205 | 0/*allow-unknown*/, &showlist); | |
9206 | ||
7915a72c AC |
9207 | add_setshow_auto_boolean_cmd ("pending", no_class, |
9208 | &pending_break_support, _("\ | |
9209 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
9210 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
9211 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
9212 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
9213 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 9214 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 9215 | NULL, |
920d2a44 | 9216 | show_pending_break_support, |
6e1d7d6c AC |
9217 | &breakpoint_set_cmdlist, |
9218 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
9219 | |
9220 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
9221 | |
9222 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
9223 | &automatic_hardware_breakpoints, _("\ | |
9224 | Set automatic usage of hardware breakpoints."), _("\ | |
9225 | Show automatic usage of hardware breakpoints."), _("\ | |
9226 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
9227 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
9228 | a warning will be emitted for such breakpoints."), | |
9229 | NULL, | |
9230 | show_automatic_hardware_breakpoints, | |
9231 | &breakpoint_set_cmdlist, | |
9232 | &breakpoint_show_cmdlist); | |
74960c60 | 9233 | |
33e5cbd6 PA |
9234 | add_setshow_enum_cmd ("always-inserted", class_support, |
9235 | always_inserted_enums, &always_inserted_mode, _("\ | |
74960c60 VP |
9236 | Set mode for inserting breakpoints."), _("\ |
9237 | Show mode for inserting breakpoints."), _("\ | |
33e5cbd6 PA |
9238 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
9239 | resumed, and removed when execution stops. When this mode is on,\n\ | |
9240 | breakpoints are inserted immediately and removed only when the user\n\ | |
9241 | deletes the breakpoint. When this mode is auto (which is the default),\n\ | |
9242 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ | |
9243 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ | |
9244 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ | |
9245 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), | |
74960c60 VP |
9246 | NULL, |
9247 | &show_always_inserted_mode, | |
9248 | &breakpoint_set_cmdlist, | |
9249 | &breakpoint_show_cmdlist); | |
765dc015 VP |
9250 | |
9251 | automatic_hardware_breakpoints = 1; | |
f3b1572e PA |
9252 | |
9253 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
c906108c | 9254 | } |