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 JG |
225 | static void skip_prologue_sal (struct symtab_and_line *sal); |
226 | ||
227 | ||
f3b1572e PA |
228 | /* Flag indicating that a command has proceeded the inferior past the |
229 | current breakpoint. */ | |
230 | ||
231 | static int breakpoint_proceeded; | |
232 | ||
2cec12e5 AR |
233 | static const char * |
234 | bpdisp_text (enum bpdisp disp) | |
235 | { | |
236 | /* NOTE: the following values are a part of MI protocol and represent | |
237 | values of 'disp' field returned when inferior stops at a breakpoint. */ | |
238 | static char *bpdisps[] = {"del", "dstp", "dis", "keep"}; | |
239 | return bpdisps[(int) disp]; | |
240 | } | |
c906108c | 241 | |
2cec12e5 | 242 | /* Prototypes for exported functions. */ |
c906108c SS |
243 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
244 | if such is available. */ | |
245 | static int can_use_hw_watchpoints; | |
246 | ||
920d2a44 AC |
247 | static void |
248 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
249 | struct cmd_list_element *c, | |
250 | const char *value) | |
251 | { | |
252 | fprintf_filtered (file, _("\ | |
253 | Debugger's willingness to use watchpoint hardware is %s.\n"), | |
254 | value); | |
255 | } | |
256 | ||
fa8d40ab JJ |
257 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
258 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
259 | for unrecognized breakpoint locations. | |
260 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ | |
261 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
262 | static void |
263 | show_pending_break_support (struct ui_file *file, int from_tty, | |
264 | struct cmd_list_element *c, | |
265 | const char *value) | |
266 | { | |
267 | fprintf_filtered (file, _("\ | |
268 | Debugger's behavior regarding pending breakpoints is %s.\n"), | |
269 | value); | |
270 | } | |
fa8d40ab | 271 | |
765dc015 VP |
272 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
273 | set with "break" but falling in read-only memory. | |
274 | If 0, gdb will warn about such breakpoints, but won't automatically | |
275 | use hardware breakpoints. */ | |
276 | static int automatic_hardware_breakpoints; | |
277 | static void | |
278 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
279 | struct cmd_list_element *c, | |
280 | const char *value) | |
281 | { | |
282 | fprintf_filtered (file, _("\ | |
283 | Automatic usage of hardware breakpoints is %s.\n"), | |
284 | value); | |
285 | } | |
286 | ||
33e5cbd6 PA |
287 | /* If on, gdb will keep breakpoints inserted even as inferior is |
288 | stopped, and immediately insert any new breakpoints. If off, gdb | |
289 | will insert breakpoints into inferior only when resuming it, and | |
290 | will remove breakpoints upon stop. If auto, GDB will behave as ON | |
291 | if in non-stop mode, and as OFF if all-stop mode.*/ | |
292 | ||
293 | static const char always_inserted_auto[] = "auto"; | |
294 | static const char always_inserted_on[] = "on"; | |
295 | static const char always_inserted_off[] = "off"; | |
296 | static const char *always_inserted_enums[] = { | |
297 | always_inserted_auto, | |
298 | always_inserted_off, | |
299 | always_inserted_on, | |
300 | NULL | |
301 | }; | |
302 | static const char *always_inserted_mode = always_inserted_auto; | |
303 | static void | |
74960c60 | 304 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 305 | struct cmd_list_element *c, const char *value) |
74960c60 | 306 | { |
33e5cbd6 PA |
307 | if (always_inserted_mode == always_inserted_auto) |
308 | fprintf_filtered (file, _("\ | |
309 | Always inserted breakpoint mode is %s (currently %s).\n"), | |
310 | value, | |
311 | breakpoints_always_inserted_mode () ? "on" : "off"); | |
312 | else | |
313 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), value); | |
74960c60 VP |
314 | } |
315 | ||
33e5cbd6 PA |
316 | int |
317 | breakpoints_always_inserted_mode (void) | |
318 | { | |
319 | return (always_inserted_mode == always_inserted_on | |
320 | || (always_inserted_mode == always_inserted_auto && non_stop)); | |
321 | } | |
765dc015 | 322 | |
a14ed312 | 323 | void _initialize_breakpoint (void); |
c906108c | 324 | |
c906108c SS |
325 | /* Are we executing breakpoint commands? */ |
326 | static int executing_breakpoint_commands; | |
327 | ||
c02f5703 MS |
328 | /* Are overlay event breakpoints enabled? */ |
329 | static int overlay_events_enabled; | |
330 | ||
c906108c SS |
331 | /* Walk the following statement or block through all breakpoints. |
332 | ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current | |
333 | breakpoint. */ | |
334 | ||
5c44784c | 335 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 336 | |
5c44784c JM |
337 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
338 | for (B = breakpoint_chain; \ | |
339 | B ? (TMP=B->next, 1): 0; \ | |
340 | B = TMP) | |
c906108c | 341 | |
876fa593 JK |
342 | /* Similar iterator for the low-level breakpoints. SAFE variant is not |
343 | provided so update_global_location_list must not be called while executing | |
344 | the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 345 | |
876fa593 JK |
346 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
347 | for (BP_TMP = bp_location; \ | |
348 | BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \ | |
349 | BP_TMP++) | |
7cc221ef | 350 | |
1042e4c0 SS |
351 | /* Iterator for tracepoints only. */ |
352 | ||
353 | #define ALL_TRACEPOINTS(B) \ | |
354 | for (B = breakpoint_chain; B; B = B->next) \ | |
7a697b8d | 355 | if (tracepoint_type (B)) |
1042e4c0 | 356 | |
7cc221ef | 357 | /* Chains of all breakpoints defined. */ |
c906108c SS |
358 | |
359 | struct breakpoint *breakpoint_chain; | |
360 | ||
876fa593 JK |
361 | /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */ |
362 | ||
363 | static struct bp_location **bp_location; | |
364 | ||
365 | /* Number of elements of BP_LOCATION. */ | |
366 | ||
367 | static unsigned bp_location_count; | |
368 | ||
369 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and ADDRESS | |
370 | for the current elements of BP_LOCATION which get a valid result from | |
371 | bp_location_has_shadow. You can use it for roughly limiting the subrange of | |
372 | BP_LOCATION to scan for shadow bytes for an address you need to read. */ | |
373 | ||
374 | static CORE_ADDR bp_location_placed_address_before_address_max; | |
375 | ||
376 | /* Maximum offset plus alignment between | |
377 | bp_target_info.PLACED_ADDRESS + bp_target_info.SHADOW_LEN and ADDRESS for | |
378 | the current elements of BP_LOCATION which get a valid result from | |
379 | bp_location_has_shadow. You can use it for roughly limiting the subrange of | |
380 | BP_LOCATION to scan for shadow bytes for an address you need to read. */ | |
381 | ||
382 | static CORE_ADDR bp_location_shadow_len_after_address_max; | |
7cc221ef | 383 | |
20874c92 | 384 | /* The locations that no longer correspond to any breakpoint, |
876fa593 | 385 | unlinked from bp_location array, but for which a hit |
20874c92 VP |
386 | may still be reported by a target. */ |
387 | VEC(bp_location_p) *moribund_locations = NULL; | |
388 | ||
c906108c SS |
389 | /* Number of last breakpoint made. */ |
390 | ||
95a42b64 TT |
391 | static int breakpoint_count; |
392 | ||
393 | /* If the last command to create a breakpoint created multiple | |
394 | breakpoints, this holds the start and end breakpoint numbers. */ | |
395 | static int multi_start; | |
396 | static int multi_end; | |
397 | /* True if the last breakpoint set was part of a group set with a | |
398 | single command, e.g., "rbreak". */ | |
399 | static int last_was_multi; | |
c906108c | 400 | |
1042e4c0 SS |
401 | /* Number of last tracepoint made. */ |
402 | ||
95a42b64 | 403 | static int tracepoint_count; |
1042e4c0 | 404 | |
468d015d JJ |
405 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
406 | static int | |
407 | breakpoint_enabled (struct breakpoint *b) | |
408 | { | |
0d381245 | 409 | return (b->enable_state == bp_enabled); |
468d015d JJ |
410 | } |
411 | ||
c906108c SS |
412 | /* Set breakpoint count to NUM. */ |
413 | ||
95a42b64 | 414 | static void |
fba45db2 | 415 | set_breakpoint_count (int num) |
c906108c SS |
416 | { |
417 | breakpoint_count = num; | |
95a42b64 | 418 | last_was_multi = 0; |
4fa62494 | 419 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
420 | } |
421 | ||
95a42b64 TT |
422 | /* Called at the start an "rbreak" command to record the first |
423 | breakpoint made. */ | |
424 | void | |
425 | start_rbreak_breakpoints (void) | |
426 | { | |
427 | multi_start = breakpoint_count + 1; | |
428 | } | |
429 | ||
430 | /* Called at the end of an "rbreak" command to record the last | |
431 | breakpoint made. */ | |
432 | void | |
433 | end_rbreak_breakpoints (void) | |
434 | { | |
435 | if (breakpoint_count >= multi_start) | |
436 | { | |
437 | multi_end = breakpoint_count; | |
438 | last_was_multi = 1; | |
439 | } | |
440 | } | |
441 | ||
c906108c SS |
442 | /* Used in run_command to zero the hit count when a new run starts. */ |
443 | ||
444 | void | |
fba45db2 | 445 | clear_breakpoint_hit_counts (void) |
c906108c SS |
446 | { |
447 | struct breakpoint *b; | |
448 | ||
449 | ALL_BREAKPOINTS (b) | |
450 | b->hit_count = 0; | |
451 | } | |
452 | ||
7a697b8d SS |
453 | /* Encapsulate tests for different types of tracepoints. */ |
454 | ||
455 | static int | |
456 | tracepoint_type (const struct breakpoint *b) | |
457 | { | |
458 | return (b->type == bp_tracepoint || b->type == bp_fast_tracepoint); | |
459 | } | |
460 | ||
9add0f1b TT |
461 | /* Allocate a new counted_command_line with reference count of 1. |
462 | The new structure owns COMMANDS. */ | |
463 | ||
464 | static struct counted_command_line * | |
465 | alloc_counted_command_line (struct command_line *commands) | |
466 | { | |
467 | struct counted_command_line *result | |
468 | = xmalloc (sizeof (struct counted_command_line)); | |
469 | result->refc = 1; | |
470 | result->commands = commands; | |
471 | return result; | |
472 | } | |
473 | ||
474 | /* Increment reference count. This does nothing if CMD is NULL. */ | |
475 | ||
476 | static void | |
477 | incref_counted_command_line (struct counted_command_line *cmd) | |
478 | { | |
479 | if (cmd) | |
480 | ++cmd->refc; | |
481 | } | |
482 | ||
483 | /* Decrement reference count. If the reference count reaches 0, | |
484 | destroy the counted_command_line. Sets *CMDP to NULL. This does | |
485 | nothing if *CMDP is NULL. */ | |
486 | ||
487 | static void | |
488 | decref_counted_command_line (struct counted_command_line **cmdp) | |
489 | { | |
490 | if (*cmdp) | |
491 | { | |
492 | if (--(*cmdp)->refc == 0) | |
493 | { | |
494 | free_command_lines (&(*cmdp)->commands); | |
495 | xfree (*cmdp); | |
496 | } | |
497 | *cmdp = NULL; | |
498 | } | |
499 | } | |
500 | ||
501 | /* A cleanup function that calls decref_counted_command_line. */ | |
502 | ||
503 | static void | |
504 | do_cleanup_counted_command_line (void *arg) | |
505 | { | |
506 | decref_counted_command_line (arg); | |
507 | } | |
508 | ||
509 | /* Create a cleanup that calls decref_counted_command_line on the | |
510 | argument. */ | |
511 | ||
512 | static struct cleanup * | |
513 | make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp) | |
514 | { | |
515 | return make_cleanup (do_cleanup_counted_command_line, cmdp); | |
516 | } | |
517 | ||
c906108c SS |
518 | /* Default address, symtab and line to put a breakpoint at |
519 | for "break" command with no arg. | |
520 | if default_breakpoint_valid is zero, the other three are | |
521 | not valid, and "break" with no arg is an error. | |
522 | ||
523 | This set by print_stack_frame, which calls set_default_breakpoint. */ | |
524 | ||
525 | int default_breakpoint_valid; | |
526 | CORE_ADDR default_breakpoint_address; | |
527 | struct symtab *default_breakpoint_symtab; | |
528 | int default_breakpoint_line; | |
6c95b8df PA |
529 | struct program_space *default_breakpoint_pspace; |
530 | ||
c906108c SS |
531 | \f |
532 | /* *PP is a string denoting a breakpoint. Get the number of the breakpoint. | |
533 | Advance *PP after the string and any trailing whitespace. | |
534 | ||
535 | Currently the string can either be a number or "$" followed by the name | |
536 | of a convenience variable. Making it an expression wouldn't work well | |
5c44784c | 537 | for map_breakpoint_numbers (e.g. "4 + 5 + 6"). |
40c03ae8 EZ |
538 | |
539 | If the string is a NULL pointer, that denotes the last breakpoint. | |
5c44784c JM |
540 | |
541 | TRAILER is a character which can be found after the number; most | |
542 | commonly this is `-'. If you don't want a trailer, use \0. */ | |
c906108c | 543 | static int |
fba45db2 | 544 | get_number_trailer (char **pp, int trailer) |
c906108c | 545 | { |
5c44784c | 546 | int retval = 0; /* default */ |
c906108c SS |
547 | char *p = *pp; |
548 | ||
549 | if (p == NULL) | |
550 | /* Empty line means refer to the last breakpoint. */ | |
551 | return breakpoint_count; | |
552 | else if (*p == '$') | |
553 | { | |
554 | /* Make a copy of the name, so we can null-terminate it | |
c5aa993b | 555 | to pass to lookup_internalvar(). */ |
c906108c SS |
556 | char *varname; |
557 | char *start = ++p; | |
4fa62494 | 558 | LONGEST val; |
c906108c SS |
559 | |
560 | while (isalnum (*p) || *p == '_') | |
561 | p++; | |
562 | varname = (char *) alloca (p - start + 1); | |
563 | strncpy (varname, start, p - start); | |
564 | varname[p - start] = '\0'; | |
4fa62494 UW |
565 | if (get_internalvar_integer (lookup_internalvar (varname), &val)) |
566 | retval = (int) val; | |
5c44784c JM |
567 | else |
568 | { | |
a3f17187 | 569 | printf_filtered (_("Convenience variable must have integer value.\n")); |
5c44784c JM |
570 | retval = 0; |
571 | } | |
c906108c SS |
572 | } |
573 | else | |
574 | { | |
575 | if (*p == '-') | |
576 | ++p; | |
577 | while (*p >= '0' && *p <= '9') | |
578 | ++p; | |
579 | if (p == *pp) | |
580 | /* There is no number here. (e.g. "cond a == b"). */ | |
5c44784c JM |
581 | { |
582 | /* Skip non-numeric token */ | |
583 | while (*p && !isspace((int) *p)) | |
584 | ++p; | |
585 | /* Return zero, which caller must interpret as error. */ | |
586 | retval = 0; | |
587 | } | |
588 | else | |
589 | retval = atoi (*pp); | |
590 | } | |
591 | if (!(isspace (*p) || *p == '\0' || *p == trailer)) | |
592 | { | |
593 | /* Trailing junk: return 0 and let caller print error msg. */ | |
594 | while (!(isspace (*p) || *p == '\0' || *p == trailer)) | |
595 | ++p; | |
596 | retval = 0; | |
c906108c | 597 | } |
c906108c SS |
598 | while (isspace (*p)) |
599 | p++; | |
600 | *pp = p; | |
601 | return retval; | |
602 | } | |
5c44784c | 603 | |
11cf8741 | 604 | |
5c44784c JM |
605 | /* Like get_number_trailer, but don't allow a trailer. */ |
606 | int | |
fba45db2 | 607 | get_number (char **pp) |
5c44784c JM |
608 | { |
609 | return get_number_trailer (pp, '\0'); | |
610 | } | |
611 | ||
612 | /* Parse a number or a range. | |
613 | * A number will be of the form handled by get_number. | |
614 | * A range will be of the form <number1> - <number2>, and | |
615 | * will represent all the integers between number1 and number2, | |
616 | * inclusive. | |
617 | * | |
618 | * While processing a range, this fuction is called iteratively; | |
619 | * At each call it will return the next value in the range. | |
620 | * | |
621 | * At the beginning of parsing a range, the char pointer PP will | |
622 | * be advanced past <number1> and left pointing at the '-' token. | |
623 | * Subsequent calls will not advance the pointer until the range | |
624 | * is completed. The call that completes the range will advance | |
625 | * pointer PP past <number2>. | |
626 | */ | |
627 | ||
628 | int | |
fba45db2 | 629 | get_number_or_range (char **pp) |
5c44784c JM |
630 | { |
631 | static int last_retval, end_value; | |
632 | static char *end_ptr; | |
633 | static int in_range = 0; | |
634 | ||
635 | if (**pp != '-') | |
636 | { | |
637 | /* Default case: pp is pointing either to a solo number, | |
638 | or to the first number of a range. */ | |
639 | last_retval = get_number_trailer (pp, '-'); | |
640 | if (**pp == '-') | |
641 | { | |
642 | char **temp; | |
643 | ||
644 | /* This is the start of a range (<number1> - <number2>). | |
645 | Skip the '-', parse and remember the second number, | |
646 | and also remember the end of the final token. */ | |
647 | ||
648 | temp = &end_ptr; | |
649 | end_ptr = *pp + 1; | |
650 | while (isspace ((int) *end_ptr)) | |
651 | end_ptr++; /* skip white space */ | |
652 | end_value = get_number (temp); | |
653 | if (end_value < last_retval) | |
654 | { | |
8a3fe4f8 | 655 | error (_("inverted range")); |
5c44784c JM |
656 | } |
657 | else if (end_value == last_retval) | |
658 | { | |
659 | /* degenerate range (number1 == number2). Advance the | |
660 | token pointer so that the range will be treated as a | |
661 | single number. */ | |
662 | *pp = end_ptr; | |
663 | } | |
664 | else | |
665 | in_range = 1; | |
666 | } | |
667 | } | |
668 | else if (! in_range) | |
8a3fe4f8 | 669 | error (_("negative value")); |
5c44784c JM |
670 | else |
671 | { | |
672 | /* pp points to the '-' that betokens a range. All | |
673 | number-parsing has already been done. Return the next | |
674 | integer value (one greater than the saved previous value). | |
675 | Do not advance the token pointer 'pp' until the end of range | |
676 | is reached. */ | |
677 | ||
678 | if (++last_retval == end_value) | |
679 | { | |
680 | /* End of range reached; advance token pointer. */ | |
681 | *pp = end_ptr; | |
682 | in_range = 0; | |
683 | } | |
684 | } | |
685 | return last_retval; | |
686 | } | |
687 | ||
48cb2d85 VP |
688 | /* Return the breakpoint with the specified number, or NULL |
689 | if the number does not refer to an existing breakpoint. */ | |
690 | ||
691 | struct breakpoint * | |
692 | get_breakpoint (int num) | |
693 | { | |
694 | struct breakpoint *b; | |
695 | ||
696 | ALL_BREAKPOINTS (b) | |
697 | if (b->number == num) | |
698 | return b; | |
699 | ||
700 | return NULL; | |
701 | } | |
5c44784c | 702 | |
c906108c SS |
703 | \f |
704 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ | |
705 | ||
706 | static void | |
fba45db2 | 707 | condition_command (char *arg, int from_tty) |
c906108c | 708 | { |
52f0bd74 | 709 | struct breakpoint *b; |
c906108c | 710 | char *p; |
52f0bd74 | 711 | int bnum; |
c906108c SS |
712 | |
713 | if (arg == 0) | |
e2e0b3e5 | 714 | error_no_arg (_("breakpoint number")); |
c906108c SS |
715 | |
716 | p = arg; | |
717 | bnum = get_number (&p); | |
5c44784c | 718 | if (bnum == 0) |
8a3fe4f8 | 719 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
720 | |
721 | ALL_BREAKPOINTS (b) | |
722 | if (b->number == bnum) | |
2f069f6f JB |
723 | { |
724 | struct bp_location *loc = b->loc; | |
725 | for (; loc; loc = loc->next) | |
726 | { | |
60e1c644 PA |
727 | xfree (loc->cond); |
728 | loc->cond = NULL; | |
2f069f6f | 729 | } |
60e1c644 PA |
730 | xfree (b->cond_string); |
731 | b->cond_string = NULL; | |
732 | xfree (b->cond_exp); | |
733 | b->cond_exp = NULL; | |
c906108c | 734 | |
2f069f6f JB |
735 | if (*p == 0) |
736 | { | |
2f069f6f JB |
737 | if (from_tty) |
738 | printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum); | |
739 | } | |
740 | else | |
741 | { | |
742 | arg = p; | |
743 | /* I don't know if it matters whether this is the string the user | |
744 | typed in or the decompiled expression. */ | |
1b36a34b | 745 | b->cond_string = xstrdup (arg); |
2f069f6f | 746 | b->condition_not_parsed = 0; |
60e1c644 PA |
747 | |
748 | if (is_watchpoint (b)) | |
2f069f6f | 749 | { |
60e1c644 | 750 | innermost_block = NULL; |
2f069f6f | 751 | arg = p; |
60e1c644 | 752 | b->cond_exp = parse_exp_1 (&arg, 0, 0); |
2f069f6f JB |
753 | if (*arg) |
754 | error (_("Junk at end of expression")); | |
60e1c644 PA |
755 | b->cond_exp_valid_block = innermost_block; |
756 | } | |
757 | else | |
758 | { | |
759 | for (loc = b->loc; loc; loc = loc->next) | |
760 | { | |
761 | arg = p; | |
762 | loc->cond = | |
763 | parse_exp_1 (&arg, block_for_pc (loc->address), 0); | |
764 | if (*arg) | |
765 | error (_("Junk at end of expression")); | |
766 | } | |
2f069f6f JB |
767 | } |
768 | } | |
769 | breakpoints_changed (); | |
383f836e | 770 | observer_notify_breakpoint_modified (b->number); |
2f069f6f JB |
771 | return; |
772 | } | |
c906108c | 773 | |
8a3fe4f8 | 774 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
775 | } |
776 | ||
a7bdde9e VP |
777 | /* Check that COMMAND do not contain commands that are suitable |
778 | only for tracepoints and not suitable for ordinary breakpoints. | |
779 | Throw if any such commands is found. | |
780 | */ | |
781 | static void | |
782 | check_no_tracepoint_commands (struct command_line *commands) | |
783 | { | |
784 | struct command_line *c; | |
785 | for (c = commands; c; c = c->next) | |
786 | { | |
787 | int i; | |
788 | ||
789 | if (c->control_type == while_stepping_control) | |
790 | error (_("The 'while-stepping' command can only be used for tracepoints")); | |
791 | ||
792 | for (i = 0; i < c->body_count; ++i) | |
793 | check_no_tracepoint_commands ((c->body_list)[i]); | |
794 | ||
795 | /* Not that command parsing removes leading whitespace and comment | |
796 | lines and also empty lines. So, we only need to check for | |
797 | command directly. */ | |
798 | if (strstr (c->line, "collect ") == c->line) | |
799 | error (_("The 'collect' command can only be used for tracepoints")); | |
800 | ||
51661e93 VP |
801 | if (strstr (c->line, "teval ") == c->line) |
802 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
803 | } |
804 | } | |
805 | ||
806 | int | |
807 | breakpoint_is_tracepoint (const struct breakpoint *b) | |
808 | { | |
809 | switch (b->type) | |
810 | { | |
811 | case bp_tracepoint: | |
812 | case bp_fast_tracepoint: | |
813 | return 1; | |
814 | default: | |
815 | return 0; | |
816 | ||
817 | } | |
818 | } | |
819 | ||
95a42b64 TT |
820 | /* A helper function that validsates that COMMANDS are valid for a |
821 | breakpoint. This function will throw an exception if a problem is | |
822 | found. */ | |
48cb2d85 | 823 | |
95a42b64 TT |
824 | static void |
825 | validate_commands_for_breakpoint (struct breakpoint *b, | |
826 | struct command_line *commands) | |
48cb2d85 | 827 | { |
a7bdde9e VP |
828 | if (breakpoint_is_tracepoint (b)) |
829 | { | |
830 | /* We need to verify that each top-level element of commands | |
831 | is valid for tracepoints, that there's at most one while-stepping | |
832 | element, and that while-stepping's body has valid tracing commands | |
833 | excluding nested while-stepping. */ | |
834 | struct command_line *c; | |
835 | struct command_line *while_stepping = 0; | |
836 | for (c = commands; c; c = c->next) | |
837 | { | |
838 | char *l = c->line; | |
839 | if (c->control_type == while_stepping_control) | |
840 | { | |
841 | if (b->type == bp_fast_tracepoint) | |
842 | error (_("The 'while-stepping' command cannot be used for fast tracepoint")); | |
843 | ||
844 | if (while_stepping) | |
845 | error (_("The 'while-stepping' command can be used only once")); | |
846 | else | |
847 | while_stepping = c; | |
848 | } | |
849 | } | |
850 | if (while_stepping) | |
851 | { | |
852 | struct command_line *c2; | |
853 | ||
854 | gdb_assert (while_stepping->body_count == 1); | |
855 | c2 = while_stepping->body_list[0]; | |
856 | for (; c2; c2 = c2->next) | |
857 | { | |
858 | char *l = c2->line; | |
859 | if (c2->control_type == while_stepping_control) | |
860 | error (_("The 'while-stepping' command cannot be nested")); | |
861 | } | |
862 | } | |
863 | } | |
864 | else | |
865 | { | |
866 | check_no_tracepoint_commands (commands); | |
867 | } | |
95a42b64 TT |
868 | } |
869 | ||
870 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, | |
871 | validate that only allowed commands are included. | |
872 | */ | |
873 | ||
874 | void | |
875 | breakpoint_set_commands (struct breakpoint *b, struct command_line *commands) | |
876 | { | |
877 | validate_commands_for_breakpoint (b, commands); | |
a7bdde9e | 878 | |
9add0f1b TT |
879 | decref_counted_command_line (&b->commands); |
880 | b->commands = alloc_counted_command_line (commands); | |
48cb2d85 VP |
881 | breakpoints_changed (); |
882 | observer_notify_breakpoint_modified (b->number); | |
883 | } | |
884 | ||
95a42b64 TT |
885 | void |
886 | check_tracepoint_command (char *line, void *closure) | |
a7bdde9e VP |
887 | { |
888 | struct breakpoint *b = closure; | |
889 | validate_actionline (&line, b); | |
890 | } | |
891 | ||
95a42b64 TT |
892 | /* A structure used to pass information through |
893 | map_breakpoint_numbers. */ | |
894 | ||
895 | struct commands_info | |
896 | { | |
897 | /* True if the command was typed at a tty. */ | |
898 | int from_tty; | |
899 | /* Non-NULL if the body of the commands are being read from this | |
900 | already-parsed command. */ | |
901 | struct command_line *control; | |
902 | /* The command lines read from the user, or NULL if they have not | |
903 | yet been read. */ | |
904 | struct counted_command_line *cmd; | |
905 | }; | |
906 | ||
907 | /* A callback for map_breakpoint_numbers that sets the commands for | |
908 | commands_command. */ | |
909 | ||
c906108c | 910 | static void |
95a42b64 | 911 | do_map_commands_command (struct breakpoint *b, void *data) |
c906108c | 912 | { |
95a42b64 | 913 | struct commands_info *info = data; |
c906108c | 914 | |
95a42b64 TT |
915 | if (info->cmd == NULL) |
916 | { | |
917 | struct command_line *l; | |
5c44784c | 918 | |
95a42b64 TT |
919 | if (info->control != NULL) |
920 | l = copy_command_lines (info->control->body_list[0]); | |
921 | else | |
c5aa993b | 922 | |
95a42b64 TT |
923 | l = read_command_lines (_("Type commands for all specified breakpoints"), |
924 | info->from_tty, 1, | |
925 | (breakpoint_is_tracepoint (b) | |
926 | ? check_tracepoint_command : 0), | |
927 | b); | |
a7bdde9e | 928 | |
95a42b64 TT |
929 | info->cmd = alloc_counted_command_line (l); |
930 | } | |
931 | ||
932 | /* If a breakpoint was on the list more than once, we don't need to | |
933 | do anything. */ | |
934 | if (b->commands != info->cmd) | |
935 | { | |
936 | validate_commands_for_breakpoint (b, info->cmd->commands); | |
937 | incref_counted_command_line (info->cmd); | |
938 | decref_counted_command_line (&b->commands); | |
939 | b->commands = info->cmd; | |
940 | breakpoints_changed (); | |
941 | observer_notify_breakpoint_modified (b->number); | |
c5aa993b | 942 | } |
95a42b64 TT |
943 | } |
944 | ||
945 | static void | |
946 | commands_command_1 (char *arg, int from_tty, struct command_line *control) | |
947 | { | |
948 | struct cleanup *cleanups; | |
949 | struct commands_info info; | |
950 | ||
951 | info.from_tty = from_tty; | |
952 | info.control = control; | |
953 | info.cmd = NULL; | |
954 | /* If we read command lines from the user, then `info' will hold an | |
955 | extra reference to the commands that we must clean up. */ | |
956 | cleanups = make_cleanup_decref_counted_command_line (&info.cmd); | |
957 | ||
958 | if (arg == NULL || !*arg) | |
959 | { | |
960 | if (last_was_multi) | |
961 | arg = xstrprintf ("%d-%d", multi_start, multi_end); | |
962 | else if (breakpoint_count > 0) | |
963 | arg = xstrprintf ("%d", breakpoint_count); | |
964 | make_cleanup (xfree, arg); | |
965 | } | |
966 | ||
967 | map_breakpoint_numbers (arg, do_map_commands_command, &info); | |
968 | ||
969 | if (info.cmd == NULL) | |
970 | error (_("No breakpoints specified.")); | |
971 | ||
972 | do_cleanups (cleanups); | |
973 | } | |
974 | ||
975 | static void | |
976 | commands_command (char *arg, int from_tty) | |
977 | { | |
978 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 979 | } |
40c03ae8 EZ |
980 | |
981 | /* Like commands_command, but instead of reading the commands from | |
982 | input stream, takes them from an already parsed command structure. | |
983 | ||
984 | This is used by cli-script.c to DTRT with breakpoint commands | |
985 | that are part of if and while bodies. */ | |
986 | enum command_control_type | |
987 | commands_from_control_command (char *arg, struct command_line *cmd) | |
988 | { | |
95a42b64 TT |
989 | commands_command_1 (arg, 0, cmd); |
990 | return simple_control; | |
40c03ae8 | 991 | } |
876fa593 JK |
992 | |
993 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
994 | ||
995 | static int | |
996 | bp_location_has_shadow (struct bp_location *bl) | |
997 | { | |
998 | if (bl->loc_type != bp_loc_software_breakpoint) | |
999 | return 0; | |
1000 | if (!bl->inserted) | |
1001 | return 0; | |
1002 | if (bl->target_info.shadow_len == 0) | |
1003 | /* bp isn't valid, or doesn't shadow memory. */ | |
1004 | return 0; | |
1005 | return 1; | |
1006 | } | |
1007 | ||
8defab1a | 1008 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1009 | by replacing any memory breakpoints with their shadowed contents. |
1010 | ||
1011 | The range of shadowed area by each bp_location is: | |
1012 | b->address - bp_location_placed_address_before_address_max | |
1013 | up to b->address + bp_location_shadow_len_after_address_max | |
1014 | The range we were requested to resolve shadows for is: | |
1015 | memaddr ... memaddr + len | |
1016 | Thus the safe cutoff boundaries for performance optimization are | |
1017 | memaddr + len <= b->address - bp_location_placed_address_before_address_max | |
1018 | and: | |
1019 | b->address + bp_location_shadow_len_after_address_max <= memaddr */ | |
c906108c | 1020 | |
8defab1a DJ |
1021 | void |
1022 | breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len) | |
c906108c | 1023 | { |
876fa593 JK |
1024 | /* Left boundary, right boundary and median element of our binary search. */ |
1025 | unsigned bc_l, bc_r, bc; | |
1026 | ||
1027 | /* Find BC_L which is a leftmost element which may affect BUF content. It is | |
1028 | safe to report lower value but a failure to report higher one. */ | |
1029 | ||
1030 | bc_l = 0; | |
1031 | bc_r = bp_location_count; | |
1032 | while (bc_l + 1 < bc_r) | |
1033 | { | |
1034 | struct bp_location *b; | |
1035 | ||
1036 | bc = (bc_l + bc_r) / 2; | |
1037 | b = bp_location[bc]; | |
1038 | ||
1039 | /* Check first B->ADDRESS will not overflow due to the added constant. | |
1040 | Then advance the left boundary only if we are sure the BC element can | |
1041 | in no way affect the BUF content (MEMADDR to MEMADDR + LEN range). | |
1042 | ||
1043 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety offset so that | |
1044 | we cannot miss a breakpoint with its shadow range tail still reaching | |
1045 | MEMADDR. */ | |
c5aa993b | 1046 | |
876fa593 JK |
1047 | if (b->address + bp_location_shadow_len_after_address_max >= b->address |
1048 | && b->address + bp_location_shadow_len_after_address_max <= memaddr) | |
1049 | bc_l = bc; | |
1050 | else | |
1051 | bc_r = bc; | |
1052 | } | |
1053 | ||
1054 | /* Now do full processing of the found relevant range of elements. */ | |
1055 | ||
1056 | for (bc = bc_l; bc < bp_location_count; bc++) | |
c5aa993b | 1057 | { |
876fa593 JK |
1058 | struct bp_location *b = bp_location[bc]; |
1059 | CORE_ADDR bp_addr = 0; | |
1060 | int bp_size = 0; | |
1061 | int bptoffset = 0; | |
1062 | ||
ffce0d52 | 1063 | if (b->owner->type == bp_none) |
8a3fe4f8 | 1064 | warning (_("reading through apparently deleted breakpoint #%d?"), |
ffce0d52 DJ |
1065 | b->owner->number); |
1066 | ||
876fa593 JK |
1067 | /* Performance optimization: any futher element can no longer affect BUF |
1068 | content. */ | |
1069 | ||
1070 | if (b->address >= bp_location_placed_address_before_address_max | |
1071 | && memaddr + len <= b->address | |
1072 | - bp_location_placed_address_before_address_max) | |
1073 | break; | |
1074 | ||
1075 | if (!bp_location_has_shadow (b)) | |
c5aa993b | 1076 | continue; |
6c95b8df PA |
1077 | if (!breakpoint_address_match (b->target_info.placed_address_space, 0, |
1078 | current_program_space->aspace, 0)) | |
1079 | continue; | |
1080 | ||
c5aa993b JM |
1081 | /* Addresses and length of the part of the breakpoint that |
1082 | we need to copy. */ | |
8181d85f DJ |
1083 | bp_addr = b->target_info.placed_address; |
1084 | bp_size = b->target_info.shadow_len; | |
8defab1a | 1085 | |
c5aa993b JM |
1086 | if (bp_addr + bp_size <= memaddr) |
1087 | /* The breakpoint is entirely before the chunk of memory we | |
1088 | are reading. */ | |
1089 | continue; | |
8defab1a | 1090 | |
c5aa993b JM |
1091 | if (bp_addr >= memaddr + len) |
1092 | /* The breakpoint is entirely after the chunk of memory we are | |
1093 | reading. */ | |
1094 | continue; | |
c5aa993b | 1095 | |
8defab1a DJ |
1096 | /* Offset within shadow_contents. */ |
1097 | if (bp_addr < memaddr) | |
1098 | { | |
1099 | /* Only copy the second part of the breakpoint. */ | |
1100 | bp_size -= memaddr - bp_addr; | |
1101 | bptoffset = memaddr - bp_addr; | |
1102 | bp_addr = memaddr; | |
1103 | } | |
c5aa993b | 1104 | |
8defab1a DJ |
1105 | if (bp_addr + bp_size > memaddr + len) |
1106 | { | |
1107 | /* Only copy the first part of the breakpoint. */ | |
1108 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1109 | } | |
c5aa993b | 1110 | |
8defab1a DJ |
1111 | memcpy (buf + bp_addr - memaddr, |
1112 | b->target_info.shadow_contents + bptoffset, bp_size); | |
c5aa993b | 1113 | } |
c906108c | 1114 | } |
c906108c | 1115 | \f |
c5aa993b | 1116 | |
687595f9 | 1117 | /* A wrapper function for inserting catchpoints. */ |
9cbc821d | 1118 | static void |
687595f9 DJ |
1119 | insert_catchpoint (struct ui_out *uo, void *args) |
1120 | { | |
1121 | struct breakpoint *b = (struct breakpoint *) args; | |
1122 | int val = -1; | |
1123 | ||
fe798b75 JB |
1124 | gdb_assert (b->type == bp_catchpoint); |
1125 | gdb_assert (b->ops != NULL && b->ops->insert != NULL); | |
1126 | ||
1127 | b->ops->insert (b); | |
687595f9 DJ |
1128 | } |
1129 | ||
60e1c644 PA |
1130 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1131 | ||
a5606eee VP |
1132 | static int |
1133 | is_hardware_watchpoint (struct breakpoint *bpt) | |
1134 | { | |
1135 | return (bpt->type == bp_hardware_watchpoint | |
1136 | || bpt->type == bp_read_watchpoint | |
1137 | || bpt->type == bp_access_watchpoint); | |
1138 | } | |
7270d8f2 | 1139 | |
60e1c644 PA |
1140 | /* Return true if BPT is of any watchpoint kind, hardware or |
1141 | software. */ | |
1142 | ||
1143 | static int | |
1144 | is_watchpoint (struct breakpoint *bpt) | |
1145 | { | |
1146 | return (is_hardware_watchpoint (bpt) | |
1147 | || bpt->type == bp_watchpoint); | |
1148 | } | |
1149 | ||
fa4727a6 DJ |
1150 | /* Find the current value of a watchpoint on EXP. Return the value in |
1151 | *VALP and *RESULTP and the chain of intermediate and final values | |
1152 | in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does | |
1153 | not need them. | |
1154 | ||
ccc57cf9 | 1155 | If a memory error occurs while evaluating the expression, *RESULTP will |
fa4727a6 DJ |
1156 | be set to NULL. *RESULTP may be a lazy value, if the result could |
1157 | not be read from memory. It is used to determine whether a value | |
1158 | is user-specified (we should watch the whole value) or intermediate | |
1159 | (we should watch only the bit used to locate the final value). | |
1160 | ||
1161 | If the final value, or any intermediate value, could not be read | |
1162 | from memory, *VALP will be set to NULL. *VAL_CHAIN will still be | |
1163 | set to any referenced values. *VALP will never be a lazy value. | |
1164 | This is the value which we store in struct breakpoint. | |
1165 | ||
1166 | If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the | |
1167 | value chain. The caller must free the values individually. If | |
1168 | VAL_CHAIN is NULL, all generated values will be left on the value | |
1169 | chain. */ | |
1170 | ||
1171 | static void | |
1172 | fetch_watchpoint_value (struct expression *exp, struct value **valp, | |
1173 | struct value **resultp, struct value **val_chain) | |
1174 | { | |
1175 | struct value *mark, *new_mark, *result; | |
ccc57cf9 | 1176 | volatile struct gdb_exception ex; |
fa4727a6 DJ |
1177 | |
1178 | *valp = NULL; | |
1179 | if (resultp) | |
1180 | *resultp = NULL; | |
1181 | if (val_chain) | |
1182 | *val_chain = NULL; | |
1183 | ||
1184 | /* Evaluate the expression. */ | |
1185 | mark = value_mark (); | |
1186 | result = NULL; | |
ccc57cf9 PA |
1187 | |
1188 | TRY_CATCH (ex, RETURN_MASK_ALL) | |
1189 | { | |
1190 | result = evaluate_expression (exp); | |
1191 | } | |
1192 | if (ex.reason < 0) | |
1193 | { | |
1194 | /* Ignore memory errors, we want watchpoints pointing at | |
1195 | inaccessible memory to still be created; otherwise, throw the | |
1196 | error to some higher catcher. */ | |
1197 | switch (ex.error) | |
1198 | { | |
1199 | case MEMORY_ERROR: | |
1200 | break; | |
1201 | default: | |
1202 | throw_exception (ex); | |
1203 | break; | |
1204 | } | |
1205 | } | |
1206 | ||
fa4727a6 DJ |
1207 | new_mark = value_mark (); |
1208 | if (mark == new_mark) | |
1209 | return; | |
1210 | if (resultp) | |
1211 | *resultp = result; | |
1212 | ||
1213 | /* Make sure it's not lazy, so that after the target stops again we | |
1214 | have a non-lazy previous value to compare with. */ | |
1215 | if (result != NULL | |
1216 | && (!value_lazy (result) || gdb_value_fetch_lazy (result))) | |
1217 | *valp = result; | |
1218 | ||
1219 | if (val_chain) | |
1220 | { | |
1221 | /* Return the chain of intermediate values. We use this to | |
1222 | decide which addresses to watch. */ | |
1223 | *val_chain = new_mark; | |
1224 | value_release_to_mark (mark); | |
1225 | } | |
1226 | } | |
1227 | ||
f6bc2008 PA |
1228 | /* Assuming that B is a watchpoint: returns true if the current thread |
1229 | and its running state are safe to evaluate or update watchpoint B. | |
1230 | Watchpoints on local expressions need to be evaluated in the | |
1231 | context of the thread that was current when the watchpoint was | |
1232 | created, and, that thread needs to be stopped to be able to select | |
1233 | the correct frame context. Watchpoints on global expressions can | |
1234 | be evaluated on any thread, and in any state. It is presently left | |
1235 | to the target allowing memory accesses when threads are | |
1236 | running. */ | |
1237 | ||
1238 | static int | |
1239 | watchpoint_in_thread_scope (struct breakpoint *b) | |
1240 | { | |
1241 | return (ptid_equal (b->watchpoint_thread, null_ptid) | |
1242 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1243 | && !is_executing (inferior_ptid))); | |
1244 | } | |
1245 | ||
567e1b4e JB |
1246 | /* Assuming that B is a watchpoint: |
1247 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1248 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1249 | - Evaluate the condition if there is one, and store the result |
1250 | in b->loc->cond. | |
a5606eee VP |
1251 | - Update the list of values that must be watched in B->loc. |
1252 | ||
bfa149ac | 1253 | If the watchpoint disposition is disp_del_at_next_stop, then do nothing. |
a79d3c27 JK |
1254 | If this is local watchpoint that is out of scope, delete it. |
1255 | ||
1256 | Even with `set breakpoint always-inserted on' the watchpoints are removed | |
1257 | + inserted on each stop here. Normal breakpoints must never be removed | |
1258 | because they might be missed by a running thread when debugging in non-stop | |
1259 | mode. On the other hand, hardware watchpoints (is_hardware_watchpoint; | |
1260 | processed here) are specific to each LWP since they are stored in each LWP's | |
1261 | hardware debug registers. Therefore, such LWP must be stopped first in | |
1262 | order to be able to modify its hardware watchpoints. | |
1263 | ||
1264 | Hardware watchpoints must be reset exactly once after being presented to the | |
1265 | user. It cannot be done sooner, because it would reset the data used to | |
1266 | present the watchpoint hit to the user. And it must not be done later | |
1267 | because it could display the same single watchpoint hit during multiple GDB | |
1268 | stops. Note that the latter is relevant only to the hardware watchpoint | |
1269 | types bp_read_watchpoint and bp_access_watchpoint. False hit by | |
1270 | bp_hardware_watchpoint is not user-visible - its hit is suppressed if the | |
1271 | memory content has not changed. | |
1272 | ||
1273 | The following constraints influence the location where we can reset hardware | |
1274 | watchpoints: | |
1275 | ||
1276 | * target_stopped_by_watchpoint and target_stopped_data_address are called | |
1277 | several times when GDB stops. | |
1278 | ||
1279 | [linux] | |
1280 | * Multiple hardware watchpoints can be hit at the same time, causing GDB to | |
1281 | stop. GDB only presents one hardware watchpoint hit at a time as the | |
1282 | reason for stopping, and all the other hits are presented later, one after | |
1283 | the other, each time the user requests the execution to be resumed. | |
1284 | Execution is not resumed for the threads still having pending hit event | |
1285 | stored in LWP_INFO->STATUS. While the watchpoint is already removed from | |
1286 | the inferior on the first stop the thread hit event is kept being reported | |
1287 | from its cached value by linux_nat_stopped_data_address until the real | |
1288 | thread resume happens after the watchpoint gets presented and thus its | |
1289 | LWP_INFO->STATUS gets reset. | |
1290 | ||
1291 | Therefore the hardware watchpoint hit can get safely reset on the watchpoint | |
1292 | removal from inferior. */ | |
1293 | ||
b40ce68a | 1294 | static void |
a5606eee | 1295 | update_watchpoint (struct breakpoint *b, int reparse) |
7270d8f2 | 1296 | { |
a5606eee | 1297 | int within_current_scope; |
a5606eee VP |
1298 | struct frame_id saved_frame_id; |
1299 | struct bp_location *loc; | |
66076460 | 1300 | int frame_saved; |
a5606eee VP |
1301 | bpstat bs; |
1302 | ||
f6bc2008 PA |
1303 | /* If this is a local watchpoint, we only want to check if the |
1304 | watchpoint frame is in scope if the current thread is the thread | |
1305 | that was used to create the watchpoint. */ | |
1306 | if (!watchpoint_in_thread_scope (b)) | |
1307 | return; | |
1308 | ||
876fa593 | 1309 | /* We don't free locations. They are stored in bp_location array and |
567e1b4e JB |
1310 | update_global_locations will eventually delete them and remove |
1311 | breakpoints if needed. */ | |
a5606eee VP |
1312 | b->loc = NULL; |
1313 | ||
1314 | if (b->disposition == disp_del_at_next_stop) | |
1315 | return; | |
1316 | ||
66076460 | 1317 | frame_saved = 0; |
a5606eee VP |
1318 | |
1319 | /* Determine if the watchpoint is within scope. */ | |
1320 | if (b->exp_valid_block == NULL) | |
1321 | within_current_scope = 1; | |
1322 | else | |
1323 | { | |
1324 | struct frame_info *fi; | |
66076460 DJ |
1325 | |
1326 | /* Save the current frame's ID so we can restore it after | |
1327 | evaluating the watchpoint expression on its own frame. */ | |
1328 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1329 | took a frame parameter, so that we didn't have to change the | |
1330 | selected frame. */ | |
1331 | frame_saved = 1; | |
1332 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1333 | ||
a5606eee VP |
1334 | fi = frame_find_by_id (b->watchpoint_frame); |
1335 | within_current_scope = (fi != NULL); | |
1336 | if (within_current_scope) | |
1337 | select_frame (fi); | |
1338 | } | |
1339 | ||
1340 | if (within_current_scope && reparse) | |
1341 | { | |
1342 | char *s; | |
1343 | if (b->exp) | |
1344 | { | |
1345 | xfree (b->exp); | |
1346 | b->exp = NULL; | |
1347 | } | |
1348 | s = b->exp_string; | |
1349 | b->exp = parse_exp_1 (&s, b->exp_valid_block, 0); | |
1350 | /* If the meaning of expression itself changed, the old value is | |
1351 | no longer relevant. We don't want to report a watchpoint hit | |
1352 | to the user when the old value and the new value may actually | |
1353 | be completely different objects. */ | |
1354 | value_free (b->val); | |
fa4727a6 DJ |
1355 | b->val = NULL; |
1356 | b->val_valid = 0; | |
60e1c644 PA |
1357 | |
1358 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1359 | expression is stored in the breakpoint object, not in the | |
1360 | locations (re)created below. */ | |
1361 | if (b->cond_string != NULL) | |
1362 | { | |
1363 | if (b->cond_exp != NULL) | |
1364 | { | |
1365 | xfree (b->cond_exp); | |
1366 | b->cond_exp = NULL; | |
1367 | } | |
1368 | ||
1369 | s = b->cond_string; | |
1370 | b->cond_exp = parse_exp_1 (&s, b->cond_exp_valid_block, 0); | |
1371 | } | |
a5606eee | 1372 | } |
a5606eee VP |
1373 | |
1374 | /* If we failed to parse the expression, for example because | |
1375 | it refers to a global variable in a not-yet-loaded shared library, | |
1376 | don't try to insert watchpoint. We don't automatically delete | |
1377 | such watchpoint, though, since failure to parse expression | |
1378 | is different from out-of-scope watchpoint. */ | |
2d134ed3 PA |
1379 | if ( !target_has_execution) |
1380 | { | |
1381 | /* Without execution, memory can't change. No use to try and | |
1382 | set watchpoint locations. The watchpoint will be reset when | |
1383 | the target gains execution, through breakpoint_re_set. */ | |
1384 | } | |
1385 | else if (within_current_scope && b->exp) | |
a5606eee | 1386 | { |
fa4727a6 | 1387 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1388 | struct program_space *frame_pspace; |
a5606eee | 1389 | |
fa4727a6 | 1390 | fetch_watchpoint_value (b->exp, &v, &result, &val_chain); |
a5606eee | 1391 | |
a5606eee VP |
1392 | /* Avoid setting b->val if it's already set. The meaning of |
1393 | b->val is 'the last value' user saw, and we should update | |
1394 | it only if we reported that last value to user. As it | |
1395 | happens, the code that reports it updates b->val directly. */ | |
fa4727a6 DJ |
1396 | if (!b->val_valid) |
1397 | { | |
1398 | b->val = v; | |
1399 | b->val_valid = 1; | |
1400 | } | |
a5606eee | 1401 | |
db2ad4c3 JK |
1402 | /* Change the type of breakpoint between hardware assisted or an |
1403 | ordinary watchpoint depending on the hardware support and free | |
1404 | hardware slots. REPARSE is set when the inferior is started. */ | |
1405 | if ((b->type == bp_watchpoint || b->type == bp_hardware_watchpoint) | |
1406 | && reparse) | |
1407 | { | |
ca2d49e8 | 1408 | int i, mem_cnt, other_type_used; |
db2ad4c3 | 1409 | |
7b838ca2 TJB |
1410 | /* We need to determine how many resources are already used |
1411 | for all other hardware watchpoints to see if we still have | |
1412 | enough resources to also fit this watchpoint in as well. | |
1413 | To avoid the hw_watchpoint_used_count call below from counting | |
1414 | this watchpoint, make sure that it is marked as a software | |
1415 | watchpoint. */ | |
1416 | b->type = bp_watchpoint; | |
db2ad4c3 JK |
1417 | i = hw_watchpoint_used_count (bp_hardware_watchpoint, |
1418 | &other_type_used); | |
1419 | mem_cnt = can_use_hardware_watchpoint (val_chain); | |
1420 | ||
ca2d49e8 | 1421 | if (!mem_cnt) |
db2ad4c3 JK |
1422 | b->type = bp_watchpoint; |
1423 | else | |
ca2d49e8 | 1424 | { |
d92524f1 | 1425 | int target_resources_ok = target_can_use_hardware_watchpoint |
ca2d49e8 SL |
1426 | (bp_hardware_watchpoint, i + mem_cnt, other_type_used); |
1427 | if (target_resources_ok <= 0) | |
1428 | b->type = bp_watchpoint; | |
1429 | else | |
1430 | b->type = bp_hardware_watchpoint; | |
1431 | } | |
db2ad4c3 JK |
1432 | } |
1433 | ||
2d134ed3 PA |
1434 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1435 | ||
a5606eee | 1436 | /* Look at each value on the value chain. */ |
fa4727a6 | 1437 | for (v = val_chain; v; v = next) |
a5606eee VP |
1438 | { |
1439 | /* If it's a memory location, and GDB actually needed | |
1440 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1441 | must watch it. If the first value returned is |
1442 | still lazy, that means an error occurred reading it; | |
1443 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1444 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1445 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1446 | { |
1447 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1448 | |
a5606eee VP |
1449 | /* We only watch structs and arrays if user asked |
1450 | for it explicitly, never if they just happen to | |
1451 | appear in the middle of some value chain. */ | |
fa4727a6 | 1452 | if (v == result |
a5606eee VP |
1453 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1454 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1455 | { | |
1456 | CORE_ADDR addr; | |
1457 | int len, type; | |
1458 | struct bp_location *loc, **tmp; | |
1459 | ||
42ae5230 | 1460 | addr = value_address (v); |
a5606eee VP |
1461 | len = TYPE_LENGTH (value_type (v)); |
1462 | type = hw_write; | |
1463 | if (b->type == bp_read_watchpoint) | |
1464 | type = hw_read; | |
1465 | else if (b->type == bp_access_watchpoint) | |
1466 | type = hw_access; | |
1467 | ||
39d61571 | 1468 | loc = allocate_bp_location (b); |
a5606eee VP |
1469 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
1470 | ; | |
1471 | *tmp = loc; | |
a6d9a66e | 1472 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1473 | |
1474 | loc->pspace = frame_pspace; | |
a5606eee VP |
1475 | loc->address = addr; |
1476 | loc->length = len; | |
1477 | loc->watchpoint_type = type; | |
1478 | } | |
1479 | } | |
1480 | ||
1481 | next = value_next (v); | |
1482 | if (v != b->val) | |
1483 | value_free (v); | |
1484 | } | |
1485 | ||
c7437ca6 PA |
1486 | /* If a software watchpoint is not watching any memory, then the |
1487 | above left it without any location set up. But, | |
1488 | bpstat_stop_status requires a location to be able to report | |
1489 | stops, so make sure there's at least a dummy one. */ | |
1490 | if (b->type == bp_watchpoint && b->loc == NULL) | |
1491 | { | |
1492 | b->loc = allocate_bp_location (b); | |
1493 | b->loc->pspace = frame_pspace; | |
1494 | b->loc->address = -1; | |
1495 | b->loc->length = -1; | |
1496 | b->loc->watchpoint_type = -1; | |
1497 | } | |
a5606eee VP |
1498 | } |
1499 | else if (!within_current_scope) | |
7270d8f2 | 1500 | { |
a5606eee | 1501 | printf_filtered (_("\ |
567e1b4e | 1502 | Watchpoint %d deleted because the program has left the block \n\ |
a5606eee VP |
1503 | in which its expression is valid.\n"), |
1504 | b->number); | |
1505 | if (b->related_breakpoint) | |
60e1c644 PA |
1506 | { |
1507 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1508 | b->related_breakpoint->related_breakpoint = NULL; | |
1509 | b->related_breakpoint= NULL; | |
1510 | } | |
a5606eee | 1511 | b->disposition = disp_del_at_next_stop; |
7270d8f2 | 1512 | } |
a5606eee VP |
1513 | |
1514 | /* Restore the selected frame. */ | |
66076460 DJ |
1515 | if (frame_saved) |
1516 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
1517 | } |
1518 | ||
a5606eee | 1519 | |
74960c60 VP |
1520 | /* Returns 1 iff breakpoint location should be |
1521 | inserted in the inferior. */ | |
1522 | static int | |
1523 | should_be_inserted (struct bp_location *bpt) | |
1524 | { | |
1525 | if (!breakpoint_enabled (bpt->owner)) | |
1526 | return 0; | |
1527 | ||
1528 | if (bpt->owner->disposition == disp_del_at_next_stop) | |
1529 | return 0; | |
1530 | ||
1531 | if (!bpt->enabled || bpt->shlib_disabled || bpt->duplicate) | |
1532 | return 0; | |
1533 | ||
56710373 PA |
1534 | /* This is set for example, when we're attached to the parent of a |
1535 | vfork, and have detached from the child. The child is running | |
1536 | free, and we expect it to do an exec or exit, at which point the | |
1537 | OS makes the parent schedulable again (and the target reports | |
1538 | that the vfork is done). Until the child is done with the shared | |
1539 | memory region, do not insert breakpoints in the parent, otherwise | |
1540 | the child could still trip on the parent's breakpoints. Since | |
1541 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
1542 | if (bpt->pspace->breakpoints_not_allowed) | |
1543 | return 0; | |
1544 | ||
1042e4c0 SS |
1545 | /* Tracepoints are inserted by the target at a time of its choosing, |
1546 | not by us. */ | |
7a697b8d | 1547 | if (tracepoint_type (bpt->owner)) |
1042e4c0 SS |
1548 | return 0; |
1549 | ||
74960c60 VP |
1550 | return 1; |
1551 | } | |
1552 | ||
879bfdc2 DJ |
1553 | /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint. |
1554 | Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS, | |
fa3a767f | 1555 | and HW_BREAKPOINT_ERROR are used to report problems. |
879bfdc2 DJ |
1556 | |
1557 | NOTE drow/2003-09-09: This routine could be broken down to an object-style | |
1558 | method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 1559 | static int |
879bfdc2 | 1560 | insert_bp_location (struct bp_location *bpt, |
26bb91f3 | 1561 | struct ui_file *tmp_error_stream, |
fa3a767f | 1562 | int *disabled_breaks, |
26bb91f3 | 1563 | int *hw_breakpoint_error) |
879bfdc2 DJ |
1564 | { |
1565 | int val = 0; | |
1566 | ||
74960c60 | 1567 | if (!should_be_inserted (bpt) || bpt->inserted) |
879bfdc2 DJ |
1568 | return 0; |
1569 | ||
8181d85f DJ |
1570 | /* Initialize the target-specific information. */ |
1571 | memset (&bpt->target_info, 0, sizeof (bpt->target_info)); | |
1572 | bpt->target_info.placed_address = bpt->address; | |
6c95b8df | 1573 | bpt->target_info.placed_address_space = bpt->pspace->aspace; |
8181d85f | 1574 | |
879bfdc2 DJ |
1575 | if (bpt->loc_type == bp_loc_software_breakpoint |
1576 | || bpt->loc_type == bp_loc_hardware_breakpoint) | |
1577 | { | |
765dc015 VP |
1578 | if (bpt->owner->type != bp_hardware_breakpoint) |
1579 | { | |
1580 | /* If the explicitly specified breakpoint type | |
1581 | is not hardware breakpoint, check the memory map to see | |
1582 | if the breakpoint address is in read only memory or not. | |
1583 | Two important cases are: | |
1584 | - location type is not hardware breakpoint, memory | |
1585 | is readonly. We change the type of the location to | |
1586 | hardware breakpoint. | |
1587 | - location type is hardware breakpoint, memory is read-write. | |
1588 | This means we've previously made the location hardware one, but | |
1589 | then the memory map changed, so we undo. | |
1590 | ||
1591 | When breakpoints are removed, remove_breakpoints will | |
1592 | use location types we've just set here, the only possible | |
1593 | problem is that memory map has changed during running program, | |
1594 | but it's not going to work anyway with current gdb. */ | |
1595 | struct mem_region *mr | |
1596 | = lookup_mem_region (bpt->target_info.placed_address); | |
1597 | ||
1598 | if (mr) | |
1599 | { | |
1600 | if (automatic_hardware_breakpoints) | |
1601 | { | |
1602 | int changed = 0; | |
1603 | enum bp_loc_type new_type; | |
1604 | ||
1605 | if (mr->attrib.mode != MEM_RW) | |
1606 | new_type = bp_loc_hardware_breakpoint; | |
1607 | else | |
1608 | new_type = bp_loc_software_breakpoint; | |
1609 | ||
1610 | if (new_type != bpt->loc_type) | |
1611 | { | |
1612 | static int said = 0; | |
1613 | bpt->loc_type = new_type; | |
1614 | if (!said) | |
1615 | { | |
1616 | fprintf_filtered (gdb_stdout, _("\ | |
0767c96d | 1617 | Note: automatically using hardware breakpoints for read-only addresses.\n")); |
765dc015 VP |
1618 | said = 1; |
1619 | } | |
1620 | } | |
1621 | } | |
1622 | else if (bpt->loc_type == bp_loc_software_breakpoint | |
1623 | && mr->attrib.mode != MEM_RW) | |
1624 | warning (_("cannot set software breakpoint at readonly address %s"), | |
5af949e3 | 1625 | paddress (bpt->gdbarch, bpt->address)); |
765dc015 VP |
1626 | } |
1627 | } | |
1628 | ||
879bfdc2 DJ |
1629 | /* First check to see if we have to handle an overlay. */ |
1630 | if (overlay_debugging == ovly_off | |
1631 | || bpt->section == NULL | |
1632 | || !(section_is_overlay (bpt->section))) | |
1633 | { | |
1634 | /* No overlay handling: just set the breakpoint. */ | |
1635 | ||
1636 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
a6d9a66e UW |
1637 | val = target_insert_hw_breakpoint (bpt->gdbarch, |
1638 | &bpt->target_info); | |
879bfdc2 | 1639 | else |
a6d9a66e UW |
1640 | val = target_insert_breakpoint (bpt->gdbarch, |
1641 | &bpt->target_info); | |
879bfdc2 DJ |
1642 | } |
1643 | else | |
1644 | { | |
1645 | /* This breakpoint is in an overlay section. | |
1646 | Shall we set a breakpoint at the LMA? */ | |
1647 | if (!overlay_events_enabled) | |
1648 | { | |
1649 | /* Yes -- overlay event support is not active, | |
1650 | so we must try to set a breakpoint at the LMA. | |
1651 | This will not work for a hardware breakpoint. */ | |
1652 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
8a3fe4f8 | 1653 | warning (_("hardware breakpoint %d not supported in overlay!"), |
879bfdc2 DJ |
1654 | bpt->owner->number); |
1655 | else | |
1656 | { | |
1657 | CORE_ADDR addr = overlay_unmapped_address (bpt->address, | |
1658 | bpt->section); | |
1659 | /* Set a software (trap) breakpoint at the LMA. */ | |
8181d85f DJ |
1660 | bpt->overlay_target_info = bpt->target_info; |
1661 | bpt->overlay_target_info.placed_address = addr; | |
a6d9a66e UW |
1662 | val = target_insert_breakpoint (bpt->gdbarch, |
1663 | &bpt->overlay_target_info); | |
879bfdc2 | 1664 | if (val != 0) |
99361f52 DE |
1665 | fprintf_unfiltered (tmp_error_stream, |
1666 | "Overlay breakpoint %d failed: in ROM?\n", | |
879bfdc2 DJ |
1667 | bpt->owner->number); |
1668 | } | |
1669 | } | |
1670 | /* Shall we set a breakpoint at the VMA? */ | |
1671 | if (section_is_mapped (bpt->section)) | |
1672 | { | |
1673 | /* Yes. This overlay section is mapped into memory. */ | |
1674 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
a6d9a66e UW |
1675 | val = target_insert_hw_breakpoint (bpt->gdbarch, |
1676 | &bpt->target_info); | |
879bfdc2 | 1677 | else |
a6d9a66e UW |
1678 | val = target_insert_breakpoint (bpt->gdbarch, |
1679 | &bpt->target_info); | |
879bfdc2 DJ |
1680 | } |
1681 | else | |
1682 | { | |
1683 | /* No. This breakpoint will not be inserted. | |
1684 | No error, but do not mark the bp as 'inserted'. */ | |
1685 | return 0; | |
1686 | } | |
1687 | } | |
1688 | ||
1689 | if (val) | |
1690 | { | |
1691 | /* Can't set the breakpoint. */ | |
6c95b8df | 1692 | if (solib_name_from_address (bpt->pspace, bpt->address)) |
879bfdc2 DJ |
1693 | { |
1694 | /* See also: disable_breakpoints_in_shlibs. */ | |
1695 | val = 0; | |
0d381245 | 1696 | bpt->shlib_disabled = 1; |
879bfdc2 DJ |
1697 | if (!*disabled_breaks) |
1698 | { | |
1699 | fprintf_unfiltered (tmp_error_stream, | |
1700 | "Cannot insert breakpoint %d.\n", | |
1701 | bpt->owner->number); | |
1702 | fprintf_unfiltered (tmp_error_stream, | |
1703 | "Temporarily disabling shared library breakpoints:\n"); | |
1704 | } | |
1705 | *disabled_breaks = 1; | |
1706 | fprintf_unfiltered (tmp_error_stream, | |
1707 | "breakpoint #%d\n", bpt->owner->number); | |
1708 | } | |
1709 | else | |
879bfdc2 | 1710 | { |
879bfdc2 DJ |
1711 | if (bpt->loc_type == bp_loc_hardware_breakpoint) |
1712 | { | |
1713 | *hw_breakpoint_error = 1; | |
1714 | fprintf_unfiltered (tmp_error_stream, | |
1715 | "Cannot insert hardware breakpoint %d.\n", | |
1716 | bpt->owner->number); | |
1717 | } | |
1718 | else | |
1719 | { | |
1720 | fprintf_unfiltered (tmp_error_stream, | |
1721 | "Cannot insert breakpoint %d.\n", | |
1722 | bpt->owner->number); | |
1723 | fprintf_filtered (tmp_error_stream, | |
1724 | "Error accessing memory address "); | |
5af949e3 UW |
1725 | fputs_filtered (paddress (bpt->gdbarch, bpt->address), |
1726 | tmp_error_stream); | |
879bfdc2 DJ |
1727 | fprintf_filtered (tmp_error_stream, ": %s.\n", |
1728 | safe_strerror (val)); | |
1729 | } | |
1730 | ||
1731 | } | |
1732 | } | |
1733 | else | |
1734 | bpt->inserted = 1; | |
1735 | ||
1736 | return val; | |
1737 | } | |
1738 | ||
1739 | else if (bpt->loc_type == bp_loc_hardware_watchpoint | |
1740 | /* NOTE drow/2003-09-08: This state only exists for removing | |
1741 | watchpoints. It's not clear that it's necessary... */ | |
1742 | && bpt->owner->disposition != disp_del_at_next_stop) | |
1743 | { | |
85d721b8 | 1744 | val = target_insert_watchpoint (bpt->address, |
a5606eee VP |
1745 | bpt->length, |
1746 | bpt->watchpoint_type); | |
85d721b8 PA |
1747 | |
1748 | /* If trying to set a read-watchpoint, and it turns out it's not | |
1749 | supported, try emulating one with an access watchpoint. */ | |
1750 | if (val == 1 && bpt->watchpoint_type == hw_read) | |
1751 | { | |
1752 | struct bp_location *loc, **loc_temp; | |
1753 | ||
1754 | /* But don't try to insert it, if there's already another | |
1755 | hw_access location that would be considered a duplicate | |
1756 | of this one. */ | |
1757 | ALL_BP_LOCATIONS (loc, loc_temp) | |
1758 | if (loc != bpt | |
1759 | && loc->watchpoint_type == hw_access | |
1760 | && watchpoint_locations_match (bpt, loc)) | |
1761 | { | |
1762 | bpt->duplicate = 1; | |
1763 | bpt->inserted = 1; | |
1764 | bpt->target_info = loc->target_info; | |
1765 | bpt->watchpoint_type = hw_access; | |
1766 | val = 0; | |
1767 | break; | |
1768 | } | |
1769 | ||
1770 | if (val == 1) | |
1771 | { | |
1772 | val = target_insert_watchpoint (bpt->address, | |
1773 | bpt->length, | |
1774 | hw_access); | |
1775 | if (val == 0) | |
1776 | bpt->watchpoint_type = hw_access; | |
1777 | } | |
1778 | } | |
1779 | ||
1780 | bpt->inserted = (val == 0); | |
879bfdc2 DJ |
1781 | } |
1782 | ||
fe798b75 | 1783 | else if (bpt->owner->type == bp_catchpoint) |
879bfdc2 | 1784 | { |
71fff37b AC |
1785 | struct gdb_exception e = catch_exception (uiout, insert_catchpoint, |
1786 | bpt->owner, RETURN_MASK_ERROR); | |
9cbc821d AC |
1787 | exception_fprintf (gdb_stderr, e, "warning: inserting catchpoint %d: ", |
1788 | bpt->owner->number); | |
1789 | if (e.reason < 0) | |
879bfdc2 DJ |
1790 | bpt->owner->enable_state = bp_disabled; |
1791 | else | |
1792 | bpt->inserted = 1; | |
1640b821 DJ |
1793 | |
1794 | /* We've already printed an error message if there was a problem | |
1795 | inserting this catchpoint, and we've disabled the catchpoint, | |
1796 | so just return success. */ | |
1797 | return 0; | |
879bfdc2 DJ |
1798 | } |
1799 | ||
1800 | return 0; | |
1801 | } | |
1802 | ||
6c95b8df PA |
1803 | /* This function is called when program space PSPACE is about to be |
1804 | deleted. It takes care of updating breakpoints to not reference | |
1805 | PSPACE anymore. */ | |
1806 | ||
1807 | void | |
1808 | breakpoint_program_space_exit (struct program_space *pspace) | |
1809 | { | |
1810 | struct breakpoint *b, *b_temp; | |
876fa593 | 1811 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
1812 | |
1813 | /* Remove any breakpoint that was set through this program space. */ | |
1814 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
1815 | { | |
1816 | if (b->pspace == pspace) | |
1817 | delete_breakpoint (b); | |
1818 | } | |
1819 | ||
1820 | /* Breakpoints set through other program spaces could have locations | |
1821 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 1822 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
1823 | { |
1824 | struct bp_location *tmp; | |
1825 | ||
1826 | if (loc->pspace == pspace) | |
1827 | { | |
1828 | if (loc->owner->loc == loc) | |
1829 | loc->owner->loc = loc->next; | |
1830 | else | |
1831 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
1832 | if (tmp->next == loc) | |
1833 | { | |
1834 | tmp->next = loc->next; | |
1835 | break; | |
1836 | } | |
1837 | } | |
1838 | } | |
1839 | ||
1840 | /* Now update the global location list to permanently delete the | |
1841 | removed locations above. */ | |
1842 | update_global_location_list (0); | |
1843 | } | |
1844 | ||
74960c60 VP |
1845 | /* Make sure all breakpoints are inserted in inferior. |
1846 | Throws exception on any error. | |
1847 | A breakpoint that is already inserted won't be inserted | |
1848 | again, so calling this function twice is safe. */ | |
1849 | void | |
1850 | insert_breakpoints (void) | |
1851 | { | |
1852 | struct breakpoint *bpt; | |
1853 | ||
1854 | ALL_BREAKPOINTS (bpt) | |
1855 | if (is_hardware_watchpoint (bpt)) | |
1856 | update_watchpoint (bpt, 0 /* don't reparse. */); | |
1857 | ||
b60e7edf | 1858 | update_global_location_list (1); |
74960c60 | 1859 | |
c35b1492 PA |
1860 | /* update_global_location_list does not insert breakpoints when |
1861 | always_inserted_mode is not enabled. Explicitly insert them | |
1862 | now. */ | |
1863 | if (!breakpoints_always_inserted_mode ()) | |
74960c60 VP |
1864 | insert_breakpoint_locations (); |
1865 | } | |
1866 | ||
c906108c SS |
1867 | /* insert_breakpoints is used when starting or continuing the program. |
1868 | remove_breakpoints is used when the program stops. | |
1869 | Both return zero if successful, | |
1870 | or an `errno' value if could not write the inferior. */ | |
1871 | ||
74960c60 VP |
1872 | static void |
1873 | insert_breakpoint_locations (void) | |
c906108c | 1874 | { |
a5606eee | 1875 | struct breakpoint *bpt; |
876fa593 | 1876 | struct bp_location *b, **bp_tmp; |
e236ba44 | 1877 | int error = 0; |
c906108c SS |
1878 | int val = 0; |
1879 | int disabled_breaks = 0; | |
81d0cc19 | 1880 | int hw_breakpoint_error = 0; |
c906108c | 1881 | |
81d0cc19 | 1882 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 1883 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 1884 | |
81d0cc19 GS |
1885 | /* Explicitly mark the warning -- this will only be printed if |
1886 | there was an error. */ | |
1887 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
1888 | |
1889 | save_current_space_and_thread (); | |
1890 | ||
876fa593 | 1891 | ALL_BP_LOCATIONS (b, bp_tmp) |
879bfdc2 | 1892 | { |
6c95b8df PA |
1893 | struct thread_info *tp; |
1894 | CORE_ADDR last_addr; | |
1895 | ||
74960c60 | 1896 | if (!should_be_inserted (b) || b->inserted) |
879bfdc2 DJ |
1897 | continue; |
1898 | ||
f365de73 AS |
1899 | /* There is no point inserting thread-specific breakpoints if the |
1900 | thread no longer exists. */ | |
1901 | if (b->owner->thread != -1 | |
1902 | && !valid_thread_id (b->owner->thread)) | |
1903 | continue; | |
1904 | ||
6c95b8df PA |
1905 | switch_to_program_space_and_thread (b->pspace); |
1906 | ||
1907 | /* For targets that support global breakpoints, there's no need | |
1908 | to select an inferior to insert breakpoint to. In fact, even | |
1909 | if we aren't attached to any process yet, we should still | |
1910 | insert breakpoints. */ | |
1911 | if (!gdbarch_has_global_breakpoints (target_gdbarch) | |
1912 | && ptid_equal (inferior_ptid, null_ptid)) | |
1913 | continue; | |
1914 | ||
879bfdc2 | 1915 | val = insert_bp_location (b, tmp_error_stream, |
fa3a767f | 1916 | &disabled_breaks, |
879bfdc2 DJ |
1917 | &hw_breakpoint_error); |
1918 | if (val) | |
e236ba44 | 1919 | error = val; |
879bfdc2 | 1920 | } |
c906108c | 1921 | |
a5606eee VP |
1922 | /* If we failed to insert all locations of a watchpoint, |
1923 | remove them, as half-inserted watchpoint is of limited use. */ | |
1924 | ALL_BREAKPOINTS (bpt) | |
1925 | { | |
1926 | int some_failed = 0; | |
1927 | struct bp_location *loc; | |
1928 | ||
1929 | if (!is_hardware_watchpoint (bpt)) | |
1930 | continue; | |
1931 | ||
d6b74ac4 | 1932 | if (!breakpoint_enabled (bpt)) |
a5606eee | 1933 | continue; |
74960c60 VP |
1934 | |
1935 | if (bpt->disposition == disp_del_at_next_stop) | |
1936 | continue; | |
a5606eee VP |
1937 | |
1938 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 1939 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
1940 | { |
1941 | some_failed = 1; | |
1942 | break; | |
1943 | } | |
1944 | if (some_failed) | |
1945 | { | |
1946 | for (loc = bpt->loc; loc; loc = loc->next) | |
1947 | if (loc->inserted) | |
1948 | remove_breakpoint (loc, mark_uninserted); | |
1949 | ||
1950 | hw_breakpoint_error = 1; | |
1951 | fprintf_unfiltered (tmp_error_stream, | |
1952 | "Could not insert hardware watchpoint %d.\n", | |
1953 | bpt->number); | |
1954 | error = -1; | |
1955 | } | |
1956 | } | |
1957 | ||
e236ba44 | 1958 | if (error) |
81d0cc19 GS |
1959 | { |
1960 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
1961 | message about possibly exhausted resources. */ | |
879bfdc2 | 1962 | if (hw_breakpoint_error) |
81d0cc19 | 1963 | { |
c6510018 MS |
1964 | fprintf_unfiltered (tmp_error_stream, |
1965 | "Could not insert hardware breakpoints:\n\ | |
1966 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 1967 | } |
81d0cc19 GS |
1968 | target_terminal_ours_for_output (); |
1969 | error_stream (tmp_error_stream); | |
1970 | } | |
f7545552 TT |
1971 | |
1972 | do_cleanups (cleanups); | |
c906108c SS |
1973 | } |
1974 | ||
c906108c | 1975 | int |
fba45db2 | 1976 | remove_breakpoints (void) |
c906108c | 1977 | { |
876fa593 | 1978 | struct bp_location *b, **bp_tmp; |
3a1bae8e | 1979 | int val = 0; |
c906108c | 1980 | |
876fa593 | 1981 | ALL_BP_LOCATIONS (b, bp_tmp) |
c5aa993b | 1982 | { |
0bde7532 | 1983 | if (b->inserted) |
3a1bae8e | 1984 | val |= remove_breakpoint (b, mark_uninserted); |
c5aa993b | 1985 | } |
3a1bae8e | 1986 | return val; |
c906108c SS |
1987 | } |
1988 | ||
6c95b8df PA |
1989 | /* Remove breakpoints of process PID. */ |
1990 | ||
1991 | int | |
1992 | remove_breakpoints_pid (int pid) | |
1993 | { | |
876fa593 | 1994 | struct bp_location *b, **b_tmp; |
6c95b8df PA |
1995 | int val; |
1996 | struct inferior *inf = find_inferior_pid (pid); | |
1997 | ||
876fa593 | 1998 | ALL_BP_LOCATIONS (b, b_tmp) |
6c95b8df PA |
1999 | { |
2000 | if (b->pspace != inf->pspace) | |
2001 | continue; | |
2002 | ||
2003 | if (b->inserted) | |
2004 | { | |
2005 | val = remove_breakpoint (b, mark_uninserted); | |
2006 | if (val != 0) | |
2007 | return val; | |
2008 | } | |
2009 | } | |
2010 | return 0; | |
2011 | } | |
2012 | ||
692590c1 | 2013 | int |
80ce1ecb | 2014 | remove_hw_watchpoints (void) |
692590c1 | 2015 | { |
876fa593 | 2016 | struct bp_location *b, **bp_tmp; |
3a1bae8e | 2017 | int val = 0; |
692590c1 | 2018 | |
876fa593 | 2019 | ALL_BP_LOCATIONS (b, bp_tmp) |
692590c1 | 2020 | { |
0bde7532 | 2021 | if (b->inserted && b->loc_type == bp_loc_hardware_watchpoint) |
3a1bae8e | 2022 | val |= remove_breakpoint (b, mark_uninserted); |
692590c1 | 2023 | } |
3a1bae8e | 2024 | return val; |
692590c1 MS |
2025 | } |
2026 | ||
c906108c | 2027 | int |
fba45db2 | 2028 | reattach_breakpoints (int pid) |
c906108c | 2029 | { |
6c95b8df | 2030 | struct cleanup *old_chain; |
876fa593 | 2031 | struct bp_location *b, **bp_tmp; |
c906108c | 2032 | int val; |
a4954f26 | 2033 | struct ui_file *tmp_error_stream = mem_fileopen (); |
fa3a767f | 2034 | int dummy1 = 0, dummy2 = 0; |
6c95b8df PA |
2035 | struct inferior *inf; |
2036 | struct thread_info *tp; | |
2037 | ||
2038 | tp = any_live_thread_of_process (pid); | |
2039 | if (tp == NULL) | |
2040 | return 1; | |
2041 | ||
2042 | inf = find_inferior_pid (pid); | |
2043 | old_chain = save_inferior_ptid (); | |
2044 | ||
2045 | inferior_ptid = tp->ptid; | |
a4954f26 DJ |
2046 | |
2047 | make_cleanup_ui_file_delete (tmp_error_stream); | |
c906108c | 2048 | |
876fa593 | 2049 | ALL_BP_LOCATIONS (b, bp_tmp) |
c5aa993b | 2050 | { |
6c95b8df PA |
2051 | if (b->pspace != inf->pspace) |
2052 | continue; | |
2053 | ||
0bde7532 | 2054 | if (b->inserted) |
c5aa993b | 2055 | { |
a4954f26 DJ |
2056 | b->inserted = 0; |
2057 | val = insert_bp_location (b, tmp_error_stream, | |
fa3a767f | 2058 | &dummy1, &dummy2); |
c5aa993b JM |
2059 | if (val != 0) |
2060 | { | |
ce696e05 | 2061 | do_cleanups (old_chain); |
c5aa993b JM |
2062 | return val; |
2063 | } | |
2064 | } | |
2065 | } | |
ce696e05 | 2066 | do_cleanups (old_chain); |
c906108c SS |
2067 | return 0; |
2068 | } | |
2069 | ||
e58b0e63 PA |
2070 | static int internal_breakpoint_number = -1; |
2071 | ||
e62c965a | 2072 | static struct breakpoint * |
a6d9a66e UW |
2073 | create_internal_breakpoint (struct gdbarch *gdbarch, |
2074 | CORE_ADDR address, enum bptype type) | |
e62c965a | 2075 | { |
e62c965a PP |
2076 | struct symtab_and_line sal; |
2077 | struct breakpoint *b; | |
2078 | ||
2079 | init_sal (&sal); /* initialize to zeroes */ | |
2080 | ||
2081 | sal.pc = address; | |
2082 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 2083 | sal.pspace = current_program_space; |
e62c965a | 2084 | |
a6d9a66e | 2085 | b = set_raw_breakpoint (gdbarch, sal, type); |
e62c965a PP |
2086 | b->number = internal_breakpoint_number--; |
2087 | b->disposition = disp_donttouch; | |
2088 | ||
2089 | return b; | |
2090 | } | |
2091 | ||
2092 | static void | |
69de3c6a | 2093 | create_overlay_event_breakpoint (char *func_name) |
e62c965a | 2094 | { |
69de3c6a | 2095 | struct objfile *objfile; |
e62c965a | 2096 | |
69de3c6a PP |
2097 | ALL_OBJFILES (objfile) |
2098 | { | |
2099 | struct breakpoint *b; | |
2100 | struct minimal_symbol *m; | |
2101 | ||
2102 | m = lookup_minimal_symbol_text (func_name, objfile); | |
2103 | if (m == NULL) | |
2104 | continue; | |
e62c965a | 2105 | |
a6d9a66e UW |
2106 | b = create_internal_breakpoint (get_objfile_arch (objfile), |
2107 | SYMBOL_VALUE_ADDRESS (m), | |
69de3c6a PP |
2108 | bp_overlay_event); |
2109 | b->addr_string = xstrdup (func_name); | |
e62c965a | 2110 | |
69de3c6a PP |
2111 | if (overlay_debugging == ovly_auto) |
2112 | { | |
2113 | b->enable_state = bp_enabled; | |
2114 | overlay_events_enabled = 1; | |
2115 | } | |
2116 | else | |
2117 | { | |
2118 | b->enable_state = bp_disabled; | |
2119 | overlay_events_enabled = 0; | |
2120 | } | |
e62c965a PP |
2121 | } |
2122 | update_global_location_list (1); | |
2123 | } | |
2124 | ||
0fd8e87f UW |
2125 | static void |
2126 | create_longjmp_master_breakpoint (char *func_name) | |
2127 | { | |
6c95b8df | 2128 | struct program_space *pspace; |
0fd8e87f | 2129 | struct objfile *objfile; |
6c95b8df PA |
2130 | struct cleanup *old_chain; |
2131 | ||
2132 | old_chain = save_current_program_space (); | |
0fd8e87f | 2133 | |
6c95b8df | 2134 | ALL_PSPACES (pspace) |
0fd8e87f UW |
2135 | ALL_OBJFILES (objfile) |
2136 | { | |
2137 | struct breakpoint *b; | |
2138 | struct minimal_symbol *m; | |
2139 | ||
2140 | if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile))) | |
2141 | continue; | |
2142 | ||
6c95b8df PA |
2143 | set_current_program_space (pspace); |
2144 | ||
0fd8e87f UW |
2145 | m = lookup_minimal_symbol_text (func_name, objfile); |
2146 | if (m == NULL) | |
2147 | continue; | |
2148 | ||
a6d9a66e UW |
2149 | b = create_internal_breakpoint (get_objfile_arch (objfile), |
2150 | SYMBOL_VALUE_ADDRESS (m), | |
0fd8e87f UW |
2151 | bp_longjmp_master); |
2152 | b->addr_string = xstrdup (func_name); | |
2153 | b->enable_state = bp_disabled; | |
2154 | } | |
2155 | update_global_location_list (1); | |
6c95b8df PA |
2156 | |
2157 | do_cleanups (old_chain); | |
0fd8e87f UW |
2158 | } |
2159 | ||
aa7d318d TT |
2160 | /* Create a master std::terminate breakpoint. The actual function |
2161 | looked for is named FUNC_NAME. */ | |
2162 | static void | |
2163 | create_std_terminate_master_breakpoint (const char *func_name) | |
2164 | { | |
2165 | struct program_space *pspace; | |
2166 | struct objfile *objfile; | |
2167 | struct cleanup *old_chain; | |
2168 | ||
2169 | old_chain = save_current_program_space (); | |
2170 | ||
2171 | ALL_PSPACES (pspace) | |
2172 | ALL_OBJFILES (objfile) | |
2173 | { | |
2174 | struct breakpoint *b; | |
2175 | struct minimal_symbol *m; | |
2176 | ||
2177 | set_current_program_space (pspace); | |
2178 | ||
2179 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
2180 | if (m == NULL || (MSYMBOL_TYPE (m) != mst_text | |
2181 | && MSYMBOL_TYPE (m) != mst_file_text)) | |
2182 | continue; | |
2183 | ||
2184 | b = create_internal_breakpoint (get_objfile_arch (objfile), | |
2185 | SYMBOL_VALUE_ADDRESS (m), | |
2186 | bp_std_terminate_master); | |
2187 | b->addr_string = xstrdup (func_name); | |
2188 | b->enable_state = bp_disabled; | |
2189 | } | |
2190 | update_global_location_list (1); | |
2191 | ||
2192 | do_cleanups (old_chain); | |
2193 | } | |
2194 | ||
c906108c | 2195 | void |
fba45db2 | 2196 | update_breakpoints_after_exec (void) |
c906108c | 2197 | { |
c5aa993b JM |
2198 | struct breakpoint *b; |
2199 | struct breakpoint *temp; | |
876fa593 | 2200 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 2201 | |
25b22b0a PA |
2202 | /* We're about to delete breakpoints from GDB's lists. If the |
2203 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
2204 | writing the breakpoints' "shadow contents" back into memory. The | |
2205 | "shadow contents" are NOT valid after an exec, so GDB should not | |
2206 | do that. Instead, the target is responsible from marking | |
2207 | breakpoints out as soon as it detects an exec. We don't do that | |
2208 | here instead, because there may be other attempts to delete | |
2209 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 2210 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
2211 | if (bploc->pspace == current_program_space) |
2212 | gdb_assert (!bploc->inserted); | |
c906108c SS |
2213 | |
2214 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b | 2215 | { |
6c95b8df PA |
2216 | if (b->pspace != current_program_space) |
2217 | continue; | |
2218 | ||
c5aa993b JM |
2219 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
2220 | if (b->type == bp_shlib_event) | |
2221 | { | |
2222 | delete_breakpoint (b); | |
2223 | continue; | |
2224 | } | |
c906108c | 2225 | |
4efc6507 DE |
2226 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
2227 | if (b->type == bp_jit_event) | |
2228 | { | |
2229 | delete_breakpoint (b); | |
2230 | continue; | |
2231 | } | |
2232 | ||
1900040c | 2233 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
2234 | as must overlay event and longjmp master breakpoints. */ |
2235 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
aa7d318d | 2236 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master) |
c4093a6a JM |
2237 | { |
2238 | delete_breakpoint (b); | |
2239 | continue; | |
2240 | } | |
2241 | ||
c5aa993b JM |
2242 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2243 | if (b->type == bp_step_resume) | |
2244 | { | |
2245 | delete_breakpoint (b); | |
2246 | continue; | |
2247 | } | |
2248 | ||
611c83ae PA |
2249 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
2250 | after an exec. */ | |
2251 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume) | |
2252 | { | |
2253 | delete_breakpoint (b); | |
2254 | continue; | |
2255 | } | |
2256 | ||
ce78b96d JB |
2257 | if (b->type == bp_catchpoint) |
2258 | { | |
2259 | /* For now, none of the bp_catchpoint breakpoints need to | |
2260 | do anything at this point. In the future, if some of | |
2261 | the catchpoints need to something, we will need to add | |
2262 | a new method, and call this method from here. */ | |
2263 | continue; | |
2264 | } | |
2265 | ||
c5aa993b JM |
2266 | /* bp_finish is a special case. The only way we ought to be able |
2267 | to see one of these when an exec() has happened, is if the user | |
2268 | caught a vfork, and then said "finish". Ordinarily a finish just | |
2269 | carries them to the call-site of the current callee, by setting | |
2270 | a temporary bp there and resuming. But in this case, the finish | |
2271 | will carry them entirely through the vfork & exec. | |
2272 | ||
2273 | We don't want to allow a bp_finish to remain inserted now. But | |
2274 | we can't safely delete it, 'cause finish_command has a handle to | |
2275 | the bp on a bpstat, and will later want to delete it. There's a | |
2276 | chance (and I've seen it happen) that if we delete the bp_finish | |
2277 | here, that its storage will get reused by the time finish_command | |
2278 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
2279 | We really must allow finish_command to delete a bp_finish. | |
2280 | ||
53a5351d JM |
2281 | In the absense of a general solution for the "how do we know |
2282 | it's safe to delete something others may have handles to?" | |
2283 | problem, what we'll do here is just uninsert the bp_finish, and | |
2284 | let finish_command delete it. | |
2285 | ||
2286 | (We know the bp_finish is "doomed" in the sense that it's | |
2287 | momentary, and will be deleted as soon as finish_command sees | |
2288 | the inferior stopped. So it doesn't matter that the bp's | |
2289 | address is probably bogus in the new a.out, unlike e.g., the | |
2290 | solib breakpoints.) */ | |
c5aa993b | 2291 | |
c5aa993b JM |
2292 | if (b->type == bp_finish) |
2293 | { | |
2294 | continue; | |
2295 | } | |
2296 | ||
2297 | /* Without a symbolic address, we have little hope of the | |
2298 | pre-exec() address meaning the same thing in the post-exec() | |
2299 | a.out. */ | |
2300 | if (b->addr_string == NULL) | |
2301 | { | |
2302 | delete_breakpoint (b); | |
2303 | continue; | |
2304 | } | |
c5aa993b | 2305 | } |
1900040c | 2306 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
69de3c6a | 2307 | create_overlay_event_breakpoint ("_ovly_debug_event"); |
0fd8e87f UW |
2308 | create_longjmp_master_breakpoint ("longjmp"); |
2309 | create_longjmp_master_breakpoint ("_longjmp"); | |
2310 | create_longjmp_master_breakpoint ("siglongjmp"); | |
2311 | create_longjmp_master_breakpoint ("_siglongjmp"); | |
aa7d318d | 2312 | create_std_terminate_master_breakpoint ("std::terminate()"); |
c906108c SS |
2313 | } |
2314 | ||
2315 | int | |
fba45db2 | 2316 | detach_breakpoints (int pid) |
c906108c | 2317 | { |
876fa593 | 2318 | struct bp_location *b, **bp_tmp; |
3a1bae8e | 2319 | int val = 0; |
ce696e05 | 2320 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 2321 | struct inferior *inf = current_inferior (); |
c5aa993b | 2322 | |
39f77062 | 2323 | if (pid == PIDGET (inferior_ptid)) |
8a3fe4f8 | 2324 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 2325 | |
6c95b8df | 2326 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
ce696e05 | 2327 | inferior_ptid = pid_to_ptid (pid); |
876fa593 | 2328 | ALL_BP_LOCATIONS (b, bp_tmp) |
c5aa993b | 2329 | { |
6c95b8df PA |
2330 | if (b->pspace != inf->pspace) |
2331 | continue; | |
2332 | ||
0bde7532 | 2333 | if (b->inserted) |
6c95b8df | 2334 | val |= remove_breakpoint_1 (b, mark_inserted); |
c5aa993b | 2335 | } |
ce696e05 | 2336 | do_cleanups (old_chain); |
3a1bae8e | 2337 | return val; |
c906108c SS |
2338 | } |
2339 | ||
6c95b8df PA |
2340 | /* Remove the breakpoint location B from the current address space. |
2341 | Note that this is used to detach breakpoints from a child fork. | |
2342 | When we get here, the child isn't in the inferior list, and neither | |
2343 | do we have objects to represent its address space --- we should | |
2344 | *not* look at b->pspace->aspace here. */ | |
2345 | ||
c906108c | 2346 | static int |
6c95b8df | 2347 | remove_breakpoint_1 (struct bp_location *b, insertion_state_t is) |
c906108c SS |
2348 | { |
2349 | int val; | |
6c95b8df | 2350 | struct cleanup *old_chain; |
c5aa993b | 2351 | |
0bde7532 | 2352 | if (b->owner->enable_state == bp_permanent) |
c2c6d25f JM |
2353 | /* Permanent breakpoints cannot be inserted or removed. */ |
2354 | return 0; | |
2355 | ||
74960c60 VP |
2356 | /* The type of none suggests that owner is actually deleted. |
2357 | This should not ever happen. */ | |
2358 | gdb_assert (b->owner->type != bp_none); | |
0bde7532 DJ |
2359 | |
2360 | if (b->loc_type == bp_loc_software_breakpoint | |
2361 | || b->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 2362 | { |
c02f5703 MS |
2363 | /* "Normal" instruction breakpoint: either the standard |
2364 | trap-instruction bp (bp_breakpoint), or a | |
2365 | bp_hardware_breakpoint. */ | |
2366 | ||
2367 | /* First check to see if we have to handle an overlay. */ | |
2368 | if (overlay_debugging == ovly_off | |
0bde7532 DJ |
2369 | || b->section == NULL |
2370 | || !(section_is_overlay (b->section))) | |
c02f5703 MS |
2371 | { |
2372 | /* No overlay handling: just remove the breakpoint. */ | |
2373 | ||
0bde7532 | 2374 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e | 2375 | val = target_remove_hw_breakpoint (b->gdbarch, &b->target_info); |
c02f5703 | 2376 | else |
a6d9a66e | 2377 | val = target_remove_breakpoint (b->gdbarch, &b->target_info); |
c02f5703 | 2378 | } |
c906108c SS |
2379 | else |
2380 | { | |
c02f5703 MS |
2381 | /* This breakpoint is in an overlay section. |
2382 | Did we set a breakpoint at the LMA? */ | |
2383 | if (!overlay_events_enabled) | |
2384 | { | |
2385 | /* Yes -- overlay event support is not active, so we | |
2386 | should have set a breakpoint at the LMA. Remove it. | |
2387 | */ | |
c02f5703 MS |
2388 | /* Ignore any failures: if the LMA is in ROM, we will |
2389 | have already warned when we failed to insert it. */ | |
0bde7532 | 2390 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e UW |
2391 | target_remove_hw_breakpoint (b->gdbarch, |
2392 | &b->overlay_target_info); | |
c02f5703 | 2393 | else |
a6d9a66e UW |
2394 | target_remove_breakpoint (b->gdbarch, |
2395 | &b->overlay_target_info); | |
c02f5703 MS |
2396 | } |
2397 | /* Did we set a breakpoint at the VMA? | |
2398 | If so, we will have marked the breakpoint 'inserted'. */ | |
0bde7532 | 2399 | if (b->inserted) |
c906108c | 2400 | { |
c02f5703 MS |
2401 | /* Yes -- remove it. Previously we did not bother to |
2402 | remove the breakpoint if the section had been | |
2403 | unmapped, but let's not rely on that being safe. We | |
2404 | don't know what the overlay manager might do. */ | |
0bde7532 | 2405 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e UW |
2406 | val = target_remove_hw_breakpoint (b->gdbarch, |
2407 | &b->target_info); | |
aa67235e UW |
2408 | |
2409 | /* However, we should remove *software* breakpoints only | |
2410 | if the section is still mapped, or else we overwrite | |
2411 | wrong code with the saved shadow contents. */ | |
2412 | else if (section_is_mapped (b->section)) | |
a6d9a66e UW |
2413 | val = target_remove_breakpoint (b->gdbarch, |
2414 | &b->target_info); | |
aa67235e UW |
2415 | else |
2416 | val = 0; | |
c906108c | 2417 | } |
c02f5703 MS |
2418 | else |
2419 | { | |
2420 | /* No -- not inserted, so no need to remove. No error. */ | |
2421 | val = 0; | |
2422 | } | |
c906108c | 2423 | } |
879d1e6b UW |
2424 | |
2425 | /* In some cases, we might not be able to remove a breakpoint | |
2426 | in a shared library that has already been removed, but we | |
2427 | have not yet processed the shlib unload event. */ | |
6c95b8df | 2428 | if (val && solib_name_from_address (b->pspace, b->address)) |
879d1e6b UW |
2429 | val = 0; |
2430 | ||
c906108c SS |
2431 | if (val) |
2432 | return val; | |
0bde7532 | 2433 | b->inserted = (is == mark_inserted); |
c906108c | 2434 | } |
a5606eee | 2435 | else if (b->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 2436 | { |
278cd55f AC |
2437 | struct value *v; |
2438 | struct value *n; | |
c5aa993b | 2439 | |
0bde7532 | 2440 | b->inserted = (is == mark_inserted); |
a5606eee VP |
2441 | val = target_remove_watchpoint (b->address, b->length, |
2442 | b->watchpoint_type); | |
2e70b7b9 | 2443 | |
c906108c | 2444 | /* Failure to remove any of the hardware watchpoints comes here. */ |
0bde7532 | 2445 | if ((is == mark_uninserted) && (b->inserted)) |
8a3fe4f8 | 2446 | warning (_("Could not remove hardware watchpoint %d."), |
0bde7532 | 2447 | b->owner->number); |
c906108c | 2448 | } |
ce78b96d JB |
2449 | else if (b->owner->type == bp_catchpoint |
2450 | && breakpoint_enabled (b->owner) | |
2451 | && !b->duplicate) | |
2452 | { | |
2453 | gdb_assert (b->owner->ops != NULL && b->owner->ops->remove != NULL); | |
2454 | ||
2455 | val = b->owner->ops->remove (b->owner); | |
2456 | if (val) | |
2457 | return val; | |
2458 | b->inserted = (is == mark_inserted); | |
2459 | } | |
c906108c SS |
2460 | |
2461 | return 0; | |
2462 | } | |
2463 | ||
6c95b8df PA |
2464 | static int |
2465 | remove_breakpoint (struct bp_location *b, insertion_state_t is) | |
2466 | { | |
2467 | int ret; | |
2468 | struct cleanup *old_chain; | |
2469 | ||
2470 | if (b->owner->enable_state == bp_permanent) | |
2471 | /* Permanent breakpoints cannot be inserted or removed. */ | |
2472 | return 0; | |
2473 | ||
2474 | /* The type of none suggests that owner is actually deleted. | |
2475 | This should not ever happen. */ | |
2476 | gdb_assert (b->owner->type != bp_none); | |
2477 | ||
2478 | old_chain = save_current_space_and_thread (); | |
2479 | ||
2480 | switch_to_program_space_and_thread (b->pspace); | |
2481 | ||
2482 | ret = remove_breakpoint_1 (b, is); | |
2483 | ||
2484 | do_cleanups (old_chain); | |
2485 | return ret; | |
2486 | } | |
2487 | ||
c906108c SS |
2488 | /* Clear the "inserted" flag in all breakpoints. */ |
2489 | ||
25b22b0a | 2490 | void |
fba45db2 | 2491 | mark_breakpoints_out (void) |
c906108c | 2492 | { |
876fa593 | 2493 | struct bp_location *bpt, **bptp_tmp; |
c906108c | 2494 | |
876fa593 | 2495 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
6c95b8df PA |
2496 | if (bpt->pspace == current_program_space) |
2497 | bpt->inserted = 0; | |
c906108c SS |
2498 | } |
2499 | ||
53a5351d JM |
2500 | /* Clear the "inserted" flag in all breakpoints and delete any |
2501 | breakpoints which should go away between runs of the program. | |
c906108c SS |
2502 | |
2503 | Plus other such housekeeping that has to be done for breakpoints | |
2504 | between runs. | |
2505 | ||
53a5351d JM |
2506 | Note: this function gets called at the end of a run (by |
2507 | generic_mourn_inferior) and when a run begins (by | |
2508 | init_wait_for_inferior). */ | |
c906108c SS |
2509 | |
2510 | ||
2511 | ||
2512 | void | |
fba45db2 | 2513 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 2514 | { |
52f0bd74 | 2515 | struct breakpoint *b, *temp; |
876fa593 | 2516 | struct bp_location *bpt, **bptp_tmp; |
1c5cfe86 | 2517 | int ix; |
6c95b8df | 2518 | struct program_space *pspace = current_program_space; |
c906108c | 2519 | |
50c71eaf PA |
2520 | /* If breakpoint locations are shared across processes, then there's |
2521 | nothing to do. */ | |
2567c7d9 | 2522 | if (gdbarch_has_global_breakpoints (target_gdbarch)) |
50c71eaf PA |
2523 | return; |
2524 | ||
876fa593 | 2525 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
6c95b8df PA |
2526 | { |
2527 | if (bpt->pspace == pspace | |
2528 | && bpt->owner->enable_state != bp_permanent) | |
514f746b | 2529 | bpt->inserted = 0; |
6c95b8df | 2530 | } |
075f6582 | 2531 | |
c906108c | 2532 | ALL_BREAKPOINTS_SAFE (b, temp) |
c5aa993b | 2533 | { |
6c95b8df PA |
2534 | if (b->loc && b->loc->pspace != pspace) |
2535 | continue; | |
2536 | ||
c5aa993b JM |
2537 | switch (b->type) |
2538 | { | |
2539 | case bp_call_dummy: | |
c906108c | 2540 | |
c5aa993b | 2541 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
2542 | cause problems when the inferior is rerun, so we better get |
2543 | rid of it. */ | |
2544 | ||
2545 | case bp_watchpoint_scope: | |
2546 | ||
2547 | /* Also get rid of scope breakpoints. */ | |
2548 | ||
2549 | case bp_shlib_event: | |
2550 | ||
2551 | /* Also remove solib event breakpoints. Their addresses may | |
2552 | have changed since the last time we ran the program. | |
2553 | Actually we may now be debugging against different target; | |
2554 | and so the solib backend that installed this breakpoint may | |
2555 | not be used in by the target. E.g., | |
2556 | ||
2557 | (gdb) file prog-linux | |
2558 | (gdb) run # native linux target | |
2559 | ... | |
2560 | (gdb) kill | |
2561 | (gdb) file prog-win.exe | |
2562 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
2563 | */ | |
c906108c | 2564 | |
c5aa993b JM |
2565 | delete_breakpoint (b); |
2566 | break; | |
c906108c | 2567 | |
c5aa993b JM |
2568 | case bp_watchpoint: |
2569 | case bp_hardware_watchpoint: | |
2570 | case bp_read_watchpoint: | |
2571 | case bp_access_watchpoint: | |
c906108c | 2572 | |
c5aa993b JM |
2573 | /* Likewise for watchpoints on local expressions. */ |
2574 | if (b->exp_valid_block != NULL) | |
2575 | delete_breakpoint (b); | |
967af18d | 2576 | else if (context == inf_starting) |
c860120c PM |
2577 | { |
2578 | /* Reset val field to force reread of starting value | |
2579 | in insert_breakpoints. */ | |
2580 | if (b->val) | |
2581 | value_free (b->val); | |
2582 | b->val = NULL; | |
fa4727a6 | 2583 | b->val_valid = 0; |
c860120c | 2584 | } |
c5aa993b JM |
2585 | break; |
2586 | default: | |
c5aa993b JM |
2587 | break; |
2588 | } | |
2589 | } | |
1c5cfe86 PA |
2590 | |
2591 | /* Get rid of the moribund locations. */ | |
2592 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bpt); ++ix) | |
2593 | free_bp_location (bpt); | |
2594 | VEC_free (bp_location_p, moribund_locations); | |
c906108c SS |
2595 | } |
2596 | ||
6c95b8df PA |
2597 | /* These functions concern about actual breakpoints inserted in the |
2598 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
2599 | we need to hop over the bkpt --- so we check for address space | |
2600 | match, not program space. */ | |
2601 | ||
c2c6d25f JM |
2602 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
2603 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
2604 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
2605 | permanent breakpoint. | |
2606 | - When continuing from a location with an ordinary breakpoint, we | |
2607 | actually single step once before calling insert_breakpoints. | |
2608 | - When continuing from a localion with a permanent breakpoint, we | |
2609 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by | |
2610 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 2611 | |
c2c6d25f | 2612 | enum breakpoint_here |
6c95b8df | 2613 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 2614 | { |
876fa593 | 2615 | struct bp_location *bpt, **bptp_tmp; |
c2c6d25f | 2616 | int any_breakpoint_here = 0; |
c906108c | 2617 | |
876fa593 | 2618 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
075f6582 DJ |
2619 | { |
2620 | if (bpt->loc_type != bp_loc_software_breakpoint | |
2621 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
2622 | continue; | |
2623 | ||
468d015d | 2624 | if ((breakpoint_enabled (bpt->owner) |
075f6582 | 2625 | || bpt->owner->enable_state == bp_permanent) |
6c95b8df PA |
2626 | && breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2627 | aspace, pc)) | |
075f6582 DJ |
2628 | { |
2629 | if (overlay_debugging | |
2630 | && section_is_overlay (bpt->section) | |
2631 | && !section_is_mapped (bpt->section)) | |
2632 | continue; /* unmapped overlay -- can't be a match */ | |
2633 | else if (bpt->owner->enable_state == bp_permanent) | |
2634 | return permanent_breakpoint_here; | |
2635 | else | |
2636 | any_breakpoint_here = 1; | |
2637 | } | |
2638 | } | |
c906108c | 2639 | |
c2c6d25f | 2640 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
2641 | } |
2642 | ||
1c5cfe86 PA |
2643 | /* Return true if there's a moribund breakpoint at PC. */ |
2644 | ||
2645 | int | |
6c95b8df | 2646 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
2647 | { |
2648 | struct bp_location *loc; | |
2649 | int ix; | |
2650 | ||
2651 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
6c95b8df PA |
2652 | if (breakpoint_address_match (loc->pspace->aspace, loc->address, |
2653 | aspace, pc)) | |
1c5cfe86 PA |
2654 | return 1; |
2655 | ||
2656 | return 0; | |
2657 | } | |
c2c6d25f | 2658 | |
c36b740a | 2659 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
876fa593 | 2660 | inserted using regular breakpoint_chain / bp_location array mechanism. |
c36b740a VP |
2661 | This does not check for single-step breakpoints, which are |
2662 | inserted and removed using direct target manipulation. */ | |
c906108c SS |
2663 | |
2664 | int | |
6c95b8df | 2665 | regular_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 2666 | { |
876fa593 | 2667 | struct bp_location *bpt, **bptp_tmp; |
c906108c | 2668 | |
876fa593 | 2669 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
c5aa993b | 2670 | { |
075f6582 DJ |
2671 | if (bpt->loc_type != bp_loc_software_breakpoint |
2672 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
2673 | continue; | |
2674 | ||
2675 | if (bpt->inserted | |
6c95b8df PA |
2676 | && breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2677 | aspace, pc)) | |
075f6582 DJ |
2678 | { |
2679 | if (overlay_debugging | |
2680 | && section_is_overlay (bpt->section) | |
2681 | && !section_is_mapped (bpt->section)) | |
2682 | continue; /* unmapped overlay -- can't be a match */ | |
2683 | else | |
2684 | return 1; | |
2685 | } | |
c5aa993b | 2686 | } |
c36b740a VP |
2687 | return 0; |
2688 | } | |
2689 | ||
2690 | /* Returns non-zero iff there's either regular breakpoint | |
2691 | or a single step breakpoint inserted at PC. */ | |
2692 | ||
2693 | int | |
6c95b8df | 2694 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c36b740a | 2695 | { |
6c95b8df | 2696 | if (regular_breakpoint_inserted_here_p (aspace, pc)) |
c36b740a | 2697 | return 1; |
c906108c | 2698 | |
6c95b8df | 2699 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2700 | return 1; |
2701 | ||
c906108c SS |
2702 | return 0; |
2703 | } | |
2704 | ||
4fa8626c DJ |
2705 | /* This function returns non-zero iff there is a software breakpoint |
2706 | inserted at PC. */ | |
2707 | ||
2708 | int | |
6c95b8df | 2709 | software_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
4fa8626c | 2710 | { |
876fa593 | 2711 | struct bp_location *bpt, **bptp_tmp; |
4fa8626c DJ |
2712 | int any_breakpoint_here = 0; |
2713 | ||
876fa593 | 2714 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
4fa8626c DJ |
2715 | { |
2716 | if (bpt->loc_type != bp_loc_software_breakpoint) | |
2717 | continue; | |
2718 | ||
0d381245 | 2719 | if (bpt->inserted |
6c95b8df PA |
2720 | && breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2721 | aspace, pc)) | |
4fa8626c DJ |
2722 | { |
2723 | if (overlay_debugging | |
2724 | && section_is_overlay (bpt->section) | |
2725 | && !section_is_mapped (bpt->section)) | |
2726 | continue; /* unmapped overlay -- can't be a match */ | |
2727 | else | |
2728 | return 1; | |
2729 | } | |
2730 | } | |
2731 | ||
1aafd4da | 2732 | /* Also check for software single-step breakpoints. */ |
6c95b8df | 2733 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2734 | return 1; |
2735 | ||
4fa8626c DJ |
2736 | return 0; |
2737 | } | |
2738 | ||
9093389c PA |
2739 | int |
2740 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
2741 | CORE_ADDR addr, ULONGEST len) | |
2742 | { | |
2743 | struct breakpoint *bpt; | |
2744 | ||
2745 | ALL_BREAKPOINTS (bpt) | |
2746 | { | |
2747 | struct bp_location *loc; | |
2748 | ||
2749 | if (bpt->type != bp_hardware_watchpoint | |
2750 | && bpt->type != bp_access_watchpoint) | |
2751 | continue; | |
2752 | ||
2753 | if (!breakpoint_enabled (bpt)) | |
2754 | continue; | |
2755 | ||
2756 | for (loc = bpt->loc; loc; loc = loc->next) | |
2757 | if (loc->pspace->aspace == aspace && loc->inserted) | |
2758 | { | |
2759 | CORE_ADDR l, h; | |
2760 | ||
2761 | /* Check for intersection. */ | |
2762 | l = max (loc->address, addr); | |
2763 | h = min (loc->address + loc->length, addr + len); | |
2764 | if (l < h) | |
2765 | return 1; | |
2766 | } | |
2767 | } | |
2768 | return 0; | |
2769 | } | |
2770 | ||
075f6582 DJ |
2771 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
2772 | PC is valid for process/thread PTID. */ | |
c906108c SS |
2773 | |
2774 | int | |
6c95b8df PA |
2775 | breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc, |
2776 | ptid_t ptid) | |
c906108c | 2777 | { |
876fa593 | 2778 | struct bp_location *bpt, **bptp_tmp; |
4a306c9a | 2779 | /* The thread and task IDs associated to PTID, computed lazily. */ |
a6f1cd96 | 2780 | int thread = -1; |
4a306c9a | 2781 | int task = 0; |
a6f1cd96 | 2782 | |
876fa593 | 2783 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
c5aa993b | 2784 | { |
075f6582 DJ |
2785 | if (bpt->loc_type != bp_loc_software_breakpoint |
2786 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
2787 | continue; | |
2788 | ||
a6f1cd96 JB |
2789 | if (!breakpoint_enabled (bpt->owner) |
2790 | && bpt->owner->enable_state != bp_permanent) | |
2791 | continue; | |
2792 | ||
6c95b8df PA |
2793 | if (!breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2794 | aspace, pc)) | |
a6f1cd96 JB |
2795 | continue; |
2796 | ||
2797 | if (bpt->owner->thread != -1) | |
075f6582 | 2798 | { |
a6f1cd96 JB |
2799 | /* This is a thread-specific breakpoint. Check that ptid |
2800 | matches that thread. If thread hasn't been computed yet, | |
2801 | it is now time to do so. */ | |
2802 | if (thread == -1) | |
2803 | thread = pid_to_thread_id (ptid); | |
2804 | if (bpt->owner->thread != thread) | |
2805 | continue; | |
075f6582 | 2806 | } |
a6f1cd96 | 2807 | |
4a306c9a JB |
2808 | if (bpt->owner->task != 0) |
2809 | { | |
2810 | /* This is a task-specific breakpoint. Check that ptid | |
2811 | matches that task. If task hasn't been computed yet, | |
2812 | it is now time to do so. */ | |
2813 | if (task == 0) | |
2814 | task = ada_get_task_number (ptid); | |
2815 | if (bpt->owner->task != task) | |
2816 | continue; | |
2817 | } | |
2818 | ||
a6f1cd96 JB |
2819 | if (overlay_debugging |
2820 | && section_is_overlay (bpt->section) | |
2821 | && !section_is_mapped (bpt->section)) | |
2822 | continue; /* unmapped overlay -- can't be a match */ | |
2823 | ||
2824 | return 1; | |
c5aa993b | 2825 | } |
c906108c SS |
2826 | |
2827 | return 0; | |
2828 | } | |
c906108c | 2829 | \f |
c5aa993b | 2830 | |
c906108c SS |
2831 | /* bpstat stuff. External routines' interfaces are documented |
2832 | in breakpoint.h. */ | |
2833 | ||
2834 | int | |
fba45db2 | 2835 | ep_is_catchpoint (struct breakpoint *ep) |
c906108c | 2836 | { |
533be4dd | 2837 | return (ep->type == bp_catchpoint); |
c906108c SS |
2838 | } |
2839 | ||
198757a8 VP |
2840 | void |
2841 | bpstat_free (bpstat bs) | |
2842 | { | |
2843 | if (bs->old_val != NULL) | |
2844 | value_free (bs->old_val); | |
9add0f1b | 2845 | decref_counted_command_line (&bs->commands); |
198757a8 VP |
2846 | xfree (bs); |
2847 | } | |
2848 | ||
c906108c SS |
2849 | /* Clear a bpstat so that it says we are not at any breakpoint. |
2850 | Also free any storage that is part of a bpstat. */ | |
2851 | ||
2852 | void | |
fba45db2 | 2853 | bpstat_clear (bpstat *bsp) |
c906108c SS |
2854 | { |
2855 | bpstat p; | |
2856 | bpstat q; | |
2857 | ||
2858 | if (bsp == 0) | |
2859 | return; | |
2860 | p = *bsp; | |
2861 | while (p != NULL) | |
2862 | { | |
2863 | q = p->next; | |
198757a8 | 2864 | bpstat_free (p); |
c906108c SS |
2865 | p = q; |
2866 | } | |
2867 | *bsp = NULL; | |
2868 | } | |
2869 | ||
2870 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
2871 | is part of the bpstat is copied as well. */ | |
2872 | ||
2873 | bpstat | |
fba45db2 | 2874 | bpstat_copy (bpstat bs) |
c906108c SS |
2875 | { |
2876 | bpstat p = NULL; | |
2877 | bpstat tmp; | |
2878 | bpstat retval = NULL; | |
2879 | ||
2880 | if (bs == NULL) | |
2881 | return bs; | |
2882 | ||
2883 | for (; bs != NULL; bs = bs->next) | |
2884 | { | |
2885 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
2886 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 2887 | incref_counted_command_line (tmp->commands); |
31cc81e9 | 2888 | if (bs->old_val != NULL) |
3c3185ac JK |
2889 | { |
2890 | tmp->old_val = value_copy (bs->old_val); | |
2891 | release_value (tmp->old_val); | |
2892 | } | |
31cc81e9 | 2893 | |
c906108c SS |
2894 | if (p == NULL) |
2895 | /* This is the first thing in the chain. */ | |
2896 | retval = tmp; | |
2897 | else | |
2898 | p->next = tmp; | |
2899 | p = tmp; | |
2900 | } | |
2901 | p->next = NULL; | |
2902 | return retval; | |
2903 | } | |
2904 | ||
2905 | /* Find the bpstat associated with this breakpoint */ | |
2906 | ||
2907 | bpstat | |
fba45db2 | 2908 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 2909 | { |
c5aa993b JM |
2910 | if (bsp == NULL) |
2911 | return NULL; | |
c906108c | 2912 | |
c5aa993b JM |
2913 | for (; bsp != NULL; bsp = bsp->next) |
2914 | { | |
4f8d1dc6 | 2915 | if (bsp->breakpoint_at && bsp->breakpoint_at->owner == breakpoint) |
c5aa993b JM |
2916 | return bsp; |
2917 | } | |
c906108c SS |
2918 | return NULL; |
2919 | } | |
2920 | ||
2921 | /* Find a step_resume breakpoint associated with this bpstat. | |
2922 | (If there are multiple step_resume bp's on the list, this function | |
2923 | will arbitrarily pick one.) | |
2924 | ||
2925 | It is an error to use this function if BPSTAT doesn't contain a | |
2926 | step_resume breakpoint. | |
2927 | ||
2928 | See wait_for_inferior's use of this function. */ | |
2929 | struct breakpoint * | |
fba45db2 | 2930 | bpstat_find_step_resume_breakpoint (bpstat bsp) |
c906108c | 2931 | { |
8601f500 MS |
2932 | int current_thread; |
2933 | ||
8a3fe4f8 | 2934 | gdb_assert (bsp != NULL); |
c906108c | 2935 | |
8601f500 MS |
2936 | current_thread = pid_to_thread_id (inferior_ptid); |
2937 | ||
c906108c SS |
2938 | for (; bsp != NULL; bsp = bsp->next) |
2939 | { | |
059fb39f PM |
2940 | if ((bsp->breakpoint_at != NULL) |
2941 | && (bsp->breakpoint_at->owner->type == bp_step_resume) | |
2942 | && (bsp->breakpoint_at->owner->thread == current_thread | |
2943 | || bsp->breakpoint_at->owner->thread == -1)) | |
4f8d1dc6 | 2944 | return bsp->breakpoint_at->owner; |
c906108c SS |
2945 | } |
2946 | ||
8a3fe4f8 | 2947 | internal_error (__FILE__, __LINE__, _("No step_resume breakpoint found.")); |
c906108c SS |
2948 | } |
2949 | ||
2950 | ||
8671a17b | 2951 | /* Put in *NUM the breakpoint number of the first breakpoint we are stopped |
c906108c SS |
2952 | at. *BSP upon return is a bpstat which points to the remaining |
2953 | breakpoints stopped at (but which is not guaranteed to be good for | |
2954 | anything but further calls to bpstat_num). | |
8671a17b PA |
2955 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
2956 | Return -1 if stopped at a breakpoint that has been deleted since | |
2957 | we set it. | |
2958 | Return 1 otherwise. */ | |
c906108c SS |
2959 | |
2960 | int | |
8671a17b | 2961 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
2962 | { |
2963 | struct breakpoint *b; | |
2964 | ||
2965 | if ((*bsp) == NULL) | |
2966 | return 0; /* No more breakpoint values */ | |
8671a17b | 2967 | |
4f8d1dc6 VP |
2968 | /* We assume we'll never have several bpstats that |
2969 | correspond to a single breakpoint -- otherwise, | |
2970 | this function might return the same number more | |
2971 | than once and this will look ugly. */ | |
2972 | b = (*bsp)->breakpoint_at ? (*bsp)->breakpoint_at->owner : NULL; | |
8671a17b PA |
2973 | *bsp = (*bsp)->next; |
2974 | if (b == NULL) | |
2975 | return -1; /* breakpoint that's been deleted since */ | |
2976 | ||
2977 | *num = b->number; /* We have its number */ | |
2978 | return 1; | |
c906108c SS |
2979 | } |
2980 | ||
2981 | /* Modify BS so that the actions will not be performed. */ | |
2982 | ||
2983 | void | |
fba45db2 | 2984 | bpstat_clear_actions (bpstat bs) |
c906108c SS |
2985 | { |
2986 | for (; bs != NULL; bs = bs->next) | |
2987 | { | |
9add0f1b | 2988 | decref_counted_command_line (&bs->commands); |
c906108c SS |
2989 | if (bs->old_val != NULL) |
2990 | { | |
2991 | value_free (bs->old_val); | |
2992 | bs->old_val = NULL; | |
2993 | } | |
2994 | } | |
2995 | } | |
2996 | ||
f3b1572e PA |
2997 | /* Called when a command is about to proceed the inferior. */ |
2998 | ||
2999 | static void | |
3000 | breakpoint_about_to_proceed (void) | |
3001 | { | |
3002 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
3003 | { | |
3004 | struct thread_info *tp = inferior_thread (); | |
3005 | ||
3006 | /* Allow inferior function calls in breakpoint commands to not | |
3007 | interrupt the command list. When the call finishes | |
3008 | successfully, the inferior will be standing at the same | |
3009 | breakpoint as if nothing happened. */ | |
3010 | if (tp->in_infcall) | |
3011 | return; | |
3012 | } | |
3013 | ||
3014 | breakpoint_proceeded = 1; | |
3015 | } | |
3016 | ||
c906108c | 3017 | /* Stub for cleaning up our state if we error-out of a breakpoint command */ |
c906108c | 3018 | static void |
4efb68b1 | 3019 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
3020 | { |
3021 | executing_breakpoint_commands = 0; | |
3022 | } | |
3023 | ||
3024 | /* Execute all the commands associated with all the breakpoints at this | |
3025 | location. Any of these commands could cause the process to proceed | |
3026 | beyond this point, etc. We look out for such changes by checking | |
347bddb7 | 3027 | the global "breakpoint_proceeded" after each command. |
c906108c | 3028 | |
347bddb7 PA |
3029 | Returns true if a breakpoint command resumed the inferior. In that |
3030 | case, it is the caller's responsibility to recall it again with the | |
3031 | bpstat of the current thread. */ | |
3032 | ||
3033 | static int | |
3034 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
3035 | { |
3036 | bpstat bs; | |
3037 | struct cleanup *old_chain; | |
347bddb7 | 3038 | int again = 0; |
c906108c SS |
3039 | |
3040 | /* Avoid endless recursion if a `source' command is contained | |
3041 | in bs->commands. */ | |
3042 | if (executing_breakpoint_commands) | |
347bddb7 | 3043 | return 0; |
c906108c SS |
3044 | |
3045 | executing_breakpoint_commands = 1; | |
3046 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
3047 | ||
c906108c SS |
3048 | /* This pointer will iterate over the list of bpstat's. */ |
3049 | bs = *bsp; | |
3050 | ||
3051 | breakpoint_proceeded = 0; | |
3052 | for (; bs != NULL; bs = bs->next) | |
3053 | { | |
9add0f1b | 3054 | struct counted_command_line *ccmd; |
6c50ab1c JB |
3055 | struct command_line *cmd; |
3056 | struct cleanup *this_cmd_tree_chain; | |
3057 | ||
3058 | /* Take ownership of the BSP's command tree, if it has one. | |
3059 | ||
3060 | The command tree could legitimately contain commands like | |
3061 | 'step' and 'next', which call clear_proceed_status, which | |
3062 | frees stop_bpstat's command tree. To make sure this doesn't | |
3063 | free the tree we're executing out from under us, we need to | |
3064 | take ownership of the tree ourselves. Since a given bpstat's | |
3065 | commands are only executed once, we don't need to copy it; we | |
3066 | can clear the pointer in the bpstat, and make sure we free | |
3067 | the tree when we're done. */ | |
9add0f1b TT |
3068 | ccmd = bs->commands; |
3069 | bs->commands = NULL; | |
3070 | this_cmd_tree_chain | |
3071 | = make_cleanup_decref_counted_command_line (&ccmd); | |
3072 | cmd = bs->commands_left; | |
3073 | bs->commands_left = NULL; | |
6c50ab1c | 3074 | |
c906108c SS |
3075 | while (cmd != NULL) |
3076 | { | |
3077 | execute_control_command (cmd); | |
3078 | ||
3079 | if (breakpoint_proceeded) | |
3080 | break; | |
3081 | else | |
3082 | cmd = cmd->next; | |
3083 | } | |
6c50ab1c JB |
3084 | |
3085 | /* We can free this command tree now. */ | |
3086 | do_cleanups (this_cmd_tree_chain); | |
3087 | ||
c906108c | 3088 | if (breakpoint_proceeded) |
32c1e744 VP |
3089 | { |
3090 | if (target_can_async_p ()) | |
347bddb7 PA |
3091 | /* If we are in async mode, then the target might be still |
3092 | running, not stopped at any breakpoint, so nothing for | |
3093 | us to do here -- just return to the event loop. */ | |
3094 | ; | |
32c1e744 VP |
3095 | else |
3096 | /* In sync mode, when execute_control_command returns | |
3097 | we're already standing on the next breakpoint. | |
347bddb7 PA |
3098 | Breakpoint commands for that stop were not run, since |
3099 | execute_command does not run breakpoint commands -- | |
3100 | only command_line_handler does, but that one is not | |
3101 | involved in execution of breakpoint commands. So, we | |
3102 | can now execute breakpoint commands. It should be | |
3103 | noted that making execute_command do bpstat actions is | |
3104 | not an option -- in this case we'll have recursive | |
3105 | invocation of bpstat for each breakpoint with a | |
3106 | command, and can easily blow up GDB stack. Instead, we | |
3107 | return true, which will trigger the caller to recall us | |
3108 | with the new stop_bpstat. */ | |
3109 | again = 1; | |
3110 | break; | |
32c1e744 | 3111 | } |
c906108c | 3112 | } |
c2b8ed2c | 3113 | do_cleanups (old_chain); |
347bddb7 PA |
3114 | return again; |
3115 | } | |
3116 | ||
3117 | void | |
3118 | bpstat_do_actions (void) | |
3119 | { | |
3120 | /* Do any commands attached to breakpoint we are stopped at. */ | |
3121 | while (!ptid_equal (inferior_ptid, null_ptid) | |
3122 | && target_has_execution | |
3123 | && !is_exited (inferior_ptid) | |
3124 | && !is_executing (inferior_ptid)) | |
3125 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
3126 | and only return when it is stopped at the next breakpoint, we | |
3127 | keep doing breakpoint actions until it returns false to | |
3128 | indicate the inferior was not resumed. */ | |
3129 | if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat)) | |
3130 | break; | |
c906108c SS |
3131 | } |
3132 | ||
fa4727a6 DJ |
3133 | /* Print out the (old or new) value associated with a watchpoint. */ |
3134 | ||
3135 | static void | |
3136 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
3137 | { | |
3138 | if (val == NULL) | |
3139 | fprintf_unfiltered (stream, _("<unreadable>")); | |
3140 | else | |
79a45b7d TT |
3141 | { |
3142 | struct value_print_options opts; | |
3143 | get_user_print_options (&opts); | |
3144 | value_print (val, stream, &opts); | |
3145 | } | |
fa4727a6 DJ |
3146 | } |
3147 | ||
e514a9d6 | 3148 | /* This is the normal print function for a bpstat. In the future, |
c906108c | 3149 | much of this logic could (should?) be moved to bpstat_stop_status, |
e514a9d6 JM |
3150 | by having it set different print_it values. |
3151 | ||
3152 | Current scheme: When we stop, bpstat_print() is called. It loops | |
3153 | through the bpstat list of things causing this stop, calling the | |
3154 | print_bp_stop_message function on each one. The behavior of the | |
3155 | print_bp_stop_message function depends on the print_it field of | |
3156 | bpstat. If such field so indicates, call this function here. | |
3157 | ||
3158 | Return values from this routine (ultimately used by bpstat_print() | |
3159 | and normal_stop() to decide what to do): | |
3160 | PRINT_NOTHING: Means we already printed all we needed to print, | |
3161 | don't print anything else. | |
3162 | PRINT_SRC_ONLY: Means we printed something, and we do *not* desire | |
3163 | that something to be followed by a location. | |
3164 | PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire | |
3165 | that something to be followed by a location. | |
3166 | PRINT_UNKNOWN: Means we printed nothing or we need to do some more | |
3167 | analysis. */ | |
c906108c | 3168 | |
917317f4 | 3169 | static enum print_stop_action |
fba45db2 | 3170 | print_it_typical (bpstat bs) |
c906108c | 3171 | { |
f7545552 | 3172 | struct cleanup *old_chain; |
4f8d1dc6 | 3173 | struct breakpoint *b; |
89f9893c | 3174 | const struct bp_location *bl; |
8b93c638 | 3175 | struct ui_stream *stb; |
f7545552 TT |
3176 | int bp_temp = 0; |
3177 | enum print_stop_action result; | |
3178 | ||
c906108c SS |
3179 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
3180 | which has since been deleted. */ | |
e514a9d6 | 3181 | if (bs->breakpoint_at == NULL) |
917317f4 | 3182 | return PRINT_UNKNOWN; |
0d381245 VP |
3183 | bl = bs->breakpoint_at; |
3184 | b = bl->owner; | |
c906108c | 3185 | |
f7545552 TT |
3186 | stb = ui_out_stream_new (uiout); |
3187 | old_chain = make_cleanup_ui_out_stream_delete (stb); | |
3188 | ||
4f8d1dc6 | 3189 | switch (b->type) |
c906108c | 3190 | { |
e514a9d6 JM |
3191 | case bp_breakpoint: |
3192 | case bp_hardware_breakpoint: | |
2cec12e5 | 3193 | bp_temp = bs->breakpoint_at->owner->disposition == disp_del; |
0d381245 VP |
3194 | if (bl->address != bl->requested_address) |
3195 | breakpoint_adjustment_warning (bl->requested_address, | |
3196 | bl->address, | |
4f8d1dc6 VP |
3197 | b->number, 1); |
3198 | annotate_breakpoint (b->number); | |
2cec12e5 AR |
3199 | if (bp_temp) |
3200 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
3201 | else | |
3202 | ui_out_text (uiout, "\nBreakpoint "); | |
9dc5e2a9 | 3203 | if (ui_out_is_mi_like_p (uiout)) |
2cec12e5 AR |
3204 | { |
3205 | ui_out_field_string (uiout, "reason", | |
3206 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
3207 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
3208 | } | |
4f8d1dc6 | 3209 | ui_out_field_int (uiout, "bkptno", b->number); |
8b93c638 | 3210 | ui_out_text (uiout, ", "); |
f7545552 | 3211 | result = PRINT_SRC_AND_LOC; |
e514a9d6 JM |
3212 | break; |
3213 | ||
3214 | case bp_shlib_event: | |
917317f4 JM |
3215 | /* Did we stop because the user set the stop_on_solib_events |
3216 | variable? (If so, we report this as a generic, "Stopped due | |
3217 | to shlib event" message.) */ | |
a3f17187 | 3218 | printf_filtered (_("Stopped due to shared library event\n")); |
f7545552 | 3219 | result = PRINT_NOTHING; |
e514a9d6 JM |
3220 | break; |
3221 | ||
c4093a6a JM |
3222 | case bp_thread_event: |
3223 | /* Not sure how we will get here. | |
3224 | GDB should not stop for these breakpoints. */ | |
a3f17187 | 3225 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 3226 | result = PRINT_NOTHING; |
c4093a6a JM |
3227 | break; |
3228 | ||
1900040c MS |
3229 | case bp_overlay_event: |
3230 | /* By analogy with the thread event, GDB should not stop for these. */ | |
a3f17187 | 3231 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 3232 | result = PRINT_NOTHING; |
1900040c MS |
3233 | break; |
3234 | ||
0fd8e87f UW |
3235 | case bp_longjmp_master: |
3236 | /* These should never be enabled. */ | |
3237 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
3238 | result = PRINT_NOTHING; | |
3239 | break; | |
3240 | ||
aa7d318d TT |
3241 | case bp_std_terminate_master: |
3242 | /* These should never be enabled. */ | |
3243 | printf_filtered (_("std::terminate Master Breakpoint: gdb should not stop!\n")); | |
3244 | result = PRINT_NOTHING; | |
3245 | break; | |
3246 | ||
e514a9d6 JM |
3247 | case bp_watchpoint: |
3248 | case bp_hardware_watchpoint: | |
fa4727a6 DJ |
3249 | annotate_watchpoint (b->number); |
3250 | if (ui_out_is_mi_like_p (uiout)) | |
3251 | ui_out_field_string | |
3252 | (uiout, "reason", | |
3253 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
3254 | mention (b); | |
f7545552 | 3255 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
fa4727a6 DJ |
3256 | ui_out_text (uiout, "\nOld value = "); |
3257 | watchpoint_value_print (bs->old_val, stb->stream); | |
3258 | ui_out_field_stream (uiout, "old", stb); | |
3259 | ui_out_text (uiout, "\nNew value = "); | |
3260 | watchpoint_value_print (b->val, stb->stream); | |
3261 | ui_out_field_stream (uiout, "new", stb); | |
fa4727a6 | 3262 | ui_out_text (uiout, "\n"); |
e514a9d6 | 3263 | /* More than one watchpoint may have been triggered. */ |
f7545552 | 3264 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
3265 | break; |
3266 | ||
3267 | case bp_read_watchpoint: | |
9dc5e2a9 | 3268 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3269 | ui_out_field_string |
3270 | (uiout, "reason", | |
3271 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 3272 | mention (b); |
f7545552 | 3273 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 3274 | ui_out_text (uiout, "\nValue = "); |
fa4727a6 | 3275 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 3276 | ui_out_field_stream (uiout, "value", stb); |
8b93c638 | 3277 | ui_out_text (uiout, "\n"); |
f7545552 | 3278 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
3279 | break; |
3280 | ||
3281 | case bp_access_watchpoint: | |
fa4727a6 | 3282 | if (bs->old_val != NULL) |
8b93c638 | 3283 | { |
4f8d1dc6 | 3284 | annotate_watchpoint (b->number); |
9dc5e2a9 | 3285 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3286 | ui_out_field_string |
3287 | (uiout, "reason", | |
3288 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 3289 | mention (b); |
f7545552 | 3290 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 3291 | ui_out_text (uiout, "\nOld value = "); |
fa4727a6 | 3292 | watchpoint_value_print (bs->old_val, stb->stream); |
8b93c638 | 3293 | ui_out_field_stream (uiout, "old", stb); |
8b93c638 JM |
3294 | ui_out_text (uiout, "\nNew value = "); |
3295 | } | |
3296 | else | |
3297 | { | |
4f8d1dc6 | 3298 | mention (b); |
9dc5e2a9 | 3299 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3300 | ui_out_field_string |
3301 | (uiout, "reason", | |
3302 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
f7545552 | 3303 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 JM |
3304 | ui_out_text (uiout, "\nValue = "); |
3305 | } | |
fa4727a6 | 3306 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 3307 | ui_out_field_stream (uiout, "new", stb); |
8b93c638 | 3308 | ui_out_text (uiout, "\n"); |
f7545552 | 3309 | result = PRINT_UNKNOWN; |
e514a9d6 | 3310 | break; |
4ce44c66 | 3311 | |
e514a9d6 JM |
3312 | /* Fall through, we don't deal with these types of breakpoints |
3313 | here. */ | |
3314 | ||
11cf8741 | 3315 | case bp_finish: |
9dc5e2a9 | 3316 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3317 | ui_out_field_string |
3318 | (uiout, "reason", | |
3319 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
f7545552 | 3320 | result = PRINT_UNKNOWN; |
8b93c638 JM |
3321 | break; |
3322 | ||
e514a9d6 | 3323 | case bp_until: |
9dc5e2a9 | 3324 | if (ui_out_is_mi_like_p (uiout)) |
1fbc2a49 NR |
3325 | ui_out_field_string |
3326 | (uiout, "reason", | |
3327 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
f7545552 | 3328 | result = PRINT_UNKNOWN; |
8b93c638 JM |
3329 | break; |
3330 | ||
c2d11a7d | 3331 | case bp_none: |
e514a9d6 JM |
3332 | case bp_longjmp: |
3333 | case bp_longjmp_resume: | |
3334 | case bp_step_resume: | |
e514a9d6 JM |
3335 | case bp_watchpoint_scope: |
3336 | case bp_call_dummy: | |
aa7d318d | 3337 | case bp_std_terminate: |
1042e4c0 | 3338 | case bp_tracepoint: |
7a697b8d | 3339 | case bp_fast_tracepoint: |
4efc6507 | 3340 | case bp_jit_event: |
e514a9d6 | 3341 | default: |
f7545552 TT |
3342 | result = PRINT_UNKNOWN; |
3343 | break; | |
e514a9d6 | 3344 | } |
f7545552 TT |
3345 | |
3346 | do_cleanups (old_chain); | |
3347 | return result; | |
e514a9d6 JM |
3348 | } |
3349 | ||
3350 | /* Generic routine for printing messages indicating why we | |
3351 | stopped. The behavior of this function depends on the value | |
3352 | 'print_it' in the bpstat structure. Under some circumstances we | |
3353 | may decide not to print anything here and delegate the task to | |
3354 | normal_stop(). */ | |
3355 | ||
3356 | static enum print_stop_action | |
3357 | print_bp_stop_message (bpstat bs) | |
3358 | { | |
3359 | switch (bs->print_it) | |
3360 | { | |
3361 | case print_it_noop: | |
3362 | /* Nothing should be printed for this bpstat entry. */ | |
3363 | return PRINT_UNKNOWN; | |
3364 | break; | |
3365 | ||
3366 | case print_it_done: | |
3367 | /* We still want to print the frame, but we already printed the | |
3368 | relevant messages. */ | |
3369 | return PRINT_SRC_AND_LOC; | |
3370 | break; | |
3371 | ||
3372 | case print_it_normal: | |
4f8d1dc6 | 3373 | { |
89f9893c | 3374 | const struct bp_location *bl = bs->breakpoint_at; |
4f8d1dc6 VP |
3375 | struct breakpoint *b = bl ? bl->owner : NULL; |
3376 | ||
3377 | /* Normal case. Call the breakpoint's print_it method, or | |
3378 | print_it_typical. */ | |
3379 | /* FIXME: how breakpoint can ever be NULL here? */ | |
3380 | if (b != NULL && b->ops != NULL && b->ops->print_it != NULL) | |
3381 | return b->ops->print_it (b); | |
3382 | else | |
3383 | return print_it_typical (bs); | |
3384 | } | |
3385 | break; | |
3086aeae | 3386 | |
e514a9d6 | 3387 | default: |
8e65ff28 | 3388 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 3389 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 3390 | break; |
c906108c | 3391 | } |
c906108c SS |
3392 | } |
3393 | ||
e514a9d6 JM |
3394 | /* Print a message indicating what happened. This is called from |
3395 | normal_stop(). The input to this routine is the head of the bpstat | |
3396 | list - a list of the eventpoints that caused this stop. This | |
3397 | routine calls the generic print routine for printing a message | |
3398 | about reasons for stopping. This will print (for example) the | |
3399 | "Breakpoint n," part of the output. The return value of this | |
3400 | routine is one of: | |
c906108c | 3401 | |
917317f4 JM |
3402 | PRINT_UNKNOWN: Means we printed nothing |
3403 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent | |
c5aa993b JM |
3404 | code to print the location. An example is |
3405 | "Breakpoint 1, " which should be followed by | |
3406 | the location. | |
917317f4 | 3407 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
3408 | to also print the location part of the message. |
3409 | An example is the catch/throw messages, which | |
917317f4 JM |
3410 | don't require a location appended to the end. |
3411 | PRINT_NOTHING: We have done some printing and we don't need any | |
3412 | further info to be printed.*/ | |
c906108c | 3413 | |
917317f4 | 3414 | enum print_stop_action |
fba45db2 | 3415 | bpstat_print (bpstat bs) |
c906108c SS |
3416 | { |
3417 | int val; | |
c5aa993b | 3418 | |
c906108c | 3419 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
3420 | (Currently all watchpoints go on the bpstat whether hit or not. |
3421 | That probably could (should) be changed, provided care is taken | |
c906108c | 3422 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
3423 | for (; bs; bs = bs->next) |
3424 | { | |
3425 | val = print_bp_stop_message (bs); | |
3426 | if (val == PRINT_SRC_ONLY | |
3427 | || val == PRINT_SRC_AND_LOC | |
3428 | || val == PRINT_NOTHING) | |
3429 | return val; | |
3430 | } | |
c906108c | 3431 | |
e514a9d6 JM |
3432 | /* We reached the end of the chain, or we got a null BS to start |
3433 | with and nothing was printed. */ | |
917317f4 | 3434 | return PRINT_UNKNOWN; |
c906108c SS |
3435 | } |
3436 | ||
3437 | /* Evaluate the expression EXP and return 1 if value is zero. | |
3438 | This is used inside a catch_errors to evaluate the breakpoint condition. | |
3439 | The argument is a "struct expression *" that has been cast to char * to | |
3440 | make it pass through catch_errors. */ | |
3441 | ||
3442 | static int | |
4efb68b1 | 3443 | breakpoint_cond_eval (void *exp) |
c906108c | 3444 | { |
278cd55f | 3445 | struct value *mark = value_mark (); |
c5aa993b | 3446 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
c906108c SS |
3447 | value_free_to_mark (mark); |
3448 | return i; | |
3449 | } | |
3450 | ||
3451 | /* Allocate a new bpstat and chain it to the current one. */ | |
3452 | ||
3453 | static bpstat | |
89f9893c | 3454 | bpstat_alloc (const struct bp_location *bl, bpstat cbs /* Current "bs" value */ ) |
c906108c SS |
3455 | { |
3456 | bpstat bs; | |
3457 | ||
3458 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
3459 | cbs->next = bs; | |
4f8d1dc6 | 3460 | bs->breakpoint_at = bl; |
c906108c SS |
3461 | /* If the condition is false, etc., don't do the commands. */ |
3462 | bs->commands = NULL; | |
9add0f1b | 3463 | bs->commands_left = NULL; |
c906108c SS |
3464 | bs->old_val = NULL; |
3465 | bs->print_it = print_it_normal; | |
3466 | return bs; | |
3467 | } | |
3468 | \f | |
d983da9c DJ |
3469 | /* The target has stopped with waitstatus WS. Check if any hardware |
3470 | watchpoints have triggered, according to the target. */ | |
3471 | ||
3472 | int | |
3473 | watchpoints_triggered (struct target_waitstatus *ws) | |
3474 | { | |
d92524f1 | 3475 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
3476 | CORE_ADDR addr; |
3477 | struct breakpoint *b; | |
3478 | ||
3479 | if (!stopped_by_watchpoint) | |
3480 | { | |
3481 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
3482 | as not triggered. */ | |
3483 | ALL_BREAKPOINTS (b) | |
3484 | if (b->type == bp_hardware_watchpoint | |
3485 | || b->type == bp_read_watchpoint | |
3486 | || b->type == bp_access_watchpoint) | |
3487 | b->watchpoint_triggered = watch_triggered_no; | |
3488 | ||
3489 | return 0; | |
3490 | } | |
3491 | ||
3492 | if (!target_stopped_data_address (¤t_target, &addr)) | |
3493 | { | |
3494 | /* We were stopped by a watchpoint, but we don't know where. | |
3495 | Mark all watchpoints as unknown. */ | |
3496 | ALL_BREAKPOINTS (b) | |
3497 | if (b->type == bp_hardware_watchpoint | |
3498 | || b->type == bp_read_watchpoint | |
3499 | || b->type == bp_access_watchpoint) | |
3500 | b->watchpoint_triggered = watch_triggered_unknown; | |
3501 | ||
3502 | return stopped_by_watchpoint; | |
3503 | } | |
3504 | ||
3505 | /* The target could report the data address. Mark watchpoints | |
3506 | affected by this data address as triggered, and all others as not | |
3507 | triggered. */ | |
3508 | ||
3509 | ALL_BREAKPOINTS (b) | |
3510 | if (b->type == bp_hardware_watchpoint | |
3511 | || b->type == bp_read_watchpoint | |
3512 | || b->type == bp_access_watchpoint) | |
3513 | { | |
a5606eee | 3514 | struct bp_location *loc; |
d983da9c DJ |
3515 | struct value *v; |
3516 | ||
3517 | b->watchpoint_triggered = watch_triggered_no; | |
a5606eee VP |
3518 | for (loc = b->loc; loc; loc = loc->next) |
3519 | /* Exact match not required. Within range is | |
3520 | sufficient. */ | |
5009afc5 AS |
3521 | if (target_watchpoint_addr_within_range (¤t_target, |
3522 | addr, loc->address, | |
3523 | loc->length)) | |
a5606eee VP |
3524 | { |
3525 | b->watchpoint_triggered = watch_triggered_yes; | |
3526 | break; | |
3527 | } | |
d983da9c DJ |
3528 | } |
3529 | ||
3530 | return 1; | |
3531 | } | |
3532 | ||
c906108c SS |
3533 | /* Possible return values for watchpoint_check (this can't be an enum |
3534 | because of check_errors). */ | |
3535 | /* The watchpoint has been deleted. */ | |
3536 | #define WP_DELETED 1 | |
3537 | /* The value has changed. */ | |
3538 | #define WP_VALUE_CHANGED 2 | |
3539 | /* The value has not changed. */ | |
3540 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
3541 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
3542 | #define WP_IGNORE 4 | |
c906108c SS |
3543 | |
3544 | #define BP_TEMPFLAG 1 | |
3545 | #define BP_HARDWAREFLAG 2 | |
3546 | ||
553e4c11 JB |
3547 | /* Evaluate watchpoint condition expression and check if its value changed. |
3548 | ||
3549 | P should be a pointer to struct bpstat, but is defined as a void * | |
3550 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
3551 | |
3552 | static int | |
4efb68b1 | 3553 | watchpoint_check (void *p) |
c906108c SS |
3554 | { |
3555 | bpstat bs = (bpstat) p; | |
3556 | struct breakpoint *b; | |
3557 | struct frame_info *fr; | |
3558 | int within_current_scope; | |
3559 | ||
4f8d1dc6 | 3560 | b = bs->breakpoint_at->owner; |
c906108c | 3561 | |
f6bc2008 PA |
3562 | /* If this is a local watchpoint, we only want to check if the |
3563 | watchpoint frame is in scope if the current thread is the thread | |
3564 | that was used to create the watchpoint. */ | |
3565 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 3566 | return WP_IGNORE; |
f6bc2008 | 3567 | |
c906108c SS |
3568 | if (b->exp_valid_block == NULL) |
3569 | within_current_scope = 1; | |
3570 | else | |
3571 | { | |
edb3359d DJ |
3572 | struct frame_info *frame = get_current_frame (); |
3573 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
3574 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
3575 | ||
a0f49112 JK |
3576 | /* in_function_epilogue_p() returns a non-zero value if we're still |
3577 | in the function but the stack frame has already been invalidated. | |
3578 | Since we can't rely on the values of local variables after the | |
3579 | stack has been destroyed, we are treating the watchpoint in that | |
3580 | state as `not changed' without further checking. Don't mark | |
3581 | watchpoints as changed if the current frame is in an epilogue - | |
3582 | even if they are in some other frame, our view of the stack | |
3583 | is likely to be wrong and frame_find_by_id could error out. */ | |
3584 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) | |
60e1c644 | 3585 | return WP_IGNORE; |
a0f49112 | 3586 | |
101dcfbe | 3587 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 3588 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
3589 | |
3590 | /* If we've gotten confused in the unwinder, we might have | |
3591 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
3592 | if (within_current_scope) |
3593 | { | |
3594 | struct symbol *function; | |
3595 | ||
3596 | function = get_frame_function (fr); | |
3597 | if (function == NULL | |
3598 | || !contained_in (b->exp_valid_block, | |
3599 | SYMBOL_BLOCK_VALUE (function))) | |
3600 | within_current_scope = 0; | |
3601 | } | |
69fbadd5 | 3602 | |
edb3359d | 3603 | if (within_current_scope) |
c906108c SS |
3604 | /* If we end up stopping, the current frame will get selected |
3605 | in normal_stop. So this call to select_frame won't affect | |
3606 | the user. */ | |
0f7d239c | 3607 | select_frame (fr); |
c906108c | 3608 | } |
c5aa993b | 3609 | |
c906108c SS |
3610 | if (within_current_scope) |
3611 | { | |
3612 | /* We use value_{,free_to_}mark because it could be a | |
3613 | *long* time before we return to the command level and | |
c5aa993b JM |
3614 | call free_all_values. We can't call free_all_values because |
3615 | we might be in the middle of evaluating a function call. */ | |
c906108c | 3616 | |
278cd55f | 3617 | struct value *mark = value_mark (); |
fa4727a6 DJ |
3618 | struct value *new_val; |
3619 | ||
3620 | fetch_watchpoint_value (b->exp, &new_val, NULL, NULL); | |
218d2fc6 TJB |
3621 | |
3622 | /* We use value_equal_contents instead of value_equal because the latter | |
3623 | coerces an array to a pointer, thus comparing just the address of the | |
3624 | array instead of its contents. This is not what we want. */ | |
fa4727a6 | 3625 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 3626 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 3627 | { |
fa4727a6 DJ |
3628 | if (new_val != NULL) |
3629 | { | |
3630 | release_value (new_val); | |
3631 | value_free_to_mark (mark); | |
3632 | } | |
c906108c SS |
3633 | bs->old_val = b->val; |
3634 | b->val = new_val; | |
fa4727a6 | 3635 | b->val_valid = 1; |
c906108c SS |
3636 | return WP_VALUE_CHANGED; |
3637 | } | |
3638 | else | |
3639 | { | |
60e1c644 | 3640 | /* Nothing changed. */ |
c906108c | 3641 | value_free_to_mark (mark); |
c906108c SS |
3642 | return WP_VALUE_NOT_CHANGED; |
3643 | } | |
3644 | } | |
3645 | else | |
3646 | { | |
3647 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
3648 | if we temporarily ignored the watchpoint, then when |
3649 | we reenter the block in which it is valid it contains | |
3650 | garbage (in the case of a function, it may have two | |
3651 | garbage values, one before and one after the prologue). | |
3652 | So we can't even detect the first assignment to it and | |
3653 | watch after that (since the garbage may or may not equal | |
3654 | the first value assigned). */ | |
4ce44c66 JM |
3655 | /* We print all the stop information in print_it_typical(), but |
3656 | in this case, by the time we call print_it_typical() this bp | |
3657 | will be deleted already. So we have no choice but print the | |
3658 | information here. */ | |
9dc5e2a9 | 3659 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3660 | ui_out_field_string |
3661 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 3662 | ui_out_text (uiout, "\nWatchpoint "); |
4f8d1dc6 | 3663 | ui_out_field_int (uiout, "wpnum", b->number); |
8b93c638 JM |
3664 | ui_out_text (uiout, " deleted because the program has left the block in\n\ |
3665 | which its expression is valid.\n"); | |
4ce44c66 | 3666 | |
c906108c | 3667 | if (b->related_breakpoint) |
60e1c644 PA |
3668 | { |
3669 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
3670 | b->related_breakpoint->related_breakpoint = NULL; | |
3671 | b->related_breakpoint = NULL; | |
3672 | } | |
b5de0fa7 | 3673 | b->disposition = disp_del_at_next_stop; |
c906108c SS |
3674 | |
3675 | return WP_DELETED; | |
3676 | } | |
3677 | } | |
3678 | ||
18a18393 VP |
3679 | /* Return true if it looks like target has stopped due to hitting |
3680 | breakpoint location BL. This function does not check if we | |
3681 | should stop, only if BL explains the stop. */ | |
3682 | static int | |
6c95b8df PA |
3683 | bpstat_check_location (const struct bp_location *bl, |
3684 | struct address_space *aspace, CORE_ADDR bp_addr) | |
18a18393 VP |
3685 | { |
3686 | struct breakpoint *b = bl->owner; | |
3687 | ||
e8595ef6 SS |
3688 | /* By definition, the inferior does not report stops at |
3689 | tracepoints. */ | |
7a697b8d | 3690 | if (tracepoint_type (b)) |
e8595ef6 SS |
3691 | return 0; |
3692 | ||
18a18393 VP |
3693 | if (b->type != bp_watchpoint |
3694 | && b->type != bp_hardware_watchpoint | |
3695 | && b->type != bp_read_watchpoint | |
3696 | && b->type != bp_access_watchpoint | |
3697 | && b->type != bp_hardware_breakpoint | |
fe798b75 | 3698 | && b->type != bp_catchpoint) /* a non-watchpoint bp */ |
18a18393 | 3699 | { |
6c95b8df PA |
3700 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
3701 | aspace, bp_addr)) | |
18a18393 VP |
3702 | return 0; |
3703 | if (overlay_debugging /* unmapped overlay section */ | |
3704 | && section_is_overlay (bl->section) | |
3705 | && !section_is_mapped (bl->section)) | |
3706 | return 0; | |
3707 | } | |
3708 | ||
3709 | /* Continuable hardware watchpoints are treated as non-existent if the | |
3710 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
3711 | some data address). Otherwise gdb won't stop on a break instruction | |
3712 | in the code (not from a breakpoint) when a hardware watchpoint has | |
3713 | been defined. Also skip watchpoints which we know did not trigger | |
3714 | (did not match the data address). */ | |
3715 | ||
3716 | if ((b->type == bp_hardware_watchpoint | |
3717 | || b->type == bp_read_watchpoint | |
3718 | || b->type == bp_access_watchpoint) | |
3719 | && b->watchpoint_triggered == watch_triggered_no) | |
3720 | return 0; | |
3721 | ||
3722 | if (b->type == bp_hardware_breakpoint) | |
3723 | { | |
3724 | if (bl->address != bp_addr) | |
3725 | return 0; | |
3726 | if (overlay_debugging /* unmapped overlay section */ | |
3727 | && section_is_overlay (bl->section) | |
3728 | && !section_is_mapped (bl->section)) | |
3729 | return 0; | |
3730 | } | |
ce78b96d | 3731 | |
ce78b96d JB |
3732 | if (b->type == bp_catchpoint) |
3733 | { | |
3734 | gdb_assert (b->ops != NULL && b->ops->breakpoint_hit != NULL); | |
3735 | if (!b->ops->breakpoint_hit (b)) | |
3736 | return 0; | |
3737 | } | |
3738 | ||
18a18393 VP |
3739 | return 1; |
3740 | } | |
3741 | ||
3742 | /* If BS refers to a watchpoint, determine if the watched values | |
3743 | has actually changed, and we should stop. If not, set BS->stop | |
3744 | to 0. */ | |
3745 | static void | |
3746 | bpstat_check_watchpoint (bpstat bs) | |
3747 | { | |
3748 | const struct bp_location *bl = bs->breakpoint_at; | |
3749 | struct breakpoint *b = bl->owner; | |
3750 | ||
3751 | if (b->type == bp_watchpoint | |
3752 | || b->type == bp_read_watchpoint | |
3753 | || b->type == bp_access_watchpoint | |
3754 | || b->type == bp_hardware_watchpoint) | |
3755 | { | |
3756 | CORE_ADDR addr; | |
3757 | struct value *v; | |
3758 | int must_check_value = 0; | |
3759 | ||
3760 | if (b->type == bp_watchpoint) | |
3761 | /* For a software watchpoint, we must always check the | |
3762 | watched value. */ | |
3763 | must_check_value = 1; | |
3764 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
3765 | /* We have a hardware watchpoint (read, write, or access) | |
3766 | and the target earlier reported an address watched by | |
3767 | this watchpoint. */ | |
3768 | must_check_value = 1; | |
3769 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3770 | && b->type == bp_hardware_watchpoint) | |
3771 | /* We were stopped by a hardware watchpoint, but the target could | |
3772 | not report the data address. We must check the watchpoint's | |
3773 | value. Access and read watchpoints are out of luck; without | |
3774 | a data address, we can't figure it out. */ | |
3775 | must_check_value = 1; | |
3776 | ||
3777 | if (must_check_value) | |
3778 | { | |
3779 | char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3780 | b->number); | |
3781 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
3782 | int e = catch_errors (watchpoint_check, bs, message, | |
3783 | RETURN_MASK_ALL); | |
3784 | do_cleanups (cleanups); | |
3785 | switch (e) | |
3786 | { | |
3787 | case WP_DELETED: | |
3788 | /* We've already printed what needs to be printed. */ | |
3789 | bs->print_it = print_it_done; | |
3790 | /* Stop. */ | |
3791 | break; | |
60e1c644 PA |
3792 | case WP_IGNORE: |
3793 | bs->print_it = print_it_noop; | |
3794 | bs->stop = 0; | |
3795 | break; | |
18a18393 VP |
3796 | case WP_VALUE_CHANGED: |
3797 | if (b->type == bp_read_watchpoint) | |
3798 | { | |
85d721b8 PA |
3799 | /* There are two cases to consider here: |
3800 | ||
3801 | 1. we're watching the triggered memory for reads. | |
3802 | In that case, trust the target, and always report | |
3803 | the watchpoint hit to the user. Even though | |
3804 | reads don't cause value changes, the value may | |
3805 | have changed since the last time it was read, and | |
3806 | since we're not trapping writes, we will not see | |
3807 | those, and as such we should ignore our notion of | |
3808 | old value. | |
3809 | ||
3810 | 2. we're watching the triggered memory for both | |
3811 | reads and writes. There are two ways this may | |
3812 | happen: | |
3813 | ||
3814 | 2.1. this is a target that can't break on data | |
3815 | reads only, but can break on accesses (reads or | |
3816 | writes), such as e.g., x86. We detect this case | |
3817 | at the time we try to insert read watchpoints. | |
3818 | ||
3819 | 2.2. otherwise, the target supports read | |
3820 | watchpoints, but, the user set an access or write | |
3821 | watchpoint watching the same memory as this read | |
3822 | watchpoint. | |
3823 | ||
3824 | If we're watching memory writes as well as reads, | |
3825 | ignore watchpoint hits when we find that the | |
3826 | value hasn't changed, as reads don't cause | |
3827 | changes. This still gives false positives when | |
3828 | the program writes the same value to memory as | |
3829 | what there was already in memory (we will confuse | |
3830 | it for a read), but it's much better than | |
3831 | nothing. */ | |
3832 | ||
3833 | int other_write_watchpoint = 0; | |
3834 | ||
3835 | if (bl->watchpoint_type == hw_read) | |
3836 | { | |
3837 | struct breakpoint *other_b; | |
3838 | ||
3839 | ALL_BREAKPOINTS (other_b) | |
3840 | if ((other_b->type == bp_hardware_watchpoint | |
3841 | || other_b->type == bp_access_watchpoint) | |
3842 | && (other_b->watchpoint_triggered | |
3843 | == watch_triggered_yes)) | |
3844 | { | |
3845 | other_write_watchpoint = 1; | |
3846 | break; | |
3847 | } | |
3848 | } | |
3849 | ||
3850 | if (other_write_watchpoint | |
3851 | || bl->watchpoint_type == hw_access) | |
3852 | { | |
3853 | /* We're watching the same memory for writes, | |
3854 | and the value changed since the last time we | |
3855 | updated it, so this trap must be for a write. | |
3856 | Ignore it. */ | |
3857 | bs->print_it = print_it_noop; | |
3858 | bs->stop = 0; | |
3859 | } | |
18a18393 VP |
3860 | } |
3861 | break; | |
3862 | case WP_VALUE_NOT_CHANGED: | |
3863 | if (b->type == bp_hardware_watchpoint | |
3864 | || b->type == bp_watchpoint) | |
3865 | { | |
3866 | /* Don't stop: write watchpoints shouldn't fire if | |
3867 | the value hasn't changed. */ | |
3868 | bs->print_it = print_it_noop; | |
3869 | bs->stop = 0; | |
3870 | } | |
3871 | /* Stop. */ | |
3872 | break; | |
3873 | default: | |
3874 | /* Can't happen. */ | |
3875 | case 0: | |
3876 | /* Error from catch_errors. */ | |
3877 | printf_filtered (_("Watchpoint %d deleted.\n"), b->number); | |
3878 | if (b->related_breakpoint) | |
3879 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
3880 | b->disposition = disp_del_at_next_stop; | |
3881 | /* We've already printed what needs to be printed. */ | |
3882 | bs->print_it = print_it_done; | |
3883 | break; | |
3884 | } | |
3885 | } | |
3886 | else /* must_check_value == 0 */ | |
3887 | { | |
3888 | /* This is a case where some watchpoint(s) triggered, but | |
3889 | not at the address of this watchpoint, or else no | |
3890 | watchpoint triggered after all. So don't print | |
3891 | anything for this watchpoint. */ | |
3892 | bs->print_it = print_it_noop; | |
3893 | bs->stop = 0; | |
3894 | } | |
3895 | } | |
3896 | } | |
3897 | ||
3898 | ||
3899 | /* Check conditions (condition proper, frame, thread and ignore count) | |
3900 | of breakpoint referred to by BS. If we should not stop for this | |
3901 | breakpoint, set BS->stop to 0. */ | |
3902 | static void | |
3903 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
3904 | { | |
3905 | int thread_id = pid_to_thread_id (ptid); | |
3906 | const struct bp_location *bl = bs->breakpoint_at; | |
3907 | struct breakpoint *b = bl->owner; | |
3908 | ||
3909 | if (frame_id_p (b->frame_id) | |
edb3359d | 3910 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 VP |
3911 | bs->stop = 0; |
3912 | else if (bs->stop) | |
3913 | { | |
3914 | int value_is_zero = 0; | |
60e1c644 PA |
3915 | struct expression *cond; |
3916 | ||
18a18393 VP |
3917 | /* If this is a scope breakpoint, mark the associated |
3918 | watchpoint as triggered so that we will handle the | |
3919 | out-of-scope event. We'll get to the watchpoint next | |
3920 | iteration. */ | |
3921 | if (b->type == bp_watchpoint_scope) | |
3922 | b->related_breakpoint->watchpoint_triggered = watch_triggered_yes; | |
60e1c644 PA |
3923 | |
3924 | if (is_watchpoint (b)) | |
3925 | cond = b->cond_exp; | |
3926 | else | |
3927 | cond = bl->cond; | |
3928 | ||
3929 | if (cond && bl->owner->disposition != disp_del_at_next_stop) | |
18a18393 | 3930 | { |
60e1c644 PA |
3931 | int within_current_scope = 1; |
3932 | ||
c5bc3a77 DJ |
3933 | /* We use value_mark and value_free_to_mark because it could |
3934 | be a long time before we return to the command level and | |
3935 | call free_all_values. We can't call free_all_values | |
3936 | because we might be in the middle of evaluating a | |
3937 | function call. */ | |
3938 | struct value *mark = value_mark (); | |
3939 | ||
edb3359d DJ |
3940 | /* Need to select the frame, with all that implies so that |
3941 | the conditions will have the right context. Because we | |
3942 | use the frame, we will not see an inlined function's | |
3943 | variables when we arrive at a breakpoint at the start | |
3944 | of the inlined function; the current frame will be the | |
3945 | call site. */ | |
60e1c644 PA |
3946 | if (!is_watchpoint (b) || b->cond_exp_valid_block == NULL) |
3947 | select_frame (get_current_frame ()); | |
3948 | else | |
3949 | { | |
3950 | struct frame_info *frame; | |
3951 | ||
3952 | /* For local watchpoint expressions, which particular | |
3953 | instance of a local is being watched matters, so we | |
3954 | keep track of the frame to evaluate the expression | |
3955 | in. To evaluate the condition however, it doesn't | |
3956 | really matter which instantiation of the function | |
3957 | where the condition makes sense triggers the | |
3958 | watchpoint. This allows an expression like "watch | |
3959 | global if q > 10" set in `func', catch writes to | |
3960 | global on all threads that call `func', or catch | |
3961 | writes on all recursive calls of `func' by a single | |
3962 | thread. We simply always evaluate the condition in | |
3963 | the innermost frame that's executing where it makes | |
3964 | sense to evaluate the condition. It seems | |
3965 | intuitive. */ | |
3966 | frame = block_innermost_frame (b->cond_exp_valid_block); | |
3967 | if (frame != NULL) | |
3968 | select_frame (frame); | |
3969 | else | |
3970 | within_current_scope = 0; | |
3971 | } | |
3972 | if (within_current_scope) | |
3973 | value_is_zero | |
3974 | = catch_errors (breakpoint_cond_eval, cond, | |
3975 | "Error in testing breakpoint condition:\n", | |
3976 | RETURN_MASK_ALL); | |
3977 | else | |
3978 | { | |
3979 | warning (_("Watchpoint condition cannot be tested " | |
3980 | "in the current scope")); | |
3981 | /* If we failed to set the right context for this | |
3982 | watchpoint, unconditionally report it. */ | |
3983 | value_is_zero = 0; | |
3984 | } | |
18a18393 | 3985 | /* FIXME-someday, should give breakpoint # */ |
c5bc3a77 | 3986 | value_free_to_mark (mark); |
18a18393 | 3987 | } |
60e1c644 PA |
3988 | |
3989 | if (cond && value_is_zero) | |
18a18393 VP |
3990 | { |
3991 | bs->stop = 0; | |
3992 | } | |
3993 | else if (b->thread != -1 && b->thread != thread_id) | |
3994 | { | |
3995 | bs->stop = 0; | |
3996 | } | |
3997 | else if (b->ignore_count > 0) | |
3998 | { | |
3999 | b->ignore_count--; | |
4000 | annotate_ignore_count_change (); | |
4001 | bs->stop = 0; | |
4002 | /* Increase the hit count even though we don't | |
4003 | stop. */ | |
4004 | ++(b->hit_count); | |
4005 | } | |
4006 | } | |
4007 | } | |
4008 | ||
4009 | ||
9709f61c | 4010 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 4011 | BP_ADDR in thread PTID. |
c906108c | 4012 | |
d983da9c | 4013 | Determine whether we stopped at a breakpoint, etc, or whether we |
c906108c SS |
4014 | don't understand this stop. Result is a chain of bpstat's such that: |
4015 | ||
c5aa993b | 4016 | if we don't understand the stop, the result is a null pointer. |
c906108c | 4017 | |
c5aa993b | 4018 | if we understand why we stopped, the result is not null. |
c906108c | 4019 | |
c5aa993b JM |
4020 | Each element of the chain refers to a particular breakpoint or |
4021 | watchpoint at which we have stopped. (We may have stopped for | |
4022 | several reasons concurrently.) | |
c906108c | 4023 | |
c5aa993b JM |
4024 | Each element of the chain has valid next, breakpoint_at, |
4025 | commands, FIXME??? fields. */ | |
c906108c SS |
4026 | |
4027 | bpstat | |
6c95b8df PA |
4028 | bpstat_stop_status (struct address_space *aspace, |
4029 | CORE_ADDR bp_addr, ptid_t ptid) | |
c906108c | 4030 | { |
0d381245 | 4031 | struct breakpoint *b = NULL; |
876fa593 | 4032 | struct bp_location *bl, **blp_tmp; |
20874c92 | 4033 | struct bp_location *loc; |
c906108c SS |
4034 | /* Root of the chain of bpstat's */ |
4035 | struct bpstats root_bs[1]; | |
4036 | /* Pointer to the last thing in the chain currently. */ | |
4037 | bpstat bs = root_bs; | |
20874c92 | 4038 | int ix; |
429374b8 | 4039 | int need_remove_insert; |
c906108c | 4040 | |
429374b8 JK |
4041 | /* ALL_BP_LOCATIONS iteration would break across |
4042 | update_global_location_list possibly executed by | |
4043 | bpstat_check_breakpoint_conditions's inferior call. */ | |
c5aa993b | 4044 | |
429374b8 JK |
4045 | ALL_BREAKPOINTS (b) |
4046 | { | |
4047 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) | |
4048 | continue; | |
a5606eee | 4049 | |
429374b8 JK |
4050 | for (bl = b->loc; bl != NULL; bl = bl->next) |
4051 | { | |
4052 | /* For hardware watchpoints, we look only at the first location. | |
4053 | The watchpoint_check function will work on entire expression, | |
4054 | not the individual locations. For read watchopints, the | |
4055 | watchpoints_triggered function have checked all locations | |
4056 | already. */ | |
4057 | if (b->type == bp_hardware_watchpoint && bl != b->loc) | |
4058 | break; | |
18a18393 | 4059 | |
429374b8 JK |
4060 | if (bl->shlib_disabled) |
4061 | continue; | |
c5aa993b | 4062 | |
429374b8 JK |
4063 | if (!bpstat_check_location (bl, aspace, bp_addr)) |
4064 | continue; | |
c5aa993b | 4065 | |
429374b8 | 4066 | /* Come here if it's a watchpoint, or if the break address matches */ |
c5aa993b | 4067 | |
429374b8 | 4068 | bs = bpstat_alloc (bl, bs); /* Alloc a bpstat to explain stop */ |
c5aa993b | 4069 | |
429374b8 JK |
4070 | /* Assume we stop. Should we find watchpoint that is not actually |
4071 | triggered, or if condition of breakpoint is false, we'll reset | |
4072 | 'stop' to 0. */ | |
4073 | bs->stop = 1; | |
4074 | bs->print = 1; | |
d983da9c | 4075 | |
429374b8 JK |
4076 | bpstat_check_watchpoint (bs); |
4077 | if (!bs->stop) | |
4078 | continue; | |
18a18393 | 4079 | |
429374b8 | 4080 | if (b->type == bp_thread_event || b->type == bp_overlay_event |
aa7d318d TT |
4081 | || b->type == bp_longjmp_master |
4082 | || b->type == bp_std_terminate_master) | |
429374b8 JK |
4083 | /* We do not stop for these. */ |
4084 | bs->stop = 0; | |
4085 | else | |
4086 | bpstat_check_breakpoint_conditions (bs, ptid); | |
4087 | ||
4088 | if (bs->stop) | |
4089 | { | |
4090 | ++(b->hit_count); | |
c906108c | 4091 | |
429374b8 JK |
4092 | /* We will stop here */ |
4093 | if (b->disposition == disp_disable) | |
4094 | { | |
4095 | if (b->enable_state != bp_permanent) | |
4096 | b->enable_state = bp_disabled; | |
4097 | update_global_location_list (0); | |
4098 | } | |
4099 | if (b->silent) | |
4100 | bs->print = 0; | |
4101 | bs->commands = b->commands; | |
9add0f1b TT |
4102 | incref_counted_command_line (bs->commands); |
4103 | bs->commands_left = bs->commands ? bs->commands->commands : NULL; | |
4104 | if (bs->commands_left | |
4105 | && (strcmp ("silent", bs->commands_left->line) == 0 | |
4106 | || (xdb_commands | |
4107 | && strcmp ("Q", | |
4108 | bs->commands_left->line) == 0))) | |
429374b8 | 4109 | { |
9add0f1b | 4110 | bs->commands_left = bs->commands_left->next; |
429374b8 JK |
4111 | bs->print = 0; |
4112 | } | |
429374b8 JK |
4113 | } |
4114 | ||
4115 | /* Print nothing for this entry if we dont stop or dont print. */ | |
4116 | if (bs->stop == 0 || bs->print == 0) | |
4117 | bs->print_it = print_it_noop; | |
4118 | } | |
4119 | } | |
876fa593 | 4120 | |
20874c92 VP |
4121 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
4122 | { | |
6c95b8df PA |
4123 | if (breakpoint_address_match (loc->pspace->aspace, loc->address, |
4124 | aspace, bp_addr)) | |
20874c92 VP |
4125 | { |
4126 | bs = bpstat_alloc (loc, bs); | |
4127 | /* For hits of moribund locations, we should just proceed. */ | |
4128 | bs->stop = 0; | |
4129 | bs->print = 0; | |
4130 | bs->print_it = print_it_noop; | |
4131 | } | |
4132 | } | |
4133 | ||
c906108c | 4134 | bs->next = NULL; /* Terminate the chain */ |
c906108c | 4135 | |
d983da9c DJ |
4136 | /* If we aren't stopping, the value of some hardware watchpoint may |
4137 | not have changed, but the intermediate memory locations we are | |
4138 | watching may have. Don't bother if we're stopping; this will get | |
4139 | done later. */ | |
4140 | for (bs = root_bs->next; bs != NULL; bs = bs->next) | |
4141 | if (bs->stop) | |
4142 | break; | |
4143 | ||
d832cb68 | 4144 | need_remove_insert = 0; |
d983da9c DJ |
4145 | if (bs == NULL) |
4146 | for (bs = root_bs->next; bs != NULL; bs = bs->next) | |
4147 | if (!bs->stop | |
20874c92 | 4148 | && bs->breakpoint_at->owner |
2d134ed3 | 4149 | && is_hardware_watchpoint (bs->breakpoint_at->owner)) |
d983da9c | 4150 | { |
2d134ed3 PA |
4151 | update_watchpoint (bs->breakpoint_at->owner, 0 /* don't reparse. */); |
4152 | /* Updating watchpoints invalidates bs->breakpoint_at. | |
4153 | Prevent further code from trying to use it. */ | |
a5606eee | 4154 | bs->breakpoint_at = NULL; |
d832cb68 | 4155 | need_remove_insert = 1; |
d983da9c DJ |
4156 | } |
4157 | ||
d832cb68 | 4158 | if (need_remove_insert) |
2d134ed3 | 4159 | update_global_location_list (1); |
d832cb68 | 4160 | |
d983da9c | 4161 | return root_bs->next; |
c906108c SS |
4162 | } |
4163 | \f | |
4164 | /* Tell what to do about this bpstat. */ | |
4165 | struct bpstat_what | |
fba45db2 | 4166 | bpstat_what (bpstat bs) |
c906108c SS |
4167 | { |
4168 | /* Classify each bpstat as one of the following. */ | |
c5aa993b JM |
4169 | enum class |
4170 | { | |
4171 | /* This bpstat element has no effect on the main_action. */ | |
4172 | no_effect = 0, | |
4173 | ||
4174 | /* There was a watchpoint, stop but don't print. */ | |
4175 | wp_silent, | |
c906108c | 4176 | |
c5aa993b JM |
4177 | /* There was a watchpoint, stop and print. */ |
4178 | wp_noisy, | |
c906108c | 4179 | |
c5aa993b JM |
4180 | /* There was a breakpoint but we're not stopping. */ |
4181 | bp_nostop, | |
c906108c | 4182 | |
c5aa993b JM |
4183 | /* There was a breakpoint, stop but don't print. */ |
4184 | bp_silent, | |
c906108c | 4185 | |
c5aa993b JM |
4186 | /* There was a breakpoint, stop and print. */ |
4187 | bp_noisy, | |
c906108c | 4188 | |
c5aa993b JM |
4189 | /* We hit the longjmp breakpoint. */ |
4190 | long_jump, | |
c906108c | 4191 | |
c5aa993b JM |
4192 | /* We hit the longjmp_resume breakpoint. */ |
4193 | long_resume, | |
c906108c | 4194 | |
c5aa993b JM |
4195 | /* We hit the step_resume breakpoint. */ |
4196 | step_resume, | |
c906108c | 4197 | |
c5aa993b JM |
4198 | /* We hit the shared library event breakpoint. */ |
4199 | shlib_event, | |
c906108c | 4200 | |
4efc6507 DE |
4201 | /* We hit the jit event breakpoint. */ |
4202 | jit_event, | |
4203 | ||
c5aa993b JM |
4204 | /* This is just used to count how many enums there are. */ |
4205 | class_last | |
c906108c SS |
4206 | }; |
4207 | ||
4208 | /* Here is the table which drives this routine. So that we can | |
4209 | format it pretty, we define some abbreviations for the | |
4210 | enum bpstat_what codes. */ | |
4211 | #define kc BPSTAT_WHAT_KEEP_CHECKING | |
4212 | #define ss BPSTAT_WHAT_STOP_SILENT | |
4213 | #define sn BPSTAT_WHAT_STOP_NOISY | |
4214 | #define sgl BPSTAT_WHAT_SINGLE | |
4215 | #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME | |
4216 | #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME | |
c906108c | 4217 | #define sr BPSTAT_WHAT_STEP_RESUME |
c906108c | 4218 | #define shl BPSTAT_WHAT_CHECK_SHLIBS |
4efc6507 | 4219 | #define jit BPSTAT_WHAT_CHECK_JIT |
c906108c SS |
4220 | |
4221 | /* "Can't happen." Might want to print an error message. | |
4222 | abort() is not out of the question, but chances are GDB is just | |
4223 | a bit confused, not unusable. */ | |
4224 | #define err BPSTAT_WHAT_STOP_NOISY | |
4225 | ||
4226 | /* Given an old action and a class, come up with a new action. */ | |
4227 | /* One interesting property of this table is that wp_silent is the same | |
4228 | as bp_silent and wp_noisy is the same as bp_noisy. That is because | |
4229 | after stopping, the check for whether to step over a breakpoint | |
4230 | (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without | |
53a5351d JM |
4231 | reference to how we stopped. We retain separate wp_silent and |
4232 | bp_silent codes in case we want to change that someday. | |
43ff13b4 JM |
4233 | |
4234 | Another possibly interesting property of this table is that | |
4235 | there's a partial ordering, priority-like, of the actions. Once | |
4236 | you've decided that some action is appropriate, you'll never go | |
4237 | back and decide something of a lower priority is better. The | |
4238 | ordering is: | |
4239 | ||
4efc6507 DE |
4240 | kc < jit clr sgl shl slr sn sr ss |
4241 | sgl < jit shl slr sn sr ss | |
4242 | slr < jit err shl sn sr ss | |
4243 | clr < jit err shl sn sr ss | |
4244 | ss < jit shl sn sr | |
4245 | sn < jit shl sr | |
4246 | jit < shl sr | |
d81191fc | 4247 | shl < sr |
4d5b2cd7 | 4248 | sr < |
c5aa993b | 4249 | |
43ff13b4 JM |
4250 | What I think this means is that we don't need a damned table |
4251 | here. If you just put the rows and columns in the right order, | |
4252 | it'd look awfully regular. We could simply walk the bpstat list | |
4253 | and choose the highest priority action we find, with a little | |
78b6a731 | 4254 | logic to handle the 'err' cases. */ |
c906108c SS |
4255 | |
4256 | /* step_resume entries: a step resume breakpoint overrides another | |
4257 | breakpoint of signal handling (see comment in wait_for_inferior | |
fcf70625 | 4258 | at where we set the step_resume breakpoint). */ |
c906108c SS |
4259 | |
4260 | static const enum bpstat_what_main_action | |
c5aa993b JM |
4261 | table[(int) class_last][(int) BPSTAT_WHAT_LAST] = |
4262 | { | |
4263 | /* old action */ | |
4efc6507 DE |
4264 | /* kc ss sn sgl slr clr sr shl jit */ |
4265 | /* no_effect */ {kc, ss, sn, sgl, slr, clr, sr, shl, jit}, | |
4266 | /* wp_silent */ {ss, ss, sn, ss, ss, ss, sr, shl, jit}, | |
4267 | /* wp_noisy */ {sn, sn, sn, sn, sn, sn, sr, shl, jit}, | |
4268 | /* bp_nostop */ {sgl, ss, sn, sgl, slr, slr, sr, shl, jit}, | |
4269 | /* bp_silent */ {ss, ss, sn, ss, ss, ss, sr, shl, jit}, | |
4270 | /* bp_noisy */ {sn, sn, sn, sn, sn, sn, sr, shl, jit}, | |
4271 | /* long_jump */ {slr, ss, sn, slr, slr, err, sr, shl, jit}, | |
4272 | /* long_resume */ {clr, ss, sn, err, err, err, sr, shl, jit}, | |
4273 | /* step_resume */ {sr, sr, sr, sr, sr, sr, sr, sr, sr }, | |
4274 | /* shlib */ {shl, shl, shl, shl, shl, shl, sr, shl, shl}, | |
4275 | /* jit_event */ {jit, jit, jit, jit, jit, jit, sr, jit, jit} | |
c5aa993b | 4276 | }; |
c906108c SS |
4277 | |
4278 | #undef kc | |
4279 | #undef ss | |
4280 | #undef sn | |
4281 | #undef sgl | |
4282 | #undef slr | |
4283 | #undef clr | |
c906108c SS |
4284 | #undef err |
4285 | #undef sr | |
4286 | #undef ts | |
4287 | #undef shl | |
4efc6507 | 4288 | #undef jit |
c906108c SS |
4289 | enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING; |
4290 | struct bpstat_what retval; | |
4291 | ||
aa7d318d | 4292 | retval.call_dummy = STOP_NONE; |
c906108c SS |
4293 | for (; bs != NULL; bs = bs->next) |
4294 | { | |
4295 | enum class bs_class = no_effect; | |
4296 | if (bs->breakpoint_at == NULL) | |
4297 | /* I suspect this can happen if it was a momentary breakpoint | |
4298 | which has since been deleted. */ | |
4299 | continue; | |
20874c92 VP |
4300 | if (bs->breakpoint_at->owner == NULL) |
4301 | bs_class = bp_nostop; | |
4302 | else | |
4f8d1dc6 | 4303 | switch (bs->breakpoint_at->owner->type) |
c906108c SS |
4304 | { |
4305 | case bp_none: | |
4306 | continue; | |
4307 | ||
4308 | case bp_breakpoint: | |
4309 | case bp_hardware_breakpoint: | |
4310 | case bp_until: | |
4311 | case bp_finish: | |
4312 | if (bs->stop) | |
4313 | { | |
4314 | if (bs->print) | |
4315 | bs_class = bp_noisy; | |
4316 | else | |
4317 | bs_class = bp_silent; | |
4318 | } | |
4319 | else | |
4320 | bs_class = bp_nostop; | |
4321 | break; | |
4322 | case bp_watchpoint: | |
4323 | case bp_hardware_watchpoint: | |
4324 | case bp_read_watchpoint: | |
4325 | case bp_access_watchpoint: | |
4326 | if (bs->stop) | |
4327 | { | |
4328 | if (bs->print) | |
4329 | bs_class = wp_noisy; | |
4330 | else | |
4331 | bs_class = wp_silent; | |
4332 | } | |
4333 | else | |
53a5351d JM |
4334 | /* There was a watchpoint, but we're not stopping. |
4335 | This requires no further action. */ | |
c906108c SS |
4336 | bs_class = no_effect; |
4337 | break; | |
4338 | case bp_longjmp: | |
4339 | bs_class = long_jump; | |
4340 | break; | |
4341 | case bp_longjmp_resume: | |
4342 | bs_class = long_resume; | |
4343 | break; | |
4344 | case bp_step_resume: | |
4345 | if (bs->stop) | |
4346 | { | |
4347 | bs_class = step_resume; | |
4348 | } | |
4349 | else | |
4350 | /* It is for the wrong frame. */ | |
4351 | bs_class = bp_nostop; | |
4352 | break; | |
c906108c SS |
4353 | case bp_watchpoint_scope: |
4354 | bs_class = bp_nostop; | |
4355 | break; | |
c5aa993b JM |
4356 | case bp_shlib_event: |
4357 | bs_class = shlib_event; | |
4358 | break; | |
4efc6507 DE |
4359 | case bp_jit_event: |
4360 | bs_class = jit_event; | |
4361 | break; | |
c4093a6a | 4362 | case bp_thread_event: |
1900040c | 4363 | case bp_overlay_event: |
0fd8e87f | 4364 | case bp_longjmp_master: |
aa7d318d | 4365 | case bp_std_terminate_master: |
c4093a6a JM |
4366 | bs_class = bp_nostop; |
4367 | break; | |
ce78b96d | 4368 | case bp_catchpoint: |
c5aa993b JM |
4369 | if (bs->stop) |
4370 | { | |
4371 | if (bs->print) | |
4372 | bs_class = bp_noisy; | |
4373 | else | |
4374 | bs_class = bp_silent; | |
4375 | } | |
4376 | else | |
53a5351d JM |
4377 | /* There was a catchpoint, but we're not stopping. |
4378 | This requires no further action. */ | |
c5aa993b JM |
4379 | bs_class = no_effect; |
4380 | break; | |
c906108c | 4381 | case bp_call_dummy: |
53a5351d JM |
4382 | /* Make sure the action is stop (silent or noisy), |
4383 | so infrun.c pops the dummy frame. */ | |
c906108c | 4384 | bs_class = bp_silent; |
aa7d318d TT |
4385 | retval.call_dummy = STOP_STACK_DUMMY; |
4386 | break; | |
4387 | case bp_std_terminate: | |
4388 | /* Make sure the action is stop (silent or noisy), | |
4389 | so infrun.c pops the dummy frame. */ | |
4390 | bs_class = bp_silent; | |
4391 | retval.call_dummy = STOP_STD_TERMINATE; | |
c906108c | 4392 | break; |
1042e4c0 | 4393 | case bp_tracepoint: |
7a697b8d | 4394 | case bp_fast_tracepoint: |
1042e4c0 SS |
4395 | /* Tracepoint hits should not be reported back to GDB, and |
4396 | if one got through somehow, it should have been filtered | |
4397 | out already. */ | |
4398 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 4399 | _("bpstat_what: tracepoint encountered")); |
1042e4c0 | 4400 | break; |
c906108c | 4401 | } |
c5aa993b | 4402 | current_action = table[(int) bs_class][(int) current_action]; |
c906108c SS |
4403 | } |
4404 | retval.main_action = current_action; | |
4405 | return retval; | |
4406 | } | |
4407 | ||
4408 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
4409 | without hardware support). This isn't related to a specific bpstat, | |
4410 | just to things like whether watchpoints are set. */ | |
4411 | ||
c5aa993b | 4412 | int |
fba45db2 | 4413 | bpstat_should_step (void) |
c906108c SS |
4414 | { |
4415 | struct breakpoint *b; | |
4416 | ALL_BREAKPOINTS (b) | |
717a8278 | 4417 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 4418 | return 1; |
c906108c SS |
4419 | return 0; |
4420 | } | |
4421 | ||
67822962 PA |
4422 | int |
4423 | bpstat_causes_stop (bpstat bs) | |
4424 | { | |
4425 | for (; bs != NULL; bs = bs->next) | |
4426 | if (bs->stop) | |
4427 | return 1; | |
4428 | ||
4429 | return 0; | |
4430 | } | |
4431 | ||
c906108c | 4432 | \f |
c5aa993b | 4433 | |
859825b8 JK |
4434 | /* Print the LOC location out of the list of B->LOC locations. */ |
4435 | ||
0d381245 VP |
4436 | static void print_breakpoint_location (struct breakpoint *b, |
4437 | struct bp_location *loc, | |
4438 | char *wrap_indent, | |
4439 | struct ui_stream *stb) | |
4440 | { | |
6c95b8df PA |
4441 | struct cleanup *old_chain = save_current_program_space (); |
4442 | ||
859825b8 JK |
4443 | if (loc != NULL && loc->shlib_disabled) |
4444 | loc = NULL; | |
4445 | ||
6c95b8df PA |
4446 | if (loc != NULL) |
4447 | set_current_program_space (loc->pspace); | |
4448 | ||
859825b8 | 4449 | if (b->source_file && loc) |
0d381245 VP |
4450 | { |
4451 | struct symbol *sym | |
4452 | = find_pc_sect_function (loc->address, loc->section); | |
4453 | if (sym) | |
4454 | { | |
4455 | ui_out_text (uiout, "in "); | |
4456 | ui_out_field_string (uiout, "func", | |
4457 | SYMBOL_PRINT_NAME (sym)); | |
4458 | ui_out_wrap_hint (uiout, wrap_indent); | |
4459 | ui_out_text (uiout, " at "); | |
4460 | } | |
4461 | ui_out_field_string (uiout, "file", b->source_file); | |
4462 | ui_out_text (uiout, ":"); | |
4463 | ||
4464 | if (ui_out_is_mi_like_p (uiout)) | |
4465 | { | |
4466 | struct symtab_and_line sal = find_pc_line (loc->address, 0); | |
4467 | char *fullname = symtab_to_fullname (sal.symtab); | |
4468 | ||
4469 | if (fullname) | |
4470 | ui_out_field_string (uiout, "fullname", fullname); | |
4471 | } | |
4472 | ||
4473 | ui_out_field_int (uiout, "line", b->line_number); | |
4474 | } | |
859825b8 | 4475 | else if (loc) |
0d381245 | 4476 | { |
22e722e1 DJ |
4477 | print_address_symbolic (loc->gdbarch, loc->address, stb->stream, |
4478 | demangle, ""); | |
0d381245 VP |
4479 | ui_out_field_stream (uiout, "at", stb); |
4480 | } | |
859825b8 JK |
4481 | else |
4482 | ui_out_field_string (uiout, "pending", b->addr_string); | |
6c95b8df PA |
4483 | |
4484 | do_cleanups (old_chain); | |
0d381245 VP |
4485 | } |
4486 | ||
c4093a6a | 4487 | /* Print B to gdb_stdout. */ |
c906108c | 4488 | static void |
0d381245 VP |
4489 | print_one_breakpoint_location (struct breakpoint *b, |
4490 | struct bp_location *loc, | |
4491 | int loc_number, | |
a6d9a66e | 4492 | struct bp_location **last_loc, |
6c95b8df PA |
4493 | int print_address_bits, |
4494 | int allflag) | |
c906108c | 4495 | { |
52f0bd74 AC |
4496 | struct command_line *l; |
4497 | struct symbol *sym; | |
c4093a6a JM |
4498 | struct ep_type_description |
4499 | { | |
4500 | enum bptype type; | |
4501 | char *description; | |
4502 | }; | |
4503 | static struct ep_type_description bptypes[] = | |
c906108c | 4504 | { |
c5aa993b JM |
4505 | {bp_none, "?deleted?"}, |
4506 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 4507 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
4508 | {bp_until, "until"}, |
4509 | {bp_finish, "finish"}, | |
4510 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 4511 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
4512 | {bp_read_watchpoint, "read watchpoint"}, |
4513 | {bp_access_watchpoint, "acc watchpoint"}, | |
4514 | {bp_longjmp, "longjmp"}, | |
4515 | {bp_longjmp_resume, "longjmp resume"}, | |
4516 | {bp_step_resume, "step resume"}, | |
c5aa993b JM |
4517 | {bp_watchpoint_scope, "watchpoint scope"}, |
4518 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 4519 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 4520 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 4521 | {bp_thread_event, "thread events"}, |
1900040c | 4522 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 4523 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 4524 | {bp_std_terminate_master, "std::terminate master"}, |
ce78b96d | 4525 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 4526 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 4527 | {bp_fast_tracepoint, "fast tracepoint"}, |
4efc6507 | 4528 | {bp_jit_event, "jit events"}, |
c5aa993b | 4529 | }; |
c4093a6a | 4530 | |
c2c6d25f | 4531 | static char bpenables[] = "nynny"; |
c906108c | 4532 | char wrap_indent[80]; |
8b93c638 JM |
4533 | struct ui_stream *stb = ui_out_stream_new (uiout); |
4534 | struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb); | |
3b31d625 | 4535 | struct cleanup *bkpt_chain; |
c906108c | 4536 | |
0d381245 VP |
4537 | int header_of_multiple = 0; |
4538 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
4539 | struct value_print_options opts; |
4540 | ||
4541 | get_user_print_options (&opts); | |
0d381245 VP |
4542 | |
4543 | gdb_assert (!loc || loc_number != 0); | |
4544 | /* See comment in print_one_breakpoint concerning | |
4545 | treatment of breakpoints with single disabled | |
4546 | location. */ | |
4547 | if (loc == NULL | |
4548 | && (b->loc != NULL | |
4549 | && (b->loc->next != NULL || !b->loc->enabled))) | |
4550 | header_of_multiple = 1; | |
4551 | if (loc == NULL) | |
4552 | loc = b->loc; | |
4553 | ||
c4093a6a | 4554 | annotate_record (); |
3b31d625 | 4555 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); |
c4093a6a JM |
4556 | |
4557 | /* 1 */ | |
4558 | annotate_field (0); | |
0d381245 VP |
4559 | if (part_of_multiple) |
4560 | { | |
4561 | char *formatted; | |
0c6773c1 | 4562 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
4563 | ui_out_field_string (uiout, "number", formatted); |
4564 | xfree (formatted); | |
4565 | } | |
4566 | else | |
4567 | { | |
4568 | ui_out_field_int (uiout, "number", b->number); | |
4569 | } | |
c4093a6a JM |
4570 | |
4571 | /* 2 */ | |
4572 | annotate_field (1); | |
0d381245 VP |
4573 | if (part_of_multiple) |
4574 | ui_out_field_skip (uiout, "type"); | |
4575 | else | |
4576 | { | |
4577 | if (((int) b->type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
4578 | || ((int) b->type != bptypes[(int) b->type].type)) | |
4579 | internal_error (__FILE__, __LINE__, | |
4580 | _("bptypes table does not describe type #%d."), | |
4581 | (int) b->type); | |
4582 | ui_out_field_string (uiout, "type", bptypes[(int) b->type].description); | |
4583 | } | |
c4093a6a JM |
4584 | |
4585 | /* 3 */ | |
4586 | annotate_field (2); | |
0d381245 VP |
4587 | if (part_of_multiple) |
4588 | ui_out_field_skip (uiout, "disp"); | |
4589 | else | |
2cec12e5 | 4590 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 4591 | |
c4093a6a JM |
4592 | |
4593 | /* 4 */ | |
4594 | annotate_field (3); | |
0d381245 | 4595 | if (part_of_multiple) |
54e52265 | 4596 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 4597 | else |
54e52265 VP |
4598 | ui_out_field_fmt (uiout, "enabled", "%c", |
4599 | bpenables[(int) b->enable_state]); | |
4600 | ui_out_spaces (uiout, 2); | |
0d381245 | 4601 | |
c4093a6a JM |
4602 | |
4603 | /* 5 and 6 */ | |
4604 | strcpy (wrap_indent, " "); | |
79a45b7d | 4605 | if (opts.addressprint) |
75ac9d7b | 4606 | { |
a6d9a66e | 4607 | if (print_address_bits <= 32) |
75ac9d7b MS |
4608 | strcat (wrap_indent, " "); |
4609 | else | |
4610 | strcat (wrap_indent, " "); | |
4611 | } | |
c906108c | 4612 | |
3086aeae | 4613 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 VP |
4614 | { |
4615 | /* Although the print_one can possibly print | |
4616 | all locations, calling it here is not likely | |
4617 | to get any nice result. So, make sure there's | |
4618 | just one location. */ | |
4619 | gdb_assert (b->loc == NULL || b->loc->next == NULL); | |
a6d9a66e | 4620 | b->ops->print_one (b, last_loc); |
0d381245 | 4621 | } |
3086aeae DJ |
4622 | else |
4623 | switch (b->type) | |
4624 | { | |
4625 | case bp_none: | |
4626 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 4627 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 4628 | break; |
c906108c | 4629 | |
3086aeae DJ |
4630 | case bp_watchpoint: |
4631 | case bp_hardware_watchpoint: | |
4632 | case bp_read_watchpoint: | |
4633 | case bp_access_watchpoint: | |
4634 | /* Field 4, the address, is omitted (which makes the columns | |
4635 | not line up too nicely with the headers, but the effect | |
4636 | is relatively readable). */ | |
79a45b7d | 4637 | if (opts.addressprint) |
3086aeae DJ |
4638 | ui_out_field_skip (uiout, "addr"); |
4639 | annotate_field (5); | |
fa8a61dc | 4640 | ui_out_field_string (uiout, "what", b->exp_string); |
3086aeae DJ |
4641 | break; |
4642 | ||
3086aeae DJ |
4643 | case bp_breakpoint: |
4644 | case bp_hardware_breakpoint: | |
4645 | case bp_until: | |
4646 | case bp_finish: | |
4647 | case bp_longjmp: | |
4648 | case bp_longjmp_resume: | |
4649 | case bp_step_resume: | |
3086aeae DJ |
4650 | case bp_watchpoint_scope: |
4651 | case bp_call_dummy: | |
aa7d318d | 4652 | case bp_std_terminate: |
3086aeae DJ |
4653 | case bp_shlib_event: |
4654 | case bp_thread_event: | |
4655 | case bp_overlay_event: | |
0fd8e87f | 4656 | case bp_longjmp_master: |
aa7d318d | 4657 | case bp_std_terminate_master: |
1042e4c0 | 4658 | case bp_tracepoint: |
7a697b8d | 4659 | case bp_fast_tracepoint: |
4efc6507 | 4660 | case bp_jit_event: |
79a45b7d | 4661 | if (opts.addressprint) |
3086aeae DJ |
4662 | { |
4663 | annotate_field (4); | |
54e52265 | 4664 | if (header_of_multiple) |
0d381245 | 4665 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 4666 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 4667 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 4668 | else |
5af949e3 UW |
4669 | ui_out_field_core_addr (uiout, "addr", |
4670 | loc->gdbarch, loc->address); | |
3086aeae DJ |
4671 | } |
4672 | annotate_field (5); | |
0d381245 VP |
4673 | if (!header_of_multiple) |
4674 | print_breakpoint_location (b, loc, wrap_indent, stb); | |
4675 | if (b->loc) | |
a6d9a66e | 4676 | *last_loc = b->loc; |
3086aeae DJ |
4677 | break; |
4678 | } | |
c906108c | 4679 | |
6c95b8df PA |
4680 | |
4681 | /* For backward compatibility, don't display inferiors unless there | |
4682 | are several. */ | |
4683 | if (loc != NULL | |
4684 | && !header_of_multiple | |
4685 | && (allflag | |
4686 | || (!gdbarch_has_global_breakpoints (target_gdbarch) | |
4687 | && (number_of_program_spaces () > 1 | |
4688 | || number_of_inferiors () > 1) | |
4689 | && loc->owner->type != bp_catchpoint))) | |
4690 | { | |
4691 | struct inferior *inf; | |
4692 | int first = 1; | |
4693 | ||
4694 | for (inf = inferior_list; inf != NULL; inf = inf->next) | |
4695 | { | |
4696 | if (inf->pspace == loc->pspace) | |
4697 | { | |
4698 | if (first) | |
4699 | { | |
4700 | first = 0; | |
4701 | ui_out_text (uiout, " inf "); | |
4702 | } | |
4703 | else | |
4704 | ui_out_text (uiout, ", "); | |
4705 | ui_out_text (uiout, plongest (inf->num)); | |
4706 | } | |
4707 | } | |
4708 | } | |
4709 | ||
4a306c9a | 4710 | if (!part_of_multiple) |
c4093a6a | 4711 | { |
4a306c9a JB |
4712 | if (b->thread != -1) |
4713 | { | |
4714 | /* FIXME: This seems to be redundant and lost here; see the | |
4715 | "stop only in" line a little further down. */ | |
4716 | ui_out_text (uiout, " thread "); | |
4717 | ui_out_field_int (uiout, "thread", b->thread); | |
4718 | } | |
4719 | else if (b->task != 0) | |
4720 | { | |
4721 | ui_out_text (uiout, " task "); | |
4722 | ui_out_field_int (uiout, "task", b->task); | |
4723 | } | |
c4093a6a JM |
4724 | } |
4725 | ||
8b93c638 | 4726 | ui_out_text (uiout, "\n"); |
c4093a6a | 4727 | |
0d381245 | 4728 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
4729 | { |
4730 | annotate_field (6); | |
8b93c638 | 4731 | ui_out_text (uiout, "\tstop only in stack frame at "); |
818dd999 AC |
4732 | /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside |
4733 | the frame ID. */ | |
5af949e3 UW |
4734 | ui_out_field_core_addr (uiout, "frame", |
4735 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 4736 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
4737 | } |
4738 | ||
0d381245 | 4739 | if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b)) |
c4093a6a | 4740 | { |
f7f9143b JB |
4741 | /* We do not print the condition for Ada exception catchpoints |
4742 | because the condition is an internal implementation detail | |
4743 | that we do not want to expose to the user. */ | |
c4093a6a | 4744 | annotate_field (7); |
7a697b8d | 4745 | if (tracepoint_type (b)) |
1042e4c0 SS |
4746 | ui_out_text (uiout, "\ttrace only if "); |
4747 | else | |
4748 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 JJ |
4749 | ui_out_field_string (uiout, "cond", b->cond_string); |
4750 | ui_out_text (uiout, "\n"); | |
4751 | } | |
4752 | ||
0d381245 | 4753 | if (!part_of_multiple && b->thread != -1) |
c4093a6a JM |
4754 | { |
4755 | /* FIXME should make an annotation for this */ | |
8b93c638 JM |
4756 | ui_out_text (uiout, "\tstop only in thread "); |
4757 | ui_out_field_int (uiout, "thread", b->thread); | |
4758 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
4759 | } |
4760 | ||
63c715c6 | 4761 | if (!part_of_multiple && b->hit_count) |
c4093a6a JM |
4762 | { |
4763 | /* FIXME should make an annotation for this */ | |
8b93c638 JM |
4764 | if (ep_is_catchpoint (b)) |
4765 | ui_out_text (uiout, "\tcatchpoint"); | |
4766 | else | |
4767 | ui_out_text (uiout, "\tbreakpoint"); | |
4768 | ui_out_text (uiout, " already hit "); | |
4769 | ui_out_field_int (uiout, "times", b->hit_count); | |
4770 | if (b->hit_count == 1) | |
4771 | ui_out_text (uiout, " time\n"); | |
4772 | else | |
4773 | ui_out_text (uiout, " times\n"); | |
c4093a6a JM |
4774 | } |
4775 | ||
fb40c209 AC |
4776 | /* Output the count also if it is zero, but only if this is |
4777 | mi. FIXME: Should have a better test for this. */ | |
9dc5e2a9 | 4778 | if (ui_out_is_mi_like_p (uiout)) |
63c715c6 | 4779 | if (!part_of_multiple && b->hit_count == 0) |
fb40c209 | 4780 | ui_out_field_int (uiout, "times", b->hit_count); |
8b93c638 | 4781 | |
0d381245 | 4782 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
4783 | { |
4784 | annotate_field (8); | |
8b93c638 JM |
4785 | ui_out_text (uiout, "\tignore next "); |
4786 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
4787 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 4788 | } |
059fb39f | 4789 | |
9add0f1b | 4790 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 4791 | if (!part_of_multiple && l) |
c4093a6a | 4792 | { |
3b31d625 EZ |
4793 | struct cleanup *script_chain; |
4794 | ||
c4093a6a | 4795 | annotate_field (9); |
3b31d625 | 4796 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 4797 | print_command_lines (uiout, l, 4); |
3b31d625 | 4798 | do_cleanups (script_chain); |
c4093a6a | 4799 | } |
d24317b4 | 4800 | |
1042e4c0 SS |
4801 | if (!part_of_multiple && b->pass_count) |
4802 | { | |
4803 | annotate_field (10); | |
4804 | ui_out_text (uiout, "\tpass count "); | |
4805 | ui_out_field_int (uiout, "pass", b->pass_count); | |
4806 | ui_out_text (uiout, " \n"); | |
4807 | } | |
4808 | ||
d24317b4 VP |
4809 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
4810 | { | |
4811 | if (b->addr_string) | |
4812 | ui_out_field_string (uiout, "original-location", b->addr_string); | |
4813 | else if (b->exp_string) | |
4814 | ui_out_field_string (uiout, "original-location", b->exp_string); | |
4815 | } | |
4816 | ||
3b31d625 | 4817 | do_cleanups (bkpt_chain); |
8b93c638 | 4818 | do_cleanups (old_chain); |
c4093a6a | 4819 | } |
c5aa993b | 4820 | |
0d381245 VP |
4821 | static void |
4822 | print_one_breakpoint (struct breakpoint *b, | |
6c95b8df PA |
4823 | struct bp_location **last_loc, int print_address_bits, |
4824 | int allflag) | |
0d381245 | 4825 | { |
6c95b8df PA |
4826 | print_one_breakpoint_location (b, NULL, 0, last_loc, |
4827 | print_address_bits, allflag); | |
0d381245 VP |
4828 | |
4829 | /* If this breakpoint has custom print function, | |
4830 | it's already printed. Otherwise, print individual | |
4831 | locations, if any. */ | |
4832 | if (b->ops == NULL || b->ops->print_one == NULL) | |
4833 | { | |
4834 | /* If breakpoint has a single location that is | |
4835 | disabled, we print it as if it had | |
4836 | several locations, since otherwise it's hard to | |
4837 | represent "breakpoint enabled, location disabled" | |
a5606eee VP |
4838 | situation. |
4839 | Note that while hardware watchpoints have | |
4840 | several locations internally, that's no a property | |
4841 | exposed to user. */ | |
0d381245 | 4842 | if (b->loc |
a5606eee | 4843 | && !is_hardware_watchpoint (b) |
0d381245 | 4844 | && (b->loc->next || !b->loc->enabled) |
a5606eee | 4845 | && !ui_out_is_mi_like_p (uiout)) |
0d381245 VP |
4846 | { |
4847 | struct bp_location *loc; | |
4848 | int n = 1; | |
4849 | for (loc = b->loc; loc; loc = loc->next, ++n) | |
a6d9a66e | 4850 | print_one_breakpoint_location (b, loc, n, last_loc, |
6c95b8df | 4851 | print_address_bits, allflag); |
0d381245 VP |
4852 | } |
4853 | } | |
4854 | } | |
4855 | ||
a6d9a66e UW |
4856 | static int |
4857 | breakpoint_address_bits (struct breakpoint *b) | |
4858 | { | |
4859 | int print_address_bits = 0; | |
4860 | struct bp_location *loc; | |
4861 | ||
4862 | for (loc = b->loc; loc; loc = loc->next) | |
4863 | { | |
c7437ca6 PA |
4864 | int addr_bit; |
4865 | ||
4866 | /* Software watchpoints that aren't watching memory don't have | |
4867 | an address to print. */ | |
4868 | if (b->type == bp_watchpoint && loc->watchpoint_type == -1) | |
4869 | continue; | |
4870 | ||
4871 | addr_bit = gdbarch_addr_bit (loc->gdbarch); | |
a6d9a66e UW |
4872 | if (addr_bit > print_address_bits) |
4873 | print_address_bits = addr_bit; | |
4874 | } | |
4875 | ||
4876 | return print_address_bits; | |
4877 | } | |
0d381245 | 4878 | |
c4093a6a JM |
4879 | struct captured_breakpoint_query_args |
4880 | { | |
4881 | int bnum; | |
4882 | }; | |
c5aa993b | 4883 | |
c4093a6a | 4884 | static int |
2b65245e | 4885 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
4886 | { |
4887 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 4888 | struct breakpoint *b; |
a6d9a66e | 4889 | struct bp_location *dummy_loc = NULL; |
c4093a6a JM |
4890 | ALL_BREAKPOINTS (b) |
4891 | { | |
4892 | if (args->bnum == b->number) | |
c5aa993b | 4893 | { |
a6d9a66e | 4894 | int print_address_bits = breakpoint_address_bits (b); |
6c95b8df | 4895 | print_one_breakpoint (b, &dummy_loc, print_address_bits, 0); |
c4093a6a | 4896 | return GDB_RC_OK; |
c5aa993b | 4897 | } |
c4093a6a JM |
4898 | } |
4899 | return GDB_RC_NONE; | |
4900 | } | |
c5aa993b | 4901 | |
c4093a6a | 4902 | enum gdb_rc |
ce43223b | 4903 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, char **error_message) |
c4093a6a JM |
4904 | { |
4905 | struct captured_breakpoint_query_args args; | |
4906 | args.bnum = bnum; | |
4907 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4908 | an error. */ | |
b0b13bb4 DJ |
4909 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
4910 | error_message, RETURN_MASK_ALL) < 0) | |
4911 | return GDB_RC_FAIL; | |
4912 | else | |
4913 | return GDB_RC_OK; | |
c4093a6a | 4914 | } |
c5aa993b | 4915 | |
7f3b0473 AC |
4916 | /* Return non-zero if B is user settable (breakpoints, watchpoints, |
4917 | catchpoints, et.al.). */ | |
4918 | ||
4919 | static int | |
4920 | user_settable_breakpoint (const struct breakpoint *b) | |
4921 | { | |
4922 | return (b->type == bp_breakpoint | |
ce78b96d | 4923 | || b->type == bp_catchpoint |
7f3b0473 | 4924 | || b->type == bp_hardware_breakpoint |
7a697b8d | 4925 | || tracepoint_type (b) |
7f3b0473 AC |
4926 | || b->type == bp_watchpoint |
4927 | || b->type == bp_read_watchpoint | |
4928 | || b->type == bp_access_watchpoint | |
4929 | || b->type == bp_hardware_watchpoint); | |
4930 | } | |
4931 | ||
4932 | /* Print information on user settable breakpoint (watchpoint, etc) | |
4933 | number BNUM. If BNUM is -1 print all user settable breakpoints. | |
4934 | If ALLFLAG is non-zero, include non- user settable breakpoints. */ | |
c906108c | 4935 | |
c4093a6a | 4936 | static void |
fba45db2 | 4937 | breakpoint_1 (int bnum, int allflag) |
c4093a6a | 4938 | { |
52f0bd74 | 4939 | struct breakpoint *b; |
a6d9a66e | 4940 | struct bp_location *last_loc = NULL; |
7f3b0473 | 4941 | int nr_printable_breakpoints; |
3b31d625 | 4942 | struct cleanup *bkpttbl_chain; |
79a45b7d | 4943 | struct value_print_options opts; |
a6d9a66e | 4944 | int print_address_bits = 0; |
c4093a6a | 4945 | |
79a45b7d TT |
4946 | get_user_print_options (&opts); |
4947 | ||
a6d9a66e UW |
4948 | /* Compute the number of rows in the table, as well as the |
4949 | size required for address fields. */ | |
7f3b0473 AC |
4950 | nr_printable_breakpoints = 0; |
4951 | ALL_BREAKPOINTS (b) | |
4952 | if (bnum == -1 | |
4953 | || bnum == b->number) | |
4954 | { | |
4955 | if (allflag || user_settable_breakpoint (b)) | |
a6d9a66e UW |
4956 | { |
4957 | int addr_bit = breakpoint_address_bits (b); | |
4958 | if (addr_bit > print_address_bits) | |
4959 | print_address_bits = addr_bit; | |
4960 | ||
4961 | nr_printable_breakpoints++; | |
4962 | } | |
7f3b0473 AC |
4963 | } |
4964 | ||
79a45b7d | 4965 | if (opts.addressprint) |
3b31d625 EZ |
4966 | bkpttbl_chain |
4967 | = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints, | |
4968 | "BreakpointTable"); | |
8b93c638 | 4969 | else |
3b31d625 EZ |
4970 | bkpttbl_chain |
4971 | = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints, | |
4972 | "BreakpointTable"); | |
8b93c638 | 4973 | |
7f3b0473 | 4974 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
4975 | annotate_breakpoints_headers (); |
4976 | if (nr_printable_breakpoints > 0) | |
4977 | annotate_field (0); | |
0d381245 | 4978 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
4979 | if (nr_printable_breakpoints > 0) |
4980 | annotate_field (1); | |
4981 | ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */ | |
4982 | if (nr_printable_breakpoints > 0) | |
4983 | annotate_field (2); | |
4984 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ | |
4985 | if (nr_printable_breakpoints > 0) | |
4986 | annotate_field (3); | |
54e52265 | 4987 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 4988 | if (opts.addressprint) |
7f3b0473 | 4989 | { |
d7faa9e7 AC |
4990 | if (nr_printable_breakpoints > 0) |
4991 | annotate_field (4); | |
a6d9a66e | 4992 | if (print_address_bits <= 32) |
b25959ec | 4993 | ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */ |
7f3b0473 | 4994 | else |
b25959ec | 4995 | ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */ |
7f3b0473 | 4996 | } |
d7faa9e7 AC |
4997 | if (nr_printable_breakpoints > 0) |
4998 | annotate_field (5); | |
4999 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
5000 | ui_out_table_body (uiout); | |
5001 | if (nr_printable_breakpoints > 0) | |
5002 | annotate_breakpoints_table (); | |
7f3b0473 | 5003 | |
c4093a6a | 5004 | ALL_BREAKPOINTS (b) |
bad56014 TT |
5005 | { |
5006 | QUIT; | |
c4093a6a JM |
5007 | if (bnum == -1 |
5008 | || bnum == b->number) | |
5009 | { | |
5010 | /* We only print out user settable breakpoints unless the | |
5011 | allflag is set. */ | |
7f3b0473 | 5012 | if (allflag || user_settable_breakpoint (b)) |
6c95b8df | 5013 | print_one_breakpoint (b, &last_loc, print_address_bits, allflag); |
c4093a6a | 5014 | } |
bad56014 | 5015 | } |
c4093a6a | 5016 | |
3b31d625 | 5017 | do_cleanups (bkpttbl_chain); |
698384cd | 5018 | |
7f3b0473 | 5019 | if (nr_printable_breakpoints == 0) |
c906108c | 5020 | { |
8b93c638 JM |
5021 | if (bnum == -1) |
5022 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); | |
5023 | else | |
5024 | ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n", | |
5025 | bnum); | |
c906108c SS |
5026 | } |
5027 | else | |
c4093a6a | 5028 | { |
a6d9a66e UW |
5029 | if (last_loc && !server_command) |
5030 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 5031 | } |
c906108c | 5032 | |
c4093a6a JM |
5033 | /* FIXME? Should this be moved up so that it is only called when |
5034 | there have been breakpoints? */ | |
c906108c SS |
5035 | annotate_breakpoints_table_end (); |
5036 | } | |
5037 | ||
c906108c | 5038 | static void |
fba45db2 | 5039 | breakpoints_info (char *bnum_exp, int from_tty) |
c906108c SS |
5040 | { |
5041 | int bnum = -1; | |
5042 | ||
5043 | if (bnum_exp) | |
bb518678 | 5044 | bnum = parse_and_eval_long (bnum_exp); |
c906108c SS |
5045 | |
5046 | breakpoint_1 (bnum, 0); | |
5047 | } | |
5048 | ||
7a292a7a | 5049 | static void |
fba45db2 | 5050 | maintenance_info_breakpoints (char *bnum_exp, int from_tty) |
c906108c SS |
5051 | { |
5052 | int bnum = -1; | |
5053 | ||
5054 | if (bnum_exp) | |
bb518678 | 5055 | bnum = parse_and_eval_long (bnum_exp); |
c906108c SS |
5056 | |
5057 | breakpoint_1 (bnum, 1); | |
5058 | } | |
5059 | ||
0d381245 | 5060 | static int |
714835d5 | 5061 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 5062 | struct program_space *pspace, |
714835d5 | 5063 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
5064 | { |
5065 | struct bp_location *bl = b->loc; | |
5066 | for (; bl; bl = bl->next) | |
5067 | { | |
6c95b8df PA |
5068 | if (bl->pspace == pspace |
5069 | && bl->address == pc | |
0d381245 VP |
5070 | && (!overlay_debugging || bl->section == section)) |
5071 | return 1; | |
5072 | } | |
5073 | return 0; | |
5074 | } | |
5075 | ||
6c95b8df PA |
5076 | /* Print a message describing any breakpoints set at PC. This |
5077 | concerns with logical breakpoints, so we match program spaces, not | |
5078 | address spaces. */ | |
c906108c SS |
5079 | |
5080 | static void | |
6c95b8df PA |
5081 | describe_other_breakpoints (struct gdbarch *gdbarch, |
5082 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 5083 | struct obj_section *section, int thread) |
c906108c | 5084 | { |
52f0bd74 AC |
5085 | int others = 0; |
5086 | struct breakpoint *b; | |
c906108c SS |
5087 | |
5088 | ALL_BREAKPOINTS (b) | |
6c95b8df | 5089 | others += breakpoint_has_pc (b, pspace, pc, section); |
c906108c SS |
5090 | if (others > 0) |
5091 | { | |
a3f17187 AC |
5092 | if (others == 1) |
5093 | printf_filtered (_("Note: breakpoint ")); | |
5094 | else /* if (others == ???) */ | |
5095 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 5096 | ALL_BREAKPOINTS (b) |
6c95b8df | 5097 | if (breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
5098 | { |
5099 | others--; | |
5100 | printf_filtered ("%d", b->number); | |
5101 | if (b->thread == -1 && thread != -1) | |
5102 | printf_filtered (" (all threads)"); | |
5103 | else if (b->thread != -1) | |
5104 | printf_filtered (" (thread %d)", b->thread); | |
5105 | printf_filtered ("%s%s ", | |
059fb39f | 5106 | ((b->enable_state == bp_disabled |
8bea4e01 UW |
5107 | || b->enable_state == bp_call_disabled |
5108 | || b->enable_state == bp_startup_disabled) | |
0d381245 VP |
5109 | ? " (disabled)" |
5110 | : b->enable_state == bp_permanent | |
5111 | ? " (permanent)" | |
5112 | : ""), | |
5113 | (others > 1) ? "," | |
5114 | : ((others == 1) ? " and" : "")); | |
5115 | } | |
a3f17187 | 5116 | printf_filtered (_("also set at pc ")); |
5af949e3 | 5117 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
5118 | printf_filtered (".\n"); |
5119 | } | |
5120 | } | |
5121 | \f | |
5122 | /* Set the default place to put a breakpoint | |
5123 | for the `break' command with no arguments. */ | |
5124 | ||
5125 | void | |
6c95b8df PA |
5126 | set_default_breakpoint (int valid, struct program_space *pspace, |
5127 | CORE_ADDR addr, struct symtab *symtab, | |
fba45db2 | 5128 | int line) |
c906108c SS |
5129 | { |
5130 | default_breakpoint_valid = valid; | |
6c95b8df | 5131 | default_breakpoint_pspace = pspace; |
c906108c SS |
5132 | default_breakpoint_address = addr; |
5133 | default_breakpoint_symtab = symtab; | |
5134 | default_breakpoint_line = line; | |
5135 | } | |
5136 | ||
e4f237da KB |
5137 | /* Return true iff it is meaningful to use the address member of |
5138 | BPT. For some breakpoint types, the address member is irrelevant | |
5139 | and it makes no sense to attempt to compare it to other addresses | |
5140 | (or use it for any other purpose either). | |
5141 | ||
5142 | More specifically, each of the following breakpoint types will always | |
876fa593 JK |
5143 | have a zero valued address and we don't want to mark breakpoints of any of |
5144 | these types to be a duplicate of an actual breakpoint at address zero: | |
e4f237da KB |
5145 | |
5146 | bp_watchpoint | |
2d134ed3 PA |
5147 | bp_catchpoint |
5148 | ||
5149 | */ | |
e4f237da KB |
5150 | |
5151 | static int | |
5152 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
5153 | { | |
5154 | enum bptype type = bpt->type; | |
5155 | ||
2d134ed3 PA |
5156 | return (type != bp_watchpoint && type != bp_catchpoint); |
5157 | } | |
5158 | ||
5159 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
5160 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
5161 | ||
5162 | static int | |
5163 | watchpoint_locations_match (struct bp_location *loc1, struct bp_location *loc2) | |
5164 | { | |
85d721b8 PA |
5165 | /* Note that this checks the owner's type, not the location's. In |
5166 | case the target does not support read watchpoints, but does | |
5167 | support access watchpoints, we'll have bp_read_watchpoint | |
5168 | watchpoints with hw_access locations. Those should be considered | |
5169 | duplicates of hw_read locations. The hw_read locations will | |
5170 | become hw_access locations later. */ | |
2d134ed3 PA |
5171 | return (loc1->owner->type == loc2->owner->type |
5172 | && loc1->pspace->aspace == loc2->pspace->aspace | |
5173 | && loc1->address == loc2->address | |
5174 | && loc1->length == loc2->length); | |
e4f237da KB |
5175 | } |
5176 | ||
6c95b8df PA |
5177 | /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the |
5178 | same breakpoint location. In most targets, this can only be true | |
5179 | if ASPACE1 matches ASPACE2. On targets that have global | |
5180 | breakpoints, the address space doesn't really matter. */ | |
5181 | ||
5182 | static int | |
5183 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, | |
5184 | struct address_space *aspace2, CORE_ADDR addr2) | |
5185 | { | |
5186 | return ((gdbarch_has_global_breakpoints (target_gdbarch) | |
5187 | || aspace1 == aspace2) | |
5188 | && addr1 == addr2); | |
5189 | } | |
5190 | ||
2d134ed3 PA |
5191 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
5192 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
5193 | represent the same location. */ | |
5194 | ||
5195 | static int | |
5196 | breakpoint_locations_match (struct bp_location *loc1, struct bp_location *loc2) | |
5197 | { | |
5198 | int hw_point1 = is_hardware_watchpoint (loc1->owner); | |
5199 | int hw_point2 = is_hardware_watchpoint (loc2->owner); | |
5200 | ||
5201 | if (hw_point1 != hw_point2) | |
5202 | return 0; | |
5203 | else if (hw_point1) | |
5204 | return watchpoint_locations_match (loc1, loc2); | |
5205 | else | |
5206 | return breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
5207 | loc2->pspace->aspace, loc2->address); | |
5208 | } | |
5209 | ||
76897487 KB |
5210 | static void |
5211 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
5212 | int bnum, int have_bnum) | |
5213 | { | |
5214 | char astr1[40]; | |
5215 | char astr2[40]; | |
5216 | ||
bb599908 PH |
5217 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
5218 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 5219 | if (have_bnum) |
8a3fe4f8 | 5220 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
5221 | bnum, astr1, astr2); |
5222 | else | |
8a3fe4f8 | 5223 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
5224 | } |
5225 | ||
5226 | /* Adjust a breakpoint's address to account for architectural constraints | |
5227 | on breakpoint placement. Return the adjusted address. Note: Very | |
5228 | few targets require this kind of adjustment. For most targets, | |
5229 | this function is simply the identity function. */ | |
5230 | ||
5231 | static CORE_ADDR | |
a6d9a66e UW |
5232 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
5233 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 5234 | { |
a6d9a66e | 5235 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
5236 | { |
5237 | /* Very few targets need any kind of breakpoint adjustment. */ | |
5238 | return bpaddr; | |
5239 | } | |
88f7da05 KB |
5240 | else if (bptype == bp_watchpoint |
5241 | || bptype == bp_hardware_watchpoint | |
5242 | || bptype == bp_read_watchpoint | |
5243 | || bptype == bp_access_watchpoint | |
fe798b75 | 5244 | || bptype == bp_catchpoint) |
88f7da05 KB |
5245 | { |
5246 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
5247 | have their addresses modified. */ | |
5248 | return bpaddr; | |
5249 | } | |
76897487 KB |
5250 | else |
5251 | { | |
5252 | CORE_ADDR adjusted_bpaddr; | |
5253 | ||
5254 | /* Some targets have architectural constraints on the placement | |
5255 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 5256 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
5257 | |
5258 | /* An adjusted breakpoint address can significantly alter | |
5259 | a user's expectations. Print a warning if an adjustment | |
5260 | is required. */ | |
5261 | if (adjusted_bpaddr != bpaddr) | |
5262 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
5263 | ||
5264 | return adjusted_bpaddr; | |
5265 | } | |
5266 | } | |
5267 | ||
7cc221ef DJ |
5268 | /* Allocate a struct bp_location. */ |
5269 | ||
26bb91f3 | 5270 | static struct bp_location * |
39d61571 | 5271 | allocate_bp_location (struct breakpoint *bpt) |
7cc221ef DJ |
5272 | { |
5273 | struct bp_location *loc, *loc_p; | |
5274 | ||
5275 | loc = xmalloc (sizeof (struct bp_location)); | |
5276 | memset (loc, 0, sizeof (*loc)); | |
5277 | ||
e049a4b5 | 5278 | loc->owner = bpt; |
511a6cd4 | 5279 | loc->cond = NULL; |
0d381245 VP |
5280 | loc->shlib_disabled = 0; |
5281 | loc->enabled = 1; | |
e049a4b5 | 5282 | |
39d61571 | 5283 | switch (bpt->type) |
e049a4b5 DJ |
5284 | { |
5285 | case bp_breakpoint: | |
5286 | case bp_until: | |
5287 | case bp_finish: | |
5288 | case bp_longjmp: | |
5289 | case bp_longjmp_resume: | |
5290 | case bp_step_resume: | |
e049a4b5 DJ |
5291 | case bp_watchpoint_scope: |
5292 | case bp_call_dummy: | |
aa7d318d | 5293 | case bp_std_terminate: |
e049a4b5 DJ |
5294 | case bp_shlib_event: |
5295 | case bp_thread_event: | |
5296 | case bp_overlay_event: | |
4efc6507 | 5297 | case bp_jit_event: |
0fd8e87f | 5298 | case bp_longjmp_master: |
aa7d318d | 5299 | case bp_std_terminate_master: |
e049a4b5 DJ |
5300 | loc->loc_type = bp_loc_software_breakpoint; |
5301 | break; | |
5302 | case bp_hardware_breakpoint: | |
5303 | loc->loc_type = bp_loc_hardware_breakpoint; | |
5304 | break; | |
5305 | case bp_hardware_watchpoint: | |
5306 | case bp_read_watchpoint: | |
5307 | case bp_access_watchpoint: | |
5308 | loc->loc_type = bp_loc_hardware_watchpoint; | |
5309 | break; | |
5310 | case bp_watchpoint: | |
ce78b96d | 5311 | case bp_catchpoint: |
15c3d785 PA |
5312 | case bp_tracepoint: |
5313 | case bp_fast_tracepoint: | |
e049a4b5 DJ |
5314 | loc->loc_type = bp_loc_other; |
5315 | break; | |
5316 | default: | |
e2e0b3e5 | 5317 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
5318 | } |
5319 | ||
7cc221ef DJ |
5320 | return loc; |
5321 | } | |
5322 | ||
fe3f5fa8 VP |
5323 | static void free_bp_location (struct bp_location *loc) |
5324 | { | |
5325 | if (loc->cond) | |
5326 | xfree (loc->cond); | |
74960c60 VP |
5327 | |
5328 | if (loc->function_name) | |
5329 | xfree (loc->function_name); | |
5330 | ||
fe3f5fa8 VP |
5331 | xfree (loc); |
5332 | } | |
5333 | ||
0d381245 VP |
5334 | /* Helper to set_raw_breakpoint below. Creates a breakpoint |
5335 | that has type BPTYPE and has no locations as yet. */ | |
63c252f8 | 5336 | /* This function is used in gdbtk sources and thus can not be made static. */ |
c906108c | 5337 | |
c40e75cd | 5338 | static struct breakpoint * |
a6d9a66e UW |
5339 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, |
5340 | enum bptype bptype) | |
c906108c | 5341 | { |
52f0bd74 | 5342 | struct breakpoint *b, *b1; |
c906108c SS |
5343 | |
5344 | b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint)); | |
5345 | memset (b, 0, sizeof (*b)); | |
2219d63c | 5346 | |
4d28f7a8 | 5347 | b->type = bptype; |
a6d9a66e | 5348 | b->gdbarch = gdbarch; |
c906108c SS |
5349 | b->language = current_language->la_language; |
5350 | b->input_radix = input_radix; | |
5351 | b->thread = -1; | |
b5de0fa7 | 5352 | b->enable_state = bp_enabled; |
c906108c SS |
5353 | b->next = 0; |
5354 | b->silent = 0; | |
5355 | b->ignore_count = 0; | |
5356 | b->commands = NULL; | |
818dd999 | 5357 | b->frame_id = null_frame_id; |
3a3e9ee3 | 5358 | b->forked_inferior_pid = null_ptid; |
c906108c | 5359 | b->exec_pathname = NULL; |
a96d9b2e | 5360 | b->syscalls_to_be_caught = NULL; |
3086aeae | 5361 | b->ops = NULL; |
0d381245 | 5362 | b->condition_not_parsed = 0; |
c906108c SS |
5363 | |
5364 | /* Add this breakpoint to the end of the chain | |
5365 | so that a list of breakpoints will come out in order | |
5366 | of increasing numbers. */ | |
5367 | ||
5368 | b1 = breakpoint_chain; | |
5369 | if (b1 == 0) | |
5370 | breakpoint_chain = b; | |
5371 | else | |
5372 | { | |
5373 | while (b1->next) | |
5374 | b1 = b1->next; | |
5375 | b1->next = b; | |
5376 | } | |
0d381245 VP |
5377 | return b; |
5378 | } | |
5379 | ||
5380 | /* Initialize loc->function_name. */ | |
5381 | static void | |
5382 | set_breakpoint_location_function (struct bp_location *loc) | |
5383 | { | |
5384 | if (loc->owner->type == bp_breakpoint | |
1042e4c0 | 5385 | || loc->owner->type == bp_hardware_breakpoint |
7a697b8d | 5386 | || tracepoint_type (loc->owner)) |
0d381245 VP |
5387 | { |
5388 | find_pc_partial_function (loc->address, &(loc->function_name), | |
5389 | NULL, NULL); | |
5390 | if (loc->function_name) | |
5391 | loc->function_name = xstrdup (loc->function_name); | |
5392 | } | |
5393 | } | |
5394 | ||
a6d9a66e UW |
5395 | /* Attempt to determine architecture of location identified by SAL. */ |
5396 | static struct gdbarch * | |
5397 | get_sal_arch (struct symtab_and_line sal) | |
5398 | { | |
5399 | if (sal.section) | |
5400 | return get_objfile_arch (sal.section->objfile); | |
5401 | if (sal.symtab) | |
5402 | return get_objfile_arch (sal.symtab->objfile); | |
5403 | ||
5404 | return NULL; | |
5405 | } | |
5406 | ||
0d381245 VP |
5407 | /* set_raw_breakpoint is a low level routine for allocating and |
5408 | partially initializing a breakpoint of type BPTYPE. The newly | |
5409 | created breakpoint's address, section, source file name, and line | |
5410 | number are provided by SAL. The newly created and partially | |
5411 | initialized breakpoint is added to the breakpoint chain and | |
5412 | is also returned as the value of this function. | |
5413 | ||
5414 | It is expected that the caller will complete the initialization of | |
5415 | the newly created breakpoint struct as well as output any status | |
5416 | information regarding the creation of a new breakpoint. In | |
5417 | particular, set_raw_breakpoint does NOT set the breakpoint | |
5418 | number! Care should be taken to not allow an error to occur | |
5419 | prior to completing the initialization of the breakpoint. If this | |
5420 | should happen, a bogus breakpoint will be left on the chain. */ | |
5421 | ||
63c252f8 | 5422 | struct breakpoint * |
a6d9a66e UW |
5423 | set_raw_breakpoint (struct gdbarch *gdbarch, |
5424 | struct symtab_and_line sal, enum bptype bptype) | |
0d381245 | 5425 | { |
a6d9a66e | 5426 | struct breakpoint *b = set_raw_breakpoint_without_location (gdbarch, bptype); |
0d381245 | 5427 | CORE_ADDR adjusted_address; |
a6d9a66e UW |
5428 | struct gdbarch *loc_gdbarch; |
5429 | ||
5430 | loc_gdbarch = get_sal_arch (sal); | |
5431 | if (!loc_gdbarch) | |
5432 | loc_gdbarch = b->gdbarch; | |
0d381245 | 5433 | |
6c95b8df PA |
5434 | if (bptype != bp_catchpoint) |
5435 | gdb_assert (sal.pspace != NULL); | |
5436 | ||
0d381245 VP |
5437 | /* Adjust the breakpoint's address prior to allocating a location. |
5438 | Once we call allocate_bp_location(), that mostly uninitialized | |
5439 | location will be placed on the location chain. Adjustment of the | |
8defab1a | 5440 | breakpoint may cause target_read_memory() to be called and we do |
0d381245 VP |
5441 | not want its scan of the location chain to find a breakpoint and |
5442 | location that's only been partially initialized. */ | |
a6d9a66e | 5443 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, sal.pc, b->type); |
0d381245 | 5444 | |
39d61571 | 5445 | b->loc = allocate_bp_location (b); |
a6d9a66e | 5446 | b->loc->gdbarch = loc_gdbarch; |
0d381245 VP |
5447 | b->loc->requested_address = sal.pc; |
5448 | b->loc->address = adjusted_address; | |
6c95b8df PA |
5449 | b->loc->pspace = sal.pspace; |
5450 | ||
5451 | /* Store the program space that was used to set the breakpoint, for | |
5452 | breakpoint resetting. */ | |
5453 | b->pspace = sal.pspace; | |
0d381245 VP |
5454 | |
5455 | if (sal.symtab == NULL) | |
5456 | b->source_file = NULL; | |
5457 | else | |
1b36a34b | 5458 | b->source_file = xstrdup (sal.symtab->filename); |
0d381245 VP |
5459 | b->loc->section = sal.section; |
5460 | b->line_number = sal.line; | |
5461 | ||
5462 | set_breakpoint_location_function (b->loc); | |
c906108c | 5463 | |
c906108c SS |
5464 | breakpoints_changed (); |
5465 | ||
5466 | return b; | |
5467 | } | |
5468 | ||
c2c6d25f JM |
5469 | |
5470 | /* Note that the breakpoint object B describes a permanent breakpoint | |
5471 | instruction, hard-wired into the inferior's code. */ | |
5472 | void | |
5473 | make_breakpoint_permanent (struct breakpoint *b) | |
5474 | { | |
0d381245 | 5475 | struct bp_location *bl; |
b5de0fa7 | 5476 | b->enable_state = bp_permanent; |
c2c6d25f | 5477 | |
0d381245 VP |
5478 | /* By definition, permanent breakpoints are already present in the code. |
5479 | Mark all locations as inserted. For now, make_breakpoint_permanent | |
5480 | is called in just one place, so it's hard to say if it's reasonable | |
5481 | to have permanent breakpoint with multiple locations or not, | |
5482 | but it's easy to implmement. */ | |
5483 | for (bl = b->loc; bl; bl = bl->next) | |
5484 | bl->inserted = 1; | |
c2c6d25f JM |
5485 | } |
5486 | ||
53a5351d | 5487 | /* Call this routine when stepping and nexting to enable a breakpoint |
0fd8e87f | 5488 | if we do a longjmp() in THREAD. When we hit that breakpoint, call |
c906108c SS |
5489 | set_longjmp_resume_breakpoint() to figure out where we are going. */ |
5490 | ||
5491 | void | |
0fd8e87f | 5492 | set_longjmp_breakpoint (int thread) |
c906108c | 5493 | { |
0fd8e87f UW |
5494 | struct breakpoint *b, *temp; |
5495 | ||
5496 | /* To avoid having to rescan all objfile symbols at every step, | |
5497 | we maintain a list of continually-inserted but always disabled | |
5498 | longjmp "master" breakpoints. Here, we simply create momentary | |
5499 | clones of those and enable them for the requested thread. */ | |
5500 | ALL_BREAKPOINTS_SAFE (b, temp) | |
6c95b8df PA |
5501 | if (b->pspace == current_program_space |
5502 | && b->type == bp_longjmp_master) | |
0fd8e87f UW |
5503 | { |
5504 | struct breakpoint *clone = clone_momentary_breakpoint (b); | |
5505 | clone->type = bp_longjmp; | |
5506 | clone->thread = thread; | |
5507 | } | |
c906108c SS |
5508 | } |
5509 | ||
611c83ae | 5510 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 5511 | void |
611c83ae | 5512 | delete_longjmp_breakpoint (int thread) |
c906108c | 5513 | { |
611c83ae | 5514 | struct breakpoint *b, *temp; |
c906108c | 5515 | |
611c83ae PA |
5516 | ALL_BREAKPOINTS_SAFE (b, temp) |
5517 | if (b->type == bp_longjmp) | |
5518 | { | |
5519 | if (b->thread == thread) | |
5520 | delete_breakpoint (b); | |
5521 | } | |
c906108c SS |
5522 | } |
5523 | ||
1900040c MS |
5524 | void |
5525 | enable_overlay_breakpoints (void) | |
5526 | { | |
52f0bd74 | 5527 | struct breakpoint *b; |
1900040c MS |
5528 | |
5529 | ALL_BREAKPOINTS (b) | |
5530 | if (b->type == bp_overlay_event) | |
5531 | { | |
5532 | b->enable_state = bp_enabled; | |
b60e7edf | 5533 | update_global_location_list (1); |
c02f5703 | 5534 | overlay_events_enabled = 1; |
1900040c MS |
5535 | } |
5536 | } | |
5537 | ||
5538 | void | |
5539 | disable_overlay_breakpoints (void) | |
5540 | { | |
52f0bd74 | 5541 | struct breakpoint *b; |
1900040c MS |
5542 | |
5543 | ALL_BREAKPOINTS (b) | |
5544 | if (b->type == bp_overlay_event) | |
5545 | { | |
5546 | b->enable_state = bp_disabled; | |
b60e7edf | 5547 | update_global_location_list (0); |
c02f5703 | 5548 | overlay_events_enabled = 0; |
1900040c MS |
5549 | } |
5550 | } | |
5551 | ||
aa7d318d TT |
5552 | /* Set an active std::terminate breakpoint for each std::terminate |
5553 | master breakpoint. */ | |
5554 | void | |
5555 | set_std_terminate_breakpoint (void) | |
5556 | { | |
5557 | struct breakpoint *b, *temp; | |
5558 | ||
5559 | ALL_BREAKPOINTS_SAFE (b, temp) | |
5560 | if (b->pspace == current_program_space | |
5561 | && b->type == bp_std_terminate_master) | |
5562 | { | |
5563 | struct breakpoint *clone = clone_momentary_breakpoint (b); | |
5564 | clone->type = bp_std_terminate; | |
5565 | } | |
5566 | } | |
5567 | ||
5568 | /* Delete all the std::terminate breakpoints. */ | |
5569 | void | |
5570 | delete_std_terminate_breakpoint (void) | |
5571 | { | |
5572 | struct breakpoint *b, *temp; | |
5573 | ||
5574 | ALL_BREAKPOINTS_SAFE (b, temp) | |
5575 | if (b->type == bp_std_terminate) | |
5576 | delete_breakpoint (b); | |
5577 | } | |
5578 | ||
c4093a6a | 5579 | struct breakpoint * |
a6d9a66e | 5580 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
5581 | { |
5582 | struct breakpoint *b; | |
c4093a6a | 5583 | |
a6d9a66e | 5584 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event); |
c4093a6a | 5585 | |
b5de0fa7 | 5586 | b->enable_state = bp_enabled; |
c4093a6a | 5587 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
5588 | b->addr_string |
5589 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 5590 | |
b60e7edf | 5591 | update_global_location_list_nothrow (1); |
74960c60 | 5592 | |
c4093a6a JM |
5593 | return b; |
5594 | } | |
5595 | ||
5596 | void | |
5597 | remove_thread_event_breakpoints (void) | |
5598 | { | |
5599 | struct breakpoint *b, *temp; | |
5600 | ||
5601 | ALL_BREAKPOINTS_SAFE (b, temp) | |
6c95b8df PA |
5602 | if (b->type == bp_thread_event |
5603 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
5604 | delete_breakpoint (b); |
5605 | } | |
5606 | ||
0101ce28 JJ |
5607 | struct captured_parse_breakpoint_args |
5608 | { | |
5609 | char **arg_p; | |
5610 | struct symtabs_and_lines *sals_p; | |
5611 | char ***addr_string_p; | |
5612 | int *not_found_ptr; | |
5613 | }; | |
5614 | ||
5615 | struct lang_and_radix | |
5616 | { | |
5617 | enum language lang; | |
5618 | int radix; | |
5619 | }; | |
5620 | ||
4efc6507 DE |
5621 | /* Create a breakpoint for JIT code registration and unregistration. */ |
5622 | ||
5623 | struct breakpoint * | |
5624 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
5625 | { | |
5626 | struct breakpoint *b; | |
5627 | ||
5628 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event); | |
5629 | update_global_location_list_nothrow (1); | |
5630 | return b; | |
5631 | } | |
0101ce28 | 5632 | |
cae688ec JJ |
5633 | void |
5634 | remove_solib_event_breakpoints (void) | |
5635 | { | |
5636 | struct breakpoint *b, *temp; | |
5637 | ||
5638 | ALL_BREAKPOINTS_SAFE (b, temp) | |
6c95b8df PA |
5639 | if (b->type == bp_shlib_event |
5640 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
5641 | delete_breakpoint (b); |
5642 | } | |
5643 | ||
5644 | struct breakpoint * | |
a6d9a66e | 5645 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
cae688ec JJ |
5646 | { |
5647 | struct breakpoint *b; | |
5648 | ||
a6d9a66e | 5649 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event); |
b60e7edf | 5650 | update_global_location_list_nothrow (1); |
cae688ec JJ |
5651 | return b; |
5652 | } | |
5653 | ||
5654 | /* Disable any breakpoints that are on code in shared libraries. Only | |
5655 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
5656 | ||
5657 | void | |
cb851954 | 5658 | disable_breakpoints_in_shlibs (void) |
cae688ec | 5659 | { |
876fa593 | 5660 | struct bp_location *loc, **locp_tmp; |
cae688ec | 5661 | |
876fa593 | 5662 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 5663 | { |
0d381245 VP |
5664 | struct breakpoint *b = loc->owner; |
5665 | /* We apply the check to all breakpoints, including disabled | |
5666 | for those with loc->duplicate set. This is so that when breakpoint | |
5667 | becomes enabled, or the duplicate is removed, gdb will try to insert | |
5668 | all breakpoints. If we don't set shlib_disabled here, we'll try | |
5669 | to insert those breakpoints and fail. */ | |
1042e4c0 | 5670 | if (((b->type == bp_breakpoint) |
508ccb1f | 5671 | || (b->type == bp_jit_event) |
1042e4c0 | 5672 | || (b->type == bp_hardware_breakpoint) |
7a697b8d | 5673 | || (tracepoint_type (b))) |
6c95b8df | 5674 | && loc->pspace == current_program_space |
0d381245 | 5675 | && !loc->shlib_disabled |
a77053c2 | 5676 | #ifdef PC_SOLIB |
0d381245 | 5677 | && PC_SOLIB (loc->address) |
a77053c2 | 5678 | #else |
6c95b8df | 5679 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 MK |
5680 | #endif |
5681 | ) | |
0d381245 VP |
5682 | { |
5683 | loc->shlib_disabled = 1; | |
5684 | } | |
cae688ec JJ |
5685 | } |
5686 | } | |
5687 | ||
84acb35a JJ |
5688 | /* Disable any breakpoints that are in in an unloaded shared library. Only |
5689 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
5690 | ||
75149521 | 5691 | static void |
84acb35a JJ |
5692 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
5693 | { | |
876fa593 | 5694 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
5695 | int disabled_shlib_breaks = 0; |
5696 | ||
c86cf029 VP |
5697 | /* SunOS a.out shared libraries are always mapped, so do not |
5698 | disable breakpoints; they will only be reported as unloaded | |
5699 | through clear_solib when GDB discards its shared library | |
5700 | list. See clear_solib for more information. */ | |
5701 | if (exec_bfd != NULL | |
5702 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
5703 | return; | |
5704 | ||
876fa593 | 5705 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 5706 | { |
0d381245 VP |
5707 | struct breakpoint *b = loc->owner; |
5708 | if ((loc->loc_type == bp_loc_hardware_breakpoint | |
5709 | || loc->loc_type == bp_loc_software_breakpoint) | |
6c95b8df | 5710 | && solib->pspace == loc->pspace |
e2dd7057 | 5711 | && !loc->shlib_disabled |
508ccb1f TT |
5712 | && (b->type == bp_breakpoint |
5713 | || b->type == bp_jit_event | |
5714 | || b->type == bp_hardware_breakpoint) | |
e2dd7057 | 5715 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 5716 | { |
e2dd7057 PP |
5717 | loc->shlib_disabled = 1; |
5718 | /* At this point, we cannot rely on remove_breakpoint | |
5719 | succeeding so we must mark the breakpoint as not inserted | |
5720 | to prevent future errors occurring in remove_breakpoints. */ | |
5721 | loc->inserted = 0; | |
5722 | if (!disabled_shlib_breaks) | |
5723 | { | |
5724 | target_terminal_ours_for_output (); | |
5725 | warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""), | |
5726 | solib->so_name); | |
84acb35a | 5727 | } |
e2dd7057 | 5728 | disabled_shlib_breaks = 1; |
84acb35a JJ |
5729 | } |
5730 | } | |
84acb35a JJ |
5731 | } |
5732 | ||
ce78b96d JB |
5733 | /* FORK & VFORK catchpoints. */ |
5734 | ||
5735 | /* Implement the "insert" breakpoint_ops method for fork catchpoints. */ | |
5736 | ||
c906108c | 5737 | static void |
ce78b96d JB |
5738 | insert_catch_fork (struct breakpoint *b) |
5739 | { | |
5740 | target_insert_fork_catchpoint (PIDGET (inferior_ptid)); | |
5741 | } | |
5742 | ||
5743 | /* Implement the "remove" breakpoint_ops method for fork catchpoints. */ | |
5744 | ||
5745 | static int | |
5746 | remove_catch_fork (struct breakpoint *b) | |
5747 | { | |
5748 | return target_remove_fork_catchpoint (PIDGET (inferior_ptid)); | |
5749 | } | |
5750 | ||
5751 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
5752 | catchpoints. */ | |
5753 | ||
5754 | static int | |
5755 | breakpoint_hit_catch_fork (struct breakpoint *b) | |
5756 | { | |
5757 | return inferior_has_forked (inferior_ptid, &b->forked_inferior_pid); | |
5758 | } | |
5759 | ||
5760 | /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */ | |
5761 | ||
5762 | static enum print_stop_action | |
5763 | print_it_catch_fork (struct breakpoint *b) | |
5764 | { | |
5765 | annotate_catchpoint (b->number); | |
5766 | printf_filtered (_("\nCatchpoint %d (forked process %d), "), | |
5767 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
5768 | return PRINT_SRC_AND_LOC; | |
5769 | } | |
5770 | ||
5771 | /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */ | |
5772 | ||
5773 | static void | |
a6d9a66e | 5774 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 5775 | { |
79a45b7d TT |
5776 | struct value_print_options opts; |
5777 | ||
5778 | get_user_print_options (&opts); | |
5779 | ||
ce78b96d JB |
5780 | /* Field 4, the address, is omitted (which makes the columns |
5781 | not line up too nicely with the headers, but the effect | |
5782 | is relatively readable). */ | |
79a45b7d | 5783 | if (opts.addressprint) |
ce78b96d JB |
5784 | ui_out_field_skip (uiout, "addr"); |
5785 | annotate_field (5); | |
5786 | ui_out_text (uiout, "fork"); | |
5787 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
5788 | { | |
5789 | ui_out_text (uiout, ", process "); | |
5790 | ui_out_field_int (uiout, "what", | |
5791 | ptid_get_pid (b->forked_inferior_pid)); | |
5792 | ui_out_spaces (uiout, 1); | |
5793 | } | |
5794 | } | |
5795 | ||
5796 | /* Implement the "print_mention" breakpoint_ops method for fork | |
5797 | catchpoints. */ | |
5798 | ||
5799 | static void | |
5800 | print_mention_catch_fork (struct breakpoint *b) | |
5801 | { | |
5802 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
5803 | } | |
5804 | ||
5805 | /* The breakpoint_ops structure to be used in fork catchpoints. */ | |
5806 | ||
5807 | static struct breakpoint_ops catch_fork_breakpoint_ops = | |
5808 | { | |
5809 | insert_catch_fork, | |
5810 | remove_catch_fork, | |
5811 | breakpoint_hit_catch_fork, | |
5812 | print_it_catch_fork, | |
5813 | print_one_catch_fork, | |
5814 | print_mention_catch_fork | |
5815 | }; | |
5816 | ||
5817 | /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */ | |
5818 | ||
5819 | static void | |
5820 | insert_catch_vfork (struct breakpoint *b) | |
5821 | { | |
5822 | target_insert_vfork_catchpoint (PIDGET (inferior_ptid)); | |
5823 | } | |
5824 | ||
5825 | /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */ | |
5826 | ||
5827 | static int | |
5828 | remove_catch_vfork (struct breakpoint *b) | |
5829 | { | |
5830 | return target_remove_vfork_catchpoint (PIDGET (inferior_ptid)); | |
5831 | } | |
5832 | ||
5833 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
5834 | catchpoints. */ | |
5835 | ||
5836 | static int | |
5837 | breakpoint_hit_catch_vfork (struct breakpoint *b) | |
5838 | { | |
5839 | return inferior_has_vforked (inferior_ptid, &b->forked_inferior_pid); | |
5840 | } | |
5841 | ||
5842 | /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */ | |
5843 | ||
5844 | static enum print_stop_action | |
5845 | print_it_catch_vfork (struct breakpoint *b) | |
5846 | { | |
5847 | annotate_catchpoint (b->number); | |
5848 | printf_filtered (_("\nCatchpoint %d (vforked process %d), "), | |
5849 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
5850 | return PRINT_SRC_AND_LOC; | |
5851 | } | |
5852 | ||
5853 | /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */ | |
5854 | ||
5855 | static void | |
a6d9a66e | 5856 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 5857 | { |
79a45b7d TT |
5858 | struct value_print_options opts; |
5859 | ||
5860 | get_user_print_options (&opts); | |
ce78b96d JB |
5861 | /* Field 4, the address, is omitted (which makes the columns |
5862 | not line up too nicely with the headers, but the effect | |
5863 | is relatively readable). */ | |
79a45b7d | 5864 | if (opts.addressprint) |
ce78b96d JB |
5865 | ui_out_field_skip (uiout, "addr"); |
5866 | annotate_field (5); | |
5867 | ui_out_text (uiout, "vfork"); | |
5868 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
5869 | { | |
5870 | ui_out_text (uiout, ", process "); | |
5871 | ui_out_field_int (uiout, "what", | |
5872 | ptid_get_pid (b->forked_inferior_pid)); | |
5873 | ui_out_spaces (uiout, 1); | |
5874 | } | |
5875 | } | |
5876 | ||
5877 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
5878 | catchpoints. */ | |
5879 | ||
5880 | static void | |
5881 | print_mention_catch_vfork (struct breakpoint *b) | |
5882 | { | |
5883 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
5884 | } | |
5885 | ||
5886 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ | |
5887 | ||
5888 | static struct breakpoint_ops catch_vfork_breakpoint_ops = | |
5889 | { | |
5890 | insert_catch_vfork, | |
5891 | remove_catch_vfork, | |
5892 | breakpoint_hit_catch_vfork, | |
5893 | print_it_catch_vfork, | |
5894 | print_one_catch_vfork, | |
5895 | print_mention_catch_vfork | |
5896 | }; | |
5897 | ||
a96d9b2e SDJ |
5898 | /* Implement the "insert" breakpoint_ops method for syscall |
5899 | catchpoints. */ | |
5900 | ||
5901 | static void | |
5902 | insert_catch_syscall (struct breakpoint *b) | |
5903 | { | |
5904 | struct inferior *inf = current_inferior (); | |
5905 | ||
5906 | ++inf->total_syscalls_count; | |
5907 | if (!b->syscalls_to_be_caught) | |
5908 | ++inf->any_syscall_count; | |
5909 | else | |
5910 | { | |
5911 | int i, iter; | |
5912 | for (i = 0; | |
5913 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
5914 | i++) | |
5915 | { | |
5916 | int elem; | |
5917 | if (iter >= VEC_length (int, inf->syscalls_counts)) | |
5918 | { | |
5919 | int old_size = VEC_length (int, inf->syscalls_counts); | |
5920 | uintptr_t vec_addr_offset = old_size * ((uintptr_t) sizeof (int)); | |
5921 | uintptr_t vec_addr; | |
5922 | VEC_safe_grow (int, inf->syscalls_counts, iter + 1); | |
5923 | vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) + | |
5924 | vec_addr_offset; | |
5925 | memset ((void *) vec_addr, 0, | |
5926 | (iter + 1 - old_size) * sizeof (int)); | |
5927 | } | |
5928 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
5929 | VEC_replace (int, inf->syscalls_counts, iter, ++elem); | |
5930 | } | |
5931 | } | |
5932 | ||
5933 | target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
5934 | inf->total_syscalls_count != 0, | |
5935 | inf->any_syscall_count, | |
5936 | VEC_length (int, inf->syscalls_counts), | |
5937 | VEC_address (int, inf->syscalls_counts)); | |
5938 | } | |
5939 | ||
5940 | /* Implement the "remove" breakpoint_ops method for syscall | |
5941 | catchpoints. */ | |
5942 | ||
5943 | static int | |
5944 | remove_catch_syscall (struct breakpoint *b) | |
5945 | { | |
5946 | struct inferior *inf = current_inferior (); | |
5947 | ||
5948 | --inf->total_syscalls_count; | |
5949 | if (!b->syscalls_to_be_caught) | |
5950 | --inf->any_syscall_count; | |
5951 | else | |
5952 | { | |
5953 | int i, iter; | |
5954 | for (i = 0; | |
5955 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
5956 | i++) | |
5957 | { | |
5958 | int elem; | |
5959 | if (iter >= VEC_length (int, inf->syscalls_counts)) | |
5960 | /* Shouldn't happen. */ | |
5961 | continue; | |
5962 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
5963 | VEC_replace (int, inf->syscalls_counts, iter, --elem); | |
5964 | } | |
5965 | } | |
5966 | ||
5967 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
5968 | inf->total_syscalls_count != 0, | |
5969 | inf->any_syscall_count, | |
5970 | VEC_length (int, inf->syscalls_counts), | |
5971 | VEC_address (int, inf->syscalls_counts)); | |
5972 | } | |
5973 | ||
5974 | /* Implement the "breakpoint_hit" breakpoint_ops method for syscall | |
5975 | catchpoints. */ | |
5976 | ||
5977 | static int | |
5978 | breakpoint_hit_catch_syscall (struct breakpoint *b) | |
5979 | { | |
5980 | /* We must check if we are catching specific syscalls in this breakpoint. | |
5981 | If we are, then we must guarantee that the called syscall is the same | |
5982 | syscall we are catching. */ | |
5983 | int syscall_number = 0; | |
5984 | ||
5985 | if (!inferior_has_called_syscall (inferior_ptid, &syscall_number)) | |
5986 | return 0; | |
5987 | ||
5988 | /* Now, checking if the syscall is the same. */ | |
5989 | if (b->syscalls_to_be_caught) | |
5990 | { | |
5991 | int i, iter; | |
5992 | for (i = 0; | |
5993 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
5994 | i++) | |
5995 | if (syscall_number == iter) | |
5996 | break; | |
5997 | /* Not the same. */ | |
5998 | if (!iter) | |
5999 | return 0; | |
6000 | } | |
6001 | ||
6002 | return 1; | |
6003 | } | |
6004 | ||
6005 | /* Implement the "print_it" breakpoint_ops method for syscall | |
6006 | catchpoints. */ | |
6007 | ||
6008 | static enum print_stop_action | |
6009 | print_it_catch_syscall (struct breakpoint *b) | |
6010 | { | |
6011 | /* These are needed because we want to know in which state a | |
6012 | syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY | |
6013 | or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we | |
6014 | must print "called syscall" or "returned from syscall". */ | |
6015 | ptid_t ptid; | |
6016 | struct target_waitstatus last; | |
6017 | struct syscall s; | |
6018 | struct cleanup *old_chain; | |
6019 | char *syscall_id; | |
6020 | ||
6021 | get_last_target_status (&ptid, &last); | |
6022 | ||
6023 | get_syscall_by_number (last.value.syscall_number, &s); | |
6024 | ||
6025 | annotate_catchpoint (b->number); | |
6026 | ||
6027 | if (s.name == NULL) | |
6028 | syscall_id = xstrprintf ("%d", last.value.syscall_number); | |
6029 | else | |
6030 | syscall_id = xstrprintf ("'%s'", s.name); | |
6031 | ||
6032 | old_chain = make_cleanup (xfree, syscall_id); | |
6033 | ||
6034 | if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) | |
6035 | printf_filtered (_("\nCatchpoint %d (call to syscall %s), "), | |
6036 | b->number, syscall_id); | |
6037 | else if (last.kind == TARGET_WAITKIND_SYSCALL_RETURN) | |
6038 | printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "), | |
6039 | b->number, syscall_id); | |
6040 | ||
6041 | do_cleanups (old_chain); | |
6042 | ||
6043 | return PRINT_SRC_AND_LOC; | |
6044 | } | |
6045 | ||
6046 | /* Implement the "print_one" breakpoint_ops method for syscall | |
6047 | catchpoints. */ | |
6048 | ||
6049 | static void | |
6050 | print_one_catch_syscall (struct breakpoint *b, | |
6051 | struct bp_location **last_loc) | |
6052 | { | |
6053 | struct value_print_options opts; | |
6054 | ||
6055 | get_user_print_options (&opts); | |
6056 | /* Field 4, the address, is omitted (which makes the columns | |
6057 | not line up too nicely with the headers, but the effect | |
6058 | is relatively readable). */ | |
6059 | if (opts.addressprint) | |
6060 | ui_out_field_skip (uiout, "addr"); | |
6061 | annotate_field (5); | |
6062 | ||
6063 | if (b->syscalls_to_be_caught | |
6064 | && VEC_length (int, b->syscalls_to_be_caught) > 1) | |
6065 | ui_out_text (uiout, "syscalls \""); | |
6066 | else | |
6067 | ui_out_text (uiout, "syscall \""); | |
6068 | ||
6069 | if (b->syscalls_to_be_caught) | |
6070 | { | |
6071 | int i, iter; | |
6072 | char *text = xstrprintf ("%s", ""); | |
6073 | for (i = 0; | |
6074 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6075 | i++) | |
6076 | { | |
6077 | char *x = text; | |
6078 | struct syscall s; | |
6079 | get_syscall_by_number (iter, &s); | |
6080 | ||
6081 | if (s.name != NULL) | |
6082 | text = xstrprintf ("%s%s, ", text, s.name); | |
6083 | else | |
6084 | text = xstrprintf ("%s%d, ", text, iter); | |
6085 | ||
6086 | /* We have to xfree the last 'text' (now stored at 'x') | |
6087 | because xstrprintf dinamically allocates new space for it | |
6088 | on every call. */ | |
6089 | xfree (x); | |
6090 | } | |
6091 | /* Remove the last comma. */ | |
6092 | text[strlen (text) - 2] = '\0'; | |
6093 | ui_out_field_string (uiout, "what", text); | |
6094 | } | |
6095 | else | |
6096 | ui_out_field_string (uiout, "what", "<any syscall>"); | |
6097 | ui_out_text (uiout, "\" "); | |
6098 | } | |
6099 | ||
6100 | /* Implement the "print_mention" breakpoint_ops method for syscall | |
6101 | catchpoints. */ | |
6102 | ||
6103 | static void | |
6104 | print_mention_catch_syscall (struct breakpoint *b) | |
6105 | { | |
6106 | if (b->syscalls_to_be_caught) | |
6107 | { | |
6108 | int i, iter; | |
6109 | ||
6110 | if (VEC_length (int, b->syscalls_to_be_caught) > 1) | |
6111 | printf_filtered (_("Catchpoint %d (syscalls"), b->number); | |
6112 | else | |
6113 | printf_filtered (_("Catchpoint %d (syscall"), b->number); | |
6114 | ||
6115 | for (i = 0; | |
6116 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6117 | i++) | |
6118 | { | |
6119 | struct syscall s; | |
6120 | get_syscall_by_number (iter, &s); | |
6121 | ||
6122 | if (s.name) | |
6123 | printf_filtered (" '%s' [%d]", s.name, s.number); | |
6124 | else | |
6125 | printf_filtered (" %d", s.number); | |
6126 | } | |
6127 | printf_filtered (")"); | |
6128 | } | |
6129 | else | |
6130 | printf_filtered (_("Catchpoint %d (any syscall)"), | |
6131 | b->number); | |
6132 | } | |
6133 | ||
6134 | /* The breakpoint_ops structure to be used in syscall catchpoints. */ | |
6135 | ||
6136 | static struct breakpoint_ops catch_syscall_breakpoint_ops = | |
6137 | { | |
6138 | insert_catch_syscall, | |
6139 | remove_catch_syscall, | |
6140 | breakpoint_hit_catch_syscall, | |
6141 | print_it_catch_syscall, | |
6142 | print_one_catch_syscall, | |
6143 | print_mention_catch_syscall | |
6144 | }; | |
6145 | ||
6146 | /* Returns non-zero if 'b' is a syscall catchpoint. */ | |
6147 | ||
6148 | static int | |
6149 | syscall_catchpoint_p (struct breakpoint *b) | |
6150 | { | |
6151 | return (b->ops == &catch_syscall_breakpoint_ops); | |
6152 | } | |
6153 | ||
6154 | /* Create a new breakpoint of the bp_catchpoint kind and return it, | |
6155 | but does NOT mention it nor update the global location list. | |
6156 | This is useful if you need to fill more fields in the | |
6157 | struct breakpoint before calling mention. | |
ce78b96d JB |
6158 | |
6159 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
6160 | If COND_STRING is not NULL, then store it in the breakpoint. | |
6161 | OPS, if not NULL, is the breakpoint_ops structure associated | |
6162 | to the catchpoint. */ | |
6163 | ||
6164 | static struct breakpoint * | |
a96d9b2e SDJ |
6165 | create_catchpoint_without_mention (struct gdbarch *gdbarch, int tempflag, |
6166 | char *cond_string, | |
6167 | struct breakpoint_ops *ops) | |
c906108c | 6168 | { |
c5aa993b JM |
6169 | struct symtab_and_line sal; |
6170 | struct breakpoint *b; | |
c5aa993b | 6171 | |
fe39c653 | 6172 | init_sal (&sal); |
6c95b8df | 6173 | sal.pspace = current_program_space; |
c5aa993b | 6174 | |
a6d9a66e | 6175 | b = set_raw_breakpoint (gdbarch, sal, bp_catchpoint); |
c906108c SS |
6176 | set_breakpoint_count (breakpoint_count + 1); |
6177 | b->number = breakpoint_count; | |
ce78b96d | 6178 | |
1b36a34b | 6179 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
ce78b96d | 6180 | b->thread = -1; |
c906108c | 6181 | b->addr_string = NULL; |
b5de0fa7 EZ |
6182 | b->enable_state = bp_enabled; |
6183 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
ce78b96d | 6184 | b->ops = ops; |
c5aa993b | 6185 | |
a96d9b2e SDJ |
6186 | return b; |
6187 | } | |
6188 | ||
6189 | /* Create a new breakpoint of the bp_catchpoint kind and return it. | |
6190 | ||
6191 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
6192 | If COND_STRING is not NULL, then store it in the breakpoint. | |
6193 | OPS, if not NULL, is the breakpoint_ops structure associated | |
6194 | to the catchpoint. */ | |
6195 | ||
6196 | static struct breakpoint * | |
6197 | create_catchpoint (struct gdbarch *gdbarch, int tempflag, | |
6198 | char *cond_string, struct breakpoint_ops *ops) | |
6199 | { | |
6200 | struct breakpoint *b = | |
6201 | create_catchpoint_without_mention (gdbarch, tempflag, cond_string, ops); | |
6202 | ||
c906108c | 6203 | mention (b); |
ce78b96d | 6204 | update_global_location_list (1); |
c906108c | 6205 | |
ce78b96d | 6206 | return b; |
c906108c | 6207 | } |
c5aa993b | 6208 | |
9b70b993 | 6209 | static void |
a6d9a66e UW |
6210 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
6211 | int tempflag, char *cond_string, | |
ce78b96d | 6212 | struct breakpoint_ops *ops) |
c906108c | 6213 | { |
a6d9a66e UW |
6214 | struct breakpoint *b |
6215 | = create_catchpoint (gdbarch, tempflag, cond_string, ops); | |
ce78b96d JB |
6216 | |
6217 | /* FIXME: We should put this information in a breakpoint private data | |
6218 | area. */ | |
6219 | b->forked_inferior_pid = null_ptid; | |
c906108c SS |
6220 | } |
6221 | ||
fe798b75 JB |
6222 | /* Exec catchpoints. */ |
6223 | ||
9b70b993 | 6224 | static void |
fe798b75 | 6225 | insert_catch_exec (struct breakpoint *b) |
c906108c | 6226 | { |
fe798b75 JB |
6227 | target_insert_exec_catchpoint (PIDGET (inferior_ptid)); |
6228 | } | |
c906108c | 6229 | |
fe798b75 JB |
6230 | static int |
6231 | remove_catch_exec (struct breakpoint *b) | |
6232 | { | |
6233 | return target_remove_exec_catchpoint (PIDGET (inferior_ptid)); | |
6234 | } | |
c906108c | 6235 | |
fe798b75 JB |
6236 | static int |
6237 | breakpoint_hit_catch_exec (struct breakpoint *b) | |
6238 | { | |
6239 | return inferior_has_execd (inferior_ptid, &b->exec_pathname); | |
6240 | } | |
c906108c | 6241 | |
fe798b75 JB |
6242 | static enum print_stop_action |
6243 | print_it_catch_exec (struct breakpoint *b) | |
6244 | { | |
6245 | annotate_catchpoint (b->number); | |
6246 | printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number, | |
6247 | b->exec_pathname); | |
6248 | return PRINT_SRC_AND_LOC; | |
c906108c SS |
6249 | } |
6250 | ||
fe798b75 | 6251 | static void |
a6d9a66e | 6252 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 JB |
6253 | { |
6254 | struct value_print_options opts; | |
6255 | ||
6256 | get_user_print_options (&opts); | |
6257 | ||
6258 | /* Field 4, the address, is omitted (which makes the columns | |
6259 | not line up too nicely with the headers, but the effect | |
6260 | is relatively readable). */ | |
6261 | if (opts.addressprint) | |
6262 | ui_out_field_skip (uiout, "addr"); | |
6263 | annotate_field (5); | |
6264 | ui_out_text (uiout, "exec"); | |
6265 | if (b->exec_pathname != NULL) | |
6266 | { | |
6267 | ui_out_text (uiout, ", program \""); | |
6268 | ui_out_field_string (uiout, "what", b->exec_pathname); | |
6269 | ui_out_text (uiout, "\" "); | |
6270 | } | |
6271 | } | |
6272 | ||
6273 | static void | |
6274 | print_mention_catch_exec (struct breakpoint *b) | |
6275 | { | |
6276 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
6277 | } | |
6278 | ||
6279 | static struct breakpoint_ops catch_exec_breakpoint_ops = | |
6280 | { | |
6281 | insert_catch_exec, | |
6282 | remove_catch_exec, | |
6283 | breakpoint_hit_catch_exec, | |
6284 | print_it_catch_exec, | |
6285 | print_one_catch_exec, | |
6286 | print_mention_catch_exec | |
6287 | }; | |
6288 | ||
a96d9b2e SDJ |
6289 | static void |
6290 | create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, | |
6291 | struct breakpoint_ops *ops) | |
6292 | { | |
6293 | struct gdbarch *gdbarch = get_current_arch (); | |
6294 | struct breakpoint *b = | |
6295 | create_catchpoint_without_mention (gdbarch, tempflag, NULL, ops); | |
6296 | ||
6297 | b->syscalls_to_be_caught = filter; | |
6298 | ||
6299 | /* Now, we have to mention the breakpoint and update the global | |
6300 | location list. */ | |
6301 | mention (b); | |
6302 | update_global_location_list (1); | |
6303 | } | |
6304 | ||
c906108c | 6305 | static int |
fba45db2 | 6306 | hw_breakpoint_used_count (void) |
c906108c | 6307 | { |
52f0bd74 | 6308 | struct breakpoint *b; |
c906108c SS |
6309 | int i = 0; |
6310 | ||
6311 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6312 | { |
d6b74ac4 | 6313 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
c5aa993b JM |
6314 | i++; |
6315 | } | |
c906108c SS |
6316 | |
6317 | return i; | |
6318 | } | |
6319 | ||
6320 | static int | |
fba45db2 | 6321 | hw_watchpoint_used_count (enum bptype type, int *other_type_used) |
c906108c | 6322 | { |
52f0bd74 | 6323 | struct breakpoint *b; |
c906108c SS |
6324 | int i = 0; |
6325 | ||
6326 | *other_type_used = 0; | |
6327 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6328 | { |
468d015d | 6329 | if (breakpoint_enabled (b)) |
c5aa993b JM |
6330 | { |
6331 | if (b->type == type) | |
6332 | i++; | |
059fb39f PM |
6333 | else if ((b->type == bp_hardware_watchpoint |
6334 | || b->type == bp_read_watchpoint | |
6335 | || b->type == bp_access_watchpoint)) | |
c5aa993b JM |
6336 | *other_type_used = 1; |
6337 | } | |
6338 | } | |
c906108c SS |
6339 | return i; |
6340 | } | |
6341 | ||
c906108c | 6342 | void |
fba45db2 | 6343 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 6344 | { |
c5aa993b | 6345 | struct breakpoint *b; |
c906108c SS |
6346 | |
6347 | ALL_BREAKPOINTS (b) | |
c5aa993b JM |
6348 | { |
6349 | if (((b->type == bp_watchpoint) | |
6350 | || (b->type == bp_hardware_watchpoint) | |
6351 | || (b->type == bp_read_watchpoint) | |
dfdfb3ca | 6352 | || (b->type == bp_access_watchpoint)) |
468d015d | 6353 | && breakpoint_enabled (b)) |
c5aa993b | 6354 | { |
b5de0fa7 | 6355 | b->enable_state = bp_call_disabled; |
b60e7edf | 6356 | update_global_location_list (0); |
c5aa993b JM |
6357 | } |
6358 | } | |
c906108c SS |
6359 | } |
6360 | ||
6361 | void | |
fba45db2 | 6362 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 6363 | { |
c5aa993b | 6364 | struct breakpoint *b; |
c906108c SS |
6365 | |
6366 | ALL_BREAKPOINTS (b) | |
c5aa993b JM |
6367 | { |
6368 | if (((b->type == bp_watchpoint) | |
6369 | || (b->type == bp_hardware_watchpoint) | |
6370 | || (b->type == bp_read_watchpoint) | |
dfdfb3ca | 6371 | || (b->type == bp_access_watchpoint)) |
b5de0fa7 | 6372 | && (b->enable_state == bp_call_disabled)) |
c5aa993b | 6373 | { |
b5de0fa7 | 6374 | b->enable_state = bp_enabled; |
b60e7edf | 6375 | update_global_location_list (1); |
c5aa993b JM |
6376 | } |
6377 | } | |
c906108c SS |
6378 | } |
6379 | ||
8bea4e01 UW |
6380 | void |
6381 | disable_breakpoints_before_startup (void) | |
6382 | { | |
6383 | struct breakpoint *b; | |
6384 | int found = 0; | |
6385 | ||
6386 | ALL_BREAKPOINTS (b) | |
6387 | { | |
6c95b8df PA |
6388 | if (b->pspace != current_program_space) |
6389 | continue; | |
6390 | ||
8bea4e01 UW |
6391 | if ((b->type == bp_breakpoint |
6392 | || b->type == bp_hardware_breakpoint) | |
6393 | && breakpoint_enabled (b)) | |
6394 | { | |
6395 | b->enable_state = bp_startup_disabled; | |
6396 | found = 1; | |
6397 | } | |
6398 | } | |
6399 | ||
6400 | if (found) | |
6401 | update_global_location_list (0); | |
6402 | ||
6c95b8df | 6403 | current_program_space->executing_startup = 1; |
8bea4e01 UW |
6404 | } |
6405 | ||
6406 | void | |
6407 | enable_breakpoints_after_startup (void) | |
6408 | { | |
6409 | struct breakpoint *b; | |
6410 | int found = 0; | |
6411 | ||
6c95b8df | 6412 | current_program_space->executing_startup = 0; |
8bea4e01 UW |
6413 | |
6414 | ALL_BREAKPOINTS (b) | |
6415 | { | |
6c95b8df PA |
6416 | if (b->pspace != current_program_space) |
6417 | continue; | |
6418 | ||
8bea4e01 UW |
6419 | if ((b->type == bp_breakpoint |
6420 | || b->type == bp_hardware_breakpoint) | |
6421 | && b->enable_state == bp_startup_disabled) | |
6422 | { | |
6423 | b->enable_state = bp_enabled; | |
6424 | found = 1; | |
6425 | } | |
6426 | } | |
6427 | ||
6428 | if (found) | |
6429 | breakpoint_re_set (); | |
6430 | } | |
6431 | ||
c906108c SS |
6432 | |
6433 | /* Set a breakpoint that will evaporate an end of command | |
6434 | at address specified by SAL. | |
6435 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
6436 | ||
6437 | struct breakpoint * | |
a6d9a66e UW |
6438 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
6439 | struct frame_id frame_id, enum bptype type) | |
c906108c | 6440 | { |
52f0bd74 | 6441 | struct breakpoint *b; |
edb3359d DJ |
6442 | |
6443 | /* If FRAME_ID is valid, it should be a real frame, not an inlined | |
6444 | one. */ | |
6445 | gdb_assert (!frame_id_inlined_p (frame_id)); | |
6446 | ||
a6d9a66e | 6447 | b = set_raw_breakpoint (gdbarch, sal, type); |
b5de0fa7 EZ |
6448 | b->enable_state = bp_enabled; |
6449 | b->disposition = disp_donttouch; | |
818dd999 | 6450 | b->frame_id = frame_id; |
c906108c SS |
6451 | |
6452 | /* If we're debugging a multi-threaded program, then we | |
6453 | want momentary breakpoints to be active in only a | |
6454 | single thread of control. */ | |
39f77062 KB |
6455 | if (in_thread_list (inferior_ptid)) |
6456 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 6457 | |
b60e7edf | 6458 | update_global_location_list_nothrow (1); |
74960c60 | 6459 | |
c906108c SS |
6460 | return b; |
6461 | } | |
611c83ae | 6462 | |
e58b0e63 PA |
6463 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
6464 | ORIG is NULL. */ | |
6465 | ||
6466 | struct breakpoint * | |
6467 | clone_momentary_breakpoint (struct breakpoint *orig) | |
6468 | { | |
6469 | struct breakpoint *copy; | |
6470 | ||
6471 | /* If there's nothing to clone, then return nothing. */ | |
6472 | if (orig == NULL) | |
6473 | return NULL; | |
6474 | ||
a6d9a66e | 6475 | copy = set_raw_breakpoint_without_location (orig->gdbarch, orig->type); |
e58b0e63 PA |
6476 | copy->loc = allocate_bp_location (copy); |
6477 | set_breakpoint_location_function (copy->loc); | |
6478 | ||
a6d9a66e | 6479 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
6480 | copy->loc->requested_address = orig->loc->requested_address; |
6481 | copy->loc->address = orig->loc->address; | |
6482 | copy->loc->section = orig->loc->section; | |
6c95b8df | 6483 | copy->loc->pspace = orig->loc->pspace; |
e58b0e63 PA |
6484 | |
6485 | if (orig->source_file == NULL) | |
6486 | copy->source_file = NULL; | |
6487 | else | |
6488 | copy->source_file = xstrdup (orig->source_file); | |
6489 | ||
6490 | copy->line_number = orig->line_number; | |
6491 | copy->frame_id = orig->frame_id; | |
6492 | copy->thread = orig->thread; | |
6c95b8df | 6493 | copy->pspace = orig->pspace; |
e58b0e63 PA |
6494 | |
6495 | copy->enable_state = bp_enabled; | |
6496 | copy->disposition = disp_donttouch; | |
6497 | copy->number = internal_breakpoint_number--; | |
6498 | ||
6499 | update_global_location_list_nothrow (0); | |
6500 | return copy; | |
6501 | } | |
6502 | ||
611c83ae | 6503 | struct breakpoint * |
a6d9a66e UW |
6504 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
6505 | enum bptype type) | |
611c83ae PA |
6506 | { |
6507 | struct symtab_and_line sal; | |
6508 | ||
6509 | sal = find_pc_line (pc, 0); | |
6510 | sal.pc = pc; | |
6511 | sal.section = find_pc_overlay (pc); | |
6512 | sal.explicit_pc = 1; | |
6513 | ||
a6d9a66e | 6514 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 6515 | } |
c906108c | 6516 | \f |
c5aa993b | 6517 | |
c906108c SS |
6518 | /* Tell the user we have just set a breakpoint B. */ |
6519 | ||
6520 | static void | |
fba45db2 | 6521 | mention (struct breakpoint *b) |
c906108c SS |
6522 | { |
6523 | int say_where = 0; | |
fa8a61dc | 6524 | struct cleanup *ui_out_chain; |
79a45b7d TT |
6525 | struct value_print_options opts; |
6526 | ||
6527 | get_user_print_options (&opts); | |
8b93c638 | 6528 | |
9a4105ab AC |
6529 | /* FIXME: This is misplaced; mention() is called by things (like |
6530 | hitting a watchpoint) other than breakpoint creation. It should | |
6531 | be possible to clean this up and at the same time replace the | |
7f4b89d1 | 6532 | random calls to breakpoint_changed with this hook. */ |
383f836e | 6533 | observer_notify_breakpoint_created (b->number); |
c906108c | 6534 | |
3086aeae DJ |
6535 | if (b->ops != NULL && b->ops->print_mention != NULL) |
6536 | b->ops->print_mention (b); | |
6537 | else | |
6538 | switch (b->type) | |
6539 | { | |
6540 | case bp_none: | |
a3f17187 | 6541 | printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b->number); |
3086aeae DJ |
6542 | break; |
6543 | case bp_watchpoint: | |
6544 | ui_out_text (uiout, "Watchpoint "); | |
6545 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
6546 | ui_out_field_int (uiout, "number", b->number); | |
6547 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6548 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6549 | do_cleanups (ui_out_chain); |
6550 | break; | |
6551 | case bp_hardware_watchpoint: | |
6552 | ui_out_text (uiout, "Hardware watchpoint "); | |
6553 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
6554 | ui_out_field_int (uiout, "number", b->number); | |
6555 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6556 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6557 | do_cleanups (ui_out_chain); |
6558 | break; | |
6559 | case bp_read_watchpoint: | |
6560 | ui_out_text (uiout, "Hardware read watchpoint "); | |
6561 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
6562 | ui_out_field_int (uiout, "number", b->number); | |
6563 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6564 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6565 | do_cleanups (ui_out_chain); |
6566 | break; | |
6567 | case bp_access_watchpoint: | |
6568 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
6569 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
6570 | ui_out_field_int (uiout, "number", b->number); | |
6571 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6572 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6573 | do_cleanups (ui_out_chain); |
6574 | break; | |
6575 | case bp_breakpoint: | |
6576 | if (ui_out_is_mi_like_p (uiout)) | |
6577 | { | |
6578 | say_where = 0; | |
6579 | break; | |
6580 | } | |
2cec12e5 AR |
6581 | if (b->disposition == disp_del) |
6582 | printf_filtered (_("Temporary breakpoint")); | |
6583 | else | |
6584 | printf_filtered (_("Breakpoint")); | |
6585 | printf_filtered (_(" %d"), b->number); | |
3086aeae DJ |
6586 | say_where = 1; |
6587 | break; | |
6588 | case bp_hardware_breakpoint: | |
6589 | if (ui_out_is_mi_like_p (uiout)) | |
6590 | { | |
6591 | say_where = 0; | |
6592 | break; | |
6593 | } | |
a3f17187 | 6594 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); |
3086aeae DJ |
6595 | say_where = 1; |
6596 | break; | |
1042e4c0 SS |
6597 | case bp_tracepoint: |
6598 | if (ui_out_is_mi_like_p (uiout)) | |
6599 | { | |
6600 | say_where = 0; | |
6601 | break; | |
6602 | } | |
6603 | printf_filtered (_("Tracepoint")); | |
6604 | printf_filtered (_(" %d"), b->number); | |
6605 | say_where = 1; | |
6606 | break; | |
7a697b8d SS |
6607 | case bp_fast_tracepoint: |
6608 | if (ui_out_is_mi_like_p (uiout)) | |
6609 | { | |
6610 | say_where = 0; | |
6611 | break; | |
6612 | } | |
6613 | printf_filtered (_("Fast tracepoint")); | |
6614 | printf_filtered (_(" %d"), b->number); | |
6615 | say_where = 1; | |
6616 | break; | |
3086aeae DJ |
6617 | |
6618 | case bp_until: | |
6619 | case bp_finish: | |
6620 | case bp_longjmp: | |
6621 | case bp_longjmp_resume: | |
6622 | case bp_step_resume: | |
3086aeae | 6623 | case bp_call_dummy: |
aa7d318d | 6624 | case bp_std_terminate: |
3086aeae DJ |
6625 | case bp_watchpoint_scope: |
6626 | case bp_shlib_event: | |
6627 | case bp_thread_event: | |
6628 | case bp_overlay_event: | |
4efc6507 | 6629 | case bp_jit_event: |
0fd8e87f | 6630 | case bp_longjmp_master: |
aa7d318d | 6631 | case bp_std_terminate_master: |
3086aeae DJ |
6632 | break; |
6633 | } | |
c906108c | 6634 | |
c906108c SS |
6635 | if (say_where) |
6636 | { | |
a3f17187 AC |
6637 | /* i18n: cagney/2005-02-11: Below needs to be merged into a |
6638 | single string. */ | |
0d381245 | 6639 | if (b->loc == NULL) |
c906108c | 6640 | { |
a3f17187 | 6641 | printf_filtered (_(" (%s) pending."), b->addr_string); |
0101ce28 JJ |
6642 | } |
6643 | else | |
6644 | { | |
79a45b7d | 6645 | if (opts.addressprint || b->source_file == NULL) |
0101ce28 JJ |
6646 | { |
6647 | printf_filtered (" at "); | |
5af949e3 UW |
6648 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), |
6649 | gdb_stdout); | |
0101ce28 JJ |
6650 | } |
6651 | if (b->source_file) | |
6652 | printf_filtered (": file %s, line %d.", | |
6653 | b->source_file, b->line_number); | |
0d381245 VP |
6654 | |
6655 | if (b->loc->next) | |
6656 | { | |
6657 | struct bp_location *loc = b->loc; | |
6658 | int n = 0; | |
6659 | for (; loc; loc = loc->next) | |
6660 | ++n; | |
6661 | printf_filtered (" (%d locations)", n); | |
6662 | } | |
6663 | ||
c906108c | 6664 | } |
c906108c | 6665 | } |
9dc5e2a9 | 6666 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 6667 | return; |
c906108c SS |
6668 | printf_filtered ("\n"); |
6669 | } | |
c906108c | 6670 | \f |
c5aa993b | 6671 | |
0d381245 | 6672 | static struct bp_location * |
39d61571 | 6673 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
6674 | const struct symtab_and_line *sal) |
6675 | { | |
6676 | struct bp_location *loc, **tmp; | |
6677 | ||
39d61571 | 6678 | loc = allocate_bp_location (b); |
0d381245 VP |
6679 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
6680 | ; | |
6681 | *tmp = loc; | |
a6d9a66e UW |
6682 | loc->gdbarch = get_sal_arch (*sal); |
6683 | if (!loc->gdbarch) | |
6684 | loc->gdbarch = b->gdbarch; | |
0d381245 | 6685 | loc->requested_address = sal->pc; |
a6d9a66e UW |
6686 | loc->address = adjust_breakpoint_address (loc->gdbarch, |
6687 | loc->requested_address, b->type); | |
6c95b8df PA |
6688 | loc->pspace = sal->pspace; |
6689 | gdb_assert (loc->pspace != NULL); | |
0d381245 VP |
6690 | loc->section = sal->section; |
6691 | ||
6692 | set_breakpoint_location_function (loc); | |
6693 | return loc; | |
6694 | } | |
514f746b AR |
6695 | \f |
6696 | ||
6697 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
6698 | return 0 otherwise. */ | |
6699 | ||
6700 | static int | |
6701 | bp_loc_is_permanent (struct bp_location *loc) | |
6702 | { | |
6703 | int len; | |
6704 | CORE_ADDR addr; | |
6705 | const gdb_byte *brk; | |
6706 | gdb_byte *target_mem; | |
939c61fa JK |
6707 | struct cleanup *cleanup; |
6708 | int retval = 0; | |
514f746b AR |
6709 | |
6710 | gdb_assert (loc != NULL); | |
6711 | ||
6712 | addr = loc->address; | |
a6d9a66e | 6713 | brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 6714 | |
939c61fa JK |
6715 | /* Software breakpoints unsupported? */ |
6716 | if (brk == NULL) | |
6717 | return 0; | |
6718 | ||
514f746b AR |
6719 | target_mem = alloca (len); |
6720 | ||
939c61fa JK |
6721 | /* Enable the automatic memory restoration from breakpoints while |
6722 | we read the memory. Otherwise we could say about our temporary | |
6723 | breakpoints they are permanent. */ | |
6c95b8df PA |
6724 | cleanup = save_current_space_and_thread (); |
6725 | ||
6726 | switch_to_program_space_and_thread (loc->pspace); | |
6727 | make_show_memory_breakpoints_cleanup (0); | |
939c61fa | 6728 | |
514f746b AR |
6729 | if (target_read_memory (loc->address, target_mem, len) == 0 |
6730 | && memcmp (target_mem, brk, len) == 0) | |
939c61fa | 6731 | retval = 1; |
514f746b | 6732 | |
939c61fa JK |
6733 | do_cleanups (cleanup); |
6734 | ||
6735 | return retval; | |
514f746b AR |
6736 | } |
6737 | ||
6738 | ||
c3f6f71d | 6739 | |
018d34a4 VP |
6740 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
6741 | as textual description of the location, and COND_STRING | |
db107f19 | 6742 | as condition expression. */ |
018d34a4 VP |
6743 | |
6744 | static void | |
8cdf0e15 VP |
6745 | create_breakpoint_sal (struct gdbarch *gdbarch, |
6746 | struct symtabs_and_lines sals, char *addr_string, | |
6747 | char *cond_string, | |
6748 | enum bptype type, enum bpdisp disposition, | |
6749 | int thread, int task, int ignore_count, | |
6750 | struct breakpoint_ops *ops, int from_tty, int enabled) | |
018d34a4 | 6751 | { |
0d381245 VP |
6752 | struct breakpoint *b = NULL; |
6753 | int i; | |
018d34a4 VP |
6754 | |
6755 | if (type == bp_hardware_breakpoint) | |
6756 | { | |
6757 | int i = hw_breakpoint_used_count (); | |
6758 | int target_resources_ok = | |
d92524f1 | 6759 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
018d34a4 VP |
6760 | i + 1, 0); |
6761 | if (target_resources_ok == 0) | |
6762 | error (_("No hardware breakpoint support in the target.")); | |
6763 | else if (target_resources_ok < 0) | |
6764 | error (_("Hardware breakpoints used exceeds limit.")); | |
6765 | } | |
6766 | ||
6c95b8df PA |
6767 | gdb_assert (sals.nelts > 0); |
6768 | ||
0d381245 VP |
6769 | for (i = 0; i < sals.nelts; ++i) |
6770 | { | |
6771 | struct symtab_and_line sal = sals.sals[i]; | |
6772 | struct bp_location *loc; | |
6773 | ||
6774 | if (from_tty) | |
5af949e3 UW |
6775 | { |
6776 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
6777 | if (!loc_gdbarch) | |
6778 | loc_gdbarch = gdbarch; | |
6779 | ||
6780 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 6781 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 6782 | } |
0d381245 VP |
6783 | |
6784 | if (i == 0) | |
6785 | { | |
a6d9a66e | 6786 | b = set_raw_breakpoint (gdbarch, sal, type); |
0d381245 VP |
6787 | set_breakpoint_count (breakpoint_count + 1); |
6788 | b->number = breakpoint_count; | |
6789 | b->thread = thread; | |
4a306c9a | 6790 | b->task = task; |
018d34a4 | 6791 | |
0d381245 VP |
6792 | b->cond_string = cond_string; |
6793 | b->ignore_count = ignore_count; | |
41447f92 | 6794 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 6795 | b->disposition = disposition; |
018d34a4 | 6796 | |
6c95b8df PA |
6797 | b->pspace = sals.sals[0].pspace; |
6798 | ||
6799 | if (enabled && b->pspace->executing_startup | |
8bea4e01 UW |
6800 | && (b->type == bp_breakpoint |
6801 | || b->type == bp_hardware_breakpoint)) | |
6802 | b->enable_state = bp_startup_disabled; | |
6803 | ||
0d381245 VP |
6804 | loc = b->loc; |
6805 | } | |
6806 | else | |
018d34a4 | 6807 | { |
39d61571 | 6808 | loc = add_location_to_breakpoint (b, &sal); |
0d381245 VP |
6809 | } |
6810 | ||
514f746b AR |
6811 | if (bp_loc_is_permanent (loc)) |
6812 | make_breakpoint_permanent (b); | |
6813 | ||
0d381245 VP |
6814 | if (b->cond_string) |
6815 | { | |
6816 | char *arg = b->cond_string; | |
d32a6982 | 6817 | loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0); |
0d381245 | 6818 | if (*arg) |
db107f19 | 6819 | error (_("Garbage %s follows condition"), arg); |
018d34a4 | 6820 | } |
0d381245 | 6821 | } |
018d34a4 VP |
6822 | |
6823 | if (addr_string) | |
6824 | b->addr_string = addr_string; | |
6825 | else | |
6826 | /* addr_string has to be used or breakpoint_re_set will delete | |
6827 | me. */ | |
5af949e3 UW |
6828 | b->addr_string |
6829 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
018d34a4 | 6830 | |
604133b5 | 6831 | b->ops = ops; |
018d34a4 VP |
6832 | mention (b); |
6833 | } | |
6834 | ||
ed0616c6 VP |
6835 | /* Remove element at INDEX_TO_REMOVE from SAL, shifting other |
6836 | elements to fill the void space. */ | |
2c0b251b PA |
6837 | static void |
6838 | remove_sal (struct symtabs_and_lines *sal, int index_to_remove) | |
ed0616c6 VP |
6839 | { |
6840 | int i = index_to_remove+1; | |
6841 | int last_index = sal->nelts-1; | |
6842 | ||
6843 | for (;i <= last_index; ++i) | |
6844 | sal->sals[i-1] = sal->sals[i]; | |
6845 | ||
6846 | --(sal->nelts); | |
6847 | } | |
6848 | ||
6c95b8df PA |
6849 | /* If appropriate, obtains all sals that correspond to the same file |
6850 | and line as SAL, in all program spaces. Users debugging with IDEs, | |
6851 | will want to set a breakpoint at foo.c:line, and not really care | |
6852 | about program spaces. This is done only if SAL does not have | |
6853 | explicit PC and has line and file information. If we got just a | |
6854 | single expanded sal, return the original. | |
ed0616c6 | 6855 | |
6c95b8df PA |
6856 | Otherwise, if SAL.explicit_line is not set, filter out all sals for |
6857 | which the name of enclosing function is different from SAL. This | |
6858 | makes sure that if we have breakpoint originally set in template | |
6859 | instantiation, say foo<int>(), we won't expand SAL to locations at | |
6860 | the same line in all existing instantiations of 'foo'. */ | |
ed0616c6 | 6861 | |
2c0b251b | 6862 | static struct symtabs_and_lines |
ed0616c6 VP |
6863 | expand_line_sal_maybe (struct symtab_and_line sal) |
6864 | { | |
6865 | struct symtabs_and_lines expanded; | |
6866 | CORE_ADDR original_pc = sal.pc; | |
6867 | char *original_function = NULL; | |
6868 | int found; | |
6869 | int i; | |
6c95b8df | 6870 | struct cleanup *old_chain; |
ed0616c6 VP |
6871 | |
6872 | /* If we have explicit pc, don't expand. | |
6873 | If we have no line number, we can't expand. */ | |
6874 | if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL) | |
6875 | { | |
6876 | expanded.nelts = 1; | |
6877 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
6878 | expanded.sals[0] = sal; | |
6879 | return expanded; | |
6880 | } | |
6881 | ||
6882 | sal.pc = 0; | |
6c95b8df PA |
6883 | |
6884 | old_chain = save_current_space_and_thread (); | |
6885 | ||
6886 | switch_to_program_space_and_thread (sal.pspace); | |
6887 | ||
ed0616c6 | 6888 | find_pc_partial_function (original_pc, &original_function, NULL, NULL); |
6c95b8df PA |
6889 | |
6890 | /* Note that expand_line_sal visits *all* program spaces. */ | |
ed0616c6 | 6891 | expanded = expand_line_sal (sal); |
6c95b8df | 6892 | |
ed0616c6 VP |
6893 | if (expanded.nelts == 1) |
6894 | { | |
3dba1c98 JB |
6895 | /* We had one sal, we got one sal. Return that sal, adjusting it |
6896 | past the function prologue if necessary. */ | |
ed0616c6 VP |
6897 | xfree (expanded.sals); |
6898 | expanded.nelts = 1; | |
6899 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
6900 | sal.pc = original_pc; | |
6901 | expanded.sals[0] = sal; | |
3dba1c98 | 6902 | skip_prologue_sal (&expanded.sals[0]); |
6c95b8df | 6903 | do_cleanups (old_chain); |
ed0616c6 VP |
6904 | return expanded; |
6905 | } | |
6906 | ||
6907 | if (!sal.explicit_line) | |
6908 | { | |
6909 | CORE_ADDR func_addr, func_end; | |
6910 | for (i = 0; i < expanded.nelts; ++i) | |
6911 | { | |
6912 | CORE_ADDR pc = expanded.sals[i].pc; | |
6913 | char *this_function; | |
6c95b8df PA |
6914 | |
6915 | /* We need to switch threads as well since we're about to | |
6916 | read memory. */ | |
6917 | switch_to_program_space_and_thread (expanded.sals[i].pspace); | |
6918 | ||
ed0616c6 VP |
6919 | if (find_pc_partial_function (pc, &this_function, |
6920 | &func_addr, &func_end)) | |
6921 | { | |
059fb39f PM |
6922 | if (this_function |
6923 | && strcmp (this_function, original_function) != 0) | |
ed0616c6 VP |
6924 | { |
6925 | remove_sal (&expanded, i); | |
6926 | --i; | |
6927 | } | |
6928 | else if (func_addr == pc) | |
6929 | { | |
6930 | /* We're at beginning of a function, and should | |
6931 | skip prologue. */ | |
6932 | struct symbol *sym = find_pc_function (pc); | |
6933 | if (sym) | |
6934 | expanded.sals[i] = find_function_start_sal (sym, 1); | |
6935 | else | |
d80b854b UW |
6936 | { |
6937 | /* Since find_pc_partial_function returned true, | |
6938 | we should really always find the section here. */ | |
6939 | struct obj_section *section = find_pc_section (pc); | |
6940 | if (section) | |
6941 | { | |
6942 | struct gdbarch *gdbarch | |
6943 | = get_objfile_arch (section->objfile); | |
6944 | expanded.sals[i].pc | |
6945 | = gdbarch_skip_prologue (gdbarch, pc); | |
6946 | } | |
6947 | } | |
ed0616c6 VP |
6948 | } |
6949 | } | |
6950 | } | |
6951 | } | |
3daf8fe5 JG |
6952 | else |
6953 | { | |
6954 | for (i = 0; i < expanded.nelts; ++i) | |
6955 | { | |
6956 | /* If this SAL corresponds to a breakpoint inserted using a | |
6957 | line number, then skip the function prologue if necessary. */ | |
6958 | skip_prologue_sal (&expanded.sals[i]); | |
6959 | } | |
6960 | } | |
ed0616c6 | 6961 | |
6c95b8df PA |
6962 | do_cleanups (old_chain); |
6963 | ||
ed0616c6 VP |
6964 | if (expanded.nelts <= 1) |
6965 | { | |
6966 | /* This is un ugly workaround. If we get zero | |
6967 | expanded sals then something is really wrong. | |
6968 | Fix that by returnign the original sal. */ | |
6969 | xfree (expanded.sals); | |
6970 | expanded.nelts = 1; | |
6971 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
6972 | sal.pc = original_pc; | |
6973 | expanded.sals[0] = sal; | |
6974 | return expanded; | |
6975 | } | |
6976 | ||
6977 | if (original_pc) | |
6978 | { | |
6979 | found = 0; | |
6980 | for (i = 0; i < expanded.nelts; ++i) | |
6981 | if (expanded.sals[i].pc == original_pc) | |
6982 | { | |
6983 | found = 1; | |
6984 | break; | |
6985 | } | |
6986 | gdb_assert (found); | |
6987 | } | |
6988 | ||
6989 | return expanded; | |
6990 | } | |
6991 | ||
018d34a4 VP |
6992 | /* Add SALS.nelts breakpoints to the breakpoint table. For each |
6993 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
6994 | value. COND_STRING, if not NULL, specified the condition to be | |
6995 | used for all breakpoints. Essentially the only case where | |
6996 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
6997 | function. In that case, it's still not possible to specify | |
6998 | separate conditions for different overloaded functions, so | |
6999 | we take just a single condition string. | |
7000 | ||
c3f6f71d | 7001 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 7002 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
7003 | array contents). If the function fails (error() is called), the |
7004 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
7005 | COND and SALS arrays and each of those arrays contents. */ | |
c906108c SS |
7006 | |
7007 | static void | |
8cdf0e15 VP |
7008 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7009 | struct symtabs_and_lines sals, char **addr_string, | |
7010 | char *cond_string, | |
7011 | enum bptype type, enum bpdisp disposition, | |
7012 | int thread, int task, int ignore_count, | |
7013 | struct breakpoint_ops *ops, int from_tty, | |
7014 | int enabled) | |
c906108c | 7015 | { |
018d34a4 VP |
7016 | int i; |
7017 | for (i = 0; i < sals.nelts; ++i) | |
c3f6f71d | 7018 | { |
ed0616c6 VP |
7019 | struct symtabs_and_lines expanded = |
7020 | expand_line_sal_maybe (sals.sals[i]); | |
0d381245 | 7021 | |
8cdf0e15 VP |
7022 | create_breakpoint_sal (gdbarch, expanded, addr_string[i], |
7023 | cond_string, type, disposition, | |
7024 | thread, task, ignore_count, ops, from_tty, enabled); | |
c3f6f71d | 7025 | } |
c3f6f71d | 7026 | } |
c906108c | 7027 | |
c3f6f71d JM |
7028 | /* Parse ARG which is assumed to be a SAL specification possibly |
7029 | followed by conditionals. On return, SALS contains an array of SAL | |
7030 | addresses found. ADDR_STRING contains a vector of (canonical) | |
7031 | address strings. ARG points to the end of the SAL. */ | |
c906108c | 7032 | |
b9362cc7 | 7033 | static void |
c3f6f71d JM |
7034 | parse_breakpoint_sals (char **address, |
7035 | struct symtabs_and_lines *sals, | |
0101ce28 JJ |
7036 | char ***addr_string, |
7037 | int *not_found_ptr) | |
c3f6f71d JM |
7038 | { |
7039 | char *addr_start = *address; | |
7040 | *addr_string = NULL; | |
7041 | /* If no arg given, or if first arg is 'if ', use the default | |
7042 | breakpoint. */ | |
7043 | if ((*address) == NULL | |
7044 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c SS |
7045 | { |
7046 | if (default_breakpoint_valid) | |
7047 | { | |
c3f6f71d | 7048 | struct symtab_and_line sal; |
fe39c653 | 7049 | init_sal (&sal); /* initialize to zeroes */ |
c3f6f71d | 7050 | sals->sals = (struct symtab_and_line *) |
c906108c SS |
7051 | xmalloc (sizeof (struct symtab_and_line)); |
7052 | sal.pc = default_breakpoint_address; | |
7053 | sal.line = default_breakpoint_line; | |
7054 | sal.symtab = default_breakpoint_symtab; | |
6c95b8df | 7055 | sal.pspace = default_breakpoint_pspace; |
c5aa993b | 7056 | sal.section = find_pc_overlay (sal.pc); |
00903456 JK |
7057 | |
7058 | /* "break" without arguments is equivalent to "break *PC" where PC is | |
7059 | the default_breakpoint_address. So make sure to set | |
7060 | sal.explicit_pc to prevent GDB from trying to expand the list of | |
7061 | sals to include all other instances with the same symtab and line. | |
7062 | */ | |
7063 | sal.explicit_pc = 1; | |
7064 | ||
c3f6f71d JM |
7065 | sals->sals[0] = sal; |
7066 | sals->nelts = 1; | |
c906108c SS |
7067 | } |
7068 | else | |
8a3fe4f8 | 7069 | error (_("No default breakpoint address now.")); |
c906108c SS |
7070 | } |
7071 | else | |
7072 | { | |
c906108c | 7073 | /* Force almost all breakpoints to be in terms of the |
c5aa993b JM |
7074 | current_source_symtab (which is decode_line_1's default). This |
7075 | should produce the results we want almost all of the time while | |
1aeae86e AF |
7076 | leaving default_breakpoint_* alone. |
7077 | ObjC: However, don't match an Objective-C method name which | |
7078 | may have a '+' or '-' succeeded by a '[' */ | |
0378c332 | 7079 | |
c214a6fd | 7080 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
0378c332 | 7081 | |
c906108c | 7082 | if (default_breakpoint_valid |
0378c332 | 7083 | && (!cursal.symtab |
1aeae86e AF |
7084 | || ((strchr ("+-", (*address)[0]) != NULL) |
7085 | && ((*address)[1] != '[')))) | |
c3f6f71d | 7086 | *sals = decode_line_1 (address, 1, default_breakpoint_symtab, |
0101ce28 JJ |
7087 | default_breakpoint_line, addr_string, |
7088 | not_found_ptr); | |
c906108c | 7089 | else |
0101ce28 JJ |
7090 | *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, |
7091 | addr_string, not_found_ptr); | |
c906108c | 7092 | } |
c3f6f71d JM |
7093 | /* For any SAL that didn't have a canonical string, fill one in. */ |
7094 | if (sals->nelts > 0 && *addr_string == NULL) | |
7095 | *addr_string = xcalloc (sals->nelts, sizeof (char **)); | |
7096 | if (addr_start != (*address)) | |
c906108c | 7097 | { |
c3f6f71d JM |
7098 | int i; |
7099 | for (i = 0; i < sals->nelts; i++) | |
c906108c | 7100 | { |
c3f6f71d JM |
7101 | /* Add the string if not present. */ |
7102 | if ((*addr_string)[i] == NULL) | |
7103 | (*addr_string)[i] = savestring (addr_start, (*address) - addr_start); | |
c906108c SS |
7104 | } |
7105 | } | |
c3f6f71d | 7106 | } |
c906108c | 7107 | |
c906108c | 7108 | |
c3f6f71d JM |
7109 | /* Convert each SAL into a real PC. Verify that the PC can be |
7110 | inserted as a breakpoint. If it can't throw an error. */ | |
c906108c | 7111 | |
b9362cc7 | 7112 | static void |
c3f6f71d JM |
7113 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals, |
7114 | char *address) | |
7115 | { | |
7116 | int i; | |
7117 | for (i = 0; i < sals->nelts; i++) | |
ee53e872 | 7118 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
7119 | } |
7120 | ||
7a697b8d SS |
7121 | /* Fast tracepoints may have restrictions on valid locations. For |
7122 | instance, a fast tracepoint using a jump instead of a trap will | |
7123 | likely have to overwrite more bytes than a trap would, and so can | |
7124 | only be placed where the instruction is longer than the jump, or a | |
7125 | multi-instruction sequence does not have a jump into the middle of | |
7126 | it, etc. */ | |
7127 | ||
7128 | static void | |
7129 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
7130 | struct symtabs_and_lines *sals) | |
7131 | { | |
7132 | int i, rslt; | |
7133 | struct symtab_and_line *sal; | |
7134 | char *msg; | |
7135 | struct cleanup *old_chain; | |
7136 | ||
7137 | for (i = 0; i < sals->nelts; i++) | |
7138 | { | |
7139 | sal = &sals->sals[i]; | |
7140 | ||
7141 | rslt = gdbarch_fast_tracepoint_valid_at (gdbarch, sal->pc, | |
7142 | NULL, &msg); | |
7143 | old_chain = make_cleanup (xfree, msg); | |
7144 | ||
7145 | if (!rslt) | |
7146 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
7147 | paddress (gdbarch, sal->pc), (msg ? msg : "")); | |
7148 | ||
7149 | do_cleanups (old_chain); | |
7150 | } | |
7151 | } | |
7152 | ||
05ff989b | 7153 | static void |
0101ce28 JJ |
7154 | do_captured_parse_breakpoint (struct ui_out *ui, void *data) |
7155 | { | |
7156 | struct captured_parse_breakpoint_args *args = data; | |
7157 | ||
7158 | parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p, | |
7159 | args->not_found_ptr); | |
0101ce28 JJ |
7160 | } |
7161 | ||
018d34a4 VP |
7162 | /* Given TOK, a string specification of condition and thread, as |
7163 | accepted by the 'break' command, extract the condition | |
7164 | string and thread number and set *COND_STRING and *THREAD. | |
7165 | PC identifies the context at which the condition should be parsed. | |
7166 | If no condition is found, *COND_STRING is set to NULL. | |
7167 | If no thread is found, *THREAD is set to -1. */ | |
7168 | static void | |
7169 | find_condition_and_thread (char *tok, CORE_ADDR pc, | |
4a306c9a | 7170 | char **cond_string, int *thread, int *task) |
018d34a4 VP |
7171 | { |
7172 | *cond_string = NULL; | |
7173 | *thread = -1; | |
7174 | while (tok && *tok) | |
7175 | { | |
7176 | char *end_tok; | |
7177 | int toklen; | |
7178 | char *cond_start = NULL; | |
7179 | char *cond_end = NULL; | |
7180 | while (*tok == ' ' || *tok == '\t') | |
7181 | tok++; | |
7182 | ||
7183 | end_tok = tok; | |
7184 | ||
7185 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
7186 | end_tok++; | |
7187 | ||
7188 | toklen = end_tok - tok; | |
7189 | ||
7190 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
7191 | { | |
f7545552 TT |
7192 | struct expression *expr; |
7193 | ||
018d34a4 | 7194 | tok = cond_start = end_tok + 1; |
f7545552 TT |
7195 | expr = parse_exp_1 (&tok, block_for_pc (pc), 0); |
7196 | xfree (expr); | |
018d34a4 VP |
7197 | cond_end = tok; |
7198 | *cond_string = savestring (cond_start, | |
7199 | cond_end - cond_start); | |
7200 | } | |
7201 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
7202 | { | |
7203 | char *tmptok; | |
7204 | ||
7205 | tok = end_tok + 1; | |
7206 | tmptok = tok; | |
7207 | *thread = strtol (tok, &tok, 0); | |
7208 | if (tok == tmptok) | |
7209 | error (_("Junk after thread keyword.")); | |
7210 | if (!valid_thread_id (*thread)) | |
7211 | error (_("Unknown thread %d."), *thread); | |
7212 | } | |
4a306c9a JB |
7213 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
7214 | { | |
7215 | char *tmptok; | |
7216 | ||
7217 | tok = end_tok + 1; | |
7218 | tmptok = tok; | |
7219 | *task = strtol (tok, &tok, 0); | |
7220 | if (tok == tmptok) | |
7221 | error (_("Junk after task keyword.")); | |
7222 | if (!valid_task_id (*task)) | |
b6199126 | 7223 | error (_("Unknown task %d."), *task); |
4a306c9a | 7224 | } |
018d34a4 VP |
7225 | else |
7226 | error (_("Junk at end of arguments.")); | |
7227 | } | |
7228 | } | |
7229 | ||
fd9b8c24 PA |
7230 | /* Set a breakpoint. This function is shared between CLI and MI |
7231 | functions for setting a breakpoint. This function has two major | |
7232 | modes of operations, selected by the PARSE_CONDITION_AND_THREAD | |
7233 | parameter. If non-zero, the function will parse arg, extracting | |
7234 | breakpoint location, address and thread. Otherwise, ARG is just the | |
7235 | location of breakpoint, with condition and thread specified by the | |
7236 | COND_STRING and THREAD parameters. Returns true if any breakpoint | |
7237 | was created; false otherwise. */ | |
0101ce28 | 7238 | |
8cdf0e15 VP |
7239 | int |
7240 | create_breakpoint (struct gdbarch *gdbarch, | |
7241 | char *arg, char *cond_string, int thread, | |
7242 | int parse_condition_and_thread, | |
7243 | int tempflag, int hardwareflag, int traceflag, | |
7244 | int ignore_count, | |
7245 | enum auto_boolean pending_break_support, | |
7246 | struct breakpoint_ops *ops, | |
7247 | int from_tty, | |
7248 | int enabled) | |
c3f6f71d | 7249 | { |
71fff37b | 7250 | struct gdb_exception e; |
c3f6f71d | 7251 | struct symtabs_and_lines sals; |
0101ce28 | 7252 | struct symtab_and_line pending_sal; |
0101ce28 JJ |
7253 | char *copy_arg; |
7254 | char *err_msg; | |
c3f6f71d JM |
7255 | char *addr_start = arg; |
7256 | char **addr_string; | |
7257 | struct cleanup *old_chain; | |
80c99de1 | 7258 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 7259 | struct captured_parse_breakpoint_args parse_args; |
05ff989b | 7260 | int i; |
0101ce28 | 7261 | int pending = 0; |
0101ce28 | 7262 | int not_found = 0; |
1042e4c0 | 7263 | enum bptype type_wanted; |
4a306c9a | 7264 | int task = 0; |
95a42b64 | 7265 | int first_bp_set = breakpoint_count + 1; |
c3f6f71d | 7266 | |
c3f6f71d JM |
7267 | sals.sals = NULL; |
7268 | sals.nelts = 0; | |
7269 | addr_string = NULL; | |
c3f6f71d | 7270 | |
0101ce28 JJ |
7271 | parse_args.arg_p = &arg; |
7272 | parse_args.sals_p = &sals; | |
7273 | parse_args.addr_string_p = &addr_string; | |
7274 | parse_args.not_found_ptr = ¬_found; | |
7275 | ||
05ff989b AC |
7276 | e = catch_exception (uiout, do_captured_parse_breakpoint, |
7277 | &parse_args, RETURN_MASK_ALL); | |
0101ce28 JJ |
7278 | |
7279 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 7280 | switch (e.reason) |
0101ce28 | 7281 | { |
05ff989b | 7282 | case RETURN_QUIT: |
98deb0da | 7283 | throw_exception (e); |
05ff989b AC |
7284 | case RETURN_ERROR: |
7285 | switch (e.error) | |
0101ce28 | 7286 | { |
05ff989b | 7287 | case NOT_FOUND_ERROR: |
0101ce28 | 7288 | |
05ff989b AC |
7289 | /* If pending breakpoint support is turned off, throw |
7290 | error. */ | |
fa8d40ab JJ |
7291 | |
7292 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
7293 | throw_exception (e); |
7294 | ||
7295 | exception_print (gdb_stderr, e); | |
fa8d40ab | 7296 | |
05ff989b AC |
7297 | /* If pending breakpoint support is auto query and the user |
7298 | selects no, then simply return the error code. */ | |
059fb39f PM |
7299 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
7300 | && !nquery ("Make breakpoint pending on future shared library load? ")) | |
fd9b8c24 | 7301 | return 0; |
fa8d40ab | 7302 | |
05ff989b AC |
7303 | /* At this point, either the user was queried about setting |
7304 | a pending breakpoint and selected yes, or pending | |
7305 | breakpoint behavior is on and thus a pending breakpoint | |
7306 | is defaulted on behalf of the user. */ | |
0101ce28 JJ |
7307 | copy_arg = xstrdup (addr_start); |
7308 | addr_string = ©_arg; | |
7309 | sals.nelts = 1; | |
7310 | sals.sals = &pending_sal; | |
7311 | pending_sal.pc = 0; | |
7312 | pending = 1; | |
05ff989b AC |
7313 | break; |
7314 | default: | |
98deb0da | 7315 | throw_exception (e); |
0101ce28 | 7316 | } |
05ff989b AC |
7317 | default: |
7318 | if (!sals.nelts) | |
fd9b8c24 | 7319 | return 0; |
0101ce28 | 7320 | } |
c3f6f71d JM |
7321 | |
7322 | /* Create a chain of things that always need to be cleaned up. */ | |
7323 | old_chain = make_cleanup (null_cleanup, 0); | |
7324 | ||
0101ce28 JJ |
7325 | if (!pending) |
7326 | { | |
7327 | /* Make sure that all storage allocated to SALS gets freed. */ | |
7328 | make_cleanup (xfree, sals.sals); | |
7329 | ||
7330 | /* Cleanup the addr_string array but not its contents. */ | |
7331 | make_cleanup (xfree, addr_string); | |
7332 | } | |
c3f6f71d | 7333 | |
c3f6f71d JM |
7334 | /* ----------------------------- SNIP ----------------------------- |
7335 | Anything added to the cleanup chain beyond this point is assumed | |
7336 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
7337 | then the memory is not reclaimed. */ |
7338 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d JM |
7339 | |
7340 | /* Mark the contents of the addr_string for cleanup. These go on | |
80c99de1 | 7341 | the bkpt_chain and only occur if the breakpoint create fails. */ |
c3f6f71d JM |
7342 | for (i = 0; i < sals.nelts; i++) |
7343 | { | |
7344 | if (addr_string[i] != NULL) | |
b8c9b27d | 7345 | make_cleanup (xfree, addr_string[i]); |
c3f6f71d JM |
7346 | } |
7347 | ||
7348 | /* Resolve all line numbers to PC's and verify that the addresses | |
7349 | are ok for the target. */ | |
0101ce28 JJ |
7350 | if (!pending) |
7351 | breakpoint_sals_to_pc (&sals, addr_start); | |
c3f6f71d | 7352 | |
1042e4c0 | 7353 | type_wanted = (traceflag |
7a697b8d | 7354 | ? (hardwareflag ? bp_fast_tracepoint : bp_tracepoint) |
1042e4c0 SS |
7355 | : (hardwareflag ? bp_hardware_breakpoint : bp_breakpoint)); |
7356 | ||
7a697b8d SS |
7357 | /* Fast tracepoints may have additional restrictions on location. */ |
7358 | if (type_wanted == bp_fast_tracepoint) | |
7359 | check_fast_tracepoint_sals (gdbarch, &sals); | |
7360 | ||
c3f6f71d JM |
7361 | /* Verify that condition can be parsed, before setting any |
7362 | breakpoints. Allocate a separate condition expression for each | |
7363 | breakpoint. */ | |
0101ce28 | 7364 | if (!pending) |
c3f6f71d | 7365 | { |
2f069f6f | 7366 | if (parse_condition_and_thread) |
72b2ff0e VP |
7367 | { |
7368 | /* Here we only parse 'arg' to separate condition | |
7369 | from thread number, so parsing in context of first | |
7370 | sal is OK. When setting the breakpoint we'll | |
7371 | re-parse it in context of each sal. */ | |
7372 | cond_string = NULL; | |
7373 | thread = -1; | |
4a306c9a JB |
7374 | find_condition_and_thread (arg, sals.sals[0].pc, &cond_string, |
7375 | &thread, &task); | |
72b2ff0e VP |
7376 | if (cond_string) |
7377 | make_cleanup (xfree, cond_string); | |
7378 | } | |
2f069f6f | 7379 | else |
72b2ff0e VP |
7380 | { |
7381 | /* Create a private copy of condition string. */ | |
7382 | if (cond_string) | |
7383 | { | |
7384 | cond_string = xstrdup (cond_string); | |
7385 | make_cleanup (xfree, cond_string); | |
7386 | } | |
7387 | } | |
8cdf0e15 VP |
7388 | create_breakpoints_sal (gdbarch, sals, addr_string, cond_string, |
7389 | type_wanted, tempflag ? disp_del : disp_donttouch, | |
7390 | thread, task, ignore_count, ops, from_tty, | |
7391 | enabled); | |
c906108c | 7392 | } |
0101ce28 JJ |
7393 | else |
7394 | { | |
fe3f5fa8 | 7395 | struct symtab_and_line sal = {0}; |
0101ce28 JJ |
7396 | struct breakpoint *b; |
7397 | ||
0101ce28 JJ |
7398 | make_cleanup (xfree, copy_arg); |
7399 | ||
a6d9a66e | 7400 | b = set_raw_breakpoint_without_location (gdbarch, type_wanted); |
0101ce28 JJ |
7401 | set_breakpoint_count (breakpoint_count + 1); |
7402 | b->number = breakpoint_count; | |
72b2ff0e | 7403 | b->thread = -1; |
018d34a4 | 7404 | b->addr_string = addr_string[0]; |
72b2ff0e | 7405 | b->cond_string = NULL; |
0101ce28 | 7406 | b->ignore_count = ignore_count; |
0101ce28 | 7407 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 7408 | b->condition_not_parsed = 1; |
604133b5 | 7409 | b->ops = ops; |
41447f92 | 7410 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
6c95b8df | 7411 | b->pspace = current_program_space; |
74960c60 | 7412 | |
6c95b8df | 7413 | if (enabled && b->pspace->executing_startup |
8bea4e01 UW |
7414 | && (b->type == bp_breakpoint |
7415 | || b->type == bp_hardware_breakpoint)) | |
7416 | b->enable_state = bp_startup_disabled; | |
7417 | ||
0101ce28 JJ |
7418 | mention (b); |
7419 | } | |
7420 | ||
c3f6f71d | 7421 | if (sals.nelts > 1) |
95a42b64 TT |
7422 | { |
7423 | warning (_("Multiple breakpoints were set.\n" | |
7424 | "Use the \"delete\" command to delete unwanted breakpoints.")); | |
7425 | multi_start = first_bp_set; | |
7426 | multi_end = breakpoint_count; | |
7427 | last_was_multi = 1; | |
7428 | } | |
7429 | ||
80c99de1 PA |
7430 | /* That's it. Discard the cleanups for data inserted into the |
7431 | breakpoint. */ | |
7432 | discard_cleanups (bkpt_chain); | |
7433 | /* But cleanup everything else. */ | |
c3f6f71d | 7434 | do_cleanups (old_chain); |
217dc9e2 | 7435 | |
80c99de1 | 7436 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
217dc9e2 | 7437 | update_global_location_list (1); |
fd9b8c24 PA |
7438 | |
7439 | return 1; | |
c3f6f71d | 7440 | } |
c906108c | 7441 | |
72b2ff0e VP |
7442 | /* Set a breakpoint. |
7443 | ARG is a string describing breakpoint address, | |
7444 | condition, and thread. | |
7445 | FLAG specifies if a breakpoint is hardware on, | |
7446 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
7447 | and BP_TEMPFLAG. */ | |
7448 | ||
98deb0da | 7449 | static void |
72b2ff0e | 7450 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 7451 | { |
72b2ff0e VP |
7452 | int hardwareflag = flag & BP_HARDWAREFLAG; |
7453 | int tempflag = flag & BP_TEMPFLAG; | |
c3f6f71d | 7454 | |
8cdf0e15 VP |
7455 | create_breakpoint (get_current_arch (), |
7456 | arg, | |
7457 | NULL, 0, 1 /* parse arg */, | |
7458 | tempflag, hardwareflag, 0 /* traceflag */, | |
7459 | 0 /* Ignore count */, | |
7460 | pending_break_support, | |
7461 | NULL /* breakpoint_ops */, | |
7462 | from_tty, | |
7463 | 1 /* enabled */); | |
c906108c SS |
7464 | } |
7465 | ||
72b2ff0e | 7466 | |
c3f6f71d | 7467 | |
6a048695 JB |
7468 | /* Adjust SAL to the first instruction past the function prologue. |
7469 | The end of the prologue is determined using the line table from | |
3daf8fe5 JG |
7470 | the debugging information. explicit_pc and explicit_line are |
7471 | not modified. | |
6a048695 JB |
7472 | |
7473 | If SAL is already past the prologue, then do nothing. */ | |
7474 | ||
7475 | static void | |
7476 | skip_prologue_sal (struct symtab_and_line *sal) | |
7477 | { | |
6c95b8df | 7478 | struct symbol *sym; |
6a048695 | 7479 | struct symtab_and_line start_sal; |
6c95b8df | 7480 | struct cleanup *old_chain; |
6a048695 | 7481 | |
6c95b8df | 7482 | old_chain = save_current_space_and_thread (); |
6a048695 | 7483 | |
6c95b8df PA |
7484 | sym = find_pc_function (sal->pc); |
7485 | if (sym != NULL) | |
3daf8fe5 | 7486 | { |
6c95b8df PA |
7487 | start_sal = find_function_start_sal (sym, 1); |
7488 | if (sal->pc < start_sal.pc) | |
7489 | { | |
7490 | start_sal.explicit_line = sal->explicit_line; | |
7491 | start_sal.explicit_pc = sal->explicit_pc; | |
7492 | *sal = start_sal; | |
7493 | } | |
3daf8fe5 | 7494 | } |
6c95b8df PA |
7495 | |
7496 | do_cleanups (old_chain); | |
6a048695 | 7497 | } |
c3f6f71d | 7498 | |
c906108c SS |
7499 | /* Helper function for break_command_1 and disassemble_command. */ |
7500 | ||
7501 | void | |
fba45db2 | 7502 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
7503 | { |
7504 | CORE_ADDR pc; | |
7505 | ||
7506 | if (sal->pc == 0 && sal->symtab != NULL) | |
7507 | { | |
7508 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 7509 | error (_("No line %d in file \"%s\"."), |
c906108c SS |
7510 | sal->line, sal->symtab->filename); |
7511 | sal->pc = pc; | |
6a048695 JB |
7512 | |
7513 | /* If this SAL corresponds to a breakpoint inserted using | |
7514 | a line number, then skip the function prologue if necessary. */ | |
7515 | if (sal->explicit_line) | |
56ef84b1 TT |
7516 | { |
7517 | /* Preserve the original line number. */ | |
7518 | int saved_line = sal->line; | |
7519 | skip_prologue_sal (sal); | |
7520 | sal->line = saved_line; | |
7521 | } | |
c906108c SS |
7522 | } |
7523 | ||
7524 | if (sal->section == 0 && sal->symtab != NULL) | |
7525 | { | |
7526 | struct blockvector *bv; | |
c5aa993b JM |
7527 | struct block *b; |
7528 | struct symbol *sym; | |
c906108c | 7529 | |
801e3a5b | 7530 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
7531 | if (bv != NULL) |
7532 | { | |
7f0df278 | 7533 | sym = block_linkage_function (b); |
c906108c SS |
7534 | if (sym != NULL) |
7535 | { | |
7536 | fixup_symbol_section (sym, sal->symtab->objfile); | |
714835d5 | 7537 | sal->section = SYMBOL_OBJ_SECTION (sym); |
c906108c SS |
7538 | } |
7539 | else | |
7540 | { | |
7541 | /* It really is worthwhile to have the section, so we'll just | |
c5aa993b JM |
7542 | have to look harder. This case can be executed if we have |
7543 | line numbers but no functions (as can happen in assembly | |
7544 | source). */ | |
c906108c | 7545 | |
c5aa993b | 7546 | struct minimal_symbol *msym; |
6c95b8df PA |
7547 | struct cleanup *old_chain = save_current_space_and_thread (); |
7548 | ||
7549 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
7550 | |
7551 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
7552 | if (msym) | |
714835d5 | 7553 | sal->section = SYMBOL_OBJ_SECTION (msym); |
6c95b8df PA |
7554 | |
7555 | do_cleanups (old_chain); | |
c906108c SS |
7556 | } |
7557 | } | |
7558 | } | |
7559 | } | |
7560 | ||
7561 | void | |
fba45db2 | 7562 | break_command (char *arg, int from_tty) |
c906108c | 7563 | { |
db107f19 | 7564 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
7565 | } |
7566 | ||
c906108c | 7567 | void |
fba45db2 | 7568 | tbreak_command (char *arg, int from_tty) |
c906108c | 7569 | { |
db107f19 | 7570 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
7571 | } |
7572 | ||
c906108c | 7573 | static void |
fba45db2 | 7574 | hbreak_command (char *arg, int from_tty) |
c906108c | 7575 | { |
db107f19 | 7576 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
7577 | } |
7578 | ||
7579 | static void | |
fba45db2 | 7580 | thbreak_command (char *arg, int from_tty) |
c906108c | 7581 | { |
db107f19 | 7582 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
7583 | } |
7584 | ||
7585 | static void | |
fba45db2 | 7586 | stop_command (char *arg, int from_tty) |
c906108c | 7587 | { |
a3f17187 | 7588 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 7589 | Usage: stop in <function | address>\n\ |
a3f17187 | 7590 | stop at <line>\n")); |
c906108c SS |
7591 | } |
7592 | ||
7593 | static void | |
fba45db2 | 7594 | stopin_command (char *arg, int from_tty) |
c906108c SS |
7595 | { |
7596 | int badInput = 0; | |
7597 | ||
c5aa993b | 7598 | if (arg == (char *) NULL) |
c906108c SS |
7599 | badInput = 1; |
7600 | else if (*arg != '*') | |
7601 | { | |
7602 | char *argptr = arg; | |
7603 | int hasColon = 0; | |
7604 | ||
53a5351d JM |
7605 | /* look for a ':'. If this is a line number specification, then |
7606 | say it is bad, otherwise, it should be an address or | |
7607 | function/method name */ | |
c906108c | 7608 | while (*argptr && !hasColon) |
c5aa993b JM |
7609 | { |
7610 | hasColon = (*argptr == ':'); | |
7611 | argptr++; | |
7612 | } | |
c906108c SS |
7613 | |
7614 | if (hasColon) | |
c5aa993b | 7615 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 7616 | else |
c5aa993b | 7617 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
7618 | } |
7619 | ||
7620 | if (badInput) | |
a3f17187 | 7621 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 7622 | else |
db107f19 | 7623 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
7624 | } |
7625 | ||
7626 | static void | |
fba45db2 | 7627 | stopat_command (char *arg, int from_tty) |
c906108c SS |
7628 | { |
7629 | int badInput = 0; | |
7630 | ||
c5aa993b | 7631 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
7632 | badInput = 1; |
7633 | else | |
7634 | { | |
7635 | char *argptr = arg; | |
7636 | int hasColon = 0; | |
7637 | ||
7638 | /* look for a ':'. If there is a '::' then get out, otherwise | |
c5aa993b | 7639 | it is probably a line number. */ |
c906108c | 7640 | while (*argptr && !hasColon) |
c5aa993b JM |
7641 | { |
7642 | hasColon = (*argptr == ':'); | |
7643 | argptr++; | |
7644 | } | |
c906108c SS |
7645 | |
7646 | if (hasColon) | |
c5aa993b | 7647 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 7648 | else |
c5aa993b | 7649 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
7650 | } |
7651 | ||
7652 | if (badInput) | |
a3f17187 | 7653 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 7654 | else |
db107f19 | 7655 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
7656 | } |
7657 | ||
53a5351d JM |
7658 | /* accessflag: hw_write: watch write, |
7659 | hw_read: watch read, | |
7660 | hw_access: watch access (read or write) */ | |
c906108c | 7661 | static void |
fba45db2 | 7662 | watch_command_1 (char *arg, int accessflag, int from_tty) |
c906108c | 7663 | { |
a6d9a66e | 7664 | struct gdbarch *gdbarch = get_current_arch (); |
d983da9c | 7665 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c | 7666 | struct expression *exp; |
60e1c644 | 7667 | struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
c906108c SS |
7668 | struct value *val, *mark; |
7669 | struct frame_info *frame; | |
c906108c SS |
7670 | char *exp_start = NULL; |
7671 | char *exp_end = NULL; | |
37e4754d | 7672 | char *tok, *id_tok_start, *end_tok; |
c906108c SS |
7673 | int toklen; |
7674 | char *cond_start = NULL; | |
7675 | char *cond_end = NULL; | |
c906108c SS |
7676 | int i, other_type_used, target_resources_ok = 0; |
7677 | enum bptype bp_type; | |
7678 | int mem_cnt = 0; | |
37e4754d | 7679 | int thread = -1; |
c906108c | 7680 | |
37e4754d LM |
7681 | /* Make sure that we actually have parameters to parse. */ |
7682 | if (arg != NULL && arg[0] != '\0') | |
7683 | { | |
7684 | toklen = strlen (arg); /* Size of argument list. */ | |
7685 | ||
7686 | /* Points tok to the end of the argument list. */ | |
7687 | tok = arg + toklen - 1; | |
7688 | ||
7689 | /* Go backwards in the parameters list. Skip the last parameter. | |
7690 | If we're expecting a 'thread <thread_num>' parameter, this should | |
7691 | be the thread identifier. */ | |
7692 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
7693 | tok--; | |
7694 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
7695 | tok--; | |
7696 | ||
7697 | /* Points end_tok to the beginning of the last token. */ | |
7698 | id_tok_start = tok + 1; | |
7699 | ||
7700 | /* Go backwards in the parameters list. Skip one more parameter. | |
7701 | If we're expecting a 'thread <thread_num>' parameter, we should | |
7702 | reach a "thread" token. */ | |
7703 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
7704 | tok--; | |
7705 | ||
7706 | end_tok = tok; | |
7707 | ||
7708 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
7709 | tok--; | |
7710 | ||
7711 | /* Move the pointer forward to skip the whitespace and | |
7712 | calculate the length of the token. */ | |
7713 | tok++; | |
7714 | toklen = end_tok - tok; | |
7715 | ||
7716 | if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
7717 | { | |
7718 | /* At this point we've found a "thread" token, which means | |
7719 | the user is trying to set a watchpoint that triggers | |
7720 | only in a specific thread. */ | |
7721 | char *endp; | |
7722 | ||
7723 | /* Extract the thread ID from the next token. */ | |
7724 | thread = strtol (id_tok_start, &endp, 0); | |
7725 | ||
7726 | /* Check if the user provided a valid numeric value for the | |
7727 | thread ID. */ | |
7728 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
7729 | error (_("Invalid thread ID specification %s."), id_tok_start); | |
7730 | ||
7731 | /* Check if the thread actually exists. */ | |
7732 | if (!valid_thread_id (thread)) | |
7733 | error (_("Unknown thread %d."), thread); | |
7734 | ||
7735 | /* Truncate the string and get rid of the thread <thread_num> | |
7736 | parameter before the parameter list is parsed by the | |
7737 | evaluate_expression() function. */ | |
7738 | *tok = '\0'; | |
7739 | } | |
7740 | } | |
7741 | ||
7742 | /* Parse the rest of the arguments. */ | |
c906108c SS |
7743 | innermost_block = NULL; |
7744 | exp_start = arg; | |
7745 | exp = parse_exp_1 (&arg, 0, 0); | |
7746 | exp_end = arg; | |
fa8a61dc TT |
7747 | /* Remove trailing whitespace from the expression before saving it. |
7748 | This makes the eventual display of the expression string a bit | |
7749 | prettier. */ | |
7750 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
7751 | --exp_end; | |
7752 | ||
c906108c SS |
7753 | exp_valid_block = innermost_block; |
7754 | mark = value_mark (); | |
fa4727a6 DJ |
7755 | fetch_watchpoint_value (exp, &val, NULL, NULL); |
7756 | if (val != NULL) | |
7757 | release_value (val); | |
c906108c SS |
7758 | |
7759 | tok = arg; | |
7760 | while (*tok == ' ' || *tok == '\t') | |
7761 | tok++; | |
7762 | end_tok = tok; | |
7763 | ||
7764 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
7765 | end_tok++; | |
7766 | ||
7767 | toklen = end_tok - tok; | |
7768 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
7769 | { | |
2d134ed3 PA |
7770 | struct expression *cond; |
7771 | ||
60e1c644 | 7772 | innermost_block = NULL; |
c906108c SS |
7773 | tok = cond_start = end_tok + 1; |
7774 | cond = parse_exp_1 (&tok, 0, 0); | |
60e1c644 PA |
7775 | |
7776 | /* The watchpoint expression may not be local, but the condition | |
7777 | may still be. E.g.: `watch global if local > 0'. */ | |
7778 | cond_exp_valid_block = innermost_block; | |
7779 | ||
2d134ed3 | 7780 | xfree (cond); |
c906108c SS |
7781 | cond_end = tok; |
7782 | } | |
7783 | if (*tok) | |
8a3fe4f8 | 7784 | error (_("Junk at end of command.")); |
c906108c | 7785 | |
53a5351d | 7786 | if (accessflag == hw_read) |
c5aa993b | 7787 | bp_type = bp_read_watchpoint; |
53a5351d | 7788 | else if (accessflag == hw_access) |
c5aa993b JM |
7789 | bp_type = bp_access_watchpoint; |
7790 | else | |
7791 | bp_type = bp_hardware_watchpoint; | |
c906108c SS |
7792 | |
7793 | mem_cnt = can_use_hardware_watchpoint (val); | |
7794 | if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint) | |
8a3fe4f8 | 7795 | error (_("Expression cannot be implemented with read/access watchpoint.")); |
c5aa993b JM |
7796 | if (mem_cnt != 0) |
7797 | { | |
7798 | i = hw_watchpoint_used_count (bp_type, &other_type_used); | |
53a5351d | 7799 | target_resources_ok = |
d92524f1 | 7800 | target_can_use_hardware_watchpoint (bp_type, i + mem_cnt, |
53a5351d | 7801 | other_type_used); |
c5aa993b | 7802 | if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint) |
8a3fe4f8 | 7803 | error (_("Target does not support this type of hardware watchpoint.")); |
53a5351d | 7804 | |
c5aa993b | 7805 | if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint) |
8a3fe4f8 | 7806 | error (_("Target can only support one kind of HW watchpoint at a time.")); |
c5aa993b | 7807 | } |
c906108c | 7808 | |
4d28f7a8 KB |
7809 | /* Change the type of breakpoint to an ordinary watchpoint if a hardware |
7810 | watchpoint could not be set. */ | |
7811 | if (!mem_cnt || target_resources_ok <= 0) | |
7812 | bp_type = bp_watchpoint; | |
7813 | ||
d983da9c | 7814 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
7815 | |
7816 | /* If the expression is "local", then set up a "watchpoint scope" | |
7817 | breakpoint at the point where we've left the scope of the watchpoint | |
7818 | expression. Create the scope breakpoint before the watchpoint, so | |
7819 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 7820 | if (exp_valid_block && frame) |
d983da9c | 7821 | { |
edb3359d DJ |
7822 | if (frame_id_p (frame_unwind_caller_id (frame))) |
7823 | { | |
7824 | scope_breakpoint | |
a6d9a66e UW |
7825 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
7826 | frame_unwind_caller_pc (frame), | |
edb3359d | 7827 | bp_watchpoint_scope); |
d983da9c | 7828 | |
edb3359d | 7829 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 7830 | |
edb3359d DJ |
7831 | /* Automatically delete the breakpoint when it hits. */ |
7832 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 7833 | |
edb3359d DJ |
7834 | /* Only break in the proper frame (help with recursion). */ |
7835 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 7836 | |
edb3359d | 7837 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
7838 | scope_breakpoint->loc->gdbarch |
7839 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
7840 | scope_breakpoint->loc->requested_address |
7841 | = frame_unwind_caller_pc (frame); | |
7842 | scope_breakpoint->loc->address | |
a6d9a66e UW |
7843 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
7844 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
7845 | scope_breakpoint->type); |
7846 | } | |
d983da9c DJ |
7847 | } |
7848 | ||
c906108c | 7849 | /* Now set up the breakpoint. */ |
2d134ed3 | 7850 | b = set_raw_breakpoint_without_location (NULL, bp_type); |
c906108c SS |
7851 | set_breakpoint_count (breakpoint_count + 1); |
7852 | b->number = breakpoint_count; | |
37e4754d | 7853 | b->thread = thread; |
b5de0fa7 | 7854 | b->disposition = disp_donttouch; |
c906108c SS |
7855 | b->exp = exp; |
7856 | b->exp_valid_block = exp_valid_block; | |
60e1c644 | 7857 | b->cond_exp_valid_block = cond_exp_valid_block; |
c906108c SS |
7858 | b->exp_string = savestring (exp_start, exp_end - exp_start); |
7859 | b->val = val; | |
fa4727a6 | 7860 | b->val_valid = 1; |
c906108c SS |
7861 | if (cond_start) |
7862 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
7863 | else | |
7864 | b->cond_string = 0; | |
c5aa993b | 7865 | |
c906108c | 7866 | if (frame) |
f6bc2008 PA |
7867 | { |
7868 | b->watchpoint_frame = get_frame_id (frame); | |
7869 | b->watchpoint_thread = inferior_ptid; | |
7870 | } | |
c906108c | 7871 | else |
f6bc2008 PA |
7872 | { |
7873 | b->watchpoint_frame = null_frame_id; | |
7874 | b->watchpoint_thread = null_ptid; | |
7875 | } | |
c906108c | 7876 | |
d983da9c | 7877 | if (scope_breakpoint != NULL) |
c906108c | 7878 | { |
d983da9c DJ |
7879 | /* The scope breakpoint is related to the watchpoint. We will |
7880 | need to act on them together. */ | |
7881 | b->related_breakpoint = scope_breakpoint; | |
7882 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 7883 | } |
d983da9c | 7884 | |
c906108c | 7885 | value_free_to_mark (mark); |
2d134ed3 PA |
7886 | |
7887 | /* Finally update the new watchpoint. This creates the locations | |
7888 | that should be inserted. */ | |
7889 | update_watchpoint (b, 1); | |
7890 | ||
c906108c | 7891 | mention (b); |
b60e7edf | 7892 | update_global_location_list (1); |
c906108c SS |
7893 | } |
7894 | ||
7895 | /* Return count of locations need to be watched and can be handled | |
7896 | in hardware. If the watchpoint can not be handled | |
7897 | in hardware return zero. */ | |
7898 | ||
c906108c | 7899 | static int |
fba45db2 | 7900 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
7901 | { |
7902 | int found_memory_cnt = 0; | |
2e70b7b9 | 7903 | struct value *head = v; |
c906108c SS |
7904 | |
7905 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 7906 | if (!can_use_hw_watchpoints) |
c906108c | 7907 | return 0; |
c5aa993b | 7908 | |
5c44784c JM |
7909 | /* Make sure that the value of the expression depends only upon |
7910 | memory contents, and values computed from them within GDB. If we | |
7911 | find any register references or function calls, we can't use a | |
7912 | hardware watchpoint. | |
7913 | ||
7914 | The idea here is that evaluating an expression generates a series | |
7915 | of values, one holding the value of every subexpression. (The | |
7916 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
7917 | a*b+c.) GDB's values hold almost enough information to establish | |
7918 | the criteria given above --- they identify memory lvalues, | |
7919 | register lvalues, computed values, etcetera. So we can evaluate | |
7920 | the expression, and then scan the chain of values that leaves | |
7921 | behind to decide whether we can detect any possible change to the | |
7922 | expression's final value using only hardware watchpoints. | |
7923 | ||
7924 | However, I don't think that the values returned by inferior | |
7925 | function calls are special in any way. So this function may not | |
7926 | notice that an expression involving an inferior function call | |
7927 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 7928 | for (; v; v = value_next (v)) |
c906108c | 7929 | { |
5c44784c | 7930 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 7931 | { |
d69fe07e | 7932 | if (value_lazy (v)) |
5c44784c JM |
7933 | /* A lazy memory lvalue is one that GDB never needed to fetch; |
7934 | we either just used its address (e.g., `a' in `a.b') or | |
7935 | we never needed it at all (e.g., `a' in `a,b'). */ | |
7936 | ; | |
53a5351d | 7937 | else |
5c44784c JM |
7938 | { |
7939 | /* Ahh, memory we actually used! Check if we can cover | |
7940 | it with hardware watchpoints. */ | |
df407dfe | 7941 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
7942 | |
7943 | /* We only watch structs and arrays if user asked for it | |
7944 | explicitly, never if they just happen to appear in a | |
7945 | middle of some value chain. */ | |
7946 | if (v == head | |
7947 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
7948 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
7949 | { | |
42ae5230 | 7950 | CORE_ADDR vaddr = value_address (v); |
df407dfe | 7951 | int len = TYPE_LENGTH (value_type (v)); |
2e70b7b9 | 7952 | |
d92524f1 | 7953 | if (!target_region_ok_for_hw_watchpoint (vaddr, len)) |
2e70b7b9 MS |
7954 | return 0; |
7955 | else | |
7956 | found_memory_cnt++; | |
7957 | } | |
5c44784c | 7958 | } |
c5aa993b | 7959 | } |
5086187c AC |
7960 | else if (VALUE_LVAL (v) != not_lval |
7961 | && deprecated_value_modifiable (v) == 0) | |
53a5351d | 7962 | return 0; /* ??? What does this represent? */ |
5086187c | 7963 | else if (VALUE_LVAL (v) == lval_register) |
53a5351d | 7964 | return 0; /* cannot watch a register with a HW watchpoint */ |
c906108c SS |
7965 | } |
7966 | ||
7967 | /* The expression itself looks suitable for using a hardware | |
7968 | watchpoint, but give the target machine a chance to reject it. */ | |
7969 | return found_memory_cnt; | |
7970 | } | |
7971 | ||
8b93c638 | 7972 | void |
fba45db2 | 7973 | watch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
7974 | { |
7975 | watch_command (arg, from_tty); | |
7976 | } | |
8926118c | 7977 | |
c5aa993b | 7978 | static void |
fba45db2 | 7979 | watch_command (char *arg, int from_tty) |
c906108c | 7980 | { |
53a5351d | 7981 | watch_command_1 (arg, hw_write, from_tty); |
c906108c SS |
7982 | } |
7983 | ||
8b93c638 | 7984 | void |
fba45db2 | 7985 | rwatch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
7986 | { |
7987 | rwatch_command (arg, from_tty); | |
7988 | } | |
8926118c | 7989 | |
c5aa993b | 7990 | static void |
fba45db2 | 7991 | rwatch_command (char *arg, int from_tty) |
c906108c | 7992 | { |
53a5351d | 7993 | watch_command_1 (arg, hw_read, from_tty); |
c906108c SS |
7994 | } |
7995 | ||
8b93c638 | 7996 | void |
fba45db2 | 7997 | awatch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
7998 | { |
7999 | awatch_command (arg, from_tty); | |
8000 | } | |
8926118c | 8001 | |
c5aa993b | 8002 | static void |
fba45db2 | 8003 | awatch_command (char *arg, int from_tty) |
c906108c | 8004 | { |
53a5351d | 8005 | watch_command_1 (arg, hw_access, from_tty); |
c906108c | 8006 | } |
c906108c | 8007 | \f |
c5aa993b | 8008 | |
43ff13b4 | 8009 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
8010 | because it uses the mechanisms of breakpoints. */ |
8011 | ||
bfec99b2 PA |
8012 | struct until_break_command_continuation_args |
8013 | { | |
8014 | struct breakpoint *breakpoint; | |
8015 | struct breakpoint *breakpoint2; | |
8016 | }; | |
8017 | ||
43ff13b4 JM |
8018 | /* This function is called by fetch_inferior_event via the |
8019 | cmd_continuation pointer, to complete the until command. It takes | |
8020 | care of cleaning up the temporary breakpoints set up by the until | |
8021 | command. */ | |
c2c6d25f | 8022 | static void |
604ead4a | 8023 | until_break_command_continuation (void *arg) |
43ff13b4 | 8024 | { |
bfec99b2 PA |
8025 | struct until_break_command_continuation_args *a = arg; |
8026 | ||
8027 | delete_breakpoint (a->breakpoint); | |
8028 | if (a->breakpoint2) | |
8029 | delete_breakpoint (a->breakpoint2); | |
43ff13b4 JM |
8030 | } |
8031 | ||
c906108c | 8032 | void |
ae66c1fc | 8033 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
8034 | { |
8035 | struct symtabs_and_lines sals; | |
8036 | struct symtab_and_line sal; | |
206415a3 | 8037 | struct frame_info *frame = get_selected_frame (NULL); |
c906108c | 8038 | struct breakpoint *breakpoint; |
f107f563 | 8039 | struct breakpoint *breakpoint2 = NULL; |
c906108c SS |
8040 | struct cleanup *old_chain; |
8041 | ||
8042 | clear_proceed_status (); | |
8043 | ||
8044 | /* Set a breakpoint where the user wants it and at return from | |
8045 | this function */ | |
c5aa993b | 8046 | |
c906108c SS |
8047 | if (default_breakpoint_valid) |
8048 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, | |
68219205 | 8049 | default_breakpoint_line, (char ***) NULL, NULL); |
c906108c | 8050 | else |
53a5351d | 8051 | sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, |
68219205 | 8052 | 0, (char ***) NULL, NULL); |
c5aa993b | 8053 | |
c906108c | 8054 | if (sals.nelts != 1) |
8a3fe4f8 | 8055 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 8056 | |
c906108c | 8057 | sal = sals.sals[0]; |
b8c9b27d | 8058 | xfree (sals.sals); /* malloc'd, so freed */ |
c5aa993b | 8059 | |
c906108c | 8060 | if (*arg) |
8a3fe4f8 | 8061 | error (_("Junk at end of arguments.")); |
c5aa993b | 8062 | |
c906108c | 8063 | resolve_sal_pc (&sal); |
c5aa993b | 8064 | |
ae66c1fc EZ |
8065 | if (anywhere) |
8066 | /* If the user told us to continue until a specified location, | |
8067 | we don't specify a frame at which we need to stop. */ | |
a6d9a66e UW |
8068 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
8069 | null_frame_id, bp_until); | |
ae66c1fc | 8070 | else |
edb3359d | 8071 | /* Otherwise, specify the selected frame, because we want to stop only |
ae66c1fc | 8072 | at the very same frame. */ |
a6d9a66e UW |
8073 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
8074 | get_stack_frame_id (frame), | |
ae66c1fc | 8075 | bp_until); |
c5aa993b | 8076 | |
f107f563 | 8077 | old_chain = make_cleanup_delete_breakpoint (breakpoint); |
c906108c | 8078 | |
ae66c1fc EZ |
8079 | /* Keep within the current frame, or in frames called by the current |
8080 | one. */ | |
edb3359d DJ |
8081 | |
8082 | if (frame_id_p (frame_unwind_caller_id (frame))) | |
c906108c | 8083 | { |
edb3359d DJ |
8084 | sal = find_pc_line (frame_unwind_caller_pc (frame), 0); |
8085 | sal.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e UW |
8086 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
8087 | sal, | |
edb3359d | 8088 | frame_unwind_caller_id (frame), |
f107f563 VP |
8089 | bp_until); |
8090 | make_cleanup_delete_breakpoint (breakpoint2); | |
c906108c | 8091 | } |
c5aa993b | 8092 | |
c906108c | 8093 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
f107f563 VP |
8094 | |
8095 | /* If we are running asynchronously, and proceed call above has actually | |
8096 | managed to start the target, arrange for breakpoints to be | |
8097 | deleted when the target stops. Otherwise, we're already stopped and | |
8098 | delete breakpoints via cleanup chain. */ | |
8099 | ||
8ea051c5 | 8100 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 8101 | { |
bfec99b2 PA |
8102 | struct until_break_command_continuation_args *args; |
8103 | args = xmalloc (sizeof (*args)); | |
f107f563 | 8104 | |
bfec99b2 PA |
8105 | args->breakpoint = breakpoint; |
8106 | args->breakpoint2 = breakpoint2; | |
f107f563 VP |
8107 | |
8108 | discard_cleanups (old_chain); | |
95e54da7 PA |
8109 | add_continuation (inferior_thread (), |
8110 | until_break_command_continuation, args, | |
604ead4a | 8111 | xfree); |
f107f563 VP |
8112 | } |
8113 | else | |
c5aa993b | 8114 | do_cleanups (old_chain); |
c906108c | 8115 | } |
ae66c1fc | 8116 | |
c906108c | 8117 | static void |
fba45db2 | 8118 | ep_skip_leading_whitespace (char **s) |
c906108c | 8119 | { |
c5aa993b JM |
8120 | if ((s == NULL) || (*s == NULL)) |
8121 | return; | |
8122 | while (isspace (**s)) | |
8123 | *s += 1; | |
c906108c | 8124 | } |
c5aa993b | 8125 | |
c906108c SS |
8126 | /* This function attempts to parse an optional "if <cond>" clause |
8127 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 8128 | |
c906108c SS |
8129 | Else, it returns a pointer to the condition string. (It does not |
8130 | attempt to evaluate the string against a particular block.) And, | |
8131 | it updates arg to point to the first character following the parsed | |
8132 | if clause in the arg string. */ | |
53a5351d | 8133 | |
c906108c | 8134 | static char * |
fba45db2 | 8135 | ep_parse_optional_if_clause (char **arg) |
c906108c | 8136 | { |
c5aa993b JM |
8137 | char *cond_string; |
8138 | ||
8139 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 8140 | return NULL; |
c5aa993b | 8141 | |
c906108c SS |
8142 | /* Skip the "if" keyword. */ |
8143 | (*arg) += 2; | |
c5aa993b | 8144 | |
c906108c SS |
8145 | /* Skip any extra leading whitespace, and record the start of the |
8146 | condition string. */ | |
8147 | ep_skip_leading_whitespace (arg); | |
8148 | cond_string = *arg; | |
c5aa993b | 8149 | |
c906108c SS |
8150 | /* Assume that the condition occupies the remainder of the arg string. */ |
8151 | (*arg) += strlen (cond_string); | |
c5aa993b | 8152 | |
c906108c SS |
8153 | return cond_string; |
8154 | } | |
c5aa993b | 8155 | |
c906108c SS |
8156 | /* Commands to deal with catching events, such as signals, exceptions, |
8157 | process start/exit, etc. */ | |
c5aa993b JM |
8158 | |
8159 | typedef enum | |
8160 | { | |
44feb3ce TT |
8161 | catch_fork_temporary, catch_vfork_temporary, |
8162 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
8163 | } |
8164 | catch_fork_kind; | |
8165 | ||
c906108c | 8166 | static void |
44feb3ce | 8167 | catch_fork_command_1 (char *arg, int from_tty, struct cmd_list_element *command) |
c906108c | 8168 | { |
a6d9a66e | 8169 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 8170 | char *cond_string = NULL; |
44feb3ce TT |
8171 | catch_fork_kind fork_kind; |
8172 | int tempflag; | |
8173 | ||
8174 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
8175 | tempflag = (fork_kind == catch_fork_temporary | |
8176 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 8177 | |
44feb3ce TT |
8178 | if (!arg) |
8179 | arg = ""; | |
c906108c | 8180 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 8181 | |
c906108c | 8182 | /* The allowed syntax is: |
c5aa993b JM |
8183 | catch [v]fork |
8184 | catch [v]fork if <cond> | |
8185 | ||
c906108c SS |
8186 | First, check if there's an if clause. */ |
8187 | cond_string = ep_parse_optional_if_clause (&arg); | |
c5aa993b | 8188 | |
c906108c | 8189 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 8190 | error (_("Junk at end of arguments.")); |
c5aa993b | 8191 | |
c906108c SS |
8192 | /* If this target supports it, create a fork or vfork catchpoint |
8193 | and enable reporting of such events. */ | |
c5aa993b JM |
8194 | switch (fork_kind) |
8195 | { | |
44feb3ce TT |
8196 | case catch_fork_temporary: |
8197 | case catch_fork_permanent: | |
a6d9a66e | 8198 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 8199 | &catch_fork_breakpoint_ops); |
c906108c | 8200 | break; |
44feb3ce TT |
8201 | case catch_vfork_temporary: |
8202 | case catch_vfork_permanent: | |
a6d9a66e | 8203 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 8204 | &catch_vfork_breakpoint_ops); |
c906108c | 8205 | break; |
c5aa993b | 8206 | default: |
8a3fe4f8 | 8207 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 8208 | break; |
c5aa993b | 8209 | } |
c906108c SS |
8210 | } |
8211 | ||
8212 | static void | |
44feb3ce | 8213 | catch_exec_command_1 (char *arg, int from_tty, struct cmd_list_element *command) |
c906108c | 8214 | { |
a6d9a66e | 8215 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 8216 | int tempflag; |
c5aa993b | 8217 | char *cond_string = NULL; |
c906108c | 8218 | |
44feb3ce TT |
8219 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
8220 | ||
8221 | if (!arg) | |
8222 | arg = ""; | |
c906108c SS |
8223 | ep_skip_leading_whitespace (&arg); |
8224 | ||
8225 | /* The allowed syntax is: | |
c5aa993b JM |
8226 | catch exec |
8227 | catch exec if <cond> | |
c906108c SS |
8228 | |
8229 | First, check if there's an if clause. */ | |
8230 | cond_string = ep_parse_optional_if_clause (&arg); | |
8231 | ||
8232 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 8233 | error (_("Junk at end of arguments.")); |
c906108c SS |
8234 | |
8235 | /* If this target supports it, create an exec catchpoint | |
8236 | and enable reporting of such events. */ | |
a6d9a66e UW |
8237 | create_catchpoint (gdbarch, tempflag, cond_string, |
8238 | &catch_exec_breakpoint_ops); | |
c906108c | 8239 | } |
c5aa993b | 8240 | |
3086aeae DJ |
8241 | static enum print_stop_action |
8242 | print_exception_catchpoint (struct breakpoint *b) | |
8243 | { | |
ade92717 | 8244 | int bp_temp, bp_throw; |
3086aeae | 8245 | |
ade92717 | 8246 | annotate_catchpoint (b->number); |
3086aeae | 8247 | |
ade92717 AR |
8248 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
8249 | if (b->loc->address != b->loc->requested_address) | |
8250 | breakpoint_adjustment_warning (b->loc->requested_address, | |
8251 | b->loc->address, | |
8252 | b->number, 1); | |
df2b6d2d | 8253 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
8254 | ui_out_text (uiout, |
8255 | bp_temp ? "Temporary catchpoint " | |
8256 | : "Catchpoint "); | |
8257 | if (!ui_out_is_mi_like_p (uiout)) | |
8258 | ui_out_field_int (uiout, "bkptno", b->number); | |
8259 | ui_out_text (uiout, | |
c0b37c48 AR |
8260 | bp_throw ? " (exception thrown), " |
8261 | : " (exception caught), "); | |
ade92717 AR |
8262 | if (ui_out_is_mi_like_p (uiout)) |
8263 | { | |
8264 | ui_out_field_string (uiout, "reason", | |
8265 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
8266 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8267 | ui_out_field_int (uiout, "bkptno", b->number); | |
8268 | } | |
3086aeae DJ |
8269 | return PRINT_SRC_AND_LOC; |
8270 | } | |
8271 | ||
8272 | static void | |
a6d9a66e | 8273 | print_one_exception_catchpoint (struct breakpoint *b, struct bp_location **last_loc) |
3086aeae | 8274 | { |
79a45b7d TT |
8275 | struct value_print_options opts; |
8276 | get_user_print_options (&opts); | |
8277 | if (opts.addressprint) | |
3086aeae DJ |
8278 | { |
8279 | annotate_field (4); | |
604133b5 AR |
8280 | if (b->loc == NULL || b->loc->shlib_disabled) |
8281 | ui_out_field_string (uiout, "addr", "<PENDING>"); | |
8282 | else | |
5af949e3 UW |
8283 | ui_out_field_core_addr (uiout, "addr", |
8284 | b->loc->gdbarch, b->loc->address); | |
3086aeae DJ |
8285 | } |
8286 | annotate_field (5); | |
604133b5 | 8287 | if (b->loc) |
a6d9a66e | 8288 | *last_loc = b->loc; |
3086aeae DJ |
8289 | if (strstr (b->addr_string, "throw") != NULL) |
8290 | ui_out_field_string (uiout, "what", "exception throw"); | |
8291 | else | |
8292 | ui_out_field_string (uiout, "what", "exception catch"); | |
8293 | } | |
8294 | ||
8295 | static void | |
8296 | print_mention_exception_catchpoint (struct breakpoint *b) | |
8297 | { | |
ade92717 AR |
8298 | int bp_temp; |
8299 | int bp_throw; | |
8300 | ||
df2b6d2d | 8301 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
8302 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
8303 | ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ") | |
8304 | : _("Catchpoint ")); | |
8305 | ui_out_field_int (uiout, "bkptno", b->number); | |
8306 | ui_out_text (uiout, bp_throw ? _(" (throw)") | |
8307 | : _(" (catch)")); | |
3086aeae DJ |
8308 | } |
8309 | ||
8310 | static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = { | |
ce78b96d JB |
8311 | NULL, /* insert */ |
8312 | NULL, /* remove */ | |
8313 | NULL, /* breakpoint_hit */ | |
3086aeae DJ |
8314 | print_exception_catchpoint, |
8315 | print_one_exception_catchpoint, | |
8316 | print_mention_exception_catchpoint | |
8317 | }; | |
8318 | ||
8319 | static int | |
8320 | handle_gnu_v3_exceptions (int tempflag, char *cond_string, | |
8321 | enum exception_event_kind ex_event, int from_tty) | |
8322 | { | |
604133b5 AR |
8323 | char *trigger_func_name; |
8324 | ||
3086aeae | 8325 | if (ex_event == EX_EVENT_CATCH) |
604133b5 | 8326 | trigger_func_name = "__cxa_begin_catch"; |
3086aeae | 8327 | else |
604133b5 | 8328 | trigger_func_name = "__cxa_throw"; |
3086aeae | 8329 | |
8cdf0e15 VP |
8330 | create_breakpoint (get_current_arch (), |
8331 | trigger_func_name, cond_string, -1, | |
8332 | 0 /* condition and thread are valid. */, | |
8333 | tempflag, 0, 0, | |
8334 | 0, | |
8335 | AUTO_BOOLEAN_TRUE /* pending */, | |
8336 | &gnu_v3_exception_catchpoint_ops, from_tty, | |
8337 | 1 /* enabled */); | |
3086aeae | 8338 | |
3086aeae DJ |
8339 | return 1; |
8340 | } | |
8341 | ||
c5aa993b | 8342 | /* Deal with "catch catch" and "catch throw" commands */ |
c906108c SS |
8343 | |
8344 | static void | |
fba45db2 KB |
8345 | catch_exception_command_1 (enum exception_event_kind ex_event, char *arg, |
8346 | int tempflag, int from_tty) | |
c906108c | 8347 | { |
c5aa993b JM |
8348 | char *cond_string = NULL; |
8349 | struct symtab_and_line *sal = NULL; | |
8350 | ||
44feb3ce TT |
8351 | if (!arg) |
8352 | arg = ""; | |
c906108c | 8353 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 8354 | |
c906108c SS |
8355 | cond_string = ep_parse_optional_if_clause (&arg); |
8356 | ||
8357 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 8358 | error (_("Junk at end of arguments.")); |
c906108c | 8359 | |
059fb39f PM |
8360 | if (ex_event != EX_EVENT_THROW |
8361 | && ex_event != EX_EVENT_CATCH) | |
8a3fe4f8 | 8362 | error (_("Unsupported or unknown exception event; cannot catch it")); |
c906108c | 8363 | |
3086aeae DJ |
8364 | if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty)) |
8365 | return; | |
8366 | ||
8a3fe4f8 | 8367 | warning (_("Unsupported with this platform/compiler combination.")); |
c906108c SS |
8368 | } |
8369 | ||
44feb3ce TT |
8370 | /* Implementation of "catch catch" command. */ |
8371 | ||
8372 | static void | |
8373 | catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command) | |
8374 | { | |
8375 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8376 | catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty); | |
8377 | } | |
8378 | ||
8379 | /* Implementation of "catch throw" command. */ | |
8380 | ||
8381 | static void | |
8382 | catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command) | |
8383 | { | |
8384 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8385 | catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty); | |
8386 | } | |
8387 | ||
f7f9143b JB |
8388 | /* Create a breakpoint struct for Ada exception catchpoints. */ |
8389 | ||
8390 | static void | |
a6d9a66e UW |
8391 | create_ada_exception_breakpoint (struct gdbarch *gdbarch, |
8392 | struct symtab_and_line sal, | |
f7f9143b JB |
8393 | char *addr_string, |
8394 | char *exp_string, | |
8395 | char *cond_string, | |
8396 | struct expression *cond, | |
8397 | struct breakpoint_ops *ops, | |
8398 | int tempflag, | |
8399 | int from_tty) | |
8400 | { | |
8401 | struct breakpoint *b; | |
8402 | ||
8403 | if (from_tty) | |
8404 | { | |
5af949e3 UW |
8405 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
8406 | if (!loc_gdbarch) | |
8407 | loc_gdbarch = gdbarch; | |
8408 | ||
6c95b8df PA |
8409 | describe_other_breakpoints (loc_gdbarch, |
8410 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
8411 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
8412 | version for exception catchpoints, because two catchpoints | |
8413 | used for different exception names will use the same address. | |
8414 | In this case, a "breakpoint ... also set at..." warning is | |
8415 | unproductive. Besides. the warning phrasing is also a bit | |
8416 | inapropriate, we should use the word catchpoint, and tell | |
8417 | the user what type of catchpoint it is. The above is good | |
8418 | enough for now, though. */ | |
8419 | } | |
8420 | ||
a6d9a66e | 8421 | b = set_raw_breakpoint (gdbarch, sal, bp_breakpoint); |
f7f9143b JB |
8422 | set_breakpoint_count (breakpoint_count + 1); |
8423 | ||
8424 | b->enable_state = bp_enabled; | |
8425 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
8426 | b->number = breakpoint_count; | |
8427 | b->ignore_count = 0; | |
511a6cd4 | 8428 | b->loc->cond = cond; |
f7f9143b JB |
8429 | b->addr_string = addr_string; |
8430 | b->language = language_ada; | |
8431 | b->cond_string = cond_string; | |
8432 | b->exp_string = exp_string; | |
8433 | b->thread = -1; | |
8434 | b->ops = ops; | |
f7f9143b JB |
8435 | |
8436 | mention (b); | |
b60e7edf | 8437 | update_global_location_list (1); |
f7f9143b JB |
8438 | } |
8439 | ||
8440 | /* Implement the "catch exception" command. */ | |
8441 | ||
8442 | static void | |
44feb3ce TT |
8443 | catch_ada_exception_command (char *arg, int from_tty, |
8444 | struct cmd_list_element *command) | |
f7f9143b | 8445 | { |
a6d9a66e | 8446 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 8447 | int tempflag; |
f7f9143b JB |
8448 | struct symtab_and_line sal; |
8449 | enum bptype type; | |
8450 | char *addr_string = NULL; | |
8451 | char *exp_string = NULL; | |
8452 | char *cond_string = NULL; | |
8453 | struct expression *cond = NULL; | |
8454 | struct breakpoint_ops *ops = NULL; | |
8455 | ||
44feb3ce TT |
8456 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
8457 | ||
8458 | if (!arg) | |
8459 | arg = ""; | |
f7f9143b JB |
8460 | sal = ada_decode_exception_location (arg, &addr_string, &exp_string, |
8461 | &cond_string, &cond, &ops); | |
a6d9a66e | 8462 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, exp_string, |
f7f9143b JB |
8463 | cond_string, cond, ops, tempflag, |
8464 | from_tty); | |
8465 | } | |
8466 | ||
a96d9b2e SDJ |
8467 | /* Cleanup function for a syscall filter list. */ |
8468 | static void | |
8469 | clean_up_filters (void *arg) | |
8470 | { | |
8471 | VEC(int) *iter = *(VEC(int) **) arg; | |
8472 | VEC_free (int, iter); | |
8473 | } | |
8474 | ||
8475 | /* Splits the argument using space as delimiter. Returns an xmalloc'd | |
8476 | filter list, or NULL if no filtering is required. */ | |
8477 | static VEC(int) * | |
8478 | catch_syscall_split_args (char *arg) | |
8479 | { | |
8480 | VEC(int) *result = NULL; | |
8481 | struct cleanup *cleanup = make_cleanup (clean_up_filters, &result); | |
8482 | ||
8483 | while (*arg != '\0') | |
8484 | { | |
8485 | int i, syscall_number; | |
8486 | char *endptr; | |
8487 | char cur_name[128]; | |
8488 | struct syscall s; | |
8489 | ||
8490 | /* Skip whitespace. */ | |
8491 | while (isspace (*arg)) | |
8492 | arg++; | |
8493 | ||
8494 | for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) | |
8495 | cur_name[i] = arg[i]; | |
8496 | cur_name[i] = '\0'; | |
8497 | arg += i; | |
8498 | ||
8499 | /* Check if the user provided a syscall name or a number. */ | |
8500 | syscall_number = (int) strtol (cur_name, &endptr, 0); | |
8501 | if (*endptr == '\0') | |
bccd0dd2 | 8502 | get_syscall_by_number (syscall_number, &s); |
a96d9b2e SDJ |
8503 | else |
8504 | { | |
8505 | /* We have a name. Let's check if it's valid and convert it | |
8506 | to a number. */ | |
8507 | get_syscall_by_name (cur_name, &s); | |
8508 | ||
8509 | if (s.number == UNKNOWN_SYSCALL) | |
8510 | /* Here we have to issue an error instead of a warning, because | |
8511 | GDB cannot do anything useful if there's no syscall number to | |
8512 | be caught. */ | |
8513 | error (_("Unknown syscall name '%s'."), cur_name); | |
8514 | } | |
8515 | ||
8516 | /* Ok, it's valid. */ | |
8517 | VEC_safe_push (int, result, s.number); | |
8518 | } | |
8519 | ||
8520 | discard_cleanups (cleanup); | |
8521 | return result; | |
8522 | } | |
8523 | ||
8524 | /* Implement the "catch syscall" command. */ | |
8525 | ||
8526 | static void | |
8527 | catch_syscall_command_1 (char *arg, int from_tty, struct cmd_list_element *command) | |
8528 | { | |
8529 | int tempflag; | |
8530 | VEC(int) *filter; | |
8531 | struct syscall s; | |
8532 | struct gdbarch *gdbarch = get_current_arch (); | |
8533 | ||
8534 | /* Checking if the feature if supported. */ | |
8535 | if (gdbarch_get_syscall_number_p (gdbarch) == 0) | |
8536 | error (_("The feature 'catch syscall' is not supported on \ | |
8537 | this architeture yet.")); | |
8538 | ||
8539 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8540 | ||
8541 | ep_skip_leading_whitespace (&arg); | |
8542 | ||
8543 | /* We need to do this first "dummy" translation in order | |
8544 | to get the syscall XML file loaded or, most important, | |
8545 | to display a warning to the user if there's no XML file | |
8546 | for his/her architecture. */ | |
8547 | get_syscall_by_number (0, &s); | |
8548 | ||
8549 | /* The allowed syntax is: | |
8550 | catch syscall | |
8551 | catch syscall <name | number> [<name | number> ... <name | number>] | |
8552 | ||
8553 | Let's check if there's a syscall name. */ | |
8554 | ||
8555 | if (arg != NULL) | |
8556 | filter = catch_syscall_split_args (arg); | |
8557 | else | |
8558 | filter = NULL; | |
8559 | ||
8560 | create_syscall_event_catchpoint (tempflag, filter, | |
8561 | &catch_syscall_breakpoint_ops); | |
8562 | } | |
8563 | ||
f7f9143b JB |
8564 | /* Implement the "catch assert" command. */ |
8565 | ||
8566 | static void | |
44feb3ce | 8567 | catch_assert_command (char *arg, int from_tty, struct cmd_list_element *command) |
f7f9143b | 8568 | { |
a6d9a66e | 8569 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 8570 | int tempflag; |
f7f9143b JB |
8571 | struct symtab_and_line sal; |
8572 | char *addr_string = NULL; | |
8573 | struct breakpoint_ops *ops = NULL; | |
8574 | ||
44feb3ce TT |
8575 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
8576 | ||
8577 | if (!arg) | |
8578 | arg = ""; | |
f7f9143b | 8579 | sal = ada_decode_assert_location (arg, &addr_string, &ops); |
a6d9a66e UW |
8580 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, NULL, NULL, NULL, |
8581 | ops, tempflag, from_tty); | |
f7f9143b JB |
8582 | } |
8583 | ||
c906108c | 8584 | static void |
fba45db2 | 8585 | catch_command (char *arg, int from_tty) |
c906108c | 8586 | { |
44feb3ce | 8587 | error (_("Catch requires an event name.")); |
c906108c SS |
8588 | } |
8589 | \f | |
8590 | ||
8591 | static void | |
fba45db2 | 8592 | tcatch_command (char *arg, int from_tty) |
c906108c | 8593 | { |
44feb3ce | 8594 | error (_("Catch requires an event name.")); |
c906108c SS |
8595 | } |
8596 | ||
80f8a6eb | 8597 | /* Delete breakpoints by address or line. */ |
c906108c SS |
8598 | |
8599 | static void | |
fba45db2 | 8600 | clear_command (char *arg, int from_tty) |
c906108c | 8601 | { |
d6e956e5 VP |
8602 | struct breakpoint *b; |
8603 | VEC(breakpoint_p) *found = 0; | |
8604 | int ix; | |
c906108c SS |
8605 | int default_match; |
8606 | struct symtabs_and_lines sals; | |
8607 | struct symtab_and_line sal; | |
c906108c SS |
8608 | int i; |
8609 | ||
8610 | if (arg) | |
8611 | { | |
8612 | sals = decode_line_spec (arg, 1); | |
8613 | default_match = 0; | |
8614 | } | |
8615 | else | |
8616 | { | |
c5aa993b | 8617 | sals.sals = (struct symtab_and_line *) |
c906108c | 8618 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 8619 | make_cleanup (xfree, sals.sals); |
fe39c653 | 8620 | init_sal (&sal); /* initialize to zeroes */ |
c906108c SS |
8621 | sal.line = default_breakpoint_line; |
8622 | sal.symtab = default_breakpoint_symtab; | |
8623 | sal.pc = default_breakpoint_address; | |
6c95b8df | 8624 | sal.pspace = default_breakpoint_pspace; |
c906108c | 8625 | if (sal.symtab == 0) |
8a3fe4f8 | 8626 | error (_("No source file specified.")); |
c906108c SS |
8627 | |
8628 | sals.sals[0] = sal; | |
8629 | sals.nelts = 1; | |
8630 | ||
8631 | default_match = 1; | |
8632 | } | |
8633 | ||
ed0616c6 VP |
8634 | /* We don't call resolve_sal_pc here. That's not |
8635 | as bad as it seems, because all existing breakpoints | |
8636 | typically have both file/line and pc set. So, if | |
8637 | clear is given file/line, we can match this to existing | |
8638 | breakpoint without obtaining pc at all. | |
8639 | ||
8640 | We only support clearing given the address explicitly | |
8641 | present in breakpoint table. Say, we've set breakpoint | |
8642 | at file:line. There were several PC values for that file:line, | |
8643 | due to optimization, all in one block. | |
8644 | We've picked one PC value. If "clear" is issued with another | |
8645 | PC corresponding to the same file:line, the breakpoint won't | |
8646 | be cleared. We probably can still clear the breakpoint, but | |
8647 | since the other PC value is never presented to user, user | |
8648 | can only find it by guessing, and it does not seem important | |
8649 | to support that. */ | |
8650 | ||
c906108c | 8651 | /* For each line spec given, delete bps which correspond |
80f8a6eb MS |
8652 | to it. Do it in two passes, solely to preserve the current |
8653 | behavior that from_tty is forced true if we delete more than | |
8654 | one breakpoint. */ | |
c906108c | 8655 | |
80f8a6eb | 8656 | found = NULL; |
c906108c SS |
8657 | for (i = 0; i < sals.nelts; i++) |
8658 | { | |
8659 | /* If exact pc given, clear bpts at that pc. | |
c5aa993b JM |
8660 | If line given (pc == 0), clear all bpts on specified line. |
8661 | If defaulting, clear all bpts on default line | |
c906108c | 8662 | or at default pc. |
c5aa993b JM |
8663 | |
8664 | defaulting sal.pc != 0 tests to do | |
8665 | ||
8666 | 0 1 pc | |
8667 | 1 1 pc _and_ line | |
8668 | 0 0 line | |
8669 | 1 0 <can't happen> */ | |
c906108c SS |
8670 | |
8671 | sal = sals.sals[i]; | |
c906108c | 8672 | |
d6e956e5 VP |
8673 | /* Find all matching breakpoints and add them to |
8674 | 'found'. */ | |
8675 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8676 | { |
0d381245 | 8677 | int match = 0; |
80f8a6eb MS |
8678 | /* Are we going to delete b? */ |
8679 | if (b->type != bp_none | |
8680 | && b->type != bp_watchpoint | |
8681 | && b->type != bp_hardware_watchpoint | |
8682 | && b->type != bp_read_watchpoint | |
0d381245 VP |
8683 | && b->type != bp_access_watchpoint) |
8684 | { | |
8685 | struct bp_location *loc = b->loc; | |
8686 | for (; loc; loc = loc->next) | |
8687 | { | |
6c95b8df PA |
8688 | int pc_match = sal.pc |
8689 | && (loc->pspace == sal.pspace) | |
0d381245 VP |
8690 | && (loc->address == sal.pc) |
8691 | && (!section_is_overlay (loc->section) | |
8692 | || loc->section == sal.section); | |
8693 | int line_match = ((default_match || (0 == sal.pc)) | |
8694 | && b->source_file != NULL | |
8695 | && sal.symtab != NULL | |
6c95b8df | 8696 | && sal.pspace == loc->pspace |
0d381245 VP |
8697 | && strcmp (b->source_file, sal.symtab->filename) == 0 |
8698 | && b->line_number == sal.line); | |
8699 | if (pc_match || line_match) | |
8700 | { | |
8701 | match = 1; | |
8702 | break; | |
8703 | } | |
8704 | } | |
8705 | } | |
8706 | ||
8707 | if (match) | |
d6e956e5 | 8708 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 8709 | } |
80f8a6eb MS |
8710 | } |
8711 | /* Now go thru the 'found' chain and delete them. */ | |
d6e956e5 | 8712 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
8713 | { |
8714 | if (arg) | |
8a3fe4f8 | 8715 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 8716 | else |
8a3fe4f8 | 8717 | error (_("No breakpoint at this line.")); |
80f8a6eb | 8718 | } |
c906108c | 8719 | |
d6e956e5 | 8720 | if (VEC_length(breakpoint_p, found) > 1) |
80f8a6eb MS |
8721 | from_tty = 1; /* Always report if deleted more than one */ |
8722 | if (from_tty) | |
a3f17187 | 8723 | { |
d6e956e5 | 8724 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
8725 | printf_unfiltered (_("Deleted breakpoint ")); |
8726 | else | |
8727 | printf_unfiltered (_("Deleted breakpoints ")); | |
8728 | } | |
80f8a6eb | 8729 | breakpoints_changed (); |
d6e956e5 VP |
8730 | |
8731 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 8732 | { |
c5aa993b | 8733 | if (from_tty) |
d6e956e5 VP |
8734 | printf_unfiltered ("%d ", b->number); |
8735 | delete_breakpoint (b); | |
c906108c | 8736 | } |
80f8a6eb MS |
8737 | if (from_tty) |
8738 | putchar_unfiltered ('\n'); | |
c906108c SS |
8739 | } |
8740 | \f | |
8741 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
8742 | all breakpoints that are marked for deletion, whether hit or not. | |
8743 | This is called after any breakpoint is hit, or after errors. */ | |
8744 | ||
8745 | void | |
fba45db2 | 8746 | breakpoint_auto_delete (bpstat bs) |
c906108c SS |
8747 | { |
8748 | struct breakpoint *b, *temp; | |
8749 | ||
8750 | for (; bs; bs = bs->next) | |
20874c92 VP |
8751 | if (bs->breakpoint_at |
8752 | && bs->breakpoint_at->owner | |
8753 | && bs->breakpoint_at->owner->disposition == disp_del | |
c906108c | 8754 | && bs->stop) |
4f8d1dc6 | 8755 | delete_breakpoint (bs->breakpoint_at->owner); |
c906108c SS |
8756 | |
8757 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b | 8758 | { |
b5de0fa7 | 8759 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
8760 | delete_breakpoint (b); |
8761 | } | |
c906108c SS |
8762 | } |
8763 | ||
494cfb0f | 8764 | /* A comparison function for bp_location AP and BP being interfaced to qsort. |
876fa593 JK |
8765 | Sort elements primarily by their ADDRESS (no matter what does |
8766 | breakpoint_address_is_meaningful say for its OWNER), secondarily by ordering | |
8767 | first bp_permanent OWNERed elements and terciarily just ensuring the array | |
8768 | is sorted stable way despite qsort being an instable algorithm. */ | |
8769 | ||
8770 | static int | |
494cfb0f | 8771 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 8772 | { |
494cfb0f JK |
8773 | struct bp_location *a = *(void **) ap; |
8774 | struct bp_location *b = *(void **) bp; | |
876fa593 JK |
8775 | int a_perm = a->owner->enable_state == bp_permanent; |
8776 | int b_perm = b->owner->enable_state == bp_permanent; | |
8777 | ||
8778 | if (a->address != b->address) | |
8779 | return (a->address > b->address) - (a->address < b->address); | |
8780 | ||
8781 | /* Sort permanent breakpoints first. */ | |
8782 | if (a_perm != b_perm) | |
8783 | return (a_perm < b_perm) - (a_perm > b_perm); | |
8784 | ||
8785 | /* Make the user-visible order stable across GDB runs. Locations of the same | |
8786 | breakpoint can be sorted in arbitrary order. */ | |
8787 | ||
8788 | if (a->owner->number != b->owner->number) | |
8789 | return (a->owner->number > b->owner->number) | |
8790 | - (a->owner->number < b->owner->number); | |
8791 | ||
8792 | return (a > b) - (a < b); | |
8793 | } | |
8794 | ||
876fa593 JK |
8795 | /* Set bp_location_placed_address_before_address_max and |
8796 | bp_location_shadow_len_after_address_max according to the current content of | |
8797 | the bp_location array. */ | |
f7545552 TT |
8798 | |
8799 | static void | |
876fa593 | 8800 | bp_location_target_extensions_update (void) |
f7545552 | 8801 | { |
876fa593 JK |
8802 | struct bp_location *bl, **blp_tmp; |
8803 | ||
8804 | bp_location_placed_address_before_address_max = 0; | |
8805 | bp_location_shadow_len_after_address_max = 0; | |
8806 | ||
8807 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
8808 | { | |
8809 | CORE_ADDR start, end, addr; | |
8810 | ||
8811 | if (!bp_location_has_shadow (bl)) | |
8812 | continue; | |
8813 | ||
8814 | start = bl->target_info.placed_address; | |
8815 | end = start + bl->target_info.shadow_len; | |
8816 | ||
8817 | gdb_assert (bl->address >= start); | |
8818 | addr = bl->address - start; | |
8819 | if (addr > bp_location_placed_address_before_address_max) | |
8820 | bp_location_placed_address_before_address_max = addr; | |
8821 | ||
8822 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
8823 | ||
8824 | gdb_assert (bl->address < end); | |
8825 | addr = end - bl->address; | |
8826 | if (addr > bp_location_shadow_len_after_address_max) | |
8827 | bp_location_shadow_len_after_address_max = addr; | |
8828 | } | |
f7545552 TT |
8829 | } |
8830 | ||
4cd9bd08 | 8831 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
b60e7edf PA |
8832 | into the inferior, only remove already-inserted locations that no |
8833 | longer should be inserted. Functions that delete a breakpoint or | |
8834 | breakpoints should pass false, so that deleting a breakpoint | |
8835 | doesn't have the side effect of inserting the locations of other | |
8836 | breakpoints that are marked not-inserted, but should_be_inserted | |
8837 | returns true on them. | |
8838 | ||
8839 | This behaviour is useful is situations close to tear-down -- e.g., | |
8840 | after an exec, while the target still has execution, but breakpoint | |
8841 | shadows of the previous executable image should *NOT* be restored | |
8842 | to the new image; or before detaching, where the target still has | |
8843 | execution and wants to delete breakpoints from GDB's lists, and all | |
8844 | breakpoints had already been removed from the inferior. */ | |
8845 | ||
0d381245 | 8846 | static void |
b60e7edf | 8847 | update_global_location_list (int should_insert) |
0d381245 | 8848 | { |
74960c60 | 8849 | struct breakpoint *b; |
876fa593 | 8850 | struct bp_location **locp, *loc; |
f7545552 TT |
8851 | struct cleanup *cleanups; |
8852 | ||
2d134ed3 PA |
8853 | /* Used in the duplicates detection below. When iterating over all |
8854 | bp_locations, points to the first bp_location of a given address. | |
8855 | Breakpoints and watchpoints of different types are never | |
8856 | duplicates of each other. Keep one pointer for each type of | |
8857 | breakpoint/watchpoint, so we only need to loop over all locations | |
8858 | once. */ | |
8859 | struct bp_location *bp_loc_first; /* breakpoint */ | |
8860 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
8861 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
8862 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 JK |
8863 | |
8864 | /* Saved former bp_location array which we compare against the newly built | |
8865 | bp_location from the current state of ALL_BREAKPOINTS. */ | |
8866 | struct bp_location **old_location, **old_locp; | |
8867 | unsigned old_location_count; | |
8868 | ||
8869 | old_location = bp_location; | |
8870 | old_location_count = bp_location_count; | |
8871 | bp_location = NULL; | |
8872 | bp_location_count = 0; | |
8873 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 8874 | |
74960c60 | 8875 | ALL_BREAKPOINTS (b) |
876fa593 JK |
8876 | for (loc = b->loc; loc; loc = loc->next) |
8877 | bp_location_count++; | |
8878 | ||
8879 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); | |
8880 | locp = bp_location; | |
8881 | ALL_BREAKPOINTS (b) | |
8882 | for (loc = b->loc; loc; loc = loc->next) | |
8883 | *locp++ = loc; | |
8884 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 8885 | bp_location_compare); |
876fa593 JK |
8886 | |
8887 | bp_location_target_extensions_update (); | |
74960c60 VP |
8888 | |
8889 | /* Identify bp_location instances that are no longer present in the new | |
8890 | list, and therefore should be freed. Note that it's not necessary that | |
8891 | those locations should be removed from inferior -- if there's another | |
8892 | location at the same address (previously marked as duplicate), | |
876fa593 JK |
8893 | we don't need to remove/insert the location. |
8894 | ||
8895 | LOCP is kept in sync with OLD_LOCP, each pointing to the current and | |
8896 | former bp_location array state respectively. */ | |
8897 | ||
8898 | locp = bp_location; | |
8899 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
8900 | old_locp++) | |
74960c60 | 8901 | { |
876fa593 | 8902 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 8903 | struct bp_location **loc2p; |
876fa593 JK |
8904 | |
8905 | /* Tells if 'old_loc' is found amoung the new locations. If not, we | |
74960c60 | 8906 | have to free it. */ |
c7d46a38 | 8907 | int found_object = 0; |
20874c92 VP |
8908 | /* Tells if the location should remain inserted in the target. */ |
8909 | int keep_in_target = 0; | |
8910 | int removed = 0; | |
876fa593 JK |
8911 | |
8912 | /* Skip LOCP entries which will definitely never be needed. Stop either | |
8913 | at or being the one matching OLD_LOC. */ | |
8914 | while (locp < bp_location + bp_location_count | |
c7d46a38 | 8915 | && (*locp)->address < old_loc->address) |
876fa593 | 8916 | locp++; |
c7d46a38 PA |
8917 | |
8918 | for (loc2p = locp; | |
8919 | (loc2p < bp_location + bp_location_count | |
8920 | && (*loc2p)->address == old_loc->address); | |
8921 | loc2p++) | |
8922 | { | |
8923 | if (*loc2p == old_loc) | |
8924 | { | |
8925 | found_object = 1; | |
8926 | break; | |
8927 | } | |
8928 | } | |
74960c60 VP |
8929 | |
8930 | /* If this location is no longer present, and inserted, look if there's | |
8931 | maybe a new location at the same address. If so, mark that one | |
8932 | inserted, and don't remove this one. This is needed so that we | |
8933 | don't have a time window where a breakpoint at certain location is not | |
8934 | inserted. */ | |
8935 | ||
876fa593 | 8936 | if (old_loc->inserted) |
0d381245 | 8937 | { |
74960c60 | 8938 | /* If the location is inserted now, we might have to remove it. */ |
74960c60 | 8939 | |
876fa593 | 8940 | if (found_object && should_be_inserted (old_loc)) |
74960c60 VP |
8941 | { |
8942 | /* The location is still present in the location list, and still | |
8943 | should be inserted. Don't do anything. */ | |
20874c92 | 8944 | keep_in_target = 1; |
74960c60 VP |
8945 | } |
8946 | else | |
8947 | { | |
8948 | /* The location is either no longer present, or got disabled. | |
8949 | See if there's another location at the same address, in which | |
8950 | case we don't need to remove this one from the target. */ | |
876fa593 JK |
8951 | |
8952 | if (breakpoint_address_is_meaningful (old_loc->owner)) | |
8953 | { | |
876fa593 | 8954 | for (loc2p = locp; |
c7d46a38 PA |
8955 | (loc2p < bp_location + bp_location_count |
8956 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
8957 | loc2p++) |
8958 | { | |
8959 | struct bp_location *loc2 = *loc2p; | |
8960 | ||
2d134ed3 | 8961 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 PA |
8962 | { |
8963 | /* For the sake of should_be_inserted. | |
8964 | Duplicates check below will fix up this later. */ | |
8965 | loc2->duplicate = 0; | |
85d721b8 PA |
8966 | |
8967 | /* Read watchpoint locations are switched to | |
8968 | access watchpoints, if the former are not | |
8969 | supported, but the latter are. */ | |
8970 | if (is_hardware_watchpoint (old_loc->owner)) | |
8971 | { | |
8972 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
8973 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
8974 | } | |
8975 | ||
c7d46a38 PA |
8976 | if (loc2 != old_loc && should_be_inserted (loc2)) |
8977 | { | |
8978 | loc2->inserted = 1; | |
8979 | loc2->target_info = old_loc->target_info; | |
8980 | keep_in_target = 1; | |
8981 | break; | |
8982 | } | |
876fa593 JK |
8983 | } |
8984 | } | |
8985 | } | |
74960c60 VP |
8986 | } |
8987 | ||
20874c92 VP |
8988 | if (!keep_in_target) |
8989 | { | |
876fa593 | 8990 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 VP |
8991 | { |
8992 | /* This is just about all we can do. We could keep this | |
8993 | location on the global list, and try to remove it next | |
8994 | time, but there's no particular reason why we will | |
8995 | succeed next time. | |
8996 | ||
876fa593 | 8997 | Note that at this point, old_loc->owner is still valid, |
20874c92 VP |
8998 | as delete_breakpoint frees the breakpoint only |
8999 | after calling us. */ | |
9000 | printf_filtered (_("warning: Error removing breakpoint %d\n"), | |
876fa593 | 9001 | old_loc->owner->number); |
20874c92 VP |
9002 | } |
9003 | removed = 1; | |
9004 | } | |
0d381245 | 9005 | } |
74960c60 VP |
9006 | |
9007 | if (!found_object) | |
1c5cfe86 | 9008 | { |
db82e815 PA |
9009 | if (removed && non_stop |
9010 | && breakpoint_address_is_meaningful (old_loc->owner) | |
9011 | && !is_hardware_watchpoint (old_loc->owner)) | |
20874c92 | 9012 | { |
db82e815 PA |
9013 | /* This location was removed from the target. In |
9014 | non-stop mode, a race condition is possible where | |
9015 | we've removed a breakpoint, but stop events for that | |
9016 | breakpoint are already queued and will arrive later. | |
9017 | We apply an heuristic to be able to distinguish such | |
9018 | SIGTRAPs from other random SIGTRAPs: we keep this | |
9019 | breakpoint location for a bit, and will retire it | |
9020 | after we see some number of events. The theory here | |
9021 | is that reporting of events should, "on the average", | |
9022 | be fair, so after a while we'll see events from all | |
9023 | threads that have anything of interest, and no longer | |
9024 | need to keep this breakpoint location around. We | |
9025 | don't hold locations forever so to reduce chances of | |
9026 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
9027 | SIGTRAP. | |
9028 | ||
9029 | The heuristic failing can be disastrous on | |
9030 | decr_pc_after_break targets. | |
9031 | ||
9032 | On decr_pc_after_break targets, like e.g., x86-linux, | |
9033 | if we fail to recognize a late breakpoint SIGTRAP, | |
9034 | because events_till_retirement has reached 0 too | |
9035 | soon, we'll fail to do the PC adjustment, and report | |
9036 | a random SIGTRAP to the user. When the user resumes | |
9037 | the inferior, it will most likely immediately crash | |
9038 | with SIGILL/SIGBUS/SEGSEGV, or worse, get silently | |
9039 | corrupted, because of being resumed e.g., in the | |
9040 | middle of a multi-byte instruction, or skipped a | |
9041 | one-byte instruction. This was actually seen happen | |
9042 | on native x86-linux, and should be less rare on | |
9043 | targets that do not support new thread events, like | |
9044 | remote, due to the heuristic depending on | |
9045 | thread_count. | |
9046 | ||
9047 | Mistaking a random SIGTRAP for a breakpoint trap | |
9048 | causes similar symptoms (PC adjustment applied when | |
9049 | it shouldn't), but then again, playing with SIGTRAPs | |
9050 | behind the debugger's back is asking for trouble. | |
9051 | ||
9052 | Since hardware watchpoint traps are always | |
9053 | distinguishable from other traps, so we don't need to | |
9054 | apply keep hardware watchpoint moribund locations | |
9055 | around. We simply always ignore hardware watchpoint | |
9056 | traps we can no longer explain. */ | |
9057 | ||
876fa593 JK |
9058 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
9059 | old_loc->owner = NULL; | |
20874c92 | 9060 | |
876fa593 | 9061 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
9062 | } |
9063 | else | |
876fa593 | 9064 | free_bp_location (old_loc); |
20874c92 | 9065 | } |
74960c60 | 9066 | } |
1c5cfe86 | 9067 | |
2d134ed3 PA |
9068 | /* Rescan breakpoints at the same address and section, marking the |
9069 | first one as "first" and any others as "duplicates". This is so | |
9070 | that the bpt instruction is only inserted once. If we have a | |
9071 | permanent breakpoint at the same place as BPT, make that one the | |
9072 | official one, and the rest as duplicates. Permanent breakpoints | |
9073 | are sorted first for the same address. | |
9074 | ||
9075 | Do the same for hardware watchpoints, but also considering the | |
9076 | watchpoint's type (regular/access/read) and length. */ | |
876fa593 | 9077 | |
2d134ed3 PA |
9078 | bp_loc_first = NULL; |
9079 | wp_loc_first = NULL; | |
9080 | awp_loc_first = NULL; | |
9081 | rwp_loc_first = NULL; | |
876fa593 | 9082 | ALL_BP_LOCATIONS (loc, locp) |
74960c60 | 9083 | { |
876fa593 | 9084 | struct breakpoint *b = loc->owner; |
2d134ed3 | 9085 | struct bp_location **loc_first_p; |
876fa593 JK |
9086 | |
9087 | if (b->enable_state == bp_disabled | |
9088 | || b->enable_state == bp_call_disabled | |
9089 | || b->enable_state == bp_startup_disabled | |
9090 | || !loc->enabled | |
9091 | || loc->shlib_disabled | |
15c3d785 PA |
9092 | || !breakpoint_address_is_meaningful (b) |
9093 | || tracepoint_type (b)) | |
876fa593 JK |
9094 | continue; |
9095 | ||
9096 | /* Permanent breakpoint should always be inserted. */ | |
9097 | if (b->enable_state == bp_permanent && ! loc->inserted) | |
9098 | internal_error (__FILE__, __LINE__, | |
9099 | _("allegedly permanent breakpoint is not " | |
9100 | "actually inserted")); | |
9101 | ||
2d134ed3 PA |
9102 | if (b->type == bp_hardware_watchpoint) |
9103 | loc_first_p = &wp_loc_first; | |
9104 | else if (b->type == bp_read_watchpoint) | |
9105 | loc_first_p = &rwp_loc_first; | |
9106 | else if (b->type == bp_access_watchpoint) | |
9107 | loc_first_p = &awp_loc_first; | |
9108 | else | |
9109 | loc_first_p = &bp_loc_first; | |
9110 | ||
9111 | if (*loc_first_p == NULL | |
9112 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
9113 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
876fa593 | 9114 | { |
2d134ed3 | 9115 | *loc_first_p = loc; |
876fa593 JK |
9116 | loc->duplicate = 0; |
9117 | continue; | |
9118 | } | |
9119 | ||
9120 | loc->duplicate = 1; | |
9121 | ||
2d134ed3 PA |
9122 | if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted |
9123 | && b->enable_state != bp_permanent) | |
876fa593 JK |
9124 | internal_error (__FILE__, __LINE__, |
9125 | _("another breakpoint was inserted on top of " | |
9126 | "a permanent breakpoint")); | |
0d381245 | 9127 | } |
74960c60 | 9128 | |
50c71eaf | 9129 | if (breakpoints_always_inserted_mode () && should_insert |
c35b1492 | 9130 | && (have_live_inferiors () |
2567c7d9 | 9131 | || (gdbarch_has_global_breakpoints (target_gdbarch)))) |
74960c60 | 9132 | insert_breakpoint_locations (); |
f7545552 TT |
9133 | |
9134 | do_cleanups (cleanups); | |
74960c60 VP |
9135 | } |
9136 | ||
20874c92 VP |
9137 | void |
9138 | breakpoint_retire_moribund (void) | |
9139 | { | |
9140 | struct bp_location *loc; | |
9141 | int ix; | |
9142 | ||
9143 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
9144 | if (--(loc->events_till_retirement) == 0) | |
9145 | { | |
9146 | free_bp_location (loc); | |
9147 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
9148 | --ix; | |
9149 | } | |
9150 | } | |
9151 | ||
74960c60 | 9152 | static void |
b60e7edf | 9153 | update_global_location_list_nothrow (int inserting) |
74960c60 VP |
9154 | { |
9155 | struct gdb_exception e; | |
9156 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
b60e7edf | 9157 | update_global_location_list (inserting); |
0d381245 VP |
9158 | } |
9159 | ||
a474d7c2 PA |
9160 | /* Clear BPT from a BPS. */ |
9161 | static void | |
9162 | bpstat_remove_breakpoint (bpstat bps, struct breakpoint *bpt) | |
9163 | { | |
9164 | bpstat bs; | |
9165 | for (bs = bps; bs; bs = bs->next) | |
9166 | if (bs->breakpoint_at && bs->breakpoint_at->owner == bpt) | |
9167 | { | |
9168 | bs->breakpoint_at = NULL; | |
9169 | bs->old_val = NULL; | |
9170 | /* bs->commands will be freed later. */ | |
9171 | } | |
9172 | } | |
9173 | ||
9174 | /* Callback for iterate_over_threads. */ | |
9175 | static int | |
9176 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
9177 | { | |
9178 | struct breakpoint *bpt = data; | |
9179 | bpstat_remove_breakpoint (th->stop_bpstat, bpt); | |
9180 | return 0; | |
9181 | } | |
9182 | ||
53a5351d JM |
9183 | /* Delete a breakpoint and clean up all traces of it in the data |
9184 | structures. */ | |
c906108c SS |
9185 | |
9186 | void | |
fba45db2 | 9187 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 9188 | { |
52f0bd74 | 9189 | struct breakpoint *b; |
74960c60 | 9190 | struct bp_location *loc, *next; |
c906108c | 9191 | |
8a3fe4f8 | 9192 | gdb_assert (bpt != NULL); |
c906108c SS |
9193 | |
9194 | /* Has this bp already been deleted? This can happen because multiple | |
9195 | lists can hold pointers to bp's. bpstat lists are especial culprits. | |
9196 | ||
9197 | One example of this happening is a watchpoint's scope bp. When the | |
9198 | scope bp triggers, we notice that the watchpoint is out of scope, and | |
9199 | delete it. We also delete its scope bp. But the scope bp is marked | |
9200 | "auto-deleting", and is already on a bpstat. That bpstat is then | |
9201 | checked for auto-deleting bp's, which are deleted. | |
9202 | ||
9203 | A real solution to this problem might involve reference counts in bp's, | |
9204 | and/or giving them pointers back to their referencing bpstat's, and | |
9205 | teaching delete_breakpoint to only free a bp's storage when no more | |
1272ad14 | 9206 | references were extent. A cheaper bandaid was chosen. */ |
c906108c SS |
9207 | if (bpt->type == bp_none) |
9208 | return; | |
9209 | ||
e5a0a904 JK |
9210 | /* At least avoid this stale reference until the reference counting of |
9211 | breakpoints gets resolved. */ | |
9212 | if (bpt->related_breakpoint != NULL) | |
9213 | { | |
9214 | gdb_assert (bpt->related_breakpoint->related_breakpoint == bpt); | |
9215 | bpt->related_breakpoint->disposition = disp_del_at_next_stop; | |
9216 | bpt->related_breakpoint->related_breakpoint = NULL; | |
9217 | bpt->related_breakpoint = NULL; | |
9218 | } | |
9219 | ||
383f836e | 9220 | observer_notify_breakpoint_deleted (bpt->number); |
c906108c | 9221 | |
c906108c SS |
9222 | if (breakpoint_chain == bpt) |
9223 | breakpoint_chain = bpt->next; | |
9224 | ||
c906108c SS |
9225 | ALL_BREAKPOINTS (b) |
9226 | if (b->next == bpt) | |
c5aa993b JM |
9227 | { |
9228 | b->next = bpt->next; | |
9229 | break; | |
9230 | } | |
c906108c | 9231 | |
9add0f1b | 9232 | decref_counted_command_line (&bpt->commands); |
60e1c644 PA |
9233 | xfree (bpt->cond_string); |
9234 | xfree (bpt->cond_exp); | |
9235 | xfree (bpt->addr_string); | |
9236 | xfree (bpt->exp); | |
9237 | xfree (bpt->exp_string); | |
9238 | value_free (bpt->val); | |
9239 | xfree (bpt->source_file); | |
9240 | xfree (bpt->exec_pathname); | |
a96d9b2e | 9241 | clean_up_filters (&bpt->syscalls_to_be_caught); |
c906108c SS |
9242 | |
9243 | /* Be sure no bpstat's are pointing at it after it's been freed. */ | |
9244 | /* FIXME, how can we find all bpstat's? | |
198757a8 VP |
9245 | We just check stop_bpstat for now. Note that we cannot just |
9246 | remove bpstats pointing at bpt from the stop_bpstat list | |
9247 | entirely, as breakpoint commands are associated with the bpstat; | |
9248 | if we remove it here, then the later call to | |
9249 | bpstat_do_actions (&stop_bpstat); | |
9250 | in event-top.c won't do anything, and temporary breakpoints | |
9251 | with commands won't work. */ | |
a474d7c2 | 9252 | |
a474d7c2 | 9253 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); |
74960c60 VP |
9254 | |
9255 | /* Now that breakpoint is removed from breakpoint | |
9256 | list, update the global location list. This | |
9257 | will remove locations that used to belong to | |
9258 | this breakpoint. Do this before freeing | |
9259 | the breakpoint itself, since remove_breakpoint | |
9260 | looks at location's owner. It might be better | |
9261 | design to have location completely self-contained, | |
9262 | but it's not the case now. */ | |
b60e7edf | 9263 | update_global_location_list (0); |
74960c60 VP |
9264 | |
9265 | ||
c906108c SS |
9266 | /* On the chance that someone will soon try again to delete this same |
9267 | bp, we mark it as deleted before freeing its storage. */ | |
9268 | bpt->type = bp_none; | |
9269 | ||
b8c9b27d | 9270 | xfree (bpt); |
c906108c SS |
9271 | } |
9272 | ||
4d6140d9 AC |
9273 | static void |
9274 | do_delete_breakpoint_cleanup (void *b) | |
9275 | { | |
9276 | delete_breakpoint (b); | |
9277 | } | |
9278 | ||
9279 | struct cleanup * | |
9280 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
9281 | { | |
9282 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
9283 | } | |
9284 | ||
95a42b64 TT |
9285 | /* A callback for map_breakpoint_numbers that calls |
9286 | delete_breakpoint. */ | |
9287 | ||
9288 | static void | |
9289 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
9290 | { | |
9291 | delete_breakpoint (b); | |
9292 | } | |
9293 | ||
c906108c | 9294 | void |
fba45db2 | 9295 | delete_command (char *arg, int from_tty) |
c906108c SS |
9296 | { |
9297 | struct breakpoint *b, *temp; | |
9298 | ||
ea9365bb TT |
9299 | dont_repeat (); |
9300 | ||
c906108c SS |
9301 | if (arg == 0) |
9302 | { | |
9303 | int breaks_to_delete = 0; | |
9304 | ||
9305 | /* Delete all breakpoints if no argument. | |
c5aa993b JM |
9306 | Do not delete internal or call-dummy breakpoints, these |
9307 | have to be deleted with an explicit breakpoint number argument. */ | |
9308 | ALL_BREAKPOINTS (b) | |
9309 | { | |
059fb39f | 9310 | if (b->type != bp_call_dummy |
aa7d318d | 9311 | && b->type != bp_std_terminate |
059fb39f | 9312 | && b->type != bp_shlib_event |
4efc6507 | 9313 | && b->type != bp_jit_event |
059fb39f PM |
9314 | && b->type != bp_thread_event |
9315 | && b->type != bp_overlay_event | |
0fd8e87f | 9316 | && b->type != bp_longjmp_master |
aa7d318d | 9317 | && b->type != bp_std_terminate_master |
059fb39f | 9318 | && b->number >= 0) |
973d738b DJ |
9319 | { |
9320 | breaks_to_delete = 1; | |
9321 | break; | |
9322 | } | |
c5aa993b | 9323 | } |
c906108c SS |
9324 | |
9325 | /* Ask user only if there are some breakpoints to delete. */ | |
9326 | if (!from_tty | |
e2e0b3e5 | 9327 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 9328 | { |
c5aa993b JM |
9329 | ALL_BREAKPOINTS_SAFE (b, temp) |
9330 | { | |
059fb39f | 9331 | if (b->type != bp_call_dummy |
aa7d318d | 9332 | && b->type != bp_std_terminate |
059fb39f PM |
9333 | && b->type != bp_shlib_event |
9334 | && b->type != bp_thread_event | |
4efc6507 | 9335 | && b->type != bp_jit_event |
059fb39f | 9336 | && b->type != bp_overlay_event |
0fd8e87f | 9337 | && b->type != bp_longjmp_master |
aa7d318d | 9338 | && b->type != bp_std_terminate_master |
059fb39f | 9339 | && b->number >= 0) |
c5aa993b JM |
9340 | delete_breakpoint (b); |
9341 | } | |
c906108c SS |
9342 | } |
9343 | } | |
9344 | else | |
95a42b64 | 9345 | map_breakpoint_numbers (arg, do_delete_breakpoint, NULL); |
c906108c SS |
9346 | } |
9347 | ||
0d381245 VP |
9348 | static int |
9349 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 9350 | { |
0d381245 VP |
9351 | for (; loc; loc = loc->next) |
9352 | if (!loc->shlib_disabled) | |
9353 | return 0; | |
9354 | return 1; | |
fe3f5fa8 VP |
9355 | } |
9356 | ||
776592bf DE |
9357 | /* Subroutine of update_breakpoint_locations to simplify it. |
9358 | Return non-zero if multiple fns in list LOC have the same name. | |
9359 | Null names are ignored. */ | |
9360 | ||
9361 | static int | |
9362 | ambiguous_names_p (struct bp_location *loc) | |
9363 | { | |
9364 | struct bp_location *l; | |
9365 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
9366 | (int (*) (const void *, const void *)) streq, | |
9367 | NULL, xcalloc, xfree); | |
9368 | ||
9369 | for (l = loc; l != NULL; l = l->next) | |
9370 | { | |
9371 | const char **slot; | |
9372 | const char *name = l->function_name; | |
9373 | ||
9374 | /* Allow for some names to be NULL, ignore them. */ | |
9375 | if (name == NULL) | |
9376 | continue; | |
9377 | ||
9378 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
9379 | INSERT); | |
9380 | /* NOTE: We can assume slot != NULL here because xcalloc never returns | |
9381 | NULL. */ | |
9382 | if (*slot != NULL) | |
9383 | { | |
9384 | htab_delete (htab); | |
9385 | return 1; | |
9386 | } | |
9387 | *slot = name; | |
9388 | } | |
9389 | ||
9390 | htab_delete (htab); | |
9391 | return 0; | |
9392 | } | |
9393 | ||
fe3f5fa8 | 9394 | static void |
0d381245 VP |
9395 | update_breakpoint_locations (struct breakpoint *b, |
9396 | struct symtabs_and_lines sals) | |
fe3f5fa8 VP |
9397 | { |
9398 | int i; | |
9399 | char *s; | |
0d381245 VP |
9400 | struct bp_location *existing_locations = b->loc; |
9401 | ||
9402 | /* If there's no new locations, and all existing locations | |
9403 | are pending, don't do anything. This optimizes | |
9404 | the common case where all locations are in the same | |
9405 | shared library, that was unloaded. We'd like to | |
9406 | retain the location, so that when the library | |
9407 | is loaded again, we don't loose the enabled/disabled | |
9408 | status of the individual locations. */ | |
9409 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) | |
fe3f5fa8 VP |
9410 | return; |
9411 | ||
fe3f5fa8 VP |
9412 | b->loc = NULL; |
9413 | ||
0d381245 | 9414 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 9415 | { |
0d381245 | 9416 | struct bp_location *new_loc = |
39d61571 | 9417 | add_location_to_breakpoint (b, &(sals.sals[i])); |
fe3f5fa8 | 9418 | |
0d381245 VP |
9419 | /* Reparse conditions, they might contain references to the |
9420 | old symtab. */ | |
9421 | if (b->cond_string != NULL) | |
9422 | { | |
9423 | struct gdb_exception e; | |
fe3f5fa8 | 9424 | |
0d381245 VP |
9425 | s = b->cond_string; |
9426 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
9427 | { | |
9428 | new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), | |
9429 | 0); | |
9430 | } | |
9431 | if (e.reason < 0) | |
9432 | { | |
9433 | warning (_("failed to reevaluate condition for breakpoint %d: %s"), | |
9434 | b->number, e.message); | |
9435 | new_loc->enabled = 0; | |
9436 | } | |
9437 | } | |
fe3f5fa8 | 9438 | |
0d381245 VP |
9439 | if (b->source_file != NULL) |
9440 | xfree (b->source_file); | |
9441 | if (sals.sals[i].symtab == NULL) | |
9442 | b->source_file = NULL; | |
9443 | else | |
1b36a34b | 9444 | b->source_file = xstrdup (sals.sals[i].symtab->filename); |
fe3f5fa8 | 9445 | |
0d381245 VP |
9446 | if (b->line_number == 0) |
9447 | b->line_number = sals.sals[i].line; | |
9448 | } | |
fe3f5fa8 | 9449 | |
514f746b AR |
9450 | /* Update locations of permanent breakpoints. */ |
9451 | if (b->enable_state == bp_permanent) | |
9452 | make_breakpoint_permanent (b); | |
9453 | ||
0d381245 VP |
9454 | /* If possible, carry over 'disable' status from existing breakpoints. */ |
9455 | { | |
9456 | struct bp_location *e = existing_locations; | |
776592bf DE |
9457 | /* If there are multiple breakpoints with the same function name, |
9458 | e.g. for inline functions, comparing function names won't work. | |
9459 | Instead compare pc addresses; this is just a heuristic as things | |
9460 | may have moved, but in practice it gives the correct answer | |
9461 | often enough until a better solution is found. */ | |
9462 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
9463 | ||
0d381245 VP |
9464 | for (; e; e = e->next) |
9465 | { | |
9466 | if (!e->enabled && e->function_name) | |
9467 | { | |
9468 | struct bp_location *l = b->loc; | |
776592bf DE |
9469 | if (have_ambiguous_names) |
9470 | { | |
9471 | for (; l; l = l->next) | |
6c95b8df PA |
9472 | if (breakpoint_address_match (e->pspace->aspace, e->address, |
9473 | l->pspace->aspace, l->address)) | |
776592bf DE |
9474 | { |
9475 | l->enabled = 0; | |
9476 | break; | |
9477 | } | |
9478 | } | |
9479 | else | |
9480 | { | |
9481 | for (; l; l = l->next) | |
9482 | if (l->function_name | |
9483 | && strcmp (e->function_name, l->function_name) == 0) | |
9484 | { | |
9485 | l->enabled = 0; | |
9486 | break; | |
9487 | } | |
9488 | } | |
0d381245 VP |
9489 | } |
9490 | } | |
9491 | } | |
fe3f5fa8 | 9492 | |
b60e7edf | 9493 | update_global_location_list (1); |
fe3f5fa8 VP |
9494 | } |
9495 | ||
9496 | ||
c906108c SS |
9497 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
9498 | The value we return ends up being the return value from catch_errors. | |
9499 | Unused in this case. */ | |
9500 | ||
9501 | static int | |
4efb68b1 | 9502 | breakpoint_re_set_one (void *bint) |
c906108c | 9503 | { |
53a5351d JM |
9504 | /* get past catch_errs */ |
9505 | struct breakpoint *b = (struct breakpoint *) bint; | |
c906108c SS |
9506 | struct value *mark; |
9507 | int i; | |
fe3f5fa8 VP |
9508 | int not_found = 0; |
9509 | int *not_found_ptr = ¬_found; | |
6c95b8df PA |
9510 | struct symtabs_and_lines sals = {0}; |
9511 | struct symtabs_and_lines expanded = {0}; | |
c906108c | 9512 | char *s; |
b5de0fa7 | 9513 | enum enable_state save_enable; |
fe3f5fa8 | 9514 | struct gdb_exception e; |
6c95b8df | 9515 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
c906108c SS |
9516 | |
9517 | switch (b->type) | |
9518 | { | |
9519 | case bp_none: | |
8a3fe4f8 | 9520 | warning (_("attempted to reset apparently deleted breakpoint #%d?"), |
53a5351d | 9521 | b->number); |
c906108c SS |
9522 | return 0; |
9523 | case bp_breakpoint: | |
9524 | case bp_hardware_breakpoint: | |
1042e4c0 | 9525 | case bp_tracepoint: |
7a697b8d | 9526 | case bp_fast_tracepoint: |
8bea4e01 UW |
9527 | /* Do not attempt to re-set breakpoints disabled during startup. */ |
9528 | if (b->enable_state == bp_startup_disabled) | |
9529 | return 0; | |
9530 | ||
c906108c SS |
9531 | if (b->addr_string == NULL) |
9532 | { | |
9533 | /* Anything without a string can't be re-set. */ | |
9534 | delete_breakpoint (b); | |
9535 | return 0; | |
9536 | } | |
c906108c SS |
9537 | |
9538 | set_language (b->language); | |
9539 | input_radix = b->input_radix; | |
9540 | s = b->addr_string; | |
6c95b8df PA |
9541 | |
9542 | save_current_space_and_thread (); | |
9543 | switch_to_program_space_and_thread (b->pspace); | |
9544 | ||
fe3f5fa8 | 9545 | TRY_CATCH (e, RETURN_MASK_ERROR) |
c906108c | 9546 | { |
fe3f5fa8 VP |
9547 | sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL, |
9548 | not_found_ptr); | |
9549 | } | |
9550 | if (e.reason < 0) | |
9551 | { | |
9552 | int not_found_and_ok = 0; | |
9553 | /* For pending breakpoints, it's expected that parsing | |
9554 | will fail until the right shared library is loaded. | |
9555 | User has already told to create pending breakpoints and | |
9556 | don't need extra messages. If breakpoint is in bp_shlib_disabled | |
9557 | state, then user already saw the message about that breakpoint | |
9558 | being disabled, and don't want to see more errors. */ | |
0d381245 VP |
9559 | if (not_found |
9560 | && (b->condition_not_parsed | |
9561 | || (b->loc && b->loc->shlib_disabled) | |
9562 | || b->enable_state == bp_disabled)) | |
fe3f5fa8 VP |
9563 | not_found_and_ok = 1; |
9564 | ||
9565 | if (!not_found_and_ok) | |
c906108c | 9566 | { |
fe3f5fa8 VP |
9567 | /* We surely don't want to warn about the same breakpoint |
9568 | 10 times. One solution, implemented here, is disable | |
9569 | the breakpoint on error. Another solution would be to | |
9570 | have separate 'warning emitted' flag. Since this | |
9571 | happens only when a binary has changed, I don't know | |
9572 | which approach is better. */ | |
9573 | b->enable_state = bp_disabled; | |
9574 | throw_exception (e); | |
c906108c | 9575 | } |
fe3f5fa8 | 9576 | } |
c906108c | 9577 | |
6c95b8df | 9578 | if (!not_found) |
fe3f5fa8 | 9579 | { |
6c95b8df PA |
9580 | gdb_assert (sals.nelts == 1); |
9581 | ||
9582 | resolve_sal_pc (&sals.sals[0]); | |
9583 | if (b->condition_not_parsed && s && s[0]) | |
9584 | { | |
9585 | char *cond_string = 0; | |
9586 | int thread = -1; | |
9587 | int task = 0; | |
9588 | ||
9589 | find_condition_and_thread (s, sals.sals[0].pc, | |
9590 | &cond_string, &thread, &task); | |
9591 | if (cond_string) | |
9592 | b->cond_string = cond_string; | |
9593 | b->thread = thread; | |
9594 | b->task = task; | |
9595 | b->condition_not_parsed = 0; | |
9596 | } | |
9597 | ||
9598 | expanded = expand_line_sal_maybe (sals.sals[0]); | |
fe3f5fa8 | 9599 | } |
6c95b8df PA |
9600 | |
9601 | make_cleanup (xfree, sals.sals); | |
ed0616c6 | 9602 | update_breakpoint_locations (b, expanded); |
c906108c SS |
9603 | break; |
9604 | ||
9605 | case bp_watchpoint: | |
9606 | case bp_hardware_watchpoint: | |
9607 | case bp_read_watchpoint: | |
9608 | case bp_access_watchpoint: | |
0b3de036 VP |
9609 | /* Watchpoint can be either on expression using entirely global variables, |
9610 | or it can be on local variables. | |
9611 | ||
9612 | Watchpoints of the first kind are never auto-deleted, and even persist | |
9613 | across program restarts. Since they can use variables from shared | |
9614 | libraries, we need to reparse expression as libraries are loaded | |
9615 | and unloaded. | |
9616 | ||
9617 | Watchpoints on local variables can also change meaning as result | |
9618 | of solib event. For example, if a watchpoint uses both a local and | |
9619 | a global variables in expression, it's a local watchpoint, but | |
9620 | unloading of a shared library will make the expression invalid. | |
9621 | This is not a very common use case, but we still re-evaluate | |
9622 | expression, to avoid surprises to the user. | |
9623 | ||
9624 | Note that for local watchpoints, we re-evaluate it only if | |
9625 | watchpoints frame id is still valid. If it's not, it means | |
9626 | the watchpoint is out of scope and will be deleted soon. In fact, | |
9627 | I'm not sure we'll ever be called in this case. | |
9628 | ||
9629 | If a local watchpoint's frame id is still valid, then | |
9630 | b->exp_valid_block is likewise valid, and we can safely use it. | |
9631 | ||
9632 | Don't do anything about disabled watchpoints, since they will | |
9633 | be reevaluated again when enabled. */ | |
a5606eee | 9634 | update_watchpoint (b, 1 /* reparse */); |
c906108c | 9635 | break; |
c5aa993b JM |
9636 | /* We needn't really do anything to reset these, since the mask |
9637 | that requests them is unaffected by e.g., new libraries being | |
9638 | loaded. */ | |
ce78b96d | 9639 | case bp_catchpoint: |
c906108c | 9640 | break; |
c5aa993b | 9641 | |
c906108c | 9642 | default: |
a3f17187 | 9643 | printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type); |
c906108c | 9644 | /* fall through */ |
0fd8e87f UW |
9645 | /* Delete overlay event and longjmp master breakpoints; they will be |
9646 | reset later by breakpoint_re_set. */ | |
1900040c | 9647 | case bp_overlay_event: |
0fd8e87f | 9648 | case bp_longjmp_master: |
aa7d318d | 9649 | case bp_std_terminate_master: |
c906108c SS |
9650 | delete_breakpoint (b); |
9651 | break; | |
9652 | ||
c5aa993b JM |
9653 | /* This breakpoint is special, it's set up when the inferior |
9654 | starts and we really don't want to touch it. */ | |
c906108c SS |
9655 | case bp_shlib_event: |
9656 | ||
c4093a6a JM |
9657 | /* Like bp_shlib_event, this breakpoint type is special. |
9658 | Once it is set up, we do not want to touch it. */ | |
9659 | case bp_thread_event: | |
9660 | ||
c5aa993b JM |
9661 | /* Keep temporary breakpoints, which can be encountered when we step |
9662 | over a dlopen call and SOLIB_ADD is resetting the breakpoints. | |
9663 | Otherwise these should have been blown away via the cleanup chain | |
9664 | or by breakpoint_init_inferior when we rerun the executable. */ | |
c906108c SS |
9665 | case bp_until: |
9666 | case bp_finish: | |
9667 | case bp_watchpoint_scope: | |
9668 | case bp_call_dummy: | |
aa7d318d | 9669 | case bp_std_terminate: |
c906108c | 9670 | case bp_step_resume: |
611c83ae PA |
9671 | case bp_longjmp: |
9672 | case bp_longjmp_resume: | |
4efc6507 | 9673 | case bp_jit_event: |
c906108c SS |
9674 | break; |
9675 | } | |
9676 | ||
6c95b8df | 9677 | do_cleanups (cleanups); |
c906108c SS |
9678 | return 0; |
9679 | } | |
9680 | ||
69de3c6a | 9681 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 9682 | void |
69de3c6a | 9683 | breakpoint_re_set (void) |
c906108c SS |
9684 | { |
9685 | struct breakpoint *b, *temp; | |
9686 | enum language save_language; | |
9687 | int save_input_radix; | |
6c95b8df | 9688 | struct cleanup *old_chain; |
c5aa993b | 9689 | |
c906108c SS |
9690 | save_language = current_language->la_language; |
9691 | save_input_radix = input_radix; | |
6c95b8df PA |
9692 | old_chain = save_current_program_space (); |
9693 | ||
c906108c | 9694 | ALL_BREAKPOINTS_SAFE (b, temp) |
c5aa993b | 9695 | { |
53a5351d | 9696 | /* Format possible error msg */ |
fe3f5fa8 | 9697 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
9698 | b->number); |
9699 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 9700 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 9701 | do_cleanups (cleanups); |
c5aa993b | 9702 | } |
c906108c SS |
9703 | set_language (save_language); |
9704 | input_radix = save_input_radix; | |
e62c965a | 9705 | |
0756c555 | 9706 | jit_breakpoint_re_set (); |
4efc6507 | 9707 | |
6c95b8df PA |
9708 | do_cleanups (old_chain); |
9709 | ||
69de3c6a | 9710 | create_overlay_event_breakpoint ("_ovly_debug_event"); |
0fd8e87f UW |
9711 | create_longjmp_master_breakpoint ("longjmp"); |
9712 | create_longjmp_master_breakpoint ("_longjmp"); | |
9713 | create_longjmp_master_breakpoint ("siglongjmp"); | |
9714 | create_longjmp_master_breakpoint ("_siglongjmp"); | |
aa7d318d | 9715 | create_std_terminate_master_breakpoint ("std::terminate()"); |
c906108c SS |
9716 | } |
9717 | \f | |
c906108c SS |
9718 | /* Reset the thread number of this breakpoint: |
9719 | ||
9720 | - If the breakpoint is for all threads, leave it as-is. | |
39f77062 | 9721 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 9722 | void |
fba45db2 | 9723 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
9724 | { |
9725 | if (b->thread != -1) | |
9726 | { | |
39f77062 KB |
9727 | if (in_thread_list (inferior_ptid)) |
9728 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
9729 | |
9730 | /* We're being called after following a fork. The new fork is | |
9731 | selected as current, and unless this was a vfork will have a | |
9732 | different program space from the original thread. Reset that | |
9733 | as well. */ | |
9734 | b->loc->pspace = current_program_space; | |
c906108c SS |
9735 | } |
9736 | } | |
9737 | ||
03ac34d5 MS |
9738 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
9739 | If from_tty is nonzero, it prints a message to that effect, | |
9740 | which ends with a period (no newline). */ | |
9741 | ||
c906108c | 9742 | void |
fba45db2 | 9743 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 9744 | { |
52f0bd74 | 9745 | struct breakpoint *b; |
c906108c SS |
9746 | |
9747 | if (count < 0) | |
9748 | count = 0; | |
9749 | ||
9750 | ALL_BREAKPOINTS (b) | |
9751 | if (b->number == bptnum) | |
c5aa993b JM |
9752 | { |
9753 | b->ignore_count = count; | |
221ea385 KS |
9754 | if (from_tty) |
9755 | { | |
9756 | if (count == 0) | |
a3f17187 | 9757 | printf_filtered (_("Will stop next time breakpoint %d is reached."), |
221ea385 KS |
9758 | bptnum); |
9759 | else if (count == 1) | |
a3f17187 | 9760 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
9761 | bptnum); |
9762 | else | |
a3f17187 | 9763 | printf_filtered (_("Will ignore next %d crossings of breakpoint %d."), |
221ea385 KS |
9764 | count, bptnum); |
9765 | } | |
c5aa993b | 9766 | breakpoints_changed (); |
383f836e | 9767 | observer_notify_breakpoint_modified (b->number); |
c5aa993b JM |
9768 | return; |
9769 | } | |
c906108c | 9770 | |
8a3fe4f8 | 9771 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
9772 | } |
9773 | ||
b2175913 MS |
9774 | void |
9775 | make_breakpoint_silent (struct breakpoint *b) | |
9776 | { | |
9777 | /* Silence the breakpoint. */ | |
9778 | b->silent = 1; | |
9779 | } | |
9780 | ||
c906108c SS |
9781 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
9782 | ||
9783 | static void | |
fba45db2 | 9784 | ignore_command (char *args, int from_tty) |
c906108c SS |
9785 | { |
9786 | char *p = args; | |
52f0bd74 | 9787 | int num; |
c906108c SS |
9788 | |
9789 | if (p == 0) | |
e2e0b3e5 | 9790 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 9791 | |
c906108c | 9792 | num = get_number (&p); |
5c44784c | 9793 | if (num == 0) |
8a3fe4f8 | 9794 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 9795 | if (*p == 0) |
8a3fe4f8 | 9796 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
9797 | |
9798 | set_ignore_count (num, | |
9799 | longest_to_int (value_as_long (parse_and_eval (p))), | |
9800 | from_tty); | |
221ea385 KS |
9801 | if (from_tty) |
9802 | printf_filtered ("\n"); | |
c906108c SS |
9803 | } |
9804 | \f | |
9805 | /* Call FUNCTION on each of the breakpoints | |
9806 | whose numbers are given in ARGS. */ | |
9807 | ||
9808 | static void | |
95a42b64 TT |
9809 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
9810 | void *), | |
9811 | void *data) | |
c906108c | 9812 | { |
52f0bd74 | 9813 | char *p = args; |
c906108c | 9814 | char *p1; |
52f0bd74 AC |
9815 | int num; |
9816 | struct breakpoint *b, *tmp; | |
11cf8741 | 9817 | int match; |
c906108c SS |
9818 | |
9819 | if (p == 0) | |
e2e0b3e5 | 9820 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c SS |
9821 | |
9822 | while (*p) | |
9823 | { | |
11cf8741 | 9824 | match = 0; |
c906108c | 9825 | p1 = p; |
c5aa993b | 9826 | |
5c44784c JM |
9827 | num = get_number_or_range (&p1); |
9828 | if (num == 0) | |
c5aa993b | 9829 | { |
8a3fe4f8 | 9830 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
9831 | } |
9832 | else | |
9833 | { | |
9834 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
9835 | if (b->number == num) | |
9836 | { | |
9837 | struct breakpoint *related_breakpoint = b->related_breakpoint; | |
11cf8741 | 9838 | match = 1; |
95a42b64 | 9839 | function (b, data); |
5c44784c | 9840 | if (related_breakpoint) |
95a42b64 | 9841 | function (related_breakpoint, data); |
11cf8741 | 9842 | break; |
5c44784c | 9843 | } |
11cf8741 | 9844 | if (match == 0) |
a3f17187 | 9845 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 9846 | } |
c906108c SS |
9847 | p = p1; |
9848 | } | |
9849 | } | |
9850 | ||
0d381245 VP |
9851 | static struct bp_location * |
9852 | find_location_by_number (char *number) | |
9853 | { | |
9854 | char *dot = strchr (number, '.'); | |
9855 | char *p1; | |
9856 | int bp_num; | |
9857 | int loc_num; | |
9858 | struct breakpoint *b; | |
9859 | struct bp_location *loc; | |
9860 | ||
9861 | *dot = '\0'; | |
9862 | ||
9863 | p1 = number; | |
9864 | bp_num = get_number_or_range (&p1); | |
9865 | if (bp_num == 0) | |
9866 | error (_("Bad breakpoint number '%s'"), number); | |
9867 | ||
9868 | ALL_BREAKPOINTS (b) | |
9869 | if (b->number == bp_num) | |
9870 | { | |
9871 | break; | |
9872 | } | |
9873 | ||
9874 | if (!b || b->number != bp_num) | |
9875 | error (_("Bad breakpoint number '%s'"), number); | |
9876 | ||
9877 | p1 = dot+1; | |
9878 | loc_num = get_number_or_range (&p1); | |
9879 | if (loc_num == 0) | |
9880 | error (_("Bad breakpoint location number '%s'"), number); | |
9881 | ||
9882 | --loc_num; | |
9883 | loc = b->loc; | |
9884 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
9885 | ; | |
9886 | if (!loc) | |
9887 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
9888 | ||
9889 | return loc; | |
9890 | } | |
9891 | ||
9892 | ||
1900040c MS |
9893 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
9894 | If from_tty is nonzero, it prints a message to that effect, | |
9895 | which ends with a period (no newline). */ | |
9896 | ||
c906108c | 9897 | void |
fba45db2 | 9898 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
9899 | { |
9900 | /* Never disable a watchpoint scope breakpoint; we want to | |
9901 | hit them when we leave scope so we can delete both the | |
9902 | watchpoint and its scope breakpoint at that time. */ | |
9903 | if (bpt->type == bp_watchpoint_scope) | |
9904 | return; | |
9905 | ||
c2c6d25f | 9906 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 9907 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
9908 | return; |
9909 | ||
b5de0fa7 | 9910 | bpt->enable_state = bp_disabled; |
c906108c | 9911 | |
b60e7edf | 9912 | update_global_location_list (0); |
c906108c | 9913 | |
383f836e | 9914 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
9915 | } |
9916 | ||
95a42b64 TT |
9917 | /* A callback for map_breakpoint_numbers that calls |
9918 | disable_breakpoint. */ | |
9919 | ||
9920 | static void | |
9921 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
9922 | { | |
9923 | disable_breakpoint (b); | |
9924 | } | |
9925 | ||
c906108c | 9926 | static void |
fba45db2 | 9927 | disable_command (char *args, int from_tty) |
c906108c | 9928 | { |
52f0bd74 | 9929 | struct breakpoint *bpt; |
c906108c SS |
9930 | if (args == 0) |
9931 | ALL_BREAKPOINTS (bpt) | |
9932 | switch (bpt->type) | |
c5aa993b JM |
9933 | { |
9934 | case bp_none: | |
8a3fe4f8 | 9935 | warning (_("attempted to disable apparently deleted breakpoint #%d?"), |
53a5351d | 9936 | bpt->number); |
c5aa993b JM |
9937 | continue; |
9938 | case bp_breakpoint: | |
1042e4c0 | 9939 | case bp_tracepoint: |
7a697b8d | 9940 | case bp_fast_tracepoint: |
ce78b96d | 9941 | case bp_catchpoint: |
c5aa993b JM |
9942 | case bp_hardware_breakpoint: |
9943 | case bp_watchpoint: | |
9944 | case bp_hardware_watchpoint: | |
9945 | case bp_read_watchpoint: | |
9946 | case bp_access_watchpoint: | |
9947 | disable_breakpoint (bpt); | |
9948 | default: | |
9949 | continue; | |
9950 | } | |
0d381245 VP |
9951 | else if (strchr (args, '.')) |
9952 | { | |
9953 | struct bp_location *loc = find_location_by_number (args); | |
9954 | if (loc) | |
9955 | loc->enabled = 0; | |
b60e7edf | 9956 | update_global_location_list (0); |
0d381245 | 9957 | } |
c906108c | 9958 | else |
95a42b64 | 9959 | map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL); |
c906108c SS |
9960 | } |
9961 | ||
9962 | static void | |
fba45db2 | 9963 | do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition) |
c906108c | 9964 | { |
c906108c SS |
9965 | int target_resources_ok, other_type_used; |
9966 | struct value *mark; | |
9967 | ||
9968 | if (bpt->type == bp_hardware_breakpoint) | |
9969 | { | |
9970 | int i; | |
c5aa993b | 9971 | i = hw_breakpoint_used_count (); |
53a5351d | 9972 | target_resources_ok = |
d92524f1 | 9973 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 9974 | i + 1, 0); |
c906108c | 9975 | if (target_resources_ok == 0) |
8a3fe4f8 | 9976 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 9977 | else if (target_resources_ok < 0) |
8a3fe4f8 | 9978 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
9979 | } |
9980 | ||
059fb39f PM |
9981 | if (bpt->type == bp_watchpoint |
9982 | || bpt->type == bp_hardware_watchpoint | |
9983 | || bpt->type == bp_read_watchpoint | |
9984 | || bpt->type == bp_access_watchpoint) | |
c906108c | 9985 | { |
dde02812 ES |
9986 | struct gdb_exception e; |
9987 | ||
9988 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 9989 | { |
dde02812 | 9990 | update_watchpoint (bpt, 1 /* reparse */); |
c906108c | 9991 | } |
dde02812 | 9992 | if (e.reason < 0) |
c5aa993b | 9993 | { |
dde02812 ES |
9994 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
9995 | bpt->number); | |
9996 | return; | |
c5aa993b | 9997 | } |
c906108c | 9998 | } |
0101ce28 | 9999 | |
b4c291bb KH |
10000 | if (bpt->enable_state != bp_permanent) |
10001 | bpt->enable_state = bp_enabled; | |
10002 | bpt->disposition = disposition; | |
b60e7edf | 10003 | update_global_location_list (1); |
b4c291bb KH |
10004 | breakpoints_changed (); |
10005 | ||
383f836e | 10006 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
10007 | } |
10008 | ||
fe3f5fa8 | 10009 | |
c906108c | 10010 | void |
fba45db2 | 10011 | enable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
10012 | { |
10013 | do_enable_breakpoint (bpt, bpt->disposition); | |
10014 | } | |
10015 | ||
95a42b64 TT |
10016 | /* A callback for map_breakpoint_numbers that calls |
10017 | enable_breakpoint. */ | |
10018 | ||
10019 | static void | |
10020 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
10021 | { | |
10022 | enable_breakpoint (b); | |
10023 | } | |
10024 | ||
c906108c SS |
10025 | /* The enable command enables the specified breakpoints (or all defined |
10026 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 10027 | in stopping the inferior. */ |
c906108c | 10028 | |
c906108c | 10029 | static void |
fba45db2 | 10030 | enable_command (char *args, int from_tty) |
c906108c | 10031 | { |
52f0bd74 | 10032 | struct breakpoint *bpt; |
c906108c SS |
10033 | if (args == 0) |
10034 | ALL_BREAKPOINTS (bpt) | |
10035 | switch (bpt->type) | |
c5aa993b JM |
10036 | { |
10037 | case bp_none: | |
8a3fe4f8 | 10038 | warning (_("attempted to enable apparently deleted breakpoint #%d?"), |
53a5351d | 10039 | bpt->number); |
c5aa993b JM |
10040 | continue; |
10041 | case bp_breakpoint: | |
1042e4c0 | 10042 | case bp_tracepoint: |
7a697b8d | 10043 | case bp_fast_tracepoint: |
ce78b96d | 10044 | case bp_catchpoint: |
c5aa993b JM |
10045 | case bp_hardware_breakpoint: |
10046 | case bp_watchpoint: | |
10047 | case bp_hardware_watchpoint: | |
10048 | case bp_read_watchpoint: | |
10049 | case bp_access_watchpoint: | |
10050 | enable_breakpoint (bpt); | |
10051 | default: | |
10052 | continue; | |
10053 | } | |
0d381245 VP |
10054 | else if (strchr (args, '.')) |
10055 | { | |
10056 | struct bp_location *loc = find_location_by_number (args); | |
10057 | if (loc) | |
10058 | loc->enabled = 1; | |
b60e7edf | 10059 | update_global_location_list (1); |
0d381245 | 10060 | } |
c906108c | 10061 | else |
95a42b64 | 10062 | map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL); |
c906108c SS |
10063 | } |
10064 | ||
10065 | static void | |
95a42b64 | 10066 | enable_once_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 10067 | { |
b5de0fa7 | 10068 | do_enable_breakpoint (bpt, disp_disable); |
c906108c SS |
10069 | } |
10070 | ||
c906108c | 10071 | static void |
fba45db2 | 10072 | enable_once_command (char *args, int from_tty) |
c906108c | 10073 | { |
95a42b64 | 10074 | map_breakpoint_numbers (args, enable_once_breakpoint, NULL); |
c906108c SS |
10075 | } |
10076 | ||
10077 | static void | |
95a42b64 | 10078 | enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 10079 | { |
b5de0fa7 | 10080 | do_enable_breakpoint (bpt, disp_del); |
c906108c SS |
10081 | } |
10082 | ||
c906108c | 10083 | static void |
fba45db2 | 10084 | enable_delete_command (char *args, int from_tty) |
c906108c | 10085 | { |
95a42b64 | 10086 | map_breakpoint_numbers (args, enable_delete_breakpoint, NULL); |
c906108c SS |
10087 | } |
10088 | \f | |
fa8d40ab JJ |
10089 | static void |
10090 | set_breakpoint_cmd (char *args, int from_tty) | |
10091 | { | |
10092 | } | |
10093 | ||
10094 | static void | |
10095 | show_breakpoint_cmd (char *args, int from_tty) | |
10096 | { | |
10097 | } | |
10098 | ||
1f3b5d1b PP |
10099 | /* Invalidate last known value of any hardware watchpoint if |
10100 | the memory which that value represents has been written to by | |
10101 | GDB itself. */ | |
10102 | ||
10103 | static void | |
10104 | invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len, | |
10105 | const bfd_byte *data) | |
10106 | { | |
10107 | struct breakpoint *bp; | |
10108 | ||
10109 | ALL_BREAKPOINTS (bp) | |
10110 | if (bp->enable_state == bp_enabled | |
10111 | && bp->type == bp_hardware_watchpoint | |
10112 | && bp->val_valid && bp->val) | |
10113 | { | |
10114 | struct bp_location *loc; | |
10115 | ||
10116 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
10117 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
10118 | && loc->address + loc->length > addr | |
10119 | && addr + len > loc->address) | |
10120 | { | |
10121 | value_free (bp->val); | |
10122 | bp->val = NULL; | |
10123 | bp->val_valid = 0; | |
10124 | } | |
10125 | } | |
10126 | } | |
10127 | ||
c906108c SS |
10128 | /* Use default_breakpoint_'s, or nothing if they aren't valid. */ |
10129 | ||
10130 | struct symtabs_and_lines | |
fba45db2 | 10131 | decode_line_spec_1 (char *string, int funfirstline) |
c906108c SS |
10132 | { |
10133 | struct symtabs_and_lines sals; | |
10134 | if (string == 0) | |
8a3fe4f8 | 10135 | error (_("Empty line specification.")); |
c906108c SS |
10136 | if (default_breakpoint_valid) |
10137 | sals = decode_line_1 (&string, funfirstline, | |
53a5351d JM |
10138 | default_breakpoint_symtab, |
10139 | default_breakpoint_line, | |
68219205 | 10140 | (char ***) NULL, NULL); |
c906108c SS |
10141 | else |
10142 | sals = decode_line_1 (&string, funfirstline, | |
68219205 | 10143 | (struct symtab *) NULL, 0, (char ***) NULL, NULL); |
c906108c | 10144 | if (*string) |
8a3fe4f8 | 10145 | error (_("Junk at end of line specification: %s"), string); |
c906108c SS |
10146 | return sals; |
10147 | } | |
8181d85f DJ |
10148 | |
10149 | /* Create and insert a raw software breakpoint at PC. Return an | |
10150 | identifier, which should be used to remove the breakpoint later. | |
10151 | In general, places which call this should be using something on the | |
10152 | breakpoint chain instead; this function should be eliminated | |
10153 | someday. */ | |
10154 | ||
10155 | void * | |
6c95b8df PA |
10156 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, |
10157 | struct address_space *aspace, CORE_ADDR pc) | |
8181d85f DJ |
10158 | { |
10159 | struct bp_target_info *bp_tgt; | |
10160 | ||
6c95b8df | 10161 | bp_tgt = XZALLOC (struct bp_target_info); |
8181d85f | 10162 | |
6c95b8df | 10163 | bp_tgt->placed_address_space = aspace; |
8181d85f | 10164 | bp_tgt->placed_address = pc; |
6c95b8df | 10165 | |
a6d9a66e | 10166 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
8181d85f DJ |
10167 | { |
10168 | /* Could not insert the breakpoint. */ | |
10169 | xfree (bp_tgt); | |
10170 | return NULL; | |
10171 | } | |
10172 | ||
10173 | return bp_tgt; | |
10174 | } | |
10175 | ||
10176 | /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */ | |
10177 | ||
10178 | int | |
a6d9a66e | 10179 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
8181d85f DJ |
10180 | { |
10181 | struct bp_target_info *bp_tgt = bp; | |
10182 | int ret; | |
10183 | ||
a6d9a66e | 10184 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
8181d85f DJ |
10185 | xfree (bp_tgt); |
10186 | ||
10187 | return ret; | |
10188 | } | |
10189 | ||
10190 | /* One (or perhaps two) breakpoints used for software single stepping. */ | |
10191 | ||
10192 | static void *single_step_breakpoints[2]; | |
a6d9a66e | 10193 | static struct gdbarch *single_step_gdbarch[2]; |
8181d85f DJ |
10194 | |
10195 | /* Create and insert a breakpoint for software single step. */ | |
10196 | ||
10197 | void | |
6c95b8df PA |
10198 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
10199 | struct address_space *aspace, CORE_ADDR next_pc) | |
8181d85f DJ |
10200 | { |
10201 | void **bpt_p; | |
10202 | ||
10203 | if (single_step_breakpoints[0] == NULL) | |
a6d9a66e UW |
10204 | { |
10205 | bpt_p = &single_step_breakpoints[0]; | |
10206 | single_step_gdbarch[0] = gdbarch; | |
10207 | } | |
8181d85f DJ |
10208 | else |
10209 | { | |
10210 | gdb_assert (single_step_breakpoints[1] == NULL); | |
10211 | bpt_p = &single_step_breakpoints[1]; | |
a6d9a66e | 10212 | single_step_gdbarch[1] = gdbarch; |
8181d85f DJ |
10213 | } |
10214 | ||
10215 | /* NOTE drow/2006-04-11: A future improvement to this function would be | |
10216 | to only create the breakpoints once, and actually put them on the | |
10217 | breakpoint chain. That would let us use set_raw_breakpoint. We could | |
10218 | adjust the addresses each time they were needed. Doing this requires | |
10219 | corresponding changes elsewhere where single step breakpoints are | |
10220 | handled, however. So, for now, we use this. */ | |
10221 | ||
6c95b8df | 10222 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc); |
8181d85f | 10223 | if (*bpt_p == NULL) |
5af949e3 UW |
10224 | error (_("Could not insert single-step breakpoint at %s"), |
10225 | paddress (gdbarch, next_pc)); | |
8181d85f DJ |
10226 | } |
10227 | ||
10228 | /* Remove and delete any breakpoints used for software single step. */ | |
10229 | ||
10230 | void | |
10231 | remove_single_step_breakpoints (void) | |
10232 | { | |
10233 | gdb_assert (single_step_breakpoints[0] != NULL); | |
10234 | ||
10235 | /* See insert_single_step_breakpoint for more about this deprecated | |
10236 | call. */ | |
a6d9a66e UW |
10237 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
10238 | single_step_breakpoints[0]); | |
10239 | single_step_gdbarch[0] = NULL; | |
8181d85f DJ |
10240 | single_step_breakpoints[0] = NULL; |
10241 | ||
10242 | if (single_step_breakpoints[1] != NULL) | |
10243 | { | |
a6d9a66e UW |
10244 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
10245 | single_step_breakpoints[1]); | |
10246 | single_step_gdbarch[1] = NULL; | |
8181d85f DJ |
10247 | single_step_breakpoints[1] = NULL; |
10248 | } | |
10249 | } | |
10250 | ||
1aafd4da UW |
10251 | /* Check whether a software single-step breakpoint is inserted at PC. */ |
10252 | ||
10253 | static int | |
6c95b8df | 10254 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
1aafd4da UW |
10255 | { |
10256 | int i; | |
10257 | ||
10258 | for (i = 0; i < 2; i++) | |
10259 | { | |
10260 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
6c95b8df PA |
10261 | if (bp_tgt |
10262 | && breakpoint_address_match (bp_tgt->placed_address_space, | |
10263 | bp_tgt->placed_address, | |
10264 | aspace, pc)) | |
1aafd4da UW |
10265 | return 1; |
10266 | } | |
10267 | ||
10268 | return 0; | |
10269 | } | |
10270 | ||
a96d9b2e SDJ |
10271 | /* Returns 0 if 'bp' is NOT a syscall catchpoint, |
10272 | non-zero otherwise. */ | |
10273 | static int | |
10274 | is_syscall_catchpoint_enabled (struct breakpoint *bp) | |
10275 | { | |
10276 | if (syscall_catchpoint_p (bp) | |
10277 | && bp->enable_state != bp_disabled | |
10278 | && bp->enable_state != bp_call_disabled) | |
10279 | return 1; | |
10280 | else | |
10281 | return 0; | |
10282 | } | |
10283 | ||
10284 | int | |
10285 | catch_syscall_enabled (void) | |
10286 | { | |
10287 | struct inferior *inf = current_inferior (); | |
10288 | ||
10289 | return inf->total_syscalls_count != 0; | |
10290 | } | |
10291 | ||
10292 | int | |
10293 | catching_syscall_number (int syscall_number) | |
10294 | { | |
10295 | struct breakpoint *bp; | |
10296 | ||
10297 | ALL_BREAKPOINTS (bp) | |
10298 | if (is_syscall_catchpoint_enabled (bp)) | |
10299 | { | |
10300 | if (bp->syscalls_to_be_caught) | |
10301 | { | |
10302 | int i, iter; | |
10303 | for (i = 0; | |
10304 | VEC_iterate (int, bp->syscalls_to_be_caught, i, iter); | |
10305 | i++) | |
10306 | if (syscall_number == iter) | |
10307 | return 1; | |
10308 | } | |
10309 | else | |
10310 | return 1; | |
10311 | } | |
10312 | ||
10313 | return 0; | |
10314 | } | |
10315 | ||
10316 | /* Complete syscall names. Used by "catch syscall". */ | |
10317 | static char ** | |
10318 | catch_syscall_completer (struct cmd_list_element *cmd, | |
10319 | char *text, char *word) | |
10320 | { | |
10321 | const char **list = get_syscall_names (); | |
10322 | return (list == NULL) ? NULL : complete_on_enum (list, text, word); | |
10323 | } | |
10324 | ||
1042e4c0 SS |
10325 | /* Tracepoint-specific operations. */ |
10326 | ||
10327 | /* Set tracepoint count to NUM. */ | |
10328 | static void | |
10329 | set_tracepoint_count (int num) | |
10330 | { | |
10331 | tracepoint_count = num; | |
4fa62494 | 10332 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
10333 | } |
10334 | ||
10335 | void | |
10336 | trace_command (char *arg, int from_tty) | |
10337 | { | |
8cdf0e15 VP |
10338 | if (create_breakpoint (get_current_arch (), |
10339 | arg, | |
10340 | NULL, 0, 1 /* parse arg */, | |
10341 | 0 /* tempflag */, 0 /* hardwareflag */, | |
10342 | 1 /* traceflag */, | |
10343 | 0 /* Ignore count */, | |
10344 | pending_break_support, | |
10345 | NULL, | |
10346 | from_tty, | |
10347 | 1 /* enabled */)) | |
fd9b8c24 | 10348 | set_tracepoint_count (breakpoint_count); |
1042e4c0 SS |
10349 | } |
10350 | ||
7a697b8d SS |
10351 | void |
10352 | ftrace_command (char *arg, int from_tty) | |
10353 | { | |
8cdf0e15 VP |
10354 | if (create_breakpoint (get_current_arch (), |
10355 | arg, | |
10356 | NULL, 0, 1 /* parse arg */, | |
10357 | 0 /* tempflag */, 1 /* hardwareflag */, | |
10358 | 1 /* traceflag */, | |
10359 | 0 /* Ignore count */, | |
10360 | pending_break_support, | |
10361 | NULL, | |
10362 | from_tty, | |
10363 | 1 /* enabled */)) | |
fd9b8c24 | 10364 | set_tracepoint_count (breakpoint_count); |
7a697b8d SS |
10365 | } |
10366 | ||
00bf0b85 SS |
10367 | /* Given information about a tracepoint as recorded on a target (which |
10368 | can be either a live system or a trace file), attempt to create an | |
10369 | equivalent GDB tracepoint. This is not a reliable process, since | |
10370 | the target does not necessarily have all the information used when | |
10371 | the tracepoint was originally defined. */ | |
10372 | ||
10373 | struct breakpoint * | |
10374 | create_tracepoint_from_upload (struct uploaded_tp *utp) | |
d5551862 SS |
10375 | { |
10376 | char buf[100]; | |
10377 | struct breakpoint *tp; | |
fd9b8c24 | 10378 | |
00bf0b85 SS |
10379 | /* In the absence of a source location, fall back to raw address. */ |
10380 | sprintf (buf, "*%s", paddress (get_current_arch(), utp->addr)); | |
d5551862 | 10381 | |
8cdf0e15 VP |
10382 | if (!create_breakpoint (get_current_arch (), |
10383 | buf, | |
10384 | NULL, 0, 1 /* parse arg */, | |
10385 | 0 /* tempflag */, | |
10386 | (utp->type == bp_fast_tracepoint) /* hardwareflag */, | |
10387 | 1 /* traceflag */, | |
10388 | 0 /* Ignore count */, | |
10389 | pending_break_support, | |
10390 | NULL, | |
10391 | 0 /* from_tty */, | |
10392 | utp->enabled /* enabled */)) | |
fd9b8c24 PA |
10393 | return NULL; |
10394 | ||
00bf0b85 SS |
10395 | set_tracepoint_count (breakpoint_count); |
10396 | ||
fd9b8c24 PA |
10397 | tp = get_tracepoint (tracepoint_count); |
10398 | gdb_assert (tp != NULL); | |
d5551862 | 10399 | |
00bf0b85 SS |
10400 | if (utp->pass > 0) |
10401 | { | |
10402 | sprintf (buf, "%d %d", utp->pass, tp->number); | |
10403 | ||
10404 | trace_pass_command (buf, 0); | |
10405 | } | |
10406 | ||
10407 | if (utp->cond) | |
10408 | { | |
10409 | printf_filtered ("Want to restore a condition\n"); | |
10410 | } | |
10411 | ||
10412 | if (utp->numactions > 0) | |
10413 | { | |
10414 | printf_filtered ("Want to restore action list\n"); | |
10415 | } | |
d5551862 | 10416 | |
00bf0b85 SS |
10417 | if (utp->num_step_actions > 0) |
10418 | { | |
10419 | printf_filtered ("Want to restore action list\n"); | |
10420 | } | |
10421 | ||
10422 | return tp; | |
10423 | } | |
10424 | ||
1042e4c0 SS |
10425 | /* Print information on tracepoint number TPNUM_EXP, or all if |
10426 | omitted. */ | |
10427 | ||
10428 | static void | |
10429 | tracepoints_info (char *tpnum_exp, int from_tty) | |
10430 | { | |
10431 | struct breakpoint *b; | |
10432 | int tps_to_list = 0; | |
10433 | ||
10434 | /* In the no-arguments case, say "No tracepoints" if none found. */ | |
10435 | if (tpnum_exp == 0) | |
10436 | { | |
10437 | ALL_TRACEPOINTS (b) | |
10438 | { | |
10439 | if (b->number >= 0) | |
10440 | { | |
10441 | tps_to_list = 1; | |
10442 | break; | |
10443 | } | |
10444 | } | |
10445 | if (!tps_to_list) | |
10446 | { | |
10447 | ui_out_message (uiout, 0, "No tracepoints.\n"); | |
10448 | return; | |
10449 | } | |
10450 | } | |
10451 | ||
10452 | /* Otherwise be the same as "info break". */ | |
10453 | breakpoints_info (tpnum_exp, from_tty); | |
10454 | } | |
10455 | ||
10456 | /* The 'enable trace' command enables tracepoints. | |
10457 | Not supported by all targets. */ | |
10458 | static void | |
10459 | enable_trace_command (char *args, int from_tty) | |
10460 | { | |
10461 | enable_command (args, from_tty); | |
10462 | } | |
10463 | ||
10464 | /* The 'disable trace' command disables tracepoints. | |
10465 | Not supported by all targets. */ | |
10466 | static void | |
10467 | disable_trace_command (char *args, int from_tty) | |
10468 | { | |
10469 | disable_command (args, from_tty); | |
10470 | } | |
10471 | ||
10472 | /* Remove a tracepoint (or all if no argument) */ | |
10473 | static void | |
10474 | delete_trace_command (char *arg, int from_tty) | |
10475 | { | |
10476 | struct breakpoint *b, *temp; | |
10477 | ||
10478 | dont_repeat (); | |
10479 | ||
10480 | if (arg == 0) | |
10481 | { | |
10482 | int breaks_to_delete = 0; | |
10483 | ||
10484 | /* Delete all breakpoints if no argument. | |
10485 | Do not delete internal or call-dummy breakpoints, these | |
10486 | have to be deleted with an explicit breakpoint number argument. */ | |
10487 | ALL_TRACEPOINTS (b) | |
10488 | { | |
10489 | if (b->number >= 0) | |
10490 | { | |
10491 | breaks_to_delete = 1; | |
10492 | break; | |
10493 | } | |
10494 | } | |
10495 | ||
10496 | /* Ask user only if there are some breakpoints to delete. */ | |
10497 | if (!from_tty | |
10498 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
10499 | { | |
10500 | ALL_BREAKPOINTS_SAFE (b, temp) | |
10501 | { | |
7a697b8d | 10502 | if (tracepoint_type (b) |
059fb39f | 10503 | && b->number >= 0) |
1042e4c0 SS |
10504 | delete_breakpoint (b); |
10505 | } | |
10506 | } | |
10507 | } | |
10508 | else | |
95a42b64 | 10509 | map_breakpoint_numbers (arg, do_delete_breakpoint, NULL); |
1042e4c0 SS |
10510 | } |
10511 | ||
10512 | /* Set passcount for tracepoint. | |
10513 | ||
10514 | First command argument is passcount, second is tracepoint number. | |
10515 | If tracepoint number omitted, apply to most recently defined. | |
10516 | Also accepts special argument "all". */ | |
10517 | ||
10518 | static void | |
10519 | trace_pass_command (char *args, int from_tty) | |
10520 | { | |
10521 | struct breakpoint *t1 = (struct breakpoint *) -1, *t2; | |
10522 | unsigned int count; | |
10523 | int all = 0; | |
10524 | ||
10525 | if (args == 0 || *args == 0) | |
10526 | error (_("passcount command requires an argument (count + optional TP num)")); | |
10527 | ||
10528 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ | |
10529 | ||
10530 | while (*args && isspace ((int) *args)) | |
10531 | args++; | |
10532 | ||
10533 | if (*args && strncasecmp (args, "all", 3) == 0) | |
10534 | { | |
10535 | args += 3; /* Skip special argument "all". */ | |
10536 | all = 1; | |
10537 | if (*args) | |
10538 | error (_("Junk at end of arguments.")); | |
10539 | } | |
10540 | else | |
10541 | t1 = get_tracepoint_by_number (&args, 1, 1); | |
10542 | ||
10543 | do | |
10544 | { | |
10545 | if (t1) | |
10546 | { | |
10547 | ALL_TRACEPOINTS (t2) | |
10548 | if (t1 == (struct breakpoint *) -1 || t1 == t2) | |
10549 | { | |
10550 | t2->pass_count = count; | |
10551 | observer_notify_tracepoint_modified (t2->number); | |
10552 | if (from_tty) | |
10553 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
10554 | t2->number, count); | |
10555 | } | |
10556 | if (! all && *args) | |
10557 | t1 = get_tracepoint_by_number (&args, 1, 0); | |
10558 | } | |
10559 | } | |
10560 | while (*args); | |
10561 | } | |
10562 | ||
10563 | struct breakpoint * | |
10564 | get_tracepoint (int num) | |
10565 | { | |
10566 | struct breakpoint *t; | |
10567 | ||
10568 | ALL_TRACEPOINTS (t) | |
10569 | if (t->number == num) | |
10570 | return t; | |
10571 | ||
10572 | return NULL; | |
10573 | } | |
10574 | ||
d5551862 SS |
10575 | /* Find the tracepoint with the given target-side number (which may be |
10576 | different from the tracepoint number after disconnecting and | |
10577 | reconnecting). */ | |
10578 | ||
10579 | struct breakpoint * | |
10580 | get_tracepoint_by_number_on_target (int num) | |
10581 | { | |
10582 | struct breakpoint *t; | |
10583 | ||
10584 | ALL_TRACEPOINTS (t) | |
10585 | if (t->number_on_target == num) | |
10586 | return t; | |
10587 | ||
10588 | return NULL; | |
10589 | } | |
10590 | ||
1042e4c0 SS |
10591 | /* Utility: parse a tracepoint number and look it up in the list. |
10592 | If MULTI_P is true, there might be a range of tracepoints in ARG. | |
10593 | if OPTIONAL_P is true, then if the argument is missing, the most | |
10594 | recent tracepoint (tracepoint_count) is returned. */ | |
10595 | struct breakpoint * | |
10596 | get_tracepoint_by_number (char **arg, int multi_p, int optional_p) | |
10597 | { | |
10598 | extern int tracepoint_count; | |
10599 | struct breakpoint *t; | |
10600 | int tpnum; | |
10601 | char *instring = arg == NULL ? NULL : *arg; | |
10602 | ||
10603 | if (arg == NULL || *arg == NULL || ! **arg) | |
10604 | { | |
10605 | if (optional_p) | |
10606 | tpnum = tracepoint_count; | |
10607 | else | |
10608 | error_no_arg (_("tracepoint number")); | |
10609 | } | |
10610 | else | |
10611 | tpnum = multi_p ? get_number_or_range (arg) : get_number (arg); | |
10612 | ||
10613 | if (tpnum <= 0) | |
10614 | { | |
10615 | if (instring && *instring) | |
10616 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
10617 | instring); | |
10618 | else | |
10619 | printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n")); | |
10620 | return NULL; | |
10621 | } | |
10622 | ||
10623 | ALL_TRACEPOINTS (t) | |
10624 | if (t->number == tpnum) | |
10625 | { | |
10626 | return t; | |
10627 | } | |
10628 | ||
10629 | /* FIXME: if we are in the middle of a range we don't want to give | |
10630 | a message. The current interface to get_number_or_range doesn't | |
10631 | allow us to discover this. */ | |
10632 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); | |
10633 | return NULL; | |
10634 | } | |
10635 | ||
10636 | /* save-tracepoints command */ | |
10637 | static void | |
10638 | tracepoint_save_command (char *args, int from_tty) | |
10639 | { | |
10640 | struct breakpoint *tp; | |
10641 | int any_tp = 0; | |
a7bdde9e VP |
10642 | struct command_line *line; |
10643 | char *pathname; | |
1042e4c0 SS |
10644 | char tmp[40]; |
10645 | struct cleanup *cleanup; | |
a7bdde9e | 10646 | struct ui_file *fp; |
1042e4c0 SS |
10647 | |
10648 | if (args == 0 || *args == 0) | |
10649 | error (_("Argument required (file name in which to save tracepoints)")); | |
10650 | ||
10651 | /* See if we have anything to save. */ | |
10652 | ALL_TRACEPOINTS (tp) | |
10653 | { | |
10654 | any_tp = 1; | |
10655 | break; | |
10656 | } | |
10657 | if (!any_tp) | |
10658 | { | |
10659 | warning (_("save-tracepoints: no tracepoints to save.")); | |
10660 | return; | |
10661 | } | |
10662 | ||
10663 | pathname = tilde_expand (args); | |
10664 | cleanup = make_cleanup (xfree, pathname); | |
a7bdde9e | 10665 | fp = gdb_fopen (pathname, "w"); |
059fb39f | 10666 | if (!fp) |
1042e4c0 SS |
10667 | error (_("Unable to open file '%s' for saving tracepoints (%s)"), |
10668 | args, safe_strerror (errno)); | |
a7bdde9e | 10669 | make_cleanup_ui_file_delete (fp); |
1042e4c0 SS |
10670 | |
10671 | ALL_TRACEPOINTS (tp) | |
10672 | { | |
10673 | if (tp->addr_string) | |
a7bdde9e | 10674 | fprintf_unfiltered (fp, "trace %s\n", tp->addr_string); |
1042e4c0 SS |
10675 | else |
10676 | { | |
10677 | sprintf_vma (tmp, tp->loc->address); | |
a7bdde9e | 10678 | fprintf_unfiltered (fp, "trace *0x%s\n", tmp); |
1042e4c0 SS |
10679 | } |
10680 | ||
10681 | if (tp->pass_count) | |
a7bdde9e | 10682 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); |
1042e4c0 | 10683 | |
a7bdde9e | 10684 | if (tp->commands) |
1042e4c0 | 10685 | { |
a7bdde9e VP |
10686 | volatile struct gdb_exception ex; |
10687 | ||
10688 | fprintf_unfiltered (fp, " actions\n"); | |
10689 | ||
10690 | ui_out_redirect (uiout, fp); | |
10691 | TRY_CATCH (ex, RETURN_MASK_ERROR) | |
1042e4c0 | 10692 | { |
9add0f1b | 10693 | print_command_lines (uiout, tp->commands->commands, 2); |
a7bdde9e VP |
10694 | } |
10695 | ui_out_redirect (uiout, NULL); | |
1042e4c0 | 10696 | |
a7bdde9e VP |
10697 | if (ex.reason < 0) |
10698 | throw_exception (ex); | |
1042e4c0 | 10699 | |
a7bdde9e | 10700 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 SS |
10701 | } |
10702 | } | |
10703 | do_cleanups (cleanup); | |
10704 | if (from_tty) | |
10705 | printf_filtered (_("Tracepoints saved to file '%s'.\n"), args); | |
10706 | return; | |
10707 | } | |
10708 | ||
10709 | /* Create a vector of all tracepoints. */ | |
10710 | ||
10711 | VEC(breakpoint_p) * | |
10712 | all_tracepoints () | |
10713 | { | |
10714 | VEC(breakpoint_p) *tp_vec = 0; | |
10715 | struct breakpoint *tp; | |
10716 | ||
10717 | ALL_TRACEPOINTS (tp) | |
10718 | { | |
10719 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
10720 | } | |
10721 | ||
10722 | return tp_vec; | |
10723 | } | |
10724 | ||
c906108c | 10725 | \f |
31e2b00f AS |
10726 | /* This help string is used for the break, hbreak, tbreak and thbreak commands. |
10727 | It is defined as a macro to prevent duplication. | |
10728 | COMMAND should be a string constant containing the name of the command. */ | |
10729 | #define BREAK_ARGS_HELP(command) \ | |
10730 | command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\ | |
10731 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ | |
10732 | If a line number is specified, break at start of code for that line.\n\ | |
10733 | If a function is specified, break at start of code for that function.\n\ | |
10734 | If an address is specified, break at that exact address.\n\ | |
10735 | With no LOCATION, uses current execution address of selected stack frame.\n\ | |
10736 | This is useful for breaking on return to a stack frame.\n\ | |
10737 | \n\ | |
10738 | THREADNUM is the number from \"info threads\".\n\ | |
10739 | CONDITION is a boolean expression.\n\ | |
10740 | \n\ | |
10741 | Multiple breakpoints at one place are permitted, and useful if conditional.\n\ | |
10742 | \n\ | |
10743 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
10744 | ||
44feb3ce TT |
10745 | /* List of subcommands for "catch". */ |
10746 | static struct cmd_list_element *catch_cmdlist; | |
10747 | ||
10748 | /* List of subcommands for "tcatch". */ | |
10749 | static struct cmd_list_element *tcatch_cmdlist; | |
10750 | ||
10751 | /* Like add_cmd, but add the command to both the "catch" and "tcatch" | |
10752 | lists, and pass some additional user data to the command function. */ | |
10753 | static void | |
10754 | add_catch_command (char *name, char *docstring, | |
10755 | void (*sfunc) (char *args, int from_tty, | |
10756 | struct cmd_list_element *command), | |
a96d9b2e SDJ |
10757 | char **(*completer) (struct cmd_list_element *cmd, |
10758 | char *text, char *word), | |
44feb3ce TT |
10759 | void *user_data_catch, |
10760 | void *user_data_tcatch) | |
10761 | { | |
10762 | struct cmd_list_element *command; | |
10763 | ||
10764 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
10765 | &catch_cmdlist); | |
10766 | set_cmd_sfunc (command, sfunc); | |
10767 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 10768 | set_cmd_completer (command, completer); |
44feb3ce TT |
10769 | |
10770 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
10771 | &tcatch_cmdlist); | |
10772 | set_cmd_sfunc (command, sfunc); | |
10773 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 10774 | set_cmd_completer (command, completer); |
44feb3ce TT |
10775 | } |
10776 | ||
6c95b8df | 10777 | static void |
a79b8f6e | 10778 | clear_syscall_counts (struct inferior *inf) |
6c95b8df | 10779 | { |
6c95b8df PA |
10780 | inf->total_syscalls_count = 0; |
10781 | inf->any_syscall_count = 0; | |
10782 | VEC_free (int, inf->syscalls_counts); | |
10783 | } | |
10784 | ||
c906108c | 10785 | void |
fba45db2 | 10786 | _initialize_breakpoint (void) |
c906108c | 10787 | { |
fa8d40ab JJ |
10788 | static struct cmd_list_element *breakpoint_set_cmdlist; |
10789 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
c906108c SS |
10790 | struct cmd_list_element *c; |
10791 | ||
84acb35a | 10792 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
6c95b8df | 10793 | observer_attach_inferior_exit (clear_syscall_counts); |
1f3b5d1b | 10794 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 10795 | |
c906108c SS |
10796 | breakpoint_chain = 0; |
10797 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
10798 | before a breakpoint is set. */ | |
10799 | breakpoint_count = 0; | |
10800 | ||
1042e4c0 SS |
10801 | tracepoint_count = 0; |
10802 | ||
1bedd215 AC |
10803 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
10804 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
10805 | Usage is `ignore N COUNT'.")); | |
c906108c | 10806 | if (xdb_commands) |
c5aa993b | 10807 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 10808 | |
1bedd215 AC |
10809 | add_com ("commands", class_breakpoint, commands_command, _("\ |
10810 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
10811 | Give breakpoint number as argument after \"commands\".\n\ |
10812 | With no argument, the targeted breakpoint is the last one set.\n\ | |
10813 | The commands themselves follow starting on the next line.\n\ | |
10814 | Type a line containing \"end\" to indicate the end of them.\n\ | |
10815 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 10816 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 10817 | |
1bedd215 AC |
10818 | add_com ("condition", class_breakpoint, condition_command, _("\ |
10819 | Specify breakpoint number N to break only if COND is true.\n\ | |
c906108c | 10820 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 10821 | expression to be evaluated whenever breakpoint N is reached.")); |
c906108c | 10822 | |
1bedd215 | 10823 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 10824 | Set a temporary breakpoint.\n\ |
c906108c SS |
10825 | Like \"break\" except the breakpoint is only temporary,\n\ |
10826 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
10827 | by using \"enable delete\" on the breakpoint number.\n\ |
10828 | \n" | |
10829 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 10830 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 10831 | |
1bedd215 | 10832 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
31e2b00f | 10833 | Set a hardware assisted breakpoint.\n\ |
c906108c | 10834 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
10835 | some target hardware may not have this support.\n\ |
10836 | \n" | |
10837 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 10838 | set_cmd_completer (c, location_completer); |
c906108c | 10839 | |
1bedd215 | 10840 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 10841 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 10842 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
10843 | so it will be deleted when hit.\n\ |
10844 | \n" | |
10845 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 10846 | set_cmd_completer (c, location_completer); |
c906108c | 10847 | |
1bedd215 AC |
10848 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
10849 | Enable some breakpoints.\n\ | |
c906108c SS |
10850 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
10851 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
10852 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 10853 | With a subcommand you can enable temporarily."), |
c906108c SS |
10854 | &enablelist, "enable ", 1, &cmdlist); |
10855 | if (xdb_commands) | |
1bedd215 AC |
10856 | add_com ("ab", class_breakpoint, enable_command, _("\ |
10857 | Enable some breakpoints.\n\ | |
c906108c SS |
10858 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
10859 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
10860 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 10861 | With a subcommand you can enable temporarily.")); |
c906108c SS |
10862 | |
10863 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
10864 | ||
1bedd215 AC |
10865 | add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
10866 | Enable some breakpoints.\n\ | |
c906108c SS |
10867 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
10868 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 10869 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 10870 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 10871 | |
1a966eab AC |
10872 | add_cmd ("once", no_class, enable_once_command, _("\ |
10873 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
10874 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
10875 | &enablebreaklist); |
10876 | ||
1a966eab AC |
10877 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
10878 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
10879 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
10880 | &enablebreaklist); |
10881 | ||
1a966eab AC |
10882 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
10883 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
10884 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
10885 | &enablelist); |
10886 | ||
1a966eab AC |
10887 | add_cmd ("once", no_class, enable_once_command, _("\ |
10888 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
10889 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
10890 | &enablelist); |
10891 | ||
1bedd215 AC |
10892 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
10893 | Disable some breakpoints.\n\ | |
c906108c SS |
10894 | Arguments are breakpoint numbers with spaces in between.\n\ |
10895 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 10896 | A disabled breakpoint is not forgotten, but has no effect until reenabled."), |
c906108c SS |
10897 | &disablelist, "disable ", 1, &cmdlist); |
10898 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
10899 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
10900 | if (xdb_commands) | |
1bedd215 AC |
10901 | add_com ("sb", class_breakpoint, disable_command, _("\ |
10902 | Disable some breakpoints.\n\ | |
c906108c SS |
10903 | Arguments are breakpoint numbers with spaces in between.\n\ |
10904 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 10905 | A disabled breakpoint is not forgotten, but has no effect until reenabled.")); |
c906108c | 10906 | |
1a966eab AC |
10907 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
10908 | Disable some breakpoints.\n\ | |
c906108c SS |
10909 | Arguments are breakpoint numbers with spaces in between.\n\ |
10910 | To disable all breakpoints, give no argument.\n\ | |
10911 | A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\ | |
1a966eab | 10912 | This command may be abbreviated \"disable\"."), |
c906108c SS |
10913 | &disablelist); |
10914 | ||
1bedd215 AC |
10915 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
10916 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
10917 | Arguments are breakpoint numbers with spaces in between.\n\ |
10918 | To delete all breakpoints, give no argument.\n\ | |
10919 | \n\ | |
10920 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 10921 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
10922 | &deletelist, "delete ", 1, &cmdlist); |
10923 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 10924 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 10925 | if (xdb_commands) |
1bedd215 AC |
10926 | add_com ("db", class_breakpoint, delete_command, _("\ |
10927 | Delete some breakpoints.\n\ | |
c906108c | 10928 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 10929 | To delete all breakpoints, give no argument.\n")); |
c906108c | 10930 | |
1a966eab AC |
10931 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
10932 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
10933 | Arguments are breakpoint numbers with spaces in between.\n\ |
10934 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 10935 | This command may be abbreviated \"delete\"."), |
c906108c SS |
10936 | &deletelist); |
10937 | ||
1bedd215 AC |
10938 | add_com ("clear", class_breakpoint, clear_command, _("\ |
10939 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
10940 | Argument may be line number, function name, or \"*\" and an address.\n\ |
10941 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
10942 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
10943 | If an address is specified, breakpoints at that address are cleared.\n\ |
10944 | \n\ | |
10945 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
10946 | is executing in.\n\ |
10947 | \n\ | |
1bedd215 | 10948 | See also the \"delete\" command which clears breakpoints by number.")); |
c906108c | 10949 | |
1bedd215 | 10950 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
10951 | Set breakpoint at specified line or function.\n" |
10952 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 10953 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 10954 | |
c906108c SS |
10955 | add_com_alias ("b", "break", class_run, 1); |
10956 | add_com_alias ("br", "break", class_run, 1); | |
10957 | add_com_alias ("bre", "break", class_run, 1); | |
10958 | add_com_alias ("brea", "break", class_run, 1); | |
10959 | ||
7681d515 PM |
10960 | if (xdb_commands) |
10961 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
10962 | |
10963 | if (dbx_commands) | |
10964 | { | |
1bedd215 AC |
10965 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
10966 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
10967 | &stoplist, "stop ", 1, &cmdlist); |
10968 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 10969 | _("Break in function or address."), &stoplist); |
c5aa993b | 10970 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 10971 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
10972 | add_com ("status", class_info, breakpoints_info, _("\ |
10973 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
10974 | The \"Type\" column indicates one of:\n\ |
10975 | \tbreakpoint - normal breakpoint\n\ | |
10976 | \twatchpoint - watchpoint\n\ | |
10977 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
10978 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
10979 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
10980 | address and file/line number respectively.\n\ |
10981 | \n\ | |
10982 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
10983 | are set to the address of the last breakpoint listed unless the command\n\ |
10984 | is prefixed with \"server \".\n\n\ | |
c906108c | 10985 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 10986 | breakpoint set.")); |
c906108c SS |
10987 | } |
10988 | ||
1bedd215 AC |
10989 | add_info ("breakpoints", breakpoints_info, _("\ |
10990 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
10991 | The \"Type\" column indicates one of:\n\ |
10992 | \tbreakpoint - normal breakpoint\n\ | |
10993 | \twatchpoint - watchpoint\n\ | |
10994 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
10995 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
10996 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
10997 | address and file/line number respectively.\n\ |
10998 | \n\ | |
10999 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
11000 | are set to the address of the last breakpoint listed unless the command\n\ |
11001 | is prefixed with \"server \".\n\n\ | |
c906108c | 11002 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 11003 | breakpoint set.")); |
c906108c | 11004 | |
6b04bdb7 MS |
11005 | add_info_alias ("b", "breakpoints", 1); |
11006 | ||
c906108c | 11007 | if (xdb_commands) |
1bedd215 AC |
11008 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
11009 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
11010 | The \"Type\" column indicates one of:\n\ |
11011 | \tbreakpoint - normal breakpoint\n\ | |
11012 | \twatchpoint - watchpoint\n\ | |
11013 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
11014 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
11015 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
11016 | address and file/line number respectively.\n\ |
11017 | \n\ | |
11018 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
11019 | are set to the address of the last breakpoint listed unless the command\n\ |
11020 | is prefixed with \"server \".\n\n\ | |
c906108c | 11021 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 11022 | breakpoint set.")); |
c906108c | 11023 | |
1a966eab AC |
11024 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
11025 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
11026 | The \"Type\" column indicates one of:\n\ |
11027 | \tbreakpoint - normal breakpoint\n\ | |
11028 | \twatchpoint - watchpoint\n\ | |
11029 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
11030 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
11031 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
11032 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
11033 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
11034 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
11035 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
11036 | address and file/line number respectively.\n\ |
11037 | \n\ | |
11038 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
11039 | are set to the address of the last breakpoint listed unless the command\n\ |
11040 | is prefixed with \"server \".\n\n\ | |
c906108c | 11041 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 11042 | breakpoint set."), |
c906108c SS |
11043 | &maintenanceinfolist); |
11044 | ||
44feb3ce TT |
11045 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
11046 | Set catchpoints to catch events."), | |
11047 | &catch_cmdlist, "catch ", | |
11048 | 0/*allow-unknown*/, &cmdlist); | |
11049 | ||
11050 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
11051 | Set temporary catchpoints to catch events."), | |
11052 | &tcatch_cmdlist, "tcatch ", | |
11053 | 0/*allow-unknown*/, &cmdlist); | |
11054 | ||
11055 | /* Add catch and tcatch sub-commands. */ | |
11056 | add_catch_command ("catch", _("\ | |
11057 | Catch an exception, when caught.\n\ | |
11058 | With an argument, catch only exceptions with the given name."), | |
11059 | catch_catch_command, | |
a96d9b2e | 11060 | NULL, |
44feb3ce TT |
11061 | CATCH_PERMANENT, |
11062 | CATCH_TEMPORARY); | |
11063 | add_catch_command ("throw", _("\ | |
11064 | Catch an exception, when thrown.\n\ | |
11065 | With an argument, catch only exceptions with the given name."), | |
11066 | catch_throw_command, | |
a96d9b2e | 11067 | NULL, |
44feb3ce TT |
11068 | CATCH_PERMANENT, |
11069 | CATCH_TEMPORARY); | |
11070 | add_catch_command ("fork", _("Catch calls to fork."), | |
11071 | catch_fork_command_1, | |
a96d9b2e | 11072 | NULL, |
44feb3ce TT |
11073 | (void *) (uintptr_t) catch_fork_permanent, |
11074 | (void *) (uintptr_t) catch_fork_temporary); | |
11075 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
11076 | catch_fork_command_1, | |
a96d9b2e | 11077 | NULL, |
44feb3ce TT |
11078 | (void *) (uintptr_t) catch_vfork_permanent, |
11079 | (void *) (uintptr_t) catch_vfork_temporary); | |
11080 | add_catch_command ("exec", _("Catch calls to exec."), | |
11081 | catch_exec_command_1, | |
a96d9b2e SDJ |
11082 | NULL, |
11083 | CATCH_PERMANENT, | |
11084 | CATCH_TEMPORARY); | |
11085 | add_catch_command ("syscall", _("\ | |
11086 | Catch system calls by their names and/or numbers.\n\ | |
11087 | Arguments say which system calls to catch. If no arguments\n\ | |
11088 | are given, every system call will be caught.\n\ | |
11089 | Arguments, if given, should be one or more system call names\n\ | |
11090 | (if your system supports that), or system call numbers."), | |
11091 | catch_syscall_command_1, | |
11092 | catch_syscall_completer, | |
44feb3ce TT |
11093 | CATCH_PERMANENT, |
11094 | CATCH_TEMPORARY); | |
44feb3ce TT |
11095 | add_catch_command ("exception", _("\ |
11096 | Catch Ada exceptions, when raised.\n\ | |
11097 | With an argument, catch only exceptions with the given name."), | |
11098 | catch_ada_exception_command, | |
a96d9b2e | 11099 | NULL, |
44feb3ce TT |
11100 | CATCH_PERMANENT, |
11101 | CATCH_TEMPORARY); | |
11102 | add_catch_command ("assert", _("\ | |
11103 | Catch failed Ada assertions, when raised.\n\ | |
11104 | With an argument, catch only exceptions with the given name."), | |
11105 | catch_assert_command, | |
a96d9b2e | 11106 | NULL, |
44feb3ce TT |
11107 | CATCH_PERMANENT, |
11108 | CATCH_TEMPORARY); | |
c5aa993b | 11109 | |
1bedd215 AC |
11110 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
11111 | Set a watchpoint for an expression.\n\ | |
c906108c | 11112 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 11113 | an expression changes.")); |
65d12d83 | 11114 | set_cmd_completer (c, expression_completer); |
c906108c | 11115 | |
1bedd215 AC |
11116 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
11117 | Set a read watchpoint for an expression.\n\ | |
c906108c | 11118 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 11119 | an expression is read.")); |
65d12d83 | 11120 | set_cmd_completer (c, expression_completer); |
c906108c | 11121 | |
1bedd215 AC |
11122 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
11123 | Set a watchpoint for an expression.\n\ | |
c906108c | 11124 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 11125 | an expression is either read or written.")); |
65d12d83 | 11126 | set_cmd_completer (c, expression_completer); |
c906108c SS |
11127 | |
11128 | add_info ("watchpoints", breakpoints_info, | |
1bedd215 | 11129 | _("Synonym for ``info breakpoints''.")); |
c906108c SS |
11130 | |
11131 | ||
920d2a44 AC |
11132 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
11133 | respond to changes - contrary to the description. */ | |
85c07804 AC |
11134 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
11135 | &can_use_hw_watchpoints, _("\ | |
11136 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
11137 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
11138 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
11139 | such is available. (However, any hardware watchpoints that were\n\ | |
11140 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
11141 | hardware.)"), |
11142 | NULL, | |
920d2a44 | 11143 | show_can_use_hw_watchpoints, |
85c07804 | 11144 | &setlist, &showlist); |
c906108c SS |
11145 | |
11146 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 11147 | |
1042e4c0 SS |
11148 | /* Tracepoint manipulation commands. */ |
11149 | ||
11150 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
11151 | Set a tracepoint at specified line or function.\n\ | |
11152 | \n" | |
11153 | BREAK_ARGS_HELP ("trace") "\n\ | |
11154 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
11155 | set_cmd_completer (c, location_completer); | |
11156 | ||
11157 | add_com_alias ("tp", "trace", class_alias, 0); | |
11158 | add_com_alias ("tr", "trace", class_alias, 1); | |
11159 | add_com_alias ("tra", "trace", class_alias, 1); | |
11160 | add_com_alias ("trac", "trace", class_alias, 1); | |
11161 | ||
7a697b8d SS |
11162 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
11163 | Set a fast tracepoint at specified line or function.\n\ | |
11164 | \n" | |
11165 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
11166 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
11167 | set_cmd_completer (c, location_completer); | |
11168 | ||
1042e4c0 SS |
11169 | add_info ("tracepoints", tracepoints_info, _("\ |
11170 | Status of tracepoints, or tracepoint number NUMBER.\n\ | |
11171 | Convenience variable \"$tpnum\" contains the number of the\n\ | |
11172 | last tracepoint set.")); | |
11173 | ||
11174 | add_info_alias ("tp", "tracepoints", 1); | |
11175 | ||
11176 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
11177 | Delete specified tracepoints.\n\ | |
11178 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
11179 | No argument means delete all tracepoints."), | |
11180 | &deletelist); | |
11181 | ||
11182 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
11183 | Disable specified tracepoints.\n\ | |
11184 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
11185 | No argument means disable all tracepoints."), | |
11186 | &disablelist); | |
11187 | deprecate_cmd (c, "disable"); | |
11188 | ||
11189 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
11190 | Enable specified tracepoints.\n\ | |
11191 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
11192 | No argument means enable all tracepoints."), | |
11193 | &enablelist); | |
11194 | deprecate_cmd (c, "enable"); | |
11195 | ||
11196 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
11197 | Set the passcount for a tracepoint.\n\ | |
11198 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
11199 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
11200 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
11201 | ||
11202 | c = add_com ("save-tracepoints", class_trace, tracepoint_save_command, _("\ | |
11203 | Save current tracepoint definitions as a script.\n\ | |
11204 | Use the 'source' command in another debug session to restore them.")); | |
11205 | set_cmd_completer (c, filename_completer); | |
11206 | ||
1bedd215 | 11207 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
11208 | Breakpoint specific settings\n\ |
11209 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 11210 | pending breakpoint behavior"), |
fa8d40ab JJ |
11211 | &breakpoint_set_cmdlist, "set breakpoint ", |
11212 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 11213 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
11214 | Breakpoint specific settings\n\ |
11215 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 11216 | pending breakpoint behavior"), |
fa8d40ab JJ |
11217 | &breakpoint_show_cmdlist, "show breakpoint ", |
11218 | 0/*allow-unknown*/, &showlist); | |
11219 | ||
7915a72c AC |
11220 | add_setshow_auto_boolean_cmd ("pending", no_class, |
11221 | &pending_break_support, _("\ | |
11222 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
11223 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
11224 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
11225 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
11226 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 11227 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 11228 | NULL, |
920d2a44 | 11229 | show_pending_break_support, |
6e1d7d6c AC |
11230 | &breakpoint_set_cmdlist, |
11231 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
11232 | |
11233 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
11234 | |
11235 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
11236 | &automatic_hardware_breakpoints, _("\ | |
11237 | Set automatic usage of hardware breakpoints."), _("\ | |
11238 | Show automatic usage of hardware breakpoints."), _("\ | |
11239 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
11240 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
11241 | a warning will be emitted for such breakpoints."), | |
11242 | NULL, | |
11243 | show_automatic_hardware_breakpoints, | |
11244 | &breakpoint_set_cmdlist, | |
11245 | &breakpoint_show_cmdlist); | |
74960c60 | 11246 | |
33e5cbd6 PA |
11247 | add_setshow_enum_cmd ("always-inserted", class_support, |
11248 | always_inserted_enums, &always_inserted_mode, _("\ | |
74960c60 VP |
11249 | Set mode for inserting breakpoints."), _("\ |
11250 | Show mode for inserting breakpoints."), _("\ | |
33e5cbd6 PA |
11251 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
11252 | resumed, and removed when execution stops. When this mode is on,\n\ | |
11253 | breakpoints are inserted immediately and removed only when the user\n\ | |
11254 | deletes the breakpoint. When this mode is auto (which is the default),\n\ | |
11255 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ | |
11256 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ | |
11257 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ | |
11258 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), | |
74960c60 VP |
11259 | NULL, |
11260 | &show_always_inserted_mode, | |
11261 | &breakpoint_set_cmdlist, | |
11262 | &breakpoint_show_cmdlist); | |
765dc015 VP |
11263 | |
11264 | automatic_hardware_breakpoints = 1; | |
f3b1572e PA |
11265 | |
11266 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
c906108c | 11267 | } |