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, |
4c38e0a4 | 5 | 2008, 2009, 2010 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_once_command (char *, int); |
c906108c | 83 | |
a14ed312 | 84 | static void disable_command (char *, int); |
c906108c | 85 | |
a14ed312 | 86 | static void enable_command (char *, int); |
c906108c | 87 | |
95a42b64 TT |
88 | static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *, |
89 | void *), | |
90 | void *); | |
c906108c | 91 | |
a14ed312 | 92 | static void ignore_command (char *, int); |
c906108c | 93 | |
4efb68b1 | 94 | static int breakpoint_re_set_one (void *); |
c906108c | 95 | |
a14ed312 | 96 | static void clear_command (char *, int); |
c906108c | 97 | |
a14ed312 | 98 | static void catch_command (char *, int); |
c906108c | 99 | |
a14ed312 | 100 | static void watch_command (char *, int); |
c906108c | 101 | |
a14ed312 | 102 | static int can_use_hardware_watchpoint (struct value *); |
c906108c | 103 | |
98deb0da | 104 | static void break_command_1 (char *, int, int); |
c906108c | 105 | |
a14ed312 | 106 | static void mention (struct breakpoint *); |
c906108c | 107 | |
63c252f8 PM |
108 | /* This function is used in gdbtk sources and thus can not be made static. */ |
109 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, | |
a6d9a66e UW |
110 | struct symtab_and_line, |
111 | enum bptype); | |
c906108c | 112 | |
76897487 KB |
113 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
114 | ||
a6d9a66e UW |
115 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
116 | CORE_ADDR bpaddr, | |
88f7da05 | 117 | enum bptype bptype); |
76897487 | 118 | |
6c95b8df PA |
119 | static void describe_other_breakpoints (struct gdbarch *, |
120 | struct program_space *, CORE_ADDR, | |
5af949e3 | 121 | struct obj_section *, int); |
c906108c | 122 | |
6c95b8df PA |
123 | static int breakpoint_address_match (struct address_space *aspace1, |
124 | CORE_ADDR addr1, | |
125 | struct address_space *aspace2, | |
126 | CORE_ADDR addr2); | |
127 | ||
85d721b8 PA |
128 | static int watchpoint_locations_match (struct bp_location *loc1, |
129 | struct bp_location *loc2); | |
130 | ||
a14ed312 | 131 | static void breakpoints_info (char *, int); |
c906108c | 132 | |
a14ed312 | 133 | static void breakpoint_1 (int, int); |
c906108c | 134 | |
89f9893c | 135 | static bpstat bpstat_alloc (const struct bp_location *, bpstat); |
c906108c | 136 | |
4efb68b1 | 137 | static int breakpoint_cond_eval (void *); |
c906108c | 138 | |
4efb68b1 | 139 | static void cleanup_executing_breakpoints (void *); |
c906108c | 140 | |
a14ed312 | 141 | static void commands_command (char *, int); |
c906108c | 142 | |
a14ed312 | 143 | static void condition_command (char *, int); |
c906108c | 144 | |
a14ed312 | 145 | static int get_number_trailer (char **, int); |
c906108c | 146 | |
c5aa993b JM |
147 | typedef enum |
148 | { | |
149 | mark_inserted, | |
150 | mark_uninserted | |
151 | } | |
152 | insertion_state_t; | |
c906108c | 153 | |
0bde7532 | 154 | static int remove_breakpoint (struct bp_location *, insertion_state_t); |
6c95b8df | 155 | static int remove_breakpoint_1 (struct bp_location *, insertion_state_t); |
c906108c | 156 | |
a14ed312 | 157 | static enum print_stop_action print_it_typical (bpstat); |
e514a9d6 JM |
158 | |
159 | static enum print_stop_action print_bp_stop_message (bpstat bs); | |
c906108c | 160 | |
4efb68b1 | 161 | static int watchpoint_check (void *); |
c906108c | 162 | |
a14ed312 | 163 | static void maintenance_info_breakpoints (char *, int); |
c906108c | 164 | |
a14ed312 | 165 | static int hw_breakpoint_used_count (void); |
c906108c | 166 | |
a14ed312 | 167 | static int hw_watchpoint_used_count (enum bptype, int *); |
c906108c | 168 | |
a14ed312 | 169 | static void hbreak_command (char *, int); |
c906108c | 170 | |
a14ed312 | 171 | static void thbreak_command (char *, int); |
c906108c | 172 | |
a14ed312 | 173 | static void watch_command_1 (char *, int, int); |
c906108c | 174 | |
a14ed312 | 175 | static void rwatch_command (char *, int); |
c906108c | 176 | |
a14ed312 | 177 | static void awatch_command (char *, int); |
c906108c | 178 | |
a14ed312 | 179 | static void do_enable_breakpoint (struct breakpoint *, enum bpdisp); |
c906108c | 180 | |
a14ed312 | 181 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 182 | |
a14ed312 | 183 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 184 | |
a14ed312 | 185 | static void stopat_command (char *arg, int from_tty); |
7a292a7a | 186 | |
a14ed312 | 187 | static char *ep_parse_optional_if_clause (char **arg); |
7a292a7a | 188 | |
d85310f7 MS |
189 | static void catch_exception_command_1 (enum exception_event_kind ex_event, |
190 | char *arg, int tempflag, int from_tty); | |
7a292a7a | 191 | |
a14ed312 | 192 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 193 | |
a14ed312 | 194 | static void ep_skip_leading_whitespace (char **s); |
7a292a7a | 195 | |
6c95b8df PA |
196 | static int single_step_breakpoint_inserted_here_p (struct address_space *, |
197 | CORE_ADDR pc); | |
1aafd4da | 198 | |
fe3f5fa8 VP |
199 | static void free_bp_location (struct bp_location *loc); |
200 | ||
39d61571 | 201 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 202 | |
b60e7edf | 203 | static void update_global_location_list (int); |
a5606eee | 204 | |
b60e7edf | 205 | static void update_global_location_list_nothrow (int); |
74960c60 VP |
206 | |
207 | static int is_hardware_watchpoint (struct breakpoint *bpt); | |
208 | ||
60e1c644 PA |
209 | static int is_watchpoint (struct breakpoint *bpt); |
210 | ||
74960c60 | 211 | static void insert_breakpoint_locations (void); |
a5606eee | 212 | |
a96d9b2e SDJ |
213 | static int syscall_catchpoint_p (struct breakpoint *b); |
214 | ||
1042e4c0 SS |
215 | static void tracepoints_info (char *, int); |
216 | ||
217 | static void delete_trace_command (char *, int); | |
218 | ||
219 | static void enable_trace_command (char *, int); | |
220 | ||
221 | static void disable_trace_command (char *, int); | |
222 | ||
223 | static void trace_pass_command (char *, int); | |
224 | ||
3daf8fe5 | 225 | |
f3b1572e PA |
226 | /* Flag indicating that a command has proceeded the inferior past the |
227 | current breakpoint. */ | |
228 | ||
229 | static int breakpoint_proceeded; | |
230 | ||
2cec12e5 AR |
231 | static const char * |
232 | bpdisp_text (enum bpdisp disp) | |
233 | { | |
234 | /* NOTE: the following values are a part of MI protocol and represent | |
235 | values of 'disp' field returned when inferior stops at a breakpoint. */ | |
236 | static char *bpdisps[] = {"del", "dstp", "dis", "keep"}; | |
237 | return bpdisps[(int) disp]; | |
238 | } | |
c906108c | 239 | |
2cec12e5 | 240 | /* Prototypes for exported functions. */ |
c906108c SS |
241 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
242 | if such is available. */ | |
243 | static int can_use_hw_watchpoints; | |
244 | ||
920d2a44 AC |
245 | static void |
246 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
247 | struct cmd_list_element *c, | |
248 | const char *value) | |
249 | { | |
250 | fprintf_filtered (file, _("\ | |
251 | Debugger's willingness to use watchpoint hardware is %s.\n"), | |
252 | value); | |
253 | } | |
254 | ||
fa8d40ab JJ |
255 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
256 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
257 | for unrecognized breakpoint locations. | |
258 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ | |
259 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
260 | static void |
261 | show_pending_break_support (struct ui_file *file, int from_tty, | |
262 | struct cmd_list_element *c, | |
263 | const char *value) | |
264 | { | |
265 | fprintf_filtered (file, _("\ | |
266 | Debugger's behavior regarding pending breakpoints is %s.\n"), | |
267 | value); | |
268 | } | |
fa8d40ab | 269 | |
765dc015 VP |
270 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
271 | set with "break" but falling in read-only memory. | |
272 | If 0, gdb will warn about such breakpoints, but won't automatically | |
273 | use hardware breakpoints. */ | |
274 | static int automatic_hardware_breakpoints; | |
275 | static void | |
276 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
277 | struct cmd_list_element *c, | |
278 | const char *value) | |
279 | { | |
280 | fprintf_filtered (file, _("\ | |
281 | Automatic usage of hardware breakpoints is %s.\n"), | |
282 | value); | |
283 | } | |
284 | ||
33e5cbd6 PA |
285 | /* If on, gdb will keep breakpoints inserted even as inferior is |
286 | stopped, and immediately insert any new breakpoints. If off, gdb | |
287 | will insert breakpoints into inferior only when resuming it, and | |
288 | will remove breakpoints upon stop. If auto, GDB will behave as ON | |
289 | if in non-stop mode, and as OFF if all-stop mode.*/ | |
290 | ||
291 | static const char always_inserted_auto[] = "auto"; | |
292 | static const char always_inserted_on[] = "on"; | |
293 | static const char always_inserted_off[] = "off"; | |
294 | static const char *always_inserted_enums[] = { | |
295 | always_inserted_auto, | |
296 | always_inserted_off, | |
297 | always_inserted_on, | |
298 | NULL | |
299 | }; | |
300 | static const char *always_inserted_mode = always_inserted_auto; | |
301 | static void | |
74960c60 | 302 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 303 | struct cmd_list_element *c, const char *value) |
74960c60 | 304 | { |
33e5cbd6 PA |
305 | if (always_inserted_mode == always_inserted_auto) |
306 | fprintf_filtered (file, _("\ | |
307 | Always inserted breakpoint mode is %s (currently %s).\n"), | |
308 | value, | |
309 | breakpoints_always_inserted_mode () ? "on" : "off"); | |
310 | else | |
311 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), value); | |
74960c60 VP |
312 | } |
313 | ||
33e5cbd6 PA |
314 | int |
315 | breakpoints_always_inserted_mode (void) | |
316 | { | |
317 | return (always_inserted_mode == always_inserted_on | |
318 | || (always_inserted_mode == always_inserted_auto && non_stop)); | |
319 | } | |
765dc015 | 320 | |
a14ed312 | 321 | void _initialize_breakpoint (void); |
c906108c | 322 | |
c906108c SS |
323 | /* Are we executing breakpoint commands? */ |
324 | static int executing_breakpoint_commands; | |
325 | ||
c02f5703 MS |
326 | /* Are overlay event breakpoints enabled? */ |
327 | static int overlay_events_enabled; | |
328 | ||
c906108c SS |
329 | /* Walk the following statement or block through all breakpoints. |
330 | ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current | |
331 | breakpoint. */ | |
332 | ||
5c44784c | 333 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 334 | |
5c44784c JM |
335 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
336 | for (B = breakpoint_chain; \ | |
337 | B ? (TMP=B->next, 1): 0; \ | |
338 | B = TMP) | |
c906108c | 339 | |
876fa593 JK |
340 | /* Similar iterator for the low-level breakpoints. SAFE variant is not |
341 | provided so update_global_location_list must not be called while executing | |
342 | the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 343 | |
876fa593 JK |
344 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
345 | for (BP_TMP = bp_location; \ | |
346 | BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \ | |
347 | BP_TMP++) | |
7cc221ef | 348 | |
1042e4c0 SS |
349 | /* Iterator for tracepoints only. */ |
350 | ||
351 | #define ALL_TRACEPOINTS(B) \ | |
352 | for (B = breakpoint_chain; B; B = B->next) \ | |
7a697b8d | 353 | if (tracepoint_type (B)) |
1042e4c0 | 354 | |
7cc221ef | 355 | /* Chains of all breakpoints defined. */ |
c906108c SS |
356 | |
357 | struct breakpoint *breakpoint_chain; | |
358 | ||
876fa593 JK |
359 | /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */ |
360 | ||
361 | static struct bp_location **bp_location; | |
362 | ||
363 | /* Number of elements of BP_LOCATION. */ | |
364 | ||
365 | static unsigned bp_location_count; | |
366 | ||
367 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and ADDRESS | |
368 | for the current elements of BP_LOCATION which get a valid result from | |
369 | bp_location_has_shadow. You can use it for roughly limiting the subrange of | |
370 | BP_LOCATION to scan for shadow bytes for an address you need to read. */ | |
371 | ||
372 | static CORE_ADDR bp_location_placed_address_before_address_max; | |
373 | ||
374 | /* Maximum offset plus alignment between | |
375 | bp_target_info.PLACED_ADDRESS + bp_target_info.SHADOW_LEN and ADDRESS for | |
376 | the current elements of BP_LOCATION which get a valid result from | |
377 | bp_location_has_shadow. You can use it for roughly limiting the subrange of | |
378 | BP_LOCATION to scan for shadow bytes for an address you need to read. */ | |
379 | ||
380 | static CORE_ADDR bp_location_shadow_len_after_address_max; | |
7cc221ef | 381 | |
20874c92 | 382 | /* The locations that no longer correspond to any breakpoint, |
876fa593 | 383 | unlinked from bp_location array, but for which a hit |
20874c92 VP |
384 | may still be reported by a target. */ |
385 | VEC(bp_location_p) *moribund_locations = NULL; | |
386 | ||
c906108c SS |
387 | /* Number of last breakpoint made. */ |
388 | ||
95a42b64 TT |
389 | static int breakpoint_count; |
390 | ||
391 | /* If the last command to create a breakpoint created multiple | |
392 | breakpoints, this holds the start and end breakpoint numbers. */ | |
393 | static int multi_start; | |
394 | static int multi_end; | |
395 | /* True if the last breakpoint set was part of a group set with a | |
396 | single command, e.g., "rbreak". */ | |
397 | static int last_was_multi; | |
c906108c | 398 | |
1042e4c0 SS |
399 | /* Number of last tracepoint made. */ |
400 | ||
95a42b64 | 401 | static int tracepoint_count; |
1042e4c0 | 402 | |
468d015d JJ |
403 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
404 | static int | |
405 | breakpoint_enabled (struct breakpoint *b) | |
406 | { | |
0d381245 | 407 | return (b->enable_state == bp_enabled); |
468d015d JJ |
408 | } |
409 | ||
c906108c SS |
410 | /* Set breakpoint count to NUM. */ |
411 | ||
95a42b64 | 412 | static void |
fba45db2 | 413 | set_breakpoint_count (int num) |
c906108c SS |
414 | { |
415 | breakpoint_count = num; | |
95a42b64 | 416 | last_was_multi = 0; |
4fa62494 | 417 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
418 | } |
419 | ||
95a42b64 TT |
420 | /* Called at the start an "rbreak" command to record the first |
421 | breakpoint made. */ | |
422 | void | |
423 | start_rbreak_breakpoints (void) | |
424 | { | |
425 | multi_start = breakpoint_count + 1; | |
426 | } | |
427 | ||
428 | /* Called at the end of an "rbreak" command to record the last | |
429 | breakpoint made. */ | |
430 | void | |
431 | end_rbreak_breakpoints (void) | |
432 | { | |
433 | if (breakpoint_count >= multi_start) | |
434 | { | |
435 | multi_end = breakpoint_count; | |
436 | last_was_multi = 1; | |
437 | } | |
438 | } | |
439 | ||
c906108c SS |
440 | /* Used in run_command to zero the hit count when a new run starts. */ |
441 | ||
442 | void | |
fba45db2 | 443 | clear_breakpoint_hit_counts (void) |
c906108c SS |
444 | { |
445 | struct breakpoint *b; | |
446 | ||
447 | ALL_BREAKPOINTS (b) | |
448 | b->hit_count = 0; | |
449 | } | |
450 | ||
7a697b8d SS |
451 | /* Encapsulate tests for different types of tracepoints. */ |
452 | ||
453 | static int | |
454 | tracepoint_type (const struct breakpoint *b) | |
455 | { | |
456 | return (b->type == bp_tracepoint || b->type == bp_fast_tracepoint); | |
457 | } | |
458 | ||
9add0f1b TT |
459 | /* Allocate a new counted_command_line with reference count of 1. |
460 | The new structure owns COMMANDS. */ | |
461 | ||
462 | static struct counted_command_line * | |
463 | alloc_counted_command_line (struct command_line *commands) | |
464 | { | |
465 | struct counted_command_line *result | |
466 | = xmalloc (sizeof (struct counted_command_line)); | |
467 | result->refc = 1; | |
468 | result->commands = commands; | |
469 | return result; | |
470 | } | |
471 | ||
472 | /* Increment reference count. This does nothing if CMD is NULL. */ | |
473 | ||
474 | static void | |
475 | incref_counted_command_line (struct counted_command_line *cmd) | |
476 | { | |
477 | if (cmd) | |
478 | ++cmd->refc; | |
479 | } | |
480 | ||
481 | /* Decrement reference count. If the reference count reaches 0, | |
482 | destroy the counted_command_line. Sets *CMDP to NULL. This does | |
483 | nothing if *CMDP is NULL. */ | |
484 | ||
485 | static void | |
486 | decref_counted_command_line (struct counted_command_line **cmdp) | |
487 | { | |
488 | if (*cmdp) | |
489 | { | |
490 | if (--(*cmdp)->refc == 0) | |
491 | { | |
492 | free_command_lines (&(*cmdp)->commands); | |
493 | xfree (*cmdp); | |
494 | } | |
495 | *cmdp = NULL; | |
496 | } | |
497 | } | |
498 | ||
499 | /* A cleanup function that calls decref_counted_command_line. */ | |
500 | ||
501 | static void | |
502 | do_cleanup_counted_command_line (void *arg) | |
503 | { | |
504 | decref_counted_command_line (arg); | |
505 | } | |
506 | ||
507 | /* Create a cleanup that calls decref_counted_command_line on the | |
508 | argument. */ | |
509 | ||
510 | static struct cleanup * | |
511 | make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp) | |
512 | { | |
513 | return make_cleanup (do_cleanup_counted_command_line, cmdp); | |
514 | } | |
515 | ||
c906108c SS |
516 | /* Default address, symtab and line to put a breakpoint at |
517 | for "break" command with no arg. | |
518 | if default_breakpoint_valid is zero, the other three are | |
519 | not valid, and "break" with no arg is an error. | |
520 | ||
521 | This set by print_stack_frame, which calls set_default_breakpoint. */ | |
522 | ||
523 | int default_breakpoint_valid; | |
524 | CORE_ADDR default_breakpoint_address; | |
525 | struct symtab *default_breakpoint_symtab; | |
526 | int default_breakpoint_line; | |
6c95b8df PA |
527 | struct program_space *default_breakpoint_pspace; |
528 | ||
c906108c SS |
529 | \f |
530 | /* *PP is a string denoting a breakpoint. Get the number of the breakpoint. | |
531 | Advance *PP after the string and any trailing whitespace. | |
532 | ||
533 | Currently the string can either be a number or "$" followed by the name | |
534 | of a convenience variable. Making it an expression wouldn't work well | |
5c44784c | 535 | for map_breakpoint_numbers (e.g. "4 + 5 + 6"). |
40c03ae8 EZ |
536 | |
537 | If the string is a NULL pointer, that denotes the last breakpoint. | |
5c44784c JM |
538 | |
539 | TRAILER is a character which can be found after the number; most | |
540 | commonly this is `-'. If you don't want a trailer, use \0. */ | |
c906108c | 541 | static int |
fba45db2 | 542 | get_number_trailer (char **pp, int trailer) |
c906108c | 543 | { |
5c44784c | 544 | int retval = 0; /* default */ |
c906108c SS |
545 | char *p = *pp; |
546 | ||
547 | if (p == NULL) | |
548 | /* Empty line means refer to the last breakpoint. */ | |
549 | return breakpoint_count; | |
550 | else if (*p == '$') | |
551 | { | |
552 | /* Make a copy of the name, so we can null-terminate it | |
c5aa993b | 553 | to pass to lookup_internalvar(). */ |
c906108c SS |
554 | char *varname; |
555 | char *start = ++p; | |
4fa62494 | 556 | LONGEST val; |
c906108c SS |
557 | |
558 | while (isalnum (*p) || *p == '_') | |
559 | p++; | |
560 | varname = (char *) alloca (p - start + 1); | |
561 | strncpy (varname, start, p - start); | |
562 | varname[p - start] = '\0'; | |
4fa62494 UW |
563 | if (get_internalvar_integer (lookup_internalvar (varname), &val)) |
564 | retval = (int) val; | |
5c44784c JM |
565 | else |
566 | { | |
a3f17187 | 567 | printf_filtered (_("Convenience variable must have integer value.\n")); |
5c44784c JM |
568 | retval = 0; |
569 | } | |
c906108c SS |
570 | } |
571 | else | |
572 | { | |
573 | if (*p == '-') | |
574 | ++p; | |
575 | while (*p >= '0' && *p <= '9') | |
576 | ++p; | |
577 | if (p == *pp) | |
578 | /* There is no number here. (e.g. "cond a == b"). */ | |
5c44784c JM |
579 | { |
580 | /* Skip non-numeric token */ | |
581 | while (*p && !isspace((int) *p)) | |
582 | ++p; | |
583 | /* Return zero, which caller must interpret as error. */ | |
584 | retval = 0; | |
585 | } | |
586 | else | |
587 | retval = atoi (*pp); | |
588 | } | |
589 | if (!(isspace (*p) || *p == '\0' || *p == trailer)) | |
590 | { | |
591 | /* Trailing junk: return 0 and let caller print error msg. */ | |
592 | while (!(isspace (*p) || *p == '\0' || *p == trailer)) | |
593 | ++p; | |
594 | retval = 0; | |
c906108c | 595 | } |
c906108c SS |
596 | while (isspace (*p)) |
597 | p++; | |
598 | *pp = p; | |
599 | return retval; | |
600 | } | |
5c44784c | 601 | |
11cf8741 | 602 | |
5c44784c JM |
603 | /* Like get_number_trailer, but don't allow a trailer. */ |
604 | int | |
fba45db2 | 605 | get_number (char **pp) |
5c44784c JM |
606 | { |
607 | return get_number_trailer (pp, '\0'); | |
608 | } | |
609 | ||
610 | /* Parse a number or a range. | |
611 | * A number will be of the form handled by get_number. | |
612 | * A range will be of the form <number1> - <number2>, and | |
613 | * will represent all the integers between number1 and number2, | |
614 | * inclusive. | |
615 | * | |
616 | * While processing a range, this fuction is called iteratively; | |
617 | * At each call it will return the next value in the range. | |
618 | * | |
619 | * At the beginning of parsing a range, the char pointer PP will | |
620 | * be advanced past <number1> and left pointing at the '-' token. | |
621 | * Subsequent calls will not advance the pointer until the range | |
622 | * is completed. The call that completes the range will advance | |
623 | * pointer PP past <number2>. | |
624 | */ | |
625 | ||
626 | int | |
fba45db2 | 627 | get_number_or_range (char **pp) |
5c44784c JM |
628 | { |
629 | static int last_retval, end_value; | |
630 | static char *end_ptr; | |
631 | static int in_range = 0; | |
632 | ||
633 | if (**pp != '-') | |
634 | { | |
635 | /* Default case: pp is pointing either to a solo number, | |
636 | or to the first number of a range. */ | |
637 | last_retval = get_number_trailer (pp, '-'); | |
638 | if (**pp == '-') | |
639 | { | |
640 | char **temp; | |
641 | ||
642 | /* This is the start of a range (<number1> - <number2>). | |
643 | Skip the '-', parse and remember the second number, | |
644 | and also remember the end of the final token. */ | |
645 | ||
646 | temp = &end_ptr; | |
647 | end_ptr = *pp + 1; | |
648 | while (isspace ((int) *end_ptr)) | |
649 | end_ptr++; /* skip white space */ | |
650 | end_value = get_number (temp); | |
651 | if (end_value < last_retval) | |
652 | { | |
8a3fe4f8 | 653 | error (_("inverted range")); |
5c44784c JM |
654 | } |
655 | else if (end_value == last_retval) | |
656 | { | |
657 | /* degenerate range (number1 == number2). Advance the | |
658 | token pointer so that the range will be treated as a | |
659 | single number. */ | |
660 | *pp = end_ptr; | |
661 | } | |
662 | else | |
663 | in_range = 1; | |
664 | } | |
665 | } | |
666 | else if (! in_range) | |
8a3fe4f8 | 667 | error (_("negative value")); |
5c44784c JM |
668 | else |
669 | { | |
670 | /* pp points to the '-' that betokens a range. All | |
671 | number-parsing has already been done. Return the next | |
672 | integer value (one greater than the saved previous value). | |
673 | Do not advance the token pointer 'pp' until the end of range | |
674 | is reached. */ | |
675 | ||
676 | if (++last_retval == end_value) | |
677 | { | |
678 | /* End of range reached; advance token pointer. */ | |
679 | *pp = end_ptr; | |
680 | in_range = 0; | |
681 | } | |
682 | } | |
683 | return last_retval; | |
684 | } | |
685 | ||
48cb2d85 VP |
686 | /* Return the breakpoint with the specified number, or NULL |
687 | if the number does not refer to an existing breakpoint. */ | |
688 | ||
689 | struct breakpoint * | |
690 | get_breakpoint (int num) | |
691 | { | |
692 | struct breakpoint *b; | |
693 | ||
694 | ALL_BREAKPOINTS (b) | |
695 | if (b->number == num) | |
696 | return b; | |
697 | ||
698 | return NULL; | |
699 | } | |
5c44784c | 700 | |
c906108c SS |
701 | \f |
702 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ | |
703 | ||
704 | static void | |
fba45db2 | 705 | condition_command (char *arg, int from_tty) |
c906108c | 706 | { |
52f0bd74 | 707 | struct breakpoint *b; |
c906108c | 708 | char *p; |
52f0bd74 | 709 | int bnum; |
c906108c SS |
710 | |
711 | if (arg == 0) | |
e2e0b3e5 | 712 | error_no_arg (_("breakpoint number")); |
c906108c SS |
713 | |
714 | p = arg; | |
715 | bnum = get_number (&p); | |
5c44784c | 716 | if (bnum == 0) |
8a3fe4f8 | 717 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
718 | |
719 | ALL_BREAKPOINTS (b) | |
720 | if (b->number == bnum) | |
2f069f6f JB |
721 | { |
722 | struct bp_location *loc = b->loc; | |
723 | for (; loc; loc = loc->next) | |
724 | { | |
60e1c644 PA |
725 | xfree (loc->cond); |
726 | loc->cond = NULL; | |
2f069f6f | 727 | } |
60e1c644 PA |
728 | xfree (b->cond_string); |
729 | b->cond_string = NULL; | |
730 | xfree (b->cond_exp); | |
731 | b->cond_exp = NULL; | |
c906108c | 732 | |
2f069f6f JB |
733 | if (*p == 0) |
734 | { | |
2f069f6f JB |
735 | if (from_tty) |
736 | printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum); | |
737 | } | |
738 | else | |
739 | { | |
740 | arg = p; | |
741 | /* I don't know if it matters whether this is the string the user | |
742 | typed in or the decompiled expression. */ | |
1b36a34b | 743 | b->cond_string = xstrdup (arg); |
2f069f6f | 744 | b->condition_not_parsed = 0; |
60e1c644 PA |
745 | |
746 | if (is_watchpoint (b)) | |
2f069f6f | 747 | { |
60e1c644 | 748 | innermost_block = NULL; |
2f069f6f | 749 | arg = p; |
60e1c644 | 750 | b->cond_exp = parse_exp_1 (&arg, 0, 0); |
2f069f6f JB |
751 | if (*arg) |
752 | error (_("Junk at end of expression")); | |
60e1c644 PA |
753 | b->cond_exp_valid_block = innermost_block; |
754 | } | |
755 | else | |
756 | { | |
757 | for (loc = b->loc; loc; loc = loc->next) | |
758 | { | |
759 | arg = p; | |
760 | loc->cond = | |
761 | parse_exp_1 (&arg, block_for_pc (loc->address), 0); | |
762 | if (*arg) | |
763 | error (_("Junk at end of expression")); | |
764 | } | |
2f069f6f JB |
765 | } |
766 | } | |
767 | breakpoints_changed (); | |
383f836e | 768 | observer_notify_breakpoint_modified (b->number); |
2f069f6f JB |
769 | return; |
770 | } | |
c906108c | 771 | |
8a3fe4f8 | 772 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
773 | } |
774 | ||
a7bdde9e VP |
775 | /* Check that COMMAND do not contain commands that are suitable |
776 | only for tracepoints and not suitable for ordinary breakpoints. | |
777 | Throw if any such commands is found. | |
778 | */ | |
779 | static void | |
780 | check_no_tracepoint_commands (struct command_line *commands) | |
781 | { | |
782 | struct command_line *c; | |
783 | for (c = commands; c; c = c->next) | |
784 | { | |
785 | int i; | |
786 | ||
787 | if (c->control_type == while_stepping_control) | |
788 | error (_("The 'while-stepping' command can only be used for tracepoints")); | |
789 | ||
790 | for (i = 0; i < c->body_count; ++i) | |
791 | check_no_tracepoint_commands ((c->body_list)[i]); | |
792 | ||
793 | /* Not that command parsing removes leading whitespace and comment | |
794 | lines and also empty lines. So, we only need to check for | |
795 | command directly. */ | |
796 | if (strstr (c->line, "collect ") == c->line) | |
797 | error (_("The 'collect' command can only be used for tracepoints")); | |
798 | ||
51661e93 VP |
799 | if (strstr (c->line, "teval ") == c->line) |
800 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
801 | } |
802 | } | |
803 | ||
804 | int | |
805 | breakpoint_is_tracepoint (const struct breakpoint *b) | |
806 | { | |
807 | switch (b->type) | |
808 | { | |
809 | case bp_tracepoint: | |
810 | case bp_fast_tracepoint: | |
811 | return 1; | |
812 | default: | |
813 | return 0; | |
814 | ||
815 | } | |
816 | } | |
817 | ||
95a42b64 TT |
818 | /* A helper function that validsates that COMMANDS are valid for a |
819 | breakpoint. This function will throw an exception if a problem is | |
820 | found. */ | |
48cb2d85 | 821 | |
95a42b64 TT |
822 | static void |
823 | validate_commands_for_breakpoint (struct breakpoint *b, | |
824 | struct command_line *commands) | |
48cb2d85 | 825 | { |
a7bdde9e VP |
826 | if (breakpoint_is_tracepoint (b)) |
827 | { | |
828 | /* We need to verify that each top-level element of commands | |
829 | is valid for tracepoints, that there's at most one while-stepping | |
830 | element, and that while-stepping's body has valid tracing commands | |
831 | excluding nested while-stepping. */ | |
832 | struct command_line *c; | |
833 | struct command_line *while_stepping = 0; | |
834 | for (c = commands; c; c = c->next) | |
835 | { | |
836 | char *l = c->line; | |
837 | if (c->control_type == while_stepping_control) | |
838 | { | |
839 | if (b->type == bp_fast_tracepoint) | |
840 | error (_("The 'while-stepping' command cannot be used for fast tracepoint")); | |
841 | ||
842 | if (while_stepping) | |
843 | error (_("The 'while-stepping' command can be used only once")); | |
844 | else | |
845 | while_stepping = c; | |
846 | } | |
847 | } | |
848 | if (while_stepping) | |
849 | { | |
850 | struct command_line *c2; | |
851 | ||
852 | gdb_assert (while_stepping->body_count == 1); | |
853 | c2 = while_stepping->body_list[0]; | |
854 | for (; c2; c2 = c2->next) | |
855 | { | |
856 | char *l = c2->line; | |
857 | if (c2->control_type == while_stepping_control) | |
858 | error (_("The 'while-stepping' command cannot be nested")); | |
859 | } | |
860 | } | |
861 | } | |
862 | else | |
863 | { | |
864 | check_no_tracepoint_commands (commands); | |
865 | } | |
95a42b64 TT |
866 | } |
867 | ||
868 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, | |
869 | validate that only allowed commands are included. | |
870 | */ | |
871 | ||
872 | void | |
873 | breakpoint_set_commands (struct breakpoint *b, struct command_line *commands) | |
874 | { | |
875 | validate_commands_for_breakpoint (b, commands); | |
a7bdde9e | 876 | |
9add0f1b TT |
877 | decref_counted_command_line (&b->commands); |
878 | b->commands = alloc_counted_command_line (commands); | |
48cb2d85 VP |
879 | breakpoints_changed (); |
880 | observer_notify_breakpoint_modified (b->number); | |
881 | } | |
882 | ||
95a42b64 TT |
883 | void |
884 | check_tracepoint_command (char *line, void *closure) | |
a7bdde9e VP |
885 | { |
886 | struct breakpoint *b = closure; | |
887 | validate_actionline (&line, b); | |
888 | } | |
889 | ||
95a42b64 TT |
890 | /* A structure used to pass information through |
891 | map_breakpoint_numbers. */ | |
892 | ||
893 | struct commands_info | |
894 | { | |
895 | /* True if the command was typed at a tty. */ | |
896 | int from_tty; | |
897 | /* Non-NULL if the body of the commands are being read from this | |
898 | already-parsed command. */ | |
899 | struct command_line *control; | |
900 | /* The command lines read from the user, or NULL if they have not | |
901 | yet been read. */ | |
902 | struct counted_command_line *cmd; | |
903 | }; | |
904 | ||
905 | /* A callback for map_breakpoint_numbers that sets the commands for | |
906 | commands_command. */ | |
907 | ||
c906108c | 908 | static void |
95a42b64 | 909 | do_map_commands_command (struct breakpoint *b, void *data) |
c906108c | 910 | { |
95a42b64 | 911 | struct commands_info *info = data; |
c906108c | 912 | |
95a42b64 TT |
913 | if (info->cmd == NULL) |
914 | { | |
915 | struct command_line *l; | |
5c44784c | 916 | |
95a42b64 TT |
917 | if (info->control != NULL) |
918 | l = copy_command_lines (info->control->body_list[0]); | |
919 | else | |
c5aa993b | 920 | |
95a42b64 TT |
921 | l = read_command_lines (_("Type commands for all specified breakpoints"), |
922 | info->from_tty, 1, | |
923 | (breakpoint_is_tracepoint (b) | |
924 | ? check_tracepoint_command : 0), | |
925 | b); | |
a7bdde9e | 926 | |
95a42b64 TT |
927 | info->cmd = alloc_counted_command_line (l); |
928 | } | |
929 | ||
930 | /* If a breakpoint was on the list more than once, we don't need to | |
931 | do anything. */ | |
932 | if (b->commands != info->cmd) | |
933 | { | |
934 | validate_commands_for_breakpoint (b, info->cmd->commands); | |
935 | incref_counted_command_line (info->cmd); | |
936 | decref_counted_command_line (&b->commands); | |
937 | b->commands = info->cmd; | |
938 | breakpoints_changed (); | |
939 | observer_notify_breakpoint_modified (b->number); | |
c5aa993b | 940 | } |
95a42b64 TT |
941 | } |
942 | ||
943 | static void | |
944 | commands_command_1 (char *arg, int from_tty, struct command_line *control) | |
945 | { | |
946 | struct cleanup *cleanups; | |
947 | struct commands_info info; | |
948 | ||
949 | info.from_tty = from_tty; | |
950 | info.control = control; | |
951 | info.cmd = NULL; | |
952 | /* If we read command lines from the user, then `info' will hold an | |
953 | extra reference to the commands that we must clean up. */ | |
954 | cleanups = make_cleanup_decref_counted_command_line (&info.cmd); | |
955 | ||
956 | if (arg == NULL || !*arg) | |
957 | { | |
958 | if (last_was_multi) | |
959 | arg = xstrprintf ("%d-%d", multi_start, multi_end); | |
960 | else if (breakpoint_count > 0) | |
961 | arg = xstrprintf ("%d", breakpoint_count); | |
962 | make_cleanup (xfree, arg); | |
963 | } | |
964 | ||
965 | map_breakpoint_numbers (arg, do_map_commands_command, &info); | |
966 | ||
967 | if (info.cmd == NULL) | |
968 | error (_("No breakpoints specified.")); | |
969 | ||
970 | do_cleanups (cleanups); | |
971 | } | |
972 | ||
973 | static void | |
974 | commands_command (char *arg, int from_tty) | |
975 | { | |
976 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 977 | } |
40c03ae8 EZ |
978 | |
979 | /* Like commands_command, but instead of reading the commands from | |
980 | input stream, takes them from an already parsed command structure. | |
981 | ||
982 | This is used by cli-script.c to DTRT with breakpoint commands | |
983 | that are part of if and while bodies. */ | |
984 | enum command_control_type | |
985 | commands_from_control_command (char *arg, struct command_line *cmd) | |
986 | { | |
95a42b64 TT |
987 | commands_command_1 (arg, 0, cmd); |
988 | return simple_control; | |
40c03ae8 | 989 | } |
876fa593 JK |
990 | |
991 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
992 | ||
993 | static int | |
994 | bp_location_has_shadow (struct bp_location *bl) | |
995 | { | |
996 | if (bl->loc_type != bp_loc_software_breakpoint) | |
997 | return 0; | |
998 | if (!bl->inserted) | |
999 | return 0; | |
1000 | if (bl->target_info.shadow_len == 0) | |
1001 | /* bp isn't valid, or doesn't shadow memory. */ | |
1002 | return 0; | |
1003 | return 1; | |
1004 | } | |
1005 | ||
8defab1a | 1006 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1007 | by replacing any memory breakpoints with their shadowed contents. |
1008 | ||
1009 | The range of shadowed area by each bp_location is: | |
1010 | b->address - bp_location_placed_address_before_address_max | |
1011 | up to b->address + bp_location_shadow_len_after_address_max | |
1012 | The range we were requested to resolve shadows for is: | |
1013 | memaddr ... memaddr + len | |
1014 | Thus the safe cutoff boundaries for performance optimization are | |
1015 | memaddr + len <= b->address - bp_location_placed_address_before_address_max | |
1016 | and: | |
1017 | b->address + bp_location_shadow_len_after_address_max <= memaddr */ | |
c906108c | 1018 | |
8defab1a DJ |
1019 | void |
1020 | breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len) | |
c906108c | 1021 | { |
876fa593 JK |
1022 | /* Left boundary, right boundary and median element of our binary search. */ |
1023 | unsigned bc_l, bc_r, bc; | |
1024 | ||
1025 | /* Find BC_L which is a leftmost element which may affect BUF content. It is | |
1026 | safe to report lower value but a failure to report higher one. */ | |
1027 | ||
1028 | bc_l = 0; | |
1029 | bc_r = bp_location_count; | |
1030 | while (bc_l + 1 < bc_r) | |
1031 | { | |
1032 | struct bp_location *b; | |
1033 | ||
1034 | bc = (bc_l + bc_r) / 2; | |
1035 | b = bp_location[bc]; | |
1036 | ||
1037 | /* Check first B->ADDRESS will not overflow due to the added constant. | |
1038 | Then advance the left boundary only if we are sure the BC element can | |
1039 | in no way affect the BUF content (MEMADDR to MEMADDR + LEN range). | |
1040 | ||
1041 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety offset so that | |
1042 | we cannot miss a breakpoint with its shadow range tail still reaching | |
1043 | MEMADDR. */ | |
c5aa993b | 1044 | |
876fa593 JK |
1045 | if (b->address + bp_location_shadow_len_after_address_max >= b->address |
1046 | && b->address + bp_location_shadow_len_after_address_max <= memaddr) | |
1047 | bc_l = bc; | |
1048 | else | |
1049 | bc_r = bc; | |
1050 | } | |
1051 | ||
1052 | /* Now do full processing of the found relevant range of elements. */ | |
1053 | ||
1054 | for (bc = bc_l; bc < bp_location_count; bc++) | |
c5aa993b | 1055 | { |
876fa593 JK |
1056 | struct bp_location *b = bp_location[bc]; |
1057 | CORE_ADDR bp_addr = 0; | |
1058 | int bp_size = 0; | |
1059 | int bptoffset = 0; | |
1060 | ||
ffce0d52 | 1061 | if (b->owner->type == bp_none) |
8a3fe4f8 | 1062 | warning (_("reading through apparently deleted breakpoint #%d?"), |
ffce0d52 DJ |
1063 | b->owner->number); |
1064 | ||
876fa593 JK |
1065 | /* Performance optimization: any futher element can no longer affect BUF |
1066 | content. */ | |
1067 | ||
1068 | if (b->address >= bp_location_placed_address_before_address_max | |
1069 | && memaddr + len <= b->address | |
1070 | - bp_location_placed_address_before_address_max) | |
1071 | break; | |
1072 | ||
1073 | if (!bp_location_has_shadow (b)) | |
c5aa993b | 1074 | continue; |
6c95b8df PA |
1075 | if (!breakpoint_address_match (b->target_info.placed_address_space, 0, |
1076 | current_program_space->aspace, 0)) | |
1077 | continue; | |
1078 | ||
c5aa993b JM |
1079 | /* Addresses and length of the part of the breakpoint that |
1080 | we need to copy. */ | |
8181d85f DJ |
1081 | bp_addr = b->target_info.placed_address; |
1082 | bp_size = b->target_info.shadow_len; | |
8defab1a | 1083 | |
c5aa993b JM |
1084 | if (bp_addr + bp_size <= memaddr) |
1085 | /* The breakpoint is entirely before the chunk of memory we | |
1086 | are reading. */ | |
1087 | continue; | |
8defab1a | 1088 | |
c5aa993b JM |
1089 | if (bp_addr >= memaddr + len) |
1090 | /* The breakpoint is entirely after the chunk of memory we are | |
1091 | reading. */ | |
1092 | continue; | |
c5aa993b | 1093 | |
8defab1a DJ |
1094 | /* Offset within shadow_contents. */ |
1095 | if (bp_addr < memaddr) | |
1096 | { | |
1097 | /* Only copy the second part of the breakpoint. */ | |
1098 | bp_size -= memaddr - bp_addr; | |
1099 | bptoffset = memaddr - bp_addr; | |
1100 | bp_addr = memaddr; | |
1101 | } | |
c5aa993b | 1102 | |
8defab1a DJ |
1103 | if (bp_addr + bp_size > memaddr + len) |
1104 | { | |
1105 | /* Only copy the first part of the breakpoint. */ | |
1106 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1107 | } | |
c5aa993b | 1108 | |
8defab1a DJ |
1109 | memcpy (buf + bp_addr - memaddr, |
1110 | b->target_info.shadow_contents + bptoffset, bp_size); | |
c5aa993b | 1111 | } |
c906108c | 1112 | } |
c906108c | 1113 | \f |
c5aa993b | 1114 | |
687595f9 | 1115 | /* A wrapper function for inserting catchpoints. */ |
9cbc821d | 1116 | static void |
687595f9 DJ |
1117 | insert_catchpoint (struct ui_out *uo, void *args) |
1118 | { | |
1119 | struct breakpoint *b = (struct breakpoint *) args; | |
1120 | int val = -1; | |
1121 | ||
fe798b75 JB |
1122 | gdb_assert (b->type == bp_catchpoint); |
1123 | gdb_assert (b->ops != NULL && b->ops->insert != NULL); | |
1124 | ||
1125 | b->ops->insert (b); | |
687595f9 DJ |
1126 | } |
1127 | ||
60e1c644 PA |
1128 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1129 | ||
a5606eee VP |
1130 | static int |
1131 | is_hardware_watchpoint (struct breakpoint *bpt) | |
1132 | { | |
1133 | return (bpt->type == bp_hardware_watchpoint | |
1134 | || bpt->type == bp_read_watchpoint | |
1135 | || bpt->type == bp_access_watchpoint); | |
1136 | } | |
7270d8f2 | 1137 | |
60e1c644 PA |
1138 | /* Return true if BPT is of any watchpoint kind, hardware or |
1139 | software. */ | |
1140 | ||
1141 | static int | |
1142 | is_watchpoint (struct breakpoint *bpt) | |
1143 | { | |
1144 | return (is_hardware_watchpoint (bpt) | |
1145 | || bpt->type == bp_watchpoint); | |
1146 | } | |
1147 | ||
fa4727a6 DJ |
1148 | /* Find the current value of a watchpoint on EXP. Return the value in |
1149 | *VALP and *RESULTP and the chain of intermediate and final values | |
1150 | in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does | |
1151 | not need them. | |
1152 | ||
ccc57cf9 | 1153 | If a memory error occurs while evaluating the expression, *RESULTP will |
fa4727a6 DJ |
1154 | be set to NULL. *RESULTP may be a lazy value, if the result could |
1155 | not be read from memory. It is used to determine whether a value | |
1156 | is user-specified (we should watch the whole value) or intermediate | |
1157 | (we should watch only the bit used to locate the final value). | |
1158 | ||
1159 | If the final value, or any intermediate value, could not be read | |
1160 | from memory, *VALP will be set to NULL. *VAL_CHAIN will still be | |
1161 | set to any referenced values. *VALP will never be a lazy value. | |
1162 | This is the value which we store in struct breakpoint. | |
1163 | ||
1164 | If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the | |
1165 | value chain. The caller must free the values individually. If | |
1166 | VAL_CHAIN is NULL, all generated values will be left on the value | |
1167 | chain. */ | |
1168 | ||
1169 | static void | |
1170 | fetch_watchpoint_value (struct expression *exp, struct value **valp, | |
1171 | struct value **resultp, struct value **val_chain) | |
1172 | { | |
1173 | struct value *mark, *new_mark, *result; | |
ccc57cf9 | 1174 | volatile struct gdb_exception ex; |
fa4727a6 DJ |
1175 | |
1176 | *valp = NULL; | |
1177 | if (resultp) | |
1178 | *resultp = NULL; | |
1179 | if (val_chain) | |
1180 | *val_chain = NULL; | |
1181 | ||
1182 | /* Evaluate the expression. */ | |
1183 | mark = value_mark (); | |
1184 | result = NULL; | |
ccc57cf9 PA |
1185 | |
1186 | TRY_CATCH (ex, RETURN_MASK_ALL) | |
1187 | { | |
1188 | result = evaluate_expression (exp); | |
1189 | } | |
1190 | if (ex.reason < 0) | |
1191 | { | |
1192 | /* Ignore memory errors, we want watchpoints pointing at | |
1193 | inaccessible memory to still be created; otherwise, throw the | |
1194 | error to some higher catcher. */ | |
1195 | switch (ex.error) | |
1196 | { | |
1197 | case MEMORY_ERROR: | |
1198 | break; | |
1199 | default: | |
1200 | throw_exception (ex); | |
1201 | break; | |
1202 | } | |
1203 | } | |
1204 | ||
fa4727a6 DJ |
1205 | new_mark = value_mark (); |
1206 | if (mark == new_mark) | |
1207 | return; | |
1208 | if (resultp) | |
1209 | *resultp = result; | |
1210 | ||
1211 | /* Make sure it's not lazy, so that after the target stops again we | |
1212 | have a non-lazy previous value to compare with. */ | |
1213 | if (result != NULL | |
1214 | && (!value_lazy (result) || gdb_value_fetch_lazy (result))) | |
1215 | *valp = result; | |
1216 | ||
1217 | if (val_chain) | |
1218 | { | |
1219 | /* Return the chain of intermediate values. We use this to | |
1220 | decide which addresses to watch. */ | |
1221 | *val_chain = new_mark; | |
1222 | value_release_to_mark (mark); | |
1223 | } | |
1224 | } | |
1225 | ||
f6bc2008 PA |
1226 | /* Assuming that B is a watchpoint: returns true if the current thread |
1227 | and its running state are safe to evaluate or update watchpoint B. | |
1228 | Watchpoints on local expressions need to be evaluated in the | |
1229 | context of the thread that was current when the watchpoint was | |
1230 | created, and, that thread needs to be stopped to be able to select | |
1231 | the correct frame context. Watchpoints on global expressions can | |
1232 | be evaluated on any thread, and in any state. It is presently left | |
1233 | to the target allowing memory accesses when threads are | |
1234 | running. */ | |
1235 | ||
1236 | static int | |
1237 | watchpoint_in_thread_scope (struct breakpoint *b) | |
1238 | { | |
1239 | return (ptid_equal (b->watchpoint_thread, null_ptid) | |
1240 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1241 | && !is_executing (inferior_ptid))); | |
1242 | } | |
1243 | ||
567e1b4e JB |
1244 | /* Assuming that B is a watchpoint: |
1245 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1246 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1247 | - Evaluate the condition if there is one, and store the result |
1248 | in b->loc->cond. | |
a5606eee VP |
1249 | - Update the list of values that must be watched in B->loc. |
1250 | ||
bfa149ac | 1251 | If the watchpoint disposition is disp_del_at_next_stop, then do nothing. |
a79d3c27 JK |
1252 | If this is local watchpoint that is out of scope, delete it. |
1253 | ||
1254 | Even with `set breakpoint always-inserted on' the watchpoints are removed | |
1255 | + inserted on each stop here. Normal breakpoints must never be removed | |
1256 | because they might be missed by a running thread when debugging in non-stop | |
1257 | mode. On the other hand, hardware watchpoints (is_hardware_watchpoint; | |
1258 | processed here) are specific to each LWP since they are stored in each LWP's | |
1259 | hardware debug registers. Therefore, such LWP must be stopped first in | |
1260 | order to be able to modify its hardware watchpoints. | |
1261 | ||
1262 | Hardware watchpoints must be reset exactly once after being presented to the | |
1263 | user. It cannot be done sooner, because it would reset the data used to | |
1264 | present the watchpoint hit to the user. And it must not be done later | |
1265 | because it could display the same single watchpoint hit during multiple GDB | |
1266 | stops. Note that the latter is relevant only to the hardware watchpoint | |
1267 | types bp_read_watchpoint and bp_access_watchpoint. False hit by | |
1268 | bp_hardware_watchpoint is not user-visible - its hit is suppressed if the | |
1269 | memory content has not changed. | |
1270 | ||
1271 | The following constraints influence the location where we can reset hardware | |
1272 | watchpoints: | |
1273 | ||
1274 | * target_stopped_by_watchpoint and target_stopped_data_address are called | |
1275 | several times when GDB stops. | |
1276 | ||
1277 | [linux] | |
1278 | * Multiple hardware watchpoints can be hit at the same time, causing GDB to | |
1279 | stop. GDB only presents one hardware watchpoint hit at a time as the | |
1280 | reason for stopping, and all the other hits are presented later, one after | |
1281 | the other, each time the user requests the execution to be resumed. | |
1282 | Execution is not resumed for the threads still having pending hit event | |
1283 | stored in LWP_INFO->STATUS. While the watchpoint is already removed from | |
1284 | the inferior on the first stop the thread hit event is kept being reported | |
1285 | from its cached value by linux_nat_stopped_data_address until the real | |
1286 | thread resume happens after the watchpoint gets presented and thus its | |
1287 | LWP_INFO->STATUS gets reset. | |
1288 | ||
1289 | Therefore the hardware watchpoint hit can get safely reset on the watchpoint | |
1290 | removal from inferior. */ | |
1291 | ||
b40ce68a | 1292 | static void |
a5606eee | 1293 | update_watchpoint (struct breakpoint *b, int reparse) |
7270d8f2 | 1294 | { |
a5606eee | 1295 | int within_current_scope; |
a5606eee VP |
1296 | struct frame_id saved_frame_id; |
1297 | struct bp_location *loc; | |
66076460 | 1298 | int frame_saved; |
a5606eee VP |
1299 | bpstat bs; |
1300 | ||
f6bc2008 PA |
1301 | /* If this is a local watchpoint, we only want to check if the |
1302 | watchpoint frame is in scope if the current thread is the thread | |
1303 | that was used to create the watchpoint. */ | |
1304 | if (!watchpoint_in_thread_scope (b)) | |
1305 | return; | |
1306 | ||
876fa593 | 1307 | /* We don't free locations. They are stored in bp_location array and |
567e1b4e JB |
1308 | update_global_locations will eventually delete them and remove |
1309 | breakpoints if needed. */ | |
a5606eee VP |
1310 | b->loc = NULL; |
1311 | ||
1312 | if (b->disposition == disp_del_at_next_stop) | |
1313 | return; | |
1314 | ||
66076460 | 1315 | frame_saved = 0; |
a5606eee VP |
1316 | |
1317 | /* Determine if the watchpoint is within scope. */ | |
1318 | if (b->exp_valid_block == NULL) | |
1319 | within_current_scope = 1; | |
1320 | else | |
1321 | { | |
1322 | struct frame_info *fi; | |
66076460 DJ |
1323 | |
1324 | /* Save the current frame's ID so we can restore it after | |
1325 | evaluating the watchpoint expression on its own frame. */ | |
1326 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1327 | took a frame parameter, so that we didn't have to change the | |
1328 | selected frame. */ | |
1329 | frame_saved = 1; | |
1330 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1331 | ||
a5606eee VP |
1332 | fi = frame_find_by_id (b->watchpoint_frame); |
1333 | within_current_scope = (fi != NULL); | |
1334 | if (within_current_scope) | |
1335 | select_frame (fi); | |
1336 | } | |
1337 | ||
1338 | if (within_current_scope && reparse) | |
1339 | { | |
1340 | char *s; | |
1341 | if (b->exp) | |
1342 | { | |
1343 | xfree (b->exp); | |
1344 | b->exp = NULL; | |
1345 | } | |
1346 | s = b->exp_string; | |
1347 | b->exp = parse_exp_1 (&s, b->exp_valid_block, 0); | |
1348 | /* If the meaning of expression itself changed, the old value is | |
1349 | no longer relevant. We don't want to report a watchpoint hit | |
1350 | to the user when the old value and the new value may actually | |
1351 | be completely different objects. */ | |
1352 | value_free (b->val); | |
fa4727a6 DJ |
1353 | b->val = NULL; |
1354 | b->val_valid = 0; | |
60e1c644 PA |
1355 | |
1356 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1357 | expression is stored in the breakpoint object, not in the | |
1358 | locations (re)created below. */ | |
1359 | if (b->cond_string != NULL) | |
1360 | { | |
1361 | if (b->cond_exp != NULL) | |
1362 | { | |
1363 | xfree (b->cond_exp); | |
1364 | b->cond_exp = NULL; | |
1365 | } | |
1366 | ||
1367 | s = b->cond_string; | |
1368 | b->cond_exp = parse_exp_1 (&s, b->cond_exp_valid_block, 0); | |
1369 | } | |
a5606eee | 1370 | } |
a5606eee VP |
1371 | |
1372 | /* If we failed to parse the expression, for example because | |
1373 | it refers to a global variable in a not-yet-loaded shared library, | |
1374 | don't try to insert watchpoint. We don't automatically delete | |
1375 | such watchpoint, though, since failure to parse expression | |
1376 | is different from out-of-scope watchpoint. */ | |
2d134ed3 PA |
1377 | if ( !target_has_execution) |
1378 | { | |
1379 | /* Without execution, memory can't change. No use to try and | |
1380 | set watchpoint locations. The watchpoint will be reset when | |
1381 | the target gains execution, through breakpoint_re_set. */ | |
1382 | } | |
1383 | else if (within_current_scope && b->exp) | |
a5606eee | 1384 | { |
fa4727a6 | 1385 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1386 | struct program_space *frame_pspace; |
a5606eee | 1387 | |
fa4727a6 | 1388 | fetch_watchpoint_value (b->exp, &v, &result, &val_chain); |
a5606eee | 1389 | |
a5606eee VP |
1390 | /* Avoid setting b->val if it's already set. The meaning of |
1391 | b->val is 'the last value' user saw, and we should update | |
1392 | it only if we reported that last value to user. As it | |
1393 | happens, the code that reports it updates b->val directly. */ | |
fa4727a6 DJ |
1394 | if (!b->val_valid) |
1395 | { | |
1396 | b->val = v; | |
1397 | b->val_valid = 1; | |
1398 | } | |
a5606eee | 1399 | |
db2ad4c3 JK |
1400 | /* Change the type of breakpoint between hardware assisted or an |
1401 | ordinary watchpoint depending on the hardware support and free | |
1402 | hardware slots. REPARSE is set when the inferior is started. */ | |
1403 | if ((b->type == bp_watchpoint || b->type == bp_hardware_watchpoint) | |
1404 | && reparse) | |
1405 | { | |
ca2d49e8 | 1406 | int i, mem_cnt, other_type_used; |
db2ad4c3 | 1407 | |
7b838ca2 TJB |
1408 | /* We need to determine how many resources are already used |
1409 | for all other hardware watchpoints to see if we still have | |
1410 | enough resources to also fit this watchpoint in as well. | |
1411 | To avoid the hw_watchpoint_used_count call below from counting | |
1412 | this watchpoint, make sure that it is marked as a software | |
1413 | watchpoint. */ | |
1414 | b->type = bp_watchpoint; | |
db2ad4c3 JK |
1415 | i = hw_watchpoint_used_count (bp_hardware_watchpoint, |
1416 | &other_type_used); | |
1417 | mem_cnt = can_use_hardware_watchpoint (val_chain); | |
1418 | ||
ca2d49e8 | 1419 | if (!mem_cnt) |
db2ad4c3 JK |
1420 | b->type = bp_watchpoint; |
1421 | else | |
ca2d49e8 | 1422 | { |
d92524f1 | 1423 | int target_resources_ok = target_can_use_hardware_watchpoint |
ca2d49e8 SL |
1424 | (bp_hardware_watchpoint, i + mem_cnt, other_type_used); |
1425 | if (target_resources_ok <= 0) | |
1426 | b->type = bp_watchpoint; | |
1427 | else | |
1428 | b->type = bp_hardware_watchpoint; | |
1429 | } | |
db2ad4c3 JK |
1430 | } |
1431 | ||
2d134ed3 PA |
1432 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1433 | ||
a5606eee | 1434 | /* Look at each value on the value chain. */ |
fa4727a6 | 1435 | for (v = val_chain; v; v = next) |
a5606eee VP |
1436 | { |
1437 | /* If it's a memory location, and GDB actually needed | |
1438 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1439 | must watch it. If the first value returned is |
1440 | still lazy, that means an error occurred reading it; | |
1441 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1442 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1443 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1444 | { |
1445 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1446 | |
a5606eee VP |
1447 | /* We only watch structs and arrays if user asked |
1448 | for it explicitly, never if they just happen to | |
1449 | appear in the middle of some value chain. */ | |
fa4727a6 | 1450 | if (v == result |
a5606eee VP |
1451 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1452 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1453 | { | |
1454 | CORE_ADDR addr; | |
1455 | int len, type; | |
1456 | struct bp_location *loc, **tmp; | |
1457 | ||
42ae5230 | 1458 | addr = value_address (v); |
a5606eee VP |
1459 | len = TYPE_LENGTH (value_type (v)); |
1460 | type = hw_write; | |
1461 | if (b->type == bp_read_watchpoint) | |
1462 | type = hw_read; | |
1463 | else if (b->type == bp_access_watchpoint) | |
1464 | type = hw_access; | |
1465 | ||
39d61571 | 1466 | loc = allocate_bp_location (b); |
a5606eee VP |
1467 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
1468 | ; | |
1469 | *tmp = loc; | |
a6d9a66e | 1470 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1471 | |
1472 | loc->pspace = frame_pspace; | |
a5606eee VP |
1473 | loc->address = addr; |
1474 | loc->length = len; | |
1475 | loc->watchpoint_type = type; | |
1476 | } | |
1477 | } | |
1478 | ||
1479 | next = value_next (v); | |
1480 | if (v != b->val) | |
1481 | value_free (v); | |
1482 | } | |
1483 | ||
c7437ca6 PA |
1484 | /* If a software watchpoint is not watching any memory, then the |
1485 | above left it without any location set up. But, | |
1486 | bpstat_stop_status requires a location to be able to report | |
1487 | stops, so make sure there's at least a dummy one. */ | |
1488 | if (b->type == bp_watchpoint && b->loc == NULL) | |
1489 | { | |
1490 | b->loc = allocate_bp_location (b); | |
1491 | b->loc->pspace = frame_pspace; | |
1492 | b->loc->address = -1; | |
1493 | b->loc->length = -1; | |
1494 | b->loc->watchpoint_type = -1; | |
1495 | } | |
a5606eee VP |
1496 | } |
1497 | else if (!within_current_scope) | |
7270d8f2 | 1498 | { |
a5606eee | 1499 | printf_filtered (_("\ |
567e1b4e | 1500 | Watchpoint %d deleted because the program has left the block \n\ |
a5606eee VP |
1501 | in which its expression is valid.\n"), |
1502 | b->number); | |
1503 | if (b->related_breakpoint) | |
60e1c644 PA |
1504 | { |
1505 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1506 | b->related_breakpoint->related_breakpoint = NULL; | |
1507 | b->related_breakpoint= NULL; | |
1508 | } | |
a5606eee | 1509 | b->disposition = disp_del_at_next_stop; |
7270d8f2 | 1510 | } |
a5606eee VP |
1511 | |
1512 | /* Restore the selected frame. */ | |
66076460 DJ |
1513 | if (frame_saved) |
1514 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
1515 | } |
1516 | ||
a5606eee | 1517 | |
74960c60 VP |
1518 | /* Returns 1 iff breakpoint location should be |
1519 | inserted in the inferior. */ | |
1520 | static int | |
1521 | should_be_inserted (struct bp_location *bpt) | |
1522 | { | |
1523 | if (!breakpoint_enabled (bpt->owner)) | |
1524 | return 0; | |
1525 | ||
1526 | if (bpt->owner->disposition == disp_del_at_next_stop) | |
1527 | return 0; | |
1528 | ||
1529 | if (!bpt->enabled || bpt->shlib_disabled || bpt->duplicate) | |
1530 | return 0; | |
1531 | ||
56710373 PA |
1532 | /* This is set for example, when we're attached to the parent of a |
1533 | vfork, and have detached from the child. The child is running | |
1534 | free, and we expect it to do an exec or exit, at which point the | |
1535 | OS makes the parent schedulable again (and the target reports | |
1536 | that the vfork is done). Until the child is done with the shared | |
1537 | memory region, do not insert breakpoints in the parent, otherwise | |
1538 | the child could still trip on the parent's breakpoints. Since | |
1539 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
1540 | if (bpt->pspace->breakpoints_not_allowed) | |
1541 | return 0; | |
1542 | ||
1042e4c0 SS |
1543 | /* Tracepoints are inserted by the target at a time of its choosing, |
1544 | not by us. */ | |
7a697b8d | 1545 | if (tracepoint_type (bpt->owner)) |
1042e4c0 SS |
1546 | return 0; |
1547 | ||
74960c60 VP |
1548 | return 1; |
1549 | } | |
1550 | ||
879bfdc2 DJ |
1551 | /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint. |
1552 | Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS, | |
fa3a767f | 1553 | and HW_BREAKPOINT_ERROR are used to report problems. |
879bfdc2 DJ |
1554 | |
1555 | NOTE drow/2003-09-09: This routine could be broken down to an object-style | |
1556 | method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 1557 | static int |
879bfdc2 | 1558 | insert_bp_location (struct bp_location *bpt, |
26bb91f3 | 1559 | struct ui_file *tmp_error_stream, |
fa3a767f | 1560 | int *disabled_breaks, |
26bb91f3 | 1561 | int *hw_breakpoint_error) |
879bfdc2 DJ |
1562 | { |
1563 | int val = 0; | |
1564 | ||
74960c60 | 1565 | if (!should_be_inserted (bpt) || bpt->inserted) |
879bfdc2 DJ |
1566 | return 0; |
1567 | ||
8181d85f DJ |
1568 | /* Initialize the target-specific information. */ |
1569 | memset (&bpt->target_info, 0, sizeof (bpt->target_info)); | |
1570 | bpt->target_info.placed_address = bpt->address; | |
6c95b8df | 1571 | bpt->target_info.placed_address_space = bpt->pspace->aspace; |
8181d85f | 1572 | |
879bfdc2 DJ |
1573 | if (bpt->loc_type == bp_loc_software_breakpoint |
1574 | || bpt->loc_type == bp_loc_hardware_breakpoint) | |
1575 | { | |
765dc015 VP |
1576 | if (bpt->owner->type != bp_hardware_breakpoint) |
1577 | { | |
1578 | /* If the explicitly specified breakpoint type | |
1579 | is not hardware breakpoint, check the memory map to see | |
1580 | if the breakpoint address is in read only memory or not. | |
1581 | Two important cases are: | |
1582 | - location type is not hardware breakpoint, memory | |
1583 | is readonly. We change the type of the location to | |
1584 | hardware breakpoint. | |
1585 | - location type is hardware breakpoint, memory is read-write. | |
1586 | This means we've previously made the location hardware one, but | |
1587 | then the memory map changed, so we undo. | |
1588 | ||
1589 | When breakpoints are removed, remove_breakpoints will | |
1590 | use location types we've just set here, the only possible | |
1591 | problem is that memory map has changed during running program, | |
1592 | but it's not going to work anyway with current gdb. */ | |
1593 | struct mem_region *mr | |
1594 | = lookup_mem_region (bpt->target_info.placed_address); | |
1595 | ||
1596 | if (mr) | |
1597 | { | |
1598 | if (automatic_hardware_breakpoints) | |
1599 | { | |
1600 | int changed = 0; | |
1601 | enum bp_loc_type new_type; | |
1602 | ||
1603 | if (mr->attrib.mode != MEM_RW) | |
1604 | new_type = bp_loc_hardware_breakpoint; | |
1605 | else | |
1606 | new_type = bp_loc_software_breakpoint; | |
1607 | ||
1608 | if (new_type != bpt->loc_type) | |
1609 | { | |
1610 | static int said = 0; | |
1611 | bpt->loc_type = new_type; | |
1612 | if (!said) | |
1613 | { | |
1614 | fprintf_filtered (gdb_stdout, _("\ | |
0767c96d | 1615 | Note: automatically using hardware breakpoints for read-only addresses.\n")); |
765dc015 VP |
1616 | said = 1; |
1617 | } | |
1618 | } | |
1619 | } | |
1620 | else if (bpt->loc_type == bp_loc_software_breakpoint | |
1621 | && mr->attrib.mode != MEM_RW) | |
1622 | warning (_("cannot set software breakpoint at readonly address %s"), | |
5af949e3 | 1623 | paddress (bpt->gdbarch, bpt->address)); |
765dc015 VP |
1624 | } |
1625 | } | |
1626 | ||
879bfdc2 DJ |
1627 | /* First check to see if we have to handle an overlay. */ |
1628 | if (overlay_debugging == ovly_off | |
1629 | || bpt->section == NULL | |
1630 | || !(section_is_overlay (bpt->section))) | |
1631 | { | |
1632 | /* No overlay handling: just set the breakpoint. */ | |
1633 | ||
1634 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
a6d9a66e UW |
1635 | val = target_insert_hw_breakpoint (bpt->gdbarch, |
1636 | &bpt->target_info); | |
879bfdc2 | 1637 | else |
a6d9a66e UW |
1638 | val = target_insert_breakpoint (bpt->gdbarch, |
1639 | &bpt->target_info); | |
879bfdc2 DJ |
1640 | } |
1641 | else | |
1642 | { | |
1643 | /* This breakpoint is in an overlay section. | |
1644 | Shall we set a breakpoint at the LMA? */ | |
1645 | if (!overlay_events_enabled) | |
1646 | { | |
1647 | /* Yes -- overlay event support is not active, | |
1648 | so we must try to set a breakpoint at the LMA. | |
1649 | This will not work for a hardware breakpoint. */ | |
1650 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
8a3fe4f8 | 1651 | warning (_("hardware breakpoint %d not supported in overlay!"), |
879bfdc2 DJ |
1652 | bpt->owner->number); |
1653 | else | |
1654 | { | |
1655 | CORE_ADDR addr = overlay_unmapped_address (bpt->address, | |
1656 | bpt->section); | |
1657 | /* Set a software (trap) breakpoint at the LMA. */ | |
8181d85f DJ |
1658 | bpt->overlay_target_info = bpt->target_info; |
1659 | bpt->overlay_target_info.placed_address = addr; | |
a6d9a66e UW |
1660 | val = target_insert_breakpoint (bpt->gdbarch, |
1661 | &bpt->overlay_target_info); | |
879bfdc2 | 1662 | if (val != 0) |
99361f52 DE |
1663 | fprintf_unfiltered (tmp_error_stream, |
1664 | "Overlay breakpoint %d failed: in ROM?\n", | |
879bfdc2 DJ |
1665 | bpt->owner->number); |
1666 | } | |
1667 | } | |
1668 | /* Shall we set a breakpoint at the VMA? */ | |
1669 | if (section_is_mapped (bpt->section)) | |
1670 | { | |
1671 | /* Yes. This overlay section is mapped into memory. */ | |
1672 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
a6d9a66e UW |
1673 | val = target_insert_hw_breakpoint (bpt->gdbarch, |
1674 | &bpt->target_info); | |
879bfdc2 | 1675 | else |
a6d9a66e UW |
1676 | val = target_insert_breakpoint (bpt->gdbarch, |
1677 | &bpt->target_info); | |
879bfdc2 DJ |
1678 | } |
1679 | else | |
1680 | { | |
1681 | /* No. This breakpoint will not be inserted. | |
1682 | No error, but do not mark the bp as 'inserted'. */ | |
1683 | return 0; | |
1684 | } | |
1685 | } | |
1686 | ||
1687 | if (val) | |
1688 | { | |
1689 | /* Can't set the breakpoint. */ | |
6c95b8df | 1690 | if (solib_name_from_address (bpt->pspace, bpt->address)) |
879bfdc2 DJ |
1691 | { |
1692 | /* See also: disable_breakpoints_in_shlibs. */ | |
1693 | val = 0; | |
0d381245 | 1694 | bpt->shlib_disabled = 1; |
879bfdc2 DJ |
1695 | if (!*disabled_breaks) |
1696 | { | |
1697 | fprintf_unfiltered (tmp_error_stream, | |
1698 | "Cannot insert breakpoint %d.\n", | |
1699 | bpt->owner->number); | |
1700 | fprintf_unfiltered (tmp_error_stream, | |
1701 | "Temporarily disabling shared library breakpoints:\n"); | |
1702 | } | |
1703 | *disabled_breaks = 1; | |
1704 | fprintf_unfiltered (tmp_error_stream, | |
1705 | "breakpoint #%d\n", bpt->owner->number); | |
1706 | } | |
1707 | else | |
879bfdc2 | 1708 | { |
879bfdc2 DJ |
1709 | if (bpt->loc_type == bp_loc_hardware_breakpoint) |
1710 | { | |
1711 | *hw_breakpoint_error = 1; | |
1712 | fprintf_unfiltered (tmp_error_stream, | |
1713 | "Cannot insert hardware breakpoint %d.\n", | |
1714 | bpt->owner->number); | |
1715 | } | |
1716 | else | |
1717 | { | |
1718 | fprintf_unfiltered (tmp_error_stream, | |
1719 | "Cannot insert breakpoint %d.\n", | |
1720 | bpt->owner->number); | |
1721 | fprintf_filtered (tmp_error_stream, | |
1722 | "Error accessing memory address "); | |
5af949e3 UW |
1723 | fputs_filtered (paddress (bpt->gdbarch, bpt->address), |
1724 | tmp_error_stream); | |
879bfdc2 DJ |
1725 | fprintf_filtered (tmp_error_stream, ": %s.\n", |
1726 | safe_strerror (val)); | |
1727 | } | |
1728 | ||
1729 | } | |
1730 | } | |
1731 | else | |
1732 | bpt->inserted = 1; | |
1733 | ||
1734 | return val; | |
1735 | } | |
1736 | ||
1737 | else if (bpt->loc_type == bp_loc_hardware_watchpoint | |
1738 | /* NOTE drow/2003-09-08: This state only exists for removing | |
1739 | watchpoints. It's not clear that it's necessary... */ | |
1740 | && bpt->owner->disposition != disp_del_at_next_stop) | |
1741 | { | |
85d721b8 | 1742 | val = target_insert_watchpoint (bpt->address, |
a5606eee VP |
1743 | bpt->length, |
1744 | bpt->watchpoint_type); | |
85d721b8 PA |
1745 | |
1746 | /* If trying to set a read-watchpoint, and it turns out it's not | |
1747 | supported, try emulating one with an access watchpoint. */ | |
1748 | if (val == 1 && bpt->watchpoint_type == hw_read) | |
1749 | { | |
1750 | struct bp_location *loc, **loc_temp; | |
1751 | ||
1752 | /* But don't try to insert it, if there's already another | |
1753 | hw_access location that would be considered a duplicate | |
1754 | of this one. */ | |
1755 | ALL_BP_LOCATIONS (loc, loc_temp) | |
1756 | if (loc != bpt | |
1757 | && loc->watchpoint_type == hw_access | |
1758 | && watchpoint_locations_match (bpt, loc)) | |
1759 | { | |
1760 | bpt->duplicate = 1; | |
1761 | bpt->inserted = 1; | |
1762 | bpt->target_info = loc->target_info; | |
1763 | bpt->watchpoint_type = hw_access; | |
1764 | val = 0; | |
1765 | break; | |
1766 | } | |
1767 | ||
1768 | if (val == 1) | |
1769 | { | |
1770 | val = target_insert_watchpoint (bpt->address, | |
1771 | bpt->length, | |
1772 | hw_access); | |
1773 | if (val == 0) | |
1774 | bpt->watchpoint_type = hw_access; | |
1775 | } | |
1776 | } | |
1777 | ||
1778 | bpt->inserted = (val == 0); | |
879bfdc2 DJ |
1779 | } |
1780 | ||
fe798b75 | 1781 | else if (bpt->owner->type == bp_catchpoint) |
879bfdc2 | 1782 | { |
71fff37b AC |
1783 | struct gdb_exception e = catch_exception (uiout, insert_catchpoint, |
1784 | bpt->owner, RETURN_MASK_ERROR); | |
9cbc821d AC |
1785 | exception_fprintf (gdb_stderr, e, "warning: inserting catchpoint %d: ", |
1786 | bpt->owner->number); | |
1787 | if (e.reason < 0) | |
879bfdc2 DJ |
1788 | bpt->owner->enable_state = bp_disabled; |
1789 | else | |
1790 | bpt->inserted = 1; | |
1640b821 DJ |
1791 | |
1792 | /* We've already printed an error message if there was a problem | |
1793 | inserting this catchpoint, and we've disabled the catchpoint, | |
1794 | so just return success. */ | |
1795 | return 0; | |
879bfdc2 DJ |
1796 | } |
1797 | ||
1798 | return 0; | |
1799 | } | |
1800 | ||
6c95b8df PA |
1801 | /* This function is called when program space PSPACE is about to be |
1802 | deleted. It takes care of updating breakpoints to not reference | |
1803 | PSPACE anymore. */ | |
1804 | ||
1805 | void | |
1806 | breakpoint_program_space_exit (struct program_space *pspace) | |
1807 | { | |
1808 | struct breakpoint *b, *b_temp; | |
876fa593 | 1809 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
1810 | |
1811 | /* Remove any breakpoint that was set through this program space. */ | |
1812 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
1813 | { | |
1814 | if (b->pspace == pspace) | |
1815 | delete_breakpoint (b); | |
1816 | } | |
1817 | ||
1818 | /* Breakpoints set through other program spaces could have locations | |
1819 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 1820 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
1821 | { |
1822 | struct bp_location *tmp; | |
1823 | ||
1824 | if (loc->pspace == pspace) | |
1825 | { | |
1826 | if (loc->owner->loc == loc) | |
1827 | loc->owner->loc = loc->next; | |
1828 | else | |
1829 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
1830 | if (tmp->next == loc) | |
1831 | { | |
1832 | tmp->next = loc->next; | |
1833 | break; | |
1834 | } | |
1835 | } | |
1836 | } | |
1837 | ||
1838 | /* Now update the global location list to permanently delete the | |
1839 | removed locations above. */ | |
1840 | update_global_location_list (0); | |
1841 | } | |
1842 | ||
74960c60 VP |
1843 | /* Make sure all breakpoints are inserted in inferior. |
1844 | Throws exception on any error. | |
1845 | A breakpoint that is already inserted won't be inserted | |
1846 | again, so calling this function twice is safe. */ | |
1847 | void | |
1848 | insert_breakpoints (void) | |
1849 | { | |
1850 | struct breakpoint *bpt; | |
1851 | ||
1852 | ALL_BREAKPOINTS (bpt) | |
1853 | if (is_hardware_watchpoint (bpt)) | |
1854 | update_watchpoint (bpt, 0 /* don't reparse. */); | |
1855 | ||
b60e7edf | 1856 | update_global_location_list (1); |
74960c60 | 1857 | |
c35b1492 PA |
1858 | /* update_global_location_list does not insert breakpoints when |
1859 | always_inserted_mode is not enabled. Explicitly insert them | |
1860 | now. */ | |
1861 | if (!breakpoints_always_inserted_mode ()) | |
74960c60 VP |
1862 | insert_breakpoint_locations (); |
1863 | } | |
1864 | ||
c906108c SS |
1865 | /* insert_breakpoints is used when starting or continuing the program. |
1866 | remove_breakpoints is used when the program stops. | |
1867 | Both return zero if successful, | |
1868 | or an `errno' value if could not write the inferior. */ | |
1869 | ||
74960c60 VP |
1870 | static void |
1871 | insert_breakpoint_locations (void) | |
c906108c | 1872 | { |
a5606eee | 1873 | struct breakpoint *bpt; |
876fa593 | 1874 | struct bp_location *b, **bp_tmp; |
e236ba44 | 1875 | int error = 0; |
c906108c SS |
1876 | int val = 0; |
1877 | int disabled_breaks = 0; | |
81d0cc19 | 1878 | int hw_breakpoint_error = 0; |
c906108c | 1879 | |
81d0cc19 | 1880 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 1881 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 1882 | |
81d0cc19 GS |
1883 | /* Explicitly mark the warning -- this will only be printed if |
1884 | there was an error. */ | |
1885 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
1886 | |
1887 | save_current_space_and_thread (); | |
1888 | ||
876fa593 | 1889 | ALL_BP_LOCATIONS (b, bp_tmp) |
879bfdc2 | 1890 | { |
6c95b8df PA |
1891 | struct thread_info *tp; |
1892 | CORE_ADDR last_addr; | |
1893 | ||
74960c60 | 1894 | if (!should_be_inserted (b) || b->inserted) |
879bfdc2 DJ |
1895 | continue; |
1896 | ||
f365de73 AS |
1897 | /* There is no point inserting thread-specific breakpoints if the |
1898 | thread no longer exists. */ | |
1899 | if (b->owner->thread != -1 | |
1900 | && !valid_thread_id (b->owner->thread)) | |
1901 | continue; | |
1902 | ||
6c95b8df PA |
1903 | switch_to_program_space_and_thread (b->pspace); |
1904 | ||
1905 | /* For targets that support global breakpoints, there's no need | |
1906 | to select an inferior to insert breakpoint to. In fact, even | |
1907 | if we aren't attached to any process yet, we should still | |
1908 | insert breakpoints. */ | |
1909 | if (!gdbarch_has_global_breakpoints (target_gdbarch) | |
1910 | && ptid_equal (inferior_ptid, null_ptid)) | |
1911 | continue; | |
1912 | ||
879bfdc2 | 1913 | val = insert_bp_location (b, tmp_error_stream, |
fa3a767f | 1914 | &disabled_breaks, |
879bfdc2 DJ |
1915 | &hw_breakpoint_error); |
1916 | if (val) | |
e236ba44 | 1917 | error = val; |
879bfdc2 | 1918 | } |
c906108c | 1919 | |
a5606eee VP |
1920 | /* If we failed to insert all locations of a watchpoint, |
1921 | remove them, as half-inserted watchpoint is of limited use. */ | |
1922 | ALL_BREAKPOINTS (bpt) | |
1923 | { | |
1924 | int some_failed = 0; | |
1925 | struct bp_location *loc; | |
1926 | ||
1927 | if (!is_hardware_watchpoint (bpt)) | |
1928 | continue; | |
1929 | ||
d6b74ac4 | 1930 | if (!breakpoint_enabled (bpt)) |
a5606eee | 1931 | continue; |
74960c60 VP |
1932 | |
1933 | if (bpt->disposition == disp_del_at_next_stop) | |
1934 | continue; | |
a5606eee VP |
1935 | |
1936 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 1937 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
1938 | { |
1939 | some_failed = 1; | |
1940 | break; | |
1941 | } | |
1942 | if (some_failed) | |
1943 | { | |
1944 | for (loc = bpt->loc; loc; loc = loc->next) | |
1945 | if (loc->inserted) | |
1946 | remove_breakpoint (loc, mark_uninserted); | |
1947 | ||
1948 | hw_breakpoint_error = 1; | |
1949 | fprintf_unfiltered (tmp_error_stream, | |
1950 | "Could not insert hardware watchpoint %d.\n", | |
1951 | bpt->number); | |
1952 | error = -1; | |
1953 | } | |
1954 | } | |
1955 | ||
e236ba44 | 1956 | if (error) |
81d0cc19 GS |
1957 | { |
1958 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
1959 | message about possibly exhausted resources. */ | |
879bfdc2 | 1960 | if (hw_breakpoint_error) |
81d0cc19 | 1961 | { |
c6510018 MS |
1962 | fprintf_unfiltered (tmp_error_stream, |
1963 | "Could not insert hardware breakpoints:\n\ | |
1964 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 1965 | } |
81d0cc19 GS |
1966 | target_terminal_ours_for_output (); |
1967 | error_stream (tmp_error_stream); | |
1968 | } | |
f7545552 TT |
1969 | |
1970 | do_cleanups (cleanups); | |
c906108c SS |
1971 | } |
1972 | ||
c906108c | 1973 | int |
fba45db2 | 1974 | remove_breakpoints (void) |
c906108c | 1975 | { |
876fa593 | 1976 | struct bp_location *b, **bp_tmp; |
3a1bae8e | 1977 | int val = 0; |
c906108c | 1978 | |
876fa593 | 1979 | ALL_BP_LOCATIONS (b, bp_tmp) |
c5aa993b | 1980 | { |
0bde7532 | 1981 | if (b->inserted) |
3a1bae8e | 1982 | val |= remove_breakpoint (b, mark_uninserted); |
c5aa993b | 1983 | } |
3a1bae8e | 1984 | return val; |
c906108c SS |
1985 | } |
1986 | ||
6c95b8df PA |
1987 | /* Remove breakpoints of process PID. */ |
1988 | ||
1989 | int | |
1990 | remove_breakpoints_pid (int pid) | |
1991 | { | |
876fa593 | 1992 | struct bp_location *b, **b_tmp; |
6c95b8df PA |
1993 | int val; |
1994 | struct inferior *inf = find_inferior_pid (pid); | |
1995 | ||
876fa593 | 1996 | ALL_BP_LOCATIONS (b, b_tmp) |
6c95b8df PA |
1997 | { |
1998 | if (b->pspace != inf->pspace) | |
1999 | continue; | |
2000 | ||
2001 | if (b->inserted) | |
2002 | { | |
2003 | val = remove_breakpoint (b, mark_uninserted); | |
2004 | if (val != 0) | |
2005 | return val; | |
2006 | } | |
2007 | } | |
2008 | return 0; | |
2009 | } | |
2010 | ||
692590c1 | 2011 | int |
80ce1ecb | 2012 | remove_hw_watchpoints (void) |
692590c1 | 2013 | { |
876fa593 | 2014 | struct bp_location *b, **bp_tmp; |
3a1bae8e | 2015 | int val = 0; |
692590c1 | 2016 | |
876fa593 | 2017 | ALL_BP_LOCATIONS (b, bp_tmp) |
692590c1 | 2018 | { |
0bde7532 | 2019 | if (b->inserted && b->loc_type == bp_loc_hardware_watchpoint) |
3a1bae8e | 2020 | val |= remove_breakpoint (b, mark_uninserted); |
692590c1 | 2021 | } |
3a1bae8e | 2022 | return val; |
692590c1 MS |
2023 | } |
2024 | ||
c906108c | 2025 | int |
fba45db2 | 2026 | reattach_breakpoints (int pid) |
c906108c | 2027 | { |
6c95b8df | 2028 | struct cleanup *old_chain; |
876fa593 | 2029 | struct bp_location *b, **bp_tmp; |
c906108c | 2030 | int val; |
a4954f26 | 2031 | struct ui_file *tmp_error_stream = mem_fileopen (); |
fa3a767f | 2032 | int dummy1 = 0, dummy2 = 0; |
6c95b8df PA |
2033 | struct inferior *inf; |
2034 | struct thread_info *tp; | |
2035 | ||
2036 | tp = any_live_thread_of_process (pid); | |
2037 | if (tp == NULL) | |
2038 | return 1; | |
2039 | ||
2040 | inf = find_inferior_pid (pid); | |
2041 | old_chain = save_inferior_ptid (); | |
2042 | ||
2043 | inferior_ptid = tp->ptid; | |
a4954f26 DJ |
2044 | |
2045 | make_cleanup_ui_file_delete (tmp_error_stream); | |
c906108c | 2046 | |
876fa593 | 2047 | ALL_BP_LOCATIONS (b, bp_tmp) |
c5aa993b | 2048 | { |
6c95b8df PA |
2049 | if (b->pspace != inf->pspace) |
2050 | continue; | |
2051 | ||
0bde7532 | 2052 | if (b->inserted) |
c5aa993b | 2053 | { |
a4954f26 DJ |
2054 | b->inserted = 0; |
2055 | val = insert_bp_location (b, tmp_error_stream, | |
fa3a767f | 2056 | &dummy1, &dummy2); |
c5aa993b JM |
2057 | if (val != 0) |
2058 | { | |
ce696e05 | 2059 | do_cleanups (old_chain); |
c5aa993b JM |
2060 | return val; |
2061 | } | |
2062 | } | |
2063 | } | |
ce696e05 | 2064 | do_cleanups (old_chain); |
c906108c SS |
2065 | return 0; |
2066 | } | |
2067 | ||
e58b0e63 PA |
2068 | static int internal_breakpoint_number = -1; |
2069 | ||
e62c965a | 2070 | static struct breakpoint * |
a6d9a66e UW |
2071 | create_internal_breakpoint (struct gdbarch *gdbarch, |
2072 | CORE_ADDR address, enum bptype type) | |
e62c965a | 2073 | { |
e62c965a PP |
2074 | struct symtab_and_line sal; |
2075 | struct breakpoint *b; | |
2076 | ||
2077 | init_sal (&sal); /* initialize to zeroes */ | |
2078 | ||
2079 | sal.pc = address; | |
2080 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 2081 | sal.pspace = current_program_space; |
e62c965a | 2082 | |
a6d9a66e | 2083 | b = set_raw_breakpoint (gdbarch, sal, type); |
e62c965a PP |
2084 | b->number = internal_breakpoint_number--; |
2085 | b->disposition = disp_donttouch; | |
2086 | ||
2087 | return b; | |
2088 | } | |
2089 | ||
2090 | static void | |
69de3c6a | 2091 | create_overlay_event_breakpoint (char *func_name) |
e62c965a | 2092 | { |
69de3c6a | 2093 | struct objfile *objfile; |
e62c965a | 2094 | |
69de3c6a PP |
2095 | ALL_OBJFILES (objfile) |
2096 | { | |
2097 | struct breakpoint *b; | |
2098 | struct minimal_symbol *m; | |
2099 | ||
2100 | m = lookup_minimal_symbol_text (func_name, objfile); | |
2101 | if (m == NULL) | |
2102 | continue; | |
e62c965a | 2103 | |
a6d9a66e UW |
2104 | b = create_internal_breakpoint (get_objfile_arch (objfile), |
2105 | SYMBOL_VALUE_ADDRESS (m), | |
69de3c6a PP |
2106 | bp_overlay_event); |
2107 | b->addr_string = xstrdup (func_name); | |
e62c965a | 2108 | |
69de3c6a PP |
2109 | if (overlay_debugging == ovly_auto) |
2110 | { | |
2111 | b->enable_state = bp_enabled; | |
2112 | overlay_events_enabled = 1; | |
2113 | } | |
2114 | else | |
2115 | { | |
2116 | b->enable_state = bp_disabled; | |
2117 | overlay_events_enabled = 0; | |
2118 | } | |
e62c965a PP |
2119 | } |
2120 | update_global_location_list (1); | |
2121 | } | |
2122 | ||
0fd8e87f UW |
2123 | static void |
2124 | create_longjmp_master_breakpoint (char *func_name) | |
2125 | { | |
6c95b8df | 2126 | struct program_space *pspace; |
0fd8e87f | 2127 | struct objfile *objfile; |
6c95b8df PA |
2128 | struct cleanup *old_chain; |
2129 | ||
2130 | old_chain = save_current_program_space (); | |
0fd8e87f | 2131 | |
6c95b8df | 2132 | ALL_PSPACES (pspace) |
0fd8e87f UW |
2133 | ALL_OBJFILES (objfile) |
2134 | { | |
2135 | struct breakpoint *b; | |
2136 | struct minimal_symbol *m; | |
2137 | ||
2138 | if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile))) | |
2139 | continue; | |
2140 | ||
6c95b8df PA |
2141 | set_current_program_space (pspace); |
2142 | ||
0fd8e87f UW |
2143 | m = lookup_minimal_symbol_text (func_name, objfile); |
2144 | if (m == NULL) | |
2145 | continue; | |
2146 | ||
a6d9a66e UW |
2147 | b = create_internal_breakpoint (get_objfile_arch (objfile), |
2148 | SYMBOL_VALUE_ADDRESS (m), | |
0fd8e87f UW |
2149 | bp_longjmp_master); |
2150 | b->addr_string = xstrdup (func_name); | |
2151 | b->enable_state = bp_disabled; | |
2152 | } | |
2153 | update_global_location_list (1); | |
6c95b8df PA |
2154 | |
2155 | do_cleanups (old_chain); | |
0fd8e87f UW |
2156 | } |
2157 | ||
aa7d318d TT |
2158 | /* Create a master std::terminate breakpoint. The actual function |
2159 | looked for is named FUNC_NAME. */ | |
2160 | static void | |
2161 | create_std_terminate_master_breakpoint (const char *func_name) | |
2162 | { | |
2163 | struct program_space *pspace; | |
2164 | struct objfile *objfile; | |
2165 | struct cleanup *old_chain; | |
2166 | ||
2167 | old_chain = save_current_program_space (); | |
2168 | ||
2169 | ALL_PSPACES (pspace) | |
2170 | ALL_OBJFILES (objfile) | |
2171 | { | |
2172 | struct breakpoint *b; | |
2173 | struct minimal_symbol *m; | |
2174 | ||
2175 | set_current_program_space (pspace); | |
2176 | ||
2177 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
2178 | if (m == NULL || (MSYMBOL_TYPE (m) != mst_text | |
2179 | && MSYMBOL_TYPE (m) != mst_file_text)) | |
2180 | continue; | |
2181 | ||
2182 | b = create_internal_breakpoint (get_objfile_arch (objfile), | |
2183 | SYMBOL_VALUE_ADDRESS (m), | |
2184 | bp_std_terminate_master); | |
2185 | b->addr_string = xstrdup (func_name); | |
2186 | b->enable_state = bp_disabled; | |
2187 | } | |
2188 | update_global_location_list (1); | |
2189 | ||
2190 | do_cleanups (old_chain); | |
2191 | } | |
2192 | ||
c906108c | 2193 | void |
fba45db2 | 2194 | update_breakpoints_after_exec (void) |
c906108c | 2195 | { |
c5aa993b JM |
2196 | struct breakpoint *b; |
2197 | struct breakpoint *temp; | |
876fa593 | 2198 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 2199 | |
25b22b0a PA |
2200 | /* We're about to delete breakpoints from GDB's lists. If the |
2201 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
2202 | writing the breakpoints' "shadow contents" back into memory. The | |
2203 | "shadow contents" are NOT valid after an exec, so GDB should not | |
2204 | do that. Instead, the target is responsible from marking | |
2205 | breakpoints out as soon as it detects an exec. We don't do that | |
2206 | here instead, because there may be other attempts to delete | |
2207 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 2208 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
2209 | if (bploc->pspace == current_program_space) |
2210 | gdb_assert (!bploc->inserted); | |
c906108c SS |
2211 | |
2212 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b | 2213 | { |
6c95b8df PA |
2214 | if (b->pspace != current_program_space) |
2215 | continue; | |
2216 | ||
c5aa993b JM |
2217 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
2218 | if (b->type == bp_shlib_event) | |
2219 | { | |
2220 | delete_breakpoint (b); | |
2221 | continue; | |
2222 | } | |
c906108c | 2223 | |
4efc6507 DE |
2224 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
2225 | if (b->type == bp_jit_event) | |
2226 | { | |
2227 | delete_breakpoint (b); | |
2228 | continue; | |
2229 | } | |
2230 | ||
1900040c | 2231 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
2232 | as must overlay event and longjmp master breakpoints. */ |
2233 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
aa7d318d | 2234 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master) |
c4093a6a JM |
2235 | { |
2236 | delete_breakpoint (b); | |
2237 | continue; | |
2238 | } | |
2239 | ||
c5aa993b JM |
2240 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2241 | if (b->type == bp_step_resume) | |
2242 | { | |
2243 | delete_breakpoint (b); | |
2244 | continue; | |
2245 | } | |
2246 | ||
611c83ae PA |
2247 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
2248 | after an exec. */ | |
2249 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume) | |
2250 | { | |
2251 | delete_breakpoint (b); | |
2252 | continue; | |
2253 | } | |
2254 | ||
ce78b96d JB |
2255 | if (b->type == bp_catchpoint) |
2256 | { | |
2257 | /* For now, none of the bp_catchpoint breakpoints need to | |
2258 | do anything at this point. In the future, if some of | |
2259 | the catchpoints need to something, we will need to add | |
2260 | a new method, and call this method from here. */ | |
2261 | continue; | |
2262 | } | |
2263 | ||
c5aa993b JM |
2264 | /* bp_finish is a special case. The only way we ought to be able |
2265 | to see one of these when an exec() has happened, is if the user | |
2266 | caught a vfork, and then said "finish". Ordinarily a finish just | |
2267 | carries them to the call-site of the current callee, by setting | |
2268 | a temporary bp there and resuming. But in this case, the finish | |
2269 | will carry them entirely through the vfork & exec. | |
2270 | ||
2271 | We don't want to allow a bp_finish to remain inserted now. But | |
2272 | we can't safely delete it, 'cause finish_command has a handle to | |
2273 | the bp on a bpstat, and will later want to delete it. There's a | |
2274 | chance (and I've seen it happen) that if we delete the bp_finish | |
2275 | here, that its storage will get reused by the time finish_command | |
2276 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
2277 | We really must allow finish_command to delete a bp_finish. | |
2278 | ||
53a5351d JM |
2279 | In the absense of a general solution for the "how do we know |
2280 | it's safe to delete something others may have handles to?" | |
2281 | problem, what we'll do here is just uninsert the bp_finish, and | |
2282 | let finish_command delete it. | |
2283 | ||
2284 | (We know the bp_finish is "doomed" in the sense that it's | |
2285 | momentary, and will be deleted as soon as finish_command sees | |
2286 | the inferior stopped. So it doesn't matter that the bp's | |
2287 | address is probably bogus in the new a.out, unlike e.g., the | |
2288 | solib breakpoints.) */ | |
c5aa993b | 2289 | |
c5aa993b JM |
2290 | if (b->type == bp_finish) |
2291 | { | |
2292 | continue; | |
2293 | } | |
2294 | ||
2295 | /* Without a symbolic address, we have little hope of the | |
2296 | pre-exec() address meaning the same thing in the post-exec() | |
2297 | a.out. */ | |
2298 | if (b->addr_string == NULL) | |
2299 | { | |
2300 | delete_breakpoint (b); | |
2301 | continue; | |
2302 | } | |
c5aa993b | 2303 | } |
1900040c | 2304 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
69de3c6a | 2305 | create_overlay_event_breakpoint ("_ovly_debug_event"); |
0fd8e87f UW |
2306 | create_longjmp_master_breakpoint ("longjmp"); |
2307 | create_longjmp_master_breakpoint ("_longjmp"); | |
2308 | create_longjmp_master_breakpoint ("siglongjmp"); | |
2309 | create_longjmp_master_breakpoint ("_siglongjmp"); | |
aa7d318d | 2310 | create_std_terminate_master_breakpoint ("std::terminate()"); |
c906108c SS |
2311 | } |
2312 | ||
2313 | int | |
fba45db2 | 2314 | detach_breakpoints (int pid) |
c906108c | 2315 | { |
876fa593 | 2316 | struct bp_location *b, **bp_tmp; |
3a1bae8e | 2317 | int val = 0; |
ce696e05 | 2318 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 2319 | struct inferior *inf = current_inferior (); |
c5aa993b | 2320 | |
39f77062 | 2321 | if (pid == PIDGET (inferior_ptid)) |
8a3fe4f8 | 2322 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 2323 | |
6c95b8df | 2324 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
ce696e05 | 2325 | inferior_ptid = pid_to_ptid (pid); |
876fa593 | 2326 | ALL_BP_LOCATIONS (b, bp_tmp) |
c5aa993b | 2327 | { |
6c95b8df PA |
2328 | if (b->pspace != inf->pspace) |
2329 | continue; | |
2330 | ||
0bde7532 | 2331 | if (b->inserted) |
6c95b8df | 2332 | val |= remove_breakpoint_1 (b, mark_inserted); |
c5aa993b | 2333 | } |
ce696e05 | 2334 | do_cleanups (old_chain); |
3a1bae8e | 2335 | return val; |
c906108c SS |
2336 | } |
2337 | ||
6c95b8df PA |
2338 | /* Remove the breakpoint location B from the current address space. |
2339 | Note that this is used to detach breakpoints from a child fork. | |
2340 | When we get here, the child isn't in the inferior list, and neither | |
2341 | do we have objects to represent its address space --- we should | |
2342 | *not* look at b->pspace->aspace here. */ | |
2343 | ||
c906108c | 2344 | static int |
6c95b8df | 2345 | remove_breakpoint_1 (struct bp_location *b, insertion_state_t is) |
c906108c SS |
2346 | { |
2347 | int val; | |
6c95b8df | 2348 | struct cleanup *old_chain; |
c5aa993b | 2349 | |
0bde7532 | 2350 | if (b->owner->enable_state == bp_permanent) |
c2c6d25f JM |
2351 | /* Permanent breakpoints cannot be inserted or removed. */ |
2352 | return 0; | |
2353 | ||
74960c60 VP |
2354 | /* The type of none suggests that owner is actually deleted. |
2355 | This should not ever happen. */ | |
2356 | gdb_assert (b->owner->type != bp_none); | |
0bde7532 DJ |
2357 | |
2358 | if (b->loc_type == bp_loc_software_breakpoint | |
2359 | || b->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 2360 | { |
c02f5703 MS |
2361 | /* "Normal" instruction breakpoint: either the standard |
2362 | trap-instruction bp (bp_breakpoint), or a | |
2363 | bp_hardware_breakpoint. */ | |
2364 | ||
2365 | /* First check to see if we have to handle an overlay. */ | |
2366 | if (overlay_debugging == ovly_off | |
0bde7532 DJ |
2367 | || b->section == NULL |
2368 | || !(section_is_overlay (b->section))) | |
c02f5703 MS |
2369 | { |
2370 | /* No overlay handling: just remove the breakpoint. */ | |
2371 | ||
0bde7532 | 2372 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e | 2373 | val = target_remove_hw_breakpoint (b->gdbarch, &b->target_info); |
c02f5703 | 2374 | else |
a6d9a66e | 2375 | val = target_remove_breakpoint (b->gdbarch, &b->target_info); |
c02f5703 | 2376 | } |
c906108c SS |
2377 | else |
2378 | { | |
c02f5703 MS |
2379 | /* This breakpoint is in an overlay section. |
2380 | Did we set a breakpoint at the LMA? */ | |
2381 | if (!overlay_events_enabled) | |
2382 | { | |
2383 | /* Yes -- overlay event support is not active, so we | |
2384 | should have set a breakpoint at the LMA. Remove it. | |
2385 | */ | |
c02f5703 MS |
2386 | /* Ignore any failures: if the LMA is in ROM, we will |
2387 | have already warned when we failed to insert it. */ | |
0bde7532 | 2388 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e UW |
2389 | target_remove_hw_breakpoint (b->gdbarch, |
2390 | &b->overlay_target_info); | |
c02f5703 | 2391 | else |
a6d9a66e UW |
2392 | target_remove_breakpoint (b->gdbarch, |
2393 | &b->overlay_target_info); | |
c02f5703 MS |
2394 | } |
2395 | /* Did we set a breakpoint at the VMA? | |
2396 | If so, we will have marked the breakpoint 'inserted'. */ | |
0bde7532 | 2397 | if (b->inserted) |
c906108c | 2398 | { |
c02f5703 MS |
2399 | /* Yes -- remove it. Previously we did not bother to |
2400 | remove the breakpoint if the section had been | |
2401 | unmapped, but let's not rely on that being safe. We | |
2402 | don't know what the overlay manager might do. */ | |
0bde7532 | 2403 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e UW |
2404 | val = target_remove_hw_breakpoint (b->gdbarch, |
2405 | &b->target_info); | |
aa67235e UW |
2406 | |
2407 | /* However, we should remove *software* breakpoints only | |
2408 | if the section is still mapped, or else we overwrite | |
2409 | wrong code with the saved shadow contents. */ | |
2410 | else if (section_is_mapped (b->section)) | |
a6d9a66e UW |
2411 | val = target_remove_breakpoint (b->gdbarch, |
2412 | &b->target_info); | |
aa67235e UW |
2413 | else |
2414 | val = 0; | |
c906108c | 2415 | } |
c02f5703 MS |
2416 | else |
2417 | { | |
2418 | /* No -- not inserted, so no need to remove. No error. */ | |
2419 | val = 0; | |
2420 | } | |
c906108c | 2421 | } |
879d1e6b UW |
2422 | |
2423 | /* In some cases, we might not be able to remove a breakpoint | |
2424 | in a shared library that has already been removed, but we | |
2425 | have not yet processed the shlib unload event. */ | |
6c95b8df | 2426 | if (val && solib_name_from_address (b->pspace, b->address)) |
879d1e6b UW |
2427 | val = 0; |
2428 | ||
c906108c SS |
2429 | if (val) |
2430 | return val; | |
0bde7532 | 2431 | b->inserted = (is == mark_inserted); |
c906108c | 2432 | } |
a5606eee | 2433 | else if (b->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 2434 | { |
278cd55f AC |
2435 | struct value *v; |
2436 | struct value *n; | |
c5aa993b | 2437 | |
0bde7532 | 2438 | b->inserted = (is == mark_inserted); |
a5606eee VP |
2439 | val = target_remove_watchpoint (b->address, b->length, |
2440 | b->watchpoint_type); | |
2e70b7b9 | 2441 | |
c906108c | 2442 | /* Failure to remove any of the hardware watchpoints comes here. */ |
0bde7532 | 2443 | if ((is == mark_uninserted) && (b->inserted)) |
8a3fe4f8 | 2444 | warning (_("Could not remove hardware watchpoint %d."), |
0bde7532 | 2445 | b->owner->number); |
c906108c | 2446 | } |
ce78b96d JB |
2447 | else if (b->owner->type == bp_catchpoint |
2448 | && breakpoint_enabled (b->owner) | |
2449 | && !b->duplicate) | |
2450 | { | |
2451 | gdb_assert (b->owner->ops != NULL && b->owner->ops->remove != NULL); | |
2452 | ||
2453 | val = b->owner->ops->remove (b->owner); | |
2454 | if (val) | |
2455 | return val; | |
2456 | b->inserted = (is == mark_inserted); | |
2457 | } | |
c906108c SS |
2458 | |
2459 | return 0; | |
2460 | } | |
2461 | ||
6c95b8df PA |
2462 | static int |
2463 | remove_breakpoint (struct bp_location *b, insertion_state_t is) | |
2464 | { | |
2465 | int ret; | |
2466 | struct cleanup *old_chain; | |
2467 | ||
2468 | if (b->owner->enable_state == bp_permanent) | |
2469 | /* Permanent breakpoints cannot be inserted or removed. */ | |
2470 | return 0; | |
2471 | ||
2472 | /* The type of none suggests that owner is actually deleted. | |
2473 | This should not ever happen. */ | |
2474 | gdb_assert (b->owner->type != bp_none); | |
2475 | ||
2476 | old_chain = save_current_space_and_thread (); | |
2477 | ||
2478 | switch_to_program_space_and_thread (b->pspace); | |
2479 | ||
2480 | ret = remove_breakpoint_1 (b, is); | |
2481 | ||
2482 | do_cleanups (old_chain); | |
2483 | return ret; | |
2484 | } | |
2485 | ||
c906108c SS |
2486 | /* Clear the "inserted" flag in all breakpoints. */ |
2487 | ||
25b22b0a | 2488 | void |
fba45db2 | 2489 | mark_breakpoints_out (void) |
c906108c | 2490 | { |
876fa593 | 2491 | struct bp_location *bpt, **bptp_tmp; |
c906108c | 2492 | |
876fa593 | 2493 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
6c95b8df PA |
2494 | if (bpt->pspace == current_program_space) |
2495 | bpt->inserted = 0; | |
c906108c SS |
2496 | } |
2497 | ||
53a5351d JM |
2498 | /* Clear the "inserted" flag in all breakpoints and delete any |
2499 | breakpoints which should go away between runs of the program. | |
c906108c SS |
2500 | |
2501 | Plus other such housekeeping that has to be done for breakpoints | |
2502 | between runs. | |
2503 | ||
53a5351d JM |
2504 | Note: this function gets called at the end of a run (by |
2505 | generic_mourn_inferior) and when a run begins (by | |
2506 | init_wait_for_inferior). */ | |
c906108c SS |
2507 | |
2508 | ||
2509 | ||
2510 | void | |
fba45db2 | 2511 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 2512 | { |
52f0bd74 | 2513 | struct breakpoint *b, *temp; |
876fa593 | 2514 | struct bp_location *bpt, **bptp_tmp; |
1c5cfe86 | 2515 | int ix; |
6c95b8df | 2516 | struct program_space *pspace = current_program_space; |
c906108c | 2517 | |
50c71eaf PA |
2518 | /* If breakpoint locations are shared across processes, then there's |
2519 | nothing to do. */ | |
2567c7d9 | 2520 | if (gdbarch_has_global_breakpoints (target_gdbarch)) |
50c71eaf PA |
2521 | return; |
2522 | ||
876fa593 | 2523 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
6c95b8df PA |
2524 | { |
2525 | if (bpt->pspace == pspace | |
2526 | && bpt->owner->enable_state != bp_permanent) | |
514f746b | 2527 | bpt->inserted = 0; |
6c95b8df | 2528 | } |
075f6582 | 2529 | |
c906108c | 2530 | ALL_BREAKPOINTS_SAFE (b, temp) |
c5aa993b | 2531 | { |
6c95b8df PA |
2532 | if (b->loc && b->loc->pspace != pspace) |
2533 | continue; | |
2534 | ||
c5aa993b JM |
2535 | switch (b->type) |
2536 | { | |
2537 | case bp_call_dummy: | |
c906108c | 2538 | |
c5aa993b | 2539 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
2540 | cause problems when the inferior is rerun, so we better get |
2541 | rid of it. */ | |
2542 | ||
2543 | case bp_watchpoint_scope: | |
2544 | ||
2545 | /* Also get rid of scope breakpoints. */ | |
2546 | ||
2547 | case bp_shlib_event: | |
2548 | ||
2549 | /* Also remove solib event breakpoints. Their addresses may | |
2550 | have changed since the last time we ran the program. | |
2551 | Actually we may now be debugging against different target; | |
2552 | and so the solib backend that installed this breakpoint may | |
2553 | not be used in by the target. E.g., | |
2554 | ||
2555 | (gdb) file prog-linux | |
2556 | (gdb) run # native linux target | |
2557 | ... | |
2558 | (gdb) kill | |
2559 | (gdb) file prog-win.exe | |
2560 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
2561 | */ | |
c906108c | 2562 | |
c5aa993b JM |
2563 | delete_breakpoint (b); |
2564 | break; | |
c906108c | 2565 | |
c5aa993b JM |
2566 | case bp_watchpoint: |
2567 | case bp_hardware_watchpoint: | |
2568 | case bp_read_watchpoint: | |
2569 | case bp_access_watchpoint: | |
c906108c | 2570 | |
c5aa993b JM |
2571 | /* Likewise for watchpoints on local expressions. */ |
2572 | if (b->exp_valid_block != NULL) | |
2573 | delete_breakpoint (b); | |
967af18d | 2574 | else if (context == inf_starting) |
c860120c PM |
2575 | { |
2576 | /* Reset val field to force reread of starting value | |
2577 | in insert_breakpoints. */ | |
2578 | if (b->val) | |
2579 | value_free (b->val); | |
2580 | b->val = NULL; | |
fa4727a6 | 2581 | b->val_valid = 0; |
c860120c | 2582 | } |
c5aa993b JM |
2583 | break; |
2584 | default: | |
c5aa993b JM |
2585 | break; |
2586 | } | |
2587 | } | |
1c5cfe86 PA |
2588 | |
2589 | /* Get rid of the moribund locations. */ | |
2590 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bpt); ++ix) | |
2591 | free_bp_location (bpt); | |
2592 | VEC_free (bp_location_p, moribund_locations); | |
c906108c SS |
2593 | } |
2594 | ||
6c95b8df PA |
2595 | /* These functions concern about actual breakpoints inserted in the |
2596 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
2597 | we need to hop over the bkpt --- so we check for address space | |
2598 | match, not program space. */ | |
2599 | ||
c2c6d25f JM |
2600 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
2601 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
2602 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
2603 | permanent breakpoint. | |
2604 | - When continuing from a location with an ordinary breakpoint, we | |
2605 | actually single step once before calling insert_breakpoints. | |
2606 | - When continuing from a localion with a permanent breakpoint, we | |
2607 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by | |
2608 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 2609 | |
c2c6d25f | 2610 | enum breakpoint_here |
6c95b8df | 2611 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 2612 | { |
876fa593 | 2613 | struct bp_location *bpt, **bptp_tmp; |
c2c6d25f | 2614 | int any_breakpoint_here = 0; |
c906108c | 2615 | |
876fa593 | 2616 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
075f6582 DJ |
2617 | { |
2618 | if (bpt->loc_type != bp_loc_software_breakpoint | |
2619 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
2620 | continue; | |
2621 | ||
468d015d | 2622 | if ((breakpoint_enabled (bpt->owner) |
075f6582 | 2623 | || bpt->owner->enable_state == bp_permanent) |
6c95b8df PA |
2624 | && breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2625 | aspace, pc)) | |
075f6582 DJ |
2626 | { |
2627 | if (overlay_debugging | |
2628 | && section_is_overlay (bpt->section) | |
2629 | && !section_is_mapped (bpt->section)) | |
2630 | continue; /* unmapped overlay -- can't be a match */ | |
2631 | else if (bpt->owner->enable_state == bp_permanent) | |
2632 | return permanent_breakpoint_here; | |
2633 | else | |
2634 | any_breakpoint_here = 1; | |
2635 | } | |
2636 | } | |
c906108c | 2637 | |
c2c6d25f | 2638 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
2639 | } |
2640 | ||
1c5cfe86 PA |
2641 | /* Return true if there's a moribund breakpoint at PC. */ |
2642 | ||
2643 | int | |
6c95b8df | 2644 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
2645 | { |
2646 | struct bp_location *loc; | |
2647 | int ix; | |
2648 | ||
2649 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
6c95b8df PA |
2650 | if (breakpoint_address_match (loc->pspace->aspace, loc->address, |
2651 | aspace, pc)) | |
1c5cfe86 PA |
2652 | return 1; |
2653 | ||
2654 | return 0; | |
2655 | } | |
c2c6d25f | 2656 | |
c36b740a | 2657 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
876fa593 | 2658 | inserted using regular breakpoint_chain / bp_location array mechanism. |
c36b740a VP |
2659 | This does not check for single-step breakpoints, which are |
2660 | inserted and removed using direct target manipulation. */ | |
c906108c SS |
2661 | |
2662 | int | |
6c95b8df | 2663 | regular_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 2664 | { |
876fa593 | 2665 | struct bp_location *bpt, **bptp_tmp; |
c906108c | 2666 | |
876fa593 | 2667 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
c5aa993b | 2668 | { |
075f6582 DJ |
2669 | if (bpt->loc_type != bp_loc_software_breakpoint |
2670 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
2671 | continue; | |
2672 | ||
2673 | if (bpt->inserted | |
6c95b8df PA |
2674 | && breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2675 | aspace, pc)) | |
075f6582 DJ |
2676 | { |
2677 | if (overlay_debugging | |
2678 | && section_is_overlay (bpt->section) | |
2679 | && !section_is_mapped (bpt->section)) | |
2680 | continue; /* unmapped overlay -- can't be a match */ | |
2681 | else | |
2682 | return 1; | |
2683 | } | |
c5aa993b | 2684 | } |
c36b740a VP |
2685 | return 0; |
2686 | } | |
2687 | ||
2688 | /* Returns non-zero iff there's either regular breakpoint | |
2689 | or a single step breakpoint inserted at PC. */ | |
2690 | ||
2691 | int | |
6c95b8df | 2692 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c36b740a | 2693 | { |
6c95b8df | 2694 | if (regular_breakpoint_inserted_here_p (aspace, pc)) |
c36b740a | 2695 | return 1; |
c906108c | 2696 | |
6c95b8df | 2697 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2698 | return 1; |
2699 | ||
c906108c SS |
2700 | return 0; |
2701 | } | |
2702 | ||
4fa8626c DJ |
2703 | /* This function returns non-zero iff there is a software breakpoint |
2704 | inserted at PC. */ | |
2705 | ||
2706 | int | |
6c95b8df | 2707 | software_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
4fa8626c | 2708 | { |
876fa593 | 2709 | struct bp_location *bpt, **bptp_tmp; |
4fa8626c DJ |
2710 | int any_breakpoint_here = 0; |
2711 | ||
876fa593 | 2712 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
4fa8626c DJ |
2713 | { |
2714 | if (bpt->loc_type != bp_loc_software_breakpoint) | |
2715 | continue; | |
2716 | ||
0d381245 | 2717 | if (bpt->inserted |
6c95b8df PA |
2718 | && breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2719 | aspace, pc)) | |
4fa8626c DJ |
2720 | { |
2721 | if (overlay_debugging | |
2722 | && section_is_overlay (bpt->section) | |
2723 | && !section_is_mapped (bpt->section)) | |
2724 | continue; /* unmapped overlay -- can't be a match */ | |
2725 | else | |
2726 | return 1; | |
2727 | } | |
2728 | } | |
2729 | ||
1aafd4da | 2730 | /* Also check for software single-step breakpoints. */ |
6c95b8df | 2731 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2732 | return 1; |
2733 | ||
4fa8626c DJ |
2734 | return 0; |
2735 | } | |
2736 | ||
9093389c PA |
2737 | int |
2738 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
2739 | CORE_ADDR addr, ULONGEST len) | |
2740 | { | |
2741 | struct breakpoint *bpt; | |
2742 | ||
2743 | ALL_BREAKPOINTS (bpt) | |
2744 | { | |
2745 | struct bp_location *loc; | |
2746 | ||
2747 | if (bpt->type != bp_hardware_watchpoint | |
2748 | && bpt->type != bp_access_watchpoint) | |
2749 | continue; | |
2750 | ||
2751 | if (!breakpoint_enabled (bpt)) | |
2752 | continue; | |
2753 | ||
2754 | for (loc = bpt->loc; loc; loc = loc->next) | |
2755 | if (loc->pspace->aspace == aspace && loc->inserted) | |
2756 | { | |
2757 | CORE_ADDR l, h; | |
2758 | ||
2759 | /* Check for intersection. */ | |
2760 | l = max (loc->address, addr); | |
2761 | h = min (loc->address + loc->length, addr + len); | |
2762 | if (l < h) | |
2763 | return 1; | |
2764 | } | |
2765 | } | |
2766 | return 0; | |
2767 | } | |
2768 | ||
075f6582 DJ |
2769 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
2770 | PC is valid for process/thread PTID. */ | |
c906108c SS |
2771 | |
2772 | int | |
6c95b8df PA |
2773 | breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc, |
2774 | ptid_t ptid) | |
c906108c | 2775 | { |
876fa593 | 2776 | struct bp_location *bpt, **bptp_tmp; |
4a306c9a | 2777 | /* The thread and task IDs associated to PTID, computed lazily. */ |
a6f1cd96 | 2778 | int thread = -1; |
4a306c9a | 2779 | int task = 0; |
a6f1cd96 | 2780 | |
876fa593 | 2781 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
c5aa993b | 2782 | { |
075f6582 DJ |
2783 | if (bpt->loc_type != bp_loc_software_breakpoint |
2784 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
2785 | continue; | |
2786 | ||
a6f1cd96 JB |
2787 | if (!breakpoint_enabled (bpt->owner) |
2788 | && bpt->owner->enable_state != bp_permanent) | |
2789 | continue; | |
2790 | ||
6c95b8df PA |
2791 | if (!breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2792 | aspace, pc)) | |
a6f1cd96 JB |
2793 | continue; |
2794 | ||
2795 | if (bpt->owner->thread != -1) | |
075f6582 | 2796 | { |
a6f1cd96 JB |
2797 | /* This is a thread-specific breakpoint. Check that ptid |
2798 | matches that thread. If thread hasn't been computed yet, | |
2799 | it is now time to do so. */ | |
2800 | if (thread == -1) | |
2801 | thread = pid_to_thread_id (ptid); | |
2802 | if (bpt->owner->thread != thread) | |
2803 | continue; | |
075f6582 | 2804 | } |
a6f1cd96 | 2805 | |
4a306c9a JB |
2806 | if (bpt->owner->task != 0) |
2807 | { | |
2808 | /* This is a task-specific breakpoint. Check that ptid | |
2809 | matches that task. If task hasn't been computed yet, | |
2810 | it is now time to do so. */ | |
2811 | if (task == 0) | |
2812 | task = ada_get_task_number (ptid); | |
2813 | if (bpt->owner->task != task) | |
2814 | continue; | |
2815 | } | |
2816 | ||
a6f1cd96 JB |
2817 | if (overlay_debugging |
2818 | && section_is_overlay (bpt->section) | |
2819 | && !section_is_mapped (bpt->section)) | |
2820 | continue; /* unmapped overlay -- can't be a match */ | |
2821 | ||
2822 | return 1; | |
c5aa993b | 2823 | } |
c906108c SS |
2824 | |
2825 | return 0; | |
2826 | } | |
c906108c | 2827 | \f |
c5aa993b | 2828 | |
c906108c SS |
2829 | /* bpstat stuff. External routines' interfaces are documented |
2830 | in breakpoint.h. */ | |
2831 | ||
2832 | int | |
fba45db2 | 2833 | ep_is_catchpoint (struct breakpoint *ep) |
c906108c | 2834 | { |
533be4dd | 2835 | return (ep->type == bp_catchpoint); |
c906108c SS |
2836 | } |
2837 | ||
198757a8 VP |
2838 | void |
2839 | bpstat_free (bpstat bs) | |
2840 | { | |
2841 | if (bs->old_val != NULL) | |
2842 | value_free (bs->old_val); | |
9add0f1b | 2843 | decref_counted_command_line (&bs->commands); |
198757a8 VP |
2844 | xfree (bs); |
2845 | } | |
2846 | ||
c906108c SS |
2847 | /* Clear a bpstat so that it says we are not at any breakpoint. |
2848 | Also free any storage that is part of a bpstat. */ | |
2849 | ||
2850 | void | |
fba45db2 | 2851 | bpstat_clear (bpstat *bsp) |
c906108c SS |
2852 | { |
2853 | bpstat p; | |
2854 | bpstat q; | |
2855 | ||
2856 | if (bsp == 0) | |
2857 | return; | |
2858 | p = *bsp; | |
2859 | while (p != NULL) | |
2860 | { | |
2861 | q = p->next; | |
198757a8 | 2862 | bpstat_free (p); |
c906108c SS |
2863 | p = q; |
2864 | } | |
2865 | *bsp = NULL; | |
2866 | } | |
2867 | ||
2868 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
2869 | is part of the bpstat is copied as well. */ | |
2870 | ||
2871 | bpstat | |
fba45db2 | 2872 | bpstat_copy (bpstat bs) |
c906108c SS |
2873 | { |
2874 | bpstat p = NULL; | |
2875 | bpstat tmp; | |
2876 | bpstat retval = NULL; | |
2877 | ||
2878 | if (bs == NULL) | |
2879 | return bs; | |
2880 | ||
2881 | for (; bs != NULL; bs = bs->next) | |
2882 | { | |
2883 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
2884 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 2885 | incref_counted_command_line (tmp->commands); |
31cc81e9 | 2886 | if (bs->old_val != NULL) |
3c3185ac JK |
2887 | { |
2888 | tmp->old_val = value_copy (bs->old_val); | |
2889 | release_value (tmp->old_val); | |
2890 | } | |
31cc81e9 | 2891 | |
c906108c SS |
2892 | if (p == NULL) |
2893 | /* This is the first thing in the chain. */ | |
2894 | retval = tmp; | |
2895 | else | |
2896 | p->next = tmp; | |
2897 | p = tmp; | |
2898 | } | |
2899 | p->next = NULL; | |
2900 | return retval; | |
2901 | } | |
2902 | ||
2903 | /* Find the bpstat associated with this breakpoint */ | |
2904 | ||
2905 | bpstat | |
fba45db2 | 2906 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 2907 | { |
c5aa993b JM |
2908 | if (bsp == NULL) |
2909 | return NULL; | |
c906108c | 2910 | |
c5aa993b JM |
2911 | for (; bsp != NULL; bsp = bsp->next) |
2912 | { | |
4f8d1dc6 | 2913 | if (bsp->breakpoint_at && bsp->breakpoint_at->owner == breakpoint) |
c5aa993b JM |
2914 | return bsp; |
2915 | } | |
c906108c SS |
2916 | return NULL; |
2917 | } | |
2918 | ||
2919 | /* Find a step_resume breakpoint associated with this bpstat. | |
2920 | (If there are multiple step_resume bp's on the list, this function | |
2921 | will arbitrarily pick one.) | |
2922 | ||
2923 | It is an error to use this function if BPSTAT doesn't contain a | |
2924 | step_resume breakpoint. | |
2925 | ||
2926 | See wait_for_inferior's use of this function. */ | |
2927 | struct breakpoint * | |
fba45db2 | 2928 | bpstat_find_step_resume_breakpoint (bpstat bsp) |
c906108c | 2929 | { |
8601f500 MS |
2930 | int current_thread; |
2931 | ||
8a3fe4f8 | 2932 | gdb_assert (bsp != NULL); |
c906108c | 2933 | |
8601f500 MS |
2934 | current_thread = pid_to_thread_id (inferior_ptid); |
2935 | ||
c906108c SS |
2936 | for (; bsp != NULL; bsp = bsp->next) |
2937 | { | |
059fb39f PM |
2938 | if ((bsp->breakpoint_at != NULL) |
2939 | && (bsp->breakpoint_at->owner->type == bp_step_resume) | |
2940 | && (bsp->breakpoint_at->owner->thread == current_thread | |
2941 | || bsp->breakpoint_at->owner->thread == -1)) | |
4f8d1dc6 | 2942 | return bsp->breakpoint_at->owner; |
c906108c SS |
2943 | } |
2944 | ||
8a3fe4f8 | 2945 | internal_error (__FILE__, __LINE__, _("No step_resume breakpoint found.")); |
c906108c SS |
2946 | } |
2947 | ||
2948 | ||
8671a17b | 2949 | /* Put in *NUM the breakpoint number of the first breakpoint we are stopped |
c906108c SS |
2950 | at. *BSP upon return is a bpstat which points to the remaining |
2951 | breakpoints stopped at (but which is not guaranteed to be good for | |
2952 | anything but further calls to bpstat_num). | |
8671a17b PA |
2953 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
2954 | Return -1 if stopped at a breakpoint that has been deleted since | |
2955 | we set it. | |
2956 | Return 1 otherwise. */ | |
c906108c SS |
2957 | |
2958 | int | |
8671a17b | 2959 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
2960 | { |
2961 | struct breakpoint *b; | |
2962 | ||
2963 | if ((*bsp) == NULL) | |
2964 | return 0; /* No more breakpoint values */ | |
8671a17b | 2965 | |
4f8d1dc6 VP |
2966 | /* We assume we'll never have several bpstats that |
2967 | correspond to a single breakpoint -- otherwise, | |
2968 | this function might return the same number more | |
2969 | than once and this will look ugly. */ | |
2970 | b = (*bsp)->breakpoint_at ? (*bsp)->breakpoint_at->owner : NULL; | |
8671a17b PA |
2971 | *bsp = (*bsp)->next; |
2972 | if (b == NULL) | |
2973 | return -1; /* breakpoint that's been deleted since */ | |
2974 | ||
2975 | *num = b->number; /* We have its number */ | |
2976 | return 1; | |
c906108c SS |
2977 | } |
2978 | ||
2979 | /* Modify BS so that the actions will not be performed. */ | |
2980 | ||
2981 | void | |
fba45db2 | 2982 | bpstat_clear_actions (bpstat bs) |
c906108c SS |
2983 | { |
2984 | for (; bs != NULL; bs = bs->next) | |
2985 | { | |
9add0f1b | 2986 | decref_counted_command_line (&bs->commands); |
dde2d684 | 2987 | bs->commands_left = NULL; |
c906108c SS |
2988 | if (bs->old_val != NULL) |
2989 | { | |
2990 | value_free (bs->old_val); | |
2991 | bs->old_val = NULL; | |
2992 | } | |
2993 | } | |
2994 | } | |
2995 | ||
f3b1572e PA |
2996 | /* Called when a command is about to proceed the inferior. */ |
2997 | ||
2998 | static void | |
2999 | breakpoint_about_to_proceed (void) | |
3000 | { | |
3001 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
3002 | { | |
3003 | struct thread_info *tp = inferior_thread (); | |
3004 | ||
3005 | /* Allow inferior function calls in breakpoint commands to not | |
3006 | interrupt the command list. When the call finishes | |
3007 | successfully, the inferior will be standing at the same | |
3008 | breakpoint as if nothing happened. */ | |
3009 | if (tp->in_infcall) | |
3010 | return; | |
3011 | } | |
3012 | ||
3013 | breakpoint_proceeded = 1; | |
3014 | } | |
3015 | ||
c906108c | 3016 | /* Stub for cleaning up our state if we error-out of a breakpoint command */ |
c906108c | 3017 | static void |
4efb68b1 | 3018 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
3019 | { |
3020 | executing_breakpoint_commands = 0; | |
3021 | } | |
3022 | ||
3023 | /* Execute all the commands associated with all the breakpoints at this | |
3024 | location. Any of these commands could cause the process to proceed | |
3025 | beyond this point, etc. We look out for such changes by checking | |
347bddb7 | 3026 | the global "breakpoint_proceeded" after each command. |
c906108c | 3027 | |
347bddb7 PA |
3028 | Returns true if a breakpoint command resumed the inferior. In that |
3029 | case, it is the caller's responsibility to recall it again with the | |
3030 | bpstat of the current thread. */ | |
3031 | ||
3032 | static int | |
3033 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
3034 | { |
3035 | bpstat bs; | |
3036 | struct cleanup *old_chain; | |
347bddb7 | 3037 | int again = 0; |
c906108c SS |
3038 | |
3039 | /* Avoid endless recursion if a `source' command is contained | |
3040 | in bs->commands. */ | |
3041 | if (executing_breakpoint_commands) | |
347bddb7 | 3042 | return 0; |
c906108c SS |
3043 | |
3044 | executing_breakpoint_commands = 1; | |
3045 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
3046 | ||
c906108c SS |
3047 | /* This pointer will iterate over the list of bpstat's. */ |
3048 | bs = *bsp; | |
3049 | ||
3050 | breakpoint_proceeded = 0; | |
3051 | for (; bs != NULL; bs = bs->next) | |
3052 | { | |
9add0f1b | 3053 | struct counted_command_line *ccmd; |
6c50ab1c JB |
3054 | struct command_line *cmd; |
3055 | struct cleanup *this_cmd_tree_chain; | |
3056 | ||
3057 | /* Take ownership of the BSP's command tree, if it has one. | |
3058 | ||
3059 | The command tree could legitimately contain commands like | |
3060 | 'step' and 'next', which call clear_proceed_status, which | |
3061 | frees stop_bpstat's command tree. To make sure this doesn't | |
3062 | free the tree we're executing out from under us, we need to | |
3063 | take ownership of the tree ourselves. Since a given bpstat's | |
3064 | commands are only executed once, we don't need to copy it; we | |
3065 | can clear the pointer in the bpstat, and make sure we free | |
3066 | the tree when we're done. */ | |
9add0f1b TT |
3067 | ccmd = bs->commands; |
3068 | bs->commands = NULL; | |
3069 | this_cmd_tree_chain | |
3070 | = make_cleanup_decref_counted_command_line (&ccmd); | |
3071 | cmd = bs->commands_left; | |
3072 | bs->commands_left = NULL; | |
6c50ab1c | 3073 | |
c906108c SS |
3074 | while (cmd != NULL) |
3075 | { | |
3076 | execute_control_command (cmd); | |
3077 | ||
3078 | if (breakpoint_proceeded) | |
3079 | break; | |
3080 | else | |
3081 | cmd = cmd->next; | |
3082 | } | |
6c50ab1c JB |
3083 | |
3084 | /* We can free this command tree now. */ | |
3085 | do_cleanups (this_cmd_tree_chain); | |
3086 | ||
c906108c | 3087 | if (breakpoint_proceeded) |
32c1e744 VP |
3088 | { |
3089 | if (target_can_async_p ()) | |
347bddb7 PA |
3090 | /* If we are in async mode, then the target might be still |
3091 | running, not stopped at any breakpoint, so nothing for | |
3092 | us to do here -- just return to the event loop. */ | |
3093 | ; | |
32c1e744 VP |
3094 | else |
3095 | /* In sync mode, when execute_control_command returns | |
3096 | we're already standing on the next breakpoint. | |
347bddb7 PA |
3097 | Breakpoint commands for that stop were not run, since |
3098 | execute_command does not run breakpoint commands -- | |
3099 | only command_line_handler does, but that one is not | |
3100 | involved in execution of breakpoint commands. So, we | |
3101 | can now execute breakpoint commands. It should be | |
3102 | noted that making execute_command do bpstat actions is | |
3103 | not an option -- in this case we'll have recursive | |
3104 | invocation of bpstat for each breakpoint with a | |
3105 | command, and can easily blow up GDB stack. Instead, we | |
3106 | return true, which will trigger the caller to recall us | |
3107 | with the new stop_bpstat. */ | |
3108 | again = 1; | |
3109 | break; | |
32c1e744 | 3110 | } |
c906108c | 3111 | } |
c2b8ed2c | 3112 | do_cleanups (old_chain); |
347bddb7 PA |
3113 | return again; |
3114 | } | |
3115 | ||
3116 | void | |
3117 | bpstat_do_actions (void) | |
3118 | { | |
3119 | /* Do any commands attached to breakpoint we are stopped at. */ | |
3120 | while (!ptid_equal (inferior_ptid, null_ptid) | |
3121 | && target_has_execution | |
3122 | && !is_exited (inferior_ptid) | |
3123 | && !is_executing (inferior_ptid)) | |
3124 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
3125 | and only return when it is stopped at the next breakpoint, we | |
3126 | keep doing breakpoint actions until it returns false to | |
3127 | indicate the inferior was not resumed. */ | |
3128 | if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat)) | |
3129 | break; | |
c906108c SS |
3130 | } |
3131 | ||
fa4727a6 DJ |
3132 | /* Print out the (old or new) value associated with a watchpoint. */ |
3133 | ||
3134 | static void | |
3135 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
3136 | { | |
3137 | if (val == NULL) | |
3138 | fprintf_unfiltered (stream, _("<unreadable>")); | |
3139 | else | |
79a45b7d TT |
3140 | { |
3141 | struct value_print_options opts; | |
3142 | get_user_print_options (&opts); | |
3143 | value_print (val, stream, &opts); | |
3144 | } | |
fa4727a6 DJ |
3145 | } |
3146 | ||
e514a9d6 | 3147 | /* This is the normal print function for a bpstat. In the future, |
c906108c | 3148 | much of this logic could (should?) be moved to bpstat_stop_status, |
e514a9d6 JM |
3149 | by having it set different print_it values. |
3150 | ||
3151 | Current scheme: When we stop, bpstat_print() is called. It loops | |
3152 | through the bpstat list of things causing this stop, calling the | |
3153 | print_bp_stop_message function on each one. The behavior of the | |
3154 | print_bp_stop_message function depends on the print_it field of | |
3155 | bpstat. If such field so indicates, call this function here. | |
3156 | ||
3157 | Return values from this routine (ultimately used by bpstat_print() | |
3158 | and normal_stop() to decide what to do): | |
3159 | PRINT_NOTHING: Means we already printed all we needed to print, | |
3160 | don't print anything else. | |
3161 | PRINT_SRC_ONLY: Means we printed something, and we do *not* desire | |
3162 | that something to be followed by a location. | |
3163 | PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire | |
3164 | that something to be followed by a location. | |
3165 | PRINT_UNKNOWN: Means we printed nothing or we need to do some more | |
3166 | analysis. */ | |
c906108c | 3167 | |
917317f4 | 3168 | static enum print_stop_action |
fba45db2 | 3169 | print_it_typical (bpstat bs) |
c906108c | 3170 | { |
f7545552 | 3171 | struct cleanup *old_chain; |
4f8d1dc6 | 3172 | struct breakpoint *b; |
89f9893c | 3173 | const struct bp_location *bl; |
8b93c638 | 3174 | struct ui_stream *stb; |
f7545552 TT |
3175 | int bp_temp = 0; |
3176 | enum print_stop_action result; | |
3177 | ||
c906108c SS |
3178 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
3179 | which has since been deleted. */ | |
e514a9d6 | 3180 | if (bs->breakpoint_at == NULL) |
917317f4 | 3181 | return PRINT_UNKNOWN; |
0d381245 VP |
3182 | bl = bs->breakpoint_at; |
3183 | b = bl->owner; | |
c906108c | 3184 | |
f7545552 TT |
3185 | stb = ui_out_stream_new (uiout); |
3186 | old_chain = make_cleanup_ui_out_stream_delete (stb); | |
3187 | ||
4f8d1dc6 | 3188 | switch (b->type) |
c906108c | 3189 | { |
e514a9d6 JM |
3190 | case bp_breakpoint: |
3191 | case bp_hardware_breakpoint: | |
2cec12e5 | 3192 | bp_temp = bs->breakpoint_at->owner->disposition == disp_del; |
0d381245 VP |
3193 | if (bl->address != bl->requested_address) |
3194 | breakpoint_adjustment_warning (bl->requested_address, | |
3195 | bl->address, | |
4f8d1dc6 VP |
3196 | b->number, 1); |
3197 | annotate_breakpoint (b->number); | |
2cec12e5 AR |
3198 | if (bp_temp) |
3199 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
3200 | else | |
3201 | ui_out_text (uiout, "\nBreakpoint "); | |
9dc5e2a9 | 3202 | if (ui_out_is_mi_like_p (uiout)) |
2cec12e5 AR |
3203 | { |
3204 | ui_out_field_string (uiout, "reason", | |
3205 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
3206 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
3207 | } | |
4f8d1dc6 | 3208 | ui_out_field_int (uiout, "bkptno", b->number); |
8b93c638 | 3209 | ui_out_text (uiout, ", "); |
f7545552 | 3210 | result = PRINT_SRC_AND_LOC; |
e514a9d6 JM |
3211 | break; |
3212 | ||
3213 | case bp_shlib_event: | |
917317f4 JM |
3214 | /* Did we stop because the user set the stop_on_solib_events |
3215 | variable? (If so, we report this as a generic, "Stopped due | |
3216 | to shlib event" message.) */ | |
a3f17187 | 3217 | printf_filtered (_("Stopped due to shared library event\n")); |
f7545552 | 3218 | result = PRINT_NOTHING; |
e514a9d6 JM |
3219 | break; |
3220 | ||
c4093a6a JM |
3221 | case bp_thread_event: |
3222 | /* Not sure how we will get here. | |
3223 | GDB should not stop for these breakpoints. */ | |
a3f17187 | 3224 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 3225 | result = PRINT_NOTHING; |
c4093a6a JM |
3226 | break; |
3227 | ||
1900040c MS |
3228 | case bp_overlay_event: |
3229 | /* By analogy with the thread event, GDB should not stop for these. */ | |
a3f17187 | 3230 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 3231 | result = PRINT_NOTHING; |
1900040c MS |
3232 | break; |
3233 | ||
0fd8e87f UW |
3234 | case bp_longjmp_master: |
3235 | /* These should never be enabled. */ | |
3236 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
3237 | result = PRINT_NOTHING; | |
3238 | break; | |
3239 | ||
aa7d318d TT |
3240 | case bp_std_terminate_master: |
3241 | /* These should never be enabled. */ | |
3242 | printf_filtered (_("std::terminate Master Breakpoint: gdb should not stop!\n")); | |
3243 | result = PRINT_NOTHING; | |
3244 | break; | |
3245 | ||
e514a9d6 JM |
3246 | case bp_watchpoint: |
3247 | case bp_hardware_watchpoint: | |
fa4727a6 DJ |
3248 | annotate_watchpoint (b->number); |
3249 | if (ui_out_is_mi_like_p (uiout)) | |
3250 | ui_out_field_string | |
3251 | (uiout, "reason", | |
3252 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
3253 | mention (b); | |
f7545552 | 3254 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
fa4727a6 DJ |
3255 | ui_out_text (uiout, "\nOld value = "); |
3256 | watchpoint_value_print (bs->old_val, stb->stream); | |
3257 | ui_out_field_stream (uiout, "old", stb); | |
3258 | ui_out_text (uiout, "\nNew value = "); | |
3259 | watchpoint_value_print (b->val, stb->stream); | |
3260 | ui_out_field_stream (uiout, "new", stb); | |
fa4727a6 | 3261 | ui_out_text (uiout, "\n"); |
e514a9d6 | 3262 | /* More than one watchpoint may have been triggered. */ |
f7545552 | 3263 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
3264 | break; |
3265 | ||
3266 | case bp_read_watchpoint: | |
9dc5e2a9 | 3267 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3268 | ui_out_field_string |
3269 | (uiout, "reason", | |
3270 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 3271 | mention (b); |
f7545552 | 3272 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 3273 | ui_out_text (uiout, "\nValue = "); |
fa4727a6 | 3274 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 3275 | ui_out_field_stream (uiout, "value", stb); |
8b93c638 | 3276 | ui_out_text (uiout, "\n"); |
f7545552 | 3277 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
3278 | break; |
3279 | ||
3280 | case bp_access_watchpoint: | |
fa4727a6 | 3281 | if (bs->old_val != NULL) |
8b93c638 | 3282 | { |
4f8d1dc6 | 3283 | annotate_watchpoint (b->number); |
9dc5e2a9 | 3284 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3285 | ui_out_field_string |
3286 | (uiout, "reason", | |
3287 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 3288 | mention (b); |
f7545552 | 3289 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 3290 | ui_out_text (uiout, "\nOld value = "); |
fa4727a6 | 3291 | watchpoint_value_print (bs->old_val, stb->stream); |
8b93c638 | 3292 | ui_out_field_stream (uiout, "old", stb); |
8b93c638 JM |
3293 | ui_out_text (uiout, "\nNew value = "); |
3294 | } | |
3295 | else | |
3296 | { | |
4f8d1dc6 | 3297 | mention (b); |
9dc5e2a9 | 3298 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3299 | ui_out_field_string |
3300 | (uiout, "reason", | |
3301 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
f7545552 | 3302 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 JM |
3303 | ui_out_text (uiout, "\nValue = "); |
3304 | } | |
fa4727a6 | 3305 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 3306 | ui_out_field_stream (uiout, "new", stb); |
8b93c638 | 3307 | ui_out_text (uiout, "\n"); |
f7545552 | 3308 | result = PRINT_UNKNOWN; |
e514a9d6 | 3309 | break; |
4ce44c66 | 3310 | |
e514a9d6 JM |
3311 | /* Fall through, we don't deal with these types of breakpoints |
3312 | here. */ | |
3313 | ||
11cf8741 | 3314 | case bp_finish: |
9dc5e2a9 | 3315 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3316 | ui_out_field_string |
3317 | (uiout, "reason", | |
3318 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
f7545552 | 3319 | result = PRINT_UNKNOWN; |
8b93c638 JM |
3320 | break; |
3321 | ||
e514a9d6 | 3322 | case bp_until: |
9dc5e2a9 | 3323 | if (ui_out_is_mi_like_p (uiout)) |
1fbc2a49 NR |
3324 | ui_out_field_string |
3325 | (uiout, "reason", | |
3326 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
f7545552 | 3327 | result = PRINT_UNKNOWN; |
8b93c638 JM |
3328 | break; |
3329 | ||
c2d11a7d | 3330 | case bp_none: |
e514a9d6 JM |
3331 | case bp_longjmp: |
3332 | case bp_longjmp_resume: | |
3333 | case bp_step_resume: | |
e514a9d6 JM |
3334 | case bp_watchpoint_scope: |
3335 | case bp_call_dummy: | |
aa7d318d | 3336 | case bp_std_terminate: |
1042e4c0 | 3337 | case bp_tracepoint: |
7a697b8d | 3338 | case bp_fast_tracepoint: |
4efc6507 | 3339 | case bp_jit_event: |
e514a9d6 | 3340 | default: |
f7545552 TT |
3341 | result = PRINT_UNKNOWN; |
3342 | break; | |
e514a9d6 | 3343 | } |
f7545552 TT |
3344 | |
3345 | do_cleanups (old_chain); | |
3346 | return result; | |
e514a9d6 JM |
3347 | } |
3348 | ||
3349 | /* Generic routine for printing messages indicating why we | |
3350 | stopped. The behavior of this function depends on the value | |
3351 | 'print_it' in the bpstat structure. Under some circumstances we | |
3352 | may decide not to print anything here and delegate the task to | |
3353 | normal_stop(). */ | |
3354 | ||
3355 | static enum print_stop_action | |
3356 | print_bp_stop_message (bpstat bs) | |
3357 | { | |
3358 | switch (bs->print_it) | |
3359 | { | |
3360 | case print_it_noop: | |
3361 | /* Nothing should be printed for this bpstat entry. */ | |
3362 | return PRINT_UNKNOWN; | |
3363 | break; | |
3364 | ||
3365 | case print_it_done: | |
3366 | /* We still want to print the frame, but we already printed the | |
3367 | relevant messages. */ | |
3368 | return PRINT_SRC_AND_LOC; | |
3369 | break; | |
3370 | ||
3371 | case print_it_normal: | |
4f8d1dc6 | 3372 | { |
89f9893c | 3373 | const struct bp_location *bl = bs->breakpoint_at; |
4f8d1dc6 VP |
3374 | struct breakpoint *b = bl ? bl->owner : NULL; |
3375 | ||
3376 | /* Normal case. Call the breakpoint's print_it method, or | |
3377 | print_it_typical. */ | |
3378 | /* FIXME: how breakpoint can ever be NULL here? */ | |
3379 | if (b != NULL && b->ops != NULL && b->ops->print_it != NULL) | |
3380 | return b->ops->print_it (b); | |
3381 | else | |
3382 | return print_it_typical (bs); | |
3383 | } | |
3384 | break; | |
3086aeae | 3385 | |
e514a9d6 | 3386 | default: |
8e65ff28 | 3387 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 3388 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 3389 | break; |
c906108c | 3390 | } |
c906108c SS |
3391 | } |
3392 | ||
e514a9d6 JM |
3393 | /* Print a message indicating what happened. This is called from |
3394 | normal_stop(). The input to this routine is the head of the bpstat | |
3395 | list - a list of the eventpoints that caused this stop. This | |
3396 | routine calls the generic print routine for printing a message | |
3397 | about reasons for stopping. This will print (for example) the | |
3398 | "Breakpoint n," part of the output. The return value of this | |
3399 | routine is one of: | |
c906108c | 3400 | |
917317f4 JM |
3401 | PRINT_UNKNOWN: Means we printed nothing |
3402 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent | |
c5aa993b JM |
3403 | code to print the location. An example is |
3404 | "Breakpoint 1, " which should be followed by | |
3405 | the location. | |
917317f4 | 3406 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
3407 | to also print the location part of the message. |
3408 | An example is the catch/throw messages, which | |
917317f4 JM |
3409 | don't require a location appended to the end. |
3410 | PRINT_NOTHING: We have done some printing and we don't need any | |
3411 | further info to be printed.*/ | |
c906108c | 3412 | |
917317f4 | 3413 | enum print_stop_action |
fba45db2 | 3414 | bpstat_print (bpstat bs) |
c906108c SS |
3415 | { |
3416 | int val; | |
c5aa993b | 3417 | |
c906108c | 3418 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
3419 | (Currently all watchpoints go on the bpstat whether hit or not. |
3420 | That probably could (should) be changed, provided care is taken | |
c906108c | 3421 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
3422 | for (; bs; bs = bs->next) |
3423 | { | |
3424 | val = print_bp_stop_message (bs); | |
3425 | if (val == PRINT_SRC_ONLY | |
3426 | || val == PRINT_SRC_AND_LOC | |
3427 | || val == PRINT_NOTHING) | |
3428 | return val; | |
3429 | } | |
c906108c | 3430 | |
e514a9d6 JM |
3431 | /* We reached the end of the chain, or we got a null BS to start |
3432 | with and nothing was printed. */ | |
917317f4 | 3433 | return PRINT_UNKNOWN; |
c906108c SS |
3434 | } |
3435 | ||
3436 | /* Evaluate the expression EXP and return 1 if value is zero. | |
3437 | This is used inside a catch_errors to evaluate the breakpoint condition. | |
3438 | The argument is a "struct expression *" that has been cast to char * to | |
3439 | make it pass through catch_errors. */ | |
3440 | ||
3441 | static int | |
4efb68b1 | 3442 | breakpoint_cond_eval (void *exp) |
c906108c | 3443 | { |
278cd55f | 3444 | struct value *mark = value_mark (); |
c5aa993b | 3445 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
c906108c SS |
3446 | value_free_to_mark (mark); |
3447 | return i; | |
3448 | } | |
3449 | ||
3450 | /* Allocate a new bpstat and chain it to the current one. */ | |
3451 | ||
3452 | static bpstat | |
89f9893c | 3453 | bpstat_alloc (const struct bp_location *bl, bpstat cbs /* Current "bs" value */ ) |
c906108c SS |
3454 | { |
3455 | bpstat bs; | |
3456 | ||
3457 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
3458 | cbs->next = bs; | |
4f8d1dc6 | 3459 | bs->breakpoint_at = bl; |
c906108c SS |
3460 | /* If the condition is false, etc., don't do the commands. */ |
3461 | bs->commands = NULL; | |
9add0f1b | 3462 | bs->commands_left = NULL; |
c906108c SS |
3463 | bs->old_val = NULL; |
3464 | bs->print_it = print_it_normal; | |
3465 | return bs; | |
3466 | } | |
3467 | \f | |
d983da9c DJ |
3468 | /* The target has stopped with waitstatus WS. Check if any hardware |
3469 | watchpoints have triggered, according to the target. */ | |
3470 | ||
3471 | int | |
3472 | watchpoints_triggered (struct target_waitstatus *ws) | |
3473 | { | |
d92524f1 | 3474 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
3475 | CORE_ADDR addr; |
3476 | struct breakpoint *b; | |
3477 | ||
3478 | if (!stopped_by_watchpoint) | |
3479 | { | |
3480 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
3481 | as not triggered. */ | |
3482 | ALL_BREAKPOINTS (b) | |
3483 | if (b->type == bp_hardware_watchpoint | |
3484 | || b->type == bp_read_watchpoint | |
3485 | || b->type == bp_access_watchpoint) | |
3486 | b->watchpoint_triggered = watch_triggered_no; | |
3487 | ||
3488 | return 0; | |
3489 | } | |
3490 | ||
3491 | if (!target_stopped_data_address (¤t_target, &addr)) | |
3492 | { | |
3493 | /* We were stopped by a watchpoint, but we don't know where. | |
3494 | Mark all watchpoints as unknown. */ | |
3495 | ALL_BREAKPOINTS (b) | |
3496 | if (b->type == bp_hardware_watchpoint | |
3497 | || b->type == bp_read_watchpoint | |
3498 | || b->type == bp_access_watchpoint) | |
3499 | b->watchpoint_triggered = watch_triggered_unknown; | |
3500 | ||
3501 | return stopped_by_watchpoint; | |
3502 | } | |
3503 | ||
3504 | /* The target could report the data address. Mark watchpoints | |
3505 | affected by this data address as triggered, and all others as not | |
3506 | triggered. */ | |
3507 | ||
3508 | ALL_BREAKPOINTS (b) | |
3509 | if (b->type == bp_hardware_watchpoint | |
3510 | || b->type == bp_read_watchpoint | |
3511 | || b->type == bp_access_watchpoint) | |
3512 | { | |
a5606eee | 3513 | struct bp_location *loc; |
d983da9c DJ |
3514 | struct value *v; |
3515 | ||
3516 | b->watchpoint_triggered = watch_triggered_no; | |
a5606eee VP |
3517 | for (loc = b->loc; loc; loc = loc->next) |
3518 | /* Exact match not required. Within range is | |
3519 | sufficient. */ | |
5009afc5 AS |
3520 | if (target_watchpoint_addr_within_range (¤t_target, |
3521 | addr, loc->address, | |
3522 | loc->length)) | |
a5606eee VP |
3523 | { |
3524 | b->watchpoint_triggered = watch_triggered_yes; | |
3525 | break; | |
3526 | } | |
d983da9c DJ |
3527 | } |
3528 | ||
3529 | return 1; | |
3530 | } | |
3531 | ||
c906108c SS |
3532 | /* Possible return values for watchpoint_check (this can't be an enum |
3533 | because of check_errors). */ | |
3534 | /* The watchpoint has been deleted. */ | |
3535 | #define WP_DELETED 1 | |
3536 | /* The value has changed. */ | |
3537 | #define WP_VALUE_CHANGED 2 | |
3538 | /* The value has not changed. */ | |
3539 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
3540 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
3541 | #define WP_IGNORE 4 | |
c906108c SS |
3542 | |
3543 | #define BP_TEMPFLAG 1 | |
3544 | #define BP_HARDWAREFLAG 2 | |
3545 | ||
553e4c11 JB |
3546 | /* Evaluate watchpoint condition expression and check if its value changed. |
3547 | ||
3548 | P should be a pointer to struct bpstat, but is defined as a void * | |
3549 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
3550 | |
3551 | static int | |
4efb68b1 | 3552 | watchpoint_check (void *p) |
c906108c SS |
3553 | { |
3554 | bpstat bs = (bpstat) p; | |
3555 | struct breakpoint *b; | |
3556 | struct frame_info *fr; | |
3557 | int within_current_scope; | |
3558 | ||
4f8d1dc6 | 3559 | b = bs->breakpoint_at->owner; |
c906108c | 3560 | |
f6bc2008 PA |
3561 | /* If this is a local watchpoint, we only want to check if the |
3562 | watchpoint frame is in scope if the current thread is the thread | |
3563 | that was used to create the watchpoint. */ | |
3564 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 3565 | return WP_IGNORE; |
f6bc2008 | 3566 | |
c906108c SS |
3567 | if (b->exp_valid_block == NULL) |
3568 | within_current_scope = 1; | |
3569 | else | |
3570 | { | |
edb3359d DJ |
3571 | struct frame_info *frame = get_current_frame (); |
3572 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
3573 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
3574 | ||
a0f49112 JK |
3575 | /* in_function_epilogue_p() returns a non-zero value if we're still |
3576 | in the function but the stack frame has already been invalidated. | |
3577 | Since we can't rely on the values of local variables after the | |
3578 | stack has been destroyed, we are treating the watchpoint in that | |
3579 | state as `not changed' without further checking. Don't mark | |
3580 | watchpoints as changed if the current frame is in an epilogue - | |
3581 | even if they are in some other frame, our view of the stack | |
3582 | is likely to be wrong and frame_find_by_id could error out. */ | |
3583 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) | |
60e1c644 | 3584 | return WP_IGNORE; |
a0f49112 | 3585 | |
101dcfbe | 3586 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 3587 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
3588 | |
3589 | /* If we've gotten confused in the unwinder, we might have | |
3590 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
3591 | if (within_current_scope) |
3592 | { | |
3593 | struct symbol *function; | |
3594 | ||
3595 | function = get_frame_function (fr); | |
3596 | if (function == NULL | |
3597 | || !contained_in (b->exp_valid_block, | |
3598 | SYMBOL_BLOCK_VALUE (function))) | |
3599 | within_current_scope = 0; | |
3600 | } | |
69fbadd5 | 3601 | |
edb3359d | 3602 | if (within_current_scope) |
c906108c SS |
3603 | /* If we end up stopping, the current frame will get selected |
3604 | in normal_stop. So this call to select_frame won't affect | |
3605 | the user. */ | |
0f7d239c | 3606 | select_frame (fr); |
c906108c | 3607 | } |
c5aa993b | 3608 | |
c906108c SS |
3609 | if (within_current_scope) |
3610 | { | |
3611 | /* We use value_{,free_to_}mark because it could be a | |
3612 | *long* time before we return to the command level and | |
c5aa993b JM |
3613 | call free_all_values. We can't call free_all_values because |
3614 | we might be in the middle of evaluating a function call. */ | |
c906108c | 3615 | |
278cd55f | 3616 | struct value *mark = value_mark (); |
fa4727a6 DJ |
3617 | struct value *new_val; |
3618 | ||
3619 | fetch_watchpoint_value (b->exp, &new_val, NULL, NULL); | |
218d2fc6 TJB |
3620 | |
3621 | /* We use value_equal_contents instead of value_equal because the latter | |
3622 | coerces an array to a pointer, thus comparing just the address of the | |
3623 | array instead of its contents. This is not what we want. */ | |
fa4727a6 | 3624 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 3625 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 3626 | { |
fa4727a6 DJ |
3627 | if (new_val != NULL) |
3628 | { | |
3629 | release_value (new_val); | |
3630 | value_free_to_mark (mark); | |
3631 | } | |
c906108c SS |
3632 | bs->old_val = b->val; |
3633 | b->val = new_val; | |
fa4727a6 | 3634 | b->val_valid = 1; |
c906108c SS |
3635 | return WP_VALUE_CHANGED; |
3636 | } | |
3637 | else | |
3638 | { | |
60e1c644 | 3639 | /* Nothing changed. */ |
c906108c | 3640 | value_free_to_mark (mark); |
c906108c SS |
3641 | return WP_VALUE_NOT_CHANGED; |
3642 | } | |
3643 | } | |
3644 | else | |
3645 | { | |
3646 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
3647 | if we temporarily ignored the watchpoint, then when |
3648 | we reenter the block in which it is valid it contains | |
3649 | garbage (in the case of a function, it may have two | |
3650 | garbage values, one before and one after the prologue). | |
3651 | So we can't even detect the first assignment to it and | |
3652 | watch after that (since the garbage may or may not equal | |
3653 | the first value assigned). */ | |
4ce44c66 JM |
3654 | /* We print all the stop information in print_it_typical(), but |
3655 | in this case, by the time we call print_it_typical() this bp | |
3656 | will be deleted already. So we have no choice but print the | |
3657 | information here. */ | |
9dc5e2a9 | 3658 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3659 | ui_out_field_string |
3660 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 3661 | ui_out_text (uiout, "\nWatchpoint "); |
4f8d1dc6 | 3662 | ui_out_field_int (uiout, "wpnum", b->number); |
8b93c638 JM |
3663 | ui_out_text (uiout, " deleted because the program has left the block in\n\ |
3664 | which its expression is valid.\n"); | |
4ce44c66 | 3665 | |
c906108c | 3666 | if (b->related_breakpoint) |
60e1c644 PA |
3667 | { |
3668 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
3669 | b->related_breakpoint->related_breakpoint = NULL; | |
3670 | b->related_breakpoint = NULL; | |
3671 | } | |
b5de0fa7 | 3672 | b->disposition = disp_del_at_next_stop; |
c906108c SS |
3673 | |
3674 | return WP_DELETED; | |
3675 | } | |
3676 | } | |
3677 | ||
18a18393 VP |
3678 | /* Return true if it looks like target has stopped due to hitting |
3679 | breakpoint location BL. This function does not check if we | |
3680 | should stop, only if BL explains the stop. */ | |
3681 | static int | |
6c95b8df PA |
3682 | bpstat_check_location (const struct bp_location *bl, |
3683 | struct address_space *aspace, CORE_ADDR bp_addr) | |
18a18393 VP |
3684 | { |
3685 | struct breakpoint *b = bl->owner; | |
3686 | ||
e8595ef6 SS |
3687 | /* By definition, the inferior does not report stops at |
3688 | tracepoints. */ | |
7a697b8d | 3689 | if (tracepoint_type (b)) |
e8595ef6 SS |
3690 | return 0; |
3691 | ||
18a18393 VP |
3692 | if (b->type != bp_watchpoint |
3693 | && b->type != bp_hardware_watchpoint | |
3694 | && b->type != bp_read_watchpoint | |
3695 | && b->type != bp_access_watchpoint | |
3696 | && b->type != bp_hardware_breakpoint | |
fe798b75 | 3697 | && b->type != bp_catchpoint) /* a non-watchpoint bp */ |
18a18393 | 3698 | { |
6c95b8df PA |
3699 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
3700 | aspace, bp_addr)) | |
18a18393 VP |
3701 | return 0; |
3702 | if (overlay_debugging /* unmapped overlay section */ | |
3703 | && section_is_overlay (bl->section) | |
3704 | && !section_is_mapped (bl->section)) | |
3705 | return 0; | |
3706 | } | |
3707 | ||
3708 | /* Continuable hardware watchpoints are treated as non-existent if the | |
3709 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
3710 | some data address). Otherwise gdb won't stop on a break instruction | |
3711 | in the code (not from a breakpoint) when a hardware watchpoint has | |
3712 | been defined. Also skip watchpoints which we know did not trigger | |
3713 | (did not match the data address). */ | |
3714 | ||
3715 | if ((b->type == bp_hardware_watchpoint | |
3716 | || b->type == bp_read_watchpoint | |
3717 | || b->type == bp_access_watchpoint) | |
3718 | && b->watchpoint_triggered == watch_triggered_no) | |
3719 | return 0; | |
3720 | ||
3721 | if (b->type == bp_hardware_breakpoint) | |
3722 | { | |
3723 | if (bl->address != bp_addr) | |
3724 | return 0; | |
3725 | if (overlay_debugging /* unmapped overlay section */ | |
3726 | && section_is_overlay (bl->section) | |
3727 | && !section_is_mapped (bl->section)) | |
3728 | return 0; | |
3729 | } | |
ce78b96d | 3730 | |
ce78b96d JB |
3731 | if (b->type == bp_catchpoint) |
3732 | { | |
3733 | gdb_assert (b->ops != NULL && b->ops->breakpoint_hit != NULL); | |
3734 | if (!b->ops->breakpoint_hit (b)) | |
3735 | return 0; | |
3736 | } | |
3737 | ||
18a18393 VP |
3738 | return 1; |
3739 | } | |
3740 | ||
3741 | /* If BS refers to a watchpoint, determine if the watched values | |
3742 | has actually changed, and we should stop. If not, set BS->stop | |
3743 | to 0. */ | |
3744 | static void | |
3745 | bpstat_check_watchpoint (bpstat bs) | |
3746 | { | |
3747 | const struct bp_location *bl = bs->breakpoint_at; | |
3748 | struct breakpoint *b = bl->owner; | |
3749 | ||
3750 | if (b->type == bp_watchpoint | |
3751 | || b->type == bp_read_watchpoint | |
3752 | || b->type == bp_access_watchpoint | |
3753 | || b->type == bp_hardware_watchpoint) | |
3754 | { | |
3755 | CORE_ADDR addr; | |
3756 | struct value *v; | |
3757 | int must_check_value = 0; | |
3758 | ||
3759 | if (b->type == bp_watchpoint) | |
3760 | /* For a software watchpoint, we must always check the | |
3761 | watched value. */ | |
3762 | must_check_value = 1; | |
3763 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
3764 | /* We have a hardware watchpoint (read, write, or access) | |
3765 | and the target earlier reported an address watched by | |
3766 | this watchpoint. */ | |
3767 | must_check_value = 1; | |
3768 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3769 | && b->type == bp_hardware_watchpoint) | |
3770 | /* We were stopped by a hardware watchpoint, but the target could | |
3771 | not report the data address. We must check the watchpoint's | |
3772 | value. Access and read watchpoints are out of luck; without | |
3773 | a data address, we can't figure it out. */ | |
3774 | must_check_value = 1; | |
3775 | ||
3776 | if (must_check_value) | |
3777 | { | |
3778 | char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3779 | b->number); | |
3780 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
3781 | int e = catch_errors (watchpoint_check, bs, message, | |
3782 | RETURN_MASK_ALL); | |
3783 | do_cleanups (cleanups); | |
3784 | switch (e) | |
3785 | { | |
3786 | case WP_DELETED: | |
3787 | /* We've already printed what needs to be printed. */ | |
3788 | bs->print_it = print_it_done; | |
3789 | /* Stop. */ | |
3790 | break; | |
60e1c644 PA |
3791 | case WP_IGNORE: |
3792 | bs->print_it = print_it_noop; | |
3793 | bs->stop = 0; | |
3794 | break; | |
18a18393 VP |
3795 | case WP_VALUE_CHANGED: |
3796 | if (b->type == bp_read_watchpoint) | |
3797 | { | |
85d721b8 PA |
3798 | /* There are two cases to consider here: |
3799 | ||
3800 | 1. we're watching the triggered memory for reads. | |
3801 | In that case, trust the target, and always report | |
3802 | the watchpoint hit to the user. Even though | |
3803 | reads don't cause value changes, the value may | |
3804 | have changed since the last time it was read, and | |
3805 | since we're not trapping writes, we will not see | |
3806 | those, and as such we should ignore our notion of | |
3807 | old value. | |
3808 | ||
3809 | 2. we're watching the triggered memory for both | |
3810 | reads and writes. There are two ways this may | |
3811 | happen: | |
3812 | ||
3813 | 2.1. this is a target that can't break on data | |
3814 | reads only, but can break on accesses (reads or | |
3815 | writes), such as e.g., x86. We detect this case | |
3816 | at the time we try to insert read watchpoints. | |
3817 | ||
3818 | 2.2. otherwise, the target supports read | |
3819 | watchpoints, but, the user set an access or write | |
3820 | watchpoint watching the same memory as this read | |
3821 | watchpoint. | |
3822 | ||
3823 | If we're watching memory writes as well as reads, | |
3824 | ignore watchpoint hits when we find that the | |
3825 | value hasn't changed, as reads don't cause | |
3826 | changes. This still gives false positives when | |
3827 | the program writes the same value to memory as | |
3828 | what there was already in memory (we will confuse | |
3829 | it for a read), but it's much better than | |
3830 | nothing. */ | |
3831 | ||
3832 | int other_write_watchpoint = 0; | |
3833 | ||
3834 | if (bl->watchpoint_type == hw_read) | |
3835 | { | |
3836 | struct breakpoint *other_b; | |
3837 | ||
3838 | ALL_BREAKPOINTS (other_b) | |
3839 | if ((other_b->type == bp_hardware_watchpoint | |
3840 | || other_b->type == bp_access_watchpoint) | |
3841 | && (other_b->watchpoint_triggered | |
3842 | == watch_triggered_yes)) | |
3843 | { | |
3844 | other_write_watchpoint = 1; | |
3845 | break; | |
3846 | } | |
3847 | } | |
3848 | ||
3849 | if (other_write_watchpoint | |
3850 | || bl->watchpoint_type == hw_access) | |
3851 | { | |
3852 | /* We're watching the same memory for writes, | |
3853 | and the value changed since the last time we | |
3854 | updated it, so this trap must be for a write. | |
3855 | Ignore it. */ | |
3856 | bs->print_it = print_it_noop; | |
3857 | bs->stop = 0; | |
3858 | } | |
18a18393 VP |
3859 | } |
3860 | break; | |
3861 | case WP_VALUE_NOT_CHANGED: | |
3862 | if (b->type == bp_hardware_watchpoint | |
3863 | || b->type == bp_watchpoint) | |
3864 | { | |
3865 | /* Don't stop: write watchpoints shouldn't fire if | |
3866 | the value hasn't changed. */ | |
3867 | bs->print_it = print_it_noop; | |
3868 | bs->stop = 0; | |
3869 | } | |
3870 | /* Stop. */ | |
3871 | break; | |
3872 | default: | |
3873 | /* Can't happen. */ | |
3874 | case 0: | |
3875 | /* Error from catch_errors. */ | |
3876 | printf_filtered (_("Watchpoint %d deleted.\n"), b->number); | |
3877 | if (b->related_breakpoint) | |
3878 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
3879 | b->disposition = disp_del_at_next_stop; | |
3880 | /* We've already printed what needs to be printed. */ | |
3881 | bs->print_it = print_it_done; | |
3882 | break; | |
3883 | } | |
3884 | } | |
3885 | else /* must_check_value == 0 */ | |
3886 | { | |
3887 | /* This is a case where some watchpoint(s) triggered, but | |
3888 | not at the address of this watchpoint, or else no | |
3889 | watchpoint triggered after all. So don't print | |
3890 | anything for this watchpoint. */ | |
3891 | bs->print_it = print_it_noop; | |
3892 | bs->stop = 0; | |
3893 | } | |
3894 | } | |
3895 | } | |
3896 | ||
3897 | ||
3898 | /* Check conditions (condition proper, frame, thread and ignore count) | |
3899 | of breakpoint referred to by BS. If we should not stop for this | |
3900 | breakpoint, set BS->stop to 0. */ | |
3901 | static void | |
3902 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
3903 | { | |
3904 | int thread_id = pid_to_thread_id (ptid); | |
3905 | const struct bp_location *bl = bs->breakpoint_at; | |
3906 | struct breakpoint *b = bl->owner; | |
3907 | ||
3908 | if (frame_id_p (b->frame_id) | |
edb3359d | 3909 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 VP |
3910 | bs->stop = 0; |
3911 | else if (bs->stop) | |
3912 | { | |
3913 | int value_is_zero = 0; | |
60e1c644 PA |
3914 | struct expression *cond; |
3915 | ||
18a18393 VP |
3916 | /* If this is a scope breakpoint, mark the associated |
3917 | watchpoint as triggered so that we will handle the | |
3918 | out-of-scope event. We'll get to the watchpoint next | |
3919 | iteration. */ | |
3920 | if (b->type == bp_watchpoint_scope) | |
3921 | b->related_breakpoint->watchpoint_triggered = watch_triggered_yes; | |
60e1c644 PA |
3922 | |
3923 | if (is_watchpoint (b)) | |
3924 | cond = b->cond_exp; | |
3925 | else | |
3926 | cond = bl->cond; | |
3927 | ||
3928 | if (cond && bl->owner->disposition != disp_del_at_next_stop) | |
18a18393 | 3929 | { |
60e1c644 PA |
3930 | int within_current_scope = 1; |
3931 | ||
c5bc3a77 DJ |
3932 | /* We use value_mark and value_free_to_mark because it could |
3933 | be a long time before we return to the command level and | |
3934 | call free_all_values. We can't call free_all_values | |
3935 | because we might be in the middle of evaluating a | |
3936 | function call. */ | |
3937 | struct value *mark = value_mark (); | |
3938 | ||
edb3359d DJ |
3939 | /* Need to select the frame, with all that implies so that |
3940 | the conditions will have the right context. Because we | |
3941 | use the frame, we will not see an inlined function's | |
3942 | variables when we arrive at a breakpoint at the start | |
3943 | of the inlined function; the current frame will be the | |
3944 | call site. */ | |
60e1c644 PA |
3945 | if (!is_watchpoint (b) || b->cond_exp_valid_block == NULL) |
3946 | select_frame (get_current_frame ()); | |
3947 | else | |
3948 | { | |
3949 | struct frame_info *frame; | |
3950 | ||
3951 | /* For local watchpoint expressions, which particular | |
3952 | instance of a local is being watched matters, so we | |
3953 | keep track of the frame to evaluate the expression | |
3954 | in. To evaluate the condition however, it doesn't | |
3955 | really matter which instantiation of the function | |
3956 | where the condition makes sense triggers the | |
3957 | watchpoint. This allows an expression like "watch | |
3958 | global if q > 10" set in `func', catch writes to | |
3959 | global on all threads that call `func', or catch | |
3960 | writes on all recursive calls of `func' by a single | |
3961 | thread. We simply always evaluate the condition in | |
3962 | the innermost frame that's executing where it makes | |
3963 | sense to evaluate the condition. It seems | |
3964 | intuitive. */ | |
3965 | frame = block_innermost_frame (b->cond_exp_valid_block); | |
3966 | if (frame != NULL) | |
3967 | select_frame (frame); | |
3968 | else | |
3969 | within_current_scope = 0; | |
3970 | } | |
3971 | if (within_current_scope) | |
3972 | value_is_zero | |
3973 | = catch_errors (breakpoint_cond_eval, cond, | |
3974 | "Error in testing breakpoint condition:\n", | |
3975 | RETURN_MASK_ALL); | |
3976 | else | |
3977 | { | |
3978 | warning (_("Watchpoint condition cannot be tested " | |
3979 | "in the current scope")); | |
3980 | /* If we failed to set the right context for this | |
3981 | watchpoint, unconditionally report it. */ | |
3982 | value_is_zero = 0; | |
3983 | } | |
18a18393 | 3984 | /* FIXME-someday, should give breakpoint # */ |
c5bc3a77 | 3985 | value_free_to_mark (mark); |
18a18393 | 3986 | } |
60e1c644 PA |
3987 | |
3988 | if (cond && value_is_zero) | |
18a18393 VP |
3989 | { |
3990 | bs->stop = 0; | |
3991 | } | |
3992 | else if (b->thread != -1 && b->thread != thread_id) | |
3993 | { | |
3994 | bs->stop = 0; | |
3995 | } | |
3996 | else if (b->ignore_count > 0) | |
3997 | { | |
3998 | b->ignore_count--; | |
3999 | annotate_ignore_count_change (); | |
4000 | bs->stop = 0; | |
4001 | /* Increase the hit count even though we don't | |
4002 | stop. */ | |
4003 | ++(b->hit_count); | |
4004 | } | |
4005 | } | |
4006 | } | |
4007 | ||
4008 | ||
9709f61c | 4009 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 4010 | BP_ADDR in thread PTID. |
c906108c | 4011 | |
d983da9c | 4012 | Determine whether we stopped at a breakpoint, etc, or whether we |
c906108c SS |
4013 | don't understand this stop. Result is a chain of bpstat's such that: |
4014 | ||
c5aa993b | 4015 | if we don't understand the stop, the result is a null pointer. |
c906108c | 4016 | |
c5aa993b | 4017 | if we understand why we stopped, the result is not null. |
c906108c | 4018 | |
c5aa993b JM |
4019 | Each element of the chain refers to a particular breakpoint or |
4020 | watchpoint at which we have stopped. (We may have stopped for | |
4021 | several reasons concurrently.) | |
c906108c | 4022 | |
c5aa993b JM |
4023 | Each element of the chain has valid next, breakpoint_at, |
4024 | commands, FIXME??? fields. */ | |
c906108c SS |
4025 | |
4026 | bpstat | |
6c95b8df PA |
4027 | bpstat_stop_status (struct address_space *aspace, |
4028 | CORE_ADDR bp_addr, ptid_t ptid) | |
c906108c | 4029 | { |
0d381245 | 4030 | struct breakpoint *b = NULL; |
876fa593 | 4031 | struct bp_location *bl, **blp_tmp; |
20874c92 | 4032 | struct bp_location *loc; |
c906108c SS |
4033 | /* Root of the chain of bpstat's */ |
4034 | struct bpstats root_bs[1]; | |
4035 | /* Pointer to the last thing in the chain currently. */ | |
4036 | bpstat bs = root_bs; | |
20874c92 | 4037 | int ix; |
429374b8 | 4038 | int need_remove_insert; |
c906108c | 4039 | |
429374b8 JK |
4040 | /* ALL_BP_LOCATIONS iteration would break across |
4041 | update_global_location_list possibly executed by | |
4042 | bpstat_check_breakpoint_conditions's inferior call. */ | |
c5aa993b | 4043 | |
429374b8 JK |
4044 | ALL_BREAKPOINTS (b) |
4045 | { | |
4046 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) | |
4047 | continue; | |
a5606eee | 4048 | |
429374b8 JK |
4049 | for (bl = b->loc; bl != NULL; bl = bl->next) |
4050 | { | |
4051 | /* For hardware watchpoints, we look only at the first location. | |
4052 | The watchpoint_check function will work on entire expression, | |
4053 | not the individual locations. For read watchopints, the | |
4054 | watchpoints_triggered function have checked all locations | |
4055 | already. */ | |
4056 | if (b->type == bp_hardware_watchpoint && bl != b->loc) | |
4057 | break; | |
18a18393 | 4058 | |
429374b8 JK |
4059 | if (bl->shlib_disabled) |
4060 | continue; | |
c5aa993b | 4061 | |
429374b8 JK |
4062 | if (!bpstat_check_location (bl, aspace, bp_addr)) |
4063 | continue; | |
c5aa993b | 4064 | |
429374b8 | 4065 | /* Come here if it's a watchpoint, or if the break address matches */ |
c5aa993b | 4066 | |
429374b8 | 4067 | bs = bpstat_alloc (bl, bs); /* Alloc a bpstat to explain stop */ |
c5aa993b | 4068 | |
429374b8 JK |
4069 | /* Assume we stop. Should we find watchpoint that is not actually |
4070 | triggered, or if condition of breakpoint is false, we'll reset | |
4071 | 'stop' to 0. */ | |
4072 | bs->stop = 1; | |
4073 | bs->print = 1; | |
d983da9c | 4074 | |
429374b8 JK |
4075 | bpstat_check_watchpoint (bs); |
4076 | if (!bs->stop) | |
4077 | continue; | |
18a18393 | 4078 | |
429374b8 | 4079 | if (b->type == bp_thread_event || b->type == bp_overlay_event |
aa7d318d TT |
4080 | || b->type == bp_longjmp_master |
4081 | || b->type == bp_std_terminate_master) | |
429374b8 JK |
4082 | /* We do not stop for these. */ |
4083 | bs->stop = 0; | |
4084 | else | |
4085 | bpstat_check_breakpoint_conditions (bs, ptid); | |
4086 | ||
4087 | if (bs->stop) | |
4088 | { | |
4089 | ++(b->hit_count); | |
c906108c | 4090 | |
429374b8 JK |
4091 | /* We will stop here */ |
4092 | if (b->disposition == disp_disable) | |
4093 | { | |
4094 | if (b->enable_state != bp_permanent) | |
4095 | b->enable_state = bp_disabled; | |
4096 | update_global_location_list (0); | |
4097 | } | |
4098 | if (b->silent) | |
4099 | bs->print = 0; | |
4100 | bs->commands = b->commands; | |
9add0f1b TT |
4101 | incref_counted_command_line (bs->commands); |
4102 | bs->commands_left = bs->commands ? bs->commands->commands : NULL; | |
4103 | if (bs->commands_left | |
4104 | && (strcmp ("silent", bs->commands_left->line) == 0 | |
4105 | || (xdb_commands | |
4106 | && strcmp ("Q", | |
4107 | bs->commands_left->line) == 0))) | |
429374b8 | 4108 | { |
9add0f1b | 4109 | bs->commands_left = bs->commands_left->next; |
429374b8 JK |
4110 | bs->print = 0; |
4111 | } | |
429374b8 JK |
4112 | } |
4113 | ||
4114 | /* Print nothing for this entry if we dont stop or dont print. */ | |
4115 | if (bs->stop == 0 || bs->print == 0) | |
4116 | bs->print_it = print_it_noop; | |
4117 | } | |
4118 | } | |
876fa593 | 4119 | |
20874c92 VP |
4120 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
4121 | { | |
6c95b8df PA |
4122 | if (breakpoint_address_match (loc->pspace->aspace, loc->address, |
4123 | aspace, bp_addr)) | |
20874c92 VP |
4124 | { |
4125 | bs = bpstat_alloc (loc, bs); | |
4126 | /* For hits of moribund locations, we should just proceed. */ | |
4127 | bs->stop = 0; | |
4128 | bs->print = 0; | |
4129 | bs->print_it = print_it_noop; | |
4130 | } | |
4131 | } | |
4132 | ||
c906108c | 4133 | bs->next = NULL; /* Terminate the chain */ |
c906108c | 4134 | |
d983da9c DJ |
4135 | /* If we aren't stopping, the value of some hardware watchpoint may |
4136 | not have changed, but the intermediate memory locations we are | |
4137 | watching may have. Don't bother if we're stopping; this will get | |
4138 | done later. */ | |
4139 | for (bs = root_bs->next; bs != NULL; bs = bs->next) | |
4140 | if (bs->stop) | |
4141 | break; | |
4142 | ||
d832cb68 | 4143 | need_remove_insert = 0; |
d983da9c DJ |
4144 | if (bs == NULL) |
4145 | for (bs = root_bs->next; bs != NULL; bs = bs->next) | |
4146 | if (!bs->stop | |
20874c92 | 4147 | && bs->breakpoint_at->owner |
2d134ed3 | 4148 | && is_hardware_watchpoint (bs->breakpoint_at->owner)) |
d983da9c | 4149 | { |
2d134ed3 PA |
4150 | update_watchpoint (bs->breakpoint_at->owner, 0 /* don't reparse. */); |
4151 | /* Updating watchpoints invalidates bs->breakpoint_at. | |
4152 | Prevent further code from trying to use it. */ | |
a5606eee | 4153 | bs->breakpoint_at = NULL; |
d832cb68 | 4154 | need_remove_insert = 1; |
d983da9c DJ |
4155 | } |
4156 | ||
d832cb68 | 4157 | if (need_remove_insert) |
2d134ed3 | 4158 | update_global_location_list (1); |
d832cb68 | 4159 | |
d983da9c | 4160 | return root_bs->next; |
c906108c SS |
4161 | } |
4162 | \f | |
4163 | /* Tell what to do about this bpstat. */ | |
4164 | struct bpstat_what | |
fba45db2 | 4165 | bpstat_what (bpstat bs) |
c906108c SS |
4166 | { |
4167 | /* Classify each bpstat as one of the following. */ | |
c5aa993b JM |
4168 | enum class |
4169 | { | |
4170 | /* This bpstat element has no effect on the main_action. */ | |
4171 | no_effect = 0, | |
4172 | ||
4173 | /* There was a watchpoint, stop but don't print. */ | |
4174 | wp_silent, | |
c906108c | 4175 | |
c5aa993b JM |
4176 | /* There was a watchpoint, stop and print. */ |
4177 | wp_noisy, | |
c906108c | 4178 | |
c5aa993b JM |
4179 | /* There was a breakpoint but we're not stopping. */ |
4180 | bp_nostop, | |
c906108c | 4181 | |
c5aa993b JM |
4182 | /* There was a breakpoint, stop but don't print. */ |
4183 | bp_silent, | |
c906108c | 4184 | |
c5aa993b JM |
4185 | /* There was a breakpoint, stop and print. */ |
4186 | bp_noisy, | |
c906108c | 4187 | |
c5aa993b JM |
4188 | /* We hit the longjmp breakpoint. */ |
4189 | long_jump, | |
c906108c | 4190 | |
c5aa993b JM |
4191 | /* We hit the longjmp_resume breakpoint. */ |
4192 | long_resume, | |
c906108c | 4193 | |
c5aa993b JM |
4194 | /* We hit the step_resume breakpoint. */ |
4195 | step_resume, | |
c906108c | 4196 | |
c5aa993b JM |
4197 | /* We hit the shared library event breakpoint. */ |
4198 | shlib_event, | |
c906108c | 4199 | |
4efc6507 DE |
4200 | /* We hit the jit event breakpoint. */ |
4201 | jit_event, | |
4202 | ||
c5aa993b JM |
4203 | /* This is just used to count how many enums there are. */ |
4204 | class_last | |
c906108c SS |
4205 | }; |
4206 | ||
4207 | /* Here is the table which drives this routine. So that we can | |
4208 | format it pretty, we define some abbreviations for the | |
4209 | enum bpstat_what codes. */ | |
4210 | #define kc BPSTAT_WHAT_KEEP_CHECKING | |
4211 | #define ss BPSTAT_WHAT_STOP_SILENT | |
4212 | #define sn BPSTAT_WHAT_STOP_NOISY | |
4213 | #define sgl BPSTAT_WHAT_SINGLE | |
4214 | #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME | |
4215 | #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME | |
c906108c | 4216 | #define sr BPSTAT_WHAT_STEP_RESUME |
c906108c | 4217 | #define shl BPSTAT_WHAT_CHECK_SHLIBS |
4efc6507 | 4218 | #define jit BPSTAT_WHAT_CHECK_JIT |
c906108c SS |
4219 | |
4220 | /* "Can't happen." Might want to print an error message. | |
4221 | abort() is not out of the question, but chances are GDB is just | |
4222 | a bit confused, not unusable. */ | |
4223 | #define err BPSTAT_WHAT_STOP_NOISY | |
4224 | ||
4225 | /* Given an old action and a class, come up with a new action. */ | |
4226 | /* One interesting property of this table is that wp_silent is the same | |
4227 | as bp_silent and wp_noisy is the same as bp_noisy. That is because | |
4228 | after stopping, the check for whether to step over a breakpoint | |
4229 | (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without | |
53a5351d JM |
4230 | reference to how we stopped. We retain separate wp_silent and |
4231 | bp_silent codes in case we want to change that someday. | |
43ff13b4 JM |
4232 | |
4233 | Another possibly interesting property of this table is that | |
4234 | there's a partial ordering, priority-like, of the actions. Once | |
4235 | you've decided that some action is appropriate, you'll never go | |
4236 | back and decide something of a lower priority is better. The | |
4237 | ordering is: | |
4238 | ||
4efc6507 DE |
4239 | kc < jit clr sgl shl slr sn sr ss |
4240 | sgl < jit shl slr sn sr ss | |
4241 | slr < jit err shl sn sr ss | |
4242 | clr < jit err shl sn sr ss | |
4243 | ss < jit shl sn sr | |
4244 | sn < jit shl sr | |
4245 | jit < shl sr | |
d81191fc | 4246 | shl < sr |
4d5b2cd7 | 4247 | sr < |
c5aa993b | 4248 | |
43ff13b4 JM |
4249 | What I think this means is that we don't need a damned table |
4250 | here. If you just put the rows and columns in the right order, | |
4251 | it'd look awfully regular. We could simply walk the bpstat list | |
4252 | and choose the highest priority action we find, with a little | |
78b6a731 | 4253 | logic to handle the 'err' cases. */ |
c906108c SS |
4254 | |
4255 | /* step_resume entries: a step resume breakpoint overrides another | |
4256 | breakpoint of signal handling (see comment in wait_for_inferior | |
fcf70625 | 4257 | at where we set the step_resume breakpoint). */ |
c906108c SS |
4258 | |
4259 | static const enum bpstat_what_main_action | |
c5aa993b JM |
4260 | table[(int) class_last][(int) BPSTAT_WHAT_LAST] = |
4261 | { | |
4262 | /* old action */ | |
4efc6507 DE |
4263 | /* kc ss sn sgl slr clr sr shl jit */ |
4264 | /* no_effect */ {kc, ss, sn, sgl, slr, clr, sr, shl, jit}, | |
4265 | /* wp_silent */ {ss, ss, sn, ss, ss, ss, sr, shl, jit}, | |
4266 | /* wp_noisy */ {sn, sn, sn, sn, sn, sn, sr, shl, jit}, | |
4267 | /* bp_nostop */ {sgl, ss, sn, sgl, slr, slr, sr, shl, jit}, | |
4268 | /* bp_silent */ {ss, ss, sn, ss, ss, ss, sr, shl, jit}, | |
4269 | /* bp_noisy */ {sn, sn, sn, sn, sn, sn, sr, shl, jit}, | |
4270 | /* long_jump */ {slr, ss, sn, slr, slr, err, sr, shl, jit}, | |
4271 | /* long_resume */ {clr, ss, sn, err, err, err, sr, shl, jit}, | |
4272 | /* step_resume */ {sr, sr, sr, sr, sr, sr, sr, sr, sr }, | |
4273 | /* shlib */ {shl, shl, shl, shl, shl, shl, sr, shl, shl}, | |
4274 | /* jit_event */ {jit, jit, jit, jit, jit, jit, sr, jit, jit} | |
c5aa993b | 4275 | }; |
c906108c SS |
4276 | |
4277 | #undef kc | |
4278 | #undef ss | |
4279 | #undef sn | |
4280 | #undef sgl | |
4281 | #undef slr | |
4282 | #undef clr | |
c906108c SS |
4283 | #undef err |
4284 | #undef sr | |
4285 | #undef ts | |
4286 | #undef shl | |
4efc6507 | 4287 | #undef jit |
c906108c SS |
4288 | enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING; |
4289 | struct bpstat_what retval; | |
4290 | ||
aa7d318d | 4291 | retval.call_dummy = STOP_NONE; |
c906108c SS |
4292 | for (; bs != NULL; bs = bs->next) |
4293 | { | |
4294 | enum class bs_class = no_effect; | |
4295 | if (bs->breakpoint_at == NULL) | |
4296 | /* I suspect this can happen if it was a momentary breakpoint | |
4297 | which has since been deleted. */ | |
4298 | continue; | |
20874c92 VP |
4299 | if (bs->breakpoint_at->owner == NULL) |
4300 | bs_class = bp_nostop; | |
4301 | else | |
4f8d1dc6 | 4302 | switch (bs->breakpoint_at->owner->type) |
c906108c SS |
4303 | { |
4304 | case bp_none: | |
4305 | continue; | |
4306 | ||
4307 | case bp_breakpoint: | |
4308 | case bp_hardware_breakpoint: | |
4309 | case bp_until: | |
4310 | case bp_finish: | |
4311 | if (bs->stop) | |
4312 | { | |
4313 | if (bs->print) | |
4314 | bs_class = bp_noisy; | |
4315 | else | |
4316 | bs_class = bp_silent; | |
4317 | } | |
4318 | else | |
4319 | bs_class = bp_nostop; | |
4320 | break; | |
4321 | case bp_watchpoint: | |
4322 | case bp_hardware_watchpoint: | |
4323 | case bp_read_watchpoint: | |
4324 | case bp_access_watchpoint: | |
4325 | if (bs->stop) | |
4326 | { | |
4327 | if (bs->print) | |
4328 | bs_class = wp_noisy; | |
4329 | else | |
4330 | bs_class = wp_silent; | |
4331 | } | |
4332 | else | |
53a5351d JM |
4333 | /* There was a watchpoint, but we're not stopping. |
4334 | This requires no further action. */ | |
c906108c SS |
4335 | bs_class = no_effect; |
4336 | break; | |
4337 | case bp_longjmp: | |
4338 | bs_class = long_jump; | |
4339 | break; | |
4340 | case bp_longjmp_resume: | |
4341 | bs_class = long_resume; | |
4342 | break; | |
4343 | case bp_step_resume: | |
4344 | if (bs->stop) | |
4345 | { | |
4346 | bs_class = step_resume; | |
4347 | } | |
4348 | else | |
4349 | /* It is for the wrong frame. */ | |
4350 | bs_class = bp_nostop; | |
4351 | break; | |
c906108c SS |
4352 | case bp_watchpoint_scope: |
4353 | bs_class = bp_nostop; | |
4354 | break; | |
c5aa993b JM |
4355 | case bp_shlib_event: |
4356 | bs_class = shlib_event; | |
4357 | break; | |
4efc6507 DE |
4358 | case bp_jit_event: |
4359 | bs_class = jit_event; | |
4360 | break; | |
c4093a6a | 4361 | case bp_thread_event: |
1900040c | 4362 | case bp_overlay_event: |
0fd8e87f | 4363 | case bp_longjmp_master: |
aa7d318d | 4364 | case bp_std_terminate_master: |
c4093a6a JM |
4365 | bs_class = bp_nostop; |
4366 | break; | |
ce78b96d | 4367 | case bp_catchpoint: |
c5aa993b JM |
4368 | if (bs->stop) |
4369 | { | |
4370 | if (bs->print) | |
4371 | bs_class = bp_noisy; | |
4372 | else | |
4373 | bs_class = bp_silent; | |
4374 | } | |
4375 | else | |
53a5351d JM |
4376 | /* There was a catchpoint, but we're not stopping. |
4377 | This requires no further action. */ | |
c5aa993b JM |
4378 | bs_class = no_effect; |
4379 | break; | |
c906108c | 4380 | case bp_call_dummy: |
53a5351d JM |
4381 | /* Make sure the action is stop (silent or noisy), |
4382 | so infrun.c pops the dummy frame. */ | |
c906108c | 4383 | bs_class = bp_silent; |
aa7d318d TT |
4384 | retval.call_dummy = STOP_STACK_DUMMY; |
4385 | break; | |
4386 | case bp_std_terminate: | |
4387 | /* Make sure the action is stop (silent or noisy), | |
4388 | so infrun.c pops the dummy frame. */ | |
4389 | bs_class = bp_silent; | |
4390 | retval.call_dummy = STOP_STD_TERMINATE; | |
c906108c | 4391 | break; |
1042e4c0 | 4392 | case bp_tracepoint: |
7a697b8d | 4393 | case bp_fast_tracepoint: |
1042e4c0 SS |
4394 | /* Tracepoint hits should not be reported back to GDB, and |
4395 | if one got through somehow, it should have been filtered | |
4396 | out already. */ | |
4397 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 4398 | _("bpstat_what: tracepoint encountered")); |
1042e4c0 | 4399 | break; |
c906108c | 4400 | } |
c5aa993b | 4401 | current_action = table[(int) bs_class][(int) current_action]; |
c906108c SS |
4402 | } |
4403 | retval.main_action = current_action; | |
4404 | return retval; | |
4405 | } | |
4406 | ||
4407 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
4408 | without hardware support). This isn't related to a specific bpstat, | |
4409 | just to things like whether watchpoints are set. */ | |
4410 | ||
c5aa993b | 4411 | int |
fba45db2 | 4412 | bpstat_should_step (void) |
c906108c SS |
4413 | { |
4414 | struct breakpoint *b; | |
4415 | ALL_BREAKPOINTS (b) | |
717a8278 | 4416 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 4417 | return 1; |
c906108c SS |
4418 | return 0; |
4419 | } | |
4420 | ||
67822962 PA |
4421 | int |
4422 | bpstat_causes_stop (bpstat bs) | |
4423 | { | |
4424 | for (; bs != NULL; bs = bs->next) | |
4425 | if (bs->stop) | |
4426 | return 1; | |
4427 | ||
4428 | return 0; | |
4429 | } | |
4430 | ||
c906108c | 4431 | \f |
c5aa993b | 4432 | |
859825b8 JK |
4433 | /* Print the LOC location out of the list of B->LOC locations. */ |
4434 | ||
0d381245 VP |
4435 | static void print_breakpoint_location (struct breakpoint *b, |
4436 | struct bp_location *loc, | |
4437 | char *wrap_indent, | |
4438 | struct ui_stream *stb) | |
4439 | { | |
6c95b8df PA |
4440 | struct cleanup *old_chain = save_current_program_space (); |
4441 | ||
859825b8 JK |
4442 | if (loc != NULL && loc->shlib_disabled) |
4443 | loc = NULL; | |
4444 | ||
6c95b8df PA |
4445 | if (loc != NULL) |
4446 | set_current_program_space (loc->pspace); | |
4447 | ||
859825b8 | 4448 | if (b->source_file && loc) |
0d381245 VP |
4449 | { |
4450 | struct symbol *sym | |
4451 | = find_pc_sect_function (loc->address, loc->section); | |
4452 | if (sym) | |
4453 | { | |
4454 | ui_out_text (uiout, "in "); | |
4455 | ui_out_field_string (uiout, "func", | |
4456 | SYMBOL_PRINT_NAME (sym)); | |
4457 | ui_out_wrap_hint (uiout, wrap_indent); | |
4458 | ui_out_text (uiout, " at "); | |
4459 | } | |
4460 | ui_out_field_string (uiout, "file", b->source_file); | |
4461 | ui_out_text (uiout, ":"); | |
4462 | ||
4463 | if (ui_out_is_mi_like_p (uiout)) | |
4464 | { | |
4465 | struct symtab_and_line sal = find_pc_line (loc->address, 0); | |
4466 | char *fullname = symtab_to_fullname (sal.symtab); | |
4467 | ||
4468 | if (fullname) | |
4469 | ui_out_field_string (uiout, "fullname", fullname); | |
4470 | } | |
4471 | ||
4472 | ui_out_field_int (uiout, "line", b->line_number); | |
4473 | } | |
859825b8 | 4474 | else if (loc) |
0d381245 | 4475 | { |
22e722e1 DJ |
4476 | print_address_symbolic (loc->gdbarch, loc->address, stb->stream, |
4477 | demangle, ""); | |
0d381245 VP |
4478 | ui_out_field_stream (uiout, "at", stb); |
4479 | } | |
859825b8 JK |
4480 | else |
4481 | ui_out_field_string (uiout, "pending", b->addr_string); | |
6c95b8df PA |
4482 | |
4483 | do_cleanups (old_chain); | |
0d381245 VP |
4484 | } |
4485 | ||
c4093a6a | 4486 | /* Print B to gdb_stdout. */ |
c906108c | 4487 | static void |
0d381245 VP |
4488 | print_one_breakpoint_location (struct breakpoint *b, |
4489 | struct bp_location *loc, | |
4490 | int loc_number, | |
a6d9a66e | 4491 | struct bp_location **last_loc, |
6c95b8df PA |
4492 | int print_address_bits, |
4493 | int allflag) | |
c906108c | 4494 | { |
52f0bd74 AC |
4495 | struct command_line *l; |
4496 | struct symbol *sym; | |
c4093a6a JM |
4497 | struct ep_type_description |
4498 | { | |
4499 | enum bptype type; | |
4500 | char *description; | |
4501 | }; | |
4502 | static struct ep_type_description bptypes[] = | |
c906108c | 4503 | { |
c5aa993b JM |
4504 | {bp_none, "?deleted?"}, |
4505 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 4506 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
4507 | {bp_until, "until"}, |
4508 | {bp_finish, "finish"}, | |
4509 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 4510 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
4511 | {bp_read_watchpoint, "read watchpoint"}, |
4512 | {bp_access_watchpoint, "acc watchpoint"}, | |
4513 | {bp_longjmp, "longjmp"}, | |
4514 | {bp_longjmp_resume, "longjmp resume"}, | |
4515 | {bp_step_resume, "step resume"}, | |
c5aa993b JM |
4516 | {bp_watchpoint_scope, "watchpoint scope"}, |
4517 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 4518 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 4519 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 4520 | {bp_thread_event, "thread events"}, |
1900040c | 4521 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 4522 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 4523 | {bp_std_terminate_master, "std::terminate master"}, |
ce78b96d | 4524 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 4525 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 4526 | {bp_fast_tracepoint, "fast tracepoint"}, |
4efc6507 | 4527 | {bp_jit_event, "jit events"}, |
c5aa993b | 4528 | }; |
c4093a6a | 4529 | |
c2c6d25f | 4530 | static char bpenables[] = "nynny"; |
c906108c | 4531 | char wrap_indent[80]; |
8b93c638 JM |
4532 | struct ui_stream *stb = ui_out_stream_new (uiout); |
4533 | struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb); | |
3b31d625 | 4534 | struct cleanup *bkpt_chain; |
c906108c | 4535 | |
0d381245 VP |
4536 | int header_of_multiple = 0; |
4537 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
4538 | struct value_print_options opts; |
4539 | ||
4540 | get_user_print_options (&opts); | |
0d381245 VP |
4541 | |
4542 | gdb_assert (!loc || loc_number != 0); | |
4543 | /* See comment in print_one_breakpoint concerning | |
4544 | treatment of breakpoints with single disabled | |
4545 | location. */ | |
4546 | if (loc == NULL | |
4547 | && (b->loc != NULL | |
4548 | && (b->loc->next != NULL || !b->loc->enabled))) | |
4549 | header_of_multiple = 1; | |
4550 | if (loc == NULL) | |
4551 | loc = b->loc; | |
4552 | ||
c4093a6a | 4553 | annotate_record (); |
3b31d625 | 4554 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); |
c4093a6a JM |
4555 | |
4556 | /* 1 */ | |
4557 | annotate_field (0); | |
0d381245 VP |
4558 | if (part_of_multiple) |
4559 | { | |
4560 | char *formatted; | |
0c6773c1 | 4561 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
4562 | ui_out_field_string (uiout, "number", formatted); |
4563 | xfree (formatted); | |
4564 | } | |
4565 | else | |
4566 | { | |
4567 | ui_out_field_int (uiout, "number", b->number); | |
4568 | } | |
c4093a6a JM |
4569 | |
4570 | /* 2 */ | |
4571 | annotate_field (1); | |
0d381245 VP |
4572 | if (part_of_multiple) |
4573 | ui_out_field_skip (uiout, "type"); | |
4574 | else | |
4575 | { | |
4576 | if (((int) b->type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
4577 | || ((int) b->type != bptypes[(int) b->type].type)) | |
4578 | internal_error (__FILE__, __LINE__, | |
4579 | _("bptypes table does not describe type #%d."), | |
4580 | (int) b->type); | |
4581 | ui_out_field_string (uiout, "type", bptypes[(int) b->type].description); | |
4582 | } | |
c4093a6a JM |
4583 | |
4584 | /* 3 */ | |
4585 | annotate_field (2); | |
0d381245 VP |
4586 | if (part_of_multiple) |
4587 | ui_out_field_skip (uiout, "disp"); | |
4588 | else | |
2cec12e5 | 4589 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 4590 | |
c4093a6a JM |
4591 | |
4592 | /* 4 */ | |
4593 | annotate_field (3); | |
0d381245 | 4594 | if (part_of_multiple) |
54e52265 | 4595 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 4596 | else |
54e52265 VP |
4597 | ui_out_field_fmt (uiout, "enabled", "%c", |
4598 | bpenables[(int) b->enable_state]); | |
4599 | ui_out_spaces (uiout, 2); | |
0d381245 | 4600 | |
c4093a6a JM |
4601 | |
4602 | /* 5 and 6 */ | |
4603 | strcpy (wrap_indent, " "); | |
79a45b7d | 4604 | if (opts.addressprint) |
75ac9d7b | 4605 | { |
a6d9a66e | 4606 | if (print_address_bits <= 32) |
75ac9d7b MS |
4607 | strcat (wrap_indent, " "); |
4608 | else | |
4609 | strcat (wrap_indent, " "); | |
4610 | } | |
c906108c | 4611 | |
3086aeae | 4612 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 VP |
4613 | { |
4614 | /* Although the print_one can possibly print | |
4615 | all locations, calling it here is not likely | |
4616 | to get any nice result. So, make sure there's | |
4617 | just one location. */ | |
4618 | gdb_assert (b->loc == NULL || b->loc->next == NULL); | |
a6d9a66e | 4619 | b->ops->print_one (b, last_loc); |
0d381245 | 4620 | } |
3086aeae DJ |
4621 | else |
4622 | switch (b->type) | |
4623 | { | |
4624 | case bp_none: | |
4625 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 4626 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 4627 | break; |
c906108c | 4628 | |
3086aeae DJ |
4629 | case bp_watchpoint: |
4630 | case bp_hardware_watchpoint: | |
4631 | case bp_read_watchpoint: | |
4632 | case bp_access_watchpoint: | |
4633 | /* Field 4, the address, is omitted (which makes the columns | |
4634 | not line up too nicely with the headers, but the effect | |
4635 | is relatively readable). */ | |
79a45b7d | 4636 | if (opts.addressprint) |
3086aeae DJ |
4637 | ui_out_field_skip (uiout, "addr"); |
4638 | annotate_field (5); | |
fa8a61dc | 4639 | ui_out_field_string (uiout, "what", b->exp_string); |
3086aeae DJ |
4640 | break; |
4641 | ||
3086aeae DJ |
4642 | case bp_breakpoint: |
4643 | case bp_hardware_breakpoint: | |
4644 | case bp_until: | |
4645 | case bp_finish: | |
4646 | case bp_longjmp: | |
4647 | case bp_longjmp_resume: | |
4648 | case bp_step_resume: | |
3086aeae DJ |
4649 | case bp_watchpoint_scope: |
4650 | case bp_call_dummy: | |
aa7d318d | 4651 | case bp_std_terminate: |
3086aeae DJ |
4652 | case bp_shlib_event: |
4653 | case bp_thread_event: | |
4654 | case bp_overlay_event: | |
0fd8e87f | 4655 | case bp_longjmp_master: |
aa7d318d | 4656 | case bp_std_terminate_master: |
1042e4c0 | 4657 | case bp_tracepoint: |
7a697b8d | 4658 | case bp_fast_tracepoint: |
4efc6507 | 4659 | case bp_jit_event: |
79a45b7d | 4660 | if (opts.addressprint) |
3086aeae DJ |
4661 | { |
4662 | annotate_field (4); | |
54e52265 | 4663 | if (header_of_multiple) |
0d381245 | 4664 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 4665 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 4666 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 4667 | else |
5af949e3 UW |
4668 | ui_out_field_core_addr (uiout, "addr", |
4669 | loc->gdbarch, loc->address); | |
3086aeae DJ |
4670 | } |
4671 | annotate_field (5); | |
0d381245 VP |
4672 | if (!header_of_multiple) |
4673 | print_breakpoint_location (b, loc, wrap_indent, stb); | |
4674 | if (b->loc) | |
a6d9a66e | 4675 | *last_loc = b->loc; |
3086aeae DJ |
4676 | break; |
4677 | } | |
c906108c | 4678 | |
6c95b8df PA |
4679 | |
4680 | /* For backward compatibility, don't display inferiors unless there | |
4681 | are several. */ | |
4682 | if (loc != NULL | |
4683 | && !header_of_multiple | |
4684 | && (allflag | |
4685 | || (!gdbarch_has_global_breakpoints (target_gdbarch) | |
4686 | && (number_of_program_spaces () > 1 | |
4687 | || number_of_inferiors () > 1) | |
4688 | && loc->owner->type != bp_catchpoint))) | |
4689 | { | |
4690 | struct inferior *inf; | |
4691 | int first = 1; | |
4692 | ||
4693 | for (inf = inferior_list; inf != NULL; inf = inf->next) | |
4694 | { | |
4695 | if (inf->pspace == loc->pspace) | |
4696 | { | |
4697 | if (first) | |
4698 | { | |
4699 | first = 0; | |
4700 | ui_out_text (uiout, " inf "); | |
4701 | } | |
4702 | else | |
4703 | ui_out_text (uiout, ", "); | |
4704 | ui_out_text (uiout, plongest (inf->num)); | |
4705 | } | |
4706 | } | |
4707 | } | |
4708 | ||
4a306c9a | 4709 | if (!part_of_multiple) |
c4093a6a | 4710 | { |
4a306c9a JB |
4711 | if (b->thread != -1) |
4712 | { | |
4713 | /* FIXME: This seems to be redundant and lost here; see the | |
4714 | "stop only in" line a little further down. */ | |
4715 | ui_out_text (uiout, " thread "); | |
4716 | ui_out_field_int (uiout, "thread", b->thread); | |
4717 | } | |
4718 | else if (b->task != 0) | |
4719 | { | |
4720 | ui_out_text (uiout, " task "); | |
4721 | ui_out_field_int (uiout, "task", b->task); | |
4722 | } | |
c4093a6a JM |
4723 | } |
4724 | ||
8b93c638 | 4725 | ui_out_text (uiout, "\n"); |
c4093a6a | 4726 | |
0d381245 | 4727 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
4728 | { |
4729 | annotate_field (6); | |
8b93c638 | 4730 | ui_out_text (uiout, "\tstop only in stack frame at "); |
818dd999 AC |
4731 | /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside |
4732 | the frame ID. */ | |
5af949e3 UW |
4733 | ui_out_field_core_addr (uiout, "frame", |
4734 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 4735 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
4736 | } |
4737 | ||
0d381245 | 4738 | if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b)) |
c4093a6a | 4739 | { |
f7f9143b JB |
4740 | /* We do not print the condition for Ada exception catchpoints |
4741 | because the condition is an internal implementation detail | |
4742 | that we do not want to expose to the user. */ | |
c4093a6a | 4743 | annotate_field (7); |
7a697b8d | 4744 | if (tracepoint_type (b)) |
1042e4c0 SS |
4745 | ui_out_text (uiout, "\ttrace only if "); |
4746 | else | |
4747 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 JJ |
4748 | ui_out_field_string (uiout, "cond", b->cond_string); |
4749 | ui_out_text (uiout, "\n"); | |
4750 | } | |
4751 | ||
0d381245 | 4752 | if (!part_of_multiple && b->thread != -1) |
c4093a6a JM |
4753 | { |
4754 | /* FIXME should make an annotation for this */ | |
8b93c638 JM |
4755 | ui_out_text (uiout, "\tstop only in thread "); |
4756 | ui_out_field_int (uiout, "thread", b->thread); | |
4757 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
4758 | } |
4759 | ||
63c715c6 | 4760 | if (!part_of_multiple && b->hit_count) |
c4093a6a JM |
4761 | { |
4762 | /* FIXME should make an annotation for this */ | |
8b93c638 JM |
4763 | if (ep_is_catchpoint (b)) |
4764 | ui_out_text (uiout, "\tcatchpoint"); | |
4765 | else | |
4766 | ui_out_text (uiout, "\tbreakpoint"); | |
4767 | ui_out_text (uiout, " already hit "); | |
4768 | ui_out_field_int (uiout, "times", b->hit_count); | |
4769 | if (b->hit_count == 1) | |
4770 | ui_out_text (uiout, " time\n"); | |
4771 | else | |
4772 | ui_out_text (uiout, " times\n"); | |
c4093a6a JM |
4773 | } |
4774 | ||
fb40c209 AC |
4775 | /* Output the count also if it is zero, but only if this is |
4776 | mi. FIXME: Should have a better test for this. */ | |
9dc5e2a9 | 4777 | if (ui_out_is_mi_like_p (uiout)) |
63c715c6 | 4778 | if (!part_of_multiple && b->hit_count == 0) |
fb40c209 | 4779 | ui_out_field_int (uiout, "times", b->hit_count); |
8b93c638 | 4780 | |
0d381245 | 4781 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
4782 | { |
4783 | annotate_field (8); | |
8b93c638 JM |
4784 | ui_out_text (uiout, "\tignore next "); |
4785 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
4786 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 4787 | } |
059fb39f | 4788 | |
9add0f1b | 4789 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 4790 | if (!part_of_multiple && l) |
c4093a6a | 4791 | { |
3b31d625 EZ |
4792 | struct cleanup *script_chain; |
4793 | ||
c4093a6a | 4794 | annotate_field (9); |
3b31d625 | 4795 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 4796 | print_command_lines (uiout, l, 4); |
3b31d625 | 4797 | do_cleanups (script_chain); |
c4093a6a | 4798 | } |
d24317b4 | 4799 | |
1042e4c0 SS |
4800 | if (!part_of_multiple && b->pass_count) |
4801 | { | |
4802 | annotate_field (10); | |
4803 | ui_out_text (uiout, "\tpass count "); | |
4804 | ui_out_field_int (uiout, "pass", b->pass_count); | |
4805 | ui_out_text (uiout, " \n"); | |
4806 | } | |
4807 | ||
d24317b4 VP |
4808 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
4809 | { | |
4810 | if (b->addr_string) | |
4811 | ui_out_field_string (uiout, "original-location", b->addr_string); | |
4812 | else if (b->exp_string) | |
4813 | ui_out_field_string (uiout, "original-location", b->exp_string); | |
4814 | } | |
4815 | ||
3b31d625 | 4816 | do_cleanups (bkpt_chain); |
8b93c638 | 4817 | do_cleanups (old_chain); |
c4093a6a | 4818 | } |
c5aa993b | 4819 | |
0d381245 VP |
4820 | static void |
4821 | print_one_breakpoint (struct breakpoint *b, | |
6c95b8df PA |
4822 | struct bp_location **last_loc, int print_address_bits, |
4823 | int allflag) | |
0d381245 | 4824 | { |
6c95b8df PA |
4825 | print_one_breakpoint_location (b, NULL, 0, last_loc, |
4826 | print_address_bits, allflag); | |
0d381245 VP |
4827 | |
4828 | /* If this breakpoint has custom print function, | |
4829 | it's already printed. Otherwise, print individual | |
4830 | locations, if any. */ | |
4831 | if (b->ops == NULL || b->ops->print_one == NULL) | |
4832 | { | |
4833 | /* If breakpoint has a single location that is | |
4834 | disabled, we print it as if it had | |
4835 | several locations, since otherwise it's hard to | |
4836 | represent "breakpoint enabled, location disabled" | |
a5606eee VP |
4837 | situation. |
4838 | Note that while hardware watchpoints have | |
4839 | several locations internally, that's no a property | |
4840 | exposed to user. */ | |
0d381245 | 4841 | if (b->loc |
a5606eee | 4842 | && !is_hardware_watchpoint (b) |
0d381245 | 4843 | && (b->loc->next || !b->loc->enabled) |
a5606eee | 4844 | && !ui_out_is_mi_like_p (uiout)) |
0d381245 VP |
4845 | { |
4846 | struct bp_location *loc; | |
4847 | int n = 1; | |
4848 | for (loc = b->loc; loc; loc = loc->next, ++n) | |
a6d9a66e | 4849 | print_one_breakpoint_location (b, loc, n, last_loc, |
6c95b8df | 4850 | print_address_bits, allflag); |
0d381245 VP |
4851 | } |
4852 | } | |
4853 | } | |
4854 | ||
a6d9a66e UW |
4855 | static int |
4856 | breakpoint_address_bits (struct breakpoint *b) | |
4857 | { | |
4858 | int print_address_bits = 0; | |
4859 | struct bp_location *loc; | |
4860 | ||
4861 | for (loc = b->loc; loc; loc = loc->next) | |
4862 | { | |
c7437ca6 PA |
4863 | int addr_bit; |
4864 | ||
4865 | /* Software watchpoints that aren't watching memory don't have | |
4866 | an address to print. */ | |
4867 | if (b->type == bp_watchpoint && loc->watchpoint_type == -1) | |
4868 | continue; | |
4869 | ||
4870 | addr_bit = gdbarch_addr_bit (loc->gdbarch); | |
a6d9a66e UW |
4871 | if (addr_bit > print_address_bits) |
4872 | print_address_bits = addr_bit; | |
4873 | } | |
4874 | ||
4875 | return print_address_bits; | |
4876 | } | |
0d381245 | 4877 | |
c4093a6a JM |
4878 | struct captured_breakpoint_query_args |
4879 | { | |
4880 | int bnum; | |
4881 | }; | |
c5aa993b | 4882 | |
c4093a6a | 4883 | static int |
2b65245e | 4884 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
4885 | { |
4886 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 4887 | struct breakpoint *b; |
a6d9a66e | 4888 | struct bp_location *dummy_loc = NULL; |
c4093a6a JM |
4889 | ALL_BREAKPOINTS (b) |
4890 | { | |
4891 | if (args->bnum == b->number) | |
c5aa993b | 4892 | { |
a6d9a66e | 4893 | int print_address_bits = breakpoint_address_bits (b); |
6c95b8df | 4894 | print_one_breakpoint (b, &dummy_loc, print_address_bits, 0); |
c4093a6a | 4895 | return GDB_RC_OK; |
c5aa993b | 4896 | } |
c4093a6a JM |
4897 | } |
4898 | return GDB_RC_NONE; | |
4899 | } | |
c5aa993b | 4900 | |
c4093a6a | 4901 | enum gdb_rc |
ce43223b | 4902 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, char **error_message) |
c4093a6a JM |
4903 | { |
4904 | struct captured_breakpoint_query_args args; | |
4905 | args.bnum = bnum; | |
4906 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4907 | an error. */ | |
b0b13bb4 DJ |
4908 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
4909 | error_message, RETURN_MASK_ALL) < 0) | |
4910 | return GDB_RC_FAIL; | |
4911 | else | |
4912 | return GDB_RC_OK; | |
c4093a6a | 4913 | } |
c5aa993b | 4914 | |
7f3b0473 AC |
4915 | /* Return non-zero if B is user settable (breakpoints, watchpoints, |
4916 | catchpoints, et.al.). */ | |
4917 | ||
4918 | static int | |
4919 | user_settable_breakpoint (const struct breakpoint *b) | |
4920 | { | |
4921 | return (b->type == bp_breakpoint | |
ce78b96d | 4922 | || b->type == bp_catchpoint |
7f3b0473 | 4923 | || b->type == bp_hardware_breakpoint |
7a697b8d | 4924 | || tracepoint_type (b) |
7f3b0473 AC |
4925 | || b->type == bp_watchpoint |
4926 | || b->type == bp_read_watchpoint | |
4927 | || b->type == bp_access_watchpoint | |
4928 | || b->type == bp_hardware_watchpoint); | |
4929 | } | |
4930 | ||
4931 | /* Print information on user settable breakpoint (watchpoint, etc) | |
4932 | number BNUM. If BNUM is -1 print all user settable breakpoints. | |
4933 | If ALLFLAG is non-zero, include non- user settable breakpoints. */ | |
c906108c | 4934 | |
c4093a6a | 4935 | static void |
fba45db2 | 4936 | breakpoint_1 (int bnum, int allflag) |
c4093a6a | 4937 | { |
52f0bd74 | 4938 | struct breakpoint *b; |
a6d9a66e | 4939 | struct bp_location *last_loc = NULL; |
7f3b0473 | 4940 | int nr_printable_breakpoints; |
3b31d625 | 4941 | struct cleanup *bkpttbl_chain; |
79a45b7d | 4942 | struct value_print_options opts; |
a6d9a66e | 4943 | int print_address_bits = 0; |
c4093a6a | 4944 | |
79a45b7d TT |
4945 | get_user_print_options (&opts); |
4946 | ||
a6d9a66e UW |
4947 | /* Compute the number of rows in the table, as well as the |
4948 | size required for address fields. */ | |
7f3b0473 AC |
4949 | nr_printable_breakpoints = 0; |
4950 | ALL_BREAKPOINTS (b) | |
4951 | if (bnum == -1 | |
4952 | || bnum == b->number) | |
4953 | { | |
4954 | if (allflag || user_settable_breakpoint (b)) | |
a6d9a66e UW |
4955 | { |
4956 | int addr_bit = breakpoint_address_bits (b); | |
4957 | if (addr_bit > print_address_bits) | |
4958 | print_address_bits = addr_bit; | |
4959 | ||
4960 | nr_printable_breakpoints++; | |
4961 | } | |
7f3b0473 AC |
4962 | } |
4963 | ||
79a45b7d | 4964 | if (opts.addressprint) |
3b31d625 EZ |
4965 | bkpttbl_chain |
4966 | = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints, | |
4967 | "BreakpointTable"); | |
8b93c638 | 4968 | else |
3b31d625 EZ |
4969 | bkpttbl_chain |
4970 | = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints, | |
4971 | "BreakpointTable"); | |
8b93c638 | 4972 | |
7f3b0473 | 4973 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
4974 | annotate_breakpoints_headers (); |
4975 | if (nr_printable_breakpoints > 0) | |
4976 | annotate_field (0); | |
0d381245 | 4977 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
4978 | if (nr_printable_breakpoints > 0) |
4979 | annotate_field (1); | |
4980 | ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */ | |
4981 | if (nr_printable_breakpoints > 0) | |
4982 | annotate_field (2); | |
4983 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ | |
4984 | if (nr_printable_breakpoints > 0) | |
4985 | annotate_field (3); | |
54e52265 | 4986 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 4987 | if (opts.addressprint) |
7f3b0473 | 4988 | { |
d7faa9e7 AC |
4989 | if (nr_printable_breakpoints > 0) |
4990 | annotate_field (4); | |
a6d9a66e | 4991 | if (print_address_bits <= 32) |
b25959ec | 4992 | ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */ |
7f3b0473 | 4993 | else |
b25959ec | 4994 | ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */ |
7f3b0473 | 4995 | } |
d7faa9e7 AC |
4996 | if (nr_printable_breakpoints > 0) |
4997 | annotate_field (5); | |
4998 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
4999 | ui_out_table_body (uiout); | |
5000 | if (nr_printable_breakpoints > 0) | |
5001 | annotate_breakpoints_table (); | |
7f3b0473 | 5002 | |
c4093a6a | 5003 | ALL_BREAKPOINTS (b) |
bad56014 TT |
5004 | { |
5005 | QUIT; | |
c4093a6a JM |
5006 | if (bnum == -1 |
5007 | || bnum == b->number) | |
5008 | { | |
5009 | /* We only print out user settable breakpoints unless the | |
5010 | allflag is set. */ | |
7f3b0473 | 5011 | if (allflag || user_settable_breakpoint (b)) |
6c95b8df | 5012 | print_one_breakpoint (b, &last_loc, print_address_bits, allflag); |
c4093a6a | 5013 | } |
bad56014 | 5014 | } |
c4093a6a | 5015 | |
3b31d625 | 5016 | do_cleanups (bkpttbl_chain); |
698384cd | 5017 | |
7f3b0473 | 5018 | if (nr_printable_breakpoints == 0) |
c906108c | 5019 | { |
8b93c638 JM |
5020 | if (bnum == -1) |
5021 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); | |
5022 | else | |
5023 | ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n", | |
5024 | bnum); | |
c906108c SS |
5025 | } |
5026 | else | |
c4093a6a | 5027 | { |
a6d9a66e UW |
5028 | if (last_loc && !server_command) |
5029 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 5030 | } |
c906108c | 5031 | |
c4093a6a JM |
5032 | /* FIXME? Should this be moved up so that it is only called when |
5033 | there have been breakpoints? */ | |
c906108c SS |
5034 | annotate_breakpoints_table_end (); |
5035 | } | |
5036 | ||
c906108c | 5037 | static void |
fba45db2 | 5038 | breakpoints_info (char *bnum_exp, int from_tty) |
c906108c SS |
5039 | { |
5040 | int bnum = -1; | |
5041 | ||
5042 | if (bnum_exp) | |
bb518678 | 5043 | bnum = parse_and_eval_long (bnum_exp); |
c906108c SS |
5044 | |
5045 | breakpoint_1 (bnum, 0); | |
5046 | } | |
5047 | ||
7a292a7a | 5048 | static void |
fba45db2 | 5049 | maintenance_info_breakpoints (char *bnum_exp, int from_tty) |
c906108c SS |
5050 | { |
5051 | int bnum = -1; | |
5052 | ||
5053 | if (bnum_exp) | |
bb518678 | 5054 | bnum = parse_and_eval_long (bnum_exp); |
c906108c SS |
5055 | |
5056 | breakpoint_1 (bnum, 1); | |
5057 | } | |
5058 | ||
0d381245 | 5059 | static int |
714835d5 | 5060 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 5061 | struct program_space *pspace, |
714835d5 | 5062 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
5063 | { |
5064 | struct bp_location *bl = b->loc; | |
5065 | for (; bl; bl = bl->next) | |
5066 | { | |
6c95b8df PA |
5067 | if (bl->pspace == pspace |
5068 | && bl->address == pc | |
0d381245 VP |
5069 | && (!overlay_debugging || bl->section == section)) |
5070 | return 1; | |
5071 | } | |
5072 | return 0; | |
5073 | } | |
5074 | ||
6c95b8df PA |
5075 | /* Print a message describing any breakpoints set at PC. This |
5076 | concerns with logical breakpoints, so we match program spaces, not | |
5077 | address spaces. */ | |
c906108c SS |
5078 | |
5079 | static void | |
6c95b8df PA |
5080 | describe_other_breakpoints (struct gdbarch *gdbarch, |
5081 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 5082 | struct obj_section *section, int thread) |
c906108c | 5083 | { |
52f0bd74 AC |
5084 | int others = 0; |
5085 | struct breakpoint *b; | |
c906108c SS |
5086 | |
5087 | ALL_BREAKPOINTS (b) | |
6c95b8df | 5088 | others += breakpoint_has_pc (b, pspace, pc, section); |
c906108c SS |
5089 | if (others > 0) |
5090 | { | |
a3f17187 AC |
5091 | if (others == 1) |
5092 | printf_filtered (_("Note: breakpoint ")); | |
5093 | else /* if (others == ???) */ | |
5094 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 5095 | ALL_BREAKPOINTS (b) |
6c95b8df | 5096 | if (breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
5097 | { |
5098 | others--; | |
5099 | printf_filtered ("%d", b->number); | |
5100 | if (b->thread == -1 && thread != -1) | |
5101 | printf_filtered (" (all threads)"); | |
5102 | else if (b->thread != -1) | |
5103 | printf_filtered (" (thread %d)", b->thread); | |
5104 | printf_filtered ("%s%s ", | |
059fb39f | 5105 | ((b->enable_state == bp_disabled |
8bea4e01 UW |
5106 | || b->enable_state == bp_call_disabled |
5107 | || b->enable_state == bp_startup_disabled) | |
0d381245 VP |
5108 | ? " (disabled)" |
5109 | : b->enable_state == bp_permanent | |
5110 | ? " (permanent)" | |
5111 | : ""), | |
5112 | (others > 1) ? "," | |
5113 | : ((others == 1) ? " and" : "")); | |
5114 | } | |
a3f17187 | 5115 | printf_filtered (_("also set at pc ")); |
5af949e3 | 5116 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
5117 | printf_filtered (".\n"); |
5118 | } | |
5119 | } | |
5120 | \f | |
5121 | /* Set the default place to put a breakpoint | |
5122 | for the `break' command with no arguments. */ | |
5123 | ||
5124 | void | |
6c95b8df PA |
5125 | set_default_breakpoint (int valid, struct program_space *pspace, |
5126 | CORE_ADDR addr, struct symtab *symtab, | |
fba45db2 | 5127 | int line) |
c906108c SS |
5128 | { |
5129 | default_breakpoint_valid = valid; | |
6c95b8df | 5130 | default_breakpoint_pspace = pspace; |
c906108c SS |
5131 | default_breakpoint_address = addr; |
5132 | default_breakpoint_symtab = symtab; | |
5133 | default_breakpoint_line = line; | |
5134 | } | |
5135 | ||
e4f237da KB |
5136 | /* Return true iff it is meaningful to use the address member of |
5137 | BPT. For some breakpoint types, the address member is irrelevant | |
5138 | and it makes no sense to attempt to compare it to other addresses | |
5139 | (or use it for any other purpose either). | |
5140 | ||
5141 | More specifically, each of the following breakpoint types will always | |
876fa593 JK |
5142 | have a zero valued address and we don't want to mark breakpoints of any of |
5143 | these types to be a duplicate of an actual breakpoint at address zero: | |
e4f237da KB |
5144 | |
5145 | bp_watchpoint | |
2d134ed3 PA |
5146 | bp_catchpoint |
5147 | ||
5148 | */ | |
e4f237da KB |
5149 | |
5150 | static int | |
5151 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
5152 | { | |
5153 | enum bptype type = bpt->type; | |
5154 | ||
2d134ed3 PA |
5155 | return (type != bp_watchpoint && type != bp_catchpoint); |
5156 | } | |
5157 | ||
5158 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
5159 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
5160 | ||
5161 | static int | |
5162 | watchpoint_locations_match (struct bp_location *loc1, struct bp_location *loc2) | |
5163 | { | |
85d721b8 PA |
5164 | /* Note that this checks the owner's type, not the location's. In |
5165 | case the target does not support read watchpoints, but does | |
5166 | support access watchpoints, we'll have bp_read_watchpoint | |
5167 | watchpoints with hw_access locations. Those should be considered | |
5168 | duplicates of hw_read locations. The hw_read locations will | |
5169 | become hw_access locations later. */ | |
2d134ed3 PA |
5170 | return (loc1->owner->type == loc2->owner->type |
5171 | && loc1->pspace->aspace == loc2->pspace->aspace | |
5172 | && loc1->address == loc2->address | |
5173 | && loc1->length == loc2->length); | |
e4f237da KB |
5174 | } |
5175 | ||
6c95b8df PA |
5176 | /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the |
5177 | same breakpoint location. In most targets, this can only be true | |
5178 | if ASPACE1 matches ASPACE2. On targets that have global | |
5179 | breakpoints, the address space doesn't really matter. */ | |
5180 | ||
5181 | static int | |
5182 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, | |
5183 | struct address_space *aspace2, CORE_ADDR addr2) | |
5184 | { | |
5185 | return ((gdbarch_has_global_breakpoints (target_gdbarch) | |
5186 | || aspace1 == aspace2) | |
5187 | && addr1 == addr2); | |
5188 | } | |
5189 | ||
2d134ed3 PA |
5190 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
5191 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
5192 | represent the same location. */ | |
5193 | ||
5194 | static int | |
5195 | breakpoint_locations_match (struct bp_location *loc1, struct bp_location *loc2) | |
5196 | { | |
5197 | int hw_point1 = is_hardware_watchpoint (loc1->owner); | |
5198 | int hw_point2 = is_hardware_watchpoint (loc2->owner); | |
5199 | ||
5200 | if (hw_point1 != hw_point2) | |
5201 | return 0; | |
5202 | else if (hw_point1) | |
5203 | return watchpoint_locations_match (loc1, loc2); | |
5204 | else | |
5205 | return breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
5206 | loc2->pspace->aspace, loc2->address); | |
5207 | } | |
5208 | ||
76897487 KB |
5209 | static void |
5210 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
5211 | int bnum, int have_bnum) | |
5212 | { | |
5213 | char astr1[40]; | |
5214 | char astr2[40]; | |
5215 | ||
bb599908 PH |
5216 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
5217 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 5218 | if (have_bnum) |
8a3fe4f8 | 5219 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
5220 | bnum, astr1, astr2); |
5221 | else | |
8a3fe4f8 | 5222 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
5223 | } |
5224 | ||
5225 | /* Adjust a breakpoint's address to account for architectural constraints | |
5226 | on breakpoint placement. Return the adjusted address. Note: Very | |
5227 | few targets require this kind of adjustment. For most targets, | |
5228 | this function is simply the identity function. */ | |
5229 | ||
5230 | static CORE_ADDR | |
a6d9a66e UW |
5231 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
5232 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 5233 | { |
a6d9a66e | 5234 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
5235 | { |
5236 | /* Very few targets need any kind of breakpoint adjustment. */ | |
5237 | return bpaddr; | |
5238 | } | |
88f7da05 KB |
5239 | else if (bptype == bp_watchpoint |
5240 | || bptype == bp_hardware_watchpoint | |
5241 | || bptype == bp_read_watchpoint | |
5242 | || bptype == bp_access_watchpoint | |
fe798b75 | 5243 | || bptype == bp_catchpoint) |
88f7da05 KB |
5244 | { |
5245 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
5246 | have their addresses modified. */ | |
5247 | return bpaddr; | |
5248 | } | |
76897487 KB |
5249 | else |
5250 | { | |
5251 | CORE_ADDR adjusted_bpaddr; | |
5252 | ||
5253 | /* Some targets have architectural constraints on the placement | |
5254 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 5255 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
5256 | |
5257 | /* An adjusted breakpoint address can significantly alter | |
5258 | a user's expectations. Print a warning if an adjustment | |
5259 | is required. */ | |
5260 | if (adjusted_bpaddr != bpaddr) | |
5261 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
5262 | ||
5263 | return adjusted_bpaddr; | |
5264 | } | |
5265 | } | |
5266 | ||
7cc221ef DJ |
5267 | /* Allocate a struct bp_location. */ |
5268 | ||
26bb91f3 | 5269 | static struct bp_location * |
39d61571 | 5270 | allocate_bp_location (struct breakpoint *bpt) |
7cc221ef DJ |
5271 | { |
5272 | struct bp_location *loc, *loc_p; | |
5273 | ||
5274 | loc = xmalloc (sizeof (struct bp_location)); | |
5275 | memset (loc, 0, sizeof (*loc)); | |
5276 | ||
e049a4b5 | 5277 | loc->owner = bpt; |
511a6cd4 | 5278 | loc->cond = NULL; |
0d381245 VP |
5279 | loc->shlib_disabled = 0; |
5280 | loc->enabled = 1; | |
e049a4b5 | 5281 | |
39d61571 | 5282 | switch (bpt->type) |
e049a4b5 DJ |
5283 | { |
5284 | case bp_breakpoint: | |
5285 | case bp_until: | |
5286 | case bp_finish: | |
5287 | case bp_longjmp: | |
5288 | case bp_longjmp_resume: | |
5289 | case bp_step_resume: | |
e049a4b5 DJ |
5290 | case bp_watchpoint_scope: |
5291 | case bp_call_dummy: | |
aa7d318d | 5292 | case bp_std_terminate: |
e049a4b5 DJ |
5293 | case bp_shlib_event: |
5294 | case bp_thread_event: | |
5295 | case bp_overlay_event: | |
4efc6507 | 5296 | case bp_jit_event: |
0fd8e87f | 5297 | case bp_longjmp_master: |
aa7d318d | 5298 | case bp_std_terminate_master: |
e049a4b5 DJ |
5299 | loc->loc_type = bp_loc_software_breakpoint; |
5300 | break; | |
5301 | case bp_hardware_breakpoint: | |
5302 | loc->loc_type = bp_loc_hardware_breakpoint; | |
5303 | break; | |
5304 | case bp_hardware_watchpoint: | |
5305 | case bp_read_watchpoint: | |
5306 | case bp_access_watchpoint: | |
5307 | loc->loc_type = bp_loc_hardware_watchpoint; | |
5308 | break; | |
5309 | case bp_watchpoint: | |
ce78b96d | 5310 | case bp_catchpoint: |
15c3d785 PA |
5311 | case bp_tracepoint: |
5312 | case bp_fast_tracepoint: | |
e049a4b5 DJ |
5313 | loc->loc_type = bp_loc_other; |
5314 | break; | |
5315 | default: | |
e2e0b3e5 | 5316 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
5317 | } |
5318 | ||
7cc221ef DJ |
5319 | return loc; |
5320 | } | |
5321 | ||
fe3f5fa8 VP |
5322 | static void free_bp_location (struct bp_location *loc) |
5323 | { | |
5324 | if (loc->cond) | |
5325 | xfree (loc->cond); | |
74960c60 VP |
5326 | |
5327 | if (loc->function_name) | |
5328 | xfree (loc->function_name); | |
5329 | ||
fe3f5fa8 VP |
5330 | xfree (loc); |
5331 | } | |
5332 | ||
0d381245 VP |
5333 | /* Helper to set_raw_breakpoint below. Creates a breakpoint |
5334 | that has type BPTYPE and has no locations as yet. */ | |
63c252f8 | 5335 | /* This function is used in gdbtk sources and thus can not be made static. */ |
c906108c | 5336 | |
c40e75cd | 5337 | static struct breakpoint * |
a6d9a66e UW |
5338 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, |
5339 | enum bptype bptype) | |
c906108c | 5340 | { |
52f0bd74 | 5341 | struct breakpoint *b, *b1; |
c906108c SS |
5342 | |
5343 | b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint)); | |
5344 | memset (b, 0, sizeof (*b)); | |
2219d63c | 5345 | |
4d28f7a8 | 5346 | b->type = bptype; |
a6d9a66e | 5347 | b->gdbarch = gdbarch; |
c906108c SS |
5348 | b->language = current_language->la_language; |
5349 | b->input_radix = input_radix; | |
5350 | b->thread = -1; | |
b5de0fa7 | 5351 | b->enable_state = bp_enabled; |
c906108c SS |
5352 | b->next = 0; |
5353 | b->silent = 0; | |
5354 | b->ignore_count = 0; | |
5355 | b->commands = NULL; | |
818dd999 | 5356 | b->frame_id = null_frame_id; |
3a3e9ee3 | 5357 | b->forked_inferior_pid = null_ptid; |
c906108c | 5358 | b->exec_pathname = NULL; |
a96d9b2e | 5359 | b->syscalls_to_be_caught = NULL; |
3086aeae | 5360 | b->ops = NULL; |
0d381245 | 5361 | b->condition_not_parsed = 0; |
c906108c SS |
5362 | |
5363 | /* Add this breakpoint to the end of the chain | |
5364 | so that a list of breakpoints will come out in order | |
5365 | of increasing numbers. */ | |
5366 | ||
5367 | b1 = breakpoint_chain; | |
5368 | if (b1 == 0) | |
5369 | breakpoint_chain = b; | |
5370 | else | |
5371 | { | |
5372 | while (b1->next) | |
5373 | b1 = b1->next; | |
5374 | b1->next = b; | |
5375 | } | |
0d381245 VP |
5376 | return b; |
5377 | } | |
5378 | ||
5379 | /* Initialize loc->function_name. */ | |
5380 | static void | |
5381 | set_breakpoint_location_function (struct bp_location *loc) | |
5382 | { | |
5383 | if (loc->owner->type == bp_breakpoint | |
1042e4c0 | 5384 | || loc->owner->type == bp_hardware_breakpoint |
7a697b8d | 5385 | || tracepoint_type (loc->owner)) |
0d381245 VP |
5386 | { |
5387 | find_pc_partial_function (loc->address, &(loc->function_name), | |
5388 | NULL, NULL); | |
5389 | if (loc->function_name) | |
5390 | loc->function_name = xstrdup (loc->function_name); | |
5391 | } | |
5392 | } | |
5393 | ||
a6d9a66e UW |
5394 | /* Attempt to determine architecture of location identified by SAL. */ |
5395 | static struct gdbarch * | |
5396 | get_sal_arch (struct symtab_and_line sal) | |
5397 | { | |
5398 | if (sal.section) | |
5399 | return get_objfile_arch (sal.section->objfile); | |
5400 | if (sal.symtab) | |
5401 | return get_objfile_arch (sal.symtab->objfile); | |
5402 | ||
5403 | return NULL; | |
5404 | } | |
5405 | ||
0d381245 VP |
5406 | /* set_raw_breakpoint is a low level routine for allocating and |
5407 | partially initializing a breakpoint of type BPTYPE. The newly | |
5408 | created breakpoint's address, section, source file name, and line | |
5409 | number are provided by SAL. The newly created and partially | |
5410 | initialized breakpoint is added to the breakpoint chain and | |
5411 | is also returned as the value of this function. | |
5412 | ||
5413 | It is expected that the caller will complete the initialization of | |
5414 | the newly created breakpoint struct as well as output any status | |
5415 | information regarding the creation of a new breakpoint. In | |
5416 | particular, set_raw_breakpoint does NOT set the breakpoint | |
5417 | number! Care should be taken to not allow an error to occur | |
5418 | prior to completing the initialization of the breakpoint. If this | |
5419 | should happen, a bogus breakpoint will be left on the chain. */ | |
5420 | ||
63c252f8 | 5421 | struct breakpoint * |
a6d9a66e UW |
5422 | set_raw_breakpoint (struct gdbarch *gdbarch, |
5423 | struct symtab_and_line sal, enum bptype bptype) | |
0d381245 | 5424 | { |
a6d9a66e | 5425 | struct breakpoint *b = set_raw_breakpoint_without_location (gdbarch, bptype); |
0d381245 | 5426 | CORE_ADDR adjusted_address; |
a6d9a66e UW |
5427 | struct gdbarch *loc_gdbarch; |
5428 | ||
5429 | loc_gdbarch = get_sal_arch (sal); | |
5430 | if (!loc_gdbarch) | |
5431 | loc_gdbarch = b->gdbarch; | |
0d381245 | 5432 | |
6c95b8df PA |
5433 | if (bptype != bp_catchpoint) |
5434 | gdb_assert (sal.pspace != NULL); | |
5435 | ||
0d381245 VP |
5436 | /* Adjust the breakpoint's address prior to allocating a location. |
5437 | Once we call allocate_bp_location(), that mostly uninitialized | |
5438 | location will be placed on the location chain. Adjustment of the | |
8defab1a | 5439 | breakpoint may cause target_read_memory() to be called and we do |
0d381245 VP |
5440 | not want its scan of the location chain to find a breakpoint and |
5441 | location that's only been partially initialized. */ | |
a6d9a66e | 5442 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, sal.pc, b->type); |
0d381245 | 5443 | |
39d61571 | 5444 | b->loc = allocate_bp_location (b); |
a6d9a66e | 5445 | b->loc->gdbarch = loc_gdbarch; |
0d381245 VP |
5446 | b->loc->requested_address = sal.pc; |
5447 | b->loc->address = adjusted_address; | |
6c95b8df PA |
5448 | b->loc->pspace = sal.pspace; |
5449 | ||
5450 | /* Store the program space that was used to set the breakpoint, for | |
5451 | breakpoint resetting. */ | |
5452 | b->pspace = sal.pspace; | |
0d381245 VP |
5453 | |
5454 | if (sal.symtab == NULL) | |
5455 | b->source_file = NULL; | |
5456 | else | |
1b36a34b | 5457 | b->source_file = xstrdup (sal.symtab->filename); |
0d381245 VP |
5458 | b->loc->section = sal.section; |
5459 | b->line_number = sal.line; | |
5460 | ||
5461 | set_breakpoint_location_function (b->loc); | |
c906108c | 5462 | |
c906108c SS |
5463 | breakpoints_changed (); |
5464 | ||
5465 | return b; | |
5466 | } | |
5467 | ||
c2c6d25f JM |
5468 | |
5469 | /* Note that the breakpoint object B describes a permanent breakpoint | |
5470 | instruction, hard-wired into the inferior's code. */ | |
5471 | void | |
5472 | make_breakpoint_permanent (struct breakpoint *b) | |
5473 | { | |
0d381245 | 5474 | struct bp_location *bl; |
b5de0fa7 | 5475 | b->enable_state = bp_permanent; |
c2c6d25f | 5476 | |
0d381245 VP |
5477 | /* By definition, permanent breakpoints are already present in the code. |
5478 | Mark all locations as inserted. For now, make_breakpoint_permanent | |
5479 | is called in just one place, so it's hard to say if it's reasonable | |
5480 | to have permanent breakpoint with multiple locations or not, | |
5481 | but it's easy to implmement. */ | |
5482 | for (bl = b->loc; bl; bl = bl->next) | |
5483 | bl->inserted = 1; | |
c2c6d25f JM |
5484 | } |
5485 | ||
53a5351d | 5486 | /* Call this routine when stepping and nexting to enable a breakpoint |
0fd8e87f | 5487 | if we do a longjmp() in THREAD. When we hit that breakpoint, call |
c906108c SS |
5488 | set_longjmp_resume_breakpoint() to figure out where we are going. */ |
5489 | ||
5490 | void | |
0fd8e87f | 5491 | set_longjmp_breakpoint (int thread) |
c906108c | 5492 | { |
0fd8e87f UW |
5493 | struct breakpoint *b, *temp; |
5494 | ||
5495 | /* To avoid having to rescan all objfile symbols at every step, | |
5496 | we maintain a list of continually-inserted but always disabled | |
5497 | longjmp "master" breakpoints. Here, we simply create momentary | |
5498 | clones of those and enable them for the requested thread. */ | |
5499 | ALL_BREAKPOINTS_SAFE (b, temp) | |
6c95b8df PA |
5500 | if (b->pspace == current_program_space |
5501 | && b->type == bp_longjmp_master) | |
0fd8e87f UW |
5502 | { |
5503 | struct breakpoint *clone = clone_momentary_breakpoint (b); | |
5504 | clone->type = bp_longjmp; | |
5505 | clone->thread = thread; | |
5506 | } | |
c906108c SS |
5507 | } |
5508 | ||
611c83ae | 5509 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 5510 | void |
611c83ae | 5511 | delete_longjmp_breakpoint (int thread) |
c906108c | 5512 | { |
611c83ae | 5513 | struct breakpoint *b, *temp; |
c906108c | 5514 | |
611c83ae PA |
5515 | ALL_BREAKPOINTS_SAFE (b, temp) |
5516 | if (b->type == bp_longjmp) | |
5517 | { | |
5518 | if (b->thread == thread) | |
5519 | delete_breakpoint (b); | |
5520 | } | |
c906108c SS |
5521 | } |
5522 | ||
1900040c MS |
5523 | void |
5524 | enable_overlay_breakpoints (void) | |
5525 | { | |
52f0bd74 | 5526 | struct breakpoint *b; |
1900040c MS |
5527 | |
5528 | ALL_BREAKPOINTS (b) | |
5529 | if (b->type == bp_overlay_event) | |
5530 | { | |
5531 | b->enable_state = bp_enabled; | |
b60e7edf | 5532 | update_global_location_list (1); |
c02f5703 | 5533 | overlay_events_enabled = 1; |
1900040c MS |
5534 | } |
5535 | } | |
5536 | ||
5537 | void | |
5538 | disable_overlay_breakpoints (void) | |
5539 | { | |
52f0bd74 | 5540 | struct breakpoint *b; |
1900040c MS |
5541 | |
5542 | ALL_BREAKPOINTS (b) | |
5543 | if (b->type == bp_overlay_event) | |
5544 | { | |
5545 | b->enable_state = bp_disabled; | |
b60e7edf | 5546 | update_global_location_list (0); |
c02f5703 | 5547 | overlay_events_enabled = 0; |
1900040c MS |
5548 | } |
5549 | } | |
5550 | ||
aa7d318d TT |
5551 | /* Set an active std::terminate breakpoint for each std::terminate |
5552 | master breakpoint. */ | |
5553 | void | |
5554 | set_std_terminate_breakpoint (void) | |
5555 | { | |
5556 | struct breakpoint *b, *temp; | |
5557 | ||
5558 | ALL_BREAKPOINTS_SAFE (b, temp) | |
5559 | if (b->pspace == current_program_space | |
5560 | && b->type == bp_std_terminate_master) | |
5561 | { | |
5562 | struct breakpoint *clone = clone_momentary_breakpoint (b); | |
5563 | clone->type = bp_std_terminate; | |
5564 | } | |
5565 | } | |
5566 | ||
5567 | /* Delete all the std::terminate breakpoints. */ | |
5568 | void | |
5569 | delete_std_terminate_breakpoint (void) | |
5570 | { | |
5571 | struct breakpoint *b, *temp; | |
5572 | ||
5573 | ALL_BREAKPOINTS_SAFE (b, temp) | |
5574 | if (b->type == bp_std_terminate) | |
5575 | delete_breakpoint (b); | |
5576 | } | |
5577 | ||
c4093a6a | 5578 | struct breakpoint * |
a6d9a66e | 5579 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
5580 | { |
5581 | struct breakpoint *b; | |
c4093a6a | 5582 | |
a6d9a66e | 5583 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event); |
c4093a6a | 5584 | |
b5de0fa7 | 5585 | b->enable_state = bp_enabled; |
c4093a6a | 5586 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
5587 | b->addr_string |
5588 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 5589 | |
b60e7edf | 5590 | update_global_location_list_nothrow (1); |
74960c60 | 5591 | |
c4093a6a JM |
5592 | return b; |
5593 | } | |
5594 | ||
5595 | void | |
5596 | remove_thread_event_breakpoints (void) | |
5597 | { | |
5598 | struct breakpoint *b, *temp; | |
5599 | ||
5600 | ALL_BREAKPOINTS_SAFE (b, temp) | |
6c95b8df PA |
5601 | if (b->type == bp_thread_event |
5602 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
5603 | delete_breakpoint (b); |
5604 | } | |
5605 | ||
0101ce28 JJ |
5606 | struct captured_parse_breakpoint_args |
5607 | { | |
5608 | char **arg_p; | |
5609 | struct symtabs_and_lines *sals_p; | |
5610 | char ***addr_string_p; | |
5611 | int *not_found_ptr; | |
5612 | }; | |
5613 | ||
5614 | struct lang_and_radix | |
5615 | { | |
5616 | enum language lang; | |
5617 | int radix; | |
5618 | }; | |
5619 | ||
4efc6507 DE |
5620 | /* Create a breakpoint for JIT code registration and unregistration. */ |
5621 | ||
5622 | struct breakpoint * | |
5623 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
5624 | { | |
5625 | struct breakpoint *b; | |
5626 | ||
5627 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event); | |
5628 | update_global_location_list_nothrow (1); | |
5629 | return b; | |
5630 | } | |
0101ce28 | 5631 | |
cae688ec JJ |
5632 | void |
5633 | remove_solib_event_breakpoints (void) | |
5634 | { | |
5635 | struct breakpoint *b, *temp; | |
5636 | ||
5637 | ALL_BREAKPOINTS_SAFE (b, temp) | |
6c95b8df PA |
5638 | if (b->type == bp_shlib_event |
5639 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
5640 | delete_breakpoint (b); |
5641 | } | |
5642 | ||
5643 | struct breakpoint * | |
a6d9a66e | 5644 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
cae688ec JJ |
5645 | { |
5646 | struct breakpoint *b; | |
5647 | ||
a6d9a66e | 5648 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event); |
b60e7edf | 5649 | update_global_location_list_nothrow (1); |
cae688ec JJ |
5650 | return b; |
5651 | } | |
5652 | ||
5653 | /* Disable any breakpoints that are on code in shared libraries. Only | |
5654 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
5655 | ||
5656 | void | |
cb851954 | 5657 | disable_breakpoints_in_shlibs (void) |
cae688ec | 5658 | { |
876fa593 | 5659 | struct bp_location *loc, **locp_tmp; |
cae688ec | 5660 | |
876fa593 | 5661 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 5662 | { |
0d381245 VP |
5663 | struct breakpoint *b = loc->owner; |
5664 | /* We apply the check to all breakpoints, including disabled | |
5665 | for those with loc->duplicate set. This is so that when breakpoint | |
5666 | becomes enabled, or the duplicate is removed, gdb will try to insert | |
5667 | all breakpoints. If we don't set shlib_disabled here, we'll try | |
5668 | to insert those breakpoints and fail. */ | |
1042e4c0 | 5669 | if (((b->type == bp_breakpoint) |
508ccb1f | 5670 | || (b->type == bp_jit_event) |
1042e4c0 | 5671 | || (b->type == bp_hardware_breakpoint) |
7a697b8d | 5672 | || (tracepoint_type (b))) |
6c95b8df | 5673 | && loc->pspace == current_program_space |
0d381245 | 5674 | && !loc->shlib_disabled |
a77053c2 | 5675 | #ifdef PC_SOLIB |
0d381245 | 5676 | && PC_SOLIB (loc->address) |
a77053c2 | 5677 | #else |
6c95b8df | 5678 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 MK |
5679 | #endif |
5680 | ) | |
0d381245 VP |
5681 | { |
5682 | loc->shlib_disabled = 1; | |
5683 | } | |
cae688ec JJ |
5684 | } |
5685 | } | |
5686 | ||
84acb35a JJ |
5687 | /* Disable any breakpoints that are in in an unloaded shared library. Only |
5688 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
5689 | ||
75149521 | 5690 | static void |
84acb35a JJ |
5691 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
5692 | { | |
876fa593 | 5693 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
5694 | int disabled_shlib_breaks = 0; |
5695 | ||
c86cf029 VP |
5696 | /* SunOS a.out shared libraries are always mapped, so do not |
5697 | disable breakpoints; they will only be reported as unloaded | |
5698 | through clear_solib when GDB discards its shared library | |
5699 | list. See clear_solib for more information. */ | |
5700 | if (exec_bfd != NULL | |
5701 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
5702 | return; | |
5703 | ||
876fa593 | 5704 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 5705 | { |
0d381245 VP |
5706 | struct breakpoint *b = loc->owner; |
5707 | if ((loc->loc_type == bp_loc_hardware_breakpoint | |
5708 | || loc->loc_type == bp_loc_software_breakpoint) | |
6c95b8df | 5709 | && solib->pspace == loc->pspace |
e2dd7057 | 5710 | && !loc->shlib_disabled |
508ccb1f TT |
5711 | && (b->type == bp_breakpoint |
5712 | || b->type == bp_jit_event | |
5713 | || b->type == bp_hardware_breakpoint) | |
e2dd7057 | 5714 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 5715 | { |
e2dd7057 PP |
5716 | loc->shlib_disabled = 1; |
5717 | /* At this point, we cannot rely on remove_breakpoint | |
5718 | succeeding so we must mark the breakpoint as not inserted | |
5719 | to prevent future errors occurring in remove_breakpoints. */ | |
5720 | loc->inserted = 0; | |
5721 | if (!disabled_shlib_breaks) | |
5722 | { | |
5723 | target_terminal_ours_for_output (); | |
5724 | warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""), | |
5725 | solib->so_name); | |
84acb35a | 5726 | } |
e2dd7057 | 5727 | disabled_shlib_breaks = 1; |
84acb35a JJ |
5728 | } |
5729 | } | |
84acb35a JJ |
5730 | } |
5731 | ||
ce78b96d JB |
5732 | /* FORK & VFORK catchpoints. */ |
5733 | ||
5734 | /* Implement the "insert" breakpoint_ops method for fork catchpoints. */ | |
5735 | ||
c906108c | 5736 | static void |
ce78b96d JB |
5737 | insert_catch_fork (struct breakpoint *b) |
5738 | { | |
5739 | target_insert_fork_catchpoint (PIDGET (inferior_ptid)); | |
5740 | } | |
5741 | ||
5742 | /* Implement the "remove" breakpoint_ops method for fork catchpoints. */ | |
5743 | ||
5744 | static int | |
5745 | remove_catch_fork (struct breakpoint *b) | |
5746 | { | |
5747 | return target_remove_fork_catchpoint (PIDGET (inferior_ptid)); | |
5748 | } | |
5749 | ||
5750 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
5751 | catchpoints. */ | |
5752 | ||
5753 | static int | |
5754 | breakpoint_hit_catch_fork (struct breakpoint *b) | |
5755 | { | |
5756 | return inferior_has_forked (inferior_ptid, &b->forked_inferior_pid); | |
5757 | } | |
5758 | ||
5759 | /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */ | |
5760 | ||
5761 | static enum print_stop_action | |
5762 | print_it_catch_fork (struct breakpoint *b) | |
5763 | { | |
5764 | annotate_catchpoint (b->number); | |
5765 | printf_filtered (_("\nCatchpoint %d (forked process %d), "), | |
5766 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
5767 | return PRINT_SRC_AND_LOC; | |
5768 | } | |
5769 | ||
5770 | /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */ | |
5771 | ||
5772 | static void | |
a6d9a66e | 5773 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 5774 | { |
79a45b7d TT |
5775 | struct value_print_options opts; |
5776 | ||
5777 | get_user_print_options (&opts); | |
5778 | ||
ce78b96d JB |
5779 | /* Field 4, the address, is omitted (which makes the columns |
5780 | not line up too nicely with the headers, but the effect | |
5781 | is relatively readable). */ | |
79a45b7d | 5782 | if (opts.addressprint) |
ce78b96d JB |
5783 | ui_out_field_skip (uiout, "addr"); |
5784 | annotate_field (5); | |
5785 | ui_out_text (uiout, "fork"); | |
5786 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
5787 | { | |
5788 | ui_out_text (uiout, ", process "); | |
5789 | ui_out_field_int (uiout, "what", | |
5790 | ptid_get_pid (b->forked_inferior_pid)); | |
5791 | ui_out_spaces (uiout, 1); | |
5792 | } | |
5793 | } | |
5794 | ||
5795 | /* Implement the "print_mention" breakpoint_ops method for fork | |
5796 | catchpoints. */ | |
5797 | ||
5798 | static void | |
5799 | print_mention_catch_fork (struct breakpoint *b) | |
5800 | { | |
5801 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
5802 | } | |
5803 | ||
5804 | /* The breakpoint_ops structure to be used in fork catchpoints. */ | |
5805 | ||
5806 | static struct breakpoint_ops catch_fork_breakpoint_ops = | |
5807 | { | |
5808 | insert_catch_fork, | |
5809 | remove_catch_fork, | |
5810 | breakpoint_hit_catch_fork, | |
5811 | print_it_catch_fork, | |
5812 | print_one_catch_fork, | |
5813 | print_mention_catch_fork | |
5814 | }; | |
5815 | ||
5816 | /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */ | |
5817 | ||
5818 | static void | |
5819 | insert_catch_vfork (struct breakpoint *b) | |
5820 | { | |
5821 | target_insert_vfork_catchpoint (PIDGET (inferior_ptid)); | |
5822 | } | |
5823 | ||
5824 | /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */ | |
5825 | ||
5826 | static int | |
5827 | remove_catch_vfork (struct breakpoint *b) | |
5828 | { | |
5829 | return target_remove_vfork_catchpoint (PIDGET (inferior_ptid)); | |
5830 | } | |
5831 | ||
5832 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
5833 | catchpoints. */ | |
5834 | ||
5835 | static int | |
5836 | breakpoint_hit_catch_vfork (struct breakpoint *b) | |
5837 | { | |
5838 | return inferior_has_vforked (inferior_ptid, &b->forked_inferior_pid); | |
5839 | } | |
5840 | ||
5841 | /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */ | |
5842 | ||
5843 | static enum print_stop_action | |
5844 | print_it_catch_vfork (struct breakpoint *b) | |
5845 | { | |
5846 | annotate_catchpoint (b->number); | |
5847 | printf_filtered (_("\nCatchpoint %d (vforked process %d), "), | |
5848 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
5849 | return PRINT_SRC_AND_LOC; | |
5850 | } | |
5851 | ||
5852 | /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */ | |
5853 | ||
5854 | static void | |
a6d9a66e | 5855 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 5856 | { |
79a45b7d TT |
5857 | struct value_print_options opts; |
5858 | ||
5859 | get_user_print_options (&opts); | |
ce78b96d JB |
5860 | /* Field 4, the address, is omitted (which makes the columns |
5861 | not line up too nicely with the headers, but the effect | |
5862 | is relatively readable). */ | |
79a45b7d | 5863 | if (opts.addressprint) |
ce78b96d JB |
5864 | ui_out_field_skip (uiout, "addr"); |
5865 | annotate_field (5); | |
5866 | ui_out_text (uiout, "vfork"); | |
5867 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
5868 | { | |
5869 | ui_out_text (uiout, ", process "); | |
5870 | ui_out_field_int (uiout, "what", | |
5871 | ptid_get_pid (b->forked_inferior_pid)); | |
5872 | ui_out_spaces (uiout, 1); | |
5873 | } | |
5874 | } | |
5875 | ||
5876 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
5877 | catchpoints. */ | |
5878 | ||
5879 | static void | |
5880 | print_mention_catch_vfork (struct breakpoint *b) | |
5881 | { | |
5882 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
5883 | } | |
5884 | ||
5885 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ | |
5886 | ||
5887 | static struct breakpoint_ops catch_vfork_breakpoint_ops = | |
5888 | { | |
5889 | insert_catch_vfork, | |
5890 | remove_catch_vfork, | |
5891 | breakpoint_hit_catch_vfork, | |
5892 | print_it_catch_vfork, | |
5893 | print_one_catch_vfork, | |
5894 | print_mention_catch_vfork | |
5895 | }; | |
5896 | ||
a96d9b2e SDJ |
5897 | /* Implement the "insert" breakpoint_ops method for syscall |
5898 | catchpoints. */ | |
5899 | ||
5900 | static void | |
5901 | insert_catch_syscall (struct breakpoint *b) | |
5902 | { | |
5903 | struct inferior *inf = current_inferior (); | |
5904 | ||
5905 | ++inf->total_syscalls_count; | |
5906 | if (!b->syscalls_to_be_caught) | |
5907 | ++inf->any_syscall_count; | |
5908 | else | |
5909 | { | |
5910 | int i, iter; | |
5911 | for (i = 0; | |
5912 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
5913 | i++) | |
5914 | { | |
5915 | int elem; | |
5916 | if (iter >= VEC_length (int, inf->syscalls_counts)) | |
5917 | { | |
5918 | int old_size = VEC_length (int, inf->syscalls_counts); | |
5919 | uintptr_t vec_addr_offset = old_size * ((uintptr_t) sizeof (int)); | |
5920 | uintptr_t vec_addr; | |
5921 | VEC_safe_grow (int, inf->syscalls_counts, iter + 1); | |
5922 | vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) + | |
5923 | vec_addr_offset; | |
5924 | memset ((void *) vec_addr, 0, | |
5925 | (iter + 1 - old_size) * sizeof (int)); | |
5926 | } | |
5927 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
5928 | VEC_replace (int, inf->syscalls_counts, iter, ++elem); | |
5929 | } | |
5930 | } | |
5931 | ||
5932 | target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
5933 | inf->total_syscalls_count != 0, | |
5934 | inf->any_syscall_count, | |
5935 | VEC_length (int, inf->syscalls_counts), | |
5936 | VEC_address (int, inf->syscalls_counts)); | |
5937 | } | |
5938 | ||
5939 | /* Implement the "remove" breakpoint_ops method for syscall | |
5940 | catchpoints. */ | |
5941 | ||
5942 | static int | |
5943 | remove_catch_syscall (struct breakpoint *b) | |
5944 | { | |
5945 | struct inferior *inf = current_inferior (); | |
5946 | ||
5947 | --inf->total_syscalls_count; | |
5948 | if (!b->syscalls_to_be_caught) | |
5949 | --inf->any_syscall_count; | |
5950 | else | |
5951 | { | |
5952 | int i, iter; | |
5953 | for (i = 0; | |
5954 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
5955 | i++) | |
5956 | { | |
5957 | int elem; | |
5958 | if (iter >= VEC_length (int, inf->syscalls_counts)) | |
5959 | /* Shouldn't happen. */ | |
5960 | continue; | |
5961 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
5962 | VEC_replace (int, inf->syscalls_counts, iter, --elem); | |
5963 | } | |
5964 | } | |
5965 | ||
5966 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
5967 | inf->total_syscalls_count != 0, | |
5968 | inf->any_syscall_count, | |
5969 | VEC_length (int, inf->syscalls_counts), | |
5970 | VEC_address (int, inf->syscalls_counts)); | |
5971 | } | |
5972 | ||
5973 | /* Implement the "breakpoint_hit" breakpoint_ops method for syscall | |
5974 | catchpoints. */ | |
5975 | ||
5976 | static int | |
5977 | breakpoint_hit_catch_syscall (struct breakpoint *b) | |
5978 | { | |
5979 | /* We must check if we are catching specific syscalls in this breakpoint. | |
5980 | If we are, then we must guarantee that the called syscall is the same | |
5981 | syscall we are catching. */ | |
5982 | int syscall_number = 0; | |
5983 | ||
5984 | if (!inferior_has_called_syscall (inferior_ptid, &syscall_number)) | |
5985 | return 0; | |
5986 | ||
5987 | /* Now, checking if the syscall is the same. */ | |
5988 | if (b->syscalls_to_be_caught) | |
5989 | { | |
5990 | int i, iter; | |
5991 | for (i = 0; | |
5992 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
5993 | i++) | |
5994 | if (syscall_number == iter) | |
5995 | break; | |
5996 | /* Not the same. */ | |
5997 | if (!iter) | |
5998 | return 0; | |
5999 | } | |
6000 | ||
6001 | return 1; | |
6002 | } | |
6003 | ||
6004 | /* Implement the "print_it" breakpoint_ops method for syscall | |
6005 | catchpoints. */ | |
6006 | ||
6007 | static enum print_stop_action | |
6008 | print_it_catch_syscall (struct breakpoint *b) | |
6009 | { | |
6010 | /* These are needed because we want to know in which state a | |
6011 | syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY | |
6012 | or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we | |
6013 | must print "called syscall" or "returned from syscall". */ | |
6014 | ptid_t ptid; | |
6015 | struct target_waitstatus last; | |
6016 | struct syscall s; | |
6017 | struct cleanup *old_chain; | |
6018 | char *syscall_id; | |
6019 | ||
6020 | get_last_target_status (&ptid, &last); | |
6021 | ||
6022 | get_syscall_by_number (last.value.syscall_number, &s); | |
6023 | ||
6024 | annotate_catchpoint (b->number); | |
6025 | ||
6026 | if (s.name == NULL) | |
6027 | syscall_id = xstrprintf ("%d", last.value.syscall_number); | |
6028 | else | |
6029 | syscall_id = xstrprintf ("'%s'", s.name); | |
6030 | ||
6031 | old_chain = make_cleanup (xfree, syscall_id); | |
6032 | ||
6033 | if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) | |
6034 | printf_filtered (_("\nCatchpoint %d (call to syscall %s), "), | |
6035 | b->number, syscall_id); | |
6036 | else if (last.kind == TARGET_WAITKIND_SYSCALL_RETURN) | |
6037 | printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "), | |
6038 | b->number, syscall_id); | |
6039 | ||
6040 | do_cleanups (old_chain); | |
6041 | ||
6042 | return PRINT_SRC_AND_LOC; | |
6043 | } | |
6044 | ||
6045 | /* Implement the "print_one" breakpoint_ops method for syscall | |
6046 | catchpoints. */ | |
6047 | ||
6048 | static void | |
6049 | print_one_catch_syscall (struct breakpoint *b, | |
6050 | struct bp_location **last_loc) | |
6051 | { | |
6052 | struct value_print_options opts; | |
6053 | ||
6054 | get_user_print_options (&opts); | |
6055 | /* Field 4, the address, is omitted (which makes the columns | |
6056 | not line up too nicely with the headers, but the effect | |
6057 | is relatively readable). */ | |
6058 | if (opts.addressprint) | |
6059 | ui_out_field_skip (uiout, "addr"); | |
6060 | annotate_field (5); | |
6061 | ||
6062 | if (b->syscalls_to_be_caught | |
6063 | && VEC_length (int, b->syscalls_to_be_caught) > 1) | |
6064 | ui_out_text (uiout, "syscalls \""); | |
6065 | else | |
6066 | ui_out_text (uiout, "syscall \""); | |
6067 | ||
6068 | if (b->syscalls_to_be_caught) | |
6069 | { | |
6070 | int i, iter; | |
6071 | char *text = xstrprintf ("%s", ""); | |
6072 | for (i = 0; | |
6073 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6074 | i++) | |
6075 | { | |
6076 | char *x = text; | |
6077 | struct syscall s; | |
6078 | get_syscall_by_number (iter, &s); | |
6079 | ||
6080 | if (s.name != NULL) | |
6081 | text = xstrprintf ("%s%s, ", text, s.name); | |
6082 | else | |
6083 | text = xstrprintf ("%s%d, ", text, iter); | |
6084 | ||
6085 | /* We have to xfree the last 'text' (now stored at 'x') | |
6086 | because xstrprintf dinamically allocates new space for it | |
6087 | on every call. */ | |
6088 | xfree (x); | |
6089 | } | |
6090 | /* Remove the last comma. */ | |
6091 | text[strlen (text) - 2] = '\0'; | |
6092 | ui_out_field_string (uiout, "what", text); | |
6093 | } | |
6094 | else | |
6095 | ui_out_field_string (uiout, "what", "<any syscall>"); | |
6096 | ui_out_text (uiout, "\" "); | |
6097 | } | |
6098 | ||
6099 | /* Implement the "print_mention" breakpoint_ops method for syscall | |
6100 | catchpoints. */ | |
6101 | ||
6102 | static void | |
6103 | print_mention_catch_syscall (struct breakpoint *b) | |
6104 | { | |
6105 | if (b->syscalls_to_be_caught) | |
6106 | { | |
6107 | int i, iter; | |
6108 | ||
6109 | if (VEC_length (int, b->syscalls_to_be_caught) > 1) | |
6110 | printf_filtered (_("Catchpoint %d (syscalls"), b->number); | |
6111 | else | |
6112 | printf_filtered (_("Catchpoint %d (syscall"), b->number); | |
6113 | ||
6114 | for (i = 0; | |
6115 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6116 | i++) | |
6117 | { | |
6118 | struct syscall s; | |
6119 | get_syscall_by_number (iter, &s); | |
6120 | ||
6121 | if (s.name) | |
6122 | printf_filtered (" '%s' [%d]", s.name, s.number); | |
6123 | else | |
6124 | printf_filtered (" %d", s.number); | |
6125 | } | |
6126 | printf_filtered (")"); | |
6127 | } | |
6128 | else | |
6129 | printf_filtered (_("Catchpoint %d (any syscall)"), | |
6130 | b->number); | |
6131 | } | |
6132 | ||
6133 | /* The breakpoint_ops structure to be used in syscall catchpoints. */ | |
6134 | ||
6135 | static struct breakpoint_ops catch_syscall_breakpoint_ops = | |
6136 | { | |
6137 | insert_catch_syscall, | |
6138 | remove_catch_syscall, | |
6139 | breakpoint_hit_catch_syscall, | |
6140 | print_it_catch_syscall, | |
6141 | print_one_catch_syscall, | |
6142 | print_mention_catch_syscall | |
6143 | }; | |
6144 | ||
6145 | /* Returns non-zero if 'b' is a syscall catchpoint. */ | |
6146 | ||
6147 | static int | |
6148 | syscall_catchpoint_p (struct breakpoint *b) | |
6149 | { | |
6150 | return (b->ops == &catch_syscall_breakpoint_ops); | |
6151 | } | |
6152 | ||
6153 | /* Create a new breakpoint of the bp_catchpoint kind and return it, | |
6154 | but does NOT mention it nor update the global location list. | |
6155 | This is useful if you need to fill more fields in the | |
6156 | struct breakpoint before calling mention. | |
ce78b96d JB |
6157 | |
6158 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
6159 | If COND_STRING is not NULL, then store it in the breakpoint. | |
6160 | OPS, if not NULL, is the breakpoint_ops structure associated | |
6161 | to the catchpoint. */ | |
6162 | ||
6163 | static struct breakpoint * | |
a96d9b2e SDJ |
6164 | create_catchpoint_without_mention (struct gdbarch *gdbarch, int tempflag, |
6165 | char *cond_string, | |
6166 | struct breakpoint_ops *ops) | |
c906108c | 6167 | { |
c5aa993b JM |
6168 | struct symtab_and_line sal; |
6169 | struct breakpoint *b; | |
c5aa993b | 6170 | |
fe39c653 | 6171 | init_sal (&sal); |
6c95b8df | 6172 | sal.pspace = current_program_space; |
c5aa993b | 6173 | |
a6d9a66e | 6174 | b = set_raw_breakpoint (gdbarch, sal, bp_catchpoint); |
c906108c SS |
6175 | set_breakpoint_count (breakpoint_count + 1); |
6176 | b->number = breakpoint_count; | |
ce78b96d | 6177 | |
1b36a34b | 6178 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
ce78b96d | 6179 | b->thread = -1; |
c906108c | 6180 | b->addr_string = NULL; |
b5de0fa7 EZ |
6181 | b->enable_state = bp_enabled; |
6182 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
ce78b96d | 6183 | b->ops = ops; |
c5aa993b | 6184 | |
a96d9b2e SDJ |
6185 | return b; |
6186 | } | |
6187 | ||
6188 | /* Create a new breakpoint of the bp_catchpoint kind and return it. | |
6189 | ||
6190 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
6191 | If COND_STRING is not NULL, then store it in the breakpoint. | |
6192 | OPS, if not NULL, is the breakpoint_ops structure associated | |
6193 | to the catchpoint. */ | |
6194 | ||
6195 | static struct breakpoint * | |
6196 | create_catchpoint (struct gdbarch *gdbarch, int tempflag, | |
6197 | char *cond_string, struct breakpoint_ops *ops) | |
6198 | { | |
6199 | struct breakpoint *b = | |
6200 | create_catchpoint_without_mention (gdbarch, tempflag, cond_string, ops); | |
6201 | ||
c906108c | 6202 | mention (b); |
ce78b96d | 6203 | update_global_location_list (1); |
c906108c | 6204 | |
ce78b96d | 6205 | return b; |
c906108c | 6206 | } |
c5aa993b | 6207 | |
9b70b993 | 6208 | static void |
a6d9a66e UW |
6209 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
6210 | int tempflag, char *cond_string, | |
ce78b96d | 6211 | struct breakpoint_ops *ops) |
c906108c | 6212 | { |
a6d9a66e UW |
6213 | struct breakpoint *b |
6214 | = create_catchpoint (gdbarch, tempflag, cond_string, ops); | |
ce78b96d JB |
6215 | |
6216 | /* FIXME: We should put this information in a breakpoint private data | |
6217 | area. */ | |
6218 | b->forked_inferior_pid = null_ptid; | |
c906108c SS |
6219 | } |
6220 | ||
fe798b75 JB |
6221 | /* Exec catchpoints. */ |
6222 | ||
9b70b993 | 6223 | static void |
fe798b75 | 6224 | insert_catch_exec (struct breakpoint *b) |
c906108c | 6225 | { |
fe798b75 JB |
6226 | target_insert_exec_catchpoint (PIDGET (inferior_ptid)); |
6227 | } | |
c906108c | 6228 | |
fe798b75 JB |
6229 | static int |
6230 | remove_catch_exec (struct breakpoint *b) | |
6231 | { | |
6232 | return target_remove_exec_catchpoint (PIDGET (inferior_ptid)); | |
6233 | } | |
c906108c | 6234 | |
fe798b75 JB |
6235 | static int |
6236 | breakpoint_hit_catch_exec (struct breakpoint *b) | |
6237 | { | |
6238 | return inferior_has_execd (inferior_ptid, &b->exec_pathname); | |
6239 | } | |
c906108c | 6240 | |
fe798b75 JB |
6241 | static enum print_stop_action |
6242 | print_it_catch_exec (struct breakpoint *b) | |
6243 | { | |
6244 | annotate_catchpoint (b->number); | |
6245 | printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number, | |
6246 | b->exec_pathname); | |
6247 | return PRINT_SRC_AND_LOC; | |
c906108c SS |
6248 | } |
6249 | ||
fe798b75 | 6250 | static void |
a6d9a66e | 6251 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 JB |
6252 | { |
6253 | struct value_print_options opts; | |
6254 | ||
6255 | get_user_print_options (&opts); | |
6256 | ||
6257 | /* Field 4, the address, is omitted (which makes the columns | |
6258 | not line up too nicely with the headers, but the effect | |
6259 | is relatively readable). */ | |
6260 | if (opts.addressprint) | |
6261 | ui_out_field_skip (uiout, "addr"); | |
6262 | annotate_field (5); | |
6263 | ui_out_text (uiout, "exec"); | |
6264 | if (b->exec_pathname != NULL) | |
6265 | { | |
6266 | ui_out_text (uiout, ", program \""); | |
6267 | ui_out_field_string (uiout, "what", b->exec_pathname); | |
6268 | ui_out_text (uiout, "\" "); | |
6269 | } | |
6270 | } | |
6271 | ||
6272 | static void | |
6273 | print_mention_catch_exec (struct breakpoint *b) | |
6274 | { | |
6275 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
6276 | } | |
6277 | ||
6278 | static struct breakpoint_ops catch_exec_breakpoint_ops = | |
6279 | { | |
6280 | insert_catch_exec, | |
6281 | remove_catch_exec, | |
6282 | breakpoint_hit_catch_exec, | |
6283 | print_it_catch_exec, | |
6284 | print_one_catch_exec, | |
6285 | print_mention_catch_exec | |
6286 | }; | |
6287 | ||
a96d9b2e SDJ |
6288 | static void |
6289 | create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, | |
6290 | struct breakpoint_ops *ops) | |
6291 | { | |
6292 | struct gdbarch *gdbarch = get_current_arch (); | |
6293 | struct breakpoint *b = | |
6294 | create_catchpoint_without_mention (gdbarch, tempflag, NULL, ops); | |
6295 | ||
6296 | b->syscalls_to_be_caught = filter; | |
6297 | ||
6298 | /* Now, we have to mention the breakpoint and update the global | |
6299 | location list. */ | |
6300 | mention (b); | |
6301 | update_global_location_list (1); | |
6302 | } | |
6303 | ||
c906108c | 6304 | static int |
fba45db2 | 6305 | hw_breakpoint_used_count (void) |
c906108c | 6306 | { |
52f0bd74 | 6307 | struct breakpoint *b; |
c906108c SS |
6308 | int i = 0; |
6309 | ||
6310 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6311 | { |
d6b74ac4 | 6312 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
c5aa993b JM |
6313 | i++; |
6314 | } | |
c906108c SS |
6315 | |
6316 | return i; | |
6317 | } | |
6318 | ||
6319 | static int | |
fba45db2 | 6320 | hw_watchpoint_used_count (enum bptype type, int *other_type_used) |
c906108c | 6321 | { |
52f0bd74 | 6322 | struct breakpoint *b; |
c906108c SS |
6323 | int i = 0; |
6324 | ||
6325 | *other_type_used = 0; | |
6326 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6327 | { |
468d015d | 6328 | if (breakpoint_enabled (b)) |
c5aa993b JM |
6329 | { |
6330 | if (b->type == type) | |
6331 | i++; | |
059fb39f PM |
6332 | else if ((b->type == bp_hardware_watchpoint |
6333 | || b->type == bp_read_watchpoint | |
6334 | || b->type == bp_access_watchpoint)) | |
c5aa993b JM |
6335 | *other_type_used = 1; |
6336 | } | |
6337 | } | |
c906108c SS |
6338 | return i; |
6339 | } | |
6340 | ||
c906108c | 6341 | void |
fba45db2 | 6342 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 6343 | { |
c5aa993b | 6344 | struct breakpoint *b; |
c906108c SS |
6345 | |
6346 | ALL_BREAKPOINTS (b) | |
c5aa993b JM |
6347 | { |
6348 | if (((b->type == bp_watchpoint) | |
6349 | || (b->type == bp_hardware_watchpoint) | |
6350 | || (b->type == bp_read_watchpoint) | |
dfdfb3ca | 6351 | || (b->type == bp_access_watchpoint)) |
468d015d | 6352 | && breakpoint_enabled (b)) |
c5aa993b | 6353 | { |
b5de0fa7 | 6354 | b->enable_state = bp_call_disabled; |
b60e7edf | 6355 | update_global_location_list (0); |
c5aa993b JM |
6356 | } |
6357 | } | |
c906108c SS |
6358 | } |
6359 | ||
6360 | void | |
fba45db2 | 6361 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 6362 | { |
c5aa993b | 6363 | struct breakpoint *b; |
c906108c SS |
6364 | |
6365 | ALL_BREAKPOINTS (b) | |
c5aa993b JM |
6366 | { |
6367 | if (((b->type == bp_watchpoint) | |
6368 | || (b->type == bp_hardware_watchpoint) | |
6369 | || (b->type == bp_read_watchpoint) | |
dfdfb3ca | 6370 | || (b->type == bp_access_watchpoint)) |
b5de0fa7 | 6371 | && (b->enable_state == bp_call_disabled)) |
c5aa993b | 6372 | { |
b5de0fa7 | 6373 | b->enable_state = bp_enabled; |
b60e7edf | 6374 | update_global_location_list (1); |
c5aa993b JM |
6375 | } |
6376 | } | |
c906108c SS |
6377 | } |
6378 | ||
8bea4e01 UW |
6379 | void |
6380 | disable_breakpoints_before_startup (void) | |
6381 | { | |
6382 | struct breakpoint *b; | |
6383 | int found = 0; | |
6384 | ||
6385 | ALL_BREAKPOINTS (b) | |
6386 | { | |
6c95b8df PA |
6387 | if (b->pspace != current_program_space) |
6388 | continue; | |
6389 | ||
8bea4e01 UW |
6390 | if ((b->type == bp_breakpoint |
6391 | || b->type == bp_hardware_breakpoint) | |
6392 | && breakpoint_enabled (b)) | |
6393 | { | |
6394 | b->enable_state = bp_startup_disabled; | |
6395 | found = 1; | |
6396 | } | |
6397 | } | |
6398 | ||
6399 | if (found) | |
6400 | update_global_location_list (0); | |
6401 | ||
6c95b8df | 6402 | current_program_space->executing_startup = 1; |
8bea4e01 UW |
6403 | } |
6404 | ||
6405 | void | |
6406 | enable_breakpoints_after_startup (void) | |
6407 | { | |
6408 | struct breakpoint *b; | |
6409 | int found = 0; | |
6410 | ||
6c95b8df | 6411 | current_program_space->executing_startup = 0; |
8bea4e01 UW |
6412 | |
6413 | ALL_BREAKPOINTS (b) | |
6414 | { | |
6c95b8df PA |
6415 | if (b->pspace != current_program_space) |
6416 | continue; | |
6417 | ||
8bea4e01 UW |
6418 | if ((b->type == bp_breakpoint |
6419 | || b->type == bp_hardware_breakpoint) | |
6420 | && b->enable_state == bp_startup_disabled) | |
6421 | { | |
6422 | b->enable_state = bp_enabled; | |
6423 | found = 1; | |
6424 | } | |
6425 | } | |
6426 | ||
6427 | if (found) | |
6428 | breakpoint_re_set (); | |
6429 | } | |
6430 | ||
c906108c SS |
6431 | |
6432 | /* Set a breakpoint that will evaporate an end of command | |
6433 | at address specified by SAL. | |
6434 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
6435 | ||
6436 | struct breakpoint * | |
a6d9a66e UW |
6437 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
6438 | struct frame_id frame_id, enum bptype type) | |
c906108c | 6439 | { |
52f0bd74 | 6440 | struct breakpoint *b; |
edb3359d DJ |
6441 | |
6442 | /* If FRAME_ID is valid, it should be a real frame, not an inlined | |
6443 | one. */ | |
6444 | gdb_assert (!frame_id_inlined_p (frame_id)); | |
6445 | ||
a6d9a66e | 6446 | b = set_raw_breakpoint (gdbarch, sal, type); |
b5de0fa7 EZ |
6447 | b->enable_state = bp_enabled; |
6448 | b->disposition = disp_donttouch; | |
818dd999 | 6449 | b->frame_id = frame_id; |
c906108c SS |
6450 | |
6451 | /* If we're debugging a multi-threaded program, then we | |
6452 | want momentary breakpoints to be active in only a | |
6453 | single thread of control. */ | |
39f77062 KB |
6454 | if (in_thread_list (inferior_ptid)) |
6455 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 6456 | |
b60e7edf | 6457 | update_global_location_list_nothrow (1); |
74960c60 | 6458 | |
c906108c SS |
6459 | return b; |
6460 | } | |
611c83ae | 6461 | |
e58b0e63 PA |
6462 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
6463 | ORIG is NULL. */ | |
6464 | ||
6465 | struct breakpoint * | |
6466 | clone_momentary_breakpoint (struct breakpoint *orig) | |
6467 | { | |
6468 | struct breakpoint *copy; | |
6469 | ||
6470 | /* If there's nothing to clone, then return nothing. */ | |
6471 | if (orig == NULL) | |
6472 | return NULL; | |
6473 | ||
a6d9a66e | 6474 | copy = set_raw_breakpoint_without_location (orig->gdbarch, orig->type); |
e58b0e63 PA |
6475 | copy->loc = allocate_bp_location (copy); |
6476 | set_breakpoint_location_function (copy->loc); | |
6477 | ||
a6d9a66e | 6478 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
6479 | copy->loc->requested_address = orig->loc->requested_address; |
6480 | copy->loc->address = orig->loc->address; | |
6481 | copy->loc->section = orig->loc->section; | |
6c95b8df | 6482 | copy->loc->pspace = orig->loc->pspace; |
e58b0e63 PA |
6483 | |
6484 | if (orig->source_file == NULL) | |
6485 | copy->source_file = NULL; | |
6486 | else | |
6487 | copy->source_file = xstrdup (orig->source_file); | |
6488 | ||
6489 | copy->line_number = orig->line_number; | |
6490 | copy->frame_id = orig->frame_id; | |
6491 | copy->thread = orig->thread; | |
6c95b8df | 6492 | copy->pspace = orig->pspace; |
e58b0e63 PA |
6493 | |
6494 | copy->enable_state = bp_enabled; | |
6495 | copy->disposition = disp_donttouch; | |
6496 | copy->number = internal_breakpoint_number--; | |
6497 | ||
6498 | update_global_location_list_nothrow (0); | |
6499 | return copy; | |
6500 | } | |
6501 | ||
611c83ae | 6502 | struct breakpoint * |
a6d9a66e UW |
6503 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
6504 | enum bptype type) | |
611c83ae PA |
6505 | { |
6506 | struct symtab_and_line sal; | |
6507 | ||
6508 | sal = find_pc_line (pc, 0); | |
6509 | sal.pc = pc; | |
6510 | sal.section = find_pc_overlay (pc); | |
6511 | sal.explicit_pc = 1; | |
6512 | ||
a6d9a66e | 6513 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 6514 | } |
c906108c | 6515 | \f |
c5aa993b | 6516 | |
c906108c SS |
6517 | /* Tell the user we have just set a breakpoint B. */ |
6518 | ||
6519 | static void | |
fba45db2 | 6520 | mention (struct breakpoint *b) |
c906108c SS |
6521 | { |
6522 | int say_where = 0; | |
fa8a61dc | 6523 | struct cleanup *ui_out_chain; |
79a45b7d TT |
6524 | struct value_print_options opts; |
6525 | ||
6526 | get_user_print_options (&opts); | |
8b93c638 | 6527 | |
9a4105ab AC |
6528 | /* FIXME: This is misplaced; mention() is called by things (like |
6529 | hitting a watchpoint) other than breakpoint creation. It should | |
6530 | be possible to clean this up and at the same time replace the | |
7f4b89d1 | 6531 | random calls to breakpoint_changed with this hook. */ |
383f836e | 6532 | observer_notify_breakpoint_created (b->number); |
c906108c | 6533 | |
3086aeae DJ |
6534 | if (b->ops != NULL && b->ops->print_mention != NULL) |
6535 | b->ops->print_mention (b); | |
6536 | else | |
6537 | switch (b->type) | |
6538 | { | |
6539 | case bp_none: | |
a3f17187 | 6540 | printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b->number); |
3086aeae DJ |
6541 | break; |
6542 | case bp_watchpoint: | |
6543 | ui_out_text (uiout, "Watchpoint "); | |
6544 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
6545 | ui_out_field_int (uiout, "number", b->number); | |
6546 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6547 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6548 | do_cleanups (ui_out_chain); |
6549 | break; | |
6550 | case bp_hardware_watchpoint: | |
6551 | ui_out_text (uiout, "Hardware watchpoint "); | |
6552 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
6553 | ui_out_field_int (uiout, "number", b->number); | |
6554 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6555 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6556 | do_cleanups (ui_out_chain); |
6557 | break; | |
6558 | case bp_read_watchpoint: | |
6559 | ui_out_text (uiout, "Hardware read watchpoint "); | |
6560 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
6561 | ui_out_field_int (uiout, "number", b->number); | |
6562 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6563 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6564 | do_cleanups (ui_out_chain); |
6565 | break; | |
6566 | case bp_access_watchpoint: | |
6567 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
6568 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
6569 | ui_out_field_int (uiout, "number", b->number); | |
6570 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6571 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6572 | do_cleanups (ui_out_chain); |
6573 | break; | |
6574 | case bp_breakpoint: | |
6575 | if (ui_out_is_mi_like_p (uiout)) | |
6576 | { | |
6577 | say_where = 0; | |
6578 | break; | |
6579 | } | |
2cec12e5 AR |
6580 | if (b->disposition == disp_del) |
6581 | printf_filtered (_("Temporary breakpoint")); | |
6582 | else | |
6583 | printf_filtered (_("Breakpoint")); | |
6584 | printf_filtered (_(" %d"), b->number); | |
3086aeae DJ |
6585 | say_where = 1; |
6586 | break; | |
6587 | case bp_hardware_breakpoint: | |
6588 | if (ui_out_is_mi_like_p (uiout)) | |
6589 | { | |
6590 | say_where = 0; | |
6591 | break; | |
6592 | } | |
a3f17187 | 6593 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); |
3086aeae DJ |
6594 | say_where = 1; |
6595 | break; | |
1042e4c0 SS |
6596 | case bp_tracepoint: |
6597 | if (ui_out_is_mi_like_p (uiout)) | |
6598 | { | |
6599 | say_where = 0; | |
6600 | break; | |
6601 | } | |
6602 | printf_filtered (_("Tracepoint")); | |
6603 | printf_filtered (_(" %d"), b->number); | |
6604 | say_where = 1; | |
6605 | break; | |
7a697b8d SS |
6606 | case bp_fast_tracepoint: |
6607 | if (ui_out_is_mi_like_p (uiout)) | |
6608 | { | |
6609 | say_where = 0; | |
6610 | break; | |
6611 | } | |
6612 | printf_filtered (_("Fast tracepoint")); | |
6613 | printf_filtered (_(" %d"), b->number); | |
6614 | say_where = 1; | |
6615 | break; | |
3086aeae DJ |
6616 | |
6617 | case bp_until: | |
6618 | case bp_finish: | |
6619 | case bp_longjmp: | |
6620 | case bp_longjmp_resume: | |
6621 | case bp_step_resume: | |
3086aeae | 6622 | case bp_call_dummy: |
aa7d318d | 6623 | case bp_std_terminate: |
3086aeae DJ |
6624 | case bp_watchpoint_scope: |
6625 | case bp_shlib_event: | |
6626 | case bp_thread_event: | |
6627 | case bp_overlay_event: | |
4efc6507 | 6628 | case bp_jit_event: |
0fd8e87f | 6629 | case bp_longjmp_master: |
aa7d318d | 6630 | case bp_std_terminate_master: |
3086aeae DJ |
6631 | break; |
6632 | } | |
c906108c | 6633 | |
c906108c SS |
6634 | if (say_where) |
6635 | { | |
a3f17187 AC |
6636 | /* i18n: cagney/2005-02-11: Below needs to be merged into a |
6637 | single string. */ | |
0d381245 | 6638 | if (b->loc == NULL) |
c906108c | 6639 | { |
a3f17187 | 6640 | printf_filtered (_(" (%s) pending."), b->addr_string); |
0101ce28 JJ |
6641 | } |
6642 | else | |
6643 | { | |
79a45b7d | 6644 | if (opts.addressprint || b->source_file == NULL) |
0101ce28 JJ |
6645 | { |
6646 | printf_filtered (" at "); | |
5af949e3 UW |
6647 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), |
6648 | gdb_stdout); | |
0101ce28 JJ |
6649 | } |
6650 | if (b->source_file) | |
6651 | printf_filtered (": file %s, line %d.", | |
6652 | b->source_file, b->line_number); | |
0d381245 VP |
6653 | |
6654 | if (b->loc->next) | |
6655 | { | |
6656 | struct bp_location *loc = b->loc; | |
6657 | int n = 0; | |
6658 | for (; loc; loc = loc->next) | |
6659 | ++n; | |
6660 | printf_filtered (" (%d locations)", n); | |
6661 | } | |
6662 | ||
c906108c | 6663 | } |
c906108c | 6664 | } |
9dc5e2a9 | 6665 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 6666 | return; |
c906108c SS |
6667 | printf_filtered ("\n"); |
6668 | } | |
c906108c | 6669 | \f |
c5aa993b | 6670 | |
0d381245 | 6671 | static struct bp_location * |
39d61571 | 6672 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
6673 | const struct symtab_and_line *sal) |
6674 | { | |
6675 | struct bp_location *loc, **tmp; | |
6676 | ||
39d61571 | 6677 | loc = allocate_bp_location (b); |
0d381245 VP |
6678 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
6679 | ; | |
6680 | *tmp = loc; | |
a6d9a66e UW |
6681 | loc->gdbarch = get_sal_arch (*sal); |
6682 | if (!loc->gdbarch) | |
6683 | loc->gdbarch = b->gdbarch; | |
0d381245 | 6684 | loc->requested_address = sal->pc; |
a6d9a66e UW |
6685 | loc->address = adjust_breakpoint_address (loc->gdbarch, |
6686 | loc->requested_address, b->type); | |
6c95b8df PA |
6687 | loc->pspace = sal->pspace; |
6688 | gdb_assert (loc->pspace != NULL); | |
0d381245 VP |
6689 | loc->section = sal->section; |
6690 | ||
6691 | set_breakpoint_location_function (loc); | |
6692 | return loc; | |
6693 | } | |
514f746b AR |
6694 | \f |
6695 | ||
6696 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
6697 | return 0 otherwise. */ | |
6698 | ||
6699 | static int | |
6700 | bp_loc_is_permanent (struct bp_location *loc) | |
6701 | { | |
6702 | int len; | |
6703 | CORE_ADDR addr; | |
6704 | const gdb_byte *brk; | |
6705 | gdb_byte *target_mem; | |
939c61fa JK |
6706 | struct cleanup *cleanup; |
6707 | int retval = 0; | |
514f746b AR |
6708 | |
6709 | gdb_assert (loc != NULL); | |
6710 | ||
6711 | addr = loc->address; | |
a6d9a66e | 6712 | brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 6713 | |
939c61fa JK |
6714 | /* Software breakpoints unsupported? */ |
6715 | if (brk == NULL) | |
6716 | return 0; | |
6717 | ||
514f746b AR |
6718 | target_mem = alloca (len); |
6719 | ||
939c61fa JK |
6720 | /* Enable the automatic memory restoration from breakpoints while |
6721 | we read the memory. Otherwise we could say about our temporary | |
6722 | breakpoints they are permanent. */ | |
6c95b8df PA |
6723 | cleanup = save_current_space_and_thread (); |
6724 | ||
6725 | switch_to_program_space_and_thread (loc->pspace); | |
6726 | make_show_memory_breakpoints_cleanup (0); | |
939c61fa | 6727 | |
514f746b AR |
6728 | if (target_read_memory (loc->address, target_mem, len) == 0 |
6729 | && memcmp (target_mem, brk, len) == 0) | |
939c61fa | 6730 | retval = 1; |
514f746b | 6731 | |
939c61fa JK |
6732 | do_cleanups (cleanup); |
6733 | ||
6734 | return retval; | |
514f746b AR |
6735 | } |
6736 | ||
6737 | ||
c3f6f71d | 6738 | |
018d34a4 VP |
6739 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
6740 | as textual description of the location, and COND_STRING | |
db107f19 | 6741 | as condition expression. */ |
018d34a4 VP |
6742 | |
6743 | static void | |
8cdf0e15 VP |
6744 | create_breakpoint_sal (struct gdbarch *gdbarch, |
6745 | struct symtabs_and_lines sals, char *addr_string, | |
6746 | char *cond_string, | |
6747 | enum bptype type, enum bpdisp disposition, | |
6748 | int thread, int task, int ignore_count, | |
6749 | struct breakpoint_ops *ops, int from_tty, int enabled) | |
018d34a4 | 6750 | { |
0d381245 VP |
6751 | struct breakpoint *b = NULL; |
6752 | int i; | |
018d34a4 VP |
6753 | |
6754 | if (type == bp_hardware_breakpoint) | |
6755 | { | |
6756 | int i = hw_breakpoint_used_count (); | |
6757 | int target_resources_ok = | |
d92524f1 | 6758 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
018d34a4 VP |
6759 | i + 1, 0); |
6760 | if (target_resources_ok == 0) | |
6761 | error (_("No hardware breakpoint support in the target.")); | |
6762 | else if (target_resources_ok < 0) | |
6763 | error (_("Hardware breakpoints used exceeds limit.")); | |
6764 | } | |
6765 | ||
6c95b8df PA |
6766 | gdb_assert (sals.nelts > 0); |
6767 | ||
0d381245 VP |
6768 | for (i = 0; i < sals.nelts; ++i) |
6769 | { | |
6770 | struct symtab_and_line sal = sals.sals[i]; | |
6771 | struct bp_location *loc; | |
6772 | ||
6773 | if (from_tty) | |
5af949e3 UW |
6774 | { |
6775 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
6776 | if (!loc_gdbarch) | |
6777 | loc_gdbarch = gdbarch; | |
6778 | ||
6779 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 6780 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 6781 | } |
0d381245 VP |
6782 | |
6783 | if (i == 0) | |
6784 | { | |
a6d9a66e | 6785 | b = set_raw_breakpoint (gdbarch, sal, type); |
0d381245 VP |
6786 | set_breakpoint_count (breakpoint_count + 1); |
6787 | b->number = breakpoint_count; | |
6788 | b->thread = thread; | |
4a306c9a | 6789 | b->task = task; |
018d34a4 | 6790 | |
0d381245 VP |
6791 | b->cond_string = cond_string; |
6792 | b->ignore_count = ignore_count; | |
41447f92 | 6793 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 6794 | b->disposition = disposition; |
018d34a4 | 6795 | |
6c95b8df PA |
6796 | b->pspace = sals.sals[0].pspace; |
6797 | ||
6798 | if (enabled && b->pspace->executing_startup | |
8bea4e01 UW |
6799 | && (b->type == bp_breakpoint |
6800 | || b->type == bp_hardware_breakpoint)) | |
6801 | b->enable_state = bp_startup_disabled; | |
6802 | ||
0d381245 VP |
6803 | loc = b->loc; |
6804 | } | |
6805 | else | |
018d34a4 | 6806 | { |
39d61571 | 6807 | loc = add_location_to_breakpoint (b, &sal); |
0d381245 VP |
6808 | } |
6809 | ||
514f746b AR |
6810 | if (bp_loc_is_permanent (loc)) |
6811 | make_breakpoint_permanent (b); | |
6812 | ||
0d381245 VP |
6813 | if (b->cond_string) |
6814 | { | |
6815 | char *arg = b->cond_string; | |
d32a6982 | 6816 | loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0); |
0d381245 | 6817 | if (*arg) |
db107f19 | 6818 | error (_("Garbage %s follows condition"), arg); |
018d34a4 | 6819 | } |
0d381245 | 6820 | } |
018d34a4 VP |
6821 | |
6822 | if (addr_string) | |
6823 | b->addr_string = addr_string; | |
6824 | else | |
6825 | /* addr_string has to be used or breakpoint_re_set will delete | |
6826 | me. */ | |
5af949e3 UW |
6827 | b->addr_string |
6828 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
018d34a4 | 6829 | |
604133b5 | 6830 | b->ops = ops; |
018d34a4 VP |
6831 | mention (b); |
6832 | } | |
6833 | ||
ed0616c6 VP |
6834 | /* Remove element at INDEX_TO_REMOVE from SAL, shifting other |
6835 | elements to fill the void space. */ | |
2c0b251b PA |
6836 | static void |
6837 | remove_sal (struct symtabs_and_lines *sal, int index_to_remove) | |
ed0616c6 VP |
6838 | { |
6839 | int i = index_to_remove+1; | |
6840 | int last_index = sal->nelts-1; | |
6841 | ||
6842 | for (;i <= last_index; ++i) | |
6843 | sal->sals[i-1] = sal->sals[i]; | |
6844 | ||
6845 | --(sal->nelts); | |
6846 | } | |
6847 | ||
6c95b8df PA |
6848 | /* If appropriate, obtains all sals that correspond to the same file |
6849 | and line as SAL, in all program spaces. Users debugging with IDEs, | |
6850 | will want to set a breakpoint at foo.c:line, and not really care | |
6851 | about program spaces. This is done only if SAL does not have | |
6852 | explicit PC and has line and file information. If we got just a | |
6853 | single expanded sal, return the original. | |
ed0616c6 | 6854 | |
6c95b8df PA |
6855 | Otherwise, if SAL.explicit_line is not set, filter out all sals for |
6856 | which the name of enclosing function is different from SAL. This | |
6857 | makes sure that if we have breakpoint originally set in template | |
6858 | instantiation, say foo<int>(), we won't expand SAL to locations at | |
6859 | the same line in all existing instantiations of 'foo'. */ | |
ed0616c6 | 6860 | |
2c0b251b | 6861 | static struct symtabs_and_lines |
ed0616c6 VP |
6862 | expand_line_sal_maybe (struct symtab_and_line sal) |
6863 | { | |
6864 | struct symtabs_and_lines expanded; | |
6865 | CORE_ADDR original_pc = sal.pc; | |
6866 | char *original_function = NULL; | |
6867 | int found; | |
6868 | int i; | |
6c95b8df | 6869 | struct cleanup *old_chain; |
ed0616c6 VP |
6870 | |
6871 | /* If we have explicit pc, don't expand. | |
6872 | If we have no line number, we can't expand. */ | |
6873 | if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL) | |
6874 | { | |
6875 | expanded.nelts = 1; | |
6876 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
6877 | expanded.sals[0] = sal; | |
6878 | return expanded; | |
6879 | } | |
6880 | ||
6881 | sal.pc = 0; | |
6c95b8df PA |
6882 | |
6883 | old_chain = save_current_space_and_thread (); | |
6884 | ||
6885 | switch_to_program_space_and_thread (sal.pspace); | |
6886 | ||
ed0616c6 | 6887 | find_pc_partial_function (original_pc, &original_function, NULL, NULL); |
6c95b8df PA |
6888 | |
6889 | /* Note that expand_line_sal visits *all* program spaces. */ | |
ed0616c6 | 6890 | expanded = expand_line_sal (sal); |
6c95b8df | 6891 | |
ed0616c6 VP |
6892 | if (expanded.nelts == 1) |
6893 | { | |
3dba1c98 JB |
6894 | /* We had one sal, we got one sal. Return that sal, adjusting it |
6895 | past the function prologue if necessary. */ | |
ed0616c6 VP |
6896 | xfree (expanded.sals); |
6897 | expanded.nelts = 1; | |
6898 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
6899 | sal.pc = original_pc; | |
6900 | expanded.sals[0] = sal; | |
3dba1c98 | 6901 | skip_prologue_sal (&expanded.sals[0]); |
6c95b8df | 6902 | do_cleanups (old_chain); |
ed0616c6 VP |
6903 | return expanded; |
6904 | } | |
6905 | ||
6906 | if (!sal.explicit_line) | |
6907 | { | |
6908 | CORE_ADDR func_addr, func_end; | |
6909 | for (i = 0; i < expanded.nelts; ++i) | |
6910 | { | |
6911 | CORE_ADDR pc = expanded.sals[i].pc; | |
6912 | char *this_function; | |
6c95b8df PA |
6913 | |
6914 | /* We need to switch threads as well since we're about to | |
6915 | read memory. */ | |
6916 | switch_to_program_space_and_thread (expanded.sals[i].pspace); | |
6917 | ||
ed0616c6 VP |
6918 | if (find_pc_partial_function (pc, &this_function, |
6919 | &func_addr, &func_end)) | |
6920 | { | |
059fb39f PM |
6921 | if (this_function |
6922 | && strcmp (this_function, original_function) != 0) | |
ed0616c6 VP |
6923 | { |
6924 | remove_sal (&expanded, i); | |
6925 | --i; | |
6926 | } | |
ed0616c6 VP |
6927 | } |
6928 | } | |
6929 | } | |
059acae7 UW |
6930 | |
6931 | /* Skip the function prologue if necessary. */ | |
6932 | for (i = 0; i < expanded.nelts; ++i) | |
6933 | skip_prologue_sal (&expanded.sals[i]); | |
ed0616c6 | 6934 | |
6c95b8df PA |
6935 | do_cleanups (old_chain); |
6936 | ||
ed0616c6 VP |
6937 | if (expanded.nelts <= 1) |
6938 | { | |
6939 | /* This is un ugly workaround. If we get zero | |
6940 | expanded sals then something is really wrong. | |
6941 | Fix that by returnign the original sal. */ | |
6942 | xfree (expanded.sals); | |
6943 | expanded.nelts = 1; | |
6944 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
6945 | sal.pc = original_pc; | |
6946 | expanded.sals[0] = sal; | |
6947 | return expanded; | |
6948 | } | |
6949 | ||
6950 | if (original_pc) | |
6951 | { | |
6952 | found = 0; | |
6953 | for (i = 0; i < expanded.nelts; ++i) | |
6954 | if (expanded.sals[i].pc == original_pc) | |
6955 | { | |
6956 | found = 1; | |
6957 | break; | |
6958 | } | |
6959 | gdb_assert (found); | |
6960 | } | |
6961 | ||
6962 | return expanded; | |
6963 | } | |
6964 | ||
018d34a4 VP |
6965 | /* Add SALS.nelts breakpoints to the breakpoint table. For each |
6966 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
6967 | value. COND_STRING, if not NULL, specified the condition to be | |
6968 | used for all breakpoints. Essentially the only case where | |
6969 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
6970 | function. In that case, it's still not possible to specify | |
6971 | separate conditions for different overloaded functions, so | |
6972 | we take just a single condition string. | |
6973 | ||
c3f6f71d | 6974 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 6975 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
6976 | array contents). If the function fails (error() is called), the |
6977 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
6978 | COND and SALS arrays and each of those arrays contents. */ | |
c906108c SS |
6979 | |
6980 | static void | |
8cdf0e15 VP |
6981 | create_breakpoints_sal (struct gdbarch *gdbarch, |
6982 | struct symtabs_and_lines sals, char **addr_string, | |
6983 | char *cond_string, | |
6984 | enum bptype type, enum bpdisp disposition, | |
6985 | int thread, int task, int ignore_count, | |
6986 | struct breakpoint_ops *ops, int from_tty, | |
6987 | int enabled) | |
c906108c | 6988 | { |
018d34a4 VP |
6989 | int i; |
6990 | for (i = 0; i < sals.nelts; ++i) | |
c3f6f71d | 6991 | { |
ed0616c6 VP |
6992 | struct symtabs_and_lines expanded = |
6993 | expand_line_sal_maybe (sals.sals[i]); | |
0d381245 | 6994 | |
8cdf0e15 VP |
6995 | create_breakpoint_sal (gdbarch, expanded, addr_string[i], |
6996 | cond_string, type, disposition, | |
6997 | thread, task, ignore_count, ops, from_tty, enabled); | |
c3f6f71d | 6998 | } |
c3f6f71d | 6999 | } |
c906108c | 7000 | |
c3f6f71d JM |
7001 | /* Parse ARG which is assumed to be a SAL specification possibly |
7002 | followed by conditionals. On return, SALS contains an array of SAL | |
7003 | addresses found. ADDR_STRING contains a vector of (canonical) | |
7004 | address strings. ARG points to the end of the SAL. */ | |
c906108c | 7005 | |
b9362cc7 | 7006 | static void |
c3f6f71d JM |
7007 | parse_breakpoint_sals (char **address, |
7008 | struct symtabs_and_lines *sals, | |
0101ce28 JJ |
7009 | char ***addr_string, |
7010 | int *not_found_ptr) | |
c3f6f71d JM |
7011 | { |
7012 | char *addr_start = *address; | |
7013 | *addr_string = NULL; | |
7014 | /* If no arg given, or if first arg is 'if ', use the default | |
7015 | breakpoint. */ | |
7016 | if ((*address) == NULL | |
7017 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c SS |
7018 | { |
7019 | if (default_breakpoint_valid) | |
7020 | { | |
c3f6f71d | 7021 | struct symtab_and_line sal; |
fe39c653 | 7022 | init_sal (&sal); /* initialize to zeroes */ |
c3f6f71d | 7023 | sals->sals = (struct symtab_and_line *) |
c906108c SS |
7024 | xmalloc (sizeof (struct symtab_and_line)); |
7025 | sal.pc = default_breakpoint_address; | |
7026 | sal.line = default_breakpoint_line; | |
7027 | sal.symtab = default_breakpoint_symtab; | |
6c95b8df | 7028 | sal.pspace = default_breakpoint_pspace; |
c5aa993b | 7029 | sal.section = find_pc_overlay (sal.pc); |
00903456 JK |
7030 | |
7031 | /* "break" without arguments is equivalent to "break *PC" where PC is | |
7032 | the default_breakpoint_address. So make sure to set | |
7033 | sal.explicit_pc to prevent GDB from trying to expand the list of | |
7034 | sals to include all other instances with the same symtab and line. | |
7035 | */ | |
7036 | sal.explicit_pc = 1; | |
7037 | ||
c3f6f71d JM |
7038 | sals->sals[0] = sal; |
7039 | sals->nelts = 1; | |
c906108c SS |
7040 | } |
7041 | else | |
8a3fe4f8 | 7042 | error (_("No default breakpoint address now.")); |
c906108c SS |
7043 | } |
7044 | else | |
7045 | { | |
c906108c | 7046 | /* Force almost all breakpoints to be in terms of the |
c5aa993b JM |
7047 | current_source_symtab (which is decode_line_1's default). This |
7048 | should produce the results we want almost all of the time while | |
1aeae86e AF |
7049 | leaving default_breakpoint_* alone. |
7050 | ObjC: However, don't match an Objective-C method name which | |
7051 | may have a '+' or '-' succeeded by a '[' */ | |
0378c332 | 7052 | |
c214a6fd | 7053 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
0378c332 | 7054 | |
c906108c | 7055 | if (default_breakpoint_valid |
0378c332 | 7056 | && (!cursal.symtab |
1aeae86e AF |
7057 | || ((strchr ("+-", (*address)[0]) != NULL) |
7058 | && ((*address)[1] != '[')))) | |
c3f6f71d | 7059 | *sals = decode_line_1 (address, 1, default_breakpoint_symtab, |
0101ce28 JJ |
7060 | default_breakpoint_line, addr_string, |
7061 | not_found_ptr); | |
c906108c | 7062 | else |
0101ce28 JJ |
7063 | *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, |
7064 | addr_string, not_found_ptr); | |
c906108c | 7065 | } |
c3f6f71d JM |
7066 | /* For any SAL that didn't have a canonical string, fill one in. */ |
7067 | if (sals->nelts > 0 && *addr_string == NULL) | |
7068 | *addr_string = xcalloc (sals->nelts, sizeof (char **)); | |
7069 | if (addr_start != (*address)) | |
c906108c | 7070 | { |
c3f6f71d JM |
7071 | int i; |
7072 | for (i = 0; i < sals->nelts; i++) | |
c906108c | 7073 | { |
c3f6f71d JM |
7074 | /* Add the string if not present. */ |
7075 | if ((*addr_string)[i] == NULL) | |
7076 | (*addr_string)[i] = savestring (addr_start, (*address) - addr_start); | |
c906108c SS |
7077 | } |
7078 | } | |
c3f6f71d | 7079 | } |
c906108c | 7080 | |
c906108c | 7081 | |
c3f6f71d JM |
7082 | /* Convert each SAL into a real PC. Verify that the PC can be |
7083 | inserted as a breakpoint. If it can't throw an error. */ | |
c906108c | 7084 | |
b9362cc7 | 7085 | static void |
c3f6f71d JM |
7086 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals, |
7087 | char *address) | |
7088 | { | |
7089 | int i; | |
7090 | for (i = 0; i < sals->nelts; i++) | |
ee53e872 | 7091 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
7092 | } |
7093 | ||
7a697b8d SS |
7094 | /* Fast tracepoints may have restrictions on valid locations. For |
7095 | instance, a fast tracepoint using a jump instead of a trap will | |
7096 | likely have to overwrite more bytes than a trap would, and so can | |
7097 | only be placed where the instruction is longer than the jump, or a | |
7098 | multi-instruction sequence does not have a jump into the middle of | |
7099 | it, etc. */ | |
7100 | ||
7101 | static void | |
7102 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
7103 | struct symtabs_and_lines *sals) | |
7104 | { | |
7105 | int i, rslt; | |
7106 | struct symtab_and_line *sal; | |
7107 | char *msg; | |
7108 | struct cleanup *old_chain; | |
7109 | ||
7110 | for (i = 0; i < sals->nelts; i++) | |
7111 | { | |
7112 | sal = &sals->sals[i]; | |
7113 | ||
7114 | rslt = gdbarch_fast_tracepoint_valid_at (gdbarch, sal->pc, | |
7115 | NULL, &msg); | |
7116 | old_chain = make_cleanup (xfree, msg); | |
7117 | ||
7118 | if (!rslt) | |
7119 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
7120 | paddress (gdbarch, sal->pc), (msg ? msg : "")); | |
7121 | ||
7122 | do_cleanups (old_chain); | |
7123 | } | |
7124 | } | |
7125 | ||
05ff989b | 7126 | static void |
0101ce28 JJ |
7127 | do_captured_parse_breakpoint (struct ui_out *ui, void *data) |
7128 | { | |
7129 | struct captured_parse_breakpoint_args *args = data; | |
7130 | ||
7131 | parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p, | |
7132 | args->not_found_ptr); | |
0101ce28 JJ |
7133 | } |
7134 | ||
018d34a4 VP |
7135 | /* Given TOK, a string specification of condition and thread, as |
7136 | accepted by the 'break' command, extract the condition | |
7137 | string and thread number and set *COND_STRING and *THREAD. | |
7138 | PC identifies the context at which the condition should be parsed. | |
7139 | If no condition is found, *COND_STRING is set to NULL. | |
7140 | If no thread is found, *THREAD is set to -1. */ | |
7141 | static void | |
7142 | find_condition_and_thread (char *tok, CORE_ADDR pc, | |
4a306c9a | 7143 | char **cond_string, int *thread, int *task) |
018d34a4 VP |
7144 | { |
7145 | *cond_string = NULL; | |
7146 | *thread = -1; | |
7147 | while (tok && *tok) | |
7148 | { | |
7149 | char *end_tok; | |
7150 | int toklen; | |
7151 | char *cond_start = NULL; | |
7152 | char *cond_end = NULL; | |
7153 | while (*tok == ' ' || *tok == '\t') | |
7154 | tok++; | |
7155 | ||
7156 | end_tok = tok; | |
7157 | ||
7158 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
7159 | end_tok++; | |
7160 | ||
7161 | toklen = end_tok - tok; | |
7162 | ||
7163 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
7164 | { | |
f7545552 TT |
7165 | struct expression *expr; |
7166 | ||
018d34a4 | 7167 | tok = cond_start = end_tok + 1; |
f7545552 TT |
7168 | expr = parse_exp_1 (&tok, block_for_pc (pc), 0); |
7169 | xfree (expr); | |
018d34a4 VP |
7170 | cond_end = tok; |
7171 | *cond_string = savestring (cond_start, | |
7172 | cond_end - cond_start); | |
7173 | } | |
7174 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
7175 | { | |
7176 | char *tmptok; | |
7177 | ||
7178 | tok = end_tok + 1; | |
7179 | tmptok = tok; | |
7180 | *thread = strtol (tok, &tok, 0); | |
7181 | if (tok == tmptok) | |
7182 | error (_("Junk after thread keyword.")); | |
7183 | if (!valid_thread_id (*thread)) | |
7184 | error (_("Unknown thread %d."), *thread); | |
7185 | } | |
4a306c9a JB |
7186 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
7187 | { | |
7188 | char *tmptok; | |
7189 | ||
7190 | tok = end_tok + 1; | |
7191 | tmptok = tok; | |
7192 | *task = strtol (tok, &tok, 0); | |
7193 | if (tok == tmptok) | |
7194 | error (_("Junk after task keyword.")); | |
7195 | if (!valid_task_id (*task)) | |
b6199126 | 7196 | error (_("Unknown task %d."), *task); |
4a306c9a | 7197 | } |
018d34a4 VP |
7198 | else |
7199 | error (_("Junk at end of arguments.")); | |
7200 | } | |
7201 | } | |
7202 | ||
fd9b8c24 PA |
7203 | /* Set a breakpoint. This function is shared between CLI and MI |
7204 | functions for setting a breakpoint. This function has two major | |
7205 | modes of operations, selected by the PARSE_CONDITION_AND_THREAD | |
7206 | parameter. If non-zero, the function will parse arg, extracting | |
7207 | breakpoint location, address and thread. Otherwise, ARG is just the | |
7208 | location of breakpoint, with condition and thread specified by the | |
7209 | COND_STRING and THREAD parameters. Returns true if any breakpoint | |
7210 | was created; false otherwise. */ | |
0101ce28 | 7211 | |
8cdf0e15 VP |
7212 | int |
7213 | create_breakpoint (struct gdbarch *gdbarch, | |
7214 | char *arg, char *cond_string, int thread, | |
7215 | int parse_condition_and_thread, | |
7216 | int tempflag, int hardwareflag, int traceflag, | |
7217 | int ignore_count, | |
7218 | enum auto_boolean pending_break_support, | |
7219 | struct breakpoint_ops *ops, | |
7220 | int from_tty, | |
7221 | int enabled) | |
c3f6f71d | 7222 | { |
71fff37b | 7223 | struct gdb_exception e; |
c3f6f71d | 7224 | struct symtabs_and_lines sals; |
0101ce28 | 7225 | struct symtab_and_line pending_sal; |
0101ce28 JJ |
7226 | char *copy_arg; |
7227 | char *err_msg; | |
c3f6f71d JM |
7228 | char *addr_start = arg; |
7229 | char **addr_string; | |
7230 | struct cleanup *old_chain; | |
80c99de1 | 7231 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 7232 | struct captured_parse_breakpoint_args parse_args; |
05ff989b | 7233 | int i; |
0101ce28 | 7234 | int pending = 0; |
0101ce28 | 7235 | int not_found = 0; |
1042e4c0 | 7236 | enum bptype type_wanted; |
4a306c9a | 7237 | int task = 0; |
95a42b64 | 7238 | int first_bp_set = breakpoint_count + 1; |
c3f6f71d | 7239 | |
c3f6f71d JM |
7240 | sals.sals = NULL; |
7241 | sals.nelts = 0; | |
7242 | addr_string = NULL; | |
c3f6f71d | 7243 | |
0101ce28 JJ |
7244 | parse_args.arg_p = &arg; |
7245 | parse_args.sals_p = &sals; | |
7246 | parse_args.addr_string_p = &addr_string; | |
7247 | parse_args.not_found_ptr = ¬_found; | |
7248 | ||
05ff989b AC |
7249 | e = catch_exception (uiout, do_captured_parse_breakpoint, |
7250 | &parse_args, RETURN_MASK_ALL); | |
0101ce28 JJ |
7251 | |
7252 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 7253 | switch (e.reason) |
0101ce28 | 7254 | { |
05ff989b | 7255 | case RETURN_QUIT: |
98deb0da | 7256 | throw_exception (e); |
05ff989b AC |
7257 | case RETURN_ERROR: |
7258 | switch (e.error) | |
0101ce28 | 7259 | { |
05ff989b | 7260 | case NOT_FOUND_ERROR: |
0101ce28 | 7261 | |
05ff989b AC |
7262 | /* If pending breakpoint support is turned off, throw |
7263 | error. */ | |
fa8d40ab JJ |
7264 | |
7265 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
7266 | throw_exception (e); |
7267 | ||
7268 | exception_print (gdb_stderr, e); | |
fa8d40ab | 7269 | |
05ff989b AC |
7270 | /* If pending breakpoint support is auto query and the user |
7271 | selects no, then simply return the error code. */ | |
059fb39f PM |
7272 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
7273 | && !nquery ("Make breakpoint pending on future shared library load? ")) | |
fd9b8c24 | 7274 | return 0; |
fa8d40ab | 7275 | |
05ff989b AC |
7276 | /* At this point, either the user was queried about setting |
7277 | a pending breakpoint and selected yes, or pending | |
7278 | breakpoint behavior is on and thus a pending breakpoint | |
7279 | is defaulted on behalf of the user. */ | |
0101ce28 JJ |
7280 | copy_arg = xstrdup (addr_start); |
7281 | addr_string = ©_arg; | |
7282 | sals.nelts = 1; | |
7283 | sals.sals = &pending_sal; | |
7284 | pending_sal.pc = 0; | |
7285 | pending = 1; | |
05ff989b AC |
7286 | break; |
7287 | default: | |
98deb0da | 7288 | throw_exception (e); |
0101ce28 | 7289 | } |
05ff989b AC |
7290 | default: |
7291 | if (!sals.nelts) | |
fd9b8c24 | 7292 | return 0; |
0101ce28 | 7293 | } |
c3f6f71d JM |
7294 | |
7295 | /* Create a chain of things that always need to be cleaned up. */ | |
7296 | old_chain = make_cleanup (null_cleanup, 0); | |
7297 | ||
0101ce28 JJ |
7298 | if (!pending) |
7299 | { | |
7300 | /* Make sure that all storage allocated to SALS gets freed. */ | |
7301 | make_cleanup (xfree, sals.sals); | |
7302 | ||
7303 | /* Cleanup the addr_string array but not its contents. */ | |
7304 | make_cleanup (xfree, addr_string); | |
7305 | } | |
c3f6f71d | 7306 | |
c3f6f71d JM |
7307 | /* ----------------------------- SNIP ----------------------------- |
7308 | Anything added to the cleanup chain beyond this point is assumed | |
7309 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
7310 | then the memory is not reclaimed. */ |
7311 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d JM |
7312 | |
7313 | /* Mark the contents of the addr_string for cleanup. These go on | |
80c99de1 | 7314 | the bkpt_chain and only occur if the breakpoint create fails. */ |
c3f6f71d JM |
7315 | for (i = 0; i < sals.nelts; i++) |
7316 | { | |
7317 | if (addr_string[i] != NULL) | |
b8c9b27d | 7318 | make_cleanup (xfree, addr_string[i]); |
c3f6f71d JM |
7319 | } |
7320 | ||
7321 | /* Resolve all line numbers to PC's and verify that the addresses | |
7322 | are ok for the target. */ | |
0101ce28 JJ |
7323 | if (!pending) |
7324 | breakpoint_sals_to_pc (&sals, addr_start); | |
c3f6f71d | 7325 | |
1042e4c0 | 7326 | type_wanted = (traceflag |
7a697b8d | 7327 | ? (hardwareflag ? bp_fast_tracepoint : bp_tracepoint) |
1042e4c0 SS |
7328 | : (hardwareflag ? bp_hardware_breakpoint : bp_breakpoint)); |
7329 | ||
7a697b8d SS |
7330 | /* Fast tracepoints may have additional restrictions on location. */ |
7331 | if (type_wanted == bp_fast_tracepoint) | |
7332 | check_fast_tracepoint_sals (gdbarch, &sals); | |
7333 | ||
c3f6f71d JM |
7334 | /* Verify that condition can be parsed, before setting any |
7335 | breakpoints. Allocate a separate condition expression for each | |
7336 | breakpoint. */ | |
0101ce28 | 7337 | if (!pending) |
c3f6f71d | 7338 | { |
2f069f6f | 7339 | if (parse_condition_and_thread) |
72b2ff0e VP |
7340 | { |
7341 | /* Here we only parse 'arg' to separate condition | |
7342 | from thread number, so parsing in context of first | |
7343 | sal is OK. When setting the breakpoint we'll | |
7344 | re-parse it in context of each sal. */ | |
7345 | cond_string = NULL; | |
7346 | thread = -1; | |
4a306c9a JB |
7347 | find_condition_and_thread (arg, sals.sals[0].pc, &cond_string, |
7348 | &thread, &task); | |
72b2ff0e VP |
7349 | if (cond_string) |
7350 | make_cleanup (xfree, cond_string); | |
7351 | } | |
2f069f6f | 7352 | else |
72b2ff0e VP |
7353 | { |
7354 | /* Create a private copy of condition string. */ | |
7355 | if (cond_string) | |
7356 | { | |
7357 | cond_string = xstrdup (cond_string); | |
7358 | make_cleanup (xfree, cond_string); | |
7359 | } | |
7360 | } | |
8cdf0e15 VP |
7361 | create_breakpoints_sal (gdbarch, sals, addr_string, cond_string, |
7362 | type_wanted, tempflag ? disp_del : disp_donttouch, | |
7363 | thread, task, ignore_count, ops, from_tty, | |
7364 | enabled); | |
c906108c | 7365 | } |
0101ce28 JJ |
7366 | else |
7367 | { | |
fe3f5fa8 | 7368 | struct symtab_and_line sal = {0}; |
0101ce28 JJ |
7369 | struct breakpoint *b; |
7370 | ||
0101ce28 JJ |
7371 | make_cleanup (xfree, copy_arg); |
7372 | ||
a6d9a66e | 7373 | b = set_raw_breakpoint_without_location (gdbarch, type_wanted); |
0101ce28 JJ |
7374 | set_breakpoint_count (breakpoint_count + 1); |
7375 | b->number = breakpoint_count; | |
72b2ff0e | 7376 | b->thread = -1; |
018d34a4 | 7377 | b->addr_string = addr_string[0]; |
72b2ff0e | 7378 | b->cond_string = NULL; |
0101ce28 | 7379 | b->ignore_count = ignore_count; |
0101ce28 | 7380 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 7381 | b->condition_not_parsed = 1; |
604133b5 | 7382 | b->ops = ops; |
41447f92 | 7383 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
6c95b8df | 7384 | b->pspace = current_program_space; |
74960c60 | 7385 | |
6c95b8df | 7386 | if (enabled && b->pspace->executing_startup |
8bea4e01 UW |
7387 | && (b->type == bp_breakpoint |
7388 | || b->type == bp_hardware_breakpoint)) | |
7389 | b->enable_state = bp_startup_disabled; | |
7390 | ||
0101ce28 JJ |
7391 | mention (b); |
7392 | } | |
7393 | ||
c3f6f71d | 7394 | if (sals.nelts > 1) |
95a42b64 TT |
7395 | { |
7396 | warning (_("Multiple breakpoints were set.\n" | |
7397 | "Use the \"delete\" command to delete unwanted breakpoints.")); | |
7398 | multi_start = first_bp_set; | |
7399 | multi_end = breakpoint_count; | |
7400 | last_was_multi = 1; | |
7401 | } | |
7402 | ||
80c99de1 PA |
7403 | /* That's it. Discard the cleanups for data inserted into the |
7404 | breakpoint. */ | |
7405 | discard_cleanups (bkpt_chain); | |
7406 | /* But cleanup everything else. */ | |
c3f6f71d | 7407 | do_cleanups (old_chain); |
217dc9e2 | 7408 | |
80c99de1 | 7409 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
217dc9e2 | 7410 | update_global_location_list (1); |
fd9b8c24 PA |
7411 | |
7412 | return 1; | |
c3f6f71d | 7413 | } |
c906108c | 7414 | |
72b2ff0e VP |
7415 | /* Set a breakpoint. |
7416 | ARG is a string describing breakpoint address, | |
7417 | condition, and thread. | |
7418 | FLAG specifies if a breakpoint is hardware on, | |
7419 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
7420 | and BP_TEMPFLAG. */ | |
7421 | ||
98deb0da | 7422 | static void |
72b2ff0e | 7423 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 7424 | { |
72b2ff0e VP |
7425 | int hardwareflag = flag & BP_HARDWAREFLAG; |
7426 | int tempflag = flag & BP_TEMPFLAG; | |
c3f6f71d | 7427 | |
8cdf0e15 VP |
7428 | create_breakpoint (get_current_arch (), |
7429 | arg, | |
7430 | NULL, 0, 1 /* parse arg */, | |
7431 | tempflag, hardwareflag, 0 /* traceflag */, | |
7432 | 0 /* Ignore count */, | |
7433 | pending_break_support, | |
7434 | NULL /* breakpoint_ops */, | |
7435 | from_tty, | |
7436 | 1 /* enabled */); | |
c906108c SS |
7437 | } |
7438 | ||
72b2ff0e | 7439 | |
c3f6f71d | 7440 | |
c906108c SS |
7441 | /* Helper function for break_command_1 and disassemble_command. */ |
7442 | ||
7443 | void | |
fba45db2 | 7444 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
7445 | { |
7446 | CORE_ADDR pc; | |
7447 | ||
7448 | if (sal->pc == 0 && sal->symtab != NULL) | |
7449 | { | |
7450 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 7451 | error (_("No line %d in file \"%s\"."), |
c906108c SS |
7452 | sal->line, sal->symtab->filename); |
7453 | sal->pc = pc; | |
6a048695 JB |
7454 | |
7455 | /* If this SAL corresponds to a breakpoint inserted using | |
7456 | a line number, then skip the function prologue if necessary. */ | |
7457 | if (sal->explicit_line) | |
059acae7 | 7458 | skip_prologue_sal (sal); |
c906108c SS |
7459 | } |
7460 | ||
7461 | if (sal->section == 0 && sal->symtab != NULL) | |
7462 | { | |
7463 | struct blockvector *bv; | |
c5aa993b JM |
7464 | struct block *b; |
7465 | struct symbol *sym; | |
c906108c | 7466 | |
801e3a5b | 7467 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
7468 | if (bv != NULL) |
7469 | { | |
7f0df278 | 7470 | sym = block_linkage_function (b); |
c906108c SS |
7471 | if (sym != NULL) |
7472 | { | |
7473 | fixup_symbol_section (sym, sal->symtab->objfile); | |
714835d5 | 7474 | sal->section = SYMBOL_OBJ_SECTION (sym); |
c906108c SS |
7475 | } |
7476 | else | |
7477 | { | |
7478 | /* It really is worthwhile to have the section, so we'll just | |
c5aa993b JM |
7479 | have to look harder. This case can be executed if we have |
7480 | line numbers but no functions (as can happen in assembly | |
7481 | source). */ | |
c906108c | 7482 | |
c5aa993b | 7483 | struct minimal_symbol *msym; |
6c95b8df PA |
7484 | struct cleanup *old_chain = save_current_space_and_thread (); |
7485 | ||
7486 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
7487 | |
7488 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
7489 | if (msym) | |
714835d5 | 7490 | sal->section = SYMBOL_OBJ_SECTION (msym); |
6c95b8df PA |
7491 | |
7492 | do_cleanups (old_chain); | |
c906108c SS |
7493 | } |
7494 | } | |
7495 | } | |
7496 | } | |
7497 | ||
7498 | void | |
fba45db2 | 7499 | break_command (char *arg, int from_tty) |
c906108c | 7500 | { |
db107f19 | 7501 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
7502 | } |
7503 | ||
c906108c | 7504 | void |
fba45db2 | 7505 | tbreak_command (char *arg, int from_tty) |
c906108c | 7506 | { |
db107f19 | 7507 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
7508 | } |
7509 | ||
c906108c | 7510 | static void |
fba45db2 | 7511 | hbreak_command (char *arg, int from_tty) |
c906108c | 7512 | { |
db107f19 | 7513 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
7514 | } |
7515 | ||
7516 | static void | |
fba45db2 | 7517 | thbreak_command (char *arg, int from_tty) |
c906108c | 7518 | { |
db107f19 | 7519 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
7520 | } |
7521 | ||
7522 | static void | |
fba45db2 | 7523 | stop_command (char *arg, int from_tty) |
c906108c | 7524 | { |
a3f17187 | 7525 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 7526 | Usage: stop in <function | address>\n\ |
a3f17187 | 7527 | stop at <line>\n")); |
c906108c SS |
7528 | } |
7529 | ||
7530 | static void | |
fba45db2 | 7531 | stopin_command (char *arg, int from_tty) |
c906108c SS |
7532 | { |
7533 | int badInput = 0; | |
7534 | ||
c5aa993b | 7535 | if (arg == (char *) NULL) |
c906108c SS |
7536 | badInput = 1; |
7537 | else if (*arg != '*') | |
7538 | { | |
7539 | char *argptr = arg; | |
7540 | int hasColon = 0; | |
7541 | ||
53a5351d JM |
7542 | /* look for a ':'. If this is a line number specification, then |
7543 | say it is bad, otherwise, it should be an address or | |
7544 | function/method name */ | |
c906108c | 7545 | while (*argptr && !hasColon) |
c5aa993b JM |
7546 | { |
7547 | hasColon = (*argptr == ':'); | |
7548 | argptr++; | |
7549 | } | |
c906108c SS |
7550 | |
7551 | if (hasColon) | |
c5aa993b | 7552 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 7553 | else |
c5aa993b | 7554 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
7555 | } |
7556 | ||
7557 | if (badInput) | |
a3f17187 | 7558 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 7559 | else |
db107f19 | 7560 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
7561 | } |
7562 | ||
7563 | static void | |
fba45db2 | 7564 | stopat_command (char *arg, int from_tty) |
c906108c SS |
7565 | { |
7566 | int badInput = 0; | |
7567 | ||
c5aa993b | 7568 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
7569 | badInput = 1; |
7570 | else | |
7571 | { | |
7572 | char *argptr = arg; | |
7573 | int hasColon = 0; | |
7574 | ||
7575 | /* look for a ':'. If there is a '::' then get out, otherwise | |
c5aa993b | 7576 | it is probably a line number. */ |
c906108c | 7577 | while (*argptr && !hasColon) |
c5aa993b JM |
7578 | { |
7579 | hasColon = (*argptr == ':'); | |
7580 | argptr++; | |
7581 | } | |
c906108c SS |
7582 | |
7583 | if (hasColon) | |
c5aa993b | 7584 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 7585 | else |
c5aa993b | 7586 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
7587 | } |
7588 | ||
7589 | if (badInput) | |
a3f17187 | 7590 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 7591 | else |
db107f19 | 7592 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
7593 | } |
7594 | ||
53a5351d JM |
7595 | /* accessflag: hw_write: watch write, |
7596 | hw_read: watch read, | |
7597 | hw_access: watch access (read or write) */ | |
c906108c | 7598 | static void |
fba45db2 | 7599 | watch_command_1 (char *arg, int accessflag, int from_tty) |
c906108c | 7600 | { |
a6d9a66e | 7601 | struct gdbarch *gdbarch = get_current_arch (); |
d983da9c | 7602 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c | 7603 | struct expression *exp; |
60e1c644 | 7604 | struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
c906108c SS |
7605 | struct value *val, *mark; |
7606 | struct frame_info *frame; | |
c906108c SS |
7607 | char *exp_start = NULL; |
7608 | char *exp_end = NULL; | |
37e4754d | 7609 | char *tok, *id_tok_start, *end_tok; |
c906108c SS |
7610 | int toklen; |
7611 | char *cond_start = NULL; | |
7612 | char *cond_end = NULL; | |
c906108c SS |
7613 | int i, other_type_used, target_resources_ok = 0; |
7614 | enum bptype bp_type; | |
7615 | int mem_cnt = 0; | |
37e4754d | 7616 | int thread = -1; |
c906108c | 7617 | |
37e4754d LM |
7618 | /* Make sure that we actually have parameters to parse. */ |
7619 | if (arg != NULL && arg[0] != '\0') | |
7620 | { | |
7621 | toklen = strlen (arg); /* Size of argument list. */ | |
7622 | ||
7623 | /* Points tok to the end of the argument list. */ | |
7624 | tok = arg + toklen - 1; | |
7625 | ||
7626 | /* Go backwards in the parameters list. Skip the last parameter. | |
7627 | If we're expecting a 'thread <thread_num>' parameter, this should | |
7628 | be the thread identifier. */ | |
7629 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
7630 | tok--; | |
7631 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
7632 | tok--; | |
7633 | ||
7634 | /* Points end_tok to the beginning of the last token. */ | |
7635 | id_tok_start = tok + 1; | |
7636 | ||
7637 | /* Go backwards in the parameters list. Skip one more parameter. | |
7638 | If we're expecting a 'thread <thread_num>' parameter, we should | |
7639 | reach a "thread" token. */ | |
7640 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
7641 | tok--; | |
7642 | ||
7643 | end_tok = tok; | |
7644 | ||
7645 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
7646 | tok--; | |
7647 | ||
7648 | /* Move the pointer forward to skip the whitespace and | |
7649 | calculate the length of the token. */ | |
7650 | tok++; | |
7651 | toklen = end_tok - tok; | |
7652 | ||
7653 | if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
7654 | { | |
7655 | /* At this point we've found a "thread" token, which means | |
7656 | the user is trying to set a watchpoint that triggers | |
7657 | only in a specific thread. */ | |
7658 | char *endp; | |
7659 | ||
7660 | /* Extract the thread ID from the next token. */ | |
7661 | thread = strtol (id_tok_start, &endp, 0); | |
7662 | ||
7663 | /* Check if the user provided a valid numeric value for the | |
7664 | thread ID. */ | |
7665 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
7666 | error (_("Invalid thread ID specification %s."), id_tok_start); | |
7667 | ||
7668 | /* Check if the thread actually exists. */ | |
7669 | if (!valid_thread_id (thread)) | |
7670 | error (_("Unknown thread %d."), thread); | |
7671 | ||
7672 | /* Truncate the string and get rid of the thread <thread_num> | |
7673 | parameter before the parameter list is parsed by the | |
7674 | evaluate_expression() function. */ | |
7675 | *tok = '\0'; | |
7676 | } | |
7677 | } | |
7678 | ||
7679 | /* Parse the rest of the arguments. */ | |
c906108c SS |
7680 | innermost_block = NULL; |
7681 | exp_start = arg; | |
7682 | exp = parse_exp_1 (&arg, 0, 0); | |
7683 | exp_end = arg; | |
fa8a61dc TT |
7684 | /* Remove trailing whitespace from the expression before saving it. |
7685 | This makes the eventual display of the expression string a bit | |
7686 | prettier. */ | |
7687 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
7688 | --exp_end; | |
7689 | ||
c906108c SS |
7690 | exp_valid_block = innermost_block; |
7691 | mark = value_mark (); | |
fa4727a6 DJ |
7692 | fetch_watchpoint_value (exp, &val, NULL, NULL); |
7693 | if (val != NULL) | |
7694 | release_value (val); | |
c906108c SS |
7695 | |
7696 | tok = arg; | |
7697 | while (*tok == ' ' || *tok == '\t') | |
7698 | tok++; | |
7699 | end_tok = tok; | |
7700 | ||
7701 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
7702 | end_tok++; | |
7703 | ||
7704 | toklen = end_tok - tok; | |
7705 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
7706 | { | |
2d134ed3 PA |
7707 | struct expression *cond; |
7708 | ||
60e1c644 | 7709 | innermost_block = NULL; |
c906108c SS |
7710 | tok = cond_start = end_tok + 1; |
7711 | cond = parse_exp_1 (&tok, 0, 0); | |
60e1c644 PA |
7712 | |
7713 | /* The watchpoint expression may not be local, but the condition | |
7714 | may still be. E.g.: `watch global if local > 0'. */ | |
7715 | cond_exp_valid_block = innermost_block; | |
7716 | ||
2d134ed3 | 7717 | xfree (cond); |
c906108c SS |
7718 | cond_end = tok; |
7719 | } | |
7720 | if (*tok) | |
8a3fe4f8 | 7721 | error (_("Junk at end of command.")); |
c906108c | 7722 | |
53a5351d | 7723 | if (accessflag == hw_read) |
c5aa993b | 7724 | bp_type = bp_read_watchpoint; |
53a5351d | 7725 | else if (accessflag == hw_access) |
c5aa993b JM |
7726 | bp_type = bp_access_watchpoint; |
7727 | else | |
7728 | bp_type = bp_hardware_watchpoint; | |
c906108c SS |
7729 | |
7730 | mem_cnt = can_use_hardware_watchpoint (val); | |
7731 | if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint) | |
8a3fe4f8 | 7732 | error (_("Expression cannot be implemented with read/access watchpoint.")); |
c5aa993b JM |
7733 | if (mem_cnt != 0) |
7734 | { | |
7735 | i = hw_watchpoint_used_count (bp_type, &other_type_used); | |
53a5351d | 7736 | target_resources_ok = |
d92524f1 | 7737 | target_can_use_hardware_watchpoint (bp_type, i + mem_cnt, |
53a5351d | 7738 | other_type_used); |
c5aa993b | 7739 | if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint) |
8a3fe4f8 | 7740 | error (_("Target does not support this type of hardware watchpoint.")); |
53a5351d | 7741 | |
c5aa993b | 7742 | if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint) |
8a3fe4f8 | 7743 | error (_("Target can only support one kind of HW watchpoint at a time.")); |
c5aa993b | 7744 | } |
c906108c | 7745 | |
4d28f7a8 KB |
7746 | /* Change the type of breakpoint to an ordinary watchpoint if a hardware |
7747 | watchpoint could not be set. */ | |
7748 | if (!mem_cnt || target_resources_ok <= 0) | |
7749 | bp_type = bp_watchpoint; | |
7750 | ||
d983da9c | 7751 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
7752 | |
7753 | /* If the expression is "local", then set up a "watchpoint scope" | |
7754 | breakpoint at the point where we've left the scope of the watchpoint | |
7755 | expression. Create the scope breakpoint before the watchpoint, so | |
7756 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 7757 | if (exp_valid_block && frame) |
d983da9c | 7758 | { |
edb3359d DJ |
7759 | if (frame_id_p (frame_unwind_caller_id (frame))) |
7760 | { | |
7761 | scope_breakpoint | |
a6d9a66e UW |
7762 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
7763 | frame_unwind_caller_pc (frame), | |
edb3359d | 7764 | bp_watchpoint_scope); |
d983da9c | 7765 | |
edb3359d | 7766 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 7767 | |
edb3359d DJ |
7768 | /* Automatically delete the breakpoint when it hits. */ |
7769 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 7770 | |
edb3359d DJ |
7771 | /* Only break in the proper frame (help with recursion). */ |
7772 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 7773 | |
edb3359d | 7774 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
7775 | scope_breakpoint->loc->gdbarch |
7776 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
7777 | scope_breakpoint->loc->requested_address |
7778 | = frame_unwind_caller_pc (frame); | |
7779 | scope_breakpoint->loc->address | |
a6d9a66e UW |
7780 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
7781 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
7782 | scope_breakpoint->type); |
7783 | } | |
d983da9c DJ |
7784 | } |
7785 | ||
c906108c | 7786 | /* Now set up the breakpoint. */ |
2d134ed3 | 7787 | b = set_raw_breakpoint_without_location (NULL, bp_type); |
c906108c SS |
7788 | set_breakpoint_count (breakpoint_count + 1); |
7789 | b->number = breakpoint_count; | |
37e4754d | 7790 | b->thread = thread; |
b5de0fa7 | 7791 | b->disposition = disp_donttouch; |
c906108c SS |
7792 | b->exp = exp; |
7793 | b->exp_valid_block = exp_valid_block; | |
60e1c644 | 7794 | b->cond_exp_valid_block = cond_exp_valid_block; |
c906108c SS |
7795 | b->exp_string = savestring (exp_start, exp_end - exp_start); |
7796 | b->val = val; | |
fa4727a6 | 7797 | b->val_valid = 1; |
c906108c SS |
7798 | if (cond_start) |
7799 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
7800 | else | |
7801 | b->cond_string = 0; | |
c5aa993b | 7802 | |
c906108c | 7803 | if (frame) |
f6bc2008 PA |
7804 | { |
7805 | b->watchpoint_frame = get_frame_id (frame); | |
7806 | b->watchpoint_thread = inferior_ptid; | |
7807 | } | |
c906108c | 7808 | else |
f6bc2008 PA |
7809 | { |
7810 | b->watchpoint_frame = null_frame_id; | |
7811 | b->watchpoint_thread = null_ptid; | |
7812 | } | |
c906108c | 7813 | |
d983da9c | 7814 | if (scope_breakpoint != NULL) |
c906108c | 7815 | { |
d983da9c DJ |
7816 | /* The scope breakpoint is related to the watchpoint. We will |
7817 | need to act on them together. */ | |
7818 | b->related_breakpoint = scope_breakpoint; | |
7819 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 7820 | } |
d983da9c | 7821 | |
c906108c | 7822 | value_free_to_mark (mark); |
2d134ed3 PA |
7823 | |
7824 | /* Finally update the new watchpoint. This creates the locations | |
7825 | that should be inserted. */ | |
7826 | update_watchpoint (b, 1); | |
7827 | ||
c906108c | 7828 | mention (b); |
b60e7edf | 7829 | update_global_location_list (1); |
c906108c SS |
7830 | } |
7831 | ||
7832 | /* Return count of locations need to be watched and can be handled | |
7833 | in hardware. If the watchpoint can not be handled | |
7834 | in hardware return zero. */ | |
7835 | ||
c906108c | 7836 | static int |
fba45db2 | 7837 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
7838 | { |
7839 | int found_memory_cnt = 0; | |
2e70b7b9 | 7840 | struct value *head = v; |
c906108c SS |
7841 | |
7842 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 7843 | if (!can_use_hw_watchpoints) |
c906108c | 7844 | return 0; |
c5aa993b | 7845 | |
5c44784c JM |
7846 | /* Make sure that the value of the expression depends only upon |
7847 | memory contents, and values computed from them within GDB. If we | |
7848 | find any register references or function calls, we can't use a | |
7849 | hardware watchpoint. | |
7850 | ||
7851 | The idea here is that evaluating an expression generates a series | |
7852 | of values, one holding the value of every subexpression. (The | |
7853 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
7854 | a*b+c.) GDB's values hold almost enough information to establish | |
7855 | the criteria given above --- they identify memory lvalues, | |
7856 | register lvalues, computed values, etcetera. So we can evaluate | |
7857 | the expression, and then scan the chain of values that leaves | |
7858 | behind to decide whether we can detect any possible change to the | |
7859 | expression's final value using only hardware watchpoints. | |
7860 | ||
7861 | However, I don't think that the values returned by inferior | |
7862 | function calls are special in any way. So this function may not | |
7863 | notice that an expression involving an inferior function call | |
7864 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 7865 | for (; v; v = value_next (v)) |
c906108c | 7866 | { |
5c44784c | 7867 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 7868 | { |
d69fe07e | 7869 | if (value_lazy (v)) |
5c44784c JM |
7870 | /* A lazy memory lvalue is one that GDB never needed to fetch; |
7871 | we either just used its address (e.g., `a' in `a.b') or | |
7872 | we never needed it at all (e.g., `a' in `a,b'). */ | |
7873 | ; | |
53a5351d | 7874 | else |
5c44784c JM |
7875 | { |
7876 | /* Ahh, memory we actually used! Check if we can cover | |
7877 | it with hardware watchpoints. */ | |
df407dfe | 7878 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
7879 | |
7880 | /* We only watch structs and arrays if user asked for it | |
7881 | explicitly, never if they just happen to appear in a | |
7882 | middle of some value chain. */ | |
7883 | if (v == head | |
7884 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
7885 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
7886 | { | |
42ae5230 | 7887 | CORE_ADDR vaddr = value_address (v); |
df407dfe | 7888 | int len = TYPE_LENGTH (value_type (v)); |
2e70b7b9 | 7889 | |
d92524f1 | 7890 | if (!target_region_ok_for_hw_watchpoint (vaddr, len)) |
2e70b7b9 MS |
7891 | return 0; |
7892 | else | |
7893 | found_memory_cnt++; | |
7894 | } | |
5c44784c | 7895 | } |
c5aa993b | 7896 | } |
5086187c AC |
7897 | else if (VALUE_LVAL (v) != not_lval |
7898 | && deprecated_value_modifiable (v) == 0) | |
53a5351d | 7899 | return 0; /* ??? What does this represent? */ |
5086187c | 7900 | else if (VALUE_LVAL (v) == lval_register) |
53a5351d | 7901 | return 0; /* cannot watch a register with a HW watchpoint */ |
c906108c SS |
7902 | } |
7903 | ||
7904 | /* The expression itself looks suitable for using a hardware | |
7905 | watchpoint, but give the target machine a chance to reject it. */ | |
7906 | return found_memory_cnt; | |
7907 | } | |
7908 | ||
8b93c638 | 7909 | void |
fba45db2 | 7910 | watch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
7911 | { |
7912 | watch_command (arg, from_tty); | |
7913 | } | |
8926118c | 7914 | |
c5aa993b | 7915 | static void |
fba45db2 | 7916 | watch_command (char *arg, int from_tty) |
c906108c | 7917 | { |
53a5351d | 7918 | watch_command_1 (arg, hw_write, from_tty); |
c906108c SS |
7919 | } |
7920 | ||
8b93c638 | 7921 | void |
fba45db2 | 7922 | rwatch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
7923 | { |
7924 | rwatch_command (arg, from_tty); | |
7925 | } | |
8926118c | 7926 | |
c5aa993b | 7927 | static void |
fba45db2 | 7928 | rwatch_command (char *arg, int from_tty) |
c906108c | 7929 | { |
53a5351d | 7930 | watch_command_1 (arg, hw_read, from_tty); |
c906108c SS |
7931 | } |
7932 | ||
8b93c638 | 7933 | void |
fba45db2 | 7934 | awatch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
7935 | { |
7936 | awatch_command (arg, from_tty); | |
7937 | } | |
8926118c | 7938 | |
c5aa993b | 7939 | static void |
fba45db2 | 7940 | awatch_command (char *arg, int from_tty) |
c906108c | 7941 | { |
53a5351d | 7942 | watch_command_1 (arg, hw_access, from_tty); |
c906108c | 7943 | } |
c906108c | 7944 | \f |
c5aa993b | 7945 | |
43ff13b4 | 7946 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
7947 | because it uses the mechanisms of breakpoints. */ |
7948 | ||
bfec99b2 PA |
7949 | struct until_break_command_continuation_args |
7950 | { | |
7951 | struct breakpoint *breakpoint; | |
7952 | struct breakpoint *breakpoint2; | |
7953 | }; | |
7954 | ||
43ff13b4 JM |
7955 | /* This function is called by fetch_inferior_event via the |
7956 | cmd_continuation pointer, to complete the until command. It takes | |
7957 | care of cleaning up the temporary breakpoints set up by the until | |
7958 | command. */ | |
c2c6d25f | 7959 | static void |
604ead4a | 7960 | until_break_command_continuation (void *arg) |
43ff13b4 | 7961 | { |
bfec99b2 PA |
7962 | struct until_break_command_continuation_args *a = arg; |
7963 | ||
7964 | delete_breakpoint (a->breakpoint); | |
7965 | if (a->breakpoint2) | |
7966 | delete_breakpoint (a->breakpoint2); | |
43ff13b4 JM |
7967 | } |
7968 | ||
c906108c | 7969 | void |
ae66c1fc | 7970 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
7971 | { |
7972 | struct symtabs_and_lines sals; | |
7973 | struct symtab_and_line sal; | |
206415a3 | 7974 | struct frame_info *frame = get_selected_frame (NULL); |
c906108c | 7975 | struct breakpoint *breakpoint; |
f107f563 | 7976 | struct breakpoint *breakpoint2 = NULL; |
c906108c SS |
7977 | struct cleanup *old_chain; |
7978 | ||
7979 | clear_proceed_status (); | |
7980 | ||
7981 | /* Set a breakpoint where the user wants it and at return from | |
7982 | this function */ | |
c5aa993b | 7983 | |
c906108c SS |
7984 | if (default_breakpoint_valid) |
7985 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, | |
68219205 | 7986 | default_breakpoint_line, (char ***) NULL, NULL); |
c906108c | 7987 | else |
53a5351d | 7988 | sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, |
68219205 | 7989 | 0, (char ***) NULL, NULL); |
c5aa993b | 7990 | |
c906108c | 7991 | if (sals.nelts != 1) |
8a3fe4f8 | 7992 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 7993 | |
c906108c | 7994 | sal = sals.sals[0]; |
b8c9b27d | 7995 | xfree (sals.sals); /* malloc'd, so freed */ |
c5aa993b | 7996 | |
c906108c | 7997 | if (*arg) |
8a3fe4f8 | 7998 | error (_("Junk at end of arguments.")); |
c5aa993b | 7999 | |
c906108c | 8000 | resolve_sal_pc (&sal); |
c5aa993b | 8001 | |
ae66c1fc EZ |
8002 | if (anywhere) |
8003 | /* If the user told us to continue until a specified location, | |
8004 | we don't specify a frame at which we need to stop. */ | |
a6d9a66e UW |
8005 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
8006 | null_frame_id, bp_until); | |
ae66c1fc | 8007 | else |
edb3359d | 8008 | /* Otherwise, specify the selected frame, because we want to stop only |
ae66c1fc | 8009 | at the very same frame. */ |
a6d9a66e UW |
8010 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
8011 | get_stack_frame_id (frame), | |
ae66c1fc | 8012 | bp_until); |
c5aa993b | 8013 | |
f107f563 | 8014 | old_chain = make_cleanup_delete_breakpoint (breakpoint); |
c906108c | 8015 | |
ae66c1fc EZ |
8016 | /* Keep within the current frame, or in frames called by the current |
8017 | one. */ | |
edb3359d DJ |
8018 | |
8019 | if (frame_id_p (frame_unwind_caller_id (frame))) | |
c906108c | 8020 | { |
edb3359d DJ |
8021 | sal = find_pc_line (frame_unwind_caller_pc (frame), 0); |
8022 | sal.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e UW |
8023 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
8024 | sal, | |
edb3359d | 8025 | frame_unwind_caller_id (frame), |
f107f563 VP |
8026 | bp_until); |
8027 | make_cleanup_delete_breakpoint (breakpoint2); | |
c906108c | 8028 | } |
c5aa993b | 8029 | |
c906108c | 8030 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
f107f563 VP |
8031 | |
8032 | /* If we are running asynchronously, and proceed call above has actually | |
8033 | managed to start the target, arrange for breakpoints to be | |
8034 | deleted when the target stops. Otherwise, we're already stopped and | |
8035 | delete breakpoints via cleanup chain. */ | |
8036 | ||
8ea051c5 | 8037 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 8038 | { |
bfec99b2 PA |
8039 | struct until_break_command_continuation_args *args; |
8040 | args = xmalloc (sizeof (*args)); | |
f107f563 | 8041 | |
bfec99b2 PA |
8042 | args->breakpoint = breakpoint; |
8043 | args->breakpoint2 = breakpoint2; | |
f107f563 VP |
8044 | |
8045 | discard_cleanups (old_chain); | |
95e54da7 PA |
8046 | add_continuation (inferior_thread (), |
8047 | until_break_command_continuation, args, | |
604ead4a | 8048 | xfree); |
f107f563 VP |
8049 | } |
8050 | else | |
c5aa993b | 8051 | do_cleanups (old_chain); |
c906108c | 8052 | } |
ae66c1fc | 8053 | |
c906108c | 8054 | static void |
fba45db2 | 8055 | ep_skip_leading_whitespace (char **s) |
c906108c | 8056 | { |
c5aa993b JM |
8057 | if ((s == NULL) || (*s == NULL)) |
8058 | return; | |
8059 | while (isspace (**s)) | |
8060 | *s += 1; | |
c906108c | 8061 | } |
c5aa993b | 8062 | |
c906108c SS |
8063 | /* This function attempts to parse an optional "if <cond>" clause |
8064 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 8065 | |
c906108c SS |
8066 | Else, it returns a pointer to the condition string. (It does not |
8067 | attempt to evaluate the string against a particular block.) And, | |
8068 | it updates arg to point to the first character following the parsed | |
8069 | if clause in the arg string. */ | |
53a5351d | 8070 | |
c906108c | 8071 | static char * |
fba45db2 | 8072 | ep_parse_optional_if_clause (char **arg) |
c906108c | 8073 | { |
c5aa993b JM |
8074 | char *cond_string; |
8075 | ||
8076 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 8077 | return NULL; |
c5aa993b | 8078 | |
c906108c SS |
8079 | /* Skip the "if" keyword. */ |
8080 | (*arg) += 2; | |
c5aa993b | 8081 | |
c906108c SS |
8082 | /* Skip any extra leading whitespace, and record the start of the |
8083 | condition string. */ | |
8084 | ep_skip_leading_whitespace (arg); | |
8085 | cond_string = *arg; | |
c5aa993b | 8086 | |
c906108c SS |
8087 | /* Assume that the condition occupies the remainder of the arg string. */ |
8088 | (*arg) += strlen (cond_string); | |
c5aa993b | 8089 | |
c906108c SS |
8090 | return cond_string; |
8091 | } | |
c5aa993b | 8092 | |
c906108c SS |
8093 | /* Commands to deal with catching events, such as signals, exceptions, |
8094 | process start/exit, etc. */ | |
c5aa993b JM |
8095 | |
8096 | typedef enum | |
8097 | { | |
44feb3ce TT |
8098 | catch_fork_temporary, catch_vfork_temporary, |
8099 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
8100 | } |
8101 | catch_fork_kind; | |
8102 | ||
c906108c | 8103 | static void |
44feb3ce | 8104 | catch_fork_command_1 (char *arg, int from_tty, struct cmd_list_element *command) |
c906108c | 8105 | { |
a6d9a66e | 8106 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 8107 | char *cond_string = NULL; |
44feb3ce TT |
8108 | catch_fork_kind fork_kind; |
8109 | int tempflag; | |
8110 | ||
8111 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
8112 | tempflag = (fork_kind == catch_fork_temporary | |
8113 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 8114 | |
44feb3ce TT |
8115 | if (!arg) |
8116 | arg = ""; | |
c906108c | 8117 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 8118 | |
c906108c | 8119 | /* The allowed syntax is: |
c5aa993b JM |
8120 | catch [v]fork |
8121 | catch [v]fork if <cond> | |
8122 | ||
c906108c SS |
8123 | First, check if there's an if clause. */ |
8124 | cond_string = ep_parse_optional_if_clause (&arg); | |
c5aa993b | 8125 | |
c906108c | 8126 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 8127 | error (_("Junk at end of arguments.")); |
c5aa993b | 8128 | |
c906108c SS |
8129 | /* If this target supports it, create a fork or vfork catchpoint |
8130 | and enable reporting of such events. */ | |
c5aa993b JM |
8131 | switch (fork_kind) |
8132 | { | |
44feb3ce TT |
8133 | case catch_fork_temporary: |
8134 | case catch_fork_permanent: | |
a6d9a66e | 8135 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 8136 | &catch_fork_breakpoint_ops); |
c906108c | 8137 | break; |
44feb3ce TT |
8138 | case catch_vfork_temporary: |
8139 | case catch_vfork_permanent: | |
a6d9a66e | 8140 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 8141 | &catch_vfork_breakpoint_ops); |
c906108c | 8142 | break; |
c5aa993b | 8143 | default: |
8a3fe4f8 | 8144 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 8145 | break; |
c5aa993b | 8146 | } |
c906108c SS |
8147 | } |
8148 | ||
8149 | static void | |
44feb3ce | 8150 | catch_exec_command_1 (char *arg, int from_tty, struct cmd_list_element *command) |
c906108c | 8151 | { |
a6d9a66e | 8152 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 8153 | int tempflag; |
c5aa993b | 8154 | char *cond_string = NULL; |
c906108c | 8155 | |
44feb3ce TT |
8156 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
8157 | ||
8158 | if (!arg) | |
8159 | arg = ""; | |
c906108c SS |
8160 | ep_skip_leading_whitespace (&arg); |
8161 | ||
8162 | /* The allowed syntax is: | |
c5aa993b JM |
8163 | catch exec |
8164 | catch exec if <cond> | |
c906108c SS |
8165 | |
8166 | First, check if there's an if clause. */ | |
8167 | cond_string = ep_parse_optional_if_clause (&arg); | |
8168 | ||
8169 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 8170 | error (_("Junk at end of arguments.")); |
c906108c SS |
8171 | |
8172 | /* If this target supports it, create an exec catchpoint | |
8173 | and enable reporting of such events. */ | |
a6d9a66e UW |
8174 | create_catchpoint (gdbarch, tempflag, cond_string, |
8175 | &catch_exec_breakpoint_ops); | |
c906108c | 8176 | } |
c5aa993b | 8177 | |
3086aeae DJ |
8178 | static enum print_stop_action |
8179 | print_exception_catchpoint (struct breakpoint *b) | |
8180 | { | |
ade92717 | 8181 | int bp_temp, bp_throw; |
3086aeae | 8182 | |
ade92717 | 8183 | annotate_catchpoint (b->number); |
3086aeae | 8184 | |
ade92717 AR |
8185 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
8186 | if (b->loc->address != b->loc->requested_address) | |
8187 | breakpoint_adjustment_warning (b->loc->requested_address, | |
8188 | b->loc->address, | |
8189 | b->number, 1); | |
df2b6d2d | 8190 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
8191 | ui_out_text (uiout, |
8192 | bp_temp ? "Temporary catchpoint " | |
8193 | : "Catchpoint "); | |
8194 | if (!ui_out_is_mi_like_p (uiout)) | |
8195 | ui_out_field_int (uiout, "bkptno", b->number); | |
8196 | ui_out_text (uiout, | |
c0b37c48 AR |
8197 | bp_throw ? " (exception thrown), " |
8198 | : " (exception caught), "); | |
ade92717 AR |
8199 | if (ui_out_is_mi_like_p (uiout)) |
8200 | { | |
8201 | ui_out_field_string (uiout, "reason", | |
8202 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
8203 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8204 | ui_out_field_int (uiout, "bkptno", b->number); | |
8205 | } | |
3086aeae DJ |
8206 | return PRINT_SRC_AND_LOC; |
8207 | } | |
8208 | ||
8209 | static void | |
a6d9a66e | 8210 | print_one_exception_catchpoint (struct breakpoint *b, struct bp_location **last_loc) |
3086aeae | 8211 | { |
79a45b7d TT |
8212 | struct value_print_options opts; |
8213 | get_user_print_options (&opts); | |
8214 | if (opts.addressprint) | |
3086aeae DJ |
8215 | { |
8216 | annotate_field (4); | |
604133b5 AR |
8217 | if (b->loc == NULL || b->loc->shlib_disabled) |
8218 | ui_out_field_string (uiout, "addr", "<PENDING>"); | |
8219 | else | |
5af949e3 UW |
8220 | ui_out_field_core_addr (uiout, "addr", |
8221 | b->loc->gdbarch, b->loc->address); | |
3086aeae DJ |
8222 | } |
8223 | annotate_field (5); | |
604133b5 | 8224 | if (b->loc) |
a6d9a66e | 8225 | *last_loc = b->loc; |
3086aeae DJ |
8226 | if (strstr (b->addr_string, "throw") != NULL) |
8227 | ui_out_field_string (uiout, "what", "exception throw"); | |
8228 | else | |
8229 | ui_out_field_string (uiout, "what", "exception catch"); | |
8230 | } | |
8231 | ||
8232 | static void | |
8233 | print_mention_exception_catchpoint (struct breakpoint *b) | |
8234 | { | |
ade92717 AR |
8235 | int bp_temp; |
8236 | int bp_throw; | |
8237 | ||
df2b6d2d | 8238 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
8239 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
8240 | ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ") | |
8241 | : _("Catchpoint ")); | |
8242 | ui_out_field_int (uiout, "bkptno", b->number); | |
8243 | ui_out_text (uiout, bp_throw ? _(" (throw)") | |
8244 | : _(" (catch)")); | |
3086aeae DJ |
8245 | } |
8246 | ||
8247 | static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = { | |
ce78b96d JB |
8248 | NULL, /* insert */ |
8249 | NULL, /* remove */ | |
8250 | NULL, /* breakpoint_hit */ | |
3086aeae DJ |
8251 | print_exception_catchpoint, |
8252 | print_one_exception_catchpoint, | |
8253 | print_mention_exception_catchpoint | |
8254 | }; | |
8255 | ||
8256 | static int | |
8257 | handle_gnu_v3_exceptions (int tempflag, char *cond_string, | |
8258 | enum exception_event_kind ex_event, int from_tty) | |
8259 | { | |
604133b5 AR |
8260 | char *trigger_func_name; |
8261 | ||
3086aeae | 8262 | if (ex_event == EX_EVENT_CATCH) |
604133b5 | 8263 | trigger_func_name = "__cxa_begin_catch"; |
3086aeae | 8264 | else |
604133b5 | 8265 | trigger_func_name = "__cxa_throw"; |
3086aeae | 8266 | |
8cdf0e15 VP |
8267 | create_breakpoint (get_current_arch (), |
8268 | trigger_func_name, cond_string, -1, | |
8269 | 0 /* condition and thread are valid. */, | |
8270 | tempflag, 0, 0, | |
8271 | 0, | |
8272 | AUTO_BOOLEAN_TRUE /* pending */, | |
8273 | &gnu_v3_exception_catchpoint_ops, from_tty, | |
8274 | 1 /* enabled */); | |
3086aeae | 8275 | |
3086aeae DJ |
8276 | return 1; |
8277 | } | |
8278 | ||
c5aa993b | 8279 | /* Deal with "catch catch" and "catch throw" commands */ |
c906108c SS |
8280 | |
8281 | static void | |
fba45db2 KB |
8282 | catch_exception_command_1 (enum exception_event_kind ex_event, char *arg, |
8283 | int tempflag, int from_tty) | |
c906108c | 8284 | { |
c5aa993b JM |
8285 | char *cond_string = NULL; |
8286 | struct symtab_and_line *sal = NULL; | |
8287 | ||
44feb3ce TT |
8288 | if (!arg) |
8289 | arg = ""; | |
c906108c | 8290 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 8291 | |
c906108c SS |
8292 | cond_string = ep_parse_optional_if_clause (&arg); |
8293 | ||
8294 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 8295 | error (_("Junk at end of arguments.")); |
c906108c | 8296 | |
059fb39f PM |
8297 | if (ex_event != EX_EVENT_THROW |
8298 | && ex_event != EX_EVENT_CATCH) | |
8a3fe4f8 | 8299 | error (_("Unsupported or unknown exception event; cannot catch it")); |
c906108c | 8300 | |
3086aeae DJ |
8301 | if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty)) |
8302 | return; | |
8303 | ||
8a3fe4f8 | 8304 | warning (_("Unsupported with this platform/compiler combination.")); |
c906108c SS |
8305 | } |
8306 | ||
44feb3ce TT |
8307 | /* Implementation of "catch catch" command. */ |
8308 | ||
8309 | static void | |
8310 | catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command) | |
8311 | { | |
8312 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8313 | catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty); | |
8314 | } | |
8315 | ||
8316 | /* Implementation of "catch throw" command. */ | |
8317 | ||
8318 | static void | |
8319 | catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command) | |
8320 | { | |
8321 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8322 | catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty); | |
8323 | } | |
8324 | ||
f7f9143b JB |
8325 | /* Create a breakpoint struct for Ada exception catchpoints. */ |
8326 | ||
8327 | static void | |
a6d9a66e UW |
8328 | create_ada_exception_breakpoint (struct gdbarch *gdbarch, |
8329 | struct symtab_and_line sal, | |
f7f9143b JB |
8330 | char *addr_string, |
8331 | char *exp_string, | |
8332 | char *cond_string, | |
8333 | struct expression *cond, | |
8334 | struct breakpoint_ops *ops, | |
8335 | int tempflag, | |
8336 | int from_tty) | |
8337 | { | |
8338 | struct breakpoint *b; | |
8339 | ||
8340 | if (from_tty) | |
8341 | { | |
5af949e3 UW |
8342 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
8343 | if (!loc_gdbarch) | |
8344 | loc_gdbarch = gdbarch; | |
8345 | ||
6c95b8df PA |
8346 | describe_other_breakpoints (loc_gdbarch, |
8347 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
8348 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
8349 | version for exception catchpoints, because two catchpoints | |
8350 | used for different exception names will use the same address. | |
8351 | In this case, a "breakpoint ... also set at..." warning is | |
8352 | unproductive. Besides. the warning phrasing is also a bit | |
8353 | inapropriate, we should use the word catchpoint, and tell | |
8354 | the user what type of catchpoint it is. The above is good | |
8355 | enough for now, though. */ | |
8356 | } | |
8357 | ||
a6d9a66e | 8358 | b = set_raw_breakpoint (gdbarch, sal, bp_breakpoint); |
f7f9143b JB |
8359 | set_breakpoint_count (breakpoint_count + 1); |
8360 | ||
8361 | b->enable_state = bp_enabled; | |
8362 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
8363 | b->number = breakpoint_count; | |
8364 | b->ignore_count = 0; | |
511a6cd4 | 8365 | b->loc->cond = cond; |
f7f9143b JB |
8366 | b->addr_string = addr_string; |
8367 | b->language = language_ada; | |
8368 | b->cond_string = cond_string; | |
8369 | b->exp_string = exp_string; | |
8370 | b->thread = -1; | |
8371 | b->ops = ops; | |
f7f9143b JB |
8372 | |
8373 | mention (b); | |
b60e7edf | 8374 | update_global_location_list (1); |
f7f9143b JB |
8375 | } |
8376 | ||
8377 | /* Implement the "catch exception" command. */ | |
8378 | ||
8379 | static void | |
44feb3ce TT |
8380 | catch_ada_exception_command (char *arg, int from_tty, |
8381 | struct cmd_list_element *command) | |
f7f9143b | 8382 | { |
a6d9a66e | 8383 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 8384 | int tempflag; |
f7f9143b JB |
8385 | struct symtab_and_line sal; |
8386 | enum bptype type; | |
8387 | char *addr_string = NULL; | |
8388 | char *exp_string = NULL; | |
8389 | char *cond_string = NULL; | |
8390 | struct expression *cond = NULL; | |
8391 | struct breakpoint_ops *ops = NULL; | |
8392 | ||
44feb3ce TT |
8393 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
8394 | ||
8395 | if (!arg) | |
8396 | arg = ""; | |
f7f9143b JB |
8397 | sal = ada_decode_exception_location (arg, &addr_string, &exp_string, |
8398 | &cond_string, &cond, &ops); | |
a6d9a66e | 8399 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, exp_string, |
f7f9143b JB |
8400 | cond_string, cond, ops, tempflag, |
8401 | from_tty); | |
8402 | } | |
8403 | ||
a96d9b2e SDJ |
8404 | /* Cleanup function for a syscall filter list. */ |
8405 | static void | |
8406 | clean_up_filters (void *arg) | |
8407 | { | |
8408 | VEC(int) *iter = *(VEC(int) **) arg; | |
8409 | VEC_free (int, iter); | |
8410 | } | |
8411 | ||
8412 | /* Splits the argument using space as delimiter. Returns an xmalloc'd | |
8413 | filter list, or NULL if no filtering is required. */ | |
8414 | static VEC(int) * | |
8415 | catch_syscall_split_args (char *arg) | |
8416 | { | |
8417 | VEC(int) *result = NULL; | |
8418 | struct cleanup *cleanup = make_cleanup (clean_up_filters, &result); | |
8419 | ||
8420 | while (*arg != '\0') | |
8421 | { | |
8422 | int i, syscall_number; | |
8423 | char *endptr; | |
8424 | char cur_name[128]; | |
8425 | struct syscall s; | |
8426 | ||
8427 | /* Skip whitespace. */ | |
8428 | while (isspace (*arg)) | |
8429 | arg++; | |
8430 | ||
8431 | for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) | |
8432 | cur_name[i] = arg[i]; | |
8433 | cur_name[i] = '\0'; | |
8434 | arg += i; | |
8435 | ||
8436 | /* Check if the user provided a syscall name or a number. */ | |
8437 | syscall_number = (int) strtol (cur_name, &endptr, 0); | |
8438 | if (*endptr == '\0') | |
bccd0dd2 | 8439 | get_syscall_by_number (syscall_number, &s); |
a96d9b2e SDJ |
8440 | else |
8441 | { | |
8442 | /* We have a name. Let's check if it's valid and convert it | |
8443 | to a number. */ | |
8444 | get_syscall_by_name (cur_name, &s); | |
8445 | ||
8446 | if (s.number == UNKNOWN_SYSCALL) | |
8447 | /* Here we have to issue an error instead of a warning, because | |
8448 | GDB cannot do anything useful if there's no syscall number to | |
8449 | be caught. */ | |
8450 | error (_("Unknown syscall name '%s'."), cur_name); | |
8451 | } | |
8452 | ||
8453 | /* Ok, it's valid. */ | |
8454 | VEC_safe_push (int, result, s.number); | |
8455 | } | |
8456 | ||
8457 | discard_cleanups (cleanup); | |
8458 | return result; | |
8459 | } | |
8460 | ||
8461 | /* Implement the "catch syscall" command. */ | |
8462 | ||
8463 | static void | |
8464 | catch_syscall_command_1 (char *arg, int from_tty, struct cmd_list_element *command) | |
8465 | { | |
8466 | int tempflag; | |
8467 | VEC(int) *filter; | |
8468 | struct syscall s; | |
8469 | struct gdbarch *gdbarch = get_current_arch (); | |
8470 | ||
8471 | /* Checking if the feature if supported. */ | |
8472 | if (gdbarch_get_syscall_number_p (gdbarch) == 0) | |
8473 | error (_("The feature 'catch syscall' is not supported on \ | |
8474 | this architeture yet.")); | |
8475 | ||
8476 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8477 | ||
8478 | ep_skip_leading_whitespace (&arg); | |
8479 | ||
8480 | /* We need to do this first "dummy" translation in order | |
8481 | to get the syscall XML file loaded or, most important, | |
8482 | to display a warning to the user if there's no XML file | |
8483 | for his/her architecture. */ | |
8484 | get_syscall_by_number (0, &s); | |
8485 | ||
8486 | /* The allowed syntax is: | |
8487 | catch syscall | |
8488 | catch syscall <name | number> [<name | number> ... <name | number>] | |
8489 | ||
8490 | Let's check if there's a syscall name. */ | |
8491 | ||
8492 | if (arg != NULL) | |
8493 | filter = catch_syscall_split_args (arg); | |
8494 | else | |
8495 | filter = NULL; | |
8496 | ||
8497 | create_syscall_event_catchpoint (tempflag, filter, | |
8498 | &catch_syscall_breakpoint_ops); | |
8499 | } | |
8500 | ||
f7f9143b JB |
8501 | /* Implement the "catch assert" command. */ |
8502 | ||
8503 | static void | |
44feb3ce | 8504 | catch_assert_command (char *arg, int from_tty, struct cmd_list_element *command) |
f7f9143b | 8505 | { |
a6d9a66e | 8506 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 8507 | int tempflag; |
f7f9143b JB |
8508 | struct symtab_and_line sal; |
8509 | char *addr_string = NULL; | |
8510 | struct breakpoint_ops *ops = NULL; | |
8511 | ||
44feb3ce TT |
8512 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
8513 | ||
8514 | if (!arg) | |
8515 | arg = ""; | |
f7f9143b | 8516 | sal = ada_decode_assert_location (arg, &addr_string, &ops); |
a6d9a66e UW |
8517 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, NULL, NULL, NULL, |
8518 | ops, tempflag, from_tty); | |
f7f9143b JB |
8519 | } |
8520 | ||
c906108c | 8521 | static void |
fba45db2 | 8522 | catch_command (char *arg, int from_tty) |
c906108c | 8523 | { |
44feb3ce | 8524 | error (_("Catch requires an event name.")); |
c906108c SS |
8525 | } |
8526 | \f | |
8527 | ||
8528 | static void | |
fba45db2 | 8529 | tcatch_command (char *arg, int from_tty) |
c906108c | 8530 | { |
44feb3ce | 8531 | error (_("Catch requires an event name.")); |
c906108c SS |
8532 | } |
8533 | ||
80f8a6eb | 8534 | /* Delete breakpoints by address or line. */ |
c906108c SS |
8535 | |
8536 | static void | |
fba45db2 | 8537 | clear_command (char *arg, int from_tty) |
c906108c | 8538 | { |
d6e956e5 VP |
8539 | struct breakpoint *b; |
8540 | VEC(breakpoint_p) *found = 0; | |
8541 | int ix; | |
c906108c SS |
8542 | int default_match; |
8543 | struct symtabs_and_lines sals; | |
8544 | struct symtab_and_line sal; | |
c906108c SS |
8545 | int i; |
8546 | ||
8547 | if (arg) | |
8548 | { | |
8549 | sals = decode_line_spec (arg, 1); | |
8550 | default_match = 0; | |
8551 | } | |
8552 | else | |
8553 | { | |
c5aa993b | 8554 | sals.sals = (struct symtab_and_line *) |
c906108c | 8555 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 8556 | make_cleanup (xfree, sals.sals); |
fe39c653 | 8557 | init_sal (&sal); /* initialize to zeroes */ |
c906108c SS |
8558 | sal.line = default_breakpoint_line; |
8559 | sal.symtab = default_breakpoint_symtab; | |
8560 | sal.pc = default_breakpoint_address; | |
6c95b8df | 8561 | sal.pspace = default_breakpoint_pspace; |
c906108c | 8562 | if (sal.symtab == 0) |
8a3fe4f8 | 8563 | error (_("No source file specified.")); |
c906108c SS |
8564 | |
8565 | sals.sals[0] = sal; | |
8566 | sals.nelts = 1; | |
8567 | ||
8568 | default_match = 1; | |
8569 | } | |
8570 | ||
ed0616c6 VP |
8571 | /* We don't call resolve_sal_pc here. That's not |
8572 | as bad as it seems, because all existing breakpoints | |
8573 | typically have both file/line and pc set. So, if | |
8574 | clear is given file/line, we can match this to existing | |
8575 | breakpoint without obtaining pc at all. | |
8576 | ||
8577 | We only support clearing given the address explicitly | |
8578 | present in breakpoint table. Say, we've set breakpoint | |
8579 | at file:line. There were several PC values for that file:line, | |
8580 | due to optimization, all in one block. | |
8581 | We've picked one PC value. If "clear" is issued with another | |
8582 | PC corresponding to the same file:line, the breakpoint won't | |
8583 | be cleared. We probably can still clear the breakpoint, but | |
8584 | since the other PC value is never presented to user, user | |
8585 | can only find it by guessing, and it does not seem important | |
8586 | to support that. */ | |
8587 | ||
c906108c | 8588 | /* For each line spec given, delete bps which correspond |
80f8a6eb MS |
8589 | to it. Do it in two passes, solely to preserve the current |
8590 | behavior that from_tty is forced true if we delete more than | |
8591 | one breakpoint. */ | |
c906108c | 8592 | |
80f8a6eb | 8593 | found = NULL; |
c906108c SS |
8594 | for (i = 0; i < sals.nelts; i++) |
8595 | { | |
8596 | /* If exact pc given, clear bpts at that pc. | |
c5aa993b JM |
8597 | If line given (pc == 0), clear all bpts on specified line. |
8598 | If defaulting, clear all bpts on default line | |
c906108c | 8599 | or at default pc. |
c5aa993b JM |
8600 | |
8601 | defaulting sal.pc != 0 tests to do | |
8602 | ||
8603 | 0 1 pc | |
8604 | 1 1 pc _and_ line | |
8605 | 0 0 line | |
8606 | 1 0 <can't happen> */ | |
c906108c SS |
8607 | |
8608 | sal = sals.sals[i]; | |
c906108c | 8609 | |
d6e956e5 VP |
8610 | /* Find all matching breakpoints and add them to |
8611 | 'found'. */ | |
8612 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8613 | { |
0d381245 | 8614 | int match = 0; |
80f8a6eb MS |
8615 | /* Are we going to delete b? */ |
8616 | if (b->type != bp_none | |
8617 | && b->type != bp_watchpoint | |
8618 | && b->type != bp_hardware_watchpoint | |
8619 | && b->type != bp_read_watchpoint | |
0d381245 VP |
8620 | && b->type != bp_access_watchpoint) |
8621 | { | |
8622 | struct bp_location *loc = b->loc; | |
8623 | for (; loc; loc = loc->next) | |
8624 | { | |
6c95b8df PA |
8625 | int pc_match = sal.pc |
8626 | && (loc->pspace == sal.pspace) | |
0d381245 VP |
8627 | && (loc->address == sal.pc) |
8628 | && (!section_is_overlay (loc->section) | |
8629 | || loc->section == sal.section); | |
8630 | int line_match = ((default_match || (0 == sal.pc)) | |
8631 | && b->source_file != NULL | |
8632 | && sal.symtab != NULL | |
6c95b8df | 8633 | && sal.pspace == loc->pspace |
0d381245 VP |
8634 | && strcmp (b->source_file, sal.symtab->filename) == 0 |
8635 | && b->line_number == sal.line); | |
8636 | if (pc_match || line_match) | |
8637 | { | |
8638 | match = 1; | |
8639 | break; | |
8640 | } | |
8641 | } | |
8642 | } | |
8643 | ||
8644 | if (match) | |
d6e956e5 | 8645 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 8646 | } |
80f8a6eb MS |
8647 | } |
8648 | /* Now go thru the 'found' chain and delete them. */ | |
d6e956e5 | 8649 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
8650 | { |
8651 | if (arg) | |
8a3fe4f8 | 8652 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 8653 | else |
8a3fe4f8 | 8654 | error (_("No breakpoint at this line.")); |
80f8a6eb | 8655 | } |
c906108c | 8656 | |
d6e956e5 | 8657 | if (VEC_length(breakpoint_p, found) > 1) |
80f8a6eb MS |
8658 | from_tty = 1; /* Always report if deleted more than one */ |
8659 | if (from_tty) | |
a3f17187 | 8660 | { |
d6e956e5 | 8661 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
8662 | printf_unfiltered (_("Deleted breakpoint ")); |
8663 | else | |
8664 | printf_unfiltered (_("Deleted breakpoints ")); | |
8665 | } | |
80f8a6eb | 8666 | breakpoints_changed (); |
d6e956e5 VP |
8667 | |
8668 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 8669 | { |
c5aa993b | 8670 | if (from_tty) |
d6e956e5 VP |
8671 | printf_unfiltered ("%d ", b->number); |
8672 | delete_breakpoint (b); | |
c906108c | 8673 | } |
80f8a6eb MS |
8674 | if (from_tty) |
8675 | putchar_unfiltered ('\n'); | |
c906108c SS |
8676 | } |
8677 | \f | |
8678 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
8679 | all breakpoints that are marked for deletion, whether hit or not. | |
8680 | This is called after any breakpoint is hit, or after errors. */ | |
8681 | ||
8682 | void | |
fba45db2 | 8683 | breakpoint_auto_delete (bpstat bs) |
c906108c SS |
8684 | { |
8685 | struct breakpoint *b, *temp; | |
8686 | ||
8687 | for (; bs; bs = bs->next) | |
20874c92 VP |
8688 | if (bs->breakpoint_at |
8689 | && bs->breakpoint_at->owner | |
8690 | && bs->breakpoint_at->owner->disposition == disp_del | |
c906108c | 8691 | && bs->stop) |
4f8d1dc6 | 8692 | delete_breakpoint (bs->breakpoint_at->owner); |
c906108c SS |
8693 | |
8694 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b | 8695 | { |
b5de0fa7 | 8696 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
8697 | delete_breakpoint (b); |
8698 | } | |
c906108c SS |
8699 | } |
8700 | ||
494cfb0f | 8701 | /* A comparison function for bp_location AP and BP being interfaced to qsort. |
876fa593 JK |
8702 | Sort elements primarily by their ADDRESS (no matter what does |
8703 | breakpoint_address_is_meaningful say for its OWNER), secondarily by ordering | |
8704 | first bp_permanent OWNERed elements and terciarily just ensuring the array | |
8705 | is sorted stable way despite qsort being an instable algorithm. */ | |
8706 | ||
8707 | static int | |
494cfb0f | 8708 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 8709 | { |
494cfb0f JK |
8710 | struct bp_location *a = *(void **) ap; |
8711 | struct bp_location *b = *(void **) bp; | |
876fa593 JK |
8712 | int a_perm = a->owner->enable_state == bp_permanent; |
8713 | int b_perm = b->owner->enable_state == bp_permanent; | |
8714 | ||
8715 | if (a->address != b->address) | |
8716 | return (a->address > b->address) - (a->address < b->address); | |
8717 | ||
8718 | /* Sort permanent breakpoints first. */ | |
8719 | if (a_perm != b_perm) | |
8720 | return (a_perm < b_perm) - (a_perm > b_perm); | |
8721 | ||
8722 | /* Make the user-visible order stable across GDB runs. Locations of the same | |
8723 | breakpoint can be sorted in arbitrary order. */ | |
8724 | ||
8725 | if (a->owner->number != b->owner->number) | |
8726 | return (a->owner->number > b->owner->number) | |
8727 | - (a->owner->number < b->owner->number); | |
8728 | ||
8729 | return (a > b) - (a < b); | |
8730 | } | |
8731 | ||
876fa593 JK |
8732 | /* Set bp_location_placed_address_before_address_max and |
8733 | bp_location_shadow_len_after_address_max according to the current content of | |
8734 | the bp_location array. */ | |
f7545552 TT |
8735 | |
8736 | static void | |
876fa593 | 8737 | bp_location_target_extensions_update (void) |
f7545552 | 8738 | { |
876fa593 JK |
8739 | struct bp_location *bl, **blp_tmp; |
8740 | ||
8741 | bp_location_placed_address_before_address_max = 0; | |
8742 | bp_location_shadow_len_after_address_max = 0; | |
8743 | ||
8744 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
8745 | { | |
8746 | CORE_ADDR start, end, addr; | |
8747 | ||
8748 | if (!bp_location_has_shadow (bl)) | |
8749 | continue; | |
8750 | ||
8751 | start = bl->target_info.placed_address; | |
8752 | end = start + bl->target_info.shadow_len; | |
8753 | ||
8754 | gdb_assert (bl->address >= start); | |
8755 | addr = bl->address - start; | |
8756 | if (addr > bp_location_placed_address_before_address_max) | |
8757 | bp_location_placed_address_before_address_max = addr; | |
8758 | ||
8759 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
8760 | ||
8761 | gdb_assert (bl->address < end); | |
8762 | addr = end - bl->address; | |
8763 | if (addr > bp_location_shadow_len_after_address_max) | |
8764 | bp_location_shadow_len_after_address_max = addr; | |
8765 | } | |
f7545552 TT |
8766 | } |
8767 | ||
4cd9bd08 | 8768 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
b60e7edf PA |
8769 | into the inferior, only remove already-inserted locations that no |
8770 | longer should be inserted. Functions that delete a breakpoint or | |
8771 | breakpoints should pass false, so that deleting a breakpoint | |
8772 | doesn't have the side effect of inserting the locations of other | |
8773 | breakpoints that are marked not-inserted, but should_be_inserted | |
8774 | returns true on them. | |
8775 | ||
8776 | This behaviour is useful is situations close to tear-down -- e.g., | |
8777 | after an exec, while the target still has execution, but breakpoint | |
8778 | shadows of the previous executable image should *NOT* be restored | |
8779 | to the new image; or before detaching, where the target still has | |
8780 | execution and wants to delete breakpoints from GDB's lists, and all | |
8781 | breakpoints had already been removed from the inferior. */ | |
8782 | ||
0d381245 | 8783 | static void |
b60e7edf | 8784 | update_global_location_list (int should_insert) |
0d381245 | 8785 | { |
74960c60 | 8786 | struct breakpoint *b; |
876fa593 | 8787 | struct bp_location **locp, *loc; |
f7545552 TT |
8788 | struct cleanup *cleanups; |
8789 | ||
2d134ed3 PA |
8790 | /* Used in the duplicates detection below. When iterating over all |
8791 | bp_locations, points to the first bp_location of a given address. | |
8792 | Breakpoints and watchpoints of different types are never | |
8793 | duplicates of each other. Keep one pointer for each type of | |
8794 | breakpoint/watchpoint, so we only need to loop over all locations | |
8795 | once. */ | |
8796 | struct bp_location *bp_loc_first; /* breakpoint */ | |
8797 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
8798 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
8799 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 JK |
8800 | |
8801 | /* Saved former bp_location array which we compare against the newly built | |
8802 | bp_location from the current state of ALL_BREAKPOINTS. */ | |
8803 | struct bp_location **old_location, **old_locp; | |
8804 | unsigned old_location_count; | |
8805 | ||
8806 | old_location = bp_location; | |
8807 | old_location_count = bp_location_count; | |
8808 | bp_location = NULL; | |
8809 | bp_location_count = 0; | |
8810 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 8811 | |
74960c60 | 8812 | ALL_BREAKPOINTS (b) |
876fa593 JK |
8813 | for (loc = b->loc; loc; loc = loc->next) |
8814 | bp_location_count++; | |
8815 | ||
8816 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); | |
8817 | locp = bp_location; | |
8818 | ALL_BREAKPOINTS (b) | |
8819 | for (loc = b->loc; loc; loc = loc->next) | |
8820 | *locp++ = loc; | |
8821 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 8822 | bp_location_compare); |
876fa593 JK |
8823 | |
8824 | bp_location_target_extensions_update (); | |
74960c60 VP |
8825 | |
8826 | /* Identify bp_location instances that are no longer present in the new | |
8827 | list, and therefore should be freed. Note that it's not necessary that | |
8828 | those locations should be removed from inferior -- if there's another | |
8829 | location at the same address (previously marked as duplicate), | |
876fa593 JK |
8830 | we don't need to remove/insert the location. |
8831 | ||
8832 | LOCP is kept in sync with OLD_LOCP, each pointing to the current and | |
8833 | former bp_location array state respectively. */ | |
8834 | ||
8835 | locp = bp_location; | |
8836 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
8837 | old_locp++) | |
74960c60 | 8838 | { |
876fa593 | 8839 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 8840 | struct bp_location **loc2p; |
876fa593 JK |
8841 | |
8842 | /* Tells if 'old_loc' is found amoung the new locations. If not, we | |
74960c60 | 8843 | have to free it. */ |
c7d46a38 | 8844 | int found_object = 0; |
20874c92 VP |
8845 | /* Tells if the location should remain inserted in the target. */ |
8846 | int keep_in_target = 0; | |
8847 | int removed = 0; | |
876fa593 JK |
8848 | |
8849 | /* Skip LOCP entries which will definitely never be needed. Stop either | |
8850 | at or being the one matching OLD_LOC. */ | |
8851 | while (locp < bp_location + bp_location_count | |
c7d46a38 | 8852 | && (*locp)->address < old_loc->address) |
876fa593 | 8853 | locp++; |
c7d46a38 PA |
8854 | |
8855 | for (loc2p = locp; | |
8856 | (loc2p < bp_location + bp_location_count | |
8857 | && (*loc2p)->address == old_loc->address); | |
8858 | loc2p++) | |
8859 | { | |
8860 | if (*loc2p == old_loc) | |
8861 | { | |
8862 | found_object = 1; | |
8863 | break; | |
8864 | } | |
8865 | } | |
74960c60 VP |
8866 | |
8867 | /* If this location is no longer present, and inserted, look if there's | |
8868 | maybe a new location at the same address. If so, mark that one | |
8869 | inserted, and don't remove this one. This is needed so that we | |
8870 | don't have a time window where a breakpoint at certain location is not | |
8871 | inserted. */ | |
8872 | ||
876fa593 | 8873 | if (old_loc->inserted) |
0d381245 | 8874 | { |
74960c60 | 8875 | /* If the location is inserted now, we might have to remove it. */ |
74960c60 | 8876 | |
876fa593 | 8877 | if (found_object && should_be_inserted (old_loc)) |
74960c60 VP |
8878 | { |
8879 | /* The location is still present in the location list, and still | |
8880 | should be inserted. Don't do anything. */ | |
20874c92 | 8881 | keep_in_target = 1; |
74960c60 VP |
8882 | } |
8883 | else | |
8884 | { | |
8885 | /* The location is either no longer present, or got disabled. | |
8886 | See if there's another location at the same address, in which | |
8887 | case we don't need to remove this one from the target. */ | |
876fa593 JK |
8888 | |
8889 | if (breakpoint_address_is_meaningful (old_loc->owner)) | |
8890 | { | |
876fa593 | 8891 | for (loc2p = locp; |
c7d46a38 PA |
8892 | (loc2p < bp_location + bp_location_count |
8893 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
8894 | loc2p++) |
8895 | { | |
8896 | struct bp_location *loc2 = *loc2p; | |
8897 | ||
2d134ed3 | 8898 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 PA |
8899 | { |
8900 | /* For the sake of should_be_inserted. | |
8901 | Duplicates check below will fix up this later. */ | |
8902 | loc2->duplicate = 0; | |
85d721b8 PA |
8903 | |
8904 | /* Read watchpoint locations are switched to | |
8905 | access watchpoints, if the former are not | |
8906 | supported, but the latter are. */ | |
8907 | if (is_hardware_watchpoint (old_loc->owner)) | |
8908 | { | |
8909 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
8910 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
8911 | } | |
8912 | ||
c7d46a38 PA |
8913 | if (loc2 != old_loc && should_be_inserted (loc2)) |
8914 | { | |
8915 | loc2->inserted = 1; | |
8916 | loc2->target_info = old_loc->target_info; | |
8917 | keep_in_target = 1; | |
8918 | break; | |
8919 | } | |
876fa593 JK |
8920 | } |
8921 | } | |
8922 | } | |
74960c60 VP |
8923 | } |
8924 | ||
20874c92 VP |
8925 | if (!keep_in_target) |
8926 | { | |
876fa593 | 8927 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 VP |
8928 | { |
8929 | /* This is just about all we can do. We could keep this | |
8930 | location on the global list, and try to remove it next | |
8931 | time, but there's no particular reason why we will | |
8932 | succeed next time. | |
8933 | ||
876fa593 | 8934 | Note that at this point, old_loc->owner is still valid, |
20874c92 VP |
8935 | as delete_breakpoint frees the breakpoint only |
8936 | after calling us. */ | |
8937 | printf_filtered (_("warning: Error removing breakpoint %d\n"), | |
876fa593 | 8938 | old_loc->owner->number); |
20874c92 VP |
8939 | } |
8940 | removed = 1; | |
8941 | } | |
0d381245 | 8942 | } |
74960c60 VP |
8943 | |
8944 | if (!found_object) | |
1c5cfe86 | 8945 | { |
db82e815 PA |
8946 | if (removed && non_stop |
8947 | && breakpoint_address_is_meaningful (old_loc->owner) | |
8948 | && !is_hardware_watchpoint (old_loc->owner)) | |
20874c92 | 8949 | { |
db82e815 PA |
8950 | /* This location was removed from the target. In |
8951 | non-stop mode, a race condition is possible where | |
8952 | we've removed a breakpoint, but stop events for that | |
8953 | breakpoint are already queued and will arrive later. | |
8954 | We apply an heuristic to be able to distinguish such | |
8955 | SIGTRAPs from other random SIGTRAPs: we keep this | |
8956 | breakpoint location for a bit, and will retire it | |
8957 | after we see some number of events. The theory here | |
8958 | is that reporting of events should, "on the average", | |
8959 | be fair, so after a while we'll see events from all | |
8960 | threads that have anything of interest, and no longer | |
8961 | need to keep this breakpoint location around. We | |
8962 | don't hold locations forever so to reduce chances of | |
8963 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
8964 | SIGTRAP. | |
8965 | ||
8966 | The heuristic failing can be disastrous on | |
8967 | decr_pc_after_break targets. | |
8968 | ||
8969 | On decr_pc_after_break targets, like e.g., x86-linux, | |
8970 | if we fail to recognize a late breakpoint SIGTRAP, | |
8971 | because events_till_retirement has reached 0 too | |
8972 | soon, we'll fail to do the PC adjustment, and report | |
8973 | a random SIGTRAP to the user. When the user resumes | |
8974 | the inferior, it will most likely immediately crash | |
8975 | with SIGILL/SIGBUS/SEGSEGV, or worse, get silently | |
8976 | corrupted, because of being resumed e.g., in the | |
8977 | middle of a multi-byte instruction, or skipped a | |
8978 | one-byte instruction. This was actually seen happen | |
8979 | on native x86-linux, and should be less rare on | |
8980 | targets that do not support new thread events, like | |
8981 | remote, due to the heuristic depending on | |
8982 | thread_count. | |
8983 | ||
8984 | Mistaking a random SIGTRAP for a breakpoint trap | |
8985 | causes similar symptoms (PC adjustment applied when | |
8986 | it shouldn't), but then again, playing with SIGTRAPs | |
8987 | behind the debugger's back is asking for trouble. | |
8988 | ||
8989 | Since hardware watchpoint traps are always | |
8990 | distinguishable from other traps, so we don't need to | |
8991 | apply keep hardware watchpoint moribund locations | |
8992 | around. We simply always ignore hardware watchpoint | |
8993 | traps we can no longer explain. */ | |
8994 | ||
876fa593 JK |
8995 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
8996 | old_loc->owner = NULL; | |
20874c92 | 8997 | |
876fa593 | 8998 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
8999 | } |
9000 | else | |
876fa593 | 9001 | free_bp_location (old_loc); |
20874c92 | 9002 | } |
74960c60 | 9003 | } |
1c5cfe86 | 9004 | |
2d134ed3 PA |
9005 | /* Rescan breakpoints at the same address and section, marking the |
9006 | first one as "first" and any others as "duplicates". This is so | |
9007 | that the bpt instruction is only inserted once. If we have a | |
9008 | permanent breakpoint at the same place as BPT, make that one the | |
9009 | official one, and the rest as duplicates. Permanent breakpoints | |
9010 | are sorted first for the same address. | |
9011 | ||
9012 | Do the same for hardware watchpoints, but also considering the | |
9013 | watchpoint's type (regular/access/read) and length. */ | |
876fa593 | 9014 | |
2d134ed3 PA |
9015 | bp_loc_first = NULL; |
9016 | wp_loc_first = NULL; | |
9017 | awp_loc_first = NULL; | |
9018 | rwp_loc_first = NULL; | |
876fa593 | 9019 | ALL_BP_LOCATIONS (loc, locp) |
74960c60 | 9020 | { |
876fa593 | 9021 | struct breakpoint *b = loc->owner; |
2d134ed3 | 9022 | struct bp_location **loc_first_p; |
876fa593 JK |
9023 | |
9024 | if (b->enable_state == bp_disabled | |
9025 | || b->enable_state == bp_call_disabled | |
9026 | || b->enable_state == bp_startup_disabled | |
9027 | || !loc->enabled | |
9028 | || loc->shlib_disabled | |
15c3d785 PA |
9029 | || !breakpoint_address_is_meaningful (b) |
9030 | || tracepoint_type (b)) | |
876fa593 JK |
9031 | continue; |
9032 | ||
9033 | /* Permanent breakpoint should always be inserted. */ | |
9034 | if (b->enable_state == bp_permanent && ! loc->inserted) | |
9035 | internal_error (__FILE__, __LINE__, | |
9036 | _("allegedly permanent breakpoint is not " | |
9037 | "actually inserted")); | |
9038 | ||
2d134ed3 PA |
9039 | if (b->type == bp_hardware_watchpoint) |
9040 | loc_first_p = &wp_loc_first; | |
9041 | else if (b->type == bp_read_watchpoint) | |
9042 | loc_first_p = &rwp_loc_first; | |
9043 | else if (b->type == bp_access_watchpoint) | |
9044 | loc_first_p = &awp_loc_first; | |
9045 | else | |
9046 | loc_first_p = &bp_loc_first; | |
9047 | ||
9048 | if (*loc_first_p == NULL | |
9049 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
9050 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
876fa593 | 9051 | { |
2d134ed3 | 9052 | *loc_first_p = loc; |
876fa593 JK |
9053 | loc->duplicate = 0; |
9054 | continue; | |
9055 | } | |
9056 | ||
9057 | loc->duplicate = 1; | |
9058 | ||
2d134ed3 PA |
9059 | if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted |
9060 | && b->enable_state != bp_permanent) | |
876fa593 JK |
9061 | internal_error (__FILE__, __LINE__, |
9062 | _("another breakpoint was inserted on top of " | |
9063 | "a permanent breakpoint")); | |
0d381245 | 9064 | } |
74960c60 | 9065 | |
50c71eaf | 9066 | if (breakpoints_always_inserted_mode () && should_insert |
c35b1492 | 9067 | && (have_live_inferiors () |
2567c7d9 | 9068 | || (gdbarch_has_global_breakpoints (target_gdbarch)))) |
74960c60 | 9069 | insert_breakpoint_locations (); |
f7545552 TT |
9070 | |
9071 | do_cleanups (cleanups); | |
74960c60 VP |
9072 | } |
9073 | ||
20874c92 VP |
9074 | void |
9075 | breakpoint_retire_moribund (void) | |
9076 | { | |
9077 | struct bp_location *loc; | |
9078 | int ix; | |
9079 | ||
9080 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
9081 | if (--(loc->events_till_retirement) == 0) | |
9082 | { | |
9083 | free_bp_location (loc); | |
9084 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
9085 | --ix; | |
9086 | } | |
9087 | } | |
9088 | ||
74960c60 | 9089 | static void |
b60e7edf | 9090 | update_global_location_list_nothrow (int inserting) |
74960c60 VP |
9091 | { |
9092 | struct gdb_exception e; | |
9093 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
b60e7edf | 9094 | update_global_location_list (inserting); |
0d381245 VP |
9095 | } |
9096 | ||
a474d7c2 PA |
9097 | /* Clear BPT from a BPS. */ |
9098 | static void | |
9099 | bpstat_remove_breakpoint (bpstat bps, struct breakpoint *bpt) | |
9100 | { | |
9101 | bpstat bs; | |
9102 | for (bs = bps; bs; bs = bs->next) | |
9103 | if (bs->breakpoint_at && bs->breakpoint_at->owner == bpt) | |
9104 | { | |
9105 | bs->breakpoint_at = NULL; | |
9106 | bs->old_val = NULL; | |
9107 | /* bs->commands will be freed later. */ | |
9108 | } | |
9109 | } | |
9110 | ||
9111 | /* Callback for iterate_over_threads. */ | |
9112 | static int | |
9113 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
9114 | { | |
9115 | struct breakpoint *bpt = data; | |
9116 | bpstat_remove_breakpoint (th->stop_bpstat, bpt); | |
9117 | return 0; | |
9118 | } | |
9119 | ||
53a5351d JM |
9120 | /* Delete a breakpoint and clean up all traces of it in the data |
9121 | structures. */ | |
c906108c SS |
9122 | |
9123 | void | |
fba45db2 | 9124 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 9125 | { |
52f0bd74 | 9126 | struct breakpoint *b; |
74960c60 | 9127 | struct bp_location *loc, *next; |
c906108c | 9128 | |
8a3fe4f8 | 9129 | gdb_assert (bpt != NULL); |
c906108c SS |
9130 | |
9131 | /* Has this bp already been deleted? This can happen because multiple | |
9132 | lists can hold pointers to bp's. bpstat lists are especial culprits. | |
9133 | ||
9134 | One example of this happening is a watchpoint's scope bp. When the | |
9135 | scope bp triggers, we notice that the watchpoint is out of scope, and | |
9136 | delete it. We also delete its scope bp. But the scope bp is marked | |
9137 | "auto-deleting", and is already on a bpstat. That bpstat is then | |
9138 | checked for auto-deleting bp's, which are deleted. | |
9139 | ||
9140 | A real solution to this problem might involve reference counts in bp's, | |
9141 | and/or giving them pointers back to their referencing bpstat's, and | |
9142 | teaching delete_breakpoint to only free a bp's storage when no more | |
1272ad14 | 9143 | references were extent. A cheaper bandaid was chosen. */ |
c906108c SS |
9144 | if (bpt->type == bp_none) |
9145 | return; | |
9146 | ||
e5a0a904 JK |
9147 | /* At least avoid this stale reference until the reference counting of |
9148 | breakpoints gets resolved. */ | |
9149 | if (bpt->related_breakpoint != NULL) | |
9150 | { | |
9151 | gdb_assert (bpt->related_breakpoint->related_breakpoint == bpt); | |
9152 | bpt->related_breakpoint->disposition = disp_del_at_next_stop; | |
9153 | bpt->related_breakpoint->related_breakpoint = NULL; | |
9154 | bpt->related_breakpoint = NULL; | |
9155 | } | |
9156 | ||
383f836e | 9157 | observer_notify_breakpoint_deleted (bpt->number); |
c906108c | 9158 | |
c906108c SS |
9159 | if (breakpoint_chain == bpt) |
9160 | breakpoint_chain = bpt->next; | |
9161 | ||
c906108c SS |
9162 | ALL_BREAKPOINTS (b) |
9163 | if (b->next == bpt) | |
c5aa993b JM |
9164 | { |
9165 | b->next = bpt->next; | |
9166 | break; | |
9167 | } | |
c906108c | 9168 | |
9add0f1b | 9169 | decref_counted_command_line (&bpt->commands); |
60e1c644 PA |
9170 | xfree (bpt->cond_string); |
9171 | xfree (bpt->cond_exp); | |
9172 | xfree (bpt->addr_string); | |
9173 | xfree (bpt->exp); | |
9174 | xfree (bpt->exp_string); | |
9175 | value_free (bpt->val); | |
9176 | xfree (bpt->source_file); | |
9177 | xfree (bpt->exec_pathname); | |
a96d9b2e | 9178 | clean_up_filters (&bpt->syscalls_to_be_caught); |
c906108c SS |
9179 | |
9180 | /* Be sure no bpstat's are pointing at it after it's been freed. */ | |
9181 | /* FIXME, how can we find all bpstat's? | |
198757a8 VP |
9182 | We just check stop_bpstat for now. Note that we cannot just |
9183 | remove bpstats pointing at bpt from the stop_bpstat list | |
9184 | entirely, as breakpoint commands are associated with the bpstat; | |
9185 | if we remove it here, then the later call to | |
9186 | bpstat_do_actions (&stop_bpstat); | |
9187 | in event-top.c won't do anything, and temporary breakpoints | |
9188 | with commands won't work. */ | |
a474d7c2 | 9189 | |
a474d7c2 | 9190 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); |
74960c60 VP |
9191 | |
9192 | /* Now that breakpoint is removed from breakpoint | |
9193 | list, update the global location list. This | |
9194 | will remove locations that used to belong to | |
9195 | this breakpoint. Do this before freeing | |
9196 | the breakpoint itself, since remove_breakpoint | |
9197 | looks at location's owner. It might be better | |
9198 | design to have location completely self-contained, | |
9199 | but it's not the case now. */ | |
b60e7edf | 9200 | update_global_location_list (0); |
74960c60 VP |
9201 | |
9202 | ||
c906108c SS |
9203 | /* On the chance that someone will soon try again to delete this same |
9204 | bp, we mark it as deleted before freeing its storage. */ | |
9205 | bpt->type = bp_none; | |
9206 | ||
b8c9b27d | 9207 | xfree (bpt); |
c906108c SS |
9208 | } |
9209 | ||
4d6140d9 AC |
9210 | static void |
9211 | do_delete_breakpoint_cleanup (void *b) | |
9212 | { | |
9213 | delete_breakpoint (b); | |
9214 | } | |
9215 | ||
9216 | struct cleanup * | |
9217 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
9218 | { | |
9219 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
9220 | } | |
9221 | ||
95a42b64 TT |
9222 | /* A callback for map_breakpoint_numbers that calls |
9223 | delete_breakpoint. */ | |
9224 | ||
9225 | static void | |
9226 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
9227 | { | |
9228 | delete_breakpoint (b); | |
9229 | } | |
9230 | ||
c906108c | 9231 | void |
fba45db2 | 9232 | delete_command (char *arg, int from_tty) |
c906108c SS |
9233 | { |
9234 | struct breakpoint *b, *temp; | |
9235 | ||
ea9365bb TT |
9236 | dont_repeat (); |
9237 | ||
c906108c SS |
9238 | if (arg == 0) |
9239 | { | |
9240 | int breaks_to_delete = 0; | |
9241 | ||
9242 | /* Delete all breakpoints if no argument. | |
c5aa993b JM |
9243 | Do not delete internal or call-dummy breakpoints, these |
9244 | have to be deleted with an explicit breakpoint number argument. */ | |
9245 | ALL_BREAKPOINTS (b) | |
9246 | { | |
059fb39f | 9247 | if (b->type != bp_call_dummy |
aa7d318d | 9248 | && b->type != bp_std_terminate |
059fb39f | 9249 | && b->type != bp_shlib_event |
4efc6507 | 9250 | && b->type != bp_jit_event |
059fb39f PM |
9251 | && b->type != bp_thread_event |
9252 | && b->type != bp_overlay_event | |
0fd8e87f | 9253 | && b->type != bp_longjmp_master |
aa7d318d | 9254 | && b->type != bp_std_terminate_master |
059fb39f | 9255 | && b->number >= 0) |
973d738b DJ |
9256 | { |
9257 | breaks_to_delete = 1; | |
9258 | break; | |
9259 | } | |
c5aa993b | 9260 | } |
c906108c SS |
9261 | |
9262 | /* Ask user only if there are some breakpoints to delete. */ | |
9263 | if (!from_tty | |
e2e0b3e5 | 9264 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 9265 | { |
c5aa993b JM |
9266 | ALL_BREAKPOINTS_SAFE (b, temp) |
9267 | { | |
059fb39f | 9268 | if (b->type != bp_call_dummy |
aa7d318d | 9269 | && b->type != bp_std_terminate |
059fb39f PM |
9270 | && b->type != bp_shlib_event |
9271 | && b->type != bp_thread_event | |
4efc6507 | 9272 | && b->type != bp_jit_event |
059fb39f | 9273 | && b->type != bp_overlay_event |
0fd8e87f | 9274 | && b->type != bp_longjmp_master |
aa7d318d | 9275 | && b->type != bp_std_terminate_master |
059fb39f | 9276 | && b->number >= 0) |
c5aa993b JM |
9277 | delete_breakpoint (b); |
9278 | } | |
c906108c SS |
9279 | } |
9280 | } | |
9281 | else | |
95a42b64 | 9282 | map_breakpoint_numbers (arg, do_delete_breakpoint, NULL); |
c906108c SS |
9283 | } |
9284 | ||
0d381245 VP |
9285 | static int |
9286 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 9287 | { |
0d381245 VP |
9288 | for (; loc; loc = loc->next) |
9289 | if (!loc->shlib_disabled) | |
9290 | return 0; | |
9291 | return 1; | |
fe3f5fa8 VP |
9292 | } |
9293 | ||
776592bf DE |
9294 | /* Subroutine of update_breakpoint_locations to simplify it. |
9295 | Return non-zero if multiple fns in list LOC have the same name. | |
9296 | Null names are ignored. */ | |
9297 | ||
9298 | static int | |
9299 | ambiguous_names_p (struct bp_location *loc) | |
9300 | { | |
9301 | struct bp_location *l; | |
9302 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
9303 | (int (*) (const void *, const void *)) streq, | |
9304 | NULL, xcalloc, xfree); | |
9305 | ||
9306 | for (l = loc; l != NULL; l = l->next) | |
9307 | { | |
9308 | const char **slot; | |
9309 | const char *name = l->function_name; | |
9310 | ||
9311 | /* Allow for some names to be NULL, ignore them. */ | |
9312 | if (name == NULL) | |
9313 | continue; | |
9314 | ||
9315 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
9316 | INSERT); | |
9317 | /* NOTE: We can assume slot != NULL here because xcalloc never returns | |
9318 | NULL. */ | |
9319 | if (*slot != NULL) | |
9320 | { | |
9321 | htab_delete (htab); | |
9322 | return 1; | |
9323 | } | |
9324 | *slot = name; | |
9325 | } | |
9326 | ||
9327 | htab_delete (htab); | |
9328 | return 0; | |
9329 | } | |
9330 | ||
fe3f5fa8 | 9331 | static void |
0d381245 VP |
9332 | update_breakpoint_locations (struct breakpoint *b, |
9333 | struct symtabs_and_lines sals) | |
fe3f5fa8 VP |
9334 | { |
9335 | int i; | |
9336 | char *s; | |
0d381245 VP |
9337 | struct bp_location *existing_locations = b->loc; |
9338 | ||
9339 | /* If there's no new locations, and all existing locations | |
9340 | are pending, don't do anything. This optimizes | |
9341 | the common case where all locations are in the same | |
9342 | shared library, that was unloaded. We'd like to | |
9343 | retain the location, so that when the library | |
9344 | is loaded again, we don't loose the enabled/disabled | |
9345 | status of the individual locations. */ | |
9346 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) | |
fe3f5fa8 VP |
9347 | return; |
9348 | ||
fe3f5fa8 VP |
9349 | b->loc = NULL; |
9350 | ||
0d381245 | 9351 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 9352 | { |
0d381245 | 9353 | struct bp_location *new_loc = |
39d61571 | 9354 | add_location_to_breakpoint (b, &(sals.sals[i])); |
fe3f5fa8 | 9355 | |
0d381245 VP |
9356 | /* Reparse conditions, they might contain references to the |
9357 | old symtab. */ | |
9358 | if (b->cond_string != NULL) | |
9359 | { | |
9360 | struct gdb_exception e; | |
fe3f5fa8 | 9361 | |
0d381245 VP |
9362 | s = b->cond_string; |
9363 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
9364 | { | |
9365 | new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), | |
9366 | 0); | |
9367 | } | |
9368 | if (e.reason < 0) | |
9369 | { | |
9370 | warning (_("failed to reevaluate condition for breakpoint %d: %s"), | |
9371 | b->number, e.message); | |
9372 | new_loc->enabled = 0; | |
9373 | } | |
9374 | } | |
fe3f5fa8 | 9375 | |
0d381245 VP |
9376 | if (b->source_file != NULL) |
9377 | xfree (b->source_file); | |
9378 | if (sals.sals[i].symtab == NULL) | |
9379 | b->source_file = NULL; | |
9380 | else | |
1b36a34b | 9381 | b->source_file = xstrdup (sals.sals[i].symtab->filename); |
fe3f5fa8 | 9382 | |
0d381245 VP |
9383 | if (b->line_number == 0) |
9384 | b->line_number = sals.sals[i].line; | |
9385 | } | |
fe3f5fa8 | 9386 | |
514f746b AR |
9387 | /* Update locations of permanent breakpoints. */ |
9388 | if (b->enable_state == bp_permanent) | |
9389 | make_breakpoint_permanent (b); | |
9390 | ||
0d381245 VP |
9391 | /* If possible, carry over 'disable' status from existing breakpoints. */ |
9392 | { | |
9393 | struct bp_location *e = existing_locations; | |
776592bf DE |
9394 | /* If there are multiple breakpoints with the same function name, |
9395 | e.g. for inline functions, comparing function names won't work. | |
9396 | Instead compare pc addresses; this is just a heuristic as things | |
9397 | may have moved, but in practice it gives the correct answer | |
9398 | often enough until a better solution is found. */ | |
9399 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
9400 | ||
0d381245 VP |
9401 | for (; e; e = e->next) |
9402 | { | |
9403 | if (!e->enabled && e->function_name) | |
9404 | { | |
9405 | struct bp_location *l = b->loc; | |
776592bf DE |
9406 | if (have_ambiguous_names) |
9407 | { | |
9408 | for (; l; l = l->next) | |
6c95b8df PA |
9409 | if (breakpoint_address_match (e->pspace->aspace, e->address, |
9410 | l->pspace->aspace, l->address)) | |
776592bf DE |
9411 | { |
9412 | l->enabled = 0; | |
9413 | break; | |
9414 | } | |
9415 | } | |
9416 | else | |
9417 | { | |
9418 | for (; l; l = l->next) | |
9419 | if (l->function_name | |
9420 | && strcmp (e->function_name, l->function_name) == 0) | |
9421 | { | |
9422 | l->enabled = 0; | |
9423 | break; | |
9424 | } | |
9425 | } | |
0d381245 VP |
9426 | } |
9427 | } | |
9428 | } | |
fe3f5fa8 | 9429 | |
b60e7edf | 9430 | update_global_location_list (1); |
fe3f5fa8 VP |
9431 | } |
9432 | ||
9433 | ||
c906108c SS |
9434 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
9435 | The value we return ends up being the return value from catch_errors. | |
9436 | Unused in this case. */ | |
9437 | ||
9438 | static int | |
4efb68b1 | 9439 | breakpoint_re_set_one (void *bint) |
c906108c | 9440 | { |
53a5351d JM |
9441 | /* get past catch_errs */ |
9442 | struct breakpoint *b = (struct breakpoint *) bint; | |
c906108c SS |
9443 | struct value *mark; |
9444 | int i; | |
fe3f5fa8 VP |
9445 | int not_found = 0; |
9446 | int *not_found_ptr = ¬_found; | |
6c95b8df PA |
9447 | struct symtabs_and_lines sals = {0}; |
9448 | struct symtabs_and_lines expanded = {0}; | |
c906108c | 9449 | char *s; |
b5de0fa7 | 9450 | enum enable_state save_enable; |
fe3f5fa8 | 9451 | struct gdb_exception e; |
6c95b8df | 9452 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
c906108c SS |
9453 | |
9454 | switch (b->type) | |
9455 | { | |
9456 | case bp_none: | |
8a3fe4f8 | 9457 | warning (_("attempted to reset apparently deleted breakpoint #%d?"), |
53a5351d | 9458 | b->number); |
c906108c SS |
9459 | return 0; |
9460 | case bp_breakpoint: | |
9461 | case bp_hardware_breakpoint: | |
1042e4c0 | 9462 | case bp_tracepoint: |
7a697b8d | 9463 | case bp_fast_tracepoint: |
8bea4e01 UW |
9464 | /* Do not attempt to re-set breakpoints disabled during startup. */ |
9465 | if (b->enable_state == bp_startup_disabled) | |
9466 | return 0; | |
9467 | ||
c906108c SS |
9468 | if (b->addr_string == NULL) |
9469 | { | |
9470 | /* Anything without a string can't be re-set. */ | |
9471 | delete_breakpoint (b); | |
9472 | return 0; | |
9473 | } | |
c906108c SS |
9474 | |
9475 | set_language (b->language); | |
9476 | input_radix = b->input_radix; | |
9477 | s = b->addr_string; | |
6c95b8df PA |
9478 | |
9479 | save_current_space_and_thread (); | |
9480 | switch_to_program_space_and_thread (b->pspace); | |
9481 | ||
fe3f5fa8 | 9482 | TRY_CATCH (e, RETURN_MASK_ERROR) |
c906108c | 9483 | { |
fe3f5fa8 VP |
9484 | sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL, |
9485 | not_found_ptr); | |
9486 | } | |
9487 | if (e.reason < 0) | |
9488 | { | |
9489 | int not_found_and_ok = 0; | |
9490 | /* For pending breakpoints, it's expected that parsing | |
9491 | will fail until the right shared library is loaded. | |
9492 | User has already told to create pending breakpoints and | |
9493 | don't need extra messages. If breakpoint is in bp_shlib_disabled | |
9494 | state, then user already saw the message about that breakpoint | |
9495 | being disabled, and don't want to see more errors. */ | |
0d381245 VP |
9496 | if (not_found |
9497 | && (b->condition_not_parsed | |
9498 | || (b->loc && b->loc->shlib_disabled) | |
9499 | || b->enable_state == bp_disabled)) | |
fe3f5fa8 VP |
9500 | not_found_and_ok = 1; |
9501 | ||
9502 | if (!not_found_and_ok) | |
c906108c | 9503 | { |
fe3f5fa8 VP |
9504 | /* We surely don't want to warn about the same breakpoint |
9505 | 10 times. One solution, implemented here, is disable | |
9506 | the breakpoint on error. Another solution would be to | |
9507 | have separate 'warning emitted' flag. Since this | |
9508 | happens only when a binary has changed, I don't know | |
9509 | which approach is better. */ | |
9510 | b->enable_state = bp_disabled; | |
9511 | throw_exception (e); | |
c906108c | 9512 | } |
fe3f5fa8 | 9513 | } |
c906108c | 9514 | |
6c95b8df | 9515 | if (!not_found) |
fe3f5fa8 | 9516 | { |
6c95b8df PA |
9517 | gdb_assert (sals.nelts == 1); |
9518 | ||
9519 | resolve_sal_pc (&sals.sals[0]); | |
9520 | if (b->condition_not_parsed && s && s[0]) | |
9521 | { | |
9522 | char *cond_string = 0; | |
9523 | int thread = -1; | |
9524 | int task = 0; | |
9525 | ||
9526 | find_condition_and_thread (s, sals.sals[0].pc, | |
9527 | &cond_string, &thread, &task); | |
9528 | if (cond_string) | |
9529 | b->cond_string = cond_string; | |
9530 | b->thread = thread; | |
9531 | b->task = task; | |
9532 | b->condition_not_parsed = 0; | |
9533 | } | |
9534 | ||
9535 | expanded = expand_line_sal_maybe (sals.sals[0]); | |
fe3f5fa8 | 9536 | } |
6c95b8df PA |
9537 | |
9538 | make_cleanup (xfree, sals.sals); | |
ed0616c6 | 9539 | update_breakpoint_locations (b, expanded); |
c906108c SS |
9540 | break; |
9541 | ||
9542 | case bp_watchpoint: | |
9543 | case bp_hardware_watchpoint: | |
9544 | case bp_read_watchpoint: | |
9545 | case bp_access_watchpoint: | |
0b3de036 VP |
9546 | /* Watchpoint can be either on expression using entirely global variables, |
9547 | or it can be on local variables. | |
9548 | ||
9549 | Watchpoints of the first kind are never auto-deleted, and even persist | |
9550 | across program restarts. Since they can use variables from shared | |
9551 | libraries, we need to reparse expression as libraries are loaded | |
9552 | and unloaded. | |
9553 | ||
9554 | Watchpoints on local variables can also change meaning as result | |
9555 | of solib event. For example, if a watchpoint uses both a local and | |
9556 | a global variables in expression, it's a local watchpoint, but | |
9557 | unloading of a shared library will make the expression invalid. | |
9558 | This is not a very common use case, but we still re-evaluate | |
9559 | expression, to avoid surprises to the user. | |
9560 | ||
9561 | Note that for local watchpoints, we re-evaluate it only if | |
9562 | watchpoints frame id is still valid. If it's not, it means | |
9563 | the watchpoint is out of scope and will be deleted soon. In fact, | |
9564 | I'm not sure we'll ever be called in this case. | |
9565 | ||
9566 | If a local watchpoint's frame id is still valid, then | |
9567 | b->exp_valid_block is likewise valid, and we can safely use it. | |
9568 | ||
9569 | Don't do anything about disabled watchpoints, since they will | |
9570 | be reevaluated again when enabled. */ | |
a5606eee | 9571 | update_watchpoint (b, 1 /* reparse */); |
c906108c | 9572 | break; |
c5aa993b JM |
9573 | /* We needn't really do anything to reset these, since the mask |
9574 | that requests them is unaffected by e.g., new libraries being | |
9575 | loaded. */ | |
ce78b96d | 9576 | case bp_catchpoint: |
c906108c | 9577 | break; |
c5aa993b | 9578 | |
c906108c | 9579 | default: |
a3f17187 | 9580 | printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type); |
c906108c | 9581 | /* fall through */ |
0fd8e87f UW |
9582 | /* Delete overlay event and longjmp master breakpoints; they will be |
9583 | reset later by breakpoint_re_set. */ | |
1900040c | 9584 | case bp_overlay_event: |
0fd8e87f | 9585 | case bp_longjmp_master: |
aa7d318d | 9586 | case bp_std_terminate_master: |
c906108c SS |
9587 | delete_breakpoint (b); |
9588 | break; | |
9589 | ||
c5aa993b JM |
9590 | /* This breakpoint is special, it's set up when the inferior |
9591 | starts and we really don't want to touch it. */ | |
c906108c SS |
9592 | case bp_shlib_event: |
9593 | ||
c4093a6a JM |
9594 | /* Like bp_shlib_event, this breakpoint type is special. |
9595 | Once it is set up, we do not want to touch it. */ | |
9596 | case bp_thread_event: | |
9597 | ||
c5aa993b JM |
9598 | /* Keep temporary breakpoints, which can be encountered when we step |
9599 | over a dlopen call and SOLIB_ADD is resetting the breakpoints. | |
9600 | Otherwise these should have been blown away via the cleanup chain | |
9601 | or by breakpoint_init_inferior when we rerun the executable. */ | |
c906108c SS |
9602 | case bp_until: |
9603 | case bp_finish: | |
9604 | case bp_watchpoint_scope: | |
9605 | case bp_call_dummy: | |
aa7d318d | 9606 | case bp_std_terminate: |
c906108c | 9607 | case bp_step_resume: |
611c83ae PA |
9608 | case bp_longjmp: |
9609 | case bp_longjmp_resume: | |
4efc6507 | 9610 | case bp_jit_event: |
c906108c SS |
9611 | break; |
9612 | } | |
9613 | ||
6c95b8df | 9614 | do_cleanups (cleanups); |
c906108c SS |
9615 | return 0; |
9616 | } | |
9617 | ||
69de3c6a | 9618 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 9619 | void |
69de3c6a | 9620 | breakpoint_re_set (void) |
c906108c SS |
9621 | { |
9622 | struct breakpoint *b, *temp; | |
9623 | enum language save_language; | |
9624 | int save_input_radix; | |
6c95b8df | 9625 | struct cleanup *old_chain; |
c5aa993b | 9626 | |
c906108c SS |
9627 | save_language = current_language->la_language; |
9628 | save_input_radix = input_radix; | |
6c95b8df PA |
9629 | old_chain = save_current_program_space (); |
9630 | ||
c906108c | 9631 | ALL_BREAKPOINTS_SAFE (b, temp) |
c5aa993b | 9632 | { |
53a5351d | 9633 | /* Format possible error msg */ |
fe3f5fa8 | 9634 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
9635 | b->number); |
9636 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 9637 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 9638 | do_cleanups (cleanups); |
c5aa993b | 9639 | } |
c906108c SS |
9640 | set_language (save_language); |
9641 | input_radix = save_input_radix; | |
e62c965a | 9642 | |
0756c555 | 9643 | jit_breakpoint_re_set (); |
4efc6507 | 9644 | |
6c95b8df PA |
9645 | do_cleanups (old_chain); |
9646 | ||
69de3c6a | 9647 | create_overlay_event_breakpoint ("_ovly_debug_event"); |
0fd8e87f UW |
9648 | create_longjmp_master_breakpoint ("longjmp"); |
9649 | create_longjmp_master_breakpoint ("_longjmp"); | |
9650 | create_longjmp_master_breakpoint ("siglongjmp"); | |
9651 | create_longjmp_master_breakpoint ("_siglongjmp"); | |
aa7d318d | 9652 | create_std_terminate_master_breakpoint ("std::terminate()"); |
c906108c SS |
9653 | } |
9654 | \f | |
c906108c SS |
9655 | /* Reset the thread number of this breakpoint: |
9656 | ||
9657 | - If the breakpoint is for all threads, leave it as-is. | |
39f77062 | 9658 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 9659 | void |
fba45db2 | 9660 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
9661 | { |
9662 | if (b->thread != -1) | |
9663 | { | |
39f77062 KB |
9664 | if (in_thread_list (inferior_ptid)) |
9665 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
9666 | |
9667 | /* We're being called after following a fork. The new fork is | |
9668 | selected as current, and unless this was a vfork will have a | |
9669 | different program space from the original thread. Reset that | |
9670 | as well. */ | |
9671 | b->loc->pspace = current_program_space; | |
c906108c SS |
9672 | } |
9673 | } | |
9674 | ||
03ac34d5 MS |
9675 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
9676 | If from_tty is nonzero, it prints a message to that effect, | |
9677 | which ends with a period (no newline). */ | |
9678 | ||
c906108c | 9679 | void |
fba45db2 | 9680 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 9681 | { |
52f0bd74 | 9682 | struct breakpoint *b; |
c906108c SS |
9683 | |
9684 | if (count < 0) | |
9685 | count = 0; | |
9686 | ||
9687 | ALL_BREAKPOINTS (b) | |
9688 | if (b->number == bptnum) | |
c5aa993b JM |
9689 | { |
9690 | b->ignore_count = count; | |
221ea385 KS |
9691 | if (from_tty) |
9692 | { | |
9693 | if (count == 0) | |
a3f17187 | 9694 | printf_filtered (_("Will stop next time breakpoint %d is reached."), |
221ea385 KS |
9695 | bptnum); |
9696 | else if (count == 1) | |
a3f17187 | 9697 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
9698 | bptnum); |
9699 | else | |
a3f17187 | 9700 | printf_filtered (_("Will ignore next %d crossings of breakpoint %d."), |
221ea385 KS |
9701 | count, bptnum); |
9702 | } | |
c5aa993b | 9703 | breakpoints_changed (); |
383f836e | 9704 | observer_notify_breakpoint_modified (b->number); |
c5aa993b JM |
9705 | return; |
9706 | } | |
c906108c | 9707 | |
8a3fe4f8 | 9708 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
9709 | } |
9710 | ||
b2175913 MS |
9711 | void |
9712 | make_breakpoint_silent (struct breakpoint *b) | |
9713 | { | |
9714 | /* Silence the breakpoint. */ | |
9715 | b->silent = 1; | |
9716 | } | |
9717 | ||
c906108c SS |
9718 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
9719 | ||
9720 | static void | |
fba45db2 | 9721 | ignore_command (char *args, int from_tty) |
c906108c SS |
9722 | { |
9723 | char *p = args; | |
52f0bd74 | 9724 | int num; |
c906108c SS |
9725 | |
9726 | if (p == 0) | |
e2e0b3e5 | 9727 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 9728 | |
c906108c | 9729 | num = get_number (&p); |
5c44784c | 9730 | if (num == 0) |
8a3fe4f8 | 9731 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 9732 | if (*p == 0) |
8a3fe4f8 | 9733 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
9734 | |
9735 | set_ignore_count (num, | |
9736 | longest_to_int (value_as_long (parse_and_eval (p))), | |
9737 | from_tty); | |
221ea385 KS |
9738 | if (from_tty) |
9739 | printf_filtered ("\n"); | |
c906108c SS |
9740 | } |
9741 | \f | |
9742 | /* Call FUNCTION on each of the breakpoints | |
9743 | whose numbers are given in ARGS. */ | |
9744 | ||
9745 | static void | |
95a42b64 TT |
9746 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
9747 | void *), | |
9748 | void *data) | |
c906108c | 9749 | { |
52f0bd74 | 9750 | char *p = args; |
c906108c | 9751 | char *p1; |
52f0bd74 AC |
9752 | int num; |
9753 | struct breakpoint *b, *tmp; | |
11cf8741 | 9754 | int match; |
c906108c SS |
9755 | |
9756 | if (p == 0) | |
e2e0b3e5 | 9757 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c SS |
9758 | |
9759 | while (*p) | |
9760 | { | |
11cf8741 | 9761 | match = 0; |
c906108c | 9762 | p1 = p; |
c5aa993b | 9763 | |
5c44784c JM |
9764 | num = get_number_or_range (&p1); |
9765 | if (num == 0) | |
c5aa993b | 9766 | { |
8a3fe4f8 | 9767 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
9768 | } |
9769 | else | |
9770 | { | |
9771 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
9772 | if (b->number == num) | |
9773 | { | |
9774 | struct breakpoint *related_breakpoint = b->related_breakpoint; | |
11cf8741 | 9775 | match = 1; |
95a42b64 | 9776 | function (b, data); |
5c44784c | 9777 | if (related_breakpoint) |
95a42b64 | 9778 | function (related_breakpoint, data); |
11cf8741 | 9779 | break; |
5c44784c | 9780 | } |
11cf8741 | 9781 | if (match == 0) |
a3f17187 | 9782 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 9783 | } |
c906108c SS |
9784 | p = p1; |
9785 | } | |
9786 | } | |
9787 | ||
0d381245 VP |
9788 | static struct bp_location * |
9789 | find_location_by_number (char *number) | |
9790 | { | |
9791 | char *dot = strchr (number, '.'); | |
9792 | char *p1; | |
9793 | int bp_num; | |
9794 | int loc_num; | |
9795 | struct breakpoint *b; | |
9796 | struct bp_location *loc; | |
9797 | ||
9798 | *dot = '\0'; | |
9799 | ||
9800 | p1 = number; | |
9801 | bp_num = get_number_or_range (&p1); | |
9802 | if (bp_num == 0) | |
9803 | error (_("Bad breakpoint number '%s'"), number); | |
9804 | ||
9805 | ALL_BREAKPOINTS (b) | |
9806 | if (b->number == bp_num) | |
9807 | { | |
9808 | break; | |
9809 | } | |
9810 | ||
9811 | if (!b || b->number != bp_num) | |
9812 | error (_("Bad breakpoint number '%s'"), number); | |
9813 | ||
9814 | p1 = dot+1; | |
9815 | loc_num = get_number_or_range (&p1); | |
9816 | if (loc_num == 0) | |
9817 | error (_("Bad breakpoint location number '%s'"), number); | |
9818 | ||
9819 | --loc_num; | |
9820 | loc = b->loc; | |
9821 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
9822 | ; | |
9823 | if (!loc) | |
9824 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
9825 | ||
9826 | return loc; | |
9827 | } | |
9828 | ||
9829 | ||
1900040c MS |
9830 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
9831 | If from_tty is nonzero, it prints a message to that effect, | |
9832 | which ends with a period (no newline). */ | |
9833 | ||
c906108c | 9834 | void |
fba45db2 | 9835 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
9836 | { |
9837 | /* Never disable a watchpoint scope breakpoint; we want to | |
9838 | hit them when we leave scope so we can delete both the | |
9839 | watchpoint and its scope breakpoint at that time. */ | |
9840 | if (bpt->type == bp_watchpoint_scope) | |
9841 | return; | |
9842 | ||
c2c6d25f | 9843 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 9844 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
9845 | return; |
9846 | ||
b5de0fa7 | 9847 | bpt->enable_state = bp_disabled; |
c906108c | 9848 | |
b60e7edf | 9849 | update_global_location_list (0); |
c906108c | 9850 | |
383f836e | 9851 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
9852 | } |
9853 | ||
95a42b64 TT |
9854 | /* A callback for map_breakpoint_numbers that calls |
9855 | disable_breakpoint. */ | |
9856 | ||
9857 | static void | |
9858 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
9859 | { | |
9860 | disable_breakpoint (b); | |
9861 | } | |
9862 | ||
c906108c | 9863 | static void |
fba45db2 | 9864 | disable_command (char *args, int from_tty) |
c906108c | 9865 | { |
52f0bd74 | 9866 | struct breakpoint *bpt; |
c906108c SS |
9867 | if (args == 0) |
9868 | ALL_BREAKPOINTS (bpt) | |
9869 | switch (bpt->type) | |
c5aa993b JM |
9870 | { |
9871 | case bp_none: | |
8a3fe4f8 | 9872 | warning (_("attempted to disable apparently deleted breakpoint #%d?"), |
53a5351d | 9873 | bpt->number); |
c5aa993b JM |
9874 | continue; |
9875 | case bp_breakpoint: | |
1042e4c0 | 9876 | case bp_tracepoint: |
7a697b8d | 9877 | case bp_fast_tracepoint: |
ce78b96d | 9878 | case bp_catchpoint: |
c5aa993b JM |
9879 | case bp_hardware_breakpoint: |
9880 | case bp_watchpoint: | |
9881 | case bp_hardware_watchpoint: | |
9882 | case bp_read_watchpoint: | |
9883 | case bp_access_watchpoint: | |
9884 | disable_breakpoint (bpt); | |
9885 | default: | |
9886 | continue; | |
9887 | } | |
0d381245 VP |
9888 | else if (strchr (args, '.')) |
9889 | { | |
9890 | struct bp_location *loc = find_location_by_number (args); | |
9891 | if (loc) | |
9892 | loc->enabled = 0; | |
b60e7edf | 9893 | update_global_location_list (0); |
0d381245 | 9894 | } |
c906108c | 9895 | else |
95a42b64 | 9896 | map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL); |
c906108c SS |
9897 | } |
9898 | ||
9899 | static void | |
fba45db2 | 9900 | do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition) |
c906108c | 9901 | { |
c906108c SS |
9902 | int target_resources_ok, other_type_used; |
9903 | struct value *mark; | |
9904 | ||
9905 | if (bpt->type == bp_hardware_breakpoint) | |
9906 | { | |
9907 | int i; | |
c5aa993b | 9908 | i = hw_breakpoint_used_count (); |
53a5351d | 9909 | target_resources_ok = |
d92524f1 | 9910 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 9911 | i + 1, 0); |
c906108c | 9912 | if (target_resources_ok == 0) |
8a3fe4f8 | 9913 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 9914 | else if (target_resources_ok < 0) |
8a3fe4f8 | 9915 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
9916 | } |
9917 | ||
059fb39f PM |
9918 | if (bpt->type == bp_watchpoint |
9919 | || bpt->type == bp_hardware_watchpoint | |
9920 | || bpt->type == bp_read_watchpoint | |
9921 | || bpt->type == bp_access_watchpoint) | |
c906108c | 9922 | { |
dde02812 ES |
9923 | struct gdb_exception e; |
9924 | ||
9925 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 9926 | { |
dde02812 | 9927 | update_watchpoint (bpt, 1 /* reparse */); |
c906108c | 9928 | } |
dde02812 | 9929 | if (e.reason < 0) |
c5aa993b | 9930 | { |
dde02812 ES |
9931 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
9932 | bpt->number); | |
9933 | return; | |
c5aa993b | 9934 | } |
c906108c | 9935 | } |
0101ce28 | 9936 | |
b4c291bb KH |
9937 | if (bpt->enable_state != bp_permanent) |
9938 | bpt->enable_state = bp_enabled; | |
9939 | bpt->disposition = disposition; | |
b60e7edf | 9940 | update_global_location_list (1); |
b4c291bb KH |
9941 | breakpoints_changed (); |
9942 | ||
383f836e | 9943 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
9944 | } |
9945 | ||
fe3f5fa8 | 9946 | |
c906108c | 9947 | void |
fba45db2 | 9948 | enable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
9949 | { |
9950 | do_enable_breakpoint (bpt, bpt->disposition); | |
9951 | } | |
9952 | ||
95a42b64 TT |
9953 | /* A callback for map_breakpoint_numbers that calls |
9954 | enable_breakpoint. */ | |
9955 | ||
9956 | static void | |
9957 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
9958 | { | |
9959 | enable_breakpoint (b); | |
9960 | } | |
9961 | ||
c906108c SS |
9962 | /* The enable command enables the specified breakpoints (or all defined |
9963 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 9964 | in stopping the inferior. */ |
c906108c | 9965 | |
c906108c | 9966 | static void |
fba45db2 | 9967 | enable_command (char *args, int from_tty) |
c906108c | 9968 | { |
52f0bd74 | 9969 | struct breakpoint *bpt; |
c906108c SS |
9970 | if (args == 0) |
9971 | ALL_BREAKPOINTS (bpt) | |
9972 | switch (bpt->type) | |
c5aa993b JM |
9973 | { |
9974 | case bp_none: | |
8a3fe4f8 | 9975 | warning (_("attempted to enable apparently deleted breakpoint #%d?"), |
53a5351d | 9976 | bpt->number); |
c5aa993b JM |
9977 | continue; |
9978 | case bp_breakpoint: | |
1042e4c0 | 9979 | case bp_tracepoint: |
7a697b8d | 9980 | case bp_fast_tracepoint: |
ce78b96d | 9981 | case bp_catchpoint: |
c5aa993b JM |
9982 | case bp_hardware_breakpoint: |
9983 | case bp_watchpoint: | |
9984 | case bp_hardware_watchpoint: | |
9985 | case bp_read_watchpoint: | |
9986 | case bp_access_watchpoint: | |
9987 | enable_breakpoint (bpt); | |
9988 | default: | |
9989 | continue; | |
9990 | } | |
0d381245 VP |
9991 | else if (strchr (args, '.')) |
9992 | { | |
9993 | struct bp_location *loc = find_location_by_number (args); | |
9994 | if (loc) | |
9995 | loc->enabled = 1; | |
b60e7edf | 9996 | update_global_location_list (1); |
0d381245 | 9997 | } |
c906108c | 9998 | else |
95a42b64 | 9999 | map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL); |
c906108c SS |
10000 | } |
10001 | ||
10002 | static void | |
95a42b64 | 10003 | enable_once_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 10004 | { |
b5de0fa7 | 10005 | do_enable_breakpoint (bpt, disp_disable); |
c906108c SS |
10006 | } |
10007 | ||
c906108c | 10008 | static void |
fba45db2 | 10009 | enable_once_command (char *args, int from_tty) |
c906108c | 10010 | { |
95a42b64 | 10011 | map_breakpoint_numbers (args, enable_once_breakpoint, NULL); |
c906108c SS |
10012 | } |
10013 | ||
10014 | static void | |
95a42b64 | 10015 | enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 10016 | { |
b5de0fa7 | 10017 | do_enable_breakpoint (bpt, disp_del); |
c906108c SS |
10018 | } |
10019 | ||
c906108c | 10020 | static void |
fba45db2 | 10021 | enable_delete_command (char *args, int from_tty) |
c906108c | 10022 | { |
95a42b64 | 10023 | map_breakpoint_numbers (args, enable_delete_breakpoint, NULL); |
c906108c SS |
10024 | } |
10025 | \f | |
fa8d40ab JJ |
10026 | static void |
10027 | set_breakpoint_cmd (char *args, int from_tty) | |
10028 | { | |
10029 | } | |
10030 | ||
10031 | static void | |
10032 | show_breakpoint_cmd (char *args, int from_tty) | |
10033 | { | |
10034 | } | |
10035 | ||
1f3b5d1b PP |
10036 | /* Invalidate last known value of any hardware watchpoint if |
10037 | the memory which that value represents has been written to by | |
10038 | GDB itself. */ | |
10039 | ||
10040 | static void | |
10041 | invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len, | |
10042 | const bfd_byte *data) | |
10043 | { | |
10044 | struct breakpoint *bp; | |
10045 | ||
10046 | ALL_BREAKPOINTS (bp) | |
10047 | if (bp->enable_state == bp_enabled | |
10048 | && bp->type == bp_hardware_watchpoint | |
10049 | && bp->val_valid && bp->val) | |
10050 | { | |
10051 | struct bp_location *loc; | |
10052 | ||
10053 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
10054 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
10055 | && loc->address + loc->length > addr | |
10056 | && addr + len > loc->address) | |
10057 | { | |
10058 | value_free (bp->val); | |
10059 | bp->val = NULL; | |
10060 | bp->val_valid = 0; | |
10061 | } | |
10062 | } | |
10063 | } | |
10064 | ||
c906108c SS |
10065 | /* Use default_breakpoint_'s, or nothing if they aren't valid. */ |
10066 | ||
10067 | struct symtabs_and_lines | |
fba45db2 | 10068 | decode_line_spec_1 (char *string, int funfirstline) |
c906108c SS |
10069 | { |
10070 | struct symtabs_and_lines sals; | |
10071 | if (string == 0) | |
8a3fe4f8 | 10072 | error (_("Empty line specification.")); |
c906108c SS |
10073 | if (default_breakpoint_valid) |
10074 | sals = decode_line_1 (&string, funfirstline, | |
53a5351d JM |
10075 | default_breakpoint_symtab, |
10076 | default_breakpoint_line, | |
68219205 | 10077 | (char ***) NULL, NULL); |
c906108c SS |
10078 | else |
10079 | sals = decode_line_1 (&string, funfirstline, | |
68219205 | 10080 | (struct symtab *) NULL, 0, (char ***) NULL, NULL); |
c906108c | 10081 | if (*string) |
8a3fe4f8 | 10082 | error (_("Junk at end of line specification: %s"), string); |
c906108c SS |
10083 | return sals; |
10084 | } | |
8181d85f DJ |
10085 | |
10086 | /* Create and insert a raw software breakpoint at PC. Return an | |
10087 | identifier, which should be used to remove the breakpoint later. | |
10088 | In general, places which call this should be using something on the | |
10089 | breakpoint chain instead; this function should be eliminated | |
10090 | someday. */ | |
10091 | ||
10092 | void * | |
6c95b8df PA |
10093 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, |
10094 | struct address_space *aspace, CORE_ADDR pc) | |
8181d85f DJ |
10095 | { |
10096 | struct bp_target_info *bp_tgt; | |
10097 | ||
6c95b8df | 10098 | bp_tgt = XZALLOC (struct bp_target_info); |
8181d85f | 10099 | |
6c95b8df | 10100 | bp_tgt->placed_address_space = aspace; |
8181d85f | 10101 | bp_tgt->placed_address = pc; |
6c95b8df | 10102 | |
a6d9a66e | 10103 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
8181d85f DJ |
10104 | { |
10105 | /* Could not insert the breakpoint. */ | |
10106 | xfree (bp_tgt); | |
10107 | return NULL; | |
10108 | } | |
10109 | ||
10110 | return bp_tgt; | |
10111 | } | |
10112 | ||
10113 | /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */ | |
10114 | ||
10115 | int | |
a6d9a66e | 10116 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
8181d85f DJ |
10117 | { |
10118 | struct bp_target_info *bp_tgt = bp; | |
10119 | int ret; | |
10120 | ||
a6d9a66e | 10121 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
8181d85f DJ |
10122 | xfree (bp_tgt); |
10123 | ||
10124 | return ret; | |
10125 | } | |
10126 | ||
10127 | /* One (or perhaps two) breakpoints used for software single stepping. */ | |
10128 | ||
10129 | static void *single_step_breakpoints[2]; | |
a6d9a66e | 10130 | static struct gdbarch *single_step_gdbarch[2]; |
8181d85f DJ |
10131 | |
10132 | /* Create and insert a breakpoint for software single step. */ | |
10133 | ||
10134 | void | |
6c95b8df PA |
10135 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
10136 | struct address_space *aspace, CORE_ADDR next_pc) | |
8181d85f DJ |
10137 | { |
10138 | void **bpt_p; | |
10139 | ||
10140 | if (single_step_breakpoints[0] == NULL) | |
a6d9a66e UW |
10141 | { |
10142 | bpt_p = &single_step_breakpoints[0]; | |
10143 | single_step_gdbarch[0] = gdbarch; | |
10144 | } | |
8181d85f DJ |
10145 | else |
10146 | { | |
10147 | gdb_assert (single_step_breakpoints[1] == NULL); | |
10148 | bpt_p = &single_step_breakpoints[1]; | |
a6d9a66e | 10149 | single_step_gdbarch[1] = gdbarch; |
8181d85f DJ |
10150 | } |
10151 | ||
10152 | /* NOTE drow/2006-04-11: A future improvement to this function would be | |
10153 | to only create the breakpoints once, and actually put them on the | |
10154 | breakpoint chain. That would let us use set_raw_breakpoint. We could | |
10155 | adjust the addresses each time they were needed. Doing this requires | |
10156 | corresponding changes elsewhere where single step breakpoints are | |
10157 | handled, however. So, for now, we use this. */ | |
10158 | ||
6c95b8df | 10159 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc); |
8181d85f | 10160 | if (*bpt_p == NULL) |
5af949e3 UW |
10161 | error (_("Could not insert single-step breakpoint at %s"), |
10162 | paddress (gdbarch, next_pc)); | |
8181d85f DJ |
10163 | } |
10164 | ||
10165 | /* Remove and delete any breakpoints used for software single step. */ | |
10166 | ||
10167 | void | |
10168 | remove_single_step_breakpoints (void) | |
10169 | { | |
10170 | gdb_assert (single_step_breakpoints[0] != NULL); | |
10171 | ||
10172 | /* See insert_single_step_breakpoint for more about this deprecated | |
10173 | call. */ | |
a6d9a66e UW |
10174 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
10175 | single_step_breakpoints[0]); | |
10176 | single_step_gdbarch[0] = NULL; | |
8181d85f DJ |
10177 | single_step_breakpoints[0] = NULL; |
10178 | ||
10179 | if (single_step_breakpoints[1] != NULL) | |
10180 | { | |
a6d9a66e UW |
10181 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
10182 | single_step_breakpoints[1]); | |
10183 | single_step_gdbarch[1] = NULL; | |
8181d85f DJ |
10184 | single_step_breakpoints[1] = NULL; |
10185 | } | |
10186 | } | |
10187 | ||
1aafd4da UW |
10188 | /* Check whether a software single-step breakpoint is inserted at PC. */ |
10189 | ||
10190 | static int | |
6c95b8df | 10191 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
1aafd4da UW |
10192 | { |
10193 | int i; | |
10194 | ||
10195 | for (i = 0; i < 2; i++) | |
10196 | { | |
10197 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
6c95b8df PA |
10198 | if (bp_tgt |
10199 | && breakpoint_address_match (bp_tgt->placed_address_space, | |
10200 | bp_tgt->placed_address, | |
10201 | aspace, pc)) | |
1aafd4da UW |
10202 | return 1; |
10203 | } | |
10204 | ||
10205 | return 0; | |
10206 | } | |
10207 | ||
a96d9b2e SDJ |
10208 | /* Returns 0 if 'bp' is NOT a syscall catchpoint, |
10209 | non-zero otherwise. */ | |
10210 | static int | |
10211 | is_syscall_catchpoint_enabled (struct breakpoint *bp) | |
10212 | { | |
10213 | if (syscall_catchpoint_p (bp) | |
10214 | && bp->enable_state != bp_disabled | |
10215 | && bp->enable_state != bp_call_disabled) | |
10216 | return 1; | |
10217 | else | |
10218 | return 0; | |
10219 | } | |
10220 | ||
10221 | int | |
10222 | catch_syscall_enabled (void) | |
10223 | { | |
10224 | struct inferior *inf = current_inferior (); | |
10225 | ||
10226 | return inf->total_syscalls_count != 0; | |
10227 | } | |
10228 | ||
10229 | int | |
10230 | catching_syscall_number (int syscall_number) | |
10231 | { | |
10232 | struct breakpoint *bp; | |
10233 | ||
10234 | ALL_BREAKPOINTS (bp) | |
10235 | if (is_syscall_catchpoint_enabled (bp)) | |
10236 | { | |
10237 | if (bp->syscalls_to_be_caught) | |
10238 | { | |
10239 | int i, iter; | |
10240 | for (i = 0; | |
10241 | VEC_iterate (int, bp->syscalls_to_be_caught, i, iter); | |
10242 | i++) | |
10243 | if (syscall_number == iter) | |
10244 | return 1; | |
10245 | } | |
10246 | else | |
10247 | return 1; | |
10248 | } | |
10249 | ||
10250 | return 0; | |
10251 | } | |
10252 | ||
10253 | /* Complete syscall names. Used by "catch syscall". */ | |
10254 | static char ** | |
10255 | catch_syscall_completer (struct cmd_list_element *cmd, | |
10256 | char *text, char *word) | |
10257 | { | |
10258 | const char **list = get_syscall_names (); | |
10259 | return (list == NULL) ? NULL : complete_on_enum (list, text, word); | |
10260 | } | |
10261 | ||
1042e4c0 SS |
10262 | /* Tracepoint-specific operations. */ |
10263 | ||
10264 | /* Set tracepoint count to NUM. */ | |
10265 | static void | |
10266 | set_tracepoint_count (int num) | |
10267 | { | |
10268 | tracepoint_count = num; | |
4fa62494 | 10269 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
10270 | } |
10271 | ||
10272 | void | |
10273 | trace_command (char *arg, int from_tty) | |
10274 | { | |
8cdf0e15 VP |
10275 | if (create_breakpoint (get_current_arch (), |
10276 | arg, | |
10277 | NULL, 0, 1 /* parse arg */, | |
10278 | 0 /* tempflag */, 0 /* hardwareflag */, | |
10279 | 1 /* traceflag */, | |
10280 | 0 /* Ignore count */, | |
10281 | pending_break_support, | |
10282 | NULL, | |
10283 | from_tty, | |
10284 | 1 /* enabled */)) | |
fd9b8c24 | 10285 | set_tracepoint_count (breakpoint_count); |
1042e4c0 SS |
10286 | } |
10287 | ||
7a697b8d SS |
10288 | void |
10289 | ftrace_command (char *arg, int from_tty) | |
10290 | { | |
8cdf0e15 VP |
10291 | if (create_breakpoint (get_current_arch (), |
10292 | arg, | |
10293 | NULL, 0, 1 /* parse arg */, | |
10294 | 0 /* tempflag */, 1 /* hardwareflag */, | |
10295 | 1 /* traceflag */, | |
10296 | 0 /* Ignore count */, | |
10297 | pending_break_support, | |
10298 | NULL, | |
10299 | from_tty, | |
10300 | 1 /* enabled */)) | |
fd9b8c24 | 10301 | set_tracepoint_count (breakpoint_count); |
7a697b8d SS |
10302 | } |
10303 | ||
00bf0b85 SS |
10304 | /* Given information about a tracepoint as recorded on a target (which |
10305 | can be either a live system or a trace file), attempt to create an | |
10306 | equivalent GDB tracepoint. This is not a reliable process, since | |
10307 | the target does not necessarily have all the information used when | |
10308 | the tracepoint was originally defined. */ | |
10309 | ||
10310 | struct breakpoint * | |
10311 | create_tracepoint_from_upload (struct uploaded_tp *utp) | |
d5551862 SS |
10312 | { |
10313 | char buf[100]; | |
10314 | struct breakpoint *tp; | |
fd9b8c24 | 10315 | |
00bf0b85 SS |
10316 | /* In the absence of a source location, fall back to raw address. */ |
10317 | sprintf (buf, "*%s", paddress (get_current_arch(), utp->addr)); | |
d5551862 | 10318 | |
8cdf0e15 VP |
10319 | if (!create_breakpoint (get_current_arch (), |
10320 | buf, | |
10321 | NULL, 0, 1 /* parse arg */, | |
10322 | 0 /* tempflag */, | |
10323 | (utp->type == bp_fast_tracepoint) /* hardwareflag */, | |
10324 | 1 /* traceflag */, | |
10325 | 0 /* Ignore count */, | |
10326 | pending_break_support, | |
10327 | NULL, | |
10328 | 0 /* from_tty */, | |
10329 | utp->enabled /* enabled */)) | |
fd9b8c24 PA |
10330 | return NULL; |
10331 | ||
00bf0b85 SS |
10332 | set_tracepoint_count (breakpoint_count); |
10333 | ||
fd9b8c24 PA |
10334 | tp = get_tracepoint (tracepoint_count); |
10335 | gdb_assert (tp != NULL); | |
d5551862 | 10336 | |
00bf0b85 SS |
10337 | if (utp->pass > 0) |
10338 | { | |
10339 | sprintf (buf, "%d %d", utp->pass, tp->number); | |
10340 | ||
10341 | trace_pass_command (buf, 0); | |
10342 | } | |
10343 | ||
10344 | if (utp->cond) | |
10345 | { | |
10346 | printf_filtered ("Want to restore a condition\n"); | |
10347 | } | |
10348 | ||
10349 | if (utp->numactions > 0) | |
10350 | { | |
10351 | printf_filtered ("Want to restore action list\n"); | |
10352 | } | |
d5551862 | 10353 | |
00bf0b85 SS |
10354 | if (utp->num_step_actions > 0) |
10355 | { | |
10356 | printf_filtered ("Want to restore action list\n"); | |
10357 | } | |
10358 | ||
10359 | return tp; | |
10360 | } | |
10361 | ||
1042e4c0 SS |
10362 | /* Print information on tracepoint number TPNUM_EXP, or all if |
10363 | omitted. */ | |
10364 | ||
10365 | static void | |
10366 | tracepoints_info (char *tpnum_exp, int from_tty) | |
10367 | { | |
10368 | struct breakpoint *b; | |
10369 | int tps_to_list = 0; | |
10370 | ||
10371 | /* In the no-arguments case, say "No tracepoints" if none found. */ | |
10372 | if (tpnum_exp == 0) | |
10373 | { | |
10374 | ALL_TRACEPOINTS (b) | |
10375 | { | |
10376 | if (b->number >= 0) | |
10377 | { | |
10378 | tps_to_list = 1; | |
10379 | break; | |
10380 | } | |
10381 | } | |
10382 | if (!tps_to_list) | |
10383 | { | |
10384 | ui_out_message (uiout, 0, "No tracepoints.\n"); | |
10385 | return; | |
10386 | } | |
10387 | } | |
10388 | ||
10389 | /* Otherwise be the same as "info break". */ | |
10390 | breakpoints_info (tpnum_exp, from_tty); | |
10391 | } | |
10392 | ||
10393 | /* The 'enable trace' command enables tracepoints. | |
10394 | Not supported by all targets. */ | |
10395 | static void | |
10396 | enable_trace_command (char *args, int from_tty) | |
10397 | { | |
10398 | enable_command (args, from_tty); | |
10399 | } | |
10400 | ||
10401 | /* The 'disable trace' command disables tracepoints. | |
10402 | Not supported by all targets. */ | |
10403 | static void | |
10404 | disable_trace_command (char *args, int from_tty) | |
10405 | { | |
10406 | disable_command (args, from_tty); | |
10407 | } | |
10408 | ||
10409 | /* Remove a tracepoint (or all if no argument) */ | |
10410 | static void | |
10411 | delete_trace_command (char *arg, int from_tty) | |
10412 | { | |
10413 | struct breakpoint *b, *temp; | |
10414 | ||
10415 | dont_repeat (); | |
10416 | ||
10417 | if (arg == 0) | |
10418 | { | |
10419 | int breaks_to_delete = 0; | |
10420 | ||
10421 | /* Delete all breakpoints if no argument. | |
10422 | Do not delete internal or call-dummy breakpoints, these | |
10423 | have to be deleted with an explicit breakpoint number argument. */ | |
10424 | ALL_TRACEPOINTS (b) | |
10425 | { | |
10426 | if (b->number >= 0) | |
10427 | { | |
10428 | breaks_to_delete = 1; | |
10429 | break; | |
10430 | } | |
10431 | } | |
10432 | ||
10433 | /* Ask user only if there are some breakpoints to delete. */ | |
10434 | if (!from_tty | |
10435 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
10436 | { | |
10437 | ALL_BREAKPOINTS_SAFE (b, temp) | |
10438 | { | |
7a697b8d | 10439 | if (tracepoint_type (b) |
059fb39f | 10440 | && b->number >= 0) |
1042e4c0 SS |
10441 | delete_breakpoint (b); |
10442 | } | |
10443 | } | |
10444 | } | |
10445 | else | |
95a42b64 | 10446 | map_breakpoint_numbers (arg, do_delete_breakpoint, NULL); |
1042e4c0 SS |
10447 | } |
10448 | ||
10449 | /* Set passcount for tracepoint. | |
10450 | ||
10451 | First command argument is passcount, second is tracepoint number. | |
10452 | If tracepoint number omitted, apply to most recently defined. | |
10453 | Also accepts special argument "all". */ | |
10454 | ||
10455 | static void | |
10456 | trace_pass_command (char *args, int from_tty) | |
10457 | { | |
10458 | struct breakpoint *t1 = (struct breakpoint *) -1, *t2; | |
10459 | unsigned int count; | |
10460 | int all = 0; | |
10461 | ||
10462 | if (args == 0 || *args == 0) | |
10463 | error (_("passcount command requires an argument (count + optional TP num)")); | |
10464 | ||
10465 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ | |
10466 | ||
10467 | while (*args && isspace ((int) *args)) | |
10468 | args++; | |
10469 | ||
10470 | if (*args && strncasecmp (args, "all", 3) == 0) | |
10471 | { | |
10472 | args += 3; /* Skip special argument "all". */ | |
10473 | all = 1; | |
10474 | if (*args) | |
10475 | error (_("Junk at end of arguments.")); | |
10476 | } | |
10477 | else | |
10478 | t1 = get_tracepoint_by_number (&args, 1, 1); | |
10479 | ||
10480 | do | |
10481 | { | |
10482 | if (t1) | |
10483 | { | |
10484 | ALL_TRACEPOINTS (t2) | |
10485 | if (t1 == (struct breakpoint *) -1 || t1 == t2) | |
10486 | { | |
10487 | t2->pass_count = count; | |
10488 | observer_notify_tracepoint_modified (t2->number); | |
10489 | if (from_tty) | |
10490 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
10491 | t2->number, count); | |
10492 | } | |
10493 | if (! all && *args) | |
10494 | t1 = get_tracepoint_by_number (&args, 1, 0); | |
10495 | } | |
10496 | } | |
10497 | while (*args); | |
10498 | } | |
10499 | ||
10500 | struct breakpoint * | |
10501 | get_tracepoint (int num) | |
10502 | { | |
10503 | struct breakpoint *t; | |
10504 | ||
10505 | ALL_TRACEPOINTS (t) | |
10506 | if (t->number == num) | |
10507 | return t; | |
10508 | ||
10509 | return NULL; | |
10510 | } | |
10511 | ||
d5551862 SS |
10512 | /* Find the tracepoint with the given target-side number (which may be |
10513 | different from the tracepoint number after disconnecting and | |
10514 | reconnecting). */ | |
10515 | ||
10516 | struct breakpoint * | |
10517 | get_tracepoint_by_number_on_target (int num) | |
10518 | { | |
10519 | struct breakpoint *t; | |
10520 | ||
10521 | ALL_TRACEPOINTS (t) | |
10522 | if (t->number_on_target == num) | |
10523 | return t; | |
10524 | ||
10525 | return NULL; | |
10526 | } | |
10527 | ||
1042e4c0 SS |
10528 | /* Utility: parse a tracepoint number and look it up in the list. |
10529 | If MULTI_P is true, there might be a range of tracepoints in ARG. | |
10530 | if OPTIONAL_P is true, then if the argument is missing, the most | |
10531 | recent tracepoint (tracepoint_count) is returned. */ | |
10532 | struct breakpoint * | |
10533 | get_tracepoint_by_number (char **arg, int multi_p, int optional_p) | |
10534 | { | |
10535 | extern int tracepoint_count; | |
10536 | struct breakpoint *t; | |
10537 | int tpnum; | |
10538 | char *instring = arg == NULL ? NULL : *arg; | |
10539 | ||
10540 | if (arg == NULL || *arg == NULL || ! **arg) | |
10541 | { | |
10542 | if (optional_p) | |
10543 | tpnum = tracepoint_count; | |
10544 | else | |
10545 | error_no_arg (_("tracepoint number")); | |
10546 | } | |
10547 | else | |
10548 | tpnum = multi_p ? get_number_or_range (arg) : get_number (arg); | |
10549 | ||
10550 | if (tpnum <= 0) | |
10551 | { | |
10552 | if (instring && *instring) | |
10553 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
10554 | instring); | |
10555 | else | |
10556 | printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n")); | |
10557 | return NULL; | |
10558 | } | |
10559 | ||
10560 | ALL_TRACEPOINTS (t) | |
10561 | if (t->number == tpnum) | |
10562 | { | |
10563 | return t; | |
10564 | } | |
10565 | ||
10566 | /* FIXME: if we are in the middle of a range we don't want to give | |
10567 | a message. The current interface to get_number_or_range doesn't | |
10568 | allow us to discover this. */ | |
10569 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); | |
10570 | return NULL; | |
10571 | } | |
10572 | ||
10573 | /* save-tracepoints command */ | |
10574 | static void | |
10575 | tracepoint_save_command (char *args, int from_tty) | |
10576 | { | |
10577 | struct breakpoint *tp; | |
10578 | int any_tp = 0; | |
a7bdde9e VP |
10579 | struct command_line *line; |
10580 | char *pathname; | |
1042e4c0 SS |
10581 | char tmp[40]; |
10582 | struct cleanup *cleanup; | |
a7bdde9e | 10583 | struct ui_file *fp; |
1042e4c0 SS |
10584 | |
10585 | if (args == 0 || *args == 0) | |
10586 | error (_("Argument required (file name in which to save tracepoints)")); | |
10587 | ||
10588 | /* See if we have anything to save. */ | |
10589 | ALL_TRACEPOINTS (tp) | |
10590 | { | |
10591 | any_tp = 1; | |
10592 | break; | |
10593 | } | |
10594 | if (!any_tp) | |
10595 | { | |
10596 | warning (_("save-tracepoints: no tracepoints to save.")); | |
10597 | return; | |
10598 | } | |
10599 | ||
10600 | pathname = tilde_expand (args); | |
10601 | cleanup = make_cleanup (xfree, pathname); | |
a7bdde9e | 10602 | fp = gdb_fopen (pathname, "w"); |
059fb39f | 10603 | if (!fp) |
1042e4c0 SS |
10604 | error (_("Unable to open file '%s' for saving tracepoints (%s)"), |
10605 | args, safe_strerror (errno)); | |
a7bdde9e | 10606 | make_cleanup_ui_file_delete (fp); |
1042e4c0 SS |
10607 | |
10608 | ALL_TRACEPOINTS (tp) | |
10609 | { | |
10610 | if (tp->addr_string) | |
a7bdde9e | 10611 | fprintf_unfiltered (fp, "trace %s\n", tp->addr_string); |
1042e4c0 SS |
10612 | else |
10613 | { | |
10614 | sprintf_vma (tmp, tp->loc->address); | |
a7bdde9e | 10615 | fprintf_unfiltered (fp, "trace *0x%s\n", tmp); |
1042e4c0 SS |
10616 | } |
10617 | ||
10618 | if (tp->pass_count) | |
a7bdde9e | 10619 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); |
1042e4c0 | 10620 | |
a7bdde9e | 10621 | if (tp->commands) |
1042e4c0 | 10622 | { |
a7bdde9e VP |
10623 | volatile struct gdb_exception ex; |
10624 | ||
10625 | fprintf_unfiltered (fp, " actions\n"); | |
10626 | ||
10627 | ui_out_redirect (uiout, fp); | |
10628 | TRY_CATCH (ex, RETURN_MASK_ERROR) | |
1042e4c0 | 10629 | { |
9add0f1b | 10630 | print_command_lines (uiout, tp->commands->commands, 2); |
a7bdde9e VP |
10631 | } |
10632 | ui_out_redirect (uiout, NULL); | |
1042e4c0 | 10633 | |
a7bdde9e VP |
10634 | if (ex.reason < 0) |
10635 | throw_exception (ex); | |
1042e4c0 | 10636 | |
a7bdde9e | 10637 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 SS |
10638 | } |
10639 | } | |
10640 | do_cleanups (cleanup); | |
10641 | if (from_tty) | |
10642 | printf_filtered (_("Tracepoints saved to file '%s'.\n"), args); | |
10643 | return; | |
10644 | } | |
10645 | ||
10646 | /* Create a vector of all tracepoints. */ | |
10647 | ||
10648 | VEC(breakpoint_p) * | |
10649 | all_tracepoints () | |
10650 | { | |
10651 | VEC(breakpoint_p) *tp_vec = 0; | |
10652 | struct breakpoint *tp; | |
10653 | ||
10654 | ALL_TRACEPOINTS (tp) | |
10655 | { | |
10656 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
10657 | } | |
10658 | ||
10659 | return tp_vec; | |
10660 | } | |
10661 | ||
c906108c | 10662 | \f |
31e2b00f AS |
10663 | /* This help string is used for the break, hbreak, tbreak and thbreak commands. |
10664 | It is defined as a macro to prevent duplication. | |
10665 | COMMAND should be a string constant containing the name of the command. */ | |
10666 | #define BREAK_ARGS_HELP(command) \ | |
10667 | command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\ | |
10668 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ | |
10669 | If a line number is specified, break at start of code for that line.\n\ | |
10670 | If a function is specified, break at start of code for that function.\n\ | |
10671 | If an address is specified, break at that exact address.\n\ | |
10672 | With no LOCATION, uses current execution address of selected stack frame.\n\ | |
10673 | This is useful for breaking on return to a stack frame.\n\ | |
10674 | \n\ | |
10675 | THREADNUM is the number from \"info threads\".\n\ | |
10676 | CONDITION is a boolean expression.\n\ | |
10677 | \n\ | |
10678 | Multiple breakpoints at one place are permitted, and useful if conditional.\n\ | |
10679 | \n\ | |
10680 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
10681 | ||
44feb3ce TT |
10682 | /* List of subcommands for "catch". */ |
10683 | static struct cmd_list_element *catch_cmdlist; | |
10684 | ||
10685 | /* List of subcommands for "tcatch". */ | |
10686 | static struct cmd_list_element *tcatch_cmdlist; | |
10687 | ||
10688 | /* Like add_cmd, but add the command to both the "catch" and "tcatch" | |
10689 | lists, and pass some additional user data to the command function. */ | |
10690 | static void | |
10691 | add_catch_command (char *name, char *docstring, | |
10692 | void (*sfunc) (char *args, int from_tty, | |
10693 | struct cmd_list_element *command), | |
a96d9b2e SDJ |
10694 | char **(*completer) (struct cmd_list_element *cmd, |
10695 | char *text, char *word), | |
44feb3ce TT |
10696 | void *user_data_catch, |
10697 | void *user_data_tcatch) | |
10698 | { | |
10699 | struct cmd_list_element *command; | |
10700 | ||
10701 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
10702 | &catch_cmdlist); | |
10703 | set_cmd_sfunc (command, sfunc); | |
10704 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 10705 | set_cmd_completer (command, completer); |
44feb3ce TT |
10706 | |
10707 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
10708 | &tcatch_cmdlist); | |
10709 | set_cmd_sfunc (command, sfunc); | |
10710 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 10711 | set_cmd_completer (command, completer); |
44feb3ce TT |
10712 | } |
10713 | ||
6c95b8df | 10714 | static void |
a79b8f6e | 10715 | clear_syscall_counts (struct inferior *inf) |
6c95b8df | 10716 | { |
6c95b8df PA |
10717 | inf->total_syscalls_count = 0; |
10718 | inf->any_syscall_count = 0; | |
10719 | VEC_free (int, inf->syscalls_counts); | |
10720 | } | |
10721 | ||
c906108c | 10722 | void |
fba45db2 | 10723 | _initialize_breakpoint (void) |
c906108c | 10724 | { |
fa8d40ab JJ |
10725 | static struct cmd_list_element *breakpoint_set_cmdlist; |
10726 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
c906108c SS |
10727 | struct cmd_list_element *c; |
10728 | ||
84acb35a | 10729 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
6c95b8df | 10730 | observer_attach_inferior_exit (clear_syscall_counts); |
1f3b5d1b | 10731 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 10732 | |
c906108c SS |
10733 | breakpoint_chain = 0; |
10734 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
10735 | before a breakpoint is set. */ | |
10736 | breakpoint_count = 0; | |
10737 | ||
1042e4c0 SS |
10738 | tracepoint_count = 0; |
10739 | ||
1bedd215 AC |
10740 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
10741 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
10742 | Usage is `ignore N COUNT'.")); | |
c906108c | 10743 | if (xdb_commands) |
c5aa993b | 10744 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 10745 | |
1bedd215 AC |
10746 | add_com ("commands", class_breakpoint, commands_command, _("\ |
10747 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
10748 | Give breakpoint number as argument after \"commands\".\n\ |
10749 | With no argument, the targeted breakpoint is the last one set.\n\ | |
10750 | The commands themselves follow starting on the next line.\n\ | |
10751 | Type a line containing \"end\" to indicate the end of them.\n\ | |
10752 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 10753 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 10754 | |
1bedd215 AC |
10755 | add_com ("condition", class_breakpoint, condition_command, _("\ |
10756 | Specify breakpoint number N to break only if COND is true.\n\ | |
c906108c | 10757 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 10758 | expression to be evaluated whenever breakpoint N is reached.")); |
c906108c | 10759 | |
1bedd215 | 10760 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 10761 | Set a temporary breakpoint.\n\ |
c906108c SS |
10762 | Like \"break\" except the breakpoint is only temporary,\n\ |
10763 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
10764 | by using \"enable delete\" on the breakpoint number.\n\ |
10765 | \n" | |
10766 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 10767 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 10768 | |
1bedd215 | 10769 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
31e2b00f | 10770 | Set a hardware assisted breakpoint.\n\ |
c906108c | 10771 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
10772 | some target hardware may not have this support.\n\ |
10773 | \n" | |
10774 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 10775 | set_cmd_completer (c, location_completer); |
c906108c | 10776 | |
1bedd215 | 10777 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 10778 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 10779 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
10780 | so it will be deleted when hit.\n\ |
10781 | \n" | |
10782 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 10783 | set_cmd_completer (c, location_completer); |
c906108c | 10784 | |
1bedd215 AC |
10785 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
10786 | Enable some breakpoints.\n\ | |
c906108c SS |
10787 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
10788 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
10789 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 10790 | With a subcommand you can enable temporarily."), |
c906108c SS |
10791 | &enablelist, "enable ", 1, &cmdlist); |
10792 | if (xdb_commands) | |
1bedd215 AC |
10793 | add_com ("ab", class_breakpoint, enable_command, _("\ |
10794 | Enable some breakpoints.\n\ | |
c906108c SS |
10795 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
10796 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
10797 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 10798 | With a subcommand you can enable temporarily.")); |
c906108c SS |
10799 | |
10800 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
10801 | ||
1bedd215 AC |
10802 | add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
10803 | Enable some breakpoints.\n\ | |
c906108c SS |
10804 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
10805 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 10806 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 10807 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 10808 | |
1a966eab AC |
10809 | add_cmd ("once", no_class, enable_once_command, _("\ |
10810 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
10811 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
10812 | &enablebreaklist); |
10813 | ||
1a966eab AC |
10814 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
10815 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
10816 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
10817 | &enablebreaklist); |
10818 | ||
1a966eab AC |
10819 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
10820 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
10821 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
10822 | &enablelist); |
10823 | ||
1a966eab AC |
10824 | add_cmd ("once", no_class, enable_once_command, _("\ |
10825 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
10826 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
10827 | &enablelist); |
10828 | ||
1bedd215 AC |
10829 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
10830 | Disable some breakpoints.\n\ | |
c906108c SS |
10831 | Arguments are breakpoint numbers with spaces in between.\n\ |
10832 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 10833 | A disabled breakpoint is not forgotten, but has no effect until reenabled."), |
c906108c SS |
10834 | &disablelist, "disable ", 1, &cmdlist); |
10835 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
10836 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
10837 | if (xdb_commands) | |
1bedd215 AC |
10838 | add_com ("sb", class_breakpoint, disable_command, _("\ |
10839 | Disable some breakpoints.\n\ | |
c906108c SS |
10840 | Arguments are breakpoint numbers with spaces in between.\n\ |
10841 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 10842 | A disabled breakpoint is not forgotten, but has no effect until reenabled.")); |
c906108c | 10843 | |
1a966eab AC |
10844 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
10845 | Disable some breakpoints.\n\ | |
c906108c SS |
10846 | Arguments are breakpoint numbers with spaces in between.\n\ |
10847 | To disable all breakpoints, give no argument.\n\ | |
10848 | A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\ | |
1a966eab | 10849 | This command may be abbreviated \"disable\"."), |
c906108c SS |
10850 | &disablelist); |
10851 | ||
1bedd215 AC |
10852 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
10853 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
10854 | Arguments are breakpoint numbers with spaces in between.\n\ |
10855 | To delete all breakpoints, give no argument.\n\ | |
10856 | \n\ | |
10857 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 10858 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
10859 | &deletelist, "delete ", 1, &cmdlist); |
10860 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 10861 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 10862 | if (xdb_commands) |
1bedd215 AC |
10863 | add_com ("db", class_breakpoint, delete_command, _("\ |
10864 | Delete some breakpoints.\n\ | |
c906108c | 10865 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 10866 | To delete all breakpoints, give no argument.\n")); |
c906108c | 10867 | |
1a966eab AC |
10868 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
10869 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
10870 | Arguments are breakpoint numbers with spaces in between.\n\ |
10871 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 10872 | This command may be abbreviated \"delete\"."), |
c906108c SS |
10873 | &deletelist); |
10874 | ||
1bedd215 AC |
10875 | add_com ("clear", class_breakpoint, clear_command, _("\ |
10876 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
10877 | Argument may be line number, function name, or \"*\" and an address.\n\ |
10878 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
10879 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
10880 | If an address is specified, breakpoints at that address are cleared.\n\ |
10881 | \n\ | |
10882 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
10883 | is executing in.\n\ |
10884 | \n\ | |
1bedd215 | 10885 | See also the \"delete\" command which clears breakpoints by number.")); |
c906108c | 10886 | |
1bedd215 | 10887 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
10888 | Set breakpoint at specified line or function.\n" |
10889 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 10890 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 10891 | |
c906108c SS |
10892 | add_com_alias ("b", "break", class_run, 1); |
10893 | add_com_alias ("br", "break", class_run, 1); | |
10894 | add_com_alias ("bre", "break", class_run, 1); | |
10895 | add_com_alias ("brea", "break", class_run, 1); | |
10896 | ||
7681d515 PM |
10897 | if (xdb_commands) |
10898 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
10899 | |
10900 | if (dbx_commands) | |
10901 | { | |
1bedd215 AC |
10902 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
10903 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
10904 | &stoplist, "stop ", 1, &cmdlist); |
10905 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 10906 | _("Break in function or address."), &stoplist); |
c5aa993b | 10907 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 10908 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
10909 | add_com ("status", class_info, breakpoints_info, _("\ |
10910 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
10911 | The \"Type\" column indicates one of:\n\ |
10912 | \tbreakpoint - normal breakpoint\n\ | |
10913 | \twatchpoint - watchpoint\n\ | |
10914 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
10915 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
10916 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
10917 | address and file/line number respectively.\n\ |
10918 | \n\ | |
10919 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
10920 | are set to the address of the last breakpoint listed unless the command\n\ |
10921 | is prefixed with \"server \".\n\n\ | |
c906108c | 10922 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 10923 | breakpoint set.")); |
c906108c SS |
10924 | } |
10925 | ||
1bedd215 AC |
10926 | add_info ("breakpoints", breakpoints_info, _("\ |
10927 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
10928 | The \"Type\" column indicates one of:\n\ |
10929 | \tbreakpoint - normal breakpoint\n\ | |
10930 | \twatchpoint - watchpoint\n\ | |
10931 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
10932 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
10933 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
10934 | address and file/line number respectively.\n\ |
10935 | \n\ | |
10936 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
10937 | are set to the address of the last breakpoint listed unless the command\n\ |
10938 | is prefixed with \"server \".\n\n\ | |
c906108c | 10939 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 10940 | breakpoint set.")); |
c906108c | 10941 | |
6b04bdb7 MS |
10942 | add_info_alias ("b", "breakpoints", 1); |
10943 | ||
c906108c | 10944 | if (xdb_commands) |
1bedd215 AC |
10945 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
10946 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
10947 | The \"Type\" column indicates one of:\n\ |
10948 | \tbreakpoint - normal breakpoint\n\ | |
10949 | \twatchpoint - watchpoint\n\ | |
10950 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
10951 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
10952 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
10953 | address and file/line number respectively.\n\ |
10954 | \n\ | |
10955 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
10956 | are set to the address of the last breakpoint listed unless the command\n\ |
10957 | is prefixed with \"server \".\n\n\ | |
c906108c | 10958 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 10959 | breakpoint set.")); |
c906108c | 10960 | |
1a966eab AC |
10961 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
10962 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
10963 | The \"Type\" column indicates one of:\n\ |
10964 | \tbreakpoint - normal breakpoint\n\ | |
10965 | \twatchpoint - watchpoint\n\ | |
10966 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
10967 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
10968 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
10969 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
10970 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
10971 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
10972 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
10973 | address and file/line number respectively.\n\ |
10974 | \n\ | |
10975 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
10976 | are set to the address of the last breakpoint listed unless the command\n\ |
10977 | is prefixed with \"server \".\n\n\ | |
c906108c | 10978 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 10979 | breakpoint set."), |
c906108c SS |
10980 | &maintenanceinfolist); |
10981 | ||
44feb3ce TT |
10982 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
10983 | Set catchpoints to catch events."), | |
10984 | &catch_cmdlist, "catch ", | |
10985 | 0/*allow-unknown*/, &cmdlist); | |
10986 | ||
10987 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
10988 | Set temporary catchpoints to catch events."), | |
10989 | &tcatch_cmdlist, "tcatch ", | |
10990 | 0/*allow-unknown*/, &cmdlist); | |
10991 | ||
10992 | /* Add catch and tcatch sub-commands. */ | |
10993 | add_catch_command ("catch", _("\ | |
10994 | Catch an exception, when caught.\n\ | |
10995 | With an argument, catch only exceptions with the given name."), | |
10996 | catch_catch_command, | |
a96d9b2e | 10997 | NULL, |
44feb3ce TT |
10998 | CATCH_PERMANENT, |
10999 | CATCH_TEMPORARY); | |
11000 | add_catch_command ("throw", _("\ | |
11001 | Catch an exception, when thrown.\n\ | |
11002 | With an argument, catch only exceptions with the given name."), | |
11003 | catch_throw_command, | |
a96d9b2e | 11004 | NULL, |
44feb3ce TT |
11005 | CATCH_PERMANENT, |
11006 | CATCH_TEMPORARY); | |
11007 | add_catch_command ("fork", _("Catch calls to fork."), | |
11008 | catch_fork_command_1, | |
a96d9b2e | 11009 | NULL, |
44feb3ce TT |
11010 | (void *) (uintptr_t) catch_fork_permanent, |
11011 | (void *) (uintptr_t) catch_fork_temporary); | |
11012 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
11013 | catch_fork_command_1, | |
a96d9b2e | 11014 | NULL, |
44feb3ce TT |
11015 | (void *) (uintptr_t) catch_vfork_permanent, |
11016 | (void *) (uintptr_t) catch_vfork_temporary); | |
11017 | add_catch_command ("exec", _("Catch calls to exec."), | |
11018 | catch_exec_command_1, | |
a96d9b2e SDJ |
11019 | NULL, |
11020 | CATCH_PERMANENT, | |
11021 | CATCH_TEMPORARY); | |
11022 | add_catch_command ("syscall", _("\ | |
11023 | Catch system calls by their names and/or numbers.\n\ | |
11024 | Arguments say which system calls to catch. If no arguments\n\ | |
11025 | are given, every system call will be caught.\n\ | |
11026 | Arguments, if given, should be one or more system call names\n\ | |
11027 | (if your system supports that), or system call numbers."), | |
11028 | catch_syscall_command_1, | |
11029 | catch_syscall_completer, | |
44feb3ce TT |
11030 | CATCH_PERMANENT, |
11031 | CATCH_TEMPORARY); | |
44feb3ce TT |
11032 | add_catch_command ("exception", _("\ |
11033 | Catch Ada exceptions, when raised.\n\ | |
11034 | With an argument, catch only exceptions with the given name."), | |
11035 | catch_ada_exception_command, | |
a96d9b2e | 11036 | NULL, |
44feb3ce TT |
11037 | CATCH_PERMANENT, |
11038 | CATCH_TEMPORARY); | |
11039 | add_catch_command ("assert", _("\ | |
11040 | Catch failed Ada assertions, when raised.\n\ | |
11041 | With an argument, catch only exceptions with the given name."), | |
11042 | catch_assert_command, | |
a96d9b2e | 11043 | NULL, |
44feb3ce TT |
11044 | CATCH_PERMANENT, |
11045 | CATCH_TEMPORARY); | |
c5aa993b | 11046 | |
1bedd215 AC |
11047 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
11048 | Set a watchpoint for an expression.\n\ | |
c906108c | 11049 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 11050 | an expression changes.")); |
65d12d83 | 11051 | set_cmd_completer (c, expression_completer); |
c906108c | 11052 | |
1bedd215 AC |
11053 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
11054 | Set a read watchpoint for an expression.\n\ | |
c906108c | 11055 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 11056 | an expression is read.")); |
65d12d83 | 11057 | set_cmd_completer (c, expression_completer); |
c906108c | 11058 | |
1bedd215 AC |
11059 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
11060 | Set a watchpoint for an expression.\n\ | |
c906108c | 11061 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 11062 | an expression is either read or written.")); |
65d12d83 | 11063 | set_cmd_completer (c, expression_completer); |
c906108c SS |
11064 | |
11065 | add_info ("watchpoints", breakpoints_info, | |
1bedd215 | 11066 | _("Synonym for ``info breakpoints''.")); |
c906108c SS |
11067 | |
11068 | ||
920d2a44 AC |
11069 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
11070 | respond to changes - contrary to the description. */ | |
85c07804 AC |
11071 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
11072 | &can_use_hw_watchpoints, _("\ | |
11073 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
11074 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
11075 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
11076 | such is available. (However, any hardware watchpoints that were\n\ | |
11077 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
11078 | hardware.)"), |
11079 | NULL, | |
920d2a44 | 11080 | show_can_use_hw_watchpoints, |
85c07804 | 11081 | &setlist, &showlist); |
c906108c SS |
11082 | |
11083 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 11084 | |
1042e4c0 SS |
11085 | /* Tracepoint manipulation commands. */ |
11086 | ||
11087 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
11088 | Set a tracepoint at specified line or function.\n\ | |
11089 | \n" | |
11090 | BREAK_ARGS_HELP ("trace") "\n\ | |
11091 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
11092 | set_cmd_completer (c, location_completer); | |
11093 | ||
11094 | add_com_alias ("tp", "trace", class_alias, 0); | |
11095 | add_com_alias ("tr", "trace", class_alias, 1); | |
11096 | add_com_alias ("tra", "trace", class_alias, 1); | |
11097 | add_com_alias ("trac", "trace", class_alias, 1); | |
11098 | ||
7a697b8d SS |
11099 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
11100 | Set a fast tracepoint at specified line or function.\n\ | |
11101 | \n" | |
11102 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
11103 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
11104 | set_cmd_completer (c, location_completer); | |
11105 | ||
1042e4c0 SS |
11106 | add_info ("tracepoints", tracepoints_info, _("\ |
11107 | Status of tracepoints, or tracepoint number NUMBER.\n\ | |
11108 | Convenience variable \"$tpnum\" contains the number of the\n\ | |
11109 | last tracepoint set.")); | |
11110 | ||
11111 | add_info_alias ("tp", "tracepoints", 1); | |
11112 | ||
11113 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
11114 | Delete specified tracepoints.\n\ | |
11115 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
11116 | No argument means delete all tracepoints."), | |
11117 | &deletelist); | |
11118 | ||
11119 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
11120 | Disable specified tracepoints.\n\ | |
11121 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
11122 | No argument means disable all tracepoints."), | |
11123 | &disablelist); | |
11124 | deprecate_cmd (c, "disable"); | |
11125 | ||
11126 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
11127 | Enable specified tracepoints.\n\ | |
11128 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
11129 | No argument means enable all tracepoints."), | |
11130 | &enablelist); | |
11131 | deprecate_cmd (c, "enable"); | |
11132 | ||
11133 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
11134 | Set the passcount for a tracepoint.\n\ | |
11135 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
11136 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
11137 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
11138 | ||
11139 | c = add_com ("save-tracepoints", class_trace, tracepoint_save_command, _("\ | |
11140 | Save current tracepoint definitions as a script.\n\ | |
11141 | Use the 'source' command in another debug session to restore them.")); | |
11142 | set_cmd_completer (c, filename_completer); | |
11143 | ||
1bedd215 | 11144 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
11145 | Breakpoint specific settings\n\ |
11146 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 11147 | pending breakpoint behavior"), |
fa8d40ab JJ |
11148 | &breakpoint_set_cmdlist, "set breakpoint ", |
11149 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 11150 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
11151 | Breakpoint specific settings\n\ |
11152 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 11153 | pending breakpoint behavior"), |
fa8d40ab JJ |
11154 | &breakpoint_show_cmdlist, "show breakpoint ", |
11155 | 0/*allow-unknown*/, &showlist); | |
11156 | ||
7915a72c AC |
11157 | add_setshow_auto_boolean_cmd ("pending", no_class, |
11158 | &pending_break_support, _("\ | |
11159 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
11160 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
11161 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
11162 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
11163 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 11164 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 11165 | NULL, |
920d2a44 | 11166 | show_pending_break_support, |
6e1d7d6c AC |
11167 | &breakpoint_set_cmdlist, |
11168 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
11169 | |
11170 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
11171 | |
11172 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
11173 | &automatic_hardware_breakpoints, _("\ | |
11174 | Set automatic usage of hardware breakpoints."), _("\ | |
11175 | Show automatic usage of hardware breakpoints."), _("\ | |
11176 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
11177 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
11178 | a warning will be emitted for such breakpoints."), | |
11179 | NULL, | |
11180 | show_automatic_hardware_breakpoints, | |
11181 | &breakpoint_set_cmdlist, | |
11182 | &breakpoint_show_cmdlist); | |
74960c60 | 11183 | |
33e5cbd6 PA |
11184 | add_setshow_enum_cmd ("always-inserted", class_support, |
11185 | always_inserted_enums, &always_inserted_mode, _("\ | |
74960c60 VP |
11186 | Set mode for inserting breakpoints."), _("\ |
11187 | Show mode for inserting breakpoints."), _("\ | |
33e5cbd6 PA |
11188 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
11189 | resumed, and removed when execution stops. When this mode is on,\n\ | |
11190 | breakpoints are inserted immediately and removed only when the user\n\ | |
11191 | deletes the breakpoint. When this mode is auto (which is the default),\n\ | |
11192 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ | |
11193 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ | |
11194 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ | |
11195 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), | |
74960c60 VP |
11196 | NULL, |
11197 | &show_always_inserted_mode, | |
11198 | &breakpoint_set_cmdlist, | |
11199 | &breakpoint_show_cmdlist); | |
765dc015 VP |
11200 | |
11201 | automatic_hardware_breakpoints = 1; | |
f3b1572e PA |
11202 | |
11203 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
c906108c | 11204 | } |