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" |
4efc6507 | 62 | #include "jit.h" |
a96d9b2e | 63 | #include "xml-syscall.h" |
c906108c | 64 | |
1042e4c0 SS |
65 | /* readline include files */ |
66 | #include "readline/readline.h" | |
67 | #include "readline/history.h" | |
68 | ||
69 | /* readline defines this. */ | |
70 | #undef savestring | |
71 | ||
034dad6f | 72 | #include "mi/mi-common.h" |
104c1213 | 73 | |
44feb3ce TT |
74 | /* Arguments to pass as context to some catch command handlers. */ |
75 | #define CATCH_PERMANENT ((void *) (uintptr_t) 0) | |
76 | #define CATCH_TEMPORARY ((void *) (uintptr_t) 1) | |
c906108c | 77 | |
44feb3ce | 78 | /* Prototypes for local functions. */ |
c906108c | 79 | |
a14ed312 | 80 | static void enable_delete_command (char *, int); |
c906108c | 81 | |
a14ed312 | 82 | static void enable_delete_breakpoint (struct breakpoint *); |
c906108c | 83 | |
a14ed312 | 84 | static void enable_once_command (char *, int); |
c906108c | 85 | |
a14ed312 | 86 | static void enable_once_breakpoint (struct breakpoint *); |
c906108c | 87 | |
a14ed312 | 88 | static void disable_command (char *, int); |
c906108c | 89 | |
a14ed312 | 90 | static void enable_command (char *, int); |
c906108c | 91 | |
a14ed312 | 92 | static void map_breakpoint_numbers (char *, void (*)(struct breakpoint *)); |
c906108c | 93 | |
a14ed312 | 94 | static void ignore_command (char *, int); |
c906108c | 95 | |
4efb68b1 | 96 | static int breakpoint_re_set_one (void *); |
c906108c | 97 | |
a14ed312 | 98 | static void clear_command (char *, int); |
c906108c | 99 | |
a14ed312 | 100 | static void catch_command (char *, int); |
c906108c | 101 | |
a14ed312 | 102 | static void watch_command (char *, int); |
c906108c | 103 | |
a14ed312 | 104 | static int can_use_hardware_watchpoint (struct value *); |
c906108c | 105 | |
98deb0da | 106 | static void break_command_1 (char *, int, int); |
c906108c | 107 | |
a14ed312 | 108 | static void mention (struct breakpoint *); |
c906108c | 109 | |
63c252f8 PM |
110 | /* This function is used in gdbtk sources and thus can not be made static. */ |
111 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, | |
a6d9a66e UW |
112 | struct symtab_and_line, |
113 | enum bptype); | |
c906108c | 114 | |
9f60f21b | 115 | static void check_duplicates (struct breakpoint *); |
c906108c | 116 | |
76897487 KB |
117 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
118 | ||
a6d9a66e UW |
119 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
120 | CORE_ADDR bpaddr, | |
88f7da05 | 121 | enum bptype bptype); |
76897487 | 122 | |
6c95b8df PA |
123 | static void describe_other_breakpoints (struct gdbarch *, |
124 | struct program_space *, CORE_ADDR, | |
5af949e3 | 125 | struct obj_section *, int); |
c906108c | 126 | |
6c95b8df PA |
127 | static int breakpoint_address_match (struct address_space *aspace1, |
128 | CORE_ADDR addr1, | |
129 | struct address_space *aspace2, | |
130 | CORE_ADDR addr2); | |
131 | ||
a14ed312 | 132 | static void breakpoints_info (char *, int); |
c906108c | 133 | |
a14ed312 | 134 | static void breakpoint_1 (int, int); |
c906108c | 135 | |
89f9893c | 136 | static bpstat bpstat_alloc (const struct bp_location *, bpstat); |
c906108c | 137 | |
4efb68b1 | 138 | static int breakpoint_cond_eval (void *); |
c906108c | 139 | |
4efb68b1 | 140 | static void cleanup_executing_breakpoints (void *); |
c906108c | 141 | |
a14ed312 | 142 | static void commands_command (char *, int); |
c906108c | 143 | |
a14ed312 | 144 | static void condition_command (char *, int); |
c906108c | 145 | |
a14ed312 | 146 | static int get_number_trailer (char **, int); |
c906108c | 147 | |
a14ed312 | 148 | void set_breakpoint_count (int); |
c906108c | 149 | |
c5aa993b JM |
150 | typedef enum |
151 | { | |
152 | mark_inserted, | |
153 | mark_uninserted | |
154 | } | |
155 | insertion_state_t; | |
c906108c | 156 | |
0bde7532 | 157 | static int remove_breakpoint (struct bp_location *, insertion_state_t); |
6c95b8df | 158 | static int remove_breakpoint_1 (struct bp_location *, insertion_state_t); |
c906108c | 159 | |
a14ed312 | 160 | static enum print_stop_action print_it_typical (bpstat); |
e514a9d6 JM |
161 | |
162 | static enum print_stop_action print_bp_stop_message (bpstat bs); | |
c906108c | 163 | |
4efb68b1 | 164 | static int watchpoint_check (void *); |
c906108c | 165 | |
a14ed312 | 166 | static void maintenance_info_breakpoints (char *, int); |
c906108c | 167 | |
a14ed312 | 168 | static int hw_breakpoint_used_count (void); |
c906108c | 169 | |
a14ed312 | 170 | static int hw_watchpoint_used_count (enum bptype, int *); |
c906108c | 171 | |
a14ed312 | 172 | static void hbreak_command (char *, int); |
c906108c | 173 | |
a14ed312 | 174 | static void thbreak_command (char *, int); |
c906108c | 175 | |
a14ed312 | 176 | static void watch_command_1 (char *, int, int); |
c906108c | 177 | |
a14ed312 | 178 | static void rwatch_command (char *, int); |
c906108c | 179 | |
a14ed312 | 180 | static void awatch_command (char *, int); |
c906108c | 181 | |
a14ed312 | 182 | static void do_enable_breakpoint (struct breakpoint *, enum bpdisp); |
c906108c | 183 | |
a14ed312 | 184 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 185 | |
a14ed312 | 186 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 187 | |
a14ed312 | 188 | static void stopat_command (char *arg, int from_tty); |
7a292a7a | 189 | |
a14ed312 | 190 | static char *ep_parse_optional_if_clause (char **arg); |
7a292a7a | 191 | |
a14ed312 | 192 | static char *ep_parse_optional_filename (char **arg); |
7a292a7a | 193 | |
d85310f7 MS |
194 | static void catch_exception_command_1 (enum exception_event_kind ex_event, |
195 | char *arg, int tempflag, int from_tty); | |
7a292a7a | 196 | |
a14ed312 | 197 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 198 | |
a14ed312 | 199 | static void ep_skip_leading_whitespace (char **s); |
7a292a7a | 200 | |
6c95b8df PA |
201 | static int single_step_breakpoint_inserted_here_p (struct address_space *, |
202 | CORE_ADDR pc); | |
1aafd4da | 203 | |
fe3f5fa8 VP |
204 | static void free_bp_location (struct bp_location *loc); |
205 | ||
39d61571 | 206 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 207 | |
b60e7edf | 208 | static void update_global_location_list (int); |
a5606eee | 209 | |
b60e7edf | 210 | static void update_global_location_list_nothrow (int); |
74960c60 VP |
211 | |
212 | static int is_hardware_watchpoint (struct breakpoint *bpt); | |
213 | ||
214 | static void insert_breakpoint_locations (void); | |
a5606eee | 215 | |
a96d9b2e SDJ |
216 | static int syscall_catchpoint_p (struct breakpoint *b); |
217 | ||
1042e4c0 SS |
218 | static void tracepoints_info (char *, int); |
219 | ||
220 | static void delete_trace_command (char *, int); | |
221 | ||
222 | static void enable_trace_command (char *, int); | |
223 | ||
224 | static void disable_trace_command (char *, int); | |
225 | ||
226 | static void trace_pass_command (char *, int); | |
227 | ||
3daf8fe5 JG |
228 | static void skip_prologue_sal (struct symtab_and_line *sal); |
229 | ||
230 | ||
f3b1572e PA |
231 | /* Flag indicating that a command has proceeded the inferior past the |
232 | current breakpoint. */ | |
233 | ||
234 | static int breakpoint_proceeded; | |
235 | ||
2cec12e5 AR |
236 | static const char * |
237 | bpdisp_text (enum bpdisp disp) | |
238 | { | |
239 | /* NOTE: the following values are a part of MI protocol and represent | |
240 | values of 'disp' field returned when inferior stops at a breakpoint. */ | |
241 | static char *bpdisps[] = {"del", "dstp", "dis", "keep"}; | |
242 | return bpdisps[(int) disp]; | |
243 | } | |
c906108c | 244 | |
2cec12e5 | 245 | /* Prototypes for exported functions. */ |
c906108c SS |
246 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
247 | if such is available. */ | |
248 | static int can_use_hw_watchpoints; | |
249 | ||
920d2a44 AC |
250 | static void |
251 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
252 | struct cmd_list_element *c, | |
253 | const char *value) | |
254 | { | |
255 | fprintf_filtered (file, _("\ | |
256 | Debugger's willingness to use watchpoint hardware is %s.\n"), | |
257 | value); | |
258 | } | |
259 | ||
fa8d40ab JJ |
260 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
261 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
262 | for unrecognized breakpoint locations. | |
263 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ | |
264 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
265 | static void |
266 | show_pending_break_support (struct ui_file *file, int from_tty, | |
267 | struct cmd_list_element *c, | |
268 | const char *value) | |
269 | { | |
270 | fprintf_filtered (file, _("\ | |
271 | Debugger's behavior regarding pending breakpoints is %s.\n"), | |
272 | value); | |
273 | } | |
fa8d40ab | 274 | |
765dc015 VP |
275 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
276 | set with "break" but falling in read-only memory. | |
277 | If 0, gdb will warn about such breakpoints, but won't automatically | |
278 | use hardware breakpoints. */ | |
279 | static int automatic_hardware_breakpoints; | |
280 | static void | |
281 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
282 | struct cmd_list_element *c, | |
283 | const char *value) | |
284 | { | |
285 | fprintf_filtered (file, _("\ | |
286 | Automatic usage of hardware breakpoints is %s.\n"), | |
287 | value); | |
288 | } | |
289 | ||
33e5cbd6 PA |
290 | /* If on, gdb will keep breakpoints inserted even as inferior is |
291 | stopped, and immediately insert any new breakpoints. If off, gdb | |
292 | will insert breakpoints into inferior only when resuming it, and | |
293 | will remove breakpoints upon stop. If auto, GDB will behave as ON | |
294 | if in non-stop mode, and as OFF if all-stop mode.*/ | |
295 | ||
296 | static const char always_inserted_auto[] = "auto"; | |
297 | static const char always_inserted_on[] = "on"; | |
298 | static const char always_inserted_off[] = "off"; | |
299 | static const char *always_inserted_enums[] = { | |
300 | always_inserted_auto, | |
301 | always_inserted_off, | |
302 | always_inserted_on, | |
303 | NULL | |
304 | }; | |
305 | static const char *always_inserted_mode = always_inserted_auto; | |
306 | static void | |
74960c60 | 307 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 308 | struct cmd_list_element *c, const char *value) |
74960c60 | 309 | { |
33e5cbd6 PA |
310 | if (always_inserted_mode == always_inserted_auto) |
311 | fprintf_filtered (file, _("\ | |
312 | Always inserted breakpoint mode is %s (currently %s).\n"), | |
313 | value, | |
314 | breakpoints_always_inserted_mode () ? "on" : "off"); | |
315 | else | |
316 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), value); | |
74960c60 VP |
317 | } |
318 | ||
33e5cbd6 PA |
319 | int |
320 | breakpoints_always_inserted_mode (void) | |
321 | { | |
322 | return (always_inserted_mode == always_inserted_on | |
323 | || (always_inserted_mode == always_inserted_auto && non_stop)); | |
324 | } | |
765dc015 | 325 | |
a14ed312 | 326 | void _initialize_breakpoint (void); |
c906108c | 327 | |
c906108c SS |
328 | /* Are we executing breakpoint commands? */ |
329 | static int executing_breakpoint_commands; | |
330 | ||
c02f5703 MS |
331 | /* Are overlay event breakpoints enabled? */ |
332 | static int overlay_events_enabled; | |
333 | ||
c906108c SS |
334 | /* Walk the following statement or block through all breakpoints. |
335 | ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current | |
336 | breakpoint. */ | |
337 | ||
5c44784c | 338 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 339 | |
5c44784c JM |
340 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
341 | for (B = breakpoint_chain; \ | |
342 | B ? (TMP=B->next, 1): 0; \ | |
343 | B = TMP) | |
c906108c | 344 | |
7cc221ef DJ |
345 | /* Similar iterators for the low-level breakpoints. */ |
346 | ||
0d381245 | 347 | #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->global_next) |
7cc221ef DJ |
348 | |
349 | #define ALL_BP_LOCATIONS_SAFE(B,TMP) \ | |
350 | for (B = bp_location_chain; \ | |
0d381245 | 351 | B ? (TMP=B->global_next, 1): 0; \ |
7cc221ef DJ |
352 | B = TMP) |
353 | ||
1042e4c0 SS |
354 | /* Iterator for tracepoints only. */ |
355 | ||
356 | #define ALL_TRACEPOINTS(B) \ | |
357 | for (B = breakpoint_chain; B; B = B->next) \ | |
358 | if ((B)->type == bp_tracepoint) | |
359 | ||
7cc221ef | 360 | /* Chains of all breakpoints defined. */ |
c906108c SS |
361 | |
362 | struct breakpoint *breakpoint_chain; | |
363 | ||
7cc221ef DJ |
364 | struct bp_location *bp_location_chain; |
365 | ||
20874c92 VP |
366 | /* The locations that no longer correspond to any breakpoint, |
367 | unlinked from bp_location_chain, but for which a hit | |
368 | may still be reported by a target. */ | |
369 | VEC(bp_location_p) *moribund_locations = NULL; | |
370 | ||
c906108c SS |
371 | /* Number of last breakpoint made. */ |
372 | ||
373 | int breakpoint_count; | |
374 | ||
1042e4c0 SS |
375 | /* Number of last tracepoint made. */ |
376 | ||
377 | int tracepoint_count; | |
378 | ||
468d015d JJ |
379 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
380 | static int | |
381 | breakpoint_enabled (struct breakpoint *b) | |
382 | { | |
0d381245 | 383 | return (b->enable_state == bp_enabled); |
468d015d JJ |
384 | } |
385 | ||
c906108c SS |
386 | /* Set breakpoint count to NUM. */ |
387 | ||
388 | void | |
fba45db2 | 389 | set_breakpoint_count (int num) |
c906108c SS |
390 | { |
391 | breakpoint_count = num; | |
4fa62494 | 392 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
393 | } |
394 | ||
395 | /* Used in run_command to zero the hit count when a new run starts. */ | |
396 | ||
397 | void | |
fba45db2 | 398 | clear_breakpoint_hit_counts (void) |
c906108c SS |
399 | { |
400 | struct breakpoint *b; | |
401 | ||
402 | ALL_BREAKPOINTS (b) | |
403 | b->hit_count = 0; | |
404 | } | |
405 | ||
406 | /* Default address, symtab and line to put a breakpoint at | |
407 | for "break" command with no arg. | |
408 | if default_breakpoint_valid is zero, the other three are | |
409 | not valid, and "break" with no arg is an error. | |
410 | ||
411 | This set by print_stack_frame, which calls set_default_breakpoint. */ | |
412 | ||
413 | int default_breakpoint_valid; | |
414 | CORE_ADDR default_breakpoint_address; | |
415 | struct symtab *default_breakpoint_symtab; | |
416 | int default_breakpoint_line; | |
6c95b8df PA |
417 | struct program_space *default_breakpoint_pspace; |
418 | ||
c906108c SS |
419 | \f |
420 | /* *PP is a string denoting a breakpoint. Get the number of the breakpoint. | |
421 | Advance *PP after the string and any trailing whitespace. | |
422 | ||
423 | Currently the string can either be a number or "$" followed by the name | |
424 | of a convenience variable. Making it an expression wouldn't work well | |
5c44784c | 425 | for map_breakpoint_numbers (e.g. "4 + 5 + 6"). |
40c03ae8 EZ |
426 | |
427 | If the string is a NULL pointer, that denotes the last breakpoint. | |
5c44784c JM |
428 | |
429 | TRAILER is a character which can be found after the number; most | |
430 | commonly this is `-'. If you don't want a trailer, use \0. */ | |
c906108c | 431 | static int |
fba45db2 | 432 | get_number_trailer (char **pp, int trailer) |
c906108c | 433 | { |
5c44784c | 434 | int retval = 0; /* default */ |
c906108c SS |
435 | char *p = *pp; |
436 | ||
437 | if (p == NULL) | |
438 | /* Empty line means refer to the last breakpoint. */ | |
439 | return breakpoint_count; | |
440 | else if (*p == '$') | |
441 | { | |
442 | /* Make a copy of the name, so we can null-terminate it | |
c5aa993b | 443 | to pass to lookup_internalvar(). */ |
c906108c SS |
444 | char *varname; |
445 | char *start = ++p; | |
4fa62494 | 446 | LONGEST val; |
c906108c SS |
447 | |
448 | while (isalnum (*p) || *p == '_') | |
449 | p++; | |
450 | varname = (char *) alloca (p - start + 1); | |
451 | strncpy (varname, start, p - start); | |
452 | varname[p - start] = '\0'; | |
4fa62494 UW |
453 | if (get_internalvar_integer (lookup_internalvar (varname), &val)) |
454 | retval = (int) val; | |
5c44784c JM |
455 | else |
456 | { | |
a3f17187 | 457 | printf_filtered (_("Convenience variable must have integer value.\n")); |
5c44784c JM |
458 | retval = 0; |
459 | } | |
c906108c SS |
460 | } |
461 | else | |
462 | { | |
463 | if (*p == '-') | |
464 | ++p; | |
465 | while (*p >= '0' && *p <= '9') | |
466 | ++p; | |
467 | if (p == *pp) | |
468 | /* There is no number here. (e.g. "cond a == b"). */ | |
5c44784c JM |
469 | { |
470 | /* Skip non-numeric token */ | |
471 | while (*p && !isspace((int) *p)) | |
472 | ++p; | |
473 | /* Return zero, which caller must interpret as error. */ | |
474 | retval = 0; | |
475 | } | |
476 | else | |
477 | retval = atoi (*pp); | |
478 | } | |
479 | if (!(isspace (*p) || *p == '\0' || *p == trailer)) | |
480 | { | |
481 | /* Trailing junk: return 0 and let caller print error msg. */ | |
482 | while (!(isspace (*p) || *p == '\0' || *p == trailer)) | |
483 | ++p; | |
484 | retval = 0; | |
c906108c | 485 | } |
c906108c SS |
486 | while (isspace (*p)) |
487 | p++; | |
488 | *pp = p; | |
489 | return retval; | |
490 | } | |
5c44784c | 491 | |
11cf8741 | 492 | |
5c44784c JM |
493 | /* Like get_number_trailer, but don't allow a trailer. */ |
494 | int | |
fba45db2 | 495 | get_number (char **pp) |
5c44784c JM |
496 | { |
497 | return get_number_trailer (pp, '\0'); | |
498 | } | |
499 | ||
500 | /* Parse a number or a range. | |
501 | * A number will be of the form handled by get_number. | |
502 | * A range will be of the form <number1> - <number2>, and | |
503 | * will represent all the integers between number1 and number2, | |
504 | * inclusive. | |
505 | * | |
506 | * While processing a range, this fuction is called iteratively; | |
507 | * At each call it will return the next value in the range. | |
508 | * | |
509 | * At the beginning of parsing a range, the char pointer PP will | |
510 | * be advanced past <number1> and left pointing at the '-' token. | |
511 | * Subsequent calls will not advance the pointer until the range | |
512 | * is completed. The call that completes the range will advance | |
513 | * pointer PP past <number2>. | |
514 | */ | |
515 | ||
516 | int | |
fba45db2 | 517 | get_number_or_range (char **pp) |
5c44784c JM |
518 | { |
519 | static int last_retval, end_value; | |
520 | static char *end_ptr; | |
521 | static int in_range = 0; | |
522 | ||
523 | if (**pp != '-') | |
524 | { | |
525 | /* Default case: pp is pointing either to a solo number, | |
526 | or to the first number of a range. */ | |
527 | last_retval = get_number_trailer (pp, '-'); | |
528 | if (**pp == '-') | |
529 | { | |
530 | char **temp; | |
531 | ||
532 | /* This is the start of a range (<number1> - <number2>). | |
533 | Skip the '-', parse and remember the second number, | |
534 | and also remember the end of the final token. */ | |
535 | ||
536 | temp = &end_ptr; | |
537 | end_ptr = *pp + 1; | |
538 | while (isspace ((int) *end_ptr)) | |
539 | end_ptr++; /* skip white space */ | |
540 | end_value = get_number (temp); | |
541 | if (end_value < last_retval) | |
542 | { | |
8a3fe4f8 | 543 | error (_("inverted range")); |
5c44784c JM |
544 | } |
545 | else if (end_value == last_retval) | |
546 | { | |
547 | /* degenerate range (number1 == number2). Advance the | |
548 | token pointer so that the range will be treated as a | |
549 | single number. */ | |
550 | *pp = end_ptr; | |
551 | } | |
552 | else | |
553 | in_range = 1; | |
554 | } | |
555 | } | |
556 | else if (! in_range) | |
8a3fe4f8 | 557 | error (_("negative value")); |
5c44784c JM |
558 | else |
559 | { | |
560 | /* pp points to the '-' that betokens a range. All | |
561 | number-parsing has already been done. Return the next | |
562 | integer value (one greater than the saved previous value). | |
563 | Do not advance the token pointer 'pp' until the end of range | |
564 | is reached. */ | |
565 | ||
566 | if (++last_retval == end_value) | |
567 | { | |
568 | /* End of range reached; advance token pointer. */ | |
569 | *pp = end_ptr; | |
570 | in_range = 0; | |
571 | } | |
572 | } | |
573 | return last_retval; | |
574 | } | |
575 | ||
48cb2d85 VP |
576 | /* Return the breakpoint with the specified number, or NULL |
577 | if the number does not refer to an existing breakpoint. */ | |
578 | ||
579 | struct breakpoint * | |
580 | get_breakpoint (int num) | |
581 | { | |
582 | struct breakpoint *b; | |
583 | ||
584 | ALL_BREAKPOINTS (b) | |
585 | if (b->number == num) | |
586 | return b; | |
587 | ||
588 | return NULL; | |
589 | } | |
5c44784c | 590 | |
c906108c SS |
591 | \f |
592 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ | |
593 | ||
594 | static void | |
fba45db2 | 595 | condition_command (char *arg, int from_tty) |
c906108c | 596 | { |
52f0bd74 | 597 | struct breakpoint *b; |
c906108c | 598 | char *p; |
52f0bd74 | 599 | int bnum; |
c906108c SS |
600 | |
601 | if (arg == 0) | |
e2e0b3e5 | 602 | error_no_arg (_("breakpoint number")); |
c906108c SS |
603 | |
604 | p = arg; | |
605 | bnum = get_number (&p); | |
5c44784c | 606 | if (bnum == 0) |
8a3fe4f8 | 607 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
608 | |
609 | ALL_BREAKPOINTS (b) | |
610 | if (b->number == bnum) | |
2f069f6f JB |
611 | { |
612 | struct bp_location *loc = b->loc; | |
613 | for (; loc; loc = loc->next) | |
614 | { | |
615 | if (loc->cond) | |
616 | { | |
617 | xfree (loc->cond); | |
618 | loc->cond = 0; | |
619 | } | |
620 | } | |
621 | if (b->cond_string != NULL) | |
622 | xfree (b->cond_string); | |
c906108c | 623 | |
2f069f6f JB |
624 | if (*p == 0) |
625 | { | |
626 | b->cond_string = NULL; | |
627 | if (from_tty) | |
628 | printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum); | |
629 | } | |
630 | else | |
631 | { | |
632 | arg = p; | |
633 | /* I don't know if it matters whether this is the string the user | |
634 | typed in or the decompiled expression. */ | |
1b36a34b | 635 | b->cond_string = xstrdup (arg); |
2f069f6f JB |
636 | b->condition_not_parsed = 0; |
637 | for (loc = b->loc; loc; loc = loc->next) | |
638 | { | |
639 | arg = p; | |
640 | loc->cond = | |
641 | parse_exp_1 (&arg, block_for_pc (loc->address), 0); | |
642 | if (*arg) | |
643 | error (_("Junk at end of expression")); | |
644 | } | |
645 | } | |
646 | breakpoints_changed (); | |
383f836e | 647 | observer_notify_breakpoint_modified (b->number); |
2f069f6f JB |
648 | return; |
649 | } | |
c906108c | 650 | |
8a3fe4f8 | 651 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
652 | } |
653 | ||
48cb2d85 VP |
654 | /* Set the command list of B to COMMANDS. */ |
655 | ||
656 | void | |
657 | breakpoint_set_commands (struct breakpoint *b, struct command_line *commands) | |
658 | { | |
659 | free_command_lines (&b->commands); | |
660 | b->commands = commands; | |
661 | breakpoints_changed (); | |
662 | observer_notify_breakpoint_modified (b->number); | |
663 | } | |
664 | ||
c906108c | 665 | static void |
fba45db2 | 666 | commands_command (char *arg, int from_tty) |
c906108c | 667 | { |
52f0bd74 | 668 | struct breakpoint *b; |
c906108c | 669 | char *p; |
52f0bd74 | 670 | int bnum; |
c906108c SS |
671 | struct command_line *l; |
672 | ||
673 | /* If we allowed this, we would have problems with when to | |
674 | free the storage, if we change the commands currently | |
675 | being read from. */ | |
676 | ||
677 | if (executing_breakpoint_commands) | |
8a3fe4f8 | 678 | error (_("Can't use the \"commands\" command among a breakpoint's commands.")); |
c906108c SS |
679 | |
680 | p = arg; | |
681 | bnum = get_number (&p); | |
5c44784c | 682 | |
c906108c | 683 | if (p && *p) |
8a3fe4f8 | 684 | error (_("Unexpected extra arguments following breakpoint number.")); |
c5aa993b | 685 | |
c906108c SS |
686 | ALL_BREAKPOINTS (b) |
687 | if (b->number == bnum) | |
9ebf4acf AC |
688 | { |
689 | char *tmpbuf = xstrprintf ("Type commands for when breakpoint %d is hit, one per line.", | |
690 | bnum); | |
691 | struct cleanup *cleanups = make_cleanup (xfree, tmpbuf); | |
311a4e6b | 692 | l = read_command_lines (tmpbuf, from_tty, 1); |
9ebf4acf | 693 | do_cleanups (cleanups); |
48cb2d85 | 694 | breakpoint_set_commands (b, l); |
9ebf4acf | 695 | return; |
c5aa993b | 696 | } |
8a3fe4f8 | 697 | error (_("No breakpoint number %d."), bnum); |
c906108c | 698 | } |
40c03ae8 EZ |
699 | |
700 | /* Like commands_command, but instead of reading the commands from | |
701 | input stream, takes them from an already parsed command structure. | |
702 | ||
703 | This is used by cli-script.c to DTRT with breakpoint commands | |
704 | that are part of if and while bodies. */ | |
705 | enum command_control_type | |
706 | commands_from_control_command (char *arg, struct command_line *cmd) | |
707 | { | |
708 | struct breakpoint *b; | |
709 | char *p; | |
710 | int bnum; | |
711 | ||
712 | /* If we allowed this, we would have problems with when to | |
713 | free the storage, if we change the commands currently | |
714 | being read from. */ | |
715 | ||
716 | if (executing_breakpoint_commands) | |
717 | error (_("Can't use the \"commands\" command among a breakpoint's commands.")); | |
718 | ||
719 | /* An empty string for the breakpoint number means the last | |
720 | breakpoint, but get_number expects a NULL pointer. */ | |
721 | if (arg && !*arg) | |
722 | p = NULL; | |
723 | else | |
724 | p = arg; | |
725 | bnum = get_number (&p); | |
726 | ||
727 | if (p && *p) | |
728 | error (_("Unexpected extra arguments following breakpoint number.")); | |
729 | ||
730 | ALL_BREAKPOINTS (b) | |
731 | if (b->number == bnum) | |
732 | { | |
733 | free_command_lines (&b->commands); | |
734 | if (cmd->body_count != 1) | |
735 | error (_("Invalid \"commands\" block structure.")); | |
736 | /* We need to copy the commands because if/while will free the | |
737 | list after it finishes execution. */ | |
738 | b->commands = copy_command_lines (cmd->body_list[0]); | |
739 | breakpoints_changed (); | |
383f836e | 740 | observer_notify_breakpoint_modified (b->number); |
40c03ae8 | 741 | return simple_control; |
2f069f6f | 742 | } |
40c03ae8 EZ |
743 | error (_("No breakpoint number %d."), bnum); |
744 | } | |
c906108c | 745 | \f |
8defab1a DJ |
746 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
747 | by replacing any memory breakpoints with their shadowed contents. */ | |
c906108c | 748 | |
8defab1a DJ |
749 | void |
750 | breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len) | |
c906108c | 751 | { |
8defab1a | 752 | struct bp_location *b; |
c906108c SS |
753 | CORE_ADDR bp_addr = 0; |
754 | int bp_size = 0; | |
8defab1a | 755 | int bptoffset = 0; |
c5aa993b | 756 | |
ffce0d52 | 757 | ALL_BP_LOCATIONS (b) |
c5aa993b | 758 | { |
ffce0d52 | 759 | if (b->owner->type == bp_none) |
8a3fe4f8 | 760 | warning (_("reading through apparently deleted breakpoint #%d?"), |
ffce0d52 DJ |
761 | b->owner->number); |
762 | ||
763 | if (b->loc_type != bp_loc_software_breakpoint) | |
c5aa993b | 764 | continue; |
ffce0d52 | 765 | if (!b->inserted) |
c5aa993b | 766 | continue; |
6c95b8df PA |
767 | if (!breakpoint_address_match (b->target_info.placed_address_space, 0, |
768 | current_program_space->aspace, 0)) | |
769 | continue; | |
770 | ||
c5aa993b JM |
771 | /* Addresses and length of the part of the breakpoint that |
772 | we need to copy. */ | |
8181d85f DJ |
773 | bp_addr = b->target_info.placed_address; |
774 | bp_size = b->target_info.shadow_len; | |
c5aa993b | 775 | if (bp_size == 0) |
8181d85f | 776 | /* bp isn't valid, or doesn't shadow memory. */ |
c5aa993b | 777 | continue; |
8defab1a | 778 | |
c5aa993b JM |
779 | if (bp_addr + bp_size <= memaddr) |
780 | /* The breakpoint is entirely before the chunk of memory we | |
781 | are reading. */ | |
782 | continue; | |
8defab1a | 783 | |
c5aa993b JM |
784 | if (bp_addr >= memaddr + len) |
785 | /* The breakpoint is entirely after the chunk of memory we are | |
786 | reading. */ | |
787 | continue; | |
c5aa993b | 788 | |
8defab1a DJ |
789 | /* Offset within shadow_contents. */ |
790 | if (bp_addr < memaddr) | |
791 | { | |
792 | /* Only copy the second part of the breakpoint. */ | |
793 | bp_size -= memaddr - bp_addr; | |
794 | bptoffset = memaddr - bp_addr; | |
795 | bp_addr = memaddr; | |
796 | } | |
c5aa993b | 797 | |
8defab1a DJ |
798 | if (bp_addr + bp_size > memaddr + len) |
799 | { | |
800 | /* Only copy the first part of the breakpoint. */ | |
801 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
802 | } | |
c5aa993b | 803 | |
8defab1a DJ |
804 | memcpy (buf + bp_addr - memaddr, |
805 | b->target_info.shadow_contents + bptoffset, bp_size); | |
c5aa993b | 806 | } |
c906108c | 807 | } |
c906108c | 808 | \f |
c5aa993b | 809 | |
687595f9 | 810 | /* A wrapper function for inserting catchpoints. */ |
9cbc821d | 811 | static void |
687595f9 DJ |
812 | insert_catchpoint (struct ui_out *uo, void *args) |
813 | { | |
814 | struct breakpoint *b = (struct breakpoint *) args; | |
815 | int val = -1; | |
816 | ||
fe798b75 JB |
817 | gdb_assert (b->type == bp_catchpoint); |
818 | gdb_assert (b->ops != NULL && b->ops->insert != NULL); | |
819 | ||
820 | b->ops->insert (b); | |
687595f9 DJ |
821 | } |
822 | ||
a5606eee VP |
823 | static int |
824 | is_hardware_watchpoint (struct breakpoint *bpt) | |
825 | { | |
826 | return (bpt->type == bp_hardware_watchpoint | |
827 | || bpt->type == bp_read_watchpoint | |
828 | || bpt->type == bp_access_watchpoint); | |
829 | } | |
7270d8f2 | 830 | |
fa4727a6 DJ |
831 | /* Find the current value of a watchpoint on EXP. Return the value in |
832 | *VALP and *RESULTP and the chain of intermediate and final values | |
833 | in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does | |
834 | not need them. | |
835 | ||
ccc57cf9 | 836 | If a memory error occurs while evaluating the expression, *RESULTP will |
fa4727a6 DJ |
837 | be set to NULL. *RESULTP may be a lazy value, if the result could |
838 | not be read from memory. It is used to determine whether a value | |
839 | is user-specified (we should watch the whole value) or intermediate | |
840 | (we should watch only the bit used to locate the final value). | |
841 | ||
842 | If the final value, or any intermediate value, could not be read | |
843 | from memory, *VALP will be set to NULL. *VAL_CHAIN will still be | |
844 | set to any referenced values. *VALP will never be a lazy value. | |
845 | This is the value which we store in struct breakpoint. | |
846 | ||
847 | If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the | |
848 | value chain. The caller must free the values individually. If | |
849 | VAL_CHAIN is NULL, all generated values will be left on the value | |
850 | chain. */ | |
851 | ||
852 | static void | |
853 | fetch_watchpoint_value (struct expression *exp, struct value **valp, | |
854 | struct value **resultp, struct value **val_chain) | |
855 | { | |
856 | struct value *mark, *new_mark, *result; | |
ccc57cf9 | 857 | volatile struct gdb_exception ex; |
fa4727a6 DJ |
858 | |
859 | *valp = NULL; | |
860 | if (resultp) | |
861 | *resultp = NULL; | |
862 | if (val_chain) | |
863 | *val_chain = NULL; | |
864 | ||
865 | /* Evaluate the expression. */ | |
866 | mark = value_mark (); | |
867 | result = NULL; | |
ccc57cf9 PA |
868 | |
869 | TRY_CATCH (ex, RETURN_MASK_ALL) | |
870 | { | |
871 | result = evaluate_expression (exp); | |
872 | } | |
873 | if (ex.reason < 0) | |
874 | { | |
875 | /* Ignore memory errors, we want watchpoints pointing at | |
876 | inaccessible memory to still be created; otherwise, throw the | |
877 | error to some higher catcher. */ | |
878 | switch (ex.error) | |
879 | { | |
880 | case MEMORY_ERROR: | |
881 | break; | |
882 | default: | |
883 | throw_exception (ex); | |
884 | break; | |
885 | } | |
886 | } | |
887 | ||
fa4727a6 DJ |
888 | new_mark = value_mark (); |
889 | if (mark == new_mark) | |
890 | return; | |
891 | if (resultp) | |
892 | *resultp = result; | |
893 | ||
894 | /* Make sure it's not lazy, so that after the target stops again we | |
895 | have a non-lazy previous value to compare with. */ | |
896 | if (result != NULL | |
897 | && (!value_lazy (result) || gdb_value_fetch_lazy (result))) | |
898 | *valp = result; | |
899 | ||
900 | if (val_chain) | |
901 | { | |
902 | /* Return the chain of intermediate values. We use this to | |
903 | decide which addresses to watch. */ | |
904 | *val_chain = new_mark; | |
905 | value_release_to_mark (mark); | |
906 | } | |
907 | } | |
908 | ||
567e1b4e JB |
909 | /* Assuming that B is a watchpoint: |
910 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 911 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
912 | - Evaluate the condition if there is one, and store the result |
913 | in b->loc->cond. | |
a5606eee VP |
914 | - Update the list of values that must be watched in B->loc. |
915 | ||
bfa149ac JB |
916 | If the watchpoint disposition is disp_del_at_next_stop, then do nothing. |
917 | If this is local watchpoint that is out of scope, delete it. */ | |
b40ce68a | 918 | static void |
a5606eee | 919 | update_watchpoint (struct breakpoint *b, int reparse) |
7270d8f2 | 920 | { |
a5606eee | 921 | int within_current_scope; |
a5606eee VP |
922 | struct frame_id saved_frame_id; |
923 | struct bp_location *loc; | |
924 | bpstat bs; | |
6c95b8df | 925 | struct program_space *frame_pspace; |
a5606eee | 926 | |
567e1b4e JB |
927 | /* We don't free locations. They are stored in bp_location_chain and |
928 | update_global_locations will eventually delete them and remove | |
929 | breakpoints if needed. */ | |
a5606eee VP |
930 | b->loc = NULL; |
931 | ||
932 | if (b->disposition == disp_del_at_next_stop) | |
933 | return; | |
934 | ||
935 | /* Save the current frame's ID so we can restore it after | |
936 | evaluating the watchpoint expression on its own frame. */ | |
937 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
938 | took a frame parameter, so that we didn't have to change the | |
939 | selected frame. */ | |
940 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
941 | ||
942 | /* Determine if the watchpoint is within scope. */ | |
943 | if (b->exp_valid_block == NULL) | |
944 | within_current_scope = 1; | |
945 | else | |
946 | { | |
947 | struct frame_info *fi; | |
948 | fi = frame_find_by_id (b->watchpoint_frame); | |
949 | within_current_scope = (fi != NULL); | |
950 | if (within_current_scope) | |
951 | select_frame (fi); | |
952 | } | |
953 | ||
6c95b8df PA |
954 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
955 | ||
a5606eee VP |
956 | if (within_current_scope && reparse) |
957 | { | |
958 | char *s; | |
959 | if (b->exp) | |
960 | { | |
961 | xfree (b->exp); | |
962 | b->exp = NULL; | |
963 | } | |
964 | s = b->exp_string; | |
965 | b->exp = parse_exp_1 (&s, b->exp_valid_block, 0); | |
966 | /* If the meaning of expression itself changed, the old value is | |
967 | no longer relevant. We don't want to report a watchpoint hit | |
968 | to the user when the old value and the new value may actually | |
969 | be completely different objects. */ | |
970 | value_free (b->val); | |
fa4727a6 DJ |
971 | b->val = NULL; |
972 | b->val_valid = 0; | |
a5606eee | 973 | } |
a5606eee VP |
974 | |
975 | /* If we failed to parse the expression, for example because | |
976 | it refers to a global variable in a not-yet-loaded shared library, | |
977 | don't try to insert watchpoint. We don't automatically delete | |
978 | such watchpoint, though, since failure to parse expression | |
979 | is different from out-of-scope watchpoint. */ | |
980 | if (within_current_scope && b->exp) | |
981 | { | |
fa4727a6 | 982 | struct value *val_chain, *v, *result, *next; |
a5606eee | 983 | |
fa4727a6 | 984 | fetch_watchpoint_value (b->exp, &v, &result, &val_chain); |
a5606eee | 985 | |
a5606eee VP |
986 | /* Avoid setting b->val if it's already set. The meaning of |
987 | b->val is 'the last value' user saw, and we should update | |
988 | it only if we reported that last value to user. As it | |
989 | happens, the code that reports it updates b->val directly. */ | |
fa4727a6 DJ |
990 | if (!b->val_valid) |
991 | { | |
992 | b->val = v; | |
993 | b->val_valid = 1; | |
994 | } | |
a5606eee | 995 | |
db2ad4c3 JK |
996 | /* Change the type of breakpoint between hardware assisted or an |
997 | ordinary watchpoint depending on the hardware support and free | |
998 | hardware slots. REPARSE is set when the inferior is started. */ | |
999 | if ((b->type == bp_watchpoint || b->type == bp_hardware_watchpoint) | |
1000 | && reparse) | |
1001 | { | |
ca2d49e8 | 1002 | int i, mem_cnt, other_type_used; |
db2ad4c3 JK |
1003 | |
1004 | i = hw_watchpoint_used_count (bp_hardware_watchpoint, | |
1005 | &other_type_used); | |
1006 | mem_cnt = can_use_hardware_watchpoint (val_chain); | |
1007 | ||
ca2d49e8 | 1008 | if (!mem_cnt) |
db2ad4c3 JK |
1009 | b->type = bp_watchpoint; |
1010 | else | |
ca2d49e8 | 1011 | { |
d92524f1 | 1012 | int target_resources_ok = target_can_use_hardware_watchpoint |
ca2d49e8 SL |
1013 | (bp_hardware_watchpoint, i + mem_cnt, other_type_used); |
1014 | if (target_resources_ok <= 0) | |
1015 | b->type = bp_watchpoint; | |
1016 | else | |
1017 | b->type = bp_hardware_watchpoint; | |
1018 | } | |
db2ad4c3 JK |
1019 | } |
1020 | ||
a5606eee | 1021 | /* Look at each value on the value chain. */ |
fa4727a6 | 1022 | for (v = val_chain; v; v = next) |
a5606eee VP |
1023 | { |
1024 | /* If it's a memory location, and GDB actually needed | |
1025 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1026 | must watch it. If the first value returned is |
1027 | still lazy, that means an error occurred reading it; | |
1028 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1029 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1030 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1031 | { |
1032 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1033 | |
a5606eee VP |
1034 | /* We only watch structs and arrays if user asked |
1035 | for it explicitly, never if they just happen to | |
1036 | appear in the middle of some value chain. */ | |
fa4727a6 | 1037 | if (v == result |
a5606eee VP |
1038 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1039 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1040 | { | |
1041 | CORE_ADDR addr; | |
1042 | int len, type; | |
1043 | struct bp_location *loc, **tmp; | |
1044 | ||
42ae5230 | 1045 | addr = value_address (v); |
a5606eee VP |
1046 | len = TYPE_LENGTH (value_type (v)); |
1047 | type = hw_write; | |
1048 | if (b->type == bp_read_watchpoint) | |
1049 | type = hw_read; | |
1050 | else if (b->type == bp_access_watchpoint) | |
1051 | type = hw_access; | |
1052 | ||
39d61571 | 1053 | loc = allocate_bp_location (b); |
a5606eee VP |
1054 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
1055 | ; | |
1056 | *tmp = loc; | |
a6d9a66e | 1057 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1058 | |
1059 | loc->pspace = frame_pspace; | |
a5606eee VP |
1060 | loc->address = addr; |
1061 | loc->length = len; | |
1062 | loc->watchpoint_type = type; | |
1063 | } | |
1064 | } | |
1065 | ||
1066 | next = value_next (v); | |
1067 | if (v != b->val) | |
1068 | value_free (v); | |
1069 | } | |
1070 | ||
2ec93238 MK |
1071 | /* We just regenerated the list of breakpoint locations. |
1072 | The new location does not have its condition field set to anything | |
1073 | and therefore, we must always reparse the cond_string, independently | |
1074 | of the value of the reparse flag. */ | |
1075 | if (b->cond_string != NULL) | |
a5606eee VP |
1076 | { |
1077 | char *s = b->cond_string; | |
a5606eee VP |
1078 | b->loc->cond = parse_exp_1 (&s, b->exp_valid_block, 0); |
1079 | } | |
1080 | } | |
1081 | else if (!within_current_scope) | |
7270d8f2 | 1082 | { |
a5606eee | 1083 | printf_filtered (_("\ |
567e1b4e | 1084 | Watchpoint %d deleted because the program has left the block \n\ |
a5606eee VP |
1085 | in which its expression is valid.\n"), |
1086 | b->number); | |
1087 | if (b->related_breakpoint) | |
1088 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1089 | b->disposition = disp_del_at_next_stop; | |
7270d8f2 | 1090 | } |
a5606eee VP |
1091 | |
1092 | /* Restore the selected frame. */ | |
1093 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
1094 | } |
1095 | ||
a5606eee | 1096 | |
74960c60 VP |
1097 | /* Returns 1 iff breakpoint location should be |
1098 | inserted in the inferior. */ | |
1099 | static int | |
1100 | should_be_inserted (struct bp_location *bpt) | |
1101 | { | |
1102 | if (!breakpoint_enabled (bpt->owner)) | |
1103 | return 0; | |
1104 | ||
1105 | if (bpt->owner->disposition == disp_del_at_next_stop) | |
1106 | return 0; | |
1107 | ||
1108 | if (!bpt->enabled || bpt->shlib_disabled || bpt->duplicate) | |
1109 | return 0; | |
1110 | ||
1042e4c0 SS |
1111 | /* Tracepoints are inserted by the target at a time of its choosing, |
1112 | not by us. */ | |
1113 | if (bpt->owner->type == bp_tracepoint) | |
1114 | return 0; | |
1115 | ||
74960c60 VP |
1116 | return 1; |
1117 | } | |
1118 | ||
879bfdc2 DJ |
1119 | /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint. |
1120 | Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS, | |
fa3a767f | 1121 | and HW_BREAKPOINT_ERROR are used to report problems. |
879bfdc2 DJ |
1122 | |
1123 | NOTE drow/2003-09-09: This routine could be broken down to an object-style | |
1124 | method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 1125 | static int |
879bfdc2 | 1126 | insert_bp_location (struct bp_location *bpt, |
26bb91f3 | 1127 | struct ui_file *tmp_error_stream, |
fa3a767f | 1128 | int *disabled_breaks, |
26bb91f3 | 1129 | int *hw_breakpoint_error) |
879bfdc2 DJ |
1130 | { |
1131 | int val = 0; | |
1132 | ||
74960c60 | 1133 | if (!should_be_inserted (bpt) || bpt->inserted) |
879bfdc2 DJ |
1134 | return 0; |
1135 | ||
8181d85f DJ |
1136 | /* Initialize the target-specific information. */ |
1137 | memset (&bpt->target_info, 0, sizeof (bpt->target_info)); | |
1138 | bpt->target_info.placed_address = bpt->address; | |
6c95b8df | 1139 | bpt->target_info.placed_address_space = bpt->pspace->aspace; |
8181d85f | 1140 | |
879bfdc2 DJ |
1141 | if (bpt->loc_type == bp_loc_software_breakpoint |
1142 | || bpt->loc_type == bp_loc_hardware_breakpoint) | |
1143 | { | |
765dc015 VP |
1144 | if (bpt->owner->type != bp_hardware_breakpoint) |
1145 | { | |
1146 | /* If the explicitly specified breakpoint type | |
1147 | is not hardware breakpoint, check the memory map to see | |
1148 | if the breakpoint address is in read only memory or not. | |
1149 | Two important cases are: | |
1150 | - location type is not hardware breakpoint, memory | |
1151 | is readonly. We change the type of the location to | |
1152 | hardware breakpoint. | |
1153 | - location type is hardware breakpoint, memory is read-write. | |
1154 | This means we've previously made the location hardware one, but | |
1155 | then the memory map changed, so we undo. | |
1156 | ||
1157 | When breakpoints are removed, remove_breakpoints will | |
1158 | use location types we've just set here, the only possible | |
1159 | problem is that memory map has changed during running program, | |
1160 | but it's not going to work anyway with current gdb. */ | |
1161 | struct mem_region *mr | |
1162 | = lookup_mem_region (bpt->target_info.placed_address); | |
1163 | ||
1164 | if (mr) | |
1165 | { | |
1166 | if (automatic_hardware_breakpoints) | |
1167 | { | |
1168 | int changed = 0; | |
1169 | enum bp_loc_type new_type; | |
1170 | ||
1171 | if (mr->attrib.mode != MEM_RW) | |
1172 | new_type = bp_loc_hardware_breakpoint; | |
1173 | else | |
1174 | new_type = bp_loc_software_breakpoint; | |
1175 | ||
1176 | if (new_type != bpt->loc_type) | |
1177 | { | |
1178 | static int said = 0; | |
1179 | bpt->loc_type = new_type; | |
1180 | if (!said) | |
1181 | { | |
1182 | fprintf_filtered (gdb_stdout, _("\ | |
0767c96d | 1183 | Note: automatically using hardware breakpoints for read-only addresses.\n")); |
765dc015 VP |
1184 | said = 1; |
1185 | } | |
1186 | } | |
1187 | } | |
1188 | else if (bpt->loc_type == bp_loc_software_breakpoint | |
1189 | && mr->attrib.mode != MEM_RW) | |
1190 | warning (_("cannot set software breakpoint at readonly address %s"), | |
5af949e3 | 1191 | paddress (bpt->gdbarch, bpt->address)); |
765dc015 VP |
1192 | } |
1193 | } | |
1194 | ||
879bfdc2 DJ |
1195 | /* First check to see if we have to handle an overlay. */ |
1196 | if (overlay_debugging == ovly_off | |
1197 | || bpt->section == NULL | |
1198 | || !(section_is_overlay (bpt->section))) | |
1199 | { | |
1200 | /* No overlay handling: just set the breakpoint. */ | |
1201 | ||
1202 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
a6d9a66e UW |
1203 | val = target_insert_hw_breakpoint (bpt->gdbarch, |
1204 | &bpt->target_info); | |
879bfdc2 | 1205 | else |
a6d9a66e UW |
1206 | val = target_insert_breakpoint (bpt->gdbarch, |
1207 | &bpt->target_info); | |
879bfdc2 DJ |
1208 | } |
1209 | else | |
1210 | { | |
1211 | /* This breakpoint is in an overlay section. | |
1212 | Shall we set a breakpoint at the LMA? */ | |
1213 | if (!overlay_events_enabled) | |
1214 | { | |
1215 | /* Yes -- overlay event support is not active, | |
1216 | so we must try to set a breakpoint at the LMA. | |
1217 | This will not work for a hardware breakpoint. */ | |
1218 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
8a3fe4f8 | 1219 | warning (_("hardware breakpoint %d not supported in overlay!"), |
879bfdc2 DJ |
1220 | bpt->owner->number); |
1221 | else | |
1222 | { | |
1223 | CORE_ADDR addr = overlay_unmapped_address (bpt->address, | |
1224 | bpt->section); | |
1225 | /* Set a software (trap) breakpoint at the LMA. */ | |
8181d85f DJ |
1226 | bpt->overlay_target_info = bpt->target_info; |
1227 | bpt->overlay_target_info.placed_address = addr; | |
a6d9a66e UW |
1228 | val = target_insert_breakpoint (bpt->gdbarch, |
1229 | &bpt->overlay_target_info); | |
879bfdc2 | 1230 | if (val != 0) |
99361f52 DE |
1231 | fprintf_unfiltered (tmp_error_stream, |
1232 | "Overlay breakpoint %d failed: in ROM?\n", | |
879bfdc2 DJ |
1233 | bpt->owner->number); |
1234 | } | |
1235 | } | |
1236 | /* Shall we set a breakpoint at the VMA? */ | |
1237 | if (section_is_mapped (bpt->section)) | |
1238 | { | |
1239 | /* Yes. This overlay section is mapped into memory. */ | |
1240 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
a6d9a66e UW |
1241 | val = target_insert_hw_breakpoint (bpt->gdbarch, |
1242 | &bpt->target_info); | |
879bfdc2 | 1243 | else |
a6d9a66e UW |
1244 | val = target_insert_breakpoint (bpt->gdbarch, |
1245 | &bpt->target_info); | |
879bfdc2 DJ |
1246 | } |
1247 | else | |
1248 | { | |
1249 | /* No. This breakpoint will not be inserted. | |
1250 | No error, but do not mark the bp as 'inserted'. */ | |
1251 | return 0; | |
1252 | } | |
1253 | } | |
1254 | ||
1255 | if (val) | |
1256 | { | |
1257 | /* Can't set the breakpoint. */ | |
6c95b8df | 1258 | if (solib_name_from_address (bpt->pspace, bpt->address)) |
879bfdc2 DJ |
1259 | { |
1260 | /* See also: disable_breakpoints_in_shlibs. */ | |
1261 | val = 0; | |
0d381245 | 1262 | bpt->shlib_disabled = 1; |
879bfdc2 DJ |
1263 | if (!*disabled_breaks) |
1264 | { | |
1265 | fprintf_unfiltered (tmp_error_stream, | |
1266 | "Cannot insert breakpoint %d.\n", | |
1267 | bpt->owner->number); | |
1268 | fprintf_unfiltered (tmp_error_stream, | |
1269 | "Temporarily disabling shared library breakpoints:\n"); | |
1270 | } | |
1271 | *disabled_breaks = 1; | |
1272 | fprintf_unfiltered (tmp_error_stream, | |
1273 | "breakpoint #%d\n", bpt->owner->number); | |
1274 | } | |
1275 | else | |
879bfdc2 | 1276 | { |
879bfdc2 DJ |
1277 | if (bpt->loc_type == bp_loc_hardware_breakpoint) |
1278 | { | |
1279 | *hw_breakpoint_error = 1; | |
1280 | fprintf_unfiltered (tmp_error_stream, | |
1281 | "Cannot insert hardware breakpoint %d.\n", | |
1282 | bpt->owner->number); | |
1283 | } | |
1284 | else | |
1285 | { | |
1286 | fprintf_unfiltered (tmp_error_stream, | |
1287 | "Cannot insert breakpoint %d.\n", | |
1288 | bpt->owner->number); | |
1289 | fprintf_filtered (tmp_error_stream, | |
1290 | "Error accessing memory address "); | |
5af949e3 UW |
1291 | fputs_filtered (paddress (bpt->gdbarch, bpt->address), |
1292 | tmp_error_stream); | |
879bfdc2 DJ |
1293 | fprintf_filtered (tmp_error_stream, ": %s.\n", |
1294 | safe_strerror (val)); | |
1295 | } | |
1296 | ||
1297 | } | |
1298 | } | |
1299 | else | |
1300 | bpt->inserted = 1; | |
1301 | ||
1302 | return val; | |
1303 | } | |
1304 | ||
1305 | else if (bpt->loc_type == bp_loc_hardware_watchpoint | |
1306 | /* NOTE drow/2003-09-08: This state only exists for removing | |
1307 | watchpoints. It's not clear that it's necessary... */ | |
1308 | && bpt->owner->disposition != disp_del_at_next_stop) | |
1309 | { | |
a5606eee VP |
1310 | val = target_insert_watchpoint (bpt->address, |
1311 | bpt->length, | |
1312 | bpt->watchpoint_type); | |
1313 | bpt->inserted = (val != -1); | |
879bfdc2 DJ |
1314 | } |
1315 | ||
fe798b75 | 1316 | else if (bpt->owner->type == bp_catchpoint) |
879bfdc2 | 1317 | { |
71fff37b AC |
1318 | struct gdb_exception e = catch_exception (uiout, insert_catchpoint, |
1319 | bpt->owner, RETURN_MASK_ERROR); | |
9cbc821d AC |
1320 | exception_fprintf (gdb_stderr, e, "warning: inserting catchpoint %d: ", |
1321 | bpt->owner->number); | |
1322 | if (e.reason < 0) | |
879bfdc2 DJ |
1323 | bpt->owner->enable_state = bp_disabled; |
1324 | else | |
1325 | bpt->inserted = 1; | |
1640b821 DJ |
1326 | |
1327 | /* We've already printed an error message if there was a problem | |
1328 | inserting this catchpoint, and we've disabled the catchpoint, | |
1329 | so just return success. */ | |
1330 | return 0; | |
879bfdc2 DJ |
1331 | } |
1332 | ||
1333 | return 0; | |
1334 | } | |
1335 | ||
6c95b8df PA |
1336 | /* This function is called when program space PSPACE is about to be |
1337 | deleted. It takes care of updating breakpoints to not reference | |
1338 | PSPACE anymore. */ | |
1339 | ||
1340 | void | |
1341 | breakpoint_program_space_exit (struct program_space *pspace) | |
1342 | { | |
1343 | struct breakpoint *b, *b_temp; | |
1344 | struct bp_location *loc, *loc_temp; | |
1345 | ||
1346 | /* Remove any breakpoint that was set through this program space. */ | |
1347 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
1348 | { | |
1349 | if (b->pspace == pspace) | |
1350 | delete_breakpoint (b); | |
1351 | } | |
1352 | ||
1353 | /* Breakpoints set through other program spaces could have locations | |
1354 | bound to PSPACE as well. Remove those. */ | |
1355 | ALL_BP_LOCATIONS_SAFE (loc, loc_temp) | |
1356 | { | |
1357 | struct bp_location *tmp; | |
1358 | ||
1359 | if (loc->pspace == pspace) | |
1360 | { | |
1361 | if (loc->owner->loc == loc) | |
1362 | loc->owner->loc = loc->next; | |
1363 | else | |
1364 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
1365 | if (tmp->next == loc) | |
1366 | { | |
1367 | tmp->next = loc->next; | |
1368 | break; | |
1369 | } | |
1370 | } | |
1371 | } | |
1372 | ||
1373 | /* Now update the global location list to permanently delete the | |
1374 | removed locations above. */ | |
1375 | update_global_location_list (0); | |
1376 | } | |
1377 | ||
74960c60 VP |
1378 | /* Make sure all breakpoints are inserted in inferior. |
1379 | Throws exception on any error. | |
1380 | A breakpoint that is already inserted won't be inserted | |
1381 | again, so calling this function twice is safe. */ | |
1382 | void | |
1383 | insert_breakpoints (void) | |
1384 | { | |
1385 | struct breakpoint *bpt; | |
1386 | ||
1387 | ALL_BREAKPOINTS (bpt) | |
1388 | if (is_hardware_watchpoint (bpt)) | |
1389 | update_watchpoint (bpt, 0 /* don't reparse. */); | |
1390 | ||
b60e7edf | 1391 | update_global_location_list (1); |
74960c60 | 1392 | |
c35b1492 PA |
1393 | /* update_global_location_list does not insert breakpoints when |
1394 | always_inserted_mode is not enabled. Explicitly insert them | |
1395 | now. */ | |
1396 | if (!breakpoints_always_inserted_mode ()) | |
74960c60 VP |
1397 | insert_breakpoint_locations (); |
1398 | } | |
1399 | ||
c906108c SS |
1400 | /* insert_breakpoints is used when starting or continuing the program. |
1401 | remove_breakpoints is used when the program stops. | |
1402 | Both return zero if successful, | |
1403 | or an `errno' value if could not write the inferior. */ | |
1404 | ||
74960c60 VP |
1405 | static void |
1406 | insert_breakpoint_locations (void) | |
c906108c | 1407 | { |
a5606eee | 1408 | struct breakpoint *bpt; |
879bfdc2 | 1409 | struct bp_location *b, *temp; |
e236ba44 | 1410 | int error = 0; |
c906108c SS |
1411 | int val = 0; |
1412 | int disabled_breaks = 0; | |
81d0cc19 | 1413 | int hw_breakpoint_error = 0; |
c906108c | 1414 | |
81d0cc19 | 1415 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 1416 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 1417 | |
81d0cc19 GS |
1418 | /* Explicitly mark the warning -- this will only be printed if |
1419 | there was an error. */ | |
1420 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
1421 | |
1422 | save_current_space_and_thread (); | |
1423 | ||
879bfdc2 DJ |
1424 | ALL_BP_LOCATIONS_SAFE (b, temp) |
1425 | { | |
6c95b8df PA |
1426 | struct thread_info *tp; |
1427 | CORE_ADDR last_addr; | |
1428 | ||
74960c60 | 1429 | if (!should_be_inserted (b) || b->inserted) |
879bfdc2 DJ |
1430 | continue; |
1431 | ||
f365de73 AS |
1432 | /* There is no point inserting thread-specific breakpoints if the |
1433 | thread no longer exists. */ | |
1434 | if (b->owner->thread != -1 | |
1435 | && !valid_thread_id (b->owner->thread)) | |
1436 | continue; | |
1437 | ||
6c95b8df PA |
1438 | switch_to_program_space_and_thread (b->pspace); |
1439 | ||
1440 | /* For targets that support global breakpoints, there's no need | |
1441 | to select an inferior to insert breakpoint to. In fact, even | |
1442 | if we aren't attached to any process yet, we should still | |
1443 | insert breakpoints. */ | |
1444 | if (!gdbarch_has_global_breakpoints (target_gdbarch) | |
1445 | && ptid_equal (inferior_ptid, null_ptid)) | |
1446 | continue; | |
1447 | ||
1448 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
1449 | { | |
1450 | struct inferior *inf = current_inferior (); | |
1451 | if (inf->waiting_for_vfork_done) | |
1452 | { | |
1453 | /* This is set when we're attached to the parent of the | |
1454 | vfork, and have detached from the child. The child | |
1455 | is running free, and we expect it to do an exec or | |
1456 | exit, at which point the OS makes the parent | |
1457 | schedulable again (and the target reports that the | |
1458 | vfork is done). Until the child is done with the | |
1459 | shared memory region, do not insert breakpoints in | |
1460 | parent, otherwise the child could still trip on the | |
1461 | parent's breakpoints. Since the parent is blocked | |
1462 | anyway, it won't miss any breakpoint. */ | |
1463 | continue; | |
1464 | } | |
1465 | } | |
1466 | ||
879bfdc2 | 1467 | val = insert_bp_location (b, tmp_error_stream, |
fa3a767f | 1468 | &disabled_breaks, |
879bfdc2 DJ |
1469 | &hw_breakpoint_error); |
1470 | if (val) | |
e236ba44 | 1471 | error = val; |
879bfdc2 | 1472 | } |
c906108c | 1473 | |
a5606eee VP |
1474 | /* If we failed to insert all locations of a watchpoint, |
1475 | remove them, as half-inserted watchpoint is of limited use. */ | |
1476 | ALL_BREAKPOINTS (bpt) | |
1477 | { | |
1478 | int some_failed = 0; | |
1479 | struct bp_location *loc; | |
1480 | ||
1481 | if (!is_hardware_watchpoint (bpt)) | |
1482 | continue; | |
1483 | ||
d6b74ac4 | 1484 | if (!breakpoint_enabled (bpt)) |
a5606eee | 1485 | continue; |
74960c60 VP |
1486 | |
1487 | if (bpt->disposition == disp_del_at_next_stop) | |
1488 | continue; | |
a5606eee VP |
1489 | |
1490 | for (loc = bpt->loc; loc; loc = loc->next) | |
1491 | if (!loc->inserted) | |
1492 | { | |
1493 | some_failed = 1; | |
1494 | break; | |
1495 | } | |
1496 | if (some_failed) | |
1497 | { | |
1498 | for (loc = bpt->loc; loc; loc = loc->next) | |
1499 | if (loc->inserted) | |
1500 | remove_breakpoint (loc, mark_uninserted); | |
1501 | ||
1502 | hw_breakpoint_error = 1; | |
1503 | fprintf_unfiltered (tmp_error_stream, | |
1504 | "Could not insert hardware watchpoint %d.\n", | |
1505 | bpt->number); | |
1506 | error = -1; | |
1507 | } | |
1508 | } | |
1509 | ||
e236ba44 | 1510 | if (error) |
81d0cc19 GS |
1511 | { |
1512 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
1513 | message about possibly exhausted resources. */ | |
879bfdc2 | 1514 | if (hw_breakpoint_error) |
81d0cc19 | 1515 | { |
c6510018 MS |
1516 | fprintf_unfiltered (tmp_error_stream, |
1517 | "Could not insert hardware breakpoints:\n\ | |
1518 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 1519 | } |
81d0cc19 GS |
1520 | target_terminal_ours_for_output (); |
1521 | error_stream (tmp_error_stream); | |
1522 | } | |
f7545552 TT |
1523 | |
1524 | do_cleanups (cleanups); | |
c906108c SS |
1525 | } |
1526 | ||
c906108c | 1527 | int |
fba45db2 | 1528 | remove_breakpoints (void) |
c906108c | 1529 | { |
0bde7532 | 1530 | struct bp_location *b; |
3a1bae8e | 1531 | int val = 0; |
c906108c | 1532 | |
0bde7532 | 1533 | ALL_BP_LOCATIONS (b) |
c5aa993b | 1534 | { |
0bde7532 | 1535 | if (b->inserted) |
3a1bae8e | 1536 | val |= remove_breakpoint (b, mark_uninserted); |
c5aa993b | 1537 | } |
3a1bae8e | 1538 | return val; |
c906108c SS |
1539 | } |
1540 | ||
6c95b8df PA |
1541 | /* Remove breakpoints of process PID. */ |
1542 | ||
1543 | int | |
1544 | remove_breakpoints_pid (int pid) | |
1545 | { | |
1546 | struct bp_location *b; | |
1547 | int val; | |
1548 | struct inferior *inf = find_inferior_pid (pid); | |
1549 | ||
1550 | ALL_BP_LOCATIONS (b) | |
1551 | { | |
1552 | if (b->pspace != inf->pspace) | |
1553 | continue; | |
1554 | ||
1555 | if (b->inserted) | |
1556 | { | |
1557 | val = remove_breakpoint (b, mark_uninserted); | |
1558 | if (val != 0) | |
1559 | return val; | |
1560 | } | |
1561 | } | |
1562 | return 0; | |
1563 | } | |
1564 | ||
692590c1 | 1565 | int |
80ce1ecb | 1566 | remove_hw_watchpoints (void) |
692590c1 | 1567 | { |
0bde7532 | 1568 | struct bp_location *b; |
3a1bae8e | 1569 | int val = 0; |
692590c1 | 1570 | |
0bde7532 | 1571 | ALL_BP_LOCATIONS (b) |
692590c1 | 1572 | { |
0bde7532 | 1573 | if (b->inserted && b->loc_type == bp_loc_hardware_watchpoint) |
3a1bae8e | 1574 | val |= remove_breakpoint (b, mark_uninserted); |
692590c1 | 1575 | } |
3a1bae8e | 1576 | return val; |
692590c1 MS |
1577 | } |
1578 | ||
c906108c | 1579 | int |
fba45db2 | 1580 | reattach_breakpoints (int pid) |
c906108c | 1581 | { |
6c95b8df | 1582 | struct cleanup *old_chain; |
0bde7532 | 1583 | struct bp_location *b; |
c906108c | 1584 | int val; |
a4954f26 | 1585 | struct ui_file *tmp_error_stream = mem_fileopen (); |
fa3a767f | 1586 | int dummy1 = 0, dummy2 = 0; |
6c95b8df PA |
1587 | struct inferior *inf; |
1588 | struct thread_info *tp; | |
1589 | ||
1590 | tp = any_live_thread_of_process (pid); | |
1591 | if (tp == NULL) | |
1592 | return 1; | |
1593 | ||
1594 | inf = find_inferior_pid (pid); | |
1595 | old_chain = save_inferior_ptid (); | |
1596 | ||
1597 | inferior_ptid = tp->ptid; | |
a4954f26 DJ |
1598 | |
1599 | make_cleanup_ui_file_delete (tmp_error_stream); | |
c906108c | 1600 | |
0bde7532 | 1601 | ALL_BP_LOCATIONS (b) |
c5aa993b | 1602 | { |
6c95b8df PA |
1603 | if (b->pspace != inf->pspace) |
1604 | continue; | |
1605 | ||
0bde7532 | 1606 | if (b->inserted) |
c5aa993b | 1607 | { |
a4954f26 DJ |
1608 | b->inserted = 0; |
1609 | val = insert_bp_location (b, tmp_error_stream, | |
fa3a767f | 1610 | &dummy1, &dummy2); |
c5aa993b JM |
1611 | if (val != 0) |
1612 | { | |
ce696e05 | 1613 | do_cleanups (old_chain); |
c5aa993b JM |
1614 | return val; |
1615 | } | |
1616 | } | |
1617 | } | |
ce696e05 | 1618 | do_cleanups (old_chain); |
c906108c SS |
1619 | return 0; |
1620 | } | |
1621 | ||
e58b0e63 PA |
1622 | static int internal_breakpoint_number = -1; |
1623 | ||
e62c965a | 1624 | static struct breakpoint * |
a6d9a66e UW |
1625 | create_internal_breakpoint (struct gdbarch *gdbarch, |
1626 | CORE_ADDR address, enum bptype type) | |
e62c965a | 1627 | { |
e62c965a PP |
1628 | struct symtab_and_line sal; |
1629 | struct breakpoint *b; | |
1630 | ||
1631 | init_sal (&sal); /* initialize to zeroes */ | |
1632 | ||
1633 | sal.pc = address; | |
1634 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 1635 | sal.pspace = current_program_space; |
e62c965a | 1636 | |
a6d9a66e | 1637 | b = set_raw_breakpoint (gdbarch, sal, type); |
e62c965a PP |
1638 | b->number = internal_breakpoint_number--; |
1639 | b->disposition = disp_donttouch; | |
1640 | ||
1641 | return b; | |
1642 | } | |
1643 | ||
1644 | static void | |
69de3c6a | 1645 | create_overlay_event_breakpoint (char *func_name) |
e62c965a | 1646 | { |
69de3c6a | 1647 | struct objfile *objfile; |
e62c965a | 1648 | |
69de3c6a PP |
1649 | ALL_OBJFILES (objfile) |
1650 | { | |
1651 | struct breakpoint *b; | |
1652 | struct minimal_symbol *m; | |
1653 | ||
1654 | m = lookup_minimal_symbol_text (func_name, objfile); | |
1655 | if (m == NULL) | |
1656 | continue; | |
e62c965a | 1657 | |
a6d9a66e UW |
1658 | b = create_internal_breakpoint (get_objfile_arch (objfile), |
1659 | SYMBOL_VALUE_ADDRESS (m), | |
69de3c6a PP |
1660 | bp_overlay_event); |
1661 | b->addr_string = xstrdup (func_name); | |
e62c965a | 1662 | |
69de3c6a PP |
1663 | if (overlay_debugging == ovly_auto) |
1664 | { | |
1665 | b->enable_state = bp_enabled; | |
1666 | overlay_events_enabled = 1; | |
1667 | } | |
1668 | else | |
1669 | { | |
1670 | b->enable_state = bp_disabled; | |
1671 | overlay_events_enabled = 0; | |
1672 | } | |
e62c965a PP |
1673 | } |
1674 | update_global_location_list (1); | |
1675 | } | |
1676 | ||
0fd8e87f UW |
1677 | static void |
1678 | create_longjmp_master_breakpoint (char *func_name) | |
1679 | { | |
6c95b8df | 1680 | struct program_space *pspace; |
0fd8e87f | 1681 | struct objfile *objfile; |
6c95b8df PA |
1682 | struct cleanup *old_chain; |
1683 | ||
1684 | old_chain = save_current_program_space (); | |
0fd8e87f | 1685 | |
6c95b8df | 1686 | ALL_PSPACES (pspace) |
0fd8e87f UW |
1687 | ALL_OBJFILES (objfile) |
1688 | { | |
1689 | struct breakpoint *b; | |
1690 | struct minimal_symbol *m; | |
1691 | ||
1692 | if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile))) | |
1693 | continue; | |
1694 | ||
6c95b8df PA |
1695 | set_current_program_space (pspace); |
1696 | ||
0fd8e87f UW |
1697 | m = lookup_minimal_symbol_text (func_name, objfile); |
1698 | if (m == NULL) | |
1699 | continue; | |
1700 | ||
a6d9a66e UW |
1701 | b = create_internal_breakpoint (get_objfile_arch (objfile), |
1702 | SYMBOL_VALUE_ADDRESS (m), | |
0fd8e87f UW |
1703 | bp_longjmp_master); |
1704 | b->addr_string = xstrdup (func_name); | |
1705 | b->enable_state = bp_disabled; | |
1706 | } | |
1707 | update_global_location_list (1); | |
6c95b8df PA |
1708 | |
1709 | do_cleanups (old_chain); | |
0fd8e87f UW |
1710 | } |
1711 | ||
c906108c | 1712 | void |
fba45db2 | 1713 | update_breakpoints_after_exec (void) |
c906108c | 1714 | { |
c5aa993b JM |
1715 | struct breakpoint *b; |
1716 | struct breakpoint *temp; | |
25b22b0a | 1717 | struct bp_location *bploc; |
c906108c | 1718 | |
25b22b0a PA |
1719 | /* We're about to delete breakpoints from GDB's lists. If the |
1720 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
1721 | writing the breakpoints' "shadow contents" back into memory. The | |
1722 | "shadow contents" are NOT valid after an exec, so GDB should not | |
1723 | do that. Instead, the target is responsible from marking | |
1724 | breakpoints out as soon as it detects an exec. We don't do that | |
1725 | here instead, because there may be other attempts to delete | |
1726 | breakpoints after detecting an exec and before reaching here. */ | |
1727 | ALL_BP_LOCATIONS (bploc) | |
6c95b8df PA |
1728 | if (bploc->pspace == current_program_space) |
1729 | gdb_assert (!bploc->inserted); | |
c906108c SS |
1730 | |
1731 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b | 1732 | { |
6c95b8df PA |
1733 | if (b->pspace != current_program_space) |
1734 | continue; | |
1735 | ||
c5aa993b JM |
1736 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
1737 | if (b->type == bp_shlib_event) | |
1738 | { | |
1739 | delete_breakpoint (b); | |
1740 | continue; | |
1741 | } | |
c906108c | 1742 | |
4efc6507 DE |
1743 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
1744 | if (b->type == bp_jit_event) | |
1745 | { | |
1746 | delete_breakpoint (b); | |
1747 | continue; | |
1748 | } | |
1749 | ||
1900040c | 1750 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
1751 | as must overlay event and longjmp master breakpoints. */ |
1752 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
1753 | || b->type == bp_longjmp_master) | |
c4093a6a JM |
1754 | { |
1755 | delete_breakpoint (b); | |
1756 | continue; | |
1757 | } | |
1758 | ||
c5aa993b JM |
1759 | /* Step-resume breakpoints are meaningless after an exec(). */ |
1760 | if (b->type == bp_step_resume) | |
1761 | { | |
1762 | delete_breakpoint (b); | |
1763 | continue; | |
1764 | } | |
1765 | ||
611c83ae PA |
1766 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
1767 | after an exec. */ | |
1768 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume) | |
1769 | { | |
1770 | delete_breakpoint (b); | |
1771 | continue; | |
1772 | } | |
1773 | ||
ce78b96d JB |
1774 | if (b->type == bp_catchpoint) |
1775 | { | |
1776 | /* For now, none of the bp_catchpoint breakpoints need to | |
1777 | do anything at this point. In the future, if some of | |
1778 | the catchpoints need to something, we will need to add | |
1779 | a new method, and call this method from here. */ | |
1780 | continue; | |
1781 | } | |
1782 | ||
c5aa993b JM |
1783 | /* bp_finish is a special case. The only way we ought to be able |
1784 | to see one of these when an exec() has happened, is if the user | |
1785 | caught a vfork, and then said "finish". Ordinarily a finish just | |
1786 | carries them to the call-site of the current callee, by setting | |
1787 | a temporary bp there and resuming. But in this case, the finish | |
1788 | will carry them entirely through the vfork & exec. | |
1789 | ||
1790 | We don't want to allow a bp_finish to remain inserted now. But | |
1791 | we can't safely delete it, 'cause finish_command has a handle to | |
1792 | the bp on a bpstat, and will later want to delete it. There's a | |
1793 | chance (and I've seen it happen) that if we delete the bp_finish | |
1794 | here, that its storage will get reused by the time finish_command | |
1795 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
1796 | We really must allow finish_command to delete a bp_finish. | |
1797 | ||
53a5351d JM |
1798 | In the absense of a general solution for the "how do we know |
1799 | it's safe to delete something others may have handles to?" | |
1800 | problem, what we'll do here is just uninsert the bp_finish, and | |
1801 | let finish_command delete it. | |
1802 | ||
1803 | (We know the bp_finish is "doomed" in the sense that it's | |
1804 | momentary, and will be deleted as soon as finish_command sees | |
1805 | the inferior stopped. So it doesn't matter that the bp's | |
1806 | address is probably bogus in the new a.out, unlike e.g., the | |
1807 | solib breakpoints.) */ | |
c5aa993b | 1808 | |
c5aa993b JM |
1809 | if (b->type == bp_finish) |
1810 | { | |
1811 | continue; | |
1812 | } | |
1813 | ||
1814 | /* Without a symbolic address, we have little hope of the | |
1815 | pre-exec() address meaning the same thing in the post-exec() | |
1816 | a.out. */ | |
1817 | if (b->addr_string == NULL) | |
1818 | { | |
1819 | delete_breakpoint (b); | |
1820 | continue; | |
1821 | } | |
c5aa993b | 1822 | } |
1900040c | 1823 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
69de3c6a | 1824 | create_overlay_event_breakpoint ("_ovly_debug_event"); |
0fd8e87f UW |
1825 | create_longjmp_master_breakpoint ("longjmp"); |
1826 | create_longjmp_master_breakpoint ("_longjmp"); | |
1827 | create_longjmp_master_breakpoint ("siglongjmp"); | |
1828 | create_longjmp_master_breakpoint ("_siglongjmp"); | |
c906108c SS |
1829 | } |
1830 | ||
1831 | int | |
fba45db2 | 1832 | detach_breakpoints (int pid) |
c906108c | 1833 | { |
0bde7532 | 1834 | struct bp_location *b; |
3a1bae8e | 1835 | int val = 0; |
ce696e05 | 1836 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 1837 | struct inferior *inf = current_inferior (); |
c5aa993b | 1838 | |
39f77062 | 1839 | if (pid == PIDGET (inferior_ptid)) |
8a3fe4f8 | 1840 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 1841 | |
6c95b8df | 1842 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
ce696e05 | 1843 | inferior_ptid = pid_to_ptid (pid); |
0bde7532 | 1844 | ALL_BP_LOCATIONS (b) |
c5aa993b | 1845 | { |
6c95b8df PA |
1846 | if (b->pspace != inf->pspace) |
1847 | continue; | |
1848 | ||
0bde7532 | 1849 | if (b->inserted) |
6c95b8df | 1850 | val |= remove_breakpoint_1 (b, mark_inserted); |
c5aa993b | 1851 | } |
ce696e05 | 1852 | do_cleanups (old_chain); |
3a1bae8e | 1853 | return val; |
c906108c SS |
1854 | } |
1855 | ||
6c95b8df PA |
1856 | /* Remove the breakpoint location B from the current address space. |
1857 | Note that this is used to detach breakpoints from a child fork. | |
1858 | When we get here, the child isn't in the inferior list, and neither | |
1859 | do we have objects to represent its address space --- we should | |
1860 | *not* look at b->pspace->aspace here. */ | |
1861 | ||
c906108c | 1862 | static int |
6c95b8df | 1863 | remove_breakpoint_1 (struct bp_location *b, insertion_state_t is) |
c906108c SS |
1864 | { |
1865 | int val; | |
6c95b8df | 1866 | struct cleanup *old_chain; |
c5aa993b | 1867 | |
0bde7532 | 1868 | if (b->owner->enable_state == bp_permanent) |
c2c6d25f JM |
1869 | /* Permanent breakpoints cannot be inserted or removed. */ |
1870 | return 0; | |
1871 | ||
74960c60 VP |
1872 | /* The type of none suggests that owner is actually deleted. |
1873 | This should not ever happen. */ | |
1874 | gdb_assert (b->owner->type != bp_none); | |
0bde7532 DJ |
1875 | |
1876 | if (b->loc_type == bp_loc_software_breakpoint | |
1877 | || b->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 1878 | { |
c02f5703 MS |
1879 | /* "Normal" instruction breakpoint: either the standard |
1880 | trap-instruction bp (bp_breakpoint), or a | |
1881 | bp_hardware_breakpoint. */ | |
1882 | ||
1883 | /* First check to see if we have to handle an overlay. */ | |
1884 | if (overlay_debugging == ovly_off | |
0bde7532 DJ |
1885 | || b->section == NULL |
1886 | || !(section_is_overlay (b->section))) | |
c02f5703 MS |
1887 | { |
1888 | /* No overlay handling: just remove the breakpoint. */ | |
1889 | ||
0bde7532 | 1890 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e | 1891 | val = target_remove_hw_breakpoint (b->gdbarch, &b->target_info); |
c02f5703 | 1892 | else |
a6d9a66e | 1893 | val = target_remove_breakpoint (b->gdbarch, &b->target_info); |
c02f5703 | 1894 | } |
c906108c SS |
1895 | else |
1896 | { | |
c02f5703 MS |
1897 | /* This breakpoint is in an overlay section. |
1898 | Did we set a breakpoint at the LMA? */ | |
1899 | if (!overlay_events_enabled) | |
1900 | { | |
1901 | /* Yes -- overlay event support is not active, so we | |
1902 | should have set a breakpoint at the LMA. Remove it. | |
1903 | */ | |
c02f5703 MS |
1904 | /* Ignore any failures: if the LMA is in ROM, we will |
1905 | have already warned when we failed to insert it. */ | |
0bde7532 | 1906 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e UW |
1907 | target_remove_hw_breakpoint (b->gdbarch, |
1908 | &b->overlay_target_info); | |
c02f5703 | 1909 | else |
a6d9a66e UW |
1910 | target_remove_breakpoint (b->gdbarch, |
1911 | &b->overlay_target_info); | |
c02f5703 MS |
1912 | } |
1913 | /* Did we set a breakpoint at the VMA? | |
1914 | If so, we will have marked the breakpoint 'inserted'. */ | |
0bde7532 | 1915 | if (b->inserted) |
c906108c | 1916 | { |
c02f5703 MS |
1917 | /* Yes -- remove it. Previously we did not bother to |
1918 | remove the breakpoint if the section had been | |
1919 | unmapped, but let's not rely on that being safe. We | |
1920 | don't know what the overlay manager might do. */ | |
0bde7532 | 1921 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e UW |
1922 | val = target_remove_hw_breakpoint (b->gdbarch, |
1923 | &b->target_info); | |
aa67235e UW |
1924 | |
1925 | /* However, we should remove *software* breakpoints only | |
1926 | if the section is still mapped, or else we overwrite | |
1927 | wrong code with the saved shadow contents. */ | |
1928 | else if (section_is_mapped (b->section)) | |
a6d9a66e UW |
1929 | val = target_remove_breakpoint (b->gdbarch, |
1930 | &b->target_info); | |
aa67235e UW |
1931 | else |
1932 | val = 0; | |
c906108c | 1933 | } |
c02f5703 MS |
1934 | else |
1935 | { | |
1936 | /* No -- not inserted, so no need to remove. No error. */ | |
1937 | val = 0; | |
1938 | } | |
c906108c | 1939 | } |
879d1e6b UW |
1940 | |
1941 | /* In some cases, we might not be able to remove a breakpoint | |
1942 | in a shared library that has already been removed, but we | |
1943 | have not yet processed the shlib unload event. */ | |
6c95b8df | 1944 | if (val && solib_name_from_address (b->pspace, b->address)) |
879d1e6b UW |
1945 | val = 0; |
1946 | ||
c906108c SS |
1947 | if (val) |
1948 | return val; | |
0bde7532 | 1949 | b->inserted = (is == mark_inserted); |
c906108c | 1950 | } |
a5606eee | 1951 | else if (b->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 1952 | { |
278cd55f AC |
1953 | struct value *v; |
1954 | struct value *n; | |
c5aa993b | 1955 | |
0bde7532 | 1956 | b->inserted = (is == mark_inserted); |
a5606eee VP |
1957 | val = target_remove_watchpoint (b->address, b->length, |
1958 | b->watchpoint_type); | |
2e70b7b9 | 1959 | |
c906108c | 1960 | /* Failure to remove any of the hardware watchpoints comes here. */ |
0bde7532 | 1961 | if ((is == mark_uninserted) && (b->inserted)) |
8a3fe4f8 | 1962 | warning (_("Could not remove hardware watchpoint %d."), |
0bde7532 | 1963 | b->owner->number); |
c906108c | 1964 | } |
ce78b96d JB |
1965 | else if (b->owner->type == bp_catchpoint |
1966 | && breakpoint_enabled (b->owner) | |
1967 | && !b->duplicate) | |
1968 | { | |
1969 | gdb_assert (b->owner->ops != NULL && b->owner->ops->remove != NULL); | |
1970 | ||
1971 | val = b->owner->ops->remove (b->owner); | |
1972 | if (val) | |
1973 | return val; | |
1974 | b->inserted = (is == mark_inserted); | |
1975 | } | |
c906108c SS |
1976 | |
1977 | return 0; | |
1978 | } | |
1979 | ||
6c95b8df PA |
1980 | static int |
1981 | remove_breakpoint (struct bp_location *b, insertion_state_t is) | |
1982 | { | |
1983 | int ret; | |
1984 | struct cleanup *old_chain; | |
1985 | ||
1986 | if (b->owner->enable_state == bp_permanent) | |
1987 | /* Permanent breakpoints cannot be inserted or removed. */ | |
1988 | return 0; | |
1989 | ||
1990 | /* The type of none suggests that owner is actually deleted. | |
1991 | This should not ever happen. */ | |
1992 | gdb_assert (b->owner->type != bp_none); | |
1993 | ||
1994 | old_chain = save_current_space_and_thread (); | |
1995 | ||
1996 | switch_to_program_space_and_thread (b->pspace); | |
1997 | ||
1998 | ret = remove_breakpoint_1 (b, is); | |
1999 | ||
2000 | do_cleanups (old_chain); | |
2001 | return ret; | |
2002 | } | |
2003 | ||
c906108c SS |
2004 | /* Clear the "inserted" flag in all breakpoints. */ |
2005 | ||
25b22b0a | 2006 | void |
fba45db2 | 2007 | mark_breakpoints_out (void) |
c906108c | 2008 | { |
075f6582 | 2009 | struct bp_location *bpt; |
c906108c | 2010 | |
075f6582 | 2011 | ALL_BP_LOCATIONS (bpt) |
6c95b8df PA |
2012 | if (bpt->pspace == current_program_space) |
2013 | bpt->inserted = 0; | |
c906108c SS |
2014 | } |
2015 | ||
53a5351d JM |
2016 | /* Clear the "inserted" flag in all breakpoints and delete any |
2017 | breakpoints which should go away between runs of the program. | |
c906108c SS |
2018 | |
2019 | Plus other such housekeeping that has to be done for breakpoints | |
2020 | between runs. | |
2021 | ||
53a5351d JM |
2022 | Note: this function gets called at the end of a run (by |
2023 | generic_mourn_inferior) and when a run begins (by | |
2024 | init_wait_for_inferior). */ | |
c906108c SS |
2025 | |
2026 | ||
2027 | ||
2028 | void | |
fba45db2 | 2029 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 2030 | { |
52f0bd74 | 2031 | struct breakpoint *b, *temp; |
075f6582 | 2032 | struct bp_location *bpt; |
1c5cfe86 | 2033 | int ix; |
6c95b8df | 2034 | struct program_space *pspace = current_program_space; |
c906108c | 2035 | |
50c71eaf PA |
2036 | /* If breakpoint locations are shared across processes, then there's |
2037 | nothing to do. */ | |
2567c7d9 | 2038 | if (gdbarch_has_global_breakpoints (target_gdbarch)) |
50c71eaf PA |
2039 | return; |
2040 | ||
075f6582 | 2041 | ALL_BP_LOCATIONS (bpt) |
6c95b8df PA |
2042 | { |
2043 | if (bpt->pspace == pspace | |
2044 | && bpt->owner->enable_state != bp_permanent) | |
514f746b | 2045 | bpt->inserted = 0; |
6c95b8df | 2046 | } |
075f6582 | 2047 | |
c906108c | 2048 | ALL_BREAKPOINTS_SAFE (b, temp) |
c5aa993b | 2049 | { |
6c95b8df PA |
2050 | if (b->loc && b->loc->pspace != pspace) |
2051 | continue; | |
2052 | ||
c5aa993b JM |
2053 | switch (b->type) |
2054 | { | |
2055 | case bp_call_dummy: | |
2056 | case bp_watchpoint_scope: | |
c906108c | 2057 | |
c5aa993b JM |
2058 | /* If the call dummy breakpoint is at the entry point it will |
2059 | cause problems when the inferior is rerun, so we better | |
2060 | get rid of it. | |
c906108c | 2061 | |
c5aa993b JM |
2062 | Also get rid of scope breakpoints. */ |
2063 | delete_breakpoint (b); | |
2064 | break; | |
c906108c | 2065 | |
c5aa993b JM |
2066 | case bp_watchpoint: |
2067 | case bp_hardware_watchpoint: | |
2068 | case bp_read_watchpoint: | |
2069 | case bp_access_watchpoint: | |
c906108c | 2070 | |
c5aa993b JM |
2071 | /* Likewise for watchpoints on local expressions. */ |
2072 | if (b->exp_valid_block != NULL) | |
2073 | delete_breakpoint (b); | |
967af18d | 2074 | else if (context == inf_starting) |
c860120c PM |
2075 | { |
2076 | /* Reset val field to force reread of starting value | |
2077 | in insert_breakpoints. */ | |
2078 | if (b->val) | |
2079 | value_free (b->val); | |
2080 | b->val = NULL; | |
fa4727a6 | 2081 | b->val_valid = 0; |
c860120c | 2082 | } |
c5aa993b JM |
2083 | break; |
2084 | default: | |
c5aa993b JM |
2085 | break; |
2086 | } | |
2087 | } | |
1c5cfe86 PA |
2088 | |
2089 | /* Get rid of the moribund locations. */ | |
2090 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bpt); ++ix) | |
2091 | free_bp_location (bpt); | |
2092 | VEC_free (bp_location_p, moribund_locations); | |
c906108c SS |
2093 | } |
2094 | ||
6c95b8df PA |
2095 | /* These functions concern about actual breakpoints inserted in the |
2096 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
2097 | we need to hop over the bkpt --- so we check for address space | |
2098 | match, not program space. */ | |
2099 | ||
c2c6d25f JM |
2100 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
2101 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
2102 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
2103 | permanent breakpoint. | |
2104 | - When continuing from a location with an ordinary breakpoint, we | |
2105 | actually single step once before calling insert_breakpoints. | |
2106 | - When continuing from a localion with a permanent breakpoint, we | |
2107 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by | |
2108 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 2109 | |
c2c6d25f | 2110 | enum breakpoint_here |
6c95b8df | 2111 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 2112 | { |
89f9893c | 2113 | const struct bp_location *bpt; |
c2c6d25f | 2114 | int any_breakpoint_here = 0; |
c906108c | 2115 | |
075f6582 DJ |
2116 | ALL_BP_LOCATIONS (bpt) |
2117 | { | |
2118 | if (bpt->loc_type != bp_loc_software_breakpoint | |
2119 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
2120 | continue; | |
2121 | ||
468d015d | 2122 | if ((breakpoint_enabled (bpt->owner) |
075f6582 | 2123 | || bpt->owner->enable_state == bp_permanent) |
6c95b8df PA |
2124 | && breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2125 | aspace, pc)) | |
075f6582 DJ |
2126 | { |
2127 | if (overlay_debugging | |
2128 | && section_is_overlay (bpt->section) | |
2129 | && !section_is_mapped (bpt->section)) | |
2130 | continue; /* unmapped overlay -- can't be a match */ | |
2131 | else if (bpt->owner->enable_state == bp_permanent) | |
2132 | return permanent_breakpoint_here; | |
2133 | else | |
2134 | any_breakpoint_here = 1; | |
2135 | } | |
2136 | } | |
c906108c | 2137 | |
c2c6d25f | 2138 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
2139 | } |
2140 | ||
1c5cfe86 PA |
2141 | /* Return true if there's a moribund breakpoint at PC. */ |
2142 | ||
2143 | int | |
6c95b8df | 2144 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
2145 | { |
2146 | struct bp_location *loc; | |
2147 | int ix; | |
2148 | ||
2149 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
6c95b8df PA |
2150 | if (breakpoint_address_match (loc->pspace->aspace, loc->address, |
2151 | aspace, pc)) | |
1c5cfe86 PA |
2152 | return 1; |
2153 | ||
2154 | return 0; | |
2155 | } | |
c2c6d25f | 2156 | |
c36b740a VP |
2157 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
2158 | inserted using regular breakpoint_chain/bp_location_chain mechanism. | |
2159 | This does not check for single-step breakpoints, which are | |
2160 | inserted and removed using direct target manipulation. */ | |
c906108c SS |
2161 | |
2162 | int | |
6c95b8df | 2163 | regular_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 2164 | { |
89f9893c | 2165 | const struct bp_location *bpt; |
c906108c | 2166 | |
075f6582 | 2167 | ALL_BP_LOCATIONS (bpt) |
c5aa993b | 2168 | { |
075f6582 DJ |
2169 | if (bpt->loc_type != bp_loc_software_breakpoint |
2170 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
2171 | continue; | |
2172 | ||
2173 | if (bpt->inserted | |
6c95b8df PA |
2174 | && breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2175 | aspace, pc)) | |
075f6582 DJ |
2176 | { |
2177 | if (overlay_debugging | |
2178 | && section_is_overlay (bpt->section) | |
2179 | && !section_is_mapped (bpt->section)) | |
2180 | continue; /* unmapped overlay -- can't be a match */ | |
2181 | else | |
2182 | return 1; | |
2183 | } | |
c5aa993b | 2184 | } |
c36b740a VP |
2185 | return 0; |
2186 | } | |
2187 | ||
2188 | /* Returns non-zero iff there's either regular breakpoint | |
2189 | or a single step breakpoint inserted at PC. */ | |
2190 | ||
2191 | int | |
6c95b8df | 2192 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c36b740a | 2193 | { |
6c95b8df | 2194 | if (regular_breakpoint_inserted_here_p (aspace, pc)) |
c36b740a | 2195 | return 1; |
c906108c | 2196 | |
6c95b8df | 2197 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2198 | return 1; |
2199 | ||
c906108c SS |
2200 | return 0; |
2201 | } | |
2202 | ||
4fa8626c DJ |
2203 | /* This function returns non-zero iff there is a software breakpoint |
2204 | inserted at PC. */ | |
2205 | ||
2206 | int | |
6c95b8df | 2207 | software_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
4fa8626c | 2208 | { |
89f9893c | 2209 | const struct bp_location *bpt; |
4fa8626c DJ |
2210 | int any_breakpoint_here = 0; |
2211 | ||
2212 | ALL_BP_LOCATIONS (bpt) | |
2213 | { | |
2214 | if (bpt->loc_type != bp_loc_software_breakpoint) | |
2215 | continue; | |
2216 | ||
0d381245 | 2217 | if (bpt->inserted |
6c95b8df PA |
2218 | && breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2219 | aspace, pc)) | |
4fa8626c DJ |
2220 | { |
2221 | if (overlay_debugging | |
2222 | && section_is_overlay (bpt->section) | |
2223 | && !section_is_mapped (bpt->section)) | |
2224 | continue; /* unmapped overlay -- can't be a match */ | |
2225 | else | |
2226 | return 1; | |
2227 | } | |
2228 | } | |
2229 | ||
1aafd4da | 2230 | /* Also check for software single-step breakpoints. */ |
6c95b8df | 2231 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2232 | return 1; |
2233 | ||
4fa8626c DJ |
2234 | return 0; |
2235 | } | |
2236 | ||
075f6582 DJ |
2237 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
2238 | PC is valid for process/thread PTID. */ | |
c906108c SS |
2239 | |
2240 | int | |
6c95b8df PA |
2241 | breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc, |
2242 | ptid_t ptid) | |
c906108c | 2243 | { |
89f9893c | 2244 | const struct bp_location *bpt; |
4a306c9a | 2245 | /* The thread and task IDs associated to PTID, computed lazily. */ |
a6f1cd96 | 2246 | int thread = -1; |
4a306c9a | 2247 | int task = 0; |
a6f1cd96 | 2248 | |
075f6582 | 2249 | ALL_BP_LOCATIONS (bpt) |
c5aa993b | 2250 | { |
075f6582 DJ |
2251 | if (bpt->loc_type != bp_loc_software_breakpoint |
2252 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
2253 | continue; | |
2254 | ||
a6f1cd96 JB |
2255 | if (!breakpoint_enabled (bpt->owner) |
2256 | && bpt->owner->enable_state != bp_permanent) | |
2257 | continue; | |
2258 | ||
6c95b8df PA |
2259 | if (!breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2260 | aspace, pc)) | |
a6f1cd96 JB |
2261 | continue; |
2262 | ||
2263 | if (bpt->owner->thread != -1) | |
075f6582 | 2264 | { |
a6f1cd96 JB |
2265 | /* This is a thread-specific breakpoint. Check that ptid |
2266 | matches that thread. If thread hasn't been computed yet, | |
2267 | it is now time to do so. */ | |
2268 | if (thread == -1) | |
2269 | thread = pid_to_thread_id (ptid); | |
2270 | if (bpt->owner->thread != thread) | |
2271 | continue; | |
075f6582 | 2272 | } |
a6f1cd96 | 2273 | |
4a306c9a JB |
2274 | if (bpt->owner->task != 0) |
2275 | { | |
2276 | /* This is a task-specific breakpoint. Check that ptid | |
2277 | matches that task. If task hasn't been computed yet, | |
2278 | it is now time to do so. */ | |
2279 | if (task == 0) | |
2280 | task = ada_get_task_number (ptid); | |
2281 | if (bpt->owner->task != task) | |
2282 | continue; | |
2283 | } | |
2284 | ||
a6f1cd96 JB |
2285 | if (overlay_debugging |
2286 | && section_is_overlay (bpt->section) | |
2287 | && !section_is_mapped (bpt->section)) | |
2288 | continue; /* unmapped overlay -- can't be a match */ | |
2289 | ||
2290 | return 1; | |
c5aa993b | 2291 | } |
c906108c SS |
2292 | |
2293 | return 0; | |
2294 | } | |
c906108c | 2295 | \f |
c5aa993b | 2296 | |
c906108c SS |
2297 | /* bpstat stuff. External routines' interfaces are documented |
2298 | in breakpoint.h. */ | |
2299 | ||
2300 | int | |
fba45db2 | 2301 | ep_is_catchpoint (struct breakpoint *ep) |
c906108c | 2302 | { |
533be4dd | 2303 | return (ep->type == bp_catchpoint); |
c906108c SS |
2304 | } |
2305 | ||
198757a8 VP |
2306 | void |
2307 | bpstat_free (bpstat bs) | |
2308 | { | |
2309 | if (bs->old_val != NULL) | |
2310 | value_free (bs->old_val); | |
2311 | free_command_lines (&bs->commands); | |
2312 | xfree (bs); | |
2313 | } | |
2314 | ||
c906108c SS |
2315 | /* Clear a bpstat so that it says we are not at any breakpoint. |
2316 | Also free any storage that is part of a bpstat. */ | |
2317 | ||
2318 | void | |
fba45db2 | 2319 | bpstat_clear (bpstat *bsp) |
c906108c SS |
2320 | { |
2321 | bpstat p; | |
2322 | bpstat q; | |
2323 | ||
2324 | if (bsp == 0) | |
2325 | return; | |
2326 | p = *bsp; | |
2327 | while (p != NULL) | |
2328 | { | |
2329 | q = p->next; | |
198757a8 | 2330 | bpstat_free (p); |
c906108c SS |
2331 | p = q; |
2332 | } | |
2333 | *bsp = NULL; | |
2334 | } | |
2335 | ||
2336 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
2337 | is part of the bpstat is copied as well. */ | |
2338 | ||
2339 | bpstat | |
fba45db2 | 2340 | bpstat_copy (bpstat bs) |
c906108c SS |
2341 | { |
2342 | bpstat p = NULL; | |
2343 | bpstat tmp; | |
2344 | bpstat retval = NULL; | |
2345 | ||
2346 | if (bs == NULL) | |
2347 | return bs; | |
2348 | ||
2349 | for (; bs != NULL; bs = bs->next) | |
2350 | { | |
2351 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
2352 | memcpy (tmp, bs, sizeof (*tmp)); | |
31cc81e9 DJ |
2353 | if (bs->commands != NULL) |
2354 | tmp->commands = copy_command_lines (bs->commands); | |
2355 | if (bs->old_val != NULL) | |
3c3185ac JK |
2356 | { |
2357 | tmp->old_val = value_copy (bs->old_val); | |
2358 | release_value (tmp->old_val); | |
2359 | } | |
31cc81e9 | 2360 | |
c906108c SS |
2361 | if (p == NULL) |
2362 | /* This is the first thing in the chain. */ | |
2363 | retval = tmp; | |
2364 | else | |
2365 | p->next = tmp; | |
2366 | p = tmp; | |
2367 | } | |
2368 | p->next = NULL; | |
2369 | return retval; | |
2370 | } | |
2371 | ||
2372 | /* Find the bpstat associated with this breakpoint */ | |
2373 | ||
2374 | bpstat | |
fba45db2 | 2375 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 2376 | { |
c5aa993b JM |
2377 | if (bsp == NULL) |
2378 | return NULL; | |
c906108c | 2379 | |
c5aa993b JM |
2380 | for (; bsp != NULL; bsp = bsp->next) |
2381 | { | |
4f8d1dc6 | 2382 | if (bsp->breakpoint_at && bsp->breakpoint_at->owner == breakpoint) |
c5aa993b JM |
2383 | return bsp; |
2384 | } | |
c906108c SS |
2385 | return NULL; |
2386 | } | |
2387 | ||
2388 | /* Find a step_resume breakpoint associated with this bpstat. | |
2389 | (If there are multiple step_resume bp's on the list, this function | |
2390 | will arbitrarily pick one.) | |
2391 | ||
2392 | It is an error to use this function if BPSTAT doesn't contain a | |
2393 | step_resume breakpoint. | |
2394 | ||
2395 | See wait_for_inferior's use of this function. */ | |
2396 | struct breakpoint * | |
fba45db2 | 2397 | bpstat_find_step_resume_breakpoint (bpstat bsp) |
c906108c | 2398 | { |
8601f500 MS |
2399 | int current_thread; |
2400 | ||
8a3fe4f8 | 2401 | gdb_assert (bsp != NULL); |
c906108c | 2402 | |
8601f500 MS |
2403 | current_thread = pid_to_thread_id (inferior_ptid); |
2404 | ||
c906108c SS |
2405 | for (; bsp != NULL; bsp = bsp->next) |
2406 | { | |
059fb39f PM |
2407 | if ((bsp->breakpoint_at != NULL) |
2408 | && (bsp->breakpoint_at->owner->type == bp_step_resume) | |
2409 | && (bsp->breakpoint_at->owner->thread == current_thread | |
2410 | || bsp->breakpoint_at->owner->thread == -1)) | |
4f8d1dc6 | 2411 | return bsp->breakpoint_at->owner; |
c906108c SS |
2412 | } |
2413 | ||
8a3fe4f8 | 2414 | internal_error (__FILE__, __LINE__, _("No step_resume breakpoint found.")); |
c906108c SS |
2415 | } |
2416 | ||
2417 | ||
8671a17b | 2418 | /* Put in *NUM the breakpoint number of the first breakpoint we are stopped |
c906108c SS |
2419 | at. *BSP upon return is a bpstat which points to the remaining |
2420 | breakpoints stopped at (but which is not guaranteed to be good for | |
2421 | anything but further calls to bpstat_num). | |
8671a17b PA |
2422 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
2423 | Return -1 if stopped at a breakpoint that has been deleted since | |
2424 | we set it. | |
2425 | Return 1 otherwise. */ | |
c906108c SS |
2426 | |
2427 | int | |
8671a17b | 2428 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
2429 | { |
2430 | struct breakpoint *b; | |
2431 | ||
2432 | if ((*bsp) == NULL) | |
2433 | return 0; /* No more breakpoint values */ | |
8671a17b | 2434 | |
4f8d1dc6 VP |
2435 | /* We assume we'll never have several bpstats that |
2436 | correspond to a single breakpoint -- otherwise, | |
2437 | this function might return the same number more | |
2438 | than once and this will look ugly. */ | |
2439 | b = (*bsp)->breakpoint_at ? (*bsp)->breakpoint_at->owner : NULL; | |
8671a17b PA |
2440 | *bsp = (*bsp)->next; |
2441 | if (b == NULL) | |
2442 | return -1; /* breakpoint that's been deleted since */ | |
2443 | ||
2444 | *num = b->number; /* We have its number */ | |
2445 | return 1; | |
c906108c SS |
2446 | } |
2447 | ||
2448 | /* Modify BS so that the actions will not be performed. */ | |
2449 | ||
2450 | void | |
fba45db2 | 2451 | bpstat_clear_actions (bpstat bs) |
c906108c SS |
2452 | { |
2453 | for (; bs != NULL; bs = bs->next) | |
2454 | { | |
c2b8ed2c | 2455 | free_command_lines (&bs->commands); |
c906108c SS |
2456 | if (bs->old_val != NULL) |
2457 | { | |
2458 | value_free (bs->old_val); | |
2459 | bs->old_val = NULL; | |
2460 | } | |
2461 | } | |
2462 | } | |
2463 | ||
f3b1572e PA |
2464 | /* Called when a command is about to proceed the inferior. */ |
2465 | ||
2466 | static void | |
2467 | breakpoint_about_to_proceed (void) | |
2468 | { | |
2469 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
2470 | { | |
2471 | struct thread_info *tp = inferior_thread (); | |
2472 | ||
2473 | /* Allow inferior function calls in breakpoint commands to not | |
2474 | interrupt the command list. When the call finishes | |
2475 | successfully, the inferior will be standing at the same | |
2476 | breakpoint as if nothing happened. */ | |
2477 | if (tp->in_infcall) | |
2478 | return; | |
2479 | } | |
2480 | ||
2481 | breakpoint_proceeded = 1; | |
2482 | } | |
2483 | ||
c906108c | 2484 | /* Stub for cleaning up our state if we error-out of a breakpoint command */ |
c906108c | 2485 | static void |
4efb68b1 | 2486 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
2487 | { |
2488 | executing_breakpoint_commands = 0; | |
2489 | } | |
2490 | ||
2491 | /* Execute all the commands associated with all the breakpoints at this | |
2492 | location. Any of these commands could cause the process to proceed | |
2493 | beyond this point, etc. We look out for such changes by checking | |
347bddb7 | 2494 | the global "breakpoint_proceeded" after each command. |
c906108c | 2495 | |
347bddb7 PA |
2496 | Returns true if a breakpoint command resumed the inferior. In that |
2497 | case, it is the caller's responsibility to recall it again with the | |
2498 | bpstat of the current thread. */ | |
2499 | ||
2500 | static int | |
2501 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
2502 | { |
2503 | bpstat bs; | |
2504 | struct cleanup *old_chain; | |
347bddb7 | 2505 | int again = 0; |
c906108c SS |
2506 | |
2507 | /* Avoid endless recursion if a `source' command is contained | |
2508 | in bs->commands. */ | |
2509 | if (executing_breakpoint_commands) | |
347bddb7 | 2510 | return 0; |
c906108c SS |
2511 | |
2512 | executing_breakpoint_commands = 1; | |
2513 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
2514 | ||
c906108c SS |
2515 | /* This pointer will iterate over the list of bpstat's. */ |
2516 | bs = *bsp; | |
2517 | ||
2518 | breakpoint_proceeded = 0; | |
2519 | for (; bs != NULL; bs = bs->next) | |
2520 | { | |
6c50ab1c JB |
2521 | struct command_line *cmd; |
2522 | struct cleanup *this_cmd_tree_chain; | |
2523 | ||
2524 | /* Take ownership of the BSP's command tree, if it has one. | |
2525 | ||
2526 | The command tree could legitimately contain commands like | |
2527 | 'step' and 'next', which call clear_proceed_status, which | |
2528 | frees stop_bpstat's command tree. To make sure this doesn't | |
2529 | free the tree we're executing out from under us, we need to | |
2530 | take ownership of the tree ourselves. Since a given bpstat's | |
2531 | commands are only executed once, we don't need to copy it; we | |
2532 | can clear the pointer in the bpstat, and make sure we free | |
2533 | the tree when we're done. */ | |
c906108c | 2534 | cmd = bs->commands; |
6c50ab1c JB |
2535 | bs->commands = 0; |
2536 | this_cmd_tree_chain = make_cleanup_free_command_lines (&cmd); | |
2537 | ||
c906108c SS |
2538 | while (cmd != NULL) |
2539 | { | |
2540 | execute_control_command (cmd); | |
2541 | ||
2542 | if (breakpoint_proceeded) | |
2543 | break; | |
2544 | else | |
2545 | cmd = cmd->next; | |
2546 | } | |
6c50ab1c JB |
2547 | |
2548 | /* We can free this command tree now. */ | |
2549 | do_cleanups (this_cmd_tree_chain); | |
2550 | ||
c906108c | 2551 | if (breakpoint_proceeded) |
32c1e744 VP |
2552 | { |
2553 | if (target_can_async_p ()) | |
347bddb7 PA |
2554 | /* If we are in async mode, then the target might be still |
2555 | running, not stopped at any breakpoint, so nothing for | |
2556 | us to do here -- just return to the event loop. */ | |
2557 | ; | |
32c1e744 VP |
2558 | else |
2559 | /* In sync mode, when execute_control_command returns | |
2560 | we're already standing on the next breakpoint. | |
347bddb7 PA |
2561 | Breakpoint commands for that stop were not run, since |
2562 | execute_command does not run breakpoint commands -- | |
2563 | only command_line_handler does, but that one is not | |
2564 | involved in execution of breakpoint commands. So, we | |
2565 | can now execute breakpoint commands. It should be | |
2566 | noted that making execute_command do bpstat actions is | |
2567 | not an option -- in this case we'll have recursive | |
2568 | invocation of bpstat for each breakpoint with a | |
2569 | command, and can easily blow up GDB stack. Instead, we | |
2570 | return true, which will trigger the caller to recall us | |
2571 | with the new stop_bpstat. */ | |
2572 | again = 1; | |
2573 | break; | |
32c1e744 | 2574 | } |
c906108c | 2575 | } |
c2b8ed2c | 2576 | do_cleanups (old_chain); |
347bddb7 PA |
2577 | return again; |
2578 | } | |
2579 | ||
2580 | void | |
2581 | bpstat_do_actions (void) | |
2582 | { | |
2583 | /* Do any commands attached to breakpoint we are stopped at. */ | |
2584 | while (!ptid_equal (inferior_ptid, null_ptid) | |
2585 | && target_has_execution | |
2586 | && !is_exited (inferior_ptid) | |
2587 | && !is_executing (inferior_ptid)) | |
2588 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
2589 | and only return when it is stopped at the next breakpoint, we | |
2590 | keep doing breakpoint actions until it returns false to | |
2591 | indicate the inferior was not resumed. */ | |
2592 | if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat)) | |
2593 | break; | |
c906108c SS |
2594 | } |
2595 | ||
fa4727a6 DJ |
2596 | /* Print out the (old or new) value associated with a watchpoint. */ |
2597 | ||
2598 | static void | |
2599 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
2600 | { | |
2601 | if (val == NULL) | |
2602 | fprintf_unfiltered (stream, _("<unreadable>")); | |
2603 | else | |
79a45b7d TT |
2604 | { |
2605 | struct value_print_options opts; | |
2606 | get_user_print_options (&opts); | |
2607 | value_print (val, stream, &opts); | |
2608 | } | |
fa4727a6 DJ |
2609 | } |
2610 | ||
e514a9d6 | 2611 | /* This is the normal print function for a bpstat. In the future, |
c906108c | 2612 | much of this logic could (should?) be moved to bpstat_stop_status, |
e514a9d6 JM |
2613 | by having it set different print_it values. |
2614 | ||
2615 | Current scheme: When we stop, bpstat_print() is called. It loops | |
2616 | through the bpstat list of things causing this stop, calling the | |
2617 | print_bp_stop_message function on each one. The behavior of the | |
2618 | print_bp_stop_message function depends on the print_it field of | |
2619 | bpstat. If such field so indicates, call this function here. | |
2620 | ||
2621 | Return values from this routine (ultimately used by bpstat_print() | |
2622 | and normal_stop() to decide what to do): | |
2623 | PRINT_NOTHING: Means we already printed all we needed to print, | |
2624 | don't print anything else. | |
2625 | PRINT_SRC_ONLY: Means we printed something, and we do *not* desire | |
2626 | that something to be followed by a location. | |
2627 | PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire | |
2628 | that something to be followed by a location. | |
2629 | PRINT_UNKNOWN: Means we printed nothing or we need to do some more | |
2630 | analysis. */ | |
c906108c | 2631 | |
917317f4 | 2632 | static enum print_stop_action |
fba45db2 | 2633 | print_it_typical (bpstat bs) |
c906108c | 2634 | { |
f7545552 | 2635 | struct cleanup *old_chain; |
4f8d1dc6 | 2636 | struct breakpoint *b; |
89f9893c | 2637 | const struct bp_location *bl; |
8b93c638 | 2638 | struct ui_stream *stb; |
f7545552 TT |
2639 | int bp_temp = 0; |
2640 | enum print_stop_action result; | |
2641 | ||
c906108c SS |
2642 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
2643 | which has since been deleted. */ | |
e514a9d6 | 2644 | if (bs->breakpoint_at == NULL) |
917317f4 | 2645 | return PRINT_UNKNOWN; |
0d381245 VP |
2646 | bl = bs->breakpoint_at; |
2647 | b = bl->owner; | |
c906108c | 2648 | |
f7545552 TT |
2649 | stb = ui_out_stream_new (uiout); |
2650 | old_chain = make_cleanup_ui_out_stream_delete (stb); | |
2651 | ||
4f8d1dc6 | 2652 | switch (b->type) |
c906108c | 2653 | { |
e514a9d6 JM |
2654 | case bp_breakpoint: |
2655 | case bp_hardware_breakpoint: | |
2cec12e5 | 2656 | bp_temp = bs->breakpoint_at->owner->disposition == disp_del; |
0d381245 VP |
2657 | if (bl->address != bl->requested_address) |
2658 | breakpoint_adjustment_warning (bl->requested_address, | |
2659 | bl->address, | |
4f8d1dc6 VP |
2660 | b->number, 1); |
2661 | annotate_breakpoint (b->number); | |
2cec12e5 AR |
2662 | if (bp_temp) |
2663 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
2664 | else | |
2665 | ui_out_text (uiout, "\nBreakpoint "); | |
9dc5e2a9 | 2666 | if (ui_out_is_mi_like_p (uiout)) |
2cec12e5 AR |
2667 | { |
2668 | ui_out_field_string (uiout, "reason", | |
2669 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
2670 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
2671 | } | |
4f8d1dc6 | 2672 | ui_out_field_int (uiout, "bkptno", b->number); |
8b93c638 | 2673 | ui_out_text (uiout, ", "); |
f7545552 | 2674 | result = PRINT_SRC_AND_LOC; |
e514a9d6 JM |
2675 | break; |
2676 | ||
2677 | case bp_shlib_event: | |
917317f4 JM |
2678 | /* Did we stop because the user set the stop_on_solib_events |
2679 | variable? (If so, we report this as a generic, "Stopped due | |
2680 | to shlib event" message.) */ | |
a3f17187 | 2681 | printf_filtered (_("Stopped due to shared library event\n")); |
f7545552 | 2682 | result = PRINT_NOTHING; |
e514a9d6 JM |
2683 | break; |
2684 | ||
c4093a6a JM |
2685 | case bp_thread_event: |
2686 | /* Not sure how we will get here. | |
2687 | GDB should not stop for these breakpoints. */ | |
a3f17187 | 2688 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 2689 | result = PRINT_NOTHING; |
c4093a6a JM |
2690 | break; |
2691 | ||
1900040c MS |
2692 | case bp_overlay_event: |
2693 | /* By analogy with the thread event, GDB should not stop for these. */ | |
a3f17187 | 2694 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 2695 | result = PRINT_NOTHING; |
1900040c MS |
2696 | break; |
2697 | ||
0fd8e87f UW |
2698 | case bp_longjmp_master: |
2699 | /* These should never be enabled. */ | |
2700 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
2701 | result = PRINT_NOTHING; | |
2702 | break; | |
2703 | ||
e514a9d6 JM |
2704 | case bp_watchpoint: |
2705 | case bp_hardware_watchpoint: | |
fa4727a6 DJ |
2706 | annotate_watchpoint (b->number); |
2707 | if (ui_out_is_mi_like_p (uiout)) | |
2708 | ui_out_field_string | |
2709 | (uiout, "reason", | |
2710 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
2711 | mention (b); | |
f7545552 | 2712 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
fa4727a6 DJ |
2713 | ui_out_text (uiout, "\nOld value = "); |
2714 | watchpoint_value_print (bs->old_val, stb->stream); | |
2715 | ui_out_field_stream (uiout, "old", stb); | |
2716 | ui_out_text (uiout, "\nNew value = "); | |
2717 | watchpoint_value_print (b->val, stb->stream); | |
2718 | ui_out_field_stream (uiout, "new", stb); | |
fa4727a6 | 2719 | ui_out_text (uiout, "\n"); |
e514a9d6 | 2720 | /* More than one watchpoint may have been triggered. */ |
f7545552 | 2721 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
2722 | break; |
2723 | ||
2724 | case bp_read_watchpoint: | |
9dc5e2a9 | 2725 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2726 | ui_out_field_string |
2727 | (uiout, "reason", | |
2728 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 2729 | mention (b); |
f7545552 | 2730 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 2731 | ui_out_text (uiout, "\nValue = "); |
fa4727a6 | 2732 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 2733 | ui_out_field_stream (uiout, "value", stb); |
8b93c638 | 2734 | ui_out_text (uiout, "\n"); |
f7545552 | 2735 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
2736 | break; |
2737 | ||
2738 | case bp_access_watchpoint: | |
fa4727a6 | 2739 | if (bs->old_val != NULL) |
8b93c638 | 2740 | { |
4f8d1dc6 | 2741 | annotate_watchpoint (b->number); |
9dc5e2a9 | 2742 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2743 | ui_out_field_string |
2744 | (uiout, "reason", | |
2745 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 2746 | mention (b); |
f7545552 | 2747 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 2748 | ui_out_text (uiout, "\nOld value = "); |
fa4727a6 | 2749 | watchpoint_value_print (bs->old_val, stb->stream); |
8b93c638 | 2750 | ui_out_field_stream (uiout, "old", stb); |
8b93c638 JM |
2751 | ui_out_text (uiout, "\nNew value = "); |
2752 | } | |
2753 | else | |
2754 | { | |
4f8d1dc6 | 2755 | mention (b); |
9dc5e2a9 | 2756 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2757 | ui_out_field_string |
2758 | (uiout, "reason", | |
2759 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
f7545552 | 2760 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 JM |
2761 | ui_out_text (uiout, "\nValue = "); |
2762 | } | |
fa4727a6 | 2763 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 2764 | ui_out_field_stream (uiout, "new", stb); |
8b93c638 | 2765 | ui_out_text (uiout, "\n"); |
f7545552 | 2766 | result = PRINT_UNKNOWN; |
e514a9d6 | 2767 | break; |
4ce44c66 | 2768 | |
e514a9d6 JM |
2769 | /* Fall through, we don't deal with these types of breakpoints |
2770 | here. */ | |
2771 | ||
11cf8741 | 2772 | case bp_finish: |
9dc5e2a9 | 2773 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2774 | ui_out_field_string |
2775 | (uiout, "reason", | |
2776 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
f7545552 | 2777 | result = PRINT_UNKNOWN; |
8b93c638 JM |
2778 | break; |
2779 | ||
e514a9d6 | 2780 | case bp_until: |
9dc5e2a9 | 2781 | if (ui_out_is_mi_like_p (uiout)) |
1fbc2a49 NR |
2782 | ui_out_field_string |
2783 | (uiout, "reason", | |
2784 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
f7545552 | 2785 | result = PRINT_UNKNOWN; |
8b93c638 JM |
2786 | break; |
2787 | ||
c2d11a7d | 2788 | case bp_none: |
e514a9d6 JM |
2789 | case bp_longjmp: |
2790 | case bp_longjmp_resume: | |
2791 | case bp_step_resume: | |
e514a9d6 JM |
2792 | case bp_watchpoint_scope: |
2793 | case bp_call_dummy: | |
1042e4c0 | 2794 | case bp_tracepoint: |
4efc6507 | 2795 | case bp_jit_event: |
e514a9d6 | 2796 | default: |
f7545552 TT |
2797 | result = PRINT_UNKNOWN; |
2798 | break; | |
e514a9d6 | 2799 | } |
f7545552 TT |
2800 | |
2801 | do_cleanups (old_chain); | |
2802 | return result; | |
e514a9d6 JM |
2803 | } |
2804 | ||
2805 | /* Generic routine for printing messages indicating why we | |
2806 | stopped. The behavior of this function depends on the value | |
2807 | 'print_it' in the bpstat structure. Under some circumstances we | |
2808 | may decide not to print anything here and delegate the task to | |
2809 | normal_stop(). */ | |
2810 | ||
2811 | static enum print_stop_action | |
2812 | print_bp_stop_message (bpstat bs) | |
2813 | { | |
2814 | switch (bs->print_it) | |
2815 | { | |
2816 | case print_it_noop: | |
2817 | /* Nothing should be printed for this bpstat entry. */ | |
2818 | return PRINT_UNKNOWN; | |
2819 | break; | |
2820 | ||
2821 | case print_it_done: | |
2822 | /* We still want to print the frame, but we already printed the | |
2823 | relevant messages. */ | |
2824 | return PRINT_SRC_AND_LOC; | |
2825 | break; | |
2826 | ||
2827 | case print_it_normal: | |
4f8d1dc6 | 2828 | { |
89f9893c | 2829 | const struct bp_location *bl = bs->breakpoint_at; |
4f8d1dc6 VP |
2830 | struct breakpoint *b = bl ? bl->owner : NULL; |
2831 | ||
2832 | /* Normal case. Call the breakpoint's print_it method, or | |
2833 | print_it_typical. */ | |
2834 | /* FIXME: how breakpoint can ever be NULL here? */ | |
2835 | if (b != NULL && b->ops != NULL && b->ops->print_it != NULL) | |
2836 | return b->ops->print_it (b); | |
2837 | else | |
2838 | return print_it_typical (bs); | |
2839 | } | |
2840 | break; | |
3086aeae | 2841 | |
e514a9d6 | 2842 | default: |
8e65ff28 | 2843 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 2844 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 2845 | break; |
c906108c | 2846 | } |
c906108c SS |
2847 | } |
2848 | ||
e514a9d6 JM |
2849 | /* Print a message indicating what happened. This is called from |
2850 | normal_stop(). The input to this routine is the head of the bpstat | |
2851 | list - a list of the eventpoints that caused this stop. This | |
2852 | routine calls the generic print routine for printing a message | |
2853 | about reasons for stopping. This will print (for example) the | |
2854 | "Breakpoint n," part of the output. The return value of this | |
2855 | routine is one of: | |
c906108c | 2856 | |
917317f4 JM |
2857 | PRINT_UNKNOWN: Means we printed nothing |
2858 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent | |
c5aa993b JM |
2859 | code to print the location. An example is |
2860 | "Breakpoint 1, " which should be followed by | |
2861 | the location. | |
917317f4 | 2862 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
2863 | to also print the location part of the message. |
2864 | An example is the catch/throw messages, which | |
917317f4 JM |
2865 | don't require a location appended to the end. |
2866 | PRINT_NOTHING: We have done some printing and we don't need any | |
2867 | further info to be printed.*/ | |
c906108c | 2868 | |
917317f4 | 2869 | enum print_stop_action |
fba45db2 | 2870 | bpstat_print (bpstat bs) |
c906108c SS |
2871 | { |
2872 | int val; | |
c5aa993b | 2873 | |
c906108c | 2874 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
2875 | (Currently all watchpoints go on the bpstat whether hit or not. |
2876 | That probably could (should) be changed, provided care is taken | |
c906108c | 2877 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
2878 | for (; bs; bs = bs->next) |
2879 | { | |
2880 | val = print_bp_stop_message (bs); | |
2881 | if (val == PRINT_SRC_ONLY | |
2882 | || val == PRINT_SRC_AND_LOC | |
2883 | || val == PRINT_NOTHING) | |
2884 | return val; | |
2885 | } | |
c906108c | 2886 | |
e514a9d6 JM |
2887 | /* We reached the end of the chain, or we got a null BS to start |
2888 | with and nothing was printed. */ | |
917317f4 | 2889 | return PRINT_UNKNOWN; |
c906108c SS |
2890 | } |
2891 | ||
2892 | /* Evaluate the expression EXP and return 1 if value is zero. | |
2893 | This is used inside a catch_errors to evaluate the breakpoint condition. | |
2894 | The argument is a "struct expression *" that has been cast to char * to | |
2895 | make it pass through catch_errors. */ | |
2896 | ||
2897 | static int | |
4efb68b1 | 2898 | breakpoint_cond_eval (void *exp) |
c906108c | 2899 | { |
278cd55f | 2900 | struct value *mark = value_mark (); |
c5aa993b | 2901 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
c906108c SS |
2902 | value_free_to_mark (mark); |
2903 | return i; | |
2904 | } | |
2905 | ||
2906 | /* Allocate a new bpstat and chain it to the current one. */ | |
2907 | ||
2908 | static bpstat | |
89f9893c | 2909 | bpstat_alloc (const struct bp_location *bl, bpstat cbs /* Current "bs" value */ ) |
c906108c SS |
2910 | { |
2911 | bpstat bs; | |
2912 | ||
2913 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
2914 | cbs->next = bs; | |
4f8d1dc6 | 2915 | bs->breakpoint_at = bl; |
c906108c SS |
2916 | /* If the condition is false, etc., don't do the commands. */ |
2917 | bs->commands = NULL; | |
2918 | bs->old_val = NULL; | |
2919 | bs->print_it = print_it_normal; | |
2920 | return bs; | |
2921 | } | |
2922 | \f | |
d983da9c DJ |
2923 | /* The target has stopped with waitstatus WS. Check if any hardware |
2924 | watchpoints have triggered, according to the target. */ | |
2925 | ||
2926 | int | |
2927 | watchpoints_triggered (struct target_waitstatus *ws) | |
2928 | { | |
d92524f1 | 2929 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
2930 | CORE_ADDR addr; |
2931 | struct breakpoint *b; | |
2932 | ||
2933 | if (!stopped_by_watchpoint) | |
2934 | { | |
2935 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
2936 | as not triggered. */ | |
2937 | ALL_BREAKPOINTS (b) | |
2938 | if (b->type == bp_hardware_watchpoint | |
2939 | || b->type == bp_read_watchpoint | |
2940 | || b->type == bp_access_watchpoint) | |
2941 | b->watchpoint_triggered = watch_triggered_no; | |
2942 | ||
2943 | return 0; | |
2944 | } | |
2945 | ||
2946 | if (!target_stopped_data_address (¤t_target, &addr)) | |
2947 | { | |
2948 | /* We were stopped by a watchpoint, but we don't know where. | |
2949 | Mark all watchpoints as unknown. */ | |
2950 | ALL_BREAKPOINTS (b) | |
2951 | if (b->type == bp_hardware_watchpoint | |
2952 | || b->type == bp_read_watchpoint | |
2953 | || b->type == bp_access_watchpoint) | |
2954 | b->watchpoint_triggered = watch_triggered_unknown; | |
2955 | ||
2956 | return stopped_by_watchpoint; | |
2957 | } | |
2958 | ||
2959 | /* The target could report the data address. Mark watchpoints | |
2960 | affected by this data address as triggered, and all others as not | |
2961 | triggered. */ | |
2962 | ||
2963 | ALL_BREAKPOINTS (b) | |
2964 | if (b->type == bp_hardware_watchpoint | |
2965 | || b->type == bp_read_watchpoint | |
2966 | || b->type == bp_access_watchpoint) | |
2967 | { | |
a5606eee | 2968 | struct bp_location *loc; |
d983da9c DJ |
2969 | struct value *v; |
2970 | ||
2971 | b->watchpoint_triggered = watch_triggered_no; | |
a5606eee VP |
2972 | for (loc = b->loc; loc; loc = loc->next) |
2973 | /* Exact match not required. Within range is | |
2974 | sufficient. */ | |
5009afc5 AS |
2975 | if (target_watchpoint_addr_within_range (¤t_target, |
2976 | addr, loc->address, | |
2977 | loc->length)) | |
a5606eee VP |
2978 | { |
2979 | b->watchpoint_triggered = watch_triggered_yes; | |
2980 | break; | |
2981 | } | |
d983da9c DJ |
2982 | } |
2983 | ||
2984 | return 1; | |
2985 | } | |
2986 | ||
c906108c SS |
2987 | /* Possible return values for watchpoint_check (this can't be an enum |
2988 | because of check_errors). */ | |
2989 | /* The watchpoint has been deleted. */ | |
2990 | #define WP_DELETED 1 | |
2991 | /* The value has changed. */ | |
2992 | #define WP_VALUE_CHANGED 2 | |
2993 | /* The value has not changed. */ | |
2994 | #define WP_VALUE_NOT_CHANGED 3 | |
2995 | ||
2996 | #define BP_TEMPFLAG 1 | |
2997 | #define BP_HARDWAREFLAG 2 | |
2998 | ||
2999 | /* Check watchpoint condition. */ | |
3000 | ||
3001 | static int | |
4efb68b1 | 3002 | watchpoint_check (void *p) |
c906108c SS |
3003 | { |
3004 | bpstat bs = (bpstat) p; | |
3005 | struct breakpoint *b; | |
3006 | struct frame_info *fr; | |
3007 | int within_current_scope; | |
3008 | ||
4f8d1dc6 | 3009 | b = bs->breakpoint_at->owner; |
c906108c SS |
3010 | |
3011 | if (b->exp_valid_block == NULL) | |
3012 | within_current_scope = 1; | |
3013 | else | |
3014 | { | |
edb3359d DJ |
3015 | struct frame_info *frame = get_current_frame (); |
3016 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
3017 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
3018 | ||
101dcfbe | 3019 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 3020 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
3021 | |
3022 | /* If we've gotten confused in the unwinder, we might have | |
3023 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
3024 | if (within_current_scope) |
3025 | { | |
3026 | struct symbol *function; | |
3027 | ||
3028 | function = get_frame_function (fr); | |
3029 | if (function == NULL | |
3030 | || !contained_in (b->exp_valid_block, | |
3031 | SYMBOL_BLOCK_VALUE (function))) | |
3032 | within_current_scope = 0; | |
3033 | } | |
69fbadd5 | 3034 | |
c12260ac CV |
3035 | /* in_function_epilogue_p() returns a non-zero value if we're still |
3036 | in the function but the stack frame has already been invalidated. | |
3037 | Since we can't rely on the values of local variables after the | |
3038 | stack has been destroyed, we are treating the watchpoint in that | |
edb3359d DJ |
3039 | state as `not changed' without further checking. Don't mark |
3040 | watchpoints as changed if the current frame is in an epilogue - | |
3041 | even if they are in some other frame, our view of the stack | |
3042 | is likely to be wrong. */ | |
3043 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) | |
3044 | return WP_VALUE_NOT_CHANGED; | |
fb14de7b | 3045 | |
edb3359d | 3046 | if (within_current_scope) |
c906108c SS |
3047 | /* If we end up stopping, the current frame will get selected |
3048 | in normal_stop. So this call to select_frame won't affect | |
3049 | the user. */ | |
0f7d239c | 3050 | select_frame (fr); |
c906108c | 3051 | } |
c5aa993b | 3052 | |
c906108c SS |
3053 | if (within_current_scope) |
3054 | { | |
3055 | /* We use value_{,free_to_}mark because it could be a | |
3056 | *long* time before we return to the command level and | |
c5aa993b JM |
3057 | call free_all_values. We can't call free_all_values because |
3058 | we might be in the middle of evaluating a function call. */ | |
c906108c | 3059 | |
278cd55f | 3060 | struct value *mark = value_mark (); |
fa4727a6 DJ |
3061 | struct value *new_val; |
3062 | ||
3063 | fetch_watchpoint_value (b->exp, &new_val, NULL, NULL); | |
3064 | if ((b->val != NULL) != (new_val != NULL) | |
3065 | || (b->val != NULL && !value_equal (b->val, new_val))) | |
c906108c | 3066 | { |
fa4727a6 DJ |
3067 | if (new_val != NULL) |
3068 | { | |
3069 | release_value (new_val); | |
3070 | value_free_to_mark (mark); | |
3071 | } | |
c906108c SS |
3072 | bs->old_val = b->val; |
3073 | b->val = new_val; | |
fa4727a6 | 3074 | b->val_valid = 1; |
c906108c SS |
3075 | /* We will stop here */ |
3076 | return WP_VALUE_CHANGED; | |
3077 | } | |
3078 | else | |
3079 | { | |
3080 | /* Nothing changed, don't do anything. */ | |
3081 | value_free_to_mark (mark); | |
3082 | /* We won't stop here */ | |
3083 | return WP_VALUE_NOT_CHANGED; | |
3084 | } | |
3085 | } | |
3086 | else | |
3087 | { | |
3088 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
3089 | if we temporarily ignored the watchpoint, then when |
3090 | we reenter the block in which it is valid it contains | |
3091 | garbage (in the case of a function, it may have two | |
3092 | garbage values, one before and one after the prologue). | |
3093 | So we can't even detect the first assignment to it and | |
3094 | watch after that (since the garbage may or may not equal | |
3095 | the first value assigned). */ | |
4ce44c66 JM |
3096 | /* We print all the stop information in print_it_typical(), but |
3097 | in this case, by the time we call print_it_typical() this bp | |
3098 | will be deleted already. So we have no choice but print the | |
3099 | information here. */ | |
9dc5e2a9 | 3100 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3101 | ui_out_field_string |
3102 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 3103 | ui_out_text (uiout, "\nWatchpoint "); |
4f8d1dc6 | 3104 | ui_out_field_int (uiout, "wpnum", b->number); |
8b93c638 JM |
3105 | ui_out_text (uiout, " deleted because the program has left the block in\n\ |
3106 | which its expression is valid.\n"); | |
4ce44c66 | 3107 | |
c906108c | 3108 | if (b->related_breakpoint) |
b5de0fa7 EZ |
3109 | b->related_breakpoint->disposition = disp_del_at_next_stop; |
3110 | b->disposition = disp_del_at_next_stop; | |
c906108c SS |
3111 | |
3112 | return WP_DELETED; | |
3113 | } | |
3114 | } | |
3115 | ||
18a18393 VP |
3116 | /* Return true if it looks like target has stopped due to hitting |
3117 | breakpoint location BL. This function does not check if we | |
3118 | should stop, only if BL explains the stop. */ | |
3119 | static int | |
6c95b8df PA |
3120 | bpstat_check_location (const struct bp_location *bl, |
3121 | struct address_space *aspace, CORE_ADDR bp_addr) | |
18a18393 VP |
3122 | { |
3123 | struct breakpoint *b = bl->owner; | |
3124 | ||
3125 | if (b->type != bp_watchpoint | |
3126 | && b->type != bp_hardware_watchpoint | |
3127 | && b->type != bp_read_watchpoint | |
3128 | && b->type != bp_access_watchpoint | |
3129 | && b->type != bp_hardware_breakpoint | |
fe798b75 | 3130 | && b->type != bp_catchpoint) /* a non-watchpoint bp */ |
18a18393 | 3131 | { |
6c95b8df PA |
3132 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
3133 | aspace, bp_addr)) | |
18a18393 VP |
3134 | return 0; |
3135 | if (overlay_debugging /* unmapped overlay section */ | |
3136 | && section_is_overlay (bl->section) | |
3137 | && !section_is_mapped (bl->section)) | |
3138 | return 0; | |
3139 | } | |
3140 | ||
3141 | /* Continuable hardware watchpoints are treated as non-existent if the | |
3142 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
3143 | some data address). Otherwise gdb won't stop on a break instruction | |
3144 | in the code (not from a breakpoint) when a hardware watchpoint has | |
3145 | been defined. Also skip watchpoints which we know did not trigger | |
3146 | (did not match the data address). */ | |
3147 | ||
3148 | if ((b->type == bp_hardware_watchpoint | |
3149 | || b->type == bp_read_watchpoint | |
3150 | || b->type == bp_access_watchpoint) | |
3151 | && b->watchpoint_triggered == watch_triggered_no) | |
3152 | return 0; | |
3153 | ||
3154 | if (b->type == bp_hardware_breakpoint) | |
3155 | { | |
3156 | if (bl->address != bp_addr) | |
3157 | return 0; | |
3158 | if (overlay_debugging /* unmapped overlay section */ | |
3159 | && section_is_overlay (bl->section) | |
3160 | && !section_is_mapped (bl->section)) | |
3161 | return 0; | |
3162 | } | |
ce78b96d | 3163 | |
ce78b96d JB |
3164 | if (b->type == bp_catchpoint) |
3165 | { | |
3166 | gdb_assert (b->ops != NULL && b->ops->breakpoint_hit != NULL); | |
3167 | if (!b->ops->breakpoint_hit (b)) | |
3168 | return 0; | |
3169 | } | |
3170 | ||
18a18393 VP |
3171 | return 1; |
3172 | } | |
3173 | ||
3174 | /* If BS refers to a watchpoint, determine if the watched values | |
3175 | has actually changed, and we should stop. If not, set BS->stop | |
3176 | to 0. */ | |
3177 | static void | |
3178 | bpstat_check_watchpoint (bpstat bs) | |
3179 | { | |
3180 | const struct bp_location *bl = bs->breakpoint_at; | |
3181 | struct breakpoint *b = bl->owner; | |
3182 | ||
3183 | if (b->type == bp_watchpoint | |
3184 | || b->type == bp_read_watchpoint | |
3185 | || b->type == bp_access_watchpoint | |
3186 | || b->type == bp_hardware_watchpoint) | |
3187 | { | |
3188 | CORE_ADDR addr; | |
3189 | struct value *v; | |
3190 | int must_check_value = 0; | |
3191 | ||
3192 | if (b->type == bp_watchpoint) | |
3193 | /* For a software watchpoint, we must always check the | |
3194 | watched value. */ | |
3195 | must_check_value = 1; | |
3196 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
3197 | /* We have a hardware watchpoint (read, write, or access) | |
3198 | and the target earlier reported an address watched by | |
3199 | this watchpoint. */ | |
3200 | must_check_value = 1; | |
3201 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3202 | && b->type == bp_hardware_watchpoint) | |
3203 | /* We were stopped by a hardware watchpoint, but the target could | |
3204 | not report the data address. We must check the watchpoint's | |
3205 | value. Access and read watchpoints are out of luck; without | |
3206 | a data address, we can't figure it out. */ | |
3207 | must_check_value = 1; | |
3208 | ||
3209 | if (must_check_value) | |
3210 | { | |
3211 | char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3212 | b->number); | |
3213 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
3214 | int e = catch_errors (watchpoint_check, bs, message, | |
3215 | RETURN_MASK_ALL); | |
3216 | do_cleanups (cleanups); | |
3217 | switch (e) | |
3218 | { | |
3219 | case WP_DELETED: | |
3220 | /* We've already printed what needs to be printed. */ | |
3221 | bs->print_it = print_it_done; | |
3222 | /* Stop. */ | |
3223 | break; | |
3224 | case WP_VALUE_CHANGED: | |
3225 | if (b->type == bp_read_watchpoint) | |
3226 | { | |
3227 | /* Don't stop: read watchpoints shouldn't fire if | |
3228 | the value has changed. This is for targets | |
3229 | which cannot set read-only watchpoints. */ | |
3230 | bs->print_it = print_it_noop; | |
3231 | bs->stop = 0; | |
3232 | } | |
3233 | break; | |
3234 | case WP_VALUE_NOT_CHANGED: | |
3235 | if (b->type == bp_hardware_watchpoint | |
3236 | || b->type == bp_watchpoint) | |
3237 | { | |
3238 | /* Don't stop: write watchpoints shouldn't fire if | |
3239 | the value hasn't changed. */ | |
3240 | bs->print_it = print_it_noop; | |
3241 | bs->stop = 0; | |
3242 | } | |
3243 | /* Stop. */ | |
3244 | break; | |
3245 | default: | |
3246 | /* Can't happen. */ | |
3247 | case 0: | |
3248 | /* Error from catch_errors. */ | |
3249 | printf_filtered (_("Watchpoint %d deleted.\n"), b->number); | |
3250 | if (b->related_breakpoint) | |
3251 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
3252 | b->disposition = disp_del_at_next_stop; | |
3253 | /* We've already printed what needs to be printed. */ | |
3254 | bs->print_it = print_it_done; | |
3255 | break; | |
3256 | } | |
3257 | } | |
3258 | else /* must_check_value == 0 */ | |
3259 | { | |
3260 | /* This is a case where some watchpoint(s) triggered, but | |
3261 | not at the address of this watchpoint, or else no | |
3262 | watchpoint triggered after all. So don't print | |
3263 | anything for this watchpoint. */ | |
3264 | bs->print_it = print_it_noop; | |
3265 | bs->stop = 0; | |
3266 | } | |
3267 | } | |
3268 | } | |
3269 | ||
3270 | ||
3271 | /* Check conditions (condition proper, frame, thread and ignore count) | |
3272 | of breakpoint referred to by BS. If we should not stop for this | |
3273 | breakpoint, set BS->stop to 0. */ | |
3274 | static void | |
3275 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
3276 | { | |
3277 | int thread_id = pid_to_thread_id (ptid); | |
3278 | const struct bp_location *bl = bs->breakpoint_at; | |
3279 | struct breakpoint *b = bl->owner; | |
3280 | ||
3281 | if (frame_id_p (b->frame_id) | |
edb3359d | 3282 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 VP |
3283 | bs->stop = 0; |
3284 | else if (bs->stop) | |
3285 | { | |
3286 | int value_is_zero = 0; | |
3287 | ||
3288 | /* If this is a scope breakpoint, mark the associated | |
3289 | watchpoint as triggered so that we will handle the | |
3290 | out-of-scope event. We'll get to the watchpoint next | |
3291 | iteration. */ | |
3292 | if (b->type == bp_watchpoint_scope) | |
3293 | b->related_breakpoint->watchpoint_triggered = watch_triggered_yes; | |
3294 | ||
3295 | if (bl->cond && bl->owner->disposition != disp_del_at_next_stop) | |
3296 | { | |
c5bc3a77 DJ |
3297 | /* We use value_mark and value_free_to_mark because it could |
3298 | be a long time before we return to the command level and | |
3299 | call free_all_values. We can't call free_all_values | |
3300 | because we might be in the middle of evaluating a | |
3301 | function call. */ | |
3302 | struct value *mark = value_mark (); | |
3303 | ||
edb3359d DJ |
3304 | /* Need to select the frame, with all that implies so that |
3305 | the conditions will have the right context. Because we | |
3306 | use the frame, we will not see an inlined function's | |
3307 | variables when we arrive at a breakpoint at the start | |
3308 | of the inlined function; the current frame will be the | |
3309 | call site. */ | |
18a18393 VP |
3310 | select_frame (get_current_frame ()); |
3311 | value_is_zero | |
3312 | = catch_errors (breakpoint_cond_eval, (bl->cond), | |
3313 | "Error in testing breakpoint condition:\n", | |
3314 | RETURN_MASK_ALL); | |
3315 | /* FIXME-someday, should give breakpoint # */ | |
c5bc3a77 | 3316 | value_free_to_mark (mark); |
18a18393 VP |
3317 | } |
3318 | if (bl->cond && value_is_zero) | |
3319 | { | |
3320 | bs->stop = 0; | |
3321 | } | |
3322 | else if (b->thread != -1 && b->thread != thread_id) | |
3323 | { | |
3324 | bs->stop = 0; | |
3325 | } | |
3326 | else if (b->ignore_count > 0) | |
3327 | { | |
3328 | b->ignore_count--; | |
3329 | annotate_ignore_count_change (); | |
3330 | bs->stop = 0; | |
3331 | /* Increase the hit count even though we don't | |
3332 | stop. */ | |
3333 | ++(b->hit_count); | |
3334 | } | |
3335 | } | |
3336 | } | |
3337 | ||
3338 | ||
9709f61c | 3339 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 3340 | BP_ADDR in thread PTID. |
c906108c | 3341 | |
d983da9c | 3342 | Determine whether we stopped at a breakpoint, etc, or whether we |
c906108c SS |
3343 | don't understand this stop. Result is a chain of bpstat's such that: |
3344 | ||
c5aa993b | 3345 | if we don't understand the stop, the result is a null pointer. |
c906108c | 3346 | |
c5aa993b | 3347 | if we understand why we stopped, the result is not null. |
c906108c | 3348 | |
c5aa993b JM |
3349 | Each element of the chain refers to a particular breakpoint or |
3350 | watchpoint at which we have stopped. (We may have stopped for | |
3351 | several reasons concurrently.) | |
c906108c | 3352 | |
c5aa993b JM |
3353 | Each element of the chain has valid next, breakpoint_at, |
3354 | commands, FIXME??? fields. */ | |
c906108c SS |
3355 | |
3356 | bpstat | |
6c95b8df PA |
3357 | bpstat_stop_status (struct address_space *aspace, |
3358 | CORE_ADDR bp_addr, ptid_t ptid) | |
c906108c | 3359 | { |
0d381245 | 3360 | struct breakpoint *b = NULL; |
89f9893c | 3361 | const struct bp_location *bl; |
20874c92 | 3362 | struct bp_location *loc; |
c906108c SS |
3363 | /* Root of the chain of bpstat's */ |
3364 | struct bpstats root_bs[1]; | |
3365 | /* Pointer to the last thing in the chain currently. */ | |
3366 | bpstat bs = root_bs; | |
20874c92 | 3367 | int ix; |
d832cb68 | 3368 | int need_remove_insert; |
c906108c | 3369 | |
0d381245 | 3370 | ALL_BP_LOCATIONS (bl) |
c5aa993b | 3371 | { |
0d381245 VP |
3372 | b = bl->owner; |
3373 | gdb_assert (b); | |
468d015d | 3374 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) |
c5aa993b JM |
3375 | continue; |
3376 | ||
a5606eee VP |
3377 | /* For hardware watchpoints, we look only at the first location. |
3378 | The watchpoint_check function will work on entire expression, | |
3379 | not the individual locations. For read watchopints, the | |
3380 | watchpoints_triggered function have checked all locations | |
3381 | alrea | |
3382 | */ | |
3383 | if (b->type == bp_hardware_watchpoint && bl != b->loc) | |
3384 | continue; | |
3385 | ||
6c95b8df | 3386 | if (!bpstat_check_location (bl, aspace, bp_addr)) |
18a18393 VP |
3387 | continue; |
3388 | ||
c5aa993b JM |
3389 | /* Come here if it's a watchpoint, or if the break address matches */ |
3390 | ||
0d381245 | 3391 | bs = bpstat_alloc (bl, bs); /* Alloc a bpstat to explain stop */ |
c5aa993b | 3392 | |
18a18393 VP |
3393 | /* Assume we stop. Should we find watchpoint that is not actually |
3394 | triggered, or if condition of breakpoint is false, we'll reset | |
3395 | 'stop' to 0. */ | |
c5aa993b JM |
3396 | bs->stop = 1; |
3397 | bs->print = 1; | |
3398 | ||
18a18393 VP |
3399 | bpstat_check_watchpoint (bs); |
3400 | if (!bs->stop) | |
3401 | continue; | |
c5aa993b | 3402 | |
0fd8e87f UW |
3403 | if (b->type == bp_thread_event || b->type == bp_overlay_event |
3404 | || b->type == bp_longjmp_master) | |
18a18393 | 3405 | /* We do not stop for these. */ |
c5aa993b JM |
3406 | bs->stop = 0; |
3407 | else | |
18a18393 VP |
3408 | bpstat_check_breakpoint_conditions (bs, ptid); |
3409 | ||
3410 | if (bs->stop) | |
c5aa993b | 3411 | { |
18a18393 | 3412 | ++(b->hit_count); |
d983da9c | 3413 | |
18a18393 VP |
3414 | /* We will stop here */ |
3415 | if (b->disposition == disp_disable) | |
c5aa993b | 3416 | { |
514f746b AR |
3417 | if (b->enable_state != bp_permanent) |
3418 | b->enable_state = bp_disabled; | |
b60e7edf | 3419 | update_global_location_list (0); |
c5aa993b | 3420 | } |
18a18393 VP |
3421 | if (b->silent) |
3422 | bs->print = 0; | |
3423 | bs->commands = b->commands; | |
059fb39f PM |
3424 | if (bs->commands |
3425 | && (strcmp ("silent", bs->commands->line) == 0 | |
3426 | || (xdb_commands && strcmp ("Q", bs->commands->line) == 0))) | |
c5aa993b | 3427 | { |
18a18393 VP |
3428 | bs->commands = bs->commands->next; |
3429 | bs->print = 0; | |
c5aa993b | 3430 | } |
18a18393 | 3431 | bs->commands = copy_command_lines (bs->commands); |
c5aa993b | 3432 | } |
18a18393 | 3433 | |
c5aa993b JM |
3434 | /* Print nothing for this entry if we dont stop or if we dont print. */ |
3435 | if (bs->stop == 0 || bs->print == 0) | |
3436 | bs->print_it = print_it_noop; | |
3437 | } | |
c906108c | 3438 | |
20874c92 VP |
3439 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
3440 | { | |
6c95b8df PA |
3441 | if (breakpoint_address_match (loc->pspace->aspace, loc->address, |
3442 | aspace, bp_addr)) | |
20874c92 VP |
3443 | { |
3444 | bs = bpstat_alloc (loc, bs); | |
3445 | /* For hits of moribund locations, we should just proceed. */ | |
3446 | bs->stop = 0; | |
3447 | bs->print = 0; | |
3448 | bs->print_it = print_it_noop; | |
3449 | } | |
3450 | } | |
3451 | ||
c906108c SS |
3452 | bs->next = NULL; /* Terminate the chain */ |
3453 | bs = root_bs->next; /* Re-grab the head of the chain */ | |
3454 | ||
d983da9c DJ |
3455 | /* If we aren't stopping, the value of some hardware watchpoint may |
3456 | not have changed, but the intermediate memory locations we are | |
3457 | watching may have. Don't bother if we're stopping; this will get | |
3458 | done later. */ | |
3459 | for (bs = root_bs->next; bs != NULL; bs = bs->next) | |
3460 | if (bs->stop) | |
3461 | break; | |
3462 | ||
d832cb68 | 3463 | need_remove_insert = 0; |
d983da9c DJ |
3464 | if (bs == NULL) |
3465 | for (bs = root_bs->next; bs != NULL; bs = bs->next) | |
3466 | if (!bs->stop | |
20874c92 | 3467 | && bs->breakpoint_at->owner |
d983da9c DJ |
3468 | && (bs->breakpoint_at->owner->type == bp_hardware_watchpoint |
3469 | || bs->breakpoint_at->owner->type == bp_read_watchpoint | |
3470 | || bs->breakpoint_at->owner->type == bp_access_watchpoint)) | |
3471 | { | |
a5606eee VP |
3472 | /* remove/insert can invalidate bs->breakpoint_at, if this |
3473 | location is no longer used by the watchpoint. Prevent | |
3474 | further code from trying to use it. */ | |
3475 | bs->breakpoint_at = NULL; | |
d832cb68 | 3476 | need_remove_insert = 1; |
d983da9c DJ |
3477 | } |
3478 | ||
d832cb68 DD |
3479 | if (need_remove_insert) |
3480 | { | |
3481 | remove_breakpoints (); | |
3482 | insert_breakpoints (); | |
3483 | } | |
3484 | ||
d983da9c | 3485 | return root_bs->next; |
c906108c SS |
3486 | } |
3487 | \f | |
3488 | /* Tell what to do about this bpstat. */ | |
3489 | struct bpstat_what | |
fba45db2 | 3490 | bpstat_what (bpstat bs) |
c906108c SS |
3491 | { |
3492 | /* Classify each bpstat as one of the following. */ | |
c5aa993b JM |
3493 | enum class |
3494 | { | |
3495 | /* This bpstat element has no effect on the main_action. */ | |
3496 | no_effect = 0, | |
3497 | ||
3498 | /* There was a watchpoint, stop but don't print. */ | |
3499 | wp_silent, | |
c906108c | 3500 | |
c5aa993b JM |
3501 | /* There was a watchpoint, stop and print. */ |
3502 | wp_noisy, | |
c906108c | 3503 | |
c5aa993b JM |
3504 | /* There was a breakpoint but we're not stopping. */ |
3505 | bp_nostop, | |
c906108c | 3506 | |
c5aa993b JM |
3507 | /* There was a breakpoint, stop but don't print. */ |
3508 | bp_silent, | |
c906108c | 3509 | |
c5aa993b JM |
3510 | /* There was a breakpoint, stop and print. */ |
3511 | bp_noisy, | |
c906108c | 3512 | |
c5aa993b JM |
3513 | /* We hit the longjmp breakpoint. */ |
3514 | long_jump, | |
c906108c | 3515 | |
c5aa993b JM |
3516 | /* We hit the longjmp_resume breakpoint. */ |
3517 | long_resume, | |
c906108c | 3518 | |
c5aa993b JM |
3519 | /* We hit the step_resume breakpoint. */ |
3520 | step_resume, | |
c906108c | 3521 | |
c5aa993b JM |
3522 | /* We hit the shared library event breakpoint. */ |
3523 | shlib_event, | |
c906108c | 3524 | |
4efc6507 DE |
3525 | /* We hit the jit event breakpoint. */ |
3526 | jit_event, | |
3527 | ||
c5aa993b JM |
3528 | /* This is just used to count how many enums there are. */ |
3529 | class_last | |
c906108c SS |
3530 | }; |
3531 | ||
3532 | /* Here is the table which drives this routine. So that we can | |
3533 | format it pretty, we define some abbreviations for the | |
3534 | enum bpstat_what codes. */ | |
3535 | #define kc BPSTAT_WHAT_KEEP_CHECKING | |
3536 | #define ss BPSTAT_WHAT_STOP_SILENT | |
3537 | #define sn BPSTAT_WHAT_STOP_NOISY | |
3538 | #define sgl BPSTAT_WHAT_SINGLE | |
3539 | #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME | |
3540 | #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME | |
c906108c | 3541 | #define sr BPSTAT_WHAT_STEP_RESUME |
c906108c | 3542 | #define shl BPSTAT_WHAT_CHECK_SHLIBS |
4efc6507 | 3543 | #define jit BPSTAT_WHAT_CHECK_JIT |
c906108c SS |
3544 | |
3545 | /* "Can't happen." Might want to print an error message. | |
3546 | abort() is not out of the question, but chances are GDB is just | |
3547 | a bit confused, not unusable. */ | |
3548 | #define err BPSTAT_WHAT_STOP_NOISY | |
3549 | ||
3550 | /* Given an old action and a class, come up with a new action. */ | |
3551 | /* One interesting property of this table is that wp_silent is the same | |
3552 | as bp_silent and wp_noisy is the same as bp_noisy. That is because | |
3553 | after stopping, the check for whether to step over a breakpoint | |
3554 | (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without | |
53a5351d JM |
3555 | reference to how we stopped. We retain separate wp_silent and |
3556 | bp_silent codes in case we want to change that someday. | |
43ff13b4 JM |
3557 | |
3558 | Another possibly interesting property of this table is that | |
3559 | there's a partial ordering, priority-like, of the actions. Once | |
3560 | you've decided that some action is appropriate, you'll never go | |
3561 | back and decide something of a lower priority is better. The | |
3562 | ordering is: | |
3563 | ||
4efc6507 DE |
3564 | kc < jit clr sgl shl slr sn sr ss |
3565 | sgl < jit shl slr sn sr ss | |
3566 | slr < jit err shl sn sr ss | |
3567 | clr < jit err shl sn sr ss | |
3568 | ss < jit shl sn sr | |
3569 | sn < jit shl sr | |
3570 | jit < shl sr | |
d81191fc | 3571 | shl < sr |
4d5b2cd7 | 3572 | sr < |
c5aa993b | 3573 | |
43ff13b4 JM |
3574 | What I think this means is that we don't need a damned table |
3575 | here. If you just put the rows and columns in the right order, | |
3576 | it'd look awfully regular. We could simply walk the bpstat list | |
3577 | and choose the highest priority action we find, with a little | |
78b6a731 | 3578 | logic to handle the 'err' cases. */ |
c906108c SS |
3579 | |
3580 | /* step_resume entries: a step resume breakpoint overrides another | |
3581 | breakpoint of signal handling (see comment in wait_for_inferior | |
fcf70625 | 3582 | at where we set the step_resume breakpoint). */ |
c906108c SS |
3583 | |
3584 | static const enum bpstat_what_main_action | |
c5aa993b JM |
3585 | table[(int) class_last][(int) BPSTAT_WHAT_LAST] = |
3586 | { | |
3587 | /* old action */ | |
4efc6507 DE |
3588 | /* kc ss sn sgl slr clr sr shl jit */ |
3589 | /* no_effect */ {kc, ss, sn, sgl, slr, clr, sr, shl, jit}, | |
3590 | /* wp_silent */ {ss, ss, sn, ss, ss, ss, sr, shl, jit}, | |
3591 | /* wp_noisy */ {sn, sn, sn, sn, sn, sn, sr, shl, jit}, | |
3592 | /* bp_nostop */ {sgl, ss, sn, sgl, slr, slr, sr, shl, jit}, | |
3593 | /* bp_silent */ {ss, ss, sn, ss, ss, ss, sr, shl, jit}, | |
3594 | /* bp_noisy */ {sn, sn, sn, sn, sn, sn, sr, shl, jit}, | |
3595 | /* long_jump */ {slr, ss, sn, slr, slr, err, sr, shl, jit}, | |
3596 | /* long_resume */ {clr, ss, sn, err, err, err, sr, shl, jit}, | |
3597 | /* step_resume */ {sr, sr, sr, sr, sr, sr, sr, sr, sr }, | |
3598 | /* shlib */ {shl, shl, shl, shl, shl, shl, sr, shl, shl}, | |
3599 | /* jit_event */ {jit, jit, jit, jit, jit, jit, sr, jit, jit} | |
c5aa993b | 3600 | }; |
c906108c SS |
3601 | |
3602 | #undef kc | |
3603 | #undef ss | |
3604 | #undef sn | |
3605 | #undef sgl | |
3606 | #undef slr | |
3607 | #undef clr | |
c906108c SS |
3608 | #undef err |
3609 | #undef sr | |
3610 | #undef ts | |
3611 | #undef shl | |
4efc6507 | 3612 | #undef jit |
c906108c SS |
3613 | enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING; |
3614 | struct bpstat_what retval; | |
3615 | ||
3616 | retval.call_dummy = 0; | |
3617 | for (; bs != NULL; bs = bs->next) | |
3618 | { | |
3619 | enum class bs_class = no_effect; | |
3620 | if (bs->breakpoint_at == NULL) | |
3621 | /* I suspect this can happen if it was a momentary breakpoint | |
3622 | which has since been deleted. */ | |
3623 | continue; | |
20874c92 VP |
3624 | if (bs->breakpoint_at->owner == NULL) |
3625 | bs_class = bp_nostop; | |
3626 | else | |
4f8d1dc6 | 3627 | switch (bs->breakpoint_at->owner->type) |
c906108c SS |
3628 | { |
3629 | case bp_none: | |
3630 | continue; | |
3631 | ||
3632 | case bp_breakpoint: | |
3633 | case bp_hardware_breakpoint: | |
3634 | case bp_until: | |
3635 | case bp_finish: | |
3636 | if (bs->stop) | |
3637 | { | |
3638 | if (bs->print) | |
3639 | bs_class = bp_noisy; | |
3640 | else | |
3641 | bs_class = bp_silent; | |
3642 | } | |
3643 | else | |
3644 | bs_class = bp_nostop; | |
3645 | break; | |
3646 | case bp_watchpoint: | |
3647 | case bp_hardware_watchpoint: | |
3648 | case bp_read_watchpoint: | |
3649 | case bp_access_watchpoint: | |
3650 | if (bs->stop) | |
3651 | { | |
3652 | if (bs->print) | |
3653 | bs_class = wp_noisy; | |
3654 | else | |
3655 | bs_class = wp_silent; | |
3656 | } | |
3657 | else | |
53a5351d JM |
3658 | /* There was a watchpoint, but we're not stopping. |
3659 | This requires no further action. */ | |
c906108c SS |
3660 | bs_class = no_effect; |
3661 | break; | |
3662 | case bp_longjmp: | |
3663 | bs_class = long_jump; | |
3664 | break; | |
3665 | case bp_longjmp_resume: | |
3666 | bs_class = long_resume; | |
3667 | break; | |
3668 | case bp_step_resume: | |
3669 | if (bs->stop) | |
3670 | { | |
3671 | bs_class = step_resume; | |
3672 | } | |
3673 | else | |
3674 | /* It is for the wrong frame. */ | |
3675 | bs_class = bp_nostop; | |
3676 | break; | |
c906108c SS |
3677 | case bp_watchpoint_scope: |
3678 | bs_class = bp_nostop; | |
3679 | break; | |
c5aa993b JM |
3680 | case bp_shlib_event: |
3681 | bs_class = shlib_event; | |
3682 | break; | |
4efc6507 DE |
3683 | case bp_jit_event: |
3684 | bs_class = jit_event; | |
3685 | break; | |
c4093a6a | 3686 | case bp_thread_event: |
1900040c | 3687 | case bp_overlay_event: |
0fd8e87f | 3688 | case bp_longjmp_master: |
c4093a6a JM |
3689 | bs_class = bp_nostop; |
3690 | break; | |
ce78b96d | 3691 | case bp_catchpoint: |
c5aa993b JM |
3692 | if (bs->stop) |
3693 | { | |
3694 | if (bs->print) | |
3695 | bs_class = bp_noisy; | |
3696 | else | |
3697 | bs_class = bp_silent; | |
3698 | } | |
3699 | else | |
53a5351d JM |
3700 | /* There was a catchpoint, but we're not stopping. |
3701 | This requires no further action. */ | |
c5aa993b JM |
3702 | bs_class = no_effect; |
3703 | break; | |
c906108c | 3704 | case bp_call_dummy: |
53a5351d JM |
3705 | /* Make sure the action is stop (silent or noisy), |
3706 | so infrun.c pops the dummy frame. */ | |
c906108c SS |
3707 | bs_class = bp_silent; |
3708 | retval.call_dummy = 1; | |
3709 | break; | |
1042e4c0 SS |
3710 | case bp_tracepoint: |
3711 | /* Tracepoint hits should not be reported back to GDB, and | |
3712 | if one got through somehow, it should have been filtered | |
3713 | out already. */ | |
3714 | internal_error (__FILE__, __LINE__, | |
3715 | _("bpstat_what: bp_tracepoint encountered")); | |
3716 | break; | |
c906108c | 3717 | } |
c5aa993b | 3718 | current_action = table[(int) bs_class][(int) current_action]; |
c906108c SS |
3719 | } |
3720 | retval.main_action = current_action; | |
3721 | return retval; | |
3722 | } | |
3723 | ||
3724 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
3725 | without hardware support). This isn't related to a specific bpstat, | |
3726 | just to things like whether watchpoints are set. */ | |
3727 | ||
c5aa993b | 3728 | int |
fba45db2 | 3729 | bpstat_should_step (void) |
c906108c SS |
3730 | { |
3731 | struct breakpoint *b; | |
3732 | ALL_BREAKPOINTS (b) | |
717a8278 | 3733 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 3734 | return 1; |
c906108c SS |
3735 | return 0; |
3736 | } | |
3737 | ||
c906108c | 3738 | \f |
c5aa993b | 3739 | |
0d381245 VP |
3740 | static void print_breakpoint_location (struct breakpoint *b, |
3741 | struct bp_location *loc, | |
3742 | char *wrap_indent, | |
3743 | struct ui_stream *stb) | |
3744 | { | |
6c95b8df PA |
3745 | struct cleanup *old_chain = save_current_program_space (); |
3746 | ||
3747 | if (loc != NULL) | |
3748 | set_current_program_space (loc->pspace); | |
3749 | ||
0d381245 VP |
3750 | if (b->source_file) |
3751 | { | |
3752 | struct symbol *sym | |
3753 | = find_pc_sect_function (loc->address, loc->section); | |
3754 | if (sym) | |
3755 | { | |
3756 | ui_out_text (uiout, "in "); | |
3757 | ui_out_field_string (uiout, "func", | |
3758 | SYMBOL_PRINT_NAME (sym)); | |
3759 | ui_out_wrap_hint (uiout, wrap_indent); | |
3760 | ui_out_text (uiout, " at "); | |
3761 | } | |
3762 | ui_out_field_string (uiout, "file", b->source_file); | |
3763 | ui_out_text (uiout, ":"); | |
3764 | ||
3765 | if (ui_out_is_mi_like_p (uiout)) | |
3766 | { | |
3767 | struct symtab_and_line sal = find_pc_line (loc->address, 0); | |
3768 | char *fullname = symtab_to_fullname (sal.symtab); | |
3769 | ||
3770 | if (fullname) | |
3771 | ui_out_field_string (uiout, "fullname", fullname); | |
3772 | } | |
3773 | ||
3774 | ui_out_field_int (uiout, "line", b->line_number); | |
3775 | } | |
3776 | else if (!b->loc) | |
3777 | { | |
3778 | ui_out_field_string (uiout, "pending", b->addr_string); | |
3779 | } | |
3780 | else | |
3781 | { | |
3782 | print_address_symbolic (loc->address, stb->stream, demangle, ""); | |
3783 | ui_out_field_stream (uiout, "at", stb); | |
3784 | } | |
6c95b8df PA |
3785 | |
3786 | do_cleanups (old_chain); | |
0d381245 VP |
3787 | } |
3788 | ||
c4093a6a | 3789 | /* Print B to gdb_stdout. */ |
c906108c | 3790 | static void |
0d381245 VP |
3791 | print_one_breakpoint_location (struct breakpoint *b, |
3792 | struct bp_location *loc, | |
3793 | int loc_number, | |
a6d9a66e | 3794 | struct bp_location **last_loc, |
6c95b8df PA |
3795 | int print_address_bits, |
3796 | int allflag) | |
c906108c | 3797 | { |
52f0bd74 AC |
3798 | struct command_line *l; |
3799 | struct symbol *sym; | |
c4093a6a JM |
3800 | struct ep_type_description |
3801 | { | |
3802 | enum bptype type; | |
3803 | char *description; | |
3804 | }; | |
3805 | static struct ep_type_description bptypes[] = | |
c906108c | 3806 | { |
c5aa993b JM |
3807 | {bp_none, "?deleted?"}, |
3808 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 3809 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
3810 | {bp_until, "until"}, |
3811 | {bp_finish, "finish"}, | |
3812 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 3813 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
3814 | {bp_read_watchpoint, "read watchpoint"}, |
3815 | {bp_access_watchpoint, "acc watchpoint"}, | |
3816 | {bp_longjmp, "longjmp"}, | |
3817 | {bp_longjmp_resume, "longjmp resume"}, | |
3818 | {bp_step_resume, "step resume"}, | |
c5aa993b JM |
3819 | {bp_watchpoint_scope, "watchpoint scope"}, |
3820 | {bp_call_dummy, "call dummy"}, | |
3821 | {bp_shlib_event, "shlib events"}, | |
c4093a6a | 3822 | {bp_thread_event, "thread events"}, |
1900040c | 3823 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 3824 | {bp_longjmp_master, "longjmp master"}, |
ce78b96d | 3825 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 3826 | {bp_tracepoint, "tracepoint"}, |
4efc6507 | 3827 | {bp_jit_event, "jit events"}, |
c5aa993b | 3828 | }; |
c4093a6a | 3829 | |
c2c6d25f | 3830 | static char bpenables[] = "nynny"; |
c906108c | 3831 | char wrap_indent[80]; |
8b93c638 JM |
3832 | struct ui_stream *stb = ui_out_stream_new (uiout); |
3833 | struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb); | |
3b31d625 | 3834 | struct cleanup *bkpt_chain; |
c906108c | 3835 | |
0d381245 VP |
3836 | int header_of_multiple = 0; |
3837 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
3838 | struct value_print_options opts; |
3839 | ||
3840 | get_user_print_options (&opts); | |
0d381245 VP |
3841 | |
3842 | gdb_assert (!loc || loc_number != 0); | |
3843 | /* See comment in print_one_breakpoint concerning | |
3844 | treatment of breakpoints with single disabled | |
3845 | location. */ | |
3846 | if (loc == NULL | |
3847 | && (b->loc != NULL | |
3848 | && (b->loc->next != NULL || !b->loc->enabled))) | |
3849 | header_of_multiple = 1; | |
3850 | if (loc == NULL) | |
3851 | loc = b->loc; | |
3852 | ||
c4093a6a | 3853 | annotate_record (); |
3b31d625 | 3854 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); |
c4093a6a JM |
3855 | |
3856 | /* 1 */ | |
3857 | annotate_field (0); | |
0d381245 VP |
3858 | if (part_of_multiple) |
3859 | { | |
3860 | char *formatted; | |
0c6773c1 | 3861 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
3862 | ui_out_field_string (uiout, "number", formatted); |
3863 | xfree (formatted); | |
3864 | } | |
3865 | else | |
3866 | { | |
3867 | ui_out_field_int (uiout, "number", b->number); | |
3868 | } | |
c4093a6a JM |
3869 | |
3870 | /* 2 */ | |
3871 | annotate_field (1); | |
0d381245 VP |
3872 | if (part_of_multiple) |
3873 | ui_out_field_skip (uiout, "type"); | |
3874 | else | |
3875 | { | |
3876 | if (((int) b->type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
3877 | || ((int) b->type != bptypes[(int) b->type].type)) | |
3878 | internal_error (__FILE__, __LINE__, | |
3879 | _("bptypes table does not describe type #%d."), | |
3880 | (int) b->type); | |
3881 | ui_out_field_string (uiout, "type", bptypes[(int) b->type].description); | |
3882 | } | |
c4093a6a JM |
3883 | |
3884 | /* 3 */ | |
3885 | annotate_field (2); | |
0d381245 VP |
3886 | if (part_of_multiple) |
3887 | ui_out_field_skip (uiout, "disp"); | |
3888 | else | |
2cec12e5 | 3889 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 3890 | |
c4093a6a JM |
3891 | |
3892 | /* 4 */ | |
3893 | annotate_field (3); | |
0d381245 | 3894 | if (part_of_multiple) |
54e52265 | 3895 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 3896 | else |
54e52265 VP |
3897 | ui_out_field_fmt (uiout, "enabled", "%c", |
3898 | bpenables[(int) b->enable_state]); | |
3899 | ui_out_spaces (uiout, 2); | |
0d381245 | 3900 | |
c4093a6a JM |
3901 | |
3902 | /* 5 and 6 */ | |
3903 | strcpy (wrap_indent, " "); | |
79a45b7d | 3904 | if (opts.addressprint) |
75ac9d7b | 3905 | { |
a6d9a66e | 3906 | if (print_address_bits <= 32) |
75ac9d7b MS |
3907 | strcat (wrap_indent, " "); |
3908 | else | |
3909 | strcat (wrap_indent, " "); | |
3910 | } | |
c906108c | 3911 | |
3086aeae | 3912 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 VP |
3913 | { |
3914 | /* Although the print_one can possibly print | |
3915 | all locations, calling it here is not likely | |
3916 | to get any nice result. So, make sure there's | |
3917 | just one location. */ | |
3918 | gdb_assert (b->loc == NULL || b->loc->next == NULL); | |
a6d9a66e | 3919 | b->ops->print_one (b, last_loc); |
0d381245 | 3920 | } |
3086aeae DJ |
3921 | else |
3922 | switch (b->type) | |
3923 | { | |
3924 | case bp_none: | |
3925 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 3926 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 3927 | break; |
c906108c | 3928 | |
3086aeae DJ |
3929 | case bp_watchpoint: |
3930 | case bp_hardware_watchpoint: | |
3931 | case bp_read_watchpoint: | |
3932 | case bp_access_watchpoint: | |
3933 | /* Field 4, the address, is omitted (which makes the columns | |
3934 | not line up too nicely with the headers, but the effect | |
3935 | is relatively readable). */ | |
79a45b7d | 3936 | if (opts.addressprint) |
3086aeae DJ |
3937 | ui_out_field_skip (uiout, "addr"); |
3938 | annotate_field (5); | |
fa8a61dc | 3939 | ui_out_field_string (uiout, "what", b->exp_string); |
3086aeae DJ |
3940 | break; |
3941 | ||
3086aeae DJ |
3942 | case bp_breakpoint: |
3943 | case bp_hardware_breakpoint: | |
3944 | case bp_until: | |
3945 | case bp_finish: | |
3946 | case bp_longjmp: | |
3947 | case bp_longjmp_resume: | |
3948 | case bp_step_resume: | |
3086aeae DJ |
3949 | case bp_watchpoint_scope: |
3950 | case bp_call_dummy: | |
3951 | case bp_shlib_event: | |
3952 | case bp_thread_event: | |
3953 | case bp_overlay_event: | |
0fd8e87f | 3954 | case bp_longjmp_master: |
1042e4c0 | 3955 | case bp_tracepoint: |
4efc6507 | 3956 | case bp_jit_event: |
79a45b7d | 3957 | if (opts.addressprint) |
3086aeae DJ |
3958 | { |
3959 | annotate_field (4); | |
54e52265 | 3960 | if (header_of_multiple) |
0d381245 | 3961 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 3962 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 3963 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 3964 | else |
5af949e3 UW |
3965 | ui_out_field_core_addr (uiout, "addr", |
3966 | loc->gdbarch, loc->address); | |
3086aeae DJ |
3967 | } |
3968 | annotate_field (5); | |
0d381245 VP |
3969 | if (!header_of_multiple) |
3970 | print_breakpoint_location (b, loc, wrap_indent, stb); | |
3971 | if (b->loc) | |
a6d9a66e | 3972 | *last_loc = b->loc; |
3086aeae DJ |
3973 | break; |
3974 | } | |
c906108c | 3975 | |
6c95b8df PA |
3976 | |
3977 | /* For backward compatibility, don't display inferiors unless there | |
3978 | are several. */ | |
3979 | if (loc != NULL | |
3980 | && !header_of_multiple | |
3981 | && (allflag | |
3982 | || (!gdbarch_has_global_breakpoints (target_gdbarch) | |
3983 | && (number_of_program_spaces () > 1 | |
3984 | || number_of_inferiors () > 1) | |
3985 | && loc->owner->type != bp_catchpoint))) | |
3986 | { | |
3987 | struct inferior *inf; | |
3988 | int first = 1; | |
3989 | ||
3990 | for (inf = inferior_list; inf != NULL; inf = inf->next) | |
3991 | { | |
3992 | if (inf->pspace == loc->pspace) | |
3993 | { | |
3994 | if (first) | |
3995 | { | |
3996 | first = 0; | |
3997 | ui_out_text (uiout, " inf "); | |
3998 | } | |
3999 | else | |
4000 | ui_out_text (uiout, ", "); | |
4001 | ui_out_text (uiout, plongest (inf->num)); | |
4002 | } | |
4003 | } | |
4004 | } | |
4005 | ||
4a306c9a | 4006 | if (!part_of_multiple) |
c4093a6a | 4007 | { |
4a306c9a JB |
4008 | if (b->thread != -1) |
4009 | { | |
4010 | /* FIXME: This seems to be redundant and lost here; see the | |
4011 | "stop only in" line a little further down. */ | |
4012 | ui_out_text (uiout, " thread "); | |
4013 | ui_out_field_int (uiout, "thread", b->thread); | |
4014 | } | |
4015 | else if (b->task != 0) | |
4016 | { | |
4017 | ui_out_text (uiout, " task "); | |
4018 | ui_out_field_int (uiout, "task", b->task); | |
4019 | } | |
c4093a6a JM |
4020 | } |
4021 | ||
8b93c638 | 4022 | ui_out_text (uiout, "\n"); |
c4093a6a | 4023 | |
0d381245 | 4024 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
4025 | { |
4026 | annotate_field (6); | |
8b93c638 | 4027 | ui_out_text (uiout, "\tstop only in stack frame at "); |
818dd999 AC |
4028 | /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside |
4029 | the frame ID. */ | |
5af949e3 UW |
4030 | ui_out_field_core_addr (uiout, "frame", |
4031 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 4032 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
4033 | } |
4034 | ||
0d381245 | 4035 | if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b)) |
c4093a6a | 4036 | { |
f7f9143b JB |
4037 | /* We do not print the condition for Ada exception catchpoints |
4038 | because the condition is an internal implementation detail | |
4039 | that we do not want to expose to the user. */ | |
c4093a6a | 4040 | annotate_field (7); |
1042e4c0 SS |
4041 | if (b->type == bp_tracepoint) |
4042 | ui_out_text (uiout, "\ttrace only if "); | |
4043 | else | |
4044 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 JJ |
4045 | ui_out_field_string (uiout, "cond", b->cond_string); |
4046 | ui_out_text (uiout, "\n"); | |
4047 | } | |
4048 | ||
0d381245 | 4049 | if (!part_of_multiple && b->thread != -1) |
c4093a6a JM |
4050 | { |
4051 | /* FIXME should make an annotation for this */ | |
8b93c638 JM |
4052 | ui_out_text (uiout, "\tstop only in thread "); |
4053 | ui_out_field_int (uiout, "thread", b->thread); | |
4054 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
4055 | } |
4056 | ||
63c715c6 | 4057 | if (!part_of_multiple && b->hit_count) |
c4093a6a JM |
4058 | { |
4059 | /* FIXME should make an annotation for this */ | |
8b93c638 JM |
4060 | if (ep_is_catchpoint (b)) |
4061 | ui_out_text (uiout, "\tcatchpoint"); | |
4062 | else | |
4063 | ui_out_text (uiout, "\tbreakpoint"); | |
4064 | ui_out_text (uiout, " already hit "); | |
4065 | ui_out_field_int (uiout, "times", b->hit_count); | |
4066 | if (b->hit_count == 1) | |
4067 | ui_out_text (uiout, " time\n"); | |
4068 | else | |
4069 | ui_out_text (uiout, " times\n"); | |
c4093a6a JM |
4070 | } |
4071 | ||
fb40c209 AC |
4072 | /* Output the count also if it is zero, but only if this is |
4073 | mi. FIXME: Should have a better test for this. */ | |
9dc5e2a9 | 4074 | if (ui_out_is_mi_like_p (uiout)) |
63c715c6 | 4075 | if (!part_of_multiple && b->hit_count == 0) |
fb40c209 | 4076 | ui_out_field_int (uiout, "times", b->hit_count); |
8b93c638 | 4077 | |
0d381245 | 4078 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
4079 | { |
4080 | annotate_field (8); | |
8b93c638 JM |
4081 | ui_out_text (uiout, "\tignore next "); |
4082 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
4083 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 4084 | } |
059fb39f PM |
4085 | |
4086 | l = b->commands; | |
4087 | if (!part_of_multiple && l) | |
c4093a6a | 4088 | { |
3b31d625 EZ |
4089 | struct cleanup *script_chain; |
4090 | ||
c4093a6a | 4091 | annotate_field (9); |
3b31d625 | 4092 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 4093 | print_command_lines (uiout, l, 4); |
3b31d625 | 4094 | do_cleanups (script_chain); |
c4093a6a | 4095 | } |
d24317b4 | 4096 | |
1042e4c0 SS |
4097 | if (!part_of_multiple && b->pass_count) |
4098 | { | |
4099 | annotate_field (10); | |
4100 | ui_out_text (uiout, "\tpass count "); | |
4101 | ui_out_field_int (uiout, "pass", b->pass_count); | |
4102 | ui_out_text (uiout, " \n"); | |
4103 | } | |
4104 | ||
4105 | if (!part_of_multiple && b->step_count) | |
4106 | { | |
4107 | annotate_field (11); | |
4108 | ui_out_text (uiout, "\tstep count "); | |
4109 | ui_out_field_int (uiout, "step", b->step_count); | |
4110 | ui_out_text (uiout, " \n"); | |
4111 | } | |
4112 | ||
4113 | if (!part_of_multiple && b->actions) | |
4114 | { | |
4115 | struct action_line *action; | |
4116 | annotate_field (12); | |
4117 | for (action = b->actions; action; action = action->next) | |
4118 | { | |
4119 | ui_out_text (uiout, " A\t"); | |
4120 | ui_out_text (uiout, action->action); | |
4121 | ui_out_text (uiout, "\n"); | |
4122 | } | |
4123 | } | |
4124 | ||
d24317b4 VP |
4125 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
4126 | { | |
4127 | if (b->addr_string) | |
4128 | ui_out_field_string (uiout, "original-location", b->addr_string); | |
4129 | else if (b->exp_string) | |
4130 | ui_out_field_string (uiout, "original-location", b->exp_string); | |
4131 | } | |
4132 | ||
3b31d625 | 4133 | do_cleanups (bkpt_chain); |
8b93c638 | 4134 | do_cleanups (old_chain); |
c4093a6a | 4135 | } |
c5aa993b | 4136 | |
0d381245 VP |
4137 | static void |
4138 | print_one_breakpoint (struct breakpoint *b, | |
6c95b8df PA |
4139 | struct bp_location **last_loc, int print_address_bits, |
4140 | int allflag) | |
0d381245 | 4141 | { |
6c95b8df PA |
4142 | print_one_breakpoint_location (b, NULL, 0, last_loc, |
4143 | print_address_bits, allflag); | |
0d381245 VP |
4144 | |
4145 | /* If this breakpoint has custom print function, | |
4146 | it's already printed. Otherwise, print individual | |
4147 | locations, if any. */ | |
4148 | if (b->ops == NULL || b->ops->print_one == NULL) | |
4149 | { | |
4150 | /* If breakpoint has a single location that is | |
4151 | disabled, we print it as if it had | |
4152 | several locations, since otherwise it's hard to | |
4153 | represent "breakpoint enabled, location disabled" | |
a5606eee VP |
4154 | situation. |
4155 | Note that while hardware watchpoints have | |
4156 | several locations internally, that's no a property | |
4157 | exposed to user. */ | |
0d381245 | 4158 | if (b->loc |
a5606eee | 4159 | && !is_hardware_watchpoint (b) |
0d381245 | 4160 | && (b->loc->next || !b->loc->enabled) |
a5606eee | 4161 | && !ui_out_is_mi_like_p (uiout)) |
0d381245 VP |
4162 | { |
4163 | struct bp_location *loc; | |
4164 | int n = 1; | |
4165 | for (loc = b->loc; loc; loc = loc->next, ++n) | |
a6d9a66e | 4166 | print_one_breakpoint_location (b, loc, n, last_loc, |
6c95b8df | 4167 | print_address_bits, allflag); |
0d381245 VP |
4168 | } |
4169 | } | |
4170 | } | |
4171 | ||
a6d9a66e UW |
4172 | static int |
4173 | breakpoint_address_bits (struct breakpoint *b) | |
4174 | { | |
4175 | int print_address_bits = 0; | |
4176 | struct bp_location *loc; | |
4177 | ||
4178 | for (loc = b->loc; loc; loc = loc->next) | |
4179 | { | |
4180 | int addr_bit = gdbarch_addr_bit (b->gdbarch); | |
4181 | if (addr_bit > print_address_bits) | |
4182 | print_address_bits = addr_bit; | |
4183 | } | |
4184 | ||
4185 | return print_address_bits; | |
4186 | } | |
0d381245 | 4187 | |
c4093a6a JM |
4188 | struct captured_breakpoint_query_args |
4189 | { | |
4190 | int bnum; | |
4191 | }; | |
c5aa993b | 4192 | |
c4093a6a | 4193 | static int |
2b65245e | 4194 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
4195 | { |
4196 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 4197 | struct breakpoint *b; |
a6d9a66e | 4198 | struct bp_location *dummy_loc = NULL; |
c4093a6a JM |
4199 | ALL_BREAKPOINTS (b) |
4200 | { | |
4201 | if (args->bnum == b->number) | |
c5aa993b | 4202 | { |
a6d9a66e | 4203 | int print_address_bits = breakpoint_address_bits (b); |
6c95b8df | 4204 | print_one_breakpoint (b, &dummy_loc, print_address_bits, 0); |
c4093a6a | 4205 | return GDB_RC_OK; |
c5aa993b | 4206 | } |
c4093a6a JM |
4207 | } |
4208 | return GDB_RC_NONE; | |
4209 | } | |
c5aa993b | 4210 | |
c4093a6a | 4211 | enum gdb_rc |
ce43223b | 4212 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, char **error_message) |
c4093a6a JM |
4213 | { |
4214 | struct captured_breakpoint_query_args args; | |
4215 | args.bnum = bnum; | |
4216 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4217 | an error. */ | |
b0b13bb4 DJ |
4218 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
4219 | error_message, RETURN_MASK_ALL) < 0) | |
4220 | return GDB_RC_FAIL; | |
4221 | else | |
4222 | return GDB_RC_OK; | |
c4093a6a | 4223 | } |
c5aa993b | 4224 | |
7f3b0473 AC |
4225 | /* Return non-zero if B is user settable (breakpoints, watchpoints, |
4226 | catchpoints, et.al.). */ | |
4227 | ||
4228 | static int | |
4229 | user_settable_breakpoint (const struct breakpoint *b) | |
4230 | { | |
4231 | return (b->type == bp_breakpoint | |
ce78b96d | 4232 | || b->type == bp_catchpoint |
7f3b0473 | 4233 | || b->type == bp_hardware_breakpoint |
1042e4c0 | 4234 | || b->type == bp_tracepoint |
7f3b0473 AC |
4235 | || b->type == bp_watchpoint |
4236 | || b->type == bp_read_watchpoint | |
4237 | || b->type == bp_access_watchpoint | |
4238 | || b->type == bp_hardware_watchpoint); | |
4239 | } | |
4240 | ||
4241 | /* Print information on user settable breakpoint (watchpoint, etc) | |
4242 | number BNUM. If BNUM is -1 print all user settable breakpoints. | |
4243 | If ALLFLAG is non-zero, include non- user settable breakpoints. */ | |
c906108c | 4244 | |
c4093a6a | 4245 | static void |
fba45db2 | 4246 | breakpoint_1 (int bnum, int allflag) |
c4093a6a | 4247 | { |
52f0bd74 | 4248 | struct breakpoint *b; |
a6d9a66e | 4249 | struct bp_location *last_loc = NULL; |
7f3b0473 | 4250 | int nr_printable_breakpoints; |
3b31d625 | 4251 | struct cleanup *bkpttbl_chain; |
79a45b7d | 4252 | struct value_print_options opts; |
a6d9a66e | 4253 | int print_address_bits = 0; |
c4093a6a | 4254 | |
79a45b7d TT |
4255 | get_user_print_options (&opts); |
4256 | ||
a6d9a66e UW |
4257 | /* Compute the number of rows in the table, as well as the |
4258 | size required for address fields. */ | |
7f3b0473 AC |
4259 | nr_printable_breakpoints = 0; |
4260 | ALL_BREAKPOINTS (b) | |
4261 | if (bnum == -1 | |
4262 | || bnum == b->number) | |
4263 | { | |
4264 | if (allflag || user_settable_breakpoint (b)) | |
a6d9a66e UW |
4265 | { |
4266 | int addr_bit = breakpoint_address_bits (b); | |
4267 | if (addr_bit > print_address_bits) | |
4268 | print_address_bits = addr_bit; | |
4269 | ||
4270 | nr_printable_breakpoints++; | |
4271 | } | |
7f3b0473 AC |
4272 | } |
4273 | ||
79a45b7d | 4274 | if (opts.addressprint) |
3b31d625 EZ |
4275 | bkpttbl_chain |
4276 | = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints, | |
4277 | "BreakpointTable"); | |
8b93c638 | 4278 | else |
3b31d625 EZ |
4279 | bkpttbl_chain |
4280 | = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints, | |
4281 | "BreakpointTable"); | |
8b93c638 | 4282 | |
7f3b0473 | 4283 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
4284 | annotate_breakpoints_headers (); |
4285 | if (nr_printable_breakpoints > 0) | |
4286 | annotate_field (0); | |
0d381245 | 4287 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
4288 | if (nr_printable_breakpoints > 0) |
4289 | annotate_field (1); | |
4290 | ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */ | |
4291 | if (nr_printable_breakpoints > 0) | |
4292 | annotate_field (2); | |
4293 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ | |
4294 | if (nr_printable_breakpoints > 0) | |
4295 | annotate_field (3); | |
54e52265 | 4296 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 4297 | if (opts.addressprint) |
7f3b0473 | 4298 | { |
d7faa9e7 AC |
4299 | if (nr_printable_breakpoints > 0) |
4300 | annotate_field (4); | |
a6d9a66e | 4301 | if (print_address_bits <= 32) |
b25959ec | 4302 | ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */ |
7f3b0473 | 4303 | else |
b25959ec | 4304 | ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */ |
7f3b0473 | 4305 | } |
d7faa9e7 AC |
4306 | if (nr_printable_breakpoints > 0) |
4307 | annotate_field (5); | |
4308 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
4309 | ui_out_table_body (uiout); | |
4310 | if (nr_printable_breakpoints > 0) | |
4311 | annotate_breakpoints_table (); | |
7f3b0473 | 4312 | |
c4093a6a JM |
4313 | ALL_BREAKPOINTS (b) |
4314 | if (bnum == -1 | |
4315 | || bnum == b->number) | |
4316 | { | |
4317 | /* We only print out user settable breakpoints unless the | |
4318 | allflag is set. */ | |
7f3b0473 | 4319 | if (allflag || user_settable_breakpoint (b)) |
6c95b8df | 4320 | print_one_breakpoint (b, &last_loc, print_address_bits, allflag); |
c4093a6a JM |
4321 | } |
4322 | ||
3b31d625 | 4323 | do_cleanups (bkpttbl_chain); |
698384cd | 4324 | |
7f3b0473 | 4325 | if (nr_printable_breakpoints == 0) |
c906108c | 4326 | { |
8b93c638 JM |
4327 | if (bnum == -1) |
4328 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); | |
4329 | else | |
4330 | ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n", | |
4331 | bnum); | |
c906108c SS |
4332 | } |
4333 | else | |
c4093a6a | 4334 | { |
a6d9a66e UW |
4335 | if (last_loc && !server_command) |
4336 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 4337 | } |
c906108c | 4338 | |
c4093a6a JM |
4339 | /* FIXME? Should this be moved up so that it is only called when |
4340 | there have been breakpoints? */ | |
c906108c SS |
4341 | annotate_breakpoints_table_end (); |
4342 | } | |
4343 | ||
c906108c | 4344 | static void |
fba45db2 | 4345 | breakpoints_info (char *bnum_exp, int from_tty) |
c906108c SS |
4346 | { |
4347 | int bnum = -1; | |
4348 | ||
4349 | if (bnum_exp) | |
bb518678 | 4350 | bnum = parse_and_eval_long (bnum_exp); |
c906108c SS |
4351 | |
4352 | breakpoint_1 (bnum, 0); | |
4353 | } | |
4354 | ||
7a292a7a | 4355 | static void |
fba45db2 | 4356 | maintenance_info_breakpoints (char *bnum_exp, int from_tty) |
c906108c SS |
4357 | { |
4358 | int bnum = -1; | |
4359 | ||
4360 | if (bnum_exp) | |
bb518678 | 4361 | bnum = parse_and_eval_long (bnum_exp); |
c906108c SS |
4362 | |
4363 | breakpoint_1 (bnum, 1); | |
4364 | } | |
4365 | ||
0d381245 | 4366 | static int |
714835d5 | 4367 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 4368 | struct program_space *pspace, |
714835d5 | 4369 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
4370 | { |
4371 | struct bp_location *bl = b->loc; | |
4372 | for (; bl; bl = bl->next) | |
4373 | { | |
6c95b8df PA |
4374 | if (bl->pspace == pspace |
4375 | && bl->address == pc | |
0d381245 VP |
4376 | && (!overlay_debugging || bl->section == section)) |
4377 | return 1; | |
4378 | } | |
4379 | return 0; | |
4380 | } | |
4381 | ||
6c95b8df PA |
4382 | /* Print a message describing any breakpoints set at PC. This |
4383 | concerns with logical breakpoints, so we match program spaces, not | |
4384 | address spaces. */ | |
c906108c SS |
4385 | |
4386 | static void | |
6c95b8df PA |
4387 | describe_other_breakpoints (struct gdbarch *gdbarch, |
4388 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 4389 | struct obj_section *section, int thread) |
c906108c | 4390 | { |
52f0bd74 AC |
4391 | int others = 0; |
4392 | struct breakpoint *b; | |
c906108c SS |
4393 | |
4394 | ALL_BREAKPOINTS (b) | |
6c95b8df | 4395 | others += breakpoint_has_pc (b, pspace, pc, section); |
c906108c SS |
4396 | if (others > 0) |
4397 | { | |
a3f17187 AC |
4398 | if (others == 1) |
4399 | printf_filtered (_("Note: breakpoint ")); | |
4400 | else /* if (others == ???) */ | |
4401 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 4402 | ALL_BREAKPOINTS (b) |
6c95b8df | 4403 | if (breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
4404 | { |
4405 | others--; | |
4406 | printf_filtered ("%d", b->number); | |
4407 | if (b->thread == -1 && thread != -1) | |
4408 | printf_filtered (" (all threads)"); | |
4409 | else if (b->thread != -1) | |
4410 | printf_filtered (" (thread %d)", b->thread); | |
4411 | printf_filtered ("%s%s ", | |
059fb39f | 4412 | ((b->enable_state == bp_disabled |
8bea4e01 UW |
4413 | || b->enable_state == bp_call_disabled |
4414 | || b->enable_state == bp_startup_disabled) | |
0d381245 VP |
4415 | ? " (disabled)" |
4416 | : b->enable_state == bp_permanent | |
4417 | ? " (permanent)" | |
4418 | : ""), | |
4419 | (others > 1) ? "," | |
4420 | : ((others == 1) ? " and" : "")); | |
4421 | } | |
a3f17187 | 4422 | printf_filtered (_("also set at pc ")); |
5af949e3 | 4423 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
4424 | printf_filtered (".\n"); |
4425 | } | |
4426 | } | |
4427 | \f | |
4428 | /* Set the default place to put a breakpoint | |
4429 | for the `break' command with no arguments. */ | |
4430 | ||
4431 | void | |
6c95b8df PA |
4432 | set_default_breakpoint (int valid, struct program_space *pspace, |
4433 | CORE_ADDR addr, struct symtab *symtab, | |
fba45db2 | 4434 | int line) |
c906108c SS |
4435 | { |
4436 | default_breakpoint_valid = valid; | |
6c95b8df | 4437 | default_breakpoint_pspace = pspace; |
c906108c SS |
4438 | default_breakpoint_address = addr; |
4439 | default_breakpoint_symtab = symtab; | |
4440 | default_breakpoint_line = line; | |
4441 | } | |
4442 | ||
e4f237da KB |
4443 | /* Return true iff it is meaningful to use the address member of |
4444 | BPT. For some breakpoint types, the address member is irrelevant | |
4445 | and it makes no sense to attempt to compare it to other addresses | |
4446 | (or use it for any other purpose either). | |
4447 | ||
4448 | More specifically, each of the following breakpoint types will always | |
4449 | have a zero valued address and we don't want check_duplicates() to mark | |
4450 | breakpoints of any of these types to be a duplicate of an actual | |
4451 | breakpoint at address zero: | |
4452 | ||
4453 | bp_watchpoint | |
4454 | bp_hardware_watchpoint | |
4455 | bp_read_watchpoint | |
4456 | bp_access_watchpoint | |
fe798b75 | 4457 | bp_catchpoint */ |
e4f237da KB |
4458 | |
4459 | static int | |
4460 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
4461 | { | |
4462 | enum bptype type = bpt->type; | |
4463 | ||
4464 | return (type != bp_watchpoint | |
4465 | && type != bp_hardware_watchpoint | |
4466 | && type != bp_read_watchpoint | |
4467 | && type != bp_access_watchpoint | |
fe798b75 | 4468 | && type != bp_catchpoint); |
e4f237da KB |
4469 | } |
4470 | ||
6c95b8df PA |
4471 | /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the |
4472 | same breakpoint location. In most targets, this can only be true | |
4473 | if ASPACE1 matches ASPACE2. On targets that have global | |
4474 | breakpoints, the address space doesn't really matter. */ | |
4475 | ||
4476 | static int | |
4477 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, | |
4478 | struct address_space *aspace2, CORE_ADDR addr2) | |
4479 | { | |
4480 | return ((gdbarch_has_global_breakpoints (target_gdbarch) | |
4481 | || aspace1 == aspace2) | |
4482 | && addr1 == addr2); | |
4483 | } | |
4484 | ||
9f60f21b | 4485 | /* Rescan breakpoints at the same address and section as BPT, |
c906108c | 4486 | marking the first one as "first" and any others as "duplicates". |
c2c6d25f | 4487 | This is so that the bpt instruction is only inserted once. |
9f60f21b JB |
4488 | If we have a permanent breakpoint at the same place as BPT, make |
4489 | that one the official one, and the rest as duplicates. */ | |
c906108c SS |
4490 | |
4491 | static void | |
6c95b8df PA |
4492 | check_duplicates_for (struct address_space *aspace, |
4493 | CORE_ADDR address, | |
4494 | struct obj_section *section) | |
c906108c | 4495 | { |
075f6582 | 4496 | struct bp_location *b; |
52f0bd74 | 4497 | int count = 0; |
075f6582 | 4498 | struct bp_location *perm_bp = 0; |
c906108c | 4499 | |
075f6582 DJ |
4500 | ALL_BP_LOCATIONS (b) |
4501 | if (b->owner->enable_state != bp_disabled | |
075f6582 | 4502 | && b->owner->enable_state != bp_call_disabled |
8bea4e01 | 4503 | && b->owner->enable_state != bp_startup_disabled |
0d381245 VP |
4504 | && b->enabled |
4505 | && !b->shlib_disabled | |
075f6582 | 4506 | && (!overlay_debugging || b->section == section) |
6c95b8df PA |
4507 | && breakpoint_address_is_meaningful (b->owner) |
4508 | && breakpoint_address_match (b->pspace->aspace, b->address, | |
4509 | aspace, address)) | |
c5aa993b | 4510 | { |
c2c6d25f | 4511 | /* Have we found a permanent breakpoint? */ |
075f6582 | 4512 | if (b->owner->enable_state == bp_permanent) |
c2c6d25f JM |
4513 | { |
4514 | perm_bp = b; | |
4515 | break; | |
4516 | } | |
4517 | ||
c5aa993b | 4518 | count++; |
075f6582 | 4519 | b->duplicate = count > 1; |
c5aa993b | 4520 | } |
c2c6d25f JM |
4521 | |
4522 | /* If we found a permanent breakpoint at this address, go over the | |
aae64587 PA |
4523 | list again and declare all the other breakpoints there (except |
4524 | other permanent breakpoints) to be the duplicates. */ | |
c2c6d25f JM |
4525 | if (perm_bp) |
4526 | { | |
075f6582 | 4527 | perm_bp->duplicate = 0; |
c2c6d25f JM |
4528 | |
4529 | /* Permanent breakpoint should always be inserted. */ | |
075f6582 | 4530 | if (! perm_bp->inserted) |
8e65ff28 | 4531 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 AC |
4532 | _("allegedly permanent breakpoint is not " |
4533 | "actually inserted")); | |
c2c6d25f | 4534 | |
075f6582 | 4535 | ALL_BP_LOCATIONS (b) |
c2c6d25f JM |
4536 | if (b != perm_bp) |
4537 | { | |
aae64587 PA |
4538 | if (b->owner->enable_state != bp_permanent |
4539 | && b->owner->enable_state != bp_disabled | |
075f6582 | 4540 | && b->owner->enable_state != bp_call_disabled |
8bea4e01 | 4541 | && b->owner->enable_state != bp_startup_disabled |
6c95b8df PA |
4542 | && b->enabled && !b->shlib_disabled |
4543 | && breakpoint_address_is_meaningful (b->owner) | |
4544 | && breakpoint_address_match (b->pspace->aspace, b->address, | |
4545 | aspace, address) | |
4546 | && (!overlay_debugging || b->section == section)) | |
075f6582 DJ |
4547 | { |
4548 | if (b->inserted) | |
4549 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 AC |
4550 | _("another breakpoint was inserted on top of " |
4551 | "a permanent breakpoint")); | |
075f6582 DJ |
4552 | |
4553 | b->duplicate = 1; | |
4554 | } | |
c2c6d25f JM |
4555 | } |
4556 | } | |
c906108c SS |
4557 | } |
4558 | ||
0d381245 VP |
4559 | static void |
4560 | check_duplicates (struct breakpoint *bpt) | |
4561 | { | |
4562 | struct bp_location *bl = bpt->loc; | |
4563 | ||
4564 | if (! breakpoint_address_is_meaningful (bpt)) | |
4565 | return; | |
4566 | ||
4567 | for (; bl; bl = bl->next) | |
6c95b8df | 4568 | check_duplicates_for (bl->pspace->aspace, bl->address, bl->section); |
0d381245 VP |
4569 | } |
4570 | ||
76897487 KB |
4571 | static void |
4572 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
4573 | int bnum, int have_bnum) | |
4574 | { | |
4575 | char astr1[40]; | |
4576 | char astr2[40]; | |
4577 | ||
bb599908 PH |
4578 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
4579 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 4580 | if (have_bnum) |
8a3fe4f8 | 4581 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
4582 | bnum, astr1, astr2); |
4583 | else | |
8a3fe4f8 | 4584 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
4585 | } |
4586 | ||
4587 | /* Adjust a breakpoint's address to account for architectural constraints | |
4588 | on breakpoint placement. Return the adjusted address. Note: Very | |
4589 | few targets require this kind of adjustment. For most targets, | |
4590 | this function is simply the identity function. */ | |
4591 | ||
4592 | static CORE_ADDR | |
a6d9a66e UW |
4593 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
4594 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 4595 | { |
a6d9a66e | 4596 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
4597 | { |
4598 | /* Very few targets need any kind of breakpoint adjustment. */ | |
4599 | return bpaddr; | |
4600 | } | |
88f7da05 KB |
4601 | else if (bptype == bp_watchpoint |
4602 | || bptype == bp_hardware_watchpoint | |
4603 | || bptype == bp_read_watchpoint | |
4604 | || bptype == bp_access_watchpoint | |
fe798b75 | 4605 | || bptype == bp_catchpoint) |
88f7da05 KB |
4606 | { |
4607 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
4608 | have their addresses modified. */ | |
4609 | return bpaddr; | |
4610 | } | |
76897487 KB |
4611 | else |
4612 | { | |
4613 | CORE_ADDR adjusted_bpaddr; | |
4614 | ||
4615 | /* Some targets have architectural constraints on the placement | |
4616 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 4617 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
4618 | |
4619 | /* An adjusted breakpoint address can significantly alter | |
4620 | a user's expectations. Print a warning if an adjustment | |
4621 | is required. */ | |
4622 | if (adjusted_bpaddr != bpaddr) | |
4623 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
4624 | ||
4625 | return adjusted_bpaddr; | |
4626 | } | |
4627 | } | |
4628 | ||
7cc221ef DJ |
4629 | /* Allocate a struct bp_location. */ |
4630 | ||
26bb91f3 | 4631 | static struct bp_location * |
39d61571 | 4632 | allocate_bp_location (struct breakpoint *bpt) |
7cc221ef DJ |
4633 | { |
4634 | struct bp_location *loc, *loc_p; | |
4635 | ||
4636 | loc = xmalloc (sizeof (struct bp_location)); | |
4637 | memset (loc, 0, sizeof (*loc)); | |
4638 | ||
e049a4b5 | 4639 | loc->owner = bpt; |
511a6cd4 | 4640 | loc->cond = NULL; |
0d381245 VP |
4641 | loc->shlib_disabled = 0; |
4642 | loc->enabled = 1; | |
e049a4b5 | 4643 | |
39d61571 | 4644 | switch (bpt->type) |
e049a4b5 DJ |
4645 | { |
4646 | case bp_breakpoint: | |
1042e4c0 | 4647 | case bp_tracepoint: |
e049a4b5 DJ |
4648 | case bp_until: |
4649 | case bp_finish: | |
4650 | case bp_longjmp: | |
4651 | case bp_longjmp_resume: | |
4652 | case bp_step_resume: | |
e049a4b5 DJ |
4653 | case bp_watchpoint_scope: |
4654 | case bp_call_dummy: | |
4655 | case bp_shlib_event: | |
4656 | case bp_thread_event: | |
4657 | case bp_overlay_event: | |
4efc6507 | 4658 | case bp_jit_event: |
0fd8e87f | 4659 | case bp_longjmp_master: |
e049a4b5 DJ |
4660 | loc->loc_type = bp_loc_software_breakpoint; |
4661 | break; | |
4662 | case bp_hardware_breakpoint: | |
4663 | loc->loc_type = bp_loc_hardware_breakpoint; | |
4664 | break; | |
4665 | case bp_hardware_watchpoint: | |
4666 | case bp_read_watchpoint: | |
4667 | case bp_access_watchpoint: | |
4668 | loc->loc_type = bp_loc_hardware_watchpoint; | |
4669 | break; | |
4670 | case bp_watchpoint: | |
ce78b96d | 4671 | case bp_catchpoint: |
e049a4b5 DJ |
4672 | loc->loc_type = bp_loc_other; |
4673 | break; | |
4674 | default: | |
e2e0b3e5 | 4675 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
4676 | } |
4677 | ||
7cc221ef DJ |
4678 | return loc; |
4679 | } | |
4680 | ||
fe3f5fa8 VP |
4681 | static void free_bp_location (struct bp_location *loc) |
4682 | { | |
4683 | if (loc->cond) | |
4684 | xfree (loc->cond); | |
74960c60 VP |
4685 | |
4686 | if (loc->function_name) | |
4687 | xfree (loc->function_name); | |
4688 | ||
fe3f5fa8 VP |
4689 | xfree (loc); |
4690 | } | |
4691 | ||
0d381245 VP |
4692 | /* Helper to set_raw_breakpoint below. Creates a breakpoint |
4693 | that has type BPTYPE and has no locations as yet. */ | |
63c252f8 | 4694 | /* This function is used in gdbtk sources and thus can not be made static. */ |
c906108c | 4695 | |
c40e75cd | 4696 | static struct breakpoint * |
a6d9a66e UW |
4697 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, |
4698 | enum bptype bptype) | |
c906108c | 4699 | { |
52f0bd74 | 4700 | struct breakpoint *b, *b1; |
c906108c SS |
4701 | |
4702 | b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint)); | |
4703 | memset (b, 0, sizeof (*b)); | |
2219d63c | 4704 | |
4d28f7a8 | 4705 | b->type = bptype; |
a6d9a66e | 4706 | b->gdbarch = gdbarch; |
c906108c SS |
4707 | b->language = current_language->la_language; |
4708 | b->input_radix = input_radix; | |
4709 | b->thread = -1; | |
b5de0fa7 | 4710 | b->enable_state = bp_enabled; |
c906108c SS |
4711 | b->next = 0; |
4712 | b->silent = 0; | |
4713 | b->ignore_count = 0; | |
4714 | b->commands = NULL; | |
818dd999 | 4715 | b->frame_id = null_frame_id; |
3a3e9ee3 | 4716 | b->forked_inferior_pid = null_ptid; |
c906108c | 4717 | b->exec_pathname = NULL; |
a96d9b2e | 4718 | b->syscalls_to_be_caught = NULL; |
3086aeae | 4719 | b->ops = NULL; |
0d381245 | 4720 | b->condition_not_parsed = 0; |
c906108c SS |
4721 | |
4722 | /* Add this breakpoint to the end of the chain | |
4723 | so that a list of breakpoints will come out in order | |
4724 | of increasing numbers. */ | |
4725 | ||
4726 | b1 = breakpoint_chain; | |
4727 | if (b1 == 0) | |
4728 | breakpoint_chain = b; | |
4729 | else | |
4730 | { | |
4731 | while (b1->next) | |
4732 | b1 = b1->next; | |
4733 | b1->next = b; | |
4734 | } | |
0d381245 VP |
4735 | return b; |
4736 | } | |
4737 | ||
4738 | /* Initialize loc->function_name. */ | |
4739 | static void | |
4740 | set_breakpoint_location_function (struct bp_location *loc) | |
4741 | { | |
4742 | if (loc->owner->type == bp_breakpoint | |
1042e4c0 SS |
4743 | || loc->owner->type == bp_hardware_breakpoint |
4744 | || loc->owner->type == bp_tracepoint) | |
0d381245 VP |
4745 | { |
4746 | find_pc_partial_function (loc->address, &(loc->function_name), | |
4747 | NULL, NULL); | |
4748 | if (loc->function_name) | |
4749 | loc->function_name = xstrdup (loc->function_name); | |
4750 | } | |
4751 | } | |
4752 | ||
a6d9a66e UW |
4753 | /* Attempt to determine architecture of location identified by SAL. */ |
4754 | static struct gdbarch * | |
4755 | get_sal_arch (struct symtab_and_line sal) | |
4756 | { | |
4757 | if (sal.section) | |
4758 | return get_objfile_arch (sal.section->objfile); | |
4759 | if (sal.symtab) | |
4760 | return get_objfile_arch (sal.symtab->objfile); | |
4761 | ||
4762 | return NULL; | |
4763 | } | |
4764 | ||
0d381245 VP |
4765 | /* set_raw_breakpoint is a low level routine for allocating and |
4766 | partially initializing a breakpoint of type BPTYPE. The newly | |
4767 | created breakpoint's address, section, source file name, and line | |
4768 | number are provided by SAL. The newly created and partially | |
4769 | initialized breakpoint is added to the breakpoint chain and | |
4770 | is also returned as the value of this function. | |
4771 | ||
4772 | It is expected that the caller will complete the initialization of | |
4773 | the newly created breakpoint struct as well as output any status | |
4774 | information regarding the creation of a new breakpoint. In | |
4775 | particular, set_raw_breakpoint does NOT set the breakpoint | |
4776 | number! Care should be taken to not allow an error to occur | |
4777 | prior to completing the initialization of the breakpoint. If this | |
4778 | should happen, a bogus breakpoint will be left on the chain. */ | |
4779 | ||
63c252f8 | 4780 | struct breakpoint * |
a6d9a66e UW |
4781 | set_raw_breakpoint (struct gdbarch *gdbarch, |
4782 | struct symtab_and_line sal, enum bptype bptype) | |
0d381245 | 4783 | { |
a6d9a66e | 4784 | struct breakpoint *b = set_raw_breakpoint_without_location (gdbarch, bptype); |
0d381245 | 4785 | CORE_ADDR adjusted_address; |
a6d9a66e UW |
4786 | struct gdbarch *loc_gdbarch; |
4787 | ||
4788 | loc_gdbarch = get_sal_arch (sal); | |
4789 | if (!loc_gdbarch) | |
4790 | loc_gdbarch = b->gdbarch; | |
0d381245 | 4791 | |
6c95b8df PA |
4792 | if (bptype != bp_catchpoint) |
4793 | gdb_assert (sal.pspace != NULL); | |
4794 | ||
0d381245 VP |
4795 | /* Adjust the breakpoint's address prior to allocating a location. |
4796 | Once we call allocate_bp_location(), that mostly uninitialized | |
4797 | location will be placed on the location chain. Adjustment of the | |
8defab1a | 4798 | breakpoint may cause target_read_memory() to be called and we do |
0d381245 VP |
4799 | not want its scan of the location chain to find a breakpoint and |
4800 | location that's only been partially initialized. */ | |
a6d9a66e | 4801 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, sal.pc, b->type); |
0d381245 | 4802 | |
39d61571 | 4803 | b->loc = allocate_bp_location (b); |
a6d9a66e | 4804 | b->loc->gdbarch = loc_gdbarch; |
0d381245 VP |
4805 | b->loc->requested_address = sal.pc; |
4806 | b->loc->address = adjusted_address; | |
6c95b8df PA |
4807 | b->loc->pspace = sal.pspace; |
4808 | ||
4809 | /* Store the program space that was used to set the breakpoint, for | |
4810 | breakpoint resetting. */ | |
4811 | b->pspace = sal.pspace; | |
0d381245 VP |
4812 | |
4813 | if (sal.symtab == NULL) | |
4814 | b->source_file = NULL; | |
4815 | else | |
1b36a34b | 4816 | b->source_file = xstrdup (sal.symtab->filename); |
0d381245 VP |
4817 | b->loc->section = sal.section; |
4818 | b->line_number = sal.line; | |
4819 | ||
4820 | set_breakpoint_location_function (b->loc); | |
c906108c | 4821 | |
c906108c SS |
4822 | breakpoints_changed (); |
4823 | ||
4824 | return b; | |
4825 | } | |
4826 | ||
c2c6d25f JM |
4827 | |
4828 | /* Note that the breakpoint object B describes a permanent breakpoint | |
4829 | instruction, hard-wired into the inferior's code. */ | |
4830 | void | |
4831 | make_breakpoint_permanent (struct breakpoint *b) | |
4832 | { | |
0d381245 | 4833 | struct bp_location *bl; |
b5de0fa7 | 4834 | b->enable_state = bp_permanent; |
c2c6d25f | 4835 | |
0d381245 VP |
4836 | /* By definition, permanent breakpoints are already present in the code. |
4837 | Mark all locations as inserted. For now, make_breakpoint_permanent | |
4838 | is called in just one place, so it's hard to say if it's reasonable | |
4839 | to have permanent breakpoint with multiple locations or not, | |
4840 | but it's easy to implmement. */ | |
4841 | for (bl = b->loc; bl; bl = bl->next) | |
4842 | bl->inserted = 1; | |
c2c6d25f JM |
4843 | } |
4844 | ||
53a5351d | 4845 | /* Call this routine when stepping and nexting to enable a breakpoint |
0fd8e87f | 4846 | if we do a longjmp() in THREAD. When we hit that breakpoint, call |
c906108c SS |
4847 | set_longjmp_resume_breakpoint() to figure out where we are going. */ |
4848 | ||
4849 | void | |
0fd8e87f | 4850 | set_longjmp_breakpoint (int thread) |
c906108c | 4851 | { |
0fd8e87f UW |
4852 | struct breakpoint *b, *temp; |
4853 | ||
4854 | /* To avoid having to rescan all objfile symbols at every step, | |
4855 | we maintain a list of continually-inserted but always disabled | |
4856 | longjmp "master" breakpoints. Here, we simply create momentary | |
4857 | clones of those and enable them for the requested thread. */ | |
4858 | ALL_BREAKPOINTS_SAFE (b, temp) | |
6c95b8df PA |
4859 | if (b->pspace == current_program_space |
4860 | && b->type == bp_longjmp_master) | |
0fd8e87f UW |
4861 | { |
4862 | struct breakpoint *clone = clone_momentary_breakpoint (b); | |
4863 | clone->type = bp_longjmp; | |
4864 | clone->thread = thread; | |
4865 | } | |
c906108c SS |
4866 | } |
4867 | ||
611c83ae | 4868 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 4869 | void |
611c83ae | 4870 | delete_longjmp_breakpoint (int thread) |
c906108c | 4871 | { |
611c83ae | 4872 | struct breakpoint *b, *temp; |
c906108c | 4873 | |
611c83ae PA |
4874 | ALL_BREAKPOINTS_SAFE (b, temp) |
4875 | if (b->type == bp_longjmp) | |
4876 | { | |
4877 | if (b->thread == thread) | |
4878 | delete_breakpoint (b); | |
4879 | } | |
c906108c SS |
4880 | } |
4881 | ||
1900040c MS |
4882 | void |
4883 | enable_overlay_breakpoints (void) | |
4884 | { | |
52f0bd74 | 4885 | struct breakpoint *b; |
1900040c MS |
4886 | |
4887 | ALL_BREAKPOINTS (b) | |
4888 | if (b->type == bp_overlay_event) | |
4889 | { | |
4890 | b->enable_state = bp_enabled; | |
b60e7edf | 4891 | update_global_location_list (1); |
c02f5703 | 4892 | overlay_events_enabled = 1; |
1900040c MS |
4893 | } |
4894 | } | |
4895 | ||
4896 | void | |
4897 | disable_overlay_breakpoints (void) | |
4898 | { | |
52f0bd74 | 4899 | struct breakpoint *b; |
1900040c MS |
4900 | |
4901 | ALL_BREAKPOINTS (b) | |
4902 | if (b->type == bp_overlay_event) | |
4903 | { | |
4904 | b->enable_state = bp_disabled; | |
b60e7edf | 4905 | update_global_location_list (0); |
c02f5703 | 4906 | overlay_events_enabled = 0; |
1900040c MS |
4907 | } |
4908 | } | |
4909 | ||
c4093a6a | 4910 | struct breakpoint * |
a6d9a66e | 4911 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
4912 | { |
4913 | struct breakpoint *b; | |
c4093a6a | 4914 | |
a6d9a66e | 4915 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event); |
c4093a6a | 4916 | |
b5de0fa7 | 4917 | b->enable_state = bp_enabled; |
c4093a6a | 4918 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
4919 | b->addr_string |
4920 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 4921 | |
b60e7edf | 4922 | update_global_location_list_nothrow (1); |
74960c60 | 4923 | |
c4093a6a JM |
4924 | return b; |
4925 | } | |
4926 | ||
4927 | void | |
4928 | remove_thread_event_breakpoints (void) | |
4929 | { | |
4930 | struct breakpoint *b, *temp; | |
4931 | ||
4932 | ALL_BREAKPOINTS_SAFE (b, temp) | |
6c95b8df PA |
4933 | if (b->type == bp_thread_event |
4934 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
4935 | delete_breakpoint (b); |
4936 | } | |
4937 | ||
0101ce28 JJ |
4938 | struct captured_parse_breakpoint_args |
4939 | { | |
4940 | char **arg_p; | |
4941 | struct symtabs_and_lines *sals_p; | |
4942 | char ***addr_string_p; | |
4943 | int *not_found_ptr; | |
4944 | }; | |
4945 | ||
4946 | struct lang_and_radix | |
4947 | { | |
4948 | enum language lang; | |
4949 | int radix; | |
4950 | }; | |
4951 | ||
4efc6507 DE |
4952 | /* Create a breakpoint for JIT code registration and unregistration. */ |
4953 | ||
4954 | struct breakpoint * | |
4955 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
4956 | { | |
4957 | struct breakpoint *b; | |
4958 | ||
4959 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event); | |
4960 | update_global_location_list_nothrow (1); | |
4961 | return b; | |
4962 | } | |
0101ce28 | 4963 | |
cae688ec JJ |
4964 | void |
4965 | remove_solib_event_breakpoints (void) | |
4966 | { | |
4967 | struct breakpoint *b, *temp; | |
4968 | ||
4969 | ALL_BREAKPOINTS_SAFE (b, temp) | |
6c95b8df PA |
4970 | if (b->type == bp_shlib_event |
4971 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
4972 | delete_breakpoint (b); |
4973 | } | |
4974 | ||
4975 | struct breakpoint * | |
a6d9a66e | 4976 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
cae688ec JJ |
4977 | { |
4978 | struct breakpoint *b; | |
4979 | ||
a6d9a66e | 4980 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event); |
b60e7edf | 4981 | update_global_location_list_nothrow (1); |
cae688ec JJ |
4982 | return b; |
4983 | } | |
4984 | ||
4985 | /* Disable any breakpoints that are on code in shared libraries. Only | |
4986 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
4987 | ||
4988 | void | |
cb851954 | 4989 | disable_breakpoints_in_shlibs (void) |
cae688ec | 4990 | { |
0d381245 | 4991 | struct bp_location *loc; |
cae688ec | 4992 | |
0d381245 | 4993 | ALL_BP_LOCATIONS (loc) |
cae688ec | 4994 | { |
0d381245 VP |
4995 | struct breakpoint *b = loc->owner; |
4996 | /* We apply the check to all breakpoints, including disabled | |
4997 | for those with loc->duplicate set. This is so that when breakpoint | |
4998 | becomes enabled, or the duplicate is removed, gdb will try to insert | |
4999 | all breakpoints. If we don't set shlib_disabled here, we'll try | |
5000 | to insert those breakpoints and fail. */ | |
1042e4c0 SS |
5001 | if (((b->type == bp_breakpoint) |
5002 | || (b->type == bp_hardware_breakpoint) | |
5003 | || (b->type == bp_tracepoint)) | |
6c95b8df | 5004 | && loc->pspace == current_program_space |
0d381245 | 5005 | && !loc->shlib_disabled |
a77053c2 | 5006 | #ifdef PC_SOLIB |
0d381245 | 5007 | && PC_SOLIB (loc->address) |
a77053c2 | 5008 | #else |
6c95b8df | 5009 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 MK |
5010 | #endif |
5011 | ) | |
0d381245 VP |
5012 | { |
5013 | loc->shlib_disabled = 1; | |
5014 | } | |
cae688ec JJ |
5015 | } |
5016 | } | |
5017 | ||
84acb35a JJ |
5018 | /* Disable any breakpoints that are in in an unloaded shared library. Only |
5019 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
5020 | ||
75149521 | 5021 | static void |
84acb35a JJ |
5022 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
5023 | { | |
0d381245 | 5024 | struct bp_location *loc; |
84acb35a JJ |
5025 | int disabled_shlib_breaks = 0; |
5026 | ||
c86cf029 VP |
5027 | /* SunOS a.out shared libraries are always mapped, so do not |
5028 | disable breakpoints; they will only be reported as unloaded | |
5029 | through clear_solib when GDB discards its shared library | |
5030 | list. See clear_solib for more information. */ | |
5031 | if (exec_bfd != NULL | |
5032 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
5033 | return; | |
5034 | ||
0d381245 | 5035 | ALL_BP_LOCATIONS (loc) |
84acb35a | 5036 | { |
0d381245 VP |
5037 | struct breakpoint *b = loc->owner; |
5038 | if ((loc->loc_type == bp_loc_hardware_breakpoint | |
5039 | || loc->loc_type == bp_loc_software_breakpoint) | |
6c95b8df | 5040 | && solib->pspace == loc->pspace |
e2dd7057 PP |
5041 | && !loc->shlib_disabled |
5042 | && (b->type == bp_breakpoint || b->type == bp_hardware_breakpoint) | |
5043 | && solib_contains_address_p (solib, loc->address)) | |
84acb35a | 5044 | { |
e2dd7057 PP |
5045 | loc->shlib_disabled = 1; |
5046 | /* At this point, we cannot rely on remove_breakpoint | |
5047 | succeeding so we must mark the breakpoint as not inserted | |
5048 | to prevent future errors occurring in remove_breakpoints. */ | |
5049 | loc->inserted = 0; | |
5050 | if (!disabled_shlib_breaks) | |
5051 | { | |
5052 | target_terminal_ours_for_output (); | |
5053 | warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""), | |
5054 | solib->so_name); | |
84acb35a | 5055 | } |
e2dd7057 | 5056 | disabled_shlib_breaks = 1; |
84acb35a JJ |
5057 | } |
5058 | } | |
84acb35a JJ |
5059 | } |
5060 | ||
ce78b96d JB |
5061 | /* FORK & VFORK catchpoints. */ |
5062 | ||
5063 | /* Implement the "insert" breakpoint_ops method for fork catchpoints. */ | |
5064 | ||
c906108c | 5065 | static void |
ce78b96d JB |
5066 | insert_catch_fork (struct breakpoint *b) |
5067 | { | |
5068 | target_insert_fork_catchpoint (PIDGET (inferior_ptid)); | |
5069 | } | |
5070 | ||
5071 | /* Implement the "remove" breakpoint_ops method for fork catchpoints. */ | |
5072 | ||
5073 | static int | |
5074 | remove_catch_fork (struct breakpoint *b) | |
5075 | { | |
5076 | return target_remove_fork_catchpoint (PIDGET (inferior_ptid)); | |
5077 | } | |
5078 | ||
5079 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
5080 | catchpoints. */ | |
5081 | ||
5082 | static int | |
5083 | breakpoint_hit_catch_fork (struct breakpoint *b) | |
5084 | { | |
5085 | return inferior_has_forked (inferior_ptid, &b->forked_inferior_pid); | |
5086 | } | |
5087 | ||
5088 | /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */ | |
5089 | ||
5090 | static enum print_stop_action | |
5091 | print_it_catch_fork (struct breakpoint *b) | |
5092 | { | |
5093 | annotate_catchpoint (b->number); | |
5094 | printf_filtered (_("\nCatchpoint %d (forked process %d), "), | |
5095 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
5096 | return PRINT_SRC_AND_LOC; | |
5097 | } | |
5098 | ||
5099 | /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */ | |
5100 | ||
5101 | static void | |
a6d9a66e | 5102 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 5103 | { |
79a45b7d TT |
5104 | struct value_print_options opts; |
5105 | ||
5106 | get_user_print_options (&opts); | |
5107 | ||
ce78b96d JB |
5108 | /* Field 4, the address, is omitted (which makes the columns |
5109 | not line up too nicely with the headers, but the effect | |
5110 | is relatively readable). */ | |
79a45b7d | 5111 | if (opts.addressprint) |
ce78b96d JB |
5112 | ui_out_field_skip (uiout, "addr"); |
5113 | annotate_field (5); | |
5114 | ui_out_text (uiout, "fork"); | |
5115 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
5116 | { | |
5117 | ui_out_text (uiout, ", process "); | |
5118 | ui_out_field_int (uiout, "what", | |
5119 | ptid_get_pid (b->forked_inferior_pid)); | |
5120 | ui_out_spaces (uiout, 1); | |
5121 | } | |
5122 | } | |
5123 | ||
5124 | /* Implement the "print_mention" breakpoint_ops method for fork | |
5125 | catchpoints. */ | |
5126 | ||
5127 | static void | |
5128 | print_mention_catch_fork (struct breakpoint *b) | |
5129 | { | |
5130 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
5131 | } | |
5132 | ||
5133 | /* The breakpoint_ops structure to be used in fork catchpoints. */ | |
5134 | ||
5135 | static struct breakpoint_ops catch_fork_breakpoint_ops = | |
5136 | { | |
5137 | insert_catch_fork, | |
5138 | remove_catch_fork, | |
5139 | breakpoint_hit_catch_fork, | |
5140 | print_it_catch_fork, | |
5141 | print_one_catch_fork, | |
5142 | print_mention_catch_fork | |
5143 | }; | |
5144 | ||
5145 | /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */ | |
5146 | ||
5147 | static void | |
5148 | insert_catch_vfork (struct breakpoint *b) | |
5149 | { | |
5150 | target_insert_vfork_catchpoint (PIDGET (inferior_ptid)); | |
5151 | } | |
5152 | ||
5153 | /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */ | |
5154 | ||
5155 | static int | |
5156 | remove_catch_vfork (struct breakpoint *b) | |
5157 | { | |
5158 | return target_remove_vfork_catchpoint (PIDGET (inferior_ptid)); | |
5159 | } | |
5160 | ||
5161 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
5162 | catchpoints. */ | |
5163 | ||
5164 | static int | |
5165 | breakpoint_hit_catch_vfork (struct breakpoint *b) | |
5166 | { | |
5167 | return inferior_has_vforked (inferior_ptid, &b->forked_inferior_pid); | |
5168 | } | |
5169 | ||
5170 | /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */ | |
5171 | ||
5172 | static enum print_stop_action | |
5173 | print_it_catch_vfork (struct breakpoint *b) | |
5174 | { | |
5175 | annotate_catchpoint (b->number); | |
5176 | printf_filtered (_("\nCatchpoint %d (vforked process %d), "), | |
5177 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
5178 | return PRINT_SRC_AND_LOC; | |
5179 | } | |
5180 | ||
5181 | /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */ | |
5182 | ||
5183 | static void | |
a6d9a66e | 5184 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 5185 | { |
79a45b7d TT |
5186 | struct value_print_options opts; |
5187 | ||
5188 | get_user_print_options (&opts); | |
ce78b96d JB |
5189 | /* Field 4, the address, is omitted (which makes the columns |
5190 | not line up too nicely with the headers, but the effect | |
5191 | is relatively readable). */ | |
79a45b7d | 5192 | if (opts.addressprint) |
ce78b96d JB |
5193 | ui_out_field_skip (uiout, "addr"); |
5194 | annotate_field (5); | |
5195 | ui_out_text (uiout, "vfork"); | |
5196 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
5197 | { | |
5198 | ui_out_text (uiout, ", process "); | |
5199 | ui_out_field_int (uiout, "what", | |
5200 | ptid_get_pid (b->forked_inferior_pid)); | |
5201 | ui_out_spaces (uiout, 1); | |
5202 | } | |
5203 | } | |
5204 | ||
5205 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
5206 | catchpoints. */ | |
5207 | ||
5208 | static void | |
5209 | print_mention_catch_vfork (struct breakpoint *b) | |
5210 | { | |
5211 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
5212 | } | |
5213 | ||
5214 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ | |
5215 | ||
5216 | static struct breakpoint_ops catch_vfork_breakpoint_ops = | |
5217 | { | |
5218 | insert_catch_vfork, | |
5219 | remove_catch_vfork, | |
5220 | breakpoint_hit_catch_vfork, | |
5221 | print_it_catch_vfork, | |
5222 | print_one_catch_vfork, | |
5223 | print_mention_catch_vfork | |
5224 | }; | |
5225 | ||
a96d9b2e SDJ |
5226 | /* Implement the "insert" breakpoint_ops method for syscall |
5227 | catchpoints. */ | |
5228 | ||
5229 | static void | |
5230 | insert_catch_syscall (struct breakpoint *b) | |
5231 | { | |
5232 | struct inferior *inf = current_inferior (); | |
5233 | ||
5234 | ++inf->total_syscalls_count; | |
5235 | if (!b->syscalls_to_be_caught) | |
5236 | ++inf->any_syscall_count; | |
5237 | else | |
5238 | { | |
5239 | int i, iter; | |
5240 | for (i = 0; | |
5241 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
5242 | i++) | |
5243 | { | |
5244 | int elem; | |
5245 | if (iter >= VEC_length (int, inf->syscalls_counts)) | |
5246 | { | |
5247 | int old_size = VEC_length (int, inf->syscalls_counts); | |
5248 | uintptr_t vec_addr_offset = old_size * ((uintptr_t) sizeof (int)); | |
5249 | uintptr_t vec_addr; | |
5250 | VEC_safe_grow (int, inf->syscalls_counts, iter + 1); | |
5251 | vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) + | |
5252 | vec_addr_offset; | |
5253 | memset ((void *) vec_addr, 0, | |
5254 | (iter + 1 - old_size) * sizeof (int)); | |
5255 | } | |
5256 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
5257 | VEC_replace (int, inf->syscalls_counts, iter, ++elem); | |
5258 | } | |
5259 | } | |
5260 | ||
5261 | target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
5262 | inf->total_syscalls_count != 0, | |
5263 | inf->any_syscall_count, | |
5264 | VEC_length (int, inf->syscalls_counts), | |
5265 | VEC_address (int, inf->syscalls_counts)); | |
5266 | } | |
5267 | ||
5268 | /* Implement the "remove" breakpoint_ops method for syscall | |
5269 | catchpoints. */ | |
5270 | ||
5271 | static int | |
5272 | remove_catch_syscall (struct breakpoint *b) | |
5273 | { | |
5274 | struct inferior *inf = current_inferior (); | |
5275 | ||
5276 | --inf->total_syscalls_count; | |
5277 | if (!b->syscalls_to_be_caught) | |
5278 | --inf->any_syscall_count; | |
5279 | else | |
5280 | { | |
5281 | int i, iter; | |
5282 | for (i = 0; | |
5283 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
5284 | i++) | |
5285 | { | |
5286 | int elem; | |
5287 | if (iter >= VEC_length (int, inf->syscalls_counts)) | |
5288 | /* Shouldn't happen. */ | |
5289 | continue; | |
5290 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
5291 | VEC_replace (int, inf->syscalls_counts, iter, --elem); | |
5292 | } | |
5293 | } | |
5294 | ||
5295 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
5296 | inf->total_syscalls_count != 0, | |
5297 | inf->any_syscall_count, | |
5298 | VEC_length (int, inf->syscalls_counts), | |
5299 | VEC_address (int, inf->syscalls_counts)); | |
5300 | } | |
5301 | ||
5302 | /* Implement the "breakpoint_hit" breakpoint_ops method for syscall | |
5303 | catchpoints. */ | |
5304 | ||
5305 | static int | |
5306 | breakpoint_hit_catch_syscall (struct breakpoint *b) | |
5307 | { | |
5308 | /* We must check if we are catching specific syscalls in this breakpoint. | |
5309 | If we are, then we must guarantee that the called syscall is the same | |
5310 | syscall we are catching. */ | |
5311 | int syscall_number = 0; | |
5312 | ||
5313 | if (!inferior_has_called_syscall (inferior_ptid, &syscall_number)) | |
5314 | return 0; | |
5315 | ||
5316 | /* Now, checking if the syscall is the same. */ | |
5317 | if (b->syscalls_to_be_caught) | |
5318 | { | |
5319 | int i, iter; | |
5320 | for (i = 0; | |
5321 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
5322 | i++) | |
5323 | if (syscall_number == iter) | |
5324 | break; | |
5325 | /* Not the same. */ | |
5326 | if (!iter) | |
5327 | return 0; | |
5328 | } | |
5329 | ||
5330 | return 1; | |
5331 | } | |
5332 | ||
5333 | /* Implement the "print_it" breakpoint_ops method for syscall | |
5334 | catchpoints. */ | |
5335 | ||
5336 | static enum print_stop_action | |
5337 | print_it_catch_syscall (struct breakpoint *b) | |
5338 | { | |
5339 | /* These are needed because we want to know in which state a | |
5340 | syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY | |
5341 | or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we | |
5342 | must print "called syscall" or "returned from syscall". */ | |
5343 | ptid_t ptid; | |
5344 | struct target_waitstatus last; | |
5345 | struct syscall s; | |
5346 | struct cleanup *old_chain; | |
5347 | char *syscall_id; | |
5348 | ||
5349 | get_last_target_status (&ptid, &last); | |
5350 | ||
5351 | get_syscall_by_number (last.value.syscall_number, &s); | |
5352 | ||
5353 | annotate_catchpoint (b->number); | |
5354 | ||
5355 | if (s.name == NULL) | |
5356 | syscall_id = xstrprintf ("%d", last.value.syscall_number); | |
5357 | else | |
5358 | syscall_id = xstrprintf ("'%s'", s.name); | |
5359 | ||
5360 | old_chain = make_cleanup (xfree, syscall_id); | |
5361 | ||
5362 | if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) | |
5363 | printf_filtered (_("\nCatchpoint %d (call to syscall %s), "), | |
5364 | b->number, syscall_id); | |
5365 | else if (last.kind == TARGET_WAITKIND_SYSCALL_RETURN) | |
5366 | printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "), | |
5367 | b->number, syscall_id); | |
5368 | ||
5369 | do_cleanups (old_chain); | |
5370 | ||
5371 | return PRINT_SRC_AND_LOC; | |
5372 | } | |
5373 | ||
5374 | /* Implement the "print_one" breakpoint_ops method for syscall | |
5375 | catchpoints. */ | |
5376 | ||
5377 | static void | |
5378 | print_one_catch_syscall (struct breakpoint *b, | |
5379 | struct bp_location **last_loc) | |
5380 | { | |
5381 | struct value_print_options opts; | |
5382 | ||
5383 | get_user_print_options (&opts); | |
5384 | /* Field 4, the address, is omitted (which makes the columns | |
5385 | not line up too nicely with the headers, but the effect | |
5386 | is relatively readable). */ | |
5387 | if (opts.addressprint) | |
5388 | ui_out_field_skip (uiout, "addr"); | |
5389 | annotate_field (5); | |
5390 | ||
5391 | if (b->syscalls_to_be_caught | |
5392 | && VEC_length (int, b->syscalls_to_be_caught) > 1) | |
5393 | ui_out_text (uiout, "syscalls \""); | |
5394 | else | |
5395 | ui_out_text (uiout, "syscall \""); | |
5396 | ||
5397 | if (b->syscalls_to_be_caught) | |
5398 | { | |
5399 | int i, iter; | |
5400 | char *text = xstrprintf ("%s", ""); | |
5401 | for (i = 0; | |
5402 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
5403 | i++) | |
5404 | { | |
5405 | char *x = text; | |
5406 | struct syscall s; | |
5407 | get_syscall_by_number (iter, &s); | |
5408 | ||
5409 | if (s.name != NULL) | |
5410 | text = xstrprintf ("%s%s, ", text, s.name); | |
5411 | else | |
5412 | text = xstrprintf ("%s%d, ", text, iter); | |
5413 | ||
5414 | /* We have to xfree the last 'text' (now stored at 'x') | |
5415 | because xstrprintf dinamically allocates new space for it | |
5416 | on every call. */ | |
5417 | xfree (x); | |
5418 | } | |
5419 | /* Remove the last comma. */ | |
5420 | text[strlen (text) - 2] = '\0'; | |
5421 | ui_out_field_string (uiout, "what", text); | |
5422 | } | |
5423 | else | |
5424 | ui_out_field_string (uiout, "what", "<any syscall>"); | |
5425 | ui_out_text (uiout, "\" "); | |
5426 | } | |
5427 | ||
5428 | /* Implement the "print_mention" breakpoint_ops method for syscall | |
5429 | catchpoints. */ | |
5430 | ||
5431 | static void | |
5432 | print_mention_catch_syscall (struct breakpoint *b) | |
5433 | { | |
5434 | if (b->syscalls_to_be_caught) | |
5435 | { | |
5436 | int i, iter; | |
5437 | ||
5438 | if (VEC_length (int, b->syscalls_to_be_caught) > 1) | |
5439 | printf_filtered (_("Catchpoint %d (syscalls"), b->number); | |
5440 | else | |
5441 | printf_filtered (_("Catchpoint %d (syscall"), b->number); | |
5442 | ||
5443 | for (i = 0; | |
5444 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
5445 | i++) | |
5446 | { | |
5447 | struct syscall s; | |
5448 | get_syscall_by_number (iter, &s); | |
5449 | ||
5450 | if (s.name) | |
5451 | printf_filtered (" '%s' [%d]", s.name, s.number); | |
5452 | else | |
5453 | printf_filtered (" %d", s.number); | |
5454 | } | |
5455 | printf_filtered (")"); | |
5456 | } | |
5457 | else | |
5458 | printf_filtered (_("Catchpoint %d (any syscall)"), | |
5459 | b->number); | |
5460 | } | |
5461 | ||
5462 | /* The breakpoint_ops structure to be used in syscall catchpoints. */ | |
5463 | ||
5464 | static struct breakpoint_ops catch_syscall_breakpoint_ops = | |
5465 | { | |
5466 | insert_catch_syscall, | |
5467 | remove_catch_syscall, | |
5468 | breakpoint_hit_catch_syscall, | |
5469 | print_it_catch_syscall, | |
5470 | print_one_catch_syscall, | |
5471 | print_mention_catch_syscall | |
5472 | }; | |
5473 | ||
5474 | /* Returns non-zero if 'b' is a syscall catchpoint. */ | |
5475 | ||
5476 | static int | |
5477 | syscall_catchpoint_p (struct breakpoint *b) | |
5478 | { | |
5479 | return (b->ops == &catch_syscall_breakpoint_ops); | |
5480 | } | |
5481 | ||
5482 | /* Create a new breakpoint of the bp_catchpoint kind and return it, | |
5483 | but does NOT mention it nor update the global location list. | |
5484 | This is useful if you need to fill more fields in the | |
5485 | struct breakpoint before calling mention. | |
ce78b96d JB |
5486 | |
5487 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
5488 | If COND_STRING is not NULL, then store it in the breakpoint. | |
5489 | OPS, if not NULL, is the breakpoint_ops structure associated | |
5490 | to the catchpoint. */ | |
5491 | ||
5492 | static struct breakpoint * | |
a96d9b2e SDJ |
5493 | create_catchpoint_without_mention (struct gdbarch *gdbarch, int tempflag, |
5494 | char *cond_string, | |
5495 | struct breakpoint_ops *ops) | |
c906108c | 5496 | { |
c5aa993b JM |
5497 | struct symtab_and_line sal; |
5498 | struct breakpoint *b; | |
c5aa993b | 5499 | |
fe39c653 | 5500 | init_sal (&sal); |
6c95b8df | 5501 | sal.pspace = current_program_space; |
c5aa993b | 5502 | |
a6d9a66e | 5503 | b = set_raw_breakpoint (gdbarch, sal, bp_catchpoint); |
c906108c SS |
5504 | set_breakpoint_count (breakpoint_count + 1); |
5505 | b->number = breakpoint_count; | |
ce78b96d | 5506 | |
1b36a34b | 5507 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
ce78b96d | 5508 | b->thread = -1; |
c906108c | 5509 | b->addr_string = NULL; |
b5de0fa7 EZ |
5510 | b->enable_state = bp_enabled; |
5511 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
ce78b96d | 5512 | b->ops = ops; |
c5aa993b | 5513 | |
a96d9b2e SDJ |
5514 | return b; |
5515 | } | |
5516 | ||
5517 | /* Create a new breakpoint of the bp_catchpoint kind and return it. | |
5518 | ||
5519 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
5520 | If COND_STRING is not NULL, then store it in the breakpoint. | |
5521 | OPS, if not NULL, is the breakpoint_ops structure associated | |
5522 | to the catchpoint. */ | |
5523 | ||
5524 | static struct breakpoint * | |
5525 | create_catchpoint (struct gdbarch *gdbarch, int tempflag, | |
5526 | char *cond_string, struct breakpoint_ops *ops) | |
5527 | { | |
5528 | struct breakpoint *b = | |
5529 | create_catchpoint_without_mention (gdbarch, tempflag, cond_string, ops); | |
5530 | ||
c906108c | 5531 | mention (b); |
ce78b96d | 5532 | update_global_location_list (1); |
c906108c | 5533 | |
ce78b96d | 5534 | return b; |
c906108c | 5535 | } |
c5aa993b | 5536 | |
9b70b993 | 5537 | static void |
a6d9a66e UW |
5538 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
5539 | int tempflag, char *cond_string, | |
ce78b96d | 5540 | struct breakpoint_ops *ops) |
c906108c | 5541 | { |
a6d9a66e UW |
5542 | struct breakpoint *b |
5543 | = create_catchpoint (gdbarch, tempflag, cond_string, ops); | |
ce78b96d JB |
5544 | |
5545 | /* FIXME: We should put this information in a breakpoint private data | |
5546 | area. */ | |
5547 | b->forked_inferior_pid = null_ptid; | |
c906108c SS |
5548 | } |
5549 | ||
fe798b75 JB |
5550 | /* Exec catchpoints. */ |
5551 | ||
9b70b993 | 5552 | static void |
fe798b75 | 5553 | insert_catch_exec (struct breakpoint *b) |
c906108c | 5554 | { |
fe798b75 JB |
5555 | target_insert_exec_catchpoint (PIDGET (inferior_ptid)); |
5556 | } | |
c906108c | 5557 | |
fe798b75 JB |
5558 | static int |
5559 | remove_catch_exec (struct breakpoint *b) | |
5560 | { | |
5561 | return target_remove_exec_catchpoint (PIDGET (inferior_ptid)); | |
5562 | } | |
c906108c | 5563 | |
fe798b75 JB |
5564 | static int |
5565 | breakpoint_hit_catch_exec (struct breakpoint *b) | |
5566 | { | |
5567 | return inferior_has_execd (inferior_ptid, &b->exec_pathname); | |
5568 | } | |
c906108c | 5569 | |
fe798b75 JB |
5570 | static enum print_stop_action |
5571 | print_it_catch_exec (struct breakpoint *b) | |
5572 | { | |
5573 | annotate_catchpoint (b->number); | |
5574 | printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number, | |
5575 | b->exec_pathname); | |
5576 | return PRINT_SRC_AND_LOC; | |
c906108c SS |
5577 | } |
5578 | ||
fe798b75 | 5579 | static void |
a6d9a66e | 5580 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 JB |
5581 | { |
5582 | struct value_print_options opts; | |
5583 | ||
5584 | get_user_print_options (&opts); | |
5585 | ||
5586 | /* Field 4, the address, is omitted (which makes the columns | |
5587 | not line up too nicely with the headers, but the effect | |
5588 | is relatively readable). */ | |
5589 | if (opts.addressprint) | |
5590 | ui_out_field_skip (uiout, "addr"); | |
5591 | annotate_field (5); | |
5592 | ui_out_text (uiout, "exec"); | |
5593 | if (b->exec_pathname != NULL) | |
5594 | { | |
5595 | ui_out_text (uiout, ", program \""); | |
5596 | ui_out_field_string (uiout, "what", b->exec_pathname); | |
5597 | ui_out_text (uiout, "\" "); | |
5598 | } | |
5599 | } | |
5600 | ||
5601 | static void | |
5602 | print_mention_catch_exec (struct breakpoint *b) | |
5603 | { | |
5604 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
5605 | } | |
5606 | ||
5607 | static struct breakpoint_ops catch_exec_breakpoint_ops = | |
5608 | { | |
5609 | insert_catch_exec, | |
5610 | remove_catch_exec, | |
5611 | breakpoint_hit_catch_exec, | |
5612 | print_it_catch_exec, | |
5613 | print_one_catch_exec, | |
5614 | print_mention_catch_exec | |
5615 | }; | |
5616 | ||
a96d9b2e SDJ |
5617 | static void |
5618 | create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, | |
5619 | struct breakpoint_ops *ops) | |
5620 | { | |
5621 | struct gdbarch *gdbarch = get_current_arch (); | |
5622 | struct breakpoint *b = | |
5623 | create_catchpoint_without_mention (gdbarch, tempflag, NULL, ops); | |
5624 | ||
5625 | b->syscalls_to_be_caught = filter; | |
5626 | ||
5627 | /* Now, we have to mention the breakpoint and update the global | |
5628 | location list. */ | |
5629 | mention (b); | |
5630 | update_global_location_list (1); | |
5631 | } | |
5632 | ||
c906108c | 5633 | static int |
fba45db2 | 5634 | hw_breakpoint_used_count (void) |
c906108c | 5635 | { |
52f0bd74 | 5636 | struct breakpoint *b; |
c906108c SS |
5637 | int i = 0; |
5638 | ||
5639 | ALL_BREAKPOINTS (b) | |
c5aa993b | 5640 | { |
d6b74ac4 | 5641 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
c5aa993b JM |
5642 | i++; |
5643 | } | |
c906108c SS |
5644 | |
5645 | return i; | |
5646 | } | |
5647 | ||
5648 | static int | |
fba45db2 | 5649 | hw_watchpoint_used_count (enum bptype type, int *other_type_used) |
c906108c | 5650 | { |
52f0bd74 | 5651 | struct breakpoint *b; |
c906108c SS |
5652 | int i = 0; |
5653 | ||
5654 | *other_type_used = 0; | |
5655 | ALL_BREAKPOINTS (b) | |
c5aa993b | 5656 | { |
468d015d | 5657 | if (breakpoint_enabled (b)) |
c5aa993b JM |
5658 | { |
5659 | if (b->type == type) | |
5660 | i++; | |
059fb39f PM |
5661 | else if ((b->type == bp_hardware_watchpoint |
5662 | || b->type == bp_read_watchpoint | |
5663 | || b->type == bp_access_watchpoint)) | |
c5aa993b JM |
5664 | *other_type_used = 1; |
5665 | } | |
5666 | } | |
c906108c SS |
5667 | return i; |
5668 | } | |
5669 | ||
c906108c | 5670 | void |
fba45db2 | 5671 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 5672 | { |
c5aa993b | 5673 | struct breakpoint *b; |
c906108c SS |
5674 | |
5675 | ALL_BREAKPOINTS (b) | |
c5aa993b JM |
5676 | { |
5677 | if (((b->type == bp_watchpoint) | |
5678 | || (b->type == bp_hardware_watchpoint) | |
5679 | || (b->type == bp_read_watchpoint) | |
dfdfb3ca | 5680 | || (b->type == bp_access_watchpoint)) |
468d015d | 5681 | && breakpoint_enabled (b)) |
c5aa993b | 5682 | { |
b5de0fa7 | 5683 | b->enable_state = bp_call_disabled; |
b60e7edf | 5684 | update_global_location_list (0); |
c5aa993b JM |
5685 | } |
5686 | } | |
c906108c SS |
5687 | } |
5688 | ||
5689 | void | |
fba45db2 | 5690 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 5691 | { |
c5aa993b | 5692 | struct breakpoint *b; |
c906108c SS |
5693 | |
5694 | ALL_BREAKPOINTS (b) | |
c5aa993b JM |
5695 | { |
5696 | if (((b->type == bp_watchpoint) | |
5697 | || (b->type == bp_hardware_watchpoint) | |
5698 | || (b->type == bp_read_watchpoint) | |
dfdfb3ca | 5699 | || (b->type == bp_access_watchpoint)) |
b5de0fa7 | 5700 | && (b->enable_state == bp_call_disabled)) |
c5aa993b | 5701 | { |
b5de0fa7 | 5702 | b->enable_state = bp_enabled; |
b60e7edf | 5703 | update_global_location_list (1); |
c5aa993b JM |
5704 | } |
5705 | } | |
c906108c SS |
5706 | } |
5707 | ||
8bea4e01 UW |
5708 | void |
5709 | disable_breakpoints_before_startup (void) | |
5710 | { | |
5711 | struct breakpoint *b; | |
5712 | int found = 0; | |
5713 | ||
5714 | ALL_BREAKPOINTS (b) | |
5715 | { | |
6c95b8df PA |
5716 | if (b->pspace != current_program_space) |
5717 | continue; | |
5718 | ||
8bea4e01 UW |
5719 | if ((b->type == bp_breakpoint |
5720 | || b->type == bp_hardware_breakpoint) | |
5721 | && breakpoint_enabled (b)) | |
5722 | { | |
5723 | b->enable_state = bp_startup_disabled; | |
5724 | found = 1; | |
5725 | } | |
5726 | } | |
5727 | ||
5728 | if (found) | |
5729 | update_global_location_list (0); | |
5730 | ||
6c95b8df | 5731 | current_program_space->executing_startup = 1; |
8bea4e01 UW |
5732 | } |
5733 | ||
5734 | void | |
5735 | enable_breakpoints_after_startup (void) | |
5736 | { | |
5737 | struct breakpoint *b; | |
5738 | int found = 0; | |
5739 | ||
6c95b8df | 5740 | current_program_space->executing_startup = 0; |
8bea4e01 UW |
5741 | |
5742 | ALL_BREAKPOINTS (b) | |
5743 | { | |
6c95b8df PA |
5744 | if (b->pspace != current_program_space) |
5745 | continue; | |
5746 | ||
8bea4e01 UW |
5747 | if ((b->type == bp_breakpoint |
5748 | || b->type == bp_hardware_breakpoint) | |
5749 | && b->enable_state == bp_startup_disabled) | |
5750 | { | |
5751 | b->enable_state = bp_enabled; | |
5752 | found = 1; | |
5753 | } | |
5754 | } | |
5755 | ||
5756 | if (found) | |
5757 | breakpoint_re_set (); | |
5758 | } | |
5759 | ||
c906108c SS |
5760 | |
5761 | /* Set a breakpoint that will evaporate an end of command | |
5762 | at address specified by SAL. | |
5763 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
5764 | ||
5765 | struct breakpoint * | |
a6d9a66e UW |
5766 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
5767 | struct frame_id frame_id, enum bptype type) | |
c906108c | 5768 | { |
52f0bd74 | 5769 | struct breakpoint *b; |
edb3359d DJ |
5770 | |
5771 | /* If FRAME_ID is valid, it should be a real frame, not an inlined | |
5772 | one. */ | |
5773 | gdb_assert (!frame_id_inlined_p (frame_id)); | |
5774 | ||
a6d9a66e | 5775 | b = set_raw_breakpoint (gdbarch, sal, type); |
b5de0fa7 EZ |
5776 | b->enable_state = bp_enabled; |
5777 | b->disposition = disp_donttouch; | |
818dd999 | 5778 | b->frame_id = frame_id; |
c906108c SS |
5779 | |
5780 | /* If we're debugging a multi-threaded program, then we | |
5781 | want momentary breakpoints to be active in only a | |
5782 | single thread of control. */ | |
39f77062 KB |
5783 | if (in_thread_list (inferior_ptid)) |
5784 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 5785 | |
b60e7edf | 5786 | update_global_location_list_nothrow (1); |
74960c60 | 5787 | |
c906108c SS |
5788 | return b; |
5789 | } | |
611c83ae | 5790 | |
e58b0e63 PA |
5791 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
5792 | ORIG is NULL. */ | |
5793 | ||
5794 | struct breakpoint * | |
5795 | clone_momentary_breakpoint (struct breakpoint *orig) | |
5796 | { | |
5797 | struct breakpoint *copy; | |
5798 | ||
5799 | /* If there's nothing to clone, then return nothing. */ | |
5800 | if (orig == NULL) | |
5801 | return NULL; | |
5802 | ||
a6d9a66e | 5803 | copy = set_raw_breakpoint_without_location (orig->gdbarch, orig->type); |
e58b0e63 PA |
5804 | copy->loc = allocate_bp_location (copy); |
5805 | set_breakpoint_location_function (copy->loc); | |
5806 | ||
a6d9a66e | 5807 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
5808 | copy->loc->requested_address = orig->loc->requested_address; |
5809 | copy->loc->address = orig->loc->address; | |
5810 | copy->loc->section = orig->loc->section; | |
6c95b8df | 5811 | copy->loc->pspace = orig->loc->pspace; |
e58b0e63 PA |
5812 | |
5813 | if (orig->source_file == NULL) | |
5814 | copy->source_file = NULL; | |
5815 | else | |
5816 | copy->source_file = xstrdup (orig->source_file); | |
5817 | ||
5818 | copy->line_number = orig->line_number; | |
5819 | copy->frame_id = orig->frame_id; | |
5820 | copy->thread = orig->thread; | |
6c95b8df | 5821 | copy->pspace = orig->pspace; |
e58b0e63 PA |
5822 | |
5823 | copy->enable_state = bp_enabled; | |
5824 | copy->disposition = disp_donttouch; | |
5825 | copy->number = internal_breakpoint_number--; | |
5826 | ||
5827 | update_global_location_list_nothrow (0); | |
5828 | return copy; | |
5829 | } | |
5830 | ||
611c83ae | 5831 | struct breakpoint * |
a6d9a66e UW |
5832 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
5833 | enum bptype type) | |
611c83ae PA |
5834 | { |
5835 | struct symtab_and_line sal; | |
5836 | ||
5837 | sal = find_pc_line (pc, 0); | |
5838 | sal.pc = pc; | |
5839 | sal.section = find_pc_overlay (pc); | |
5840 | sal.explicit_pc = 1; | |
5841 | ||
a6d9a66e | 5842 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 5843 | } |
c906108c | 5844 | \f |
c5aa993b | 5845 | |
c906108c SS |
5846 | /* Tell the user we have just set a breakpoint B. */ |
5847 | ||
5848 | static void | |
fba45db2 | 5849 | mention (struct breakpoint *b) |
c906108c SS |
5850 | { |
5851 | int say_where = 0; | |
fa8a61dc | 5852 | struct cleanup *ui_out_chain; |
79a45b7d TT |
5853 | struct value_print_options opts; |
5854 | ||
5855 | get_user_print_options (&opts); | |
8b93c638 | 5856 | |
9a4105ab AC |
5857 | /* FIXME: This is misplaced; mention() is called by things (like |
5858 | hitting a watchpoint) other than breakpoint creation. It should | |
5859 | be possible to clean this up and at the same time replace the | |
7f4b89d1 | 5860 | random calls to breakpoint_changed with this hook. */ |
383f836e | 5861 | observer_notify_breakpoint_created (b->number); |
c906108c | 5862 | |
3086aeae DJ |
5863 | if (b->ops != NULL && b->ops->print_mention != NULL) |
5864 | b->ops->print_mention (b); | |
5865 | else | |
5866 | switch (b->type) | |
5867 | { | |
5868 | case bp_none: | |
a3f17187 | 5869 | printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b->number); |
3086aeae DJ |
5870 | break; |
5871 | case bp_watchpoint: | |
5872 | ui_out_text (uiout, "Watchpoint "); | |
5873 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
5874 | ui_out_field_int (uiout, "number", b->number); | |
5875 | ui_out_text (uiout, ": "); | |
fa8a61dc | 5876 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
5877 | do_cleanups (ui_out_chain); |
5878 | break; | |
5879 | case bp_hardware_watchpoint: | |
5880 | ui_out_text (uiout, "Hardware watchpoint "); | |
5881 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
5882 | ui_out_field_int (uiout, "number", b->number); | |
5883 | ui_out_text (uiout, ": "); | |
fa8a61dc | 5884 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
5885 | do_cleanups (ui_out_chain); |
5886 | break; | |
5887 | case bp_read_watchpoint: | |
5888 | ui_out_text (uiout, "Hardware read watchpoint "); | |
5889 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
5890 | ui_out_field_int (uiout, "number", b->number); | |
5891 | ui_out_text (uiout, ": "); | |
fa8a61dc | 5892 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
5893 | do_cleanups (ui_out_chain); |
5894 | break; | |
5895 | case bp_access_watchpoint: | |
5896 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
5897 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
5898 | ui_out_field_int (uiout, "number", b->number); | |
5899 | ui_out_text (uiout, ": "); | |
fa8a61dc | 5900 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
5901 | do_cleanups (ui_out_chain); |
5902 | break; | |
5903 | case bp_breakpoint: | |
5904 | if (ui_out_is_mi_like_p (uiout)) | |
5905 | { | |
5906 | say_where = 0; | |
5907 | break; | |
5908 | } | |
2cec12e5 AR |
5909 | if (b->disposition == disp_del) |
5910 | printf_filtered (_("Temporary breakpoint")); | |
5911 | else | |
5912 | printf_filtered (_("Breakpoint")); | |
5913 | printf_filtered (_(" %d"), b->number); | |
3086aeae DJ |
5914 | say_where = 1; |
5915 | break; | |
5916 | case bp_hardware_breakpoint: | |
5917 | if (ui_out_is_mi_like_p (uiout)) | |
5918 | { | |
5919 | say_where = 0; | |
5920 | break; | |
5921 | } | |
a3f17187 | 5922 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); |
3086aeae DJ |
5923 | say_where = 1; |
5924 | break; | |
1042e4c0 SS |
5925 | case bp_tracepoint: |
5926 | if (ui_out_is_mi_like_p (uiout)) | |
5927 | { | |
5928 | say_where = 0; | |
5929 | break; | |
5930 | } | |
5931 | printf_filtered (_("Tracepoint")); | |
5932 | printf_filtered (_(" %d"), b->number); | |
5933 | say_where = 1; | |
5934 | break; | |
3086aeae DJ |
5935 | |
5936 | case bp_until: | |
5937 | case bp_finish: | |
5938 | case bp_longjmp: | |
5939 | case bp_longjmp_resume: | |
5940 | case bp_step_resume: | |
3086aeae DJ |
5941 | case bp_call_dummy: |
5942 | case bp_watchpoint_scope: | |
5943 | case bp_shlib_event: | |
5944 | case bp_thread_event: | |
5945 | case bp_overlay_event: | |
4efc6507 | 5946 | case bp_jit_event: |
0fd8e87f | 5947 | case bp_longjmp_master: |
3086aeae DJ |
5948 | break; |
5949 | } | |
c906108c | 5950 | |
c906108c SS |
5951 | if (say_where) |
5952 | { | |
a3f17187 AC |
5953 | /* i18n: cagney/2005-02-11: Below needs to be merged into a |
5954 | single string. */ | |
0d381245 | 5955 | if (b->loc == NULL) |
c906108c | 5956 | { |
a3f17187 | 5957 | printf_filtered (_(" (%s) pending."), b->addr_string); |
0101ce28 JJ |
5958 | } |
5959 | else | |
5960 | { | |
79a45b7d | 5961 | if (opts.addressprint || b->source_file == NULL) |
0101ce28 JJ |
5962 | { |
5963 | printf_filtered (" at "); | |
5af949e3 UW |
5964 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), |
5965 | gdb_stdout); | |
0101ce28 JJ |
5966 | } |
5967 | if (b->source_file) | |
5968 | printf_filtered (": file %s, line %d.", | |
5969 | b->source_file, b->line_number); | |
0d381245 VP |
5970 | |
5971 | if (b->loc->next) | |
5972 | { | |
5973 | struct bp_location *loc = b->loc; | |
5974 | int n = 0; | |
5975 | for (; loc; loc = loc->next) | |
5976 | ++n; | |
5977 | printf_filtered (" (%d locations)", n); | |
5978 | } | |
5979 | ||
c906108c | 5980 | } |
c906108c | 5981 | } |
9dc5e2a9 | 5982 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 5983 | return; |
c906108c SS |
5984 | printf_filtered ("\n"); |
5985 | } | |
c906108c | 5986 | \f |
c5aa993b | 5987 | |
0d381245 | 5988 | static struct bp_location * |
39d61571 | 5989 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
5990 | const struct symtab_and_line *sal) |
5991 | { | |
5992 | struct bp_location *loc, **tmp; | |
5993 | ||
39d61571 | 5994 | loc = allocate_bp_location (b); |
0d381245 VP |
5995 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
5996 | ; | |
5997 | *tmp = loc; | |
a6d9a66e UW |
5998 | loc->gdbarch = get_sal_arch (*sal); |
5999 | if (!loc->gdbarch) | |
6000 | loc->gdbarch = b->gdbarch; | |
0d381245 | 6001 | loc->requested_address = sal->pc; |
a6d9a66e UW |
6002 | loc->address = adjust_breakpoint_address (loc->gdbarch, |
6003 | loc->requested_address, b->type); | |
6c95b8df PA |
6004 | loc->pspace = sal->pspace; |
6005 | gdb_assert (loc->pspace != NULL); | |
0d381245 VP |
6006 | loc->section = sal->section; |
6007 | ||
6008 | set_breakpoint_location_function (loc); | |
6009 | return loc; | |
6010 | } | |
514f746b AR |
6011 | \f |
6012 | ||
6013 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
6014 | return 0 otherwise. */ | |
6015 | ||
6016 | static int | |
6017 | bp_loc_is_permanent (struct bp_location *loc) | |
6018 | { | |
6019 | int len; | |
6020 | CORE_ADDR addr; | |
6021 | const gdb_byte *brk; | |
6022 | gdb_byte *target_mem; | |
939c61fa JK |
6023 | struct cleanup *cleanup; |
6024 | int retval = 0; | |
514f746b AR |
6025 | |
6026 | gdb_assert (loc != NULL); | |
6027 | ||
6028 | addr = loc->address; | |
a6d9a66e | 6029 | brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 6030 | |
939c61fa JK |
6031 | /* Software breakpoints unsupported? */ |
6032 | if (brk == NULL) | |
6033 | return 0; | |
6034 | ||
514f746b AR |
6035 | target_mem = alloca (len); |
6036 | ||
939c61fa JK |
6037 | /* Enable the automatic memory restoration from breakpoints while |
6038 | we read the memory. Otherwise we could say about our temporary | |
6039 | breakpoints they are permanent. */ | |
6c95b8df PA |
6040 | cleanup = save_current_space_and_thread (); |
6041 | ||
6042 | switch_to_program_space_and_thread (loc->pspace); | |
6043 | make_show_memory_breakpoints_cleanup (0); | |
939c61fa | 6044 | |
514f746b AR |
6045 | if (target_read_memory (loc->address, target_mem, len) == 0 |
6046 | && memcmp (target_mem, brk, len) == 0) | |
939c61fa | 6047 | retval = 1; |
514f746b | 6048 | |
939c61fa JK |
6049 | do_cleanups (cleanup); |
6050 | ||
6051 | return retval; | |
514f746b AR |
6052 | } |
6053 | ||
6054 | ||
c3f6f71d | 6055 | |
018d34a4 VP |
6056 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
6057 | as textual description of the location, and COND_STRING | |
db107f19 | 6058 | as condition expression. */ |
018d34a4 VP |
6059 | |
6060 | static void | |
a6d9a66e UW |
6061 | create_breakpoint (struct gdbarch *gdbarch, |
6062 | struct symtabs_and_lines sals, char *addr_string, | |
018d34a4 VP |
6063 | char *cond_string, |
6064 | enum bptype type, enum bpdisp disposition, | |
4a306c9a | 6065 | int thread, int task, int ignore_count, |
41447f92 | 6066 | struct breakpoint_ops *ops, int from_tty, int enabled) |
018d34a4 | 6067 | { |
0d381245 VP |
6068 | struct breakpoint *b = NULL; |
6069 | int i; | |
018d34a4 VP |
6070 | |
6071 | if (type == bp_hardware_breakpoint) | |
6072 | { | |
6073 | int i = hw_breakpoint_used_count (); | |
6074 | int target_resources_ok = | |
d92524f1 | 6075 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
018d34a4 VP |
6076 | i + 1, 0); |
6077 | if (target_resources_ok == 0) | |
6078 | error (_("No hardware breakpoint support in the target.")); | |
6079 | else if (target_resources_ok < 0) | |
6080 | error (_("Hardware breakpoints used exceeds limit.")); | |
6081 | } | |
6082 | ||
6c95b8df PA |
6083 | gdb_assert (sals.nelts > 0); |
6084 | ||
0d381245 VP |
6085 | for (i = 0; i < sals.nelts; ++i) |
6086 | { | |
6087 | struct symtab_and_line sal = sals.sals[i]; | |
6088 | struct bp_location *loc; | |
6089 | ||
6090 | if (from_tty) | |
5af949e3 UW |
6091 | { |
6092 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
6093 | if (!loc_gdbarch) | |
6094 | loc_gdbarch = gdbarch; | |
6095 | ||
6096 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 6097 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 6098 | } |
0d381245 VP |
6099 | |
6100 | if (i == 0) | |
6101 | { | |
a6d9a66e | 6102 | b = set_raw_breakpoint (gdbarch, sal, type); |
0d381245 VP |
6103 | set_breakpoint_count (breakpoint_count + 1); |
6104 | b->number = breakpoint_count; | |
6105 | b->thread = thread; | |
4a306c9a | 6106 | b->task = task; |
018d34a4 | 6107 | |
0d381245 VP |
6108 | b->cond_string = cond_string; |
6109 | b->ignore_count = ignore_count; | |
41447f92 | 6110 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 6111 | b->disposition = disposition; |
018d34a4 | 6112 | |
6c95b8df PA |
6113 | b->pspace = sals.sals[0].pspace; |
6114 | ||
6115 | if (enabled && b->pspace->executing_startup | |
8bea4e01 UW |
6116 | && (b->type == bp_breakpoint |
6117 | || b->type == bp_hardware_breakpoint)) | |
6118 | b->enable_state = bp_startup_disabled; | |
6119 | ||
0d381245 VP |
6120 | loc = b->loc; |
6121 | } | |
6122 | else | |
018d34a4 | 6123 | { |
39d61571 | 6124 | loc = add_location_to_breakpoint (b, &sal); |
0d381245 VP |
6125 | } |
6126 | ||
514f746b AR |
6127 | if (bp_loc_is_permanent (loc)) |
6128 | make_breakpoint_permanent (b); | |
6129 | ||
0d381245 VP |
6130 | if (b->cond_string) |
6131 | { | |
6132 | char *arg = b->cond_string; | |
d32a6982 | 6133 | loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0); |
0d381245 | 6134 | if (*arg) |
db107f19 | 6135 | error (_("Garbage %s follows condition"), arg); |
018d34a4 | 6136 | } |
0d381245 | 6137 | } |
018d34a4 VP |
6138 | |
6139 | if (addr_string) | |
6140 | b->addr_string = addr_string; | |
6141 | else | |
6142 | /* addr_string has to be used or breakpoint_re_set will delete | |
6143 | me. */ | |
5af949e3 UW |
6144 | b->addr_string |
6145 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
018d34a4 | 6146 | |
604133b5 | 6147 | b->ops = ops; |
018d34a4 VP |
6148 | mention (b); |
6149 | } | |
6150 | ||
ed0616c6 VP |
6151 | /* Remove element at INDEX_TO_REMOVE from SAL, shifting other |
6152 | elements to fill the void space. */ | |
2c0b251b PA |
6153 | static void |
6154 | remove_sal (struct symtabs_and_lines *sal, int index_to_remove) | |
ed0616c6 VP |
6155 | { |
6156 | int i = index_to_remove+1; | |
6157 | int last_index = sal->nelts-1; | |
6158 | ||
6159 | for (;i <= last_index; ++i) | |
6160 | sal->sals[i-1] = sal->sals[i]; | |
6161 | ||
6162 | --(sal->nelts); | |
6163 | } | |
6164 | ||
6c95b8df PA |
6165 | /* If appropriate, obtains all sals that correspond to the same file |
6166 | and line as SAL, in all program spaces. Users debugging with IDEs, | |
6167 | will want to set a breakpoint at foo.c:line, and not really care | |
6168 | about program spaces. This is done only if SAL does not have | |
6169 | explicit PC and has line and file information. If we got just a | |
6170 | single expanded sal, return the original. | |
ed0616c6 | 6171 | |
6c95b8df PA |
6172 | Otherwise, if SAL.explicit_line is not set, filter out all sals for |
6173 | which the name of enclosing function is different from SAL. This | |
6174 | makes sure that if we have breakpoint originally set in template | |
6175 | instantiation, say foo<int>(), we won't expand SAL to locations at | |
6176 | the same line in all existing instantiations of 'foo'. */ | |
ed0616c6 | 6177 | |
2c0b251b | 6178 | static struct symtabs_and_lines |
ed0616c6 VP |
6179 | expand_line_sal_maybe (struct symtab_and_line sal) |
6180 | { | |
6181 | struct symtabs_and_lines expanded; | |
6182 | CORE_ADDR original_pc = sal.pc; | |
6183 | char *original_function = NULL; | |
6184 | int found; | |
6185 | int i; | |
6c95b8df | 6186 | struct cleanup *old_chain; |
ed0616c6 VP |
6187 | |
6188 | /* If we have explicit pc, don't expand. | |
6189 | If we have no line number, we can't expand. */ | |
6190 | if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL) | |
6191 | { | |
6192 | expanded.nelts = 1; | |
6193 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
6194 | expanded.sals[0] = sal; | |
6195 | return expanded; | |
6196 | } | |
6197 | ||
6198 | sal.pc = 0; | |
6c95b8df PA |
6199 | |
6200 | old_chain = save_current_space_and_thread (); | |
6201 | ||
6202 | switch_to_program_space_and_thread (sal.pspace); | |
6203 | ||
ed0616c6 | 6204 | find_pc_partial_function (original_pc, &original_function, NULL, NULL); |
6c95b8df PA |
6205 | |
6206 | /* Note that expand_line_sal visits *all* program spaces. */ | |
ed0616c6 | 6207 | expanded = expand_line_sal (sal); |
6c95b8df | 6208 | |
ed0616c6 VP |
6209 | if (expanded.nelts == 1) |
6210 | { | |
6211 | /* We had one sal, we got one sal. Without futher | |
6212 | processing, just return the original sal. */ | |
6213 | xfree (expanded.sals); | |
6214 | expanded.nelts = 1; | |
6215 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
6216 | sal.pc = original_pc; | |
6217 | expanded.sals[0] = sal; | |
6c95b8df | 6218 | do_cleanups (old_chain); |
ed0616c6 VP |
6219 | return expanded; |
6220 | } | |
6221 | ||
6222 | if (!sal.explicit_line) | |
6223 | { | |
6224 | CORE_ADDR func_addr, func_end; | |
6225 | for (i = 0; i < expanded.nelts; ++i) | |
6226 | { | |
6227 | CORE_ADDR pc = expanded.sals[i].pc; | |
6228 | char *this_function; | |
6c95b8df PA |
6229 | |
6230 | /* We need to switch threads as well since we're about to | |
6231 | read memory. */ | |
6232 | switch_to_program_space_and_thread (expanded.sals[i].pspace); | |
6233 | ||
ed0616c6 VP |
6234 | if (find_pc_partial_function (pc, &this_function, |
6235 | &func_addr, &func_end)) | |
6236 | { | |
059fb39f PM |
6237 | if (this_function |
6238 | && strcmp (this_function, original_function) != 0) | |
ed0616c6 VP |
6239 | { |
6240 | remove_sal (&expanded, i); | |
6241 | --i; | |
6242 | } | |
6243 | else if (func_addr == pc) | |
6244 | { | |
6245 | /* We're at beginning of a function, and should | |
6246 | skip prologue. */ | |
6247 | struct symbol *sym = find_pc_function (pc); | |
6248 | if (sym) | |
6249 | expanded.sals[i] = find_function_start_sal (sym, 1); | |
6250 | else | |
d80b854b UW |
6251 | { |
6252 | /* Since find_pc_partial_function returned true, | |
6253 | we should really always find the section here. */ | |
6254 | struct obj_section *section = find_pc_section (pc); | |
6255 | if (section) | |
6256 | { | |
6257 | struct gdbarch *gdbarch | |
6258 | = get_objfile_arch (section->objfile); | |
6259 | expanded.sals[i].pc | |
6260 | = gdbarch_skip_prologue (gdbarch, pc); | |
6261 | } | |
6262 | } | |
ed0616c6 VP |
6263 | } |
6264 | } | |
6265 | } | |
6266 | } | |
3daf8fe5 JG |
6267 | else |
6268 | { | |
6269 | for (i = 0; i < expanded.nelts; ++i) | |
6270 | { | |
6271 | /* If this SAL corresponds to a breakpoint inserted using a | |
6272 | line number, then skip the function prologue if necessary. */ | |
6273 | skip_prologue_sal (&expanded.sals[i]); | |
6274 | } | |
6275 | } | |
ed0616c6 | 6276 | |
6c95b8df PA |
6277 | do_cleanups (old_chain); |
6278 | ||
ed0616c6 VP |
6279 | if (expanded.nelts <= 1) |
6280 | { | |
6281 | /* This is un ugly workaround. If we get zero | |
6282 | expanded sals then something is really wrong. | |
6283 | Fix that by returnign the original sal. */ | |
6284 | xfree (expanded.sals); | |
6285 | expanded.nelts = 1; | |
6286 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
6287 | sal.pc = original_pc; | |
6288 | expanded.sals[0] = sal; | |
6289 | return expanded; | |
6290 | } | |
6291 | ||
6292 | if (original_pc) | |
6293 | { | |
6294 | found = 0; | |
6295 | for (i = 0; i < expanded.nelts; ++i) | |
6296 | if (expanded.sals[i].pc == original_pc) | |
6297 | { | |
6298 | found = 1; | |
6299 | break; | |
6300 | } | |
6301 | gdb_assert (found); | |
6302 | } | |
6303 | ||
6304 | return expanded; | |
6305 | } | |
6306 | ||
018d34a4 VP |
6307 | /* Add SALS.nelts breakpoints to the breakpoint table. For each |
6308 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
6309 | value. COND_STRING, if not NULL, specified the condition to be | |
6310 | used for all breakpoints. Essentially the only case where | |
6311 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
6312 | function. In that case, it's still not possible to specify | |
6313 | separate conditions for different overloaded functions, so | |
6314 | we take just a single condition string. | |
6315 | ||
c3f6f71d | 6316 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 6317 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
6318 | array contents). If the function fails (error() is called), the |
6319 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
6320 | COND and SALS arrays and each of those arrays contents. */ | |
c906108c SS |
6321 | |
6322 | static void | |
a6d9a66e UW |
6323 | create_breakpoints (struct gdbarch *gdbarch, |
6324 | struct symtabs_and_lines sals, char **addr_string, | |
018d34a4 | 6325 | char *cond_string, |
c3f6f71d | 6326 | enum bptype type, enum bpdisp disposition, |
4a306c9a | 6327 | int thread, int task, int ignore_count, |
41447f92 VP |
6328 | struct breakpoint_ops *ops, int from_tty, |
6329 | int enabled) | |
c906108c | 6330 | { |
018d34a4 VP |
6331 | int i; |
6332 | for (i = 0; i < sals.nelts; ++i) | |
c3f6f71d | 6333 | { |
ed0616c6 VP |
6334 | struct symtabs_and_lines expanded = |
6335 | expand_line_sal_maybe (sals.sals[i]); | |
0d381245 | 6336 | |
a6d9a66e | 6337 | create_breakpoint (gdbarch, expanded, addr_string[i], |
018d34a4 | 6338 | cond_string, type, disposition, |
4a306c9a | 6339 | thread, task, ignore_count, ops, from_tty, enabled); |
c3f6f71d | 6340 | } |
c3f6f71d | 6341 | } |
c906108c | 6342 | |
c3f6f71d JM |
6343 | /* Parse ARG which is assumed to be a SAL specification possibly |
6344 | followed by conditionals. On return, SALS contains an array of SAL | |
6345 | addresses found. ADDR_STRING contains a vector of (canonical) | |
6346 | address strings. ARG points to the end of the SAL. */ | |
c906108c | 6347 | |
b9362cc7 | 6348 | static void |
c3f6f71d JM |
6349 | parse_breakpoint_sals (char **address, |
6350 | struct symtabs_and_lines *sals, | |
0101ce28 JJ |
6351 | char ***addr_string, |
6352 | int *not_found_ptr) | |
c3f6f71d JM |
6353 | { |
6354 | char *addr_start = *address; | |
6355 | *addr_string = NULL; | |
6356 | /* If no arg given, or if first arg is 'if ', use the default | |
6357 | breakpoint. */ | |
6358 | if ((*address) == NULL | |
6359 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c SS |
6360 | { |
6361 | if (default_breakpoint_valid) | |
6362 | { | |
c3f6f71d | 6363 | struct symtab_and_line sal; |
fe39c653 | 6364 | init_sal (&sal); /* initialize to zeroes */ |
c3f6f71d | 6365 | sals->sals = (struct symtab_and_line *) |
c906108c SS |
6366 | xmalloc (sizeof (struct symtab_and_line)); |
6367 | sal.pc = default_breakpoint_address; | |
6368 | sal.line = default_breakpoint_line; | |
6369 | sal.symtab = default_breakpoint_symtab; | |
6c95b8df | 6370 | sal.pspace = default_breakpoint_pspace; |
c5aa993b | 6371 | sal.section = find_pc_overlay (sal.pc); |
00903456 JK |
6372 | |
6373 | /* "break" without arguments is equivalent to "break *PC" where PC is | |
6374 | the default_breakpoint_address. So make sure to set | |
6375 | sal.explicit_pc to prevent GDB from trying to expand the list of | |
6376 | sals to include all other instances with the same symtab and line. | |
6377 | */ | |
6378 | sal.explicit_pc = 1; | |
6379 | ||
c3f6f71d JM |
6380 | sals->sals[0] = sal; |
6381 | sals->nelts = 1; | |
c906108c SS |
6382 | } |
6383 | else | |
8a3fe4f8 | 6384 | error (_("No default breakpoint address now.")); |
c906108c SS |
6385 | } |
6386 | else | |
6387 | { | |
c906108c | 6388 | /* Force almost all breakpoints to be in terms of the |
c5aa993b JM |
6389 | current_source_symtab (which is decode_line_1's default). This |
6390 | should produce the results we want almost all of the time while | |
1aeae86e AF |
6391 | leaving default_breakpoint_* alone. |
6392 | ObjC: However, don't match an Objective-C method name which | |
6393 | may have a '+' or '-' succeeded by a '[' */ | |
0378c332 | 6394 | |
c214a6fd | 6395 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
0378c332 | 6396 | |
c906108c | 6397 | if (default_breakpoint_valid |
0378c332 | 6398 | && (!cursal.symtab |
1aeae86e AF |
6399 | || ((strchr ("+-", (*address)[0]) != NULL) |
6400 | && ((*address)[1] != '[')))) | |
c3f6f71d | 6401 | *sals = decode_line_1 (address, 1, default_breakpoint_symtab, |
0101ce28 JJ |
6402 | default_breakpoint_line, addr_string, |
6403 | not_found_ptr); | |
c906108c | 6404 | else |
0101ce28 JJ |
6405 | *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, |
6406 | addr_string, not_found_ptr); | |
c906108c | 6407 | } |
c3f6f71d JM |
6408 | /* For any SAL that didn't have a canonical string, fill one in. */ |
6409 | if (sals->nelts > 0 && *addr_string == NULL) | |
6410 | *addr_string = xcalloc (sals->nelts, sizeof (char **)); | |
6411 | if (addr_start != (*address)) | |
c906108c | 6412 | { |
c3f6f71d JM |
6413 | int i; |
6414 | for (i = 0; i < sals->nelts; i++) | |
c906108c | 6415 | { |
c3f6f71d JM |
6416 | /* Add the string if not present. */ |
6417 | if ((*addr_string)[i] == NULL) | |
6418 | (*addr_string)[i] = savestring (addr_start, (*address) - addr_start); | |
c906108c SS |
6419 | } |
6420 | } | |
c3f6f71d | 6421 | } |
c906108c | 6422 | |
c906108c | 6423 | |
c3f6f71d JM |
6424 | /* Convert each SAL into a real PC. Verify that the PC can be |
6425 | inserted as a breakpoint. If it can't throw an error. */ | |
c906108c | 6426 | |
b9362cc7 | 6427 | static void |
c3f6f71d JM |
6428 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals, |
6429 | char *address) | |
6430 | { | |
6431 | int i; | |
6432 | for (i = 0; i < sals->nelts; i++) | |
ee53e872 | 6433 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
6434 | } |
6435 | ||
05ff989b | 6436 | static void |
0101ce28 JJ |
6437 | do_captured_parse_breakpoint (struct ui_out *ui, void *data) |
6438 | { | |
6439 | struct captured_parse_breakpoint_args *args = data; | |
6440 | ||
6441 | parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p, | |
6442 | args->not_found_ptr); | |
0101ce28 JJ |
6443 | } |
6444 | ||
018d34a4 VP |
6445 | /* Given TOK, a string specification of condition and thread, as |
6446 | accepted by the 'break' command, extract the condition | |
6447 | string and thread number and set *COND_STRING and *THREAD. | |
6448 | PC identifies the context at which the condition should be parsed. | |
6449 | If no condition is found, *COND_STRING is set to NULL. | |
6450 | If no thread is found, *THREAD is set to -1. */ | |
6451 | static void | |
6452 | find_condition_and_thread (char *tok, CORE_ADDR pc, | |
4a306c9a | 6453 | char **cond_string, int *thread, int *task) |
018d34a4 VP |
6454 | { |
6455 | *cond_string = NULL; | |
6456 | *thread = -1; | |
6457 | while (tok && *tok) | |
6458 | { | |
6459 | char *end_tok; | |
6460 | int toklen; | |
6461 | char *cond_start = NULL; | |
6462 | char *cond_end = NULL; | |
6463 | while (*tok == ' ' || *tok == '\t') | |
6464 | tok++; | |
6465 | ||
6466 | end_tok = tok; | |
6467 | ||
6468 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
6469 | end_tok++; | |
6470 | ||
6471 | toklen = end_tok - tok; | |
6472 | ||
6473 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
6474 | { | |
f7545552 TT |
6475 | struct expression *expr; |
6476 | ||
018d34a4 | 6477 | tok = cond_start = end_tok + 1; |
f7545552 TT |
6478 | expr = parse_exp_1 (&tok, block_for_pc (pc), 0); |
6479 | xfree (expr); | |
018d34a4 VP |
6480 | cond_end = tok; |
6481 | *cond_string = savestring (cond_start, | |
6482 | cond_end - cond_start); | |
6483 | } | |
6484 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
6485 | { | |
6486 | char *tmptok; | |
6487 | ||
6488 | tok = end_tok + 1; | |
6489 | tmptok = tok; | |
6490 | *thread = strtol (tok, &tok, 0); | |
6491 | if (tok == tmptok) | |
6492 | error (_("Junk after thread keyword.")); | |
6493 | if (!valid_thread_id (*thread)) | |
6494 | error (_("Unknown thread %d."), *thread); | |
6495 | } | |
4a306c9a JB |
6496 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
6497 | { | |
6498 | char *tmptok; | |
6499 | ||
6500 | tok = end_tok + 1; | |
6501 | tmptok = tok; | |
6502 | *task = strtol (tok, &tok, 0); | |
6503 | if (tok == tmptok) | |
6504 | error (_("Junk after task keyword.")); | |
6505 | if (!valid_task_id (*task)) | |
6506 | error (_("Unknown task %d\n"), *task); | |
6507 | } | |
018d34a4 VP |
6508 | else |
6509 | error (_("Junk at end of arguments.")); | |
6510 | } | |
6511 | } | |
6512 | ||
72b2ff0e VP |
6513 | /* Set a breakpoint. This function is shared between |
6514 | CLI and MI functions for setting a breakpoint. | |
6515 | This function has two major modes of operations, | |
6516 | selected by the PARSE_CONDITION_AND_THREAD parameter. | |
6517 | If non-zero, the function will parse arg, extracting | |
6518 | breakpoint location, address and thread. Otherwise, | |
6519 | ARG is just the location of breakpoint, with condition | |
6520 | and thread specified by the COND_STRING and THREAD | |
6521 | parameters. */ | |
0101ce28 | 6522 | |
98deb0da | 6523 | static void |
a6d9a66e UW |
6524 | break_command_really (struct gdbarch *gdbarch, |
6525 | char *arg, char *cond_string, int thread, | |
60c46647 | 6526 | int parse_condition_and_thread, |
1042e4c0 | 6527 | int tempflag, int hardwareflag, int traceflag, |
60c46647 VP |
6528 | int ignore_count, |
6529 | enum auto_boolean pending_break_support, | |
604133b5 | 6530 | struct breakpoint_ops *ops, |
41447f92 VP |
6531 | int from_tty, |
6532 | int enabled) | |
c3f6f71d | 6533 | { |
71fff37b | 6534 | struct gdb_exception e; |
c3f6f71d | 6535 | struct symtabs_and_lines sals; |
0101ce28 | 6536 | struct symtab_and_line pending_sal; |
0101ce28 JJ |
6537 | char *copy_arg; |
6538 | char *err_msg; | |
c3f6f71d JM |
6539 | char *addr_start = arg; |
6540 | char **addr_string; | |
6541 | struct cleanup *old_chain; | |
80c99de1 | 6542 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 6543 | struct captured_parse_breakpoint_args parse_args; |
05ff989b | 6544 | int i; |
0101ce28 | 6545 | int pending = 0; |
0101ce28 | 6546 | int not_found = 0; |
1042e4c0 | 6547 | enum bptype type_wanted; |
4a306c9a | 6548 | int task = 0; |
c3f6f71d | 6549 | |
c3f6f71d JM |
6550 | sals.sals = NULL; |
6551 | sals.nelts = 0; | |
6552 | addr_string = NULL; | |
c3f6f71d | 6553 | |
0101ce28 JJ |
6554 | parse_args.arg_p = &arg; |
6555 | parse_args.sals_p = &sals; | |
6556 | parse_args.addr_string_p = &addr_string; | |
6557 | parse_args.not_found_ptr = ¬_found; | |
6558 | ||
05ff989b AC |
6559 | e = catch_exception (uiout, do_captured_parse_breakpoint, |
6560 | &parse_args, RETURN_MASK_ALL); | |
0101ce28 JJ |
6561 | |
6562 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 6563 | switch (e.reason) |
0101ce28 | 6564 | { |
05ff989b | 6565 | case RETURN_QUIT: |
98deb0da | 6566 | throw_exception (e); |
05ff989b AC |
6567 | case RETURN_ERROR: |
6568 | switch (e.error) | |
0101ce28 | 6569 | { |
05ff989b | 6570 | case NOT_FOUND_ERROR: |
0101ce28 | 6571 | |
05ff989b AC |
6572 | /* If pending breakpoint support is turned off, throw |
6573 | error. */ | |
fa8d40ab JJ |
6574 | |
6575 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
6576 | throw_exception (e); |
6577 | ||
6578 | exception_print (gdb_stderr, e); | |
fa8d40ab | 6579 | |
05ff989b AC |
6580 | /* If pending breakpoint support is auto query and the user |
6581 | selects no, then simply return the error code. */ | |
059fb39f PM |
6582 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
6583 | && !nquery ("Make breakpoint pending on future shared library load? ")) | |
98deb0da | 6584 | return; |
fa8d40ab | 6585 | |
05ff989b AC |
6586 | /* At this point, either the user was queried about setting |
6587 | a pending breakpoint and selected yes, or pending | |
6588 | breakpoint behavior is on and thus a pending breakpoint | |
6589 | is defaulted on behalf of the user. */ | |
0101ce28 JJ |
6590 | copy_arg = xstrdup (addr_start); |
6591 | addr_string = ©_arg; | |
6592 | sals.nelts = 1; | |
6593 | sals.sals = &pending_sal; | |
6594 | pending_sal.pc = 0; | |
6595 | pending = 1; | |
05ff989b AC |
6596 | break; |
6597 | default: | |
98deb0da | 6598 | throw_exception (e); |
0101ce28 | 6599 | } |
05ff989b AC |
6600 | default: |
6601 | if (!sals.nelts) | |
98deb0da | 6602 | return; |
0101ce28 | 6603 | } |
c3f6f71d JM |
6604 | |
6605 | /* Create a chain of things that always need to be cleaned up. */ | |
6606 | old_chain = make_cleanup (null_cleanup, 0); | |
6607 | ||
0101ce28 JJ |
6608 | if (!pending) |
6609 | { | |
6610 | /* Make sure that all storage allocated to SALS gets freed. */ | |
6611 | make_cleanup (xfree, sals.sals); | |
6612 | ||
6613 | /* Cleanup the addr_string array but not its contents. */ | |
6614 | make_cleanup (xfree, addr_string); | |
6615 | } | |
c3f6f71d | 6616 | |
c3f6f71d JM |
6617 | /* ----------------------------- SNIP ----------------------------- |
6618 | Anything added to the cleanup chain beyond this point is assumed | |
6619 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
6620 | then the memory is not reclaimed. */ |
6621 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d JM |
6622 | |
6623 | /* Mark the contents of the addr_string for cleanup. These go on | |
80c99de1 | 6624 | the bkpt_chain and only occur if the breakpoint create fails. */ |
c3f6f71d JM |
6625 | for (i = 0; i < sals.nelts; i++) |
6626 | { | |
6627 | if (addr_string[i] != NULL) | |
b8c9b27d | 6628 | make_cleanup (xfree, addr_string[i]); |
c3f6f71d JM |
6629 | } |
6630 | ||
6631 | /* Resolve all line numbers to PC's and verify that the addresses | |
6632 | are ok for the target. */ | |
0101ce28 JJ |
6633 | if (!pending) |
6634 | breakpoint_sals_to_pc (&sals, addr_start); | |
c3f6f71d | 6635 | |
1042e4c0 SS |
6636 | type_wanted = (traceflag |
6637 | ? bp_tracepoint | |
6638 | : (hardwareflag ? bp_hardware_breakpoint : bp_breakpoint)); | |
6639 | ||
c3f6f71d JM |
6640 | /* Verify that condition can be parsed, before setting any |
6641 | breakpoints. Allocate a separate condition expression for each | |
6642 | breakpoint. */ | |
0101ce28 | 6643 | if (!pending) |
c3f6f71d | 6644 | { |
2f069f6f | 6645 | if (parse_condition_and_thread) |
72b2ff0e VP |
6646 | { |
6647 | /* Here we only parse 'arg' to separate condition | |
6648 | from thread number, so parsing in context of first | |
6649 | sal is OK. When setting the breakpoint we'll | |
6650 | re-parse it in context of each sal. */ | |
6651 | cond_string = NULL; | |
6652 | thread = -1; | |
4a306c9a JB |
6653 | find_condition_and_thread (arg, sals.sals[0].pc, &cond_string, |
6654 | &thread, &task); | |
72b2ff0e VP |
6655 | if (cond_string) |
6656 | make_cleanup (xfree, cond_string); | |
6657 | } | |
2f069f6f | 6658 | else |
72b2ff0e VP |
6659 | { |
6660 | /* Create a private copy of condition string. */ | |
6661 | if (cond_string) | |
6662 | { | |
6663 | cond_string = xstrdup (cond_string); | |
6664 | make_cleanup (xfree, cond_string); | |
6665 | } | |
6666 | } | |
a6d9a66e | 6667 | create_breakpoints (gdbarch, sals, addr_string, cond_string, type_wanted, |
0101ce28 | 6668 | tempflag ? disp_del : disp_donttouch, |
4a306c9a | 6669 | thread, task, ignore_count, ops, from_tty, enabled); |
c906108c | 6670 | } |
0101ce28 JJ |
6671 | else |
6672 | { | |
fe3f5fa8 | 6673 | struct symtab_and_line sal = {0}; |
0101ce28 JJ |
6674 | struct breakpoint *b; |
6675 | ||
0101ce28 JJ |
6676 | make_cleanup (xfree, copy_arg); |
6677 | ||
a6d9a66e | 6678 | b = set_raw_breakpoint_without_location (gdbarch, type_wanted); |
0101ce28 JJ |
6679 | set_breakpoint_count (breakpoint_count + 1); |
6680 | b->number = breakpoint_count; | |
72b2ff0e | 6681 | b->thread = -1; |
018d34a4 | 6682 | b->addr_string = addr_string[0]; |
72b2ff0e | 6683 | b->cond_string = NULL; |
0101ce28 | 6684 | b->ignore_count = ignore_count; |
0101ce28 | 6685 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 6686 | b->condition_not_parsed = 1; |
604133b5 | 6687 | b->ops = ops; |
41447f92 | 6688 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
6c95b8df | 6689 | b->pspace = current_program_space; |
74960c60 | 6690 | |
6c95b8df | 6691 | if (enabled && b->pspace->executing_startup |
8bea4e01 UW |
6692 | && (b->type == bp_breakpoint |
6693 | || b->type == bp_hardware_breakpoint)) | |
6694 | b->enable_state = bp_startup_disabled; | |
6695 | ||
0101ce28 JJ |
6696 | mention (b); |
6697 | } | |
6698 | ||
c3f6f71d | 6699 | if (sals.nelts > 1) |
8a3fe4f8 AC |
6700 | warning (_("Multiple breakpoints were set.\n" |
6701 | "Use the \"delete\" command to delete unwanted breakpoints.")); | |
80c99de1 PA |
6702 | /* That's it. Discard the cleanups for data inserted into the |
6703 | breakpoint. */ | |
6704 | discard_cleanups (bkpt_chain); | |
6705 | /* But cleanup everything else. */ | |
c3f6f71d | 6706 | do_cleanups (old_chain); |
217dc9e2 | 6707 | |
80c99de1 | 6708 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
217dc9e2 | 6709 | update_global_location_list (1); |
c3f6f71d | 6710 | } |
c906108c | 6711 | |
72b2ff0e VP |
6712 | /* Set a breakpoint. |
6713 | ARG is a string describing breakpoint address, | |
6714 | condition, and thread. | |
6715 | FLAG specifies if a breakpoint is hardware on, | |
6716 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
6717 | and BP_TEMPFLAG. */ | |
6718 | ||
98deb0da | 6719 | static void |
72b2ff0e | 6720 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 6721 | { |
72b2ff0e VP |
6722 | int hardwareflag = flag & BP_HARDWAREFLAG; |
6723 | int tempflag = flag & BP_TEMPFLAG; | |
c3f6f71d | 6724 | |
a6d9a66e UW |
6725 | break_command_really (get_current_arch (), |
6726 | arg, | |
98deb0da | 6727 | NULL, 0, 1 /* parse arg */, |
1042e4c0 | 6728 | tempflag, hardwareflag, 0 /* traceflag */, |
98deb0da | 6729 | 0 /* Ignore count */, |
604133b5 AR |
6730 | pending_break_support, |
6731 | NULL /* breakpoint_ops */, | |
41447f92 VP |
6732 | from_tty, |
6733 | 1 /* enabled */); | |
c906108c SS |
6734 | } |
6735 | ||
72b2ff0e | 6736 | |
98deb0da | 6737 | void |
a6d9a66e UW |
6738 | set_breakpoint (struct gdbarch *gdbarch, |
6739 | char *address, char *condition, | |
c3f6f71d | 6740 | int hardwareflag, int tempflag, |
ce43223b | 6741 | int thread, int ignore_count, |
41447f92 | 6742 | int pending, int enabled) |
c3f6f71d | 6743 | { |
a6d9a66e UW |
6744 | break_command_really (gdbarch, |
6745 | address, condition, thread, | |
98deb0da | 6746 | 0 /* condition and thread are valid. */, |
1042e4c0 | 6747 | tempflag, hardwareflag, 0 /* traceflag */, |
98deb0da VP |
6748 | ignore_count, |
6749 | pending | |
6750 | ? AUTO_BOOLEAN_TRUE : AUTO_BOOLEAN_FALSE, | |
41447f92 | 6751 | NULL, 0, enabled); |
c3f6f71d JM |
6752 | } |
6753 | ||
6a048695 JB |
6754 | /* Adjust SAL to the first instruction past the function prologue. |
6755 | The end of the prologue is determined using the line table from | |
3daf8fe5 JG |
6756 | the debugging information. explicit_pc and explicit_line are |
6757 | not modified. | |
6a048695 JB |
6758 | |
6759 | If SAL is already past the prologue, then do nothing. */ | |
6760 | ||
6761 | static void | |
6762 | skip_prologue_sal (struct symtab_and_line *sal) | |
6763 | { | |
6c95b8df | 6764 | struct symbol *sym; |
6a048695 | 6765 | struct symtab_and_line start_sal; |
6c95b8df | 6766 | struct cleanup *old_chain; |
6a048695 | 6767 | |
6c95b8df | 6768 | old_chain = save_current_space_and_thread (); |
6a048695 | 6769 | |
6c95b8df PA |
6770 | sym = find_pc_function (sal->pc); |
6771 | if (sym != NULL) | |
3daf8fe5 | 6772 | { |
6c95b8df PA |
6773 | start_sal = find_function_start_sal (sym, 1); |
6774 | if (sal->pc < start_sal.pc) | |
6775 | { | |
6776 | start_sal.explicit_line = sal->explicit_line; | |
6777 | start_sal.explicit_pc = sal->explicit_pc; | |
6778 | *sal = start_sal; | |
6779 | } | |
3daf8fe5 | 6780 | } |
6c95b8df PA |
6781 | |
6782 | do_cleanups (old_chain); | |
6a048695 | 6783 | } |
c3f6f71d | 6784 | |
c906108c SS |
6785 | /* Helper function for break_command_1 and disassemble_command. */ |
6786 | ||
6787 | void | |
fba45db2 | 6788 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
6789 | { |
6790 | CORE_ADDR pc; | |
6791 | ||
6792 | if (sal->pc == 0 && sal->symtab != NULL) | |
6793 | { | |
6794 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 6795 | error (_("No line %d in file \"%s\"."), |
c906108c SS |
6796 | sal->line, sal->symtab->filename); |
6797 | sal->pc = pc; | |
6a048695 JB |
6798 | |
6799 | /* If this SAL corresponds to a breakpoint inserted using | |
6800 | a line number, then skip the function prologue if necessary. */ | |
6801 | if (sal->explicit_line) | |
56ef84b1 TT |
6802 | { |
6803 | /* Preserve the original line number. */ | |
6804 | int saved_line = sal->line; | |
6805 | skip_prologue_sal (sal); | |
6806 | sal->line = saved_line; | |
6807 | } | |
c906108c SS |
6808 | } |
6809 | ||
6810 | if (sal->section == 0 && sal->symtab != NULL) | |
6811 | { | |
6812 | struct blockvector *bv; | |
c5aa993b JM |
6813 | struct block *b; |
6814 | struct symbol *sym; | |
c906108c | 6815 | |
801e3a5b | 6816 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
6817 | if (bv != NULL) |
6818 | { | |
7f0df278 | 6819 | sym = block_linkage_function (b); |
c906108c SS |
6820 | if (sym != NULL) |
6821 | { | |
6822 | fixup_symbol_section (sym, sal->symtab->objfile); | |
714835d5 | 6823 | sal->section = SYMBOL_OBJ_SECTION (sym); |
c906108c SS |
6824 | } |
6825 | else | |
6826 | { | |
6827 | /* It really is worthwhile to have the section, so we'll just | |
c5aa993b JM |
6828 | have to look harder. This case can be executed if we have |
6829 | line numbers but no functions (as can happen in assembly | |
6830 | source). */ | |
c906108c | 6831 | |
c5aa993b | 6832 | struct minimal_symbol *msym; |
6c95b8df PA |
6833 | struct cleanup *old_chain = save_current_space_and_thread (); |
6834 | ||
6835 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
6836 | |
6837 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
6838 | if (msym) | |
714835d5 | 6839 | sal->section = SYMBOL_OBJ_SECTION (msym); |
6c95b8df PA |
6840 | |
6841 | do_cleanups (old_chain); | |
c906108c SS |
6842 | } |
6843 | } | |
6844 | } | |
6845 | } | |
6846 | ||
6847 | void | |
fba45db2 | 6848 | break_command (char *arg, int from_tty) |
c906108c | 6849 | { |
db107f19 | 6850 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
6851 | } |
6852 | ||
c906108c | 6853 | void |
fba45db2 | 6854 | tbreak_command (char *arg, int from_tty) |
c906108c | 6855 | { |
db107f19 | 6856 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
6857 | } |
6858 | ||
c906108c | 6859 | static void |
fba45db2 | 6860 | hbreak_command (char *arg, int from_tty) |
c906108c | 6861 | { |
db107f19 | 6862 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
6863 | } |
6864 | ||
6865 | static void | |
fba45db2 | 6866 | thbreak_command (char *arg, int from_tty) |
c906108c | 6867 | { |
db107f19 | 6868 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
6869 | } |
6870 | ||
6871 | static void | |
fba45db2 | 6872 | stop_command (char *arg, int from_tty) |
c906108c | 6873 | { |
a3f17187 | 6874 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 6875 | Usage: stop in <function | address>\n\ |
a3f17187 | 6876 | stop at <line>\n")); |
c906108c SS |
6877 | } |
6878 | ||
6879 | static void | |
fba45db2 | 6880 | stopin_command (char *arg, int from_tty) |
c906108c SS |
6881 | { |
6882 | int badInput = 0; | |
6883 | ||
c5aa993b | 6884 | if (arg == (char *) NULL) |
c906108c SS |
6885 | badInput = 1; |
6886 | else if (*arg != '*') | |
6887 | { | |
6888 | char *argptr = arg; | |
6889 | int hasColon = 0; | |
6890 | ||
53a5351d JM |
6891 | /* look for a ':'. If this is a line number specification, then |
6892 | say it is bad, otherwise, it should be an address or | |
6893 | function/method name */ | |
c906108c | 6894 | while (*argptr && !hasColon) |
c5aa993b JM |
6895 | { |
6896 | hasColon = (*argptr == ':'); | |
6897 | argptr++; | |
6898 | } | |
c906108c SS |
6899 | |
6900 | if (hasColon) | |
c5aa993b | 6901 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 6902 | else |
c5aa993b | 6903 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
6904 | } |
6905 | ||
6906 | if (badInput) | |
a3f17187 | 6907 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 6908 | else |
db107f19 | 6909 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
6910 | } |
6911 | ||
6912 | static void | |
fba45db2 | 6913 | stopat_command (char *arg, int from_tty) |
c906108c SS |
6914 | { |
6915 | int badInput = 0; | |
6916 | ||
c5aa993b | 6917 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
6918 | badInput = 1; |
6919 | else | |
6920 | { | |
6921 | char *argptr = arg; | |
6922 | int hasColon = 0; | |
6923 | ||
6924 | /* look for a ':'. If there is a '::' then get out, otherwise | |
c5aa993b | 6925 | it is probably a line number. */ |
c906108c | 6926 | while (*argptr && !hasColon) |
c5aa993b JM |
6927 | { |
6928 | hasColon = (*argptr == ':'); | |
6929 | argptr++; | |
6930 | } | |
c906108c SS |
6931 | |
6932 | if (hasColon) | |
c5aa993b | 6933 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 6934 | else |
c5aa993b | 6935 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
6936 | } |
6937 | ||
6938 | if (badInput) | |
a3f17187 | 6939 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 6940 | else |
db107f19 | 6941 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
6942 | } |
6943 | ||
53a5351d JM |
6944 | /* accessflag: hw_write: watch write, |
6945 | hw_read: watch read, | |
6946 | hw_access: watch access (read or write) */ | |
c906108c | 6947 | static void |
fba45db2 | 6948 | watch_command_1 (char *arg, int accessflag, int from_tty) |
c906108c | 6949 | { |
a6d9a66e | 6950 | struct gdbarch *gdbarch = get_current_arch (); |
d983da9c | 6951 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c SS |
6952 | struct symtab_and_line sal; |
6953 | struct expression *exp; | |
6954 | struct block *exp_valid_block; | |
6955 | struct value *val, *mark; | |
6956 | struct frame_info *frame; | |
c906108c SS |
6957 | char *exp_start = NULL; |
6958 | char *exp_end = NULL; | |
37e4754d | 6959 | char *tok, *id_tok_start, *end_tok; |
c906108c SS |
6960 | int toklen; |
6961 | char *cond_start = NULL; | |
6962 | char *cond_end = NULL; | |
6963 | struct expression *cond = NULL; | |
6964 | int i, other_type_used, target_resources_ok = 0; | |
6965 | enum bptype bp_type; | |
6966 | int mem_cnt = 0; | |
37e4754d | 6967 | int thread = -1; |
c906108c | 6968 | |
fe39c653 | 6969 | init_sal (&sal); /* initialize to zeroes */ |
c5aa993b | 6970 | |
37e4754d LM |
6971 | /* Make sure that we actually have parameters to parse. */ |
6972 | if (arg != NULL && arg[0] != '\0') | |
6973 | { | |
6974 | toklen = strlen (arg); /* Size of argument list. */ | |
6975 | ||
6976 | /* Points tok to the end of the argument list. */ | |
6977 | tok = arg + toklen - 1; | |
6978 | ||
6979 | /* Go backwards in the parameters list. Skip the last parameter. | |
6980 | If we're expecting a 'thread <thread_num>' parameter, this should | |
6981 | be the thread identifier. */ | |
6982 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
6983 | tok--; | |
6984 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
6985 | tok--; | |
6986 | ||
6987 | /* Points end_tok to the beginning of the last token. */ | |
6988 | id_tok_start = tok + 1; | |
6989 | ||
6990 | /* Go backwards in the parameters list. Skip one more parameter. | |
6991 | If we're expecting a 'thread <thread_num>' parameter, we should | |
6992 | reach a "thread" token. */ | |
6993 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
6994 | tok--; | |
6995 | ||
6996 | end_tok = tok; | |
6997 | ||
6998 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
6999 | tok--; | |
7000 | ||
7001 | /* Move the pointer forward to skip the whitespace and | |
7002 | calculate the length of the token. */ | |
7003 | tok++; | |
7004 | toklen = end_tok - tok; | |
7005 | ||
7006 | if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
7007 | { | |
7008 | /* At this point we've found a "thread" token, which means | |
7009 | the user is trying to set a watchpoint that triggers | |
7010 | only in a specific thread. */ | |
7011 | char *endp; | |
7012 | ||
7013 | /* Extract the thread ID from the next token. */ | |
7014 | thread = strtol (id_tok_start, &endp, 0); | |
7015 | ||
7016 | /* Check if the user provided a valid numeric value for the | |
7017 | thread ID. */ | |
7018 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
7019 | error (_("Invalid thread ID specification %s."), id_tok_start); | |
7020 | ||
7021 | /* Check if the thread actually exists. */ | |
7022 | if (!valid_thread_id (thread)) | |
7023 | error (_("Unknown thread %d."), thread); | |
7024 | ||
7025 | /* Truncate the string and get rid of the thread <thread_num> | |
7026 | parameter before the parameter list is parsed by the | |
7027 | evaluate_expression() function. */ | |
7028 | *tok = '\0'; | |
7029 | } | |
7030 | } | |
7031 | ||
6c95b8df PA |
7032 | sal.pspace = current_program_space; |
7033 | ||
37e4754d | 7034 | /* Parse the rest of the arguments. */ |
c906108c SS |
7035 | innermost_block = NULL; |
7036 | exp_start = arg; | |
7037 | exp = parse_exp_1 (&arg, 0, 0); | |
7038 | exp_end = arg; | |
fa8a61dc TT |
7039 | /* Remove trailing whitespace from the expression before saving it. |
7040 | This makes the eventual display of the expression string a bit | |
7041 | prettier. */ | |
7042 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
7043 | --exp_end; | |
7044 | ||
c906108c SS |
7045 | exp_valid_block = innermost_block; |
7046 | mark = value_mark (); | |
fa4727a6 DJ |
7047 | fetch_watchpoint_value (exp, &val, NULL, NULL); |
7048 | if (val != NULL) | |
7049 | release_value (val); | |
c906108c SS |
7050 | |
7051 | tok = arg; | |
7052 | while (*tok == ' ' || *tok == '\t') | |
7053 | tok++; | |
7054 | end_tok = tok; | |
7055 | ||
7056 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
7057 | end_tok++; | |
7058 | ||
7059 | toklen = end_tok - tok; | |
7060 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
7061 | { | |
7062 | tok = cond_start = end_tok + 1; | |
7063 | cond = parse_exp_1 (&tok, 0, 0); | |
7064 | cond_end = tok; | |
7065 | } | |
7066 | if (*tok) | |
8a3fe4f8 | 7067 | error (_("Junk at end of command.")); |
c906108c | 7068 | |
53a5351d | 7069 | if (accessflag == hw_read) |
c5aa993b | 7070 | bp_type = bp_read_watchpoint; |
53a5351d | 7071 | else if (accessflag == hw_access) |
c5aa993b JM |
7072 | bp_type = bp_access_watchpoint; |
7073 | else | |
7074 | bp_type = bp_hardware_watchpoint; | |
c906108c SS |
7075 | |
7076 | mem_cnt = can_use_hardware_watchpoint (val); | |
7077 | if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint) | |
8a3fe4f8 | 7078 | error (_("Expression cannot be implemented with read/access watchpoint.")); |
c5aa993b JM |
7079 | if (mem_cnt != 0) |
7080 | { | |
7081 | i = hw_watchpoint_used_count (bp_type, &other_type_used); | |
53a5351d | 7082 | target_resources_ok = |
d92524f1 | 7083 | target_can_use_hardware_watchpoint (bp_type, i + mem_cnt, |
53a5351d | 7084 | other_type_used); |
c5aa993b | 7085 | if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint) |
8a3fe4f8 | 7086 | error (_("Target does not support this type of hardware watchpoint.")); |
53a5351d | 7087 | |
c5aa993b | 7088 | if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint) |
8a3fe4f8 | 7089 | error (_("Target can only support one kind of HW watchpoint at a time.")); |
c5aa993b | 7090 | } |
c906108c | 7091 | |
4d28f7a8 KB |
7092 | /* Change the type of breakpoint to an ordinary watchpoint if a hardware |
7093 | watchpoint could not be set. */ | |
7094 | if (!mem_cnt || target_resources_ok <= 0) | |
7095 | bp_type = bp_watchpoint; | |
7096 | ||
d983da9c | 7097 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
7098 | |
7099 | /* If the expression is "local", then set up a "watchpoint scope" | |
7100 | breakpoint at the point where we've left the scope of the watchpoint | |
7101 | expression. Create the scope breakpoint before the watchpoint, so | |
7102 | that we will encounter it first in bpstat_stop_status. */ | |
edb3359d | 7103 | if (innermost_block && frame) |
d983da9c | 7104 | { |
edb3359d DJ |
7105 | if (frame_id_p (frame_unwind_caller_id (frame))) |
7106 | { | |
7107 | scope_breakpoint | |
a6d9a66e UW |
7108 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
7109 | frame_unwind_caller_pc (frame), | |
edb3359d | 7110 | bp_watchpoint_scope); |
d983da9c | 7111 | |
edb3359d | 7112 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 7113 | |
edb3359d DJ |
7114 | /* Automatically delete the breakpoint when it hits. */ |
7115 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 7116 | |
edb3359d DJ |
7117 | /* Only break in the proper frame (help with recursion). */ |
7118 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 7119 | |
edb3359d | 7120 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
7121 | scope_breakpoint->loc->gdbarch |
7122 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
7123 | scope_breakpoint->loc->requested_address |
7124 | = frame_unwind_caller_pc (frame); | |
7125 | scope_breakpoint->loc->address | |
a6d9a66e UW |
7126 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
7127 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
7128 | scope_breakpoint->type); |
7129 | } | |
d983da9c DJ |
7130 | } |
7131 | ||
c906108c | 7132 | /* Now set up the breakpoint. */ |
a6d9a66e | 7133 | b = set_raw_breakpoint (gdbarch, sal, bp_type); |
c906108c SS |
7134 | set_breakpoint_count (breakpoint_count + 1); |
7135 | b->number = breakpoint_count; | |
37e4754d | 7136 | b->thread = thread; |
b5de0fa7 | 7137 | b->disposition = disp_donttouch; |
c906108c SS |
7138 | b->exp = exp; |
7139 | b->exp_valid_block = exp_valid_block; | |
7140 | b->exp_string = savestring (exp_start, exp_end - exp_start); | |
7141 | b->val = val; | |
fa4727a6 | 7142 | b->val_valid = 1; |
511a6cd4 | 7143 | b->loc->cond = cond; |
c906108c SS |
7144 | if (cond_start) |
7145 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
7146 | else | |
7147 | b->cond_string = 0; | |
c5aa993b | 7148 | |
c906108c | 7149 | if (frame) |
d983da9c | 7150 | b->watchpoint_frame = get_frame_id (frame); |
c906108c | 7151 | else |
35a487f1 | 7152 | b->watchpoint_frame = null_frame_id; |
c906108c | 7153 | |
d983da9c | 7154 | if (scope_breakpoint != NULL) |
c906108c | 7155 | { |
d983da9c DJ |
7156 | /* The scope breakpoint is related to the watchpoint. We will |
7157 | need to act on them together. */ | |
7158 | b->related_breakpoint = scope_breakpoint; | |
7159 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 7160 | } |
d983da9c | 7161 | |
c906108c SS |
7162 | value_free_to_mark (mark); |
7163 | mention (b); | |
b60e7edf | 7164 | update_global_location_list (1); |
c906108c SS |
7165 | } |
7166 | ||
7167 | /* Return count of locations need to be watched and can be handled | |
7168 | in hardware. If the watchpoint can not be handled | |
7169 | in hardware return zero. */ | |
7170 | ||
c906108c | 7171 | static int |
fba45db2 | 7172 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
7173 | { |
7174 | int found_memory_cnt = 0; | |
2e70b7b9 | 7175 | struct value *head = v; |
c906108c SS |
7176 | |
7177 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 7178 | if (!can_use_hw_watchpoints) |
c906108c | 7179 | return 0; |
c5aa993b | 7180 | |
5c44784c JM |
7181 | /* Make sure that the value of the expression depends only upon |
7182 | memory contents, and values computed from them within GDB. If we | |
7183 | find any register references or function calls, we can't use a | |
7184 | hardware watchpoint. | |
7185 | ||
7186 | The idea here is that evaluating an expression generates a series | |
7187 | of values, one holding the value of every subexpression. (The | |
7188 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
7189 | a*b+c.) GDB's values hold almost enough information to establish | |
7190 | the criteria given above --- they identify memory lvalues, | |
7191 | register lvalues, computed values, etcetera. So we can evaluate | |
7192 | the expression, and then scan the chain of values that leaves | |
7193 | behind to decide whether we can detect any possible change to the | |
7194 | expression's final value using only hardware watchpoints. | |
7195 | ||
7196 | However, I don't think that the values returned by inferior | |
7197 | function calls are special in any way. So this function may not | |
7198 | notice that an expression involving an inferior function call | |
7199 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 7200 | for (; v; v = value_next (v)) |
c906108c | 7201 | { |
5c44784c | 7202 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 7203 | { |
d69fe07e | 7204 | if (value_lazy (v)) |
5c44784c JM |
7205 | /* A lazy memory lvalue is one that GDB never needed to fetch; |
7206 | we either just used its address (e.g., `a' in `a.b') or | |
7207 | we never needed it at all (e.g., `a' in `a,b'). */ | |
7208 | ; | |
53a5351d | 7209 | else |
5c44784c JM |
7210 | { |
7211 | /* Ahh, memory we actually used! Check if we can cover | |
7212 | it with hardware watchpoints. */ | |
df407dfe | 7213 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
7214 | |
7215 | /* We only watch structs and arrays if user asked for it | |
7216 | explicitly, never if they just happen to appear in a | |
7217 | middle of some value chain. */ | |
7218 | if (v == head | |
7219 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
7220 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
7221 | { | |
42ae5230 | 7222 | CORE_ADDR vaddr = value_address (v); |
df407dfe | 7223 | int len = TYPE_LENGTH (value_type (v)); |
2e70b7b9 | 7224 | |
d92524f1 | 7225 | if (!target_region_ok_for_hw_watchpoint (vaddr, len)) |
2e70b7b9 MS |
7226 | return 0; |
7227 | else | |
7228 | found_memory_cnt++; | |
7229 | } | |
5c44784c | 7230 | } |
c5aa993b | 7231 | } |
5086187c AC |
7232 | else if (VALUE_LVAL (v) != not_lval |
7233 | && deprecated_value_modifiable (v) == 0) | |
53a5351d | 7234 | return 0; /* ??? What does this represent? */ |
5086187c | 7235 | else if (VALUE_LVAL (v) == lval_register) |
53a5351d | 7236 | return 0; /* cannot watch a register with a HW watchpoint */ |
c906108c SS |
7237 | } |
7238 | ||
7239 | /* The expression itself looks suitable for using a hardware | |
7240 | watchpoint, but give the target machine a chance to reject it. */ | |
7241 | return found_memory_cnt; | |
7242 | } | |
7243 | ||
8b93c638 | 7244 | void |
fba45db2 | 7245 | watch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
7246 | { |
7247 | watch_command (arg, from_tty); | |
7248 | } | |
8926118c | 7249 | |
c5aa993b | 7250 | static void |
fba45db2 | 7251 | watch_command (char *arg, int from_tty) |
c906108c | 7252 | { |
53a5351d | 7253 | watch_command_1 (arg, hw_write, from_tty); |
c906108c SS |
7254 | } |
7255 | ||
8b93c638 | 7256 | void |
fba45db2 | 7257 | rwatch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
7258 | { |
7259 | rwatch_command (arg, from_tty); | |
7260 | } | |
8926118c | 7261 | |
c5aa993b | 7262 | static void |
fba45db2 | 7263 | rwatch_command (char *arg, int from_tty) |
c906108c | 7264 | { |
53a5351d | 7265 | watch_command_1 (arg, hw_read, from_tty); |
c906108c SS |
7266 | } |
7267 | ||
8b93c638 | 7268 | void |
fba45db2 | 7269 | awatch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
7270 | { |
7271 | awatch_command (arg, from_tty); | |
7272 | } | |
8926118c | 7273 | |
c5aa993b | 7274 | static void |
fba45db2 | 7275 | awatch_command (char *arg, int from_tty) |
c906108c | 7276 | { |
53a5351d | 7277 | watch_command_1 (arg, hw_access, from_tty); |
c906108c | 7278 | } |
c906108c | 7279 | \f |
c5aa993b | 7280 | |
43ff13b4 | 7281 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
7282 | because it uses the mechanisms of breakpoints. */ |
7283 | ||
bfec99b2 PA |
7284 | struct until_break_command_continuation_args |
7285 | { | |
7286 | struct breakpoint *breakpoint; | |
7287 | struct breakpoint *breakpoint2; | |
7288 | }; | |
7289 | ||
43ff13b4 JM |
7290 | /* This function is called by fetch_inferior_event via the |
7291 | cmd_continuation pointer, to complete the until command. It takes | |
7292 | care of cleaning up the temporary breakpoints set up by the until | |
7293 | command. */ | |
c2c6d25f | 7294 | static void |
604ead4a | 7295 | until_break_command_continuation (void *arg) |
43ff13b4 | 7296 | { |
bfec99b2 PA |
7297 | struct until_break_command_continuation_args *a = arg; |
7298 | ||
7299 | delete_breakpoint (a->breakpoint); | |
7300 | if (a->breakpoint2) | |
7301 | delete_breakpoint (a->breakpoint2); | |
43ff13b4 JM |
7302 | } |
7303 | ||
c906108c | 7304 | void |
ae66c1fc | 7305 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
7306 | { |
7307 | struct symtabs_and_lines sals; | |
7308 | struct symtab_and_line sal; | |
206415a3 | 7309 | struct frame_info *frame = get_selected_frame (NULL); |
c906108c | 7310 | struct breakpoint *breakpoint; |
f107f563 | 7311 | struct breakpoint *breakpoint2 = NULL; |
c906108c SS |
7312 | struct cleanup *old_chain; |
7313 | ||
7314 | clear_proceed_status (); | |
7315 | ||
7316 | /* Set a breakpoint where the user wants it and at return from | |
7317 | this function */ | |
c5aa993b | 7318 | |
c906108c SS |
7319 | if (default_breakpoint_valid) |
7320 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, | |
68219205 | 7321 | default_breakpoint_line, (char ***) NULL, NULL); |
c906108c | 7322 | else |
53a5351d | 7323 | sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, |
68219205 | 7324 | 0, (char ***) NULL, NULL); |
c5aa993b | 7325 | |
c906108c | 7326 | if (sals.nelts != 1) |
8a3fe4f8 | 7327 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 7328 | |
c906108c | 7329 | sal = sals.sals[0]; |
b8c9b27d | 7330 | xfree (sals.sals); /* malloc'd, so freed */ |
c5aa993b | 7331 | |
c906108c | 7332 | if (*arg) |
8a3fe4f8 | 7333 | error (_("Junk at end of arguments.")); |
c5aa993b | 7334 | |
c906108c | 7335 | resolve_sal_pc (&sal); |
c5aa993b | 7336 | |
ae66c1fc EZ |
7337 | if (anywhere) |
7338 | /* If the user told us to continue until a specified location, | |
7339 | we don't specify a frame at which we need to stop. */ | |
a6d9a66e UW |
7340 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
7341 | null_frame_id, bp_until); | |
ae66c1fc | 7342 | else |
edb3359d | 7343 | /* Otherwise, specify the selected frame, because we want to stop only |
ae66c1fc | 7344 | at the very same frame. */ |
a6d9a66e UW |
7345 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
7346 | get_stack_frame_id (frame), | |
ae66c1fc | 7347 | bp_until); |
c5aa993b | 7348 | |
f107f563 | 7349 | old_chain = make_cleanup_delete_breakpoint (breakpoint); |
c906108c | 7350 | |
ae66c1fc EZ |
7351 | /* Keep within the current frame, or in frames called by the current |
7352 | one. */ | |
edb3359d DJ |
7353 | |
7354 | if (frame_id_p (frame_unwind_caller_id (frame))) | |
c906108c | 7355 | { |
edb3359d DJ |
7356 | sal = find_pc_line (frame_unwind_caller_pc (frame), 0); |
7357 | sal.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e UW |
7358 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
7359 | sal, | |
edb3359d | 7360 | frame_unwind_caller_id (frame), |
f107f563 VP |
7361 | bp_until); |
7362 | make_cleanup_delete_breakpoint (breakpoint2); | |
c906108c | 7363 | } |
c5aa993b | 7364 | |
c906108c | 7365 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
f107f563 VP |
7366 | |
7367 | /* If we are running asynchronously, and proceed call above has actually | |
7368 | managed to start the target, arrange for breakpoints to be | |
7369 | deleted when the target stops. Otherwise, we're already stopped and | |
7370 | delete breakpoints via cleanup chain. */ | |
7371 | ||
8ea051c5 | 7372 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 7373 | { |
bfec99b2 PA |
7374 | struct until_break_command_continuation_args *args; |
7375 | args = xmalloc (sizeof (*args)); | |
f107f563 | 7376 | |
bfec99b2 PA |
7377 | args->breakpoint = breakpoint; |
7378 | args->breakpoint2 = breakpoint2; | |
f107f563 VP |
7379 | |
7380 | discard_cleanups (old_chain); | |
95e54da7 PA |
7381 | add_continuation (inferior_thread (), |
7382 | until_break_command_continuation, args, | |
604ead4a | 7383 | xfree); |
f107f563 VP |
7384 | } |
7385 | else | |
c5aa993b | 7386 | do_cleanups (old_chain); |
c906108c | 7387 | } |
ae66c1fc | 7388 | |
c906108c | 7389 | static void |
fba45db2 | 7390 | ep_skip_leading_whitespace (char **s) |
c906108c | 7391 | { |
c5aa993b JM |
7392 | if ((s == NULL) || (*s == NULL)) |
7393 | return; | |
7394 | while (isspace (**s)) | |
7395 | *s += 1; | |
c906108c | 7396 | } |
c5aa993b | 7397 | |
c906108c SS |
7398 | /* This function attempts to parse an optional "if <cond>" clause |
7399 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 7400 | |
c906108c SS |
7401 | Else, it returns a pointer to the condition string. (It does not |
7402 | attempt to evaluate the string against a particular block.) And, | |
7403 | it updates arg to point to the first character following the parsed | |
7404 | if clause in the arg string. */ | |
53a5351d | 7405 | |
c906108c | 7406 | static char * |
fba45db2 | 7407 | ep_parse_optional_if_clause (char **arg) |
c906108c | 7408 | { |
c5aa993b JM |
7409 | char *cond_string; |
7410 | ||
7411 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 7412 | return NULL; |
c5aa993b | 7413 | |
c906108c SS |
7414 | /* Skip the "if" keyword. */ |
7415 | (*arg) += 2; | |
c5aa993b | 7416 | |
c906108c SS |
7417 | /* Skip any extra leading whitespace, and record the start of the |
7418 | condition string. */ | |
7419 | ep_skip_leading_whitespace (arg); | |
7420 | cond_string = *arg; | |
c5aa993b | 7421 | |
c906108c SS |
7422 | /* Assume that the condition occupies the remainder of the arg string. */ |
7423 | (*arg) += strlen (cond_string); | |
c5aa993b | 7424 | |
c906108c SS |
7425 | return cond_string; |
7426 | } | |
c5aa993b | 7427 | |
c906108c SS |
7428 | /* This function attempts to parse an optional filename from the arg |
7429 | string. If one is not found, it returns NULL. | |
c5aa993b | 7430 | |
c906108c SS |
7431 | Else, it returns a pointer to the parsed filename. (This function |
7432 | makes no attempt to verify that a file of that name exists, or is | |
7433 | accessible.) And, it updates arg to point to the first character | |
7434 | following the parsed filename in the arg string. | |
c5aa993b | 7435 | |
c906108c SS |
7436 | Note that clients needing to preserve the returned filename for |
7437 | future access should copy it to their own buffers. */ | |
7438 | static char * | |
fba45db2 | 7439 | ep_parse_optional_filename (char **arg) |
c906108c | 7440 | { |
c5aa993b JM |
7441 | static char filename[1024]; |
7442 | char *arg_p = *arg; | |
7443 | int i; | |
7444 | char c; | |
7445 | ||
c906108c SS |
7446 | if ((*arg_p == '\0') || isspace (*arg_p)) |
7447 | return NULL; | |
c5aa993b JM |
7448 | |
7449 | for (i = 0;; i++) | |
c906108c SS |
7450 | { |
7451 | c = *arg_p; | |
7452 | if (isspace (c)) | |
c5aa993b | 7453 | c = '\0'; |
c906108c SS |
7454 | filename[i] = c; |
7455 | if (c == '\0') | |
c5aa993b | 7456 | break; |
c906108c SS |
7457 | arg_p++; |
7458 | } | |
7459 | *arg = arg_p; | |
c5aa993b | 7460 | |
c906108c SS |
7461 | return filename; |
7462 | } | |
c5aa993b | 7463 | |
c906108c SS |
7464 | /* Commands to deal with catching events, such as signals, exceptions, |
7465 | process start/exit, etc. */ | |
c5aa993b JM |
7466 | |
7467 | typedef enum | |
7468 | { | |
44feb3ce TT |
7469 | catch_fork_temporary, catch_vfork_temporary, |
7470 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
7471 | } |
7472 | catch_fork_kind; | |
7473 | ||
c906108c | 7474 | static void |
44feb3ce | 7475 | catch_fork_command_1 (char *arg, int from_tty, struct cmd_list_element *command) |
c906108c | 7476 | { |
a6d9a66e | 7477 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 7478 | char *cond_string = NULL; |
44feb3ce TT |
7479 | catch_fork_kind fork_kind; |
7480 | int tempflag; | |
7481 | ||
7482 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
7483 | tempflag = (fork_kind == catch_fork_temporary | |
7484 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 7485 | |
44feb3ce TT |
7486 | if (!arg) |
7487 | arg = ""; | |
c906108c | 7488 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 7489 | |
c906108c | 7490 | /* The allowed syntax is: |
c5aa993b JM |
7491 | catch [v]fork |
7492 | catch [v]fork if <cond> | |
7493 | ||
c906108c SS |
7494 | First, check if there's an if clause. */ |
7495 | cond_string = ep_parse_optional_if_clause (&arg); | |
c5aa993b | 7496 | |
c906108c | 7497 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 7498 | error (_("Junk at end of arguments.")); |
c5aa993b | 7499 | |
c906108c SS |
7500 | /* If this target supports it, create a fork or vfork catchpoint |
7501 | and enable reporting of such events. */ | |
c5aa993b JM |
7502 | switch (fork_kind) |
7503 | { | |
44feb3ce TT |
7504 | case catch_fork_temporary: |
7505 | case catch_fork_permanent: | |
a6d9a66e | 7506 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 7507 | &catch_fork_breakpoint_ops); |
c906108c | 7508 | break; |
44feb3ce TT |
7509 | case catch_vfork_temporary: |
7510 | case catch_vfork_permanent: | |
a6d9a66e | 7511 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 7512 | &catch_vfork_breakpoint_ops); |
c906108c | 7513 | break; |
c5aa993b | 7514 | default: |
8a3fe4f8 | 7515 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 7516 | break; |
c5aa993b | 7517 | } |
c906108c SS |
7518 | } |
7519 | ||
7520 | static void | |
44feb3ce | 7521 | catch_exec_command_1 (char *arg, int from_tty, struct cmd_list_element *command) |
c906108c | 7522 | { |
a6d9a66e | 7523 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 7524 | int tempflag; |
c5aa993b | 7525 | char *cond_string = NULL; |
c906108c | 7526 | |
44feb3ce TT |
7527 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
7528 | ||
7529 | if (!arg) | |
7530 | arg = ""; | |
c906108c SS |
7531 | ep_skip_leading_whitespace (&arg); |
7532 | ||
7533 | /* The allowed syntax is: | |
c5aa993b JM |
7534 | catch exec |
7535 | catch exec if <cond> | |
c906108c SS |
7536 | |
7537 | First, check if there's an if clause. */ | |
7538 | cond_string = ep_parse_optional_if_clause (&arg); | |
7539 | ||
7540 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 7541 | error (_("Junk at end of arguments.")); |
c906108c SS |
7542 | |
7543 | /* If this target supports it, create an exec catchpoint | |
7544 | and enable reporting of such events. */ | |
a6d9a66e UW |
7545 | create_catchpoint (gdbarch, tempflag, cond_string, |
7546 | &catch_exec_breakpoint_ops); | |
c906108c | 7547 | } |
c5aa993b | 7548 | |
3086aeae DJ |
7549 | static enum print_stop_action |
7550 | print_exception_catchpoint (struct breakpoint *b) | |
7551 | { | |
ade92717 | 7552 | int bp_temp, bp_throw; |
3086aeae | 7553 | |
ade92717 | 7554 | annotate_catchpoint (b->number); |
3086aeae | 7555 | |
ade92717 AR |
7556 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
7557 | if (b->loc->address != b->loc->requested_address) | |
7558 | breakpoint_adjustment_warning (b->loc->requested_address, | |
7559 | b->loc->address, | |
7560 | b->number, 1); | |
df2b6d2d | 7561 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
7562 | ui_out_text (uiout, |
7563 | bp_temp ? "Temporary catchpoint " | |
7564 | : "Catchpoint "); | |
7565 | if (!ui_out_is_mi_like_p (uiout)) | |
7566 | ui_out_field_int (uiout, "bkptno", b->number); | |
7567 | ui_out_text (uiout, | |
c0b37c48 AR |
7568 | bp_throw ? " (exception thrown), " |
7569 | : " (exception caught), "); | |
ade92717 AR |
7570 | if (ui_out_is_mi_like_p (uiout)) |
7571 | { | |
7572 | ui_out_field_string (uiout, "reason", | |
7573 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
7574 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
7575 | ui_out_field_int (uiout, "bkptno", b->number); | |
7576 | } | |
3086aeae DJ |
7577 | return PRINT_SRC_AND_LOC; |
7578 | } | |
7579 | ||
7580 | static void | |
a6d9a66e | 7581 | print_one_exception_catchpoint (struct breakpoint *b, struct bp_location **last_loc) |
3086aeae | 7582 | { |
79a45b7d TT |
7583 | struct value_print_options opts; |
7584 | get_user_print_options (&opts); | |
7585 | if (opts.addressprint) | |
3086aeae DJ |
7586 | { |
7587 | annotate_field (4); | |
604133b5 AR |
7588 | if (b->loc == NULL || b->loc->shlib_disabled) |
7589 | ui_out_field_string (uiout, "addr", "<PENDING>"); | |
7590 | else | |
5af949e3 UW |
7591 | ui_out_field_core_addr (uiout, "addr", |
7592 | b->loc->gdbarch, b->loc->address); | |
3086aeae DJ |
7593 | } |
7594 | annotate_field (5); | |
604133b5 | 7595 | if (b->loc) |
a6d9a66e | 7596 | *last_loc = b->loc; |
3086aeae DJ |
7597 | if (strstr (b->addr_string, "throw") != NULL) |
7598 | ui_out_field_string (uiout, "what", "exception throw"); | |
7599 | else | |
7600 | ui_out_field_string (uiout, "what", "exception catch"); | |
7601 | } | |
7602 | ||
7603 | static void | |
7604 | print_mention_exception_catchpoint (struct breakpoint *b) | |
7605 | { | |
ade92717 AR |
7606 | int bp_temp; |
7607 | int bp_throw; | |
7608 | ||
df2b6d2d | 7609 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
7610 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
7611 | ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ") | |
7612 | : _("Catchpoint ")); | |
7613 | ui_out_field_int (uiout, "bkptno", b->number); | |
7614 | ui_out_text (uiout, bp_throw ? _(" (throw)") | |
7615 | : _(" (catch)")); | |
3086aeae DJ |
7616 | } |
7617 | ||
7618 | static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = { | |
ce78b96d JB |
7619 | NULL, /* insert */ |
7620 | NULL, /* remove */ | |
7621 | NULL, /* breakpoint_hit */ | |
3086aeae DJ |
7622 | print_exception_catchpoint, |
7623 | print_one_exception_catchpoint, | |
7624 | print_mention_exception_catchpoint | |
7625 | }; | |
7626 | ||
7627 | static int | |
7628 | handle_gnu_v3_exceptions (int tempflag, char *cond_string, | |
7629 | enum exception_event_kind ex_event, int from_tty) | |
7630 | { | |
604133b5 AR |
7631 | char *trigger_func_name; |
7632 | ||
3086aeae | 7633 | if (ex_event == EX_EVENT_CATCH) |
604133b5 | 7634 | trigger_func_name = "__cxa_begin_catch"; |
3086aeae | 7635 | else |
604133b5 | 7636 | trigger_func_name = "__cxa_throw"; |
3086aeae | 7637 | |
a6d9a66e UW |
7638 | break_command_really (get_current_arch (), |
7639 | trigger_func_name, cond_string, -1, | |
604133b5 | 7640 | 0 /* condition and thread are valid. */, |
1042e4c0 | 7641 | tempflag, 0, 0, |
604133b5 AR |
7642 | 0, |
7643 | AUTO_BOOLEAN_TRUE /* pending */, | |
41447f92 VP |
7644 | &gnu_v3_exception_catchpoint_ops, from_tty, |
7645 | 1 /* enabled */); | |
3086aeae | 7646 | |
3086aeae DJ |
7647 | return 1; |
7648 | } | |
7649 | ||
c5aa993b | 7650 | /* Deal with "catch catch" and "catch throw" commands */ |
c906108c SS |
7651 | |
7652 | static void | |
fba45db2 KB |
7653 | catch_exception_command_1 (enum exception_event_kind ex_event, char *arg, |
7654 | int tempflag, int from_tty) | |
c906108c | 7655 | { |
c5aa993b JM |
7656 | char *cond_string = NULL; |
7657 | struct symtab_and_line *sal = NULL; | |
7658 | ||
44feb3ce TT |
7659 | if (!arg) |
7660 | arg = ""; | |
c906108c | 7661 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 7662 | |
c906108c SS |
7663 | cond_string = ep_parse_optional_if_clause (&arg); |
7664 | ||
7665 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 7666 | error (_("Junk at end of arguments.")); |
c906108c | 7667 | |
059fb39f PM |
7668 | if (ex_event != EX_EVENT_THROW |
7669 | && ex_event != EX_EVENT_CATCH) | |
8a3fe4f8 | 7670 | error (_("Unsupported or unknown exception event; cannot catch it")); |
c906108c | 7671 | |
3086aeae DJ |
7672 | if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty)) |
7673 | return; | |
7674 | ||
8a3fe4f8 | 7675 | warning (_("Unsupported with this platform/compiler combination.")); |
c906108c SS |
7676 | } |
7677 | ||
44feb3ce TT |
7678 | /* Implementation of "catch catch" command. */ |
7679 | ||
7680 | static void | |
7681 | catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command) | |
7682 | { | |
7683 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
7684 | catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty); | |
7685 | } | |
7686 | ||
7687 | /* Implementation of "catch throw" command. */ | |
7688 | ||
7689 | static void | |
7690 | catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command) | |
7691 | { | |
7692 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
7693 | catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty); | |
7694 | } | |
7695 | ||
f7f9143b JB |
7696 | /* Create a breakpoint struct for Ada exception catchpoints. */ |
7697 | ||
7698 | static void | |
a6d9a66e UW |
7699 | create_ada_exception_breakpoint (struct gdbarch *gdbarch, |
7700 | struct symtab_and_line sal, | |
f7f9143b JB |
7701 | char *addr_string, |
7702 | char *exp_string, | |
7703 | char *cond_string, | |
7704 | struct expression *cond, | |
7705 | struct breakpoint_ops *ops, | |
7706 | int tempflag, | |
7707 | int from_tty) | |
7708 | { | |
7709 | struct breakpoint *b; | |
7710 | ||
7711 | if (from_tty) | |
7712 | { | |
5af949e3 UW |
7713 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
7714 | if (!loc_gdbarch) | |
7715 | loc_gdbarch = gdbarch; | |
7716 | ||
6c95b8df PA |
7717 | describe_other_breakpoints (loc_gdbarch, |
7718 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
7719 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
7720 | version for exception catchpoints, because two catchpoints | |
7721 | used for different exception names will use the same address. | |
7722 | In this case, a "breakpoint ... also set at..." warning is | |
7723 | unproductive. Besides. the warning phrasing is also a bit | |
7724 | inapropriate, we should use the word catchpoint, and tell | |
7725 | the user what type of catchpoint it is. The above is good | |
7726 | enough for now, though. */ | |
7727 | } | |
7728 | ||
a6d9a66e | 7729 | b = set_raw_breakpoint (gdbarch, sal, bp_breakpoint); |
f7f9143b JB |
7730 | set_breakpoint_count (breakpoint_count + 1); |
7731 | ||
7732 | b->enable_state = bp_enabled; | |
7733 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
7734 | b->number = breakpoint_count; | |
7735 | b->ignore_count = 0; | |
511a6cd4 | 7736 | b->loc->cond = cond; |
f7f9143b JB |
7737 | b->addr_string = addr_string; |
7738 | b->language = language_ada; | |
7739 | b->cond_string = cond_string; | |
7740 | b->exp_string = exp_string; | |
7741 | b->thread = -1; | |
7742 | b->ops = ops; | |
f7f9143b JB |
7743 | |
7744 | mention (b); | |
b60e7edf | 7745 | update_global_location_list (1); |
f7f9143b JB |
7746 | } |
7747 | ||
7748 | /* Implement the "catch exception" command. */ | |
7749 | ||
7750 | static void | |
44feb3ce TT |
7751 | catch_ada_exception_command (char *arg, int from_tty, |
7752 | struct cmd_list_element *command) | |
f7f9143b | 7753 | { |
a6d9a66e | 7754 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 7755 | int tempflag; |
f7f9143b JB |
7756 | struct symtab_and_line sal; |
7757 | enum bptype type; | |
7758 | char *addr_string = NULL; | |
7759 | char *exp_string = NULL; | |
7760 | char *cond_string = NULL; | |
7761 | struct expression *cond = NULL; | |
7762 | struct breakpoint_ops *ops = NULL; | |
7763 | ||
44feb3ce TT |
7764 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
7765 | ||
7766 | if (!arg) | |
7767 | arg = ""; | |
f7f9143b JB |
7768 | sal = ada_decode_exception_location (arg, &addr_string, &exp_string, |
7769 | &cond_string, &cond, &ops); | |
a6d9a66e | 7770 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, exp_string, |
f7f9143b JB |
7771 | cond_string, cond, ops, tempflag, |
7772 | from_tty); | |
7773 | } | |
7774 | ||
a96d9b2e SDJ |
7775 | /* Cleanup function for a syscall filter list. */ |
7776 | static void | |
7777 | clean_up_filters (void *arg) | |
7778 | { | |
7779 | VEC(int) *iter = *(VEC(int) **) arg; | |
7780 | VEC_free (int, iter); | |
7781 | } | |
7782 | ||
7783 | /* Splits the argument using space as delimiter. Returns an xmalloc'd | |
7784 | filter list, or NULL if no filtering is required. */ | |
7785 | static VEC(int) * | |
7786 | catch_syscall_split_args (char *arg) | |
7787 | { | |
7788 | VEC(int) *result = NULL; | |
7789 | struct cleanup *cleanup = make_cleanup (clean_up_filters, &result); | |
7790 | ||
7791 | while (*arg != '\0') | |
7792 | { | |
7793 | int i, syscall_number; | |
7794 | char *endptr; | |
7795 | char cur_name[128]; | |
7796 | struct syscall s; | |
7797 | ||
7798 | /* Skip whitespace. */ | |
7799 | while (isspace (*arg)) | |
7800 | arg++; | |
7801 | ||
7802 | for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) | |
7803 | cur_name[i] = arg[i]; | |
7804 | cur_name[i] = '\0'; | |
7805 | arg += i; | |
7806 | ||
7807 | /* Check if the user provided a syscall name or a number. */ | |
7808 | syscall_number = (int) strtol (cur_name, &endptr, 0); | |
7809 | if (*endptr == '\0') | |
7810 | { | |
7811 | get_syscall_by_number (syscall_number, &s); | |
7812 | ||
7813 | if (s.name == NULL) | |
7814 | /* We can issue just a warning, but still create the catchpoint. | |
7815 | This is because, even not knowing the syscall name that | |
7816 | this number represents, we can still try to catch the syscall | |
7817 | number. */ | |
7818 | warning (_("The number '%d' does not represent a known syscall."), | |
7819 | syscall_number); | |
7820 | } | |
7821 | else | |
7822 | { | |
7823 | /* We have a name. Let's check if it's valid and convert it | |
7824 | to a number. */ | |
7825 | get_syscall_by_name (cur_name, &s); | |
7826 | ||
7827 | if (s.number == UNKNOWN_SYSCALL) | |
7828 | /* Here we have to issue an error instead of a warning, because | |
7829 | GDB cannot do anything useful if there's no syscall number to | |
7830 | be caught. */ | |
7831 | error (_("Unknown syscall name '%s'."), cur_name); | |
7832 | } | |
7833 | ||
7834 | /* Ok, it's valid. */ | |
7835 | VEC_safe_push (int, result, s.number); | |
7836 | } | |
7837 | ||
7838 | discard_cleanups (cleanup); | |
7839 | return result; | |
7840 | } | |
7841 | ||
7842 | /* Implement the "catch syscall" command. */ | |
7843 | ||
7844 | static void | |
7845 | catch_syscall_command_1 (char *arg, int from_tty, struct cmd_list_element *command) | |
7846 | { | |
7847 | int tempflag; | |
7848 | VEC(int) *filter; | |
7849 | struct syscall s; | |
7850 | struct gdbarch *gdbarch = get_current_arch (); | |
7851 | ||
7852 | /* Checking if the feature if supported. */ | |
7853 | if (gdbarch_get_syscall_number_p (gdbarch) == 0) | |
7854 | error (_("The feature 'catch syscall' is not supported on \ | |
7855 | this architeture yet.")); | |
7856 | ||
7857 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
7858 | ||
7859 | ep_skip_leading_whitespace (&arg); | |
7860 | ||
7861 | /* We need to do this first "dummy" translation in order | |
7862 | to get the syscall XML file loaded or, most important, | |
7863 | to display a warning to the user if there's no XML file | |
7864 | for his/her architecture. */ | |
7865 | get_syscall_by_number (0, &s); | |
7866 | ||
7867 | /* The allowed syntax is: | |
7868 | catch syscall | |
7869 | catch syscall <name | number> [<name | number> ... <name | number>] | |
7870 | ||
7871 | Let's check if there's a syscall name. */ | |
7872 | ||
7873 | if (arg != NULL) | |
7874 | filter = catch_syscall_split_args (arg); | |
7875 | else | |
7876 | filter = NULL; | |
7877 | ||
7878 | create_syscall_event_catchpoint (tempflag, filter, | |
7879 | &catch_syscall_breakpoint_ops); | |
7880 | } | |
7881 | ||
f7f9143b JB |
7882 | /* Implement the "catch assert" command. */ |
7883 | ||
7884 | static void | |
44feb3ce | 7885 | catch_assert_command (char *arg, int from_tty, struct cmd_list_element *command) |
f7f9143b | 7886 | { |
a6d9a66e | 7887 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 7888 | int tempflag; |
f7f9143b JB |
7889 | struct symtab_and_line sal; |
7890 | char *addr_string = NULL; | |
7891 | struct breakpoint_ops *ops = NULL; | |
7892 | ||
44feb3ce TT |
7893 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
7894 | ||
7895 | if (!arg) | |
7896 | arg = ""; | |
f7f9143b | 7897 | sal = ada_decode_assert_location (arg, &addr_string, &ops); |
a6d9a66e UW |
7898 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, NULL, NULL, NULL, |
7899 | ops, tempflag, from_tty); | |
f7f9143b JB |
7900 | } |
7901 | ||
c906108c | 7902 | static void |
fba45db2 | 7903 | catch_command (char *arg, int from_tty) |
c906108c | 7904 | { |
44feb3ce | 7905 | error (_("Catch requires an event name.")); |
c906108c SS |
7906 | } |
7907 | \f | |
7908 | ||
7909 | static void | |
fba45db2 | 7910 | tcatch_command (char *arg, int from_tty) |
c906108c | 7911 | { |
44feb3ce | 7912 | error (_("Catch requires an event name.")); |
c906108c SS |
7913 | } |
7914 | ||
80f8a6eb | 7915 | /* Delete breakpoints by address or line. */ |
c906108c SS |
7916 | |
7917 | static void | |
fba45db2 | 7918 | clear_command (char *arg, int from_tty) |
c906108c | 7919 | { |
d6e956e5 VP |
7920 | struct breakpoint *b; |
7921 | VEC(breakpoint_p) *found = 0; | |
7922 | int ix; | |
c906108c SS |
7923 | int default_match; |
7924 | struct symtabs_and_lines sals; | |
7925 | struct symtab_and_line sal; | |
c906108c SS |
7926 | int i; |
7927 | ||
7928 | if (arg) | |
7929 | { | |
7930 | sals = decode_line_spec (arg, 1); | |
7931 | default_match = 0; | |
7932 | } | |
7933 | else | |
7934 | { | |
c5aa993b | 7935 | sals.sals = (struct symtab_and_line *) |
c906108c | 7936 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 7937 | make_cleanup (xfree, sals.sals); |
fe39c653 | 7938 | init_sal (&sal); /* initialize to zeroes */ |
c906108c SS |
7939 | sal.line = default_breakpoint_line; |
7940 | sal.symtab = default_breakpoint_symtab; | |
7941 | sal.pc = default_breakpoint_address; | |
6c95b8df | 7942 | sal.pspace = default_breakpoint_pspace; |
c906108c | 7943 | if (sal.symtab == 0) |
8a3fe4f8 | 7944 | error (_("No source file specified.")); |
c906108c SS |
7945 | |
7946 | sals.sals[0] = sal; | |
7947 | sals.nelts = 1; | |
7948 | ||
7949 | default_match = 1; | |
7950 | } | |
7951 | ||
ed0616c6 VP |
7952 | /* We don't call resolve_sal_pc here. That's not |
7953 | as bad as it seems, because all existing breakpoints | |
7954 | typically have both file/line and pc set. So, if | |
7955 | clear is given file/line, we can match this to existing | |
7956 | breakpoint without obtaining pc at all. | |
7957 | ||
7958 | We only support clearing given the address explicitly | |
7959 | present in breakpoint table. Say, we've set breakpoint | |
7960 | at file:line. There were several PC values for that file:line, | |
7961 | due to optimization, all in one block. | |
7962 | We've picked one PC value. If "clear" is issued with another | |
7963 | PC corresponding to the same file:line, the breakpoint won't | |
7964 | be cleared. We probably can still clear the breakpoint, but | |
7965 | since the other PC value is never presented to user, user | |
7966 | can only find it by guessing, and it does not seem important | |
7967 | to support that. */ | |
7968 | ||
c906108c | 7969 | /* For each line spec given, delete bps which correspond |
80f8a6eb MS |
7970 | to it. Do it in two passes, solely to preserve the current |
7971 | behavior that from_tty is forced true if we delete more than | |
7972 | one breakpoint. */ | |
c906108c | 7973 | |
80f8a6eb | 7974 | found = NULL; |
c906108c SS |
7975 | for (i = 0; i < sals.nelts; i++) |
7976 | { | |
7977 | /* If exact pc given, clear bpts at that pc. | |
c5aa993b JM |
7978 | If line given (pc == 0), clear all bpts on specified line. |
7979 | If defaulting, clear all bpts on default line | |
c906108c | 7980 | or at default pc. |
c5aa993b JM |
7981 | |
7982 | defaulting sal.pc != 0 tests to do | |
7983 | ||
7984 | 0 1 pc | |
7985 | 1 1 pc _and_ line | |
7986 | 0 0 line | |
7987 | 1 0 <can't happen> */ | |
c906108c SS |
7988 | |
7989 | sal = sals.sals[i]; | |
c906108c | 7990 | |
d6e956e5 VP |
7991 | /* Find all matching breakpoints and add them to |
7992 | 'found'. */ | |
7993 | ALL_BREAKPOINTS (b) | |
c5aa993b | 7994 | { |
0d381245 | 7995 | int match = 0; |
80f8a6eb MS |
7996 | /* Are we going to delete b? */ |
7997 | if (b->type != bp_none | |
7998 | && b->type != bp_watchpoint | |
7999 | && b->type != bp_hardware_watchpoint | |
8000 | && b->type != bp_read_watchpoint | |
0d381245 VP |
8001 | && b->type != bp_access_watchpoint) |
8002 | { | |
8003 | struct bp_location *loc = b->loc; | |
8004 | for (; loc; loc = loc->next) | |
8005 | { | |
6c95b8df PA |
8006 | int pc_match = sal.pc |
8007 | && (loc->pspace == sal.pspace) | |
0d381245 VP |
8008 | && (loc->address == sal.pc) |
8009 | && (!section_is_overlay (loc->section) | |
8010 | || loc->section == sal.section); | |
8011 | int line_match = ((default_match || (0 == sal.pc)) | |
8012 | && b->source_file != NULL | |
8013 | && sal.symtab != NULL | |
6c95b8df | 8014 | && sal.pspace == loc->pspace |
0d381245 VP |
8015 | && strcmp (b->source_file, sal.symtab->filename) == 0 |
8016 | && b->line_number == sal.line); | |
8017 | if (pc_match || line_match) | |
8018 | { | |
8019 | match = 1; | |
8020 | break; | |
8021 | } | |
8022 | } | |
8023 | } | |
8024 | ||
8025 | if (match) | |
d6e956e5 | 8026 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 8027 | } |
80f8a6eb MS |
8028 | } |
8029 | /* Now go thru the 'found' chain and delete them. */ | |
d6e956e5 | 8030 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
8031 | { |
8032 | if (arg) | |
8a3fe4f8 | 8033 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 8034 | else |
8a3fe4f8 | 8035 | error (_("No breakpoint at this line.")); |
80f8a6eb | 8036 | } |
c906108c | 8037 | |
d6e956e5 | 8038 | if (VEC_length(breakpoint_p, found) > 1) |
80f8a6eb MS |
8039 | from_tty = 1; /* Always report if deleted more than one */ |
8040 | if (from_tty) | |
a3f17187 | 8041 | { |
d6e956e5 | 8042 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
8043 | printf_unfiltered (_("Deleted breakpoint ")); |
8044 | else | |
8045 | printf_unfiltered (_("Deleted breakpoints ")); | |
8046 | } | |
80f8a6eb | 8047 | breakpoints_changed (); |
d6e956e5 VP |
8048 | |
8049 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 8050 | { |
c5aa993b | 8051 | if (from_tty) |
d6e956e5 VP |
8052 | printf_unfiltered ("%d ", b->number); |
8053 | delete_breakpoint (b); | |
c906108c | 8054 | } |
80f8a6eb MS |
8055 | if (from_tty) |
8056 | putchar_unfiltered ('\n'); | |
c906108c SS |
8057 | } |
8058 | \f | |
8059 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
8060 | all breakpoints that are marked for deletion, whether hit or not. | |
8061 | This is called after any breakpoint is hit, or after errors. */ | |
8062 | ||
8063 | void | |
fba45db2 | 8064 | breakpoint_auto_delete (bpstat bs) |
c906108c SS |
8065 | { |
8066 | struct breakpoint *b, *temp; | |
8067 | ||
8068 | for (; bs; bs = bs->next) | |
20874c92 VP |
8069 | if (bs->breakpoint_at |
8070 | && bs->breakpoint_at->owner | |
8071 | && bs->breakpoint_at->owner->disposition == disp_del | |
c906108c | 8072 | && bs->stop) |
4f8d1dc6 | 8073 | delete_breakpoint (bs->breakpoint_at->owner); |
c906108c SS |
8074 | |
8075 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b | 8076 | { |
b5de0fa7 | 8077 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
8078 | delete_breakpoint (b); |
8079 | } | |
c906108c SS |
8080 | } |
8081 | ||
f7545552 TT |
8082 | /* A cleanup function which destroys a vector. */ |
8083 | ||
8084 | static void | |
8085 | do_vec_free (void *p) | |
8086 | { | |
8087 | VEC(bp_location_p) **vec = p; | |
8088 | if (*vec) | |
8089 | VEC_free (bp_location_p, *vec); | |
8090 | } | |
8091 | ||
4cd9bd08 | 8092 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
b60e7edf PA |
8093 | into the inferior, only remove already-inserted locations that no |
8094 | longer should be inserted. Functions that delete a breakpoint or | |
8095 | breakpoints should pass false, so that deleting a breakpoint | |
8096 | doesn't have the side effect of inserting the locations of other | |
8097 | breakpoints that are marked not-inserted, but should_be_inserted | |
8098 | returns true on them. | |
8099 | ||
8100 | This behaviour is useful is situations close to tear-down -- e.g., | |
8101 | after an exec, while the target still has execution, but breakpoint | |
8102 | shadows of the previous executable image should *NOT* be restored | |
8103 | to the new image; or before detaching, where the target still has | |
8104 | execution and wants to delete breakpoints from GDB's lists, and all | |
8105 | breakpoints had already been removed from the inferior. */ | |
8106 | ||
0d381245 | 8107 | static void |
b60e7edf | 8108 | update_global_location_list (int should_insert) |
0d381245 | 8109 | { |
74960c60 VP |
8110 | struct breakpoint *b; |
8111 | struct bp_location **next = &bp_location_chain; | |
8112 | struct bp_location *loc; | |
8113 | struct bp_location *loc2; | |
74960c60 VP |
8114 | VEC(bp_location_p) *old_locations = NULL; |
8115 | int ret; | |
8116 | int ix; | |
f7545552 TT |
8117 | struct cleanup *cleanups; |
8118 | ||
8119 | cleanups = make_cleanup (do_vec_free, &old_locations); | |
74960c60 VP |
8120 | /* Store old locations for future reference. */ |
8121 | for (loc = bp_location_chain; loc; loc = loc->global_next) | |
8122 | VEC_safe_push (bp_location_p, old_locations, loc); | |
0d381245 | 8123 | |
74960c60 VP |
8124 | bp_location_chain = NULL; |
8125 | ALL_BREAKPOINTS (b) | |
0d381245 | 8126 | { |
74960c60 | 8127 | for (loc = b->loc; loc; loc = loc->next) |
0d381245 | 8128 | { |
74960c60 VP |
8129 | *next = loc; |
8130 | next = &(loc->global_next); | |
8131 | *next = NULL; | |
0d381245 | 8132 | } |
74960c60 VP |
8133 | } |
8134 | ||
8135 | /* Identify bp_location instances that are no longer present in the new | |
8136 | list, and therefore should be freed. Note that it's not necessary that | |
8137 | those locations should be removed from inferior -- if there's another | |
8138 | location at the same address (previously marked as duplicate), | |
8139 | we don't need to remove/insert the location. */ | |
8140 | for (ix = 0; VEC_iterate(bp_location_p, old_locations, ix, loc); ++ix) | |
8141 | { | |
8142 | /* Tells if 'loc' is found amoung the new locations. If not, we | |
8143 | have to free it. */ | |
8144 | int found_object = 0; | |
20874c92 VP |
8145 | /* Tells if the location should remain inserted in the target. */ |
8146 | int keep_in_target = 0; | |
8147 | int removed = 0; | |
74960c60 VP |
8148 | for (loc2 = bp_location_chain; loc2; loc2 = loc2->global_next) |
8149 | if (loc2 == loc) | |
8150 | { | |
8151 | found_object = 1; | |
8152 | break; | |
8153 | } | |
8154 | ||
8155 | /* If this location is no longer present, and inserted, look if there's | |
8156 | maybe a new location at the same address. If so, mark that one | |
8157 | inserted, and don't remove this one. This is needed so that we | |
8158 | don't have a time window where a breakpoint at certain location is not | |
8159 | inserted. */ | |
8160 | ||
8161 | if (loc->inserted) | |
0d381245 | 8162 | { |
74960c60 | 8163 | /* If the location is inserted now, we might have to remove it. */ |
74960c60 VP |
8164 | |
8165 | if (found_object && should_be_inserted (loc)) | |
8166 | { | |
8167 | /* The location is still present in the location list, and still | |
8168 | should be inserted. Don't do anything. */ | |
20874c92 | 8169 | keep_in_target = 1; |
74960c60 VP |
8170 | } |
8171 | else | |
8172 | { | |
8173 | /* The location is either no longer present, or got disabled. | |
8174 | See if there's another location at the same address, in which | |
8175 | case we don't need to remove this one from the target. */ | |
8176 | if (breakpoint_address_is_meaningful (loc->owner)) | |
8177 | for (loc2 = bp_location_chain; loc2; loc2 = loc2->global_next) | |
8178 | { | |
8179 | /* For the sake of should_insert_location. The | |
8180 | call to check_duplicates will fix up this later. */ | |
8181 | loc2->duplicate = 0; | |
8182 | if (should_be_inserted (loc2) | |
6c95b8df PA |
8183 | && loc2 != loc |
8184 | && breakpoint_address_match (loc2->pspace->aspace, | |
8185 | loc2->address, | |
8186 | loc->pspace->aspace, | |
8187 | loc->address)) | |
8188 | { | |
74960c60 VP |
8189 | loc2->inserted = 1; |
8190 | loc2->target_info = loc->target_info; | |
20874c92 | 8191 | keep_in_target = 1; |
74960c60 VP |
8192 | break; |
8193 | } | |
8194 | } | |
8195 | } | |
8196 | ||
20874c92 VP |
8197 | if (!keep_in_target) |
8198 | { | |
8199 | if (remove_breakpoint (loc, mark_uninserted)) | |
8200 | { | |
8201 | /* This is just about all we can do. We could keep this | |
8202 | location on the global list, and try to remove it next | |
8203 | time, but there's no particular reason why we will | |
8204 | succeed next time. | |
8205 | ||
8206 | Note that at this point, loc->owner is still valid, | |
8207 | as delete_breakpoint frees the breakpoint only | |
8208 | after calling us. */ | |
8209 | printf_filtered (_("warning: Error removing breakpoint %d\n"), | |
8210 | loc->owner->number); | |
8211 | } | |
8212 | removed = 1; | |
8213 | } | |
0d381245 | 8214 | } |
74960c60 VP |
8215 | |
8216 | if (!found_object) | |
1c5cfe86 PA |
8217 | { |
8218 | if (removed && non_stop) | |
20874c92 VP |
8219 | { |
8220 | /* This location was removed from the targets. In non-stop mode, | |
8221 | a race condition is possible where we've removed a breakpoint, | |
8222 | but stop events for that breakpoint are already queued and will | |
8223 | arrive later. To suppress spurious SIGTRAPs reported to user, | |
8224 | we keep this breakpoint location for a bit, and will retire it | |
8225 | after we see 3 * thread_count events. | |
1c5cfe86 | 8226 | The theory here is that reporting of events should, |
20874c92 VP |
8227 | "on the average", be fair, so after that many event we'll see |
8228 | events from all threads that have anything of interest, and no | |
1c5cfe86 | 8229 | longer need to keep this breakpoint. This is just a |
20874c92 | 8230 | heuristic, but if it's wrong, we'll report unexpected SIGTRAP, |
1c5cfe86 | 8231 | which is usability issue, but not a correctness problem. */ |
20874c92 VP |
8232 | loc->events_till_retirement = 3 * (thread_count () + 1); |
8233 | loc->owner = NULL; | |
20874c92 | 8234 | |
1c5cfe86 PA |
8235 | VEC_safe_push (bp_location_p, moribund_locations, loc); |
8236 | } | |
8237 | else | |
8238 | free_bp_location (loc); | |
20874c92 | 8239 | } |
74960c60 | 8240 | } |
1c5cfe86 | 8241 | |
74960c60 VP |
8242 | ALL_BREAKPOINTS (b) |
8243 | { | |
8244 | check_duplicates (b); | |
0d381245 | 8245 | } |
74960c60 | 8246 | |
50c71eaf | 8247 | if (breakpoints_always_inserted_mode () && should_insert |
c35b1492 | 8248 | && (have_live_inferiors () |
2567c7d9 | 8249 | || (gdbarch_has_global_breakpoints (target_gdbarch)))) |
74960c60 | 8250 | insert_breakpoint_locations (); |
f7545552 TT |
8251 | |
8252 | do_cleanups (cleanups); | |
74960c60 VP |
8253 | } |
8254 | ||
20874c92 VP |
8255 | void |
8256 | breakpoint_retire_moribund (void) | |
8257 | { | |
8258 | struct bp_location *loc; | |
8259 | int ix; | |
8260 | ||
8261 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
8262 | if (--(loc->events_till_retirement) == 0) | |
8263 | { | |
8264 | free_bp_location (loc); | |
8265 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
8266 | --ix; | |
8267 | } | |
8268 | } | |
8269 | ||
74960c60 | 8270 | static void |
b60e7edf | 8271 | update_global_location_list_nothrow (int inserting) |
74960c60 VP |
8272 | { |
8273 | struct gdb_exception e; | |
8274 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
b60e7edf | 8275 | update_global_location_list (inserting); |
0d381245 VP |
8276 | } |
8277 | ||
a474d7c2 PA |
8278 | /* Clear BPT from a BPS. */ |
8279 | static void | |
8280 | bpstat_remove_breakpoint (bpstat bps, struct breakpoint *bpt) | |
8281 | { | |
8282 | bpstat bs; | |
8283 | for (bs = bps; bs; bs = bs->next) | |
8284 | if (bs->breakpoint_at && bs->breakpoint_at->owner == bpt) | |
8285 | { | |
8286 | bs->breakpoint_at = NULL; | |
8287 | bs->old_val = NULL; | |
8288 | /* bs->commands will be freed later. */ | |
8289 | } | |
8290 | } | |
8291 | ||
8292 | /* Callback for iterate_over_threads. */ | |
8293 | static int | |
8294 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
8295 | { | |
8296 | struct breakpoint *bpt = data; | |
8297 | bpstat_remove_breakpoint (th->stop_bpstat, bpt); | |
8298 | return 0; | |
8299 | } | |
8300 | ||
53a5351d JM |
8301 | /* Delete a breakpoint and clean up all traces of it in the data |
8302 | structures. */ | |
c906108c SS |
8303 | |
8304 | void | |
fba45db2 | 8305 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 8306 | { |
52f0bd74 | 8307 | struct breakpoint *b; |
74960c60 | 8308 | struct bp_location *loc, *next; |
c906108c | 8309 | |
8a3fe4f8 | 8310 | gdb_assert (bpt != NULL); |
c906108c SS |
8311 | |
8312 | /* Has this bp already been deleted? This can happen because multiple | |
8313 | lists can hold pointers to bp's. bpstat lists are especial culprits. | |
8314 | ||
8315 | One example of this happening is a watchpoint's scope bp. When the | |
8316 | scope bp triggers, we notice that the watchpoint is out of scope, and | |
8317 | delete it. We also delete its scope bp. But the scope bp is marked | |
8318 | "auto-deleting", and is already on a bpstat. That bpstat is then | |
8319 | checked for auto-deleting bp's, which are deleted. | |
8320 | ||
8321 | A real solution to this problem might involve reference counts in bp's, | |
8322 | and/or giving them pointers back to their referencing bpstat's, and | |
8323 | teaching delete_breakpoint to only free a bp's storage when no more | |
1272ad14 | 8324 | references were extent. A cheaper bandaid was chosen. */ |
c906108c SS |
8325 | if (bpt->type == bp_none) |
8326 | return; | |
8327 | ||
383f836e | 8328 | observer_notify_breakpoint_deleted (bpt->number); |
c906108c | 8329 | |
c906108c SS |
8330 | if (breakpoint_chain == bpt) |
8331 | breakpoint_chain = bpt->next; | |
8332 | ||
c906108c SS |
8333 | ALL_BREAKPOINTS (b) |
8334 | if (b->next == bpt) | |
c5aa993b JM |
8335 | { |
8336 | b->next = bpt->next; | |
8337 | break; | |
8338 | } | |
c906108c | 8339 | |
c906108c | 8340 | free_command_lines (&bpt->commands); |
c906108c | 8341 | if (bpt->cond_string != NULL) |
b8c9b27d | 8342 | xfree (bpt->cond_string); |
c906108c | 8343 | if (bpt->addr_string != NULL) |
b8c9b27d | 8344 | xfree (bpt->addr_string); |
c906108c | 8345 | if (bpt->exp != NULL) |
b8c9b27d | 8346 | xfree (bpt->exp); |
c906108c | 8347 | if (bpt->exp_string != NULL) |
b8c9b27d | 8348 | xfree (bpt->exp_string); |
c906108c SS |
8349 | if (bpt->val != NULL) |
8350 | value_free (bpt->val); | |
8351 | if (bpt->source_file != NULL) | |
b8c9b27d | 8352 | xfree (bpt->source_file); |
c906108c | 8353 | if (bpt->exec_pathname != NULL) |
b8c9b27d | 8354 | xfree (bpt->exec_pathname); |
a96d9b2e | 8355 | clean_up_filters (&bpt->syscalls_to_be_caught); |
c906108c SS |
8356 | |
8357 | /* Be sure no bpstat's are pointing at it after it's been freed. */ | |
8358 | /* FIXME, how can we find all bpstat's? | |
198757a8 VP |
8359 | We just check stop_bpstat for now. Note that we cannot just |
8360 | remove bpstats pointing at bpt from the stop_bpstat list | |
8361 | entirely, as breakpoint commands are associated with the bpstat; | |
8362 | if we remove it here, then the later call to | |
8363 | bpstat_do_actions (&stop_bpstat); | |
8364 | in event-top.c won't do anything, and temporary breakpoints | |
8365 | with commands won't work. */ | |
a474d7c2 | 8366 | |
a474d7c2 | 8367 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); |
74960c60 VP |
8368 | |
8369 | /* Now that breakpoint is removed from breakpoint | |
8370 | list, update the global location list. This | |
8371 | will remove locations that used to belong to | |
8372 | this breakpoint. Do this before freeing | |
8373 | the breakpoint itself, since remove_breakpoint | |
8374 | looks at location's owner. It might be better | |
8375 | design to have location completely self-contained, | |
8376 | but it's not the case now. */ | |
b60e7edf | 8377 | update_global_location_list (0); |
74960c60 VP |
8378 | |
8379 | ||
c906108c SS |
8380 | /* On the chance that someone will soon try again to delete this same |
8381 | bp, we mark it as deleted before freeing its storage. */ | |
8382 | bpt->type = bp_none; | |
8383 | ||
b8c9b27d | 8384 | xfree (bpt); |
c906108c SS |
8385 | } |
8386 | ||
4d6140d9 AC |
8387 | static void |
8388 | do_delete_breakpoint_cleanup (void *b) | |
8389 | { | |
8390 | delete_breakpoint (b); | |
8391 | } | |
8392 | ||
8393 | struct cleanup * | |
8394 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
8395 | { | |
8396 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
8397 | } | |
8398 | ||
c906108c | 8399 | void |
fba45db2 | 8400 | delete_command (char *arg, int from_tty) |
c906108c SS |
8401 | { |
8402 | struct breakpoint *b, *temp; | |
8403 | ||
ea9365bb TT |
8404 | dont_repeat (); |
8405 | ||
c906108c SS |
8406 | if (arg == 0) |
8407 | { | |
8408 | int breaks_to_delete = 0; | |
8409 | ||
8410 | /* Delete all breakpoints if no argument. | |
c5aa993b JM |
8411 | Do not delete internal or call-dummy breakpoints, these |
8412 | have to be deleted with an explicit breakpoint number argument. */ | |
8413 | ALL_BREAKPOINTS (b) | |
8414 | { | |
059fb39f PM |
8415 | if (b->type != bp_call_dummy |
8416 | && b->type != bp_shlib_event | |
4efc6507 | 8417 | && b->type != bp_jit_event |
059fb39f PM |
8418 | && b->type != bp_thread_event |
8419 | && b->type != bp_overlay_event | |
0fd8e87f | 8420 | && b->type != bp_longjmp_master |
059fb39f | 8421 | && b->number >= 0) |
973d738b DJ |
8422 | { |
8423 | breaks_to_delete = 1; | |
8424 | break; | |
8425 | } | |
c5aa993b | 8426 | } |
c906108c SS |
8427 | |
8428 | /* Ask user only if there are some breakpoints to delete. */ | |
8429 | if (!from_tty | |
e2e0b3e5 | 8430 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 8431 | { |
c5aa993b JM |
8432 | ALL_BREAKPOINTS_SAFE (b, temp) |
8433 | { | |
059fb39f PM |
8434 | if (b->type != bp_call_dummy |
8435 | && b->type != bp_shlib_event | |
8436 | && b->type != bp_thread_event | |
4efc6507 | 8437 | && b->type != bp_jit_event |
059fb39f | 8438 | && b->type != bp_overlay_event |
0fd8e87f | 8439 | && b->type != bp_longjmp_master |
059fb39f | 8440 | && b->number >= 0) |
c5aa993b JM |
8441 | delete_breakpoint (b); |
8442 | } | |
c906108c SS |
8443 | } |
8444 | } | |
8445 | else | |
8446 | map_breakpoint_numbers (arg, delete_breakpoint); | |
8447 | } | |
8448 | ||
0d381245 VP |
8449 | static int |
8450 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 8451 | { |
0d381245 VP |
8452 | for (; loc; loc = loc->next) |
8453 | if (!loc->shlib_disabled) | |
8454 | return 0; | |
8455 | return 1; | |
fe3f5fa8 VP |
8456 | } |
8457 | ||
776592bf DE |
8458 | /* Subroutine of update_breakpoint_locations to simplify it. |
8459 | Return non-zero if multiple fns in list LOC have the same name. | |
8460 | Null names are ignored. */ | |
8461 | ||
8462 | static int | |
8463 | ambiguous_names_p (struct bp_location *loc) | |
8464 | { | |
8465 | struct bp_location *l; | |
8466 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
8467 | (int (*) (const void *, const void *)) streq, | |
8468 | NULL, xcalloc, xfree); | |
8469 | ||
8470 | for (l = loc; l != NULL; l = l->next) | |
8471 | { | |
8472 | const char **slot; | |
8473 | const char *name = l->function_name; | |
8474 | ||
8475 | /* Allow for some names to be NULL, ignore them. */ | |
8476 | if (name == NULL) | |
8477 | continue; | |
8478 | ||
8479 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
8480 | INSERT); | |
8481 | /* NOTE: We can assume slot != NULL here because xcalloc never returns | |
8482 | NULL. */ | |
8483 | if (*slot != NULL) | |
8484 | { | |
8485 | htab_delete (htab); | |
8486 | return 1; | |
8487 | } | |
8488 | *slot = name; | |
8489 | } | |
8490 | ||
8491 | htab_delete (htab); | |
8492 | return 0; | |
8493 | } | |
8494 | ||
fe3f5fa8 | 8495 | static void |
0d381245 VP |
8496 | update_breakpoint_locations (struct breakpoint *b, |
8497 | struct symtabs_and_lines sals) | |
fe3f5fa8 VP |
8498 | { |
8499 | int i; | |
8500 | char *s; | |
0d381245 VP |
8501 | struct bp_location *existing_locations = b->loc; |
8502 | ||
8503 | /* If there's no new locations, and all existing locations | |
8504 | are pending, don't do anything. This optimizes | |
8505 | the common case where all locations are in the same | |
8506 | shared library, that was unloaded. We'd like to | |
8507 | retain the location, so that when the library | |
8508 | is loaded again, we don't loose the enabled/disabled | |
8509 | status of the individual locations. */ | |
8510 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) | |
fe3f5fa8 VP |
8511 | return; |
8512 | ||
fe3f5fa8 VP |
8513 | b->loc = NULL; |
8514 | ||
0d381245 | 8515 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 8516 | { |
0d381245 | 8517 | struct bp_location *new_loc = |
39d61571 | 8518 | add_location_to_breakpoint (b, &(sals.sals[i])); |
fe3f5fa8 | 8519 | |
0d381245 VP |
8520 | /* Reparse conditions, they might contain references to the |
8521 | old symtab. */ | |
8522 | if (b->cond_string != NULL) | |
8523 | { | |
8524 | struct gdb_exception e; | |
fe3f5fa8 | 8525 | |
0d381245 VP |
8526 | s = b->cond_string; |
8527 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
8528 | { | |
8529 | new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), | |
8530 | 0); | |
8531 | } | |
8532 | if (e.reason < 0) | |
8533 | { | |
8534 | warning (_("failed to reevaluate condition for breakpoint %d: %s"), | |
8535 | b->number, e.message); | |
8536 | new_loc->enabled = 0; | |
8537 | } | |
8538 | } | |
fe3f5fa8 | 8539 | |
0d381245 VP |
8540 | if (b->source_file != NULL) |
8541 | xfree (b->source_file); | |
8542 | if (sals.sals[i].symtab == NULL) | |
8543 | b->source_file = NULL; | |
8544 | else | |
1b36a34b | 8545 | b->source_file = xstrdup (sals.sals[i].symtab->filename); |
fe3f5fa8 | 8546 | |
0d381245 VP |
8547 | if (b->line_number == 0) |
8548 | b->line_number = sals.sals[i].line; | |
8549 | } | |
fe3f5fa8 | 8550 | |
514f746b AR |
8551 | /* Update locations of permanent breakpoints. */ |
8552 | if (b->enable_state == bp_permanent) | |
8553 | make_breakpoint_permanent (b); | |
8554 | ||
0d381245 VP |
8555 | /* If possible, carry over 'disable' status from existing breakpoints. */ |
8556 | { | |
8557 | struct bp_location *e = existing_locations; | |
776592bf DE |
8558 | /* If there are multiple breakpoints with the same function name, |
8559 | e.g. for inline functions, comparing function names won't work. | |
8560 | Instead compare pc addresses; this is just a heuristic as things | |
8561 | may have moved, but in practice it gives the correct answer | |
8562 | often enough until a better solution is found. */ | |
8563 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
8564 | ||
0d381245 VP |
8565 | for (; e; e = e->next) |
8566 | { | |
8567 | if (!e->enabled && e->function_name) | |
8568 | { | |
8569 | struct bp_location *l = b->loc; | |
776592bf DE |
8570 | if (have_ambiguous_names) |
8571 | { | |
8572 | for (; l; l = l->next) | |
6c95b8df PA |
8573 | if (breakpoint_address_match (e->pspace->aspace, e->address, |
8574 | l->pspace->aspace, l->address)) | |
776592bf DE |
8575 | { |
8576 | l->enabled = 0; | |
8577 | break; | |
8578 | } | |
8579 | } | |
8580 | else | |
8581 | { | |
8582 | for (; l; l = l->next) | |
8583 | if (l->function_name | |
8584 | && strcmp (e->function_name, l->function_name) == 0) | |
8585 | { | |
8586 | l->enabled = 0; | |
8587 | break; | |
8588 | } | |
8589 | } | |
0d381245 VP |
8590 | } |
8591 | } | |
8592 | } | |
fe3f5fa8 | 8593 | |
b60e7edf | 8594 | update_global_location_list (1); |
fe3f5fa8 VP |
8595 | } |
8596 | ||
8597 | ||
c906108c SS |
8598 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
8599 | The value we return ends up being the return value from catch_errors. | |
8600 | Unused in this case. */ | |
8601 | ||
8602 | static int | |
4efb68b1 | 8603 | breakpoint_re_set_one (void *bint) |
c906108c | 8604 | { |
53a5351d JM |
8605 | /* get past catch_errs */ |
8606 | struct breakpoint *b = (struct breakpoint *) bint; | |
c906108c SS |
8607 | struct value *mark; |
8608 | int i; | |
fe3f5fa8 VP |
8609 | int not_found = 0; |
8610 | int *not_found_ptr = ¬_found; | |
6c95b8df PA |
8611 | struct symtabs_and_lines sals = {0}; |
8612 | struct symtabs_and_lines expanded = {0}; | |
c906108c | 8613 | char *s; |
b5de0fa7 | 8614 | enum enable_state save_enable; |
fe3f5fa8 | 8615 | struct gdb_exception e; |
6c95b8df | 8616 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
c906108c SS |
8617 | |
8618 | switch (b->type) | |
8619 | { | |
8620 | case bp_none: | |
8a3fe4f8 | 8621 | warning (_("attempted to reset apparently deleted breakpoint #%d?"), |
53a5351d | 8622 | b->number); |
c906108c SS |
8623 | return 0; |
8624 | case bp_breakpoint: | |
8625 | case bp_hardware_breakpoint: | |
1042e4c0 | 8626 | case bp_tracepoint: |
8bea4e01 UW |
8627 | /* Do not attempt to re-set breakpoints disabled during startup. */ |
8628 | if (b->enable_state == bp_startup_disabled) | |
8629 | return 0; | |
8630 | ||
c906108c SS |
8631 | if (b->addr_string == NULL) |
8632 | { | |
8633 | /* Anything without a string can't be re-set. */ | |
8634 | delete_breakpoint (b); | |
8635 | return 0; | |
8636 | } | |
c906108c SS |
8637 | |
8638 | set_language (b->language); | |
8639 | input_radix = b->input_radix; | |
8640 | s = b->addr_string; | |
6c95b8df PA |
8641 | |
8642 | save_current_space_and_thread (); | |
8643 | switch_to_program_space_and_thread (b->pspace); | |
8644 | ||
fe3f5fa8 | 8645 | TRY_CATCH (e, RETURN_MASK_ERROR) |
c906108c | 8646 | { |
fe3f5fa8 VP |
8647 | sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL, |
8648 | not_found_ptr); | |
8649 | } | |
8650 | if (e.reason < 0) | |
8651 | { | |
8652 | int not_found_and_ok = 0; | |
8653 | /* For pending breakpoints, it's expected that parsing | |
8654 | will fail until the right shared library is loaded. | |
8655 | User has already told to create pending breakpoints and | |
8656 | don't need extra messages. If breakpoint is in bp_shlib_disabled | |
8657 | state, then user already saw the message about that breakpoint | |
8658 | being disabled, and don't want to see more errors. */ | |
0d381245 VP |
8659 | if (not_found |
8660 | && (b->condition_not_parsed | |
8661 | || (b->loc && b->loc->shlib_disabled) | |
8662 | || b->enable_state == bp_disabled)) | |
fe3f5fa8 VP |
8663 | not_found_and_ok = 1; |
8664 | ||
8665 | if (!not_found_and_ok) | |
c906108c | 8666 | { |
fe3f5fa8 VP |
8667 | /* We surely don't want to warn about the same breakpoint |
8668 | 10 times. One solution, implemented here, is disable | |
8669 | the breakpoint on error. Another solution would be to | |
8670 | have separate 'warning emitted' flag. Since this | |
8671 | happens only when a binary has changed, I don't know | |
8672 | which approach is better. */ | |
8673 | b->enable_state = bp_disabled; | |
8674 | throw_exception (e); | |
c906108c | 8675 | } |
fe3f5fa8 | 8676 | } |
c906108c | 8677 | |
6c95b8df | 8678 | if (!not_found) |
fe3f5fa8 | 8679 | { |
6c95b8df PA |
8680 | gdb_assert (sals.nelts == 1); |
8681 | ||
8682 | resolve_sal_pc (&sals.sals[0]); | |
8683 | if (b->condition_not_parsed && s && s[0]) | |
8684 | { | |
8685 | char *cond_string = 0; | |
8686 | int thread = -1; | |
8687 | int task = 0; | |
8688 | ||
8689 | find_condition_and_thread (s, sals.sals[0].pc, | |
8690 | &cond_string, &thread, &task); | |
8691 | if (cond_string) | |
8692 | b->cond_string = cond_string; | |
8693 | b->thread = thread; | |
8694 | b->task = task; | |
8695 | b->condition_not_parsed = 0; | |
8696 | } | |
8697 | ||
8698 | expanded = expand_line_sal_maybe (sals.sals[0]); | |
fe3f5fa8 | 8699 | } |
6c95b8df PA |
8700 | |
8701 | make_cleanup (xfree, sals.sals); | |
ed0616c6 | 8702 | update_breakpoint_locations (b, expanded); |
c906108c SS |
8703 | break; |
8704 | ||
8705 | case bp_watchpoint: | |
8706 | case bp_hardware_watchpoint: | |
8707 | case bp_read_watchpoint: | |
8708 | case bp_access_watchpoint: | |
0b3de036 VP |
8709 | /* Watchpoint can be either on expression using entirely global variables, |
8710 | or it can be on local variables. | |
8711 | ||
8712 | Watchpoints of the first kind are never auto-deleted, and even persist | |
8713 | across program restarts. Since they can use variables from shared | |
8714 | libraries, we need to reparse expression as libraries are loaded | |
8715 | and unloaded. | |
8716 | ||
8717 | Watchpoints on local variables can also change meaning as result | |
8718 | of solib event. For example, if a watchpoint uses both a local and | |
8719 | a global variables in expression, it's a local watchpoint, but | |
8720 | unloading of a shared library will make the expression invalid. | |
8721 | This is not a very common use case, but we still re-evaluate | |
8722 | expression, to avoid surprises to the user. | |
8723 | ||
8724 | Note that for local watchpoints, we re-evaluate it only if | |
8725 | watchpoints frame id is still valid. If it's not, it means | |
8726 | the watchpoint is out of scope and will be deleted soon. In fact, | |
8727 | I'm not sure we'll ever be called in this case. | |
8728 | ||
8729 | If a local watchpoint's frame id is still valid, then | |
8730 | b->exp_valid_block is likewise valid, and we can safely use it. | |
8731 | ||
8732 | Don't do anything about disabled watchpoints, since they will | |
8733 | be reevaluated again when enabled. */ | |
a5606eee | 8734 | update_watchpoint (b, 1 /* reparse */); |
c906108c | 8735 | break; |
c5aa993b JM |
8736 | /* We needn't really do anything to reset these, since the mask |
8737 | that requests them is unaffected by e.g., new libraries being | |
8738 | loaded. */ | |
ce78b96d | 8739 | case bp_catchpoint: |
c906108c | 8740 | break; |
c5aa993b | 8741 | |
c906108c | 8742 | default: |
a3f17187 | 8743 | printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type); |
c906108c | 8744 | /* fall through */ |
0fd8e87f UW |
8745 | /* Delete overlay event and longjmp master breakpoints; they will be |
8746 | reset later by breakpoint_re_set. */ | |
1900040c | 8747 | case bp_overlay_event: |
0fd8e87f | 8748 | case bp_longjmp_master: |
c906108c SS |
8749 | delete_breakpoint (b); |
8750 | break; | |
8751 | ||
c5aa993b JM |
8752 | /* This breakpoint is special, it's set up when the inferior |
8753 | starts and we really don't want to touch it. */ | |
c906108c SS |
8754 | case bp_shlib_event: |
8755 | ||
c4093a6a JM |
8756 | /* Like bp_shlib_event, this breakpoint type is special. |
8757 | Once it is set up, we do not want to touch it. */ | |
8758 | case bp_thread_event: | |
8759 | ||
c5aa993b JM |
8760 | /* Keep temporary breakpoints, which can be encountered when we step |
8761 | over a dlopen call and SOLIB_ADD is resetting the breakpoints. | |
8762 | Otherwise these should have been blown away via the cleanup chain | |
8763 | or by breakpoint_init_inferior when we rerun the executable. */ | |
c906108c SS |
8764 | case bp_until: |
8765 | case bp_finish: | |
8766 | case bp_watchpoint_scope: | |
8767 | case bp_call_dummy: | |
8768 | case bp_step_resume: | |
611c83ae PA |
8769 | case bp_longjmp: |
8770 | case bp_longjmp_resume: | |
4efc6507 | 8771 | case bp_jit_event: |
c906108c SS |
8772 | break; |
8773 | } | |
8774 | ||
6c95b8df | 8775 | do_cleanups (cleanups); |
c906108c SS |
8776 | return 0; |
8777 | } | |
8778 | ||
69de3c6a | 8779 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 8780 | void |
69de3c6a | 8781 | breakpoint_re_set (void) |
c906108c SS |
8782 | { |
8783 | struct breakpoint *b, *temp; | |
8784 | enum language save_language; | |
8785 | int save_input_radix; | |
6c95b8df | 8786 | struct cleanup *old_chain; |
c5aa993b | 8787 | |
c906108c SS |
8788 | save_language = current_language->la_language; |
8789 | save_input_radix = input_radix; | |
6c95b8df PA |
8790 | old_chain = save_current_program_space (); |
8791 | ||
c906108c | 8792 | ALL_BREAKPOINTS_SAFE (b, temp) |
c5aa993b | 8793 | { |
53a5351d | 8794 | /* Format possible error msg */ |
fe3f5fa8 | 8795 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
8796 | b->number); |
8797 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 8798 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 8799 | do_cleanups (cleanups); |
c5aa993b | 8800 | } |
c906108c SS |
8801 | set_language (save_language); |
8802 | input_radix = save_input_radix; | |
e62c965a | 8803 | |
0756c555 | 8804 | jit_breakpoint_re_set (); |
4efc6507 | 8805 | |
6c95b8df PA |
8806 | do_cleanups (old_chain); |
8807 | ||
69de3c6a | 8808 | create_overlay_event_breakpoint ("_ovly_debug_event"); |
0fd8e87f UW |
8809 | create_longjmp_master_breakpoint ("longjmp"); |
8810 | create_longjmp_master_breakpoint ("_longjmp"); | |
8811 | create_longjmp_master_breakpoint ("siglongjmp"); | |
8812 | create_longjmp_master_breakpoint ("_siglongjmp"); | |
c906108c SS |
8813 | } |
8814 | \f | |
c906108c SS |
8815 | /* Reset the thread number of this breakpoint: |
8816 | ||
8817 | - If the breakpoint is for all threads, leave it as-is. | |
39f77062 | 8818 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 8819 | void |
fba45db2 | 8820 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
8821 | { |
8822 | if (b->thread != -1) | |
8823 | { | |
39f77062 KB |
8824 | if (in_thread_list (inferior_ptid)) |
8825 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
8826 | |
8827 | /* We're being called after following a fork. The new fork is | |
8828 | selected as current, and unless this was a vfork will have a | |
8829 | different program space from the original thread. Reset that | |
8830 | as well. */ | |
8831 | b->loc->pspace = current_program_space; | |
c906108c SS |
8832 | } |
8833 | } | |
8834 | ||
03ac34d5 MS |
8835 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
8836 | If from_tty is nonzero, it prints a message to that effect, | |
8837 | which ends with a period (no newline). */ | |
8838 | ||
c906108c | 8839 | void |
fba45db2 | 8840 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 8841 | { |
52f0bd74 | 8842 | struct breakpoint *b; |
c906108c SS |
8843 | |
8844 | if (count < 0) | |
8845 | count = 0; | |
8846 | ||
8847 | ALL_BREAKPOINTS (b) | |
8848 | if (b->number == bptnum) | |
c5aa993b JM |
8849 | { |
8850 | b->ignore_count = count; | |
221ea385 KS |
8851 | if (from_tty) |
8852 | { | |
8853 | if (count == 0) | |
a3f17187 | 8854 | printf_filtered (_("Will stop next time breakpoint %d is reached."), |
221ea385 KS |
8855 | bptnum); |
8856 | else if (count == 1) | |
a3f17187 | 8857 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
8858 | bptnum); |
8859 | else | |
a3f17187 | 8860 | printf_filtered (_("Will ignore next %d crossings of breakpoint %d."), |
221ea385 KS |
8861 | count, bptnum); |
8862 | } | |
c5aa993b | 8863 | breakpoints_changed (); |
383f836e | 8864 | observer_notify_breakpoint_modified (b->number); |
c5aa993b JM |
8865 | return; |
8866 | } | |
c906108c | 8867 | |
8a3fe4f8 | 8868 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
8869 | } |
8870 | ||
b2175913 MS |
8871 | void |
8872 | make_breakpoint_silent (struct breakpoint *b) | |
8873 | { | |
8874 | /* Silence the breakpoint. */ | |
8875 | b->silent = 1; | |
8876 | } | |
8877 | ||
c906108c SS |
8878 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
8879 | ||
8880 | static void | |
fba45db2 | 8881 | ignore_command (char *args, int from_tty) |
c906108c SS |
8882 | { |
8883 | char *p = args; | |
52f0bd74 | 8884 | int num; |
c906108c SS |
8885 | |
8886 | if (p == 0) | |
e2e0b3e5 | 8887 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 8888 | |
c906108c | 8889 | num = get_number (&p); |
5c44784c | 8890 | if (num == 0) |
8a3fe4f8 | 8891 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 8892 | if (*p == 0) |
8a3fe4f8 | 8893 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
8894 | |
8895 | set_ignore_count (num, | |
8896 | longest_to_int (value_as_long (parse_and_eval (p))), | |
8897 | from_tty); | |
221ea385 KS |
8898 | if (from_tty) |
8899 | printf_filtered ("\n"); | |
c906108c SS |
8900 | } |
8901 | \f | |
8902 | /* Call FUNCTION on each of the breakpoints | |
8903 | whose numbers are given in ARGS. */ | |
8904 | ||
8905 | static void | |
831662b3 | 8906 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *)) |
c906108c | 8907 | { |
52f0bd74 | 8908 | char *p = args; |
c906108c | 8909 | char *p1; |
52f0bd74 AC |
8910 | int num; |
8911 | struct breakpoint *b, *tmp; | |
11cf8741 | 8912 | int match; |
c906108c SS |
8913 | |
8914 | if (p == 0) | |
e2e0b3e5 | 8915 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c SS |
8916 | |
8917 | while (*p) | |
8918 | { | |
11cf8741 | 8919 | match = 0; |
c906108c | 8920 | p1 = p; |
c5aa993b | 8921 | |
5c44784c JM |
8922 | num = get_number_or_range (&p1); |
8923 | if (num == 0) | |
c5aa993b | 8924 | { |
8a3fe4f8 | 8925 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
8926 | } |
8927 | else | |
8928 | { | |
8929 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
8930 | if (b->number == num) | |
8931 | { | |
8932 | struct breakpoint *related_breakpoint = b->related_breakpoint; | |
11cf8741 | 8933 | match = 1; |
5c44784c JM |
8934 | function (b); |
8935 | if (related_breakpoint) | |
8936 | function (related_breakpoint); | |
11cf8741 | 8937 | break; |
5c44784c | 8938 | } |
11cf8741 | 8939 | if (match == 0) |
a3f17187 | 8940 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 8941 | } |
c906108c SS |
8942 | p = p1; |
8943 | } | |
8944 | } | |
8945 | ||
0d381245 VP |
8946 | static struct bp_location * |
8947 | find_location_by_number (char *number) | |
8948 | { | |
8949 | char *dot = strchr (number, '.'); | |
8950 | char *p1; | |
8951 | int bp_num; | |
8952 | int loc_num; | |
8953 | struct breakpoint *b; | |
8954 | struct bp_location *loc; | |
8955 | ||
8956 | *dot = '\0'; | |
8957 | ||
8958 | p1 = number; | |
8959 | bp_num = get_number_or_range (&p1); | |
8960 | if (bp_num == 0) | |
8961 | error (_("Bad breakpoint number '%s'"), number); | |
8962 | ||
8963 | ALL_BREAKPOINTS (b) | |
8964 | if (b->number == bp_num) | |
8965 | { | |
8966 | break; | |
8967 | } | |
8968 | ||
8969 | if (!b || b->number != bp_num) | |
8970 | error (_("Bad breakpoint number '%s'"), number); | |
8971 | ||
8972 | p1 = dot+1; | |
8973 | loc_num = get_number_or_range (&p1); | |
8974 | if (loc_num == 0) | |
8975 | error (_("Bad breakpoint location number '%s'"), number); | |
8976 | ||
8977 | --loc_num; | |
8978 | loc = b->loc; | |
8979 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
8980 | ; | |
8981 | if (!loc) | |
8982 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
8983 | ||
8984 | return loc; | |
8985 | } | |
8986 | ||
8987 | ||
1900040c MS |
8988 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
8989 | If from_tty is nonzero, it prints a message to that effect, | |
8990 | which ends with a period (no newline). */ | |
8991 | ||
c906108c | 8992 | void |
fba45db2 | 8993 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
8994 | { |
8995 | /* Never disable a watchpoint scope breakpoint; we want to | |
8996 | hit them when we leave scope so we can delete both the | |
8997 | watchpoint and its scope breakpoint at that time. */ | |
8998 | if (bpt->type == bp_watchpoint_scope) | |
8999 | return; | |
9000 | ||
c2c6d25f | 9001 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 9002 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
9003 | return; |
9004 | ||
b5de0fa7 | 9005 | bpt->enable_state = bp_disabled; |
c906108c | 9006 | |
b60e7edf | 9007 | update_global_location_list (0); |
c906108c | 9008 | |
383f836e | 9009 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
9010 | } |
9011 | ||
c906108c | 9012 | static void |
fba45db2 | 9013 | disable_command (char *args, int from_tty) |
c906108c | 9014 | { |
52f0bd74 | 9015 | struct breakpoint *bpt; |
c906108c SS |
9016 | if (args == 0) |
9017 | ALL_BREAKPOINTS (bpt) | |
9018 | switch (bpt->type) | |
c5aa993b JM |
9019 | { |
9020 | case bp_none: | |
8a3fe4f8 | 9021 | warning (_("attempted to disable apparently deleted breakpoint #%d?"), |
53a5351d | 9022 | bpt->number); |
c5aa993b JM |
9023 | continue; |
9024 | case bp_breakpoint: | |
1042e4c0 | 9025 | case bp_tracepoint: |
ce78b96d | 9026 | case bp_catchpoint: |
c5aa993b JM |
9027 | case bp_hardware_breakpoint: |
9028 | case bp_watchpoint: | |
9029 | case bp_hardware_watchpoint: | |
9030 | case bp_read_watchpoint: | |
9031 | case bp_access_watchpoint: | |
9032 | disable_breakpoint (bpt); | |
9033 | default: | |
9034 | continue; | |
9035 | } | |
0d381245 VP |
9036 | else if (strchr (args, '.')) |
9037 | { | |
9038 | struct bp_location *loc = find_location_by_number (args); | |
9039 | if (loc) | |
9040 | loc->enabled = 0; | |
b60e7edf | 9041 | update_global_location_list (0); |
0d381245 | 9042 | } |
c906108c SS |
9043 | else |
9044 | map_breakpoint_numbers (args, disable_breakpoint); | |
9045 | } | |
9046 | ||
9047 | static void | |
fba45db2 | 9048 | do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition) |
c906108c | 9049 | { |
c906108c SS |
9050 | int target_resources_ok, other_type_used; |
9051 | struct value *mark; | |
9052 | ||
9053 | if (bpt->type == bp_hardware_breakpoint) | |
9054 | { | |
9055 | int i; | |
c5aa993b | 9056 | i = hw_breakpoint_used_count (); |
53a5351d | 9057 | target_resources_ok = |
d92524f1 | 9058 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 9059 | i + 1, 0); |
c906108c | 9060 | if (target_resources_ok == 0) |
8a3fe4f8 | 9061 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 9062 | else if (target_resources_ok < 0) |
8a3fe4f8 | 9063 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
9064 | } |
9065 | ||
059fb39f PM |
9066 | if (bpt->type == bp_watchpoint |
9067 | || bpt->type == bp_hardware_watchpoint | |
9068 | || bpt->type == bp_read_watchpoint | |
9069 | || bpt->type == bp_access_watchpoint) | |
c906108c | 9070 | { |
dde02812 ES |
9071 | struct gdb_exception e; |
9072 | ||
9073 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 9074 | { |
dde02812 | 9075 | update_watchpoint (bpt, 1 /* reparse */); |
c906108c | 9076 | } |
dde02812 | 9077 | if (e.reason < 0) |
c5aa993b | 9078 | { |
dde02812 ES |
9079 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
9080 | bpt->number); | |
9081 | return; | |
c5aa993b | 9082 | } |
c906108c | 9083 | } |
0101ce28 | 9084 | |
b4c291bb KH |
9085 | if (bpt->enable_state != bp_permanent) |
9086 | bpt->enable_state = bp_enabled; | |
9087 | bpt->disposition = disposition; | |
b60e7edf | 9088 | update_global_location_list (1); |
b4c291bb KH |
9089 | breakpoints_changed (); |
9090 | ||
383f836e | 9091 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
9092 | } |
9093 | ||
fe3f5fa8 | 9094 | |
c906108c | 9095 | void |
fba45db2 | 9096 | enable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
9097 | { |
9098 | do_enable_breakpoint (bpt, bpt->disposition); | |
9099 | } | |
9100 | ||
9101 | /* The enable command enables the specified breakpoints (or all defined | |
9102 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 9103 | in stopping the inferior. */ |
c906108c | 9104 | |
c906108c | 9105 | static void |
fba45db2 | 9106 | enable_command (char *args, int from_tty) |
c906108c | 9107 | { |
52f0bd74 | 9108 | struct breakpoint *bpt; |
c906108c SS |
9109 | if (args == 0) |
9110 | ALL_BREAKPOINTS (bpt) | |
9111 | switch (bpt->type) | |
c5aa993b JM |
9112 | { |
9113 | case bp_none: | |
8a3fe4f8 | 9114 | warning (_("attempted to enable apparently deleted breakpoint #%d?"), |
53a5351d | 9115 | bpt->number); |
c5aa993b JM |
9116 | continue; |
9117 | case bp_breakpoint: | |
1042e4c0 | 9118 | case bp_tracepoint: |
ce78b96d | 9119 | case bp_catchpoint: |
c5aa993b JM |
9120 | case bp_hardware_breakpoint: |
9121 | case bp_watchpoint: | |
9122 | case bp_hardware_watchpoint: | |
9123 | case bp_read_watchpoint: | |
9124 | case bp_access_watchpoint: | |
9125 | enable_breakpoint (bpt); | |
9126 | default: | |
9127 | continue; | |
9128 | } | |
0d381245 VP |
9129 | else if (strchr (args, '.')) |
9130 | { | |
9131 | struct bp_location *loc = find_location_by_number (args); | |
9132 | if (loc) | |
9133 | loc->enabled = 1; | |
b60e7edf | 9134 | update_global_location_list (1); |
0d381245 | 9135 | } |
c906108c SS |
9136 | else |
9137 | map_breakpoint_numbers (args, enable_breakpoint); | |
9138 | } | |
9139 | ||
9140 | static void | |
fba45db2 | 9141 | enable_once_breakpoint (struct breakpoint *bpt) |
c906108c | 9142 | { |
b5de0fa7 | 9143 | do_enable_breakpoint (bpt, disp_disable); |
c906108c SS |
9144 | } |
9145 | ||
c906108c | 9146 | static void |
fba45db2 | 9147 | enable_once_command (char *args, int from_tty) |
c906108c SS |
9148 | { |
9149 | map_breakpoint_numbers (args, enable_once_breakpoint); | |
9150 | } | |
9151 | ||
9152 | static void | |
fba45db2 | 9153 | enable_delete_breakpoint (struct breakpoint *bpt) |
c906108c | 9154 | { |
b5de0fa7 | 9155 | do_enable_breakpoint (bpt, disp_del); |
c906108c SS |
9156 | } |
9157 | ||
c906108c | 9158 | static void |
fba45db2 | 9159 | enable_delete_command (char *args, int from_tty) |
c906108c SS |
9160 | { |
9161 | map_breakpoint_numbers (args, enable_delete_breakpoint); | |
9162 | } | |
9163 | \f | |
fa8d40ab JJ |
9164 | static void |
9165 | set_breakpoint_cmd (char *args, int from_tty) | |
9166 | { | |
9167 | } | |
9168 | ||
9169 | static void | |
9170 | show_breakpoint_cmd (char *args, int from_tty) | |
9171 | { | |
9172 | } | |
9173 | ||
c906108c SS |
9174 | /* Use default_breakpoint_'s, or nothing if they aren't valid. */ |
9175 | ||
9176 | struct symtabs_and_lines | |
fba45db2 | 9177 | decode_line_spec_1 (char *string, int funfirstline) |
c906108c SS |
9178 | { |
9179 | struct symtabs_and_lines sals; | |
9180 | if (string == 0) | |
8a3fe4f8 | 9181 | error (_("Empty line specification.")); |
c906108c SS |
9182 | if (default_breakpoint_valid) |
9183 | sals = decode_line_1 (&string, funfirstline, | |
53a5351d JM |
9184 | default_breakpoint_symtab, |
9185 | default_breakpoint_line, | |
68219205 | 9186 | (char ***) NULL, NULL); |
c906108c SS |
9187 | else |
9188 | sals = decode_line_1 (&string, funfirstline, | |
68219205 | 9189 | (struct symtab *) NULL, 0, (char ***) NULL, NULL); |
c906108c | 9190 | if (*string) |
8a3fe4f8 | 9191 | error (_("Junk at end of line specification: %s"), string); |
c906108c SS |
9192 | return sals; |
9193 | } | |
8181d85f DJ |
9194 | |
9195 | /* Create and insert a raw software breakpoint at PC. Return an | |
9196 | identifier, which should be used to remove the breakpoint later. | |
9197 | In general, places which call this should be using something on the | |
9198 | breakpoint chain instead; this function should be eliminated | |
9199 | someday. */ | |
9200 | ||
9201 | void * | |
6c95b8df PA |
9202 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, |
9203 | struct address_space *aspace, CORE_ADDR pc) | |
8181d85f DJ |
9204 | { |
9205 | struct bp_target_info *bp_tgt; | |
9206 | ||
6c95b8df | 9207 | bp_tgt = XZALLOC (struct bp_target_info); |
8181d85f | 9208 | |
6c95b8df | 9209 | bp_tgt->placed_address_space = aspace; |
8181d85f | 9210 | bp_tgt->placed_address = pc; |
6c95b8df | 9211 | |
a6d9a66e | 9212 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
8181d85f DJ |
9213 | { |
9214 | /* Could not insert the breakpoint. */ | |
9215 | xfree (bp_tgt); | |
9216 | return NULL; | |
9217 | } | |
9218 | ||
9219 | return bp_tgt; | |
9220 | } | |
9221 | ||
9222 | /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */ | |
9223 | ||
9224 | int | |
a6d9a66e | 9225 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
8181d85f DJ |
9226 | { |
9227 | struct bp_target_info *bp_tgt = bp; | |
9228 | int ret; | |
9229 | ||
a6d9a66e | 9230 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
8181d85f DJ |
9231 | xfree (bp_tgt); |
9232 | ||
9233 | return ret; | |
9234 | } | |
9235 | ||
9236 | /* One (or perhaps two) breakpoints used for software single stepping. */ | |
9237 | ||
9238 | static void *single_step_breakpoints[2]; | |
a6d9a66e | 9239 | static struct gdbarch *single_step_gdbarch[2]; |
8181d85f DJ |
9240 | |
9241 | /* Create and insert a breakpoint for software single step. */ | |
9242 | ||
9243 | void | |
6c95b8df PA |
9244 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
9245 | struct address_space *aspace, CORE_ADDR next_pc) | |
8181d85f DJ |
9246 | { |
9247 | void **bpt_p; | |
9248 | ||
9249 | if (single_step_breakpoints[0] == NULL) | |
a6d9a66e UW |
9250 | { |
9251 | bpt_p = &single_step_breakpoints[0]; | |
9252 | single_step_gdbarch[0] = gdbarch; | |
9253 | } | |
8181d85f DJ |
9254 | else |
9255 | { | |
9256 | gdb_assert (single_step_breakpoints[1] == NULL); | |
9257 | bpt_p = &single_step_breakpoints[1]; | |
a6d9a66e | 9258 | single_step_gdbarch[1] = gdbarch; |
8181d85f DJ |
9259 | } |
9260 | ||
9261 | /* NOTE drow/2006-04-11: A future improvement to this function would be | |
9262 | to only create the breakpoints once, and actually put them on the | |
9263 | breakpoint chain. That would let us use set_raw_breakpoint. We could | |
9264 | adjust the addresses each time they were needed. Doing this requires | |
9265 | corresponding changes elsewhere where single step breakpoints are | |
9266 | handled, however. So, for now, we use this. */ | |
9267 | ||
6c95b8df | 9268 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc); |
8181d85f | 9269 | if (*bpt_p == NULL) |
5af949e3 UW |
9270 | error (_("Could not insert single-step breakpoint at %s"), |
9271 | paddress (gdbarch, next_pc)); | |
8181d85f DJ |
9272 | } |
9273 | ||
9274 | /* Remove and delete any breakpoints used for software single step. */ | |
9275 | ||
9276 | void | |
9277 | remove_single_step_breakpoints (void) | |
9278 | { | |
9279 | gdb_assert (single_step_breakpoints[0] != NULL); | |
9280 | ||
9281 | /* See insert_single_step_breakpoint for more about this deprecated | |
9282 | call. */ | |
a6d9a66e UW |
9283 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
9284 | single_step_breakpoints[0]); | |
9285 | single_step_gdbarch[0] = NULL; | |
8181d85f DJ |
9286 | single_step_breakpoints[0] = NULL; |
9287 | ||
9288 | if (single_step_breakpoints[1] != NULL) | |
9289 | { | |
a6d9a66e UW |
9290 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
9291 | single_step_breakpoints[1]); | |
9292 | single_step_gdbarch[1] = NULL; | |
8181d85f DJ |
9293 | single_step_breakpoints[1] = NULL; |
9294 | } | |
9295 | } | |
9296 | ||
1aafd4da UW |
9297 | /* Check whether a software single-step breakpoint is inserted at PC. */ |
9298 | ||
9299 | static int | |
6c95b8df | 9300 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
1aafd4da UW |
9301 | { |
9302 | int i; | |
9303 | ||
9304 | for (i = 0; i < 2; i++) | |
9305 | { | |
9306 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
6c95b8df PA |
9307 | if (bp_tgt |
9308 | && breakpoint_address_match (bp_tgt->placed_address_space, | |
9309 | bp_tgt->placed_address, | |
9310 | aspace, pc)) | |
1aafd4da UW |
9311 | return 1; |
9312 | } | |
9313 | ||
9314 | return 0; | |
9315 | } | |
9316 | ||
a96d9b2e SDJ |
9317 | /* Returns 0 if 'bp' is NOT a syscall catchpoint, |
9318 | non-zero otherwise. */ | |
9319 | static int | |
9320 | is_syscall_catchpoint_enabled (struct breakpoint *bp) | |
9321 | { | |
9322 | if (syscall_catchpoint_p (bp) | |
9323 | && bp->enable_state != bp_disabled | |
9324 | && bp->enable_state != bp_call_disabled) | |
9325 | return 1; | |
9326 | else | |
9327 | return 0; | |
9328 | } | |
9329 | ||
9330 | int | |
9331 | catch_syscall_enabled (void) | |
9332 | { | |
9333 | struct inferior *inf = current_inferior (); | |
9334 | ||
9335 | return inf->total_syscalls_count != 0; | |
9336 | } | |
9337 | ||
9338 | int | |
9339 | catching_syscall_number (int syscall_number) | |
9340 | { | |
9341 | struct breakpoint *bp; | |
9342 | ||
9343 | ALL_BREAKPOINTS (bp) | |
9344 | if (is_syscall_catchpoint_enabled (bp)) | |
9345 | { | |
9346 | if (bp->syscalls_to_be_caught) | |
9347 | { | |
9348 | int i, iter; | |
9349 | for (i = 0; | |
9350 | VEC_iterate (int, bp->syscalls_to_be_caught, i, iter); | |
9351 | i++) | |
9352 | if (syscall_number == iter) | |
9353 | return 1; | |
9354 | } | |
9355 | else | |
9356 | return 1; | |
9357 | } | |
9358 | ||
9359 | return 0; | |
9360 | } | |
9361 | ||
9362 | /* Complete syscall names. Used by "catch syscall". */ | |
9363 | static char ** | |
9364 | catch_syscall_completer (struct cmd_list_element *cmd, | |
9365 | char *text, char *word) | |
9366 | { | |
9367 | const char **list = get_syscall_names (); | |
9368 | return (list == NULL) ? NULL : complete_on_enum (list, text, word); | |
9369 | } | |
9370 | ||
1042e4c0 SS |
9371 | /* Tracepoint-specific operations. */ |
9372 | ||
9373 | /* Set tracepoint count to NUM. */ | |
9374 | static void | |
9375 | set_tracepoint_count (int num) | |
9376 | { | |
9377 | tracepoint_count = num; | |
4fa62494 | 9378 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
9379 | } |
9380 | ||
9381 | void | |
9382 | trace_command (char *arg, int from_tty) | |
9383 | { | |
a6d9a66e UW |
9384 | break_command_really (get_current_arch (), |
9385 | arg, | |
1042e4c0 SS |
9386 | NULL, 0, 1 /* parse arg */, |
9387 | 0 /* tempflag */, 0 /* hardwareflag */, | |
9388 | 1 /* traceflag */, | |
9389 | 0 /* Ignore count */, | |
9390 | pending_break_support, | |
9391 | NULL, | |
9392 | from_tty, | |
9393 | 1 /* enabled */); | |
9394 | set_tracepoint_count (breakpoint_count); | |
9395 | } | |
9396 | ||
9397 | /* Print information on tracepoint number TPNUM_EXP, or all if | |
9398 | omitted. */ | |
9399 | ||
9400 | static void | |
9401 | tracepoints_info (char *tpnum_exp, int from_tty) | |
9402 | { | |
9403 | struct breakpoint *b; | |
9404 | int tps_to_list = 0; | |
9405 | ||
9406 | /* In the no-arguments case, say "No tracepoints" if none found. */ | |
9407 | if (tpnum_exp == 0) | |
9408 | { | |
9409 | ALL_TRACEPOINTS (b) | |
9410 | { | |
9411 | if (b->number >= 0) | |
9412 | { | |
9413 | tps_to_list = 1; | |
9414 | break; | |
9415 | } | |
9416 | } | |
9417 | if (!tps_to_list) | |
9418 | { | |
9419 | ui_out_message (uiout, 0, "No tracepoints.\n"); | |
9420 | return; | |
9421 | } | |
9422 | } | |
9423 | ||
9424 | /* Otherwise be the same as "info break". */ | |
9425 | breakpoints_info (tpnum_exp, from_tty); | |
9426 | } | |
9427 | ||
9428 | /* The 'enable trace' command enables tracepoints. | |
9429 | Not supported by all targets. */ | |
9430 | static void | |
9431 | enable_trace_command (char *args, int from_tty) | |
9432 | { | |
9433 | enable_command (args, from_tty); | |
9434 | } | |
9435 | ||
9436 | /* The 'disable trace' command disables tracepoints. | |
9437 | Not supported by all targets. */ | |
9438 | static void | |
9439 | disable_trace_command (char *args, int from_tty) | |
9440 | { | |
9441 | disable_command (args, from_tty); | |
9442 | } | |
9443 | ||
9444 | /* Remove a tracepoint (or all if no argument) */ | |
9445 | static void | |
9446 | delete_trace_command (char *arg, int from_tty) | |
9447 | { | |
9448 | struct breakpoint *b, *temp; | |
9449 | ||
9450 | dont_repeat (); | |
9451 | ||
9452 | if (arg == 0) | |
9453 | { | |
9454 | int breaks_to_delete = 0; | |
9455 | ||
9456 | /* Delete all breakpoints if no argument. | |
9457 | Do not delete internal or call-dummy breakpoints, these | |
9458 | have to be deleted with an explicit breakpoint number argument. */ | |
9459 | ALL_TRACEPOINTS (b) | |
9460 | { | |
9461 | if (b->number >= 0) | |
9462 | { | |
9463 | breaks_to_delete = 1; | |
9464 | break; | |
9465 | } | |
9466 | } | |
9467 | ||
9468 | /* Ask user only if there are some breakpoints to delete. */ | |
9469 | if (!from_tty | |
9470 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
9471 | { | |
9472 | ALL_BREAKPOINTS_SAFE (b, temp) | |
9473 | { | |
059fb39f PM |
9474 | if (b->type == bp_tracepoint |
9475 | && b->number >= 0) | |
1042e4c0 SS |
9476 | delete_breakpoint (b); |
9477 | } | |
9478 | } | |
9479 | } | |
9480 | else | |
9481 | map_breakpoint_numbers (arg, delete_breakpoint); | |
9482 | } | |
9483 | ||
9484 | /* Set passcount for tracepoint. | |
9485 | ||
9486 | First command argument is passcount, second is tracepoint number. | |
9487 | If tracepoint number omitted, apply to most recently defined. | |
9488 | Also accepts special argument "all". */ | |
9489 | ||
9490 | static void | |
9491 | trace_pass_command (char *args, int from_tty) | |
9492 | { | |
9493 | struct breakpoint *t1 = (struct breakpoint *) -1, *t2; | |
9494 | unsigned int count; | |
9495 | int all = 0; | |
9496 | ||
9497 | if (args == 0 || *args == 0) | |
9498 | error (_("passcount command requires an argument (count + optional TP num)")); | |
9499 | ||
9500 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ | |
9501 | ||
9502 | while (*args && isspace ((int) *args)) | |
9503 | args++; | |
9504 | ||
9505 | if (*args && strncasecmp (args, "all", 3) == 0) | |
9506 | { | |
9507 | args += 3; /* Skip special argument "all". */ | |
9508 | all = 1; | |
9509 | if (*args) | |
9510 | error (_("Junk at end of arguments.")); | |
9511 | } | |
9512 | else | |
9513 | t1 = get_tracepoint_by_number (&args, 1, 1); | |
9514 | ||
9515 | do | |
9516 | { | |
9517 | if (t1) | |
9518 | { | |
9519 | ALL_TRACEPOINTS (t2) | |
9520 | if (t1 == (struct breakpoint *) -1 || t1 == t2) | |
9521 | { | |
9522 | t2->pass_count = count; | |
9523 | observer_notify_tracepoint_modified (t2->number); | |
9524 | if (from_tty) | |
9525 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
9526 | t2->number, count); | |
9527 | } | |
9528 | if (! all && *args) | |
9529 | t1 = get_tracepoint_by_number (&args, 1, 0); | |
9530 | } | |
9531 | } | |
9532 | while (*args); | |
9533 | } | |
9534 | ||
9535 | struct breakpoint * | |
9536 | get_tracepoint (int num) | |
9537 | { | |
9538 | struct breakpoint *t; | |
9539 | ||
9540 | ALL_TRACEPOINTS (t) | |
9541 | if (t->number == num) | |
9542 | return t; | |
9543 | ||
9544 | return NULL; | |
9545 | } | |
9546 | ||
9547 | /* Utility: parse a tracepoint number and look it up in the list. | |
9548 | If MULTI_P is true, there might be a range of tracepoints in ARG. | |
9549 | if OPTIONAL_P is true, then if the argument is missing, the most | |
9550 | recent tracepoint (tracepoint_count) is returned. */ | |
9551 | struct breakpoint * | |
9552 | get_tracepoint_by_number (char **arg, int multi_p, int optional_p) | |
9553 | { | |
9554 | extern int tracepoint_count; | |
9555 | struct breakpoint *t; | |
9556 | int tpnum; | |
9557 | char *instring = arg == NULL ? NULL : *arg; | |
9558 | ||
9559 | if (arg == NULL || *arg == NULL || ! **arg) | |
9560 | { | |
9561 | if (optional_p) | |
9562 | tpnum = tracepoint_count; | |
9563 | else | |
9564 | error_no_arg (_("tracepoint number")); | |
9565 | } | |
9566 | else | |
9567 | tpnum = multi_p ? get_number_or_range (arg) : get_number (arg); | |
9568 | ||
9569 | if (tpnum <= 0) | |
9570 | { | |
9571 | if (instring && *instring) | |
9572 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
9573 | instring); | |
9574 | else | |
9575 | printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n")); | |
9576 | return NULL; | |
9577 | } | |
9578 | ||
9579 | ALL_TRACEPOINTS (t) | |
9580 | if (t->number == tpnum) | |
9581 | { | |
9582 | return t; | |
9583 | } | |
9584 | ||
9585 | /* FIXME: if we are in the middle of a range we don't want to give | |
9586 | a message. The current interface to get_number_or_range doesn't | |
9587 | allow us to discover this. */ | |
9588 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); | |
9589 | return NULL; | |
9590 | } | |
9591 | ||
9592 | /* save-tracepoints command */ | |
9593 | static void | |
9594 | tracepoint_save_command (char *args, int from_tty) | |
9595 | { | |
9596 | struct breakpoint *tp; | |
9597 | int any_tp = 0; | |
9598 | struct action_line *line; | |
9599 | FILE *fp; | |
9600 | char *i1 = " ", *i2 = " "; | |
9601 | char *indent, *actionline, *pathname; | |
9602 | char tmp[40]; | |
9603 | struct cleanup *cleanup; | |
9604 | ||
9605 | if (args == 0 || *args == 0) | |
9606 | error (_("Argument required (file name in which to save tracepoints)")); | |
9607 | ||
9608 | /* See if we have anything to save. */ | |
9609 | ALL_TRACEPOINTS (tp) | |
9610 | { | |
9611 | any_tp = 1; | |
9612 | break; | |
9613 | } | |
9614 | if (!any_tp) | |
9615 | { | |
9616 | warning (_("save-tracepoints: no tracepoints to save.")); | |
9617 | return; | |
9618 | } | |
9619 | ||
9620 | pathname = tilde_expand (args); | |
9621 | cleanup = make_cleanup (xfree, pathname); | |
059fb39f PM |
9622 | fp = fopen (pathname, "w"); |
9623 | if (!fp) | |
1042e4c0 SS |
9624 | error (_("Unable to open file '%s' for saving tracepoints (%s)"), |
9625 | args, safe_strerror (errno)); | |
9626 | make_cleanup_fclose (fp); | |
9627 | ||
9628 | ALL_TRACEPOINTS (tp) | |
9629 | { | |
9630 | if (tp->addr_string) | |
9631 | fprintf (fp, "trace %s\n", tp->addr_string); | |
9632 | else | |
9633 | { | |
9634 | sprintf_vma (tmp, tp->loc->address); | |
9635 | fprintf (fp, "trace *0x%s\n", tmp); | |
9636 | } | |
9637 | ||
9638 | if (tp->pass_count) | |
9639 | fprintf (fp, " passcount %d\n", tp->pass_count); | |
9640 | ||
9641 | if (tp->actions) | |
9642 | { | |
9643 | fprintf (fp, " actions\n"); | |
9644 | indent = i1; | |
9645 | for (line = tp->actions; line; line = line->next) | |
9646 | { | |
9647 | struct cmd_list_element *cmd; | |
9648 | ||
9649 | QUIT; /* allow user to bail out with ^C */ | |
9650 | actionline = line->action; | |
9651 | while (isspace ((int) *actionline)) | |
9652 | actionline++; | |
9653 | ||
9654 | fprintf (fp, "%s%s\n", indent, actionline); | |
9655 | if (*actionline != '#') /* skip for comment lines */ | |
9656 | { | |
9657 | cmd = lookup_cmd (&actionline, cmdlist, "", -1, 1); | |
9658 | if (cmd == 0) | |
9659 | error (_("Bad action list item: %s"), actionline); | |
9660 | if (cmd_cfunc_eq (cmd, while_stepping_pseudocommand)) | |
9661 | indent = i2; | |
9662 | else if (cmd_cfunc_eq (cmd, end_actions_pseudocommand)) | |
9663 | indent = i1; | |
9664 | } | |
9665 | } | |
9666 | } | |
9667 | } | |
9668 | do_cleanups (cleanup); | |
9669 | if (from_tty) | |
9670 | printf_filtered (_("Tracepoints saved to file '%s'.\n"), args); | |
9671 | return; | |
9672 | } | |
9673 | ||
9674 | /* Create a vector of all tracepoints. */ | |
9675 | ||
9676 | VEC(breakpoint_p) * | |
9677 | all_tracepoints () | |
9678 | { | |
9679 | VEC(breakpoint_p) *tp_vec = 0; | |
9680 | struct breakpoint *tp; | |
9681 | ||
9682 | ALL_TRACEPOINTS (tp) | |
9683 | { | |
9684 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
9685 | } | |
9686 | ||
9687 | return tp_vec; | |
9688 | } | |
9689 | ||
c906108c | 9690 | \f |
31e2b00f AS |
9691 | /* This help string is used for the break, hbreak, tbreak and thbreak commands. |
9692 | It is defined as a macro to prevent duplication. | |
9693 | COMMAND should be a string constant containing the name of the command. */ | |
9694 | #define BREAK_ARGS_HELP(command) \ | |
9695 | command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\ | |
9696 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ | |
9697 | If a line number is specified, break at start of code for that line.\n\ | |
9698 | If a function is specified, break at start of code for that function.\n\ | |
9699 | If an address is specified, break at that exact address.\n\ | |
9700 | With no LOCATION, uses current execution address of selected stack frame.\n\ | |
9701 | This is useful for breaking on return to a stack frame.\n\ | |
9702 | \n\ | |
9703 | THREADNUM is the number from \"info threads\".\n\ | |
9704 | CONDITION is a boolean expression.\n\ | |
9705 | \n\ | |
9706 | Multiple breakpoints at one place are permitted, and useful if conditional.\n\ | |
9707 | \n\ | |
9708 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
9709 | ||
44feb3ce TT |
9710 | /* List of subcommands for "catch". */ |
9711 | static struct cmd_list_element *catch_cmdlist; | |
9712 | ||
9713 | /* List of subcommands for "tcatch". */ | |
9714 | static struct cmd_list_element *tcatch_cmdlist; | |
9715 | ||
9716 | /* Like add_cmd, but add the command to both the "catch" and "tcatch" | |
9717 | lists, and pass some additional user data to the command function. */ | |
9718 | static void | |
9719 | add_catch_command (char *name, char *docstring, | |
9720 | void (*sfunc) (char *args, int from_tty, | |
9721 | struct cmd_list_element *command), | |
a96d9b2e SDJ |
9722 | char **(*completer) (struct cmd_list_element *cmd, |
9723 | char *text, char *word), | |
44feb3ce TT |
9724 | void *user_data_catch, |
9725 | void *user_data_tcatch) | |
9726 | { | |
9727 | struct cmd_list_element *command; | |
9728 | ||
9729 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
9730 | &catch_cmdlist); | |
9731 | set_cmd_sfunc (command, sfunc); | |
9732 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 9733 | set_cmd_completer (command, completer); |
44feb3ce TT |
9734 | |
9735 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
9736 | &tcatch_cmdlist); | |
9737 | set_cmd_sfunc (command, sfunc); | |
9738 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 9739 | set_cmd_completer (command, completer); |
44feb3ce TT |
9740 | } |
9741 | ||
6c95b8df PA |
9742 | static void |
9743 | clear_syscall_counts (int pid) | |
9744 | { | |
9745 | struct inferior *inf = find_inferior_pid (pid); | |
9746 | ||
9747 | inf->total_syscalls_count = 0; | |
9748 | inf->any_syscall_count = 0; | |
9749 | VEC_free (int, inf->syscalls_counts); | |
9750 | } | |
9751 | ||
c906108c | 9752 | void |
fba45db2 | 9753 | _initialize_breakpoint (void) |
c906108c | 9754 | { |
fa8d40ab JJ |
9755 | static struct cmd_list_element *breakpoint_set_cmdlist; |
9756 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
c906108c SS |
9757 | struct cmd_list_element *c; |
9758 | ||
84acb35a | 9759 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
6c95b8df | 9760 | observer_attach_inferior_exit (clear_syscall_counts); |
84acb35a | 9761 | |
c906108c SS |
9762 | breakpoint_chain = 0; |
9763 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
9764 | before a breakpoint is set. */ | |
9765 | breakpoint_count = 0; | |
9766 | ||
1042e4c0 SS |
9767 | tracepoint_count = 0; |
9768 | ||
1bedd215 AC |
9769 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
9770 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
9771 | Usage is `ignore N COUNT'.")); | |
c906108c | 9772 | if (xdb_commands) |
c5aa993b | 9773 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 9774 | |
1bedd215 AC |
9775 | add_com ("commands", class_breakpoint, commands_command, _("\ |
9776 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
9777 | Give breakpoint number as argument after \"commands\".\n\ |
9778 | With no argument, the targeted breakpoint is the last one set.\n\ | |
9779 | The commands themselves follow starting on the next line.\n\ | |
9780 | Type a line containing \"end\" to indicate the end of them.\n\ | |
9781 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 9782 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 9783 | |
1bedd215 AC |
9784 | add_com ("condition", class_breakpoint, condition_command, _("\ |
9785 | Specify breakpoint number N to break only if COND is true.\n\ | |
c906108c | 9786 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 9787 | expression to be evaluated whenever breakpoint N is reached.")); |
c906108c | 9788 | |
1bedd215 | 9789 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 9790 | Set a temporary breakpoint.\n\ |
c906108c SS |
9791 | Like \"break\" except the breakpoint is only temporary,\n\ |
9792 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
9793 | by using \"enable delete\" on the breakpoint number.\n\ |
9794 | \n" | |
9795 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 9796 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 9797 | |
1bedd215 | 9798 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
31e2b00f | 9799 | Set a hardware assisted breakpoint.\n\ |
c906108c | 9800 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
9801 | some target hardware may not have this support.\n\ |
9802 | \n" | |
9803 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 9804 | set_cmd_completer (c, location_completer); |
c906108c | 9805 | |
1bedd215 | 9806 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 9807 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 9808 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
9809 | so it will be deleted when hit.\n\ |
9810 | \n" | |
9811 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 9812 | set_cmd_completer (c, location_completer); |
c906108c | 9813 | |
1bedd215 AC |
9814 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
9815 | Enable some breakpoints.\n\ | |
c906108c SS |
9816 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
9817 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
9818 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 9819 | With a subcommand you can enable temporarily."), |
c906108c SS |
9820 | &enablelist, "enable ", 1, &cmdlist); |
9821 | if (xdb_commands) | |
1bedd215 AC |
9822 | add_com ("ab", class_breakpoint, enable_command, _("\ |
9823 | Enable some breakpoints.\n\ | |
c906108c SS |
9824 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
9825 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
9826 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 9827 | With a subcommand you can enable temporarily.")); |
c906108c SS |
9828 | |
9829 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
9830 | ||
1bedd215 AC |
9831 | add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
9832 | Enable some breakpoints.\n\ | |
c906108c SS |
9833 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
9834 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 9835 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 9836 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 9837 | |
1a966eab AC |
9838 | add_cmd ("once", no_class, enable_once_command, _("\ |
9839 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
9840 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
9841 | &enablebreaklist); |
9842 | ||
1a966eab AC |
9843 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
9844 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
9845 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
9846 | &enablebreaklist); |
9847 | ||
1a966eab AC |
9848 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
9849 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
9850 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
9851 | &enablelist); |
9852 | ||
1a966eab AC |
9853 | add_cmd ("once", no_class, enable_once_command, _("\ |
9854 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
9855 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
9856 | &enablelist); |
9857 | ||
1bedd215 AC |
9858 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
9859 | Disable some breakpoints.\n\ | |
c906108c SS |
9860 | Arguments are breakpoint numbers with spaces in between.\n\ |
9861 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 9862 | A disabled breakpoint is not forgotten, but has no effect until reenabled."), |
c906108c SS |
9863 | &disablelist, "disable ", 1, &cmdlist); |
9864 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
9865 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
9866 | if (xdb_commands) | |
1bedd215 AC |
9867 | add_com ("sb", class_breakpoint, disable_command, _("\ |
9868 | Disable some breakpoints.\n\ | |
c906108c SS |
9869 | Arguments are breakpoint numbers with spaces in between.\n\ |
9870 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 9871 | A disabled breakpoint is not forgotten, but has no effect until reenabled.")); |
c906108c | 9872 | |
1a966eab AC |
9873 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
9874 | Disable some breakpoints.\n\ | |
c906108c SS |
9875 | Arguments are breakpoint numbers with spaces in between.\n\ |
9876 | To disable all breakpoints, give no argument.\n\ | |
9877 | A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\ | |
1a966eab | 9878 | This command may be abbreviated \"disable\"."), |
c906108c SS |
9879 | &disablelist); |
9880 | ||
1bedd215 AC |
9881 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
9882 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
9883 | Arguments are breakpoint numbers with spaces in between.\n\ |
9884 | To delete all breakpoints, give no argument.\n\ | |
9885 | \n\ | |
9886 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 9887 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
9888 | &deletelist, "delete ", 1, &cmdlist); |
9889 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 9890 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 9891 | if (xdb_commands) |
1bedd215 AC |
9892 | add_com ("db", class_breakpoint, delete_command, _("\ |
9893 | Delete some breakpoints.\n\ | |
c906108c | 9894 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 9895 | To delete all breakpoints, give no argument.\n")); |
c906108c | 9896 | |
1a966eab AC |
9897 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
9898 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
9899 | Arguments are breakpoint numbers with spaces in between.\n\ |
9900 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 9901 | This command may be abbreviated \"delete\"."), |
c906108c SS |
9902 | &deletelist); |
9903 | ||
1bedd215 AC |
9904 | add_com ("clear", class_breakpoint, clear_command, _("\ |
9905 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
9906 | Argument may be line number, function name, or \"*\" and an address.\n\ |
9907 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
9908 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
9909 | If an address is specified, breakpoints at that address are cleared.\n\ |
9910 | \n\ | |
9911 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
9912 | is executing in.\n\ |
9913 | \n\ | |
1bedd215 | 9914 | See also the \"delete\" command which clears breakpoints by number.")); |
c906108c | 9915 | |
1bedd215 | 9916 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
9917 | Set breakpoint at specified line or function.\n" |
9918 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 9919 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 9920 | |
c906108c SS |
9921 | add_com_alias ("b", "break", class_run, 1); |
9922 | add_com_alias ("br", "break", class_run, 1); | |
9923 | add_com_alias ("bre", "break", class_run, 1); | |
9924 | add_com_alias ("brea", "break", class_run, 1); | |
9925 | ||
7681d515 PM |
9926 | if (xdb_commands) |
9927 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
9928 | |
9929 | if (dbx_commands) | |
9930 | { | |
1bedd215 AC |
9931 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
9932 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
9933 | &stoplist, "stop ", 1, &cmdlist); |
9934 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 9935 | _("Break in function or address."), &stoplist); |
c5aa993b | 9936 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 9937 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
9938 | add_com ("status", class_info, breakpoints_info, _("\ |
9939 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
9940 | The \"Type\" column indicates one of:\n\ |
9941 | \tbreakpoint - normal breakpoint\n\ | |
9942 | \twatchpoint - watchpoint\n\ | |
9943 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
9944 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
9945 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
9946 | address and file/line number respectively.\n\ |
9947 | \n\ | |
9948 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
9949 | are set to the address of the last breakpoint listed unless the command\n\ |
9950 | is prefixed with \"server \".\n\n\ | |
c906108c | 9951 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 9952 | breakpoint set.")); |
c906108c SS |
9953 | } |
9954 | ||
1bedd215 AC |
9955 | add_info ("breakpoints", breakpoints_info, _("\ |
9956 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
9957 | The \"Type\" column indicates one of:\n\ |
9958 | \tbreakpoint - normal breakpoint\n\ | |
9959 | \twatchpoint - watchpoint\n\ | |
9960 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
9961 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
9962 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
9963 | address and file/line number respectively.\n\ |
9964 | \n\ | |
9965 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
9966 | are set to the address of the last breakpoint listed unless the command\n\ |
9967 | is prefixed with \"server \".\n\n\ | |
c906108c | 9968 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 9969 | breakpoint set.")); |
c906108c SS |
9970 | |
9971 | if (xdb_commands) | |
1bedd215 AC |
9972 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
9973 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
9974 | The \"Type\" column indicates one of:\n\ |
9975 | \tbreakpoint - normal breakpoint\n\ | |
9976 | \twatchpoint - watchpoint\n\ | |
9977 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
9978 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
9979 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
9980 | address and file/line number respectively.\n\ |
9981 | \n\ | |
9982 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
9983 | are set to the address of the last breakpoint listed unless the command\n\ |
9984 | is prefixed with \"server \".\n\n\ | |
c906108c | 9985 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 9986 | breakpoint set.")); |
c906108c | 9987 | |
1a966eab AC |
9988 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
9989 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
9990 | The \"Type\" column indicates one of:\n\ |
9991 | \tbreakpoint - normal breakpoint\n\ | |
9992 | \twatchpoint - watchpoint\n\ | |
9993 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
9994 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
9995 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
9996 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
9997 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
9998 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
9999 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
10000 | address and file/line number respectively.\n\ |
10001 | \n\ | |
10002 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
10003 | are set to the address of the last breakpoint listed unless the command\n\ |
10004 | is prefixed with \"server \".\n\n\ | |
c906108c | 10005 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 10006 | breakpoint set."), |
c906108c SS |
10007 | &maintenanceinfolist); |
10008 | ||
44feb3ce TT |
10009 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
10010 | Set catchpoints to catch events."), | |
10011 | &catch_cmdlist, "catch ", | |
10012 | 0/*allow-unknown*/, &cmdlist); | |
10013 | ||
10014 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
10015 | Set temporary catchpoints to catch events."), | |
10016 | &tcatch_cmdlist, "tcatch ", | |
10017 | 0/*allow-unknown*/, &cmdlist); | |
10018 | ||
10019 | /* Add catch and tcatch sub-commands. */ | |
10020 | add_catch_command ("catch", _("\ | |
10021 | Catch an exception, when caught.\n\ | |
10022 | With an argument, catch only exceptions with the given name."), | |
10023 | catch_catch_command, | |
a96d9b2e | 10024 | NULL, |
44feb3ce TT |
10025 | CATCH_PERMANENT, |
10026 | CATCH_TEMPORARY); | |
10027 | add_catch_command ("throw", _("\ | |
10028 | Catch an exception, when thrown.\n\ | |
10029 | With an argument, catch only exceptions with the given name."), | |
10030 | catch_throw_command, | |
a96d9b2e | 10031 | NULL, |
44feb3ce TT |
10032 | CATCH_PERMANENT, |
10033 | CATCH_TEMPORARY); | |
10034 | add_catch_command ("fork", _("Catch calls to fork."), | |
10035 | catch_fork_command_1, | |
a96d9b2e | 10036 | NULL, |
44feb3ce TT |
10037 | (void *) (uintptr_t) catch_fork_permanent, |
10038 | (void *) (uintptr_t) catch_fork_temporary); | |
10039 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
10040 | catch_fork_command_1, | |
a96d9b2e | 10041 | NULL, |
44feb3ce TT |
10042 | (void *) (uintptr_t) catch_vfork_permanent, |
10043 | (void *) (uintptr_t) catch_vfork_temporary); | |
10044 | add_catch_command ("exec", _("Catch calls to exec."), | |
10045 | catch_exec_command_1, | |
a96d9b2e SDJ |
10046 | NULL, |
10047 | CATCH_PERMANENT, | |
10048 | CATCH_TEMPORARY); | |
10049 | add_catch_command ("syscall", _("\ | |
10050 | Catch system calls by their names and/or numbers.\n\ | |
10051 | Arguments say which system calls to catch. If no arguments\n\ | |
10052 | are given, every system call will be caught.\n\ | |
10053 | Arguments, if given, should be one or more system call names\n\ | |
10054 | (if your system supports that), or system call numbers."), | |
10055 | catch_syscall_command_1, | |
10056 | catch_syscall_completer, | |
44feb3ce TT |
10057 | CATCH_PERMANENT, |
10058 | CATCH_TEMPORARY); | |
44feb3ce TT |
10059 | add_catch_command ("exception", _("\ |
10060 | Catch Ada exceptions, when raised.\n\ | |
10061 | With an argument, catch only exceptions with the given name."), | |
10062 | catch_ada_exception_command, | |
a96d9b2e | 10063 | NULL, |
44feb3ce TT |
10064 | CATCH_PERMANENT, |
10065 | CATCH_TEMPORARY); | |
10066 | add_catch_command ("assert", _("\ | |
10067 | Catch failed Ada assertions, when raised.\n\ | |
10068 | With an argument, catch only exceptions with the given name."), | |
10069 | catch_assert_command, | |
a96d9b2e | 10070 | NULL, |
44feb3ce TT |
10071 | CATCH_PERMANENT, |
10072 | CATCH_TEMPORARY); | |
c5aa993b | 10073 | |
1bedd215 AC |
10074 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
10075 | Set a watchpoint for an expression.\n\ | |
c906108c | 10076 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 10077 | an expression changes.")); |
65d12d83 | 10078 | set_cmd_completer (c, expression_completer); |
c906108c | 10079 | |
1bedd215 AC |
10080 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
10081 | Set a read watchpoint for an expression.\n\ | |
c906108c | 10082 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 10083 | an expression is read.")); |
65d12d83 | 10084 | set_cmd_completer (c, expression_completer); |
c906108c | 10085 | |
1bedd215 AC |
10086 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
10087 | Set a watchpoint for an expression.\n\ | |
c906108c | 10088 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 10089 | an expression is either read or written.")); |
65d12d83 | 10090 | set_cmd_completer (c, expression_completer); |
c906108c SS |
10091 | |
10092 | add_info ("watchpoints", breakpoints_info, | |
1bedd215 | 10093 | _("Synonym for ``info breakpoints''.")); |
c906108c SS |
10094 | |
10095 | ||
920d2a44 AC |
10096 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
10097 | respond to changes - contrary to the description. */ | |
85c07804 AC |
10098 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
10099 | &can_use_hw_watchpoints, _("\ | |
10100 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
10101 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
10102 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
10103 | such is available. (However, any hardware watchpoints that were\n\ | |
10104 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
10105 | hardware.)"), |
10106 | NULL, | |
920d2a44 | 10107 | show_can_use_hw_watchpoints, |
85c07804 | 10108 | &setlist, &showlist); |
c906108c SS |
10109 | |
10110 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 10111 | |
1042e4c0 SS |
10112 | /* Tracepoint manipulation commands. */ |
10113 | ||
10114 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
10115 | Set a tracepoint at specified line or function.\n\ | |
10116 | \n" | |
10117 | BREAK_ARGS_HELP ("trace") "\n\ | |
10118 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
10119 | set_cmd_completer (c, location_completer); | |
10120 | ||
10121 | add_com_alias ("tp", "trace", class_alias, 0); | |
10122 | add_com_alias ("tr", "trace", class_alias, 1); | |
10123 | add_com_alias ("tra", "trace", class_alias, 1); | |
10124 | add_com_alias ("trac", "trace", class_alias, 1); | |
10125 | ||
10126 | add_info ("tracepoints", tracepoints_info, _("\ | |
10127 | Status of tracepoints, or tracepoint number NUMBER.\n\ | |
10128 | Convenience variable \"$tpnum\" contains the number of the\n\ | |
10129 | last tracepoint set.")); | |
10130 | ||
10131 | add_info_alias ("tp", "tracepoints", 1); | |
10132 | ||
10133 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
10134 | Delete specified tracepoints.\n\ | |
10135 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
10136 | No argument means delete all tracepoints."), | |
10137 | &deletelist); | |
10138 | ||
10139 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
10140 | Disable specified tracepoints.\n\ | |
10141 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
10142 | No argument means disable all tracepoints."), | |
10143 | &disablelist); | |
10144 | deprecate_cmd (c, "disable"); | |
10145 | ||
10146 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
10147 | Enable specified tracepoints.\n\ | |
10148 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
10149 | No argument means enable all tracepoints."), | |
10150 | &enablelist); | |
10151 | deprecate_cmd (c, "enable"); | |
10152 | ||
10153 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
10154 | Set the passcount for a tracepoint.\n\ | |
10155 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
10156 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
10157 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
10158 | ||
10159 | c = add_com ("save-tracepoints", class_trace, tracepoint_save_command, _("\ | |
10160 | Save current tracepoint definitions as a script.\n\ | |
10161 | Use the 'source' command in another debug session to restore them.")); | |
10162 | set_cmd_completer (c, filename_completer); | |
10163 | ||
1bedd215 | 10164 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
10165 | Breakpoint specific settings\n\ |
10166 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 10167 | pending breakpoint behavior"), |
fa8d40ab JJ |
10168 | &breakpoint_set_cmdlist, "set breakpoint ", |
10169 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 10170 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
10171 | Breakpoint specific settings\n\ |
10172 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 10173 | pending breakpoint behavior"), |
fa8d40ab JJ |
10174 | &breakpoint_show_cmdlist, "show breakpoint ", |
10175 | 0/*allow-unknown*/, &showlist); | |
10176 | ||
7915a72c AC |
10177 | add_setshow_auto_boolean_cmd ("pending", no_class, |
10178 | &pending_break_support, _("\ | |
10179 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
10180 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
10181 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
10182 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
10183 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 10184 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 10185 | NULL, |
920d2a44 | 10186 | show_pending_break_support, |
6e1d7d6c AC |
10187 | &breakpoint_set_cmdlist, |
10188 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
10189 | |
10190 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
10191 | |
10192 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
10193 | &automatic_hardware_breakpoints, _("\ | |
10194 | Set automatic usage of hardware breakpoints."), _("\ | |
10195 | Show automatic usage of hardware breakpoints."), _("\ | |
10196 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
10197 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
10198 | a warning will be emitted for such breakpoints."), | |
10199 | NULL, | |
10200 | show_automatic_hardware_breakpoints, | |
10201 | &breakpoint_set_cmdlist, | |
10202 | &breakpoint_show_cmdlist); | |
74960c60 | 10203 | |
33e5cbd6 PA |
10204 | add_setshow_enum_cmd ("always-inserted", class_support, |
10205 | always_inserted_enums, &always_inserted_mode, _("\ | |
74960c60 VP |
10206 | Set mode for inserting breakpoints."), _("\ |
10207 | Show mode for inserting breakpoints."), _("\ | |
33e5cbd6 PA |
10208 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
10209 | resumed, and removed when execution stops. When this mode is on,\n\ | |
10210 | breakpoints are inserted immediately and removed only when the user\n\ | |
10211 | deletes the breakpoint. When this mode is auto (which is the default),\n\ | |
10212 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ | |
10213 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ | |
10214 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ | |
10215 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), | |
74960c60 VP |
10216 | NULL, |
10217 | &show_always_inserted_mode, | |
10218 | &breakpoint_set_cmdlist, | |
10219 | &breakpoint_show_cmdlist); | |
765dc015 VP |
10220 | |
10221 | automatic_hardware_breakpoints = 1; | |
f3b1572e PA |
10222 | |
10223 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
c906108c | 10224 | } |