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); | |
95a42b64 | 962 | } |
9766ced4 SS |
963 | else |
964 | /* The command loop has some static state, so we need to preserve | |
965 | our argument. */ | |
966 | arg = xstrdup (arg); | |
967 | make_cleanup (xfree, arg); | |
95a42b64 TT |
968 | |
969 | map_breakpoint_numbers (arg, do_map_commands_command, &info); | |
970 | ||
971 | if (info.cmd == NULL) | |
972 | error (_("No breakpoints specified.")); | |
973 | ||
974 | do_cleanups (cleanups); | |
975 | } | |
976 | ||
977 | static void | |
978 | commands_command (char *arg, int from_tty) | |
979 | { | |
980 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 981 | } |
40c03ae8 EZ |
982 | |
983 | /* Like commands_command, but instead of reading the commands from | |
984 | input stream, takes them from an already parsed command structure. | |
985 | ||
986 | This is used by cli-script.c to DTRT with breakpoint commands | |
987 | that are part of if and while bodies. */ | |
988 | enum command_control_type | |
989 | commands_from_control_command (char *arg, struct command_line *cmd) | |
990 | { | |
95a42b64 TT |
991 | commands_command_1 (arg, 0, cmd); |
992 | return simple_control; | |
40c03ae8 | 993 | } |
876fa593 JK |
994 | |
995 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
996 | ||
997 | static int | |
998 | bp_location_has_shadow (struct bp_location *bl) | |
999 | { | |
1000 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1001 | return 0; | |
1002 | if (!bl->inserted) | |
1003 | return 0; | |
1004 | if (bl->target_info.shadow_len == 0) | |
1005 | /* bp isn't valid, or doesn't shadow memory. */ | |
1006 | return 0; | |
1007 | return 1; | |
1008 | } | |
1009 | ||
8defab1a | 1010 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1011 | by replacing any memory breakpoints with their shadowed contents. |
1012 | ||
1013 | The range of shadowed area by each bp_location is: | |
1014 | b->address - bp_location_placed_address_before_address_max | |
1015 | up to b->address + bp_location_shadow_len_after_address_max | |
1016 | The range we were requested to resolve shadows for is: | |
1017 | memaddr ... memaddr + len | |
1018 | Thus the safe cutoff boundaries for performance optimization are | |
1019 | memaddr + len <= b->address - bp_location_placed_address_before_address_max | |
1020 | and: | |
1021 | b->address + bp_location_shadow_len_after_address_max <= memaddr */ | |
c906108c | 1022 | |
8defab1a DJ |
1023 | void |
1024 | breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len) | |
c906108c | 1025 | { |
876fa593 JK |
1026 | /* Left boundary, right boundary and median element of our binary search. */ |
1027 | unsigned bc_l, bc_r, bc; | |
1028 | ||
1029 | /* Find BC_L which is a leftmost element which may affect BUF content. It is | |
1030 | safe to report lower value but a failure to report higher one. */ | |
1031 | ||
1032 | bc_l = 0; | |
1033 | bc_r = bp_location_count; | |
1034 | while (bc_l + 1 < bc_r) | |
1035 | { | |
1036 | struct bp_location *b; | |
1037 | ||
1038 | bc = (bc_l + bc_r) / 2; | |
1039 | b = bp_location[bc]; | |
1040 | ||
1041 | /* Check first B->ADDRESS will not overflow due to the added constant. | |
1042 | Then advance the left boundary only if we are sure the BC element can | |
1043 | in no way affect the BUF content (MEMADDR to MEMADDR + LEN range). | |
1044 | ||
1045 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety offset so that | |
1046 | we cannot miss a breakpoint with its shadow range tail still reaching | |
1047 | MEMADDR. */ | |
c5aa993b | 1048 | |
876fa593 JK |
1049 | if (b->address + bp_location_shadow_len_after_address_max >= b->address |
1050 | && b->address + bp_location_shadow_len_after_address_max <= memaddr) | |
1051 | bc_l = bc; | |
1052 | else | |
1053 | bc_r = bc; | |
1054 | } | |
1055 | ||
1056 | /* Now do full processing of the found relevant range of elements. */ | |
1057 | ||
1058 | for (bc = bc_l; bc < bp_location_count; bc++) | |
c5aa993b | 1059 | { |
876fa593 JK |
1060 | struct bp_location *b = bp_location[bc]; |
1061 | CORE_ADDR bp_addr = 0; | |
1062 | int bp_size = 0; | |
1063 | int bptoffset = 0; | |
1064 | ||
ffce0d52 | 1065 | if (b->owner->type == bp_none) |
8a3fe4f8 | 1066 | warning (_("reading through apparently deleted breakpoint #%d?"), |
ffce0d52 DJ |
1067 | b->owner->number); |
1068 | ||
876fa593 JK |
1069 | /* Performance optimization: any futher element can no longer affect BUF |
1070 | content. */ | |
1071 | ||
1072 | if (b->address >= bp_location_placed_address_before_address_max | |
1073 | && memaddr + len <= b->address | |
1074 | - bp_location_placed_address_before_address_max) | |
1075 | break; | |
1076 | ||
1077 | if (!bp_location_has_shadow (b)) | |
c5aa993b | 1078 | continue; |
6c95b8df PA |
1079 | if (!breakpoint_address_match (b->target_info.placed_address_space, 0, |
1080 | current_program_space->aspace, 0)) | |
1081 | continue; | |
1082 | ||
c5aa993b JM |
1083 | /* Addresses and length of the part of the breakpoint that |
1084 | we need to copy. */ | |
8181d85f DJ |
1085 | bp_addr = b->target_info.placed_address; |
1086 | bp_size = b->target_info.shadow_len; | |
8defab1a | 1087 | |
c5aa993b JM |
1088 | if (bp_addr + bp_size <= memaddr) |
1089 | /* The breakpoint is entirely before the chunk of memory we | |
1090 | are reading. */ | |
1091 | continue; | |
8defab1a | 1092 | |
c5aa993b JM |
1093 | if (bp_addr >= memaddr + len) |
1094 | /* The breakpoint is entirely after the chunk of memory we are | |
1095 | reading. */ | |
1096 | continue; | |
c5aa993b | 1097 | |
8defab1a DJ |
1098 | /* Offset within shadow_contents. */ |
1099 | if (bp_addr < memaddr) | |
1100 | { | |
1101 | /* Only copy the second part of the breakpoint. */ | |
1102 | bp_size -= memaddr - bp_addr; | |
1103 | bptoffset = memaddr - bp_addr; | |
1104 | bp_addr = memaddr; | |
1105 | } | |
c5aa993b | 1106 | |
8defab1a DJ |
1107 | if (bp_addr + bp_size > memaddr + len) |
1108 | { | |
1109 | /* Only copy the first part of the breakpoint. */ | |
1110 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1111 | } | |
c5aa993b | 1112 | |
8defab1a DJ |
1113 | memcpy (buf + bp_addr - memaddr, |
1114 | b->target_info.shadow_contents + bptoffset, bp_size); | |
c5aa993b | 1115 | } |
c906108c | 1116 | } |
c906108c | 1117 | \f |
c5aa993b | 1118 | |
687595f9 | 1119 | /* A wrapper function for inserting catchpoints. */ |
9cbc821d | 1120 | static void |
687595f9 DJ |
1121 | insert_catchpoint (struct ui_out *uo, void *args) |
1122 | { | |
1123 | struct breakpoint *b = (struct breakpoint *) args; | |
1124 | int val = -1; | |
1125 | ||
fe798b75 JB |
1126 | gdb_assert (b->type == bp_catchpoint); |
1127 | gdb_assert (b->ops != NULL && b->ops->insert != NULL); | |
1128 | ||
1129 | b->ops->insert (b); | |
687595f9 DJ |
1130 | } |
1131 | ||
60e1c644 PA |
1132 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1133 | ||
a5606eee VP |
1134 | static int |
1135 | is_hardware_watchpoint (struct breakpoint *bpt) | |
1136 | { | |
1137 | return (bpt->type == bp_hardware_watchpoint | |
1138 | || bpt->type == bp_read_watchpoint | |
1139 | || bpt->type == bp_access_watchpoint); | |
1140 | } | |
7270d8f2 | 1141 | |
60e1c644 PA |
1142 | /* Return true if BPT is of any watchpoint kind, hardware or |
1143 | software. */ | |
1144 | ||
1145 | static int | |
1146 | is_watchpoint (struct breakpoint *bpt) | |
1147 | { | |
1148 | return (is_hardware_watchpoint (bpt) | |
1149 | || bpt->type == bp_watchpoint); | |
1150 | } | |
1151 | ||
fa4727a6 DJ |
1152 | /* Find the current value of a watchpoint on EXP. Return the value in |
1153 | *VALP and *RESULTP and the chain of intermediate and final values | |
1154 | in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does | |
1155 | not need them. | |
1156 | ||
ccc57cf9 | 1157 | If a memory error occurs while evaluating the expression, *RESULTP will |
fa4727a6 DJ |
1158 | be set to NULL. *RESULTP may be a lazy value, if the result could |
1159 | not be read from memory. It is used to determine whether a value | |
1160 | is user-specified (we should watch the whole value) or intermediate | |
1161 | (we should watch only the bit used to locate the final value). | |
1162 | ||
1163 | If the final value, or any intermediate value, could not be read | |
1164 | from memory, *VALP will be set to NULL. *VAL_CHAIN will still be | |
1165 | set to any referenced values. *VALP will never be a lazy value. | |
1166 | This is the value which we store in struct breakpoint. | |
1167 | ||
1168 | If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the | |
1169 | value chain. The caller must free the values individually. If | |
1170 | VAL_CHAIN is NULL, all generated values will be left on the value | |
1171 | chain. */ | |
1172 | ||
1173 | static void | |
1174 | fetch_watchpoint_value (struct expression *exp, struct value **valp, | |
1175 | struct value **resultp, struct value **val_chain) | |
1176 | { | |
1177 | struct value *mark, *new_mark, *result; | |
ccc57cf9 | 1178 | volatile struct gdb_exception ex; |
fa4727a6 DJ |
1179 | |
1180 | *valp = NULL; | |
1181 | if (resultp) | |
1182 | *resultp = NULL; | |
1183 | if (val_chain) | |
1184 | *val_chain = NULL; | |
1185 | ||
1186 | /* Evaluate the expression. */ | |
1187 | mark = value_mark (); | |
1188 | result = NULL; | |
ccc57cf9 PA |
1189 | |
1190 | TRY_CATCH (ex, RETURN_MASK_ALL) | |
1191 | { | |
1192 | result = evaluate_expression (exp); | |
1193 | } | |
1194 | if (ex.reason < 0) | |
1195 | { | |
1196 | /* Ignore memory errors, we want watchpoints pointing at | |
1197 | inaccessible memory to still be created; otherwise, throw the | |
1198 | error to some higher catcher. */ | |
1199 | switch (ex.error) | |
1200 | { | |
1201 | case MEMORY_ERROR: | |
1202 | break; | |
1203 | default: | |
1204 | throw_exception (ex); | |
1205 | break; | |
1206 | } | |
1207 | } | |
1208 | ||
fa4727a6 DJ |
1209 | new_mark = value_mark (); |
1210 | if (mark == new_mark) | |
1211 | return; | |
1212 | if (resultp) | |
1213 | *resultp = result; | |
1214 | ||
1215 | /* Make sure it's not lazy, so that after the target stops again we | |
1216 | have a non-lazy previous value to compare with. */ | |
1217 | if (result != NULL | |
1218 | && (!value_lazy (result) || gdb_value_fetch_lazy (result))) | |
1219 | *valp = result; | |
1220 | ||
1221 | if (val_chain) | |
1222 | { | |
1223 | /* Return the chain of intermediate values. We use this to | |
1224 | decide which addresses to watch. */ | |
1225 | *val_chain = new_mark; | |
1226 | value_release_to_mark (mark); | |
1227 | } | |
1228 | } | |
1229 | ||
f6bc2008 PA |
1230 | /* Assuming that B is a watchpoint: returns true if the current thread |
1231 | and its running state are safe to evaluate or update watchpoint B. | |
1232 | Watchpoints on local expressions need to be evaluated in the | |
1233 | context of the thread that was current when the watchpoint was | |
1234 | created, and, that thread needs to be stopped to be able to select | |
1235 | the correct frame context. Watchpoints on global expressions can | |
1236 | be evaluated on any thread, and in any state. It is presently left | |
1237 | to the target allowing memory accesses when threads are | |
1238 | running. */ | |
1239 | ||
1240 | static int | |
1241 | watchpoint_in_thread_scope (struct breakpoint *b) | |
1242 | { | |
1243 | return (ptid_equal (b->watchpoint_thread, null_ptid) | |
1244 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1245 | && !is_executing (inferior_ptid))); | |
1246 | } | |
1247 | ||
567e1b4e JB |
1248 | /* Assuming that B is a watchpoint: |
1249 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1250 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1251 | - Evaluate the condition if there is one, and store the result |
1252 | in b->loc->cond. | |
a5606eee VP |
1253 | - Update the list of values that must be watched in B->loc. |
1254 | ||
bfa149ac | 1255 | If the watchpoint disposition is disp_del_at_next_stop, then do nothing. |
a79d3c27 JK |
1256 | If this is local watchpoint that is out of scope, delete it. |
1257 | ||
1258 | Even with `set breakpoint always-inserted on' the watchpoints are removed | |
1259 | + inserted on each stop here. Normal breakpoints must never be removed | |
1260 | because they might be missed by a running thread when debugging in non-stop | |
1261 | mode. On the other hand, hardware watchpoints (is_hardware_watchpoint; | |
1262 | processed here) are specific to each LWP since they are stored in each LWP's | |
1263 | hardware debug registers. Therefore, such LWP must be stopped first in | |
1264 | order to be able to modify its hardware watchpoints. | |
1265 | ||
1266 | Hardware watchpoints must be reset exactly once after being presented to the | |
1267 | user. It cannot be done sooner, because it would reset the data used to | |
1268 | present the watchpoint hit to the user. And it must not be done later | |
1269 | because it could display the same single watchpoint hit during multiple GDB | |
1270 | stops. Note that the latter is relevant only to the hardware watchpoint | |
1271 | types bp_read_watchpoint and bp_access_watchpoint. False hit by | |
1272 | bp_hardware_watchpoint is not user-visible - its hit is suppressed if the | |
1273 | memory content has not changed. | |
1274 | ||
1275 | The following constraints influence the location where we can reset hardware | |
1276 | watchpoints: | |
1277 | ||
1278 | * target_stopped_by_watchpoint and target_stopped_data_address are called | |
1279 | several times when GDB stops. | |
1280 | ||
1281 | [linux] | |
1282 | * Multiple hardware watchpoints can be hit at the same time, causing GDB to | |
1283 | stop. GDB only presents one hardware watchpoint hit at a time as the | |
1284 | reason for stopping, and all the other hits are presented later, one after | |
1285 | the other, each time the user requests the execution to be resumed. | |
1286 | Execution is not resumed for the threads still having pending hit event | |
1287 | stored in LWP_INFO->STATUS. While the watchpoint is already removed from | |
1288 | the inferior on the first stop the thread hit event is kept being reported | |
1289 | from its cached value by linux_nat_stopped_data_address until the real | |
1290 | thread resume happens after the watchpoint gets presented and thus its | |
1291 | LWP_INFO->STATUS gets reset. | |
1292 | ||
1293 | Therefore the hardware watchpoint hit can get safely reset on the watchpoint | |
1294 | removal from inferior. */ | |
1295 | ||
b40ce68a | 1296 | static void |
a5606eee | 1297 | update_watchpoint (struct breakpoint *b, int reparse) |
7270d8f2 | 1298 | { |
a5606eee | 1299 | int within_current_scope; |
a5606eee VP |
1300 | struct frame_id saved_frame_id; |
1301 | struct bp_location *loc; | |
66076460 | 1302 | int frame_saved; |
a5606eee VP |
1303 | bpstat bs; |
1304 | ||
f6bc2008 PA |
1305 | /* If this is a local watchpoint, we only want to check if the |
1306 | watchpoint frame is in scope if the current thread is the thread | |
1307 | that was used to create the watchpoint. */ | |
1308 | if (!watchpoint_in_thread_scope (b)) | |
1309 | return; | |
1310 | ||
876fa593 | 1311 | /* We don't free locations. They are stored in bp_location array and |
567e1b4e JB |
1312 | update_global_locations will eventually delete them and remove |
1313 | breakpoints if needed. */ | |
a5606eee VP |
1314 | b->loc = NULL; |
1315 | ||
1316 | if (b->disposition == disp_del_at_next_stop) | |
1317 | return; | |
1318 | ||
66076460 | 1319 | frame_saved = 0; |
a5606eee VP |
1320 | |
1321 | /* Determine if the watchpoint is within scope. */ | |
1322 | if (b->exp_valid_block == NULL) | |
1323 | within_current_scope = 1; | |
1324 | else | |
1325 | { | |
1326 | struct frame_info *fi; | |
66076460 DJ |
1327 | |
1328 | /* Save the current frame's ID so we can restore it after | |
1329 | evaluating the watchpoint expression on its own frame. */ | |
1330 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1331 | took a frame parameter, so that we didn't have to change the | |
1332 | selected frame. */ | |
1333 | frame_saved = 1; | |
1334 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1335 | ||
a5606eee VP |
1336 | fi = frame_find_by_id (b->watchpoint_frame); |
1337 | within_current_scope = (fi != NULL); | |
1338 | if (within_current_scope) | |
1339 | select_frame (fi); | |
1340 | } | |
1341 | ||
1342 | if (within_current_scope && reparse) | |
1343 | { | |
1344 | char *s; | |
1345 | if (b->exp) | |
1346 | { | |
1347 | xfree (b->exp); | |
1348 | b->exp = NULL; | |
1349 | } | |
1350 | s = b->exp_string; | |
1351 | b->exp = parse_exp_1 (&s, b->exp_valid_block, 0); | |
1352 | /* If the meaning of expression itself changed, the old value is | |
1353 | no longer relevant. We don't want to report a watchpoint hit | |
1354 | to the user when the old value and the new value may actually | |
1355 | be completely different objects. */ | |
1356 | value_free (b->val); | |
fa4727a6 DJ |
1357 | b->val = NULL; |
1358 | b->val_valid = 0; | |
60e1c644 PA |
1359 | |
1360 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1361 | expression is stored in the breakpoint object, not in the | |
1362 | locations (re)created below. */ | |
1363 | if (b->cond_string != NULL) | |
1364 | { | |
1365 | if (b->cond_exp != NULL) | |
1366 | { | |
1367 | xfree (b->cond_exp); | |
1368 | b->cond_exp = NULL; | |
1369 | } | |
1370 | ||
1371 | s = b->cond_string; | |
1372 | b->cond_exp = parse_exp_1 (&s, b->cond_exp_valid_block, 0); | |
1373 | } | |
a5606eee | 1374 | } |
a5606eee VP |
1375 | |
1376 | /* If we failed to parse the expression, for example because | |
1377 | it refers to a global variable in a not-yet-loaded shared library, | |
1378 | don't try to insert watchpoint. We don't automatically delete | |
1379 | such watchpoint, though, since failure to parse expression | |
1380 | is different from out-of-scope watchpoint. */ | |
2d134ed3 PA |
1381 | if ( !target_has_execution) |
1382 | { | |
1383 | /* Without execution, memory can't change. No use to try and | |
1384 | set watchpoint locations. The watchpoint will be reset when | |
1385 | the target gains execution, through breakpoint_re_set. */ | |
1386 | } | |
1387 | else if (within_current_scope && b->exp) | |
a5606eee | 1388 | { |
fa4727a6 | 1389 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1390 | struct program_space *frame_pspace; |
a5606eee | 1391 | |
fa4727a6 | 1392 | fetch_watchpoint_value (b->exp, &v, &result, &val_chain); |
a5606eee | 1393 | |
a5606eee VP |
1394 | /* Avoid setting b->val if it's already set. The meaning of |
1395 | b->val is 'the last value' user saw, and we should update | |
1396 | it only if we reported that last value to user. As it | |
1397 | happens, the code that reports it updates b->val directly. */ | |
fa4727a6 DJ |
1398 | if (!b->val_valid) |
1399 | { | |
1400 | b->val = v; | |
1401 | b->val_valid = 1; | |
1402 | } | |
a5606eee | 1403 | |
db2ad4c3 JK |
1404 | /* Change the type of breakpoint between hardware assisted or an |
1405 | ordinary watchpoint depending on the hardware support and free | |
1406 | hardware slots. REPARSE is set when the inferior is started. */ | |
1407 | if ((b->type == bp_watchpoint || b->type == bp_hardware_watchpoint) | |
1408 | && reparse) | |
1409 | { | |
ca2d49e8 | 1410 | int i, mem_cnt, other_type_used; |
db2ad4c3 | 1411 | |
7b838ca2 TJB |
1412 | /* We need to determine how many resources are already used |
1413 | for all other hardware watchpoints to see if we still have | |
1414 | enough resources to also fit this watchpoint in as well. | |
1415 | To avoid the hw_watchpoint_used_count call below from counting | |
1416 | this watchpoint, make sure that it is marked as a software | |
1417 | watchpoint. */ | |
1418 | b->type = bp_watchpoint; | |
db2ad4c3 JK |
1419 | i = hw_watchpoint_used_count (bp_hardware_watchpoint, |
1420 | &other_type_used); | |
1421 | mem_cnt = can_use_hardware_watchpoint (val_chain); | |
1422 | ||
ca2d49e8 | 1423 | if (!mem_cnt) |
db2ad4c3 JK |
1424 | b->type = bp_watchpoint; |
1425 | else | |
ca2d49e8 | 1426 | { |
d92524f1 | 1427 | int target_resources_ok = target_can_use_hardware_watchpoint |
ca2d49e8 SL |
1428 | (bp_hardware_watchpoint, i + mem_cnt, other_type_used); |
1429 | if (target_resources_ok <= 0) | |
1430 | b->type = bp_watchpoint; | |
1431 | else | |
1432 | b->type = bp_hardware_watchpoint; | |
1433 | } | |
db2ad4c3 JK |
1434 | } |
1435 | ||
2d134ed3 PA |
1436 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1437 | ||
a5606eee | 1438 | /* Look at each value on the value chain. */ |
fa4727a6 | 1439 | for (v = val_chain; v; v = next) |
a5606eee VP |
1440 | { |
1441 | /* If it's a memory location, and GDB actually needed | |
1442 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1443 | must watch it. If the first value returned is |
1444 | still lazy, that means an error occurred reading it; | |
1445 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1446 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1447 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1448 | { |
1449 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1450 | |
a5606eee VP |
1451 | /* We only watch structs and arrays if user asked |
1452 | for it explicitly, never if they just happen to | |
1453 | appear in the middle of some value chain. */ | |
fa4727a6 | 1454 | if (v == result |
a5606eee VP |
1455 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1456 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1457 | { | |
1458 | CORE_ADDR addr; | |
1459 | int len, type; | |
1460 | struct bp_location *loc, **tmp; | |
1461 | ||
42ae5230 | 1462 | addr = value_address (v); |
a5606eee VP |
1463 | len = TYPE_LENGTH (value_type (v)); |
1464 | type = hw_write; | |
1465 | if (b->type == bp_read_watchpoint) | |
1466 | type = hw_read; | |
1467 | else if (b->type == bp_access_watchpoint) | |
1468 | type = hw_access; | |
1469 | ||
39d61571 | 1470 | loc = allocate_bp_location (b); |
a5606eee VP |
1471 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
1472 | ; | |
1473 | *tmp = loc; | |
a6d9a66e | 1474 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1475 | |
1476 | loc->pspace = frame_pspace; | |
a5606eee VP |
1477 | loc->address = addr; |
1478 | loc->length = len; | |
1479 | loc->watchpoint_type = type; | |
1480 | } | |
1481 | } | |
1482 | ||
1483 | next = value_next (v); | |
1484 | if (v != b->val) | |
1485 | value_free (v); | |
1486 | } | |
1487 | ||
c7437ca6 PA |
1488 | /* If a software watchpoint is not watching any memory, then the |
1489 | above left it without any location set up. But, | |
1490 | bpstat_stop_status requires a location to be able to report | |
1491 | stops, so make sure there's at least a dummy one. */ | |
1492 | if (b->type == bp_watchpoint && b->loc == NULL) | |
1493 | { | |
1494 | b->loc = allocate_bp_location (b); | |
1495 | b->loc->pspace = frame_pspace; | |
1496 | b->loc->address = -1; | |
1497 | b->loc->length = -1; | |
1498 | b->loc->watchpoint_type = -1; | |
1499 | } | |
a5606eee VP |
1500 | } |
1501 | else if (!within_current_scope) | |
7270d8f2 | 1502 | { |
a5606eee | 1503 | printf_filtered (_("\ |
567e1b4e | 1504 | Watchpoint %d deleted because the program has left the block \n\ |
a5606eee VP |
1505 | in which its expression is valid.\n"), |
1506 | b->number); | |
1507 | if (b->related_breakpoint) | |
60e1c644 PA |
1508 | { |
1509 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1510 | b->related_breakpoint->related_breakpoint = NULL; | |
1511 | b->related_breakpoint= NULL; | |
1512 | } | |
a5606eee | 1513 | b->disposition = disp_del_at_next_stop; |
7270d8f2 | 1514 | } |
a5606eee VP |
1515 | |
1516 | /* Restore the selected frame. */ | |
66076460 DJ |
1517 | if (frame_saved) |
1518 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
1519 | } |
1520 | ||
a5606eee | 1521 | |
74960c60 VP |
1522 | /* Returns 1 iff breakpoint location should be |
1523 | inserted in the inferior. */ | |
1524 | static int | |
1525 | should_be_inserted (struct bp_location *bpt) | |
1526 | { | |
1527 | if (!breakpoint_enabled (bpt->owner)) | |
1528 | return 0; | |
1529 | ||
1530 | if (bpt->owner->disposition == disp_del_at_next_stop) | |
1531 | return 0; | |
1532 | ||
1533 | if (!bpt->enabled || bpt->shlib_disabled || bpt->duplicate) | |
1534 | return 0; | |
1535 | ||
56710373 PA |
1536 | /* This is set for example, when we're attached to the parent of a |
1537 | vfork, and have detached from the child. The child is running | |
1538 | free, and we expect it to do an exec or exit, at which point the | |
1539 | OS makes the parent schedulable again (and the target reports | |
1540 | that the vfork is done). Until the child is done with the shared | |
1541 | memory region, do not insert breakpoints in the parent, otherwise | |
1542 | the child could still trip on the parent's breakpoints. Since | |
1543 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
1544 | if (bpt->pspace->breakpoints_not_allowed) | |
1545 | return 0; | |
1546 | ||
1042e4c0 SS |
1547 | /* Tracepoints are inserted by the target at a time of its choosing, |
1548 | not by us. */ | |
7a697b8d | 1549 | if (tracepoint_type (bpt->owner)) |
1042e4c0 SS |
1550 | return 0; |
1551 | ||
74960c60 VP |
1552 | return 1; |
1553 | } | |
1554 | ||
879bfdc2 DJ |
1555 | /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint. |
1556 | Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS, | |
fa3a767f | 1557 | and HW_BREAKPOINT_ERROR are used to report problems. |
879bfdc2 DJ |
1558 | |
1559 | NOTE drow/2003-09-09: This routine could be broken down to an object-style | |
1560 | method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 1561 | static int |
879bfdc2 | 1562 | insert_bp_location (struct bp_location *bpt, |
26bb91f3 | 1563 | struct ui_file *tmp_error_stream, |
fa3a767f | 1564 | int *disabled_breaks, |
26bb91f3 | 1565 | int *hw_breakpoint_error) |
879bfdc2 DJ |
1566 | { |
1567 | int val = 0; | |
1568 | ||
74960c60 | 1569 | if (!should_be_inserted (bpt) || bpt->inserted) |
879bfdc2 DJ |
1570 | return 0; |
1571 | ||
8181d85f DJ |
1572 | /* Initialize the target-specific information. */ |
1573 | memset (&bpt->target_info, 0, sizeof (bpt->target_info)); | |
1574 | bpt->target_info.placed_address = bpt->address; | |
6c95b8df | 1575 | bpt->target_info.placed_address_space = bpt->pspace->aspace; |
8181d85f | 1576 | |
879bfdc2 DJ |
1577 | if (bpt->loc_type == bp_loc_software_breakpoint |
1578 | || bpt->loc_type == bp_loc_hardware_breakpoint) | |
1579 | { | |
765dc015 VP |
1580 | if (bpt->owner->type != bp_hardware_breakpoint) |
1581 | { | |
1582 | /* If the explicitly specified breakpoint type | |
1583 | is not hardware breakpoint, check the memory map to see | |
1584 | if the breakpoint address is in read only memory or not. | |
1585 | Two important cases are: | |
1586 | - location type is not hardware breakpoint, memory | |
1587 | is readonly. We change the type of the location to | |
1588 | hardware breakpoint. | |
1589 | - location type is hardware breakpoint, memory is read-write. | |
1590 | This means we've previously made the location hardware one, but | |
1591 | then the memory map changed, so we undo. | |
1592 | ||
1593 | When breakpoints are removed, remove_breakpoints will | |
1594 | use location types we've just set here, the only possible | |
1595 | problem is that memory map has changed during running program, | |
1596 | but it's not going to work anyway with current gdb. */ | |
1597 | struct mem_region *mr | |
1598 | = lookup_mem_region (bpt->target_info.placed_address); | |
1599 | ||
1600 | if (mr) | |
1601 | { | |
1602 | if (automatic_hardware_breakpoints) | |
1603 | { | |
1604 | int changed = 0; | |
1605 | enum bp_loc_type new_type; | |
1606 | ||
1607 | if (mr->attrib.mode != MEM_RW) | |
1608 | new_type = bp_loc_hardware_breakpoint; | |
1609 | else | |
1610 | new_type = bp_loc_software_breakpoint; | |
1611 | ||
1612 | if (new_type != bpt->loc_type) | |
1613 | { | |
1614 | static int said = 0; | |
1615 | bpt->loc_type = new_type; | |
1616 | if (!said) | |
1617 | { | |
1618 | fprintf_filtered (gdb_stdout, _("\ | |
0767c96d | 1619 | Note: automatically using hardware breakpoints for read-only addresses.\n")); |
765dc015 VP |
1620 | said = 1; |
1621 | } | |
1622 | } | |
1623 | } | |
1624 | else if (bpt->loc_type == bp_loc_software_breakpoint | |
1625 | && mr->attrib.mode != MEM_RW) | |
1626 | warning (_("cannot set software breakpoint at readonly address %s"), | |
5af949e3 | 1627 | paddress (bpt->gdbarch, bpt->address)); |
765dc015 VP |
1628 | } |
1629 | } | |
1630 | ||
879bfdc2 DJ |
1631 | /* First check to see if we have to handle an overlay. */ |
1632 | if (overlay_debugging == ovly_off | |
1633 | || bpt->section == NULL | |
1634 | || !(section_is_overlay (bpt->section))) | |
1635 | { | |
1636 | /* No overlay handling: just set the breakpoint. */ | |
1637 | ||
1638 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
a6d9a66e UW |
1639 | val = target_insert_hw_breakpoint (bpt->gdbarch, |
1640 | &bpt->target_info); | |
879bfdc2 | 1641 | else |
a6d9a66e UW |
1642 | val = target_insert_breakpoint (bpt->gdbarch, |
1643 | &bpt->target_info); | |
879bfdc2 DJ |
1644 | } |
1645 | else | |
1646 | { | |
1647 | /* This breakpoint is in an overlay section. | |
1648 | Shall we set a breakpoint at the LMA? */ | |
1649 | if (!overlay_events_enabled) | |
1650 | { | |
1651 | /* Yes -- overlay event support is not active, | |
1652 | so we must try to set a breakpoint at the LMA. | |
1653 | This will not work for a hardware breakpoint. */ | |
1654 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
8a3fe4f8 | 1655 | warning (_("hardware breakpoint %d not supported in overlay!"), |
879bfdc2 DJ |
1656 | bpt->owner->number); |
1657 | else | |
1658 | { | |
1659 | CORE_ADDR addr = overlay_unmapped_address (bpt->address, | |
1660 | bpt->section); | |
1661 | /* Set a software (trap) breakpoint at the LMA. */ | |
8181d85f DJ |
1662 | bpt->overlay_target_info = bpt->target_info; |
1663 | bpt->overlay_target_info.placed_address = addr; | |
a6d9a66e UW |
1664 | val = target_insert_breakpoint (bpt->gdbarch, |
1665 | &bpt->overlay_target_info); | |
879bfdc2 | 1666 | if (val != 0) |
99361f52 DE |
1667 | fprintf_unfiltered (tmp_error_stream, |
1668 | "Overlay breakpoint %d failed: in ROM?\n", | |
879bfdc2 DJ |
1669 | bpt->owner->number); |
1670 | } | |
1671 | } | |
1672 | /* Shall we set a breakpoint at the VMA? */ | |
1673 | if (section_is_mapped (bpt->section)) | |
1674 | { | |
1675 | /* Yes. This overlay section is mapped into memory. */ | |
1676 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
a6d9a66e UW |
1677 | val = target_insert_hw_breakpoint (bpt->gdbarch, |
1678 | &bpt->target_info); | |
879bfdc2 | 1679 | else |
a6d9a66e UW |
1680 | val = target_insert_breakpoint (bpt->gdbarch, |
1681 | &bpt->target_info); | |
879bfdc2 DJ |
1682 | } |
1683 | else | |
1684 | { | |
1685 | /* No. This breakpoint will not be inserted. | |
1686 | No error, but do not mark the bp as 'inserted'. */ | |
1687 | return 0; | |
1688 | } | |
1689 | } | |
1690 | ||
1691 | if (val) | |
1692 | { | |
1693 | /* Can't set the breakpoint. */ | |
6c95b8df | 1694 | if (solib_name_from_address (bpt->pspace, bpt->address)) |
879bfdc2 DJ |
1695 | { |
1696 | /* See also: disable_breakpoints_in_shlibs. */ | |
1697 | val = 0; | |
0d381245 | 1698 | bpt->shlib_disabled = 1; |
879bfdc2 DJ |
1699 | if (!*disabled_breaks) |
1700 | { | |
1701 | fprintf_unfiltered (tmp_error_stream, | |
1702 | "Cannot insert breakpoint %d.\n", | |
1703 | bpt->owner->number); | |
1704 | fprintf_unfiltered (tmp_error_stream, | |
1705 | "Temporarily disabling shared library breakpoints:\n"); | |
1706 | } | |
1707 | *disabled_breaks = 1; | |
1708 | fprintf_unfiltered (tmp_error_stream, | |
1709 | "breakpoint #%d\n", bpt->owner->number); | |
1710 | } | |
1711 | else | |
879bfdc2 | 1712 | { |
879bfdc2 DJ |
1713 | if (bpt->loc_type == bp_loc_hardware_breakpoint) |
1714 | { | |
1715 | *hw_breakpoint_error = 1; | |
1716 | fprintf_unfiltered (tmp_error_stream, | |
1717 | "Cannot insert hardware breakpoint %d.\n", | |
1718 | bpt->owner->number); | |
1719 | } | |
1720 | else | |
1721 | { | |
1722 | fprintf_unfiltered (tmp_error_stream, | |
1723 | "Cannot insert breakpoint %d.\n", | |
1724 | bpt->owner->number); | |
1725 | fprintf_filtered (tmp_error_stream, | |
1726 | "Error accessing memory address "); | |
5af949e3 UW |
1727 | fputs_filtered (paddress (bpt->gdbarch, bpt->address), |
1728 | tmp_error_stream); | |
879bfdc2 DJ |
1729 | fprintf_filtered (tmp_error_stream, ": %s.\n", |
1730 | safe_strerror (val)); | |
1731 | } | |
1732 | ||
1733 | } | |
1734 | } | |
1735 | else | |
1736 | bpt->inserted = 1; | |
1737 | ||
1738 | return val; | |
1739 | } | |
1740 | ||
1741 | else if (bpt->loc_type == bp_loc_hardware_watchpoint | |
1742 | /* NOTE drow/2003-09-08: This state only exists for removing | |
1743 | watchpoints. It's not clear that it's necessary... */ | |
1744 | && bpt->owner->disposition != disp_del_at_next_stop) | |
1745 | { | |
85d721b8 | 1746 | val = target_insert_watchpoint (bpt->address, |
a5606eee VP |
1747 | bpt->length, |
1748 | bpt->watchpoint_type); | |
85d721b8 PA |
1749 | |
1750 | /* If trying to set a read-watchpoint, and it turns out it's not | |
1751 | supported, try emulating one with an access watchpoint. */ | |
1752 | if (val == 1 && bpt->watchpoint_type == hw_read) | |
1753 | { | |
1754 | struct bp_location *loc, **loc_temp; | |
1755 | ||
1756 | /* But don't try to insert it, if there's already another | |
1757 | hw_access location that would be considered a duplicate | |
1758 | of this one. */ | |
1759 | ALL_BP_LOCATIONS (loc, loc_temp) | |
1760 | if (loc != bpt | |
1761 | && loc->watchpoint_type == hw_access | |
1762 | && watchpoint_locations_match (bpt, loc)) | |
1763 | { | |
1764 | bpt->duplicate = 1; | |
1765 | bpt->inserted = 1; | |
1766 | bpt->target_info = loc->target_info; | |
1767 | bpt->watchpoint_type = hw_access; | |
1768 | val = 0; | |
1769 | break; | |
1770 | } | |
1771 | ||
1772 | if (val == 1) | |
1773 | { | |
1774 | val = target_insert_watchpoint (bpt->address, | |
1775 | bpt->length, | |
1776 | hw_access); | |
1777 | if (val == 0) | |
1778 | bpt->watchpoint_type = hw_access; | |
1779 | } | |
1780 | } | |
1781 | ||
1782 | bpt->inserted = (val == 0); | |
879bfdc2 DJ |
1783 | } |
1784 | ||
fe798b75 | 1785 | else if (bpt->owner->type == bp_catchpoint) |
879bfdc2 | 1786 | { |
71fff37b AC |
1787 | struct gdb_exception e = catch_exception (uiout, insert_catchpoint, |
1788 | bpt->owner, RETURN_MASK_ERROR); | |
9cbc821d AC |
1789 | exception_fprintf (gdb_stderr, e, "warning: inserting catchpoint %d: ", |
1790 | bpt->owner->number); | |
1791 | if (e.reason < 0) | |
879bfdc2 DJ |
1792 | bpt->owner->enable_state = bp_disabled; |
1793 | else | |
1794 | bpt->inserted = 1; | |
1640b821 DJ |
1795 | |
1796 | /* We've already printed an error message if there was a problem | |
1797 | inserting this catchpoint, and we've disabled the catchpoint, | |
1798 | so just return success. */ | |
1799 | return 0; | |
879bfdc2 DJ |
1800 | } |
1801 | ||
1802 | return 0; | |
1803 | } | |
1804 | ||
6c95b8df PA |
1805 | /* This function is called when program space PSPACE is about to be |
1806 | deleted. It takes care of updating breakpoints to not reference | |
1807 | PSPACE anymore. */ | |
1808 | ||
1809 | void | |
1810 | breakpoint_program_space_exit (struct program_space *pspace) | |
1811 | { | |
1812 | struct breakpoint *b, *b_temp; | |
876fa593 | 1813 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
1814 | |
1815 | /* Remove any breakpoint that was set through this program space. */ | |
1816 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
1817 | { | |
1818 | if (b->pspace == pspace) | |
1819 | delete_breakpoint (b); | |
1820 | } | |
1821 | ||
1822 | /* Breakpoints set through other program spaces could have locations | |
1823 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 1824 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
1825 | { |
1826 | struct bp_location *tmp; | |
1827 | ||
1828 | if (loc->pspace == pspace) | |
1829 | { | |
1830 | if (loc->owner->loc == loc) | |
1831 | loc->owner->loc = loc->next; | |
1832 | else | |
1833 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
1834 | if (tmp->next == loc) | |
1835 | { | |
1836 | tmp->next = loc->next; | |
1837 | break; | |
1838 | } | |
1839 | } | |
1840 | } | |
1841 | ||
1842 | /* Now update the global location list to permanently delete the | |
1843 | removed locations above. */ | |
1844 | update_global_location_list (0); | |
1845 | } | |
1846 | ||
74960c60 VP |
1847 | /* Make sure all breakpoints are inserted in inferior. |
1848 | Throws exception on any error. | |
1849 | A breakpoint that is already inserted won't be inserted | |
1850 | again, so calling this function twice is safe. */ | |
1851 | void | |
1852 | insert_breakpoints (void) | |
1853 | { | |
1854 | struct breakpoint *bpt; | |
1855 | ||
1856 | ALL_BREAKPOINTS (bpt) | |
1857 | if (is_hardware_watchpoint (bpt)) | |
1858 | update_watchpoint (bpt, 0 /* don't reparse. */); | |
1859 | ||
b60e7edf | 1860 | update_global_location_list (1); |
74960c60 | 1861 | |
c35b1492 PA |
1862 | /* update_global_location_list does not insert breakpoints when |
1863 | always_inserted_mode is not enabled. Explicitly insert them | |
1864 | now. */ | |
1865 | if (!breakpoints_always_inserted_mode ()) | |
74960c60 VP |
1866 | insert_breakpoint_locations (); |
1867 | } | |
1868 | ||
c906108c SS |
1869 | /* insert_breakpoints is used when starting or continuing the program. |
1870 | remove_breakpoints is used when the program stops. | |
1871 | Both return zero if successful, | |
1872 | or an `errno' value if could not write the inferior. */ | |
1873 | ||
74960c60 VP |
1874 | static void |
1875 | insert_breakpoint_locations (void) | |
c906108c | 1876 | { |
a5606eee | 1877 | struct breakpoint *bpt; |
876fa593 | 1878 | struct bp_location *b, **bp_tmp; |
e236ba44 | 1879 | int error = 0; |
c906108c SS |
1880 | int val = 0; |
1881 | int disabled_breaks = 0; | |
81d0cc19 | 1882 | int hw_breakpoint_error = 0; |
c906108c | 1883 | |
81d0cc19 | 1884 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 1885 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 1886 | |
81d0cc19 GS |
1887 | /* Explicitly mark the warning -- this will only be printed if |
1888 | there was an error. */ | |
1889 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
1890 | |
1891 | save_current_space_and_thread (); | |
1892 | ||
876fa593 | 1893 | ALL_BP_LOCATIONS (b, bp_tmp) |
879bfdc2 | 1894 | { |
6c95b8df PA |
1895 | struct thread_info *tp; |
1896 | CORE_ADDR last_addr; | |
1897 | ||
74960c60 | 1898 | if (!should_be_inserted (b) || b->inserted) |
879bfdc2 DJ |
1899 | continue; |
1900 | ||
f365de73 AS |
1901 | /* There is no point inserting thread-specific breakpoints if the |
1902 | thread no longer exists. */ | |
1903 | if (b->owner->thread != -1 | |
1904 | && !valid_thread_id (b->owner->thread)) | |
1905 | continue; | |
1906 | ||
6c95b8df PA |
1907 | switch_to_program_space_and_thread (b->pspace); |
1908 | ||
1909 | /* For targets that support global breakpoints, there's no need | |
1910 | to select an inferior to insert breakpoint to. In fact, even | |
1911 | if we aren't attached to any process yet, we should still | |
1912 | insert breakpoints. */ | |
1913 | if (!gdbarch_has_global_breakpoints (target_gdbarch) | |
1914 | && ptid_equal (inferior_ptid, null_ptid)) | |
1915 | continue; | |
1916 | ||
879bfdc2 | 1917 | val = insert_bp_location (b, tmp_error_stream, |
fa3a767f | 1918 | &disabled_breaks, |
879bfdc2 DJ |
1919 | &hw_breakpoint_error); |
1920 | if (val) | |
e236ba44 | 1921 | error = val; |
879bfdc2 | 1922 | } |
c906108c | 1923 | |
a5606eee VP |
1924 | /* If we failed to insert all locations of a watchpoint, |
1925 | remove them, as half-inserted watchpoint is of limited use. */ | |
1926 | ALL_BREAKPOINTS (bpt) | |
1927 | { | |
1928 | int some_failed = 0; | |
1929 | struct bp_location *loc; | |
1930 | ||
1931 | if (!is_hardware_watchpoint (bpt)) | |
1932 | continue; | |
1933 | ||
d6b74ac4 | 1934 | if (!breakpoint_enabled (bpt)) |
a5606eee | 1935 | continue; |
74960c60 VP |
1936 | |
1937 | if (bpt->disposition == disp_del_at_next_stop) | |
1938 | continue; | |
a5606eee VP |
1939 | |
1940 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 1941 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
1942 | { |
1943 | some_failed = 1; | |
1944 | break; | |
1945 | } | |
1946 | if (some_failed) | |
1947 | { | |
1948 | for (loc = bpt->loc; loc; loc = loc->next) | |
1949 | if (loc->inserted) | |
1950 | remove_breakpoint (loc, mark_uninserted); | |
1951 | ||
1952 | hw_breakpoint_error = 1; | |
1953 | fprintf_unfiltered (tmp_error_stream, | |
1954 | "Could not insert hardware watchpoint %d.\n", | |
1955 | bpt->number); | |
1956 | error = -1; | |
1957 | } | |
1958 | } | |
1959 | ||
e236ba44 | 1960 | if (error) |
81d0cc19 GS |
1961 | { |
1962 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
1963 | message about possibly exhausted resources. */ | |
879bfdc2 | 1964 | if (hw_breakpoint_error) |
81d0cc19 | 1965 | { |
c6510018 MS |
1966 | fprintf_unfiltered (tmp_error_stream, |
1967 | "Could not insert hardware breakpoints:\n\ | |
1968 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 1969 | } |
81d0cc19 GS |
1970 | target_terminal_ours_for_output (); |
1971 | error_stream (tmp_error_stream); | |
1972 | } | |
f7545552 TT |
1973 | |
1974 | do_cleanups (cleanups); | |
c906108c SS |
1975 | } |
1976 | ||
c906108c | 1977 | int |
fba45db2 | 1978 | remove_breakpoints (void) |
c906108c | 1979 | { |
876fa593 | 1980 | struct bp_location *b, **bp_tmp; |
3a1bae8e | 1981 | int val = 0; |
c906108c | 1982 | |
876fa593 | 1983 | ALL_BP_LOCATIONS (b, bp_tmp) |
c5aa993b | 1984 | { |
0bde7532 | 1985 | if (b->inserted) |
3a1bae8e | 1986 | val |= remove_breakpoint (b, mark_uninserted); |
c5aa993b | 1987 | } |
3a1bae8e | 1988 | return val; |
c906108c SS |
1989 | } |
1990 | ||
6c95b8df PA |
1991 | /* Remove breakpoints of process PID. */ |
1992 | ||
1993 | int | |
1994 | remove_breakpoints_pid (int pid) | |
1995 | { | |
876fa593 | 1996 | struct bp_location *b, **b_tmp; |
6c95b8df PA |
1997 | int val; |
1998 | struct inferior *inf = find_inferior_pid (pid); | |
1999 | ||
876fa593 | 2000 | ALL_BP_LOCATIONS (b, b_tmp) |
6c95b8df PA |
2001 | { |
2002 | if (b->pspace != inf->pspace) | |
2003 | continue; | |
2004 | ||
2005 | if (b->inserted) | |
2006 | { | |
2007 | val = remove_breakpoint (b, mark_uninserted); | |
2008 | if (val != 0) | |
2009 | return val; | |
2010 | } | |
2011 | } | |
2012 | return 0; | |
2013 | } | |
2014 | ||
692590c1 | 2015 | int |
80ce1ecb | 2016 | remove_hw_watchpoints (void) |
692590c1 | 2017 | { |
876fa593 | 2018 | struct bp_location *b, **bp_tmp; |
3a1bae8e | 2019 | int val = 0; |
692590c1 | 2020 | |
876fa593 | 2021 | ALL_BP_LOCATIONS (b, bp_tmp) |
692590c1 | 2022 | { |
0bde7532 | 2023 | if (b->inserted && b->loc_type == bp_loc_hardware_watchpoint) |
3a1bae8e | 2024 | val |= remove_breakpoint (b, mark_uninserted); |
692590c1 | 2025 | } |
3a1bae8e | 2026 | return val; |
692590c1 MS |
2027 | } |
2028 | ||
c906108c | 2029 | int |
fba45db2 | 2030 | reattach_breakpoints (int pid) |
c906108c | 2031 | { |
6c95b8df | 2032 | struct cleanup *old_chain; |
876fa593 | 2033 | struct bp_location *b, **bp_tmp; |
c906108c | 2034 | int val; |
a4954f26 | 2035 | struct ui_file *tmp_error_stream = mem_fileopen (); |
fa3a767f | 2036 | int dummy1 = 0, dummy2 = 0; |
6c95b8df PA |
2037 | struct inferior *inf; |
2038 | struct thread_info *tp; | |
2039 | ||
2040 | tp = any_live_thread_of_process (pid); | |
2041 | if (tp == NULL) | |
2042 | return 1; | |
2043 | ||
2044 | inf = find_inferior_pid (pid); | |
2045 | old_chain = save_inferior_ptid (); | |
2046 | ||
2047 | inferior_ptid = tp->ptid; | |
a4954f26 DJ |
2048 | |
2049 | make_cleanup_ui_file_delete (tmp_error_stream); | |
c906108c | 2050 | |
876fa593 | 2051 | ALL_BP_LOCATIONS (b, bp_tmp) |
c5aa993b | 2052 | { |
6c95b8df PA |
2053 | if (b->pspace != inf->pspace) |
2054 | continue; | |
2055 | ||
0bde7532 | 2056 | if (b->inserted) |
c5aa993b | 2057 | { |
a4954f26 DJ |
2058 | b->inserted = 0; |
2059 | val = insert_bp_location (b, tmp_error_stream, | |
fa3a767f | 2060 | &dummy1, &dummy2); |
c5aa993b JM |
2061 | if (val != 0) |
2062 | { | |
ce696e05 | 2063 | do_cleanups (old_chain); |
c5aa993b JM |
2064 | return val; |
2065 | } | |
2066 | } | |
2067 | } | |
ce696e05 | 2068 | do_cleanups (old_chain); |
c906108c SS |
2069 | return 0; |
2070 | } | |
2071 | ||
e58b0e63 PA |
2072 | static int internal_breakpoint_number = -1; |
2073 | ||
e62c965a | 2074 | static struct breakpoint * |
a6d9a66e UW |
2075 | create_internal_breakpoint (struct gdbarch *gdbarch, |
2076 | CORE_ADDR address, enum bptype type) | |
e62c965a | 2077 | { |
e62c965a PP |
2078 | struct symtab_and_line sal; |
2079 | struct breakpoint *b; | |
2080 | ||
2081 | init_sal (&sal); /* initialize to zeroes */ | |
2082 | ||
2083 | sal.pc = address; | |
2084 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 2085 | sal.pspace = current_program_space; |
e62c965a | 2086 | |
a6d9a66e | 2087 | b = set_raw_breakpoint (gdbarch, sal, type); |
e62c965a PP |
2088 | b->number = internal_breakpoint_number--; |
2089 | b->disposition = disp_donttouch; | |
2090 | ||
2091 | return b; | |
2092 | } | |
2093 | ||
2094 | static void | |
69de3c6a | 2095 | create_overlay_event_breakpoint (char *func_name) |
e62c965a | 2096 | { |
69de3c6a | 2097 | struct objfile *objfile; |
e62c965a | 2098 | |
69de3c6a PP |
2099 | ALL_OBJFILES (objfile) |
2100 | { | |
2101 | struct breakpoint *b; | |
2102 | struct minimal_symbol *m; | |
2103 | ||
2104 | m = lookup_minimal_symbol_text (func_name, objfile); | |
2105 | if (m == NULL) | |
2106 | continue; | |
e62c965a | 2107 | |
a6d9a66e UW |
2108 | b = create_internal_breakpoint (get_objfile_arch (objfile), |
2109 | SYMBOL_VALUE_ADDRESS (m), | |
69de3c6a PP |
2110 | bp_overlay_event); |
2111 | b->addr_string = xstrdup (func_name); | |
e62c965a | 2112 | |
69de3c6a PP |
2113 | if (overlay_debugging == ovly_auto) |
2114 | { | |
2115 | b->enable_state = bp_enabled; | |
2116 | overlay_events_enabled = 1; | |
2117 | } | |
2118 | else | |
2119 | { | |
2120 | b->enable_state = bp_disabled; | |
2121 | overlay_events_enabled = 0; | |
2122 | } | |
e62c965a PP |
2123 | } |
2124 | update_global_location_list (1); | |
2125 | } | |
2126 | ||
0fd8e87f UW |
2127 | static void |
2128 | create_longjmp_master_breakpoint (char *func_name) | |
2129 | { | |
6c95b8df | 2130 | struct program_space *pspace; |
0fd8e87f | 2131 | struct objfile *objfile; |
6c95b8df PA |
2132 | struct cleanup *old_chain; |
2133 | ||
2134 | old_chain = save_current_program_space (); | |
0fd8e87f | 2135 | |
6c95b8df | 2136 | ALL_PSPACES (pspace) |
0fd8e87f UW |
2137 | ALL_OBJFILES (objfile) |
2138 | { | |
2139 | struct breakpoint *b; | |
2140 | struct minimal_symbol *m; | |
2141 | ||
2142 | if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile))) | |
2143 | continue; | |
2144 | ||
6c95b8df PA |
2145 | set_current_program_space (pspace); |
2146 | ||
0fd8e87f UW |
2147 | m = lookup_minimal_symbol_text (func_name, objfile); |
2148 | if (m == NULL) | |
2149 | continue; | |
2150 | ||
a6d9a66e UW |
2151 | b = create_internal_breakpoint (get_objfile_arch (objfile), |
2152 | SYMBOL_VALUE_ADDRESS (m), | |
0fd8e87f UW |
2153 | bp_longjmp_master); |
2154 | b->addr_string = xstrdup (func_name); | |
2155 | b->enable_state = bp_disabled; | |
2156 | } | |
2157 | update_global_location_list (1); | |
6c95b8df PA |
2158 | |
2159 | do_cleanups (old_chain); | |
0fd8e87f UW |
2160 | } |
2161 | ||
aa7d318d TT |
2162 | /* Create a master std::terminate breakpoint. The actual function |
2163 | looked for is named FUNC_NAME. */ | |
2164 | static void | |
2165 | create_std_terminate_master_breakpoint (const char *func_name) | |
2166 | { | |
2167 | struct program_space *pspace; | |
2168 | struct objfile *objfile; | |
2169 | struct cleanup *old_chain; | |
2170 | ||
2171 | old_chain = save_current_program_space (); | |
2172 | ||
2173 | ALL_PSPACES (pspace) | |
2174 | ALL_OBJFILES (objfile) | |
2175 | { | |
2176 | struct breakpoint *b; | |
2177 | struct minimal_symbol *m; | |
2178 | ||
2179 | set_current_program_space (pspace); | |
2180 | ||
2181 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
2182 | if (m == NULL || (MSYMBOL_TYPE (m) != mst_text | |
2183 | && MSYMBOL_TYPE (m) != mst_file_text)) | |
2184 | continue; | |
2185 | ||
2186 | b = create_internal_breakpoint (get_objfile_arch (objfile), | |
2187 | SYMBOL_VALUE_ADDRESS (m), | |
2188 | bp_std_terminate_master); | |
2189 | b->addr_string = xstrdup (func_name); | |
2190 | b->enable_state = bp_disabled; | |
2191 | } | |
2192 | update_global_location_list (1); | |
2193 | ||
2194 | do_cleanups (old_chain); | |
2195 | } | |
2196 | ||
c906108c | 2197 | void |
fba45db2 | 2198 | update_breakpoints_after_exec (void) |
c906108c | 2199 | { |
c5aa993b JM |
2200 | struct breakpoint *b; |
2201 | struct breakpoint *temp; | |
876fa593 | 2202 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 2203 | |
25b22b0a PA |
2204 | /* We're about to delete breakpoints from GDB's lists. If the |
2205 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
2206 | writing the breakpoints' "shadow contents" back into memory. The | |
2207 | "shadow contents" are NOT valid after an exec, so GDB should not | |
2208 | do that. Instead, the target is responsible from marking | |
2209 | breakpoints out as soon as it detects an exec. We don't do that | |
2210 | here instead, because there may be other attempts to delete | |
2211 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 2212 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
2213 | if (bploc->pspace == current_program_space) |
2214 | gdb_assert (!bploc->inserted); | |
c906108c SS |
2215 | |
2216 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b | 2217 | { |
6c95b8df PA |
2218 | if (b->pspace != current_program_space) |
2219 | continue; | |
2220 | ||
c5aa993b JM |
2221 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
2222 | if (b->type == bp_shlib_event) | |
2223 | { | |
2224 | delete_breakpoint (b); | |
2225 | continue; | |
2226 | } | |
c906108c | 2227 | |
4efc6507 DE |
2228 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
2229 | if (b->type == bp_jit_event) | |
2230 | { | |
2231 | delete_breakpoint (b); | |
2232 | continue; | |
2233 | } | |
2234 | ||
1900040c | 2235 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
2236 | as must overlay event and longjmp master breakpoints. */ |
2237 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
aa7d318d | 2238 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master) |
c4093a6a JM |
2239 | { |
2240 | delete_breakpoint (b); | |
2241 | continue; | |
2242 | } | |
2243 | ||
c5aa993b JM |
2244 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2245 | if (b->type == bp_step_resume) | |
2246 | { | |
2247 | delete_breakpoint (b); | |
2248 | continue; | |
2249 | } | |
2250 | ||
611c83ae PA |
2251 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
2252 | after an exec. */ | |
2253 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume) | |
2254 | { | |
2255 | delete_breakpoint (b); | |
2256 | continue; | |
2257 | } | |
2258 | ||
ce78b96d JB |
2259 | if (b->type == bp_catchpoint) |
2260 | { | |
2261 | /* For now, none of the bp_catchpoint breakpoints need to | |
2262 | do anything at this point. In the future, if some of | |
2263 | the catchpoints need to something, we will need to add | |
2264 | a new method, and call this method from here. */ | |
2265 | continue; | |
2266 | } | |
2267 | ||
c5aa993b JM |
2268 | /* bp_finish is a special case. The only way we ought to be able |
2269 | to see one of these when an exec() has happened, is if the user | |
2270 | caught a vfork, and then said "finish". Ordinarily a finish just | |
2271 | carries them to the call-site of the current callee, by setting | |
2272 | a temporary bp there and resuming. But in this case, the finish | |
2273 | will carry them entirely through the vfork & exec. | |
2274 | ||
2275 | We don't want to allow a bp_finish to remain inserted now. But | |
2276 | we can't safely delete it, 'cause finish_command has a handle to | |
2277 | the bp on a bpstat, and will later want to delete it. There's a | |
2278 | chance (and I've seen it happen) that if we delete the bp_finish | |
2279 | here, that its storage will get reused by the time finish_command | |
2280 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
2281 | We really must allow finish_command to delete a bp_finish. | |
2282 | ||
53a5351d JM |
2283 | In the absense of a general solution for the "how do we know |
2284 | it's safe to delete something others may have handles to?" | |
2285 | problem, what we'll do here is just uninsert the bp_finish, and | |
2286 | let finish_command delete it. | |
2287 | ||
2288 | (We know the bp_finish is "doomed" in the sense that it's | |
2289 | momentary, and will be deleted as soon as finish_command sees | |
2290 | the inferior stopped. So it doesn't matter that the bp's | |
2291 | address is probably bogus in the new a.out, unlike e.g., the | |
2292 | solib breakpoints.) */ | |
c5aa993b | 2293 | |
c5aa993b JM |
2294 | if (b->type == bp_finish) |
2295 | { | |
2296 | continue; | |
2297 | } | |
2298 | ||
2299 | /* Without a symbolic address, we have little hope of the | |
2300 | pre-exec() address meaning the same thing in the post-exec() | |
2301 | a.out. */ | |
2302 | if (b->addr_string == NULL) | |
2303 | { | |
2304 | delete_breakpoint (b); | |
2305 | continue; | |
2306 | } | |
c5aa993b | 2307 | } |
1900040c | 2308 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
69de3c6a | 2309 | create_overlay_event_breakpoint ("_ovly_debug_event"); |
0fd8e87f UW |
2310 | create_longjmp_master_breakpoint ("longjmp"); |
2311 | create_longjmp_master_breakpoint ("_longjmp"); | |
2312 | create_longjmp_master_breakpoint ("siglongjmp"); | |
2313 | create_longjmp_master_breakpoint ("_siglongjmp"); | |
aa7d318d | 2314 | create_std_terminate_master_breakpoint ("std::terminate()"); |
c906108c SS |
2315 | } |
2316 | ||
2317 | int | |
fba45db2 | 2318 | detach_breakpoints (int pid) |
c906108c | 2319 | { |
876fa593 | 2320 | struct bp_location *b, **bp_tmp; |
3a1bae8e | 2321 | int val = 0; |
ce696e05 | 2322 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 2323 | struct inferior *inf = current_inferior (); |
c5aa993b | 2324 | |
39f77062 | 2325 | if (pid == PIDGET (inferior_ptid)) |
8a3fe4f8 | 2326 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 2327 | |
6c95b8df | 2328 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
ce696e05 | 2329 | inferior_ptid = pid_to_ptid (pid); |
876fa593 | 2330 | ALL_BP_LOCATIONS (b, bp_tmp) |
c5aa993b | 2331 | { |
6c95b8df PA |
2332 | if (b->pspace != inf->pspace) |
2333 | continue; | |
2334 | ||
0bde7532 | 2335 | if (b->inserted) |
6c95b8df | 2336 | val |= remove_breakpoint_1 (b, mark_inserted); |
c5aa993b | 2337 | } |
ce696e05 | 2338 | do_cleanups (old_chain); |
3a1bae8e | 2339 | return val; |
c906108c SS |
2340 | } |
2341 | ||
6c95b8df PA |
2342 | /* Remove the breakpoint location B from the current address space. |
2343 | Note that this is used to detach breakpoints from a child fork. | |
2344 | When we get here, the child isn't in the inferior list, and neither | |
2345 | do we have objects to represent its address space --- we should | |
2346 | *not* look at b->pspace->aspace here. */ | |
2347 | ||
c906108c | 2348 | static int |
6c95b8df | 2349 | remove_breakpoint_1 (struct bp_location *b, insertion_state_t is) |
c906108c SS |
2350 | { |
2351 | int val; | |
6c95b8df | 2352 | struct cleanup *old_chain; |
c5aa993b | 2353 | |
0bde7532 | 2354 | if (b->owner->enable_state == bp_permanent) |
c2c6d25f JM |
2355 | /* Permanent breakpoints cannot be inserted or removed. */ |
2356 | return 0; | |
2357 | ||
74960c60 VP |
2358 | /* The type of none suggests that owner is actually deleted. |
2359 | This should not ever happen. */ | |
2360 | gdb_assert (b->owner->type != bp_none); | |
0bde7532 DJ |
2361 | |
2362 | if (b->loc_type == bp_loc_software_breakpoint | |
2363 | || b->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 2364 | { |
c02f5703 MS |
2365 | /* "Normal" instruction breakpoint: either the standard |
2366 | trap-instruction bp (bp_breakpoint), or a | |
2367 | bp_hardware_breakpoint. */ | |
2368 | ||
2369 | /* First check to see if we have to handle an overlay. */ | |
2370 | if (overlay_debugging == ovly_off | |
0bde7532 DJ |
2371 | || b->section == NULL |
2372 | || !(section_is_overlay (b->section))) | |
c02f5703 MS |
2373 | { |
2374 | /* No overlay handling: just remove the breakpoint. */ | |
2375 | ||
0bde7532 | 2376 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e | 2377 | val = target_remove_hw_breakpoint (b->gdbarch, &b->target_info); |
c02f5703 | 2378 | else |
a6d9a66e | 2379 | val = target_remove_breakpoint (b->gdbarch, &b->target_info); |
c02f5703 | 2380 | } |
c906108c SS |
2381 | else |
2382 | { | |
c02f5703 MS |
2383 | /* This breakpoint is in an overlay section. |
2384 | Did we set a breakpoint at the LMA? */ | |
2385 | if (!overlay_events_enabled) | |
2386 | { | |
2387 | /* Yes -- overlay event support is not active, so we | |
2388 | should have set a breakpoint at the LMA. Remove it. | |
2389 | */ | |
c02f5703 MS |
2390 | /* Ignore any failures: if the LMA is in ROM, we will |
2391 | have already warned when we failed to insert it. */ | |
0bde7532 | 2392 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e UW |
2393 | target_remove_hw_breakpoint (b->gdbarch, |
2394 | &b->overlay_target_info); | |
c02f5703 | 2395 | else |
a6d9a66e UW |
2396 | target_remove_breakpoint (b->gdbarch, |
2397 | &b->overlay_target_info); | |
c02f5703 MS |
2398 | } |
2399 | /* Did we set a breakpoint at the VMA? | |
2400 | If so, we will have marked the breakpoint 'inserted'. */ | |
0bde7532 | 2401 | if (b->inserted) |
c906108c | 2402 | { |
c02f5703 MS |
2403 | /* Yes -- remove it. Previously we did not bother to |
2404 | remove the breakpoint if the section had been | |
2405 | unmapped, but let's not rely on that being safe. We | |
2406 | don't know what the overlay manager might do. */ | |
0bde7532 | 2407 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e UW |
2408 | val = target_remove_hw_breakpoint (b->gdbarch, |
2409 | &b->target_info); | |
aa67235e UW |
2410 | |
2411 | /* However, we should remove *software* breakpoints only | |
2412 | if the section is still mapped, or else we overwrite | |
2413 | wrong code with the saved shadow contents. */ | |
2414 | else if (section_is_mapped (b->section)) | |
a6d9a66e UW |
2415 | val = target_remove_breakpoint (b->gdbarch, |
2416 | &b->target_info); | |
aa67235e UW |
2417 | else |
2418 | val = 0; | |
c906108c | 2419 | } |
c02f5703 MS |
2420 | else |
2421 | { | |
2422 | /* No -- not inserted, so no need to remove. No error. */ | |
2423 | val = 0; | |
2424 | } | |
c906108c | 2425 | } |
879d1e6b UW |
2426 | |
2427 | /* In some cases, we might not be able to remove a breakpoint | |
2428 | in a shared library that has already been removed, but we | |
2429 | have not yet processed the shlib unload event. */ | |
6c95b8df | 2430 | if (val && solib_name_from_address (b->pspace, b->address)) |
879d1e6b UW |
2431 | val = 0; |
2432 | ||
c906108c SS |
2433 | if (val) |
2434 | return val; | |
0bde7532 | 2435 | b->inserted = (is == mark_inserted); |
c906108c | 2436 | } |
a5606eee | 2437 | else if (b->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 2438 | { |
278cd55f AC |
2439 | struct value *v; |
2440 | struct value *n; | |
c5aa993b | 2441 | |
0bde7532 | 2442 | b->inserted = (is == mark_inserted); |
a5606eee VP |
2443 | val = target_remove_watchpoint (b->address, b->length, |
2444 | b->watchpoint_type); | |
2e70b7b9 | 2445 | |
c906108c | 2446 | /* Failure to remove any of the hardware watchpoints comes here. */ |
0bde7532 | 2447 | if ((is == mark_uninserted) && (b->inserted)) |
8a3fe4f8 | 2448 | warning (_("Could not remove hardware watchpoint %d."), |
0bde7532 | 2449 | b->owner->number); |
c906108c | 2450 | } |
ce78b96d JB |
2451 | else if (b->owner->type == bp_catchpoint |
2452 | && breakpoint_enabled (b->owner) | |
2453 | && !b->duplicate) | |
2454 | { | |
2455 | gdb_assert (b->owner->ops != NULL && b->owner->ops->remove != NULL); | |
2456 | ||
2457 | val = b->owner->ops->remove (b->owner); | |
2458 | if (val) | |
2459 | return val; | |
2460 | b->inserted = (is == mark_inserted); | |
2461 | } | |
c906108c SS |
2462 | |
2463 | return 0; | |
2464 | } | |
2465 | ||
6c95b8df PA |
2466 | static int |
2467 | remove_breakpoint (struct bp_location *b, insertion_state_t is) | |
2468 | { | |
2469 | int ret; | |
2470 | struct cleanup *old_chain; | |
2471 | ||
2472 | if (b->owner->enable_state == bp_permanent) | |
2473 | /* Permanent breakpoints cannot be inserted or removed. */ | |
2474 | return 0; | |
2475 | ||
2476 | /* The type of none suggests that owner is actually deleted. | |
2477 | This should not ever happen. */ | |
2478 | gdb_assert (b->owner->type != bp_none); | |
2479 | ||
2480 | old_chain = save_current_space_and_thread (); | |
2481 | ||
2482 | switch_to_program_space_and_thread (b->pspace); | |
2483 | ||
2484 | ret = remove_breakpoint_1 (b, is); | |
2485 | ||
2486 | do_cleanups (old_chain); | |
2487 | return ret; | |
2488 | } | |
2489 | ||
c906108c SS |
2490 | /* Clear the "inserted" flag in all breakpoints. */ |
2491 | ||
25b22b0a | 2492 | void |
fba45db2 | 2493 | mark_breakpoints_out (void) |
c906108c | 2494 | { |
876fa593 | 2495 | struct bp_location *bpt, **bptp_tmp; |
c906108c | 2496 | |
876fa593 | 2497 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
6c95b8df PA |
2498 | if (bpt->pspace == current_program_space) |
2499 | bpt->inserted = 0; | |
c906108c SS |
2500 | } |
2501 | ||
53a5351d JM |
2502 | /* Clear the "inserted" flag in all breakpoints and delete any |
2503 | breakpoints which should go away between runs of the program. | |
c906108c SS |
2504 | |
2505 | Plus other such housekeeping that has to be done for breakpoints | |
2506 | between runs. | |
2507 | ||
53a5351d JM |
2508 | Note: this function gets called at the end of a run (by |
2509 | generic_mourn_inferior) and when a run begins (by | |
2510 | init_wait_for_inferior). */ | |
c906108c SS |
2511 | |
2512 | ||
2513 | ||
2514 | void | |
fba45db2 | 2515 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 2516 | { |
52f0bd74 | 2517 | struct breakpoint *b, *temp; |
876fa593 | 2518 | struct bp_location *bpt, **bptp_tmp; |
1c5cfe86 | 2519 | int ix; |
6c95b8df | 2520 | struct program_space *pspace = current_program_space; |
c906108c | 2521 | |
50c71eaf PA |
2522 | /* If breakpoint locations are shared across processes, then there's |
2523 | nothing to do. */ | |
2567c7d9 | 2524 | if (gdbarch_has_global_breakpoints (target_gdbarch)) |
50c71eaf PA |
2525 | return; |
2526 | ||
876fa593 | 2527 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
6c95b8df PA |
2528 | { |
2529 | if (bpt->pspace == pspace | |
2530 | && bpt->owner->enable_state != bp_permanent) | |
514f746b | 2531 | bpt->inserted = 0; |
6c95b8df | 2532 | } |
075f6582 | 2533 | |
c906108c | 2534 | ALL_BREAKPOINTS_SAFE (b, temp) |
c5aa993b | 2535 | { |
6c95b8df PA |
2536 | if (b->loc && b->loc->pspace != pspace) |
2537 | continue; | |
2538 | ||
c5aa993b JM |
2539 | switch (b->type) |
2540 | { | |
2541 | case bp_call_dummy: | |
c906108c | 2542 | |
c5aa993b | 2543 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
2544 | cause problems when the inferior is rerun, so we better get |
2545 | rid of it. */ | |
2546 | ||
2547 | case bp_watchpoint_scope: | |
2548 | ||
2549 | /* Also get rid of scope breakpoints. */ | |
2550 | ||
2551 | case bp_shlib_event: | |
2552 | ||
2553 | /* Also remove solib event breakpoints. Their addresses may | |
2554 | have changed since the last time we ran the program. | |
2555 | Actually we may now be debugging against different target; | |
2556 | and so the solib backend that installed this breakpoint may | |
2557 | not be used in by the target. E.g., | |
2558 | ||
2559 | (gdb) file prog-linux | |
2560 | (gdb) run # native linux target | |
2561 | ... | |
2562 | (gdb) kill | |
2563 | (gdb) file prog-win.exe | |
2564 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
2565 | */ | |
c906108c | 2566 | |
c5aa993b JM |
2567 | delete_breakpoint (b); |
2568 | break; | |
c906108c | 2569 | |
c5aa993b JM |
2570 | case bp_watchpoint: |
2571 | case bp_hardware_watchpoint: | |
2572 | case bp_read_watchpoint: | |
2573 | case bp_access_watchpoint: | |
c906108c | 2574 | |
c5aa993b JM |
2575 | /* Likewise for watchpoints on local expressions. */ |
2576 | if (b->exp_valid_block != NULL) | |
2577 | delete_breakpoint (b); | |
967af18d | 2578 | else if (context == inf_starting) |
c860120c PM |
2579 | { |
2580 | /* Reset val field to force reread of starting value | |
2581 | in insert_breakpoints. */ | |
2582 | if (b->val) | |
2583 | value_free (b->val); | |
2584 | b->val = NULL; | |
fa4727a6 | 2585 | b->val_valid = 0; |
c860120c | 2586 | } |
c5aa993b JM |
2587 | break; |
2588 | default: | |
c5aa993b JM |
2589 | break; |
2590 | } | |
2591 | } | |
1c5cfe86 PA |
2592 | |
2593 | /* Get rid of the moribund locations. */ | |
2594 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bpt); ++ix) | |
2595 | free_bp_location (bpt); | |
2596 | VEC_free (bp_location_p, moribund_locations); | |
c906108c SS |
2597 | } |
2598 | ||
6c95b8df PA |
2599 | /* These functions concern about actual breakpoints inserted in the |
2600 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
2601 | we need to hop over the bkpt --- so we check for address space | |
2602 | match, not program space. */ | |
2603 | ||
c2c6d25f JM |
2604 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
2605 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
2606 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
2607 | permanent breakpoint. | |
2608 | - When continuing from a location with an ordinary breakpoint, we | |
2609 | actually single step once before calling insert_breakpoints. | |
2610 | - When continuing from a localion with a permanent breakpoint, we | |
2611 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by | |
2612 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 2613 | |
c2c6d25f | 2614 | enum breakpoint_here |
6c95b8df | 2615 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 2616 | { |
876fa593 | 2617 | struct bp_location *bpt, **bptp_tmp; |
c2c6d25f | 2618 | int any_breakpoint_here = 0; |
c906108c | 2619 | |
876fa593 | 2620 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
075f6582 DJ |
2621 | { |
2622 | if (bpt->loc_type != bp_loc_software_breakpoint | |
2623 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
2624 | continue; | |
2625 | ||
468d015d | 2626 | if ((breakpoint_enabled (bpt->owner) |
075f6582 | 2627 | || bpt->owner->enable_state == bp_permanent) |
6c95b8df PA |
2628 | && breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2629 | aspace, pc)) | |
075f6582 DJ |
2630 | { |
2631 | if (overlay_debugging | |
2632 | && section_is_overlay (bpt->section) | |
2633 | && !section_is_mapped (bpt->section)) | |
2634 | continue; /* unmapped overlay -- can't be a match */ | |
2635 | else if (bpt->owner->enable_state == bp_permanent) | |
2636 | return permanent_breakpoint_here; | |
2637 | else | |
2638 | any_breakpoint_here = 1; | |
2639 | } | |
2640 | } | |
c906108c | 2641 | |
c2c6d25f | 2642 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
2643 | } |
2644 | ||
1c5cfe86 PA |
2645 | /* Return true if there's a moribund breakpoint at PC. */ |
2646 | ||
2647 | int | |
6c95b8df | 2648 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
2649 | { |
2650 | struct bp_location *loc; | |
2651 | int ix; | |
2652 | ||
2653 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
6c95b8df PA |
2654 | if (breakpoint_address_match (loc->pspace->aspace, loc->address, |
2655 | aspace, pc)) | |
1c5cfe86 PA |
2656 | return 1; |
2657 | ||
2658 | return 0; | |
2659 | } | |
c2c6d25f | 2660 | |
c36b740a | 2661 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
876fa593 | 2662 | inserted using regular breakpoint_chain / bp_location array mechanism. |
c36b740a VP |
2663 | This does not check for single-step breakpoints, which are |
2664 | inserted and removed using direct target manipulation. */ | |
c906108c SS |
2665 | |
2666 | int | |
6c95b8df | 2667 | regular_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 2668 | { |
876fa593 | 2669 | struct bp_location *bpt, **bptp_tmp; |
c906108c | 2670 | |
876fa593 | 2671 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
c5aa993b | 2672 | { |
075f6582 DJ |
2673 | if (bpt->loc_type != bp_loc_software_breakpoint |
2674 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
2675 | continue; | |
2676 | ||
2677 | if (bpt->inserted | |
6c95b8df PA |
2678 | && breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2679 | aspace, pc)) | |
075f6582 DJ |
2680 | { |
2681 | if (overlay_debugging | |
2682 | && section_is_overlay (bpt->section) | |
2683 | && !section_is_mapped (bpt->section)) | |
2684 | continue; /* unmapped overlay -- can't be a match */ | |
2685 | else | |
2686 | return 1; | |
2687 | } | |
c5aa993b | 2688 | } |
c36b740a VP |
2689 | return 0; |
2690 | } | |
2691 | ||
2692 | /* Returns non-zero iff there's either regular breakpoint | |
2693 | or a single step breakpoint inserted at PC. */ | |
2694 | ||
2695 | int | |
6c95b8df | 2696 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c36b740a | 2697 | { |
6c95b8df | 2698 | if (regular_breakpoint_inserted_here_p (aspace, pc)) |
c36b740a | 2699 | return 1; |
c906108c | 2700 | |
6c95b8df | 2701 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2702 | return 1; |
2703 | ||
c906108c SS |
2704 | return 0; |
2705 | } | |
2706 | ||
4fa8626c DJ |
2707 | /* This function returns non-zero iff there is a software breakpoint |
2708 | inserted at PC. */ | |
2709 | ||
2710 | int | |
6c95b8df | 2711 | software_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
4fa8626c | 2712 | { |
876fa593 | 2713 | struct bp_location *bpt, **bptp_tmp; |
4fa8626c DJ |
2714 | int any_breakpoint_here = 0; |
2715 | ||
876fa593 | 2716 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
4fa8626c DJ |
2717 | { |
2718 | if (bpt->loc_type != bp_loc_software_breakpoint) | |
2719 | continue; | |
2720 | ||
0d381245 | 2721 | if (bpt->inserted |
6c95b8df PA |
2722 | && breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2723 | aspace, pc)) | |
4fa8626c DJ |
2724 | { |
2725 | if (overlay_debugging | |
2726 | && section_is_overlay (bpt->section) | |
2727 | && !section_is_mapped (bpt->section)) | |
2728 | continue; /* unmapped overlay -- can't be a match */ | |
2729 | else | |
2730 | return 1; | |
2731 | } | |
2732 | } | |
2733 | ||
1aafd4da | 2734 | /* Also check for software single-step breakpoints. */ |
6c95b8df | 2735 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2736 | return 1; |
2737 | ||
4fa8626c DJ |
2738 | return 0; |
2739 | } | |
2740 | ||
9093389c PA |
2741 | int |
2742 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
2743 | CORE_ADDR addr, ULONGEST len) | |
2744 | { | |
2745 | struct breakpoint *bpt; | |
2746 | ||
2747 | ALL_BREAKPOINTS (bpt) | |
2748 | { | |
2749 | struct bp_location *loc; | |
2750 | ||
2751 | if (bpt->type != bp_hardware_watchpoint | |
2752 | && bpt->type != bp_access_watchpoint) | |
2753 | continue; | |
2754 | ||
2755 | if (!breakpoint_enabled (bpt)) | |
2756 | continue; | |
2757 | ||
2758 | for (loc = bpt->loc; loc; loc = loc->next) | |
2759 | if (loc->pspace->aspace == aspace && loc->inserted) | |
2760 | { | |
2761 | CORE_ADDR l, h; | |
2762 | ||
2763 | /* Check for intersection. */ | |
2764 | l = max (loc->address, addr); | |
2765 | h = min (loc->address + loc->length, addr + len); | |
2766 | if (l < h) | |
2767 | return 1; | |
2768 | } | |
2769 | } | |
2770 | return 0; | |
2771 | } | |
2772 | ||
075f6582 DJ |
2773 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
2774 | PC is valid for process/thread PTID. */ | |
c906108c SS |
2775 | |
2776 | int | |
6c95b8df PA |
2777 | breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc, |
2778 | ptid_t ptid) | |
c906108c | 2779 | { |
876fa593 | 2780 | struct bp_location *bpt, **bptp_tmp; |
4a306c9a | 2781 | /* The thread and task IDs associated to PTID, computed lazily. */ |
a6f1cd96 | 2782 | int thread = -1; |
4a306c9a | 2783 | int task = 0; |
a6f1cd96 | 2784 | |
876fa593 | 2785 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
c5aa993b | 2786 | { |
075f6582 DJ |
2787 | if (bpt->loc_type != bp_loc_software_breakpoint |
2788 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
2789 | continue; | |
2790 | ||
a6f1cd96 JB |
2791 | if (!breakpoint_enabled (bpt->owner) |
2792 | && bpt->owner->enable_state != bp_permanent) | |
2793 | continue; | |
2794 | ||
6c95b8df PA |
2795 | if (!breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2796 | aspace, pc)) | |
a6f1cd96 JB |
2797 | continue; |
2798 | ||
2799 | if (bpt->owner->thread != -1) | |
075f6582 | 2800 | { |
a6f1cd96 JB |
2801 | /* This is a thread-specific breakpoint. Check that ptid |
2802 | matches that thread. If thread hasn't been computed yet, | |
2803 | it is now time to do so. */ | |
2804 | if (thread == -1) | |
2805 | thread = pid_to_thread_id (ptid); | |
2806 | if (bpt->owner->thread != thread) | |
2807 | continue; | |
075f6582 | 2808 | } |
a6f1cd96 | 2809 | |
4a306c9a JB |
2810 | if (bpt->owner->task != 0) |
2811 | { | |
2812 | /* This is a task-specific breakpoint. Check that ptid | |
2813 | matches that task. If task hasn't been computed yet, | |
2814 | it is now time to do so. */ | |
2815 | if (task == 0) | |
2816 | task = ada_get_task_number (ptid); | |
2817 | if (bpt->owner->task != task) | |
2818 | continue; | |
2819 | } | |
2820 | ||
a6f1cd96 JB |
2821 | if (overlay_debugging |
2822 | && section_is_overlay (bpt->section) | |
2823 | && !section_is_mapped (bpt->section)) | |
2824 | continue; /* unmapped overlay -- can't be a match */ | |
2825 | ||
2826 | return 1; | |
c5aa993b | 2827 | } |
c906108c SS |
2828 | |
2829 | return 0; | |
2830 | } | |
c906108c | 2831 | \f |
c5aa993b | 2832 | |
c906108c SS |
2833 | /* bpstat stuff. External routines' interfaces are documented |
2834 | in breakpoint.h. */ | |
2835 | ||
2836 | int | |
fba45db2 | 2837 | ep_is_catchpoint (struct breakpoint *ep) |
c906108c | 2838 | { |
533be4dd | 2839 | return (ep->type == bp_catchpoint); |
c906108c SS |
2840 | } |
2841 | ||
198757a8 VP |
2842 | void |
2843 | bpstat_free (bpstat bs) | |
2844 | { | |
2845 | if (bs->old_val != NULL) | |
2846 | value_free (bs->old_val); | |
9add0f1b | 2847 | decref_counted_command_line (&bs->commands); |
198757a8 VP |
2848 | xfree (bs); |
2849 | } | |
2850 | ||
c906108c SS |
2851 | /* Clear a bpstat so that it says we are not at any breakpoint. |
2852 | Also free any storage that is part of a bpstat. */ | |
2853 | ||
2854 | void | |
fba45db2 | 2855 | bpstat_clear (bpstat *bsp) |
c906108c SS |
2856 | { |
2857 | bpstat p; | |
2858 | bpstat q; | |
2859 | ||
2860 | if (bsp == 0) | |
2861 | return; | |
2862 | p = *bsp; | |
2863 | while (p != NULL) | |
2864 | { | |
2865 | q = p->next; | |
198757a8 | 2866 | bpstat_free (p); |
c906108c SS |
2867 | p = q; |
2868 | } | |
2869 | *bsp = NULL; | |
2870 | } | |
2871 | ||
2872 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
2873 | is part of the bpstat is copied as well. */ | |
2874 | ||
2875 | bpstat | |
fba45db2 | 2876 | bpstat_copy (bpstat bs) |
c906108c SS |
2877 | { |
2878 | bpstat p = NULL; | |
2879 | bpstat tmp; | |
2880 | bpstat retval = NULL; | |
2881 | ||
2882 | if (bs == NULL) | |
2883 | return bs; | |
2884 | ||
2885 | for (; bs != NULL; bs = bs->next) | |
2886 | { | |
2887 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
2888 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 2889 | incref_counted_command_line (tmp->commands); |
31cc81e9 | 2890 | if (bs->old_val != NULL) |
3c3185ac JK |
2891 | { |
2892 | tmp->old_val = value_copy (bs->old_val); | |
2893 | release_value (tmp->old_val); | |
2894 | } | |
31cc81e9 | 2895 | |
c906108c SS |
2896 | if (p == NULL) |
2897 | /* This is the first thing in the chain. */ | |
2898 | retval = tmp; | |
2899 | else | |
2900 | p->next = tmp; | |
2901 | p = tmp; | |
2902 | } | |
2903 | p->next = NULL; | |
2904 | return retval; | |
2905 | } | |
2906 | ||
2907 | /* Find the bpstat associated with this breakpoint */ | |
2908 | ||
2909 | bpstat | |
fba45db2 | 2910 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 2911 | { |
c5aa993b JM |
2912 | if (bsp == NULL) |
2913 | return NULL; | |
c906108c | 2914 | |
c5aa993b JM |
2915 | for (; bsp != NULL; bsp = bsp->next) |
2916 | { | |
4f8d1dc6 | 2917 | if (bsp->breakpoint_at && bsp->breakpoint_at->owner == breakpoint) |
c5aa993b JM |
2918 | return bsp; |
2919 | } | |
c906108c SS |
2920 | return NULL; |
2921 | } | |
2922 | ||
2923 | /* Find a step_resume breakpoint associated with this bpstat. | |
2924 | (If there are multiple step_resume bp's on the list, this function | |
2925 | will arbitrarily pick one.) | |
2926 | ||
2927 | It is an error to use this function if BPSTAT doesn't contain a | |
2928 | step_resume breakpoint. | |
2929 | ||
2930 | See wait_for_inferior's use of this function. */ | |
2931 | struct breakpoint * | |
fba45db2 | 2932 | bpstat_find_step_resume_breakpoint (bpstat bsp) |
c906108c | 2933 | { |
8601f500 MS |
2934 | int current_thread; |
2935 | ||
8a3fe4f8 | 2936 | gdb_assert (bsp != NULL); |
c906108c | 2937 | |
8601f500 MS |
2938 | current_thread = pid_to_thread_id (inferior_ptid); |
2939 | ||
c906108c SS |
2940 | for (; bsp != NULL; bsp = bsp->next) |
2941 | { | |
059fb39f PM |
2942 | if ((bsp->breakpoint_at != NULL) |
2943 | && (bsp->breakpoint_at->owner->type == bp_step_resume) | |
2944 | && (bsp->breakpoint_at->owner->thread == current_thread | |
2945 | || bsp->breakpoint_at->owner->thread == -1)) | |
4f8d1dc6 | 2946 | return bsp->breakpoint_at->owner; |
c906108c SS |
2947 | } |
2948 | ||
8a3fe4f8 | 2949 | internal_error (__FILE__, __LINE__, _("No step_resume breakpoint found.")); |
c906108c SS |
2950 | } |
2951 | ||
2952 | ||
8671a17b | 2953 | /* Put in *NUM the breakpoint number of the first breakpoint we are stopped |
c906108c SS |
2954 | at. *BSP upon return is a bpstat which points to the remaining |
2955 | breakpoints stopped at (but which is not guaranteed to be good for | |
2956 | anything but further calls to bpstat_num). | |
8671a17b PA |
2957 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
2958 | Return -1 if stopped at a breakpoint that has been deleted since | |
2959 | we set it. | |
2960 | Return 1 otherwise. */ | |
c906108c SS |
2961 | |
2962 | int | |
8671a17b | 2963 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
2964 | { |
2965 | struct breakpoint *b; | |
2966 | ||
2967 | if ((*bsp) == NULL) | |
2968 | return 0; /* No more breakpoint values */ | |
8671a17b | 2969 | |
4f8d1dc6 VP |
2970 | /* We assume we'll never have several bpstats that |
2971 | correspond to a single breakpoint -- otherwise, | |
2972 | this function might return the same number more | |
2973 | than once and this will look ugly. */ | |
2974 | b = (*bsp)->breakpoint_at ? (*bsp)->breakpoint_at->owner : NULL; | |
8671a17b PA |
2975 | *bsp = (*bsp)->next; |
2976 | if (b == NULL) | |
2977 | return -1; /* breakpoint that's been deleted since */ | |
2978 | ||
2979 | *num = b->number; /* We have its number */ | |
2980 | return 1; | |
c906108c SS |
2981 | } |
2982 | ||
2983 | /* Modify BS so that the actions will not be performed. */ | |
2984 | ||
2985 | void | |
fba45db2 | 2986 | bpstat_clear_actions (bpstat bs) |
c906108c SS |
2987 | { |
2988 | for (; bs != NULL; bs = bs->next) | |
2989 | { | |
9add0f1b | 2990 | decref_counted_command_line (&bs->commands); |
dde2d684 | 2991 | bs->commands_left = NULL; |
c906108c SS |
2992 | if (bs->old_val != NULL) |
2993 | { | |
2994 | value_free (bs->old_val); | |
2995 | bs->old_val = NULL; | |
2996 | } | |
2997 | } | |
2998 | } | |
2999 | ||
f3b1572e PA |
3000 | /* Called when a command is about to proceed the inferior. */ |
3001 | ||
3002 | static void | |
3003 | breakpoint_about_to_proceed (void) | |
3004 | { | |
3005 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
3006 | { | |
3007 | struct thread_info *tp = inferior_thread (); | |
3008 | ||
3009 | /* Allow inferior function calls in breakpoint commands to not | |
3010 | interrupt the command list. When the call finishes | |
3011 | successfully, the inferior will be standing at the same | |
3012 | breakpoint as if nothing happened. */ | |
3013 | if (tp->in_infcall) | |
3014 | return; | |
3015 | } | |
3016 | ||
3017 | breakpoint_proceeded = 1; | |
3018 | } | |
3019 | ||
c906108c | 3020 | /* Stub for cleaning up our state if we error-out of a breakpoint command */ |
c906108c | 3021 | static void |
4efb68b1 | 3022 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
3023 | { |
3024 | executing_breakpoint_commands = 0; | |
3025 | } | |
3026 | ||
3027 | /* Execute all the commands associated with all the breakpoints at this | |
3028 | location. Any of these commands could cause the process to proceed | |
3029 | beyond this point, etc. We look out for such changes by checking | |
347bddb7 | 3030 | the global "breakpoint_proceeded" after each command. |
c906108c | 3031 | |
347bddb7 PA |
3032 | Returns true if a breakpoint command resumed the inferior. In that |
3033 | case, it is the caller's responsibility to recall it again with the | |
3034 | bpstat of the current thread. */ | |
3035 | ||
3036 | static int | |
3037 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
3038 | { |
3039 | bpstat bs; | |
3040 | struct cleanup *old_chain; | |
347bddb7 | 3041 | int again = 0; |
c906108c SS |
3042 | |
3043 | /* Avoid endless recursion if a `source' command is contained | |
3044 | in bs->commands. */ | |
3045 | if (executing_breakpoint_commands) | |
347bddb7 | 3046 | return 0; |
c906108c SS |
3047 | |
3048 | executing_breakpoint_commands = 1; | |
3049 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
3050 | ||
c906108c SS |
3051 | /* This pointer will iterate over the list of bpstat's. */ |
3052 | bs = *bsp; | |
3053 | ||
3054 | breakpoint_proceeded = 0; | |
3055 | for (; bs != NULL; bs = bs->next) | |
3056 | { | |
9add0f1b | 3057 | struct counted_command_line *ccmd; |
6c50ab1c JB |
3058 | struct command_line *cmd; |
3059 | struct cleanup *this_cmd_tree_chain; | |
3060 | ||
3061 | /* Take ownership of the BSP's command tree, if it has one. | |
3062 | ||
3063 | The command tree could legitimately contain commands like | |
3064 | 'step' and 'next', which call clear_proceed_status, which | |
3065 | frees stop_bpstat's command tree. To make sure this doesn't | |
3066 | free the tree we're executing out from under us, we need to | |
3067 | take ownership of the tree ourselves. Since a given bpstat's | |
3068 | commands are only executed once, we don't need to copy it; we | |
3069 | can clear the pointer in the bpstat, and make sure we free | |
3070 | the tree when we're done. */ | |
9add0f1b TT |
3071 | ccmd = bs->commands; |
3072 | bs->commands = NULL; | |
3073 | this_cmd_tree_chain | |
3074 | = make_cleanup_decref_counted_command_line (&ccmd); | |
3075 | cmd = bs->commands_left; | |
3076 | bs->commands_left = NULL; | |
6c50ab1c | 3077 | |
c906108c SS |
3078 | while (cmd != NULL) |
3079 | { | |
3080 | execute_control_command (cmd); | |
3081 | ||
3082 | if (breakpoint_proceeded) | |
3083 | break; | |
3084 | else | |
3085 | cmd = cmd->next; | |
3086 | } | |
6c50ab1c JB |
3087 | |
3088 | /* We can free this command tree now. */ | |
3089 | do_cleanups (this_cmd_tree_chain); | |
3090 | ||
c906108c | 3091 | if (breakpoint_proceeded) |
32c1e744 VP |
3092 | { |
3093 | if (target_can_async_p ()) | |
347bddb7 PA |
3094 | /* If we are in async mode, then the target might be still |
3095 | running, not stopped at any breakpoint, so nothing for | |
3096 | us to do here -- just return to the event loop. */ | |
3097 | ; | |
32c1e744 VP |
3098 | else |
3099 | /* In sync mode, when execute_control_command returns | |
3100 | we're already standing on the next breakpoint. | |
347bddb7 PA |
3101 | Breakpoint commands for that stop were not run, since |
3102 | execute_command does not run breakpoint commands -- | |
3103 | only command_line_handler does, but that one is not | |
3104 | involved in execution of breakpoint commands. So, we | |
3105 | can now execute breakpoint commands. It should be | |
3106 | noted that making execute_command do bpstat actions is | |
3107 | not an option -- in this case we'll have recursive | |
3108 | invocation of bpstat for each breakpoint with a | |
3109 | command, and can easily blow up GDB stack. Instead, we | |
3110 | return true, which will trigger the caller to recall us | |
3111 | with the new stop_bpstat. */ | |
3112 | again = 1; | |
3113 | break; | |
32c1e744 | 3114 | } |
c906108c | 3115 | } |
c2b8ed2c | 3116 | do_cleanups (old_chain); |
347bddb7 PA |
3117 | return again; |
3118 | } | |
3119 | ||
3120 | void | |
3121 | bpstat_do_actions (void) | |
3122 | { | |
3123 | /* Do any commands attached to breakpoint we are stopped at. */ | |
3124 | while (!ptid_equal (inferior_ptid, null_ptid) | |
3125 | && target_has_execution | |
3126 | && !is_exited (inferior_ptid) | |
3127 | && !is_executing (inferior_ptid)) | |
3128 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
3129 | and only return when it is stopped at the next breakpoint, we | |
3130 | keep doing breakpoint actions until it returns false to | |
3131 | indicate the inferior was not resumed. */ | |
3132 | if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat)) | |
3133 | break; | |
c906108c SS |
3134 | } |
3135 | ||
fa4727a6 DJ |
3136 | /* Print out the (old or new) value associated with a watchpoint. */ |
3137 | ||
3138 | static void | |
3139 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
3140 | { | |
3141 | if (val == NULL) | |
3142 | fprintf_unfiltered (stream, _("<unreadable>")); | |
3143 | else | |
79a45b7d TT |
3144 | { |
3145 | struct value_print_options opts; | |
3146 | get_user_print_options (&opts); | |
3147 | value_print (val, stream, &opts); | |
3148 | } | |
fa4727a6 DJ |
3149 | } |
3150 | ||
e514a9d6 | 3151 | /* This is the normal print function for a bpstat. In the future, |
c906108c | 3152 | much of this logic could (should?) be moved to bpstat_stop_status, |
e514a9d6 JM |
3153 | by having it set different print_it values. |
3154 | ||
3155 | Current scheme: When we stop, bpstat_print() is called. It loops | |
3156 | through the bpstat list of things causing this stop, calling the | |
3157 | print_bp_stop_message function on each one. The behavior of the | |
3158 | print_bp_stop_message function depends on the print_it field of | |
3159 | bpstat. If such field so indicates, call this function here. | |
3160 | ||
3161 | Return values from this routine (ultimately used by bpstat_print() | |
3162 | and normal_stop() to decide what to do): | |
3163 | PRINT_NOTHING: Means we already printed all we needed to print, | |
3164 | don't print anything else. | |
3165 | PRINT_SRC_ONLY: Means we printed something, and we do *not* desire | |
3166 | that something to be followed by a location. | |
3167 | PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire | |
3168 | that something to be followed by a location. | |
3169 | PRINT_UNKNOWN: Means we printed nothing or we need to do some more | |
3170 | analysis. */ | |
c906108c | 3171 | |
917317f4 | 3172 | static enum print_stop_action |
fba45db2 | 3173 | print_it_typical (bpstat bs) |
c906108c | 3174 | { |
f7545552 | 3175 | struct cleanup *old_chain; |
4f8d1dc6 | 3176 | struct breakpoint *b; |
89f9893c | 3177 | const struct bp_location *bl; |
8b93c638 | 3178 | struct ui_stream *stb; |
f7545552 TT |
3179 | int bp_temp = 0; |
3180 | enum print_stop_action result; | |
3181 | ||
c906108c SS |
3182 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
3183 | which has since been deleted. */ | |
e514a9d6 | 3184 | if (bs->breakpoint_at == NULL) |
917317f4 | 3185 | return PRINT_UNKNOWN; |
0d381245 VP |
3186 | bl = bs->breakpoint_at; |
3187 | b = bl->owner; | |
c906108c | 3188 | |
f7545552 TT |
3189 | stb = ui_out_stream_new (uiout); |
3190 | old_chain = make_cleanup_ui_out_stream_delete (stb); | |
3191 | ||
4f8d1dc6 | 3192 | switch (b->type) |
c906108c | 3193 | { |
e514a9d6 JM |
3194 | case bp_breakpoint: |
3195 | case bp_hardware_breakpoint: | |
2cec12e5 | 3196 | bp_temp = bs->breakpoint_at->owner->disposition == disp_del; |
0d381245 VP |
3197 | if (bl->address != bl->requested_address) |
3198 | breakpoint_adjustment_warning (bl->requested_address, | |
3199 | bl->address, | |
4f8d1dc6 VP |
3200 | b->number, 1); |
3201 | annotate_breakpoint (b->number); | |
2cec12e5 AR |
3202 | if (bp_temp) |
3203 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
3204 | else | |
3205 | ui_out_text (uiout, "\nBreakpoint "); | |
9dc5e2a9 | 3206 | if (ui_out_is_mi_like_p (uiout)) |
2cec12e5 AR |
3207 | { |
3208 | ui_out_field_string (uiout, "reason", | |
3209 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
3210 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
3211 | } | |
4f8d1dc6 | 3212 | ui_out_field_int (uiout, "bkptno", b->number); |
8b93c638 | 3213 | ui_out_text (uiout, ", "); |
f7545552 | 3214 | result = PRINT_SRC_AND_LOC; |
e514a9d6 JM |
3215 | break; |
3216 | ||
3217 | case bp_shlib_event: | |
917317f4 JM |
3218 | /* Did we stop because the user set the stop_on_solib_events |
3219 | variable? (If so, we report this as a generic, "Stopped due | |
3220 | to shlib event" message.) */ | |
a3f17187 | 3221 | printf_filtered (_("Stopped due to shared library event\n")); |
f7545552 | 3222 | result = PRINT_NOTHING; |
e514a9d6 JM |
3223 | break; |
3224 | ||
c4093a6a JM |
3225 | case bp_thread_event: |
3226 | /* Not sure how we will get here. | |
3227 | GDB should not stop for these breakpoints. */ | |
a3f17187 | 3228 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 3229 | result = PRINT_NOTHING; |
c4093a6a JM |
3230 | break; |
3231 | ||
1900040c MS |
3232 | case bp_overlay_event: |
3233 | /* By analogy with the thread event, GDB should not stop for these. */ | |
a3f17187 | 3234 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 3235 | result = PRINT_NOTHING; |
1900040c MS |
3236 | break; |
3237 | ||
0fd8e87f UW |
3238 | case bp_longjmp_master: |
3239 | /* These should never be enabled. */ | |
3240 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
3241 | result = PRINT_NOTHING; | |
3242 | break; | |
3243 | ||
aa7d318d TT |
3244 | case bp_std_terminate_master: |
3245 | /* These should never be enabled. */ | |
3246 | printf_filtered (_("std::terminate Master Breakpoint: gdb should not stop!\n")); | |
3247 | result = PRINT_NOTHING; | |
3248 | break; | |
3249 | ||
e514a9d6 JM |
3250 | case bp_watchpoint: |
3251 | case bp_hardware_watchpoint: | |
fa4727a6 DJ |
3252 | annotate_watchpoint (b->number); |
3253 | if (ui_out_is_mi_like_p (uiout)) | |
3254 | ui_out_field_string | |
3255 | (uiout, "reason", | |
3256 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
3257 | mention (b); | |
f7545552 | 3258 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
fa4727a6 DJ |
3259 | ui_out_text (uiout, "\nOld value = "); |
3260 | watchpoint_value_print (bs->old_val, stb->stream); | |
3261 | ui_out_field_stream (uiout, "old", stb); | |
3262 | ui_out_text (uiout, "\nNew value = "); | |
3263 | watchpoint_value_print (b->val, stb->stream); | |
3264 | ui_out_field_stream (uiout, "new", stb); | |
fa4727a6 | 3265 | ui_out_text (uiout, "\n"); |
e514a9d6 | 3266 | /* More than one watchpoint may have been triggered. */ |
f7545552 | 3267 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
3268 | break; |
3269 | ||
3270 | case bp_read_watchpoint: | |
9dc5e2a9 | 3271 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3272 | ui_out_field_string |
3273 | (uiout, "reason", | |
3274 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 3275 | mention (b); |
f7545552 | 3276 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 3277 | ui_out_text (uiout, "\nValue = "); |
fa4727a6 | 3278 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 3279 | ui_out_field_stream (uiout, "value", stb); |
8b93c638 | 3280 | ui_out_text (uiout, "\n"); |
f7545552 | 3281 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
3282 | break; |
3283 | ||
3284 | case bp_access_watchpoint: | |
fa4727a6 | 3285 | if (bs->old_val != NULL) |
8b93c638 | 3286 | { |
4f8d1dc6 | 3287 | annotate_watchpoint (b->number); |
9dc5e2a9 | 3288 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3289 | ui_out_field_string |
3290 | (uiout, "reason", | |
3291 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 3292 | mention (b); |
f7545552 | 3293 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 3294 | ui_out_text (uiout, "\nOld value = "); |
fa4727a6 | 3295 | watchpoint_value_print (bs->old_val, stb->stream); |
8b93c638 | 3296 | ui_out_field_stream (uiout, "old", stb); |
8b93c638 JM |
3297 | ui_out_text (uiout, "\nNew value = "); |
3298 | } | |
3299 | else | |
3300 | { | |
4f8d1dc6 | 3301 | mention (b); |
9dc5e2a9 | 3302 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3303 | ui_out_field_string |
3304 | (uiout, "reason", | |
3305 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
f7545552 | 3306 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 JM |
3307 | ui_out_text (uiout, "\nValue = "); |
3308 | } | |
fa4727a6 | 3309 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 3310 | ui_out_field_stream (uiout, "new", stb); |
8b93c638 | 3311 | ui_out_text (uiout, "\n"); |
f7545552 | 3312 | result = PRINT_UNKNOWN; |
e514a9d6 | 3313 | break; |
4ce44c66 | 3314 | |
e514a9d6 JM |
3315 | /* Fall through, we don't deal with these types of breakpoints |
3316 | here. */ | |
3317 | ||
11cf8741 | 3318 | case bp_finish: |
9dc5e2a9 | 3319 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3320 | ui_out_field_string |
3321 | (uiout, "reason", | |
3322 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
f7545552 | 3323 | result = PRINT_UNKNOWN; |
8b93c638 JM |
3324 | break; |
3325 | ||
e514a9d6 | 3326 | case bp_until: |
9dc5e2a9 | 3327 | if (ui_out_is_mi_like_p (uiout)) |
1fbc2a49 NR |
3328 | ui_out_field_string |
3329 | (uiout, "reason", | |
3330 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
f7545552 | 3331 | result = PRINT_UNKNOWN; |
8b93c638 JM |
3332 | break; |
3333 | ||
c2d11a7d | 3334 | case bp_none: |
e514a9d6 JM |
3335 | case bp_longjmp: |
3336 | case bp_longjmp_resume: | |
3337 | case bp_step_resume: | |
e514a9d6 JM |
3338 | case bp_watchpoint_scope: |
3339 | case bp_call_dummy: | |
aa7d318d | 3340 | case bp_std_terminate: |
1042e4c0 | 3341 | case bp_tracepoint: |
7a697b8d | 3342 | case bp_fast_tracepoint: |
4efc6507 | 3343 | case bp_jit_event: |
e514a9d6 | 3344 | default: |
f7545552 TT |
3345 | result = PRINT_UNKNOWN; |
3346 | break; | |
e514a9d6 | 3347 | } |
f7545552 TT |
3348 | |
3349 | do_cleanups (old_chain); | |
3350 | return result; | |
e514a9d6 JM |
3351 | } |
3352 | ||
3353 | /* Generic routine for printing messages indicating why we | |
3354 | stopped. The behavior of this function depends on the value | |
3355 | 'print_it' in the bpstat structure. Under some circumstances we | |
3356 | may decide not to print anything here and delegate the task to | |
3357 | normal_stop(). */ | |
3358 | ||
3359 | static enum print_stop_action | |
3360 | print_bp_stop_message (bpstat bs) | |
3361 | { | |
3362 | switch (bs->print_it) | |
3363 | { | |
3364 | case print_it_noop: | |
3365 | /* Nothing should be printed for this bpstat entry. */ | |
3366 | return PRINT_UNKNOWN; | |
3367 | break; | |
3368 | ||
3369 | case print_it_done: | |
3370 | /* We still want to print the frame, but we already printed the | |
3371 | relevant messages. */ | |
3372 | return PRINT_SRC_AND_LOC; | |
3373 | break; | |
3374 | ||
3375 | case print_it_normal: | |
4f8d1dc6 | 3376 | { |
89f9893c | 3377 | const struct bp_location *bl = bs->breakpoint_at; |
4f8d1dc6 VP |
3378 | struct breakpoint *b = bl ? bl->owner : NULL; |
3379 | ||
3380 | /* Normal case. Call the breakpoint's print_it method, or | |
3381 | print_it_typical. */ | |
3382 | /* FIXME: how breakpoint can ever be NULL here? */ | |
3383 | if (b != NULL && b->ops != NULL && b->ops->print_it != NULL) | |
3384 | return b->ops->print_it (b); | |
3385 | else | |
3386 | return print_it_typical (bs); | |
3387 | } | |
3388 | break; | |
3086aeae | 3389 | |
e514a9d6 | 3390 | default: |
8e65ff28 | 3391 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 3392 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 3393 | break; |
c906108c | 3394 | } |
c906108c SS |
3395 | } |
3396 | ||
e514a9d6 JM |
3397 | /* Print a message indicating what happened. This is called from |
3398 | normal_stop(). The input to this routine is the head of the bpstat | |
3399 | list - a list of the eventpoints that caused this stop. This | |
3400 | routine calls the generic print routine for printing a message | |
3401 | about reasons for stopping. This will print (for example) the | |
3402 | "Breakpoint n," part of the output. The return value of this | |
3403 | routine is one of: | |
c906108c | 3404 | |
917317f4 JM |
3405 | PRINT_UNKNOWN: Means we printed nothing |
3406 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent | |
c5aa993b JM |
3407 | code to print the location. An example is |
3408 | "Breakpoint 1, " which should be followed by | |
3409 | the location. | |
917317f4 | 3410 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
3411 | to also print the location part of the message. |
3412 | An example is the catch/throw messages, which | |
917317f4 JM |
3413 | don't require a location appended to the end. |
3414 | PRINT_NOTHING: We have done some printing and we don't need any | |
3415 | further info to be printed.*/ | |
c906108c | 3416 | |
917317f4 | 3417 | enum print_stop_action |
fba45db2 | 3418 | bpstat_print (bpstat bs) |
c906108c SS |
3419 | { |
3420 | int val; | |
c5aa993b | 3421 | |
c906108c | 3422 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
3423 | (Currently all watchpoints go on the bpstat whether hit or not. |
3424 | That probably could (should) be changed, provided care is taken | |
c906108c | 3425 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
3426 | for (; bs; bs = bs->next) |
3427 | { | |
3428 | val = print_bp_stop_message (bs); | |
3429 | if (val == PRINT_SRC_ONLY | |
3430 | || val == PRINT_SRC_AND_LOC | |
3431 | || val == PRINT_NOTHING) | |
3432 | return val; | |
3433 | } | |
c906108c | 3434 | |
e514a9d6 JM |
3435 | /* We reached the end of the chain, or we got a null BS to start |
3436 | with and nothing was printed. */ | |
917317f4 | 3437 | return PRINT_UNKNOWN; |
c906108c SS |
3438 | } |
3439 | ||
3440 | /* Evaluate the expression EXP and return 1 if value is zero. | |
3441 | This is used inside a catch_errors to evaluate the breakpoint condition. | |
3442 | The argument is a "struct expression *" that has been cast to char * to | |
3443 | make it pass through catch_errors. */ | |
3444 | ||
3445 | static int | |
4efb68b1 | 3446 | breakpoint_cond_eval (void *exp) |
c906108c | 3447 | { |
278cd55f | 3448 | struct value *mark = value_mark (); |
c5aa993b | 3449 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
c906108c SS |
3450 | value_free_to_mark (mark); |
3451 | return i; | |
3452 | } | |
3453 | ||
3454 | /* Allocate a new bpstat and chain it to the current one. */ | |
3455 | ||
3456 | static bpstat | |
89f9893c | 3457 | bpstat_alloc (const struct bp_location *bl, bpstat cbs /* Current "bs" value */ ) |
c906108c SS |
3458 | { |
3459 | bpstat bs; | |
3460 | ||
3461 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
3462 | cbs->next = bs; | |
4f8d1dc6 | 3463 | bs->breakpoint_at = bl; |
c906108c SS |
3464 | /* If the condition is false, etc., don't do the commands. */ |
3465 | bs->commands = NULL; | |
9add0f1b | 3466 | bs->commands_left = NULL; |
c906108c SS |
3467 | bs->old_val = NULL; |
3468 | bs->print_it = print_it_normal; | |
3469 | return bs; | |
3470 | } | |
3471 | \f | |
d983da9c DJ |
3472 | /* The target has stopped with waitstatus WS. Check if any hardware |
3473 | watchpoints have triggered, according to the target. */ | |
3474 | ||
3475 | int | |
3476 | watchpoints_triggered (struct target_waitstatus *ws) | |
3477 | { | |
d92524f1 | 3478 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
3479 | CORE_ADDR addr; |
3480 | struct breakpoint *b; | |
3481 | ||
3482 | if (!stopped_by_watchpoint) | |
3483 | { | |
3484 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
3485 | as not triggered. */ | |
3486 | ALL_BREAKPOINTS (b) | |
3487 | if (b->type == bp_hardware_watchpoint | |
3488 | || b->type == bp_read_watchpoint | |
3489 | || b->type == bp_access_watchpoint) | |
3490 | b->watchpoint_triggered = watch_triggered_no; | |
3491 | ||
3492 | return 0; | |
3493 | } | |
3494 | ||
3495 | if (!target_stopped_data_address (¤t_target, &addr)) | |
3496 | { | |
3497 | /* We were stopped by a watchpoint, but we don't know where. | |
3498 | Mark all watchpoints as unknown. */ | |
3499 | ALL_BREAKPOINTS (b) | |
3500 | if (b->type == bp_hardware_watchpoint | |
3501 | || b->type == bp_read_watchpoint | |
3502 | || b->type == bp_access_watchpoint) | |
3503 | b->watchpoint_triggered = watch_triggered_unknown; | |
3504 | ||
3505 | return stopped_by_watchpoint; | |
3506 | } | |
3507 | ||
3508 | /* The target could report the data address. Mark watchpoints | |
3509 | affected by this data address as triggered, and all others as not | |
3510 | triggered. */ | |
3511 | ||
3512 | ALL_BREAKPOINTS (b) | |
3513 | if (b->type == bp_hardware_watchpoint | |
3514 | || b->type == bp_read_watchpoint | |
3515 | || b->type == bp_access_watchpoint) | |
3516 | { | |
a5606eee | 3517 | struct bp_location *loc; |
d983da9c DJ |
3518 | struct value *v; |
3519 | ||
3520 | b->watchpoint_triggered = watch_triggered_no; | |
a5606eee VP |
3521 | for (loc = b->loc; loc; loc = loc->next) |
3522 | /* Exact match not required. Within range is | |
3523 | sufficient. */ | |
5009afc5 AS |
3524 | if (target_watchpoint_addr_within_range (¤t_target, |
3525 | addr, loc->address, | |
3526 | loc->length)) | |
a5606eee VP |
3527 | { |
3528 | b->watchpoint_triggered = watch_triggered_yes; | |
3529 | break; | |
3530 | } | |
d983da9c DJ |
3531 | } |
3532 | ||
3533 | return 1; | |
3534 | } | |
3535 | ||
c906108c SS |
3536 | /* Possible return values for watchpoint_check (this can't be an enum |
3537 | because of check_errors). */ | |
3538 | /* The watchpoint has been deleted. */ | |
3539 | #define WP_DELETED 1 | |
3540 | /* The value has changed. */ | |
3541 | #define WP_VALUE_CHANGED 2 | |
3542 | /* The value has not changed. */ | |
3543 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
3544 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
3545 | #define WP_IGNORE 4 | |
c906108c SS |
3546 | |
3547 | #define BP_TEMPFLAG 1 | |
3548 | #define BP_HARDWAREFLAG 2 | |
3549 | ||
553e4c11 JB |
3550 | /* Evaluate watchpoint condition expression and check if its value changed. |
3551 | ||
3552 | P should be a pointer to struct bpstat, but is defined as a void * | |
3553 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
3554 | |
3555 | static int | |
4efb68b1 | 3556 | watchpoint_check (void *p) |
c906108c SS |
3557 | { |
3558 | bpstat bs = (bpstat) p; | |
3559 | struct breakpoint *b; | |
3560 | struct frame_info *fr; | |
3561 | int within_current_scope; | |
3562 | ||
4f8d1dc6 | 3563 | b = bs->breakpoint_at->owner; |
c906108c | 3564 | |
f6bc2008 PA |
3565 | /* If this is a local watchpoint, we only want to check if the |
3566 | watchpoint frame is in scope if the current thread is the thread | |
3567 | that was used to create the watchpoint. */ | |
3568 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 3569 | return WP_IGNORE; |
f6bc2008 | 3570 | |
c906108c SS |
3571 | if (b->exp_valid_block == NULL) |
3572 | within_current_scope = 1; | |
3573 | else | |
3574 | { | |
edb3359d DJ |
3575 | struct frame_info *frame = get_current_frame (); |
3576 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
3577 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
3578 | ||
a0f49112 JK |
3579 | /* in_function_epilogue_p() returns a non-zero value if we're still |
3580 | in the function but the stack frame has already been invalidated. | |
3581 | Since we can't rely on the values of local variables after the | |
3582 | stack has been destroyed, we are treating the watchpoint in that | |
3583 | state as `not changed' without further checking. Don't mark | |
3584 | watchpoints as changed if the current frame is in an epilogue - | |
3585 | even if they are in some other frame, our view of the stack | |
3586 | is likely to be wrong and frame_find_by_id could error out. */ | |
3587 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) | |
60e1c644 | 3588 | return WP_IGNORE; |
a0f49112 | 3589 | |
101dcfbe | 3590 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 3591 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
3592 | |
3593 | /* If we've gotten confused in the unwinder, we might have | |
3594 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
3595 | if (within_current_scope) |
3596 | { | |
3597 | struct symbol *function; | |
3598 | ||
3599 | function = get_frame_function (fr); | |
3600 | if (function == NULL | |
3601 | || !contained_in (b->exp_valid_block, | |
3602 | SYMBOL_BLOCK_VALUE (function))) | |
3603 | within_current_scope = 0; | |
3604 | } | |
69fbadd5 | 3605 | |
edb3359d | 3606 | if (within_current_scope) |
c906108c SS |
3607 | /* If we end up stopping, the current frame will get selected |
3608 | in normal_stop. So this call to select_frame won't affect | |
3609 | the user. */ | |
0f7d239c | 3610 | select_frame (fr); |
c906108c | 3611 | } |
c5aa993b | 3612 | |
c906108c SS |
3613 | if (within_current_scope) |
3614 | { | |
3615 | /* We use value_{,free_to_}mark because it could be a | |
3616 | *long* time before we return to the command level and | |
c5aa993b JM |
3617 | call free_all_values. We can't call free_all_values because |
3618 | we might be in the middle of evaluating a function call. */ | |
c906108c | 3619 | |
278cd55f | 3620 | struct value *mark = value_mark (); |
fa4727a6 DJ |
3621 | struct value *new_val; |
3622 | ||
3623 | fetch_watchpoint_value (b->exp, &new_val, NULL, NULL); | |
218d2fc6 TJB |
3624 | |
3625 | /* We use value_equal_contents instead of value_equal because the latter | |
3626 | coerces an array to a pointer, thus comparing just the address of the | |
3627 | array instead of its contents. This is not what we want. */ | |
fa4727a6 | 3628 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 3629 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 3630 | { |
fa4727a6 DJ |
3631 | if (new_val != NULL) |
3632 | { | |
3633 | release_value (new_val); | |
3634 | value_free_to_mark (mark); | |
3635 | } | |
c906108c SS |
3636 | bs->old_val = b->val; |
3637 | b->val = new_val; | |
fa4727a6 | 3638 | b->val_valid = 1; |
c906108c SS |
3639 | return WP_VALUE_CHANGED; |
3640 | } | |
3641 | else | |
3642 | { | |
60e1c644 | 3643 | /* Nothing changed. */ |
c906108c | 3644 | value_free_to_mark (mark); |
c906108c SS |
3645 | return WP_VALUE_NOT_CHANGED; |
3646 | } | |
3647 | } | |
3648 | else | |
3649 | { | |
3650 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
3651 | if we temporarily ignored the watchpoint, then when |
3652 | we reenter the block in which it is valid it contains | |
3653 | garbage (in the case of a function, it may have two | |
3654 | garbage values, one before and one after the prologue). | |
3655 | So we can't even detect the first assignment to it and | |
3656 | watch after that (since the garbage may or may not equal | |
3657 | the first value assigned). */ | |
4ce44c66 JM |
3658 | /* We print all the stop information in print_it_typical(), but |
3659 | in this case, by the time we call print_it_typical() this bp | |
3660 | will be deleted already. So we have no choice but print the | |
3661 | information here. */ | |
9dc5e2a9 | 3662 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3663 | ui_out_field_string |
3664 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 3665 | ui_out_text (uiout, "\nWatchpoint "); |
4f8d1dc6 | 3666 | ui_out_field_int (uiout, "wpnum", b->number); |
8b93c638 JM |
3667 | ui_out_text (uiout, " deleted because the program has left the block in\n\ |
3668 | which its expression is valid.\n"); | |
4ce44c66 | 3669 | |
c906108c | 3670 | if (b->related_breakpoint) |
60e1c644 PA |
3671 | { |
3672 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
3673 | b->related_breakpoint->related_breakpoint = NULL; | |
3674 | b->related_breakpoint = NULL; | |
3675 | } | |
b5de0fa7 | 3676 | b->disposition = disp_del_at_next_stop; |
c906108c SS |
3677 | |
3678 | return WP_DELETED; | |
3679 | } | |
3680 | } | |
3681 | ||
18a18393 VP |
3682 | /* Return true if it looks like target has stopped due to hitting |
3683 | breakpoint location BL. This function does not check if we | |
3684 | should stop, only if BL explains the stop. */ | |
3685 | static int | |
6c95b8df PA |
3686 | bpstat_check_location (const struct bp_location *bl, |
3687 | struct address_space *aspace, CORE_ADDR bp_addr) | |
18a18393 VP |
3688 | { |
3689 | struct breakpoint *b = bl->owner; | |
3690 | ||
e8595ef6 SS |
3691 | /* By definition, the inferior does not report stops at |
3692 | tracepoints. */ | |
7a697b8d | 3693 | if (tracepoint_type (b)) |
e8595ef6 SS |
3694 | return 0; |
3695 | ||
18a18393 VP |
3696 | if (b->type != bp_watchpoint |
3697 | && b->type != bp_hardware_watchpoint | |
3698 | && b->type != bp_read_watchpoint | |
3699 | && b->type != bp_access_watchpoint | |
3700 | && b->type != bp_hardware_breakpoint | |
fe798b75 | 3701 | && b->type != bp_catchpoint) /* a non-watchpoint bp */ |
18a18393 | 3702 | { |
6c95b8df PA |
3703 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
3704 | aspace, bp_addr)) | |
18a18393 VP |
3705 | return 0; |
3706 | if (overlay_debugging /* unmapped overlay section */ | |
3707 | && section_is_overlay (bl->section) | |
3708 | && !section_is_mapped (bl->section)) | |
3709 | return 0; | |
3710 | } | |
3711 | ||
3712 | /* Continuable hardware watchpoints are treated as non-existent if the | |
3713 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
3714 | some data address). Otherwise gdb won't stop on a break instruction | |
3715 | in the code (not from a breakpoint) when a hardware watchpoint has | |
3716 | been defined. Also skip watchpoints which we know did not trigger | |
3717 | (did not match the data address). */ | |
3718 | ||
3719 | if ((b->type == bp_hardware_watchpoint | |
3720 | || b->type == bp_read_watchpoint | |
3721 | || b->type == bp_access_watchpoint) | |
3722 | && b->watchpoint_triggered == watch_triggered_no) | |
3723 | return 0; | |
3724 | ||
3725 | if (b->type == bp_hardware_breakpoint) | |
3726 | { | |
3727 | if (bl->address != bp_addr) | |
3728 | return 0; | |
3729 | if (overlay_debugging /* unmapped overlay section */ | |
3730 | && section_is_overlay (bl->section) | |
3731 | && !section_is_mapped (bl->section)) | |
3732 | return 0; | |
3733 | } | |
ce78b96d | 3734 | |
ce78b96d JB |
3735 | if (b->type == bp_catchpoint) |
3736 | { | |
3737 | gdb_assert (b->ops != NULL && b->ops->breakpoint_hit != NULL); | |
3738 | if (!b->ops->breakpoint_hit (b)) | |
3739 | return 0; | |
3740 | } | |
3741 | ||
18a18393 VP |
3742 | return 1; |
3743 | } | |
3744 | ||
3745 | /* If BS refers to a watchpoint, determine if the watched values | |
3746 | has actually changed, and we should stop. If not, set BS->stop | |
3747 | to 0. */ | |
3748 | static void | |
3749 | bpstat_check_watchpoint (bpstat bs) | |
3750 | { | |
3751 | const struct bp_location *bl = bs->breakpoint_at; | |
3752 | struct breakpoint *b = bl->owner; | |
3753 | ||
3754 | if (b->type == bp_watchpoint | |
3755 | || b->type == bp_read_watchpoint | |
3756 | || b->type == bp_access_watchpoint | |
3757 | || b->type == bp_hardware_watchpoint) | |
3758 | { | |
3759 | CORE_ADDR addr; | |
3760 | struct value *v; | |
3761 | int must_check_value = 0; | |
3762 | ||
3763 | if (b->type == bp_watchpoint) | |
3764 | /* For a software watchpoint, we must always check the | |
3765 | watched value. */ | |
3766 | must_check_value = 1; | |
3767 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
3768 | /* We have a hardware watchpoint (read, write, or access) | |
3769 | and the target earlier reported an address watched by | |
3770 | this watchpoint. */ | |
3771 | must_check_value = 1; | |
3772 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3773 | && b->type == bp_hardware_watchpoint) | |
3774 | /* We were stopped by a hardware watchpoint, but the target could | |
3775 | not report the data address. We must check the watchpoint's | |
3776 | value. Access and read watchpoints are out of luck; without | |
3777 | a data address, we can't figure it out. */ | |
3778 | must_check_value = 1; | |
3779 | ||
3780 | if (must_check_value) | |
3781 | { | |
3782 | char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3783 | b->number); | |
3784 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
3785 | int e = catch_errors (watchpoint_check, bs, message, | |
3786 | RETURN_MASK_ALL); | |
3787 | do_cleanups (cleanups); | |
3788 | switch (e) | |
3789 | { | |
3790 | case WP_DELETED: | |
3791 | /* We've already printed what needs to be printed. */ | |
3792 | bs->print_it = print_it_done; | |
3793 | /* Stop. */ | |
3794 | break; | |
60e1c644 PA |
3795 | case WP_IGNORE: |
3796 | bs->print_it = print_it_noop; | |
3797 | bs->stop = 0; | |
3798 | break; | |
18a18393 VP |
3799 | case WP_VALUE_CHANGED: |
3800 | if (b->type == bp_read_watchpoint) | |
3801 | { | |
85d721b8 PA |
3802 | /* There are two cases to consider here: |
3803 | ||
3804 | 1. we're watching the triggered memory for reads. | |
3805 | In that case, trust the target, and always report | |
3806 | the watchpoint hit to the user. Even though | |
3807 | reads don't cause value changes, the value may | |
3808 | have changed since the last time it was read, and | |
3809 | since we're not trapping writes, we will not see | |
3810 | those, and as such we should ignore our notion of | |
3811 | old value. | |
3812 | ||
3813 | 2. we're watching the triggered memory for both | |
3814 | reads and writes. There are two ways this may | |
3815 | happen: | |
3816 | ||
3817 | 2.1. this is a target that can't break on data | |
3818 | reads only, but can break on accesses (reads or | |
3819 | writes), such as e.g., x86. We detect this case | |
3820 | at the time we try to insert read watchpoints. | |
3821 | ||
3822 | 2.2. otherwise, the target supports read | |
3823 | watchpoints, but, the user set an access or write | |
3824 | watchpoint watching the same memory as this read | |
3825 | watchpoint. | |
3826 | ||
3827 | If we're watching memory writes as well as reads, | |
3828 | ignore watchpoint hits when we find that the | |
3829 | value hasn't changed, as reads don't cause | |
3830 | changes. This still gives false positives when | |
3831 | the program writes the same value to memory as | |
3832 | what there was already in memory (we will confuse | |
3833 | it for a read), but it's much better than | |
3834 | nothing. */ | |
3835 | ||
3836 | int other_write_watchpoint = 0; | |
3837 | ||
3838 | if (bl->watchpoint_type == hw_read) | |
3839 | { | |
3840 | struct breakpoint *other_b; | |
3841 | ||
3842 | ALL_BREAKPOINTS (other_b) | |
3843 | if ((other_b->type == bp_hardware_watchpoint | |
3844 | || other_b->type == bp_access_watchpoint) | |
3845 | && (other_b->watchpoint_triggered | |
3846 | == watch_triggered_yes)) | |
3847 | { | |
3848 | other_write_watchpoint = 1; | |
3849 | break; | |
3850 | } | |
3851 | } | |
3852 | ||
3853 | if (other_write_watchpoint | |
3854 | || bl->watchpoint_type == hw_access) | |
3855 | { | |
3856 | /* We're watching the same memory for writes, | |
3857 | and the value changed since the last time we | |
3858 | updated it, so this trap must be for a write. | |
3859 | Ignore it. */ | |
3860 | bs->print_it = print_it_noop; | |
3861 | bs->stop = 0; | |
3862 | } | |
18a18393 VP |
3863 | } |
3864 | break; | |
3865 | case WP_VALUE_NOT_CHANGED: | |
3866 | if (b->type == bp_hardware_watchpoint | |
3867 | || b->type == bp_watchpoint) | |
3868 | { | |
3869 | /* Don't stop: write watchpoints shouldn't fire if | |
3870 | the value hasn't changed. */ | |
3871 | bs->print_it = print_it_noop; | |
3872 | bs->stop = 0; | |
3873 | } | |
3874 | /* Stop. */ | |
3875 | break; | |
3876 | default: | |
3877 | /* Can't happen. */ | |
3878 | case 0: | |
3879 | /* Error from catch_errors. */ | |
3880 | printf_filtered (_("Watchpoint %d deleted.\n"), b->number); | |
3881 | if (b->related_breakpoint) | |
3882 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
3883 | b->disposition = disp_del_at_next_stop; | |
3884 | /* We've already printed what needs to be printed. */ | |
3885 | bs->print_it = print_it_done; | |
3886 | break; | |
3887 | } | |
3888 | } | |
3889 | else /* must_check_value == 0 */ | |
3890 | { | |
3891 | /* This is a case where some watchpoint(s) triggered, but | |
3892 | not at the address of this watchpoint, or else no | |
3893 | watchpoint triggered after all. So don't print | |
3894 | anything for this watchpoint. */ | |
3895 | bs->print_it = print_it_noop; | |
3896 | bs->stop = 0; | |
3897 | } | |
3898 | } | |
3899 | } | |
3900 | ||
3901 | ||
3902 | /* Check conditions (condition proper, frame, thread and ignore count) | |
3903 | of breakpoint referred to by BS. If we should not stop for this | |
3904 | breakpoint, set BS->stop to 0. */ | |
3905 | static void | |
3906 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
3907 | { | |
3908 | int thread_id = pid_to_thread_id (ptid); | |
3909 | const struct bp_location *bl = bs->breakpoint_at; | |
3910 | struct breakpoint *b = bl->owner; | |
3911 | ||
3912 | if (frame_id_p (b->frame_id) | |
edb3359d | 3913 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 VP |
3914 | bs->stop = 0; |
3915 | else if (bs->stop) | |
3916 | { | |
3917 | int value_is_zero = 0; | |
60e1c644 PA |
3918 | struct expression *cond; |
3919 | ||
18a18393 VP |
3920 | /* If this is a scope breakpoint, mark the associated |
3921 | watchpoint as triggered so that we will handle the | |
3922 | out-of-scope event. We'll get to the watchpoint next | |
3923 | iteration. */ | |
3924 | if (b->type == bp_watchpoint_scope) | |
3925 | b->related_breakpoint->watchpoint_triggered = watch_triggered_yes; | |
60e1c644 PA |
3926 | |
3927 | if (is_watchpoint (b)) | |
3928 | cond = b->cond_exp; | |
3929 | else | |
3930 | cond = bl->cond; | |
3931 | ||
3932 | if (cond && bl->owner->disposition != disp_del_at_next_stop) | |
18a18393 | 3933 | { |
60e1c644 PA |
3934 | int within_current_scope = 1; |
3935 | ||
c5bc3a77 DJ |
3936 | /* We use value_mark and value_free_to_mark because it could |
3937 | be a long time before we return to the command level and | |
3938 | call free_all_values. We can't call free_all_values | |
3939 | because we might be in the middle of evaluating a | |
3940 | function call. */ | |
3941 | struct value *mark = value_mark (); | |
3942 | ||
edb3359d DJ |
3943 | /* Need to select the frame, with all that implies so that |
3944 | the conditions will have the right context. Because we | |
3945 | use the frame, we will not see an inlined function's | |
3946 | variables when we arrive at a breakpoint at the start | |
3947 | of the inlined function; the current frame will be the | |
3948 | call site. */ | |
60e1c644 PA |
3949 | if (!is_watchpoint (b) || b->cond_exp_valid_block == NULL) |
3950 | select_frame (get_current_frame ()); | |
3951 | else | |
3952 | { | |
3953 | struct frame_info *frame; | |
3954 | ||
3955 | /* For local watchpoint expressions, which particular | |
3956 | instance of a local is being watched matters, so we | |
3957 | keep track of the frame to evaluate the expression | |
3958 | in. To evaluate the condition however, it doesn't | |
3959 | really matter which instantiation of the function | |
3960 | where the condition makes sense triggers the | |
3961 | watchpoint. This allows an expression like "watch | |
3962 | global if q > 10" set in `func', catch writes to | |
3963 | global on all threads that call `func', or catch | |
3964 | writes on all recursive calls of `func' by a single | |
3965 | thread. We simply always evaluate the condition in | |
3966 | the innermost frame that's executing where it makes | |
3967 | sense to evaluate the condition. It seems | |
3968 | intuitive. */ | |
3969 | frame = block_innermost_frame (b->cond_exp_valid_block); | |
3970 | if (frame != NULL) | |
3971 | select_frame (frame); | |
3972 | else | |
3973 | within_current_scope = 0; | |
3974 | } | |
3975 | if (within_current_scope) | |
3976 | value_is_zero | |
3977 | = catch_errors (breakpoint_cond_eval, cond, | |
3978 | "Error in testing breakpoint condition:\n", | |
3979 | RETURN_MASK_ALL); | |
3980 | else | |
3981 | { | |
3982 | warning (_("Watchpoint condition cannot be tested " | |
3983 | "in the current scope")); | |
3984 | /* If we failed to set the right context for this | |
3985 | watchpoint, unconditionally report it. */ | |
3986 | value_is_zero = 0; | |
3987 | } | |
18a18393 | 3988 | /* FIXME-someday, should give breakpoint # */ |
c5bc3a77 | 3989 | value_free_to_mark (mark); |
18a18393 | 3990 | } |
60e1c644 PA |
3991 | |
3992 | if (cond && value_is_zero) | |
18a18393 VP |
3993 | { |
3994 | bs->stop = 0; | |
3995 | } | |
3996 | else if (b->thread != -1 && b->thread != thread_id) | |
3997 | { | |
3998 | bs->stop = 0; | |
3999 | } | |
4000 | else if (b->ignore_count > 0) | |
4001 | { | |
4002 | b->ignore_count--; | |
4003 | annotate_ignore_count_change (); | |
4004 | bs->stop = 0; | |
4005 | /* Increase the hit count even though we don't | |
4006 | stop. */ | |
4007 | ++(b->hit_count); | |
4008 | } | |
4009 | } | |
4010 | } | |
4011 | ||
4012 | ||
9709f61c | 4013 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 4014 | BP_ADDR in thread PTID. |
c906108c | 4015 | |
d983da9c | 4016 | Determine whether we stopped at a breakpoint, etc, or whether we |
c906108c SS |
4017 | don't understand this stop. Result is a chain of bpstat's such that: |
4018 | ||
c5aa993b | 4019 | if we don't understand the stop, the result is a null pointer. |
c906108c | 4020 | |
c5aa993b | 4021 | if we understand why we stopped, the result is not null. |
c906108c | 4022 | |
c5aa993b JM |
4023 | Each element of the chain refers to a particular breakpoint or |
4024 | watchpoint at which we have stopped. (We may have stopped for | |
4025 | several reasons concurrently.) | |
c906108c | 4026 | |
c5aa993b JM |
4027 | Each element of the chain has valid next, breakpoint_at, |
4028 | commands, FIXME??? fields. */ | |
c906108c SS |
4029 | |
4030 | bpstat | |
6c95b8df PA |
4031 | bpstat_stop_status (struct address_space *aspace, |
4032 | CORE_ADDR bp_addr, ptid_t ptid) | |
c906108c | 4033 | { |
0d381245 | 4034 | struct breakpoint *b = NULL; |
876fa593 | 4035 | struct bp_location *bl, **blp_tmp; |
20874c92 | 4036 | struct bp_location *loc; |
c906108c SS |
4037 | /* Root of the chain of bpstat's */ |
4038 | struct bpstats root_bs[1]; | |
4039 | /* Pointer to the last thing in the chain currently. */ | |
4040 | bpstat bs = root_bs; | |
20874c92 | 4041 | int ix; |
429374b8 | 4042 | int need_remove_insert; |
c906108c | 4043 | |
429374b8 JK |
4044 | /* ALL_BP_LOCATIONS iteration would break across |
4045 | update_global_location_list possibly executed by | |
4046 | bpstat_check_breakpoint_conditions's inferior call. */ | |
c5aa993b | 4047 | |
429374b8 JK |
4048 | ALL_BREAKPOINTS (b) |
4049 | { | |
4050 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) | |
4051 | continue; | |
a5606eee | 4052 | |
429374b8 JK |
4053 | for (bl = b->loc; bl != NULL; bl = bl->next) |
4054 | { | |
4055 | /* For hardware watchpoints, we look only at the first location. | |
4056 | The watchpoint_check function will work on entire expression, | |
4057 | not the individual locations. For read watchopints, the | |
4058 | watchpoints_triggered function have checked all locations | |
4059 | already. */ | |
4060 | if (b->type == bp_hardware_watchpoint && bl != b->loc) | |
4061 | break; | |
18a18393 | 4062 | |
429374b8 JK |
4063 | if (bl->shlib_disabled) |
4064 | continue; | |
c5aa993b | 4065 | |
429374b8 JK |
4066 | if (!bpstat_check_location (bl, aspace, bp_addr)) |
4067 | continue; | |
c5aa993b | 4068 | |
429374b8 | 4069 | /* Come here if it's a watchpoint, or if the break address matches */ |
c5aa993b | 4070 | |
429374b8 | 4071 | bs = bpstat_alloc (bl, bs); /* Alloc a bpstat to explain stop */ |
c5aa993b | 4072 | |
429374b8 JK |
4073 | /* Assume we stop. Should we find watchpoint that is not actually |
4074 | triggered, or if condition of breakpoint is false, we'll reset | |
4075 | 'stop' to 0. */ | |
4076 | bs->stop = 1; | |
4077 | bs->print = 1; | |
d983da9c | 4078 | |
429374b8 JK |
4079 | bpstat_check_watchpoint (bs); |
4080 | if (!bs->stop) | |
4081 | continue; | |
18a18393 | 4082 | |
429374b8 | 4083 | if (b->type == bp_thread_event || b->type == bp_overlay_event |
aa7d318d TT |
4084 | || b->type == bp_longjmp_master |
4085 | || b->type == bp_std_terminate_master) | |
429374b8 JK |
4086 | /* We do not stop for these. */ |
4087 | bs->stop = 0; | |
4088 | else | |
4089 | bpstat_check_breakpoint_conditions (bs, ptid); | |
4090 | ||
4091 | if (bs->stop) | |
4092 | { | |
4093 | ++(b->hit_count); | |
c906108c | 4094 | |
429374b8 JK |
4095 | /* We will stop here */ |
4096 | if (b->disposition == disp_disable) | |
4097 | { | |
4098 | if (b->enable_state != bp_permanent) | |
4099 | b->enable_state = bp_disabled; | |
4100 | update_global_location_list (0); | |
4101 | } | |
4102 | if (b->silent) | |
4103 | bs->print = 0; | |
4104 | bs->commands = b->commands; | |
9add0f1b TT |
4105 | incref_counted_command_line (bs->commands); |
4106 | bs->commands_left = bs->commands ? bs->commands->commands : NULL; | |
4107 | if (bs->commands_left | |
4108 | && (strcmp ("silent", bs->commands_left->line) == 0 | |
4109 | || (xdb_commands | |
4110 | && strcmp ("Q", | |
4111 | bs->commands_left->line) == 0))) | |
429374b8 | 4112 | { |
9add0f1b | 4113 | bs->commands_left = bs->commands_left->next; |
429374b8 JK |
4114 | bs->print = 0; |
4115 | } | |
429374b8 JK |
4116 | } |
4117 | ||
4118 | /* Print nothing for this entry if we dont stop or dont print. */ | |
4119 | if (bs->stop == 0 || bs->print == 0) | |
4120 | bs->print_it = print_it_noop; | |
4121 | } | |
4122 | } | |
876fa593 | 4123 | |
20874c92 VP |
4124 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
4125 | { | |
6c95b8df PA |
4126 | if (breakpoint_address_match (loc->pspace->aspace, loc->address, |
4127 | aspace, bp_addr)) | |
20874c92 VP |
4128 | { |
4129 | bs = bpstat_alloc (loc, bs); | |
4130 | /* For hits of moribund locations, we should just proceed. */ | |
4131 | bs->stop = 0; | |
4132 | bs->print = 0; | |
4133 | bs->print_it = print_it_noop; | |
4134 | } | |
4135 | } | |
4136 | ||
c906108c | 4137 | bs->next = NULL; /* Terminate the chain */ |
c906108c | 4138 | |
d983da9c DJ |
4139 | /* If we aren't stopping, the value of some hardware watchpoint may |
4140 | not have changed, but the intermediate memory locations we are | |
4141 | watching may have. Don't bother if we're stopping; this will get | |
4142 | done later. */ | |
4143 | for (bs = root_bs->next; bs != NULL; bs = bs->next) | |
4144 | if (bs->stop) | |
4145 | break; | |
4146 | ||
d832cb68 | 4147 | need_remove_insert = 0; |
d983da9c DJ |
4148 | if (bs == NULL) |
4149 | for (bs = root_bs->next; bs != NULL; bs = bs->next) | |
4150 | if (!bs->stop | |
20874c92 | 4151 | && bs->breakpoint_at->owner |
2d134ed3 | 4152 | && is_hardware_watchpoint (bs->breakpoint_at->owner)) |
d983da9c | 4153 | { |
2d134ed3 PA |
4154 | update_watchpoint (bs->breakpoint_at->owner, 0 /* don't reparse. */); |
4155 | /* Updating watchpoints invalidates bs->breakpoint_at. | |
4156 | Prevent further code from trying to use it. */ | |
a5606eee | 4157 | bs->breakpoint_at = NULL; |
d832cb68 | 4158 | need_remove_insert = 1; |
d983da9c DJ |
4159 | } |
4160 | ||
d832cb68 | 4161 | if (need_remove_insert) |
2d134ed3 | 4162 | update_global_location_list (1); |
d832cb68 | 4163 | |
d983da9c | 4164 | return root_bs->next; |
c906108c SS |
4165 | } |
4166 | \f | |
4167 | /* Tell what to do about this bpstat. */ | |
4168 | struct bpstat_what | |
fba45db2 | 4169 | bpstat_what (bpstat bs) |
c906108c SS |
4170 | { |
4171 | /* Classify each bpstat as one of the following. */ | |
c5aa993b JM |
4172 | enum class |
4173 | { | |
4174 | /* This bpstat element has no effect on the main_action. */ | |
4175 | no_effect = 0, | |
4176 | ||
4177 | /* There was a watchpoint, stop but don't print. */ | |
4178 | wp_silent, | |
c906108c | 4179 | |
c5aa993b JM |
4180 | /* There was a watchpoint, stop and print. */ |
4181 | wp_noisy, | |
c906108c | 4182 | |
c5aa993b JM |
4183 | /* There was a breakpoint but we're not stopping. */ |
4184 | bp_nostop, | |
c906108c | 4185 | |
c5aa993b JM |
4186 | /* There was a breakpoint, stop but don't print. */ |
4187 | bp_silent, | |
c906108c | 4188 | |
c5aa993b JM |
4189 | /* There was a breakpoint, stop and print. */ |
4190 | bp_noisy, | |
c906108c | 4191 | |
c5aa993b JM |
4192 | /* We hit the longjmp breakpoint. */ |
4193 | long_jump, | |
c906108c | 4194 | |
c5aa993b JM |
4195 | /* We hit the longjmp_resume breakpoint. */ |
4196 | long_resume, | |
c906108c | 4197 | |
c5aa993b JM |
4198 | /* We hit the step_resume breakpoint. */ |
4199 | step_resume, | |
c906108c | 4200 | |
c5aa993b JM |
4201 | /* We hit the shared library event breakpoint. */ |
4202 | shlib_event, | |
c906108c | 4203 | |
4efc6507 DE |
4204 | /* We hit the jit event breakpoint. */ |
4205 | jit_event, | |
4206 | ||
c5aa993b JM |
4207 | /* This is just used to count how many enums there are. */ |
4208 | class_last | |
c906108c SS |
4209 | }; |
4210 | ||
4211 | /* Here is the table which drives this routine. So that we can | |
4212 | format it pretty, we define some abbreviations for the | |
4213 | enum bpstat_what codes. */ | |
4214 | #define kc BPSTAT_WHAT_KEEP_CHECKING | |
4215 | #define ss BPSTAT_WHAT_STOP_SILENT | |
4216 | #define sn BPSTAT_WHAT_STOP_NOISY | |
4217 | #define sgl BPSTAT_WHAT_SINGLE | |
4218 | #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME | |
4219 | #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME | |
c906108c | 4220 | #define sr BPSTAT_WHAT_STEP_RESUME |
c906108c | 4221 | #define shl BPSTAT_WHAT_CHECK_SHLIBS |
4efc6507 | 4222 | #define jit BPSTAT_WHAT_CHECK_JIT |
c906108c SS |
4223 | |
4224 | /* "Can't happen." Might want to print an error message. | |
4225 | abort() is not out of the question, but chances are GDB is just | |
4226 | a bit confused, not unusable. */ | |
4227 | #define err BPSTAT_WHAT_STOP_NOISY | |
4228 | ||
4229 | /* Given an old action and a class, come up with a new action. */ | |
4230 | /* One interesting property of this table is that wp_silent is the same | |
4231 | as bp_silent and wp_noisy is the same as bp_noisy. That is because | |
4232 | after stopping, the check for whether to step over a breakpoint | |
4233 | (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without | |
53a5351d JM |
4234 | reference to how we stopped. We retain separate wp_silent and |
4235 | bp_silent codes in case we want to change that someday. | |
43ff13b4 JM |
4236 | |
4237 | Another possibly interesting property of this table is that | |
4238 | there's a partial ordering, priority-like, of the actions. Once | |
4239 | you've decided that some action is appropriate, you'll never go | |
4240 | back and decide something of a lower priority is better. The | |
4241 | ordering is: | |
4242 | ||
4efc6507 DE |
4243 | kc < jit clr sgl shl slr sn sr ss |
4244 | sgl < jit shl slr sn sr ss | |
4245 | slr < jit err shl sn sr ss | |
4246 | clr < jit err shl sn sr ss | |
4247 | ss < jit shl sn sr | |
4248 | sn < jit shl sr | |
4249 | jit < shl sr | |
d81191fc | 4250 | shl < sr |
4d5b2cd7 | 4251 | sr < |
c5aa993b | 4252 | |
43ff13b4 JM |
4253 | What I think this means is that we don't need a damned table |
4254 | here. If you just put the rows and columns in the right order, | |
4255 | it'd look awfully regular. We could simply walk the bpstat list | |
4256 | and choose the highest priority action we find, with a little | |
78b6a731 | 4257 | logic to handle the 'err' cases. */ |
c906108c SS |
4258 | |
4259 | /* step_resume entries: a step resume breakpoint overrides another | |
4260 | breakpoint of signal handling (see comment in wait_for_inferior | |
fcf70625 | 4261 | at where we set the step_resume breakpoint). */ |
c906108c SS |
4262 | |
4263 | static const enum bpstat_what_main_action | |
c5aa993b JM |
4264 | table[(int) class_last][(int) BPSTAT_WHAT_LAST] = |
4265 | { | |
4266 | /* old action */ | |
4efc6507 DE |
4267 | /* kc ss sn sgl slr clr sr shl jit */ |
4268 | /* no_effect */ {kc, ss, sn, sgl, slr, clr, sr, shl, jit}, | |
4269 | /* wp_silent */ {ss, ss, sn, ss, ss, ss, sr, shl, jit}, | |
4270 | /* wp_noisy */ {sn, sn, sn, sn, sn, sn, sr, shl, jit}, | |
4271 | /* bp_nostop */ {sgl, ss, sn, sgl, slr, slr, sr, shl, jit}, | |
4272 | /* bp_silent */ {ss, ss, sn, ss, ss, ss, sr, shl, jit}, | |
4273 | /* bp_noisy */ {sn, sn, sn, sn, sn, sn, sr, shl, jit}, | |
4274 | /* long_jump */ {slr, ss, sn, slr, slr, err, sr, shl, jit}, | |
4275 | /* long_resume */ {clr, ss, sn, err, err, err, sr, shl, jit}, | |
4276 | /* step_resume */ {sr, sr, sr, sr, sr, sr, sr, sr, sr }, | |
4277 | /* shlib */ {shl, shl, shl, shl, shl, shl, sr, shl, shl}, | |
4278 | /* jit_event */ {jit, jit, jit, jit, jit, jit, sr, jit, jit} | |
c5aa993b | 4279 | }; |
c906108c SS |
4280 | |
4281 | #undef kc | |
4282 | #undef ss | |
4283 | #undef sn | |
4284 | #undef sgl | |
4285 | #undef slr | |
4286 | #undef clr | |
c906108c SS |
4287 | #undef err |
4288 | #undef sr | |
4289 | #undef ts | |
4290 | #undef shl | |
4efc6507 | 4291 | #undef jit |
c906108c SS |
4292 | enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING; |
4293 | struct bpstat_what retval; | |
4294 | ||
aa7d318d | 4295 | retval.call_dummy = STOP_NONE; |
c906108c SS |
4296 | for (; bs != NULL; bs = bs->next) |
4297 | { | |
4298 | enum class bs_class = no_effect; | |
4299 | if (bs->breakpoint_at == NULL) | |
4300 | /* I suspect this can happen if it was a momentary breakpoint | |
4301 | which has since been deleted. */ | |
4302 | continue; | |
20874c92 VP |
4303 | if (bs->breakpoint_at->owner == NULL) |
4304 | bs_class = bp_nostop; | |
4305 | else | |
4f8d1dc6 | 4306 | switch (bs->breakpoint_at->owner->type) |
c906108c SS |
4307 | { |
4308 | case bp_none: | |
4309 | continue; | |
4310 | ||
4311 | case bp_breakpoint: | |
4312 | case bp_hardware_breakpoint: | |
4313 | case bp_until: | |
4314 | case bp_finish: | |
4315 | if (bs->stop) | |
4316 | { | |
4317 | if (bs->print) | |
4318 | bs_class = bp_noisy; | |
4319 | else | |
4320 | bs_class = bp_silent; | |
4321 | } | |
4322 | else | |
4323 | bs_class = bp_nostop; | |
4324 | break; | |
4325 | case bp_watchpoint: | |
4326 | case bp_hardware_watchpoint: | |
4327 | case bp_read_watchpoint: | |
4328 | case bp_access_watchpoint: | |
4329 | if (bs->stop) | |
4330 | { | |
4331 | if (bs->print) | |
4332 | bs_class = wp_noisy; | |
4333 | else | |
4334 | bs_class = wp_silent; | |
4335 | } | |
4336 | else | |
53a5351d JM |
4337 | /* There was a watchpoint, but we're not stopping. |
4338 | This requires no further action. */ | |
c906108c SS |
4339 | bs_class = no_effect; |
4340 | break; | |
4341 | case bp_longjmp: | |
4342 | bs_class = long_jump; | |
4343 | break; | |
4344 | case bp_longjmp_resume: | |
4345 | bs_class = long_resume; | |
4346 | break; | |
4347 | case bp_step_resume: | |
4348 | if (bs->stop) | |
4349 | { | |
4350 | bs_class = step_resume; | |
4351 | } | |
4352 | else | |
4353 | /* It is for the wrong frame. */ | |
4354 | bs_class = bp_nostop; | |
4355 | break; | |
c906108c SS |
4356 | case bp_watchpoint_scope: |
4357 | bs_class = bp_nostop; | |
4358 | break; | |
c5aa993b JM |
4359 | case bp_shlib_event: |
4360 | bs_class = shlib_event; | |
4361 | break; | |
4efc6507 DE |
4362 | case bp_jit_event: |
4363 | bs_class = jit_event; | |
4364 | break; | |
c4093a6a | 4365 | case bp_thread_event: |
1900040c | 4366 | case bp_overlay_event: |
0fd8e87f | 4367 | case bp_longjmp_master: |
aa7d318d | 4368 | case bp_std_terminate_master: |
c4093a6a JM |
4369 | bs_class = bp_nostop; |
4370 | break; | |
ce78b96d | 4371 | case bp_catchpoint: |
c5aa993b JM |
4372 | if (bs->stop) |
4373 | { | |
4374 | if (bs->print) | |
4375 | bs_class = bp_noisy; | |
4376 | else | |
4377 | bs_class = bp_silent; | |
4378 | } | |
4379 | else | |
53a5351d JM |
4380 | /* There was a catchpoint, but we're not stopping. |
4381 | This requires no further action. */ | |
c5aa993b JM |
4382 | bs_class = no_effect; |
4383 | break; | |
c906108c | 4384 | case bp_call_dummy: |
53a5351d JM |
4385 | /* Make sure the action is stop (silent or noisy), |
4386 | so infrun.c pops the dummy frame. */ | |
c906108c | 4387 | bs_class = bp_silent; |
aa7d318d TT |
4388 | retval.call_dummy = STOP_STACK_DUMMY; |
4389 | break; | |
4390 | case bp_std_terminate: | |
4391 | /* Make sure the action is stop (silent or noisy), | |
4392 | so infrun.c pops the dummy frame. */ | |
4393 | bs_class = bp_silent; | |
4394 | retval.call_dummy = STOP_STD_TERMINATE; | |
c906108c | 4395 | break; |
1042e4c0 | 4396 | case bp_tracepoint: |
7a697b8d | 4397 | case bp_fast_tracepoint: |
1042e4c0 SS |
4398 | /* Tracepoint hits should not be reported back to GDB, and |
4399 | if one got through somehow, it should have been filtered | |
4400 | out already. */ | |
4401 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 4402 | _("bpstat_what: tracepoint encountered")); |
1042e4c0 | 4403 | break; |
c906108c | 4404 | } |
c5aa993b | 4405 | current_action = table[(int) bs_class][(int) current_action]; |
c906108c SS |
4406 | } |
4407 | retval.main_action = current_action; | |
4408 | return retval; | |
4409 | } | |
4410 | ||
4411 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
4412 | without hardware support). This isn't related to a specific bpstat, | |
4413 | just to things like whether watchpoints are set. */ | |
4414 | ||
c5aa993b | 4415 | int |
fba45db2 | 4416 | bpstat_should_step (void) |
c906108c SS |
4417 | { |
4418 | struct breakpoint *b; | |
4419 | ALL_BREAKPOINTS (b) | |
717a8278 | 4420 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 4421 | return 1; |
c906108c SS |
4422 | return 0; |
4423 | } | |
4424 | ||
67822962 PA |
4425 | int |
4426 | bpstat_causes_stop (bpstat bs) | |
4427 | { | |
4428 | for (; bs != NULL; bs = bs->next) | |
4429 | if (bs->stop) | |
4430 | return 1; | |
4431 | ||
4432 | return 0; | |
4433 | } | |
4434 | ||
c906108c | 4435 | \f |
c5aa993b | 4436 | |
859825b8 JK |
4437 | /* Print the LOC location out of the list of B->LOC locations. */ |
4438 | ||
0d381245 VP |
4439 | static void print_breakpoint_location (struct breakpoint *b, |
4440 | struct bp_location *loc, | |
4441 | char *wrap_indent, | |
4442 | struct ui_stream *stb) | |
4443 | { | |
6c95b8df PA |
4444 | struct cleanup *old_chain = save_current_program_space (); |
4445 | ||
859825b8 JK |
4446 | if (loc != NULL && loc->shlib_disabled) |
4447 | loc = NULL; | |
4448 | ||
6c95b8df PA |
4449 | if (loc != NULL) |
4450 | set_current_program_space (loc->pspace); | |
4451 | ||
859825b8 | 4452 | if (b->source_file && loc) |
0d381245 VP |
4453 | { |
4454 | struct symbol *sym | |
4455 | = find_pc_sect_function (loc->address, loc->section); | |
4456 | if (sym) | |
4457 | { | |
4458 | ui_out_text (uiout, "in "); | |
4459 | ui_out_field_string (uiout, "func", | |
4460 | SYMBOL_PRINT_NAME (sym)); | |
4461 | ui_out_wrap_hint (uiout, wrap_indent); | |
4462 | ui_out_text (uiout, " at "); | |
4463 | } | |
4464 | ui_out_field_string (uiout, "file", b->source_file); | |
4465 | ui_out_text (uiout, ":"); | |
4466 | ||
4467 | if (ui_out_is_mi_like_p (uiout)) | |
4468 | { | |
4469 | struct symtab_and_line sal = find_pc_line (loc->address, 0); | |
4470 | char *fullname = symtab_to_fullname (sal.symtab); | |
4471 | ||
4472 | if (fullname) | |
4473 | ui_out_field_string (uiout, "fullname", fullname); | |
4474 | } | |
4475 | ||
4476 | ui_out_field_int (uiout, "line", b->line_number); | |
4477 | } | |
859825b8 | 4478 | else if (loc) |
0d381245 | 4479 | { |
22e722e1 DJ |
4480 | print_address_symbolic (loc->gdbarch, loc->address, stb->stream, |
4481 | demangle, ""); | |
0d381245 VP |
4482 | ui_out_field_stream (uiout, "at", stb); |
4483 | } | |
859825b8 JK |
4484 | else |
4485 | ui_out_field_string (uiout, "pending", b->addr_string); | |
6c95b8df PA |
4486 | |
4487 | do_cleanups (old_chain); | |
0d381245 VP |
4488 | } |
4489 | ||
c4093a6a | 4490 | /* Print B to gdb_stdout. */ |
c906108c | 4491 | static void |
0d381245 VP |
4492 | print_one_breakpoint_location (struct breakpoint *b, |
4493 | struct bp_location *loc, | |
4494 | int loc_number, | |
a6d9a66e | 4495 | struct bp_location **last_loc, |
6c95b8df PA |
4496 | int print_address_bits, |
4497 | int allflag) | |
c906108c | 4498 | { |
52f0bd74 AC |
4499 | struct command_line *l; |
4500 | struct symbol *sym; | |
c4093a6a JM |
4501 | struct ep_type_description |
4502 | { | |
4503 | enum bptype type; | |
4504 | char *description; | |
4505 | }; | |
4506 | static struct ep_type_description bptypes[] = | |
c906108c | 4507 | { |
c5aa993b JM |
4508 | {bp_none, "?deleted?"}, |
4509 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 4510 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
4511 | {bp_until, "until"}, |
4512 | {bp_finish, "finish"}, | |
4513 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 4514 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
4515 | {bp_read_watchpoint, "read watchpoint"}, |
4516 | {bp_access_watchpoint, "acc watchpoint"}, | |
4517 | {bp_longjmp, "longjmp"}, | |
4518 | {bp_longjmp_resume, "longjmp resume"}, | |
4519 | {bp_step_resume, "step resume"}, | |
c5aa993b JM |
4520 | {bp_watchpoint_scope, "watchpoint scope"}, |
4521 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 4522 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 4523 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 4524 | {bp_thread_event, "thread events"}, |
1900040c | 4525 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 4526 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 4527 | {bp_std_terminate_master, "std::terminate master"}, |
ce78b96d | 4528 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 4529 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 4530 | {bp_fast_tracepoint, "fast tracepoint"}, |
4efc6507 | 4531 | {bp_jit_event, "jit events"}, |
c5aa993b | 4532 | }; |
c4093a6a | 4533 | |
c2c6d25f | 4534 | static char bpenables[] = "nynny"; |
c906108c | 4535 | char wrap_indent[80]; |
8b93c638 JM |
4536 | struct ui_stream *stb = ui_out_stream_new (uiout); |
4537 | struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb); | |
3b31d625 | 4538 | struct cleanup *bkpt_chain; |
c906108c | 4539 | |
0d381245 VP |
4540 | int header_of_multiple = 0; |
4541 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
4542 | struct value_print_options opts; |
4543 | ||
4544 | get_user_print_options (&opts); | |
0d381245 VP |
4545 | |
4546 | gdb_assert (!loc || loc_number != 0); | |
4547 | /* See comment in print_one_breakpoint concerning | |
4548 | treatment of breakpoints with single disabled | |
4549 | location. */ | |
4550 | if (loc == NULL | |
4551 | && (b->loc != NULL | |
4552 | && (b->loc->next != NULL || !b->loc->enabled))) | |
4553 | header_of_multiple = 1; | |
4554 | if (loc == NULL) | |
4555 | loc = b->loc; | |
4556 | ||
c4093a6a | 4557 | annotate_record (); |
3b31d625 | 4558 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); |
c4093a6a JM |
4559 | |
4560 | /* 1 */ | |
4561 | annotate_field (0); | |
0d381245 VP |
4562 | if (part_of_multiple) |
4563 | { | |
4564 | char *formatted; | |
0c6773c1 | 4565 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
4566 | ui_out_field_string (uiout, "number", formatted); |
4567 | xfree (formatted); | |
4568 | } | |
4569 | else | |
4570 | { | |
4571 | ui_out_field_int (uiout, "number", b->number); | |
4572 | } | |
c4093a6a JM |
4573 | |
4574 | /* 2 */ | |
4575 | annotate_field (1); | |
0d381245 VP |
4576 | if (part_of_multiple) |
4577 | ui_out_field_skip (uiout, "type"); | |
4578 | else | |
4579 | { | |
4580 | if (((int) b->type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
4581 | || ((int) b->type != bptypes[(int) b->type].type)) | |
4582 | internal_error (__FILE__, __LINE__, | |
4583 | _("bptypes table does not describe type #%d."), | |
4584 | (int) b->type); | |
4585 | ui_out_field_string (uiout, "type", bptypes[(int) b->type].description); | |
4586 | } | |
c4093a6a JM |
4587 | |
4588 | /* 3 */ | |
4589 | annotate_field (2); | |
0d381245 VP |
4590 | if (part_of_multiple) |
4591 | ui_out_field_skip (uiout, "disp"); | |
4592 | else | |
2cec12e5 | 4593 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 4594 | |
c4093a6a JM |
4595 | |
4596 | /* 4 */ | |
4597 | annotate_field (3); | |
0d381245 | 4598 | if (part_of_multiple) |
54e52265 | 4599 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 4600 | else |
54e52265 VP |
4601 | ui_out_field_fmt (uiout, "enabled", "%c", |
4602 | bpenables[(int) b->enable_state]); | |
4603 | ui_out_spaces (uiout, 2); | |
0d381245 | 4604 | |
c4093a6a JM |
4605 | |
4606 | /* 5 and 6 */ | |
4607 | strcpy (wrap_indent, " "); | |
79a45b7d | 4608 | if (opts.addressprint) |
75ac9d7b | 4609 | { |
a6d9a66e | 4610 | if (print_address_bits <= 32) |
75ac9d7b MS |
4611 | strcat (wrap_indent, " "); |
4612 | else | |
4613 | strcat (wrap_indent, " "); | |
4614 | } | |
c906108c | 4615 | |
3086aeae | 4616 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 VP |
4617 | { |
4618 | /* Although the print_one can possibly print | |
4619 | all locations, calling it here is not likely | |
4620 | to get any nice result. So, make sure there's | |
4621 | just one location. */ | |
4622 | gdb_assert (b->loc == NULL || b->loc->next == NULL); | |
a6d9a66e | 4623 | b->ops->print_one (b, last_loc); |
0d381245 | 4624 | } |
3086aeae DJ |
4625 | else |
4626 | switch (b->type) | |
4627 | { | |
4628 | case bp_none: | |
4629 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 4630 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 4631 | break; |
c906108c | 4632 | |
3086aeae DJ |
4633 | case bp_watchpoint: |
4634 | case bp_hardware_watchpoint: | |
4635 | case bp_read_watchpoint: | |
4636 | case bp_access_watchpoint: | |
4637 | /* Field 4, the address, is omitted (which makes the columns | |
4638 | not line up too nicely with the headers, but the effect | |
4639 | is relatively readable). */ | |
79a45b7d | 4640 | if (opts.addressprint) |
3086aeae DJ |
4641 | ui_out_field_skip (uiout, "addr"); |
4642 | annotate_field (5); | |
fa8a61dc | 4643 | ui_out_field_string (uiout, "what", b->exp_string); |
3086aeae DJ |
4644 | break; |
4645 | ||
3086aeae DJ |
4646 | case bp_breakpoint: |
4647 | case bp_hardware_breakpoint: | |
4648 | case bp_until: | |
4649 | case bp_finish: | |
4650 | case bp_longjmp: | |
4651 | case bp_longjmp_resume: | |
4652 | case bp_step_resume: | |
3086aeae DJ |
4653 | case bp_watchpoint_scope: |
4654 | case bp_call_dummy: | |
aa7d318d | 4655 | case bp_std_terminate: |
3086aeae DJ |
4656 | case bp_shlib_event: |
4657 | case bp_thread_event: | |
4658 | case bp_overlay_event: | |
0fd8e87f | 4659 | case bp_longjmp_master: |
aa7d318d | 4660 | case bp_std_terminate_master: |
1042e4c0 | 4661 | case bp_tracepoint: |
7a697b8d | 4662 | case bp_fast_tracepoint: |
4efc6507 | 4663 | case bp_jit_event: |
79a45b7d | 4664 | if (opts.addressprint) |
3086aeae DJ |
4665 | { |
4666 | annotate_field (4); | |
54e52265 | 4667 | if (header_of_multiple) |
0d381245 | 4668 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 4669 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 4670 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 4671 | else |
5af949e3 UW |
4672 | ui_out_field_core_addr (uiout, "addr", |
4673 | loc->gdbarch, loc->address); | |
3086aeae DJ |
4674 | } |
4675 | annotate_field (5); | |
0d381245 VP |
4676 | if (!header_of_multiple) |
4677 | print_breakpoint_location (b, loc, wrap_indent, stb); | |
4678 | if (b->loc) | |
a6d9a66e | 4679 | *last_loc = b->loc; |
3086aeae DJ |
4680 | break; |
4681 | } | |
c906108c | 4682 | |
6c95b8df PA |
4683 | |
4684 | /* For backward compatibility, don't display inferiors unless there | |
4685 | are several. */ | |
4686 | if (loc != NULL | |
4687 | && !header_of_multiple | |
4688 | && (allflag | |
4689 | || (!gdbarch_has_global_breakpoints (target_gdbarch) | |
4690 | && (number_of_program_spaces () > 1 | |
4691 | || number_of_inferiors () > 1) | |
4692 | && loc->owner->type != bp_catchpoint))) | |
4693 | { | |
4694 | struct inferior *inf; | |
4695 | int first = 1; | |
4696 | ||
4697 | for (inf = inferior_list; inf != NULL; inf = inf->next) | |
4698 | { | |
4699 | if (inf->pspace == loc->pspace) | |
4700 | { | |
4701 | if (first) | |
4702 | { | |
4703 | first = 0; | |
4704 | ui_out_text (uiout, " inf "); | |
4705 | } | |
4706 | else | |
4707 | ui_out_text (uiout, ", "); | |
4708 | ui_out_text (uiout, plongest (inf->num)); | |
4709 | } | |
4710 | } | |
4711 | } | |
4712 | ||
4a306c9a | 4713 | if (!part_of_multiple) |
c4093a6a | 4714 | { |
4a306c9a JB |
4715 | if (b->thread != -1) |
4716 | { | |
4717 | /* FIXME: This seems to be redundant and lost here; see the | |
4718 | "stop only in" line a little further down. */ | |
4719 | ui_out_text (uiout, " thread "); | |
4720 | ui_out_field_int (uiout, "thread", b->thread); | |
4721 | } | |
4722 | else if (b->task != 0) | |
4723 | { | |
4724 | ui_out_text (uiout, " task "); | |
4725 | ui_out_field_int (uiout, "task", b->task); | |
4726 | } | |
c4093a6a JM |
4727 | } |
4728 | ||
8b93c638 | 4729 | ui_out_text (uiout, "\n"); |
c4093a6a | 4730 | |
0d381245 | 4731 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
4732 | { |
4733 | annotate_field (6); | |
8b93c638 | 4734 | ui_out_text (uiout, "\tstop only in stack frame at "); |
818dd999 AC |
4735 | /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside |
4736 | the frame ID. */ | |
5af949e3 UW |
4737 | ui_out_field_core_addr (uiout, "frame", |
4738 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 4739 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
4740 | } |
4741 | ||
0d381245 | 4742 | if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b)) |
c4093a6a | 4743 | { |
f7f9143b JB |
4744 | /* We do not print the condition for Ada exception catchpoints |
4745 | because the condition is an internal implementation detail | |
4746 | that we do not want to expose to the user. */ | |
c4093a6a | 4747 | annotate_field (7); |
7a697b8d | 4748 | if (tracepoint_type (b)) |
1042e4c0 SS |
4749 | ui_out_text (uiout, "\ttrace only if "); |
4750 | else | |
4751 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 JJ |
4752 | ui_out_field_string (uiout, "cond", b->cond_string); |
4753 | ui_out_text (uiout, "\n"); | |
4754 | } | |
4755 | ||
0d381245 | 4756 | if (!part_of_multiple && b->thread != -1) |
c4093a6a JM |
4757 | { |
4758 | /* FIXME should make an annotation for this */ | |
8b93c638 JM |
4759 | ui_out_text (uiout, "\tstop only in thread "); |
4760 | ui_out_field_int (uiout, "thread", b->thread); | |
4761 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
4762 | } |
4763 | ||
63c715c6 | 4764 | if (!part_of_multiple && b->hit_count) |
c4093a6a JM |
4765 | { |
4766 | /* FIXME should make an annotation for this */ | |
8b93c638 JM |
4767 | if (ep_is_catchpoint (b)) |
4768 | ui_out_text (uiout, "\tcatchpoint"); | |
4769 | else | |
4770 | ui_out_text (uiout, "\tbreakpoint"); | |
4771 | ui_out_text (uiout, " already hit "); | |
4772 | ui_out_field_int (uiout, "times", b->hit_count); | |
4773 | if (b->hit_count == 1) | |
4774 | ui_out_text (uiout, " time\n"); | |
4775 | else | |
4776 | ui_out_text (uiout, " times\n"); | |
c4093a6a JM |
4777 | } |
4778 | ||
fb40c209 AC |
4779 | /* Output the count also if it is zero, but only if this is |
4780 | mi. FIXME: Should have a better test for this. */ | |
9dc5e2a9 | 4781 | if (ui_out_is_mi_like_p (uiout)) |
63c715c6 | 4782 | if (!part_of_multiple && b->hit_count == 0) |
fb40c209 | 4783 | ui_out_field_int (uiout, "times", b->hit_count); |
8b93c638 | 4784 | |
0d381245 | 4785 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
4786 | { |
4787 | annotate_field (8); | |
8b93c638 JM |
4788 | ui_out_text (uiout, "\tignore next "); |
4789 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
4790 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 4791 | } |
059fb39f | 4792 | |
9add0f1b | 4793 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 4794 | if (!part_of_multiple && l) |
c4093a6a | 4795 | { |
3b31d625 EZ |
4796 | struct cleanup *script_chain; |
4797 | ||
c4093a6a | 4798 | annotate_field (9); |
3b31d625 | 4799 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 4800 | print_command_lines (uiout, l, 4); |
3b31d625 | 4801 | do_cleanups (script_chain); |
c4093a6a | 4802 | } |
d24317b4 | 4803 | |
1042e4c0 SS |
4804 | if (!part_of_multiple && b->pass_count) |
4805 | { | |
4806 | annotate_field (10); | |
4807 | ui_out_text (uiout, "\tpass count "); | |
4808 | ui_out_field_int (uiout, "pass", b->pass_count); | |
4809 | ui_out_text (uiout, " \n"); | |
4810 | } | |
4811 | ||
d24317b4 VP |
4812 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
4813 | { | |
4814 | if (b->addr_string) | |
4815 | ui_out_field_string (uiout, "original-location", b->addr_string); | |
4816 | else if (b->exp_string) | |
4817 | ui_out_field_string (uiout, "original-location", b->exp_string); | |
4818 | } | |
4819 | ||
3b31d625 | 4820 | do_cleanups (bkpt_chain); |
8b93c638 | 4821 | do_cleanups (old_chain); |
c4093a6a | 4822 | } |
c5aa993b | 4823 | |
0d381245 VP |
4824 | static void |
4825 | print_one_breakpoint (struct breakpoint *b, | |
6c95b8df PA |
4826 | struct bp_location **last_loc, int print_address_bits, |
4827 | int allflag) | |
0d381245 | 4828 | { |
6c95b8df PA |
4829 | print_one_breakpoint_location (b, NULL, 0, last_loc, |
4830 | print_address_bits, allflag); | |
0d381245 VP |
4831 | |
4832 | /* If this breakpoint has custom print function, | |
4833 | it's already printed. Otherwise, print individual | |
4834 | locations, if any. */ | |
4835 | if (b->ops == NULL || b->ops->print_one == NULL) | |
4836 | { | |
4837 | /* If breakpoint has a single location that is | |
4838 | disabled, we print it as if it had | |
4839 | several locations, since otherwise it's hard to | |
4840 | represent "breakpoint enabled, location disabled" | |
a5606eee VP |
4841 | situation. |
4842 | Note that while hardware watchpoints have | |
4843 | several locations internally, that's no a property | |
4844 | exposed to user. */ | |
0d381245 | 4845 | if (b->loc |
a5606eee | 4846 | && !is_hardware_watchpoint (b) |
0d381245 | 4847 | && (b->loc->next || !b->loc->enabled) |
a5606eee | 4848 | && !ui_out_is_mi_like_p (uiout)) |
0d381245 VP |
4849 | { |
4850 | struct bp_location *loc; | |
4851 | int n = 1; | |
4852 | for (loc = b->loc; loc; loc = loc->next, ++n) | |
a6d9a66e | 4853 | print_one_breakpoint_location (b, loc, n, last_loc, |
6c95b8df | 4854 | print_address_bits, allflag); |
0d381245 VP |
4855 | } |
4856 | } | |
4857 | } | |
4858 | ||
a6d9a66e UW |
4859 | static int |
4860 | breakpoint_address_bits (struct breakpoint *b) | |
4861 | { | |
4862 | int print_address_bits = 0; | |
4863 | struct bp_location *loc; | |
4864 | ||
4865 | for (loc = b->loc; loc; loc = loc->next) | |
4866 | { | |
c7437ca6 PA |
4867 | int addr_bit; |
4868 | ||
4869 | /* Software watchpoints that aren't watching memory don't have | |
4870 | an address to print. */ | |
4871 | if (b->type == bp_watchpoint && loc->watchpoint_type == -1) | |
4872 | continue; | |
4873 | ||
4874 | addr_bit = gdbarch_addr_bit (loc->gdbarch); | |
a6d9a66e UW |
4875 | if (addr_bit > print_address_bits) |
4876 | print_address_bits = addr_bit; | |
4877 | } | |
4878 | ||
4879 | return print_address_bits; | |
4880 | } | |
0d381245 | 4881 | |
c4093a6a JM |
4882 | struct captured_breakpoint_query_args |
4883 | { | |
4884 | int bnum; | |
4885 | }; | |
c5aa993b | 4886 | |
c4093a6a | 4887 | static int |
2b65245e | 4888 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
4889 | { |
4890 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 4891 | struct breakpoint *b; |
a6d9a66e | 4892 | struct bp_location *dummy_loc = NULL; |
c4093a6a JM |
4893 | ALL_BREAKPOINTS (b) |
4894 | { | |
4895 | if (args->bnum == b->number) | |
c5aa993b | 4896 | { |
a6d9a66e | 4897 | int print_address_bits = breakpoint_address_bits (b); |
6c95b8df | 4898 | print_one_breakpoint (b, &dummy_loc, print_address_bits, 0); |
c4093a6a | 4899 | return GDB_RC_OK; |
c5aa993b | 4900 | } |
c4093a6a JM |
4901 | } |
4902 | return GDB_RC_NONE; | |
4903 | } | |
c5aa993b | 4904 | |
c4093a6a | 4905 | enum gdb_rc |
ce43223b | 4906 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, char **error_message) |
c4093a6a JM |
4907 | { |
4908 | struct captured_breakpoint_query_args args; | |
4909 | args.bnum = bnum; | |
4910 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4911 | an error. */ | |
b0b13bb4 DJ |
4912 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
4913 | error_message, RETURN_MASK_ALL) < 0) | |
4914 | return GDB_RC_FAIL; | |
4915 | else | |
4916 | return GDB_RC_OK; | |
c4093a6a | 4917 | } |
c5aa993b | 4918 | |
7f3b0473 AC |
4919 | /* Return non-zero if B is user settable (breakpoints, watchpoints, |
4920 | catchpoints, et.al.). */ | |
4921 | ||
4922 | static int | |
4923 | user_settable_breakpoint (const struct breakpoint *b) | |
4924 | { | |
4925 | return (b->type == bp_breakpoint | |
ce78b96d | 4926 | || b->type == bp_catchpoint |
7f3b0473 | 4927 | || b->type == bp_hardware_breakpoint |
7a697b8d | 4928 | || tracepoint_type (b) |
7f3b0473 AC |
4929 | || b->type == bp_watchpoint |
4930 | || b->type == bp_read_watchpoint | |
4931 | || b->type == bp_access_watchpoint | |
4932 | || b->type == bp_hardware_watchpoint); | |
4933 | } | |
4934 | ||
4935 | /* Print information on user settable breakpoint (watchpoint, etc) | |
4936 | number BNUM. If BNUM is -1 print all user settable breakpoints. | |
4937 | If ALLFLAG is non-zero, include non- user settable breakpoints. */ | |
c906108c | 4938 | |
c4093a6a | 4939 | static void |
fba45db2 | 4940 | breakpoint_1 (int bnum, int allflag) |
c4093a6a | 4941 | { |
52f0bd74 | 4942 | struct breakpoint *b; |
a6d9a66e | 4943 | struct bp_location *last_loc = NULL; |
7f3b0473 | 4944 | int nr_printable_breakpoints; |
3b31d625 | 4945 | struct cleanup *bkpttbl_chain; |
79a45b7d | 4946 | struct value_print_options opts; |
a6d9a66e | 4947 | int print_address_bits = 0; |
c4093a6a | 4948 | |
79a45b7d TT |
4949 | get_user_print_options (&opts); |
4950 | ||
a6d9a66e UW |
4951 | /* Compute the number of rows in the table, as well as the |
4952 | size required for address fields. */ | |
7f3b0473 AC |
4953 | nr_printable_breakpoints = 0; |
4954 | ALL_BREAKPOINTS (b) | |
4955 | if (bnum == -1 | |
4956 | || bnum == b->number) | |
4957 | { | |
4958 | if (allflag || user_settable_breakpoint (b)) | |
a6d9a66e UW |
4959 | { |
4960 | int addr_bit = breakpoint_address_bits (b); | |
4961 | if (addr_bit > print_address_bits) | |
4962 | print_address_bits = addr_bit; | |
4963 | ||
4964 | nr_printable_breakpoints++; | |
4965 | } | |
7f3b0473 AC |
4966 | } |
4967 | ||
79a45b7d | 4968 | if (opts.addressprint) |
3b31d625 EZ |
4969 | bkpttbl_chain |
4970 | = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints, | |
4971 | "BreakpointTable"); | |
8b93c638 | 4972 | else |
3b31d625 EZ |
4973 | bkpttbl_chain |
4974 | = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints, | |
4975 | "BreakpointTable"); | |
8b93c638 | 4976 | |
7f3b0473 | 4977 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
4978 | annotate_breakpoints_headers (); |
4979 | if (nr_printable_breakpoints > 0) | |
4980 | annotate_field (0); | |
0d381245 | 4981 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
4982 | if (nr_printable_breakpoints > 0) |
4983 | annotate_field (1); | |
4984 | ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */ | |
4985 | if (nr_printable_breakpoints > 0) | |
4986 | annotate_field (2); | |
4987 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ | |
4988 | if (nr_printable_breakpoints > 0) | |
4989 | annotate_field (3); | |
54e52265 | 4990 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 4991 | if (opts.addressprint) |
7f3b0473 | 4992 | { |
d7faa9e7 AC |
4993 | if (nr_printable_breakpoints > 0) |
4994 | annotate_field (4); | |
a6d9a66e | 4995 | if (print_address_bits <= 32) |
b25959ec | 4996 | ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */ |
7f3b0473 | 4997 | else |
b25959ec | 4998 | ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */ |
7f3b0473 | 4999 | } |
d7faa9e7 AC |
5000 | if (nr_printable_breakpoints > 0) |
5001 | annotate_field (5); | |
5002 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
5003 | ui_out_table_body (uiout); | |
5004 | if (nr_printable_breakpoints > 0) | |
5005 | annotate_breakpoints_table (); | |
7f3b0473 | 5006 | |
c4093a6a | 5007 | ALL_BREAKPOINTS (b) |
bad56014 TT |
5008 | { |
5009 | QUIT; | |
c4093a6a JM |
5010 | if (bnum == -1 |
5011 | || bnum == b->number) | |
5012 | { | |
5013 | /* We only print out user settable breakpoints unless the | |
5014 | allflag is set. */ | |
7f3b0473 | 5015 | if (allflag || user_settable_breakpoint (b)) |
6c95b8df | 5016 | print_one_breakpoint (b, &last_loc, print_address_bits, allflag); |
c4093a6a | 5017 | } |
bad56014 | 5018 | } |
c4093a6a | 5019 | |
3b31d625 | 5020 | do_cleanups (bkpttbl_chain); |
698384cd | 5021 | |
7f3b0473 | 5022 | if (nr_printable_breakpoints == 0) |
c906108c | 5023 | { |
8b93c638 JM |
5024 | if (bnum == -1) |
5025 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); | |
5026 | else | |
5027 | ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n", | |
5028 | bnum); | |
c906108c SS |
5029 | } |
5030 | else | |
c4093a6a | 5031 | { |
a6d9a66e UW |
5032 | if (last_loc && !server_command) |
5033 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 5034 | } |
c906108c | 5035 | |
c4093a6a JM |
5036 | /* FIXME? Should this be moved up so that it is only called when |
5037 | there have been breakpoints? */ | |
c906108c SS |
5038 | annotate_breakpoints_table_end (); |
5039 | } | |
5040 | ||
c906108c | 5041 | static void |
fba45db2 | 5042 | breakpoints_info (char *bnum_exp, int from_tty) |
c906108c SS |
5043 | { |
5044 | int bnum = -1; | |
5045 | ||
5046 | if (bnum_exp) | |
bb518678 | 5047 | bnum = parse_and_eval_long (bnum_exp); |
c906108c SS |
5048 | |
5049 | breakpoint_1 (bnum, 0); | |
5050 | } | |
5051 | ||
7a292a7a | 5052 | static void |
fba45db2 | 5053 | maintenance_info_breakpoints (char *bnum_exp, int from_tty) |
c906108c SS |
5054 | { |
5055 | int bnum = -1; | |
5056 | ||
5057 | if (bnum_exp) | |
bb518678 | 5058 | bnum = parse_and_eval_long (bnum_exp); |
c906108c SS |
5059 | |
5060 | breakpoint_1 (bnum, 1); | |
5061 | } | |
5062 | ||
0d381245 | 5063 | static int |
714835d5 | 5064 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 5065 | struct program_space *pspace, |
714835d5 | 5066 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
5067 | { |
5068 | struct bp_location *bl = b->loc; | |
5069 | for (; bl; bl = bl->next) | |
5070 | { | |
6c95b8df PA |
5071 | if (bl->pspace == pspace |
5072 | && bl->address == pc | |
0d381245 VP |
5073 | && (!overlay_debugging || bl->section == section)) |
5074 | return 1; | |
5075 | } | |
5076 | return 0; | |
5077 | } | |
5078 | ||
6c95b8df PA |
5079 | /* Print a message describing any breakpoints set at PC. This |
5080 | concerns with logical breakpoints, so we match program spaces, not | |
5081 | address spaces. */ | |
c906108c SS |
5082 | |
5083 | static void | |
6c95b8df PA |
5084 | describe_other_breakpoints (struct gdbarch *gdbarch, |
5085 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 5086 | struct obj_section *section, int thread) |
c906108c | 5087 | { |
52f0bd74 AC |
5088 | int others = 0; |
5089 | struct breakpoint *b; | |
c906108c SS |
5090 | |
5091 | ALL_BREAKPOINTS (b) | |
6c95b8df | 5092 | others += breakpoint_has_pc (b, pspace, pc, section); |
c906108c SS |
5093 | if (others > 0) |
5094 | { | |
a3f17187 AC |
5095 | if (others == 1) |
5096 | printf_filtered (_("Note: breakpoint ")); | |
5097 | else /* if (others == ???) */ | |
5098 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 5099 | ALL_BREAKPOINTS (b) |
6c95b8df | 5100 | if (breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
5101 | { |
5102 | others--; | |
5103 | printf_filtered ("%d", b->number); | |
5104 | if (b->thread == -1 && thread != -1) | |
5105 | printf_filtered (" (all threads)"); | |
5106 | else if (b->thread != -1) | |
5107 | printf_filtered (" (thread %d)", b->thread); | |
5108 | printf_filtered ("%s%s ", | |
059fb39f | 5109 | ((b->enable_state == bp_disabled |
8bea4e01 UW |
5110 | || b->enable_state == bp_call_disabled |
5111 | || b->enable_state == bp_startup_disabled) | |
0d381245 VP |
5112 | ? " (disabled)" |
5113 | : b->enable_state == bp_permanent | |
5114 | ? " (permanent)" | |
5115 | : ""), | |
5116 | (others > 1) ? "," | |
5117 | : ((others == 1) ? " and" : "")); | |
5118 | } | |
a3f17187 | 5119 | printf_filtered (_("also set at pc ")); |
5af949e3 | 5120 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
5121 | printf_filtered (".\n"); |
5122 | } | |
5123 | } | |
5124 | \f | |
5125 | /* Set the default place to put a breakpoint | |
5126 | for the `break' command with no arguments. */ | |
5127 | ||
5128 | void | |
6c95b8df PA |
5129 | set_default_breakpoint (int valid, struct program_space *pspace, |
5130 | CORE_ADDR addr, struct symtab *symtab, | |
fba45db2 | 5131 | int line) |
c906108c SS |
5132 | { |
5133 | default_breakpoint_valid = valid; | |
6c95b8df | 5134 | default_breakpoint_pspace = pspace; |
c906108c SS |
5135 | default_breakpoint_address = addr; |
5136 | default_breakpoint_symtab = symtab; | |
5137 | default_breakpoint_line = line; | |
5138 | } | |
5139 | ||
e4f237da KB |
5140 | /* Return true iff it is meaningful to use the address member of |
5141 | BPT. For some breakpoint types, the address member is irrelevant | |
5142 | and it makes no sense to attempt to compare it to other addresses | |
5143 | (or use it for any other purpose either). | |
5144 | ||
5145 | More specifically, each of the following breakpoint types will always | |
876fa593 JK |
5146 | have a zero valued address and we don't want to mark breakpoints of any of |
5147 | these types to be a duplicate of an actual breakpoint at address zero: | |
e4f237da KB |
5148 | |
5149 | bp_watchpoint | |
2d134ed3 PA |
5150 | bp_catchpoint |
5151 | ||
5152 | */ | |
e4f237da KB |
5153 | |
5154 | static int | |
5155 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
5156 | { | |
5157 | enum bptype type = bpt->type; | |
5158 | ||
2d134ed3 PA |
5159 | return (type != bp_watchpoint && type != bp_catchpoint); |
5160 | } | |
5161 | ||
5162 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
5163 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
5164 | ||
5165 | static int | |
5166 | watchpoint_locations_match (struct bp_location *loc1, struct bp_location *loc2) | |
5167 | { | |
85d721b8 PA |
5168 | /* Note that this checks the owner's type, not the location's. In |
5169 | case the target does not support read watchpoints, but does | |
5170 | support access watchpoints, we'll have bp_read_watchpoint | |
5171 | watchpoints with hw_access locations. Those should be considered | |
5172 | duplicates of hw_read locations. The hw_read locations will | |
5173 | become hw_access locations later. */ | |
2d134ed3 PA |
5174 | return (loc1->owner->type == loc2->owner->type |
5175 | && loc1->pspace->aspace == loc2->pspace->aspace | |
5176 | && loc1->address == loc2->address | |
5177 | && loc1->length == loc2->length); | |
e4f237da KB |
5178 | } |
5179 | ||
6c95b8df PA |
5180 | /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the |
5181 | same breakpoint location. In most targets, this can only be true | |
5182 | if ASPACE1 matches ASPACE2. On targets that have global | |
5183 | breakpoints, the address space doesn't really matter. */ | |
5184 | ||
5185 | static int | |
5186 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, | |
5187 | struct address_space *aspace2, CORE_ADDR addr2) | |
5188 | { | |
5189 | return ((gdbarch_has_global_breakpoints (target_gdbarch) | |
5190 | || aspace1 == aspace2) | |
5191 | && addr1 == addr2); | |
5192 | } | |
5193 | ||
2d134ed3 PA |
5194 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
5195 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
5196 | represent the same location. */ | |
5197 | ||
5198 | static int | |
5199 | breakpoint_locations_match (struct bp_location *loc1, struct bp_location *loc2) | |
5200 | { | |
5201 | int hw_point1 = is_hardware_watchpoint (loc1->owner); | |
5202 | int hw_point2 = is_hardware_watchpoint (loc2->owner); | |
5203 | ||
5204 | if (hw_point1 != hw_point2) | |
5205 | return 0; | |
5206 | else if (hw_point1) | |
5207 | return watchpoint_locations_match (loc1, loc2); | |
5208 | else | |
5209 | return breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
5210 | loc2->pspace->aspace, loc2->address); | |
5211 | } | |
5212 | ||
76897487 KB |
5213 | static void |
5214 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
5215 | int bnum, int have_bnum) | |
5216 | { | |
5217 | char astr1[40]; | |
5218 | char astr2[40]; | |
5219 | ||
bb599908 PH |
5220 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
5221 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 5222 | if (have_bnum) |
8a3fe4f8 | 5223 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
5224 | bnum, astr1, astr2); |
5225 | else | |
8a3fe4f8 | 5226 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
5227 | } |
5228 | ||
5229 | /* Adjust a breakpoint's address to account for architectural constraints | |
5230 | on breakpoint placement. Return the adjusted address. Note: Very | |
5231 | few targets require this kind of adjustment. For most targets, | |
5232 | this function is simply the identity function. */ | |
5233 | ||
5234 | static CORE_ADDR | |
a6d9a66e UW |
5235 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
5236 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 5237 | { |
a6d9a66e | 5238 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
5239 | { |
5240 | /* Very few targets need any kind of breakpoint adjustment. */ | |
5241 | return bpaddr; | |
5242 | } | |
88f7da05 KB |
5243 | else if (bptype == bp_watchpoint |
5244 | || bptype == bp_hardware_watchpoint | |
5245 | || bptype == bp_read_watchpoint | |
5246 | || bptype == bp_access_watchpoint | |
fe798b75 | 5247 | || bptype == bp_catchpoint) |
88f7da05 KB |
5248 | { |
5249 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
5250 | have their addresses modified. */ | |
5251 | return bpaddr; | |
5252 | } | |
76897487 KB |
5253 | else |
5254 | { | |
5255 | CORE_ADDR adjusted_bpaddr; | |
5256 | ||
5257 | /* Some targets have architectural constraints on the placement | |
5258 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 5259 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
5260 | |
5261 | /* An adjusted breakpoint address can significantly alter | |
5262 | a user's expectations. Print a warning if an adjustment | |
5263 | is required. */ | |
5264 | if (adjusted_bpaddr != bpaddr) | |
5265 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
5266 | ||
5267 | return adjusted_bpaddr; | |
5268 | } | |
5269 | } | |
5270 | ||
7cc221ef DJ |
5271 | /* Allocate a struct bp_location. */ |
5272 | ||
26bb91f3 | 5273 | static struct bp_location * |
39d61571 | 5274 | allocate_bp_location (struct breakpoint *bpt) |
7cc221ef DJ |
5275 | { |
5276 | struct bp_location *loc, *loc_p; | |
5277 | ||
5278 | loc = xmalloc (sizeof (struct bp_location)); | |
5279 | memset (loc, 0, sizeof (*loc)); | |
5280 | ||
e049a4b5 | 5281 | loc->owner = bpt; |
511a6cd4 | 5282 | loc->cond = NULL; |
0d381245 VP |
5283 | loc->shlib_disabled = 0; |
5284 | loc->enabled = 1; | |
e049a4b5 | 5285 | |
39d61571 | 5286 | switch (bpt->type) |
e049a4b5 DJ |
5287 | { |
5288 | case bp_breakpoint: | |
5289 | case bp_until: | |
5290 | case bp_finish: | |
5291 | case bp_longjmp: | |
5292 | case bp_longjmp_resume: | |
5293 | case bp_step_resume: | |
e049a4b5 DJ |
5294 | case bp_watchpoint_scope: |
5295 | case bp_call_dummy: | |
aa7d318d | 5296 | case bp_std_terminate: |
e049a4b5 DJ |
5297 | case bp_shlib_event: |
5298 | case bp_thread_event: | |
5299 | case bp_overlay_event: | |
4efc6507 | 5300 | case bp_jit_event: |
0fd8e87f | 5301 | case bp_longjmp_master: |
aa7d318d | 5302 | case bp_std_terminate_master: |
e049a4b5 DJ |
5303 | loc->loc_type = bp_loc_software_breakpoint; |
5304 | break; | |
5305 | case bp_hardware_breakpoint: | |
5306 | loc->loc_type = bp_loc_hardware_breakpoint; | |
5307 | break; | |
5308 | case bp_hardware_watchpoint: | |
5309 | case bp_read_watchpoint: | |
5310 | case bp_access_watchpoint: | |
5311 | loc->loc_type = bp_loc_hardware_watchpoint; | |
5312 | break; | |
5313 | case bp_watchpoint: | |
ce78b96d | 5314 | case bp_catchpoint: |
15c3d785 PA |
5315 | case bp_tracepoint: |
5316 | case bp_fast_tracepoint: | |
e049a4b5 DJ |
5317 | loc->loc_type = bp_loc_other; |
5318 | break; | |
5319 | default: | |
e2e0b3e5 | 5320 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
5321 | } |
5322 | ||
7cc221ef DJ |
5323 | return loc; |
5324 | } | |
5325 | ||
fe3f5fa8 VP |
5326 | static void free_bp_location (struct bp_location *loc) |
5327 | { | |
5328 | if (loc->cond) | |
5329 | xfree (loc->cond); | |
74960c60 VP |
5330 | |
5331 | if (loc->function_name) | |
5332 | xfree (loc->function_name); | |
5333 | ||
fe3f5fa8 VP |
5334 | xfree (loc); |
5335 | } | |
5336 | ||
0d381245 VP |
5337 | /* Helper to set_raw_breakpoint below. Creates a breakpoint |
5338 | that has type BPTYPE and has no locations as yet. */ | |
63c252f8 | 5339 | /* This function is used in gdbtk sources and thus can not be made static. */ |
c906108c | 5340 | |
c40e75cd | 5341 | static struct breakpoint * |
a6d9a66e UW |
5342 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, |
5343 | enum bptype bptype) | |
c906108c | 5344 | { |
52f0bd74 | 5345 | struct breakpoint *b, *b1; |
c906108c SS |
5346 | |
5347 | b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint)); | |
5348 | memset (b, 0, sizeof (*b)); | |
2219d63c | 5349 | |
4d28f7a8 | 5350 | b->type = bptype; |
a6d9a66e | 5351 | b->gdbarch = gdbarch; |
c906108c SS |
5352 | b->language = current_language->la_language; |
5353 | b->input_radix = input_radix; | |
5354 | b->thread = -1; | |
b5de0fa7 | 5355 | b->enable_state = bp_enabled; |
c906108c SS |
5356 | b->next = 0; |
5357 | b->silent = 0; | |
5358 | b->ignore_count = 0; | |
5359 | b->commands = NULL; | |
818dd999 | 5360 | b->frame_id = null_frame_id; |
3a3e9ee3 | 5361 | b->forked_inferior_pid = null_ptid; |
c906108c | 5362 | b->exec_pathname = NULL; |
a96d9b2e | 5363 | b->syscalls_to_be_caught = NULL; |
3086aeae | 5364 | b->ops = NULL; |
0d381245 | 5365 | b->condition_not_parsed = 0; |
c906108c SS |
5366 | |
5367 | /* Add this breakpoint to the end of the chain | |
5368 | so that a list of breakpoints will come out in order | |
5369 | of increasing numbers. */ | |
5370 | ||
5371 | b1 = breakpoint_chain; | |
5372 | if (b1 == 0) | |
5373 | breakpoint_chain = b; | |
5374 | else | |
5375 | { | |
5376 | while (b1->next) | |
5377 | b1 = b1->next; | |
5378 | b1->next = b; | |
5379 | } | |
0d381245 VP |
5380 | return b; |
5381 | } | |
5382 | ||
5383 | /* Initialize loc->function_name. */ | |
5384 | static void | |
5385 | set_breakpoint_location_function (struct bp_location *loc) | |
5386 | { | |
5387 | if (loc->owner->type == bp_breakpoint | |
1042e4c0 | 5388 | || loc->owner->type == bp_hardware_breakpoint |
7a697b8d | 5389 | || tracepoint_type (loc->owner)) |
0d381245 VP |
5390 | { |
5391 | find_pc_partial_function (loc->address, &(loc->function_name), | |
5392 | NULL, NULL); | |
5393 | if (loc->function_name) | |
5394 | loc->function_name = xstrdup (loc->function_name); | |
5395 | } | |
5396 | } | |
5397 | ||
a6d9a66e UW |
5398 | /* Attempt to determine architecture of location identified by SAL. */ |
5399 | static struct gdbarch * | |
5400 | get_sal_arch (struct symtab_and_line sal) | |
5401 | { | |
5402 | if (sal.section) | |
5403 | return get_objfile_arch (sal.section->objfile); | |
5404 | if (sal.symtab) | |
5405 | return get_objfile_arch (sal.symtab->objfile); | |
5406 | ||
5407 | return NULL; | |
5408 | } | |
5409 | ||
0d381245 VP |
5410 | /* set_raw_breakpoint is a low level routine for allocating and |
5411 | partially initializing a breakpoint of type BPTYPE. The newly | |
5412 | created breakpoint's address, section, source file name, and line | |
5413 | number are provided by SAL. The newly created and partially | |
5414 | initialized breakpoint is added to the breakpoint chain and | |
5415 | is also returned as the value of this function. | |
5416 | ||
5417 | It is expected that the caller will complete the initialization of | |
5418 | the newly created breakpoint struct as well as output any status | |
5419 | information regarding the creation of a new breakpoint. In | |
5420 | particular, set_raw_breakpoint does NOT set the breakpoint | |
5421 | number! Care should be taken to not allow an error to occur | |
5422 | prior to completing the initialization of the breakpoint. If this | |
5423 | should happen, a bogus breakpoint will be left on the chain. */ | |
5424 | ||
63c252f8 | 5425 | struct breakpoint * |
a6d9a66e UW |
5426 | set_raw_breakpoint (struct gdbarch *gdbarch, |
5427 | struct symtab_and_line sal, enum bptype bptype) | |
0d381245 | 5428 | { |
a6d9a66e | 5429 | struct breakpoint *b = set_raw_breakpoint_without_location (gdbarch, bptype); |
0d381245 | 5430 | CORE_ADDR adjusted_address; |
a6d9a66e UW |
5431 | struct gdbarch *loc_gdbarch; |
5432 | ||
5433 | loc_gdbarch = get_sal_arch (sal); | |
5434 | if (!loc_gdbarch) | |
5435 | loc_gdbarch = b->gdbarch; | |
0d381245 | 5436 | |
6c95b8df PA |
5437 | if (bptype != bp_catchpoint) |
5438 | gdb_assert (sal.pspace != NULL); | |
5439 | ||
0d381245 VP |
5440 | /* Adjust the breakpoint's address prior to allocating a location. |
5441 | Once we call allocate_bp_location(), that mostly uninitialized | |
5442 | location will be placed on the location chain. Adjustment of the | |
8defab1a | 5443 | breakpoint may cause target_read_memory() to be called and we do |
0d381245 VP |
5444 | not want its scan of the location chain to find a breakpoint and |
5445 | location that's only been partially initialized. */ | |
a6d9a66e | 5446 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, sal.pc, b->type); |
0d381245 | 5447 | |
39d61571 | 5448 | b->loc = allocate_bp_location (b); |
a6d9a66e | 5449 | b->loc->gdbarch = loc_gdbarch; |
0d381245 VP |
5450 | b->loc->requested_address = sal.pc; |
5451 | b->loc->address = adjusted_address; | |
6c95b8df PA |
5452 | b->loc->pspace = sal.pspace; |
5453 | ||
5454 | /* Store the program space that was used to set the breakpoint, for | |
5455 | breakpoint resetting. */ | |
5456 | b->pspace = sal.pspace; | |
0d381245 VP |
5457 | |
5458 | if (sal.symtab == NULL) | |
5459 | b->source_file = NULL; | |
5460 | else | |
1b36a34b | 5461 | b->source_file = xstrdup (sal.symtab->filename); |
0d381245 VP |
5462 | b->loc->section = sal.section; |
5463 | b->line_number = sal.line; | |
5464 | ||
5465 | set_breakpoint_location_function (b->loc); | |
c906108c | 5466 | |
c906108c SS |
5467 | breakpoints_changed (); |
5468 | ||
5469 | return b; | |
5470 | } | |
5471 | ||
c2c6d25f JM |
5472 | |
5473 | /* Note that the breakpoint object B describes a permanent breakpoint | |
5474 | instruction, hard-wired into the inferior's code. */ | |
5475 | void | |
5476 | make_breakpoint_permanent (struct breakpoint *b) | |
5477 | { | |
0d381245 | 5478 | struct bp_location *bl; |
b5de0fa7 | 5479 | b->enable_state = bp_permanent; |
c2c6d25f | 5480 | |
0d381245 VP |
5481 | /* By definition, permanent breakpoints are already present in the code. |
5482 | Mark all locations as inserted. For now, make_breakpoint_permanent | |
5483 | is called in just one place, so it's hard to say if it's reasonable | |
5484 | to have permanent breakpoint with multiple locations or not, | |
5485 | but it's easy to implmement. */ | |
5486 | for (bl = b->loc; bl; bl = bl->next) | |
5487 | bl->inserted = 1; | |
c2c6d25f JM |
5488 | } |
5489 | ||
53a5351d | 5490 | /* Call this routine when stepping and nexting to enable a breakpoint |
0fd8e87f | 5491 | if we do a longjmp() in THREAD. When we hit that breakpoint, call |
c906108c SS |
5492 | set_longjmp_resume_breakpoint() to figure out where we are going. */ |
5493 | ||
5494 | void | |
0fd8e87f | 5495 | set_longjmp_breakpoint (int thread) |
c906108c | 5496 | { |
0fd8e87f UW |
5497 | struct breakpoint *b, *temp; |
5498 | ||
5499 | /* To avoid having to rescan all objfile symbols at every step, | |
5500 | we maintain a list of continually-inserted but always disabled | |
5501 | longjmp "master" breakpoints. Here, we simply create momentary | |
5502 | clones of those and enable them for the requested thread. */ | |
5503 | ALL_BREAKPOINTS_SAFE (b, temp) | |
6c95b8df PA |
5504 | if (b->pspace == current_program_space |
5505 | && b->type == bp_longjmp_master) | |
0fd8e87f UW |
5506 | { |
5507 | struct breakpoint *clone = clone_momentary_breakpoint (b); | |
5508 | clone->type = bp_longjmp; | |
5509 | clone->thread = thread; | |
5510 | } | |
c906108c SS |
5511 | } |
5512 | ||
611c83ae | 5513 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 5514 | void |
611c83ae | 5515 | delete_longjmp_breakpoint (int thread) |
c906108c | 5516 | { |
611c83ae | 5517 | struct breakpoint *b, *temp; |
c906108c | 5518 | |
611c83ae PA |
5519 | ALL_BREAKPOINTS_SAFE (b, temp) |
5520 | if (b->type == bp_longjmp) | |
5521 | { | |
5522 | if (b->thread == thread) | |
5523 | delete_breakpoint (b); | |
5524 | } | |
c906108c SS |
5525 | } |
5526 | ||
1900040c MS |
5527 | void |
5528 | enable_overlay_breakpoints (void) | |
5529 | { | |
52f0bd74 | 5530 | struct breakpoint *b; |
1900040c MS |
5531 | |
5532 | ALL_BREAKPOINTS (b) | |
5533 | if (b->type == bp_overlay_event) | |
5534 | { | |
5535 | b->enable_state = bp_enabled; | |
b60e7edf | 5536 | update_global_location_list (1); |
c02f5703 | 5537 | overlay_events_enabled = 1; |
1900040c MS |
5538 | } |
5539 | } | |
5540 | ||
5541 | void | |
5542 | disable_overlay_breakpoints (void) | |
5543 | { | |
52f0bd74 | 5544 | struct breakpoint *b; |
1900040c MS |
5545 | |
5546 | ALL_BREAKPOINTS (b) | |
5547 | if (b->type == bp_overlay_event) | |
5548 | { | |
5549 | b->enable_state = bp_disabled; | |
b60e7edf | 5550 | update_global_location_list (0); |
c02f5703 | 5551 | overlay_events_enabled = 0; |
1900040c MS |
5552 | } |
5553 | } | |
5554 | ||
aa7d318d TT |
5555 | /* Set an active std::terminate breakpoint for each std::terminate |
5556 | master breakpoint. */ | |
5557 | void | |
5558 | set_std_terminate_breakpoint (void) | |
5559 | { | |
5560 | struct breakpoint *b, *temp; | |
5561 | ||
5562 | ALL_BREAKPOINTS_SAFE (b, temp) | |
5563 | if (b->pspace == current_program_space | |
5564 | && b->type == bp_std_terminate_master) | |
5565 | { | |
5566 | struct breakpoint *clone = clone_momentary_breakpoint (b); | |
5567 | clone->type = bp_std_terminate; | |
5568 | } | |
5569 | } | |
5570 | ||
5571 | /* Delete all the std::terminate breakpoints. */ | |
5572 | void | |
5573 | delete_std_terminate_breakpoint (void) | |
5574 | { | |
5575 | struct breakpoint *b, *temp; | |
5576 | ||
5577 | ALL_BREAKPOINTS_SAFE (b, temp) | |
5578 | if (b->type == bp_std_terminate) | |
5579 | delete_breakpoint (b); | |
5580 | } | |
5581 | ||
c4093a6a | 5582 | struct breakpoint * |
a6d9a66e | 5583 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
5584 | { |
5585 | struct breakpoint *b; | |
c4093a6a | 5586 | |
a6d9a66e | 5587 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event); |
c4093a6a | 5588 | |
b5de0fa7 | 5589 | b->enable_state = bp_enabled; |
c4093a6a | 5590 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
5591 | b->addr_string |
5592 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 5593 | |
b60e7edf | 5594 | update_global_location_list_nothrow (1); |
74960c60 | 5595 | |
c4093a6a JM |
5596 | return b; |
5597 | } | |
5598 | ||
5599 | void | |
5600 | remove_thread_event_breakpoints (void) | |
5601 | { | |
5602 | struct breakpoint *b, *temp; | |
5603 | ||
5604 | ALL_BREAKPOINTS_SAFE (b, temp) | |
6c95b8df PA |
5605 | if (b->type == bp_thread_event |
5606 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
5607 | delete_breakpoint (b); |
5608 | } | |
5609 | ||
0101ce28 JJ |
5610 | struct captured_parse_breakpoint_args |
5611 | { | |
5612 | char **arg_p; | |
5613 | struct symtabs_and_lines *sals_p; | |
5614 | char ***addr_string_p; | |
5615 | int *not_found_ptr; | |
5616 | }; | |
5617 | ||
5618 | struct lang_and_radix | |
5619 | { | |
5620 | enum language lang; | |
5621 | int radix; | |
5622 | }; | |
5623 | ||
4efc6507 DE |
5624 | /* Create a breakpoint for JIT code registration and unregistration. */ |
5625 | ||
5626 | struct breakpoint * | |
5627 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
5628 | { | |
5629 | struct breakpoint *b; | |
5630 | ||
5631 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event); | |
5632 | update_global_location_list_nothrow (1); | |
5633 | return b; | |
5634 | } | |
0101ce28 | 5635 | |
cae688ec JJ |
5636 | void |
5637 | remove_solib_event_breakpoints (void) | |
5638 | { | |
5639 | struct breakpoint *b, *temp; | |
5640 | ||
5641 | ALL_BREAKPOINTS_SAFE (b, temp) | |
6c95b8df PA |
5642 | if (b->type == bp_shlib_event |
5643 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
5644 | delete_breakpoint (b); |
5645 | } | |
5646 | ||
5647 | struct breakpoint * | |
a6d9a66e | 5648 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
cae688ec JJ |
5649 | { |
5650 | struct breakpoint *b; | |
5651 | ||
a6d9a66e | 5652 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event); |
b60e7edf | 5653 | update_global_location_list_nothrow (1); |
cae688ec JJ |
5654 | return b; |
5655 | } | |
5656 | ||
5657 | /* Disable any breakpoints that are on code in shared libraries. Only | |
5658 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
5659 | ||
5660 | void | |
cb851954 | 5661 | disable_breakpoints_in_shlibs (void) |
cae688ec | 5662 | { |
876fa593 | 5663 | struct bp_location *loc, **locp_tmp; |
cae688ec | 5664 | |
876fa593 | 5665 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 5666 | { |
0d381245 VP |
5667 | struct breakpoint *b = loc->owner; |
5668 | /* We apply the check to all breakpoints, including disabled | |
5669 | for those with loc->duplicate set. This is so that when breakpoint | |
5670 | becomes enabled, or the duplicate is removed, gdb will try to insert | |
5671 | all breakpoints. If we don't set shlib_disabled here, we'll try | |
5672 | to insert those breakpoints and fail. */ | |
1042e4c0 | 5673 | if (((b->type == bp_breakpoint) |
508ccb1f | 5674 | || (b->type == bp_jit_event) |
1042e4c0 | 5675 | || (b->type == bp_hardware_breakpoint) |
7a697b8d | 5676 | || (tracepoint_type (b))) |
6c95b8df | 5677 | && loc->pspace == current_program_space |
0d381245 | 5678 | && !loc->shlib_disabled |
a77053c2 | 5679 | #ifdef PC_SOLIB |
0d381245 | 5680 | && PC_SOLIB (loc->address) |
a77053c2 | 5681 | #else |
6c95b8df | 5682 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 MK |
5683 | #endif |
5684 | ) | |
0d381245 VP |
5685 | { |
5686 | loc->shlib_disabled = 1; | |
5687 | } | |
cae688ec JJ |
5688 | } |
5689 | } | |
5690 | ||
84acb35a JJ |
5691 | /* Disable any breakpoints that are in in an unloaded shared library. Only |
5692 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
5693 | ||
75149521 | 5694 | static void |
84acb35a JJ |
5695 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
5696 | { | |
876fa593 | 5697 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
5698 | int disabled_shlib_breaks = 0; |
5699 | ||
c86cf029 VP |
5700 | /* SunOS a.out shared libraries are always mapped, so do not |
5701 | disable breakpoints; they will only be reported as unloaded | |
5702 | through clear_solib when GDB discards its shared library | |
5703 | list. See clear_solib for more information. */ | |
5704 | if (exec_bfd != NULL | |
5705 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
5706 | return; | |
5707 | ||
876fa593 | 5708 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 5709 | { |
0d381245 VP |
5710 | struct breakpoint *b = loc->owner; |
5711 | if ((loc->loc_type == bp_loc_hardware_breakpoint | |
5712 | || loc->loc_type == bp_loc_software_breakpoint) | |
6c95b8df | 5713 | && solib->pspace == loc->pspace |
e2dd7057 | 5714 | && !loc->shlib_disabled |
508ccb1f TT |
5715 | && (b->type == bp_breakpoint |
5716 | || b->type == bp_jit_event | |
5717 | || b->type == bp_hardware_breakpoint) | |
e2dd7057 | 5718 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 5719 | { |
e2dd7057 PP |
5720 | loc->shlib_disabled = 1; |
5721 | /* At this point, we cannot rely on remove_breakpoint | |
5722 | succeeding so we must mark the breakpoint as not inserted | |
5723 | to prevent future errors occurring in remove_breakpoints. */ | |
5724 | loc->inserted = 0; | |
5725 | if (!disabled_shlib_breaks) | |
5726 | { | |
5727 | target_terminal_ours_for_output (); | |
5728 | warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""), | |
5729 | solib->so_name); | |
84acb35a | 5730 | } |
e2dd7057 | 5731 | disabled_shlib_breaks = 1; |
84acb35a JJ |
5732 | } |
5733 | } | |
84acb35a JJ |
5734 | } |
5735 | ||
ce78b96d JB |
5736 | /* FORK & VFORK catchpoints. */ |
5737 | ||
5738 | /* Implement the "insert" breakpoint_ops method for fork catchpoints. */ | |
5739 | ||
c906108c | 5740 | static void |
ce78b96d JB |
5741 | insert_catch_fork (struct breakpoint *b) |
5742 | { | |
5743 | target_insert_fork_catchpoint (PIDGET (inferior_ptid)); | |
5744 | } | |
5745 | ||
5746 | /* Implement the "remove" breakpoint_ops method for fork catchpoints. */ | |
5747 | ||
5748 | static int | |
5749 | remove_catch_fork (struct breakpoint *b) | |
5750 | { | |
5751 | return target_remove_fork_catchpoint (PIDGET (inferior_ptid)); | |
5752 | } | |
5753 | ||
5754 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
5755 | catchpoints. */ | |
5756 | ||
5757 | static int | |
5758 | breakpoint_hit_catch_fork (struct breakpoint *b) | |
5759 | { | |
5760 | return inferior_has_forked (inferior_ptid, &b->forked_inferior_pid); | |
5761 | } | |
5762 | ||
5763 | /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */ | |
5764 | ||
5765 | static enum print_stop_action | |
5766 | print_it_catch_fork (struct breakpoint *b) | |
5767 | { | |
5768 | annotate_catchpoint (b->number); | |
5769 | printf_filtered (_("\nCatchpoint %d (forked process %d), "), | |
5770 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
5771 | return PRINT_SRC_AND_LOC; | |
5772 | } | |
5773 | ||
5774 | /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */ | |
5775 | ||
5776 | static void | |
a6d9a66e | 5777 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 5778 | { |
79a45b7d TT |
5779 | struct value_print_options opts; |
5780 | ||
5781 | get_user_print_options (&opts); | |
5782 | ||
ce78b96d JB |
5783 | /* Field 4, the address, is omitted (which makes the columns |
5784 | not line up too nicely with the headers, but the effect | |
5785 | is relatively readable). */ | |
79a45b7d | 5786 | if (opts.addressprint) |
ce78b96d JB |
5787 | ui_out_field_skip (uiout, "addr"); |
5788 | annotate_field (5); | |
5789 | ui_out_text (uiout, "fork"); | |
5790 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
5791 | { | |
5792 | ui_out_text (uiout, ", process "); | |
5793 | ui_out_field_int (uiout, "what", | |
5794 | ptid_get_pid (b->forked_inferior_pid)); | |
5795 | ui_out_spaces (uiout, 1); | |
5796 | } | |
5797 | } | |
5798 | ||
5799 | /* Implement the "print_mention" breakpoint_ops method for fork | |
5800 | catchpoints. */ | |
5801 | ||
5802 | static void | |
5803 | print_mention_catch_fork (struct breakpoint *b) | |
5804 | { | |
5805 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
5806 | } | |
5807 | ||
5808 | /* The breakpoint_ops structure to be used in fork catchpoints. */ | |
5809 | ||
5810 | static struct breakpoint_ops catch_fork_breakpoint_ops = | |
5811 | { | |
5812 | insert_catch_fork, | |
5813 | remove_catch_fork, | |
5814 | breakpoint_hit_catch_fork, | |
5815 | print_it_catch_fork, | |
5816 | print_one_catch_fork, | |
5817 | print_mention_catch_fork | |
5818 | }; | |
5819 | ||
5820 | /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */ | |
5821 | ||
5822 | static void | |
5823 | insert_catch_vfork (struct breakpoint *b) | |
5824 | { | |
5825 | target_insert_vfork_catchpoint (PIDGET (inferior_ptid)); | |
5826 | } | |
5827 | ||
5828 | /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */ | |
5829 | ||
5830 | static int | |
5831 | remove_catch_vfork (struct breakpoint *b) | |
5832 | { | |
5833 | return target_remove_vfork_catchpoint (PIDGET (inferior_ptid)); | |
5834 | } | |
5835 | ||
5836 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
5837 | catchpoints. */ | |
5838 | ||
5839 | static int | |
5840 | breakpoint_hit_catch_vfork (struct breakpoint *b) | |
5841 | { | |
5842 | return inferior_has_vforked (inferior_ptid, &b->forked_inferior_pid); | |
5843 | } | |
5844 | ||
5845 | /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */ | |
5846 | ||
5847 | static enum print_stop_action | |
5848 | print_it_catch_vfork (struct breakpoint *b) | |
5849 | { | |
5850 | annotate_catchpoint (b->number); | |
5851 | printf_filtered (_("\nCatchpoint %d (vforked process %d), "), | |
5852 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
5853 | return PRINT_SRC_AND_LOC; | |
5854 | } | |
5855 | ||
5856 | /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */ | |
5857 | ||
5858 | static void | |
a6d9a66e | 5859 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 5860 | { |
79a45b7d TT |
5861 | struct value_print_options opts; |
5862 | ||
5863 | get_user_print_options (&opts); | |
ce78b96d JB |
5864 | /* Field 4, the address, is omitted (which makes the columns |
5865 | not line up too nicely with the headers, but the effect | |
5866 | is relatively readable). */ | |
79a45b7d | 5867 | if (opts.addressprint) |
ce78b96d JB |
5868 | ui_out_field_skip (uiout, "addr"); |
5869 | annotate_field (5); | |
5870 | ui_out_text (uiout, "vfork"); | |
5871 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
5872 | { | |
5873 | ui_out_text (uiout, ", process "); | |
5874 | ui_out_field_int (uiout, "what", | |
5875 | ptid_get_pid (b->forked_inferior_pid)); | |
5876 | ui_out_spaces (uiout, 1); | |
5877 | } | |
5878 | } | |
5879 | ||
5880 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
5881 | catchpoints. */ | |
5882 | ||
5883 | static void | |
5884 | print_mention_catch_vfork (struct breakpoint *b) | |
5885 | { | |
5886 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
5887 | } | |
5888 | ||
5889 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ | |
5890 | ||
5891 | static struct breakpoint_ops catch_vfork_breakpoint_ops = | |
5892 | { | |
5893 | insert_catch_vfork, | |
5894 | remove_catch_vfork, | |
5895 | breakpoint_hit_catch_vfork, | |
5896 | print_it_catch_vfork, | |
5897 | print_one_catch_vfork, | |
5898 | print_mention_catch_vfork | |
5899 | }; | |
5900 | ||
a96d9b2e SDJ |
5901 | /* Implement the "insert" breakpoint_ops method for syscall |
5902 | catchpoints. */ | |
5903 | ||
5904 | static void | |
5905 | insert_catch_syscall (struct breakpoint *b) | |
5906 | { | |
5907 | struct inferior *inf = current_inferior (); | |
5908 | ||
5909 | ++inf->total_syscalls_count; | |
5910 | if (!b->syscalls_to_be_caught) | |
5911 | ++inf->any_syscall_count; | |
5912 | else | |
5913 | { | |
5914 | int i, iter; | |
5915 | for (i = 0; | |
5916 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
5917 | i++) | |
5918 | { | |
5919 | int elem; | |
5920 | if (iter >= VEC_length (int, inf->syscalls_counts)) | |
5921 | { | |
5922 | int old_size = VEC_length (int, inf->syscalls_counts); | |
5923 | uintptr_t vec_addr_offset = old_size * ((uintptr_t) sizeof (int)); | |
5924 | uintptr_t vec_addr; | |
5925 | VEC_safe_grow (int, inf->syscalls_counts, iter + 1); | |
5926 | vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) + | |
5927 | vec_addr_offset; | |
5928 | memset ((void *) vec_addr, 0, | |
5929 | (iter + 1 - old_size) * sizeof (int)); | |
5930 | } | |
5931 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
5932 | VEC_replace (int, inf->syscalls_counts, iter, ++elem); | |
5933 | } | |
5934 | } | |
5935 | ||
5936 | target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
5937 | inf->total_syscalls_count != 0, | |
5938 | inf->any_syscall_count, | |
5939 | VEC_length (int, inf->syscalls_counts), | |
5940 | VEC_address (int, inf->syscalls_counts)); | |
5941 | } | |
5942 | ||
5943 | /* Implement the "remove" breakpoint_ops method for syscall | |
5944 | catchpoints. */ | |
5945 | ||
5946 | static int | |
5947 | remove_catch_syscall (struct breakpoint *b) | |
5948 | { | |
5949 | struct inferior *inf = current_inferior (); | |
5950 | ||
5951 | --inf->total_syscalls_count; | |
5952 | if (!b->syscalls_to_be_caught) | |
5953 | --inf->any_syscall_count; | |
5954 | else | |
5955 | { | |
5956 | int i, iter; | |
5957 | for (i = 0; | |
5958 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
5959 | i++) | |
5960 | { | |
5961 | int elem; | |
5962 | if (iter >= VEC_length (int, inf->syscalls_counts)) | |
5963 | /* Shouldn't happen. */ | |
5964 | continue; | |
5965 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
5966 | VEC_replace (int, inf->syscalls_counts, iter, --elem); | |
5967 | } | |
5968 | } | |
5969 | ||
5970 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
5971 | inf->total_syscalls_count != 0, | |
5972 | inf->any_syscall_count, | |
5973 | VEC_length (int, inf->syscalls_counts), | |
5974 | VEC_address (int, inf->syscalls_counts)); | |
5975 | } | |
5976 | ||
5977 | /* Implement the "breakpoint_hit" breakpoint_ops method for syscall | |
5978 | catchpoints. */ | |
5979 | ||
5980 | static int | |
5981 | breakpoint_hit_catch_syscall (struct breakpoint *b) | |
5982 | { | |
5983 | /* We must check if we are catching specific syscalls in this breakpoint. | |
5984 | If we are, then we must guarantee that the called syscall is the same | |
5985 | syscall we are catching. */ | |
5986 | int syscall_number = 0; | |
5987 | ||
5988 | if (!inferior_has_called_syscall (inferior_ptid, &syscall_number)) | |
5989 | return 0; | |
5990 | ||
5991 | /* Now, checking if the syscall is the same. */ | |
5992 | if (b->syscalls_to_be_caught) | |
5993 | { | |
5994 | int i, iter; | |
5995 | for (i = 0; | |
5996 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
5997 | i++) | |
5998 | if (syscall_number == iter) | |
5999 | break; | |
6000 | /* Not the same. */ | |
6001 | if (!iter) | |
6002 | return 0; | |
6003 | } | |
6004 | ||
6005 | return 1; | |
6006 | } | |
6007 | ||
6008 | /* Implement the "print_it" breakpoint_ops method for syscall | |
6009 | catchpoints. */ | |
6010 | ||
6011 | static enum print_stop_action | |
6012 | print_it_catch_syscall (struct breakpoint *b) | |
6013 | { | |
6014 | /* These are needed because we want to know in which state a | |
6015 | syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY | |
6016 | or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we | |
6017 | must print "called syscall" or "returned from syscall". */ | |
6018 | ptid_t ptid; | |
6019 | struct target_waitstatus last; | |
6020 | struct syscall s; | |
6021 | struct cleanup *old_chain; | |
6022 | char *syscall_id; | |
6023 | ||
6024 | get_last_target_status (&ptid, &last); | |
6025 | ||
6026 | get_syscall_by_number (last.value.syscall_number, &s); | |
6027 | ||
6028 | annotate_catchpoint (b->number); | |
6029 | ||
6030 | if (s.name == NULL) | |
6031 | syscall_id = xstrprintf ("%d", last.value.syscall_number); | |
6032 | else | |
6033 | syscall_id = xstrprintf ("'%s'", s.name); | |
6034 | ||
6035 | old_chain = make_cleanup (xfree, syscall_id); | |
6036 | ||
6037 | if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) | |
6038 | printf_filtered (_("\nCatchpoint %d (call to syscall %s), "), | |
6039 | b->number, syscall_id); | |
6040 | else if (last.kind == TARGET_WAITKIND_SYSCALL_RETURN) | |
6041 | printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "), | |
6042 | b->number, syscall_id); | |
6043 | ||
6044 | do_cleanups (old_chain); | |
6045 | ||
6046 | return PRINT_SRC_AND_LOC; | |
6047 | } | |
6048 | ||
6049 | /* Implement the "print_one" breakpoint_ops method for syscall | |
6050 | catchpoints. */ | |
6051 | ||
6052 | static void | |
6053 | print_one_catch_syscall (struct breakpoint *b, | |
6054 | struct bp_location **last_loc) | |
6055 | { | |
6056 | struct value_print_options opts; | |
6057 | ||
6058 | get_user_print_options (&opts); | |
6059 | /* Field 4, the address, is omitted (which makes the columns | |
6060 | not line up too nicely with the headers, but the effect | |
6061 | is relatively readable). */ | |
6062 | if (opts.addressprint) | |
6063 | ui_out_field_skip (uiout, "addr"); | |
6064 | annotate_field (5); | |
6065 | ||
6066 | if (b->syscalls_to_be_caught | |
6067 | && VEC_length (int, b->syscalls_to_be_caught) > 1) | |
6068 | ui_out_text (uiout, "syscalls \""); | |
6069 | else | |
6070 | ui_out_text (uiout, "syscall \""); | |
6071 | ||
6072 | if (b->syscalls_to_be_caught) | |
6073 | { | |
6074 | int i, iter; | |
6075 | char *text = xstrprintf ("%s", ""); | |
6076 | for (i = 0; | |
6077 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6078 | i++) | |
6079 | { | |
6080 | char *x = text; | |
6081 | struct syscall s; | |
6082 | get_syscall_by_number (iter, &s); | |
6083 | ||
6084 | if (s.name != NULL) | |
6085 | text = xstrprintf ("%s%s, ", text, s.name); | |
6086 | else | |
6087 | text = xstrprintf ("%s%d, ", text, iter); | |
6088 | ||
6089 | /* We have to xfree the last 'text' (now stored at 'x') | |
6090 | because xstrprintf dinamically allocates new space for it | |
6091 | on every call. */ | |
6092 | xfree (x); | |
6093 | } | |
6094 | /* Remove the last comma. */ | |
6095 | text[strlen (text) - 2] = '\0'; | |
6096 | ui_out_field_string (uiout, "what", text); | |
6097 | } | |
6098 | else | |
6099 | ui_out_field_string (uiout, "what", "<any syscall>"); | |
6100 | ui_out_text (uiout, "\" "); | |
6101 | } | |
6102 | ||
6103 | /* Implement the "print_mention" breakpoint_ops method for syscall | |
6104 | catchpoints. */ | |
6105 | ||
6106 | static void | |
6107 | print_mention_catch_syscall (struct breakpoint *b) | |
6108 | { | |
6109 | if (b->syscalls_to_be_caught) | |
6110 | { | |
6111 | int i, iter; | |
6112 | ||
6113 | if (VEC_length (int, b->syscalls_to_be_caught) > 1) | |
6114 | printf_filtered (_("Catchpoint %d (syscalls"), b->number); | |
6115 | else | |
6116 | printf_filtered (_("Catchpoint %d (syscall"), b->number); | |
6117 | ||
6118 | for (i = 0; | |
6119 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6120 | i++) | |
6121 | { | |
6122 | struct syscall s; | |
6123 | get_syscall_by_number (iter, &s); | |
6124 | ||
6125 | if (s.name) | |
6126 | printf_filtered (" '%s' [%d]", s.name, s.number); | |
6127 | else | |
6128 | printf_filtered (" %d", s.number); | |
6129 | } | |
6130 | printf_filtered (")"); | |
6131 | } | |
6132 | else | |
6133 | printf_filtered (_("Catchpoint %d (any syscall)"), | |
6134 | b->number); | |
6135 | } | |
6136 | ||
6137 | /* The breakpoint_ops structure to be used in syscall catchpoints. */ | |
6138 | ||
6139 | static struct breakpoint_ops catch_syscall_breakpoint_ops = | |
6140 | { | |
6141 | insert_catch_syscall, | |
6142 | remove_catch_syscall, | |
6143 | breakpoint_hit_catch_syscall, | |
6144 | print_it_catch_syscall, | |
6145 | print_one_catch_syscall, | |
6146 | print_mention_catch_syscall | |
6147 | }; | |
6148 | ||
6149 | /* Returns non-zero if 'b' is a syscall catchpoint. */ | |
6150 | ||
6151 | static int | |
6152 | syscall_catchpoint_p (struct breakpoint *b) | |
6153 | { | |
6154 | return (b->ops == &catch_syscall_breakpoint_ops); | |
6155 | } | |
6156 | ||
6157 | /* Create a new breakpoint of the bp_catchpoint kind and return it, | |
6158 | but does NOT mention it nor update the global location list. | |
6159 | This is useful if you need to fill more fields in the | |
6160 | struct breakpoint before calling mention. | |
ce78b96d JB |
6161 | |
6162 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
6163 | If COND_STRING is not NULL, then store it in the breakpoint. | |
6164 | OPS, if not NULL, is the breakpoint_ops structure associated | |
6165 | to the catchpoint. */ | |
6166 | ||
6167 | static struct breakpoint * | |
a96d9b2e SDJ |
6168 | create_catchpoint_without_mention (struct gdbarch *gdbarch, int tempflag, |
6169 | char *cond_string, | |
6170 | struct breakpoint_ops *ops) | |
c906108c | 6171 | { |
c5aa993b JM |
6172 | struct symtab_and_line sal; |
6173 | struct breakpoint *b; | |
c5aa993b | 6174 | |
fe39c653 | 6175 | init_sal (&sal); |
6c95b8df | 6176 | sal.pspace = current_program_space; |
c5aa993b | 6177 | |
a6d9a66e | 6178 | b = set_raw_breakpoint (gdbarch, sal, bp_catchpoint); |
c906108c SS |
6179 | set_breakpoint_count (breakpoint_count + 1); |
6180 | b->number = breakpoint_count; | |
ce78b96d | 6181 | |
1b36a34b | 6182 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
ce78b96d | 6183 | b->thread = -1; |
c906108c | 6184 | b->addr_string = NULL; |
b5de0fa7 EZ |
6185 | b->enable_state = bp_enabled; |
6186 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
ce78b96d | 6187 | b->ops = ops; |
c5aa993b | 6188 | |
a96d9b2e SDJ |
6189 | return b; |
6190 | } | |
6191 | ||
6192 | /* Create a new breakpoint of the bp_catchpoint kind and return it. | |
6193 | ||
6194 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
6195 | If COND_STRING is not NULL, then store it in the breakpoint. | |
6196 | OPS, if not NULL, is the breakpoint_ops structure associated | |
6197 | to the catchpoint. */ | |
6198 | ||
6199 | static struct breakpoint * | |
6200 | create_catchpoint (struct gdbarch *gdbarch, int tempflag, | |
6201 | char *cond_string, struct breakpoint_ops *ops) | |
6202 | { | |
6203 | struct breakpoint *b = | |
6204 | create_catchpoint_without_mention (gdbarch, tempflag, cond_string, ops); | |
6205 | ||
c906108c | 6206 | mention (b); |
ce78b96d | 6207 | update_global_location_list (1); |
c906108c | 6208 | |
ce78b96d | 6209 | return b; |
c906108c | 6210 | } |
c5aa993b | 6211 | |
9b70b993 | 6212 | static void |
a6d9a66e UW |
6213 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
6214 | int tempflag, char *cond_string, | |
ce78b96d | 6215 | struct breakpoint_ops *ops) |
c906108c | 6216 | { |
a6d9a66e UW |
6217 | struct breakpoint *b |
6218 | = create_catchpoint (gdbarch, tempflag, cond_string, ops); | |
ce78b96d JB |
6219 | |
6220 | /* FIXME: We should put this information in a breakpoint private data | |
6221 | area. */ | |
6222 | b->forked_inferior_pid = null_ptid; | |
c906108c SS |
6223 | } |
6224 | ||
fe798b75 JB |
6225 | /* Exec catchpoints. */ |
6226 | ||
9b70b993 | 6227 | static void |
fe798b75 | 6228 | insert_catch_exec (struct breakpoint *b) |
c906108c | 6229 | { |
fe798b75 JB |
6230 | target_insert_exec_catchpoint (PIDGET (inferior_ptid)); |
6231 | } | |
c906108c | 6232 | |
fe798b75 JB |
6233 | static int |
6234 | remove_catch_exec (struct breakpoint *b) | |
6235 | { | |
6236 | return target_remove_exec_catchpoint (PIDGET (inferior_ptid)); | |
6237 | } | |
c906108c | 6238 | |
fe798b75 JB |
6239 | static int |
6240 | breakpoint_hit_catch_exec (struct breakpoint *b) | |
6241 | { | |
6242 | return inferior_has_execd (inferior_ptid, &b->exec_pathname); | |
6243 | } | |
c906108c | 6244 | |
fe798b75 JB |
6245 | static enum print_stop_action |
6246 | print_it_catch_exec (struct breakpoint *b) | |
6247 | { | |
6248 | annotate_catchpoint (b->number); | |
6249 | printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number, | |
6250 | b->exec_pathname); | |
6251 | return PRINT_SRC_AND_LOC; | |
c906108c SS |
6252 | } |
6253 | ||
fe798b75 | 6254 | static void |
a6d9a66e | 6255 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 JB |
6256 | { |
6257 | struct value_print_options opts; | |
6258 | ||
6259 | get_user_print_options (&opts); | |
6260 | ||
6261 | /* Field 4, the address, is omitted (which makes the columns | |
6262 | not line up too nicely with the headers, but the effect | |
6263 | is relatively readable). */ | |
6264 | if (opts.addressprint) | |
6265 | ui_out_field_skip (uiout, "addr"); | |
6266 | annotate_field (5); | |
6267 | ui_out_text (uiout, "exec"); | |
6268 | if (b->exec_pathname != NULL) | |
6269 | { | |
6270 | ui_out_text (uiout, ", program \""); | |
6271 | ui_out_field_string (uiout, "what", b->exec_pathname); | |
6272 | ui_out_text (uiout, "\" "); | |
6273 | } | |
6274 | } | |
6275 | ||
6276 | static void | |
6277 | print_mention_catch_exec (struct breakpoint *b) | |
6278 | { | |
6279 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
6280 | } | |
6281 | ||
6282 | static struct breakpoint_ops catch_exec_breakpoint_ops = | |
6283 | { | |
6284 | insert_catch_exec, | |
6285 | remove_catch_exec, | |
6286 | breakpoint_hit_catch_exec, | |
6287 | print_it_catch_exec, | |
6288 | print_one_catch_exec, | |
6289 | print_mention_catch_exec | |
6290 | }; | |
6291 | ||
a96d9b2e SDJ |
6292 | static void |
6293 | create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, | |
6294 | struct breakpoint_ops *ops) | |
6295 | { | |
6296 | struct gdbarch *gdbarch = get_current_arch (); | |
6297 | struct breakpoint *b = | |
6298 | create_catchpoint_without_mention (gdbarch, tempflag, NULL, ops); | |
6299 | ||
6300 | b->syscalls_to_be_caught = filter; | |
6301 | ||
6302 | /* Now, we have to mention the breakpoint and update the global | |
6303 | location list. */ | |
6304 | mention (b); | |
6305 | update_global_location_list (1); | |
6306 | } | |
6307 | ||
c906108c | 6308 | static int |
fba45db2 | 6309 | hw_breakpoint_used_count (void) |
c906108c | 6310 | { |
52f0bd74 | 6311 | struct breakpoint *b; |
c906108c SS |
6312 | int i = 0; |
6313 | ||
6314 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6315 | { |
d6b74ac4 | 6316 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
c5aa993b JM |
6317 | i++; |
6318 | } | |
c906108c SS |
6319 | |
6320 | return i; | |
6321 | } | |
6322 | ||
6323 | static int | |
fba45db2 | 6324 | hw_watchpoint_used_count (enum bptype type, int *other_type_used) |
c906108c | 6325 | { |
52f0bd74 | 6326 | struct breakpoint *b; |
c906108c SS |
6327 | int i = 0; |
6328 | ||
6329 | *other_type_used = 0; | |
6330 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6331 | { |
468d015d | 6332 | if (breakpoint_enabled (b)) |
c5aa993b JM |
6333 | { |
6334 | if (b->type == type) | |
6335 | i++; | |
059fb39f PM |
6336 | else if ((b->type == bp_hardware_watchpoint |
6337 | || b->type == bp_read_watchpoint | |
6338 | || b->type == bp_access_watchpoint)) | |
c5aa993b JM |
6339 | *other_type_used = 1; |
6340 | } | |
6341 | } | |
c906108c SS |
6342 | return i; |
6343 | } | |
6344 | ||
c906108c | 6345 | void |
fba45db2 | 6346 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 6347 | { |
c5aa993b | 6348 | struct breakpoint *b; |
c906108c SS |
6349 | |
6350 | ALL_BREAKPOINTS (b) | |
c5aa993b JM |
6351 | { |
6352 | if (((b->type == bp_watchpoint) | |
6353 | || (b->type == bp_hardware_watchpoint) | |
6354 | || (b->type == bp_read_watchpoint) | |
dfdfb3ca | 6355 | || (b->type == bp_access_watchpoint)) |
468d015d | 6356 | && breakpoint_enabled (b)) |
c5aa993b | 6357 | { |
b5de0fa7 | 6358 | b->enable_state = bp_call_disabled; |
b60e7edf | 6359 | update_global_location_list (0); |
c5aa993b JM |
6360 | } |
6361 | } | |
c906108c SS |
6362 | } |
6363 | ||
6364 | void | |
fba45db2 | 6365 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 6366 | { |
c5aa993b | 6367 | struct breakpoint *b; |
c906108c SS |
6368 | |
6369 | ALL_BREAKPOINTS (b) | |
c5aa993b JM |
6370 | { |
6371 | if (((b->type == bp_watchpoint) | |
6372 | || (b->type == bp_hardware_watchpoint) | |
6373 | || (b->type == bp_read_watchpoint) | |
dfdfb3ca | 6374 | || (b->type == bp_access_watchpoint)) |
b5de0fa7 | 6375 | && (b->enable_state == bp_call_disabled)) |
c5aa993b | 6376 | { |
b5de0fa7 | 6377 | b->enable_state = bp_enabled; |
b60e7edf | 6378 | update_global_location_list (1); |
c5aa993b JM |
6379 | } |
6380 | } | |
c906108c SS |
6381 | } |
6382 | ||
8bea4e01 UW |
6383 | void |
6384 | disable_breakpoints_before_startup (void) | |
6385 | { | |
6386 | struct breakpoint *b; | |
6387 | int found = 0; | |
6388 | ||
6389 | ALL_BREAKPOINTS (b) | |
6390 | { | |
6c95b8df PA |
6391 | if (b->pspace != current_program_space) |
6392 | continue; | |
6393 | ||
8bea4e01 UW |
6394 | if ((b->type == bp_breakpoint |
6395 | || b->type == bp_hardware_breakpoint) | |
6396 | && breakpoint_enabled (b)) | |
6397 | { | |
6398 | b->enable_state = bp_startup_disabled; | |
6399 | found = 1; | |
6400 | } | |
6401 | } | |
6402 | ||
6403 | if (found) | |
6404 | update_global_location_list (0); | |
6405 | ||
6c95b8df | 6406 | current_program_space->executing_startup = 1; |
8bea4e01 UW |
6407 | } |
6408 | ||
6409 | void | |
6410 | enable_breakpoints_after_startup (void) | |
6411 | { | |
6412 | struct breakpoint *b; | |
6413 | int found = 0; | |
6414 | ||
6c95b8df | 6415 | current_program_space->executing_startup = 0; |
8bea4e01 UW |
6416 | |
6417 | ALL_BREAKPOINTS (b) | |
6418 | { | |
6c95b8df PA |
6419 | if (b->pspace != current_program_space) |
6420 | continue; | |
6421 | ||
8bea4e01 UW |
6422 | if ((b->type == bp_breakpoint |
6423 | || b->type == bp_hardware_breakpoint) | |
6424 | && b->enable_state == bp_startup_disabled) | |
6425 | { | |
6426 | b->enable_state = bp_enabled; | |
6427 | found = 1; | |
6428 | } | |
6429 | } | |
6430 | ||
6431 | if (found) | |
6432 | breakpoint_re_set (); | |
6433 | } | |
6434 | ||
c906108c SS |
6435 | |
6436 | /* Set a breakpoint that will evaporate an end of command | |
6437 | at address specified by SAL. | |
6438 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
6439 | ||
6440 | struct breakpoint * | |
a6d9a66e UW |
6441 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
6442 | struct frame_id frame_id, enum bptype type) | |
c906108c | 6443 | { |
52f0bd74 | 6444 | struct breakpoint *b; |
edb3359d DJ |
6445 | |
6446 | /* If FRAME_ID is valid, it should be a real frame, not an inlined | |
6447 | one. */ | |
6448 | gdb_assert (!frame_id_inlined_p (frame_id)); | |
6449 | ||
a6d9a66e | 6450 | b = set_raw_breakpoint (gdbarch, sal, type); |
b5de0fa7 EZ |
6451 | b->enable_state = bp_enabled; |
6452 | b->disposition = disp_donttouch; | |
818dd999 | 6453 | b->frame_id = frame_id; |
c906108c SS |
6454 | |
6455 | /* If we're debugging a multi-threaded program, then we | |
6456 | want momentary breakpoints to be active in only a | |
6457 | single thread of control. */ | |
39f77062 KB |
6458 | if (in_thread_list (inferior_ptid)) |
6459 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 6460 | |
b60e7edf | 6461 | update_global_location_list_nothrow (1); |
74960c60 | 6462 | |
c906108c SS |
6463 | return b; |
6464 | } | |
611c83ae | 6465 | |
e58b0e63 PA |
6466 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
6467 | ORIG is NULL. */ | |
6468 | ||
6469 | struct breakpoint * | |
6470 | clone_momentary_breakpoint (struct breakpoint *orig) | |
6471 | { | |
6472 | struct breakpoint *copy; | |
6473 | ||
6474 | /* If there's nothing to clone, then return nothing. */ | |
6475 | if (orig == NULL) | |
6476 | return NULL; | |
6477 | ||
a6d9a66e | 6478 | copy = set_raw_breakpoint_without_location (orig->gdbarch, orig->type); |
e58b0e63 PA |
6479 | copy->loc = allocate_bp_location (copy); |
6480 | set_breakpoint_location_function (copy->loc); | |
6481 | ||
a6d9a66e | 6482 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
6483 | copy->loc->requested_address = orig->loc->requested_address; |
6484 | copy->loc->address = orig->loc->address; | |
6485 | copy->loc->section = orig->loc->section; | |
6c95b8df | 6486 | copy->loc->pspace = orig->loc->pspace; |
e58b0e63 PA |
6487 | |
6488 | if (orig->source_file == NULL) | |
6489 | copy->source_file = NULL; | |
6490 | else | |
6491 | copy->source_file = xstrdup (orig->source_file); | |
6492 | ||
6493 | copy->line_number = orig->line_number; | |
6494 | copy->frame_id = orig->frame_id; | |
6495 | copy->thread = orig->thread; | |
6c95b8df | 6496 | copy->pspace = orig->pspace; |
e58b0e63 PA |
6497 | |
6498 | copy->enable_state = bp_enabled; | |
6499 | copy->disposition = disp_donttouch; | |
6500 | copy->number = internal_breakpoint_number--; | |
6501 | ||
6502 | update_global_location_list_nothrow (0); | |
6503 | return copy; | |
6504 | } | |
6505 | ||
611c83ae | 6506 | struct breakpoint * |
a6d9a66e UW |
6507 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
6508 | enum bptype type) | |
611c83ae PA |
6509 | { |
6510 | struct symtab_and_line sal; | |
6511 | ||
6512 | sal = find_pc_line (pc, 0); | |
6513 | sal.pc = pc; | |
6514 | sal.section = find_pc_overlay (pc); | |
6515 | sal.explicit_pc = 1; | |
6516 | ||
a6d9a66e | 6517 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 6518 | } |
c906108c | 6519 | \f |
c5aa993b | 6520 | |
c906108c SS |
6521 | /* Tell the user we have just set a breakpoint B. */ |
6522 | ||
6523 | static void | |
fba45db2 | 6524 | mention (struct breakpoint *b) |
c906108c SS |
6525 | { |
6526 | int say_where = 0; | |
fa8a61dc | 6527 | struct cleanup *ui_out_chain; |
79a45b7d TT |
6528 | struct value_print_options opts; |
6529 | ||
6530 | get_user_print_options (&opts); | |
8b93c638 | 6531 | |
9a4105ab AC |
6532 | /* FIXME: This is misplaced; mention() is called by things (like |
6533 | hitting a watchpoint) other than breakpoint creation. It should | |
6534 | be possible to clean this up and at the same time replace the | |
7f4b89d1 | 6535 | random calls to breakpoint_changed with this hook. */ |
383f836e | 6536 | observer_notify_breakpoint_created (b->number); |
c906108c | 6537 | |
3086aeae DJ |
6538 | if (b->ops != NULL && b->ops->print_mention != NULL) |
6539 | b->ops->print_mention (b); | |
6540 | else | |
6541 | switch (b->type) | |
6542 | { | |
6543 | case bp_none: | |
a3f17187 | 6544 | printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b->number); |
3086aeae DJ |
6545 | break; |
6546 | case bp_watchpoint: | |
6547 | ui_out_text (uiout, "Watchpoint "); | |
6548 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
6549 | ui_out_field_int (uiout, "number", b->number); | |
6550 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6551 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6552 | do_cleanups (ui_out_chain); |
6553 | break; | |
6554 | case bp_hardware_watchpoint: | |
6555 | ui_out_text (uiout, "Hardware watchpoint "); | |
6556 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
6557 | ui_out_field_int (uiout, "number", b->number); | |
6558 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6559 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6560 | do_cleanups (ui_out_chain); |
6561 | break; | |
6562 | case bp_read_watchpoint: | |
6563 | ui_out_text (uiout, "Hardware read watchpoint "); | |
6564 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
6565 | ui_out_field_int (uiout, "number", b->number); | |
6566 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6567 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6568 | do_cleanups (ui_out_chain); |
6569 | break; | |
6570 | case bp_access_watchpoint: | |
6571 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
6572 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
6573 | ui_out_field_int (uiout, "number", b->number); | |
6574 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6575 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6576 | do_cleanups (ui_out_chain); |
6577 | break; | |
6578 | case bp_breakpoint: | |
6579 | if (ui_out_is_mi_like_p (uiout)) | |
6580 | { | |
6581 | say_where = 0; | |
6582 | break; | |
6583 | } | |
2cec12e5 AR |
6584 | if (b->disposition == disp_del) |
6585 | printf_filtered (_("Temporary breakpoint")); | |
6586 | else | |
6587 | printf_filtered (_("Breakpoint")); | |
6588 | printf_filtered (_(" %d"), b->number); | |
3086aeae DJ |
6589 | say_where = 1; |
6590 | break; | |
6591 | case bp_hardware_breakpoint: | |
6592 | if (ui_out_is_mi_like_p (uiout)) | |
6593 | { | |
6594 | say_where = 0; | |
6595 | break; | |
6596 | } | |
a3f17187 | 6597 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); |
3086aeae DJ |
6598 | say_where = 1; |
6599 | break; | |
1042e4c0 SS |
6600 | case bp_tracepoint: |
6601 | if (ui_out_is_mi_like_p (uiout)) | |
6602 | { | |
6603 | say_where = 0; | |
6604 | break; | |
6605 | } | |
6606 | printf_filtered (_("Tracepoint")); | |
6607 | printf_filtered (_(" %d"), b->number); | |
6608 | say_where = 1; | |
6609 | break; | |
7a697b8d SS |
6610 | case bp_fast_tracepoint: |
6611 | if (ui_out_is_mi_like_p (uiout)) | |
6612 | { | |
6613 | say_where = 0; | |
6614 | break; | |
6615 | } | |
6616 | printf_filtered (_("Fast tracepoint")); | |
6617 | printf_filtered (_(" %d"), b->number); | |
6618 | say_where = 1; | |
6619 | break; | |
3086aeae DJ |
6620 | |
6621 | case bp_until: | |
6622 | case bp_finish: | |
6623 | case bp_longjmp: | |
6624 | case bp_longjmp_resume: | |
6625 | case bp_step_resume: | |
3086aeae | 6626 | case bp_call_dummy: |
aa7d318d | 6627 | case bp_std_terminate: |
3086aeae DJ |
6628 | case bp_watchpoint_scope: |
6629 | case bp_shlib_event: | |
6630 | case bp_thread_event: | |
6631 | case bp_overlay_event: | |
4efc6507 | 6632 | case bp_jit_event: |
0fd8e87f | 6633 | case bp_longjmp_master: |
aa7d318d | 6634 | case bp_std_terminate_master: |
3086aeae DJ |
6635 | break; |
6636 | } | |
c906108c | 6637 | |
c906108c SS |
6638 | if (say_where) |
6639 | { | |
a3f17187 AC |
6640 | /* i18n: cagney/2005-02-11: Below needs to be merged into a |
6641 | single string. */ | |
0d381245 | 6642 | if (b->loc == NULL) |
c906108c | 6643 | { |
a3f17187 | 6644 | printf_filtered (_(" (%s) pending."), b->addr_string); |
0101ce28 JJ |
6645 | } |
6646 | else | |
6647 | { | |
79a45b7d | 6648 | if (opts.addressprint || b->source_file == NULL) |
0101ce28 JJ |
6649 | { |
6650 | printf_filtered (" at "); | |
5af949e3 UW |
6651 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), |
6652 | gdb_stdout); | |
0101ce28 JJ |
6653 | } |
6654 | if (b->source_file) | |
6655 | printf_filtered (": file %s, line %d.", | |
6656 | b->source_file, b->line_number); | |
0d381245 VP |
6657 | |
6658 | if (b->loc->next) | |
6659 | { | |
6660 | struct bp_location *loc = b->loc; | |
6661 | int n = 0; | |
6662 | for (; loc; loc = loc->next) | |
6663 | ++n; | |
6664 | printf_filtered (" (%d locations)", n); | |
6665 | } | |
6666 | ||
c906108c | 6667 | } |
c906108c | 6668 | } |
9dc5e2a9 | 6669 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 6670 | return; |
c906108c SS |
6671 | printf_filtered ("\n"); |
6672 | } | |
c906108c | 6673 | \f |
c5aa993b | 6674 | |
0d381245 | 6675 | static struct bp_location * |
39d61571 | 6676 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
6677 | const struct symtab_and_line *sal) |
6678 | { | |
6679 | struct bp_location *loc, **tmp; | |
6680 | ||
39d61571 | 6681 | loc = allocate_bp_location (b); |
0d381245 VP |
6682 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
6683 | ; | |
6684 | *tmp = loc; | |
a6d9a66e UW |
6685 | loc->gdbarch = get_sal_arch (*sal); |
6686 | if (!loc->gdbarch) | |
6687 | loc->gdbarch = b->gdbarch; | |
0d381245 | 6688 | loc->requested_address = sal->pc; |
a6d9a66e UW |
6689 | loc->address = adjust_breakpoint_address (loc->gdbarch, |
6690 | loc->requested_address, b->type); | |
6c95b8df PA |
6691 | loc->pspace = sal->pspace; |
6692 | gdb_assert (loc->pspace != NULL); | |
0d381245 VP |
6693 | loc->section = sal->section; |
6694 | ||
6695 | set_breakpoint_location_function (loc); | |
6696 | return loc; | |
6697 | } | |
514f746b AR |
6698 | \f |
6699 | ||
6700 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
6701 | return 0 otherwise. */ | |
6702 | ||
6703 | static int | |
6704 | bp_loc_is_permanent (struct bp_location *loc) | |
6705 | { | |
6706 | int len; | |
6707 | CORE_ADDR addr; | |
6708 | const gdb_byte *brk; | |
6709 | gdb_byte *target_mem; | |
939c61fa JK |
6710 | struct cleanup *cleanup; |
6711 | int retval = 0; | |
514f746b AR |
6712 | |
6713 | gdb_assert (loc != NULL); | |
6714 | ||
6715 | addr = loc->address; | |
a6d9a66e | 6716 | brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 6717 | |
939c61fa JK |
6718 | /* Software breakpoints unsupported? */ |
6719 | if (brk == NULL) | |
6720 | return 0; | |
6721 | ||
514f746b AR |
6722 | target_mem = alloca (len); |
6723 | ||
939c61fa JK |
6724 | /* Enable the automatic memory restoration from breakpoints while |
6725 | we read the memory. Otherwise we could say about our temporary | |
6726 | breakpoints they are permanent. */ | |
6c95b8df PA |
6727 | cleanup = save_current_space_and_thread (); |
6728 | ||
6729 | switch_to_program_space_and_thread (loc->pspace); | |
6730 | make_show_memory_breakpoints_cleanup (0); | |
939c61fa | 6731 | |
514f746b AR |
6732 | if (target_read_memory (loc->address, target_mem, len) == 0 |
6733 | && memcmp (target_mem, brk, len) == 0) | |
939c61fa | 6734 | retval = 1; |
514f746b | 6735 | |
939c61fa JK |
6736 | do_cleanups (cleanup); |
6737 | ||
6738 | return retval; | |
514f746b AR |
6739 | } |
6740 | ||
6741 | ||
c3f6f71d | 6742 | |
018d34a4 VP |
6743 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
6744 | as textual description of the location, and COND_STRING | |
db107f19 | 6745 | as condition expression. */ |
018d34a4 VP |
6746 | |
6747 | static void | |
8cdf0e15 VP |
6748 | create_breakpoint_sal (struct gdbarch *gdbarch, |
6749 | struct symtabs_and_lines sals, char *addr_string, | |
6750 | char *cond_string, | |
6751 | enum bptype type, enum bpdisp disposition, | |
6752 | int thread, int task, int ignore_count, | |
6753 | struct breakpoint_ops *ops, int from_tty, int enabled) | |
018d34a4 | 6754 | { |
0d381245 VP |
6755 | struct breakpoint *b = NULL; |
6756 | int i; | |
018d34a4 VP |
6757 | |
6758 | if (type == bp_hardware_breakpoint) | |
6759 | { | |
6760 | int i = hw_breakpoint_used_count (); | |
6761 | int target_resources_ok = | |
d92524f1 | 6762 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
018d34a4 VP |
6763 | i + 1, 0); |
6764 | if (target_resources_ok == 0) | |
6765 | error (_("No hardware breakpoint support in the target.")); | |
6766 | else if (target_resources_ok < 0) | |
6767 | error (_("Hardware breakpoints used exceeds limit.")); | |
6768 | } | |
6769 | ||
6c95b8df PA |
6770 | gdb_assert (sals.nelts > 0); |
6771 | ||
0d381245 VP |
6772 | for (i = 0; i < sals.nelts; ++i) |
6773 | { | |
6774 | struct symtab_and_line sal = sals.sals[i]; | |
6775 | struct bp_location *loc; | |
6776 | ||
6777 | if (from_tty) | |
5af949e3 UW |
6778 | { |
6779 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
6780 | if (!loc_gdbarch) | |
6781 | loc_gdbarch = gdbarch; | |
6782 | ||
6783 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 6784 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 6785 | } |
0d381245 VP |
6786 | |
6787 | if (i == 0) | |
6788 | { | |
a6d9a66e | 6789 | b = set_raw_breakpoint (gdbarch, sal, type); |
0d381245 VP |
6790 | set_breakpoint_count (breakpoint_count + 1); |
6791 | b->number = breakpoint_count; | |
6792 | b->thread = thread; | |
4a306c9a | 6793 | b->task = task; |
018d34a4 | 6794 | |
0d381245 VP |
6795 | b->cond_string = cond_string; |
6796 | b->ignore_count = ignore_count; | |
41447f92 | 6797 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 6798 | b->disposition = disposition; |
018d34a4 | 6799 | |
6c95b8df PA |
6800 | b->pspace = sals.sals[0].pspace; |
6801 | ||
6802 | if (enabled && b->pspace->executing_startup | |
8bea4e01 UW |
6803 | && (b->type == bp_breakpoint |
6804 | || b->type == bp_hardware_breakpoint)) | |
6805 | b->enable_state = bp_startup_disabled; | |
6806 | ||
0d381245 VP |
6807 | loc = b->loc; |
6808 | } | |
6809 | else | |
018d34a4 | 6810 | { |
39d61571 | 6811 | loc = add_location_to_breakpoint (b, &sal); |
0d381245 VP |
6812 | } |
6813 | ||
514f746b AR |
6814 | if (bp_loc_is_permanent (loc)) |
6815 | make_breakpoint_permanent (b); | |
6816 | ||
0d381245 VP |
6817 | if (b->cond_string) |
6818 | { | |
6819 | char *arg = b->cond_string; | |
d32a6982 | 6820 | loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0); |
0d381245 | 6821 | if (*arg) |
db107f19 | 6822 | error (_("Garbage %s follows condition"), arg); |
018d34a4 | 6823 | } |
0d381245 | 6824 | } |
018d34a4 VP |
6825 | |
6826 | if (addr_string) | |
6827 | b->addr_string = addr_string; | |
6828 | else | |
6829 | /* addr_string has to be used or breakpoint_re_set will delete | |
6830 | me. */ | |
5af949e3 UW |
6831 | b->addr_string |
6832 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
018d34a4 | 6833 | |
604133b5 | 6834 | b->ops = ops; |
018d34a4 VP |
6835 | mention (b); |
6836 | } | |
6837 | ||
ed0616c6 VP |
6838 | /* Remove element at INDEX_TO_REMOVE from SAL, shifting other |
6839 | elements to fill the void space. */ | |
2c0b251b PA |
6840 | static void |
6841 | remove_sal (struct symtabs_and_lines *sal, int index_to_remove) | |
ed0616c6 VP |
6842 | { |
6843 | int i = index_to_remove+1; | |
6844 | int last_index = sal->nelts-1; | |
6845 | ||
6846 | for (;i <= last_index; ++i) | |
6847 | sal->sals[i-1] = sal->sals[i]; | |
6848 | ||
6849 | --(sal->nelts); | |
6850 | } | |
6851 | ||
6c95b8df PA |
6852 | /* If appropriate, obtains all sals that correspond to the same file |
6853 | and line as SAL, in all program spaces. Users debugging with IDEs, | |
6854 | will want to set a breakpoint at foo.c:line, and not really care | |
6855 | about program spaces. This is done only if SAL does not have | |
6856 | explicit PC and has line and file information. If we got just a | |
6857 | single expanded sal, return the original. | |
ed0616c6 | 6858 | |
6c95b8df PA |
6859 | Otherwise, if SAL.explicit_line is not set, filter out all sals for |
6860 | which the name of enclosing function is different from SAL. This | |
6861 | makes sure that if we have breakpoint originally set in template | |
6862 | instantiation, say foo<int>(), we won't expand SAL to locations at | |
6863 | the same line in all existing instantiations of 'foo'. */ | |
ed0616c6 | 6864 | |
2c0b251b | 6865 | static struct symtabs_and_lines |
ed0616c6 VP |
6866 | expand_line_sal_maybe (struct symtab_and_line sal) |
6867 | { | |
6868 | struct symtabs_and_lines expanded; | |
6869 | CORE_ADDR original_pc = sal.pc; | |
6870 | char *original_function = NULL; | |
6871 | int found; | |
6872 | int i; | |
6c95b8df | 6873 | struct cleanup *old_chain; |
ed0616c6 VP |
6874 | |
6875 | /* If we have explicit pc, don't expand. | |
6876 | If we have no line number, we can't expand. */ | |
6877 | if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL) | |
6878 | { | |
6879 | expanded.nelts = 1; | |
6880 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
6881 | expanded.sals[0] = sal; | |
6882 | return expanded; | |
6883 | } | |
6884 | ||
6885 | sal.pc = 0; | |
6c95b8df PA |
6886 | |
6887 | old_chain = save_current_space_and_thread (); | |
6888 | ||
6889 | switch_to_program_space_and_thread (sal.pspace); | |
6890 | ||
ed0616c6 | 6891 | find_pc_partial_function (original_pc, &original_function, NULL, NULL); |
6c95b8df PA |
6892 | |
6893 | /* Note that expand_line_sal visits *all* program spaces. */ | |
ed0616c6 | 6894 | expanded = expand_line_sal (sal); |
6c95b8df | 6895 | |
ed0616c6 VP |
6896 | if (expanded.nelts == 1) |
6897 | { | |
3dba1c98 JB |
6898 | /* We had one sal, we got one sal. Return that sal, adjusting it |
6899 | past the function prologue if necessary. */ | |
ed0616c6 VP |
6900 | xfree (expanded.sals); |
6901 | expanded.nelts = 1; | |
6902 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
6903 | sal.pc = original_pc; | |
6904 | expanded.sals[0] = sal; | |
3dba1c98 | 6905 | skip_prologue_sal (&expanded.sals[0]); |
6c95b8df | 6906 | do_cleanups (old_chain); |
ed0616c6 VP |
6907 | return expanded; |
6908 | } | |
6909 | ||
6910 | if (!sal.explicit_line) | |
6911 | { | |
6912 | CORE_ADDR func_addr, func_end; | |
6913 | for (i = 0; i < expanded.nelts; ++i) | |
6914 | { | |
6915 | CORE_ADDR pc = expanded.sals[i].pc; | |
6916 | char *this_function; | |
6c95b8df PA |
6917 | |
6918 | /* We need to switch threads as well since we're about to | |
6919 | read memory. */ | |
6920 | switch_to_program_space_and_thread (expanded.sals[i].pspace); | |
6921 | ||
ed0616c6 VP |
6922 | if (find_pc_partial_function (pc, &this_function, |
6923 | &func_addr, &func_end)) | |
6924 | { | |
059fb39f PM |
6925 | if (this_function |
6926 | && strcmp (this_function, original_function) != 0) | |
ed0616c6 VP |
6927 | { |
6928 | remove_sal (&expanded, i); | |
6929 | --i; | |
6930 | } | |
ed0616c6 VP |
6931 | } |
6932 | } | |
6933 | } | |
059acae7 UW |
6934 | |
6935 | /* Skip the function prologue if necessary. */ | |
6936 | for (i = 0; i < expanded.nelts; ++i) | |
6937 | skip_prologue_sal (&expanded.sals[i]); | |
ed0616c6 | 6938 | |
6c95b8df PA |
6939 | do_cleanups (old_chain); |
6940 | ||
ed0616c6 VP |
6941 | if (expanded.nelts <= 1) |
6942 | { | |
6943 | /* This is un ugly workaround. If we get zero | |
6944 | expanded sals then something is really wrong. | |
6945 | Fix that by returnign the original sal. */ | |
6946 | xfree (expanded.sals); | |
6947 | expanded.nelts = 1; | |
6948 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
6949 | sal.pc = original_pc; | |
6950 | expanded.sals[0] = sal; | |
6951 | return expanded; | |
6952 | } | |
6953 | ||
6954 | if (original_pc) | |
6955 | { | |
6956 | found = 0; | |
6957 | for (i = 0; i < expanded.nelts; ++i) | |
6958 | if (expanded.sals[i].pc == original_pc) | |
6959 | { | |
6960 | found = 1; | |
6961 | break; | |
6962 | } | |
6963 | gdb_assert (found); | |
6964 | } | |
6965 | ||
6966 | return expanded; | |
6967 | } | |
6968 | ||
018d34a4 VP |
6969 | /* Add SALS.nelts breakpoints to the breakpoint table. For each |
6970 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
6971 | value. COND_STRING, if not NULL, specified the condition to be | |
6972 | used for all breakpoints. Essentially the only case where | |
6973 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
6974 | function. In that case, it's still not possible to specify | |
6975 | separate conditions for different overloaded functions, so | |
6976 | we take just a single condition string. | |
6977 | ||
c3f6f71d | 6978 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 6979 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
6980 | array contents). If the function fails (error() is called), the |
6981 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
6982 | COND and SALS arrays and each of those arrays contents. */ | |
c906108c SS |
6983 | |
6984 | static void | |
8cdf0e15 VP |
6985 | create_breakpoints_sal (struct gdbarch *gdbarch, |
6986 | struct symtabs_and_lines sals, char **addr_string, | |
6987 | char *cond_string, | |
6988 | enum bptype type, enum bpdisp disposition, | |
6989 | int thread, int task, int ignore_count, | |
6990 | struct breakpoint_ops *ops, int from_tty, | |
6991 | int enabled) | |
c906108c | 6992 | { |
018d34a4 VP |
6993 | int i; |
6994 | for (i = 0; i < sals.nelts; ++i) | |
c3f6f71d | 6995 | { |
ed0616c6 VP |
6996 | struct symtabs_and_lines expanded = |
6997 | expand_line_sal_maybe (sals.sals[i]); | |
0d381245 | 6998 | |
8cdf0e15 VP |
6999 | create_breakpoint_sal (gdbarch, expanded, addr_string[i], |
7000 | cond_string, type, disposition, | |
7001 | thread, task, ignore_count, ops, from_tty, enabled); | |
c3f6f71d | 7002 | } |
c3f6f71d | 7003 | } |
c906108c | 7004 | |
c3f6f71d JM |
7005 | /* Parse ARG which is assumed to be a SAL specification possibly |
7006 | followed by conditionals. On return, SALS contains an array of SAL | |
7007 | addresses found. ADDR_STRING contains a vector of (canonical) | |
7008 | address strings. ARG points to the end of the SAL. */ | |
c906108c | 7009 | |
b9362cc7 | 7010 | static void |
c3f6f71d JM |
7011 | parse_breakpoint_sals (char **address, |
7012 | struct symtabs_and_lines *sals, | |
0101ce28 JJ |
7013 | char ***addr_string, |
7014 | int *not_found_ptr) | |
c3f6f71d JM |
7015 | { |
7016 | char *addr_start = *address; | |
7017 | *addr_string = NULL; | |
7018 | /* If no arg given, or if first arg is 'if ', use the default | |
7019 | breakpoint. */ | |
7020 | if ((*address) == NULL | |
7021 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c SS |
7022 | { |
7023 | if (default_breakpoint_valid) | |
7024 | { | |
c3f6f71d | 7025 | struct symtab_and_line sal; |
fe39c653 | 7026 | init_sal (&sal); /* initialize to zeroes */ |
c3f6f71d | 7027 | sals->sals = (struct symtab_and_line *) |
c906108c SS |
7028 | xmalloc (sizeof (struct symtab_and_line)); |
7029 | sal.pc = default_breakpoint_address; | |
7030 | sal.line = default_breakpoint_line; | |
7031 | sal.symtab = default_breakpoint_symtab; | |
6c95b8df | 7032 | sal.pspace = default_breakpoint_pspace; |
c5aa993b | 7033 | sal.section = find_pc_overlay (sal.pc); |
00903456 JK |
7034 | |
7035 | /* "break" without arguments is equivalent to "break *PC" where PC is | |
7036 | the default_breakpoint_address. So make sure to set | |
7037 | sal.explicit_pc to prevent GDB from trying to expand the list of | |
7038 | sals to include all other instances with the same symtab and line. | |
7039 | */ | |
7040 | sal.explicit_pc = 1; | |
7041 | ||
c3f6f71d JM |
7042 | sals->sals[0] = sal; |
7043 | sals->nelts = 1; | |
c906108c SS |
7044 | } |
7045 | else | |
8a3fe4f8 | 7046 | error (_("No default breakpoint address now.")); |
c906108c SS |
7047 | } |
7048 | else | |
7049 | { | |
c906108c | 7050 | /* Force almost all breakpoints to be in terms of the |
c5aa993b JM |
7051 | current_source_symtab (which is decode_line_1's default). This |
7052 | should produce the results we want almost all of the time while | |
1aeae86e AF |
7053 | leaving default_breakpoint_* alone. |
7054 | ObjC: However, don't match an Objective-C method name which | |
7055 | may have a '+' or '-' succeeded by a '[' */ | |
0378c332 | 7056 | |
c214a6fd | 7057 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
0378c332 | 7058 | |
c906108c | 7059 | if (default_breakpoint_valid |
0378c332 | 7060 | && (!cursal.symtab |
1aeae86e AF |
7061 | || ((strchr ("+-", (*address)[0]) != NULL) |
7062 | && ((*address)[1] != '[')))) | |
c3f6f71d | 7063 | *sals = decode_line_1 (address, 1, default_breakpoint_symtab, |
0101ce28 JJ |
7064 | default_breakpoint_line, addr_string, |
7065 | not_found_ptr); | |
c906108c | 7066 | else |
0101ce28 JJ |
7067 | *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, |
7068 | addr_string, not_found_ptr); | |
c906108c | 7069 | } |
c3f6f71d JM |
7070 | /* For any SAL that didn't have a canonical string, fill one in. */ |
7071 | if (sals->nelts > 0 && *addr_string == NULL) | |
7072 | *addr_string = xcalloc (sals->nelts, sizeof (char **)); | |
7073 | if (addr_start != (*address)) | |
c906108c | 7074 | { |
c3f6f71d JM |
7075 | int i; |
7076 | for (i = 0; i < sals->nelts; i++) | |
c906108c | 7077 | { |
c3f6f71d JM |
7078 | /* Add the string if not present. */ |
7079 | if ((*addr_string)[i] == NULL) | |
7080 | (*addr_string)[i] = savestring (addr_start, (*address) - addr_start); | |
c906108c SS |
7081 | } |
7082 | } | |
c3f6f71d | 7083 | } |
c906108c | 7084 | |
c906108c | 7085 | |
c3f6f71d JM |
7086 | /* Convert each SAL into a real PC. Verify that the PC can be |
7087 | inserted as a breakpoint. If it can't throw an error. */ | |
c906108c | 7088 | |
b9362cc7 | 7089 | static void |
c3f6f71d JM |
7090 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals, |
7091 | char *address) | |
7092 | { | |
7093 | int i; | |
7094 | for (i = 0; i < sals->nelts; i++) | |
ee53e872 | 7095 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
7096 | } |
7097 | ||
7a697b8d SS |
7098 | /* Fast tracepoints may have restrictions on valid locations. For |
7099 | instance, a fast tracepoint using a jump instead of a trap will | |
7100 | likely have to overwrite more bytes than a trap would, and so can | |
7101 | only be placed where the instruction is longer than the jump, or a | |
7102 | multi-instruction sequence does not have a jump into the middle of | |
7103 | it, etc. */ | |
7104 | ||
7105 | static void | |
7106 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
7107 | struct symtabs_and_lines *sals) | |
7108 | { | |
7109 | int i, rslt; | |
7110 | struct symtab_and_line *sal; | |
7111 | char *msg; | |
7112 | struct cleanup *old_chain; | |
7113 | ||
7114 | for (i = 0; i < sals->nelts; i++) | |
7115 | { | |
7116 | sal = &sals->sals[i]; | |
7117 | ||
7118 | rslt = gdbarch_fast_tracepoint_valid_at (gdbarch, sal->pc, | |
7119 | NULL, &msg); | |
7120 | old_chain = make_cleanup (xfree, msg); | |
7121 | ||
7122 | if (!rslt) | |
7123 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
7124 | paddress (gdbarch, sal->pc), (msg ? msg : "")); | |
7125 | ||
7126 | do_cleanups (old_chain); | |
7127 | } | |
7128 | } | |
7129 | ||
05ff989b | 7130 | static void |
0101ce28 JJ |
7131 | do_captured_parse_breakpoint (struct ui_out *ui, void *data) |
7132 | { | |
7133 | struct captured_parse_breakpoint_args *args = data; | |
7134 | ||
7135 | parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p, | |
7136 | args->not_found_ptr); | |
0101ce28 JJ |
7137 | } |
7138 | ||
018d34a4 VP |
7139 | /* Given TOK, a string specification of condition and thread, as |
7140 | accepted by the 'break' command, extract the condition | |
7141 | string and thread number and set *COND_STRING and *THREAD. | |
7142 | PC identifies the context at which the condition should be parsed. | |
7143 | If no condition is found, *COND_STRING is set to NULL. | |
7144 | If no thread is found, *THREAD is set to -1. */ | |
7145 | static void | |
7146 | find_condition_and_thread (char *tok, CORE_ADDR pc, | |
4a306c9a | 7147 | char **cond_string, int *thread, int *task) |
018d34a4 VP |
7148 | { |
7149 | *cond_string = NULL; | |
7150 | *thread = -1; | |
7151 | while (tok && *tok) | |
7152 | { | |
7153 | char *end_tok; | |
7154 | int toklen; | |
7155 | char *cond_start = NULL; | |
7156 | char *cond_end = NULL; | |
7157 | while (*tok == ' ' || *tok == '\t') | |
7158 | tok++; | |
7159 | ||
7160 | end_tok = tok; | |
7161 | ||
7162 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
7163 | end_tok++; | |
7164 | ||
7165 | toklen = end_tok - tok; | |
7166 | ||
7167 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
7168 | { | |
f7545552 TT |
7169 | struct expression *expr; |
7170 | ||
018d34a4 | 7171 | tok = cond_start = end_tok + 1; |
f7545552 TT |
7172 | expr = parse_exp_1 (&tok, block_for_pc (pc), 0); |
7173 | xfree (expr); | |
018d34a4 VP |
7174 | cond_end = tok; |
7175 | *cond_string = savestring (cond_start, | |
7176 | cond_end - cond_start); | |
7177 | } | |
7178 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
7179 | { | |
7180 | char *tmptok; | |
7181 | ||
7182 | tok = end_tok + 1; | |
7183 | tmptok = tok; | |
7184 | *thread = strtol (tok, &tok, 0); | |
7185 | if (tok == tmptok) | |
7186 | error (_("Junk after thread keyword.")); | |
7187 | if (!valid_thread_id (*thread)) | |
7188 | error (_("Unknown thread %d."), *thread); | |
7189 | } | |
4a306c9a JB |
7190 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
7191 | { | |
7192 | char *tmptok; | |
7193 | ||
7194 | tok = end_tok + 1; | |
7195 | tmptok = tok; | |
7196 | *task = strtol (tok, &tok, 0); | |
7197 | if (tok == tmptok) | |
7198 | error (_("Junk after task keyword.")); | |
7199 | if (!valid_task_id (*task)) | |
b6199126 | 7200 | error (_("Unknown task %d."), *task); |
4a306c9a | 7201 | } |
018d34a4 VP |
7202 | else |
7203 | error (_("Junk at end of arguments.")); | |
7204 | } | |
7205 | } | |
7206 | ||
fd9b8c24 PA |
7207 | /* Set a breakpoint. This function is shared between CLI and MI |
7208 | functions for setting a breakpoint. This function has two major | |
7209 | modes of operations, selected by the PARSE_CONDITION_AND_THREAD | |
7210 | parameter. If non-zero, the function will parse arg, extracting | |
7211 | breakpoint location, address and thread. Otherwise, ARG is just the | |
7212 | location of breakpoint, with condition and thread specified by the | |
7213 | COND_STRING and THREAD parameters. Returns true if any breakpoint | |
7214 | was created; false otherwise. */ | |
0101ce28 | 7215 | |
8cdf0e15 VP |
7216 | int |
7217 | create_breakpoint (struct gdbarch *gdbarch, | |
7218 | char *arg, char *cond_string, int thread, | |
7219 | int parse_condition_and_thread, | |
7220 | int tempflag, int hardwareflag, int traceflag, | |
7221 | int ignore_count, | |
7222 | enum auto_boolean pending_break_support, | |
7223 | struct breakpoint_ops *ops, | |
7224 | int from_tty, | |
7225 | int enabled) | |
c3f6f71d | 7226 | { |
71fff37b | 7227 | struct gdb_exception e; |
c3f6f71d | 7228 | struct symtabs_and_lines sals; |
0101ce28 | 7229 | struct symtab_and_line pending_sal; |
0101ce28 JJ |
7230 | char *copy_arg; |
7231 | char *err_msg; | |
c3f6f71d JM |
7232 | char *addr_start = arg; |
7233 | char **addr_string; | |
7234 | struct cleanup *old_chain; | |
80c99de1 | 7235 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 7236 | struct captured_parse_breakpoint_args parse_args; |
05ff989b | 7237 | int i; |
0101ce28 | 7238 | int pending = 0; |
0101ce28 | 7239 | int not_found = 0; |
1042e4c0 | 7240 | enum bptype type_wanted; |
4a306c9a | 7241 | int task = 0; |
95a42b64 | 7242 | int first_bp_set = breakpoint_count + 1; |
c3f6f71d | 7243 | |
c3f6f71d JM |
7244 | sals.sals = NULL; |
7245 | sals.nelts = 0; | |
7246 | addr_string = NULL; | |
c3f6f71d | 7247 | |
0101ce28 JJ |
7248 | parse_args.arg_p = &arg; |
7249 | parse_args.sals_p = &sals; | |
7250 | parse_args.addr_string_p = &addr_string; | |
7251 | parse_args.not_found_ptr = ¬_found; | |
7252 | ||
05ff989b AC |
7253 | e = catch_exception (uiout, do_captured_parse_breakpoint, |
7254 | &parse_args, RETURN_MASK_ALL); | |
0101ce28 JJ |
7255 | |
7256 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 7257 | switch (e.reason) |
0101ce28 | 7258 | { |
05ff989b | 7259 | case RETURN_QUIT: |
98deb0da | 7260 | throw_exception (e); |
05ff989b AC |
7261 | case RETURN_ERROR: |
7262 | switch (e.error) | |
0101ce28 | 7263 | { |
05ff989b | 7264 | case NOT_FOUND_ERROR: |
0101ce28 | 7265 | |
05ff989b AC |
7266 | /* If pending breakpoint support is turned off, throw |
7267 | error. */ | |
fa8d40ab JJ |
7268 | |
7269 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
7270 | throw_exception (e); |
7271 | ||
7272 | exception_print (gdb_stderr, e); | |
fa8d40ab | 7273 | |
05ff989b AC |
7274 | /* If pending breakpoint support is auto query and the user |
7275 | selects no, then simply return the error code. */ | |
059fb39f PM |
7276 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
7277 | && !nquery ("Make breakpoint pending on future shared library load? ")) | |
fd9b8c24 | 7278 | return 0; |
fa8d40ab | 7279 | |
05ff989b AC |
7280 | /* At this point, either the user was queried about setting |
7281 | a pending breakpoint and selected yes, or pending | |
7282 | breakpoint behavior is on and thus a pending breakpoint | |
7283 | is defaulted on behalf of the user. */ | |
0101ce28 JJ |
7284 | copy_arg = xstrdup (addr_start); |
7285 | addr_string = ©_arg; | |
7286 | sals.nelts = 1; | |
7287 | sals.sals = &pending_sal; | |
7288 | pending_sal.pc = 0; | |
7289 | pending = 1; | |
05ff989b AC |
7290 | break; |
7291 | default: | |
98deb0da | 7292 | throw_exception (e); |
0101ce28 | 7293 | } |
05ff989b AC |
7294 | default: |
7295 | if (!sals.nelts) | |
fd9b8c24 | 7296 | return 0; |
0101ce28 | 7297 | } |
c3f6f71d JM |
7298 | |
7299 | /* Create a chain of things that always need to be cleaned up. */ | |
7300 | old_chain = make_cleanup (null_cleanup, 0); | |
7301 | ||
0101ce28 JJ |
7302 | if (!pending) |
7303 | { | |
7304 | /* Make sure that all storage allocated to SALS gets freed. */ | |
7305 | make_cleanup (xfree, sals.sals); | |
7306 | ||
7307 | /* Cleanup the addr_string array but not its contents. */ | |
7308 | make_cleanup (xfree, addr_string); | |
7309 | } | |
c3f6f71d | 7310 | |
c3f6f71d JM |
7311 | /* ----------------------------- SNIP ----------------------------- |
7312 | Anything added to the cleanup chain beyond this point is assumed | |
7313 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
7314 | then the memory is not reclaimed. */ |
7315 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d JM |
7316 | |
7317 | /* Mark the contents of the addr_string for cleanup. These go on | |
80c99de1 | 7318 | the bkpt_chain and only occur if the breakpoint create fails. */ |
c3f6f71d JM |
7319 | for (i = 0; i < sals.nelts; i++) |
7320 | { | |
7321 | if (addr_string[i] != NULL) | |
b8c9b27d | 7322 | make_cleanup (xfree, addr_string[i]); |
c3f6f71d JM |
7323 | } |
7324 | ||
7325 | /* Resolve all line numbers to PC's and verify that the addresses | |
7326 | are ok for the target. */ | |
0101ce28 JJ |
7327 | if (!pending) |
7328 | breakpoint_sals_to_pc (&sals, addr_start); | |
c3f6f71d | 7329 | |
1042e4c0 | 7330 | type_wanted = (traceflag |
7a697b8d | 7331 | ? (hardwareflag ? bp_fast_tracepoint : bp_tracepoint) |
1042e4c0 SS |
7332 | : (hardwareflag ? bp_hardware_breakpoint : bp_breakpoint)); |
7333 | ||
7a697b8d SS |
7334 | /* Fast tracepoints may have additional restrictions on location. */ |
7335 | if (type_wanted == bp_fast_tracepoint) | |
7336 | check_fast_tracepoint_sals (gdbarch, &sals); | |
7337 | ||
c3f6f71d JM |
7338 | /* Verify that condition can be parsed, before setting any |
7339 | breakpoints. Allocate a separate condition expression for each | |
7340 | breakpoint. */ | |
0101ce28 | 7341 | if (!pending) |
c3f6f71d | 7342 | { |
2f069f6f | 7343 | if (parse_condition_and_thread) |
72b2ff0e VP |
7344 | { |
7345 | /* Here we only parse 'arg' to separate condition | |
7346 | from thread number, so parsing in context of first | |
7347 | sal is OK. When setting the breakpoint we'll | |
7348 | re-parse it in context of each sal. */ | |
7349 | cond_string = NULL; | |
7350 | thread = -1; | |
4a306c9a JB |
7351 | find_condition_and_thread (arg, sals.sals[0].pc, &cond_string, |
7352 | &thread, &task); | |
72b2ff0e VP |
7353 | if (cond_string) |
7354 | make_cleanup (xfree, cond_string); | |
7355 | } | |
2f069f6f | 7356 | else |
72b2ff0e VP |
7357 | { |
7358 | /* Create a private copy of condition string. */ | |
7359 | if (cond_string) | |
7360 | { | |
7361 | cond_string = xstrdup (cond_string); | |
7362 | make_cleanup (xfree, cond_string); | |
7363 | } | |
7364 | } | |
8cdf0e15 VP |
7365 | create_breakpoints_sal (gdbarch, sals, addr_string, cond_string, |
7366 | type_wanted, tempflag ? disp_del : disp_donttouch, | |
7367 | thread, task, ignore_count, ops, from_tty, | |
7368 | enabled); | |
c906108c | 7369 | } |
0101ce28 JJ |
7370 | else |
7371 | { | |
fe3f5fa8 | 7372 | struct symtab_and_line sal = {0}; |
0101ce28 JJ |
7373 | struct breakpoint *b; |
7374 | ||
0101ce28 JJ |
7375 | make_cleanup (xfree, copy_arg); |
7376 | ||
a6d9a66e | 7377 | b = set_raw_breakpoint_without_location (gdbarch, type_wanted); |
0101ce28 JJ |
7378 | set_breakpoint_count (breakpoint_count + 1); |
7379 | b->number = breakpoint_count; | |
72b2ff0e | 7380 | b->thread = -1; |
018d34a4 | 7381 | b->addr_string = addr_string[0]; |
72b2ff0e | 7382 | b->cond_string = NULL; |
0101ce28 | 7383 | b->ignore_count = ignore_count; |
0101ce28 | 7384 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 7385 | b->condition_not_parsed = 1; |
604133b5 | 7386 | b->ops = ops; |
41447f92 | 7387 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
6c95b8df | 7388 | b->pspace = current_program_space; |
74960c60 | 7389 | |
6c95b8df | 7390 | if (enabled && b->pspace->executing_startup |
8bea4e01 UW |
7391 | && (b->type == bp_breakpoint |
7392 | || b->type == bp_hardware_breakpoint)) | |
7393 | b->enable_state = bp_startup_disabled; | |
7394 | ||
0101ce28 JJ |
7395 | mention (b); |
7396 | } | |
7397 | ||
c3f6f71d | 7398 | if (sals.nelts > 1) |
95a42b64 TT |
7399 | { |
7400 | warning (_("Multiple breakpoints were set.\n" | |
7401 | "Use the \"delete\" command to delete unwanted breakpoints.")); | |
7402 | multi_start = first_bp_set; | |
7403 | multi_end = breakpoint_count; | |
7404 | last_was_multi = 1; | |
7405 | } | |
7406 | ||
80c99de1 PA |
7407 | /* That's it. Discard the cleanups for data inserted into the |
7408 | breakpoint. */ | |
7409 | discard_cleanups (bkpt_chain); | |
7410 | /* But cleanup everything else. */ | |
c3f6f71d | 7411 | do_cleanups (old_chain); |
217dc9e2 | 7412 | |
80c99de1 | 7413 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
217dc9e2 | 7414 | update_global_location_list (1); |
fd9b8c24 PA |
7415 | |
7416 | return 1; | |
c3f6f71d | 7417 | } |
c906108c | 7418 | |
72b2ff0e VP |
7419 | /* Set a breakpoint. |
7420 | ARG is a string describing breakpoint address, | |
7421 | condition, and thread. | |
7422 | FLAG specifies if a breakpoint is hardware on, | |
7423 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
7424 | and BP_TEMPFLAG. */ | |
7425 | ||
98deb0da | 7426 | static void |
72b2ff0e | 7427 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 7428 | { |
72b2ff0e VP |
7429 | int hardwareflag = flag & BP_HARDWAREFLAG; |
7430 | int tempflag = flag & BP_TEMPFLAG; | |
c3f6f71d | 7431 | |
8cdf0e15 VP |
7432 | create_breakpoint (get_current_arch (), |
7433 | arg, | |
7434 | NULL, 0, 1 /* parse arg */, | |
7435 | tempflag, hardwareflag, 0 /* traceflag */, | |
7436 | 0 /* Ignore count */, | |
7437 | pending_break_support, | |
7438 | NULL /* breakpoint_ops */, | |
7439 | from_tty, | |
7440 | 1 /* enabled */); | |
c906108c SS |
7441 | } |
7442 | ||
72b2ff0e | 7443 | |
c3f6f71d | 7444 | |
c906108c SS |
7445 | /* Helper function for break_command_1 and disassemble_command. */ |
7446 | ||
7447 | void | |
fba45db2 | 7448 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
7449 | { |
7450 | CORE_ADDR pc; | |
7451 | ||
7452 | if (sal->pc == 0 && sal->symtab != NULL) | |
7453 | { | |
7454 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 7455 | error (_("No line %d in file \"%s\"."), |
c906108c SS |
7456 | sal->line, sal->symtab->filename); |
7457 | sal->pc = pc; | |
6a048695 JB |
7458 | |
7459 | /* If this SAL corresponds to a breakpoint inserted using | |
7460 | a line number, then skip the function prologue if necessary. */ | |
7461 | if (sal->explicit_line) | |
059acae7 | 7462 | skip_prologue_sal (sal); |
c906108c SS |
7463 | } |
7464 | ||
7465 | if (sal->section == 0 && sal->symtab != NULL) | |
7466 | { | |
7467 | struct blockvector *bv; | |
c5aa993b JM |
7468 | struct block *b; |
7469 | struct symbol *sym; | |
c906108c | 7470 | |
801e3a5b | 7471 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
7472 | if (bv != NULL) |
7473 | { | |
7f0df278 | 7474 | sym = block_linkage_function (b); |
c906108c SS |
7475 | if (sym != NULL) |
7476 | { | |
7477 | fixup_symbol_section (sym, sal->symtab->objfile); | |
714835d5 | 7478 | sal->section = SYMBOL_OBJ_SECTION (sym); |
c906108c SS |
7479 | } |
7480 | else | |
7481 | { | |
7482 | /* It really is worthwhile to have the section, so we'll just | |
c5aa993b JM |
7483 | have to look harder. This case can be executed if we have |
7484 | line numbers but no functions (as can happen in assembly | |
7485 | source). */ | |
c906108c | 7486 | |
c5aa993b | 7487 | struct minimal_symbol *msym; |
6c95b8df PA |
7488 | struct cleanup *old_chain = save_current_space_and_thread (); |
7489 | ||
7490 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
7491 | |
7492 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
7493 | if (msym) | |
714835d5 | 7494 | sal->section = SYMBOL_OBJ_SECTION (msym); |
6c95b8df PA |
7495 | |
7496 | do_cleanups (old_chain); | |
c906108c SS |
7497 | } |
7498 | } | |
7499 | } | |
7500 | } | |
7501 | ||
7502 | void | |
fba45db2 | 7503 | break_command (char *arg, int from_tty) |
c906108c | 7504 | { |
db107f19 | 7505 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
7506 | } |
7507 | ||
c906108c | 7508 | void |
fba45db2 | 7509 | tbreak_command (char *arg, int from_tty) |
c906108c | 7510 | { |
db107f19 | 7511 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
7512 | } |
7513 | ||
c906108c | 7514 | static void |
fba45db2 | 7515 | hbreak_command (char *arg, int from_tty) |
c906108c | 7516 | { |
db107f19 | 7517 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
7518 | } |
7519 | ||
7520 | static void | |
fba45db2 | 7521 | thbreak_command (char *arg, int from_tty) |
c906108c | 7522 | { |
db107f19 | 7523 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
7524 | } |
7525 | ||
7526 | static void | |
fba45db2 | 7527 | stop_command (char *arg, int from_tty) |
c906108c | 7528 | { |
a3f17187 | 7529 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 7530 | Usage: stop in <function | address>\n\ |
a3f17187 | 7531 | stop at <line>\n")); |
c906108c SS |
7532 | } |
7533 | ||
7534 | static void | |
fba45db2 | 7535 | stopin_command (char *arg, int from_tty) |
c906108c SS |
7536 | { |
7537 | int badInput = 0; | |
7538 | ||
c5aa993b | 7539 | if (arg == (char *) NULL) |
c906108c SS |
7540 | badInput = 1; |
7541 | else if (*arg != '*') | |
7542 | { | |
7543 | char *argptr = arg; | |
7544 | int hasColon = 0; | |
7545 | ||
53a5351d JM |
7546 | /* look for a ':'. If this is a line number specification, then |
7547 | say it is bad, otherwise, it should be an address or | |
7548 | function/method name */ | |
c906108c | 7549 | while (*argptr && !hasColon) |
c5aa993b JM |
7550 | { |
7551 | hasColon = (*argptr == ':'); | |
7552 | argptr++; | |
7553 | } | |
c906108c SS |
7554 | |
7555 | if (hasColon) | |
c5aa993b | 7556 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 7557 | else |
c5aa993b | 7558 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
7559 | } |
7560 | ||
7561 | if (badInput) | |
a3f17187 | 7562 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 7563 | else |
db107f19 | 7564 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
7565 | } |
7566 | ||
7567 | static void | |
fba45db2 | 7568 | stopat_command (char *arg, int from_tty) |
c906108c SS |
7569 | { |
7570 | int badInput = 0; | |
7571 | ||
c5aa993b | 7572 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
7573 | badInput = 1; |
7574 | else | |
7575 | { | |
7576 | char *argptr = arg; | |
7577 | int hasColon = 0; | |
7578 | ||
7579 | /* look for a ':'. If there is a '::' then get out, otherwise | |
c5aa993b | 7580 | it is probably a line number. */ |
c906108c | 7581 | while (*argptr && !hasColon) |
c5aa993b JM |
7582 | { |
7583 | hasColon = (*argptr == ':'); | |
7584 | argptr++; | |
7585 | } | |
c906108c SS |
7586 | |
7587 | if (hasColon) | |
c5aa993b | 7588 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 7589 | else |
c5aa993b | 7590 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
7591 | } |
7592 | ||
7593 | if (badInput) | |
a3f17187 | 7594 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 7595 | else |
db107f19 | 7596 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
7597 | } |
7598 | ||
53a5351d JM |
7599 | /* accessflag: hw_write: watch write, |
7600 | hw_read: watch read, | |
7601 | hw_access: watch access (read or write) */ | |
c906108c | 7602 | static void |
fba45db2 | 7603 | watch_command_1 (char *arg, int accessflag, int from_tty) |
c906108c | 7604 | { |
a6d9a66e | 7605 | struct gdbarch *gdbarch = get_current_arch (); |
d983da9c | 7606 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c | 7607 | struct expression *exp; |
60e1c644 | 7608 | struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
c906108c SS |
7609 | struct value *val, *mark; |
7610 | struct frame_info *frame; | |
c906108c SS |
7611 | char *exp_start = NULL; |
7612 | char *exp_end = NULL; | |
37e4754d | 7613 | char *tok, *id_tok_start, *end_tok; |
c906108c SS |
7614 | int toklen; |
7615 | char *cond_start = NULL; | |
7616 | char *cond_end = NULL; | |
c906108c SS |
7617 | int i, other_type_used, target_resources_ok = 0; |
7618 | enum bptype bp_type; | |
7619 | int mem_cnt = 0; | |
37e4754d | 7620 | int thread = -1; |
c906108c | 7621 | |
37e4754d LM |
7622 | /* Make sure that we actually have parameters to parse. */ |
7623 | if (arg != NULL && arg[0] != '\0') | |
7624 | { | |
7625 | toklen = strlen (arg); /* Size of argument list. */ | |
7626 | ||
7627 | /* Points tok to the end of the argument list. */ | |
7628 | tok = arg + toklen - 1; | |
7629 | ||
7630 | /* Go backwards in the parameters list. Skip the last parameter. | |
7631 | If we're expecting a 'thread <thread_num>' parameter, this should | |
7632 | be the thread identifier. */ | |
7633 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
7634 | tok--; | |
7635 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
7636 | tok--; | |
7637 | ||
7638 | /* Points end_tok to the beginning of the last token. */ | |
7639 | id_tok_start = tok + 1; | |
7640 | ||
7641 | /* Go backwards in the parameters list. Skip one more parameter. | |
7642 | If we're expecting a 'thread <thread_num>' parameter, we should | |
7643 | reach a "thread" token. */ | |
7644 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
7645 | tok--; | |
7646 | ||
7647 | end_tok = tok; | |
7648 | ||
7649 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
7650 | tok--; | |
7651 | ||
7652 | /* Move the pointer forward to skip the whitespace and | |
7653 | calculate the length of the token. */ | |
7654 | tok++; | |
7655 | toklen = end_tok - tok; | |
7656 | ||
7657 | if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
7658 | { | |
7659 | /* At this point we've found a "thread" token, which means | |
7660 | the user is trying to set a watchpoint that triggers | |
7661 | only in a specific thread. */ | |
7662 | char *endp; | |
7663 | ||
7664 | /* Extract the thread ID from the next token. */ | |
7665 | thread = strtol (id_tok_start, &endp, 0); | |
7666 | ||
7667 | /* Check if the user provided a valid numeric value for the | |
7668 | thread ID. */ | |
7669 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
7670 | error (_("Invalid thread ID specification %s."), id_tok_start); | |
7671 | ||
7672 | /* Check if the thread actually exists. */ | |
7673 | if (!valid_thread_id (thread)) | |
7674 | error (_("Unknown thread %d."), thread); | |
7675 | ||
7676 | /* Truncate the string and get rid of the thread <thread_num> | |
7677 | parameter before the parameter list is parsed by the | |
7678 | evaluate_expression() function. */ | |
7679 | *tok = '\0'; | |
7680 | } | |
7681 | } | |
7682 | ||
7683 | /* Parse the rest of the arguments. */ | |
c906108c SS |
7684 | innermost_block = NULL; |
7685 | exp_start = arg; | |
7686 | exp = parse_exp_1 (&arg, 0, 0); | |
7687 | exp_end = arg; | |
fa8a61dc TT |
7688 | /* Remove trailing whitespace from the expression before saving it. |
7689 | This makes the eventual display of the expression string a bit | |
7690 | prettier. */ | |
7691 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
7692 | --exp_end; | |
7693 | ||
c906108c SS |
7694 | exp_valid_block = innermost_block; |
7695 | mark = value_mark (); | |
fa4727a6 DJ |
7696 | fetch_watchpoint_value (exp, &val, NULL, NULL); |
7697 | if (val != NULL) | |
7698 | release_value (val); | |
c906108c SS |
7699 | |
7700 | tok = arg; | |
7701 | while (*tok == ' ' || *tok == '\t') | |
7702 | tok++; | |
7703 | end_tok = tok; | |
7704 | ||
7705 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
7706 | end_tok++; | |
7707 | ||
7708 | toklen = end_tok - tok; | |
7709 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
7710 | { | |
2d134ed3 PA |
7711 | struct expression *cond; |
7712 | ||
60e1c644 | 7713 | innermost_block = NULL; |
c906108c SS |
7714 | tok = cond_start = end_tok + 1; |
7715 | cond = parse_exp_1 (&tok, 0, 0); | |
60e1c644 PA |
7716 | |
7717 | /* The watchpoint expression may not be local, but the condition | |
7718 | may still be. E.g.: `watch global if local > 0'. */ | |
7719 | cond_exp_valid_block = innermost_block; | |
7720 | ||
2d134ed3 | 7721 | xfree (cond); |
c906108c SS |
7722 | cond_end = tok; |
7723 | } | |
7724 | if (*tok) | |
8a3fe4f8 | 7725 | error (_("Junk at end of command.")); |
c906108c | 7726 | |
53a5351d | 7727 | if (accessflag == hw_read) |
c5aa993b | 7728 | bp_type = bp_read_watchpoint; |
53a5351d | 7729 | else if (accessflag == hw_access) |
c5aa993b JM |
7730 | bp_type = bp_access_watchpoint; |
7731 | else | |
7732 | bp_type = bp_hardware_watchpoint; | |
c906108c SS |
7733 | |
7734 | mem_cnt = can_use_hardware_watchpoint (val); | |
7735 | if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint) | |
8a3fe4f8 | 7736 | error (_("Expression cannot be implemented with read/access watchpoint.")); |
c5aa993b JM |
7737 | if (mem_cnt != 0) |
7738 | { | |
7739 | i = hw_watchpoint_used_count (bp_type, &other_type_used); | |
53a5351d | 7740 | target_resources_ok = |
d92524f1 | 7741 | target_can_use_hardware_watchpoint (bp_type, i + mem_cnt, |
53a5351d | 7742 | other_type_used); |
c5aa993b | 7743 | if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint) |
8a3fe4f8 | 7744 | error (_("Target does not support this type of hardware watchpoint.")); |
53a5351d | 7745 | |
c5aa993b | 7746 | if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint) |
8a3fe4f8 | 7747 | error (_("Target can only support one kind of HW watchpoint at a time.")); |
c5aa993b | 7748 | } |
c906108c | 7749 | |
4d28f7a8 KB |
7750 | /* Change the type of breakpoint to an ordinary watchpoint if a hardware |
7751 | watchpoint could not be set. */ | |
7752 | if (!mem_cnt || target_resources_ok <= 0) | |
7753 | bp_type = bp_watchpoint; | |
7754 | ||
d983da9c | 7755 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
7756 | |
7757 | /* If the expression is "local", then set up a "watchpoint scope" | |
7758 | breakpoint at the point where we've left the scope of the watchpoint | |
7759 | expression. Create the scope breakpoint before the watchpoint, so | |
7760 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 7761 | if (exp_valid_block && frame) |
d983da9c | 7762 | { |
edb3359d DJ |
7763 | if (frame_id_p (frame_unwind_caller_id (frame))) |
7764 | { | |
7765 | scope_breakpoint | |
a6d9a66e UW |
7766 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
7767 | frame_unwind_caller_pc (frame), | |
edb3359d | 7768 | bp_watchpoint_scope); |
d983da9c | 7769 | |
edb3359d | 7770 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 7771 | |
edb3359d DJ |
7772 | /* Automatically delete the breakpoint when it hits. */ |
7773 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 7774 | |
edb3359d DJ |
7775 | /* Only break in the proper frame (help with recursion). */ |
7776 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 7777 | |
edb3359d | 7778 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
7779 | scope_breakpoint->loc->gdbarch |
7780 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
7781 | scope_breakpoint->loc->requested_address |
7782 | = frame_unwind_caller_pc (frame); | |
7783 | scope_breakpoint->loc->address | |
a6d9a66e UW |
7784 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
7785 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
7786 | scope_breakpoint->type); |
7787 | } | |
d983da9c DJ |
7788 | } |
7789 | ||
c906108c | 7790 | /* Now set up the breakpoint. */ |
2d134ed3 | 7791 | b = set_raw_breakpoint_without_location (NULL, bp_type); |
c906108c SS |
7792 | set_breakpoint_count (breakpoint_count + 1); |
7793 | b->number = breakpoint_count; | |
37e4754d | 7794 | b->thread = thread; |
b5de0fa7 | 7795 | b->disposition = disp_donttouch; |
c906108c SS |
7796 | b->exp = exp; |
7797 | b->exp_valid_block = exp_valid_block; | |
60e1c644 | 7798 | b->cond_exp_valid_block = cond_exp_valid_block; |
c906108c SS |
7799 | b->exp_string = savestring (exp_start, exp_end - exp_start); |
7800 | b->val = val; | |
fa4727a6 | 7801 | b->val_valid = 1; |
c906108c SS |
7802 | if (cond_start) |
7803 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
7804 | else | |
7805 | b->cond_string = 0; | |
c5aa993b | 7806 | |
c906108c | 7807 | if (frame) |
f6bc2008 PA |
7808 | { |
7809 | b->watchpoint_frame = get_frame_id (frame); | |
7810 | b->watchpoint_thread = inferior_ptid; | |
7811 | } | |
c906108c | 7812 | else |
f6bc2008 PA |
7813 | { |
7814 | b->watchpoint_frame = null_frame_id; | |
7815 | b->watchpoint_thread = null_ptid; | |
7816 | } | |
c906108c | 7817 | |
d983da9c | 7818 | if (scope_breakpoint != NULL) |
c906108c | 7819 | { |
d983da9c DJ |
7820 | /* The scope breakpoint is related to the watchpoint. We will |
7821 | need to act on them together. */ | |
7822 | b->related_breakpoint = scope_breakpoint; | |
7823 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 7824 | } |
d983da9c | 7825 | |
c906108c | 7826 | value_free_to_mark (mark); |
2d134ed3 PA |
7827 | |
7828 | /* Finally update the new watchpoint. This creates the locations | |
7829 | that should be inserted. */ | |
7830 | update_watchpoint (b, 1); | |
7831 | ||
c906108c | 7832 | mention (b); |
b60e7edf | 7833 | update_global_location_list (1); |
c906108c SS |
7834 | } |
7835 | ||
7836 | /* Return count of locations need to be watched and can be handled | |
7837 | in hardware. If the watchpoint can not be handled | |
7838 | in hardware return zero. */ | |
7839 | ||
c906108c | 7840 | static int |
fba45db2 | 7841 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
7842 | { |
7843 | int found_memory_cnt = 0; | |
2e70b7b9 | 7844 | struct value *head = v; |
c906108c SS |
7845 | |
7846 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 7847 | if (!can_use_hw_watchpoints) |
c906108c | 7848 | return 0; |
c5aa993b | 7849 | |
5c44784c JM |
7850 | /* Make sure that the value of the expression depends only upon |
7851 | memory contents, and values computed from them within GDB. If we | |
7852 | find any register references or function calls, we can't use a | |
7853 | hardware watchpoint. | |
7854 | ||
7855 | The idea here is that evaluating an expression generates a series | |
7856 | of values, one holding the value of every subexpression. (The | |
7857 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
7858 | a*b+c.) GDB's values hold almost enough information to establish | |
7859 | the criteria given above --- they identify memory lvalues, | |
7860 | register lvalues, computed values, etcetera. So we can evaluate | |
7861 | the expression, and then scan the chain of values that leaves | |
7862 | behind to decide whether we can detect any possible change to the | |
7863 | expression's final value using only hardware watchpoints. | |
7864 | ||
7865 | However, I don't think that the values returned by inferior | |
7866 | function calls are special in any way. So this function may not | |
7867 | notice that an expression involving an inferior function call | |
7868 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 7869 | for (; v; v = value_next (v)) |
c906108c | 7870 | { |
5c44784c | 7871 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 7872 | { |
d69fe07e | 7873 | if (value_lazy (v)) |
5c44784c JM |
7874 | /* A lazy memory lvalue is one that GDB never needed to fetch; |
7875 | we either just used its address (e.g., `a' in `a.b') or | |
7876 | we never needed it at all (e.g., `a' in `a,b'). */ | |
7877 | ; | |
53a5351d | 7878 | else |
5c44784c JM |
7879 | { |
7880 | /* Ahh, memory we actually used! Check if we can cover | |
7881 | it with hardware watchpoints. */ | |
df407dfe | 7882 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
7883 | |
7884 | /* We only watch structs and arrays if user asked for it | |
7885 | explicitly, never if they just happen to appear in a | |
7886 | middle of some value chain. */ | |
7887 | if (v == head | |
7888 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
7889 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
7890 | { | |
42ae5230 | 7891 | CORE_ADDR vaddr = value_address (v); |
df407dfe | 7892 | int len = TYPE_LENGTH (value_type (v)); |
2e70b7b9 | 7893 | |
d92524f1 | 7894 | if (!target_region_ok_for_hw_watchpoint (vaddr, len)) |
2e70b7b9 MS |
7895 | return 0; |
7896 | else | |
7897 | found_memory_cnt++; | |
7898 | } | |
5c44784c | 7899 | } |
c5aa993b | 7900 | } |
5086187c AC |
7901 | else if (VALUE_LVAL (v) != not_lval |
7902 | && deprecated_value_modifiable (v) == 0) | |
53a5351d | 7903 | return 0; /* ??? What does this represent? */ |
5086187c | 7904 | else if (VALUE_LVAL (v) == lval_register) |
53a5351d | 7905 | return 0; /* cannot watch a register with a HW watchpoint */ |
c906108c SS |
7906 | } |
7907 | ||
7908 | /* The expression itself looks suitable for using a hardware | |
7909 | watchpoint, but give the target machine a chance to reject it. */ | |
7910 | return found_memory_cnt; | |
7911 | } | |
7912 | ||
8b93c638 | 7913 | void |
fba45db2 | 7914 | watch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
7915 | { |
7916 | watch_command (arg, from_tty); | |
7917 | } | |
8926118c | 7918 | |
c5aa993b | 7919 | static void |
fba45db2 | 7920 | watch_command (char *arg, int from_tty) |
c906108c | 7921 | { |
53a5351d | 7922 | watch_command_1 (arg, hw_write, from_tty); |
c906108c SS |
7923 | } |
7924 | ||
8b93c638 | 7925 | void |
fba45db2 | 7926 | rwatch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
7927 | { |
7928 | rwatch_command (arg, from_tty); | |
7929 | } | |
8926118c | 7930 | |
c5aa993b | 7931 | static void |
fba45db2 | 7932 | rwatch_command (char *arg, int from_tty) |
c906108c | 7933 | { |
53a5351d | 7934 | watch_command_1 (arg, hw_read, from_tty); |
c906108c SS |
7935 | } |
7936 | ||
8b93c638 | 7937 | void |
fba45db2 | 7938 | awatch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
7939 | { |
7940 | awatch_command (arg, from_tty); | |
7941 | } | |
8926118c | 7942 | |
c5aa993b | 7943 | static void |
fba45db2 | 7944 | awatch_command (char *arg, int from_tty) |
c906108c | 7945 | { |
53a5351d | 7946 | watch_command_1 (arg, hw_access, from_tty); |
c906108c | 7947 | } |
c906108c | 7948 | \f |
c5aa993b | 7949 | |
43ff13b4 | 7950 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
7951 | because it uses the mechanisms of breakpoints. */ |
7952 | ||
bfec99b2 PA |
7953 | struct until_break_command_continuation_args |
7954 | { | |
7955 | struct breakpoint *breakpoint; | |
7956 | struct breakpoint *breakpoint2; | |
7957 | }; | |
7958 | ||
43ff13b4 JM |
7959 | /* This function is called by fetch_inferior_event via the |
7960 | cmd_continuation pointer, to complete the until command. It takes | |
7961 | care of cleaning up the temporary breakpoints set up by the until | |
7962 | command. */ | |
c2c6d25f | 7963 | static void |
604ead4a | 7964 | until_break_command_continuation (void *arg) |
43ff13b4 | 7965 | { |
bfec99b2 PA |
7966 | struct until_break_command_continuation_args *a = arg; |
7967 | ||
7968 | delete_breakpoint (a->breakpoint); | |
7969 | if (a->breakpoint2) | |
7970 | delete_breakpoint (a->breakpoint2); | |
43ff13b4 JM |
7971 | } |
7972 | ||
c906108c | 7973 | void |
ae66c1fc | 7974 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
7975 | { |
7976 | struct symtabs_and_lines sals; | |
7977 | struct symtab_and_line sal; | |
206415a3 | 7978 | struct frame_info *frame = get_selected_frame (NULL); |
c906108c | 7979 | struct breakpoint *breakpoint; |
f107f563 | 7980 | struct breakpoint *breakpoint2 = NULL; |
c906108c SS |
7981 | struct cleanup *old_chain; |
7982 | ||
7983 | clear_proceed_status (); | |
7984 | ||
7985 | /* Set a breakpoint where the user wants it and at return from | |
7986 | this function */ | |
c5aa993b | 7987 | |
c906108c SS |
7988 | if (default_breakpoint_valid) |
7989 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, | |
68219205 | 7990 | default_breakpoint_line, (char ***) NULL, NULL); |
c906108c | 7991 | else |
53a5351d | 7992 | sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, |
68219205 | 7993 | 0, (char ***) NULL, NULL); |
c5aa993b | 7994 | |
c906108c | 7995 | if (sals.nelts != 1) |
8a3fe4f8 | 7996 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 7997 | |
c906108c | 7998 | sal = sals.sals[0]; |
b8c9b27d | 7999 | xfree (sals.sals); /* malloc'd, so freed */ |
c5aa993b | 8000 | |
c906108c | 8001 | if (*arg) |
8a3fe4f8 | 8002 | error (_("Junk at end of arguments.")); |
c5aa993b | 8003 | |
c906108c | 8004 | resolve_sal_pc (&sal); |
c5aa993b | 8005 | |
ae66c1fc EZ |
8006 | if (anywhere) |
8007 | /* If the user told us to continue until a specified location, | |
8008 | we don't specify a frame at which we need to stop. */ | |
a6d9a66e UW |
8009 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
8010 | null_frame_id, bp_until); | |
ae66c1fc | 8011 | else |
edb3359d | 8012 | /* Otherwise, specify the selected frame, because we want to stop only |
ae66c1fc | 8013 | at the very same frame. */ |
a6d9a66e UW |
8014 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
8015 | get_stack_frame_id (frame), | |
ae66c1fc | 8016 | bp_until); |
c5aa993b | 8017 | |
f107f563 | 8018 | old_chain = make_cleanup_delete_breakpoint (breakpoint); |
c906108c | 8019 | |
ae66c1fc EZ |
8020 | /* Keep within the current frame, or in frames called by the current |
8021 | one. */ | |
edb3359d DJ |
8022 | |
8023 | if (frame_id_p (frame_unwind_caller_id (frame))) | |
c906108c | 8024 | { |
edb3359d DJ |
8025 | sal = find_pc_line (frame_unwind_caller_pc (frame), 0); |
8026 | sal.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e UW |
8027 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
8028 | sal, | |
edb3359d | 8029 | frame_unwind_caller_id (frame), |
f107f563 VP |
8030 | bp_until); |
8031 | make_cleanup_delete_breakpoint (breakpoint2); | |
c906108c | 8032 | } |
c5aa993b | 8033 | |
c906108c | 8034 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
f107f563 VP |
8035 | |
8036 | /* If we are running asynchronously, and proceed call above has actually | |
8037 | managed to start the target, arrange for breakpoints to be | |
8038 | deleted when the target stops. Otherwise, we're already stopped and | |
8039 | delete breakpoints via cleanup chain. */ | |
8040 | ||
8ea051c5 | 8041 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 8042 | { |
bfec99b2 PA |
8043 | struct until_break_command_continuation_args *args; |
8044 | args = xmalloc (sizeof (*args)); | |
f107f563 | 8045 | |
bfec99b2 PA |
8046 | args->breakpoint = breakpoint; |
8047 | args->breakpoint2 = breakpoint2; | |
f107f563 VP |
8048 | |
8049 | discard_cleanups (old_chain); | |
95e54da7 PA |
8050 | add_continuation (inferior_thread (), |
8051 | until_break_command_continuation, args, | |
604ead4a | 8052 | xfree); |
f107f563 VP |
8053 | } |
8054 | else | |
c5aa993b | 8055 | do_cleanups (old_chain); |
c906108c | 8056 | } |
ae66c1fc | 8057 | |
c906108c | 8058 | static void |
fba45db2 | 8059 | ep_skip_leading_whitespace (char **s) |
c906108c | 8060 | { |
c5aa993b JM |
8061 | if ((s == NULL) || (*s == NULL)) |
8062 | return; | |
8063 | while (isspace (**s)) | |
8064 | *s += 1; | |
c906108c | 8065 | } |
c5aa993b | 8066 | |
c906108c SS |
8067 | /* This function attempts to parse an optional "if <cond>" clause |
8068 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 8069 | |
c906108c SS |
8070 | Else, it returns a pointer to the condition string. (It does not |
8071 | attempt to evaluate the string against a particular block.) And, | |
8072 | it updates arg to point to the first character following the parsed | |
8073 | if clause in the arg string. */ | |
53a5351d | 8074 | |
c906108c | 8075 | static char * |
fba45db2 | 8076 | ep_parse_optional_if_clause (char **arg) |
c906108c | 8077 | { |
c5aa993b JM |
8078 | char *cond_string; |
8079 | ||
8080 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 8081 | return NULL; |
c5aa993b | 8082 | |
c906108c SS |
8083 | /* Skip the "if" keyword. */ |
8084 | (*arg) += 2; | |
c5aa993b | 8085 | |
c906108c SS |
8086 | /* Skip any extra leading whitespace, and record the start of the |
8087 | condition string. */ | |
8088 | ep_skip_leading_whitespace (arg); | |
8089 | cond_string = *arg; | |
c5aa993b | 8090 | |
c906108c SS |
8091 | /* Assume that the condition occupies the remainder of the arg string. */ |
8092 | (*arg) += strlen (cond_string); | |
c5aa993b | 8093 | |
c906108c SS |
8094 | return cond_string; |
8095 | } | |
c5aa993b | 8096 | |
c906108c SS |
8097 | /* Commands to deal with catching events, such as signals, exceptions, |
8098 | process start/exit, etc. */ | |
c5aa993b JM |
8099 | |
8100 | typedef enum | |
8101 | { | |
44feb3ce TT |
8102 | catch_fork_temporary, catch_vfork_temporary, |
8103 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
8104 | } |
8105 | catch_fork_kind; | |
8106 | ||
c906108c | 8107 | static void |
44feb3ce | 8108 | catch_fork_command_1 (char *arg, int from_tty, struct cmd_list_element *command) |
c906108c | 8109 | { |
a6d9a66e | 8110 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 8111 | char *cond_string = NULL; |
44feb3ce TT |
8112 | catch_fork_kind fork_kind; |
8113 | int tempflag; | |
8114 | ||
8115 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
8116 | tempflag = (fork_kind == catch_fork_temporary | |
8117 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 8118 | |
44feb3ce TT |
8119 | if (!arg) |
8120 | arg = ""; | |
c906108c | 8121 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 8122 | |
c906108c | 8123 | /* The allowed syntax is: |
c5aa993b JM |
8124 | catch [v]fork |
8125 | catch [v]fork if <cond> | |
8126 | ||
c906108c SS |
8127 | First, check if there's an if clause. */ |
8128 | cond_string = ep_parse_optional_if_clause (&arg); | |
c5aa993b | 8129 | |
c906108c | 8130 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 8131 | error (_("Junk at end of arguments.")); |
c5aa993b | 8132 | |
c906108c SS |
8133 | /* If this target supports it, create a fork or vfork catchpoint |
8134 | and enable reporting of such events. */ | |
c5aa993b JM |
8135 | switch (fork_kind) |
8136 | { | |
44feb3ce TT |
8137 | case catch_fork_temporary: |
8138 | case catch_fork_permanent: | |
a6d9a66e | 8139 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 8140 | &catch_fork_breakpoint_ops); |
c906108c | 8141 | break; |
44feb3ce TT |
8142 | case catch_vfork_temporary: |
8143 | case catch_vfork_permanent: | |
a6d9a66e | 8144 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 8145 | &catch_vfork_breakpoint_ops); |
c906108c | 8146 | break; |
c5aa993b | 8147 | default: |
8a3fe4f8 | 8148 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 8149 | break; |
c5aa993b | 8150 | } |
c906108c SS |
8151 | } |
8152 | ||
8153 | static void | |
44feb3ce | 8154 | catch_exec_command_1 (char *arg, int from_tty, struct cmd_list_element *command) |
c906108c | 8155 | { |
a6d9a66e | 8156 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 8157 | int tempflag; |
c5aa993b | 8158 | char *cond_string = NULL; |
c906108c | 8159 | |
44feb3ce TT |
8160 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
8161 | ||
8162 | if (!arg) | |
8163 | arg = ""; | |
c906108c SS |
8164 | ep_skip_leading_whitespace (&arg); |
8165 | ||
8166 | /* The allowed syntax is: | |
c5aa993b JM |
8167 | catch exec |
8168 | catch exec if <cond> | |
c906108c SS |
8169 | |
8170 | First, check if there's an if clause. */ | |
8171 | cond_string = ep_parse_optional_if_clause (&arg); | |
8172 | ||
8173 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 8174 | error (_("Junk at end of arguments.")); |
c906108c SS |
8175 | |
8176 | /* If this target supports it, create an exec catchpoint | |
8177 | and enable reporting of such events. */ | |
a6d9a66e UW |
8178 | create_catchpoint (gdbarch, tempflag, cond_string, |
8179 | &catch_exec_breakpoint_ops); | |
c906108c | 8180 | } |
c5aa993b | 8181 | |
3086aeae DJ |
8182 | static enum print_stop_action |
8183 | print_exception_catchpoint (struct breakpoint *b) | |
8184 | { | |
ade92717 | 8185 | int bp_temp, bp_throw; |
3086aeae | 8186 | |
ade92717 | 8187 | annotate_catchpoint (b->number); |
3086aeae | 8188 | |
ade92717 AR |
8189 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
8190 | if (b->loc->address != b->loc->requested_address) | |
8191 | breakpoint_adjustment_warning (b->loc->requested_address, | |
8192 | b->loc->address, | |
8193 | b->number, 1); | |
df2b6d2d | 8194 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
8195 | ui_out_text (uiout, |
8196 | bp_temp ? "Temporary catchpoint " | |
8197 | : "Catchpoint "); | |
8198 | if (!ui_out_is_mi_like_p (uiout)) | |
8199 | ui_out_field_int (uiout, "bkptno", b->number); | |
8200 | ui_out_text (uiout, | |
c0b37c48 AR |
8201 | bp_throw ? " (exception thrown), " |
8202 | : " (exception caught), "); | |
ade92717 AR |
8203 | if (ui_out_is_mi_like_p (uiout)) |
8204 | { | |
8205 | ui_out_field_string (uiout, "reason", | |
8206 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
8207 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8208 | ui_out_field_int (uiout, "bkptno", b->number); | |
8209 | } | |
3086aeae DJ |
8210 | return PRINT_SRC_AND_LOC; |
8211 | } | |
8212 | ||
8213 | static void | |
a6d9a66e | 8214 | print_one_exception_catchpoint (struct breakpoint *b, struct bp_location **last_loc) |
3086aeae | 8215 | { |
79a45b7d TT |
8216 | struct value_print_options opts; |
8217 | get_user_print_options (&opts); | |
8218 | if (opts.addressprint) | |
3086aeae DJ |
8219 | { |
8220 | annotate_field (4); | |
604133b5 AR |
8221 | if (b->loc == NULL || b->loc->shlib_disabled) |
8222 | ui_out_field_string (uiout, "addr", "<PENDING>"); | |
8223 | else | |
5af949e3 UW |
8224 | ui_out_field_core_addr (uiout, "addr", |
8225 | b->loc->gdbarch, b->loc->address); | |
3086aeae DJ |
8226 | } |
8227 | annotate_field (5); | |
604133b5 | 8228 | if (b->loc) |
a6d9a66e | 8229 | *last_loc = b->loc; |
3086aeae DJ |
8230 | if (strstr (b->addr_string, "throw") != NULL) |
8231 | ui_out_field_string (uiout, "what", "exception throw"); | |
8232 | else | |
8233 | ui_out_field_string (uiout, "what", "exception catch"); | |
8234 | } | |
8235 | ||
8236 | static void | |
8237 | print_mention_exception_catchpoint (struct breakpoint *b) | |
8238 | { | |
ade92717 AR |
8239 | int bp_temp; |
8240 | int bp_throw; | |
8241 | ||
df2b6d2d | 8242 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
8243 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
8244 | ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ") | |
8245 | : _("Catchpoint ")); | |
8246 | ui_out_field_int (uiout, "bkptno", b->number); | |
8247 | ui_out_text (uiout, bp_throw ? _(" (throw)") | |
8248 | : _(" (catch)")); | |
3086aeae DJ |
8249 | } |
8250 | ||
8251 | static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = { | |
ce78b96d JB |
8252 | NULL, /* insert */ |
8253 | NULL, /* remove */ | |
8254 | NULL, /* breakpoint_hit */ | |
3086aeae DJ |
8255 | print_exception_catchpoint, |
8256 | print_one_exception_catchpoint, | |
8257 | print_mention_exception_catchpoint | |
8258 | }; | |
8259 | ||
8260 | static int | |
8261 | handle_gnu_v3_exceptions (int tempflag, char *cond_string, | |
8262 | enum exception_event_kind ex_event, int from_tty) | |
8263 | { | |
604133b5 AR |
8264 | char *trigger_func_name; |
8265 | ||
3086aeae | 8266 | if (ex_event == EX_EVENT_CATCH) |
604133b5 | 8267 | trigger_func_name = "__cxa_begin_catch"; |
3086aeae | 8268 | else |
604133b5 | 8269 | trigger_func_name = "__cxa_throw"; |
3086aeae | 8270 | |
8cdf0e15 VP |
8271 | create_breakpoint (get_current_arch (), |
8272 | trigger_func_name, cond_string, -1, | |
8273 | 0 /* condition and thread are valid. */, | |
8274 | tempflag, 0, 0, | |
8275 | 0, | |
8276 | AUTO_BOOLEAN_TRUE /* pending */, | |
8277 | &gnu_v3_exception_catchpoint_ops, from_tty, | |
8278 | 1 /* enabled */); | |
3086aeae | 8279 | |
3086aeae DJ |
8280 | return 1; |
8281 | } | |
8282 | ||
c5aa993b | 8283 | /* Deal with "catch catch" and "catch throw" commands */ |
c906108c SS |
8284 | |
8285 | static void | |
fba45db2 KB |
8286 | catch_exception_command_1 (enum exception_event_kind ex_event, char *arg, |
8287 | int tempflag, int from_tty) | |
c906108c | 8288 | { |
c5aa993b JM |
8289 | char *cond_string = NULL; |
8290 | struct symtab_and_line *sal = NULL; | |
8291 | ||
44feb3ce TT |
8292 | if (!arg) |
8293 | arg = ""; | |
c906108c | 8294 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 8295 | |
c906108c SS |
8296 | cond_string = ep_parse_optional_if_clause (&arg); |
8297 | ||
8298 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 8299 | error (_("Junk at end of arguments.")); |
c906108c | 8300 | |
059fb39f PM |
8301 | if (ex_event != EX_EVENT_THROW |
8302 | && ex_event != EX_EVENT_CATCH) | |
8a3fe4f8 | 8303 | error (_("Unsupported or unknown exception event; cannot catch it")); |
c906108c | 8304 | |
3086aeae DJ |
8305 | if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty)) |
8306 | return; | |
8307 | ||
8a3fe4f8 | 8308 | warning (_("Unsupported with this platform/compiler combination.")); |
c906108c SS |
8309 | } |
8310 | ||
44feb3ce TT |
8311 | /* Implementation of "catch catch" command. */ |
8312 | ||
8313 | static void | |
8314 | catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command) | |
8315 | { | |
8316 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8317 | catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty); | |
8318 | } | |
8319 | ||
8320 | /* Implementation of "catch throw" command. */ | |
8321 | ||
8322 | static void | |
8323 | catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command) | |
8324 | { | |
8325 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8326 | catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty); | |
8327 | } | |
8328 | ||
f7f9143b JB |
8329 | /* Create a breakpoint struct for Ada exception catchpoints. */ |
8330 | ||
8331 | static void | |
a6d9a66e UW |
8332 | create_ada_exception_breakpoint (struct gdbarch *gdbarch, |
8333 | struct symtab_and_line sal, | |
f7f9143b JB |
8334 | char *addr_string, |
8335 | char *exp_string, | |
8336 | char *cond_string, | |
8337 | struct expression *cond, | |
8338 | struct breakpoint_ops *ops, | |
8339 | int tempflag, | |
8340 | int from_tty) | |
8341 | { | |
8342 | struct breakpoint *b; | |
8343 | ||
8344 | if (from_tty) | |
8345 | { | |
5af949e3 UW |
8346 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
8347 | if (!loc_gdbarch) | |
8348 | loc_gdbarch = gdbarch; | |
8349 | ||
6c95b8df PA |
8350 | describe_other_breakpoints (loc_gdbarch, |
8351 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
8352 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
8353 | version for exception catchpoints, because two catchpoints | |
8354 | used for different exception names will use the same address. | |
8355 | In this case, a "breakpoint ... also set at..." warning is | |
8356 | unproductive. Besides. the warning phrasing is also a bit | |
8357 | inapropriate, we should use the word catchpoint, and tell | |
8358 | the user what type of catchpoint it is. The above is good | |
8359 | enough for now, though. */ | |
8360 | } | |
8361 | ||
a6d9a66e | 8362 | b = set_raw_breakpoint (gdbarch, sal, bp_breakpoint); |
f7f9143b JB |
8363 | set_breakpoint_count (breakpoint_count + 1); |
8364 | ||
8365 | b->enable_state = bp_enabled; | |
8366 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
8367 | b->number = breakpoint_count; | |
8368 | b->ignore_count = 0; | |
511a6cd4 | 8369 | b->loc->cond = cond; |
f7f9143b JB |
8370 | b->addr_string = addr_string; |
8371 | b->language = language_ada; | |
8372 | b->cond_string = cond_string; | |
8373 | b->exp_string = exp_string; | |
8374 | b->thread = -1; | |
8375 | b->ops = ops; | |
f7f9143b JB |
8376 | |
8377 | mention (b); | |
b60e7edf | 8378 | update_global_location_list (1); |
f7f9143b JB |
8379 | } |
8380 | ||
8381 | /* Implement the "catch exception" command. */ | |
8382 | ||
8383 | static void | |
44feb3ce TT |
8384 | catch_ada_exception_command (char *arg, int from_tty, |
8385 | struct cmd_list_element *command) | |
f7f9143b | 8386 | { |
a6d9a66e | 8387 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 8388 | int tempflag; |
f7f9143b JB |
8389 | struct symtab_and_line sal; |
8390 | enum bptype type; | |
8391 | char *addr_string = NULL; | |
8392 | char *exp_string = NULL; | |
8393 | char *cond_string = NULL; | |
8394 | struct expression *cond = NULL; | |
8395 | struct breakpoint_ops *ops = NULL; | |
8396 | ||
44feb3ce TT |
8397 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
8398 | ||
8399 | if (!arg) | |
8400 | arg = ""; | |
f7f9143b JB |
8401 | sal = ada_decode_exception_location (arg, &addr_string, &exp_string, |
8402 | &cond_string, &cond, &ops); | |
a6d9a66e | 8403 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, exp_string, |
f7f9143b JB |
8404 | cond_string, cond, ops, tempflag, |
8405 | from_tty); | |
8406 | } | |
8407 | ||
a96d9b2e SDJ |
8408 | /* Cleanup function for a syscall filter list. */ |
8409 | static void | |
8410 | clean_up_filters (void *arg) | |
8411 | { | |
8412 | VEC(int) *iter = *(VEC(int) **) arg; | |
8413 | VEC_free (int, iter); | |
8414 | } | |
8415 | ||
8416 | /* Splits the argument using space as delimiter. Returns an xmalloc'd | |
8417 | filter list, or NULL if no filtering is required. */ | |
8418 | static VEC(int) * | |
8419 | catch_syscall_split_args (char *arg) | |
8420 | { | |
8421 | VEC(int) *result = NULL; | |
8422 | struct cleanup *cleanup = make_cleanup (clean_up_filters, &result); | |
8423 | ||
8424 | while (*arg != '\0') | |
8425 | { | |
8426 | int i, syscall_number; | |
8427 | char *endptr; | |
8428 | char cur_name[128]; | |
8429 | struct syscall s; | |
8430 | ||
8431 | /* Skip whitespace. */ | |
8432 | while (isspace (*arg)) | |
8433 | arg++; | |
8434 | ||
8435 | for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) | |
8436 | cur_name[i] = arg[i]; | |
8437 | cur_name[i] = '\0'; | |
8438 | arg += i; | |
8439 | ||
8440 | /* Check if the user provided a syscall name or a number. */ | |
8441 | syscall_number = (int) strtol (cur_name, &endptr, 0); | |
8442 | if (*endptr == '\0') | |
bccd0dd2 | 8443 | get_syscall_by_number (syscall_number, &s); |
a96d9b2e SDJ |
8444 | else |
8445 | { | |
8446 | /* We have a name. Let's check if it's valid and convert it | |
8447 | to a number. */ | |
8448 | get_syscall_by_name (cur_name, &s); | |
8449 | ||
8450 | if (s.number == UNKNOWN_SYSCALL) | |
8451 | /* Here we have to issue an error instead of a warning, because | |
8452 | GDB cannot do anything useful if there's no syscall number to | |
8453 | be caught. */ | |
8454 | error (_("Unknown syscall name '%s'."), cur_name); | |
8455 | } | |
8456 | ||
8457 | /* Ok, it's valid. */ | |
8458 | VEC_safe_push (int, result, s.number); | |
8459 | } | |
8460 | ||
8461 | discard_cleanups (cleanup); | |
8462 | return result; | |
8463 | } | |
8464 | ||
8465 | /* Implement the "catch syscall" command. */ | |
8466 | ||
8467 | static void | |
8468 | catch_syscall_command_1 (char *arg, int from_tty, struct cmd_list_element *command) | |
8469 | { | |
8470 | int tempflag; | |
8471 | VEC(int) *filter; | |
8472 | struct syscall s; | |
8473 | struct gdbarch *gdbarch = get_current_arch (); | |
8474 | ||
8475 | /* Checking if the feature if supported. */ | |
8476 | if (gdbarch_get_syscall_number_p (gdbarch) == 0) | |
8477 | error (_("The feature 'catch syscall' is not supported on \ | |
8478 | this architeture yet.")); | |
8479 | ||
8480 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8481 | ||
8482 | ep_skip_leading_whitespace (&arg); | |
8483 | ||
8484 | /* We need to do this first "dummy" translation in order | |
8485 | to get the syscall XML file loaded or, most important, | |
8486 | to display a warning to the user if there's no XML file | |
8487 | for his/her architecture. */ | |
8488 | get_syscall_by_number (0, &s); | |
8489 | ||
8490 | /* The allowed syntax is: | |
8491 | catch syscall | |
8492 | catch syscall <name | number> [<name | number> ... <name | number>] | |
8493 | ||
8494 | Let's check if there's a syscall name. */ | |
8495 | ||
8496 | if (arg != NULL) | |
8497 | filter = catch_syscall_split_args (arg); | |
8498 | else | |
8499 | filter = NULL; | |
8500 | ||
8501 | create_syscall_event_catchpoint (tempflag, filter, | |
8502 | &catch_syscall_breakpoint_ops); | |
8503 | } | |
8504 | ||
f7f9143b JB |
8505 | /* Implement the "catch assert" command. */ |
8506 | ||
8507 | static void | |
44feb3ce | 8508 | catch_assert_command (char *arg, int from_tty, struct cmd_list_element *command) |
f7f9143b | 8509 | { |
a6d9a66e | 8510 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 8511 | int tempflag; |
f7f9143b JB |
8512 | struct symtab_and_line sal; |
8513 | char *addr_string = NULL; | |
8514 | struct breakpoint_ops *ops = NULL; | |
8515 | ||
44feb3ce TT |
8516 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
8517 | ||
8518 | if (!arg) | |
8519 | arg = ""; | |
f7f9143b | 8520 | sal = ada_decode_assert_location (arg, &addr_string, &ops); |
a6d9a66e UW |
8521 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, NULL, NULL, NULL, |
8522 | ops, tempflag, from_tty); | |
f7f9143b JB |
8523 | } |
8524 | ||
c906108c | 8525 | static void |
fba45db2 | 8526 | catch_command (char *arg, int from_tty) |
c906108c | 8527 | { |
44feb3ce | 8528 | error (_("Catch requires an event name.")); |
c906108c SS |
8529 | } |
8530 | \f | |
8531 | ||
8532 | static void | |
fba45db2 | 8533 | tcatch_command (char *arg, int from_tty) |
c906108c | 8534 | { |
44feb3ce | 8535 | error (_("Catch requires an event name.")); |
c906108c SS |
8536 | } |
8537 | ||
80f8a6eb | 8538 | /* Delete breakpoints by address or line. */ |
c906108c SS |
8539 | |
8540 | static void | |
fba45db2 | 8541 | clear_command (char *arg, int from_tty) |
c906108c | 8542 | { |
d6e956e5 VP |
8543 | struct breakpoint *b; |
8544 | VEC(breakpoint_p) *found = 0; | |
8545 | int ix; | |
c906108c SS |
8546 | int default_match; |
8547 | struct symtabs_and_lines sals; | |
8548 | struct symtab_and_line sal; | |
c906108c SS |
8549 | int i; |
8550 | ||
8551 | if (arg) | |
8552 | { | |
8553 | sals = decode_line_spec (arg, 1); | |
8554 | default_match = 0; | |
8555 | } | |
8556 | else | |
8557 | { | |
c5aa993b | 8558 | sals.sals = (struct symtab_and_line *) |
c906108c | 8559 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 8560 | make_cleanup (xfree, sals.sals); |
fe39c653 | 8561 | init_sal (&sal); /* initialize to zeroes */ |
c906108c SS |
8562 | sal.line = default_breakpoint_line; |
8563 | sal.symtab = default_breakpoint_symtab; | |
8564 | sal.pc = default_breakpoint_address; | |
6c95b8df | 8565 | sal.pspace = default_breakpoint_pspace; |
c906108c | 8566 | if (sal.symtab == 0) |
8a3fe4f8 | 8567 | error (_("No source file specified.")); |
c906108c SS |
8568 | |
8569 | sals.sals[0] = sal; | |
8570 | sals.nelts = 1; | |
8571 | ||
8572 | default_match = 1; | |
8573 | } | |
8574 | ||
ed0616c6 VP |
8575 | /* We don't call resolve_sal_pc here. That's not |
8576 | as bad as it seems, because all existing breakpoints | |
8577 | typically have both file/line and pc set. So, if | |
8578 | clear is given file/line, we can match this to existing | |
8579 | breakpoint without obtaining pc at all. | |
8580 | ||
8581 | We only support clearing given the address explicitly | |
8582 | present in breakpoint table. Say, we've set breakpoint | |
8583 | at file:line. There were several PC values for that file:line, | |
8584 | due to optimization, all in one block. | |
8585 | We've picked one PC value. If "clear" is issued with another | |
8586 | PC corresponding to the same file:line, the breakpoint won't | |
8587 | be cleared. We probably can still clear the breakpoint, but | |
8588 | since the other PC value is never presented to user, user | |
8589 | can only find it by guessing, and it does not seem important | |
8590 | to support that. */ | |
8591 | ||
c906108c | 8592 | /* For each line spec given, delete bps which correspond |
80f8a6eb MS |
8593 | to it. Do it in two passes, solely to preserve the current |
8594 | behavior that from_tty is forced true if we delete more than | |
8595 | one breakpoint. */ | |
c906108c | 8596 | |
80f8a6eb | 8597 | found = NULL; |
c906108c SS |
8598 | for (i = 0; i < sals.nelts; i++) |
8599 | { | |
8600 | /* If exact pc given, clear bpts at that pc. | |
c5aa993b JM |
8601 | If line given (pc == 0), clear all bpts on specified line. |
8602 | If defaulting, clear all bpts on default line | |
c906108c | 8603 | or at default pc. |
c5aa993b JM |
8604 | |
8605 | defaulting sal.pc != 0 tests to do | |
8606 | ||
8607 | 0 1 pc | |
8608 | 1 1 pc _and_ line | |
8609 | 0 0 line | |
8610 | 1 0 <can't happen> */ | |
c906108c SS |
8611 | |
8612 | sal = sals.sals[i]; | |
c906108c | 8613 | |
d6e956e5 VP |
8614 | /* Find all matching breakpoints and add them to |
8615 | 'found'. */ | |
8616 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8617 | { |
0d381245 | 8618 | int match = 0; |
80f8a6eb MS |
8619 | /* Are we going to delete b? */ |
8620 | if (b->type != bp_none | |
8621 | && b->type != bp_watchpoint | |
8622 | && b->type != bp_hardware_watchpoint | |
8623 | && b->type != bp_read_watchpoint | |
0d381245 VP |
8624 | && b->type != bp_access_watchpoint) |
8625 | { | |
8626 | struct bp_location *loc = b->loc; | |
8627 | for (; loc; loc = loc->next) | |
8628 | { | |
6c95b8df PA |
8629 | int pc_match = sal.pc |
8630 | && (loc->pspace == sal.pspace) | |
0d381245 VP |
8631 | && (loc->address == sal.pc) |
8632 | && (!section_is_overlay (loc->section) | |
8633 | || loc->section == sal.section); | |
8634 | int line_match = ((default_match || (0 == sal.pc)) | |
8635 | && b->source_file != NULL | |
8636 | && sal.symtab != NULL | |
6c95b8df | 8637 | && sal.pspace == loc->pspace |
0d381245 VP |
8638 | && strcmp (b->source_file, sal.symtab->filename) == 0 |
8639 | && b->line_number == sal.line); | |
8640 | if (pc_match || line_match) | |
8641 | { | |
8642 | match = 1; | |
8643 | break; | |
8644 | } | |
8645 | } | |
8646 | } | |
8647 | ||
8648 | if (match) | |
d6e956e5 | 8649 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 8650 | } |
80f8a6eb MS |
8651 | } |
8652 | /* Now go thru the 'found' chain and delete them. */ | |
d6e956e5 | 8653 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
8654 | { |
8655 | if (arg) | |
8a3fe4f8 | 8656 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 8657 | else |
8a3fe4f8 | 8658 | error (_("No breakpoint at this line.")); |
80f8a6eb | 8659 | } |
c906108c | 8660 | |
d6e956e5 | 8661 | if (VEC_length(breakpoint_p, found) > 1) |
80f8a6eb MS |
8662 | from_tty = 1; /* Always report if deleted more than one */ |
8663 | if (from_tty) | |
a3f17187 | 8664 | { |
d6e956e5 | 8665 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
8666 | printf_unfiltered (_("Deleted breakpoint ")); |
8667 | else | |
8668 | printf_unfiltered (_("Deleted breakpoints ")); | |
8669 | } | |
80f8a6eb | 8670 | breakpoints_changed (); |
d6e956e5 VP |
8671 | |
8672 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 8673 | { |
c5aa993b | 8674 | if (from_tty) |
d6e956e5 VP |
8675 | printf_unfiltered ("%d ", b->number); |
8676 | delete_breakpoint (b); | |
c906108c | 8677 | } |
80f8a6eb MS |
8678 | if (from_tty) |
8679 | putchar_unfiltered ('\n'); | |
c906108c SS |
8680 | } |
8681 | \f | |
8682 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
8683 | all breakpoints that are marked for deletion, whether hit or not. | |
8684 | This is called after any breakpoint is hit, or after errors. */ | |
8685 | ||
8686 | void | |
fba45db2 | 8687 | breakpoint_auto_delete (bpstat bs) |
c906108c SS |
8688 | { |
8689 | struct breakpoint *b, *temp; | |
8690 | ||
8691 | for (; bs; bs = bs->next) | |
20874c92 VP |
8692 | if (bs->breakpoint_at |
8693 | && bs->breakpoint_at->owner | |
8694 | && bs->breakpoint_at->owner->disposition == disp_del | |
c906108c | 8695 | && bs->stop) |
4f8d1dc6 | 8696 | delete_breakpoint (bs->breakpoint_at->owner); |
c906108c SS |
8697 | |
8698 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b | 8699 | { |
b5de0fa7 | 8700 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
8701 | delete_breakpoint (b); |
8702 | } | |
c906108c SS |
8703 | } |
8704 | ||
494cfb0f | 8705 | /* A comparison function for bp_location AP and BP being interfaced to qsort. |
876fa593 JK |
8706 | Sort elements primarily by their ADDRESS (no matter what does |
8707 | breakpoint_address_is_meaningful say for its OWNER), secondarily by ordering | |
8708 | first bp_permanent OWNERed elements and terciarily just ensuring the array | |
8709 | is sorted stable way despite qsort being an instable algorithm. */ | |
8710 | ||
8711 | static int | |
494cfb0f | 8712 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 8713 | { |
494cfb0f JK |
8714 | struct bp_location *a = *(void **) ap; |
8715 | struct bp_location *b = *(void **) bp; | |
876fa593 JK |
8716 | int a_perm = a->owner->enable_state == bp_permanent; |
8717 | int b_perm = b->owner->enable_state == bp_permanent; | |
8718 | ||
8719 | if (a->address != b->address) | |
8720 | return (a->address > b->address) - (a->address < b->address); | |
8721 | ||
8722 | /* Sort permanent breakpoints first. */ | |
8723 | if (a_perm != b_perm) | |
8724 | return (a_perm < b_perm) - (a_perm > b_perm); | |
8725 | ||
8726 | /* Make the user-visible order stable across GDB runs. Locations of the same | |
8727 | breakpoint can be sorted in arbitrary order. */ | |
8728 | ||
8729 | if (a->owner->number != b->owner->number) | |
8730 | return (a->owner->number > b->owner->number) | |
8731 | - (a->owner->number < b->owner->number); | |
8732 | ||
8733 | return (a > b) - (a < b); | |
8734 | } | |
8735 | ||
876fa593 JK |
8736 | /* Set bp_location_placed_address_before_address_max and |
8737 | bp_location_shadow_len_after_address_max according to the current content of | |
8738 | the bp_location array. */ | |
f7545552 TT |
8739 | |
8740 | static void | |
876fa593 | 8741 | bp_location_target_extensions_update (void) |
f7545552 | 8742 | { |
876fa593 JK |
8743 | struct bp_location *bl, **blp_tmp; |
8744 | ||
8745 | bp_location_placed_address_before_address_max = 0; | |
8746 | bp_location_shadow_len_after_address_max = 0; | |
8747 | ||
8748 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
8749 | { | |
8750 | CORE_ADDR start, end, addr; | |
8751 | ||
8752 | if (!bp_location_has_shadow (bl)) | |
8753 | continue; | |
8754 | ||
8755 | start = bl->target_info.placed_address; | |
8756 | end = start + bl->target_info.shadow_len; | |
8757 | ||
8758 | gdb_assert (bl->address >= start); | |
8759 | addr = bl->address - start; | |
8760 | if (addr > bp_location_placed_address_before_address_max) | |
8761 | bp_location_placed_address_before_address_max = addr; | |
8762 | ||
8763 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
8764 | ||
8765 | gdb_assert (bl->address < end); | |
8766 | addr = end - bl->address; | |
8767 | if (addr > bp_location_shadow_len_after_address_max) | |
8768 | bp_location_shadow_len_after_address_max = addr; | |
8769 | } | |
f7545552 TT |
8770 | } |
8771 | ||
4cd9bd08 | 8772 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
b60e7edf PA |
8773 | into the inferior, only remove already-inserted locations that no |
8774 | longer should be inserted. Functions that delete a breakpoint or | |
8775 | breakpoints should pass false, so that deleting a breakpoint | |
8776 | doesn't have the side effect of inserting the locations of other | |
8777 | breakpoints that are marked not-inserted, but should_be_inserted | |
8778 | returns true on them. | |
8779 | ||
8780 | This behaviour is useful is situations close to tear-down -- e.g., | |
8781 | after an exec, while the target still has execution, but breakpoint | |
8782 | shadows of the previous executable image should *NOT* be restored | |
8783 | to the new image; or before detaching, where the target still has | |
8784 | execution and wants to delete breakpoints from GDB's lists, and all | |
8785 | breakpoints had already been removed from the inferior. */ | |
8786 | ||
0d381245 | 8787 | static void |
b60e7edf | 8788 | update_global_location_list (int should_insert) |
0d381245 | 8789 | { |
74960c60 | 8790 | struct breakpoint *b; |
876fa593 | 8791 | struct bp_location **locp, *loc; |
f7545552 TT |
8792 | struct cleanup *cleanups; |
8793 | ||
2d134ed3 PA |
8794 | /* Used in the duplicates detection below. When iterating over all |
8795 | bp_locations, points to the first bp_location of a given address. | |
8796 | Breakpoints and watchpoints of different types are never | |
8797 | duplicates of each other. Keep one pointer for each type of | |
8798 | breakpoint/watchpoint, so we only need to loop over all locations | |
8799 | once. */ | |
8800 | struct bp_location *bp_loc_first; /* breakpoint */ | |
8801 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
8802 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
8803 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 JK |
8804 | |
8805 | /* Saved former bp_location array which we compare against the newly built | |
8806 | bp_location from the current state of ALL_BREAKPOINTS. */ | |
8807 | struct bp_location **old_location, **old_locp; | |
8808 | unsigned old_location_count; | |
8809 | ||
8810 | old_location = bp_location; | |
8811 | old_location_count = bp_location_count; | |
8812 | bp_location = NULL; | |
8813 | bp_location_count = 0; | |
8814 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 8815 | |
74960c60 | 8816 | ALL_BREAKPOINTS (b) |
876fa593 JK |
8817 | for (loc = b->loc; loc; loc = loc->next) |
8818 | bp_location_count++; | |
8819 | ||
8820 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); | |
8821 | locp = bp_location; | |
8822 | ALL_BREAKPOINTS (b) | |
8823 | for (loc = b->loc; loc; loc = loc->next) | |
8824 | *locp++ = loc; | |
8825 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 8826 | bp_location_compare); |
876fa593 JK |
8827 | |
8828 | bp_location_target_extensions_update (); | |
74960c60 VP |
8829 | |
8830 | /* Identify bp_location instances that are no longer present in the new | |
8831 | list, and therefore should be freed. Note that it's not necessary that | |
8832 | those locations should be removed from inferior -- if there's another | |
8833 | location at the same address (previously marked as duplicate), | |
876fa593 JK |
8834 | we don't need to remove/insert the location. |
8835 | ||
8836 | LOCP is kept in sync with OLD_LOCP, each pointing to the current and | |
8837 | former bp_location array state respectively. */ | |
8838 | ||
8839 | locp = bp_location; | |
8840 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
8841 | old_locp++) | |
74960c60 | 8842 | { |
876fa593 | 8843 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 8844 | struct bp_location **loc2p; |
876fa593 JK |
8845 | |
8846 | /* Tells if 'old_loc' is found amoung the new locations. If not, we | |
74960c60 | 8847 | have to free it. */ |
c7d46a38 | 8848 | int found_object = 0; |
20874c92 VP |
8849 | /* Tells if the location should remain inserted in the target. */ |
8850 | int keep_in_target = 0; | |
8851 | int removed = 0; | |
876fa593 JK |
8852 | |
8853 | /* Skip LOCP entries which will definitely never be needed. Stop either | |
8854 | at or being the one matching OLD_LOC. */ | |
8855 | while (locp < bp_location + bp_location_count | |
c7d46a38 | 8856 | && (*locp)->address < old_loc->address) |
876fa593 | 8857 | locp++; |
c7d46a38 PA |
8858 | |
8859 | for (loc2p = locp; | |
8860 | (loc2p < bp_location + bp_location_count | |
8861 | && (*loc2p)->address == old_loc->address); | |
8862 | loc2p++) | |
8863 | { | |
8864 | if (*loc2p == old_loc) | |
8865 | { | |
8866 | found_object = 1; | |
8867 | break; | |
8868 | } | |
8869 | } | |
74960c60 VP |
8870 | |
8871 | /* If this location is no longer present, and inserted, look if there's | |
8872 | maybe a new location at the same address. If so, mark that one | |
8873 | inserted, and don't remove this one. This is needed so that we | |
8874 | don't have a time window where a breakpoint at certain location is not | |
8875 | inserted. */ | |
8876 | ||
876fa593 | 8877 | if (old_loc->inserted) |
0d381245 | 8878 | { |
74960c60 | 8879 | /* If the location is inserted now, we might have to remove it. */ |
74960c60 | 8880 | |
876fa593 | 8881 | if (found_object && should_be_inserted (old_loc)) |
74960c60 VP |
8882 | { |
8883 | /* The location is still present in the location list, and still | |
8884 | should be inserted. Don't do anything. */ | |
20874c92 | 8885 | keep_in_target = 1; |
74960c60 VP |
8886 | } |
8887 | else | |
8888 | { | |
8889 | /* The location is either no longer present, or got disabled. | |
8890 | See if there's another location at the same address, in which | |
8891 | case we don't need to remove this one from the target. */ | |
876fa593 JK |
8892 | |
8893 | if (breakpoint_address_is_meaningful (old_loc->owner)) | |
8894 | { | |
876fa593 | 8895 | for (loc2p = locp; |
c7d46a38 PA |
8896 | (loc2p < bp_location + bp_location_count |
8897 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
8898 | loc2p++) |
8899 | { | |
8900 | struct bp_location *loc2 = *loc2p; | |
8901 | ||
2d134ed3 | 8902 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 PA |
8903 | { |
8904 | /* For the sake of should_be_inserted. | |
8905 | Duplicates check below will fix up this later. */ | |
8906 | loc2->duplicate = 0; | |
85d721b8 PA |
8907 | |
8908 | /* Read watchpoint locations are switched to | |
8909 | access watchpoints, if the former are not | |
8910 | supported, but the latter are. */ | |
8911 | if (is_hardware_watchpoint (old_loc->owner)) | |
8912 | { | |
8913 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
8914 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
8915 | } | |
8916 | ||
c7d46a38 PA |
8917 | if (loc2 != old_loc && should_be_inserted (loc2)) |
8918 | { | |
8919 | loc2->inserted = 1; | |
8920 | loc2->target_info = old_loc->target_info; | |
8921 | keep_in_target = 1; | |
8922 | break; | |
8923 | } | |
876fa593 JK |
8924 | } |
8925 | } | |
8926 | } | |
74960c60 VP |
8927 | } |
8928 | ||
20874c92 VP |
8929 | if (!keep_in_target) |
8930 | { | |
876fa593 | 8931 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 VP |
8932 | { |
8933 | /* This is just about all we can do. We could keep this | |
8934 | location on the global list, and try to remove it next | |
8935 | time, but there's no particular reason why we will | |
8936 | succeed next time. | |
8937 | ||
876fa593 | 8938 | Note that at this point, old_loc->owner is still valid, |
20874c92 VP |
8939 | as delete_breakpoint frees the breakpoint only |
8940 | after calling us. */ | |
8941 | printf_filtered (_("warning: Error removing breakpoint %d\n"), | |
876fa593 | 8942 | old_loc->owner->number); |
20874c92 VP |
8943 | } |
8944 | removed = 1; | |
8945 | } | |
0d381245 | 8946 | } |
74960c60 VP |
8947 | |
8948 | if (!found_object) | |
1c5cfe86 | 8949 | { |
db82e815 PA |
8950 | if (removed && non_stop |
8951 | && breakpoint_address_is_meaningful (old_loc->owner) | |
8952 | && !is_hardware_watchpoint (old_loc->owner)) | |
20874c92 | 8953 | { |
db82e815 PA |
8954 | /* This location was removed from the target. In |
8955 | non-stop mode, a race condition is possible where | |
8956 | we've removed a breakpoint, but stop events for that | |
8957 | breakpoint are already queued and will arrive later. | |
8958 | We apply an heuristic to be able to distinguish such | |
8959 | SIGTRAPs from other random SIGTRAPs: we keep this | |
8960 | breakpoint location for a bit, and will retire it | |
8961 | after we see some number of events. The theory here | |
8962 | is that reporting of events should, "on the average", | |
8963 | be fair, so after a while we'll see events from all | |
8964 | threads that have anything of interest, and no longer | |
8965 | need to keep this breakpoint location around. We | |
8966 | don't hold locations forever so to reduce chances of | |
8967 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
8968 | SIGTRAP. | |
8969 | ||
8970 | The heuristic failing can be disastrous on | |
8971 | decr_pc_after_break targets. | |
8972 | ||
8973 | On decr_pc_after_break targets, like e.g., x86-linux, | |
8974 | if we fail to recognize a late breakpoint SIGTRAP, | |
8975 | because events_till_retirement has reached 0 too | |
8976 | soon, we'll fail to do the PC adjustment, and report | |
8977 | a random SIGTRAP to the user. When the user resumes | |
8978 | the inferior, it will most likely immediately crash | |
8979 | with SIGILL/SIGBUS/SEGSEGV, or worse, get silently | |
8980 | corrupted, because of being resumed e.g., in the | |
8981 | middle of a multi-byte instruction, or skipped a | |
8982 | one-byte instruction. This was actually seen happen | |
8983 | on native x86-linux, and should be less rare on | |
8984 | targets that do not support new thread events, like | |
8985 | remote, due to the heuristic depending on | |
8986 | thread_count. | |
8987 | ||
8988 | Mistaking a random SIGTRAP for a breakpoint trap | |
8989 | causes similar symptoms (PC adjustment applied when | |
8990 | it shouldn't), but then again, playing with SIGTRAPs | |
8991 | behind the debugger's back is asking for trouble. | |
8992 | ||
8993 | Since hardware watchpoint traps are always | |
8994 | distinguishable from other traps, so we don't need to | |
8995 | apply keep hardware watchpoint moribund locations | |
8996 | around. We simply always ignore hardware watchpoint | |
8997 | traps we can no longer explain. */ | |
8998 | ||
876fa593 JK |
8999 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
9000 | old_loc->owner = NULL; | |
20874c92 | 9001 | |
876fa593 | 9002 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
9003 | } |
9004 | else | |
876fa593 | 9005 | free_bp_location (old_loc); |
20874c92 | 9006 | } |
74960c60 | 9007 | } |
1c5cfe86 | 9008 | |
2d134ed3 PA |
9009 | /* Rescan breakpoints at the same address and section, marking the |
9010 | first one as "first" and any others as "duplicates". This is so | |
9011 | that the bpt instruction is only inserted once. If we have a | |
9012 | permanent breakpoint at the same place as BPT, make that one the | |
9013 | official one, and the rest as duplicates. Permanent breakpoints | |
9014 | are sorted first for the same address. | |
9015 | ||
9016 | Do the same for hardware watchpoints, but also considering the | |
9017 | watchpoint's type (regular/access/read) and length. */ | |
876fa593 | 9018 | |
2d134ed3 PA |
9019 | bp_loc_first = NULL; |
9020 | wp_loc_first = NULL; | |
9021 | awp_loc_first = NULL; | |
9022 | rwp_loc_first = NULL; | |
876fa593 | 9023 | ALL_BP_LOCATIONS (loc, locp) |
74960c60 | 9024 | { |
876fa593 | 9025 | struct breakpoint *b = loc->owner; |
2d134ed3 | 9026 | struct bp_location **loc_first_p; |
876fa593 JK |
9027 | |
9028 | if (b->enable_state == bp_disabled | |
9029 | || b->enable_state == bp_call_disabled | |
9030 | || b->enable_state == bp_startup_disabled | |
9031 | || !loc->enabled | |
9032 | || loc->shlib_disabled | |
15c3d785 PA |
9033 | || !breakpoint_address_is_meaningful (b) |
9034 | || tracepoint_type (b)) | |
876fa593 JK |
9035 | continue; |
9036 | ||
9037 | /* Permanent breakpoint should always be inserted. */ | |
9038 | if (b->enable_state == bp_permanent && ! loc->inserted) | |
9039 | internal_error (__FILE__, __LINE__, | |
9040 | _("allegedly permanent breakpoint is not " | |
9041 | "actually inserted")); | |
9042 | ||
2d134ed3 PA |
9043 | if (b->type == bp_hardware_watchpoint) |
9044 | loc_first_p = &wp_loc_first; | |
9045 | else if (b->type == bp_read_watchpoint) | |
9046 | loc_first_p = &rwp_loc_first; | |
9047 | else if (b->type == bp_access_watchpoint) | |
9048 | loc_first_p = &awp_loc_first; | |
9049 | else | |
9050 | loc_first_p = &bp_loc_first; | |
9051 | ||
9052 | if (*loc_first_p == NULL | |
9053 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
9054 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
876fa593 | 9055 | { |
2d134ed3 | 9056 | *loc_first_p = loc; |
876fa593 JK |
9057 | loc->duplicate = 0; |
9058 | continue; | |
9059 | } | |
9060 | ||
9061 | loc->duplicate = 1; | |
9062 | ||
2d134ed3 PA |
9063 | if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted |
9064 | && b->enable_state != bp_permanent) | |
876fa593 JK |
9065 | internal_error (__FILE__, __LINE__, |
9066 | _("another breakpoint was inserted on top of " | |
9067 | "a permanent breakpoint")); | |
0d381245 | 9068 | } |
74960c60 | 9069 | |
50c71eaf | 9070 | if (breakpoints_always_inserted_mode () && should_insert |
c35b1492 | 9071 | && (have_live_inferiors () |
2567c7d9 | 9072 | || (gdbarch_has_global_breakpoints (target_gdbarch)))) |
74960c60 | 9073 | insert_breakpoint_locations (); |
f7545552 TT |
9074 | |
9075 | do_cleanups (cleanups); | |
74960c60 VP |
9076 | } |
9077 | ||
20874c92 VP |
9078 | void |
9079 | breakpoint_retire_moribund (void) | |
9080 | { | |
9081 | struct bp_location *loc; | |
9082 | int ix; | |
9083 | ||
9084 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
9085 | if (--(loc->events_till_retirement) == 0) | |
9086 | { | |
9087 | free_bp_location (loc); | |
9088 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
9089 | --ix; | |
9090 | } | |
9091 | } | |
9092 | ||
74960c60 | 9093 | static void |
b60e7edf | 9094 | update_global_location_list_nothrow (int inserting) |
74960c60 VP |
9095 | { |
9096 | struct gdb_exception e; | |
9097 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
b60e7edf | 9098 | update_global_location_list (inserting); |
0d381245 VP |
9099 | } |
9100 | ||
a474d7c2 PA |
9101 | /* Clear BPT from a BPS. */ |
9102 | static void | |
9103 | bpstat_remove_breakpoint (bpstat bps, struct breakpoint *bpt) | |
9104 | { | |
9105 | bpstat bs; | |
9106 | for (bs = bps; bs; bs = bs->next) | |
9107 | if (bs->breakpoint_at && bs->breakpoint_at->owner == bpt) | |
9108 | { | |
9109 | bs->breakpoint_at = NULL; | |
9110 | bs->old_val = NULL; | |
9111 | /* bs->commands will be freed later. */ | |
9112 | } | |
9113 | } | |
9114 | ||
9115 | /* Callback for iterate_over_threads. */ | |
9116 | static int | |
9117 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
9118 | { | |
9119 | struct breakpoint *bpt = data; | |
9120 | bpstat_remove_breakpoint (th->stop_bpstat, bpt); | |
9121 | return 0; | |
9122 | } | |
9123 | ||
53a5351d JM |
9124 | /* Delete a breakpoint and clean up all traces of it in the data |
9125 | structures. */ | |
c906108c SS |
9126 | |
9127 | void | |
fba45db2 | 9128 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 9129 | { |
52f0bd74 | 9130 | struct breakpoint *b; |
74960c60 | 9131 | struct bp_location *loc, *next; |
c906108c | 9132 | |
8a3fe4f8 | 9133 | gdb_assert (bpt != NULL); |
c906108c SS |
9134 | |
9135 | /* Has this bp already been deleted? This can happen because multiple | |
9136 | lists can hold pointers to bp's. bpstat lists are especial culprits. | |
9137 | ||
9138 | One example of this happening is a watchpoint's scope bp. When the | |
9139 | scope bp triggers, we notice that the watchpoint is out of scope, and | |
9140 | delete it. We also delete its scope bp. But the scope bp is marked | |
9141 | "auto-deleting", and is already on a bpstat. That bpstat is then | |
9142 | checked for auto-deleting bp's, which are deleted. | |
9143 | ||
9144 | A real solution to this problem might involve reference counts in bp's, | |
9145 | and/or giving them pointers back to their referencing bpstat's, and | |
9146 | teaching delete_breakpoint to only free a bp's storage when no more | |
1272ad14 | 9147 | references were extent. A cheaper bandaid was chosen. */ |
c906108c SS |
9148 | if (bpt->type == bp_none) |
9149 | return; | |
9150 | ||
e5a0a904 JK |
9151 | /* At least avoid this stale reference until the reference counting of |
9152 | breakpoints gets resolved. */ | |
9153 | if (bpt->related_breakpoint != NULL) | |
9154 | { | |
9155 | gdb_assert (bpt->related_breakpoint->related_breakpoint == bpt); | |
9156 | bpt->related_breakpoint->disposition = disp_del_at_next_stop; | |
9157 | bpt->related_breakpoint->related_breakpoint = NULL; | |
9158 | bpt->related_breakpoint = NULL; | |
9159 | } | |
9160 | ||
383f836e | 9161 | observer_notify_breakpoint_deleted (bpt->number); |
c906108c | 9162 | |
c906108c SS |
9163 | if (breakpoint_chain == bpt) |
9164 | breakpoint_chain = bpt->next; | |
9165 | ||
c906108c SS |
9166 | ALL_BREAKPOINTS (b) |
9167 | if (b->next == bpt) | |
c5aa993b JM |
9168 | { |
9169 | b->next = bpt->next; | |
9170 | break; | |
9171 | } | |
c906108c | 9172 | |
9add0f1b | 9173 | decref_counted_command_line (&bpt->commands); |
60e1c644 PA |
9174 | xfree (bpt->cond_string); |
9175 | xfree (bpt->cond_exp); | |
9176 | xfree (bpt->addr_string); | |
9177 | xfree (bpt->exp); | |
9178 | xfree (bpt->exp_string); | |
9179 | value_free (bpt->val); | |
9180 | xfree (bpt->source_file); | |
9181 | xfree (bpt->exec_pathname); | |
a96d9b2e | 9182 | clean_up_filters (&bpt->syscalls_to_be_caught); |
c906108c SS |
9183 | |
9184 | /* Be sure no bpstat's are pointing at it after it's been freed. */ | |
9185 | /* FIXME, how can we find all bpstat's? | |
198757a8 VP |
9186 | We just check stop_bpstat for now. Note that we cannot just |
9187 | remove bpstats pointing at bpt from the stop_bpstat list | |
9188 | entirely, as breakpoint commands are associated with the bpstat; | |
9189 | if we remove it here, then the later call to | |
9190 | bpstat_do_actions (&stop_bpstat); | |
9191 | in event-top.c won't do anything, and temporary breakpoints | |
9192 | with commands won't work. */ | |
a474d7c2 | 9193 | |
a474d7c2 | 9194 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); |
74960c60 VP |
9195 | |
9196 | /* Now that breakpoint is removed from breakpoint | |
9197 | list, update the global location list. This | |
9198 | will remove locations that used to belong to | |
9199 | this breakpoint. Do this before freeing | |
9200 | the breakpoint itself, since remove_breakpoint | |
9201 | looks at location's owner. It might be better | |
9202 | design to have location completely self-contained, | |
9203 | but it's not the case now. */ | |
b60e7edf | 9204 | update_global_location_list (0); |
74960c60 VP |
9205 | |
9206 | ||
c906108c SS |
9207 | /* On the chance that someone will soon try again to delete this same |
9208 | bp, we mark it as deleted before freeing its storage. */ | |
9209 | bpt->type = bp_none; | |
9210 | ||
b8c9b27d | 9211 | xfree (bpt); |
c906108c SS |
9212 | } |
9213 | ||
4d6140d9 AC |
9214 | static void |
9215 | do_delete_breakpoint_cleanup (void *b) | |
9216 | { | |
9217 | delete_breakpoint (b); | |
9218 | } | |
9219 | ||
9220 | struct cleanup * | |
9221 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
9222 | { | |
9223 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
9224 | } | |
9225 | ||
95a42b64 TT |
9226 | /* A callback for map_breakpoint_numbers that calls |
9227 | delete_breakpoint. */ | |
9228 | ||
9229 | static void | |
9230 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
9231 | { | |
9232 | delete_breakpoint (b); | |
9233 | } | |
9234 | ||
c906108c | 9235 | void |
fba45db2 | 9236 | delete_command (char *arg, int from_tty) |
c906108c SS |
9237 | { |
9238 | struct breakpoint *b, *temp; | |
9239 | ||
ea9365bb TT |
9240 | dont_repeat (); |
9241 | ||
c906108c SS |
9242 | if (arg == 0) |
9243 | { | |
9244 | int breaks_to_delete = 0; | |
9245 | ||
9246 | /* Delete all breakpoints if no argument. | |
c5aa993b JM |
9247 | Do not delete internal or call-dummy breakpoints, these |
9248 | have to be deleted with an explicit breakpoint number argument. */ | |
9249 | ALL_BREAKPOINTS (b) | |
9250 | { | |
059fb39f | 9251 | if (b->type != bp_call_dummy |
aa7d318d | 9252 | && b->type != bp_std_terminate |
059fb39f | 9253 | && b->type != bp_shlib_event |
4efc6507 | 9254 | && b->type != bp_jit_event |
059fb39f PM |
9255 | && b->type != bp_thread_event |
9256 | && b->type != bp_overlay_event | |
0fd8e87f | 9257 | && b->type != bp_longjmp_master |
aa7d318d | 9258 | && b->type != bp_std_terminate_master |
059fb39f | 9259 | && b->number >= 0) |
973d738b DJ |
9260 | { |
9261 | breaks_to_delete = 1; | |
9262 | break; | |
9263 | } | |
c5aa993b | 9264 | } |
c906108c SS |
9265 | |
9266 | /* Ask user only if there are some breakpoints to delete. */ | |
9267 | if (!from_tty | |
e2e0b3e5 | 9268 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 9269 | { |
c5aa993b JM |
9270 | ALL_BREAKPOINTS_SAFE (b, temp) |
9271 | { | |
059fb39f | 9272 | if (b->type != bp_call_dummy |
aa7d318d | 9273 | && b->type != bp_std_terminate |
059fb39f PM |
9274 | && b->type != bp_shlib_event |
9275 | && b->type != bp_thread_event | |
4efc6507 | 9276 | && b->type != bp_jit_event |
059fb39f | 9277 | && b->type != bp_overlay_event |
0fd8e87f | 9278 | && b->type != bp_longjmp_master |
aa7d318d | 9279 | && b->type != bp_std_terminate_master |
059fb39f | 9280 | && b->number >= 0) |
c5aa993b JM |
9281 | delete_breakpoint (b); |
9282 | } | |
c906108c SS |
9283 | } |
9284 | } | |
9285 | else | |
95a42b64 | 9286 | map_breakpoint_numbers (arg, do_delete_breakpoint, NULL); |
c906108c SS |
9287 | } |
9288 | ||
0d381245 VP |
9289 | static int |
9290 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 9291 | { |
0d381245 VP |
9292 | for (; loc; loc = loc->next) |
9293 | if (!loc->shlib_disabled) | |
9294 | return 0; | |
9295 | return 1; | |
fe3f5fa8 VP |
9296 | } |
9297 | ||
776592bf DE |
9298 | /* Subroutine of update_breakpoint_locations to simplify it. |
9299 | Return non-zero if multiple fns in list LOC have the same name. | |
9300 | Null names are ignored. */ | |
9301 | ||
9302 | static int | |
9303 | ambiguous_names_p (struct bp_location *loc) | |
9304 | { | |
9305 | struct bp_location *l; | |
9306 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
9307 | (int (*) (const void *, const void *)) streq, | |
9308 | NULL, xcalloc, xfree); | |
9309 | ||
9310 | for (l = loc; l != NULL; l = l->next) | |
9311 | { | |
9312 | const char **slot; | |
9313 | const char *name = l->function_name; | |
9314 | ||
9315 | /* Allow for some names to be NULL, ignore them. */ | |
9316 | if (name == NULL) | |
9317 | continue; | |
9318 | ||
9319 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
9320 | INSERT); | |
9321 | /* NOTE: We can assume slot != NULL here because xcalloc never returns | |
9322 | NULL. */ | |
9323 | if (*slot != NULL) | |
9324 | { | |
9325 | htab_delete (htab); | |
9326 | return 1; | |
9327 | } | |
9328 | *slot = name; | |
9329 | } | |
9330 | ||
9331 | htab_delete (htab); | |
9332 | return 0; | |
9333 | } | |
9334 | ||
fe3f5fa8 | 9335 | static void |
0d381245 VP |
9336 | update_breakpoint_locations (struct breakpoint *b, |
9337 | struct symtabs_and_lines sals) | |
fe3f5fa8 VP |
9338 | { |
9339 | int i; | |
9340 | char *s; | |
0d381245 VP |
9341 | struct bp_location *existing_locations = b->loc; |
9342 | ||
9343 | /* If there's no new locations, and all existing locations | |
9344 | are pending, don't do anything. This optimizes | |
9345 | the common case where all locations are in the same | |
9346 | shared library, that was unloaded. We'd like to | |
9347 | retain the location, so that when the library | |
9348 | is loaded again, we don't loose the enabled/disabled | |
9349 | status of the individual locations. */ | |
9350 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) | |
fe3f5fa8 VP |
9351 | return; |
9352 | ||
fe3f5fa8 VP |
9353 | b->loc = NULL; |
9354 | ||
0d381245 | 9355 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 9356 | { |
0d381245 | 9357 | struct bp_location *new_loc = |
39d61571 | 9358 | add_location_to_breakpoint (b, &(sals.sals[i])); |
fe3f5fa8 | 9359 | |
0d381245 VP |
9360 | /* Reparse conditions, they might contain references to the |
9361 | old symtab. */ | |
9362 | if (b->cond_string != NULL) | |
9363 | { | |
9364 | struct gdb_exception e; | |
fe3f5fa8 | 9365 | |
0d381245 VP |
9366 | s = b->cond_string; |
9367 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
9368 | { | |
9369 | new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), | |
9370 | 0); | |
9371 | } | |
9372 | if (e.reason < 0) | |
9373 | { | |
9374 | warning (_("failed to reevaluate condition for breakpoint %d: %s"), | |
9375 | b->number, e.message); | |
9376 | new_loc->enabled = 0; | |
9377 | } | |
9378 | } | |
fe3f5fa8 | 9379 | |
0d381245 VP |
9380 | if (b->source_file != NULL) |
9381 | xfree (b->source_file); | |
9382 | if (sals.sals[i].symtab == NULL) | |
9383 | b->source_file = NULL; | |
9384 | else | |
1b36a34b | 9385 | b->source_file = xstrdup (sals.sals[i].symtab->filename); |
fe3f5fa8 | 9386 | |
0d381245 VP |
9387 | if (b->line_number == 0) |
9388 | b->line_number = sals.sals[i].line; | |
9389 | } | |
fe3f5fa8 | 9390 | |
514f746b AR |
9391 | /* Update locations of permanent breakpoints. */ |
9392 | if (b->enable_state == bp_permanent) | |
9393 | make_breakpoint_permanent (b); | |
9394 | ||
0d381245 VP |
9395 | /* If possible, carry over 'disable' status from existing breakpoints. */ |
9396 | { | |
9397 | struct bp_location *e = existing_locations; | |
776592bf DE |
9398 | /* If there are multiple breakpoints with the same function name, |
9399 | e.g. for inline functions, comparing function names won't work. | |
9400 | Instead compare pc addresses; this is just a heuristic as things | |
9401 | may have moved, but in practice it gives the correct answer | |
9402 | often enough until a better solution is found. */ | |
9403 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
9404 | ||
0d381245 VP |
9405 | for (; e; e = e->next) |
9406 | { | |
9407 | if (!e->enabled && e->function_name) | |
9408 | { | |
9409 | struct bp_location *l = b->loc; | |
776592bf DE |
9410 | if (have_ambiguous_names) |
9411 | { | |
9412 | for (; l; l = l->next) | |
6c95b8df PA |
9413 | if (breakpoint_address_match (e->pspace->aspace, e->address, |
9414 | l->pspace->aspace, l->address)) | |
776592bf DE |
9415 | { |
9416 | l->enabled = 0; | |
9417 | break; | |
9418 | } | |
9419 | } | |
9420 | else | |
9421 | { | |
9422 | for (; l; l = l->next) | |
9423 | if (l->function_name | |
9424 | && strcmp (e->function_name, l->function_name) == 0) | |
9425 | { | |
9426 | l->enabled = 0; | |
9427 | break; | |
9428 | } | |
9429 | } | |
0d381245 VP |
9430 | } |
9431 | } | |
9432 | } | |
fe3f5fa8 | 9433 | |
b60e7edf | 9434 | update_global_location_list (1); |
fe3f5fa8 VP |
9435 | } |
9436 | ||
9437 | ||
c906108c SS |
9438 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
9439 | The value we return ends up being the return value from catch_errors. | |
9440 | Unused in this case. */ | |
9441 | ||
9442 | static int | |
4efb68b1 | 9443 | breakpoint_re_set_one (void *bint) |
c906108c | 9444 | { |
53a5351d JM |
9445 | /* get past catch_errs */ |
9446 | struct breakpoint *b = (struct breakpoint *) bint; | |
c906108c SS |
9447 | struct value *mark; |
9448 | int i; | |
fe3f5fa8 VP |
9449 | int not_found = 0; |
9450 | int *not_found_ptr = ¬_found; | |
6c95b8df PA |
9451 | struct symtabs_and_lines sals = {0}; |
9452 | struct symtabs_and_lines expanded = {0}; | |
c906108c | 9453 | char *s; |
b5de0fa7 | 9454 | enum enable_state save_enable; |
fe3f5fa8 | 9455 | struct gdb_exception e; |
6c95b8df | 9456 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
c906108c SS |
9457 | |
9458 | switch (b->type) | |
9459 | { | |
9460 | case bp_none: | |
8a3fe4f8 | 9461 | warning (_("attempted to reset apparently deleted breakpoint #%d?"), |
53a5351d | 9462 | b->number); |
c906108c SS |
9463 | return 0; |
9464 | case bp_breakpoint: | |
9465 | case bp_hardware_breakpoint: | |
1042e4c0 | 9466 | case bp_tracepoint: |
7a697b8d | 9467 | case bp_fast_tracepoint: |
8bea4e01 UW |
9468 | /* Do not attempt to re-set breakpoints disabled during startup. */ |
9469 | if (b->enable_state == bp_startup_disabled) | |
9470 | return 0; | |
9471 | ||
c906108c SS |
9472 | if (b->addr_string == NULL) |
9473 | { | |
9474 | /* Anything without a string can't be re-set. */ | |
9475 | delete_breakpoint (b); | |
9476 | return 0; | |
9477 | } | |
c906108c SS |
9478 | |
9479 | set_language (b->language); | |
9480 | input_radix = b->input_radix; | |
9481 | s = b->addr_string; | |
6c95b8df PA |
9482 | |
9483 | save_current_space_and_thread (); | |
9484 | switch_to_program_space_and_thread (b->pspace); | |
9485 | ||
fe3f5fa8 | 9486 | TRY_CATCH (e, RETURN_MASK_ERROR) |
c906108c | 9487 | { |
fe3f5fa8 VP |
9488 | sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL, |
9489 | not_found_ptr); | |
9490 | } | |
9491 | if (e.reason < 0) | |
9492 | { | |
9493 | int not_found_and_ok = 0; | |
9494 | /* For pending breakpoints, it's expected that parsing | |
9495 | will fail until the right shared library is loaded. | |
9496 | User has already told to create pending breakpoints and | |
9497 | don't need extra messages. If breakpoint is in bp_shlib_disabled | |
9498 | state, then user already saw the message about that breakpoint | |
9499 | being disabled, and don't want to see more errors. */ | |
0d381245 VP |
9500 | if (not_found |
9501 | && (b->condition_not_parsed | |
9502 | || (b->loc && b->loc->shlib_disabled) | |
9503 | || b->enable_state == bp_disabled)) | |
fe3f5fa8 VP |
9504 | not_found_and_ok = 1; |
9505 | ||
9506 | if (!not_found_and_ok) | |
c906108c | 9507 | { |
fe3f5fa8 VP |
9508 | /* We surely don't want to warn about the same breakpoint |
9509 | 10 times. One solution, implemented here, is disable | |
9510 | the breakpoint on error. Another solution would be to | |
9511 | have separate 'warning emitted' flag. Since this | |
9512 | happens only when a binary has changed, I don't know | |
9513 | which approach is better. */ | |
9514 | b->enable_state = bp_disabled; | |
9515 | throw_exception (e); | |
c906108c | 9516 | } |
fe3f5fa8 | 9517 | } |
c906108c | 9518 | |
6c95b8df | 9519 | if (!not_found) |
fe3f5fa8 | 9520 | { |
6c95b8df PA |
9521 | gdb_assert (sals.nelts == 1); |
9522 | ||
9523 | resolve_sal_pc (&sals.sals[0]); | |
9524 | if (b->condition_not_parsed && s && s[0]) | |
9525 | { | |
9526 | char *cond_string = 0; | |
9527 | int thread = -1; | |
9528 | int task = 0; | |
9529 | ||
9530 | find_condition_and_thread (s, sals.sals[0].pc, | |
9531 | &cond_string, &thread, &task); | |
9532 | if (cond_string) | |
9533 | b->cond_string = cond_string; | |
9534 | b->thread = thread; | |
9535 | b->task = task; | |
9536 | b->condition_not_parsed = 0; | |
9537 | } | |
9538 | ||
9539 | expanded = expand_line_sal_maybe (sals.sals[0]); | |
fe3f5fa8 | 9540 | } |
6c95b8df PA |
9541 | |
9542 | make_cleanup (xfree, sals.sals); | |
ed0616c6 | 9543 | update_breakpoint_locations (b, expanded); |
c906108c SS |
9544 | break; |
9545 | ||
9546 | case bp_watchpoint: | |
9547 | case bp_hardware_watchpoint: | |
9548 | case bp_read_watchpoint: | |
9549 | case bp_access_watchpoint: | |
0b3de036 VP |
9550 | /* Watchpoint can be either on expression using entirely global variables, |
9551 | or it can be on local variables. | |
9552 | ||
9553 | Watchpoints of the first kind are never auto-deleted, and even persist | |
9554 | across program restarts. Since they can use variables from shared | |
9555 | libraries, we need to reparse expression as libraries are loaded | |
9556 | and unloaded. | |
9557 | ||
9558 | Watchpoints on local variables can also change meaning as result | |
9559 | of solib event. For example, if a watchpoint uses both a local and | |
9560 | a global variables in expression, it's a local watchpoint, but | |
9561 | unloading of a shared library will make the expression invalid. | |
9562 | This is not a very common use case, but we still re-evaluate | |
9563 | expression, to avoid surprises to the user. | |
9564 | ||
9565 | Note that for local watchpoints, we re-evaluate it only if | |
9566 | watchpoints frame id is still valid. If it's not, it means | |
9567 | the watchpoint is out of scope and will be deleted soon. In fact, | |
9568 | I'm not sure we'll ever be called in this case. | |
9569 | ||
9570 | If a local watchpoint's frame id is still valid, then | |
9571 | b->exp_valid_block is likewise valid, and we can safely use it. | |
9572 | ||
9573 | Don't do anything about disabled watchpoints, since they will | |
9574 | be reevaluated again when enabled. */ | |
a5606eee | 9575 | update_watchpoint (b, 1 /* reparse */); |
c906108c | 9576 | break; |
c5aa993b JM |
9577 | /* We needn't really do anything to reset these, since the mask |
9578 | that requests them is unaffected by e.g., new libraries being | |
9579 | loaded. */ | |
ce78b96d | 9580 | case bp_catchpoint: |
c906108c | 9581 | break; |
c5aa993b | 9582 | |
c906108c | 9583 | default: |
a3f17187 | 9584 | printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type); |
c906108c | 9585 | /* fall through */ |
0fd8e87f UW |
9586 | /* Delete overlay event and longjmp master breakpoints; they will be |
9587 | reset later by breakpoint_re_set. */ | |
1900040c | 9588 | case bp_overlay_event: |
0fd8e87f | 9589 | case bp_longjmp_master: |
aa7d318d | 9590 | case bp_std_terminate_master: |
c906108c SS |
9591 | delete_breakpoint (b); |
9592 | break; | |
9593 | ||
c5aa993b JM |
9594 | /* This breakpoint is special, it's set up when the inferior |
9595 | starts and we really don't want to touch it. */ | |
c906108c SS |
9596 | case bp_shlib_event: |
9597 | ||
c4093a6a JM |
9598 | /* Like bp_shlib_event, this breakpoint type is special. |
9599 | Once it is set up, we do not want to touch it. */ | |
9600 | case bp_thread_event: | |
9601 | ||
c5aa993b JM |
9602 | /* Keep temporary breakpoints, which can be encountered when we step |
9603 | over a dlopen call and SOLIB_ADD is resetting the breakpoints. | |
9604 | Otherwise these should have been blown away via the cleanup chain | |
9605 | or by breakpoint_init_inferior when we rerun the executable. */ | |
c906108c SS |
9606 | case bp_until: |
9607 | case bp_finish: | |
9608 | case bp_watchpoint_scope: | |
9609 | case bp_call_dummy: | |
aa7d318d | 9610 | case bp_std_terminate: |
c906108c | 9611 | case bp_step_resume: |
611c83ae PA |
9612 | case bp_longjmp: |
9613 | case bp_longjmp_resume: | |
4efc6507 | 9614 | case bp_jit_event: |
c906108c SS |
9615 | break; |
9616 | } | |
9617 | ||
6c95b8df | 9618 | do_cleanups (cleanups); |
c906108c SS |
9619 | return 0; |
9620 | } | |
9621 | ||
69de3c6a | 9622 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 9623 | void |
69de3c6a | 9624 | breakpoint_re_set (void) |
c906108c SS |
9625 | { |
9626 | struct breakpoint *b, *temp; | |
9627 | enum language save_language; | |
9628 | int save_input_radix; | |
6c95b8df | 9629 | struct cleanup *old_chain; |
c5aa993b | 9630 | |
c906108c SS |
9631 | save_language = current_language->la_language; |
9632 | save_input_radix = input_radix; | |
6c95b8df PA |
9633 | old_chain = save_current_program_space (); |
9634 | ||
c906108c | 9635 | ALL_BREAKPOINTS_SAFE (b, temp) |
c5aa993b | 9636 | { |
53a5351d | 9637 | /* Format possible error msg */ |
fe3f5fa8 | 9638 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
9639 | b->number); |
9640 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 9641 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 9642 | do_cleanups (cleanups); |
c5aa993b | 9643 | } |
c906108c SS |
9644 | set_language (save_language); |
9645 | input_radix = save_input_radix; | |
e62c965a | 9646 | |
0756c555 | 9647 | jit_breakpoint_re_set (); |
4efc6507 | 9648 | |
6c95b8df PA |
9649 | do_cleanups (old_chain); |
9650 | ||
69de3c6a | 9651 | create_overlay_event_breakpoint ("_ovly_debug_event"); |
0fd8e87f UW |
9652 | create_longjmp_master_breakpoint ("longjmp"); |
9653 | create_longjmp_master_breakpoint ("_longjmp"); | |
9654 | create_longjmp_master_breakpoint ("siglongjmp"); | |
9655 | create_longjmp_master_breakpoint ("_siglongjmp"); | |
aa7d318d | 9656 | create_std_terminate_master_breakpoint ("std::terminate()"); |
c906108c SS |
9657 | } |
9658 | \f | |
c906108c SS |
9659 | /* Reset the thread number of this breakpoint: |
9660 | ||
9661 | - If the breakpoint is for all threads, leave it as-is. | |
39f77062 | 9662 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 9663 | void |
fba45db2 | 9664 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
9665 | { |
9666 | if (b->thread != -1) | |
9667 | { | |
39f77062 KB |
9668 | if (in_thread_list (inferior_ptid)) |
9669 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
9670 | |
9671 | /* We're being called after following a fork. The new fork is | |
9672 | selected as current, and unless this was a vfork will have a | |
9673 | different program space from the original thread. Reset that | |
9674 | as well. */ | |
9675 | b->loc->pspace = current_program_space; | |
c906108c SS |
9676 | } |
9677 | } | |
9678 | ||
03ac34d5 MS |
9679 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
9680 | If from_tty is nonzero, it prints a message to that effect, | |
9681 | which ends with a period (no newline). */ | |
9682 | ||
c906108c | 9683 | void |
fba45db2 | 9684 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 9685 | { |
52f0bd74 | 9686 | struct breakpoint *b; |
c906108c SS |
9687 | |
9688 | if (count < 0) | |
9689 | count = 0; | |
9690 | ||
9691 | ALL_BREAKPOINTS (b) | |
9692 | if (b->number == bptnum) | |
c5aa993b JM |
9693 | { |
9694 | b->ignore_count = count; | |
221ea385 KS |
9695 | if (from_tty) |
9696 | { | |
9697 | if (count == 0) | |
a3f17187 | 9698 | printf_filtered (_("Will stop next time breakpoint %d is reached."), |
221ea385 KS |
9699 | bptnum); |
9700 | else if (count == 1) | |
a3f17187 | 9701 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
9702 | bptnum); |
9703 | else | |
a3f17187 | 9704 | printf_filtered (_("Will ignore next %d crossings of breakpoint %d."), |
221ea385 KS |
9705 | count, bptnum); |
9706 | } | |
c5aa993b | 9707 | breakpoints_changed (); |
383f836e | 9708 | observer_notify_breakpoint_modified (b->number); |
c5aa993b JM |
9709 | return; |
9710 | } | |
c906108c | 9711 | |
8a3fe4f8 | 9712 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
9713 | } |
9714 | ||
b2175913 MS |
9715 | void |
9716 | make_breakpoint_silent (struct breakpoint *b) | |
9717 | { | |
9718 | /* Silence the breakpoint. */ | |
9719 | b->silent = 1; | |
9720 | } | |
9721 | ||
c906108c SS |
9722 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
9723 | ||
9724 | static void | |
fba45db2 | 9725 | ignore_command (char *args, int from_tty) |
c906108c SS |
9726 | { |
9727 | char *p = args; | |
52f0bd74 | 9728 | int num; |
c906108c SS |
9729 | |
9730 | if (p == 0) | |
e2e0b3e5 | 9731 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 9732 | |
c906108c | 9733 | num = get_number (&p); |
5c44784c | 9734 | if (num == 0) |
8a3fe4f8 | 9735 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 9736 | if (*p == 0) |
8a3fe4f8 | 9737 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
9738 | |
9739 | set_ignore_count (num, | |
9740 | longest_to_int (value_as_long (parse_and_eval (p))), | |
9741 | from_tty); | |
221ea385 KS |
9742 | if (from_tty) |
9743 | printf_filtered ("\n"); | |
c906108c SS |
9744 | } |
9745 | \f | |
9746 | /* Call FUNCTION on each of the breakpoints | |
9747 | whose numbers are given in ARGS. */ | |
9748 | ||
9749 | static void | |
95a42b64 TT |
9750 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
9751 | void *), | |
9752 | void *data) | |
c906108c | 9753 | { |
52f0bd74 | 9754 | char *p = args; |
c906108c | 9755 | char *p1; |
52f0bd74 AC |
9756 | int num; |
9757 | struct breakpoint *b, *tmp; | |
11cf8741 | 9758 | int match; |
c906108c SS |
9759 | |
9760 | if (p == 0) | |
e2e0b3e5 | 9761 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c SS |
9762 | |
9763 | while (*p) | |
9764 | { | |
11cf8741 | 9765 | match = 0; |
c906108c | 9766 | p1 = p; |
c5aa993b | 9767 | |
5c44784c JM |
9768 | num = get_number_or_range (&p1); |
9769 | if (num == 0) | |
c5aa993b | 9770 | { |
8a3fe4f8 | 9771 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
9772 | } |
9773 | else | |
9774 | { | |
9775 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
9776 | if (b->number == num) | |
9777 | { | |
9778 | struct breakpoint *related_breakpoint = b->related_breakpoint; | |
11cf8741 | 9779 | match = 1; |
95a42b64 | 9780 | function (b, data); |
5c44784c | 9781 | if (related_breakpoint) |
95a42b64 | 9782 | function (related_breakpoint, data); |
11cf8741 | 9783 | break; |
5c44784c | 9784 | } |
11cf8741 | 9785 | if (match == 0) |
a3f17187 | 9786 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 9787 | } |
c906108c SS |
9788 | p = p1; |
9789 | } | |
9790 | } | |
9791 | ||
0d381245 VP |
9792 | static struct bp_location * |
9793 | find_location_by_number (char *number) | |
9794 | { | |
9795 | char *dot = strchr (number, '.'); | |
9796 | char *p1; | |
9797 | int bp_num; | |
9798 | int loc_num; | |
9799 | struct breakpoint *b; | |
9800 | struct bp_location *loc; | |
9801 | ||
9802 | *dot = '\0'; | |
9803 | ||
9804 | p1 = number; | |
9805 | bp_num = get_number_or_range (&p1); | |
9806 | if (bp_num == 0) | |
9807 | error (_("Bad breakpoint number '%s'"), number); | |
9808 | ||
9809 | ALL_BREAKPOINTS (b) | |
9810 | if (b->number == bp_num) | |
9811 | { | |
9812 | break; | |
9813 | } | |
9814 | ||
9815 | if (!b || b->number != bp_num) | |
9816 | error (_("Bad breakpoint number '%s'"), number); | |
9817 | ||
9818 | p1 = dot+1; | |
9819 | loc_num = get_number_or_range (&p1); | |
9820 | if (loc_num == 0) | |
9821 | error (_("Bad breakpoint location number '%s'"), number); | |
9822 | ||
9823 | --loc_num; | |
9824 | loc = b->loc; | |
9825 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
9826 | ; | |
9827 | if (!loc) | |
9828 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
9829 | ||
9830 | return loc; | |
9831 | } | |
9832 | ||
9833 | ||
1900040c MS |
9834 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
9835 | If from_tty is nonzero, it prints a message to that effect, | |
9836 | which ends with a period (no newline). */ | |
9837 | ||
c906108c | 9838 | void |
fba45db2 | 9839 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
9840 | { |
9841 | /* Never disable a watchpoint scope breakpoint; we want to | |
9842 | hit them when we leave scope so we can delete both the | |
9843 | watchpoint and its scope breakpoint at that time. */ | |
9844 | if (bpt->type == bp_watchpoint_scope) | |
9845 | return; | |
9846 | ||
c2c6d25f | 9847 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 9848 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
9849 | return; |
9850 | ||
b5de0fa7 | 9851 | bpt->enable_state = bp_disabled; |
c906108c | 9852 | |
b60e7edf | 9853 | update_global_location_list (0); |
c906108c | 9854 | |
383f836e | 9855 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
9856 | } |
9857 | ||
95a42b64 TT |
9858 | /* A callback for map_breakpoint_numbers that calls |
9859 | disable_breakpoint. */ | |
9860 | ||
9861 | static void | |
9862 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
9863 | { | |
9864 | disable_breakpoint (b); | |
9865 | } | |
9866 | ||
c906108c | 9867 | static void |
fba45db2 | 9868 | disable_command (char *args, int from_tty) |
c906108c | 9869 | { |
52f0bd74 | 9870 | struct breakpoint *bpt; |
c906108c SS |
9871 | if (args == 0) |
9872 | ALL_BREAKPOINTS (bpt) | |
9873 | switch (bpt->type) | |
c5aa993b JM |
9874 | { |
9875 | case bp_none: | |
8a3fe4f8 | 9876 | warning (_("attempted to disable apparently deleted breakpoint #%d?"), |
53a5351d | 9877 | bpt->number); |
c5aa993b JM |
9878 | continue; |
9879 | case bp_breakpoint: | |
1042e4c0 | 9880 | case bp_tracepoint: |
7a697b8d | 9881 | case bp_fast_tracepoint: |
ce78b96d | 9882 | case bp_catchpoint: |
c5aa993b JM |
9883 | case bp_hardware_breakpoint: |
9884 | case bp_watchpoint: | |
9885 | case bp_hardware_watchpoint: | |
9886 | case bp_read_watchpoint: | |
9887 | case bp_access_watchpoint: | |
9888 | disable_breakpoint (bpt); | |
9889 | default: | |
9890 | continue; | |
9891 | } | |
0d381245 VP |
9892 | else if (strchr (args, '.')) |
9893 | { | |
9894 | struct bp_location *loc = find_location_by_number (args); | |
9895 | if (loc) | |
9896 | loc->enabled = 0; | |
b60e7edf | 9897 | update_global_location_list (0); |
0d381245 | 9898 | } |
c906108c | 9899 | else |
95a42b64 | 9900 | map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL); |
c906108c SS |
9901 | } |
9902 | ||
9903 | static void | |
fba45db2 | 9904 | do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition) |
c906108c | 9905 | { |
c906108c SS |
9906 | int target_resources_ok, other_type_used; |
9907 | struct value *mark; | |
9908 | ||
9909 | if (bpt->type == bp_hardware_breakpoint) | |
9910 | { | |
9911 | int i; | |
c5aa993b | 9912 | i = hw_breakpoint_used_count (); |
53a5351d | 9913 | target_resources_ok = |
d92524f1 | 9914 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 9915 | i + 1, 0); |
c906108c | 9916 | if (target_resources_ok == 0) |
8a3fe4f8 | 9917 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 9918 | else if (target_resources_ok < 0) |
8a3fe4f8 | 9919 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
9920 | } |
9921 | ||
059fb39f PM |
9922 | if (bpt->type == bp_watchpoint |
9923 | || bpt->type == bp_hardware_watchpoint | |
9924 | || bpt->type == bp_read_watchpoint | |
9925 | || bpt->type == bp_access_watchpoint) | |
c906108c | 9926 | { |
dde02812 ES |
9927 | struct gdb_exception e; |
9928 | ||
9929 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 9930 | { |
dde02812 | 9931 | update_watchpoint (bpt, 1 /* reparse */); |
c906108c | 9932 | } |
dde02812 | 9933 | if (e.reason < 0) |
c5aa993b | 9934 | { |
dde02812 ES |
9935 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
9936 | bpt->number); | |
9937 | return; | |
c5aa993b | 9938 | } |
c906108c | 9939 | } |
0101ce28 | 9940 | |
b4c291bb KH |
9941 | if (bpt->enable_state != bp_permanent) |
9942 | bpt->enable_state = bp_enabled; | |
9943 | bpt->disposition = disposition; | |
b60e7edf | 9944 | update_global_location_list (1); |
b4c291bb KH |
9945 | breakpoints_changed (); |
9946 | ||
383f836e | 9947 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
9948 | } |
9949 | ||
fe3f5fa8 | 9950 | |
c906108c | 9951 | void |
fba45db2 | 9952 | enable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
9953 | { |
9954 | do_enable_breakpoint (bpt, bpt->disposition); | |
9955 | } | |
9956 | ||
95a42b64 TT |
9957 | /* A callback for map_breakpoint_numbers that calls |
9958 | enable_breakpoint. */ | |
9959 | ||
9960 | static void | |
9961 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
9962 | { | |
9963 | enable_breakpoint (b); | |
9964 | } | |
9965 | ||
c906108c SS |
9966 | /* The enable command enables the specified breakpoints (or all defined |
9967 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 9968 | in stopping the inferior. */ |
c906108c | 9969 | |
c906108c | 9970 | static void |
fba45db2 | 9971 | enable_command (char *args, int from_tty) |
c906108c | 9972 | { |
52f0bd74 | 9973 | struct breakpoint *bpt; |
c906108c SS |
9974 | if (args == 0) |
9975 | ALL_BREAKPOINTS (bpt) | |
9976 | switch (bpt->type) | |
c5aa993b JM |
9977 | { |
9978 | case bp_none: | |
8a3fe4f8 | 9979 | warning (_("attempted to enable apparently deleted breakpoint #%d?"), |
53a5351d | 9980 | bpt->number); |
c5aa993b JM |
9981 | continue; |
9982 | case bp_breakpoint: | |
1042e4c0 | 9983 | case bp_tracepoint: |
7a697b8d | 9984 | case bp_fast_tracepoint: |
ce78b96d | 9985 | case bp_catchpoint: |
c5aa993b JM |
9986 | case bp_hardware_breakpoint: |
9987 | case bp_watchpoint: | |
9988 | case bp_hardware_watchpoint: | |
9989 | case bp_read_watchpoint: | |
9990 | case bp_access_watchpoint: | |
9991 | enable_breakpoint (bpt); | |
9992 | default: | |
9993 | continue; | |
9994 | } | |
0d381245 VP |
9995 | else if (strchr (args, '.')) |
9996 | { | |
9997 | struct bp_location *loc = find_location_by_number (args); | |
9998 | if (loc) | |
9999 | loc->enabled = 1; | |
b60e7edf | 10000 | update_global_location_list (1); |
0d381245 | 10001 | } |
c906108c | 10002 | else |
95a42b64 | 10003 | map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL); |
c906108c SS |
10004 | } |
10005 | ||
10006 | static void | |
95a42b64 | 10007 | enable_once_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 10008 | { |
b5de0fa7 | 10009 | do_enable_breakpoint (bpt, disp_disable); |
c906108c SS |
10010 | } |
10011 | ||
c906108c | 10012 | static void |
fba45db2 | 10013 | enable_once_command (char *args, int from_tty) |
c906108c | 10014 | { |
95a42b64 | 10015 | map_breakpoint_numbers (args, enable_once_breakpoint, NULL); |
c906108c SS |
10016 | } |
10017 | ||
10018 | static void | |
95a42b64 | 10019 | enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 10020 | { |
b5de0fa7 | 10021 | do_enable_breakpoint (bpt, disp_del); |
c906108c SS |
10022 | } |
10023 | ||
c906108c | 10024 | static void |
fba45db2 | 10025 | enable_delete_command (char *args, int from_tty) |
c906108c | 10026 | { |
95a42b64 | 10027 | map_breakpoint_numbers (args, enable_delete_breakpoint, NULL); |
c906108c SS |
10028 | } |
10029 | \f | |
fa8d40ab JJ |
10030 | static void |
10031 | set_breakpoint_cmd (char *args, int from_tty) | |
10032 | { | |
10033 | } | |
10034 | ||
10035 | static void | |
10036 | show_breakpoint_cmd (char *args, int from_tty) | |
10037 | { | |
10038 | } | |
10039 | ||
1f3b5d1b PP |
10040 | /* Invalidate last known value of any hardware watchpoint if |
10041 | the memory which that value represents has been written to by | |
10042 | GDB itself. */ | |
10043 | ||
10044 | static void | |
10045 | invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len, | |
10046 | const bfd_byte *data) | |
10047 | { | |
10048 | struct breakpoint *bp; | |
10049 | ||
10050 | ALL_BREAKPOINTS (bp) | |
10051 | if (bp->enable_state == bp_enabled | |
10052 | && bp->type == bp_hardware_watchpoint | |
10053 | && bp->val_valid && bp->val) | |
10054 | { | |
10055 | struct bp_location *loc; | |
10056 | ||
10057 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
10058 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
10059 | && loc->address + loc->length > addr | |
10060 | && addr + len > loc->address) | |
10061 | { | |
10062 | value_free (bp->val); | |
10063 | bp->val = NULL; | |
10064 | bp->val_valid = 0; | |
10065 | } | |
10066 | } | |
10067 | } | |
10068 | ||
c906108c SS |
10069 | /* Use default_breakpoint_'s, or nothing if they aren't valid. */ |
10070 | ||
10071 | struct symtabs_and_lines | |
fba45db2 | 10072 | decode_line_spec_1 (char *string, int funfirstline) |
c906108c SS |
10073 | { |
10074 | struct symtabs_and_lines sals; | |
10075 | if (string == 0) | |
8a3fe4f8 | 10076 | error (_("Empty line specification.")); |
c906108c SS |
10077 | if (default_breakpoint_valid) |
10078 | sals = decode_line_1 (&string, funfirstline, | |
53a5351d JM |
10079 | default_breakpoint_symtab, |
10080 | default_breakpoint_line, | |
68219205 | 10081 | (char ***) NULL, NULL); |
c906108c SS |
10082 | else |
10083 | sals = decode_line_1 (&string, funfirstline, | |
68219205 | 10084 | (struct symtab *) NULL, 0, (char ***) NULL, NULL); |
c906108c | 10085 | if (*string) |
8a3fe4f8 | 10086 | error (_("Junk at end of line specification: %s"), string); |
c906108c SS |
10087 | return sals; |
10088 | } | |
8181d85f DJ |
10089 | |
10090 | /* Create and insert a raw software breakpoint at PC. Return an | |
10091 | identifier, which should be used to remove the breakpoint later. | |
10092 | In general, places which call this should be using something on the | |
10093 | breakpoint chain instead; this function should be eliminated | |
10094 | someday. */ | |
10095 | ||
10096 | void * | |
6c95b8df PA |
10097 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, |
10098 | struct address_space *aspace, CORE_ADDR pc) | |
8181d85f DJ |
10099 | { |
10100 | struct bp_target_info *bp_tgt; | |
10101 | ||
6c95b8df | 10102 | bp_tgt = XZALLOC (struct bp_target_info); |
8181d85f | 10103 | |
6c95b8df | 10104 | bp_tgt->placed_address_space = aspace; |
8181d85f | 10105 | bp_tgt->placed_address = pc; |
6c95b8df | 10106 | |
a6d9a66e | 10107 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
8181d85f DJ |
10108 | { |
10109 | /* Could not insert the breakpoint. */ | |
10110 | xfree (bp_tgt); | |
10111 | return NULL; | |
10112 | } | |
10113 | ||
10114 | return bp_tgt; | |
10115 | } | |
10116 | ||
10117 | /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */ | |
10118 | ||
10119 | int | |
a6d9a66e | 10120 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
8181d85f DJ |
10121 | { |
10122 | struct bp_target_info *bp_tgt = bp; | |
10123 | int ret; | |
10124 | ||
a6d9a66e | 10125 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
8181d85f DJ |
10126 | xfree (bp_tgt); |
10127 | ||
10128 | return ret; | |
10129 | } | |
10130 | ||
10131 | /* One (or perhaps two) breakpoints used for software single stepping. */ | |
10132 | ||
10133 | static void *single_step_breakpoints[2]; | |
a6d9a66e | 10134 | static struct gdbarch *single_step_gdbarch[2]; |
8181d85f DJ |
10135 | |
10136 | /* Create and insert a breakpoint for software single step. */ | |
10137 | ||
10138 | void | |
6c95b8df PA |
10139 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
10140 | struct address_space *aspace, CORE_ADDR next_pc) | |
8181d85f DJ |
10141 | { |
10142 | void **bpt_p; | |
10143 | ||
10144 | if (single_step_breakpoints[0] == NULL) | |
a6d9a66e UW |
10145 | { |
10146 | bpt_p = &single_step_breakpoints[0]; | |
10147 | single_step_gdbarch[0] = gdbarch; | |
10148 | } | |
8181d85f DJ |
10149 | else |
10150 | { | |
10151 | gdb_assert (single_step_breakpoints[1] == NULL); | |
10152 | bpt_p = &single_step_breakpoints[1]; | |
a6d9a66e | 10153 | single_step_gdbarch[1] = gdbarch; |
8181d85f DJ |
10154 | } |
10155 | ||
10156 | /* NOTE drow/2006-04-11: A future improvement to this function would be | |
10157 | to only create the breakpoints once, and actually put them on the | |
10158 | breakpoint chain. That would let us use set_raw_breakpoint. We could | |
10159 | adjust the addresses each time they were needed. Doing this requires | |
10160 | corresponding changes elsewhere where single step breakpoints are | |
10161 | handled, however. So, for now, we use this. */ | |
10162 | ||
6c95b8df | 10163 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc); |
8181d85f | 10164 | if (*bpt_p == NULL) |
5af949e3 UW |
10165 | error (_("Could not insert single-step breakpoint at %s"), |
10166 | paddress (gdbarch, next_pc)); | |
8181d85f DJ |
10167 | } |
10168 | ||
10169 | /* Remove and delete any breakpoints used for software single step. */ | |
10170 | ||
10171 | void | |
10172 | remove_single_step_breakpoints (void) | |
10173 | { | |
10174 | gdb_assert (single_step_breakpoints[0] != NULL); | |
10175 | ||
10176 | /* See insert_single_step_breakpoint for more about this deprecated | |
10177 | call. */ | |
a6d9a66e UW |
10178 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
10179 | single_step_breakpoints[0]); | |
10180 | single_step_gdbarch[0] = NULL; | |
8181d85f DJ |
10181 | single_step_breakpoints[0] = NULL; |
10182 | ||
10183 | if (single_step_breakpoints[1] != NULL) | |
10184 | { | |
a6d9a66e UW |
10185 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
10186 | single_step_breakpoints[1]); | |
10187 | single_step_gdbarch[1] = NULL; | |
8181d85f DJ |
10188 | single_step_breakpoints[1] = NULL; |
10189 | } | |
10190 | } | |
10191 | ||
1aafd4da UW |
10192 | /* Check whether a software single-step breakpoint is inserted at PC. */ |
10193 | ||
10194 | static int | |
6c95b8df | 10195 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
1aafd4da UW |
10196 | { |
10197 | int i; | |
10198 | ||
10199 | for (i = 0; i < 2; i++) | |
10200 | { | |
10201 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
6c95b8df PA |
10202 | if (bp_tgt |
10203 | && breakpoint_address_match (bp_tgt->placed_address_space, | |
10204 | bp_tgt->placed_address, | |
10205 | aspace, pc)) | |
1aafd4da UW |
10206 | return 1; |
10207 | } | |
10208 | ||
10209 | return 0; | |
10210 | } | |
10211 | ||
a96d9b2e SDJ |
10212 | /* Returns 0 if 'bp' is NOT a syscall catchpoint, |
10213 | non-zero otherwise. */ | |
10214 | static int | |
10215 | is_syscall_catchpoint_enabled (struct breakpoint *bp) | |
10216 | { | |
10217 | if (syscall_catchpoint_p (bp) | |
10218 | && bp->enable_state != bp_disabled | |
10219 | && bp->enable_state != bp_call_disabled) | |
10220 | return 1; | |
10221 | else | |
10222 | return 0; | |
10223 | } | |
10224 | ||
10225 | int | |
10226 | catch_syscall_enabled (void) | |
10227 | { | |
10228 | struct inferior *inf = current_inferior (); | |
10229 | ||
10230 | return inf->total_syscalls_count != 0; | |
10231 | } | |
10232 | ||
10233 | int | |
10234 | catching_syscall_number (int syscall_number) | |
10235 | { | |
10236 | struct breakpoint *bp; | |
10237 | ||
10238 | ALL_BREAKPOINTS (bp) | |
10239 | if (is_syscall_catchpoint_enabled (bp)) | |
10240 | { | |
10241 | if (bp->syscalls_to_be_caught) | |
10242 | { | |
10243 | int i, iter; | |
10244 | for (i = 0; | |
10245 | VEC_iterate (int, bp->syscalls_to_be_caught, i, iter); | |
10246 | i++) | |
10247 | if (syscall_number == iter) | |
10248 | return 1; | |
10249 | } | |
10250 | else | |
10251 | return 1; | |
10252 | } | |
10253 | ||
10254 | return 0; | |
10255 | } | |
10256 | ||
10257 | /* Complete syscall names. Used by "catch syscall". */ | |
10258 | static char ** | |
10259 | catch_syscall_completer (struct cmd_list_element *cmd, | |
10260 | char *text, char *word) | |
10261 | { | |
10262 | const char **list = get_syscall_names (); | |
10263 | return (list == NULL) ? NULL : complete_on_enum (list, text, word); | |
10264 | } | |
10265 | ||
1042e4c0 SS |
10266 | /* Tracepoint-specific operations. */ |
10267 | ||
10268 | /* Set tracepoint count to NUM. */ | |
10269 | static void | |
10270 | set_tracepoint_count (int num) | |
10271 | { | |
10272 | tracepoint_count = num; | |
4fa62494 | 10273 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
10274 | } |
10275 | ||
10276 | void | |
10277 | trace_command (char *arg, int from_tty) | |
10278 | { | |
8cdf0e15 VP |
10279 | if (create_breakpoint (get_current_arch (), |
10280 | arg, | |
10281 | NULL, 0, 1 /* parse arg */, | |
10282 | 0 /* tempflag */, 0 /* hardwareflag */, | |
10283 | 1 /* traceflag */, | |
10284 | 0 /* Ignore count */, | |
10285 | pending_break_support, | |
10286 | NULL, | |
10287 | from_tty, | |
10288 | 1 /* enabled */)) | |
fd9b8c24 | 10289 | set_tracepoint_count (breakpoint_count); |
1042e4c0 SS |
10290 | } |
10291 | ||
7a697b8d SS |
10292 | void |
10293 | ftrace_command (char *arg, int from_tty) | |
10294 | { | |
8cdf0e15 VP |
10295 | if (create_breakpoint (get_current_arch (), |
10296 | arg, | |
10297 | NULL, 0, 1 /* parse arg */, | |
10298 | 0 /* tempflag */, 1 /* hardwareflag */, | |
10299 | 1 /* traceflag */, | |
10300 | 0 /* Ignore count */, | |
10301 | pending_break_support, | |
10302 | NULL, | |
10303 | from_tty, | |
10304 | 1 /* enabled */)) | |
fd9b8c24 | 10305 | set_tracepoint_count (breakpoint_count); |
7a697b8d SS |
10306 | } |
10307 | ||
409873ef SS |
10308 | /* Set up a fake reader function that gets command lines from a linked |
10309 | list that was acquired during tracepoint uploading. */ | |
10310 | ||
10311 | static struct uploaded_tp *this_utp; | |
10312 | static struct uploaded_string *next_cmd; | |
10313 | ||
10314 | static char * | |
10315 | read_uploaded_action (void) | |
10316 | { | |
10317 | char *rslt; | |
10318 | ||
10319 | if (!next_cmd) | |
10320 | return NULL; | |
10321 | ||
10322 | rslt = next_cmd->str; | |
10323 | next_cmd = next_cmd->next; | |
10324 | ||
10325 | return rslt; | |
10326 | } | |
10327 | ||
00bf0b85 SS |
10328 | /* Given information about a tracepoint as recorded on a target (which |
10329 | can be either a live system or a trace file), attempt to create an | |
10330 | equivalent GDB tracepoint. This is not a reliable process, since | |
10331 | the target does not necessarily have all the information used when | |
10332 | the tracepoint was originally defined. */ | |
10333 | ||
10334 | struct breakpoint * | |
10335 | create_tracepoint_from_upload (struct uploaded_tp *utp) | |
d5551862 | 10336 | { |
409873ef | 10337 | char *addr_str, small_buf[100]; |
d5551862 | 10338 | struct breakpoint *tp; |
fd9b8c24 | 10339 | |
409873ef SS |
10340 | if (utp->at_string) |
10341 | addr_str = utp->at_string; | |
10342 | else | |
10343 | { | |
10344 | /* In the absence of a source location, fall back to raw | |
10345 | address. Since there is no way to confirm that the address | |
10346 | means the same thing as when the trace was started, warn the | |
10347 | user. */ | |
10348 | warning (_("Uploaded tracepoint %d has no source location, using raw address"), | |
10349 | utp->number); | |
10350 | sprintf (small_buf, "*%s", hex_string (utp->addr)); | |
10351 | addr_str = small_buf; | |
10352 | } | |
10353 | ||
10354 | /* There's not much we can do with a sequence of bytecodes. */ | |
10355 | if (utp->cond && !utp->cond_string) | |
10356 | warning (_("Uploaded tracepoint %d condition has no source form, ignoring it"), | |
10357 | utp->number); | |
d5551862 | 10358 | |
8cdf0e15 | 10359 | if (!create_breakpoint (get_current_arch (), |
409873ef SS |
10360 | addr_str, |
10361 | utp->cond_string, -1, 0 /* parse cond/thread */, | |
8cdf0e15 VP |
10362 | 0 /* tempflag */, |
10363 | (utp->type == bp_fast_tracepoint) /* hardwareflag */, | |
10364 | 1 /* traceflag */, | |
10365 | 0 /* Ignore count */, | |
10366 | pending_break_support, | |
10367 | NULL, | |
10368 | 0 /* from_tty */, | |
10369 | utp->enabled /* enabled */)) | |
fd9b8c24 PA |
10370 | return NULL; |
10371 | ||
00bf0b85 SS |
10372 | set_tracepoint_count (breakpoint_count); |
10373 | ||
409873ef | 10374 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
10375 | tp = get_tracepoint (tracepoint_count); |
10376 | gdb_assert (tp != NULL); | |
d5551862 | 10377 | |
00bf0b85 SS |
10378 | if (utp->pass > 0) |
10379 | { | |
409873ef | 10380 | sprintf (small_buf, "%d %d", utp->pass, tp->number); |
00bf0b85 | 10381 | |
409873ef | 10382 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
10383 | } |
10384 | ||
409873ef SS |
10385 | /* If we have uploaded versions of the original commands, set up a |
10386 | special-purpose "reader" function and call the usual command line | |
10387 | reader, then pass the result to the breakpoint command-setting | |
10388 | function. */ | |
10389 | if (utp->cmd_strings) | |
00bf0b85 | 10390 | { |
409873ef | 10391 | struct command_line *cmd_list; |
00bf0b85 | 10392 | |
409873ef SS |
10393 | this_utp = utp; |
10394 | next_cmd = utp->cmd_strings; | |
d5551862 | 10395 | |
409873ef SS |
10396 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
10397 | ||
10398 | breakpoint_set_commands (tp, cmd_list); | |
00bf0b85 | 10399 | } |
409873ef SS |
10400 | else if (utp->numactions > 0 || utp->num_step_actions > 0) |
10401 | warning (_("Uploaded tracepoint %d actions have no source form, ignoring them"), | |
10402 | utp->number); | |
00bf0b85 SS |
10403 | |
10404 | return tp; | |
10405 | } | |
10406 | ||
1042e4c0 SS |
10407 | /* Print information on tracepoint number TPNUM_EXP, or all if |
10408 | omitted. */ | |
10409 | ||
10410 | static void | |
10411 | tracepoints_info (char *tpnum_exp, int from_tty) | |
10412 | { | |
10413 | struct breakpoint *b; | |
10414 | int tps_to_list = 0; | |
10415 | ||
10416 | /* In the no-arguments case, say "No tracepoints" if none found. */ | |
10417 | if (tpnum_exp == 0) | |
10418 | { | |
10419 | ALL_TRACEPOINTS (b) | |
10420 | { | |
10421 | if (b->number >= 0) | |
10422 | { | |
10423 | tps_to_list = 1; | |
10424 | break; | |
10425 | } | |
10426 | } | |
10427 | if (!tps_to_list) | |
10428 | { | |
10429 | ui_out_message (uiout, 0, "No tracepoints.\n"); | |
10430 | return; | |
10431 | } | |
10432 | } | |
10433 | ||
10434 | /* Otherwise be the same as "info break". */ | |
10435 | breakpoints_info (tpnum_exp, from_tty); | |
10436 | } | |
10437 | ||
10438 | /* The 'enable trace' command enables tracepoints. | |
10439 | Not supported by all targets. */ | |
10440 | static void | |
10441 | enable_trace_command (char *args, int from_tty) | |
10442 | { | |
10443 | enable_command (args, from_tty); | |
10444 | } | |
10445 | ||
10446 | /* The 'disable trace' command disables tracepoints. | |
10447 | Not supported by all targets. */ | |
10448 | static void | |
10449 | disable_trace_command (char *args, int from_tty) | |
10450 | { | |
10451 | disable_command (args, from_tty); | |
10452 | } | |
10453 | ||
10454 | /* Remove a tracepoint (or all if no argument) */ | |
10455 | static void | |
10456 | delete_trace_command (char *arg, int from_tty) | |
10457 | { | |
10458 | struct breakpoint *b, *temp; | |
10459 | ||
10460 | dont_repeat (); | |
10461 | ||
10462 | if (arg == 0) | |
10463 | { | |
10464 | int breaks_to_delete = 0; | |
10465 | ||
10466 | /* Delete all breakpoints if no argument. | |
10467 | Do not delete internal or call-dummy breakpoints, these | |
10468 | have to be deleted with an explicit breakpoint number argument. */ | |
10469 | ALL_TRACEPOINTS (b) | |
10470 | { | |
10471 | if (b->number >= 0) | |
10472 | { | |
10473 | breaks_to_delete = 1; | |
10474 | break; | |
10475 | } | |
10476 | } | |
10477 | ||
10478 | /* Ask user only if there are some breakpoints to delete. */ | |
10479 | if (!from_tty | |
10480 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
10481 | { | |
10482 | ALL_BREAKPOINTS_SAFE (b, temp) | |
10483 | { | |
7a697b8d | 10484 | if (tracepoint_type (b) |
059fb39f | 10485 | && b->number >= 0) |
1042e4c0 SS |
10486 | delete_breakpoint (b); |
10487 | } | |
10488 | } | |
10489 | } | |
10490 | else | |
95a42b64 | 10491 | map_breakpoint_numbers (arg, do_delete_breakpoint, NULL); |
1042e4c0 SS |
10492 | } |
10493 | ||
10494 | /* Set passcount for tracepoint. | |
10495 | ||
10496 | First command argument is passcount, second is tracepoint number. | |
10497 | If tracepoint number omitted, apply to most recently defined. | |
10498 | Also accepts special argument "all". */ | |
10499 | ||
10500 | static void | |
10501 | trace_pass_command (char *args, int from_tty) | |
10502 | { | |
10503 | struct breakpoint *t1 = (struct breakpoint *) -1, *t2; | |
10504 | unsigned int count; | |
10505 | int all = 0; | |
10506 | ||
10507 | if (args == 0 || *args == 0) | |
10508 | error (_("passcount command requires an argument (count + optional TP num)")); | |
10509 | ||
10510 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ | |
10511 | ||
10512 | while (*args && isspace ((int) *args)) | |
10513 | args++; | |
10514 | ||
10515 | if (*args && strncasecmp (args, "all", 3) == 0) | |
10516 | { | |
10517 | args += 3; /* Skip special argument "all". */ | |
10518 | all = 1; | |
10519 | if (*args) | |
10520 | error (_("Junk at end of arguments.")); | |
10521 | } | |
10522 | else | |
10523 | t1 = get_tracepoint_by_number (&args, 1, 1); | |
10524 | ||
10525 | do | |
10526 | { | |
10527 | if (t1) | |
10528 | { | |
10529 | ALL_TRACEPOINTS (t2) | |
10530 | if (t1 == (struct breakpoint *) -1 || t1 == t2) | |
10531 | { | |
10532 | t2->pass_count = count; | |
10533 | observer_notify_tracepoint_modified (t2->number); | |
10534 | if (from_tty) | |
10535 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
10536 | t2->number, count); | |
10537 | } | |
10538 | if (! all && *args) | |
10539 | t1 = get_tracepoint_by_number (&args, 1, 0); | |
10540 | } | |
10541 | } | |
10542 | while (*args); | |
10543 | } | |
10544 | ||
10545 | struct breakpoint * | |
10546 | get_tracepoint (int num) | |
10547 | { | |
10548 | struct breakpoint *t; | |
10549 | ||
10550 | ALL_TRACEPOINTS (t) | |
10551 | if (t->number == num) | |
10552 | return t; | |
10553 | ||
10554 | return NULL; | |
10555 | } | |
10556 | ||
d5551862 SS |
10557 | /* Find the tracepoint with the given target-side number (which may be |
10558 | different from the tracepoint number after disconnecting and | |
10559 | reconnecting). */ | |
10560 | ||
10561 | struct breakpoint * | |
10562 | get_tracepoint_by_number_on_target (int num) | |
10563 | { | |
10564 | struct breakpoint *t; | |
10565 | ||
10566 | ALL_TRACEPOINTS (t) | |
10567 | if (t->number_on_target == num) | |
10568 | return t; | |
10569 | ||
10570 | return NULL; | |
10571 | } | |
10572 | ||
1042e4c0 SS |
10573 | /* Utility: parse a tracepoint number and look it up in the list. |
10574 | If MULTI_P is true, there might be a range of tracepoints in ARG. | |
10575 | if OPTIONAL_P is true, then if the argument is missing, the most | |
10576 | recent tracepoint (tracepoint_count) is returned. */ | |
10577 | struct breakpoint * | |
10578 | get_tracepoint_by_number (char **arg, int multi_p, int optional_p) | |
10579 | { | |
10580 | extern int tracepoint_count; | |
10581 | struct breakpoint *t; | |
10582 | int tpnum; | |
10583 | char *instring = arg == NULL ? NULL : *arg; | |
10584 | ||
10585 | if (arg == NULL || *arg == NULL || ! **arg) | |
10586 | { | |
10587 | if (optional_p) | |
10588 | tpnum = tracepoint_count; | |
10589 | else | |
10590 | error_no_arg (_("tracepoint number")); | |
10591 | } | |
10592 | else | |
10593 | tpnum = multi_p ? get_number_or_range (arg) : get_number (arg); | |
10594 | ||
10595 | if (tpnum <= 0) | |
10596 | { | |
10597 | if (instring && *instring) | |
10598 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
10599 | instring); | |
10600 | else | |
10601 | printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n")); | |
10602 | return NULL; | |
10603 | } | |
10604 | ||
10605 | ALL_TRACEPOINTS (t) | |
10606 | if (t->number == tpnum) | |
10607 | { | |
10608 | return t; | |
10609 | } | |
10610 | ||
10611 | /* FIXME: if we are in the middle of a range we don't want to give | |
10612 | a message. The current interface to get_number_or_range doesn't | |
10613 | allow us to discover this. */ | |
10614 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); | |
10615 | return NULL; | |
10616 | } | |
10617 | ||
10618 | /* save-tracepoints command */ | |
10619 | static void | |
10620 | tracepoint_save_command (char *args, int from_tty) | |
10621 | { | |
10622 | struct breakpoint *tp; | |
10623 | int any_tp = 0; | |
a7bdde9e VP |
10624 | struct command_line *line; |
10625 | char *pathname; | |
1042e4c0 SS |
10626 | char tmp[40]; |
10627 | struct cleanup *cleanup; | |
a7bdde9e | 10628 | struct ui_file *fp; |
1042e4c0 SS |
10629 | |
10630 | if (args == 0 || *args == 0) | |
10631 | error (_("Argument required (file name in which to save tracepoints)")); | |
10632 | ||
10633 | /* See if we have anything to save. */ | |
10634 | ALL_TRACEPOINTS (tp) | |
10635 | { | |
10636 | any_tp = 1; | |
10637 | break; | |
10638 | } | |
10639 | if (!any_tp) | |
10640 | { | |
10641 | warning (_("save-tracepoints: no tracepoints to save.")); | |
10642 | return; | |
10643 | } | |
10644 | ||
10645 | pathname = tilde_expand (args); | |
10646 | cleanup = make_cleanup (xfree, pathname); | |
a7bdde9e | 10647 | fp = gdb_fopen (pathname, "w"); |
059fb39f | 10648 | if (!fp) |
1042e4c0 SS |
10649 | error (_("Unable to open file '%s' for saving tracepoints (%s)"), |
10650 | args, safe_strerror (errno)); | |
a7bdde9e | 10651 | make_cleanup_ui_file_delete (fp); |
8bf6485c SS |
10652 | |
10653 | save_trace_state_variables (fp); | |
10654 | ||
1042e4c0 SS |
10655 | ALL_TRACEPOINTS (tp) |
10656 | { | |
8bf6485c SS |
10657 | if (tp->type == bp_fast_tracepoint) |
10658 | fprintf_unfiltered (fp, "ftrace"); | |
10659 | else | |
10660 | fprintf_unfiltered (fp, "trace"); | |
10661 | ||
1042e4c0 | 10662 | if (tp->addr_string) |
8bf6485c | 10663 | fprintf_unfiltered (fp, " %s", tp->addr_string); |
1042e4c0 SS |
10664 | else |
10665 | { | |
10666 | sprintf_vma (tmp, tp->loc->address); | |
8bf6485c | 10667 | fprintf_unfiltered (fp, " *0x%s", tmp); |
1042e4c0 SS |
10668 | } |
10669 | ||
8bf6485c SS |
10670 | if (tp->cond_string) |
10671 | fprintf_unfiltered (fp, " if %s", tp->cond_string); | |
10672 | ||
10673 | fprintf_unfiltered (fp, "\n"); | |
10674 | ||
1042e4c0 | 10675 | if (tp->pass_count) |
a7bdde9e | 10676 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); |
1042e4c0 | 10677 | |
a7bdde9e | 10678 | if (tp->commands) |
1042e4c0 | 10679 | { |
a7bdde9e VP |
10680 | volatile struct gdb_exception ex; |
10681 | ||
10682 | fprintf_unfiltered (fp, " actions\n"); | |
10683 | ||
10684 | ui_out_redirect (uiout, fp); | |
10685 | TRY_CATCH (ex, RETURN_MASK_ERROR) | |
1042e4c0 | 10686 | { |
9add0f1b | 10687 | print_command_lines (uiout, tp->commands->commands, 2); |
a7bdde9e VP |
10688 | } |
10689 | ui_out_redirect (uiout, NULL); | |
1042e4c0 | 10690 | |
a7bdde9e VP |
10691 | if (ex.reason < 0) |
10692 | throw_exception (ex); | |
1042e4c0 | 10693 | |
a7bdde9e | 10694 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 SS |
10695 | } |
10696 | } | |
8bf6485c SS |
10697 | |
10698 | if (*default_collect) | |
10699 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); | |
10700 | ||
1042e4c0 SS |
10701 | do_cleanups (cleanup); |
10702 | if (from_tty) | |
10703 | printf_filtered (_("Tracepoints saved to file '%s'.\n"), args); | |
10704 | return; | |
10705 | } | |
10706 | ||
10707 | /* Create a vector of all tracepoints. */ | |
10708 | ||
10709 | VEC(breakpoint_p) * | |
10710 | all_tracepoints () | |
10711 | { | |
10712 | VEC(breakpoint_p) *tp_vec = 0; | |
10713 | struct breakpoint *tp; | |
10714 | ||
10715 | ALL_TRACEPOINTS (tp) | |
10716 | { | |
10717 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
10718 | } | |
10719 | ||
10720 | return tp_vec; | |
10721 | } | |
10722 | ||
c906108c | 10723 | \f |
31e2b00f AS |
10724 | /* This help string is used for the break, hbreak, tbreak and thbreak commands. |
10725 | It is defined as a macro to prevent duplication. | |
10726 | COMMAND should be a string constant containing the name of the command. */ | |
10727 | #define BREAK_ARGS_HELP(command) \ | |
10728 | command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\ | |
10729 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ | |
10730 | If a line number is specified, break at start of code for that line.\n\ | |
10731 | If a function is specified, break at start of code for that function.\n\ | |
10732 | If an address is specified, break at that exact address.\n\ | |
10733 | With no LOCATION, uses current execution address of selected stack frame.\n\ | |
10734 | This is useful for breaking on return to a stack frame.\n\ | |
10735 | \n\ | |
10736 | THREADNUM is the number from \"info threads\".\n\ | |
10737 | CONDITION is a boolean expression.\n\ | |
10738 | \n\ | |
10739 | Multiple breakpoints at one place are permitted, and useful if conditional.\n\ | |
10740 | \n\ | |
10741 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
10742 | ||
44feb3ce TT |
10743 | /* List of subcommands for "catch". */ |
10744 | static struct cmd_list_element *catch_cmdlist; | |
10745 | ||
10746 | /* List of subcommands for "tcatch". */ | |
10747 | static struct cmd_list_element *tcatch_cmdlist; | |
10748 | ||
10749 | /* Like add_cmd, but add the command to both the "catch" and "tcatch" | |
10750 | lists, and pass some additional user data to the command function. */ | |
10751 | static void | |
10752 | add_catch_command (char *name, char *docstring, | |
10753 | void (*sfunc) (char *args, int from_tty, | |
10754 | struct cmd_list_element *command), | |
a96d9b2e SDJ |
10755 | char **(*completer) (struct cmd_list_element *cmd, |
10756 | char *text, char *word), | |
44feb3ce TT |
10757 | void *user_data_catch, |
10758 | void *user_data_tcatch) | |
10759 | { | |
10760 | struct cmd_list_element *command; | |
10761 | ||
10762 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
10763 | &catch_cmdlist); | |
10764 | set_cmd_sfunc (command, sfunc); | |
10765 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 10766 | set_cmd_completer (command, completer); |
44feb3ce TT |
10767 | |
10768 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
10769 | &tcatch_cmdlist); | |
10770 | set_cmd_sfunc (command, sfunc); | |
10771 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 10772 | set_cmd_completer (command, completer); |
44feb3ce TT |
10773 | } |
10774 | ||
6c95b8df | 10775 | static void |
a79b8f6e | 10776 | clear_syscall_counts (struct inferior *inf) |
6c95b8df | 10777 | { |
6c95b8df PA |
10778 | inf->total_syscalls_count = 0; |
10779 | inf->any_syscall_count = 0; | |
10780 | VEC_free (int, inf->syscalls_counts); | |
10781 | } | |
10782 | ||
c906108c | 10783 | void |
fba45db2 | 10784 | _initialize_breakpoint (void) |
c906108c | 10785 | { |
fa8d40ab JJ |
10786 | static struct cmd_list_element *breakpoint_set_cmdlist; |
10787 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
c906108c SS |
10788 | struct cmd_list_element *c; |
10789 | ||
84acb35a | 10790 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
6c95b8df | 10791 | observer_attach_inferior_exit (clear_syscall_counts); |
1f3b5d1b | 10792 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 10793 | |
c906108c SS |
10794 | breakpoint_chain = 0; |
10795 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
10796 | before a breakpoint is set. */ | |
10797 | breakpoint_count = 0; | |
10798 | ||
1042e4c0 SS |
10799 | tracepoint_count = 0; |
10800 | ||
1bedd215 AC |
10801 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
10802 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
10803 | Usage is `ignore N COUNT'.")); | |
c906108c | 10804 | if (xdb_commands) |
c5aa993b | 10805 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 10806 | |
1bedd215 AC |
10807 | add_com ("commands", class_breakpoint, commands_command, _("\ |
10808 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
10809 | Give breakpoint number as argument after \"commands\".\n\ |
10810 | With no argument, the targeted breakpoint is the last one set.\n\ | |
10811 | The commands themselves follow starting on the next line.\n\ | |
10812 | Type a line containing \"end\" to indicate the end of them.\n\ | |
10813 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 10814 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 10815 | |
1bedd215 AC |
10816 | add_com ("condition", class_breakpoint, condition_command, _("\ |
10817 | Specify breakpoint number N to break only if COND is true.\n\ | |
c906108c | 10818 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 10819 | expression to be evaluated whenever breakpoint N is reached.")); |
c906108c | 10820 | |
1bedd215 | 10821 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 10822 | Set a temporary breakpoint.\n\ |
c906108c SS |
10823 | Like \"break\" except the breakpoint is only temporary,\n\ |
10824 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
10825 | by using \"enable delete\" on the breakpoint number.\n\ |
10826 | \n" | |
10827 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 10828 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 10829 | |
1bedd215 | 10830 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
31e2b00f | 10831 | Set a hardware assisted breakpoint.\n\ |
c906108c | 10832 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
10833 | some target hardware may not have this support.\n\ |
10834 | \n" | |
10835 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 10836 | set_cmd_completer (c, location_completer); |
c906108c | 10837 | |
1bedd215 | 10838 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 10839 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 10840 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
10841 | so it will be deleted when hit.\n\ |
10842 | \n" | |
10843 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 10844 | set_cmd_completer (c, location_completer); |
c906108c | 10845 | |
1bedd215 AC |
10846 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
10847 | Enable some breakpoints.\n\ | |
c906108c SS |
10848 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
10849 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
10850 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 10851 | With a subcommand you can enable temporarily."), |
c906108c SS |
10852 | &enablelist, "enable ", 1, &cmdlist); |
10853 | if (xdb_commands) | |
1bedd215 AC |
10854 | add_com ("ab", class_breakpoint, enable_command, _("\ |
10855 | Enable some breakpoints.\n\ | |
c906108c SS |
10856 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
10857 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
10858 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 10859 | With a subcommand you can enable temporarily.")); |
c906108c SS |
10860 | |
10861 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
10862 | ||
1bedd215 AC |
10863 | add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
10864 | Enable some breakpoints.\n\ | |
c906108c SS |
10865 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
10866 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 10867 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 10868 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 10869 | |
1a966eab AC |
10870 | add_cmd ("once", no_class, enable_once_command, _("\ |
10871 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
10872 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
10873 | &enablebreaklist); |
10874 | ||
1a966eab AC |
10875 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
10876 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
10877 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
10878 | &enablebreaklist); |
10879 | ||
1a966eab AC |
10880 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
10881 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
10882 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
10883 | &enablelist); |
10884 | ||
1a966eab AC |
10885 | add_cmd ("once", no_class, enable_once_command, _("\ |
10886 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
10887 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
10888 | &enablelist); |
10889 | ||
1bedd215 AC |
10890 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
10891 | Disable some breakpoints.\n\ | |
c906108c SS |
10892 | Arguments are breakpoint numbers with spaces in between.\n\ |
10893 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 10894 | A disabled breakpoint is not forgotten, but has no effect until reenabled."), |
c906108c SS |
10895 | &disablelist, "disable ", 1, &cmdlist); |
10896 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
10897 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
10898 | if (xdb_commands) | |
1bedd215 AC |
10899 | add_com ("sb", class_breakpoint, disable_command, _("\ |
10900 | Disable some breakpoints.\n\ | |
c906108c SS |
10901 | Arguments are breakpoint numbers with spaces in between.\n\ |
10902 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 10903 | A disabled breakpoint is not forgotten, but has no effect until reenabled.")); |
c906108c | 10904 | |
1a966eab AC |
10905 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
10906 | Disable some breakpoints.\n\ | |
c906108c SS |
10907 | Arguments are breakpoint numbers with spaces in between.\n\ |
10908 | To disable all breakpoints, give no argument.\n\ | |
10909 | A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\ | |
1a966eab | 10910 | This command may be abbreviated \"disable\"."), |
c906108c SS |
10911 | &disablelist); |
10912 | ||
1bedd215 AC |
10913 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
10914 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
10915 | Arguments are breakpoint numbers with spaces in between.\n\ |
10916 | To delete all breakpoints, give no argument.\n\ | |
10917 | \n\ | |
10918 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 10919 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
10920 | &deletelist, "delete ", 1, &cmdlist); |
10921 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 10922 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 10923 | if (xdb_commands) |
1bedd215 AC |
10924 | add_com ("db", class_breakpoint, delete_command, _("\ |
10925 | Delete some breakpoints.\n\ | |
c906108c | 10926 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 10927 | To delete all breakpoints, give no argument.\n")); |
c906108c | 10928 | |
1a966eab AC |
10929 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
10930 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
10931 | Arguments are breakpoint numbers with spaces in between.\n\ |
10932 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 10933 | This command may be abbreviated \"delete\"."), |
c906108c SS |
10934 | &deletelist); |
10935 | ||
1bedd215 AC |
10936 | add_com ("clear", class_breakpoint, clear_command, _("\ |
10937 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
10938 | Argument may be line number, function name, or \"*\" and an address.\n\ |
10939 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
10940 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
10941 | If an address is specified, breakpoints at that address are cleared.\n\ |
10942 | \n\ | |
10943 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
10944 | is executing in.\n\ |
10945 | \n\ | |
1bedd215 | 10946 | See also the \"delete\" command which clears breakpoints by number.")); |
c906108c | 10947 | |
1bedd215 | 10948 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
10949 | Set breakpoint at specified line or function.\n" |
10950 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 10951 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 10952 | |
c906108c SS |
10953 | add_com_alias ("b", "break", class_run, 1); |
10954 | add_com_alias ("br", "break", class_run, 1); | |
10955 | add_com_alias ("bre", "break", class_run, 1); | |
10956 | add_com_alias ("brea", "break", class_run, 1); | |
10957 | ||
7681d515 PM |
10958 | if (xdb_commands) |
10959 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
10960 | |
10961 | if (dbx_commands) | |
10962 | { | |
1bedd215 AC |
10963 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
10964 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
10965 | &stoplist, "stop ", 1, &cmdlist); |
10966 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 10967 | _("Break in function or address."), &stoplist); |
c5aa993b | 10968 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 10969 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
10970 | add_com ("status", class_info, breakpoints_info, _("\ |
10971 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
10972 | The \"Type\" column indicates one of:\n\ |
10973 | \tbreakpoint - normal breakpoint\n\ | |
10974 | \twatchpoint - watchpoint\n\ | |
10975 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
10976 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
10977 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
10978 | address and file/line number respectively.\n\ |
10979 | \n\ | |
10980 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
10981 | are set to the address of the last breakpoint listed unless the command\n\ |
10982 | is prefixed with \"server \".\n\n\ | |
c906108c | 10983 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 10984 | breakpoint set.")); |
c906108c SS |
10985 | } |
10986 | ||
1bedd215 AC |
10987 | add_info ("breakpoints", breakpoints_info, _("\ |
10988 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
10989 | The \"Type\" column indicates one of:\n\ |
10990 | \tbreakpoint - normal breakpoint\n\ | |
10991 | \twatchpoint - watchpoint\n\ | |
10992 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
10993 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
10994 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
10995 | address and file/line number respectively.\n\ |
10996 | \n\ | |
10997 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
10998 | are set to the address of the last breakpoint listed unless the command\n\ |
10999 | is prefixed with \"server \".\n\n\ | |
c906108c | 11000 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 11001 | breakpoint set.")); |
c906108c | 11002 | |
6b04bdb7 MS |
11003 | add_info_alias ("b", "breakpoints", 1); |
11004 | ||
c906108c | 11005 | if (xdb_commands) |
1bedd215 AC |
11006 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
11007 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
11008 | The \"Type\" column indicates one of:\n\ |
11009 | \tbreakpoint - normal breakpoint\n\ | |
11010 | \twatchpoint - watchpoint\n\ | |
11011 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
11012 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
11013 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
11014 | address and file/line number respectively.\n\ |
11015 | \n\ | |
11016 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
11017 | are set to the address of the last breakpoint listed unless the command\n\ |
11018 | is prefixed with \"server \".\n\n\ | |
c906108c | 11019 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 11020 | breakpoint set.")); |
c906108c | 11021 | |
1a966eab AC |
11022 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
11023 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
11024 | The \"Type\" column indicates one of:\n\ |
11025 | \tbreakpoint - normal breakpoint\n\ | |
11026 | \twatchpoint - watchpoint\n\ | |
11027 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
11028 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
11029 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
11030 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
11031 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
11032 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
11033 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
11034 | address and file/line number respectively.\n\ |
11035 | \n\ | |
11036 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
11037 | are set to the address of the last breakpoint listed unless the command\n\ |
11038 | is prefixed with \"server \".\n\n\ | |
c906108c | 11039 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 11040 | breakpoint set."), |
c906108c SS |
11041 | &maintenanceinfolist); |
11042 | ||
44feb3ce TT |
11043 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
11044 | Set catchpoints to catch events."), | |
11045 | &catch_cmdlist, "catch ", | |
11046 | 0/*allow-unknown*/, &cmdlist); | |
11047 | ||
11048 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
11049 | Set temporary catchpoints to catch events."), | |
11050 | &tcatch_cmdlist, "tcatch ", | |
11051 | 0/*allow-unknown*/, &cmdlist); | |
11052 | ||
11053 | /* Add catch and tcatch sub-commands. */ | |
11054 | add_catch_command ("catch", _("\ | |
11055 | Catch an exception, when caught.\n\ | |
11056 | With an argument, catch only exceptions with the given name."), | |
11057 | catch_catch_command, | |
a96d9b2e | 11058 | NULL, |
44feb3ce TT |
11059 | CATCH_PERMANENT, |
11060 | CATCH_TEMPORARY); | |
11061 | add_catch_command ("throw", _("\ | |
11062 | Catch an exception, when thrown.\n\ | |
11063 | With an argument, catch only exceptions with the given name."), | |
11064 | catch_throw_command, | |
a96d9b2e | 11065 | NULL, |
44feb3ce TT |
11066 | CATCH_PERMANENT, |
11067 | CATCH_TEMPORARY); | |
11068 | add_catch_command ("fork", _("Catch calls to fork."), | |
11069 | catch_fork_command_1, | |
a96d9b2e | 11070 | NULL, |
44feb3ce TT |
11071 | (void *) (uintptr_t) catch_fork_permanent, |
11072 | (void *) (uintptr_t) catch_fork_temporary); | |
11073 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
11074 | catch_fork_command_1, | |
a96d9b2e | 11075 | NULL, |
44feb3ce TT |
11076 | (void *) (uintptr_t) catch_vfork_permanent, |
11077 | (void *) (uintptr_t) catch_vfork_temporary); | |
11078 | add_catch_command ("exec", _("Catch calls to exec."), | |
11079 | catch_exec_command_1, | |
a96d9b2e SDJ |
11080 | NULL, |
11081 | CATCH_PERMANENT, | |
11082 | CATCH_TEMPORARY); | |
11083 | add_catch_command ("syscall", _("\ | |
11084 | Catch system calls by their names and/or numbers.\n\ | |
11085 | Arguments say which system calls to catch. If no arguments\n\ | |
11086 | are given, every system call will be caught.\n\ | |
11087 | Arguments, if given, should be one or more system call names\n\ | |
11088 | (if your system supports that), or system call numbers."), | |
11089 | catch_syscall_command_1, | |
11090 | catch_syscall_completer, | |
44feb3ce TT |
11091 | CATCH_PERMANENT, |
11092 | CATCH_TEMPORARY); | |
44feb3ce TT |
11093 | add_catch_command ("exception", _("\ |
11094 | Catch Ada exceptions, when raised.\n\ | |
11095 | With an argument, catch only exceptions with the given name."), | |
11096 | catch_ada_exception_command, | |
a96d9b2e | 11097 | NULL, |
44feb3ce TT |
11098 | CATCH_PERMANENT, |
11099 | CATCH_TEMPORARY); | |
11100 | add_catch_command ("assert", _("\ | |
11101 | Catch failed Ada assertions, when raised.\n\ | |
11102 | With an argument, catch only exceptions with the given name."), | |
11103 | catch_assert_command, | |
a96d9b2e | 11104 | NULL, |
44feb3ce TT |
11105 | CATCH_PERMANENT, |
11106 | CATCH_TEMPORARY); | |
c5aa993b | 11107 | |
1bedd215 AC |
11108 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
11109 | Set a watchpoint for an expression.\n\ | |
c906108c | 11110 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 11111 | an expression changes.")); |
65d12d83 | 11112 | set_cmd_completer (c, expression_completer); |
c906108c | 11113 | |
1bedd215 AC |
11114 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
11115 | Set a read watchpoint for an expression.\n\ | |
c906108c | 11116 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 11117 | an expression is read.")); |
65d12d83 | 11118 | set_cmd_completer (c, expression_completer); |
c906108c | 11119 | |
1bedd215 AC |
11120 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
11121 | Set a watchpoint for an expression.\n\ | |
c906108c | 11122 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 11123 | an expression is either read or written.")); |
65d12d83 | 11124 | set_cmd_completer (c, expression_completer); |
c906108c SS |
11125 | |
11126 | add_info ("watchpoints", breakpoints_info, | |
1bedd215 | 11127 | _("Synonym for ``info breakpoints''.")); |
c906108c SS |
11128 | |
11129 | ||
920d2a44 AC |
11130 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
11131 | respond to changes - contrary to the description. */ | |
85c07804 AC |
11132 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
11133 | &can_use_hw_watchpoints, _("\ | |
11134 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
11135 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
11136 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
11137 | such is available. (However, any hardware watchpoints that were\n\ | |
11138 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
11139 | hardware.)"), |
11140 | NULL, | |
920d2a44 | 11141 | show_can_use_hw_watchpoints, |
85c07804 | 11142 | &setlist, &showlist); |
c906108c SS |
11143 | |
11144 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 11145 | |
1042e4c0 SS |
11146 | /* Tracepoint manipulation commands. */ |
11147 | ||
11148 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
11149 | Set a tracepoint at specified line or function.\n\ | |
11150 | \n" | |
11151 | BREAK_ARGS_HELP ("trace") "\n\ | |
11152 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
11153 | set_cmd_completer (c, location_completer); | |
11154 | ||
11155 | add_com_alias ("tp", "trace", class_alias, 0); | |
11156 | add_com_alias ("tr", "trace", class_alias, 1); | |
11157 | add_com_alias ("tra", "trace", class_alias, 1); | |
11158 | add_com_alias ("trac", "trace", class_alias, 1); | |
11159 | ||
7a697b8d SS |
11160 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
11161 | Set a fast tracepoint at specified line or function.\n\ | |
11162 | \n" | |
11163 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
11164 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
11165 | set_cmd_completer (c, location_completer); | |
11166 | ||
1042e4c0 SS |
11167 | add_info ("tracepoints", tracepoints_info, _("\ |
11168 | Status of tracepoints, or tracepoint number NUMBER.\n\ | |
11169 | Convenience variable \"$tpnum\" contains the number of the\n\ | |
11170 | last tracepoint set.")); | |
11171 | ||
11172 | add_info_alias ("tp", "tracepoints", 1); | |
11173 | ||
11174 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
11175 | Delete specified tracepoints.\n\ | |
11176 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
11177 | No argument means delete all tracepoints."), | |
11178 | &deletelist); | |
11179 | ||
11180 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
11181 | Disable specified tracepoints.\n\ | |
11182 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
11183 | No argument means disable all tracepoints."), | |
11184 | &disablelist); | |
11185 | deprecate_cmd (c, "disable"); | |
11186 | ||
11187 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
11188 | Enable specified tracepoints.\n\ | |
11189 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
11190 | No argument means enable all tracepoints."), | |
11191 | &enablelist); | |
11192 | deprecate_cmd (c, "enable"); | |
11193 | ||
11194 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
11195 | Set the passcount for a tracepoint.\n\ | |
11196 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
11197 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
11198 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
11199 | ||
11200 | c = add_com ("save-tracepoints", class_trace, tracepoint_save_command, _("\ | |
11201 | Save current tracepoint definitions as a script.\n\ | |
11202 | Use the 'source' command in another debug session to restore them.")); | |
11203 | set_cmd_completer (c, filename_completer); | |
11204 | ||
1bedd215 | 11205 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
11206 | Breakpoint specific settings\n\ |
11207 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 11208 | pending breakpoint behavior"), |
fa8d40ab JJ |
11209 | &breakpoint_set_cmdlist, "set breakpoint ", |
11210 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 11211 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
11212 | Breakpoint specific settings\n\ |
11213 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 11214 | pending breakpoint behavior"), |
fa8d40ab JJ |
11215 | &breakpoint_show_cmdlist, "show breakpoint ", |
11216 | 0/*allow-unknown*/, &showlist); | |
11217 | ||
7915a72c AC |
11218 | add_setshow_auto_boolean_cmd ("pending", no_class, |
11219 | &pending_break_support, _("\ | |
11220 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
11221 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
11222 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
11223 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
11224 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 11225 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 11226 | NULL, |
920d2a44 | 11227 | show_pending_break_support, |
6e1d7d6c AC |
11228 | &breakpoint_set_cmdlist, |
11229 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
11230 | |
11231 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
11232 | |
11233 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
11234 | &automatic_hardware_breakpoints, _("\ | |
11235 | Set automatic usage of hardware breakpoints."), _("\ | |
11236 | Show automatic usage of hardware breakpoints."), _("\ | |
11237 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
11238 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
11239 | a warning will be emitted for such breakpoints."), | |
11240 | NULL, | |
11241 | show_automatic_hardware_breakpoints, | |
11242 | &breakpoint_set_cmdlist, | |
11243 | &breakpoint_show_cmdlist); | |
74960c60 | 11244 | |
33e5cbd6 PA |
11245 | add_setshow_enum_cmd ("always-inserted", class_support, |
11246 | always_inserted_enums, &always_inserted_mode, _("\ | |
74960c60 VP |
11247 | Set mode for inserting breakpoints."), _("\ |
11248 | Show mode for inserting breakpoints."), _("\ | |
33e5cbd6 PA |
11249 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
11250 | resumed, and removed when execution stops. When this mode is on,\n\ | |
11251 | breakpoints are inserted immediately and removed only when the user\n\ | |
11252 | deletes the breakpoint. When this mode is auto (which is the default),\n\ | |
11253 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ | |
11254 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ | |
11255 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ | |
11256 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), | |
74960c60 VP |
11257 | NULL, |
11258 | &show_always_inserted_mode, | |
11259 | &breakpoint_set_cmdlist, | |
11260 | &breakpoint_show_cmdlist); | |
765dc015 VP |
11261 | |
11262 | automatic_hardware_breakpoints = 1; | |
f3b1572e PA |
11263 | |
11264 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
c906108c | 11265 | } |