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 | ||
5cea2a26 PA |
225 | /* A reference-counted struct command_line. This lets multiple |
226 | breakpoints share a single command list. */ | |
227 | struct counted_command_line | |
228 | { | |
229 | /* The reference count. */ | |
230 | int refc; | |
231 | ||
232 | /* The command list. */ | |
233 | struct command_line *commands; | |
234 | }; | |
235 | ||
236 | struct command_line * | |
237 | breakpoint_commands (struct breakpoint *b) | |
238 | { | |
239 | return b->commands ? b->commands->commands : NULL; | |
240 | } | |
3daf8fe5 | 241 | |
f3b1572e PA |
242 | /* Flag indicating that a command has proceeded the inferior past the |
243 | current breakpoint. */ | |
244 | ||
245 | static int breakpoint_proceeded; | |
246 | ||
2cec12e5 AR |
247 | static const char * |
248 | bpdisp_text (enum bpdisp disp) | |
249 | { | |
250 | /* NOTE: the following values are a part of MI protocol and represent | |
251 | values of 'disp' field returned when inferior stops at a breakpoint. */ | |
252 | static char *bpdisps[] = {"del", "dstp", "dis", "keep"}; | |
253 | return bpdisps[(int) disp]; | |
254 | } | |
c906108c | 255 | |
2cec12e5 | 256 | /* Prototypes for exported functions. */ |
c906108c SS |
257 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
258 | if such is available. */ | |
259 | static int can_use_hw_watchpoints; | |
260 | ||
920d2a44 AC |
261 | static void |
262 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
263 | struct cmd_list_element *c, | |
264 | const char *value) | |
265 | { | |
266 | fprintf_filtered (file, _("\ | |
267 | Debugger's willingness to use watchpoint hardware is %s.\n"), | |
268 | value); | |
269 | } | |
270 | ||
fa8d40ab JJ |
271 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
272 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
273 | for unrecognized breakpoint locations. | |
274 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ | |
275 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
276 | static void |
277 | show_pending_break_support (struct ui_file *file, int from_tty, | |
278 | struct cmd_list_element *c, | |
279 | const char *value) | |
280 | { | |
281 | fprintf_filtered (file, _("\ | |
282 | Debugger's behavior regarding pending breakpoints is %s.\n"), | |
283 | value); | |
284 | } | |
fa8d40ab | 285 | |
765dc015 VP |
286 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
287 | set with "break" but falling in read-only memory. | |
288 | If 0, gdb will warn about such breakpoints, but won't automatically | |
289 | use hardware breakpoints. */ | |
290 | static int automatic_hardware_breakpoints; | |
291 | static void | |
292 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
293 | struct cmd_list_element *c, | |
294 | const char *value) | |
295 | { | |
296 | fprintf_filtered (file, _("\ | |
297 | Automatic usage of hardware breakpoints is %s.\n"), | |
298 | value); | |
299 | } | |
300 | ||
33e5cbd6 PA |
301 | /* If on, gdb will keep breakpoints inserted even as inferior is |
302 | stopped, and immediately insert any new breakpoints. If off, gdb | |
303 | will insert breakpoints into inferior only when resuming it, and | |
304 | will remove breakpoints upon stop. If auto, GDB will behave as ON | |
305 | if in non-stop mode, and as OFF if all-stop mode.*/ | |
306 | ||
307 | static const char always_inserted_auto[] = "auto"; | |
308 | static const char always_inserted_on[] = "on"; | |
309 | static const char always_inserted_off[] = "off"; | |
310 | static const char *always_inserted_enums[] = { | |
311 | always_inserted_auto, | |
312 | always_inserted_off, | |
313 | always_inserted_on, | |
314 | NULL | |
315 | }; | |
316 | static const char *always_inserted_mode = always_inserted_auto; | |
317 | static void | |
74960c60 | 318 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 319 | struct cmd_list_element *c, const char *value) |
74960c60 | 320 | { |
33e5cbd6 PA |
321 | if (always_inserted_mode == always_inserted_auto) |
322 | fprintf_filtered (file, _("\ | |
323 | Always inserted breakpoint mode is %s (currently %s).\n"), | |
324 | value, | |
325 | breakpoints_always_inserted_mode () ? "on" : "off"); | |
326 | else | |
327 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), value); | |
74960c60 VP |
328 | } |
329 | ||
33e5cbd6 PA |
330 | int |
331 | breakpoints_always_inserted_mode (void) | |
332 | { | |
333 | return (always_inserted_mode == always_inserted_on | |
334 | || (always_inserted_mode == always_inserted_auto && non_stop)); | |
335 | } | |
765dc015 | 336 | |
a14ed312 | 337 | void _initialize_breakpoint (void); |
c906108c | 338 | |
c906108c SS |
339 | /* Are we executing breakpoint commands? */ |
340 | static int executing_breakpoint_commands; | |
341 | ||
c02f5703 MS |
342 | /* Are overlay event breakpoints enabled? */ |
343 | static int overlay_events_enabled; | |
344 | ||
c906108c SS |
345 | /* Walk the following statement or block through all breakpoints. |
346 | ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current | |
347 | breakpoint. */ | |
348 | ||
5c44784c | 349 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 350 | |
5c44784c JM |
351 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
352 | for (B = breakpoint_chain; \ | |
353 | B ? (TMP=B->next, 1): 0; \ | |
354 | B = TMP) | |
c906108c | 355 | |
876fa593 JK |
356 | /* Similar iterator for the low-level breakpoints. SAFE variant is not |
357 | provided so update_global_location_list must not be called while executing | |
358 | the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 359 | |
876fa593 JK |
360 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
361 | for (BP_TMP = bp_location; \ | |
362 | BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \ | |
363 | BP_TMP++) | |
7cc221ef | 364 | |
1042e4c0 SS |
365 | /* Iterator for tracepoints only. */ |
366 | ||
367 | #define ALL_TRACEPOINTS(B) \ | |
368 | for (B = breakpoint_chain; B; B = B->next) \ | |
7a697b8d | 369 | if (tracepoint_type (B)) |
1042e4c0 | 370 | |
7cc221ef | 371 | /* Chains of all breakpoints defined. */ |
c906108c SS |
372 | |
373 | struct breakpoint *breakpoint_chain; | |
374 | ||
876fa593 JK |
375 | /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */ |
376 | ||
377 | static struct bp_location **bp_location; | |
378 | ||
379 | /* Number of elements of BP_LOCATION. */ | |
380 | ||
381 | static unsigned bp_location_count; | |
382 | ||
383 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and ADDRESS | |
384 | for the current elements of BP_LOCATION which get a valid result from | |
385 | bp_location_has_shadow. You can use it for roughly limiting the subrange of | |
386 | BP_LOCATION to scan for shadow bytes for an address you need to read. */ | |
387 | ||
388 | static CORE_ADDR bp_location_placed_address_before_address_max; | |
389 | ||
390 | /* Maximum offset plus alignment between | |
391 | bp_target_info.PLACED_ADDRESS + bp_target_info.SHADOW_LEN and ADDRESS for | |
392 | the current elements of BP_LOCATION which get a valid result from | |
393 | bp_location_has_shadow. You can use it for roughly limiting the subrange of | |
394 | BP_LOCATION to scan for shadow bytes for an address you need to read. */ | |
395 | ||
396 | static CORE_ADDR bp_location_shadow_len_after_address_max; | |
7cc221ef | 397 | |
20874c92 | 398 | /* The locations that no longer correspond to any breakpoint, |
876fa593 | 399 | unlinked from bp_location array, but for which a hit |
20874c92 VP |
400 | may still be reported by a target. */ |
401 | VEC(bp_location_p) *moribund_locations = NULL; | |
402 | ||
c906108c SS |
403 | /* Number of last breakpoint made. */ |
404 | ||
95a42b64 TT |
405 | static int breakpoint_count; |
406 | ||
86b17b60 PA |
407 | /* The value of `breakpoint_count' before the last command that |
408 | created breakpoints. If the last (break-like) command created more | |
409 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
410 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
411 | static int prev_breakpoint_count; | |
c906108c | 412 | |
1042e4c0 SS |
413 | /* Number of last tracepoint made. */ |
414 | ||
95a42b64 | 415 | static int tracepoint_count; |
1042e4c0 | 416 | |
468d015d JJ |
417 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
418 | static int | |
419 | breakpoint_enabled (struct breakpoint *b) | |
420 | { | |
0d381245 | 421 | return (b->enable_state == bp_enabled); |
468d015d JJ |
422 | } |
423 | ||
c906108c SS |
424 | /* Set breakpoint count to NUM. */ |
425 | ||
95a42b64 | 426 | static void |
fba45db2 | 427 | set_breakpoint_count (int num) |
c906108c | 428 | { |
86b17b60 | 429 | prev_breakpoint_count = breakpoint_count; |
c906108c | 430 | breakpoint_count = num; |
4fa62494 | 431 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
432 | } |
433 | ||
86b17b60 PA |
434 | /* Used by `start_rbreak_breakpoints' below, to record the current |
435 | breakpoint count before "rbreak" creates any breakpoint. */ | |
436 | static int rbreak_start_breakpoint_count; | |
437 | ||
95a42b64 TT |
438 | /* Called at the start an "rbreak" command to record the first |
439 | breakpoint made. */ | |
86b17b60 | 440 | |
95a42b64 TT |
441 | void |
442 | start_rbreak_breakpoints (void) | |
443 | { | |
86b17b60 | 444 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
445 | } |
446 | ||
447 | /* Called at the end of an "rbreak" command to record the last | |
448 | breakpoint made. */ | |
86b17b60 | 449 | |
95a42b64 TT |
450 | void |
451 | end_rbreak_breakpoints (void) | |
452 | { | |
86b17b60 | 453 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
454 | } |
455 | ||
c906108c SS |
456 | /* Used in run_command to zero the hit count when a new run starts. */ |
457 | ||
458 | void | |
fba45db2 | 459 | clear_breakpoint_hit_counts (void) |
c906108c SS |
460 | { |
461 | struct breakpoint *b; | |
462 | ||
463 | ALL_BREAKPOINTS (b) | |
464 | b->hit_count = 0; | |
465 | } | |
466 | ||
7a697b8d SS |
467 | /* Encapsulate tests for different types of tracepoints. */ |
468 | ||
469 | static int | |
470 | tracepoint_type (const struct breakpoint *b) | |
471 | { | |
472 | return (b->type == bp_tracepoint || b->type == bp_fast_tracepoint); | |
473 | } | |
474 | ||
9add0f1b TT |
475 | /* Allocate a new counted_command_line with reference count of 1. |
476 | The new structure owns COMMANDS. */ | |
477 | ||
478 | static struct counted_command_line * | |
479 | alloc_counted_command_line (struct command_line *commands) | |
480 | { | |
481 | struct counted_command_line *result | |
482 | = xmalloc (sizeof (struct counted_command_line)); | |
483 | result->refc = 1; | |
484 | result->commands = commands; | |
485 | return result; | |
486 | } | |
487 | ||
488 | /* Increment reference count. This does nothing if CMD is NULL. */ | |
489 | ||
490 | static void | |
491 | incref_counted_command_line (struct counted_command_line *cmd) | |
492 | { | |
493 | if (cmd) | |
494 | ++cmd->refc; | |
495 | } | |
496 | ||
497 | /* Decrement reference count. If the reference count reaches 0, | |
498 | destroy the counted_command_line. Sets *CMDP to NULL. This does | |
499 | nothing if *CMDP is NULL. */ | |
500 | ||
501 | static void | |
502 | decref_counted_command_line (struct counted_command_line **cmdp) | |
503 | { | |
504 | if (*cmdp) | |
505 | { | |
506 | if (--(*cmdp)->refc == 0) | |
507 | { | |
508 | free_command_lines (&(*cmdp)->commands); | |
509 | xfree (*cmdp); | |
510 | } | |
511 | *cmdp = NULL; | |
512 | } | |
513 | } | |
514 | ||
515 | /* A cleanup function that calls decref_counted_command_line. */ | |
516 | ||
517 | static void | |
518 | do_cleanup_counted_command_line (void *arg) | |
519 | { | |
520 | decref_counted_command_line (arg); | |
521 | } | |
522 | ||
523 | /* Create a cleanup that calls decref_counted_command_line on the | |
524 | argument. */ | |
525 | ||
526 | static struct cleanup * | |
527 | make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp) | |
528 | { | |
529 | return make_cleanup (do_cleanup_counted_command_line, cmdp); | |
530 | } | |
531 | ||
c906108c SS |
532 | /* Default address, symtab and line to put a breakpoint at |
533 | for "break" command with no arg. | |
534 | if default_breakpoint_valid is zero, the other three are | |
535 | not valid, and "break" with no arg is an error. | |
536 | ||
537 | This set by print_stack_frame, which calls set_default_breakpoint. */ | |
538 | ||
539 | int default_breakpoint_valid; | |
540 | CORE_ADDR default_breakpoint_address; | |
541 | struct symtab *default_breakpoint_symtab; | |
542 | int default_breakpoint_line; | |
6c95b8df PA |
543 | struct program_space *default_breakpoint_pspace; |
544 | ||
c906108c SS |
545 | \f |
546 | /* *PP is a string denoting a breakpoint. Get the number of the breakpoint. | |
547 | Advance *PP after the string and any trailing whitespace. | |
548 | ||
549 | Currently the string can either be a number or "$" followed by the name | |
550 | of a convenience variable. Making it an expression wouldn't work well | |
5c44784c | 551 | for map_breakpoint_numbers (e.g. "4 + 5 + 6"). |
40c03ae8 EZ |
552 | |
553 | If the string is a NULL pointer, that denotes the last breakpoint. | |
5c44784c JM |
554 | |
555 | TRAILER is a character which can be found after the number; most | |
556 | commonly this is `-'. If you don't want a trailer, use \0. */ | |
c906108c | 557 | static int |
fba45db2 | 558 | get_number_trailer (char **pp, int trailer) |
c906108c | 559 | { |
5c44784c | 560 | int retval = 0; /* default */ |
c906108c SS |
561 | char *p = *pp; |
562 | ||
563 | if (p == NULL) | |
564 | /* Empty line means refer to the last breakpoint. */ | |
565 | return breakpoint_count; | |
566 | else if (*p == '$') | |
567 | { | |
568 | /* Make a copy of the name, so we can null-terminate it | |
c5aa993b | 569 | to pass to lookup_internalvar(). */ |
c906108c SS |
570 | char *varname; |
571 | char *start = ++p; | |
4fa62494 | 572 | LONGEST val; |
c906108c SS |
573 | |
574 | while (isalnum (*p) || *p == '_') | |
575 | p++; | |
576 | varname = (char *) alloca (p - start + 1); | |
577 | strncpy (varname, start, p - start); | |
578 | varname[p - start] = '\0'; | |
4fa62494 UW |
579 | if (get_internalvar_integer (lookup_internalvar (varname), &val)) |
580 | retval = (int) val; | |
5c44784c JM |
581 | else |
582 | { | |
a3f17187 | 583 | printf_filtered (_("Convenience variable must have integer value.\n")); |
5c44784c JM |
584 | retval = 0; |
585 | } | |
c906108c SS |
586 | } |
587 | else | |
588 | { | |
589 | if (*p == '-') | |
590 | ++p; | |
591 | while (*p >= '0' && *p <= '9') | |
592 | ++p; | |
593 | if (p == *pp) | |
594 | /* There is no number here. (e.g. "cond a == b"). */ | |
5c44784c JM |
595 | { |
596 | /* Skip non-numeric token */ | |
597 | while (*p && !isspace((int) *p)) | |
598 | ++p; | |
599 | /* Return zero, which caller must interpret as error. */ | |
600 | retval = 0; | |
601 | } | |
602 | else | |
603 | retval = atoi (*pp); | |
604 | } | |
605 | if (!(isspace (*p) || *p == '\0' || *p == trailer)) | |
606 | { | |
607 | /* Trailing junk: return 0 and let caller print error msg. */ | |
608 | while (!(isspace (*p) || *p == '\0' || *p == trailer)) | |
609 | ++p; | |
610 | retval = 0; | |
c906108c | 611 | } |
c906108c SS |
612 | while (isspace (*p)) |
613 | p++; | |
614 | *pp = p; | |
615 | return retval; | |
616 | } | |
5c44784c | 617 | |
11cf8741 | 618 | |
5c44784c JM |
619 | /* Like get_number_trailer, but don't allow a trailer. */ |
620 | int | |
fba45db2 | 621 | get_number (char **pp) |
5c44784c JM |
622 | { |
623 | return get_number_trailer (pp, '\0'); | |
624 | } | |
625 | ||
626 | /* Parse a number or a range. | |
627 | * A number will be of the form handled by get_number. | |
628 | * A range will be of the form <number1> - <number2>, and | |
629 | * will represent all the integers between number1 and number2, | |
630 | * inclusive. | |
631 | * | |
632 | * While processing a range, this fuction is called iteratively; | |
633 | * At each call it will return the next value in the range. | |
634 | * | |
635 | * At the beginning of parsing a range, the char pointer PP will | |
636 | * be advanced past <number1> and left pointing at the '-' token. | |
637 | * Subsequent calls will not advance the pointer until the range | |
638 | * is completed. The call that completes the range will advance | |
639 | * pointer PP past <number2>. | |
640 | */ | |
641 | ||
642 | int | |
fba45db2 | 643 | get_number_or_range (char **pp) |
5c44784c JM |
644 | { |
645 | static int last_retval, end_value; | |
646 | static char *end_ptr; | |
647 | static int in_range = 0; | |
648 | ||
649 | if (**pp != '-') | |
650 | { | |
651 | /* Default case: pp is pointing either to a solo number, | |
652 | or to the first number of a range. */ | |
653 | last_retval = get_number_trailer (pp, '-'); | |
654 | if (**pp == '-') | |
655 | { | |
656 | char **temp; | |
657 | ||
658 | /* This is the start of a range (<number1> - <number2>). | |
659 | Skip the '-', parse and remember the second number, | |
660 | and also remember the end of the final token. */ | |
661 | ||
662 | temp = &end_ptr; | |
663 | end_ptr = *pp + 1; | |
664 | while (isspace ((int) *end_ptr)) | |
665 | end_ptr++; /* skip white space */ | |
666 | end_value = get_number (temp); | |
667 | if (end_value < last_retval) | |
668 | { | |
8a3fe4f8 | 669 | error (_("inverted range")); |
5c44784c JM |
670 | } |
671 | else if (end_value == last_retval) | |
672 | { | |
673 | /* degenerate range (number1 == number2). Advance the | |
674 | token pointer so that the range will be treated as a | |
675 | single number. */ | |
676 | *pp = end_ptr; | |
677 | } | |
678 | else | |
679 | in_range = 1; | |
680 | } | |
681 | } | |
682 | else if (! in_range) | |
8a3fe4f8 | 683 | error (_("negative value")); |
5c44784c JM |
684 | else |
685 | { | |
686 | /* pp points to the '-' that betokens a range. All | |
687 | number-parsing has already been done. Return the next | |
688 | integer value (one greater than the saved previous value). | |
689 | Do not advance the token pointer 'pp' until the end of range | |
690 | is reached. */ | |
691 | ||
692 | if (++last_retval == end_value) | |
693 | { | |
694 | /* End of range reached; advance token pointer. */ | |
695 | *pp = end_ptr; | |
696 | in_range = 0; | |
697 | } | |
698 | } | |
699 | return last_retval; | |
700 | } | |
701 | ||
48cb2d85 VP |
702 | /* Return the breakpoint with the specified number, or NULL |
703 | if the number does not refer to an existing breakpoint. */ | |
704 | ||
705 | struct breakpoint * | |
706 | get_breakpoint (int num) | |
707 | { | |
708 | struct breakpoint *b; | |
709 | ||
710 | ALL_BREAKPOINTS (b) | |
711 | if (b->number == num) | |
712 | return b; | |
713 | ||
714 | return NULL; | |
715 | } | |
5c44784c | 716 | |
c906108c SS |
717 | \f |
718 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ | |
719 | ||
720 | static void | |
fba45db2 | 721 | condition_command (char *arg, int from_tty) |
c906108c | 722 | { |
52f0bd74 | 723 | struct breakpoint *b; |
c906108c | 724 | char *p; |
52f0bd74 | 725 | int bnum; |
c906108c SS |
726 | |
727 | if (arg == 0) | |
e2e0b3e5 | 728 | error_no_arg (_("breakpoint number")); |
c906108c SS |
729 | |
730 | p = arg; | |
731 | bnum = get_number (&p); | |
5c44784c | 732 | if (bnum == 0) |
8a3fe4f8 | 733 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
734 | |
735 | ALL_BREAKPOINTS (b) | |
736 | if (b->number == bnum) | |
2f069f6f JB |
737 | { |
738 | struct bp_location *loc = b->loc; | |
739 | for (; loc; loc = loc->next) | |
740 | { | |
60e1c644 PA |
741 | xfree (loc->cond); |
742 | loc->cond = NULL; | |
2f069f6f | 743 | } |
60e1c644 PA |
744 | xfree (b->cond_string); |
745 | b->cond_string = NULL; | |
746 | xfree (b->cond_exp); | |
747 | b->cond_exp = NULL; | |
c906108c | 748 | |
2f069f6f JB |
749 | if (*p == 0) |
750 | { | |
2f069f6f JB |
751 | if (from_tty) |
752 | printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum); | |
753 | } | |
754 | else | |
755 | { | |
756 | arg = p; | |
757 | /* I don't know if it matters whether this is the string the user | |
758 | typed in or the decompiled expression. */ | |
1b36a34b | 759 | b->cond_string = xstrdup (arg); |
2f069f6f | 760 | b->condition_not_parsed = 0; |
60e1c644 PA |
761 | |
762 | if (is_watchpoint (b)) | |
2f069f6f | 763 | { |
60e1c644 | 764 | innermost_block = NULL; |
2f069f6f | 765 | arg = p; |
60e1c644 | 766 | b->cond_exp = parse_exp_1 (&arg, 0, 0); |
2f069f6f JB |
767 | if (*arg) |
768 | error (_("Junk at end of expression")); | |
60e1c644 PA |
769 | b->cond_exp_valid_block = innermost_block; |
770 | } | |
771 | else | |
772 | { | |
773 | for (loc = b->loc; loc; loc = loc->next) | |
774 | { | |
775 | arg = p; | |
776 | loc->cond = | |
777 | parse_exp_1 (&arg, block_for_pc (loc->address), 0); | |
778 | if (*arg) | |
779 | error (_("Junk at end of expression")); | |
780 | } | |
2f069f6f JB |
781 | } |
782 | } | |
783 | breakpoints_changed (); | |
383f836e | 784 | observer_notify_breakpoint_modified (b->number); |
2f069f6f JB |
785 | return; |
786 | } | |
c906108c | 787 | |
8a3fe4f8 | 788 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
789 | } |
790 | ||
a7bdde9e VP |
791 | /* Check that COMMAND do not contain commands that are suitable |
792 | only for tracepoints and not suitable for ordinary breakpoints. | |
793 | Throw if any such commands is found. | |
794 | */ | |
795 | static void | |
796 | check_no_tracepoint_commands (struct command_line *commands) | |
797 | { | |
798 | struct command_line *c; | |
799 | for (c = commands; c; c = c->next) | |
800 | { | |
801 | int i; | |
802 | ||
803 | if (c->control_type == while_stepping_control) | |
804 | error (_("The 'while-stepping' command can only be used for tracepoints")); | |
805 | ||
806 | for (i = 0; i < c->body_count; ++i) | |
807 | check_no_tracepoint_commands ((c->body_list)[i]); | |
808 | ||
809 | /* Not that command parsing removes leading whitespace and comment | |
810 | lines and also empty lines. So, we only need to check for | |
811 | command directly. */ | |
812 | if (strstr (c->line, "collect ") == c->line) | |
813 | error (_("The 'collect' command can only be used for tracepoints")); | |
814 | ||
51661e93 VP |
815 | if (strstr (c->line, "teval ") == c->line) |
816 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
817 | } |
818 | } | |
819 | ||
820 | int | |
821 | breakpoint_is_tracepoint (const struct breakpoint *b) | |
822 | { | |
823 | switch (b->type) | |
824 | { | |
825 | case bp_tracepoint: | |
826 | case bp_fast_tracepoint: | |
827 | return 1; | |
828 | default: | |
829 | return 0; | |
830 | ||
831 | } | |
832 | } | |
833 | ||
95a42b64 TT |
834 | /* A helper function that validsates that COMMANDS are valid for a |
835 | breakpoint. This function will throw an exception if a problem is | |
836 | found. */ | |
48cb2d85 | 837 | |
95a42b64 TT |
838 | static void |
839 | validate_commands_for_breakpoint (struct breakpoint *b, | |
840 | struct command_line *commands) | |
48cb2d85 | 841 | { |
a7bdde9e VP |
842 | if (breakpoint_is_tracepoint (b)) |
843 | { | |
844 | /* We need to verify that each top-level element of commands | |
845 | is valid for tracepoints, that there's at most one while-stepping | |
846 | element, and that while-stepping's body has valid tracing commands | |
847 | excluding nested while-stepping. */ | |
848 | struct command_line *c; | |
849 | struct command_line *while_stepping = 0; | |
850 | for (c = commands; c; c = c->next) | |
851 | { | |
852 | char *l = c->line; | |
853 | if (c->control_type == while_stepping_control) | |
854 | { | |
855 | if (b->type == bp_fast_tracepoint) | |
856 | error (_("The 'while-stepping' command cannot be used for fast tracepoint")); | |
857 | ||
858 | if (while_stepping) | |
859 | error (_("The 'while-stepping' command can be used only once")); | |
860 | else | |
861 | while_stepping = c; | |
862 | } | |
863 | } | |
864 | if (while_stepping) | |
865 | { | |
866 | struct command_line *c2; | |
867 | ||
868 | gdb_assert (while_stepping->body_count == 1); | |
869 | c2 = while_stepping->body_list[0]; | |
870 | for (; c2; c2 = c2->next) | |
871 | { | |
872 | char *l = c2->line; | |
873 | if (c2->control_type == while_stepping_control) | |
874 | error (_("The 'while-stepping' command cannot be nested")); | |
875 | } | |
876 | } | |
877 | } | |
878 | else | |
879 | { | |
880 | check_no_tracepoint_commands (commands); | |
881 | } | |
95a42b64 TT |
882 | } |
883 | ||
884 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, | |
885 | validate that only allowed commands are included. | |
886 | */ | |
887 | ||
888 | void | |
889 | breakpoint_set_commands (struct breakpoint *b, struct command_line *commands) | |
890 | { | |
891 | validate_commands_for_breakpoint (b, commands); | |
a7bdde9e | 892 | |
9add0f1b TT |
893 | decref_counted_command_line (&b->commands); |
894 | b->commands = alloc_counted_command_line (commands); | |
48cb2d85 VP |
895 | breakpoints_changed (); |
896 | observer_notify_breakpoint_modified (b->number); | |
897 | } | |
898 | ||
95a42b64 TT |
899 | void |
900 | check_tracepoint_command (char *line, void *closure) | |
a7bdde9e VP |
901 | { |
902 | struct breakpoint *b = closure; | |
903 | validate_actionline (&line, b); | |
904 | } | |
905 | ||
95a42b64 TT |
906 | /* A structure used to pass information through |
907 | map_breakpoint_numbers. */ | |
908 | ||
909 | struct commands_info | |
910 | { | |
911 | /* True if the command was typed at a tty. */ | |
912 | int from_tty; | |
86b17b60 PA |
913 | |
914 | /* The breakpoint range spec. */ | |
915 | char *arg; | |
916 | ||
95a42b64 TT |
917 | /* Non-NULL if the body of the commands are being read from this |
918 | already-parsed command. */ | |
919 | struct command_line *control; | |
86b17b60 | 920 | |
95a42b64 TT |
921 | /* The command lines read from the user, or NULL if they have not |
922 | yet been read. */ | |
923 | struct counted_command_line *cmd; | |
924 | }; | |
925 | ||
926 | /* A callback for map_breakpoint_numbers that sets the commands for | |
927 | commands_command. */ | |
928 | ||
c906108c | 929 | static void |
95a42b64 | 930 | do_map_commands_command (struct breakpoint *b, void *data) |
c906108c | 931 | { |
95a42b64 | 932 | struct commands_info *info = data; |
c906108c | 933 | |
95a42b64 TT |
934 | if (info->cmd == NULL) |
935 | { | |
936 | struct command_line *l; | |
5c44784c | 937 | |
95a42b64 TT |
938 | if (info->control != NULL) |
939 | l = copy_command_lines (info->control->body_list[0]); | |
940 | else | |
86b17b60 PA |
941 | { |
942 | struct cleanup *old_chain; | |
943 | char *str; | |
c5aa993b | 944 | |
86b17b60 PA |
945 | str = xstrprintf (_("Type commands for breakpoint(s) %s, one per line."), |
946 | info->arg); | |
947 | ||
948 | old_chain = make_cleanup (xfree, str); | |
949 | ||
950 | l = read_command_lines (str, | |
951 | info->from_tty, 1, | |
952 | (breakpoint_is_tracepoint (b) | |
953 | ? check_tracepoint_command : 0), | |
954 | b); | |
955 | ||
956 | do_cleanups (old_chain); | |
957 | } | |
a7bdde9e | 958 | |
95a42b64 TT |
959 | info->cmd = alloc_counted_command_line (l); |
960 | } | |
961 | ||
962 | /* If a breakpoint was on the list more than once, we don't need to | |
963 | do anything. */ | |
964 | if (b->commands != info->cmd) | |
965 | { | |
966 | validate_commands_for_breakpoint (b, info->cmd->commands); | |
967 | incref_counted_command_line (info->cmd); | |
968 | decref_counted_command_line (&b->commands); | |
969 | b->commands = info->cmd; | |
970 | breakpoints_changed (); | |
971 | observer_notify_breakpoint_modified (b->number); | |
c5aa993b | 972 | } |
95a42b64 TT |
973 | } |
974 | ||
975 | static void | |
976 | commands_command_1 (char *arg, int from_tty, struct command_line *control) | |
977 | { | |
978 | struct cleanup *cleanups; | |
979 | struct commands_info info; | |
980 | ||
981 | info.from_tty = from_tty; | |
982 | info.control = control; | |
983 | info.cmd = NULL; | |
984 | /* If we read command lines from the user, then `info' will hold an | |
985 | extra reference to the commands that we must clean up. */ | |
986 | cleanups = make_cleanup_decref_counted_command_line (&info.cmd); | |
987 | ||
988 | if (arg == NULL || !*arg) | |
989 | { | |
86b17b60 PA |
990 | if (breakpoint_count - prev_breakpoint_count > 1) |
991 | arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1, breakpoint_count); | |
95a42b64 TT |
992 | else if (breakpoint_count > 0) |
993 | arg = xstrprintf ("%d", breakpoint_count); | |
86b17b60 PA |
994 | else |
995 | { | |
996 | /* So that we don't try to free the incoming non-NULL | |
997 | argument in the cleanup below. Mapping breakpoint | |
998 | numbers will fail in this case. */ | |
999 | arg = NULL; | |
1000 | } | |
95a42b64 | 1001 | } |
9766ced4 SS |
1002 | else |
1003 | /* The command loop has some static state, so we need to preserve | |
1004 | our argument. */ | |
1005 | arg = xstrdup (arg); | |
86b17b60 PA |
1006 | |
1007 | if (arg != NULL) | |
1008 | make_cleanup (xfree, arg); | |
1009 | ||
1010 | info.arg = arg; | |
95a42b64 TT |
1011 | |
1012 | map_breakpoint_numbers (arg, do_map_commands_command, &info); | |
1013 | ||
1014 | if (info.cmd == NULL) | |
1015 | error (_("No breakpoints specified.")); | |
1016 | ||
1017 | do_cleanups (cleanups); | |
1018 | } | |
1019 | ||
1020 | static void | |
1021 | commands_command (char *arg, int from_tty) | |
1022 | { | |
1023 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1024 | } |
40c03ae8 EZ |
1025 | |
1026 | /* Like commands_command, but instead of reading the commands from | |
1027 | input stream, takes them from an already parsed command structure. | |
1028 | ||
1029 | This is used by cli-script.c to DTRT with breakpoint commands | |
1030 | that are part of if and while bodies. */ | |
1031 | enum command_control_type | |
1032 | commands_from_control_command (char *arg, struct command_line *cmd) | |
1033 | { | |
95a42b64 TT |
1034 | commands_command_1 (arg, 0, cmd); |
1035 | return simple_control; | |
40c03ae8 | 1036 | } |
876fa593 JK |
1037 | |
1038 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1039 | ||
1040 | static int | |
1041 | bp_location_has_shadow (struct bp_location *bl) | |
1042 | { | |
1043 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1044 | return 0; | |
1045 | if (!bl->inserted) | |
1046 | return 0; | |
1047 | if (bl->target_info.shadow_len == 0) | |
1048 | /* bp isn't valid, or doesn't shadow memory. */ | |
1049 | return 0; | |
1050 | return 1; | |
1051 | } | |
1052 | ||
8defab1a | 1053 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1054 | by replacing any memory breakpoints with their shadowed contents. |
1055 | ||
1056 | The range of shadowed area by each bp_location is: | |
1057 | b->address - bp_location_placed_address_before_address_max | |
1058 | up to b->address + bp_location_shadow_len_after_address_max | |
1059 | The range we were requested to resolve shadows for is: | |
1060 | memaddr ... memaddr + len | |
1061 | Thus the safe cutoff boundaries for performance optimization are | |
1062 | memaddr + len <= b->address - bp_location_placed_address_before_address_max | |
1063 | and: | |
1064 | b->address + bp_location_shadow_len_after_address_max <= memaddr */ | |
c906108c | 1065 | |
8defab1a DJ |
1066 | void |
1067 | breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len) | |
c906108c | 1068 | { |
876fa593 JK |
1069 | /* Left boundary, right boundary and median element of our binary search. */ |
1070 | unsigned bc_l, bc_r, bc; | |
1071 | ||
1072 | /* Find BC_L which is a leftmost element which may affect BUF content. It is | |
1073 | safe to report lower value but a failure to report higher one. */ | |
1074 | ||
1075 | bc_l = 0; | |
1076 | bc_r = bp_location_count; | |
1077 | while (bc_l + 1 < bc_r) | |
1078 | { | |
1079 | struct bp_location *b; | |
1080 | ||
1081 | bc = (bc_l + bc_r) / 2; | |
1082 | b = bp_location[bc]; | |
1083 | ||
1084 | /* Check first B->ADDRESS will not overflow due to the added constant. | |
1085 | Then advance the left boundary only if we are sure the BC element can | |
1086 | in no way affect the BUF content (MEMADDR to MEMADDR + LEN range). | |
1087 | ||
1088 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety offset so that | |
1089 | we cannot miss a breakpoint with its shadow range tail still reaching | |
1090 | MEMADDR. */ | |
c5aa993b | 1091 | |
876fa593 JK |
1092 | if (b->address + bp_location_shadow_len_after_address_max >= b->address |
1093 | && b->address + bp_location_shadow_len_after_address_max <= memaddr) | |
1094 | bc_l = bc; | |
1095 | else | |
1096 | bc_r = bc; | |
1097 | } | |
1098 | ||
1099 | /* Now do full processing of the found relevant range of elements. */ | |
1100 | ||
1101 | for (bc = bc_l; bc < bp_location_count; bc++) | |
c5aa993b | 1102 | { |
876fa593 JK |
1103 | struct bp_location *b = bp_location[bc]; |
1104 | CORE_ADDR bp_addr = 0; | |
1105 | int bp_size = 0; | |
1106 | int bptoffset = 0; | |
1107 | ||
ffce0d52 | 1108 | if (b->owner->type == bp_none) |
8a3fe4f8 | 1109 | warning (_("reading through apparently deleted breakpoint #%d?"), |
ffce0d52 DJ |
1110 | b->owner->number); |
1111 | ||
876fa593 JK |
1112 | /* Performance optimization: any futher element can no longer affect BUF |
1113 | content. */ | |
1114 | ||
1115 | if (b->address >= bp_location_placed_address_before_address_max | |
1116 | && memaddr + len <= b->address | |
1117 | - bp_location_placed_address_before_address_max) | |
1118 | break; | |
1119 | ||
1120 | if (!bp_location_has_shadow (b)) | |
c5aa993b | 1121 | continue; |
6c95b8df PA |
1122 | if (!breakpoint_address_match (b->target_info.placed_address_space, 0, |
1123 | current_program_space->aspace, 0)) | |
1124 | continue; | |
1125 | ||
c5aa993b JM |
1126 | /* Addresses and length of the part of the breakpoint that |
1127 | we need to copy. */ | |
8181d85f DJ |
1128 | bp_addr = b->target_info.placed_address; |
1129 | bp_size = b->target_info.shadow_len; | |
8defab1a | 1130 | |
c5aa993b JM |
1131 | if (bp_addr + bp_size <= memaddr) |
1132 | /* The breakpoint is entirely before the chunk of memory we | |
1133 | are reading. */ | |
1134 | continue; | |
8defab1a | 1135 | |
c5aa993b JM |
1136 | if (bp_addr >= memaddr + len) |
1137 | /* The breakpoint is entirely after the chunk of memory we are | |
1138 | reading. */ | |
1139 | continue; | |
c5aa993b | 1140 | |
8defab1a DJ |
1141 | /* Offset within shadow_contents. */ |
1142 | if (bp_addr < memaddr) | |
1143 | { | |
1144 | /* Only copy the second part of the breakpoint. */ | |
1145 | bp_size -= memaddr - bp_addr; | |
1146 | bptoffset = memaddr - bp_addr; | |
1147 | bp_addr = memaddr; | |
1148 | } | |
c5aa993b | 1149 | |
8defab1a DJ |
1150 | if (bp_addr + bp_size > memaddr + len) |
1151 | { | |
1152 | /* Only copy the first part of the breakpoint. */ | |
1153 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1154 | } | |
c5aa993b | 1155 | |
8defab1a DJ |
1156 | memcpy (buf + bp_addr - memaddr, |
1157 | b->target_info.shadow_contents + bptoffset, bp_size); | |
c5aa993b | 1158 | } |
c906108c | 1159 | } |
c906108c | 1160 | \f |
c5aa993b | 1161 | |
687595f9 | 1162 | /* A wrapper function for inserting catchpoints. */ |
9cbc821d | 1163 | static void |
687595f9 DJ |
1164 | insert_catchpoint (struct ui_out *uo, void *args) |
1165 | { | |
1166 | struct breakpoint *b = (struct breakpoint *) args; | |
1167 | int val = -1; | |
1168 | ||
fe798b75 JB |
1169 | gdb_assert (b->type == bp_catchpoint); |
1170 | gdb_assert (b->ops != NULL && b->ops->insert != NULL); | |
1171 | ||
1172 | b->ops->insert (b); | |
687595f9 DJ |
1173 | } |
1174 | ||
60e1c644 PA |
1175 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1176 | ||
a5606eee VP |
1177 | static int |
1178 | is_hardware_watchpoint (struct breakpoint *bpt) | |
1179 | { | |
1180 | return (bpt->type == bp_hardware_watchpoint | |
1181 | || bpt->type == bp_read_watchpoint | |
1182 | || bpt->type == bp_access_watchpoint); | |
1183 | } | |
7270d8f2 | 1184 | |
60e1c644 PA |
1185 | /* Return true if BPT is of any watchpoint kind, hardware or |
1186 | software. */ | |
1187 | ||
1188 | static int | |
1189 | is_watchpoint (struct breakpoint *bpt) | |
1190 | { | |
1191 | return (is_hardware_watchpoint (bpt) | |
1192 | || bpt->type == bp_watchpoint); | |
1193 | } | |
1194 | ||
fa4727a6 DJ |
1195 | /* Find the current value of a watchpoint on EXP. Return the value in |
1196 | *VALP and *RESULTP and the chain of intermediate and final values | |
1197 | in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does | |
1198 | not need them. | |
1199 | ||
ccc57cf9 | 1200 | If a memory error occurs while evaluating the expression, *RESULTP will |
fa4727a6 DJ |
1201 | be set to NULL. *RESULTP may be a lazy value, if the result could |
1202 | not be read from memory. It is used to determine whether a value | |
1203 | is user-specified (we should watch the whole value) or intermediate | |
1204 | (we should watch only the bit used to locate the final value). | |
1205 | ||
1206 | If the final value, or any intermediate value, could not be read | |
1207 | from memory, *VALP will be set to NULL. *VAL_CHAIN will still be | |
1208 | set to any referenced values. *VALP will never be a lazy value. | |
1209 | This is the value which we store in struct breakpoint. | |
1210 | ||
1211 | If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the | |
1212 | value chain. The caller must free the values individually. If | |
1213 | VAL_CHAIN is NULL, all generated values will be left on the value | |
1214 | chain. */ | |
1215 | ||
1216 | static void | |
1217 | fetch_watchpoint_value (struct expression *exp, struct value **valp, | |
1218 | struct value **resultp, struct value **val_chain) | |
1219 | { | |
1220 | struct value *mark, *new_mark, *result; | |
ccc57cf9 | 1221 | volatile struct gdb_exception ex; |
fa4727a6 DJ |
1222 | |
1223 | *valp = NULL; | |
1224 | if (resultp) | |
1225 | *resultp = NULL; | |
1226 | if (val_chain) | |
1227 | *val_chain = NULL; | |
1228 | ||
1229 | /* Evaluate the expression. */ | |
1230 | mark = value_mark (); | |
1231 | result = NULL; | |
ccc57cf9 PA |
1232 | |
1233 | TRY_CATCH (ex, RETURN_MASK_ALL) | |
1234 | { | |
1235 | result = evaluate_expression (exp); | |
1236 | } | |
1237 | if (ex.reason < 0) | |
1238 | { | |
1239 | /* Ignore memory errors, we want watchpoints pointing at | |
1240 | inaccessible memory to still be created; otherwise, throw the | |
1241 | error to some higher catcher. */ | |
1242 | switch (ex.error) | |
1243 | { | |
1244 | case MEMORY_ERROR: | |
1245 | break; | |
1246 | default: | |
1247 | throw_exception (ex); | |
1248 | break; | |
1249 | } | |
1250 | } | |
1251 | ||
fa4727a6 DJ |
1252 | new_mark = value_mark (); |
1253 | if (mark == new_mark) | |
1254 | return; | |
1255 | if (resultp) | |
1256 | *resultp = result; | |
1257 | ||
1258 | /* Make sure it's not lazy, so that after the target stops again we | |
1259 | have a non-lazy previous value to compare with. */ | |
1260 | if (result != NULL | |
1261 | && (!value_lazy (result) || gdb_value_fetch_lazy (result))) | |
1262 | *valp = result; | |
1263 | ||
1264 | if (val_chain) | |
1265 | { | |
1266 | /* Return the chain of intermediate values. We use this to | |
1267 | decide which addresses to watch. */ | |
1268 | *val_chain = new_mark; | |
1269 | value_release_to_mark (mark); | |
1270 | } | |
1271 | } | |
1272 | ||
f6bc2008 PA |
1273 | /* Assuming that B is a watchpoint: returns true if the current thread |
1274 | and its running state are safe to evaluate or update watchpoint B. | |
1275 | Watchpoints on local expressions need to be evaluated in the | |
1276 | context of the thread that was current when the watchpoint was | |
1277 | created, and, that thread needs to be stopped to be able to select | |
1278 | the correct frame context. Watchpoints on global expressions can | |
1279 | be evaluated on any thread, and in any state. It is presently left | |
1280 | to the target allowing memory accesses when threads are | |
1281 | running. */ | |
1282 | ||
1283 | static int | |
1284 | watchpoint_in_thread_scope (struct breakpoint *b) | |
1285 | { | |
1286 | return (ptid_equal (b->watchpoint_thread, null_ptid) | |
1287 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1288 | && !is_executing (inferior_ptid))); | |
1289 | } | |
1290 | ||
567e1b4e JB |
1291 | /* Assuming that B is a watchpoint: |
1292 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1293 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1294 | - Evaluate the condition if there is one, and store the result |
1295 | in b->loc->cond. | |
a5606eee VP |
1296 | - Update the list of values that must be watched in B->loc. |
1297 | ||
bfa149ac | 1298 | If the watchpoint disposition is disp_del_at_next_stop, then do nothing. |
a79d3c27 JK |
1299 | If this is local watchpoint that is out of scope, delete it. |
1300 | ||
1301 | Even with `set breakpoint always-inserted on' the watchpoints are removed | |
1302 | + inserted on each stop here. Normal breakpoints must never be removed | |
1303 | because they might be missed by a running thread when debugging in non-stop | |
1304 | mode. On the other hand, hardware watchpoints (is_hardware_watchpoint; | |
1305 | processed here) are specific to each LWP since they are stored in each LWP's | |
1306 | hardware debug registers. Therefore, such LWP must be stopped first in | |
1307 | order to be able to modify its hardware watchpoints. | |
1308 | ||
1309 | Hardware watchpoints must be reset exactly once after being presented to the | |
1310 | user. It cannot be done sooner, because it would reset the data used to | |
1311 | present the watchpoint hit to the user. And it must not be done later | |
1312 | because it could display the same single watchpoint hit during multiple GDB | |
1313 | stops. Note that the latter is relevant only to the hardware watchpoint | |
1314 | types bp_read_watchpoint and bp_access_watchpoint. False hit by | |
1315 | bp_hardware_watchpoint is not user-visible - its hit is suppressed if the | |
1316 | memory content has not changed. | |
1317 | ||
1318 | The following constraints influence the location where we can reset hardware | |
1319 | watchpoints: | |
1320 | ||
1321 | * target_stopped_by_watchpoint and target_stopped_data_address are called | |
1322 | several times when GDB stops. | |
1323 | ||
1324 | [linux] | |
1325 | * Multiple hardware watchpoints can be hit at the same time, causing GDB to | |
1326 | stop. GDB only presents one hardware watchpoint hit at a time as the | |
1327 | reason for stopping, and all the other hits are presented later, one after | |
1328 | the other, each time the user requests the execution to be resumed. | |
1329 | Execution is not resumed for the threads still having pending hit event | |
1330 | stored in LWP_INFO->STATUS. While the watchpoint is already removed from | |
1331 | the inferior on the first stop the thread hit event is kept being reported | |
1332 | from its cached value by linux_nat_stopped_data_address until the real | |
1333 | thread resume happens after the watchpoint gets presented and thus its | |
1334 | LWP_INFO->STATUS gets reset. | |
1335 | ||
1336 | Therefore the hardware watchpoint hit can get safely reset on the watchpoint | |
1337 | removal from inferior. */ | |
1338 | ||
b40ce68a | 1339 | static void |
a5606eee | 1340 | update_watchpoint (struct breakpoint *b, int reparse) |
7270d8f2 | 1341 | { |
a5606eee | 1342 | int within_current_scope; |
a5606eee VP |
1343 | struct frame_id saved_frame_id; |
1344 | struct bp_location *loc; | |
66076460 | 1345 | int frame_saved; |
a5606eee VP |
1346 | bpstat bs; |
1347 | ||
f6bc2008 PA |
1348 | /* If this is a local watchpoint, we only want to check if the |
1349 | watchpoint frame is in scope if the current thread is the thread | |
1350 | that was used to create the watchpoint. */ | |
1351 | if (!watchpoint_in_thread_scope (b)) | |
1352 | return; | |
1353 | ||
876fa593 | 1354 | /* We don't free locations. They are stored in bp_location array and |
567e1b4e JB |
1355 | update_global_locations will eventually delete them and remove |
1356 | breakpoints if needed. */ | |
a5606eee VP |
1357 | b->loc = NULL; |
1358 | ||
1359 | if (b->disposition == disp_del_at_next_stop) | |
1360 | return; | |
1361 | ||
66076460 | 1362 | frame_saved = 0; |
a5606eee VP |
1363 | |
1364 | /* Determine if the watchpoint is within scope. */ | |
1365 | if (b->exp_valid_block == NULL) | |
1366 | within_current_scope = 1; | |
1367 | else | |
1368 | { | |
1369 | struct frame_info *fi; | |
66076460 DJ |
1370 | |
1371 | /* Save the current frame's ID so we can restore it after | |
1372 | evaluating the watchpoint expression on its own frame. */ | |
1373 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1374 | took a frame parameter, so that we didn't have to change the | |
1375 | selected frame. */ | |
1376 | frame_saved = 1; | |
1377 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1378 | ||
a5606eee VP |
1379 | fi = frame_find_by_id (b->watchpoint_frame); |
1380 | within_current_scope = (fi != NULL); | |
1381 | if (within_current_scope) | |
1382 | select_frame (fi); | |
1383 | } | |
1384 | ||
1385 | if (within_current_scope && reparse) | |
1386 | { | |
1387 | char *s; | |
1388 | if (b->exp) | |
1389 | { | |
1390 | xfree (b->exp); | |
1391 | b->exp = NULL; | |
1392 | } | |
1393 | s = b->exp_string; | |
1394 | b->exp = parse_exp_1 (&s, b->exp_valid_block, 0); | |
1395 | /* If the meaning of expression itself changed, the old value is | |
1396 | no longer relevant. We don't want to report a watchpoint hit | |
1397 | to the user when the old value and the new value may actually | |
1398 | be completely different objects. */ | |
1399 | value_free (b->val); | |
fa4727a6 DJ |
1400 | b->val = NULL; |
1401 | b->val_valid = 0; | |
60e1c644 PA |
1402 | |
1403 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1404 | expression is stored in the breakpoint object, not in the | |
1405 | locations (re)created below. */ | |
1406 | if (b->cond_string != NULL) | |
1407 | { | |
1408 | if (b->cond_exp != NULL) | |
1409 | { | |
1410 | xfree (b->cond_exp); | |
1411 | b->cond_exp = NULL; | |
1412 | } | |
1413 | ||
1414 | s = b->cond_string; | |
1415 | b->cond_exp = parse_exp_1 (&s, b->cond_exp_valid_block, 0); | |
1416 | } | |
a5606eee | 1417 | } |
a5606eee VP |
1418 | |
1419 | /* If we failed to parse the expression, for example because | |
1420 | it refers to a global variable in a not-yet-loaded shared library, | |
1421 | don't try to insert watchpoint. We don't automatically delete | |
1422 | such watchpoint, though, since failure to parse expression | |
1423 | is different from out-of-scope watchpoint. */ | |
2d134ed3 PA |
1424 | if ( !target_has_execution) |
1425 | { | |
1426 | /* Without execution, memory can't change. No use to try and | |
1427 | set watchpoint locations. The watchpoint will be reset when | |
1428 | the target gains execution, through breakpoint_re_set. */ | |
1429 | } | |
1430 | else if (within_current_scope && b->exp) | |
a5606eee | 1431 | { |
fa4727a6 | 1432 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1433 | struct program_space *frame_pspace; |
a5606eee | 1434 | |
fa4727a6 | 1435 | fetch_watchpoint_value (b->exp, &v, &result, &val_chain); |
a5606eee | 1436 | |
a5606eee VP |
1437 | /* Avoid setting b->val if it's already set. The meaning of |
1438 | b->val is 'the last value' user saw, and we should update | |
1439 | it only if we reported that last value to user. As it | |
1440 | happens, the code that reports it updates b->val directly. */ | |
fa4727a6 DJ |
1441 | if (!b->val_valid) |
1442 | { | |
1443 | b->val = v; | |
1444 | b->val_valid = 1; | |
1445 | } | |
a5606eee | 1446 | |
db2ad4c3 JK |
1447 | /* Change the type of breakpoint between hardware assisted or an |
1448 | ordinary watchpoint depending on the hardware support and free | |
1449 | hardware slots. REPARSE is set when the inferior is started. */ | |
1450 | if ((b->type == bp_watchpoint || b->type == bp_hardware_watchpoint) | |
1451 | && reparse) | |
1452 | { | |
ca2d49e8 | 1453 | int i, mem_cnt, other_type_used; |
db2ad4c3 | 1454 | |
7b838ca2 TJB |
1455 | /* We need to determine how many resources are already used |
1456 | for all other hardware watchpoints to see if we still have | |
1457 | enough resources to also fit this watchpoint in as well. | |
1458 | To avoid the hw_watchpoint_used_count call below from counting | |
1459 | this watchpoint, make sure that it is marked as a software | |
1460 | watchpoint. */ | |
1461 | b->type = bp_watchpoint; | |
db2ad4c3 JK |
1462 | i = hw_watchpoint_used_count (bp_hardware_watchpoint, |
1463 | &other_type_used); | |
1464 | mem_cnt = can_use_hardware_watchpoint (val_chain); | |
1465 | ||
ca2d49e8 | 1466 | if (!mem_cnt) |
db2ad4c3 JK |
1467 | b->type = bp_watchpoint; |
1468 | else | |
ca2d49e8 | 1469 | { |
d92524f1 | 1470 | int target_resources_ok = target_can_use_hardware_watchpoint |
ca2d49e8 SL |
1471 | (bp_hardware_watchpoint, i + mem_cnt, other_type_used); |
1472 | if (target_resources_ok <= 0) | |
1473 | b->type = bp_watchpoint; | |
1474 | else | |
1475 | b->type = bp_hardware_watchpoint; | |
1476 | } | |
db2ad4c3 JK |
1477 | } |
1478 | ||
2d134ed3 PA |
1479 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1480 | ||
a5606eee | 1481 | /* Look at each value on the value chain. */ |
fa4727a6 | 1482 | for (v = val_chain; v; v = next) |
a5606eee VP |
1483 | { |
1484 | /* If it's a memory location, and GDB actually needed | |
1485 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1486 | must watch it. If the first value returned is |
1487 | still lazy, that means an error occurred reading it; | |
1488 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1489 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1490 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1491 | { |
1492 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1493 | |
a5606eee VP |
1494 | /* We only watch structs and arrays if user asked |
1495 | for it explicitly, never if they just happen to | |
1496 | appear in the middle of some value chain. */ | |
fa4727a6 | 1497 | if (v == result |
a5606eee VP |
1498 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1499 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1500 | { | |
1501 | CORE_ADDR addr; | |
1502 | int len, type; | |
1503 | struct bp_location *loc, **tmp; | |
1504 | ||
42ae5230 | 1505 | addr = value_address (v); |
a5606eee VP |
1506 | len = TYPE_LENGTH (value_type (v)); |
1507 | type = hw_write; | |
1508 | if (b->type == bp_read_watchpoint) | |
1509 | type = hw_read; | |
1510 | else if (b->type == bp_access_watchpoint) | |
1511 | type = hw_access; | |
1512 | ||
39d61571 | 1513 | loc = allocate_bp_location (b); |
a5606eee VP |
1514 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
1515 | ; | |
1516 | *tmp = loc; | |
a6d9a66e | 1517 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1518 | |
1519 | loc->pspace = frame_pspace; | |
a5606eee VP |
1520 | loc->address = addr; |
1521 | loc->length = len; | |
1522 | loc->watchpoint_type = type; | |
1523 | } | |
1524 | } | |
1525 | ||
1526 | next = value_next (v); | |
1527 | if (v != b->val) | |
1528 | value_free (v); | |
1529 | } | |
1530 | ||
c7437ca6 PA |
1531 | /* If a software watchpoint is not watching any memory, then the |
1532 | above left it without any location set up. But, | |
1533 | bpstat_stop_status requires a location to be able to report | |
1534 | stops, so make sure there's at least a dummy one. */ | |
1535 | if (b->type == bp_watchpoint && b->loc == NULL) | |
1536 | { | |
1537 | b->loc = allocate_bp_location (b); | |
1538 | b->loc->pspace = frame_pspace; | |
1539 | b->loc->address = -1; | |
1540 | b->loc->length = -1; | |
1541 | b->loc->watchpoint_type = -1; | |
1542 | } | |
a5606eee VP |
1543 | } |
1544 | else if (!within_current_scope) | |
7270d8f2 | 1545 | { |
a5606eee | 1546 | printf_filtered (_("\ |
567e1b4e | 1547 | Watchpoint %d deleted because the program has left the block \n\ |
a5606eee VP |
1548 | in which its expression is valid.\n"), |
1549 | b->number); | |
1550 | if (b->related_breakpoint) | |
60e1c644 PA |
1551 | { |
1552 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1553 | b->related_breakpoint->related_breakpoint = NULL; | |
1554 | b->related_breakpoint= NULL; | |
1555 | } | |
a5606eee | 1556 | b->disposition = disp_del_at_next_stop; |
7270d8f2 | 1557 | } |
a5606eee VP |
1558 | |
1559 | /* Restore the selected frame. */ | |
66076460 DJ |
1560 | if (frame_saved) |
1561 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
1562 | } |
1563 | ||
a5606eee | 1564 | |
74960c60 VP |
1565 | /* Returns 1 iff breakpoint location should be |
1566 | inserted in the inferior. */ | |
1567 | static int | |
1568 | should_be_inserted (struct bp_location *bpt) | |
1569 | { | |
1570 | if (!breakpoint_enabled (bpt->owner)) | |
1571 | return 0; | |
1572 | ||
1573 | if (bpt->owner->disposition == disp_del_at_next_stop) | |
1574 | return 0; | |
1575 | ||
1576 | if (!bpt->enabled || bpt->shlib_disabled || bpt->duplicate) | |
1577 | return 0; | |
1578 | ||
56710373 PA |
1579 | /* This is set for example, when we're attached to the parent of a |
1580 | vfork, and have detached from the child. The child is running | |
1581 | free, and we expect it to do an exec or exit, at which point the | |
1582 | OS makes the parent schedulable again (and the target reports | |
1583 | that the vfork is done). Until the child is done with the shared | |
1584 | memory region, do not insert breakpoints in the parent, otherwise | |
1585 | the child could still trip on the parent's breakpoints. Since | |
1586 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
1587 | if (bpt->pspace->breakpoints_not_allowed) | |
1588 | return 0; | |
1589 | ||
1042e4c0 SS |
1590 | /* Tracepoints are inserted by the target at a time of its choosing, |
1591 | not by us. */ | |
7a697b8d | 1592 | if (tracepoint_type (bpt->owner)) |
1042e4c0 SS |
1593 | return 0; |
1594 | ||
74960c60 VP |
1595 | return 1; |
1596 | } | |
1597 | ||
879bfdc2 DJ |
1598 | /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint. |
1599 | Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS, | |
fa3a767f | 1600 | and HW_BREAKPOINT_ERROR are used to report problems. |
879bfdc2 DJ |
1601 | |
1602 | NOTE drow/2003-09-09: This routine could be broken down to an object-style | |
1603 | method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 1604 | static int |
879bfdc2 | 1605 | insert_bp_location (struct bp_location *bpt, |
26bb91f3 | 1606 | struct ui_file *tmp_error_stream, |
fa3a767f | 1607 | int *disabled_breaks, |
26bb91f3 | 1608 | int *hw_breakpoint_error) |
879bfdc2 DJ |
1609 | { |
1610 | int val = 0; | |
1611 | ||
74960c60 | 1612 | if (!should_be_inserted (bpt) || bpt->inserted) |
879bfdc2 DJ |
1613 | return 0; |
1614 | ||
8181d85f DJ |
1615 | /* Initialize the target-specific information. */ |
1616 | memset (&bpt->target_info, 0, sizeof (bpt->target_info)); | |
1617 | bpt->target_info.placed_address = bpt->address; | |
6c95b8df | 1618 | bpt->target_info.placed_address_space = bpt->pspace->aspace; |
8181d85f | 1619 | |
879bfdc2 DJ |
1620 | if (bpt->loc_type == bp_loc_software_breakpoint |
1621 | || bpt->loc_type == bp_loc_hardware_breakpoint) | |
1622 | { | |
765dc015 VP |
1623 | if (bpt->owner->type != bp_hardware_breakpoint) |
1624 | { | |
1625 | /* If the explicitly specified breakpoint type | |
1626 | is not hardware breakpoint, check the memory map to see | |
1627 | if the breakpoint address is in read only memory or not. | |
1628 | Two important cases are: | |
1629 | - location type is not hardware breakpoint, memory | |
1630 | is readonly. We change the type of the location to | |
1631 | hardware breakpoint. | |
1632 | - location type is hardware breakpoint, memory is read-write. | |
1633 | This means we've previously made the location hardware one, but | |
1634 | then the memory map changed, so we undo. | |
1635 | ||
1636 | When breakpoints are removed, remove_breakpoints will | |
1637 | use location types we've just set here, the only possible | |
1638 | problem is that memory map has changed during running program, | |
1639 | but it's not going to work anyway with current gdb. */ | |
1640 | struct mem_region *mr | |
1641 | = lookup_mem_region (bpt->target_info.placed_address); | |
1642 | ||
1643 | if (mr) | |
1644 | { | |
1645 | if (automatic_hardware_breakpoints) | |
1646 | { | |
1647 | int changed = 0; | |
1648 | enum bp_loc_type new_type; | |
1649 | ||
1650 | if (mr->attrib.mode != MEM_RW) | |
1651 | new_type = bp_loc_hardware_breakpoint; | |
1652 | else | |
1653 | new_type = bp_loc_software_breakpoint; | |
1654 | ||
1655 | if (new_type != bpt->loc_type) | |
1656 | { | |
1657 | static int said = 0; | |
1658 | bpt->loc_type = new_type; | |
1659 | if (!said) | |
1660 | { | |
1661 | fprintf_filtered (gdb_stdout, _("\ | |
0767c96d | 1662 | Note: automatically using hardware breakpoints for read-only addresses.\n")); |
765dc015 VP |
1663 | said = 1; |
1664 | } | |
1665 | } | |
1666 | } | |
1667 | else if (bpt->loc_type == bp_loc_software_breakpoint | |
1668 | && mr->attrib.mode != MEM_RW) | |
1669 | warning (_("cannot set software breakpoint at readonly address %s"), | |
5af949e3 | 1670 | paddress (bpt->gdbarch, bpt->address)); |
765dc015 VP |
1671 | } |
1672 | } | |
1673 | ||
879bfdc2 DJ |
1674 | /* First check to see if we have to handle an overlay. */ |
1675 | if (overlay_debugging == ovly_off | |
1676 | || bpt->section == NULL | |
1677 | || !(section_is_overlay (bpt->section))) | |
1678 | { | |
1679 | /* No overlay handling: just set the breakpoint. */ | |
1680 | ||
1681 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
a6d9a66e UW |
1682 | val = target_insert_hw_breakpoint (bpt->gdbarch, |
1683 | &bpt->target_info); | |
879bfdc2 | 1684 | else |
a6d9a66e UW |
1685 | val = target_insert_breakpoint (bpt->gdbarch, |
1686 | &bpt->target_info); | |
879bfdc2 DJ |
1687 | } |
1688 | else | |
1689 | { | |
1690 | /* This breakpoint is in an overlay section. | |
1691 | Shall we set a breakpoint at the LMA? */ | |
1692 | if (!overlay_events_enabled) | |
1693 | { | |
1694 | /* Yes -- overlay event support is not active, | |
1695 | so we must try to set a breakpoint at the LMA. | |
1696 | This will not work for a hardware breakpoint. */ | |
1697 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
8a3fe4f8 | 1698 | warning (_("hardware breakpoint %d not supported in overlay!"), |
879bfdc2 DJ |
1699 | bpt->owner->number); |
1700 | else | |
1701 | { | |
1702 | CORE_ADDR addr = overlay_unmapped_address (bpt->address, | |
1703 | bpt->section); | |
1704 | /* Set a software (trap) breakpoint at the LMA. */ | |
8181d85f DJ |
1705 | bpt->overlay_target_info = bpt->target_info; |
1706 | bpt->overlay_target_info.placed_address = addr; | |
a6d9a66e UW |
1707 | val = target_insert_breakpoint (bpt->gdbarch, |
1708 | &bpt->overlay_target_info); | |
879bfdc2 | 1709 | if (val != 0) |
99361f52 DE |
1710 | fprintf_unfiltered (tmp_error_stream, |
1711 | "Overlay breakpoint %d failed: in ROM?\n", | |
879bfdc2 DJ |
1712 | bpt->owner->number); |
1713 | } | |
1714 | } | |
1715 | /* Shall we set a breakpoint at the VMA? */ | |
1716 | if (section_is_mapped (bpt->section)) | |
1717 | { | |
1718 | /* Yes. This overlay section is mapped into memory. */ | |
1719 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
a6d9a66e UW |
1720 | val = target_insert_hw_breakpoint (bpt->gdbarch, |
1721 | &bpt->target_info); | |
879bfdc2 | 1722 | else |
a6d9a66e UW |
1723 | val = target_insert_breakpoint (bpt->gdbarch, |
1724 | &bpt->target_info); | |
879bfdc2 DJ |
1725 | } |
1726 | else | |
1727 | { | |
1728 | /* No. This breakpoint will not be inserted. | |
1729 | No error, but do not mark the bp as 'inserted'. */ | |
1730 | return 0; | |
1731 | } | |
1732 | } | |
1733 | ||
1734 | if (val) | |
1735 | { | |
1736 | /* Can't set the breakpoint. */ | |
6c95b8df | 1737 | if (solib_name_from_address (bpt->pspace, bpt->address)) |
879bfdc2 DJ |
1738 | { |
1739 | /* See also: disable_breakpoints_in_shlibs. */ | |
1740 | val = 0; | |
0d381245 | 1741 | bpt->shlib_disabled = 1; |
879bfdc2 DJ |
1742 | if (!*disabled_breaks) |
1743 | { | |
1744 | fprintf_unfiltered (tmp_error_stream, | |
1745 | "Cannot insert breakpoint %d.\n", | |
1746 | bpt->owner->number); | |
1747 | fprintf_unfiltered (tmp_error_stream, | |
1748 | "Temporarily disabling shared library breakpoints:\n"); | |
1749 | } | |
1750 | *disabled_breaks = 1; | |
1751 | fprintf_unfiltered (tmp_error_stream, | |
1752 | "breakpoint #%d\n", bpt->owner->number); | |
1753 | } | |
1754 | else | |
879bfdc2 | 1755 | { |
879bfdc2 DJ |
1756 | if (bpt->loc_type == bp_loc_hardware_breakpoint) |
1757 | { | |
1758 | *hw_breakpoint_error = 1; | |
1759 | fprintf_unfiltered (tmp_error_stream, | |
1760 | "Cannot insert hardware breakpoint %d.\n", | |
1761 | bpt->owner->number); | |
1762 | } | |
1763 | else | |
1764 | { | |
1765 | fprintf_unfiltered (tmp_error_stream, | |
1766 | "Cannot insert breakpoint %d.\n", | |
1767 | bpt->owner->number); | |
1768 | fprintf_filtered (tmp_error_stream, | |
1769 | "Error accessing memory address "); | |
5af949e3 UW |
1770 | fputs_filtered (paddress (bpt->gdbarch, bpt->address), |
1771 | tmp_error_stream); | |
879bfdc2 DJ |
1772 | fprintf_filtered (tmp_error_stream, ": %s.\n", |
1773 | safe_strerror (val)); | |
1774 | } | |
1775 | ||
1776 | } | |
1777 | } | |
1778 | else | |
1779 | bpt->inserted = 1; | |
1780 | ||
1781 | return val; | |
1782 | } | |
1783 | ||
1784 | else if (bpt->loc_type == bp_loc_hardware_watchpoint | |
1785 | /* NOTE drow/2003-09-08: This state only exists for removing | |
1786 | watchpoints. It's not clear that it's necessary... */ | |
1787 | && bpt->owner->disposition != disp_del_at_next_stop) | |
1788 | { | |
85d721b8 | 1789 | val = target_insert_watchpoint (bpt->address, |
a5606eee VP |
1790 | bpt->length, |
1791 | bpt->watchpoint_type); | |
85d721b8 PA |
1792 | |
1793 | /* If trying to set a read-watchpoint, and it turns out it's not | |
1794 | supported, try emulating one with an access watchpoint. */ | |
1795 | if (val == 1 && bpt->watchpoint_type == hw_read) | |
1796 | { | |
1797 | struct bp_location *loc, **loc_temp; | |
1798 | ||
1799 | /* But don't try to insert it, if there's already another | |
1800 | hw_access location that would be considered a duplicate | |
1801 | of this one. */ | |
1802 | ALL_BP_LOCATIONS (loc, loc_temp) | |
1803 | if (loc != bpt | |
1804 | && loc->watchpoint_type == hw_access | |
1805 | && watchpoint_locations_match (bpt, loc)) | |
1806 | { | |
1807 | bpt->duplicate = 1; | |
1808 | bpt->inserted = 1; | |
1809 | bpt->target_info = loc->target_info; | |
1810 | bpt->watchpoint_type = hw_access; | |
1811 | val = 0; | |
1812 | break; | |
1813 | } | |
1814 | ||
1815 | if (val == 1) | |
1816 | { | |
1817 | val = target_insert_watchpoint (bpt->address, | |
1818 | bpt->length, | |
1819 | hw_access); | |
1820 | if (val == 0) | |
1821 | bpt->watchpoint_type = hw_access; | |
1822 | } | |
1823 | } | |
1824 | ||
1825 | bpt->inserted = (val == 0); | |
879bfdc2 DJ |
1826 | } |
1827 | ||
fe798b75 | 1828 | else if (bpt->owner->type == bp_catchpoint) |
879bfdc2 | 1829 | { |
71fff37b AC |
1830 | struct gdb_exception e = catch_exception (uiout, insert_catchpoint, |
1831 | bpt->owner, RETURN_MASK_ERROR); | |
9cbc821d AC |
1832 | exception_fprintf (gdb_stderr, e, "warning: inserting catchpoint %d: ", |
1833 | bpt->owner->number); | |
1834 | if (e.reason < 0) | |
879bfdc2 DJ |
1835 | bpt->owner->enable_state = bp_disabled; |
1836 | else | |
1837 | bpt->inserted = 1; | |
1640b821 DJ |
1838 | |
1839 | /* We've already printed an error message if there was a problem | |
1840 | inserting this catchpoint, and we've disabled the catchpoint, | |
1841 | so just return success. */ | |
1842 | return 0; | |
879bfdc2 DJ |
1843 | } |
1844 | ||
1845 | return 0; | |
1846 | } | |
1847 | ||
6c95b8df PA |
1848 | /* This function is called when program space PSPACE is about to be |
1849 | deleted. It takes care of updating breakpoints to not reference | |
1850 | PSPACE anymore. */ | |
1851 | ||
1852 | void | |
1853 | breakpoint_program_space_exit (struct program_space *pspace) | |
1854 | { | |
1855 | struct breakpoint *b, *b_temp; | |
876fa593 | 1856 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
1857 | |
1858 | /* Remove any breakpoint that was set through this program space. */ | |
1859 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
1860 | { | |
1861 | if (b->pspace == pspace) | |
1862 | delete_breakpoint (b); | |
1863 | } | |
1864 | ||
1865 | /* Breakpoints set through other program spaces could have locations | |
1866 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 1867 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
1868 | { |
1869 | struct bp_location *tmp; | |
1870 | ||
1871 | if (loc->pspace == pspace) | |
1872 | { | |
1873 | if (loc->owner->loc == loc) | |
1874 | loc->owner->loc = loc->next; | |
1875 | else | |
1876 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
1877 | if (tmp->next == loc) | |
1878 | { | |
1879 | tmp->next = loc->next; | |
1880 | break; | |
1881 | } | |
1882 | } | |
1883 | } | |
1884 | ||
1885 | /* Now update the global location list to permanently delete the | |
1886 | removed locations above. */ | |
1887 | update_global_location_list (0); | |
1888 | } | |
1889 | ||
74960c60 VP |
1890 | /* Make sure all breakpoints are inserted in inferior. |
1891 | Throws exception on any error. | |
1892 | A breakpoint that is already inserted won't be inserted | |
1893 | again, so calling this function twice is safe. */ | |
1894 | void | |
1895 | insert_breakpoints (void) | |
1896 | { | |
1897 | struct breakpoint *bpt; | |
1898 | ||
1899 | ALL_BREAKPOINTS (bpt) | |
1900 | if (is_hardware_watchpoint (bpt)) | |
1901 | update_watchpoint (bpt, 0 /* don't reparse. */); | |
1902 | ||
b60e7edf | 1903 | update_global_location_list (1); |
74960c60 | 1904 | |
c35b1492 PA |
1905 | /* update_global_location_list does not insert breakpoints when |
1906 | always_inserted_mode is not enabled. Explicitly insert them | |
1907 | now. */ | |
1908 | if (!breakpoints_always_inserted_mode ()) | |
74960c60 VP |
1909 | insert_breakpoint_locations (); |
1910 | } | |
1911 | ||
c906108c SS |
1912 | /* insert_breakpoints is used when starting or continuing the program. |
1913 | remove_breakpoints is used when the program stops. | |
1914 | Both return zero if successful, | |
1915 | or an `errno' value if could not write the inferior. */ | |
1916 | ||
74960c60 VP |
1917 | static void |
1918 | insert_breakpoint_locations (void) | |
c906108c | 1919 | { |
a5606eee | 1920 | struct breakpoint *bpt; |
876fa593 | 1921 | struct bp_location *b, **bp_tmp; |
e236ba44 | 1922 | int error = 0; |
c906108c SS |
1923 | int val = 0; |
1924 | int disabled_breaks = 0; | |
81d0cc19 | 1925 | int hw_breakpoint_error = 0; |
c906108c | 1926 | |
81d0cc19 | 1927 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 1928 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 1929 | |
81d0cc19 GS |
1930 | /* Explicitly mark the warning -- this will only be printed if |
1931 | there was an error. */ | |
1932 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
1933 | |
1934 | save_current_space_and_thread (); | |
1935 | ||
876fa593 | 1936 | ALL_BP_LOCATIONS (b, bp_tmp) |
879bfdc2 | 1937 | { |
6c95b8df PA |
1938 | struct thread_info *tp; |
1939 | CORE_ADDR last_addr; | |
1940 | ||
74960c60 | 1941 | if (!should_be_inserted (b) || b->inserted) |
879bfdc2 DJ |
1942 | continue; |
1943 | ||
f365de73 AS |
1944 | /* There is no point inserting thread-specific breakpoints if the |
1945 | thread no longer exists. */ | |
1946 | if (b->owner->thread != -1 | |
1947 | && !valid_thread_id (b->owner->thread)) | |
1948 | continue; | |
1949 | ||
6c95b8df PA |
1950 | switch_to_program_space_and_thread (b->pspace); |
1951 | ||
1952 | /* For targets that support global breakpoints, there's no need | |
1953 | to select an inferior to insert breakpoint to. In fact, even | |
1954 | if we aren't attached to any process yet, we should still | |
1955 | insert breakpoints. */ | |
1956 | if (!gdbarch_has_global_breakpoints (target_gdbarch) | |
1957 | && ptid_equal (inferior_ptid, null_ptid)) | |
1958 | continue; | |
1959 | ||
879bfdc2 | 1960 | val = insert_bp_location (b, tmp_error_stream, |
fa3a767f | 1961 | &disabled_breaks, |
879bfdc2 DJ |
1962 | &hw_breakpoint_error); |
1963 | if (val) | |
e236ba44 | 1964 | error = val; |
879bfdc2 | 1965 | } |
c906108c | 1966 | |
a5606eee VP |
1967 | /* If we failed to insert all locations of a watchpoint, |
1968 | remove them, as half-inserted watchpoint is of limited use. */ | |
1969 | ALL_BREAKPOINTS (bpt) | |
1970 | { | |
1971 | int some_failed = 0; | |
1972 | struct bp_location *loc; | |
1973 | ||
1974 | if (!is_hardware_watchpoint (bpt)) | |
1975 | continue; | |
1976 | ||
d6b74ac4 | 1977 | if (!breakpoint_enabled (bpt)) |
a5606eee | 1978 | continue; |
74960c60 VP |
1979 | |
1980 | if (bpt->disposition == disp_del_at_next_stop) | |
1981 | continue; | |
a5606eee VP |
1982 | |
1983 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 1984 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
1985 | { |
1986 | some_failed = 1; | |
1987 | break; | |
1988 | } | |
1989 | if (some_failed) | |
1990 | { | |
1991 | for (loc = bpt->loc; loc; loc = loc->next) | |
1992 | if (loc->inserted) | |
1993 | remove_breakpoint (loc, mark_uninserted); | |
1994 | ||
1995 | hw_breakpoint_error = 1; | |
1996 | fprintf_unfiltered (tmp_error_stream, | |
1997 | "Could not insert hardware watchpoint %d.\n", | |
1998 | bpt->number); | |
1999 | error = -1; | |
2000 | } | |
2001 | } | |
2002 | ||
e236ba44 | 2003 | if (error) |
81d0cc19 GS |
2004 | { |
2005 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
2006 | message about possibly exhausted resources. */ | |
879bfdc2 | 2007 | if (hw_breakpoint_error) |
81d0cc19 | 2008 | { |
c6510018 MS |
2009 | fprintf_unfiltered (tmp_error_stream, |
2010 | "Could not insert hardware breakpoints:\n\ | |
2011 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 2012 | } |
81d0cc19 GS |
2013 | target_terminal_ours_for_output (); |
2014 | error_stream (tmp_error_stream); | |
2015 | } | |
f7545552 TT |
2016 | |
2017 | do_cleanups (cleanups); | |
c906108c SS |
2018 | } |
2019 | ||
c906108c | 2020 | int |
fba45db2 | 2021 | remove_breakpoints (void) |
c906108c | 2022 | { |
876fa593 | 2023 | struct bp_location *b, **bp_tmp; |
3a1bae8e | 2024 | int val = 0; |
c906108c | 2025 | |
876fa593 | 2026 | ALL_BP_LOCATIONS (b, bp_tmp) |
c5aa993b | 2027 | { |
0bde7532 | 2028 | if (b->inserted) |
3a1bae8e | 2029 | val |= remove_breakpoint (b, mark_uninserted); |
c5aa993b | 2030 | } |
3a1bae8e | 2031 | return val; |
c906108c SS |
2032 | } |
2033 | ||
6c95b8df PA |
2034 | /* Remove breakpoints of process PID. */ |
2035 | ||
2036 | int | |
2037 | remove_breakpoints_pid (int pid) | |
2038 | { | |
876fa593 | 2039 | struct bp_location *b, **b_tmp; |
6c95b8df PA |
2040 | int val; |
2041 | struct inferior *inf = find_inferior_pid (pid); | |
2042 | ||
876fa593 | 2043 | ALL_BP_LOCATIONS (b, b_tmp) |
6c95b8df PA |
2044 | { |
2045 | if (b->pspace != inf->pspace) | |
2046 | continue; | |
2047 | ||
2048 | if (b->inserted) | |
2049 | { | |
2050 | val = remove_breakpoint (b, mark_uninserted); | |
2051 | if (val != 0) | |
2052 | return val; | |
2053 | } | |
2054 | } | |
2055 | return 0; | |
2056 | } | |
2057 | ||
692590c1 | 2058 | int |
80ce1ecb | 2059 | remove_hw_watchpoints (void) |
692590c1 | 2060 | { |
876fa593 | 2061 | struct bp_location *b, **bp_tmp; |
3a1bae8e | 2062 | int val = 0; |
692590c1 | 2063 | |
876fa593 | 2064 | ALL_BP_LOCATIONS (b, bp_tmp) |
692590c1 | 2065 | { |
0bde7532 | 2066 | if (b->inserted && b->loc_type == bp_loc_hardware_watchpoint) |
3a1bae8e | 2067 | val |= remove_breakpoint (b, mark_uninserted); |
692590c1 | 2068 | } |
3a1bae8e | 2069 | return val; |
692590c1 MS |
2070 | } |
2071 | ||
c906108c | 2072 | int |
fba45db2 | 2073 | reattach_breakpoints (int pid) |
c906108c | 2074 | { |
6c95b8df | 2075 | struct cleanup *old_chain; |
876fa593 | 2076 | struct bp_location *b, **bp_tmp; |
c906108c | 2077 | int val; |
a4954f26 | 2078 | struct ui_file *tmp_error_stream = mem_fileopen (); |
fa3a767f | 2079 | int dummy1 = 0, dummy2 = 0; |
6c95b8df PA |
2080 | struct inferior *inf; |
2081 | struct thread_info *tp; | |
2082 | ||
2083 | tp = any_live_thread_of_process (pid); | |
2084 | if (tp == NULL) | |
2085 | return 1; | |
2086 | ||
2087 | inf = find_inferior_pid (pid); | |
2088 | old_chain = save_inferior_ptid (); | |
2089 | ||
2090 | inferior_ptid = tp->ptid; | |
a4954f26 DJ |
2091 | |
2092 | make_cleanup_ui_file_delete (tmp_error_stream); | |
c906108c | 2093 | |
876fa593 | 2094 | ALL_BP_LOCATIONS (b, bp_tmp) |
c5aa993b | 2095 | { |
6c95b8df PA |
2096 | if (b->pspace != inf->pspace) |
2097 | continue; | |
2098 | ||
0bde7532 | 2099 | if (b->inserted) |
c5aa993b | 2100 | { |
a4954f26 DJ |
2101 | b->inserted = 0; |
2102 | val = insert_bp_location (b, tmp_error_stream, | |
fa3a767f | 2103 | &dummy1, &dummy2); |
c5aa993b JM |
2104 | if (val != 0) |
2105 | { | |
ce696e05 | 2106 | do_cleanups (old_chain); |
c5aa993b JM |
2107 | return val; |
2108 | } | |
2109 | } | |
2110 | } | |
ce696e05 | 2111 | do_cleanups (old_chain); |
c906108c SS |
2112 | return 0; |
2113 | } | |
2114 | ||
e58b0e63 PA |
2115 | static int internal_breakpoint_number = -1; |
2116 | ||
e62c965a | 2117 | static struct breakpoint * |
a6d9a66e UW |
2118 | create_internal_breakpoint (struct gdbarch *gdbarch, |
2119 | CORE_ADDR address, enum bptype type) | |
e62c965a | 2120 | { |
e62c965a PP |
2121 | struct symtab_and_line sal; |
2122 | struct breakpoint *b; | |
2123 | ||
2124 | init_sal (&sal); /* initialize to zeroes */ | |
2125 | ||
2126 | sal.pc = address; | |
2127 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 2128 | sal.pspace = current_program_space; |
e62c965a | 2129 | |
a6d9a66e | 2130 | b = set_raw_breakpoint (gdbarch, sal, type); |
e62c965a PP |
2131 | b->number = internal_breakpoint_number--; |
2132 | b->disposition = disp_donttouch; | |
2133 | ||
2134 | return b; | |
2135 | } | |
2136 | ||
2137 | static void | |
69de3c6a | 2138 | create_overlay_event_breakpoint (char *func_name) |
e62c965a | 2139 | { |
69de3c6a | 2140 | struct objfile *objfile; |
e62c965a | 2141 | |
69de3c6a PP |
2142 | ALL_OBJFILES (objfile) |
2143 | { | |
2144 | struct breakpoint *b; | |
2145 | struct minimal_symbol *m; | |
2146 | ||
2147 | m = lookup_minimal_symbol_text (func_name, objfile); | |
2148 | if (m == NULL) | |
2149 | continue; | |
e62c965a | 2150 | |
a6d9a66e UW |
2151 | b = create_internal_breakpoint (get_objfile_arch (objfile), |
2152 | SYMBOL_VALUE_ADDRESS (m), | |
69de3c6a PP |
2153 | bp_overlay_event); |
2154 | b->addr_string = xstrdup (func_name); | |
e62c965a | 2155 | |
69de3c6a PP |
2156 | if (overlay_debugging == ovly_auto) |
2157 | { | |
2158 | b->enable_state = bp_enabled; | |
2159 | overlay_events_enabled = 1; | |
2160 | } | |
2161 | else | |
2162 | { | |
2163 | b->enable_state = bp_disabled; | |
2164 | overlay_events_enabled = 0; | |
2165 | } | |
e62c965a PP |
2166 | } |
2167 | update_global_location_list (1); | |
2168 | } | |
2169 | ||
0fd8e87f UW |
2170 | static void |
2171 | create_longjmp_master_breakpoint (char *func_name) | |
2172 | { | |
6c95b8df | 2173 | struct program_space *pspace; |
0fd8e87f | 2174 | struct objfile *objfile; |
6c95b8df PA |
2175 | struct cleanup *old_chain; |
2176 | ||
2177 | old_chain = save_current_program_space (); | |
0fd8e87f | 2178 | |
6c95b8df | 2179 | ALL_PSPACES (pspace) |
0fd8e87f UW |
2180 | ALL_OBJFILES (objfile) |
2181 | { | |
2182 | struct breakpoint *b; | |
2183 | struct minimal_symbol *m; | |
2184 | ||
2185 | if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile))) | |
2186 | continue; | |
2187 | ||
6c95b8df PA |
2188 | set_current_program_space (pspace); |
2189 | ||
0fd8e87f UW |
2190 | m = lookup_minimal_symbol_text (func_name, objfile); |
2191 | if (m == NULL) | |
2192 | continue; | |
2193 | ||
a6d9a66e UW |
2194 | b = create_internal_breakpoint (get_objfile_arch (objfile), |
2195 | SYMBOL_VALUE_ADDRESS (m), | |
0fd8e87f UW |
2196 | bp_longjmp_master); |
2197 | b->addr_string = xstrdup (func_name); | |
2198 | b->enable_state = bp_disabled; | |
2199 | } | |
2200 | update_global_location_list (1); | |
6c95b8df PA |
2201 | |
2202 | do_cleanups (old_chain); | |
0fd8e87f UW |
2203 | } |
2204 | ||
aa7d318d TT |
2205 | /* Create a master std::terminate breakpoint. The actual function |
2206 | looked for is named FUNC_NAME. */ | |
2207 | static void | |
2208 | create_std_terminate_master_breakpoint (const char *func_name) | |
2209 | { | |
2210 | struct program_space *pspace; | |
2211 | struct objfile *objfile; | |
2212 | struct cleanup *old_chain; | |
2213 | ||
2214 | old_chain = save_current_program_space (); | |
2215 | ||
2216 | ALL_PSPACES (pspace) | |
2217 | ALL_OBJFILES (objfile) | |
2218 | { | |
2219 | struct breakpoint *b; | |
2220 | struct minimal_symbol *m; | |
2221 | ||
2222 | set_current_program_space (pspace); | |
2223 | ||
2224 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
2225 | if (m == NULL || (MSYMBOL_TYPE (m) != mst_text | |
2226 | && MSYMBOL_TYPE (m) != mst_file_text)) | |
2227 | continue; | |
2228 | ||
2229 | b = create_internal_breakpoint (get_objfile_arch (objfile), | |
2230 | SYMBOL_VALUE_ADDRESS (m), | |
2231 | bp_std_terminate_master); | |
2232 | b->addr_string = xstrdup (func_name); | |
2233 | b->enable_state = bp_disabled; | |
2234 | } | |
2235 | update_global_location_list (1); | |
2236 | ||
2237 | do_cleanups (old_chain); | |
2238 | } | |
2239 | ||
c906108c | 2240 | void |
fba45db2 | 2241 | update_breakpoints_after_exec (void) |
c906108c | 2242 | { |
c5aa993b JM |
2243 | struct breakpoint *b; |
2244 | struct breakpoint *temp; | |
876fa593 | 2245 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 2246 | |
25b22b0a PA |
2247 | /* We're about to delete breakpoints from GDB's lists. If the |
2248 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
2249 | writing the breakpoints' "shadow contents" back into memory. The | |
2250 | "shadow contents" are NOT valid after an exec, so GDB should not | |
2251 | do that. Instead, the target is responsible from marking | |
2252 | breakpoints out as soon as it detects an exec. We don't do that | |
2253 | here instead, because there may be other attempts to delete | |
2254 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 2255 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
2256 | if (bploc->pspace == current_program_space) |
2257 | gdb_assert (!bploc->inserted); | |
c906108c SS |
2258 | |
2259 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b | 2260 | { |
6c95b8df PA |
2261 | if (b->pspace != current_program_space) |
2262 | continue; | |
2263 | ||
c5aa993b JM |
2264 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
2265 | if (b->type == bp_shlib_event) | |
2266 | { | |
2267 | delete_breakpoint (b); | |
2268 | continue; | |
2269 | } | |
c906108c | 2270 | |
4efc6507 DE |
2271 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
2272 | if (b->type == bp_jit_event) | |
2273 | { | |
2274 | delete_breakpoint (b); | |
2275 | continue; | |
2276 | } | |
2277 | ||
1900040c | 2278 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
2279 | as must overlay event and longjmp master breakpoints. */ |
2280 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
aa7d318d | 2281 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master) |
c4093a6a JM |
2282 | { |
2283 | delete_breakpoint (b); | |
2284 | continue; | |
2285 | } | |
2286 | ||
c5aa993b JM |
2287 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2288 | if (b->type == bp_step_resume) | |
2289 | { | |
2290 | delete_breakpoint (b); | |
2291 | continue; | |
2292 | } | |
2293 | ||
611c83ae PA |
2294 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
2295 | after an exec. */ | |
2296 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume) | |
2297 | { | |
2298 | delete_breakpoint (b); | |
2299 | continue; | |
2300 | } | |
2301 | ||
ce78b96d JB |
2302 | if (b->type == bp_catchpoint) |
2303 | { | |
2304 | /* For now, none of the bp_catchpoint breakpoints need to | |
2305 | do anything at this point. In the future, if some of | |
2306 | the catchpoints need to something, we will need to add | |
2307 | a new method, and call this method from here. */ | |
2308 | continue; | |
2309 | } | |
2310 | ||
c5aa993b JM |
2311 | /* bp_finish is a special case. The only way we ought to be able |
2312 | to see one of these when an exec() has happened, is if the user | |
2313 | caught a vfork, and then said "finish". Ordinarily a finish just | |
2314 | carries them to the call-site of the current callee, by setting | |
2315 | a temporary bp there and resuming. But in this case, the finish | |
2316 | will carry them entirely through the vfork & exec. | |
2317 | ||
2318 | We don't want to allow a bp_finish to remain inserted now. But | |
2319 | we can't safely delete it, 'cause finish_command has a handle to | |
2320 | the bp on a bpstat, and will later want to delete it. There's a | |
2321 | chance (and I've seen it happen) that if we delete the bp_finish | |
2322 | here, that its storage will get reused by the time finish_command | |
2323 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
2324 | We really must allow finish_command to delete a bp_finish. | |
2325 | ||
53a5351d JM |
2326 | In the absense of a general solution for the "how do we know |
2327 | it's safe to delete something others may have handles to?" | |
2328 | problem, what we'll do here is just uninsert the bp_finish, and | |
2329 | let finish_command delete it. | |
2330 | ||
2331 | (We know the bp_finish is "doomed" in the sense that it's | |
2332 | momentary, and will be deleted as soon as finish_command sees | |
2333 | the inferior stopped. So it doesn't matter that the bp's | |
2334 | address is probably bogus in the new a.out, unlike e.g., the | |
2335 | solib breakpoints.) */ | |
c5aa993b | 2336 | |
c5aa993b JM |
2337 | if (b->type == bp_finish) |
2338 | { | |
2339 | continue; | |
2340 | } | |
2341 | ||
2342 | /* Without a symbolic address, we have little hope of the | |
2343 | pre-exec() address meaning the same thing in the post-exec() | |
2344 | a.out. */ | |
2345 | if (b->addr_string == NULL) | |
2346 | { | |
2347 | delete_breakpoint (b); | |
2348 | continue; | |
2349 | } | |
c5aa993b | 2350 | } |
1900040c | 2351 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
69de3c6a | 2352 | create_overlay_event_breakpoint ("_ovly_debug_event"); |
0fd8e87f UW |
2353 | create_longjmp_master_breakpoint ("longjmp"); |
2354 | create_longjmp_master_breakpoint ("_longjmp"); | |
2355 | create_longjmp_master_breakpoint ("siglongjmp"); | |
2356 | create_longjmp_master_breakpoint ("_siglongjmp"); | |
aa7d318d | 2357 | create_std_terminate_master_breakpoint ("std::terminate()"); |
c906108c SS |
2358 | } |
2359 | ||
2360 | int | |
fba45db2 | 2361 | detach_breakpoints (int pid) |
c906108c | 2362 | { |
876fa593 | 2363 | struct bp_location *b, **bp_tmp; |
3a1bae8e | 2364 | int val = 0; |
ce696e05 | 2365 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 2366 | struct inferior *inf = current_inferior (); |
c5aa993b | 2367 | |
39f77062 | 2368 | if (pid == PIDGET (inferior_ptid)) |
8a3fe4f8 | 2369 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 2370 | |
6c95b8df | 2371 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
ce696e05 | 2372 | inferior_ptid = pid_to_ptid (pid); |
876fa593 | 2373 | ALL_BP_LOCATIONS (b, bp_tmp) |
c5aa993b | 2374 | { |
6c95b8df PA |
2375 | if (b->pspace != inf->pspace) |
2376 | continue; | |
2377 | ||
0bde7532 | 2378 | if (b->inserted) |
6c95b8df | 2379 | val |= remove_breakpoint_1 (b, mark_inserted); |
c5aa993b | 2380 | } |
ce696e05 | 2381 | do_cleanups (old_chain); |
3a1bae8e | 2382 | return val; |
c906108c SS |
2383 | } |
2384 | ||
6c95b8df PA |
2385 | /* Remove the breakpoint location B from the current address space. |
2386 | Note that this is used to detach breakpoints from a child fork. | |
2387 | When we get here, the child isn't in the inferior list, and neither | |
2388 | do we have objects to represent its address space --- we should | |
2389 | *not* look at b->pspace->aspace here. */ | |
2390 | ||
c906108c | 2391 | static int |
6c95b8df | 2392 | remove_breakpoint_1 (struct bp_location *b, insertion_state_t is) |
c906108c SS |
2393 | { |
2394 | int val; | |
6c95b8df | 2395 | struct cleanup *old_chain; |
c5aa993b | 2396 | |
0bde7532 | 2397 | if (b->owner->enable_state == bp_permanent) |
c2c6d25f JM |
2398 | /* Permanent breakpoints cannot be inserted or removed. */ |
2399 | return 0; | |
2400 | ||
74960c60 VP |
2401 | /* The type of none suggests that owner is actually deleted. |
2402 | This should not ever happen. */ | |
2403 | gdb_assert (b->owner->type != bp_none); | |
0bde7532 DJ |
2404 | |
2405 | if (b->loc_type == bp_loc_software_breakpoint | |
2406 | || b->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 2407 | { |
c02f5703 MS |
2408 | /* "Normal" instruction breakpoint: either the standard |
2409 | trap-instruction bp (bp_breakpoint), or a | |
2410 | bp_hardware_breakpoint. */ | |
2411 | ||
2412 | /* First check to see if we have to handle an overlay. */ | |
2413 | if (overlay_debugging == ovly_off | |
0bde7532 DJ |
2414 | || b->section == NULL |
2415 | || !(section_is_overlay (b->section))) | |
c02f5703 MS |
2416 | { |
2417 | /* No overlay handling: just remove the breakpoint. */ | |
2418 | ||
0bde7532 | 2419 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e | 2420 | val = target_remove_hw_breakpoint (b->gdbarch, &b->target_info); |
c02f5703 | 2421 | else |
a6d9a66e | 2422 | val = target_remove_breakpoint (b->gdbarch, &b->target_info); |
c02f5703 | 2423 | } |
c906108c SS |
2424 | else |
2425 | { | |
c02f5703 MS |
2426 | /* This breakpoint is in an overlay section. |
2427 | Did we set a breakpoint at the LMA? */ | |
2428 | if (!overlay_events_enabled) | |
2429 | { | |
2430 | /* Yes -- overlay event support is not active, so we | |
2431 | should have set a breakpoint at the LMA. Remove it. | |
2432 | */ | |
c02f5703 MS |
2433 | /* Ignore any failures: if the LMA is in ROM, we will |
2434 | have already warned when we failed to insert it. */ | |
0bde7532 | 2435 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e UW |
2436 | target_remove_hw_breakpoint (b->gdbarch, |
2437 | &b->overlay_target_info); | |
c02f5703 | 2438 | else |
a6d9a66e UW |
2439 | target_remove_breakpoint (b->gdbarch, |
2440 | &b->overlay_target_info); | |
c02f5703 MS |
2441 | } |
2442 | /* Did we set a breakpoint at the VMA? | |
2443 | If so, we will have marked the breakpoint 'inserted'. */ | |
0bde7532 | 2444 | if (b->inserted) |
c906108c | 2445 | { |
c02f5703 MS |
2446 | /* Yes -- remove it. Previously we did not bother to |
2447 | remove the breakpoint if the section had been | |
2448 | unmapped, but let's not rely on that being safe. We | |
2449 | don't know what the overlay manager might do. */ | |
0bde7532 | 2450 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e UW |
2451 | val = target_remove_hw_breakpoint (b->gdbarch, |
2452 | &b->target_info); | |
aa67235e UW |
2453 | |
2454 | /* However, we should remove *software* breakpoints only | |
2455 | if the section is still mapped, or else we overwrite | |
2456 | wrong code with the saved shadow contents. */ | |
2457 | else if (section_is_mapped (b->section)) | |
a6d9a66e UW |
2458 | val = target_remove_breakpoint (b->gdbarch, |
2459 | &b->target_info); | |
aa67235e UW |
2460 | else |
2461 | val = 0; | |
c906108c | 2462 | } |
c02f5703 MS |
2463 | else |
2464 | { | |
2465 | /* No -- not inserted, so no need to remove. No error. */ | |
2466 | val = 0; | |
2467 | } | |
c906108c | 2468 | } |
879d1e6b UW |
2469 | |
2470 | /* In some cases, we might not be able to remove a breakpoint | |
2471 | in a shared library that has already been removed, but we | |
2472 | have not yet processed the shlib unload event. */ | |
6c95b8df | 2473 | if (val && solib_name_from_address (b->pspace, b->address)) |
879d1e6b UW |
2474 | val = 0; |
2475 | ||
c906108c SS |
2476 | if (val) |
2477 | return val; | |
0bde7532 | 2478 | b->inserted = (is == mark_inserted); |
c906108c | 2479 | } |
a5606eee | 2480 | else if (b->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 2481 | { |
278cd55f AC |
2482 | struct value *v; |
2483 | struct value *n; | |
c5aa993b | 2484 | |
0bde7532 | 2485 | b->inserted = (is == mark_inserted); |
a5606eee VP |
2486 | val = target_remove_watchpoint (b->address, b->length, |
2487 | b->watchpoint_type); | |
2e70b7b9 | 2488 | |
c906108c | 2489 | /* Failure to remove any of the hardware watchpoints comes here. */ |
0bde7532 | 2490 | if ((is == mark_uninserted) && (b->inserted)) |
8a3fe4f8 | 2491 | warning (_("Could not remove hardware watchpoint %d."), |
0bde7532 | 2492 | b->owner->number); |
c906108c | 2493 | } |
ce78b96d JB |
2494 | else if (b->owner->type == bp_catchpoint |
2495 | && breakpoint_enabled (b->owner) | |
2496 | && !b->duplicate) | |
2497 | { | |
2498 | gdb_assert (b->owner->ops != NULL && b->owner->ops->remove != NULL); | |
2499 | ||
2500 | val = b->owner->ops->remove (b->owner); | |
2501 | if (val) | |
2502 | return val; | |
2503 | b->inserted = (is == mark_inserted); | |
2504 | } | |
c906108c SS |
2505 | |
2506 | return 0; | |
2507 | } | |
2508 | ||
6c95b8df PA |
2509 | static int |
2510 | remove_breakpoint (struct bp_location *b, insertion_state_t is) | |
2511 | { | |
2512 | int ret; | |
2513 | struct cleanup *old_chain; | |
2514 | ||
2515 | if (b->owner->enable_state == bp_permanent) | |
2516 | /* Permanent breakpoints cannot be inserted or removed. */ | |
2517 | return 0; | |
2518 | ||
2519 | /* The type of none suggests that owner is actually deleted. | |
2520 | This should not ever happen. */ | |
2521 | gdb_assert (b->owner->type != bp_none); | |
2522 | ||
2523 | old_chain = save_current_space_and_thread (); | |
2524 | ||
2525 | switch_to_program_space_and_thread (b->pspace); | |
2526 | ||
2527 | ret = remove_breakpoint_1 (b, is); | |
2528 | ||
2529 | do_cleanups (old_chain); | |
2530 | return ret; | |
2531 | } | |
2532 | ||
c906108c SS |
2533 | /* Clear the "inserted" flag in all breakpoints. */ |
2534 | ||
25b22b0a | 2535 | void |
fba45db2 | 2536 | mark_breakpoints_out (void) |
c906108c | 2537 | { |
876fa593 | 2538 | struct bp_location *bpt, **bptp_tmp; |
c906108c | 2539 | |
876fa593 | 2540 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
6c95b8df PA |
2541 | if (bpt->pspace == current_program_space) |
2542 | bpt->inserted = 0; | |
c906108c SS |
2543 | } |
2544 | ||
53a5351d JM |
2545 | /* Clear the "inserted" flag in all breakpoints and delete any |
2546 | breakpoints which should go away between runs of the program. | |
c906108c SS |
2547 | |
2548 | Plus other such housekeeping that has to be done for breakpoints | |
2549 | between runs. | |
2550 | ||
53a5351d JM |
2551 | Note: this function gets called at the end of a run (by |
2552 | generic_mourn_inferior) and when a run begins (by | |
2553 | init_wait_for_inferior). */ | |
c906108c SS |
2554 | |
2555 | ||
2556 | ||
2557 | void | |
fba45db2 | 2558 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 2559 | { |
52f0bd74 | 2560 | struct breakpoint *b, *temp; |
876fa593 | 2561 | struct bp_location *bpt, **bptp_tmp; |
1c5cfe86 | 2562 | int ix; |
6c95b8df | 2563 | struct program_space *pspace = current_program_space; |
c906108c | 2564 | |
50c71eaf PA |
2565 | /* If breakpoint locations are shared across processes, then there's |
2566 | nothing to do. */ | |
2567c7d9 | 2567 | if (gdbarch_has_global_breakpoints (target_gdbarch)) |
50c71eaf PA |
2568 | return; |
2569 | ||
876fa593 | 2570 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
6c95b8df PA |
2571 | { |
2572 | if (bpt->pspace == pspace | |
2573 | && bpt->owner->enable_state != bp_permanent) | |
514f746b | 2574 | bpt->inserted = 0; |
6c95b8df | 2575 | } |
075f6582 | 2576 | |
c906108c | 2577 | ALL_BREAKPOINTS_SAFE (b, temp) |
c5aa993b | 2578 | { |
6c95b8df PA |
2579 | if (b->loc && b->loc->pspace != pspace) |
2580 | continue; | |
2581 | ||
c5aa993b JM |
2582 | switch (b->type) |
2583 | { | |
2584 | case bp_call_dummy: | |
c906108c | 2585 | |
c5aa993b | 2586 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
2587 | cause problems when the inferior is rerun, so we better get |
2588 | rid of it. */ | |
2589 | ||
2590 | case bp_watchpoint_scope: | |
2591 | ||
2592 | /* Also get rid of scope breakpoints. */ | |
2593 | ||
2594 | case bp_shlib_event: | |
2595 | ||
2596 | /* Also remove solib event breakpoints. Their addresses may | |
2597 | have changed since the last time we ran the program. | |
2598 | Actually we may now be debugging against different target; | |
2599 | and so the solib backend that installed this breakpoint may | |
2600 | not be used in by the target. E.g., | |
2601 | ||
2602 | (gdb) file prog-linux | |
2603 | (gdb) run # native linux target | |
2604 | ... | |
2605 | (gdb) kill | |
2606 | (gdb) file prog-win.exe | |
2607 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
2608 | */ | |
c906108c | 2609 | |
c5aa993b JM |
2610 | delete_breakpoint (b); |
2611 | break; | |
c906108c | 2612 | |
c5aa993b JM |
2613 | case bp_watchpoint: |
2614 | case bp_hardware_watchpoint: | |
2615 | case bp_read_watchpoint: | |
2616 | case bp_access_watchpoint: | |
c906108c | 2617 | |
c5aa993b JM |
2618 | /* Likewise for watchpoints on local expressions. */ |
2619 | if (b->exp_valid_block != NULL) | |
2620 | delete_breakpoint (b); | |
967af18d | 2621 | else if (context == inf_starting) |
c860120c PM |
2622 | { |
2623 | /* Reset val field to force reread of starting value | |
2624 | in insert_breakpoints. */ | |
2625 | if (b->val) | |
2626 | value_free (b->val); | |
2627 | b->val = NULL; | |
fa4727a6 | 2628 | b->val_valid = 0; |
c860120c | 2629 | } |
c5aa993b JM |
2630 | break; |
2631 | default: | |
c5aa993b JM |
2632 | break; |
2633 | } | |
2634 | } | |
1c5cfe86 PA |
2635 | |
2636 | /* Get rid of the moribund locations. */ | |
2637 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bpt); ++ix) | |
2638 | free_bp_location (bpt); | |
2639 | VEC_free (bp_location_p, moribund_locations); | |
c906108c SS |
2640 | } |
2641 | ||
6c95b8df PA |
2642 | /* These functions concern about actual breakpoints inserted in the |
2643 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
2644 | we need to hop over the bkpt --- so we check for address space | |
2645 | match, not program space. */ | |
2646 | ||
c2c6d25f JM |
2647 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
2648 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
2649 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
2650 | permanent breakpoint. | |
2651 | - When continuing from a location with an ordinary breakpoint, we | |
2652 | actually single step once before calling insert_breakpoints. | |
2653 | - When continuing from a localion with a permanent breakpoint, we | |
2654 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by | |
2655 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 2656 | |
c2c6d25f | 2657 | enum breakpoint_here |
6c95b8df | 2658 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 2659 | { |
876fa593 | 2660 | struct bp_location *bpt, **bptp_tmp; |
c2c6d25f | 2661 | int any_breakpoint_here = 0; |
c906108c | 2662 | |
876fa593 | 2663 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
075f6582 DJ |
2664 | { |
2665 | if (bpt->loc_type != bp_loc_software_breakpoint | |
2666 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
2667 | continue; | |
2668 | ||
468d015d | 2669 | if ((breakpoint_enabled (bpt->owner) |
075f6582 | 2670 | || bpt->owner->enable_state == bp_permanent) |
6c95b8df PA |
2671 | && breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2672 | aspace, pc)) | |
075f6582 DJ |
2673 | { |
2674 | if (overlay_debugging | |
2675 | && section_is_overlay (bpt->section) | |
2676 | && !section_is_mapped (bpt->section)) | |
2677 | continue; /* unmapped overlay -- can't be a match */ | |
2678 | else if (bpt->owner->enable_state == bp_permanent) | |
2679 | return permanent_breakpoint_here; | |
2680 | else | |
2681 | any_breakpoint_here = 1; | |
2682 | } | |
2683 | } | |
c906108c | 2684 | |
c2c6d25f | 2685 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
2686 | } |
2687 | ||
1c5cfe86 PA |
2688 | /* Return true if there's a moribund breakpoint at PC. */ |
2689 | ||
2690 | int | |
6c95b8df | 2691 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
2692 | { |
2693 | struct bp_location *loc; | |
2694 | int ix; | |
2695 | ||
2696 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
6c95b8df PA |
2697 | if (breakpoint_address_match (loc->pspace->aspace, loc->address, |
2698 | aspace, pc)) | |
1c5cfe86 PA |
2699 | return 1; |
2700 | ||
2701 | return 0; | |
2702 | } | |
c2c6d25f | 2703 | |
c36b740a | 2704 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
876fa593 | 2705 | inserted using regular breakpoint_chain / bp_location array mechanism. |
c36b740a VP |
2706 | This does not check for single-step breakpoints, which are |
2707 | inserted and removed using direct target manipulation. */ | |
c906108c SS |
2708 | |
2709 | int | |
6c95b8df | 2710 | regular_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 2711 | { |
876fa593 | 2712 | struct bp_location *bpt, **bptp_tmp; |
c906108c | 2713 | |
876fa593 | 2714 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
c5aa993b | 2715 | { |
075f6582 DJ |
2716 | if (bpt->loc_type != bp_loc_software_breakpoint |
2717 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
2718 | continue; | |
2719 | ||
2720 | if (bpt->inserted | |
6c95b8df PA |
2721 | && breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2722 | aspace, pc)) | |
075f6582 DJ |
2723 | { |
2724 | if (overlay_debugging | |
2725 | && section_is_overlay (bpt->section) | |
2726 | && !section_is_mapped (bpt->section)) | |
2727 | continue; /* unmapped overlay -- can't be a match */ | |
2728 | else | |
2729 | return 1; | |
2730 | } | |
c5aa993b | 2731 | } |
c36b740a VP |
2732 | return 0; |
2733 | } | |
2734 | ||
2735 | /* Returns non-zero iff there's either regular breakpoint | |
2736 | or a single step breakpoint inserted at PC. */ | |
2737 | ||
2738 | int | |
6c95b8df | 2739 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c36b740a | 2740 | { |
6c95b8df | 2741 | if (regular_breakpoint_inserted_here_p (aspace, pc)) |
c36b740a | 2742 | return 1; |
c906108c | 2743 | |
6c95b8df | 2744 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2745 | return 1; |
2746 | ||
c906108c SS |
2747 | return 0; |
2748 | } | |
2749 | ||
4fa8626c DJ |
2750 | /* This function returns non-zero iff there is a software breakpoint |
2751 | inserted at PC. */ | |
2752 | ||
2753 | int | |
6c95b8df | 2754 | software_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
4fa8626c | 2755 | { |
876fa593 | 2756 | struct bp_location *bpt, **bptp_tmp; |
4fa8626c DJ |
2757 | int any_breakpoint_here = 0; |
2758 | ||
876fa593 | 2759 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
4fa8626c DJ |
2760 | { |
2761 | if (bpt->loc_type != bp_loc_software_breakpoint) | |
2762 | continue; | |
2763 | ||
0d381245 | 2764 | if (bpt->inserted |
6c95b8df PA |
2765 | && breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2766 | aspace, pc)) | |
4fa8626c DJ |
2767 | { |
2768 | if (overlay_debugging | |
2769 | && section_is_overlay (bpt->section) | |
2770 | && !section_is_mapped (bpt->section)) | |
2771 | continue; /* unmapped overlay -- can't be a match */ | |
2772 | else | |
2773 | return 1; | |
2774 | } | |
2775 | } | |
2776 | ||
1aafd4da | 2777 | /* Also check for software single-step breakpoints. */ |
6c95b8df | 2778 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2779 | return 1; |
2780 | ||
4fa8626c DJ |
2781 | return 0; |
2782 | } | |
2783 | ||
9093389c PA |
2784 | int |
2785 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
2786 | CORE_ADDR addr, ULONGEST len) | |
2787 | { | |
2788 | struct breakpoint *bpt; | |
2789 | ||
2790 | ALL_BREAKPOINTS (bpt) | |
2791 | { | |
2792 | struct bp_location *loc; | |
2793 | ||
2794 | if (bpt->type != bp_hardware_watchpoint | |
2795 | && bpt->type != bp_access_watchpoint) | |
2796 | continue; | |
2797 | ||
2798 | if (!breakpoint_enabled (bpt)) | |
2799 | continue; | |
2800 | ||
2801 | for (loc = bpt->loc; loc; loc = loc->next) | |
2802 | if (loc->pspace->aspace == aspace && loc->inserted) | |
2803 | { | |
2804 | CORE_ADDR l, h; | |
2805 | ||
2806 | /* Check for intersection. */ | |
2807 | l = max (loc->address, addr); | |
2808 | h = min (loc->address + loc->length, addr + len); | |
2809 | if (l < h) | |
2810 | return 1; | |
2811 | } | |
2812 | } | |
2813 | return 0; | |
2814 | } | |
2815 | ||
075f6582 DJ |
2816 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
2817 | PC is valid for process/thread PTID. */ | |
c906108c SS |
2818 | |
2819 | int | |
6c95b8df PA |
2820 | breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc, |
2821 | ptid_t ptid) | |
c906108c | 2822 | { |
876fa593 | 2823 | struct bp_location *bpt, **bptp_tmp; |
4a306c9a | 2824 | /* The thread and task IDs associated to PTID, computed lazily. */ |
a6f1cd96 | 2825 | int thread = -1; |
4a306c9a | 2826 | int task = 0; |
a6f1cd96 | 2827 | |
876fa593 | 2828 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
c5aa993b | 2829 | { |
075f6582 DJ |
2830 | if (bpt->loc_type != bp_loc_software_breakpoint |
2831 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
2832 | continue; | |
2833 | ||
a6f1cd96 JB |
2834 | if (!breakpoint_enabled (bpt->owner) |
2835 | && bpt->owner->enable_state != bp_permanent) | |
2836 | continue; | |
2837 | ||
6c95b8df PA |
2838 | if (!breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2839 | aspace, pc)) | |
a6f1cd96 JB |
2840 | continue; |
2841 | ||
2842 | if (bpt->owner->thread != -1) | |
075f6582 | 2843 | { |
a6f1cd96 JB |
2844 | /* This is a thread-specific breakpoint. Check that ptid |
2845 | matches that thread. If thread hasn't been computed yet, | |
2846 | it is now time to do so. */ | |
2847 | if (thread == -1) | |
2848 | thread = pid_to_thread_id (ptid); | |
2849 | if (bpt->owner->thread != thread) | |
2850 | continue; | |
075f6582 | 2851 | } |
a6f1cd96 | 2852 | |
4a306c9a JB |
2853 | if (bpt->owner->task != 0) |
2854 | { | |
2855 | /* This is a task-specific breakpoint. Check that ptid | |
2856 | matches that task. If task hasn't been computed yet, | |
2857 | it is now time to do so. */ | |
2858 | if (task == 0) | |
2859 | task = ada_get_task_number (ptid); | |
2860 | if (bpt->owner->task != task) | |
2861 | continue; | |
2862 | } | |
2863 | ||
a6f1cd96 JB |
2864 | if (overlay_debugging |
2865 | && section_is_overlay (bpt->section) | |
2866 | && !section_is_mapped (bpt->section)) | |
2867 | continue; /* unmapped overlay -- can't be a match */ | |
2868 | ||
2869 | return 1; | |
c5aa993b | 2870 | } |
c906108c SS |
2871 | |
2872 | return 0; | |
2873 | } | |
c906108c | 2874 | \f |
c5aa993b | 2875 | |
c906108c SS |
2876 | /* bpstat stuff. External routines' interfaces are documented |
2877 | in breakpoint.h. */ | |
2878 | ||
2879 | int | |
fba45db2 | 2880 | ep_is_catchpoint (struct breakpoint *ep) |
c906108c | 2881 | { |
533be4dd | 2882 | return (ep->type == bp_catchpoint); |
c906108c SS |
2883 | } |
2884 | ||
198757a8 VP |
2885 | void |
2886 | bpstat_free (bpstat bs) | |
2887 | { | |
2888 | if (bs->old_val != NULL) | |
2889 | value_free (bs->old_val); | |
9add0f1b | 2890 | decref_counted_command_line (&bs->commands); |
198757a8 VP |
2891 | xfree (bs); |
2892 | } | |
2893 | ||
c906108c SS |
2894 | /* Clear a bpstat so that it says we are not at any breakpoint. |
2895 | Also free any storage that is part of a bpstat. */ | |
2896 | ||
2897 | void | |
fba45db2 | 2898 | bpstat_clear (bpstat *bsp) |
c906108c SS |
2899 | { |
2900 | bpstat p; | |
2901 | bpstat q; | |
2902 | ||
2903 | if (bsp == 0) | |
2904 | return; | |
2905 | p = *bsp; | |
2906 | while (p != NULL) | |
2907 | { | |
2908 | q = p->next; | |
198757a8 | 2909 | bpstat_free (p); |
c906108c SS |
2910 | p = q; |
2911 | } | |
2912 | *bsp = NULL; | |
2913 | } | |
2914 | ||
2915 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
2916 | is part of the bpstat is copied as well. */ | |
2917 | ||
2918 | bpstat | |
fba45db2 | 2919 | bpstat_copy (bpstat bs) |
c906108c SS |
2920 | { |
2921 | bpstat p = NULL; | |
2922 | bpstat tmp; | |
2923 | bpstat retval = NULL; | |
2924 | ||
2925 | if (bs == NULL) | |
2926 | return bs; | |
2927 | ||
2928 | for (; bs != NULL; bs = bs->next) | |
2929 | { | |
2930 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
2931 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 2932 | incref_counted_command_line (tmp->commands); |
31cc81e9 | 2933 | if (bs->old_val != NULL) |
3c3185ac JK |
2934 | { |
2935 | tmp->old_val = value_copy (bs->old_val); | |
2936 | release_value (tmp->old_val); | |
2937 | } | |
31cc81e9 | 2938 | |
c906108c SS |
2939 | if (p == NULL) |
2940 | /* This is the first thing in the chain. */ | |
2941 | retval = tmp; | |
2942 | else | |
2943 | p->next = tmp; | |
2944 | p = tmp; | |
2945 | } | |
2946 | p->next = NULL; | |
2947 | return retval; | |
2948 | } | |
2949 | ||
2950 | /* Find the bpstat associated with this breakpoint */ | |
2951 | ||
2952 | bpstat | |
fba45db2 | 2953 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 2954 | { |
c5aa993b JM |
2955 | if (bsp == NULL) |
2956 | return NULL; | |
c906108c | 2957 | |
c5aa993b JM |
2958 | for (; bsp != NULL; bsp = bsp->next) |
2959 | { | |
4f8d1dc6 | 2960 | if (bsp->breakpoint_at && bsp->breakpoint_at->owner == breakpoint) |
c5aa993b JM |
2961 | return bsp; |
2962 | } | |
c906108c SS |
2963 | return NULL; |
2964 | } | |
2965 | ||
2966 | /* Find a step_resume breakpoint associated with this bpstat. | |
2967 | (If there are multiple step_resume bp's on the list, this function | |
2968 | will arbitrarily pick one.) | |
2969 | ||
2970 | It is an error to use this function if BPSTAT doesn't contain a | |
2971 | step_resume breakpoint. | |
2972 | ||
2973 | See wait_for_inferior's use of this function. */ | |
2974 | struct breakpoint * | |
fba45db2 | 2975 | bpstat_find_step_resume_breakpoint (bpstat bsp) |
c906108c | 2976 | { |
8601f500 MS |
2977 | int current_thread; |
2978 | ||
8a3fe4f8 | 2979 | gdb_assert (bsp != NULL); |
c906108c | 2980 | |
8601f500 MS |
2981 | current_thread = pid_to_thread_id (inferior_ptid); |
2982 | ||
c906108c SS |
2983 | for (; bsp != NULL; bsp = bsp->next) |
2984 | { | |
059fb39f PM |
2985 | if ((bsp->breakpoint_at != NULL) |
2986 | && (bsp->breakpoint_at->owner->type == bp_step_resume) | |
2987 | && (bsp->breakpoint_at->owner->thread == current_thread | |
2988 | || bsp->breakpoint_at->owner->thread == -1)) | |
4f8d1dc6 | 2989 | return bsp->breakpoint_at->owner; |
c906108c SS |
2990 | } |
2991 | ||
8a3fe4f8 | 2992 | internal_error (__FILE__, __LINE__, _("No step_resume breakpoint found.")); |
c906108c SS |
2993 | } |
2994 | ||
2995 | ||
8671a17b | 2996 | /* Put in *NUM the breakpoint number of the first breakpoint we are stopped |
c906108c SS |
2997 | at. *BSP upon return is a bpstat which points to the remaining |
2998 | breakpoints stopped at (but which is not guaranteed to be good for | |
2999 | anything but further calls to bpstat_num). | |
8671a17b PA |
3000 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
3001 | Return -1 if stopped at a breakpoint that has been deleted since | |
3002 | we set it. | |
3003 | Return 1 otherwise. */ | |
c906108c SS |
3004 | |
3005 | int | |
8671a17b | 3006 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
3007 | { |
3008 | struct breakpoint *b; | |
3009 | ||
3010 | if ((*bsp) == NULL) | |
3011 | return 0; /* No more breakpoint values */ | |
8671a17b | 3012 | |
4f8d1dc6 VP |
3013 | /* We assume we'll never have several bpstats that |
3014 | correspond to a single breakpoint -- otherwise, | |
3015 | this function might return the same number more | |
3016 | than once and this will look ugly. */ | |
3017 | b = (*bsp)->breakpoint_at ? (*bsp)->breakpoint_at->owner : NULL; | |
8671a17b PA |
3018 | *bsp = (*bsp)->next; |
3019 | if (b == NULL) | |
3020 | return -1; /* breakpoint that's been deleted since */ | |
3021 | ||
3022 | *num = b->number; /* We have its number */ | |
3023 | return 1; | |
c906108c SS |
3024 | } |
3025 | ||
3026 | /* Modify BS so that the actions will not be performed. */ | |
3027 | ||
3028 | void | |
fba45db2 | 3029 | bpstat_clear_actions (bpstat bs) |
c906108c SS |
3030 | { |
3031 | for (; bs != NULL; bs = bs->next) | |
3032 | { | |
9add0f1b | 3033 | decref_counted_command_line (&bs->commands); |
dde2d684 | 3034 | bs->commands_left = NULL; |
c906108c SS |
3035 | if (bs->old_val != NULL) |
3036 | { | |
3037 | value_free (bs->old_val); | |
3038 | bs->old_val = NULL; | |
3039 | } | |
3040 | } | |
3041 | } | |
3042 | ||
f3b1572e PA |
3043 | /* Called when a command is about to proceed the inferior. */ |
3044 | ||
3045 | static void | |
3046 | breakpoint_about_to_proceed (void) | |
3047 | { | |
3048 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
3049 | { | |
3050 | struct thread_info *tp = inferior_thread (); | |
3051 | ||
3052 | /* Allow inferior function calls in breakpoint commands to not | |
3053 | interrupt the command list. When the call finishes | |
3054 | successfully, the inferior will be standing at the same | |
3055 | breakpoint as if nothing happened. */ | |
3056 | if (tp->in_infcall) | |
3057 | return; | |
3058 | } | |
3059 | ||
3060 | breakpoint_proceeded = 1; | |
3061 | } | |
3062 | ||
c906108c | 3063 | /* Stub for cleaning up our state if we error-out of a breakpoint command */ |
c906108c | 3064 | static void |
4efb68b1 | 3065 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
3066 | { |
3067 | executing_breakpoint_commands = 0; | |
3068 | } | |
3069 | ||
3070 | /* Execute all the commands associated with all the breakpoints at this | |
3071 | location. Any of these commands could cause the process to proceed | |
3072 | beyond this point, etc. We look out for such changes by checking | |
347bddb7 | 3073 | the global "breakpoint_proceeded" after each command. |
c906108c | 3074 | |
347bddb7 PA |
3075 | Returns true if a breakpoint command resumed the inferior. In that |
3076 | case, it is the caller's responsibility to recall it again with the | |
3077 | bpstat of the current thread. */ | |
3078 | ||
3079 | static int | |
3080 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
3081 | { |
3082 | bpstat bs; | |
3083 | struct cleanup *old_chain; | |
347bddb7 | 3084 | int again = 0; |
c906108c SS |
3085 | |
3086 | /* Avoid endless recursion if a `source' command is contained | |
3087 | in bs->commands. */ | |
3088 | if (executing_breakpoint_commands) | |
347bddb7 | 3089 | return 0; |
c906108c SS |
3090 | |
3091 | executing_breakpoint_commands = 1; | |
3092 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
3093 | ||
c906108c SS |
3094 | /* This pointer will iterate over the list of bpstat's. */ |
3095 | bs = *bsp; | |
3096 | ||
3097 | breakpoint_proceeded = 0; | |
3098 | for (; bs != NULL; bs = bs->next) | |
3099 | { | |
9add0f1b | 3100 | struct counted_command_line *ccmd; |
6c50ab1c JB |
3101 | struct command_line *cmd; |
3102 | struct cleanup *this_cmd_tree_chain; | |
3103 | ||
3104 | /* Take ownership of the BSP's command tree, if it has one. | |
3105 | ||
3106 | The command tree could legitimately contain commands like | |
3107 | 'step' and 'next', which call clear_proceed_status, which | |
3108 | frees stop_bpstat's command tree. To make sure this doesn't | |
3109 | free the tree we're executing out from under us, we need to | |
3110 | take ownership of the tree ourselves. Since a given bpstat's | |
3111 | commands are only executed once, we don't need to copy it; we | |
3112 | can clear the pointer in the bpstat, and make sure we free | |
3113 | the tree when we're done. */ | |
9add0f1b TT |
3114 | ccmd = bs->commands; |
3115 | bs->commands = NULL; | |
3116 | this_cmd_tree_chain | |
3117 | = make_cleanup_decref_counted_command_line (&ccmd); | |
3118 | cmd = bs->commands_left; | |
3119 | bs->commands_left = NULL; | |
6c50ab1c | 3120 | |
c906108c SS |
3121 | while (cmd != NULL) |
3122 | { | |
3123 | execute_control_command (cmd); | |
3124 | ||
3125 | if (breakpoint_proceeded) | |
3126 | break; | |
3127 | else | |
3128 | cmd = cmd->next; | |
3129 | } | |
6c50ab1c JB |
3130 | |
3131 | /* We can free this command tree now. */ | |
3132 | do_cleanups (this_cmd_tree_chain); | |
3133 | ||
c906108c | 3134 | if (breakpoint_proceeded) |
32c1e744 VP |
3135 | { |
3136 | if (target_can_async_p ()) | |
347bddb7 PA |
3137 | /* If we are in async mode, then the target might be still |
3138 | running, not stopped at any breakpoint, so nothing for | |
3139 | us to do here -- just return to the event loop. */ | |
3140 | ; | |
32c1e744 VP |
3141 | else |
3142 | /* In sync mode, when execute_control_command returns | |
3143 | we're already standing on the next breakpoint. | |
347bddb7 PA |
3144 | Breakpoint commands for that stop were not run, since |
3145 | execute_command does not run breakpoint commands -- | |
3146 | only command_line_handler does, but that one is not | |
3147 | involved in execution of breakpoint commands. So, we | |
3148 | can now execute breakpoint commands. It should be | |
3149 | noted that making execute_command do bpstat actions is | |
3150 | not an option -- in this case we'll have recursive | |
3151 | invocation of bpstat for each breakpoint with a | |
3152 | command, and can easily blow up GDB stack. Instead, we | |
3153 | return true, which will trigger the caller to recall us | |
3154 | with the new stop_bpstat. */ | |
3155 | again = 1; | |
3156 | break; | |
32c1e744 | 3157 | } |
c906108c | 3158 | } |
c2b8ed2c | 3159 | do_cleanups (old_chain); |
347bddb7 PA |
3160 | return again; |
3161 | } | |
3162 | ||
3163 | void | |
3164 | bpstat_do_actions (void) | |
3165 | { | |
3166 | /* Do any commands attached to breakpoint we are stopped at. */ | |
3167 | while (!ptid_equal (inferior_ptid, null_ptid) | |
3168 | && target_has_execution | |
3169 | && !is_exited (inferior_ptid) | |
3170 | && !is_executing (inferior_ptid)) | |
3171 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
3172 | and only return when it is stopped at the next breakpoint, we | |
3173 | keep doing breakpoint actions until it returns false to | |
3174 | indicate the inferior was not resumed. */ | |
3175 | if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat)) | |
3176 | break; | |
c906108c SS |
3177 | } |
3178 | ||
fa4727a6 DJ |
3179 | /* Print out the (old or new) value associated with a watchpoint. */ |
3180 | ||
3181 | static void | |
3182 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
3183 | { | |
3184 | if (val == NULL) | |
3185 | fprintf_unfiltered (stream, _("<unreadable>")); | |
3186 | else | |
79a45b7d TT |
3187 | { |
3188 | struct value_print_options opts; | |
3189 | get_user_print_options (&opts); | |
3190 | value_print (val, stream, &opts); | |
3191 | } | |
fa4727a6 DJ |
3192 | } |
3193 | ||
e514a9d6 | 3194 | /* This is the normal print function for a bpstat. In the future, |
c906108c | 3195 | much of this logic could (should?) be moved to bpstat_stop_status, |
e514a9d6 JM |
3196 | by having it set different print_it values. |
3197 | ||
3198 | Current scheme: When we stop, bpstat_print() is called. It loops | |
3199 | through the bpstat list of things causing this stop, calling the | |
3200 | print_bp_stop_message function on each one. The behavior of the | |
3201 | print_bp_stop_message function depends on the print_it field of | |
3202 | bpstat. If such field so indicates, call this function here. | |
3203 | ||
3204 | Return values from this routine (ultimately used by bpstat_print() | |
3205 | and normal_stop() to decide what to do): | |
3206 | PRINT_NOTHING: Means we already printed all we needed to print, | |
3207 | don't print anything else. | |
3208 | PRINT_SRC_ONLY: Means we printed something, and we do *not* desire | |
3209 | that something to be followed by a location. | |
3210 | PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire | |
3211 | that something to be followed by a location. | |
3212 | PRINT_UNKNOWN: Means we printed nothing or we need to do some more | |
3213 | analysis. */ | |
c906108c | 3214 | |
917317f4 | 3215 | static enum print_stop_action |
fba45db2 | 3216 | print_it_typical (bpstat bs) |
c906108c | 3217 | { |
f7545552 | 3218 | struct cleanup *old_chain; |
4f8d1dc6 | 3219 | struct breakpoint *b; |
89f9893c | 3220 | const struct bp_location *bl; |
8b93c638 | 3221 | struct ui_stream *stb; |
f7545552 TT |
3222 | int bp_temp = 0; |
3223 | enum print_stop_action result; | |
3224 | ||
c906108c SS |
3225 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
3226 | which has since been deleted. */ | |
e514a9d6 | 3227 | if (bs->breakpoint_at == NULL) |
917317f4 | 3228 | return PRINT_UNKNOWN; |
0d381245 VP |
3229 | bl = bs->breakpoint_at; |
3230 | b = bl->owner; | |
c906108c | 3231 | |
f7545552 TT |
3232 | stb = ui_out_stream_new (uiout); |
3233 | old_chain = make_cleanup_ui_out_stream_delete (stb); | |
3234 | ||
4f8d1dc6 | 3235 | switch (b->type) |
c906108c | 3236 | { |
e514a9d6 JM |
3237 | case bp_breakpoint: |
3238 | case bp_hardware_breakpoint: | |
2cec12e5 | 3239 | bp_temp = bs->breakpoint_at->owner->disposition == disp_del; |
0d381245 VP |
3240 | if (bl->address != bl->requested_address) |
3241 | breakpoint_adjustment_warning (bl->requested_address, | |
3242 | bl->address, | |
4f8d1dc6 VP |
3243 | b->number, 1); |
3244 | annotate_breakpoint (b->number); | |
2cec12e5 AR |
3245 | if (bp_temp) |
3246 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
3247 | else | |
3248 | ui_out_text (uiout, "\nBreakpoint "); | |
9dc5e2a9 | 3249 | if (ui_out_is_mi_like_p (uiout)) |
2cec12e5 AR |
3250 | { |
3251 | ui_out_field_string (uiout, "reason", | |
3252 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
3253 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
3254 | } | |
4f8d1dc6 | 3255 | ui_out_field_int (uiout, "bkptno", b->number); |
8b93c638 | 3256 | ui_out_text (uiout, ", "); |
f7545552 | 3257 | result = PRINT_SRC_AND_LOC; |
e514a9d6 JM |
3258 | break; |
3259 | ||
3260 | case bp_shlib_event: | |
917317f4 JM |
3261 | /* Did we stop because the user set the stop_on_solib_events |
3262 | variable? (If so, we report this as a generic, "Stopped due | |
3263 | to shlib event" message.) */ | |
a3f17187 | 3264 | printf_filtered (_("Stopped due to shared library event\n")); |
f7545552 | 3265 | result = PRINT_NOTHING; |
e514a9d6 JM |
3266 | break; |
3267 | ||
c4093a6a JM |
3268 | case bp_thread_event: |
3269 | /* Not sure how we will get here. | |
3270 | GDB should not stop for these breakpoints. */ | |
a3f17187 | 3271 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 3272 | result = PRINT_NOTHING; |
c4093a6a JM |
3273 | break; |
3274 | ||
1900040c MS |
3275 | case bp_overlay_event: |
3276 | /* By analogy with the thread event, GDB should not stop for these. */ | |
a3f17187 | 3277 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 3278 | result = PRINT_NOTHING; |
1900040c MS |
3279 | break; |
3280 | ||
0fd8e87f UW |
3281 | case bp_longjmp_master: |
3282 | /* These should never be enabled. */ | |
3283 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
3284 | result = PRINT_NOTHING; | |
3285 | break; | |
3286 | ||
aa7d318d TT |
3287 | case bp_std_terminate_master: |
3288 | /* These should never be enabled. */ | |
3289 | printf_filtered (_("std::terminate Master Breakpoint: gdb should not stop!\n")); | |
3290 | result = PRINT_NOTHING; | |
3291 | break; | |
3292 | ||
e514a9d6 JM |
3293 | case bp_watchpoint: |
3294 | case bp_hardware_watchpoint: | |
fa4727a6 DJ |
3295 | annotate_watchpoint (b->number); |
3296 | if (ui_out_is_mi_like_p (uiout)) | |
3297 | ui_out_field_string | |
3298 | (uiout, "reason", | |
3299 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
3300 | mention (b); | |
f7545552 | 3301 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
fa4727a6 DJ |
3302 | ui_out_text (uiout, "\nOld value = "); |
3303 | watchpoint_value_print (bs->old_val, stb->stream); | |
3304 | ui_out_field_stream (uiout, "old", stb); | |
3305 | ui_out_text (uiout, "\nNew value = "); | |
3306 | watchpoint_value_print (b->val, stb->stream); | |
3307 | ui_out_field_stream (uiout, "new", stb); | |
fa4727a6 | 3308 | ui_out_text (uiout, "\n"); |
e514a9d6 | 3309 | /* More than one watchpoint may have been triggered. */ |
f7545552 | 3310 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
3311 | break; |
3312 | ||
3313 | case bp_read_watchpoint: | |
9dc5e2a9 | 3314 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3315 | ui_out_field_string |
3316 | (uiout, "reason", | |
3317 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 3318 | mention (b); |
f7545552 | 3319 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 3320 | ui_out_text (uiout, "\nValue = "); |
fa4727a6 | 3321 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 3322 | ui_out_field_stream (uiout, "value", stb); |
8b93c638 | 3323 | ui_out_text (uiout, "\n"); |
f7545552 | 3324 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
3325 | break; |
3326 | ||
3327 | case bp_access_watchpoint: | |
fa4727a6 | 3328 | if (bs->old_val != NULL) |
8b93c638 | 3329 | { |
4f8d1dc6 | 3330 | annotate_watchpoint (b->number); |
9dc5e2a9 | 3331 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3332 | ui_out_field_string |
3333 | (uiout, "reason", | |
3334 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 3335 | mention (b); |
f7545552 | 3336 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 3337 | ui_out_text (uiout, "\nOld value = "); |
fa4727a6 | 3338 | watchpoint_value_print (bs->old_val, stb->stream); |
8b93c638 | 3339 | ui_out_field_stream (uiout, "old", stb); |
8b93c638 JM |
3340 | ui_out_text (uiout, "\nNew value = "); |
3341 | } | |
3342 | else | |
3343 | { | |
4f8d1dc6 | 3344 | mention (b); |
9dc5e2a9 | 3345 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3346 | ui_out_field_string |
3347 | (uiout, "reason", | |
3348 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
f7545552 | 3349 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 JM |
3350 | ui_out_text (uiout, "\nValue = "); |
3351 | } | |
fa4727a6 | 3352 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 3353 | ui_out_field_stream (uiout, "new", stb); |
8b93c638 | 3354 | ui_out_text (uiout, "\n"); |
f7545552 | 3355 | result = PRINT_UNKNOWN; |
e514a9d6 | 3356 | break; |
4ce44c66 | 3357 | |
e514a9d6 JM |
3358 | /* Fall through, we don't deal with these types of breakpoints |
3359 | here. */ | |
3360 | ||
11cf8741 | 3361 | case bp_finish: |
9dc5e2a9 | 3362 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3363 | ui_out_field_string |
3364 | (uiout, "reason", | |
3365 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
f7545552 | 3366 | result = PRINT_UNKNOWN; |
8b93c638 JM |
3367 | break; |
3368 | ||
e514a9d6 | 3369 | case bp_until: |
9dc5e2a9 | 3370 | if (ui_out_is_mi_like_p (uiout)) |
1fbc2a49 NR |
3371 | ui_out_field_string |
3372 | (uiout, "reason", | |
3373 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
f7545552 | 3374 | result = PRINT_UNKNOWN; |
8b93c638 JM |
3375 | break; |
3376 | ||
c2d11a7d | 3377 | case bp_none: |
e514a9d6 JM |
3378 | case bp_longjmp: |
3379 | case bp_longjmp_resume: | |
3380 | case bp_step_resume: | |
e514a9d6 JM |
3381 | case bp_watchpoint_scope: |
3382 | case bp_call_dummy: | |
aa7d318d | 3383 | case bp_std_terminate: |
1042e4c0 | 3384 | case bp_tracepoint: |
7a697b8d | 3385 | case bp_fast_tracepoint: |
4efc6507 | 3386 | case bp_jit_event: |
e514a9d6 | 3387 | default: |
f7545552 TT |
3388 | result = PRINT_UNKNOWN; |
3389 | break; | |
e514a9d6 | 3390 | } |
f7545552 TT |
3391 | |
3392 | do_cleanups (old_chain); | |
3393 | return result; | |
e514a9d6 JM |
3394 | } |
3395 | ||
3396 | /* Generic routine for printing messages indicating why we | |
3397 | stopped. The behavior of this function depends on the value | |
3398 | 'print_it' in the bpstat structure. Under some circumstances we | |
3399 | may decide not to print anything here and delegate the task to | |
3400 | normal_stop(). */ | |
3401 | ||
3402 | static enum print_stop_action | |
3403 | print_bp_stop_message (bpstat bs) | |
3404 | { | |
3405 | switch (bs->print_it) | |
3406 | { | |
3407 | case print_it_noop: | |
3408 | /* Nothing should be printed for this bpstat entry. */ | |
3409 | return PRINT_UNKNOWN; | |
3410 | break; | |
3411 | ||
3412 | case print_it_done: | |
3413 | /* We still want to print the frame, but we already printed the | |
3414 | relevant messages. */ | |
3415 | return PRINT_SRC_AND_LOC; | |
3416 | break; | |
3417 | ||
3418 | case print_it_normal: | |
4f8d1dc6 | 3419 | { |
89f9893c | 3420 | const struct bp_location *bl = bs->breakpoint_at; |
4f8d1dc6 VP |
3421 | struct breakpoint *b = bl ? bl->owner : NULL; |
3422 | ||
3423 | /* Normal case. Call the breakpoint's print_it method, or | |
3424 | print_it_typical. */ | |
3425 | /* FIXME: how breakpoint can ever be NULL here? */ | |
3426 | if (b != NULL && b->ops != NULL && b->ops->print_it != NULL) | |
3427 | return b->ops->print_it (b); | |
3428 | else | |
3429 | return print_it_typical (bs); | |
3430 | } | |
3431 | break; | |
3086aeae | 3432 | |
e514a9d6 | 3433 | default: |
8e65ff28 | 3434 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 3435 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 3436 | break; |
c906108c | 3437 | } |
c906108c SS |
3438 | } |
3439 | ||
e514a9d6 JM |
3440 | /* Print a message indicating what happened. This is called from |
3441 | normal_stop(). The input to this routine is the head of the bpstat | |
3442 | list - a list of the eventpoints that caused this stop. This | |
3443 | routine calls the generic print routine for printing a message | |
3444 | about reasons for stopping. This will print (for example) the | |
3445 | "Breakpoint n," part of the output. The return value of this | |
3446 | routine is one of: | |
c906108c | 3447 | |
917317f4 JM |
3448 | PRINT_UNKNOWN: Means we printed nothing |
3449 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent | |
c5aa993b JM |
3450 | code to print the location. An example is |
3451 | "Breakpoint 1, " which should be followed by | |
3452 | the location. | |
917317f4 | 3453 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
3454 | to also print the location part of the message. |
3455 | An example is the catch/throw messages, which | |
917317f4 JM |
3456 | don't require a location appended to the end. |
3457 | PRINT_NOTHING: We have done some printing and we don't need any | |
3458 | further info to be printed.*/ | |
c906108c | 3459 | |
917317f4 | 3460 | enum print_stop_action |
fba45db2 | 3461 | bpstat_print (bpstat bs) |
c906108c SS |
3462 | { |
3463 | int val; | |
c5aa993b | 3464 | |
c906108c | 3465 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
3466 | (Currently all watchpoints go on the bpstat whether hit or not. |
3467 | That probably could (should) be changed, provided care is taken | |
c906108c | 3468 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
3469 | for (; bs; bs = bs->next) |
3470 | { | |
3471 | val = print_bp_stop_message (bs); | |
3472 | if (val == PRINT_SRC_ONLY | |
3473 | || val == PRINT_SRC_AND_LOC | |
3474 | || val == PRINT_NOTHING) | |
3475 | return val; | |
3476 | } | |
c906108c | 3477 | |
e514a9d6 JM |
3478 | /* We reached the end of the chain, or we got a null BS to start |
3479 | with and nothing was printed. */ | |
917317f4 | 3480 | return PRINT_UNKNOWN; |
c906108c SS |
3481 | } |
3482 | ||
3483 | /* Evaluate the expression EXP and return 1 if value is zero. | |
3484 | This is used inside a catch_errors to evaluate the breakpoint condition. | |
3485 | The argument is a "struct expression *" that has been cast to char * to | |
3486 | make it pass through catch_errors. */ | |
3487 | ||
3488 | static int | |
4efb68b1 | 3489 | breakpoint_cond_eval (void *exp) |
c906108c | 3490 | { |
278cd55f | 3491 | struct value *mark = value_mark (); |
c5aa993b | 3492 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
c906108c SS |
3493 | value_free_to_mark (mark); |
3494 | return i; | |
3495 | } | |
3496 | ||
3497 | /* Allocate a new bpstat and chain it to the current one. */ | |
3498 | ||
3499 | static bpstat | |
89f9893c | 3500 | bpstat_alloc (const struct bp_location *bl, bpstat cbs /* Current "bs" value */ ) |
c906108c SS |
3501 | { |
3502 | bpstat bs; | |
3503 | ||
3504 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
3505 | cbs->next = bs; | |
4f8d1dc6 | 3506 | bs->breakpoint_at = bl; |
c906108c SS |
3507 | /* If the condition is false, etc., don't do the commands. */ |
3508 | bs->commands = NULL; | |
9add0f1b | 3509 | bs->commands_left = NULL; |
c906108c SS |
3510 | bs->old_val = NULL; |
3511 | bs->print_it = print_it_normal; | |
3512 | return bs; | |
3513 | } | |
3514 | \f | |
d983da9c DJ |
3515 | /* The target has stopped with waitstatus WS. Check if any hardware |
3516 | watchpoints have triggered, according to the target. */ | |
3517 | ||
3518 | int | |
3519 | watchpoints_triggered (struct target_waitstatus *ws) | |
3520 | { | |
d92524f1 | 3521 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
3522 | CORE_ADDR addr; |
3523 | struct breakpoint *b; | |
3524 | ||
3525 | if (!stopped_by_watchpoint) | |
3526 | { | |
3527 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
3528 | as not triggered. */ | |
3529 | ALL_BREAKPOINTS (b) | |
3530 | if (b->type == bp_hardware_watchpoint | |
3531 | || b->type == bp_read_watchpoint | |
3532 | || b->type == bp_access_watchpoint) | |
3533 | b->watchpoint_triggered = watch_triggered_no; | |
3534 | ||
3535 | return 0; | |
3536 | } | |
3537 | ||
3538 | if (!target_stopped_data_address (¤t_target, &addr)) | |
3539 | { | |
3540 | /* We were stopped by a watchpoint, but we don't know where. | |
3541 | Mark all watchpoints as unknown. */ | |
3542 | ALL_BREAKPOINTS (b) | |
3543 | if (b->type == bp_hardware_watchpoint | |
3544 | || b->type == bp_read_watchpoint | |
3545 | || b->type == bp_access_watchpoint) | |
3546 | b->watchpoint_triggered = watch_triggered_unknown; | |
3547 | ||
3548 | return stopped_by_watchpoint; | |
3549 | } | |
3550 | ||
3551 | /* The target could report the data address. Mark watchpoints | |
3552 | affected by this data address as triggered, and all others as not | |
3553 | triggered. */ | |
3554 | ||
3555 | ALL_BREAKPOINTS (b) | |
3556 | if (b->type == bp_hardware_watchpoint | |
3557 | || b->type == bp_read_watchpoint | |
3558 | || b->type == bp_access_watchpoint) | |
3559 | { | |
a5606eee | 3560 | struct bp_location *loc; |
d983da9c DJ |
3561 | struct value *v; |
3562 | ||
3563 | b->watchpoint_triggered = watch_triggered_no; | |
a5606eee VP |
3564 | for (loc = b->loc; loc; loc = loc->next) |
3565 | /* Exact match not required. Within range is | |
3566 | sufficient. */ | |
5009afc5 AS |
3567 | if (target_watchpoint_addr_within_range (¤t_target, |
3568 | addr, loc->address, | |
3569 | loc->length)) | |
a5606eee VP |
3570 | { |
3571 | b->watchpoint_triggered = watch_triggered_yes; | |
3572 | break; | |
3573 | } | |
d983da9c DJ |
3574 | } |
3575 | ||
3576 | return 1; | |
3577 | } | |
3578 | ||
c906108c SS |
3579 | /* Possible return values for watchpoint_check (this can't be an enum |
3580 | because of check_errors). */ | |
3581 | /* The watchpoint has been deleted. */ | |
3582 | #define WP_DELETED 1 | |
3583 | /* The value has changed. */ | |
3584 | #define WP_VALUE_CHANGED 2 | |
3585 | /* The value has not changed. */ | |
3586 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
3587 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
3588 | #define WP_IGNORE 4 | |
c906108c SS |
3589 | |
3590 | #define BP_TEMPFLAG 1 | |
3591 | #define BP_HARDWAREFLAG 2 | |
3592 | ||
553e4c11 JB |
3593 | /* Evaluate watchpoint condition expression and check if its value changed. |
3594 | ||
3595 | P should be a pointer to struct bpstat, but is defined as a void * | |
3596 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
3597 | |
3598 | static int | |
4efb68b1 | 3599 | watchpoint_check (void *p) |
c906108c SS |
3600 | { |
3601 | bpstat bs = (bpstat) p; | |
3602 | struct breakpoint *b; | |
3603 | struct frame_info *fr; | |
3604 | int within_current_scope; | |
3605 | ||
4f8d1dc6 | 3606 | b = bs->breakpoint_at->owner; |
c906108c | 3607 | |
f6bc2008 PA |
3608 | /* If this is a local watchpoint, we only want to check if the |
3609 | watchpoint frame is in scope if the current thread is the thread | |
3610 | that was used to create the watchpoint. */ | |
3611 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 3612 | return WP_IGNORE; |
f6bc2008 | 3613 | |
c906108c SS |
3614 | if (b->exp_valid_block == NULL) |
3615 | within_current_scope = 1; | |
3616 | else | |
3617 | { | |
edb3359d DJ |
3618 | struct frame_info *frame = get_current_frame (); |
3619 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
3620 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
3621 | ||
a0f49112 JK |
3622 | /* in_function_epilogue_p() returns a non-zero value if we're still |
3623 | in the function but the stack frame has already been invalidated. | |
3624 | Since we can't rely on the values of local variables after the | |
3625 | stack has been destroyed, we are treating the watchpoint in that | |
3626 | state as `not changed' without further checking. Don't mark | |
3627 | watchpoints as changed if the current frame is in an epilogue - | |
3628 | even if they are in some other frame, our view of the stack | |
3629 | is likely to be wrong and frame_find_by_id could error out. */ | |
3630 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) | |
60e1c644 | 3631 | return WP_IGNORE; |
a0f49112 | 3632 | |
101dcfbe | 3633 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 3634 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
3635 | |
3636 | /* If we've gotten confused in the unwinder, we might have | |
3637 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
3638 | if (within_current_scope) |
3639 | { | |
3640 | struct symbol *function; | |
3641 | ||
3642 | function = get_frame_function (fr); | |
3643 | if (function == NULL | |
3644 | || !contained_in (b->exp_valid_block, | |
3645 | SYMBOL_BLOCK_VALUE (function))) | |
3646 | within_current_scope = 0; | |
3647 | } | |
69fbadd5 | 3648 | |
edb3359d | 3649 | if (within_current_scope) |
c906108c SS |
3650 | /* If we end up stopping, the current frame will get selected |
3651 | in normal_stop. So this call to select_frame won't affect | |
3652 | the user. */ | |
0f7d239c | 3653 | select_frame (fr); |
c906108c | 3654 | } |
c5aa993b | 3655 | |
c906108c SS |
3656 | if (within_current_scope) |
3657 | { | |
3658 | /* We use value_{,free_to_}mark because it could be a | |
3659 | *long* time before we return to the command level and | |
c5aa993b JM |
3660 | call free_all_values. We can't call free_all_values because |
3661 | we might be in the middle of evaluating a function call. */ | |
c906108c | 3662 | |
278cd55f | 3663 | struct value *mark = value_mark (); |
fa4727a6 DJ |
3664 | struct value *new_val; |
3665 | ||
3666 | fetch_watchpoint_value (b->exp, &new_val, NULL, NULL); | |
218d2fc6 TJB |
3667 | |
3668 | /* We use value_equal_contents instead of value_equal because the latter | |
3669 | coerces an array to a pointer, thus comparing just the address of the | |
3670 | array instead of its contents. This is not what we want. */ | |
fa4727a6 | 3671 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 3672 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 3673 | { |
fa4727a6 DJ |
3674 | if (new_val != NULL) |
3675 | { | |
3676 | release_value (new_val); | |
3677 | value_free_to_mark (mark); | |
3678 | } | |
c906108c SS |
3679 | bs->old_val = b->val; |
3680 | b->val = new_val; | |
fa4727a6 | 3681 | b->val_valid = 1; |
c906108c SS |
3682 | return WP_VALUE_CHANGED; |
3683 | } | |
3684 | else | |
3685 | { | |
60e1c644 | 3686 | /* Nothing changed. */ |
c906108c | 3687 | value_free_to_mark (mark); |
c906108c SS |
3688 | return WP_VALUE_NOT_CHANGED; |
3689 | } | |
3690 | } | |
3691 | else | |
3692 | { | |
3693 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
3694 | if we temporarily ignored the watchpoint, then when |
3695 | we reenter the block in which it is valid it contains | |
3696 | garbage (in the case of a function, it may have two | |
3697 | garbage values, one before and one after the prologue). | |
3698 | So we can't even detect the first assignment to it and | |
3699 | watch after that (since the garbage may or may not equal | |
3700 | the first value assigned). */ | |
4ce44c66 JM |
3701 | /* We print all the stop information in print_it_typical(), but |
3702 | in this case, by the time we call print_it_typical() this bp | |
3703 | will be deleted already. So we have no choice but print the | |
3704 | information here. */ | |
9dc5e2a9 | 3705 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3706 | ui_out_field_string |
3707 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 3708 | ui_out_text (uiout, "\nWatchpoint "); |
4f8d1dc6 | 3709 | ui_out_field_int (uiout, "wpnum", b->number); |
8b93c638 JM |
3710 | ui_out_text (uiout, " deleted because the program has left the block in\n\ |
3711 | which its expression is valid.\n"); | |
4ce44c66 | 3712 | |
c906108c | 3713 | if (b->related_breakpoint) |
60e1c644 PA |
3714 | { |
3715 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
3716 | b->related_breakpoint->related_breakpoint = NULL; | |
3717 | b->related_breakpoint = NULL; | |
3718 | } | |
b5de0fa7 | 3719 | b->disposition = disp_del_at_next_stop; |
c906108c SS |
3720 | |
3721 | return WP_DELETED; | |
3722 | } | |
3723 | } | |
3724 | ||
18a18393 VP |
3725 | /* Return true if it looks like target has stopped due to hitting |
3726 | breakpoint location BL. This function does not check if we | |
3727 | should stop, only if BL explains the stop. */ | |
3728 | static int | |
6c95b8df PA |
3729 | bpstat_check_location (const struct bp_location *bl, |
3730 | struct address_space *aspace, CORE_ADDR bp_addr) | |
18a18393 VP |
3731 | { |
3732 | struct breakpoint *b = bl->owner; | |
3733 | ||
e8595ef6 SS |
3734 | /* By definition, the inferior does not report stops at |
3735 | tracepoints. */ | |
7a697b8d | 3736 | if (tracepoint_type (b)) |
e8595ef6 SS |
3737 | return 0; |
3738 | ||
18a18393 VP |
3739 | if (b->type != bp_watchpoint |
3740 | && b->type != bp_hardware_watchpoint | |
3741 | && b->type != bp_read_watchpoint | |
3742 | && b->type != bp_access_watchpoint | |
3743 | && b->type != bp_hardware_breakpoint | |
fe798b75 | 3744 | && b->type != bp_catchpoint) /* a non-watchpoint bp */ |
18a18393 | 3745 | { |
6c95b8df PA |
3746 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
3747 | aspace, bp_addr)) | |
18a18393 VP |
3748 | return 0; |
3749 | if (overlay_debugging /* unmapped overlay section */ | |
3750 | && section_is_overlay (bl->section) | |
3751 | && !section_is_mapped (bl->section)) | |
3752 | return 0; | |
3753 | } | |
3754 | ||
3755 | /* Continuable hardware watchpoints are treated as non-existent if the | |
3756 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
3757 | some data address). Otherwise gdb won't stop on a break instruction | |
3758 | in the code (not from a breakpoint) when a hardware watchpoint has | |
3759 | been defined. Also skip watchpoints which we know did not trigger | |
3760 | (did not match the data address). */ | |
3761 | ||
3762 | if ((b->type == bp_hardware_watchpoint | |
3763 | || b->type == bp_read_watchpoint | |
3764 | || b->type == bp_access_watchpoint) | |
3765 | && b->watchpoint_triggered == watch_triggered_no) | |
3766 | return 0; | |
3767 | ||
3768 | if (b->type == bp_hardware_breakpoint) | |
3769 | { | |
3770 | if (bl->address != bp_addr) | |
3771 | return 0; | |
3772 | if (overlay_debugging /* unmapped overlay section */ | |
3773 | && section_is_overlay (bl->section) | |
3774 | && !section_is_mapped (bl->section)) | |
3775 | return 0; | |
3776 | } | |
ce78b96d | 3777 | |
ce78b96d JB |
3778 | if (b->type == bp_catchpoint) |
3779 | { | |
3780 | gdb_assert (b->ops != NULL && b->ops->breakpoint_hit != NULL); | |
3781 | if (!b->ops->breakpoint_hit (b)) | |
3782 | return 0; | |
3783 | } | |
3784 | ||
18a18393 VP |
3785 | return 1; |
3786 | } | |
3787 | ||
3788 | /* If BS refers to a watchpoint, determine if the watched values | |
3789 | has actually changed, and we should stop. If not, set BS->stop | |
3790 | to 0. */ | |
3791 | static void | |
3792 | bpstat_check_watchpoint (bpstat bs) | |
3793 | { | |
3794 | const struct bp_location *bl = bs->breakpoint_at; | |
3795 | struct breakpoint *b = bl->owner; | |
3796 | ||
3797 | if (b->type == bp_watchpoint | |
3798 | || b->type == bp_read_watchpoint | |
3799 | || b->type == bp_access_watchpoint | |
3800 | || b->type == bp_hardware_watchpoint) | |
3801 | { | |
3802 | CORE_ADDR addr; | |
3803 | struct value *v; | |
3804 | int must_check_value = 0; | |
3805 | ||
3806 | if (b->type == bp_watchpoint) | |
3807 | /* For a software watchpoint, we must always check the | |
3808 | watched value. */ | |
3809 | must_check_value = 1; | |
3810 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
3811 | /* We have a hardware watchpoint (read, write, or access) | |
3812 | and the target earlier reported an address watched by | |
3813 | this watchpoint. */ | |
3814 | must_check_value = 1; | |
3815 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3816 | && b->type == bp_hardware_watchpoint) | |
3817 | /* We were stopped by a hardware watchpoint, but the target could | |
3818 | not report the data address. We must check the watchpoint's | |
3819 | value. Access and read watchpoints are out of luck; without | |
3820 | a data address, we can't figure it out. */ | |
3821 | must_check_value = 1; | |
3822 | ||
3823 | if (must_check_value) | |
3824 | { | |
3825 | char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3826 | b->number); | |
3827 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
3828 | int e = catch_errors (watchpoint_check, bs, message, | |
3829 | RETURN_MASK_ALL); | |
3830 | do_cleanups (cleanups); | |
3831 | switch (e) | |
3832 | { | |
3833 | case WP_DELETED: | |
3834 | /* We've already printed what needs to be printed. */ | |
3835 | bs->print_it = print_it_done; | |
3836 | /* Stop. */ | |
3837 | break; | |
60e1c644 PA |
3838 | case WP_IGNORE: |
3839 | bs->print_it = print_it_noop; | |
3840 | bs->stop = 0; | |
3841 | break; | |
18a18393 VP |
3842 | case WP_VALUE_CHANGED: |
3843 | if (b->type == bp_read_watchpoint) | |
3844 | { | |
85d721b8 PA |
3845 | /* There are two cases to consider here: |
3846 | ||
3847 | 1. we're watching the triggered memory for reads. | |
3848 | In that case, trust the target, and always report | |
3849 | the watchpoint hit to the user. Even though | |
3850 | reads don't cause value changes, the value may | |
3851 | have changed since the last time it was read, and | |
3852 | since we're not trapping writes, we will not see | |
3853 | those, and as such we should ignore our notion of | |
3854 | old value. | |
3855 | ||
3856 | 2. we're watching the triggered memory for both | |
3857 | reads and writes. There are two ways this may | |
3858 | happen: | |
3859 | ||
3860 | 2.1. this is a target that can't break on data | |
3861 | reads only, but can break on accesses (reads or | |
3862 | writes), such as e.g., x86. We detect this case | |
3863 | at the time we try to insert read watchpoints. | |
3864 | ||
3865 | 2.2. otherwise, the target supports read | |
3866 | watchpoints, but, the user set an access or write | |
3867 | watchpoint watching the same memory as this read | |
3868 | watchpoint. | |
3869 | ||
3870 | If we're watching memory writes as well as reads, | |
3871 | ignore watchpoint hits when we find that the | |
3872 | value hasn't changed, as reads don't cause | |
3873 | changes. This still gives false positives when | |
3874 | the program writes the same value to memory as | |
3875 | what there was already in memory (we will confuse | |
3876 | it for a read), but it's much better than | |
3877 | nothing. */ | |
3878 | ||
3879 | int other_write_watchpoint = 0; | |
3880 | ||
3881 | if (bl->watchpoint_type == hw_read) | |
3882 | { | |
3883 | struct breakpoint *other_b; | |
3884 | ||
3885 | ALL_BREAKPOINTS (other_b) | |
3886 | if ((other_b->type == bp_hardware_watchpoint | |
3887 | || other_b->type == bp_access_watchpoint) | |
3888 | && (other_b->watchpoint_triggered | |
3889 | == watch_triggered_yes)) | |
3890 | { | |
3891 | other_write_watchpoint = 1; | |
3892 | break; | |
3893 | } | |
3894 | } | |
3895 | ||
3896 | if (other_write_watchpoint | |
3897 | || bl->watchpoint_type == hw_access) | |
3898 | { | |
3899 | /* We're watching the same memory for writes, | |
3900 | and the value changed since the last time we | |
3901 | updated it, so this trap must be for a write. | |
3902 | Ignore it. */ | |
3903 | bs->print_it = print_it_noop; | |
3904 | bs->stop = 0; | |
3905 | } | |
18a18393 VP |
3906 | } |
3907 | break; | |
3908 | case WP_VALUE_NOT_CHANGED: | |
3909 | if (b->type == bp_hardware_watchpoint | |
3910 | || b->type == bp_watchpoint) | |
3911 | { | |
3912 | /* Don't stop: write watchpoints shouldn't fire if | |
3913 | the value hasn't changed. */ | |
3914 | bs->print_it = print_it_noop; | |
3915 | bs->stop = 0; | |
3916 | } | |
3917 | /* Stop. */ | |
3918 | break; | |
3919 | default: | |
3920 | /* Can't happen. */ | |
3921 | case 0: | |
3922 | /* Error from catch_errors. */ | |
3923 | printf_filtered (_("Watchpoint %d deleted.\n"), b->number); | |
3924 | if (b->related_breakpoint) | |
3925 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
3926 | b->disposition = disp_del_at_next_stop; | |
3927 | /* We've already printed what needs to be printed. */ | |
3928 | bs->print_it = print_it_done; | |
3929 | break; | |
3930 | } | |
3931 | } | |
3932 | else /* must_check_value == 0 */ | |
3933 | { | |
3934 | /* This is a case where some watchpoint(s) triggered, but | |
3935 | not at the address of this watchpoint, or else no | |
3936 | watchpoint triggered after all. So don't print | |
3937 | anything for this watchpoint. */ | |
3938 | bs->print_it = print_it_noop; | |
3939 | bs->stop = 0; | |
3940 | } | |
3941 | } | |
3942 | } | |
3943 | ||
3944 | ||
3945 | /* Check conditions (condition proper, frame, thread and ignore count) | |
3946 | of breakpoint referred to by BS. If we should not stop for this | |
3947 | breakpoint, set BS->stop to 0. */ | |
3948 | static void | |
3949 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
3950 | { | |
3951 | int thread_id = pid_to_thread_id (ptid); | |
3952 | const struct bp_location *bl = bs->breakpoint_at; | |
3953 | struct breakpoint *b = bl->owner; | |
3954 | ||
3955 | if (frame_id_p (b->frame_id) | |
edb3359d | 3956 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 VP |
3957 | bs->stop = 0; |
3958 | else if (bs->stop) | |
3959 | { | |
3960 | int value_is_zero = 0; | |
60e1c644 PA |
3961 | struct expression *cond; |
3962 | ||
18a18393 VP |
3963 | /* If this is a scope breakpoint, mark the associated |
3964 | watchpoint as triggered so that we will handle the | |
3965 | out-of-scope event. We'll get to the watchpoint next | |
3966 | iteration. */ | |
3967 | if (b->type == bp_watchpoint_scope) | |
3968 | b->related_breakpoint->watchpoint_triggered = watch_triggered_yes; | |
60e1c644 PA |
3969 | |
3970 | if (is_watchpoint (b)) | |
3971 | cond = b->cond_exp; | |
3972 | else | |
3973 | cond = bl->cond; | |
3974 | ||
3975 | if (cond && bl->owner->disposition != disp_del_at_next_stop) | |
18a18393 | 3976 | { |
60e1c644 PA |
3977 | int within_current_scope = 1; |
3978 | ||
c5bc3a77 DJ |
3979 | /* We use value_mark and value_free_to_mark because it could |
3980 | be a long time before we return to the command level and | |
3981 | call free_all_values. We can't call free_all_values | |
3982 | because we might be in the middle of evaluating a | |
3983 | function call. */ | |
3984 | struct value *mark = value_mark (); | |
3985 | ||
edb3359d DJ |
3986 | /* Need to select the frame, with all that implies so that |
3987 | the conditions will have the right context. Because we | |
3988 | use the frame, we will not see an inlined function's | |
3989 | variables when we arrive at a breakpoint at the start | |
3990 | of the inlined function; the current frame will be the | |
3991 | call site. */ | |
60e1c644 PA |
3992 | if (!is_watchpoint (b) || b->cond_exp_valid_block == NULL) |
3993 | select_frame (get_current_frame ()); | |
3994 | else | |
3995 | { | |
3996 | struct frame_info *frame; | |
3997 | ||
3998 | /* For local watchpoint expressions, which particular | |
3999 | instance of a local is being watched matters, so we | |
4000 | keep track of the frame to evaluate the expression | |
4001 | in. To evaluate the condition however, it doesn't | |
4002 | really matter which instantiation of the function | |
4003 | where the condition makes sense triggers the | |
4004 | watchpoint. This allows an expression like "watch | |
4005 | global if q > 10" set in `func', catch writes to | |
4006 | global on all threads that call `func', or catch | |
4007 | writes on all recursive calls of `func' by a single | |
4008 | thread. We simply always evaluate the condition in | |
4009 | the innermost frame that's executing where it makes | |
4010 | sense to evaluate the condition. It seems | |
4011 | intuitive. */ | |
4012 | frame = block_innermost_frame (b->cond_exp_valid_block); | |
4013 | if (frame != NULL) | |
4014 | select_frame (frame); | |
4015 | else | |
4016 | within_current_scope = 0; | |
4017 | } | |
4018 | if (within_current_scope) | |
4019 | value_is_zero | |
4020 | = catch_errors (breakpoint_cond_eval, cond, | |
4021 | "Error in testing breakpoint condition:\n", | |
4022 | RETURN_MASK_ALL); | |
4023 | else | |
4024 | { | |
4025 | warning (_("Watchpoint condition cannot be tested " | |
4026 | "in the current scope")); | |
4027 | /* If we failed to set the right context for this | |
4028 | watchpoint, unconditionally report it. */ | |
4029 | value_is_zero = 0; | |
4030 | } | |
18a18393 | 4031 | /* FIXME-someday, should give breakpoint # */ |
c5bc3a77 | 4032 | value_free_to_mark (mark); |
18a18393 | 4033 | } |
60e1c644 PA |
4034 | |
4035 | if (cond && value_is_zero) | |
18a18393 VP |
4036 | { |
4037 | bs->stop = 0; | |
4038 | } | |
4039 | else if (b->thread != -1 && b->thread != thread_id) | |
4040 | { | |
4041 | bs->stop = 0; | |
4042 | } | |
4043 | else if (b->ignore_count > 0) | |
4044 | { | |
4045 | b->ignore_count--; | |
4046 | annotate_ignore_count_change (); | |
4047 | bs->stop = 0; | |
4048 | /* Increase the hit count even though we don't | |
4049 | stop. */ | |
4050 | ++(b->hit_count); | |
4051 | } | |
4052 | } | |
4053 | } | |
4054 | ||
4055 | ||
9709f61c | 4056 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 4057 | BP_ADDR in thread PTID. |
c906108c | 4058 | |
d983da9c | 4059 | Determine whether we stopped at a breakpoint, etc, or whether we |
c906108c SS |
4060 | don't understand this stop. Result is a chain of bpstat's such that: |
4061 | ||
c5aa993b | 4062 | if we don't understand the stop, the result is a null pointer. |
c906108c | 4063 | |
c5aa993b | 4064 | if we understand why we stopped, the result is not null. |
c906108c | 4065 | |
c5aa993b JM |
4066 | Each element of the chain refers to a particular breakpoint or |
4067 | watchpoint at which we have stopped. (We may have stopped for | |
4068 | several reasons concurrently.) | |
c906108c | 4069 | |
c5aa993b JM |
4070 | Each element of the chain has valid next, breakpoint_at, |
4071 | commands, FIXME??? fields. */ | |
c906108c SS |
4072 | |
4073 | bpstat | |
6c95b8df PA |
4074 | bpstat_stop_status (struct address_space *aspace, |
4075 | CORE_ADDR bp_addr, ptid_t ptid) | |
c906108c | 4076 | { |
0d381245 | 4077 | struct breakpoint *b = NULL; |
876fa593 | 4078 | struct bp_location *bl, **blp_tmp; |
20874c92 | 4079 | struct bp_location *loc; |
c906108c SS |
4080 | /* Root of the chain of bpstat's */ |
4081 | struct bpstats root_bs[1]; | |
4082 | /* Pointer to the last thing in the chain currently. */ | |
4083 | bpstat bs = root_bs; | |
20874c92 | 4084 | int ix; |
429374b8 | 4085 | int need_remove_insert; |
c906108c | 4086 | |
429374b8 JK |
4087 | /* ALL_BP_LOCATIONS iteration would break across |
4088 | update_global_location_list possibly executed by | |
4089 | bpstat_check_breakpoint_conditions's inferior call. */ | |
c5aa993b | 4090 | |
429374b8 JK |
4091 | ALL_BREAKPOINTS (b) |
4092 | { | |
4093 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) | |
4094 | continue; | |
a5606eee | 4095 | |
429374b8 JK |
4096 | for (bl = b->loc; bl != NULL; bl = bl->next) |
4097 | { | |
4098 | /* For hardware watchpoints, we look only at the first location. | |
4099 | The watchpoint_check function will work on entire expression, | |
4100 | not the individual locations. For read watchopints, the | |
4101 | watchpoints_triggered function have checked all locations | |
4102 | already. */ | |
4103 | if (b->type == bp_hardware_watchpoint && bl != b->loc) | |
4104 | break; | |
18a18393 | 4105 | |
429374b8 JK |
4106 | if (bl->shlib_disabled) |
4107 | continue; | |
c5aa993b | 4108 | |
429374b8 JK |
4109 | if (!bpstat_check_location (bl, aspace, bp_addr)) |
4110 | continue; | |
c5aa993b | 4111 | |
429374b8 | 4112 | /* Come here if it's a watchpoint, or if the break address matches */ |
c5aa993b | 4113 | |
429374b8 | 4114 | bs = bpstat_alloc (bl, bs); /* Alloc a bpstat to explain stop */ |
c5aa993b | 4115 | |
429374b8 JK |
4116 | /* Assume we stop. Should we find watchpoint that is not actually |
4117 | triggered, or if condition of breakpoint is false, we'll reset | |
4118 | 'stop' to 0. */ | |
4119 | bs->stop = 1; | |
4120 | bs->print = 1; | |
d983da9c | 4121 | |
429374b8 JK |
4122 | bpstat_check_watchpoint (bs); |
4123 | if (!bs->stop) | |
4124 | continue; | |
18a18393 | 4125 | |
429374b8 | 4126 | if (b->type == bp_thread_event || b->type == bp_overlay_event |
aa7d318d TT |
4127 | || b->type == bp_longjmp_master |
4128 | || b->type == bp_std_terminate_master) | |
429374b8 JK |
4129 | /* We do not stop for these. */ |
4130 | bs->stop = 0; | |
4131 | else | |
4132 | bpstat_check_breakpoint_conditions (bs, ptid); | |
4133 | ||
4134 | if (bs->stop) | |
4135 | { | |
4136 | ++(b->hit_count); | |
c906108c | 4137 | |
429374b8 JK |
4138 | /* We will stop here */ |
4139 | if (b->disposition == disp_disable) | |
4140 | { | |
4141 | if (b->enable_state != bp_permanent) | |
4142 | b->enable_state = bp_disabled; | |
4143 | update_global_location_list (0); | |
4144 | } | |
4145 | if (b->silent) | |
4146 | bs->print = 0; | |
4147 | bs->commands = b->commands; | |
9add0f1b TT |
4148 | incref_counted_command_line (bs->commands); |
4149 | bs->commands_left = bs->commands ? bs->commands->commands : NULL; | |
4150 | if (bs->commands_left | |
4151 | && (strcmp ("silent", bs->commands_left->line) == 0 | |
4152 | || (xdb_commands | |
4153 | && strcmp ("Q", | |
4154 | bs->commands_left->line) == 0))) | |
429374b8 | 4155 | { |
9add0f1b | 4156 | bs->commands_left = bs->commands_left->next; |
429374b8 JK |
4157 | bs->print = 0; |
4158 | } | |
429374b8 JK |
4159 | } |
4160 | ||
4161 | /* Print nothing for this entry if we dont stop or dont print. */ | |
4162 | if (bs->stop == 0 || bs->print == 0) | |
4163 | bs->print_it = print_it_noop; | |
4164 | } | |
4165 | } | |
876fa593 | 4166 | |
20874c92 VP |
4167 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
4168 | { | |
6c95b8df PA |
4169 | if (breakpoint_address_match (loc->pspace->aspace, loc->address, |
4170 | aspace, bp_addr)) | |
20874c92 VP |
4171 | { |
4172 | bs = bpstat_alloc (loc, bs); | |
4173 | /* For hits of moribund locations, we should just proceed. */ | |
4174 | bs->stop = 0; | |
4175 | bs->print = 0; | |
4176 | bs->print_it = print_it_noop; | |
4177 | } | |
4178 | } | |
4179 | ||
c906108c | 4180 | bs->next = NULL; /* Terminate the chain */ |
c906108c | 4181 | |
d983da9c DJ |
4182 | /* If we aren't stopping, the value of some hardware watchpoint may |
4183 | not have changed, but the intermediate memory locations we are | |
4184 | watching may have. Don't bother if we're stopping; this will get | |
4185 | done later. */ | |
4186 | for (bs = root_bs->next; bs != NULL; bs = bs->next) | |
4187 | if (bs->stop) | |
4188 | break; | |
4189 | ||
d832cb68 | 4190 | need_remove_insert = 0; |
d983da9c DJ |
4191 | if (bs == NULL) |
4192 | for (bs = root_bs->next; bs != NULL; bs = bs->next) | |
4193 | if (!bs->stop | |
20874c92 | 4194 | && bs->breakpoint_at->owner |
2d134ed3 | 4195 | && is_hardware_watchpoint (bs->breakpoint_at->owner)) |
d983da9c | 4196 | { |
2d134ed3 PA |
4197 | update_watchpoint (bs->breakpoint_at->owner, 0 /* don't reparse. */); |
4198 | /* Updating watchpoints invalidates bs->breakpoint_at. | |
4199 | Prevent further code from trying to use it. */ | |
a5606eee | 4200 | bs->breakpoint_at = NULL; |
d832cb68 | 4201 | need_remove_insert = 1; |
d983da9c DJ |
4202 | } |
4203 | ||
d832cb68 | 4204 | if (need_remove_insert) |
2d134ed3 | 4205 | update_global_location_list (1); |
d832cb68 | 4206 | |
d983da9c | 4207 | return root_bs->next; |
c906108c SS |
4208 | } |
4209 | \f | |
4210 | /* Tell what to do about this bpstat. */ | |
4211 | struct bpstat_what | |
fba45db2 | 4212 | bpstat_what (bpstat bs) |
c906108c SS |
4213 | { |
4214 | /* Classify each bpstat as one of the following. */ | |
c5aa993b JM |
4215 | enum class |
4216 | { | |
4217 | /* This bpstat element has no effect on the main_action. */ | |
4218 | no_effect = 0, | |
4219 | ||
4220 | /* There was a watchpoint, stop but don't print. */ | |
4221 | wp_silent, | |
c906108c | 4222 | |
c5aa993b JM |
4223 | /* There was a watchpoint, stop and print. */ |
4224 | wp_noisy, | |
c906108c | 4225 | |
c5aa993b JM |
4226 | /* There was a breakpoint but we're not stopping. */ |
4227 | bp_nostop, | |
c906108c | 4228 | |
c5aa993b JM |
4229 | /* There was a breakpoint, stop but don't print. */ |
4230 | bp_silent, | |
c906108c | 4231 | |
c5aa993b JM |
4232 | /* There was a breakpoint, stop and print. */ |
4233 | bp_noisy, | |
c906108c | 4234 | |
c5aa993b JM |
4235 | /* We hit the longjmp breakpoint. */ |
4236 | long_jump, | |
c906108c | 4237 | |
c5aa993b JM |
4238 | /* We hit the longjmp_resume breakpoint. */ |
4239 | long_resume, | |
c906108c | 4240 | |
c5aa993b JM |
4241 | /* We hit the step_resume breakpoint. */ |
4242 | step_resume, | |
c906108c | 4243 | |
c5aa993b JM |
4244 | /* We hit the shared library event breakpoint. */ |
4245 | shlib_event, | |
c906108c | 4246 | |
4efc6507 DE |
4247 | /* We hit the jit event breakpoint. */ |
4248 | jit_event, | |
4249 | ||
c5aa993b JM |
4250 | /* This is just used to count how many enums there are. */ |
4251 | class_last | |
c906108c SS |
4252 | }; |
4253 | ||
4254 | /* Here is the table which drives this routine. So that we can | |
4255 | format it pretty, we define some abbreviations for the | |
4256 | enum bpstat_what codes. */ | |
4257 | #define kc BPSTAT_WHAT_KEEP_CHECKING | |
4258 | #define ss BPSTAT_WHAT_STOP_SILENT | |
4259 | #define sn BPSTAT_WHAT_STOP_NOISY | |
4260 | #define sgl BPSTAT_WHAT_SINGLE | |
4261 | #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME | |
4262 | #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME | |
c906108c | 4263 | #define sr BPSTAT_WHAT_STEP_RESUME |
c906108c | 4264 | #define shl BPSTAT_WHAT_CHECK_SHLIBS |
4efc6507 | 4265 | #define jit BPSTAT_WHAT_CHECK_JIT |
c906108c SS |
4266 | |
4267 | /* "Can't happen." Might want to print an error message. | |
4268 | abort() is not out of the question, but chances are GDB is just | |
4269 | a bit confused, not unusable. */ | |
4270 | #define err BPSTAT_WHAT_STOP_NOISY | |
4271 | ||
4272 | /* Given an old action and a class, come up with a new action. */ | |
4273 | /* One interesting property of this table is that wp_silent is the same | |
4274 | as bp_silent and wp_noisy is the same as bp_noisy. That is because | |
4275 | after stopping, the check for whether to step over a breakpoint | |
4276 | (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without | |
53a5351d JM |
4277 | reference to how we stopped. We retain separate wp_silent and |
4278 | bp_silent codes in case we want to change that someday. | |
43ff13b4 JM |
4279 | |
4280 | Another possibly interesting property of this table is that | |
4281 | there's a partial ordering, priority-like, of the actions. Once | |
4282 | you've decided that some action is appropriate, you'll never go | |
4283 | back and decide something of a lower priority is better. The | |
4284 | ordering is: | |
4285 | ||
4efc6507 DE |
4286 | kc < jit clr sgl shl slr sn sr ss |
4287 | sgl < jit shl slr sn sr ss | |
4288 | slr < jit err shl sn sr ss | |
4289 | clr < jit err shl sn sr ss | |
4290 | ss < jit shl sn sr | |
4291 | sn < jit shl sr | |
4292 | jit < shl sr | |
d81191fc | 4293 | shl < sr |
4d5b2cd7 | 4294 | sr < |
c5aa993b | 4295 | |
43ff13b4 JM |
4296 | What I think this means is that we don't need a damned table |
4297 | here. If you just put the rows and columns in the right order, | |
4298 | it'd look awfully regular. We could simply walk the bpstat list | |
4299 | and choose the highest priority action we find, with a little | |
78b6a731 | 4300 | logic to handle the 'err' cases. */ |
c906108c SS |
4301 | |
4302 | /* step_resume entries: a step resume breakpoint overrides another | |
4303 | breakpoint of signal handling (see comment in wait_for_inferior | |
fcf70625 | 4304 | at where we set the step_resume breakpoint). */ |
c906108c SS |
4305 | |
4306 | static const enum bpstat_what_main_action | |
c5aa993b JM |
4307 | table[(int) class_last][(int) BPSTAT_WHAT_LAST] = |
4308 | { | |
4309 | /* old action */ | |
4efc6507 DE |
4310 | /* kc ss sn sgl slr clr sr shl jit */ |
4311 | /* no_effect */ {kc, ss, sn, sgl, slr, clr, sr, shl, jit}, | |
4312 | /* wp_silent */ {ss, ss, sn, ss, ss, ss, sr, shl, jit}, | |
4313 | /* wp_noisy */ {sn, sn, sn, sn, sn, sn, sr, shl, jit}, | |
4314 | /* bp_nostop */ {sgl, ss, sn, sgl, slr, slr, sr, shl, jit}, | |
4315 | /* bp_silent */ {ss, ss, sn, ss, ss, ss, sr, shl, jit}, | |
4316 | /* bp_noisy */ {sn, sn, sn, sn, sn, sn, sr, shl, jit}, | |
4317 | /* long_jump */ {slr, ss, sn, slr, slr, err, sr, shl, jit}, | |
4318 | /* long_resume */ {clr, ss, sn, err, err, err, sr, shl, jit}, | |
4319 | /* step_resume */ {sr, sr, sr, sr, sr, sr, sr, sr, sr }, | |
4320 | /* shlib */ {shl, shl, shl, shl, shl, shl, sr, shl, shl}, | |
4321 | /* jit_event */ {jit, jit, jit, jit, jit, jit, sr, jit, jit} | |
c5aa993b | 4322 | }; |
c906108c SS |
4323 | |
4324 | #undef kc | |
4325 | #undef ss | |
4326 | #undef sn | |
4327 | #undef sgl | |
4328 | #undef slr | |
4329 | #undef clr | |
c906108c SS |
4330 | #undef err |
4331 | #undef sr | |
4332 | #undef ts | |
4333 | #undef shl | |
4efc6507 | 4334 | #undef jit |
c906108c SS |
4335 | enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING; |
4336 | struct bpstat_what retval; | |
4337 | ||
aa7d318d | 4338 | retval.call_dummy = STOP_NONE; |
c906108c SS |
4339 | for (; bs != NULL; bs = bs->next) |
4340 | { | |
4341 | enum class bs_class = no_effect; | |
4342 | if (bs->breakpoint_at == NULL) | |
4343 | /* I suspect this can happen if it was a momentary breakpoint | |
4344 | which has since been deleted. */ | |
4345 | continue; | |
20874c92 VP |
4346 | if (bs->breakpoint_at->owner == NULL) |
4347 | bs_class = bp_nostop; | |
4348 | else | |
4f8d1dc6 | 4349 | switch (bs->breakpoint_at->owner->type) |
c906108c SS |
4350 | { |
4351 | case bp_none: | |
4352 | continue; | |
4353 | ||
4354 | case bp_breakpoint: | |
4355 | case bp_hardware_breakpoint: | |
4356 | case bp_until: | |
4357 | case bp_finish: | |
4358 | if (bs->stop) | |
4359 | { | |
4360 | if (bs->print) | |
4361 | bs_class = bp_noisy; | |
4362 | else | |
4363 | bs_class = bp_silent; | |
4364 | } | |
4365 | else | |
4366 | bs_class = bp_nostop; | |
4367 | break; | |
4368 | case bp_watchpoint: | |
4369 | case bp_hardware_watchpoint: | |
4370 | case bp_read_watchpoint: | |
4371 | case bp_access_watchpoint: | |
4372 | if (bs->stop) | |
4373 | { | |
4374 | if (bs->print) | |
4375 | bs_class = wp_noisy; | |
4376 | else | |
4377 | bs_class = wp_silent; | |
4378 | } | |
4379 | else | |
53a5351d JM |
4380 | /* There was a watchpoint, but we're not stopping. |
4381 | This requires no further action. */ | |
c906108c SS |
4382 | bs_class = no_effect; |
4383 | break; | |
4384 | case bp_longjmp: | |
4385 | bs_class = long_jump; | |
4386 | break; | |
4387 | case bp_longjmp_resume: | |
4388 | bs_class = long_resume; | |
4389 | break; | |
4390 | case bp_step_resume: | |
4391 | if (bs->stop) | |
4392 | { | |
4393 | bs_class = step_resume; | |
4394 | } | |
4395 | else | |
4396 | /* It is for the wrong frame. */ | |
4397 | bs_class = bp_nostop; | |
4398 | break; | |
c906108c SS |
4399 | case bp_watchpoint_scope: |
4400 | bs_class = bp_nostop; | |
4401 | break; | |
c5aa993b JM |
4402 | case bp_shlib_event: |
4403 | bs_class = shlib_event; | |
4404 | break; | |
4efc6507 DE |
4405 | case bp_jit_event: |
4406 | bs_class = jit_event; | |
4407 | break; | |
c4093a6a | 4408 | case bp_thread_event: |
1900040c | 4409 | case bp_overlay_event: |
0fd8e87f | 4410 | case bp_longjmp_master: |
aa7d318d | 4411 | case bp_std_terminate_master: |
c4093a6a JM |
4412 | bs_class = bp_nostop; |
4413 | break; | |
ce78b96d | 4414 | case bp_catchpoint: |
c5aa993b JM |
4415 | if (bs->stop) |
4416 | { | |
4417 | if (bs->print) | |
4418 | bs_class = bp_noisy; | |
4419 | else | |
4420 | bs_class = bp_silent; | |
4421 | } | |
4422 | else | |
53a5351d JM |
4423 | /* There was a catchpoint, but we're not stopping. |
4424 | This requires no further action. */ | |
c5aa993b JM |
4425 | bs_class = no_effect; |
4426 | break; | |
c906108c | 4427 | case bp_call_dummy: |
53a5351d JM |
4428 | /* Make sure the action is stop (silent or noisy), |
4429 | so infrun.c pops the dummy frame. */ | |
c906108c | 4430 | bs_class = bp_silent; |
aa7d318d TT |
4431 | retval.call_dummy = STOP_STACK_DUMMY; |
4432 | break; | |
4433 | case bp_std_terminate: | |
4434 | /* Make sure the action is stop (silent or noisy), | |
4435 | so infrun.c pops the dummy frame. */ | |
4436 | bs_class = bp_silent; | |
4437 | retval.call_dummy = STOP_STD_TERMINATE; | |
c906108c | 4438 | break; |
1042e4c0 | 4439 | case bp_tracepoint: |
7a697b8d | 4440 | case bp_fast_tracepoint: |
1042e4c0 SS |
4441 | /* Tracepoint hits should not be reported back to GDB, and |
4442 | if one got through somehow, it should have been filtered | |
4443 | out already. */ | |
4444 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 4445 | _("bpstat_what: tracepoint encountered")); |
1042e4c0 | 4446 | break; |
c906108c | 4447 | } |
c5aa993b | 4448 | current_action = table[(int) bs_class][(int) current_action]; |
c906108c SS |
4449 | } |
4450 | retval.main_action = current_action; | |
4451 | return retval; | |
4452 | } | |
4453 | ||
4454 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
4455 | without hardware support). This isn't related to a specific bpstat, | |
4456 | just to things like whether watchpoints are set. */ | |
4457 | ||
c5aa993b | 4458 | int |
fba45db2 | 4459 | bpstat_should_step (void) |
c906108c SS |
4460 | { |
4461 | struct breakpoint *b; | |
4462 | ALL_BREAKPOINTS (b) | |
717a8278 | 4463 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 4464 | return 1; |
c906108c SS |
4465 | return 0; |
4466 | } | |
4467 | ||
67822962 PA |
4468 | int |
4469 | bpstat_causes_stop (bpstat bs) | |
4470 | { | |
4471 | for (; bs != NULL; bs = bs->next) | |
4472 | if (bs->stop) | |
4473 | return 1; | |
4474 | ||
4475 | return 0; | |
4476 | } | |
4477 | ||
c906108c | 4478 | \f |
c5aa993b | 4479 | |
859825b8 JK |
4480 | /* Print the LOC location out of the list of B->LOC locations. */ |
4481 | ||
0d381245 VP |
4482 | static void print_breakpoint_location (struct breakpoint *b, |
4483 | struct bp_location *loc, | |
4484 | char *wrap_indent, | |
4485 | struct ui_stream *stb) | |
4486 | { | |
6c95b8df PA |
4487 | struct cleanup *old_chain = save_current_program_space (); |
4488 | ||
859825b8 JK |
4489 | if (loc != NULL && loc->shlib_disabled) |
4490 | loc = NULL; | |
4491 | ||
6c95b8df PA |
4492 | if (loc != NULL) |
4493 | set_current_program_space (loc->pspace); | |
4494 | ||
859825b8 | 4495 | if (b->source_file && loc) |
0d381245 VP |
4496 | { |
4497 | struct symbol *sym | |
4498 | = find_pc_sect_function (loc->address, loc->section); | |
4499 | if (sym) | |
4500 | { | |
4501 | ui_out_text (uiout, "in "); | |
4502 | ui_out_field_string (uiout, "func", | |
4503 | SYMBOL_PRINT_NAME (sym)); | |
4504 | ui_out_wrap_hint (uiout, wrap_indent); | |
4505 | ui_out_text (uiout, " at "); | |
4506 | } | |
4507 | ui_out_field_string (uiout, "file", b->source_file); | |
4508 | ui_out_text (uiout, ":"); | |
4509 | ||
4510 | if (ui_out_is_mi_like_p (uiout)) | |
4511 | { | |
4512 | struct symtab_and_line sal = find_pc_line (loc->address, 0); | |
4513 | char *fullname = symtab_to_fullname (sal.symtab); | |
4514 | ||
4515 | if (fullname) | |
4516 | ui_out_field_string (uiout, "fullname", fullname); | |
4517 | } | |
4518 | ||
4519 | ui_out_field_int (uiout, "line", b->line_number); | |
4520 | } | |
859825b8 | 4521 | else if (loc) |
0d381245 | 4522 | { |
22e722e1 DJ |
4523 | print_address_symbolic (loc->gdbarch, loc->address, stb->stream, |
4524 | demangle, ""); | |
0d381245 VP |
4525 | ui_out_field_stream (uiout, "at", stb); |
4526 | } | |
859825b8 JK |
4527 | else |
4528 | ui_out_field_string (uiout, "pending", b->addr_string); | |
6c95b8df PA |
4529 | |
4530 | do_cleanups (old_chain); | |
0d381245 VP |
4531 | } |
4532 | ||
c4093a6a | 4533 | /* Print B to gdb_stdout. */ |
c906108c | 4534 | static void |
0d381245 VP |
4535 | print_one_breakpoint_location (struct breakpoint *b, |
4536 | struct bp_location *loc, | |
4537 | int loc_number, | |
a6d9a66e | 4538 | struct bp_location **last_loc, |
6c95b8df PA |
4539 | int print_address_bits, |
4540 | int allflag) | |
c906108c | 4541 | { |
52f0bd74 AC |
4542 | struct command_line *l; |
4543 | struct symbol *sym; | |
c4093a6a JM |
4544 | struct ep_type_description |
4545 | { | |
4546 | enum bptype type; | |
4547 | char *description; | |
4548 | }; | |
4549 | static struct ep_type_description bptypes[] = | |
c906108c | 4550 | { |
c5aa993b JM |
4551 | {bp_none, "?deleted?"}, |
4552 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 4553 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
4554 | {bp_until, "until"}, |
4555 | {bp_finish, "finish"}, | |
4556 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 4557 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
4558 | {bp_read_watchpoint, "read watchpoint"}, |
4559 | {bp_access_watchpoint, "acc watchpoint"}, | |
4560 | {bp_longjmp, "longjmp"}, | |
4561 | {bp_longjmp_resume, "longjmp resume"}, | |
4562 | {bp_step_resume, "step resume"}, | |
c5aa993b JM |
4563 | {bp_watchpoint_scope, "watchpoint scope"}, |
4564 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 4565 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 4566 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 4567 | {bp_thread_event, "thread events"}, |
1900040c | 4568 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 4569 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 4570 | {bp_std_terminate_master, "std::terminate master"}, |
ce78b96d | 4571 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 4572 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 4573 | {bp_fast_tracepoint, "fast tracepoint"}, |
4efc6507 | 4574 | {bp_jit_event, "jit events"}, |
c5aa993b | 4575 | }; |
c4093a6a | 4576 | |
c2c6d25f | 4577 | static char bpenables[] = "nynny"; |
c906108c | 4578 | char wrap_indent[80]; |
8b93c638 JM |
4579 | struct ui_stream *stb = ui_out_stream_new (uiout); |
4580 | struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb); | |
3b31d625 | 4581 | struct cleanup *bkpt_chain; |
c906108c | 4582 | |
0d381245 VP |
4583 | int header_of_multiple = 0; |
4584 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
4585 | struct value_print_options opts; |
4586 | ||
4587 | get_user_print_options (&opts); | |
0d381245 VP |
4588 | |
4589 | gdb_assert (!loc || loc_number != 0); | |
4590 | /* See comment in print_one_breakpoint concerning | |
4591 | treatment of breakpoints with single disabled | |
4592 | location. */ | |
4593 | if (loc == NULL | |
4594 | && (b->loc != NULL | |
4595 | && (b->loc->next != NULL || !b->loc->enabled))) | |
4596 | header_of_multiple = 1; | |
4597 | if (loc == NULL) | |
4598 | loc = b->loc; | |
4599 | ||
c4093a6a | 4600 | annotate_record (); |
3b31d625 | 4601 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); |
c4093a6a JM |
4602 | |
4603 | /* 1 */ | |
4604 | annotate_field (0); | |
0d381245 VP |
4605 | if (part_of_multiple) |
4606 | { | |
4607 | char *formatted; | |
0c6773c1 | 4608 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
4609 | ui_out_field_string (uiout, "number", formatted); |
4610 | xfree (formatted); | |
4611 | } | |
4612 | else | |
4613 | { | |
4614 | ui_out_field_int (uiout, "number", b->number); | |
4615 | } | |
c4093a6a JM |
4616 | |
4617 | /* 2 */ | |
4618 | annotate_field (1); | |
0d381245 VP |
4619 | if (part_of_multiple) |
4620 | ui_out_field_skip (uiout, "type"); | |
4621 | else | |
4622 | { | |
4623 | if (((int) b->type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
4624 | || ((int) b->type != bptypes[(int) b->type].type)) | |
4625 | internal_error (__FILE__, __LINE__, | |
4626 | _("bptypes table does not describe type #%d."), | |
4627 | (int) b->type); | |
4628 | ui_out_field_string (uiout, "type", bptypes[(int) b->type].description); | |
4629 | } | |
c4093a6a JM |
4630 | |
4631 | /* 3 */ | |
4632 | annotate_field (2); | |
0d381245 VP |
4633 | if (part_of_multiple) |
4634 | ui_out_field_skip (uiout, "disp"); | |
4635 | else | |
2cec12e5 | 4636 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 4637 | |
c4093a6a JM |
4638 | |
4639 | /* 4 */ | |
4640 | annotate_field (3); | |
0d381245 | 4641 | if (part_of_multiple) |
54e52265 | 4642 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 4643 | else |
54e52265 VP |
4644 | ui_out_field_fmt (uiout, "enabled", "%c", |
4645 | bpenables[(int) b->enable_state]); | |
4646 | ui_out_spaces (uiout, 2); | |
0d381245 | 4647 | |
c4093a6a JM |
4648 | |
4649 | /* 5 and 6 */ | |
4650 | strcpy (wrap_indent, " "); | |
79a45b7d | 4651 | if (opts.addressprint) |
75ac9d7b | 4652 | { |
a6d9a66e | 4653 | if (print_address_bits <= 32) |
75ac9d7b MS |
4654 | strcat (wrap_indent, " "); |
4655 | else | |
4656 | strcat (wrap_indent, " "); | |
4657 | } | |
c906108c | 4658 | |
3086aeae | 4659 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 VP |
4660 | { |
4661 | /* Although the print_one can possibly print | |
4662 | all locations, calling it here is not likely | |
4663 | to get any nice result. So, make sure there's | |
4664 | just one location. */ | |
4665 | gdb_assert (b->loc == NULL || b->loc->next == NULL); | |
a6d9a66e | 4666 | b->ops->print_one (b, last_loc); |
0d381245 | 4667 | } |
3086aeae DJ |
4668 | else |
4669 | switch (b->type) | |
4670 | { | |
4671 | case bp_none: | |
4672 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 4673 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 4674 | break; |
c906108c | 4675 | |
3086aeae DJ |
4676 | case bp_watchpoint: |
4677 | case bp_hardware_watchpoint: | |
4678 | case bp_read_watchpoint: | |
4679 | case bp_access_watchpoint: | |
4680 | /* Field 4, the address, is omitted (which makes the columns | |
4681 | not line up too nicely with the headers, but the effect | |
4682 | is relatively readable). */ | |
79a45b7d | 4683 | if (opts.addressprint) |
3086aeae DJ |
4684 | ui_out_field_skip (uiout, "addr"); |
4685 | annotate_field (5); | |
fa8a61dc | 4686 | ui_out_field_string (uiout, "what", b->exp_string); |
3086aeae DJ |
4687 | break; |
4688 | ||
3086aeae DJ |
4689 | case bp_breakpoint: |
4690 | case bp_hardware_breakpoint: | |
4691 | case bp_until: | |
4692 | case bp_finish: | |
4693 | case bp_longjmp: | |
4694 | case bp_longjmp_resume: | |
4695 | case bp_step_resume: | |
3086aeae DJ |
4696 | case bp_watchpoint_scope: |
4697 | case bp_call_dummy: | |
aa7d318d | 4698 | case bp_std_terminate: |
3086aeae DJ |
4699 | case bp_shlib_event: |
4700 | case bp_thread_event: | |
4701 | case bp_overlay_event: | |
0fd8e87f | 4702 | case bp_longjmp_master: |
aa7d318d | 4703 | case bp_std_terminate_master: |
1042e4c0 | 4704 | case bp_tracepoint: |
7a697b8d | 4705 | case bp_fast_tracepoint: |
4efc6507 | 4706 | case bp_jit_event: |
79a45b7d | 4707 | if (opts.addressprint) |
3086aeae DJ |
4708 | { |
4709 | annotate_field (4); | |
54e52265 | 4710 | if (header_of_multiple) |
0d381245 | 4711 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 4712 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 4713 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 4714 | else |
5af949e3 UW |
4715 | ui_out_field_core_addr (uiout, "addr", |
4716 | loc->gdbarch, loc->address); | |
3086aeae DJ |
4717 | } |
4718 | annotate_field (5); | |
0d381245 VP |
4719 | if (!header_of_multiple) |
4720 | print_breakpoint_location (b, loc, wrap_indent, stb); | |
4721 | if (b->loc) | |
a6d9a66e | 4722 | *last_loc = b->loc; |
3086aeae DJ |
4723 | break; |
4724 | } | |
c906108c | 4725 | |
6c95b8df PA |
4726 | |
4727 | /* For backward compatibility, don't display inferiors unless there | |
4728 | are several. */ | |
4729 | if (loc != NULL | |
4730 | && !header_of_multiple | |
4731 | && (allflag | |
4732 | || (!gdbarch_has_global_breakpoints (target_gdbarch) | |
4733 | && (number_of_program_spaces () > 1 | |
4734 | || number_of_inferiors () > 1) | |
4735 | && loc->owner->type != bp_catchpoint))) | |
4736 | { | |
4737 | struct inferior *inf; | |
4738 | int first = 1; | |
4739 | ||
4740 | for (inf = inferior_list; inf != NULL; inf = inf->next) | |
4741 | { | |
4742 | if (inf->pspace == loc->pspace) | |
4743 | { | |
4744 | if (first) | |
4745 | { | |
4746 | first = 0; | |
4747 | ui_out_text (uiout, " inf "); | |
4748 | } | |
4749 | else | |
4750 | ui_out_text (uiout, ", "); | |
4751 | ui_out_text (uiout, plongest (inf->num)); | |
4752 | } | |
4753 | } | |
4754 | } | |
4755 | ||
4a306c9a | 4756 | if (!part_of_multiple) |
c4093a6a | 4757 | { |
4a306c9a JB |
4758 | if (b->thread != -1) |
4759 | { | |
4760 | /* FIXME: This seems to be redundant and lost here; see the | |
4761 | "stop only in" line a little further down. */ | |
4762 | ui_out_text (uiout, " thread "); | |
4763 | ui_out_field_int (uiout, "thread", b->thread); | |
4764 | } | |
4765 | else if (b->task != 0) | |
4766 | { | |
4767 | ui_out_text (uiout, " task "); | |
4768 | ui_out_field_int (uiout, "task", b->task); | |
4769 | } | |
c4093a6a JM |
4770 | } |
4771 | ||
8b93c638 | 4772 | ui_out_text (uiout, "\n"); |
c4093a6a | 4773 | |
0d381245 | 4774 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
4775 | { |
4776 | annotate_field (6); | |
8b93c638 | 4777 | ui_out_text (uiout, "\tstop only in stack frame at "); |
818dd999 AC |
4778 | /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside |
4779 | the frame ID. */ | |
5af949e3 UW |
4780 | ui_out_field_core_addr (uiout, "frame", |
4781 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 4782 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
4783 | } |
4784 | ||
0d381245 | 4785 | if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b)) |
c4093a6a | 4786 | { |
f7f9143b JB |
4787 | /* We do not print the condition for Ada exception catchpoints |
4788 | because the condition is an internal implementation detail | |
4789 | that we do not want to expose to the user. */ | |
c4093a6a | 4790 | annotate_field (7); |
7a697b8d | 4791 | if (tracepoint_type (b)) |
1042e4c0 SS |
4792 | ui_out_text (uiout, "\ttrace only if "); |
4793 | else | |
4794 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 JJ |
4795 | ui_out_field_string (uiout, "cond", b->cond_string); |
4796 | ui_out_text (uiout, "\n"); | |
4797 | } | |
4798 | ||
0d381245 | 4799 | if (!part_of_multiple && b->thread != -1) |
c4093a6a JM |
4800 | { |
4801 | /* FIXME should make an annotation for this */ | |
8b93c638 JM |
4802 | ui_out_text (uiout, "\tstop only in thread "); |
4803 | ui_out_field_int (uiout, "thread", b->thread); | |
4804 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
4805 | } |
4806 | ||
63c715c6 | 4807 | if (!part_of_multiple && b->hit_count) |
c4093a6a JM |
4808 | { |
4809 | /* FIXME should make an annotation for this */ | |
8b93c638 JM |
4810 | if (ep_is_catchpoint (b)) |
4811 | ui_out_text (uiout, "\tcatchpoint"); | |
4812 | else | |
4813 | ui_out_text (uiout, "\tbreakpoint"); | |
4814 | ui_out_text (uiout, " already hit "); | |
4815 | ui_out_field_int (uiout, "times", b->hit_count); | |
4816 | if (b->hit_count == 1) | |
4817 | ui_out_text (uiout, " time\n"); | |
4818 | else | |
4819 | ui_out_text (uiout, " times\n"); | |
c4093a6a JM |
4820 | } |
4821 | ||
fb40c209 AC |
4822 | /* Output the count also if it is zero, but only if this is |
4823 | mi. FIXME: Should have a better test for this. */ | |
9dc5e2a9 | 4824 | if (ui_out_is_mi_like_p (uiout)) |
63c715c6 | 4825 | if (!part_of_multiple && b->hit_count == 0) |
fb40c209 | 4826 | ui_out_field_int (uiout, "times", b->hit_count); |
8b93c638 | 4827 | |
0d381245 | 4828 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
4829 | { |
4830 | annotate_field (8); | |
8b93c638 JM |
4831 | ui_out_text (uiout, "\tignore next "); |
4832 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
4833 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 4834 | } |
059fb39f | 4835 | |
9add0f1b | 4836 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 4837 | if (!part_of_multiple && l) |
c4093a6a | 4838 | { |
3b31d625 EZ |
4839 | struct cleanup *script_chain; |
4840 | ||
c4093a6a | 4841 | annotate_field (9); |
3b31d625 | 4842 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 4843 | print_command_lines (uiout, l, 4); |
3b31d625 | 4844 | do_cleanups (script_chain); |
c4093a6a | 4845 | } |
d24317b4 | 4846 | |
1042e4c0 SS |
4847 | if (!part_of_multiple && b->pass_count) |
4848 | { | |
4849 | annotate_field (10); | |
4850 | ui_out_text (uiout, "\tpass count "); | |
4851 | ui_out_field_int (uiout, "pass", b->pass_count); | |
4852 | ui_out_text (uiout, " \n"); | |
4853 | } | |
4854 | ||
d24317b4 VP |
4855 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
4856 | { | |
4857 | if (b->addr_string) | |
4858 | ui_out_field_string (uiout, "original-location", b->addr_string); | |
4859 | else if (b->exp_string) | |
4860 | ui_out_field_string (uiout, "original-location", b->exp_string); | |
4861 | } | |
4862 | ||
3b31d625 | 4863 | do_cleanups (bkpt_chain); |
8b93c638 | 4864 | do_cleanups (old_chain); |
c4093a6a | 4865 | } |
c5aa993b | 4866 | |
0d381245 VP |
4867 | static void |
4868 | print_one_breakpoint (struct breakpoint *b, | |
6c95b8df PA |
4869 | struct bp_location **last_loc, int print_address_bits, |
4870 | int allflag) | |
0d381245 | 4871 | { |
6c95b8df PA |
4872 | print_one_breakpoint_location (b, NULL, 0, last_loc, |
4873 | print_address_bits, allflag); | |
0d381245 VP |
4874 | |
4875 | /* If this breakpoint has custom print function, | |
4876 | it's already printed. Otherwise, print individual | |
4877 | locations, if any. */ | |
4878 | if (b->ops == NULL || b->ops->print_one == NULL) | |
4879 | { | |
4880 | /* If breakpoint has a single location that is | |
4881 | disabled, we print it as if it had | |
4882 | several locations, since otherwise it's hard to | |
4883 | represent "breakpoint enabled, location disabled" | |
a5606eee VP |
4884 | situation. |
4885 | Note that while hardware watchpoints have | |
4886 | several locations internally, that's no a property | |
4887 | exposed to user. */ | |
0d381245 | 4888 | if (b->loc |
a5606eee | 4889 | && !is_hardware_watchpoint (b) |
0d381245 | 4890 | && (b->loc->next || !b->loc->enabled) |
a5606eee | 4891 | && !ui_out_is_mi_like_p (uiout)) |
0d381245 VP |
4892 | { |
4893 | struct bp_location *loc; | |
4894 | int n = 1; | |
4895 | for (loc = b->loc; loc; loc = loc->next, ++n) | |
a6d9a66e | 4896 | print_one_breakpoint_location (b, loc, n, last_loc, |
6c95b8df | 4897 | print_address_bits, allflag); |
0d381245 VP |
4898 | } |
4899 | } | |
4900 | } | |
4901 | ||
a6d9a66e UW |
4902 | static int |
4903 | breakpoint_address_bits (struct breakpoint *b) | |
4904 | { | |
4905 | int print_address_bits = 0; | |
4906 | struct bp_location *loc; | |
4907 | ||
4908 | for (loc = b->loc; loc; loc = loc->next) | |
4909 | { | |
c7437ca6 PA |
4910 | int addr_bit; |
4911 | ||
4912 | /* Software watchpoints that aren't watching memory don't have | |
4913 | an address to print. */ | |
4914 | if (b->type == bp_watchpoint && loc->watchpoint_type == -1) | |
4915 | continue; | |
4916 | ||
4917 | addr_bit = gdbarch_addr_bit (loc->gdbarch); | |
a6d9a66e UW |
4918 | if (addr_bit > print_address_bits) |
4919 | print_address_bits = addr_bit; | |
4920 | } | |
4921 | ||
4922 | return print_address_bits; | |
4923 | } | |
0d381245 | 4924 | |
c4093a6a JM |
4925 | struct captured_breakpoint_query_args |
4926 | { | |
4927 | int bnum; | |
4928 | }; | |
c5aa993b | 4929 | |
c4093a6a | 4930 | static int |
2b65245e | 4931 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
4932 | { |
4933 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 4934 | struct breakpoint *b; |
a6d9a66e | 4935 | struct bp_location *dummy_loc = NULL; |
c4093a6a JM |
4936 | ALL_BREAKPOINTS (b) |
4937 | { | |
4938 | if (args->bnum == b->number) | |
c5aa993b | 4939 | { |
a6d9a66e | 4940 | int print_address_bits = breakpoint_address_bits (b); |
6c95b8df | 4941 | print_one_breakpoint (b, &dummy_loc, print_address_bits, 0); |
c4093a6a | 4942 | return GDB_RC_OK; |
c5aa993b | 4943 | } |
c4093a6a JM |
4944 | } |
4945 | return GDB_RC_NONE; | |
4946 | } | |
c5aa993b | 4947 | |
c4093a6a | 4948 | enum gdb_rc |
ce43223b | 4949 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, char **error_message) |
c4093a6a JM |
4950 | { |
4951 | struct captured_breakpoint_query_args args; | |
4952 | args.bnum = bnum; | |
4953 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4954 | an error. */ | |
b0b13bb4 DJ |
4955 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
4956 | error_message, RETURN_MASK_ALL) < 0) | |
4957 | return GDB_RC_FAIL; | |
4958 | else | |
4959 | return GDB_RC_OK; | |
c4093a6a | 4960 | } |
c5aa993b | 4961 | |
7f3b0473 AC |
4962 | /* Return non-zero if B is user settable (breakpoints, watchpoints, |
4963 | catchpoints, et.al.). */ | |
4964 | ||
4965 | static int | |
4966 | user_settable_breakpoint (const struct breakpoint *b) | |
4967 | { | |
4968 | return (b->type == bp_breakpoint | |
ce78b96d | 4969 | || b->type == bp_catchpoint |
7f3b0473 | 4970 | || b->type == bp_hardware_breakpoint |
7a697b8d | 4971 | || tracepoint_type (b) |
7f3b0473 AC |
4972 | || b->type == bp_watchpoint |
4973 | || b->type == bp_read_watchpoint | |
4974 | || b->type == bp_access_watchpoint | |
4975 | || b->type == bp_hardware_watchpoint); | |
4976 | } | |
4977 | ||
4978 | /* Print information on user settable breakpoint (watchpoint, etc) | |
4979 | number BNUM. If BNUM is -1 print all user settable breakpoints. | |
4980 | If ALLFLAG is non-zero, include non- user settable breakpoints. */ | |
c906108c | 4981 | |
c4093a6a | 4982 | static void |
fba45db2 | 4983 | breakpoint_1 (int bnum, int allflag) |
c4093a6a | 4984 | { |
52f0bd74 | 4985 | struct breakpoint *b; |
a6d9a66e | 4986 | struct bp_location *last_loc = NULL; |
7f3b0473 | 4987 | int nr_printable_breakpoints; |
3b31d625 | 4988 | struct cleanup *bkpttbl_chain; |
79a45b7d | 4989 | struct value_print_options opts; |
a6d9a66e | 4990 | int print_address_bits = 0; |
c4093a6a | 4991 | |
79a45b7d TT |
4992 | get_user_print_options (&opts); |
4993 | ||
a6d9a66e UW |
4994 | /* Compute the number of rows in the table, as well as the |
4995 | size required for address fields. */ | |
7f3b0473 AC |
4996 | nr_printable_breakpoints = 0; |
4997 | ALL_BREAKPOINTS (b) | |
4998 | if (bnum == -1 | |
4999 | || bnum == b->number) | |
5000 | { | |
5001 | if (allflag || user_settable_breakpoint (b)) | |
a6d9a66e UW |
5002 | { |
5003 | int addr_bit = breakpoint_address_bits (b); | |
5004 | if (addr_bit > print_address_bits) | |
5005 | print_address_bits = addr_bit; | |
5006 | ||
5007 | nr_printable_breakpoints++; | |
5008 | } | |
7f3b0473 AC |
5009 | } |
5010 | ||
79a45b7d | 5011 | if (opts.addressprint) |
3b31d625 EZ |
5012 | bkpttbl_chain |
5013 | = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints, | |
5014 | "BreakpointTable"); | |
8b93c638 | 5015 | else |
3b31d625 EZ |
5016 | bkpttbl_chain |
5017 | = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints, | |
5018 | "BreakpointTable"); | |
8b93c638 | 5019 | |
7f3b0473 | 5020 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
5021 | annotate_breakpoints_headers (); |
5022 | if (nr_printable_breakpoints > 0) | |
5023 | annotate_field (0); | |
0d381245 | 5024 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
5025 | if (nr_printable_breakpoints > 0) |
5026 | annotate_field (1); | |
5027 | ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */ | |
5028 | if (nr_printable_breakpoints > 0) | |
5029 | annotate_field (2); | |
5030 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ | |
5031 | if (nr_printable_breakpoints > 0) | |
5032 | annotate_field (3); | |
54e52265 | 5033 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 5034 | if (opts.addressprint) |
7f3b0473 | 5035 | { |
d7faa9e7 AC |
5036 | if (nr_printable_breakpoints > 0) |
5037 | annotate_field (4); | |
a6d9a66e | 5038 | if (print_address_bits <= 32) |
b25959ec | 5039 | ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */ |
7f3b0473 | 5040 | else |
b25959ec | 5041 | ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */ |
7f3b0473 | 5042 | } |
d7faa9e7 AC |
5043 | if (nr_printable_breakpoints > 0) |
5044 | annotate_field (5); | |
5045 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
5046 | ui_out_table_body (uiout); | |
5047 | if (nr_printable_breakpoints > 0) | |
5048 | annotate_breakpoints_table (); | |
7f3b0473 | 5049 | |
c4093a6a | 5050 | ALL_BREAKPOINTS (b) |
bad56014 TT |
5051 | { |
5052 | QUIT; | |
c4093a6a JM |
5053 | if (bnum == -1 |
5054 | || bnum == b->number) | |
5055 | { | |
5056 | /* We only print out user settable breakpoints unless the | |
5057 | allflag is set. */ | |
7f3b0473 | 5058 | if (allflag || user_settable_breakpoint (b)) |
6c95b8df | 5059 | print_one_breakpoint (b, &last_loc, print_address_bits, allflag); |
c4093a6a | 5060 | } |
bad56014 | 5061 | } |
c4093a6a | 5062 | |
3b31d625 | 5063 | do_cleanups (bkpttbl_chain); |
698384cd | 5064 | |
7f3b0473 | 5065 | if (nr_printable_breakpoints == 0) |
c906108c | 5066 | { |
8b93c638 JM |
5067 | if (bnum == -1) |
5068 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); | |
5069 | else | |
5070 | ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n", | |
5071 | bnum); | |
c906108c SS |
5072 | } |
5073 | else | |
c4093a6a | 5074 | { |
a6d9a66e UW |
5075 | if (last_loc && !server_command) |
5076 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 5077 | } |
c906108c | 5078 | |
c4093a6a JM |
5079 | /* FIXME? Should this be moved up so that it is only called when |
5080 | there have been breakpoints? */ | |
c906108c SS |
5081 | annotate_breakpoints_table_end (); |
5082 | } | |
5083 | ||
c906108c | 5084 | static void |
fba45db2 | 5085 | breakpoints_info (char *bnum_exp, int from_tty) |
c906108c SS |
5086 | { |
5087 | int bnum = -1; | |
5088 | ||
5089 | if (bnum_exp) | |
bb518678 | 5090 | bnum = parse_and_eval_long (bnum_exp); |
c906108c SS |
5091 | |
5092 | breakpoint_1 (bnum, 0); | |
5093 | } | |
5094 | ||
7a292a7a | 5095 | static void |
fba45db2 | 5096 | maintenance_info_breakpoints (char *bnum_exp, int from_tty) |
c906108c SS |
5097 | { |
5098 | int bnum = -1; | |
5099 | ||
5100 | if (bnum_exp) | |
bb518678 | 5101 | bnum = parse_and_eval_long (bnum_exp); |
c906108c SS |
5102 | |
5103 | breakpoint_1 (bnum, 1); | |
5104 | } | |
5105 | ||
0d381245 | 5106 | static int |
714835d5 | 5107 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 5108 | struct program_space *pspace, |
714835d5 | 5109 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
5110 | { |
5111 | struct bp_location *bl = b->loc; | |
5112 | for (; bl; bl = bl->next) | |
5113 | { | |
6c95b8df PA |
5114 | if (bl->pspace == pspace |
5115 | && bl->address == pc | |
0d381245 VP |
5116 | && (!overlay_debugging || bl->section == section)) |
5117 | return 1; | |
5118 | } | |
5119 | return 0; | |
5120 | } | |
5121 | ||
6c95b8df PA |
5122 | /* Print a message describing any breakpoints set at PC. This |
5123 | concerns with logical breakpoints, so we match program spaces, not | |
5124 | address spaces. */ | |
c906108c SS |
5125 | |
5126 | static void | |
6c95b8df PA |
5127 | describe_other_breakpoints (struct gdbarch *gdbarch, |
5128 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 5129 | struct obj_section *section, int thread) |
c906108c | 5130 | { |
52f0bd74 AC |
5131 | int others = 0; |
5132 | struct breakpoint *b; | |
c906108c SS |
5133 | |
5134 | ALL_BREAKPOINTS (b) | |
6c95b8df | 5135 | others += breakpoint_has_pc (b, pspace, pc, section); |
c906108c SS |
5136 | if (others > 0) |
5137 | { | |
a3f17187 AC |
5138 | if (others == 1) |
5139 | printf_filtered (_("Note: breakpoint ")); | |
5140 | else /* if (others == ???) */ | |
5141 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 5142 | ALL_BREAKPOINTS (b) |
6c95b8df | 5143 | if (breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
5144 | { |
5145 | others--; | |
5146 | printf_filtered ("%d", b->number); | |
5147 | if (b->thread == -1 && thread != -1) | |
5148 | printf_filtered (" (all threads)"); | |
5149 | else if (b->thread != -1) | |
5150 | printf_filtered (" (thread %d)", b->thread); | |
5151 | printf_filtered ("%s%s ", | |
059fb39f | 5152 | ((b->enable_state == bp_disabled |
8bea4e01 UW |
5153 | || b->enable_state == bp_call_disabled |
5154 | || b->enable_state == bp_startup_disabled) | |
0d381245 VP |
5155 | ? " (disabled)" |
5156 | : b->enable_state == bp_permanent | |
5157 | ? " (permanent)" | |
5158 | : ""), | |
5159 | (others > 1) ? "," | |
5160 | : ((others == 1) ? " and" : "")); | |
5161 | } | |
a3f17187 | 5162 | printf_filtered (_("also set at pc ")); |
5af949e3 | 5163 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
5164 | printf_filtered (".\n"); |
5165 | } | |
5166 | } | |
5167 | \f | |
5168 | /* Set the default place to put a breakpoint | |
5169 | for the `break' command with no arguments. */ | |
5170 | ||
5171 | void | |
6c95b8df PA |
5172 | set_default_breakpoint (int valid, struct program_space *pspace, |
5173 | CORE_ADDR addr, struct symtab *symtab, | |
fba45db2 | 5174 | int line) |
c906108c SS |
5175 | { |
5176 | default_breakpoint_valid = valid; | |
6c95b8df | 5177 | default_breakpoint_pspace = pspace; |
c906108c SS |
5178 | default_breakpoint_address = addr; |
5179 | default_breakpoint_symtab = symtab; | |
5180 | default_breakpoint_line = line; | |
5181 | } | |
5182 | ||
e4f237da KB |
5183 | /* Return true iff it is meaningful to use the address member of |
5184 | BPT. For some breakpoint types, the address member is irrelevant | |
5185 | and it makes no sense to attempt to compare it to other addresses | |
5186 | (or use it for any other purpose either). | |
5187 | ||
5188 | More specifically, each of the following breakpoint types will always | |
876fa593 JK |
5189 | have a zero valued address and we don't want to mark breakpoints of any of |
5190 | these types to be a duplicate of an actual breakpoint at address zero: | |
e4f237da KB |
5191 | |
5192 | bp_watchpoint | |
2d134ed3 PA |
5193 | bp_catchpoint |
5194 | ||
5195 | */ | |
e4f237da KB |
5196 | |
5197 | static int | |
5198 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
5199 | { | |
5200 | enum bptype type = bpt->type; | |
5201 | ||
2d134ed3 PA |
5202 | return (type != bp_watchpoint && type != bp_catchpoint); |
5203 | } | |
5204 | ||
5205 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
5206 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
5207 | ||
5208 | static int | |
5209 | watchpoint_locations_match (struct bp_location *loc1, struct bp_location *loc2) | |
5210 | { | |
85d721b8 PA |
5211 | /* Note that this checks the owner's type, not the location's. In |
5212 | case the target does not support read watchpoints, but does | |
5213 | support access watchpoints, we'll have bp_read_watchpoint | |
5214 | watchpoints with hw_access locations. Those should be considered | |
5215 | duplicates of hw_read locations. The hw_read locations will | |
5216 | become hw_access locations later. */ | |
2d134ed3 PA |
5217 | return (loc1->owner->type == loc2->owner->type |
5218 | && loc1->pspace->aspace == loc2->pspace->aspace | |
5219 | && loc1->address == loc2->address | |
5220 | && loc1->length == loc2->length); | |
e4f237da KB |
5221 | } |
5222 | ||
6c95b8df PA |
5223 | /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the |
5224 | same breakpoint location. In most targets, this can only be true | |
5225 | if ASPACE1 matches ASPACE2. On targets that have global | |
5226 | breakpoints, the address space doesn't really matter. */ | |
5227 | ||
5228 | static int | |
5229 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, | |
5230 | struct address_space *aspace2, CORE_ADDR addr2) | |
5231 | { | |
5232 | return ((gdbarch_has_global_breakpoints (target_gdbarch) | |
5233 | || aspace1 == aspace2) | |
5234 | && addr1 == addr2); | |
5235 | } | |
5236 | ||
2d134ed3 PA |
5237 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
5238 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
5239 | represent the same location. */ | |
5240 | ||
5241 | static int | |
5242 | breakpoint_locations_match (struct bp_location *loc1, struct bp_location *loc2) | |
5243 | { | |
5244 | int hw_point1 = is_hardware_watchpoint (loc1->owner); | |
5245 | int hw_point2 = is_hardware_watchpoint (loc2->owner); | |
5246 | ||
5247 | if (hw_point1 != hw_point2) | |
5248 | return 0; | |
5249 | else if (hw_point1) | |
5250 | return watchpoint_locations_match (loc1, loc2); | |
5251 | else | |
5252 | return breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
5253 | loc2->pspace->aspace, loc2->address); | |
5254 | } | |
5255 | ||
76897487 KB |
5256 | static void |
5257 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
5258 | int bnum, int have_bnum) | |
5259 | { | |
5260 | char astr1[40]; | |
5261 | char astr2[40]; | |
5262 | ||
bb599908 PH |
5263 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
5264 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 5265 | if (have_bnum) |
8a3fe4f8 | 5266 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
5267 | bnum, astr1, astr2); |
5268 | else | |
8a3fe4f8 | 5269 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
5270 | } |
5271 | ||
5272 | /* Adjust a breakpoint's address to account for architectural constraints | |
5273 | on breakpoint placement. Return the adjusted address. Note: Very | |
5274 | few targets require this kind of adjustment. For most targets, | |
5275 | this function is simply the identity function. */ | |
5276 | ||
5277 | static CORE_ADDR | |
a6d9a66e UW |
5278 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
5279 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 5280 | { |
a6d9a66e | 5281 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
5282 | { |
5283 | /* Very few targets need any kind of breakpoint adjustment. */ | |
5284 | return bpaddr; | |
5285 | } | |
88f7da05 KB |
5286 | else if (bptype == bp_watchpoint |
5287 | || bptype == bp_hardware_watchpoint | |
5288 | || bptype == bp_read_watchpoint | |
5289 | || bptype == bp_access_watchpoint | |
fe798b75 | 5290 | || bptype == bp_catchpoint) |
88f7da05 KB |
5291 | { |
5292 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
5293 | have their addresses modified. */ | |
5294 | return bpaddr; | |
5295 | } | |
76897487 KB |
5296 | else |
5297 | { | |
5298 | CORE_ADDR adjusted_bpaddr; | |
5299 | ||
5300 | /* Some targets have architectural constraints on the placement | |
5301 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 5302 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
5303 | |
5304 | /* An adjusted breakpoint address can significantly alter | |
5305 | a user's expectations. Print a warning if an adjustment | |
5306 | is required. */ | |
5307 | if (adjusted_bpaddr != bpaddr) | |
5308 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
5309 | ||
5310 | return adjusted_bpaddr; | |
5311 | } | |
5312 | } | |
5313 | ||
7cc221ef DJ |
5314 | /* Allocate a struct bp_location. */ |
5315 | ||
26bb91f3 | 5316 | static struct bp_location * |
39d61571 | 5317 | allocate_bp_location (struct breakpoint *bpt) |
7cc221ef DJ |
5318 | { |
5319 | struct bp_location *loc, *loc_p; | |
5320 | ||
5321 | loc = xmalloc (sizeof (struct bp_location)); | |
5322 | memset (loc, 0, sizeof (*loc)); | |
5323 | ||
e049a4b5 | 5324 | loc->owner = bpt; |
511a6cd4 | 5325 | loc->cond = NULL; |
0d381245 VP |
5326 | loc->shlib_disabled = 0; |
5327 | loc->enabled = 1; | |
e049a4b5 | 5328 | |
39d61571 | 5329 | switch (bpt->type) |
e049a4b5 DJ |
5330 | { |
5331 | case bp_breakpoint: | |
5332 | case bp_until: | |
5333 | case bp_finish: | |
5334 | case bp_longjmp: | |
5335 | case bp_longjmp_resume: | |
5336 | case bp_step_resume: | |
e049a4b5 DJ |
5337 | case bp_watchpoint_scope: |
5338 | case bp_call_dummy: | |
aa7d318d | 5339 | case bp_std_terminate: |
e049a4b5 DJ |
5340 | case bp_shlib_event: |
5341 | case bp_thread_event: | |
5342 | case bp_overlay_event: | |
4efc6507 | 5343 | case bp_jit_event: |
0fd8e87f | 5344 | case bp_longjmp_master: |
aa7d318d | 5345 | case bp_std_terminate_master: |
e049a4b5 DJ |
5346 | loc->loc_type = bp_loc_software_breakpoint; |
5347 | break; | |
5348 | case bp_hardware_breakpoint: | |
5349 | loc->loc_type = bp_loc_hardware_breakpoint; | |
5350 | break; | |
5351 | case bp_hardware_watchpoint: | |
5352 | case bp_read_watchpoint: | |
5353 | case bp_access_watchpoint: | |
5354 | loc->loc_type = bp_loc_hardware_watchpoint; | |
5355 | break; | |
5356 | case bp_watchpoint: | |
ce78b96d | 5357 | case bp_catchpoint: |
15c3d785 PA |
5358 | case bp_tracepoint: |
5359 | case bp_fast_tracepoint: | |
e049a4b5 DJ |
5360 | loc->loc_type = bp_loc_other; |
5361 | break; | |
5362 | default: | |
e2e0b3e5 | 5363 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
5364 | } |
5365 | ||
7cc221ef DJ |
5366 | return loc; |
5367 | } | |
5368 | ||
fe3f5fa8 VP |
5369 | static void free_bp_location (struct bp_location *loc) |
5370 | { | |
5371 | if (loc->cond) | |
5372 | xfree (loc->cond); | |
74960c60 VP |
5373 | |
5374 | if (loc->function_name) | |
5375 | xfree (loc->function_name); | |
5376 | ||
fe3f5fa8 VP |
5377 | xfree (loc); |
5378 | } | |
5379 | ||
0d381245 VP |
5380 | /* Helper to set_raw_breakpoint below. Creates a breakpoint |
5381 | that has type BPTYPE and has no locations as yet. */ | |
63c252f8 | 5382 | /* This function is used in gdbtk sources and thus can not be made static. */ |
c906108c | 5383 | |
c40e75cd | 5384 | static struct breakpoint * |
a6d9a66e UW |
5385 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, |
5386 | enum bptype bptype) | |
c906108c | 5387 | { |
52f0bd74 | 5388 | struct breakpoint *b, *b1; |
c906108c SS |
5389 | |
5390 | b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint)); | |
5391 | memset (b, 0, sizeof (*b)); | |
2219d63c | 5392 | |
4d28f7a8 | 5393 | b->type = bptype; |
a6d9a66e | 5394 | b->gdbarch = gdbarch; |
c906108c SS |
5395 | b->language = current_language->la_language; |
5396 | b->input_radix = input_radix; | |
5397 | b->thread = -1; | |
b5de0fa7 | 5398 | b->enable_state = bp_enabled; |
c906108c SS |
5399 | b->next = 0; |
5400 | b->silent = 0; | |
5401 | b->ignore_count = 0; | |
5402 | b->commands = NULL; | |
818dd999 | 5403 | b->frame_id = null_frame_id; |
3a3e9ee3 | 5404 | b->forked_inferior_pid = null_ptid; |
c906108c | 5405 | b->exec_pathname = NULL; |
a96d9b2e | 5406 | b->syscalls_to_be_caught = NULL; |
3086aeae | 5407 | b->ops = NULL; |
0d381245 | 5408 | b->condition_not_parsed = 0; |
c906108c SS |
5409 | |
5410 | /* Add this breakpoint to the end of the chain | |
5411 | so that a list of breakpoints will come out in order | |
5412 | of increasing numbers. */ | |
5413 | ||
5414 | b1 = breakpoint_chain; | |
5415 | if (b1 == 0) | |
5416 | breakpoint_chain = b; | |
5417 | else | |
5418 | { | |
5419 | while (b1->next) | |
5420 | b1 = b1->next; | |
5421 | b1->next = b; | |
5422 | } | |
0d381245 VP |
5423 | return b; |
5424 | } | |
5425 | ||
5426 | /* Initialize loc->function_name. */ | |
5427 | static void | |
5428 | set_breakpoint_location_function (struct bp_location *loc) | |
5429 | { | |
5430 | if (loc->owner->type == bp_breakpoint | |
1042e4c0 | 5431 | || loc->owner->type == bp_hardware_breakpoint |
7a697b8d | 5432 | || tracepoint_type (loc->owner)) |
0d381245 VP |
5433 | { |
5434 | find_pc_partial_function (loc->address, &(loc->function_name), | |
5435 | NULL, NULL); | |
5436 | if (loc->function_name) | |
5437 | loc->function_name = xstrdup (loc->function_name); | |
5438 | } | |
5439 | } | |
5440 | ||
a6d9a66e UW |
5441 | /* Attempt to determine architecture of location identified by SAL. */ |
5442 | static struct gdbarch * | |
5443 | get_sal_arch (struct symtab_and_line sal) | |
5444 | { | |
5445 | if (sal.section) | |
5446 | return get_objfile_arch (sal.section->objfile); | |
5447 | if (sal.symtab) | |
5448 | return get_objfile_arch (sal.symtab->objfile); | |
5449 | ||
5450 | return NULL; | |
5451 | } | |
5452 | ||
0d381245 VP |
5453 | /* set_raw_breakpoint is a low level routine for allocating and |
5454 | partially initializing a breakpoint of type BPTYPE. The newly | |
5455 | created breakpoint's address, section, source file name, and line | |
5456 | number are provided by SAL. The newly created and partially | |
5457 | initialized breakpoint is added to the breakpoint chain and | |
5458 | is also returned as the value of this function. | |
5459 | ||
5460 | It is expected that the caller will complete the initialization of | |
5461 | the newly created breakpoint struct as well as output any status | |
5462 | information regarding the creation of a new breakpoint. In | |
5463 | particular, set_raw_breakpoint does NOT set the breakpoint | |
5464 | number! Care should be taken to not allow an error to occur | |
5465 | prior to completing the initialization of the breakpoint. If this | |
5466 | should happen, a bogus breakpoint will be left on the chain. */ | |
5467 | ||
63c252f8 | 5468 | struct breakpoint * |
a6d9a66e UW |
5469 | set_raw_breakpoint (struct gdbarch *gdbarch, |
5470 | struct symtab_and_line sal, enum bptype bptype) | |
0d381245 | 5471 | { |
a6d9a66e | 5472 | struct breakpoint *b = set_raw_breakpoint_without_location (gdbarch, bptype); |
0d381245 | 5473 | CORE_ADDR adjusted_address; |
a6d9a66e UW |
5474 | struct gdbarch *loc_gdbarch; |
5475 | ||
5476 | loc_gdbarch = get_sal_arch (sal); | |
5477 | if (!loc_gdbarch) | |
5478 | loc_gdbarch = b->gdbarch; | |
0d381245 | 5479 | |
6c95b8df PA |
5480 | if (bptype != bp_catchpoint) |
5481 | gdb_assert (sal.pspace != NULL); | |
5482 | ||
0d381245 VP |
5483 | /* Adjust the breakpoint's address prior to allocating a location. |
5484 | Once we call allocate_bp_location(), that mostly uninitialized | |
5485 | location will be placed on the location chain. Adjustment of the | |
8defab1a | 5486 | breakpoint may cause target_read_memory() to be called and we do |
0d381245 VP |
5487 | not want its scan of the location chain to find a breakpoint and |
5488 | location that's only been partially initialized. */ | |
a6d9a66e | 5489 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, sal.pc, b->type); |
0d381245 | 5490 | |
39d61571 | 5491 | b->loc = allocate_bp_location (b); |
a6d9a66e | 5492 | b->loc->gdbarch = loc_gdbarch; |
0d381245 VP |
5493 | b->loc->requested_address = sal.pc; |
5494 | b->loc->address = adjusted_address; | |
6c95b8df PA |
5495 | b->loc->pspace = sal.pspace; |
5496 | ||
5497 | /* Store the program space that was used to set the breakpoint, for | |
5498 | breakpoint resetting. */ | |
5499 | b->pspace = sal.pspace; | |
0d381245 VP |
5500 | |
5501 | if (sal.symtab == NULL) | |
5502 | b->source_file = NULL; | |
5503 | else | |
1b36a34b | 5504 | b->source_file = xstrdup (sal.symtab->filename); |
0d381245 VP |
5505 | b->loc->section = sal.section; |
5506 | b->line_number = sal.line; | |
5507 | ||
5508 | set_breakpoint_location_function (b->loc); | |
c906108c | 5509 | |
c906108c SS |
5510 | breakpoints_changed (); |
5511 | ||
5512 | return b; | |
5513 | } | |
5514 | ||
c2c6d25f JM |
5515 | |
5516 | /* Note that the breakpoint object B describes a permanent breakpoint | |
5517 | instruction, hard-wired into the inferior's code. */ | |
5518 | void | |
5519 | make_breakpoint_permanent (struct breakpoint *b) | |
5520 | { | |
0d381245 | 5521 | struct bp_location *bl; |
b5de0fa7 | 5522 | b->enable_state = bp_permanent; |
c2c6d25f | 5523 | |
0d381245 VP |
5524 | /* By definition, permanent breakpoints are already present in the code. |
5525 | Mark all locations as inserted. For now, make_breakpoint_permanent | |
5526 | is called in just one place, so it's hard to say if it's reasonable | |
5527 | to have permanent breakpoint with multiple locations or not, | |
5528 | but it's easy to implmement. */ | |
5529 | for (bl = b->loc; bl; bl = bl->next) | |
5530 | bl->inserted = 1; | |
c2c6d25f JM |
5531 | } |
5532 | ||
53a5351d | 5533 | /* Call this routine when stepping and nexting to enable a breakpoint |
0fd8e87f | 5534 | if we do a longjmp() in THREAD. When we hit that breakpoint, call |
c906108c SS |
5535 | set_longjmp_resume_breakpoint() to figure out where we are going. */ |
5536 | ||
5537 | void | |
0fd8e87f | 5538 | set_longjmp_breakpoint (int thread) |
c906108c | 5539 | { |
0fd8e87f UW |
5540 | struct breakpoint *b, *temp; |
5541 | ||
5542 | /* To avoid having to rescan all objfile symbols at every step, | |
5543 | we maintain a list of continually-inserted but always disabled | |
5544 | longjmp "master" breakpoints. Here, we simply create momentary | |
5545 | clones of those and enable them for the requested thread. */ | |
5546 | ALL_BREAKPOINTS_SAFE (b, temp) | |
6c95b8df PA |
5547 | if (b->pspace == current_program_space |
5548 | && b->type == bp_longjmp_master) | |
0fd8e87f UW |
5549 | { |
5550 | struct breakpoint *clone = clone_momentary_breakpoint (b); | |
5551 | clone->type = bp_longjmp; | |
5552 | clone->thread = thread; | |
5553 | } | |
c906108c SS |
5554 | } |
5555 | ||
611c83ae | 5556 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 5557 | void |
611c83ae | 5558 | delete_longjmp_breakpoint (int thread) |
c906108c | 5559 | { |
611c83ae | 5560 | struct breakpoint *b, *temp; |
c906108c | 5561 | |
611c83ae PA |
5562 | ALL_BREAKPOINTS_SAFE (b, temp) |
5563 | if (b->type == bp_longjmp) | |
5564 | { | |
5565 | if (b->thread == thread) | |
5566 | delete_breakpoint (b); | |
5567 | } | |
c906108c SS |
5568 | } |
5569 | ||
1900040c MS |
5570 | void |
5571 | enable_overlay_breakpoints (void) | |
5572 | { | |
52f0bd74 | 5573 | struct breakpoint *b; |
1900040c MS |
5574 | |
5575 | ALL_BREAKPOINTS (b) | |
5576 | if (b->type == bp_overlay_event) | |
5577 | { | |
5578 | b->enable_state = bp_enabled; | |
b60e7edf | 5579 | update_global_location_list (1); |
c02f5703 | 5580 | overlay_events_enabled = 1; |
1900040c MS |
5581 | } |
5582 | } | |
5583 | ||
5584 | void | |
5585 | disable_overlay_breakpoints (void) | |
5586 | { | |
52f0bd74 | 5587 | struct breakpoint *b; |
1900040c MS |
5588 | |
5589 | ALL_BREAKPOINTS (b) | |
5590 | if (b->type == bp_overlay_event) | |
5591 | { | |
5592 | b->enable_state = bp_disabled; | |
b60e7edf | 5593 | update_global_location_list (0); |
c02f5703 | 5594 | overlay_events_enabled = 0; |
1900040c MS |
5595 | } |
5596 | } | |
5597 | ||
aa7d318d TT |
5598 | /* Set an active std::terminate breakpoint for each std::terminate |
5599 | master breakpoint. */ | |
5600 | void | |
5601 | set_std_terminate_breakpoint (void) | |
5602 | { | |
5603 | struct breakpoint *b, *temp; | |
5604 | ||
5605 | ALL_BREAKPOINTS_SAFE (b, temp) | |
5606 | if (b->pspace == current_program_space | |
5607 | && b->type == bp_std_terminate_master) | |
5608 | { | |
5609 | struct breakpoint *clone = clone_momentary_breakpoint (b); | |
5610 | clone->type = bp_std_terminate; | |
5611 | } | |
5612 | } | |
5613 | ||
5614 | /* Delete all the std::terminate breakpoints. */ | |
5615 | void | |
5616 | delete_std_terminate_breakpoint (void) | |
5617 | { | |
5618 | struct breakpoint *b, *temp; | |
5619 | ||
5620 | ALL_BREAKPOINTS_SAFE (b, temp) | |
5621 | if (b->type == bp_std_terminate) | |
5622 | delete_breakpoint (b); | |
5623 | } | |
5624 | ||
c4093a6a | 5625 | struct breakpoint * |
a6d9a66e | 5626 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
5627 | { |
5628 | struct breakpoint *b; | |
c4093a6a | 5629 | |
a6d9a66e | 5630 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event); |
c4093a6a | 5631 | |
b5de0fa7 | 5632 | b->enable_state = bp_enabled; |
c4093a6a | 5633 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
5634 | b->addr_string |
5635 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 5636 | |
b60e7edf | 5637 | update_global_location_list_nothrow (1); |
74960c60 | 5638 | |
c4093a6a JM |
5639 | return b; |
5640 | } | |
5641 | ||
5642 | void | |
5643 | remove_thread_event_breakpoints (void) | |
5644 | { | |
5645 | struct breakpoint *b, *temp; | |
5646 | ||
5647 | ALL_BREAKPOINTS_SAFE (b, temp) | |
6c95b8df PA |
5648 | if (b->type == bp_thread_event |
5649 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
5650 | delete_breakpoint (b); |
5651 | } | |
5652 | ||
0101ce28 JJ |
5653 | struct captured_parse_breakpoint_args |
5654 | { | |
5655 | char **arg_p; | |
5656 | struct symtabs_and_lines *sals_p; | |
5657 | char ***addr_string_p; | |
5658 | int *not_found_ptr; | |
5659 | }; | |
5660 | ||
5661 | struct lang_and_radix | |
5662 | { | |
5663 | enum language lang; | |
5664 | int radix; | |
5665 | }; | |
5666 | ||
4efc6507 DE |
5667 | /* Create a breakpoint for JIT code registration and unregistration. */ |
5668 | ||
5669 | struct breakpoint * | |
5670 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
5671 | { | |
5672 | struct breakpoint *b; | |
5673 | ||
5674 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event); | |
5675 | update_global_location_list_nothrow (1); | |
5676 | return b; | |
5677 | } | |
0101ce28 | 5678 | |
cae688ec JJ |
5679 | void |
5680 | remove_solib_event_breakpoints (void) | |
5681 | { | |
5682 | struct breakpoint *b, *temp; | |
5683 | ||
5684 | ALL_BREAKPOINTS_SAFE (b, temp) | |
6c95b8df PA |
5685 | if (b->type == bp_shlib_event |
5686 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
5687 | delete_breakpoint (b); |
5688 | } | |
5689 | ||
5690 | struct breakpoint * | |
a6d9a66e | 5691 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
cae688ec JJ |
5692 | { |
5693 | struct breakpoint *b; | |
5694 | ||
a6d9a66e | 5695 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event); |
b60e7edf | 5696 | update_global_location_list_nothrow (1); |
cae688ec JJ |
5697 | return b; |
5698 | } | |
5699 | ||
5700 | /* Disable any breakpoints that are on code in shared libraries. Only | |
5701 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
5702 | ||
5703 | void | |
cb851954 | 5704 | disable_breakpoints_in_shlibs (void) |
cae688ec | 5705 | { |
876fa593 | 5706 | struct bp_location *loc, **locp_tmp; |
cae688ec | 5707 | |
876fa593 | 5708 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 5709 | { |
0d381245 VP |
5710 | struct breakpoint *b = loc->owner; |
5711 | /* We apply the check to all breakpoints, including disabled | |
5712 | for those with loc->duplicate set. This is so that when breakpoint | |
5713 | becomes enabled, or the duplicate is removed, gdb will try to insert | |
5714 | all breakpoints. If we don't set shlib_disabled here, we'll try | |
5715 | to insert those breakpoints and fail. */ | |
1042e4c0 | 5716 | if (((b->type == bp_breakpoint) |
508ccb1f | 5717 | || (b->type == bp_jit_event) |
1042e4c0 | 5718 | || (b->type == bp_hardware_breakpoint) |
7a697b8d | 5719 | || (tracepoint_type (b))) |
6c95b8df | 5720 | && loc->pspace == current_program_space |
0d381245 | 5721 | && !loc->shlib_disabled |
a77053c2 | 5722 | #ifdef PC_SOLIB |
0d381245 | 5723 | && PC_SOLIB (loc->address) |
a77053c2 | 5724 | #else |
6c95b8df | 5725 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 MK |
5726 | #endif |
5727 | ) | |
0d381245 VP |
5728 | { |
5729 | loc->shlib_disabled = 1; | |
5730 | } | |
cae688ec JJ |
5731 | } |
5732 | } | |
5733 | ||
84acb35a JJ |
5734 | /* Disable any breakpoints that are in in an unloaded shared library. Only |
5735 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
5736 | ||
75149521 | 5737 | static void |
84acb35a JJ |
5738 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
5739 | { | |
876fa593 | 5740 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
5741 | int disabled_shlib_breaks = 0; |
5742 | ||
c86cf029 VP |
5743 | /* SunOS a.out shared libraries are always mapped, so do not |
5744 | disable breakpoints; they will only be reported as unloaded | |
5745 | through clear_solib when GDB discards its shared library | |
5746 | list. See clear_solib for more information. */ | |
5747 | if (exec_bfd != NULL | |
5748 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
5749 | return; | |
5750 | ||
876fa593 | 5751 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 5752 | { |
0d381245 VP |
5753 | struct breakpoint *b = loc->owner; |
5754 | if ((loc->loc_type == bp_loc_hardware_breakpoint | |
5755 | || loc->loc_type == bp_loc_software_breakpoint) | |
6c95b8df | 5756 | && solib->pspace == loc->pspace |
e2dd7057 | 5757 | && !loc->shlib_disabled |
508ccb1f TT |
5758 | && (b->type == bp_breakpoint |
5759 | || b->type == bp_jit_event | |
5760 | || b->type == bp_hardware_breakpoint) | |
e2dd7057 | 5761 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 5762 | { |
e2dd7057 PP |
5763 | loc->shlib_disabled = 1; |
5764 | /* At this point, we cannot rely on remove_breakpoint | |
5765 | succeeding so we must mark the breakpoint as not inserted | |
5766 | to prevent future errors occurring in remove_breakpoints. */ | |
5767 | loc->inserted = 0; | |
5768 | if (!disabled_shlib_breaks) | |
5769 | { | |
5770 | target_terminal_ours_for_output (); | |
5771 | warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""), | |
5772 | solib->so_name); | |
84acb35a | 5773 | } |
e2dd7057 | 5774 | disabled_shlib_breaks = 1; |
84acb35a JJ |
5775 | } |
5776 | } | |
84acb35a JJ |
5777 | } |
5778 | ||
ce78b96d JB |
5779 | /* FORK & VFORK catchpoints. */ |
5780 | ||
5781 | /* Implement the "insert" breakpoint_ops method for fork catchpoints. */ | |
5782 | ||
c906108c | 5783 | static void |
ce78b96d JB |
5784 | insert_catch_fork (struct breakpoint *b) |
5785 | { | |
5786 | target_insert_fork_catchpoint (PIDGET (inferior_ptid)); | |
5787 | } | |
5788 | ||
5789 | /* Implement the "remove" breakpoint_ops method for fork catchpoints. */ | |
5790 | ||
5791 | static int | |
5792 | remove_catch_fork (struct breakpoint *b) | |
5793 | { | |
5794 | return target_remove_fork_catchpoint (PIDGET (inferior_ptid)); | |
5795 | } | |
5796 | ||
5797 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
5798 | catchpoints. */ | |
5799 | ||
5800 | static int | |
5801 | breakpoint_hit_catch_fork (struct breakpoint *b) | |
5802 | { | |
5803 | return inferior_has_forked (inferior_ptid, &b->forked_inferior_pid); | |
5804 | } | |
5805 | ||
5806 | /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */ | |
5807 | ||
5808 | static enum print_stop_action | |
5809 | print_it_catch_fork (struct breakpoint *b) | |
5810 | { | |
5811 | annotate_catchpoint (b->number); | |
5812 | printf_filtered (_("\nCatchpoint %d (forked process %d), "), | |
5813 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
5814 | return PRINT_SRC_AND_LOC; | |
5815 | } | |
5816 | ||
5817 | /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */ | |
5818 | ||
5819 | static void | |
a6d9a66e | 5820 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 5821 | { |
79a45b7d TT |
5822 | struct value_print_options opts; |
5823 | ||
5824 | get_user_print_options (&opts); | |
5825 | ||
ce78b96d JB |
5826 | /* Field 4, the address, is omitted (which makes the columns |
5827 | not line up too nicely with the headers, but the effect | |
5828 | is relatively readable). */ | |
79a45b7d | 5829 | if (opts.addressprint) |
ce78b96d JB |
5830 | ui_out_field_skip (uiout, "addr"); |
5831 | annotate_field (5); | |
5832 | ui_out_text (uiout, "fork"); | |
5833 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
5834 | { | |
5835 | ui_out_text (uiout, ", process "); | |
5836 | ui_out_field_int (uiout, "what", | |
5837 | ptid_get_pid (b->forked_inferior_pid)); | |
5838 | ui_out_spaces (uiout, 1); | |
5839 | } | |
5840 | } | |
5841 | ||
5842 | /* Implement the "print_mention" breakpoint_ops method for fork | |
5843 | catchpoints. */ | |
5844 | ||
5845 | static void | |
5846 | print_mention_catch_fork (struct breakpoint *b) | |
5847 | { | |
5848 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
5849 | } | |
5850 | ||
5851 | /* The breakpoint_ops structure to be used in fork catchpoints. */ | |
5852 | ||
5853 | static struct breakpoint_ops catch_fork_breakpoint_ops = | |
5854 | { | |
5855 | insert_catch_fork, | |
5856 | remove_catch_fork, | |
5857 | breakpoint_hit_catch_fork, | |
5858 | print_it_catch_fork, | |
5859 | print_one_catch_fork, | |
5860 | print_mention_catch_fork | |
5861 | }; | |
5862 | ||
5863 | /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */ | |
5864 | ||
5865 | static void | |
5866 | insert_catch_vfork (struct breakpoint *b) | |
5867 | { | |
5868 | target_insert_vfork_catchpoint (PIDGET (inferior_ptid)); | |
5869 | } | |
5870 | ||
5871 | /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */ | |
5872 | ||
5873 | static int | |
5874 | remove_catch_vfork (struct breakpoint *b) | |
5875 | { | |
5876 | return target_remove_vfork_catchpoint (PIDGET (inferior_ptid)); | |
5877 | } | |
5878 | ||
5879 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
5880 | catchpoints. */ | |
5881 | ||
5882 | static int | |
5883 | breakpoint_hit_catch_vfork (struct breakpoint *b) | |
5884 | { | |
5885 | return inferior_has_vforked (inferior_ptid, &b->forked_inferior_pid); | |
5886 | } | |
5887 | ||
5888 | /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */ | |
5889 | ||
5890 | static enum print_stop_action | |
5891 | print_it_catch_vfork (struct breakpoint *b) | |
5892 | { | |
5893 | annotate_catchpoint (b->number); | |
5894 | printf_filtered (_("\nCatchpoint %d (vforked process %d), "), | |
5895 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
5896 | return PRINT_SRC_AND_LOC; | |
5897 | } | |
5898 | ||
5899 | /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */ | |
5900 | ||
5901 | static void | |
a6d9a66e | 5902 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 5903 | { |
79a45b7d TT |
5904 | struct value_print_options opts; |
5905 | ||
5906 | get_user_print_options (&opts); | |
ce78b96d JB |
5907 | /* Field 4, the address, is omitted (which makes the columns |
5908 | not line up too nicely with the headers, but the effect | |
5909 | is relatively readable). */ | |
79a45b7d | 5910 | if (opts.addressprint) |
ce78b96d JB |
5911 | ui_out_field_skip (uiout, "addr"); |
5912 | annotate_field (5); | |
5913 | ui_out_text (uiout, "vfork"); | |
5914 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
5915 | { | |
5916 | ui_out_text (uiout, ", process "); | |
5917 | ui_out_field_int (uiout, "what", | |
5918 | ptid_get_pid (b->forked_inferior_pid)); | |
5919 | ui_out_spaces (uiout, 1); | |
5920 | } | |
5921 | } | |
5922 | ||
5923 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
5924 | catchpoints. */ | |
5925 | ||
5926 | static void | |
5927 | print_mention_catch_vfork (struct breakpoint *b) | |
5928 | { | |
5929 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
5930 | } | |
5931 | ||
5932 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ | |
5933 | ||
5934 | static struct breakpoint_ops catch_vfork_breakpoint_ops = | |
5935 | { | |
5936 | insert_catch_vfork, | |
5937 | remove_catch_vfork, | |
5938 | breakpoint_hit_catch_vfork, | |
5939 | print_it_catch_vfork, | |
5940 | print_one_catch_vfork, | |
5941 | print_mention_catch_vfork | |
5942 | }; | |
5943 | ||
a96d9b2e SDJ |
5944 | /* Implement the "insert" breakpoint_ops method for syscall |
5945 | catchpoints. */ | |
5946 | ||
5947 | static void | |
5948 | insert_catch_syscall (struct breakpoint *b) | |
5949 | { | |
5950 | struct inferior *inf = current_inferior (); | |
5951 | ||
5952 | ++inf->total_syscalls_count; | |
5953 | if (!b->syscalls_to_be_caught) | |
5954 | ++inf->any_syscall_count; | |
5955 | else | |
5956 | { | |
5957 | int i, iter; | |
5958 | for (i = 0; | |
5959 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
5960 | i++) | |
5961 | { | |
5962 | int elem; | |
5963 | if (iter >= VEC_length (int, inf->syscalls_counts)) | |
5964 | { | |
5965 | int old_size = VEC_length (int, inf->syscalls_counts); | |
5966 | uintptr_t vec_addr_offset = old_size * ((uintptr_t) sizeof (int)); | |
5967 | uintptr_t vec_addr; | |
5968 | VEC_safe_grow (int, inf->syscalls_counts, iter + 1); | |
5969 | vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) + | |
5970 | vec_addr_offset; | |
5971 | memset ((void *) vec_addr, 0, | |
5972 | (iter + 1 - old_size) * sizeof (int)); | |
5973 | } | |
5974 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
5975 | VEC_replace (int, inf->syscalls_counts, iter, ++elem); | |
5976 | } | |
5977 | } | |
5978 | ||
5979 | target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
5980 | inf->total_syscalls_count != 0, | |
5981 | inf->any_syscall_count, | |
5982 | VEC_length (int, inf->syscalls_counts), | |
5983 | VEC_address (int, inf->syscalls_counts)); | |
5984 | } | |
5985 | ||
5986 | /* Implement the "remove" breakpoint_ops method for syscall | |
5987 | catchpoints. */ | |
5988 | ||
5989 | static int | |
5990 | remove_catch_syscall (struct breakpoint *b) | |
5991 | { | |
5992 | struct inferior *inf = current_inferior (); | |
5993 | ||
5994 | --inf->total_syscalls_count; | |
5995 | if (!b->syscalls_to_be_caught) | |
5996 | --inf->any_syscall_count; | |
5997 | else | |
5998 | { | |
5999 | int i, iter; | |
6000 | for (i = 0; | |
6001 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6002 | i++) | |
6003 | { | |
6004 | int elem; | |
6005 | if (iter >= VEC_length (int, inf->syscalls_counts)) | |
6006 | /* Shouldn't happen. */ | |
6007 | continue; | |
6008 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
6009 | VEC_replace (int, inf->syscalls_counts, iter, --elem); | |
6010 | } | |
6011 | } | |
6012 | ||
6013 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
6014 | inf->total_syscalls_count != 0, | |
6015 | inf->any_syscall_count, | |
6016 | VEC_length (int, inf->syscalls_counts), | |
6017 | VEC_address (int, inf->syscalls_counts)); | |
6018 | } | |
6019 | ||
6020 | /* Implement the "breakpoint_hit" breakpoint_ops method for syscall | |
6021 | catchpoints. */ | |
6022 | ||
6023 | static int | |
6024 | breakpoint_hit_catch_syscall (struct breakpoint *b) | |
6025 | { | |
6026 | /* We must check if we are catching specific syscalls in this breakpoint. | |
6027 | If we are, then we must guarantee that the called syscall is the same | |
6028 | syscall we are catching. */ | |
6029 | int syscall_number = 0; | |
6030 | ||
6031 | if (!inferior_has_called_syscall (inferior_ptid, &syscall_number)) | |
6032 | return 0; | |
6033 | ||
6034 | /* Now, checking if the syscall is the same. */ | |
6035 | if (b->syscalls_to_be_caught) | |
6036 | { | |
6037 | int i, iter; | |
6038 | for (i = 0; | |
6039 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6040 | i++) | |
6041 | if (syscall_number == iter) | |
6042 | break; | |
6043 | /* Not the same. */ | |
6044 | if (!iter) | |
6045 | return 0; | |
6046 | } | |
6047 | ||
6048 | return 1; | |
6049 | } | |
6050 | ||
6051 | /* Implement the "print_it" breakpoint_ops method for syscall | |
6052 | catchpoints. */ | |
6053 | ||
6054 | static enum print_stop_action | |
6055 | print_it_catch_syscall (struct breakpoint *b) | |
6056 | { | |
6057 | /* These are needed because we want to know in which state a | |
6058 | syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY | |
6059 | or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we | |
6060 | must print "called syscall" or "returned from syscall". */ | |
6061 | ptid_t ptid; | |
6062 | struct target_waitstatus last; | |
6063 | struct syscall s; | |
6064 | struct cleanup *old_chain; | |
6065 | char *syscall_id; | |
6066 | ||
6067 | get_last_target_status (&ptid, &last); | |
6068 | ||
6069 | get_syscall_by_number (last.value.syscall_number, &s); | |
6070 | ||
6071 | annotate_catchpoint (b->number); | |
6072 | ||
6073 | if (s.name == NULL) | |
6074 | syscall_id = xstrprintf ("%d", last.value.syscall_number); | |
6075 | else | |
6076 | syscall_id = xstrprintf ("'%s'", s.name); | |
6077 | ||
6078 | old_chain = make_cleanup (xfree, syscall_id); | |
6079 | ||
6080 | if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) | |
6081 | printf_filtered (_("\nCatchpoint %d (call to syscall %s), "), | |
6082 | b->number, syscall_id); | |
6083 | else if (last.kind == TARGET_WAITKIND_SYSCALL_RETURN) | |
6084 | printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "), | |
6085 | b->number, syscall_id); | |
6086 | ||
6087 | do_cleanups (old_chain); | |
6088 | ||
6089 | return PRINT_SRC_AND_LOC; | |
6090 | } | |
6091 | ||
6092 | /* Implement the "print_one" breakpoint_ops method for syscall | |
6093 | catchpoints. */ | |
6094 | ||
6095 | static void | |
6096 | print_one_catch_syscall (struct breakpoint *b, | |
6097 | struct bp_location **last_loc) | |
6098 | { | |
6099 | struct value_print_options opts; | |
6100 | ||
6101 | get_user_print_options (&opts); | |
6102 | /* Field 4, the address, is omitted (which makes the columns | |
6103 | not line up too nicely with the headers, but the effect | |
6104 | is relatively readable). */ | |
6105 | if (opts.addressprint) | |
6106 | ui_out_field_skip (uiout, "addr"); | |
6107 | annotate_field (5); | |
6108 | ||
6109 | if (b->syscalls_to_be_caught | |
6110 | && VEC_length (int, b->syscalls_to_be_caught) > 1) | |
6111 | ui_out_text (uiout, "syscalls \""); | |
6112 | else | |
6113 | ui_out_text (uiout, "syscall \""); | |
6114 | ||
6115 | if (b->syscalls_to_be_caught) | |
6116 | { | |
6117 | int i, iter; | |
6118 | char *text = xstrprintf ("%s", ""); | |
6119 | for (i = 0; | |
6120 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6121 | i++) | |
6122 | { | |
6123 | char *x = text; | |
6124 | struct syscall s; | |
6125 | get_syscall_by_number (iter, &s); | |
6126 | ||
6127 | if (s.name != NULL) | |
6128 | text = xstrprintf ("%s%s, ", text, s.name); | |
6129 | else | |
6130 | text = xstrprintf ("%s%d, ", text, iter); | |
6131 | ||
6132 | /* We have to xfree the last 'text' (now stored at 'x') | |
6133 | because xstrprintf dinamically allocates new space for it | |
6134 | on every call. */ | |
6135 | xfree (x); | |
6136 | } | |
6137 | /* Remove the last comma. */ | |
6138 | text[strlen (text) - 2] = '\0'; | |
6139 | ui_out_field_string (uiout, "what", text); | |
6140 | } | |
6141 | else | |
6142 | ui_out_field_string (uiout, "what", "<any syscall>"); | |
6143 | ui_out_text (uiout, "\" "); | |
6144 | } | |
6145 | ||
6146 | /* Implement the "print_mention" breakpoint_ops method for syscall | |
6147 | catchpoints. */ | |
6148 | ||
6149 | static void | |
6150 | print_mention_catch_syscall (struct breakpoint *b) | |
6151 | { | |
6152 | if (b->syscalls_to_be_caught) | |
6153 | { | |
6154 | int i, iter; | |
6155 | ||
6156 | if (VEC_length (int, b->syscalls_to_be_caught) > 1) | |
6157 | printf_filtered (_("Catchpoint %d (syscalls"), b->number); | |
6158 | else | |
6159 | printf_filtered (_("Catchpoint %d (syscall"), b->number); | |
6160 | ||
6161 | for (i = 0; | |
6162 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6163 | i++) | |
6164 | { | |
6165 | struct syscall s; | |
6166 | get_syscall_by_number (iter, &s); | |
6167 | ||
6168 | if (s.name) | |
6169 | printf_filtered (" '%s' [%d]", s.name, s.number); | |
6170 | else | |
6171 | printf_filtered (" %d", s.number); | |
6172 | } | |
6173 | printf_filtered (")"); | |
6174 | } | |
6175 | else | |
6176 | printf_filtered (_("Catchpoint %d (any syscall)"), | |
6177 | b->number); | |
6178 | } | |
6179 | ||
6180 | /* The breakpoint_ops structure to be used in syscall catchpoints. */ | |
6181 | ||
6182 | static struct breakpoint_ops catch_syscall_breakpoint_ops = | |
6183 | { | |
6184 | insert_catch_syscall, | |
6185 | remove_catch_syscall, | |
6186 | breakpoint_hit_catch_syscall, | |
6187 | print_it_catch_syscall, | |
6188 | print_one_catch_syscall, | |
6189 | print_mention_catch_syscall | |
6190 | }; | |
6191 | ||
6192 | /* Returns non-zero if 'b' is a syscall catchpoint. */ | |
6193 | ||
6194 | static int | |
6195 | syscall_catchpoint_p (struct breakpoint *b) | |
6196 | { | |
6197 | return (b->ops == &catch_syscall_breakpoint_ops); | |
6198 | } | |
6199 | ||
6200 | /* Create a new breakpoint of the bp_catchpoint kind and return it, | |
6201 | but does NOT mention it nor update the global location list. | |
6202 | This is useful if you need to fill more fields in the | |
6203 | struct breakpoint before calling mention. | |
ce78b96d JB |
6204 | |
6205 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
6206 | If COND_STRING is not NULL, then store it in the breakpoint. | |
6207 | OPS, if not NULL, is the breakpoint_ops structure associated | |
6208 | to the catchpoint. */ | |
6209 | ||
6210 | static struct breakpoint * | |
a96d9b2e SDJ |
6211 | create_catchpoint_without_mention (struct gdbarch *gdbarch, int tempflag, |
6212 | char *cond_string, | |
6213 | struct breakpoint_ops *ops) | |
c906108c | 6214 | { |
c5aa993b JM |
6215 | struct symtab_and_line sal; |
6216 | struct breakpoint *b; | |
c5aa993b | 6217 | |
fe39c653 | 6218 | init_sal (&sal); |
6c95b8df | 6219 | sal.pspace = current_program_space; |
c5aa993b | 6220 | |
a6d9a66e | 6221 | b = set_raw_breakpoint (gdbarch, sal, bp_catchpoint); |
c906108c SS |
6222 | set_breakpoint_count (breakpoint_count + 1); |
6223 | b->number = breakpoint_count; | |
ce78b96d | 6224 | |
1b36a34b | 6225 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
ce78b96d | 6226 | b->thread = -1; |
c906108c | 6227 | b->addr_string = NULL; |
b5de0fa7 EZ |
6228 | b->enable_state = bp_enabled; |
6229 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
ce78b96d | 6230 | b->ops = ops; |
c5aa993b | 6231 | |
a96d9b2e SDJ |
6232 | return b; |
6233 | } | |
6234 | ||
6235 | /* Create a new breakpoint of the bp_catchpoint kind and return it. | |
6236 | ||
6237 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
6238 | If COND_STRING is not NULL, then store it in the breakpoint. | |
6239 | OPS, if not NULL, is the breakpoint_ops structure associated | |
6240 | to the catchpoint. */ | |
6241 | ||
6242 | static struct breakpoint * | |
6243 | create_catchpoint (struct gdbarch *gdbarch, int tempflag, | |
6244 | char *cond_string, struct breakpoint_ops *ops) | |
6245 | { | |
6246 | struct breakpoint *b = | |
6247 | create_catchpoint_without_mention (gdbarch, tempflag, cond_string, ops); | |
6248 | ||
c906108c | 6249 | mention (b); |
ce78b96d | 6250 | update_global_location_list (1); |
c906108c | 6251 | |
ce78b96d | 6252 | return b; |
c906108c | 6253 | } |
c5aa993b | 6254 | |
9b70b993 | 6255 | static void |
a6d9a66e UW |
6256 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
6257 | int tempflag, char *cond_string, | |
ce78b96d | 6258 | struct breakpoint_ops *ops) |
c906108c | 6259 | { |
a6d9a66e UW |
6260 | struct breakpoint *b |
6261 | = create_catchpoint (gdbarch, tempflag, cond_string, ops); | |
ce78b96d JB |
6262 | |
6263 | /* FIXME: We should put this information in a breakpoint private data | |
6264 | area. */ | |
6265 | b->forked_inferior_pid = null_ptid; | |
c906108c SS |
6266 | } |
6267 | ||
fe798b75 JB |
6268 | /* Exec catchpoints. */ |
6269 | ||
9b70b993 | 6270 | static void |
fe798b75 | 6271 | insert_catch_exec (struct breakpoint *b) |
c906108c | 6272 | { |
fe798b75 JB |
6273 | target_insert_exec_catchpoint (PIDGET (inferior_ptid)); |
6274 | } | |
c906108c | 6275 | |
fe798b75 JB |
6276 | static int |
6277 | remove_catch_exec (struct breakpoint *b) | |
6278 | { | |
6279 | return target_remove_exec_catchpoint (PIDGET (inferior_ptid)); | |
6280 | } | |
c906108c | 6281 | |
fe798b75 JB |
6282 | static int |
6283 | breakpoint_hit_catch_exec (struct breakpoint *b) | |
6284 | { | |
6285 | return inferior_has_execd (inferior_ptid, &b->exec_pathname); | |
6286 | } | |
c906108c | 6287 | |
fe798b75 JB |
6288 | static enum print_stop_action |
6289 | print_it_catch_exec (struct breakpoint *b) | |
6290 | { | |
6291 | annotate_catchpoint (b->number); | |
6292 | printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number, | |
6293 | b->exec_pathname); | |
6294 | return PRINT_SRC_AND_LOC; | |
c906108c SS |
6295 | } |
6296 | ||
fe798b75 | 6297 | static void |
a6d9a66e | 6298 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 JB |
6299 | { |
6300 | struct value_print_options opts; | |
6301 | ||
6302 | get_user_print_options (&opts); | |
6303 | ||
6304 | /* Field 4, the address, is omitted (which makes the columns | |
6305 | not line up too nicely with the headers, but the effect | |
6306 | is relatively readable). */ | |
6307 | if (opts.addressprint) | |
6308 | ui_out_field_skip (uiout, "addr"); | |
6309 | annotate_field (5); | |
6310 | ui_out_text (uiout, "exec"); | |
6311 | if (b->exec_pathname != NULL) | |
6312 | { | |
6313 | ui_out_text (uiout, ", program \""); | |
6314 | ui_out_field_string (uiout, "what", b->exec_pathname); | |
6315 | ui_out_text (uiout, "\" "); | |
6316 | } | |
6317 | } | |
6318 | ||
6319 | static void | |
6320 | print_mention_catch_exec (struct breakpoint *b) | |
6321 | { | |
6322 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
6323 | } | |
6324 | ||
6325 | static struct breakpoint_ops catch_exec_breakpoint_ops = | |
6326 | { | |
6327 | insert_catch_exec, | |
6328 | remove_catch_exec, | |
6329 | breakpoint_hit_catch_exec, | |
6330 | print_it_catch_exec, | |
6331 | print_one_catch_exec, | |
6332 | print_mention_catch_exec | |
6333 | }; | |
6334 | ||
a96d9b2e SDJ |
6335 | static void |
6336 | create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, | |
6337 | struct breakpoint_ops *ops) | |
6338 | { | |
6339 | struct gdbarch *gdbarch = get_current_arch (); | |
6340 | struct breakpoint *b = | |
6341 | create_catchpoint_without_mention (gdbarch, tempflag, NULL, ops); | |
6342 | ||
6343 | b->syscalls_to_be_caught = filter; | |
6344 | ||
6345 | /* Now, we have to mention the breakpoint and update the global | |
6346 | location list. */ | |
6347 | mention (b); | |
6348 | update_global_location_list (1); | |
6349 | } | |
6350 | ||
c906108c | 6351 | static int |
fba45db2 | 6352 | hw_breakpoint_used_count (void) |
c906108c | 6353 | { |
52f0bd74 | 6354 | struct breakpoint *b; |
c906108c SS |
6355 | int i = 0; |
6356 | ||
6357 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6358 | { |
d6b74ac4 | 6359 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
c5aa993b JM |
6360 | i++; |
6361 | } | |
c906108c SS |
6362 | |
6363 | return i; | |
6364 | } | |
6365 | ||
6366 | static int | |
fba45db2 | 6367 | hw_watchpoint_used_count (enum bptype type, int *other_type_used) |
c906108c | 6368 | { |
52f0bd74 | 6369 | struct breakpoint *b; |
c906108c SS |
6370 | int i = 0; |
6371 | ||
6372 | *other_type_used = 0; | |
6373 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6374 | { |
468d015d | 6375 | if (breakpoint_enabled (b)) |
c5aa993b JM |
6376 | { |
6377 | if (b->type == type) | |
6378 | i++; | |
059fb39f PM |
6379 | else if ((b->type == bp_hardware_watchpoint |
6380 | || b->type == bp_read_watchpoint | |
6381 | || b->type == bp_access_watchpoint)) | |
c5aa993b JM |
6382 | *other_type_used = 1; |
6383 | } | |
6384 | } | |
c906108c SS |
6385 | return i; |
6386 | } | |
6387 | ||
c906108c | 6388 | void |
fba45db2 | 6389 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 6390 | { |
c5aa993b | 6391 | struct breakpoint *b; |
c906108c SS |
6392 | |
6393 | ALL_BREAKPOINTS (b) | |
c5aa993b JM |
6394 | { |
6395 | if (((b->type == bp_watchpoint) | |
6396 | || (b->type == bp_hardware_watchpoint) | |
6397 | || (b->type == bp_read_watchpoint) | |
dfdfb3ca | 6398 | || (b->type == bp_access_watchpoint)) |
468d015d | 6399 | && breakpoint_enabled (b)) |
c5aa993b | 6400 | { |
b5de0fa7 | 6401 | b->enable_state = bp_call_disabled; |
b60e7edf | 6402 | update_global_location_list (0); |
c5aa993b JM |
6403 | } |
6404 | } | |
c906108c SS |
6405 | } |
6406 | ||
6407 | void | |
fba45db2 | 6408 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 6409 | { |
c5aa993b | 6410 | struct breakpoint *b; |
c906108c SS |
6411 | |
6412 | ALL_BREAKPOINTS (b) | |
c5aa993b JM |
6413 | { |
6414 | if (((b->type == bp_watchpoint) | |
6415 | || (b->type == bp_hardware_watchpoint) | |
6416 | || (b->type == bp_read_watchpoint) | |
dfdfb3ca | 6417 | || (b->type == bp_access_watchpoint)) |
b5de0fa7 | 6418 | && (b->enable_state == bp_call_disabled)) |
c5aa993b | 6419 | { |
b5de0fa7 | 6420 | b->enable_state = bp_enabled; |
b60e7edf | 6421 | update_global_location_list (1); |
c5aa993b JM |
6422 | } |
6423 | } | |
c906108c SS |
6424 | } |
6425 | ||
8bea4e01 UW |
6426 | void |
6427 | disable_breakpoints_before_startup (void) | |
6428 | { | |
6429 | struct breakpoint *b; | |
6430 | int found = 0; | |
6431 | ||
6432 | ALL_BREAKPOINTS (b) | |
6433 | { | |
6c95b8df PA |
6434 | if (b->pspace != current_program_space) |
6435 | continue; | |
6436 | ||
8bea4e01 UW |
6437 | if ((b->type == bp_breakpoint |
6438 | || b->type == bp_hardware_breakpoint) | |
6439 | && breakpoint_enabled (b)) | |
6440 | { | |
6441 | b->enable_state = bp_startup_disabled; | |
6442 | found = 1; | |
6443 | } | |
6444 | } | |
6445 | ||
6446 | if (found) | |
6447 | update_global_location_list (0); | |
6448 | ||
6c95b8df | 6449 | current_program_space->executing_startup = 1; |
8bea4e01 UW |
6450 | } |
6451 | ||
6452 | void | |
6453 | enable_breakpoints_after_startup (void) | |
6454 | { | |
6455 | struct breakpoint *b; | |
6456 | int found = 0; | |
6457 | ||
6c95b8df | 6458 | current_program_space->executing_startup = 0; |
8bea4e01 UW |
6459 | |
6460 | ALL_BREAKPOINTS (b) | |
6461 | { | |
6c95b8df PA |
6462 | if (b->pspace != current_program_space) |
6463 | continue; | |
6464 | ||
8bea4e01 UW |
6465 | if ((b->type == bp_breakpoint |
6466 | || b->type == bp_hardware_breakpoint) | |
6467 | && b->enable_state == bp_startup_disabled) | |
6468 | { | |
6469 | b->enable_state = bp_enabled; | |
6470 | found = 1; | |
6471 | } | |
6472 | } | |
6473 | ||
6474 | if (found) | |
6475 | breakpoint_re_set (); | |
6476 | } | |
6477 | ||
c906108c SS |
6478 | |
6479 | /* Set a breakpoint that will evaporate an end of command | |
6480 | at address specified by SAL. | |
6481 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
6482 | ||
6483 | struct breakpoint * | |
a6d9a66e UW |
6484 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
6485 | struct frame_id frame_id, enum bptype type) | |
c906108c | 6486 | { |
52f0bd74 | 6487 | struct breakpoint *b; |
edb3359d DJ |
6488 | |
6489 | /* If FRAME_ID is valid, it should be a real frame, not an inlined | |
6490 | one. */ | |
6491 | gdb_assert (!frame_id_inlined_p (frame_id)); | |
6492 | ||
a6d9a66e | 6493 | b = set_raw_breakpoint (gdbarch, sal, type); |
b5de0fa7 EZ |
6494 | b->enable_state = bp_enabled; |
6495 | b->disposition = disp_donttouch; | |
818dd999 | 6496 | b->frame_id = frame_id; |
c906108c SS |
6497 | |
6498 | /* If we're debugging a multi-threaded program, then we | |
6499 | want momentary breakpoints to be active in only a | |
6500 | single thread of control. */ | |
39f77062 KB |
6501 | if (in_thread_list (inferior_ptid)) |
6502 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 6503 | |
b60e7edf | 6504 | update_global_location_list_nothrow (1); |
74960c60 | 6505 | |
c906108c SS |
6506 | return b; |
6507 | } | |
611c83ae | 6508 | |
e58b0e63 PA |
6509 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
6510 | ORIG is NULL. */ | |
6511 | ||
6512 | struct breakpoint * | |
6513 | clone_momentary_breakpoint (struct breakpoint *orig) | |
6514 | { | |
6515 | struct breakpoint *copy; | |
6516 | ||
6517 | /* If there's nothing to clone, then return nothing. */ | |
6518 | if (orig == NULL) | |
6519 | return NULL; | |
6520 | ||
a6d9a66e | 6521 | copy = set_raw_breakpoint_without_location (orig->gdbarch, orig->type); |
e58b0e63 PA |
6522 | copy->loc = allocate_bp_location (copy); |
6523 | set_breakpoint_location_function (copy->loc); | |
6524 | ||
a6d9a66e | 6525 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
6526 | copy->loc->requested_address = orig->loc->requested_address; |
6527 | copy->loc->address = orig->loc->address; | |
6528 | copy->loc->section = orig->loc->section; | |
6c95b8df | 6529 | copy->loc->pspace = orig->loc->pspace; |
e58b0e63 PA |
6530 | |
6531 | if (orig->source_file == NULL) | |
6532 | copy->source_file = NULL; | |
6533 | else | |
6534 | copy->source_file = xstrdup (orig->source_file); | |
6535 | ||
6536 | copy->line_number = orig->line_number; | |
6537 | copy->frame_id = orig->frame_id; | |
6538 | copy->thread = orig->thread; | |
6c95b8df | 6539 | copy->pspace = orig->pspace; |
e58b0e63 PA |
6540 | |
6541 | copy->enable_state = bp_enabled; | |
6542 | copy->disposition = disp_donttouch; | |
6543 | copy->number = internal_breakpoint_number--; | |
6544 | ||
6545 | update_global_location_list_nothrow (0); | |
6546 | return copy; | |
6547 | } | |
6548 | ||
611c83ae | 6549 | struct breakpoint * |
a6d9a66e UW |
6550 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
6551 | enum bptype type) | |
611c83ae PA |
6552 | { |
6553 | struct symtab_and_line sal; | |
6554 | ||
6555 | sal = find_pc_line (pc, 0); | |
6556 | sal.pc = pc; | |
6557 | sal.section = find_pc_overlay (pc); | |
6558 | sal.explicit_pc = 1; | |
6559 | ||
a6d9a66e | 6560 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 6561 | } |
c906108c | 6562 | \f |
c5aa993b | 6563 | |
c906108c SS |
6564 | /* Tell the user we have just set a breakpoint B. */ |
6565 | ||
6566 | static void | |
fba45db2 | 6567 | mention (struct breakpoint *b) |
c906108c SS |
6568 | { |
6569 | int say_where = 0; | |
fa8a61dc | 6570 | struct cleanup *ui_out_chain; |
79a45b7d TT |
6571 | struct value_print_options opts; |
6572 | ||
6573 | get_user_print_options (&opts); | |
8b93c638 | 6574 | |
9a4105ab AC |
6575 | /* FIXME: This is misplaced; mention() is called by things (like |
6576 | hitting a watchpoint) other than breakpoint creation. It should | |
6577 | be possible to clean this up and at the same time replace the | |
7f4b89d1 | 6578 | random calls to breakpoint_changed with this hook. */ |
383f836e | 6579 | observer_notify_breakpoint_created (b->number); |
c906108c | 6580 | |
3086aeae DJ |
6581 | if (b->ops != NULL && b->ops->print_mention != NULL) |
6582 | b->ops->print_mention (b); | |
6583 | else | |
6584 | switch (b->type) | |
6585 | { | |
6586 | case bp_none: | |
a3f17187 | 6587 | printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b->number); |
3086aeae DJ |
6588 | break; |
6589 | case bp_watchpoint: | |
6590 | ui_out_text (uiout, "Watchpoint "); | |
6591 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
6592 | ui_out_field_int (uiout, "number", b->number); | |
6593 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6594 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6595 | do_cleanups (ui_out_chain); |
6596 | break; | |
6597 | case bp_hardware_watchpoint: | |
6598 | ui_out_text (uiout, "Hardware watchpoint "); | |
6599 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
6600 | ui_out_field_int (uiout, "number", b->number); | |
6601 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6602 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6603 | do_cleanups (ui_out_chain); |
6604 | break; | |
6605 | case bp_read_watchpoint: | |
6606 | ui_out_text (uiout, "Hardware read watchpoint "); | |
6607 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
6608 | ui_out_field_int (uiout, "number", b->number); | |
6609 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6610 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6611 | do_cleanups (ui_out_chain); |
6612 | break; | |
6613 | case bp_access_watchpoint: | |
6614 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
6615 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
6616 | ui_out_field_int (uiout, "number", b->number); | |
6617 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6618 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6619 | do_cleanups (ui_out_chain); |
6620 | break; | |
6621 | case bp_breakpoint: | |
6622 | if (ui_out_is_mi_like_p (uiout)) | |
6623 | { | |
6624 | say_where = 0; | |
6625 | break; | |
6626 | } | |
2cec12e5 AR |
6627 | if (b->disposition == disp_del) |
6628 | printf_filtered (_("Temporary breakpoint")); | |
6629 | else | |
6630 | printf_filtered (_("Breakpoint")); | |
6631 | printf_filtered (_(" %d"), b->number); | |
3086aeae DJ |
6632 | say_where = 1; |
6633 | break; | |
6634 | case bp_hardware_breakpoint: | |
6635 | if (ui_out_is_mi_like_p (uiout)) | |
6636 | { | |
6637 | say_where = 0; | |
6638 | break; | |
6639 | } | |
a3f17187 | 6640 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); |
3086aeae DJ |
6641 | say_where = 1; |
6642 | break; | |
1042e4c0 SS |
6643 | case bp_tracepoint: |
6644 | if (ui_out_is_mi_like_p (uiout)) | |
6645 | { | |
6646 | say_where = 0; | |
6647 | break; | |
6648 | } | |
6649 | printf_filtered (_("Tracepoint")); | |
6650 | printf_filtered (_(" %d"), b->number); | |
6651 | say_where = 1; | |
6652 | break; | |
7a697b8d SS |
6653 | case bp_fast_tracepoint: |
6654 | if (ui_out_is_mi_like_p (uiout)) | |
6655 | { | |
6656 | say_where = 0; | |
6657 | break; | |
6658 | } | |
6659 | printf_filtered (_("Fast tracepoint")); | |
6660 | printf_filtered (_(" %d"), b->number); | |
6661 | say_where = 1; | |
6662 | break; | |
3086aeae DJ |
6663 | |
6664 | case bp_until: | |
6665 | case bp_finish: | |
6666 | case bp_longjmp: | |
6667 | case bp_longjmp_resume: | |
6668 | case bp_step_resume: | |
3086aeae | 6669 | case bp_call_dummy: |
aa7d318d | 6670 | case bp_std_terminate: |
3086aeae DJ |
6671 | case bp_watchpoint_scope: |
6672 | case bp_shlib_event: | |
6673 | case bp_thread_event: | |
6674 | case bp_overlay_event: | |
4efc6507 | 6675 | case bp_jit_event: |
0fd8e87f | 6676 | case bp_longjmp_master: |
aa7d318d | 6677 | case bp_std_terminate_master: |
3086aeae DJ |
6678 | break; |
6679 | } | |
c906108c | 6680 | |
c906108c SS |
6681 | if (say_where) |
6682 | { | |
a3f17187 AC |
6683 | /* i18n: cagney/2005-02-11: Below needs to be merged into a |
6684 | single string. */ | |
0d381245 | 6685 | if (b->loc == NULL) |
c906108c | 6686 | { |
a3f17187 | 6687 | printf_filtered (_(" (%s) pending."), b->addr_string); |
0101ce28 JJ |
6688 | } |
6689 | else | |
6690 | { | |
79a45b7d | 6691 | if (opts.addressprint || b->source_file == NULL) |
0101ce28 JJ |
6692 | { |
6693 | printf_filtered (" at "); | |
5af949e3 UW |
6694 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), |
6695 | gdb_stdout); | |
0101ce28 JJ |
6696 | } |
6697 | if (b->source_file) | |
6698 | printf_filtered (": file %s, line %d.", | |
6699 | b->source_file, b->line_number); | |
0d381245 VP |
6700 | |
6701 | if (b->loc->next) | |
6702 | { | |
6703 | struct bp_location *loc = b->loc; | |
6704 | int n = 0; | |
6705 | for (; loc; loc = loc->next) | |
6706 | ++n; | |
6707 | printf_filtered (" (%d locations)", n); | |
6708 | } | |
6709 | ||
c906108c | 6710 | } |
c906108c | 6711 | } |
9dc5e2a9 | 6712 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 6713 | return; |
c906108c SS |
6714 | printf_filtered ("\n"); |
6715 | } | |
c906108c | 6716 | \f |
c5aa993b | 6717 | |
0d381245 | 6718 | static struct bp_location * |
39d61571 | 6719 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
6720 | const struct symtab_and_line *sal) |
6721 | { | |
6722 | struct bp_location *loc, **tmp; | |
6723 | ||
39d61571 | 6724 | loc = allocate_bp_location (b); |
0d381245 VP |
6725 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
6726 | ; | |
6727 | *tmp = loc; | |
a6d9a66e UW |
6728 | loc->gdbarch = get_sal_arch (*sal); |
6729 | if (!loc->gdbarch) | |
6730 | loc->gdbarch = b->gdbarch; | |
0d381245 | 6731 | loc->requested_address = sal->pc; |
a6d9a66e UW |
6732 | loc->address = adjust_breakpoint_address (loc->gdbarch, |
6733 | loc->requested_address, b->type); | |
6c95b8df PA |
6734 | loc->pspace = sal->pspace; |
6735 | gdb_assert (loc->pspace != NULL); | |
0d381245 VP |
6736 | loc->section = sal->section; |
6737 | ||
6738 | set_breakpoint_location_function (loc); | |
6739 | return loc; | |
6740 | } | |
514f746b AR |
6741 | \f |
6742 | ||
6743 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
6744 | return 0 otherwise. */ | |
6745 | ||
6746 | static int | |
6747 | bp_loc_is_permanent (struct bp_location *loc) | |
6748 | { | |
6749 | int len; | |
6750 | CORE_ADDR addr; | |
6751 | const gdb_byte *brk; | |
6752 | gdb_byte *target_mem; | |
939c61fa JK |
6753 | struct cleanup *cleanup; |
6754 | int retval = 0; | |
514f746b AR |
6755 | |
6756 | gdb_assert (loc != NULL); | |
6757 | ||
6758 | addr = loc->address; | |
a6d9a66e | 6759 | brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 6760 | |
939c61fa JK |
6761 | /* Software breakpoints unsupported? */ |
6762 | if (brk == NULL) | |
6763 | return 0; | |
6764 | ||
514f746b AR |
6765 | target_mem = alloca (len); |
6766 | ||
939c61fa JK |
6767 | /* Enable the automatic memory restoration from breakpoints while |
6768 | we read the memory. Otherwise we could say about our temporary | |
6769 | breakpoints they are permanent. */ | |
6c95b8df PA |
6770 | cleanup = save_current_space_and_thread (); |
6771 | ||
6772 | switch_to_program_space_and_thread (loc->pspace); | |
6773 | make_show_memory_breakpoints_cleanup (0); | |
939c61fa | 6774 | |
514f746b AR |
6775 | if (target_read_memory (loc->address, target_mem, len) == 0 |
6776 | && memcmp (target_mem, brk, len) == 0) | |
939c61fa | 6777 | retval = 1; |
514f746b | 6778 | |
939c61fa JK |
6779 | do_cleanups (cleanup); |
6780 | ||
6781 | return retval; | |
514f746b AR |
6782 | } |
6783 | ||
6784 | ||
c3f6f71d | 6785 | |
018d34a4 VP |
6786 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
6787 | as textual description of the location, and COND_STRING | |
db107f19 | 6788 | as condition expression. */ |
018d34a4 VP |
6789 | |
6790 | static void | |
8cdf0e15 VP |
6791 | create_breakpoint_sal (struct gdbarch *gdbarch, |
6792 | struct symtabs_and_lines sals, char *addr_string, | |
6793 | char *cond_string, | |
6794 | enum bptype type, enum bpdisp disposition, | |
6795 | int thread, int task, int ignore_count, | |
6796 | struct breakpoint_ops *ops, int from_tty, int enabled) | |
018d34a4 | 6797 | { |
0d381245 VP |
6798 | struct breakpoint *b = NULL; |
6799 | int i; | |
018d34a4 VP |
6800 | |
6801 | if (type == bp_hardware_breakpoint) | |
6802 | { | |
6803 | int i = hw_breakpoint_used_count (); | |
6804 | int target_resources_ok = | |
d92524f1 | 6805 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
018d34a4 VP |
6806 | i + 1, 0); |
6807 | if (target_resources_ok == 0) | |
6808 | error (_("No hardware breakpoint support in the target.")); | |
6809 | else if (target_resources_ok < 0) | |
6810 | error (_("Hardware breakpoints used exceeds limit.")); | |
6811 | } | |
6812 | ||
6c95b8df PA |
6813 | gdb_assert (sals.nelts > 0); |
6814 | ||
0d381245 VP |
6815 | for (i = 0; i < sals.nelts; ++i) |
6816 | { | |
6817 | struct symtab_and_line sal = sals.sals[i]; | |
6818 | struct bp_location *loc; | |
6819 | ||
6820 | if (from_tty) | |
5af949e3 UW |
6821 | { |
6822 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
6823 | if (!loc_gdbarch) | |
6824 | loc_gdbarch = gdbarch; | |
6825 | ||
6826 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 6827 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 6828 | } |
0d381245 VP |
6829 | |
6830 | if (i == 0) | |
6831 | { | |
a6d9a66e | 6832 | b = set_raw_breakpoint (gdbarch, sal, type); |
0d381245 VP |
6833 | set_breakpoint_count (breakpoint_count + 1); |
6834 | b->number = breakpoint_count; | |
6835 | b->thread = thread; | |
4a306c9a | 6836 | b->task = task; |
018d34a4 | 6837 | |
0d381245 VP |
6838 | b->cond_string = cond_string; |
6839 | b->ignore_count = ignore_count; | |
41447f92 | 6840 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 6841 | b->disposition = disposition; |
018d34a4 | 6842 | |
6c95b8df PA |
6843 | b->pspace = sals.sals[0].pspace; |
6844 | ||
6845 | if (enabled && b->pspace->executing_startup | |
8bea4e01 UW |
6846 | && (b->type == bp_breakpoint |
6847 | || b->type == bp_hardware_breakpoint)) | |
6848 | b->enable_state = bp_startup_disabled; | |
6849 | ||
0d381245 VP |
6850 | loc = b->loc; |
6851 | } | |
6852 | else | |
018d34a4 | 6853 | { |
39d61571 | 6854 | loc = add_location_to_breakpoint (b, &sal); |
0d381245 VP |
6855 | } |
6856 | ||
514f746b AR |
6857 | if (bp_loc_is_permanent (loc)) |
6858 | make_breakpoint_permanent (b); | |
6859 | ||
0d381245 VP |
6860 | if (b->cond_string) |
6861 | { | |
6862 | char *arg = b->cond_string; | |
d32a6982 | 6863 | loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0); |
0d381245 | 6864 | if (*arg) |
db107f19 | 6865 | error (_("Garbage %s follows condition"), arg); |
018d34a4 | 6866 | } |
0d381245 | 6867 | } |
018d34a4 VP |
6868 | |
6869 | if (addr_string) | |
6870 | b->addr_string = addr_string; | |
6871 | else | |
6872 | /* addr_string has to be used or breakpoint_re_set will delete | |
6873 | me. */ | |
5af949e3 UW |
6874 | b->addr_string |
6875 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
018d34a4 | 6876 | |
604133b5 | 6877 | b->ops = ops; |
018d34a4 VP |
6878 | mention (b); |
6879 | } | |
6880 | ||
ed0616c6 VP |
6881 | /* Remove element at INDEX_TO_REMOVE from SAL, shifting other |
6882 | elements to fill the void space. */ | |
2c0b251b PA |
6883 | static void |
6884 | remove_sal (struct symtabs_and_lines *sal, int index_to_remove) | |
ed0616c6 VP |
6885 | { |
6886 | int i = index_to_remove+1; | |
6887 | int last_index = sal->nelts-1; | |
6888 | ||
6889 | for (;i <= last_index; ++i) | |
6890 | sal->sals[i-1] = sal->sals[i]; | |
6891 | ||
6892 | --(sal->nelts); | |
6893 | } | |
6894 | ||
6c95b8df PA |
6895 | /* If appropriate, obtains all sals that correspond to the same file |
6896 | and line as SAL, in all program spaces. Users debugging with IDEs, | |
6897 | will want to set a breakpoint at foo.c:line, and not really care | |
6898 | about program spaces. This is done only if SAL does not have | |
6899 | explicit PC and has line and file information. If we got just a | |
6900 | single expanded sal, return the original. | |
ed0616c6 | 6901 | |
6c95b8df PA |
6902 | Otherwise, if SAL.explicit_line is not set, filter out all sals for |
6903 | which the name of enclosing function is different from SAL. This | |
6904 | makes sure that if we have breakpoint originally set in template | |
6905 | instantiation, say foo<int>(), we won't expand SAL to locations at | |
6906 | the same line in all existing instantiations of 'foo'. */ | |
ed0616c6 | 6907 | |
2c0b251b | 6908 | static struct symtabs_and_lines |
ed0616c6 VP |
6909 | expand_line_sal_maybe (struct symtab_and_line sal) |
6910 | { | |
6911 | struct symtabs_and_lines expanded; | |
6912 | CORE_ADDR original_pc = sal.pc; | |
6913 | char *original_function = NULL; | |
6914 | int found; | |
6915 | int i; | |
6c95b8df | 6916 | struct cleanup *old_chain; |
ed0616c6 VP |
6917 | |
6918 | /* If we have explicit pc, don't expand. | |
6919 | If we have no line number, we can't expand. */ | |
6920 | if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL) | |
6921 | { | |
6922 | expanded.nelts = 1; | |
6923 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
6924 | expanded.sals[0] = sal; | |
6925 | return expanded; | |
6926 | } | |
6927 | ||
6928 | sal.pc = 0; | |
6c95b8df PA |
6929 | |
6930 | old_chain = save_current_space_and_thread (); | |
6931 | ||
6932 | switch_to_program_space_and_thread (sal.pspace); | |
6933 | ||
ed0616c6 | 6934 | find_pc_partial_function (original_pc, &original_function, NULL, NULL); |
6c95b8df PA |
6935 | |
6936 | /* Note that expand_line_sal visits *all* program spaces. */ | |
ed0616c6 | 6937 | expanded = expand_line_sal (sal); |
6c95b8df | 6938 | |
ed0616c6 VP |
6939 | if (expanded.nelts == 1) |
6940 | { | |
3dba1c98 JB |
6941 | /* We had one sal, we got one sal. Return that sal, adjusting it |
6942 | past the function prologue if necessary. */ | |
ed0616c6 VP |
6943 | xfree (expanded.sals); |
6944 | expanded.nelts = 1; | |
6945 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
6946 | sal.pc = original_pc; | |
6947 | expanded.sals[0] = sal; | |
3dba1c98 | 6948 | skip_prologue_sal (&expanded.sals[0]); |
6c95b8df | 6949 | do_cleanups (old_chain); |
ed0616c6 VP |
6950 | return expanded; |
6951 | } | |
6952 | ||
6953 | if (!sal.explicit_line) | |
6954 | { | |
6955 | CORE_ADDR func_addr, func_end; | |
6956 | for (i = 0; i < expanded.nelts; ++i) | |
6957 | { | |
6958 | CORE_ADDR pc = expanded.sals[i].pc; | |
6959 | char *this_function; | |
6c95b8df PA |
6960 | |
6961 | /* We need to switch threads as well since we're about to | |
6962 | read memory. */ | |
6963 | switch_to_program_space_and_thread (expanded.sals[i].pspace); | |
6964 | ||
ed0616c6 VP |
6965 | if (find_pc_partial_function (pc, &this_function, |
6966 | &func_addr, &func_end)) | |
6967 | { | |
059fb39f PM |
6968 | if (this_function |
6969 | && strcmp (this_function, original_function) != 0) | |
ed0616c6 VP |
6970 | { |
6971 | remove_sal (&expanded, i); | |
6972 | --i; | |
6973 | } | |
ed0616c6 VP |
6974 | } |
6975 | } | |
6976 | } | |
059acae7 UW |
6977 | |
6978 | /* Skip the function prologue if necessary. */ | |
6979 | for (i = 0; i < expanded.nelts; ++i) | |
6980 | skip_prologue_sal (&expanded.sals[i]); | |
ed0616c6 | 6981 | |
6c95b8df PA |
6982 | do_cleanups (old_chain); |
6983 | ||
ed0616c6 VP |
6984 | if (expanded.nelts <= 1) |
6985 | { | |
6986 | /* This is un ugly workaround. If we get zero | |
6987 | expanded sals then something is really wrong. | |
6988 | Fix that by returnign the original sal. */ | |
6989 | xfree (expanded.sals); | |
6990 | expanded.nelts = 1; | |
6991 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
6992 | sal.pc = original_pc; | |
6993 | expanded.sals[0] = sal; | |
6994 | return expanded; | |
6995 | } | |
6996 | ||
6997 | if (original_pc) | |
6998 | { | |
6999 | found = 0; | |
7000 | for (i = 0; i < expanded.nelts; ++i) | |
7001 | if (expanded.sals[i].pc == original_pc) | |
7002 | { | |
7003 | found = 1; | |
7004 | break; | |
7005 | } | |
7006 | gdb_assert (found); | |
7007 | } | |
7008 | ||
7009 | return expanded; | |
7010 | } | |
7011 | ||
018d34a4 VP |
7012 | /* Add SALS.nelts breakpoints to the breakpoint table. For each |
7013 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
7014 | value. COND_STRING, if not NULL, specified the condition to be | |
7015 | used for all breakpoints. Essentially the only case where | |
7016 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
7017 | function. In that case, it's still not possible to specify | |
7018 | separate conditions for different overloaded functions, so | |
7019 | we take just a single condition string. | |
7020 | ||
c3f6f71d | 7021 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 7022 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
7023 | array contents). If the function fails (error() is called), the |
7024 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
7025 | COND and SALS arrays and each of those arrays contents. */ | |
c906108c SS |
7026 | |
7027 | static void | |
8cdf0e15 VP |
7028 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7029 | struct symtabs_and_lines sals, char **addr_string, | |
7030 | char *cond_string, | |
7031 | enum bptype type, enum bpdisp disposition, | |
7032 | int thread, int task, int ignore_count, | |
7033 | struct breakpoint_ops *ops, int from_tty, | |
7034 | int enabled) | |
c906108c | 7035 | { |
018d34a4 VP |
7036 | int i; |
7037 | for (i = 0; i < sals.nelts; ++i) | |
c3f6f71d | 7038 | { |
ed0616c6 VP |
7039 | struct symtabs_and_lines expanded = |
7040 | expand_line_sal_maybe (sals.sals[i]); | |
0d381245 | 7041 | |
8cdf0e15 VP |
7042 | create_breakpoint_sal (gdbarch, expanded, addr_string[i], |
7043 | cond_string, type, disposition, | |
7044 | thread, task, ignore_count, ops, from_tty, enabled); | |
c3f6f71d | 7045 | } |
c3f6f71d | 7046 | } |
c906108c | 7047 | |
c3f6f71d JM |
7048 | /* Parse ARG which is assumed to be a SAL specification possibly |
7049 | followed by conditionals. On return, SALS contains an array of SAL | |
7050 | addresses found. ADDR_STRING contains a vector of (canonical) | |
7051 | address strings. ARG points to the end of the SAL. */ | |
c906108c | 7052 | |
b9362cc7 | 7053 | static void |
c3f6f71d JM |
7054 | parse_breakpoint_sals (char **address, |
7055 | struct symtabs_and_lines *sals, | |
0101ce28 JJ |
7056 | char ***addr_string, |
7057 | int *not_found_ptr) | |
c3f6f71d JM |
7058 | { |
7059 | char *addr_start = *address; | |
7060 | *addr_string = NULL; | |
7061 | /* If no arg given, or if first arg is 'if ', use the default | |
7062 | breakpoint. */ | |
7063 | if ((*address) == NULL | |
7064 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c SS |
7065 | { |
7066 | if (default_breakpoint_valid) | |
7067 | { | |
c3f6f71d | 7068 | struct symtab_and_line sal; |
fe39c653 | 7069 | init_sal (&sal); /* initialize to zeroes */ |
c3f6f71d | 7070 | sals->sals = (struct symtab_and_line *) |
c906108c SS |
7071 | xmalloc (sizeof (struct symtab_and_line)); |
7072 | sal.pc = default_breakpoint_address; | |
7073 | sal.line = default_breakpoint_line; | |
7074 | sal.symtab = default_breakpoint_symtab; | |
6c95b8df | 7075 | sal.pspace = default_breakpoint_pspace; |
c5aa993b | 7076 | sal.section = find_pc_overlay (sal.pc); |
00903456 JK |
7077 | |
7078 | /* "break" without arguments is equivalent to "break *PC" where PC is | |
7079 | the default_breakpoint_address. So make sure to set | |
7080 | sal.explicit_pc to prevent GDB from trying to expand the list of | |
7081 | sals to include all other instances with the same symtab and line. | |
7082 | */ | |
7083 | sal.explicit_pc = 1; | |
7084 | ||
c3f6f71d JM |
7085 | sals->sals[0] = sal; |
7086 | sals->nelts = 1; | |
c906108c SS |
7087 | } |
7088 | else | |
8a3fe4f8 | 7089 | error (_("No default breakpoint address now.")); |
c906108c SS |
7090 | } |
7091 | else | |
7092 | { | |
c906108c | 7093 | /* Force almost all breakpoints to be in terms of the |
c5aa993b JM |
7094 | current_source_symtab (which is decode_line_1's default). This |
7095 | should produce the results we want almost all of the time while | |
1aeae86e AF |
7096 | leaving default_breakpoint_* alone. |
7097 | ObjC: However, don't match an Objective-C method name which | |
7098 | may have a '+' or '-' succeeded by a '[' */ | |
0378c332 | 7099 | |
c214a6fd | 7100 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
0378c332 | 7101 | |
c906108c | 7102 | if (default_breakpoint_valid |
0378c332 | 7103 | && (!cursal.symtab |
1aeae86e AF |
7104 | || ((strchr ("+-", (*address)[0]) != NULL) |
7105 | && ((*address)[1] != '[')))) | |
c3f6f71d | 7106 | *sals = decode_line_1 (address, 1, default_breakpoint_symtab, |
0101ce28 JJ |
7107 | default_breakpoint_line, addr_string, |
7108 | not_found_ptr); | |
c906108c | 7109 | else |
0101ce28 JJ |
7110 | *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, |
7111 | addr_string, not_found_ptr); | |
c906108c | 7112 | } |
c3f6f71d JM |
7113 | /* For any SAL that didn't have a canonical string, fill one in. */ |
7114 | if (sals->nelts > 0 && *addr_string == NULL) | |
7115 | *addr_string = xcalloc (sals->nelts, sizeof (char **)); | |
7116 | if (addr_start != (*address)) | |
c906108c | 7117 | { |
c3f6f71d JM |
7118 | int i; |
7119 | for (i = 0; i < sals->nelts; i++) | |
c906108c | 7120 | { |
c3f6f71d JM |
7121 | /* Add the string if not present. */ |
7122 | if ((*addr_string)[i] == NULL) | |
7123 | (*addr_string)[i] = savestring (addr_start, (*address) - addr_start); | |
c906108c SS |
7124 | } |
7125 | } | |
c3f6f71d | 7126 | } |
c906108c | 7127 | |
c906108c | 7128 | |
c3f6f71d JM |
7129 | /* Convert each SAL into a real PC. Verify that the PC can be |
7130 | inserted as a breakpoint. If it can't throw an error. */ | |
c906108c | 7131 | |
b9362cc7 | 7132 | static void |
c3f6f71d JM |
7133 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals, |
7134 | char *address) | |
7135 | { | |
7136 | int i; | |
7137 | for (i = 0; i < sals->nelts; i++) | |
ee53e872 | 7138 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
7139 | } |
7140 | ||
7a697b8d SS |
7141 | /* Fast tracepoints may have restrictions on valid locations. For |
7142 | instance, a fast tracepoint using a jump instead of a trap will | |
7143 | likely have to overwrite more bytes than a trap would, and so can | |
7144 | only be placed where the instruction is longer than the jump, or a | |
7145 | multi-instruction sequence does not have a jump into the middle of | |
7146 | it, etc. */ | |
7147 | ||
7148 | static void | |
7149 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
7150 | struct symtabs_and_lines *sals) | |
7151 | { | |
7152 | int i, rslt; | |
7153 | struct symtab_and_line *sal; | |
7154 | char *msg; | |
7155 | struct cleanup *old_chain; | |
7156 | ||
7157 | for (i = 0; i < sals->nelts; i++) | |
7158 | { | |
7159 | sal = &sals->sals[i]; | |
7160 | ||
7161 | rslt = gdbarch_fast_tracepoint_valid_at (gdbarch, sal->pc, | |
7162 | NULL, &msg); | |
7163 | old_chain = make_cleanup (xfree, msg); | |
7164 | ||
7165 | if (!rslt) | |
7166 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
7167 | paddress (gdbarch, sal->pc), (msg ? msg : "")); | |
7168 | ||
7169 | do_cleanups (old_chain); | |
7170 | } | |
7171 | } | |
7172 | ||
05ff989b | 7173 | static void |
0101ce28 JJ |
7174 | do_captured_parse_breakpoint (struct ui_out *ui, void *data) |
7175 | { | |
7176 | struct captured_parse_breakpoint_args *args = data; | |
7177 | ||
7178 | parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p, | |
7179 | args->not_found_ptr); | |
0101ce28 JJ |
7180 | } |
7181 | ||
018d34a4 VP |
7182 | /* Given TOK, a string specification of condition and thread, as |
7183 | accepted by the 'break' command, extract the condition | |
7184 | string and thread number and set *COND_STRING and *THREAD. | |
7185 | PC identifies the context at which the condition should be parsed. | |
7186 | If no condition is found, *COND_STRING is set to NULL. | |
7187 | If no thread is found, *THREAD is set to -1. */ | |
7188 | static void | |
7189 | find_condition_and_thread (char *tok, CORE_ADDR pc, | |
4a306c9a | 7190 | char **cond_string, int *thread, int *task) |
018d34a4 VP |
7191 | { |
7192 | *cond_string = NULL; | |
7193 | *thread = -1; | |
7194 | while (tok && *tok) | |
7195 | { | |
7196 | char *end_tok; | |
7197 | int toklen; | |
7198 | char *cond_start = NULL; | |
7199 | char *cond_end = NULL; | |
7200 | while (*tok == ' ' || *tok == '\t') | |
7201 | tok++; | |
7202 | ||
7203 | end_tok = tok; | |
7204 | ||
7205 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
7206 | end_tok++; | |
7207 | ||
7208 | toklen = end_tok - tok; | |
7209 | ||
7210 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
7211 | { | |
f7545552 TT |
7212 | struct expression *expr; |
7213 | ||
018d34a4 | 7214 | tok = cond_start = end_tok + 1; |
f7545552 TT |
7215 | expr = parse_exp_1 (&tok, block_for_pc (pc), 0); |
7216 | xfree (expr); | |
018d34a4 VP |
7217 | cond_end = tok; |
7218 | *cond_string = savestring (cond_start, | |
7219 | cond_end - cond_start); | |
7220 | } | |
7221 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
7222 | { | |
7223 | char *tmptok; | |
7224 | ||
7225 | tok = end_tok + 1; | |
7226 | tmptok = tok; | |
7227 | *thread = strtol (tok, &tok, 0); | |
7228 | if (tok == tmptok) | |
7229 | error (_("Junk after thread keyword.")); | |
7230 | if (!valid_thread_id (*thread)) | |
7231 | error (_("Unknown thread %d."), *thread); | |
7232 | } | |
4a306c9a JB |
7233 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
7234 | { | |
7235 | char *tmptok; | |
7236 | ||
7237 | tok = end_tok + 1; | |
7238 | tmptok = tok; | |
7239 | *task = strtol (tok, &tok, 0); | |
7240 | if (tok == tmptok) | |
7241 | error (_("Junk after task keyword.")); | |
7242 | if (!valid_task_id (*task)) | |
b6199126 | 7243 | error (_("Unknown task %d."), *task); |
4a306c9a | 7244 | } |
018d34a4 VP |
7245 | else |
7246 | error (_("Junk at end of arguments.")); | |
7247 | } | |
7248 | } | |
7249 | ||
fd9b8c24 PA |
7250 | /* Set a breakpoint. This function is shared between CLI and MI |
7251 | functions for setting a breakpoint. This function has two major | |
7252 | modes of operations, selected by the PARSE_CONDITION_AND_THREAD | |
7253 | parameter. If non-zero, the function will parse arg, extracting | |
7254 | breakpoint location, address and thread. Otherwise, ARG is just the | |
7255 | location of breakpoint, with condition and thread specified by the | |
7256 | COND_STRING and THREAD parameters. Returns true if any breakpoint | |
7257 | was created; false otherwise. */ | |
0101ce28 | 7258 | |
8cdf0e15 VP |
7259 | int |
7260 | create_breakpoint (struct gdbarch *gdbarch, | |
7261 | char *arg, char *cond_string, int thread, | |
7262 | int parse_condition_and_thread, | |
7263 | int tempflag, int hardwareflag, int traceflag, | |
7264 | int ignore_count, | |
7265 | enum auto_boolean pending_break_support, | |
7266 | struct breakpoint_ops *ops, | |
7267 | int from_tty, | |
7268 | int enabled) | |
c3f6f71d | 7269 | { |
71fff37b | 7270 | struct gdb_exception e; |
c3f6f71d | 7271 | struct symtabs_and_lines sals; |
0101ce28 | 7272 | struct symtab_and_line pending_sal; |
0101ce28 JJ |
7273 | char *copy_arg; |
7274 | char *err_msg; | |
c3f6f71d JM |
7275 | char *addr_start = arg; |
7276 | char **addr_string; | |
7277 | struct cleanup *old_chain; | |
80c99de1 | 7278 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 7279 | struct captured_parse_breakpoint_args parse_args; |
05ff989b | 7280 | int i; |
0101ce28 | 7281 | int pending = 0; |
0101ce28 | 7282 | int not_found = 0; |
1042e4c0 | 7283 | enum bptype type_wanted; |
4a306c9a | 7284 | int task = 0; |
86b17b60 | 7285 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 7286 | |
c3f6f71d JM |
7287 | sals.sals = NULL; |
7288 | sals.nelts = 0; | |
7289 | addr_string = NULL; | |
c3f6f71d | 7290 | |
0101ce28 JJ |
7291 | parse_args.arg_p = &arg; |
7292 | parse_args.sals_p = &sals; | |
7293 | parse_args.addr_string_p = &addr_string; | |
7294 | parse_args.not_found_ptr = ¬_found; | |
7295 | ||
05ff989b AC |
7296 | e = catch_exception (uiout, do_captured_parse_breakpoint, |
7297 | &parse_args, RETURN_MASK_ALL); | |
0101ce28 JJ |
7298 | |
7299 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 7300 | switch (e.reason) |
0101ce28 | 7301 | { |
05ff989b | 7302 | case RETURN_QUIT: |
98deb0da | 7303 | throw_exception (e); |
05ff989b AC |
7304 | case RETURN_ERROR: |
7305 | switch (e.error) | |
0101ce28 | 7306 | { |
05ff989b | 7307 | case NOT_FOUND_ERROR: |
0101ce28 | 7308 | |
05ff989b AC |
7309 | /* If pending breakpoint support is turned off, throw |
7310 | error. */ | |
fa8d40ab JJ |
7311 | |
7312 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
7313 | throw_exception (e); |
7314 | ||
7315 | exception_print (gdb_stderr, e); | |
fa8d40ab | 7316 | |
05ff989b AC |
7317 | /* If pending breakpoint support is auto query and the user |
7318 | selects no, then simply return the error code. */ | |
059fb39f PM |
7319 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
7320 | && !nquery ("Make breakpoint pending on future shared library load? ")) | |
fd9b8c24 | 7321 | return 0; |
fa8d40ab | 7322 | |
05ff989b AC |
7323 | /* At this point, either the user was queried about setting |
7324 | a pending breakpoint and selected yes, or pending | |
7325 | breakpoint behavior is on and thus a pending breakpoint | |
7326 | is defaulted on behalf of the user. */ | |
0101ce28 JJ |
7327 | copy_arg = xstrdup (addr_start); |
7328 | addr_string = ©_arg; | |
7329 | sals.nelts = 1; | |
7330 | sals.sals = &pending_sal; | |
7331 | pending_sal.pc = 0; | |
7332 | pending = 1; | |
05ff989b AC |
7333 | break; |
7334 | default: | |
98deb0da | 7335 | throw_exception (e); |
0101ce28 | 7336 | } |
05ff989b AC |
7337 | default: |
7338 | if (!sals.nelts) | |
fd9b8c24 | 7339 | return 0; |
0101ce28 | 7340 | } |
c3f6f71d JM |
7341 | |
7342 | /* Create a chain of things that always need to be cleaned up. */ | |
7343 | old_chain = make_cleanup (null_cleanup, 0); | |
7344 | ||
0101ce28 JJ |
7345 | if (!pending) |
7346 | { | |
7347 | /* Make sure that all storage allocated to SALS gets freed. */ | |
7348 | make_cleanup (xfree, sals.sals); | |
7349 | ||
7350 | /* Cleanup the addr_string array but not its contents. */ | |
7351 | make_cleanup (xfree, addr_string); | |
7352 | } | |
c3f6f71d | 7353 | |
c3f6f71d JM |
7354 | /* ----------------------------- SNIP ----------------------------- |
7355 | Anything added to the cleanup chain beyond this point is assumed | |
7356 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
7357 | then the memory is not reclaimed. */ |
7358 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d JM |
7359 | |
7360 | /* Mark the contents of the addr_string for cleanup. These go on | |
80c99de1 | 7361 | the bkpt_chain and only occur if the breakpoint create fails. */ |
c3f6f71d JM |
7362 | for (i = 0; i < sals.nelts; i++) |
7363 | { | |
7364 | if (addr_string[i] != NULL) | |
b8c9b27d | 7365 | make_cleanup (xfree, addr_string[i]); |
c3f6f71d JM |
7366 | } |
7367 | ||
7368 | /* Resolve all line numbers to PC's and verify that the addresses | |
7369 | are ok for the target. */ | |
0101ce28 JJ |
7370 | if (!pending) |
7371 | breakpoint_sals_to_pc (&sals, addr_start); | |
c3f6f71d | 7372 | |
1042e4c0 | 7373 | type_wanted = (traceflag |
7a697b8d | 7374 | ? (hardwareflag ? bp_fast_tracepoint : bp_tracepoint) |
1042e4c0 SS |
7375 | : (hardwareflag ? bp_hardware_breakpoint : bp_breakpoint)); |
7376 | ||
7a697b8d SS |
7377 | /* Fast tracepoints may have additional restrictions on location. */ |
7378 | if (type_wanted == bp_fast_tracepoint) | |
7379 | check_fast_tracepoint_sals (gdbarch, &sals); | |
7380 | ||
c3f6f71d JM |
7381 | /* Verify that condition can be parsed, before setting any |
7382 | breakpoints. Allocate a separate condition expression for each | |
7383 | breakpoint. */ | |
0101ce28 | 7384 | if (!pending) |
c3f6f71d | 7385 | { |
2f069f6f | 7386 | if (parse_condition_and_thread) |
72b2ff0e VP |
7387 | { |
7388 | /* Here we only parse 'arg' to separate condition | |
7389 | from thread number, so parsing in context of first | |
7390 | sal is OK. When setting the breakpoint we'll | |
7391 | re-parse it in context of each sal. */ | |
7392 | cond_string = NULL; | |
7393 | thread = -1; | |
4a306c9a JB |
7394 | find_condition_and_thread (arg, sals.sals[0].pc, &cond_string, |
7395 | &thread, &task); | |
72b2ff0e VP |
7396 | if (cond_string) |
7397 | make_cleanup (xfree, cond_string); | |
7398 | } | |
2f069f6f | 7399 | else |
72b2ff0e VP |
7400 | { |
7401 | /* Create a private copy of condition string. */ | |
7402 | if (cond_string) | |
7403 | { | |
7404 | cond_string = xstrdup (cond_string); | |
7405 | make_cleanup (xfree, cond_string); | |
7406 | } | |
7407 | } | |
8cdf0e15 VP |
7408 | create_breakpoints_sal (gdbarch, sals, addr_string, cond_string, |
7409 | type_wanted, tempflag ? disp_del : disp_donttouch, | |
7410 | thread, task, ignore_count, ops, from_tty, | |
7411 | enabled); | |
c906108c | 7412 | } |
0101ce28 JJ |
7413 | else |
7414 | { | |
fe3f5fa8 | 7415 | struct symtab_and_line sal = {0}; |
0101ce28 JJ |
7416 | struct breakpoint *b; |
7417 | ||
0101ce28 JJ |
7418 | make_cleanup (xfree, copy_arg); |
7419 | ||
a6d9a66e | 7420 | b = set_raw_breakpoint_without_location (gdbarch, type_wanted); |
0101ce28 JJ |
7421 | set_breakpoint_count (breakpoint_count + 1); |
7422 | b->number = breakpoint_count; | |
72b2ff0e | 7423 | b->thread = -1; |
018d34a4 | 7424 | b->addr_string = addr_string[0]; |
72b2ff0e | 7425 | b->cond_string = NULL; |
0101ce28 | 7426 | b->ignore_count = ignore_count; |
0101ce28 | 7427 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 7428 | b->condition_not_parsed = 1; |
604133b5 | 7429 | b->ops = ops; |
41447f92 | 7430 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
6c95b8df | 7431 | b->pspace = current_program_space; |
74960c60 | 7432 | |
6c95b8df | 7433 | if (enabled && b->pspace->executing_startup |
8bea4e01 UW |
7434 | && (b->type == bp_breakpoint |
7435 | || b->type == bp_hardware_breakpoint)) | |
7436 | b->enable_state = bp_startup_disabled; | |
7437 | ||
0101ce28 JJ |
7438 | mention (b); |
7439 | } | |
7440 | ||
c3f6f71d | 7441 | if (sals.nelts > 1) |
95a42b64 TT |
7442 | { |
7443 | warning (_("Multiple breakpoints were set.\n" | |
7444 | "Use the \"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 7445 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
7446 | } |
7447 | ||
80c99de1 PA |
7448 | /* That's it. Discard the cleanups for data inserted into the |
7449 | breakpoint. */ | |
7450 | discard_cleanups (bkpt_chain); | |
7451 | /* But cleanup everything else. */ | |
c3f6f71d | 7452 | do_cleanups (old_chain); |
217dc9e2 | 7453 | |
80c99de1 | 7454 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
217dc9e2 | 7455 | update_global_location_list (1); |
fd9b8c24 PA |
7456 | |
7457 | return 1; | |
c3f6f71d | 7458 | } |
c906108c | 7459 | |
72b2ff0e VP |
7460 | /* Set a breakpoint. |
7461 | ARG is a string describing breakpoint address, | |
7462 | condition, and thread. | |
7463 | FLAG specifies if a breakpoint is hardware on, | |
7464 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
7465 | and BP_TEMPFLAG. */ | |
7466 | ||
98deb0da | 7467 | static void |
72b2ff0e | 7468 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 7469 | { |
72b2ff0e VP |
7470 | int hardwareflag = flag & BP_HARDWAREFLAG; |
7471 | int tempflag = flag & BP_TEMPFLAG; | |
c3f6f71d | 7472 | |
8cdf0e15 VP |
7473 | create_breakpoint (get_current_arch (), |
7474 | arg, | |
7475 | NULL, 0, 1 /* parse arg */, | |
7476 | tempflag, hardwareflag, 0 /* traceflag */, | |
7477 | 0 /* Ignore count */, | |
7478 | pending_break_support, | |
7479 | NULL /* breakpoint_ops */, | |
7480 | from_tty, | |
7481 | 1 /* enabled */); | |
c906108c SS |
7482 | } |
7483 | ||
72b2ff0e | 7484 | |
c3f6f71d | 7485 | |
c906108c SS |
7486 | /* Helper function for break_command_1 and disassemble_command. */ |
7487 | ||
7488 | void | |
fba45db2 | 7489 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
7490 | { |
7491 | CORE_ADDR pc; | |
7492 | ||
7493 | if (sal->pc == 0 && sal->symtab != NULL) | |
7494 | { | |
7495 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 7496 | error (_("No line %d in file \"%s\"."), |
c906108c SS |
7497 | sal->line, sal->symtab->filename); |
7498 | sal->pc = pc; | |
6a048695 JB |
7499 | |
7500 | /* If this SAL corresponds to a breakpoint inserted using | |
7501 | a line number, then skip the function prologue if necessary. */ | |
7502 | if (sal->explicit_line) | |
059acae7 | 7503 | skip_prologue_sal (sal); |
c906108c SS |
7504 | } |
7505 | ||
7506 | if (sal->section == 0 && sal->symtab != NULL) | |
7507 | { | |
7508 | struct blockvector *bv; | |
c5aa993b JM |
7509 | struct block *b; |
7510 | struct symbol *sym; | |
c906108c | 7511 | |
801e3a5b | 7512 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
7513 | if (bv != NULL) |
7514 | { | |
7f0df278 | 7515 | sym = block_linkage_function (b); |
c906108c SS |
7516 | if (sym != NULL) |
7517 | { | |
7518 | fixup_symbol_section (sym, sal->symtab->objfile); | |
714835d5 | 7519 | sal->section = SYMBOL_OBJ_SECTION (sym); |
c906108c SS |
7520 | } |
7521 | else | |
7522 | { | |
7523 | /* It really is worthwhile to have the section, so we'll just | |
c5aa993b JM |
7524 | have to look harder. This case can be executed if we have |
7525 | line numbers but no functions (as can happen in assembly | |
7526 | source). */ | |
c906108c | 7527 | |
c5aa993b | 7528 | struct minimal_symbol *msym; |
6c95b8df PA |
7529 | struct cleanup *old_chain = save_current_space_and_thread (); |
7530 | ||
7531 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
7532 | |
7533 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
7534 | if (msym) | |
714835d5 | 7535 | sal->section = SYMBOL_OBJ_SECTION (msym); |
6c95b8df PA |
7536 | |
7537 | do_cleanups (old_chain); | |
c906108c SS |
7538 | } |
7539 | } | |
7540 | } | |
7541 | } | |
7542 | ||
7543 | void | |
fba45db2 | 7544 | break_command (char *arg, int from_tty) |
c906108c | 7545 | { |
db107f19 | 7546 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
7547 | } |
7548 | ||
c906108c | 7549 | void |
fba45db2 | 7550 | tbreak_command (char *arg, int from_tty) |
c906108c | 7551 | { |
db107f19 | 7552 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
7553 | } |
7554 | ||
c906108c | 7555 | static void |
fba45db2 | 7556 | hbreak_command (char *arg, int from_tty) |
c906108c | 7557 | { |
db107f19 | 7558 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
7559 | } |
7560 | ||
7561 | static void | |
fba45db2 | 7562 | thbreak_command (char *arg, int from_tty) |
c906108c | 7563 | { |
db107f19 | 7564 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
7565 | } |
7566 | ||
7567 | static void | |
fba45db2 | 7568 | stop_command (char *arg, int from_tty) |
c906108c | 7569 | { |
a3f17187 | 7570 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 7571 | Usage: stop in <function | address>\n\ |
a3f17187 | 7572 | stop at <line>\n")); |
c906108c SS |
7573 | } |
7574 | ||
7575 | static void | |
fba45db2 | 7576 | stopin_command (char *arg, int from_tty) |
c906108c SS |
7577 | { |
7578 | int badInput = 0; | |
7579 | ||
c5aa993b | 7580 | if (arg == (char *) NULL) |
c906108c SS |
7581 | badInput = 1; |
7582 | else if (*arg != '*') | |
7583 | { | |
7584 | char *argptr = arg; | |
7585 | int hasColon = 0; | |
7586 | ||
53a5351d JM |
7587 | /* look for a ':'. If this is a line number specification, then |
7588 | say it is bad, otherwise, it should be an address or | |
7589 | function/method name */ | |
c906108c | 7590 | while (*argptr && !hasColon) |
c5aa993b JM |
7591 | { |
7592 | hasColon = (*argptr == ':'); | |
7593 | argptr++; | |
7594 | } | |
c906108c SS |
7595 | |
7596 | if (hasColon) | |
c5aa993b | 7597 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 7598 | else |
c5aa993b | 7599 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
7600 | } |
7601 | ||
7602 | if (badInput) | |
a3f17187 | 7603 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 7604 | else |
db107f19 | 7605 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
7606 | } |
7607 | ||
7608 | static void | |
fba45db2 | 7609 | stopat_command (char *arg, int from_tty) |
c906108c SS |
7610 | { |
7611 | int badInput = 0; | |
7612 | ||
c5aa993b | 7613 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
7614 | badInput = 1; |
7615 | else | |
7616 | { | |
7617 | char *argptr = arg; | |
7618 | int hasColon = 0; | |
7619 | ||
7620 | /* look for a ':'. If there is a '::' then get out, otherwise | |
c5aa993b | 7621 | it is probably a line number. */ |
c906108c | 7622 | while (*argptr && !hasColon) |
c5aa993b JM |
7623 | { |
7624 | hasColon = (*argptr == ':'); | |
7625 | argptr++; | |
7626 | } | |
c906108c SS |
7627 | |
7628 | if (hasColon) | |
c5aa993b | 7629 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 7630 | else |
c5aa993b | 7631 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
7632 | } |
7633 | ||
7634 | if (badInput) | |
a3f17187 | 7635 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 7636 | else |
db107f19 | 7637 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
7638 | } |
7639 | ||
53a5351d JM |
7640 | /* accessflag: hw_write: watch write, |
7641 | hw_read: watch read, | |
7642 | hw_access: watch access (read or write) */ | |
c906108c | 7643 | static void |
fba45db2 | 7644 | watch_command_1 (char *arg, int accessflag, int from_tty) |
c906108c | 7645 | { |
a6d9a66e | 7646 | struct gdbarch *gdbarch = get_current_arch (); |
d983da9c | 7647 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c | 7648 | struct expression *exp; |
60e1c644 | 7649 | struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
c906108c SS |
7650 | struct value *val, *mark; |
7651 | struct frame_info *frame; | |
c906108c SS |
7652 | char *exp_start = NULL; |
7653 | char *exp_end = NULL; | |
37e4754d | 7654 | char *tok, *id_tok_start, *end_tok; |
c906108c SS |
7655 | int toklen; |
7656 | char *cond_start = NULL; | |
7657 | char *cond_end = NULL; | |
c906108c SS |
7658 | int i, other_type_used, target_resources_ok = 0; |
7659 | enum bptype bp_type; | |
7660 | int mem_cnt = 0; | |
37e4754d | 7661 | int thread = -1; |
c906108c | 7662 | |
37e4754d LM |
7663 | /* Make sure that we actually have parameters to parse. */ |
7664 | if (arg != NULL && arg[0] != '\0') | |
7665 | { | |
7666 | toklen = strlen (arg); /* Size of argument list. */ | |
7667 | ||
7668 | /* Points tok to the end of the argument list. */ | |
7669 | tok = arg + toklen - 1; | |
7670 | ||
7671 | /* Go backwards in the parameters list. Skip the last parameter. | |
7672 | If we're expecting a 'thread <thread_num>' parameter, this should | |
7673 | be the thread identifier. */ | |
7674 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
7675 | tok--; | |
7676 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
7677 | tok--; | |
7678 | ||
7679 | /* Points end_tok to the beginning of the last token. */ | |
7680 | id_tok_start = tok + 1; | |
7681 | ||
7682 | /* Go backwards in the parameters list. Skip one more parameter. | |
7683 | If we're expecting a 'thread <thread_num>' parameter, we should | |
7684 | reach a "thread" token. */ | |
7685 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
7686 | tok--; | |
7687 | ||
7688 | end_tok = tok; | |
7689 | ||
7690 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
7691 | tok--; | |
7692 | ||
7693 | /* Move the pointer forward to skip the whitespace and | |
7694 | calculate the length of the token. */ | |
7695 | tok++; | |
7696 | toklen = end_tok - tok; | |
7697 | ||
7698 | if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
7699 | { | |
7700 | /* At this point we've found a "thread" token, which means | |
7701 | the user is trying to set a watchpoint that triggers | |
7702 | only in a specific thread. */ | |
7703 | char *endp; | |
7704 | ||
7705 | /* Extract the thread ID from the next token. */ | |
7706 | thread = strtol (id_tok_start, &endp, 0); | |
7707 | ||
7708 | /* Check if the user provided a valid numeric value for the | |
7709 | thread ID. */ | |
7710 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
7711 | error (_("Invalid thread ID specification %s."), id_tok_start); | |
7712 | ||
7713 | /* Check if the thread actually exists. */ | |
7714 | if (!valid_thread_id (thread)) | |
7715 | error (_("Unknown thread %d."), thread); | |
7716 | ||
7717 | /* Truncate the string and get rid of the thread <thread_num> | |
7718 | parameter before the parameter list is parsed by the | |
7719 | evaluate_expression() function. */ | |
7720 | *tok = '\0'; | |
7721 | } | |
7722 | } | |
7723 | ||
7724 | /* Parse the rest of the arguments. */ | |
c906108c SS |
7725 | innermost_block = NULL; |
7726 | exp_start = arg; | |
7727 | exp = parse_exp_1 (&arg, 0, 0); | |
7728 | exp_end = arg; | |
fa8a61dc TT |
7729 | /* Remove trailing whitespace from the expression before saving it. |
7730 | This makes the eventual display of the expression string a bit | |
7731 | prettier. */ | |
7732 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
7733 | --exp_end; | |
7734 | ||
c906108c SS |
7735 | exp_valid_block = innermost_block; |
7736 | mark = value_mark (); | |
fa4727a6 DJ |
7737 | fetch_watchpoint_value (exp, &val, NULL, NULL); |
7738 | if (val != NULL) | |
7739 | release_value (val); | |
c906108c SS |
7740 | |
7741 | tok = arg; | |
7742 | while (*tok == ' ' || *tok == '\t') | |
7743 | tok++; | |
7744 | end_tok = tok; | |
7745 | ||
7746 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
7747 | end_tok++; | |
7748 | ||
7749 | toklen = end_tok - tok; | |
7750 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
7751 | { | |
2d134ed3 PA |
7752 | struct expression *cond; |
7753 | ||
60e1c644 | 7754 | innermost_block = NULL; |
c906108c SS |
7755 | tok = cond_start = end_tok + 1; |
7756 | cond = parse_exp_1 (&tok, 0, 0); | |
60e1c644 PA |
7757 | |
7758 | /* The watchpoint expression may not be local, but the condition | |
7759 | may still be. E.g.: `watch global if local > 0'. */ | |
7760 | cond_exp_valid_block = innermost_block; | |
7761 | ||
2d134ed3 | 7762 | xfree (cond); |
c906108c SS |
7763 | cond_end = tok; |
7764 | } | |
7765 | if (*tok) | |
8a3fe4f8 | 7766 | error (_("Junk at end of command.")); |
c906108c | 7767 | |
53a5351d | 7768 | if (accessflag == hw_read) |
c5aa993b | 7769 | bp_type = bp_read_watchpoint; |
53a5351d | 7770 | else if (accessflag == hw_access) |
c5aa993b JM |
7771 | bp_type = bp_access_watchpoint; |
7772 | else | |
7773 | bp_type = bp_hardware_watchpoint; | |
c906108c SS |
7774 | |
7775 | mem_cnt = can_use_hardware_watchpoint (val); | |
7776 | if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint) | |
8a3fe4f8 | 7777 | error (_("Expression cannot be implemented with read/access watchpoint.")); |
c5aa993b JM |
7778 | if (mem_cnt != 0) |
7779 | { | |
7780 | i = hw_watchpoint_used_count (bp_type, &other_type_used); | |
53a5351d | 7781 | target_resources_ok = |
d92524f1 | 7782 | target_can_use_hardware_watchpoint (bp_type, i + mem_cnt, |
53a5351d | 7783 | other_type_used); |
c5aa993b | 7784 | if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint) |
8a3fe4f8 | 7785 | error (_("Target does not support this type of hardware watchpoint.")); |
53a5351d | 7786 | |
c5aa993b | 7787 | if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint) |
8a3fe4f8 | 7788 | error (_("Target can only support one kind of HW watchpoint at a time.")); |
c5aa993b | 7789 | } |
c906108c | 7790 | |
4d28f7a8 KB |
7791 | /* Change the type of breakpoint to an ordinary watchpoint if a hardware |
7792 | watchpoint could not be set. */ | |
7793 | if (!mem_cnt || target_resources_ok <= 0) | |
7794 | bp_type = bp_watchpoint; | |
7795 | ||
d983da9c | 7796 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
7797 | |
7798 | /* If the expression is "local", then set up a "watchpoint scope" | |
7799 | breakpoint at the point where we've left the scope of the watchpoint | |
7800 | expression. Create the scope breakpoint before the watchpoint, so | |
7801 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 7802 | if (exp_valid_block && frame) |
d983da9c | 7803 | { |
edb3359d DJ |
7804 | if (frame_id_p (frame_unwind_caller_id (frame))) |
7805 | { | |
7806 | scope_breakpoint | |
a6d9a66e UW |
7807 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
7808 | frame_unwind_caller_pc (frame), | |
edb3359d | 7809 | bp_watchpoint_scope); |
d983da9c | 7810 | |
edb3359d | 7811 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 7812 | |
edb3359d DJ |
7813 | /* Automatically delete the breakpoint when it hits. */ |
7814 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 7815 | |
edb3359d DJ |
7816 | /* Only break in the proper frame (help with recursion). */ |
7817 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 7818 | |
edb3359d | 7819 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
7820 | scope_breakpoint->loc->gdbarch |
7821 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
7822 | scope_breakpoint->loc->requested_address |
7823 | = frame_unwind_caller_pc (frame); | |
7824 | scope_breakpoint->loc->address | |
a6d9a66e UW |
7825 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
7826 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
7827 | scope_breakpoint->type); |
7828 | } | |
d983da9c DJ |
7829 | } |
7830 | ||
c906108c | 7831 | /* Now set up the breakpoint. */ |
2d134ed3 | 7832 | b = set_raw_breakpoint_without_location (NULL, bp_type); |
c906108c SS |
7833 | set_breakpoint_count (breakpoint_count + 1); |
7834 | b->number = breakpoint_count; | |
37e4754d | 7835 | b->thread = thread; |
b5de0fa7 | 7836 | b->disposition = disp_donttouch; |
c906108c SS |
7837 | b->exp = exp; |
7838 | b->exp_valid_block = exp_valid_block; | |
60e1c644 | 7839 | b->cond_exp_valid_block = cond_exp_valid_block; |
c906108c SS |
7840 | b->exp_string = savestring (exp_start, exp_end - exp_start); |
7841 | b->val = val; | |
fa4727a6 | 7842 | b->val_valid = 1; |
c906108c SS |
7843 | if (cond_start) |
7844 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
7845 | else | |
7846 | b->cond_string = 0; | |
c5aa993b | 7847 | |
c906108c | 7848 | if (frame) |
f6bc2008 PA |
7849 | { |
7850 | b->watchpoint_frame = get_frame_id (frame); | |
7851 | b->watchpoint_thread = inferior_ptid; | |
7852 | } | |
c906108c | 7853 | else |
f6bc2008 PA |
7854 | { |
7855 | b->watchpoint_frame = null_frame_id; | |
7856 | b->watchpoint_thread = null_ptid; | |
7857 | } | |
c906108c | 7858 | |
d983da9c | 7859 | if (scope_breakpoint != NULL) |
c906108c | 7860 | { |
d983da9c DJ |
7861 | /* The scope breakpoint is related to the watchpoint. We will |
7862 | need to act on them together. */ | |
7863 | b->related_breakpoint = scope_breakpoint; | |
7864 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 7865 | } |
d983da9c | 7866 | |
c906108c | 7867 | value_free_to_mark (mark); |
2d134ed3 PA |
7868 | |
7869 | /* Finally update the new watchpoint. This creates the locations | |
7870 | that should be inserted. */ | |
7871 | update_watchpoint (b, 1); | |
7872 | ||
c906108c | 7873 | mention (b); |
b60e7edf | 7874 | update_global_location_list (1); |
c906108c SS |
7875 | } |
7876 | ||
7877 | /* Return count of locations need to be watched and can be handled | |
7878 | in hardware. If the watchpoint can not be handled | |
7879 | in hardware return zero. */ | |
7880 | ||
c906108c | 7881 | static int |
fba45db2 | 7882 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
7883 | { |
7884 | int found_memory_cnt = 0; | |
2e70b7b9 | 7885 | struct value *head = v; |
c906108c SS |
7886 | |
7887 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 7888 | if (!can_use_hw_watchpoints) |
c906108c | 7889 | return 0; |
c5aa993b | 7890 | |
5c44784c JM |
7891 | /* Make sure that the value of the expression depends only upon |
7892 | memory contents, and values computed from them within GDB. If we | |
7893 | find any register references or function calls, we can't use a | |
7894 | hardware watchpoint. | |
7895 | ||
7896 | The idea here is that evaluating an expression generates a series | |
7897 | of values, one holding the value of every subexpression. (The | |
7898 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
7899 | a*b+c.) GDB's values hold almost enough information to establish | |
7900 | the criteria given above --- they identify memory lvalues, | |
7901 | register lvalues, computed values, etcetera. So we can evaluate | |
7902 | the expression, and then scan the chain of values that leaves | |
7903 | behind to decide whether we can detect any possible change to the | |
7904 | expression's final value using only hardware watchpoints. | |
7905 | ||
7906 | However, I don't think that the values returned by inferior | |
7907 | function calls are special in any way. So this function may not | |
7908 | notice that an expression involving an inferior function call | |
7909 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 7910 | for (; v; v = value_next (v)) |
c906108c | 7911 | { |
5c44784c | 7912 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 7913 | { |
d69fe07e | 7914 | if (value_lazy (v)) |
5c44784c JM |
7915 | /* A lazy memory lvalue is one that GDB never needed to fetch; |
7916 | we either just used its address (e.g., `a' in `a.b') or | |
7917 | we never needed it at all (e.g., `a' in `a,b'). */ | |
7918 | ; | |
53a5351d | 7919 | else |
5c44784c JM |
7920 | { |
7921 | /* Ahh, memory we actually used! Check if we can cover | |
7922 | it with hardware watchpoints. */ | |
df407dfe | 7923 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
7924 | |
7925 | /* We only watch structs and arrays if user asked for it | |
7926 | explicitly, never if they just happen to appear in a | |
7927 | middle of some value chain. */ | |
7928 | if (v == head | |
7929 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
7930 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
7931 | { | |
42ae5230 | 7932 | CORE_ADDR vaddr = value_address (v); |
df407dfe | 7933 | int len = TYPE_LENGTH (value_type (v)); |
2e70b7b9 | 7934 | |
d92524f1 | 7935 | if (!target_region_ok_for_hw_watchpoint (vaddr, len)) |
2e70b7b9 MS |
7936 | return 0; |
7937 | else | |
7938 | found_memory_cnt++; | |
7939 | } | |
5c44784c | 7940 | } |
c5aa993b | 7941 | } |
5086187c AC |
7942 | else if (VALUE_LVAL (v) != not_lval |
7943 | && deprecated_value_modifiable (v) == 0) | |
53a5351d | 7944 | return 0; /* ??? What does this represent? */ |
5086187c | 7945 | else if (VALUE_LVAL (v) == lval_register) |
53a5351d | 7946 | return 0; /* cannot watch a register with a HW watchpoint */ |
c906108c SS |
7947 | } |
7948 | ||
7949 | /* The expression itself looks suitable for using a hardware | |
7950 | watchpoint, but give the target machine a chance to reject it. */ | |
7951 | return found_memory_cnt; | |
7952 | } | |
7953 | ||
8b93c638 | 7954 | void |
fba45db2 | 7955 | watch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
7956 | { |
7957 | watch_command (arg, from_tty); | |
7958 | } | |
8926118c | 7959 | |
c5aa993b | 7960 | static void |
fba45db2 | 7961 | watch_command (char *arg, int from_tty) |
c906108c | 7962 | { |
53a5351d | 7963 | watch_command_1 (arg, hw_write, from_tty); |
c906108c SS |
7964 | } |
7965 | ||
8b93c638 | 7966 | void |
fba45db2 | 7967 | rwatch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
7968 | { |
7969 | rwatch_command (arg, from_tty); | |
7970 | } | |
8926118c | 7971 | |
c5aa993b | 7972 | static void |
fba45db2 | 7973 | rwatch_command (char *arg, int from_tty) |
c906108c | 7974 | { |
53a5351d | 7975 | watch_command_1 (arg, hw_read, from_tty); |
c906108c SS |
7976 | } |
7977 | ||
8b93c638 | 7978 | void |
fba45db2 | 7979 | awatch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
7980 | { |
7981 | awatch_command (arg, from_tty); | |
7982 | } | |
8926118c | 7983 | |
c5aa993b | 7984 | static void |
fba45db2 | 7985 | awatch_command (char *arg, int from_tty) |
c906108c | 7986 | { |
53a5351d | 7987 | watch_command_1 (arg, hw_access, from_tty); |
c906108c | 7988 | } |
c906108c | 7989 | \f |
c5aa993b | 7990 | |
43ff13b4 | 7991 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
7992 | because it uses the mechanisms of breakpoints. */ |
7993 | ||
bfec99b2 PA |
7994 | struct until_break_command_continuation_args |
7995 | { | |
7996 | struct breakpoint *breakpoint; | |
7997 | struct breakpoint *breakpoint2; | |
7998 | }; | |
7999 | ||
43ff13b4 JM |
8000 | /* This function is called by fetch_inferior_event via the |
8001 | cmd_continuation pointer, to complete the until command. It takes | |
8002 | care of cleaning up the temporary breakpoints set up by the until | |
8003 | command. */ | |
c2c6d25f | 8004 | static void |
604ead4a | 8005 | until_break_command_continuation (void *arg) |
43ff13b4 | 8006 | { |
bfec99b2 PA |
8007 | struct until_break_command_continuation_args *a = arg; |
8008 | ||
8009 | delete_breakpoint (a->breakpoint); | |
8010 | if (a->breakpoint2) | |
8011 | delete_breakpoint (a->breakpoint2); | |
43ff13b4 JM |
8012 | } |
8013 | ||
c906108c | 8014 | void |
ae66c1fc | 8015 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
8016 | { |
8017 | struct symtabs_and_lines sals; | |
8018 | struct symtab_and_line sal; | |
206415a3 | 8019 | struct frame_info *frame = get_selected_frame (NULL); |
c906108c | 8020 | struct breakpoint *breakpoint; |
f107f563 | 8021 | struct breakpoint *breakpoint2 = NULL; |
c906108c SS |
8022 | struct cleanup *old_chain; |
8023 | ||
8024 | clear_proceed_status (); | |
8025 | ||
8026 | /* Set a breakpoint where the user wants it and at return from | |
8027 | this function */ | |
c5aa993b | 8028 | |
c906108c SS |
8029 | if (default_breakpoint_valid) |
8030 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, | |
68219205 | 8031 | default_breakpoint_line, (char ***) NULL, NULL); |
c906108c | 8032 | else |
53a5351d | 8033 | sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, |
68219205 | 8034 | 0, (char ***) NULL, NULL); |
c5aa993b | 8035 | |
c906108c | 8036 | if (sals.nelts != 1) |
8a3fe4f8 | 8037 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 8038 | |
c906108c | 8039 | sal = sals.sals[0]; |
b8c9b27d | 8040 | xfree (sals.sals); /* malloc'd, so freed */ |
c5aa993b | 8041 | |
c906108c | 8042 | if (*arg) |
8a3fe4f8 | 8043 | error (_("Junk at end of arguments.")); |
c5aa993b | 8044 | |
c906108c | 8045 | resolve_sal_pc (&sal); |
c5aa993b | 8046 | |
ae66c1fc EZ |
8047 | if (anywhere) |
8048 | /* If the user told us to continue until a specified location, | |
8049 | we don't specify a frame at which we need to stop. */ | |
a6d9a66e UW |
8050 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
8051 | null_frame_id, bp_until); | |
ae66c1fc | 8052 | else |
edb3359d | 8053 | /* Otherwise, specify the selected frame, because we want to stop only |
ae66c1fc | 8054 | at the very same frame. */ |
a6d9a66e UW |
8055 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
8056 | get_stack_frame_id (frame), | |
ae66c1fc | 8057 | bp_until); |
c5aa993b | 8058 | |
f107f563 | 8059 | old_chain = make_cleanup_delete_breakpoint (breakpoint); |
c906108c | 8060 | |
ae66c1fc EZ |
8061 | /* Keep within the current frame, or in frames called by the current |
8062 | one. */ | |
edb3359d DJ |
8063 | |
8064 | if (frame_id_p (frame_unwind_caller_id (frame))) | |
c906108c | 8065 | { |
edb3359d DJ |
8066 | sal = find_pc_line (frame_unwind_caller_pc (frame), 0); |
8067 | sal.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e UW |
8068 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
8069 | sal, | |
edb3359d | 8070 | frame_unwind_caller_id (frame), |
f107f563 VP |
8071 | bp_until); |
8072 | make_cleanup_delete_breakpoint (breakpoint2); | |
c906108c | 8073 | } |
c5aa993b | 8074 | |
c906108c | 8075 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
f107f563 VP |
8076 | |
8077 | /* If we are running asynchronously, and proceed call above has actually | |
8078 | managed to start the target, arrange for breakpoints to be | |
8079 | deleted when the target stops. Otherwise, we're already stopped and | |
8080 | delete breakpoints via cleanup chain. */ | |
8081 | ||
8ea051c5 | 8082 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 8083 | { |
bfec99b2 PA |
8084 | struct until_break_command_continuation_args *args; |
8085 | args = xmalloc (sizeof (*args)); | |
f107f563 | 8086 | |
bfec99b2 PA |
8087 | args->breakpoint = breakpoint; |
8088 | args->breakpoint2 = breakpoint2; | |
f107f563 VP |
8089 | |
8090 | discard_cleanups (old_chain); | |
95e54da7 PA |
8091 | add_continuation (inferior_thread (), |
8092 | until_break_command_continuation, args, | |
604ead4a | 8093 | xfree); |
f107f563 VP |
8094 | } |
8095 | else | |
c5aa993b | 8096 | do_cleanups (old_chain); |
c906108c | 8097 | } |
ae66c1fc | 8098 | |
c906108c | 8099 | static void |
fba45db2 | 8100 | ep_skip_leading_whitespace (char **s) |
c906108c | 8101 | { |
c5aa993b JM |
8102 | if ((s == NULL) || (*s == NULL)) |
8103 | return; | |
8104 | while (isspace (**s)) | |
8105 | *s += 1; | |
c906108c | 8106 | } |
c5aa993b | 8107 | |
c906108c SS |
8108 | /* This function attempts to parse an optional "if <cond>" clause |
8109 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 8110 | |
c906108c SS |
8111 | Else, it returns a pointer to the condition string. (It does not |
8112 | attempt to evaluate the string against a particular block.) And, | |
8113 | it updates arg to point to the first character following the parsed | |
8114 | if clause in the arg string. */ | |
53a5351d | 8115 | |
c906108c | 8116 | static char * |
fba45db2 | 8117 | ep_parse_optional_if_clause (char **arg) |
c906108c | 8118 | { |
c5aa993b JM |
8119 | char *cond_string; |
8120 | ||
8121 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 8122 | return NULL; |
c5aa993b | 8123 | |
c906108c SS |
8124 | /* Skip the "if" keyword. */ |
8125 | (*arg) += 2; | |
c5aa993b | 8126 | |
c906108c SS |
8127 | /* Skip any extra leading whitespace, and record the start of the |
8128 | condition string. */ | |
8129 | ep_skip_leading_whitespace (arg); | |
8130 | cond_string = *arg; | |
c5aa993b | 8131 | |
c906108c SS |
8132 | /* Assume that the condition occupies the remainder of the arg string. */ |
8133 | (*arg) += strlen (cond_string); | |
c5aa993b | 8134 | |
c906108c SS |
8135 | return cond_string; |
8136 | } | |
c5aa993b | 8137 | |
c906108c SS |
8138 | /* Commands to deal with catching events, such as signals, exceptions, |
8139 | process start/exit, etc. */ | |
c5aa993b JM |
8140 | |
8141 | typedef enum | |
8142 | { | |
44feb3ce TT |
8143 | catch_fork_temporary, catch_vfork_temporary, |
8144 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
8145 | } |
8146 | catch_fork_kind; | |
8147 | ||
c906108c | 8148 | static void |
44feb3ce | 8149 | catch_fork_command_1 (char *arg, int from_tty, struct cmd_list_element *command) |
c906108c | 8150 | { |
a6d9a66e | 8151 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 8152 | char *cond_string = NULL; |
44feb3ce TT |
8153 | catch_fork_kind fork_kind; |
8154 | int tempflag; | |
8155 | ||
8156 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
8157 | tempflag = (fork_kind == catch_fork_temporary | |
8158 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 8159 | |
44feb3ce TT |
8160 | if (!arg) |
8161 | arg = ""; | |
c906108c | 8162 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 8163 | |
c906108c | 8164 | /* The allowed syntax is: |
c5aa993b JM |
8165 | catch [v]fork |
8166 | catch [v]fork if <cond> | |
8167 | ||
c906108c SS |
8168 | First, check if there's an if clause. */ |
8169 | cond_string = ep_parse_optional_if_clause (&arg); | |
c5aa993b | 8170 | |
c906108c | 8171 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 8172 | error (_("Junk at end of arguments.")); |
c5aa993b | 8173 | |
c906108c SS |
8174 | /* If this target supports it, create a fork or vfork catchpoint |
8175 | and enable reporting of such events. */ | |
c5aa993b JM |
8176 | switch (fork_kind) |
8177 | { | |
44feb3ce TT |
8178 | case catch_fork_temporary: |
8179 | case catch_fork_permanent: | |
a6d9a66e | 8180 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 8181 | &catch_fork_breakpoint_ops); |
c906108c | 8182 | break; |
44feb3ce TT |
8183 | case catch_vfork_temporary: |
8184 | case catch_vfork_permanent: | |
a6d9a66e | 8185 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 8186 | &catch_vfork_breakpoint_ops); |
c906108c | 8187 | break; |
c5aa993b | 8188 | default: |
8a3fe4f8 | 8189 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 8190 | break; |
c5aa993b | 8191 | } |
c906108c SS |
8192 | } |
8193 | ||
8194 | static void | |
44feb3ce | 8195 | catch_exec_command_1 (char *arg, int from_tty, struct cmd_list_element *command) |
c906108c | 8196 | { |
a6d9a66e | 8197 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 8198 | int tempflag; |
c5aa993b | 8199 | char *cond_string = NULL; |
c906108c | 8200 | |
44feb3ce TT |
8201 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
8202 | ||
8203 | if (!arg) | |
8204 | arg = ""; | |
c906108c SS |
8205 | ep_skip_leading_whitespace (&arg); |
8206 | ||
8207 | /* The allowed syntax is: | |
c5aa993b JM |
8208 | catch exec |
8209 | catch exec if <cond> | |
c906108c SS |
8210 | |
8211 | First, check if there's an if clause. */ | |
8212 | cond_string = ep_parse_optional_if_clause (&arg); | |
8213 | ||
8214 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 8215 | error (_("Junk at end of arguments.")); |
c906108c SS |
8216 | |
8217 | /* If this target supports it, create an exec catchpoint | |
8218 | and enable reporting of such events. */ | |
a6d9a66e UW |
8219 | create_catchpoint (gdbarch, tempflag, cond_string, |
8220 | &catch_exec_breakpoint_ops); | |
c906108c | 8221 | } |
c5aa993b | 8222 | |
3086aeae DJ |
8223 | static enum print_stop_action |
8224 | print_exception_catchpoint (struct breakpoint *b) | |
8225 | { | |
ade92717 | 8226 | int bp_temp, bp_throw; |
3086aeae | 8227 | |
ade92717 | 8228 | annotate_catchpoint (b->number); |
3086aeae | 8229 | |
ade92717 AR |
8230 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
8231 | if (b->loc->address != b->loc->requested_address) | |
8232 | breakpoint_adjustment_warning (b->loc->requested_address, | |
8233 | b->loc->address, | |
8234 | b->number, 1); | |
df2b6d2d | 8235 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
8236 | ui_out_text (uiout, |
8237 | bp_temp ? "Temporary catchpoint " | |
8238 | : "Catchpoint "); | |
8239 | if (!ui_out_is_mi_like_p (uiout)) | |
8240 | ui_out_field_int (uiout, "bkptno", b->number); | |
8241 | ui_out_text (uiout, | |
c0b37c48 AR |
8242 | bp_throw ? " (exception thrown), " |
8243 | : " (exception caught), "); | |
ade92717 AR |
8244 | if (ui_out_is_mi_like_p (uiout)) |
8245 | { | |
8246 | ui_out_field_string (uiout, "reason", | |
8247 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
8248 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8249 | ui_out_field_int (uiout, "bkptno", b->number); | |
8250 | } | |
3086aeae DJ |
8251 | return PRINT_SRC_AND_LOC; |
8252 | } | |
8253 | ||
8254 | static void | |
a6d9a66e | 8255 | print_one_exception_catchpoint (struct breakpoint *b, struct bp_location **last_loc) |
3086aeae | 8256 | { |
79a45b7d TT |
8257 | struct value_print_options opts; |
8258 | get_user_print_options (&opts); | |
8259 | if (opts.addressprint) | |
3086aeae DJ |
8260 | { |
8261 | annotate_field (4); | |
604133b5 AR |
8262 | if (b->loc == NULL || b->loc->shlib_disabled) |
8263 | ui_out_field_string (uiout, "addr", "<PENDING>"); | |
8264 | else | |
5af949e3 UW |
8265 | ui_out_field_core_addr (uiout, "addr", |
8266 | b->loc->gdbarch, b->loc->address); | |
3086aeae DJ |
8267 | } |
8268 | annotate_field (5); | |
604133b5 | 8269 | if (b->loc) |
a6d9a66e | 8270 | *last_loc = b->loc; |
3086aeae DJ |
8271 | if (strstr (b->addr_string, "throw") != NULL) |
8272 | ui_out_field_string (uiout, "what", "exception throw"); | |
8273 | else | |
8274 | ui_out_field_string (uiout, "what", "exception catch"); | |
8275 | } | |
8276 | ||
8277 | static void | |
8278 | print_mention_exception_catchpoint (struct breakpoint *b) | |
8279 | { | |
ade92717 AR |
8280 | int bp_temp; |
8281 | int bp_throw; | |
8282 | ||
df2b6d2d | 8283 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
8284 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
8285 | ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ") | |
8286 | : _("Catchpoint ")); | |
8287 | ui_out_field_int (uiout, "bkptno", b->number); | |
8288 | ui_out_text (uiout, bp_throw ? _(" (throw)") | |
8289 | : _(" (catch)")); | |
3086aeae DJ |
8290 | } |
8291 | ||
8292 | static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = { | |
ce78b96d JB |
8293 | NULL, /* insert */ |
8294 | NULL, /* remove */ | |
8295 | NULL, /* breakpoint_hit */ | |
3086aeae DJ |
8296 | print_exception_catchpoint, |
8297 | print_one_exception_catchpoint, | |
8298 | print_mention_exception_catchpoint | |
8299 | }; | |
8300 | ||
8301 | static int | |
8302 | handle_gnu_v3_exceptions (int tempflag, char *cond_string, | |
8303 | enum exception_event_kind ex_event, int from_tty) | |
8304 | { | |
604133b5 AR |
8305 | char *trigger_func_name; |
8306 | ||
3086aeae | 8307 | if (ex_event == EX_EVENT_CATCH) |
604133b5 | 8308 | trigger_func_name = "__cxa_begin_catch"; |
3086aeae | 8309 | else |
604133b5 | 8310 | trigger_func_name = "__cxa_throw"; |
3086aeae | 8311 | |
8cdf0e15 VP |
8312 | create_breakpoint (get_current_arch (), |
8313 | trigger_func_name, cond_string, -1, | |
8314 | 0 /* condition and thread are valid. */, | |
8315 | tempflag, 0, 0, | |
8316 | 0, | |
8317 | AUTO_BOOLEAN_TRUE /* pending */, | |
8318 | &gnu_v3_exception_catchpoint_ops, from_tty, | |
8319 | 1 /* enabled */); | |
3086aeae | 8320 | |
3086aeae DJ |
8321 | return 1; |
8322 | } | |
8323 | ||
c5aa993b | 8324 | /* Deal with "catch catch" and "catch throw" commands */ |
c906108c SS |
8325 | |
8326 | static void | |
fba45db2 KB |
8327 | catch_exception_command_1 (enum exception_event_kind ex_event, char *arg, |
8328 | int tempflag, int from_tty) | |
c906108c | 8329 | { |
c5aa993b JM |
8330 | char *cond_string = NULL; |
8331 | struct symtab_and_line *sal = NULL; | |
8332 | ||
44feb3ce TT |
8333 | if (!arg) |
8334 | arg = ""; | |
c906108c | 8335 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 8336 | |
c906108c SS |
8337 | cond_string = ep_parse_optional_if_clause (&arg); |
8338 | ||
8339 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 8340 | error (_("Junk at end of arguments.")); |
c906108c | 8341 | |
059fb39f PM |
8342 | if (ex_event != EX_EVENT_THROW |
8343 | && ex_event != EX_EVENT_CATCH) | |
8a3fe4f8 | 8344 | error (_("Unsupported or unknown exception event; cannot catch it")); |
c906108c | 8345 | |
3086aeae DJ |
8346 | if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty)) |
8347 | return; | |
8348 | ||
8a3fe4f8 | 8349 | warning (_("Unsupported with this platform/compiler combination.")); |
c906108c SS |
8350 | } |
8351 | ||
44feb3ce TT |
8352 | /* Implementation of "catch catch" command. */ |
8353 | ||
8354 | static void | |
8355 | catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command) | |
8356 | { | |
8357 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8358 | catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty); | |
8359 | } | |
8360 | ||
8361 | /* Implementation of "catch throw" command. */ | |
8362 | ||
8363 | static void | |
8364 | catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command) | |
8365 | { | |
8366 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8367 | catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty); | |
8368 | } | |
8369 | ||
f7f9143b JB |
8370 | /* Create a breakpoint struct for Ada exception catchpoints. */ |
8371 | ||
8372 | static void | |
a6d9a66e UW |
8373 | create_ada_exception_breakpoint (struct gdbarch *gdbarch, |
8374 | struct symtab_and_line sal, | |
f7f9143b JB |
8375 | char *addr_string, |
8376 | char *exp_string, | |
8377 | char *cond_string, | |
8378 | struct expression *cond, | |
8379 | struct breakpoint_ops *ops, | |
8380 | int tempflag, | |
8381 | int from_tty) | |
8382 | { | |
8383 | struct breakpoint *b; | |
8384 | ||
8385 | if (from_tty) | |
8386 | { | |
5af949e3 UW |
8387 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
8388 | if (!loc_gdbarch) | |
8389 | loc_gdbarch = gdbarch; | |
8390 | ||
6c95b8df PA |
8391 | describe_other_breakpoints (loc_gdbarch, |
8392 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
8393 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
8394 | version for exception catchpoints, because two catchpoints | |
8395 | used for different exception names will use the same address. | |
8396 | In this case, a "breakpoint ... also set at..." warning is | |
8397 | unproductive. Besides. the warning phrasing is also a bit | |
8398 | inapropriate, we should use the word catchpoint, and tell | |
8399 | the user what type of catchpoint it is. The above is good | |
8400 | enough for now, though. */ | |
8401 | } | |
8402 | ||
a6d9a66e | 8403 | b = set_raw_breakpoint (gdbarch, sal, bp_breakpoint); |
f7f9143b JB |
8404 | set_breakpoint_count (breakpoint_count + 1); |
8405 | ||
8406 | b->enable_state = bp_enabled; | |
8407 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
8408 | b->number = breakpoint_count; | |
8409 | b->ignore_count = 0; | |
511a6cd4 | 8410 | b->loc->cond = cond; |
f7f9143b JB |
8411 | b->addr_string = addr_string; |
8412 | b->language = language_ada; | |
8413 | b->cond_string = cond_string; | |
8414 | b->exp_string = exp_string; | |
8415 | b->thread = -1; | |
8416 | b->ops = ops; | |
f7f9143b JB |
8417 | |
8418 | mention (b); | |
b60e7edf | 8419 | update_global_location_list (1); |
f7f9143b JB |
8420 | } |
8421 | ||
8422 | /* Implement the "catch exception" command. */ | |
8423 | ||
8424 | static void | |
44feb3ce TT |
8425 | catch_ada_exception_command (char *arg, int from_tty, |
8426 | struct cmd_list_element *command) | |
f7f9143b | 8427 | { |
a6d9a66e | 8428 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 8429 | int tempflag; |
f7f9143b JB |
8430 | struct symtab_and_line sal; |
8431 | enum bptype type; | |
8432 | char *addr_string = NULL; | |
8433 | char *exp_string = NULL; | |
8434 | char *cond_string = NULL; | |
8435 | struct expression *cond = NULL; | |
8436 | struct breakpoint_ops *ops = NULL; | |
8437 | ||
44feb3ce TT |
8438 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
8439 | ||
8440 | if (!arg) | |
8441 | arg = ""; | |
f7f9143b JB |
8442 | sal = ada_decode_exception_location (arg, &addr_string, &exp_string, |
8443 | &cond_string, &cond, &ops); | |
a6d9a66e | 8444 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, exp_string, |
f7f9143b JB |
8445 | cond_string, cond, ops, tempflag, |
8446 | from_tty); | |
8447 | } | |
8448 | ||
a96d9b2e SDJ |
8449 | /* Cleanup function for a syscall filter list. */ |
8450 | static void | |
8451 | clean_up_filters (void *arg) | |
8452 | { | |
8453 | VEC(int) *iter = *(VEC(int) **) arg; | |
8454 | VEC_free (int, iter); | |
8455 | } | |
8456 | ||
8457 | /* Splits the argument using space as delimiter. Returns an xmalloc'd | |
8458 | filter list, or NULL if no filtering is required. */ | |
8459 | static VEC(int) * | |
8460 | catch_syscall_split_args (char *arg) | |
8461 | { | |
8462 | VEC(int) *result = NULL; | |
8463 | struct cleanup *cleanup = make_cleanup (clean_up_filters, &result); | |
8464 | ||
8465 | while (*arg != '\0') | |
8466 | { | |
8467 | int i, syscall_number; | |
8468 | char *endptr; | |
8469 | char cur_name[128]; | |
8470 | struct syscall s; | |
8471 | ||
8472 | /* Skip whitespace. */ | |
8473 | while (isspace (*arg)) | |
8474 | arg++; | |
8475 | ||
8476 | for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) | |
8477 | cur_name[i] = arg[i]; | |
8478 | cur_name[i] = '\0'; | |
8479 | arg += i; | |
8480 | ||
8481 | /* Check if the user provided a syscall name or a number. */ | |
8482 | syscall_number = (int) strtol (cur_name, &endptr, 0); | |
8483 | if (*endptr == '\0') | |
bccd0dd2 | 8484 | get_syscall_by_number (syscall_number, &s); |
a96d9b2e SDJ |
8485 | else |
8486 | { | |
8487 | /* We have a name. Let's check if it's valid and convert it | |
8488 | to a number. */ | |
8489 | get_syscall_by_name (cur_name, &s); | |
8490 | ||
8491 | if (s.number == UNKNOWN_SYSCALL) | |
8492 | /* Here we have to issue an error instead of a warning, because | |
8493 | GDB cannot do anything useful if there's no syscall number to | |
8494 | be caught. */ | |
8495 | error (_("Unknown syscall name '%s'."), cur_name); | |
8496 | } | |
8497 | ||
8498 | /* Ok, it's valid. */ | |
8499 | VEC_safe_push (int, result, s.number); | |
8500 | } | |
8501 | ||
8502 | discard_cleanups (cleanup); | |
8503 | return result; | |
8504 | } | |
8505 | ||
8506 | /* Implement the "catch syscall" command. */ | |
8507 | ||
8508 | static void | |
8509 | catch_syscall_command_1 (char *arg, int from_tty, struct cmd_list_element *command) | |
8510 | { | |
8511 | int tempflag; | |
8512 | VEC(int) *filter; | |
8513 | struct syscall s; | |
8514 | struct gdbarch *gdbarch = get_current_arch (); | |
8515 | ||
8516 | /* Checking if the feature if supported. */ | |
8517 | if (gdbarch_get_syscall_number_p (gdbarch) == 0) | |
8518 | error (_("The feature 'catch syscall' is not supported on \ | |
8519 | this architeture yet.")); | |
8520 | ||
8521 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8522 | ||
8523 | ep_skip_leading_whitespace (&arg); | |
8524 | ||
8525 | /* We need to do this first "dummy" translation in order | |
8526 | to get the syscall XML file loaded or, most important, | |
8527 | to display a warning to the user if there's no XML file | |
8528 | for his/her architecture. */ | |
8529 | get_syscall_by_number (0, &s); | |
8530 | ||
8531 | /* The allowed syntax is: | |
8532 | catch syscall | |
8533 | catch syscall <name | number> [<name | number> ... <name | number>] | |
8534 | ||
8535 | Let's check if there's a syscall name. */ | |
8536 | ||
8537 | if (arg != NULL) | |
8538 | filter = catch_syscall_split_args (arg); | |
8539 | else | |
8540 | filter = NULL; | |
8541 | ||
8542 | create_syscall_event_catchpoint (tempflag, filter, | |
8543 | &catch_syscall_breakpoint_ops); | |
8544 | } | |
8545 | ||
f7f9143b JB |
8546 | /* Implement the "catch assert" command. */ |
8547 | ||
8548 | static void | |
44feb3ce | 8549 | catch_assert_command (char *arg, int from_tty, struct cmd_list_element *command) |
f7f9143b | 8550 | { |
a6d9a66e | 8551 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 8552 | int tempflag; |
f7f9143b JB |
8553 | struct symtab_and_line sal; |
8554 | char *addr_string = NULL; | |
8555 | struct breakpoint_ops *ops = NULL; | |
8556 | ||
44feb3ce TT |
8557 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
8558 | ||
8559 | if (!arg) | |
8560 | arg = ""; | |
f7f9143b | 8561 | sal = ada_decode_assert_location (arg, &addr_string, &ops); |
a6d9a66e UW |
8562 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, NULL, NULL, NULL, |
8563 | ops, tempflag, from_tty); | |
f7f9143b JB |
8564 | } |
8565 | ||
c906108c | 8566 | static void |
fba45db2 | 8567 | catch_command (char *arg, int from_tty) |
c906108c | 8568 | { |
44feb3ce | 8569 | error (_("Catch requires an event name.")); |
c906108c SS |
8570 | } |
8571 | \f | |
8572 | ||
8573 | static void | |
fba45db2 | 8574 | tcatch_command (char *arg, int from_tty) |
c906108c | 8575 | { |
44feb3ce | 8576 | error (_("Catch requires an event name.")); |
c906108c SS |
8577 | } |
8578 | ||
80f8a6eb | 8579 | /* Delete breakpoints by address or line. */ |
c906108c SS |
8580 | |
8581 | static void | |
fba45db2 | 8582 | clear_command (char *arg, int from_tty) |
c906108c | 8583 | { |
d6e956e5 VP |
8584 | struct breakpoint *b; |
8585 | VEC(breakpoint_p) *found = 0; | |
8586 | int ix; | |
c906108c SS |
8587 | int default_match; |
8588 | struct symtabs_and_lines sals; | |
8589 | struct symtab_and_line sal; | |
c906108c SS |
8590 | int i; |
8591 | ||
8592 | if (arg) | |
8593 | { | |
8594 | sals = decode_line_spec (arg, 1); | |
8595 | default_match = 0; | |
8596 | } | |
8597 | else | |
8598 | { | |
c5aa993b | 8599 | sals.sals = (struct symtab_and_line *) |
c906108c | 8600 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 8601 | make_cleanup (xfree, sals.sals); |
fe39c653 | 8602 | init_sal (&sal); /* initialize to zeroes */ |
c906108c SS |
8603 | sal.line = default_breakpoint_line; |
8604 | sal.symtab = default_breakpoint_symtab; | |
8605 | sal.pc = default_breakpoint_address; | |
6c95b8df | 8606 | sal.pspace = default_breakpoint_pspace; |
c906108c | 8607 | if (sal.symtab == 0) |
8a3fe4f8 | 8608 | error (_("No source file specified.")); |
c906108c SS |
8609 | |
8610 | sals.sals[0] = sal; | |
8611 | sals.nelts = 1; | |
8612 | ||
8613 | default_match = 1; | |
8614 | } | |
8615 | ||
ed0616c6 VP |
8616 | /* We don't call resolve_sal_pc here. That's not |
8617 | as bad as it seems, because all existing breakpoints | |
8618 | typically have both file/line and pc set. So, if | |
8619 | clear is given file/line, we can match this to existing | |
8620 | breakpoint without obtaining pc at all. | |
8621 | ||
8622 | We only support clearing given the address explicitly | |
8623 | present in breakpoint table. Say, we've set breakpoint | |
8624 | at file:line. There were several PC values for that file:line, | |
8625 | due to optimization, all in one block. | |
8626 | We've picked one PC value. If "clear" is issued with another | |
8627 | PC corresponding to the same file:line, the breakpoint won't | |
8628 | be cleared. We probably can still clear the breakpoint, but | |
8629 | since the other PC value is never presented to user, user | |
8630 | can only find it by guessing, and it does not seem important | |
8631 | to support that. */ | |
8632 | ||
c906108c | 8633 | /* For each line spec given, delete bps which correspond |
80f8a6eb MS |
8634 | to it. Do it in two passes, solely to preserve the current |
8635 | behavior that from_tty is forced true if we delete more than | |
8636 | one breakpoint. */ | |
c906108c | 8637 | |
80f8a6eb | 8638 | found = NULL; |
c906108c SS |
8639 | for (i = 0; i < sals.nelts; i++) |
8640 | { | |
8641 | /* If exact pc given, clear bpts at that pc. | |
c5aa993b JM |
8642 | If line given (pc == 0), clear all bpts on specified line. |
8643 | If defaulting, clear all bpts on default line | |
c906108c | 8644 | or at default pc. |
c5aa993b JM |
8645 | |
8646 | defaulting sal.pc != 0 tests to do | |
8647 | ||
8648 | 0 1 pc | |
8649 | 1 1 pc _and_ line | |
8650 | 0 0 line | |
8651 | 1 0 <can't happen> */ | |
c906108c SS |
8652 | |
8653 | sal = sals.sals[i]; | |
c906108c | 8654 | |
d6e956e5 VP |
8655 | /* Find all matching breakpoints and add them to |
8656 | 'found'. */ | |
8657 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8658 | { |
0d381245 | 8659 | int match = 0; |
80f8a6eb MS |
8660 | /* Are we going to delete b? */ |
8661 | if (b->type != bp_none | |
8662 | && b->type != bp_watchpoint | |
8663 | && b->type != bp_hardware_watchpoint | |
8664 | && b->type != bp_read_watchpoint | |
0d381245 VP |
8665 | && b->type != bp_access_watchpoint) |
8666 | { | |
8667 | struct bp_location *loc = b->loc; | |
8668 | for (; loc; loc = loc->next) | |
8669 | { | |
6c95b8df PA |
8670 | int pc_match = sal.pc |
8671 | && (loc->pspace == sal.pspace) | |
0d381245 VP |
8672 | && (loc->address == sal.pc) |
8673 | && (!section_is_overlay (loc->section) | |
8674 | || loc->section == sal.section); | |
8675 | int line_match = ((default_match || (0 == sal.pc)) | |
8676 | && b->source_file != NULL | |
8677 | && sal.symtab != NULL | |
6c95b8df | 8678 | && sal.pspace == loc->pspace |
0d381245 VP |
8679 | && strcmp (b->source_file, sal.symtab->filename) == 0 |
8680 | && b->line_number == sal.line); | |
8681 | if (pc_match || line_match) | |
8682 | { | |
8683 | match = 1; | |
8684 | break; | |
8685 | } | |
8686 | } | |
8687 | } | |
8688 | ||
8689 | if (match) | |
d6e956e5 | 8690 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 8691 | } |
80f8a6eb MS |
8692 | } |
8693 | /* Now go thru the 'found' chain and delete them. */ | |
d6e956e5 | 8694 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
8695 | { |
8696 | if (arg) | |
8a3fe4f8 | 8697 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 8698 | else |
8a3fe4f8 | 8699 | error (_("No breakpoint at this line.")); |
80f8a6eb | 8700 | } |
c906108c | 8701 | |
d6e956e5 | 8702 | if (VEC_length(breakpoint_p, found) > 1) |
80f8a6eb MS |
8703 | from_tty = 1; /* Always report if deleted more than one */ |
8704 | if (from_tty) | |
a3f17187 | 8705 | { |
d6e956e5 | 8706 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
8707 | printf_unfiltered (_("Deleted breakpoint ")); |
8708 | else | |
8709 | printf_unfiltered (_("Deleted breakpoints ")); | |
8710 | } | |
80f8a6eb | 8711 | breakpoints_changed (); |
d6e956e5 VP |
8712 | |
8713 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 8714 | { |
c5aa993b | 8715 | if (from_tty) |
d6e956e5 VP |
8716 | printf_unfiltered ("%d ", b->number); |
8717 | delete_breakpoint (b); | |
c906108c | 8718 | } |
80f8a6eb MS |
8719 | if (from_tty) |
8720 | putchar_unfiltered ('\n'); | |
c906108c SS |
8721 | } |
8722 | \f | |
8723 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
8724 | all breakpoints that are marked for deletion, whether hit or not. | |
8725 | This is called after any breakpoint is hit, or after errors. */ | |
8726 | ||
8727 | void | |
fba45db2 | 8728 | breakpoint_auto_delete (bpstat bs) |
c906108c SS |
8729 | { |
8730 | struct breakpoint *b, *temp; | |
8731 | ||
8732 | for (; bs; bs = bs->next) | |
20874c92 VP |
8733 | if (bs->breakpoint_at |
8734 | && bs->breakpoint_at->owner | |
8735 | && bs->breakpoint_at->owner->disposition == disp_del | |
c906108c | 8736 | && bs->stop) |
4f8d1dc6 | 8737 | delete_breakpoint (bs->breakpoint_at->owner); |
c906108c SS |
8738 | |
8739 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b | 8740 | { |
b5de0fa7 | 8741 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
8742 | delete_breakpoint (b); |
8743 | } | |
c906108c SS |
8744 | } |
8745 | ||
494cfb0f | 8746 | /* A comparison function for bp_location AP and BP being interfaced to qsort. |
876fa593 JK |
8747 | Sort elements primarily by their ADDRESS (no matter what does |
8748 | breakpoint_address_is_meaningful say for its OWNER), secondarily by ordering | |
8749 | first bp_permanent OWNERed elements and terciarily just ensuring the array | |
8750 | is sorted stable way despite qsort being an instable algorithm. */ | |
8751 | ||
8752 | static int | |
494cfb0f | 8753 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 8754 | { |
494cfb0f JK |
8755 | struct bp_location *a = *(void **) ap; |
8756 | struct bp_location *b = *(void **) bp; | |
876fa593 JK |
8757 | int a_perm = a->owner->enable_state == bp_permanent; |
8758 | int b_perm = b->owner->enable_state == bp_permanent; | |
8759 | ||
8760 | if (a->address != b->address) | |
8761 | return (a->address > b->address) - (a->address < b->address); | |
8762 | ||
8763 | /* Sort permanent breakpoints first. */ | |
8764 | if (a_perm != b_perm) | |
8765 | return (a_perm < b_perm) - (a_perm > b_perm); | |
8766 | ||
8767 | /* Make the user-visible order stable across GDB runs. Locations of the same | |
8768 | breakpoint can be sorted in arbitrary order. */ | |
8769 | ||
8770 | if (a->owner->number != b->owner->number) | |
8771 | return (a->owner->number > b->owner->number) | |
8772 | - (a->owner->number < b->owner->number); | |
8773 | ||
8774 | return (a > b) - (a < b); | |
8775 | } | |
8776 | ||
876fa593 JK |
8777 | /* Set bp_location_placed_address_before_address_max and |
8778 | bp_location_shadow_len_after_address_max according to the current content of | |
8779 | the bp_location array. */ | |
f7545552 TT |
8780 | |
8781 | static void | |
876fa593 | 8782 | bp_location_target_extensions_update (void) |
f7545552 | 8783 | { |
876fa593 JK |
8784 | struct bp_location *bl, **blp_tmp; |
8785 | ||
8786 | bp_location_placed_address_before_address_max = 0; | |
8787 | bp_location_shadow_len_after_address_max = 0; | |
8788 | ||
8789 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
8790 | { | |
8791 | CORE_ADDR start, end, addr; | |
8792 | ||
8793 | if (!bp_location_has_shadow (bl)) | |
8794 | continue; | |
8795 | ||
8796 | start = bl->target_info.placed_address; | |
8797 | end = start + bl->target_info.shadow_len; | |
8798 | ||
8799 | gdb_assert (bl->address >= start); | |
8800 | addr = bl->address - start; | |
8801 | if (addr > bp_location_placed_address_before_address_max) | |
8802 | bp_location_placed_address_before_address_max = addr; | |
8803 | ||
8804 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
8805 | ||
8806 | gdb_assert (bl->address < end); | |
8807 | addr = end - bl->address; | |
8808 | if (addr > bp_location_shadow_len_after_address_max) | |
8809 | bp_location_shadow_len_after_address_max = addr; | |
8810 | } | |
f7545552 TT |
8811 | } |
8812 | ||
4cd9bd08 | 8813 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
b60e7edf PA |
8814 | into the inferior, only remove already-inserted locations that no |
8815 | longer should be inserted. Functions that delete a breakpoint or | |
8816 | breakpoints should pass false, so that deleting a breakpoint | |
8817 | doesn't have the side effect of inserting the locations of other | |
8818 | breakpoints that are marked not-inserted, but should_be_inserted | |
8819 | returns true on them. | |
8820 | ||
8821 | This behaviour is useful is situations close to tear-down -- e.g., | |
8822 | after an exec, while the target still has execution, but breakpoint | |
8823 | shadows of the previous executable image should *NOT* be restored | |
8824 | to the new image; or before detaching, where the target still has | |
8825 | execution and wants to delete breakpoints from GDB's lists, and all | |
8826 | breakpoints had already been removed from the inferior. */ | |
8827 | ||
0d381245 | 8828 | static void |
b60e7edf | 8829 | update_global_location_list (int should_insert) |
0d381245 | 8830 | { |
74960c60 | 8831 | struct breakpoint *b; |
876fa593 | 8832 | struct bp_location **locp, *loc; |
f7545552 TT |
8833 | struct cleanup *cleanups; |
8834 | ||
2d134ed3 PA |
8835 | /* Used in the duplicates detection below. When iterating over all |
8836 | bp_locations, points to the first bp_location of a given address. | |
8837 | Breakpoints and watchpoints of different types are never | |
8838 | duplicates of each other. Keep one pointer for each type of | |
8839 | breakpoint/watchpoint, so we only need to loop over all locations | |
8840 | once. */ | |
8841 | struct bp_location *bp_loc_first; /* breakpoint */ | |
8842 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
8843 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
8844 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 JK |
8845 | |
8846 | /* Saved former bp_location array which we compare against the newly built | |
8847 | bp_location from the current state of ALL_BREAKPOINTS. */ | |
8848 | struct bp_location **old_location, **old_locp; | |
8849 | unsigned old_location_count; | |
8850 | ||
8851 | old_location = bp_location; | |
8852 | old_location_count = bp_location_count; | |
8853 | bp_location = NULL; | |
8854 | bp_location_count = 0; | |
8855 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 8856 | |
74960c60 | 8857 | ALL_BREAKPOINTS (b) |
876fa593 JK |
8858 | for (loc = b->loc; loc; loc = loc->next) |
8859 | bp_location_count++; | |
8860 | ||
8861 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); | |
8862 | locp = bp_location; | |
8863 | ALL_BREAKPOINTS (b) | |
8864 | for (loc = b->loc; loc; loc = loc->next) | |
8865 | *locp++ = loc; | |
8866 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 8867 | bp_location_compare); |
876fa593 JK |
8868 | |
8869 | bp_location_target_extensions_update (); | |
74960c60 VP |
8870 | |
8871 | /* Identify bp_location instances that are no longer present in the new | |
8872 | list, and therefore should be freed. Note that it's not necessary that | |
8873 | those locations should be removed from inferior -- if there's another | |
8874 | location at the same address (previously marked as duplicate), | |
876fa593 JK |
8875 | we don't need to remove/insert the location. |
8876 | ||
8877 | LOCP is kept in sync with OLD_LOCP, each pointing to the current and | |
8878 | former bp_location array state respectively. */ | |
8879 | ||
8880 | locp = bp_location; | |
8881 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
8882 | old_locp++) | |
74960c60 | 8883 | { |
876fa593 | 8884 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 8885 | struct bp_location **loc2p; |
876fa593 JK |
8886 | |
8887 | /* Tells if 'old_loc' is found amoung the new locations. If not, we | |
74960c60 | 8888 | have to free it. */ |
c7d46a38 | 8889 | int found_object = 0; |
20874c92 VP |
8890 | /* Tells if the location should remain inserted in the target. */ |
8891 | int keep_in_target = 0; | |
8892 | int removed = 0; | |
876fa593 JK |
8893 | |
8894 | /* Skip LOCP entries which will definitely never be needed. Stop either | |
8895 | at or being the one matching OLD_LOC. */ | |
8896 | while (locp < bp_location + bp_location_count | |
c7d46a38 | 8897 | && (*locp)->address < old_loc->address) |
876fa593 | 8898 | locp++; |
c7d46a38 PA |
8899 | |
8900 | for (loc2p = locp; | |
8901 | (loc2p < bp_location + bp_location_count | |
8902 | && (*loc2p)->address == old_loc->address); | |
8903 | loc2p++) | |
8904 | { | |
8905 | if (*loc2p == old_loc) | |
8906 | { | |
8907 | found_object = 1; | |
8908 | break; | |
8909 | } | |
8910 | } | |
74960c60 VP |
8911 | |
8912 | /* If this location is no longer present, and inserted, look if there's | |
8913 | maybe a new location at the same address. If so, mark that one | |
8914 | inserted, and don't remove this one. This is needed so that we | |
8915 | don't have a time window where a breakpoint at certain location is not | |
8916 | inserted. */ | |
8917 | ||
876fa593 | 8918 | if (old_loc->inserted) |
0d381245 | 8919 | { |
74960c60 | 8920 | /* If the location is inserted now, we might have to remove it. */ |
74960c60 | 8921 | |
876fa593 | 8922 | if (found_object && should_be_inserted (old_loc)) |
74960c60 VP |
8923 | { |
8924 | /* The location is still present in the location list, and still | |
8925 | should be inserted. Don't do anything. */ | |
20874c92 | 8926 | keep_in_target = 1; |
74960c60 VP |
8927 | } |
8928 | else | |
8929 | { | |
8930 | /* The location is either no longer present, or got disabled. | |
8931 | See if there's another location at the same address, in which | |
8932 | case we don't need to remove this one from the target. */ | |
876fa593 JK |
8933 | |
8934 | if (breakpoint_address_is_meaningful (old_loc->owner)) | |
8935 | { | |
876fa593 | 8936 | for (loc2p = locp; |
c7d46a38 PA |
8937 | (loc2p < bp_location + bp_location_count |
8938 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
8939 | loc2p++) |
8940 | { | |
8941 | struct bp_location *loc2 = *loc2p; | |
8942 | ||
2d134ed3 | 8943 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 PA |
8944 | { |
8945 | /* For the sake of should_be_inserted. | |
8946 | Duplicates check below will fix up this later. */ | |
8947 | loc2->duplicate = 0; | |
85d721b8 PA |
8948 | |
8949 | /* Read watchpoint locations are switched to | |
8950 | access watchpoints, if the former are not | |
8951 | supported, but the latter are. */ | |
8952 | if (is_hardware_watchpoint (old_loc->owner)) | |
8953 | { | |
8954 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
8955 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
8956 | } | |
8957 | ||
c7d46a38 PA |
8958 | if (loc2 != old_loc && should_be_inserted (loc2)) |
8959 | { | |
8960 | loc2->inserted = 1; | |
8961 | loc2->target_info = old_loc->target_info; | |
8962 | keep_in_target = 1; | |
8963 | break; | |
8964 | } | |
876fa593 JK |
8965 | } |
8966 | } | |
8967 | } | |
74960c60 VP |
8968 | } |
8969 | ||
20874c92 VP |
8970 | if (!keep_in_target) |
8971 | { | |
876fa593 | 8972 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 VP |
8973 | { |
8974 | /* This is just about all we can do. We could keep this | |
8975 | location on the global list, and try to remove it next | |
8976 | time, but there's no particular reason why we will | |
8977 | succeed next time. | |
8978 | ||
876fa593 | 8979 | Note that at this point, old_loc->owner is still valid, |
20874c92 VP |
8980 | as delete_breakpoint frees the breakpoint only |
8981 | after calling us. */ | |
8982 | printf_filtered (_("warning: Error removing breakpoint %d\n"), | |
876fa593 | 8983 | old_loc->owner->number); |
20874c92 VP |
8984 | } |
8985 | removed = 1; | |
8986 | } | |
0d381245 | 8987 | } |
74960c60 VP |
8988 | |
8989 | if (!found_object) | |
1c5cfe86 | 8990 | { |
db82e815 PA |
8991 | if (removed && non_stop |
8992 | && breakpoint_address_is_meaningful (old_loc->owner) | |
8993 | && !is_hardware_watchpoint (old_loc->owner)) | |
20874c92 | 8994 | { |
db82e815 PA |
8995 | /* This location was removed from the target. In |
8996 | non-stop mode, a race condition is possible where | |
8997 | we've removed a breakpoint, but stop events for that | |
8998 | breakpoint are already queued and will arrive later. | |
8999 | We apply an heuristic to be able to distinguish such | |
9000 | SIGTRAPs from other random SIGTRAPs: we keep this | |
9001 | breakpoint location for a bit, and will retire it | |
9002 | after we see some number of events. The theory here | |
9003 | is that reporting of events should, "on the average", | |
9004 | be fair, so after a while we'll see events from all | |
9005 | threads that have anything of interest, and no longer | |
9006 | need to keep this breakpoint location around. We | |
9007 | don't hold locations forever so to reduce chances of | |
9008 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
9009 | SIGTRAP. | |
9010 | ||
9011 | The heuristic failing can be disastrous on | |
9012 | decr_pc_after_break targets. | |
9013 | ||
9014 | On decr_pc_after_break targets, like e.g., x86-linux, | |
9015 | if we fail to recognize a late breakpoint SIGTRAP, | |
9016 | because events_till_retirement has reached 0 too | |
9017 | soon, we'll fail to do the PC adjustment, and report | |
9018 | a random SIGTRAP to the user. When the user resumes | |
9019 | the inferior, it will most likely immediately crash | |
9020 | with SIGILL/SIGBUS/SEGSEGV, or worse, get silently | |
9021 | corrupted, because of being resumed e.g., in the | |
9022 | middle of a multi-byte instruction, or skipped a | |
9023 | one-byte instruction. This was actually seen happen | |
9024 | on native x86-linux, and should be less rare on | |
9025 | targets that do not support new thread events, like | |
9026 | remote, due to the heuristic depending on | |
9027 | thread_count. | |
9028 | ||
9029 | Mistaking a random SIGTRAP for a breakpoint trap | |
9030 | causes similar symptoms (PC adjustment applied when | |
9031 | it shouldn't), but then again, playing with SIGTRAPs | |
9032 | behind the debugger's back is asking for trouble. | |
9033 | ||
9034 | Since hardware watchpoint traps are always | |
9035 | distinguishable from other traps, so we don't need to | |
9036 | apply keep hardware watchpoint moribund locations | |
9037 | around. We simply always ignore hardware watchpoint | |
9038 | traps we can no longer explain. */ | |
9039 | ||
876fa593 JK |
9040 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
9041 | old_loc->owner = NULL; | |
20874c92 | 9042 | |
876fa593 | 9043 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
9044 | } |
9045 | else | |
876fa593 | 9046 | free_bp_location (old_loc); |
20874c92 | 9047 | } |
74960c60 | 9048 | } |
1c5cfe86 | 9049 | |
2d134ed3 PA |
9050 | /* Rescan breakpoints at the same address and section, marking the |
9051 | first one as "first" and any others as "duplicates". This is so | |
9052 | that the bpt instruction is only inserted once. If we have a | |
9053 | permanent breakpoint at the same place as BPT, make that one the | |
9054 | official one, and the rest as duplicates. Permanent breakpoints | |
9055 | are sorted first for the same address. | |
9056 | ||
9057 | Do the same for hardware watchpoints, but also considering the | |
9058 | watchpoint's type (regular/access/read) and length. */ | |
876fa593 | 9059 | |
2d134ed3 PA |
9060 | bp_loc_first = NULL; |
9061 | wp_loc_first = NULL; | |
9062 | awp_loc_first = NULL; | |
9063 | rwp_loc_first = NULL; | |
876fa593 | 9064 | ALL_BP_LOCATIONS (loc, locp) |
74960c60 | 9065 | { |
876fa593 | 9066 | struct breakpoint *b = loc->owner; |
2d134ed3 | 9067 | struct bp_location **loc_first_p; |
876fa593 JK |
9068 | |
9069 | if (b->enable_state == bp_disabled | |
9070 | || b->enable_state == bp_call_disabled | |
9071 | || b->enable_state == bp_startup_disabled | |
9072 | || !loc->enabled | |
9073 | || loc->shlib_disabled | |
15c3d785 PA |
9074 | || !breakpoint_address_is_meaningful (b) |
9075 | || tracepoint_type (b)) | |
876fa593 JK |
9076 | continue; |
9077 | ||
9078 | /* Permanent breakpoint should always be inserted. */ | |
9079 | if (b->enable_state == bp_permanent && ! loc->inserted) | |
9080 | internal_error (__FILE__, __LINE__, | |
9081 | _("allegedly permanent breakpoint is not " | |
9082 | "actually inserted")); | |
9083 | ||
2d134ed3 PA |
9084 | if (b->type == bp_hardware_watchpoint) |
9085 | loc_first_p = &wp_loc_first; | |
9086 | else if (b->type == bp_read_watchpoint) | |
9087 | loc_first_p = &rwp_loc_first; | |
9088 | else if (b->type == bp_access_watchpoint) | |
9089 | loc_first_p = &awp_loc_first; | |
9090 | else | |
9091 | loc_first_p = &bp_loc_first; | |
9092 | ||
9093 | if (*loc_first_p == NULL | |
9094 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
9095 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
876fa593 | 9096 | { |
2d134ed3 | 9097 | *loc_first_p = loc; |
876fa593 JK |
9098 | loc->duplicate = 0; |
9099 | continue; | |
9100 | } | |
9101 | ||
9102 | loc->duplicate = 1; | |
9103 | ||
2d134ed3 PA |
9104 | if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted |
9105 | && b->enable_state != bp_permanent) | |
876fa593 JK |
9106 | internal_error (__FILE__, __LINE__, |
9107 | _("another breakpoint was inserted on top of " | |
9108 | "a permanent breakpoint")); | |
0d381245 | 9109 | } |
74960c60 | 9110 | |
50c71eaf | 9111 | if (breakpoints_always_inserted_mode () && should_insert |
c35b1492 | 9112 | && (have_live_inferiors () |
2567c7d9 | 9113 | || (gdbarch_has_global_breakpoints (target_gdbarch)))) |
74960c60 | 9114 | insert_breakpoint_locations (); |
f7545552 TT |
9115 | |
9116 | do_cleanups (cleanups); | |
74960c60 VP |
9117 | } |
9118 | ||
20874c92 VP |
9119 | void |
9120 | breakpoint_retire_moribund (void) | |
9121 | { | |
9122 | struct bp_location *loc; | |
9123 | int ix; | |
9124 | ||
9125 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
9126 | if (--(loc->events_till_retirement) == 0) | |
9127 | { | |
9128 | free_bp_location (loc); | |
9129 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
9130 | --ix; | |
9131 | } | |
9132 | } | |
9133 | ||
74960c60 | 9134 | static void |
b60e7edf | 9135 | update_global_location_list_nothrow (int inserting) |
74960c60 VP |
9136 | { |
9137 | struct gdb_exception e; | |
9138 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
b60e7edf | 9139 | update_global_location_list (inserting); |
0d381245 VP |
9140 | } |
9141 | ||
a474d7c2 PA |
9142 | /* Clear BPT from a BPS. */ |
9143 | static void | |
9144 | bpstat_remove_breakpoint (bpstat bps, struct breakpoint *bpt) | |
9145 | { | |
9146 | bpstat bs; | |
9147 | for (bs = bps; bs; bs = bs->next) | |
9148 | if (bs->breakpoint_at && bs->breakpoint_at->owner == bpt) | |
9149 | { | |
9150 | bs->breakpoint_at = NULL; | |
9151 | bs->old_val = NULL; | |
9152 | /* bs->commands will be freed later. */ | |
9153 | } | |
9154 | } | |
9155 | ||
9156 | /* Callback for iterate_over_threads. */ | |
9157 | static int | |
9158 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
9159 | { | |
9160 | struct breakpoint *bpt = data; | |
9161 | bpstat_remove_breakpoint (th->stop_bpstat, bpt); | |
9162 | return 0; | |
9163 | } | |
9164 | ||
53a5351d JM |
9165 | /* Delete a breakpoint and clean up all traces of it in the data |
9166 | structures. */ | |
c906108c SS |
9167 | |
9168 | void | |
fba45db2 | 9169 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 9170 | { |
52f0bd74 | 9171 | struct breakpoint *b; |
74960c60 | 9172 | struct bp_location *loc, *next; |
c906108c | 9173 | |
8a3fe4f8 | 9174 | gdb_assert (bpt != NULL); |
c906108c SS |
9175 | |
9176 | /* Has this bp already been deleted? This can happen because multiple | |
9177 | lists can hold pointers to bp's. bpstat lists are especial culprits. | |
9178 | ||
9179 | One example of this happening is a watchpoint's scope bp. When the | |
9180 | scope bp triggers, we notice that the watchpoint is out of scope, and | |
9181 | delete it. We also delete its scope bp. But the scope bp is marked | |
9182 | "auto-deleting", and is already on a bpstat. That bpstat is then | |
9183 | checked for auto-deleting bp's, which are deleted. | |
9184 | ||
9185 | A real solution to this problem might involve reference counts in bp's, | |
9186 | and/or giving them pointers back to their referencing bpstat's, and | |
9187 | teaching delete_breakpoint to only free a bp's storage when no more | |
1272ad14 | 9188 | references were extent. A cheaper bandaid was chosen. */ |
c906108c SS |
9189 | if (bpt->type == bp_none) |
9190 | return; | |
9191 | ||
e5a0a904 JK |
9192 | /* At least avoid this stale reference until the reference counting of |
9193 | breakpoints gets resolved. */ | |
9194 | if (bpt->related_breakpoint != NULL) | |
9195 | { | |
9196 | gdb_assert (bpt->related_breakpoint->related_breakpoint == bpt); | |
9197 | bpt->related_breakpoint->disposition = disp_del_at_next_stop; | |
9198 | bpt->related_breakpoint->related_breakpoint = NULL; | |
9199 | bpt->related_breakpoint = NULL; | |
9200 | } | |
9201 | ||
383f836e | 9202 | observer_notify_breakpoint_deleted (bpt->number); |
c906108c | 9203 | |
c906108c SS |
9204 | if (breakpoint_chain == bpt) |
9205 | breakpoint_chain = bpt->next; | |
9206 | ||
c906108c SS |
9207 | ALL_BREAKPOINTS (b) |
9208 | if (b->next == bpt) | |
c5aa993b JM |
9209 | { |
9210 | b->next = bpt->next; | |
9211 | break; | |
9212 | } | |
c906108c | 9213 | |
9add0f1b | 9214 | decref_counted_command_line (&bpt->commands); |
60e1c644 PA |
9215 | xfree (bpt->cond_string); |
9216 | xfree (bpt->cond_exp); | |
9217 | xfree (bpt->addr_string); | |
9218 | xfree (bpt->exp); | |
9219 | xfree (bpt->exp_string); | |
9220 | value_free (bpt->val); | |
9221 | xfree (bpt->source_file); | |
9222 | xfree (bpt->exec_pathname); | |
a96d9b2e | 9223 | clean_up_filters (&bpt->syscalls_to_be_caught); |
c906108c SS |
9224 | |
9225 | /* Be sure no bpstat's are pointing at it after it's been freed. */ | |
9226 | /* FIXME, how can we find all bpstat's? | |
198757a8 VP |
9227 | We just check stop_bpstat for now. Note that we cannot just |
9228 | remove bpstats pointing at bpt from the stop_bpstat list | |
9229 | entirely, as breakpoint commands are associated with the bpstat; | |
9230 | if we remove it here, then the later call to | |
9231 | bpstat_do_actions (&stop_bpstat); | |
9232 | in event-top.c won't do anything, and temporary breakpoints | |
9233 | with commands won't work. */ | |
a474d7c2 | 9234 | |
a474d7c2 | 9235 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); |
74960c60 VP |
9236 | |
9237 | /* Now that breakpoint is removed from breakpoint | |
9238 | list, update the global location list. This | |
9239 | will remove locations that used to belong to | |
9240 | this breakpoint. Do this before freeing | |
9241 | the breakpoint itself, since remove_breakpoint | |
9242 | looks at location's owner. It might be better | |
9243 | design to have location completely self-contained, | |
9244 | but it's not the case now. */ | |
b60e7edf | 9245 | update_global_location_list (0); |
74960c60 VP |
9246 | |
9247 | ||
c906108c SS |
9248 | /* On the chance that someone will soon try again to delete this same |
9249 | bp, we mark it as deleted before freeing its storage. */ | |
9250 | bpt->type = bp_none; | |
9251 | ||
b8c9b27d | 9252 | xfree (bpt); |
c906108c SS |
9253 | } |
9254 | ||
4d6140d9 AC |
9255 | static void |
9256 | do_delete_breakpoint_cleanup (void *b) | |
9257 | { | |
9258 | delete_breakpoint (b); | |
9259 | } | |
9260 | ||
9261 | struct cleanup * | |
9262 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
9263 | { | |
9264 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
9265 | } | |
9266 | ||
95a42b64 TT |
9267 | /* A callback for map_breakpoint_numbers that calls |
9268 | delete_breakpoint. */ | |
9269 | ||
9270 | static void | |
9271 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
9272 | { | |
9273 | delete_breakpoint (b); | |
9274 | } | |
9275 | ||
c906108c | 9276 | void |
fba45db2 | 9277 | delete_command (char *arg, int from_tty) |
c906108c SS |
9278 | { |
9279 | struct breakpoint *b, *temp; | |
9280 | ||
ea9365bb TT |
9281 | dont_repeat (); |
9282 | ||
c906108c SS |
9283 | if (arg == 0) |
9284 | { | |
9285 | int breaks_to_delete = 0; | |
9286 | ||
9287 | /* Delete all breakpoints if no argument. | |
c5aa993b JM |
9288 | Do not delete internal or call-dummy breakpoints, these |
9289 | have to be deleted with an explicit breakpoint number argument. */ | |
9290 | ALL_BREAKPOINTS (b) | |
9291 | { | |
059fb39f | 9292 | if (b->type != bp_call_dummy |
aa7d318d | 9293 | && b->type != bp_std_terminate |
059fb39f | 9294 | && b->type != bp_shlib_event |
4efc6507 | 9295 | && b->type != bp_jit_event |
059fb39f PM |
9296 | && b->type != bp_thread_event |
9297 | && b->type != bp_overlay_event | |
0fd8e87f | 9298 | && b->type != bp_longjmp_master |
aa7d318d | 9299 | && b->type != bp_std_terminate_master |
059fb39f | 9300 | && b->number >= 0) |
973d738b DJ |
9301 | { |
9302 | breaks_to_delete = 1; | |
9303 | break; | |
9304 | } | |
c5aa993b | 9305 | } |
c906108c SS |
9306 | |
9307 | /* Ask user only if there are some breakpoints to delete. */ | |
9308 | if (!from_tty | |
e2e0b3e5 | 9309 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 9310 | { |
c5aa993b JM |
9311 | ALL_BREAKPOINTS_SAFE (b, temp) |
9312 | { | |
059fb39f | 9313 | if (b->type != bp_call_dummy |
aa7d318d | 9314 | && b->type != bp_std_terminate |
059fb39f PM |
9315 | && b->type != bp_shlib_event |
9316 | && b->type != bp_thread_event | |
4efc6507 | 9317 | && b->type != bp_jit_event |
059fb39f | 9318 | && b->type != bp_overlay_event |
0fd8e87f | 9319 | && b->type != bp_longjmp_master |
aa7d318d | 9320 | && b->type != bp_std_terminate_master |
059fb39f | 9321 | && b->number >= 0) |
c5aa993b JM |
9322 | delete_breakpoint (b); |
9323 | } | |
c906108c SS |
9324 | } |
9325 | } | |
9326 | else | |
95a42b64 | 9327 | map_breakpoint_numbers (arg, do_delete_breakpoint, NULL); |
c906108c SS |
9328 | } |
9329 | ||
0d381245 VP |
9330 | static int |
9331 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 9332 | { |
0d381245 VP |
9333 | for (; loc; loc = loc->next) |
9334 | if (!loc->shlib_disabled) | |
9335 | return 0; | |
9336 | return 1; | |
fe3f5fa8 VP |
9337 | } |
9338 | ||
776592bf DE |
9339 | /* Subroutine of update_breakpoint_locations to simplify it. |
9340 | Return non-zero if multiple fns in list LOC have the same name. | |
9341 | Null names are ignored. */ | |
9342 | ||
9343 | static int | |
9344 | ambiguous_names_p (struct bp_location *loc) | |
9345 | { | |
9346 | struct bp_location *l; | |
9347 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
9348 | (int (*) (const void *, const void *)) streq, | |
9349 | NULL, xcalloc, xfree); | |
9350 | ||
9351 | for (l = loc; l != NULL; l = l->next) | |
9352 | { | |
9353 | const char **slot; | |
9354 | const char *name = l->function_name; | |
9355 | ||
9356 | /* Allow for some names to be NULL, ignore them. */ | |
9357 | if (name == NULL) | |
9358 | continue; | |
9359 | ||
9360 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
9361 | INSERT); | |
9362 | /* NOTE: We can assume slot != NULL here because xcalloc never returns | |
9363 | NULL. */ | |
9364 | if (*slot != NULL) | |
9365 | { | |
9366 | htab_delete (htab); | |
9367 | return 1; | |
9368 | } | |
9369 | *slot = name; | |
9370 | } | |
9371 | ||
9372 | htab_delete (htab); | |
9373 | return 0; | |
9374 | } | |
9375 | ||
fe3f5fa8 | 9376 | static void |
0d381245 VP |
9377 | update_breakpoint_locations (struct breakpoint *b, |
9378 | struct symtabs_and_lines sals) | |
fe3f5fa8 VP |
9379 | { |
9380 | int i; | |
9381 | char *s; | |
0d381245 VP |
9382 | struct bp_location *existing_locations = b->loc; |
9383 | ||
9384 | /* If there's no new locations, and all existing locations | |
9385 | are pending, don't do anything. This optimizes | |
9386 | the common case where all locations are in the same | |
9387 | shared library, that was unloaded. We'd like to | |
9388 | retain the location, so that when the library | |
9389 | is loaded again, we don't loose the enabled/disabled | |
9390 | status of the individual locations. */ | |
9391 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) | |
fe3f5fa8 VP |
9392 | return; |
9393 | ||
fe3f5fa8 VP |
9394 | b->loc = NULL; |
9395 | ||
0d381245 | 9396 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 9397 | { |
0d381245 | 9398 | struct bp_location *new_loc = |
39d61571 | 9399 | add_location_to_breakpoint (b, &(sals.sals[i])); |
fe3f5fa8 | 9400 | |
0d381245 VP |
9401 | /* Reparse conditions, they might contain references to the |
9402 | old symtab. */ | |
9403 | if (b->cond_string != NULL) | |
9404 | { | |
9405 | struct gdb_exception e; | |
fe3f5fa8 | 9406 | |
0d381245 VP |
9407 | s = b->cond_string; |
9408 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
9409 | { | |
9410 | new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), | |
9411 | 0); | |
9412 | } | |
9413 | if (e.reason < 0) | |
9414 | { | |
9415 | warning (_("failed to reevaluate condition for breakpoint %d: %s"), | |
9416 | b->number, e.message); | |
9417 | new_loc->enabled = 0; | |
9418 | } | |
9419 | } | |
fe3f5fa8 | 9420 | |
0d381245 VP |
9421 | if (b->source_file != NULL) |
9422 | xfree (b->source_file); | |
9423 | if (sals.sals[i].symtab == NULL) | |
9424 | b->source_file = NULL; | |
9425 | else | |
1b36a34b | 9426 | b->source_file = xstrdup (sals.sals[i].symtab->filename); |
fe3f5fa8 | 9427 | |
0d381245 VP |
9428 | if (b->line_number == 0) |
9429 | b->line_number = sals.sals[i].line; | |
9430 | } | |
fe3f5fa8 | 9431 | |
514f746b AR |
9432 | /* Update locations of permanent breakpoints. */ |
9433 | if (b->enable_state == bp_permanent) | |
9434 | make_breakpoint_permanent (b); | |
9435 | ||
0d381245 VP |
9436 | /* If possible, carry over 'disable' status from existing breakpoints. */ |
9437 | { | |
9438 | struct bp_location *e = existing_locations; | |
776592bf DE |
9439 | /* If there are multiple breakpoints with the same function name, |
9440 | e.g. for inline functions, comparing function names won't work. | |
9441 | Instead compare pc addresses; this is just a heuristic as things | |
9442 | may have moved, but in practice it gives the correct answer | |
9443 | often enough until a better solution is found. */ | |
9444 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
9445 | ||
0d381245 VP |
9446 | for (; e; e = e->next) |
9447 | { | |
9448 | if (!e->enabled && e->function_name) | |
9449 | { | |
9450 | struct bp_location *l = b->loc; | |
776592bf DE |
9451 | if (have_ambiguous_names) |
9452 | { | |
9453 | for (; l; l = l->next) | |
6c95b8df PA |
9454 | if (breakpoint_address_match (e->pspace->aspace, e->address, |
9455 | l->pspace->aspace, l->address)) | |
776592bf DE |
9456 | { |
9457 | l->enabled = 0; | |
9458 | break; | |
9459 | } | |
9460 | } | |
9461 | else | |
9462 | { | |
9463 | for (; l; l = l->next) | |
9464 | if (l->function_name | |
9465 | && strcmp (e->function_name, l->function_name) == 0) | |
9466 | { | |
9467 | l->enabled = 0; | |
9468 | break; | |
9469 | } | |
9470 | } | |
0d381245 VP |
9471 | } |
9472 | } | |
9473 | } | |
fe3f5fa8 | 9474 | |
b60e7edf | 9475 | update_global_location_list (1); |
fe3f5fa8 VP |
9476 | } |
9477 | ||
9478 | ||
c906108c SS |
9479 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
9480 | The value we return ends up being the return value from catch_errors. | |
9481 | Unused in this case. */ | |
9482 | ||
9483 | static int | |
4efb68b1 | 9484 | breakpoint_re_set_one (void *bint) |
c906108c | 9485 | { |
53a5351d JM |
9486 | /* get past catch_errs */ |
9487 | struct breakpoint *b = (struct breakpoint *) bint; | |
c906108c SS |
9488 | struct value *mark; |
9489 | int i; | |
fe3f5fa8 VP |
9490 | int not_found = 0; |
9491 | int *not_found_ptr = ¬_found; | |
6c95b8df PA |
9492 | struct symtabs_and_lines sals = {0}; |
9493 | struct symtabs_and_lines expanded = {0}; | |
c906108c | 9494 | char *s; |
b5de0fa7 | 9495 | enum enable_state save_enable; |
fe3f5fa8 | 9496 | struct gdb_exception e; |
6c95b8df | 9497 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
c906108c SS |
9498 | |
9499 | switch (b->type) | |
9500 | { | |
9501 | case bp_none: | |
8a3fe4f8 | 9502 | warning (_("attempted to reset apparently deleted breakpoint #%d?"), |
53a5351d | 9503 | b->number); |
c906108c SS |
9504 | return 0; |
9505 | case bp_breakpoint: | |
9506 | case bp_hardware_breakpoint: | |
1042e4c0 | 9507 | case bp_tracepoint: |
7a697b8d | 9508 | case bp_fast_tracepoint: |
8bea4e01 UW |
9509 | /* Do not attempt to re-set breakpoints disabled during startup. */ |
9510 | if (b->enable_state == bp_startup_disabled) | |
9511 | return 0; | |
9512 | ||
c906108c SS |
9513 | if (b->addr_string == NULL) |
9514 | { | |
9515 | /* Anything without a string can't be re-set. */ | |
9516 | delete_breakpoint (b); | |
9517 | return 0; | |
9518 | } | |
c906108c SS |
9519 | |
9520 | set_language (b->language); | |
9521 | input_radix = b->input_radix; | |
9522 | s = b->addr_string; | |
6c95b8df PA |
9523 | |
9524 | save_current_space_and_thread (); | |
9525 | switch_to_program_space_and_thread (b->pspace); | |
9526 | ||
fe3f5fa8 | 9527 | TRY_CATCH (e, RETURN_MASK_ERROR) |
c906108c | 9528 | { |
fe3f5fa8 VP |
9529 | sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL, |
9530 | not_found_ptr); | |
9531 | } | |
9532 | if (e.reason < 0) | |
9533 | { | |
9534 | int not_found_and_ok = 0; | |
9535 | /* For pending breakpoints, it's expected that parsing | |
9536 | will fail until the right shared library is loaded. | |
9537 | User has already told to create pending breakpoints and | |
9538 | don't need extra messages. If breakpoint is in bp_shlib_disabled | |
9539 | state, then user already saw the message about that breakpoint | |
9540 | being disabled, and don't want to see more errors. */ | |
0d381245 VP |
9541 | if (not_found |
9542 | && (b->condition_not_parsed | |
9543 | || (b->loc && b->loc->shlib_disabled) | |
9544 | || b->enable_state == bp_disabled)) | |
fe3f5fa8 VP |
9545 | not_found_and_ok = 1; |
9546 | ||
9547 | if (!not_found_and_ok) | |
c906108c | 9548 | { |
fe3f5fa8 VP |
9549 | /* We surely don't want to warn about the same breakpoint |
9550 | 10 times. One solution, implemented here, is disable | |
9551 | the breakpoint on error. Another solution would be to | |
9552 | have separate 'warning emitted' flag. Since this | |
9553 | happens only when a binary has changed, I don't know | |
9554 | which approach is better. */ | |
9555 | b->enable_state = bp_disabled; | |
9556 | throw_exception (e); | |
c906108c | 9557 | } |
fe3f5fa8 | 9558 | } |
c906108c | 9559 | |
6c95b8df | 9560 | if (!not_found) |
fe3f5fa8 | 9561 | { |
6c95b8df PA |
9562 | gdb_assert (sals.nelts == 1); |
9563 | ||
9564 | resolve_sal_pc (&sals.sals[0]); | |
9565 | if (b->condition_not_parsed && s && s[0]) | |
9566 | { | |
9567 | char *cond_string = 0; | |
9568 | int thread = -1; | |
9569 | int task = 0; | |
9570 | ||
9571 | find_condition_and_thread (s, sals.sals[0].pc, | |
9572 | &cond_string, &thread, &task); | |
9573 | if (cond_string) | |
9574 | b->cond_string = cond_string; | |
9575 | b->thread = thread; | |
9576 | b->task = task; | |
9577 | b->condition_not_parsed = 0; | |
9578 | } | |
9579 | ||
9580 | expanded = expand_line_sal_maybe (sals.sals[0]); | |
fe3f5fa8 | 9581 | } |
6c95b8df PA |
9582 | |
9583 | make_cleanup (xfree, sals.sals); | |
ed0616c6 | 9584 | update_breakpoint_locations (b, expanded); |
c906108c SS |
9585 | break; |
9586 | ||
9587 | case bp_watchpoint: | |
9588 | case bp_hardware_watchpoint: | |
9589 | case bp_read_watchpoint: | |
9590 | case bp_access_watchpoint: | |
0b3de036 VP |
9591 | /* Watchpoint can be either on expression using entirely global variables, |
9592 | or it can be on local variables. | |
9593 | ||
9594 | Watchpoints of the first kind are never auto-deleted, and even persist | |
9595 | across program restarts. Since they can use variables from shared | |
9596 | libraries, we need to reparse expression as libraries are loaded | |
9597 | and unloaded. | |
9598 | ||
9599 | Watchpoints on local variables can also change meaning as result | |
9600 | of solib event. For example, if a watchpoint uses both a local and | |
9601 | a global variables in expression, it's a local watchpoint, but | |
9602 | unloading of a shared library will make the expression invalid. | |
9603 | This is not a very common use case, but we still re-evaluate | |
9604 | expression, to avoid surprises to the user. | |
9605 | ||
9606 | Note that for local watchpoints, we re-evaluate it only if | |
9607 | watchpoints frame id is still valid. If it's not, it means | |
9608 | the watchpoint is out of scope and will be deleted soon. In fact, | |
9609 | I'm not sure we'll ever be called in this case. | |
9610 | ||
9611 | If a local watchpoint's frame id is still valid, then | |
9612 | b->exp_valid_block is likewise valid, and we can safely use it. | |
9613 | ||
9614 | Don't do anything about disabled watchpoints, since they will | |
9615 | be reevaluated again when enabled. */ | |
a5606eee | 9616 | update_watchpoint (b, 1 /* reparse */); |
c906108c | 9617 | break; |
c5aa993b JM |
9618 | /* We needn't really do anything to reset these, since the mask |
9619 | that requests them is unaffected by e.g., new libraries being | |
9620 | loaded. */ | |
ce78b96d | 9621 | case bp_catchpoint: |
c906108c | 9622 | break; |
c5aa993b | 9623 | |
c906108c | 9624 | default: |
a3f17187 | 9625 | printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type); |
c906108c | 9626 | /* fall through */ |
0fd8e87f UW |
9627 | /* Delete overlay event and longjmp master breakpoints; they will be |
9628 | reset later by breakpoint_re_set. */ | |
1900040c | 9629 | case bp_overlay_event: |
0fd8e87f | 9630 | case bp_longjmp_master: |
aa7d318d | 9631 | case bp_std_terminate_master: |
c906108c SS |
9632 | delete_breakpoint (b); |
9633 | break; | |
9634 | ||
c5aa993b JM |
9635 | /* This breakpoint is special, it's set up when the inferior |
9636 | starts and we really don't want to touch it. */ | |
c906108c SS |
9637 | case bp_shlib_event: |
9638 | ||
c4093a6a JM |
9639 | /* Like bp_shlib_event, this breakpoint type is special. |
9640 | Once it is set up, we do not want to touch it. */ | |
9641 | case bp_thread_event: | |
9642 | ||
c5aa993b JM |
9643 | /* Keep temporary breakpoints, which can be encountered when we step |
9644 | over a dlopen call and SOLIB_ADD is resetting the breakpoints. | |
9645 | Otherwise these should have been blown away via the cleanup chain | |
9646 | or by breakpoint_init_inferior when we rerun the executable. */ | |
c906108c SS |
9647 | case bp_until: |
9648 | case bp_finish: | |
9649 | case bp_watchpoint_scope: | |
9650 | case bp_call_dummy: | |
aa7d318d | 9651 | case bp_std_terminate: |
c906108c | 9652 | case bp_step_resume: |
611c83ae PA |
9653 | case bp_longjmp: |
9654 | case bp_longjmp_resume: | |
4efc6507 | 9655 | case bp_jit_event: |
c906108c SS |
9656 | break; |
9657 | } | |
9658 | ||
6c95b8df | 9659 | do_cleanups (cleanups); |
c906108c SS |
9660 | return 0; |
9661 | } | |
9662 | ||
69de3c6a | 9663 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 9664 | void |
69de3c6a | 9665 | breakpoint_re_set (void) |
c906108c SS |
9666 | { |
9667 | struct breakpoint *b, *temp; | |
9668 | enum language save_language; | |
9669 | int save_input_radix; | |
6c95b8df | 9670 | struct cleanup *old_chain; |
c5aa993b | 9671 | |
c906108c SS |
9672 | save_language = current_language->la_language; |
9673 | save_input_radix = input_radix; | |
6c95b8df PA |
9674 | old_chain = save_current_program_space (); |
9675 | ||
c906108c | 9676 | ALL_BREAKPOINTS_SAFE (b, temp) |
c5aa993b | 9677 | { |
53a5351d | 9678 | /* Format possible error msg */ |
fe3f5fa8 | 9679 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
9680 | b->number); |
9681 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 9682 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 9683 | do_cleanups (cleanups); |
c5aa993b | 9684 | } |
c906108c SS |
9685 | set_language (save_language); |
9686 | input_radix = save_input_radix; | |
e62c965a | 9687 | |
0756c555 | 9688 | jit_breakpoint_re_set (); |
4efc6507 | 9689 | |
6c95b8df PA |
9690 | do_cleanups (old_chain); |
9691 | ||
69de3c6a | 9692 | create_overlay_event_breakpoint ("_ovly_debug_event"); |
0fd8e87f UW |
9693 | create_longjmp_master_breakpoint ("longjmp"); |
9694 | create_longjmp_master_breakpoint ("_longjmp"); | |
9695 | create_longjmp_master_breakpoint ("siglongjmp"); | |
9696 | create_longjmp_master_breakpoint ("_siglongjmp"); | |
aa7d318d | 9697 | create_std_terminate_master_breakpoint ("std::terminate()"); |
c906108c SS |
9698 | } |
9699 | \f | |
c906108c SS |
9700 | /* Reset the thread number of this breakpoint: |
9701 | ||
9702 | - If the breakpoint is for all threads, leave it as-is. | |
39f77062 | 9703 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 9704 | void |
fba45db2 | 9705 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
9706 | { |
9707 | if (b->thread != -1) | |
9708 | { | |
39f77062 KB |
9709 | if (in_thread_list (inferior_ptid)) |
9710 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
9711 | |
9712 | /* We're being called after following a fork. The new fork is | |
9713 | selected as current, and unless this was a vfork will have a | |
9714 | different program space from the original thread. Reset that | |
9715 | as well. */ | |
9716 | b->loc->pspace = current_program_space; | |
c906108c SS |
9717 | } |
9718 | } | |
9719 | ||
03ac34d5 MS |
9720 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
9721 | If from_tty is nonzero, it prints a message to that effect, | |
9722 | which ends with a period (no newline). */ | |
9723 | ||
c906108c | 9724 | void |
fba45db2 | 9725 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 9726 | { |
52f0bd74 | 9727 | struct breakpoint *b; |
c906108c SS |
9728 | |
9729 | if (count < 0) | |
9730 | count = 0; | |
9731 | ||
9732 | ALL_BREAKPOINTS (b) | |
9733 | if (b->number == bptnum) | |
c5aa993b JM |
9734 | { |
9735 | b->ignore_count = count; | |
221ea385 KS |
9736 | if (from_tty) |
9737 | { | |
9738 | if (count == 0) | |
a3f17187 | 9739 | printf_filtered (_("Will stop next time breakpoint %d is reached."), |
221ea385 KS |
9740 | bptnum); |
9741 | else if (count == 1) | |
a3f17187 | 9742 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
9743 | bptnum); |
9744 | else | |
a3f17187 | 9745 | printf_filtered (_("Will ignore next %d crossings of breakpoint %d."), |
221ea385 KS |
9746 | count, bptnum); |
9747 | } | |
c5aa993b | 9748 | breakpoints_changed (); |
383f836e | 9749 | observer_notify_breakpoint_modified (b->number); |
c5aa993b JM |
9750 | return; |
9751 | } | |
c906108c | 9752 | |
8a3fe4f8 | 9753 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
9754 | } |
9755 | ||
b2175913 MS |
9756 | void |
9757 | make_breakpoint_silent (struct breakpoint *b) | |
9758 | { | |
9759 | /* Silence the breakpoint. */ | |
9760 | b->silent = 1; | |
9761 | } | |
9762 | ||
c906108c SS |
9763 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
9764 | ||
9765 | static void | |
fba45db2 | 9766 | ignore_command (char *args, int from_tty) |
c906108c SS |
9767 | { |
9768 | char *p = args; | |
52f0bd74 | 9769 | int num; |
c906108c SS |
9770 | |
9771 | if (p == 0) | |
e2e0b3e5 | 9772 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 9773 | |
c906108c | 9774 | num = get_number (&p); |
5c44784c | 9775 | if (num == 0) |
8a3fe4f8 | 9776 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 9777 | if (*p == 0) |
8a3fe4f8 | 9778 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
9779 | |
9780 | set_ignore_count (num, | |
9781 | longest_to_int (value_as_long (parse_and_eval (p))), | |
9782 | from_tty); | |
221ea385 KS |
9783 | if (from_tty) |
9784 | printf_filtered ("\n"); | |
c906108c SS |
9785 | } |
9786 | \f | |
9787 | /* Call FUNCTION on each of the breakpoints | |
9788 | whose numbers are given in ARGS. */ | |
9789 | ||
9790 | static void | |
95a42b64 TT |
9791 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
9792 | void *), | |
9793 | void *data) | |
c906108c | 9794 | { |
52f0bd74 | 9795 | char *p = args; |
c906108c | 9796 | char *p1; |
52f0bd74 AC |
9797 | int num; |
9798 | struct breakpoint *b, *tmp; | |
11cf8741 | 9799 | int match; |
c906108c SS |
9800 | |
9801 | if (p == 0) | |
e2e0b3e5 | 9802 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c SS |
9803 | |
9804 | while (*p) | |
9805 | { | |
11cf8741 | 9806 | match = 0; |
c906108c | 9807 | p1 = p; |
c5aa993b | 9808 | |
5c44784c JM |
9809 | num = get_number_or_range (&p1); |
9810 | if (num == 0) | |
c5aa993b | 9811 | { |
8a3fe4f8 | 9812 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
9813 | } |
9814 | else | |
9815 | { | |
9816 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
9817 | if (b->number == num) | |
9818 | { | |
9819 | struct breakpoint *related_breakpoint = b->related_breakpoint; | |
11cf8741 | 9820 | match = 1; |
95a42b64 | 9821 | function (b, data); |
5c44784c | 9822 | if (related_breakpoint) |
95a42b64 | 9823 | function (related_breakpoint, data); |
11cf8741 | 9824 | break; |
5c44784c | 9825 | } |
11cf8741 | 9826 | if (match == 0) |
a3f17187 | 9827 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 9828 | } |
c906108c SS |
9829 | p = p1; |
9830 | } | |
9831 | } | |
9832 | ||
0d381245 VP |
9833 | static struct bp_location * |
9834 | find_location_by_number (char *number) | |
9835 | { | |
9836 | char *dot = strchr (number, '.'); | |
9837 | char *p1; | |
9838 | int bp_num; | |
9839 | int loc_num; | |
9840 | struct breakpoint *b; | |
9841 | struct bp_location *loc; | |
9842 | ||
9843 | *dot = '\0'; | |
9844 | ||
9845 | p1 = number; | |
9846 | bp_num = get_number_or_range (&p1); | |
9847 | if (bp_num == 0) | |
9848 | error (_("Bad breakpoint number '%s'"), number); | |
9849 | ||
9850 | ALL_BREAKPOINTS (b) | |
9851 | if (b->number == bp_num) | |
9852 | { | |
9853 | break; | |
9854 | } | |
9855 | ||
9856 | if (!b || b->number != bp_num) | |
9857 | error (_("Bad breakpoint number '%s'"), number); | |
9858 | ||
9859 | p1 = dot+1; | |
9860 | loc_num = get_number_or_range (&p1); | |
9861 | if (loc_num == 0) | |
9862 | error (_("Bad breakpoint location number '%s'"), number); | |
9863 | ||
9864 | --loc_num; | |
9865 | loc = b->loc; | |
9866 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
9867 | ; | |
9868 | if (!loc) | |
9869 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
9870 | ||
9871 | return loc; | |
9872 | } | |
9873 | ||
9874 | ||
1900040c MS |
9875 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
9876 | If from_tty is nonzero, it prints a message to that effect, | |
9877 | which ends with a period (no newline). */ | |
9878 | ||
c906108c | 9879 | void |
fba45db2 | 9880 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
9881 | { |
9882 | /* Never disable a watchpoint scope breakpoint; we want to | |
9883 | hit them when we leave scope so we can delete both the | |
9884 | watchpoint and its scope breakpoint at that time. */ | |
9885 | if (bpt->type == bp_watchpoint_scope) | |
9886 | return; | |
9887 | ||
c2c6d25f | 9888 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 9889 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
9890 | return; |
9891 | ||
b5de0fa7 | 9892 | bpt->enable_state = bp_disabled; |
c906108c | 9893 | |
b60e7edf | 9894 | update_global_location_list (0); |
c906108c | 9895 | |
383f836e | 9896 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
9897 | } |
9898 | ||
95a42b64 TT |
9899 | /* A callback for map_breakpoint_numbers that calls |
9900 | disable_breakpoint. */ | |
9901 | ||
9902 | static void | |
9903 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
9904 | { | |
9905 | disable_breakpoint (b); | |
9906 | } | |
9907 | ||
c906108c | 9908 | static void |
fba45db2 | 9909 | disable_command (char *args, int from_tty) |
c906108c | 9910 | { |
52f0bd74 | 9911 | struct breakpoint *bpt; |
c906108c SS |
9912 | if (args == 0) |
9913 | ALL_BREAKPOINTS (bpt) | |
9914 | switch (bpt->type) | |
c5aa993b JM |
9915 | { |
9916 | case bp_none: | |
8a3fe4f8 | 9917 | warning (_("attempted to disable apparently deleted breakpoint #%d?"), |
53a5351d | 9918 | bpt->number); |
c5aa993b JM |
9919 | continue; |
9920 | case bp_breakpoint: | |
1042e4c0 | 9921 | case bp_tracepoint: |
7a697b8d | 9922 | case bp_fast_tracepoint: |
ce78b96d | 9923 | case bp_catchpoint: |
c5aa993b JM |
9924 | case bp_hardware_breakpoint: |
9925 | case bp_watchpoint: | |
9926 | case bp_hardware_watchpoint: | |
9927 | case bp_read_watchpoint: | |
9928 | case bp_access_watchpoint: | |
9929 | disable_breakpoint (bpt); | |
9930 | default: | |
9931 | continue; | |
9932 | } | |
0d381245 VP |
9933 | else if (strchr (args, '.')) |
9934 | { | |
9935 | struct bp_location *loc = find_location_by_number (args); | |
9936 | if (loc) | |
9937 | loc->enabled = 0; | |
b60e7edf | 9938 | update_global_location_list (0); |
0d381245 | 9939 | } |
c906108c | 9940 | else |
95a42b64 | 9941 | map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL); |
c906108c SS |
9942 | } |
9943 | ||
9944 | static void | |
fba45db2 | 9945 | do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition) |
c906108c | 9946 | { |
c906108c SS |
9947 | int target_resources_ok, other_type_used; |
9948 | struct value *mark; | |
9949 | ||
9950 | if (bpt->type == bp_hardware_breakpoint) | |
9951 | { | |
9952 | int i; | |
c5aa993b | 9953 | i = hw_breakpoint_used_count (); |
53a5351d | 9954 | target_resources_ok = |
d92524f1 | 9955 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 9956 | i + 1, 0); |
c906108c | 9957 | if (target_resources_ok == 0) |
8a3fe4f8 | 9958 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 9959 | else if (target_resources_ok < 0) |
8a3fe4f8 | 9960 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
9961 | } |
9962 | ||
059fb39f PM |
9963 | if (bpt->type == bp_watchpoint |
9964 | || bpt->type == bp_hardware_watchpoint | |
9965 | || bpt->type == bp_read_watchpoint | |
9966 | || bpt->type == bp_access_watchpoint) | |
c906108c | 9967 | { |
dde02812 ES |
9968 | struct gdb_exception e; |
9969 | ||
9970 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 9971 | { |
dde02812 | 9972 | update_watchpoint (bpt, 1 /* reparse */); |
c906108c | 9973 | } |
dde02812 | 9974 | if (e.reason < 0) |
c5aa993b | 9975 | { |
dde02812 ES |
9976 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
9977 | bpt->number); | |
9978 | return; | |
c5aa993b | 9979 | } |
c906108c | 9980 | } |
0101ce28 | 9981 | |
b4c291bb KH |
9982 | if (bpt->enable_state != bp_permanent) |
9983 | bpt->enable_state = bp_enabled; | |
9984 | bpt->disposition = disposition; | |
b60e7edf | 9985 | update_global_location_list (1); |
b4c291bb KH |
9986 | breakpoints_changed (); |
9987 | ||
383f836e | 9988 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
9989 | } |
9990 | ||
fe3f5fa8 | 9991 | |
c906108c | 9992 | void |
fba45db2 | 9993 | enable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
9994 | { |
9995 | do_enable_breakpoint (bpt, bpt->disposition); | |
9996 | } | |
9997 | ||
95a42b64 TT |
9998 | /* A callback for map_breakpoint_numbers that calls |
9999 | enable_breakpoint. */ | |
10000 | ||
10001 | static void | |
10002 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
10003 | { | |
10004 | enable_breakpoint (b); | |
10005 | } | |
10006 | ||
c906108c SS |
10007 | /* The enable command enables the specified breakpoints (or all defined |
10008 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 10009 | in stopping the inferior. */ |
c906108c | 10010 | |
c906108c | 10011 | static void |
fba45db2 | 10012 | enable_command (char *args, int from_tty) |
c906108c | 10013 | { |
52f0bd74 | 10014 | struct breakpoint *bpt; |
c906108c SS |
10015 | if (args == 0) |
10016 | ALL_BREAKPOINTS (bpt) | |
10017 | switch (bpt->type) | |
c5aa993b JM |
10018 | { |
10019 | case bp_none: | |
8a3fe4f8 | 10020 | warning (_("attempted to enable apparently deleted breakpoint #%d?"), |
53a5351d | 10021 | bpt->number); |
c5aa993b JM |
10022 | continue; |
10023 | case bp_breakpoint: | |
1042e4c0 | 10024 | case bp_tracepoint: |
7a697b8d | 10025 | case bp_fast_tracepoint: |
ce78b96d | 10026 | case bp_catchpoint: |
c5aa993b JM |
10027 | case bp_hardware_breakpoint: |
10028 | case bp_watchpoint: | |
10029 | case bp_hardware_watchpoint: | |
10030 | case bp_read_watchpoint: | |
10031 | case bp_access_watchpoint: | |
10032 | enable_breakpoint (bpt); | |
10033 | default: | |
10034 | continue; | |
10035 | } | |
0d381245 VP |
10036 | else if (strchr (args, '.')) |
10037 | { | |
10038 | struct bp_location *loc = find_location_by_number (args); | |
10039 | if (loc) | |
10040 | loc->enabled = 1; | |
b60e7edf | 10041 | update_global_location_list (1); |
0d381245 | 10042 | } |
c906108c | 10043 | else |
95a42b64 | 10044 | map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL); |
c906108c SS |
10045 | } |
10046 | ||
10047 | static void | |
95a42b64 | 10048 | enable_once_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 10049 | { |
b5de0fa7 | 10050 | do_enable_breakpoint (bpt, disp_disable); |
c906108c SS |
10051 | } |
10052 | ||
c906108c | 10053 | static void |
fba45db2 | 10054 | enable_once_command (char *args, int from_tty) |
c906108c | 10055 | { |
95a42b64 | 10056 | map_breakpoint_numbers (args, enable_once_breakpoint, NULL); |
c906108c SS |
10057 | } |
10058 | ||
10059 | static void | |
95a42b64 | 10060 | enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 10061 | { |
b5de0fa7 | 10062 | do_enable_breakpoint (bpt, disp_del); |
c906108c SS |
10063 | } |
10064 | ||
c906108c | 10065 | static void |
fba45db2 | 10066 | enable_delete_command (char *args, int from_tty) |
c906108c | 10067 | { |
95a42b64 | 10068 | map_breakpoint_numbers (args, enable_delete_breakpoint, NULL); |
c906108c SS |
10069 | } |
10070 | \f | |
fa8d40ab JJ |
10071 | static void |
10072 | set_breakpoint_cmd (char *args, int from_tty) | |
10073 | { | |
10074 | } | |
10075 | ||
10076 | static void | |
10077 | show_breakpoint_cmd (char *args, int from_tty) | |
10078 | { | |
10079 | } | |
10080 | ||
1f3b5d1b PP |
10081 | /* Invalidate last known value of any hardware watchpoint if |
10082 | the memory which that value represents has been written to by | |
10083 | GDB itself. */ | |
10084 | ||
10085 | static void | |
10086 | invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len, | |
10087 | const bfd_byte *data) | |
10088 | { | |
10089 | struct breakpoint *bp; | |
10090 | ||
10091 | ALL_BREAKPOINTS (bp) | |
10092 | if (bp->enable_state == bp_enabled | |
10093 | && bp->type == bp_hardware_watchpoint | |
10094 | && bp->val_valid && bp->val) | |
10095 | { | |
10096 | struct bp_location *loc; | |
10097 | ||
10098 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
10099 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
10100 | && loc->address + loc->length > addr | |
10101 | && addr + len > loc->address) | |
10102 | { | |
10103 | value_free (bp->val); | |
10104 | bp->val = NULL; | |
10105 | bp->val_valid = 0; | |
10106 | } | |
10107 | } | |
10108 | } | |
10109 | ||
c906108c SS |
10110 | /* Use default_breakpoint_'s, or nothing if they aren't valid. */ |
10111 | ||
10112 | struct symtabs_and_lines | |
fba45db2 | 10113 | decode_line_spec_1 (char *string, int funfirstline) |
c906108c SS |
10114 | { |
10115 | struct symtabs_and_lines sals; | |
10116 | if (string == 0) | |
8a3fe4f8 | 10117 | error (_("Empty line specification.")); |
c906108c SS |
10118 | if (default_breakpoint_valid) |
10119 | sals = decode_line_1 (&string, funfirstline, | |
53a5351d JM |
10120 | default_breakpoint_symtab, |
10121 | default_breakpoint_line, | |
68219205 | 10122 | (char ***) NULL, NULL); |
c906108c SS |
10123 | else |
10124 | sals = decode_line_1 (&string, funfirstline, | |
68219205 | 10125 | (struct symtab *) NULL, 0, (char ***) NULL, NULL); |
c906108c | 10126 | if (*string) |
8a3fe4f8 | 10127 | error (_("Junk at end of line specification: %s"), string); |
c906108c SS |
10128 | return sals; |
10129 | } | |
8181d85f DJ |
10130 | |
10131 | /* Create and insert a raw software breakpoint at PC. Return an | |
10132 | identifier, which should be used to remove the breakpoint later. | |
10133 | In general, places which call this should be using something on the | |
10134 | breakpoint chain instead; this function should be eliminated | |
10135 | someday. */ | |
10136 | ||
10137 | void * | |
6c95b8df PA |
10138 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, |
10139 | struct address_space *aspace, CORE_ADDR pc) | |
8181d85f DJ |
10140 | { |
10141 | struct bp_target_info *bp_tgt; | |
10142 | ||
6c95b8df | 10143 | bp_tgt = XZALLOC (struct bp_target_info); |
8181d85f | 10144 | |
6c95b8df | 10145 | bp_tgt->placed_address_space = aspace; |
8181d85f | 10146 | bp_tgt->placed_address = pc; |
6c95b8df | 10147 | |
a6d9a66e | 10148 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
8181d85f DJ |
10149 | { |
10150 | /* Could not insert the breakpoint. */ | |
10151 | xfree (bp_tgt); | |
10152 | return NULL; | |
10153 | } | |
10154 | ||
10155 | return bp_tgt; | |
10156 | } | |
10157 | ||
10158 | /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */ | |
10159 | ||
10160 | int | |
a6d9a66e | 10161 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
8181d85f DJ |
10162 | { |
10163 | struct bp_target_info *bp_tgt = bp; | |
10164 | int ret; | |
10165 | ||
a6d9a66e | 10166 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
8181d85f DJ |
10167 | xfree (bp_tgt); |
10168 | ||
10169 | return ret; | |
10170 | } | |
10171 | ||
10172 | /* One (or perhaps two) breakpoints used for software single stepping. */ | |
10173 | ||
10174 | static void *single_step_breakpoints[2]; | |
a6d9a66e | 10175 | static struct gdbarch *single_step_gdbarch[2]; |
8181d85f DJ |
10176 | |
10177 | /* Create and insert a breakpoint for software single step. */ | |
10178 | ||
10179 | void | |
6c95b8df PA |
10180 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
10181 | struct address_space *aspace, CORE_ADDR next_pc) | |
8181d85f DJ |
10182 | { |
10183 | void **bpt_p; | |
10184 | ||
10185 | if (single_step_breakpoints[0] == NULL) | |
a6d9a66e UW |
10186 | { |
10187 | bpt_p = &single_step_breakpoints[0]; | |
10188 | single_step_gdbarch[0] = gdbarch; | |
10189 | } | |
8181d85f DJ |
10190 | else |
10191 | { | |
10192 | gdb_assert (single_step_breakpoints[1] == NULL); | |
10193 | bpt_p = &single_step_breakpoints[1]; | |
a6d9a66e | 10194 | single_step_gdbarch[1] = gdbarch; |
8181d85f DJ |
10195 | } |
10196 | ||
10197 | /* NOTE drow/2006-04-11: A future improvement to this function would be | |
10198 | to only create the breakpoints once, and actually put them on the | |
10199 | breakpoint chain. That would let us use set_raw_breakpoint. We could | |
10200 | adjust the addresses each time they were needed. Doing this requires | |
10201 | corresponding changes elsewhere where single step breakpoints are | |
10202 | handled, however. So, for now, we use this. */ | |
10203 | ||
6c95b8df | 10204 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc); |
8181d85f | 10205 | if (*bpt_p == NULL) |
5af949e3 UW |
10206 | error (_("Could not insert single-step breakpoint at %s"), |
10207 | paddress (gdbarch, next_pc)); | |
8181d85f DJ |
10208 | } |
10209 | ||
10210 | /* Remove and delete any breakpoints used for software single step. */ | |
10211 | ||
10212 | void | |
10213 | remove_single_step_breakpoints (void) | |
10214 | { | |
10215 | gdb_assert (single_step_breakpoints[0] != NULL); | |
10216 | ||
10217 | /* See insert_single_step_breakpoint for more about this deprecated | |
10218 | call. */ | |
a6d9a66e UW |
10219 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
10220 | single_step_breakpoints[0]); | |
10221 | single_step_gdbarch[0] = NULL; | |
8181d85f DJ |
10222 | single_step_breakpoints[0] = NULL; |
10223 | ||
10224 | if (single_step_breakpoints[1] != NULL) | |
10225 | { | |
a6d9a66e UW |
10226 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
10227 | single_step_breakpoints[1]); | |
10228 | single_step_gdbarch[1] = NULL; | |
8181d85f DJ |
10229 | single_step_breakpoints[1] = NULL; |
10230 | } | |
10231 | } | |
10232 | ||
1aafd4da UW |
10233 | /* Check whether a software single-step breakpoint is inserted at PC. */ |
10234 | ||
10235 | static int | |
6c95b8df | 10236 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
1aafd4da UW |
10237 | { |
10238 | int i; | |
10239 | ||
10240 | for (i = 0; i < 2; i++) | |
10241 | { | |
10242 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
6c95b8df PA |
10243 | if (bp_tgt |
10244 | && breakpoint_address_match (bp_tgt->placed_address_space, | |
10245 | bp_tgt->placed_address, | |
10246 | aspace, pc)) | |
1aafd4da UW |
10247 | return 1; |
10248 | } | |
10249 | ||
10250 | return 0; | |
10251 | } | |
10252 | ||
a96d9b2e SDJ |
10253 | /* Returns 0 if 'bp' is NOT a syscall catchpoint, |
10254 | non-zero otherwise. */ | |
10255 | static int | |
10256 | is_syscall_catchpoint_enabled (struct breakpoint *bp) | |
10257 | { | |
10258 | if (syscall_catchpoint_p (bp) | |
10259 | && bp->enable_state != bp_disabled | |
10260 | && bp->enable_state != bp_call_disabled) | |
10261 | return 1; | |
10262 | else | |
10263 | return 0; | |
10264 | } | |
10265 | ||
10266 | int | |
10267 | catch_syscall_enabled (void) | |
10268 | { | |
10269 | struct inferior *inf = current_inferior (); | |
10270 | ||
10271 | return inf->total_syscalls_count != 0; | |
10272 | } | |
10273 | ||
10274 | int | |
10275 | catching_syscall_number (int syscall_number) | |
10276 | { | |
10277 | struct breakpoint *bp; | |
10278 | ||
10279 | ALL_BREAKPOINTS (bp) | |
10280 | if (is_syscall_catchpoint_enabled (bp)) | |
10281 | { | |
10282 | if (bp->syscalls_to_be_caught) | |
10283 | { | |
10284 | int i, iter; | |
10285 | for (i = 0; | |
10286 | VEC_iterate (int, bp->syscalls_to_be_caught, i, iter); | |
10287 | i++) | |
10288 | if (syscall_number == iter) | |
10289 | return 1; | |
10290 | } | |
10291 | else | |
10292 | return 1; | |
10293 | } | |
10294 | ||
10295 | return 0; | |
10296 | } | |
10297 | ||
10298 | /* Complete syscall names. Used by "catch syscall". */ | |
10299 | static char ** | |
10300 | catch_syscall_completer (struct cmd_list_element *cmd, | |
10301 | char *text, char *word) | |
10302 | { | |
10303 | const char **list = get_syscall_names (); | |
10304 | return (list == NULL) ? NULL : complete_on_enum (list, text, word); | |
10305 | } | |
10306 | ||
1042e4c0 SS |
10307 | /* Tracepoint-specific operations. */ |
10308 | ||
10309 | /* Set tracepoint count to NUM. */ | |
10310 | static void | |
10311 | set_tracepoint_count (int num) | |
10312 | { | |
10313 | tracepoint_count = num; | |
4fa62494 | 10314 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
10315 | } |
10316 | ||
10317 | void | |
10318 | trace_command (char *arg, int from_tty) | |
10319 | { | |
8cdf0e15 VP |
10320 | if (create_breakpoint (get_current_arch (), |
10321 | arg, | |
10322 | NULL, 0, 1 /* parse arg */, | |
10323 | 0 /* tempflag */, 0 /* hardwareflag */, | |
10324 | 1 /* traceflag */, | |
10325 | 0 /* Ignore count */, | |
10326 | pending_break_support, | |
10327 | NULL, | |
10328 | from_tty, | |
10329 | 1 /* enabled */)) | |
fd9b8c24 | 10330 | set_tracepoint_count (breakpoint_count); |
1042e4c0 SS |
10331 | } |
10332 | ||
7a697b8d SS |
10333 | void |
10334 | ftrace_command (char *arg, int from_tty) | |
10335 | { | |
8cdf0e15 VP |
10336 | if (create_breakpoint (get_current_arch (), |
10337 | arg, | |
10338 | NULL, 0, 1 /* parse arg */, | |
10339 | 0 /* tempflag */, 1 /* hardwareflag */, | |
10340 | 1 /* traceflag */, | |
10341 | 0 /* Ignore count */, | |
10342 | pending_break_support, | |
10343 | NULL, | |
10344 | from_tty, | |
10345 | 1 /* enabled */)) | |
fd9b8c24 | 10346 | set_tracepoint_count (breakpoint_count); |
7a697b8d SS |
10347 | } |
10348 | ||
409873ef SS |
10349 | /* Set up a fake reader function that gets command lines from a linked |
10350 | list that was acquired during tracepoint uploading. */ | |
10351 | ||
10352 | static struct uploaded_tp *this_utp; | |
10353 | static struct uploaded_string *next_cmd; | |
10354 | ||
10355 | static char * | |
10356 | read_uploaded_action (void) | |
10357 | { | |
10358 | char *rslt; | |
10359 | ||
10360 | if (!next_cmd) | |
10361 | return NULL; | |
10362 | ||
10363 | rslt = next_cmd->str; | |
10364 | next_cmd = next_cmd->next; | |
10365 | ||
10366 | return rslt; | |
10367 | } | |
10368 | ||
00bf0b85 SS |
10369 | /* Given information about a tracepoint as recorded on a target (which |
10370 | can be either a live system or a trace file), attempt to create an | |
10371 | equivalent GDB tracepoint. This is not a reliable process, since | |
10372 | the target does not necessarily have all the information used when | |
10373 | the tracepoint was originally defined. */ | |
10374 | ||
10375 | struct breakpoint * | |
10376 | create_tracepoint_from_upload (struct uploaded_tp *utp) | |
d5551862 | 10377 | { |
409873ef | 10378 | char *addr_str, small_buf[100]; |
d5551862 | 10379 | struct breakpoint *tp; |
fd9b8c24 | 10380 | |
409873ef SS |
10381 | if (utp->at_string) |
10382 | addr_str = utp->at_string; | |
10383 | else | |
10384 | { | |
10385 | /* In the absence of a source location, fall back to raw | |
10386 | address. Since there is no way to confirm that the address | |
10387 | means the same thing as when the trace was started, warn the | |
10388 | user. */ | |
10389 | warning (_("Uploaded tracepoint %d has no source location, using raw address"), | |
10390 | utp->number); | |
10391 | sprintf (small_buf, "*%s", hex_string (utp->addr)); | |
10392 | addr_str = small_buf; | |
10393 | } | |
10394 | ||
10395 | /* There's not much we can do with a sequence of bytecodes. */ | |
10396 | if (utp->cond && !utp->cond_string) | |
10397 | warning (_("Uploaded tracepoint %d condition has no source form, ignoring it"), | |
10398 | utp->number); | |
d5551862 | 10399 | |
8cdf0e15 | 10400 | if (!create_breakpoint (get_current_arch (), |
409873ef SS |
10401 | addr_str, |
10402 | utp->cond_string, -1, 0 /* parse cond/thread */, | |
8cdf0e15 VP |
10403 | 0 /* tempflag */, |
10404 | (utp->type == bp_fast_tracepoint) /* hardwareflag */, | |
10405 | 1 /* traceflag */, | |
10406 | 0 /* Ignore count */, | |
10407 | pending_break_support, | |
10408 | NULL, | |
10409 | 0 /* from_tty */, | |
10410 | utp->enabled /* enabled */)) | |
fd9b8c24 PA |
10411 | return NULL; |
10412 | ||
00bf0b85 SS |
10413 | set_tracepoint_count (breakpoint_count); |
10414 | ||
409873ef | 10415 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
10416 | tp = get_tracepoint (tracepoint_count); |
10417 | gdb_assert (tp != NULL); | |
d5551862 | 10418 | |
00bf0b85 SS |
10419 | if (utp->pass > 0) |
10420 | { | |
409873ef | 10421 | sprintf (small_buf, "%d %d", utp->pass, tp->number); |
00bf0b85 | 10422 | |
409873ef | 10423 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
10424 | } |
10425 | ||
409873ef SS |
10426 | /* If we have uploaded versions of the original commands, set up a |
10427 | special-purpose "reader" function and call the usual command line | |
10428 | reader, then pass the result to the breakpoint command-setting | |
10429 | function. */ | |
10430 | if (utp->cmd_strings) | |
00bf0b85 | 10431 | { |
409873ef | 10432 | struct command_line *cmd_list; |
00bf0b85 | 10433 | |
409873ef SS |
10434 | this_utp = utp; |
10435 | next_cmd = utp->cmd_strings; | |
d5551862 | 10436 | |
409873ef SS |
10437 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
10438 | ||
10439 | breakpoint_set_commands (tp, cmd_list); | |
00bf0b85 | 10440 | } |
409873ef SS |
10441 | else if (utp->numactions > 0 || utp->num_step_actions > 0) |
10442 | warning (_("Uploaded tracepoint %d actions have no source form, ignoring them"), | |
10443 | utp->number); | |
00bf0b85 SS |
10444 | |
10445 | return tp; | |
10446 | } | |
10447 | ||
1042e4c0 SS |
10448 | /* Print information on tracepoint number TPNUM_EXP, or all if |
10449 | omitted. */ | |
10450 | ||
10451 | static void | |
10452 | tracepoints_info (char *tpnum_exp, int from_tty) | |
10453 | { | |
10454 | struct breakpoint *b; | |
10455 | int tps_to_list = 0; | |
10456 | ||
10457 | /* In the no-arguments case, say "No tracepoints" if none found. */ | |
10458 | if (tpnum_exp == 0) | |
10459 | { | |
10460 | ALL_TRACEPOINTS (b) | |
10461 | { | |
10462 | if (b->number >= 0) | |
10463 | { | |
10464 | tps_to_list = 1; | |
10465 | break; | |
10466 | } | |
10467 | } | |
10468 | if (!tps_to_list) | |
10469 | { | |
10470 | ui_out_message (uiout, 0, "No tracepoints.\n"); | |
10471 | return; | |
10472 | } | |
10473 | } | |
10474 | ||
10475 | /* Otherwise be the same as "info break". */ | |
10476 | breakpoints_info (tpnum_exp, from_tty); | |
10477 | } | |
10478 | ||
10479 | /* The 'enable trace' command enables tracepoints. | |
10480 | Not supported by all targets. */ | |
10481 | static void | |
10482 | enable_trace_command (char *args, int from_tty) | |
10483 | { | |
10484 | enable_command (args, from_tty); | |
10485 | } | |
10486 | ||
10487 | /* The 'disable trace' command disables tracepoints. | |
10488 | Not supported by all targets. */ | |
10489 | static void | |
10490 | disable_trace_command (char *args, int from_tty) | |
10491 | { | |
10492 | disable_command (args, from_tty); | |
10493 | } | |
10494 | ||
10495 | /* Remove a tracepoint (or all if no argument) */ | |
10496 | static void | |
10497 | delete_trace_command (char *arg, int from_tty) | |
10498 | { | |
10499 | struct breakpoint *b, *temp; | |
10500 | ||
10501 | dont_repeat (); | |
10502 | ||
10503 | if (arg == 0) | |
10504 | { | |
10505 | int breaks_to_delete = 0; | |
10506 | ||
10507 | /* Delete all breakpoints if no argument. | |
10508 | Do not delete internal or call-dummy breakpoints, these | |
10509 | have to be deleted with an explicit breakpoint number argument. */ | |
10510 | ALL_TRACEPOINTS (b) | |
10511 | { | |
10512 | if (b->number >= 0) | |
10513 | { | |
10514 | breaks_to_delete = 1; | |
10515 | break; | |
10516 | } | |
10517 | } | |
10518 | ||
10519 | /* Ask user only if there are some breakpoints to delete. */ | |
10520 | if (!from_tty | |
10521 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
10522 | { | |
10523 | ALL_BREAKPOINTS_SAFE (b, temp) | |
10524 | { | |
7a697b8d | 10525 | if (tracepoint_type (b) |
059fb39f | 10526 | && b->number >= 0) |
1042e4c0 SS |
10527 | delete_breakpoint (b); |
10528 | } | |
10529 | } | |
10530 | } | |
10531 | else | |
95a42b64 | 10532 | map_breakpoint_numbers (arg, do_delete_breakpoint, NULL); |
1042e4c0 SS |
10533 | } |
10534 | ||
10535 | /* Set passcount for tracepoint. | |
10536 | ||
10537 | First command argument is passcount, second is tracepoint number. | |
10538 | If tracepoint number omitted, apply to most recently defined. | |
10539 | Also accepts special argument "all". */ | |
10540 | ||
10541 | static void | |
10542 | trace_pass_command (char *args, int from_tty) | |
10543 | { | |
10544 | struct breakpoint *t1 = (struct breakpoint *) -1, *t2; | |
10545 | unsigned int count; | |
10546 | int all = 0; | |
10547 | ||
10548 | if (args == 0 || *args == 0) | |
10549 | error (_("passcount command requires an argument (count + optional TP num)")); | |
10550 | ||
10551 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ | |
10552 | ||
10553 | while (*args && isspace ((int) *args)) | |
10554 | args++; | |
10555 | ||
10556 | if (*args && strncasecmp (args, "all", 3) == 0) | |
10557 | { | |
10558 | args += 3; /* Skip special argument "all". */ | |
10559 | all = 1; | |
10560 | if (*args) | |
10561 | error (_("Junk at end of arguments.")); | |
10562 | } | |
10563 | else | |
10564 | t1 = get_tracepoint_by_number (&args, 1, 1); | |
10565 | ||
10566 | do | |
10567 | { | |
10568 | if (t1) | |
10569 | { | |
10570 | ALL_TRACEPOINTS (t2) | |
10571 | if (t1 == (struct breakpoint *) -1 || t1 == t2) | |
10572 | { | |
10573 | t2->pass_count = count; | |
10574 | observer_notify_tracepoint_modified (t2->number); | |
10575 | if (from_tty) | |
10576 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
10577 | t2->number, count); | |
10578 | } | |
10579 | if (! all && *args) | |
10580 | t1 = get_tracepoint_by_number (&args, 1, 0); | |
10581 | } | |
10582 | } | |
10583 | while (*args); | |
10584 | } | |
10585 | ||
10586 | struct breakpoint * | |
10587 | get_tracepoint (int num) | |
10588 | { | |
10589 | struct breakpoint *t; | |
10590 | ||
10591 | ALL_TRACEPOINTS (t) | |
10592 | if (t->number == num) | |
10593 | return t; | |
10594 | ||
10595 | return NULL; | |
10596 | } | |
10597 | ||
d5551862 SS |
10598 | /* Find the tracepoint with the given target-side number (which may be |
10599 | different from the tracepoint number after disconnecting and | |
10600 | reconnecting). */ | |
10601 | ||
10602 | struct breakpoint * | |
10603 | get_tracepoint_by_number_on_target (int num) | |
10604 | { | |
10605 | struct breakpoint *t; | |
10606 | ||
10607 | ALL_TRACEPOINTS (t) | |
10608 | if (t->number_on_target == num) | |
10609 | return t; | |
10610 | ||
10611 | return NULL; | |
10612 | } | |
10613 | ||
1042e4c0 SS |
10614 | /* Utility: parse a tracepoint number and look it up in the list. |
10615 | If MULTI_P is true, there might be a range of tracepoints in ARG. | |
10616 | if OPTIONAL_P is true, then if the argument is missing, the most | |
10617 | recent tracepoint (tracepoint_count) is returned. */ | |
10618 | struct breakpoint * | |
10619 | get_tracepoint_by_number (char **arg, int multi_p, int optional_p) | |
10620 | { | |
10621 | extern int tracepoint_count; | |
10622 | struct breakpoint *t; | |
10623 | int tpnum; | |
10624 | char *instring = arg == NULL ? NULL : *arg; | |
10625 | ||
10626 | if (arg == NULL || *arg == NULL || ! **arg) | |
10627 | { | |
10628 | if (optional_p) | |
10629 | tpnum = tracepoint_count; | |
10630 | else | |
10631 | error_no_arg (_("tracepoint number")); | |
10632 | } | |
10633 | else | |
10634 | tpnum = multi_p ? get_number_or_range (arg) : get_number (arg); | |
10635 | ||
10636 | if (tpnum <= 0) | |
10637 | { | |
10638 | if (instring && *instring) | |
10639 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
10640 | instring); | |
10641 | else | |
10642 | printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n")); | |
10643 | return NULL; | |
10644 | } | |
10645 | ||
10646 | ALL_TRACEPOINTS (t) | |
10647 | if (t->number == tpnum) | |
10648 | { | |
10649 | return t; | |
10650 | } | |
10651 | ||
10652 | /* FIXME: if we are in the middle of a range we don't want to give | |
10653 | a message. The current interface to get_number_or_range doesn't | |
10654 | allow us to discover this. */ | |
10655 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); | |
10656 | return NULL; | |
10657 | } | |
10658 | ||
10659 | /* save-tracepoints command */ | |
10660 | static void | |
10661 | tracepoint_save_command (char *args, int from_tty) | |
10662 | { | |
10663 | struct breakpoint *tp; | |
10664 | int any_tp = 0; | |
a7bdde9e VP |
10665 | struct command_line *line; |
10666 | char *pathname; | |
1042e4c0 SS |
10667 | char tmp[40]; |
10668 | struct cleanup *cleanup; | |
a7bdde9e | 10669 | struct ui_file *fp; |
1042e4c0 SS |
10670 | |
10671 | if (args == 0 || *args == 0) | |
10672 | error (_("Argument required (file name in which to save tracepoints)")); | |
10673 | ||
10674 | /* See if we have anything to save. */ | |
10675 | ALL_TRACEPOINTS (tp) | |
10676 | { | |
10677 | any_tp = 1; | |
10678 | break; | |
10679 | } | |
10680 | if (!any_tp) | |
10681 | { | |
10682 | warning (_("save-tracepoints: no tracepoints to save.")); | |
10683 | return; | |
10684 | } | |
10685 | ||
10686 | pathname = tilde_expand (args); | |
10687 | cleanup = make_cleanup (xfree, pathname); | |
a7bdde9e | 10688 | fp = gdb_fopen (pathname, "w"); |
059fb39f | 10689 | if (!fp) |
1042e4c0 SS |
10690 | error (_("Unable to open file '%s' for saving tracepoints (%s)"), |
10691 | args, safe_strerror (errno)); | |
a7bdde9e | 10692 | make_cleanup_ui_file_delete (fp); |
8bf6485c SS |
10693 | |
10694 | save_trace_state_variables (fp); | |
10695 | ||
1042e4c0 SS |
10696 | ALL_TRACEPOINTS (tp) |
10697 | { | |
8bf6485c SS |
10698 | if (tp->type == bp_fast_tracepoint) |
10699 | fprintf_unfiltered (fp, "ftrace"); | |
10700 | else | |
10701 | fprintf_unfiltered (fp, "trace"); | |
10702 | ||
1042e4c0 | 10703 | if (tp->addr_string) |
8bf6485c | 10704 | fprintf_unfiltered (fp, " %s", tp->addr_string); |
1042e4c0 SS |
10705 | else |
10706 | { | |
10707 | sprintf_vma (tmp, tp->loc->address); | |
8bf6485c | 10708 | fprintf_unfiltered (fp, " *0x%s", tmp); |
1042e4c0 SS |
10709 | } |
10710 | ||
8bf6485c SS |
10711 | if (tp->cond_string) |
10712 | fprintf_unfiltered (fp, " if %s", tp->cond_string); | |
10713 | ||
10714 | fprintf_unfiltered (fp, "\n"); | |
10715 | ||
1042e4c0 | 10716 | if (tp->pass_count) |
a7bdde9e | 10717 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); |
1042e4c0 | 10718 | |
a7bdde9e | 10719 | if (tp->commands) |
1042e4c0 | 10720 | { |
a7bdde9e VP |
10721 | volatile struct gdb_exception ex; |
10722 | ||
10723 | fprintf_unfiltered (fp, " actions\n"); | |
10724 | ||
10725 | ui_out_redirect (uiout, fp); | |
10726 | TRY_CATCH (ex, RETURN_MASK_ERROR) | |
1042e4c0 | 10727 | { |
9add0f1b | 10728 | print_command_lines (uiout, tp->commands->commands, 2); |
a7bdde9e VP |
10729 | } |
10730 | ui_out_redirect (uiout, NULL); | |
1042e4c0 | 10731 | |
a7bdde9e VP |
10732 | if (ex.reason < 0) |
10733 | throw_exception (ex); | |
1042e4c0 | 10734 | |
a7bdde9e | 10735 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 SS |
10736 | } |
10737 | } | |
8bf6485c SS |
10738 | |
10739 | if (*default_collect) | |
10740 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); | |
10741 | ||
1042e4c0 SS |
10742 | do_cleanups (cleanup); |
10743 | if (from_tty) | |
10744 | printf_filtered (_("Tracepoints saved to file '%s'.\n"), args); | |
10745 | return; | |
10746 | } | |
10747 | ||
10748 | /* Create a vector of all tracepoints. */ | |
10749 | ||
10750 | VEC(breakpoint_p) * | |
10751 | all_tracepoints () | |
10752 | { | |
10753 | VEC(breakpoint_p) *tp_vec = 0; | |
10754 | struct breakpoint *tp; | |
10755 | ||
10756 | ALL_TRACEPOINTS (tp) | |
10757 | { | |
10758 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
10759 | } | |
10760 | ||
10761 | return tp_vec; | |
10762 | } | |
10763 | ||
c906108c | 10764 | \f |
31e2b00f AS |
10765 | /* This help string is used for the break, hbreak, tbreak and thbreak commands. |
10766 | It is defined as a macro to prevent duplication. | |
10767 | COMMAND should be a string constant containing the name of the command. */ | |
10768 | #define BREAK_ARGS_HELP(command) \ | |
10769 | command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\ | |
10770 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ | |
10771 | If a line number is specified, break at start of code for that line.\n\ | |
10772 | If a function is specified, break at start of code for that function.\n\ | |
10773 | If an address is specified, break at that exact address.\n\ | |
10774 | With no LOCATION, uses current execution address of selected stack frame.\n\ | |
10775 | This is useful for breaking on return to a stack frame.\n\ | |
10776 | \n\ | |
10777 | THREADNUM is the number from \"info threads\".\n\ | |
10778 | CONDITION is a boolean expression.\n\ | |
10779 | \n\ | |
10780 | Multiple breakpoints at one place are permitted, and useful if conditional.\n\ | |
10781 | \n\ | |
10782 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
10783 | ||
44feb3ce TT |
10784 | /* List of subcommands for "catch". */ |
10785 | static struct cmd_list_element *catch_cmdlist; | |
10786 | ||
10787 | /* List of subcommands for "tcatch". */ | |
10788 | static struct cmd_list_element *tcatch_cmdlist; | |
10789 | ||
10790 | /* Like add_cmd, but add the command to both the "catch" and "tcatch" | |
10791 | lists, and pass some additional user data to the command function. */ | |
10792 | static void | |
10793 | add_catch_command (char *name, char *docstring, | |
10794 | void (*sfunc) (char *args, int from_tty, | |
10795 | struct cmd_list_element *command), | |
a96d9b2e SDJ |
10796 | char **(*completer) (struct cmd_list_element *cmd, |
10797 | char *text, char *word), | |
44feb3ce TT |
10798 | void *user_data_catch, |
10799 | void *user_data_tcatch) | |
10800 | { | |
10801 | struct cmd_list_element *command; | |
10802 | ||
10803 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
10804 | &catch_cmdlist); | |
10805 | set_cmd_sfunc (command, sfunc); | |
10806 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 10807 | set_cmd_completer (command, completer); |
44feb3ce TT |
10808 | |
10809 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
10810 | &tcatch_cmdlist); | |
10811 | set_cmd_sfunc (command, sfunc); | |
10812 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 10813 | set_cmd_completer (command, completer); |
44feb3ce TT |
10814 | } |
10815 | ||
6c95b8df | 10816 | static void |
a79b8f6e | 10817 | clear_syscall_counts (struct inferior *inf) |
6c95b8df | 10818 | { |
6c95b8df PA |
10819 | inf->total_syscalls_count = 0; |
10820 | inf->any_syscall_count = 0; | |
10821 | VEC_free (int, inf->syscalls_counts); | |
10822 | } | |
10823 | ||
c906108c | 10824 | void |
fba45db2 | 10825 | _initialize_breakpoint (void) |
c906108c | 10826 | { |
fa8d40ab JJ |
10827 | static struct cmd_list_element *breakpoint_set_cmdlist; |
10828 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
c906108c SS |
10829 | struct cmd_list_element *c; |
10830 | ||
84acb35a | 10831 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
6c95b8df | 10832 | observer_attach_inferior_exit (clear_syscall_counts); |
1f3b5d1b | 10833 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 10834 | |
c906108c SS |
10835 | breakpoint_chain = 0; |
10836 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
10837 | before a breakpoint is set. */ | |
10838 | breakpoint_count = 0; | |
10839 | ||
1042e4c0 SS |
10840 | tracepoint_count = 0; |
10841 | ||
1bedd215 AC |
10842 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
10843 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
10844 | Usage is `ignore N COUNT'.")); | |
c906108c | 10845 | if (xdb_commands) |
c5aa993b | 10846 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 10847 | |
1bedd215 AC |
10848 | add_com ("commands", class_breakpoint, commands_command, _("\ |
10849 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
10850 | Give breakpoint number as argument after \"commands\".\n\ |
10851 | With no argument, the targeted breakpoint is the last one set.\n\ | |
10852 | The commands themselves follow starting on the next line.\n\ | |
10853 | Type a line containing \"end\" to indicate the end of them.\n\ | |
10854 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 10855 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 10856 | |
1bedd215 AC |
10857 | add_com ("condition", class_breakpoint, condition_command, _("\ |
10858 | Specify breakpoint number N to break only if COND is true.\n\ | |
c906108c | 10859 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 10860 | expression to be evaluated whenever breakpoint N is reached.")); |
c906108c | 10861 | |
1bedd215 | 10862 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 10863 | Set a temporary breakpoint.\n\ |
c906108c SS |
10864 | Like \"break\" except the breakpoint is only temporary,\n\ |
10865 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
10866 | by using \"enable delete\" on the breakpoint number.\n\ |
10867 | \n" | |
10868 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 10869 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 10870 | |
1bedd215 | 10871 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
31e2b00f | 10872 | Set a hardware assisted breakpoint.\n\ |
c906108c | 10873 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
10874 | some target hardware may not have this support.\n\ |
10875 | \n" | |
10876 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 10877 | set_cmd_completer (c, location_completer); |
c906108c | 10878 | |
1bedd215 | 10879 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 10880 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 10881 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
10882 | so it will be deleted when hit.\n\ |
10883 | \n" | |
10884 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 10885 | set_cmd_completer (c, location_completer); |
c906108c | 10886 | |
1bedd215 AC |
10887 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
10888 | Enable some breakpoints.\n\ | |
c906108c SS |
10889 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
10890 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
10891 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 10892 | With a subcommand you can enable temporarily."), |
c906108c SS |
10893 | &enablelist, "enable ", 1, &cmdlist); |
10894 | if (xdb_commands) | |
1bedd215 AC |
10895 | add_com ("ab", class_breakpoint, enable_command, _("\ |
10896 | Enable some breakpoints.\n\ | |
c906108c SS |
10897 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
10898 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
10899 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 10900 | With a subcommand you can enable temporarily.")); |
c906108c SS |
10901 | |
10902 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
10903 | ||
1bedd215 AC |
10904 | add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
10905 | Enable some breakpoints.\n\ | |
c906108c SS |
10906 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
10907 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 10908 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 10909 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 10910 | |
1a966eab AC |
10911 | add_cmd ("once", no_class, enable_once_command, _("\ |
10912 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
10913 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
10914 | &enablebreaklist); |
10915 | ||
1a966eab AC |
10916 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
10917 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
10918 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
10919 | &enablebreaklist); |
10920 | ||
1a966eab AC |
10921 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
10922 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
10923 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
10924 | &enablelist); |
10925 | ||
1a966eab AC |
10926 | add_cmd ("once", no_class, enable_once_command, _("\ |
10927 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
10928 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
10929 | &enablelist); |
10930 | ||
1bedd215 AC |
10931 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
10932 | Disable some breakpoints.\n\ | |
c906108c SS |
10933 | Arguments are breakpoint numbers with spaces in between.\n\ |
10934 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 10935 | A disabled breakpoint is not forgotten, but has no effect until reenabled."), |
c906108c SS |
10936 | &disablelist, "disable ", 1, &cmdlist); |
10937 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
10938 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
10939 | if (xdb_commands) | |
1bedd215 AC |
10940 | add_com ("sb", class_breakpoint, disable_command, _("\ |
10941 | Disable some breakpoints.\n\ | |
c906108c SS |
10942 | Arguments are breakpoint numbers with spaces in between.\n\ |
10943 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 10944 | A disabled breakpoint is not forgotten, but has no effect until reenabled.")); |
c906108c | 10945 | |
1a966eab AC |
10946 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
10947 | Disable some breakpoints.\n\ | |
c906108c SS |
10948 | Arguments are breakpoint numbers with spaces in between.\n\ |
10949 | To disable all breakpoints, give no argument.\n\ | |
10950 | A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\ | |
1a966eab | 10951 | This command may be abbreviated \"disable\"."), |
c906108c SS |
10952 | &disablelist); |
10953 | ||
1bedd215 AC |
10954 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
10955 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
10956 | Arguments are breakpoint numbers with spaces in between.\n\ |
10957 | To delete all breakpoints, give no argument.\n\ | |
10958 | \n\ | |
10959 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 10960 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
10961 | &deletelist, "delete ", 1, &cmdlist); |
10962 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 10963 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 10964 | if (xdb_commands) |
1bedd215 AC |
10965 | add_com ("db", class_breakpoint, delete_command, _("\ |
10966 | Delete some breakpoints.\n\ | |
c906108c | 10967 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 10968 | To delete all breakpoints, give no argument.\n")); |
c906108c | 10969 | |
1a966eab AC |
10970 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
10971 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
10972 | Arguments are breakpoint numbers with spaces in between.\n\ |
10973 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 10974 | This command may be abbreviated \"delete\"."), |
c906108c SS |
10975 | &deletelist); |
10976 | ||
1bedd215 AC |
10977 | add_com ("clear", class_breakpoint, clear_command, _("\ |
10978 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
10979 | Argument may be line number, function name, or \"*\" and an address.\n\ |
10980 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
10981 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
10982 | If an address is specified, breakpoints at that address are cleared.\n\ |
10983 | \n\ | |
10984 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
10985 | is executing in.\n\ |
10986 | \n\ | |
1bedd215 | 10987 | See also the \"delete\" command which clears breakpoints by number.")); |
c906108c | 10988 | |
1bedd215 | 10989 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
10990 | Set breakpoint at specified line or function.\n" |
10991 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 10992 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 10993 | |
c906108c SS |
10994 | add_com_alias ("b", "break", class_run, 1); |
10995 | add_com_alias ("br", "break", class_run, 1); | |
10996 | add_com_alias ("bre", "break", class_run, 1); | |
10997 | add_com_alias ("brea", "break", class_run, 1); | |
10998 | ||
7681d515 PM |
10999 | if (xdb_commands) |
11000 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
11001 | |
11002 | if (dbx_commands) | |
11003 | { | |
1bedd215 AC |
11004 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
11005 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
11006 | &stoplist, "stop ", 1, &cmdlist); |
11007 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 11008 | _("Break in function or address."), &stoplist); |
c5aa993b | 11009 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 11010 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
11011 | add_com ("status", class_info, breakpoints_info, _("\ |
11012 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
11013 | The \"Type\" column indicates one of:\n\ |
11014 | \tbreakpoint - normal breakpoint\n\ | |
11015 | \twatchpoint - watchpoint\n\ | |
11016 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
11017 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
11018 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
11019 | address and file/line number respectively.\n\ |
11020 | \n\ | |
11021 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
11022 | are set to the address of the last breakpoint listed unless the command\n\ |
11023 | is prefixed with \"server \".\n\n\ | |
c906108c | 11024 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 11025 | breakpoint set.")); |
c906108c SS |
11026 | } |
11027 | ||
1bedd215 AC |
11028 | add_info ("breakpoints", breakpoints_info, _("\ |
11029 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
11030 | The \"Type\" column indicates one of:\n\ |
11031 | \tbreakpoint - normal breakpoint\n\ | |
11032 | \twatchpoint - watchpoint\n\ | |
11033 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
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\ | |
1bedd215 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\ |
1bedd215 | 11042 | breakpoint set.")); |
c906108c | 11043 | |
6b04bdb7 MS |
11044 | add_info_alias ("b", "breakpoints", 1); |
11045 | ||
c906108c | 11046 | if (xdb_commands) |
1bedd215 AC |
11047 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
11048 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
11049 | The \"Type\" column indicates one of:\n\ |
11050 | \tbreakpoint - normal breakpoint\n\ | |
11051 | \twatchpoint - watchpoint\n\ | |
11052 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
11053 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
11054 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
11055 | address and file/line number respectively.\n\ |
11056 | \n\ | |
11057 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
11058 | are set to the address of the last breakpoint listed unless the command\n\ |
11059 | is prefixed with \"server \".\n\n\ | |
c906108c | 11060 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 11061 | breakpoint set.")); |
c906108c | 11062 | |
1a966eab AC |
11063 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
11064 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
11065 | The \"Type\" column indicates one of:\n\ |
11066 | \tbreakpoint - normal breakpoint\n\ | |
11067 | \twatchpoint - watchpoint\n\ | |
11068 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
11069 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
11070 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
11071 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
11072 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
11073 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
11074 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
11075 | address and file/line number respectively.\n\ |
11076 | \n\ | |
11077 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
11078 | are set to the address of the last breakpoint listed unless the command\n\ |
11079 | is prefixed with \"server \".\n\n\ | |
c906108c | 11080 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 11081 | breakpoint set."), |
c906108c SS |
11082 | &maintenanceinfolist); |
11083 | ||
44feb3ce TT |
11084 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
11085 | Set catchpoints to catch events."), | |
11086 | &catch_cmdlist, "catch ", | |
11087 | 0/*allow-unknown*/, &cmdlist); | |
11088 | ||
11089 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
11090 | Set temporary catchpoints to catch events."), | |
11091 | &tcatch_cmdlist, "tcatch ", | |
11092 | 0/*allow-unknown*/, &cmdlist); | |
11093 | ||
11094 | /* Add catch and tcatch sub-commands. */ | |
11095 | add_catch_command ("catch", _("\ | |
11096 | Catch an exception, when caught.\n\ | |
11097 | With an argument, catch only exceptions with the given name."), | |
11098 | catch_catch_command, | |
a96d9b2e | 11099 | NULL, |
44feb3ce TT |
11100 | CATCH_PERMANENT, |
11101 | CATCH_TEMPORARY); | |
11102 | add_catch_command ("throw", _("\ | |
11103 | Catch an exception, when thrown.\n\ | |
11104 | With an argument, catch only exceptions with the given name."), | |
11105 | catch_throw_command, | |
a96d9b2e | 11106 | NULL, |
44feb3ce TT |
11107 | CATCH_PERMANENT, |
11108 | CATCH_TEMPORARY); | |
11109 | add_catch_command ("fork", _("Catch calls to fork."), | |
11110 | catch_fork_command_1, | |
a96d9b2e | 11111 | NULL, |
44feb3ce TT |
11112 | (void *) (uintptr_t) catch_fork_permanent, |
11113 | (void *) (uintptr_t) catch_fork_temporary); | |
11114 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
11115 | catch_fork_command_1, | |
a96d9b2e | 11116 | NULL, |
44feb3ce TT |
11117 | (void *) (uintptr_t) catch_vfork_permanent, |
11118 | (void *) (uintptr_t) catch_vfork_temporary); | |
11119 | add_catch_command ("exec", _("Catch calls to exec."), | |
11120 | catch_exec_command_1, | |
a96d9b2e SDJ |
11121 | NULL, |
11122 | CATCH_PERMANENT, | |
11123 | CATCH_TEMPORARY); | |
11124 | add_catch_command ("syscall", _("\ | |
11125 | Catch system calls by their names and/or numbers.\n\ | |
11126 | Arguments say which system calls to catch. If no arguments\n\ | |
11127 | are given, every system call will be caught.\n\ | |
11128 | Arguments, if given, should be one or more system call names\n\ | |
11129 | (if your system supports that), or system call numbers."), | |
11130 | catch_syscall_command_1, | |
11131 | catch_syscall_completer, | |
44feb3ce TT |
11132 | CATCH_PERMANENT, |
11133 | CATCH_TEMPORARY); | |
44feb3ce TT |
11134 | add_catch_command ("exception", _("\ |
11135 | Catch Ada exceptions, when raised.\n\ | |
11136 | With an argument, catch only exceptions with the given name."), | |
11137 | catch_ada_exception_command, | |
a96d9b2e | 11138 | NULL, |
44feb3ce TT |
11139 | CATCH_PERMANENT, |
11140 | CATCH_TEMPORARY); | |
11141 | add_catch_command ("assert", _("\ | |
11142 | Catch failed Ada assertions, when raised.\n\ | |
11143 | With an argument, catch only exceptions with the given name."), | |
11144 | catch_assert_command, | |
a96d9b2e | 11145 | NULL, |
44feb3ce TT |
11146 | CATCH_PERMANENT, |
11147 | CATCH_TEMPORARY); | |
c5aa993b | 11148 | |
1bedd215 AC |
11149 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
11150 | Set a watchpoint for an expression.\n\ | |
c906108c | 11151 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 11152 | an expression changes.")); |
65d12d83 | 11153 | set_cmd_completer (c, expression_completer); |
c906108c | 11154 | |
1bedd215 AC |
11155 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
11156 | Set a read watchpoint for an expression.\n\ | |
c906108c | 11157 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 11158 | an expression is read.")); |
65d12d83 | 11159 | set_cmd_completer (c, expression_completer); |
c906108c | 11160 | |
1bedd215 AC |
11161 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
11162 | Set a watchpoint for an expression.\n\ | |
c906108c | 11163 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 11164 | an expression is either read or written.")); |
65d12d83 | 11165 | set_cmd_completer (c, expression_completer); |
c906108c SS |
11166 | |
11167 | add_info ("watchpoints", breakpoints_info, | |
1bedd215 | 11168 | _("Synonym for ``info breakpoints''.")); |
c906108c SS |
11169 | |
11170 | ||
920d2a44 AC |
11171 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
11172 | respond to changes - contrary to the description. */ | |
85c07804 AC |
11173 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
11174 | &can_use_hw_watchpoints, _("\ | |
11175 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
11176 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
11177 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
11178 | such is available. (However, any hardware watchpoints that were\n\ | |
11179 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
11180 | hardware.)"), |
11181 | NULL, | |
920d2a44 | 11182 | show_can_use_hw_watchpoints, |
85c07804 | 11183 | &setlist, &showlist); |
c906108c SS |
11184 | |
11185 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 11186 | |
1042e4c0 SS |
11187 | /* Tracepoint manipulation commands. */ |
11188 | ||
11189 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
11190 | Set a tracepoint at specified line or function.\n\ | |
11191 | \n" | |
11192 | BREAK_ARGS_HELP ("trace") "\n\ | |
11193 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
11194 | set_cmd_completer (c, location_completer); | |
11195 | ||
11196 | add_com_alias ("tp", "trace", class_alias, 0); | |
11197 | add_com_alias ("tr", "trace", class_alias, 1); | |
11198 | add_com_alias ("tra", "trace", class_alias, 1); | |
11199 | add_com_alias ("trac", "trace", class_alias, 1); | |
11200 | ||
7a697b8d SS |
11201 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
11202 | Set a fast tracepoint at specified line or function.\n\ | |
11203 | \n" | |
11204 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
11205 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
11206 | set_cmd_completer (c, location_completer); | |
11207 | ||
1042e4c0 SS |
11208 | add_info ("tracepoints", tracepoints_info, _("\ |
11209 | Status of tracepoints, or tracepoint number NUMBER.\n\ | |
11210 | Convenience variable \"$tpnum\" contains the number of the\n\ | |
11211 | last tracepoint set.")); | |
11212 | ||
11213 | add_info_alias ("tp", "tracepoints", 1); | |
11214 | ||
11215 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
11216 | Delete specified tracepoints.\n\ | |
11217 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
11218 | No argument means delete all tracepoints."), | |
11219 | &deletelist); | |
11220 | ||
11221 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
11222 | Disable specified tracepoints.\n\ | |
11223 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
11224 | No argument means disable all tracepoints."), | |
11225 | &disablelist); | |
11226 | deprecate_cmd (c, "disable"); | |
11227 | ||
11228 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
11229 | Enable specified tracepoints.\n\ | |
11230 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
11231 | No argument means enable all tracepoints."), | |
11232 | &enablelist); | |
11233 | deprecate_cmd (c, "enable"); | |
11234 | ||
11235 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
11236 | Set the passcount for a tracepoint.\n\ | |
11237 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
11238 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
11239 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
11240 | ||
11241 | c = add_com ("save-tracepoints", class_trace, tracepoint_save_command, _("\ | |
11242 | Save current tracepoint definitions as a script.\n\ | |
11243 | Use the 'source' command in another debug session to restore them.")); | |
11244 | set_cmd_completer (c, filename_completer); | |
11245 | ||
1bedd215 | 11246 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
11247 | Breakpoint specific settings\n\ |
11248 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 11249 | pending breakpoint behavior"), |
fa8d40ab JJ |
11250 | &breakpoint_set_cmdlist, "set breakpoint ", |
11251 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 11252 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
11253 | Breakpoint specific settings\n\ |
11254 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 11255 | pending breakpoint behavior"), |
fa8d40ab JJ |
11256 | &breakpoint_show_cmdlist, "show breakpoint ", |
11257 | 0/*allow-unknown*/, &showlist); | |
11258 | ||
7915a72c AC |
11259 | add_setshow_auto_boolean_cmd ("pending", no_class, |
11260 | &pending_break_support, _("\ | |
11261 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
11262 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
11263 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
11264 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
11265 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 11266 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 11267 | NULL, |
920d2a44 | 11268 | show_pending_break_support, |
6e1d7d6c AC |
11269 | &breakpoint_set_cmdlist, |
11270 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
11271 | |
11272 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
11273 | |
11274 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
11275 | &automatic_hardware_breakpoints, _("\ | |
11276 | Set automatic usage of hardware breakpoints."), _("\ | |
11277 | Show automatic usage of hardware breakpoints."), _("\ | |
11278 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
11279 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
11280 | a warning will be emitted for such breakpoints."), | |
11281 | NULL, | |
11282 | show_automatic_hardware_breakpoints, | |
11283 | &breakpoint_set_cmdlist, | |
11284 | &breakpoint_show_cmdlist); | |
74960c60 | 11285 | |
33e5cbd6 PA |
11286 | add_setshow_enum_cmd ("always-inserted", class_support, |
11287 | always_inserted_enums, &always_inserted_mode, _("\ | |
74960c60 VP |
11288 | Set mode for inserting breakpoints."), _("\ |
11289 | Show mode for inserting breakpoints."), _("\ | |
33e5cbd6 PA |
11290 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
11291 | resumed, and removed when execution stops. When this mode is on,\n\ | |
11292 | breakpoints are inserted immediately and removed only when the user\n\ | |
11293 | deletes the breakpoint. When this mode is auto (which is the default),\n\ | |
11294 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ | |
11295 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ | |
11296 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ | |
11297 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), | |
74960c60 VP |
11298 | NULL, |
11299 | &show_always_inserted_mode, | |
11300 | &breakpoint_set_cmdlist, | |
11301 | &breakpoint_show_cmdlist); | |
765dc015 VP |
11302 | |
11303 | automatic_hardware_breakpoints = 1; | |
f3b1572e PA |
11304 | |
11305 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
c906108c | 11306 | } |