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 | |
76897487 KB |
115 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
116 | ||
a6d9a66e UW |
117 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
118 | CORE_ADDR bpaddr, | |
88f7da05 | 119 | enum bptype bptype); |
76897487 | 120 | |
6c95b8df PA |
121 | static void describe_other_breakpoints (struct gdbarch *, |
122 | struct program_space *, CORE_ADDR, | |
5af949e3 | 123 | struct obj_section *, int); |
c906108c | 124 | |
6c95b8df PA |
125 | static int breakpoint_address_match (struct address_space *aspace1, |
126 | CORE_ADDR addr1, | |
127 | struct address_space *aspace2, | |
128 | CORE_ADDR addr2); | |
129 | ||
a14ed312 | 130 | static void breakpoints_info (char *, int); |
c906108c | 131 | |
a14ed312 | 132 | static void breakpoint_1 (int, int); |
c906108c | 133 | |
89f9893c | 134 | static bpstat bpstat_alloc (const struct bp_location *, bpstat); |
c906108c | 135 | |
4efb68b1 | 136 | static int breakpoint_cond_eval (void *); |
c906108c | 137 | |
4efb68b1 | 138 | static void cleanup_executing_breakpoints (void *); |
c906108c | 139 | |
a14ed312 | 140 | static void commands_command (char *, int); |
c906108c | 141 | |
a14ed312 | 142 | static void condition_command (char *, int); |
c906108c | 143 | |
a14ed312 | 144 | static int get_number_trailer (char **, int); |
c906108c | 145 | |
a14ed312 | 146 | void set_breakpoint_count (int); |
c906108c | 147 | |
c5aa993b JM |
148 | typedef enum |
149 | { | |
150 | mark_inserted, | |
151 | mark_uninserted | |
152 | } | |
153 | insertion_state_t; | |
c906108c | 154 | |
0bde7532 | 155 | static int remove_breakpoint (struct bp_location *, insertion_state_t); |
6c95b8df | 156 | static int remove_breakpoint_1 (struct bp_location *, insertion_state_t); |
c906108c | 157 | |
a14ed312 | 158 | static enum print_stop_action print_it_typical (bpstat); |
e514a9d6 JM |
159 | |
160 | static enum print_stop_action print_bp_stop_message (bpstat bs); | |
c906108c | 161 | |
4efb68b1 | 162 | static int watchpoint_check (void *); |
c906108c | 163 | |
a14ed312 | 164 | static void maintenance_info_breakpoints (char *, int); |
c906108c | 165 | |
a14ed312 | 166 | static int hw_breakpoint_used_count (void); |
c906108c | 167 | |
a14ed312 | 168 | static int hw_watchpoint_used_count (enum bptype, int *); |
c906108c | 169 | |
a14ed312 | 170 | static void hbreak_command (char *, int); |
c906108c | 171 | |
a14ed312 | 172 | static void thbreak_command (char *, int); |
c906108c | 173 | |
a14ed312 | 174 | static void watch_command_1 (char *, int, int); |
c906108c | 175 | |
a14ed312 | 176 | static void rwatch_command (char *, int); |
c906108c | 177 | |
a14ed312 | 178 | static void awatch_command (char *, int); |
c906108c | 179 | |
a14ed312 | 180 | static void do_enable_breakpoint (struct breakpoint *, enum bpdisp); |
c906108c | 181 | |
a14ed312 | 182 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 183 | |
a14ed312 | 184 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 185 | |
a14ed312 | 186 | static void stopat_command (char *arg, int from_tty); |
7a292a7a | 187 | |
a14ed312 | 188 | static char *ep_parse_optional_if_clause (char **arg); |
7a292a7a | 189 | |
a14ed312 | 190 | static char *ep_parse_optional_filename (char **arg); |
7a292a7a | 191 | |
d85310f7 MS |
192 | static void catch_exception_command_1 (enum exception_event_kind ex_event, |
193 | char *arg, int tempflag, int from_tty); | |
7a292a7a | 194 | |
a14ed312 | 195 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 196 | |
a14ed312 | 197 | static void ep_skip_leading_whitespace (char **s); |
7a292a7a | 198 | |
6c95b8df PA |
199 | static int single_step_breakpoint_inserted_here_p (struct address_space *, |
200 | CORE_ADDR pc); | |
1aafd4da | 201 | |
fe3f5fa8 VP |
202 | static void free_bp_location (struct bp_location *loc); |
203 | ||
39d61571 | 204 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 205 | |
b60e7edf | 206 | static void update_global_location_list (int); |
a5606eee | 207 | |
b60e7edf | 208 | static void update_global_location_list_nothrow (int); |
74960c60 VP |
209 | |
210 | static int is_hardware_watchpoint (struct breakpoint *bpt); | |
211 | ||
212 | static void insert_breakpoint_locations (void); | |
a5606eee | 213 | |
a96d9b2e SDJ |
214 | static int syscall_catchpoint_p (struct breakpoint *b); |
215 | ||
1042e4c0 SS |
216 | static void tracepoints_info (char *, int); |
217 | ||
218 | static void delete_trace_command (char *, int); | |
219 | ||
220 | static void enable_trace_command (char *, int); | |
221 | ||
222 | static void disable_trace_command (char *, int); | |
223 | ||
224 | static void trace_pass_command (char *, int); | |
225 | ||
3daf8fe5 JG |
226 | static void skip_prologue_sal (struct symtab_and_line *sal); |
227 | ||
228 | ||
f3b1572e PA |
229 | /* Flag indicating that a command has proceeded the inferior past the |
230 | current breakpoint. */ | |
231 | ||
232 | static int breakpoint_proceeded; | |
233 | ||
2cec12e5 AR |
234 | static const char * |
235 | bpdisp_text (enum bpdisp disp) | |
236 | { | |
237 | /* NOTE: the following values are a part of MI protocol and represent | |
238 | values of 'disp' field returned when inferior stops at a breakpoint. */ | |
239 | static char *bpdisps[] = {"del", "dstp", "dis", "keep"}; | |
240 | return bpdisps[(int) disp]; | |
241 | } | |
c906108c | 242 | |
2cec12e5 | 243 | /* Prototypes for exported functions. */ |
c906108c SS |
244 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
245 | if such is available. */ | |
246 | static int can_use_hw_watchpoints; | |
247 | ||
920d2a44 AC |
248 | static void |
249 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
250 | struct cmd_list_element *c, | |
251 | const char *value) | |
252 | { | |
253 | fprintf_filtered (file, _("\ | |
254 | Debugger's willingness to use watchpoint hardware is %s.\n"), | |
255 | value); | |
256 | } | |
257 | ||
fa8d40ab JJ |
258 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
259 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
260 | for unrecognized breakpoint locations. | |
261 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ | |
262 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
263 | static void |
264 | show_pending_break_support (struct ui_file *file, int from_tty, | |
265 | struct cmd_list_element *c, | |
266 | const char *value) | |
267 | { | |
268 | fprintf_filtered (file, _("\ | |
269 | Debugger's behavior regarding pending breakpoints is %s.\n"), | |
270 | value); | |
271 | } | |
fa8d40ab | 272 | |
765dc015 VP |
273 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
274 | set with "break" but falling in read-only memory. | |
275 | If 0, gdb will warn about such breakpoints, but won't automatically | |
276 | use hardware breakpoints. */ | |
277 | static int automatic_hardware_breakpoints; | |
278 | static void | |
279 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
280 | struct cmd_list_element *c, | |
281 | const char *value) | |
282 | { | |
283 | fprintf_filtered (file, _("\ | |
284 | Automatic usage of hardware breakpoints is %s.\n"), | |
285 | value); | |
286 | } | |
287 | ||
33e5cbd6 PA |
288 | /* If on, gdb will keep breakpoints inserted even as inferior is |
289 | stopped, and immediately insert any new breakpoints. If off, gdb | |
290 | will insert breakpoints into inferior only when resuming it, and | |
291 | will remove breakpoints upon stop. If auto, GDB will behave as ON | |
292 | if in non-stop mode, and as OFF if all-stop mode.*/ | |
293 | ||
294 | static const char always_inserted_auto[] = "auto"; | |
295 | static const char always_inserted_on[] = "on"; | |
296 | static const char always_inserted_off[] = "off"; | |
297 | static const char *always_inserted_enums[] = { | |
298 | always_inserted_auto, | |
299 | always_inserted_off, | |
300 | always_inserted_on, | |
301 | NULL | |
302 | }; | |
303 | static const char *always_inserted_mode = always_inserted_auto; | |
304 | static void | |
74960c60 | 305 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 306 | struct cmd_list_element *c, const char *value) |
74960c60 | 307 | { |
33e5cbd6 PA |
308 | if (always_inserted_mode == always_inserted_auto) |
309 | fprintf_filtered (file, _("\ | |
310 | Always inserted breakpoint mode is %s (currently %s).\n"), | |
311 | value, | |
312 | breakpoints_always_inserted_mode () ? "on" : "off"); | |
313 | else | |
314 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), value); | |
74960c60 VP |
315 | } |
316 | ||
33e5cbd6 PA |
317 | int |
318 | breakpoints_always_inserted_mode (void) | |
319 | { | |
320 | return (always_inserted_mode == always_inserted_on | |
321 | || (always_inserted_mode == always_inserted_auto && non_stop)); | |
322 | } | |
765dc015 | 323 | |
a14ed312 | 324 | void _initialize_breakpoint (void); |
c906108c | 325 | |
c906108c SS |
326 | /* Are we executing breakpoint commands? */ |
327 | static int executing_breakpoint_commands; | |
328 | ||
c02f5703 MS |
329 | /* Are overlay event breakpoints enabled? */ |
330 | static int overlay_events_enabled; | |
331 | ||
c906108c SS |
332 | /* Walk the following statement or block through all breakpoints. |
333 | ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current | |
334 | breakpoint. */ | |
335 | ||
5c44784c | 336 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 337 | |
5c44784c JM |
338 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
339 | for (B = breakpoint_chain; \ | |
340 | B ? (TMP=B->next, 1): 0; \ | |
341 | B = TMP) | |
c906108c | 342 | |
876fa593 JK |
343 | /* Similar iterator for the low-level breakpoints. SAFE variant is not |
344 | provided so update_global_location_list must not be called while executing | |
345 | the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 346 | |
876fa593 JK |
347 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
348 | for (BP_TMP = bp_location; \ | |
349 | BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \ | |
350 | BP_TMP++) | |
7cc221ef | 351 | |
1042e4c0 SS |
352 | /* Iterator for tracepoints only. */ |
353 | ||
354 | #define ALL_TRACEPOINTS(B) \ | |
355 | for (B = breakpoint_chain; B; B = B->next) \ | |
356 | if ((B)->type == bp_tracepoint) | |
357 | ||
7cc221ef | 358 | /* Chains of all breakpoints defined. */ |
c906108c SS |
359 | |
360 | struct breakpoint *breakpoint_chain; | |
361 | ||
876fa593 JK |
362 | /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */ |
363 | ||
364 | static struct bp_location **bp_location; | |
365 | ||
366 | /* Number of elements of BP_LOCATION. */ | |
367 | ||
368 | static unsigned bp_location_count; | |
369 | ||
370 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and ADDRESS | |
371 | for the current elements of BP_LOCATION which get a valid result from | |
372 | bp_location_has_shadow. You can use it for roughly limiting the subrange of | |
373 | BP_LOCATION to scan for shadow bytes for an address you need to read. */ | |
374 | ||
375 | static CORE_ADDR bp_location_placed_address_before_address_max; | |
376 | ||
377 | /* Maximum offset plus alignment between | |
378 | bp_target_info.PLACED_ADDRESS + bp_target_info.SHADOW_LEN and ADDRESS for | |
379 | the current elements of BP_LOCATION which get a valid result from | |
380 | bp_location_has_shadow. You can use it for roughly limiting the subrange of | |
381 | BP_LOCATION to scan for shadow bytes for an address you need to read. */ | |
382 | ||
383 | static CORE_ADDR bp_location_shadow_len_after_address_max; | |
7cc221ef | 384 | |
20874c92 | 385 | /* The locations that no longer correspond to any breakpoint, |
876fa593 | 386 | unlinked from bp_location array, but for which a hit |
20874c92 VP |
387 | may still be reported by a target. */ |
388 | VEC(bp_location_p) *moribund_locations = NULL; | |
389 | ||
c906108c SS |
390 | /* Number of last breakpoint made. */ |
391 | ||
392 | int breakpoint_count; | |
393 | ||
1042e4c0 SS |
394 | /* Number of last tracepoint made. */ |
395 | ||
396 | int tracepoint_count; | |
397 | ||
468d015d JJ |
398 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
399 | static int | |
400 | breakpoint_enabled (struct breakpoint *b) | |
401 | { | |
0d381245 | 402 | return (b->enable_state == bp_enabled); |
468d015d JJ |
403 | } |
404 | ||
c906108c SS |
405 | /* Set breakpoint count to NUM. */ |
406 | ||
407 | void | |
fba45db2 | 408 | set_breakpoint_count (int num) |
c906108c SS |
409 | { |
410 | breakpoint_count = num; | |
4fa62494 | 411 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
412 | } |
413 | ||
414 | /* Used in run_command to zero the hit count when a new run starts. */ | |
415 | ||
416 | void | |
fba45db2 | 417 | clear_breakpoint_hit_counts (void) |
c906108c SS |
418 | { |
419 | struct breakpoint *b; | |
420 | ||
421 | ALL_BREAKPOINTS (b) | |
422 | b->hit_count = 0; | |
423 | } | |
424 | ||
425 | /* Default address, symtab and line to put a breakpoint at | |
426 | for "break" command with no arg. | |
427 | if default_breakpoint_valid is zero, the other three are | |
428 | not valid, and "break" with no arg is an error. | |
429 | ||
430 | This set by print_stack_frame, which calls set_default_breakpoint. */ | |
431 | ||
432 | int default_breakpoint_valid; | |
433 | CORE_ADDR default_breakpoint_address; | |
434 | struct symtab *default_breakpoint_symtab; | |
435 | int default_breakpoint_line; | |
6c95b8df PA |
436 | struct program_space *default_breakpoint_pspace; |
437 | ||
c906108c SS |
438 | \f |
439 | /* *PP is a string denoting a breakpoint. Get the number of the breakpoint. | |
440 | Advance *PP after the string and any trailing whitespace. | |
441 | ||
442 | Currently the string can either be a number or "$" followed by the name | |
443 | of a convenience variable. Making it an expression wouldn't work well | |
5c44784c | 444 | for map_breakpoint_numbers (e.g. "4 + 5 + 6"). |
40c03ae8 EZ |
445 | |
446 | If the string is a NULL pointer, that denotes the last breakpoint. | |
5c44784c JM |
447 | |
448 | TRAILER is a character which can be found after the number; most | |
449 | commonly this is `-'. If you don't want a trailer, use \0. */ | |
c906108c | 450 | static int |
fba45db2 | 451 | get_number_trailer (char **pp, int trailer) |
c906108c | 452 | { |
5c44784c | 453 | int retval = 0; /* default */ |
c906108c SS |
454 | char *p = *pp; |
455 | ||
456 | if (p == NULL) | |
457 | /* Empty line means refer to the last breakpoint. */ | |
458 | return breakpoint_count; | |
459 | else if (*p == '$') | |
460 | { | |
461 | /* Make a copy of the name, so we can null-terminate it | |
c5aa993b | 462 | to pass to lookup_internalvar(). */ |
c906108c SS |
463 | char *varname; |
464 | char *start = ++p; | |
4fa62494 | 465 | LONGEST val; |
c906108c SS |
466 | |
467 | while (isalnum (*p) || *p == '_') | |
468 | p++; | |
469 | varname = (char *) alloca (p - start + 1); | |
470 | strncpy (varname, start, p - start); | |
471 | varname[p - start] = '\0'; | |
4fa62494 UW |
472 | if (get_internalvar_integer (lookup_internalvar (varname), &val)) |
473 | retval = (int) val; | |
5c44784c JM |
474 | else |
475 | { | |
a3f17187 | 476 | printf_filtered (_("Convenience variable must have integer value.\n")); |
5c44784c JM |
477 | retval = 0; |
478 | } | |
c906108c SS |
479 | } |
480 | else | |
481 | { | |
482 | if (*p == '-') | |
483 | ++p; | |
484 | while (*p >= '0' && *p <= '9') | |
485 | ++p; | |
486 | if (p == *pp) | |
487 | /* There is no number here. (e.g. "cond a == b"). */ | |
5c44784c JM |
488 | { |
489 | /* Skip non-numeric token */ | |
490 | while (*p && !isspace((int) *p)) | |
491 | ++p; | |
492 | /* Return zero, which caller must interpret as error. */ | |
493 | retval = 0; | |
494 | } | |
495 | else | |
496 | retval = atoi (*pp); | |
497 | } | |
498 | if (!(isspace (*p) || *p == '\0' || *p == trailer)) | |
499 | { | |
500 | /* Trailing junk: return 0 and let caller print error msg. */ | |
501 | while (!(isspace (*p) || *p == '\0' || *p == trailer)) | |
502 | ++p; | |
503 | retval = 0; | |
c906108c | 504 | } |
c906108c SS |
505 | while (isspace (*p)) |
506 | p++; | |
507 | *pp = p; | |
508 | return retval; | |
509 | } | |
5c44784c | 510 | |
11cf8741 | 511 | |
5c44784c JM |
512 | /* Like get_number_trailer, but don't allow a trailer. */ |
513 | int | |
fba45db2 | 514 | get_number (char **pp) |
5c44784c JM |
515 | { |
516 | return get_number_trailer (pp, '\0'); | |
517 | } | |
518 | ||
519 | /* Parse a number or a range. | |
520 | * A number will be of the form handled by get_number. | |
521 | * A range will be of the form <number1> - <number2>, and | |
522 | * will represent all the integers between number1 and number2, | |
523 | * inclusive. | |
524 | * | |
525 | * While processing a range, this fuction is called iteratively; | |
526 | * At each call it will return the next value in the range. | |
527 | * | |
528 | * At the beginning of parsing a range, the char pointer PP will | |
529 | * be advanced past <number1> and left pointing at the '-' token. | |
530 | * Subsequent calls will not advance the pointer until the range | |
531 | * is completed. The call that completes the range will advance | |
532 | * pointer PP past <number2>. | |
533 | */ | |
534 | ||
535 | int | |
fba45db2 | 536 | get_number_or_range (char **pp) |
5c44784c JM |
537 | { |
538 | static int last_retval, end_value; | |
539 | static char *end_ptr; | |
540 | static int in_range = 0; | |
541 | ||
542 | if (**pp != '-') | |
543 | { | |
544 | /* Default case: pp is pointing either to a solo number, | |
545 | or to the first number of a range. */ | |
546 | last_retval = get_number_trailer (pp, '-'); | |
547 | if (**pp == '-') | |
548 | { | |
549 | char **temp; | |
550 | ||
551 | /* This is the start of a range (<number1> - <number2>). | |
552 | Skip the '-', parse and remember the second number, | |
553 | and also remember the end of the final token. */ | |
554 | ||
555 | temp = &end_ptr; | |
556 | end_ptr = *pp + 1; | |
557 | while (isspace ((int) *end_ptr)) | |
558 | end_ptr++; /* skip white space */ | |
559 | end_value = get_number (temp); | |
560 | if (end_value < last_retval) | |
561 | { | |
8a3fe4f8 | 562 | error (_("inverted range")); |
5c44784c JM |
563 | } |
564 | else if (end_value == last_retval) | |
565 | { | |
566 | /* degenerate range (number1 == number2). Advance the | |
567 | token pointer so that the range will be treated as a | |
568 | single number. */ | |
569 | *pp = end_ptr; | |
570 | } | |
571 | else | |
572 | in_range = 1; | |
573 | } | |
574 | } | |
575 | else if (! in_range) | |
8a3fe4f8 | 576 | error (_("negative value")); |
5c44784c JM |
577 | else |
578 | { | |
579 | /* pp points to the '-' that betokens a range. All | |
580 | number-parsing has already been done. Return the next | |
581 | integer value (one greater than the saved previous value). | |
582 | Do not advance the token pointer 'pp' until the end of range | |
583 | is reached. */ | |
584 | ||
585 | if (++last_retval == end_value) | |
586 | { | |
587 | /* End of range reached; advance token pointer. */ | |
588 | *pp = end_ptr; | |
589 | in_range = 0; | |
590 | } | |
591 | } | |
592 | return last_retval; | |
593 | } | |
594 | ||
48cb2d85 VP |
595 | /* Return the breakpoint with the specified number, or NULL |
596 | if the number does not refer to an existing breakpoint. */ | |
597 | ||
598 | struct breakpoint * | |
599 | get_breakpoint (int num) | |
600 | { | |
601 | struct breakpoint *b; | |
602 | ||
603 | ALL_BREAKPOINTS (b) | |
604 | if (b->number == num) | |
605 | return b; | |
606 | ||
607 | return NULL; | |
608 | } | |
5c44784c | 609 | |
c906108c SS |
610 | \f |
611 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ | |
612 | ||
613 | static void | |
fba45db2 | 614 | condition_command (char *arg, int from_tty) |
c906108c | 615 | { |
52f0bd74 | 616 | struct breakpoint *b; |
c906108c | 617 | char *p; |
52f0bd74 | 618 | int bnum; |
c906108c SS |
619 | |
620 | if (arg == 0) | |
e2e0b3e5 | 621 | error_no_arg (_("breakpoint number")); |
c906108c SS |
622 | |
623 | p = arg; | |
624 | bnum = get_number (&p); | |
5c44784c | 625 | if (bnum == 0) |
8a3fe4f8 | 626 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
627 | |
628 | ALL_BREAKPOINTS (b) | |
629 | if (b->number == bnum) | |
2f069f6f JB |
630 | { |
631 | struct bp_location *loc = b->loc; | |
632 | for (; loc; loc = loc->next) | |
633 | { | |
634 | if (loc->cond) | |
635 | { | |
636 | xfree (loc->cond); | |
637 | loc->cond = 0; | |
638 | } | |
639 | } | |
640 | if (b->cond_string != NULL) | |
641 | xfree (b->cond_string); | |
c906108c | 642 | |
2f069f6f JB |
643 | if (*p == 0) |
644 | { | |
645 | b->cond_string = NULL; | |
646 | if (from_tty) | |
647 | printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum); | |
648 | } | |
649 | else | |
650 | { | |
651 | arg = p; | |
652 | /* I don't know if it matters whether this is the string the user | |
653 | typed in or the decompiled expression. */ | |
1b36a34b | 654 | b->cond_string = xstrdup (arg); |
2f069f6f JB |
655 | b->condition_not_parsed = 0; |
656 | for (loc = b->loc; loc; loc = loc->next) | |
657 | { | |
658 | arg = p; | |
659 | loc->cond = | |
660 | parse_exp_1 (&arg, block_for_pc (loc->address), 0); | |
661 | if (*arg) | |
662 | error (_("Junk at end of expression")); | |
663 | } | |
664 | } | |
665 | breakpoints_changed (); | |
383f836e | 666 | observer_notify_breakpoint_modified (b->number); |
2f069f6f JB |
667 | return; |
668 | } | |
c906108c | 669 | |
8a3fe4f8 | 670 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
671 | } |
672 | ||
48cb2d85 VP |
673 | /* Set the command list of B to COMMANDS. */ |
674 | ||
675 | void | |
676 | breakpoint_set_commands (struct breakpoint *b, struct command_line *commands) | |
677 | { | |
678 | free_command_lines (&b->commands); | |
679 | b->commands = commands; | |
680 | breakpoints_changed (); | |
681 | observer_notify_breakpoint_modified (b->number); | |
682 | } | |
683 | ||
c906108c | 684 | static void |
fba45db2 | 685 | commands_command (char *arg, int from_tty) |
c906108c | 686 | { |
52f0bd74 | 687 | struct breakpoint *b; |
c906108c | 688 | char *p; |
52f0bd74 | 689 | int bnum; |
c906108c SS |
690 | struct command_line *l; |
691 | ||
692 | /* If we allowed this, we would have problems with when to | |
693 | free the storage, if we change the commands currently | |
694 | being read from. */ | |
695 | ||
696 | if (executing_breakpoint_commands) | |
8a3fe4f8 | 697 | error (_("Can't use the \"commands\" command among a breakpoint's commands.")); |
c906108c SS |
698 | |
699 | p = arg; | |
700 | bnum = get_number (&p); | |
5c44784c | 701 | |
c906108c | 702 | if (p && *p) |
8a3fe4f8 | 703 | error (_("Unexpected extra arguments following breakpoint number.")); |
c5aa993b | 704 | |
c906108c SS |
705 | ALL_BREAKPOINTS (b) |
706 | if (b->number == bnum) | |
9ebf4acf AC |
707 | { |
708 | char *tmpbuf = xstrprintf ("Type commands for when breakpoint %d is hit, one per line.", | |
709 | bnum); | |
710 | struct cleanup *cleanups = make_cleanup (xfree, tmpbuf); | |
311a4e6b | 711 | l = read_command_lines (tmpbuf, from_tty, 1); |
9ebf4acf | 712 | do_cleanups (cleanups); |
48cb2d85 | 713 | breakpoint_set_commands (b, l); |
9ebf4acf | 714 | return; |
c5aa993b | 715 | } |
8a3fe4f8 | 716 | error (_("No breakpoint number %d."), bnum); |
c906108c | 717 | } |
40c03ae8 EZ |
718 | |
719 | /* Like commands_command, but instead of reading the commands from | |
720 | input stream, takes them from an already parsed command structure. | |
721 | ||
722 | This is used by cli-script.c to DTRT with breakpoint commands | |
723 | that are part of if and while bodies. */ | |
724 | enum command_control_type | |
725 | commands_from_control_command (char *arg, struct command_line *cmd) | |
726 | { | |
727 | struct breakpoint *b; | |
728 | char *p; | |
729 | int bnum; | |
730 | ||
731 | /* If we allowed this, we would have problems with when to | |
732 | free the storage, if we change the commands currently | |
733 | being read from. */ | |
734 | ||
735 | if (executing_breakpoint_commands) | |
736 | error (_("Can't use the \"commands\" command among a breakpoint's commands.")); | |
737 | ||
738 | /* An empty string for the breakpoint number means the last | |
739 | breakpoint, but get_number expects a NULL pointer. */ | |
740 | if (arg && !*arg) | |
741 | p = NULL; | |
742 | else | |
743 | p = arg; | |
744 | bnum = get_number (&p); | |
745 | ||
746 | if (p && *p) | |
747 | error (_("Unexpected extra arguments following breakpoint number.")); | |
748 | ||
749 | ALL_BREAKPOINTS (b) | |
750 | if (b->number == bnum) | |
751 | { | |
752 | free_command_lines (&b->commands); | |
753 | if (cmd->body_count != 1) | |
754 | error (_("Invalid \"commands\" block structure.")); | |
755 | /* We need to copy the commands because if/while will free the | |
756 | list after it finishes execution. */ | |
757 | b->commands = copy_command_lines (cmd->body_list[0]); | |
758 | breakpoints_changed (); | |
383f836e | 759 | observer_notify_breakpoint_modified (b->number); |
40c03ae8 | 760 | return simple_control; |
2f069f6f | 761 | } |
40c03ae8 EZ |
762 | error (_("No breakpoint number %d."), bnum); |
763 | } | |
876fa593 JK |
764 | |
765 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
766 | ||
767 | static int | |
768 | bp_location_has_shadow (struct bp_location *bl) | |
769 | { | |
770 | if (bl->loc_type != bp_loc_software_breakpoint) | |
771 | return 0; | |
772 | if (!bl->inserted) | |
773 | return 0; | |
774 | if (bl->target_info.shadow_len == 0) | |
775 | /* bp isn't valid, or doesn't shadow memory. */ | |
776 | return 0; | |
777 | return 1; | |
778 | } | |
779 | ||
8defab1a | 780 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
781 | by replacing any memory breakpoints with their shadowed contents. |
782 | ||
783 | The range of shadowed area by each bp_location is: | |
784 | b->address - bp_location_placed_address_before_address_max | |
785 | up to b->address + bp_location_shadow_len_after_address_max | |
786 | The range we were requested to resolve shadows for is: | |
787 | memaddr ... memaddr + len | |
788 | Thus the safe cutoff boundaries for performance optimization are | |
789 | memaddr + len <= b->address - bp_location_placed_address_before_address_max | |
790 | and: | |
791 | b->address + bp_location_shadow_len_after_address_max <= memaddr */ | |
c906108c | 792 | |
8defab1a DJ |
793 | void |
794 | breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len) | |
c906108c | 795 | { |
876fa593 JK |
796 | /* Left boundary, right boundary and median element of our binary search. */ |
797 | unsigned bc_l, bc_r, bc; | |
798 | ||
799 | /* Find BC_L which is a leftmost element which may affect BUF content. It is | |
800 | safe to report lower value but a failure to report higher one. */ | |
801 | ||
802 | bc_l = 0; | |
803 | bc_r = bp_location_count; | |
804 | while (bc_l + 1 < bc_r) | |
805 | { | |
806 | struct bp_location *b; | |
807 | ||
808 | bc = (bc_l + bc_r) / 2; | |
809 | b = bp_location[bc]; | |
810 | ||
811 | /* Check first B->ADDRESS will not overflow due to the added constant. | |
812 | Then advance the left boundary only if we are sure the BC element can | |
813 | in no way affect the BUF content (MEMADDR to MEMADDR + LEN range). | |
814 | ||
815 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety offset so that | |
816 | we cannot miss a breakpoint with its shadow range tail still reaching | |
817 | MEMADDR. */ | |
c5aa993b | 818 | |
876fa593 JK |
819 | if (b->address + bp_location_shadow_len_after_address_max >= b->address |
820 | && b->address + bp_location_shadow_len_after_address_max <= memaddr) | |
821 | bc_l = bc; | |
822 | else | |
823 | bc_r = bc; | |
824 | } | |
825 | ||
826 | /* Now do full processing of the found relevant range of elements. */ | |
827 | ||
828 | for (bc = bc_l; bc < bp_location_count; bc++) | |
c5aa993b | 829 | { |
876fa593 JK |
830 | struct bp_location *b = bp_location[bc]; |
831 | CORE_ADDR bp_addr = 0; | |
832 | int bp_size = 0; | |
833 | int bptoffset = 0; | |
834 | ||
ffce0d52 | 835 | if (b->owner->type == bp_none) |
8a3fe4f8 | 836 | warning (_("reading through apparently deleted breakpoint #%d?"), |
ffce0d52 DJ |
837 | b->owner->number); |
838 | ||
876fa593 JK |
839 | /* Performance optimization: any futher element can no longer affect BUF |
840 | content. */ | |
841 | ||
842 | if (b->address >= bp_location_placed_address_before_address_max | |
843 | && memaddr + len <= b->address | |
844 | - bp_location_placed_address_before_address_max) | |
845 | break; | |
846 | ||
847 | if (!bp_location_has_shadow (b)) | |
c5aa993b | 848 | continue; |
6c95b8df PA |
849 | if (!breakpoint_address_match (b->target_info.placed_address_space, 0, |
850 | current_program_space->aspace, 0)) | |
851 | continue; | |
852 | ||
c5aa993b JM |
853 | /* Addresses and length of the part of the breakpoint that |
854 | we need to copy. */ | |
8181d85f DJ |
855 | bp_addr = b->target_info.placed_address; |
856 | bp_size = b->target_info.shadow_len; | |
8defab1a | 857 | |
c5aa993b JM |
858 | if (bp_addr + bp_size <= memaddr) |
859 | /* The breakpoint is entirely before the chunk of memory we | |
860 | are reading. */ | |
861 | continue; | |
8defab1a | 862 | |
c5aa993b JM |
863 | if (bp_addr >= memaddr + len) |
864 | /* The breakpoint is entirely after the chunk of memory we are | |
865 | reading. */ | |
866 | continue; | |
c5aa993b | 867 | |
8defab1a DJ |
868 | /* Offset within shadow_contents. */ |
869 | if (bp_addr < memaddr) | |
870 | { | |
871 | /* Only copy the second part of the breakpoint. */ | |
872 | bp_size -= memaddr - bp_addr; | |
873 | bptoffset = memaddr - bp_addr; | |
874 | bp_addr = memaddr; | |
875 | } | |
c5aa993b | 876 | |
8defab1a DJ |
877 | if (bp_addr + bp_size > memaddr + len) |
878 | { | |
879 | /* Only copy the first part of the breakpoint. */ | |
880 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
881 | } | |
c5aa993b | 882 | |
8defab1a DJ |
883 | memcpy (buf + bp_addr - memaddr, |
884 | b->target_info.shadow_contents + bptoffset, bp_size); | |
c5aa993b | 885 | } |
c906108c | 886 | } |
c906108c | 887 | \f |
c5aa993b | 888 | |
687595f9 | 889 | /* A wrapper function for inserting catchpoints. */ |
9cbc821d | 890 | static void |
687595f9 DJ |
891 | insert_catchpoint (struct ui_out *uo, void *args) |
892 | { | |
893 | struct breakpoint *b = (struct breakpoint *) args; | |
894 | int val = -1; | |
895 | ||
fe798b75 JB |
896 | gdb_assert (b->type == bp_catchpoint); |
897 | gdb_assert (b->ops != NULL && b->ops->insert != NULL); | |
898 | ||
899 | b->ops->insert (b); | |
687595f9 DJ |
900 | } |
901 | ||
a5606eee VP |
902 | static int |
903 | is_hardware_watchpoint (struct breakpoint *bpt) | |
904 | { | |
905 | return (bpt->type == bp_hardware_watchpoint | |
906 | || bpt->type == bp_read_watchpoint | |
907 | || bpt->type == bp_access_watchpoint); | |
908 | } | |
7270d8f2 | 909 | |
fa4727a6 DJ |
910 | /* Find the current value of a watchpoint on EXP. Return the value in |
911 | *VALP and *RESULTP and the chain of intermediate and final values | |
912 | in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does | |
913 | not need them. | |
914 | ||
ccc57cf9 | 915 | If a memory error occurs while evaluating the expression, *RESULTP will |
fa4727a6 DJ |
916 | be set to NULL. *RESULTP may be a lazy value, if the result could |
917 | not be read from memory. It is used to determine whether a value | |
918 | is user-specified (we should watch the whole value) or intermediate | |
919 | (we should watch only the bit used to locate the final value). | |
920 | ||
921 | If the final value, or any intermediate value, could not be read | |
922 | from memory, *VALP will be set to NULL. *VAL_CHAIN will still be | |
923 | set to any referenced values. *VALP will never be a lazy value. | |
924 | This is the value which we store in struct breakpoint. | |
925 | ||
926 | If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the | |
927 | value chain. The caller must free the values individually. If | |
928 | VAL_CHAIN is NULL, all generated values will be left on the value | |
929 | chain. */ | |
930 | ||
931 | static void | |
932 | fetch_watchpoint_value (struct expression *exp, struct value **valp, | |
933 | struct value **resultp, struct value **val_chain) | |
934 | { | |
935 | struct value *mark, *new_mark, *result; | |
ccc57cf9 | 936 | volatile struct gdb_exception ex; |
fa4727a6 DJ |
937 | |
938 | *valp = NULL; | |
939 | if (resultp) | |
940 | *resultp = NULL; | |
941 | if (val_chain) | |
942 | *val_chain = NULL; | |
943 | ||
944 | /* Evaluate the expression. */ | |
945 | mark = value_mark (); | |
946 | result = NULL; | |
ccc57cf9 PA |
947 | |
948 | TRY_CATCH (ex, RETURN_MASK_ALL) | |
949 | { | |
950 | result = evaluate_expression (exp); | |
951 | } | |
952 | if (ex.reason < 0) | |
953 | { | |
954 | /* Ignore memory errors, we want watchpoints pointing at | |
955 | inaccessible memory to still be created; otherwise, throw the | |
956 | error to some higher catcher. */ | |
957 | switch (ex.error) | |
958 | { | |
959 | case MEMORY_ERROR: | |
960 | break; | |
961 | default: | |
962 | throw_exception (ex); | |
963 | break; | |
964 | } | |
965 | } | |
966 | ||
fa4727a6 DJ |
967 | new_mark = value_mark (); |
968 | if (mark == new_mark) | |
969 | return; | |
970 | if (resultp) | |
971 | *resultp = result; | |
972 | ||
973 | /* Make sure it's not lazy, so that after the target stops again we | |
974 | have a non-lazy previous value to compare with. */ | |
975 | if (result != NULL | |
976 | && (!value_lazy (result) || gdb_value_fetch_lazy (result))) | |
977 | *valp = result; | |
978 | ||
979 | if (val_chain) | |
980 | { | |
981 | /* Return the chain of intermediate values. We use this to | |
982 | decide which addresses to watch. */ | |
983 | *val_chain = new_mark; | |
984 | value_release_to_mark (mark); | |
985 | } | |
986 | } | |
987 | ||
567e1b4e JB |
988 | /* Assuming that B is a watchpoint: |
989 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 990 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
991 | - Evaluate the condition if there is one, and store the result |
992 | in b->loc->cond. | |
a5606eee VP |
993 | - Update the list of values that must be watched in B->loc. |
994 | ||
bfa149ac JB |
995 | If the watchpoint disposition is disp_del_at_next_stop, then do nothing. |
996 | If this is local watchpoint that is out of scope, delete it. */ | |
b40ce68a | 997 | static void |
a5606eee | 998 | update_watchpoint (struct breakpoint *b, int reparse) |
7270d8f2 | 999 | { |
a5606eee | 1000 | int within_current_scope; |
a5606eee VP |
1001 | struct frame_id saved_frame_id; |
1002 | struct bp_location *loc; | |
66076460 | 1003 | int frame_saved; |
a5606eee | 1004 | bpstat bs; |
6c95b8df | 1005 | struct program_space *frame_pspace; |
a5606eee | 1006 | |
876fa593 | 1007 | /* We don't free locations. They are stored in bp_location array and |
567e1b4e JB |
1008 | update_global_locations will eventually delete them and remove |
1009 | breakpoints if needed. */ | |
a5606eee VP |
1010 | b->loc = NULL; |
1011 | ||
1012 | if (b->disposition == disp_del_at_next_stop) | |
1013 | return; | |
1014 | ||
66076460 | 1015 | frame_saved = 0; |
a5606eee VP |
1016 | |
1017 | /* Determine if the watchpoint is within scope. */ | |
1018 | if (b->exp_valid_block == NULL) | |
1019 | within_current_scope = 1; | |
1020 | else | |
1021 | { | |
1022 | struct frame_info *fi; | |
66076460 DJ |
1023 | |
1024 | /* Save the current frame's ID so we can restore it after | |
1025 | evaluating the watchpoint expression on its own frame. */ | |
1026 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1027 | took a frame parameter, so that we didn't have to change the | |
1028 | selected frame. */ | |
1029 | frame_saved = 1; | |
1030 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1031 | ||
a5606eee VP |
1032 | fi = frame_find_by_id (b->watchpoint_frame); |
1033 | within_current_scope = (fi != NULL); | |
1034 | if (within_current_scope) | |
1035 | select_frame (fi); | |
1036 | } | |
1037 | ||
6c95b8df PA |
1038 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1039 | ||
a5606eee VP |
1040 | if (within_current_scope && reparse) |
1041 | { | |
1042 | char *s; | |
1043 | if (b->exp) | |
1044 | { | |
1045 | xfree (b->exp); | |
1046 | b->exp = NULL; | |
1047 | } | |
1048 | s = b->exp_string; | |
1049 | b->exp = parse_exp_1 (&s, b->exp_valid_block, 0); | |
1050 | /* If the meaning of expression itself changed, the old value is | |
1051 | no longer relevant. We don't want to report a watchpoint hit | |
1052 | to the user when the old value and the new value may actually | |
1053 | be completely different objects. */ | |
1054 | value_free (b->val); | |
fa4727a6 DJ |
1055 | b->val = NULL; |
1056 | b->val_valid = 0; | |
a5606eee | 1057 | } |
a5606eee VP |
1058 | |
1059 | /* If we failed to parse the expression, for example because | |
1060 | it refers to a global variable in a not-yet-loaded shared library, | |
1061 | don't try to insert watchpoint. We don't automatically delete | |
1062 | such watchpoint, though, since failure to parse expression | |
1063 | is different from out-of-scope watchpoint. */ | |
1064 | if (within_current_scope && b->exp) | |
1065 | { | |
fa4727a6 | 1066 | struct value *val_chain, *v, *result, *next; |
a5606eee | 1067 | |
fa4727a6 | 1068 | fetch_watchpoint_value (b->exp, &v, &result, &val_chain); |
a5606eee | 1069 | |
a5606eee VP |
1070 | /* Avoid setting b->val if it's already set. The meaning of |
1071 | b->val is 'the last value' user saw, and we should update | |
1072 | it only if we reported that last value to user. As it | |
1073 | happens, the code that reports it updates b->val directly. */ | |
fa4727a6 DJ |
1074 | if (!b->val_valid) |
1075 | { | |
1076 | b->val = v; | |
1077 | b->val_valid = 1; | |
1078 | } | |
a5606eee | 1079 | |
db2ad4c3 JK |
1080 | /* Change the type of breakpoint between hardware assisted or an |
1081 | ordinary watchpoint depending on the hardware support and free | |
1082 | hardware slots. REPARSE is set when the inferior is started. */ | |
1083 | if ((b->type == bp_watchpoint || b->type == bp_hardware_watchpoint) | |
1084 | && reparse) | |
1085 | { | |
ca2d49e8 | 1086 | int i, mem_cnt, other_type_used; |
db2ad4c3 JK |
1087 | |
1088 | i = hw_watchpoint_used_count (bp_hardware_watchpoint, | |
1089 | &other_type_used); | |
1090 | mem_cnt = can_use_hardware_watchpoint (val_chain); | |
1091 | ||
ca2d49e8 | 1092 | if (!mem_cnt) |
db2ad4c3 JK |
1093 | b->type = bp_watchpoint; |
1094 | else | |
ca2d49e8 | 1095 | { |
d92524f1 | 1096 | int target_resources_ok = target_can_use_hardware_watchpoint |
ca2d49e8 SL |
1097 | (bp_hardware_watchpoint, i + mem_cnt, other_type_used); |
1098 | if (target_resources_ok <= 0) | |
1099 | b->type = bp_watchpoint; | |
1100 | else | |
1101 | b->type = bp_hardware_watchpoint; | |
1102 | } | |
db2ad4c3 JK |
1103 | } |
1104 | ||
a5606eee | 1105 | /* Look at each value on the value chain. */ |
fa4727a6 | 1106 | for (v = val_chain; v; v = next) |
a5606eee VP |
1107 | { |
1108 | /* If it's a memory location, and GDB actually needed | |
1109 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1110 | must watch it. If the first value returned is |
1111 | still lazy, that means an error occurred reading it; | |
1112 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1113 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1114 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1115 | { |
1116 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1117 | |
a5606eee VP |
1118 | /* We only watch structs and arrays if user asked |
1119 | for it explicitly, never if they just happen to | |
1120 | appear in the middle of some value chain. */ | |
fa4727a6 | 1121 | if (v == result |
a5606eee VP |
1122 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1123 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1124 | { | |
1125 | CORE_ADDR addr; | |
1126 | int len, type; | |
1127 | struct bp_location *loc, **tmp; | |
1128 | ||
42ae5230 | 1129 | addr = value_address (v); |
a5606eee VP |
1130 | len = TYPE_LENGTH (value_type (v)); |
1131 | type = hw_write; | |
1132 | if (b->type == bp_read_watchpoint) | |
1133 | type = hw_read; | |
1134 | else if (b->type == bp_access_watchpoint) | |
1135 | type = hw_access; | |
1136 | ||
39d61571 | 1137 | loc = allocate_bp_location (b); |
a5606eee VP |
1138 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
1139 | ; | |
1140 | *tmp = loc; | |
a6d9a66e | 1141 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1142 | |
1143 | loc->pspace = frame_pspace; | |
a5606eee VP |
1144 | loc->address = addr; |
1145 | loc->length = len; | |
1146 | loc->watchpoint_type = type; | |
1147 | } | |
1148 | } | |
1149 | ||
1150 | next = value_next (v); | |
1151 | if (v != b->val) | |
1152 | value_free (v); | |
1153 | } | |
1154 | ||
2ec93238 MK |
1155 | /* We just regenerated the list of breakpoint locations. |
1156 | The new location does not have its condition field set to anything | |
1157 | and therefore, we must always reparse the cond_string, independently | |
1158 | of the value of the reparse flag. */ | |
1159 | if (b->cond_string != NULL) | |
a5606eee VP |
1160 | { |
1161 | char *s = b->cond_string; | |
a5606eee VP |
1162 | b->loc->cond = parse_exp_1 (&s, b->exp_valid_block, 0); |
1163 | } | |
1164 | } | |
1165 | else if (!within_current_scope) | |
7270d8f2 | 1166 | { |
a5606eee | 1167 | printf_filtered (_("\ |
567e1b4e | 1168 | Watchpoint %d deleted because the program has left the block \n\ |
a5606eee VP |
1169 | in which its expression is valid.\n"), |
1170 | b->number); | |
1171 | if (b->related_breakpoint) | |
1172 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1173 | b->disposition = disp_del_at_next_stop; | |
7270d8f2 | 1174 | } |
a5606eee VP |
1175 | |
1176 | /* Restore the selected frame. */ | |
66076460 DJ |
1177 | if (frame_saved) |
1178 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
1179 | } |
1180 | ||
a5606eee | 1181 | |
74960c60 VP |
1182 | /* Returns 1 iff breakpoint location should be |
1183 | inserted in the inferior. */ | |
1184 | static int | |
1185 | should_be_inserted (struct bp_location *bpt) | |
1186 | { | |
1187 | if (!breakpoint_enabled (bpt->owner)) | |
1188 | return 0; | |
1189 | ||
1190 | if (bpt->owner->disposition == disp_del_at_next_stop) | |
1191 | return 0; | |
1192 | ||
1193 | if (!bpt->enabled || bpt->shlib_disabled || bpt->duplicate) | |
1194 | return 0; | |
1195 | ||
56710373 PA |
1196 | /* This is set for example, when we're attached to the parent of a |
1197 | vfork, and have detached from the child. The child is running | |
1198 | free, and we expect it to do an exec or exit, at which point the | |
1199 | OS makes the parent schedulable again (and the target reports | |
1200 | that the vfork is done). Until the child is done with the shared | |
1201 | memory region, do not insert breakpoints in the parent, otherwise | |
1202 | the child could still trip on the parent's breakpoints. Since | |
1203 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
1204 | if (bpt->pspace->breakpoints_not_allowed) | |
1205 | return 0; | |
1206 | ||
1042e4c0 SS |
1207 | /* Tracepoints are inserted by the target at a time of its choosing, |
1208 | not by us. */ | |
1209 | if (bpt->owner->type == bp_tracepoint) | |
1210 | return 0; | |
1211 | ||
74960c60 VP |
1212 | return 1; |
1213 | } | |
1214 | ||
879bfdc2 DJ |
1215 | /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint. |
1216 | Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS, | |
fa3a767f | 1217 | and HW_BREAKPOINT_ERROR are used to report problems. |
879bfdc2 DJ |
1218 | |
1219 | NOTE drow/2003-09-09: This routine could be broken down to an object-style | |
1220 | method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 1221 | static int |
879bfdc2 | 1222 | insert_bp_location (struct bp_location *bpt, |
26bb91f3 | 1223 | struct ui_file *tmp_error_stream, |
fa3a767f | 1224 | int *disabled_breaks, |
26bb91f3 | 1225 | int *hw_breakpoint_error) |
879bfdc2 DJ |
1226 | { |
1227 | int val = 0; | |
1228 | ||
74960c60 | 1229 | if (!should_be_inserted (bpt) || bpt->inserted) |
879bfdc2 DJ |
1230 | return 0; |
1231 | ||
8181d85f DJ |
1232 | /* Initialize the target-specific information. */ |
1233 | memset (&bpt->target_info, 0, sizeof (bpt->target_info)); | |
1234 | bpt->target_info.placed_address = bpt->address; | |
6c95b8df | 1235 | bpt->target_info.placed_address_space = bpt->pspace->aspace; |
8181d85f | 1236 | |
879bfdc2 DJ |
1237 | if (bpt->loc_type == bp_loc_software_breakpoint |
1238 | || bpt->loc_type == bp_loc_hardware_breakpoint) | |
1239 | { | |
765dc015 VP |
1240 | if (bpt->owner->type != bp_hardware_breakpoint) |
1241 | { | |
1242 | /* If the explicitly specified breakpoint type | |
1243 | is not hardware breakpoint, check the memory map to see | |
1244 | if the breakpoint address is in read only memory or not. | |
1245 | Two important cases are: | |
1246 | - location type is not hardware breakpoint, memory | |
1247 | is readonly. We change the type of the location to | |
1248 | hardware breakpoint. | |
1249 | - location type is hardware breakpoint, memory is read-write. | |
1250 | This means we've previously made the location hardware one, but | |
1251 | then the memory map changed, so we undo. | |
1252 | ||
1253 | When breakpoints are removed, remove_breakpoints will | |
1254 | use location types we've just set here, the only possible | |
1255 | problem is that memory map has changed during running program, | |
1256 | but it's not going to work anyway with current gdb. */ | |
1257 | struct mem_region *mr | |
1258 | = lookup_mem_region (bpt->target_info.placed_address); | |
1259 | ||
1260 | if (mr) | |
1261 | { | |
1262 | if (automatic_hardware_breakpoints) | |
1263 | { | |
1264 | int changed = 0; | |
1265 | enum bp_loc_type new_type; | |
1266 | ||
1267 | if (mr->attrib.mode != MEM_RW) | |
1268 | new_type = bp_loc_hardware_breakpoint; | |
1269 | else | |
1270 | new_type = bp_loc_software_breakpoint; | |
1271 | ||
1272 | if (new_type != bpt->loc_type) | |
1273 | { | |
1274 | static int said = 0; | |
1275 | bpt->loc_type = new_type; | |
1276 | if (!said) | |
1277 | { | |
1278 | fprintf_filtered (gdb_stdout, _("\ | |
0767c96d | 1279 | Note: automatically using hardware breakpoints for read-only addresses.\n")); |
765dc015 VP |
1280 | said = 1; |
1281 | } | |
1282 | } | |
1283 | } | |
1284 | else if (bpt->loc_type == bp_loc_software_breakpoint | |
1285 | && mr->attrib.mode != MEM_RW) | |
1286 | warning (_("cannot set software breakpoint at readonly address %s"), | |
5af949e3 | 1287 | paddress (bpt->gdbarch, bpt->address)); |
765dc015 VP |
1288 | } |
1289 | } | |
1290 | ||
879bfdc2 DJ |
1291 | /* First check to see if we have to handle an overlay. */ |
1292 | if (overlay_debugging == ovly_off | |
1293 | || bpt->section == NULL | |
1294 | || !(section_is_overlay (bpt->section))) | |
1295 | { | |
1296 | /* No overlay handling: just set the breakpoint. */ | |
1297 | ||
1298 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
a6d9a66e UW |
1299 | val = target_insert_hw_breakpoint (bpt->gdbarch, |
1300 | &bpt->target_info); | |
879bfdc2 | 1301 | else |
a6d9a66e UW |
1302 | val = target_insert_breakpoint (bpt->gdbarch, |
1303 | &bpt->target_info); | |
879bfdc2 DJ |
1304 | } |
1305 | else | |
1306 | { | |
1307 | /* This breakpoint is in an overlay section. | |
1308 | Shall we set a breakpoint at the LMA? */ | |
1309 | if (!overlay_events_enabled) | |
1310 | { | |
1311 | /* Yes -- overlay event support is not active, | |
1312 | so we must try to set a breakpoint at the LMA. | |
1313 | This will not work for a hardware breakpoint. */ | |
1314 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
8a3fe4f8 | 1315 | warning (_("hardware breakpoint %d not supported in overlay!"), |
879bfdc2 DJ |
1316 | bpt->owner->number); |
1317 | else | |
1318 | { | |
1319 | CORE_ADDR addr = overlay_unmapped_address (bpt->address, | |
1320 | bpt->section); | |
1321 | /* Set a software (trap) breakpoint at the LMA. */ | |
8181d85f DJ |
1322 | bpt->overlay_target_info = bpt->target_info; |
1323 | bpt->overlay_target_info.placed_address = addr; | |
a6d9a66e UW |
1324 | val = target_insert_breakpoint (bpt->gdbarch, |
1325 | &bpt->overlay_target_info); | |
879bfdc2 | 1326 | if (val != 0) |
99361f52 DE |
1327 | fprintf_unfiltered (tmp_error_stream, |
1328 | "Overlay breakpoint %d failed: in ROM?\n", | |
879bfdc2 DJ |
1329 | bpt->owner->number); |
1330 | } | |
1331 | } | |
1332 | /* Shall we set a breakpoint at the VMA? */ | |
1333 | if (section_is_mapped (bpt->section)) | |
1334 | { | |
1335 | /* Yes. This overlay section is mapped into memory. */ | |
1336 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
a6d9a66e UW |
1337 | val = target_insert_hw_breakpoint (bpt->gdbarch, |
1338 | &bpt->target_info); | |
879bfdc2 | 1339 | else |
a6d9a66e UW |
1340 | val = target_insert_breakpoint (bpt->gdbarch, |
1341 | &bpt->target_info); | |
879bfdc2 DJ |
1342 | } |
1343 | else | |
1344 | { | |
1345 | /* No. This breakpoint will not be inserted. | |
1346 | No error, but do not mark the bp as 'inserted'. */ | |
1347 | return 0; | |
1348 | } | |
1349 | } | |
1350 | ||
1351 | if (val) | |
1352 | { | |
1353 | /* Can't set the breakpoint. */ | |
6c95b8df | 1354 | if (solib_name_from_address (bpt->pspace, bpt->address)) |
879bfdc2 DJ |
1355 | { |
1356 | /* See also: disable_breakpoints_in_shlibs. */ | |
1357 | val = 0; | |
0d381245 | 1358 | bpt->shlib_disabled = 1; |
879bfdc2 DJ |
1359 | if (!*disabled_breaks) |
1360 | { | |
1361 | fprintf_unfiltered (tmp_error_stream, | |
1362 | "Cannot insert breakpoint %d.\n", | |
1363 | bpt->owner->number); | |
1364 | fprintf_unfiltered (tmp_error_stream, | |
1365 | "Temporarily disabling shared library breakpoints:\n"); | |
1366 | } | |
1367 | *disabled_breaks = 1; | |
1368 | fprintf_unfiltered (tmp_error_stream, | |
1369 | "breakpoint #%d\n", bpt->owner->number); | |
1370 | } | |
1371 | else | |
879bfdc2 | 1372 | { |
879bfdc2 DJ |
1373 | if (bpt->loc_type == bp_loc_hardware_breakpoint) |
1374 | { | |
1375 | *hw_breakpoint_error = 1; | |
1376 | fprintf_unfiltered (tmp_error_stream, | |
1377 | "Cannot insert hardware breakpoint %d.\n", | |
1378 | bpt->owner->number); | |
1379 | } | |
1380 | else | |
1381 | { | |
1382 | fprintf_unfiltered (tmp_error_stream, | |
1383 | "Cannot insert breakpoint %d.\n", | |
1384 | bpt->owner->number); | |
1385 | fprintf_filtered (tmp_error_stream, | |
1386 | "Error accessing memory address "); | |
5af949e3 UW |
1387 | fputs_filtered (paddress (bpt->gdbarch, bpt->address), |
1388 | tmp_error_stream); | |
879bfdc2 DJ |
1389 | fprintf_filtered (tmp_error_stream, ": %s.\n", |
1390 | safe_strerror (val)); | |
1391 | } | |
1392 | ||
1393 | } | |
1394 | } | |
1395 | else | |
1396 | bpt->inserted = 1; | |
1397 | ||
1398 | return val; | |
1399 | } | |
1400 | ||
1401 | else if (bpt->loc_type == bp_loc_hardware_watchpoint | |
1402 | /* NOTE drow/2003-09-08: This state only exists for removing | |
1403 | watchpoints. It's not clear that it's necessary... */ | |
1404 | && bpt->owner->disposition != disp_del_at_next_stop) | |
1405 | { | |
a5606eee VP |
1406 | val = target_insert_watchpoint (bpt->address, |
1407 | bpt->length, | |
1408 | bpt->watchpoint_type); | |
1409 | bpt->inserted = (val != -1); | |
879bfdc2 DJ |
1410 | } |
1411 | ||
fe798b75 | 1412 | else if (bpt->owner->type == bp_catchpoint) |
879bfdc2 | 1413 | { |
71fff37b AC |
1414 | struct gdb_exception e = catch_exception (uiout, insert_catchpoint, |
1415 | bpt->owner, RETURN_MASK_ERROR); | |
9cbc821d AC |
1416 | exception_fprintf (gdb_stderr, e, "warning: inserting catchpoint %d: ", |
1417 | bpt->owner->number); | |
1418 | if (e.reason < 0) | |
879bfdc2 DJ |
1419 | bpt->owner->enable_state = bp_disabled; |
1420 | else | |
1421 | bpt->inserted = 1; | |
1640b821 DJ |
1422 | |
1423 | /* We've already printed an error message if there was a problem | |
1424 | inserting this catchpoint, and we've disabled the catchpoint, | |
1425 | so just return success. */ | |
1426 | return 0; | |
879bfdc2 DJ |
1427 | } |
1428 | ||
1429 | return 0; | |
1430 | } | |
1431 | ||
6c95b8df PA |
1432 | /* This function is called when program space PSPACE is about to be |
1433 | deleted. It takes care of updating breakpoints to not reference | |
1434 | PSPACE anymore. */ | |
1435 | ||
1436 | void | |
1437 | breakpoint_program_space_exit (struct program_space *pspace) | |
1438 | { | |
1439 | struct breakpoint *b, *b_temp; | |
876fa593 | 1440 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
1441 | |
1442 | /* Remove any breakpoint that was set through this program space. */ | |
1443 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
1444 | { | |
1445 | if (b->pspace == pspace) | |
1446 | delete_breakpoint (b); | |
1447 | } | |
1448 | ||
1449 | /* Breakpoints set through other program spaces could have locations | |
1450 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 1451 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
1452 | { |
1453 | struct bp_location *tmp; | |
1454 | ||
1455 | if (loc->pspace == pspace) | |
1456 | { | |
1457 | if (loc->owner->loc == loc) | |
1458 | loc->owner->loc = loc->next; | |
1459 | else | |
1460 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
1461 | if (tmp->next == loc) | |
1462 | { | |
1463 | tmp->next = loc->next; | |
1464 | break; | |
1465 | } | |
1466 | } | |
1467 | } | |
1468 | ||
1469 | /* Now update the global location list to permanently delete the | |
1470 | removed locations above. */ | |
1471 | update_global_location_list (0); | |
1472 | } | |
1473 | ||
74960c60 VP |
1474 | /* Make sure all breakpoints are inserted in inferior. |
1475 | Throws exception on any error. | |
1476 | A breakpoint that is already inserted won't be inserted | |
1477 | again, so calling this function twice is safe. */ | |
1478 | void | |
1479 | insert_breakpoints (void) | |
1480 | { | |
1481 | struct breakpoint *bpt; | |
1482 | ||
1483 | ALL_BREAKPOINTS (bpt) | |
1484 | if (is_hardware_watchpoint (bpt)) | |
1485 | update_watchpoint (bpt, 0 /* don't reparse. */); | |
1486 | ||
b60e7edf | 1487 | update_global_location_list (1); |
74960c60 | 1488 | |
c35b1492 PA |
1489 | /* update_global_location_list does not insert breakpoints when |
1490 | always_inserted_mode is not enabled. Explicitly insert them | |
1491 | now. */ | |
1492 | if (!breakpoints_always_inserted_mode ()) | |
74960c60 VP |
1493 | insert_breakpoint_locations (); |
1494 | } | |
1495 | ||
c906108c SS |
1496 | /* insert_breakpoints is used when starting or continuing the program. |
1497 | remove_breakpoints is used when the program stops. | |
1498 | Both return zero if successful, | |
1499 | or an `errno' value if could not write the inferior. */ | |
1500 | ||
74960c60 VP |
1501 | static void |
1502 | insert_breakpoint_locations (void) | |
c906108c | 1503 | { |
a5606eee | 1504 | struct breakpoint *bpt; |
876fa593 | 1505 | struct bp_location *b, **bp_tmp; |
e236ba44 | 1506 | int error = 0; |
c906108c SS |
1507 | int val = 0; |
1508 | int disabled_breaks = 0; | |
81d0cc19 | 1509 | int hw_breakpoint_error = 0; |
c906108c | 1510 | |
81d0cc19 | 1511 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 1512 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 1513 | |
81d0cc19 GS |
1514 | /* Explicitly mark the warning -- this will only be printed if |
1515 | there was an error. */ | |
1516 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
1517 | |
1518 | save_current_space_and_thread (); | |
1519 | ||
876fa593 | 1520 | ALL_BP_LOCATIONS (b, bp_tmp) |
879bfdc2 | 1521 | { |
6c95b8df PA |
1522 | struct thread_info *tp; |
1523 | CORE_ADDR last_addr; | |
1524 | ||
74960c60 | 1525 | if (!should_be_inserted (b) || b->inserted) |
879bfdc2 DJ |
1526 | continue; |
1527 | ||
f365de73 AS |
1528 | /* There is no point inserting thread-specific breakpoints if the |
1529 | thread no longer exists. */ | |
1530 | if (b->owner->thread != -1 | |
1531 | && !valid_thread_id (b->owner->thread)) | |
1532 | continue; | |
1533 | ||
6c95b8df PA |
1534 | switch_to_program_space_and_thread (b->pspace); |
1535 | ||
1536 | /* For targets that support global breakpoints, there's no need | |
1537 | to select an inferior to insert breakpoint to. In fact, even | |
1538 | if we aren't attached to any process yet, we should still | |
1539 | insert breakpoints. */ | |
1540 | if (!gdbarch_has_global_breakpoints (target_gdbarch) | |
1541 | && ptid_equal (inferior_ptid, null_ptid)) | |
1542 | continue; | |
1543 | ||
879bfdc2 | 1544 | val = insert_bp_location (b, tmp_error_stream, |
fa3a767f | 1545 | &disabled_breaks, |
879bfdc2 DJ |
1546 | &hw_breakpoint_error); |
1547 | if (val) | |
e236ba44 | 1548 | error = val; |
879bfdc2 | 1549 | } |
c906108c | 1550 | |
a5606eee VP |
1551 | /* If we failed to insert all locations of a watchpoint, |
1552 | remove them, as half-inserted watchpoint is of limited use. */ | |
1553 | ALL_BREAKPOINTS (bpt) | |
1554 | { | |
1555 | int some_failed = 0; | |
1556 | struct bp_location *loc; | |
1557 | ||
1558 | if (!is_hardware_watchpoint (bpt)) | |
1559 | continue; | |
1560 | ||
d6b74ac4 | 1561 | if (!breakpoint_enabled (bpt)) |
a5606eee | 1562 | continue; |
74960c60 VP |
1563 | |
1564 | if (bpt->disposition == disp_del_at_next_stop) | |
1565 | continue; | |
a5606eee VP |
1566 | |
1567 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 1568 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
1569 | { |
1570 | some_failed = 1; | |
1571 | break; | |
1572 | } | |
1573 | if (some_failed) | |
1574 | { | |
1575 | for (loc = bpt->loc; loc; loc = loc->next) | |
1576 | if (loc->inserted) | |
1577 | remove_breakpoint (loc, mark_uninserted); | |
1578 | ||
1579 | hw_breakpoint_error = 1; | |
1580 | fprintf_unfiltered (tmp_error_stream, | |
1581 | "Could not insert hardware watchpoint %d.\n", | |
1582 | bpt->number); | |
1583 | error = -1; | |
1584 | } | |
1585 | } | |
1586 | ||
e236ba44 | 1587 | if (error) |
81d0cc19 GS |
1588 | { |
1589 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
1590 | message about possibly exhausted resources. */ | |
879bfdc2 | 1591 | if (hw_breakpoint_error) |
81d0cc19 | 1592 | { |
c6510018 MS |
1593 | fprintf_unfiltered (tmp_error_stream, |
1594 | "Could not insert hardware breakpoints:\n\ | |
1595 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 1596 | } |
81d0cc19 GS |
1597 | target_terminal_ours_for_output (); |
1598 | error_stream (tmp_error_stream); | |
1599 | } | |
f7545552 TT |
1600 | |
1601 | do_cleanups (cleanups); | |
c906108c SS |
1602 | } |
1603 | ||
c906108c | 1604 | int |
fba45db2 | 1605 | remove_breakpoints (void) |
c906108c | 1606 | { |
876fa593 | 1607 | struct bp_location *b, **bp_tmp; |
3a1bae8e | 1608 | int val = 0; |
c906108c | 1609 | |
876fa593 | 1610 | ALL_BP_LOCATIONS (b, bp_tmp) |
c5aa993b | 1611 | { |
0bde7532 | 1612 | if (b->inserted) |
3a1bae8e | 1613 | val |= remove_breakpoint (b, mark_uninserted); |
c5aa993b | 1614 | } |
3a1bae8e | 1615 | return val; |
c906108c SS |
1616 | } |
1617 | ||
6c95b8df PA |
1618 | /* Remove breakpoints of process PID. */ |
1619 | ||
1620 | int | |
1621 | remove_breakpoints_pid (int pid) | |
1622 | { | |
876fa593 | 1623 | struct bp_location *b, **b_tmp; |
6c95b8df PA |
1624 | int val; |
1625 | struct inferior *inf = find_inferior_pid (pid); | |
1626 | ||
876fa593 | 1627 | ALL_BP_LOCATIONS (b, b_tmp) |
6c95b8df PA |
1628 | { |
1629 | if (b->pspace != inf->pspace) | |
1630 | continue; | |
1631 | ||
1632 | if (b->inserted) | |
1633 | { | |
1634 | val = remove_breakpoint (b, mark_uninserted); | |
1635 | if (val != 0) | |
1636 | return val; | |
1637 | } | |
1638 | } | |
1639 | return 0; | |
1640 | } | |
1641 | ||
692590c1 | 1642 | int |
80ce1ecb | 1643 | remove_hw_watchpoints (void) |
692590c1 | 1644 | { |
876fa593 | 1645 | struct bp_location *b, **bp_tmp; |
3a1bae8e | 1646 | int val = 0; |
692590c1 | 1647 | |
876fa593 | 1648 | ALL_BP_LOCATIONS (b, bp_tmp) |
692590c1 | 1649 | { |
0bde7532 | 1650 | if (b->inserted && b->loc_type == bp_loc_hardware_watchpoint) |
3a1bae8e | 1651 | val |= remove_breakpoint (b, mark_uninserted); |
692590c1 | 1652 | } |
3a1bae8e | 1653 | return val; |
692590c1 MS |
1654 | } |
1655 | ||
c906108c | 1656 | int |
fba45db2 | 1657 | reattach_breakpoints (int pid) |
c906108c | 1658 | { |
6c95b8df | 1659 | struct cleanup *old_chain; |
876fa593 | 1660 | struct bp_location *b, **bp_tmp; |
c906108c | 1661 | int val; |
a4954f26 | 1662 | struct ui_file *tmp_error_stream = mem_fileopen (); |
fa3a767f | 1663 | int dummy1 = 0, dummy2 = 0; |
6c95b8df PA |
1664 | struct inferior *inf; |
1665 | struct thread_info *tp; | |
1666 | ||
1667 | tp = any_live_thread_of_process (pid); | |
1668 | if (tp == NULL) | |
1669 | return 1; | |
1670 | ||
1671 | inf = find_inferior_pid (pid); | |
1672 | old_chain = save_inferior_ptid (); | |
1673 | ||
1674 | inferior_ptid = tp->ptid; | |
a4954f26 DJ |
1675 | |
1676 | make_cleanup_ui_file_delete (tmp_error_stream); | |
c906108c | 1677 | |
876fa593 | 1678 | ALL_BP_LOCATIONS (b, bp_tmp) |
c5aa993b | 1679 | { |
6c95b8df PA |
1680 | if (b->pspace != inf->pspace) |
1681 | continue; | |
1682 | ||
0bde7532 | 1683 | if (b->inserted) |
c5aa993b | 1684 | { |
a4954f26 DJ |
1685 | b->inserted = 0; |
1686 | val = insert_bp_location (b, tmp_error_stream, | |
fa3a767f | 1687 | &dummy1, &dummy2); |
c5aa993b JM |
1688 | if (val != 0) |
1689 | { | |
ce696e05 | 1690 | do_cleanups (old_chain); |
c5aa993b JM |
1691 | return val; |
1692 | } | |
1693 | } | |
1694 | } | |
ce696e05 | 1695 | do_cleanups (old_chain); |
c906108c SS |
1696 | return 0; |
1697 | } | |
1698 | ||
e58b0e63 PA |
1699 | static int internal_breakpoint_number = -1; |
1700 | ||
e62c965a | 1701 | static struct breakpoint * |
a6d9a66e UW |
1702 | create_internal_breakpoint (struct gdbarch *gdbarch, |
1703 | CORE_ADDR address, enum bptype type) | |
e62c965a | 1704 | { |
e62c965a PP |
1705 | struct symtab_and_line sal; |
1706 | struct breakpoint *b; | |
1707 | ||
1708 | init_sal (&sal); /* initialize to zeroes */ | |
1709 | ||
1710 | sal.pc = address; | |
1711 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 1712 | sal.pspace = current_program_space; |
e62c965a | 1713 | |
a6d9a66e | 1714 | b = set_raw_breakpoint (gdbarch, sal, type); |
e62c965a PP |
1715 | b->number = internal_breakpoint_number--; |
1716 | b->disposition = disp_donttouch; | |
1717 | ||
1718 | return b; | |
1719 | } | |
1720 | ||
1721 | static void | |
69de3c6a | 1722 | create_overlay_event_breakpoint (char *func_name) |
e62c965a | 1723 | { |
69de3c6a | 1724 | struct objfile *objfile; |
e62c965a | 1725 | |
69de3c6a PP |
1726 | ALL_OBJFILES (objfile) |
1727 | { | |
1728 | struct breakpoint *b; | |
1729 | struct minimal_symbol *m; | |
1730 | ||
1731 | m = lookup_minimal_symbol_text (func_name, objfile); | |
1732 | if (m == NULL) | |
1733 | continue; | |
e62c965a | 1734 | |
a6d9a66e UW |
1735 | b = create_internal_breakpoint (get_objfile_arch (objfile), |
1736 | SYMBOL_VALUE_ADDRESS (m), | |
69de3c6a PP |
1737 | bp_overlay_event); |
1738 | b->addr_string = xstrdup (func_name); | |
e62c965a | 1739 | |
69de3c6a PP |
1740 | if (overlay_debugging == ovly_auto) |
1741 | { | |
1742 | b->enable_state = bp_enabled; | |
1743 | overlay_events_enabled = 1; | |
1744 | } | |
1745 | else | |
1746 | { | |
1747 | b->enable_state = bp_disabled; | |
1748 | overlay_events_enabled = 0; | |
1749 | } | |
e62c965a PP |
1750 | } |
1751 | update_global_location_list (1); | |
1752 | } | |
1753 | ||
0fd8e87f UW |
1754 | static void |
1755 | create_longjmp_master_breakpoint (char *func_name) | |
1756 | { | |
6c95b8df | 1757 | struct program_space *pspace; |
0fd8e87f | 1758 | struct objfile *objfile; |
6c95b8df PA |
1759 | struct cleanup *old_chain; |
1760 | ||
1761 | old_chain = save_current_program_space (); | |
0fd8e87f | 1762 | |
6c95b8df | 1763 | ALL_PSPACES (pspace) |
0fd8e87f UW |
1764 | ALL_OBJFILES (objfile) |
1765 | { | |
1766 | struct breakpoint *b; | |
1767 | struct minimal_symbol *m; | |
1768 | ||
1769 | if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile))) | |
1770 | continue; | |
1771 | ||
6c95b8df PA |
1772 | set_current_program_space (pspace); |
1773 | ||
0fd8e87f UW |
1774 | m = lookup_minimal_symbol_text (func_name, objfile); |
1775 | if (m == NULL) | |
1776 | continue; | |
1777 | ||
a6d9a66e UW |
1778 | b = create_internal_breakpoint (get_objfile_arch (objfile), |
1779 | SYMBOL_VALUE_ADDRESS (m), | |
0fd8e87f UW |
1780 | bp_longjmp_master); |
1781 | b->addr_string = xstrdup (func_name); | |
1782 | b->enable_state = bp_disabled; | |
1783 | } | |
1784 | update_global_location_list (1); | |
6c95b8df PA |
1785 | |
1786 | do_cleanups (old_chain); | |
0fd8e87f UW |
1787 | } |
1788 | ||
c906108c | 1789 | void |
fba45db2 | 1790 | update_breakpoints_after_exec (void) |
c906108c | 1791 | { |
c5aa993b JM |
1792 | struct breakpoint *b; |
1793 | struct breakpoint *temp; | |
876fa593 | 1794 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 1795 | |
25b22b0a PA |
1796 | /* We're about to delete breakpoints from GDB's lists. If the |
1797 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
1798 | writing the breakpoints' "shadow contents" back into memory. The | |
1799 | "shadow contents" are NOT valid after an exec, so GDB should not | |
1800 | do that. Instead, the target is responsible from marking | |
1801 | breakpoints out as soon as it detects an exec. We don't do that | |
1802 | here instead, because there may be other attempts to delete | |
1803 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 1804 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
1805 | if (bploc->pspace == current_program_space) |
1806 | gdb_assert (!bploc->inserted); | |
c906108c SS |
1807 | |
1808 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b | 1809 | { |
6c95b8df PA |
1810 | if (b->pspace != current_program_space) |
1811 | continue; | |
1812 | ||
c5aa993b JM |
1813 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
1814 | if (b->type == bp_shlib_event) | |
1815 | { | |
1816 | delete_breakpoint (b); | |
1817 | continue; | |
1818 | } | |
c906108c | 1819 | |
4efc6507 DE |
1820 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
1821 | if (b->type == bp_jit_event) | |
1822 | { | |
1823 | delete_breakpoint (b); | |
1824 | continue; | |
1825 | } | |
1826 | ||
1900040c | 1827 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
1828 | as must overlay event and longjmp master breakpoints. */ |
1829 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
1830 | || b->type == bp_longjmp_master) | |
c4093a6a JM |
1831 | { |
1832 | delete_breakpoint (b); | |
1833 | continue; | |
1834 | } | |
1835 | ||
c5aa993b JM |
1836 | /* Step-resume breakpoints are meaningless after an exec(). */ |
1837 | if (b->type == bp_step_resume) | |
1838 | { | |
1839 | delete_breakpoint (b); | |
1840 | continue; | |
1841 | } | |
1842 | ||
611c83ae PA |
1843 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
1844 | after an exec. */ | |
1845 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume) | |
1846 | { | |
1847 | delete_breakpoint (b); | |
1848 | continue; | |
1849 | } | |
1850 | ||
ce78b96d JB |
1851 | if (b->type == bp_catchpoint) |
1852 | { | |
1853 | /* For now, none of the bp_catchpoint breakpoints need to | |
1854 | do anything at this point. In the future, if some of | |
1855 | the catchpoints need to something, we will need to add | |
1856 | a new method, and call this method from here. */ | |
1857 | continue; | |
1858 | } | |
1859 | ||
c5aa993b JM |
1860 | /* bp_finish is a special case. The only way we ought to be able |
1861 | to see one of these when an exec() has happened, is if the user | |
1862 | caught a vfork, and then said "finish". Ordinarily a finish just | |
1863 | carries them to the call-site of the current callee, by setting | |
1864 | a temporary bp there and resuming. But in this case, the finish | |
1865 | will carry them entirely through the vfork & exec. | |
1866 | ||
1867 | We don't want to allow a bp_finish to remain inserted now. But | |
1868 | we can't safely delete it, 'cause finish_command has a handle to | |
1869 | the bp on a bpstat, and will later want to delete it. There's a | |
1870 | chance (and I've seen it happen) that if we delete the bp_finish | |
1871 | here, that its storage will get reused by the time finish_command | |
1872 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
1873 | We really must allow finish_command to delete a bp_finish. | |
1874 | ||
53a5351d JM |
1875 | In the absense of a general solution for the "how do we know |
1876 | it's safe to delete something others may have handles to?" | |
1877 | problem, what we'll do here is just uninsert the bp_finish, and | |
1878 | let finish_command delete it. | |
1879 | ||
1880 | (We know the bp_finish is "doomed" in the sense that it's | |
1881 | momentary, and will be deleted as soon as finish_command sees | |
1882 | the inferior stopped. So it doesn't matter that the bp's | |
1883 | address is probably bogus in the new a.out, unlike e.g., the | |
1884 | solib breakpoints.) */ | |
c5aa993b | 1885 | |
c5aa993b JM |
1886 | if (b->type == bp_finish) |
1887 | { | |
1888 | continue; | |
1889 | } | |
1890 | ||
1891 | /* Without a symbolic address, we have little hope of the | |
1892 | pre-exec() address meaning the same thing in the post-exec() | |
1893 | a.out. */ | |
1894 | if (b->addr_string == NULL) | |
1895 | { | |
1896 | delete_breakpoint (b); | |
1897 | continue; | |
1898 | } | |
c5aa993b | 1899 | } |
1900040c | 1900 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
69de3c6a | 1901 | create_overlay_event_breakpoint ("_ovly_debug_event"); |
0fd8e87f UW |
1902 | create_longjmp_master_breakpoint ("longjmp"); |
1903 | create_longjmp_master_breakpoint ("_longjmp"); | |
1904 | create_longjmp_master_breakpoint ("siglongjmp"); | |
1905 | create_longjmp_master_breakpoint ("_siglongjmp"); | |
c906108c SS |
1906 | } |
1907 | ||
1908 | int | |
fba45db2 | 1909 | detach_breakpoints (int pid) |
c906108c | 1910 | { |
876fa593 | 1911 | struct bp_location *b, **bp_tmp; |
3a1bae8e | 1912 | int val = 0; |
ce696e05 | 1913 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 1914 | struct inferior *inf = current_inferior (); |
c5aa993b | 1915 | |
39f77062 | 1916 | if (pid == PIDGET (inferior_ptid)) |
8a3fe4f8 | 1917 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 1918 | |
6c95b8df | 1919 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
ce696e05 | 1920 | inferior_ptid = pid_to_ptid (pid); |
876fa593 | 1921 | ALL_BP_LOCATIONS (b, bp_tmp) |
c5aa993b | 1922 | { |
6c95b8df PA |
1923 | if (b->pspace != inf->pspace) |
1924 | continue; | |
1925 | ||
0bde7532 | 1926 | if (b->inserted) |
6c95b8df | 1927 | val |= remove_breakpoint_1 (b, mark_inserted); |
c5aa993b | 1928 | } |
ce696e05 | 1929 | do_cleanups (old_chain); |
3a1bae8e | 1930 | return val; |
c906108c SS |
1931 | } |
1932 | ||
6c95b8df PA |
1933 | /* Remove the breakpoint location B from the current address space. |
1934 | Note that this is used to detach breakpoints from a child fork. | |
1935 | When we get here, the child isn't in the inferior list, and neither | |
1936 | do we have objects to represent its address space --- we should | |
1937 | *not* look at b->pspace->aspace here. */ | |
1938 | ||
c906108c | 1939 | static int |
6c95b8df | 1940 | remove_breakpoint_1 (struct bp_location *b, insertion_state_t is) |
c906108c SS |
1941 | { |
1942 | int val; | |
6c95b8df | 1943 | struct cleanup *old_chain; |
c5aa993b | 1944 | |
0bde7532 | 1945 | if (b->owner->enable_state == bp_permanent) |
c2c6d25f JM |
1946 | /* Permanent breakpoints cannot be inserted or removed. */ |
1947 | return 0; | |
1948 | ||
74960c60 VP |
1949 | /* The type of none suggests that owner is actually deleted. |
1950 | This should not ever happen. */ | |
1951 | gdb_assert (b->owner->type != bp_none); | |
0bde7532 DJ |
1952 | |
1953 | if (b->loc_type == bp_loc_software_breakpoint | |
1954 | || b->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 1955 | { |
c02f5703 MS |
1956 | /* "Normal" instruction breakpoint: either the standard |
1957 | trap-instruction bp (bp_breakpoint), or a | |
1958 | bp_hardware_breakpoint. */ | |
1959 | ||
1960 | /* First check to see if we have to handle an overlay. */ | |
1961 | if (overlay_debugging == ovly_off | |
0bde7532 DJ |
1962 | || b->section == NULL |
1963 | || !(section_is_overlay (b->section))) | |
c02f5703 MS |
1964 | { |
1965 | /* No overlay handling: just remove the breakpoint. */ | |
1966 | ||
0bde7532 | 1967 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e | 1968 | val = target_remove_hw_breakpoint (b->gdbarch, &b->target_info); |
c02f5703 | 1969 | else |
a6d9a66e | 1970 | val = target_remove_breakpoint (b->gdbarch, &b->target_info); |
c02f5703 | 1971 | } |
c906108c SS |
1972 | else |
1973 | { | |
c02f5703 MS |
1974 | /* This breakpoint is in an overlay section. |
1975 | Did we set a breakpoint at the LMA? */ | |
1976 | if (!overlay_events_enabled) | |
1977 | { | |
1978 | /* Yes -- overlay event support is not active, so we | |
1979 | should have set a breakpoint at the LMA. Remove it. | |
1980 | */ | |
c02f5703 MS |
1981 | /* Ignore any failures: if the LMA is in ROM, we will |
1982 | have already warned when we failed to insert it. */ | |
0bde7532 | 1983 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e UW |
1984 | target_remove_hw_breakpoint (b->gdbarch, |
1985 | &b->overlay_target_info); | |
c02f5703 | 1986 | else |
a6d9a66e UW |
1987 | target_remove_breakpoint (b->gdbarch, |
1988 | &b->overlay_target_info); | |
c02f5703 MS |
1989 | } |
1990 | /* Did we set a breakpoint at the VMA? | |
1991 | If so, we will have marked the breakpoint 'inserted'. */ | |
0bde7532 | 1992 | if (b->inserted) |
c906108c | 1993 | { |
c02f5703 MS |
1994 | /* Yes -- remove it. Previously we did not bother to |
1995 | remove the breakpoint if the section had been | |
1996 | unmapped, but let's not rely on that being safe. We | |
1997 | don't know what the overlay manager might do. */ | |
0bde7532 | 1998 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e UW |
1999 | val = target_remove_hw_breakpoint (b->gdbarch, |
2000 | &b->target_info); | |
aa67235e UW |
2001 | |
2002 | /* However, we should remove *software* breakpoints only | |
2003 | if the section is still mapped, or else we overwrite | |
2004 | wrong code with the saved shadow contents. */ | |
2005 | else if (section_is_mapped (b->section)) | |
a6d9a66e UW |
2006 | val = target_remove_breakpoint (b->gdbarch, |
2007 | &b->target_info); | |
aa67235e UW |
2008 | else |
2009 | val = 0; | |
c906108c | 2010 | } |
c02f5703 MS |
2011 | else |
2012 | { | |
2013 | /* No -- not inserted, so no need to remove. No error. */ | |
2014 | val = 0; | |
2015 | } | |
c906108c | 2016 | } |
879d1e6b UW |
2017 | |
2018 | /* In some cases, we might not be able to remove a breakpoint | |
2019 | in a shared library that has already been removed, but we | |
2020 | have not yet processed the shlib unload event. */ | |
6c95b8df | 2021 | if (val && solib_name_from_address (b->pspace, b->address)) |
879d1e6b UW |
2022 | val = 0; |
2023 | ||
c906108c SS |
2024 | if (val) |
2025 | return val; | |
0bde7532 | 2026 | b->inserted = (is == mark_inserted); |
c906108c | 2027 | } |
a5606eee | 2028 | else if (b->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 2029 | { |
278cd55f AC |
2030 | struct value *v; |
2031 | struct value *n; | |
c5aa993b | 2032 | |
0bde7532 | 2033 | b->inserted = (is == mark_inserted); |
a5606eee VP |
2034 | val = target_remove_watchpoint (b->address, b->length, |
2035 | b->watchpoint_type); | |
2e70b7b9 | 2036 | |
c906108c | 2037 | /* Failure to remove any of the hardware watchpoints comes here. */ |
0bde7532 | 2038 | if ((is == mark_uninserted) && (b->inserted)) |
8a3fe4f8 | 2039 | warning (_("Could not remove hardware watchpoint %d."), |
0bde7532 | 2040 | b->owner->number); |
c906108c | 2041 | } |
ce78b96d JB |
2042 | else if (b->owner->type == bp_catchpoint |
2043 | && breakpoint_enabled (b->owner) | |
2044 | && !b->duplicate) | |
2045 | { | |
2046 | gdb_assert (b->owner->ops != NULL && b->owner->ops->remove != NULL); | |
2047 | ||
2048 | val = b->owner->ops->remove (b->owner); | |
2049 | if (val) | |
2050 | return val; | |
2051 | b->inserted = (is == mark_inserted); | |
2052 | } | |
c906108c SS |
2053 | |
2054 | return 0; | |
2055 | } | |
2056 | ||
6c95b8df PA |
2057 | static int |
2058 | remove_breakpoint (struct bp_location *b, insertion_state_t is) | |
2059 | { | |
2060 | int ret; | |
2061 | struct cleanup *old_chain; | |
2062 | ||
2063 | if (b->owner->enable_state == bp_permanent) | |
2064 | /* Permanent breakpoints cannot be inserted or removed. */ | |
2065 | return 0; | |
2066 | ||
2067 | /* The type of none suggests that owner is actually deleted. | |
2068 | This should not ever happen. */ | |
2069 | gdb_assert (b->owner->type != bp_none); | |
2070 | ||
2071 | old_chain = save_current_space_and_thread (); | |
2072 | ||
2073 | switch_to_program_space_and_thread (b->pspace); | |
2074 | ||
2075 | ret = remove_breakpoint_1 (b, is); | |
2076 | ||
2077 | do_cleanups (old_chain); | |
2078 | return ret; | |
2079 | } | |
2080 | ||
c906108c SS |
2081 | /* Clear the "inserted" flag in all breakpoints. */ |
2082 | ||
25b22b0a | 2083 | void |
fba45db2 | 2084 | mark_breakpoints_out (void) |
c906108c | 2085 | { |
876fa593 | 2086 | struct bp_location *bpt, **bptp_tmp; |
c906108c | 2087 | |
876fa593 | 2088 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
6c95b8df PA |
2089 | if (bpt->pspace == current_program_space) |
2090 | bpt->inserted = 0; | |
c906108c SS |
2091 | } |
2092 | ||
53a5351d JM |
2093 | /* Clear the "inserted" flag in all breakpoints and delete any |
2094 | breakpoints which should go away between runs of the program. | |
c906108c SS |
2095 | |
2096 | Plus other such housekeeping that has to be done for breakpoints | |
2097 | between runs. | |
2098 | ||
53a5351d JM |
2099 | Note: this function gets called at the end of a run (by |
2100 | generic_mourn_inferior) and when a run begins (by | |
2101 | init_wait_for_inferior). */ | |
c906108c SS |
2102 | |
2103 | ||
2104 | ||
2105 | void | |
fba45db2 | 2106 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 2107 | { |
52f0bd74 | 2108 | struct breakpoint *b, *temp; |
876fa593 | 2109 | struct bp_location *bpt, **bptp_tmp; |
1c5cfe86 | 2110 | int ix; |
6c95b8df | 2111 | struct program_space *pspace = current_program_space; |
c906108c | 2112 | |
50c71eaf PA |
2113 | /* If breakpoint locations are shared across processes, then there's |
2114 | nothing to do. */ | |
2567c7d9 | 2115 | if (gdbarch_has_global_breakpoints (target_gdbarch)) |
50c71eaf PA |
2116 | return; |
2117 | ||
876fa593 | 2118 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
6c95b8df PA |
2119 | { |
2120 | if (bpt->pspace == pspace | |
2121 | && bpt->owner->enable_state != bp_permanent) | |
514f746b | 2122 | bpt->inserted = 0; |
6c95b8df | 2123 | } |
075f6582 | 2124 | |
c906108c | 2125 | ALL_BREAKPOINTS_SAFE (b, temp) |
c5aa993b | 2126 | { |
6c95b8df PA |
2127 | if (b->loc && b->loc->pspace != pspace) |
2128 | continue; | |
2129 | ||
c5aa993b JM |
2130 | switch (b->type) |
2131 | { | |
2132 | case bp_call_dummy: | |
2133 | case bp_watchpoint_scope: | |
c906108c | 2134 | |
c5aa993b JM |
2135 | /* If the call dummy breakpoint is at the entry point it will |
2136 | cause problems when the inferior is rerun, so we better | |
2137 | get rid of it. | |
c906108c | 2138 | |
c5aa993b JM |
2139 | Also get rid of scope breakpoints. */ |
2140 | delete_breakpoint (b); | |
2141 | break; | |
c906108c | 2142 | |
c5aa993b JM |
2143 | case bp_watchpoint: |
2144 | case bp_hardware_watchpoint: | |
2145 | case bp_read_watchpoint: | |
2146 | case bp_access_watchpoint: | |
c906108c | 2147 | |
c5aa993b JM |
2148 | /* Likewise for watchpoints on local expressions. */ |
2149 | if (b->exp_valid_block != NULL) | |
2150 | delete_breakpoint (b); | |
967af18d | 2151 | else if (context == inf_starting) |
c860120c PM |
2152 | { |
2153 | /* Reset val field to force reread of starting value | |
2154 | in insert_breakpoints. */ | |
2155 | if (b->val) | |
2156 | value_free (b->val); | |
2157 | b->val = NULL; | |
fa4727a6 | 2158 | b->val_valid = 0; |
c860120c | 2159 | } |
c5aa993b JM |
2160 | break; |
2161 | default: | |
c5aa993b JM |
2162 | break; |
2163 | } | |
2164 | } | |
1c5cfe86 PA |
2165 | |
2166 | /* Get rid of the moribund locations. */ | |
2167 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bpt); ++ix) | |
2168 | free_bp_location (bpt); | |
2169 | VEC_free (bp_location_p, moribund_locations); | |
c906108c SS |
2170 | } |
2171 | ||
6c95b8df PA |
2172 | /* These functions concern about actual breakpoints inserted in the |
2173 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
2174 | we need to hop over the bkpt --- so we check for address space | |
2175 | match, not program space. */ | |
2176 | ||
c2c6d25f JM |
2177 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
2178 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
2179 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
2180 | permanent breakpoint. | |
2181 | - When continuing from a location with an ordinary breakpoint, we | |
2182 | actually single step once before calling insert_breakpoints. | |
2183 | - When continuing from a localion with a permanent breakpoint, we | |
2184 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by | |
2185 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 2186 | |
c2c6d25f | 2187 | enum breakpoint_here |
6c95b8df | 2188 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 2189 | { |
876fa593 | 2190 | struct bp_location *bpt, **bptp_tmp; |
c2c6d25f | 2191 | int any_breakpoint_here = 0; |
c906108c | 2192 | |
876fa593 | 2193 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
075f6582 DJ |
2194 | { |
2195 | if (bpt->loc_type != bp_loc_software_breakpoint | |
2196 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
2197 | continue; | |
2198 | ||
468d015d | 2199 | if ((breakpoint_enabled (bpt->owner) |
075f6582 | 2200 | || bpt->owner->enable_state == bp_permanent) |
6c95b8df PA |
2201 | && breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2202 | aspace, pc)) | |
075f6582 DJ |
2203 | { |
2204 | if (overlay_debugging | |
2205 | && section_is_overlay (bpt->section) | |
2206 | && !section_is_mapped (bpt->section)) | |
2207 | continue; /* unmapped overlay -- can't be a match */ | |
2208 | else if (bpt->owner->enable_state == bp_permanent) | |
2209 | return permanent_breakpoint_here; | |
2210 | else | |
2211 | any_breakpoint_here = 1; | |
2212 | } | |
2213 | } | |
c906108c | 2214 | |
c2c6d25f | 2215 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
2216 | } |
2217 | ||
1c5cfe86 PA |
2218 | /* Return true if there's a moribund breakpoint at PC. */ |
2219 | ||
2220 | int | |
6c95b8df | 2221 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
2222 | { |
2223 | struct bp_location *loc; | |
2224 | int ix; | |
2225 | ||
2226 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
6c95b8df PA |
2227 | if (breakpoint_address_match (loc->pspace->aspace, loc->address, |
2228 | aspace, pc)) | |
1c5cfe86 PA |
2229 | return 1; |
2230 | ||
2231 | return 0; | |
2232 | } | |
c2c6d25f | 2233 | |
c36b740a | 2234 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
876fa593 | 2235 | inserted using regular breakpoint_chain / bp_location array mechanism. |
c36b740a VP |
2236 | This does not check for single-step breakpoints, which are |
2237 | inserted and removed using direct target manipulation. */ | |
c906108c SS |
2238 | |
2239 | int | |
6c95b8df | 2240 | regular_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 2241 | { |
876fa593 | 2242 | struct bp_location *bpt, **bptp_tmp; |
c906108c | 2243 | |
876fa593 | 2244 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
c5aa993b | 2245 | { |
075f6582 DJ |
2246 | if (bpt->loc_type != bp_loc_software_breakpoint |
2247 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
2248 | continue; | |
2249 | ||
2250 | if (bpt->inserted | |
6c95b8df PA |
2251 | && breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2252 | aspace, pc)) | |
075f6582 DJ |
2253 | { |
2254 | if (overlay_debugging | |
2255 | && section_is_overlay (bpt->section) | |
2256 | && !section_is_mapped (bpt->section)) | |
2257 | continue; /* unmapped overlay -- can't be a match */ | |
2258 | else | |
2259 | return 1; | |
2260 | } | |
c5aa993b | 2261 | } |
c36b740a VP |
2262 | return 0; |
2263 | } | |
2264 | ||
2265 | /* Returns non-zero iff there's either regular breakpoint | |
2266 | or a single step breakpoint inserted at PC. */ | |
2267 | ||
2268 | int | |
6c95b8df | 2269 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c36b740a | 2270 | { |
6c95b8df | 2271 | if (regular_breakpoint_inserted_here_p (aspace, pc)) |
c36b740a | 2272 | return 1; |
c906108c | 2273 | |
6c95b8df | 2274 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2275 | return 1; |
2276 | ||
c906108c SS |
2277 | return 0; |
2278 | } | |
2279 | ||
4fa8626c DJ |
2280 | /* This function returns non-zero iff there is a software breakpoint |
2281 | inserted at PC. */ | |
2282 | ||
2283 | int | |
6c95b8df | 2284 | software_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
4fa8626c | 2285 | { |
876fa593 | 2286 | struct bp_location *bpt, **bptp_tmp; |
4fa8626c DJ |
2287 | int any_breakpoint_here = 0; |
2288 | ||
876fa593 | 2289 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
4fa8626c DJ |
2290 | { |
2291 | if (bpt->loc_type != bp_loc_software_breakpoint) | |
2292 | continue; | |
2293 | ||
0d381245 | 2294 | if (bpt->inserted |
6c95b8df PA |
2295 | && breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2296 | aspace, pc)) | |
4fa8626c DJ |
2297 | { |
2298 | if (overlay_debugging | |
2299 | && section_is_overlay (bpt->section) | |
2300 | && !section_is_mapped (bpt->section)) | |
2301 | continue; /* unmapped overlay -- can't be a match */ | |
2302 | else | |
2303 | return 1; | |
2304 | } | |
2305 | } | |
2306 | ||
1aafd4da | 2307 | /* Also check for software single-step breakpoints. */ |
6c95b8df | 2308 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2309 | return 1; |
2310 | ||
4fa8626c DJ |
2311 | return 0; |
2312 | } | |
2313 | ||
075f6582 DJ |
2314 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
2315 | PC is valid for process/thread PTID. */ | |
c906108c SS |
2316 | |
2317 | int | |
6c95b8df PA |
2318 | breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc, |
2319 | ptid_t ptid) | |
c906108c | 2320 | { |
876fa593 | 2321 | struct bp_location *bpt, **bptp_tmp; |
4a306c9a | 2322 | /* The thread and task IDs associated to PTID, computed lazily. */ |
a6f1cd96 | 2323 | int thread = -1; |
4a306c9a | 2324 | int task = 0; |
a6f1cd96 | 2325 | |
876fa593 | 2326 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
c5aa993b | 2327 | { |
075f6582 DJ |
2328 | if (bpt->loc_type != bp_loc_software_breakpoint |
2329 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
2330 | continue; | |
2331 | ||
a6f1cd96 JB |
2332 | if (!breakpoint_enabled (bpt->owner) |
2333 | && bpt->owner->enable_state != bp_permanent) | |
2334 | continue; | |
2335 | ||
6c95b8df PA |
2336 | if (!breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2337 | aspace, pc)) | |
a6f1cd96 JB |
2338 | continue; |
2339 | ||
2340 | if (bpt->owner->thread != -1) | |
075f6582 | 2341 | { |
a6f1cd96 JB |
2342 | /* This is a thread-specific breakpoint. Check that ptid |
2343 | matches that thread. If thread hasn't been computed yet, | |
2344 | it is now time to do so. */ | |
2345 | if (thread == -1) | |
2346 | thread = pid_to_thread_id (ptid); | |
2347 | if (bpt->owner->thread != thread) | |
2348 | continue; | |
075f6582 | 2349 | } |
a6f1cd96 | 2350 | |
4a306c9a JB |
2351 | if (bpt->owner->task != 0) |
2352 | { | |
2353 | /* This is a task-specific breakpoint. Check that ptid | |
2354 | matches that task. If task hasn't been computed yet, | |
2355 | it is now time to do so. */ | |
2356 | if (task == 0) | |
2357 | task = ada_get_task_number (ptid); | |
2358 | if (bpt->owner->task != task) | |
2359 | continue; | |
2360 | } | |
2361 | ||
a6f1cd96 JB |
2362 | if (overlay_debugging |
2363 | && section_is_overlay (bpt->section) | |
2364 | && !section_is_mapped (bpt->section)) | |
2365 | continue; /* unmapped overlay -- can't be a match */ | |
2366 | ||
2367 | return 1; | |
c5aa993b | 2368 | } |
c906108c SS |
2369 | |
2370 | return 0; | |
2371 | } | |
c906108c | 2372 | \f |
c5aa993b | 2373 | |
c906108c SS |
2374 | /* bpstat stuff. External routines' interfaces are documented |
2375 | in breakpoint.h. */ | |
2376 | ||
2377 | int | |
fba45db2 | 2378 | ep_is_catchpoint (struct breakpoint *ep) |
c906108c | 2379 | { |
533be4dd | 2380 | return (ep->type == bp_catchpoint); |
c906108c SS |
2381 | } |
2382 | ||
198757a8 VP |
2383 | void |
2384 | bpstat_free (bpstat bs) | |
2385 | { | |
2386 | if (bs->old_val != NULL) | |
2387 | value_free (bs->old_val); | |
2388 | free_command_lines (&bs->commands); | |
2389 | xfree (bs); | |
2390 | } | |
2391 | ||
c906108c SS |
2392 | /* Clear a bpstat so that it says we are not at any breakpoint. |
2393 | Also free any storage that is part of a bpstat. */ | |
2394 | ||
2395 | void | |
fba45db2 | 2396 | bpstat_clear (bpstat *bsp) |
c906108c SS |
2397 | { |
2398 | bpstat p; | |
2399 | bpstat q; | |
2400 | ||
2401 | if (bsp == 0) | |
2402 | return; | |
2403 | p = *bsp; | |
2404 | while (p != NULL) | |
2405 | { | |
2406 | q = p->next; | |
198757a8 | 2407 | bpstat_free (p); |
c906108c SS |
2408 | p = q; |
2409 | } | |
2410 | *bsp = NULL; | |
2411 | } | |
2412 | ||
2413 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
2414 | is part of the bpstat is copied as well. */ | |
2415 | ||
2416 | bpstat | |
fba45db2 | 2417 | bpstat_copy (bpstat bs) |
c906108c SS |
2418 | { |
2419 | bpstat p = NULL; | |
2420 | bpstat tmp; | |
2421 | bpstat retval = NULL; | |
2422 | ||
2423 | if (bs == NULL) | |
2424 | return bs; | |
2425 | ||
2426 | for (; bs != NULL; bs = bs->next) | |
2427 | { | |
2428 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
2429 | memcpy (tmp, bs, sizeof (*tmp)); | |
31cc81e9 DJ |
2430 | if (bs->commands != NULL) |
2431 | tmp->commands = copy_command_lines (bs->commands); | |
2432 | if (bs->old_val != NULL) | |
3c3185ac JK |
2433 | { |
2434 | tmp->old_val = value_copy (bs->old_val); | |
2435 | release_value (tmp->old_val); | |
2436 | } | |
31cc81e9 | 2437 | |
c906108c SS |
2438 | if (p == NULL) |
2439 | /* This is the first thing in the chain. */ | |
2440 | retval = tmp; | |
2441 | else | |
2442 | p->next = tmp; | |
2443 | p = tmp; | |
2444 | } | |
2445 | p->next = NULL; | |
2446 | return retval; | |
2447 | } | |
2448 | ||
2449 | /* Find the bpstat associated with this breakpoint */ | |
2450 | ||
2451 | bpstat | |
fba45db2 | 2452 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 2453 | { |
c5aa993b JM |
2454 | if (bsp == NULL) |
2455 | return NULL; | |
c906108c | 2456 | |
c5aa993b JM |
2457 | for (; bsp != NULL; bsp = bsp->next) |
2458 | { | |
4f8d1dc6 | 2459 | if (bsp->breakpoint_at && bsp->breakpoint_at->owner == breakpoint) |
c5aa993b JM |
2460 | return bsp; |
2461 | } | |
c906108c SS |
2462 | return NULL; |
2463 | } | |
2464 | ||
2465 | /* Find a step_resume breakpoint associated with this bpstat. | |
2466 | (If there are multiple step_resume bp's on the list, this function | |
2467 | will arbitrarily pick one.) | |
2468 | ||
2469 | It is an error to use this function if BPSTAT doesn't contain a | |
2470 | step_resume breakpoint. | |
2471 | ||
2472 | See wait_for_inferior's use of this function. */ | |
2473 | struct breakpoint * | |
fba45db2 | 2474 | bpstat_find_step_resume_breakpoint (bpstat bsp) |
c906108c | 2475 | { |
8601f500 MS |
2476 | int current_thread; |
2477 | ||
8a3fe4f8 | 2478 | gdb_assert (bsp != NULL); |
c906108c | 2479 | |
8601f500 MS |
2480 | current_thread = pid_to_thread_id (inferior_ptid); |
2481 | ||
c906108c SS |
2482 | for (; bsp != NULL; bsp = bsp->next) |
2483 | { | |
059fb39f PM |
2484 | if ((bsp->breakpoint_at != NULL) |
2485 | && (bsp->breakpoint_at->owner->type == bp_step_resume) | |
2486 | && (bsp->breakpoint_at->owner->thread == current_thread | |
2487 | || bsp->breakpoint_at->owner->thread == -1)) | |
4f8d1dc6 | 2488 | return bsp->breakpoint_at->owner; |
c906108c SS |
2489 | } |
2490 | ||
8a3fe4f8 | 2491 | internal_error (__FILE__, __LINE__, _("No step_resume breakpoint found.")); |
c906108c SS |
2492 | } |
2493 | ||
2494 | ||
8671a17b | 2495 | /* Put in *NUM the breakpoint number of the first breakpoint we are stopped |
c906108c SS |
2496 | at. *BSP upon return is a bpstat which points to the remaining |
2497 | breakpoints stopped at (but which is not guaranteed to be good for | |
2498 | anything but further calls to bpstat_num). | |
8671a17b PA |
2499 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
2500 | Return -1 if stopped at a breakpoint that has been deleted since | |
2501 | we set it. | |
2502 | Return 1 otherwise. */ | |
c906108c SS |
2503 | |
2504 | int | |
8671a17b | 2505 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
2506 | { |
2507 | struct breakpoint *b; | |
2508 | ||
2509 | if ((*bsp) == NULL) | |
2510 | return 0; /* No more breakpoint values */ | |
8671a17b | 2511 | |
4f8d1dc6 VP |
2512 | /* We assume we'll never have several bpstats that |
2513 | correspond to a single breakpoint -- otherwise, | |
2514 | this function might return the same number more | |
2515 | than once and this will look ugly. */ | |
2516 | b = (*bsp)->breakpoint_at ? (*bsp)->breakpoint_at->owner : NULL; | |
8671a17b PA |
2517 | *bsp = (*bsp)->next; |
2518 | if (b == NULL) | |
2519 | return -1; /* breakpoint that's been deleted since */ | |
2520 | ||
2521 | *num = b->number; /* We have its number */ | |
2522 | return 1; | |
c906108c SS |
2523 | } |
2524 | ||
2525 | /* Modify BS so that the actions will not be performed. */ | |
2526 | ||
2527 | void | |
fba45db2 | 2528 | bpstat_clear_actions (bpstat bs) |
c906108c SS |
2529 | { |
2530 | for (; bs != NULL; bs = bs->next) | |
2531 | { | |
c2b8ed2c | 2532 | free_command_lines (&bs->commands); |
c906108c SS |
2533 | if (bs->old_val != NULL) |
2534 | { | |
2535 | value_free (bs->old_val); | |
2536 | bs->old_val = NULL; | |
2537 | } | |
2538 | } | |
2539 | } | |
2540 | ||
f3b1572e PA |
2541 | /* Called when a command is about to proceed the inferior. */ |
2542 | ||
2543 | static void | |
2544 | breakpoint_about_to_proceed (void) | |
2545 | { | |
2546 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
2547 | { | |
2548 | struct thread_info *tp = inferior_thread (); | |
2549 | ||
2550 | /* Allow inferior function calls in breakpoint commands to not | |
2551 | interrupt the command list. When the call finishes | |
2552 | successfully, the inferior will be standing at the same | |
2553 | breakpoint as if nothing happened. */ | |
2554 | if (tp->in_infcall) | |
2555 | return; | |
2556 | } | |
2557 | ||
2558 | breakpoint_proceeded = 1; | |
2559 | } | |
2560 | ||
c906108c | 2561 | /* Stub for cleaning up our state if we error-out of a breakpoint command */ |
c906108c | 2562 | static void |
4efb68b1 | 2563 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
2564 | { |
2565 | executing_breakpoint_commands = 0; | |
2566 | } | |
2567 | ||
2568 | /* Execute all the commands associated with all the breakpoints at this | |
2569 | location. Any of these commands could cause the process to proceed | |
2570 | beyond this point, etc. We look out for such changes by checking | |
347bddb7 | 2571 | the global "breakpoint_proceeded" after each command. |
c906108c | 2572 | |
347bddb7 PA |
2573 | Returns true if a breakpoint command resumed the inferior. In that |
2574 | case, it is the caller's responsibility to recall it again with the | |
2575 | bpstat of the current thread. */ | |
2576 | ||
2577 | static int | |
2578 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
2579 | { |
2580 | bpstat bs; | |
2581 | struct cleanup *old_chain; | |
347bddb7 | 2582 | int again = 0; |
c906108c SS |
2583 | |
2584 | /* Avoid endless recursion if a `source' command is contained | |
2585 | in bs->commands. */ | |
2586 | if (executing_breakpoint_commands) | |
347bddb7 | 2587 | return 0; |
c906108c SS |
2588 | |
2589 | executing_breakpoint_commands = 1; | |
2590 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
2591 | ||
c906108c SS |
2592 | /* This pointer will iterate over the list of bpstat's. */ |
2593 | bs = *bsp; | |
2594 | ||
2595 | breakpoint_proceeded = 0; | |
2596 | for (; bs != NULL; bs = bs->next) | |
2597 | { | |
6c50ab1c JB |
2598 | struct command_line *cmd; |
2599 | struct cleanup *this_cmd_tree_chain; | |
2600 | ||
2601 | /* Take ownership of the BSP's command tree, if it has one. | |
2602 | ||
2603 | The command tree could legitimately contain commands like | |
2604 | 'step' and 'next', which call clear_proceed_status, which | |
2605 | frees stop_bpstat's command tree. To make sure this doesn't | |
2606 | free the tree we're executing out from under us, we need to | |
2607 | take ownership of the tree ourselves. Since a given bpstat's | |
2608 | commands are only executed once, we don't need to copy it; we | |
2609 | can clear the pointer in the bpstat, and make sure we free | |
2610 | the tree when we're done. */ | |
c906108c | 2611 | cmd = bs->commands; |
6c50ab1c JB |
2612 | bs->commands = 0; |
2613 | this_cmd_tree_chain = make_cleanup_free_command_lines (&cmd); | |
2614 | ||
c906108c SS |
2615 | while (cmd != NULL) |
2616 | { | |
2617 | execute_control_command (cmd); | |
2618 | ||
2619 | if (breakpoint_proceeded) | |
2620 | break; | |
2621 | else | |
2622 | cmd = cmd->next; | |
2623 | } | |
6c50ab1c JB |
2624 | |
2625 | /* We can free this command tree now. */ | |
2626 | do_cleanups (this_cmd_tree_chain); | |
2627 | ||
c906108c | 2628 | if (breakpoint_proceeded) |
32c1e744 VP |
2629 | { |
2630 | if (target_can_async_p ()) | |
347bddb7 PA |
2631 | /* If we are in async mode, then the target might be still |
2632 | running, not stopped at any breakpoint, so nothing for | |
2633 | us to do here -- just return to the event loop. */ | |
2634 | ; | |
32c1e744 VP |
2635 | else |
2636 | /* In sync mode, when execute_control_command returns | |
2637 | we're already standing on the next breakpoint. | |
347bddb7 PA |
2638 | Breakpoint commands for that stop were not run, since |
2639 | execute_command does not run breakpoint commands -- | |
2640 | only command_line_handler does, but that one is not | |
2641 | involved in execution of breakpoint commands. So, we | |
2642 | can now execute breakpoint commands. It should be | |
2643 | noted that making execute_command do bpstat actions is | |
2644 | not an option -- in this case we'll have recursive | |
2645 | invocation of bpstat for each breakpoint with a | |
2646 | command, and can easily blow up GDB stack. Instead, we | |
2647 | return true, which will trigger the caller to recall us | |
2648 | with the new stop_bpstat. */ | |
2649 | again = 1; | |
2650 | break; | |
32c1e744 | 2651 | } |
c906108c | 2652 | } |
c2b8ed2c | 2653 | do_cleanups (old_chain); |
347bddb7 PA |
2654 | return again; |
2655 | } | |
2656 | ||
2657 | void | |
2658 | bpstat_do_actions (void) | |
2659 | { | |
2660 | /* Do any commands attached to breakpoint we are stopped at. */ | |
2661 | while (!ptid_equal (inferior_ptid, null_ptid) | |
2662 | && target_has_execution | |
2663 | && !is_exited (inferior_ptid) | |
2664 | && !is_executing (inferior_ptid)) | |
2665 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
2666 | and only return when it is stopped at the next breakpoint, we | |
2667 | keep doing breakpoint actions until it returns false to | |
2668 | indicate the inferior was not resumed. */ | |
2669 | if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat)) | |
2670 | break; | |
c906108c SS |
2671 | } |
2672 | ||
fa4727a6 DJ |
2673 | /* Print out the (old or new) value associated with a watchpoint. */ |
2674 | ||
2675 | static void | |
2676 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
2677 | { | |
2678 | if (val == NULL) | |
2679 | fprintf_unfiltered (stream, _("<unreadable>")); | |
2680 | else | |
79a45b7d TT |
2681 | { |
2682 | struct value_print_options opts; | |
2683 | get_user_print_options (&opts); | |
2684 | value_print (val, stream, &opts); | |
2685 | } | |
fa4727a6 DJ |
2686 | } |
2687 | ||
e514a9d6 | 2688 | /* This is the normal print function for a bpstat. In the future, |
c906108c | 2689 | much of this logic could (should?) be moved to bpstat_stop_status, |
e514a9d6 JM |
2690 | by having it set different print_it values. |
2691 | ||
2692 | Current scheme: When we stop, bpstat_print() is called. It loops | |
2693 | through the bpstat list of things causing this stop, calling the | |
2694 | print_bp_stop_message function on each one. The behavior of the | |
2695 | print_bp_stop_message function depends on the print_it field of | |
2696 | bpstat. If such field so indicates, call this function here. | |
2697 | ||
2698 | Return values from this routine (ultimately used by bpstat_print() | |
2699 | and normal_stop() to decide what to do): | |
2700 | PRINT_NOTHING: Means we already printed all we needed to print, | |
2701 | don't print anything else. | |
2702 | PRINT_SRC_ONLY: Means we printed something, and we do *not* desire | |
2703 | that something to be followed by a location. | |
2704 | PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire | |
2705 | that something to be followed by a location. | |
2706 | PRINT_UNKNOWN: Means we printed nothing or we need to do some more | |
2707 | analysis. */ | |
c906108c | 2708 | |
917317f4 | 2709 | static enum print_stop_action |
fba45db2 | 2710 | print_it_typical (bpstat bs) |
c906108c | 2711 | { |
f7545552 | 2712 | struct cleanup *old_chain; |
4f8d1dc6 | 2713 | struct breakpoint *b; |
89f9893c | 2714 | const struct bp_location *bl; |
8b93c638 | 2715 | struct ui_stream *stb; |
f7545552 TT |
2716 | int bp_temp = 0; |
2717 | enum print_stop_action result; | |
2718 | ||
c906108c SS |
2719 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
2720 | which has since been deleted. */ | |
e514a9d6 | 2721 | if (bs->breakpoint_at == NULL) |
917317f4 | 2722 | return PRINT_UNKNOWN; |
0d381245 VP |
2723 | bl = bs->breakpoint_at; |
2724 | b = bl->owner; | |
c906108c | 2725 | |
f7545552 TT |
2726 | stb = ui_out_stream_new (uiout); |
2727 | old_chain = make_cleanup_ui_out_stream_delete (stb); | |
2728 | ||
4f8d1dc6 | 2729 | switch (b->type) |
c906108c | 2730 | { |
e514a9d6 JM |
2731 | case bp_breakpoint: |
2732 | case bp_hardware_breakpoint: | |
2cec12e5 | 2733 | bp_temp = bs->breakpoint_at->owner->disposition == disp_del; |
0d381245 VP |
2734 | if (bl->address != bl->requested_address) |
2735 | breakpoint_adjustment_warning (bl->requested_address, | |
2736 | bl->address, | |
4f8d1dc6 VP |
2737 | b->number, 1); |
2738 | annotate_breakpoint (b->number); | |
2cec12e5 AR |
2739 | if (bp_temp) |
2740 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
2741 | else | |
2742 | ui_out_text (uiout, "\nBreakpoint "); | |
9dc5e2a9 | 2743 | if (ui_out_is_mi_like_p (uiout)) |
2cec12e5 AR |
2744 | { |
2745 | ui_out_field_string (uiout, "reason", | |
2746 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
2747 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
2748 | } | |
4f8d1dc6 | 2749 | ui_out_field_int (uiout, "bkptno", b->number); |
8b93c638 | 2750 | ui_out_text (uiout, ", "); |
f7545552 | 2751 | result = PRINT_SRC_AND_LOC; |
e514a9d6 JM |
2752 | break; |
2753 | ||
2754 | case bp_shlib_event: | |
917317f4 JM |
2755 | /* Did we stop because the user set the stop_on_solib_events |
2756 | variable? (If so, we report this as a generic, "Stopped due | |
2757 | to shlib event" message.) */ | |
a3f17187 | 2758 | printf_filtered (_("Stopped due to shared library event\n")); |
f7545552 | 2759 | result = PRINT_NOTHING; |
e514a9d6 JM |
2760 | break; |
2761 | ||
c4093a6a JM |
2762 | case bp_thread_event: |
2763 | /* Not sure how we will get here. | |
2764 | GDB should not stop for these breakpoints. */ | |
a3f17187 | 2765 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 2766 | result = PRINT_NOTHING; |
c4093a6a JM |
2767 | break; |
2768 | ||
1900040c MS |
2769 | case bp_overlay_event: |
2770 | /* By analogy with the thread event, GDB should not stop for these. */ | |
a3f17187 | 2771 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 2772 | result = PRINT_NOTHING; |
1900040c MS |
2773 | break; |
2774 | ||
0fd8e87f UW |
2775 | case bp_longjmp_master: |
2776 | /* These should never be enabled. */ | |
2777 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
2778 | result = PRINT_NOTHING; | |
2779 | break; | |
2780 | ||
e514a9d6 JM |
2781 | case bp_watchpoint: |
2782 | case bp_hardware_watchpoint: | |
fa4727a6 DJ |
2783 | annotate_watchpoint (b->number); |
2784 | if (ui_out_is_mi_like_p (uiout)) | |
2785 | ui_out_field_string | |
2786 | (uiout, "reason", | |
2787 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
2788 | mention (b); | |
f7545552 | 2789 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
fa4727a6 DJ |
2790 | ui_out_text (uiout, "\nOld value = "); |
2791 | watchpoint_value_print (bs->old_val, stb->stream); | |
2792 | ui_out_field_stream (uiout, "old", stb); | |
2793 | ui_out_text (uiout, "\nNew value = "); | |
2794 | watchpoint_value_print (b->val, stb->stream); | |
2795 | ui_out_field_stream (uiout, "new", stb); | |
fa4727a6 | 2796 | ui_out_text (uiout, "\n"); |
e514a9d6 | 2797 | /* More than one watchpoint may have been triggered. */ |
f7545552 | 2798 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
2799 | break; |
2800 | ||
2801 | case bp_read_watchpoint: | |
9dc5e2a9 | 2802 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2803 | ui_out_field_string |
2804 | (uiout, "reason", | |
2805 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 2806 | mention (b); |
f7545552 | 2807 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 2808 | ui_out_text (uiout, "\nValue = "); |
fa4727a6 | 2809 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 2810 | ui_out_field_stream (uiout, "value", stb); |
8b93c638 | 2811 | ui_out_text (uiout, "\n"); |
f7545552 | 2812 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
2813 | break; |
2814 | ||
2815 | case bp_access_watchpoint: | |
fa4727a6 | 2816 | if (bs->old_val != NULL) |
8b93c638 | 2817 | { |
4f8d1dc6 | 2818 | annotate_watchpoint (b->number); |
9dc5e2a9 | 2819 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2820 | ui_out_field_string |
2821 | (uiout, "reason", | |
2822 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 2823 | mention (b); |
f7545552 | 2824 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 2825 | ui_out_text (uiout, "\nOld value = "); |
fa4727a6 | 2826 | watchpoint_value_print (bs->old_val, stb->stream); |
8b93c638 | 2827 | ui_out_field_stream (uiout, "old", stb); |
8b93c638 JM |
2828 | ui_out_text (uiout, "\nNew value = "); |
2829 | } | |
2830 | else | |
2831 | { | |
4f8d1dc6 | 2832 | mention (b); |
9dc5e2a9 | 2833 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2834 | ui_out_field_string |
2835 | (uiout, "reason", | |
2836 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
f7545552 | 2837 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 JM |
2838 | ui_out_text (uiout, "\nValue = "); |
2839 | } | |
fa4727a6 | 2840 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 2841 | ui_out_field_stream (uiout, "new", stb); |
8b93c638 | 2842 | ui_out_text (uiout, "\n"); |
f7545552 | 2843 | result = PRINT_UNKNOWN; |
e514a9d6 | 2844 | break; |
4ce44c66 | 2845 | |
e514a9d6 JM |
2846 | /* Fall through, we don't deal with these types of breakpoints |
2847 | here. */ | |
2848 | ||
11cf8741 | 2849 | case bp_finish: |
9dc5e2a9 | 2850 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2851 | ui_out_field_string |
2852 | (uiout, "reason", | |
2853 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
f7545552 | 2854 | result = PRINT_UNKNOWN; |
8b93c638 JM |
2855 | break; |
2856 | ||
e514a9d6 | 2857 | case bp_until: |
9dc5e2a9 | 2858 | if (ui_out_is_mi_like_p (uiout)) |
1fbc2a49 NR |
2859 | ui_out_field_string |
2860 | (uiout, "reason", | |
2861 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
f7545552 | 2862 | result = PRINT_UNKNOWN; |
8b93c638 JM |
2863 | break; |
2864 | ||
c2d11a7d | 2865 | case bp_none: |
e514a9d6 JM |
2866 | case bp_longjmp: |
2867 | case bp_longjmp_resume: | |
2868 | case bp_step_resume: | |
e514a9d6 JM |
2869 | case bp_watchpoint_scope: |
2870 | case bp_call_dummy: | |
1042e4c0 | 2871 | case bp_tracepoint: |
4efc6507 | 2872 | case bp_jit_event: |
e514a9d6 | 2873 | default: |
f7545552 TT |
2874 | result = PRINT_UNKNOWN; |
2875 | break; | |
e514a9d6 | 2876 | } |
f7545552 TT |
2877 | |
2878 | do_cleanups (old_chain); | |
2879 | return result; | |
e514a9d6 JM |
2880 | } |
2881 | ||
2882 | /* Generic routine for printing messages indicating why we | |
2883 | stopped. The behavior of this function depends on the value | |
2884 | 'print_it' in the bpstat structure. Under some circumstances we | |
2885 | may decide not to print anything here and delegate the task to | |
2886 | normal_stop(). */ | |
2887 | ||
2888 | static enum print_stop_action | |
2889 | print_bp_stop_message (bpstat bs) | |
2890 | { | |
2891 | switch (bs->print_it) | |
2892 | { | |
2893 | case print_it_noop: | |
2894 | /* Nothing should be printed for this bpstat entry. */ | |
2895 | return PRINT_UNKNOWN; | |
2896 | break; | |
2897 | ||
2898 | case print_it_done: | |
2899 | /* We still want to print the frame, but we already printed the | |
2900 | relevant messages. */ | |
2901 | return PRINT_SRC_AND_LOC; | |
2902 | break; | |
2903 | ||
2904 | case print_it_normal: | |
4f8d1dc6 | 2905 | { |
89f9893c | 2906 | const struct bp_location *bl = bs->breakpoint_at; |
4f8d1dc6 VP |
2907 | struct breakpoint *b = bl ? bl->owner : NULL; |
2908 | ||
2909 | /* Normal case. Call the breakpoint's print_it method, or | |
2910 | print_it_typical. */ | |
2911 | /* FIXME: how breakpoint can ever be NULL here? */ | |
2912 | if (b != NULL && b->ops != NULL && b->ops->print_it != NULL) | |
2913 | return b->ops->print_it (b); | |
2914 | else | |
2915 | return print_it_typical (bs); | |
2916 | } | |
2917 | break; | |
3086aeae | 2918 | |
e514a9d6 | 2919 | default: |
8e65ff28 | 2920 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 2921 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 2922 | break; |
c906108c | 2923 | } |
c906108c SS |
2924 | } |
2925 | ||
e514a9d6 JM |
2926 | /* Print a message indicating what happened. This is called from |
2927 | normal_stop(). The input to this routine is the head of the bpstat | |
2928 | list - a list of the eventpoints that caused this stop. This | |
2929 | routine calls the generic print routine for printing a message | |
2930 | about reasons for stopping. This will print (for example) the | |
2931 | "Breakpoint n," part of the output. The return value of this | |
2932 | routine is one of: | |
c906108c | 2933 | |
917317f4 JM |
2934 | PRINT_UNKNOWN: Means we printed nothing |
2935 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent | |
c5aa993b JM |
2936 | code to print the location. An example is |
2937 | "Breakpoint 1, " which should be followed by | |
2938 | the location. | |
917317f4 | 2939 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
2940 | to also print the location part of the message. |
2941 | An example is the catch/throw messages, which | |
917317f4 JM |
2942 | don't require a location appended to the end. |
2943 | PRINT_NOTHING: We have done some printing and we don't need any | |
2944 | further info to be printed.*/ | |
c906108c | 2945 | |
917317f4 | 2946 | enum print_stop_action |
fba45db2 | 2947 | bpstat_print (bpstat bs) |
c906108c SS |
2948 | { |
2949 | int val; | |
c5aa993b | 2950 | |
c906108c | 2951 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
2952 | (Currently all watchpoints go on the bpstat whether hit or not. |
2953 | That probably could (should) be changed, provided care is taken | |
c906108c | 2954 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
2955 | for (; bs; bs = bs->next) |
2956 | { | |
2957 | val = print_bp_stop_message (bs); | |
2958 | if (val == PRINT_SRC_ONLY | |
2959 | || val == PRINT_SRC_AND_LOC | |
2960 | || val == PRINT_NOTHING) | |
2961 | return val; | |
2962 | } | |
c906108c | 2963 | |
e514a9d6 JM |
2964 | /* We reached the end of the chain, or we got a null BS to start |
2965 | with and nothing was printed. */ | |
917317f4 | 2966 | return PRINT_UNKNOWN; |
c906108c SS |
2967 | } |
2968 | ||
2969 | /* Evaluate the expression EXP and return 1 if value is zero. | |
2970 | This is used inside a catch_errors to evaluate the breakpoint condition. | |
2971 | The argument is a "struct expression *" that has been cast to char * to | |
2972 | make it pass through catch_errors. */ | |
2973 | ||
2974 | static int | |
4efb68b1 | 2975 | breakpoint_cond_eval (void *exp) |
c906108c | 2976 | { |
278cd55f | 2977 | struct value *mark = value_mark (); |
c5aa993b | 2978 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
c906108c SS |
2979 | value_free_to_mark (mark); |
2980 | return i; | |
2981 | } | |
2982 | ||
2983 | /* Allocate a new bpstat and chain it to the current one. */ | |
2984 | ||
2985 | static bpstat | |
89f9893c | 2986 | bpstat_alloc (const struct bp_location *bl, bpstat cbs /* Current "bs" value */ ) |
c906108c SS |
2987 | { |
2988 | bpstat bs; | |
2989 | ||
2990 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
2991 | cbs->next = bs; | |
4f8d1dc6 | 2992 | bs->breakpoint_at = bl; |
c906108c SS |
2993 | /* If the condition is false, etc., don't do the commands. */ |
2994 | bs->commands = NULL; | |
2995 | bs->old_val = NULL; | |
2996 | bs->print_it = print_it_normal; | |
2997 | return bs; | |
2998 | } | |
2999 | \f | |
d983da9c DJ |
3000 | /* The target has stopped with waitstatus WS. Check if any hardware |
3001 | watchpoints have triggered, according to the target. */ | |
3002 | ||
3003 | int | |
3004 | watchpoints_triggered (struct target_waitstatus *ws) | |
3005 | { | |
d92524f1 | 3006 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
3007 | CORE_ADDR addr; |
3008 | struct breakpoint *b; | |
3009 | ||
3010 | if (!stopped_by_watchpoint) | |
3011 | { | |
3012 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
3013 | as not triggered. */ | |
3014 | ALL_BREAKPOINTS (b) | |
3015 | if (b->type == bp_hardware_watchpoint | |
3016 | || b->type == bp_read_watchpoint | |
3017 | || b->type == bp_access_watchpoint) | |
3018 | b->watchpoint_triggered = watch_triggered_no; | |
3019 | ||
3020 | return 0; | |
3021 | } | |
3022 | ||
3023 | if (!target_stopped_data_address (¤t_target, &addr)) | |
3024 | { | |
3025 | /* We were stopped by a watchpoint, but we don't know where. | |
3026 | Mark all watchpoints as unknown. */ | |
3027 | ALL_BREAKPOINTS (b) | |
3028 | if (b->type == bp_hardware_watchpoint | |
3029 | || b->type == bp_read_watchpoint | |
3030 | || b->type == bp_access_watchpoint) | |
3031 | b->watchpoint_triggered = watch_triggered_unknown; | |
3032 | ||
3033 | return stopped_by_watchpoint; | |
3034 | } | |
3035 | ||
3036 | /* The target could report the data address. Mark watchpoints | |
3037 | affected by this data address as triggered, and all others as not | |
3038 | triggered. */ | |
3039 | ||
3040 | ALL_BREAKPOINTS (b) | |
3041 | if (b->type == bp_hardware_watchpoint | |
3042 | || b->type == bp_read_watchpoint | |
3043 | || b->type == bp_access_watchpoint) | |
3044 | { | |
a5606eee | 3045 | struct bp_location *loc; |
d983da9c DJ |
3046 | struct value *v; |
3047 | ||
3048 | b->watchpoint_triggered = watch_triggered_no; | |
a5606eee VP |
3049 | for (loc = b->loc; loc; loc = loc->next) |
3050 | /* Exact match not required. Within range is | |
3051 | sufficient. */ | |
5009afc5 AS |
3052 | if (target_watchpoint_addr_within_range (¤t_target, |
3053 | addr, loc->address, | |
3054 | loc->length)) | |
a5606eee VP |
3055 | { |
3056 | b->watchpoint_triggered = watch_triggered_yes; | |
3057 | break; | |
3058 | } | |
d983da9c DJ |
3059 | } |
3060 | ||
3061 | return 1; | |
3062 | } | |
3063 | ||
c906108c SS |
3064 | /* Possible return values for watchpoint_check (this can't be an enum |
3065 | because of check_errors). */ | |
3066 | /* The watchpoint has been deleted. */ | |
3067 | #define WP_DELETED 1 | |
3068 | /* The value has changed. */ | |
3069 | #define WP_VALUE_CHANGED 2 | |
3070 | /* The value has not changed. */ | |
3071 | #define WP_VALUE_NOT_CHANGED 3 | |
3072 | ||
3073 | #define BP_TEMPFLAG 1 | |
3074 | #define BP_HARDWAREFLAG 2 | |
3075 | ||
3076 | /* Check watchpoint condition. */ | |
3077 | ||
3078 | static int | |
4efb68b1 | 3079 | watchpoint_check (void *p) |
c906108c SS |
3080 | { |
3081 | bpstat bs = (bpstat) p; | |
3082 | struct breakpoint *b; | |
3083 | struct frame_info *fr; | |
3084 | int within_current_scope; | |
3085 | ||
4f8d1dc6 | 3086 | b = bs->breakpoint_at->owner; |
c906108c SS |
3087 | |
3088 | if (b->exp_valid_block == NULL) | |
3089 | within_current_scope = 1; | |
3090 | else | |
3091 | { | |
edb3359d DJ |
3092 | struct frame_info *frame = get_current_frame (); |
3093 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
3094 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
3095 | ||
101dcfbe | 3096 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 3097 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
3098 | |
3099 | /* If we've gotten confused in the unwinder, we might have | |
3100 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
3101 | if (within_current_scope) |
3102 | { | |
3103 | struct symbol *function; | |
3104 | ||
3105 | function = get_frame_function (fr); | |
3106 | if (function == NULL | |
3107 | || !contained_in (b->exp_valid_block, | |
3108 | SYMBOL_BLOCK_VALUE (function))) | |
3109 | within_current_scope = 0; | |
3110 | } | |
69fbadd5 | 3111 | |
c12260ac CV |
3112 | /* in_function_epilogue_p() returns a non-zero value if we're still |
3113 | in the function but the stack frame has already been invalidated. | |
3114 | Since we can't rely on the values of local variables after the | |
3115 | stack has been destroyed, we are treating the watchpoint in that | |
edb3359d DJ |
3116 | state as `not changed' without further checking. Don't mark |
3117 | watchpoints as changed if the current frame is in an epilogue - | |
3118 | even if they are in some other frame, our view of the stack | |
3119 | is likely to be wrong. */ | |
3120 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) | |
3121 | return WP_VALUE_NOT_CHANGED; | |
fb14de7b | 3122 | |
edb3359d | 3123 | if (within_current_scope) |
c906108c SS |
3124 | /* If we end up stopping, the current frame will get selected |
3125 | in normal_stop. So this call to select_frame won't affect | |
3126 | the user. */ | |
0f7d239c | 3127 | select_frame (fr); |
c906108c | 3128 | } |
c5aa993b | 3129 | |
c906108c SS |
3130 | if (within_current_scope) |
3131 | { | |
3132 | /* We use value_{,free_to_}mark because it could be a | |
3133 | *long* time before we return to the command level and | |
c5aa993b JM |
3134 | call free_all_values. We can't call free_all_values because |
3135 | we might be in the middle of evaluating a function call. */ | |
c906108c | 3136 | |
278cd55f | 3137 | struct value *mark = value_mark (); |
fa4727a6 DJ |
3138 | struct value *new_val; |
3139 | ||
3140 | fetch_watchpoint_value (b->exp, &new_val, NULL, NULL); | |
3141 | if ((b->val != NULL) != (new_val != NULL) | |
3142 | || (b->val != NULL && !value_equal (b->val, new_val))) | |
c906108c | 3143 | { |
fa4727a6 DJ |
3144 | if (new_val != NULL) |
3145 | { | |
3146 | release_value (new_val); | |
3147 | value_free_to_mark (mark); | |
3148 | } | |
c906108c SS |
3149 | bs->old_val = b->val; |
3150 | b->val = new_val; | |
fa4727a6 | 3151 | b->val_valid = 1; |
c906108c SS |
3152 | /* We will stop here */ |
3153 | return WP_VALUE_CHANGED; | |
3154 | } | |
3155 | else | |
3156 | { | |
3157 | /* Nothing changed, don't do anything. */ | |
3158 | value_free_to_mark (mark); | |
3159 | /* We won't stop here */ | |
3160 | return WP_VALUE_NOT_CHANGED; | |
3161 | } | |
3162 | } | |
3163 | else | |
3164 | { | |
3165 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
3166 | if we temporarily ignored the watchpoint, then when |
3167 | we reenter the block in which it is valid it contains | |
3168 | garbage (in the case of a function, it may have two | |
3169 | garbage values, one before and one after the prologue). | |
3170 | So we can't even detect the first assignment to it and | |
3171 | watch after that (since the garbage may or may not equal | |
3172 | the first value assigned). */ | |
4ce44c66 JM |
3173 | /* We print all the stop information in print_it_typical(), but |
3174 | in this case, by the time we call print_it_typical() this bp | |
3175 | will be deleted already. So we have no choice but print the | |
3176 | information here. */ | |
9dc5e2a9 | 3177 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3178 | ui_out_field_string |
3179 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 3180 | ui_out_text (uiout, "\nWatchpoint "); |
4f8d1dc6 | 3181 | ui_out_field_int (uiout, "wpnum", b->number); |
8b93c638 JM |
3182 | ui_out_text (uiout, " deleted because the program has left the block in\n\ |
3183 | which its expression is valid.\n"); | |
4ce44c66 | 3184 | |
c906108c | 3185 | if (b->related_breakpoint) |
b5de0fa7 EZ |
3186 | b->related_breakpoint->disposition = disp_del_at_next_stop; |
3187 | b->disposition = disp_del_at_next_stop; | |
c906108c SS |
3188 | |
3189 | return WP_DELETED; | |
3190 | } | |
3191 | } | |
3192 | ||
18a18393 VP |
3193 | /* Return true if it looks like target has stopped due to hitting |
3194 | breakpoint location BL. This function does not check if we | |
3195 | should stop, only if BL explains the stop. */ | |
3196 | static int | |
6c95b8df PA |
3197 | bpstat_check_location (const struct bp_location *bl, |
3198 | struct address_space *aspace, CORE_ADDR bp_addr) | |
18a18393 VP |
3199 | { |
3200 | struct breakpoint *b = bl->owner; | |
3201 | ||
3202 | if (b->type != bp_watchpoint | |
3203 | && b->type != bp_hardware_watchpoint | |
3204 | && b->type != bp_read_watchpoint | |
3205 | && b->type != bp_access_watchpoint | |
3206 | && b->type != bp_hardware_breakpoint | |
fe798b75 | 3207 | && b->type != bp_catchpoint) /* a non-watchpoint bp */ |
18a18393 | 3208 | { |
6c95b8df PA |
3209 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
3210 | aspace, bp_addr)) | |
18a18393 VP |
3211 | return 0; |
3212 | if (overlay_debugging /* unmapped overlay section */ | |
3213 | && section_is_overlay (bl->section) | |
3214 | && !section_is_mapped (bl->section)) | |
3215 | return 0; | |
3216 | } | |
3217 | ||
3218 | /* Continuable hardware watchpoints are treated as non-existent if the | |
3219 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
3220 | some data address). Otherwise gdb won't stop on a break instruction | |
3221 | in the code (not from a breakpoint) when a hardware watchpoint has | |
3222 | been defined. Also skip watchpoints which we know did not trigger | |
3223 | (did not match the data address). */ | |
3224 | ||
3225 | if ((b->type == bp_hardware_watchpoint | |
3226 | || b->type == bp_read_watchpoint | |
3227 | || b->type == bp_access_watchpoint) | |
3228 | && b->watchpoint_triggered == watch_triggered_no) | |
3229 | return 0; | |
3230 | ||
3231 | if (b->type == bp_hardware_breakpoint) | |
3232 | { | |
3233 | if (bl->address != bp_addr) | |
3234 | return 0; | |
3235 | if (overlay_debugging /* unmapped overlay section */ | |
3236 | && section_is_overlay (bl->section) | |
3237 | && !section_is_mapped (bl->section)) | |
3238 | return 0; | |
3239 | } | |
ce78b96d | 3240 | |
ce78b96d JB |
3241 | if (b->type == bp_catchpoint) |
3242 | { | |
3243 | gdb_assert (b->ops != NULL && b->ops->breakpoint_hit != NULL); | |
3244 | if (!b->ops->breakpoint_hit (b)) | |
3245 | return 0; | |
3246 | } | |
3247 | ||
18a18393 VP |
3248 | return 1; |
3249 | } | |
3250 | ||
3251 | /* If BS refers to a watchpoint, determine if the watched values | |
3252 | has actually changed, and we should stop. If not, set BS->stop | |
3253 | to 0. */ | |
3254 | static void | |
3255 | bpstat_check_watchpoint (bpstat bs) | |
3256 | { | |
3257 | const struct bp_location *bl = bs->breakpoint_at; | |
3258 | struct breakpoint *b = bl->owner; | |
3259 | ||
3260 | if (b->type == bp_watchpoint | |
3261 | || b->type == bp_read_watchpoint | |
3262 | || b->type == bp_access_watchpoint | |
3263 | || b->type == bp_hardware_watchpoint) | |
3264 | { | |
3265 | CORE_ADDR addr; | |
3266 | struct value *v; | |
3267 | int must_check_value = 0; | |
3268 | ||
3269 | if (b->type == bp_watchpoint) | |
3270 | /* For a software watchpoint, we must always check the | |
3271 | watched value. */ | |
3272 | must_check_value = 1; | |
3273 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
3274 | /* We have a hardware watchpoint (read, write, or access) | |
3275 | and the target earlier reported an address watched by | |
3276 | this watchpoint. */ | |
3277 | must_check_value = 1; | |
3278 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3279 | && b->type == bp_hardware_watchpoint) | |
3280 | /* We were stopped by a hardware watchpoint, but the target could | |
3281 | not report the data address. We must check the watchpoint's | |
3282 | value. Access and read watchpoints are out of luck; without | |
3283 | a data address, we can't figure it out. */ | |
3284 | must_check_value = 1; | |
3285 | ||
3286 | if (must_check_value) | |
3287 | { | |
3288 | char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3289 | b->number); | |
3290 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
3291 | int e = catch_errors (watchpoint_check, bs, message, | |
3292 | RETURN_MASK_ALL); | |
3293 | do_cleanups (cleanups); | |
3294 | switch (e) | |
3295 | { | |
3296 | case WP_DELETED: | |
3297 | /* We've already printed what needs to be printed. */ | |
3298 | bs->print_it = print_it_done; | |
3299 | /* Stop. */ | |
3300 | break; | |
3301 | case WP_VALUE_CHANGED: | |
3302 | if (b->type == bp_read_watchpoint) | |
3303 | { | |
3304 | /* Don't stop: read watchpoints shouldn't fire if | |
3305 | the value has changed. This is for targets | |
3306 | which cannot set read-only watchpoints. */ | |
3307 | bs->print_it = print_it_noop; | |
3308 | bs->stop = 0; | |
3309 | } | |
3310 | break; | |
3311 | case WP_VALUE_NOT_CHANGED: | |
3312 | if (b->type == bp_hardware_watchpoint | |
3313 | || b->type == bp_watchpoint) | |
3314 | { | |
3315 | /* Don't stop: write watchpoints shouldn't fire if | |
3316 | the value hasn't changed. */ | |
3317 | bs->print_it = print_it_noop; | |
3318 | bs->stop = 0; | |
3319 | } | |
3320 | /* Stop. */ | |
3321 | break; | |
3322 | default: | |
3323 | /* Can't happen. */ | |
3324 | case 0: | |
3325 | /* Error from catch_errors. */ | |
3326 | printf_filtered (_("Watchpoint %d deleted.\n"), b->number); | |
3327 | if (b->related_breakpoint) | |
3328 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
3329 | b->disposition = disp_del_at_next_stop; | |
3330 | /* We've already printed what needs to be printed. */ | |
3331 | bs->print_it = print_it_done; | |
3332 | break; | |
3333 | } | |
3334 | } | |
3335 | else /* must_check_value == 0 */ | |
3336 | { | |
3337 | /* This is a case where some watchpoint(s) triggered, but | |
3338 | not at the address of this watchpoint, or else no | |
3339 | watchpoint triggered after all. So don't print | |
3340 | anything for this watchpoint. */ | |
3341 | bs->print_it = print_it_noop; | |
3342 | bs->stop = 0; | |
3343 | } | |
3344 | } | |
3345 | } | |
3346 | ||
3347 | ||
3348 | /* Check conditions (condition proper, frame, thread and ignore count) | |
3349 | of breakpoint referred to by BS. If we should not stop for this | |
3350 | breakpoint, set BS->stop to 0. */ | |
3351 | static void | |
3352 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
3353 | { | |
3354 | int thread_id = pid_to_thread_id (ptid); | |
3355 | const struct bp_location *bl = bs->breakpoint_at; | |
3356 | struct breakpoint *b = bl->owner; | |
3357 | ||
3358 | if (frame_id_p (b->frame_id) | |
edb3359d | 3359 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 VP |
3360 | bs->stop = 0; |
3361 | else if (bs->stop) | |
3362 | { | |
3363 | int value_is_zero = 0; | |
3364 | ||
3365 | /* If this is a scope breakpoint, mark the associated | |
3366 | watchpoint as triggered so that we will handle the | |
3367 | out-of-scope event. We'll get to the watchpoint next | |
3368 | iteration. */ | |
3369 | if (b->type == bp_watchpoint_scope) | |
3370 | b->related_breakpoint->watchpoint_triggered = watch_triggered_yes; | |
3371 | ||
3372 | if (bl->cond && bl->owner->disposition != disp_del_at_next_stop) | |
3373 | { | |
c5bc3a77 DJ |
3374 | /* We use value_mark and value_free_to_mark because it could |
3375 | be a long time before we return to the command level and | |
3376 | call free_all_values. We can't call free_all_values | |
3377 | because we might be in the middle of evaluating a | |
3378 | function call. */ | |
3379 | struct value *mark = value_mark (); | |
3380 | ||
edb3359d DJ |
3381 | /* Need to select the frame, with all that implies so that |
3382 | the conditions will have the right context. Because we | |
3383 | use the frame, we will not see an inlined function's | |
3384 | variables when we arrive at a breakpoint at the start | |
3385 | of the inlined function; the current frame will be the | |
3386 | call site. */ | |
18a18393 VP |
3387 | select_frame (get_current_frame ()); |
3388 | value_is_zero | |
3389 | = catch_errors (breakpoint_cond_eval, (bl->cond), | |
3390 | "Error in testing breakpoint condition:\n", | |
3391 | RETURN_MASK_ALL); | |
3392 | /* FIXME-someday, should give breakpoint # */ | |
c5bc3a77 | 3393 | value_free_to_mark (mark); |
18a18393 VP |
3394 | } |
3395 | if (bl->cond && value_is_zero) | |
3396 | { | |
3397 | bs->stop = 0; | |
3398 | } | |
3399 | else if (b->thread != -1 && b->thread != thread_id) | |
3400 | { | |
3401 | bs->stop = 0; | |
3402 | } | |
3403 | else if (b->ignore_count > 0) | |
3404 | { | |
3405 | b->ignore_count--; | |
3406 | annotate_ignore_count_change (); | |
3407 | bs->stop = 0; | |
3408 | /* Increase the hit count even though we don't | |
3409 | stop. */ | |
3410 | ++(b->hit_count); | |
3411 | } | |
3412 | } | |
3413 | } | |
3414 | ||
3415 | ||
9709f61c | 3416 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 3417 | BP_ADDR in thread PTID. |
c906108c | 3418 | |
d983da9c | 3419 | Determine whether we stopped at a breakpoint, etc, or whether we |
c906108c SS |
3420 | don't understand this stop. Result is a chain of bpstat's such that: |
3421 | ||
c5aa993b | 3422 | if we don't understand the stop, the result is a null pointer. |
c906108c | 3423 | |
c5aa993b | 3424 | if we understand why we stopped, the result is not null. |
c906108c | 3425 | |
c5aa993b JM |
3426 | Each element of the chain refers to a particular breakpoint or |
3427 | watchpoint at which we have stopped. (We may have stopped for | |
3428 | several reasons concurrently.) | |
c906108c | 3429 | |
c5aa993b JM |
3430 | Each element of the chain has valid next, breakpoint_at, |
3431 | commands, FIXME??? fields. */ | |
c906108c SS |
3432 | |
3433 | bpstat | |
6c95b8df PA |
3434 | bpstat_stop_status (struct address_space *aspace, |
3435 | CORE_ADDR bp_addr, ptid_t ptid) | |
c906108c | 3436 | { |
0d381245 | 3437 | struct breakpoint *b = NULL; |
876fa593 | 3438 | struct bp_location *bl, **blp_tmp; |
20874c92 | 3439 | struct bp_location *loc; |
c906108c SS |
3440 | /* Root of the chain of bpstat's */ |
3441 | struct bpstats root_bs[1]; | |
3442 | /* Pointer to the last thing in the chain currently. */ | |
3443 | bpstat bs = root_bs; | |
20874c92 | 3444 | int ix; |
876fa593 | 3445 | int need_remove_insert, update_locations = 0; |
c906108c | 3446 | |
876fa593 | 3447 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3448 | { |
0d381245 VP |
3449 | b = bl->owner; |
3450 | gdb_assert (b); | |
468d015d | 3451 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) |
c5aa993b JM |
3452 | continue; |
3453 | ||
a5606eee VP |
3454 | /* For hardware watchpoints, we look only at the first location. |
3455 | The watchpoint_check function will work on entire expression, | |
3456 | not the individual locations. For read watchopints, the | |
3457 | watchpoints_triggered function have checked all locations | |
3d947dff | 3458 | already. */ |
a5606eee VP |
3459 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
3460 | continue; | |
3461 | ||
6c95b8df | 3462 | if (!bpstat_check_location (bl, aspace, bp_addr)) |
18a18393 VP |
3463 | continue; |
3464 | ||
c5aa993b JM |
3465 | /* Come here if it's a watchpoint, or if the break address matches */ |
3466 | ||
0d381245 | 3467 | bs = bpstat_alloc (bl, bs); /* Alloc a bpstat to explain stop */ |
c5aa993b | 3468 | |
18a18393 VP |
3469 | /* Assume we stop. Should we find watchpoint that is not actually |
3470 | triggered, or if condition of breakpoint is false, we'll reset | |
3471 | 'stop' to 0. */ | |
c5aa993b JM |
3472 | bs->stop = 1; |
3473 | bs->print = 1; | |
3474 | ||
18a18393 VP |
3475 | bpstat_check_watchpoint (bs); |
3476 | if (!bs->stop) | |
3477 | continue; | |
c5aa993b | 3478 | |
0fd8e87f UW |
3479 | if (b->type == bp_thread_event || b->type == bp_overlay_event |
3480 | || b->type == bp_longjmp_master) | |
18a18393 | 3481 | /* We do not stop for these. */ |
c5aa993b JM |
3482 | bs->stop = 0; |
3483 | else | |
18a18393 VP |
3484 | bpstat_check_breakpoint_conditions (bs, ptid); |
3485 | ||
3486 | if (bs->stop) | |
c5aa993b | 3487 | { |
876fa593 JK |
3488 | if (b->enable_state != bp_disabled) |
3489 | ++(b->hit_count); | |
d983da9c | 3490 | |
18a18393 VP |
3491 | /* We will stop here */ |
3492 | if (b->disposition == disp_disable) | |
c5aa993b | 3493 | { |
514f746b AR |
3494 | if (b->enable_state != bp_permanent) |
3495 | b->enable_state = bp_disabled; | |
876fa593 | 3496 | update_locations = 1; |
c5aa993b | 3497 | } |
18a18393 VP |
3498 | if (b->silent) |
3499 | bs->print = 0; | |
3500 | bs->commands = b->commands; | |
059fb39f PM |
3501 | if (bs->commands |
3502 | && (strcmp ("silent", bs->commands->line) == 0 | |
3503 | || (xdb_commands && strcmp ("Q", bs->commands->line) == 0))) | |
c5aa993b | 3504 | { |
18a18393 VP |
3505 | bs->commands = bs->commands->next; |
3506 | bs->print = 0; | |
c5aa993b | 3507 | } |
18a18393 | 3508 | bs->commands = copy_command_lines (bs->commands); |
c5aa993b | 3509 | } |
18a18393 | 3510 | |
c5aa993b JM |
3511 | /* Print nothing for this entry if we dont stop or if we dont print. */ |
3512 | if (bs->stop == 0 || bs->print == 0) | |
3513 | bs->print_it = print_it_noop; | |
3514 | } | |
c906108c | 3515 | |
876fa593 JK |
3516 | /* Delay this call which would break the ALL_BP_LOCATIONS iteration above. */ |
3517 | if (update_locations) | |
3518 | update_global_location_list (0); | |
3519 | ||
20874c92 VP |
3520 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
3521 | { | |
6c95b8df PA |
3522 | if (breakpoint_address_match (loc->pspace->aspace, loc->address, |
3523 | aspace, bp_addr)) | |
20874c92 VP |
3524 | { |
3525 | bs = bpstat_alloc (loc, bs); | |
3526 | /* For hits of moribund locations, we should just proceed. */ | |
3527 | bs->stop = 0; | |
3528 | bs->print = 0; | |
3529 | bs->print_it = print_it_noop; | |
3530 | } | |
3531 | } | |
3532 | ||
c906108c SS |
3533 | bs->next = NULL; /* Terminate the chain */ |
3534 | bs = root_bs->next; /* Re-grab the head of the chain */ | |
3535 | ||
d983da9c DJ |
3536 | /* If we aren't stopping, the value of some hardware watchpoint may |
3537 | not have changed, but the intermediate memory locations we are | |
3538 | watching may have. Don't bother if we're stopping; this will get | |
3539 | done later. */ | |
3540 | for (bs = root_bs->next; bs != NULL; bs = bs->next) | |
3541 | if (bs->stop) | |
3542 | break; | |
3543 | ||
d832cb68 | 3544 | need_remove_insert = 0; |
d983da9c DJ |
3545 | if (bs == NULL) |
3546 | for (bs = root_bs->next; bs != NULL; bs = bs->next) | |
3547 | if (!bs->stop | |
20874c92 | 3548 | && bs->breakpoint_at->owner |
d983da9c DJ |
3549 | && (bs->breakpoint_at->owner->type == bp_hardware_watchpoint |
3550 | || bs->breakpoint_at->owner->type == bp_read_watchpoint | |
3551 | || bs->breakpoint_at->owner->type == bp_access_watchpoint)) | |
3552 | { | |
a5606eee VP |
3553 | /* remove/insert can invalidate bs->breakpoint_at, if this |
3554 | location is no longer used by the watchpoint. Prevent | |
3555 | further code from trying to use it. */ | |
3556 | bs->breakpoint_at = NULL; | |
d832cb68 | 3557 | need_remove_insert = 1; |
d983da9c DJ |
3558 | } |
3559 | ||
d832cb68 DD |
3560 | if (need_remove_insert) |
3561 | { | |
3562 | remove_breakpoints (); | |
3563 | insert_breakpoints (); | |
3564 | } | |
3565 | ||
d983da9c | 3566 | return root_bs->next; |
c906108c SS |
3567 | } |
3568 | \f | |
3569 | /* Tell what to do about this bpstat. */ | |
3570 | struct bpstat_what | |
fba45db2 | 3571 | bpstat_what (bpstat bs) |
c906108c SS |
3572 | { |
3573 | /* Classify each bpstat as one of the following. */ | |
c5aa993b JM |
3574 | enum class |
3575 | { | |
3576 | /* This bpstat element has no effect on the main_action. */ | |
3577 | no_effect = 0, | |
3578 | ||
3579 | /* There was a watchpoint, stop but don't print. */ | |
3580 | wp_silent, | |
c906108c | 3581 | |
c5aa993b JM |
3582 | /* There was a watchpoint, stop and print. */ |
3583 | wp_noisy, | |
c906108c | 3584 | |
c5aa993b JM |
3585 | /* There was a breakpoint but we're not stopping. */ |
3586 | bp_nostop, | |
c906108c | 3587 | |
c5aa993b JM |
3588 | /* There was a breakpoint, stop but don't print. */ |
3589 | bp_silent, | |
c906108c | 3590 | |
c5aa993b JM |
3591 | /* There was a breakpoint, stop and print. */ |
3592 | bp_noisy, | |
c906108c | 3593 | |
c5aa993b JM |
3594 | /* We hit the longjmp breakpoint. */ |
3595 | long_jump, | |
c906108c | 3596 | |
c5aa993b JM |
3597 | /* We hit the longjmp_resume breakpoint. */ |
3598 | long_resume, | |
c906108c | 3599 | |
c5aa993b JM |
3600 | /* We hit the step_resume breakpoint. */ |
3601 | step_resume, | |
c906108c | 3602 | |
c5aa993b JM |
3603 | /* We hit the shared library event breakpoint. */ |
3604 | shlib_event, | |
c906108c | 3605 | |
4efc6507 DE |
3606 | /* We hit the jit event breakpoint. */ |
3607 | jit_event, | |
3608 | ||
c5aa993b JM |
3609 | /* This is just used to count how many enums there are. */ |
3610 | class_last | |
c906108c SS |
3611 | }; |
3612 | ||
3613 | /* Here is the table which drives this routine. So that we can | |
3614 | format it pretty, we define some abbreviations for the | |
3615 | enum bpstat_what codes. */ | |
3616 | #define kc BPSTAT_WHAT_KEEP_CHECKING | |
3617 | #define ss BPSTAT_WHAT_STOP_SILENT | |
3618 | #define sn BPSTAT_WHAT_STOP_NOISY | |
3619 | #define sgl BPSTAT_WHAT_SINGLE | |
3620 | #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME | |
3621 | #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME | |
c906108c | 3622 | #define sr BPSTAT_WHAT_STEP_RESUME |
c906108c | 3623 | #define shl BPSTAT_WHAT_CHECK_SHLIBS |
4efc6507 | 3624 | #define jit BPSTAT_WHAT_CHECK_JIT |
c906108c SS |
3625 | |
3626 | /* "Can't happen." Might want to print an error message. | |
3627 | abort() is not out of the question, but chances are GDB is just | |
3628 | a bit confused, not unusable. */ | |
3629 | #define err BPSTAT_WHAT_STOP_NOISY | |
3630 | ||
3631 | /* Given an old action and a class, come up with a new action. */ | |
3632 | /* One interesting property of this table is that wp_silent is the same | |
3633 | as bp_silent and wp_noisy is the same as bp_noisy. That is because | |
3634 | after stopping, the check for whether to step over a breakpoint | |
3635 | (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without | |
53a5351d JM |
3636 | reference to how we stopped. We retain separate wp_silent and |
3637 | bp_silent codes in case we want to change that someday. | |
43ff13b4 JM |
3638 | |
3639 | Another possibly interesting property of this table is that | |
3640 | there's a partial ordering, priority-like, of the actions. Once | |
3641 | you've decided that some action is appropriate, you'll never go | |
3642 | back and decide something of a lower priority is better. The | |
3643 | ordering is: | |
3644 | ||
4efc6507 DE |
3645 | kc < jit clr sgl shl slr sn sr ss |
3646 | sgl < jit shl slr sn sr ss | |
3647 | slr < jit err shl sn sr ss | |
3648 | clr < jit err shl sn sr ss | |
3649 | ss < jit shl sn sr | |
3650 | sn < jit shl sr | |
3651 | jit < shl sr | |
d81191fc | 3652 | shl < sr |
4d5b2cd7 | 3653 | sr < |
c5aa993b | 3654 | |
43ff13b4 JM |
3655 | What I think this means is that we don't need a damned table |
3656 | here. If you just put the rows and columns in the right order, | |
3657 | it'd look awfully regular. We could simply walk the bpstat list | |
3658 | and choose the highest priority action we find, with a little | |
78b6a731 | 3659 | logic to handle the 'err' cases. */ |
c906108c SS |
3660 | |
3661 | /* step_resume entries: a step resume breakpoint overrides another | |
3662 | breakpoint of signal handling (see comment in wait_for_inferior | |
fcf70625 | 3663 | at where we set the step_resume breakpoint). */ |
c906108c SS |
3664 | |
3665 | static const enum bpstat_what_main_action | |
c5aa993b JM |
3666 | table[(int) class_last][(int) BPSTAT_WHAT_LAST] = |
3667 | { | |
3668 | /* old action */ | |
4efc6507 DE |
3669 | /* kc ss sn sgl slr clr sr shl jit */ |
3670 | /* no_effect */ {kc, ss, sn, sgl, slr, clr, sr, shl, jit}, | |
3671 | /* wp_silent */ {ss, ss, sn, ss, ss, ss, sr, shl, jit}, | |
3672 | /* wp_noisy */ {sn, sn, sn, sn, sn, sn, sr, shl, jit}, | |
3673 | /* bp_nostop */ {sgl, ss, sn, sgl, slr, slr, sr, shl, jit}, | |
3674 | /* bp_silent */ {ss, ss, sn, ss, ss, ss, sr, shl, jit}, | |
3675 | /* bp_noisy */ {sn, sn, sn, sn, sn, sn, sr, shl, jit}, | |
3676 | /* long_jump */ {slr, ss, sn, slr, slr, err, sr, shl, jit}, | |
3677 | /* long_resume */ {clr, ss, sn, err, err, err, sr, shl, jit}, | |
3678 | /* step_resume */ {sr, sr, sr, sr, sr, sr, sr, sr, sr }, | |
3679 | /* shlib */ {shl, shl, shl, shl, shl, shl, sr, shl, shl}, | |
3680 | /* jit_event */ {jit, jit, jit, jit, jit, jit, sr, jit, jit} | |
c5aa993b | 3681 | }; |
c906108c SS |
3682 | |
3683 | #undef kc | |
3684 | #undef ss | |
3685 | #undef sn | |
3686 | #undef sgl | |
3687 | #undef slr | |
3688 | #undef clr | |
c906108c SS |
3689 | #undef err |
3690 | #undef sr | |
3691 | #undef ts | |
3692 | #undef shl | |
4efc6507 | 3693 | #undef jit |
c906108c SS |
3694 | enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING; |
3695 | struct bpstat_what retval; | |
3696 | ||
3697 | retval.call_dummy = 0; | |
3698 | for (; bs != NULL; bs = bs->next) | |
3699 | { | |
3700 | enum class bs_class = no_effect; | |
3701 | if (bs->breakpoint_at == NULL) | |
3702 | /* I suspect this can happen if it was a momentary breakpoint | |
3703 | which has since been deleted. */ | |
3704 | continue; | |
20874c92 VP |
3705 | if (bs->breakpoint_at->owner == NULL) |
3706 | bs_class = bp_nostop; | |
3707 | else | |
4f8d1dc6 | 3708 | switch (bs->breakpoint_at->owner->type) |
c906108c SS |
3709 | { |
3710 | case bp_none: | |
3711 | continue; | |
3712 | ||
3713 | case bp_breakpoint: | |
3714 | case bp_hardware_breakpoint: | |
3715 | case bp_until: | |
3716 | case bp_finish: | |
3717 | if (bs->stop) | |
3718 | { | |
3719 | if (bs->print) | |
3720 | bs_class = bp_noisy; | |
3721 | else | |
3722 | bs_class = bp_silent; | |
3723 | } | |
3724 | else | |
3725 | bs_class = bp_nostop; | |
3726 | break; | |
3727 | case bp_watchpoint: | |
3728 | case bp_hardware_watchpoint: | |
3729 | case bp_read_watchpoint: | |
3730 | case bp_access_watchpoint: | |
3731 | if (bs->stop) | |
3732 | { | |
3733 | if (bs->print) | |
3734 | bs_class = wp_noisy; | |
3735 | else | |
3736 | bs_class = wp_silent; | |
3737 | } | |
3738 | else | |
53a5351d JM |
3739 | /* There was a watchpoint, but we're not stopping. |
3740 | This requires no further action. */ | |
c906108c SS |
3741 | bs_class = no_effect; |
3742 | break; | |
3743 | case bp_longjmp: | |
3744 | bs_class = long_jump; | |
3745 | break; | |
3746 | case bp_longjmp_resume: | |
3747 | bs_class = long_resume; | |
3748 | break; | |
3749 | case bp_step_resume: | |
3750 | if (bs->stop) | |
3751 | { | |
3752 | bs_class = step_resume; | |
3753 | } | |
3754 | else | |
3755 | /* It is for the wrong frame. */ | |
3756 | bs_class = bp_nostop; | |
3757 | break; | |
c906108c SS |
3758 | case bp_watchpoint_scope: |
3759 | bs_class = bp_nostop; | |
3760 | break; | |
c5aa993b JM |
3761 | case bp_shlib_event: |
3762 | bs_class = shlib_event; | |
3763 | break; | |
4efc6507 DE |
3764 | case bp_jit_event: |
3765 | bs_class = jit_event; | |
3766 | break; | |
c4093a6a | 3767 | case bp_thread_event: |
1900040c | 3768 | case bp_overlay_event: |
0fd8e87f | 3769 | case bp_longjmp_master: |
c4093a6a JM |
3770 | bs_class = bp_nostop; |
3771 | break; | |
ce78b96d | 3772 | case bp_catchpoint: |
c5aa993b JM |
3773 | if (bs->stop) |
3774 | { | |
3775 | if (bs->print) | |
3776 | bs_class = bp_noisy; | |
3777 | else | |
3778 | bs_class = bp_silent; | |
3779 | } | |
3780 | else | |
53a5351d JM |
3781 | /* There was a catchpoint, but we're not stopping. |
3782 | This requires no further action. */ | |
c5aa993b JM |
3783 | bs_class = no_effect; |
3784 | break; | |
c906108c | 3785 | case bp_call_dummy: |
53a5351d JM |
3786 | /* Make sure the action is stop (silent or noisy), |
3787 | so infrun.c pops the dummy frame. */ | |
c906108c SS |
3788 | bs_class = bp_silent; |
3789 | retval.call_dummy = 1; | |
3790 | break; | |
1042e4c0 SS |
3791 | case bp_tracepoint: |
3792 | /* Tracepoint hits should not be reported back to GDB, and | |
3793 | if one got through somehow, it should have been filtered | |
3794 | out already. */ | |
3795 | internal_error (__FILE__, __LINE__, | |
3796 | _("bpstat_what: bp_tracepoint encountered")); | |
3797 | break; | |
c906108c | 3798 | } |
c5aa993b | 3799 | current_action = table[(int) bs_class][(int) current_action]; |
c906108c SS |
3800 | } |
3801 | retval.main_action = current_action; | |
3802 | return retval; | |
3803 | } | |
3804 | ||
3805 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
3806 | without hardware support). This isn't related to a specific bpstat, | |
3807 | just to things like whether watchpoints are set. */ | |
3808 | ||
c5aa993b | 3809 | int |
fba45db2 | 3810 | bpstat_should_step (void) |
c906108c SS |
3811 | { |
3812 | struct breakpoint *b; | |
3813 | ALL_BREAKPOINTS (b) | |
717a8278 | 3814 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 3815 | return 1; |
c906108c SS |
3816 | return 0; |
3817 | } | |
3818 | ||
67822962 PA |
3819 | int |
3820 | bpstat_causes_stop (bpstat bs) | |
3821 | { | |
3822 | for (; bs != NULL; bs = bs->next) | |
3823 | if (bs->stop) | |
3824 | return 1; | |
3825 | ||
3826 | return 0; | |
3827 | } | |
3828 | ||
c906108c | 3829 | \f |
c5aa993b | 3830 | |
0d381245 VP |
3831 | static void print_breakpoint_location (struct breakpoint *b, |
3832 | struct bp_location *loc, | |
3833 | char *wrap_indent, | |
3834 | struct ui_stream *stb) | |
3835 | { | |
6c95b8df PA |
3836 | struct cleanup *old_chain = save_current_program_space (); |
3837 | ||
3838 | if (loc != NULL) | |
3839 | set_current_program_space (loc->pspace); | |
3840 | ||
0d381245 VP |
3841 | if (b->source_file) |
3842 | { | |
3843 | struct symbol *sym | |
3844 | = find_pc_sect_function (loc->address, loc->section); | |
3845 | if (sym) | |
3846 | { | |
3847 | ui_out_text (uiout, "in "); | |
3848 | ui_out_field_string (uiout, "func", | |
3849 | SYMBOL_PRINT_NAME (sym)); | |
3850 | ui_out_wrap_hint (uiout, wrap_indent); | |
3851 | ui_out_text (uiout, " at "); | |
3852 | } | |
3853 | ui_out_field_string (uiout, "file", b->source_file); | |
3854 | ui_out_text (uiout, ":"); | |
3855 | ||
3856 | if (ui_out_is_mi_like_p (uiout)) | |
3857 | { | |
3858 | struct symtab_and_line sal = find_pc_line (loc->address, 0); | |
3859 | char *fullname = symtab_to_fullname (sal.symtab); | |
3860 | ||
3861 | if (fullname) | |
3862 | ui_out_field_string (uiout, "fullname", fullname); | |
3863 | } | |
3864 | ||
3865 | ui_out_field_int (uiout, "line", b->line_number); | |
3866 | } | |
3867 | else if (!b->loc) | |
3868 | { | |
3869 | ui_out_field_string (uiout, "pending", b->addr_string); | |
3870 | } | |
3871 | else | |
3872 | { | |
3873 | print_address_symbolic (loc->address, stb->stream, demangle, ""); | |
3874 | ui_out_field_stream (uiout, "at", stb); | |
3875 | } | |
6c95b8df PA |
3876 | |
3877 | do_cleanups (old_chain); | |
0d381245 VP |
3878 | } |
3879 | ||
c4093a6a | 3880 | /* Print B to gdb_stdout. */ |
c906108c | 3881 | static void |
0d381245 VP |
3882 | print_one_breakpoint_location (struct breakpoint *b, |
3883 | struct bp_location *loc, | |
3884 | int loc_number, | |
a6d9a66e | 3885 | struct bp_location **last_loc, |
6c95b8df PA |
3886 | int print_address_bits, |
3887 | int allflag) | |
c906108c | 3888 | { |
52f0bd74 AC |
3889 | struct command_line *l; |
3890 | struct symbol *sym; | |
c4093a6a JM |
3891 | struct ep_type_description |
3892 | { | |
3893 | enum bptype type; | |
3894 | char *description; | |
3895 | }; | |
3896 | static struct ep_type_description bptypes[] = | |
c906108c | 3897 | { |
c5aa993b JM |
3898 | {bp_none, "?deleted?"}, |
3899 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 3900 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
3901 | {bp_until, "until"}, |
3902 | {bp_finish, "finish"}, | |
3903 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 3904 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
3905 | {bp_read_watchpoint, "read watchpoint"}, |
3906 | {bp_access_watchpoint, "acc watchpoint"}, | |
3907 | {bp_longjmp, "longjmp"}, | |
3908 | {bp_longjmp_resume, "longjmp resume"}, | |
3909 | {bp_step_resume, "step resume"}, | |
c5aa993b JM |
3910 | {bp_watchpoint_scope, "watchpoint scope"}, |
3911 | {bp_call_dummy, "call dummy"}, | |
3912 | {bp_shlib_event, "shlib events"}, | |
c4093a6a | 3913 | {bp_thread_event, "thread events"}, |
1900040c | 3914 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 3915 | {bp_longjmp_master, "longjmp master"}, |
ce78b96d | 3916 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 3917 | {bp_tracepoint, "tracepoint"}, |
4efc6507 | 3918 | {bp_jit_event, "jit events"}, |
c5aa993b | 3919 | }; |
c4093a6a | 3920 | |
c2c6d25f | 3921 | static char bpenables[] = "nynny"; |
c906108c | 3922 | char wrap_indent[80]; |
8b93c638 JM |
3923 | struct ui_stream *stb = ui_out_stream_new (uiout); |
3924 | struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb); | |
3b31d625 | 3925 | struct cleanup *bkpt_chain; |
c906108c | 3926 | |
0d381245 VP |
3927 | int header_of_multiple = 0; |
3928 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
3929 | struct value_print_options opts; |
3930 | ||
3931 | get_user_print_options (&opts); | |
0d381245 VP |
3932 | |
3933 | gdb_assert (!loc || loc_number != 0); | |
3934 | /* See comment in print_one_breakpoint concerning | |
3935 | treatment of breakpoints with single disabled | |
3936 | location. */ | |
3937 | if (loc == NULL | |
3938 | && (b->loc != NULL | |
3939 | && (b->loc->next != NULL || !b->loc->enabled))) | |
3940 | header_of_multiple = 1; | |
3941 | if (loc == NULL) | |
3942 | loc = b->loc; | |
3943 | ||
c4093a6a | 3944 | annotate_record (); |
3b31d625 | 3945 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); |
c4093a6a JM |
3946 | |
3947 | /* 1 */ | |
3948 | annotate_field (0); | |
0d381245 VP |
3949 | if (part_of_multiple) |
3950 | { | |
3951 | char *formatted; | |
0c6773c1 | 3952 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
3953 | ui_out_field_string (uiout, "number", formatted); |
3954 | xfree (formatted); | |
3955 | } | |
3956 | else | |
3957 | { | |
3958 | ui_out_field_int (uiout, "number", b->number); | |
3959 | } | |
c4093a6a JM |
3960 | |
3961 | /* 2 */ | |
3962 | annotate_field (1); | |
0d381245 VP |
3963 | if (part_of_multiple) |
3964 | ui_out_field_skip (uiout, "type"); | |
3965 | else | |
3966 | { | |
3967 | if (((int) b->type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
3968 | || ((int) b->type != bptypes[(int) b->type].type)) | |
3969 | internal_error (__FILE__, __LINE__, | |
3970 | _("bptypes table does not describe type #%d."), | |
3971 | (int) b->type); | |
3972 | ui_out_field_string (uiout, "type", bptypes[(int) b->type].description); | |
3973 | } | |
c4093a6a JM |
3974 | |
3975 | /* 3 */ | |
3976 | annotate_field (2); | |
0d381245 VP |
3977 | if (part_of_multiple) |
3978 | ui_out_field_skip (uiout, "disp"); | |
3979 | else | |
2cec12e5 | 3980 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 3981 | |
c4093a6a JM |
3982 | |
3983 | /* 4 */ | |
3984 | annotate_field (3); | |
0d381245 | 3985 | if (part_of_multiple) |
54e52265 | 3986 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 3987 | else |
54e52265 VP |
3988 | ui_out_field_fmt (uiout, "enabled", "%c", |
3989 | bpenables[(int) b->enable_state]); | |
3990 | ui_out_spaces (uiout, 2); | |
0d381245 | 3991 | |
c4093a6a JM |
3992 | |
3993 | /* 5 and 6 */ | |
3994 | strcpy (wrap_indent, " "); | |
79a45b7d | 3995 | if (opts.addressprint) |
75ac9d7b | 3996 | { |
a6d9a66e | 3997 | if (print_address_bits <= 32) |
75ac9d7b MS |
3998 | strcat (wrap_indent, " "); |
3999 | else | |
4000 | strcat (wrap_indent, " "); | |
4001 | } | |
c906108c | 4002 | |
3086aeae | 4003 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 VP |
4004 | { |
4005 | /* Although the print_one can possibly print | |
4006 | all locations, calling it here is not likely | |
4007 | to get any nice result. So, make sure there's | |
4008 | just one location. */ | |
4009 | gdb_assert (b->loc == NULL || b->loc->next == NULL); | |
a6d9a66e | 4010 | b->ops->print_one (b, last_loc); |
0d381245 | 4011 | } |
3086aeae DJ |
4012 | else |
4013 | switch (b->type) | |
4014 | { | |
4015 | case bp_none: | |
4016 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 4017 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 4018 | break; |
c906108c | 4019 | |
3086aeae DJ |
4020 | case bp_watchpoint: |
4021 | case bp_hardware_watchpoint: | |
4022 | case bp_read_watchpoint: | |
4023 | case bp_access_watchpoint: | |
4024 | /* Field 4, the address, is omitted (which makes the columns | |
4025 | not line up too nicely with the headers, but the effect | |
4026 | is relatively readable). */ | |
79a45b7d | 4027 | if (opts.addressprint) |
3086aeae DJ |
4028 | ui_out_field_skip (uiout, "addr"); |
4029 | annotate_field (5); | |
fa8a61dc | 4030 | ui_out_field_string (uiout, "what", b->exp_string); |
3086aeae DJ |
4031 | break; |
4032 | ||
3086aeae DJ |
4033 | case bp_breakpoint: |
4034 | case bp_hardware_breakpoint: | |
4035 | case bp_until: | |
4036 | case bp_finish: | |
4037 | case bp_longjmp: | |
4038 | case bp_longjmp_resume: | |
4039 | case bp_step_resume: | |
3086aeae DJ |
4040 | case bp_watchpoint_scope: |
4041 | case bp_call_dummy: | |
4042 | case bp_shlib_event: | |
4043 | case bp_thread_event: | |
4044 | case bp_overlay_event: | |
0fd8e87f | 4045 | case bp_longjmp_master: |
1042e4c0 | 4046 | case bp_tracepoint: |
4efc6507 | 4047 | case bp_jit_event: |
79a45b7d | 4048 | if (opts.addressprint) |
3086aeae DJ |
4049 | { |
4050 | annotate_field (4); | |
54e52265 | 4051 | if (header_of_multiple) |
0d381245 | 4052 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 4053 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 4054 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 4055 | else |
5af949e3 UW |
4056 | ui_out_field_core_addr (uiout, "addr", |
4057 | loc->gdbarch, loc->address); | |
3086aeae DJ |
4058 | } |
4059 | annotate_field (5); | |
0d381245 VP |
4060 | if (!header_of_multiple) |
4061 | print_breakpoint_location (b, loc, wrap_indent, stb); | |
4062 | if (b->loc) | |
a6d9a66e | 4063 | *last_loc = b->loc; |
3086aeae DJ |
4064 | break; |
4065 | } | |
c906108c | 4066 | |
6c95b8df PA |
4067 | |
4068 | /* For backward compatibility, don't display inferiors unless there | |
4069 | are several. */ | |
4070 | if (loc != NULL | |
4071 | && !header_of_multiple | |
4072 | && (allflag | |
4073 | || (!gdbarch_has_global_breakpoints (target_gdbarch) | |
4074 | && (number_of_program_spaces () > 1 | |
4075 | || number_of_inferiors () > 1) | |
4076 | && loc->owner->type != bp_catchpoint))) | |
4077 | { | |
4078 | struct inferior *inf; | |
4079 | int first = 1; | |
4080 | ||
4081 | for (inf = inferior_list; inf != NULL; inf = inf->next) | |
4082 | { | |
4083 | if (inf->pspace == loc->pspace) | |
4084 | { | |
4085 | if (first) | |
4086 | { | |
4087 | first = 0; | |
4088 | ui_out_text (uiout, " inf "); | |
4089 | } | |
4090 | else | |
4091 | ui_out_text (uiout, ", "); | |
4092 | ui_out_text (uiout, plongest (inf->num)); | |
4093 | } | |
4094 | } | |
4095 | } | |
4096 | ||
4a306c9a | 4097 | if (!part_of_multiple) |
c4093a6a | 4098 | { |
4a306c9a JB |
4099 | if (b->thread != -1) |
4100 | { | |
4101 | /* FIXME: This seems to be redundant and lost here; see the | |
4102 | "stop only in" line a little further down. */ | |
4103 | ui_out_text (uiout, " thread "); | |
4104 | ui_out_field_int (uiout, "thread", b->thread); | |
4105 | } | |
4106 | else if (b->task != 0) | |
4107 | { | |
4108 | ui_out_text (uiout, " task "); | |
4109 | ui_out_field_int (uiout, "task", b->task); | |
4110 | } | |
c4093a6a JM |
4111 | } |
4112 | ||
8b93c638 | 4113 | ui_out_text (uiout, "\n"); |
c4093a6a | 4114 | |
0d381245 | 4115 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
4116 | { |
4117 | annotate_field (6); | |
8b93c638 | 4118 | ui_out_text (uiout, "\tstop only in stack frame at "); |
818dd999 AC |
4119 | /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside |
4120 | the frame ID. */ | |
5af949e3 UW |
4121 | ui_out_field_core_addr (uiout, "frame", |
4122 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 4123 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
4124 | } |
4125 | ||
0d381245 | 4126 | if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b)) |
c4093a6a | 4127 | { |
f7f9143b JB |
4128 | /* We do not print the condition for Ada exception catchpoints |
4129 | because the condition is an internal implementation detail | |
4130 | that we do not want to expose to the user. */ | |
c4093a6a | 4131 | annotate_field (7); |
1042e4c0 SS |
4132 | if (b->type == bp_tracepoint) |
4133 | ui_out_text (uiout, "\ttrace only if "); | |
4134 | else | |
4135 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 JJ |
4136 | ui_out_field_string (uiout, "cond", b->cond_string); |
4137 | ui_out_text (uiout, "\n"); | |
4138 | } | |
4139 | ||
0d381245 | 4140 | if (!part_of_multiple && b->thread != -1) |
c4093a6a JM |
4141 | { |
4142 | /* FIXME should make an annotation for this */ | |
8b93c638 JM |
4143 | ui_out_text (uiout, "\tstop only in thread "); |
4144 | ui_out_field_int (uiout, "thread", b->thread); | |
4145 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
4146 | } |
4147 | ||
63c715c6 | 4148 | if (!part_of_multiple && b->hit_count) |
c4093a6a JM |
4149 | { |
4150 | /* FIXME should make an annotation for this */ | |
8b93c638 JM |
4151 | if (ep_is_catchpoint (b)) |
4152 | ui_out_text (uiout, "\tcatchpoint"); | |
4153 | else | |
4154 | ui_out_text (uiout, "\tbreakpoint"); | |
4155 | ui_out_text (uiout, " already hit "); | |
4156 | ui_out_field_int (uiout, "times", b->hit_count); | |
4157 | if (b->hit_count == 1) | |
4158 | ui_out_text (uiout, " time\n"); | |
4159 | else | |
4160 | ui_out_text (uiout, " times\n"); | |
c4093a6a JM |
4161 | } |
4162 | ||
fb40c209 AC |
4163 | /* Output the count also if it is zero, but only if this is |
4164 | mi. FIXME: Should have a better test for this. */ | |
9dc5e2a9 | 4165 | if (ui_out_is_mi_like_p (uiout)) |
63c715c6 | 4166 | if (!part_of_multiple && b->hit_count == 0) |
fb40c209 | 4167 | ui_out_field_int (uiout, "times", b->hit_count); |
8b93c638 | 4168 | |
0d381245 | 4169 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
4170 | { |
4171 | annotate_field (8); | |
8b93c638 JM |
4172 | ui_out_text (uiout, "\tignore next "); |
4173 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
4174 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 4175 | } |
059fb39f PM |
4176 | |
4177 | l = b->commands; | |
4178 | if (!part_of_multiple && l) | |
c4093a6a | 4179 | { |
3b31d625 EZ |
4180 | struct cleanup *script_chain; |
4181 | ||
c4093a6a | 4182 | annotate_field (9); |
3b31d625 | 4183 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 4184 | print_command_lines (uiout, l, 4); |
3b31d625 | 4185 | do_cleanups (script_chain); |
c4093a6a | 4186 | } |
d24317b4 | 4187 | |
1042e4c0 SS |
4188 | if (!part_of_multiple && b->pass_count) |
4189 | { | |
4190 | annotate_field (10); | |
4191 | ui_out_text (uiout, "\tpass count "); | |
4192 | ui_out_field_int (uiout, "pass", b->pass_count); | |
4193 | ui_out_text (uiout, " \n"); | |
4194 | } | |
4195 | ||
4196 | if (!part_of_multiple && b->step_count) | |
4197 | { | |
4198 | annotate_field (11); | |
4199 | ui_out_text (uiout, "\tstep count "); | |
4200 | ui_out_field_int (uiout, "step", b->step_count); | |
4201 | ui_out_text (uiout, " \n"); | |
4202 | } | |
4203 | ||
4204 | if (!part_of_multiple && b->actions) | |
4205 | { | |
4206 | struct action_line *action; | |
4207 | annotate_field (12); | |
4208 | for (action = b->actions; action; action = action->next) | |
4209 | { | |
4210 | ui_out_text (uiout, " A\t"); | |
4211 | ui_out_text (uiout, action->action); | |
4212 | ui_out_text (uiout, "\n"); | |
4213 | } | |
4214 | } | |
4215 | ||
d24317b4 VP |
4216 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
4217 | { | |
4218 | if (b->addr_string) | |
4219 | ui_out_field_string (uiout, "original-location", b->addr_string); | |
4220 | else if (b->exp_string) | |
4221 | ui_out_field_string (uiout, "original-location", b->exp_string); | |
4222 | } | |
4223 | ||
3b31d625 | 4224 | do_cleanups (bkpt_chain); |
8b93c638 | 4225 | do_cleanups (old_chain); |
c4093a6a | 4226 | } |
c5aa993b | 4227 | |
0d381245 VP |
4228 | static void |
4229 | print_one_breakpoint (struct breakpoint *b, | |
6c95b8df PA |
4230 | struct bp_location **last_loc, int print_address_bits, |
4231 | int allflag) | |
0d381245 | 4232 | { |
6c95b8df PA |
4233 | print_one_breakpoint_location (b, NULL, 0, last_loc, |
4234 | print_address_bits, allflag); | |
0d381245 VP |
4235 | |
4236 | /* If this breakpoint has custom print function, | |
4237 | it's already printed. Otherwise, print individual | |
4238 | locations, if any. */ | |
4239 | if (b->ops == NULL || b->ops->print_one == NULL) | |
4240 | { | |
4241 | /* If breakpoint has a single location that is | |
4242 | disabled, we print it as if it had | |
4243 | several locations, since otherwise it's hard to | |
4244 | represent "breakpoint enabled, location disabled" | |
a5606eee VP |
4245 | situation. |
4246 | Note that while hardware watchpoints have | |
4247 | several locations internally, that's no a property | |
4248 | exposed to user. */ | |
0d381245 | 4249 | if (b->loc |
a5606eee | 4250 | && !is_hardware_watchpoint (b) |
0d381245 | 4251 | && (b->loc->next || !b->loc->enabled) |
a5606eee | 4252 | && !ui_out_is_mi_like_p (uiout)) |
0d381245 VP |
4253 | { |
4254 | struct bp_location *loc; | |
4255 | int n = 1; | |
4256 | for (loc = b->loc; loc; loc = loc->next, ++n) | |
a6d9a66e | 4257 | print_one_breakpoint_location (b, loc, n, last_loc, |
6c95b8df | 4258 | print_address_bits, allflag); |
0d381245 VP |
4259 | } |
4260 | } | |
4261 | } | |
4262 | ||
a6d9a66e UW |
4263 | static int |
4264 | breakpoint_address_bits (struct breakpoint *b) | |
4265 | { | |
4266 | int print_address_bits = 0; | |
4267 | struct bp_location *loc; | |
4268 | ||
4269 | for (loc = b->loc; loc; loc = loc->next) | |
4270 | { | |
c561c276 | 4271 | int addr_bit = gdbarch_addr_bit (loc->gdbarch); |
a6d9a66e UW |
4272 | if (addr_bit > print_address_bits) |
4273 | print_address_bits = addr_bit; | |
4274 | } | |
4275 | ||
4276 | return print_address_bits; | |
4277 | } | |
0d381245 | 4278 | |
c4093a6a JM |
4279 | struct captured_breakpoint_query_args |
4280 | { | |
4281 | int bnum; | |
4282 | }; | |
c5aa993b | 4283 | |
c4093a6a | 4284 | static int |
2b65245e | 4285 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
4286 | { |
4287 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 4288 | struct breakpoint *b; |
a6d9a66e | 4289 | struct bp_location *dummy_loc = NULL; |
c4093a6a JM |
4290 | ALL_BREAKPOINTS (b) |
4291 | { | |
4292 | if (args->bnum == b->number) | |
c5aa993b | 4293 | { |
a6d9a66e | 4294 | int print_address_bits = breakpoint_address_bits (b); |
6c95b8df | 4295 | print_one_breakpoint (b, &dummy_loc, print_address_bits, 0); |
c4093a6a | 4296 | return GDB_RC_OK; |
c5aa993b | 4297 | } |
c4093a6a JM |
4298 | } |
4299 | return GDB_RC_NONE; | |
4300 | } | |
c5aa993b | 4301 | |
c4093a6a | 4302 | enum gdb_rc |
ce43223b | 4303 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, char **error_message) |
c4093a6a JM |
4304 | { |
4305 | struct captured_breakpoint_query_args args; | |
4306 | args.bnum = bnum; | |
4307 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4308 | an error. */ | |
b0b13bb4 DJ |
4309 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
4310 | error_message, RETURN_MASK_ALL) < 0) | |
4311 | return GDB_RC_FAIL; | |
4312 | else | |
4313 | return GDB_RC_OK; | |
c4093a6a | 4314 | } |
c5aa993b | 4315 | |
7f3b0473 AC |
4316 | /* Return non-zero if B is user settable (breakpoints, watchpoints, |
4317 | catchpoints, et.al.). */ | |
4318 | ||
4319 | static int | |
4320 | user_settable_breakpoint (const struct breakpoint *b) | |
4321 | { | |
4322 | return (b->type == bp_breakpoint | |
ce78b96d | 4323 | || b->type == bp_catchpoint |
7f3b0473 | 4324 | || b->type == bp_hardware_breakpoint |
1042e4c0 | 4325 | || b->type == bp_tracepoint |
7f3b0473 AC |
4326 | || b->type == bp_watchpoint |
4327 | || b->type == bp_read_watchpoint | |
4328 | || b->type == bp_access_watchpoint | |
4329 | || b->type == bp_hardware_watchpoint); | |
4330 | } | |
4331 | ||
4332 | /* Print information on user settable breakpoint (watchpoint, etc) | |
4333 | number BNUM. If BNUM is -1 print all user settable breakpoints. | |
4334 | If ALLFLAG is non-zero, include non- user settable breakpoints. */ | |
c906108c | 4335 | |
c4093a6a | 4336 | static void |
fba45db2 | 4337 | breakpoint_1 (int bnum, int allflag) |
c4093a6a | 4338 | { |
52f0bd74 | 4339 | struct breakpoint *b; |
a6d9a66e | 4340 | struct bp_location *last_loc = NULL; |
7f3b0473 | 4341 | int nr_printable_breakpoints; |
3b31d625 | 4342 | struct cleanup *bkpttbl_chain; |
79a45b7d | 4343 | struct value_print_options opts; |
a6d9a66e | 4344 | int print_address_bits = 0; |
c4093a6a | 4345 | |
79a45b7d TT |
4346 | get_user_print_options (&opts); |
4347 | ||
a6d9a66e UW |
4348 | /* Compute the number of rows in the table, as well as the |
4349 | size required for address fields. */ | |
7f3b0473 AC |
4350 | nr_printable_breakpoints = 0; |
4351 | ALL_BREAKPOINTS (b) | |
4352 | if (bnum == -1 | |
4353 | || bnum == b->number) | |
4354 | { | |
4355 | if (allflag || user_settable_breakpoint (b)) | |
a6d9a66e UW |
4356 | { |
4357 | int addr_bit = breakpoint_address_bits (b); | |
4358 | if (addr_bit > print_address_bits) | |
4359 | print_address_bits = addr_bit; | |
4360 | ||
4361 | nr_printable_breakpoints++; | |
4362 | } | |
7f3b0473 AC |
4363 | } |
4364 | ||
79a45b7d | 4365 | if (opts.addressprint) |
3b31d625 EZ |
4366 | bkpttbl_chain |
4367 | = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints, | |
4368 | "BreakpointTable"); | |
8b93c638 | 4369 | else |
3b31d625 EZ |
4370 | bkpttbl_chain |
4371 | = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints, | |
4372 | "BreakpointTable"); | |
8b93c638 | 4373 | |
7f3b0473 | 4374 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
4375 | annotate_breakpoints_headers (); |
4376 | if (nr_printable_breakpoints > 0) | |
4377 | annotate_field (0); | |
0d381245 | 4378 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
4379 | if (nr_printable_breakpoints > 0) |
4380 | annotate_field (1); | |
4381 | ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */ | |
4382 | if (nr_printable_breakpoints > 0) | |
4383 | annotate_field (2); | |
4384 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ | |
4385 | if (nr_printable_breakpoints > 0) | |
4386 | annotate_field (3); | |
54e52265 | 4387 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 4388 | if (opts.addressprint) |
7f3b0473 | 4389 | { |
d7faa9e7 AC |
4390 | if (nr_printable_breakpoints > 0) |
4391 | annotate_field (4); | |
a6d9a66e | 4392 | if (print_address_bits <= 32) |
b25959ec | 4393 | ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */ |
7f3b0473 | 4394 | else |
b25959ec | 4395 | ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */ |
7f3b0473 | 4396 | } |
d7faa9e7 AC |
4397 | if (nr_printable_breakpoints > 0) |
4398 | annotate_field (5); | |
4399 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
4400 | ui_out_table_body (uiout); | |
4401 | if (nr_printable_breakpoints > 0) | |
4402 | annotate_breakpoints_table (); | |
7f3b0473 | 4403 | |
c4093a6a JM |
4404 | ALL_BREAKPOINTS (b) |
4405 | if (bnum == -1 | |
4406 | || bnum == b->number) | |
4407 | { | |
4408 | /* We only print out user settable breakpoints unless the | |
4409 | allflag is set. */ | |
7f3b0473 | 4410 | if (allflag || user_settable_breakpoint (b)) |
6c95b8df | 4411 | print_one_breakpoint (b, &last_loc, print_address_bits, allflag); |
c4093a6a JM |
4412 | } |
4413 | ||
3b31d625 | 4414 | do_cleanups (bkpttbl_chain); |
698384cd | 4415 | |
7f3b0473 | 4416 | if (nr_printable_breakpoints == 0) |
c906108c | 4417 | { |
8b93c638 JM |
4418 | if (bnum == -1) |
4419 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); | |
4420 | else | |
4421 | ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n", | |
4422 | bnum); | |
c906108c SS |
4423 | } |
4424 | else | |
c4093a6a | 4425 | { |
a6d9a66e UW |
4426 | if (last_loc && !server_command) |
4427 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 4428 | } |
c906108c | 4429 | |
c4093a6a JM |
4430 | /* FIXME? Should this be moved up so that it is only called when |
4431 | there have been breakpoints? */ | |
c906108c SS |
4432 | annotate_breakpoints_table_end (); |
4433 | } | |
4434 | ||
c906108c | 4435 | static void |
fba45db2 | 4436 | breakpoints_info (char *bnum_exp, int from_tty) |
c906108c SS |
4437 | { |
4438 | int bnum = -1; | |
4439 | ||
4440 | if (bnum_exp) | |
bb518678 | 4441 | bnum = parse_and_eval_long (bnum_exp); |
c906108c SS |
4442 | |
4443 | breakpoint_1 (bnum, 0); | |
4444 | } | |
4445 | ||
7a292a7a | 4446 | static void |
fba45db2 | 4447 | maintenance_info_breakpoints (char *bnum_exp, int from_tty) |
c906108c SS |
4448 | { |
4449 | int bnum = -1; | |
4450 | ||
4451 | if (bnum_exp) | |
bb518678 | 4452 | bnum = parse_and_eval_long (bnum_exp); |
c906108c SS |
4453 | |
4454 | breakpoint_1 (bnum, 1); | |
4455 | } | |
4456 | ||
0d381245 | 4457 | static int |
714835d5 | 4458 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 4459 | struct program_space *pspace, |
714835d5 | 4460 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
4461 | { |
4462 | struct bp_location *bl = b->loc; | |
4463 | for (; bl; bl = bl->next) | |
4464 | { | |
6c95b8df PA |
4465 | if (bl->pspace == pspace |
4466 | && bl->address == pc | |
0d381245 VP |
4467 | && (!overlay_debugging || bl->section == section)) |
4468 | return 1; | |
4469 | } | |
4470 | return 0; | |
4471 | } | |
4472 | ||
6c95b8df PA |
4473 | /* Print a message describing any breakpoints set at PC. This |
4474 | concerns with logical breakpoints, so we match program spaces, not | |
4475 | address spaces. */ | |
c906108c SS |
4476 | |
4477 | static void | |
6c95b8df PA |
4478 | describe_other_breakpoints (struct gdbarch *gdbarch, |
4479 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 4480 | struct obj_section *section, int thread) |
c906108c | 4481 | { |
52f0bd74 AC |
4482 | int others = 0; |
4483 | struct breakpoint *b; | |
c906108c SS |
4484 | |
4485 | ALL_BREAKPOINTS (b) | |
6c95b8df | 4486 | others += breakpoint_has_pc (b, pspace, pc, section); |
c906108c SS |
4487 | if (others > 0) |
4488 | { | |
a3f17187 AC |
4489 | if (others == 1) |
4490 | printf_filtered (_("Note: breakpoint ")); | |
4491 | else /* if (others == ???) */ | |
4492 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 4493 | ALL_BREAKPOINTS (b) |
6c95b8df | 4494 | if (breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
4495 | { |
4496 | others--; | |
4497 | printf_filtered ("%d", b->number); | |
4498 | if (b->thread == -1 && thread != -1) | |
4499 | printf_filtered (" (all threads)"); | |
4500 | else if (b->thread != -1) | |
4501 | printf_filtered (" (thread %d)", b->thread); | |
4502 | printf_filtered ("%s%s ", | |
059fb39f | 4503 | ((b->enable_state == bp_disabled |
8bea4e01 UW |
4504 | || b->enable_state == bp_call_disabled |
4505 | || b->enable_state == bp_startup_disabled) | |
0d381245 VP |
4506 | ? " (disabled)" |
4507 | : b->enable_state == bp_permanent | |
4508 | ? " (permanent)" | |
4509 | : ""), | |
4510 | (others > 1) ? "," | |
4511 | : ((others == 1) ? " and" : "")); | |
4512 | } | |
a3f17187 | 4513 | printf_filtered (_("also set at pc ")); |
5af949e3 | 4514 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
4515 | printf_filtered (".\n"); |
4516 | } | |
4517 | } | |
4518 | \f | |
4519 | /* Set the default place to put a breakpoint | |
4520 | for the `break' command with no arguments. */ | |
4521 | ||
4522 | void | |
6c95b8df PA |
4523 | set_default_breakpoint (int valid, struct program_space *pspace, |
4524 | CORE_ADDR addr, struct symtab *symtab, | |
fba45db2 | 4525 | int line) |
c906108c SS |
4526 | { |
4527 | default_breakpoint_valid = valid; | |
6c95b8df | 4528 | default_breakpoint_pspace = pspace; |
c906108c SS |
4529 | default_breakpoint_address = addr; |
4530 | default_breakpoint_symtab = symtab; | |
4531 | default_breakpoint_line = line; | |
4532 | } | |
4533 | ||
e4f237da KB |
4534 | /* Return true iff it is meaningful to use the address member of |
4535 | BPT. For some breakpoint types, the address member is irrelevant | |
4536 | and it makes no sense to attempt to compare it to other addresses | |
4537 | (or use it for any other purpose either). | |
4538 | ||
4539 | More specifically, each of the following breakpoint types will always | |
876fa593 JK |
4540 | have a zero valued address and we don't want to mark breakpoints of any of |
4541 | these types to be a duplicate of an actual breakpoint at address zero: | |
e4f237da KB |
4542 | |
4543 | bp_watchpoint | |
4544 | bp_hardware_watchpoint | |
4545 | bp_read_watchpoint | |
4546 | bp_access_watchpoint | |
fe798b75 | 4547 | bp_catchpoint */ |
e4f237da KB |
4548 | |
4549 | static int | |
4550 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
4551 | { | |
4552 | enum bptype type = bpt->type; | |
4553 | ||
4554 | return (type != bp_watchpoint | |
4555 | && type != bp_hardware_watchpoint | |
4556 | && type != bp_read_watchpoint | |
4557 | && type != bp_access_watchpoint | |
fe798b75 | 4558 | && type != bp_catchpoint); |
e4f237da KB |
4559 | } |
4560 | ||
6c95b8df PA |
4561 | /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the |
4562 | same breakpoint location. In most targets, this can only be true | |
4563 | if ASPACE1 matches ASPACE2. On targets that have global | |
4564 | breakpoints, the address space doesn't really matter. */ | |
4565 | ||
4566 | static int | |
4567 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, | |
4568 | struct address_space *aspace2, CORE_ADDR addr2) | |
4569 | { | |
4570 | return ((gdbarch_has_global_breakpoints (target_gdbarch) | |
4571 | || aspace1 == aspace2) | |
4572 | && addr1 == addr2); | |
4573 | } | |
4574 | ||
76897487 KB |
4575 | static void |
4576 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
4577 | int bnum, int have_bnum) | |
4578 | { | |
4579 | char astr1[40]; | |
4580 | char astr2[40]; | |
4581 | ||
bb599908 PH |
4582 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
4583 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 4584 | if (have_bnum) |
8a3fe4f8 | 4585 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
4586 | bnum, astr1, astr2); |
4587 | else | |
8a3fe4f8 | 4588 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
4589 | } |
4590 | ||
4591 | /* Adjust a breakpoint's address to account for architectural constraints | |
4592 | on breakpoint placement. Return the adjusted address. Note: Very | |
4593 | few targets require this kind of adjustment. For most targets, | |
4594 | this function is simply the identity function. */ | |
4595 | ||
4596 | static CORE_ADDR | |
a6d9a66e UW |
4597 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
4598 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 4599 | { |
a6d9a66e | 4600 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
4601 | { |
4602 | /* Very few targets need any kind of breakpoint adjustment. */ | |
4603 | return bpaddr; | |
4604 | } | |
88f7da05 KB |
4605 | else if (bptype == bp_watchpoint |
4606 | || bptype == bp_hardware_watchpoint | |
4607 | || bptype == bp_read_watchpoint | |
4608 | || bptype == bp_access_watchpoint | |
fe798b75 | 4609 | || bptype == bp_catchpoint) |
88f7da05 KB |
4610 | { |
4611 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
4612 | have their addresses modified. */ | |
4613 | return bpaddr; | |
4614 | } | |
76897487 KB |
4615 | else |
4616 | { | |
4617 | CORE_ADDR adjusted_bpaddr; | |
4618 | ||
4619 | /* Some targets have architectural constraints on the placement | |
4620 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 4621 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
4622 | |
4623 | /* An adjusted breakpoint address can significantly alter | |
4624 | a user's expectations. Print a warning if an adjustment | |
4625 | is required. */ | |
4626 | if (adjusted_bpaddr != bpaddr) | |
4627 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
4628 | ||
4629 | return adjusted_bpaddr; | |
4630 | } | |
4631 | } | |
4632 | ||
7cc221ef DJ |
4633 | /* Allocate a struct bp_location. */ |
4634 | ||
26bb91f3 | 4635 | static struct bp_location * |
39d61571 | 4636 | allocate_bp_location (struct breakpoint *bpt) |
7cc221ef DJ |
4637 | { |
4638 | struct bp_location *loc, *loc_p; | |
4639 | ||
4640 | loc = xmalloc (sizeof (struct bp_location)); | |
4641 | memset (loc, 0, sizeof (*loc)); | |
4642 | ||
e049a4b5 | 4643 | loc->owner = bpt; |
511a6cd4 | 4644 | loc->cond = NULL; |
0d381245 VP |
4645 | loc->shlib_disabled = 0; |
4646 | loc->enabled = 1; | |
e049a4b5 | 4647 | |
39d61571 | 4648 | switch (bpt->type) |
e049a4b5 DJ |
4649 | { |
4650 | case bp_breakpoint: | |
1042e4c0 | 4651 | case bp_tracepoint: |
e049a4b5 DJ |
4652 | case bp_until: |
4653 | case bp_finish: | |
4654 | case bp_longjmp: | |
4655 | case bp_longjmp_resume: | |
4656 | case bp_step_resume: | |
e049a4b5 DJ |
4657 | case bp_watchpoint_scope: |
4658 | case bp_call_dummy: | |
4659 | case bp_shlib_event: | |
4660 | case bp_thread_event: | |
4661 | case bp_overlay_event: | |
4efc6507 | 4662 | case bp_jit_event: |
0fd8e87f | 4663 | case bp_longjmp_master: |
e049a4b5 DJ |
4664 | loc->loc_type = bp_loc_software_breakpoint; |
4665 | break; | |
4666 | case bp_hardware_breakpoint: | |
4667 | loc->loc_type = bp_loc_hardware_breakpoint; | |
4668 | break; | |
4669 | case bp_hardware_watchpoint: | |
4670 | case bp_read_watchpoint: | |
4671 | case bp_access_watchpoint: | |
4672 | loc->loc_type = bp_loc_hardware_watchpoint; | |
4673 | break; | |
4674 | case bp_watchpoint: | |
ce78b96d | 4675 | case bp_catchpoint: |
e049a4b5 DJ |
4676 | loc->loc_type = bp_loc_other; |
4677 | break; | |
4678 | default: | |
e2e0b3e5 | 4679 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
4680 | } |
4681 | ||
7cc221ef DJ |
4682 | return loc; |
4683 | } | |
4684 | ||
fe3f5fa8 VP |
4685 | static void free_bp_location (struct bp_location *loc) |
4686 | { | |
4687 | if (loc->cond) | |
4688 | xfree (loc->cond); | |
74960c60 VP |
4689 | |
4690 | if (loc->function_name) | |
4691 | xfree (loc->function_name); | |
4692 | ||
fe3f5fa8 VP |
4693 | xfree (loc); |
4694 | } | |
4695 | ||
0d381245 VP |
4696 | /* Helper to set_raw_breakpoint below. Creates a breakpoint |
4697 | that has type BPTYPE and has no locations as yet. */ | |
63c252f8 | 4698 | /* This function is used in gdbtk sources and thus can not be made static. */ |
c906108c | 4699 | |
c40e75cd | 4700 | static struct breakpoint * |
a6d9a66e UW |
4701 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, |
4702 | enum bptype bptype) | |
c906108c | 4703 | { |
52f0bd74 | 4704 | struct breakpoint *b, *b1; |
c906108c SS |
4705 | |
4706 | b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint)); | |
4707 | memset (b, 0, sizeof (*b)); | |
2219d63c | 4708 | |
4d28f7a8 | 4709 | b->type = bptype; |
a6d9a66e | 4710 | b->gdbarch = gdbarch; |
c906108c SS |
4711 | b->language = current_language->la_language; |
4712 | b->input_radix = input_radix; | |
4713 | b->thread = -1; | |
b5de0fa7 | 4714 | b->enable_state = bp_enabled; |
c906108c SS |
4715 | b->next = 0; |
4716 | b->silent = 0; | |
4717 | b->ignore_count = 0; | |
4718 | b->commands = NULL; | |
818dd999 | 4719 | b->frame_id = null_frame_id; |
3a3e9ee3 | 4720 | b->forked_inferior_pid = null_ptid; |
c906108c | 4721 | b->exec_pathname = NULL; |
a96d9b2e | 4722 | b->syscalls_to_be_caught = NULL; |
3086aeae | 4723 | b->ops = NULL; |
0d381245 | 4724 | b->condition_not_parsed = 0; |
c906108c SS |
4725 | |
4726 | /* Add this breakpoint to the end of the chain | |
4727 | so that a list of breakpoints will come out in order | |
4728 | of increasing numbers. */ | |
4729 | ||
4730 | b1 = breakpoint_chain; | |
4731 | if (b1 == 0) | |
4732 | breakpoint_chain = b; | |
4733 | else | |
4734 | { | |
4735 | while (b1->next) | |
4736 | b1 = b1->next; | |
4737 | b1->next = b; | |
4738 | } | |
0d381245 VP |
4739 | return b; |
4740 | } | |
4741 | ||
4742 | /* Initialize loc->function_name. */ | |
4743 | static void | |
4744 | set_breakpoint_location_function (struct bp_location *loc) | |
4745 | { | |
4746 | if (loc->owner->type == bp_breakpoint | |
1042e4c0 SS |
4747 | || loc->owner->type == bp_hardware_breakpoint |
4748 | || loc->owner->type == bp_tracepoint) | |
0d381245 VP |
4749 | { |
4750 | find_pc_partial_function (loc->address, &(loc->function_name), | |
4751 | NULL, NULL); | |
4752 | if (loc->function_name) | |
4753 | loc->function_name = xstrdup (loc->function_name); | |
4754 | } | |
4755 | } | |
4756 | ||
a6d9a66e UW |
4757 | /* Attempt to determine architecture of location identified by SAL. */ |
4758 | static struct gdbarch * | |
4759 | get_sal_arch (struct symtab_and_line sal) | |
4760 | { | |
4761 | if (sal.section) | |
4762 | return get_objfile_arch (sal.section->objfile); | |
4763 | if (sal.symtab) | |
4764 | return get_objfile_arch (sal.symtab->objfile); | |
4765 | ||
4766 | return NULL; | |
4767 | } | |
4768 | ||
0d381245 VP |
4769 | /* set_raw_breakpoint is a low level routine for allocating and |
4770 | partially initializing a breakpoint of type BPTYPE. The newly | |
4771 | created breakpoint's address, section, source file name, and line | |
4772 | number are provided by SAL. The newly created and partially | |
4773 | initialized breakpoint is added to the breakpoint chain and | |
4774 | is also returned as the value of this function. | |
4775 | ||
4776 | It is expected that the caller will complete the initialization of | |
4777 | the newly created breakpoint struct as well as output any status | |
4778 | information regarding the creation of a new breakpoint. In | |
4779 | particular, set_raw_breakpoint does NOT set the breakpoint | |
4780 | number! Care should be taken to not allow an error to occur | |
4781 | prior to completing the initialization of the breakpoint. If this | |
4782 | should happen, a bogus breakpoint will be left on the chain. */ | |
4783 | ||
63c252f8 | 4784 | struct breakpoint * |
a6d9a66e UW |
4785 | set_raw_breakpoint (struct gdbarch *gdbarch, |
4786 | struct symtab_and_line sal, enum bptype bptype) | |
0d381245 | 4787 | { |
a6d9a66e | 4788 | struct breakpoint *b = set_raw_breakpoint_without_location (gdbarch, bptype); |
0d381245 | 4789 | CORE_ADDR adjusted_address; |
a6d9a66e UW |
4790 | struct gdbarch *loc_gdbarch; |
4791 | ||
4792 | loc_gdbarch = get_sal_arch (sal); | |
4793 | if (!loc_gdbarch) | |
4794 | loc_gdbarch = b->gdbarch; | |
0d381245 | 4795 | |
6c95b8df PA |
4796 | if (bptype != bp_catchpoint) |
4797 | gdb_assert (sal.pspace != NULL); | |
4798 | ||
0d381245 VP |
4799 | /* Adjust the breakpoint's address prior to allocating a location. |
4800 | Once we call allocate_bp_location(), that mostly uninitialized | |
4801 | location will be placed on the location chain. Adjustment of the | |
8defab1a | 4802 | breakpoint may cause target_read_memory() to be called and we do |
0d381245 VP |
4803 | not want its scan of the location chain to find a breakpoint and |
4804 | location that's only been partially initialized. */ | |
a6d9a66e | 4805 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, sal.pc, b->type); |
0d381245 | 4806 | |
39d61571 | 4807 | b->loc = allocate_bp_location (b); |
a6d9a66e | 4808 | b->loc->gdbarch = loc_gdbarch; |
0d381245 VP |
4809 | b->loc->requested_address = sal.pc; |
4810 | b->loc->address = adjusted_address; | |
6c95b8df PA |
4811 | b->loc->pspace = sal.pspace; |
4812 | ||
4813 | /* Store the program space that was used to set the breakpoint, for | |
4814 | breakpoint resetting. */ | |
4815 | b->pspace = sal.pspace; | |
0d381245 VP |
4816 | |
4817 | if (sal.symtab == NULL) | |
4818 | b->source_file = NULL; | |
4819 | else | |
1b36a34b | 4820 | b->source_file = xstrdup (sal.symtab->filename); |
0d381245 VP |
4821 | b->loc->section = sal.section; |
4822 | b->line_number = sal.line; | |
4823 | ||
4824 | set_breakpoint_location_function (b->loc); | |
c906108c | 4825 | |
c906108c SS |
4826 | breakpoints_changed (); |
4827 | ||
4828 | return b; | |
4829 | } | |
4830 | ||
c2c6d25f JM |
4831 | |
4832 | /* Note that the breakpoint object B describes a permanent breakpoint | |
4833 | instruction, hard-wired into the inferior's code. */ | |
4834 | void | |
4835 | make_breakpoint_permanent (struct breakpoint *b) | |
4836 | { | |
0d381245 | 4837 | struct bp_location *bl; |
b5de0fa7 | 4838 | b->enable_state = bp_permanent; |
c2c6d25f | 4839 | |
0d381245 VP |
4840 | /* By definition, permanent breakpoints are already present in the code. |
4841 | Mark all locations as inserted. For now, make_breakpoint_permanent | |
4842 | is called in just one place, so it's hard to say if it's reasonable | |
4843 | to have permanent breakpoint with multiple locations or not, | |
4844 | but it's easy to implmement. */ | |
4845 | for (bl = b->loc; bl; bl = bl->next) | |
4846 | bl->inserted = 1; | |
c2c6d25f JM |
4847 | } |
4848 | ||
53a5351d | 4849 | /* Call this routine when stepping and nexting to enable a breakpoint |
0fd8e87f | 4850 | if we do a longjmp() in THREAD. When we hit that breakpoint, call |
c906108c SS |
4851 | set_longjmp_resume_breakpoint() to figure out where we are going. */ |
4852 | ||
4853 | void | |
0fd8e87f | 4854 | set_longjmp_breakpoint (int thread) |
c906108c | 4855 | { |
0fd8e87f UW |
4856 | struct breakpoint *b, *temp; |
4857 | ||
4858 | /* To avoid having to rescan all objfile symbols at every step, | |
4859 | we maintain a list of continually-inserted but always disabled | |
4860 | longjmp "master" breakpoints. Here, we simply create momentary | |
4861 | clones of those and enable them for the requested thread. */ | |
4862 | ALL_BREAKPOINTS_SAFE (b, temp) | |
6c95b8df PA |
4863 | if (b->pspace == current_program_space |
4864 | && b->type == bp_longjmp_master) | |
0fd8e87f UW |
4865 | { |
4866 | struct breakpoint *clone = clone_momentary_breakpoint (b); | |
4867 | clone->type = bp_longjmp; | |
4868 | clone->thread = thread; | |
4869 | } | |
c906108c SS |
4870 | } |
4871 | ||
611c83ae | 4872 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 4873 | void |
611c83ae | 4874 | delete_longjmp_breakpoint (int thread) |
c906108c | 4875 | { |
611c83ae | 4876 | struct breakpoint *b, *temp; |
c906108c | 4877 | |
611c83ae PA |
4878 | ALL_BREAKPOINTS_SAFE (b, temp) |
4879 | if (b->type == bp_longjmp) | |
4880 | { | |
4881 | if (b->thread == thread) | |
4882 | delete_breakpoint (b); | |
4883 | } | |
c906108c SS |
4884 | } |
4885 | ||
1900040c MS |
4886 | void |
4887 | enable_overlay_breakpoints (void) | |
4888 | { | |
52f0bd74 | 4889 | struct breakpoint *b; |
1900040c MS |
4890 | |
4891 | ALL_BREAKPOINTS (b) | |
4892 | if (b->type == bp_overlay_event) | |
4893 | { | |
4894 | b->enable_state = bp_enabled; | |
b60e7edf | 4895 | update_global_location_list (1); |
c02f5703 | 4896 | overlay_events_enabled = 1; |
1900040c MS |
4897 | } |
4898 | } | |
4899 | ||
4900 | void | |
4901 | disable_overlay_breakpoints (void) | |
4902 | { | |
52f0bd74 | 4903 | struct breakpoint *b; |
1900040c MS |
4904 | |
4905 | ALL_BREAKPOINTS (b) | |
4906 | if (b->type == bp_overlay_event) | |
4907 | { | |
4908 | b->enable_state = bp_disabled; | |
b60e7edf | 4909 | update_global_location_list (0); |
c02f5703 | 4910 | overlay_events_enabled = 0; |
1900040c MS |
4911 | } |
4912 | } | |
4913 | ||
c4093a6a | 4914 | struct breakpoint * |
a6d9a66e | 4915 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
4916 | { |
4917 | struct breakpoint *b; | |
c4093a6a | 4918 | |
a6d9a66e | 4919 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event); |
c4093a6a | 4920 | |
b5de0fa7 | 4921 | b->enable_state = bp_enabled; |
c4093a6a | 4922 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
4923 | b->addr_string |
4924 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 4925 | |
b60e7edf | 4926 | update_global_location_list_nothrow (1); |
74960c60 | 4927 | |
c4093a6a JM |
4928 | return b; |
4929 | } | |
4930 | ||
4931 | void | |
4932 | remove_thread_event_breakpoints (void) | |
4933 | { | |
4934 | struct breakpoint *b, *temp; | |
4935 | ||
4936 | ALL_BREAKPOINTS_SAFE (b, temp) | |
6c95b8df PA |
4937 | if (b->type == bp_thread_event |
4938 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
4939 | delete_breakpoint (b); |
4940 | } | |
4941 | ||
0101ce28 JJ |
4942 | struct captured_parse_breakpoint_args |
4943 | { | |
4944 | char **arg_p; | |
4945 | struct symtabs_and_lines *sals_p; | |
4946 | char ***addr_string_p; | |
4947 | int *not_found_ptr; | |
4948 | }; | |
4949 | ||
4950 | struct lang_and_radix | |
4951 | { | |
4952 | enum language lang; | |
4953 | int radix; | |
4954 | }; | |
4955 | ||
4efc6507 DE |
4956 | /* Create a breakpoint for JIT code registration and unregistration. */ |
4957 | ||
4958 | struct breakpoint * | |
4959 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
4960 | { | |
4961 | struct breakpoint *b; | |
4962 | ||
4963 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event); | |
4964 | update_global_location_list_nothrow (1); | |
4965 | return b; | |
4966 | } | |
0101ce28 | 4967 | |
cae688ec JJ |
4968 | void |
4969 | remove_solib_event_breakpoints (void) | |
4970 | { | |
4971 | struct breakpoint *b, *temp; | |
4972 | ||
4973 | ALL_BREAKPOINTS_SAFE (b, temp) | |
6c95b8df PA |
4974 | if (b->type == bp_shlib_event |
4975 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
4976 | delete_breakpoint (b); |
4977 | } | |
4978 | ||
4979 | struct breakpoint * | |
a6d9a66e | 4980 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
cae688ec JJ |
4981 | { |
4982 | struct breakpoint *b; | |
4983 | ||
a6d9a66e | 4984 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event); |
b60e7edf | 4985 | update_global_location_list_nothrow (1); |
cae688ec JJ |
4986 | return b; |
4987 | } | |
4988 | ||
4989 | /* Disable any breakpoints that are on code in shared libraries. Only | |
4990 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
4991 | ||
4992 | void | |
cb851954 | 4993 | disable_breakpoints_in_shlibs (void) |
cae688ec | 4994 | { |
876fa593 | 4995 | struct bp_location *loc, **locp_tmp; |
cae688ec | 4996 | |
876fa593 | 4997 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 4998 | { |
0d381245 VP |
4999 | struct breakpoint *b = loc->owner; |
5000 | /* We apply the check to all breakpoints, including disabled | |
5001 | for those with loc->duplicate set. This is so that when breakpoint | |
5002 | becomes enabled, or the duplicate is removed, gdb will try to insert | |
5003 | all breakpoints. If we don't set shlib_disabled here, we'll try | |
5004 | to insert those breakpoints and fail. */ | |
1042e4c0 SS |
5005 | if (((b->type == bp_breakpoint) |
5006 | || (b->type == bp_hardware_breakpoint) | |
5007 | || (b->type == bp_tracepoint)) | |
6c95b8df | 5008 | && loc->pspace == current_program_space |
0d381245 | 5009 | && !loc->shlib_disabled |
a77053c2 | 5010 | #ifdef PC_SOLIB |
0d381245 | 5011 | && PC_SOLIB (loc->address) |
a77053c2 | 5012 | #else |
6c95b8df | 5013 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 MK |
5014 | #endif |
5015 | ) | |
0d381245 VP |
5016 | { |
5017 | loc->shlib_disabled = 1; | |
5018 | } | |
cae688ec JJ |
5019 | } |
5020 | } | |
5021 | ||
84acb35a JJ |
5022 | /* Disable any breakpoints that are in in an unloaded shared library. Only |
5023 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
5024 | ||
75149521 | 5025 | static void |
84acb35a JJ |
5026 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
5027 | { | |
876fa593 | 5028 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
5029 | int disabled_shlib_breaks = 0; |
5030 | ||
c86cf029 VP |
5031 | /* SunOS a.out shared libraries are always mapped, so do not |
5032 | disable breakpoints; they will only be reported as unloaded | |
5033 | through clear_solib when GDB discards its shared library | |
5034 | list. See clear_solib for more information. */ | |
5035 | if (exec_bfd != NULL | |
5036 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
5037 | return; | |
5038 | ||
876fa593 | 5039 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 5040 | { |
0d381245 VP |
5041 | struct breakpoint *b = loc->owner; |
5042 | if ((loc->loc_type == bp_loc_hardware_breakpoint | |
5043 | || loc->loc_type == bp_loc_software_breakpoint) | |
6c95b8df | 5044 | && solib->pspace == loc->pspace |
e2dd7057 PP |
5045 | && !loc->shlib_disabled |
5046 | && (b->type == bp_breakpoint || b->type == bp_hardware_breakpoint) | |
5047 | && solib_contains_address_p (solib, loc->address)) | |
84acb35a | 5048 | { |
e2dd7057 PP |
5049 | loc->shlib_disabled = 1; |
5050 | /* At this point, we cannot rely on remove_breakpoint | |
5051 | succeeding so we must mark the breakpoint as not inserted | |
5052 | to prevent future errors occurring in remove_breakpoints. */ | |
5053 | loc->inserted = 0; | |
5054 | if (!disabled_shlib_breaks) | |
5055 | { | |
5056 | target_terminal_ours_for_output (); | |
5057 | warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""), | |
5058 | solib->so_name); | |
84acb35a | 5059 | } |
e2dd7057 | 5060 | disabled_shlib_breaks = 1; |
84acb35a JJ |
5061 | } |
5062 | } | |
84acb35a JJ |
5063 | } |
5064 | ||
ce78b96d JB |
5065 | /* FORK & VFORK catchpoints. */ |
5066 | ||
5067 | /* Implement the "insert" breakpoint_ops method for fork catchpoints. */ | |
5068 | ||
c906108c | 5069 | static void |
ce78b96d JB |
5070 | insert_catch_fork (struct breakpoint *b) |
5071 | { | |
5072 | target_insert_fork_catchpoint (PIDGET (inferior_ptid)); | |
5073 | } | |
5074 | ||
5075 | /* Implement the "remove" breakpoint_ops method for fork catchpoints. */ | |
5076 | ||
5077 | static int | |
5078 | remove_catch_fork (struct breakpoint *b) | |
5079 | { | |
5080 | return target_remove_fork_catchpoint (PIDGET (inferior_ptid)); | |
5081 | } | |
5082 | ||
5083 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
5084 | catchpoints. */ | |
5085 | ||
5086 | static int | |
5087 | breakpoint_hit_catch_fork (struct breakpoint *b) | |
5088 | { | |
5089 | return inferior_has_forked (inferior_ptid, &b->forked_inferior_pid); | |
5090 | } | |
5091 | ||
5092 | /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */ | |
5093 | ||
5094 | static enum print_stop_action | |
5095 | print_it_catch_fork (struct breakpoint *b) | |
5096 | { | |
5097 | annotate_catchpoint (b->number); | |
5098 | printf_filtered (_("\nCatchpoint %d (forked process %d), "), | |
5099 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
5100 | return PRINT_SRC_AND_LOC; | |
5101 | } | |
5102 | ||
5103 | /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */ | |
5104 | ||
5105 | static void | |
a6d9a66e | 5106 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 5107 | { |
79a45b7d TT |
5108 | struct value_print_options opts; |
5109 | ||
5110 | get_user_print_options (&opts); | |
5111 | ||
ce78b96d JB |
5112 | /* Field 4, the address, is omitted (which makes the columns |
5113 | not line up too nicely with the headers, but the effect | |
5114 | is relatively readable). */ | |
79a45b7d | 5115 | if (opts.addressprint) |
ce78b96d JB |
5116 | ui_out_field_skip (uiout, "addr"); |
5117 | annotate_field (5); | |
5118 | ui_out_text (uiout, "fork"); | |
5119 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
5120 | { | |
5121 | ui_out_text (uiout, ", process "); | |
5122 | ui_out_field_int (uiout, "what", | |
5123 | ptid_get_pid (b->forked_inferior_pid)); | |
5124 | ui_out_spaces (uiout, 1); | |
5125 | } | |
5126 | } | |
5127 | ||
5128 | /* Implement the "print_mention" breakpoint_ops method for fork | |
5129 | catchpoints. */ | |
5130 | ||
5131 | static void | |
5132 | print_mention_catch_fork (struct breakpoint *b) | |
5133 | { | |
5134 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
5135 | } | |
5136 | ||
5137 | /* The breakpoint_ops structure to be used in fork catchpoints. */ | |
5138 | ||
5139 | static struct breakpoint_ops catch_fork_breakpoint_ops = | |
5140 | { | |
5141 | insert_catch_fork, | |
5142 | remove_catch_fork, | |
5143 | breakpoint_hit_catch_fork, | |
5144 | print_it_catch_fork, | |
5145 | print_one_catch_fork, | |
5146 | print_mention_catch_fork | |
5147 | }; | |
5148 | ||
5149 | /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */ | |
5150 | ||
5151 | static void | |
5152 | insert_catch_vfork (struct breakpoint *b) | |
5153 | { | |
5154 | target_insert_vfork_catchpoint (PIDGET (inferior_ptid)); | |
5155 | } | |
5156 | ||
5157 | /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */ | |
5158 | ||
5159 | static int | |
5160 | remove_catch_vfork (struct breakpoint *b) | |
5161 | { | |
5162 | return target_remove_vfork_catchpoint (PIDGET (inferior_ptid)); | |
5163 | } | |
5164 | ||
5165 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
5166 | catchpoints. */ | |
5167 | ||
5168 | static int | |
5169 | breakpoint_hit_catch_vfork (struct breakpoint *b) | |
5170 | { | |
5171 | return inferior_has_vforked (inferior_ptid, &b->forked_inferior_pid); | |
5172 | } | |
5173 | ||
5174 | /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */ | |
5175 | ||
5176 | static enum print_stop_action | |
5177 | print_it_catch_vfork (struct breakpoint *b) | |
5178 | { | |
5179 | annotate_catchpoint (b->number); | |
5180 | printf_filtered (_("\nCatchpoint %d (vforked process %d), "), | |
5181 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
5182 | return PRINT_SRC_AND_LOC; | |
5183 | } | |
5184 | ||
5185 | /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */ | |
5186 | ||
5187 | static void | |
a6d9a66e | 5188 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 5189 | { |
79a45b7d TT |
5190 | struct value_print_options opts; |
5191 | ||
5192 | get_user_print_options (&opts); | |
ce78b96d JB |
5193 | /* Field 4, the address, is omitted (which makes the columns |
5194 | not line up too nicely with the headers, but the effect | |
5195 | is relatively readable). */ | |
79a45b7d | 5196 | if (opts.addressprint) |
ce78b96d JB |
5197 | ui_out_field_skip (uiout, "addr"); |
5198 | annotate_field (5); | |
5199 | ui_out_text (uiout, "vfork"); | |
5200 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
5201 | { | |
5202 | ui_out_text (uiout, ", process "); | |
5203 | ui_out_field_int (uiout, "what", | |
5204 | ptid_get_pid (b->forked_inferior_pid)); | |
5205 | ui_out_spaces (uiout, 1); | |
5206 | } | |
5207 | } | |
5208 | ||
5209 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
5210 | catchpoints. */ | |
5211 | ||
5212 | static void | |
5213 | print_mention_catch_vfork (struct breakpoint *b) | |
5214 | { | |
5215 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
5216 | } | |
5217 | ||
5218 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ | |
5219 | ||
5220 | static struct breakpoint_ops catch_vfork_breakpoint_ops = | |
5221 | { | |
5222 | insert_catch_vfork, | |
5223 | remove_catch_vfork, | |
5224 | breakpoint_hit_catch_vfork, | |
5225 | print_it_catch_vfork, | |
5226 | print_one_catch_vfork, | |
5227 | print_mention_catch_vfork | |
5228 | }; | |
5229 | ||
a96d9b2e SDJ |
5230 | /* Implement the "insert" breakpoint_ops method for syscall |
5231 | catchpoints. */ | |
5232 | ||
5233 | static void | |
5234 | insert_catch_syscall (struct breakpoint *b) | |
5235 | { | |
5236 | struct inferior *inf = current_inferior (); | |
5237 | ||
5238 | ++inf->total_syscalls_count; | |
5239 | if (!b->syscalls_to_be_caught) | |
5240 | ++inf->any_syscall_count; | |
5241 | else | |
5242 | { | |
5243 | int i, iter; | |
5244 | for (i = 0; | |
5245 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
5246 | i++) | |
5247 | { | |
5248 | int elem; | |
5249 | if (iter >= VEC_length (int, inf->syscalls_counts)) | |
5250 | { | |
5251 | int old_size = VEC_length (int, inf->syscalls_counts); | |
5252 | uintptr_t vec_addr_offset = old_size * ((uintptr_t) sizeof (int)); | |
5253 | uintptr_t vec_addr; | |
5254 | VEC_safe_grow (int, inf->syscalls_counts, iter + 1); | |
5255 | vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) + | |
5256 | vec_addr_offset; | |
5257 | memset ((void *) vec_addr, 0, | |
5258 | (iter + 1 - old_size) * sizeof (int)); | |
5259 | } | |
5260 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
5261 | VEC_replace (int, inf->syscalls_counts, iter, ++elem); | |
5262 | } | |
5263 | } | |
5264 | ||
5265 | target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
5266 | inf->total_syscalls_count != 0, | |
5267 | inf->any_syscall_count, | |
5268 | VEC_length (int, inf->syscalls_counts), | |
5269 | VEC_address (int, inf->syscalls_counts)); | |
5270 | } | |
5271 | ||
5272 | /* Implement the "remove" breakpoint_ops method for syscall | |
5273 | catchpoints. */ | |
5274 | ||
5275 | static int | |
5276 | remove_catch_syscall (struct breakpoint *b) | |
5277 | { | |
5278 | struct inferior *inf = current_inferior (); | |
5279 | ||
5280 | --inf->total_syscalls_count; | |
5281 | if (!b->syscalls_to_be_caught) | |
5282 | --inf->any_syscall_count; | |
5283 | else | |
5284 | { | |
5285 | int i, iter; | |
5286 | for (i = 0; | |
5287 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
5288 | i++) | |
5289 | { | |
5290 | int elem; | |
5291 | if (iter >= VEC_length (int, inf->syscalls_counts)) | |
5292 | /* Shouldn't happen. */ | |
5293 | continue; | |
5294 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
5295 | VEC_replace (int, inf->syscalls_counts, iter, --elem); | |
5296 | } | |
5297 | } | |
5298 | ||
5299 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
5300 | inf->total_syscalls_count != 0, | |
5301 | inf->any_syscall_count, | |
5302 | VEC_length (int, inf->syscalls_counts), | |
5303 | VEC_address (int, inf->syscalls_counts)); | |
5304 | } | |
5305 | ||
5306 | /* Implement the "breakpoint_hit" breakpoint_ops method for syscall | |
5307 | catchpoints. */ | |
5308 | ||
5309 | static int | |
5310 | breakpoint_hit_catch_syscall (struct breakpoint *b) | |
5311 | { | |
5312 | /* We must check if we are catching specific syscalls in this breakpoint. | |
5313 | If we are, then we must guarantee that the called syscall is the same | |
5314 | syscall we are catching. */ | |
5315 | int syscall_number = 0; | |
5316 | ||
5317 | if (!inferior_has_called_syscall (inferior_ptid, &syscall_number)) | |
5318 | return 0; | |
5319 | ||
5320 | /* Now, checking if the syscall is the same. */ | |
5321 | if (b->syscalls_to_be_caught) | |
5322 | { | |
5323 | int i, iter; | |
5324 | for (i = 0; | |
5325 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
5326 | i++) | |
5327 | if (syscall_number == iter) | |
5328 | break; | |
5329 | /* Not the same. */ | |
5330 | if (!iter) | |
5331 | return 0; | |
5332 | } | |
5333 | ||
5334 | return 1; | |
5335 | } | |
5336 | ||
5337 | /* Implement the "print_it" breakpoint_ops method for syscall | |
5338 | catchpoints. */ | |
5339 | ||
5340 | static enum print_stop_action | |
5341 | print_it_catch_syscall (struct breakpoint *b) | |
5342 | { | |
5343 | /* These are needed because we want to know in which state a | |
5344 | syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY | |
5345 | or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we | |
5346 | must print "called syscall" or "returned from syscall". */ | |
5347 | ptid_t ptid; | |
5348 | struct target_waitstatus last; | |
5349 | struct syscall s; | |
5350 | struct cleanup *old_chain; | |
5351 | char *syscall_id; | |
5352 | ||
5353 | get_last_target_status (&ptid, &last); | |
5354 | ||
5355 | get_syscall_by_number (last.value.syscall_number, &s); | |
5356 | ||
5357 | annotate_catchpoint (b->number); | |
5358 | ||
5359 | if (s.name == NULL) | |
5360 | syscall_id = xstrprintf ("%d", last.value.syscall_number); | |
5361 | else | |
5362 | syscall_id = xstrprintf ("'%s'", s.name); | |
5363 | ||
5364 | old_chain = make_cleanup (xfree, syscall_id); | |
5365 | ||
5366 | if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) | |
5367 | printf_filtered (_("\nCatchpoint %d (call to syscall %s), "), | |
5368 | b->number, syscall_id); | |
5369 | else if (last.kind == TARGET_WAITKIND_SYSCALL_RETURN) | |
5370 | printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "), | |
5371 | b->number, syscall_id); | |
5372 | ||
5373 | do_cleanups (old_chain); | |
5374 | ||
5375 | return PRINT_SRC_AND_LOC; | |
5376 | } | |
5377 | ||
5378 | /* Implement the "print_one" breakpoint_ops method for syscall | |
5379 | catchpoints. */ | |
5380 | ||
5381 | static void | |
5382 | print_one_catch_syscall (struct breakpoint *b, | |
5383 | struct bp_location **last_loc) | |
5384 | { | |
5385 | struct value_print_options opts; | |
5386 | ||
5387 | get_user_print_options (&opts); | |
5388 | /* Field 4, the address, is omitted (which makes the columns | |
5389 | not line up too nicely with the headers, but the effect | |
5390 | is relatively readable). */ | |
5391 | if (opts.addressprint) | |
5392 | ui_out_field_skip (uiout, "addr"); | |
5393 | annotate_field (5); | |
5394 | ||
5395 | if (b->syscalls_to_be_caught | |
5396 | && VEC_length (int, b->syscalls_to_be_caught) > 1) | |
5397 | ui_out_text (uiout, "syscalls \""); | |
5398 | else | |
5399 | ui_out_text (uiout, "syscall \""); | |
5400 | ||
5401 | if (b->syscalls_to_be_caught) | |
5402 | { | |
5403 | int i, iter; | |
5404 | char *text = xstrprintf ("%s", ""); | |
5405 | for (i = 0; | |
5406 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
5407 | i++) | |
5408 | { | |
5409 | char *x = text; | |
5410 | struct syscall s; | |
5411 | get_syscall_by_number (iter, &s); | |
5412 | ||
5413 | if (s.name != NULL) | |
5414 | text = xstrprintf ("%s%s, ", text, s.name); | |
5415 | else | |
5416 | text = xstrprintf ("%s%d, ", text, iter); | |
5417 | ||
5418 | /* We have to xfree the last 'text' (now stored at 'x') | |
5419 | because xstrprintf dinamically allocates new space for it | |
5420 | on every call. */ | |
5421 | xfree (x); | |
5422 | } | |
5423 | /* Remove the last comma. */ | |
5424 | text[strlen (text) - 2] = '\0'; | |
5425 | ui_out_field_string (uiout, "what", text); | |
5426 | } | |
5427 | else | |
5428 | ui_out_field_string (uiout, "what", "<any syscall>"); | |
5429 | ui_out_text (uiout, "\" "); | |
5430 | } | |
5431 | ||
5432 | /* Implement the "print_mention" breakpoint_ops method for syscall | |
5433 | catchpoints. */ | |
5434 | ||
5435 | static void | |
5436 | print_mention_catch_syscall (struct breakpoint *b) | |
5437 | { | |
5438 | if (b->syscalls_to_be_caught) | |
5439 | { | |
5440 | int i, iter; | |
5441 | ||
5442 | if (VEC_length (int, b->syscalls_to_be_caught) > 1) | |
5443 | printf_filtered (_("Catchpoint %d (syscalls"), b->number); | |
5444 | else | |
5445 | printf_filtered (_("Catchpoint %d (syscall"), b->number); | |
5446 | ||
5447 | for (i = 0; | |
5448 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
5449 | i++) | |
5450 | { | |
5451 | struct syscall s; | |
5452 | get_syscall_by_number (iter, &s); | |
5453 | ||
5454 | if (s.name) | |
5455 | printf_filtered (" '%s' [%d]", s.name, s.number); | |
5456 | else | |
5457 | printf_filtered (" %d", s.number); | |
5458 | } | |
5459 | printf_filtered (")"); | |
5460 | } | |
5461 | else | |
5462 | printf_filtered (_("Catchpoint %d (any syscall)"), | |
5463 | b->number); | |
5464 | } | |
5465 | ||
5466 | /* The breakpoint_ops structure to be used in syscall catchpoints. */ | |
5467 | ||
5468 | static struct breakpoint_ops catch_syscall_breakpoint_ops = | |
5469 | { | |
5470 | insert_catch_syscall, | |
5471 | remove_catch_syscall, | |
5472 | breakpoint_hit_catch_syscall, | |
5473 | print_it_catch_syscall, | |
5474 | print_one_catch_syscall, | |
5475 | print_mention_catch_syscall | |
5476 | }; | |
5477 | ||
5478 | /* Returns non-zero if 'b' is a syscall catchpoint. */ | |
5479 | ||
5480 | static int | |
5481 | syscall_catchpoint_p (struct breakpoint *b) | |
5482 | { | |
5483 | return (b->ops == &catch_syscall_breakpoint_ops); | |
5484 | } | |
5485 | ||
5486 | /* Create a new breakpoint of the bp_catchpoint kind and return it, | |
5487 | but does NOT mention it nor update the global location list. | |
5488 | This is useful if you need to fill more fields in the | |
5489 | struct breakpoint before calling mention. | |
ce78b96d JB |
5490 | |
5491 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
5492 | If COND_STRING is not NULL, then store it in the breakpoint. | |
5493 | OPS, if not NULL, is the breakpoint_ops structure associated | |
5494 | to the catchpoint. */ | |
5495 | ||
5496 | static struct breakpoint * | |
a96d9b2e SDJ |
5497 | create_catchpoint_without_mention (struct gdbarch *gdbarch, int tempflag, |
5498 | char *cond_string, | |
5499 | struct breakpoint_ops *ops) | |
c906108c | 5500 | { |
c5aa993b JM |
5501 | struct symtab_and_line sal; |
5502 | struct breakpoint *b; | |
c5aa993b | 5503 | |
fe39c653 | 5504 | init_sal (&sal); |
6c95b8df | 5505 | sal.pspace = current_program_space; |
c5aa993b | 5506 | |
a6d9a66e | 5507 | b = set_raw_breakpoint (gdbarch, sal, bp_catchpoint); |
c906108c SS |
5508 | set_breakpoint_count (breakpoint_count + 1); |
5509 | b->number = breakpoint_count; | |
ce78b96d | 5510 | |
1b36a34b | 5511 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
ce78b96d | 5512 | b->thread = -1; |
c906108c | 5513 | b->addr_string = NULL; |
b5de0fa7 EZ |
5514 | b->enable_state = bp_enabled; |
5515 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
ce78b96d | 5516 | b->ops = ops; |
c5aa993b | 5517 | |
a96d9b2e SDJ |
5518 | return b; |
5519 | } | |
5520 | ||
5521 | /* Create a new breakpoint of the bp_catchpoint kind and return it. | |
5522 | ||
5523 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
5524 | If COND_STRING is not NULL, then store it in the breakpoint. | |
5525 | OPS, if not NULL, is the breakpoint_ops structure associated | |
5526 | to the catchpoint. */ | |
5527 | ||
5528 | static struct breakpoint * | |
5529 | create_catchpoint (struct gdbarch *gdbarch, int tempflag, | |
5530 | char *cond_string, struct breakpoint_ops *ops) | |
5531 | { | |
5532 | struct breakpoint *b = | |
5533 | create_catchpoint_without_mention (gdbarch, tempflag, cond_string, ops); | |
5534 | ||
c906108c | 5535 | mention (b); |
ce78b96d | 5536 | update_global_location_list (1); |
c906108c | 5537 | |
ce78b96d | 5538 | return b; |
c906108c | 5539 | } |
c5aa993b | 5540 | |
9b70b993 | 5541 | static void |
a6d9a66e UW |
5542 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
5543 | int tempflag, char *cond_string, | |
ce78b96d | 5544 | struct breakpoint_ops *ops) |
c906108c | 5545 | { |
a6d9a66e UW |
5546 | struct breakpoint *b |
5547 | = create_catchpoint (gdbarch, tempflag, cond_string, ops); | |
ce78b96d JB |
5548 | |
5549 | /* FIXME: We should put this information in a breakpoint private data | |
5550 | area. */ | |
5551 | b->forked_inferior_pid = null_ptid; | |
c906108c SS |
5552 | } |
5553 | ||
fe798b75 JB |
5554 | /* Exec catchpoints. */ |
5555 | ||
9b70b993 | 5556 | static void |
fe798b75 | 5557 | insert_catch_exec (struct breakpoint *b) |
c906108c | 5558 | { |
fe798b75 JB |
5559 | target_insert_exec_catchpoint (PIDGET (inferior_ptid)); |
5560 | } | |
c906108c | 5561 | |
fe798b75 JB |
5562 | static int |
5563 | remove_catch_exec (struct breakpoint *b) | |
5564 | { | |
5565 | return target_remove_exec_catchpoint (PIDGET (inferior_ptid)); | |
5566 | } | |
c906108c | 5567 | |
fe798b75 JB |
5568 | static int |
5569 | breakpoint_hit_catch_exec (struct breakpoint *b) | |
5570 | { | |
5571 | return inferior_has_execd (inferior_ptid, &b->exec_pathname); | |
5572 | } | |
c906108c | 5573 | |
fe798b75 JB |
5574 | static enum print_stop_action |
5575 | print_it_catch_exec (struct breakpoint *b) | |
5576 | { | |
5577 | annotate_catchpoint (b->number); | |
5578 | printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number, | |
5579 | b->exec_pathname); | |
5580 | return PRINT_SRC_AND_LOC; | |
c906108c SS |
5581 | } |
5582 | ||
fe798b75 | 5583 | static void |
a6d9a66e | 5584 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 JB |
5585 | { |
5586 | struct value_print_options opts; | |
5587 | ||
5588 | get_user_print_options (&opts); | |
5589 | ||
5590 | /* Field 4, the address, is omitted (which makes the columns | |
5591 | not line up too nicely with the headers, but the effect | |
5592 | is relatively readable). */ | |
5593 | if (opts.addressprint) | |
5594 | ui_out_field_skip (uiout, "addr"); | |
5595 | annotate_field (5); | |
5596 | ui_out_text (uiout, "exec"); | |
5597 | if (b->exec_pathname != NULL) | |
5598 | { | |
5599 | ui_out_text (uiout, ", program \""); | |
5600 | ui_out_field_string (uiout, "what", b->exec_pathname); | |
5601 | ui_out_text (uiout, "\" "); | |
5602 | } | |
5603 | } | |
5604 | ||
5605 | static void | |
5606 | print_mention_catch_exec (struct breakpoint *b) | |
5607 | { | |
5608 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
5609 | } | |
5610 | ||
5611 | static struct breakpoint_ops catch_exec_breakpoint_ops = | |
5612 | { | |
5613 | insert_catch_exec, | |
5614 | remove_catch_exec, | |
5615 | breakpoint_hit_catch_exec, | |
5616 | print_it_catch_exec, | |
5617 | print_one_catch_exec, | |
5618 | print_mention_catch_exec | |
5619 | }; | |
5620 | ||
a96d9b2e SDJ |
5621 | static void |
5622 | create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, | |
5623 | struct breakpoint_ops *ops) | |
5624 | { | |
5625 | struct gdbarch *gdbarch = get_current_arch (); | |
5626 | struct breakpoint *b = | |
5627 | create_catchpoint_without_mention (gdbarch, tempflag, NULL, ops); | |
5628 | ||
5629 | b->syscalls_to_be_caught = filter; | |
5630 | ||
5631 | /* Now, we have to mention the breakpoint and update the global | |
5632 | location list. */ | |
5633 | mention (b); | |
5634 | update_global_location_list (1); | |
5635 | } | |
5636 | ||
c906108c | 5637 | static int |
fba45db2 | 5638 | hw_breakpoint_used_count (void) |
c906108c | 5639 | { |
52f0bd74 | 5640 | struct breakpoint *b; |
c906108c SS |
5641 | int i = 0; |
5642 | ||
5643 | ALL_BREAKPOINTS (b) | |
c5aa993b | 5644 | { |
d6b74ac4 | 5645 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
c5aa993b JM |
5646 | i++; |
5647 | } | |
c906108c SS |
5648 | |
5649 | return i; | |
5650 | } | |
5651 | ||
5652 | static int | |
fba45db2 | 5653 | hw_watchpoint_used_count (enum bptype type, int *other_type_used) |
c906108c | 5654 | { |
52f0bd74 | 5655 | struct breakpoint *b; |
c906108c SS |
5656 | int i = 0; |
5657 | ||
5658 | *other_type_used = 0; | |
5659 | ALL_BREAKPOINTS (b) | |
c5aa993b | 5660 | { |
468d015d | 5661 | if (breakpoint_enabled (b)) |
c5aa993b JM |
5662 | { |
5663 | if (b->type == type) | |
5664 | i++; | |
059fb39f PM |
5665 | else if ((b->type == bp_hardware_watchpoint |
5666 | || b->type == bp_read_watchpoint | |
5667 | || b->type == bp_access_watchpoint)) | |
c5aa993b JM |
5668 | *other_type_used = 1; |
5669 | } | |
5670 | } | |
c906108c SS |
5671 | return i; |
5672 | } | |
5673 | ||
c906108c | 5674 | void |
fba45db2 | 5675 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 5676 | { |
c5aa993b | 5677 | struct breakpoint *b; |
c906108c SS |
5678 | |
5679 | ALL_BREAKPOINTS (b) | |
c5aa993b JM |
5680 | { |
5681 | if (((b->type == bp_watchpoint) | |
5682 | || (b->type == bp_hardware_watchpoint) | |
5683 | || (b->type == bp_read_watchpoint) | |
dfdfb3ca | 5684 | || (b->type == bp_access_watchpoint)) |
468d015d | 5685 | && breakpoint_enabled (b)) |
c5aa993b | 5686 | { |
b5de0fa7 | 5687 | b->enable_state = bp_call_disabled; |
b60e7edf | 5688 | update_global_location_list (0); |
c5aa993b JM |
5689 | } |
5690 | } | |
c906108c SS |
5691 | } |
5692 | ||
5693 | void | |
fba45db2 | 5694 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 5695 | { |
c5aa993b | 5696 | struct breakpoint *b; |
c906108c SS |
5697 | |
5698 | ALL_BREAKPOINTS (b) | |
c5aa993b JM |
5699 | { |
5700 | if (((b->type == bp_watchpoint) | |
5701 | || (b->type == bp_hardware_watchpoint) | |
5702 | || (b->type == bp_read_watchpoint) | |
dfdfb3ca | 5703 | || (b->type == bp_access_watchpoint)) |
b5de0fa7 | 5704 | && (b->enable_state == bp_call_disabled)) |
c5aa993b | 5705 | { |
b5de0fa7 | 5706 | b->enable_state = bp_enabled; |
b60e7edf | 5707 | update_global_location_list (1); |
c5aa993b JM |
5708 | } |
5709 | } | |
c906108c SS |
5710 | } |
5711 | ||
8bea4e01 UW |
5712 | void |
5713 | disable_breakpoints_before_startup (void) | |
5714 | { | |
5715 | struct breakpoint *b; | |
5716 | int found = 0; | |
5717 | ||
5718 | ALL_BREAKPOINTS (b) | |
5719 | { | |
6c95b8df PA |
5720 | if (b->pspace != current_program_space) |
5721 | continue; | |
5722 | ||
8bea4e01 UW |
5723 | if ((b->type == bp_breakpoint |
5724 | || b->type == bp_hardware_breakpoint) | |
5725 | && breakpoint_enabled (b)) | |
5726 | { | |
5727 | b->enable_state = bp_startup_disabled; | |
5728 | found = 1; | |
5729 | } | |
5730 | } | |
5731 | ||
5732 | if (found) | |
5733 | update_global_location_list (0); | |
5734 | ||
6c95b8df | 5735 | current_program_space->executing_startup = 1; |
8bea4e01 UW |
5736 | } |
5737 | ||
5738 | void | |
5739 | enable_breakpoints_after_startup (void) | |
5740 | { | |
5741 | struct breakpoint *b; | |
5742 | int found = 0; | |
5743 | ||
6c95b8df | 5744 | current_program_space->executing_startup = 0; |
8bea4e01 UW |
5745 | |
5746 | ALL_BREAKPOINTS (b) | |
5747 | { | |
6c95b8df PA |
5748 | if (b->pspace != current_program_space) |
5749 | continue; | |
5750 | ||
8bea4e01 UW |
5751 | if ((b->type == bp_breakpoint |
5752 | || b->type == bp_hardware_breakpoint) | |
5753 | && b->enable_state == bp_startup_disabled) | |
5754 | { | |
5755 | b->enable_state = bp_enabled; | |
5756 | found = 1; | |
5757 | } | |
5758 | } | |
5759 | ||
5760 | if (found) | |
5761 | breakpoint_re_set (); | |
5762 | } | |
5763 | ||
c906108c SS |
5764 | |
5765 | /* Set a breakpoint that will evaporate an end of command | |
5766 | at address specified by SAL. | |
5767 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
5768 | ||
5769 | struct breakpoint * | |
a6d9a66e UW |
5770 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
5771 | struct frame_id frame_id, enum bptype type) | |
c906108c | 5772 | { |
52f0bd74 | 5773 | struct breakpoint *b; |
edb3359d DJ |
5774 | |
5775 | /* If FRAME_ID is valid, it should be a real frame, not an inlined | |
5776 | one. */ | |
5777 | gdb_assert (!frame_id_inlined_p (frame_id)); | |
5778 | ||
a6d9a66e | 5779 | b = set_raw_breakpoint (gdbarch, sal, type); |
b5de0fa7 EZ |
5780 | b->enable_state = bp_enabled; |
5781 | b->disposition = disp_donttouch; | |
818dd999 | 5782 | b->frame_id = frame_id; |
c906108c SS |
5783 | |
5784 | /* If we're debugging a multi-threaded program, then we | |
5785 | want momentary breakpoints to be active in only a | |
5786 | single thread of control. */ | |
39f77062 KB |
5787 | if (in_thread_list (inferior_ptid)) |
5788 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 5789 | |
b60e7edf | 5790 | update_global_location_list_nothrow (1); |
74960c60 | 5791 | |
c906108c SS |
5792 | return b; |
5793 | } | |
611c83ae | 5794 | |
e58b0e63 PA |
5795 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
5796 | ORIG is NULL. */ | |
5797 | ||
5798 | struct breakpoint * | |
5799 | clone_momentary_breakpoint (struct breakpoint *orig) | |
5800 | { | |
5801 | struct breakpoint *copy; | |
5802 | ||
5803 | /* If there's nothing to clone, then return nothing. */ | |
5804 | if (orig == NULL) | |
5805 | return NULL; | |
5806 | ||
a6d9a66e | 5807 | copy = set_raw_breakpoint_without_location (orig->gdbarch, orig->type); |
e58b0e63 PA |
5808 | copy->loc = allocate_bp_location (copy); |
5809 | set_breakpoint_location_function (copy->loc); | |
5810 | ||
a6d9a66e | 5811 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
5812 | copy->loc->requested_address = orig->loc->requested_address; |
5813 | copy->loc->address = orig->loc->address; | |
5814 | copy->loc->section = orig->loc->section; | |
6c95b8df | 5815 | copy->loc->pspace = orig->loc->pspace; |
e58b0e63 PA |
5816 | |
5817 | if (orig->source_file == NULL) | |
5818 | copy->source_file = NULL; | |
5819 | else | |
5820 | copy->source_file = xstrdup (orig->source_file); | |
5821 | ||
5822 | copy->line_number = orig->line_number; | |
5823 | copy->frame_id = orig->frame_id; | |
5824 | copy->thread = orig->thread; | |
6c95b8df | 5825 | copy->pspace = orig->pspace; |
e58b0e63 PA |
5826 | |
5827 | copy->enable_state = bp_enabled; | |
5828 | copy->disposition = disp_donttouch; | |
5829 | copy->number = internal_breakpoint_number--; | |
5830 | ||
5831 | update_global_location_list_nothrow (0); | |
5832 | return copy; | |
5833 | } | |
5834 | ||
611c83ae | 5835 | struct breakpoint * |
a6d9a66e UW |
5836 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
5837 | enum bptype type) | |
611c83ae PA |
5838 | { |
5839 | struct symtab_and_line sal; | |
5840 | ||
5841 | sal = find_pc_line (pc, 0); | |
5842 | sal.pc = pc; | |
5843 | sal.section = find_pc_overlay (pc); | |
5844 | sal.explicit_pc = 1; | |
5845 | ||
a6d9a66e | 5846 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 5847 | } |
c906108c | 5848 | \f |
c5aa993b | 5849 | |
c906108c SS |
5850 | /* Tell the user we have just set a breakpoint B. */ |
5851 | ||
5852 | static void | |
fba45db2 | 5853 | mention (struct breakpoint *b) |
c906108c SS |
5854 | { |
5855 | int say_where = 0; | |
fa8a61dc | 5856 | struct cleanup *ui_out_chain; |
79a45b7d TT |
5857 | struct value_print_options opts; |
5858 | ||
5859 | get_user_print_options (&opts); | |
8b93c638 | 5860 | |
9a4105ab AC |
5861 | /* FIXME: This is misplaced; mention() is called by things (like |
5862 | hitting a watchpoint) other than breakpoint creation. It should | |
5863 | be possible to clean this up and at the same time replace the | |
7f4b89d1 | 5864 | random calls to breakpoint_changed with this hook. */ |
383f836e | 5865 | observer_notify_breakpoint_created (b->number); |
c906108c | 5866 | |
3086aeae DJ |
5867 | if (b->ops != NULL && b->ops->print_mention != NULL) |
5868 | b->ops->print_mention (b); | |
5869 | else | |
5870 | switch (b->type) | |
5871 | { | |
5872 | case bp_none: | |
a3f17187 | 5873 | printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b->number); |
3086aeae DJ |
5874 | break; |
5875 | case bp_watchpoint: | |
5876 | ui_out_text (uiout, "Watchpoint "); | |
5877 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
5878 | ui_out_field_int (uiout, "number", b->number); | |
5879 | ui_out_text (uiout, ": "); | |
fa8a61dc | 5880 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
5881 | do_cleanups (ui_out_chain); |
5882 | break; | |
5883 | case bp_hardware_watchpoint: | |
5884 | ui_out_text (uiout, "Hardware watchpoint "); | |
5885 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
5886 | ui_out_field_int (uiout, "number", b->number); | |
5887 | ui_out_text (uiout, ": "); | |
fa8a61dc | 5888 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
5889 | do_cleanups (ui_out_chain); |
5890 | break; | |
5891 | case bp_read_watchpoint: | |
5892 | ui_out_text (uiout, "Hardware read watchpoint "); | |
5893 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
5894 | ui_out_field_int (uiout, "number", b->number); | |
5895 | ui_out_text (uiout, ": "); | |
fa8a61dc | 5896 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
5897 | do_cleanups (ui_out_chain); |
5898 | break; | |
5899 | case bp_access_watchpoint: | |
5900 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
5901 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
5902 | ui_out_field_int (uiout, "number", b->number); | |
5903 | ui_out_text (uiout, ": "); | |
fa8a61dc | 5904 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
5905 | do_cleanups (ui_out_chain); |
5906 | break; | |
5907 | case bp_breakpoint: | |
5908 | if (ui_out_is_mi_like_p (uiout)) | |
5909 | { | |
5910 | say_where = 0; | |
5911 | break; | |
5912 | } | |
2cec12e5 AR |
5913 | if (b->disposition == disp_del) |
5914 | printf_filtered (_("Temporary breakpoint")); | |
5915 | else | |
5916 | printf_filtered (_("Breakpoint")); | |
5917 | printf_filtered (_(" %d"), b->number); | |
3086aeae DJ |
5918 | say_where = 1; |
5919 | break; | |
5920 | case bp_hardware_breakpoint: | |
5921 | if (ui_out_is_mi_like_p (uiout)) | |
5922 | { | |
5923 | say_where = 0; | |
5924 | break; | |
5925 | } | |
a3f17187 | 5926 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); |
3086aeae DJ |
5927 | say_where = 1; |
5928 | break; | |
1042e4c0 SS |
5929 | case bp_tracepoint: |
5930 | if (ui_out_is_mi_like_p (uiout)) | |
5931 | { | |
5932 | say_where = 0; | |
5933 | break; | |
5934 | } | |
5935 | printf_filtered (_("Tracepoint")); | |
5936 | printf_filtered (_(" %d"), b->number); | |
5937 | say_where = 1; | |
5938 | break; | |
3086aeae DJ |
5939 | |
5940 | case bp_until: | |
5941 | case bp_finish: | |
5942 | case bp_longjmp: | |
5943 | case bp_longjmp_resume: | |
5944 | case bp_step_resume: | |
3086aeae DJ |
5945 | case bp_call_dummy: |
5946 | case bp_watchpoint_scope: | |
5947 | case bp_shlib_event: | |
5948 | case bp_thread_event: | |
5949 | case bp_overlay_event: | |
4efc6507 | 5950 | case bp_jit_event: |
0fd8e87f | 5951 | case bp_longjmp_master: |
3086aeae DJ |
5952 | break; |
5953 | } | |
c906108c | 5954 | |
c906108c SS |
5955 | if (say_where) |
5956 | { | |
a3f17187 AC |
5957 | /* i18n: cagney/2005-02-11: Below needs to be merged into a |
5958 | single string. */ | |
0d381245 | 5959 | if (b->loc == NULL) |
c906108c | 5960 | { |
a3f17187 | 5961 | printf_filtered (_(" (%s) pending."), b->addr_string); |
0101ce28 JJ |
5962 | } |
5963 | else | |
5964 | { | |
79a45b7d | 5965 | if (opts.addressprint || b->source_file == NULL) |
0101ce28 JJ |
5966 | { |
5967 | printf_filtered (" at "); | |
5af949e3 UW |
5968 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), |
5969 | gdb_stdout); | |
0101ce28 JJ |
5970 | } |
5971 | if (b->source_file) | |
5972 | printf_filtered (": file %s, line %d.", | |
5973 | b->source_file, b->line_number); | |
0d381245 VP |
5974 | |
5975 | if (b->loc->next) | |
5976 | { | |
5977 | struct bp_location *loc = b->loc; | |
5978 | int n = 0; | |
5979 | for (; loc; loc = loc->next) | |
5980 | ++n; | |
5981 | printf_filtered (" (%d locations)", n); | |
5982 | } | |
5983 | ||
c906108c | 5984 | } |
c906108c | 5985 | } |
9dc5e2a9 | 5986 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 5987 | return; |
c906108c SS |
5988 | printf_filtered ("\n"); |
5989 | } | |
c906108c | 5990 | \f |
c5aa993b | 5991 | |
0d381245 | 5992 | static struct bp_location * |
39d61571 | 5993 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
5994 | const struct symtab_and_line *sal) |
5995 | { | |
5996 | struct bp_location *loc, **tmp; | |
5997 | ||
39d61571 | 5998 | loc = allocate_bp_location (b); |
0d381245 VP |
5999 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
6000 | ; | |
6001 | *tmp = loc; | |
a6d9a66e UW |
6002 | loc->gdbarch = get_sal_arch (*sal); |
6003 | if (!loc->gdbarch) | |
6004 | loc->gdbarch = b->gdbarch; | |
0d381245 | 6005 | loc->requested_address = sal->pc; |
a6d9a66e UW |
6006 | loc->address = adjust_breakpoint_address (loc->gdbarch, |
6007 | loc->requested_address, b->type); | |
6c95b8df PA |
6008 | loc->pspace = sal->pspace; |
6009 | gdb_assert (loc->pspace != NULL); | |
0d381245 VP |
6010 | loc->section = sal->section; |
6011 | ||
6012 | set_breakpoint_location_function (loc); | |
6013 | return loc; | |
6014 | } | |
514f746b AR |
6015 | \f |
6016 | ||
6017 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
6018 | return 0 otherwise. */ | |
6019 | ||
6020 | static int | |
6021 | bp_loc_is_permanent (struct bp_location *loc) | |
6022 | { | |
6023 | int len; | |
6024 | CORE_ADDR addr; | |
6025 | const gdb_byte *brk; | |
6026 | gdb_byte *target_mem; | |
939c61fa JK |
6027 | struct cleanup *cleanup; |
6028 | int retval = 0; | |
514f746b AR |
6029 | |
6030 | gdb_assert (loc != NULL); | |
6031 | ||
6032 | addr = loc->address; | |
a6d9a66e | 6033 | brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 6034 | |
939c61fa JK |
6035 | /* Software breakpoints unsupported? */ |
6036 | if (brk == NULL) | |
6037 | return 0; | |
6038 | ||
514f746b AR |
6039 | target_mem = alloca (len); |
6040 | ||
939c61fa JK |
6041 | /* Enable the automatic memory restoration from breakpoints while |
6042 | we read the memory. Otherwise we could say about our temporary | |
6043 | breakpoints they are permanent. */ | |
6c95b8df PA |
6044 | cleanup = save_current_space_and_thread (); |
6045 | ||
6046 | switch_to_program_space_and_thread (loc->pspace); | |
6047 | make_show_memory_breakpoints_cleanup (0); | |
939c61fa | 6048 | |
514f746b AR |
6049 | if (target_read_memory (loc->address, target_mem, len) == 0 |
6050 | && memcmp (target_mem, brk, len) == 0) | |
939c61fa | 6051 | retval = 1; |
514f746b | 6052 | |
939c61fa JK |
6053 | do_cleanups (cleanup); |
6054 | ||
6055 | return retval; | |
514f746b AR |
6056 | } |
6057 | ||
6058 | ||
c3f6f71d | 6059 | |
018d34a4 VP |
6060 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
6061 | as textual description of the location, and COND_STRING | |
db107f19 | 6062 | as condition expression. */ |
018d34a4 VP |
6063 | |
6064 | static void | |
a6d9a66e UW |
6065 | create_breakpoint (struct gdbarch *gdbarch, |
6066 | struct symtabs_and_lines sals, char *addr_string, | |
018d34a4 VP |
6067 | char *cond_string, |
6068 | enum bptype type, enum bpdisp disposition, | |
4a306c9a | 6069 | int thread, int task, int ignore_count, |
41447f92 | 6070 | struct breakpoint_ops *ops, int from_tty, int enabled) |
018d34a4 | 6071 | { |
0d381245 VP |
6072 | struct breakpoint *b = NULL; |
6073 | int i; | |
018d34a4 VP |
6074 | |
6075 | if (type == bp_hardware_breakpoint) | |
6076 | { | |
6077 | int i = hw_breakpoint_used_count (); | |
6078 | int target_resources_ok = | |
d92524f1 | 6079 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
018d34a4 VP |
6080 | i + 1, 0); |
6081 | if (target_resources_ok == 0) | |
6082 | error (_("No hardware breakpoint support in the target.")); | |
6083 | else if (target_resources_ok < 0) | |
6084 | error (_("Hardware breakpoints used exceeds limit.")); | |
6085 | } | |
6086 | ||
6c95b8df PA |
6087 | gdb_assert (sals.nelts > 0); |
6088 | ||
0d381245 VP |
6089 | for (i = 0; i < sals.nelts; ++i) |
6090 | { | |
6091 | struct symtab_and_line sal = sals.sals[i]; | |
6092 | struct bp_location *loc; | |
6093 | ||
6094 | if (from_tty) | |
5af949e3 UW |
6095 | { |
6096 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
6097 | if (!loc_gdbarch) | |
6098 | loc_gdbarch = gdbarch; | |
6099 | ||
6100 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 6101 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 6102 | } |
0d381245 VP |
6103 | |
6104 | if (i == 0) | |
6105 | { | |
a6d9a66e | 6106 | b = set_raw_breakpoint (gdbarch, sal, type); |
0d381245 VP |
6107 | set_breakpoint_count (breakpoint_count + 1); |
6108 | b->number = breakpoint_count; | |
6109 | b->thread = thread; | |
4a306c9a | 6110 | b->task = task; |
018d34a4 | 6111 | |
0d381245 VP |
6112 | b->cond_string = cond_string; |
6113 | b->ignore_count = ignore_count; | |
41447f92 | 6114 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 6115 | b->disposition = disposition; |
018d34a4 | 6116 | |
6c95b8df PA |
6117 | b->pspace = sals.sals[0].pspace; |
6118 | ||
6119 | if (enabled && b->pspace->executing_startup | |
8bea4e01 UW |
6120 | && (b->type == bp_breakpoint |
6121 | || b->type == bp_hardware_breakpoint)) | |
6122 | b->enable_state = bp_startup_disabled; | |
6123 | ||
0d381245 VP |
6124 | loc = b->loc; |
6125 | } | |
6126 | else | |
018d34a4 | 6127 | { |
39d61571 | 6128 | loc = add_location_to_breakpoint (b, &sal); |
0d381245 VP |
6129 | } |
6130 | ||
514f746b AR |
6131 | if (bp_loc_is_permanent (loc)) |
6132 | make_breakpoint_permanent (b); | |
6133 | ||
0d381245 VP |
6134 | if (b->cond_string) |
6135 | { | |
6136 | char *arg = b->cond_string; | |
d32a6982 | 6137 | loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0); |
0d381245 | 6138 | if (*arg) |
db107f19 | 6139 | error (_("Garbage %s follows condition"), arg); |
018d34a4 | 6140 | } |
0d381245 | 6141 | } |
018d34a4 VP |
6142 | |
6143 | if (addr_string) | |
6144 | b->addr_string = addr_string; | |
6145 | else | |
6146 | /* addr_string has to be used or breakpoint_re_set will delete | |
6147 | me. */ | |
5af949e3 UW |
6148 | b->addr_string |
6149 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
018d34a4 | 6150 | |
604133b5 | 6151 | b->ops = ops; |
018d34a4 VP |
6152 | mention (b); |
6153 | } | |
6154 | ||
ed0616c6 VP |
6155 | /* Remove element at INDEX_TO_REMOVE from SAL, shifting other |
6156 | elements to fill the void space. */ | |
2c0b251b PA |
6157 | static void |
6158 | remove_sal (struct symtabs_and_lines *sal, int index_to_remove) | |
ed0616c6 VP |
6159 | { |
6160 | int i = index_to_remove+1; | |
6161 | int last_index = sal->nelts-1; | |
6162 | ||
6163 | for (;i <= last_index; ++i) | |
6164 | sal->sals[i-1] = sal->sals[i]; | |
6165 | ||
6166 | --(sal->nelts); | |
6167 | } | |
6168 | ||
6c95b8df PA |
6169 | /* If appropriate, obtains all sals that correspond to the same file |
6170 | and line as SAL, in all program spaces. Users debugging with IDEs, | |
6171 | will want to set a breakpoint at foo.c:line, and not really care | |
6172 | about program spaces. This is done only if SAL does not have | |
6173 | explicit PC and has line and file information. If we got just a | |
6174 | single expanded sal, return the original. | |
ed0616c6 | 6175 | |
6c95b8df PA |
6176 | Otherwise, if SAL.explicit_line is not set, filter out all sals for |
6177 | which the name of enclosing function is different from SAL. This | |
6178 | makes sure that if we have breakpoint originally set in template | |
6179 | instantiation, say foo<int>(), we won't expand SAL to locations at | |
6180 | the same line in all existing instantiations of 'foo'. */ | |
ed0616c6 | 6181 | |
2c0b251b | 6182 | static struct symtabs_and_lines |
ed0616c6 VP |
6183 | expand_line_sal_maybe (struct symtab_and_line sal) |
6184 | { | |
6185 | struct symtabs_and_lines expanded; | |
6186 | CORE_ADDR original_pc = sal.pc; | |
6187 | char *original_function = NULL; | |
6188 | int found; | |
6189 | int i; | |
6c95b8df | 6190 | struct cleanup *old_chain; |
ed0616c6 VP |
6191 | |
6192 | /* If we have explicit pc, don't expand. | |
6193 | If we have no line number, we can't expand. */ | |
6194 | if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL) | |
6195 | { | |
6196 | expanded.nelts = 1; | |
6197 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
6198 | expanded.sals[0] = sal; | |
6199 | return expanded; | |
6200 | } | |
6201 | ||
6202 | sal.pc = 0; | |
6c95b8df PA |
6203 | |
6204 | old_chain = save_current_space_and_thread (); | |
6205 | ||
6206 | switch_to_program_space_and_thread (sal.pspace); | |
6207 | ||
ed0616c6 | 6208 | find_pc_partial_function (original_pc, &original_function, NULL, NULL); |
6c95b8df PA |
6209 | |
6210 | /* Note that expand_line_sal visits *all* program spaces. */ | |
ed0616c6 | 6211 | expanded = expand_line_sal (sal); |
6c95b8df | 6212 | |
ed0616c6 VP |
6213 | if (expanded.nelts == 1) |
6214 | { | |
6215 | /* We had one sal, we got one sal. Without futher | |
6216 | processing, just return the original sal. */ | |
6217 | xfree (expanded.sals); | |
6218 | expanded.nelts = 1; | |
6219 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
6220 | sal.pc = original_pc; | |
6221 | expanded.sals[0] = sal; | |
6c95b8df | 6222 | do_cleanups (old_chain); |
ed0616c6 VP |
6223 | return expanded; |
6224 | } | |
6225 | ||
6226 | if (!sal.explicit_line) | |
6227 | { | |
6228 | CORE_ADDR func_addr, func_end; | |
6229 | for (i = 0; i < expanded.nelts; ++i) | |
6230 | { | |
6231 | CORE_ADDR pc = expanded.sals[i].pc; | |
6232 | char *this_function; | |
6c95b8df PA |
6233 | |
6234 | /* We need to switch threads as well since we're about to | |
6235 | read memory. */ | |
6236 | switch_to_program_space_and_thread (expanded.sals[i].pspace); | |
6237 | ||
ed0616c6 VP |
6238 | if (find_pc_partial_function (pc, &this_function, |
6239 | &func_addr, &func_end)) | |
6240 | { | |
059fb39f PM |
6241 | if (this_function |
6242 | && strcmp (this_function, original_function) != 0) | |
ed0616c6 VP |
6243 | { |
6244 | remove_sal (&expanded, i); | |
6245 | --i; | |
6246 | } | |
6247 | else if (func_addr == pc) | |
6248 | { | |
6249 | /* We're at beginning of a function, and should | |
6250 | skip prologue. */ | |
6251 | struct symbol *sym = find_pc_function (pc); | |
6252 | if (sym) | |
6253 | expanded.sals[i] = find_function_start_sal (sym, 1); | |
6254 | else | |
d80b854b UW |
6255 | { |
6256 | /* Since find_pc_partial_function returned true, | |
6257 | we should really always find the section here. */ | |
6258 | struct obj_section *section = find_pc_section (pc); | |
6259 | if (section) | |
6260 | { | |
6261 | struct gdbarch *gdbarch | |
6262 | = get_objfile_arch (section->objfile); | |
6263 | expanded.sals[i].pc | |
6264 | = gdbarch_skip_prologue (gdbarch, pc); | |
6265 | } | |
6266 | } | |
ed0616c6 VP |
6267 | } |
6268 | } | |
6269 | } | |
6270 | } | |
3daf8fe5 JG |
6271 | else |
6272 | { | |
6273 | for (i = 0; i < expanded.nelts; ++i) | |
6274 | { | |
6275 | /* If this SAL corresponds to a breakpoint inserted using a | |
6276 | line number, then skip the function prologue if necessary. */ | |
6277 | skip_prologue_sal (&expanded.sals[i]); | |
6278 | } | |
6279 | } | |
ed0616c6 | 6280 | |
6c95b8df PA |
6281 | do_cleanups (old_chain); |
6282 | ||
ed0616c6 VP |
6283 | if (expanded.nelts <= 1) |
6284 | { | |
6285 | /* This is un ugly workaround. If we get zero | |
6286 | expanded sals then something is really wrong. | |
6287 | Fix that by returnign the original sal. */ | |
6288 | xfree (expanded.sals); | |
6289 | expanded.nelts = 1; | |
6290 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
6291 | sal.pc = original_pc; | |
6292 | expanded.sals[0] = sal; | |
6293 | return expanded; | |
6294 | } | |
6295 | ||
6296 | if (original_pc) | |
6297 | { | |
6298 | found = 0; | |
6299 | for (i = 0; i < expanded.nelts; ++i) | |
6300 | if (expanded.sals[i].pc == original_pc) | |
6301 | { | |
6302 | found = 1; | |
6303 | break; | |
6304 | } | |
6305 | gdb_assert (found); | |
6306 | } | |
6307 | ||
6308 | return expanded; | |
6309 | } | |
6310 | ||
018d34a4 VP |
6311 | /* Add SALS.nelts breakpoints to the breakpoint table. For each |
6312 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
6313 | value. COND_STRING, if not NULL, specified the condition to be | |
6314 | used for all breakpoints. Essentially the only case where | |
6315 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
6316 | function. In that case, it's still not possible to specify | |
6317 | separate conditions for different overloaded functions, so | |
6318 | we take just a single condition string. | |
6319 | ||
c3f6f71d | 6320 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 6321 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
6322 | array contents). If the function fails (error() is called), the |
6323 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
6324 | COND and SALS arrays and each of those arrays contents. */ | |
c906108c SS |
6325 | |
6326 | static void | |
a6d9a66e UW |
6327 | create_breakpoints (struct gdbarch *gdbarch, |
6328 | struct symtabs_and_lines sals, char **addr_string, | |
018d34a4 | 6329 | char *cond_string, |
c3f6f71d | 6330 | enum bptype type, enum bpdisp disposition, |
4a306c9a | 6331 | int thread, int task, int ignore_count, |
41447f92 VP |
6332 | struct breakpoint_ops *ops, int from_tty, |
6333 | int enabled) | |
c906108c | 6334 | { |
018d34a4 VP |
6335 | int i; |
6336 | for (i = 0; i < sals.nelts; ++i) | |
c3f6f71d | 6337 | { |
ed0616c6 VP |
6338 | struct symtabs_and_lines expanded = |
6339 | expand_line_sal_maybe (sals.sals[i]); | |
0d381245 | 6340 | |
a6d9a66e | 6341 | create_breakpoint (gdbarch, expanded, addr_string[i], |
018d34a4 | 6342 | cond_string, type, disposition, |
4a306c9a | 6343 | thread, task, ignore_count, ops, from_tty, enabled); |
c3f6f71d | 6344 | } |
c3f6f71d | 6345 | } |
c906108c | 6346 | |
c3f6f71d JM |
6347 | /* Parse ARG which is assumed to be a SAL specification possibly |
6348 | followed by conditionals. On return, SALS contains an array of SAL | |
6349 | addresses found. ADDR_STRING contains a vector of (canonical) | |
6350 | address strings. ARG points to the end of the SAL. */ | |
c906108c | 6351 | |
b9362cc7 | 6352 | static void |
c3f6f71d JM |
6353 | parse_breakpoint_sals (char **address, |
6354 | struct symtabs_and_lines *sals, | |
0101ce28 JJ |
6355 | char ***addr_string, |
6356 | int *not_found_ptr) | |
c3f6f71d JM |
6357 | { |
6358 | char *addr_start = *address; | |
6359 | *addr_string = NULL; | |
6360 | /* If no arg given, or if first arg is 'if ', use the default | |
6361 | breakpoint. */ | |
6362 | if ((*address) == NULL | |
6363 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c SS |
6364 | { |
6365 | if (default_breakpoint_valid) | |
6366 | { | |
c3f6f71d | 6367 | struct symtab_and_line sal; |
fe39c653 | 6368 | init_sal (&sal); /* initialize to zeroes */ |
c3f6f71d | 6369 | sals->sals = (struct symtab_and_line *) |
c906108c SS |
6370 | xmalloc (sizeof (struct symtab_and_line)); |
6371 | sal.pc = default_breakpoint_address; | |
6372 | sal.line = default_breakpoint_line; | |
6373 | sal.symtab = default_breakpoint_symtab; | |
6c95b8df | 6374 | sal.pspace = default_breakpoint_pspace; |
c5aa993b | 6375 | sal.section = find_pc_overlay (sal.pc); |
00903456 JK |
6376 | |
6377 | /* "break" without arguments is equivalent to "break *PC" where PC is | |
6378 | the default_breakpoint_address. So make sure to set | |
6379 | sal.explicit_pc to prevent GDB from trying to expand the list of | |
6380 | sals to include all other instances with the same symtab and line. | |
6381 | */ | |
6382 | sal.explicit_pc = 1; | |
6383 | ||
c3f6f71d JM |
6384 | sals->sals[0] = sal; |
6385 | sals->nelts = 1; | |
c906108c SS |
6386 | } |
6387 | else | |
8a3fe4f8 | 6388 | error (_("No default breakpoint address now.")); |
c906108c SS |
6389 | } |
6390 | else | |
6391 | { | |
c906108c | 6392 | /* Force almost all breakpoints to be in terms of the |
c5aa993b JM |
6393 | current_source_symtab (which is decode_line_1's default). This |
6394 | should produce the results we want almost all of the time while | |
1aeae86e AF |
6395 | leaving default_breakpoint_* alone. |
6396 | ObjC: However, don't match an Objective-C method name which | |
6397 | may have a '+' or '-' succeeded by a '[' */ | |
0378c332 | 6398 | |
c214a6fd | 6399 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
0378c332 | 6400 | |
c906108c | 6401 | if (default_breakpoint_valid |
0378c332 | 6402 | && (!cursal.symtab |
1aeae86e AF |
6403 | || ((strchr ("+-", (*address)[0]) != NULL) |
6404 | && ((*address)[1] != '[')))) | |
c3f6f71d | 6405 | *sals = decode_line_1 (address, 1, default_breakpoint_symtab, |
0101ce28 JJ |
6406 | default_breakpoint_line, addr_string, |
6407 | not_found_ptr); | |
c906108c | 6408 | else |
0101ce28 JJ |
6409 | *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, |
6410 | addr_string, not_found_ptr); | |
c906108c | 6411 | } |
c3f6f71d JM |
6412 | /* For any SAL that didn't have a canonical string, fill one in. */ |
6413 | if (sals->nelts > 0 && *addr_string == NULL) | |
6414 | *addr_string = xcalloc (sals->nelts, sizeof (char **)); | |
6415 | if (addr_start != (*address)) | |
c906108c | 6416 | { |
c3f6f71d JM |
6417 | int i; |
6418 | for (i = 0; i < sals->nelts; i++) | |
c906108c | 6419 | { |
c3f6f71d JM |
6420 | /* Add the string if not present. */ |
6421 | if ((*addr_string)[i] == NULL) | |
6422 | (*addr_string)[i] = savestring (addr_start, (*address) - addr_start); | |
c906108c SS |
6423 | } |
6424 | } | |
c3f6f71d | 6425 | } |
c906108c | 6426 | |
c906108c | 6427 | |
c3f6f71d JM |
6428 | /* Convert each SAL into a real PC. Verify that the PC can be |
6429 | inserted as a breakpoint. If it can't throw an error. */ | |
c906108c | 6430 | |
b9362cc7 | 6431 | static void |
c3f6f71d JM |
6432 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals, |
6433 | char *address) | |
6434 | { | |
6435 | int i; | |
6436 | for (i = 0; i < sals->nelts; i++) | |
ee53e872 | 6437 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
6438 | } |
6439 | ||
05ff989b | 6440 | static void |
0101ce28 JJ |
6441 | do_captured_parse_breakpoint (struct ui_out *ui, void *data) |
6442 | { | |
6443 | struct captured_parse_breakpoint_args *args = data; | |
6444 | ||
6445 | parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p, | |
6446 | args->not_found_ptr); | |
0101ce28 JJ |
6447 | } |
6448 | ||
018d34a4 VP |
6449 | /* Given TOK, a string specification of condition and thread, as |
6450 | accepted by the 'break' command, extract the condition | |
6451 | string and thread number and set *COND_STRING and *THREAD. | |
6452 | PC identifies the context at which the condition should be parsed. | |
6453 | If no condition is found, *COND_STRING is set to NULL. | |
6454 | If no thread is found, *THREAD is set to -1. */ | |
6455 | static void | |
6456 | find_condition_and_thread (char *tok, CORE_ADDR pc, | |
4a306c9a | 6457 | char **cond_string, int *thread, int *task) |
018d34a4 VP |
6458 | { |
6459 | *cond_string = NULL; | |
6460 | *thread = -1; | |
6461 | while (tok && *tok) | |
6462 | { | |
6463 | char *end_tok; | |
6464 | int toklen; | |
6465 | char *cond_start = NULL; | |
6466 | char *cond_end = NULL; | |
6467 | while (*tok == ' ' || *tok == '\t') | |
6468 | tok++; | |
6469 | ||
6470 | end_tok = tok; | |
6471 | ||
6472 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
6473 | end_tok++; | |
6474 | ||
6475 | toklen = end_tok - tok; | |
6476 | ||
6477 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
6478 | { | |
f7545552 TT |
6479 | struct expression *expr; |
6480 | ||
018d34a4 | 6481 | tok = cond_start = end_tok + 1; |
f7545552 TT |
6482 | expr = parse_exp_1 (&tok, block_for_pc (pc), 0); |
6483 | xfree (expr); | |
018d34a4 VP |
6484 | cond_end = tok; |
6485 | *cond_string = savestring (cond_start, | |
6486 | cond_end - cond_start); | |
6487 | } | |
6488 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
6489 | { | |
6490 | char *tmptok; | |
6491 | ||
6492 | tok = end_tok + 1; | |
6493 | tmptok = tok; | |
6494 | *thread = strtol (tok, &tok, 0); | |
6495 | if (tok == tmptok) | |
6496 | error (_("Junk after thread keyword.")); | |
6497 | if (!valid_thread_id (*thread)) | |
6498 | error (_("Unknown thread %d."), *thread); | |
6499 | } | |
4a306c9a JB |
6500 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
6501 | { | |
6502 | char *tmptok; | |
6503 | ||
6504 | tok = end_tok + 1; | |
6505 | tmptok = tok; | |
6506 | *task = strtol (tok, &tok, 0); | |
6507 | if (tok == tmptok) | |
6508 | error (_("Junk after task keyword.")); | |
6509 | if (!valid_task_id (*task)) | |
6510 | error (_("Unknown task %d\n"), *task); | |
6511 | } | |
018d34a4 VP |
6512 | else |
6513 | error (_("Junk at end of arguments.")); | |
6514 | } | |
6515 | } | |
6516 | ||
72b2ff0e VP |
6517 | /* Set a breakpoint. This function is shared between |
6518 | CLI and MI functions for setting a breakpoint. | |
6519 | This function has two major modes of operations, | |
6520 | selected by the PARSE_CONDITION_AND_THREAD parameter. | |
6521 | If non-zero, the function will parse arg, extracting | |
6522 | breakpoint location, address and thread. Otherwise, | |
6523 | ARG is just the location of breakpoint, with condition | |
6524 | and thread specified by the COND_STRING and THREAD | |
6525 | parameters. */ | |
0101ce28 | 6526 | |
98deb0da | 6527 | static void |
a6d9a66e UW |
6528 | break_command_really (struct gdbarch *gdbarch, |
6529 | char *arg, char *cond_string, int thread, | |
60c46647 | 6530 | int parse_condition_and_thread, |
1042e4c0 | 6531 | int tempflag, int hardwareflag, int traceflag, |
60c46647 VP |
6532 | int ignore_count, |
6533 | enum auto_boolean pending_break_support, | |
604133b5 | 6534 | struct breakpoint_ops *ops, |
41447f92 VP |
6535 | int from_tty, |
6536 | int enabled) | |
c3f6f71d | 6537 | { |
71fff37b | 6538 | struct gdb_exception e; |
c3f6f71d | 6539 | struct symtabs_and_lines sals; |
0101ce28 | 6540 | struct symtab_and_line pending_sal; |
0101ce28 JJ |
6541 | char *copy_arg; |
6542 | char *err_msg; | |
c3f6f71d JM |
6543 | char *addr_start = arg; |
6544 | char **addr_string; | |
6545 | struct cleanup *old_chain; | |
80c99de1 | 6546 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 6547 | struct captured_parse_breakpoint_args parse_args; |
05ff989b | 6548 | int i; |
0101ce28 | 6549 | int pending = 0; |
0101ce28 | 6550 | int not_found = 0; |
1042e4c0 | 6551 | enum bptype type_wanted; |
4a306c9a | 6552 | int task = 0; |
c3f6f71d | 6553 | |
c3f6f71d JM |
6554 | sals.sals = NULL; |
6555 | sals.nelts = 0; | |
6556 | addr_string = NULL; | |
c3f6f71d | 6557 | |
0101ce28 JJ |
6558 | parse_args.arg_p = &arg; |
6559 | parse_args.sals_p = &sals; | |
6560 | parse_args.addr_string_p = &addr_string; | |
6561 | parse_args.not_found_ptr = ¬_found; | |
6562 | ||
05ff989b AC |
6563 | e = catch_exception (uiout, do_captured_parse_breakpoint, |
6564 | &parse_args, RETURN_MASK_ALL); | |
0101ce28 JJ |
6565 | |
6566 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 6567 | switch (e.reason) |
0101ce28 | 6568 | { |
05ff989b | 6569 | case RETURN_QUIT: |
98deb0da | 6570 | throw_exception (e); |
05ff989b AC |
6571 | case RETURN_ERROR: |
6572 | switch (e.error) | |
0101ce28 | 6573 | { |
05ff989b | 6574 | case NOT_FOUND_ERROR: |
0101ce28 | 6575 | |
05ff989b AC |
6576 | /* If pending breakpoint support is turned off, throw |
6577 | error. */ | |
fa8d40ab JJ |
6578 | |
6579 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
6580 | throw_exception (e); |
6581 | ||
6582 | exception_print (gdb_stderr, e); | |
fa8d40ab | 6583 | |
05ff989b AC |
6584 | /* If pending breakpoint support is auto query and the user |
6585 | selects no, then simply return the error code. */ | |
059fb39f PM |
6586 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
6587 | && !nquery ("Make breakpoint pending on future shared library load? ")) | |
98deb0da | 6588 | return; |
fa8d40ab | 6589 | |
05ff989b AC |
6590 | /* At this point, either the user was queried about setting |
6591 | a pending breakpoint and selected yes, or pending | |
6592 | breakpoint behavior is on and thus a pending breakpoint | |
6593 | is defaulted on behalf of the user. */ | |
0101ce28 JJ |
6594 | copy_arg = xstrdup (addr_start); |
6595 | addr_string = ©_arg; | |
6596 | sals.nelts = 1; | |
6597 | sals.sals = &pending_sal; | |
6598 | pending_sal.pc = 0; | |
6599 | pending = 1; | |
05ff989b AC |
6600 | break; |
6601 | default: | |
98deb0da | 6602 | throw_exception (e); |
0101ce28 | 6603 | } |
05ff989b AC |
6604 | default: |
6605 | if (!sals.nelts) | |
98deb0da | 6606 | return; |
0101ce28 | 6607 | } |
c3f6f71d JM |
6608 | |
6609 | /* Create a chain of things that always need to be cleaned up. */ | |
6610 | old_chain = make_cleanup (null_cleanup, 0); | |
6611 | ||
0101ce28 JJ |
6612 | if (!pending) |
6613 | { | |
6614 | /* Make sure that all storage allocated to SALS gets freed. */ | |
6615 | make_cleanup (xfree, sals.sals); | |
6616 | ||
6617 | /* Cleanup the addr_string array but not its contents. */ | |
6618 | make_cleanup (xfree, addr_string); | |
6619 | } | |
c3f6f71d | 6620 | |
c3f6f71d JM |
6621 | /* ----------------------------- SNIP ----------------------------- |
6622 | Anything added to the cleanup chain beyond this point is assumed | |
6623 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
6624 | then the memory is not reclaimed. */ |
6625 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d JM |
6626 | |
6627 | /* Mark the contents of the addr_string for cleanup. These go on | |
80c99de1 | 6628 | the bkpt_chain and only occur if the breakpoint create fails. */ |
c3f6f71d JM |
6629 | for (i = 0; i < sals.nelts; i++) |
6630 | { | |
6631 | if (addr_string[i] != NULL) | |
b8c9b27d | 6632 | make_cleanup (xfree, addr_string[i]); |
c3f6f71d JM |
6633 | } |
6634 | ||
6635 | /* Resolve all line numbers to PC's and verify that the addresses | |
6636 | are ok for the target. */ | |
0101ce28 JJ |
6637 | if (!pending) |
6638 | breakpoint_sals_to_pc (&sals, addr_start); | |
c3f6f71d | 6639 | |
1042e4c0 SS |
6640 | type_wanted = (traceflag |
6641 | ? bp_tracepoint | |
6642 | : (hardwareflag ? bp_hardware_breakpoint : bp_breakpoint)); | |
6643 | ||
c3f6f71d JM |
6644 | /* Verify that condition can be parsed, before setting any |
6645 | breakpoints. Allocate a separate condition expression for each | |
6646 | breakpoint. */ | |
0101ce28 | 6647 | if (!pending) |
c3f6f71d | 6648 | { |
2f069f6f | 6649 | if (parse_condition_and_thread) |
72b2ff0e VP |
6650 | { |
6651 | /* Here we only parse 'arg' to separate condition | |
6652 | from thread number, so parsing in context of first | |
6653 | sal is OK. When setting the breakpoint we'll | |
6654 | re-parse it in context of each sal. */ | |
6655 | cond_string = NULL; | |
6656 | thread = -1; | |
4a306c9a JB |
6657 | find_condition_and_thread (arg, sals.sals[0].pc, &cond_string, |
6658 | &thread, &task); | |
72b2ff0e VP |
6659 | if (cond_string) |
6660 | make_cleanup (xfree, cond_string); | |
6661 | } | |
2f069f6f | 6662 | else |
72b2ff0e VP |
6663 | { |
6664 | /* Create a private copy of condition string. */ | |
6665 | if (cond_string) | |
6666 | { | |
6667 | cond_string = xstrdup (cond_string); | |
6668 | make_cleanup (xfree, cond_string); | |
6669 | } | |
6670 | } | |
a6d9a66e | 6671 | create_breakpoints (gdbarch, sals, addr_string, cond_string, type_wanted, |
0101ce28 | 6672 | tempflag ? disp_del : disp_donttouch, |
4a306c9a | 6673 | thread, task, ignore_count, ops, from_tty, enabled); |
c906108c | 6674 | } |
0101ce28 JJ |
6675 | else |
6676 | { | |
fe3f5fa8 | 6677 | struct symtab_and_line sal = {0}; |
0101ce28 JJ |
6678 | struct breakpoint *b; |
6679 | ||
0101ce28 JJ |
6680 | make_cleanup (xfree, copy_arg); |
6681 | ||
a6d9a66e | 6682 | b = set_raw_breakpoint_without_location (gdbarch, type_wanted); |
0101ce28 JJ |
6683 | set_breakpoint_count (breakpoint_count + 1); |
6684 | b->number = breakpoint_count; | |
72b2ff0e | 6685 | b->thread = -1; |
018d34a4 | 6686 | b->addr_string = addr_string[0]; |
72b2ff0e | 6687 | b->cond_string = NULL; |
0101ce28 | 6688 | b->ignore_count = ignore_count; |
0101ce28 | 6689 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 6690 | b->condition_not_parsed = 1; |
604133b5 | 6691 | b->ops = ops; |
41447f92 | 6692 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
6c95b8df | 6693 | b->pspace = current_program_space; |
74960c60 | 6694 | |
6c95b8df | 6695 | if (enabled && b->pspace->executing_startup |
8bea4e01 UW |
6696 | && (b->type == bp_breakpoint |
6697 | || b->type == bp_hardware_breakpoint)) | |
6698 | b->enable_state = bp_startup_disabled; | |
6699 | ||
0101ce28 JJ |
6700 | mention (b); |
6701 | } | |
6702 | ||
c3f6f71d | 6703 | if (sals.nelts > 1) |
8a3fe4f8 AC |
6704 | warning (_("Multiple breakpoints were set.\n" |
6705 | "Use the \"delete\" command to delete unwanted breakpoints.")); | |
80c99de1 PA |
6706 | /* That's it. Discard the cleanups for data inserted into the |
6707 | breakpoint. */ | |
6708 | discard_cleanups (bkpt_chain); | |
6709 | /* But cleanup everything else. */ | |
c3f6f71d | 6710 | do_cleanups (old_chain); |
217dc9e2 | 6711 | |
80c99de1 | 6712 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
217dc9e2 | 6713 | update_global_location_list (1); |
c3f6f71d | 6714 | } |
c906108c | 6715 | |
72b2ff0e VP |
6716 | /* Set a breakpoint. |
6717 | ARG is a string describing breakpoint address, | |
6718 | condition, and thread. | |
6719 | FLAG specifies if a breakpoint is hardware on, | |
6720 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
6721 | and BP_TEMPFLAG. */ | |
6722 | ||
98deb0da | 6723 | static void |
72b2ff0e | 6724 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 6725 | { |
72b2ff0e VP |
6726 | int hardwareflag = flag & BP_HARDWAREFLAG; |
6727 | int tempflag = flag & BP_TEMPFLAG; | |
c3f6f71d | 6728 | |
a6d9a66e UW |
6729 | break_command_really (get_current_arch (), |
6730 | arg, | |
98deb0da | 6731 | NULL, 0, 1 /* parse arg */, |
1042e4c0 | 6732 | tempflag, hardwareflag, 0 /* traceflag */, |
98deb0da | 6733 | 0 /* Ignore count */, |
604133b5 AR |
6734 | pending_break_support, |
6735 | NULL /* breakpoint_ops */, | |
41447f92 VP |
6736 | from_tty, |
6737 | 1 /* enabled */); | |
c906108c SS |
6738 | } |
6739 | ||
72b2ff0e | 6740 | |
98deb0da | 6741 | void |
a6d9a66e UW |
6742 | set_breakpoint (struct gdbarch *gdbarch, |
6743 | char *address, char *condition, | |
c3f6f71d | 6744 | int hardwareflag, int tempflag, |
ce43223b | 6745 | int thread, int ignore_count, |
41447f92 | 6746 | int pending, int enabled) |
c3f6f71d | 6747 | { |
a6d9a66e UW |
6748 | break_command_really (gdbarch, |
6749 | address, condition, thread, | |
98deb0da | 6750 | 0 /* condition and thread are valid. */, |
1042e4c0 | 6751 | tempflag, hardwareflag, 0 /* traceflag */, |
98deb0da VP |
6752 | ignore_count, |
6753 | pending | |
6754 | ? AUTO_BOOLEAN_TRUE : AUTO_BOOLEAN_FALSE, | |
41447f92 | 6755 | NULL, 0, enabled); |
c3f6f71d JM |
6756 | } |
6757 | ||
6a048695 JB |
6758 | /* Adjust SAL to the first instruction past the function prologue. |
6759 | The end of the prologue is determined using the line table from | |
3daf8fe5 JG |
6760 | the debugging information. explicit_pc and explicit_line are |
6761 | not modified. | |
6a048695 JB |
6762 | |
6763 | If SAL is already past the prologue, then do nothing. */ | |
6764 | ||
6765 | static void | |
6766 | skip_prologue_sal (struct symtab_and_line *sal) | |
6767 | { | |
6c95b8df | 6768 | struct symbol *sym; |
6a048695 | 6769 | struct symtab_and_line start_sal; |
6c95b8df | 6770 | struct cleanup *old_chain; |
6a048695 | 6771 | |
6c95b8df | 6772 | old_chain = save_current_space_and_thread (); |
6a048695 | 6773 | |
6c95b8df PA |
6774 | sym = find_pc_function (sal->pc); |
6775 | if (sym != NULL) | |
3daf8fe5 | 6776 | { |
6c95b8df PA |
6777 | start_sal = find_function_start_sal (sym, 1); |
6778 | if (sal->pc < start_sal.pc) | |
6779 | { | |
6780 | start_sal.explicit_line = sal->explicit_line; | |
6781 | start_sal.explicit_pc = sal->explicit_pc; | |
6782 | *sal = start_sal; | |
6783 | } | |
3daf8fe5 | 6784 | } |
6c95b8df PA |
6785 | |
6786 | do_cleanups (old_chain); | |
6a048695 | 6787 | } |
c3f6f71d | 6788 | |
c906108c SS |
6789 | /* Helper function for break_command_1 and disassemble_command. */ |
6790 | ||
6791 | void | |
fba45db2 | 6792 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
6793 | { |
6794 | CORE_ADDR pc; | |
6795 | ||
6796 | if (sal->pc == 0 && sal->symtab != NULL) | |
6797 | { | |
6798 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 6799 | error (_("No line %d in file \"%s\"."), |
c906108c SS |
6800 | sal->line, sal->symtab->filename); |
6801 | sal->pc = pc; | |
6a048695 JB |
6802 | |
6803 | /* If this SAL corresponds to a breakpoint inserted using | |
6804 | a line number, then skip the function prologue if necessary. */ | |
6805 | if (sal->explicit_line) | |
56ef84b1 TT |
6806 | { |
6807 | /* Preserve the original line number. */ | |
6808 | int saved_line = sal->line; | |
6809 | skip_prologue_sal (sal); | |
6810 | sal->line = saved_line; | |
6811 | } | |
c906108c SS |
6812 | } |
6813 | ||
6814 | if (sal->section == 0 && sal->symtab != NULL) | |
6815 | { | |
6816 | struct blockvector *bv; | |
c5aa993b JM |
6817 | struct block *b; |
6818 | struct symbol *sym; | |
c906108c | 6819 | |
801e3a5b | 6820 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
6821 | if (bv != NULL) |
6822 | { | |
7f0df278 | 6823 | sym = block_linkage_function (b); |
c906108c SS |
6824 | if (sym != NULL) |
6825 | { | |
6826 | fixup_symbol_section (sym, sal->symtab->objfile); | |
714835d5 | 6827 | sal->section = SYMBOL_OBJ_SECTION (sym); |
c906108c SS |
6828 | } |
6829 | else | |
6830 | { | |
6831 | /* It really is worthwhile to have the section, so we'll just | |
c5aa993b JM |
6832 | have to look harder. This case can be executed if we have |
6833 | line numbers but no functions (as can happen in assembly | |
6834 | source). */ | |
c906108c | 6835 | |
c5aa993b | 6836 | struct minimal_symbol *msym; |
6c95b8df PA |
6837 | struct cleanup *old_chain = save_current_space_and_thread (); |
6838 | ||
6839 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
6840 | |
6841 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
6842 | if (msym) | |
714835d5 | 6843 | sal->section = SYMBOL_OBJ_SECTION (msym); |
6c95b8df PA |
6844 | |
6845 | do_cleanups (old_chain); | |
c906108c SS |
6846 | } |
6847 | } | |
6848 | } | |
6849 | } | |
6850 | ||
6851 | void | |
fba45db2 | 6852 | break_command (char *arg, int from_tty) |
c906108c | 6853 | { |
db107f19 | 6854 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
6855 | } |
6856 | ||
c906108c | 6857 | void |
fba45db2 | 6858 | tbreak_command (char *arg, int from_tty) |
c906108c | 6859 | { |
db107f19 | 6860 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
6861 | } |
6862 | ||
c906108c | 6863 | static void |
fba45db2 | 6864 | hbreak_command (char *arg, int from_tty) |
c906108c | 6865 | { |
db107f19 | 6866 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
6867 | } |
6868 | ||
6869 | static void | |
fba45db2 | 6870 | thbreak_command (char *arg, int from_tty) |
c906108c | 6871 | { |
db107f19 | 6872 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
6873 | } |
6874 | ||
6875 | static void | |
fba45db2 | 6876 | stop_command (char *arg, int from_tty) |
c906108c | 6877 | { |
a3f17187 | 6878 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 6879 | Usage: stop in <function | address>\n\ |
a3f17187 | 6880 | stop at <line>\n")); |
c906108c SS |
6881 | } |
6882 | ||
6883 | static void | |
fba45db2 | 6884 | stopin_command (char *arg, int from_tty) |
c906108c SS |
6885 | { |
6886 | int badInput = 0; | |
6887 | ||
c5aa993b | 6888 | if (arg == (char *) NULL) |
c906108c SS |
6889 | badInput = 1; |
6890 | else if (*arg != '*') | |
6891 | { | |
6892 | char *argptr = arg; | |
6893 | int hasColon = 0; | |
6894 | ||
53a5351d JM |
6895 | /* look for a ':'. If this is a line number specification, then |
6896 | say it is bad, otherwise, it should be an address or | |
6897 | function/method name */ | |
c906108c | 6898 | while (*argptr && !hasColon) |
c5aa993b JM |
6899 | { |
6900 | hasColon = (*argptr == ':'); | |
6901 | argptr++; | |
6902 | } | |
c906108c SS |
6903 | |
6904 | if (hasColon) | |
c5aa993b | 6905 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 6906 | else |
c5aa993b | 6907 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
6908 | } |
6909 | ||
6910 | if (badInput) | |
a3f17187 | 6911 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 6912 | else |
db107f19 | 6913 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
6914 | } |
6915 | ||
6916 | static void | |
fba45db2 | 6917 | stopat_command (char *arg, int from_tty) |
c906108c SS |
6918 | { |
6919 | int badInput = 0; | |
6920 | ||
c5aa993b | 6921 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
6922 | badInput = 1; |
6923 | else | |
6924 | { | |
6925 | char *argptr = arg; | |
6926 | int hasColon = 0; | |
6927 | ||
6928 | /* look for a ':'. If there is a '::' then get out, otherwise | |
c5aa993b | 6929 | it is probably a line number. */ |
c906108c | 6930 | while (*argptr && !hasColon) |
c5aa993b JM |
6931 | { |
6932 | hasColon = (*argptr == ':'); | |
6933 | argptr++; | |
6934 | } | |
c906108c SS |
6935 | |
6936 | if (hasColon) | |
c5aa993b | 6937 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 6938 | else |
c5aa993b | 6939 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
6940 | } |
6941 | ||
6942 | if (badInput) | |
a3f17187 | 6943 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 6944 | else |
db107f19 | 6945 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
6946 | } |
6947 | ||
53a5351d JM |
6948 | /* accessflag: hw_write: watch write, |
6949 | hw_read: watch read, | |
6950 | hw_access: watch access (read or write) */ | |
c906108c | 6951 | static void |
fba45db2 | 6952 | watch_command_1 (char *arg, int accessflag, int from_tty) |
c906108c | 6953 | { |
a6d9a66e | 6954 | struct gdbarch *gdbarch = get_current_arch (); |
d983da9c | 6955 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c SS |
6956 | struct symtab_and_line sal; |
6957 | struct expression *exp; | |
6958 | struct block *exp_valid_block; | |
6959 | struct value *val, *mark; | |
6960 | struct frame_info *frame; | |
c906108c SS |
6961 | char *exp_start = NULL; |
6962 | char *exp_end = NULL; | |
37e4754d | 6963 | char *tok, *id_tok_start, *end_tok; |
c906108c SS |
6964 | int toklen; |
6965 | char *cond_start = NULL; | |
6966 | char *cond_end = NULL; | |
6967 | struct expression *cond = NULL; | |
6968 | int i, other_type_used, target_resources_ok = 0; | |
6969 | enum bptype bp_type; | |
6970 | int mem_cnt = 0; | |
37e4754d | 6971 | int thread = -1; |
c906108c | 6972 | |
fe39c653 | 6973 | init_sal (&sal); /* initialize to zeroes */ |
c5aa993b | 6974 | |
37e4754d LM |
6975 | /* Make sure that we actually have parameters to parse. */ |
6976 | if (arg != NULL && arg[0] != '\0') | |
6977 | { | |
6978 | toklen = strlen (arg); /* Size of argument list. */ | |
6979 | ||
6980 | /* Points tok to the end of the argument list. */ | |
6981 | tok = arg + toklen - 1; | |
6982 | ||
6983 | /* Go backwards in the parameters list. Skip the last parameter. | |
6984 | If we're expecting a 'thread <thread_num>' parameter, this should | |
6985 | be the thread identifier. */ | |
6986 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
6987 | tok--; | |
6988 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
6989 | tok--; | |
6990 | ||
6991 | /* Points end_tok to the beginning of the last token. */ | |
6992 | id_tok_start = tok + 1; | |
6993 | ||
6994 | /* Go backwards in the parameters list. Skip one more parameter. | |
6995 | If we're expecting a 'thread <thread_num>' parameter, we should | |
6996 | reach a "thread" token. */ | |
6997 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
6998 | tok--; | |
6999 | ||
7000 | end_tok = tok; | |
7001 | ||
7002 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
7003 | tok--; | |
7004 | ||
7005 | /* Move the pointer forward to skip the whitespace and | |
7006 | calculate the length of the token. */ | |
7007 | tok++; | |
7008 | toklen = end_tok - tok; | |
7009 | ||
7010 | if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
7011 | { | |
7012 | /* At this point we've found a "thread" token, which means | |
7013 | the user is trying to set a watchpoint that triggers | |
7014 | only in a specific thread. */ | |
7015 | char *endp; | |
7016 | ||
7017 | /* Extract the thread ID from the next token. */ | |
7018 | thread = strtol (id_tok_start, &endp, 0); | |
7019 | ||
7020 | /* Check if the user provided a valid numeric value for the | |
7021 | thread ID. */ | |
7022 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
7023 | error (_("Invalid thread ID specification %s."), id_tok_start); | |
7024 | ||
7025 | /* Check if the thread actually exists. */ | |
7026 | if (!valid_thread_id (thread)) | |
7027 | error (_("Unknown thread %d."), thread); | |
7028 | ||
7029 | /* Truncate the string and get rid of the thread <thread_num> | |
7030 | parameter before the parameter list is parsed by the | |
7031 | evaluate_expression() function. */ | |
7032 | *tok = '\0'; | |
7033 | } | |
7034 | } | |
7035 | ||
6c95b8df PA |
7036 | sal.pspace = current_program_space; |
7037 | ||
37e4754d | 7038 | /* Parse the rest of the arguments. */ |
c906108c SS |
7039 | innermost_block = NULL; |
7040 | exp_start = arg; | |
7041 | exp = parse_exp_1 (&arg, 0, 0); | |
7042 | exp_end = arg; | |
fa8a61dc TT |
7043 | /* Remove trailing whitespace from the expression before saving it. |
7044 | This makes the eventual display of the expression string a bit | |
7045 | prettier. */ | |
7046 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
7047 | --exp_end; | |
7048 | ||
c906108c SS |
7049 | exp_valid_block = innermost_block; |
7050 | mark = value_mark (); | |
fa4727a6 DJ |
7051 | fetch_watchpoint_value (exp, &val, NULL, NULL); |
7052 | if (val != NULL) | |
7053 | release_value (val); | |
c906108c SS |
7054 | |
7055 | tok = arg; | |
7056 | while (*tok == ' ' || *tok == '\t') | |
7057 | tok++; | |
7058 | end_tok = tok; | |
7059 | ||
7060 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
7061 | end_tok++; | |
7062 | ||
7063 | toklen = end_tok - tok; | |
7064 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
7065 | { | |
7066 | tok = cond_start = end_tok + 1; | |
7067 | cond = parse_exp_1 (&tok, 0, 0); | |
7068 | cond_end = tok; | |
7069 | } | |
7070 | if (*tok) | |
8a3fe4f8 | 7071 | error (_("Junk at end of command.")); |
c906108c | 7072 | |
53a5351d | 7073 | if (accessflag == hw_read) |
c5aa993b | 7074 | bp_type = bp_read_watchpoint; |
53a5351d | 7075 | else if (accessflag == hw_access) |
c5aa993b JM |
7076 | bp_type = bp_access_watchpoint; |
7077 | else | |
7078 | bp_type = bp_hardware_watchpoint; | |
c906108c SS |
7079 | |
7080 | mem_cnt = can_use_hardware_watchpoint (val); | |
7081 | if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint) | |
8a3fe4f8 | 7082 | error (_("Expression cannot be implemented with read/access watchpoint.")); |
c5aa993b JM |
7083 | if (mem_cnt != 0) |
7084 | { | |
7085 | i = hw_watchpoint_used_count (bp_type, &other_type_used); | |
53a5351d | 7086 | target_resources_ok = |
d92524f1 | 7087 | target_can_use_hardware_watchpoint (bp_type, i + mem_cnt, |
53a5351d | 7088 | other_type_used); |
c5aa993b | 7089 | if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint) |
8a3fe4f8 | 7090 | error (_("Target does not support this type of hardware watchpoint.")); |
53a5351d | 7091 | |
c5aa993b | 7092 | if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint) |
8a3fe4f8 | 7093 | error (_("Target can only support one kind of HW watchpoint at a time.")); |
c5aa993b | 7094 | } |
c906108c | 7095 | |
4d28f7a8 KB |
7096 | /* Change the type of breakpoint to an ordinary watchpoint if a hardware |
7097 | watchpoint could not be set. */ | |
7098 | if (!mem_cnt || target_resources_ok <= 0) | |
7099 | bp_type = bp_watchpoint; | |
7100 | ||
d983da9c | 7101 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
7102 | |
7103 | /* If the expression is "local", then set up a "watchpoint scope" | |
7104 | breakpoint at the point where we've left the scope of the watchpoint | |
7105 | expression. Create the scope breakpoint before the watchpoint, so | |
7106 | that we will encounter it first in bpstat_stop_status. */ | |
edb3359d | 7107 | if (innermost_block && frame) |
d983da9c | 7108 | { |
edb3359d DJ |
7109 | if (frame_id_p (frame_unwind_caller_id (frame))) |
7110 | { | |
7111 | scope_breakpoint | |
a6d9a66e UW |
7112 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
7113 | frame_unwind_caller_pc (frame), | |
edb3359d | 7114 | bp_watchpoint_scope); |
d983da9c | 7115 | |
edb3359d | 7116 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 7117 | |
edb3359d DJ |
7118 | /* Automatically delete the breakpoint when it hits. */ |
7119 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 7120 | |
edb3359d DJ |
7121 | /* Only break in the proper frame (help with recursion). */ |
7122 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 7123 | |
edb3359d | 7124 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
7125 | scope_breakpoint->loc->gdbarch |
7126 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
7127 | scope_breakpoint->loc->requested_address |
7128 | = frame_unwind_caller_pc (frame); | |
7129 | scope_breakpoint->loc->address | |
a6d9a66e UW |
7130 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
7131 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
7132 | scope_breakpoint->type); |
7133 | } | |
d983da9c DJ |
7134 | } |
7135 | ||
c906108c | 7136 | /* Now set up the breakpoint. */ |
a6d9a66e | 7137 | b = set_raw_breakpoint (gdbarch, sal, bp_type); |
c906108c SS |
7138 | set_breakpoint_count (breakpoint_count + 1); |
7139 | b->number = breakpoint_count; | |
37e4754d | 7140 | b->thread = thread; |
b5de0fa7 | 7141 | b->disposition = disp_donttouch; |
c906108c SS |
7142 | b->exp = exp; |
7143 | b->exp_valid_block = exp_valid_block; | |
7144 | b->exp_string = savestring (exp_start, exp_end - exp_start); | |
7145 | b->val = val; | |
fa4727a6 | 7146 | b->val_valid = 1; |
511a6cd4 | 7147 | b->loc->cond = cond; |
c906108c SS |
7148 | if (cond_start) |
7149 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
7150 | else | |
7151 | b->cond_string = 0; | |
c5aa993b | 7152 | |
c906108c | 7153 | if (frame) |
d983da9c | 7154 | b->watchpoint_frame = get_frame_id (frame); |
c906108c | 7155 | else |
35a487f1 | 7156 | b->watchpoint_frame = null_frame_id; |
c906108c | 7157 | |
d983da9c | 7158 | if (scope_breakpoint != NULL) |
c906108c | 7159 | { |
d983da9c DJ |
7160 | /* The scope breakpoint is related to the watchpoint. We will |
7161 | need to act on them together. */ | |
7162 | b->related_breakpoint = scope_breakpoint; | |
7163 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 7164 | } |
d983da9c | 7165 | |
c906108c SS |
7166 | value_free_to_mark (mark); |
7167 | mention (b); | |
b60e7edf | 7168 | update_global_location_list (1); |
c906108c SS |
7169 | } |
7170 | ||
7171 | /* Return count of locations need to be watched and can be handled | |
7172 | in hardware. If the watchpoint can not be handled | |
7173 | in hardware return zero. */ | |
7174 | ||
c906108c | 7175 | static int |
fba45db2 | 7176 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
7177 | { |
7178 | int found_memory_cnt = 0; | |
2e70b7b9 | 7179 | struct value *head = v; |
c906108c SS |
7180 | |
7181 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 7182 | if (!can_use_hw_watchpoints) |
c906108c | 7183 | return 0; |
c5aa993b | 7184 | |
5c44784c JM |
7185 | /* Make sure that the value of the expression depends only upon |
7186 | memory contents, and values computed from them within GDB. If we | |
7187 | find any register references or function calls, we can't use a | |
7188 | hardware watchpoint. | |
7189 | ||
7190 | The idea here is that evaluating an expression generates a series | |
7191 | of values, one holding the value of every subexpression. (The | |
7192 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
7193 | a*b+c.) GDB's values hold almost enough information to establish | |
7194 | the criteria given above --- they identify memory lvalues, | |
7195 | register lvalues, computed values, etcetera. So we can evaluate | |
7196 | the expression, and then scan the chain of values that leaves | |
7197 | behind to decide whether we can detect any possible change to the | |
7198 | expression's final value using only hardware watchpoints. | |
7199 | ||
7200 | However, I don't think that the values returned by inferior | |
7201 | function calls are special in any way. So this function may not | |
7202 | notice that an expression involving an inferior function call | |
7203 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 7204 | for (; v; v = value_next (v)) |
c906108c | 7205 | { |
5c44784c | 7206 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 7207 | { |
d69fe07e | 7208 | if (value_lazy (v)) |
5c44784c JM |
7209 | /* A lazy memory lvalue is one that GDB never needed to fetch; |
7210 | we either just used its address (e.g., `a' in `a.b') or | |
7211 | we never needed it at all (e.g., `a' in `a,b'). */ | |
7212 | ; | |
53a5351d | 7213 | else |
5c44784c JM |
7214 | { |
7215 | /* Ahh, memory we actually used! Check if we can cover | |
7216 | it with hardware watchpoints. */ | |
df407dfe | 7217 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
7218 | |
7219 | /* We only watch structs and arrays if user asked for it | |
7220 | explicitly, never if they just happen to appear in a | |
7221 | middle of some value chain. */ | |
7222 | if (v == head | |
7223 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
7224 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
7225 | { | |
42ae5230 | 7226 | CORE_ADDR vaddr = value_address (v); |
df407dfe | 7227 | int len = TYPE_LENGTH (value_type (v)); |
2e70b7b9 | 7228 | |
d92524f1 | 7229 | if (!target_region_ok_for_hw_watchpoint (vaddr, len)) |
2e70b7b9 MS |
7230 | return 0; |
7231 | else | |
7232 | found_memory_cnt++; | |
7233 | } | |
5c44784c | 7234 | } |
c5aa993b | 7235 | } |
5086187c AC |
7236 | else if (VALUE_LVAL (v) != not_lval |
7237 | && deprecated_value_modifiable (v) == 0) | |
53a5351d | 7238 | return 0; /* ??? What does this represent? */ |
5086187c | 7239 | else if (VALUE_LVAL (v) == lval_register) |
53a5351d | 7240 | return 0; /* cannot watch a register with a HW watchpoint */ |
c906108c SS |
7241 | } |
7242 | ||
7243 | /* The expression itself looks suitable for using a hardware | |
7244 | watchpoint, but give the target machine a chance to reject it. */ | |
7245 | return found_memory_cnt; | |
7246 | } | |
7247 | ||
8b93c638 | 7248 | void |
fba45db2 | 7249 | watch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
7250 | { |
7251 | watch_command (arg, from_tty); | |
7252 | } | |
8926118c | 7253 | |
c5aa993b | 7254 | static void |
fba45db2 | 7255 | watch_command (char *arg, int from_tty) |
c906108c | 7256 | { |
53a5351d | 7257 | watch_command_1 (arg, hw_write, from_tty); |
c906108c SS |
7258 | } |
7259 | ||
8b93c638 | 7260 | void |
fba45db2 | 7261 | rwatch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
7262 | { |
7263 | rwatch_command (arg, from_tty); | |
7264 | } | |
8926118c | 7265 | |
c5aa993b | 7266 | static void |
fba45db2 | 7267 | rwatch_command (char *arg, int from_tty) |
c906108c | 7268 | { |
53a5351d | 7269 | watch_command_1 (arg, hw_read, from_tty); |
c906108c SS |
7270 | } |
7271 | ||
8b93c638 | 7272 | void |
fba45db2 | 7273 | awatch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
7274 | { |
7275 | awatch_command (arg, from_tty); | |
7276 | } | |
8926118c | 7277 | |
c5aa993b | 7278 | static void |
fba45db2 | 7279 | awatch_command (char *arg, int from_tty) |
c906108c | 7280 | { |
53a5351d | 7281 | watch_command_1 (arg, hw_access, from_tty); |
c906108c | 7282 | } |
c906108c | 7283 | \f |
c5aa993b | 7284 | |
43ff13b4 | 7285 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
7286 | because it uses the mechanisms of breakpoints. */ |
7287 | ||
bfec99b2 PA |
7288 | struct until_break_command_continuation_args |
7289 | { | |
7290 | struct breakpoint *breakpoint; | |
7291 | struct breakpoint *breakpoint2; | |
7292 | }; | |
7293 | ||
43ff13b4 JM |
7294 | /* This function is called by fetch_inferior_event via the |
7295 | cmd_continuation pointer, to complete the until command. It takes | |
7296 | care of cleaning up the temporary breakpoints set up by the until | |
7297 | command. */ | |
c2c6d25f | 7298 | static void |
604ead4a | 7299 | until_break_command_continuation (void *arg) |
43ff13b4 | 7300 | { |
bfec99b2 PA |
7301 | struct until_break_command_continuation_args *a = arg; |
7302 | ||
7303 | delete_breakpoint (a->breakpoint); | |
7304 | if (a->breakpoint2) | |
7305 | delete_breakpoint (a->breakpoint2); | |
43ff13b4 JM |
7306 | } |
7307 | ||
c906108c | 7308 | void |
ae66c1fc | 7309 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
7310 | { |
7311 | struct symtabs_and_lines sals; | |
7312 | struct symtab_and_line sal; | |
206415a3 | 7313 | struct frame_info *frame = get_selected_frame (NULL); |
c906108c | 7314 | struct breakpoint *breakpoint; |
f107f563 | 7315 | struct breakpoint *breakpoint2 = NULL; |
c906108c SS |
7316 | struct cleanup *old_chain; |
7317 | ||
7318 | clear_proceed_status (); | |
7319 | ||
7320 | /* Set a breakpoint where the user wants it and at return from | |
7321 | this function */ | |
c5aa993b | 7322 | |
c906108c SS |
7323 | if (default_breakpoint_valid) |
7324 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, | |
68219205 | 7325 | default_breakpoint_line, (char ***) NULL, NULL); |
c906108c | 7326 | else |
53a5351d | 7327 | sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, |
68219205 | 7328 | 0, (char ***) NULL, NULL); |
c5aa993b | 7329 | |
c906108c | 7330 | if (sals.nelts != 1) |
8a3fe4f8 | 7331 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 7332 | |
c906108c | 7333 | sal = sals.sals[0]; |
b8c9b27d | 7334 | xfree (sals.sals); /* malloc'd, so freed */ |
c5aa993b | 7335 | |
c906108c | 7336 | if (*arg) |
8a3fe4f8 | 7337 | error (_("Junk at end of arguments.")); |
c5aa993b | 7338 | |
c906108c | 7339 | resolve_sal_pc (&sal); |
c5aa993b | 7340 | |
ae66c1fc EZ |
7341 | if (anywhere) |
7342 | /* If the user told us to continue until a specified location, | |
7343 | we don't specify a frame at which we need to stop. */ | |
a6d9a66e UW |
7344 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
7345 | null_frame_id, bp_until); | |
ae66c1fc | 7346 | else |
edb3359d | 7347 | /* Otherwise, specify the selected frame, because we want to stop only |
ae66c1fc | 7348 | at the very same frame. */ |
a6d9a66e UW |
7349 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
7350 | get_stack_frame_id (frame), | |
ae66c1fc | 7351 | bp_until); |
c5aa993b | 7352 | |
f107f563 | 7353 | old_chain = make_cleanup_delete_breakpoint (breakpoint); |
c906108c | 7354 | |
ae66c1fc EZ |
7355 | /* Keep within the current frame, or in frames called by the current |
7356 | one. */ | |
edb3359d DJ |
7357 | |
7358 | if (frame_id_p (frame_unwind_caller_id (frame))) | |
c906108c | 7359 | { |
edb3359d DJ |
7360 | sal = find_pc_line (frame_unwind_caller_pc (frame), 0); |
7361 | sal.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e UW |
7362 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
7363 | sal, | |
edb3359d | 7364 | frame_unwind_caller_id (frame), |
f107f563 VP |
7365 | bp_until); |
7366 | make_cleanup_delete_breakpoint (breakpoint2); | |
c906108c | 7367 | } |
c5aa993b | 7368 | |
c906108c | 7369 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
f107f563 VP |
7370 | |
7371 | /* If we are running asynchronously, and proceed call above has actually | |
7372 | managed to start the target, arrange for breakpoints to be | |
7373 | deleted when the target stops. Otherwise, we're already stopped and | |
7374 | delete breakpoints via cleanup chain. */ | |
7375 | ||
8ea051c5 | 7376 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 7377 | { |
bfec99b2 PA |
7378 | struct until_break_command_continuation_args *args; |
7379 | args = xmalloc (sizeof (*args)); | |
f107f563 | 7380 | |
bfec99b2 PA |
7381 | args->breakpoint = breakpoint; |
7382 | args->breakpoint2 = breakpoint2; | |
f107f563 VP |
7383 | |
7384 | discard_cleanups (old_chain); | |
95e54da7 PA |
7385 | add_continuation (inferior_thread (), |
7386 | until_break_command_continuation, args, | |
604ead4a | 7387 | xfree); |
f107f563 VP |
7388 | } |
7389 | else | |
c5aa993b | 7390 | do_cleanups (old_chain); |
c906108c | 7391 | } |
ae66c1fc | 7392 | |
c906108c | 7393 | static void |
fba45db2 | 7394 | ep_skip_leading_whitespace (char **s) |
c906108c | 7395 | { |
c5aa993b JM |
7396 | if ((s == NULL) || (*s == NULL)) |
7397 | return; | |
7398 | while (isspace (**s)) | |
7399 | *s += 1; | |
c906108c | 7400 | } |
c5aa993b | 7401 | |
c906108c SS |
7402 | /* This function attempts to parse an optional "if <cond>" clause |
7403 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 7404 | |
c906108c SS |
7405 | Else, it returns a pointer to the condition string. (It does not |
7406 | attempt to evaluate the string against a particular block.) And, | |
7407 | it updates arg to point to the first character following the parsed | |
7408 | if clause in the arg string. */ | |
53a5351d | 7409 | |
c906108c | 7410 | static char * |
fba45db2 | 7411 | ep_parse_optional_if_clause (char **arg) |
c906108c | 7412 | { |
c5aa993b JM |
7413 | char *cond_string; |
7414 | ||
7415 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 7416 | return NULL; |
c5aa993b | 7417 | |
c906108c SS |
7418 | /* Skip the "if" keyword. */ |
7419 | (*arg) += 2; | |
c5aa993b | 7420 | |
c906108c SS |
7421 | /* Skip any extra leading whitespace, and record the start of the |
7422 | condition string. */ | |
7423 | ep_skip_leading_whitespace (arg); | |
7424 | cond_string = *arg; | |
c5aa993b | 7425 | |
c906108c SS |
7426 | /* Assume that the condition occupies the remainder of the arg string. */ |
7427 | (*arg) += strlen (cond_string); | |
c5aa993b | 7428 | |
c906108c SS |
7429 | return cond_string; |
7430 | } | |
c5aa993b | 7431 | |
c906108c SS |
7432 | /* This function attempts to parse an optional filename from the arg |
7433 | string. If one is not found, it returns NULL. | |
c5aa993b | 7434 | |
c906108c SS |
7435 | Else, it returns a pointer to the parsed filename. (This function |
7436 | makes no attempt to verify that a file of that name exists, or is | |
7437 | accessible.) And, it updates arg to point to the first character | |
7438 | following the parsed filename in the arg string. | |
c5aa993b | 7439 | |
c906108c SS |
7440 | Note that clients needing to preserve the returned filename for |
7441 | future access should copy it to their own buffers. */ | |
7442 | static char * | |
fba45db2 | 7443 | ep_parse_optional_filename (char **arg) |
c906108c | 7444 | { |
c5aa993b JM |
7445 | static char filename[1024]; |
7446 | char *arg_p = *arg; | |
7447 | int i; | |
7448 | char c; | |
7449 | ||
c906108c SS |
7450 | if ((*arg_p == '\0') || isspace (*arg_p)) |
7451 | return NULL; | |
c5aa993b JM |
7452 | |
7453 | for (i = 0;; i++) | |
c906108c SS |
7454 | { |
7455 | c = *arg_p; | |
7456 | if (isspace (c)) | |
c5aa993b | 7457 | c = '\0'; |
c906108c SS |
7458 | filename[i] = c; |
7459 | if (c == '\0') | |
c5aa993b | 7460 | break; |
c906108c SS |
7461 | arg_p++; |
7462 | } | |
7463 | *arg = arg_p; | |
c5aa993b | 7464 | |
c906108c SS |
7465 | return filename; |
7466 | } | |
c5aa993b | 7467 | |
c906108c SS |
7468 | /* Commands to deal with catching events, such as signals, exceptions, |
7469 | process start/exit, etc. */ | |
c5aa993b JM |
7470 | |
7471 | typedef enum | |
7472 | { | |
44feb3ce TT |
7473 | catch_fork_temporary, catch_vfork_temporary, |
7474 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
7475 | } |
7476 | catch_fork_kind; | |
7477 | ||
c906108c | 7478 | static void |
44feb3ce | 7479 | catch_fork_command_1 (char *arg, int from_tty, struct cmd_list_element *command) |
c906108c | 7480 | { |
a6d9a66e | 7481 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 7482 | char *cond_string = NULL; |
44feb3ce TT |
7483 | catch_fork_kind fork_kind; |
7484 | int tempflag; | |
7485 | ||
7486 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
7487 | tempflag = (fork_kind == catch_fork_temporary | |
7488 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 7489 | |
44feb3ce TT |
7490 | if (!arg) |
7491 | arg = ""; | |
c906108c | 7492 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 7493 | |
c906108c | 7494 | /* The allowed syntax is: |
c5aa993b JM |
7495 | catch [v]fork |
7496 | catch [v]fork if <cond> | |
7497 | ||
c906108c SS |
7498 | First, check if there's an if clause. */ |
7499 | cond_string = ep_parse_optional_if_clause (&arg); | |
c5aa993b | 7500 | |
c906108c | 7501 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 7502 | error (_("Junk at end of arguments.")); |
c5aa993b | 7503 | |
c906108c SS |
7504 | /* If this target supports it, create a fork or vfork catchpoint |
7505 | and enable reporting of such events. */ | |
c5aa993b JM |
7506 | switch (fork_kind) |
7507 | { | |
44feb3ce TT |
7508 | case catch_fork_temporary: |
7509 | case catch_fork_permanent: | |
a6d9a66e | 7510 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 7511 | &catch_fork_breakpoint_ops); |
c906108c | 7512 | break; |
44feb3ce TT |
7513 | case catch_vfork_temporary: |
7514 | case catch_vfork_permanent: | |
a6d9a66e | 7515 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 7516 | &catch_vfork_breakpoint_ops); |
c906108c | 7517 | break; |
c5aa993b | 7518 | default: |
8a3fe4f8 | 7519 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 7520 | break; |
c5aa993b | 7521 | } |
c906108c SS |
7522 | } |
7523 | ||
7524 | static void | |
44feb3ce | 7525 | catch_exec_command_1 (char *arg, int from_tty, struct cmd_list_element *command) |
c906108c | 7526 | { |
a6d9a66e | 7527 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 7528 | int tempflag; |
c5aa993b | 7529 | char *cond_string = NULL; |
c906108c | 7530 | |
44feb3ce TT |
7531 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
7532 | ||
7533 | if (!arg) | |
7534 | arg = ""; | |
c906108c SS |
7535 | ep_skip_leading_whitespace (&arg); |
7536 | ||
7537 | /* The allowed syntax is: | |
c5aa993b JM |
7538 | catch exec |
7539 | catch exec if <cond> | |
c906108c SS |
7540 | |
7541 | First, check if there's an if clause. */ | |
7542 | cond_string = ep_parse_optional_if_clause (&arg); | |
7543 | ||
7544 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 7545 | error (_("Junk at end of arguments.")); |
c906108c SS |
7546 | |
7547 | /* If this target supports it, create an exec catchpoint | |
7548 | and enable reporting of such events. */ | |
a6d9a66e UW |
7549 | create_catchpoint (gdbarch, tempflag, cond_string, |
7550 | &catch_exec_breakpoint_ops); | |
c906108c | 7551 | } |
c5aa993b | 7552 | |
3086aeae DJ |
7553 | static enum print_stop_action |
7554 | print_exception_catchpoint (struct breakpoint *b) | |
7555 | { | |
ade92717 | 7556 | int bp_temp, bp_throw; |
3086aeae | 7557 | |
ade92717 | 7558 | annotate_catchpoint (b->number); |
3086aeae | 7559 | |
ade92717 AR |
7560 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
7561 | if (b->loc->address != b->loc->requested_address) | |
7562 | breakpoint_adjustment_warning (b->loc->requested_address, | |
7563 | b->loc->address, | |
7564 | b->number, 1); | |
df2b6d2d | 7565 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
7566 | ui_out_text (uiout, |
7567 | bp_temp ? "Temporary catchpoint " | |
7568 | : "Catchpoint "); | |
7569 | if (!ui_out_is_mi_like_p (uiout)) | |
7570 | ui_out_field_int (uiout, "bkptno", b->number); | |
7571 | ui_out_text (uiout, | |
c0b37c48 AR |
7572 | bp_throw ? " (exception thrown), " |
7573 | : " (exception caught), "); | |
ade92717 AR |
7574 | if (ui_out_is_mi_like_p (uiout)) |
7575 | { | |
7576 | ui_out_field_string (uiout, "reason", | |
7577 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
7578 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
7579 | ui_out_field_int (uiout, "bkptno", b->number); | |
7580 | } | |
3086aeae DJ |
7581 | return PRINT_SRC_AND_LOC; |
7582 | } | |
7583 | ||
7584 | static void | |
a6d9a66e | 7585 | print_one_exception_catchpoint (struct breakpoint *b, struct bp_location **last_loc) |
3086aeae | 7586 | { |
79a45b7d TT |
7587 | struct value_print_options opts; |
7588 | get_user_print_options (&opts); | |
7589 | if (opts.addressprint) | |
3086aeae DJ |
7590 | { |
7591 | annotate_field (4); | |
604133b5 AR |
7592 | if (b->loc == NULL || b->loc->shlib_disabled) |
7593 | ui_out_field_string (uiout, "addr", "<PENDING>"); | |
7594 | else | |
5af949e3 UW |
7595 | ui_out_field_core_addr (uiout, "addr", |
7596 | b->loc->gdbarch, b->loc->address); | |
3086aeae DJ |
7597 | } |
7598 | annotate_field (5); | |
604133b5 | 7599 | if (b->loc) |
a6d9a66e | 7600 | *last_loc = b->loc; |
3086aeae DJ |
7601 | if (strstr (b->addr_string, "throw") != NULL) |
7602 | ui_out_field_string (uiout, "what", "exception throw"); | |
7603 | else | |
7604 | ui_out_field_string (uiout, "what", "exception catch"); | |
7605 | } | |
7606 | ||
7607 | static void | |
7608 | print_mention_exception_catchpoint (struct breakpoint *b) | |
7609 | { | |
ade92717 AR |
7610 | int bp_temp; |
7611 | int bp_throw; | |
7612 | ||
df2b6d2d | 7613 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
7614 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
7615 | ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ") | |
7616 | : _("Catchpoint ")); | |
7617 | ui_out_field_int (uiout, "bkptno", b->number); | |
7618 | ui_out_text (uiout, bp_throw ? _(" (throw)") | |
7619 | : _(" (catch)")); | |
3086aeae DJ |
7620 | } |
7621 | ||
7622 | static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = { | |
ce78b96d JB |
7623 | NULL, /* insert */ |
7624 | NULL, /* remove */ | |
7625 | NULL, /* breakpoint_hit */ | |
3086aeae DJ |
7626 | print_exception_catchpoint, |
7627 | print_one_exception_catchpoint, | |
7628 | print_mention_exception_catchpoint | |
7629 | }; | |
7630 | ||
7631 | static int | |
7632 | handle_gnu_v3_exceptions (int tempflag, char *cond_string, | |
7633 | enum exception_event_kind ex_event, int from_tty) | |
7634 | { | |
604133b5 AR |
7635 | char *trigger_func_name; |
7636 | ||
3086aeae | 7637 | if (ex_event == EX_EVENT_CATCH) |
604133b5 | 7638 | trigger_func_name = "__cxa_begin_catch"; |
3086aeae | 7639 | else |
604133b5 | 7640 | trigger_func_name = "__cxa_throw"; |
3086aeae | 7641 | |
a6d9a66e UW |
7642 | break_command_really (get_current_arch (), |
7643 | trigger_func_name, cond_string, -1, | |
604133b5 | 7644 | 0 /* condition and thread are valid. */, |
1042e4c0 | 7645 | tempflag, 0, 0, |
604133b5 AR |
7646 | 0, |
7647 | AUTO_BOOLEAN_TRUE /* pending */, | |
41447f92 VP |
7648 | &gnu_v3_exception_catchpoint_ops, from_tty, |
7649 | 1 /* enabled */); | |
3086aeae | 7650 | |
3086aeae DJ |
7651 | return 1; |
7652 | } | |
7653 | ||
c5aa993b | 7654 | /* Deal with "catch catch" and "catch throw" commands */ |
c906108c SS |
7655 | |
7656 | static void | |
fba45db2 KB |
7657 | catch_exception_command_1 (enum exception_event_kind ex_event, char *arg, |
7658 | int tempflag, int from_tty) | |
c906108c | 7659 | { |
c5aa993b JM |
7660 | char *cond_string = NULL; |
7661 | struct symtab_and_line *sal = NULL; | |
7662 | ||
44feb3ce TT |
7663 | if (!arg) |
7664 | arg = ""; | |
c906108c | 7665 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 7666 | |
c906108c SS |
7667 | cond_string = ep_parse_optional_if_clause (&arg); |
7668 | ||
7669 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 7670 | error (_("Junk at end of arguments.")); |
c906108c | 7671 | |
059fb39f PM |
7672 | if (ex_event != EX_EVENT_THROW |
7673 | && ex_event != EX_EVENT_CATCH) | |
8a3fe4f8 | 7674 | error (_("Unsupported or unknown exception event; cannot catch it")); |
c906108c | 7675 | |
3086aeae DJ |
7676 | if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty)) |
7677 | return; | |
7678 | ||
8a3fe4f8 | 7679 | warning (_("Unsupported with this platform/compiler combination.")); |
c906108c SS |
7680 | } |
7681 | ||
44feb3ce TT |
7682 | /* Implementation of "catch catch" command. */ |
7683 | ||
7684 | static void | |
7685 | catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command) | |
7686 | { | |
7687 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
7688 | catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty); | |
7689 | } | |
7690 | ||
7691 | /* Implementation of "catch throw" command. */ | |
7692 | ||
7693 | static void | |
7694 | catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command) | |
7695 | { | |
7696 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
7697 | catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty); | |
7698 | } | |
7699 | ||
f7f9143b JB |
7700 | /* Create a breakpoint struct for Ada exception catchpoints. */ |
7701 | ||
7702 | static void | |
a6d9a66e UW |
7703 | create_ada_exception_breakpoint (struct gdbarch *gdbarch, |
7704 | struct symtab_and_line sal, | |
f7f9143b JB |
7705 | char *addr_string, |
7706 | char *exp_string, | |
7707 | char *cond_string, | |
7708 | struct expression *cond, | |
7709 | struct breakpoint_ops *ops, | |
7710 | int tempflag, | |
7711 | int from_tty) | |
7712 | { | |
7713 | struct breakpoint *b; | |
7714 | ||
7715 | if (from_tty) | |
7716 | { | |
5af949e3 UW |
7717 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
7718 | if (!loc_gdbarch) | |
7719 | loc_gdbarch = gdbarch; | |
7720 | ||
6c95b8df PA |
7721 | describe_other_breakpoints (loc_gdbarch, |
7722 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
7723 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
7724 | version for exception catchpoints, because two catchpoints | |
7725 | used for different exception names will use the same address. | |
7726 | In this case, a "breakpoint ... also set at..." warning is | |
7727 | unproductive. Besides. the warning phrasing is also a bit | |
7728 | inapropriate, we should use the word catchpoint, and tell | |
7729 | the user what type of catchpoint it is. The above is good | |
7730 | enough for now, though. */ | |
7731 | } | |
7732 | ||
a6d9a66e | 7733 | b = set_raw_breakpoint (gdbarch, sal, bp_breakpoint); |
f7f9143b JB |
7734 | set_breakpoint_count (breakpoint_count + 1); |
7735 | ||
7736 | b->enable_state = bp_enabled; | |
7737 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
7738 | b->number = breakpoint_count; | |
7739 | b->ignore_count = 0; | |
511a6cd4 | 7740 | b->loc->cond = cond; |
f7f9143b JB |
7741 | b->addr_string = addr_string; |
7742 | b->language = language_ada; | |
7743 | b->cond_string = cond_string; | |
7744 | b->exp_string = exp_string; | |
7745 | b->thread = -1; | |
7746 | b->ops = ops; | |
f7f9143b JB |
7747 | |
7748 | mention (b); | |
b60e7edf | 7749 | update_global_location_list (1); |
f7f9143b JB |
7750 | } |
7751 | ||
7752 | /* Implement the "catch exception" command. */ | |
7753 | ||
7754 | static void | |
44feb3ce TT |
7755 | catch_ada_exception_command (char *arg, int from_tty, |
7756 | struct cmd_list_element *command) | |
f7f9143b | 7757 | { |
a6d9a66e | 7758 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 7759 | int tempflag; |
f7f9143b JB |
7760 | struct symtab_and_line sal; |
7761 | enum bptype type; | |
7762 | char *addr_string = NULL; | |
7763 | char *exp_string = NULL; | |
7764 | char *cond_string = NULL; | |
7765 | struct expression *cond = NULL; | |
7766 | struct breakpoint_ops *ops = NULL; | |
7767 | ||
44feb3ce TT |
7768 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
7769 | ||
7770 | if (!arg) | |
7771 | arg = ""; | |
f7f9143b JB |
7772 | sal = ada_decode_exception_location (arg, &addr_string, &exp_string, |
7773 | &cond_string, &cond, &ops); | |
a6d9a66e | 7774 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, exp_string, |
f7f9143b JB |
7775 | cond_string, cond, ops, tempflag, |
7776 | from_tty); | |
7777 | } | |
7778 | ||
a96d9b2e SDJ |
7779 | /* Cleanup function for a syscall filter list. */ |
7780 | static void | |
7781 | clean_up_filters (void *arg) | |
7782 | { | |
7783 | VEC(int) *iter = *(VEC(int) **) arg; | |
7784 | VEC_free (int, iter); | |
7785 | } | |
7786 | ||
7787 | /* Splits the argument using space as delimiter. Returns an xmalloc'd | |
7788 | filter list, or NULL if no filtering is required. */ | |
7789 | static VEC(int) * | |
7790 | catch_syscall_split_args (char *arg) | |
7791 | { | |
7792 | VEC(int) *result = NULL; | |
7793 | struct cleanup *cleanup = make_cleanup (clean_up_filters, &result); | |
7794 | ||
7795 | while (*arg != '\0') | |
7796 | { | |
7797 | int i, syscall_number; | |
7798 | char *endptr; | |
7799 | char cur_name[128]; | |
7800 | struct syscall s; | |
7801 | ||
7802 | /* Skip whitespace. */ | |
7803 | while (isspace (*arg)) | |
7804 | arg++; | |
7805 | ||
7806 | for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) | |
7807 | cur_name[i] = arg[i]; | |
7808 | cur_name[i] = '\0'; | |
7809 | arg += i; | |
7810 | ||
7811 | /* Check if the user provided a syscall name or a number. */ | |
7812 | syscall_number = (int) strtol (cur_name, &endptr, 0); | |
7813 | if (*endptr == '\0') | |
bccd0dd2 | 7814 | get_syscall_by_number (syscall_number, &s); |
a96d9b2e SDJ |
7815 | else |
7816 | { | |
7817 | /* We have a name. Let's check if it's valid and convert it | |
7818 | to a number. */ | |
7819 | get_syscall_by_name (cur_name, &s); | |
7820 | ||
7821 | if (s.number == UNKNOWN_SYSCALL) | |
7822 | /* Here we have to issue an error instead of a warning, because | |
7823 | GDB cannot do anything useful if there's no syscall number to | |
7824 | be caught. */ | |
7825 | error (_("Unknown syscall name '%s'."), cur_name); | |
7826 | } | |
7827 | ||
7828 | /* Ok, it's valid. */ | |
7829 | VEC_safe_push (int, result, s.number); | |
7830 | } | |
7831 | ||
7832 | discard_cleanups (cleanup); | |
7833 | return result; | |
7834 | } | |
7835 | ||
7836 | /* Implement the "catch syscall" command. */ | |
7837 | ||
7838 | static void | |
7839 | catch_syscall_command_1 (char *arg, int from_tty, struct cmd_list_element *command) | |
7840 | { | |
7841 | int tempflag; | |
7842 | VEC(int) *filter; | |
7843 | struct syscall s; | |
7844 | struct gdbarch *gdbarch = get_current_arch (); | |
7845 | ||
7846 | /* Checking if the feature if supported. */ | |
7847 | if (gdbarch_get_syscall_number_p (gdbarch) == 0) | |
7848 | error (_("The feature 'catch syscall' is not supported on \ | |
7849 | this architeture yet.")); | |
7850 | ||
7851 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
7852 | ||
7853 | ep_skip_leading_whitespace (&arg); | |
7854 | ||
7855 | /* We need to do this first "dummy" translation in order | |
7856 | to get the syscall XML file loaded or, most important, | |
7857 | to display a warning to the user if there's no XML file | |
7858 | for his/her architecture. */ | |
7859 | get_syscall_by_number (0, &s); | |
7860 | ||
7861 | /* The allowed syntax is: | |
7862 | catch syscall | |
7863 | catch syscall <name | number> [<name | number> ... <name | number>] | |
7864 | ||
7865 | Let's check if there's a syscall name. */ | |
7866 | ||
7867 | if (arg != NULL) | |
7868 | filter = catch_syscall_split_args (arg); | |
7869 | else | |
7870 | filter = NULL; | |
7871 | ||
7872 | create_syscall_event_catchpoint (tempflag, filter, | |
7873 | &catch_syscall_breakpoint_ops); | |
7874 | } | |
7875 | ||
f7f9143b JB |
7876 | /* Implement the "catch assert" command. */ |
7877 | ||
7878 | static void | |
44feb3ce | 7879 | catch_assert_command (char *arg, int from_tty, struct cmd_list_element *command) |
f7f9143b | 7880 | { |
a6d9a66e | 7881 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 7882 | int tempflag; |
f7f9143b JB |
7883 | struct symtab_and_line sal; |
7884 | char *addr_string = NULL; | |
7885 | struct breakpoint_ops *ops = NULL; | |
7886 | ||
44feb3ce TT |
7887 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
7888 | ||
7889 | if (!arg) | |
7890 | arg = ""; | |
f7f9143b | 7891 | sal = ada_decode_assert_location (arg, &addr_string, &ops); |
a6d9a66e UW |
7892 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, NULL, NULL, NULL, |
7893 | ops, tempflag, from_tty); | |
f7f9143b JB |
7894 | } |
7895 | ||
c906108c | 7896 | static void |
fba45db2 | 7897 | catch_command (char *arg, int from_tty) |
c906108c | 7898 | { |
44feb3ce | 7899 | error (_("Catch requires an event name.")); |
c906108c SS |
7900 | } |
7901 | \f | |
7902 | ||
7903 | static void | |
fba45db2 | 7904 | tcatch_command (char *arg, int from_tty) |
c906108c | 7905 | { |
44feb3ce | 7906 | error (_("Catch requires an event name.")); |
c906108c SS |
7907 | } |
7908 | ||
80f8a6eb | 7909 | /* Delete breakpoints by address or line. */ |
c906108c SS |
7910 | |
7911 | static void | |
fba45db2 | 7912 | clear_command (char *arg, int from_tty) |
c906108c | 7913 | { |
d6e956e5 VP |
7914 | struct breakpoint *b; |
7915 | VEC(breakpoint_p) *found = 0; | |
7916 | int ix; | |
c906108c SS |
7917 | int default_match; |
7918 | struct symtabs_and_lines sals; | |
7919 | struct symtab_and_line sal; | |
c906108c SS |
7920 | int i; |
7921 | ||
7922 | if (arg) | |
7923 | { | |
7924 | sals = decode_line_spec (arg, 1); | |
7925 | default_match = 0; | |
7926 | } | |
7927 | else | |
7928 | { | |
c5aa993b | 7929 | sals.sals = (struct symtab_and_line *) |
c906108c | 7930 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 7931 | make_cleanup (xfree, sals.sals); |
fe39c653 | 7932 | init_sal (&sal); /* initialize to zeroes */ |
c906108c SS |
7933 | sal.line = default_breakpoint_line; |
7934 | sal.symtab = default_breakpoint_symtab; | |
7935 | sal.pc = default_breakpoint_address; | |
6c95b8df | 7936 | sal.pspace = default_breakpoint_pspace; |
c906108c | 7937 | if (sal.symtab == 0) |
8a3fe4f8 | 7938 | error (_("No source file specified.")); |
c906108c SS |
7939 | |
7940 | sals.sals[0] = sal; | |
7941 | sals.nelts = 1; | |
7942 | ||
7943 | default_match = 1; | |
7944 | } | |
7945 | ||
ed0616c6 VP |
7946 | /* We don't call resolve_sal_pc here. That's not |
7947 | as bad as it seems, because all existing breakpoints | |
7948 | typically have both file/line and pc set. So, if | |
7949 | clear is given file/line, we can match this to existing | |
7950 | breakpoint without obtaining pc at all. | |
7951 | ||
7952 | We only support clearing given the address explicitly | |
7953 | present in breakpoint table. Say, we've set breakpoint | |
7954 | at file:line. There were several PC values for that file:line, | |
7955 | due to optimization, all in one block. | |
7956 | We've picked one PC value. If "clear" is issued with another | |
7957 | PC corresponding to the same file:line, the breakpoint won't | |
7958 | be cleared. We probably can still clear the breakpoint, but | |
7959 | since the other PC value is never presented to user, user | |
7960 | can only find it by guessing, and it does not seem important | |
7961 | to support that. */ | |
7962 | ||
c906108c | 7963 | /* For each line spec given, delete bps which correspond |
80f8a6eb MS |
7964 | to it. Do it in two passes, solely to preserve the current |
7965 | behavior that from_tty is forced true if we delete more than | |
7966 | one breakpoint. */ | |
c906108c | 7967 | |
80f8a6eb | 7968 | found = NULL; |
c906108c SS |
7969 | for (i = 0; i < sals.nelts; i++) |
7970 | { | |
7971 | /* If exact pc given, clear bpts at that pc. | |
c5aa993b JM |
7972 | If line given (pc == 0), clear all bpts on specified line. |
7973 | If defaulting, clear all bpts on default line | |
c906108c | 7974 | or at default pc. |
c5aa993b JM |
7975 | |
7976 | defaulting sal.pc != 0 tests to do | |
7977 | ||
7978 | 0 1 pc | |
7979 | 1 1 pc _and_ line | |
7980 | 0 0 line | |
7981 | 1 0 <can't happen> */ | |
c906108c SS |
7982 | |
7983 | sal = sals.sals[i]; | |
c906108c | 7984 | |
d6e956e5 VP |
7985 | /* Find all matching breakpoints and add them to |
7986 | 'found'. */ | |
7987 | ALL_BREAKPOINTS (b) | |
c5aa993b | 7988 | { |
0d381245 | 7989 | int match = 0; |
80f8a6eb MS |
7990 | /* Are we going to delete b? */ |
7991 | if (b->type != bp_none | |
7992 | && b->type != bp_watchpoint | |
7993 | && b->type != bp_hardware_watchpoint | |
7994 | && b->type != bp_read_watchpoint | |
0d381245 VP |
7995 | && b->type != bp_access_watchpoint) |
7996 | { | |
7997 | struct bp_location *loc = b->loc; | |
7998 | for (; loc; loc = loc->next) | |
7999 | { | |
6c95b8df PA |
8000 | int pc_match = sal.pc |
8001 | && (loc->pspace == sal.pspace) | |
0d381245 VP |
8002 | && (loc->address == sal.pc) |
8003 | && (!section_is_overlay (loc->section) | |
8004 | || loc->section == sal.section); | |
8005 | int line_match = ((default_match || (0 == sal.pc)) | |
8006 | && b->source_file != NULL | |
8007 | && sal.symtab != NULL | |
6c95b8df | 8008 | && sal.pspace == loc->pspace |
0d381245 VP |
8009 | && strcmp (b->source_file, sal.symtab->filename) == 0 |
8010 | && b->line_number == sal.line); | |
8011 | if (pc_match || line_match) | |
8012 | { | |
8013 | match = 1; | |
8014 | break; | |
8015 | } | |
8016 | } | |
8017 | } | |
8018 | ||
8019 | if (match) | |
d6e956e5 | 8020 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 8021 | } |
80f8a6eb MS |
8022 | } |
8023 | /* Now go thru the 'found' chain and delete them. */ | |
d6e956e5 | 8024 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
8025 | { |
8026 | if (arg) | |
8a3fe4f8 | 8027 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 8028 | else |
8a3fe4f8 | 8029 | error (_("No breakpoint at this line.")); |
80f8a6eb | 8030 | } |
c906108c | 8031 | |
d6e956e5 | 8032 | if (VEC_length(breakpoint_p, found) > 1) |
80f8a6eb MS |
8033 | from_tty = 1; /* Always report if deleted more than one */ |
8034 | if (from_tty) | |
a3f17187 | 8035 | { |
d6e956e5 | 8036 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
8037 | printf_unfiltered (_("Deleted breakpoint ")); |
8038 | else | |
8039 | printf_unfiltered (_("Deleted breakpoints ")); | |
8040 | } | |
80f8a6eb | 8041 | breakpoints_changed (); |
d6e956e5 VP |
8042 | |
8043 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 8044 | { |
c5aa993b | 8045 | if (from_tty) |
d6e956e5 VP |
8046 | printf_unfiltered ("%d ", b->number); |
8047 | delete_breakpoint (b); | |
c906108c | 8048 | } |
80f8a6eb MS |
8049 | if (from_tty) |
8050 | putchar_unfiltered ('\n'); | |
c906108c SS |
8051 | } |
8052 | \f | |
8053 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
8054 | all breakpoints that are marked for deletion, whether hit or not. | |
8055 | This is called after any breakpoint is hit, or after errors. */ | |
8056 | ||
8057 | void | |
fba45db2 | 8058 | breakpoint_auto_delete (bpstat bs) |
c906108c SS |
8059 | { |
8060 | struct breakpoint *b, *temp; | |
8061 | ||
8062 | for (; bs; bs = bs->next) | |
20874c92 VP |
8063 | if (bs->breakpoint_at |
8064 | && bs->breakpoint_at->owner | |
8065 | && bs->breakpoint_at->owner->disposition == disp_del | |
c906108c | 8066 | && bs->stop) |
4f8d1dc6 | 8067 | delete_breakpoint (bs->breakpoint_at->owner); |
c906108c SS |
8068 | |
8069 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b | 8070 | { |
b5de0fa7 | 8071 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
8072 | delete_breakpoint (b); |
8073 | } | |
c906108c SS |
8074 | } |
8075 | ||
876fa593 JK |
8076 | /* A comparison function for bp_location A and B being interfaced to qsort. |
8077 | Sort elements primarily by their ADDRESS (no matter what does | |
8078 | breakpoint_address_is_meaningful say for its OWNER), secondarily by ordering | |
8079 | first bp_permanent OWNERed elements and terciarily just ensuring the array | |
8080 | is sorted stable way despite qsort being an instable algorithm. */ | |
8081 | ||
8082 | static int | |
8083 | bp_location_compare (struct bp_location *a, struct bp_location *b) | |
8084 | { | |
8085 | int a_perm = a->owner->enable_state == bp_permanent; | |
8086 | int b_perm = b->owner->enable_state == bp_permanent; | |
8087 | ||
8088 | if (a->address != b->address) | |
8089 | return (a->address > b->address) - (a->address < b->address); | |
8090 | ||
8091 | /* Sort permanent breakpoints first. */ | |
8092 | if (a_perm != b_perm) | |
8093 | return (a_perm < b_perm) - (a_perm > b_perm); | |
8094 | ||
8095 | /* Make the user-visible order stable across GDB runs. Locations of the same | |
8096 | breakpoint can be sorted in arbitrary order. */ | |
8097 | ||
8098 | if (a->owner->number != b->owner->number) | |
8099 | return (a->owner->number > b->owner->number) | |
8100 | - (a->owner->number < b->owner->number); | |
8101 | ||
8102 | return (a > b) - (a < b); | |
8103 | } | |
8104 | ||
8105 | /* Interface bp_location_compare as the COMPAR parameter of qsort function. */ | |
8106 | ||
8107 | static int | |
8108 | bp_location_compare_for_qsort (const void *ap, const void *bp) | |
8109 | { | |
8110 | struct bp_location *a = *(void **) ap; | |
8111 | struct bp_location *b = *(void **) bp; | |
8112 | ||
8113 | return bp_location_compare (a, b); | |
8114 | } | |
8115 | ||
8116 | /* Set bp_location_placed_address_before_address_max and | |
8117 | bp_location_shadow_len_after_address_max according to the current content of | |
8118 | the bp_location array. */ | |
f7545552 TT |
8119 | |
8120 | static void | |
876fa593 | 8121 | bp_location_target_extensions_update (void) |
f7545552 | 8122 | { |
876fa593 JK |
8123 | struct bp_location *bl, **blp_tmp; |
8124 | ||
8125 | bp_location_placed_address_before_address_max = 0; | |
8126 | bp_location_shadow_len_after_address_max = 0; | |
8127 | ||
8128 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
8129 | { | |
8130 | CORE_ADDR start, end, addr; | |
8131 | ||
8132 | if (!bp_location_has_shadow (bl)) | |
8133 | continue; | |
8134 | ||
8135 | start = bl->target_info.placed_address; | |
8136 | end = start + bl->target_info.shadow_len; | |
8137 | ||
8138 | gdb_assert (bl->address >= start); | |
8139 | addr = bl->address - start; | |
8140 | if (addr > bp_location_placed_address_before_address_max) | |
8141 | bp_location_placed_address_before_address_max = addr; | |
8142 | ||
8143 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
8144 | ||
8145 | gdb_assert (bl->address < end); | |
8146 | addr = end - bl->address; | |
8147 | if (addr > bp_location_shadow_len_after_address_max) | |
8148 | bp_location_shadow_len_after_address_max = addr; | |
8149 | } | |
f7545552 TT |
8150 | } |
8151 | ||
4cd9bd08 | 8152 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
b60e7edf PA |
8153 | into the inferior, only remove already-inserted locations that no |
8154 | longer should be inserted. Functions that delete a breakpoint or | |
8155 | breakpoints should pass false, so that deleting a breakpoint | |
8156 | doesn't have the side effect of inserting the locations of other | |
8157 | breakpoints that are marked not-inserted, but should_be_inserted | |
8158 | returns true on them. | |
8159 | ||
8160 | This behaviour is useful is situations close to tear-down -- e.g., | |
8161 | after an exec, while the target still has execution, but breakpoint | |
8162 | shadows of the previous executable image should *NOT* be restored | |
8163 | to the new image; or before detaching, where the target still has | |
8164 | execution and wants to delete breakpoints from GDB's lists, and all | |
8165 | breakpoints had already been removed from the inferior. */ | |
8166 | ||
0d381245 | 8167 | static void |
b60e7edf | 8168 | update_global_location_list (int should_insert) |
0d381245 | 8169 | { |
74960c60 | 8170 | struct breakpoint *b; |
876fa593 | 8171 | struct bp_location **locp, *loc; |
f7545552 TT |
8172 | struct cleanup *cleanups; |
8173 | ||
876fa593 JK |
8174 | /* The first bp_location being the only one non-DUPLICATE for the current run |
8175 | of the same ADDRESS. */ | |
8176 | struct bp_location *loc_first; | |
8177 | ||
8178 | /* Saved former bp_location array which we compare against the newly built | |
8179 | bp_location from the current state of ALL_BREAKPOINTS. */ | |
8180 | struct bp_location **old_location, **old_locp; | |
8181 | unsigned old_location_count; | |
8182 | ||
8183 | old_location = bp_location; | |
8184 | old_location_count = bp_location_count; | |
8185 | bp_location = NULL; | |
8186 | bp_location_count = 0; | |
8187 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 8188 | |
74960c60 | 8189 | ALL_BREAKPOINTS (b) |
876fa593 JK |
8190 | for (loc = b->loc; loc; loc = loc->next) |
8191 | bp_location_count++; | |
8192 | ||
8193 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); | |
8194 | locp = bp_location; | |
8195 | ALL_BREAKPOINTS (b) | |
8196 | for (loc = b->loc; loc; loc = loc->next) | |
8197 | *locp++ = loc; | |
8198 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
8199 | bp_location_compare_for_qsort); | |
8200 | ||
8201 | bp_location_target_extensions_update (); | |
74960c60 VP |
8202 | |
8203 | /* Identify bp_location instances that are no longer present in the new | |
8204 | list, and therefore should be freed. Note that it's not necessary that | |
8205 | those locations should be removed from inferior -- if there's another | |
8206 | location at the same address (previously marked as duplicate), | |
876fa593 JK |
8207 | we don't need to remove/insert the location. |
8208 | ||
8209 | LOCP is kept in sync with OLD_LOCP, each pointing to the current and | |
8210 | former bp_location array state respectively. */ | |
8211 | ||
8212 | locp = bp_location; | |
8213 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
8214 | old_locp++) | |
74960c60 | 8215 | { |
876fa593 JK |
8216 | struct bp_location *old_loc = *old_locp; |
8217 | ||
8218 | /* Tells if 'old_loc' is found amoung the new locations. If not, we | |
74960c60 | 8219 | have to free it. */ |
876fa593 | 8220 | int found_object; |
20874c92 VP |
8221 | /* Tells if the location should remain inserted in the target. */ |
8222 | int keep_in_target = 0; | |
8223 | int removed = 0; | |
876fa593 JK |
8224 | |
8225 | /* Skip LOCP entries which will definitely never be needed. Stop either | |
8226 | at or being the one matching OLD_LOC. */ | |
8227 | while (locp < bp_location + bp_location_count | |
8228 | && bp_location_compare (*locp, old_loc) < 0) | |
8229 | locp++; | |
8230 | found_object = locp < bp_location + bp_location_count && *locp == old_loc; | |
74960c60 VP |
8231 | |
8232 | /* If this location is no longer present, and inserted, look if there's | |
8233 | maybe a new location at the same address. If so, mark that one | |
8234 | inserted, and don't remove this one. This is needed so that we | |
8235 | don't have a time window where a breakpoint at certain location is not | |
8236 | inserted. */ | |
8237 | ||
876fa593 | 8238 | if (old_loc->inserted) |
0d381245 | 8239 | { |
74960c60 | 8240 | /* If the location is inserted now, we might have to remove it. */ |
74960c60 | 8241 | |
876fa593 | 8242 | if (found_object && should_be_inserted (old_loc)) |
74960c60 VP |
8243 | { |
8244 | /* The location is still present in the location list, and still | |
8245 | should be inserted. Don't do anything. */ | |
20874c92 | 8246 | keep_in_target = 1; |
74960c60 VP |
8247 | } |
8248 | else | |
8249 | { | |
8250 | /* The location is either no longer present, or got disabled. | |
8251 | See if there's another location at the same address, in which | |
8252 | case we don't need to remove this one from the target. */ | |
876fa593 JK |
8253 | |
8254 | if (breakpoint_address_is_meaningful (old_loc->owner)) | |
8255 | { | |
8256 | struct bp_location **loc2p; | |
8257 | ||
8258 | for (loc2p = locp; | |
8259 | loc2p < bp_location + bp_location_count | |
8260 | && breakpoint_address_match ((*loc2p)->pspace->aspace, | |
8261 | (*loc2p)->address, | |
8262 | old_loc->pspace->aspace, | |
8263 | old_loc->address); | |
8264 | loc2p++) | |
8265 | { | |
8266 | struct bp_location *loc2 = *loc2p; | |
8267 | ||
8268 | /* For the sake of should_be_inserted. | |
8269 | Duplicates check below will fix up this later. */ | |
8270 | loc2->duplicate = 0; | |
8271 | if (loc2 != old_loc && should_be_inserted (loc2)) | |
8272 | { | |
8273 | loc2->inserted = 1; | |
8274 | loc2->target_info = old_loc->target_info; | |
8275 | keep_in_target = 1; | |
8276 | break; | |
8277 | } | |
8278 | } | |
8279 | } | |
74960c60 VP |
8280 | } |
8281 | ||
20874c92 VP |
8282 | if (!keep_in_target) |
8283 | { | |
876fa593 | 8284 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 VP |
8285 | { |
8286 | /* This is just about all we can do. We could keep this | |
8287 | location on the global list, and try to remove it next | |
8288 | time, but there's no particular reason why we will | |
8289 | succeed next time. | |
8290 | ||
876fa593 | 8291 | Note that at this point, old_loc->owner is still valid, |
20874c92 VP |
8292 | as delete_breakpoint frees the breakpoint only |
8293 | after calling us. */ | |
8294 | printf_filtered (_("warning: Error removing breakpoint %d\n"), | |
876fa593 | 8295 | old_loc->owner->number); |
20874c92 VP |
8296 | } |
8297 | removed = 1; | |
8298 | } | |
0d381245 | 8299 | } |
74960c60 VP |
8300 | |
8301 | if (!found_object) | |
1c5cfe86 PA |
8302 | { |
8303 | if (removed && non_stop) | |
20874c92 VP |
8304 | { |
8305 | /* This location was removed from the targets. In non-stop mode, | |
8306 | a race condition is possible where we've removed a breakpoint, | |
8307 | but stop events for that breakpoint are already queued and will | |
8308 | arrive later. To suppress spurious SIGTRAPs reported to user, | |
8309 | we keep this breakpoint location for a bit, and will retire it | |
8310 | after we see 3 * thread_count events. | |
1c5cfe86 | 8311 | The theory here is that reporting of events should, |
20874c92 VP |
8312 | "on the average", be fair, so after that many event we'll see |
8313 | events from all threads that have anything of interest, and no | |
1c5cfe86 | 8314 | longer need to keep this breakpoint. This is just a |
20874c92 | 8315 | heuristic, but if it's wrong, we'll report unexpected SIGTRAP, |
1c5cfe86 | 8316 | which is usability issue, but not a correctness problem. */ |
876fa593 JK |
8317 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
8318 | old_loc->owner = NULL; | |
20874c92 | 8319 | |
876fa593 | 8320 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
8321 | } |
8322 | else | |
876fa593 | 8323 | free_bp_location (old_loc); |
20874c92 | 8324 | } |
74960c60 | 8325 | } |
1c5cfe86 | 8326 | |
876fa593 JK |
8327 | /* Rescan breakpoints at the same address and section, |
8328 | marking the first one as "first" and any others as "duplicates". | |
8329 | This is so that the bpt instruction is only inserted once. | |
8330 | If we have a permanent breakpoint at the same place as BPT, make | |
8331 | that one the official one, and the rest as duplicates. Permanent | |
8332 | breakpoints are sorted first for the same address. */ | |
8333 | ||
8334 | loc_first = NULL; | |
8335 | ALL_BP_LOCATIONS (loc, locp) | |
74960c60 | 8336 | { |
876fa593 JK |
8337 | struct breakpoint *b = loc->owner; |
8338 | ||
8339 | if (b->enable_state == bp_disabled | |
8340 | || b->enable_state == bp_call_disabled | |
8341 | || b->enable_state == bp_startup_disabled | |
8342 | || !loc->enabled | |
8343 | || loc->shlib_disabled | |
8344 | || !breakpoint_address_is_meaningful (b)) | |
8345 | continue; | |
8346 | ||
8347 | /* Permanent breakpoint should always be inserted. */ | |
8348 | if (b->enable_state == bp_permanent && ! loc->inserted) | |
8349 | internal_error (__FILE__, __LINE__, | |
8350 | _("allegedly permanent breakpoint is not " | |
8351 | "actually inserted")); | |
8352 | ||
8353 | if (loc_first == NULL | |
8354 | || (overlay_debugging && loc->section != loc_first->section) | |
8355 | || !breakpoint_address_match (loc->pspace->aspace, loc->address, | |
8356 | loc_first->pspace->aspace, | |
8357 | loc_first->address)) | |
8358 | { | |
8359 | loc_first = loc; | |
8360 | loc->duplicate = 0; | |
8361 | continue; | |
8362 | } | |
8363 | ||
8364 | loc->duplicate = 1; | |
8365 | ||
8366 | if (loc_first->owner->enable_state == bp_permanent && loc->inserted | |
8367 | && b->enable_state != bp_permanent) | |
8368 | internal_error (__FILE__, __LINE__, | |
8369 | _("another breakpoint was inserted on top of " | |
8370 | "a permanent breakpoint")); | |
0d381245 | 8371 | } |
74960c60 | 8372 | |
50c71eaf | 8373 | if (breakpoints_always_inserted_mode () && should_insert |
c35b1492 | 8374 | && (have_live_inferiors () |
2567c7d9 | 8375 | || (gdbarch_has_global_breakpoints (target_gdbarch)))) |
74960c60 | 8376 | insert_breakpoint_locations (); |
f7545552 TT |
8377 | |
8378 | do_cleanups (cleanups); | |
74960c60 VP |
8379 | } |
8380 | ||
20874c92 VP |
8381 | void |
8382 | breakpoint_retire_moribund (void) | |
8383 | { | |
8384 | struct bp_location *loc; | |
8385 | int ix; | |
8386 | ||
8387 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
8388 | if (--(loc->events_till_retirement) == 0) | |
8389 | { | |
8390 | free_bp_location (loc); | |
8391 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
8392 | --ix; | |
8393 | } | |
8394 | } | |
8395 | ||
74960c60 | 8396 | static void |
b60e7edf | 8397 | update_global_location_list_nothrow (int inserting) |
74960c60 VP |
8398 | { |
8399 | struct gdb_exception e; | |
8400 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
b60e7edf | 8401 | update_global_location_list (inserting); |
0d381245 VP |
8402 | } |
8403 | ||
a474d7c2 PA |
8404 | /* Clear BPT from a BPS. */ |
8405 | static void | |
8406 | bpstat_remove_breakpoint (bpstat bps, struct breakpoint *bpt) | |
8407 | { | |
8408 | bpstat bs; | |
8409 | for (bs = bps; bs; bs = bs->next) | |
8410 | if (bs->breakpoint_at && bs->breakpoint_at->owner == bpt) | |
8411 | { | |
8412 | bs->breakpoint_at = NULL; | |
8413 | bs->old_val = NULL; | |
8414 | /* bs->commands will be freed later. */ | |
8415 | } | |
8416 | } | |
8417 | ||
8418 | /* Callback for iterate_over_threads. */ | |
8419 | static int | |
8420 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
8421 | { | |
8422 | struct breakpoint *bpt = data; | |
8423 | bpstat_remove_breakpoint (th->stop_bpstat, bpt); | |
8424 | return 0; | |
8425 | } | |
8426 | ||
53a5351d JM |
8427 | /* Delete a breakpoint and clean up all traces of it in the data |
8428 | structures. */ | |
c906108c SS |
8429 | |
8430 | void | |
fba45db2 | 8431 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 8432 | { |
52f0bd74 | 8433 | struct breakpoint *b; |
74960c60 | 8434 | struct bp_location *loc, *next; |
c906108c | 8435 | |
8a3fe4f8 | 8436 | gdb_assert (bpt != NULL); |
c906108c SS |
8437 | |
8438 | /* Has this bp already been deleted? This can happen because multiple | |
8439 | lists can hold pointers to bp's. bpstat lists are especial culprits. | |
8440 | ||
8441 | One example of this happening is a watchpoint's scope bp. When the | |
8442 | scope bp triggers, we notice that the watchpoint is out of scope, and | |
8443 | delete it. We also delete its scope bp. But the scope bp is marked | |
8444 | "auto-deleting", and is already on a bpstat. That bpstat is then | |
8445 | checked for auto-deleting bp's, which are deleted. | |
8446 | ||
8447 | A real solution to this problem might involve reference counts in bp's, | |
8448 | and/or giving them pointers back to their referencing bpstat's, and | |
8449 | teaching delete_breakpoint to only free a bp's storage when no more | |
1272ad14 | 8450 | references were extent. A cheaper bandaid was chosen. */ |
c906108c SS |
8451 | if (bpt->type == bp_none) |
8452 | return; | |
8453 | ||
383f836e | 8454 | observer_notify_breakpoint_deleted (bpt->number); |
c906108c | 8455 | |
c906108c SS |
8456 | if (breakpoint_chain == bpt) |
8457 | breakpoint_chain = bpt->next; | |
8458 | ||
c906108c SS |
8459 | ALL_BREAKPOINTS (b) |
8460 | if (b->next == bpt) | |
c5aa993b JM |
8461 | { |
8462 | b->next = bpt->next; | |
8463 | break; | |
8464 | } | |
c906108c | 8465 | |
c906108c | 8466 | free_command_lines (&bpt->commands); |
c906108c | 8467 | if (bpt->cond_string != NULL) |
b8c9b27d | 8468 | xfree (bpt->cond_string); |
c906108c | 8469 | if (bpt->addr_string != NULL) |
b8c9b27d | 8470 | xfree (bpt->addr_string); |
c906108c | 8471 | if (bpt->exp != NULL) |
b8c9b27d | 8472 | xfree (bpt->exp); |
c906108c | 8473 | if (bpt->exp_string != NULL) |
b8c9b27d | 8474 | xfree (bpt->exp_string); |
c906108c SS |
8475 | if (bpt->val != NULL) |
8476 | value_free (bpt->val); | |
8477 | if (bpt->source_file != NULL) | |
b8c9b27d | 8478 | xfree (bpt->source_file); |
c906108c | 8479 | if (bpt->exec_pathname != NULL) |
b8c9b27d | 8480 | xfree (bpt->exec_pathname); |
a96d9b2e | 8481 | clean_up_filters (&bpt->syscalls_to_be_caught); |
c906108c SS |
8482 | |
8483 | /* Be sure no bpstat's are pointing at it after it's been freed. */ | |
8484 | /* FIXME, how can we find all bpstat's? | |
198757a8 VP |
8485 | We just check stop_bpstat for now. Note that we cannot just |
8486 | remove bpstats pointing at bpt from the stop_bpstat list | |
8487 | entirely, as breakpoint commands are associated with the bpstat; | |
8488 | if we remove it here, then the later call to | |
8489 | bpstat_do_actions (&stop_bpstat); | |
8490 | in event-top.c won't do anything, and temporary breakpoints | |
8491 | with commands won't work. */ | |
a474d7c2 | 8492 | |
a474d7c2 | 8493 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); |
74960c60 VP |
8494 | |
8495 | /* Now that breakpoint is removed from breakpoint | |
8496 | list, update the global location list. This | |
8497 | will remove locations that used to belong to | |
8498 | this breakpoint. Do this before freeing | |
8499 | the breakpoint itself, since remove_breakpoint | |
8500 | looks at location's owner. It might be better | |
8501 | design to have location completely self-contained, | |
8502 | but it's not the case now. */ | |
b60e7edf | 8503 | update_global_location_list (0); |
74960c60 VP |
8504 | |
8505 | ||
c906108c SS |
8506 | /* On the chance that someone will soon try again to delete this same |
8507 | bp, we mark it as deleted before freeing its storage. */ | |
8508 | bpt->type = bp_none; | |
8509 | ||
b8c9b27d | 8510 | xfree (bpt); |
c906108c SS |
8511 | } |
8512 | ||
4d6140d9 AC |
8513 | static void |
8514 | do_delete_breakpoint_cleanup (void *b) | |
8515 | { | |
8516 | delete_breakpoint (b); | |
8517 | } | |
8518 | ||
8519 | struct cleanup * | |
8520 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
8521 | { | |
8522 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
8523 | } | |
8524 | ||
c906108c | 8525 | void |
fba45db2 | 8526 | delete_command (char *arg, int from_tty) |
c906108c SS |
8527 | { |
8528 | struct breakpoint *b, *temp; | |
8529 | ||
ea9365bb TT |
8530 | dont_repeat (); |
8531 | ||
c906108c SS |
8532 | if (arg == 0) |
8533 | { | |
8534 | int breaks_to_delete = 0; | |
8535 | ||
8536 | /* Delete all breakpoints if no argument. | |
c5aa993b JM |
8537 | Do not delete internal or call-dummy breakpoints, these |
8538 | have to be deleted with an explicit breakpoint number argument. */ | |
8539 | ALL_BREAKPOINTS (b) | |
8540 | { | |
059fb39f PM |
8541 | if (b->type != bp_call_dummy |
8542 | && b->type != bp_shlib_event | |
4efc6507 | 8543 | && b->type != bp_jit_event |
059fb39f PM |
8544 | && b->type != bp_thread_event |
8545 | && b->type != bp_overlay_event | |
0fd8e87f | 8546 | && b->type != bp_longjmp_master |
059fb39f | 8547 | && b->number >= 0) |
973d738b DJ |
8548 | { |
8549 | breaks_to_delete = 1; | |
8550 | break; | |
8551 | } | |
c5aa993b | 8552 | } |
c906108c SS |
8553 | |
8554 | /* Ask user only if there are some breakpoints to delete. */ | |
8555 | if (!from_tty | |
e2e0b3e5 | 8556 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 8557 | { |
c5aa993b JM |
8558 | ALL_BREAKPOINTS_SAFE (b, temp) |
8559 | { | |
059fb39f PM |
8560 | if (b->type != bp_call_dummy |
8561 | && b->type != bp_shlib_event | |
8562 | && b->type != bp_thread_event | |
4efc6507 | 8563 | && b->type != bp_jit_event |
059fb39f | 8564 | && b->type != bp_overlay_event |
0fd8e87f | 8565 | && b->type != bp_longjmp_master |
059fb39f | 8566 | && b->number >= 0) |
c5aa993b JM |
8567 | delete_breakpoint (b); |
8568 | } | |
c906108c SS |
8569 | } |
8570 | } | |
8571 | else | |
8572 | map_breakpoint_numbers (arg, delete_breakpoint); | |
8573 | } | |
8574 | ||
0d381245 VP |
8575 | static int |
8576 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 8577 | { |
0d381245 VP |
8578 | for (; loc; loc = loc->next) |
8579 | if (!loc->shlib_disabled) | |
8580 | return 0; | |
8581 | return 1; | |
fe3f5fa8 VP |
8582 | } |
8583 | ||
776592bf DE |
8584 | /* Subroutine of update_breakpoint_locations to simplify it. |
8585 | Return non-zero if multiple fns in list LOC have the same name. | |
8586 | Null names are ignored. */ | |
8587 | ||
8588 | static int | |
8589 | ambiguous_names_p (struct bp_location *loc) | |
8590 | { | |
8591 | struct bp_location *l; | |
8592 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
8593 | (int (*) (const void *, const void *)) streq, | |
8594 | NULL, xcalloc, xfree); | |
8595 | ||
8596 | for (l = loc; l != NULL; l = l->next) | |
8597 | { | |
8598 | const char **slot; | |
8599 | const char *name = l->function_name; | |
8600 | ||
8601 | /* Allow for some names to be NULL, ignore them. */ | |
8602 | if (name == NULL) | |
8603 | continue; | |
8604 | ||
8605 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
8606 | INSERT); | |
8607 | /* NOTE: We can assume slot != NULL here because xcalloc never returns | |
8608 | NULL. */ | |
8609 | if (*slot != NULL) | |
8610 | { | |
8611 | htab_delete (htab); | |
8612 | return 1; | |
8613 | } | |
8614 | *slot = name; | |
8615 | } | |
8616 | ||
8617 | htab_delete (htab); | |
8618 | return 0; | |
8619 | } | |
8620 | ||
fe3f5fa8 | 8621 | static void |
0d381245 VP |
8622 | update_breakpoint_locations (struct breakpoint *b, |
8623 | struct symtabs_and_lines sals) | |
fe3f5fa8 VP |
8624 | { |
8625 | int i; | |
8626 | char *s; | |
0d381245 VP |
8627 | struct bp_location *existing_locations = b->loc; |
8628 | ||
8629 | /* If there's no new locations, and all existing locations | |
8630 | are pending, don't do anything. This optimizes | |
8631 | the common case where all locations are in the same | |
8632 | shared library, that was unloaded. We'd like to | |
8633 | retain the location, so that when the library | |
8634 | is loaded again, we don't loose the enabled/disabled | |
8635 | status of the individual locations. */ | |
8636 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) | |
fe3f5fa8 VP |
8637 | return; |
8638 | ||
fe3f5fa8 VP |
8639 | b->loc = NULL; |
8640 | ||
0d381245 | 8641 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 8642 | { |
0d381245 | 8643 | struct bp_location *new_loc = |
39d61571 | 8644 | add_location_to_breakpoint (b, &(sals.sals[i])); |
fe3f5fa8 | 8645 | |
0d381245 VP |
8646 | /* Reparse conditions, they might contain references to the |
8647 | old symtab. */ | |
8648 | if (b->cond_string != NULL) | |
8649 | { | |
8650 | struct gdb_exception e; | |
fe3f5fa8 | 8651 | |
0d381245 VP |
8652 | s = b->cond_string; |
8653 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
8654 | { | |
8655 | new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), | |
8656 | 0); | |
8657 | } | |
8658 | if (e.reason < 0) | |
8659 | { | |
8660 | warning (_("failed to reevaluate condition for breakpoint %d: %s"), | |
8661 | b->number, e.message); | |
8662 | new_loc->enabled = 0; | |
8663 | } | |
8664 | } | |
fe3f5fa8 | 8665 | |
0d381245 VP |
8666 | if (b->source_file != NULL) |
8667 | xfree (b->source_file); | |
8668 | if (sals.sals[i].symtab == NULL) | |
8669 | b->source_file = NULL; | |
8670 | else | |
1b36a34b | 8671 | b->source_file = xstrdup (sals.sals[i].symtab->filename); |
fe3f5fa8 | 8672 | |
0d381245 VP |
8673 | if (b->line_number == 0) |
8674 | b->line_number = sals.sals[i].line; | |
8675 | } | |
fe3f5fa8 | 8676 | |
514f746b AR |
8677 | /* Update locations of permanent breakpoints. */ |
8678 | if (b->enable_state == bp_permanent) | |
8679 | make_breakpoint_permanent (b); | |
8680 | ||
0d381245 VP |
8681 | /* If possible, carry over 'disable' status from existing breakpoints. */ |
8682 | { | |
8683 | struct bp_location *e = existing_locations; | |
776592bf DE |
8684 | /* If there are multiple breakpoints with the same function name, |
8685 | e.g. for inline functions, comparing function names won't work. | |
8686 | Instead compare pc addresses; this is just a heuristic as things | |
8687 | may have moved, but in practice it gives the correct answer | |
8688 | often enough until a better solution is found. */ | |
8689 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
8690 | ||
0d381245 VP |
8691 | for (; e; e = e->next) |
8692 | { | |
8693 | if (!e->enabled && e->function_name) | |
8694 | { | |
8695 | struct bp_location *l = b->loc; | |
776592bf DE |
8696 | if (have_ambiguous_names) |
8697 | { | |
8698 | for (; l; l = l->next) | |
6c95b8df PA |
8699 | if (breakpoint_address_match (e->pspace->aspace, e->address, |
8700 | l->pspace->aspace, l->address)) | |
776592bf DE |
8701 | { |
8702 | l->enabled = 0; | |
8703 | break; | |
8704 | } | |
8705 | } | |
8706 | else | |
8707 | { | |
8708 | for (; l; l = l->next) | |
8709 | if (l->function_name | |
8710 | && strcmp (e->function_name, l->function_name) == 0) | |
8711 | { | |
8712 | l->enabled = 0; | |
8713 | break; | |
8714 | } | |
8715 | } | |
0d381245 VP |
8716 | } |
8717 | } | |
8718 | } | |
fe3f5fa8 | 8719 | |
b60e7edf | 8720 | update_global_location_list (1); |
fe3f5fa8 VP |
8721 | } |
8722 | ||
8723 | ||
c906108c SS |
8724 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
8725 | The value we return ends up being the return value from catch_errors. | |
8726 | Unused in this case. */ | |
8727 | ||
8728 | static int | |
4efb68b1 | 8729 | breakpoint_re_set_one (void *bint) |
c906108c | 8730 | { |
53a5351d JM |
8731 | /* get past catch_errs */ |
8732 | struct breakpoint *b = (struct breakpoint *) bint; | |
c906108c SS |
8733 | struct value *mark; |
8734 | int i; | |
fe3f5fa8 VP |
8735 | int not_found = 0; |
8736 | int *not_found_ptr = ¬_found; | |
6c95b8df PA |
8737 | struct symtabs_and_lines sals = {0}; |
8738 | struct symtabs_and_lines expanded = {0}; | |
c906108c | 8739 | char *s; |
b5de0fa7 | 8740 | enum enable_state save_enable; |
fe3f5fa8 | 8741 | struct gdb_exception e; |
6c95b8df | 8742 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
c906108c SS |
8743 | |
8744 | switch (b->type) | |
8745 | { | |
8746 | case bp_none: | |
8a3fe4f8 | 8747 | warning (_("attempted to reset apparently deleted breakpoint #%d?"), |
53a5351d | 8748 | b->number); |
c906108c SS |
8749 | return 0; |
8750 | case bp_breakpoint: | |
8751 | case bp_hardware_breakpoint: | |
1042e4c0 | 8752 | case bp_tracepoint: |
8bea4e01 UW |
8753 | /* Do not attempt to re-set breakpoints disabled during startup. */ |
8754 | if (b->enable_state == bp_startup_disabled) | |
8755 | return 0; | |
8756 | ||
c906108c SS |
8757 | if (b->addr_string == NULL) |
8758 | { | |
8759 | /* Anything without a string can't be re-set. */ | |
8760 | delete_breakpoint (b); | |
8761 | return 0; | |
8762 | } | |
c906108c SS |
8763 | |
8764 | set_language (b->language); | |
8765 | input_radix = b->input_radix; | |
8766 | s = b->addr_string; | |
6c95b8df PA |
8767 | |
8768 | save_current_space_and_thread (); | |
8769 | switch_to_program_space_and_thread (b->pspace); | |
8770 | ||
fe3f5fa8 | 8771 | TRY_CATCH (e, RETURN_MASK_ERROR) |
c906108c | 8772 | { |
fe3f5fa8 VP |
8773 | sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL, |
8774 | not_found_ptr); | |
8775 | } | |
8776 | if (e.reason < 0) | |
8777 | { | |
8778 | int not_found_and_ok = 0; | |
8779 | /* For pending breakpoints, it's expected that parsing | |
8780 | will fail until the right shared library is loaded. | |
8781 | User has already told to create pending breakpoints and | |
8782 | don't need extra messages. If breakpoint is in bp_shlib_disabled | |
8783 | state, then user already saw the message about that breakpoint | |
8784 | being disabled, and don't want to see more errors. */ | |
0d381245 VP |
8785 | if (not_found |
8786 | && (b->condition_not_parsed | |
8787 | || (b->loc && b->loc->shlib_disabled) | |
8788 | || b->enable_state == bp_disabled)) | |
fe3f5fa8 VP |
8789 | not_found_and_ok = 1; |
8790 | ||
8791 | if (!not_found_and_ok) | |
c906108c | 8792 | { |
fe3f5fa8 VP |
8793 | /* We surely don't want to warn about the same breakpoint |
8794 | 10 times. One solution, implemented here, is disable | |
8795 | the breakpoint on error. Another solution would be to | |
8796 | have separate 'warning emitted' flag. Since this | |
8797 | happens only when a binary has changed, I don't know | |
8798 | which approach is better. */ | |
8799 | b->enable_state = bp_disabled; | |
8800 | throw_exception (e); | |
c906108c | 8801 | } |
fe3f5fa8 | 8802 | } |
c906108c | 8803 | |
6c95b8df | 8804 | if (!not_found) |
fe3f5fa8 | 8805 | { |
6c95b8df PA |
8806 | gdb_assert (sals.nelts == 1); |
8807 | ||
8808 | resolve_sal_pc (&sals.sals[0]); | |
8809 | if (b->condition_not_parsed && s && s[0]) | |
8810 | { | |
8811 | char *cond_string = 0; | |
8812 | int thread = -1; | |
8813 | int task = 0; | |
8814 | ||
8815 | find_condition_and_thread (s, sals.sals[0].pc, | |
8816 | &cond_string, &thread, &task); | |
8817 | if (cond_string) | |
8818 | b->cond_string = cond_string; | |
8819 | b->thread = thread; | |
8820 | b->task = task; | |
8821 | b->condition_not_parsed = 0; | |
8822 | } | |
8823 | ||
8824 | expanded = expand_line_sal_maybe (sals.sals[0]); | |
fe3f5fa8 | 8825 | } |
6c95b8df PA |
8826 | |
8827 | make_cleanup (xfree, sals.sals); | |
ed0616c6 | 8828 | update_breakpoint_locations (b, expanded); |
c906108c SS |
8829 | break; |
8830 | ||
8831 | case bp_watchpoint: | |
8832 | case bp_hardware_watchpoint: | |
8833 | case bp_read_watchpoint: | |
8834 | case bp_access_watchpoint: | |
0b3de036 VP |
8835 | /* Watchpoint can be either on expression using entirely global variables, |
8836 | or it can be on local variables. | |
8837 | ||
8838 | Watchpoints of the first kind are never auto-deleted, and even persist | |
8839 | across program restarts. Since they can use variables from shared | |
8840 | libraries, we need to reparse expression as libraries are loaded | |
8841 | and unloaded. | |
8842 | ||
8843 | Watchpoints on local variables can also change meaning as result | |
8844 | of solib event. For example, if a watchpoint uses both a local and | |
8845 | a global variables in expression, it's a local watchpoint, but | |
8846 | unloading of a shared library will make the expression invalid. | |
8847 | This is not a very common use case, but we still re-evaluate | |
8848 | expression, to avoid surprises to the user. | |
8849 | ||
8850 | Note that for local watchpoints, we re-evaluate it only if | |
8851 | watchpoints frame id is still valid. If it's not, it means | |
8852 | the watchpoint is out of scope and will be deleted soon. In fact, | |
8853 | I'm not sure we'll ever be called in this case. | |
8854 | ||
8855 | If a local watchpoint's frame id is still valid, then | |
8856 | b->exp_valid_block is likewise valid, and we can safely use it. | |
8857 | ||
8858 | Don't do anything about disabled watchpoints, since they will | |
8859 | be reevaluated again when enabled. */ | |
a5606eee | 8860 | update_watchpoint (b, 1 /* reparse */); |
c906108c | 8861 | break; |
c5aa993b JM |
8862 | /* We needn't really do anything to reset these, since the mask |
8863 | that requests them is unaffected by e.g., new libraries being | |
8864 | loaded. */ | |
ce78b96d | 8865 | case bp_catchpoint: |
c906108c | 8866 | break; |
c5aa993b | 8867 | |
c906108c | 8868 | default: |
a3f17187 | 8869 | printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type); |
c906108c | 8870 | /* fall through */ |
0fd8e87f UW |
8871 | /* Delete overlay event and longjmp master breakpoints; they will be |
8872 | reset later by breakpoint_re_set. */ | |
1900040c | 8873 | case bp_overlay_event: |
0fd8e87f | 8874 | case bp_longjmp_master: |
c906108c SS |
8875 | delete_breakpoint (b); |
8876 | break; | |
8877 | ||
c5aa993b JM |
8878 | /* This breakpoint is special, it's set up when the inferior |
8879 | starts and we really don't want to touch it. */ | |
c906108c SS |
8880 | case bp_shlib_event: |
8881 | ||
c4093a6a JM |
8882 | /* Like bp_shlib_event, this breakpoint type is special. |
8883 | Once it is set up, we do not want to touch it. */ | |
8884 | case bp_thread_event: | |
8885 | ||
c5aa993b JM |
8886 | /* Keep temporary breakpoints, which can be encountered when we step |
8887 | over a dlopen call and SOLIB_ADD is resetting the breakpoints. | |
8888 | Otherwise these should have been blown away via the cleanup chain | |
8889 | or by breakpoint_init_inferior when we rerun the executable. */ | |
c906108c SS |
8890 | case bp_until: |
8891 | case bp_finish: | |
8892 | case bp_watchpoint_scope: | |
8893 | case bp_call_dummy: | |
8894 | case bp_step_resume: | |
611c83ae PA |
8895 | case bp_longjmp: |
8896 | case bp_longjmp_resume: | |
4efc6507 | 8897 | case bp_jit_event: |
c906108c SS |
8898 | break; |
8899 | } | |
8900 | ||
6c95b8df | 8901 | do_cleanups (cleanups); |
c906108c SS |
8902 | return 0; |
8903 | } | |
8904 | ||
69de3c6a | 8905 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 8906 | void |
69de3c6a | 8907 | breakpoint_re_set (void) |
c906108c SS |
8908 | { |
8909 | struct breakpoint *b, *temp; | |
8910 | enum language save_language; | |
8911 | int save_input_radix; | |
6c95b8df | 8912 | struct cleanup *old_chain; |
c5aa993b | 8913 | |
c906108c SS |
8914 | save_language = current_language->la_language; |
8915 | save_input_radix = input_radix; | |
6c95b8df PA |
8916 | old_chain = save_current_program_space (); |
8917 | ||
c906108c | 8918 | ALL_BREAKPOINTS_SAFE (b, temp) |
c5aa993b | 8919 | { |
53a5351d | 8920 | /* Format possible error msg */ |
fe3f5fa8 | 8921 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
8922 | b->number); |
8923 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 8924 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 8925 | do_cleanups (cleanups); |
c5aa993b | 8926 | } |
c906108c SS |
8927 | set_language (save_language); |
8928 | input_radix = save_input_radix; | |
e62c965a | 8929 | |
0756c555 | 8930 | jit_breakpoint_re_set (); |
4efc6507 | 8931 | |
6c95b8df PA |
8932 | do_cleanups (old_chain); |
8933 | ||
69de3c6a | 8934 | create_overlay_event_breakpoint ("_ovly_debug_event"); |
0fd8e87f UW |
8935 | create_longjmp_master_breakpoint ("longjmp"); |
8936 | create_longjmp_master_breakpoint ("_longjmp"); | |
8937 | create_longjmp_master_breakpoint ("siglongjmp"); | |
8938 | create_longjmp_master_breakpoint ("_siglongjmp"); | |
c906108c SS |
8939 | } |
8940 | \f | |
c906108c SS |
8941 | /* Reset the thread number of this breakpoint: |
8942 | ||
8943 | - If the breakpoint is for all threads, leave it as-is. | |
39f77062 | 8944 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 8945 | void |
fba45db2 | 8946 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
8947 | { |
8948 | if (b->thread != -1) | |
8949 | { | |
39f77062 KB |
8950 | if (in_thread_list (inferior_ptid)) |
8951 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
8952 | |
8953 | /* We're being called after following a fork. The new fork is | |
8954 | selected as current, and unless this was a vfork will have a | |
8955 | different program space from the original thread. Reset that | |
8956 | as well. */ | |
8957 | b->loc->pspace = current_program_space; | |
c906108c SS |
8958 | } |
8959 | } | |
8960 | ||
03ac34d5 MS |
8961 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
8962 | If from_tty is nonzero, it prints a message to that effect, | |
8963 | which ends with a period (no newline). */ | |
8964 | ||
c906108c | 8965 | void |
fba45db2 | 8966 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 8967 | { |
52f0bd74 | 8968 | struct breakpoint *b; |
c906108c SS |
8969 | |
8970 | if (count < 0) | |
8971 | count = 0; | |
8972 | ||
8973 | ALL_BREAKPOINTS (b) | |
8974 | if (b->number == bptnum) | |
c5aa993b JM |
8975 | { |
8976 | b->ignore_count = count; | |
221ea385 KS |
8977 | if (from_tty) |
8978 | { | |
8979 | if (count == 0) | |
a3f17187 | 8980 | printf_filtered (_("Will stop next time breakpoint %d is reached."), |
221ea385 KS |
8981 | bptnum); |
8982 | else if (count == 1) | |
a3f17187 | 8983 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
8984 | bptnum); |
8985 | else | |
a3f17187 | 8986 | printf_filtered (_("Will ignore next %d crossings of breakpoint %d."), |
221ea385 KS |
8987 | count, bptnum); |
8988 | } | |
c5aa993b | 8989 | breakpoints_changed (); |
383f836e | 8990 | observer_notify_breakpoint_modified (b->number); |
c5aa993b JM |
8991 | return; |
8992 | } | |
c906108c | 8993 | |
8a3fe4f8 | 8994 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
8995 | } |
8996 | ||
b2175913 MS |
8997 | void |
8998 | make_breakpoint_silent (struct breakpoint *b) | |
8999 | { | |
9000 | /* Silence the breakpoint. */ | |
9001 | b->silent = 1; | |
9002 | } | |
9003 | ||
c906108c SS |
9004 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
9005 | ||
9006 | static void | |
fba45db2 | 9007 | ignore_command (char *args, int from_tty) |
c906108c SS |
9008 | { |
9009 | char *p = args; | |
52f0bd74 | 9010 | int num; |
c906108c SS |
9011 | |
9012 | if (p == 0) | |
e2e0b3e5 | 9013 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 9014 | |
c906108c | 9015 | num = get_number (&p); |
5c44784c | 9016 | if (num == 0) |
8a3fe4f8 | 9017 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 9018 | if (*p == 0) |
8a3fe4f8 | 9019 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
9020 | |
9021 | set_ignore_count (num, | |
9022 | longest_to_int (value_as_long (parse_and_eval (p))), | |
9023 | from_tty); | |
221ea385 KS |
9024 | if (from_tty) |
9025 | printf_filtered ("\n"); | |
c906108c SS |
9026 | } |
9027 | \f | |
9028 | /* Call FUNCTION on each of the breakpoints | |
9029 | whose numbers are given in ARGS. */ | |
9030 | ||
9031 | static void | |
831662b3 | 9032 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *)) |
c906108c | 9033 | { |
52f0bd74 | 9034 | char *p = args; |
c906108c | 9035 | char *p1; |
52f0bd74 AC |
9036 | int num; |
9037 | struct breakpoint *b, *tmp; | |
11cf8741 | 9038 | int match; |
c906108c SS |
9039 | |
9040 | if (p == 0) | |
e2e0b3e5 | 9041 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c SS |
9042 | |
9043 | while (*p) | |
9044 | { | |
11cf8741 | 9045 | match = 0; |
c906108c | 9046 | p1 = p; |
c5aa993b | 9047 | |
5c44784c JM |
9048 | num = get_number_or_range (&p1); |
9049 | if (num == 0) | |
c5aa993b | 9050 | { |
8a3fe4f8 | 9051 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
9052 | } |
9053 | else | |
9054 | { | |
9055 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
9056 | if (b->number == num) | |
9057 | { | |
9058 | struct breakpoint *related_breakpoint = b->related_breakpoint; | |
11cf8741 | 9059 | match = 1; |
5c44784c JM |
9060 | function (b); |
9061 | if (related_breakpoint) | |
9062 | function (related_breakpoint); | |
11cf8741 | 9063 | break; |
5c44784c | 9064 | } |
11cf8741 | 9065 | if (match == 0) |
a3f17187 | 9066 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 9067 | } |
c906108c SS |
9068 | p = p1; |
9069 | } | |
9070 | } | |
9071 | ||
0d381245 VP |
9072 | static struct bp_location * |
9073 | find_location_by_number (char *number) | |
9074 | { | |
9075 | char *dot = strchr (number, '.'); | |
9076 | char *p1; | |
9077 | int bp_num; | |
9078 | int loc_num; | |
9079 | struct breakpoint *b; | |
9080 | struct bp_location *loc; | |
9081 | ||
9082 | *dot = '\0'; | |
9083 | ||
9084 | p1 = number; | |
9085 | bp_num = get_number_or_range (&p1); | |
9086 | if (bp_num == 0) | |
9087 | error (_("Bad breakpoint number '%s'"), number); | |
9088 | ||
9089 | ALL_BREAKPOINTS (b) | |
9090 | if (b->number == bp_num) | |
9091 | { | |
9092 | break; | |
9093 | } | |
9094 | ||
9095 | if (!b || b->number != bp_num) | |
9096 | error (_("Bad breakpoint number '%s'"), number); | |
9097 | ||
9098 | p1 = dot+1; | |
9099 | loc_num = get_number_or_range (&p1); | |
9100 | if (loc_num == 0) | |
9101 | error (_("Bad breakpoint location number '%s'"), number); | |
9102 | ||
9103 | --loc_num; | |
9104 | loc = b->loc; | |
9105 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
9106 | ; | |
9107 | if (!loc) | |
9108 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
9109 | ||
9110 | return loc; | |
9111 | } | |
9112 | ||
9113 | ||
1900040c MS |
9114 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
9115 | If from_tty is nonzero, it prints a message to that effect, | |
9116 | which ends with a period (no newline). */ | |
9117 | ||
c906108c | 9118 | void |
fba45db2 | 9119 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
9120 | { |
9121 | /* Never disable a watchpoint scope breakpoint; we want to | |
9122 | hit them when we leave scope so we can delete both the | |
9123 | watchpoint and its scope breakpoint at that time. */ | |
9124 | if (bpt->type == bp_watchpoint_scope) | |
9125 | return; | |
9126 | ||
c2c6d25f | 9127 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 9128 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
9129 | return; |
9130 | ||
b5de0fa7 | 9131 | bpt->enable_state = bp_disabled; |
c906108c | 9132 | |
b60e7edf | 9133 | update_global_location_list (0); |
c906108c | 9134 | |
383f836e | 9135 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
9136 | } |
9137 | ||
c906108c | 9138 | static void |
fba45db2 | 9139 | disable_command (char *args, int from_tty) |
c906108c | 9140 | { |
52f0bd74 | 9141 | struct breakpoint *bpt; |
c906108c SS |
9142 | if (args == 0) |
9143 | ALL_BREAKPOINTS (bpt) | |
9144 | switch (bpt->type) | |
c5aa993b JM |
9145 | { |
9146 | case bp_none: | |
8a3fe4f8 | 9147 | warning (_("attempted to disable apparently deleted breakpoint #%d?"), |
53a5351d | 9148 | bpt->number); |
c5aa993b JM |
9149 | continue; |
9150 | case bp_breakpoint: | |
1042e4c0 | 9151 | case bp_tracepoint: |
ce78b96d | 9152 | case bp_catchpoint: |
c5aa993b JM |
9153 | case bp_hardware_breakpoint: |
9154 | case bp_watchpoint: | |
9155 | case bp_hardware_watchpoint: | |
9156 | case bp_read_watchpoint: | |
9157 | case bp_access_watchpoint: | |
9158 | disable_breakpoint (bpt); | |
9159 | default: | |
9160 | continue; | |
9161 | } | |
0d381245 VP |
9162 | else if (strchr (args, '.')) |
9163 | { | |
9164 | struct bp_location *loc = find_location_by_number (args); | |
9165 | if (loc) | |
9166 | loc->enabled = 0; | |
b60e7edf | 9167 | update_global_location_list (0); |
0d381245 | 9168 | } |
c906108c SS |
9169 | else |
9170 | map_breakpoint_numbers (args, disable_breakpoint); | |
9171 | } | |
9172 | ||
9173 | static void | |
fba45db2 | 9174 | do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition) |
c906108c | 9175 | { |
c906108c SS |
9176 | int target_resources_ok, other_type_used; |
9177 | struct value *mark; | |
9178 | ||
9179 | if (bpt->type == bp_hardware_breakpoint) | |
9180 | { | |
9181 | int i; | |
c5aa993b | 9182 | i = hw_breakpoint_used_count (); |
53a5351d | 9183 | target_resources_ok = |
d92524f1 | 9184 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 9185 | i + 1, 0); |
c906108c | 9186 | if (target_resources_ok == 0) |
8a3fe4f8 | 9187 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 9188 | else if (target_resources_ok < 0) |
8a3fe4f8 | 9189 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
9190 | } |
9191 | ||
059fb39f PM |
9192 | if (bpt->type == bp_watchpoint |
9193 | || bpt->type == bp_hardware_watchpoint | |
9194 | || bpt->type == bp_read_watchpoint | |
9195 | || bpt->type == bp_access_watchpoint) | |
c906108c | 9196 | { |
dde02812 ES |
9197 | struct gdb_exception e; |
9198 | ||
9199 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 9200 | { |
dde02812 | 9201 | update_watchpoint (bpt, 1 /* reparse */); |
c906108c | 9202 | } |
dde02812 | 9203 | if (e.reason < 0) |
c5aa993b | 9204 | { |
dde02812 ES |
9205 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
9206 | bpt->number); | |
9207 | return; | |
c5aa993b | 9208 | } |
c906108c | 9209 | } |
0101ce28 | 9210 | |
b4c291bb KH |
9211 | if (bpt->enable_state != bp_permanent) |
9212 | bpt->enable_state = bp_enabled; | |
9213 | bpt->disposition = disposition; | |
b60e7edf | 9214 | update_global_location_list (1); |
b4c291bb KH |
9215 | breakpoints_changed (); |
9216 | ||
383f836e | 9217 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
9218 | } |
9219 | ||
fe3f5fa8 | 9220 | |
c906108c | 9221 | void |
fba45db2 | 9222 | enable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
9223 | { |
9224 | do_enable_breakpoint (bpt, bpt->disposition); | |
9225 | } | |
9226 | ||
9227 | /* The enable command enables the specified breakpoints (or all defined | |
9228 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 9229 | in stopping the inferior. */ |
c906108c | 9230 | |
c906108c | 9231 | static void |
fba45db2 | 9232 | enable_command (char *args, int from_tty) |
c906108c | 9233 | { |
52f0bd74 | 9234 | struct breakpoint *bpt; |
c906108c SS |
9235 | if (args == 0) |
9236 | ALL_BREAKPOINTS (bpt) | |
9237 | switch (bpt->type) | |
c5aa993b JM |
9238 | { |
9239 | case bp_none: | |
8a3fe4f8 | 9240 | warning (_("attempted to enable apparently deleted breakpoint #%d?"), |
53a5351d | 9241 | bpt->number); |
c5aa993b JM |
9242 | continue; |
9243 | case bp_breakpoint: | |
1042e4c0 | 9244 | case bp_tracepoint: |
ce78b96d | 9245 | case bp_catchpoint: |
c5aa993b JM |
9246 | case bp_hardware_breakpoint: |
9247 | case bp_watchpoint: | |
9248 | case bp_hardware_watchpoint: | |
9249 | case bp_read_watchpoint: | |
9250 | case bp_access_watchpoint: | |
9251 | enable_breakpoint (bpt); | |
9252 | default: | |
9253 | continue; | |
9254 | } | |
0d381245 VP |
9255 | else if (strchr (args, '.')) |
9256 | { | |
9257 | struct bp_location *loc = find_location_by_number (args); | |
9258 | if (loc) | |
9259 | loc->enabled = 1; | |
b60e7edf | 9260 | update_global_location_list (1); |
0d381245 | 9261 | } |
c906108c SS |
9262 | else |
9263 | map_breakpoint_numbers (args, enable_breakpoint); | |
9264 | } | |
9265 | ||
9266 | static void | |
fba45db2 | 9267 | enable_once_breakpoint (struct breakpoint *bpt) |
c906108c | 9268 | { |
b5de0fa7 | 9269 | do_enable_breakpoint (bpt, disp_disable); |
c906108c SS |
9270 | } |
9271 | ||
c906108c | 9272 | static void |
fba45db2 | 9273 | enable_once_command (char *args, int from_tty) |
c906108c SS |
9274 | { |
9275 | map_breakpoint_numbers (args, enable_once_breakpoint); | |
9276 | } | |
9277 | ||
9278 | static void | |
fba45db2 | 9279 | enable_delete_breakpoint (struct breakpoint *bpt) |
c906108c | 9280 | { |
b5de0fa7 | 9281 | do_enable_breakpoint (bpt, disp_del); |
c906108c SS |
9282 | } |
9283 | ||
c906108c | 9284 | static void |
fba45db2 | 9285 | enable_delete_command (char *args, int from_tty) |
c906108c SS |
9286 | { |
9287 | map_breakpoint_numbers (args, enable_delete_breakpoint); | |
9288 | } | |
9289 | \f | |
fa8d40ab JJ |
9290 | static void |
9291 | set_breakpoint_cmd (char *args, int from_tty) | |
9292 | { | |
9293 | } | |
9294 | ||
9295 | static void | |
9296 | show_breakpoint_cmd (char *args, int from_tty) | |
9297 | { | |
9298 | } | |
9299 | ||
c906108c SS |
9300 | /* Use default_breakpoint_'s, or nothing if they aren't valid. */ |
9301 | ||
9302 | struct symtabs_and_lines | |
fba45db2 | 9303 | decode_line_spec_1 (char *string, int funfirstline) |
c906108c SS |
9304 | { |
9305 | struct symtabs_and_lines sals; | |
9306 | if (string == 0) | |
8a3fe4f8 | 9307 | error (_("Empty line specification.")); |
c906108c SS |
9308 | if (default_breakpoint_valid) |
9309 | sals = decode_line_1 (&string, funfirstline, | |
53a5351d JM |
9310 | default_breakpoint_symtab, |
9311 | default_breakpoint_line, | |
68219205 | 9312 | (char ***) NULL, NULL); |
c906108c SS |
9313 | else |
9314 | sals = decode_line_1 (&string, funfirstline, | |
68219205 | 9315 | (struct symtab *) NULL, 0, (char ***) NULL, NULL); |
c906108c | 9316 | if (*string) |
8a3fe4f8 | 9317 | error (_("Junk at end of line specification: %s"), string); |
c906108c SS |
9318 | return sals; |
9319 | } | |
8181d85f DJ |
9320 | |
9321 | /* Create and insert a raw software breakpoint at PC. Return an | |
9322 | identifier, which should be used to remove the breakpoint later. | |
9323 | In general, places which call this should be using something on the | |
9324 | breakpoint chain instead; this function should be eliminated | |
9325 | someday. */ | |
9326 | ||
9327 | void * | |
6c95b8df PA |
9328 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, |
9329 | struct address_space *aspace, CORE_ADDR pc) | |
8181d85f DJ |
9330 | { |
9331 | struct bp_target_info *bp_tgt; | |
9332 | ||
6c95b8df | 9333 | bp_tgt = XZALLOC (struct bp_target_info); |
8181d85f | 9334 | |
6c95b8df | 9335 | bp_tgt->placed_address_space = aspace; |
8181d85f | 9336 | bp_tgt->placed_address = pc; |
6c95b8df | 9337 | |
a6d9a66e | 9338 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
8181d85f DJ |
9339 | { |
9340 | /* Could not insert the breakpoint. */ | |
9341 | xfree (bp_tgt); | |
9342 | return NULL; | |
9343 | } | |
9344 | ||
9345 | return bp_tgt; | |
9346 | } | |
9347 | ||
9348 | /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */ | |
9349 | ||
9350 | int | |
a6d9a66e | 9351 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
8181d85f DJ |
9352 | { |
9353 | struct bp_target_info *bp_tgt = bp; | |
9354 | int ret; | |
9355 | ||
a6d9a66e | 9356 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
8181d85f DJ |
9357 | xfree (bp_tgt); |
9358 | ||
9359 | return ret; | |
9360 | } | |
9361 | ||
9362 | /* One (or perhaps two) breakpoints used for software single stepping. */ | |
9363 | ||
9364 | static void *single_step_breakpoints[2]; | |
a6d9a66e | 9365 | static struct gdbarch *single_step_gdbarch[2]; |
8181d85f DJ |
9366 | |
9367 | /* Create and insert a breakpoint for software single step. */ | |
9368 | ||
9369 | void | |
6c95b8df PA |
9370 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
9371 | struct address_space *aspace, CORE_ADDR next_pc) | |
8181d85f DJ |
9372 | { |
9373 | void **bpt_p; | |
9374 | ||
9375 | if (single_step_breakpoints[0] == NULL) | |
a6d9a66e UW |
9376 | { |
9377 | bpt_p = &single_step_breakpoints[0]; | |
9378 | single_step_gdbarch[0] = gdbarch; | |
9379 | } | |
8181d85f DJ |
9380 | else |
9381 | { | |
9382 | gdb_assert (single_step_breakpoints[1] == NULL); | |
9383 | bpt_p = &single_step_breakpoints[1]; | |
a6d9a66e | 9384 | single_step_gdbarch[1] = gdbarch; |
8181d85f DJ |
9385 | } |
9386 | ||
9387 | /* NOTE drow/2006-04-11: A future improvement to this function would be | |
9388 | to only create the breakpoints once, and actually put them on the | |
9389 | breakpoint chain. That would let us use set_raw_breakpoint. We could | |
9390 | adjust the addresses each time they were needed. Doing this requires | |
9391 | corresponding changes elsewhere where single step breakpoints are | |
9392 | handled, however. So, for now, we use this. */ | |
9393 | ||
6c95b8df | 9394 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc); |
8181d85f | 9395 | if (*bpt_p == NULL) |
5af949e3 UW |
9396 | error (_("Could not insert single-step breakpoint at %s"), |
9397 | paddress (gdbarch, next_pc)); | |
8181d85f DJ |
9398 | } |
9399 | ||
9400 | /* Remove and delete any breakpoints used for software single step. */ | |
9401 | ||
9402 | void | |
9403 | remove_single_step_breakpoints (void) | |
9404 | { | |
9405 | gdb_assert (single_step_breakpoints[0] != NULL); | |
9406 | ||
9407 | /* See insert_single_step_breakpoint for more about this deprecated | |
9408 | call. */ | |
a6d9a66e UW |
9409 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
9410 | single_step_breakpoints[0]); | |
9411 | single_step_gdbarch[0] = NULL; | |
8181d85f DJ |
9412 | single_step_breakpoints[0] = NULL; |
9413 | ||
9414 | if (single_step_breakpoints[1] != NULL) | |
9415 | { | |
a6d9a66e UW |
9416 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
9417 | single_step_breakpoints[1]); | |
9418 | single_step_gdbarch[1] = NULL; | |
8181d85f DJ |
9419 | single_step_breakpoints[1] = NULL; |
9420 | } | |
9421 | } | |
9422 | ||
1aafd4da UW |
9423 | /* Check whether a software single-step breakpoint is inserted at PC. */ |
9424 | ||
9425 | static int | |
6c95b8df | 9426 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
1aafd4da UW |
9427 | { |
9428 | int i; | |
9429 | ||
9430 | for (i = 0; i < 2; i++) | |
9431 | { | |
9432 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
6c95b8df PA |
9433 | if (bp_tgt |
9434 | && breakpoint_address_match (bp_tgt->placed_address_space, | |
9435 | bp_tgt->placed_address, | |
9436 | aspace, pc)) | |
1aafd4da UW |
9437 | return 1; |
9438 | } | |
9439 | ||
9440 | return 0; | |
9441 | } | |
9442 | ||
a96d9b2e SDJ |
9443 | /* Returns 0 if 'bp' is NOT a syscall catchpoint, |
9444 | non-zero otherwise. */ | |
9445 | static int | |
9446 | is_syscall_catchpoint_enabled (struct breakpoint *bp) | |
9447 | { | |
9448 | if (syscall_catchpoint_p (bp) | |
9449 | && bp->enable_state != bp_disabled | |
9450 | && bp->enable_state != bp_call_disabled) | |
9451 | return 1; | |
9452 | else | |
9453 | return 0; | |
9454 | } | |
9455 | ||
9456 | int | |
9457 | catch_syscall_enabled (void) | |
9458 | { | |
9459 | struct inferior *inf = current_inferior (); | |
9460 | ||
9461 | return inf->total_syscalls_count != 0; | |
9462 | } | |
9463 | ||
9464 | int | |
9465 | catching_syscall_number (int syscall_number) | |
9466 | { | |
9467 | struct breakpoint *bp; | |
9468 | ||
9469 | ALL_BREAKPOINTS (bp) | |
9470 | if (is_syscall_catchpoint_enabled (bp)) | |
9471 | { | |
9472 | if (bp->syscalls_to_be_caught) | |
9473 | { | |
9474 | int i, iter; | |
9475 | for (i = 0; | |
9476 | VEC_iterate (int, bp->syscalls_to_be_caught, i, iter); | |
9477 | i++) | |
9478 | if (syscall_number == iter) | |
9479 | return 1; | |
9480 | } | |
9481 | else | |
9482 | return 1; | |
9483 | } | |
9484 | ||
9485 | return 0; | |
9486 | } | |
9487 | ||
9488 | /* Complete syscall names. Used by "catch syscall". */ | |
9489 | static char ** | |
9490 | catch_syscall_completer (struct cmd_list_element *cmd, | |
9491 | char *text, char *word) | |
9492 | { | |
9493 | const char **list = get_syscall_names (); | |
9494 | return (list == NULL) ? NULL : complete_on_enum (list, text, word); | |
9495 | } | |
9496 | ||
1042e4c0 SS |
9497 | /* Tracepoint-specific operations. */ |
9498 | ||
9499 | /* Set tracepoint count to NUM. */ | |
9500 | static void | |
9501 | set_tracepoint_count (int num) | |
9502 | { | |
9503 | tracepoint_count = num; | |
4fa62494 | 9504 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
9505 | } |
9506 | ||
9507 | void | |
9508 | trace_command (char *arg, int from_tty) | |
9509 | { | |
a6d9a66e UW |
9510 | break_command_really (get_current_arch (), |
9511 | arg, | |
1042e4c0 SS |
9512 | NULL, 0, 1 /* parse arg */, |
9513 | 0 /* tempflag */, 0 /* hardwareflag */, | |
9514 | 1 /* traceflag */, | |
9515 | 0 /* Ignore count */, | |
9516 | pending_break_support, | |
9517 | NULL, | |
9518 | from_tty, | |
9519 | 1 /* enabled */); | |
9520 | set_tracepoint_count (breakpoint_count); | |
9521 | } | |
9522 | ||
9523 | /* Print information on tracepoint number TPNUM_EXP, or all if | |
9524 | omitted. */ | |
9525 | ||
9526 | static void | |
9527 | tracepoints_info (char *tpnum_exp, int from_tty) | |
9528 | { | |
9529 | struct breakpoint *b; | |
9530 | int tps_to_list = 0; | |
9531 | ||
9532 | /* In the no-arguments case, say "No tracepoints" if none found. */ | |
9533 | if (tpnum_exp == 0) | |
9534 | { | |
9535 | ALL_TRACEPOINTS (b) | |
9536 | { | |
9537 | if (b->number >= 0) | |
9538 | { | |
9539 | tps_to_list = 1; | |
9540 | break; | |
9541 | } | |
9542 | } | |
9543 | if (!tps_to_list) | |
9544 | { | |
9545 | ui_out_message (uiout, 0, "No tracepoints.\n"); | |
9546 | return; | |
9547 | } | |
9548 | } | |
9549 | ||
9550 | /* Otherwise be the same as "info break". */ | |
9551 | breakpoints_info (tpnum_exp, from_tty); | |
9552 | } | |
9553 | ||
9554 | /* The 'enable trace' command enables tracepoints. | |
9555 | Not supported by all targets. */ | |
9556 | static void | |
9557 | enable_trace_command (char *args, int from_tty) | |
9558 | { | |
9559 | enable_command (args, from_tty); | |
9560 | } | |
9561 | ||
9562 | /* The 'disable trace' command disables tracepoints. | |
9563 | Not supported by all targets. */ | |
9564 | static void | |
9565 | disable_trace_command (char *args, int from_tty) | |
9566 | { | |
9567 | disable_command (args, from_tty); | |
9568 | } | |
9569 | ||
9570 | /* Remove a tracepoint (or all if no argument) */ | |
9571 | static void | |
9572 | delete_trace_command (char *arg, int from_tty) | |
9573 | { | |
9574 | struct breakpoint *b, *temp; | |
9575 | ||
9576 | dont_repeat (); | |
9577 | ||
9578 | if (arg == 0) | |
9579 | { | |
9580 | int breaks_to_delete = 0; | |
9581 | ||
9582 | /* Delete all breakpoints if no argument. | |
9583 | Do not delete internal or call-dummy breakpoints, these | |
9584 | have to be deleted with an explicit breakpoint number argument. */ | |
9585 | ALL_TRACEPOINTS (b) | |
9586 | { | |
9587 | if (b->number >= 0) | |
9588 | { | |
9589 | breaks_to_delete = 1; | |
9590 | break; | |
9591 | } | |
9592 | } | |
9593 | ||
9594 | /* Ask user only if there are some breakpoints to delete. */ | |
9595 | if (!from_tty | |
9596 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
9597 | { | |
9598 | ALL_BREAKPOINTS_SAFE (b, temp) | |
9599 | { | |
059fb39f PM |
9600 | if (b->type == bp_tracepoint |
9601 | && b->number >= 0) | |
1042e4c0 SS |
9602 | delete_breakpoint (b); |
9603 | } | |
9604 | } | |
9605 | } | |
9606 | else | |
9607 | map_breakpoint_numbers (arg, delete_breakpoint); | |
9608 | } | |
9609 | ||
9610 | /* Set passcount for tracepoint. | |
9611 | ||
9612 | First command argument is passcount, second is tracepoint number. | |
9613 | If tracepoint number omitted, apply to most recently defined. | |
9614 | Also accepts special argument "all". */ | |
9615 | ||
9616 | static void | |
9617 | trace_pass_command (char *args, int from_tty) | |
9618 | { | |
9619 | struct breakpoint *t1 = (struct breakpoint *) -1, *t2; | |
9620 | unsigned int count; | |
9621 | int all = 0; | |
9622 | ||
9623 | if (args == 0 || *args == 0) | |
9624 | error (_("passcount command requires an argument (count + optional TP num)")); | |
9625 | ||
9626 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ | |
9627 | ||
9628 | while (*args && isspace ((int) *args)) | |
9629 | args++; | |
9630 | ||
9631 | if (*args && strncasecmp (args, "all", 3) == 0) | |
9632 | { | |
9633 | args += 3; /* Skip special argument "all". */ | |
9634 | all = 1; | |
9635 | if (*args) | |
9636 | error (_("Junk at end of arguments.")); | |
9637 | } | |
9638 | else | |
9639 | t1 = get_tracepoint_by_number (&args, 1, 1); | |
9640 | ||
9641 | do | |
9642 | { | |
9643 | if (t1) | |
9644 | { | |
9645 | ALL_TRACEPOINTS (t2) | |
9646 | if (t1 == (struct breakpoint *) -1 || t1 == t2) | |
9647 | { | |
9648 | t2->pass_count = count; | |
9649 | observer_notify_tracepoint_modified (t2->number); | |
9650 | if (from_tty) | |
9651 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
9652 | t2->number, count); | |
9653 | } | |
9654 | if (! all && *args) | |
9655 | t1 = get_tracepoint_by_number (&args, 1, 0); | |
9656 | } | |
9657 | } | |
9658 | while (*args); | |
9659 | } | |
9660 | ||
9661 | struct breakpoint * | |
9662 | get_tracepoint (int num) | |
9663 | { | |
9664 | struct breakpoint *t; | |
9665 | ||
9666 | ALL_TRACEPOINTS (t) | |
9667 | if (t->number == num) | |
9668 | return t; | |
9669 | ||
9670 | return NULL; | |
9671 | } | |
9672 | ||
9673 | /* Utility: parse a tracepoint number and look it up in the list. | |
9674 | If MULTI_P is true, there might be a range of tracepoints in ARG. | |
9675 | if OPTIONAL_P is true, then if the argument is missing, the most | |
9676 | recent tracepoint (tracepoint_count) is returned. */ | |
9677 | struct breakpoint * | |
9678 | get_tracepoint_by_number (char **arg, int multi_p, int optional_p) | |
9679 | { | |
9680 | extern int tracepoint_count; | |
9681 | struct breakpoint *t; | |
9682 | int tpnum; | |
9683 | char *instring = arg == NULL ? NULL : *arg; | |
9684 | ||
9685 | if (arg == NULL || *arg == NULL || ! **arg) | |
9686 | { | |
9687 | if (optional_p) | |
9688 | tpnum = tracepoint_count; | |
9689 | else | |
9690 | error_no_arg (_("tracepoint number")); | |
9691 | } | |
9692 | else | |
9693 | tpnum = multi_p ? get_number_or_range (arg) : get_number (arg); | |
9694 | ||
9695 | if (tpnum <= 0) | |
9696 | { | |
9697 | if (instring && *instring) | |
9698 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
9699 | instring); | |
9700 | else | |
9701 | printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n")); | |
9702 | return NULL; | |
9703 | } | |
9704 | ||
9705 | ALL_TRACEPOINTS (t) | |
9706 | if (t->number == tpnum) | |
9707 | { | |
9708 | return t; | |
9709 | } | |
9710 | ||
9711 | /* FIXME: if we are in the middle of a range we don't want to give | |
9712 | a message. The current interface to get_number_or_range doesn't | |
9713 | allow us to discover this. */ | |
9714 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); | |
9715 | return NULL; | |
9716 | } | |
9717 | ||
9718 | /* save-tracepoints command */ | |
9719 | static void | |
9720 | tracepoint_save_command (char *args, int from_tty) | |
9721 | { | |
9722 | struct breakpoint *tp; | |
9723 | int any_tp = 0; | |
9724 | struct action_line *line; | |
9725 | FILE *fp; | |
9726 | char *i1 = " ", *i2 = " "; | |
9727 | char *indent, *actionline, *pathname; | |
9728 | char tmp[40]; | |
9729 | struct cleanup *cleanup; | |
9730 | ||
9731 | if (args == 0 || *args == 0) | |
9732 | error (_("Argument required (file name in which to save tracepoints)")); | |
9733 | ||
9734 | /* See if we have anything to save. */ | |
9735 | ALL_TRACEPOINTS (tp) | |
9736 | { | |
9737 | any_tp = 1; | |
9738 | break; | |
9739 | } | |
9740 | if (!any_tp) | |
9741 | { | |
9742 | warning (_("save-tracepoints: no tracepoints to save.")); | |
9743 | return; | |
9744 | } | |
9745 | ||
9746 | pathname = tilde_expand (args); | |
9747 | cleanup = make_cleanup (xfree, pathname); | |
059fb39f PM |
9748 | fp = fopen (pathname, "w"); |
9749 | if (!fp) | |
1042e4c0 SS |
9750 | error (_("Unable to open file '%s' for saving tracepoints (%s)"), |
9751 | args, safe_strerror (errno)); | |
9752 | make_cleanup_fclose (fp); | |
9753 | ||
9754 | ALL_TRACEPOINTS (tp) | |
9755 | { | |
9756 | if (tp->addr_string) | |
9757 | fprintf (fp, "trace %s\n", tp->addr_string); | |
9758 | else | |
9759 | { | |
9760 | sprintf_vma (tmp, tp->loc->address); | |
9761 | fprintf (fp, "trace *0x%s\n", tmp); | |
9762 | } | |
9763 | ||
9764 | if (tp->pass_count) | |
9765 | fprintf (fp, " passcount %d\n", tp->pass_count); | |
9766 | ||
9767 | if (tp->actions) | |
9768 | { | |
9769 | fprintf (fp, " actions\n"); | |
9770 | indent = i1; | |
9771 | for (line = tp->actions; line; line = line->next) | |
9772 | { | |
9773 | struct cmd_list_element *cmd; | |
9774 | ||
9775 | QUIT; /* allow user to bail out with ^C */ | |
9776 | actionline = line->action; | |
9777 | while (isspace ((int) *actionline)) | |
9778 | actionline++; | |
9779 | ||
9780 | fprintf (fp, "%s%s\n", indent, actionline); | |
9781 | if (*actionline != '#') /* skip for comment lines */ | |
9782 | { | |
9783 | cmd = lookup_cmd (&actionline, cmdlist, "", -1, 1); | |
9784 | if (cmd == 0) | |
9785 | error (_("Bad action list item: %s"), actionline); | |
9786 | if (cmd_cfunc_eq (cmd, while_stepping_pseudocommand)) | |
9787 | indent = i2; | |
9788 | else if (cmd_cfunc_eq (cmd, end_actions_pseudocommand)) | |
9789 | indent = i1; | |
9790 | } | |
9791 | } | |
9792 | } | |
9793 | } | |
9794 | do_cleanups (cleanup); | |
9795 | if (from_tty) | |
9796 | printf_filtered (_("Tracepoints saved to file '%s'.\n"), args); | |
9797 | return; | |
9798 | } | |
9799 | ||
9800 | /* Create a vector of all tracepoints. */ | |
9801 | ||
9802 | VEC(breakpoint_p) * | |
9803 | all_tracepoints () | |
9804 | { | |
9805 | VEC(breakpoint_p) *tp_vec = 0; | |
9806 | struct breakpoint *tp; | |
9807 | ||
9808 | ALL_TRACEPOINTS (tp) | |
9809 | { | |
9810 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
9811 | } | |
9812 | ||
9813 | return tp_vec; | |
9814 | } | |
9815 | ||
c906108c | 9816 | \f |
31e2b00f AS |
9817 | /* This help string is used for the break, hbreak, tbreak and thbreak commands. |
9818 | It is defined as a macro to prevent duplication. | |
9819 | COMMAND should be a string constant containing the name of the command. */ | |
9820 | #define BREAK_ARGS_HELP(command) \ | |
9821 | command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\ | |
9822 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ | |
9823 | If a line number is specified, break at start of code for that line.\n\ | |
9824 | If a function is specified, break at start of code for that function.\n\ | |
9825 | If an address is specified, break at that exact address.\n\ | |
9826 | With no LOCATION, uses current execution address of selected stack frame.\n\ | |
9827 | This is useful for breaking on return to a stack frame.\n\ | |
9828 | \n\ | |
9829 | THREADNUM is the number from \"info threads\".\n\ | |
9830 | CONDITION is a boolean expression.\n\ | |
9831 | \n\ | |
9832 | Multiple breakpoints at one place are permitted, and useful if conditional.\n\ | |
9833 | \n\ | |
9834 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
9835 | ||
44feb3ce TT |
9836 | /* List of subcommands for "catch". */ |
9837 | static struct cmd_list_element *catch_cmdlist; | |
9838 | ||
9839 | /* List of subcommands for "tcatch". */ | |
9840 | static struct cmd_list_element *tcatch_cmdlist; | |
9841 | ||
9842 | /* Like add_cmd, but add the command to both the "catch" and "tcatch" | |
9843 | lists, and pass some additional user data to the command function. */ | |
9844 | static void | |
9845 | add_catch_command (char *name, char *docstring, | |
9846 | void (*sfunc) (char *args, int from_tty, | |
9847 | struct cmd_list_element *command), | |
a96d9b2e SDJ |
9848 | char **(*completer) (struct cmd_list_element *cmd, |
9849 | char *text, char *word), | |
44feb3ce TT |
9850 | void *user_data_catch, |
9851 | void *user_data_tcatch) | |
9852 | { | |
9853 | struct cmd_list_element *command; | |
9854 | ||
9855 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
9856 | &catch_cmdlist); | |
9857 | set_cmd_sfunc (command, sfunc); | |
9858 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 9859 | set_cmd_completer (command, completer); |
44feb3ce TT |
9860 | |
9861 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
9862 | &tcatch_cmdlist); | |
9863 | set_cmd_sfunc (command, sfunc); | |
9864 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 9865 | set_cmd_completer (command, completer); |
44feb3ce TT |
9866 | } |
9867 | ||
6c95b8df PA |
9868 | static void |
9869 | clear_syscall_counts (int pid) | |
9870 | { | |
9871 | struct inferior *inf = find_inferior_pid (pid); | |
9872 | ||
9873 | inf->total_syscalls_count = 0; | |
9874 | inf->any_syscall_count = 0; | |
9875 | VEC_free (int, inf->syscalls_counts); | |
9876 | } | |
9877 | ||
c906108c | 9878 | void |
fba45db2 | 9879 | _initialize_breakpoint (void) |
c906108c | 9880 | { |
fa8d40ab JJ |
9881 | static struct cmd_list_element *breakpoint_set_cmdlist; |
9882 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
c906108c SS |
9883 | struct cmd_list_element *c; |
9884 | ||
84acb35a | 9885 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
6c95b8df | 9886 | observer_attach_inferior_exit (clear_syscall_counts); |
84acb35a | 9887 | |
c906108c SS |
9888 | breakpoint_chain = 0; |
9889 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
9890 | before a breakpoint is set. */ | |
9891 | breakpoint_count = 0; | |
9892 | ||
1042e4c0 SS |
9893 | tracepoint_count = 0; |
9894 | ||
1bedd215 AC |
9895 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
9896 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
9897 | Usage is `ignore N COUNT'.")); | |
c906108c | 9898 | if (xdb_commands) |
c5aa993b | 9899 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 9900 | |
1bedd215 AC |
9901 | add_com ("commands", class_breakpoint, commands_command, _("\ |
9902 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
9903 | Give breakpoint number as argument after \"commands\".\n\ |
9904 | With no argument, the targeted breakpoint is the last one set.\n\ | |
9905 | The commands themselves follow starting on the next line.\n\ | |
9906 | Type a line containing \"end\" to indicate the end of them.\n\ | |
9907 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 9908 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 9909 | |
1bedd215 AC |
9910 | add_com ("condition", class_breakpoint, condition_command, _("\ |
9911 | Specify breakpoint number N to break only if COND is true.\n\ | |
c906108c | 9912 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 9913 | expression to be evaluated whenever breakpoint N is reached.")); |
c906108c | 9914 | |
1bedd215 | 9915 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 9916 | Set a temporary breakpoint.\n\ |
c906108c SS |
9917 | Like \"break\" except the breakpoint is only temporary,\n\ |
9918 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
9919 | by using \"enable delete\" on the breakpoint number.\n\ |
9920 | \n" | |
9921 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 9922 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 9923 | |
1bedd215 | 9924 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
31e2b00f | 9925 | Set a hardware assisted breakpoint.\n\ |
c906108c | 9926 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
9927 | some target hardware may not have this support.\n\ |
9928 | \n" | |
9929 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 9930 | set_cmd_completer (c, location_completer); |
c906108c | 9931 | |
1bedd215 | 9932 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 9933 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 9934 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
9935 | so it will be deleted when hit.\n\ |
9936 | \n" | |
9937 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 9938 | set_cmd_completer (c, location_completer); |
c906108c | 9939 | |
1bedd215 AC |
9940 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
9941 | Enable some breakpoints.\n\ | |
c906108c SS |
9942 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
9943 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
9944 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 9945 | With a subcommand you can enable temporarily."), |
c906108c SS |
9946 | &enablelist, "enable ", 1, &cmdlist); |
9947 | if (xdb_commands) | |
1bedd215 AC |
9948 | add_com ("ab", class_breakpoint, enable_command, _("\ |
9949 | Enable some breakpoints.\n\ | |
c906108c SS |
9950 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
9951 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
9952 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 9953 | With a subcommand you can enable temporarily.")); |
c906108c SS |
9954 | |
9955 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
9956 | ||
1bedd215 AC |
9957 | add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
9958 | Enable some breakpoints.\n\ | |
c906108c SS |
9959 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
9960 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 9961 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 9962 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 9963 | |
1a966eab AC |
9964 | add_cmd ("once", no_class, enable_once_command, _("\ |
9965 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
9966 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
9967 | &enablebreaklist); |
9968 | ||
1a966eab AC |
9969 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
9970 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
9971 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
9972 | &enablebreaklist); |
9973 | ||
1a966eab AC |
9974 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
9975 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
9976 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
9977 | &enablelist); |
9978 | ||
1a966eab AC |
9979 | add_cmd ("once", no_class, enable_once_command, _("\ |
9980 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
9981 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
9982 | &enablelist); |
9983 | ||
1bedd215 AC |
9984 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
9985 | Disable some breakpoints.\n\ | |
c906108c SS |
9986 | Arguments are breakpoint numbers with spaces in between.\n\ |
9987 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 9988 | A disabled breakpoint is not forgotten, but has no effect until reenabled."), |
c906108c SS |
9989 | &disablelist, "disable ", 1, &cmdlist); |
9990 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
9991 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
9992 | if (xdb_commands) | |
1bedd215 AC |
9993 | add_com ("sb", class_breakpoint, disable_command, _("\ |
9994 | Disable some breakpoints.\n\ | |
c906108c SS |
9995 | Arguments are breakpoint numbers with spaces in between.\n\ |
9996 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 9997 | A disabled breakpoint is not forgotten, but has no effect until reenabled.")); |
c906108c | 9998 | |
1a966eab AC |
9999 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
10000 | Disable some breakpoints.\n\ | |
c906108c SS |
10001 | Arguments are breakpoint numbers with spaces in between.\n\ |
10002 | To disable all breakpoints, give no argument.\n\ | |
10003 | A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\ | |
1a966eab | 10004 | This command may be abbreviated \"disable\"."), |
c906108c SS |
10005 | &disablelist); |
10006 | ||
1bedd215 AC |
10007 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
10008 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
10009 | Arguments are breakpoint numbers with spaces in between.\n\ |
10010 | To delete all breakpoints, give no argument.\n\ | |
10011 | \n\ | |
10012 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 10013 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
10014 | &deletelist, "delete ", 1, &cmdlist); |
10015 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 10016 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 10017 | if (xdb_commands) |
1bedd215 AC |
10018 | add_com ("db", class_breakpoint, delete_command, _("\ |
10019 | Delete some breakpoints.\n\ | |
c906108c | 10020 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 10021 | To delete all breakpoints, give no argument.\n")); |
c906108c | 10022 | |
1a966eab AC |
10023 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
10024 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
10025 | Arguments are breakpoint numbers with spaces in between.\n\ |
10026 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 10027 | This command may be abbreviated \"delete\"."), |
c906108c SS |
10028 | &deletelist); |
10029 | ||
1bedd215 AC |
10030 | add_com ("clear", class_breakpoint, clear_command, _("\ |
10031 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
10032 | Argument may be line number, function name, or \"*\" and an address.\n\ |
10033 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
10034 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
10035 | If an address is specified, breakpoints at that address are cleared.\n\ |
10036 | \n\ | |
10037 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
10038 | is executing in.\n\ |
10039 | \n\ | |
1bedd215 | 10040 | See also the \"delete\" command which clears breakpoints by number.")); |
c906108c | 10041 | |
1bedd215 | 10042 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
10043 | Set breakpoint at specified line or function.\n" |
10044 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 10045 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 10046 | |
c906108c SS |
10047 | add_com_alias ("b", "break", class_run, 1); |
10048 | add_com_alias ("br", "break", class_run, 1); | |
10049 | add_com_alias ("bre", "break", class_run, 1); | |
10050 | add_com_alias ("brea", "break", class_run, 1); | |
10051 | ||
7681d515 PM |
10052 | if (xdb_commands) |
10053 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
10054 | |
10055 | if (dbx_commands) | |
10056 | { | |
1bedd215 AC |
10057 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
10058 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
10059 | &stoplist, "stop ", 1, &cmdlist); |
10060 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 10061 | _("Break in function or address."), &stoplist); |
c5aa993b | 10062 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 10063 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
10064 | add_com ("status", class_info, breakpoints_info, _("\ |
10065 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
10066 | The \"Type\" column indicates one of:\n\ |
10067 | \tbreakpoint - normal breakpoint\n\ | |
10068 | \twatchpoint - watchpoint\n\ | |
10069 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
10070 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
10071 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
10072 | address and file/line number respectively.\n\ |
10073 | \n\ | |
10074 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
10075 | are set to the address of the last breakpoint listed unless the command\n\ |
10076 | is prefixed with \"server \".\n\n\ | |
c906108c | 10077 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 10078 | breakpoint set.")); |
c906108c SS |
10079 | } |
10080 | ||
1bedd215 AC |
10081 | add_info ("breakpoints", breakpoints_info, _("\ |
10082 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
10083 | The \"Type\" column indicates one of:\n\ |
10084 | \tbreakpoint - normal breakpoint\n\ | |
10085 | \twatchpoint - watchpoint\n\ | |
10086 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
10087 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
10088 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
10089 | address and file/line number respectively.\n\ |
10090 | \n\ | |
10091 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
10092 | are set to the address of the last breakpoint listed unless the command\n\ |
10093 | is prefixed with \"server \".\n\n\ | |
c906108c | 10094 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 10095 | breakpoint set.")); |
c906108c SS |
10096 | |
10097 | if (xdb_commands) | |
1bedd215 AC |
10098 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
10099 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
10100 | The \"Type\" column indicates one of:\n\ |
10101 | \tbreakpoint - normal breakpoint\n\ | |
10102 | \twatchpoint - watchpoint\n\ | |
10103 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
10104 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
10105 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
10106 | address and file/line number respectively.\n\ |
10107 | \n\ | |
10108 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
10109 | are set to the address of the last breakpoint listed unless the command\n\ |
10110 | is prefixed with \"server \".\n\n\ | |
c906108c | 10111 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 10112 | breakpoint set.")); |
c906108c | 10113 | |
1a966eab AC |
10114 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
10115 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
10116 | The \"Type\" column indicates one of:\n\ |
10117 | \tbreakpoint - normal breakpoint\n\ | |
10118 | \twatchpoint - watchpoint\n\ | |
10119 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
10120 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
10121 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
10122 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
10123 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
10124 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
10125 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
10126 | address and file/line number respectively.\n\ |
10127 | \n\ | |
10128 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
10129 | are set to the address of the last breakpoint listed unless the command\n\ |
10130 | is prefixed with \"server \".\n\n\ | |
c906108c | 10131 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 10132 | breakpoint set."), |
c906108c SS |
10133 | &maintenanceinfolist); |
10134 | ||
44feb3ce TT |
10135 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
10136 | Set catchpoints to catch events."), | |
10137 | &catch_cmdlist, "catch ", | |
10138 | 0/*allow-unknown*/, &cmdlist); | |
10139 | ||
10140 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
10141 | Set temporary catchpoints to catch events."), | |
10142 | &tcatch_cmdlist, "tcatch ", | |
10143 | 0/*allow-unknown*/, &cmdlist); | |
10144 | ||
10145 | /* Add catch and tcatch sub-commands. */ | |
10146 | add_catch_command ("catch", _("\ | |
10147 | Catch an exception, when caught.\n\ | |
10148 | With an argument, catch only exceptions with the given name."), | |
10149 | catch_catch_command, | |
a96d9b2e | 10150 | NULL, |
44feb3ce TT |
10151 | CATCH_PERMANENT, |
10152 | CATCH_TEMPORARY); | |
10153 | add_catch_command ("throw", _("\ | |
10154 | Catch an exception, when thrown.\n\ | |
10155 | With an argument, catch only exceptions with the given name."), | |
10156 | catch_throw_command, | |
a96d9b2e | 10157 | NULL, |
44feb3ce TT |
10158 | CATCH_PERMANENT, |
10159 | CATCH_TEMPORARY); | |
10160 | add_catch_command ("fork", _("Catch calls to fork."), | |
10161 | catch_fork_command_1, | |
a96d9b2e | 10162 | NULL, |
44feb3ce TT |
10163 | (void *) (uintptr_t) catch_fork_permanent, |
10164 | (void *) (uintptr_t) catch_fork_temporary); | |
10165 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
10166 | catch_fork_command_1, | |
a96d9b2e | 10167 | NULL, |
44feb3ce TT |
10168 | (void *) (uintptr_t) catch_vfork_permanent, |
10169 | (void *) (uintptr_t) catch_vfork_temporary); | |
10170 | add_catch_command ("exec", _("Catch calls to exec."), | |
10171 | catch_exec_command_1, | |
a96d9b2e SDJ |
10172 | NULL, |
10173 | CATCH_PERMANENT, | |
10174 | CATCH_TEMPORARY); | |
10175 | add_catch_command ("syscall", _("\ | |
10176 | Catch system calls by their names and/or numbers.\n\ | |
10177 | Arguments say which system calls to catch. If no arguments\n\ | |
10178 | are given, every system call will be caught.\n\ | |
10179 | Arguments, if given, should be one or more system call names\n\ | |
10180 | (if your system supports that), or system call numbers."), | |
10181 | catch_syscall_command_1, | |
10182 | catch_syscall_completer, | |
44feb3ce TT |
10183 | CATCH_PERMANENT, |
10184 | CATCH_TEMPORARY); | |
44feb3ce TT |
10185 | add_catch_command ("exception", _("\ |
10186 | Catch Ada exceptions, when raised.\n\ | |
10187 | With an argument, catch only exceptions with the given name."), | |
10188 | catch_ada_exception_command, | |
a96d9b2e | 10189 | NULL, |
44feb3ce TT |
10190 | CATCH_PERMANENT, |
10191 | CATCH_TEMPORARY); | |
10192 | add_catch_command ("assert", _("\ | |
10193 | Catch failed Ada assertions, when raised.\n\ | |
10194 | With an argument, catch only exceptions with the given name."), | |
10195 | catch_assert_command, | |
a96d9b2e | 10196 | NULL, |
44feb3ce TT |
10197 | CATCH_PERMANENT, |
10198 | CATCH_TEMPORARY); | |
c5aa993b | 10199 | |
1bedd215 AC |
10200 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
10201 | Set a watchpoint for an expression.\n\ | |
c906108c | 10202 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 10203 | an expression changes.")); |
65d12d83 | 10204 | set_cmd_completer (c, expression_completer); |
c906108c | 10205 | |
1bedd215 AC |
10206 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
10207 | Set a read watchpoint for an expression.\n\ | |
c906108c | 10208 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 10209 | an expression is read.")); |
65d12d83 | 10210 | set_cmd_completer (c, expression_completer); |
c906108c | 10211 | |
1bedd215 AC |
10212 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
10213 | Set a watchpoint for an expression.\n\ | |
c906108c | 10214 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 10215 | an expression is either read or written.")); |
65d12d83 | 10216 | set_cmd_completer (c, expression_completer); |
c906108c SS |
10217 | |
10218 | add_info ("watchpoints", breakpoints_info, | |
1bedd215 | 10219 | _("Synonym for ``info breakpoints''.")); |
c906108c SS |
10220 | |
10221 | ||
920d2a44 AC |
10222 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
10223 | respond to changes - contrary to the description. */ | |
85c07804 AC |
10224 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
10225 | &can_use_hw_watchpoints, _("\ | |
10226 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
10227 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
10228 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
10229 | such is available. (However, any hardware watchpoints that were\n\ | |
10230 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
10231 | hardware.)"), |
10232 | NULL, | |
920d2a44 | 10233 | show_can_use_hw_watchpoints, |
85c07804 | 10234 | &setlist, &showlist); |
c906108c SS |
10235 | |
10236 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 10237 | |
1042e4c0 SS |
10238 | /* Tracepoint manipulation commands. */ |
10239 | ||
10240 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
10241 | Set a tracepoint at specified line or function.\n\ | |
10242 | \n" | |
10243 | BREAK_ARGS_HELP ("trace") "\n\ | |
10244 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
10245 | set_cmd_completer (c, location_completer); | |
10246 | ||
10247 | add_com_alias ("tp", "trace", class_alias, 0); | |
10248 | add_com_alias ("tr", "trace", class_alias, 1); | |
10249 | add_com_alias ("tra", "trace", class_alias, 1); | |
10250 | add_com_alias ("trac", "trace", class_alias, 1); | |
10251 | ||
10252 | add_info ("tracepoints", tracepoints_info, _("\ | |
10253 | Status of tracepoints, or tracepoint number NUMBER.\n\ | |
10254 | Convenience variable \"$tpnum\" contains the number of the\n\ | |
10255 | last tracepoint set.")); | |
10256 | ||
10257 | add_info_alias ("tp", "tracepoints", 1); | |
10258 | ||
10259 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
10260 | Delete specified tracepoints.\n\ | |
10261 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
10262 | No argument means delete all tracepoints."), | |
10263 | &deletelist); | |
10264 | ||
10265 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
10266 | Disable specified tracepoints.\n\ | |
10267 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
10268 | No argument means disable all tracepoints."), | |
10269 | &disablelist); | |
10270 | deprecate_cmd (c, "disable"); | |
10271 | ||
10272 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
10273 | Enable specified tracepoints.\n\ | |
10274 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
10275 | No argument means enable all tracepoints."), | |
10276 | &enablelist); | |
10277 | deprecate_cmd (c, "enable"); | |
10278 | ||
10279 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
10280 | Set the passcount for a tracepoint.\n\ | |
10281 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
10282 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
10283 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
10284 | ||
10285 | c = add_com ("save-tracepoints", class_trace, tracepoint_save_command, _("\ | |
10286 | Save current tracepoint definitions as a script.\n\ | |
10287 | Use the 'source' command in another debug session to restore them.")); | |
10288 | set_cmd_completer (c, filename_completer); | |
10289 | ||
1bedd215 | 10290 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
10291 | Breakpoint specific settings\n\ |
10292 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 10293 | pending breakpoint behavior"), |
fa8d40ab JJ |
10294 | &breakpoint_set_cmdlist, "set breakpoint ", |
10295 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 10296 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
10297 | Breakpoint specific settings\n\ |
10298 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 10299 | pending breakpoint behavior"), |
fa8d40ab JJ |
10300 | &breakpoint_show_cmdlist, "show breakpoint ", |
10301 | 0/*allow-unknown*/, &showlist); | |
10302 | ||
7915a72c AC |
10303 | add_setshow_auto_boolean_cmd ("pending", no_class, |
10304 | &pending_break_support, _("\ | |
10305 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
10306 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
10307 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
10308 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
10309 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 10310 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 10311 | NULL, |
920d2a44 | 10312 | show_pending_break_support, |
6e1d7d6c AC |
10313 | &breakpoint_set_cmdlist, |
10314 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
10315 | |
10316 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
10317 | |
10318 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
10319 | &automatic_hardware_breakpoints, _("\ | |
10320 | Set automatic usage of hardware breakpoints."), _("\ | |
10321 | Show automatic usage of hardware breakpoints."), _("\ | |
10322 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
10323 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
10324 | a warning will be emitted for such breakpoints."), | |
10325 | NULL, | |
10326 | show_automatic_hardware_breakpoints, | |
10327 | &breakpoint_set_cmdlist, | |
10328 | &breakpoint_show_cmdlist); | |
74960c60 | 10329 | |
33e5cbd6 PA |
10330 | add_setshow_enum_cmd ("always-inserted", class_support, |
10331 | always_inserted_enums, &always_inserted_mode, _("\ | |
74960c60 VP |
10332 | Set mode for inserting breakpoints."), _("\ |
10333 | Show mode for inserting breakpoints."), _("\ | |
33e5cbd6 PA |
10334 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
10335 | resumed, and removed when execution stops. When this mode is on,\n\ | |
10336 | breakpoints are inserted immediately and removed only when the user\n\ | |
10337 | deletes the breakpoint. When this mode is auto (which is the default),\n\ | |
10338 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ | |
10339 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ | |
10340 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ | |
10341 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), | |
74960c60 VP |
10342 | NULL, |
10343 | &show_always_inserted_mode, | |
10344 | &breakpoint_set_cmdlist, | |
10345 | &breakpoint_show_cmdlist); | |
765dc015 VP |
10346 | |
10347 | automatic_hardware_breakpoints = 1; | |
f3b1572e PA |
10348 | |
10349 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
c906108c | 10350 | } |