Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Everything about breakpoints, for GDB. |
8926118c | 2 | |
0b302171 | 3 | Copyright (C) 1986-2012 Free Software Foundation, Inc. |
c906108c | 4 | |
c5aa993b | 5 | This file is part of GDB. |
c906108c | 6 | |
c5aa993b JM |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 10 | (at your option) any later version. |
c906108c | 11 | |
c5aa993b JM |
12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
c906108c | 16 | |
c5aa993b | 17 | You should have received a copy of the GNU General Public License |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
19 | |
20 | #include "defs.h" | |
a6d9a66e | 21 | #include "arch-utils.h" |
c906108c | 22 | #include <ctype.h> |
776592bf | 23 | #include "hashtab.h" |
c906108c SS |
24 | #include "symtab.h" |
25 | #include "frame.h" | |
26 | #include "breakpoint.h" | |
1042e4c0 | 27 | #include "tracepoint.h" |
c906108c SS |
28 | #include "gdbtypes.h" |
29 | #include "expression.h" | |
30 | #include "gdbcore.h" | |
31 | #include "gdbcmd.h" | |
32 | #include "value.h" | |
33 | #include "command.h" | |
34 | #include "inferior.h" | |
35 | #include "gdbthread.h" | |
36 | #include "target.h" | |
37 | #include "language.h" | |
38 | #include "gdb_string.h" | |
50f182aa | 39 | #include "gdb-demangle.h" |
0ba1096a | 40 | #include "filenames.h" |
c906108c SS |
41 | #include "annotate.h" |
42 | #include "symfile.h" | |
43 | #include "objfiles.h" | |
0378c332 | 44 | #include "source.h" |
c5f0f3d0 | 45 | #include "linespec.h" |
c94fdfd0 | 46 | #include "completer.h" |
5b7f31a4 | 47 | #include "gdb.h" |
8b93c638 | 48 | #include "ui-out.h" |
e1507482 | 49 | #include "cli/cli-script.h" |
0225421b | 50 | #include "gdb_assert.h" |
fe898f56 | 51 | #include "block.h" |
a77053c2 | 52 | #include "solib.h" |
84acb35a JJ |
53 | #include "solist.h" |
54 | #include "observer.h" | |
60250e8b | 55 | #include "exceptions.h" |
765dc015 | 56 | #include "memattr.h" |
f7f9143b | 57 | #include "ada-lang.h" |
d1aa2f50 | 58 | #include "top.h" |
79a45b7d | 59 | #include "valprint.h" |
4efc6507 | 60 | #include "jit.h" |
a96d9b2e | 61 | #include "xml-syscall.h" |
65d79d4b | 62 | #include "parser-defs.h" |
e9cafbcc | 63 | #include "cli/cli-utils.h" |
be34f849 | 64 | #include "continuations.h" |
1bfeeb0f JL |
65 | #include "stack.h" |
66 | #include "skip.h" | |
049e32d3 | 67 | #include "record.h" |
edcc5120 | 68 | #include "gdb_regex.h" |
c906108c | 69 | |
1042e4c0 SS |
70 | /* readline include files */ |
71 | #include "readline/readline.h" | |
72 | #include "readline/history.h" | |
73 | ||
74 | /* readline defines this. */ | |
75 | #undef savestring | |
76 | ||
034dad6f | 77 | #include "mi/mi-common.h" |
7371cf6d | 78 | #include "python/python.h" |
104c1213 | 79 | |
4a64f543 | 80 | /* Prototypes for local functions. */ |
c906108c | 81 | |
a14ed312 | 82 | static void enable_delete_command (char *, int); |
c906108c | 83 | |
a14ed312 | 84 | static void enable_once_command (char *, int); |
c906108c | 85 | |
a14ed312 | 86 | static void disable_command (char *, int); |
c906108c | 87 | |
a14ed312 | 88 | static void enable_command (char *, int); |
c906108c | 89 | |
95a42b64 TT |
90 | static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *, |
91 | void *), | |
92 | void *); | |
c906108c | 93 | |
a14ed312 | 94 | static void ignore_command (char *, int); |
c906108c | 95 | |
4efb68b1 | 96 | static int breakpoint_re_set_one (void *); |
c906108c | 97 | |
348d480f PA |
98 | static void breakpoint_re_set_default (struct breakpoint *); |
99 | ||
983af33b SDJ |
100 | static void create_sals_from_address_default (char **, |
101 | struct linespec_result *, | |
102 | enum bptype, char *, | |
103 | char **); | |
104 | ||
105 | static void create_breakpoints_sal_default (struct gdbarch *, | |
106 | struct linespec_result *, | |
107 | struct linespec_sals *, | |
108 | char *, enum bptype, | |
109 | enum bpdisp, int, int, | |
110 | int, | |
111 | const struct breakpoint_ops *, | |
112 | int, int, int); | |
113 | ||
114 | static void decode_linespec_default (struct breakpoint *, char **, | |
115 | struct symtabs_and_lines *); | |
116 | ||
a14ed312 | 117 | static void clear_command (char *, int); |
c906108c | 118 | |
a14ed312 | 119 | static void catch_command (char *, int); |
c906108c | 120 | |
a9634178 | 121 | static int can_use_hardware_watchpoint (struct value *); |
c906108c | 122 | |
98deb0da | 123 | static void break_command_1 (char *, int, int); |
c906108c | 124 | |
a14ed312 | 125 | static void mention (struct breakpoint *); |
c906108c | 126 | |
348d480f PA |
127 | static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *, |
128 | enum bptype, | |
c0a91b2b | 129 | const struct breakpoint_ops *); |
3742cc8b YQ |
130 | static struct bp_location *add_location_to_breakpoint (struct breakpoint *, |
131 | const struct symtab_and_line *); | |
132 | ||
4a64f543 MS |
133 | /* This function is used in gdbtk sources and thus can not be made |
134 | static. */ | |
63c252f8 | 135 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
348d480f | 136 | struct symtab_and_line, |
c0a91b2b TT |
137 | enum bptype, |
138 | const struct breakpoint_ops *); | |
c906108c | 139 | |
06edf0c0 PA |
140 | static struct breakpoint * |
141 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
142 | enum bptype type, | |
c0a91b2b | 143 | const struct breakpoint_ops *ops); |
06edf0c0 | 144 | |
76897487 KB |
145 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
146 | ||
a6d9a66e UW |
147 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
148 | CORE_ADDR bpaddr, | |
88f7da05 | 149 | enum bptype bptype); |
76897487 | 150 | |
6c95b8df PA |
151 | static void describe_other_breakpoints (struct gdbarch *, |
152 | struct program_space *, CORE_ADDR, | |
5af949e3 | 153 | struct obj_section *, int); |
c906108c | 154 | |
6c95b8df PA |
155 | static int breakpoint_address_match (struct address_space *aspace1, |
156 | CORE_ADDR addr1, | |
157 | struct address_space *aspace2, | |
158 | CORE_ADDR addr2); | |
159 | ||
85d721b8 PA |
160 | static int watchpoint_locations_match (struct bp_location *loc1, |
161 | struct bp_location *loc2); | |
162 | ||
f1310107 TJB |
163 | static int breakpoint_location_address_match (struct bp_location *bl, |
164 | struct address_space *aspace, | |
165 | CORE_ADDR addr); | |
166 | ||
a14ed312 | 167 | static void breakpoints_info (char *, int); |
c906108c | 168 | |
d77f58be SS |
169 | static void watchpoints_info (char *, int); |
170 | ||
e5a67952 MS |
171 | static int breakpoint_1 (char *, int, |
172 | int (*) (const struct breakpoint *)); | |
c906108c | 173 | |
4efb68b1 | 174 | static int breakpoint_cond_eval (void *); |
c906108c | 175 | |
4efb68b1 | 176 | static void cleanup_executing_breakpoints (void *); |
c906108c | 177 | |
a14ed312 | 178 | static void commands_command (char *, int); |
c906108c | 179 | |
a14ed312 | 180 | static void condition_command (char *, int); |
c906108c | 181 | |
c5aa993b JM |
182 | typedef enum |
183 | { | |
184 | mark_inserted, | |
185 | mark_uninserted | |
186 | } | |
187 | insertion_state_t; | |
c906108c | 188 | |
0bde7532 | 189 | static int remove_breakpoint (struct bp_location *, insertion_state_t); |
6c95b8df | 190 | static int remove_breakpoint_1 (struct bp_location *, insertion_state_t); |
c906108c | 191 | |
e514a9d6 | 192 | static enum print_stop_action print_bp_stop_message (bpstat bs); |
c906108c | 193 | |
4efb68b1 | 194 | static int watchpoint_check (void *); |
c906108c | 195 | |
a14ed312 | 196 | static void maintenance_info_breakpoints (char *, int); |
c906108c | 197 | |
a14ed312 | 198 | static int hw_breakpoint_used_count (void); |
c906108c | 199 | |
a1398e0c PA |
200 | static int hw_watchpoint_use_count (struct breakpoint *); |
201 | ||
202 | static int hw_watchpoint_used_count_others (struct breakpoint *except, | |
203 | enum bptype type, | |
204 | int *other_type_used); | |
c906108c | 205 | |
a14ed312 | 206 | static void hbreak_command (char *, int); |
c906108c | 207 | |
a14ed312 | 208 | static void thbreak_command (char *, int); |
c906108c | 209 | |
51be5b68 | 210 | static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp); |
c906108c | 211 | |
a14ed312 | 212 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 213 | |
a14ed312 | 214 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 215 | |
a14ed312 | 216 | static void stopat_command (char *arg, int from_tty); |
7a292a7a | 217 | |
a14ed312 | 218 | static char *ep_parse_optional_if_clause (char **arg); |
7a292a7a | 219 | |
d85310f7 MS |
220 | static void catch_exception_command_1 (enum exception_event_kind ex_event, |
221 | char *arg, int tempflag, int from_tty); | |
7a292a7a | 222 | |
a14ed312 | 223 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 224 | |
d03285ec UW |
225 | static void detach_single_step_breakpoints (void); |
226 | ||
6c95b8df PA |
227 | static int single_step_breakpoint_inserted_here_p (struct address_space *, |
228 | CORE_ADDR pc); | |
1aafd4da | 229 | |
fe3f5fa8 | 230 | static void free_bp_location (struct bp_location *loc); |
f431efe5 PA |
231 | static void incref_bp_location (struct bp_location *loc); |
232 | static void decref_bp_location (struct bp_location **loc); | |
fe3f5fa8 | 233 | |
39d61571 | 234 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 235 | |
b60e7edf | 236 | static void update_global_location_list (int); |
a5606eee | 237 | |
b60e7edf | 238 | static void update_global_location_list_nothrow (int); |
74960c60 | 239 | |
d77f58be | 240 | static int is_hardware_watchpoint (const struct breakpoint *bpt); |
74960c60 VP |
241 | |
242 | static void insert_breakpoint_locations (void); | |
a5606eee | 243 | |
a96d9b2e SDJ |
244 | static int syscall_catchpoint_p (struct breakpoint *b); |
245 | ||
1042e4c0 SS |
246 | static void tracepoints_info (char *, int); |
247 | ||
248 | static void delete_trace_command (char *, int); | |
249 | ||
250 | static void enable_trace_command (char *, int); | |
251 | ||
252 | static void disable_trace_command (char *, int); | |
253 | ||
254 | static void trace_pass_command (char *, int); | |
255 | ||
9c06b0b4 TJB |
256 | static int is_masked_watchpoint (const struct breakpoint *b); |
257 | ||
983af33b SDJ |
258 | /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero |
259 | otherwise. */ | |
260 | ||
261 | static int strace_marker_p (struct breakpoint *b); | |
0fb4aa4b | 262 | |
edcc5120 TT |
263 | static void init_catchpoint (struct breakpoint *b, |
264 | struct gdbarch *gdbarch, int tempflag, | |
265 | char *cond_string, | |
266 | const struct breakpoint_ops *ops); | |
267 | ||
2060206e PA |
268 | /* The abstract base class all breakpoint_ops structures inherit |
269 | from. */ | |
270 | static struct breakpoint_ops base_breakpoint_ops; | |
271 | ||
272 | /* The breakpoint_ops structure to be inherited by all breakpoint_ops | |
273 | that are implemented on top of software or hardware breakpoints | |
274 | (user breakpoints, internal and momentary breakpoints, etc.). */ | |
275 | static struct breakpoint_ops bkpt_base_breakpoint_ops; | |
276 | ||
277 | /* Internal breakpoints class type. */ | |
06edf0c0 | 278 | static struct breakpoint_ops internal_breakpoint_ops; |
2060206e PA |
279 | |
280 | /* Momentary breakpoints class type. */ | |
06edf0c0 PA |
281 | static struct breakpoint_ops momentary_breakpoint_ops; |
282 | ||
2060206e PA |
283 | /* The breakpoint_ops structure to be used in regular user created |
284 | breakpoints. */ | |
285 | struct breakpoint_ops bkpt_breakpoint_ops; | |
286 | ||
5cea2a26 PA |
287 | /* A reference-counted struct command_line. This lets multiple |
288 | breakpoints share a single command list. */ | |
289 | struct counted_command_line | |
290 | { | |
291 | /* The reference count. */ | |
292 | int refc; | |
293 | ||
294 | /* The command list. */ | |
295 | struct command_line *commands; | |
296 | }; | |
297 | ||
298 | struct command_line * | |
299 | breakpoint_commands (struct breakpoint *b) | |
300 | { | |
301 | return b->commands ? b->commands->commands : NULL; | |
302 | } | |
3daf8fe5 | 303 | |
f3b1572e PA |
304 | /* Flag indicating that a command has proceeded the inferior past the |
305 | current breakpoint. */ | |
306 | ||
307 | static int breakpoint_proceeded; | |
308 | ||
956a9fb9 | 309 | const char * |
2cec12e5 AR |
310 | bpdisp_text (enum bpdisp disp) |
311 | { | |
4a64f543 MS |
312 | /* NOTE: the following values are a part of MI protocol and |
313 | represent values of 'disp' field returned when inferior stops at | |
314 | a breakpoint. */ | |
bc043ef3 | 315 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
cc59ec59 | 316 | |
2cec12e5 AR |
317 | return bpdisps[(int) disp]; |
318 | } | |
c906108c | 319 | |
4a64f543 | 320 | /* Prototypes for exported functions. */ |
c906108c | 321 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
4a64f543 | 322 | if such is available. */ |
c906108c SS |
323 | static int can_use_hw_watchpoints; |
324 | ||
920d2a44 AC |
325 | static void |
326 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
327 | struct cmd_list_element *c, | |
328 | const char *value) | |
329 | { | |
3e43a32a MS |
330 | fprintf_filtered (file, |
331 | _("Debugger's willingness to use " | |
332 | "watchpoint hardware is %s.\n"), | |
920d2a44 AC |
333 | value); |
334 | } | |
335 | ||
fa8d40ab JJ |
336 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
337 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
4a64f543 | 338 | for unrecognized breakpoint locations. |
fa8d40ab JJ |
339 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
340 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
341 | static void |
342 | show_pending_break_support (struct ui_file *file, int from_tty, | |
343 | struct cmd_list_element *c, | |
344 | const char *value) | |
345 | { | |
3e43a32a MS |
346 | fprintf_filtered (file, |
347 | _("Debugger's behavior regarding " | |
348 | "pending breakpoints is %s.\n"), | |
920d2a44 AC |
349 | value); |
350 | } | |
fa8d40ab | 351 | |
765dc015 | 352 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
4a64f543 | 353 | set with "break" but falling in read-only memory. |
765dc015 VP |
354 | If 0, gdb will warn about such breakpoints, but won't automatically |
355 | use hardware breakpoints. */ | |
356 | static int automatic_hardware_breakpoints; | |
357 | static void | |
358 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
359 | struct cmd_list_element *c, | |
360 | const char *value) | |
361 | { | |
3e43a32a MS |
362 | fprintf_filtered (file, |
363 | _("Automatic usage of hardware breakpoints is %s.\n"), | |
765dc015 VP |
364 | value); |
365 | } | |
366 | ||
33e5cbd6 PA |
367 | /* If on, gdb will keep breakpoints inserted even as inferior is |
368 | stopped, and immediately insert any new breakpoints. If off, gdb | |
369 | will insert breakpoints into inferior only when resuming it, and | |
370 | will remove breakpoints upon stop. If auto, GDB will behave as ON | |
371 | if in non-stop mode, and as OFF if all-stop mode.*/ | |
372 | ||
373 | static const char always_inserted_auto[] = "auto"; | |
374 | static const char always_inserted_on[] = "on"; | |
375 | static const char always_inserted_off[] = "off"; | |
40478521 | 376 | static const char *const always_inserted_enums[] = { |
33e5cbd6 PA |
377 | always_inserted_auto, |
378 | always_inserted_off, | |
379 | always_inserted_on, | |
380 | NULL | |
381 | }; | |
382 | static const char *always_inserted_mode = always_inserted_auto; | |
383 | static void | |
74960c60 | 384 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 385 | struct cmd_list_element *c, const char *value) |
74960c60 | 386 | { |
33e5cbd6 | 387 | if (always_inserted_mode == always_inserted_auto) |
3e43a32a MS |
388 | fprintf_filtered (file, |
389 | _("Always inserted breakpoint " | |
390 | "mode is %s (currently %s).\n"), | |
33e5cbd6 PA |
391 | value, |
392 | breakpoints_always_inserted_mode () ? "on" : "off"); | |
393 | else | |
3e43a32a MS |
394 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), |
395 | value); | |
74960c60 VP |
396 | } |
397 | ||
33e5cbd6 PA |
398 | int |
399 | breakpoints_always_inserted_mode (void) | |
400 | { | |
049e32d3 PA |
401 | return ((always_inserted_mode == always_inserted_on |
402 | || (always_inserted_mode == always_inserted_auto && non_stop)) | |
403 | && !RECORD_IS_USED); | |
33e5cbd6 | 404 | } |
765dc015 | 405 | |
a14ed312 | 406 | void _initialize_breakpoint (void); |
c906108c | 407 | |
c906108c SS |
408 | /* Are we executing breakpoint commands? */ |
409 | static int executing_breakpoint_commands; | |
410 | ||
c02f5703 MS |
411 | /* Are overlay event breakpoints enabled? */ |
412 | static int overlay_events_enabled; | |
413 | ||
e09342b5 TJB |
414 | /* See description in breakpoint.h. */ |
415 | int target_exact_watchpoints = 0; | |
416 | ||
c906108c | 417 | /* Walk the following statement or block through all breakpoints. |
e5dd4106 | 418 | ALL_BREAKPOINTS_SAFE does so even if the statement deletes the |
4a64f543 | 419 | current breakpoint. */ |
c906108c | 420 | |
5c44784c | 421 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 422 | |
5c44784c JM |
423 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
424 | for (B = breakpoint_chain; \ | |
425 | B ? (TMP=B->next, 1): 0; \ | |
426 | B = TMP) | |
c906108c | 427 | |
4a64f543 MS |
428 | /* Similar iterator for the low-level breakpoints. SAFE variant is |
429 | not provided so update_global_location_list must not be called | |
430 | while executing the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 431 | |
876fa593 JK |
432 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
433 | for (BP_TMP = bp_location; \ | |
434 | BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \ | |
435 | BP_TMP++) | |
7cc221ef | 436 | |
1042e4c0 SS |
437 | /* Iterator for tracepoints only. */ |
438 | ||
439 | #define ALL_TRACEPOINTS(B) \ | |
440 | for (B = breakpoint_chain; B; B = B->next) \ | |
d77f58be | 441 | if (is_tracepoint (B)) |
1042e4c0 | 442 | |
7cc221ef | 443 | /* Chains of all breakpoints defined. */ |
c906108c SS |
444 | |
445 | struct breakpoint *breakpoint_chain; | |
446 | ||
876fa593 JK |
447 | /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */ |
448 | ||
449 | static struct bp_location **bp_location; | |
450 | ||
451 | /* Number of elements of BP_LOCATION. */ | |
452 | ||
453 | static unsigned bp_location_count; | |
454 | ||
4a64f543 MS |
455 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
456 | ADDRESS for the current elements of BP_LOCATION which get a valid | |
457 | result from bp_location_has_shadow. You can use it for roughly | |
458 | limiting the subrange of BP_LOCATION to scan for shadow bytes for | |
459 | an address you need to read. */ | |
876fa593 JK |
460 | |
461 | static CORE_ADDR bp_location_placed_address_before_address_max; | |
462 | ||
4a64f543 MS |
463 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
464 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of | |
465 | BP_LOCATION which get a valid result from bp_location_has_shadow. | |
466 | You can use it for roughly limiting the subrange of BP_LOCATION to | |
467 | scan for shadow bytes for an address you need to read. */ | |
876fa593 JK |
468 | |
469 | static CORE_ADDR bp_location_shadow_len_after_address_max; | |
7cc221ef | 470 | |
4a64f543 MS |
471 | /* The locations that no longer correspond to any breakpoint, unlinked |
472 | from bp_location array, but for which a hit may still be reported | |
473 | by a target. */ | |
20874c92 VP |
474 | VEC(bp_location_p) *moribund_locations = NULL; |
475 | ||
c906108c SS |
476 | /* Number of last breakpoint made. */ |
477 | ||
95a42b64 TT |
478 | static int breakpoint_count; |
479 | ||
86b17b60 PA |
480 | /* The value of `breakpoint_count' before the last command that |
481 | created breakpoints. If the last (break-like) command created more | |
482 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
483 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
484 | static int prev_breakpoint_count; | |
c906108c | 485 | |
1042e4c0 SS |
486 | /* Number of last tracepoint made. */ |
487 | ||
95a42b64 | 488 | static int tracepoint_count; |
1042e4c0 | 489 | |
6149aea9 PA |
490 | static struct cmd_list_element *breakpoint_set_cmdlist; |
491 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
9291a0cd | 492 | struct cmd_list_element *save_cmdlist; |
6149aea9 | 493 | |
468d015d JJ |
494 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
495 | static int | |
496 | breakpoint_enabled (struct breakpoint *b) | |
497 | { | |
0d381245 | 498 | return (b->enable_state == bp_enabled); |
468d015d JJ |
499 | } |
500 | ||
c906108c SS |
501 | /* Set breakpoint count to NUM. */ |
502 | ||
95a42b64 | 503 | static void |
fba45db2 | 504 | set_breakpoint_count (int num) |
c906108c | 505 | { |
86b17b60 | 506 | prev_breakpoint_count = breakpoint_count; |
c906108c | 507 | breakpoint_count = num; |
4fa62494 | 508 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
509 | } |
510 | ||
86b17b60 PA |
511 | /* Used by `start_rbreak_breakpoints' below, to record the current |
512 | breakpoint count before "rbreak" creates any breakpoint. */ | |
513 | static int rbreak_start_breakpoint_count; | |
514 | ||
95a42b64 TT |
515 | /* Called at the start an "rbreak" command to record the first |
516 | breakpoint made. */ | |
86b17b60 | 517 | |
95a42b64 TT |
518 | void |
519 | start_rbreak_breakpoints (void) | |
520 | { | |
86b17b60 | 521 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
522 | } |
523 | ||
524 | /* Called at the end of an "rbreak" command to record the last | |
525 | breakpoint made. */ | |
86b17b60 | 526 | |
95a42b64 TT |
527 | void |
528 | end_rbreak_breakpoints (void) | |
529 | { | |
86b17b60 | 530 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
531 | } |
532 | ||
4a64f543 | 533 | /* Used in run_command to zero the hit count when a new run starts. */ |
c906108c SS |
534 | |
535 | void | |
fba45db2 | 536 | clear_breakpoint_hit_counts (void) |
c906108c SS |
537 | { |
538 | struct breakpoint *b; | |
539 | ||
540 | ALL_BREAKPOINTS (b) | |
541 | b->hit_count = 0; | |
542 | } | |
543 | ||
9add0f1b TT |
544 | /* Allocate a new counted_command_line with reference count of 1. |
545 | The new structure owns COMMANDS. */ | |
546 | ||
547 | static struct counted_command_line * | |
548 | alloc_counted_command_line (struct command_line *commands) | |
549 | { | |
550 | struct counted_command_line *result | |
551 | = xmalloc (sizeof (struct counted_command_line)); | |
cc59ec59 | 552 | |
9add0f1b TT |
553 | result->refc = 1; |
554 | result->commands = commands; | |
555 | return result; | |
556 | } | |
557 | ||
558 | /* Increment reference count. This does nothing if CMD is NULL. */ | |
559 | ||
560 | static void | |
561 | incref_counted_command_line (struct counted_command_line *cmd) | |
562 | { | |
563 | if (cmd) | |
564 | ++cmd->refc; | |
565 | } | |
566 | ||
567 | /* Decrement reference count. If the reference count reaches 0, | |
568 | destroy the counted_command_line. Sets *CMDP to NULL. This does | |
569 | nothing if *CMDP is NULL. */ | |
570 | ||
571 | static void | |
572 | decref_counted_command_line (struct counted_command_line **cmdp) | |
573 | { | |
574 | if (*cmdp) | |
575 | { | |
576 | if (--(*cmdp)->refc == 0) | |
577 | { | |
578 | free_command_lines (&(*cmdp)->commands); | |
579 | xfree (*cmdp); | |
580 | } | |
581 | *cmdp = NULL; | |
582 | } | |
583 | } | |
584 | ||
585 | /* A cleanup function that calls decref_counted_command_line. */ | |
586 | ||
587 | static void | |
588 | do_cleanup_counted_command_line (void *arg) | |
589 | { | |
590 | decref_counted_command_line (arg); | |
591 | } | |
592 | ||
593 | /* Create a cleanup that calls decref_counted_command_line on the | |
594 | argument. */ | |
595 | ||
596 | static struct cleanup * | |
597 | make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp) | |
598 | { | |
599 | return make_cleanup (do_cleanup_counted_command_line, cmdp); | |
600 | } | |
601 | ||
c906108c | 602 | \f |
48cb2d85 VP |
603 | /* Return the breakpoint with the specified number, or NULL |
604 | if the number does not refer to an existing breakpoint. */ | |
605 | ||
606 | struct breakpoint * | |
607 | get_breakpoint (int num) | |
608 | { | |
609 | struct breakpoint *b; | |
610 | ||
611 | ALL_BREAKPOINTS (b) | |
612 | if (b->number == num) | |
613 | return b; | |
614 | ||
615 | return NULL; | |
616 | } | |
5c44784c | 617 | |
c906108c | 618 | \f |
adc36818 PM |
619 | |
620 | void | |
621 | set_breakpoint_condition (struct breakpoint *b, char *exp, | |
622 | int from_tty) | |
623 | { | |
3a5c3e22 PA |
624 | xfree (b->cond_string); |
625 | b->cond_string = NULL; | |
adc36818 | 626 | |
3a5c3e22 | 627 | if (is_watchpoint (b)) |
adc36818 | 628 | { |
3a5c3e22 PA |
629 | struct watchpoint *w = (struct watchpoint *) b; |
630 | ||
631 | xfree (w->cond_exp); | |
632 | w->cond_exp = NULL; | |
633 | } | |
634 | else | |
635 | { | |
636 | struct bp_location *loc; | |
637 | ||
638 | for (loc = b->loc; loc; loc = loc->next) | |
639 | { | |
640 | xfree (loc->cond); | |
641 | loc->cond = NULL; | |
642 | } | |
adc36818 | 643 | } |
adc36818 PM |
644 | |
645 | if (*exp == 0) | |
646 | { | |
647 | if (from_tty) | |
648 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
649 | } | |
650 | else | |
651 | { | |
652 | char *arg = exp; | |
cc59ec59 | 653 | |
adc36818 PM |
654 | /* I don't know if it matters whether this is the string the user |
655 | typed in or the decompiled expression. */ | |
656 | b->cond_string = xstrdup (arg); | |
657 | b->condition_not_parsed = 0; | |
658 | ||
659 | if (is_watchpoint (b)) | |
660 | { | |
3a5c3e22 PA |
661 | struct watchpoint *w = (struct watchpoint *) b; |
662 | ||
adc36818 PM |
663 | innermost_block = NULL; |
664 | arg = exp; | |
3a5c3e22 | 665 | w->cond_exp = parse_exp_1 (&arg, 0, 0); |
adc36818 PM |
666 | if (*arg) |
667 | error (_("Junk at end of expression")); | |
3a5c3e22 | 668 | w->cond_exp_valid_block = innermost_block; |
adc36818 PM |
669 | } |
670 | else | |
671 | { | |
3a5c3e22 PA |
672 | struct bp_location *loc; |
673 | ||
adc36818 PM |
674 | for (loc = b->loc; loc; loc = loc->next) |
675 | { | |
676 | arg = exp; | |
677 | loc->cond = | |
678 | parse_exp_1 (&arg, block_for_pc (loc->address), 0); | |
679 | if (*arg) | |
680 | error (_("Junk at end of expression")); | |
681 | } | |
682 | } | |
683 | } | |
684 | breakpoints_changed (); | |
8d3788bd | 685 | observer_notify_breakpoint_modified (b); |
adc36818 PM |
686 | } |
687 | ||
c906108c SS |
688 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
689 | ||
690 | static void | |
fba45db2 | 691 | condition_command (char *arg, int from_tty) |
c906108c | 692 | { |
52f0bd74 | 693 | struct breakpoint *b; |
c906108c | 694 | char *p; |
52f0bd74 | 695 | int bnum; |
c906108c SS |
696 | |
697 | if (arg == 0) | |
e2e0b3e5 | 698 | error_no_arg (_("breakpoint number")); |
c906108c SS |
699 | |
700 | p = arg; | |
701 | bnum = get_number (&p); | |
5c44784c | 702 | if (bnum == 0) |
8a3fe4f8 | 703 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
704 | |
705 | ALL_BREAKPOINTS (b) | |
706 | if (b->number == bnum) | |
2f069f6f | 707 | { |
7371cf6d PM |
708 | /* Check if this breakpoint has a Python object assigned to |
709 | it, and if it has a definition of the "stop" | |
710 | method. This method and conditions entered into GDB from | |
711 | the CLI are mutually exclusive. */ | |
712 | if (b->py_bp_object | |
713 | && gdbpy_breakpoint_has_py_cond (b->py_bp_object)) | |
714 | error (_("Cannot set a condition where a Python 'stop' " | |
715 | "method has been defined in the breakpoint.")); | |
2566ad2d | 716 | set_breakpoint_condition (b, p, from_tty); |
2f069f6f JB |
717 | return; |
718 | } | |
c906108c | 719 | |
8a3fe4f8 | 720 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
721 | } |
722 | ||
a7bdde9e VP |
723 | /* Check that COMMAND do not contain commands that are suitable |
724 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
725 | Throw if any such commands is found. */ |
726 | ||
a7bdde9e VP |
727 | static void |
728 | check_no_tracepoint_commands (struct command_line *commands) | |
729 | { | |
730 | struct command_line *c; | |
cc59ec59 | 731 | |
a7bdde9e VP |
732 | for (c = commands; c; c = c->next) |
733 | { | |
734 | int i; | |
735 | ||
736 | if (c->control_type == while_stepping_control) | |
3e43a32a MS |
737 | error (_("The 'while-stepping' command can " |
738 | "only be used for tracepoints")); | |
a7bdde9e VP |
739 | |
740 | for (i = 0; i < c->body_count; ++i) | |
741 | check_no_tracepoint_commands ((c->body_list)[i]); | |
742 | ||
743 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 744 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
745 | command directly. */ |
746 | if (strstr (c->line, "collect ") == c->line) | |
747 | error (_("The 'collect' command can only be used for tracepoints")); | |
748 | ||
51661e93 VP |
749 | if (strstr (c->line, "teval ") == c->line) |
750 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
751 | } |
752 | } | |
753 | ||
d77f58be SS |
754 | /* Encapsulate tests for different types of tracepoints. */ |
755 | ||
d9b3f62e PA |
756 | static int |
757 | is_tracepoint_type (enum bptype type) | |
758 | { | |
759 | return (type == bp_tracepoint | |
760 | || type == bp_fast_tracepoint | |
761 | || type == bp_static_tracepoint); | |
762 | } | |
763 | ||
a7bdde9e | 764 | int |
d77f58be | 765 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 766 | { |
d9b3f62e | 767 | return is_tracepoint_type (b->type); |
a7bdde9e | 768 | } |
d9b3f62e | 769 | |
e5dd4106 | 770 | /* A helper function that validates that COMMANDS are valid for a |
95a42b64 TT |
771 | breakpoint. This function will throw an exception if a problem is |
772 | found. */ | |
48cb2d85 | 773 | |
95a42b64 TT |
774 | static void |
775 | validate_commands_for_breakpoint (struct breakpoint *b, | |
776 | struct command_line *commands) | |
48cb2d85 | 777 | { |
d77f58be | 778 | if (is_tracepoint (b)) |
a7bdde9e | 779 | { |
4a64f543 MS |
780 | /* We need to verify that each top-level element of commands is |
781 | valid for tracepoints, that there's at most one | |
782 | while-stepping element, and that while-stepping's body has | |
783 | valid tracing commands excluding nested while-stepping. */ | |
a7bdde9e VP |
784 | struct command_line *c; |
785 | struct command_line *while_stepping = 0; | |
786 | for (c = commands; c; c = c->next) | |
787 | { | |
a7bdde9e VP |
788 | if (c->control_type == while_stepping_control) |
789 | { | |
790 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
791 | error (_("The 'while-stepping' command " |
792 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 793 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
794 | error (_("The 'while-stepping' command " |
795 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
796 | |
797 | if (while_stepping) | |
3e43a32a MS |
798 | error (_("The 'while-stepping' command " |
799 | "can be used only once")); | |
a7bdde9e VP |
800 | else |
801 | while_stepping = c; | |
802 | } | |
803 | } | |
804 | if (while_stepping) | |
805 | { | |
806 | struct command_line *c2; | |
807 | ||
808 | gdb_assert (while_stepping->body_count == 1); | |
809 | c2 = while_stepping->body_list[0]; | |
810 | for (; c2; c2 = c2->next) | |
811 | { | |
a7bdde9e VP |
812 | if (c2->control_type == while_stepping_control) |
813 | error (_("The 'while-stepping' command cannot be nested")); | |
814 | } | |
815 | } | |
816 | } | |
817 | else | |
818 | { | |
819 | check_no_tracepoint_commands (commands); | |
820 | } | |
95a42b64 TT |
821 | } |
822 | ||
0fb4aa4b PA |
823 | /* Return a vector of all the static tracepoints set at ADDR. The |
824 | caller is responsible for releasing the vector. */ | |
825 | ||
826 | VEC(breakpoint_p) * | |
827 | static_tracepoints_here (CORE_ADDR addr) | |
828 | { | |
829 | struct breakpoint *b; | |
830 | VEC(breakpoint_p) *found = 0; | |
831 | struct bp_location *loc; | |
832 | ||
833 | ALL_BREAKPOINTS (b) | |
834 | if (b->type == bp_static_tracepoint) | |
835 | { | |
836 | for (loc = b->loc; loc; loc = loc->next) | |
837 | if (loc->address == addr) | |
838 | VEC_safe_push(breakpoint_p, found, b); | |
839 | } | |
840 | ||
841 | return found; | |
842 | } | |
843 | ||
95a42b64 | 844 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 845 | validate that only allowed commands are included. */ |
95a42b64 TT |
846 | |
847 | void | |
4a64f543 MS |
848 | breakpoint_set_commands (struct breakpoint *b, |
849 | struct command_line *commands) | |
95a42b64 TT |
850 | { |
851 | validate_commands_for_breakpoint (b, commands); | |
a7bdde9e | 852 | |
9add0f1b TT |
853 | decref_counted_command_line (&b->commands); |
854 | b->commands = alloc_counted_command_line (commands); | |
48cb2d85 | 855 | breakpoints_changed (); |
8d3788bd | 856 | observer_notify_breakpoint_modified (b); |
48cb2d85 VP |
857 | } |
858 | ||
45a43567 TT |
859 | /* Set the internal `silent' flag on the breakpoint. Note that this |
860 | is not the same as the "silent" that may appear in the breakpoint's | |
861 | commands. */ | |
862 | ||
863 | void | |
864 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
865 | { | |
866 | int old_silent = b->silent; | |
867 | ||
868 | b->silent = silent; | |
869 | if (old_silent != silent) | |
8d3788bd | 870 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
871 | } |
872 | ||
873 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
874 | breakpoint work for any thread. */ | |
875 | ||
876 | void | |
877 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
878 | { | |
879 | int old_thread = b->thread; | |
880 | ||
881 | b->thread = thread; | |
882 | if (old_thread != thread) | |
8d3788bd | 883 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
884 | } |
885 | ||
886 | /* Set the task for this breakpoint. If TASK is 0, make the | |
887 | breakpoint work for any task. */ | |
888 | ||
889 | void | |
890 | breakpoint_set_task (struct breakpoint *b, int task) | |
891 | { | |
892 | int old_task = b->task; | |
893 | ||
894 | b->task = task; | |
895 | if (old_task != task) | |
8d3788bd | 896 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
897 | } |
898 | ||
95a42b64 TT |
899 | void |
900 | check_tracepoint_command (char *line, void *closure) | |
a7bdde9e VP |
901 | { |
902 | struct breakpoint *b = closure; | |
cc59ec59 | 903 | |
a7bdde9e VP |
904 | validate_actionline (&line, b); |
905 | } | |
906 | ||
95a42b64 TT |
907 | /* A structure used to pass information through |
908 | map_breakpoint_numbers. */ | |
909 | ||
910 | struct commands_info | |
911 | { | |
912 | /* True if the command was typed at a tty. */ | |
913 | int from_tty; | |
86b17b60 PA |
914 | |
915 | /* The breakpoint range spec. */ | |
916 | char *arg; | |
917 | ||
95a42b64 TT |
918 | /* Non-NULL if the body of the commands are being read from this |
919 | already-parsed command. */ | |
920 | struct command_line *control; | |
86b17b60 | 921 | |
95a42b64 TT |
922 | /* The command lines read from the user, or NULL if they have not |
923 | yet been read. */ | |
924 | struct counted_command_line *cmd; | |
925 | }; | |
926 | ||
927 | /* A callback for map_breakpoint_numbers that sets the commands for | |
928 | commands_command. */ | |
929 | ||
c906108c | 930 | static void |
95a42b64 | 931 | do_map_commands_command (struct breakpoint *b, void *data) |
c906108c | 932 | { |
95a42b64 | 933 | struct commands_info *info = data; |
c906108c | 934 | |
95a42b64 TT |
935 | if (info->cmd == NULL) |
936 | { | |
937 | struct command_line *l; | |
5c44784c | 938 | |
95a42b64 TT |
939 | if (info->control != NULL) |
940 | l = copy_command_lines (info->control->body_list[0]); | |
941 | else | |
86b17b60 PA |
942 | { |
943 | struct cleanup *old_chain; | |
944 | char *str; | |
c5aa993b | 945 | |
3e43a32a MS |
946 | str = xstrprintf (_("Type commands for breakpoint(s) " |
947 | "%s, one per line."), | |
86b17b60 PA |
948 | info->arg); |
949 | ||
950 | old_chain = make_cleanup (xfree, str); | |
951 | ||
952 | l = read_command_lines (str, | |
953 | info->from_tty, 1, | |
d77f58be | 954 | (is_tracepoint (b) |
86b17b60 PA |
955 | ? check_tracepoint_command : 0), |
956 | b); | |
957 | ||
958 | do_cleanups (old_chain); | |
959 | } | |
a7bdde9e | 960 | |
95a42b64 TT |
961 | info->cmd = alloc_counted_command_line (l); |
962 | } | |
963 | ||
964 | /* If a breakpoint was on the list more than once, we don't need to | |
965 | do anything. */ | |
966 | if (b->commands != info->cmd) | |
967 | { | |
968 | validate_commands_for_breakpoint (b, info->cmd->commands); | |
969 | incref_counted_command_line (info->cmd); | |
970 | decref_counted_command_line (&b->commands); | |
971 | b->commands = info->cmd; | |
972 | breakpoints_changed (); | |
8d3788bd | 973 | observer_notify_breakpoint_modified (b); |
c5aa993b | 974 | } |
95a42b64 TT |
975 | } |
976 | ||
977 | static void | |
4a64f543 MS |
978 | commands_command_1 (char *arg, int from_tty, |
979 | struct command_line *control) | |
95a42b64 TT |
980 | { |
981 | struct cleanup *cleanups; | |
982 | struct commands_info info; | |
983 | ||
984 | info.from_tty = from_tty; | |
985 | info.control = control; | |
986 | info.cmd = NULL; | |
987 | /* If we read command lines from the user, then `info' will hold an | |
988 | extra reference to the commands that we must clean up. */ | |
989 | cleanups = make_cleanup_decref_counted_command_line (&info.cmd); | |
990 | ||
991 | if (arg == NULL || !*arg) | |
992 | { | |
86b17b60 | 993 | if (breakpoint_count - prev_breakpoint_count > 1) |
4a64f543 MS |
994 | arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1, |
995 | breakpoint_count); | |
95a42b64 TT |
996 | else if (breakpoint_count > 0) |
997 | arg = xstrprintf ("%d", breakpoint_count); | |
86b17b60 PA |
998 | else |
999 | { | |
1000 | /* So that we don't try to free the incoming non-NULL | |
1001 | argument in the cleanup below. Mapping breakpoint | |
1002 | numbers will fail in this case. */ | |
1003 | arg = NULL; | |
1004 | } | |
95a42b64 | 1005 | } |
9766ced4 SS |
1006 | else |
1007 | /* The command loop has some static state, so we need to preserve | |
1008 | our argument. */ | |
1009 | arg = xstrdup (arg); | |
86b17b60 PA |
1010 | |
1011 | if (arg != NULL) | |
1012 | make_cleanup (xfree, arg); | |
1013 | ||
1014 | info.arg = arg; | |
95a42b64 TT |
1015 | |
1016 | map_breakpoint_numbers (arg, do_map_commands_command, &info); | |
1017 | ||
1018 | if (info.cmd == NULL) | |
1019 | error (_("No breakpoints specified.")); | |
1020 | ||
1021 | do_cleanups (cleanups); | |
1022 | } | |
1023 | ||
1024 | static void | |
1025 | commands_command (char *arg, int from_tty) | |
1026 | { | |
1027 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1028 | } |
40c03ae8 EZ |
1029 | |
1030 | /* Like commands_command, but instead of reading the commands from | |
1031 | input stream, takes them from an already parsed command structure. | |
1032 | ||
1033 | This is used by cli-script.c to DTRT with breakpoint commands | |
1034 | that are part of if and while bodies. */ | |
1035 | enum command_control_type | |
1036 | commands_from_control_command (char *arg, struct command_line *cmd) | |
1037 | { | |
95a42b64 TT |
1038 | commands_command_1 (arg, 0, cmd); |
1039 | return simple_control; | |
40c03ae8 | 1040 | } |
876fa593 JK |
1041 | |
1042 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1043 | ||
1044 | static int | |
1045 | bp_location_has_shadow (struct bp_location *bl) | |
1046 | { | |
1047 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1048 | return 0; | |
1049 | if (!bl->inserted) | |
1050 | return 0; | |
1051 | if (bl->target_info.shadow_len == 0) | |
e5dd4106 | 1052 | /* BL isn't valid, or doesn't shadow memory. */ |
876fa593 JK |
1053 | return 0; |
1054 | return 1; | |
1055 | } | |
1056 | ||
8defab1a | 1057 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1058 | by replacing any memory breakpoints with their shadowed contents. |
1059 | ||
1060 | The range of shadowed area by each bp_location is: | |
35df4500 TJB |
1061 | bl->address - bp_location_placed_address_before_address_max |
1062 | up to bl->address + bp_location_shadow_len_after_address_max | |
876fa593 JK |
1063 | The range we were requested to resolve shadows for is: |
1064 | memaddr ... memaddr + len | |
1065 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 TJB |
1066 | memaddr + len <= (bl->address |
1067 | - bp_location_placed_address_before_address_max) | |
876fa593 | 1068 | and: |
35df4500 | 1069 | bl->address + bp_location_shadow_len_after_address_max <= memaddr */ |
c906108c | 1070 | |
8defab1a | 1071 | void |
f0ba3972 PA |
1072 | breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, |
1073 | const gdb_byte *writebuf_org, | |
1074 | ULONGEST memaddr, LONGEST len) | |
c906108c | 1075 | { |
4a64f543 MS |
1076 | /* Left boundary, right boundary and median element of our binary |
1077 | search. */ | |
876fa593 JK |
1078 | unsigned bc_l, bc_r, bc; |
1079 | ||
4a64f543 MS |
1080 | /* Find BC_L which is a leftmost element which may affect BUF |
1081 | content. It is safe to report lower value but a failure to | |
1082 | report higher one. */ | |
876fa593 JK |
1083 | |
1084 | bc_l = 0; | |
1085 | bc_r = bp_location_count; | |
1086 | while (bc_l + 1 < bc_r) | |
1087 | { | |
35df4500 | 1088 | struct bp_location *bl; |
876fa593 JK |
1089 | |
1090 | bc = (bc_l + bc_r) / 2; | |
35df4500 | 1091 | bl = bp_location[bc]; |
876fa593 | 1092 | |
4a64f543 MS |
1093 | /* Check first BL->ADDRESS will not overflow due to the added |
1094 | constant. Then advance the left boundary only if we are sure | |
1095 | the BC element can in no way affect the BUF content (MEMADDR | |
1096 | to MEMADDR + LEN range). | |
876fa593 | 1097 | |
4a64f543 MS |
1098 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
1099 | offset so that we cannot miss a breakpoint with its shadow | |
1100 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1101 | |
35df4500 TJB |
1102 | if ((bl->address + bp_location_shadow_len_after_address_max |
1103 | >= bl->address) | |
1104 | && (bl->address + bp_location_shadow_len_after_address_max | |
1105 | <= memaddr)) | |
876fa593 JK |
1106 | bc_l = bc; |
1107 | else | |
1108 | bc_r = bc; | |
1109 | } | |
1110 | ||
128070bb PA |
1111 | /* Due to the binary search above, we need to make sure we pick the |
1112 | first location that's at BC_L's address. E.g., if there are | |
1113 | multiple locations at the same address, BC_L may end up pointing | |
1114 | at a duplicate location, and miss the "master"/"inserted" | |
1115 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1116 | B: | |
1117 | ||
1118 | L1@A, L2@A, L3@B, ... | |
1119 | ||
1120 | BC_L could end up pointing at location L2, while the "master" | |
1121 | location could be L1. Since the `loc->inserted' flag is only set | |
1122 | on "master" locations, we'd forget to restore the shadow of L1 | |
1123 | and L2. */ | |
1124 | while (bc_l > 0 | |
1125 | && bp_location[bc_l]->address == bp_location[bc_l - 1]->address) | |
1126 | bc_l--; | |
1127 | ||
876fa593 JK |
1128 | /* Now do full processing of the found relevant range of elements. */ |
1129 | ||
1130 | for (bc = bc_l; bc < bp_location_count; bc++) | |
c5aa993b | 1131 | { |
35df4500 | 1132 | struct bp_location *bl = bp_location[bc]; |
876fa593 JK |
1133 | CORE_ADDR bp_addr = 0; |
1134 | int bp_size = 0; | |
1135 | int bptoffset = 0; | |
1136 | ||
35df4500 TJB |
1137 | /* bp_location array has BL->OWNER always non-NULL. */ |
1138 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1139 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1140 | bl->owner->number); |
ffce0d52 | 1141 | |
e5dd4106 | 1142 | /* Performance optimization: any further element can no longer affect BUF |
876fa593 JK |
1143 | content. */ |
1144 | ||
35df4500 TJB |
1145 | if (bl->address >= bp_location_placed_address_before_address_max |
1146 | && memaddr + len <= (bl->address | |
1147 | - bp_location_placed_address_before_address_max)) | |
876fa593 JK |
1148 | break; |
1149 | ||
35df4500 | 1150 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1151 | continue; |
35df4500 | 1152 | if (!breakpoint_address_match (bl->target_info.placed_address_space, 0, |
6c95b8df PA |
1153 | current_program_space->aspace, 0)) |
1154 | continue; | |
1155 | ||
c5aa993b JM |
1156 | /* Addresses and length of the part of the breakpoint that |
1157 | we need to copy. */ | |
35df4500 TJB |
1158 | bp_addr = bl->target_info.placed_address; |
1159 | bp_size = bl->target_info.shadow_len; | |
8defab1a | 1160 | |
c5aa993b JM |
1161 | if (bp_addr + bp_size <= memaddr) |
1162 | /* The breakpoint is entirely before the chunk of memory we | |
1163 | are reading. */ | |
1164 | continue; | |
8defab1a | 1165 | |
c5aa993b JM |
1166 | if (bp_addr >= memaddr + len) |
1167 | /* The breakpoint is entirely after the chunk of memory we are | |
4a64f543 | 1168 | reading. */ |
c5aa993b | 1169 | continue; |
c5aa993b | 1170 | |
8defab1a DJ |
1171 | /* Offset within shadow_contents. */ |
1172 | if (bp_addr < memaddr) | |
1173 | { | |
1174 | /* Only copy the second part of the breakpoint. */ | |
1175 | bp_size -= memaddr - bp_addr; | |
1176 | bptoffset = memaddr - bp_addr; | |
1177 | bp_addr = memaddr; | |
1178 | } | |
c5aa993b | 1179 | |
8defab1a DJ |
1180 | if (bp_addr + bp_size > memaddr + len) |
1181 | { | |
1182 | /* Only copy the first part of the breakpoint. */ | |
1183 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1184 | } | |
c5aa993b | 1185 | |
f0ba3972 PA |
1186 | if (readbuf != NULL) |
1187 | { | |
1188 | /* Update the read buffer with this inserted breakpoint's | |
1189 | shadow. */ | |
1190 | memcpy (readbuf + bp_addr - memaddr, | |
1191 | bl->target_info.shadow_contents + bptoffset, bp_size); | |
1192 | } | |
1193 | else | |
1194 | { | |
1195 | struct gdbarch *gdbarch = bl->gdbarch; | |
1196 | const unsigned char *bp; | |
1197 | CORE_ADDR placed_address = bl->target_info.placed_address; | |
1198 | unsigned placed_size = bl->target_info.placed_size; | |
1199 | ||
1200 | /* Update the shadow with what we want to write to memory. */ | |
1201 | memcpy (bl->target_info.shadow_contents + bptoffset, | |
1202 | writebuf_org + bp_addr - memaddr, bp_size); | |
1203 | ||
1204 | /* Determine appropriate breakpoint contents and size for this | |
1205 | address. */ | |
1206 | bp = gdbarch_breakpoint_from_pc (gdbarch, &placed_address, &placed_size); | |
1207 | ||
1208 | /* Update the final write buffer with this inserted | |
1209 | breakpoint's INSN. */ | |
1210 | memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size); | |
1211 | } | |
c5aa993b | 1212 | } |
c906108c | 1213 | } |
c906108c | 1214 | \f |
c5aa993b | 1215 | |
60e1c644 PA |
1216 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1217 | ||
a5606eee | 1218 | static int |
d77f58be | 1219 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1220 | { |
1221 | return (bpt->type == bp_hardware_watchpoint | |
1222 | || bpt->type == bp_read_watchpoint | |
1223 | || bpt->type == bp_access_watchpoint); | |
1224 | } | |
7270d8f2 | 1225 | |
60e1c644 PA |
1226 | /* Return true if BPT is of any watchpoint kind, hardware or |
1227 | software. */ | |
1228 | ||
3a5c3e22 | 1229 | int |
d77f58be | 1230 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1231 | { |
1232 | return (is_hardware_watchpoint (bpt) | |
1233 | || bpt->type == bp_watchpoint); | |
1234 | } | |
1235 | ||
3a5c3e22 PA |
1236 | /* Returns true if the current thread and its running state are safe |
1237 | to evaluate or update watchpoint B. Watchpoints on local | |
1238 | expressions need to be evaluated in the context of the thread that | |
1239 | was current when the watchpoint was created, and, that thread needs | |
1240 | to be stopped to be able to select the correct frame context. | |
1241 | Watchpoints on global expressions can be evaluated on any thread, | |
1242 | and in any state. It is presently left to the target allowing | |
1243 | memory accesses when threads are running. */ | |
f6bc2008 PA |
1244 | |
1245 | static int | |
3a5c3e22 | 1246 | watchpoint_in_thread_scope (struct watchpoint *b) |
f6bc2008 | 1247 | { |
d0d8b0c6 JK |
1248 | return (b->base.pspace == current_program_space |
1249 | && (ptid_equal (b->watchpoint_thread, null_ptid) | |
1250 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1251 | && !is_executing (inferior_ptid)))); | |
f6bc2008 PA |
1252 | } |
1253 | ||
d0fb5eae JK |
1254 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
1255 | associated bp_watchpoint_scope breakpoint. */ | |
1256 | ||
1257 | static void | |
3a5c3e22 | 1258 | watchpoint_del_at_next_stop (struct watchpoint *w) |
d0fb5eae | 1259 | { |
3a5c3e22 | 1260 | struct breakpoint *b = &w->base; |
d0fb5eae JK |
1261 | |
1262 | if (b->related_breakpoint != b) | |
1263 | { | |
1264 | gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope); | |
1265 | gdb_assert (b->related_breakpoint->related_breakpoint == b); | |
1266 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1267 | b->related_breakpoint->related_breakpoint = b->related_breakpoint; | |
1268 | b->related_breakpoint = b; | |
1269 | } | |
1270 | b->disposition = disp_del_at_next_stop; | |
1271 | } | |
1272 | ||
567e1b4e JB |
1273 | /* Assuming that B is a watchpoint: |
1274 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1275 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1276 | - Evaluate the condition if there is one, and store the result |
1277 | in b->loc->cond. | |
a5606eee VP |
1278 | - Update the list of values that must be watched in B->loc. |
1279 | ||
4a64f543 MS |
1280 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1281 | nothing. If this is local watchpoint that is out of scope, delete | |
1282 | it. | |
1283 | ||
1284 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1285 | removed + inserted on each stop here. Normal breakpoints must | |
1286 | never be removed because they might be missed by a running thread | |
1287 | when debugging in non-stop mode. On the other hand, hardware | |
1288 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1289 | to each LWP since they are stored in each LWP's hardware debug | |
1290 | registers. Therefore, such LWP must be stopped first in order to | |
1291 | be able to modify its hardware watchpoints. | |
1292 | ||
1293 | Hardware watchpoints must be reset exactly once after being | |
1294 | presented to the user. It cannot be done sooner, because it would | |
1295 | reset the data used to present the watchpoint hit to the user. And | |
1296 | it must not be done later because it could display the same single | |
1297 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1298 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1299 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1300 | not user-visible - its hit is suppressed if the memory content has | |
1301 | not changed. | |
1302 | ||
1303 | The following constraints influence the location where we can reset | |
1304 | hardware watchpoints: | |
1305 | ||
1306 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1307 | called several times when GDB stops. | |
1308 | ||
1309 | [linux] | |
1310 | * Multiple hardware watchpoints can be hit at the same time, | |
1311 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1312 | hit at a time as the reason for stopping, and all the other hits | |
1313 | are presented later, one after the other, each time the user | |
1314 | requests the execution to be resumed. Execution is not resumed | |
1315 | for the threads still having pending hit event stored in | |
1316 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1317 | the inferior on the first stop the thread hit event is kept being | |
1318 | reported from its cached value by linux_nat_stopped_data_address | |
1319 | until the real thread resume happens after the watchpoint gets | |
1320 | presented and thus its LWP_INFO->STATUS gets reset. | |
1321 | ||
1322 | Therefore the hardware watchpoint hit can get safely reset on the | |
1323 | watchpoint removal from inferior. */ | |
a79d3c27 | 1324 | |
b40ce68a | 1325 | static void |
3a5c3e22 | 1326 | update_watchpoint (struct watchpoint *b, int reparse) |
7270d8f2 | 1327 | { |
a5606eee | 1328 | int within_current_scope; |
a5606eee | 1329 | struct frame_id saved_frame_id; |
66076460 | 1330 | int frame_saved; |
a5606eee | 1331 | |
f6bc2008 PA |
1332 | /* If this is a local watchpoint, we only want to check if the |
1333 | watchpoint frame is in scope if the current thread is the thread | |
1334 | that was used to create the watchpoint. */ | |
1335 | if (!watchpoint_in_thread_scope (b)) | |
1336 | return; | |
1337 | ||
3a5c3e22 | 1338 | if (b->base.disposition == disp_del_at_next_stop) |
a5606eee VP |
1339 | return; |
1340 | ||
66076460 | 1341 | frame_saved = 0; |
a5606eee VP |
1342 | |
1343 | /* Determine if the watchpoint is within scope. */ | |
1344 | if (b->exp_valid_block == NULL) | |
1345 | within_current_scope = 1; | |
1346 | else | |
1347 | { | |
b5db5dfc UW |
1348 | struct frame_info *fi = get_current_frame (); |
1349 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1350 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1351 | ||
1352 | /* If we're in a function epilogue, unwinding may not work | |
1353 | properly, so do not attempt to recreate locations at this | |
1354 | point. See similar comments in watchpoint_check. */ | |
1355 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) | |
1356 | return; | |
66076460 DJ |
1357 | |
1358 | /* Save the current frame's ID so we can restore it after | |
1359 | evaluating the watchpoint expression on its own frame. */ | |
1360 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1361 | took a frame parameter, so that we didn't have to change the | |
1362 | selected frame. */ | |
1363 | frame_saved = 1; | |
1364 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1365 | ||
a5606eee VP |
1366 | fi = frame_find_by_id (b->watchpoint_frame); |
1367 | within_current_scope = (fi != NULL); | |
1368 | if (within_current_scope) | |
1369 | select_frame (fi); | |
1370 | } | |
1371 | ||
b5db5dfc UW |
1372 | /* We don't free locations. They are stored in the bp_location array |
1373 | and update_global_location_list will eventually delete them and | |
1374 | remove breakpoints if needed. */ | |
3a5c3e22 | 1375 | b->base.loc = NULL; |
b5db5dfc | 1376 | |
a5606eee VP |
1377 | if (within_current_scope && reparse) |
1378 | { | |
1379 | char *s; | |
d63d0675 | 1380 | |
a5606eee VP |
1381 | if (b->exp) |
1382 | { | |
1383 | xfree (b->exp); | |
1384 | b->exp = NULL; | |
1385 | } | |
d63d0675 | 1386 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
a5606eee VP |
1387 | b->exp = parse_exp_1 (&s, b->exp_valid_block, 0); |
1388 | /* If the meaning of expression itself changed, the old value is | |
1389 | no longer relevant. We don't want to report a watchpoint hit | |
1390 | to the user when the old value and the new value may actually | |
1391 | be completely different objects. */ | |
1392 | value_free (b->val); | |
fa4727a6 DJ |
1393 | b->val = NULL; |
1394 | b->val_valid = 0; | |
60e1c644 PA |
1395 | |
1396 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1397 | expression is stored in the breakpoint object, not in the | |
1398 | locations (re)created below. */ | |
3a5c3e22 | 1399 | if (b->base.cond_string != NULL) |
60e1c644 PA |
1400 | { |
1401 | if (b->cond_exp != NULL) | |
1402 | { | |
1403 | xfree (b->cond_exp); | |
1404 | b->cond_exp = NULL; | |
1405 | } | |
1406 | ||
3a5c3e22 | 1407 | s = b->base.cond_string; |
60e1c644 PA |
1408 | b->cond_exp = parse_exp_1 (&s, b->cond_exp_valid_block, 0); |
1409 | } | |
a5606eee | 1410 | } |
a5606eee VP |
1411 | |
1412 | /* If we failed to parse the expression, for example because | |
1413 | it refers to a global variable in a not-yet-loaded shared library, | |
1414 | don't try to insert watchpoint. We don't automatically delete | |
1415 | such watchpoint, though, since failure to parse expression | |
1416 | is different from out-of-scope watchpoint. */ | |
2d134ed3 PA |
1417 | if ( !target_has_execution) |
1418 | { | |
1419 | /* Without execution, memory can't change. No use to try and | |
1420 | set watchpoint locations. The watchpoint will be reset when | |
1421 | the target gains execution, through breakpoint_re_set. */ | |
1422 | } | |
1423 | else if (within_current_scope && b->exp) | |
a5606eee | 1424 | { |
0cf6dd15 | 1425 | int pc = 0; |
fa4727a6 | 1426 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1427 | struct program_space *frame_pspace; |
a5606eee | 1428 | |
0cf6dd15 | 1429 | fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain); |
a5606eee | 1430 | |
a5606eee VP |
1431 | /* Avoid setting b->val if it's already set. The meaning of |
1432 | b->val is 'the last value' user saw, and we should update | |
1433 | it only if we reported that last value to user. As it | |
9c06b0b4 TJB |
1434 | happens, the code that reports it updates b->val directly. |
1435 | We don't keep track of the memory value for masked | |
1436 | watchpoints. */ | |
3a5c3e22 | 1437 | if (!b->val_valid && !is_masked_watchpoint (&b->base)) |
fa4727a6 DJ |
1438 | { |
1439 | b->val = v; | |
1440 | b->val_valid = 1; | |
1441 | } | |
a5606eee | 1442 | |
2d134ed3 PA |
1443 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1444 | ||
a5606eee | 1445 | /* Look at each value on the value chain. */ |
9fa40276 | 1446 | for (v = val_chain; v; v = value_next (v)) |
a5606eee VP |
1447 | { |
1448 | /* If it's a memory location, and GDB actually needed | |
1449 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1450 | must watch it. If the first value returned is |
1451 | still lazy, that means an error occurred reading it; | |
1452 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1453 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1454 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1455 | { |
1456 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1457 | |
a5606eee VP |
1458 | /* We only watch structs and arrays if user asked |
1459 | for it explicitly, never if they just happen to | |
1460 | appear in the middle of some value chain. */ | |
fa4727a6 | 1461 | if (v == result |
a5606eee VP |
1462 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1463 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1464 | { | |
1465 | CORE_ADDR addr; | |
1466 | int len, type; | |
1467 | struct bp_location *loc, **tmp; | |
1468 | ||
42ae5230 | 1469 | addr = value_address (v); |
a5606eee VP |
1470 | len = TYPE_LENGTH (value_type (v)); |
1471 | type = hw_write; | |
3a5c3e22 | 1472 | if (b->base.type == bp_read_watchpoint) |
a5606eee | 1473 | type = hw_read; |
3a5c3e22 | 1474 | else if (b->base.type == bp_access_watchpoint) |
a5606eee | 1475 | type = hw_access; |
3a5c3e22 PA |
1476 | |
1477 | loc = allocate_bp_location (&b->base); | |
1478 | for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next)) | |
a5606eee VP |
1479 | ; |
1480 | *tmp = loc; | |
a6d9a66e | 1481 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1482 | |
1483 | loc->pspace = frame_pspace; | |
a5606eee VP |
1484 | loc->address = addr; |
1485 | loc->length = len; | |
1486 | loc->watchpoint_type = type; | |
1487 | } | |
1488 | } | |
9fa40276 TJB |
1489 | } |
1490 | ||
1491 | /* Change the type of breakpoint between hardware assisted or | |
1492 | an ordinary watchpoint depending on the hardware support | |
1493 | and free hardware slots. REPARSE is set when the inferior | |
1494 | is started. */ | |
a9634178 | 1495 | if (reparse) |
9fa40276 | 1496 | { |
e09342b5 | 1497 | int reg_cnt; |
9fa40276 TJB |
1498 | enum bp_loc_type loc_type; |
1499 | struct bp_location *bl; | |
a5606eee | 1500 | |
a9634178 | 1501 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
e09342b5 TJB |
1502 | |
1503 | if (reg_cnt) | |
9fa40276 TJB |
1504 | { |
1505 | int i, target_resources_ok, other_type_used; | |
a1398e0c | 1506 | enum bptype type; |
9fa40276 | 1507 | |
a9634178 TJB |
1508 | /* Use an exact watchpoint when there's only one memory region to be |
1509 | watched, and only one debug register is needed to watch it. */ | |
1510 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
1511 | ||
9fa40276 | 1512 | /* We need to determine how many resources are already |
e09342b5 TJB |
1513 | used for all other hardware watchpoints plus this one |
1514 | to see if we still have enough resources to also fit | |
a1398e0c PA |
1515 | this watchpoint in as well. */ |
1516 | ||
1517 | /* If this is a software watchpoint, we try to turn it | |
1518 | to a hardware one -- count resources as if B was of | |
1519 | hardware watchpoint type. */ | |
1520 | type = b->base.type; | |
1521 | if (type == bp_watchpoint) | |
1522 | type = bp_hardware_watchpoint; | |
1523 | ||
1524 | /* This watchpoint may or may not have been placed on | |
1525 | the list yet at this point (it won't be in the list | |
1526 | if we're trying to create it for the first time, | |
1527 | through watch_command), so always account for it | |
1528 | manually. */ | |
1529 | ||
1530 | /* Count resources used by all watchpoints except B. */ | |
1531 | i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used); | |
1532 | ||
1533 | /* Add in the resources needed for B. */ | |
1534 | i += hw_watchpoint_use_count (&b->base); | |
1535 | ||
1536 | target_resources_ok | |
1537 | = target_can_use_hardware_watchpoint (type, i, other_type_used); | |
e09342b5 | 1538 | if (target_resources_ok <= 0) |
a9634178 | 1539 | { |
3a5c3e22 | 1540 | int sw_mode = b->base.ops->works_in_software_mode (&b->base); |
9c06b0b4 TJB |
1541 | |
1542 | if (target_resources_ok == 0 && !sw_mode) | |
a9634178 TJB |
1543 | error (_("Target does not support this type of " |
1544 | "hardware watchpoint.")); | |
9c06b0b4 TJB |
1545 | else if (target_resources_ok < 0 && !sw_mode) |
1546 | error (_("There are not enough available hardware " | |
1547 | "resources for this watchpoint.")); | |
a1398e0c PA |
1548 | |
1549 | /* Downgrade to software watchpoint. */ | |
1550 | b->base.type = bp_watchpoint; | |
1551 | } | |
1552 | else | |
1553 | { | |
1554 | /* If this was a software watchpoint, we've just | |
1555 | found we have enough resources to turn it to a | |
1556 | hardware watchpoint. Otherwise, this is a | |
1557 | nop. */ | |
1558 | b->base.type = type; | |
a9634178 | 1559 | } |
9fa40276 | 1560 | } |
3a5c3e22 | 1561 | else if (!b->base.ops->works_in_software_mode (&b->base)) |
a9634178 TJB |
1562 | error (_("Expression cannot be implemented with " |
1563 | "read/access watchpoint.")); | |
9fa40276 | 1564 | else |
3a5c3e22 | 1565 | b->base.type = bp_watchpoint; |
9fa40276 | 1566 | |
3a5c3e22 | 1567 | loc_type = (b->base.type == bp_watchpoint? bp_loc_other |
9fa40276 | 1568 | : bp_loc_hardware_watchpoint); |
3a5c3e22 | 1569 | for (bl = b->base.loc; bl; bl = bl->next) |
9fa40276 TJB |
1570 | bl->loc_type = loc_type; |
1571 | } | |
1572 | ||
1573 | for (v = val_chain; v; v = next) | |
1574 | { | |
a5606eee VP |
1575 | next = value_next (v); |
1576 | if (v != b->val) | |
1577 | value_free (v); | |
1578 | } | |
1579 | ||
c7437ca6 PA |
1580 | /* If a software watchpoint is not watching any memory, then the |
1581 | above left it without any location set up. But, | |
1582 | bpstat_stop_status requires a location to be able to report | |
1583 | stops, so make sure there's at least a dummy one. */ | |
3a5c3e22 | 1584 | if (b->base.type == bp_watchpoint && b->base.loc == NULL) |
c7437ca6 | 1585 | { |
3a5c3e22 PA |
1586 | struct breakpoint *base = &b->base; |
1587 | base->loc = allocate_bp_location (base); | |
1588 | base->loc->pspace = frame_pspace; | |
1589 | base->loc->address = -1; | |
1590 | base->loc->length = -1; | |
1591 | base->loc->watchpoint_type = -1; | |
c7437ca6 | 1592 | } |
a5606eee VP |
1593 | } |
1594 | else if (!within_current_scope) | |
7270d8f2 | 1595 | { |
ac74f770 MS |
1596 | printf_filtered (_("\ |
1597 | Watchpoint %d deleted because the program has left the block\n\ | |
1598 | in which its expression is valid.\n"), | |
3a5c3e22 | 1599 | b->base.number); |
d0fb5eae | 1600 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 1601 | } |
a5606eee VP |
1602 | |
1603 | /* Restore the selected frame. */ | |
66076460 DJ |
1604 | if (frame_saved) |
1605 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
1606 | } |
1607 | ||
a5606eee | 1608 | |
74960c60 | 1609 | /* Returns 1 iff breakpoint location should be |
1e4d1764 YQ |
1610 | inserted in the inferior. We don't differentiate the type of BL's owner |
1611 | (breakpoint vs. tracepoint), although insert_location in tracepoint's | |
1612 | breakpoint_ops is not defined, because in insert_bp_location, | |
1613 | tracepoint's insert_location will not be called. */ | |
74960c60 | 1614 | static int |
35df4500 | 1615 | should_be_inserted (struct bp_location *bl) |
74960c60 | 1616 | { |
35df4500 | 1617 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
1618 | return 0; |
1619 | ||
35df4500 | 1620 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
1621 | return 0; |
1622 | ||
35df4500 | 1623 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
1624 | return 0; |
1625 | ||
f8eba3c6 TT |
1626 | if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup) |
1627 | return 0; | |
1628 | ||
56710373 PA |
1629 | /* This is set for example, when we're attached to the parent of a |
1630 | vfork, and have detached from the child. The child is running | |
1631 | free, and we expect it to do an exec or exit, at which point the | |
1632 | OS makes the parent schedulable again (and the target reports | |
1633 | that the vfork is done). Until the child is done with the shared | |
1634 | memory region, do not insert breakpoints in the parent, otherwise | |
1635 | the child could still trip on the parent's breakpoints. Since | |
1636 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 1637 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
1638 | return 0; |
1639 | ||
74960c60 VP |
1640 | return 1; |
1641 | } | |
1642 | ||
934709f0 PW |
1643 | /* Same as should_be_inserted but does the check assuming |
1644 | that the location is not duplicated. */ | |
1645 | ||
1646 | static int | |
1647 | unduplicated_should_be_inserted (struct bp_location *bl) | |
1648 | { | |
1649 | int result; | |
1650 | const int save_duplicate = bl->duplicate; | |
1651 | ||
1652 | bl->duplicate = 0; | |
1653 | result = should_be_inserted (bl); | |
1654 | bl->duplicate = save_duplicate; | |
1655 | return result; | |
1656 | } | |
1657 | ||
35df4500 TJB |
1658 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
1659 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
3fbb6ffa | 1660 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
c30eee59 TJB |
1661 | Returns 0 for success, 1 if the bp_location type is not supported or |
1662 | -1 for failure. | |
879bfdc2 | 1663 | |
4a64f543 MS |
1664 | NOTE drow/2003-09-09: This routine could be broken down to an |
1665 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 1666 | static int |
35df4500 | 1667 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 1668 | struct ui_file *tmp_error_stream, |
3fbb6ffa | 1669 | int *disabled_breaks, |
26bb91f3 | 1670 | int *hw_breakpoint_error) |
879bfdc2 DJ |
1671 | { |
1672 | int val = 0; | |
1673 | ||
35df4500 | 1674 | if (!should_be_inserted (bl) || bl->inserted) |
879bfdc2 DJ |
1675 | return 0; |
1676 | ||
8181d85f | 1677 | /* Initialize the target-specific information. */ |
35df4500 TJB |
1678 | memset (&bl->target_info, 0, sizeof (bl->target_info)); |
1679 | bl->target_info.placed_address = bl->address; | |
1680 | bl->target_info.placed_address_space = bl->pspace->aspace; | |
f1310107 | 1681 | bl->target_info.length = bl->length; |
8181d85f | 1682 | |
35df4500 TJB |
1683 | if (bl->loc_type == bp_loc_software_breakpoint |
1684 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 1685 | { |
35df4500 | 1686 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
1687 | { |
1688 | /* If the explicitly specified breakpoint type | |
1689 | is not hardware breakpoint, check the memory map to see | |
1690 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 1691 | |
765dc015 VP |
1692 | Two important cases are: |
1693 | - location type is not hardware breakpoint, memory | |
1694 | is readonly. We change the type of the location to | |
1695 | hardware breakpoint. | |
4a64f543 MS |
1696 | - location type is hardware breakpoint, memory is |
1697 | read-write. This means we've previously made the | |
1698 | location hardware one, but then the memory map changed, | |
1699 | so we undo. | |
765dc015 | 1700 | |
4a64f543 MS |
1701 | When breakpoints are removed, remove_breakpoints will use |
1702 | location types we've just set here, the only possible | |
1703 | problem is that memory map has changed during running | |
1704 | program, but it's not going to work anyway with current | |
1705 | gdb. */ | |
765dc015 | 1706 | struct mem_region *mr |
35df4500 | 1707 | = lookup_mem_region (bl->target_info.placed_address); |
765dc015 VP |
1708 | |
1709 | if (mr) | |
1710 | { | |
1711 | if (automatic_hardware_breakpoints) | |
1712 | { | |
765dc015 VP |
1713 | enum bp_loc_type new_type; |
1714 | ||
1715 | if (mr->attrib.mode != MEM_RW) | |
1716 | new_type = bp_loc_hardware_breakpoint; | |
1717 | else | |
1718 | new_type = bp_loc_software_breakpoint; | |
1719 | ||
35df4500 | 1720 | if (new_type != bl->loc_type) |
765dc015 VP |
1721 | { |
1722 | static int said = 0; | |
cc59ec59 | 1723 | |
35df4500 | 1724 | bl->loc_type = new_type; |
765dc015 VP |
1725 | if (!said) |
1726 | { | |
3e43a32a MS |
1727 | fprintf_filtered (gdb_stdout, |
1728 | _("Note: automatically using " | |
1729 | "hardware breakpoints for " | |
1730 | "read-only addresses.\n")); | |
765dc015 VP |
1731 | said = 1; |
1732 | } | |
1733 | } | |
1734 | } | |
35df4500 | 1735 | else if (bl->loc_type == bp_loc_software_breakpoint |
765dc015 | 1736 | && mr->attrib.mode != MEM_RW) |
3e43a32a MS |
1737 | warning (_("cannot set software breakpoint " |
1738 | "at readonly address %s"), | |
35df4500 | 1739 | paddress (bl->gdbarch, bl->address)); |
765dc015 VP |
1740 | } |
1741 | } | |
1742 | ||
879bfdc2 DJ |
1743 | /* First check to see if we have to handle an overlay. */ |
1744 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
1745 | || bl->section == NULL |
1746 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
1747 | { |
1748 | /* No overlay handling: just set the breakpoint. */ | |
1749 | ||
348d480f | 1750 | val = bl->owner->ops->insert_location (bl); |
879bfdc2 DJ |
1751 | } |
1752 | else | |
1753 | { | |
4a64f543 | 1754 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
1755 | Shall we set a breakpoint at the LMA? */ |
1756 | if (!overlay_events_enabled) | |
1757 | { | |
1758 | /* Yes -- overlay event support is not active, | |
1759 | so we must try to set a breakpoint at the LMA. | |
1760 | This will not work for a hardware breakpoint. */ | |
35df4500 | 1761 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 1762 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 1763 | bl->owner->number); |
879bfdc2 DJ |
1764 | else |
1765 | { | |
35df4500 TJB |
1766 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
1767 | bl->section); | |
879bfdc2 | 1768 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 TJB |
1769 | bl->overlay_target_info = bl->target_info; |
1770 | bl->overlay_target_info.placed_address = addr; | |
1771 | val = target_insert_breakpoint (bl->gdbarch, | |
1772 | &bl->overlay_target_info); | |
879bfdc2 | 1773 | if (val != 0) |
99361f52 | 1774 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
1775 | "Overlay breakpoint %d " |
1776 | "failed: in ROM?\n", | |
35df4500 | 1777 | bl->owner->number); |
879bfdc2 DJ |
1778 | } |
1779 | } | |
1780 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 1781 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
1782 | { |
1783 | /* Yes. This overlay section is mapped into memory. */ | |
348d480f | 1784 | val = bl->owner->ops->insert_location (bl); |
879bfdc2 DJ |
1785 | } |
1786 | else | |
1787 | { | |
1788 | /* No. This breakpoint will not be inserted. | |
1789 | No error, but do not mark the bp as 'inserted'. */ | |
1790 | return 0; | |
1791 | } | |
1792 | } | |
1793 | ||
1794 | if (val) | |
1795 | { | |
1796 | /* Can't set the breakpoint. */ | |
35df4500 | 1797 | if (solib_name_from_address (bl->pspace, bl->address)) |
879bfdc2 | 1798 | { |
4a64f543 | 1799 | /* See also: disable_breakpoints_in_shlibs. */ |
879bfdc2 | 1800 | val = 0; |
35df4500 | 1801 | bl->shlib_disabled = 1; |
8d3788bd | 1802 | observer_notify_breakpoint_modified (bl->owner); |
3fbb6ffa TJB |
1803 | if (!*disabled_breaks) |
1804 | { | |
1805 | fprintf_unfiltered (tmp_error_stream, | |
1806 | "Cannot insert breakpoint %d.\n", | |
1807 | bl->owner->number); | |
1808 | fprintf_unfiltered (tmp_error_stream, | |
1809 | "Temporarily disabling shared " | |
1810 | "library breakpoints:\n"); | |
1811 | } | |
1812 | *disabled_breaks = 1; | |
879bfdc2 | 1813 | fprintf_unfiltered (tmp_error_stream, |
35df4500 | 1814 | "breakpoint #%d\n", bl->owner->number); |
879bfdc2 DJ |
1815 | } |
1816 | else | |
879bfdc2 | 1817 | { |
35df4500 | 1818 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 DJ |
1819 | { |
1820 | *hw_breakpoint_error = 1; | |
3e43a32a MS |
1821 | fprintf_unfiltered (tmp_error_stream, |
1822 | "Cannot insert hardware " | |
1823 | "breakpoint %d.\n", | |
35df4500 | 1824 | bl->owner->number); |
879bfdc2 DJ |
1825 | } |
1826 | else | |
1827 | { | |
1828 | fprintf_unfiltered (tmp_error_stream, | |
1829 | "Cannot insert breakpoint %d.\n", | |
35df4500 | 1830 | bl->owner->number); |
879bfdc2 DJ |
1831 | fprintf_filtered (tmp_error_stream, |
1832 | "Error accessing memory address "); | |
35df4500 | 1833 | fputs_filtered (paddress (bl->gdbarch, bl->address), |
5af949e3 | 1834 | tmp_error_stream); |
879bfdc2 DJ |
1835 | fprintf_filtered (tmp_error_stream, ": %s.\n", |
1836 | safe_strerror (val)); | |
1837 | } | |
1838 | ||
1839 | } | |
1840 | } | |
1841 | else | |
35df4500 | 1842 | bl->inserted = 1; |
879bfdc2 DJ |
1843 | |
1844 | return val; | |
1845 | } | |
1846 | ||
35df4500 | 1847 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 1848 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 1849 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 1850 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 1851 | { |
77b06cd7 TJB |
1852 | gdb_assert (bl->owner->ops != NULL |
1853 | && bl->owner->ops->insert_location != NULL); | |
1854 | ||
1855 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
1856 | |
1857 | /* If trying to set a read-watchpoint, and it turns out it's not | |
1858 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 1859 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
1860 | { |
1861 | struct bp_location *loc, **loc_temp; | |
1862 | ||
1863 | /* But don't try to insert it, if there's already another | |
1864 | hw_access location that would be considered a duplicate | |
1865 | of this one. */ | |
1866 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 1867 | if (loc != bl |
85d721b8 | 1868 | && loc->watchpoint_type == hw_access |
35df4500 | 1869 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 1870 | { |
35df4500 TJB |
1871 | bl->duplicate = 1; |
1872 | bl->inserted = 1; | |
1873 | bl->target_info = loc->target_info; | |
1874 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
1875 | val = 0; |
1876 | break; | |
1877 | } | |
1878 | ||
1879 | if (val == 1) | |
1880 | { | |
77b06cd7 TJB |
1881 | bl->watchpoint_type = hw_access; |
1882 | val = bl->owner->ops->insert_location (bl); | |
1883 | ||
1884 | if (val) | |
1885 | /* Back to the original value. */ | |
1886 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
1887 | } |
1888 | } | |
1889 | ||
35df4500 | 1890 | bl->inserted = (val == 0); |
879bfdc2 DJ |
1891 | } |
1892 | ||
35df4500 | 1893 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 1894 | { |
77b06cd7 TJB |
1895 | gdb_assert (bl->owner->ops != NULL |
1896 | && bl->owner->ops->insert_location != NULL); | |
1897 | ||
1898 | val = bl->owner->ops->insert_location (bl); | |
1899 | if (val) | |
1900 | { | |
1901 | bl->owner->enable_state = bp_disabled; | |
1902 | ||
1903 | if (val == 1) | |
1904 | warning (_("\ | |
1905 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
1906 | of catchpoint."), bl->owner->number); | |
1907 | else | |
1908 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
1909 | } | |
1910 | ||
1911 | bl->inserted = (val == 0); | |
1640b821 DJ |
1912 | |
1913 | /* We've already printed an error message if there was a problem | |
1914 | inserting this catchpoint, and we've disabled the catchpoint, | |
1915 | so just return success. */ | |
1916 | return 0; | |
879bfdc2 DJ |
1917 | } |
1918 | ||
1919 | return 0; | |
1920 | } | |
1921 | ||
6c95b8df PA |
1922 | /* This function is called when program space PSPACE is about to be |
1923 | deleted. It takes care of updating breakpoints to not reference | |
1924 | PSPACE anymore. */ | |
1925 | ||
1926 | void | |
1927 | breakpoint_program_space_exit (struct program_space *pspace) | |
1928 | { | |
1929 | struct breakpoint *b, *b_temp; | |
876fa593 | 1930 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
1931 | |
1932 | /* Remove any breakpoint that was set through this program space. */ | |
1933 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
1934 | { | |
1935 | if (b->pspace == pspace) | |
1936 | delete_breakpoint (b); | |
1937 | } | |
1938 | ||
1939 | /* Breakpoints set through other program spaces could have locations | |
1940 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 1941 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
1942 | { |
1943 | struct bp_location *tmp; | |
1944 | ||
1945 | if (loc->pspace == pspace) | |
1946 | { | |
2bdf28a0 | 1947 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
1948 | if (loc->owner->loc == loc) |
1949 | loc->owner->loc = loc->next; | |
1950 | else | |
1951 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
1952 | if (tmp->next == loc) | |
1953 | { | |
1954 | tmp->next = loc->next; | |
1955 | break; | |
1956 | } | |
1957 | } | |
1958 | } | |
1959 | ||
1960 | /* Now update the global location list to permanently delete the | |
1961 | removed locations above. */ | |
1962 | update_global_location_list (0); | |
1963 | } | |
1964 | ||
74960c60 VP |
1965 | /* Make sure all breakpoints are inserted in inferior. |
1966 | Throws exception on any error. | |
1967 | A breakpoint that is already inserted won't be inserted | |
1968 | again, so calling this function twice is safe. */ | |
1969 | void | |
1970 | insert_breakpoints (void) | |
1971 | { | |
1972 | struct breakpoint *bpt; | |
1973 | ||
1974 | ALL_BREAKPOINTS (bpt) | |
1975 | if (is_hardware_watchpoint (bpt)) | |
3a5c3e22 PA |
1976 | { |
1977 | struct watchpoint *w = (struct watchpoint *) bpt; | |
1978 | ||
1979 | update_watchpoint (w, 0 /* don't reparse. */); | |
1980 | } | |
74960c60 | 1981 | |
b60e7edf | 1982 | update_global_location_list (1); |
74960c60 | 1983 | |
c35b1492 PA |
1984 | /* update_global_location_list does not insert breakpoints when |
1985 | always_inserted_mode is not enabled. Explicitly insert them | |
1986 | now. */ | |
1987 | if (!breakpoints_always_inserted_mode ()) | |
74960c60 VP |
1988 | insert_breakpoint_locations (); |
1989 | } | |
1990 | ||
c30eee59 | 1991 | /* Used when starting or continuing the program. */ |
c906108c | 1992 | |
74960c60 VP |
1993 | static void |
1994 | insert_breakpoint_locations (void) | |
c906108c | 1995 | { |
a5606eee | 1996 | struct breakpoint *bpt; |
35df4500 | 1997 | struct bp_location *bl, **blp_tmp; |
eacd795a | 1998 | int error_flag = 0; |
c906108c | 1999 | int val = 0; |
3fbb6ffa | 2000 | int disabled_breaks = 0; |
81d0cc19 | 2001 | int hw_breakpoint_error = 0; |
c906108c | 2002 | |
81d0cc19 | 2003 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 2004 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 2005 | |
81d0cc19 GS |
2006 | /* Explicitly mark the warning -- this will only be printed if |
2007 | there was an error. */ | |
2008 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
2009 | |
2010 | save_current_space_and_thread (); | |
2011 | ||
35df4500 | 2012 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 2013 | { |
35df4500 | 2014 | if (!should_be_inserted (bl) || bl->inserted) |
879bfdc2 DJ |
2015 | continue; |
2016 | ||
4a64f543 MS |
2017 | /* There is no point inserting thread-specific breakpoints if |
2018 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
2019 | has BL->OWNER always non-NULL. */ | |
35df4500 TJB |
2020 | if (bl->owner->thread != -1 |
2021 | && !valid_thread_id (bl->owner->thread)) | |
f365de73 AS |
2022 | continue; |
2023 | ||
35df4500 | 2024 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
2025 | |
2026 | /* For targets that support global breakpoints, there's no need | |
2027 | to select an inferior to insert breakpoint to. In fact, even | |
2028 | if we aren't attached to any process yet, we should still | |
2029 | insert breakpoints. */ | |
2030 | if (!gdbarch_has_global_breakpoints (target_gdbarch) | |
2031 | && ptid_equal (inferior_ptid, null_ptid)) | |
2032 | continue; | |
2033 | ||
3fbb6ffa TJB |
2034 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, |
2035 | &hw_breakpoint_error); | |
879bfdc2 | 2036 | if (val) |
eacd795a | 2037 | error_flag = val; |
879bfdc2 | 2038 | } |
c906108c | 2039 | |
4a64f543 MS |
2040 | /* If we failed to insert all locations of a watchpoint, remove |
2041 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
2042 | ALL_BREAKPOINTS (bpt) |
2043 | { | |
2044 | int some_failed = 0; | |
2045 | struct bp_location *loc; | |
2046 | ||
2047 | if (!is_hardware_watchpoint (bpt)) | |
2048 | continue; | |
2049 | ||
d6b74ac4 | 2050 | if (!breakpoint_enabled (bpt)) |
a5606eee | 2051 | continue; |
74960c60 VP |
2052 | |
2053 | if (bpt->disposition == disp_del_at_next_stop) | |
2054 | continue; | |
a5606eee VP |
2055 | |
2056 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 2057 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
2058 | { |
2059 | some_failed = 1; | |
2060 | break; | |
2061 | } | |
2062 | if (some_failed) | |
2063 | { | |
2064 | for (loc = bpt->loc; loc; loc = loc->next) | |
2065 | if (loc->inserted) | |
2066 | remove_breakpoint (loc, mark_uninserted); | |
2067 | ||
2068 | hw_breakpoint_error = 1; | |
2069 | fprintf_unfiltered (tmp_error_stream, | |
2070 | "Could not insert hardware watchpoint %d.\n", | |
2071 | bpt->number); | |
eacd795a | 2072 | error_flag = -1; |
a5606eee VP |
2073 | } |
2074 | } | |
2075 | ||
eacd795a | 2076 | if (error_flag) |
81d0cc19 GS |
2077 | { |
2078 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
2079 | message about possibly exhausted resources. */ | |
879bfdc2 | 2080 | if (hw_breakpoint_error) |
81d0cc19 | 2081 | { |
c6510018 MS |
2082 | fprintf_unfiltered (tmp_error_stream, |
2083 | "Could not insert hardware breakpoints:\n\ | |
2084 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 2085 | } |
81d0cc19 GS |
2086 | target_terminal_ours_for_output (); |
2087 | error_stream (tmp_error_stream); | |
2088 | } | |
f7545552 TT |
2089 | |
2090 | do_cleanups (cleanups); | |
c906108c SS |
2091 | } |
2092 | ||
c30eee59 TJB |
2093 | /* Used when the program stops. |
2094 | Returns zero if successful, or non-zero if there was a problem | |
2095 | removing a breakpoint location. */ | |
2096 | ||
c906108c | 2097 | int |
fba45db2 | 2098 | remove_breakpoints (void) |
c906108c | 2099 | { |
35df4500 | 2100 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 2101 | int val = 0; |
c906108c | 2102 | |
35df4500 | 2103 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2104 | { |
1e4d1764 | 2105 | if (bl->inserted && !is_tracepoint (bl->owner)) |
35df4500 | 2106 | val |= remove_breakpoint (bl, mark_uninserted); |
c5aa993b | 2107 | } |
3a1bae8e | 2108 | return val; |
c906108c SS |
2109 | } |
2110 | ||
6c95b8df PA |
2111 | /* Remove breakpoints of process PID. */ |
2112 | ||
2113 | int | |
2114 | remove_breakpoints_pid (int pid) | |
2115 | { | |
35df4500 | 2116 | struct bp_location *bl, **blp_tmp; |
6c95b8df PA |
2117 | int val; |
2118 | struct inferior *inf = find_inferior_pid (pid); | |
2119 | ||
35df4500 | 2120 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 2121 | { |
35df4500 | 2122 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2123 | continue; |
2124 | ||
35df4500 | 2125 | if (bl->inserted) |
6c95b8df | 2126 | { |
35df4500 | 2127 | val = remove_breakpoint (bl, mark_uninserted); |
6c95b8df PA |
2128 | if (val != 0) |
2129 | return val; | |
2130 | } | |
2131 | } | |
2132 | return 0; | |
2133 | } | |
2134 | ||
c906108c | 2135 | int |
fba45db2 | 2136 | reattach_breakpoints (int pid) |
c906108c | 2137 | { |
6c95b8df | 2138 | struct cleanup *old_chain; |
35df4500 | 2139 | struct bp_location *bl, **blp_tmp; |
c906108c | 2140 | int val; |
86b887df | 2141 | struct ui_file *tmp_error_stream; |
3fbb6ffa | 2142 | int dummy1 = 0, dummy2 = 0; |
6c95b8df PA |
2143 | struct inferior *inf; |
2144 | struct thread_info *tp; | |
2145 | ||
2146 | tp = any_live_thread_of_process (pid); | |
2147 | if (tp == NULL) | |
2148 | return 1; | |
2149 | ||
2150 | inf = find_inferior_pid (pid); | |
2151 | old_chain = save_inferior_ptid (); | |
2152 | ||
2153 | inferior_ptid = tp->ptid; | |
a4954f26 | 2154 | |
86b887df | 2155 | tmp_error_stream = mem_fileopen (); |
a4954f26 | 2156 | make_cleanup_ui_file_delete (tmp_error_stream); |
c906108c | 2157 | |
35df4500 | 2158 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2159 | { |
35df4500 | 2160 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2161 | continue; |
2162 | ||
35df4500 | 2163 | if (bl->inserted) |
c5aa993b | 2164 | { |
35df4500 | 2165 | bl->inserted = 0; |
3fbb6ffa | 2166 | val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2); |
c5aa993b JM |
2167 | if (val != 0) |
2168 | { | |
ce696e05 | 2169 | do_cleanups (old_chain); |
c5aa993b JM |
2170 | return val; |
2171 | } | |
2172 | } | |
2173 | } | |
ce696e05 | 2174 | do_cleanups (old_chain); |
c906108c SS |
2175 | return 0; |
2176 | } | |
2177 | ||
e58b0e63 PA |
2178 | static int internal_breakpoint_number = -1; |
2179 | ||
84f4c1fe PM |
2180 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
2181 | If INTERNAL is non-zero, the breakpoint number will be populated | |
2182 | from internal_breakpoint_number and that variable decremented. | |
e5dd4106 | 2183 | Otherwise the breakpoint number will be populated from |
84f4c1fe PM |
2184 | breakpoint_count and that value incremented. Internal breakpoints |
2185 | do not set the internal var bpnum. */ | |
2186 | static void | |
2187 | set_breakpoint_number (int internal, struct breakpoint *b) | |
2188 | { | |
2189 | if (internal) | |
2190 | b->number = internal_breakpoint_number--; | |
2191 | else | |
2192 | { | |
2193 | set_breakpoint_count (breakpoint_count + 1); | |
2194 | b->number = breakpoint_count; | |
2195 | } | |
2196 | } | |
2197 | ||
e62c965a | 2198 | static struct breakpoint * |
a6d9a66e | 2199 | create_internal_breakpoint (struct gdbarch *gdbarch, |
06edf0c0 | 2200 | CORE_ADDR address, enum bptype type, |
c0a91b2b | 2201 | const struct breakpoint_ops *ops) |
e62c965a | 2202 | { |
e62c965a PP |
2203 | struct symtab_and_line sal; |
2204 | struct breakpoint *b; | |
2205 | ||
4a64f543 | 2206 | init_sal (&sal); /* Initialize to zeroes. */ |
e62c965a PP |
2207 | |
2208 | sal.pc = address; | |
2209 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 2210 | sal.pspace = current_program_space; |
e62c965a | 2211 | |
06edf0c0 | 2212 | b = set_raw_breakpoint (gdbarch, sal, type, ops); |
e62c965a PP |
2213 | b->number = internal_breakpoint_number--; |
2214 | b->disposition = disp_donttouch; | |
2215 | ||
2216 | return b; | |
2217 | } | |
2218 | ||
17450429 PP |
2219 | static const char *const longjmp_names[] = |
2220 | { | |
2221 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
2222 | }; | |
2223 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
2224 | ||
2225 | /* Per-objfile data private to breakpoint.c. */ | |
2226 | struct breakpoint_objfile_data | |
2227 | { | |
2228 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
2229 | struct minimal_symbol *overlay_msym; | |
2230 | ||
2231 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
2232 | struct minimal_symbol *longjmp_msym[NUM_LONGJMP_NAMES]; | |
2233 | ||
2234 | /* Minimal symbol for "std::terminate()" (if any). */ | |
2235 | struct minimal_symbol *terminate_msym; | |
2236 | ||
2237 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
2238 | struct minimal_symbol *exception_msym; | |
2239 | }; | |
2240 | ||
2241 | static const struct objfile_data *breakpoint_objfile_key; | |
2242 | ||
2243 | /* Minimal symbol not found sentinel. */ | |
2244 | static struct minimal_symbol msym_not_found; | |
2245 | ||
2246 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
2247 | ||
2248 | static int | |
2249 | msym_not_found_p (const struct minimal_symbol *msym) | |
2250 | { | |
2251 | return msym == &msym_not_found; | |
2252 | } | |
2253 | ||
2254 | /* Return per-objfile data needed by breakpoint.c. | |
2255 | Allocate the data if necessary. */ | |
2256 | ||
2257 | static struct breakpoint_objfile_data * | |
2258 | get_breakpoint_objfile_data (struct objfile *objfile) | |
2259 | { | |
2260 | struct breakpoint_objfile_data *bp_objfile_data; | |
2261 | ||
2262 | bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key); | |
2263 | if (bp_objfile_data == NULL) | |
2264 | { | |
2265 | bp_objfile_data = obstack_alloc (&objfile->objfile_obstack, | |
2266 | sizeof (*bp_objfile_data)); | |
2267 | ||
2268 | memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); | |
2269 | set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); | |
2270 | } | |
2271 | return bp_objfile_data; | |
2272 | } | |
2273 | ||
e62c965a | 2274 | static void |
af02033e | 2275 | create_overlay_event_breakpoint (void) |
e62c965a | 2276 | { |
69de3c6a | 2277 | struct objfile *objfile; |
af02033e | 2278 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 2279 | |
69de3c6a PP |
2280 | ALL_OBJFILES (objfile) |
2281 | { | |
2282 | struct breakpoint *b; | |
17450429 PP |
2283 | struct breakpoint_objfile_data *bp_objfile_data; |
2284 | CORE_ADDR addr; | |
69de3c6a | 2285 | |
17450429 PP |
2286 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
2287 | ||
2288 | if (msym_not_found_p (bp_objfile_data->overlay_msym)) | |
2289 | continue; | |
2290 | ||
2291 | if (bp_objfile_data->overlay_msym == NULL) | |
2292 | { | |
2293 | struct minimal_symbol *m; | |
2294 | ||
2295 | m = lookup_minimal_symbol_text (func_name, objfile); | |
2296 | if (m == NULL) | |
2297 | { | |
2298 | /* Avoid future lookups in this objfile. */ | |
2299 | bp_objfile_data->overlay_msym = &msym_not_found; | |
2300 | continue; | |
2301 | } | |
2302 | bp_objfile_data->overlay_msym = m; | |
2303 | } | |
e62c965a | 2304 | |
17450429 PP |
2305 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
2306 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, | |
06edf0c0 PA |
2307 | bp_overlay_event, |
2308 | &internal_breakpoint_ops); | |
69de3c6a | 2309 | b->addr_string = xstrdup (func_name); |
e62c965a | 2310 | |
69de3c6a PP |
2311 | if (overlay_debugging == ovly_auto) |
2312 | { | |
2313 | b->enable_state = bp_enabled; | |
2314 | overlay_events_enabled = 1; | |
2315 | } | |
2316 | else | |
2317 | { | |
2318 | b->enable_state = bp_disabled; | |
2319 | overlay_events_enabled = 0; | |
2320 | } | |
e62c965a PP |
2321 | } |
2322 | update_global_location_list (1); | |
2323 | } | |
2324 | ||
0fd8e87f | 2325 | static void |
af02033e | 2326 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 2327 | { |
6c95b8df | 2328 | struct program_space *pspace; |
6c95b8df PA |
2329 | struct cleanup *old_chain; |
2330 | ||
2331 | old_chain = save_current_program_space (); | |
0fd8e87f | 2332 | |
6c95b8df | 2333 | ALL_PSPACES (pspace) |
af02033e PP |
2334 | { |
2335 | struct objfile *objfile; | |
2336 | ||
2337 | set_current_program_space (pspace); | |
2338 | ||
2339 | ALL_OBJFILES (objfile) | |
0fd8e87f | 2340 | { |
af02033e PP |
2341 | int i; |
2342 | struct gdbarch *gdbarch; | |
17450429 | 2343 | struct breakpoint_objfile_data *bp_objfile_data; |
0fd8e87f | 2344 | |
af02033e PP |
2345 | gdbarch = get_objfile_arch (objfile); |
2346 | if (!gdbarch_get_longjmp_target_p (gdbarch)) | |
0fd8e87f UW |
2347 | continue; |
2348 | ||
17450429 PP |
2349 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
2350 | ||
2351 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) | |
af02033e PP |
2352 | { |
2353 | struct breakpoint *b; | |
af02033e | 2354 | const char *func_name; |
17450429 | 2355 | CORE_ADDR addr; |
6c95b8df | 2356 | |
17450429 | 2357 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i])) |
af02033e | 2358 | continue; |
0fd8e87f | 2359 | |
17450429 PP |
2360 | func_name = longjmp_names[i]; |
2361 | if (bp_objfile_data->longjmp_msym[i] == NULL) | |
2362 | { | |
2363 | struct minimal_symbol *m; | |
2364 | ||
2365 | m = lookup_minimal_symbol_text (func_name, objfile); | |
2366 | if (m == NULL) | |
2367 | { | |
2368 | /* Prevent future lookups in this objfile. */ | |
2369 | bp_objfile_data->longjmp_msym[i] = &msym_not_found; | |
2370 | continue; | |
2371 | } | |
2372 | bp_objfile_data->longjmp_msym[i] = m; | |
2373 | } | |
2374 | ||
2375 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); | |
06edf0c0 PA |
2376 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, |
2377 | &internal_breakpoint_ops); | |
af02033e PP |
2378 | b->addr_string = xstrdup (func_name); |
2379 | b->enable_state = bp_disabled; | |
2380 | } | |
0fd8e87f | 2381 | } |
af02033e | 2382 | } |
0fd8e87f | 2383 | update_global_location_list (1); |
6c95b8df PA |
2384 | |
2385 | do_cleanups (old_chain); | |
0fd8e87f UW |
2386 | } |
2387 | ||
af02033e | 2388 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 2389 | static void |
af02033e | 2390 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
2391 | { |
2392 | struct program_space *pspace; | |
aa7d318d | 2393 | struct cleanup *old_chain; |
af02033e | 2394 | const char *const func_name = "std::terminate()"; |
aa7d318d TT |
2395 | |
2396 | old_chain = save_current_program_space (); | |
2397 | ||
2398 | ALL_PSPACES (pspace) | |
17450429 PP |
2399 | { |
2400 | struct objfile *objfile; | |
2401 | CORE_ADDR addr; | |
2402 | ||
2403 | set_current_program_space (pspace); | |
2404 | ||
aa7d318d TT |
2405 | ALL_OBJFILES (objfile) |
2406 | { | |
2407 | struct breakpoint *b; | |
17450429 | 2408 | struct breakpoint_objfile_data *bp_objfile_data; |
aa7d318d | 2409 | |
17450429 | 2410 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 2411 | |
17450429 PP |
2412 | if (msym_not_found_p (bp_objfile_data->terminate_msym)) |
2413 | continue; | |
2414 | ||
2415 | if (bp_objfile_data->terminate_msym == NULL) | |
2416 | { | |
2417 | struct minimal_symbol *m; | |
2418 | ||
2419 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
2420 | if (m == NULL || (MSYMBOL_TYPE (m) != mst_text | |
2421 | && MSYMBOL_TYPE (m) != mst_file_text)) | |
2422 | { | |
2423 | /* Prevent future lookups in this objfile. */ | |
2424 | bp_objfile_data->terminate_msym = &msym_not_found; | |
2425 | continue; | |
2426 | } | |
2427 | bp_objfile_data->terminate_msym = m; | |
2428 | } | |
aa7d318d | 2429 | |
17450429 PP |
2430 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
2431 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, | |
06edf0c0 PA |
2432 | bp_std_terminate_master, |
2433 | &internal_breakpoint_ops); | |
aa7d318d TT |
2434 | b->addr_string = xstrdup (func_name); |
2435 | b->enable_state = bp_disabled; | |
2436 | } | |
17450429 PP |
2437 | } |
2438 | ||
aa7d318d TT |
2439 | update_global_location_list (1); |
2440 | ||
2441 | do_cleanups (old_chain); | |
2442 | } | |
2443 | ||
186c406b TT |
2444 | /* Install a master breakpoint on the unwinder's debug hook. */ |
2445 | ||
2446 | void | |
2447 | create_exception_master_breakpoint (void) | |
2448 | { | |
2449 | struct objfile *objfile; | |
17450429 | 2450 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b TT |
2451 | |
2452 | ALL_OBJFILES (objfile) | |
2453 | { | |
17450429 PP |
2454 | struct breakpoint *b; |
2455 | struct gdbarch *gdbarch; | |
2456 | struct breakpoint_objfile_data *bp_objfile_data; | |
2457 | CORE_ADDR addr; | |
2458 | ||
2459 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
2460 | ||
2461 | if (msym_not_found_p (bp_objfile_data->exception_msym)) | |
2462 | continue; | |
2463 | ||
2464 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 2465 | |
17450429 | 2466 | if (bp_objfile_data->exception_msym == NULL) |
186c406b | 2467 | { |
17450429 | 2468 | struct minimal_symbol *debug_hook; |
186c406b | 2469 | |
17450429 PP |
2470 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
2471 | if (debug_hook == NULL) | |
2472 | { | |
2473 | bp_objfile_data->exception_msym = &msym_not_found; | |
2474 | continue; | |
2475 | } | |
2476 | ||
2477 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 2478 | } |
17450429 PP |
2479 | |
2480 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); | |
2481 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, | |
2482 | ¤t_target); | |
06edf0c0 PA |
2483 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
2484 | &internal_breakpoint_ops); | |
17450429 PP |
2485 | b->addr_string = xstrdup (func_name); |
2486 | b->enable_state = bp_disabled; | |
186c406b TT |
2487 | } |
2488 | ||
2489 | update_global_location_list (1); | |
2490 | } | |
2491 | ||
c906108c | 2492 | void |
fba45db2 | 2493 | update_breakpoints_after_exec (void) |
c906108c | 2494 | { |
35df4500 | 2495 | struct breakpoint *b, *b_tmp; |
876fa593 | 2496 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 2497 | |
25b22b0a PA |
2498 | /* We're about to delete breakpoints from GDB's lists. If the |
2499 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
2500 | writing the breakpoints' "shadow contents" back into memory. The | |
2501 | "shadow contents" are NOT valid after an exec, so GDB should not | |
2502 | do that. Instead, the target is responsible from marking | |
2503 | breakpoints out as soon as it detects an exec. We don't do that | |
2504 | here instead, because there may be other attempts to delete | |
2505 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 2506 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
2507 | if (bploc->pspace == current_program_space) |
2508 | gdb_assert (!bploc->inserted); | |
c906108c | 2509 | |
35df4500 | 2510 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 2511 | { |
6c95b8df PA |
2512 | if (b->pspace != current_program_space) |
2513 | continue; | |
2514 | ||
4a64f543 | 2515 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
2516 | if (b->type == bp_shlib_event) |
2517 | { | |
2518 | delete_breakpoint (b); | |
2519 | continue; | |
2520 | } | |
c906108c | 2521 | |
4a64f543 | 2522 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
2523 | if (b->type == bp_jit_event) |
2524 | { | |
2525 | delete_breakpoint (b); | |
2526 | continue; | |
2527 | } | |
2528 | ||
1900040c | 2529 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
2530 | as must overlay event and longjmp master breakpoints. */ |
2531 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
2532 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
2533 | || b->type == bp_exception_master) | |
c4093a6a JM |
2534 | { |
2535 | delete_breakpoint (b); | |
2536 | continue; | |
2537 | } | |
2538 | ||
4a64f543 | 2539 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2c03e5be | 2540 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
c5aa993b JM |
2541 | { |
2542 | delete_breakpoint (b); | |
2543 | continue; | |
2544 | } | |
2545 | ||
611c83ae PA |
2546 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
2547 | after an exec. */ | |
186c406b TT |
2548 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
2549 | || b->type == bp_exception || b->type == bp_exception_resume) | |
611c83ae PA |
2550 | { |
2551 | delete_breakpoint (b); | |
2552 | continue; | |
2553 | } | |
2554 | ||
ce78b96d JB |
2555 | if (b->type == bp_catchpoint) |
2556 | { | |
2557 | /* For now, none of the bp_catchpoint breakpoints need to | |
2558 | do anything at this point. In the future, if some of | |
2559 | the catchpoints need to something, we will need to add | |
2560 | a new method, and call this method from here. */ | |
2561 | continue; | |
2562 | } | |
2563 | ||
c5aa993b JM |
2564 | /* bp_finish is a special case. The only way we ought to be able |
2565 | to see one of these when an exec() has happened, is if the user | |
2566 | caught a vfork, and then said "finish". Ordinarily a finish just | |
2567 | carries them to the call-site of the current callee, by setting | |
2568 | a temporary bp there and resuming. But in this case, the finish | |
2569 | will carry them entirely through the vfork & exec. | |
2570 | ||
2571 | We don't want to allow a bp_finish to remain inserted now. But | |
2572 | we can't safely delete it, 'cause finish_command has a handle to | |
2573 | the bp on a bpstat, and will later want to delete it. There's a | |
2574 | chance (and I've seen it happen) that if we delete the bp_finish | |
2575 | here, that its storage will get reused by the time finish_command | |
2576 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
2577 | We really must allow finish_command to delete a bp_finish. | |
2578 | ||
e5dd4106 | 2579 | In the absence of a general solution for the "how do we know |
53a5351d JM |
2580 | it's safe to delete something others may have handles to?" |
2581 | problem, what we'll do here is just uninsert the bp_finish, and | |
2582 | let finish_command delete it. | |
2583 | ||
2584 | (We know the bp_finish is "doomed" in the sense that it's | |
2585 | momentary, and will be deleted as soon as finish_command sees | |
2586 | the inferior stopped. So it doesn't matter that the bp's | |
2587 | address is probably bogus in the new a.out, unlike e.g., the | |
2588 | solib breakpoints.) */ | |
c5aa993b | 2589 | |
c5aa993b JM |
2590 | if (b->type == bp_finish) |
2591 | { | |
2592 | continue; | |
2593 | } | |
2594 | ||
2595 | /* Without a symbolic address, we have little hope of the | |
2596 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 2597 | a.out. */ |
c5aa993b JM |
2598 | if (b->addr_string == NULL) |
2599 | { | |
2600 | delete_breakpoint (b); | |
2601 | continue; | |
2602 | } | |
c5aa993b | 2603 | } |
1900040c | 2604 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
af02033e PP |
2605 | create_overlay_event_breakpoint (); |
2606 | create_longjmp_master_breakpoint (); | |
2607 | create_std_terminate_master_breakpoint (); | |
186c406b | 2608 | create_exception_master_breakpoint (); |
c906108c SS |
2609 | } |
2610 | ||
2611 | int | |
fba45db2 | 2612 | detach_breakpoints (int pid) |
c906108c | 2613 | { |
35df4500 | 2614 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 2615 | int val = 0; |
ce696e05 | 2616 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 2617 | struct inferior *inf = current_inferior (); |
c5aa993b | 2618 | |
39f77062 | 2619 | if (pid == PIDGET (inferior_ptid)) |
8a3fe4f8 | 2620 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 2621 | |
6c95b8df | 2622 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
ce696e05 | 2623 | inferior_ptid = pid_to_ptid (pid); |
35df4500 | 2624 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2625 | { |
35df4500 | 2626 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2627 | continue; |
2628 | ||
35df4500 TJB |
2629 | if (bl->inserted) |
2630 | val |= remove_breakpoint_1 (bl, mark_inserted); | |
c5aa993b | 2631 | } |
d03285ec UW |
2632 | |
2633 | /* Detach single-step breakpoints as well. */ | |
2634 | detach_single_step_breakpoints (); | |
2635 | ||
ce696e05 | 2636 | do_cleanups (old_chain); |
3a1bae8e | 2637 | return val; |
c906108c SS |
2638 | } |
2639 | ||
35df4500 | 2640 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
2641 | Note that this is used to detach breakpoints from a child fork. |
2642 | When we get here, the child isn't in the inferior list, and neither | |
2643 | do we have objects to represent its address space --- we should | |
35df4500 | 2644 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 2645 | |
c906108c | 2646 | static int |
35df4500 | 2647 | remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is) |
c906108c SS |
2648 | { |
2649 | int val; | |
c5aa993b | 2650 | |
35df4500 TJB |
2651 | /* BL is never in moribund_locations by our callers. */ |
2652 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 2653 | |
35df4500 | 2654 | if (bl->owner->enable_state == bp_permanent) |
c2c6d25f JM |
2655 | /* Permanent breakpoints cannot be inserted or removed. */ |
2656 | return 0; | |
2657 | ||
74960c60 VP |
2658 | /* The type of none suggests that owner is actually deleted. |
2659 | This should not ever happen. */ | |
35df4500 | 2660 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 2661 | |
35df4500 TJB |
2662 | if (bl->loc_type == bp_loc_software_breakpoint |
2663 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 2664 | { |
c02f5703 MS |
2665 | /* "Normal" instruction breakpoint: either the standard |
2666 | trap-instruction bp (bp_breakpoint), or a | |
2667 | bp_hardware_breakpoint. */ | |
2668 | ||
2669 | /* First check to see if we have to handle an overlay. */ | |
2670 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2671 | || bl->section == NULL |
2672 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
2673 | { |
2674 | /* No overlay handling: just remove the breakpoint. */ | |
348d480f | 2675 | val = bl->owner->ops->remove_location (bl); |
c02f5703 | 2676 | } |
c906108c SS |
2677 | else |
2678 | { | |
4a64f543 | 2679 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
2680 | Did we set a breakpoint at the LMA? */ |
2681 | if (!overlay_events_enabled) | |
2682 | { | |
2683 | /* Yes -- overlay event support is not active, so we | |
2684 | should have set a breakpoint at the LMA. Remove it. | |
2685 | */ | |
c02f5703 MS |
2686 | /* Ignore any failures: if the LMA is in ROM, we will |
2687 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
2688 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
2689 | target_remove_hw_breakpoint (bl->gdbarch, | |
2690 | &bl->overlay_target_info); | |
c02f5703 | 2691 | else |
35df4500 TJB |
2692 | target_remove_breakpoint (bl->gdbarch, |
2693 | &bl->overlay_target_info); | |
c02f5703 MS |
2694 | } |
2695 | /* Did we set a breakpoint at the VMA? | |
2696 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 2697 | if (bl->inserted) |
c906108c | 2698 | { |
c02f5703 MS |
2699 | /* Yes -- remove it. Previously we did not bother to |
2700 | remove the breakpoint if the section had been | |
2701 | unmapped, but let's not rely on that being safe. We | |
2702 | don't know what the overlay manager might do. */ | |
aa67235e UW |
2703 | |
2704 | /* However, we should remove *software* breakpoints only | |
2705 | if the section is still mapped, or else we overwrite | |
2706 | wrong code with the saved shadow contents. */ | |
348d480f PA |
2707 | if (bl->loc_type == bp_loc_hardware_breakpoint |
2708 | || section_is_mapped (bl->section)) | |
2709 | val = bl->owner->ops->remove_location (bl); | |
aa67235e UW |
2710 | else |
2711 | val = 0; | |
c906108c | 2712 | } |
c02f5703 MS |
2713 | else |
2714 | { | |
2715 | /* No -- not inserted, so no need to remove. No error. */ | |
2716 | val = 0; | |
2717 | } | |
c906108c | 2718 | } |
879d1e6b UW |
2719 | |
2720 | /* In some cases, we might not be able to remove a breakpoint | |
2721 | in a shared library that has already been removed, but we | |
2722 | have not yet processed the shlib unload event. */ | |
35df4500 | 2723 | if (val && solib_name_from_address (bl->pspace, bl->address)) |
879d1e6b UW |
2724 | val = 0; |
2725 | ||
c906108c SS |
2726 | if (val) |
2727 | return val; | |
35df4500 | 2728 | bl->inserted = (is == mark_inserted); |
c906108c | 2729 | } |
35df4500 | 2730 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 2731 | { |
77b06cd7 TJB |
2732 | gdb_assert (bl->owner->ops != NULL |
2733 | && bl->owner->ops->remove_location != NULL); | |
2734 | ||
35df4500 | 2735 | bl->inserted = (is == mark_inserted); |
77b06cd7 | 2736 | bl->owner->ops->remove_location (bl); |
2e70b7b9 | 2737 | |
c906108c | 2738 | /* Failure to remove any of the hardware watchpoints comes here. */ |
35df4500 | 2739 | if ((is == mark_uninserted) && (bl->inserted)) |
8a3fe4f8 | 2740 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 2741 | bl->owner->number); |
c906108c | 2742 | } |
35df4500 TJB |
2743 | else if (bl->owner->type == bp_catchpoint |
2744 | && breakpoint_enabled (bl->owner) | |
2745 | && !bl->duplicate) | |
ce78b96d | 2746 | { |
77b06cd7 TJB |
2747 | gdb_assert (bl->owner->ops != NULL |
2748 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 2749 | |
77b06cd7 | 2750 | val = bl->owner->ops->remove_location (bl); |
ce78b96d JB |
2751 | if (val) |
2752 | return val; | |
77b06cd7 | 2753 | |
35df4500 | 2754 | bl->inserted = (is == mark_inserted); |
ce78b96d | 2755 | } |
c906108c SS |
2756 | |
2757 | return 0; | |
2758 | } | |
2759 | ||
6c95b8df | 2760 | static int |
35df4500 | 2761 | remove_breakpoint (struct bp_location *bl, insertion_state_t is) |
6c95b8df PA |
2762 | { |
2763 | int ret; | |
2764 | struct cleanup *old_chain; | |
2765 | ||
35df4500 TJB |
2766 | /* BL is never in moribund_locations by our callers. */ |
2767 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 2768 | |
35df4500 | 2769 | if (bl->owner->enable_state == bp_permanent) |
6c95b8df PA |
2770 | /* Permanent breakpoints cannot be inserted or removed. */ |
2771 | return 0; | |
2772 | ||
2773 | /* The type of none suggests that owner is actually deleted. | |
2774 | This should not ever happen. */ | |
35df4500 | 2775 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df PA |
2776 | |
2777 | old_chain = save_current_space_and_thread (); | |
2778 | ||
35df4500 | 2779 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 2780 | |
35df4500 | 2781 | ret = remove_breakpoint_1 (bl, is); |
6c95b8df PA |
2782 | |
2783 | do_cleanups (old_chain); | |
2784 | return ret; | |
2785 | } | |
2786 | ||
c906108c SS |
2787 | /* Clear the "inserted" flag in all breakpoints. */ |
2788 | ||
25b22b0a | 2789 | void |
fba45db2 | 2790 | mark_breakpoints_out (void) |
c906108c | 2791 | { |
35df4500 | 2792 | struct bp_location *bl, **blp_tmp; |
c906108c | 2793 | |
35df4500 TJB |
2794 | ALL_BP_LOCATIONS (bl, blp_tmp) |
2795 | if (bl->pspace == current_program_space) | |
2796 | bl->inserted = 0; | |
c906108c SS |
2797 | } |
2798 | ||
53a5351d JM |
2799 | /* Clear the "inserted" flag in all breakpoints and delete any |
2800 | breakpoints which should go away between runs of the program. | |
c906108c SS |
2801 | |
2802 | Plus other such housekeeping that has to be done for breakpoints | |
2803 | between runs. | |
2804 | ||
53a5351d JM |
2805 | Note: this function gets called at the end of a run (by |
2806 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 2807 | init_wait_for_inferior). */ |
c906108c SS |
2808 | |
2809 | ||
2810 | ||
2811 | void | |
fba45db2 | 2812 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 2813 | { |
35df4500 TJB |
2814 | struct breakpoint *b, *b_tmp; |
2815 | struct bp_location *bl, **blp_tmp; | |
1c5cfe86 | 2816 | int ix; |
6c95b8df | 2817 | struct program_space *pspace = current_program_space; |
c906108c | 2818 | |
50c71eaf PA |
2819 | /* If breakpoint locations are shared across processes, then there's |
2820 | nothing to do. */ | |
2567c7d9 | 2821 | if (gdbarch_has_global_breakpoints (target_gdbarch)) |
50c71eaf PA |
2822 | return; |
2823 | ||
35df4500 | 2824 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 2825 | { |
35df4500 TJB |
2826 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
2827 | if (bl->pspace == pspace | |
2828 | && bl->owner->enable_state != bp_permanent) | |
2829 | bl->inserted = 0; | |
6c95b8df | 2830 | } |
075f6582 | 2831 | |
35df4500 | 2832 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 2833 | { |
6c95b8df PA |
2834 | if (b->loc && b->loc->pspace != pspace) |
2835 | continue; | |
2836 | ||
c5aa993b JM |
2837 | switch (b->type) |
2838 | { | |
2839 | case bp_call_dummy: | |
c906108c | 2840 | |
c5aa993b | 2841 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
2842 | cause problems when the inferior is rerun, so we better get |
2843 | rid of it. */ | |
2844 | ||
2845 | case bp_watchpoint_scope: | |
2846 | ||
2847 | /* Also get rid of scope breakpoints. */ | |
2848 | ||
2849 | case bp_shlib_event: | |
2850 | ||
2851 | /* Also remove solib event breakpoints. Their addresses may | |
2852 | have changed since the last time we ran the program. | |
2853 | Actually we may now be debugging against different target; | |
2854 | and so the solib backend that installed this breakpoint may | |
2855 | not be used in by the target. E.g., | |
2856 | ||
2857 | (gdb) file prog-linux | |
2858 | (gdb) run # native linux target | |
2859 | ... | |
2860 | (gdb) kill | |
2861 | (gdb) file prog-win.exe | |
2862 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
2863 | */ | |
c906108c | 2864 | |
c5aa993b JM |
2865 | delete_breakpoint (b); |
2866 | break; | |
c906108c | 2867 | |
c5aa993b JM |
2868 | case bp_watchpoint: |
2869 | case bp_hardware_watchpoint: | |
2870 | case bp_read_watchpoint: | |
2871 | case bp_access_watchpoint: | |
3a5c3e22 PA |
2872 | { |
2873 | struct watchpoint *w = (struct watchpoint *) b; | |
c906108c | 2874 | |
3a5c3e22 PA |
2875 | /* Likewise for watchpoints on local expressions. */ |
2876 | if (w->exp_valid_block != NULL) | |
2877 | delete_breakpoint (b); | |
2878 | else if (context == inf_starting) | |
2879 | { | |
2880 | /* Reset val field to force reread of starting value in | |
2881 | insert_breakpoints. */ | |
2882 | if (w->val) | |
2883 | value_free (w->val); | |
2884 | w->val = NULL; | |
2885 | w->val_valid = 0; | |
c860120c | 2886 | } |
3a5c3e22 | 2887 | } |
c5aa993b JM |
2888 | break; |
2889 | default: | |
c5aa993b JM |
2890 | break; |
2891 | } | |
2892 | } | |
1c5cfe86 PA |
2893 | |
2894 | /* Get rid of the moribund locations. */ | |
35df4500 TJB |
2895 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
2896 | decref_bp_location (&bl); | |
1c5cfe86 | 2897 | VEC_free (bp_location_p, moribund_locations); |
c906108c SS |
2898 | } |
2899 | ||
6c95b8df PA |
2900 | /* These functions concern about actual breakpoints inserted in the |
2901 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
2902 | we need to hop over the bkpt --- so we check for address space | |
2903 | match, not program space. */ | |
2904 | ||
c2c6d25f JM |
2905 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
2906 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
2907 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
2908 | permanent breakpoint. | |
2909 | - When continuing from a location with an ordinary breakpoint, we | |
2910 | actually single step once before calling insert_breakpoints. | |
e5dd4106 | 2911 | - When continuing from a location with a permanent breakpoint, we |
c2c6d25f JM |
2912 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
2913 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 2914 | |
c2c6d25f | 2915 | enum breakpoint_here |
6c95b8df | 2916 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 2917 | { |
35df4500 | 2918 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 2919 | int any_breakpoint_here = 0; |
c906108c | 2920 | |
35df4500 | 2921 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 2922 | { |
35df4500 TJB |
2923 | if (bl->loc_type != bp_loc_software_breakpoint |
2924 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
2925 | continue; |
2926 | ||
f1310107 | 2927 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 TJB |
2928 | if ((breakpoint_enabled (bl->owner) |
2929 | || bl->owner->enable_state == bp_permanent) | |
f1310107 | 2930 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
2931 | { |
2932 | if (overlay_debugging | |
35df4500 TJB |
2933 | && section_is_overlay (bl->section) |
2934 | && !section_is_mapped (bl->section)) | |
075f6582 | 2935 | continue; /* unmapped overlay -- can't be a match */ |
35df4500 | 2936 | else if (bl->owner->enable_state == bp_permanent) |
075f6582 DJ |
2937 | return permanent_breakpoint_here; |
2938 | else | |
2939 | any_breakpoint_here = 1; | |
2940 | } | |
2941 | } | |
c906108c | 2942 | |
c2c6d25f | 2943 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
2944 | } |
2945 | ||
1c5cfe86 PA |
2946 | /* Return true if there's a moribund breakpoint at PC. */ |
2947 | ||
2948 | int | |
6c95b8df | 2949 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
2950 | { |
2951 | struct bp_location *loc; | |
2952 | int ix; | |
2953 | ||
2954 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
f1310107 | 2955 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
2956 | return 1; |
2957 | ||
2958 | return 0; | |
2959 | } | |
c2c6d25f | 2960 | |
c36b740a | 2961 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
4a64f543 MS |
2962 | inserted using regular breakpoint_chain / bp_location array |
2963 | mechanism. This does not check for single-step breakpoints, which | |
2964 | are inserted and removed using direct target manipulation. */ | |
c906108c SS |
2965 | |
2966 | int | |
4a64f543 MS |
2967 | regular_breakpoint_inserted_here_p (struct address_space *aspace, |
2968 | CORE_ADDR pc) | |
c906108c | 2969 | { |
35df4500 | 2970 | struct bp_location *bl, **blp_tmp; |
c906108c | 2971 | |
35df4500 | 2972 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2973 | { |
35df4500 TJB |
2974 | if (bl->loc_type != bp_loc_software_breakpoint |
2975 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
2976 | continue; |
2977 | ||
35df4500 | 2978 | if (bl->inserted |
f1310107 | 2979 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
2980 | { |
2981 | if (overlay_debugging | |
35df4500 TJB |
2982 | && section_is_overlay (bl->section) |
2983 | && !section_is_mapped (bl->section)) | |
075f6582 DJ |
2984 | continue; /* unmapped overlay -- can't be a match */ |
2985 | else | |
2986 | return 1; | |
2987 | } | |
c5aa993b | 2988 | } |
c36b740a VP |
2989 | return 0; |
2990 | } | |
2991 | ||
2992 | /* Returns non-zero iff there's either regular breakpoint | |
2993 | or a single step breakpoint inserted at PC. */ | |
2994 | ||
2995 | int | |
6c95b8df | 2996 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c36b740a | 2997 | { |
6c95b8df | 2998 | if (regular_breakpoint_inserted_here_p (aspace, pc)) |
c36b740a | 2999 | return 1; |
c906108c | 3000 | |
6c95b8df | 3001 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
3002 | return 1; |
3003 | ||
c906108c SS |
3004 | return 0; |
3005 | } | |
3006 | ||
4fa8626c DJ |
3007 | /* This function returns non-zero iff there is a software breakpoint |
3008 | inserted at PC. */ | |
3009 | ||
3010 | int | |
3e43a32a MS |
3011 | software_breakpoint_inserted_here_p (struct address_space *aspace, |
3012 | CORE_ADDR pc) | |
4fa8626c | 3013 | { |
35df4500 | 3014 | struct bp_location *bl, **blp_tmp; |
4fa8626c | 3015 | |
35df4500 | 3016 | ALL_BP_LOCATIONS (bl, blp_tmp) |
4fa8626c | 3017 | { |
35df4500 | 3018 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
3019 | continue; |
3020 | ||
35df4500 TJB |
3021 | if (bl->inserted |
3022 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6c95b8df | 3023 | aspace, pc)) |
4fa8626c DJ |
3024 | { |
3025 | if (overlay_debugging | |
35df4500 TJB |
3026 | && section_is_overlay (bl->section) |
3027 | && !section_is_mapped (bl->section)) | |
4fa8626c DJ |
3028 | continue; /* unmapped overlay -- can't be a match */ |
3029 | else | |
3030 | return 1; | |
3031 | } | |
3032 | } | |
3033 | ||
1aafd4da | 3034 | /* Also check for software single-step breakpoints. */ |
6c95b8df | 3035 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
3036 | return 1; |
3037 | ||
4fa8626c DJ |
3038 | return 0; |
3039 | } | |
3040 | ||
9093389c PA |
3041 | int |
3042 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
3043 | CORE_ADDR addr, ULONGEST len) | |
3044 | { | |
3045 | struct breakpoint *bpt; | |
3046 | ||
3047 | ALL_BREAKPOINTS (bpt) | |
3048 | { | |
3049 | struct bp_location *loc; | |
3050 | ||
3051 | if (bpt->type != bp_hardware_watchpoint | |
3052 | && bpt->type != bp_access_watchpoint) | |
3053 | continue; | |
3054 | ||
3055 | if (!breakpoint_enabled (bpt)) | |
3056 | continue; | |
3057 | ||
3058 | for (loc = bpt->loc; loc; loc = loc->next) | |
3059 | if (loc->pspace->aspace == aspace && loc->inserted) | |
3060 | { | |
3061 | CORE_ADDR l, h; | |
3062 | ||
3063 | /* Check for intersection. */ | |
3064 | l = max (loc->address, addr); | |
3065 | h = min (loc->address + loc->length, addr + len); | |
3066 | if (l < h) | |
3067 | return 1; | |
3068 | } | |
3069 | } | |
3070 | return 0; | |
3071 | } | |
3072 | ||
075f6582 DJ |
3073 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
3074 | PC is valid for process/thread PTID. */ | |
c906108c SS |
3075 | |
3076 | int | |
6c95b8df PA |
3077 | breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc, |
3078 | ptid_t ptid) | |
c906108c | 3079 | { |
35df4500 | 3080 | struct bp_location *bl, **blp_tmp; |
4a306c9a | 3081 | /* The thread and task IDs associated to PTID, computed lazily. */ |
a6f1cd96 | 3082 | int thread = -1; |
4a306c9a | 3083 | int task = 0; |
a6f1cd96 | 3084 | |
35df4500 | 3085 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3086 | { |
35df4500 TJB |
3087 | if (bl->loc_type != bp_loc_software_breakpoint |
3088 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
3089 | continue; |
3090 | ||
35df4500 TJB |
3091 | /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */ |
3092 | if (!breakpoint_enabled (bl->owner) | |
3093 | && bl->owner->enable_state != bp_permanent) | |
a6f1cd96 JB |
3094 | continue; |
3095 | ||
f1310107 | 3096 | if (!breakpoint_location_address_match (bl, aspace, pc)) |
a6f1cd96 JB |
3097 | continue; |
3098 | ||
35df4500 | 3099 | if (bl->owner->thread != -1) |
075f6582 | 3100 | { |
a6f1cd96 JB |
3101 | /* This is a thread-specific breakpoint. Check that ptid |
3102 | matches that thread. If thread hasn't been computed yet, | |
3103 | it is now time to do so. */ | |
3104 | if (thread == -1) | |
3105 | thread = pid_to_thread_id (ptid); | |
35df4500 | 3106 | if (bl->owner->thread != thread) |
a6f1cd96 | 3107 | continue; |
075f6582 | 3108 | } |
a6f1cd96 | 3109 | |
35df4500 | 3110 | if (bl->owner->task != 0) |
4a306c9a JB |
3111 | { |
3112 | /* This is a task-specific breakpoint. Check that ptid | |
3113 | matches that task. If task hasn't been computed yet, | |
3114 | it is now time to do so. */ | |
3115 | if (task == 0) | |
3116 | task = ada_get_task_number (ptid); | |
35df4500 | 3117 | if (bl->owner->task != task) |
4a306c9a JB |
3118 | continue; |
3119 | } | |
3120 | ||
a6f1cd96 | 3121 | if (overlay_debugging |
35df4500 TJB |
3122 | && section_is_overlay (bl->section) |
3123 | && !section_is_mapped (bl->section)) | |
a6f1cd96 JB |
3124 | continue; /* unmapped overlay -- can't be a match */ |
3125 | ||
3126 | return 1; | |
c5aa993b | 3127 | } |
c906108c SS |
3128 | |
3129 | return 0; | |
3130 | } | |
c906108c | 3131 | \f |
c5aa993b | 3132 | |
c906108c SS |
3133 | /* bpstat stuff. External routines' interfaces are documented |
3134 | in breakpoint.h. */ | |
3135 | ||
3136 | int | |
fba45db2 | 3137 | ep_is_catchpoint (struct breakpoint *ep) |
c906108c | 3138 | { |
533be4dd | 3139 | return (ep->type == bp_catchpoint); |
c906108c SS |
3140 | } |
3141 | ||
f431efe5 PA |
3142 | /* Frees any storage that is part of a bpstat. Does not walk the |
3143 | 'next' chain. */ | |
3144 | ||
3145 | static void | |
198757a8 VP |
3146 | bpstat_free (bpstat bs) |
3147 | { | |
3148 | if (bs->old_val != NULL) | |
3149 | value_free (bs->old_val); | |
9add0f1b | 3150 | decref_counted_command_line (&bs->commands); |
f431efe5 | 3151 | decref_bp_location (&bs->bp_location_at); |
198757a8 VP |
3152 | xfree (bs); |
3153 | } | |
3154 | ||
c906108c SS |
3155 | /* Clear a bpstat so that it says we are not at any breakpoint. |
3156 | Also free any storage that is part of a bpstat. */ | |
3157 | ||
3158 | void | |
fba45db2 | 3159 | bpstat_clear (bpstat *bsp) |
c906108c SS |
3160 | { |
3161 | bpstat p; | |
3162 | bpstat q; | |
3163 | ||
3164 | if (bsp == 0) | |
3165 | return; | |
3166 | p = *bsp; | |
3167 | while (p != NULL) | |
3168 | { | |
3169 | q = p->next; | |
198757a8 | 3170 | bpstat_free (p); |
c906108c SS |
3171 | p = q; |
3172 | } | |
3173 | *bsp = NULL; | |
3174 | } | |
3175 | ||
3176 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
3177 | is part of the bpstat is copied as well. */ | |
3178 | ||
3179 | bpstat | |
fba45db2 | 3180 | bpstat_copy (bpstat bs) |
c906108c SS |
3181 | { |
3182 | bpstat p = NULL; | |
3183 | bpstat tmp; | |
3184 | bpstat retval = NULL; | |
3185 | ||
3186 | if (bs == NULL) | |
3187 | return bs; | |
3188 | ||
3189 | for (; bs != NULL; bs = bs->next) | |
3190 | { | |
3191 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
3192 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 3193 | incref_counted_command_line (tmp->commands); |
f431efe5 | 3194 | incref_bp_location (tmp->bp_location_at); |
31cc81e9 | 3195 | if (bs->old_val != NULL) |
3c3185ac JK |
3196 | { |
3197 | tmp->old_val = value_copy (bs->old_val); | |
3198 | release_value (tmp->old_val); | |
3199 | } | |
31cc81e9 | 3200 | |
c906108c SS |
3201 | if (p == NULL) |
3202 | /* This is the first thing in the chain. */ | |
3203 | retval = tmp; | |
3204 | else | |
3205 | p->next = tmp; | |
3206 | p = tmp; | |
3207 | } | |
3208 | p->next = NULL; | |
3209 | return retval; | |
3210 | } | |
3211 | ||
4a64f543 | 3212 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
3213 | |
3214 | bpstat | |
fba45db2 | 3215 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 3216 | { |
c5aa993b JM |
3217 | if (bsp == NULL) |
3218 | return NULL; | |
c906108c | 3219 | |
c5aa993b JM |
3220 | for (; bsp != NULL; bsp = bsp->next) |
3221 | { | |
f431efe5 | 3222 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
3223 | return bsp; |
3224 | } | |
c906108c SS |
3225 | return NULL; |
3226 | } | |
3227 | ||
4a64f543 MS |
3228 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
3229 | stopped at. *BSP upon return is a bpstat which points to the | |
3230 | remaining breakpoints stopped at (but which is not guaranteed to be | |
3231 | good for anything but further calls to bpstat_num). | |
3232 | ||
8671a17b PA |
3233 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
3234 | Return -1 if stopped at a breakpoint that has been deleted since | |
3235 | we set it. | |
3236 | Return 1 otherwise. */ | |
c906108c SS |
3237 | |
3238 | int | |
8671a17b | 3239 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
3240 | { |
3241 | struct breakpoint *b; | |
3242 | ||
3243 | if ((*bsp) == NULL) | |
3244 | return 0; /* No more breakpoint values */ | |
8671a17b | 3245 | |
4a64f543 MS |
3246 | /* We assume we'll never have several bpstats that correspond to a |
3247 | single breakpoint -- otherwise, this function might return the | |
3248 | same number more than once and this will look ugly. */ | |
f431efe5 | 3249 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
3250 | *bsp = (*bsp)->next; |
3251 | if (b == NULL) | |
3252 | return -1; /* breakpoint that's been deleted since */ | |
3253 | ||
3254 | *num = b->number; /* We have its number */ | |
3255 | return 1; | |
c906108c SS |
3256 | } |
3257 | ||
e93ca019 | 3258 | /* See breakpoint.h. */ |
c906108c SS |
3259 | |
3260 | void | |
e93ca019 | 3261 | bpstat_clear_actions (void) |
c906108c | 3262 | { |
e93ca019 JK |
3263 | struct thread_info *tp; |
3264 | bpstat bs; | |
3265 | ||
3266 | if (ptid_equal (inferior_ptid, null_ptid)) | |
3267 | return; | |
3268 | ||
3269 | tp = find_thread_ptid (inferior_ptid); | |
3270 | if (tp == NULL) | |
3271 | return; | |
3272 | ||
3273 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) | |
c906108c | 3274 | { |
9add0f1b | 3275 | decref_counted_command_line (&bs->commands); |
abf85f46 | 3276 | |
c906108c SS |
3277 | if (bs->old_val != NULL) |
3278 | { | |
3279 | value_free (bs->old_val); | |
3280 | bs->old_val = NULL; | |
3281 | } | |
3282 | } | |
3283 | } | |
3284 | ||
f3b1572e PA |
3285 | /* Called when a command is about to proceed the inferior. */ |
3286 | ||
3287 | static void | |
3288 | breakpoint_about_to_proceed (void) | |
3289 | { | |
3290 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
3291 | { | |
3292 | struct thread_info *tp = inferior_thread (); | |
3293 | ||
3294 | /* Allow inferior function calls in breakpoint commands to not | |
3295 | interrupt the command list. When the call finishes | |
3296 | successfully, the inferior will be standing at the same | |
3297 | breakpoint as if nothing happened. */ | |
16c381f0 | 3298 | if (tp->control.in_infcall) |
f3b1572e PA |
3299 | return; |
3300 | } | |
3301 | ||
3302 | breakpoint_proceeded = 1; | |
3303 | } | |
3304 | ||
4a64f543 MS |
3305 | /* Stub for cleaning up our state if we error-out of a breakpoint |
3306 | command. */ | |
c906108c | 3307 | static void |
4efb68b1 | 3308 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
3309 | { |
3310 | executing_breakpoint_commands = 0; | |
3311 | } | |
3312 | ||
abf85f46 JK |
3313 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
3314 | or its equivalent. */ | |
3315 | ||
3316 | static int | |
3317 | command_line_is_silent (struct command_line *cmd) | |
3318 | { | |
3319 | return cmd && (strcmp ("silent", cmd->line) == 0 | |
3320 | || (xdb_commands && strcmp ("Q", cmd->line) == 0)); | |
3321 | } | |
3322 | ||
4a64f543 MS |
3323 | /* Execute all the commands associated with all the breakpoints at |
3324 | this location. Any of these commands could cause the process to | |
3325 | proceed beyond this point, etc. We look out for such changes by | |
3326 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 3327 | |
347bddb7 PA |
3328 | Returns true if a breakpoint command resumed the inferior. In that |
3329 | case, it is the caller's responsibility to recall it again with the | |
3330 | bpstat of the current thread. */ | |
3331 | ||
3332 | static int | |
3333 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
3334 | { |
3335 | bpstat bs; | |
3336 | struct cleanup *old_chain; | |
347bddb7 | 3337 | int again = 0; |
c906108c SS |
3338 | |
3339 | /* Avoid endless recursion if a `source' command is contained | |
3340 | in bs->commands. */ | |
3341 | if (executing_breakpoint_commands) | |
347bddb7 | 3342 | return 0; |
c906108c SS |
3343 | |
3344 | executing_breakpoint_commands = 1; | |
3345 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
3346 | ||
cf6c5ffb TT |
3347 | prevent_dont_repeat (); |
3348 | ||
4a64f543 | 3349 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
3350 | bs = *bsp; |
3351 | ||
3352 | breakpoint_proceeded = 0; | |
3353 | for (; bs != NULL; bs = bs->next) | |
3354 | { | |
9add0f1b | 3355 | struct counted_command_line *ccmd; |
6c50ab1c JB |
3356 | struct command_line *cmd; |
3357 | struct cleanup *this_cmd_tree_chain; | |
3358 | ||
3359 | /* Take ownership of the BSP's command tree, if it has one. | |
3360 | ||
3361 | The command tree could legitimately contain commands like | |
3362 | 'step' and 'next', which call clear_proceed_status, which | |
3363 | frees stop_bpstat's command tree. To make sure this doesn't | |
3364 | free the tree we're executing out from under us, we need to | |
3365 | take ownership of the tree ourselves. Since a given bpstat's | |
3366 | commands are only executed once, we don't need to copy it; we | |
3367 | can clear the pointer in the bpstat, and make sure we free | |
3368 | the tree when we're done. */ | |
9add0f1b TT |
3369 | ccmd = bs->commands; |
3370 | bs->commands = NULL; | |
abf85f46 JK |
3371 | this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd); |
3372 | cmd = ccmd ? ccmd->commands : NULL; | |
3373 | if (command_line_is_silent (cmd)) | |
3374 | { | |
3375 | /* The action has been already done by bpstat_stop_status. */ | |
3376 | cmd = cmd->next; | |
3377 | } | |
6c50ab1c | 3378 | |
c906108c SS |
3379 | while (cmd != NULL) |
3380 | { | |
3381 | execute_control_command (cmd); | |
3382 | ||
3383 | if (breakpoint_proceeded) | |
3384 | break; | |
3385 | else | |
3386 | cmd = cmd->next; | |
3387 | } | |
6c50ab1c JB |
3388 | |
3389 | /* We can free this command tree now. */ | |
3390 | do_cleanups (this_cmd_tree_chain); | |
3391 | ||
c906108c | 3392 | if (breakpoint_proceeded) |
32c1e744 VP |
3393 | { |
3394 | if (target_can_async_p ()) | |
347bddb7 PA |
3395 | /* If we are in async mode, then the target might be still |
3396 | running, not stopped at any breakpoint, so nothing for | |
3397 | us to do here -- just return to the event loop. */ | |
3398 | ; | |
32c1e744 VP |
3399 | else |
3400 | /* In sync mode, when execute_control_command returns | |
3401 | we're already standing on the next breakpoint. | |
347bddb7 PA |
3402 | Breakpoint commands for that stop were not run, since |
3403 | execute_command does not run breakpoint commands -- | |
3404 | only command_line_handler does, but that one is not | |
3405 | involved in execution of breakpoint commands. So, we | |
3406 | can now execute breakpoint commands. It should be | |
3407 | noted that making execute_command do bpstat actions is | |
3408 | not an option -- in this case we'll have recursive | |
3409 | invocation of bpstat for each breakpoint with a | |
3410 | command, and can easily blow up GDB stack. Instead, we | |
3411 | return true, which will trigger the caller to recall us | |
3412 | with the new stop_bpstat. */ | |
3413 | again = 1; | |
3414 | break; | |
32c1e744 | 3415 | } |
c906108c | 3416 | } |
c2b8ed2c | 3417 | do_cleanups (old_chain); |
347bddb7 PA |
3418 | return again; |
3419 | } | |
3420 | ||
3421 | void | |
3422 | bpstat_do_actions (void) | |
3423 | { | |
353d1d73 JK |
3424 | struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup (); |
3425 | ||
347bddb7 PA |
3426 | /* Do any commands attached to breakpoint we are stopped at. */ |
3427 | while (!ptid_equal (inferior_ptid, null_ptid) | |
3428 | && target_has_execution | |
3429 | && !is_exited (inferior_ptid) | |
3430 | && !is_executing (inferior_ptid)) | |
3431 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
3432 | and only return when it is stopped at the next breakpoint, we | |
3433 | keep doing breakpoint actions until it returns false to | |
3434 | indicate the inferior was not resumed. */ | |
16c381f0 | 3435 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
347bddb7 | 3436 | break; |
353d1d73 JK |
3437 | |
3438 | discard_cleanups (cleanup_if_error); | |
c906108c SS |
3439 | } |
3440 | ||
fa4727a6 DJ |
3441 | /* Print out the (old or new) value associated with a watchpoint. */ |
3442 | ||
3443 | static void | |
3444 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
3445 | { | |
3446 | if (val == NULL) | |
3447 | fprintf_unfiltered (stream, _("<unreadable>")); | |
3448 | else | |
79a45b7d TT |
3449 | { |
3450 | struct value_print_options opts; | |
3451 | get_user_print_options (&opts); | |
3452 | value_print (val, stream, &opts); | |
3453 | } | |
fa4727a6 DJ |
3454 | } |
3455 | ||
e514a9d6 | 3456 | /* Generic routine for printing messages indicating why we |
4a64f543 | 3457 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
3458 | 'print_it' in the bpstat structure. Under some circumstances we |
3459 | may decide not to print anything here and delegate the task to | |
4a64f543 | 3460 | normal_stop(). */ |
e514a9d6 JM |
3461 | |
3462 | static enum print_stop_action | |
3463 | print_bp_stop_message (bpstat bs) | |
3464 | { | |
3465 | switch (bs->print_it) | |
3466 | { | |
3467 | case print_it_noop: | |
4a64f543 | 3468 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
3469 | return PRINT_UNKNOWN; |
3470 | break; | |
3471 | ||
3472 | case print_it_done: | |
3473 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 3474 | relevant messages. */ |
e514a9d6 JM |
3475 | return PRINT_SRC_AND_LOC; |
3476 | break; | |
3477 | ||
3478 | case print_it_normal: | |
4f8d1dc6 | 3479 | { |
f431efe5 PA |
3480 | struct breakpoint *b = bs->breakpoint_at; |
3481 | ||
1a6a67de TJB |
3482 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
3483 | which has since been deleted. */ | |
3484 | if (b == NULL) | |
3485 | return PRINT_UNKNOWN; | |
3486 | ||
348d480f PA |
3487 | /* Normal case. Call the breakpoint's print_it method. */ |
3488 | return b->ops->print_it (bs); | |
4f8d1dc6 | 3489 | } |
348d480f | 3490 | break; |
3086aeae | 3491 | |
e514a9d6 | 3492 | default: |
8e65ff28 | 3493 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 3494 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 3495 | break; |
c906108c | 3496 | } |
c906108c SS |
3497 | } |
3498 | ||
edcc5120 TT |
3499 | /* A helper function that prints a shared library stopped event. */ |
3500 | ||
3501 | static void | |
3502 | print_solib_event (int is_catchpoint) | |
3503 | { | |
3504 | int any_deleted | |
3505 | = !VEC_empty (char_ptr, current_program_space->deleted_solibs); | |
3506 | int any_added | |
3507 | = !VEC_empty (so_list_ptr, current_program_space->added_solibs); | |
3508 | ||
3509 | if (!is_catchpoint) | |
3510 | { | |
3511 | if (any_added || any_deleted) | |
3512 | ui_out_text (current_uiout, | |
3513 | _("Stopped due to shared library event:\n")); | |
3514 | else | |
3515 | ui_out_text (current_uiout, | |
3516 | _("Stopped due to shared library event (no " | |
3517 | "libraries added or removed)\n")); | |
3518 | } | |
3519 | ||
3520 | if (ui_out_is_mi_like_p (current_uiout)) | |
3521 | ui_out_field_string (current_uiout, "reason", | |
3522 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); | |
3523 | ||
3524 | if (any_deleted) | |
3525 | { | |
3526 | struct cleanup *cleanup; | |
3527 | char *name; | |
3528 | int ix; | |
3529 | ||
3530 | ui_out_text (current_uiout, _(" Inferior unloaded ")); | |
3531 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
3532 | "removed"); | |
3533 | for (ix = 0; | |
3534 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
3535 | ix, name); | |
3536 | ++ix) | |
3537 | { | |
3538 | if (ix > 0) | |
3539 | ui_out_text (current_uiout, " "); | |
3540 | ui_out_field_string (current_uiout, "library", name); | |
3541 | ui_out_text (current_uiout, "\n"); | |
3542 | } | |
3543 | ||
3544 | do_cleanups (cleanup); | |
3545 | } | |
3546 | ||
3547 | if (any_added) | |
3548 | { | |
3549 | struct so_list *iter; | |
3550 | int ix; | |
3551 | struct cleanup *cleanup; | |
3552 | ||
3553 | ui_out_text (current_uiout, _(" Inferior loaded ")); | |
3554 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
3555 | "added"); | |
3556 | for (ix = 0; | |
3557 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
3558 | ix, iter); | |
3559 | ++ix) | |
3560 | { | |
3561 | if (ix > 0) | |
3562 | ui_out_text (current_uiout, " "); | |
3563 | ui_out_field_string (current_uiout, "library", iter->so_name); | |
3564 | ui_out_text (current_uiout, "\n"); | |
3565 | } | |
3566 | ||
3567 | do_cleanups (cleanup); | |
3568 | } | |
3569 | } | |
3570 | ||
e514a9d6 JM |
3571 | /* Print a message indicating what happened. This is called from |
3572 | normal_stop(). The input to this routine is the head of the bpstat | |
36dfb11c TT |
3573 | list - a list of the eventpoints that caused this stop. KIND is |
3574 | the target_waitkind for the stopping event. This | |
e514a9d6 JM |
3575 | routine calls the generic print routine for printing a message |
3576 | about reasons for stopping. This will print (for example) the | |
3577 | "Breakpoint n," part of the output. The return value of this | |
3578 | routine is one of: | |
c906108c | 3579 | |
4a64f543 | 3580 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 3581 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 3582 | code to print the location. An example is |
c5aa993b JM |
3583 | "Breakpoint 1, " which should be followed by |
3584 | the location. | |
917317f4 | 3585 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
3586 | to also print the location part of the message. |
3587 | An example is the catch/throw messages, which | |
4a64f543 | 3588 | don't require a location appended to the end. |
917317f4 | 3589 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 3590 | further info to be printed. */ |
c906108c | 3591 | |
917317f4 | 3592 | enum print_stop_action |
36dfb11c | 3593 | bpstat_print (bpstat bs, int kind) |
c906108c SS |
3594 | { |
3595 | int val; | |
c5aa993b | 3596 | |
c906108c | 3597 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
3598 | (Currently all watchpoints go on the bpstat whether hit or not. |
3599 | That probably could (should) be changed, provided care is taken | |
c906108c | 3600 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
3601 | for (; bs; bs = bs->next) |
3602 | { | |
3603 | val = print_bp_stop_message (bs); | |
3604 | if (val == PRINT_SRC_ONLY | |
3605 | || val == PRINT_SRC_AND_LOC | |
3606 | || val == PRINT_NOTHING) | |
3607 | return val; | |
3608 | } | |
c906108c | 3609 | |
36dfb11c TT |
3610 | /* If we had hit a shared library event breakpoint, |
3611 | print_bp_stop_message would print out this message. If we hit an | |
3612 | OS-level shared library event, do the same thing. */ | |
3613 | if (kind == TARGET_WAITKIND_LOADED) | |
3614 | { | |
edcc5120 | 3615 | print_solib_event (0); |
36dfb11c TT |
3616 | return PRINT_NOTHING; |
3617 | } | |
3618 | ||
e514a9d6 | 3619 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 3620 | with and nothing was printed. */ |
917317f4 | 3621 | return PRINT_UNKNOWN; |
c906108c SS |
3622 | } |
3623 | ||
4a64f543 MS |
3624 | /* Evaluate the expression EXP and return 1 if value is zero. This is |
3625 | used inside a catch_errors to evaluate the breakpoint condition. | |
3626 | The argument is a "struct expression *" that has been cast to a | |
3627 | "char *" to make it pass through catch_errors. */ | |
c906108c SS |
3628 | |
3629 | static int | |
4efb68b1 | 3630 | breakpoint_cond_eval (void *exp) |
c906108c | 3631 | { |
278cd55f | 3632 | struct value *mark = value_mark (); |
c5aa993b | 3633 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 3634 | |
c906108c SS |
3635 | value_free_to_mark (mark); |
3636 | return i; | |
3637 | } | |
3638 | ||
5760d0ab | 3639 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c SS |
3640 | |
3641 | static bpstat | |
5760d0ab | 3642 | bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) |
c906108c SS |
3643 | { |
3644 | bpstat bs; | |
3645 | ||
3646 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
5760d0ab JK |
3647 | bs->next = NULL; |
3648 | **bs_link_pointer = bs; | |
3649 | *bs_link_pointer = &bs->next; | |
f431efe5 PA |
3650 | bs->breakpoint_at = bl->owner; |
3651 | bs->bp_location_at = bl; | |
3652 | incref_bp_location (bl); | |
c906108c SS |
3653 | /* If the condition is false, etc., don't do the commands. */ |
3654 | bs->commands = NULL; | |
3655 | bs->old_val = NULL; | |
3656 | bs->print_it = print_it_normal; | |
3657 | return bs; | |
3658 | } | |
3659 | \f | |
d983da9c DJ |
3660 | /* The target has stopped with waitstatus WS. Check if any hardware |
3661 | watchpoints have triggered, according to the target. */ | |
3662 | ||
3663 | int | |
3664 | watchpoints_triggered (struct target_waitstatus *ws) | |
3665 | { | |
d92524f1 | 3666 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
3667 | CORE_ADDR addr; |
3668 | struct breakpoint *b; | |
3669 | ||
3670 | if (!stopped_by_watchpoint) | |
3671 | { | |
3672 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
3673 | as not triggered. */ | |
3674 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3675 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
3676 | { |
3677 | struct watchpoint *w = (struct watchpoint *) b; | |
3678 | ||
3679 | w->watchpoint_triggered = watch_triggered_no; | |
3680 | } | |
d983da9c DJ |
3681 | |
3682 | return 0; | |
3683 | } | |
3684 | ||
3685 | if (!target_stopped_data_address (¤t_target, &addr)) | |
3686 | { | |
3687 | /* We were stopped by a watchpoint, but we don't know where. | |
3688 | Mark all watchpoints as unknown. */ | |
3689 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3690 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
3691 | { |
3692 | struct watchpoint *w = (struct watchpoint *) b; | |
3693 | ||
3694 | w->watchpoint_triggered = watch_triggered_unknown; | |
3695 | } | |
d983da9c DJ |
3696 | |
3697 | return stopped_by_watchpoint; | |
3698 | } | |
3699 | ||
3700 | /* The target could report the data address. Mark watchpoints | |
3701 | affected by this data address as triggered, and all others as not | |
3702 | triggered. */ | |
3703 | ||
3704 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3705 | if (is_hardware_watchpoint (b)) |
d983da9c | 3706 | { |
3a5c3e22 | 3707 | struct watchpoint *w = (struct watchpoint *) b; |
a5606eee | 3708 | struct bp_location *loc; |
d983da9c | 3709 | |
3a5c3e22 | 3710 | w->watchpoint_triggered = watch_triggered_no; |
a5606eee | 3711 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 | 3712 | { |
3a5c3e22 | 3713 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 3714 | { |
3a5c3e22 PA |
3715 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
3716 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
3717 | |
3718 | if (newaddr == start) | |
3719 | { | |
3a5c3e22 | 3720 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
3721 | break; |
3722 | } | |
3723 | } | |
3724 | /* Exact match not required. Within range is sufficient. */ | |
3725 | else if (target_watchpoint_addr_within_range (¤t_target, | |
3726 | addr, loc->address, | |
3727 | loc->length)) | |
3728 | { | |
3a5c3e22 | 3729 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
3730 | break; |
3731 | } | |
3732 | } | |
d983da9c DJ |
3733 | } |
3734 | ||
3735 | return 1; | |
3736 | } | |
3737 | ||
c906108c SS |
3738 | /* Possible return values for watchpoint_check (this can't be an enum |
3739 | because of check_errors). */ | |
3740 | /* The watchpoint has been deleted. */ | |
3741 | #define WP_DELETED 1 | |
3742 | /* The value has changed. */ | |
3743 | #define WP_VALUE_CHANGED 2 | |
3744 | /* The value has not changed. */ | |
3745 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
3746 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
3747 | #define WP_IGNORE 4 | |
c906108c SS |
3748 | |
3749 | #define BP_TEMPFLAG 1 | |
3750 | #define BP_HARDWAREFLAG 2 | |
3751 | ||
4a64f543 MS |
3752 | /* Evaluate watchpoint condition expression and check if its value |
3753 | changed. | |
553e4c11 JB |
3754 | |
3755 | P should be a pointer to struct bpstat, but is defined as a void * | |
3756 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
3757 | |
3758 | static int | |
4efb68b1 | 3759 | watchpoint_check (void *p) |
c906108c SS |
3760 | { |
3761 | bpstat bs = (bpstat) p; | |
3a5c3e22 | 3762 | struct watchpoint *b; |
c906108c SS |
3763 | struct frame_info *fr; |
3764 | int within_current_scope; | |
3765 | ||
f431efe5 | 3766 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 3767 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 3768 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 3769 | |
f6bc2008 PA |
3770 | /* If this is a local watchpoint, we only want to check if the |
3771 | watchpoint frame is in scope if the current thread is the thread | |
3772 | that was used to create the watchpoint. */ | |
3773 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 3774 | return WP_IGNORE; |
f6bc2008 | 3775 | |
c906108c SS |
3776 | if (b->exp_valid_block == NULL) |
3777 | within_current_scope = 1; | |
3778 | else | |
3779 | { | |
edb3359d DJ |
3780 | struct frame_info *frame = get_current_frame (); |
3781 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
3782 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
3783 | ||
4a64f543 MS |
3784 | /* in_function_epilogue_p() returns a non-zero value if we're |
3785 | still in the function but the stack frame has already been | |
3786 | invalidated. Since we can't rely on the values of local | |
3787 | variables after the stack has been destroyed, we are treating | |
3788 | the watchpoint in that state as `not changed' without further | |
3789 | checking. Don't mark watchpoints as changed if the current | |
3790 | frame is in an epilogue - even if they are in some other | |
3791 | frame, our view of the stack is likely to be wrong and | |
3792 | frame_find_by_id could error out. */ | |
a0f49112 | 3793 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) |
60e1c644 | 3794 | return WP_IGNORE; |
a0f49112 | 3795 | |
101dcfbe | 3796 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 3797 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
3798 | |
3799 | /* If we've gotten confused in the unwinder, we might have | |
3800 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
3801 | if (within_current_scope) |
3802 | { | |
3803 | struct symbol *function; | |
3804 | ||
3805 | function = get_frame_function (fr); | |
3806 | if (function == NULL | |
3807 | || !contained_in (b->exp_valid_block, | |
3808 | SYMBOL_BLOCK_VALUE (function))) | |
3809 | within_current_scope = 0; | |
3810 | } | |
69fbadd5 | 3811 | |
edb3359d | 3812 | if (within_current_scope) |
c906108c SS |
3813 | /* If we end up stopping, the current frame will get selected |
3814 | in normal_stop. So this call to select_frame won't affect | |
3815 | the user. */ | |
0f7d239c | 3816 | select_frame (fr); |
c906108c | 3817 | } |
c5aa993b | 3818 | |
c906108c SS |
3819 | if (within_current_scope) |
3820 | { | |
4a64f543 MS |
3821 | /* We use value_{,free_to_}mark because it could be a *long* |
3822 | time before we return to the command level and call | |
3823 | free_all_values. We can't call free_all_values because we | |
3824 | might be in the middle of evaluating a function call. */ | |
c906108c | 3825 | |
0cf6dd15 | 3826 | int pc = 0; |
9c06b0b4 | 3827 | struct value *mark; |
fa4727a6 DJ |
3828 | struct value *new_val; |
3829 | ||
3a5c3e22 | 3830 | if (is_masked_watchpoint (&b->base)) |
9c06b0b4 TJB |
3831 | /* Since we don't know the exact trigger address (from |
3832 | stopped_data_address), just tell the user we've triggered | |
3833 | a mask watchpoint. */ | |
3834 | return WP_VALUE_CHANGED; | |
3835 | ||
3836 | mark = value_mark (); | |
0cf6dd15 | 3837 | fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL); |
218d2fc6 | 3838 | |
4a64f543 MS |
3839 | /* We use value_equal_contents instead of value_equal because |
3840 | the latter coerces an array to a pointer, thus comparing just | |
3841 | the address of the array instead of its contents. This is | |
3842 | not what we want. */ | |
fa4727a6 | 3843 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 3844 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 3845 | { |
fa4727a6 DJ |
3846 | if (new_val != NULL) |
3847 | { | |
3848 | release_value (new_val); | |
3849 | value_free_to_mark (mark); | |
3850 | } | |
c906108c SS |
3851 | bs->old_val = b->val; |
3852 | b->val = new_val; | |
fa4727a6 | 3853 | b->val_valid = 1; |
c906108c SS |
3854 | return WP_VALUE_CHANGED; |
3855 | } | |
3856 | else | |
3857 | { | |
60e1c644 | 3858 | /* Nothing changed. */ |
c906108c | 3859 | value_free_to_mark (mark); |
c906108c SS |
3860 | return WP_VALUE_NOT_CHANGED; |
3861 | } | |
3862 | } | |
3863 | else | |
3864 | { | |
79a45e25 PA |
3865 | struct ui_out *uiout = current_uiout; |
3866 | ||
c906108c | 3867 | /* This seems like the only logical thing to do because |
c5aa993b JM |
3868 | if we temporarily ignored the watchpoint, then when |
3869 | we reenter the block in which it is valid it contains | |
3870 | garbage (in the case of a function, it may have two | |
3871 | garbage values, one before and one after the prologue). | |
3872 | So we can't even detect the first assignment to it and | |
3873 | watch after that (since the garbage may or may not equal | |
3874 | the first value assigned). */ | |
348d480f PA |
3875 | /* We print all the stop information in |
3876 | breakpoint_ops->print_it, but in this case, by the time we | |
3877 | call breakpoint_ops->print_it this bp will be deleted | |
3878 | already. So we have no choice but print the information | |
3879 | here. */ | |
9dc5e2a9 | 3880 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3881 | ui_out_field_string |
3882 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 3883 | ui_out_text (uiout, "\nWatchpoint "); |
3a5c3e22 | 3884 | ui_out_field_int (uiout, "wpnum", b->base.number); |
3e43a32a MS |
3885 | ui_out_text (uiout, |
3886 | " deleted because the program has left the block in\n\ | |
8b93c638 | 3887 | which its expression is valid.\n"); |
4ce44c66 | 3888 | |
cdac0397 | 3889 | /* Make sure the watchpoint's commands aren't executed. */ |
3a5c3e22 | 3890 | decref_counted_command_line (&b->base.commands); |
d0fb5eae | 3891 | watchpoint_del_at_next_stop (b); |
c906108c SS |
3892 | |
3893 | return WP_DELETED; | |
3894 | } | |
3895 | } | |
3896 | ||
18a18393 | 3897 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
3898 | breakpoint location BL. This function does not check if we should |
3899 | stop, only if BL explains the stop. */ | |
3900 | ||
18a18393 | 3901 | static int |
6c95b8df | 3902 | bpstat_check_location (const struct bp_location *bl, |
09ac7c10 TT |
3903 | struct address_space *aspace, CORE_ADDR bp_addr, |
3904 | const struct target_waitstatus *ws) | |
18a18393 VP |
3905 | { |
3906 | struct breakpoint *b = bl->owner; | |
3907 | ||
348d480f | 3908 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
3909 | gdb_assert (b != NULL); |
3910 | ||
09ac7c10 | 3911 | return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws); |
18a18393 VP |
3912 | } |
3913 | ||
3a5c3e22 PA |
3914 | /* Determine if the watched values have actually changed, and we |
3915 | should stop. If not, set BS->stop to 0. */ | |
3916 | ||
18a18393 VP |
3917 | static void |
3918 | bpstat_check_watchpoint (bpstat bs) | |
3919 | { | |
2bdf28a0 | 3920 | const struct bp_location *bl; |
3a5c3e22 | 3921 | struct watchpoint *b; |
2bdf28a0 JK |
3922 | |
3923 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 3924 | bl = bs->bp_location_at; |
2bdf28a0 | 3925 | gdb_assert (bl != NULL); |
3a5c3e22 | 3926 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 3927 | gdb_assert (b != NULL); |
18a18393 | 3928 | |
18a18393 | 3929 | { |
18a18393 VP |
3930 | int must_check_value = 0; |
3931 | ||
3a5c3e22 | 3932 | if (b->base.type == bp_watchpoint) |
18a18393 VP |
3933 | /* For a software watchpoint, we must always check the |
3934 | watched value. */ | |
3935 | must_check_value = 1; | |
3936 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
3937 | /* We have a hardware watchpoint (read, write, or access) | |
3938 | and the target earlier reported an address watched by | |
3939 | this watchpoint. */ | |
3940 | must_check_value = 1; | |
3941 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3a5c3e22 | 3942 | && b->base.type == bp_hardware_watchpoint) |
18a18393 VP |
3943 | /* We were stopped by a hardware watchpoint, but the target could |
3944 | not report the data address. We must check the watchpoint's | |
3945 | value. Access and read watchpoints are out of luck; without | |
3946 | a data address, we can't figure it out. */ | |
3947 | must_check_value = 1; | |
3a5c3e22 | 3948 | |
18a18393 VP |
3949 | if (must_check_value) |
3950 | { | |
3e43a32a MS |
3951 | char *message |
3952 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3a5c3e22 | 3953 | b->base.number); |
18a18393 VP |
3954 | struct cleanup *cleanups = make_cleanup (xfree, message); |
3955 | int e = catch_errors (watchpoint_check, bs, message, | |
3956 | RETURN_MASK_ALL); | |
3957 | do_cleanups (cleanups); | |
3958 | switch (e) | |
3959 | { | |
3960 | case WP_DELETED: | |
3961 | /* We've already printed what needs to be printed. */ | |
3962 | bs->print_it = print_it_done; | |
3963 | /* Stop. */ | |
3964 | break; | |
60e1c644 PA |
3965 | case WP_IGNORE: |
3966 | bs->print_it = print_it_noop; | |
3967 | bs->stop = 0; | |
3968 | break; | |
18a18393 | 3969 | case WP_VALUE_CHANGED: |
3a5c3e22 | 3970 | if (b->base.type == bp_read_watchpoint) |
18a18393 | 3971 | { |
85d721b8 PA |
3972 | /* There are two cases to consider here: |
3973 | ||
4a64f543 | 3974 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
3975 | In that case, trust the target, and always report |
3976 | the watchpoint hit to the user. Even though | |
3977 | reads don't cause value changes, the value may | |
3978 | have changed since the last time it was read, and | |
3979 | since we're not trapping writes, we will not see | |
3980 | those, and as such we should ignore our notion of | |
3981 | old value. | |
3982 | ||
4a64f543 | 3983 | 2. We're watching the triggered memory for both |
85d721b8 PA |
3984 | reads and writes. There are two ways this may |
3985 | happen: | |
3986 | ||
4a64f543 | 3987 | 2.1. This is a target that can't break on data |
85d721b8 PA |
3988 | reads only, but can break on accesses (reads or |
3989 | writes), such as e.g., x86. We detect this case | |
3990 | at the time we try to insert read watchpoints. | |
3991 | ||
4a64f543 | 3992 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
3993 | watchpoints, but, the user set an access or write |
3994 | watchpoint watching the same memory as this read | |
3995 | watchpoint. | |
3996 | ||
3997 | If we're watching memory writes as well as reads, | |
3998 | ignore watchpoint hits when we find that the | |
3999 | value hasn't changed, as reads don't cause | |
4000 | changes. This still gives false positives when | |
4001 | the program writes the same value to memory as | |
4002 | what there was already in memory (we will confuse | |
4003 | it for a read), but it's much better than | |
4004 | nothing. */ | |
4005 | ||
4006 | int other_write_watchpoint = 0; | |
4007 | ||
4008 | if (bl->watchpoint_type == hw_read) | |
4009 | { | |
4010 | struct breakpoint *other_b; | |
4011 | ||
4012 | ALL_BREAKPOINTS (other_b) | |
3a5c3e22 PA |
4013 | if (other_b->type == bp_hardware_watchpoint |
4014 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 4015 | { |
3a5c3e22 PA |
4016 | struct watchpoint *other_w = |
4017 | (struct watchpoint *) other_b; | |
4018 | ||
4019 | if (other_w->watchpoint_triggered | |
4020 | == watch_triggered_yes) | |
4021 | { | |
4022 | other_write_watchpoint = 1; | |
4023 | break; | |
4024 | } | |
85d721b8 PA |
4025 | } |
4026 | } | |
4027 | ||
4028 | if (other_write_watchpoint | |
4029 | || bl->watchpoint_type == hw_access) | |
4030 | { | |
4031 | /* We're watching the same memory for writes, | |
4032 | and the value changed since the last time we | |
4033 | updated it, so this trap must be for a write. | |
4034 | Ignore it. */ | |
4035 | bs->print_it = print_it_noop; | |
4036 | bs->stop = 0; | |
4037 | } | |
18a18393 VP |
4038 | } |
4039 | break; | |
4040 | case WP_VALUE_NOT_CHANGED: | |
3a5c3e22 PA |
4041 | if (b->base.type == bp_hardware_watchpoint |
4042 | || b->base.type == bp_watchpoint) | |
18a18393 VP |
4043 | { |
4044 | /* Don't stop: write watchpoints shouldn't fire if | |
4045 | the value hasn't changed. */ | |
4046 | bs->print_it = print_it_noop; | |
4047 | bs->stop = 0; | |
4048 | } | |
4049 | /* Stop. */ | |
4050 | break; | |
4051 | default: | |
4052 | /* Can't happen. */ | |
4053 | case 0: | |
4054 | /* Error from catch_errors. */ | |
3a5c3e22 | 4055 | printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number); |
d0fb5eae | 4056 | watchpoint_del_at_next_stop (b); |
18a18393 VP |
4057 | /* We've already printed what needs to be printed. */ |
4058 | bs->print_it = print_it_done; | |
4059 | break; | |
4060 | } | |
4061 | } | |
4062 | else /* must_check_value == 0 */ | |
4063 | { | |
4064 | /* This is a case where some watchpoint(s) triggered, but | |
4065 | not at the address of this watchpoint, or else no | |
4066 | watchpoint triggered after all. So don't print | |
4067 | anything for this watchpoint. */ | |
4068 | bs->print_it = print_it_noop; | |
4069 | bs->stop = 0; | |
4070 | } | |
4071 | } | |
4072 | } | |
4073 | ||
4074 | ||
4075 | /* Check conditions (condition proper, frame, thread and ignore count) | |
4076 | of breakpoint referred to by BS. If we should not stop for this | |
4077 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 4078 | |
18a18393 VP |
4079 | static void |
4080 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
4081 | { | |
4082 | int thread_id = pid_to_thread_id (ptid); | |
2bdf28a0 JK |
4083 | const struct bp_location *bl; |
4084 | struct breakpoint *b; | |
4085 | ||
4086 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 4087 | bl = bs->bp_location_at; |
2bdf28a0 | 4088 | gdb_assert (bl != NULL); |
f431efe5 | 4089 | b = bs->breakpoint_at; |
2bdf28a0 | 4090 | gdb_assert (b != NULL); |
18a18393 VP |
4091 | |
4092 | if (frame_id_p (b->frame_id) | |
edb3359d | 4093 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 VP |
4094 | bs->stop = 0; |
4095 | else if (bs->stop) | |
4096 | { | |
4097 | int value_is_zero = 0; | |
60e1c644 PA |
4098 | struct expression *cond; |
4099 | ||
7371cf6d PM |
4100 | /* Evaluate Python breakpoints that have a "stop" |
4101 | method implemented. */ | |
4102 | if (b->py_bp_object) | |
4103 | bs->stop = gdbpy_should_stop (b->py_bp_object); | |
4104 | ||
60e1c644 | 4105 | if (is_watchpoint (b)) |
3a5c3e22 PA |
4106 | { |
4107 | struct watchpoint *w = (struct watchpoint *) b; | |
4108 | ||
4109 | cond = w->cond_exp; | |
4110 | } | |
60e1c644 PA |
4111 | else |
4112 | cond = bl->cond; | |
4113 | ||
f431efe5 | 4114 | if (cond && b->disposition != disp_del_at_next_stop) |
18a18393 | 4115 | { |
60e1c644 | 4116 | int within_current_scope = 1; |
3a5c3e22 | 4117 | struct watchpoint * w; |
60e1c644 | 4118 | |
c5bc3a77 DJ |
4119 | /* We use value_mark and value_free_to_mark because it could |
4120 | be a long time before we return to the command level and | |
4121 | call free_all_values. We can't call free_all_values | |
4122 | because we might be in the middle of evaluating a | |
4123 | function call. */ | |
4124 | struct value *mark = value_mark (); | |
4125 | ||
3a5c3e22 PA |
4126 | if (is_watchpoint (b)) |
4127 | w = (struct watchpoint *) b; | |
4128 | else | |
4129 | w = NULL; | |
4130 | ||
edb3359d DJ |
4131 | /* Need to select the frame, with all that implies so that |
4132 | the conditions will have the right context. Because we | |
4133 | use the frame, we will not see an inlined function's | |
4134 | variables when we arrive at a breakpoint at the start | |
4135 | of the inlined function; the current frame will be the | |
4136 | call site. */ | |
3a5c3e22 | 4137 | if (w == NULL || w->cond_exp_valid_block == NULL) |
60e1c644 PA |
4138 | select_frame (get_current_frame ()); |
4139 | else | |
4140 | { | |
4141 | struct frame_info *frame; | |
4142 | ||
4143 | /* For local watchpoint expressions, which particular | |
4144 | instance of a local is being watched matters, so we | |
4145 | keep track of the frame to evaluate the expression | |
4146 | in. To evaluate the condition however, it doesn't | |
4147 | really matter which instantiation of the function | |
4148 | where the condition makes sense triggers the | |
4149 | watchpoint. This allows an expression like "watch | |
4150 | global if q > 10" set in `func', catch writes to | |
4151 | global on all threads that call `func', or catch | |
4152 | writes on all recursive calls of `func' by a single | |
4153 | thread. We simply always evaluate the condition in | |
4154 | the innermost frame that's executing where it makes | |
4155 | sense to evaluate the condition. It seems | |
4156 | intuitive. */ | |
3a5c3e22 | 4157 | frame = block_innermost_frame (w->cond_exp_valid_block); |
60e1c644 PA |
4158 | if (frame != NULL) |
4159 | select_frame (frame); | |
4160 | else | |
4161 | within_current_scope = 0; | |
4162 | } | |
4163 | if (within_current_scope) | |
4164 | value_is_zero | |
4165 | = catch_errors (breakpoint_cond_eval, cond, | |
4166 | "Error in testing breakpoint condition:\n", | |
4167 | RETURN_MASK_ALL); | |
4168 | else | |
4169 | { | |
4170 | warning (_("Watchpoint condition cannot be tested " | |
4171 | "in the current scope")); | |
4172 | /* If we failed to set the right context for this | |
4173 | watchpoint, unconditionally report it. */ | |
4174 | value_is_zero = 0; | |
4175 | } | |
4a64f543 | 4176 | /* FIXME-someday, should give breakpoint #. */ |
c5bc3a77 | 4177 | value_free_to_mark (mark); |
18a18393 | 4178 | } |
60e1c644 PA |
4179 | |
4180 | if (cond && value_is_zero) | |
18a18393 VP |
4181 | { |
4182 | bs->stop = 0; | |
4183 | } | |
4184 | else if (b->thread != -1 && b->thread != thread_id) | |
4185 | { | |
4186 | bs->stop = 0; | |
4187 | } | |
4188 | else if (b->ignore_count > 0) | |
4189 | { | |
4190 | b->ignore_count--; | |
4191 | annotate_ignore_count_change (); | |
4192 | bs->stop = 0; | |
4a64f543 | 4193 | /* Increase the hit count even though we don't stop. */ |
18a18393 | 4194 | ++(b->hit_count); |
8d3788bd | 4195 | observer_notify_breakpoint_modified (b); |
18a18393 VP |
4196 | } |
4197 | } | |
4198 | } | |
4199 | ||
4200 | ||
9709f61c | 4201 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 4202 | BP_ADDR in thread PTID. |
c906108c | 4203 | |
d983da9c | 4204 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
4205 | don't understand this stop. Result is a chain of bpstat's such |
4206 | that: | |
c906108c | 4207 | |
c5aa993b | 4208 | if we don't understand the stop, the result is a null pointer. |
c906108c | 4209 | |
c5aa993b | 4210 | if we understand why we stopped, the result is not null. |
c906108c | 4211 | |
c5aa993b JM |
4212 | Each element of the chain refers to a particular breakpoint or |
4213 | watchpoint at which we have stopped. (We may have stopped for | |
4214 | several reasons concurrently.) | |
c906108c | 4215 | |
c5aa993b JM |
4216 | Each element of the chain has valid next, breakpoint_at, |
4217 | commands, FIXME??? fields. */ | |
c906108c SS |
4218 | |
4219 | bpstat | |
6c95b8df | 4220 | bpstat_stop_status (struct address_space *aspace, |
09ac7c10 TT |
4221 | CORE_ADDR bp_addr, ptid_t ptid, |
4222 | const struct target_waitstatus *ws) | |
c906108c | 4223 | { |
0d381245 | 4224 | struct breakpoint *b = NULL; |
afe38095 | 4225 | struct bp_location *bl; |
20874c92 | 4226 | struct bp_location *loc; |
5760d0ab JK |
4227 | /* First item of allocated bpstat's. */ |
4228 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 4229 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 4230 | bpstat bs; |
20874c92 | 4231 | int ix; |
429374b8 | 4232 | int need_remove_insert; |
f431efe5 | 4233 | int removed_any; |
c906108c | 4234 | |
f431efe5 PA |
4235 | /* First, build the bpstat chain with locations that explain a |
4236 | target stop, while being careful to not set the target running, | |
4237 | as that may invalidate locations (in particular watchpoint | |
4238 | locations are recreated). Resuming will happen here with | |
4239 | breakpoint conditions or watchpoint expressions that include | |
4240 | inferior function calls. */ | |
c5aa993b | 4241 | |
429374b8 JK |
4242 | ALL_BREAKPOINTS (b) |
4243 | { | |
4244 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) | |
4245 | continue; | |
a5606eee | 4246 | |
429374b8 JK |
4247 | for (bl = b->loc; bl != NULL; bl = bl->next) |
4248 | { | |
4a64f543 MS |
4249 | /* For hardware watchpoints, we look only at the first |
4250 | location. The watchpoint_check function will work on the | |
4251 | entire expression, not the individual locations. For | |
4252 | read watchpoints, the watchpoints_triggered function has | |
4253 | checked all locations already. */ | |
429374b8 JK |
4254 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
4255 | break; | |
18a18393 | 4256 | |
429374b8 JK |
4257 | if (bl->shlib_disabled) |
4258 | continue; | |
c5aa993b | 4259 | |
09ac7c10 | 4260 | if (!bpstat_check_location (bl, aspace, bp_addr, ws)) |
429374b8 | 4261 | continue; |
c5aa993b | 4262 | |
4a64f543 MS |
4263 | /* Come here if it's a watchpoint, or if the break address |
4264 | matches. */ | |
c5aa993b | 4265 | |
4a64f543 MS |
4266 | bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to |
4267 | explain stop. */ | |
c5aa993b | 4268 | |
f431efe5 PA |
4269 | /* Assume we stop. Should we find a watchpoint that is not |
4270 | actually triggered, or if the condition of the breakpoint | |
4271 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
4272 | bs->stop = 1; |
4273 | bs->print = 1; | |
d983da9c | 4274 | |
f431efe5 PA |
4275 | /* If this is a scope breakpoint, mark the associated |
4276 | watchpoint as triggered so that we will handle the | |
4277 | out-of-scope event. We'll get to the watchpoint next | |
4278 | iteration. */ | |
d0fb5eae | 4279 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
4280 | { |
4281 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
4282 | ||
4283 | w->watchpoint_triggered = watch_triggered_yes; | |
4284 | } | |
f431efe5 PA |
4285 | } |
4286 | } | |
4287 | ||
4288 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
4289 | { | |
f1310107 | 4290 | if (breakpoint_location_address_match (loc, aspace, bp_addr)) |
f431efe5 | 4291 | { |
5760d0ab | 4292 | bs = bpstat_alloc (loc, &bs_link); |
f431efe5 PA |
4293 | /* For hits of moribund locations, we should just proceed. */ |
4294 | bs->stop = 0; | |
4295 | bs->print = 0; | |
4296 | bs->print_it = print_it_noop; | |
4297 | } | |
4298 | } | |
4299 | ||
edcc5120 TT |
4300 | /* A bit of special processing for shlib breakpoints. We need to |
4301 | process solib loading here, so that the lists of loaded and | |
4302 | unloaded libraries are correct before we handle "catch load" and | |
4303 | "catch unload". */ | |
4304 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
4305 | { | |
5d268276 | 4306 | if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event) |
edcc5120 TT |
4307 | { |
4308 | handle_solib_event (); | |
4309 | break; | |
4310 | } | |
4311 | } | |
4312 | ||
f431efe5 PA |
4313 | /* Now go through the locations that caused the target to stop, and |
4314 | check whether we're interested in reporting this stop to higher | |
4315 | layers, or whether we should resume the target transparently. */ | |
4316 | ||
4317 | removed_any = 0; | |
4318 | ||
5760d0ab | 4319 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
4320 | { |
4321 | if (!bs->stop) | |
4322 | continue; | |
4323 | ||
f431efe5 | 4324 | b = bs->breakpoint_at; |
348d480f PA |
4325 | b->ops->check_status (bs); |
4326 | if (bs->stop) | |
28010a5d | 4327 | { |
348d480f | 4328 | bpstat_check_breakpoint_conditions (bs, ptid); |
f431efe5 | 4329 | |
429374b8 JK |
4330 | if (bs->stop) |
4331 | { | |
4332 | ++(b->hit_count); | |
8d3788bd | 4333 | observer_notify_breakpoint_modified (b); |
c906108c | 4334 | |
4a64f543 | 4335 | /* We will stop here. */ |
429374b8 JK |
4336 | if (b->disposition == disp_disable) |
4337 | { | |
4338 | if (b->enable_state != bp_permanent) | |
4339 | b->enable_state = bp_disabled; | |
f431efe5 | 4340 | removed_any = 1; |
429374b8 JK |
4341 | } |
4342 | if (b->silent) | |
4343 | bs->print = 0; | |
4344 | bs->commands = b->commands; | |
9add0f1b | 4345 | incref_counted_command_line (bs->commands); |
abf85f46 JK |
4346 | if (command_line_is_silent (bs->commands |
4347 | ? bs->commands->commands : NULL)) | |
4348 | bs->print = 0; | |
429374b8 JK |
4349 | } |
4350 | ||
348d480f | 4351 | } |
a9b3a50f PA |
4352 | |
4353 | /* Print nothing for this entry if we don't stop or don't | |
4354 | print. */ | |
4355 | if (!bs->stop || !bs->print) | |
4356 | bs->print_it = print_it_noop; | |
429374b8 | 4357 | } |
876fa593 | 4358 | |
d983da9c DJ |
4359 | /* If we aren't stopping, the value of some hardware watchpoint may |
4360 | not have changed, but the intermediate memory locations we are | |
4361 | watching may have. Don't bother if we're stopping; this will get | |
4362 | done later. */ | |
d832cb68 | 4363 | need_remove_insert = 0; |
5760d0ab JK |
4364 | if (! bpstat_causes_stop (bs_head)) |
4365 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 4366 | if (!bs->stop |
f431efe5 PA |
4367 | && bs->breakpoint_at |
4368 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 4369 | { |
3a5c3e22 PA |
4370 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
4371 | ||
4372 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 4373 | need_remove_insert = 1; |
d983da9c DJ |
4374 | } |
4375 | ||
d832cb68 | 4376 | if (need_remove_insert) |
2d134ed3 | 4377 | update_global_location_list (1); |
f431efe5 PA |
4378 | else if (removed_any) |
4379 | update_global_location_list (0); | |
d832cb68 | 4380 | |
5760d0ab | 4381 | return bs_head; |
c906108c | 4382 | } |
628fe4e4 JK |
4383 | |
4384 | static void | |
4385 | handle_jit_event (void) | |
4386 | { | |
4387 | struct frame_info *frame; | |
4388 | struct gdbarch *gdbarch; | |
4389 | ||
4390 | /* Switch terminal for any messages produced by | |
4391 | breakpoint_re_set. */ | |
4392 | target_terminal_ours_for_output (); | |
4393 | ||
4394 | frame = get_current_frame (); | |
4395 | gdbarch = get_frame_arch (frame); | |
4396 | ||
4397 | jit_event_handler (gdbarch); | |
4398 | ||
4399 | target_terminal_inferior (); | |
4400 | } | |
4401 | ||
edcc5120 TT |
4402 | /* Handle an solib event by calling solib_add. */ |
4403 | ||
4404 | void | |
4405 | handle_solib_event (void) | |
4406 | { | |
4407 | clear_program_space_solib_cache (current_inferior ()->pspace); | |
4408 | ||
4409 | /* Check for any newly added shared libraries if we're supposed to | |
4410 | be adding them automatically. Switch terminal for any messages | |
4411 | produced by breakpoint_re_set. */ | |
4412 | target_terminal_ours_for_output (); | |
4413 | #ifdef SOLIB_ADD | |
4414 | SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add); | |
4415 | #else | |
4416 | solib_add (NULL, 0, ¤t_target, auto_solib_add); | |
4417 | #endif | |
4418 | target_terminal_inferior (); | |
4419 | } | |
4420 | ||
628fe4e4 JK |
4421 | /* Prepare WHAT final decision for infrun. */ |
4422 | ||
4423 | /* Decide what infrun needs to do with this bpstat. */ | |
4424 | ||
c906108c | 4425 | struct bpstat_what |
0e30163f | 4426 | bpstat_what (bpstat bs_head) |
c906108c | 4427 | { |
c906108c | 4428 | struct bpstat_what retval; |
628fe4e4 | 4429 | int jit_event = 0; |
0e30163f | 4430 | bpstat bs; |
c906108c | 4431 | |
628fe4e4 | 4432 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 4433 | retval.call_dummy = STOP_NONE; |
186c406b | 4434 | retval.is_longjmp = 0; |
628fe4e4 | 4435 | |
0e30163f | 4436 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 4437 | { |
628fe4e4 JK |
4438 | /* Extract this BS's action. After processing each BS, we check |
4439 | if its action overrides all we've seem so far. */ | |
4440 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
4441 | enum bptype bptype; | |
4442 | ||
c906108c | 4443 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
4444 | { |
4445 | /* I suspect this can happen if it was a momentary | |
4446 | breakpoint which has since been deleted. */ | |
4447 | bptype = bp_none; | |
4448 | } | |
20874c92 | 4449 | else |
f431efe5 | 4450 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
4451 | |
4452 | switch (bptype) | |
c906108c SS |
4453 | { |
4454 | case bp_none: | |
628fe4e4 | 4455 | break; |
c906108c SS |
4456 | case bp_breakpoint: |
4457 | case bp_hardware_breakpoint: | |
4458 | case bp_until: | |
4459 | case bp_finish: | |
a9b3a50f | 4460 | case bp_shlib_event: |
c906108c SS |
4461 | if (bs->stop) |
4462 | { | |
4463 | if (bs->print) | |
628fe4e4 | 4464 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 4465 | else |
628fe4e4 | 4466 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
4467 | } |
4468 | else | |
628fe4e4 | 4469 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
4470 | break; |
4471 | case bp_watchpoint: | |
4472 | case bp_hardware_watchpoint: | |
4473 | case bp_read_watchpoint: | |
4474 | case bp_access_watchpoint: | |
4475 | if (bs->stop) | |
4476 | { | |
4477 | if (bs->print) | |
628fe4e4 | 4478 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 4479 | else |
628fe4e4 | 4480 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
4481 | } |
4482 | else | |
628fe4e4 JK |
4483 | { |
4484 | /* There was a watchpoint, but we're not stopping. | |
4485 | This requires no further action. */ | |
4486 | } | |
c906108c SS |
4487 | break; |
4488 | case bp_longjmp: | |
186c406b | 4489 | case bp_exception: |
628fe4e4 | 4490 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; |
186c406b | 4491 | retval.is_longjmp = bptype == bp_longjmp; |
c906108c SS |
4492 | break; |
4493 | case bp_longjmp_resume: | |
186c406b | 4494 | case bp_exception_resume: |
628fe4e4 | 4495 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; |
186c406b | 4496 | retval.is_longjmp = bptype == bp_longjmp_resume; |
c906108c SS |
4497 | break; |
4498 | case bp_step_resume: | |
4499 | if (bs->stop) | |
628fe4e4 JK |
4500 | this_action = BPSTAT_WHAT_STEP_RESUME; |
4501 | else | |
c906108c | 4502 | { |
628fe4e4 JK |
4503 | /* It is for the wrong frame. */ |
4504 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 4505 | } |
c906108c | 4506 | break; |
2c03e5be PA |
4507 | case bp_hp_step_resume: |
4508 | if (bs->stop) | |
4509 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
4510 | else | |
4511 | { | |
4512 | /* It is for the wrong frame. */ | |
4513 | this_action = BPSTAT_WHAT_SINGLE; | |
4514 | } | |
4515 | break; | |
c906108c | 4516 | case bp_watchpoint_scope: |
c4093a6a | 4517 | case bp_thread_event: |
1900040c | 4518 | case bp_overlay_event: |
0fd8e87f | 4519 | case bp_longjmp_master: |
aa7d318d | 4520 | case bp_std_terminate_master: |
186c406b | 4521 | case bp_exception_master: |
628fe4e4 | 4522 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 4523 | break; |
ce78b96d | 4524 | case bp_catchpoint: |
c5aa993b JM |
4525 | if (bs->stop) |
4526 | { | |
4527 | if (bs->print) | |
628fe4e4 | 4528 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 4529 | else |
628fe4e4 | 4530 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
4531 | } |
4532 | else | |
628fe4e4 JK |
4533 | { |
4534 | /* There was a catchpoint, but we're not stopping. | |
4535 | This requires no further action. */ | |
4536 | } | |
4537 | break; | |
628fe4e4 JK |
4538 | case bp_jit_event: |
4539 | jit_event = 1; | |
4540 | this_action = BPSTAT_WHAT_SINGLE; | |
c5aa993b | 4541 | break; |
c906108c | 4542 | case bp_call_dummy: |
53a5351d JM |
4543 | /* Make sure the action is stop (silent or noisy), |
4544 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 4545 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 4546 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
4547 | break; |
4548 | case bp_std_terminate: | |
4549 | /* Make sure the action is stop (silent or noisy), | |
4550 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 4551 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 4552 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 4553 | break; |
1042e4c0 | 4554 | case bp_tracepoint: |
7a697b8d | 4555 | case bp_fast_tracepoint: |
0fb4aa4b | 4556 | case bp_static_tracepoint: |
1042e4c0 SS |
4557 | /* Tracepoint hits should not be reported back to GDB, and |
4558 | if one got through somehow, it should have been filtered | |
4559 | out already. */ | |
4560 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 4561 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
4562 | break; |
4563 | case bp_gnu_ifunc_resolver: | |
4564 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
4565 | this_action = BPSTAT_WHAT_SINGLE; | |
4566 | break; | |
4567 | case bp_gnu_ifunc_resolver_return: | |
4568 | /* The breakpoint will be removed, execution will restart from the | |
4569 | PC of the former breakpoint. */ | |
4570 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
4571 | break; | |
628fe4e4 JK |
4572 | default: |
4573 | internal_error (__FILE__, __LINE__, | |
4574 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 4575 | } |
628fe4e4 JK |
4576 | |
4577 | retval.main_action = max (retval.main_action, this_action); | |
c906108c | 4578 | } |
628fe4e4 | 4579 | |
0e30163f JK |
4580 | /* These operations may affect the bs->breakpoint_at state so they are |
4581 | delayed after MAIN_ACTION is decided above. */ | |
4582 | ||
628fe4e4 JK |
4583 | if (jit_event) |
4584 | { | |
4585 | if (debug_infrun) | |
4586 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n"); | |
4587 | ||
4588 | handle_jit_event (); | |
4589 | } | |
4590 | ||
0e30163f JK |
4591 | for (bs = bs_head; bs != NULL; bs = bs->next) |
4592 | { | |
4593 | struct breakpoint *b = bs->breakpoint_at; | |
4594 | ||
4595 | if (b == NULL) | |
4596 | continue; | |
4597 | switch (b->type) | |
4598 | { | |
4599 | case bp_gnu_ifunc_resolver: | |
4600 | gnu_ifunc_resolver_stop (b); | |
4601 | break; | |
4602 | case bp_gnu_ifunc_resolver_return: | |
4603 | gnu_ifunc_resolver_return_stop (b); | |
4604 | break; | |
4605 | } | |
4606 | } | |
4607 | ||
c906108c SS |
4608 | return retval; |
4609 | } | |
4610 | ||
4611 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
4612 | without hardware support). This isn't related to a specific bpstat, | |
4613 | just to things like whether watchpoints are set. */ | |
4614 | ||
c5aa993b | 4615 | int |
fba45db2 | 4616 | bpstat_should_step (void) |
c906108c SS |
4617 | { |
4618 | struct breakpoint *b; | |
cc59ec59 | 4619 | |
c906108c | 4620 | ALL_BREAKPOINTS (b) |
717a8278 | 4621 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 4622 | return 1; |
c906108c SS |
4623 | return 0; |
4624 | } | |
4625 | ||
67822962 PA |
4626 | int |
4627 | bpstat_causes_stop (bpstat bs) | |
4628 | { | |
4629 | for (; bs != NULL; bs = bs->next) | |
4630 | if (bs->stop) | |
4631 | return 1; | |
4632 | ||
4633 | return 0; | |
4634 | } | |
4635 | ||
c906108c | 4636 | \f |
c5aa993b | 4637 | |
170b53b2 UW |
4638 | /* Compute a string of spaces suitable to indent the next line |
4639 | so it starts at the position corresponding to the table column | |
4640 | named COL_NAME in the currently active table of UIOUT. */ | |
4641 | ||
4642 | static char * | |
4643 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
4644 | { | |
4645 | static char wrap_indent[80]; | |
4646 | int i, total_width, width, align; | |
4647 | char *text; | |
4648 | ||
4649 | total_width = 0; | |
4650 | for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++) | |
4651 | { | |
4652 | if (strcmp (text, col_name) == 0) | |
4653 | { | |
4654 | gdb_assert (total_width < sizeof wrap_indent); | |
4655 | memset (wrap_indent, ' ', total_width); | |
4656 | wrap_indent[total_width] = 0; | |
4657 | ||
4658 | return wrap_indent; | |
4659 | } | |
4660 | ||
4661 | total_width += width + 1; | |
4662 | } | |
4663 | ||
4664 | return NULL; | |
4665 | } | |
4666 | ||
859825b8 JK |
4667 | /* Print the LOC location out of the list of B->LOC locations. */ |
4668 | ||
170b53b2 UW |
4669 | static void |
4670 | print_breakpoint_location (struct breakpoint *b, | |
4671 | struct bp_location *loc) | |
0d381245 | 4672 | { |
79a45e25 | 4673 | struct ui_out *uiout = current_uiout; |
6c95b8df PA |
4674 | struct cleanup *old_chain = save_current_program_space (); |
4675 | ||
859825b8 JK |
4676 | if (loc != NULL && loc->shlib_disabled) |
4677 | loc = NULL; | |
4678 | ||
6c95b8df PA |
4679 | if (loc != NULL) |
4680 | set_current_program_space (loc->pspace); | |
4681 | ||
56435ebe TT |
4682 | if (b->display_canonical) |
4683 | ui_out_field_string (uiout, "what", b->addr_string); | |
f8eba3c6 | 4684 | else if (loc && loc->source_file) |
0d381245 VP |
4685 | { |
4686 | struct symbol *sym | |
4687 | = find_pc_sect_function (loc->address, loc->section); | |
4688 | if (sym) | |
4689 | { | |
4690 | ui_out_text (uiout, "in "); | |
4691 | ui_out_field_string (uiout, "func", | |
4692 | SYMBOL_PRINT_NAME (sym)); | |
170b53b2 UW |
4693 | ui_out_text (uiout, " "); |
4694 | ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what")); | |
4695 | ui_out_text (uiout, "at "); | |
0d381245 | 4696 | } |
f8eba3c6 | 4697 | ui_out_field_string (uiout, "file", loc->source_file); |
0d381245 VP |
4698 | ui_out_text (uiout, ":"); |
4699 | ||
4700 | if (ui_out_is_mi_like_p (uiout)) | |
4701 | { | |
4702 | struct symtab_and_line sal = find_pc_line (loc->address, 0); | |
4703 | char *fullname = symtab_to_fullname (sal.symtab); | |
4704 | ||
4705 | if (fullname) | |
4706 | ui_out_field_string (uiout, "fullname", fullname); | |
4707 | } | |
4708 | ||
f8eba3c6 | 4709 | ui_out_field_int (uiout, "line", loc->line_number); |
0d381245 | 4710 | } |
859825b8 | 4711 | else if (loc) |
0d381245 | 4712 | { |
170b53b2 UW |
4713 | struct ui_stream *stb = ui_out_stream_new (uiout); |
4714 | struct cleanup *stb_chain = make_cleanup_ui_out_stream_delete (stb); | |
4715 | ||
22e722e1 DJ |
4716 | print_address_symbolic (loc->gdbarch, loc->address, stb->stream, |
4717 | demangle, ""); | |
0d381245 | 4718 | ui_out_field_stream (uiout, "at", stb); |
170b53b2 UW |
4719 | |
4720 | do_cleanups (stb_chain); | |
0d381245 | 4721 | } |
859825b8 JK |
4722 | else |
4723 | ui_out_field_string (uiout, "pending", b->addr_string); | |
6c95b8df PA |
4724 | |
4725 | do_cleanups (old_chain); | |
0d381245 VP |
4726 | } |
4727 | ||
269b11a2 PA |
4728 | static const char * |
4729 | bptype_string (enum bptype type) | |
c906108c | 4730 | { |
c4093a6a JM |
4731 | struct ep_type_description |
4732 | { | |
4733 | enum bptype type; | |
4734 | char *description; | |
4735 | }; | |
4736 | static struct ep_type_description bptypes[] = | |
c906108c | 4737 | { |
c5aa993b JM |
4738 | {bp_none, "?deleted?"}, |
4739 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 4740 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
4741 | {bp_until, "until"}, |
4742 | {bp_finish, "finish"}, | |
4743 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 4744 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
4745 | {bp_read_watchpoint, "read watchpoint"}, |
4746 | {bp_access_watchpoint, "acc watchpoint"}, | |
4747 | {bp_longjmp, "longjmp"}, | |
4748 | {bp_longjmp_resume, "longjmp resume"}, | |
186c406b TT |
4749 | {bp_exception, "exception"}, |
4750 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 4751 | {bp_step_resume, "step resume"}, |
2c03e5be | 4752 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
4753 | {bp_watchpoint_scope, "watchpoint scope"}, |
4754 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 4755 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 4756 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 4757 | {bp_thread_event, "thread events"}, |
1900040c | 4758 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 4759 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 4760 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 4761 | {bp_exception_master, "exception master"}, |
ce78b96d | 4762 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 4763 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 4764 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 4765 | {bp_static_tracepoint, "static tracepoint"}, |
4efc6507 | 4766 | {bp_jit_event, "jit events"}, |
0e30163f JK |
4767 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
4768 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 4769 | }; |
269b11a2 PA |
4770 | |
4771 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
4772 | || ((int) type != bptypes[(int) type].type)) | |
4773 | internal_error (__FILE__, __LINE__, | |
4774 | _("bptypes table does not describe type #%d."), | |
4775 | (int) type); | |
4776 | ||
4777 | return bptypes[(int) type].description; | |
4778 | } | |
4779 | ||
4780 | /* Print B to gdb_stdout. */ | |
4781 | ||
4782 | static void | |
4783 | print_one_breakpoint_location (struct breakpoint *b, | |
4784 | struct bp_location *loc, | |
4785 | int loc_number, | |
4786 | struct bp_location **last_loc, | |
269b11a2 PA |
4787 | int allflag) |
4788 | { | |
4789 | struct command_line *l; | |
c2c6d25f | 4790 | static char bpenables[] = "nynny"; |
c906108c | 4791 | |
79a45e25 | 4792 | struct ui_out *uiout = current_uiout; |
0d381245 VP |
4793 | int header_of_multiple = 0; |
4794 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
4795 | struct value_print_options opts; |
4796 | ||
4797 | get_user_print_options (&opts); | |
0d381245 VP |
4798 | |
4799 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
4800 | /* See comment in print_one_breakpoint concerning treatment of |
4801 | breakpoints with single disabled location. */ | |
0d381245 VP |
4802 | if (loc == NULL |
4803 | && (b->loc != NULL | |
4804 | && (b->loc->next != NULL || !b->loc->enabled))) | |
4805 | header_of_multiple = 1; | |
4806 | if (loc == NULL) | |
4807 | loc = b->loc; | |
4808 | ||
c4093a6a JM |
4809 | annotate_record (); |
4810 | ||
4811 | /* 1 */ | |
4812 | annotate_field (0); | |
0d381245 VP |
4813 | if (part_of_multiple) |
4814 | { | |
4815 | char *formatted; | |
0c6773c1 | 4816 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
4817 | ui_out_field_string (uiout, "number", formatted); |
4818 | xfree (formatted); | |
4819 | } | |
4820 | else | |
4821 | { | |
4822 | ui_out_field_int (uiout, "number", b->number); | |
4823 | } | |
c4093a6a JM |
4824 | |
4825 | /* 2 */ | |
4826 | annotate_field (1); | |
0d381245 VP |
4827 | if (part_of_multiple) |
4828 | ui_out_field_skip (uiout, "type"); | |
269b11a2 PA |
4829 | else |
4830 | ui_out_field_string (uiout, "type", bptype_string (b->type)); | |
c4093a6a JM |
4831 | |
4832 | /* 3 */ | |
4833 | annotate_field (2); | |
0d381245 VP |
4834 | if (part_of_multiple) |
4835 | ui_out_field_skip (uiout, "disp"); | |
4836 | else | |
2cec12e5 | 4837 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 4838 | |
c4093a6a JM |
4839 | |
4840 | /* 4 */ | |
4841 | annotate_field (3); | |
0d381245 | 4842 | if (part_of_multiple) |
54e52265 | 4843 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 4844 | else |
4a64f543 MS |
4845 | ui_out_field_fmt (uiout, "enabled", "%c", |
4846 | bpenables[(int) b->enable_state]); | |
54e52265 | 4847 | ui_out_spaces (uiout, 2); |
0d381245 | 4848 | |
c4093a6a JM |
4849 | |
4850 | /* 5 and 6 */ | |
3086aeae | 4851 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 4852 | { |
4a64f543 MS |
4853 | /* Although the print_one can possibly print all locations, |
4854 | calling it here is not likely to get any nice result. So, | |
4855 | make sure there's just one location. */ | |
0d381245 | 4856 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 4857 | b->ops->print_one (b, last_loc); |
0d381245 | 4858 | } |
3086aeae DJ |
4859 | else |
4860 | switch (b->type) | |
4861 | { | |
4862 | case bp_none: | |
4863 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 4864 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 4865 | break; |
c906108c | 4866 | |
3086aeae DJ |
4867 | case bp_watchpoint: |
4868 | case bp_hardware_watchpoint: | |
4869 | case bp_read_watchpoint: | |
4870 | case bp_access_watchpoint: | |
3a5c3e22 PA |
4871 | { |
4872 | struct watchpoint *w = (struct watchpoint *) b; | |
4873 | ||
4874 | /* Field 4, the address, is omitted (which makes the columns | |
4875 | not line up too nicely with the headers, but the effect | |
4876 | is relatively readable). */ | |
4877 | if (opts.addressprint) | |
4878 | ui_out_field_skip (uiout, "addr"); | |
4879 | annotate_field (5); | |
4880 | ui_out_field_string (uiout, "what", w->exp_string); | |
4881 | } | |
3086aeae DJ |
4882 | break; |
4883 | ||
3086aeae DJ |
4884 | case bp_breakpoint: |
4885 | case bp_hardware_breakpoint: | |
4886 | case bp_until: | |
4887 | case bp_finish: | |
4888 | case bp_longjmp: | |
4889 | case bp_longjmp_resume: | |
186c406b TT |
4890 | case bp_exception: |
4891 | case bp_exception_resume: | |
3086aeae | 4892 | case bp_step_resume: |
2c03e5be | 4893 | case bp_hp_step_resume: |
3086aeae DJ |
4894 | case bp_watchpoint_scope: |
4895 | case bp_call_dummy: | |
aa7d318d | 4896 | case bp_std_terminate: |
3086aeae DJ |
4897 | case bp_shlib_event: |
4898 | case bp_thread_event: | |
4899 | case bp_overlay_event: | |
0fd8e87f | 4900 | case bp_longjmp_master: |
aa7d318d | 4901 | case bp_std_terminate_master: |
186c406b | 4902 | case bp_exception_master: |
1042e4c0 | 4903 | case bp_tracepoint: |
7a697b8d | 4904 | case bp_fast_tracepoint: |
0fb4aa4b | 4905 | case bp_static_tracepoint: |
4efc6507 | 4906 | case bp_jit_event: |
0e30163f JK |
4907 | case bp_gnu_ifunc_resolver: |
4908 | case bp_gnu_ifunc_resolver_return: | |
79a45b7d | 4909 | if (opts.addressprint) |
3086aeae DJ |
4910 | { |
4911 | annotate_field (4); | |
54e52265 | 4912 | if (header_of_multiple) |
0d381245 | 4913 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 4914 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 4915 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 4916 | else |
5af949e3 UW |
4917 | ui_out_field_core_addr (uiout, "addr", |
4918 | loc->gdbarch, loc->address); | |
3086aeae DJ |
4919 | } |
4920 | annotate_field (5); | |
0d381245 | 4921 | if (!header_of_multiple) |
170b53b2 | 4922 | print_breakpoint_location (b, loc); |
0d381245 | 4923 | if (b->loc) |
a6d9a66e | 4924 | *last_loc = b->loc; |
3086aeae DJ |
4925 | break; |
4926 | } | |
c906108c | 4927 | |
6c95b8df PA |
4928 | |
4929 | /* For backward compatibility, don't display inferiors unless there | |
4930 | are several. */ | |
4931 | if (loc != NULL | |
4932 | && !header_of_multiple | |
4933 | && (allflag | |
4934 | || (!gdbarch_has_global_breakpoints (target_gdbarch) | |
4935 | && (number_of_program_spaces () > 1 | |
4936 | || number_of_inferiors () > 1) | |
4a64f543 MS |
4937 | /* LOC is for existing B, it cannot be in |
4938 | moribund_locations and thus having NULL OWNER. */ | |
6c95b8df PA |
4939 | && loc->owner->type != bp_catchpoint))) |
4940 | { | |
4941 | struct inferior *inf; | |
4942 | int first = 1; | |
4943 | ||
4944 | for (inf = inferior_list; inf != NULL; inf = inf->next) | |
4945 | { | |
4946 | if (inf->pspace == loc->pspace) | |
4947 | { | |
4948 | if (first) | |
4949 | { | |
4950 | first = 0; | |
4951 | ui_out_text (uiout, " inf "); | |
4952 | } | |
4953 | else | |
4954 | ui_out_text (uiout, ", "); | |
4955 | ui_out_text (uiout, plongest (inf->num)); | |
4956 | } | |
4957 | } | |
4958 | } | |
4959 | ||
4a306c9a | 4960 | if (!part_of_multiple) |
c4093a6a | 4961 | { |
4a306c9a JB |
4962 | if (b->thread != -1) |
4963 | { | |
4964 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 4965 | "stop only in" line a little further down. */ |
4a306c9a JB |
4966 | ui_out_text (uiout, " thread "); |
4967 | ui_out_field_int (uiout, "thread", b->thread); | |
4968 | } | |
4969 | else if (b->task != 0) | |
4970 | { | |
4971 | ui_out_text (uiout, " task "); | |
4972 | ui_out_field_int (uiout, "task", b->task); | |
4973 | } | |
c4093a6a | 4974 | } |
f1310107 | 4975 | |
8b93c638 | 4976 | ui_out_text (uiout, "\n"); |
f1310107 | 4977 | |
348d480f | 4978 | if (!part_of_multiple) |
f1310107 TJB |
4979 | b->ops->print_one_detail (b, uiout); |
4980 | ||
0d381245 | 4981 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
4982 | { |
4983 | annotate_field (6); | |
8b93c638 | 4984 | ui_out_text (uiout, "\tstop only in stack frame at "); |
e5dd4106 | 4985 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
818dd999 | 4986 | the frame ID. */ |
5af949e3 UW |
4987 | ui_out_field_core_addr (uiout, "frame", |
4988 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 4989 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
4990 | } |
4991 | ||
28010a5d | 4992 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
4993 | { |
4994 | annotate_field (7); | |
d77f58be | 4995 | if (is_tracepoint (b)) |
1042e4c0 SS |
4996 | ui_out_text (uiout, "\ttrace only if "); |
4997 | else | |
4998 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 JJ |
4999 | ui_out_field_string (uiout, "cond", b->cond_string); |
5000 | ui_out_text (uiout, "\n"); | |
5001 | } | |
5002 | ||
0d381245 | 5003 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 5004 | { |
4a64f543 | 5005 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
5006 | ui_out_text (uiout, "\tstop only in thread "); |
5007 | ui_out_field_int (uiout, "thread", b->thread); | |
5008 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
5009 | } |
5010 | ||
63c715c6 | 5011 | if (!part_of_multiple && b->hit_count) |
c4093a6a | 5012 | { |
4a64f543 | 5013 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
5014 | if (ep_is_catchpoint (b)) |
5015 | ui_out_text (uiout, "\tcatchpoint"); | |
f196051f SS |
5016 | else if (is_tracepoint (b)) |
5017 | ui_out_text (uiout, "\ttracepoint"); | |
8b93c638 JM |
5018 | else |
5019 | ui_out_text (uiout, "\tbreakpoint"); | |
5020 | ui_out_text (uiout, " already hit "); | |
5021 | ui_out_field_int (uiout, "times", b->hit_count); | |
5022 | if (b->hit_count == 1) | |
5023 | ui_out_text (uiout, " time\n"); | |
5024 | else | |
5025 | ui_out_text (uiout, " times\n"); | |
c4093a6a JM |
5026 | } |
5027 | ||
4a64f543 MS |
5028 | /* Output the count also if it is zero, but only if this is mi. |
5029 | FIXME: Should have a better test for this. */ | |
9dc5e2a9 | 5030 | if (ui_out_is_mi_like_p (uiout)) |
63c715c6 | 5031 | if (!part_of_multiple && b->hit_count == 0) |
fb40c209 | 5032 | ui_out_field_int (uiout, "times", b->hit_count); |
8b93c638 | 5033 | |
0d381245 | 5034 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
5035 | { |
5036 | annotate_field (8); | |
8b93c638 JM |
5037 | ui_out_text (uiout, "\tignore next "); |
5038 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
5039 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 5040 | } |
059fb39f | 5041 | |
f196051f SS |
5042 | if (!part_of_multiple && is_tracepoint (b)) |
5043 | { | |
5044 | struct tracepoint *tp = (struct tracepoint *) b; | |
5045 | ||
5046 | if (tp->traceframe_usage) | |
5047 | { | |
5048 | ui_out_text (uiout, "\ttrace buffer usage "); | |
5049 | ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage); | |
5050 | ui_out_text (uiout, " bytes\n"); | |
5051 | } | |
5052 | } | |
5053 | ||
9add0f1b | 5054 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 5055 | if (!part_of_multiple && l) |
c4093a6a | 5056 | { |
3b31d625 EZ |
5057 | struct cleanup *script_chain; |
5058 | ||
c4093a6a | 5059 | annotate_field (9); |
3b31d625 | 5060 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 5061 | print_command_lines (uiout, l, 4); |
3b31d625 | 5062 | do_cleanups (script_chain); |
c4093a6a | 5063 | } |
d24317b4 | 5064 | |
d9b3f62e | 5065 | if (is_tracepoint (b)) |
1042e4c0 | 5066 | { |
d9b3f62e PA |
5067 | struct tracepoint *t = (struct tracepoint *) b; |
5068 | ||
5069 | if (!part_of_multiple && t->pass_count) | |
5070 | { | |
5071 | annotate_field (10); | |
5072 | ui_out_text (uiout, "\tpass count "); | |
5073 | ui_out_field_int (uiout, "pass", t->pass_count); | |
5074 | ui_out_text (uiout, " \n"); | |
5075 | } | |
1042e4c0 SS |
5076 | } |
5077 | ||
d24317b4 VP |
5078 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
5079 | { | |
3a5c3e22 PA |
5080 | if (is_watchpoint (b)) |
5081 | { | |
5082 | struct watchpoint *w = (struct watchpoint *) b; | |
5083 | ||
5084 | ui_out_field_string (uiout, "original-location", w->exp_string); | |
5085 | } | |
5086 | else if (b->addr_string) | |
d24317b4 | 5087 | ui_out_field_string (uiout, "original-location", b->addr_string); |
d24317b4 | 5088 | } |
c4093a6a | 5089 | } |
c5aa993b | 5090 | |
0d381245 VP |
5091 | static void |
5092 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 5093 | struct bp_location **last_loc, |
6c95b8df | 5094 | int allflag) |
0d381245 | 5095 | { |
8d3788bd | 5096 | struct cleanup *bkpt_chain; |
79a45e25 | 5097 | struct ui_out *uiout = current_uiout; |
8d3788bd VP |
5098 | |
5099 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); | |
5100 | ||
12c5a436 | 5101 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); |
8d3788bd | 5102 | do_cleanups (bkpt_chain); |
0d381245 VP |
5103 | |
5104 | /* If this breakpoint has custom print function, | |
5105 | it's already printed. Otherwise, print individual | |
5106 | locations, if any. */ | |
5107 | if (b->ops == NULL || b->ops->print_one == NULL) | |
5108 | { | |
4a64f543 MS |
5109 | /* If breakpoint has a single location that is disabled, we |
5110 | print it as if it had several locations, since otherwise it's | |
5111 | hard to represent "breakpoint enabled, location disabled" | |
5112 | situation. | |
5113 | ||
5114 | Note that while hardware watchpoints have several locations | |
a3be7890 | 5115 | internally, that's not a property exposed to user. */ |
0d381245 | 5116 | if (b->loc |
a5606eee | 5117 | && !is_hardware_watchpoint (b) |
8d3788bd | 5118 | && (b->loc->next || !b->loc->enabled)) |
0d381245 VP |
5119 | { |
5120 | struct bp_location *loc; | |
5121 | int n = 1; | |
8d3788bd | 5122 | |
0d381245 | 5123 | for (loc = b->loc; loc; loc = loc->next, ++n) |
8d3788bd VP |
5124 | { |
5125 | struct cleanup *inner2 = | |
5126 | make_cleanup_ui_out_tuple_begin_end (uiout, NULL); | |
5127 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); | |
5128 | do_cleanups (inner2); | |
5129 | } | |
0d381245 VP |
5130 | } |
5131 | } | |
5132 | } | |
5133 | ||
a6d9a66e UW |
5134 | static int |
5135 | breakpoint_address_bits (struct breakpoint *b) | |
5136 | { | |
5137 | int print_address_bits = 0; | |
5138 | struct bp_location *loc; | |
5139 | ||
5140 | for (loc = b->loc; loc; loc = loc->next) | |
5141 | { | |
c7437ca6 PA |
5142 | int addr_bit; |
5143 | ||
5144 | /* Software watchpoints that aren't watching memory don't have | |
5145 | an address to print. */ | |
5146 | if (b->type == bp_watchpoint && loc->watchpoint_type == -1) | |
5147 | continue; | |
5148 | ||
5149 | addr_bit = gdbarch_addr_bit (loc->gdbarch); | |
a6d9a66e UW |
5150 | if (addr_bit > print_address_bits) |
5151 | print_address_bits = addr_bit; | |
5152 | } | |
5153 | ||
5154 | return print_address_bits; | |
5155 | } | |
0d381245 | 5156 | |
c4093a6a JM |
5157 | struct captured_breakpoint_query_args |
5158 | { | |
5159 | int bnum; | |
5160 | }; | |
c5aa993b | 5161 | |
c4093a6a | 5162 | static int |
2b65245e | 5163 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
5164 | { |
5165 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 5166 | struct breakpoint *b; |
a6d9a66e | 5167 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 5168 | |
c4093a6a JM |
5169 | ALL_BREAKPOINTS (b) |
5170 | { | |
5171 | if (args->bnum == b->number) | |
c5aa993b | 5172 | { |
12c5a436 | 5173 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 5174 | return GDB_RC_OK; |
c5aa993b | 5175 | } |
c4093a6a JM |
5176 | } |
5177 | return GDB_RC_NONE; | |
5178 | } | |
c5aa993b | 5179 | |
c4093a6a | 5180 | enum gdb_rc |
4a64f543 MS |
5181 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, |
5182 | char **error_message) | |
c4093a6a JM |
5183 | { |
5184 | struct captured_breakpoint_query_args args; | |
cc59ec59 | 5185 | |
c4093a6a JM |
5186 | args.bnum = bnum; |
5187 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4a64f543 | 5188 | an error. */ |
b0b13bb4 DJ |
5189 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
5190 | error_message, RETURN_MASK_ALL) < 0) | |
5191 | return GDB_RC_FAIL; | |
5192 | else | |
5193 | return GDB_RC_OK; | |
c4093a6a | 5194 | } |
c5aa993b | 5195 | |
09d682a4 TT |
5196 | /* Return true if this breakpoint was set by the user, false if it is |
5197 | internal or momentary. */ | |
5198 | ||
5199 | int | |
5200 | user_breakpoint_p (struct breakpoint *b) | |
5201 | { | |
46c6471b | 5202 | return b->number > 0; |
09d682a4 TT |
5203 | } |
5204 | ||
7f3b0473 | 5205 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
5206 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
5207 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
5208 | FILTER is non-NULL, call it on each breakpoint and only include the | |
5209 | ones for which it returns non-zero. Return the total number of | |
5210 | breakpoints listed. */ | |
c906108c | 5211 | |
d77f58be | 5212 | static int |
e5a67952 | 5213 | breakpoint_1 (char *args, int allflag, |
4a64f543 | 5214 | int (*filter) (const struct breakpoint *)) |
c4093a6a | 5215 | { |
52f0bd74 | 5216 | struct breakpoint *b; |
a6d9a66e | 5217 | struct bp_location *last_loc = NULL; |
7f3b0473 | 5218 | int nr_printable_breakpoints; |
3b31d625 | 5219 | struct cleanup *bkpttbl_chain; |
79a45b7d | 5220 | struct value_print_options opts; |
a6d9a66e | 5221 | int print_address_bits = 0; |
269b11a2 | 5222 | int print_type_col_width = 14; |
79a45e25 | 5223 | struct ui_out *uiout = current_uiout; |
269b11a2 | 5224 | |
79a45b7d TT |
5225 | get_user_print_options (&opts); |
5226 | ||
4a64f543 MS |
5227 | /* Compute the number of rows in the table, as well as the size |
5228 | required for address fields. */ | |
7f3b0473 AC |
5229 | nr_printable_breakpoints = 0; |
5230 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
5231 | { |
5232 | /* If we have a filter, only list the breakpoints it accepts. */ | |
5233 | if (filter && !filter (b)) | |
5234 | continue; | |
5235 | ||
5236 | /* If we have an "args" string, it is a list of breakpoints to | |
5237 | accept. Skip the others. */ | |
5238 | if (args != NULL && *args != '\0') | |
5239 | { | |
5240 | if (allflag && parse_and_eval_long (args) != b->number) | |
5241 | continue; | |
5242 | if (!allflag && !number_is_in_list (args, b->number)) | |
5243 | continue; | |
5244 | } | |
269b11a2 | 5245 | |
e5a67952 MS |
5246 | if (allflag || user_breakpoint_p (b)) |
5247 | { | |
5248 | int addr_bit, type_len; | |
a6d9a66e | 5249 | |
e5a67952 MS |
5250 | addr_bit = breakpoint_address_bits (b); |
5251 | if (addr_bit > print_address_bits) | |
5252 | print_address_bits = addr_bit; | |
269b11a2 | 5253 | |
e5a67952 MS |
5254 | type_len = strlen (bptype_string (b->type)); |
5255 | if (type_len > print_type_col_width) | |
5256 | print_type_col_width = type_len; | |
5257 | ||
5258 | nr_printable_breakpoints++; | |
5259 | } | |
5260 | } | |
7f3b0473 | 5261 | |
79a45b7d | 5262 | if (opts.addressprint) |
3b31d625 | 5263 | bkpttbl_chain |
3e43a32a MS |
5264 | = make_cleanup_ui_out_table_begin_end (uiout, 6, |
5265 | nr_printable_breakpoints, | |
3b31d625 | 5266 | "BreakpointTable"); |
8b93c638 | 5267 | else |
3b31d625 | 5268 | bkpttbl_chain |
3e43a32a MS |
5269 | = make_cleanup_ui_out_table_begin_end (uiout, 5, |
5270 | nr_printable_breakpoints, | |
3b31d625 | 5271 | "BreakpointTable"); |
8b93c638 | 5272 | |
7f3b0473 | 5273 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
5274 | annotate_breakpoints_headers (); |
5275 | if (nr_printable_breakpoints > 0) | |
5276 | annotate_field (0); | |
4a64f543 | 5277 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
5278 | if (nr_printable_breakpoints > 0) |
5279 | annotate_field (1); | |
269b11a2 | 5280 | ui_out_table_header (uiout, print_type_col_width, ui_left, |
4a64f543 | 5281 | "type", "Type"); /* 2 */ |
d7faa9e7 AC |
5282 | if (nr_printable_breakpoints > 0) |
5283 | annotate_field (2); | |
4a64f543 | 5284 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ |
d7faa9e7 AC |
5285 | if (nr_printable_breakpoints > 0) |
5286 | annotate_field (3); | |
54e52265 | 5287 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 5288 | if (opts.addressprint) |
e5a67952 MS |
5289 | { |
5290 | if (nr_printable_breakpoints > 0) | |
5291 | annotate_field (4); | |
5292 | if (print_address_bits <= 32) | |
5293 | ui_out_table_header (uiout, 10, ui_left, | |
5294 | "addr", "Address"); /* 5 */ | |
5295 | else | |
5296 | ui_out_table_header (uiout, 18, ui_left, | |
5297 | "addr", "Address"); /* 5 */ | |
5298 | } | |
d7faa9e7 AC |
5299 | if (nr_printable_breakpoints > 0) |
5300 | annotate_field (5); | |
5301 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
5302 | ui_out_table_body (uiout); | |
5303 | if (nr_printable_breakpoints > 0) | |
5304 | annotate_breakpoints_table (); | |
7f3b0473 | 5305 | |
c4093a6a | 5306 | ALL_BREAKPOINTS (b) |
e5a67952 MS |
5307 | { |
5308 | QUIT; | |
5309 | /* If we have a filter, only list the breakpoints it accepts. */ | |
5310 | if (filter && !filter (b)) | |
5311 | continue; | |
5312 | ||
5313 | /* If we have an "args" string, it is a list of breakpoints to | |
5314 | accept. Skip the others. */ | |
5315 | ||
5316 | if (args != NULL && *args != '\0') | |
5317 | { | |
5318 | if (allflag) /* maintenance info breakpoint */ | |
5319 | { | |
5320 | if (parse_and_eval_long (args) != b->number) | |
5321 | continue; | |
5322 | } | |
5323 | else /* all others */ | |
5324 | { | |
5325 | if (!number_is_in_list (args, b->number)) | |
5326 | continue; | |
5327 | } | |
5328 | } | |
5329 | /* We only print out user settable breakpoints unless the | |
5330 | allflag is set. */ | |
5331 | if (allflag || user_breakpoint_p (b)) | |
12c5a436 | 5332 | print_one_breakpoint (b, &last_loc, allflag); |
e5a67952 MS |
5333 | } |
5334 | ||
3b31d625 | 5335 | do_cleanups (bkpttbl_chain); |
698384cd | 5336 | |
7f3b0473 | 5337 | if (nr_printable_breakpoints == 0) |
c906108c | 5338 | { |
4a64f543 MS |
5339 | /* If there's a filter, let the caller decide how to report |
5340 | empty list. */ | |
d77f58be SS |
5341 | if (!filter) |
5342 | { | |
e5a67952 | 5343 | if (args == NULL || *args == '\0') |
d77f58be SS |
5344 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); |
5345 | else | |
4a64f543 | 5346 | ui_out_message (uiout, 0, |
e5a67952 MS |
5347 | "No breakpoint or watchpoint matching '%s'.\n", |
5348 | args); | |
d77f58be | 5349 | } |
c906108c SS |
5350 | } |
5351 | else | |
c4093a6a | 5352 | { |
a6d9a66e UW |
5353 | if (last_loc && !server_command) |
5354 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 5355 | } |
c906108c | 5356 | |
4a64f543 | 5357 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 5358 | there have been breakpoints? */ |
c906108c | 5359 | annotate_breakpoints_table_end (); |
d77f58be SS |
5360 | |
5361 | return nr_printable_breakpoints; | |
c906108c SS |
5362 | } |
5363 | ||
ad443146 SS |
5364 | /* Display the value of default-collect in a way that is generally |
5365 | compatible with the breakpoint list. */ | |
5366 | ||
5367 | static void | |
5368 | default_collect_info (void) | |
5369 | { | |
79a45e25 PA |
5370 | struct ui_out *uiout = current_uiout; |
5371 | ||
ad443146 SS |
5372 | /* If it has no value (which is frequently the case), say nothing; a |
5373 | message like "No default-collect." gets in user's face when it's | |
5374 | not wanted. */ | |
5375 | if (!*default_collect) | |
5376 | return; | |
5377 | ||
5378 | /* The following phrase lines up nicely with per-tracepoint collect | |
5379 | actions. */ | |
5380 | ui_out_text (uiout, "default collect "); | |
5381 | ui_out_field_string (uiout, "default-collect", default_collect); | |
5382 | ui_out_text (uiout, " \n"); | |
5383 | } | |
5384 | ||
c906108c | 5385 | static void |
e5a67952 | 5386 | breakpoints_info (char *args, int from_tty) |
c906108c | 5387 | { |
e5a67952 | 5388 | breakpoint_1 (args, 0, NULL); |
ad443146 SS |
5389 | |
5390 | default_collect_info (); | |
d77f58be SS |
5391 | } |
5392 | ||
5393 | static void | |
e5a67952 | 5394 | watchpoints_info (char *args, int from_tty) |
d77f58be | 5395 | { |
e5a67952 | 5396 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
79a45e25 | 5397 | struct ui_out *uiout = current_uiout; |
d77f58be SS |
5398 | |
5399 | if (num_printed == 0) | |
5400 | { | |
e5a67952 | 5401 | if (args == NULL || *args == '\0') |
d77f58be SS |
5402 | ui_out_message (uiout, 0, "No watchpoints.\n"); |
5403 | else | |
e5a67952 | 5404 | ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args); |
d77f58be | 5405 | } |
c906108c SS |
5406 | } |
5407 | ||
7a292a7a | 5408 | static void |
e5a67952 | 5409 | maintenance_info_breakpoints (char *args, int from_tty) |
c906108c | 5410 | { |
e5a67952 | 5411 | breakpoint_1 (args, 1, NULL); |
ad443146 SS |
5412 | |
5413 | default_collect_info (); | |
c906108c SS |
5414 | } |
5415 | ||
0d381245 | 5416 | static int |
714835d5 | 5417 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 5418 | struct program_space *pspace, |
714835d5 | 5419 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
5420 | { |
5421 | struct bp_location *bl = b->loc; | |
cc59ec59 | 5422 | |
0d381245 VP |
5423 | for (; bl; bl = bl->next) |
5424 | { | |
6c95b8df PA |
5425 | if (bl->pspace == pspace |
5426 | && bl->address == pc | |
0d381245 VP |
5427 | && (!overlay_debugging || bl->section == section)) |
5428 | return 1; | |
5429 | } | |
5430 | return 0; | |
5431 | } | |
5432 | ||
672f9b60 | 5433 | /* Print a message describing any user-breakpoints set at PC. This |
6c95b8df PA |
5434 | concerns with logical breakpoints, so we match program spaces, not |
5435 | address spaces. */ | |
c906108c SS |
5436 | |
5437 | static void | |
6c95b8df PA |
5438 | describe_other_breakpoints (struct gdbarch *gdbarch, |
5439 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 5440 | struct obj_section *section, int thread) |
c906108c | 5441 | { |
52f0bd74 AC |
5442 | int others = 0; |
5443 | struct breakpoint *b; | |
c906108c SS |
5444 | |
5445 | ALL_BREAKPOINTS (b) | |
672f9b60 KP |
5446 | others += (user_breakpoint_p (b) |
5447 | && breakpoint_has_pc (b, pspace, pc, section)); | |
c906108c SS |
5448 | if (others > 0) |
5449 | { | |
a3f17187 AC |
5450 | if (others == 1) |
5451 | printf_filtered (_("Note: breakpoint ")); | |
5452 | else /* if (others == ???) */ | |
5453 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 5454 | ALL_BREAKPOINTS (b) |
672f9b60 | 5455 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
5456 | { |
5457 | others--; | |
5458 | printf_filtered ("%d", b->number); | |
5459 | if (b->thread == -1 && thread != -1) | |
5460 | printf_filtered (" (all threads)"); | |
5461 | else if (b->thread != -1) | |
5462 | printf_filtered (" (thread %d)", b->thread); | |
5463 | printf_filtered ("%s%s ", | |
059fb39f | 5464 | ((b->enable_state == bp_disabled |
f8eba3c6 | 5465 | || b->enable_state == bp_call_disabled) |
0d381245 VP |
5466 | ? " (disabled)" |
5467 | : b->enable_state == bp_permanent | |
5468 | ? " (permanent)" | |
5469 | : ""), | |
5470 | (others > 1) ? "," | |
5471 | : ((others == 1) ? " and" : "")); | |
5472 | } | |
a3f17187 | 5473 | printf_filtered (_("also set at pc ")); |
5af949e3 | 5474 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
5475 | printf_filtered (".\n"); |
5476 | } | |
5477 | } | |
5478 | \f | |
c906108c | 5479 | |
e4f237da KB |
5480 | /* Return true iff it is meaningful to use the address member of |
5481 | BPT. For some breakpoint types, the address member is irrelevant | |
5482 | and it makes no sense to attempt to compare it to other addresses | |
5483 | (or use it for any other purpose either). | |
5484 | ||
4a64f543 MS |
5485 | More specifically, each of the following breakpoint types will |
5486 | always have a zero valued address and we don't want to mark | |
5487 | breakpoints of any of these types to be a duplicate of an actual | |
5488 | breakpoint at address zero: | |
e4f237da KB |
5489 | |
5490 | bp_watchpoint | |
2d134ed3 PA |
5491 | bp_catchpoint |
5492 | ||
5493 | */ | |
e4f237da KB |
5494 | |
5495 | static int | |
5496 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
5497 | { | |
5498 | enum bptype type = bpt->type; | |
5499 | ||
2d134ed3 PA |
5500 | return (type != bp_watchpoint && type != bp_catchpoint); |
5501 | } | |
5502 | ||
5503 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
5504 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
5505 | ||
5506 | static int | |
4a64f543 MS |
5507 | watchpoint_locations_match (struct bp_location *loc1, |
5508 | struct bp_location *loc2) | |
2d134ed3 | 5509 | { |
3a5c3e22 PA |
5510 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
5511 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
5512 | ||
5513 | /* Both of them must exist. */ | |
5514 | gdb_assert (w1 != NULL); | |
5515 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 5516 | |
4a64f543 MS |
5517 | /* If the target can evaluate the condition expression in hardware, |
5518 | then we we need to insert both watchpoints even if they are at | |
5519 | the same place. Otherwise the watchpoint will only trigger when | |
5520 | the condition of whichever watchpoint was inserted evaluates to | |
5521 | true, not giving a chance for GDB to check the condition of the | |
5522 | other watchpoint. */ | |
3a5c3e22 | 5523 | if ((w1->cond_exp |
4a64f543 MS |
5524 | && target_can_accel_watchpoint_condition (loc1->address, |
5525 | loc1->length, | |
0cf6dd15 | 5526 | loc1->watchpoint_type, |
3a5c3e22 PA |
5527 | w1->cond_exp)) |
5528 | || (w2->cond_exp | |
4a64f543 MS |
5529 | && target_can_accel_watchpoint_condition (loc2->address, |
5530 | loc2->length, | |
0cf6dd15 | 5531 | loc2->watchpoint_type, |
3a5c3e22 | 5532 | w2->cond_exp))) |
0cf6dd15 TJB |
5533 | return 0; |
5534 | ||
85d721b8 PA |
5535 | /* Note that this checks the owner's type, not the location's. In |
5536 | case the target does not support read watchpoints, but does | |
5537 | support access watchpoints, we'll have bp_read_watchpoint | |
5538 | watchpoints with hw_access locations. Those should be considered | |
5539 | duplicates of hw_read locations. The hw_read locations will | |
5540 | become hw_access locations later. */ | |
2d134ed3 PA |
5541 | return (loc1->owner->type == loc2->owner->type |
5542 | && loc1->pspace->aspace == loc2->pspace->aspace | |
5543 | && loc1->address == loc2->address | |
5544 | && loc1->length == loc2->length); | |
e4f237da KB |
5545 | } |
5546 | ||
6c95b8df PA |
5547 | /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the |
5548 | same breakpoint location. In most targets, this can only be true | |
5549 | if ASPACE1 matches ASPACE2. On targets that have global | |
5550 | breakpoints, the address space doesn't really matter. */ | |
5551 | ||
5552 | static int | |
5553 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, | |
5554 | struct address_space *aspace2, CORE_ADDR addr2) | |
5555 | { | |
5556 | return ((gdbarch_has_global_breakpoints (target_gdbarch) | |
5557 | || aspace1 == aspace2) | |
5558 | && addr1 == addr2); | |
5559 | } | |
5560 | ||
f1310107 TJB |
5561 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
5562 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
5563 | matches ASPACE2. On targets that have global breakpoints, the address | |
5564 | space doesn't really matter. */ | |
5565 | ||
5566 | static int | |
5567 | breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1, | |
5568 | int len1, struct address_space *aspace2, | |
5569 | CORE_ADDR addr2) | |
5570 | { | |
5571 | return ((gdbarch_has_global_breakpoints (target_gdbarch) | |
5572 | || aspace1 == aspace2) | |
5573 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
5574 | } | |
5575 | ||
5576 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
5577 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
5578 | matches the breakpoint's address space. On targets that have global | |
5579 | breakpoints, the address space doesn't really matter. */ | |
5580 | ||
5581 | static int | |
5582 | breakpoint_location_address_match (struct bp_location *bl, | |
5583 | struct address_space *aspace, | |
5584 | CORE_ADDR addr) | |
5585 | { | |
5586 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
5587 | aspace, addr) | |
5588 | || (bl->length | |
5589 | && breakpoint_address_match_range (bl->pspace->aspace, | |
5590 | bl->address, bl->length, | |
5591 | aspace, addr))); | |
5592 | } | |
5593 | ||
1e4d1764 YQ |
5594 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
5595 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns | |
5596 | true, otherwise returns false. */ | |
5597 | ||
5598 | static int | |
5599 | tracepoint_locations_match (struct bp_location *loc1, | |
5600 | struct bp_location *loc2) | |
5601 | { | |
5602 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) | |
5603 | /* Since tracepoint locations are never duplicated with others', tracepoint | |
5604 | locations at the same address of different tracepoints are regarded as | |
5605 | different locations. */ | |
5606 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); | |
5607 | else | |
5608 | return 0; | |
5609 | } | |
5610 | ||
2d134ed3 PA |
5611 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
5612 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
5613 | represent the same location. */ | |
5614 | ||
5615 | static int | |
4a64f543 MS |
5616 | breakpoint_locations_match (struct bp_location *loc1, |
5617 | struct bp_location *loc2) | |
2d134ed3 | 5618 | { |
2bdf28a0 JK |
5619 | int hw_point1, hw_point2; |
5620 | ||
5621 | /* Both of them must not be in moribund_locations. */ | |
5622 | gdb_assert (loc1->owner != NULL); | |
5623 | gdb_assert (loc2->owner != NULL); | |
5624 | ||
5625 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
5626 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
5627 | |
5628 | if (hw_point1 != hw_point2) | |
5629 | return 0; | |
5630 | else if (hw_point1) | |
5631 | return watchpoint_locations_match (loc1, loc2); | |
1e4d1764 YQ |
5632 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
5633 | return tracepoint_locations_match (loc1, loc2); | |
2d134ed3 | 5634 | else |
f1310107 TJB |
5635 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
5636 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
5637 | loc2->pspace->aspace, loc2->address) | |
5638 | && loc1->length == loc2->length); | |
2d134ed3 PA |
5639 | } |
5640 | ||
76897487 KB |
5641 | static void |
5642 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
5643 | int bnum, int have_bnum) | |
5644 | { | |
f63fbe86 MS |
5645 | /* The longest string possibly returned by hex_string_custom |
5646 | is 50 chars. These must be at least that big for safety. */ | |
5647 | char astr1[64]; | |
5648 | char astr2[64]; | |
76897487 | 5649 | |
bb599908 PH |
5650 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
5651 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 5652 | if (have_bnum) |
8a3fe4f8 | 5653 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
5654 | bnum, astr1, astr2); |
5655 | else | |
8a3fe4f8 | 5656 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
5657 | } |
5658 | ||
4a64f543 MS |
5659 | /* Adjust a breakpoint's address to account for architectural |
5660 | constraints on breakpoint placement. Return the adjusted address. | |
5661 | Note: Very few targets require this kind of adjustment. For most | |
5662 | targets, this function is simply the identity function. */ | |
76897487 KB |
5663 | |
5664 | static CORE_ADDR | |
a6d9a66e UW |
5665 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
5666 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 5667 | { |
a6d9a66e | 5668 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
5669 | { |
5670 | /* Very few targets need any kind of breakpoint adjustment. */ | |
5671 | return bpaddr; | |
5672 | } | |
88f7da05 KB |
5673 | else if (bptype == bp_watchpoint |
5674 | || bptype == bp_hardware_watchpoint | |
5675 | || bptype == bp_read_watchpoint | |
5676 | || bptype == bp_access_watchpoint | |
fe798b75 | 5677 | || bptype == bp_catchpoint) |
88f7da05 KB |
5678 | { |
5679 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
5680 | have their addresses modified. */ | |
5681 | return bpaddr; | |
5682 | } | |
76897487 KB |
5683 | else |
5684 | { | |
5685 | CORE_ADDR adjusted_bpaddr; | |
5686 | ||
5687 | /* Some targets have architectural constraints on the placement | |
5688 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 5689 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
5690 | |
5691 | /* An adjusted breakpoint address can significantly alter | |
5692 | a user's expectations. Print a warning if an adjustment | |
5693 | is required. */ | |
5694 | if (adjusted_bpaddr != bpaddr) | |
5695 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
5696 | ||
5697 | return adjusted_bpaddr; | |
5698 | } | |
5699 | } | |
5700 | ||
28010a5d PA |
5701 | void |
5702 | init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops, | |
5703 | struct breakpoint *owner) | |
7cc221ef | 5704 | { |
7cc221ef DJ |
5705 | memset (loc, 0, sizeof (*loc)); |
5706 | ||
348d480f PA |
5707 | gdb_assert (ops != NULL); |
5708 | ||
28010a5d PA |
5709 | loc->ops = ops; |
5710 | loc->owner = owner; | |
511a6cd4 | 5711 | loc->cond = NULL; |
0d381245 VP |
5712 | loc->shlib_disabled = 0; |
5713 | loc->enabled = 1; | |
e049a4b5 | 5714 | |
28010a5d | 5715 | switch (owner->type) |
e049a4b5 DJ |
5716 | { |
5717 | case bp_breakpoint: | |
5718 | case bp_until: | |
5719 | case bp_finish: | |
5720 | case bp_longjmp: | |
5721 | case bp_longjmp_resume: | |
186c406b TT |
5722 | case bp_exception: |
5723 | case bp_exception_resume: | |
e049a4b5 | 5724 | case bp_step_resume: |
2c03e5be | 5725 | case bp_hp_step_resume: |
e049a4b5 DJ |
5726 | case bp_watchpoint_scope: |
5727 | case bp_call_dummy: | |
aa7d318d | 5728 | case bp_std_terminate: |
e049a4b5 DJ |
5729 | case bp_shlib_event: |
5730 | case bp_thread_event: | |
5731 | case bp_overlay_event: | |
4efc6507 | 5732 | case bp_jit_event: |
0fd8e87f | 5733 | case bp_longjmp_master: |
aa7d318d | 5734 | case bp_std_terminate_master: |
186c406b | 5735 | case bp_exception_master: |
0e30163f JK |
5736 | case bp_gnu_ifunc_resolver: |
5737 | case bp_gnu_ifunc_resolver_return: | |
e049a4b5 DJ |
5738 | loc->loc_type = bp_loc_software_breakpoint; |
5739 | break; | |
5740 | case bp_hardware_breakpoint: | |
5741 | loc->loc_type = bp_loc_hardware_breakpoint; | |
5742 | break; | |
5743 | case bp_hardware_watchpoint: | |
5744 | case bp_read_watchpoint: | |
5745 | case bp_access_watchpoint: | |
5746 | loc->loc_type = bp_loc_hardware_watchpoint; | |
5747 | break; | |
5748 | case bp_watchpoint: | |
ce78b96d | 5749 | case bp_catchpoint: |
15c3d785 PA |
5750 | case bp_tracepoint: |
5751 | case bp_fast_tracepoint: | |
0fb4aa4b | 5752 | case bp_static_tracepoint: |
e049a4b5 DJ |
5753 | loc->loc_type = bp_loc_other; |
5754 | break; | |
5755 | default: | |
e2e0b3e5 | 5756 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
5757 | } |
5758 | ||
f431efe5 | 5759 | loc->refc = 1; |
28010a5d PA |
5760 | } |
5761 | ||
5762 | /* Allocate a struct bp_location. */ | |
5763 | ||
5764 | static struct bp_location * | |
5765 | allocate_bp_location (struct breakpoint *bpt) | |
5766 | { | |
348d480f PA |
5767 | return bpt->ops->allocate_location (bpt); |
5768 | } | |
7cc221ef | 5769 | |
f431efe5 PA |
5770 | static void |
5771 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 | 5772 | { |
348d480f | 5773 | loc->ops->dtor (loc); |
fe3f5fa8 VP |
5774 | xfree (loc); |
5775 | } | |
5776 | ||
f431efe5 PA |
5777 | /* Increment reference count. */ |
5778 | ||
5779 | static void | |
5780 | incref_bp_location (struct bp_location *bl) | |
5781 | { | |
5782 | ++bl->refc; | |
5783 | } | |
5784 | ||
5785 | /* Decrement reference count. If the reference count reaches 0, | |
5786 | destroy the bp_location. Sets *BLP to NULL. */ | |
5787 | ||
5788 | static void | |
5789 | decref_bp_location (struct bp_location **blp) | |
5790 | { | |
0807b50c PA |
5791 | gdb_assert ((*blp)->refc > 0); |
5792 | ||
f431efe5 PA |
5793 | if (--(*blp)->refc == 0) |
5794 | free_bp_location (*blp); | |
5795 | *blp = NULL; | |
5796 | } | |
5797 | ||
346774a9 | 5798 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 5799 | |
346774a9 PA |
5800 | static void |
5801 | add_to_breakpoint_chain (struct breakpoint *b) | |
c906108c | 5802 | { |
346774a9 | 5803 | struct breakpoint *b1; |
c906108c | 5804 | |
346774a9 PA |
5805 | /* Add this breakpoint to the end of the chain so that a list of |
5806 | breakpoints will come out in order of increasing numbers. */ | |
5807 | ||
5808 | b1 = breakpoint_chain; | |
5809 | if (b1 == 0) | |
5810 | breakpoint_chain = b; | |
5811 | else | |
5812 | { | |
5813 | while (b1->next) | |
5814 | b1 = b1->next; | |
5815 | b1->next = b; | |
5816 | } | |
5817 | } | |
5818 | ||
5819 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
5820 | ||
5821 | static void | |
5822 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
5823 | struct gdbarch *gdbarch, | |
28010a5d | 5824 | enum bptype bptype, |
c0a91b2b | 5825 | const struct breakpoint_ops *ops) |
346774a9 | 5826 | { |
c906108c | 5827 | memset (b, 0, sizeof (*b)); |
2219d63c | 5828 | |
348d480f PA |
5829 | gdb_assert (ops != NULL); |
5830 | ||
28010a5d | 5831 | b->ops = ops; |
4d28f7a8 | 5832 | b->type = bptype; |
a6d9a66e | 5833 | b->gdbarch = gdbarch; |
c906108c SS |
5834 | b->language = current_language->la_language; |
5835 | b->input_radix = input_radix; | |
5836 | b->thread = -1; | |
b5de0fa7 | 5837 | b->enable_state = bp_enabled; |
c906108c SS |
5838 | b->next = 0; |
5839 | b->silent = 0; | |
5840 | b->ignore_count = 0; | |
5841 | b->commands = NULL; | |
818dd999 | 5842 | b->frame_id = null_frame_id; |
0d381245 | 5843 | b->condition_not_parsed = 0; |
84f4c1fe | 5844 | b->py_bp_object = NULL; |
d0fb5eae | 5845 | b->related_breakpoint = b; |
346774a9 PA |
5846 | } |
5847 | ||
5848 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
5849 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
5850 | |
5851 | static struct breakpoint * | |
5852 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 5853 | enum bptype bptype, |
c0a91b2b | 5854 | const struct breakpoint_ops *ops) |
346774a9 PA |
5855 | { |
5856 | struct breakpoint *b = XNEW (struct breakpoint); | |
5857 | ||
348d480f | 5858 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
c56053d2 | 5859 | add_to_breakpoint_chain (b); |
0d381245 VP |
5860 | return b; |
5861 | } | |
5862 | ||
0e30163f JK |
5863 | /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function |
5864 | resolutions should be made as the user specified the location explicitly | |
5865 | enough. */ | |
5866 | ||
0d381245 | 5867 | static void |
0e30163f | 5868 | set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) |
0d381245 | 5869 | { |
2bdf28a0 JK |
5870 | gdb_assert (loc->owner != NULL); |
5871 | ||
0d381245 | 5872 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 5873 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 5874 | || is_tracepoint (loc->owner)) |
0d381245 | 5875 | { |
0e30163f JK |
5876 | int is_gnu_ifunc; |
5877 | ||
5878 | find_pc_partial_function_gnu_ifunc (loc->address, &loc->function_name, | |
5879 | NULL, NULL, &is_gnu_ifunc); | |
5880 | ||
5881 | if (is_gnu_ifunc && !explicit_loc) | |
5882 | { | |
5883 | struct breakpoint *b = loc->owner; | |
5884 | ||
5885 | gdb_assert (loc->pspace == current_program_space); | |
5886 | if (gnu_ifunc_resolve_name (loc->function_name, | |
5887 | &loc->requested_address)) | |
5888 | { | |
5889 | /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */ | |
5890 | loc->address = adjust_breakpoint_address (loc->gdbarch, | |
5891 | loc->requested_address, | |
5892 | b->type); | |
5893 | } | |
5894 | else if (b->type == bp_breakpoint && b->loc == loc | |
5895 | && loc->next == NULL && b->related_breakpoint == b) | |
5896 | { | |
5897 | /* Create only the whole new breakpoint of this type but do not | |
5898 | mess more complicated breakpoints with multiple locations. */ | |
5899 | b->type = bp_gnu_ifunc_resolver; | |
5900 | } | |
5901 | } | |
5902 | ||
0d381245 VP |
5903 | if (loc->function_name) |
5904 | loc->function_name = xstrdup (loc->function_name); | |
5905 | } | |
5906 | } | |
5907 | ||
a6d9a66e | 5908 | /* Attempt to determine architecture of location identified by SAL. */ |
1bfeeb0f | 5909 | struct gdbarch * |
a6d9a66e UW |
5910 | get_sal_arch (struct symtab_and_line sal) |
5911 | { | |
5912 | if (sal.section) | |
5913 | return get_objfile_arch (sal.section->objfile); | |
5914 | if (sal.symtab) | |
5915 | return get_objfile_arch (sal.symtab->objfile); | |
5916 | ||
5917 | return NULL; | |
5918 | } | |
5919 | ||
346774a9 PA |
5920 | /* Low level routine for partially initializing a breakpoint of type |
5921 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 5922 | file name, and line number are provided by SAL. |
0d381245 VP |
5923 | |
5924 | It is expected that the caller will complete the initialization of | |
5925 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 5926 | information regarding the creation of a new breakpoint. */ |
0d381245 | 5927 | |
346774a9 PA |
5928 | static void |
5929 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 5930 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 5931 | const struct breakpoint_ops *ops) |
0d381245 | 5932 | { |
28010a5d | 5933 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 5934 | |
3742cc8b | 5935 | add_location_to_breakpoint (b, &sal); |
0d381245 | 5936 | |
6c95b8df PA |
5937 | if (bptype != bp_catchpoint) |
5938 | gdb_assert (sal.pspace != NULL); | |
5939 | ||
f8eba3c6 TT |
5940 | /* Store the program space that was used to set the breakpoint, |
5941 | except for ordinary breakpoints, which are independent of the | |
5942 | program space. */ | |
5943 | if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) | |
5944 | b->pspace = sal.pspace; | |
0d381245 | 5945 | |
c906108c | 5946 | breakpoints_changed (); |
346774a9 | 5947 | } |
c906108c | 5948 | |
346774a9 PA |
5949 | /* set_raw_breakpoint is a low level routine for allocating and |
5950 | partially initializing a breakpoint of type BPTYPE. The newly | |
5951 | created breakpoint's address, section, source file name, and line | |
5952 | number are provided by SAL. The newly created and partially | |
5953 | initialized breakpoint is added to the breakpoint chain and | |
5954 | is also returned as the value of this function. | |
5955 | ||
5956 | It is expected that the caller will complete the initialization of | |
5957 | the newly created breakpoint struct as well as output any status | |
5958 | information regarding the creation of a new breakpoint. In | |
5959 | particular, set_raw_breakpoint does NOT set the breakpoint | |
5960 | number! Care should be taken to not allow an error to occur | |
5961 | prior to completing the initialization of the breakpoint. If this | |
5962 | should happen, a bogus breakpoint will be left on the chain. */ | |
5963 | ||
5964 | struct breakpoint * | |
5965 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
348d480f | 5966 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 5967 | const struct breakpoint_ops *ops) |
346774a9 PA |
5968 | { |
5969 | struct breakpoint *b = XNEW (struct breakpoint); | |
5970 | ||
348d480f | 5971 | init_raw_breakpoint (b, gdbarch, sal, bptype, ops); |
c56053d2 | 5972 | add_to_breakpoint_chain (b); |
c906108c SS |
5973 | return b; |
5974 | } | |
5975 | ||
c2c6d25f JM |
5976 | |
5977 | /* Note that the breakpoint object B describes a permanent breakpoint | |
5978 | instruction, hard-wired into the inferior's code. */ | |
5979 | void | |
5980 | make_breakpoint_permanent (struct breakpoint *b) | |
5981 | { | |
0d381245 | 5982 | struct bp_location *bl; |
cc59ec59 | 5983 | |
b5de0fa7 | 5984 | b->enable_state = bp_permanent; |
c2c6d25f | 5985 | |
4a64f543 MS |
5986 | /* By definition, permanent breakpoints are already present in the |
5987 | code. Mark all locations as inserted. For now, | |
5988 | make_breakpoint_permanent is called in just one place, so it's | |
5989 | hard to say if it's reasonable to have permanent breakpoint with | |
e5dd4106 | 5990 | multiple locations or not, but it's easy to implement. */ |
0d381245 VP |
5991 | for (bl = b->loc; bl; bl = bl->next) |
5992 | bl->inserted = 1; | |
c2c6d25f JM |
5993 | } |
5994 | ||
53a5351d | 5995 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
5996 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
5997 | initiated the operation. */ | |
c906108c SS |
5998 | |
5999 | void | |
186c406b | 6000 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 6001 | { |
35df4500 | 6002 | struct breakpoint *b, *b_tmp; |
186c406b | 6003 | int thread = tp->num; |
0fd8e87f UW |
6004 | |
6005 | /* To avoid having to rescan all objfile symbols at every step, | |
6006 | we maintain a list of continually-inserted but always disabled | |
6007 | longjmp "master" breakpoints. Here, we simply create momentary | |
6008 | clones of those and enable them for the requested thread. */ | |
35df4500 | 6009 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 6010 | if (b->pspace == current_program_space |
186c406b TT |
6011 | && (b->type == bp_longjmp_master |
6012 | || b->type == bp_exception_master)) | |
0fd8e87f | 6013 | { |
06edf0c0 PA |
6014 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
6015 | struct breakpoint *clone; | |
cc59ec59 | 6016 | |
06edf0c0 PA |
6017 | clone = momentary_breakpoint_from_master (b, type, |
6018 | &momentary_breakpoint_ops); | |
0fd8e87f UW |
6019 | clone->thread = thread; |
6020 | } | |
186c406b TT |
6021 | |
6022 | tp->initiating_frame = frame; | |
c906108c SS |
6023 | } |
6024 | ||
611c83ae | 6025 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 6026 | void |
611c83ae | 6027 | delete_longjmp_breakpoint (int thread) |
c906108c | 6028 | { |
35df4500 | 6029 | struct breakpoint *b, *b_tmp; |
c906108c | 6030 | |
35df4500 | 6031 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 6032 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
6033 | { |
6034 | if (b->thread == thread) | |
6035 | delete_breakpoint (b); | |
6036 | } | |
c906108c SS |
6037 | } |
6038 | ||
1900040c MS |
6039 | void |
6040 | enable_overlay_breakpoints (void) | |
6041 | { | |
52f0bd74 | 6042 | struct breakpoint *b; |
1900040c MS |
6043 | |
6044 | ALL_BREAKPOINTS (b) | |
6045 | if (b->type == bp_overlay_event) | |
6046 | { | |
6047 | b->enable_state = bp_enabled; | |
b60e7edf | 6048 | update_global_location_list (1); |
c02f5703 | 6049 | overlay_events_enabled = 1; |
1900040c MS |
6050 | } |
6051 | } | |
6052 | ||
6053 | void | |
6054 | disable_overlay_breakpoints (void) | |
6055 | { | |
52f0bd74 | 6056 | struct breakpoint *b; |
1900040c MS |
6057 | |
6058 | ALL_BREAKPOINTS (b) | |
6059 | if (b->type == bp_overlay_event) | |
6060 | { | |
6061 | b->enable_state = bp_disabled; | |
b60e7edf | 6062 | update_global_location_list (0); |
c02f5703 | 6063 | overlay_events_enabled = 0; |
1900040c MS |
6064 | } |
6065 | } | |
6066 | ||
aa7d318d TT |
6067 | /* Set an active std::terminate breakpoint for each std::terminate |
6068 | master breakpoint. */ | |
6069 | void | |
6070 | set_std_terminate_breakpoint (void) | |
6071 | { | |
35df4500 | 6072 | struct breakpoint *b, *b_tmp; |
aa7d318d | 6073 | |
35df4500 | 6074 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
6075 | if (b->pspace == current_program_space |
6076 | && b->type == bp_std_terminate_master) | |
6077 | { | |
06edf0c0 PA |
6078 | momentary_breakpoint_from_master (b, bp_std_terminate, |
6079 | &momentary_breakpoint_ops); | |
aa7d318d TT |
6080 | } |
6081 | } | |
6082 | ||
6083 | /* Delete all the std::terminate breakpoints. */ | |
6084 | void | |
6085 | delete_std_terminate_breakpoint (void) | |
6086 | { | |
35df4500 | 6087 | struct breakpoint *b, *b_tmp; |
aa7d318d | 6088 | |
35df4500 | 6089 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
6090 | if (b->type == bp_std_terminate) |
6091 | delete_breakpoint (b); | |
6092 | } | |
6093 | ||
c4093a6a | 6094 | struct breakpoint * |
a6d9a66e | 6095 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
6096 | { |
6097 | struct breakpoint *b; | |
c4093a6a | 6098 | |
06edf0c0 PA |
6099 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
6100 | &internal_breakpoint_ops); | |
6101 | ||
b5de0fa7 | 6102 | b->enable_state = bp_enabled; |
c4093a6a | 6103 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
6104 | b->addr_string |
6105 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 6106 | |
b60e7edf | 6107 | update_global_location_list_nothrow (1); |
74960c60 | 6108 | |
c4093a6a JM |
6109 | return b; |
6110 | } | |
6111 | ||
6112 | void | |
6113 | remove_thread_event_breakpoints (void) | |
6114 | { | |
35df4500 | 6115 | struct breakpoint *b, *b_tmp; |
c4093a6a | 6116 | |
35df4500 | 6117 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
6118 | if (b->type == bp_thread_event |
6119 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
6120 | delete_breakpoint (b); |
6121 | } | |
6122 | ||
0101ce28 JJ |
6123 | struct lang_and_radix |
6124 | { | |
6125 | enum language lang; | |
6126 | int radix; | |
6127 | }; | |
6128 | ||
4efc6507 DE |
6129 | /* Create a breakpoint for JIT code registration and unregistration. */ |
6130 | ||
6131 | struct breakpoint * | |
6132 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
6133 | { | |
6134 | struct breakpoint *b; | |
6135 | ||
06edf0c0 PA |
6136 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event, |
6137 | &internal_breakpoint_ops); | |
4efc6507 DE |
6138 | update_global_location_list_nothrow (1); |
6139 | return b; | |
6140 | } | |
0101ce28 | 6141 | |
03673fc7 PP |
6142 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
6143 | ||
6144 | void | |
6145 | remove_jit_event_breakpoints (void) | |
6146 | { | |
6147 | struct breakpoint *b, *b_tmp; | |
6148 | ||
6149 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
6150 | if (b->type == bp_jit_event | |
6151 | && b->loc->pspace == current_program_space) | |
6152 | delete_breakpoint (b); | |
6153 | } | |
6154 | ||
cae688ec JJ |
6155 | void |
6156 | remove_solib_event_breakpoints (void) | |
6157 | { | |
35df4500 | 6158 | struct breakpoint *b, *b_tmp; |
cae688ec | 6159 | |
35df4500 | 6160 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
6161 | if (b->type == bp_shlib_event |
6162 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
6163 | delete_breakpoint (b); |
6164 | } | |
6165 | ||
6166 | struct breakpoint * | |
a6d9a66e | 6167 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
cae688ec JJ |
6168 | { |
6169 | struct breakpoint *b; | |
6170 | ||
06edf0c0 PA |
6171 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
6172 | &internal_breakpoint_ops); | |
b60e7edf | 6173 | update_global_location_list_nothrow (1); |
cae688ec JJ |
6174 | return b; |
6175 | } | |
6176 | ||
6177 | /* Disable any breakpoints that are on code in shared libraries. Only | |
6178 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
6179 | ||
6180 | void | |
cb851954 | 6181 | disable_breakpoints_in_shlibs (void) |
cae688ec | 6182 | { |
876fa593 | 6183 | struct bp_location *loc, **locp_tmp; |
cae688ec | 6184 | |
876fa593 | 6185 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 6186 | { |
2bdf28a0 | 6187 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 6188 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 6189 | |
4a64f543 MS |
6190 | /* We apply the check to all breakpoints, including disabled for |
6191 | those with loc->duplicate set. This is so that when breakpoint | |
6192 | becomes enabled, or the duplicate is removed, gdb will try to | |
6193 | insert all breakpoints. If we don't set shlib_disabled here, | |
6194 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 6195 | if (((b->type == bp_breakpoint) |
508ccb1f | 6196 | || (b->type == bp_jit_event) |
1042e4c0 | 6197 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 6198 | || (is_tracepoint (b))) |
6c95b8df | 6199 | && loc->pspace == current_program_space |
0d381245 | 6200 | && !loc->shlib_disabled |
a77053c2 | 6201 | #ifdef PC_SOLIB |
0d381245 | 6202 | && PC_SOLIB (loc->address) |
a77053c2 | 6203 | #else |
6c95b8df | 6204 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 MK |
6205 | #endif |
6206 | ) | |
0d381245 VP |
6207 | { |
6208 | loc->shlib_disabled = 1; | |
6209 | } | |
cae688ec JJ |
6210 | } |
6211 | } | |
6212 | ||
1e4d1764 YQ |
6213 | /* Disable any breakpoints and tracepoints that are in an unloaded shared |
6214 | library. Only apply to enabled breakpoints, disabled ones can just stay | |
4a64f543 | 6215 | disabled. */ |
84acb35a | 6216 | |
75149521 | 6217 | static void |
84acb35a JJ |
6218 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
6219 | { | |
876fa593 | 6220 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
6221 | int disabled_shlib_breaks = 0; |
6222 | ||
c86cf029 VP |
6223 | /* SunOS a.out shared libraries are always mapped, so do not |
6224 | disable breakpoints; they will only be reported as unloaded | |
6225 | through clear_solib when GDB discards its shared library | |
6226 | list. See clear_solib for more information. */ | |
6227 | if (exec_bfd != NULL | |
6228 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
6229 | return; | |
6230 | ||
876fa593 | 6231 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 6232 | { |
2bdf28a0 | 6233 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 6234 | struct breakpoint *b = loc->owner; |
cc59ec59 | 6235 | |
1e4d1764 | 6236 | if (solib->pspace == loc->pspace |
e2dd7057 | 6237 | && !loc->shlib_disabled |
1e4d1764 YQ |
6238 | && (((b->type == bp_breakpoint |
6239 | || b->type == bp_jit_event | |
6240 | || b->type == bp_hardware_breakpoint) | |
6241 | && (loc->loc_type == bp_loc_hardware_breakpoint | |
6242 | || loc->loc_type == bp_loc_software_breakpoint)) | |
6243 | || is_tracepoint (b)) | |
e2dd7057 | 6244 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 6245 | { |
e2dd7057 PP |
6246 | loc->shlib_disabled = 1; |
6247 | /* At this point, we cannot rely on remove_breakpoint | |
6248 | succeeding so we must mark the breakpoint as not inserted | |
6249 | to prevent future errors occurring in remove_breakpoints. */ | |
6250 | loc->inserted = 0; | |
8d3788bd VP |
6251 | |
6252 | /* This may cause duplicate notifications for the same breakpoint. */ | |
6253 | observer_notify_breakpoint_modified (b); | |
6254 | ||
e2dd7057 PP |
6255 | if (!disabled_shlib_breaks) |
6256 | { | |
6257 | target_terminal_ours_for_output (); | |
3e43a32a MS |
6258 | warning (_("Temporarily disabling breakpoints " |
6259 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 6260 | solib->so_name); |
84acb35a | 6261 | } |
e2dd7057 | 6262 | disabled_shlib_breaks = 1; |
84acb35a JJ |
6263 | } |
6264 | } | |
84acb35a JJ |
6265 | } |
6266 | ||
ce78b96d JB |
6267 | /* FORK & VFORK catchpoints. */ |
6268 | ||
e29a4733 PA |
6269 | /* An instance of this type is used to represent a fork or vfork |
6270 | catchpoint. It includes a "struct breakpoint" as a kind of base | |
6271 | class; users downcast to "struct breakpoint *" when needed. A | |
6272 | breakpoint is really of this type iff its ops pointer points to | |
6273 | CATCH_FORK_BREAKPOINT_OPS. */ | |
6274 | ||
6275 | struct fork_catchpoint | |
6276 | { | |
6277 | /* The base class. */ | |
6278 | struct breakpoint base; | |
6279 | ||
6280 | /* Process id of a child process whose forking triggered this | |
6281 | catchpoint. This field is only valid immediately after this | |
6282 | catchpoint has triggered. */ | |
6283 | ptid_t forked_inferior_pid; | |
6284 | }; | |
6285 | ||
4a64f543 MS |
6286 | /* Implement the "insert" breakpoint_ops method for fork |
6287 | catchpoints. */ | |
ce78b96d | 6288 | |
77b06cd7 TJB |
6289 | static int |
6290 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 6291 | { |
77b06cd7 | 6292 | return target_insert_fork_catchpoint (PIDGET (inferior_ptid)); |
ce78b96d JB |
6293 | } |
6294 | ||
4a64f543 MS |
6295 | /* Implement the "remove" breakpoint_ops method for fork |
6296 | catchpoints. */ | |
ce78b96d JB |
6297 | |
6298 | static int | |
77b06cd7 | 6299 | remove_catch_fork (struct bp_location *bl) |
ce78b96d JB |
6300 | { |
6301 | return target_remove_fork_catchpoint (PIDGET (inferior_ptid)); | |
6302 | } | |
6303 | ||
6304 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
6305 | catchpoints. */ | |
6306 | ||
6307 | static int | |
f1310107 | 6308 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
09ac7c10 TT |
6309 | struct address_space *aspace, CORE_ADDR bp_addr, |
6310 | const struct target_waitstatus *ws) | |
ce78b96d | 6311 | { |
e29a4733 PA |
6312 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
6313 | ||
f90263c1 TT |
6314 | if (ws->kind != TARGET_WAITKIND_FORKED) |
6315 | return 0; | |
6316 | ||
6317 | c->forked_inferior_pid = ws->value.related_pid; | |
6318 | return 1; | |
ce78b96d JB |
6319 | } |
6320 | ||
4a64f543 MS |
6321 | /* Implement the "print_it" breakpoint_ops method for fork |
6322 | catchpoints. */ | |
ce78b96d JB |
6323 | |
6324 | static enum print_stop_action | |
348d480f | 6325 | print_it_catch_fork (bpstat bs) |
ce78b96d | 6326 | { |
36dfb11c | 6327 | struct ui_out *uiout = current_uiout; |
348d480f PA |
6328 | struct breakpoint *b = bs->breakpoint_at; |
6329 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; | |
e29a4733 | 6330 | |
ce78b96d | 6331 | annotate_catchpoint (b->number); |
36dfb11c TT |
6332 | if (b->disposition == disp_del) |
6333 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
6334 | else | |
6335 | ui_out_text (uiout, "\nCatchpoint "); | |
6336 | if (ui_out_is_mi_like_p (uiout)) | |
6337 | { | |
6338 | ui_out_field_string (uiout, "reason", | |
6339 | async_reason_lookup (EXEC_ASYNC_FORK)); | |
6340 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
6341 | } | |
6342 | ui_out_field_int (uiout, "bkptno", b->number); | |
6343 | ui_out_text (uiout, " (forked process "); | |
6344 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
6345 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
6346 | return PRINT_SRC_AND_LOC; |
6347 | } | |
6348 | ||
4a64f543 MS |
6349 | /* Implement the "print_one" breakpoint_ops method for fork |
6350 | catchpoints. */ | |
ce78b96d JB |
6351 | |
6352 | static void | |
a6d9a66e | 6353 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 6354 | { |
e29a4733 | 6355 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 6356 | struct value_print_options opts; |
79a45e25 | 6357 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
6358 | |
6359 | get_user_print_options (&opts); | |
6360 | ||
4a64f543 MS |
6361 | /* Field 4, the address, is omitted (which makes the columns not |
6362 | line up too nicely with the headers, but the effect is relatively | |
6363 | readable). */ | |
79a45b7d | 6364 | if (opts.addressprint) |
ce78b96d JB |
6365 | ui_out_field_skip (uiout, "addr"); |
6366 | annotate_field (5); | |
6367 | ui_out_text (uiout, "fork"); | |
e29a4733 | 6368 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
6369 | { |
6370 | ui_out_text (uiout, ", process "); | |
6371 | ui_out_field_int (uiout, "what", | |
e29a4733 | 6372 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
6373 | ui_out_spaces (uiout, 1); |
6374 | } | |
6375 | } | |
6376 | ||
6377 | /* Implement the "print_mention" breakpoint_ops method for fork | |
6378 | catchpoints. */ | |
6379 | ||
6380 | static void | |
6381 | print_mention_catch_fork (struct breakpoint *b) | |
6382 | { | |
6383 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
6384 | } | |
6385 | ||
6149aea9 PA |
6386 | /* Implement the "print_recreate" breakpoint_ops method for fork |
6387 | catchpoints. */ | |
6388 | ||
6389 | static void | |
6390 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
6391 | { | |
6392 | fprintf_unfiltered (fp, "catch fork"); | |
d9b3f62e | 6393 | print_recreate_thread (b, fp); |
6149aea9 PA |
6394 | } |
6395 | ||
ce78b96d JB |
6396 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
6397 | ||
2060206e | 6398 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
ce78b96d | 6399 | |
4a64f543 MS |
6400 | /* Implement the "insert" breakpoint_ops method for vfork |
6401 | catchpoints. */ | |
ce78b96d | 6402 | |
77b06cd7 TJB |
6403 | static int |
6404 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 6405 | { |
77b06cd7 | 6406 | return target_insert_vfork_catchpoint (PIDGET (inferior_ptid)); |
ce78b96d JB |
6407 | } |
6408 | ||
4a64f543 MS |
6409 | /* Implement the "remove" breakpoint_ops method for vfork |
6410 | catchpoints. */ | |
ce78b96d JB |
6411 | |
6412 | static int | |
77b06cd7 | 6413 | remove_catch_vfork (struct bp_location *bl) |
ce78b96d JB |
6414 | { |
6415 | return target_remove_vfork_catchpoint (PIDGET (inferior_ptid)); | |
6416 | } | |
6417 | ||
6418 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
6419 | catchpoints. */ | |
6420 | ||
6421 | static int | |
f1310107 | 6422 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
09ac7c10 TT |
6423 | struct address_space *aspace, CORE_ADDR bp_addr, |
6424 | const struct target_waitstatus *ws) | |
ce78b96d | 6425 | { |
e29a4733 PA |
6426 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
6427 | ||
f90263c1 TT |
6428 | if (ws->kind != TARGET_WAITKIND_VFORKED) |
6429 | return 0; | |
6430 | ||
6431 | c->forked_inferior_pid = ws->value.related_pid; | |
6432 | return 1; | |
ce78b96d JB |
6433 | } |
6434 | ||
4a64f543 MS |
6435 | /* Implement the "print_it" breakpoint_ops method for vfork |
6436 | catchpoints. */ | |
ce78b96d JB |
6437 | |
6438 | static enum print_stop_action | |
348d480f | 6439 | print_it_catch_vfork (bpstat bs) |
ce78b96d | 6440 | { |
36dfb11c | 6441 | struct ui_out *uiout = current_uiout; |
348d480f | 6442 | struct breakpoint *b = bs->breakpoint_at; |
e29a4733 PA |
6443 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
6444 | ||
ce78b96d | 6445 | annotate_catchpoint (b->number); |
36dfb11c TT |
6446 | if (b->disposition == disp_del) |
6447 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
6448 | else | |
6449 | ui_out_text (uiout, "\nCatchpoint "); | |
6450 | if (ui_out_is_mi_like_p (uiout)) | |
6451 | { | |
6452 | ui_out_field_string (uiout, "reason", | |
6453 | async_reason_lookup (EXEC_ASYNC_VFORK)); | |
6454 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
6455 | } | |
6456 | ui_out_field_int (uiout, "bkptno", b->number); | |
6457 | ui_out_text (uiout, " (vforked process "); | |
6458 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
6459 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
6460 | return PRINT_SRC_AND_LOC; |
6461 | } | |
6462 | ||
4a64f543 MS |
6463 | /* Implement the "print_one" breakpoint_ops method for vfork |
6464 | catchpoints. */ | |
ce78b96d JB |
6465 | |
6466 | static void | |
a6d9a66e | 6467 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 6468 | { |
e29a4733 | 6469 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 6470 | struct value_print_options opts; |
79a45e25 | 6471 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
6472 | |
6473 | get_user_print_options (&opts); | |
4a64f543 MS |
6474 | /* Field 4, the address, is omitted (which makes the columns not |
6475 | line up too nicely with the headers, but the effect is relatively | |
6476 | readable). */ | |
79a45b7d | 6477 | if (opts.addressprint) |
ce78b96d JB |
6478 | ui_out_field_skip (uiout, "addr"); |
6479 | annotate_field (5); | |
6480 | ui_out_text (uiout, "vfork"); | |
e29a4733 | 6481 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
6482 | { |
6483 | ui_out_text (uiout, ", process "); | |
6484 | ui_out_field_int (uiout, "what", | |
e29a4733 | 6485 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
6486 | ui_out_spaces (uiout, 1); |
6487 | } | |
6488 | } | |
6489 | ||
6490 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
6491 | catchpoints. */ | |
6492 | ||
6493 | static void | |
6494 | print_mention_catch_vfork (struct breakpoint *b) | |
6495 | { | |
6496 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
6497 | } | |
6498 | ||
6149aea9 PA |
6499 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
6500 | catchpoints. */ | |
6501 | ||
6502 | static void | |
6503 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
6504 | { | |
6505 | fprintf_unfiltered (fp, "catch vfork"); | |
d9b3f62e | 6506 | print_recreate_thread (b, fp); |
6149aea9 PA |
6507 | } |
6508 | ||
ce78b96d JB |
6509 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
6510 | ||
2060206e | 6511 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
ce78b96d | 6512 | |
edcc5120 TT |
6513 | /* An instance of this type is used to represent an solib catchpoint. |
6514 | It includes a "struct breakpoint" as a kind of base class; users | |
6515 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
6516 | really of this type iff its ops pointer points to | |
6517 | CATCH_SOLIB_BREAKPOINT_OPS. */ | |
6518 | ||
6519 | struct solib_catchpoint | |
6520 | { | |
6521 | /* The base class. */ | |
6522 | struct breakpoint base; | |
6523 | ||
6524 | /* True for "catch load", false for "catch unload". */ | |
6525 | unsigned char is_load; | |
6526 | ||
6527 | /* Regular expression to match, if any. COMPILED is only valid when | |
6528 | REGEX is non-NULL. */ | |
6529 | char *regex; | |
6530 | regex_t compiled; | |
6531 | }; | |
6532 | ||
6533 | static void | |
6534 | dtor_catch_solib (struct breakpoint *b) | |
6535 | { | |
6536 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
6537 | ||
6538 | if (self->regex) | |
6539 | regfree (&self->compiled); | |
6540 | xfree (self->regex); | |
6541 | ||
6542 | base_breakpoint_ops.dtor (b); | |
6543 | } | |
6544 | ||
6545 | static int | |
6546 | insert_catch_solib (struct bp_location *ignore) | |
6547 | { | |
6548 | return 0; | |
6549 | } | |
6550 | ||
6551 | static int | |
6552 | remove_catch_solib (struct bp_location *ignore) | |
6553 | { | |
6554 | return 0; | |
6555 | } | |
6556 | ||
6557 | static int | |
6558 | breakpoint_hit_catch_solib (const struct bp_location *bl, | |
6559 | struct address_space *aspace, | |
6560 | CORE_ADDR bp_addr, | |
6561 | const struct target_waitstatus *ws) | |
6562 | { | |
6563 | struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner; | |
6564 | struct breakpoint *other; | |
6565 | ||
6566 | if (ws->kind == TARGET_WAITKIND_LOADED) | |
6567 | return 1; | |
6568 | ||
6569 | ALL_BREAKPOINTS (other) | |
6570 | { | |
6571 | struct bp_location *other_bl; | |
6572 | ||
6573 | if (other == bl->owner) | |
6574 | continue; | |
6575 | ||
6576 | if (other->type != bp_shlib_event) | |
6577 | continue; | |
6578 | ||
6579 | if (self->base.pspace != NULL && other->pspace != self->base.pspace) | |
6580 | continue; | |
6581 | ||
6582 | for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next) | |
6583 | { | |
6584 | if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) | |
6585 | return 1; | |
6586 | } | |
6587 | } | |
6588 | ||
6589 | return 0; | |
6590 | } | |
6591 | ||
6592 | static void | |
6593 | check_status_catch_solib (struct bpstats *bs) | |
6594 | { | |
6595 | struct solib_catchpoint *self | |
6596 | = (struct solib_catchpoint *) bs->breakpoint_at; | |
6597 | int ix; | |
6598 | ||
6599 | if (self->is_load) | |
6600 | { | |
6601 | struct so_list *iter; | |
6602 | ||
6603 | for (ix = 0; | |
6604 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
6605 | ix, iter); | |
6606 | ++ix) | |
6607 | { | |
6608 | if (!self->regex | |
6609 | || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0) | |
6610 | return; | |
6611 | } | |
6612 | } | |
6613 | else | |
6614 | { | |
6615 | char *iter; | |
6616 | ||
6617 | for (ix = 0; | |
6618 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
6619 | ix, iter); | |
6620 | ++ix) | |
6621 | { | |
6622 | if (!self->regex | |
6623 | || regexec (&self->compiled, iter, 0, NULL, 0) == 0) | |
6624 | return; | |
6625 | } | |
6626 | } | |
6627 | ||
6628 | bs->stop = 0; | |
6629 | bs->print_it = print_it_noop; | |
6630 | } | |
6631 | ||
6632 | static enum print_stop_action | |
6633 | print_it_catch_solib (bpstat bs) | |
6634 | { | |
6635 | struct breakpoint *b = bs->breakpoint_at; | |
6636 | struct ui_out *uiout = current_uiout; | |
6637 | ||
6638 | annotate_catchpoint (b->number); | |
6639 | if (b->disposition == disp_del) | |
6640 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
6641 | else | |
6642 | ui_out_text (uiout, "\nCatchpoint "); | |
6643 | ui_out_field_int (uiout, "bkptno", b->number); | |
6644 | ui_out_text (uiout, "\n"); | |
6645 | if (ui_out_is_mi_like_p (uiout)) | |
6646 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
6647 | print_solib_event (1); | |
6648 | return PRINT_SRC_AND_LOC; | |
6649 | } | |
6650 | ||
6651 | static void | |
6652 | print_one_catch_solib (struct breakpoint *b, struct bp_location **locs) | |
6653 | { | |
6654 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
6655 | struct value_print_options opts; | |
6656 | struct ui_out *uiout = current_uiout; | |
6657 | char *msg; | |
6658 | ||
6659 | get_user_print_options (&opts); | |
6660 | /* Field 4, the address, is omitted (which makes the columns not | |
6661 | line up too nicely with the headers, but the effect is relatively | |
6662 | readable). */ | |
6663 | if (opts.addressprint) | |
6664 | { | |
6665 | annotate_field (4); | |
6666 | ui_out_field_skip (uiout, "addr"); | |
6667 | } | |
6668 | ||
6669 | annotate_field (5); | |
6670 | if (self->is_load) | |
6671 | { | |
6672 | if (self->regex) | |
6673 | msg = xstrprintf (_("load of library matching %s"), self->regex); | |
6674 | else | |
6675 | msg = xstrdup (_("load of library")); | |
6676 | } | |
6677 | else | |
6678 | { | |
6679 | if (self->regex) | |
6680 | msg = xstrprintf (_("unload of library matching %s"), self->regex); | |
6681 | else | |
6682 | msg = xstrdup (_("unload of library")); | |
6683 | } | |
6684 | ui_out_field_string (uiout, "what", msg); | |
6685 | xfree (msg); | |
6686 | } | |
6687 | ||
6688 | static void | |
6689 | print_mention_catch_solib (struct breakpoint *b) | |
6690 | { | |
6691 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
6692 | ||
6693 | printf_filtered (_("Catchpoint %d (%s)"), b->number, | |
6694 | self->is_load ? "load" : "unload"); | |
6695 | } | |
6696 | ||
6697 | static void | |
6698 | print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp) | |
6699 | { | |
6700 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
6701 | ||
6702 | fprintf_unfiltered (fp, "%s %s", | |
6703 | b->disposition == disp_del ? "tcatch" : "catch", | |
6704 | self->is_load ? "load" : "unload"); | |
6705 | if (self->regex) | |
6706 | fprintf_unfiltered (fp, " %s", self->regex); | |
6707 | fprintf_unfiltered (fp, "\n"); | |
6708 | } | |
6709 | ||
6710 | static struct breakpoint_ops catch_solib_breakpoint_ops; | |
6711 | ||
6712 | /* A helper function that does all the work for "catch load" and | |
6713 | "catch unload". */ | |
6714 | ||
6715 | static void | |
6716 | catch_load_or_unload (char *arg, int from_tty, int is_load, | |
6717 | struct cmd_list_element *command) | |
6718 | { | |
6719 | struct solib_catchpoint *c; | |
6720 | struct gdbarch *gdbarch = get_current_arch (); | |
6721 | int tempflag; | |
6722 | regex_t compiled; | |
6723 | struct cleanup *cleanup; | |
6724 | ||
6725 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
6726 | ||
6727 | if (!arg) | |
6728 | arg = ""; | |
6729 | arg = skip_spaces (arg); | |
6730 | ||
6731 | c = XCNEW (struct solib_catchpoint); | |
6732 | cleanup = make_cleanup (xfree, c); | |
6733 | ||
6734 | if (*arg != '\0') | |
6735 | { | |
6736 | int errcode; | |
6737 | ||
6738 | errcode = regcomp (&c->compiled, arg, REG_NOSUB); | |
6739 | if (errcode != 0) | |
6740 | { | |
6741 | char *err = get_regcomp_error (errcode, &c->compiled); | |
6742 | ||
6743 | make_cleanup (xfree, err); | |
6744 | error (_("Invalid regexp (%s): %s"), err, arg); | |
6745 | } | |
6746 | c->regex = xstrdup (arg); | |
6747 | } | |
6748 | ||
6749 | c->is_load = is_load; | |
6750 | init_catchpoint (&c->base, gdbarch, tempflag, NULL, | |
6751 | &catch_solib_breakpoint_ops); | |
6752 | ||
6753 | discard_cleanups (cleanup); | |
6754 | install_breakpoint (0, &c->base, 1); | |
6755 | } | |
6756 | ||
6757 | static void | |
6758 | catch_load_command_1 (char *arg, int from_tty, | |
6759 | struct cmd_list_element *command) | |
6760 | { | |
6761 | catch_load_or_unload (arg, from_tty, 1, command); | |
6762 | } | |
6763 | ||
6764 | static void | |
6765 | catch_unload_command_1 (char *arg, int from_tty, | |
6766 | struct cmd_list_element *command) | |
6767 | { | |
6768 | catch_load_or_unload (arg, from_tty, 0, command); | |
6769 | } | |
6770 | ||
be5c67c1 PA |
6771 | /* An instance of this type is used to represent a syscall catchpoint. |
6772 | It includes a "struct breakpoint" as a kind of base class; users | |
6773 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
6774 | really of this type iff its ops pointer points to | |
6775 | CATCH_SYSCALL_BREAKPOINT_OPS. */ | |
6776 | ||
6777 | struct syscall_catchpoint | |
6778 | { | |
6779 | /* The base class. */ | |
6780 | struct breakpoint base; | |
6781 | ||
6782 | /* Syscall numbers used for the 'catch syscall' feature. If no | |
6783 | syscall has been specified for filtering, its value is NULL. | |
6784 | Otherwise, it holds a list of all syscalls to be caught. The | |
6785 | list elements are allocated with xmalloc. */ | |
6786 | VEC(int) *syscalls_to_be_caught; | |
6787 | }; | |
6788 | ||
6789 | /* Implement the "dtor" breakpoint_ops method for syscall | |
6790 | catchpoints. */ | |
6791 | ||
6792 | static void | |
6793 | dtor_catch_syscall (struct breakpoint *b) | |
6794 | { | |
6795 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; | |
6796 | ||
6797 | VEC_free (int, c->syscalls_to_be_caught); | |
348d480f | 6798 | |
2060206e | 6799 | base_breakpoint_ops.dtor (b); |
be5c67c1 PA |
6800 | } |
6801 | ||
a96d9b2e SDJ |
6802 | /* Implement the "insert" breakpoint_ops method for syscall |
6803 | catchpoints. */ | |
6804 | ||
77b06cd7 TJB |
6805 | static int |
6806 | insert_catch_syscall (struct bp_location *bl) | |
a96d9b2e | 6807 | { |
be5c67c1 | 6808 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; |
a96d9b2e SDJ |
6809 | struct inferior *inf = current_inferior (); |
6810 | ||
6811 | ++inf->total_syscalls_count; | |
be5c67c1 | 6812 | if (!c->syscalls_to_be_caught) |
a96d9b2e SDJ |
6813 | ++inf->any_syscall_count; |
6814 | else | |
6815 | { | |
6816 | int i, iter; | |
cc59ec59 | 6817 | |
a96d9b2e | 6818 | for (i = 0; |
be5c67c1 | 6819 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6820 | i++) |
6821 | { | |
6822 | int elem; | |
cc59ec59 | 6823 | |
a96d9b2e SDJ |
6824 | if (iter >= VEC_length (int, inf->syscalls_counts)) |
6825 | { | |
6826 | int old_size = VEC_length (int, inf->syscalls_counts); | |
3e43a32a MS |
6827 | uintptr_t vec_addr_offset |
6828 | = old_size * ((uintptr_t) sizeof (int)); | |
a96d9b2e SDJ |
6829 | uintptr_t vec_addr; |
6830 | VEC_safe_grow (int, inf->syscalls_counts, iter + 1); | |
6831 | vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) + | |
6832 | vec_addr_offset; | |
6833 | memset ((void *) vec_addr, 0, | |
6834 | (iter + 1 - old_size) * sizeof (int)); | |
6835 | } | |
6836 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
6837 | VEC_replace (int, inf->syscalls_counts, iter, ++elem); | |
6838 | } | |
6839 | } | |
6840 | ||
77b06cd7 TJB |
6841 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), |
6842 | inf->total_syscalls_count != 0, | |
6843 | inf->any_syscall_count, | |
6844 | VEC_length (int, inf->syscalls_counts), | |
6845 | VEC_address (int, inf->syscalls_counts)); | |
a96d9b2e SDJ |
6846 | } |
6847 | ||
6848 | /* Implement the "remove" breakpoint_ops method for syscall | |
6849 | catchpoints. */ | |
6850 | ||
6851 | static int | |
77b06cd7 | 6852 | remove_catch_syscall (struct bp_location *bl) |
a96d9b2e | 6853 | { |
be5c67c1 | 6854 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; |
a96d9b2e SDJ |
6855 | struct inferior *inf = current_inferior (); |
6856 | ||
6857 | --inf->total_syscalls_count; | |
be5c67c1 | 6858 | if (!c->syscalls_to_be_caught) |
a96d9b2e SDJ |
6859 | --inf->any_syscall_count; |
6860 | else | |
6861 | { | |
6862 | int i, iter; | |
cc59ec59 | 6863 | |
a96d9b2e | 6864 | for (i = 0; |
be5c67c1 | 6865 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6866 | i++) |
6867 | { | |
6868 | int elem; | |
6869 | if (iter >= VEC_length (int, inf->syscalls_counts)) | |
6870 | /* Shouldn't happen. */ | |
6871 | continue; | |
6872 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
6873 | VEC_replace (int, inf->syscalls_counts, iter, --elem); | |
6874 | } | |
6875 | } | |
6876 | ||
6877 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
6878 | inf->total_syscalls_count != 0, | |
6879 | inf->any_syscall_count, | |
6880 | VEC_length (int, inf->syscalls_counts), | |
3e43a32a MS |
6881 | VEC_address (int, |
6882 | inf->syscalls_counts)); | |
a96d9b2e SDJ |
6883 | } |
6884 | ||
6885 | /* Implement the "breakpoint_hit" breakpoint_ops method for syscall | |
6886 | catchpoints. */ | |
6887 | ||
6888 | static int | |
f1310107 | 6889 | breakpoint_hit_catch_syscall (const struct bp_location *bl, |
09ac7c10 TT |
6890 | struct address_space *aspace, CORE_ADDR bp_addr, |
6891 | const struct target_waitstatus *ws) | |
a96d9b2e | 6892 | { |
4a64f543 MS |
6893 | /* We must check if we are catching specific syscalls in this |
6894 | breakpoint. If we are, then we must guarantee that the called | |
6895 | syscall is the same syscall we are catching. */ | |
a96d9b2e | 6896 | int syscall_number = 0; |
be5c67c1 PA |
6897 | const struct syscall_catchpoint *c |
6898 | = (const struct syscall_catchpoint *) bl->owner; | |
a96d9b2e | 6899 | |
f90263c1 TT |
6900 | if (ws->kind != TARGET_WAITKIND_SYSCALL_ENTRY |
6901 | && ws->kind != TARGET_WAITKIND_SYSCALL_RETURN) | |
a96d9b2e SDJ |
6902 | return 0; |
6903 | ||
f90263c1 TT |
6904 | syscall_number = ws->value.syscall_number; |
6905 | ||
a96d9b2e | 6906 | /* Now, checking if the syscall is the same. */ |
be5c67c1 | 6907 | if (c->syscalls_to_be_caught) |
a96d9b2e SDJ |
6908 | { |
6909 | int i, iter; | |
cc59ec59 | 6910 | |
a96d9b2e | 6911 | for (i = 0; |
be5c67c1 | 6912 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6913 | i++) |
6914 | if (syscall_number == iter) | |
6915 | break; | |
6916 | /* Not the same. */ | |
6917 | if (!iter) | |
6918 | return 0; | |
6919 | } | |
6920 | ||
6921 | return 1; | |
6922 | } | |
6923 | ||
6924 | /* Implement the "print_it" breakpoint_ops method for syscall | |
6925 | catchpoints. */ | |
6926 | ||
6927 | static enum print_stop_action | |
348d480f | 6928 | print_it_catch_syscall (bpstat bs) |
a96d9b2e | 6929 | { |
36dfb11c | 6930 | struct ui_out *uiout = current_uiout; |
348d480f | 6931 | struct breakpoint *b = bs->breakpoint_at; |
a96d9b2e SDJ |
6932 | /* These are needed because we want to know in which state a |
6933 | syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY | |
6934 | or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we | |
6935 | must print "called syscall" or "returned from syscall". */ | |
6936 | ptid_t ptid; | |
6937 | struct target_waitstatus last; | |
6938 | struct syscall s; | |
a96d9b2e SDJ |
6939 | char *syscall_id; |
6940 | ||
6941 | get_last_target_status (&ptid, &last); | |
6942 | ||
6943 | get_syscall_by_number (last.value.syscall_number, &s); | |
6944 | ||
6945 | annotate_catchpoint (b->number); | |
6946 | ||
36dfb11c TT |
6947 | if (b->disposition == disp_del) |
6948 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
a96d9b2e | 6949 | else |
36dfb11c TT |
6950 | ui_out_text (uiout, "\nCatchpoint "); |
6951 | if (ui_out_is_mi_like_p (uiout)) | |
6952 | { | |
6953 | ui_out_field_string (uiout, "reason", | |
6954 | async_reason_lookup (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY | |
6955 | ? EXEC_ASYNC_SYSCALL_ENTRY | |
6956 | : EXEC_ASYNC_SYSCALL_RETURN)); | |
6957 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
6958 | } | |
6959 | ui_out_field_int (uiout, "bkptno", b->number); | |
a96d9b2e SDJ |
6960 | |
6961 | if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) | |
36dfb11c TT |
6962 | ui_out_text (uiout, " (call to syscall "); |
6963 | else | |
6964 | ui_out_text (uiout, " (returned from syscall "); | |
a96d9b2e | 6965 | |
36dfb11c TT |
6966 | if (s.name == NULL || ui_out_is_mi_like_p (uiout)) |
6967 | ui_out_field_int (uiout, "syscall-number", last.value.syscall_number); | |
6968 | if (s.name != NULL) | |
6969 | ui_out_field_string (uiout, "syscall-name", s.name); | |
6970 | ||
6971 | ui_out_text (uiout, "), "); | |
a96d9b2e SDJ |
6972 | |
6973 | return PRINT_SRC_AND_LOC; | |
6974 | } | |
6975 | ||
6976 | /* Implement the "print_one" breakpoint_ops method for syscall | |
6977 | catchpoints. */ | |
6978 | ||
6979 | static void | |
6980 | print_one_catch_syscall (struct breakpoint *b, | |
f1310107 | 6981 | struct bp_location **last_loc) |
a96d9b2e | 6982 | { |
be5c67c1 | 6983 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
a96d9b2e | 6984 | struct value_print_options opts; |
79a45e25 | 6985 | struct ui_out *uiout = current_uiout; |
a96d9b2e SDJ |
6986 | |
6987 | get_user_print_options (&opts); | |
4a64f543 MS |
6988 | /* Field 4, the address, is omitted (which makes the columns not |
6989 | line up too nicely with the headers, but the effect is relatively | |
6990 | readable). */ | |
a96d9b2e SDJ |
6991 | if (opts.addressprint) |
6992 | ui_out_field_skip (uiout, "addr"); | |
6993 | annotate_field (5); | |
6994 | ||
be5c67c1 PA |
6995 | if (c->syscalls_to_be_caught |
6996 | && VEC_length (int, c->syscalls_to_be_caught) > 1) | |
a96d9b2e SDJ |
6997 | ui_out_text (uiout, "syscalls \""); |
6998 | else | |
6999 | ui_out_text (uiout, "syscall \""); | |
7000 | ||
be5c67c1 | 7001 | if (c->syscalls_to_be_caught) |
a96d9b2e SDJ |
7002 | { |
7003 | int i, iter; | |
7004 | char *text = xstrprintf ("%s", ""); | |
cc59ec59 | 7005 | |
a96d9b2e | 7006 | for (i = 0; |
be5c67c1 | 7007 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
7008 | i++) |
7009 | { | |
7010 | char *x = text; | |
7011 | struct syscall s; | |
7012 | get_syscall_by_number (iter, &s); | |
7013 | ||
7014 | if (s.name != NULL) | |
7015 | text = xstrprintf ("%s%s, ", text, s.name); | |
7016 | else | |
7017 | text = xstrprintf ("%s%d, ", text, iter); | |
7018 | ||
7019 | /* We have to xfree the last 'text' (now stored at 'x') | |
e5dd4106 | 7020 | because xstrprintf dynamically allocates new space for it |
a96d9b2e SDJ |
7021 | on every call. */ |
7022 | xfree (x); | |
7023 | } | |
7024 | /* Remove the last comma. */ | |
7025 | text[strlen (text) - 2] = '\0'; | |
7026 | ui_out_field_string (uiout, "what", text); | |
7027 | } | |
7028 | else | |
7029 | ui_out_field_string (uiout, "what", "<any syscall>"); | |
7030 | ui_out_text (uiout, "\" "); | |
7031 | } | |
7032 | ||
7033 | /* Implement the "print_mention" breakpoint_ops method for syscall | |
7034 | catchpoints. */ | |
7035 | ||
7036 | static void | |
7037 | print_mention_catch_syscall (struct breakpoint *b) | |
7038 | { | |
be5c67c1 PA |
7039 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
7040 | ||
7041 | if (c->syscalls_to_be_caught) | |
a96d9b2e SDJ |
7042 | { |
7043 | int i, iter; | |
7044 | ||
be5c67c1 | 7045 | if (VEC_length (int, c->syscalls_to_be_caught) > 1) |
a96d9b2e SDJ |
7046 | printf_filtered (_("Catchpoint %d (syscalls"), b->number); |
7047 | else | |
7048 | printf_filtered (_("Catchpoint %d (syscall"), b->number); | |
7049 | ||
7050 | for (i = 0; | |
be5c67c1 | 7051 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
7052 | i++) |
7053 | { | |
7054 | struct syscall s; | |
7055 | get_syscall_by_number (iter, &s); | |
7056 | ||
7057 | if (s.name) | |
7058 | printf_filtered (" '%s' [%d]", s.name, s.number); | |
7059 | else | |
7060 | printf_filtered (" %d", s.number); | |
7061 | } | |
7062 | printf_filtered (")"); | |
7063 | } | |
7064 | else | |
7065 | printf_filtered (_("Catchpoint %d (any syscall)"), | |
7066 | b->number); | |
7067 | } | |
7068 | ||
6149aea9 PA |
7069 | /* Implement the "print_recreate" breakpoint_ops method for syscall |
7070 | catchpoints. */ | |
7071 | ||
7072 | static void | |
7073 | print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp) | |
7074 | { | |
be5c67c1 PA |
7075 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
7076 | ||
6149aea9 PA |
7077 | fprintf_unfiltered (fp, "catch syscall"); |
7078 | ||
be5c67c1 | 7079 | if (c->syscalls_to_be_caught) |
6149aea9 PA |
7080 | { |
7081 | int i, iter; | |
7082 | ||
7083 | for (i = 0; | |
be5c67c1 | 7084 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
6149aea9 PA |
7085 | i++) |
7086 | { | |
7087 | struct syscall s; | |
7088 | ||
7089 | get_syscall_by_number (iter, &s); | |
7090 | if (s.name) | |
7091 | fprintf_unfiltered (fp, " %s", s.name); | |
7092 | else | |
7093 | fprintf_unfiltered (fp, " %d", s.number); | |
7094 | } | |
7095 | } | |
d9b3f62e | 7096 | print_recreate_thread (b, fp); |
6149aea9 PA |
7097 | } |
7098 | ||
a96d9b2e SDJ |
7099 | /* The breakpoint_ops structure to be used in syscall catchpoints. */ |
7100 | ||
2060206e | 7101 | static struct breakpoint_ops catch_syscall_breakpoint_ops; |
a96d9b2e SDJ |
7102 | |
7103 | /* Returns non-zero if 'b' is a syscall catchpoint. */ | |
7104 | ||
7105 | static int | |
7106 | syscall_catchpoint_p (struct breakpoint *b) | |
7107 | { | |
7108 | return (b->ops == &catch_syscall_breakpoint_ops); | |
7109 | } | |
7110 | ||
346774a9 PA |
7111 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
7112 | is non-zero, then make the breakpoint temporary. If COND_STRING is | |
7113 | not NULL, then store it in the breakpoint. OPS, if not NULL, is | |
7114 | the breakpoint_ops structure associated to the catchpoint. */ | |
ce78b96d | 7115 | |
346774a9 PA |
7116 | static void |
7117 | init_catchpoint (struct breakpoint *b, | |
7118 | struct gdbarch *gdbarch, int tempflag, | |
7119 | char *cond_string, | |
c0a91b2b | 7120 | const struct breakpoint_ops *ops) |
c906108c | 7121 | { |
c5aa993b | 7122 | struct symtab_and_line sal; |
346774a9 | 7123 | |
fe39c653 | 7124 | init_sal (&sal); |
6c95b8df | 7125 | sal.pspace = current_program_space; |
c5aa993b | 7126 | |
28010a5d | 7127 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 7128 | |
1b36a34b | 7129 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
b5de0fa7 | 7130 | b->disposition = tempflag ? disp_del : disp_donttouch; |
346774a9 PA |
7131 | } |
7132 | ||
28010a5d | 7133 | void |
3ea46bff | 7134 | install_breakpoint (int internal, struct breakpoint *b, int update_gll) |
c56053d2 PA |
7135 | { |
7136 | add_to_breakpoint_chain (b); | |
3a5c3e22 PA |
7137 | set_breakpoint_number (internal, b); |
7138 | if (!internal) | |
7139 | mention (b); | |
c56053d2 | 7140 | observer_notify_breakpoint_created (b); |
3ea46bff YQ |
7141 | |
7142 | if (update_gll) | |
7143 | update_global_location_list (1); | |
c56053d2 PA |
7144 | } |
7145 | ||
9b70b993 | 7146 | static void |
a6d9a66e UW |
7147 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
7148 | int tempflag, char *cond_string, | |
c0a91b2b | 7149 | const struct breakpoint_ops *ops) |
c906108c | 7150 | { |
e29a4733 | 7151 | struct fork_catchpoint *c = XNEW (struct fork_catchpoint); |
ce78b96d | 7152 | |
e29a4733 PA |
7153 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops); |
7154 | ||
7155 | c->forked_inferior_pid = null_ptid; | |
7156 | ||
3ea46bff | 7157 | install_breakpoint (0, &c->base, 1); |
c906108c SS |
7158 | } |
7159 | ||
fe798b75 JB |
7160 | /* Exec catchpoints. */ |
7161 | ||
b4d90040 PA |
7162 | /* An instance of this type is used to represent an exec catchpoint. |
7163 | It includes a "struct breakpoint" as a kind of base class; users | |
7164 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
7165 | really of this type iff its ops pointer points to | |
7166 | CATCH_EXEC_BREAKPOINT_OPS. */ | |
7167 | ||
7168 | struct exec_catchpoint | |
7169 | { | |
7170 | /* The base class. */ | |
7171 | struct breakpoint base; | |
7172 | ||
7173 | /* Filename of a program whose exec triggered this catchpoint. | |
7174 | This field is only valid immediately after this catchpoint has | |
7175 | triggered. */ | |
7176 | char *exec_pathname; | |
7177 | }; | |
7178 | ||
7179 | /* Implement the "dtor" breakpoint_ops method for exec | |
7180 | catchpoints. */ | |
7181 | ||
7182 | static void | |
7183 | dtor_catch_exec (struct breakpoint *b) | |
7184 | { | |
7185 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; | |
7186 | ||
7187 | xfree (c->exec_pathname); | |
348d480f | 7188 | |
2060206e | 7189 | base_breakpoint_ops.dtor (b); |
b4d90040 PA |
7190 | } |
7191 | ||
77b06cd7 TJB |
7192 | static int |
7193 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 7194 | { |
77b06cd7 | 7195 | return target_insert_exec_catchpoint (PIDGET (inferior_ptid)); |
fe798b75 | 7196 | } |
c906108c | 7197 | |
fe798b75 | 7198 | static int |
77b06cd7 | 7199 | remove_catch_exec (struct bp_location *bl) |
fe798b75 JB |
7200 | { |
7201 | return target_remove_exec_catchpoint (PIDGET (inferior_ptid)); | |
7202 | } | |
c906108c | 7203 | |
fe798b75 | 7204 | static int |
f1310107 | 7205 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
09ac7c10 TT |
7206 | struct address_space *aspace, CORE_ADDR bp_addr, |
7207 | const struct target_waitstatus *ws) | |
fe798b75 | 7208 | { |
b4d90040 PA |
7209 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
7210 | ||
f90263c1 TT |
7211 | if (ws->kind != TARGET_WAITKIND_EXECD) |
7212 | return 0; | |
7213 | ||
7214 | c->exec_pathname = xstrdup (ws->value.execd_pathname); | |
7215 | return 1; | |
fe798b75 | 7216 | } |
c906108c | 7217 | |
fe798b75 | 7218 | static enum print_stop_action |
348d480f | 7219 | print_it_catch_exec (bpstat bs) |
fe798b75 | 7220 | { |
36dfb11c | 7221 | struct ui_out *uiout = current_uiout; |
348d480f | 7222 | struct breakpoint *b = bs->breakpoint_at; |
b4d90040 PA |
7223 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
7224 | ||
fe798b75 | 7225 | annotate_catchpoint (b->number); |
36dfb11c TT |
7226 | if (b->disposition == disp_del) |
7227 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
7228 | else | |
7229 | ui_out_text (uiout, "\nCatchpoint "); | |
7230 | if (ui_out_is_mi_like_p (uiout)) | |
7231 | { | |
7232 | ui_out_field_string (uiout, "reason", | |
7233 | async_reason_lookup (EXEC_ASYNC_EXEC)); | |
7234 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
7235 | } | |
7236 | ui_out_field_int (uiout, "bkptno", b->number); | |
7237 | ui_out_text (uiout, " (exec'd "); | |
7238 | ui_out_field_string (uiout, "new-exec", c->exec_pathname); | |
7239 | ui_out_text (uiout, "), "); | |
7240 | ||
fe798b75 | 7241 | return PRINT_SRC_AND_LOC; |
c906108c SS |
7242 | } |
7243 | ||
fe798b75 | 7244 | static void |
a6d9a66e | 7245 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 | 7246 | { |
b4d90040 | 7247 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
fe798b75 | 7248 | struct value_print_options opts; |
79a45e25 | 7249 | struct ui_out *uiout = current_uiout; |
fe798b75 JB |
7250 | |
7251 | get_user_print_options (&opts); | |
7252 | ||
7253 | /* Field 4, the address, is omitted (which makes the columns | |
7254 | not line up too nicely with the headers, but the effect | |
7255 | is relatively readable). */ | |
7256 | if (opts.addressprint) | |
7257 | ui_out_field_skip (uiout, "addr"); | |
7258 | annotate_field (5); | |
7259 | ui_out_text (uiout, "exec"); | |
b4d90040 | 7260 | if (c->exec_pathname != NULL) |
fe798b75 JB |
7261 | { |
7262 | ui_out_text (uiout, ", program \""); | |
b4d90040 | 7263 | ui_out_field_string (uiout, "what", c->exec_pathname); |
fe798b75 JB |
7264 | ui_out_text (uiout, "\" "); |
7265 | } | |
7266 | } | |
7267 | ||
7268 | static void | |
7269 | print_mention_catch_exec (struct breakpoint *b) | |
7270 | { | |
7271 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
7272 | } | |
7273 | ||
6149aea9 PA |
7274 | /* Implement the "print_recreate" breakpoint_ops method for exec |
7275 | catchpoints. */ | |
7276 | ||
7277 | static void | |
7278 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
7279 | { | |
7280 | fprintf_unfiltered (fp, "catch exec"); | |
d9b3f62e | 7281 | print_recreate_thread (b, fp); |
6149aea9 PA |
7282 | } |
7283 | ||
2060206e | 7284 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
fe798b75 | 7285 | |
a96d9b2e SDJ |
7286 | static void |
7287 | create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, | |
c0a91b2b | 7288 | const struct breakpoint_ops *ops) |
a96d9b2e | 7289 | { |
be5c67c1 | 7290 | struct syscall_catchpoint *c; |
a96d9b2e | 7291 | struct gdbarch *gdbarch = get_current_arch (); |
a96d9b2e | 7292 | |
be5c67c1 PA |
7293 | c = XNEW (struct syscall_catchpoint); |
7294 | init_catchpoint (&c->base, gdbarch, tempflag, NULL, ops); | |
7295 | c->syscalls_to_be_caught = filter; | |
a96d9b2e | 7296 | |
3ea46bff | 7297 | install_breakpoint (0, &c->base, 1); |
a96d9b2e SDJ |
7298 | } |
7299 | ||
c906108c | 7300 | static int |
fba45db2 | 7301 | hw_breakpoint_used_count (void) |
c906108c | 7302 | { |
c906108c | 7303 | int i = 0; |
f1310107 TJB |
7304 | struct breakpoint *b; |
7305 | struct bp_location *bl; | |
c906108c SS |
7306 | |
7307 | ALL_BREAKPOINTS (b) | |
c5aa993b | 7308 | { |
d6b74ac4 | 7309 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
7310 | for (bl = b->loc; bl; bl = bl->next) |
7311 | { | |
7312 | /* Special types of hardware breakpoints may use more than | |
7313 | one register. */ | |
348d480f | 7314 | i += b->ops->resources_needed (bl); |
f1310107 | 7315 | } |
c5aa993b | 7316 | } |
c906108c SS |
7317 | |
7318 | return i; | |
7319 | } | |
7320 | ||
a1398e0c PA |
7321 | /* Returns the resources B would use if it were a hardware |
7322 | watchpoint. */ | |
7323 | ||
c906108c | 7324 | static int |
a1398e0c | 7325 | hw_watchpoint_use_count (struct breakpoint *b) |
c906108c | 7326 | { |
c906108c | 7327 | int i = 0; |
e09342b5 | 7328 | struct bp_location *bl; |
c906108c | 7329 | |
a1398e0c PA |
7330 | if (!breakpoint_enabled (b)) |
7331 | return 0; | |
7332 | ||
7333 | for (bl = b->loc; bl; bl = bl->next) | |
7334 | { | |
7335 | /* Special types of hardware watchpoints may use more than | |
7336 | one register. */ | |
7337 | i += b->ops->resources_needed (bl); | |
7338 | } | |
7339 | ||
7340 | return i; | |
7341 | } | |
7342 | ||
7343 | /* Returns the sum the used resources of all hardware watchpoints of | |
7344 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED | |
7345 | the sum of the used resources of all hardware watchpoints of other | |
7346 | types _not_ TYPE. */ | |
7347 | ||
7348 | static int | |
7349 | hw_watchpoint_used_count_others (struct breakpoint *except, | |
7350 | enum bptype type, int *other_type_used) | |
7351 | { | |
7352 | int i = 0; | |
7353 | struct breakpoint *b; | |
7354 | ||
c906108c SS |
7355 | *other_type_used = 0; |
7356 | ALL_BREAKPOINTS (b) | |
e09342b5 | 7357 | { |
a1398e0c PA |
7358 | if (b == except) |
7359 | continue; | |
e09342b5 TJB |
7360 | if (!breakpoint_enabled (b)) |
7361 | continue; | |
7362 | ||
a1398e0c PA |
7363 | if (b->type == type) |
7364 | i += hw_watchpoint_use_count (b); | |
7365 | else if (is_hardware_watchpoint (b)) | |
7366 | *other_type_used = 1; | |
e09342b5 TJB |
7367 | } |
7368 | ||
c906108c SS |
7369 | return i; |
7370 | } | |
7371 | ||
c906108c | 7372 | void |
fba45db2 | 7373 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 7374 | { |
c5aa993b | 7375 | struct breakpoint *b; |
c906108c SS |
7376 | |
7377 | ALL_BREAKPOINTS (b) | |
c5aa993b | 7378 | { |
cc60f2e3 | 7379 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 7380 | { |
b5de0fa7 | 7381 | b->enable_state = bp_call_disabled; |
b60e7edf | 7382 | update_global_location_list (0); |
c5aa993b JM |
7383 | } |
7384 | } | |
c906108c SS |
7385 | } |
7386 | ||
7387 | void | |
fba45db2 | 7388 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 7389 | { |
c5aa993b | 7390 | struct breakpoint *b; |
c906108c SS |
7391 | |
7392 | ALL_BREAKPOINTS (b) | |
c5aa993b | 7393 | { |
cc60f2e3 | 7394 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 7395 | { |
b5de0fa7 | 7396 | b->enable_state = bp_enabled; |
b60e7edf | 7397 | update_global_location_list (1); |
c5aa993b JM |
7398 | } |
7399 | } | |
c906108c SS |
7400 | } |
7401 | ||
8bea4e01 UW |
7402 | void |
7403 | disable_breakpoints_before_startup (void) | |
7404 | { | |
6c95b8df | 7405 | current_program_space->executing_startup = 1; |
f8eba3c6 | 7406 | update_global_location_list (0); |
8bea4e01 UW |
7407 | } |
7408 | ||
7409 | void | |
7410 | enable_breakpoints_after_startup (void) | |
7411 | { | |
6c95b8df | 7412 | current_program_space->executing_startup = 0; |
f8eba3c6 | 7413 | breakpoint_re_set (); |
8bea4e01 UW |
7414 | } |
7415 | ||
c906108c SS |
7416 | |
7417 | /* Set a breakpoint that will evaporate an end of command | |
7418 | at address specified by SAL. | |
7419 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
7420 | ||
7421 | struct breakpoint * | |
a6d9a66e UW |
7422 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
7423 | struct frame_id frame_id, enum bptype type) | |
c906108c | 7424 | { |
52f0bd74 | 7425 | struct breakpoint *b; |
edb3359d DJ |
7426 | |
7427 | /* If FRAME_ID is valid, it should be a real frame, not an inlined | |
7428 | one. */ | |
7429 | gdb_assert (!frame_id_inlined_p (frame_id)); | |
7430 | ||
06edf0c0 | 7431 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
7432 | b->enable_state = bp_enabled; |
7433 | b->disposition = disp_donttouch; | |
818dd999 | 7434 | b->frame_id = frame_id; |
c906108c | 7435 | |
4a64f543 MS |
7436 | /* If we're debugging a multi-threaded program, then we want |
7437 | momentary breakpoints to be active in only a single thread of | |
7438 | control. */ | |
39f77062 KB |
7439 | if (in_thread_list (inferior_ptid)) |
7440 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 7441 | |
b60e7edf | 7442 | update_global_location_list_nothrow (1); |
74960c60 | 7443 | |
c906108c SS |
7444 | return b; |
7445 | } | |
611c83ae | 7446 | |
06edf0c0 PA |
7447 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
7448 | The new breakpoint will have type TYPE, and use OPS as it | |
7449 | breakpoint_ops. */ | |
e58b0e63 | 7450 | |
06edf0c0 PA |
7451 | static struct breakpoint * |
7452 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
7453 | enum bptype type, | |
c0a91b2b | 7454 | const struct breakpoint_ops *ops) |
e58b0e63 PA |
7455 | { |
7456 | struct breakpoint *copy; | |
7457 | ||
06edf0c0 | 7458 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 7459 | copy->loc = allocate_bp_location (copy); |
0e30163f | 7460 | set_breakpoint_location_function (copy->loc, 1); |
e58b0e63 | 7461 | |
a6d9a66e | 7462 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
7463 | copy->loc->requested_address = orig->loc->requested_address; |
7464 | copy->loc->address = orig->loc->address; | |
7465 | copy->loc->section = orig->loc->section; | |
6c95b8df | 7466 | copy->loc->pspace = orig->loc->pspace; |
e58b0e63 | 7467 | |
f8eba3c6 TT |
7468 | if (orig->loc->source_file != NULL) |
7469 | copy->loc->source_file = xstrdup (orig->loc->source_file); | |
e58b0e63 | 7470 | |
f8eba3c6 | 7471 | copy->loc->line_number = orig->loc->line_number; |
e58b0e63 PA |
7472 | copy->frame_id = orig->frame_id; |
7473 | copy->thread = orig->thread; | |
6c95b8df | 7474 | copy->pspace = orig->pspace; |
e58b0e63 PA |
7475 | |
7476 | copy->enable_state = bp_enabled; | |
7477 | copy->disposition = disp_donttouch; | |
7478 | copy->number = internal_breakpoint_number--; | |
7479 | ||
7480 | update_global_location_list_nothrow (0); | |
7481 | return copy; | |
7482 | } | |
7483 | ||
06edf0c0 PA |
7484 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
7485 | ORIG is NULL. */ | |
7486 | ||
7487 | struct breakpoint * | |
7488 | clone_momentary_breakpoint (struct breakpoint *orig) | |
7489 | { | |
7490 | /* If there's nothing to clone, then return nothing. */ | |
7491 | if (orig == NULL) | |
7492 | return NULL; | |
7493 | ||
7494 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops); | |
7495 | } | |
7496 | ||
611c83ae | 7497 | struct breakpoint * |
a6d9a66e UW |
7498 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
7499 | enum bptype type) | |
611c83ae PA |
7500 | { |
7501 | struct symtab_and_line sal; | |
7502 | ||
7503 | sal = find_pc_line (pc, 0); | |
7504 | sal.pc = pc; | |
7505 | sal.section = find_pc_overlay (pc); | |
7506 | sal.explicit_pc = 1; | |
7507 | ||
a6d9a66e | 7508 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 7509 | } |
c906108c | 7510 | \f |
c5aa993b | 7511 | |
c906108c SS |
7512 | /* Tell the user we have just set a breakpoint B. */ |
7513 | ||
7514 | static void | |
fba45db2 | 7515 | mention (struct breakpoint *b) |
c906108c | 7516 | { |
348d480f | 7517 | b->ops->print_mention (b); |
79a45e25 | 7518 | if (ui_out_is_mi_like_p (current_uiout)) |
fb40c209 | 7519 | return; |
c906108c SS |
7520 | printf_filtered ("\n"); |
7521 | } | |
c906108c | 7522 | \f |
c5aa993b | 7523 | |
0d381245 | 7524 | static struct bp_location * |
39d61571 | 7525 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
7526 | const struct symtab_and_line *sal) |
7527 | { | |
7528 | struct bp_location *loc, **tmp; | |
3742cc8b YQ |
7529 | CORE_ADDR adjusted_address; |
7530 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); | |
7531 | ||
7532 | if (loc_gdbarch == NULL) | |
7533 | loc_gdbarch = b->gdbarch; | |
7534 | ||
7535 | /* Adjust the breakpoint's address prior to allocating a location. | |
7536 | Once we call allocate_bp_location(), that mostly uninitialized | |
7537 | location will be placed on the location chain. Adjustment of the | |
7538 | breakpoint may cause target_read_memory() to be called and we do | |
7539 | not want its scan of the location chain to find a breakpoint and | |
7540 | location that's only been partially initialized. */ | |
7541 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, | |
7542 | sal->pc, b->type); | |
0d381245 | 7543 | |
39d61571 | 7544 | loc = allocate_bp_location (b); |
0d381245 VP |
7545 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
7546 | ; | |
7547 | *tmp = loc; | |
3742cc8b | 7548 | |
0d381245 | 7549 | loc->requested_address = sal->pc; |
3742cc8b | 7550 | loc->address = adjusted_address; |
6c95b8df PA |
7551 | loc->pspace = sal->pspace; |
7552 | gdb_assert (loc->pspace != NULL); | |
0d381245 | 7553 | loc->section = sal->section; |
3742cc8b | 7554 | loc->gdbarch = loc_gdbarch; |
f8eba3c6 TT |
7555 | |
7556 | if (sal->symtab != NULL) | |
7557 | loc->source_file = xstrdup (sal->symtab->filename); | |
7558 | loc->line_number = sal->line; | |
7559 | ||
0e30163f JK |
7560 | set_breakpoint_location_function (loc, |
7561 | sal->explicit_pc || sal->explicit_line); | |
0d381245 VP |
7562 | return loc; |
7563 | } | |
514f746b AR |
7564 | \f |
7565 | ||
7566 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
7567 | return 0 otherwise. */ | |
7568 | ||
7569 | static int | |
7570 | bp_loc_is_permanent (struct bp_location *loc) | |
7571 | { | |
7572 | int len; | |
7573 | CORE_ADDR addr; | |
1afeeb75 | 7574 | const gdb_byte *bpoint; |
514f746b | 7575 | gdb_byte *target_mem; |
939c61fa JK |
7576 | struct cleanup *cleanup; |
7577 | int retval = 0; | |
514f746b AR |
7578 | |
7579 | gdb_assert (loc != NULL); | |
7580 | ||
7581 | addr = loc->address; | |
1afeeb75 | 7582 | bpoint = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 7583 | |
939c61fa | 7584 | /* Software breakpoints unsupported? */ |
1afeeb75 | 7585 | if (bpoint == NULL) |
939c61fa JK |
7586 | return 0; |
7587 | ||
514f746b AR |
7588 | target_mem = alloca (len); |
7589 | ||
939c61fa JK |
7590 | /* Enable the automatic memory restoration from breakpoints while |
7591 | we read the memory. Otherwise we could say about our temporary | |
7592 | breakpoints they are permanent. */ | |
6c95b8df PA |
7593 | cleanup = save_current_space_and_thread (); |
7594 | ||
7595 | switch_to_program_space_and_thread (loc->pspace); | |
7596 | make_show_memory_breakpoints_cleanup (0); | |
939c61fa | 7597 | |
514f746b | 7598 | if (target_read_memory (loc->address, target_mem, len) == 0 |
1afeeb75 | 7599 | && memcmp (target_mem, bpoint, len) == 0) |
939c61fa | 7600 | retval = 1; |
514f746b | 7601 | |
939c61fa JK |
7602 | do_cleanups (cleanup); |
7603 | ||
7604 | return retval; | |
514f746b AR |
7605 | } |
7606 | ||
7607 | ||
c3f6f71d | 7608 | |
018d34a4 VP |
7609 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
7610 | as textual description of the location, and COND_STRING | |
db107f19 | 7611 | as condition expression. */ |
018d34a4 VP |
7612 | |
7613 | static void | |
d9b3f62e PA |
7614 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
7615 | struct symtabs_and_lines sals, char *addr_string, | |
f8eba3c6 | 7616 | char *filter, char *cond_string, |
d9b3f62e PA |
7617 | enum bptype type, enum bpdisp disposition, |
7618 | int thread, int task, int ignore_count, | |
c0a91b2b | 7619 | const struct breakpoint_ops *ops, int from_tty, |
d9b3f62e | 7620 | int enabled, int internal, int display_canonical) |
018d34a4 | 7621 | { |
0d381245 | 7622 | int i; |
018d34a4 VP |
7623 | |
7624 | if (type == bp_hardware_breakpoint) | |
7625 | { | |
fbbd034e AS |
7626 | int target_resources_ok; |
7627 | ||
7628 | i = hw_breakpoint_used_count (); | |
7629 | target_resources_ok = | |
7630 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
018d34a4 VP |
7631 | i + 1, 0); |
7632 | if (target_resources_ok == 0) | |
7633 | error (_("No hardware breakpoint support in the target.")); | |
7634 | else if (target_resources_ok < 0) | |
7635 | error (_("Hardware breakpoints used exceeds limit.")); | |
7636 | } | |
7637 | ||
6c95b8df PA |
7638 | gdb_assert (sals.nelts > 0); |
7639 | ||
0d381245 VP |
7640 | for (i = 0; i < sals.nelts; ++i) |
7641 | { | |
7642 | struct symtab_and_line sal = sals.sals[i]; | |
7643 | struct bp_location *loc; | |
7644 | ||
7645 | if (from_tty) | |
5af949e3 UW |
7646 | { |
7647 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
7648 | if (!loc_gdbarch) | |
7649 | loc_gdbarch = gdbarch; | |
7650 | ||
7651 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 7652 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 7653 | } |
0d381245 VP |
7654 | |
7655 | if (i == 0) | |
7656 | { | |
d9b3f62e | 7657 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 7658 | b->thread = thread; |
4a306c9a | 7659 | b->task = task; |
018d34a4 | 7660 | |
0d381245 VP |
7661 | b->cond_string = cond_string; |
7662 | b->ignore_count = ignore_count; | |
41447f92 | 7663 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 7664 | b->disposition = disposition; |
6c95b8df | 7665 | |
0fb4aa4b PA |
7666 | if (type == bp_static_tracepoint) |
7667 | { | |
d9b3f62e | 7668 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
7669 | struct static_tracepoint_marker marker; |
7670 | ||
983af33b | 7671 | if (strace_marker_p (b)) |
0fb4aa4b PA |
7672 | { |
7673 | /* We already know the marker exists, otherwise, we | |
7674 | wouldn't see a sal for it. */ | |
7675 | char *p = &addr_string[3]; | |
7676 | char *endp; | |
7677 | char *marker_str; | |
0fb4aa4b | 7678 | |
e9cafbcc | 7679 | p = skip_spaces (p); |
0fb4aa4b | 7680 | |
e9cafbcc | 7681 | endp = skip_to_space (p); |
0fb4aa4b PA |
7682 | |
7683 | marker_str = savestring (p, endp - p); | |
d9b3f62e | 7684 | t->static_trace_marker_id = marker_str; |
0fb4aa4b | 7685 | |
3e43a32a MS |
7686 | printf_filtered (_("Probed static tracepoint " |
7687 | "marker \"%s\"\n"), | |
d9b3f62e | 7688 | t->static_trace_marker_id); |
0fb4aa4b PA |
7689 | } |
7690 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
7691 | { | |
d9b3f62e | 7692 | t->static_trace_marker_id = xstrdup (marker.str_id); |
0fb4aa4b PA |
7693 | release_static_tracepoint_marker (&marker); |
7694 | ||
3e43a32a MS |
7695 | printf_filtered (_("Probed static tracepoint " |
7696 | "marker \"%s\"\n"), | |
d9b3f62e | 7697 | t->static_trace_marker_id); |
0fb4aa4b PA |
7698 | } |
7699 | else | |
3e43a32a MS |
7700 | warning (_("Couldn't determine the static " |
7701 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
7702 | } |
7703 | ||
0d381245 VP |
7704 | loc = b->loc; |
7705 | } | |
7706 | else | |
018d34a4 | 7707 | { |
39d61571 | 7708 | loc = add_location_to_breakpoint (b, &sal); |
0d381245 VP |
7709 | } |
7710 | ||
514f746b AR |
7711 | if (bp_loc_is_permanent (loc)) |
7712 | make_breakpoint_permanent (b); | |
7713 | ||
0d381245 VP |
7714 | if (b->cond_string) |
7715 | { | |
7716 | char *arg = b->cond_string; | |
d32a6982 | 7717 | loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0); |
0d381245 | 7718 | if (*arg) |
db107f19 | 7719 | error (_("Garbage %s follows condition"), arg); |
018d34a4 | 7720 | } |
0d381245 | 7721 | } |
018d34a4 | 7722 | |
56435ebe | 7723 | b->display_canonical = display_canonical; |
018d34a4 VP |
7724 | if (addr_string) |
7725 | b->addr_string = addr_string; | |
7726 | else | |
7727 | /* addr_string has to be used or breakpoint_re_set will delete | |
7728 | me. */ | |
5af949e3 UW |
7729 | b->addr_string |
7730 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
f8eba3c6 | 7731 | b->filter = filter; |
d9b3f62e | 7732 | } |
018d34a4 | 7733 | |
d9b3f62e PA |
7734 | static void |
7735 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
7736 | struct symtabs_and_lines sals, char *addr_string, | |
f8eba3c6 | 7737 | char *filter, char *cond_string, |
d9b3f62e PA |
7738 | enum bptype type, enum bpdisp disposition, |
7739 | int thread, int task, int ignore_count, | |
c0a91b2b | 7740 | const struct breakpoint_ops *ops, int from_tty, |
d9b3f62e PA |
7741 | int enabled, int internal, int display_canonical) |
7742 | { | |
7743 | struct breakpoint *b; | |
7744 | struct cleanup *old_chain; | |
7745 | ||
7746 | if (is_tracepoint_type (type)) | |
7747 | { | |
7748 | struct tracepoint *t; | |
7749 | ||
7750 | t = XCNEW (struct tracepoint); | |
7751 | b = &t->base; | |
7752 | } | |
7753 | else | |
7754 | b = XNEW (struct breakpoint); | |
7755 | ||
7756 | old_chain = make_cleanup (xfree, b); | |
7757 | ||
7758 | init_breakpoint_sal (b, gdbarch, | |
7759 | sals, addr_string, | |
f8eba3c6 | 7760 | filter, cond_string, |
d9b3f62e PA |
7761 | type, disposition, |
7762 | thread, task, ignore_count, | |
7763 | ops, from_tty, | |
7764 | enabled, internal, display_canonical); | |
7765 | discard_cleanups (old_chain); | |
7766 | ||
3ea46bff | 7767 | install_breakpoint (internal, b, 0); |
018d34a4 VP |
7768 | } |
7769 | ||
7770 | /* Add SALS.nelts breakpoints to the breakpoint table. For each | |
7771 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
7772 | value. COND_STRING, if not NULL, specified the condition to be | |
7773 | used for all breakpoints. Essentially the only case where | |
7774 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
7775 | function. In that case, it's still not possible to specify | |
7776 | separate conditions for different overloaded functions, so | |
7777 | we take just a single condition string. | |
7778 | ||
c3f6f71d | 7779 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 7780 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
7781 | array contents). If the function fails (error() is called), the |
7782 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 7783 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
7784 | |
7785 | static void | |
8cdf0e15 | 7786 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 | 7787 | struct linespec_result *canonical, |
8cdf0e15 VP |
7788 | char *cond_string, |
7789 | enum bptype type, enum bpdisp disposition, | |
7790 | int thread, int task, int ignore_count, | |
c0a91b2b | 7791 | const struct breakpoint_ops *ops, int from_tty, |
84f4c1fe | 7792 | int enabled, int internal) |
c906108c | 7793 | { |
018d34a4 | 7794 | int i; |
f8eba3c6 | 7795 | struct linespec_sals *lsal; |
cc59ec59 | 7796 | |
f8eba3c6 TT |
7797 | if (canonical->pre_expanded) |
7798 | gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1); | |
7799 | ||
7800 | for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i) | |
c3f6f71d | 7801 | { |
f8eba3c6 TT |
7802 | /* Note that 'addr_string' can be NULL in the case of a plain |
7803 | 'break', without arguments. */ | |
7804 | char *addr_string = (canonical->addr_string | |
7805 | ? xstrdup (canonical->addr_string) | |
7806 | : NULL); | |
7807 | char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL; | |
7808 | struct cleanup *inner = make_cleanup (xfree, addr_string); | |
0d381245 | 7809 | |
f8eba3c6 TT |
7810 | make_cleanup (xfree, filter_string); |
7811 | create_breakpoint_sal (gdbarch, lsal->sals, | |
7812 | addr_string, | |
7813 | filter_string, | |
8cdf0e15 | 7814 | cond_string, type, disposition, |
84f4c1fe | 7815 | thread, task, ignore_count, ops, |
56435ebe TT |
7816 | from_tty, enabled, internal, |
7817 | canonical->special_display); | |
f8eba3c6 | 7818 | discard_cleanups (inner); |
c3f6f71d | 7819 | } |
c3f6f71d | 7820 | } |
c906108c | 7821 | |
9998af43 | 7822 | /* Parse ADDRESS which is assumed to be a SAL specification possibly |
c3f6f71d | 7823 | followed by conditionals. On return, SALS contains an array of SAL |
4a64f543 | 7824 | addresses found. ADDR_STRING contains a vector of (canonical) |
9998af43 TJB |
7825 | address strings. ADDRESS points to the end of the SAL. |
7826 | ||
7827 | The array and the line spec strings are allocated on the heap, it is | |
7828 | the caller's responsibility to free them. */ | |
c906108c | 7829 | |
b9362cc7 | 7830 | static void |
c3f6f71d | 7831 | parse_breakpoint_sals (char **address, |
58438ac1 | 7832 | struct linespec_result *canonical) |
c3f6f71d JM |
7833 | { |
7834 | char *addr_start = *address; | |
cc59ec59 | 7835 | |
c3f6f71d | 7836 | /* If no arg given, or if first arg is 'if ', use the default |
4a64f543 | 7837 | breakpoint. */ |
c3f6f71d JM |
7838 | if ((*address) == NULL |
7839 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c | 7840 | { |
1bfeeb0f JL |
7841 | /* The last displayed codepoint, if it's valid, is our default breakpoint |
7842 | address. */ | |
7843 | if (last_displayed_sal_is_valid ()) | |
c906108c | 7844 | { |
f8eba3c6 | 7845 | struct linespec_sals lsal; |
c3f6f71d | 7846 | struct symtab_and_line sal; |
cc59ec59 | 7847 | |
4a64f543 | 7848 | init_sal (&sal); /* Initialize to zeroes. */ |
f8eba3c6 | 7849 | lsal.sals.sals = (struct symtab_and_line *) |
c906108c | 7850 | xmalloc (sizeof (struct symtab_and_line)); |
1bfeeb0f JL |
7851 | |
7852 | /* Set sal's pspace, pc, symtab, and line to the values | |
7853 | corresponding to the last call to print_frame_info. */ | |
7854 | get_last_displayed_sal (&sal); | |
7855 | sal.section = find_pc_overlay (sal.pc); | |
00903456 | 7856 | |
4a64f543 | 7857 | /* "break" without arguments is equivalent to "break *PC" |
1bfeeb0f JL |
7858 | where PC is the last displayed codepoint's address. So |
7859 | make sure to set sal.explicit_pc to prevent GDB from | |
7860 | trying to expand the list of sals to include all other | |
7861 | instances with the same symtab and line. */ | |
00903456 JK |
7862 | sal.explicit_pc = 1; |
7863 | ||
f8eba3c6 TT |
7864 | lsal.sals.sals[0] = sal; |
7865 | lsal.sals.nelts = 1; | |
7866 | lsal.canonical = NULL; | |
7867 | ||
7868 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
c906108c SS |
7869 | } |
7870 | else | |
8a3fe4f8 | 7871 | error (_("No default breakpoint address now.")); |
c906108c SS |
7872 | } |
7873 | else | |
7874 | { | |
c906108c | 7875 | /* Force almost all breakpoints to be in terms of the |
4a64f543 MS |
7876 | current_source_symtab (which is decode_line_1's default). |
7877 | This should produce the results we want almost all of the | |
f8eba3c6 TT |
7878 | time while leaving default_breakpoint_* alone. */ |
7879 | if (last_displayed_sal_is_valid ()) | |
7880 | decode_line_full (address, DECODE_LINE_FUNFIRSTLINE, | |
7881 | get_last_displayed_symtab (), | |
7882 | get_last_displayed_line (), | |
7883 | canonical, NULL, NULL); | |
c906108c | 7884 | else |
f8eba3c6 TT |
7885 | decode_line_full (address, DECODE_LINE_FUNFIRSTLINE, |
7886 | (struct symtab *) NULL, 0, | |
7887 | canonical, NULL, NULL); | |
c906108c | 7888 | } |
c3f6f71d | 7889 | } |
c906108c | 7890 | |
c906108c | 7891 | |
c3f6f71d | 7892 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 7893 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 7894 | |
b9362cc7 | 7895 | static void |
23e7acfb | 7896 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
c3f6f71d JM |
7897 | { |
7898 | int i; | |
cc59ec59 | 7899 | |
c3f6f71d | 7900 | for (i = 0; i < sals->nelts; i++) |
ee53e872 | 7901 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
7902 | } |
7903 | ||
7a697b8d SS |
7904 | /* Fast tracepoints may have restrictions on valid locations. For |
7905 | instance, a fast tracepoint using a jump instead of a trap will | |
7906 | likely have to overwrite more bytes than a trap would, and so can | |
7907 | only be placed where the instruction is longer than the jump, or a | |
7908 | multi-instruction sequence does not have a jump into the middle of | |
7909 | it, etc. */ | |
7910 | ||
7911 | static void | |
7912 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
7913 | struct symtabs_and_lines *sals) | |
7914 | { | |
7915 | int i, rslt; | |
7916 | struct symtab_and_line *sal; | |
7917 | char *msg; | |
7918 | struct cleanup *old_chain; | |
7919 | ||
7920 | for (i = 0; i < sals->nelts; i++) | |
7921 | { | |
f8eba3c6 TT |
7922 | struct gdbarch *sarch; |
7923 | ||
7a697b8d SS |
7924 | sal = &sals->sals[i]; |
7925 | ||
f8eba3c6 TT |
7926 | sarch = get_sal_arch (*sal); |
7927 | /* We fall back to GDBARCH if there is no architecture | |
7928 | associated with SAL. */ | |
7929 | if (sarch == NULL) | |
7930 | sarch = gdbarch; | |
7931 | rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc, | |
7a697b8d SS |
7932 | NULL, &msg); |
7933 | old_chain = make_cleanup (xfree, msg); | |
7934 | ||
7935 | if (!rslt) | |
7936 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
f8eba3c6 | 7937 | paddress (sarch, sal->pc), (msg ? msg : "")); |
7a697b8d SS |
7938 | |
7939 | do_cleanups (old_chain); | |
7940 | } | |
7941 | } | |
7942 | ||
018d34a4 VP |
7943 | /* Given TOK, a string specification of condition and thread, as |
7944 | accepted by the 'break' command, extract the condition | |
7945 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 7946 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
7947 | If no condition is found, *COND_STRING is set to NULL. |
7948 | If no thread is found, *THREAD is set to -1. */ | |
7949 | static void | |
7950 | find_condition_and_thread (char *tok, CORE_ADDR pc, | |
4a306c9a | 7951 | char **cond_string, int *thread, int *task) |
018d34a4 VP |
7952 | { |
7953 | *cond_string = NULL; | |
7954 | *thread = -1; | |
7955 | while (tok && *tok) | |
7956 | { | |
7957 | char *end_tok; | |
7958 | int toklen; | |
7959 | char *cond_start = NULL; | |
7960 | char *cond_end = NULL; | |
cc59ec59 | 7961 | |
e9cafbcc | 7962 | tok = skip_spaces (tok); |
018d34a4 | 7963 | |
e9cafbcc | 7964 | end_tok = skip_to_space (tok); |
018d34a4 VP |
7965 | |
7966 | toklen = end_tok - tok; | |
7967 | ||
7968 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
7969 | { | |
f7545552 TT |
7970 | struct expression *expr; |
7971 | ||
018d34a4 | 7972 | tok = cond_start = end_tok + 1; |
f7545552 TT |
7973 | expr = parse_exp_1 (&tok, block_for_pc (pc), 0); |
7974 | xfree (expr); | |
018d34a4 VP |
7975 | cond_end = tok; |
7976 | *cond_string = savestring (cond_start, | |
7977 | cond_end - cond_start); | |
7978 | } | |
7979 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
7980 | { | |
7981 | char *tmptok; | |
7982 | ||
7983 | tok = end_tok + 1; | |
7984 | tmptok = tok; | |
7985 | *thread = strtol (tok, &tok, 0); | |
7986 | if (tok == tmptok) | |
7987 | error (_("Junk after thread keyword.")); | |
7988 | if (!valid_thread_id (*thread)) | |
7989 | error (_("Unknown thread %d."), *thread); | |
7990 | } | |
4a306c9a JB |
7991 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
7992 | { | |
7993 | char *tmptok; | |
7994 | ||
7995 | tok = end_tok + 1; | |
7996 | tmptok = tok; | |
7997 | *task = strtol (tok, &tok, 0); | |
7998 | if (tok == tmptok) | |
7999 | error (_("Junk after task keyword.")); | |
8000 | if (!valid_task_id (*task)) | |
b6199126 | 8001 | error (_("Unknown task %d."), *task); |
4a306c9a | 8002 | } |
018d34a4 VP |
8003 | else |
8004 | error (_("Junk at end of arguments.")); | |
8005 | } | |
8006 | } | |
8007 | ||
0fb4aa4b PA |
8008 | /* Decode a static tracepoint marker spec. */ |
8009 | ||
8010 | static struct symtabs_and_lines | |
8011 | decode_static_tracepoint_spec (char **arg_p) | |
8012 | { | |
8013 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
8014 | struct symtabs_and_lines sals; | |
8015 | struct symtab_and_line sal; | |
8016 | struct symbol *sym; | |
8017 | struct cleanup *old_chain; | |
8018 | char *p = &(*arg_p)[3]; | |
8019 | char *endp; | |
8020 | char *marker_str; | |
8021 | int i; | |
8022 | ||
e9cafbcc | 8023 | p = skip_spaces (p); |
0fb4aa4b | 8024 | |
e9cafbcc | 8025 | endp = skip_to_space (p); |
0fb4aa4b PA |
8026 | |
8027 | marker_str = savestring (p, endp - p); | |
8028 | old_chain = make_cleanup (xfree, marker_str); | |
8029 | ||
8030 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
8031 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
8032 | error (_("No known static tracepoint marker named %s"), marker_str); | |
8033 | ||
8034 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); | |
8035 | sals.sals = xmalloc (sizeof *sals.sals * sals.nelts); | |
8036 | ||
8037 | for (i = 0; i < sals.nelts; i++) | |
8038 | { | |
8039 | struct static_tracepoint_marker *marker; | |
8040 | ||
8041 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
8042 | ||
8043 | init_sal (&sals.sals[i]); | |
8044 | ||
8045 | sals.sals[i] = find_pc_line (marker->address, 0); | |
8046 | sals.sals[i].pc = marker->address; | |
8047 | ||
8048 | release_static_tracepoint_marker (marker); | |
8049 | } | |
8050 | ||
8051 | do_cleanups (old_chain); | |
8052 | ||
8053 | *arg_p = endp; | |
8054 | return sals; | |
8055 | } | |
8056 | ||
fd9b8c24 PA |
8057 | /* Set a breakpoint. This function is shared between CLI and MI |
8058 | functions for setting a breakpoint. This function has two major | |
8059 | modes of operations, selected by the PARSE_CONDITION_AND_THREAD | |
8060 | parameter. If non-zero, the function will parse arg, extracting | |
4a64f543 MS |
8061 | breakpoint location, address and thread. Otherwise, ARG is just |
8062 | the location of breakpoint, with condition and thread specified by | |
8063 | the COND_STRING and THREAD parameters. If INTERNAL is non-zero, | |
8064 | the breakpoint number will be allocated from the internal | |
8065 | breakpoint count. Returns true if any breakpoint was created; | |
8066 | false otherwise. */ | |
0101ce28 | 8067 | |
8cdf0e15 VP |
8068 | int |
8069 | create_breakpoint (struct gdbarch *gdbarch, | |
8070 | char *arg, char *cond_string, int thread, | |
8071 | int parse_condition_and_thread, | |
0fb4aa4b | 8072 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
8073 | int ignore_count, |
8074 | enum auto_boolean pending_break_support, | |
c0a91b2b | 8075 | const struct breakpoint_ops *ops, |
84f4c1fe | 8076 | int from_tty, int enabled, int internal) |
c3f6f71d | 8077 | { |
b78a6381 | 8078 | volatile struct gdb_exception e; |
f8eba3c6 | 8079 | char *copy_arg = NULL; |
c3f6f71d | 8080 | char *addr_start = arg; |
7efd8fc2 | 8081 | struct linespec_result canonical; |
c3f6f71d | 8082 | struct cleanup *old_chain; |
80c99de1 | 8083 | struct cleanup *bkpt_chain = NULL; |
05ff989b | 8084 | int i; |
0101ce28 | 8085 | int pending = 0; |
4a306c9a | 8086 | int task = 0; |
86b17b60 | 8087 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 8088 | |
348d480f PA |
8089 | gdb_assert (ops != NULL); |
8090 | ||
7efd8fc2 | 8091 | init_linespec_result (&canonical); |
c3f6f71d | 8092 | |
b78a6381 TT |
8093 | TRY_CATCH (e, RETURN_MASK_ALL) |
8094 | { | |
983af33b SDJ |
8095 | ops->create_sals_from_address (&arg, &canonical, type_wanted, |
8096 | addr_start, ©_arg); | |
b78a6381 | 8097 | } |
0101ce28 JJ |
8098 | |
8099 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 8100 | switch (e.reason) |
0101ce28 | 8101 | { |
983af33b SDJ |
8102 | case GDB_NO_ERROR: |
8103 | if (VEC_empty (linespec_sals, canonical.sals)) | |
8104 | return 0; | |
8105 | break; | |
05ff989b AC |
8106 | case RETURN_ERROR: |
8107 | switch (e.error) | |
0101ce28 | 8108 | { |
05ff989b | 8109 | case NOT_FOUND_ERROR: |
0101ce28 | 8110 | |
05ff989b AC |
8111 | /* If pending breakpoint support is turned off, throw |
8112 | error. */ | |
fa8d40ab JJ |
8113 | |
8114 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
8115 | throw_exception (e); |
8116 | ||
8117 | exception_print (gdb_stderr, e); | |
fa8d40ab | 8118 | |
05ff989b AC |
8119 | /* If pending breakpoint support is auto query and the user |
8120 | selects no, then simply return the error code. */ | |
059fb39f | 8121 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
bfccc43c YQ |
8122 | && !nquery (_("Make %s pending on future shared library load? "), |
8123 | bptype_string (type_wanted))) | |
fd9b8c24 | 8124 | return 0; |
fa8d40ab | 8125 | |
05ff989b AC |
8126 | /* At this point, either the user was queried about setting |
8127 | a pending breakpoint and selected yes, or pending | |
8128 | breakpoint behavior is on and thus a pending breakpoint | |
8129 | is defaulted on behalf of the user. */ | |
f8eba3c6 TT |
8130 | { |
8131 | struct linespec_sals lsal; | |
8132 | ||
8133 | copy_arg = xstrdup (addr_start); | |
8134 | lsal.canonical = xstrdup (copy_arg); | |
8135 | lsal.sals.nelts = 1; | |
8136 | lsal.sals.sals = XNEW (struct symtab_and_line); | |
8137 | init_sal (&lsal.sals.sals[0]); | |
8138 | pending = 1; | |
8139 | VEC_safe_push (linespec_sals, canonical.sals, &lsal); | |
8140 | } | |
05ff989b AC |
8141 | break; |
8142 | default: | |
98deb0da | 8143 | throw_exception (e); |
0101ce28 | 8144 | } |
2abae994 | 8145 | break; |
05ff989b | 8146 | default: |
983af33b | 8147 | throw_exception (e); |
0101ce28 | 8148 | } |
c3f6f71d | 8149 | |
4a64f543 | 8150 | /* Create a chain of things that always need to be cleaned up. */ |
f8eba3c6 | 8151 | old_chain = make_cleanup_destroy_linespec_result (&canonical); |
c3f6f71d | 8152 | |
c3f6f71d JM |
8153 | /* ----------------------------- SNIP ----------------------------- |
8154 | Anything added to the cleanup chain beyond this point is assumed | |
8155 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
8156 | then the memory is not reclaimed. */ |
8157 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d | 8158 | |
c3f6f71d JM |
8159 | /* Resolve all line numbers to PC's and verify that the addresses |
8160 | are ok for the target. */ | |
0101ce28 | 8161 | if (!pending) |
f8eba3c6 TT |
8162 | { |
8163 | int ix; | |
8164 | struct linespec_sals *iter; | |
8165 | ||
8166 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
8167 | breakpoint_sals_to_pc (&iter->sals); | |
8168 | } | |
c3f6f71d | 8169 | |
7a697b8d | 8170 | /* Fast tracepoints may have additional restrictions on location. */ |
bfccc43c | 8171 | if (!pending && type_wanted == bp_fast_tracepoint) |
f8eba3c6 TT |
8172 | { |
8173 | int ix; | |
8174 | struct linespec_sals *iter; | |
8175 | ||
8176 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
8177 | check_fast_tracepoint_sals (gdbarch, &iter->sals); | |
8178 | } | |
7a697b8d | 8179 | |
c3f6f71d JM |
8180 | /* Verify that condition can be parsed, before setting any |
8181 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 8182 | breakpoint. */ |
0101ce28 | 8183 | if (!pending) |
c3f6f71d | 8184 | { |
f8eba3c6 TT |
8185 | struct linespec_sals *lsal; |
8186 | ||
8187 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
8188 | ||
2f069f6f | 8189 | if (parse_condition_and_thread) |
72b2ff0e VP |
8190 | { |
8191 | /* Here we only parse 'arg' to separate condition | |
8192 | from thread number, so parsing in context of first | |
8193 | sal is OK. When setting the breakpoint we'll | |
8194 | re-parse it in context of each sal. */ | |
8195 | cond_string = NULL; | |
8196 | thread = -1; | |
f8eba3c6 | 8197 | find_condition_and_thread (arg, lsal->sals.sals[0].pc, &cond_string, |
4a306c9a | 8198 | &thread, &task); |
72b2ff0e VP |
8199 | if (cond_string) |
8200 | make_cleanup (xfree, cond_string); | |
8201 | } | |
2f069f6f | 8202 | else |
72b2ff0e VP |
8203 | { |
8204 | /* Create a private copy of condition string. */ | |
8205 | if (cond_string) | |
8206 | { | |
8207 | cond_string = xstrdup (cond_string); | |
8208 | make_cleanup (xfree, cond_string); | |
8209 | } | |
8210 | } | |
0fb4aa4b | 8211 | |
983af33b | 8212 | ops->create_breakpoints_sal (gdbarch, &canonical, lsal, |
d9b3f62e PA |
8213 | cond_string, type_wanted, |
8214 | tempflag ? disp_del : disp_donttouch, | |
8215 | thread, task, ignore_count, ops, | |
983af33b | 8216 | from_tty, enabled, internal); |
c906108c | 8217 | } |
0101ce28 JJ |
8218 | else |
8219 | { | |
0101ce28 JJ |
8220 | struct breakpoint *b; |
8221 | ||
0101ce28 JJ |
8222 | make_cleanup (xfree, copy_arg); |
8223 | ||
bfccc43c YQ |
8224 | if (is_tracepoint_type (type_wanted)) |
8225 | { | |
8226 | struct tracepoint *t; | |
8227 | ||
8228 | t = XCNEW (struct tracepoint); | |
8229 | b = &t->base; | |
8230 | } | |
8231 | else | |
8232 | b = XNEW (struct breakpoint); | |
8233 | ||
8234 | init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops); | |
8235 | ||
f8eba3c6 | 8236 | b->addr_string = copy_arg; |
72b2ff0e | 8237 | b->cond_string = NULL; |
0101ce28 | 8238 | b->ignore_count = ignore_count; |
0101ce28 | 8239 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 8240 | b->condition_not_parsed = 1; |
41447f92 | 8241 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
cc72b2a2 KP |
8242 | if ((type_wanted != bp_breakpoint |
8243 | && type_wanted != bp_hardware_breakpoint) || thread != -1) | |
f8eba3c6 | 8244 | b->pspace = current_program_space; |
8bea4e01 | 8245 | |
bfccc43c | 8246 | install_breakpoint (internal, b, 0); |
0101ce28 JJ |
8247 | } |
8248 | ||
f8eba3c6 | 8249 | if (VEC_length (linespec_sals, canonical.sals) > 1) |
95a42b64 | 8250 | { |
3e43a32a MS |
8251 | warning (_("Multiple breakpoints were set.\nUse the " |
8252 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 8253 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
8254 | } |
8255 | ||
80c99de1 PA |
8256 | /* That's it. Discard the cleanups for data inserted into the |
8257 | breakpoint. */ | |
8258 | discard_cleanups (bkpt_chain); | |
8259 | /* But cleanup everything else. */ | |
c3f6f71d | 8260 | do_cleanups (old_chain); |
217dc9e2 | 8261 | |
80c99de1 | 8262 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
217dc9e2 | 8263 | update_global_location_list (1); |
fd9b8c24 PA |
8264 | |
8265 | return 1; | |
c3f6f71d | 8266 | } |
c906108c | 8267 | |
348d480f | 8268 | /* Set a breakpoint. |
72b2ff0e VP |
8269 | ARG is a string describing breakpoint address, |
8270 | condition, and thread. | |
8271 | FLAG specifies if a breakpoint is hardware on, | |
8272 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
8273 | and BP_TEMPFLAG. */ | |
348d480f | 8274 | |
98deb0da | 8275 | static void |
72b2ff0e | 8276 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 8277 | { |
72b2ff0e | 8278 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
8279 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
8280 | ? bp_hardware_breakpoint | |
8281 | : bp_breakpoint); | |
c3f6f71d | 8282 | |
8cdf0e15 VP |
8283 | create_breakpoint (get_current_arch (), |
8284 | arg, | |
8285 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b | 8286 | tempflag, type_wanted, |
8cdf0e15 VP |
8287 | 0 /* Ignore count */, |
8288 | pending_break_support, | |
348d480f | 8289 | &bkpt_breakpoint_ops, |
8cdf0e15 | 8290 | from_tty, |
84f4c1fe PM |
8291 | 1 /* enabled */, |
8292 | 0 /* internal */); | |
c906108c SS |
8293 | } |
8294 | ||
c906108c SS |
8295 | /* Helper function for break_command_1 and disassemble_command. */ |
8296 | ||
8297 | void | |
fba45db2 | 8298 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
8299 | { |
8300 | CORE_ADDR pc; | |
8301 | ||
8302 | if (sal->pc == 0 && sal->symtab != NULL) | |
8303 | { | |
8304 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 8305 | error (_("No line %d in file \"%s\"."), |
c906108c SS |
8306 | sal->line, sal->symtab->filename); |
8307 | sal->pc = pc; | |
6a048695 | 8308 | |
4a64f543 MS |
8309 | /* If this SAL corresponds to a breakpoint inserted using a line |
8310 | number, then skip the function prologue if necessary. */ | |
6a048695 | 8311 | if (sal->explicit_line) |
059acae7 | 8312 | skip_prologue_sal (sal); |
c906108c SS |
8313 | } |
8314 | ||
8315 | if (sal->section == 0 && sal->symtab != NULL) | |
8316 | { | |
8317 | struct blockvector *bv; | |
c5aa993b JM |
8318 | struct block *b; |
8319 | struct symbol *sym; | |
c906108c | 8320 | |
801e3a5b | 8321 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
8322 | if (bv != NULL) |
8323 | { | |
7f0df278 | 8324 | sym = block_linkage_function (b); |
c906108c SS |
8325 | if (sym != NULL) |
8326 | { | |
8327 | fixup_symbol_section (sym, sal->symtab->objfile); | |
714835d5 | 8328 | sal->section = SYMBOL_OBJ_SECTION (sym); |
c906108c SS |
8329 | } |
8330 | else | |
8331 | { | |
4a64f543 MS |
8332 | /* It really is worthwhile to have the section, so we'll |
8333 | just have to look harder. This case can be executed | |
8334 | if we have line numbers but no functions (as can | |
8335 | happen in assembly source). */ | |
c906108c | 8336 | |
c5aa993b | 8337 | struct minimal_symbol *msym; |
6c95b8df PA |
8338 | struct cleanup *old_chain = save_current_space_and_thread (); |
8339 | ||
8340 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
8341 | |
8342 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
8343 | if (msym) | |
714835d5 | 8344 | sal->section = SYMBOL_OBJ_SECTION (msym); |
6c95b8df PA |
8345 | |
8346 | do_cleanups (old_chain); | |
c906108c SS |
8347 | } |
8348 | } | |
8349 | } | |
8350 | } | |
8351 | ||
8352 | void | |
fba45db2 | 8353 | break_command (char *arg, int from_tty) |
c906108c | 8354 | { |
db107f19 | 8355 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8356 | } |
8357 | ||
c906108c | 8358 | void |
fba45db2 | 8359 | tbreak_command (char *arg, int from_tty) |
c906108c | 8360 | { |
db107f19 | 8361 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
8362 | } |
8363 | ||
c906108c | 8364 | static void |
fba45db2 | 8365 | hbreak_command (char *arg, int from_tty) |
c906108c | 8366 | { |
db107f19 | 8367 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
8368 | } |
8369 | ||
8370 | static void | |
fba45db2 | 8371 | thbreak_command (char *arg, int from_tty) |
c906108c | 8372 | { |
db107f19 | 8373 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
8374 | } |
8375 | ||
8376 | static void | |
fba45db2 | 8377 | stop_command (char *arg, int from_tty) |
c906108c | 8378 | { |
a3f17187 | 8379 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 8380 | Usage: stop in <function | address>\n\ |
a3f17187 | 8381 | stop at <line>\n")); |
c906108c SS |
8382 | } |
8383 | ||
8384 | static void | |
fba45db2 | 8385 | stopin_command (char *arg, int from_tty) |
c906108c SS |
8386 | { |
8387 | int badInput = 0; | |
8388 | ||
c5aa993b | 8389 | if (arg == (char *) NULL) |
c906108c SS |
8390 | badInput = 1; |
8391 | else if (*arg != '*') | |
8392 | { | |
8393 | char *argptr = arg; | |
8394 | int hasColon = 0; | |
8395 | ||
4a64f543 | 8396 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 8397 | say it is bad, otherwise, it should be an address or |
4a64f543 | 8398 | function/method name. */ |
c906108c | 8399 | while (*argptr && !hasColon) |
c5aa993b JM |
8400 | { |
8401 | hasColon = (*argptr == ':'); | |
8402 | argptr++; | |
8403 | } | |
c906108c SS |
8404 | |
8405 | if (hasColon) | |
c5aa993b | 8406 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 8407 | else |
c5aa993b | 8408 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
8409 | } |
8410 | ||
8411 | if (badInput) | |
a3f17187 | 8412 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 8413 | else |
db107f19 | 8414 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8415 | } |
8416 | ||
8417 | static void | |
fba45db2 | 8418 | stopat_command (char *arg, int from_tty) |
c906108c SS |
8419 | { |
8420 | int badInput = 0; | |
8421 | ||
c5aa993b | 8422 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
8423 | badInput = 1; |
8424 | else | |
8425 | { | |
8426 | char *argptr = arg; | |
8427 | int hasColon = 0; | |
8428 | ||
4a64f543 MS |
8429 | /* Look for a ':'. If there is a '::' then get out, otherwise |
8430 | it is probably a line number. */ | |
c906108c | 8431 | while (*argptr && !hasColon) |
c5aa993b JM |
8432 | { |
8433 | hasColon = (*argptr == ':'); | |
8434 | argptr++; | |
8435 | } | |
c906108c SS |
8436 | |
8437 | if (hasColon) | |
c5aa993b | 8438 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 8439 | else |
c5aa993b | 8440 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
8441 | } |
8442 | ||
8443 | if (badInput) | |
a3f17187 | 8444 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 8445 | else |
db107f19 | 8446 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8447 | } |
8448 | ||
f1310107 TJB |
8449 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
8450 | ranged breakpoints. */ | |
8451 | ||
8452 | static int | |
8453 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
8454 | struct address_space *aspace, | |
09ac7c10 TT |
8455 | CORE_ADDR bp_addr, |
8456 | const struct target_waitstatus *ws) | |
f1310107 | 8457 | { |
09ac7c10 TT |
8458 | if (ws->kind != TARGET_WAITKIND_STOPPED |
8459 | || ws->value.sig != TARGET_SIGNAL_TRAP) | |
8460 | return 0; | |
8461 | ||
f1310107 TJB |
8462 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, |
8463 | bl->length, aspace, bp_addr); | |
8464 | } | |
8465 | ||
8466 | /* Implement the "resources_needed" breakpoint_ops method for | |
8467 | ranged breakpoints. */ | |
8468 | ||
8469 | static int | |
8470 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
8471 | { | |
8472 | return target_ranged_break_num_registers (); | |
8473 | } | |
8474 | ||
8475 | /* Implement the "print_it" breakpoint_ops method for | |
8476 | ranged breakpoints. */ | |
8477 | ||
8478 | static enum print_stop_action | |
348d480f | 8479 | print_it_ranged_breakpoint (bpstat bs) |
f1310107 | 8480 | { |
348d480f | 8481 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 | 8482 | struct bp_location *bl = b->loc; |
79a45e25 | 8483 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
8484 | |
8485 | gdb_assert (b->type == bp_hardware_breakpoint); | |
8486 | ||
8487 | /* Ranged breakpoints have only one location. */ | |
8488 | gdb_assert (bl && bl->next == NULL); | |
8489 | ||
8490 | annotate_breakpoint (b->number); | |
8491 | if (b->disposition == disp_del) | |
8492 | ui_out_text (uiout, "\nTemporary ranged breakpoint "); | |
8493 | else | |
8494 | ui_out_text (uiout, "\nRanged breakpoint "); | |
8495 | if (ui_out_is_mi_like_p (uiout)) | |
8496 | { | |
8497 | ui_out_field_string (uiout, "reason", | |
8498 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
8499 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8500 | } | |
8501 | ui_out_field_int (uiout, "bkptno", b->number); | |
8502 | ui_out_text (uiout, ", "); | |
8503 | ||
8504 | return PRINT_SRC_AND_LOC; | |
8505 | } | |
8506 | ||
8507 | /* Implement the "print_one" breakpoint_ops method for | |
8508 | ranged breakpoints. */ | |
8509 | ||
8510 | static void | |
8511 | print_one_ranged_breakpoint (struct breakpoint *b, | |
8512 | struct bp_location **last_loc) | |
8513 | { | |
8514 | struct bp_location *bl = b->loc; | |
8515 | struct value_print_options opts; | |
79a45e25 | 8516 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
8517 | |
8518 | /* Ranged breakpoints have only one location. */ | |
8519 | gdb_assert (bl && bl->next == NULL); | |
8520 | ||
8521 | get_user_print_options (&opts); | |
8522 | ||
8523 | if (opts.addressprint) | |
8524 | /* We don't print the address range here, it will be printed later | |
8525 | by print_one_detail_ranged_breakpoint. */ | |
8526 | ui_out_field_skip (uiout, "addr"); | |
8527 | annotate_field (5); | |
8528 | print_breakpoint_location (b, bl); | |
8529 | *last_loc = bl; | |
8530 | } | |
8531 | ||
8532 | /* Implement the "print_one_detail" breakpoint_ops method for | |
8533 | ranged breakpoints. */ | |
8534 | ||
8535 | static void | |
8536 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
8537 | struct ui_out *uiout) | |
8538 | { | |
8539 | CORE_ADDR address_start, address_end; | |
8540 | struct bp_location *bl = b->loc; | |
8541 | struct ui_stream *stb = ui_out_stream_new (uiout); | |
8542 | struct cleanup *cleanup = make_cleanup_ui_out_stream_delete (stb); | |
8543 | ||
8544 | gdb_assert (bl); | |
8545 | ||
8546 | address_start = bl->address; | |
8547 | address_end = address_start + bl->length - 1; | |
8548 | ||
8549 | ui_out_text (uiout, "\taddress range: "); | |
8550 | fprintf_unfiltered (stb->stream, "[%s, %s]", | |
8551 | print_core_address (bl->gdbarch, address_start), | |
8552 | print_core_address (bl->gdbarch, address_end)); | |
8553 | ui_out_field_stream (uiout, "addr", stb); | |
8554 | ui_out_text (uiout, "\n"); | |
8555 | ||
8556 | do_cleanups (cleanup); | |
8557 | } | |
8558 | ||
8559 | /* Implement the "print_mention" breakpoint_ops method for | |
8560 | ranged breakpoints. */ | |
8561 | ||
8562 | static void | |
8563 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
8564 | { | |
8565 | struct bp_location *bl = b->loc; | |
79a45e25 | 8566 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
8567 | |
8568 | gdb_assert (bl); | |
8569 | gdb_assert (b->type == bp_hardware_breakpoint); | |
8570 | ||
8571 | if (ui_out_is_mi_like_p (uiout)) | |
8572 | return; | |
8573 | ||
8574 | printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."), | |
8575 | b->number, paddress (bl->gdbarch, bl->address), | |
8576 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
8577 | } | |
8578 | ||
8579 | /* Implement the "print_recreate" breakpoint_ops method for | |
8580 | ranged breakpoints. */ | |
8581 | ||
8582 | static void | |
8583 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
8584 | { | |
8585 | fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string, | |
8586 | b->addr_string_range_end); | |
d9b3f62e | 8587 | print_recreate_thread (b, fp); |
f1310107 TJB |
8588 | } |
8589 | ||
8590 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
8591 | ||
2060206e | 8592 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
8593 | |
8594 | /* Find the address where the end of the breakpoint range should be | |
8595 | placed, given the SAL of the end of the range. This is so that if | |
8596 | the user provides a line number, the end of the range is set to the | |
8597 | last instruction of the given line. */ | |
8598 | ||
8599 | static CORE_ADDR | |
8600 | find_breakpoint_range_end (struct symtab_and_line sal) | |
8601 | { | |
8602 | CORE_ADDR end; | |
8603 | ||
8604 | /* If the user provided a PC value, use it. Otherwise, | |
8605 | find the address of the end of the given location. */ | |
8606 | if (sal.explicit_pc) | |
8607 | end = sal.pc; | |
8608 | else | |
8609 | { | |
8610 | int ret; | |
8611 | CORE_ADDR start; | |
8612 | ||
8613 | ret = find_line_pc_range (sal, &start, &end); | |
8614 | if (!ret) | |
8615 | error (_("Could not find location of the end of the range.")); | |
8616 | ||
8617 | /* find_line_pc_range returns the start of the next line. */ | |
8618 | end--; | |
8619 | } | |
8620 | ||
8621 | return end; | |
8622 | } | |
8623 | ||
8624 | /* Implement the "break-range" CLI command. */ | |
8625 | ||
8626 | static void | |
8627 | break_range_command (char *arg, int from_tty) | |
8628 | { | |
8629 | char *arg_start, *addr_string_start, *addr_string_end; | |
8630 | struct linespec_result canonical_start, canonical_end; | |
8631 | int bp_count, can_use_bp, length; | |
8632 | CORE_ADDR end; | |
8633 | struct breakpoint *b; | |
8634 | struct symtab_and_line sal_start, sal_end; | |
f1310107 | 8635 | struct cleanup *cleanup_bkpt; |
f8eba3c6 | 8636 | struct linespec_sals *lsal_start, *lsal_end; |
f1310107 TJB |
8637 | |
8638 | /* We don't support software ranged breakpoints. */ | |
8639 | if (target_ranged_break_num_registers () < 0) | |
8640 | error (_("This target does not support hardware ranged breakpoints.")); | |
8641 | ||
8642 | bp_count = hw_breakpoint_used_count (); | |
8643 | bp_count += target_ranged_break_num_registers (); | |
8644 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
8645 | bp_count, 0); | |
8646 | if (can_use_bp < 0) | |
8647 | error (_("Hardware breakpoints used exceeds limit.")); | |
8648 | ||
f8eba3c6 | 8649 | arg = skip_spaces (arg); |
f1310107 TJB |
8650 | if (arg == NULL || arg[0] == '\0') |
8651 | error(_("No address range specified.")); | |
8652 | ||
f1310107 TJB |
8653 | init_linespec_result (&canonical_start); |
8654 | ||
f8eba3c6 TT |
8655 | arg_start = arg; |
8656 | parse_breakpoint_sals (&arg, &canonical_start); | |
f1310107 | 8657 | |
f8eba3c6 | 8658 | cleanup_bkpt = make_cleanup_destroy_linespec_result (&canonical_start); |
f1310107 TJB |
8659 | |
8660 | if (arg[0] != ',') | |
8661 | error (_("Too few arguments.")); | |
f8eba3c6 | 8662 | else if (VEC_empty (linespec_sals, canonical_start.sals)) |
f1310107 | 8663 | error (_("Could not find location of the beginning of the range.")); |
f8eba3c6 TT |
8664 | |
8665 | lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0); | |
8666 | ||
8667 | if (VEC_length (linespec_sals, canonical_start.sals) > 1 | |
8668 | || lsal_start->sals.nelts != 1) | |
f1310107 TJB |
8669 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
8670 | ||
f8eba3c6 TT |
8671 | sal_start = lsal_start->sals.sals[0]; |
8672 | addr_string_start = savestring (arg_start, arg - arg_start); | |
8673 | make_cleanup (xfree, addr_string_start); | |
f1310107 TJB |
8674 | |
8675 | arg++; /* Skip the comma. */ | |
f8eba3c6 | 8676 | arg = skip_spaces (arg); |
f1310107 TJB |
8677 | |
8678 | /* Parse the end location. */ | |
8679 | ||
f1310107 TJB |
8680 | init_linespec_result (&canonical_end); |
8681 | arg_start = arg; | |
8682 | ||
f8eba3c6 | 8683 | /* We call decode_line_full directly here instead of using |
f1310107 TJB |
8684 | parse_breakpoint_sals because we need to specify the start location's |
8685 | symtab and line as the default symtab and line for the end of the | |
8686 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
8687 | where +14 means 14 lines from the start location. */ | |
f8eba3c6 TT |
8688 | decode_line_full (&arg, DECODE_LINE_FUNFIRSTLINE, |
8689 | sal_start.symtab, sal_start.line, | |
8690 | &canonical_end, NULL, NULL); | |
8691 | ||
8692 | make_cleanup_destroy_linespec_result (&canonical_end); | |
f1310107 | 8693 | |
f8eba3c6 | 8694 | if (VEC_empty (linespec_sals, canonical_end.sals)) |
f1310107 | 8695 | error (_("Could not find location of the end of the range.")); |
f8eba3c6 TT |
8696 | |
8697 | lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0); | |
8698 | if (VEC_length (linespec_sals, canonical_end.sals) > 1 | |
8699 | || lsal_end->sals.nelts != 1) | |
f1310107 TJB |
8700 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
8701 | ||
f8eba3c6 TT |
8702 | sal_end = lsal_end->sals.sals[0]; |
8703 | addr_string_end = savestring (arg_start, arg - arg_start); | |
8704 | make_cleanup (xfree, addr_string_end); | |
f1310107 TJB |
8705 | |
8706 | end = find_breakpoint_range_end (sal_end); | |
8707 | if (sal_start.pc > end) | |
177b42fe | 8708 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
8709 | |
8710 | length = end - sal_start.pc + 1; | |
8711 | if (length < 0) | |
8712 | /* Length overflowed. */ | |
8713 | error (_("Address range too large.")); | |
8714 | else if (length == 1) | |
8715 | { | |
8716 | /* This range is simple enough to be handled by | |
8717 | the `hbreak' command. */ | |
8718 | hbreak_command (addr_string_start, 1); | |
8719 | ||
8720 | do_cleanups (cleanup_bkpt); | |
8721 | ||
8722 | return; | |
8723 | } | |
8724 | ||
8725 | /* Now set up the breakpoint. */ | |
8726 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 8727 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
8728 | set_breakpoint_count (breakpoint_count + 1); |
8729 | b->number = breakpoint_count; | |
8730 | b->disposition = disp_donttouch; | |
f8eba3c6 TT |
8731 | b->addr_string = xstrdup (addr_string_start); |
8732 | b->addr_string_range_end = xstrdup (addr_string_end); | |
f1310107 TJB |
8733 | b->loc->length = length; |
8734 | ||
f8eba3c6 | 8735 | do_cleanups (cleanup_bkpt); |
f1310107 TJB |
8736 | |
8737 | mention (b); | |
8d3788bd | 8738 | observer_notify_breakpoint_created (b); |
f1310107 TJB |
8739 | update_global_location_list (1); |
8740 | } | |
8741 | ||
4a64f543 MS |
8742 | /* Return non-zero if EXP is verified as constant. Returned zero |
8743 | means EXP is variable. Also the constant detection may fail for | |
8744 | some constant expressions and in such case still falsely return | |
8745 | zero. */ | |
65d79d4b SDJ |
8746 | static int |
8747 | watchpoint_exp_is_const (const struct expression *exp) | |
8748 | { | |
8749 | int i = exp->nelts; | |
8750 | ||
8751 | while (i > 0) | |
8752 | { | |
8753 | int oplenp, argsp; | |
8754 | ||
8755 | /* We are only interested in the descriptor of each element. */ | |
8756 | operator_length (exp, i, &oplenp, &argsp); | |
8757 | i -= oplenp; | |
8758 | ||
8759 | switch (exp->elts[i].opcode) | |
8760 | { | |
8761 | case BINOP_ADD: | |
8762 | case BINOP_SUB: | |
8763 | case BINOP_MUL: | |
8764 | case BINOP_DIV: | |
8765 | case BINOP_REM: | |
8766 | case BINOP_MOD: | |
8767 | case BINOP_LSH: | |
8768 | case BINOP_RSH: | |
8769 | case BINOP_LOGICAL_AND: | |
8770 | case BINOP_LOGICAL_OR: | |
8771 | case BINOP_BITWISE_AND: | |
8772 | case BINOP_BITWISE_IOR: | |
8773 | case BINOP_BITWISE_XOR: | |
8774 | case BINOP_EQUAL: | |
8775 | case BINOP_NOTEQUAL: | |
8776 | case BINOP_LESS: | |
8777 | case BINOP_GTR: | |
8778 | case BINOP_LEQ: | |
8779 | case BINOP_GEQ: | |
8780 | case BINOP_REPEAT: | |
8781 | case BINOP_COMMA: | |
8782 | case BINOP_EXP: | |
8783 | case BINOP_MIN: | |
8784 | case BINOP_MAX: | |
8785 | case BINOP_INTDIV: | |
8786 | case BINOP_CONCAT: | |
8787 | case BINOP_IN: | |
8788 | case BINOP_RANGE: | |
8789 | case TERNOP_COND: | |
8790 | case TERNOP_SLICE: | |
8791 | case TERNOP_SLICE_COUNT: | |
8792 | ||
8793 | case OP_LONG: | |
8794 | case OP_DOUBLE: | |
8795 | case OP_DECFLOAT: | |
8796 | case OP_LAST: | |
8797 | case OP_COMPLEX: | |
8798 | case OP_STRING: | |
8799 | case OP_BITSTRING: | |
8800 | case OP_ARRAY: | |
8801 | case OP_TYPE: | |
8802 | case OP_NAME: | |
8803 | case OP_OBJC_NSSTRING: | |
8804 | ||
8805 | case UNOP_NEG: | |
8806 | case UNOP_LOGICAL_NOT: | |
8807 | case UNOP_COMPLEMENT: | |
8808 | case UNOP_ADDR: | |
8809 | case UNOP_HIGH: | |
4a64f543 MS |
8810 | /* Unary, binary and ternary operators: We have to check |
8811 | their operands. If they are constant, then so is the | |
8812 | result of that operation. For instance, if A and B are | |
8813 | determined to be constants, then so is "A + B". | |
8814 | ||
8815 | UNOP_IND is one exception to the rule above, because the | |
8816 | value of *ADDR is not necessarily a constant, even when | |
8817 | ADDR is. */ | |
65d79d4b SDJ |
8818 | break; |
8819 | ||
8820 | case OP_VAR_VALUE: | |
8821 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 8822 | |
65d79d4b | 8823 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
8824 | possible that a buggy compiler could mark a variable as |
8825 | constant even when it is not, and TYPE_CONST would return | |
8826 | true in this case, while SYMBOL_CLASS wouldn't. | |
8827 | ||
8828 | We also have to check for function symbols because they | |
8829 | are always constant. */ | |
65d79d4b SDJ |
8830 | { |
8831 | struct symbol *s = exp->elts[i + 2].symbol; | |
8832 | ||
8833 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
8834 | && SYMBOL_CLASS (s) != LOC_CONST | |
8835 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
8836 | return 0; | |
8837 | break; | |
8838 | } | |
8839 | ||
8840 | /* The default action is to return 0 because we are using | |
8841 | the optimistic approach here: If we don't know something, | |
8842 | then it is not a constant. */ | |
8843 | default: | |
8844 | return 0; | |
8845 | } | |
8846 | } | |
8847 | ||
8848 | return 1; | |
8849 | } | |
8850 | ||
3a5c3e22 PA |
8851 | /* Implement the "dtor" breakpoint_ops method for watchpoints. */ |
8852 | ||
8853 | static void | |
8854 | dtor_watchpoint (struct breakpoint *self) | |
8855 | { | |
8856 | struct watchpoint *w = (struct watchpoint *) self; | |
8857 | ||
8858 | xfree (w->cond_exp); | |
8859 | xfree (w->exp); | |
8860 | xfree (w->exp_string); | |
8861 | xfree (w->exp_string_reparse); | |
8862 | value_free (w->val); | |
8863 | ||
8864 | base_breakpoint_ops.dtor (self); | |
8865 | } | |
8866 | ||
348d480f PA |
8867 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
8868 | ||
8869 | static void | |
8870 | re_set_watchpoint (struct breakpoint *b) | |
8871 | { | |
3a5c3e22 PA |
8872 | struct watchpoint *w = (struct watchpoint *) b; |
8873 | ||
348d480f PA |
8874 | /* Watchpoint can be either on expression using entirely global |
8875 | variables, or it can be on local variables. | |
8876 | ||
8877 | Watchpoints of the first kind are never auto-deleted, and even | |
8878 | persist across program restarts. Since they can use variables | |
8879 | from shared libraries, we need to reparse expression as libraries | |
8880 | are loaded and unloaded. | |
8881 | ||
8882 | Watchpoints on local variables can also change meaning as result | |
8883 | of solib event. For example, if a watchpoint uses both a local | |
8884 | and a global variables in expression, it's a local watchpoint, | |
8885 | but unloading of a shared library will make the expression | |
8886 | invalid. This is not a very common use case, but we still | |
8887 | re-evaluate expression, to avoid surprises to the user. | |
8888 | ||
8889 | Note that for local watchpoints, we re-evaluate it only if | |
8890 | watchpoints frame id is still valid. If it's not, it means the | |
8891 | watchpoint is out of scope and will be deleted soon. In fact, | |
8892 | I'm not sure we'll ever be called in this case. | |
8893 | ||
8894 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 8895 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 8896 | |
3a5c3e22 PA |
8897 | Don't do anything about disabled watchpoints, since they will be |
8898 | reevaluated again when enabled. */ | |
8899 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
8900 | } |
8901 | ||
77b06cd7 TJB |
8902 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
8903 | ||
8904 | static int | |
8905 | insert_watchpoint (struct bp_location *bl) | |
8906 | { | |
3a5c3e22 PA |
8907 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
8908 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
8909 | |
8910 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 8911 | w->cond_exp); |
77b06cd7 TJB |
8912 | } |
8913 | ||
8914 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
8915 | ||
8916 | static int | |
8917 | remove_watchpoint (struct bp_location *bl) | |
8918 | { | |
3a5c3e22 PA |
8919 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
8920 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
8921 | |
8922 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 8923 | w->cond_exp); |
e09342b5 TJB |
8924 | } |
8925 | ||
e09342b5 | 8926 | static int |
348d480f | 8927 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
09ac7c10 TT |
8928 | struct address_space *aspace, CORE_ADDR bp_addr, |
8929 | const struct target_waitstatus *ws) | |
e09342b5 | 8930 | { |
348d480f | 8931 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 8932 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 8933 | |
348d480f PA |
8934 | /* Continuable hardware watchpoints are treated as non-existent if the |
8935 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
8936 | some data address). Otherwise gdb won't stop on a break instruction | |
8937 | in the code (not from a breakpoint) when a hardware watchpoint has | |
8938 | been defined. Also skip watchpoints which we know did not trigger | |
8939 | (did not match the data address). */ | |
8940 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 8941 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 8942 | return 0; |
9c06b0b4 | 8943 | |
348d480f | 8944 | return 1; |
9c06b0b4 TJB |
8945 | } |
8946 | ||
348d480f PA |
8947 | static void |
8948 | check_status_watchpoint (bpstat bs) | |
9c06b0b4 | 8949 | { |
348d480f | 8950 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 8951 | |
348d480f | 8952 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
8953 | } |
8954 | ||
8955 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 8956 | hardware watchpoints. */ |
9c06b0b4 TJB |
8957 | |
8958 | static int | |
348d480f | 8959 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 8960 | { |
3a5c3e22 PA |
8961 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
8962 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
8963 | |
8964 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
8965 | } |
8966 | ||
8967 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 8968 | hardware watchpoints. */ |
9c06b0b4 TJB |
8969 | |
8970 | static int | |
348d480f | 8971 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 8972 | { |
efa80663 PA |
8973 | /* Read and access watchpoints only work with hardware support. */ |
8974 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
8975 | } |
8976 | ||
9c06b0b4 | 8977 | static enum print_stop_action |
348d480f | 8978 | print_it_watchpoint (bpstat bs) |
9c06b0b4 | 8979 | { |
348d480f PA |
8980 | struct cleanup *old_chain; |
8981 | struct breakpoint *b; | |
8982 | const struct bp_location *bl; | |
8983 | struct ui_stream *stb; | |
8984 | enum print_stop_action result; | |
3a5c3e22 | 8985 | struct watchpoint *w; |
79a45e25 | 8986 | struct ui_out *uiout = current_uiout; |
348d480f PA |
8987 | |
8988 | gdb_assert (bs->bp_location_at != NULL); | |
8989 | ||
8990 | bl = bs->bp_location_at; | |
8991 | b = bs->breakpoint_at; | |
3a5c3e22 | 8992 | w = (struct watchpoint *) b; |
348d480f PA |
8993 | |
8994 | stb = ui_out_stream_new (uiout); | |
8995 | old_chain = make_cleanup_ui_out_stream_delete (stb); | |
9c06b0b4 TJB |
8996 | |
8997 | switch (b->type) | |
8998 | { | |
348d480f | 8999 | case bp_watchpoint: |
9c06b0b4 TJB |
9000 | case bp_hardware_watchpoint: |
9001 | annotate_watchpoint (b->number); | |
9002 | if (ui_out_is_mi_like_p (uiout)) | |
9003 | ui_out_field_string | |
9004 | (uiout, "reason", | |
9005 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
9006 | mention (b); |
9007 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
9008 | ui_out_text (uiout, "\nOld value = "); | |
9009 | watchpoint_value_print (bs->old_val, stb->stream); | |
9010 | ui_out_field_stream (uiout, "old", stb); | |
9011 | ui_out_text (uiout, "\nNew value = "); | |
3a5c3e22 | 9012 | watchpoint_value_print (w->val, stb->stream); |
348d480f PA |
9013 | ui_out_field_stream (uiout, "new", stb); |
9014 | ui_out_text (uiout, "\n"); | |
9015 | /* More than one watchpoint may have been triggered. */ | |
9016 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
9017 | break; |
9018 | ||
9019 | case bp_read_watchpoint: | |
9020 | if (ui_out_is_mi_like_p (uiout)) | |
9021 | ui_out_field_string | |
9022 | (uiout, "reason", | |
9023 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
9024 | mention (b); |
9025 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
9026 | ui_out_text (uiout, "\nValue = "); | |
3a5c3e22 | 9027 | watchpoint_value_print (w->val, stb->stream); |
348d480f PA |
9028 | ui_out_field_stream (uiout, "value", stb); |
9029 | ui_out_text (uiout, "\n"); | |
9030 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
9031 | break; |
9032 | ||
9033 | case bp_access_watchpoint: | |
348d480f PA |
9034 | if (bs->old_val != NULL) |
9035 | { | |
9036 | annotate_watchpoint (b->number); | |
9037 | if (ui_out_is_mi_like_p (uiout)) | |
9038 | ui_out_field_string | |
9039 | (uiout, "reason", | |
9040 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
9041 | mention (b); | |
9042 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
9043 | ui_out_text (uiout, "\nOld value = "); | |
9044 | watchpoint_value_print (bs->old_val, stb->stream); | |
9045 | ui_out_field_stream (uiout, "old", stb); | |
9046 | ui_out_text (uiout, "\nNew value = "); | |
9047 | } | |
9048 | else | |
9049 | { | |
9050 | mention (b); | |
9051 | if (ui_out_is_mi_like_p (uiout)) | |
9052 | ui_out_field_string | |
9053 | (uiout, "reason", | |
9054 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
9055 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
9056 | ui_out_text (uiout, "\nValue = "); | |
9057 | } | |
3a5c3e22 | 9058 | watchpoint_value_print (w->val, stb->stream); |
348d480f PA |
9059 | ui_out_field_stream (uiout, "new", stb); |
9060 | ui_out_text (uiout, "\n"); | |
9061 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
9062 | break; |
9063 | default: | |
348d480f | 9064 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
9065 | } |
9066 | ||
348d480f PA |
9067 | do_cleanups (old_chain); |
9068 | return result; | |
9069 | } | |
9070 | ||
9071 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
9072 | watchpoints. */ | |
9073 | ||
9074 | static void | |
9075 | print_mention_watchpoint (struct breakpoint *b) | |
9076 | { | |
9077 | struct cleanup *ui_out_chain; | |
3a5c3e22 | 9078 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 9079 | struct ui_out *uiout = current_uiout; |
348d480f PA |
9080 | |
9081 | switch (b->type) | |
9082 | { | |
9083 | case bp_watchpoint: | |
9084 | ui_out_text (uiout, "Watchpoint "); | |
9085 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
9086 | break; | |
9087 | case bp_hardware_watchpoint: | |
9088 | ui_out_text (uiout, "Hardware watchpoint "); | |
9089 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
9090 | break; | |
9091 | case bp_read_watchpoint: | |
9092 | ui_out_text (uiout, "Hardware read watchpoint "); | |
9093 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
9094 | break; | |
9095 | case bp_access_watchpoint: | |
9096 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
9097 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
9098 | break; | |
9099 | default: | |
9100 | internal_error (__FILE__, __LINE__, | |
9101 | _("Invalid hardware watchpoint type.")); | |
9102 | } | |
9103 | ||
9104 | ui_out_field_int (uiout, "number", b->number); | |
9105 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 9106 | ui_out_field_string (uiout, "exp", w->exp_string); |
348d480f PA |
9107 | do_cleanups (ui_out_chain); |
9108 | } | |
9109 | ||
9110 | /* Implement the "print_recreate" breakpoint_ops method for | |
9111 | watchpoints. */ | |
9112 | ||
9113 | static void | |
9114 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
9115 | { | |
3a5c3e22 PA |
9116 | struct watchpoint *w = (struct watchpoint *) b; |
9117 | ||
348d480f PA |
9118 | switch (b->type) |
9119 | { | |
9120 | case bp_watchpoint: | |
9121 | case bp_hardware_watchpoint: | |
9122 | fprintf_unfiltered (fp, "watch"); | |
9123 | break; | |
9124 | case bp_read_watchpoint: | |
9125 | fprintf_unfiltered (fp, "rwatch"); | |
9126 | break; | |
9127 | case bp_access_watchpoint: | |
9128 | fprintf_unfiltered (fp, "awatch"); | |
9129 | break; | |
9130 | default: | |
9131 | internal_error (__FILE__, __LINE__, | |
9132 | _("Invalid watchpoint type.")); | |
9133 | } | |
9134 | ||
3a5c3e22 | 9135 | fprintf_unfiltered (fp, " %s", w->exp_string); |
d9b3f62e | 9136 | print_recreate_thread (b, fp); |
348d480f PA |
9137 | } |
9138 | ||
9139 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ | |
9140 | ||
2060206e | 9141 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
9142 | |
9143 | /* Implement the "insert" breakpoint_ops method for | |
9144 | masked hardware watchpoints. */ | |
9145 | ||
9146 | static int | |
9147 | insert_masked_watchpoint (struct bp_location *bl) | |
9148 | { | |
3a5c3e22 PA |
9149 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
9150 | ||
9151 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
9152 | bl->watchpoint_type); |
9153 | } | |
9154 | ||
9155 | /* Implement the "remove" breakpoint_ops method for | |
9156 | masked hardware watchpoints. */ | |
9157 | ||
9158 | static int | |
9159 | remove_masked_watchpoint (struct bp_location *bl) | |
9160 | { | |
3a5c3e22 PA |
9161 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
9162 | ||
9163 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
9164 | bl->watchpoint_type); |
9165 | } | |
9166 | ||
9167 | /* Implement the "resources_needed" breakpoint_ops method for | |
9168 | masked hardware watchpoints. */ | |
9169 | ||
9170 | static int | |
9171 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
9172 | { | |
3a5c3e22 PA |
9173 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
9174 | ||
9175 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
9176 | } |
9177 | ||
9178 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
9179 | masked hardware watchpoints. */ | |
9180 | ||
9181 | static int | |
9182 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
9183 | { | |
9184 | return 0; | |
9185 | } | |
9186 | ||
9187 | /* Implement the "print_it" breakpoint_ops method for | |
9188 | masked hardware watchpoints. */ | |
9189 | ||
9190 | static enum print_stop_action | |
9191 | print_it_masked_watchpoint (bpstat bs) | |
9192 | { | |
9193 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 9194 | struct ui_out *uiout = current_uiout; |
348d480f PA |
9195 | |
9196 | /* Masked watchpoints have only one location. */ | |
9197 | gdb_assert (b->loc && b->loc->next == NULL); | |
9198 | ||
9199 | switch (b->type) | |
9200 | { | |
9201 | case bp_hardware_watchpoint: | |
9202 | annotate_watchpoint (b->number); | |
9203 | if (ui_out_is_mi_like_p (uiout)) | |
9204 | ui_out_field_string | |
9205 | (uiout, "reason", | |
9206 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
9207 | break; | |
9208 | ||
9209 | case bp_read_watchpoint: | |
9210 | if (ui_out_is_mi_like_p (uiout)) | |
9211 | ui_out_field_string | |
9212 | (uiout, "reason", | |
9213 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
9214 | break; | |
9215 | ||
9216 | case bp_access_watchpoint: | |
9217 | if (ui_out_is_mi_like_p (uiout)) | |
9218 | ui_out_field_string | |
9219 | (uiout, "reason", | |
9220 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
9221 | break; | |
9222 | default: | |
9223 | internal_error (__FILE__, __LINE__, | |
9224 | _("Invalid hardware watchpoint type.")); | |
9225 | } | |
9226 | ||
9227 | mention (b); | |
9c06b0b4 TJB |
9228 | ui_out_text (uiout, _("\n\ |
9229 | Check the underlying instruction at PC for the memory\n\ | |
9230 | address and value which triggered this watchpoint.\n")); | |
9231 | ui_out_text (uiout, "\n"); | |
9232 | ||
9233 | /* More than one watchpoint may have been triggered. */ | |
9234 | return PRINT_UNKNOWN; | |
9235 | } | |
9236 | ||
9237 | /* Implement the "print_one_detail" breakpoint_ops method for | |
9238 | masked hardware watchpoints. */ | |
9239 | ||
9240 | static void | |
9241 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
9242 | struct ui_out *uiout) | |
9243 | { | |
3a5c3e22 PA |
9244 | struct watchpoint *w = (struct watchpoint *) b; |
9245 | ||
9c06b0b4 TJB |
9246 | /* Masked watchpoints have only one location. */ |
9247 | gdb_assert (b->loc && b->loc->next == NULL); | |
9248 | ||
9249 | ui_out_text (uiout, "\tmask "); | |
3a5c3e22 | 9250 | ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask); |
9c06b0b4 TJB |
9251 | ui_out_text (uiout, "\n"); |
9252 | } | |
9253 | ||
9254 | /* Implement the "print_mention" breakpoint_ops method for | |
9255 | masked hardware watchpoints. */ | |
9256 | ||
9257 | static void | |
9258 | print_mention_masked_watchpoint (struct breakpoint *b) | |
9259 | { | |
3a5c3e22 | 9260 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 9261 | struct ui_out *uiout = current_uiout; |
9c06b0b4 TJB |
9262 | struct cleanup *ui_out_chain; |
9263 | ||
9264 | switch (b->type) | |
9265 | { | |
9266 | case bp_hardware_watchpoint: | |
9267 | ui_out_text (uiout, "Masked hardware watchpoint "); | |
9268 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
9269 | break; | |
9270 | case bp_read_watchpoint: | |
9271 | ui_out_text (uiout, "Masked hardware read watchpoint "); | |
9272 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
9273 | break; | |
9274 | case bp_access_watchpoint: | |
9275 | ui_out_text (uiout, "Masked hardware access (read/write) watchpoint "); | |
9276 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
9277 | break; | |
9278 | default: | |
9279 | internal_error (__FILE__, __LINE__, | |
9280 | _("Invalid hardware watchpoint type.")); | |
9281 | } | |
9282 | ||
9283 | ui_out_field_int (uiout, "number", b->number); | |
9284 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 9285 | ui_out_field_string (uiout, "exp", w->exp_string); |
9c06b0b4 TJB |
9286 | do_cleanups (ui_out_chain); |
9287 | } | |
9288 | ||
9289 | /* Implement the "print_recreate" breakpoint_ops method for | |
9290 | masked hardware watchpoints. */ | |
9291 | ||
9292 | static void | |
9293 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
9294 | { | |
3a5c3e22 | 9295 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
9296 | char tmp[40]; |
9297 | ||
9298 | switch (b->type) | |
9299 | { | |
9300 | case bp_hardware_watchpoint: | |
9301 | fprintf_unfiltered (fp, "watch"); | |
9302 | break; | |
9303 | case bp_read_watchpoint: | |
9304 | fprintf_unfiltered (fp, "rwatch"); | |
9305 | break; | |
9306 | case bp_access_watchpoint: | |
9307 | fprintf_unfiltered (fp, "awatch"); | |
9308 | break; | |
9309 | default: | |
9310 | internal_error (__FILE__, __LINE__, | |
9311 | _("Invalid hardware watchpoint type.")); | |
9312 | } | |
9313 | ||
3a5c3e22 PA |
9314 | sprintf_vma (tmp, w->hw_wp_mask); |
9315 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); | |
d9b3f62e | 9316 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
9317 | } |
9318 | ||
9319 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
9320 | ||
2060206e | 9321 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
9322 | |
9323 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
9324 | ||
9325 | static int | |
9326 | is_masked_watchpoint (const struct breakpoint *b) | |
9327 | { | |
9328 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
9329 | } | |
9330 | ||
53a5351d JM |
9331 | /* accessflag: hw_write: watch write, |
9332 | hw_read: watch read, | |
9333 | hw_access: watch access (read or write) */ | |
c906108c | 9334 | static void |
84f4c1fe PM |
9335 | watch_command_1 (char *arg, int accessflag, int from_tty, |
9336 | int just_location, int internal) | |
c906108c | 9337 | { |
a9634178 | 9338 | volatile struct gdb_exception e; |
d983da9c | 9339 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c | 9340 | struct expression *exp; |
60e1c644 | 9341 | struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 9342 | struct value *val, *mark, *result; |
c906108c | 9343 | struct frame_info *frame; |
c906108c SS |
9344 | char *exp_start = NULL; |
9345 | char *exp_end = NULL; | |
9c06b0b4 TJB |
9346 | char *tok, *end_tok; |
9347 | int toklen = -1; | |
c906108c SS |
9348 | char *cond_start = NULL; |
9349 | char *cond_end = NULL; | |
c906108c | 9350 | enum bptype bp_type; |
37e4754d | 9351 | int thread = -1; |
0cf6dd15 | 9352 | int pc = 0; |
9c06b0b4 TJB |
9353 | /* Flag to indicate whether we are going to use masks for |
9354 | the hardware watchpoint. */ | |
9355 | int use_mask = 0; | |
9356 | CORE_ADDR mask = 0; | |
3a5c3e22 | 9357 | struct watchpoint *w; |
c906108c | 9358 | |
37e4754d LM |
9359 | /* Make sure that we actually have parameters to parse. */ |
9360 | if (arg != NULL && arg[0] != '\0') | |
9361 | { | |
9c06b0b4 | 9362 | char *value_start; |
37e4754d | 9363 | |
9c06b0b4 TJB |
9364 | /* Look for "parameter value" pairs at the end |
9365 | of the arguments string. */ | |
9366 | for (tok = arg + strlen (arg) - 1; tok > arg; tok--) | |
9367 | { | |
9368 | /* Skip whitespace at the end of the argument list. */ | |
9369 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
9370 | tok--; | |
9371 | ||
9372 | /* Find the beginning of the last token. | |
9373 | This is the value of the parameter. */ | |
9374 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
9375 | tok--; | |
9376 | value_start = tok + 1; | |
9377 | ||
9378 | /* Skip whitespace. */ | |
9379 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
9380 | tok--; | |
9381 | ||
9382 | end_tok = tok; | |
9383 | ||
9384 | /* Find the beginning of the second to last token. | |
9385 | This is the parameter itself. */ | |
9386 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
9387 | tok--; | |
9388 | tok++; | |
9389 | toklen = end_tok - tok + 1; | |
9390 | ||
9391 | if (toklen == 6 && !strncmp (tok, "thread", 6)) | |
9392 | { | |
9393 | /* At this point we've found a "thread" token, which means | |
9394 | the user is trying to set a watchpoint that triggers | |
9395 | only in a specific thread. */ | |
9396 | char *endp; | |
37e4754d | 9397 | |
9c06b0b4 TJB |
9398 | if (thread != -1) |
9399 | error(_("You can specify only one thread.")); | |
37e4754d | 9400 | |
9c06b0b4 TJB |
9401 | /* Extract the thread ID from the next token. */ |
9402 | thread = strtol (value_start, &endp, 0); | |
37e4754d | 9403 | |
9c06b0b4 TJB |
9404 | /* Check if the user provided a valid numeric value for the |
9405 | thread ID. */ | |
9406 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
9407 | error (_("Invalid thread ID specification %s."), value_start); | |
9408 | ||
9409 | /* Check if the thread actually exists. */ | |
9410 | if (!valid_thread_id (thread)) | |
9411 | error (_("Unknown thread %d."), thread); | |
9412 | } | |
9413 | else if (toklen == 4 && !strncmp (tok, "mask", 4)) | |
9414 | { | |
9415 | /* We've found a "mask" token, which means the user wants to | |
9416 | create a hardware watchpoint that is going to have the mask | |
9417 | facility. */ | |
9418 | struct value *mask_value, *mark; | |
37e4754d | 9419 | |
9c06b0b4 TJB |
9420 | if (use_mask) |
9421 | error(_("You can specify only one mask.")); | |
37e4754d | 9422 | |
9c06b0b4 | 9423 | use_mask = just_location = 1; |
37e4754d | 9424 | |
9c06b0b4 TJB |
9425 | mark = value_mark (); |
9426 | mask_value = parse_to_comma_and_eval (&value_start); | |
9427 | mask = value_as_address (mask_value); | |
9428 | value_free_to_mark (mark); | |
9429 | } | |
9430 | else | |
9431 | /* We didn't recognize what we found. We should stop here. */ | |
9432 | break; | |
37e4754d | 9433 | |
9c06b0b4 TJB |
9434 | /* Truncate the string and get rid of the "parameter value" pair before |
9435 | the arguments string is parsed by the parse_exp_1 function. */ | |
9436 | *tok = '\0'; | |
9437 | } | |
37e4754d LM |
9438 | } |
9439 | ||
9440 | /* Parse the rest of the arguments. */ | |
c906108c SS |
9441 | innermost_block = NULL; |
9442 | exp_start = arg; | |
9443 | exp = parse_exp_1 (&arg, 0, 0); | |
9444 | exp_end = arg; | |
fa8a61dc TT |
9445 | /* Remove trailing whitespace from the expression before saving it. |
9446 | This makes the eventual display of the expression string a bit | |
9447 | prettier. */ | |
9448 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
9449 | --exp_end; | |
9450 | ||
65d79d4b SDJ |
9451 | /* Checking if the expression is not constant. */ |
9452 | if (watchpoint_exp_is_const (exp)) | |
9453 | { | |
9454 | int len; | |
9455 | ||
9456 | len = exp_end - exp_start; | |
9457 | while (len > 0 && isspace (exp_start[len - 1])) | |
9458 | len--; | |
9459 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
9460 | } | |
9461 | ||
c906108c SS |
9462 | exp_valid_block = innermost_block; |
9463 | mark = value_mark (); | |
a1442452 | 9464 | fetch_subexp_value (exp, &pc, &val, &result, NULL); |
06a64a0b TT |
9465 | |
9466 | if (just_location) | |
9467 | { | |
9c06b0b4 TJB |
9468 | int ret; |
9469 | ||
06a64a0b | 9470 | exp_valid_block = NULL; |
a1442452 | 9471 | val = value_addr (result); |
06a64a0b TT |
9472 | release_value (val); |
9473 | value_free_to_mark (mark); | |
9c06b0b4 TJB |
9474 | |
9475 | if (use_mask) | |
9476 | { | |
9477 | ret = target_masked_watch_num_registers (value_as_address (val), | |
9478 | mask); | |
9479 | if (ret == -1) | |
9480 | error (_("This target does not support masked watchpoints.")); | |
9481 | else if (ret == -2) | |
9482 | error (_("Invalid mask or memory region.")); | |
9483 | } | |
06a64a0b TT |
9484 | } |
9485 | else if (val != NULL) | |
fa4727a6 | 9486 | release_value (val); |
c906108c | 9487 | |
e9cafbcc TT |
9488 | tok = skip_spaces (arg); |
9489 | end_tok = skip_to_space (tok); | |
c906108c SS |
9490 | |
9491 | toklen = end_tok - tok; | |
9492 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
9493 | { | |
2d134ed3 PA |
9494 | struct expression *cond; |
9495 | ||
60e1c644 | 9496 | innermost_block = NULL; |
c906108c SS |
9497 | tok = cond_start = end_tok + 1; |
9498 | cond = parse_exp_1 (&tok, 0, 0); | |
60e1c644 PA |
9499 | |
9500 | /* The watchpoint expression may not be local, but the condition | |
9501 | may still be. E.g.: `watch global if local > 0'. */ | |
9502 | cond_exp_valid_block = innermost_block; | |
9503 | ||
2d134ed3 | 9504 | xfree (cond); |
c906108c SS |
9505 | cond_end = tok; |
9506 | } | |
9507 | if (*tok) | |
8a3fe4f8 | 9508 | error (_("Junk at end of command.")); |
c906108c | 9509 | |
53a5351d | 9510 | if (accessflag == hw_read) |
c5aa993b | 9511 | bp_type = bp_read_watchpoint; |
53a5351d | 9512 | else if (accessflag == hw_access) |
c5aa993b JM |
9513 | bp_type = bp_access_watchpoint; |
9514 | else | |
9515 | bp_type = bp_hardware_watchpoint; | |
c906108c | 9516 | |
d983da9c | 9517 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
9518 | |
9519 | /* If the expression is "local", then set up a "watchpoint scope" | |
9520 | breakpoint at the point where we've left the scope of the watchpoint | |
9521 | expression. Create the scope breakpoint before the watchpoint, so | |
9522 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 9523 | if (exp_valid_block && frame) |
d983da9c | 9524 | { |
edb3359d DJ |
9525 | if (frame_id_p (frame_unwind_caller_id (frame))) |
9526 | { | |
9527 | scope_breakpoint | |
a6d9a66e UW |
9528 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
9529 | frame_unwind_caller_pc (frame), | |
06edf0c0 PA |
9530 | bp_watchpoint_scope, |
9531 | &momentary_breakpoint_ops); | |
d983da9c | 9532 | |
edb3359d | 9533 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 9534 | |
edb3359d DJ |
9535 | /* Automatically delete the breakpoint when it hits. */ |
9536 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 9537 | |
edb3359d DJ |
9538 | /* Only break in the proper frame (help with recursion). */ |
9539 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 9540 | |
edb3359d | 9541 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
9542 | scope_breakpoint->loc->gdbarch |
9543 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
9544 | scope_breakpoint->loc->requested_address |
9545 | = frame_unwind_caller_pc (frame); | |
9546 | scope_breakpoint->loc->address | |
a6d9a66e UW |
9547 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
9548 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
9549 | scope_breakpoint->type); |
9550 | } | |
d983da9c DJ |
9551 | } |
9552 | ||
c906108c | 9553 | /* Now set up the breakpoint. */ |
3a5c3e22 PA |
9554 | |
9555 | w = XCNEW (struct watchpoint); | |
9556 | b = &w->base; | |
348d480f | 9557 | if (use_mask) |
3a5c3e22 PA |
9558 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
9559 | &masked_watchpoint_breakpoint_ops); | |
348d480f | 9560 | else |
3a5c3e22 PA |
9561 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
9562 | &watchpoint_breakpoint_ops); | |
37e4754d | 9563 | b->thread = thread; |
b5de0fa7 | 9564 | b->disposition = disp_donttouch; |
348d480f | 9565 | b->pspace = current_program_space; |
3a5c3e22 PA |
9566 | w->exp = exp; |
9567 | w->exp_valid_block = exp_valid_block; | |
9568 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
9569 | if (just_location) |
9570 | { | |
9571 | struct type *t = value_type (val); | |
9572 | CORE_ADDR addr = value_as_address (val); | |
9573 | char *name; | |
9574 | ||
9575 | t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); | |
9576 | name = type_to_string (t); | |
9577 | ||
3a5c3e22 | 9578 | w->exp_string_reparse = xstrprintf ("* (%s *) %s", name, |
d63d0675 | 9579 | core_addr_to_string (addr)); |
06a64a0b TT |
9580 | xfree (name); |
9581 | ||
3a5c3e22 | 9582 | w->exp_string = xstrprintf ("-location %.*s", |
d63d0675 JK |
9583 | (int) (exp_end - exp_start), exp_start); |
9584 | ||
06a64a0b TT |
9585 | /* The above expression is in C. */ |
9586 | b->language = language_c; | |
9587 | } | |
9588 | else | |
3a5c3e22 | 9589 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
9c06b0b4 TJB |
9590 | |
9591 | if (use_mask) | |
9592 | { | |
3a5c3e22 | 9593 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
9594 | } |
9595 | else | |
9596 | { | |
3a5c3e22 PA |
9597 | w->val = val; |
9598 | w->val_valid = 1; | |
9c06b0b4 | 9599 | } |
77b06cd7 | 9600 | |
c906108c SS |
9601 | if (cond_start) |
9602 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
9603 | else | |
9604 | b->cond_string = 0; | |
c5aa993b | 9605 | |
c906108c | 9606 | if (frame) |
f6bc2008 | 9607 | { |
3a5c3e22 PA |
9608 | w->watchpoint_frame = get_frame_id (frame); |
9609 | w->watchpoint_thread = inferior_ptid; | |
f6bc2008 | 9610 | } |
c906108c | 9611 | else |
f6bc2008 | 9612 | { |
3a5c3e22 PA |
9613 | w->watchpoint_frame = null_frame_id; |
9614 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 9615 | } |
c906108c | 9616 | |
d983da9c | 9617 | if (scope_breakpoint != NULL) |
c906108c | 9618 | { |
d983da9c DJ |
9619 | /* The scope breakpoint is related to the watchpoint. We will |
9620 | need to act on them together. */ | |
9621 | b->related_breakpoint = scope_breakpoint; | |
9622 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 9623 | } |
d983da9c | 9624 | |
06a64a0b TT |
9625 | if (!just_location) |
9626 | value_free_to_mark (mark); | |
2d134ed3 | 9627 | |
a9634178 TJB |
9628 | TRY_CATCH (e, RETURN_MASK_ALL) |
9629 | { | |
9630 | /* Finally update the new watchpoint. This creates the locations | |
9631 | that should be inserted. */ | |
3a5c3e22 | 9632 | update_watchpoint (w, 1); |
a9634178 TJB |
9633 | } |
9634 | if (e.reason < 0) | |
9635 | { | |
9636 | delete_breakpoint (b); | |
9637 | throw_exception (e); | |
9638 | } | |
9639 | ||
3ea46bff | 9640 | install_breakpoint (internal, b, 1); |
c906108c SS |
9641 | } |
9642 | ||
e09342b5 | 9643 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 9644 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 9645 | |
c906108c | 9646 | static int |
a9634178 | 9647 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
9648 | { |
9649 | int found_memory_cnt = 0; | |
2e70b7b9 | 9650 | struct value *head = v; |
c906108c SS |
9651 | |
9652 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 9653 | if (!can_use_hw_watchpoints) |
c906108c | 9654 | return 0; |
c5aa993b | 9655 | |
5c44784c JM |
9656 | /* Make sure that the value of the expression depends only upon |
9657 | memory contents, and values computed from them within GDB. If we | |
9658 | find any register references or function calls, we can't use a | |
9659 | hardware watchpoint. | |
9660 | ||
9661 | The idea here is that evaluating an expression generates a series | |
9662 | of values, one holding the value of every subexpression. (The | |
9663 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
9664 | a*b+c.) GDB's values hold almost enough information to establish | |
9665 | the criteria given above --- they identify memory lvalues, | |
9666 | register lvalues, computed values, etcetera. So we can evaluate | |
9667 | the expression, and then scan the chain of values that leaves | |
9668 | behind to decide whether we can detect any possible change to the | |
9669 | expression's final value using only hardware watchpoints. | |
9670 | ||
9671 | However, I don't think that the values returned by inferior | |
9672 | function calls are special in any way. So this function may not | |
9673 | notice that an expression involving an inferior function call | |
9674 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 9675 | for (; v; v = value_next (v)) |
c906108c | 9676 | { |
5c44784c | 9677 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 9678 | { |
8464be76 DJ |
9679 | if (v != head && value_lazy (v)) |
9680 | /* A lazy memory lvalue in the chain is one that GDB never | |
9681 | needed to fetch; we either just used its address (e.g., | |
9682 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
9683 | in `a,b'). This doesn't apply to HEAD; if that is | |
9684 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 9685 | ; |
53a5351d | 9686 | else |
5c44784c JM |
9687 | { |
9688 | /* Ahh, memory we actually used! Check if we can cover | |
9689 | it with hardware watchpoints. */ | |
df407dfe | 9690 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
9691 | |
9692 | /* We only watch structs and arrays if user asked for it | |
9693 | explicitly, never if they just happen to appear in a | |
9694 | middle of some value chain. */ | |
9695 | if (v == head | |
9696 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
9697 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
9698 | { | |
42ae5230 | 9699 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
9700 | int len; |
9701 | int num_regs; | |
9702 | ||
a9634178 | 9703 | len = (target_exact_watchpoints |
e09342b5 TJB |
9704 | && is_scalar_type_recursive (vtype))? |
9705 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 9706 | |
e09342b5 TJB |
9707 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
9708 | if (!num_regs) | |
2e70b7b9 MS |
9709 | return 0; |
9710 | else | |
e09342b5 | 9711 | found_memory_cnt += num_regs; |
2e70b7b9 | 9712 | } |
5c44784c | 9713 | } |
c5aa993b | 9714 | } |
5086187c AC |
9715 | else if (VALUE_LVAL (v) != not_lval |
9716 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 9717 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 9718 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 9719 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
9720 | } |
9721 | ||
9722 | /* The expression itself looks suitable for using a hardware | |
9723 | watchpoint, but give the target machine a chance to reject it. */ | |
9724 | return found_memory_cnt; | |
9725 | } | |
9726 | ||
8b93c638 | 9727 | void |
84f4c1fe | 9728 | watch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 9729 | { |
84f4c1fe | 9730 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
9731 | } |
9732 | ||
9733 | /* A helper function that looks for an argument at the start of a | |
9734 | string. The argument must also either be at the end of the string, | |
9735 | or be followed by whitespace. Returns 1 if it finds the argument, | |
9736 | 0 otherwise. If the argument is found, it updates *STR. */ | |
9737 | ||
9738 | static int | |
9739 | check_for_argument (char **str, char *arg, int arg_len) | |
9740 | { | |
9741 | if (strncmp (*str, arg, arg_len) == 0 | |
9742 | && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len]))) | |
9743 | { | |
9744 | *str += arg_len; | |
9745 | return 1; | |
9746 | } | |
9747 | return 0; | |
9748 | } | |
9749 | ||
9750 | /* A helper function that looks for the "-location" argument and then | |
9751 | calls watch_command_1. */ | |
9752 | ||
9753 | static void | |
9754 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
9755 | { | |
9756 | int just_location = 0; | |
9757 | ||
9758 | if (arg | |
9759 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
9760 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
9761 | { | |
e9cafbcc | 9762 | arg = skip_spaces (arg); |
06a64a0b TT |
9763 | just_location = 1; |
9764 | } | |
9765 | ||
84f4c1fe | 9766 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 9767 | } |
8926118c | 9768 | |
c5aa993b | 9769 | static void |
fba45db2 | 9770 | watch_command (char *arg, int from_tty) |
c906108c | 9771 | { |
06a64a0b | 9772 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
9773 | } |
9774 | ||
8b93c638 | 9775 | void |
84f4c1fe | 9776 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 9777 | { |
84f4c1fe | 9778 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 9779 | } |
8926118c | 9780 | |
c5aa993b | 9781 | static void |
fba45db2 | 9782 | rwatch_command (char *arg, int from_tty) |
c906108c | 9783 | { |
06a64a0b | 9784 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
9785 | } |
9786 | ||
8b93c638 | 9787 | void |
84f4c1fe | 9788 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 9789 | { |
84f4c1fe | 9790 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 9791 | } |
8926118c | 9792 | |
c5aa993b | 9793 | static void |
fba45db2 | 9794 | awatch_command (char *arg, int from_tty) |
c906108c | 9795 | { |
06a64a0b | 9796 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 9797 | } |
c906108c | 9798 | \f |
c5aa993b | 9799 | |
43ff13b4 | 9800 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
9801 | because it uses the mechanisms of breakpoints. */ |
9802 | ||
bfec99b2 PA |
9803 | struct until_break_command_continuation_args |
9804 | { | |
9805 | struct breakpoint *breakpoint; | |
9806 | struct breakpoint *breakpoint2; | |
186c406b | 9807 | int thread_num; |
bfec99b2 PA |
9808 | }; |
9809 | ||
43ff13b4 | 9810 | /* This function is called by fetch_inferior_event via the |
4a64f543 | 9811 | cmd_continuation pointer, to complete the until command. It takes |
43ff13b4 | 9812 | care of cleaning up the temporary breakpoints set up by the until |
4a64f543 | 9813 | command. */ |
c2c6d25f | 9814 | static void |
fa4cd53f | 9815 | until_break_command_continuation (void *arg, int err) |
43ff13b4 | 9816 | { |
bfec99b2 PA |
9817 | struct until_break_command_continuation_args *a = arg; |
9818 | ||
9819 | delete_breakpoint (a->breakpoint); | |
9820 | if (a->breakpoint2) | |
9821 | delete_breakpoint (a->breakpoint2); | |
186c406b | 9822 | delete_longjmp_breakpoint (a->thread_num); |
43ff13b4 JM |
9823 | } |
9824 | ||
c906108c | 9825 | void |
ae66c1fc | 9826 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
9827 | { |
9828 | struct symtabs_and_lines sals; | |
9829 | struct symtab_and_line sal; | |
206415a3 | 9830 | struct frame_info *frame = get_selected_frame (NULL); |
c906108c | 9831 | struct breakpoint *breakpoint; |
f107f563 | 9832 | struct breakpoint *breakpoint2 = NULL; |
c906108c | 9833 | struct cleanup *old_chain; |
186c406b TT |
9834 | int thread; |
9835 | struct thread_info *tp; | |
c906108c SS |
9836 | |
9837 | clear_proceed_status (); | |
9838 | ||
9839 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 9840 | this function. */ |
c5aa993b | 9841 | |
1bfeeb0f | 9842 | if (last_displayed_sal_is_valid ()) |
f8eba3c6 | 9843 | sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE, |
1bfeeb0f | 9844 | get_last_displayed_symtab (), |
f8eba3c6 | 9845 | get_last_displayed_line ()); |
c906108c | 9846 | else |
f8eba3c6 TT |
9847 | sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE, |
9848 | (struct symtab *) NULL, 0); | |
c5aa993b | 9849 | |
c906108c | 9850 | if (sals.nelts != 1) |
8a3fe4f8 | 9851 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 9852 | |
c906108c | 9853 | sal = sals.sals[0]; |
4a64f543 | 9854 | xfree (sals.sals); /* malloc'd, so freed. */ |
c5aa993b | 9855 | |
c906108c | 9856 | if (*arg) |
8a3fe4f8 | 9857 | error (_("Junk at end of arguments.")); |
c5aa993b | 9858 | |
c906108c | 9859 | resolve_sal_pc (&sal); |
c5aa993b | 9860 | |
ae66c1fc EZ |
9861 | if (anywhere) |
9862 | /* If the user told us to continue until a specified location, | |
9863 | we don't specify a frame at which we need to stop. */ | |
a6d9a66e UW |
9864 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
9865 | null_frame_id, bp_until); | |
ae66c1fc | 9866 | else |
4a64f543 MS |
9867 | /* Otherwise, specify the selected frame, because we want to stop |
9868 | only at the very same frame. */ | |
a6d9a66e UW |
9869 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
9870 | get_stack_frame_id (frame), | |
ae66c1fc | 9871 | bp_until); |
c5aa993b | 9872 | |
f107f563 | 9873 | old_chain = make_cleanup_delete_breakpoint (breakpoint); |
c906108c | 9874 | |
186c406b TT |
9875 | tp = inferior_thread (); |
9876 | thread = tp->num; | |
9877 | ||
ae66c1fc EZ |
9878 | /* Keep within the current frame, or in frames called by the current |
9879 | one. */ | |
edb3359d DJ |
9880 | |
9881 | if (frame_id_p (frame_unwind_caller_id (frame))) | |
c906108c | 9882 | { |
edb3359d DJ |
9883 | sal = find_pc_line (frame_unwind_caller_pc (frame), 0); |
9884 | sal.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e UW |
9885 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
9886 | sal, | |
edb3359d | 9887 | frame_unwind_caller_id (frame), |
f107f563 VP |
9888 | bp_until); |
9889 | make_cleanup_delete_breakpoint (breakpoint2); | |
186c406b TT |
9890 | |
9891 | set_longjmp_breakpoint (tp, frame_unwind_caller_id (frame)); | |
9892 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); | |
c906108c | 9893 | } |
c5aa993b | 9894 | |
c906108c | 9895 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
f107f563 | 9896 | |
4a64f543 MS |
9897 | /* If we are running asynchronously, and proceed call above has |
9898 | actually managed to start the target, arrange for breakpoints to | |
9899 | be deleted when the target stops. Otherwise, we're already | |
9900 | stopped and delete breakpoints via cleanup chain. */ | |
f107f563 | 9901 | |
8ea051c5 | 9902 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 9903 | { |
bfec99b2 PA |
9904 | struct until_break_command_continuation_args *args; |
9905 | args = xmalloc (sizeof (*args)); | |
f107f563 | 9906 | |
bfec99b2 PA |
9907 | args->breakpoint = breakpoint; |
9908 | args->breakpoint2 = breakpoint2; | |
186c406b | 9909 | args->thread_num = thread; |
f107f563 VP |
9910 | |
9911 | discard_cleanups (old_chain); | |
95e54da7 PA |
9912 | add_continuation (inferior_thread (), |
9913 | until_break_command_continuation, args, | |
604ead4a | 9914 | xfree); |
f107f563 VP |
9915 | } |
9916 | else | |
c5aa993b | 9917 | do_cleanups (old_chain); |
c906108c | 9918 | } |
ae66c1fc | 9919 | |
c906108c SS |
9920 | /* This function attempts to parse an optional "if <cond>" clause |
9921 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 9922 | |
c906108c SS |
9923 | Else, it returns a pointer to the condition string. (It does not |
9924 | attempt to evaluate the string against a particular block.) And, | |
9925 | it updates arg to point to the first character following the parsed | |
4a64f543 | 9926 | if clause in the arg string. */ |
53a5351d | 9927 | |
c906108c | 9928 | static char * |
fba45db2 | 9929 | ep_parse_optional_if_clause (char **arg) |
c906108c | 9930 | { |
c5aa993b JM |
9931 | char *cond_string; |
9932 | ||
9933 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 9934 | return NULL; |
c5aa993b | 9935 | |
4a64f543 | 9936 | /* Skip the "if" keyword. */ |
c906108c | 9937 | (*arg) += 2; |
c5aa993b | 9938 | |
c906108c | 9939 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 9940 | condition string. */ |
e9cafbcc | 9941 | *arg = skip_spaces (*arg); |
c906108c | 9942 | cond_string = *arg; |
c5aa993b | 9943 | |
4a64f543 MS |
9944 | /* Assume that the condition occupies the remainder of the arg |
9945 | string. */ | |
c906108c | 9946 | (*arg) += strlen (cond_string); |
c5aa993b | 9947 | |
c906108c SS |
9948 | return cond_string; |
9949 | } | |
c5aa993b | 9950 | |
c906108c SS |
9951 | /* Commands to deal with catching events, such as signals, exceptions, |
9952 | process start/exit, etc. */ | |
c5aa993b JM |
9953 | |
9954 | typedef enum | |
9955 | { | |
44feb3ce TT |
9956 | catch_fork_temporary, catch_vfork_temporary, |
9957 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
9958 | } |
9959 | catch_fork_kind; | |
9960 | ||
c906108c | 9961 | static void |
cc59ec59 MS |
9962 | catch_fork_command_1 (char *arg, int from_tty, |
9963 | struct cmd_list_element *command) | |
c906108c | 9964 | { |
a6d9a66e | 9965 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 9966 | char *cond_string = NULL; |
44feb3ce TT |
9967 | catch_fork_kind fork_kind; |
9968 | int tempflag; | |
9969 | ||
9970 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
9971 | tempflag = (fork_kind == catch_fork_temporary | |
9972 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 9973 | |
44feb3ce TT |
9974 | if (!arg) |
9975 | arg = ""; | |
e9cafbcc | 9976 | arg = skip_spaces (arg); |
c5aa993b | 9977 | |
c906108c | 9978 | /* The allowed syntax is: |
c5aa993b JM |
9979 | catch [v]fork |
9980 | catch [v]fork if <cond> | |
9981 | ||
4a64f543 | 9982 | First, check if there's an if clause. */ |
c906108c | 9983 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 9984 | |
c906108c | 9985 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 9986 | error (_("Junk at end of arguments.")); |
c5aa993b | 9987 | |
c906108c | 9988 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 9989 | and enable reporting of such events. */ |
c5aa993b JM |
9990 | switch (fork_kind) |
9991 | { | |
44feb3ce TT |
9992 | case catch_fork_temporary: |
9993 | case catch_fork_permanent: | |
a6d9a66e | 9994 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 9995 | &catch_fork_breakpoint_ops); |
c906108c | 9996 | break; |
44feb3ce TT |
9997 | case catch_vfork_temporary: |
9998 | case catch_vfork_permanent: | |
a6d9a66e | 9999 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 10000 | &catch_vfork_breakpoint_ops); |
c906108c | 10001 | break; |
c5aa993b | 10002 | default: |
8a3fe4f8 | 10003 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 10004 | break; |
c5aa993b | 10005 | } |
c906108c SS |
10006 | } |
10007 | ||
10008 | static void | |
cc59ec59 MS |
10009 | catch_exec_command_1 (char *arg, int from_tty, |
10010 | struct cmd_list_element *command) | |
c906108c | 10011 | { |
b4d90040 | 10012 | struct exec_catchpoint *c; |
a6d9a66e | 10013 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 10014 | int tempflag; |
c5aa993b | 10015 | char *cond_string = NULL; |
c906108c | 10016 | |
44feb3ce TT |
10017 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
10018 | ||
10019 | if (!arg) | |
10020 | arg = ""; | |
e9cafbcc | 10021 | arg = skip_spaces (arg); |
c906108c SS |
10022 | |
10023 | /* The allowed syntax is: | |
c5aa993b JM |
10024 | catch exec |
10025 | catch exec if <cond> | |
c906108c | 10026 | |
4a64f543 | 10027 | First, check if there's an if clause. */ |
c906108c SS |
10028 | cond_string = ep_parse_optional_if_clause (&arg); |
10029 | ||
10030 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 10031 | error (_("Junk at end of arguments.")); |
c906108c | 10032 | |
b4d90040 PA |
10033 | c = XNEW (struct exec_catchpoint); |
10034 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, | |
10035 | &catch_exec_breakpoint_ops); | |
10036 | c->exec_pathname = NULL; | |
10037 | ||
3ea46bff | 10038 | install_breakpoint (0, &c->base, 1); |
c906108c | 10039 | } |
c5aa993b | 10040 | |
3086aeae | 10041 | static enum print_stop_action |
348d480f | 10042 | print_it_exception_catchpoint (bpstat bs) |
3086aeae | 10043 | { |
79a45e25 | 10044 | struct ui_out *uiout = current_uiout; |
348d480f | 10045 | struct breakpoint *b = bs->breakpoint_at; |
ade92717 | 10046 | int bp_temp, bp_throw; |
3086aeae | 10047 | |
ade92717 | 10048 | annotate_catchpoint (b->number); |
3086aeae | 10049 | |
ade92717 AR |
10050 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
10051 | if (b->loc->address != b->loc->requested_address) | |
10052 | breakpoint_adjustment_warning (b->loc->requested_address, | |
10053 | b->loc->address, | |
10054 | b->number, 1); | |
df2b6d2d | 10055 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
10056 | ui_out_text (uiout, |
10057 | bp_temp ? "Temporary catchpoint " | |
10058 | : "Catchpoint "); | |
10059 | if (!ui_out_is_mi_like_p (uiout)) | |
10060 | ui_out_field_int (uiout, "bkptno", b->number); | |
10061 | ui_out_text (uiout, | |
c0b37c48 AR |
10062 | bp_throw ? " (exception thrown), " |
10063 | : " (exception caught), "); | |
ade92717 AR |
10064 | if (ui_out_is_mi_like_p (uiout)) |
10065 | { | |
10066 | ui_out_field_string (uiout, "reason", | |
10067 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
10068 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
10069 | ui_out_field_int (uiout, "bkptno", b->number); | |
10070 | } | |
3086aeae DJ |
10071 | return PRINT_SRC_AND_LOC; |
10072 | } | |
10073 | ||
10074 | static void | |
cc59ec59 MS |
10075 | print_one_exception_catchpoint (struct breakpoint *b, |
10076 | struct bp_location **last_loc) | |
3086aeae | 10077 | { |
79a45b7d | 10078 | struct value_print_options opts; |
79a45e25 | 10079 | struct ui_out *uiout = current_uiout; |
cc59ec59 | 10080 | |
79a45b7d TT |
10081 | get_user_print_options (&opts); |
10082 | if (opts.addressprint) | |
3086aeae DJ |
10083 | { |
10084 | annotate_field (4); | |
604133b5 AR |
10085 | if (b->loc == NULL || b->loc->shlib_disabled) |
10086 | ui_out_field_string (uiout, "addr", "<PENDING>"); | |
10087 | else | |
5af949e3 UW |
10088 | ui_out_field_core_addr (uiout, "addr", |
10089 | b->loc->gdbarch, b->loc->address); | |
3086aeae DJ |
10090 | } |
10091 | annotate_field (5); | |
604133b5 | 10092 | if (b->loc) |
a6d9a66e | 10093 | *last_loc = b->loc; |
3086aeae DJ |
10094 | if (strstr (b->addr_string, "throw") != NULL) |
10095 | ui_out_field_string (uiout, "what", "exception throw"); | |
10096 | else | |
10097 | ui_out_field_string (uiout, "what", "exception catch"); | |
10098 | } | |
10099 | ||
10100 | static void | |
10101 | print_mention_exception_catchpoint (struct breakpoint *b) | |
10102 | { | |
79a45e25 | 10103 | struct ui_out *uiout = current_uiout; |
ade92717 AR |
10104 | int bp_temp; |
10105 | int bp_throw; | |
10106 | ||
df2b6d2d | 10107 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
10108 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
10109 | ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ") | |
10110 | : _("Catchpoint ")); | |
10111 | ui_out_field_int (uiout, "bkptno", b->number); | |
10112 | ui_out_text (uiout, bp_throw ? _(" (throw)") | |
10113 | : _(" (catch)")); | |
3086aeae DJ |
10114 | } |
10115 | ||
6149aea9 PA |
10116 | /* Implement the "print_recreate" breakpoint_ops method for throw and |
10117 | catch catchpoints. */ | |
10118 | ||
10119 | static void | |
4a64f543 MS |
10120 | print_recreate_exception_catchpoint (struct breakpoint *b, |
10121 | struct ui_file *fp) | |
6149aea9 PA |
10122 | { |
10123 | int bp_temp; | |
10124 | int bp_throw; | |
10125 | ||
10126 | bp_temp = b->disposition == disp_del; | |
10127 | bp_throw = strstr (b->addr_string, "throw") != NULL; | |
10128 | fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch "); | |
10129 | fprintf_unfiltered (fp, bp_throw ? "throw" : "catch"); | |
d9b3f62e | 10130 | print_recreate_thread (b, fp); |
6149aea9 PA |
10131 | } |
10132 | ||
2060206e | 10133 | static struct breakpoint_ops gnu_v3_exception_catchpoint_ops; |
3086aeae DJ |
10134 | |
10135 | static int | |
10136 | handle_gnu_v3_exceptions (int tempflag, char *cond_string, | |
10137 | enum exception_event_kind ex_event, int from_tty) | |
10138 | { | |
604133b5 AR |
10139 | char *trigger_func_name; |
10140 | ||
3086aeae | 10141 | if (ex_event == EX_EVENT_CATCH) |
604133b5 | 10142 | trigger_func_name = "__cxa_begin_catch"; |
3086aeae | 10143 | else |
604133b5 | 10144 | trigger_func_name = "__cxa_throw"; |
3086aeae | 10145 | |
8cdf0e15 VP |
10146 | create_breakpoint (get_current_arch (), |
10147 | trigger_func_name, cond_string, -1, | |
10148 | 0 /* condition and thread are valid. */, | |
0fb4aa4b | 10149 | tempflag, bp_breakpoint, |
8cdf0e15 VP |
10150 | 0, |
10151 | AUTO_BOOLEAN_TRUE /* pending */, | |
10152 | &gnu_v3_exception_catchpoint_ops, from_tty, | |
84f4c1fe PM |
10153 | 1 /* enabled */, |
10154 | 0 /* internal */); | |
3086aeae | 10155 | |
3086aeae DJ |
10156 | return 1; |
10157 | } | |
10158 | ||
4a64f543 | 10159 | /* Deal with "catch catch" and "catch throw" commands. */ |
c906108c SS |
10160 | |
10161 | static void | |
fba45db2 KB |
10162 | catch_exception_command_1 (enum exception_event_kind ex_event, char *arg, |
10163 | int tempflag, int from_tty) | |
c906108c | 10164 | { |
c5aa993b | 10165 | char *cond_string = NULL; |
c5aa993b | 10166 | |
44feb3ce TT |
10167 | if (!arg) |
10168 | arg = ""; | |
e9cafbcc | 10169 | arg = skip_spaces (arg); |
c5aa993b | 10170 | |
c906108c SS |
10171 | cond_string = ep_parse_optional_if_clause (&arg); |
10172 | ||
10173 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 10174 | error (_("Junk at end of arguments.")); |
c906108c | 10175 | |
059fb39f PM |
10176 | if (ex_event != EX_EVENT_THROW |
10177 | && ex_event != EX_EVENT_CATCH) | |
8a3fe4f8 | 10178 | error (_("Unsupported or unknown exception event; cannot catch it")); |
c906108c | 10179 | |
3086aeae DJ |
10180 | if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty)) |
10181 | return; | |
10182 | ||
8a3fe4f8 | 10183 | warning (_("Unsupported with this platform/compiler combination.")); |
c906108c SS |
10184 | } |
10185 | ||
44feb3ce TT |
10186 | /* Implementation of "catch catch" command. */ |
10187 | ||
10188 | static void | |
10189 | catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command) | |
10190 | { | |
10191 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
cc59ec59 | 10192 | |
44feb3ce TT |
10193 | catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty); |
10194 | } | |
10195 | ||
10196 | /* Implementation of "catch throw" command. */ | |
10197 | ||
10198 | static void | |
10199 | catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command) | |
10200 | { | |
10201 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
cc59ec59 | 10202 | |
44feb3ce TT |
10203 | catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty); |
10204 | } | |
10205 | ||
9ac4176b | 10206 | void |
28010a5d PA |
10207 | init_ada_exception_breakpoint (struct breakpoint *b, |
10208 | struct gdbarch *gdbarch, | |
10209 | struct symtab_and_line sal, | |
10210 | char *addr_string, | |
c0a91b2b | 10211 | const struct breakpoint_ops *ops, |
28010a5d PA |
10212 | int tempflag, |
10213 | int from_tty) | |
f7f9143b | 10214 | { |
f7f9143b JB |
10215 | if (from_tty) |
10216 | { | |
5af949e3 UW |
10217 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
10218 | if (!loc_gdbarch) | |
10219 | loc_gdbarch = gdbarch; | |
10220 | ||
6c95b8df PA |
10221 | describe_other_breakpoints (loc_gdbarch, |
10222 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
10223 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
10224 | version for exception catchpoints, because two catchpoints | |
10225 | used for different exception names will use the same address. | |
10226 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 10227 | unproductive. Besides, the warning phrasing is also a bit |
e5dd4106 | 10228 | inappropriate, we should use the word catchpoint, and tell |
f7f9143b JB |
10229 | the user what type of catchpoint it is. The above is good |
10230 | enough for now, though. */ | |
10231 | } | |
10232 | ||
28010a5d | 10233 | init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops); |
f7f9143b JB |
10234 | |
10235 | b->enable_state = bp_enabled; | |
10236 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
f7f9143b JB |
10237 | b->addr_string = addr_string; |
10238 | b->language = language_ada; | |
f7f9143b JB |
10239 | } |
10240 | ||
a96d9b2e SDJ |
10241 | /* Splits the argument using space as delimiter. Returns an xmalloc'd |
10242 | filter list, or NULL if no filtering is required. */ | |
10243 | static VEC(int) * | |
10244 | catch_syscall_split_args (char *arg) | |
10245 | { | |
10246 | VEC(int) *result = NULL; | |
29d0bb3d | 10247 | struct cleanup *cleanup = make_cleanup (VEC_cleanup (int), &result); |
a96d9b2e SDJ |
10248 | |
10249 | while (*arg != '\0') | |
10250 | { | |
10251 | int i, syscall_number; | |
10252 | char *endptr; | |
10253 | char cur_name[128]; | |
10254 | struct syscall s; | |
10255 | ||
10256 | /* Skip whitespace. */ | |
10257 | while (isspace (*arg)) | |
10258 | arg++; | |
10259 | ||
10260 | for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) | |
10261 | cur_name[i] = arg[i]; | |
10262 | cur_name[i] = '\0'; | |
10263 | arg += i; | |
10264 | ||
10265 | /* Check if the user provided a syscall name or a number. */ | |
10266 | syscall_number = (int) strtol (cur_name, &endptr, 0); | |
10267 | if (*endptr == '\0') | |
bccd0dd2 | 10268 | get_syscall_by_number (syscall_number, &s); |
a96d9b2e SDJ |
10269 | else |
10270 | { | |
10271 | /* We have a name. Let's check if it's valid and convert it | |
10272 | to a number. */ | |
10273 | get_syscall_by_name (cur_name, &s); | |
10274 | ||
10275 | if (s.number == UNKNOWN_SYSCALL) | |
4a64f543 MS |
10276 | /* Here we have to issue an error instead of a warning, |
10277 | because GDB cannot do anything useful if there's no | |
10278 | syscall number to be caught. */ | |
a96d9b2e SDJ |
10279 | error (_("Unknown syscall name '%s'."), cur_name); |
10280 | } | |
10281 | ||
10282 | /* Ok, it's valid. */ | |
10283 | VEC_safe_push (int, result, s.number); | |
10284 | } | |
10285 | ||
10286 | discard_cleanups (cleanup); | |
10287 | return result; | |
10288 | } | |
10289 | ||
10290 | /* Implement the "catch syscall" command. */ | |
10291 | ||
10292 | static void | |
cc59ec59 MS |
10293 | catch_syscall_command_1 (char *arg, int from_tty, |
10294 | struct cmd_list_element *command) | |
a96d9b2e SDJ |
10295 | { |
10296 | int tempflag; | |
10297 | VEC(int) *filter; | |
10298 | struct syscall s; | |
10299 | struct gdbarch *gdbarch = get_current_arch (); | |
10300 | ||
10301 | /* Checking if the feature if supported. */ | |
10302 | if (gdbarch_get_syscall_number_p (gdbarch) == 0) | |
10303 | error (_("The feature 'catch syscall' is not supported on \ | |
ea666128 | 10304 | this architecture yet.")); |
a96d9b2e SDJ |
10305 | |
10306 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
10307 | ||
e9cafbcc | 10308 | arg = skip_spaces (arg); |
a96d9b2e SDJ |
10309 | |
10310 | /* We need to do this first "dummy" translation in order | |
10311 | to get the syscall XML file loaded or, most important, | |
10312 | to display a warning to the user if there's no XML file | |
10313 | for his/her architecture. */ | |
10314 | get_syscall_by_number (0, &s); | |
10315 | ||
10316 | /* The allowed syntax is: | |
10317 | catch syscall | |
10318 | catch syscall <name | number> [<name | number> ... <name | number>] | |
10319 | ||
10320 | Let's check if there's a syscall name. */ | |
10321 | ||
10322 | if (arg != NULL) | |
10323 | filter = catch_syscall_split_args (arg); | |
10324 | else | |
10325 | filter = NULL; | |
10326 | ||
10327 | create_syscall_event_catchpoint (tempflag, filter, | |
10328 | &catch_syscall_breakpoint_ops); | |
10329 | } | |
10330 | ||
c906108c | 10331 | static void |
fba45db2 | 10332 | catch_command (char *arg, int from_tty) |
c906108c | 10333 | { |
44feb3ce | 10334 | error (_("Catch requires an event name.")); |
c906108c SS |
10335 | } |
10336 | \f | |
10337 | ||
10338 | static void | |
fba45db2 | 10339 | tcatch_command (char *arg, int from_tty) |
c906108c | 10340 | { |
44feb3ce | 10341 | error (_("Catch requires an event name.")); |
c906108c SS |
10342 | } |
10343 | ||
8a2c437b TT |
10344 | /* A qsort comparison function that sorts breakpoints in order. */ |
10345 | ||
10346 | static int | |
10347 | compare_breakpoints (const void *a, const void *b) | |
10348 | { | |
10349 | const breakpoint_p *ba = a; | |
10350 | uintptr_t ua = (uintptr_t) *ba; | |
10351 | const breakpoint_p *bb = b; | |
10352 | uintptr_t ub = (uintptr_t) *bb; | |
10353 | ||
10354 | if ((*ba)->number < (*bb)->number) | |
10355 | return -1; | |
10356 | else if ((*ba)->number > (*bb)->number) | |
10357 | return 1; | |
10358 | ||
10359 | /* Now sort by address, in case we see, e..g, two breakpoints with | |
10360 | the number 0. */ | |
10361 | if (ua < ub) | |
10362 | return -1; | |
10363 | return ub > ub ? 1 : 0; | |
10364 | } | |
10365 | ||
80f8a6eb | 10366 | /* Delete breakpoints by address or line. */ |
c906108c SS |
10367 | |
10368 | static void | |
fba45db2 | 10369 | clear_command (char *arg, int from_tty) |
c906108c | 10370 | { |
8a2c437b | 10371 | struct breakpoint *b, *prev; |
d6e956e5 VP |
10372 | VEC(breakpoint_p) *found = 0; |
10373 | int ix; | |
c906108c SS |
10374 | int default_match; |
10375 | struct symtabs_and_lines sals; | |
10376 | struct symtab_and_line sal; | |
c906108c | 10377 | int i; |
8a2c437b | 10378 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
c906108c SS |
10379 | |
10380 | if (arg) | |
10381 | { | |
f8eba3c6 TT |
10382 | sals = decode_line_spec (arg, (DECODE_LINE_FUNFIRSTLINE |
10383 | | DECODE_LINE_LIST_MODE)); | |
c906108c SS |
10384 | default_match = 0; |
10385 | } | |
10386 | else | |
10387 | { | |
c5aa993b | 10388 | sals.sals = (struct symtab_and_line *) |
c906108c | 10389 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 10390 | make_cleanup (xfree, sals.sals); |
4a64f543 | 10391 | init_sal (&sal); /* Initialize to zeroes. */ |
1bfeeb0f JL |
10392 | |
10393 | /* Set sal's line, symtab, pc, and pspace to the values | |
10394 | corresponding to the last call to print_frame_info. If the | |
10395 | codepoint is not valid, this will set all the fields to 0. */ | |
10396 | get_last_displayed_sal (&sal); | |
c906108c | 10397 | if (sal.symtab == 0) |
8a3fe4f8 | 10398 | error (_("No source file specified.")); |
c906108c SS |
10399 | |
10400 | sals.sals[0] = sal; | |
10401 | sals.nelts = 1; | |
10402 | ||
10403 | default_match = 1; | |
10404 | } | |
10405 | ||
4a64f543 MS |
10406 | /* We don't call resolve_sal_pc here. That's not as bad as it |
10407 | seems, because all existing breakpoints typically have both | |
10408 | file/line and pc set. So, if clear is given file/line, we can | |
10409 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
10410 | |
10411 | We only support clearing given the address explicitly | |
10412 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 10413 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 10414 | due to optimization, all in one block. |
4a64f543 MS |
10415 | |
10416 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
10417 | PC corresponding to the same file:line, the breakpoint won't |
10418 | be cleared. We probably can still clear the breakpoint, but | |
10419 | since the other PC value is never presented to user, user | |
10420 | can only find it by guessing, and it does not seem important | |
10421 | to support that. */ | |
10422 | ||
4a64f543 MS |
10423 | /* For each line spec given, delete bps which correspond to it. Do |
10424 | it in two passes, solely to preserve the current behavior that | |
10425 | from_tty is forced true if we delete more than one | |
10426 | breakpoint. */ | |
c906108c | 10427 | |
80f8a6eb | 10428 | found = NULL; |
8a2c437b | 10429 | make_cleanup (VEC_cleanup (breakpoint_p), &found); |
c906108c SS |
10430 | for (i = 0; i < sals.nelts; i++) |
10431 | { | |
4aac40c8 TT |
10432 | int is_abs, sal_name_len; |
10433 | ||
c906108c | 10434 | /* If exact pc given, clear bpts at that pc. |
c5aa993b JM |
10435 | If line given (pc == 0), clear all bpts on specified line. |
10436 | If defaulting, clear all bpts on default line | |
c906108c | 10437 | or at default pc. |
c5aa993b JM |
10438 | |
10439 | defaulting sal.pc != 0 tests to do | |
10440 | ||
10441 | 0 1 pc | |
10442 | 1 1 pc _and_ line | |
10443 | 0 0 line | |
10444 | 1 0 <can't happen> */ | |
c906108c SS |
10445 | |
10446 | sal = sals.sals[i]; | |
4aac40c8 TT |
10447 | is_abs = sal.symtab == NULL ? 1 : IS_ABSOLUTE_PATH (sal.symtab->filename); |
10448 | sal_name_len = is_abs ? 0 : strlen (sal.symtab->filename); | |
c906108c | 10449 | |
4a64f543 | 10450 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 10451 | ALL_BREAKPOINTS (b) |
c5aa993b | 10452 | { |
0d381245 | 10453 | int match = 0; |
4a64f543 | 10454 | /* Are we going to delete b? */ |
cc60f2e3 | 10455 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
10456 | { |
10457 | struct bp_location *loc = b->loc; | |
10458 | for (; loc; loc = loc->next) | |
10459 | { | |
f8eba3c6 TT |
10460 | /* If the user specified file:line, don't allow a PC |
10461 | match. This matches historical gdb behavior. */ | |
10462 | int pc_match = (!sal.explicit_line | |
10463 | && sal.pc | |
10464 | && (loc->pspace == sal.pspace) | |
10465 | && (loc->address == sal.pc) | |
10466 | && (!section_is_overlay (loc->section) | |
10467 | || loc->section == sal.section)); | |
4aac40c8 TT |
10468 | int line_match = 0; |
10469 | ||
10470 | if ((default_match || sal.explicit_line) | |
10471 | && loc->source_file != NULL | |
10472 | && sal.symtab != NULL | |
10473 | && sal.pspace == loc->pspace | |
10474 | && loc->line_number == sal.line) | |
10475 | { | |
10476 | if (filename_cmp (loc->source_file, | |
10477 | sal.symtab->filename) == 0) | |
10478 | line_match = 1; | |
10479 | else if (!IS_ABSOLUTE_PATH (sal.symtab->filename) | |
10480 | && compare_filenames_for_search (loc->source_file, | |
10481 | sal.symtab->filename, | |
10482 | sal_name_len)) | |
10483 | line_match = 1; | |
10484 | } | |
10485 | ||
0d381245 VP |
10486 | if (pc_match || line_match) |
10487 | { | |
10488 | match = 1; | |
10489 | break; | |
10490 | } | |
10491 | } | |
10492 | } | |
10493 | ||
10494 | if (match) | |
d6e956e5 | 10495 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 10496 | } |
80f8a6eb | 10497 | } |
8a2c437b | 10498 | |
80f8a6eb | 10499 | /* Now go thru the 'found' chain and delete them. */ |
d6e956e5 | 10500 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
10501 | { |
10502 | if (arg) | |
8a3fe4f8 | 10503 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 10504 | else |
8a3fe4f8 | 10505 | error (_("No breakpoint at this line.")); |
80f8a6eb | 10506 | } |
c906108c | 10507 | |
8a2c437b TT |
10508 | /* Remove duplicates from the vec. */ |
10509 | qsort (VEC_address (breakpoint_p, found), | |
10510 | VEC_length (breakpoint_p, found), | |
10511 | sizeof (breakpoint_p), | |
10512 | compare_breakpoints); | |
10513 | prev = VEC_index (breakpoint_p, found, 0); | |
10514 | for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix) | |
10515 | { | |
10516 | if (b == prev) | |
10517 | { | |
10518 | VEC_ordered_remove (breakpoint_p, found, ix); | |
10519 | --ix; | |
10520 | } | |
10521 | } | |
10522 | ||
d6e956e5 | 10523 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 10524 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 10525 | if (from_tty) |
a3f17187 | 10526 | { |
d6e956e5 | 10527 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
10528 | printf_unfiltered (_("Deleted breakpoint ")); |
10529 | else | |
10530 | printf_unfiltered (_("Deleted breakpoints ")); | |
10531 | } | |
80f8a6eb | 10532 | breakpoints_changed (); |
d6e956e5 VP |
10533 | |
10534 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 10535 | { |
c5aa993b | 10536 | if (from_tty) |
d6e956e5 VP |
10537 | printf_unfiltered ("%d ", b->number); |
10538 | delete_breakpoint (b); | |
c906108c | 10539 | } |
80f8a6eb MS |
10540 | if (from_tty) |
10541 | putchar_unfiltered ('\n'); | |
8a2c437b TT |
10542 | |
10543 | do_cleanups (cleanups); | |
c906108c SS |
10544 | } |
10545 | \f | |
10546 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
10547 | all breakpoints that are marked for deletion, whether hit or not. | |
10548 | This is called after any breakpoint is hit, or after errors. */ | |
10549 | ||
10550 | void | |
fba45db2 | 10551 | breakpoint_auto_delete (bpstat bs) |
c906108c | 10552 | { |
35df4500 | 10553 | struct breakpoint *b, *b_tmp; |
c906108c SS |
10554 | |
10555 | for (; bs; bs = bs->next) | |
f431efe5 PA |
10556 | if (bs->breakpoint_at |
10557 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 10558 | && bs->stop) |
f431efe5 | 10559 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 10560 | |
35df4500 | 10561 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 10562 | { |
b5de0fa7 | 10563 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
10564 | delete_breakpoint (b); |
10565 | } | |
c906108c SS |
10566 | } |
10567 | ||
4a64f543 MS |
10568 | /* A comparison function for bp_location AP and BP being interfaced to |
10569 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
10570 | does breakpoint_address_is_meaningful say for its OWNER), | |
10571 | secondarily by ordering first bp_permanent OWNERed elements and | |
10572 | terciarily just ensuring the array is sorted stable way despite | |
e5dd4106 | 10573 | qsort being an unstable algorithm. */ |
876fa593 JK |
10574 | |
10575 | static int | |
494cfb0f | 10576 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 10577 | { |
494cfb0f JK |
10578 | struct bp_location *a = *(void **) ap; |
10579 | struct bp_location *b = *(void **) bp; | |
2bdf28a0 | 10580 | /* A and B come from existing breakpoints having non-NULL OWNER. */ |
876fa593 JK |
10581 | int a_perm = a->owner->enable_state == bp_permanent; |
10582 | int b_perm = b->owner->enable_state == bp_permanent; | |
10583 | ||
10584 | if (a->address != b->address) | |
10585 | return (a->address > b->address) - (a->address < b->address); | |
10586 | ||
10587 | /* Sort permanent breakpoints first. */ | |
10588 | if (a_perm != b_perm) | |
10589 | return (a_perm < b_perm) - (a_perm > b_perm); | |
10590 | ||
4a64f543 MS |
10591 | /* Make the user-visible order stable across GDB runs. Locations of |
10592 | the same breakpoint can be sorted in arbitrary order. */ | |
876fa593 JK |
10593 | |
10594 | if (a->owner->number != b->owner->number) | |
10595 | return (a->owner->number > b->owner->number) | |
10596 | - (a->owner->number < b->owner->number); | |
10597 | ||
10598 | return (a > b) - (a < b); | |
10599 | } | |
10600 | ||
876fa593 | 10601 | /* Set bp_location_placed_address_before_address_max and |
4a64f543 MS |
10602 | bp_location_shadow_len_after_address_max according to the current |
10603 | content of the bp_location array. */ | |
f7545552 TT |
10604 | |
10605 | static void | |
876fa593 | 10606 | bp_location_target_extensions_update (void) |
f7545552 | 10607 | { |
876fa593 JK |
10608 | struct bp_location *bl, **blp_tmp; |
10609 | ||
10610 | bp_location_placed_address_before_address_max = 0; | |
10611 | bp_location_shadow_len_after_address_max = 0; | |
10612 | ||
10613 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
10614 | { | |
10615 | CORE_ADDR start, end, addr; | |
10616 | ||
10617 | if (!bp_location_has_shadow (bl)) | |
10618 | continue; | |
10619 | ||
10620 | start = bl->target_info.placed_address; | |
10621 | end = start + bl->target_info.shadow_len; | |
10622 | ||
10623 | gdb_assert (bl->address >= start); | |
10624 | addr = bl->address - start; | |
10625 | if (addr > bp_location_placed_address_before_address_max) | |
10626 | bp_location_placed_address_before_address_max = addr; | |
10627 | ||
10628 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
10629 | ||
10630 | gdb_assert (bl->address < end); | |
10631 | addr = end - bl->address; | |
10632 | if (addr > bp_location_shadow_len_after_address_max) | |
10633 | bp_location_shadow_len_after_address_max = addr; | |
10634 | } | |
f7545552 TT |
10635 | } |
10636 | ||
1e4d1764 YQ |
10637 | /* Download tracepoint locations if they haven't been. */ |
10638 | ||
10639 | static void | |
10640 | download_tracepoint_locations (void) | |
10641 | { | |
10642 | struct bp_location *bl, **blp_tmp; | |
10643 | struct cleanup *old_chain; | |
10644 | ||
10645 | if (!target_can_download_tracepoint ()) | |
10646 | return; | |
10647 | ||
10648 | old_chain = save_current_space_and_thread (); | |
10649 | ||
10650 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
10651 | { | |
10652 | struct tracepoint *t; | |
10653 | ||
10654 | if (!is_tracepoint (bl->owner)) | |
10655 | continue; | |
10656 | ||
10657 | if ((bl->owner->type == bp_fast_tracepoint | |
10658 | ? !may_insert_fast_tracepoints | |
10659 | : !may_insert_tracepoints)) | |
10660 | continue; | |
10661 | ||
10662 | /* In tracepoint, locations are _never_ duplicated, so | |
10663 | should_be_inserted is equivalent to | |
10664 | unduplicated_should_be_inserted. */ | |
10665 | if (!should_be_inserted (bl) || bl->inserted) | |
10666 | continue; | |
10667 | ||
10668 | switch_to_program_space_and_thread (bl->pspace); | |
10669 | ||
10670 | target_download_tracepoint (bl); | |
10671 | ||
10672 | bl->inserted = 1; | |
10673 | t = (struct tracepoint *) bl->owner; | |
10674 | t->number_on_target = bl->owner->number; | |
10675 | } | |
10676 | ||
10677 | do_cleanups (old_chain); | |
10678 | } | |
10679 | ||
934709f0 PW |
10680 | /* Swap the insertion/duplication state between two locations. */ |
10681 | ||
10682 | static void | |
10683 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
10684 | { | |
10685 | const int left_inserted = left->inserted; | |
10686 | const int left_duplicate = left->duplicate; | |
10687 | const struct bp_target_info left_target_info = left->target_info; | |
10688 | ||
1e4d1764 YQ |
10689 | /* Locations of tracepoints can never be duplicated. */ |
10690 | if (is_tracepoint (left->owner)) | |
10691 | gdb_assert (!left->duplicate); | |
10692 | if (is_tracepoint (right->owner)) | |
10693 | gdb_assert (!right->duplicate); | |
10694 | ||
934709f0 PW |
10695 | left->inserted = right->inserted; |
10696 | left->duplicate = right->duplicate; | |
10697 | left->target_info = right->target_info; | |
10698 | right->inserted = left_inserted; | |
10699 | right->duplicate = left_duplicate; | |
10700 | right->target_info = left_target_info; | |
10701 | } | |
10702 | ||
4cd9bd08 | 10703 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
b60e7edf PA |
10704 | into the inferior, only remove already-inserted locations that no |
10705 | longer should be inserted. Functions that delete a breakpoint or | |
10706 | breakpoints should pass false, so that deleting a breakpoint | |
10707 | doesn't have the side effect of inserting the locations of other | |
10708 | breakpoints that are marked not-inserted, but should_be_inserted | |
10709 | returns true on them. | |
10710 | ||
10711 | This behaviour is useful is situations close to tear-down -- e.g., | |
10712 | after an exec, while the target still has execution, but breakpoint | |
10713 | shadows of the previous executable image should *NOT* be restored | |
10714 | to the new image; or before detaching, where the target still has | |
10715 | execution and wants to delete breakpoints from GDB's lists, and all | |
10716 | breakpoints had already been removed from the inferior. */ | |
10717 | ||
0d381245 | 10718 | static void |
b60e7edf | 10719 | update_global_location_list (int should_insert) |
0d381245 | 10720 | { |
74960c60 | 10721 | struct breakpoint *b; |
876fa593 | 10722 | struct bp_location **locp, *loc; |
f7545552 TT |
10723 | struct cleanup *cleanups; |
10724 | ||
2d134ed3 PA |
10725 | /* Used in the duplicates detection below. When iterating over all |
10726 | bp_locations, points to the first bp_location of a given address. | |
10727 | Breakpoints and watchpoints of different types are never | |
10728 | duplicates of each other. Keep one pointer for each type of | |
10729 | breakpoint/watchpoint, so we only need to loop over all locations | |
10730 | once. */ | |
10731 | struct bp_location *bp_loc_first; /* breakpoint */ | |
10732 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
10733 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
10734 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 10735 | |
4a64f543 MS |
10736 | /* Saved former bp_location array which we compare against the newly |
10737 | built bp_location from the current state of ALL_BREAKPOINTS. */ | |
876fa593 JK |
10738 | struct bp_location **old_location, **old_locp; |
10739 | unsigned old_location_count; | |
10740 | ||
10741 | old_location = bp_location; | |
10742 | old_location_count = bp_location_count; | |
10743 | bp_location = NULL; | |
10744 | bp_location_count = 0; | |
10745 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 10746 | |
74960c60 | 10747 | ALL_BREAKPOINTS (b) |
876fa593 JK |
10748 | for (loc = b->loc; loc; loc = loc->next) |
10749 | bp_location_count++; | |
10750 | ||
10751 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); | |
10752 | locp = bp_location; | |
10753 | ALL_BREAKPOINTS (b) | |
10754 | for (loc = b->loc; loc; loc = loc->next) | |
10755 | *locp++ = loc; | |
10756 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 10757 | bp_location_compare); |
876fa593 JK |
10758 | |
10759 | bp_location_target_extensions_update (); | |
74960c60 | 10760 | |
4a64f543 MS |
10761 | /* Identify bp_location instances that are no longer present in the |
10762 | new list, and therefore should be freed. Note that it's not | |
10763 | necessary that those locations should be removed from inferior -- | |
10764 | if there's another location at the same address (previously | |
10765 | marked as duplicate), we don't need to remove/insert the | |
10766 | location. | |
876fa593 | 10767 | |
4a64f543 MS |
10768 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
10769 | and former bp_location array state respectively. */ | |
876fa593 JK |
10770 | |
10771 | locp = bp_location; | |
10772 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
10773 | old_locp++) | |
74960c60 | 10774 | { |
876fa593 | 10775 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 10776 | struct bp_location **loc2p; |
876fa593 | 10777 | |
e5dd4106 | 10778 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 10779 | not, we have to free it. */ |
c7d46a38 | 10780 | int found_object = 0; |
20874c92 VP |
10781 | /* Tells if the location should remain inserted in the target. */ |
10782 | int keep_in_target = 0; | |
10783 | int removed = 0; | |
876fa593 | 10784 | |
4a64f543 MS |
10785 | /* Skip LOCP entries which will definitely never be needed. |
10786 | Stop either at or being the one matching OLD_LOC. */ | |
876fa593 | 10787 | while (locp < bp_location + bp_location_count |
c7d46a38 | 10788 | && (*locp)->address < old_loc->address) |
876fa593 | 10789 | locp++; |
c7d46a38 PA |
10790 | |
10791 | for (loc2p = locp; | |
10792 | (loc2p < bp_location + bp_location_count | |
10793 | && (*loc2p)->address == old_loc->address); | |
10794 | loc2p++) | |
10795 | { | |
10796 | if (*loc2p == old_loc) | |
10797 | { | |
10798 | found_object = 1; | |
10799 | break; | |
10800 | } | |
10801 | } | |
74960c60 | 10802 | |
4a64f543 MS |
10803 | /* If this location is no longer present, and inserted, look if |
10804 | there's maybe a new location at the same address. If so, | |
10805 | mark that one inserted, and don't remove this one. This is | |
10806 | needed so that we don't have a time window where a breakpoint | |
10807 | at certain location is not inserted. */ | |
74960c60 | 10808 | |
876fa593 | 10809 | if (old_loc->inserted) |
0d381245 | 10810 | { |
4a64f543 MS |
10811 | /* If the location is inserted now, we might have to remove |
10812 | it. */ | |
74960c60 | 10813 | |
876fa593 | 10814 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 10815 | { |
4a64f543 MS |
10816 | /* The location is still present in the location list, |
10817 | and still should be inserted. Don't do anything. */ | |
20874c92 | 10818 | keep_in_target = 1; |
74960c60 VP |
10819 | } |
10820 | else | |
10821 | { | |
4a64f543 MS |
10822 | /* The location is either no longer present, or got |
10823 | disabled. See if there's another location at the | |
10824 | same address, in which case we don't need to remove | |
10825 | this one from the target. */ | |
876fa593 | 10826 | |
2bdf28a0 | 10827 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
10828 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
10829 | { | |
876fa593 | 10830 | for (loc2p = locp; |
c7d46a38 PA |
10831 | (loc2p < bp_location + bp_location_count |
10832 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
10833 | loc2p++) |
10834 | { | |
10835 | struct bp_location *loc2 = *loc2p; | |
10836 | ||
2d134ed3 | 10837 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 10838 | { |
85d721b8 PA |
10839 | /* Read watchpoint locations are switched to |
10840 | access watchpoints, if the former are not | |
10841 | supported, but the latter are. */ | |
10842 | if (is_hardware_watchpoint (old_loc->owner)) | |
10843 | { | |
10844 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
10845 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
10846 | } | |
10847 | ||
934709f0 PW |
10848 | /* loc2 is a duplicated location. We need to check |
10849 | if it should be inserted in case it will be | |
10850 | unduplicated. */ | |
10851 | if (loc2 != old_loc | |
10852 | && unduplicated_should_be_inserted (loc2)) | |
c7d46a38 | 10853 | { |
934709f0 | 10854 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
10855 | keep_in_target = 1; |
10856 | break; | |
10857 | } | |
876fa593 JK |
10858 | } |
10859 | } | |
10860 | } | |
74960c60 VP |
10861 | } |
10862 | ||
20874c92 VP |
10863 | if (!keep_in_target) |
10864 | { | |
876fa593 | 10865 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 | 10866 | { |
4a64f543 MS |
10867 | /* This is just about all we can do. We could keep |
10868 | this location on the global list, and try to | |
10869 | remove it next time, but there's no particular | |
10870 | reason why we will succeed next time. | |
20874c92 | 10871 | |
4a64f543 MS |
10872 | Note that at this point, old_loc->owner is still |
10873 | valid, as delete_breakpoint frees the breakpoint | |
10874 | only after calling us. */ | |
3e43a32a MS |
10875 | printf_filtered (_("warning: Error removing " |
10876 | "breakpoint %d\n"), | |
876fa593 | 10877 | old_loc->owner->number); |
20874c92 VP |
10878 | } |
10879 | removed = 1; | |
10880 | } | |
0d381245 | 10881 | } |
74960c60 VP |
10882 | |
10883 | if (!found_object) | |
1c5cfe86 | 10884 | { |
db82e815 PA |
10885 | if (removed && non_stop |
10886 | && breakpoint_address_is_meaningful (old_loc->owner) | |
10887 | && !is_hardware_watchpoint (old_loc->owner)) | |
20874c92 | 10888 | { |
db82e815 PA |
10889 | /* This location was removed from the target. In |
10890 | non-stop mode, a race condition is possible where | |
10891 | we've removed a breakpoint, but stop events for that | |
10892 | breakpoint are already queued and will arrive later. | |
10893 | We apply an heuristic to be able to distinguish such | |
10894 | SIGTRAPs from other random SIGTRAPs: we keep this | |
10895 | breakpoint location for a bit, and will retire it | |
10896 | after we see some number of events. The theory here | |
10897 | is that reporting of events should, "on the average", | |
10898 | be fair, so after a while we'll see events from all | |
10899 | threads that have anything of interest, and no longer | |
10900 | need to keep this breakpoint location around. We | |
10901 | don't hold locations forever so to reduce chances of | |
10902 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
10903 | SIGTRAP. | |
10904 | ||
10905 | The heuristic failing can be disastrous on | |
10906 | decr_pc_after_break targets. | |
10907 | ||
10908 | On decr_pc_after_break targets, like e.g., x86-linux, | |
10909 | if we fail to recognize a late breakpoint SIGTRAP, | |
10910 | because events_till_retirement has reached 0 too | |
10911 | soon, we'll fail to do the PC adjustment, and report | |
10912 | a random SIGTRAP to the user. When the user resumes | |
10913 | the inferior, it will most likely immediately crash | |
2dec564e | 10914 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
10915 | corrupted, because of being resumed e.g., in the |
10916 | middle of a multi-byte instruction, or skipped a | |
10917 | one-byte instruction. This was actually seen happen | |
10918 | on native x86-linux, and should be less rare on | |
10919 | targets that do not support new thread events, like | |
10920 | remote, due to the heuristic depending on | |
10921 | thread_count. | |
10922 | ||
10923 | Mistaking a random SIGTRAP for a breakpoint trap | |
10924 | causes similar symptoms (PC adjustment applied when | |
10925 | it shouldn't), but then again, playing with SIGTRAPs | |
10926 | behind the debugger's back is asking for trouble. | |
10927 | ||
10928 | Since hardware watchpoint traps are always | |
10929 | distinguishable from other traps, so we don't need to | |
10930 | apply keep hardware watchpoint moribund locations | |
10931 | around. We simply always ignore hardware watchpoint | |
10932 | traps we can no longer explain. */ | |
10933 | ||
876fa593 JK |
10934 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
10935 | old_loc->owner = NULL; | |
20874c92 | 10936 | |
876fa593 | 10937 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
10938 | } |
10939 | else | |
f431efe5 PA |
10940 | { |
10941 | old_loc->owner = NULL; | |
10942 | decref_bp_location (&old_loc); | |
10943 | } | |
20874c92 | 10944 | } |
74960c60 | 10945 | } |
1c5cfe86 | 10946 | |
348d480f PA |
10947 | /* Rescan breakpoints at the same address and section, marking the |
10948 | first one as "first" and any others as "duplicates". This is so | |
10949 | that the bpt instruction is only inserted once. If we have a | |
10950 | permanent breakpoint at the same place as BPT, make that one the | |
10951 | official one, and the rest as duplicates. Permanent breakpoints | |
10952 | are sorted first for the same address. | |
10953 | ||
10954 | Do the same for hardware watchpoints, but also considering the | |
10955 | watchpoint's type (regular/access/read) and length. */ | |
10956 | ||
10957 | bp_loc_first = NULL; | |
10958 | wp_loc_first = NULL; | |
10959 | awp_loc_first = NULL; | |
10960 | rwp_loc_first = NULL; | |
10961 | ALL_BP_LOCATIONS (loc, locp) | |
10962 | { | |
10963 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
10964 | non-NULL. */ | |
348d480f | 10965 | struct bp_location **loc_first_p; |
d3fbdd86 | 10966 | b = loc->owner; |
348d480f | 10967 | |
f8eba3c6 | 10968 | if (!should_be_inserted (loc) |
348d480f | 10969 | || !breakpoint_address_is_meaningful (b) |
1e4d1764 YQ |
10970 | /* Don't detect duplicate for tracepoint locations because they are |
10971 | never duplicated. See the comments in field `duplicate' of | |
10972 | `struct bp_location'. */ | |
348d480f PA |
10973 | || is_tracepoint (b)) |
10974 | continue; | |
10975 | ||
10976 | /* Permanent breakpoint should always be inserted. */ | |
10977 | if (b->enable_state == bp_permanent && ! loc->inserted) | |
10978 | internal_error (__FILE__, __LINE__, | |
10979 | _("allegedly permanent breakpoint is not " | |
10980 | "actually inserted")); | |
10981 | ||
10982 | if (b->type == bp_hardware_watchpoint) | |
10983 | loc_first_p = &wp_loc_first; | |
10984 | else if (b->type == bp_read_watchpoint) | |
10985 | loc_first_p = &rwp_loc_first; | |
10986 | else if (b->type == bp_access_watchpoint) | |
10987 | loc_first_p = &awp_loc_first; | |
10988 | else | |
10989 | loc_first_p = &bp_loc_first; | |
10990 | ||
10991 | if (*loc_first_p == NULL | |
10992 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
10993 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
10994 | { | |
10995 | *loc_first_p = loc; | |
10996 | loc->duplicate = 0; | |
10997 | continue; | |
10998 | } | |
10999 | ||
934709f0 PW |
11000 | |
11001 | /* This and the above ensure the invariant that the first location | |
11002 | is not duplicated, and is the inserted one. | |
11003 | All following are marked as duplicated, and are not inserted. */ | |
11004 | if (loc->inserted) | |
11005 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
11006 | loc->duplicate = 1; |
11007 | ||
11008 | if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted | |
11009 | && b->enable_state != bp_permanent) | |
11010 | internal_error (__FILE__, __LINE__, | |
11011 | _("another breakpoint was inserted on top of " | |
11012 | "a permanent breakpoint")); | |
11013 | } | |
11014 | ||
11015 | if (breakpoints_always_inserted_mode () && should_insert | |
11016 | && (have_live_inferiors () | |
11017 | || (gdbarch_has_global_breakpoints (target_gdbarch)))) | |
11018 | insert_breakpoint_locations (); | |
11019 | ||
1e4d1764 YQ |
11020 | if (should_insert) |
11021 | download_tracepoint_locations (); | |
11022 | ||
348d480f PA |
11023 | do_cleanups (cleanups); |
11024 | } | |
11025 | ||
11026 | void | |
11027 | breakpoint_retire_moribund (void) | |
11028 | { | |
11029 | struct bp_location *loc; | |
11030 | int ix; | |
11031 | ||
11032 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
11033 | if (--(loc->events_till_retirement) == 0) | |
11034 | { | |
11035 | decref_bp_location (&loc); | |
11036 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
11037 | --ix; | |
11038 | } | |
11039 | } | |
11040 | ||
11041 | static void | |
11042 | update_global_location_list_nothrow (int inserting) | |
11043 | { | |
bfd189b1 | 11044 | volatile struct gdb_exception e; |
348d480f PA |
11045 | |
11046 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
11047 | update_global_location_list (inserting); | |
11048 | } | |
11049 | ||
11050 | /* Clear BKP from a BPS. */ | |
11051 | ||
11052 | static void | |
11053 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) | |
11054 | { | |
11055 | bpstat bs; | |
11056 | ||
11057 | for (bs = bps; bs; bs = bs->next) | |
11058 | if (bs->breakpoint_at == bpt) | |
11059 | { | |
11060 | bs->breakpoint_at = NULL; | |
11061 | bs->old_val = NULL; | |
11062 | /* bs->commands will be freed later. */ | |
11063 | } | |
11064 | } | |
11065 | ||
11066 | /* Callback for iterate_over_threads. */ | |
11067 | static int | |
11068 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
11069 | { | |
11070 | struct breakpoint *bpt = data; | |
11071 | ||
11072 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
11073 | return 0; | |
11074 | } | |
11075 | ||
11076 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
11077 | callbacks. */ | |
11078 | ||
11079 | static void | |
11080 | say_where (struct breakpoint *b) | |
11081 | { | |
79a45e25 | 11082 | struct ui_out *uiout = current_uiout; |
348d480f PA |
11083 | struct value_print_options opts; |
11084 | ||
11085 | get_user_print_options (&opts); | |
11086 | ||
11087 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
11088 | single string. */ | |
11089 | if (b->loc == NULL) | |
11090 | { | |
11091 | printf_filtered (_(" (%s) pending."), b->addr_string); | |
11092 | } | |
11093 | else | |
11094 | { | |
f8eba3c6 | 11095 | if (opts.addressprint || b->loc->source_file == NULL) |
348d480f PA |
11096 | { |
11097 | printf_filtered (" at "); | |
11098 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), | |
11099 | gdb_stdout); | |
11100 | } | |
f8eba3c6 TT |
11101 | if (b->loc->source_file) |
11102 | { | |
11103 | /* If there is a single location, we can print the location | |
11104 | more nicely. */ | |
11105 | if (b->loc->next == NULL) | |
11106 | printf_filtered (": file %s, line %d.", | |
11107 | b->loc->source_file, b->loc->line_number); | |
11108 | else | |
11109 | /* This is not ideal, but each location may have a | |
11110 | different file name, and this at least reflects the | |
11111 | real situation somewhat. */ | |
11112 | printf_filtered (": %s.", b->addr_string); | |
11113 | } | |
348d480f PA |
11114 | |
11115 | if (b->loc->next) | |
11116 | { | |
11117 | struct bp_location *loc = b->loc; | |
11118 | int n = 0; | |
11119 | for (; loc; loc = loc->next) | |
11120 | ++n; | |
11121 | printf_filtered (" (%d locations)", n); | |
11122 | } | |
11123 | } | |
11124 | } | |
11125 | ||
348d480f PA |
11126 | /* Default bp_location_ops methods. */ |
11127 | ||
11128 | static void | |
11129 | bp_location_dtor (struct bp_location *self) | |
11130 | { | |
11131 | xfree (self->cond); | |
11132 | xfree (self->function_name); | |
f8eba3c6 | 11133 | xfree (self->source_file); |
348d480f PA |
11134 | } |
11135 | ||
11136 | static const struct bp_location_ops bp_location_ops = | |
11137 | { | |
11138 | bp_location_dtor | |
11139 | }; | |
11140 | ||
2060206e PA |
11141 | /* Default breakpoint_ops methods all breakpoint_ops ultimately |
11142 | inherit from. */ | |
348d480f | 11143 | |
2060206e PA |
11144 | static void |
11145 | base_breakpoint_dtor (struct breakpoint *self) | |
348d480f PA |
11146 | { |
11147 | decref_counted_command_line (&self->commands); | |
11148 | xfree (self->cond_string); | |
348d480f | 11149 | xfree (self->addr_string); |
f8eba3c6 | 11150 | xfree (self->filter); |
348d480f | 11151 | xfree (self->addr_string_range_end); |
348d480f PA |
11152 | } |
11153 | ||
2060206e PA |
11154 | static struct bp_location * |
11155 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f PA |
11156 | { |
11157 | struct bp_location *loc; | |
11158 | ||
11159 | loc = XNEW (struct bp_location); | |
11160 | init_bp_location (loc, &bp_location_ops, self); | |
11161 | return loc; | |
11162 | } | |
11163 | ||
2060206e PA |
11164 | static void |
11165 | base_breakpoint_re_set (struct breakpoint *b) | |
11166 | { | |
11167 | /* Nothing to re-set. */ | |
11168 | } | |
11169 | ||
11170 | #define internal_error_pure_virtual_called() \ | |
11171 | gdb_assert_not_reached ("pure virtual function called") | |
11172 | ||
11173 | static int | |
11174 | base_breakpoint_insert_location (struct bp_location *bl) | |
11175 | { | |
11176 | internal_error_pure_virtual_called (); | |
11177 | } | |
11178 | ||
11179 | static int | |
11180 | base_breakpoint_remove_location (struct bp_location *bl) | |
11181 | { | |
11182 | internal_error_pure_virtual_called (); | |
11183 | } | |
11184 | ||
11185 | static int | |
11186 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
11187 | struct address_space *aspace, | |
09ac7c10 TT |
11188 | CORE_ADDR bp_addr, |
11189 | const struct target_waitstatus *ws) | |
2060206e PA |
11190 | { |
11191 | internal_error_pure_virtual_called (); | |
11192 | } | |
11193 | ||
11194 | static void | |
11195 | base_breakpoint_check_status (bpstat bs) | |
11196 | { | |
11197 | /* Always stop. */ | |
11198 | } | |
11199 | ||
11200 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
11201 | errors. */ | |
11202 | ||
11203 | static int | |
11204 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
11205 | { | |
11206 | internal_error_pure_virtual_called (); | |
11207 | } | |
11208 | ||
11209 | /* A "resources_needed" breakpoint_ops method that just internal | |
11210 | errors. */ | |
11211 | ||
11212 | static int | |
11213 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
11214 | { | |
11215 | internal_error_pure_virtual_called (); | |
11216 | } | |
11217 | ||
11218 | static enum print_stop_action | |
11219 | base_breakpoint_print_it (bpstat bs) | |
11220 | { | |
11221 | internal_error_pure_virtual_called (); | |
11222 | } | |
11223 | ||
11224 | static void | |
11225 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
11226 | struct ui_out *uiout) | |
11227 | { | |
11228 | /* nothing */ | |
11229 | } | |
11230 | ||
11231 | static void | |
11232 | base_breakpoint_print_mention (struct breakpoint *b) | |
11233 | { | |
11234 | internal_error_pure_virtual_called (); | |
11235 | } | |
11236 | ||
11237 | static void | |
11238 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
11239 | { | |
11240 | internal_error_pure_virtual_called (); | |
11241 | } | |
11242 | ||
983af33b SDJ |
11243 | static void |
11244 | base_breakpoint_create_sals_from_address (char **arg, | |
11245 | struct linespec_result *canonical, | |
11246 | enum bptype type_wanted, | |
11247 | char *addr_start, | |
11248 | char **copy_arg) | |
11249 | { | |
11250 | internal_error_pure_virtual_called (); | |
11251 | } | |
11252 | ||
11253 | static void | |
11254 | base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
11255 | struct linespec_result *c, | |
11256 | struct linespec_sals *lsal, | |
11257 | char *cond_string, | |
11258 | enum bptype type_wanted, | |
11259 | enum bpdisp disposition, | |
11260 | int thread, | |
11261 | int task, int ignore_count, | |
11262 | const struct breakpoint_ops *o, | |
11263 | int from_tty, int enabled, | |
11264 | int internal) | |
11265 | { | |
11266 | internal_error_pure_virtual_called (); | |
11267 | } | |
11268 | ||
11269 | static void | |
11270 | base_breakpoint_decode_linespec (struct breakpoint *b, char **s, | |
11271 | struct symtabs_and_lines *sals) | |
11272 | { | |
11273 | internal_error_pure_virtual_called (); | |
11274 | } | |
11275 | ||
2060206e PA |
11276 | static struct breakpoint_ops base_breakpoint_ops = |
11277 | { | |
11278 | base_breakpoint_dtor, | |
11279 | base_breakpoint_allocate_location, | |
11280 | base_breakpoint_re_set, | |
11281 | base_breakpoint_insert_location, | |
11282 | base_breakpoint_remove_location, | |
11283 | base_breakpoint_breakpoint_hit, | |
11284 | base_breakpoint_check_status, | |
11285 | base_breakpoint_resources_needed, | |
11286 | base_breakpoint_works_in_software_mode, | |
11287 | base_breakpoint_print_it, | |
11288 | NULL, | |
11289 | base_breakpoint_print_one_detail, | |
11290 | base_breakpoint_print_mention, | |
983af33b SDJ |
11291 | base_breakpoint_print_recreate, |
11292 | base_breakpoint_create_sals_from_address, | |
11293 | base_breakpoint_create_breakpoints_sal, | |
11294 | base_breakpoint_decode_linespec, | |
2060206e PA |
11295 | }; |
11296 | ||
11297 | /* Default breakpoint_ops methods. */ | |
11298 | ||
11299 | static void | |
348d480f PA |
11300 | bkpt_re_set (struct breakpoint *b) |
11301 | { | |
06edf0c0 PA |
11302 | /* FIXME: is this still reachable? */ |
11303 | if (b->addr_string == NULL) | |
11304 | { | |
11305 | /* Anything without a string can't be re-set. */ | |
348d480f | 11306 | delete_breakpoint (b); |
06edf0c0 | 11307 | return; |
348d480f | 11308 | } |
06edf0c0 PA |
11309 | |
11310 | breakpoint_re_set_default (b); | |
348d480f PA |
11311 | } |
11312 | ||
2060206e | 11313 | static int |
348d480f PA |
11314 | bkpt_insert_location (struct bp_location *bl) |
11315 | { | |
11316 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
11317 | return target_insert_hw_breakpoint (bl->gdbarch, | |
11318 | &bl->target_info); | |
11319 | else | |
11320 | return target_insert_breakpoint (bl->gdbarch, | |
11321 | &bl->target_info); | |
11322 | } | |
11323 | ||
2060206e | 11324 | static int |
348d480f PA |
11325 | bkpt_remove_location (struct bp_location *bl) |
11326 | { | |
11327 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
11328 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
11329 | else | |
11330 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info); | |
11331 | } | |
11332 | ||
2060206e | 11333 | static int |
348d480f | 11334 | bkpt_breakpoint_hit (const struct bp_location *bl, |
09ac7c10 TT |
11335 | struct address_space *aspace, CORE_ADDR bp_addr, |
11336 | const struct target_waitstatus *ws) | |
348d480f PA |
11337 | { |
11338 | struct breakpoint *b = bl->owner; | |
11339 | ||
09ac7c10 TT |
11340 | if (ws->kind != TARGET_WAITKIND_STOPPED |
11341 | || ws->value.sig != TARGET_SIGNAL_TRAP) | |
11342 | return 0; | |
11343 | ||
348d480f PA |
11344 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
11345 | aspace, bp_addr)) | |
11346 | return 0; | |
11347 | ||
11348 | if (overlay_debugging /* unmapped overlay section */ | |
11349 | && section_is_overlay (bl->section) | |
11350 | && !section_is_mapped (bl->section)) | |
11351 | return 0; | |
11352 | ||
11353 | return 1; | |
11354 | } | |
11355 | ||
2060206e | 11356 | static int |
348d480f PA |
11357 | bkpt_resources_needed (const struct bp_location *bl) |
11358 | { | |
11359 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
11360 | ||
11361 | return 1; | |
11362 | } | |
11363 | ||
2060206e | 11364 | static enum print_stop_action |
348d480f PA |
11365 | bkpt_print_it (bpstat bs) |
11366 | { | |
348d480f PA |
11367 | struct breakpoint *b; |
11368 | const struct bp_location *bl; | |
001c8c33 | 11369 | int bp_temp; |
79a45e25 | 11370 | struct ui_out *uiout = current_uiout; |
348d480f PA |
11371 | |
11372 | gdb_assert (bs->bp_location_at != NULL); | |
11373 | ||
11374 | bl = bs->bp_location_at; | |
11375 | b = bs->breakpoint_at; | |
11376 | ||
001c8c33 PA |
11377 | bp_temp = b->disposition == disp_del; |
11378 | if (bl->address != bl->requested_address) | |
11379 | breakpoint_adjustment_warning (bl->requested_address, | |
11380 | bl->address, | |
11381 | b->number, 1); | |
11382 | annotate_breakpoint (b->number); | |
11383 | if (bp_temp) | |
11384 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
11385 | else | |
11386 | ui_out_text (uiout, "\nBreakpoint "); | |
11387 | if (ui_out_is_mi_like_p (uiout)) | |
348d480f | 11388 | { |
001c8c33 PA |
11389 | ui_out_field_string (uiout, "reason", |
11390 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
11391 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
06edf0c0 | 11392 | } |
001c8c33 PA |
11393 | ui_out_field_int (uiout, "bkptno", b->number); |
11394 | ui_out_text (uiout, ", "); | |
06edf0c0 | 11395 | |
001c8c33 | 11396 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
11397 | } |
11398 | ||
2060206e | 11399 | static void |
06edf0c0 PA |
11400 | bkpt_print_mention (struct breakpoint *b) |
11401 | { | |
79a45e25 | 11402 | if (ui_out_is_mi_like_p (current_uiout)) |
06edf0c0 PA |
11403 | return; |
11404 | ||
11405 | switch (b->type) | |
11406 | { | |
11407 | case bp_breakpoint: | |
11408 | case bp_gnu_ifunc_resolver: | |
11409 | if (b->disposition == disp_del) | |
11410 | printf_filtered (_("Temporary breakpoint")); | |
11411 | else | |
11412 | printf_filtered (_("Breakpoint")); | |
11413 | printf_filtered (_(" %d"), b->number); | |
11414 | if (b->type == bp_gnu_ifunc_resolver) | |
11415 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
11416 | break; | |
11417 | case bp_hardware_breakpoint: | |
11418 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
11419 | break; | |
11420 | } | |
11421 | ||
11422 | say_where (b); | |
11423 | } | |
11424 | ||
2060206e | 11425 | static void |
06edf0c0 PA |
11426 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
11427 | { | |
11428 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
11429 | fprintf_unfiltered (fp, "tbreak"); | |
11430 | else if (tp->type == bp_breakpoint) | |
11431 | fprintf_unfiltered (fp, "break"); | |
11432 | else if (tp->type == bp_hardware_breakpoint | |
11433 | && tp->disposition == disp_del) | |
11434 | fprintf_unfiltered (fp, "thbreak"); | |
11435 | else if (tp->type == bp_hardware_breakpoint) | |
11436 | fprintf_unfiltered (fp, "hbreak"); | |
11437 | else | |
11438 | internal_error (__FILE__, __LINE__, | |
11439 | _("unhandled breakpoint type %d"), (int) tp->type); | |
11440 | ||
2060206e | 11441 | fprintf_unfiltered (fp, " %s", tp->addr_string); |
dd11a36c | 11442 | print_recreate_thread (tp, fp); |
06edf0c0 PA |
11443 | } |
11444 | ||
983af33b SDJ |
11445 | static void |
11446 | bkpt_create_sals_from_address (char **arg, | |
11447 | struct linespec_result *canonical, | |
11448 | enum bptype type_wanted, | |
11449 | char *addr_start, char **copy_arg) | |
11450 | { | |
11451 | create_sals_from_address_default (arg, canonical, type_wanted, | |
11452 | addr_start, copy_arg); | |
11453 | } | |
11454 | ||
11455 | static void | |
11456 | bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, | |
11457 | struct linespec_result *canonical, | |
11458 | struct linespec_sals *lsal, | |
11459 | char *cond_string, | |
11460 | enum bptype type_wanted, | |
11461 | enum bpdisp disposition, | |
11462 | int thread, | |
11463 | int task, int ignore_count, | |
11464 | const struct breakpoint_ops *ops, | |
11465 | int from_tty, int enabled, | |
11466 | int internal) | |
11467 | { | |
11468 | create_breakpoints_sal_default (gdbarch, canonical, lsal, | |
11469 | cond_string, type_wanted, | |
11470 | disposition, thread, task, | |
11471 | ignore_count, ops, from_tty, | |
11472 | enabled, internal); | |
11473 | } | |
11474 | ||
11475 | static void | |
11476 | bkpt_decode_linespec (struct breakpoint *b, char **s, | |
11477 | struct symtabs_and_lines *sals) | |
11478 | { | |
11479 | decode_linespec_default (b, s, sals); | |
11480 | } | |
11481 | ||
06edf0c0 PA |
11482 | /* Virtual table for internal breakpoints. */ |
11483 | ||
11484 | static void | |
11485 | internal_bkpt_re_set (struct breakpoint *b) | |
11486 | { | |
11487 | switch (b->type) | |
11488 | { | |
11489 | /* Delete overlay event and longjmp master breakpoints; they | |
11490 | will be reset later by breakpoint_re_set. */ | |
11491 | case bp_overlay_event: | |
11492 | case bp_longjmp_master: | |
11493 | case bp_std_terminate_master: | |
11494 | case bp_exception_master: | |
11495 | delete_breakpoint (b); | |
11496 | break; | |
11497 | ||
11498 | /* This breakpoint is special, it's set up when the inferior | |
11499 | starts and we really don't want to touch it. */ | |
11500 | case bp_shlib_event: | |
11501 | ||
11502 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
11503 | it is set up, we do not want to touch it. */ | |
11504 | case bp_thread_event: | |
11505 | break; | |
11506 | } | |
11507 | } | |
11508 | ||
11509 | static void | |
11510 | internal_bkpt_check_status (bpstat bs) | |
11511 | { | |
a9b3a50f PA |
11512 | if (bs->breakpoint_at->type == bp_shlib_event) |
11513 | { | |
11514 | /* If requested, stop when the dynamic linker notifies GDB of | |
11515 | events. This allows the user to get control and place | |
11516 | breakpoints in initializer routines for dynamically loaded | |
11517 | objects (among other things). */ | |
11518 | bs->stop = stop_on_solib_events; | |
11519 | bs->print = stop_on_solib_events; | |
11520 | } | |
11521 | else | |
11522 | bs->stop = 0; | |
06edf0c0 PA |
11523 | } |
11524 | ||
11525 | static enum print_stop_action | |
11526 | internal_bkpt_print_it (bpstat bs) | |
11527 | { | |
36dfb11c | 11528 | struct ui_out *uiout = current_uiout; |
06edf0c0 | 11529 | struct breakpoint *b; |
06edf0c0 | 11530 | |
06edf0c0 PA |
11531 | b = bs->breakpoint_at; |
11532 | ||
06edf0c0 PA |
11533 | switch (b->type) |
11534 | { | |
348d480f PA |
11535 | case bp_shlib_event: |
11536 | /* Did we stop because the user set the stop_on_solib_events | |
11537 | variable? (If so, we report this as a generic, "Stopped due | |
11538 | to shlib event" message.) */ | |
edcc5120 | 11539 | print_solib_event (0); |
348d480f PA |
11540 | break; |
11541 | ||
11542 | case bp_thread_event: | |
11543 | /* Not sure how we will get here. | |
11544 | GDB should not stop for these breakpoints. */ | |
11545 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
11546 | break; |
11547 | ||
11548 | case bp_overlay_event: | |
11549 | /* By analogy with the thread event, GDB should not stop for these. */ | |
11550 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
11551 | break; |
11552 | ||
11553 | case bp_longjmp_master: | |
11554 | /* These should never be enabled. */ | |
11555 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
11556 | break; |
11557 | ||
11558 | case bp_std_terminate_master: | |
11559 | /* These should never be enabled. */ | |
11560 | printf_filtered (_("std::terminate Master Breakpoint: " | |
11561 | "gdb should not stop!\n")); | |
348d480f PA |
11562 | break; |
11563 | ||
11564 | case bp_exception_master: | |
11565 | /* These should never be enabled. */ | |
11566 | printf_filtered (_("Exception Master Breakpoint: " | |
11567 | "gdb should not stop!\n")); | |
06edf0c0 PA |
11568 | break; |
11569 | } | |
11570 | ||
001c8c33 | 11571 | return PRINT_NOTHING; |
06edf0c0 PA |
11572 | } |
11573 | ||
11574 | static void | |
11575 | internal_bkpt_print_mention (struct breakpoint *b) | |
11576 | { | |
11577 | /* Nothing to mention. These breakpoints are internal. */ | |
11578 | } | |
11579 | ||
06edf0c0 PA |
11580 | /* Virtual table for momentary breakpoints */ |
11581 | ||
11582 | static void | |
11583 | momentary_bkpt_re_set (struct breakpoint *b) | |
11584 | { | |
11585 | /* Keep temporary breakpoints, which can be encountered when we step | |
11586 | over a dlopen call and SOLIB_ADD is resetting the breakpoints. | |
11587 | Otherwise these should have been blown away via the cleanup chain | |
11588 | or by breakpoint_init_inferior when we rerun the executable. */ | |
11589 | } | |
11590 | ||
11591 | static void | |
11592 | momentary_bkpt_check_status (bpstat bs) | |
11593 | { | |
11594 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
11595 | } | |
11596 | ||
11597 | static enum print_stop_action | |
11598 | momentary_bkpt_print_it (bpstat bs) | |
11599 | { | |
79a45e25 PA |
11600 | struct ui_out *uiout = current_uiout; |
11601 | ||
001c8c33 | 11602 | if (ui_out_is_mi_like_p (uiout)) |
06edf0c0 | 11603 | { |
001c8c33 | 11604 | struct breakpoint *b = bs->breakpoint_at; |
348d480f | 11605 | |
001c8c33 PA |
11606 | switch (b->type) |
11607 | { | |
11608 | case bp_finish: | |
11609 | ui_out_field_string | |
11610 | (uiout, "reason", | |
11611 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
11612 | break; | |
348d480f | 11613 | |
001c8c33 PA |
11614 | case bp_until: |
11615 | ui_out_field_string | |
11616 | (uiout, "reason", | |
11617 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
11618 | break; | |
11619 | } | |
348d480f PA |
11620 | } |
11621 | ||
001c8c33 | 11622 | return PRINT_UNKNOWN; |
348d480f PA |
11623 | } |
11624 | ||
06edf0c0 PA |
11625 | static void |
11626 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 11627 | { |
06edf0c0 | 11628 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
11629 | } |
11630 | ||
348d480f | 11631 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 11632 | |
348d480f PA |
11633 | static void |
11634 | tracepoint_re_set (struct breakpoint *b) | |
11635 | { | |
11636 | breakpoint_re_set_default (b); | |
11637 | } | |
876fa593 | 11638 | |
348d480f PA |
11639 | static int |
11640 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
09ac7c10 TT |
11641 | struct address_space *aspace, CORE_ADDR bp_addr, |
11642 | const struct target_waitstatus *ws) | |
348d480f PA |
11643 | { |
11644 | /* By definition, the inferior does not report stops at | |
11645 | tracepoints. */ | |
11646 | return 0; | |
74960c60 VP |
11647 | } |
11648 | ||
11649 | static void | |
348d480f PA |
11650 | tracepoint_print_one_detail (const struct breakpoint *self, |
11651 | struct ui_out *uiout) | |
74960c60 | 11652 | { |
d9b3f62e PA |
11653 | struct tracepoint *tp = (struct tracepoint *) self; |
11654 | if (tp->static_trace_marker_id) | |
348d480f PA |
11655 | { |
11656 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 11657 | |
348d480f PA |
11658 | ui_out_text (uiout, "\tmarker id is "); |
11659 | ui_out_field_string (uiout, "static-tracepoint-marker-string-id", | |
d9b3f62e | 11660 | tp->static_trace_marker_id); |
348d480f PA |
11661 | ui_out_text (uiout, "\n"); |
11662 | } | |
0d381245 VP |
11663 | } |
11664 | ||
a474d7c2 | 11665 | static void |
348d480f | 11666 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 11667 | { |
79a45e25 | 11668 | if (ui_out_is_mi_like_p (current_uiout)) |
348d480f | 11669 | return; |
cc59ec59 | 11670 | |
348d480f PA |
11671 | switch (b->type) |
11672 | { | |
11673 | case bp_tracepoint: | |
11674 | printf_filtered (_("Tracepoint")); | |
11675 | printf_filtered (_(" %d"), b->number); | |
11676 | break; | |
11677 | case bp_fast_tracepoint: | |
11678 | printf_filtered (_("Fast tracepoint")); | |
11679 | printf_filtered (_(" %d"), b->number); | |
11680 | break; | |
11681 | case bp_static_tracepoint: | |
11682 | printf_filtered (_("Static tracepoint")); | |
11683 | printf_filtered (_(" %d"), b->number); | |
11684 | break; | |
11685 | default: | |
11686 | internal_error (__FILE__, __LINE__, | |
11687 | _("unhandled tracepoint type %d"), (int) b->type); | |
11688 | } | |
11689 | ||
11690 | say_where (b); | |
a474d7c2 PA |
11691 | } |
11692 | ||
348d480f | 11693 | static void |
d9b3f62e | 11694 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 11695 | { |
d9b3f62e PA |
11696 | struct tracepoint *tp = (struct tracepoint *) self; |
11697 | ||
11698 | if (self->type == bp_fast_tracepoint) | |
348d480f | 11699 | fprintf_unfiltered (fp, "ftrace"); |
d9b3f62e | 11700 | if (self->type == bp_static_tracepoint) |
348d480f | 11701 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 11702 | else if (self->type == bp_tracepoint) |
348d480f PA |
11703 | fprintf_unfiltered (fp, "trace"); |
11704 | else | |
11705 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 11706 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 11707 | |
d9b3f62e PA |
11708 | fprintf_unfiltered (fp, " %s", self->addr_string); |
11709 | print_recreate_thread (self, fp); | |
11710 | ||
11711 | if (tp->pass_count) | |
11712 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
11713 | } |
11714 | ||
983af33b SDJ |
11715 | static void |
11716 | tracepoint_create_sals_from_address (char **arg, | |
11717 | struct linespec_result *canonical, | |
11718 | enum bptype type_wanted, | |
11719 | char *addr_start, char **copy_arg) | |
11720 | { | |
11721 | create_sals_from_address_default (arg, canonical, type_wanted, | |
11722 | addr_start, copy_arg); | |
11723 | } | |
11724 | ||
11725 | static void | |
11726 | tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
11727 | struct linespec_result *canonical, | |
11728 | struct linespec_sals *lsal, | |
11729 | char *cond_string, | |
11730 | enum bptype type_wanted, | |
11731 | enum bpdisp disposition, | |
11732 | int thread, | |
11733 | int task, int ignore_count, | |
11734 | const struct breakpoint_ops *ops, | |
11735 | int from_tty, int enabled, | |
11736 | int internal) | |
11737 | { | |
11738 | create_breakpoints_sal_default (gdbarch, canonical, lsal, | |
11739 | cond_string, type_wanted, | |
11740 | disposition, thread, task, | |
11741 | ignore_count, ops, from_tty, | |
11742 | enabled, internal); | |
11743 | } | |
11744 | ||
11745 | static void | |
11746 | tracepoint_decode_linespec (struct breakpoint *b, char **s, | |
11747 | struct symtabs_and_lines *sals) | |
11748 | { | |
11749 | decode_linespec_default (b, s, sals); | |
11750 | } | |
11751 | ||
2060206e | 11752 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 11753 | |
983af33b SDJ |
11754 | /* The breakpoint_ops structure to be used on static tracepoints with |
11755 | markers (`-m'). */ | |
11756 | ||
11757 | static void | |
11758 | strace_marker_create_sals_from_address (char **arg, | |
11759 | struct linespec_result *canonical, | |
11760 | enum bptype type_wanted, | |
11761 | char *addr_start, char **copy_arg) | |
11762 | { | |
11763 | struct linespec_sals lsal; | |
11764 | ||
11765 | lsal.sals = decode_static_tracepoint_spec (arg); | |
11766 | ||
11767 | *copy_arg = savestring (addr_start, *arg - addr_start); | |
11768 | ||
11769 | canonical->addr_string = xstrdup (*copy_arg); | |
11770 | lsal.canonical = xstrdup (*copy_arg); | |
11771 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
11772 | } | |
11773 | ||
11774 | static void | |
11775 | strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, | |
11776 | struct linespec_result *canonical, | |
11777 | struct linespec_sals *lsal, | |
11778 | char *cond_string, | |
11779 | enum bptype type_wanted, | |
11780 | enum bpdisp disposition, | |
11781 | int thread, | |
11782 | int task, int ignore_count, | |
11783 | const struct breakpoint_ops *ops, | |
11784 | int from_tty, int enabled, | |
11785 | int internal) | |
11786 | { | |
11787 | int i; | |
11788 | ||
11789 | /* If the user is creating a static tracepoint by marker id | |
11790 | (strace -m MARKER_ID), then store the sals index, so that | |
11791 | breakpoint_re_set can try to match up which of the newly | |
11792 | found markers corresponds to this one, and, don't try to | |
11793 | expand multiple locations for each sal, given than SALS | |
11794 | already should contain all sals for MARKER_ID. */ | |
11795 | ||
11796 | for (i = 0; i < lsal->sals.nelts; ++i) | |
11797 | { | |
11798 | struct symtabs_and_lines expanded; | |
11799 | struct tracepoint *tp; | |
11800 | struct cleanup *old_chain; | |
11801 | char *addr_string; | |
11802 | ||
11803 | expanded.nelts = 1; | |
11804 | expanded.sals = &lsal->sals.sals[i]; | |
11805 | ||
11806 | addr_string = xstrdup (canonical->addr_string); | |
11807 | old_chain = make_cleanup (xfree, addr_string); | |
11808 | ||
11809 | tp = XCNEW (struct tracepoint); | |
11810 | init_breakpoint_sal (&tp->base, gdbarch, expanded, | |
11811 | addr_string, NULL, | |
11812 | cond_string, type_wanted, disposition, | |
11813 | thread, task, ignore_count, ops, | |
11814 | from_tty, enabled, internal, | |
11815 | canonical->special_display); | |
11816 | /* Given that its possible to have multiple markers with | |
11817 | the same string id, if the user is creating a static | |
11818 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
11819 | store the sals index, so that breakpoint_re_set can | |
11820 | try to match up which of the newly found markers | |
11821 | corresponds to this one */ | |
11822 | tp->static_trace_marker_id_idx = i; | |
11823 | ||
11824 | install_breakpoint (internal, &tp->base, 0); | |
11825 | ||
11826 | discard_cleanups (old_chain); | |
11827 | } | |
11828 | } | |
11829 | ||
11830 | static void | |
11831 | strace_marker_decode_linespec (struct breakpoint *b, char **s, | |
11832 | struct symtabs_and_lines *sals) | |
11833 | { | |
11834 | struct tracepoint *tp = (struct tracepoint *) b; | |
11835 | ||
11836 | *sals = decode_static_tracepoint_spec (s); | |
11837 | if (sals->nelts > tp->static_trace_marker_id_idx) | |
11838 | { | |
11839 | sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx]; | |
11840 | sals->nelts = 1; | |
11841 | } | |
11842 | else | |
11843 | error (_("marker %s not found"), tp->static_trace_marker_id); | |
11844 | } | |
11845 | ||
11846 | static struct breakpoint_ops strace_marker_breakpoint_ops; | |
11847 | ||
11848 | static int | |
11849 | strace_marker_p (struct breakpoint *b) | |
11850 | { | |
11851 | return b->ops == &strace_marker_breakpoint_ops; | |
11852 | } | |
11853 | ||
53a5351d | 11854 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 11855 | structures. */ |
c906108c SS |
11856 | |
11857 | void | |
fba45db2 | 11858 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 11859 | { |
52f0bd74 | 11860 | struct breakpoint *b; |
c906108c | 11861 | |
8a3fe4f8 | 11862 | gdb_assert (bpt != NULL); |
c906108c | 11863 | |
4a64f543 MS |
11864 | /* Has this bp already been deleted? This can happen because |
11865 | multiple lists can hold pointers to bp's. bpstat lists are | |
11866 | especial culprits. | |
11867 | ||
11868 | One example of this happening is a watchpoint's scope bp. When | |
11869 | the scope bp triggers, we notice that the watchpoint is out of | |
11870 | scope, and delete it. We also delete its scope bp. But the | |
11871 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
11872 | That bpstat is then checked for auto-deleting bp's, which are | |
11873 | deleted. | |
11874 | ||
11875 | A real solution to this problem might involve reference counts in | |
11876 | bp's, and/or giving them pointers back to their referencing | |
11877 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
11878 | storage when no more references were extent. A cheaper bandaid | |
11879 | was chosen. */ | |
c906108c SS |
11880 | if (bpt->type == bp_none) |
11881 | return; | |
11882 | ||
4a64f543 MS |
11883 | /* At least avoid this stale reference until the reference counting |
11884 | of breakpoints gets resolved. */ | |
d0fb5eae | 11885 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 11886 | { |
d0fb5eae | 11887 | struct breakpoint *related; |
3a5c3e22 | 11888 | struct watchpoint *w; |
d0fb5eae JK |
11889 | |
11890 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 11891 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 11892 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
11893 | w = (struct watchpoint *) bpt; |
11894 | else | |
11895 | w = NULL; | |
11896 | if (w != NULL) | |
11897 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
11898 | |
11899 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
11900 | for (related = bpt; related->related_breakpoint != bpt; | |
11901 | related = related->related_breakpoint); | |
11902 | related->related_breakpoint = bpt->related_breakpoint; | |
11903 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
11904 | } |
11905 | ||
a9634178 TJB |
11906 | /* watch_command_1 creates a watchpoint but only sets its number if |
11907 | update_watchpoint succeeds in creating its bp_locations. If there's | |
11908 | a problem in that process, we'll be asked to delete the half-created | |
11909 | watchpoint. In that case, don't announce the deletion. */ | |
11910 | if (bpt->number) | |
11911 | observer_notify_breakpoint_deleted (bpt); | |
c906108c | 11912 | |
c906108c SS |
11913 | if (breakpoint_chain == bpt) |
11914 | breakpoint_chain = bpt->next; | |
11915 | ||
c906108c SS |
11916 | ALL_BREAKPOINTS (b) |
11917 | if (b->next == bpt) | |
c5aa993b JM |
11918 | { |
11919 | b->next = bpt->next; | |
11920 | break; | |
11921 | } | |
c906108c | 11922 | |
f431efe5 PA |
11923 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
11924 | been freed. */ | |
11925 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 11926 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
11927 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
11928 | commands are associated with the bpstat; if we remove it here, | |
11929 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
11930 | event-top.c won't do anything, and temporary breakpoints with | |
11931 | commands won't work. */ | |
11932 | ||
11933 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
11934 | ||
4a64f543 MS |
11935 | /* Now that breakpoint is removed from breakpoint list, update the |
11936 | global location list. This will remove locations that used to | |
11937 | belong to this breakpoint. Do this before freeing the breakpoint | |
11938 | itself, since remove_breakpoint looks at location's owner. It | |
11939 | might be better design to have location completely | |
11940 | self-contained, but it's not the case now. */ | |
b60e7edf | 11941 | update_global_location_list (0); |
74960c60 | 11942 | |
348d480f | 11943 | bpt->ops->dtor (bpt); |
4a64f543 MS |
11944 | /* On the chance that someone will soon try again to delete this |
11945 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 11946 | bpt->type = bp_none; |
b8c9b27d | 11947 | xfree (bpt); |
c906108c SS |
11948 | } |
11949 | ||
4d6140d9 AC |
11950 | static void |
11951 | do_delete_breakpoint_cleanup (void *b) | |
11952 | { | |
11953 | delete_breakpoint (b); | |
11954 | } | |
11955 | ||
11956 | struct cleanup * | |
11957 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
11958 | { | |
11959 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
11960 | } | |
11961 | ||
51be5b68 PA |
11962 | /* Iterator function to call a user-provided callback function once |
11963 | for each of B and its related breakpoints. */ | |
11964 | ||
11965 | static void | |
11966 | iterate_over_related_breakpoints (struct breakpoint *b, | |
11967 | void (*function) (struct breakpoint *, | |
11968 | void *), | |
11969 | void *data) | |
11970 | { | |
11971 | struct breakpoint *related; | |
11972 | ||
11973 | related = b; | |
11974 | do | |
11975 | { | |
11976 | struct breakpoint *next; | |
11977 | ||
11978 | /* FUNCTION may delete RELATED. */ | |
11979 | next = related->related_breakpoint; | |
11980 | ||
11981 | if (next == related) | |
11982 | { | |
11983 | /* RELATED is the last ring entry. */ | |
11984 | function (related, data); | |
11985 | ||
11986 | /* FUNCTION may have deleted it, so we'd never reach back to | |
11987 | B. There's nothing left to do anyway, so just break | |
11988 | out. */ | |
11989 | break; | |
11990 | } | |
11991 | else | |
11992 | function (related, data); | |
11993 | ||
11994 | related = next; | |
11995 | } | |
11996 | while (related != b); | |
11997 | } | |
95a42b64 TT |
11998 | |
11999 | static void | |
12000 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
12001 | { | |
12002 | delete_breakpoint (b); | |
12003 | } | |
12004 | ||
51be5b68 PA |
12005 | /* A callback for map_breakpoint_numbers that calls |
12006 | delete_breakpoint. */ | |
12007 | ||
12008 | static void | |
12009 | do_map_delete_breakpoint (struct breakpoint *b, void *ignore) | |
12010 | { | |
12011 | iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL); | |
12012 | } | |
12013 | ||
c906108c | 12014 | void |
fba45db2 | 12015 | delete_command (char *arg, int from_tty) |
c906108c | 12016 | { |
35df4500 | 12017 | struct breakpoint *b, *b_tmp; |
c906108c | 12018 | |
ea9365bb TT |
12019 | dont_repeat (); |
12020 | ||
c906108c SS |
12021 | if (arg == 0) |
12022 | { | |
12023 | int breaks_to_delete = 0; | |
12024 | ||
46c6471b PA |
12025 | /* Delete all breakpoints if no argument. Do not delete |
12026 | internal breakpoints, these have to be deleted with an | |
12027 | explicit breakpoint number argument. */ | |
c5aa993b | 12028 | ALL_BREAKPOINTS (b) |
46c6471b | 12029 | if (user_breakpoint_p (b)) |
973d738b DJ |
12030 | { |
12031 | breaks_to_delete = 1; | |
12032 | break; | |
12033 | } | |
c906108c SS |
12034 | |
12035 | /* Ask user only if there are some breakpoints to delete. */ | |
12036 | if (!from_tty | |
e2e0b3e5 | 12037 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 12038 | { |
35df4500 | 12039 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 12040 | if (user_breakpoint_p (b)) |
c5aa993b | 12041 | delete_breakpoint (b); |
c906108c SS |
12042 | } |
12043 | } | |
12044 | else | |
51be5b68 | 12045 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
c906108c SS |
12046 | } |
12047 | ||
0d381245 VP |
12048 | static int |
12049 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 12050 | { |
0d381245 | 12051 | for (; loc; loc = loc->next) |
8645ff69 UW |
12052 | if (!loc->shlib_disabled |
12053 | && !loc->pspace->executing_startup) | |
0d381245 VP |
12054 | return 0; |
12055 | return 1; | |
fe3f5fa8 VP |
12056 | } |
12057 | ||
776592bf DE |
12058 | /* Subroutine of update_breakpoint_locations to simplify it. |
12059 | Return non-zero if multiple fns in list LOC have the same name. | |
12060 | Null names are ignored. */ | |
12061 | ||
12062 | static int | |
12063 | ambiguous_names_p (struct bp_location *loc) | |
12064 | { | |
12065 | struct bp_location *l; | |
12066 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
12067 | (int (*) (const void *, |
12068 | const void *)) streq, | |
776592bf DE |
12069 | NULL, xcalloc, xfree); |
12070 | ||
12071 | for (l = loc; l != NULL; l = l->next) | |
12072 | { | |
12073 | const char **slot; | |
12074 | const char *name = l->function_name; | |
12075 | ||
12076 | /* Allow for some names to be NULL, ignore them. */ | |
12077 | if (name == NULL) | |
12078 | continue; | |
12079 | ||
12080 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
12081 | INSERT); | |
4a64f543 MS |
12082 | /* NOTE: We can assume slot != NULL here because xcalloc never |
12083 | returns NULL. */ | |
776592bf DE |
12084 | if (*slot != NULL) |
12085 | { | |
12086 | htab_delete (htab); | |
12087 | return 1; | |
12088 | } | |
12089 | *slot = name; | |
12090 | } | |
12091 | ||
12092 | htab_delete (htab); | |
12093 | return 0; | |
12094 | } | |
12095 | ||
0fb4aa4b PA |
12096 | /* When symbols change, it probably means the sources changed as well, |
12097 | and it might mean the static tracepoint markers are no longer at | |
12098 | the same address or line numbers they used to be at last we | |
12099 | checked. Losing your static tracepoints whenever you rebuild is | |
12100 | undesirable. This function tries to resync/rematch gdb static | |
12101 | tracepoints with the markers on the target, for static tracepoints | |
12102 | that have not been set by marker id. Static tracepoint that have | |
12103 | been set by marker id are reset by marker id in breakpoint_re_set. | |
12104 | The heuristic is: | |
12105 | ||
12106 | 1) For a tracepoint set at a specific address, look for a marker at | |
12107 | the old PC. If one is found there, assume to be the same marker. | |
12108 | If the name / string id of the marker found is different from the | |
12109 | previous known name, assume that means the user renamed the marker | |
12110 | in the sources, and output a warning. | |
12111 | ||
12112 | 2) For a tracepoint set at a given line number, look for a marker | |
12113 | at the new address of the old line number. If one is found there, | |
12114 | assume to be the same marker. If the name / string id of the | |
12115 | marker found is different from the previous known name, assume that | |
12116 | means the user renamed the marker in the sources, and output a | |
12117 | warning. | |
12118 | ||
12119 | 3) If a marker is no longer found at the same address or line, it | |
12120 | may mean the marker no longer exists. But it may also just mean | |
12121 | the code changed a bit. Maybe the user added a few lines of code | |
12122 | that made the marker move up or down (in line number terms). Ask | |
12123 | the target for info about the marker with the string id as we knew | |
12124 | it. If found, update line number and address in the matching | |
12125 | static tracepoint. This will get confused if there's more than one | |
12126 | marker with the same ID (possible in UST, although unadvised | |
12127 | precisely because it confuses tools). */ | |
12128 | ||
12129 | static struct symtab_and_line | |
12130 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
12131 | { | |
d9b3f62e | 12132 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
12133 | struct static_tracepoint_marker marker; |
12134 | CORE_ADDR pc; | |
12135 | int i; | |
12136 | ||
12137 | pc = sal.pc; | |
12138 | if (sal.line) | |
12139 | find_line_pc (sal.symtab, sal.line, &pc); | |
12140 | ||
12141 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
12142 | { | |
d9b3f62e | 12143 | if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0) |
0fb4aa4b PA |
12144 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
12145 | b->number, | |
d9b3f62e | 12146 | tp->static_trace_marker_id, marker.str_id); |
0fb4aa4b | 12147 | |
d9b3f62e PA |
12148 | xfree (tp->static_trace_marker_id); |
12149 | tp->static_trace_marker_id = xstrdup (marker.str_id); | |
0fb4aa4b PA |
12150 | release_static_tracepoint_marker (&marker); |
12151 | ||
12152 | return sal; | |
12153 | } | |
12154 | ||
12155 | /* Old marker wasn't found on target at lineno. Try looking it up | |
12156 | by string ID. */ | |
12157 | if (!sal.explicit_pc | |
12158 | && sal.line != 0 | |
12159 | && sal.symtab != NULL | |
d9b3f62e | 12160 | && tp->static_trace_marker_id != NULL) |
0fb4aa4b PA |
12161 | { |
12162 | VEC(static_tracepoint_marker_p) *markers; | |
12163 | ||
12164 | markers | |
d9b3f62e | 12165 | = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id); |
0fb4aa4b PA |
12166 | |
12167 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
12168 | { | |
80e1d417 | 12169 | struct symtab_and_line sal2; |
0fb4aa4b | 12170 | struct symbol *sym; |
80e1d417 | 12171 | struct static_tracepoint_marker *tpmarker; |
79a45e25 | 12172 | struct ui_out *uiout = current_uiout; |
0fb4aa4b | 12173 | |
80e1d417 | 12174 | tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0); |
0fb4aa4b | 12175 | |
d9b3f62e | 12176 | xfree (tp->static_trace_marker_id); |
80e1d417 | 12177 | tp->static_trace_marker_id = xstrdup (tpmarker->str_id); |
0fb4aa4b PA |
12178 | |
12179 | warning (_("marker for static tracepoint %d (%s) not " | |
12180 | "found at previous line number"), | |
d9b3f62e | 12181 | b->number, tp->static_trace_marker_id); |
0fb4aa4b | 12182 | |
80e1d417 | 12183 | init_sal (&sal2); |
0fb4aa4b | 12184 | |
80e1d417 | 12185 | sal2.pc = tpmarker->address; |
0fb4aa4b | 12186 | |
80e1d417 AS |
12187 | sal2 = find_pc_line (tpmarker->address, 0); |
12188 | sym = find_pc_sect_function (tpmarker->address, NULL); | |
0fb4aa4b PA |
12189 | ui_out_text (uiout, "Now in "); |
12190 | if (sym) | |
12191 | { | |
12192 | ui_out_field_string (uiout, "func", | |
12193 | SYMBOL_PRINT_NAME (sym)); | |
12194 | ui_out_text (uiout, " at "); | |
12195 | } | |
80e1d417 | 12196 | ui_out_field_string (uiout, "file", sal2.symtab->filename); |
0fb4aa4b PA |
12197 | ui_out_text (uiout, ":"); |
12198 | ||
12199 | if (ui_out_is_mi_like_p (uiout)) | |
12200 | { | |
80e1d417 | 12201 | char *fullname = symtab_to_fullname (sal2.symtab); |
0fb4aa4b PA |
12202 | |
12203 | if (fullname) | |
12204 | ui_out_field_string (uiout, "fullname", fullname); | |
12205 | } | |
12206 | ||
80e1d417 | 12207 | ui_out_field_int (uiout, "line", sal2.line); |
0fb4aa4b PA |
12208 | ui_out_text (uiout, "\n"); |
12209 | ||
80e1d417 | 12210 | b->loc->line_number = sal2.line; |
0fb4aa4b | 12211 | |
f8eba3c6 | 12212 | xfree (b->loc->source_file); |
0fb4aa4b | 12213 | if (sym) |
80e1d417 | 12214 | b->loc->source_file = xstrdup (sal2.symtab->filename); |
0fb4aa4b | 12215 | else |
f8eba3c6 | 12216 | b->loc->source_file = NULL; |
0fb4aa4b PA |
12217 | |
12218 | xfree (b->addr_string); | |
12219 | b->addr_string = xstrprintf ("%s:%d", | |
80e1d417 | 12220 | sal2.symtab->filename, |
f8eba3c6 | 12221 | b->loc->line_number); |
0fb4aa4b PA |
12222 | |
12223 | /* Might be nice to check if function changed, and warn if | |
12224 | so. */ | |
12225 | ||
80e1d417 | 12226 | release_static_tracepoint_marker (tpmarker); |
0fb4aa4b PA |
12227 | } |
12228 | } | |
12229 | return sal; | |
12230 | } | |
12231 | ||
8d3788bd VP |
12232 | /* Returns 1 iff locations A and B are sufficiently same that |
12233 | we don't need to report breakpoint as changed. */ | |
12234 | ||
12235 | static int | |
12236 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
12237 | { | |
12238 | while (a && b) | |
12239 | { | |
12240 | if (a->address != b->address) | |
12241 | return 0; | |
12242 | ||
12243 | if (a->shlib_disabled != b->shlib_disabled) | |
12244 | return 0; | |
12245 | ||
12246 | if (a->enabled != b->enabled) | |
12247 | return 0; | |
12248 | ||
12249 | a = a->next; | |
12250 | b = b->next; | |
12251 | } | |
12252 | ||
12253 | if ((a == NULL) != (b == NULL)) | |
12254 | return 0; | |
12255 | ||
12256 | return 1; | |
12257 | } | |
12258 | ||
f1310107 TJB |
12259 | /* Create new breakpoint locations for B (a hardware or software breakpoint) |
12260 | based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is | |
12261 | a ranged breakpoint. */ | |
12262 | ||
0e30163f | 12263 | void |
0d381245 | 12264 | update_breakpoint_locations (struct breakpoint *b, |
f1310107 TJB |
12265 | struct symtabs_and_lines sals, |
12266 | struct symtabs_and_lines sals_end) | |
fe3f5fa8 VP |
12267 | { |
12268 | int i; | |
0d381245 VP |
12269 | struct bp_location *existing_locations = b->loc; |
12270 | ||
f8eba3c6 TT |
12271 | if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1)) |
12272 | { | |
12273 | /* Ranged breakpoints have only one start location and one end | |
12274 | location. */ | |
12275 | b->enable_state = bp_disabled; | |
12276 | update_global_location_list (1); | |
12277 | printf_unfiltered (_("Could not reset ranged breakpoint %d: " | |
12278 | "multiple locations found\n"), | |
12279 | b->number); | |
12280 | return; | |
12281 | } | |
f1310107 | 12282 | |
4a64f543 MS |
12283 | /* If there's no new locations, and all existing locations are |
12284 | pending, don't do anything. This optimizes the common case where | |
12285 | all locations are in the same shared library, that was unloaded. | |
12286 | We'd like to retain the location, so that when the library is | |
12287 | loaded again, we don't loose the enabled/disabled status of the | |
12288 | individual locations. */ | |
0d381245 | 12289 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) |
fe3f5fa8 VP |
12290 | return; |
12291 | ||
fe3f5fa8 VP |
12292 | b->loc = NULL; |
12293 | ||
0d381245 | 12294 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 12295 | { |
f8eba3c6 TT |
12296 | struct bp_location *new_loc; |
12297 | ||
12298 | switch_to_program_space_and_thread (sals.sals[i].pspace); | |
12299 | ||
12300 | new_loc = add_location_to_breakpoint (b, &(sals.sals[i])); | |
fe3f5fa8 | 12301 | |
0d381245 VP |
12302 | /* Reparse conditions, they might contain references to the |
12303 | old symtab. */ | |
12304 | if (b->cond_string != NULL) | |
12305 | { | |
f1310107 | 12306 | char *s; |
bfd189b1 | 12307 | volatile struct gdb_exception e; |
fe3f5fa8 | 12308 | |
0d381245 VP |
12309 | s = b->cond_string; |
12310 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
12311 | { | |
12312 | new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), | |
12313 | 0); | |
12314 | } | |
12315 | if (e.reason < 0) | |
12316 | { | |
3e43a32a MS |
12317 | warning (_("failed to reevaluate condition " |
12318 | "for breakpoint %d: %s"), | |
0d381245 VP |
12319 | b->number, e.message); |
12320 | new_loc->enabled = 0; | |
12321 | } | |
12322 | } | |
fe3f5fa8 | 12323 | |
f1310107 TJB |
12324 | if (sals_end.nelts) |
12325 | { | |
12326 | CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]); | |
12327 | ||
12328 | new_loc->length = end - sals.sals[0].pc + 1; | |
12329 | } | |
0d381245 | 12330 | } |
fe3f5fa8 | 12331 | |
514f746b AR |
12332 | /* Update locations of permanent breakpoints. */ |
12333 | if (b->enable_state == bp_permanent) | |
12334 | make_breakpoint_permanent (b); | |
12335 | ||
4a64f543 MS |
12336 | /* If possible, carry over 'disable' status from existing |
12337 | breakpoints. */ | |
0d381245 VP |
12338 | { |
12339 | struct bp_location *e = existing_locations; | |
776592bf DE |
12340 | /* If there are multiple breakpoints with the same function name, |
12341 | e.g. for inline functions, comparing function names won't work. | |
12342 | Instead compare pc addresses; this is just a heuristic as things | |
12343 | may have moved, but in practice it gives the correct answer | |
12344 | often enough until a better solution is found. */ | |
12345 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
12346 | ||
0d381245 VP |
12347 | for (; e; e = e->next) |
12348 | { | |
12349 | if (!e->enabled && e->function_name) | |
12350 | { | |
12351 | struct bp_location *l = b->loc; | |
776592bf DE |
12352 | if (have_ambiguous_names) |
12353 | { | |
12354 | for (; l; l = l->next) | |
f1310107 | 12355 | if (breakpoint_locations_match (e, l)) |
776592bf DE |
12356 | { |
12357 | l->enabled = 0; | |
12358 | break; | |
12359 | } | |
12360 | } | |
12361 | else | |
12362 | { | |
12363 | for (; l; l = l->next) | |
12364 | if (l->function_name | |
12365 | && strcmp (e->function_name, l->function_name) == 0) | |
12366 | { | |
12367 | l->enabled = 0; | |
12368 | break; | |
12369 | } | |
12370 | } | |
0d381245 VP |
12371 | } |
12372 | } | |
12373 | } | |
fe3f5fa8 | 12374 | |
8d3788bd VP |
12375 | if (!locations_are_equal (existing_locations, b->loc)) |
12376 | observer_notify_breakpoint_modified (b); | |
12377 | ||
b60e7edf | 12378 | update_global_location_list (1); |
fe3f5fa8 VP |
12379 | } |
12380 | ||
ef23e705 TJB |
12381 | /* Find the SaL locations corresponding to the given ADDR_STRING. |
12382 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ | |
12383 | ||
12384 | static struct symtabs_and_lines | |
12385 | addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found) | |
12386 | { | |
12387 | char *s; | |
02d20e4a | 12388 | struct symtabs_and_lines sals = {0}; |
f8eba3c6 | 12389 | volatile struct gdb_exception e; |
ef23e705 | 12390 | |
983af33b | 12391 | gdb_assert (b->ops != NULL); |
ef23e705 | 12392 | s = addr_string; |
ef23e705 TJB |
12393 | |
12394 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
12395 | { | |
983af33b | 12396 | b->ops->decode_linespec (b, &s, &sals); |
ef23e705 TJB |
12397 | } |
12398 | if (e.reason < 0) | |
12399 | { | |
12400 | int not_found_and_ok = 0; | |
12401 | /* For pending breakpoints, it's expected that parsing will | |
12402 | fail until the right shared library is loaded. User has | |
12403 | already told to create pending breakpoints and don't need | |
12404 | extra messages. If breakpoint is in bp_shlib_disabled | |
12405 | state, then user already saw the message about that | |
12406 | breakpoint being disabled, and don't want to see more | |
12407 | errors. */ | |
58438ac1 | 12408 | if (e.error == NOT_FOUND_ERROR |
ef23e705 TJB |
12409 | && (b->condition_not_parsed |
12410 | || (b->loc && b->loc->shlib_disabled) | |
f8eba3c6 | 12411 | || (b->loc && b->loc->pspace->executing_startup) |
ef23e705 TJB |
12412 | || b->enable_state == bp_disabled)) |
12413 | not_found_and_ok = 1; | |
12414 | ||
12415 | if (!not_found_and_ok) | |
12416 | { | |
12417 | /* We surely don't want to warn about the same breakpoint | |
12418 | 10 times. One solution, implemented here, is disable | |
12419 | the breakpoint on error. Another solution would be to | |
12420 | have separate 'warning emitted' flag. Since this | |
12421 | happens only when a binary has changed, I don't know | |
12422 | which approach is better. */ | |
12423 | b->enable_state = bp_disabled; | |
12424 | throw_exception (e); | |
12425 | } | |
12426 | } | |
12427 | ||
58438ac1 | 12428 | if (e.reason == 0 || e.error != NOT_FOUND_ERROR) |
ef23e705 | 12429 | { |
f8eba3c6 | 12430 | int i; |
ef23e705 | 12431 | |
f8eba3c6 TT |
12432 | for (i = 0; i < sals.nelts; ++i) |
12433 | resolve_sal_pc (&sals.sals[i]); | |
ef23e705 TJB |
12434 | if (b->condition_not_parsed && s && s[0]) |
12435 | { | |
12436 | char *cond_string = 0; | |
12437 | int thread = -1; | |
12438 | int task = 0; | |
12439 | ||
12440 | find_condition_and_thread (s, sals.sals[0].pc, | |
12441 | &cond_string, &thread, &task); | |
12442 | if (cond_string) | |
12443 | b->cond_string = cond_string; | |
12444 | b->thread = thread; | |
12445 | b->task = task; | |
12446 | b->condition_not_parsed = 0; | |
12447 | } | |
12448 | ||
983af33b | 12449 | if (b->type == bp_static_tracepoint && !strace_marker_p (b)) |
ef23e705 | 12450 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); |
ef23e705 | 12451 | |
58438ac1 TT |
12452 | *found = 1; |
12453 | } | |
12454 | else | |
12455 | *found = 0; | |
ef23e705 TJB |
12456 | |
12457 | return sals; | |
12458 | } | |
12459 | ||
348d480f PA |
12460 | /* The default re_set method, for typical hardware or software |
12461 | breakpoints. Reevaluate the breakpoint and recreate its | |
12462 | locations. */ | |
12463 | ||
12464 | static void | |
28010a5d | 12465 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 TJB |
12466 | { |
12467 | int found; | |
f1310107 | 12468 | struct symtabs_and_lines sals, sals_end; |
ef23e705 | 12469 | struct symtabs_and_lines expanded = {0}; |
f1310107 | 12470 | struct symtabs_and_lines expanded_end = {0}; |
ef23e705 TJB |
12471 | |
12472 | sals = addr_string_to_sals (b, b->addr_string, &found); | |
12473 | if (found) | |
12474 | { | |
12475 | make_cleanup (xfree, sals.sals); | |
f8eba3c6 | 12476 | expanded = sals; |
ef23e705 TJB |
12477 | } |
12478 | ||
f1310107 TJB |
12479 | if (b->addr_string_range_end) |
12480 | { | |
12481 | sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found); | |
12482 | if (found) | |
12483 | { | |
12484 | make_cleanup (xfree, sals_end.sals); | |
f8eba3c6 | 12485 | expanded_end = sals_end; |
f1310107 TJB |
12486 | } |
12487 | } | |
12488 | ||
12489 | update_breakpoint_locations (b, expanded, expanded_end); | |
28010a5d PA |
12490 | } |
12491 | ||
983af33b SDJ |
12492 | /* Default method for creating SALs from an address string. It basically |
12493 | calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ | |
12494 | ||
12495 | static void | |
12496 | create_sals_from_address_default (char **arg, | |
12497 | struct linespec_result *canonical, | |
12498 | enum bptype type_wanted, | |
12499 | char *addr_start, char **copy_arg) | |
12500 | { | |
12501 | parse_breakpoint_sals (arg, canonical); | |
12502 | } | |
12503 | ||
12504 | /* Call create_breakpoints_sal for the given arguments. This is the default | |
12505 | function for the `create_breakpoints_sal' method of | |
12506 | breakpoint_ops. */ | |
12507 | ||
12508 | static void | |
12509 | create_breakpoints_sal_default (struct gdbarch *gdbarch, | |
12510 | struct linespec_result *canonical, | |
12511 | struct linespec_sals *lsal, | |
12512 | char *cond_string, | |
12513 | enum bptype type_wanted, | |
12514 | enum bpdisp disposition, | |
12515 | int thread, | |
12516 | int task, int ignore_count, | |
12517 | const struct breakpoint_ops *ops, | |
12518 | int from_tty, int enabled, | |
12519 | int internal) | |
12520 | { | |
12521 | create_breakpoints_sal (gdbarch, canonical, cond_string, | |
12522 | type_wanted, disposition, | |
12523 | thread, task, ignore_count, ops, from_tty, | |
12524 | enabled, internal); | |
12525 | } | |
12526 | ||
12527 | /* Decode the line represented by S by calling decode_line_full. This is the | |
12528 | default function for the `decode_linespec' method of breakpoint_ops. */ | |
12529 | ||
12530 | static void | |
12531 | decode_linespec_default (struct breakpoint *b, char **s, | |
12532 | struct symtabs_and_lines *sals) | |
12533 | { | |
12534 | struct linespec_result canonical; | |
12535 | ||
12536 | init_linespec_result (&canonical); | |
12537 | decode_line_full (s, DECODE_LINE_FUNFIRSTLINE, | |
12538 | (struct symtab *) NULL, 0, | |
12539 | &canonical, multiple_symbols_all, | |
12540 | b->filter); | |
12541 | ||
12542 | /* We should get 0 or 1 resulting SALs. */ | |
12543 | gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2); | |
12544 | ||
12545 | if (VEC_length (linespec_sals, canonical.sals) > 0) | |
12546 | { | |
12547 | struct linespec_sals *lsal; | |
12548 | ||
12549 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
12550 | *sals = lsal->sals; | |
12551 | /* Arrange it so the destructor does not free the | |
12552 | contents. */ | |
12553 | lsal->sals.sals = NULL; | |
12554 | } | |
12555 | ||
12556 | destroy_linespec_result (&canonical); | |
12557 | } | |
12558 | ||
28010a5d PA |
12559 | /* Prepare the global context for a re-set of breakpoint B. */ |
12560 | ||
12561 | static struct cleanup * | |
12562 | prepare_re_set_context (struct breakpoint *b) | |
12563 | { | |
12564 | struct cleanup *cleanups; | |
12565 | ||
12566 | input_radix = b->input_radix; | |
12567 | cleanups = save_current_space_and_thread (); | |
f8eba3c6 TT |
12568 | if (b->pspace != NULL) |
12569 | switch_to_program_space_and_thread (b->pspace); | |
28010a5d PA |
12570 | set_language (b->language); |
12571 | ||
12572 | return cleanups; | |
ef23e705 TJB |
12573 | } |
12574 | ||
c906108c SS |
12575 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
12576 | The value we return ends up being the return value from catch_errors. | |
12577 | Unused in this case. */ | |
12578 | ||
12579 | static int | |
4efb68b1 | 12580 | breakpoint_re_set_one (void *bint) |
c906108c | 12581 | { |
4a64f543 | 12582 | /* Get past catch_errs. */ |
53a5351d | 12583 | struct breakpoint *b = (struct breakpoint *) bint; |
348d480f | 12584 | struct cleanup *cleanups; |
c906108c | 12585 | |
348d480f PA |
12586 | cleanups = prepare_re_set_context (b); |
12587 | b->ops->re_set (b); | |
12588 | do_cleanups (cleanups); | |
c906108c SS |
12589 | return 0; |
12590 | } | |
12591 | ||
69de3c6a | 12592 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 12593 | void |
69de3c6a | 12594 | breakpoint_re_set (void) |
c906108c | 12595 | { |
35df4500 | 12596 | struct breakpoint *b, *b_tmp; |
c906108c SS |
12597 | enum language save_language; |
12598 | int save_input_radix; | |
6c95b8df | 12599 | struct cleanup *old_chain; |
c5aa993b | 12600 | |
c906108c SS |
12601 | save_language = current_language->la_language; |
12602 | save_input_radix = input_radix; | |
6c95b8df PA |
12603 | old_chain = save_current_program_space (); |
12604 | ||
35df4500 | 12605 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 12606 | { |
4a64f543 | 12607 | /* Format possible error msg. */ |
fe3f5fa8 | 12608 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
12609 | b->number); |
12610 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 12611 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 12612 | do_cleanups (cleanups); |
c5aa993b | 12613 | } |
c906108c SS |
12614 | set_language (save_language); |
12615 | input_radix = save_input_radix; | |
e62c965a | 12616 | |
0756c555 | 12617 | jit_breakpoint_re_set (); |
4efc6507 | 12618 | |
6c95b8df PA |
12619 | do_cleanups (old_chain); |
12620 | ||
af02033e PP |
12621 | create_overlay_event_breakpoint (); |
12622 | create_longjmp_master_breakpoint (); | |
12623 | create_std_terminate_master_breakpoint (); | |
186c406b | 12624 | create_exception_master_breakpoint (); |
1bfeeb0f JL |
12625 | |
12626 | /* While we're at it, reset the skip list too. */ | |
12627 | skip_re_set (); | |
c906108c SS |
12628 | } |
12629 | \f | |
c906108c SS |
12630 | /* Reset the thread number of this breakpoint: |
12631 | ||
12632 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 12633 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 12634 | void |
fba45db2 | 12635 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
12636 | { |
12637 | if (b->thread != -1) | |
12638 | { | |
39f77062 KB |
12639 | if (in_thread_list (inferior_ptid)) |
12640 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
12641 | |
12642 | /* We're being called after following a fork. The new fork is | |
12643 | selected as current, and unless this was a vfork will have a | |
12644 | different program space from the original thread. Reset that | |
12645 | as well. */ | |
12646 | b->loc->pspace = current_program_space; | |
c906108c SS |
12647 | } |
12648 | } | |
12649 | ||
03ac34d5 MS |
12650 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
12651 | If from_tty is nonzero, it prints a message to that effect, | |
12652 | which ends with a period (no newline). */ | |
12653 | ||
c906108c | 12654 | void |
fba45db2 | 12655 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 12656 | { |
52f0bd74 | 12657 | struct breakpoint *b; |
c906108c SS |
12658 | |
12659 | if (count < 0) | |
12660 | count = 0; | |
12661 | ||
12662 | ALL_BREAKPOINTS (b) | |
12663 | if (b->number == bptnum) | |
c5aa993b | 12664 | { |
d77f58be SS |
12665 | if (is_tracepoint (b)) |
12666 | { | |
12667 | if (from_tty && count != 0) | |
12668 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
12669 | bptnum); | |
12670 | return; | |
12671 | } | |
12672 | ||
c5aa993b | 12673 | b->ignore_count = count; |
221ea385 KS |
12674 | if (from_tty) |
12675 | { | |
12676 | if (count == 0) | |
3e43a32a MS |
12677 | printf_filtered (_("Will stop next time " |
12678 | "breakpoint %d is reached."), | |
221ea385 KS |
12679 | bptnum); |
12680 | else if (count == 1) | |
a3f17187 | 12681 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
12682 | bptnum); |
12683 | else | |
3e43a32a MS |
12684 | printf_filtered (_("Will ignore next %d " |
12685 | "crossings of breakpoint %d."), | |
221ea385 KS |
12686 | count, bptnum); |
12687 | } | |
c5aa993b | 12688 | breakpoints_changed (); |
8d3788bd | 12689 | observer_notify_breakpoint_modified (b); |
c5aa993b JM |
12690 | return; |
12691 | } | |
c906108c | 12692 | |
8a3fe4f8 | 12693 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
12694 | } |
12695 | ||
c906108c SS |
12696 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
12697 | ||
12698 | static void | |
fba45db2 | 12699 | ignore_command (char *args, int from_tty) |
c906108c SS |
12700 | { |
12701 | char *p = args; | |
52f0bd74 | 12702 | int num; |
c906108c SS |
12703 | |
12704 | if (p == 0) | |
e2e0b3e5 | 12705 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 12706 | |
c906108c | 12707 | num = get_number (&p); |
5c44784c | 12708 | if (num == 0) |
8a3fe4f8 | 12709 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 12710 | if (*p == 0) |
8a3fe4f8 | 12711 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
12712 | |
12713 | set_ignore_count (num, | |
12714 | longest_to_int (value_as_long (parse_and_eval (p))), | |
12715 | from_tty); | |
221ea385 KS |
12716 | if (from_tty) |
12717 | printf_filtered ("\n"); | |
c906108c SS |
12718 | } |
12719 | \f | |
12720 | /* Call FUNCTION on each of the breakpoints | |
12721 | whose numbers are given in ARGS. */ | |
12722 | ||
12723 | static void | |
95a42b64 TT |
12724 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
12725 | void *), | |
12726 | void *data) | |
c906108c | 12727 | { |
52f0bd74 AC |
12728 | int num; |
12729 | struct breakpoint *b, *tmp; | |
11cf8741 | 12730 | int match; |
197f0a60 | 12731 | struct get_number_or_range_state state; |
c906108c | 12732 | |
197f0a60 | 12733 | if (args == 0) |
e2e0b3e5 | 12734 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c | 12735 | |
197f0a60 TT |
12736 | init_number_or_range (&state, args); |
12737 | ||
12738 | while (!state.finished) | |
c906108c | 12739 | { |
197f0a60 TT |
12740 | char *p = state.string; |
12741 | ||
11cf8741 | 12742 | match = 0; |
c5aa993b | 12743 | |
197f0a60 | 12744 | num = get_number_or_range (&state); |
5c44784c | 12745 | if (num == 0) |
c5aa993b | 12746 | { |
8a3fe4f8 | 12747 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
12748 | } |
12749 | else | |
12750 | { | |
12751 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
12752 | if (b->number == num) | |
12753 | { | |
11cf8741 | 12754 | match = 1; |
cdac0397 | 12755 | function (b, data); |
11cf8741 | 12756 | break; |
5c44784c | 12757 | } |
11cf8741 | 12758 | if (match == 0) |
a3f17187 | 12759 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 12760 | } |
c906108c SS |
12761 | } |
12762 | } | |
12763 | ||
0d381245 VP |
12764 | static struct bp_location * |
12765 | find_location_by_number (char *number) | |
12766 | { | |
12767 | char *dot = strchr (number, '.'); | |
12768 | char *p1; | |
12769 | int bp_num; | |
12770 | int loc_num; | |
12771 | struct breakpoint *b; | |
12772 | struct bp_location *loc; | |
12773 | ||
12774 | *dot = '\0'; | |
12775 | ||
12776 | p1 = number; | |
197f0a60 | 12777 | bp_num = get_number (&p1); |
0d381245 VP |
12778 | if (bp_num == 0) |
12779 | error (_("Bad breakpoint number '%s'"), number); | |
12780 | ||
12781 | ALL_BREAKPOINTS (b) | |
12782 | if (b->number == bp_num) | |
12783 | { | |
12784 | break; | |
12785 | } | |
12786 | ||
12787 | if (!b || b->number != bp_num) | |
12788 | error (_("Bad breakpoint number '%s'"), number); | |
12789 | ||
12790 | p1 = dot+1; | |
197f0a60 | 12791 | loc_num = get_number (&p1); |
0d381245 VP |
12792 | if (loc_num == 0) |
12793 | error (_("Bad breakpoint location number '%s'"), number); | |
12794 | ||
12795 | --loc_num; | |
12796 | loc = b->loc; | |
12797 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
12798 | ; | |
12799 | if (!loc) | |
12800 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
12801 | ||
12802 | return loc; | |
12803 | } | |
12804 | ||
12805 | ||
1900040c MS |
12806 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
12807 | If from_tty is nonzero, it prints a message to that effect, | |
12808 | which ends with a period (no newline). */ | |
12809 | ||
c906108c | 12810 | void |
fba45db2 | 12811 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
12812 | { |
12813 | /* Never disable a watchpoint scope breakpoint; we want to | |
12814 | hit them when we leave scope so we can delete both the | |
12815 | watchpoint and its scope breakpoint at that time. */ | |
12816 | if (bpt->type == bp_watchpoint_scope) | |
12817 | return; | |
12818 | ||
c2c6d25f | 12819 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 12820 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
12821 | return; |
12822 | ||
b5de0fa7 | 12823 | bpt->enable_state = bp_disabled; |
c906108c | 12824 | |
d248b706 KY |
12825 | if (target_supports_enable_disable_tracepoint () |
12826 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
12827 | { | |
12828 | struct bp_location *location; | |
12829 | ||
12830 | for (location = bpt->loc; location; location = location->next) | |
12831 | target_disable_tracepoint (location); | |
12832 | } | |
12833 | ||
b60e7edf | 12834 | update_global_location_list (0); |
c906108c | 12835 | |
8d3788bd | 12836 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
12837 | } |
12838 | ||
51be5b68 PA |
12839 | /* A callback for iterate_over_related_breakpoints. */ |
12840 | ||
12841 | static void | |
12842 | do_disable_breakpoint (struct breakpoint *b, void *ignore) | |
12843 | { | |
12844 | disable_breakpoint (b); | |
12845 | } | |
12846 | ||
95a42b64 TT |
12847 | /* A callback for map_breakpoint_numbers that calls |
12848 | disable_breakpoint. */ | |
12849 | ||
12850 | static void | |
12851 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
12852 | { | |
51be5b68 | 12853 | iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL); |
95a42b64 TT |
12854 | } |
12855 | ||
c906108c | 12856 | static void |
fba45db2 | 12857 | disable_command (char *args, int from_tty) |
c906108c | 12858 | { |
c906108c | 12859 | if (args == 0) |
46c6471b PA |
12860 | { |
12861 | struct breakpoint *bpt; | |
12862 | ||
12863 | ALL_BREAKPOINTS (bpt) | |
12864 | if (user_breakpoint_p (bpt)) | |
12865 | disable_breakpoint (bpt); | |
12866 | } | |
0d381245 VP |
12867 | else if (strchr (args, '.')) |
12868 | { | |
12869 | struct bp_location *loc = find_location_by_number (args); | |
12870 | if (loc) | |
d248b706 KY |
12871 | { |
12872 | loc->enabled = 0; | |
12873 | if (target_supports_enable_disable_tracepoint () | |
12874 | && current_trace_status ()->running && loc->owner | |
12875 | && is_tracepoint (loc->owner)) | |
12876 | target_disable_tracepoint (loc); | |
12877 | } | |
b60e7edf | 12878 | update_global_location_list (0); |
0d381245 | 12879 | } |
c906108c | 12880 | else |
95a42b64 | 12881 | map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL); |
c906108c SS |
12882 | } |
12883 | ||
12884 | static void | |
51be5b68 | 12885 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition) |
c906108c | 12886 | { |
afe38095 | 12887 | int target_resources_ok; |
c906108c SS |
12888 | |
12889 | if (bpt->type == bp_hardware_breakpoint) | |
12890 | { | |
12891 | int i; | |
c5aa993b | 12892 | i = hw_breakpoint_used_count (); |
53a5351d | 12893 | target_resources_ok = |
d92524f1 | 12894 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 12895 | i + 1, 0); |
c906108c | 12896 | if (target_resources_ok == 0) |
8a3fe4f8 | 12897 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 12898 | else if (target_resources_ok < 0) |
8a3fe4f8 | 12899 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
12900 | } |
12901 | ||
cc60f2e3 | 12902 | if (is_watchpoint (bpt)) |
c906108c | 12903 | { |
d07205c2 JK |
12904 | /* Initialize it just to avoid a GCC false warning. */ |
12905 | enum enable_state orig_enable_state = 0; | |
bfd189b1 | 12906 | volatile struct gdb_exception e; |
dde02812 ES |
12907 | |
12908 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 12909 | { |
3a5c3e22 PA |
12910 | struct watchpoint *w = (struct watchpoint *) bpt; |
12911 | ||
1e718ff1 TJB |
12912 | orig_enable_state = bpt->enable_state; |
12913 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 12914 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 12915 | } |
dde02812 | 12916 | if (e.reason < 0) |
c5aa993b | 12917 | { |
1e718ff1 | 12918 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
12919 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
12920 | bpt->number); | |
12921 | return; | |
c5aa993b | 12922 | } |
c906108c | 12923 | } |
0101ce28 | 12924 | |
b4c291bb KH |
12925 | if (bpt->enable_state != bp_permanent) |
12926 | bpt->enable_state = bp_enabled; | |
d248b706 KY |
12927 | |
12928 | if (target_supports_enable_disable_tracepoint () | |
12929 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
12930 | { | |
12931 | struct bp_location *location; | |
12932 | ||
12933 | for (location = bpt->loc; location; location = location->next) | |
12934 | target_enable_tracepoint (location); | |
12935 | } | |
12936 | ||
b4c291bb | 12937 | bpt->disposition = disposition; |
b60e7edf | 12938 | update_global_location_list (1); |
b4c291bb KH |
12939 | breakpoints_changed (); |
12940 | ||
8d3788bd | 12941 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
12942 | } |
12943 | ||
fe3f5fa8 | 12944 | |
c906108c | 12945 | void |
fba45db2 | 12946 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 12947 | { |
51be5b68 PA |
12948 | enable_breakpoint_disp (bpt, bpt->disposition); |
12949 | } | |
12950 | ||
12951 | static void | |
12952 | do_enable_breakpoint (struct breakpoint *bpt, void *arg) | |
12953 | { | |
12954 | enable_breakpoint (bpt); | |
c906108c SS |
12955 | } |
12956 | ||
95a42b64 TT |
12957 | /* A callback for map_breakpoint_numbers that calls |
12958 | enable_breakpoint. */ | |
12959 | ||
12960 | static void | |
12961 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
12962 | { | |
51be5b68 | 12963 | iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL); |
95a42b64 TT |
12964 | } |
12965 | ||
c906108c SS |
12966 | /* The enable command enables the specified breakpoints (or all defined |
12967 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 12968 | in stopping the inferior. */ |
c906108c | 12969 | |
c906108c | 12970 | static void |
fba45db2 | 12971 | enable_command (char *args, int from_tty) |
c906108c | 12972 | { |
c906108c | 12973 | if (args == 0) |
46c6471b PA |
12974 | { |
12975 | struct breakpoint *bpt; | |
12976 | ||
12977 | ALL_BREAKPOINTS (bpt) | |
12978 | if (user_breakpoint_p (bpt)) | |
12979 | enable_breakpoint (bpt); | |
12980 | } | |
0d381245 VP |
12981 | else if (strchr (args, '.')) |
12982 | { | |
12983 | struct bp_location *loc = find_location_by_number (args); | |
12984 | if (loc) | |
d248b706 KY |
12985 | { |
12986 | loc->enabled = 1; | |
12987 | if (target_supports_enable_disable_tracepoint () | |
12988 | && current_trace_status ()->running && loc->owner | |
12989 | && is_tracepoint (loc->owner)) | |
12990 | target_enable_tracepoint (loc); | |
12991 | } | |
b60e7edf | 12992 | update_global_location_list (1); |
0d381245 | 12993 | } |
c906108c | 12994 | else |
95a42b64 | 12995 | map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL); |
c906108c SS |
12996 | } |
12997 | ||
12998 | static void | |
51be5b68 PA |
12999 | do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg) |
13000 | { | |
13001 | enum bpdisp disp = *(enum bpdisp *) arg; | |
13002 | ||
13003 | enable_breakpoint_disp (bpt, disp); | |
13004 | } | |
13005 | ||
13006 | static void | |
13007 | do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore) | |
c906108c | 13008 | { |
51be5b68 PA |
13009 | enum bpdisp disp = disp_disable; |
13010 | ||
13011 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
13012 | } |
13013 | ||
c906108c | 13014 | static void |
fba45db2 | 13015 | enable_once_command (char *args, int from_tty) |
c906108c | 13016 | { |
51be5b68 | 13017 | map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL); |
c906108c SS |
13018 | } |
13019 | ||
13020 | static void | |
51be5b68 | 13021 | do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 13022 | { |
51be5b68 PA |
13023 | enum bpdisp disp = disp_del; |
13024 | ||
13025 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
13026 | } |
13027 | ||
c906108c | 13028 | static void |
fba45db2 | 13029 | enable_delete_command (char *args, int from_tty) |
c906108c | 13030 | { |
51be5b68 | 13031 | map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL); |
c906108c SS |
13032 | } |
13033 | \f | |
fa8d40ab JJ |
13034 | static void |
13035 | set_breakpoint_cmd (char *args, int from_tty) | |
13036 | { | |
13037 | } | |
13038 | ||
13039 | static void | |
13040 | show_breakpoint_cmd (char *args, int from_tty) | |
13041 | { | |
13042 | } | |
13043 | ||
1f3b5d1b PP |
13044 | /* Invalidate last known value of any hardware watchpoint if |
13045 | the memory which that value represents has been written to by | |
13046 | GDB itself. */ | |
13047 | ||
13048 | static void | |
13049 | invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len, | |
13050 | const bfd_byte *data) | |
13051 | { | |
13052 | struct breakpoint *bp; | |
13053 | ||
13054 | ALL_BREAKPOINTS (bp) | |
13055 | if (bp->enable_state == bp_enabled | |
3a5c3e22 | 13056 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 13057 | { |
3a5c3e22 | 13058 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 13059 | |
3a5c3e22 PA |
13060 | if (wp->val_valid && wp->val) |
13061 | { | |
13062 | struct bp_location *loc; | |
13063 | ||
13064 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
13065 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
13066 | && loc->address + loc->length > addr | |
13067 | && addr + len > loc->address) | |
13068 | { | |
13069 | value_free (wp->val); | |
13070 | wp->val = NULL; | |
13071 | wp->val_valid = 0; | |
13072 | } | |
13073 | } | |
1f3b5d1b PP |
13074 | } |
13075 | } | |
13076 | ||
1bfeeb0f JL |
13077 | /* Use the last displayed codepoint's values, or nothing |
13078 | if they aren't valid. */ | |
c906108c SS |
13079 | |
13080 | struct symtabs_and_lines | |
f8eba3c6 | 13081 | decode_line_spec_1 (char *string, int flags) |
c906108c SS |
13082 | { |
13083 | struct symtabs_and_lines sals; | |
cc59ec59 | 13084 | |
c906108c | 13085 | if (string == 0) |
8a3fe4f8 | 13086 | error (_("Empty line specification.")); |
1bfeeb0f | 13087 | if (last_displayed_sal_is_valid ()) |
f8eba3c6 | 13088 | sals = decode_line_1 (&string, flags, |
1bfeeb0f | 13089 | get_last_displayed_symtab (), |
f8eba3c6 | 13090 | get_last_displayed_line ()); |
c906108c | 13091 | else |
f8eba3c6 | 13092 | sals = decode_line_1 (&string, flags, (struct symtab *) NULL, 0); |
c906108c | 13093 | if (*string) |
8a3fe4f8 | 13094 | error (_("Junk at end of line specification: %s"), string); |
c906108c SS |
13095 | return sals; |
13096 | } | |
8181d85f DJ |
13097 | |
13098 | /* Create and insert a raw software breakpoint at PC. Return an | |
13099 | identifier, which should be used to remove the breakpoint later. | |
13100 | In general, places which call this should be using something on the | |
13101 | breakpoint chain instead; this function should be eliminated | |
13102 | someday. */ | |
13103 | ||
13104 | void * | |
6c95b8df PA |
13105 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, |
13106 | struct address_space *aspace, CORE_ADDR pc) | |
8181d85f DJ |
13107 | { |
13108 | struct bp_target_info *bp_tgt; | |
13109 | ||
6c95b8df | 13110 | bp_tgt = XZALLOC (struct bp_target_info); |
8181d85f | 13111 | |
6c95b8df | 13112 | bp_tgt->placed_address_space = aspace; |
8181d85f | 13113 | bp_tgt->placed_address = pc; |
6c95b8df | 13114 | |
a6d9a66e | 13115 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
8181d85f DJ |
13116 | { |
13117 | /* Could not insert the breakpoint. */ | |
13118 | xfree (bp_tgt); | |
13119 | return NULL; | |
13120 | } | |
13121 | ||
13122 | return bp_tgt; | |
13123 | } | |
13124 | ||
4a64f543 MS |
13125 | /* Remove a breakpoint BP inserted by |
13126 | deprecated_insert_raw_breakpoint. */ | |
8181d85f DJ |
13127 | |
13128 | int | |
a6d9a66e | 13129 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
8181d85f DJ |
13130 | { |
13131 | struct bp_target_info *bp_tgt = bp; | |
13132 | int ret; | |
13133 | ||
a6d9a66e | 13134 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
8181d85f DJ |
13135 | xfree (bp_tgt); |
13136 | ||
13137 | return ret; | |
13138 | } | |
13139 | ||
4a64f543 MS |
13140 | /* One (or perhaps two) breakpoints used for software single |
13141 | stepping. */ | |
8181d85f DJ |
13142 | |
13143 | static void *single_step_breakpoints[2]; | |
a6d9a66e | 13144 | static struct gdbarch *single_step_gdbarch[2]; |
8181d85f DJ |
13145 | |
13146 | /* Create and insert a breakpoint for software single step. */ | |
13147 | ||
13148 | void | |
6c95b8df | 13149 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
13150 | struct address_space *aspace, |
13151 | CORE_ADDR next_pc) | |
8181d85f DJ |
13152 | { |
13153 | void **bpt_p; | |
13154 | ||
13155 | if (single_step_breakpoints[0] == NULL) | |
a6d9a66e UW |
13156 | { |
13157 | bpt_p = &single_step_breakpoints[0]; | |
13158 | single_step_gdbarch[0] = gdbarch; | |
13159 | } | |
8181d85f DJ |
13160 | else |
13161 | { | |
13162 | gdb_assert (single_step_breakpoints[1] == NULL); | |
13163 | bpt_p = &single_step_breakpoints[1]; | |
a6d9a66e | 13164 | single_step_gdbarch[1] = gdbarch; |
8181d85f DJ |
13165 | } |
13166 | ||
4a64f543 MS |
13167 | /* NOTE drow/2006-04-11: A future improvement to this function would |
13168 | be to only create the breakpoints once, and actually put them on | |
13169 | the breakpoint chain. That would let us use set_raw_breakpoint. | |
13170 | We could adjust the addresses each time they were needed. Doing | |
13171 | this requires corresponding changes elsewhere where single step | |
13172 | breakpoints are handled, however. So, for now, we use this. */ | |
8181d85f | 13173 | |
6c95b8df | 13174 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc); |
8181d85f | 13175 | if (*bpt_p == NULL) |
5af949e3 UW |
13176 | error (_("Could not insert single-step breakpoint at %s"), |
13177 | paddress (gdbarch, next_pc)); | |
8181d85f DJ |
13178 | } |
13179 | ||
f02253f1 HZ |
13180 | /* Check if the breakpoints used for software single stepping |
13181 | were inserted or not. */ | |
13182 | ||
13183 | int | |
13184 | single_step_breakpoints_inserted (void) | |
13185 | { | |
13186 | return (single_step_breakpoints[0] != NULL | |
13187 | || single_step_breakpoints[1] != NULL); | |
13188 | } | |
13189 | ||
8181d85f DJ |
13190 | /* Remove and delete any breakpoints used for software single step. */ |
13191 | ||
13192 | void | |
13193 | remove_single_step_breakpoints (void) | |
13194 | { | |
13195 | gdb_assert (single_step_breakpoints[0] != NULL); | |
13196 | ||
13197 | /* See insert_single_step_breakpoint for more about this deprecated | |
13198 | call. */ | |
a6d9a66e UW |
13199 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
13200 | single_step_breakpoints[0]); | |
13201 | single_step_gdbarch[0] = NULL; | |
8181d85f DJ |
13202 | single_step_breakpoints[0] = NULL; |
13203 | ||
13204 | if (single_step_breakpoints[1] != NULL) | |
13205 | { | |
a6d9a66e UW |
13206 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
13207 | single_step_breakpoints[1]); | |
13208 | single_step_gdbarch[1] = NULL; | |
8181d85f DJ |
13209 | single_step_breakpoints[1] = NULL; |
13210 | } | |
13211 | } | |
13212 | ||
d03285ec UW |
13213 | /* Delete software single step breakpoints without removing them from |
13214 | the inferior. This is intended to be used if the inferior's address | |
13215 | space where they were inserted is already gone, e.g. after exit or | |
13216 | exec. */ | |
13217 | ||
13218 | void | |
13219 | cancel_single_step_breakpoints (void) | |
13220 | { | |
13221 | int i; | |
13222 | ||
13223 | for (i = 0; i < 2; i++) | |
13224 | if (single_step_breakpoints[i]) | |
13225 | { | |
13226 | xfree (single_step_breakpoints[i]); | |
13227 | single_step_breakpoints[i] = NULL; | |
13228 | single_step_gdbarch[i] = NULL; | |
13229 | } | |
13230 | } | |
13231 | ||
13232 | /* Detach software single-step breakpoints from INFERIOR_PTID without | |
13233 | removing them. */ | |
13234 | ||
13235 | static void | |
13236 | detach_single_step_breakpoints (void) | |
13237 | { | |
13238 | int i; | |
13239 | ||
13240 | for (i = 0; i < 2; i++) | |
13241 | if (single_step_breakpoints[i]) | |
13242 | target_remove_breakpoint (single_step_gdbarch[i], | |
13243 | single_step_breakpoints[i]); | |
13244 | } | |
13245 | ||
4a64f543 MS |
13246 | /* Check whether a software single-step breakpoint is inserted at |
13247 | PC. */ | |
1aafd4da UW |
13248 | |
13249 | static int | |
cc59ec59 MS |
13250 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, |
13251 | CORE_ADDR pc) | |
1aafd4da UW |
13252 | { |
13253 | int i; | |
13254 | ||
13255 | for (i = 0; i < 2; i++) | |
13256 | { | |
13257 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
6c95b8df PA |
13258 | if (bp_tgt |
13259 | && breakpoint_address_match (bp_tgt->placed_address_space, | |
13260 | bp_tgt->placed_address, | |
13261 | aspace, pc)) | |
1aafd4da UW |
13262 | return 1; |
13263 | } | |
13264 | ||
13265 | return 0; | |
13266 | } | |
13267 | ||
a96d9b2e SDJ |
13268 | /* Returns 0 if 'bp' is NOT a syscall catchpoint, |
13269 | non-zero otherwise. */ | |
13270 | static int | |
13271 | is_syscall_catchpoint_enabled (struct breakpoint *bp) | |
13272 | { | |
13273 | if (syscall_catchpoint_p (bp) | |
13274 | && bp->enable_state != bp_disabled | |
13275 | && bp->enable_state != bp_call_disabled) | |
13276 | return 1; | |
13277 | else | |
13278 | return 0; | |
13279 | } | |
13280 | ||
13281 | int | |
13282 | catch_syscall_enabled (void) | |
13283 | { | |
13284 | struct inferior *inf = current_inferior (); | |
13285 | ||
13286 | return inf->total_syscalls_count != 0; | |
13287 | } | |
13288 | ||
13289 | int | |
13290 | catching_syscall_number (int syscall_number) | |
13291 | { | |
13292 | struct breakpoint *bp; | |
13293 | ||
13294 | ALL_BREAKPOINTS (bp) | |
13295 | if (is_syscall_catchpoint_enabled (bp)) | |
13296 | { | |
be5c67c1 PA |
13297 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bp; |
13298 | ||
13299 | if (c->syscalls_to_be_caught) | |
a96d9b2e SDJ |
13300 | { |
13301 | int i, iter; | |
13302 | for (i = 0; | |
be5c67c1 | 13303 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
13304 | i++) |
13305 | if (syscall_number == iter) | |
13306 | return 1; | |
13307 | } | |
13308 | else | |
13309 | return 1; | |
13310 | } | |
13311 | ||
13312 | return 0; | |
13313 | } | |
13314 | ||
13315 | /* Complete syscall names. Used by "catch syscall". */ | |
13316 | static char ** | |
13317 | catch_syscall_completer (struct cmd_list_element *cmd, | |
13318 | char *text, char *word) | |
13319 | { | |
13320 | const char **list = get_syscall_names (); | |
c38eea1a MS |
13321 | char **retlist |
13322 | = (list == NULL) ? NULL : complete_on_enum (list, text, word); | |
cc59ec59 | 13323 | |
c38eea1a MS |
13324 | xfree (list); |
13325 | return retlist; | |
a96d9b2e SDJ |
13326 | } |
13327 | ||
1042e4c0 SS |
13328 | /* Tracepoint-specific operations. */ |
13329 | ||
13330 | /* Set tracepoint count to NUM. */ | |
13331 | static void | |
13332 | set_tracepoint_count (int num) | |
13333 | { | |
13334 | tracepoint_count = num; | |
4fa62494 | 13335 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
13336 | } |
13337 | ||
13338 | void | |
13339 | trace_command (char *arg, int from_tty) | |
13340 | { | |
8cdf0e15 VP |
13341 | if (create_breakpoint (get_current_arch (), |
13342 | arg, | |
13343 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b PA |
13344 | 0 /* tempflag */, |
13345 | bp_tracepoint /* type_wanted */, | |
8cdf0e15 VP |
13346 | 0 /* Ignore count */, |
13347 | pending_break_support, | |
348d480f | 13348 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 13349 | from_tty, |
84f4c1fe PM |
13350 | 1 /* enabled */, |
13351 | 0 /* internal */)) | |
fd9b8c24 | 13352 | set_tracepoint_count (breakpoint_count); |
1042e4c0 SS |
13353 | } |
13354 | ||
7a697b8d SS |
13355 | void |
13356 | ftrace_command (char *arg, int from_tty) | |
13357 | { | |
8cdf0e15 VP |
13358 | if (create_breakpoint (get_current_arch (), |
13359 | arg, | |
13360 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b PA |
13361 | 0 /* tempflag */, |
13362 | bp_fast_tracepoint /* type_wanted */, | |
13363 | 0 /* Ignore count */, | |
13364 | pending_break_support, | |
348d480f | 13365 | &tracepoint_breakpoint_ops, |
0fb4aa4b | 13366 | from_tty, |
84f4c1fe PM |
13367 | 1 /* enabled */, |
13368 | 0 /* internal */)) | |
0fb4aa4b PA |
13369 | set_tracepoint_count (breakpoint_count); |
13370 | } | |
13371 | ||
13372 | /* strace command implementation. Creates a static tracepoint. */ | |
13373 | ||
13374 | void | |
13375 | strace_command (char *arg, int from_tty) | |
13376 | { | |
983af33b SDJ |
13377 | struct breakpoint_ops *ops; |
13378 | ||
13379 | /* Decide if we are dealing with a static tracepoint marker (`-m'), | |
13380 | or with a normal static tracepoint. */ | |
13381 | if (arg && strncmp (arg, "-m", 2) == 0 && isspace (arg[2])) | |
13382 | ops = &strace_marker_breakpoint_ops; | |
13383 | else | |
13384 | ops = &tracepoint_breakpoint_ops; | |
13385 | ||
0fb4aa4b PA |
13386 | if (create_breakpoint (get_current_arch (), |
13387 | arg, | |
13388 | NULL, 0, 1 /* parse arg */, | |
13389 | 0 /* tempflag */, | |
13390 | bp_static_tracepoint /* type_wanted */, | |
8cdf0e15 VP |
13391 | 0 /* Ignore count */, |
13392 | pending_break_support, | |
983af33b | 13393 | ops, |
8cdf0e15 | 13394 | from_tty, |
84f4c1fe PM |
13395 | 1 /* enabled */, |
13396 | 0 /* internal */)) | |
fd9b8c24 | 13397 | set_tracepoint_count (breakpoint_count); |
7a697b8d SS |
13398 | } |
13399 | ||
409873ef SS |
13400 | /* Set up a fake reader function that gets command lines from a linked |
13401 | list that was acquired during tracepoint uploading. */ | |
13402 | ||
13403 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 13404 | static int next_cmd; |
409873ef SS |
13405 | |
13406 | static char * | |
13407 | read_uploaded_action (void) | |
13408 | { | |
13409 | char *rslt; | |
13410 | ||
3149d8c1 | 13411 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 13412 | |
3149d8c1 | 13413 | next_cmd++; |
409873ef SS |
13414 | |
13415 | return rslt; | |
13416 | } | |
13417 | ||
00bf0b85 SS |
13418 | /* Given information about a tracepoint as recorded on a target (which |
13419 | can be either a live system or a trace file), attempt to create an | |
13420 | equivalent GDB tracepoint. This is not a reliable process, since | |
13421 | the target does not necessarily have all the information used when | |
13422 | the tracepoint was originally defined. */ | |
13423 | ||
d9b3f62e | 13424 | struct tracepoint * |
00bf0b85 | 13425 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 13426 | { |
409873ef | 13427 | char *addr_str, small_buf[100]; |
d9b3f62e | 13428 | struct tracepoint *tp; |
fd9b8c24 | 13429 | |
409873ef SS |
13430 | if (utp->at_string) |
13431 | addr_str = utp->at_string; | |
13432 | else | |
13433 | { | |
13434 | /* In the absence of a source location, fall back to raw | |
13435 | address. Since there is no way to confirm that the address | |
13436 | means the same thing as when the trace was started, warn the | |
13437 | user. */ | |
3e43a32a MS |
13438 | warning (_("Uploaded tracepoint %d has no " |
13439 | "source location, using raw address"), | |
409873ef SS |
13440 | utp->number); |
13441 | sprintf (small_buf, "*%s", hex_string (utp->addr)); | |
13442 | addr_str = small_buf; | |
13443 | } | |
13444 | ||
13445 | /* There's not much we can do with a sequence of bytecodes. */ | |
13446 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
13447 | warning (_("Uploaded tracepoint %d condition " |
13448 | "has no source form, ignoring it"), | |
409873ef | 13449 | utp->number); |
d5551862 | 13450 | |
8cdf0e15 | 13451 | if (!create_breakpoint (get_current_arch (), |
409873ef SS |
13452 | addr_str, |
13453 | utp->cond_string, -1, 0 /* parse cond/thread */, | |
8cdf0e15 | 13454 | 0 /* tempflag */, |
0fb4aa4b | 13455 | utp->type /* type_wanted */, |
8cdf0e15 VP |
13456 | 0 /* Ignore count */, |
13457 | pending_break_support, | |
348d480f | 13458 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 13459 | 0 /* from_tty */, |
84f4c1fe PM |
13460 | utp->enabled /* enabled */, |
13461 | 0 /* internal */)) | |
fd9b8c24 PA |
13462 | return NULL; |
13463 | ||
00bf0b85 SS |
13464 | set_tracepoint_count (breakpoint_count); |
13465 | ||
409873ef | 13466 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
13467 | tp = get_tracepoint (tracepoint_count); |
13468 | gdb_assert (tp != NULL); | |
d5551862 | 13469 | |
00bf0b85 SS |
13470 | if (utp->pass > 0) |
13471 | { | |
d9b3f62e | 13472 | sprintf (small_buf, "%d %d", utp->pass, tp->base.number); |
00bf0b85 | 13473 | |
409873ef | 13474 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
13475 | } |
13476 | ||
409873ef SS |
13477 | /* If we have uploaded versions of the original commands, set up a |
13478 | special-purpose "reader" function and call the usual command line | |
13479 | reader, then pass the result to the breakpoint command-setting | |
13480 | function. */ | |
3149d8c1 | 13481 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 13482 | { |
409873ef | 13483 | struct command_line *cmd_list; |
00bf0b85 | 13484 | |
409873ef | 13485 | this_utp = utp; |
3149d8c1 | 13486 | next_cmd = 0; |
d5551862 | 13487 | |
409873ef SS |
13488 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
13489 | ||
d9b3f62e | 13490 | breakpoint_set_commands (&tp->base, cmd_list); |
00bf0b85 | 13491 | } |
3149d8c1 SS |
13492 | else if (!VEC_empty (char_ptr, utp->actions) |
13493 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
13494 | warning (_("Uploaded tracepoint %d actions " |
13495 | "have no source form, ignoring them"), | |
409873ef | 13496 | utp->number); |
00bf0b85 | 13497 | |
f196051f SS |
13498 | /* Copy any status information that might be available. */ |
13499 | tp->base.hit_count = utp->hit_count; | |
13500 | tp->traceframe_usage = utp->traceframe_usage; | |
13501 | ||
00bf0b85 | 13502 | return tp; |
d9b3f62e | 13503 | } |
00bf0b85 | 13504 | |
1042e4c0 SS |
13505 | /* Print information on tracepoint number TPNUM_EXP, or all if |
13506 | omitted. */ | |
13507 | ||
13508 | static void | |
e5a67952 | 13509 | tracepoints_info (char *args, int from_tty) |
1042e4c0 | 13510 | { |
79a45e25 | 13511 | struct ui_out *uiout = current_uiout; |
e5a67952 | 13512 | int num_printed; |
1042e4c0 | 13513 | |
e5a67952 | 13514 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
13515 | |
13516 | if (num_printed == 0) | |
1042e4c0 | 13517 | { |
e5a67952 | 13518 | if (args == NULL || *args == '\0') |
d77f58be SS |
13519 | ui_out_message (uiout, 0, "No tracepoints.\n"); |
13520 | else | |
e5a67952 | 13521 | ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args); |
1042e4c0 | 13522 | } |
ad443146 SS |
13523 | |
13524 | default_collect_info (); | |
1042e4c0 SS |
13525 | } |
13526 | ||
4a64f543 | 13527 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
13528 | Not supported by all targets. */ |
13529 | static void | |
13530 | enable_trace_command (char *args, int from_tty) | |
13531 | { | |
13532 | enable_command (args, from_tty); | |
13533 | } | |
13534 | ||
4a64f543 | 13535 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
13536 | Not supported by all targets. */ |
13537 | static void | |
13538 | disable_trace_command (char *args, int from_tty) | |
13539 | { | |
13540 | disable_command (args, from_tty); | |
13541 | } | |
13542 | ||
4a64f543 | 13543 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 SS |
13544 | static void |
13545 | delete_trace_command (char *arg, int from_tty) | |
13546 | { | |
35df4500 | 13547 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
13548 | |
13549 | dont_repeat (); | |
13550 | ||
13551 | if (arg == 0) | |
13552 | { | |
13553 | int breaks_to_delete = 0; | |
13554 | ||
13555 | /* Delete all breakpoints if no argument. | |
13556 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
13557 | have to be deleted with an explicit breakpoint number |
13558 | argument. */ | |
1042e4c0 | 13559 | ALL_TRACEPOINTS (b) |
46c6471b | 13560 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
13561 | { |
13562 | breaks_to_delete = 1; | |
13563 | break; | |
13564 | } | |
1042e4c0 SS |
13565 | |
13566 | /* Ask user only if there are some breakpoints to delete. */ | |
13567 | if (!from_tty | |
13568 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
13569 | { | |
35df4500 | 13570 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 13571 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 13572 | delete_breakpoint (b); |
1042e4c0 SS |
13573 | } |
13574 | } | |
13575 | else | |
51be5b68 | 13576 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
1042e4c0 SS |
13577 | } |
13578 | ||
197f0a60 TT |
13579 | /* Helper function for trace_pass_command. */ |
13580 | ||
13581 | static void | |
d9b3f62e | 13582 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 13583 | { |
d9b3f62e PA |
13584 | tp->pass_count = count; |
13585 | observer_notify_tracepoint_modified (tp->base.number); | |
197f0a60 TT |
13586 | if (from_tty) |
13587 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
d9b3f62e | 13588 | tp->base.number, count); |
197f0a60 TT |
13589 | } |
13590 | ||
1042e4c0 SS |
13591 | /* Set passcount for tracepoint. |
13592 | ||
13593 | First command argument is passcount, second is tracepoint number. | |
13594 | If tracepoint number omitted, apply to most recently defined. | |
13595 | Also accepts special argument "all". */ | |
13596 | ||
13597 | static void | |
13598 | trace_pass_command (char *args, int from_tty) | |
13599 | { | |
d9b3f62e | 13600 | struct tracepoint *t1; |
1042e4c0 | 13601 | unsigned int count; |
1042e4c0 SS |
13602 | |
13603 | if (args == 0 || *args == 0) | |
3e43a32a MS |
13604 | error (_("passcount command requires an " |
13605 | "argument (count + optional TP num)")); | |
1042e4c0 | 13606 | |
4a64f543 | 13607 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 SS |
13608 | |
13609 | while (*args && isspace ((int) *args)) | |
13610 | args++; | |
13611 | ||
13612 | if (*args && strncasecmp (args, "all", 3) == 0) | |
13613 | { | |
d9b3f62e PA |
13614 | struct breakpoint *b; |
13615 | ||
1042e4c0 | 13616 | args += 3; /* Skip special argument "all". */ |
1042e4c0 SS |
13617 | if (*args) |
13618 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 13619 | |
d9b3f62e | 13620 | ALL_TRACEPOINTS (b) |
197f0a60 | 13621 | { |
d9b3f62e | 13622 | t1 = (struct tracepoint *) b; |
197f0a60 TT |
13623 | trace_pass_set_count (t1, count, from_tty); |
13624 | } | |
13625 | } | |
13626 | else if (*args == '\0') | |
1042e4c0 | 13627 | { |
197f0a60 | 13628 | t1 = get_tracepoint_by_number (&args, NULL, 1); |
1042e4c0 | 13629 | if (t1) |
197f0a60 TT |
13630 | trace_pass_set_count (t1, count, from_tty); |
13631 | } | |
13632 | else | |
13633 | { | |
13634 | struct get_number_or_range_state state; | |
13635 | ||
13636 | init_number_or_range (&state, args); | |
13637 | while (!state.finished) | |
1042e4c0 | 13638 | { |
197f0a60 TT |
13639 | t1 = get_tracepoint_by_number (&args, &state, 1); |
13640 | if (t1) | |
13641 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
13642 | } |
13643 | } | |
1042e4c0 SS |
13644 | } |
13645 | ||
d9b3f62e | 13646 | struct tracepoint * |
1042e4c0 SS |
13647 | get_tracepoint (int num) |
13648 | { | |
13649 | struct breakpoint *t; | |
13650 | ||
13651 | ALL_TRACEPOINTS (t) | |
13652 | if (t->number == num) | |
d9b3f62e | 13653 | return (struct tracepoint *) t; |
1042e4c0 SS |
13654 | |
13655 | return NULL; | |
13656 | } | |
13657 | ||
d5551862 SS |
13658 | /* Find the tracepoint with the given target-side number (which may be |
13659 | different from the tracepoint number after disconnecting and | |
13660 | reconnecting). */ | |
13661 | ||
d9b3f62e | 13662 | struct tracepoint * |
d5551862 SS |
13663 | get_tracepoint_by_number_on_target (int num) |
13664 | { | |
d9b3f62e | 13665 | struct breakpoint *b; |
d5551862 | 13666 | |
d9b3f62e PA |
13667 | ALL_TRACEPOINTS (b) |
13668 | { | |
13669 | struct tracepoint *t = (struct tracepoint *) b; | |
13670 | ||
13671 | if (t->number_on_target == num) | |
13672 | return t; | |
13673 | } | |
d5551862 SS |
13674 | |
13675 | return NULL; | |
13676 | } | |
13677 | ||
1042e4c0 | 13678 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 TT |
13679 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
13680 | If OPTIONAL_P is true, then if the argument is missing, the most | |
1042e4c0 | 13681 | recent tracepoint (tracepoint_count) is returned. */ |
d9b3f62e | 13682 | struct tracepoint * |
197f0a60 TT |
13683 | get_tracepoint_by_number (char **arg, |
13684 | struct get_number_or_range_state *state, | |
13685 | int optional_p) | |
1042e4c0 SS |
13686 | { |
13687 | extern int tracepoint_count; | |
13688 | struct breakpoint *t; | |
13689 | int tpnum; | |
13690 | char *instring = arg == NULL ? NULL : *arg; | |
13691 | ||
197f0a60 TT |
13692 | if (state) |
13693 | { | |
13694 | gdb_assert (!state->finished); | |
13695 | tpnum = get_number_or_range (state); | |
13696 | } | |
13697 | else if (arg == NULL || *arg == NULL || ! **arg) | |
1042e4c0 SS |
13698 | { |
13699 | if (optional_p) | |
13700 | tpnum = tracepoint_count; | |
13701 | else | |
13702 | error_no_arg (_("tracepoint number")); | |
13703 | } | |
13704 | else | |
197f0a60 | 13705 | tpnum = get_number (arg); |
1042e4c0 SS |
13706 | |
13707 | if (tpnum <= 0) | |
13708 | { | |
13709 | if (instring && *instring) | |
13710 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
13711 | instring); | |
13712 | else | |
3e43a32a MS |
13713 | printf_filtered (_("Tracepoint argument missing " |
13714 | "and no previous tracepoint\n")); | |
1042e4c0 SS |
13715 | return NULL; |
13716 | } | |
13717 | ||
13718 | ALL_TRACEPOINTS (t) | |
13719 | if (t->number == tpnum) | |
13720 | { | |
d9b3f62e | 13721 | return (struct tracepoint *) t; |
1042e4c0 SS |
13722 | } |
13723 | ||
1042e4c0 SS |
13724 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
13725 | return NULL; | |
13726 | } | |
13727 | ||
d9b3f62e PA |
13728 | void |
13729 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
13730 | { | |
13731 | if (b->thread != -1) | |
13732 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
13733 | ||
13734 | if (b->task != 0) | |
13735 | fprintf_unfiltered (fp, " task %d", b->task); | |
13736 | ||
13737 | fprintf_unfiltered (fp, "\n"); | |
13738 | } | |
13739 | ||
6149aea9 PA |
13740 | /* Save information on user settable breakpoints (watchpoints, etc) to |
13741 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
13742 | on each breakpoint and only include the ones for which it returns | |
13743 | non-zero. */ | |
13744 | ||
1042e4c0 | 13745 | static void |
6149aea9 PA |
13746 | save_breakpoints (char *filename, int from_tty, |
13747 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
13748 | { |
13749 | struct breakpoint *tp; | |
6149aea9 | 13750 | int any = 0; |
a7bdde9e | 13751 | char *pathname; |
1042e4c0 | 13752 | struct cleanup *cleanup; |
a7bdde9e | 13753 | struct ui_file *fp; |
6149aea9 | 13754 | int extra_trace_bits = 0; |
1042e4c0 | 13755 | |
6149aea9 PA |
13756 | if (filename == 0 || *filename == 0) |
13757 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
13758 | |
13759 | /* See if we have anything to save. */ | |
6149aea9 | 13760 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 13761 | { |
6149aea9 | 13762 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 13763 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
13764 | continue; |
13765 | ||
13766 | /* If we have a filter, only save the breakpoints it accepts. */ | |
13767 | if (filter && !filter (tp)) | |
13768 | continue; | |
13769 | ||
13770 | any = 1; | |
13771 | ||
13772 | if (is_tracepoint (tp)) | |
13773 | { | |
13774 | extra_trace_bits = 1; | |
13775 | ||
13776 | /* We can stop searching. */ | |
13777 | break; | |
13778 | } | |
1042e4c0 | 13779 | } |
6149aea9 PA |
13780 | |
13781 | if (!any) | |
1042e4c0 | 13782 | { |
6149aea9 | 13783 | warning (_("Nothing to save.")); |
1042e4c0 SS |
13784 | return; |
13785 | } | |
13786 | ||
6149aea9 | 13787 | pathname = tilde_expand (filename); |
1042e4c0 | 13788 | cleanup = make_cleanup (xfree, pathname); |
a7bdde9e | 13789 | fp = gdb_fopen (pathname, "w"); |
059fb39f | 13790 | if (!fp) |
6149aea9 PA |
13791 | error (_("Unable to open file '%s' for saving (%s)"), |
13792 | filename, safe_strerror (errno)); | |
a7bdde9e | 13793 | make_cleanup_ui_file_delete (fp); |
8bf6485c | 13794 | |
6149aea9 PA |
13795 | if (extra_trace_bits) |
13796 | save_trace_state_variables (fp); | |
8bf6485c | 13797 | |
6149aea9 | 13798 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 13799 | { |
6149aea9 | 13800 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 13801 | if (!user_breakpoint_p (tp)) |
6149aea9 | 13802 | continue; |
8bf6485c | 13803 | |
6149aea9 PA |
13804 | /* If we have a filter, only save the breakpoints it accepts. */ |
13805 | if (filter && !filter (tp)) | |
13806 | continue; | |
13807 | ||
348d480f | 13808 | tp->ops->print_recreate (tp, fp); |
1042e4c0 | 13809 | |
6149aea9 PA |
13810 | /* Note, we can't rely on tp->number for anything, as we can't |
13811 | assume the recreated breakpoint numbers will match. Use $bpnum | |
13812 | instead. */ | |
13813 | ||
13814 | if (tp->cond_string) | |
13815 | fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); | |
13816 | ||
13817 | if (tp->ignore_count) | |
13818 | fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); | |
13819 | ||
a7bdde9e | 13820 | if (tp->commands) |
1042e4c0 | 13821 | { |
a7bdde9e VP |
13822 | volatile struct gdb_exception ex; |
13823 | ||
6149aea9 | 13824 | fprintf_unfiltered (fp, " commands\n"); |
a7bdde9e | 13825 | |
79a45e25 | 13826 | ui_out_redirect (current_uiout, fp); |
14dba4b4 | 13827 | TRY_CATCH (ex, RETURN_MASK_ALL) |
1042e4c0 | 13828 | { |
79a45e25 | 13829 | print_command_lines (current_uiout, tp->commands->commands, 2); |
a7bdde9e | 13830 | } |
79a45e25 | 13831 | ui_out_redirect (current_uiout, NULL); |
1042e4c0 | 13832 | |
a7bdde9e VP |
13833 | if (ex.reason < 0) |
13834 | throw_exception (ex); | |
1042e4c0 | 13835 | |
a7bdde9e | 13836 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 | 13837 | } |
6149aea9 PA |
13838 | |
13839 | if (tp->enable_state == bp_disabled) | |
13840 | fprintf_unfiltered (fp, "disable\n"); | |
13841 | ||
13842 | /* If this is a multi-location breakpoint, check if the locations | |
13843 | should be individually disabled. Watchpoint locations are | |
13844 | special, and not user visible. */ | |
13845 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
13846 | { | |
13847 | struct bp_location *loc; | |
13848 | int n = 1; | |
13849 | ||
13850 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
13851 | if (!loc->enabled) | |
13852 | fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); | |
13853 | } | |
1042e4c0 | 13854 | } |
8bf6485c | 13855 | |
6149aea9 | 13856 | if (extra_trace_bits && *default_collect) |
8bf6485c SS |
13857 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); |
13858 | ||
1042e4c0 SS |
13859 | do_cleanups (cleanup); |
13860 | if (from_tty) | |
6149aea9 PA |
13861 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
13862 | } | |
13863 | ||
13864 | /* The `save breakpoints' command. */ | |
13865 | ||
13866 | static void | |
13867 | save_breakpoints_command (char *args, int from_tty) | |
13868 | { | |
13869 | save_breakpoints (args, from_tty, NULL); | |
13870 | } | |
13871 | ||
13872 | /* The `save tracepoints' command. */ | |
13873 | ||
13874 | static void | |
13875 | save_tracepoints_command (char *args, int from_tty) | |
13876 | { | |
13877 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
13878 | } |
13879 | ||
13880 | /* Create a vector of all tracepoints. */ | |
13881 | ||
13882 | VEC(breakpoint_p) * | |
eeae04df | 13883 | all_tracepoints (void) |
1042e4c0 SS |
13884 | { |
13885 | VEC(breakpoint_p) *tp_vec = 0; | |
13886 | struct breakpoint *tp; | |
13887 | ||
13888 | ALL_TRACEPOINTS (tp) | |
13889 | { | |
13890 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
13891 | } | |
13892 | ||
13893 | return tp_vec; | |
13894 | } | |
13895 | ||
c906108c | 13896 | \f |
4a64f543 MS |
13897 | /* This help string is used for the break, hbreak, tbreak and thbreak |
13898 | commands. It is defined as a macro to prevent duplication. | |
13899 | COMMAND should be a string constant containing the name of the | |
13900 | command. */ | |
31e2b00f AS |
13901 | #define BREAK_ARGS_HELP(command) \ |
13902 | command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\ | |
13903 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ | |
13904 | If a line number is specified, break at start of code for that line.\n\ | |
13905 | If a function is specified, break at start of code for that function.\n\ | |
13906 | If an address is specified, break at that exact address.\n\ | |
dc10affe PA |
13907 | With no LOCATION, uses current execution address of the selected\n\ |
13908 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
13909 | \n\ |
13910 | THREADNUM is the number from \"info threads\".\n\ | |
13911 | CONDITION is a boolean expression.\n\ | |
13912 | \n\ | |
d41c0fc8 PA |
13913 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
13914 | conditions are different.\n\ | |
31e2b00f AS |
13915 | \n\ |
13916 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
13917 | ||
44feb3ce TT |
13918 | /* List of subcommands for "catch". */ |
13919 | static struct cmd_list_element *catch_cmdlist; | |
13920 | ||
13921 | /* List of subcommands for "tcatch". */ | |
13922 | static struct cmd_list_element *tcatch_cmdlist; | |
13923 | ||
9ac4176b | 13924 | void |
44feb3ce TT |
13925 | add_catch_command (char *name, char *docstring, |
13926 | void (*sfunc) (char *args, int from_tty, | |
13927 | struct cmd_list_element *command), | |
a96d9b2e SDJ |
13928 | char **(*completer) (struct cmd_list_element *cmd, |
13929 | char *text, char *word), | |
44feb3ce TT |
13930 | void *user_data_catch, |
13931 | void *user_data_tcatch) | |
13932 | { | |
13933 | struct cmd_list_element *command; | |
13934 | ||
13935 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
13936 | &catch_cmdlist); | |
13937 | set_cmd_sfunc (command, sfunc); | |
13938 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 13939 | set_cmd_completer (command, completer); |
44feb3ce TT |
13940 | |
13941 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
13942 | &tcatch_cmdlist); | |
13943 | set_cmd_sfunc (command, sfunc); | |
13944 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 13945 | set_cmd_completer (command, completer); |
44feb3ce TT |
13946 | } |
13947 | ||
6c95b8df | 13948 | static void |
a79b8f6e | 13949 | clear_syscall_counts (struct inferior *inf) |
6c95b8df | 13950 | { |
6c95b8df PA |
13951 | inf->total_syscalls_count = 0; |
13952 | inf->any_syscall_count = 0; | |
13953 | VEC_free (int, inf->syscalls_counts); | |
13954 | } | |
13955 | ||
6149aea9 PA |
13956 | static void |
13957 | save_command (char *arg, int from_tty) | |
13958 | { | |
3e43a32a MS |
13959 | printf_unfiltered (_("\"save\" must be followed by " |
13960 | "the name of a save subcommand.\n")); | |
6149aea9 PA |
13961 | help_list (save_cmdlist, "save ", -1, gdb_stdout); |
13962 | } | |
13963 | ||
84f4c1fe PM |
13964 | struct breakpoint * |
13965 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
13966 | void *data) | |
13967 | { | |
35df4500 | 13968 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 13969 | |
35df4500 | 13970 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
13971 | { |
13972 | if ((*callback) (b, data)) | |
13973 | return b; | |
13974 | } | |
13975 | ||
13976 | return NULL; | |
13977 | } | |
13978 | ||
0574c78f GB |
13979 | /* Zero if any of the breakpoint's locations could be a location where |
13980 | functions have been inlined, nonzero otherwise. */ | |
13981 | ||
13982 | static int | |
13983 | is_non_inline_function (struct breakpoint *b) | |
13984 | { | |
13985 | /* The shared library event breakpoint is set on the address of a | |
13986 | non-inline function. */ | |
13987 | if (b->type == bp_shlib_event) | |
13988 | return 1; | |
13989 | ||
13990 | return 0; | |
13991 | } | |
13992 | ||
13993 | /* Nonzero if the specified PC cannot be a location where functions | |
13994 | have been inlined. */ | |
13995 | ||
13996 | int | |
09ac7c10 TT |
13997 | pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc, |
13998 | const struct target_waitstatus *ws) | |
0574c78f GB |
13999 | { |
14000 | struct breakpoint *b; | |
14001 | struct bp_location *bl; | |
14002 | ||
14003 | ALL_BREAKPOINTS (b) | |
14004 | { | |
14005 | if (!is_non_inline_function (b)) | |
14006 | continue; | |
14007 | ||
14008 | for (bl = b->loc; bl != NULL; bl = bl->next) | |
14009 | { | |
14010 | if (!bl->shlib_disabled | |
09ac7c10 | 14011 | && bpstat_check_location (bl, aspace, pc, ws)) |
0574c78f GB |
14012 | return 1; |
14013 | } | |
14014 | } | |
14015 | ||
14016 | return 0; | |
14017 | } | |
14018 | ||
2060206e PA |
14019 | void |
14020 | initialize_breakpoint_ops (void) | |
14021 | { | |
14022 | static int initialized = 0; | |
14023 | ||
14024 | struct breakpoint_ops *ops; | |
14025 | ||
14026 | if (initialized) | |
14027 | return; | |
14028 | initialized = 1; | |
14029 | ||
14030 | /* The breakpoint_ops structure to be inherit by all kinds of | |
14031 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
14032 | internal and momentary breakpoints, etc.). */ | |
14033 | ops = &bkpt_base_breakpoint_ops; | |
14034 | *ops = base_breakpoint_ops; | |
14035 | ops->re_set = bkpt_re_set; | |
14036 | ops->insert_location = bkpt_insert_location; | |
14037 | ops->remove_location = bkpt_remove_location; | |
14038 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
983af33b SDJ |
14039 | ops->create_sals_from_address = bkpt_create_sals_from_address; |
14040 | ops->create_breakpoints_sal = bkpt_create_breakpoints_sal; | |
14041 | ops->decode_linespec = bkpt_decode_linespec; | |
2060206e PA |
14042 | |
14043 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
14044 | ops = &bkpt_breakpoint_ops; | |
14045 | *ops = bkpt_base_breakpoint_ops; | |
14046 | ops->re_set = bkpt_re_set; | |
14047 | ops->resources_needed = bkpt_resources_needed; | |
14048 | ops->print_it = bkpt_print_it; | |
14049 | ops->print_mention = bkpt_print_mention; | |
14050 | ops->print_recreate = bkpt_print_recreate; | |
14051 | ||
14052 | /* Ranged breakpoints. */ | |
14053 | ops = &ranged_breakpoint_ops; | |
14054 | *ops = bkpt_breakpoint_ops; | |
14055 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
14056 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
14057 | ops->print_it = print_it_ranged_breakpoint; | |
14058 | ops->print_one = print_one_ranged_breakpoint; | |
14059 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
14060 | ops->print_mention = print_mention_ranged_breakpoint; | |
14061 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
14062 | ||
14063 | /* Internal breakpoints. */ | |
14064 | ops = &internal_breakpoint_ops; | |
14065 | *ops = bkpt_base_breakpoint_ops; | |
14066 | ops->re_set = internal_bkpt_re_set; | |
14067 | ops->check_status = internal_bkpt_check_status; | |
14068 | ops->print_it = internal_bkpt_print_it; | |
14069 | ops->print_mention = internal_bkpt_print_mention; | |
14070 | ||
14071 | /* Momentary breakpoints. */ | |
14072 | ops = &momentary_breakpoint_ops; | |
14073 | *ops = bkpt_base_breakpoint_ops; | |
14074 | ops->re_set = momentary_bkpt_re_set; | |
14075 | ops->check_status = momentary_bkpt_check_status; | |
14076 | ops->print_it = momentary_bkpt_print_it; | |
14077 | ops->print_mention = momentary_bkpt_print_mention; | |
14078 | ||
14079 | /* GNU v3 exception catchpoints. */ | |
14080 | ops = &gnu_v3_exception_catchpoint_ops; | |
14081 | *ops = bkpt_breakpoint_ops; | |
14082 | ops->print_it = print_it_exception_catchpoint; | |
14083 | ops->print_one = print_one_exception_catchpoint; | |
14084 | ops->print_mention = print_mention_exception_catchpoint; | |
14085 | ops->print_recreate = print_recreate_exception_catchpoint; | |
14086 | ||
14087 | /* Watchpoints. */ | |
14088 | ops = &watchpoint_breakpoint_ops; | |
14089 | *ops = base_breakpoint_ops; | |
3a5c3e22 | 14090 | ops->dtor = dtor_watchpoint; |
2060206e PA |
14091 | ops->re_set = re_set_watchpoint; |
14092 | ops->insert_location = insert_watchpoint; | |
14093 | ops->remove_location = remove_watchpoint; | |
14094 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
14095 | ops->check_status = check_status_watchpoint; | |
14096 | ops->resources_needed = resources_needed_watchpoint; | |
14097 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
14098 | ops->print_it = print_it_watchpoint; | |
14099 | ops->print_mention = print_mention_watchpoint; | |
14100 | ops->print_recreate = print_recreate_watchpoint; | |
14101 | ||
14102 | /* Masked watchpoints. */ | |
14103 | ops = &masked_watchpoint_breakpoint_ops; | |
14104 | *ops = watchpoint_breakpoint_ops; | |
14105 | ops->insert_location = insert_masked_watchpoint; | |
14106 | ops->remove_location = remove_masked_watchpoint; | |
14107 | ops->resources_needed = resources_needed_masked_watchpoint; | |
14108 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
14109 | ops->print_it = print_it_masked_watchpoint; | |
14110 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
14111 | ops->print_mention = print_mention_masked_watchpoint; | |
14112 | ops->print_recreate = print_recreate_masked_watchpoint; | |
14113 | ||
14114 | /* Tracepoints. */ | |
14115 | ops = &tracepoint_breakpoint_ops; | |
14116 | *ops = base_breakpoint_ops; | |
14117 | ops->re_set = tracepoint_re_set; | |
14118 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
14119 | ops->print_one_detail = tracepoint_print_one_detail; | |
14120 | ops->print_mention = tracepoint_print_mention; | |
14121 | ops->print_recreate = tracepoint_print_recreate; | |
983af33b SDJ |
14122 | ops->create_sals_from_address = tracepoint_create_sals_from_address; |
14123 | ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal; | |
14124 | ops->decode_linespec = tracepoint_decode_linespec; | |
14125 | ||
14126 | /* Static tracepoints with marker (`-m'). */ | |
14127 | ops = &strace_marker_breakpoint_ops; | |
14128 | *ops = tracepoint_breakpoint_ops; | |
14129 | ops->create_sals_from_address = strace_marker_create_sals_from_address; | |
14130 | ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal; | |
14131 | ops->decode_linespec = strace_marker_decode_linespec; | |
2060206e PA |
14132 | |
14133 | /* Fork catchpoints. */ | |
14134 | ops = &catch_fork_breakpoint_ops; | |
14135 | *ops = base_breakpoint_ops; | |
14136 | ops->insert_location = insert_catch_fork; | |
14137 | ops->remove_location = remove_catch_fork; | |
14138 | ops->breakpoint_hit = breakpoint_hit_catch_fork; | |
14139 | ops->print_it = print_it_catch_fork; | |
14140 | ops->print_one = print_one_catch_fork; | |
14141 | ops->print_mention = print_mention_catch_fork; | |
14142 | ops->print_recreate = print_recreate_catch_fork; | |
14143 | ||
14144 | /* Vfork catchpoints. */ | |
14145 | ops = &catch_vfork_breakpoint_ops; | |
14146 | *ops = base_breakpoint_ops; | |
14147 | ops->insert_location = insert_catch_vfork; | |
14148 | ops->remove_location = remove_catch_vfork; | |
14149 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; | |
14150 | ops->print_it = print_it_catch_vfork; | |
14151 | ops->print_one = print_one_catch_vfork; | |
14152 | ops->print_mention = print_mention_catch_vfork; | |
14153 | ops->print_recreate = print_recreate_catch_vfork; | |
14154 | ||
14155 | /* Exec catchpoints. */ | |
14156 | ops = &catch_exec_breakpoint_ops; | |
14157 | *ops = base_breakpoint_ops; | |
14158 | ops->dtor = dtor_catch_exec; | |
14159 | ops->insert_location = insert_catch_exec; | |
14160 | ops->remove_location = remove_catch_exec; | |
14161 | ops->breakpoint_hit = breakpoint_hit_catch_exec; | |
14162 | ops->print_it = print_it_catch_exec; | |
14163 | ops->print_one = print_one_catch_exec; | |
14164 | ops->print_mention = print_mention_catch_exec; | |
14165 | ops->print_recreate = print_recreate_catch_exec; | |
14166 | ||
14167 | /* Syscall catchpoints. */ | |
14168 | ops = &catch_syscall_breakpoint_ops; | |
14169 | *ops = base_breakpoint_ops; | |
14170 | ops->dtor = dtor_catch_syscall; | |
14171 | ops->insert_location = insert_catch_syscall; | |
14172 | ops->remove_location = remove_catch_syscall; | |
14173 | ops->breakpoint_hit = breakpoint_hit_catch_syscall; | |
14174 | ops->print_it = print_it_catch_syscall; | |
14175 | ops->print_one = print_one_catch_syscall; | |
14176 | ops->print_mention = print_mention_catch_syscall; | |
14177 | ops->print_recreate = print_recreate_catch_syscall; | |
edcc5120 TT |
14178 | |
14179 | /* Solib-related catchpoints. */ | |
14180 | ops = &catch_solib_breakpoint_ops; | |
14181 | *ops = base_breakpoint_ops; | |
14182 | ops->dtor = dtor_catch_solib; | |
14183 | ops->insert_location = insert_catch_solib; | |
14184 | ops->remove_location = remove_catch_solib; | |
14185 | ops->breakpoint_hit = breakpoint_hit_catch_solib; | |
14186 | ops->check_status = check_status_catch_solib; | |
14187 | ops->print_it = print_it_catch_solib; | |
14188 | ops->print_one = print_one_catch_solib; | |
14189 | ops->print_mention = print_mention_catch_solib; | |
14190 | ops->print_recreate = print_recreate_catch_solib; | |
2060206e PA |
14191 | } |
14192 | ||
c906108c | 14193 | void |
fba45db2 | 14194 | _initialize_breakpoint (void) |
c906108c SS |
14195 | { |
14196 | struct cmd_list_element *c; | |
14197 | ||
2060206e PA |
14198 | initialize_breakpoint_ops (); |
14199 | ||
84acb35a | 14200 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
6c95b8df | 14201 | observer_attach_inferior_exit (clear_syscall_counts); |
1f3b5d1b | 14202 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 14203 | |
17450429 PP |
14204 | breakpoint_objfile_key = register_objfile_data (); |
14205 | ||
c906108c SS |
14206 | breakpoint_chain = 0; |
14207 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
14208 | before a breakpoint is set. */ | |
14209 | breakpoint_count = 0; | |
14210 | ||
1042e4c0 SS |
14211 | tracepoint_count = 0; |
14212 | ||
1bedd215 AC |
14213 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
14214 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
14215 | Usage is `ignore N COUNT'.")); | |
c906108c | 14216 | if (xdb_commands) |
c5aa993b | 14217 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 14218 | |
1bedd215 AC |
14219 | add_com ("commands", class_breakpoint, commands_command, _("\ |
14220 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
14221 | Give breakpoint number as argument after \"commands\".\n\ |
14222 | With no argument, the targeted breakpoint is the last one set.\n\ | |
14223 | The commands themselves follow starting on the next line.\n\ | |
14224 | Type a line containing \"end\" to indicate the end of them.\n\ | |
14225 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 14226 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 14227 | |
1bedd215 AC |
14228 | add_com ("condition", class_breakpoint, condition_command, _("\ |
14229 | Specify breakpoint number N to break only if COND is true.\n\ | |
c906108c | 14230 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 14231 | expression to be evaluated whenever breakpoint N is reached.")); |
c906108c | 14232 | |
1bedd215 | 14233 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 14234 | Set a temporary breakpoint.\n\ |
c906108c SS |
14235 | Like \"break\" except the breakpoint is only temporary,\n\ |
14236 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
14237 | by using \"enable delete\" on the breakpoint number.\n\ |
14238 | \n" | |
14239 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 14240 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 14241 | |
1bedd215 | 14242 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 14243 | Set a hardware assisted breakpoint.\n\ |
c906108c | 14244 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
14245 | some target hardware may not have this support.\n\ |
14246 | \n" | |
14247 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 14248 | set_cmd_completer (c, location_completer); |
c906108c | 14249 | |
1bedd215 | 14250 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 14251 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 14252 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
14253 | so it will be deleted when hit.\n\ |
14254 | \n" | |
14255 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 14256 | set_cmd_completer (c, location_completer); |
c906108c | 14257 | |
1bedd215 AC |
14258 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
14259 | Enable some breakpoints.\n\ | |
c906108c SS |
14260 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
14261 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
14262 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 14263 | With a subcommand you can enable temporarily."), |
c906108c SS |
14264 | &enablelist, "enable ", 1, &cmdlist); |
14265 | if (xdb_commands) | |
1bedd215 AC |
14266 | add_com ("ab", class_breakpoint, enable_command, _("\ |
14267 | Enable some breakpoints.\n\ | |
c906108c SS |
14268 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
14269 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
14270 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 14271 | With a subcommand you can enable temporarily.")); |
c906108c SS |
14272 | |
14273 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
14274 | ||
84951ab5 | 14275 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 14276 | Enable some breakpoints.\n\ |
c906108c SS |
14277 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
14278 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 14279 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 14280 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 14281 | |
1a966eab AC |
14282 | add_cmd ("once", no_class, enable_once_command, _("\ |
14283 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
14284 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
14285 | &enablebreaklist); |
14286 | ||
1a966eab AC |
14287 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
14288 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
14289 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
14290 | &enablebreaklist); |
14291 | ||
1a966eab AC |
14292 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
14293 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
14294 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
14295 | &enablelist); |
14296 | ||
1a966eab AC |
14297 | add_cmd ("once", no_class, enable_once_command, _("\ |
14298 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
14299 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
14300 | &enablelist); |
14301 | ||
1bedd215 AC |
14302 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
14303 | Disable some breakpoints.\n\ | |
c906108c SS |
14304 | Arguments are breakpoint numbers with spaces in between.\n\ |
14305 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 14306 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
c906108c SS |
14307 | &disablelist, "disable ", 1, &cmdlist); |
14308 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
14309 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
14310 | if (xdb_commands) | |
1bedd215 AC |
14311 | add_com ("sb", class_breakpoint, disable_command, _("\ |
14312 | Disable some breakpoints.\n\ | |
c906108c SS |
14313 | Arguments are breakpoint numbers with spaces in between.\n\ |
14314 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 14315 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.")); |
c906108c | 14316 | |
1a966eab AC |
14317 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
14318 | Disable some breakpoints.\n\ | |
c906108c SS |
14319 | Arguments are breakpoint numbers with spaces in between.\n\ |
14320 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 14321 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 14322 | This command may be abbreviated \"disable\"."), |
c906108c SS |
14323 | &disablelist); |
14324 | ||
1bedd215 AC |
14325 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
14326 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
14327 | Arguments are breakpoint numbers with spaces in between.\n\ |
14328 | To delete all breakpoints, give no argument.\n\ | |
14329 | \n\ | |
14330 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 14331 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
14332 | &deletelist, "delete ", 1, &cmdlist); |
14333 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 14334 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 14335 | if (xdb_commands) |
1bedd215 AC |
14336 | add_com ("db", class_breakpoint, delete_command, _("\ |
14337 | Delete some breakpoints.\n\ | |
c906108c | 14338 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 14339 | To delete all breakpoints, give no argument.\n")); |
c906108c | 14340 | |
1a966eab AC |
14341 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
14342 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
14343 | Arguments are breakpoint numbers with spaces in between.\n\ |
14344 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 14345 | This command may be abbreviated \"delete\"."), |
c906108c SS |
14346 | &deletelist); |
14347 | ||
1bedd215 AC |
14348 | add_com ("clear", class_breakpoint, clear_command, _("\ |
14349 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
14350 | Argument may be line number, function name, or \"*\" and an address.\n\ |
14351 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
14352 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
14353 | If an address is specified, breakpoints at that address are cleared.\n\ |
14354 | \n\ | |
14355 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
14356 | is executing in.\n\ |
14357 | \n\ | |
1bedd215 | 14358 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 14359 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 14360 | |
1bedd215 | 14361 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
14362 | Set breakpoint at specified line or function.\n" |
14363 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 14364 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 14365 | |
c906108c SS |
14366 | add_com_alias ("b", "break", class_run, 1); |
14367 | add_com_alias ("br", "break", class_run, 1); | |
14368 | add_com_alias ("bre", "break", class_run, 1); | |
14369 | add_com_alias ("brea", "break", class_run, 1); | |
14370 | ||
7681d515 PM |
14371 | if (xdb_commands) |
14372 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
14373 | |
14374 | if (dbx_commands) | |
14375 | { | |
1bedd215 AC |
14376 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
14377 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
14378 | &stoplist, "stop ", 1, &cmdlist); |
14379 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 14380 | _("Break in function or address."), &stoplist); |
c5aa993b | 14381 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 14382 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
14383 | add_com ("status", class_info, breakpoints_info, _("\ |
14384 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
14385 | The \"Type\" column indicates one of:\n\ |
14386 | \tbreakpoint - normal breakpoint\n\ | |
14387 | \twatchpoint - watchpoint\n\ | |
14388 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
14389 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
14390 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
14391 | address and file/line number respectively.\n\ |
14392 | \n\ | |
14393 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
14394 | are set to the address of the last breakpoint listed unless the command\n\ |
14395 | is prefixed with \"server \".\n\n\ | |
c906108c | 14396 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 14397 | breakpoint set.")); |
c906108c SS |
14398 | } |
14399 | ||
1bedd215 | 14400 | add_info ("breakpoints", breakpoints_info, _("\ |
e5a67952 | 14401 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
14402 | The \"Type\" column indicates one of:\n\ |
14403 | \tbreakpoint - normal breakpoint\n\ | |
14404 | \twatchpoint - watchpoint\n\ | |
14405 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
14406 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
14407 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
14408 | address and file/line number respectively.\n\ |
14409 | \n\ | |
14410 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
14411 | are set to the address of the last breakpoint listed unless the command\n\ |
14412 | is prefixed with \"server \".\n\n\ | |
c906108c | 14413 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 14414 | breakpoint set.")); |
c906108c | 14415 | |
6b04bdb7 MS |
14416 | add_info_alias ("b", "breakpoints", 1); |
14417 | ||
c906108c | 14418 | if (xdb_commands) |
1bedd215 AC |
14419 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
14420 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
14421 | The \"Type\" column indicates one of:\n\ |
14422 | \tbreakpoint - normal breakpoint\n\ | |
14423 | \twatchpoint - watchpoint\n\ | |
14424 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
14425 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
14426 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
14427 | address and file/line number respectively.\n\ |
14428 | \n\ | |
14429 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
14430 | are set to the address of the last breakpoint listed unless the command\n\ |
14431 | is prefixed with \"server \".\n\n\ | |
c906108c | 14432 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 14433 | breakpoint set.")); |
c906108c | 14434 | |
1a966eab AC |
14435 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
14436 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
14437 | The \"Type\" column indicates one of:\n\ |
14438 | \tbreakpoint - normal breakpoint\n\ | |
14439 | \twatchpoint - watchpoint\n\ | |
14440 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
14441 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
14442 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
14443 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
14444 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
14445 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
14446 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
14447 | address and file/line number respectively.\n\ |
14448 | \n\ | |
14449 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
14450 | are set to the address of the last breakpoint listed unless the command\n\ |
14451 | is prefixed with \"server \".\n\n\ | |
c906108c | 14452 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 14453 | breakpoint set."), |
c906108c SS |
14454 | &maintenanceinfolist); |
14455 | ||
44feb3ce TT |
14456 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
14457 | Set catchpoints to catch events."), | |
14458 | &catch_cmdlist, "catch ", | |
14459 | 0/*allow-unknown*/, &cmdlist); | |
14460 | ||
14461 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
14462 | Set temporary catchpoints to catch events."), | |
14463 | &tcatch_cmdlist, "tcatch ", | |
14464 | 0/*allow-unknown*/, &cmdlist); | |
14465 | ||
14466 | /* Add catch and tcatch sub-commands. */ | |
14467 | add_catch_command ("catch", _("\ | |
88e7d25d | 14468 | Catch an exception, when caught."), |
44feb3ce | 14469 | catch_catch_command, |
a96d9b2e | 14470 | NULL, |
44feb3ce TT |
14471 | CATCH_PERMANENT, |
14472 | CATCH_TEMPORARY); | |
14473 | add_catch_command ("throw", _("\ | |
88e7d25d | 14474 | Catch an exception, when thrown."), |
44feb3ce | 14475 | catch_throw_command, |
a96d9b2e | 14476 | NULL, |
44feb3ce TT |
14477 | CATCH_PERMANENT, |
14478 | CATCH_TEMPORARY); | |
14479 | add_catch_command ("fork", _("Catch calls to fork."), | |
14480 | catch_fork_command_1, | |
a96d9b2e | 14481 | NULL, |
44feb3ce TT |
14482 | (void *) (uintptr_t) catch_fork_permanent, |
14483 | (void *) (uintptr_t) catch_fork_temporary); | |
14484 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
14485 | catch_fork_command_1, | |
a96d9b2e | 14486 | NULL, |
44feb3ce TT |
14487 | (void *) (uintptr_t) catch_vfork_permanent, |
14488 | (void *) (uintptr_t) catch_vfork_temporary); | |
14489 | add_catch_command ("exec", _("Catch calls to exec."), | |
14490 | catch_exec_command_1, | |
a96d9b2e SDJ |
14491 | NULL, |
14492 | CATCH_PERMANENT, | |
14493 | CATCH_TEMPORARY); | |
edcc5120 TT |
14494 | add_catch_command ("load", _("Catch loads of shared libraries.\n\ |
14495 | Usage: catch load [REGEX]\n\ | |
14496 | If REGEX is given, only stop for libraries matching the regular expression."), | |
14497 | catch_load_command_1, | |
14498 | NULL, | |
14499 | CATCH_PERMANENT, | |
14500 | CATCH_TEMPORARY); | |
14501 | add_catch_command ("unload", _("Catch unloads of shared libraries.\n\ | |
14502 | Usage: catch unload [REGEX]\n\ | |
14503 | If REGEX is given, only stop for libraries matching the regular expression."), | |
14504 | catch_unload_command_1, | |
14505 | NULL, | |
14506 | CATCH_PERMANENT, | |
14507 | CATCH_TEMPORARY); | |
a96d9b2e SDJ |
14508 | add_catch_command ("syscall", _("\ |
14509 | Catch system calls by their names and/or numbers.\n\ | |
14510 | Arguments say which system calls to catch. If no arguments\n\ | |
14511 | are given, every system call will be caught.\n\ | |
14512 | Arguments, if given, should be one or more system call names\n\ | |
14513 | (if your system supports that), or system call numbers."), | |
14514 | catch_syscall_command_1, | |
14515 | catch_syscall_completer, | |
44feb3ce TT |
14516 | CATCH_PERMANENT, |
14517 | CATCH_TEMPORARY); | |
c5aa993b | 14518 | |
1bedd215 AC |
14519 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
14520 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 14521 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 14522 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
14523 | an expression changes.\n\ |
14524 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
14525 | the memory to which it refers.")); | |
65d12d83 | 14526 | set_cmd_completer (c, expression_completer); |
c906108c | 14527 | |
1bedd215 AC |
14528 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
14529 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 14530 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 14531 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
14532 | an expression is read.\n\ |
14533 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
14534 | the memory to which it refers.")); | |
65d12d83 | 14535 | set_cmd_completer (c, expression_completer); |
c906108c | 14536 | |
1bedd215 AC |
14537 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
14538 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 14539 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 14540 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
14541 | an expression is either read or written.\n\ |
14542 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
14543 | the memory to which it refers.")); | |
65d12d83 | 14544 | set_cmd_completer (c, expression_completer); |
c906108c | 14545 | |
d77f58be | 14546 | add_info ("watchpoints", watchpoints_info, _("\ |
e5a67952 | 14547 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 14548 | |
920d2a44 AC |
14549 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
14550 | respond to changes - contrary to the description. */ | |
85c07804 AC |
14551 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
14552 | &can_use_hw_watchpoints, _("\ | |
14553 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
14554 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
14555 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
14556 | such is available. (However, any hardware watchpoints that were\n\ | |
14557 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
14558 | hardware.)"), |
14559 | NULL, | |
920d2a44 | 14560 | show_can_use_hw_watchpoints, |
85c07804 | 14561 | &setlist, &showlist); |
c906108c SS |
14562 | |
14563 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 14564 | |
1042e4c0 SS |
14565 | /* Tracepoint manipulation commands. */ |
14566 | ||
14567 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
14568 | Set a tracepoint at specified line or function.\n\ | |
14569 | \n" | |
14570 | BREAK_ARGS_HELP ("trace") "\n\ | |
14571 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
14572 | set_cmd_completer (c, location_completer); | |
14573 | ||
14574 | add_com_alias ("tp", "trace", class_alias, 0); | |
14575 | add_com_alias ("tr", "trace", class_alias, 1); | |
14576 | add_com_alias ("tra", "trace", class_alias, 1); | |
14577 | add_com_alias ("trac", "trace", class_alias, 1); | |
14578 | ||
7a697b8d SS |
14579 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
14580 | Set a fast tracepoint at specified line or function.\n\ | |
14581 | \n" | |
14582 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
14583 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
14584 | set_cmd_completer (c, location_completer); | |
14585 | ||
0fb4aa4b PA |
14586 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
14587 | Set a static tracepoint at specified line, function or marker.\n\ | |
14588 | \n\ | |
14589 | strace [LOCATION] [if CONDITION]\n\ | |
14590 | LOCATION may be a line number, function name, \"*\" and an address,\n\ | |
14591 | or -m MARKER_ID.\n\ | |
14592 | If a line number is specified, probe the marker at start of code\n\ | |
14593 | for that line. If a function is specified, probe the marker at start\n\ | |
14594 | of code for that function. If an address is specified, probe the marker\n\ | |
14595 | at that exact address. If a marker id is specified, probe the marker\n\ | |
14596 | with that name. With no LOCATION, uses current execution address of\n\ | |
14597 | the selected stack frame.\n\ | |
14598 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ | |
14599 | This collects arbitrary user data passed in the probe point call to the\n\ | |
14600 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
14601 | by printing the $_sdata variable like any other convenience variable.\n\ | |
14602 | \n\ | |
14603 | CONDITION is a boolean expression.\n\ | |
14604 | \n\ | |
d41c0fc8 PA |
14605 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
14606 | conditions are different.\n\ | |
0fb4aa4b PA |
14607 | \n\ |
14608 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
14609 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
14610 | set_cmd_completer (c, location_completer); | |
14611 | ||
1042e4c0 | 14612 | add_info ("tracepoints", tracepoints_info, _("\ |
e5a67952 | 14613 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
14614 | Convenience variable \"$tpnum\" contains the number of the\n\ |
14615 | last tracepoint set.")); | |
14616 | ||
14617 | add_info_alias ("tp", "tracepoints", 1); | |
14618 | ||
14619 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
14620 | Delete specified tracepoints.\n\ | |
14621 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
14622 | No argument means delete all tracepoints."), | |
14623 | &deletelist); | |
14624 | ||
14625 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
14626 | Disable specified tracepoints.\n\ | |
14627 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
14628 | No argument means disable all tracepoints."), | |
14629 | &disablelist); | |
14630 | deprecate_cmd (c, "disable"); | |
14631 | ||
14632 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
14633 | Enable specified tracepoints.\n\ | |
14634 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
14635 | No argument means enable all tracepoints."), | |
14636 | &enablelist); | |
14637 | deprecate_cmd (c, "enable"); | |
14638 | ||
14639 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
14640 | Set the passcount for a tracepoint.\n\ | |
14641 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
14642 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
14643 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
14644 | ||
6149aea9 PA |
14645 | add_prefix_cmd ("save", class_breakpoint, save_command, |
14646 | _("Save breakpoint definitions as a script."), | |
14647 | &save_cmdlist, "save ", | |
14648 | 0/*allow-unknown*/, &cmdlist); | |
14649 | ||
14650 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
14651 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 14652 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
14653 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
14654 | session to restore them."), | |
14655 | &save_cmdlist); | |
14656 | set_cmd_completer (c, filename_completer); | |
14657 | ||
14658 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 14659 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
14660 | Use the 'source' command in another debug session to restore them."), |
14661 | &save_cmdlist); | |
1042e4c0 SS |
14662 | set_cmd_completer (c, filename_completer); |
14663 | ||
6149aea9 PA |
14664 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
14665 | deprecate_cmd (c, "save tracepoints"); | |
14666 | ||
1bedd215 | 14667 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
14668 | Breakpoint specific settings\n\ |
14669 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 14670 | pending breakpoint behavior"), |
fa8d40ab JJ |
14671 | &breakpoint_set_cmdlist, "set breakpoint ", |
14672 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 14673 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
14674 | Breakpoint specific settings\n\ |
14675 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 14676 | pending breakpoint behavior"), |
fa8d40ab JJ |
14677 | &breakpoint_show_cmdlist, "show breakpoint ", |
14678 | 0/*allow-unknown*/, &showlist); | |
14679 | ||
7915a72c AC |
14680 | add_setshow_auto_boolean_cmd ("pending", no_class, |
14681 | &pending_break_support, _("\ | |
14682 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
14683 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
14684 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
14685 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
14686 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 14687 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 14688 | NULL, |
920d2a44 | 14689 | show_pending_break_support, |
6e1d7d6c AC |
14690 | &breakpoint_set_cmdlist, |
14691 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
14692 | |
14693 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
14694 | |
14695 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
14696 | &automatic_hardware_breakpoints, _("\ | |
14697 | Set automatic usage of hardware breakpoints."), _("\ | |
14698 | Show automatic usage of hardware breakpoints."), _("\ | |
14699 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
14700 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
14701 | a warning will be emitted for such breakpoints."), | |
14702 | NULL, | |
14703 | show_automatic_hardware_breakpoints, | |
14704 | &breakpoint_set_cmdlist, | |
14705 | &breakpoint_show_cmdlist); | |
74960c60 | 14706 | |
33e5cbd6 PA |
14707 | add_setshow_enum_cmd ("always-inserted", class_support, |
14708 | always_inserted_enums, &always_inserted_mode, _("\ | |
74960c60 VP |
14709 | Set mode for inserting breakpoints."), _("\ |
14710 | Show mode for inserting breakpoints."), _("\ | |
33e5cbd6 PA |
14711 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
14712 | resumed, and removed when execution stops. When this mode is on,\n\ | |
14713 | breakpoints are inserted immediately and removed only when the user\n\ | |
14714 | deletes the breakpoint. When this mode is auto (which is the default),\n\ | |
14715 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ | |
14716 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ | |
14717 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ | |
14718 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), | |
74960c60 VP |
14719 | NULL, |
14720 | &show_always_inserted_mode, | |
14721 | &breakpoint_set_cmdlist, | |
14722 | &breakpoint_show_cmdlist); | |
f1310107 TJB |
14723 | |
14724 | add_com ("break-range", class_breakpoint, break_range_command, _("\ | |
14725 | Set a breakpoint for an address range.\n\ | |
14726 | break-range START-LOCATION, END-LOCATION\n\ | |
14727 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
14728 | LINENUM, for that line in the current file,\n\ | |
14729 | FILE:LINENUM, for that line in that file,\n\ | |
14730 | +OFFSET, for that number of lines after the current line\n\ | |
14731 | or the start of the range\n\ | |
14732 | FUNCTION, for the first line in that function,\n\ | |
14733 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
14734 | *ADDRESS, for the instruction at that address.\n\ | |
14735 | \n\ | |
14736 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
14737 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
14738 | range (including START-LOCATION and END-LOCATION).")); | |
14739 | ||
765dc015 | 14740 | automatic_hardware_breakpoints = 1; |
f3b1572e PA |
14741 | |
14742 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
c906108c | 14743 | } |