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" |
c906108c | 68 | |
1042e4c0 SS |
69 | /* readline include files */ |
70 | #include "readline/readline.h" | |
71 | #include "readline/history.h" | |
72 | ||
73 | /* readline defines this. */ | |
74 | #undef savestring | |
75 | ||
034dad6f | 76 | #include "mi/mi-common.h" |
7371cf6d | 77 | #include "python/python.h" |
104c1213 | 78 | |
4a64f543 | 79 | /* Prototypes for local functions. */ |
c906108c | 80 | |
a14ed312 | 81 | static void enable_delete_command (char *, int); |
c906108c | 82 | |
a14ed312 | 83 | static void enable_once_command (char *, int); |
c906108c | 84 | |
a14ed312 | 85 | static void disable_command (char *, int); |
c906108c | 86 | |
a14ed312 | 87 | static void enable_command (char *, int); |
c906108c | 88 | |
95a42b64 TT |
89 | static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *, |
90 | void *), | |
91 | void *); | |
c906108c | 92 | |
a14ed312 | 93 | static void ignore_command (char *, int); |
c906108c | 94 | |
4efb68b1 | 95 | static int breakpoint_re_set_one (void *); |
c906108c | 96 | |
348d480f PA |
97 | static void breakpoint_re_set_default (struct breakpoint *); |
98 | ||
983af33b SDJ |
99 | static void create_sals_from_address_default (char **, |
100 | struct linespec_result *, | |
101 | enum bptype, char *, | |
102 | char **); | |
103 | ||
104 | static void create_breakpoints_sal_default (struct gdbarch *, | |
105 | struct linespec_result *, | |
106 | struct linespec_sals *, | |
107 | char *, enum bptype, | |
108 | enum bpdisp, int, int, | |
109 | int, | |
110 | const struct breakpoint_ops *, | |
111 | int, int, int); | |
112 | ||
113 | static void decode_linespec_default (struct breakpoint *, char **, | |
114 | struct symtabs_and_lines *); | |
115 | ||
a14ed312 | 116 | static void clear_command (char *, int); |
c906108c | 117 | |
a14ed312 | 118 | static void catch_command (char *, int); |
c906108c | 119 | |
a9634178 | 120 | static int can_use_hardware_watchpoint (struct value *); |
c906108c | 121 | |
98deb0da | 122 | static void break_command_1 (char *, int, int); |
c906108c | 123 | |
a14ed312 | 124 | static void mention (struct breakpoint *); |
c906108c | 125 | |
348d480f PA |
126 | static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *, |
127 | enum bptype, | |
c0a91b2b | 128 | const struct breakpoint_ops *); |
3742cc8b YQ |
129 | static struct bp_location *add_location_to_breakpoint (struct breakpoint *, |
130 | const struct symtab_and_line *); | |
131 | ||
4a64f543 MS |
132 | /* This function is used in gdbtk sources and thus can not be made |
133 | static. */ | |
63c252f8 | 134 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
348d480f | 135 | struct symtab_and_line, |
c0a91b2b TT |
136 | enum bptype, |
137 | const struct breakpoint_ops *); | |
c906108c | 138 | |
06edf0c0 PA |
139 | static struct breakpoint * |
140 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
141 | enum bptype type, | |
c0a91b2b | 142 | const struct breakpoint_ops *ops); |
06edf0c0 | 143 | |
76897487 KB |
144 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
145 | ||
a6d9a66e UW |
146 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
147 | CORE_ADDR bpaddr, | |
88f7da05 | 148 | enum bptype bptype); |
76897487 | 149 | |
6c95b8df PA |
150 | static void describe_other_breakpoints (struct gdbarch *, |
151 | struct program_space *, CORE_ADDR, | |
5af949e3 | 152 | struct obj_section *, int); |
c906108c | 153 | |
6c95b8df PA |
154 | static int breakpoint_address_match (struct address_space *aspace1, |
155 | CORE_ADDR addr1, | |
156 | struct address_space *aspace2, | |
157 | CORE_ADDR addr2); | |
158 | ||
85d721b8 PA |
159 | static int watchpoint_locations_match (struct bp_location *loc1, |
160 | struct bp_location *loc2); | |
161 | ||
f1310107 TJB |
162 | static int breakpoint_location_address_match (struct bp_location *bl, |
163 | struct address_space *aspace, | |
164 | CORE_ADDR addr); | |
165 | ||
a14ed312 | 166 | static void breakpoints_info (char *, int); |
c906108c | 167 | |
d77f58be SS |
168 | static void watchpoints_info (char *, int); |
169 | ||
e5a67952 MS |
170 | static int breakpoint_1 (char *, int, |
171 | int (*) (const struct breakpoint *)); | |
c906108c | 172 | |
4efb68b1 | 173 | static int breakpoint_cond_eval (void *); |
c906108c | 174 | |
4efb68b1 | 175 | static void cleanup_executing_breakpoints (void *); |
c906108c | 176 | |
a14ed312 | 177 | static void commands_command (char *, int); |
c906108c | 178 | |
a14ed312 | 179 | static void condition_command (char *, int); |
c906108c | 180 | |
c5aa993b JM |
181 | typedef enum |
182 | { | |
183 | mark_inserted, | |
184 | mark_uninserted | |
185 | } | |
186 | insertion_state_t; | |
c906108c | 187 | |
0bde7532 | 188 | static int remove_breakpoint (struct bp_location *, insertion_state_t); |
6c95b8df | 189 | static int remove_breakpoint_1 (struct bp_location *, insertion_state_t); |
c906108c | 190 | |
e514a9d6 | 191 | static enum print_stop_action print_bp_stop_message (bpstat bs); |
c906108c | 192 | |
4efb68b1 | 193 | static int watchpoint_check (void *); |
c906108c | 194 | |
a14ed312 | 195 | static void maintenance_info_breakpoints (char *, int); |
c906108c | 196 | |
a14ed312 | 197 | static int hw_breakpoint_used_count (void); |
c906108c | 198 | |
a1398e0c PA |
199 | static int hw_watchpoint_use_count (struct breakpoint *); |
200 | ||
201 | static int hw_watchpoint_used_count_others (struct breakpoint *except, | |
202 | enum bptype type, | |
203 | int *other_type_used); | |
c906108c | 204 | |
a14ed312 | 205 | static void hbreak_command (char *, int); |
c906108c | 206 | |
a14ed312 | 207 | static void thbreak_command (char *, int); |
c906108c | 208 | |
51be5b68 | 209 | static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp); |
c906108c | 210 | |
a14ed312 | 211 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 212 | |
a14ed312 | 213 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 214 | |
a14ed312 | 215 | static void stopat_command (char *arg, int from_tty); |
7a292a7a | 216 | |
a14ed312 | 217 | static char *ep_parse_optional_if_clause (char **arg); |
7a292a7a | 218 | |
d85310f7 MS |
219 | static void catch_exception_command_1 (enum exception_event_kind ex_event, |
220 | char *arg, int tempflag, int from_tty); | |
7a292a7a | 221 | |
a14ed312 | 222 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 223 | |
d03285ec UW |
224 | static void detach_single_step_breakpoints (void); |
225 | ||
6c95b8df PA |
226 | static int single_step_breakpoint_inserted_here_p (struct address_space *, |
227 | CORE_ADDR pc); | |
1aafd4da | 228 | |
fe3f5fa8 | 229 | static void free_bp_location (struct bp_location *loc); |
f431efe5 PA |
230 | static void incref_bp_location (struct bp_location *loc); |
231 | static void decref_bp_location (struct bp_location **loc); | |
fe3f5fa8 | 232 | |
39d61571 | 233 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 234 | |
b60e7edf | 235 | static void update_global_location_list (int); |
a5606eee | 236 | |
b60e7edf | 237 | static void update_global_location_list_nothrow (int); |
74960c60 | 238 | |
d77f58be | 239 | static int is_hardware_watchpoint (const struct breakpoint *bpt); |
74960c60 VP |
240 | |
241 | static void insert_breakpoint_locations (void); | |
a5606eee | 242 | |
a96d9b2e SDJ |
243 | static int syscall_catchpoint_p (struct breakpoint *b); |
244 | ||
1042e4c0 SS |
245 | static void tracepoints_info (char *, int); |
246 | ||
247 | static void delete_trace_command (char *, int); | |
248 | ||
249 | static void enable_trace_command (char *, int); | |
250 | ||
251 | static void disable_trace_command (char *, int); | |
252 | ||
253 | static void trace_pass_command (char *, int); | |
254 | ||
9c06b0b4 TJB |
255 | static int is_masked_watchpoint (const struct breakpoint *b); |
256 | ||
983af33b SDJ |
257 | /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero |
258 | otherwise. */ | |
259 | ||
260 | static int strace_marker_p (struct breakpoint *b); | |
0fb4aa4b | 261 | |
2060206e PA |
262 | /* The abstract base class all breakpoint_ops structures inherit |
263 | from. */ | |
264 | static struct breakpoint_ops base_breakpoint_ops; | |
265 | ||
266 | /* The breakpoint_ops structure to be inherited by all breakpoint_ops | |
267 | that are implemented on top of software or hardware breakpoints | |
268 | (user breakpoints, internal and momentary breakpoints, etc.). */ | |
269 | static struct breakpoint_ops bkpt_base_breakpoint_ops; | |
270 | ||
271 | /* Internal breakpoints class type. */ | |
06edf0c0 | 272 | static struct breakpoint_ops internal_breakpoint_ops; |
2060206e PA |
273 | |
274 | /* Momentary breakpoints class type. */ | |
06edf0c0 PA |
275 | static struct breakpoint_ops momentary_breakpoint_ops; |
276 | ||
2060206e PA |
277 | /* The breakpoint_ops structure to be used in regular user created |
278 | breakpoints. */ | |
279 | struct breakpoint_ops bkpt_breakpoint_ops; | |
280 | ||
5cea2a26 PA |
281 | /* A reference-counted struct command_line. This lets multiple |
282 | breakpoints share a single command list. */ | |
283 | struct counted_command_line | |
284 | { | |
285 | /* The reference count. */ | |
286 | int refc; | |
287 | ||
288 | /* The command list. */ | |
289 | struct command_line *commands; | |
290 | }; | |
291 | ||
292 | struct command_line * | |
293 | breakpoint_commands (struct breakpoint *b) | |
294 | { | |
295 | return b->commands ? b->commands->commands : NULL; | |
296 | } | |
3daf8fe5 | 297 | |
f3b1572e PA |
298 | /* Flag indicating that a command has proceeded the inferior past the |
299 | current breakpoint. */ | |
300 | ||
301 | static int breakpoint_proceeded; | |
302 | ||
956a9fb9 | 303 | const char * |
2cec12e5 AR |
304 | bpdisp_text (enum bpdisp disp) |
305 | { | |
4a64f543 MS |
306 | /* NOTE: the following values are a part of MI protocol and |
307 | represent values of 'disp' field returned when inferior stops at | |
308 | a breakpoint. */ | |
bc043ef3 | 309 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
cc59ec59 | 310 | |
2cec12e5 AR |
311 | return bpdisps[(int) disp]; |
312 | } | |
c906108c | 313 | |
4a64f543 | 314 | /* Prototypes for exported functions. */ |
c906108c | 315 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
4a64f543 | 316 | if such is available. */ |
c906108c SS |
317 | static int can_use_hw_watchpoints; |
318 | ||
920d2a44 AC |
319 | static void |
320 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
321 | struct cmd_list_element *c, | |
322 | const char *value) | |
323 | { | |
3e43a32a MS |
324 | fprintf_filtered (file, |
325 | _("Debugger's willingness to use " | |
326 | "watchpoint hardware is %s.\n"), | |
920d2a44 AC |
327 | value); |
328 | } | |
329 | ||
fa8d40ab JJ |
330 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
331 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
4a64f543 | 332 | for unrecognized breakpoint locations. |
fa8d40ab JJ |
333 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
334 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
335 | static void |
336 | show_pending_break_support (struct ui_file *file, int from_tty, | |
337 | struct cmd_list_element *c, | |
338 | const char *value) | |
339 | { | |
3e43a32a MS |
340 | fprintf_filtered (file, |
341 | _("Debugger's behavior regarding " | |
342 | "pending breakpoints is %s.\n"), | |
920d2a44 AC |
343 | value); |
344 | } | |
fa8d40ab | 345 | |
765dc015 | 346 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
4a64f543 | 347 | set with "break" but falling in read-only memory. |
765dc015 VP |
348 | If 0, gdb will warn about such breakpoints, but won't automatically |
349 | use hardware breakpoints. */ | |
350 | static int automatic_hardware_breakpoints; | |
351 | static void | |
352 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
353 | struct cmd_list_element *c, | |
354 | const char *value) | |
355 | { | |
3e43a32a MS |
356 | fprintf_filtered (file, |
357 | _("Automatic usage of hardware breakpoints is %s.\n"), | |
765dc015 VP |
358 | value); |
359 | } | |
360 | ||
33e5cbd6 PA |
361 | /* If on, gdb will keep breakpoints inserted even as inferior is |
362 | stopped, and immediately insert any new breakpoints. If off, gdb | |
363 | will insert breakpoints into inferior only when resuming it, and | |
364 | will remove breakpoints upon stop. If auto, GDB will behave as ON | |
365 | if in non-stop mode, and as OFF if all-stop mode.*/ | |
366 | ||
367 | static const char always_inserted_auto[] = "auto"; | |
368 | static const char always_inserted_on[] = "on"; | |
369 | static const char always_inserted_off[] = "off"; | |
370 | static const char *always_inserted_enums[] = { | |
371 | always_inserted_auto, | |
372 | always_inserted_off, | |
373 | always_inserted_on, | |
374 | NULL | |
375 | }; | |
376 | static const char *always_inserted_mode = always_inserted_auto; | |
377 | static void | |
74960c60 | 378 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 379 | struct cmd_list_element *c, const char *value) |
74960c60 | 380 | { |
33e5cbd6 | 381 | if (always_inserted_mode == always_inserted_auto) |
3e43a32a MS |
382 | fprintf_filtered (file, |
383 | _("Always inserted breakpoint " | |
384 | "mode is %s (currently %s).\n"), | |
33e5cbd6 PA |
385 | value, |
386 | breakpoints_always_inserted_mode () ? "on" : "off"); | |
387 | else | |
3e43a32a MS |
388 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), |
389 | value); | |
74960c60 VP |
390 | } |
391 | ||
33e5cbd6 PA |
392 | int |
393 | breakpoints_always_inserted_mode (void) | |
394 | { | |
049e32d3 PA |
395 | return ((always_inserted_mode == always_inserted_on |
396 | || (always_inserted_mode == always_inserted_auto && non_stop)) | |
397 | && !RECORD_IS_USED); | |
33e5cbd6 | 398 | } |
765dc015 | 399 | |
a14ed312 | 400 | void _initialize_breakpoint (void); |
c906108c | 401 | |
c906108c SS |
402 | /* Are we executing breakpoint commands? */ |
403 | static int executing_breakpoint_commands; | |
404 | ||
c02f5703 MS |
405 | /* Are overlay event breakpoints enabled? */ |
406 | static int overlay_events_enabled; | |
407 | ||
e09342b5 TJB |
408 | /* See description in breakpoint.h. */ |
409 | int target_exact_watchpoints = 0; | |
410 | ||
c906108c | 411 | /* Walk the following statement or block through all breakpoints. |
e5dd4106 | 412 | ALL_BREAKPOINTS_SAFE does so even if the statement deletes the |
4a64f543 | 413 | current breakpoint. */ |
c906108c | 414 | |
5c44784c | 415 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 416 | |
5c44784c JM |
417 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
418 | for (B = breakpoint_chain; \ | |
419 | B ? (TMP=B->next, 1): 0; \ | |
420 | B = TMP) | |
c906108c | 421 | |
4a64f543 MS |
422 | /* Similar iterator for the low-level breakpoints. SAFE variant is |
423 | not provided so update_global_location_list must not be called | |
424 | while executing the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 425 | |
876fa593 JK |
426 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
427 | for (BP_TMP = bp_location; \ | |
428 | BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \ | |
429 | BP_TMP++) | |
7cc221ef | 430 | |
1042e4c0 SS |
431 | /* Iterator for tracepoints only. */ |
432 | ||
433 | #define ALL_TRACEPOINTS(B) \ | |
434 | for (B = breakpoint_chain; B; B = B->next) \ | |
d77f58be | 435 | if (is_tracepoint (B)) |
1042e4c0 | 436 | |
7cc221ef | 437 | /* Chains of all breakpoints defined. */ |
c906108c SS |
438 | |
439 | struct breakpoint *breakpoint_chain; | |
440 | ||
876fa593 JK |
441 | /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */ |
442 | ||
443 | static struct bp_location **bp_location; | |
444 | ||
445 | /* Number of elements of BP_LOCATION. */ | |
446 | ||
447 | static unsigned bp_location_count; | |
448 | ||
4a64f543 MS |
449 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
450 | ADDRESS for the current elements of BP_LOCATION which get a valid | |
451 | result from bp_location_has_shadow. You can use it for roughly | |
452 | limiting the subrange of BP_LOCATION to scan for shadow bytes for | |
453 | an address you need to read. */ | |
876fa593 JK |
454 | |
455 | static CORE_ADDR bp_location_placed_address_before_address_max; | |
456 | ||
4a64f543 MS |
457 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
458 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of | |
459 | BP_LOCATION which get a valid result from bp_location_has_shadow. | |
460 | You can use it for roughly limiting the subrange of BP_LOCATION to | |
461 | scan for shadow bytes for an address you need to read. */ | |
876fa593 JK |
462 | |
463 | static CORE_ADDR bp_location_shadow_len_after_address_max; | |
7cc221ef | 464 | |
4a64f543 MS |
465 | /* The locations that no longer correspond to any breakpoint, unlinked |
466 | from bp_location array, but for which a hit may still be reported | |
467 | by a target. */ | |
20874c92 VP |
468 | VEC(bp_location_p) *moribund_locations = NULL; |
469 | ||
c906108c SS |
470 | /* Number of last breakpoint made. */ |
471 | ||
95a42b64 TT |
472 | static int breakpoint_count; |
473 | ||
86b17b60 PA |
474 | /* The value of `breakpoint_count' before the last command that |
475 | created breakpoints. If the last (break-like) command created more | |
476 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
477 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
478 | static int prev_breakpoint_count; | |
c906108c | 479 | |
1042e4c0 SS |
480 | /* Number of last tracepoint made. */ |
481 | ||
95a42b64 | 482 | static int tracepoint_count; |
1042e4c0 | 483 | |
6149aea9 PA |
484 | static struct cmd_list_element *breakpoint_set_cmdlist; |
485 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
9291a0cd | 486 | struct cmd_list_element *save_cmdlist; |
6149aea9 | 487 | |
468d015d JJ |
488 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
489 | static int | |
490 | breakpoint_enabled (struct breakpoint *b) | |
491 | { | |
0d381245 | 492 | return (b->enable_state == bp_enabled); |
468d015d JJ |
493 | } |
494 | ||
c906108c SS |
495 | /* Set breakpoint count to NUM. */ |
496 | ||
95a42b64 | 497 | static void |
fba45db2 | 498 | set_breakpoint_count (int num) |
c906108c | 499 | { |
86b17b60 | 500 | prev_breakpoint_count = breakpoint_count; |
c906108c | 501 | breakpoint_count = num; |
4fa62494 | 502 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
503 | } |
504 | ||
86b17b60 PA |
505 | /* Used by `start_rbreak_breakpoints' below, to record the current |
506 | breakpoint count before "rbreak" creates any breakpoint. */ | |
507 | static int rbreak_start_breakpoint_count; | |
508 | ||
95a42b64 TT |
509 | /* Called at the start an "rbreak" command to record the first |
510 | breakpoint made. */ | |
86b17b60 | 511 | |
95a42b64 TT |
512 | void |
513 | start_rbreak_breakpoints (void) | |
514 | { | |
86b17b60 | 515 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
516 | } |
517 | ||
518 | /* Called at the end of an "rbreak" command to record the last | |
519 | breakpoint made. */ | |
86b17b60 | 520 | |
95a42b64 TT |
521 | void |
522 | end_rbreak_breakpoints (void) | |
523 | { | |
86b17b60 | 524 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
525 | } |
526 | ||
4a64f543 | 527 | /* Used in run_command to zero the hit count when a new run starts. */ |
c906108c SS |
528 | |
529 | void | |
fba45db2 | 530 | clear_breakpoint_hit_counts (void) |
c906108c SS |
531 | { |
532 | struct breakpoint *b; | |
533 | ||
534 | ALL_BREAKPOINTS (b) | |
535 | b->hit_count = 0; | |
536 | } | |
537 | ||
9add0f1b TT |
538 | /* Allocate a new counted_command_line with reference count of 1. |
539 | The new structure owns COMMANDS. */ | |
540 | ||
541 | static struct counted_command_line * | |
542 | alloc_counted_command_line (struct command_line *commands) | |
543 | { | |
544 | struct counted_command_line *result | |
545 | = xmalloc (sizeof (struct counted_command_line)); | |
cc59ec59 | 546 | |
9add0f1b TT |
547 | result->refc = 1; |
548 | result->commands = commands; | |
549 | return result; | |
550 | } | |
551 | ||
552 | /* Increment reference count. This does nothing if CMD is NULL. */ | |
553 | ||
554 | static void | |
555 | incref_counted_command_line (struct counted_command_line *cmd) | |
556 | { | |
557 | if (cmd) | |
558 | ++cmd->refc; | |
559 | } | |
560 | ||
561 | /* Decrement reference count. If the reference count reaches 0, | |
562 | destroy the counted_command_line. Sets *CMDP to NULL. This does | |
563 | nothing if *CMDP is NULL. */ | |
564 | ||
565 | static void | |
566 | decref_counted_command_line (struct counted_command_line **cmdp) | |
567 | { | |
568 | if (*cmdp) | |
569 | { | |
570 | if (--(*cmdp)->refc == 0) | |
571 | { | |
572 | free_command_lines (&(*cmdp)->commands); | |
573 | xfree (*cmdp); | |
574 | } | |
575 | *cmdp = NULL; | |
576 | } | |
577 | } | |
578 | ||
579 | /* A cleanup function that calls decref_counted_command_line. */ | |
580 | ||
581 | static void | |
582 | do_cleanup_counted_command_line (void *arg) | |
583 | { | |
584 | decref_counted_command_line (arg); | |
585 | } | |
586 | ||
587 | /* Create a cleanup that calls decref_counted_command_line on the | |
588 | argument. */ | |
589 | ||
590 | static struct cleanup * | |
591 | make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp) | |
592 | { | |
593 | return make_cleanup (do_cleanup_counted_command_line, cmdp); | |
594 | } | |
595 | ||
c906108c | 596 | \f |
48cb2d85 VP |
597 | /* Return the breakpoint with the specified number, or NULL |
598 | if the number does not refer to an existing breakpoint. */ | |
599 | ||
600 | struct breakpoint * | |
601 | get_breakpoint (int num) | |
602 | { | |
603 | struct breakpoint *b; | |
604 | ||
605 | ALL_BREAKPOINTS (b) | |
606 | if (b->number == num) | |
607 | return b; | |
608 | ||
609 | return NULL; | |
610 | } | |
5c44784c | 611 | |
c906108c | 612 | \f |
adc36818 PM |
613 | |
614 | void | |
615 | set_breakpoint_condition (struct breakpoint *b, char *exp, | |
616 | int from_tty) | |
617 | { | |
3a5c3e22 PA |
618 | xfree (b->cond_string); |
619 | b->cond_string = NULL; | |
adc36818 | 620 | |
3a5c3e22 | 621 | if (is_watchpoint (b)) |
adc36818 | 622 | { |
3a5c3e22 PA |
623 | struct watchpoint *w = (struct watchpoint *) b; |
624 | ||
625 | xfree (w->cond_exp); | |
626 | w->cond_exp = NULL; | |
627 | } | |
628 | else | |
629 | { | |
630 | struct bp_location *loc; | |
631 | ||
632 | for (loc = b->loc; loc; loc = loc->next) | |
633 | { | |
634 | xfree (loc->cond); | |
635 | loc->cond = NULL; | |
636 | } | |
adc36818 | 637 | } |
adc36818 PM |
638 | |
639 | if (*exp == 0) | |
640 | { | |
641 | if (from_tty) | |
642 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
643 | } | |
644 | else | |
645 | { | |
646 | char *arg = exp; | |
cc59ec59 | 647 | |
adc36818 PM |
648 | /* I don't know if it matters whether this is the string the user |
649 | typed in or the decompiled expression. */ | |
650 | b->cond_string = xstrdup (arg); | |
651 | b->condition_not_parsed = 0; | |
652 | ||
653 | if (is_watchpoint (b)) | |
654 | { | |
3a5c3e22 PA |
655 | struct watchpoint *w = (struct watchpoint *) b; |
656 | ||
adc36818 PM |
657 | innermost_block = NULL; |
658 | arg = exp; | |
3a5c3e22 | 659 | w->cond_exp = parse_exp_1 (&arg, 0, 0); |
adc36818 PM |
660 | if (*arg) |
661 | error (_("Junk at end of expression")); | |
3a5c3e22 | 662 | w->cond_exp_valid_block = innermost_block; |
adc36818 PM |
663 | } |
664 | else | |
665 | { | |
3a5c3e22 PA |
666 | struct bp_location *loc; |
667 | ||
adc36818 PM |
668 | for (loc = b->loc; loc; loc = loc->next) |
669 | { | |
670 | arg = exp; | |
671 | loc->cond = | |
672 | parse_exp_1 (&arg, block_for_pc (loc->address), 0); | |
673 | if (*arg) | |
674 | error (_("Junk at end of expression")); | |
675 | } | |
676 | } | |
677 | } | |
678 | breakpoints_changed (); | |
8d3788bd | 679 | observer_notify_breakpoint_modified (b); |
adc36818 PM |
680 | } |
681 | ||
c906108c SS |
682 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
683 | ||
684 | static void | |
fba45db2 | 685 | condition_command (char *arg, int from_tty) |
c906108c | 686 | { |
52f0bd74 | 687 | struct breakpoint *b; |
c906108c | 688 | char *p; |
52f0bd74 | 689 | int bnum; |
c906108c SS |
690 | |
691 | if (arg == 0) | |
e2e0b3e5 | 692 | error_no_arg (_("breakpoint number")); |
c906108c SS |
693 | |
694 | p = arg; | |
695 | bnum = get_number (&p); | |
5c44784c | 696 | if (bnum == 0) |
8a3fe4f8 | 697 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
698 | |
699 | ALL_BREAKPOINTS (b) | |
700 | if (b->number == bnum) | |
2f069f6f | 701 | { |
7371cf6d PM |
702 | /* Check if this breakpoint has a Python object assigned to |
703 | it, and if it has a definition of the "stop" | |
704 | method. This method and conditions entered into GDB from | |
705 | the CLI are mutually exclusive. */ | |
706 | if (b->py_bp_object | |
707 | && gdbpy_breakpoint_has_py_cond (b->py_bp_object)) | |
708 | error (_("Cannot set a condition where a Python 'stop' " | |
709 | "method has been defined in the breakpoint.")); | |
2566ad2d | 710 | set_breakpoint_condition (b, p, from_tty); |
2f069f6f JB |
711 | return; |
712 | } | |
c906108c | 713 | |
8a3fe4f8 | 714 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
715 | } |
716 | ||
a7bdde9e VP |
717 | /* Check that COMMAND do not contain commands that are suitable |
718 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
719 | Throw if any such commands is found. */ |
720 | ||
a7bdde9e VP |
721 | static void |
722 | check_no_tracepoint_commands (struct command_line *commands) | |
723 | { | |
724 | struct command_line *c; | |
cc59ec59 | 725 | |
a7bdde9e VP |
726 | for (c = commands; c; c = c->next) |
727 | { | |
728 | int i; | |
729 | ||
730 | if (c->control_type == while_stepping_control) | |
3e43a32a MS |
731 | error (_("The 'while-stepping' command can " |
732 | "only be used for tracepoints")); | |
a7bdde9e VP |
733 | |
734 | for (i = 0; i < c->body_count; ++i) | |
735 | check_no_tracepoint_commands ((c->body_list)[i]); | |
736 | ||
737 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 738 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
739 | command directly. */ |
740 | if (strstr (c->line, "collect ") == c->line) | |
741 | error (_("The 'collect' command can only be used for tracepoints")); | |
742 | ||
51661e93 VP |
743 | if (strstr (c->line, "teval ") == c->line) |
744 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
745 | } |
746 | } | |
747 | ||
d77f58be SS |
748 | /* Encapsulate tests for different types of tracepoints. */ |
749 | ||
d9b3f62e PA |
750 | static int |
751 | is_tracepoint_type (enum bptype type) | |
752 | { | |
753 | return (type == bp_tracepoint | |
754 | || type == bp_fast_tracepoint | |
755 | || type == bp_static_tracepoint); | |
756 | } | |
757 | ||
a7bdde9e | 758 | int |
d77f58be | 759 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 760 | { |
d9b3f62e | 761 | return is_tracepoint_type (b->type); |
a7bdde9e | 762 | } |
d9b3f62e | 763 | |
e5dd4106 | 764 | /* A helper function that validates that COMMANDS are valid for a |
95a42b64 TT |
765 | breakpoint. This function will throw an exception if a problem is |
766 | found. */ | |
48cb2d85 | 767 | |
95a42b64 TT |
768 | static void |
769 | validate_commands_for_breakpoint (struct breakpoint *b, | |
770 | struct command_line *commands) | |
48cb2d85 | 771 | { |
d77f58be | 772 | if (is_tracepoint (b)) |
a7bdde9e | 773 | { |
4a64f543 MS |
774 | /* We need to verify that each top-level element of commands is |
775 | valid for tracepoints, that there's at most one | |
776 | while-stepping element, and that while-stepping's body has | |
777 | valid tracing commands excluding nested while-stepping. */ | |
a7bdde9e VP |
778 | struct command_line *c; |
779 | struct command_line *while_stepping = 0; | |
780 | for (c = commands; c; c = c->next) | |
781 | { | |
a7bdde9e VP |
782 | if (c->control_type == while_stepping_control) |
783 | { | |
784 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
785 | error (_("The 'while-stepping' command " |
786 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 787 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
788 | error (_("The 'while-stepping' command " |
789 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
790 | |
791 | if (while_stepping) | |
3e43a32a MS |
792 | error (_("The 'while-stepping' command " |
793 | "can be used only once")); | |
a7bdde9e VP |
794 | else |
795 | while_stepping = c; | |
796 | } | |
797 | } | |
798 | if (while_stepping) | |
799 | { | |
800 | struct command_line *c2; | |
801 | ||
802 | gdb_assert (while_stepping->body_count == 1); | |
803 | c2 = while_stepping->body_list[0]; | |
804 | for (; c2; c2 = c2->next) | |
805 | { | |
a7bdde9e VP |
806 | if (c2->control_type == while_stepping_control) |
807 | error (_("The 'while-stepping' command cannot be nested")); | |
808 | } | |
809 | } | |
810 | } | |
811 | else | |
812 | { | |
813 | check_no_tracepoint_commands (commands); | |
814 | } | |
95a42b64 TT |
815 | } |
816 | ||
0fb4aa4b PA |
817 | /* Return a vector of all the static tracepoints set at ADDR. The |
818 | caller is responsible for releasing the vector. */ | |
819 | ||
820 | VEC(breakpoint_p) * | |
821 | static_tracepoints_here (CORE_ADDR addr) | |
822 | { | |
823 | struct breakpoint *b; | |
824 | VEC(breakpoint_p) *found = 0; | |
825 | struct bp_location *loc; | |
826 | ||
827 | ALL_BREAKPOINTS (b) | |
828 | if (b->type == bp_static_tracepoint) | |
829 | { | |
830 | for (loc = b->loc; loc; loc = loc->next) | |
831 | if (loc->address == addr) | |
832 | VEC_safe_push(breakpoint_p, found, b); | |
833 | } | |
834 | ||
835 | return found; | |
836 | } | |
837 | ||
95a42b64 | 838 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 839 | validate that only allowed commands are included. */ |
95a42b64 TT |
840 | |
841 | void | |
4a64f543 MS |
842 | breakpoint_set_commands (struct breakpoint *b, |
843 | struct command_line *commands) | |
95a42b64 TT |
844 | { |
845 | validate_commands_for_breakpoint (b, commands); | |
a7bdde9e | 846 | |
9add0f1b TT |
847 | decref_counted_command_line (&b->commands); |
848 | b->commands = alloc_counted_command_line (commands); | |
48cb2d85 | 849 | breakpoints_changed (); |
8d3788bd | 850 | observer_notify_breakpoint_modified (b); |
48cb2d85 VP |
851 | } |
852 | ||
45a43567 TT |
853 | /* Set the internal `silent' flag on the breakpoint. Note that this |
854 | is not the same as the "silent" that may appear in the breakpoint's | |
855 | commands. */ | |
856 | ||
857 | void | |
858 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
859 | { | |
860 | int old_silent = b->silent; | |
861 | ||
862 | b->silent = silent; | |
863 | if (old_silent != silent) | |
8d3788bd | 864 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
865 | } |
866 | ||
867 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
868 | breakpoint work for any thread. */ | |
869 | ||
870 | void | |
871 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
872 | { | |
873 | int old_thread = b->thread; | |
874 | ||
875 | b->thread = thread; | |
876 | if (old_thread != thread) | |
8d3788bd | 877 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
878 | } |
879 | ||
880 | /* Set the task for this breakpoint. If TASK is 0, make the | |
881 | breakpoint work for any task. */ | |
882 | ||
883 | void | |
884 | breakpoint_set_task (struct breakpoint *b, int task) | |
885 | { | |
886 | int old_task = b->task; | |
887 | ||
888 | b->task = task; | |
889 | if (old_task != task) | |
8d3788bd | 890 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
891 | } |
892 | ||
95a42b64 TT |
893 | void |
894 | check_tracepoint_command (char *line, void *closure) | |
a7bdde9e VP |
895 | { |
896 | struct breakpoint *b = closure; | |
cc59ec59 | 897 | |
a7bdde9e VP |
898 | validate_actionline (&line, b); |
899 | } | |
900 | ||
95a42b64 TT |
901 | /* A structure used to pass information through |
902 | map_breakpoint_numbers. */ | |
903 | ||
904 | struct commands_info | |
905 | { | |
906 | /* True if the command was typed at a tty. */ | |
907 | int from_tty; | |
86b17b60 PA |
908 | |
909 | /* The breakpoint range spec. */ | |
910 | char *arg; | |
911 | ||
95a42b64 TT |
912 | /* Non-NULL if the body of the commands are being read from this |
913 | already-parsed command. */ | |
914 | struct command_line *control; | |
86b17b60 | 915 | |
95a42b64 TT |
916 | /* The command lines read from the user, or NULL if they have not |
917 | yet been read. */ | |
918 | struct counted_command_line *cmd; | |
919 | }; | |
920 | ||
921 | /* A callback for map_breakpoint_numbers that sets the commands for | |
922 | commands_command. */ | |
923 | ||
c906108c | 924 | static void |
95a42b64 | 925 | do_map_commands_command (struct breakpoint *b, void *data) |
c906108c | 926 | { |
95a42b64 | 927 | struct commands_info *info = data; |
c906108c | 928 | |
95a42b64 TT |
929 | if (info->cmd == NULL) |
930 | { | |
931 | struct command_line *l; | |
5c44784c | 932 | |
95a42b64 TT |
933 | if (info->control != NULL) |
934 | l = copy_command_lines (info->control->body_list[0]); | |
935 | else | |
86b17b60 PA |
936 | { |
937 | struct cleanup *old_chain; | |
938 | char *str; | |
c5aa993b | 939 | |
3e43a32a MS |
940 | str = xstrprintf (_("Type commands for breakpoint(s) " |
941 | "%s, one per line."), | |
86b17b60 PA |
942 | info->arg); |
943 | ||
944 | old_chain = make_cleanup (xfree, str); | |
945 | ||
946 | l = read_command_lines (str, | |
947 | info->from_tty, 1, | |
d77f58be | 948 | (is_tracepoint (b) |
86b17b60 PA |
949 | ? check_tracepoint_command : 0), |
950 | b); | |
951 | ||
952 | do_cleanups (old_chain); | |
953 | } | |
a7bdde9e | 954 | |
95a42b64 TT |
955 | info->cmd = alloc_counted_command_line (l); |
956 | } | |
957 | ||
958 | /* If a breakpoint was on the list more than once, we don't need to | |
959 | do anything. */ | |
960 | if (b->commands != info->cmd) | |
961 | { | |
962 | validate_commands_for_breakpoint (b, info->cmd->commands); | |
963 | incref_counted_command_line (info->cmd); | |
964 | decref_counted_command_line (&b->commands); | |
965 | b->commands = info->cmd; | |
966 | breakpoints_changed (); | |
8d3788bd | 967 | observer_notify_breakpoint_modified (b); |
c5aa993b | 968 | } |
95a42b64 TT |
969 | } |
970 | ||
971 | static void | |
4a64f543 MS |
972 | commands_command_1 (char *arg, int from_tty, |
973 | struct command_line *control) | |
95a42b64 TT |
974 | { |
975 | struct cleanup *cleanups; | |
976 | struct commands_info info; | |
977 | ||
978 | info.from_tty = from_tty; | |
979 | info.control = control; | |
980 | info.cmd = NULL; | |
981 | /* If we read command lines from the user, then `info' will hold an | |
982 | extra reference to the commands that we must clean up. */ | |
983 | cleanups = make_cleanup_decref_counted_command_line (&info.cmd); | |
984 | ||
985 | if (arg == NULL || !*arg) | |
986 | { | |
86b17b60 | 987 | if (breakpoint_count - prev_breakpoint_count > 1) |
4a64f543 MS |
988 | arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1, |
989 | breakpoint_count); | |
95a42b64 TT |
990 | else if (breakpoint_count > 0) |
991 | arg = xstrprintf ("%d", breakpoint_count); | |
86b17b60 PA |
992 | else |
993 | { | |
994 | /* So that we don't try to free the incoming non-NULL | |
995 | argument in the cleanup below. Mapping breakpoint | |
996 | numbers will fail in this case. */ | |
997 | arg = NULL; | |
998 | } | |
95a42b64 | 999 | } |
9766ced4 SS |
1000 | else |
1001 | /* The command loop has some static state, so we need to preserve | |
1002 | our argument. */ | |
1003 | arg = xstrdup (arg); | |
86b17b60 PA |
1004 | |
1005 | if (arg != NULL) | |
1006 | make_cleanup (xfree, arg); | |
1007 | ||
1008 | info.arg = arg; | |
95a42b64 TT |
1009 | |
1010 | map_breakpoint_numbers (arg, do_map_commands_command, &info); | |
1011 | ||
1012 | if (info.cmd == NULL) | |
1013 | error (_("No breakpoints specified.")); | |
1014 | ||
1015 | do_cleanups (cleanups); | |
1016 | } | |
1017 | ||
1018 | static void | |
1019 | commands_command (char *arg, int from_tty) | |
1020 | { | |
1021 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1022 | } |
40c03ae8 EZ |
1023 | |
1024 | /* Like commands_command, but instead of reading the commands from | |
1025 | input stream, takes them from an already parsed command structure. | |
1026 | ||
1027 | This is used by cli-script.c to DTRT with breakpoint commands | |
1028 | that are part of if and while bodies. */ | |
1029 | enum command_control_type | |
1030 | commands_from_control_command (char *arg, struct command_line *cmd) | |
1031 | { | |
95a42b64 TT |
1032 | commands_command_1 (arg, 0, cmd); |
1033 | return simple_control; | |
40c03ae8 | 1034 | } |
876fa593 JK |
1035 | |
1036 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1037 | ||
1038 | static int | |
1039 | bp_location_has_shadow (struct bp_location *bl) | |
1040 | { | |
1041 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1042 | return 0; | |
1043 | if (!bl->inserted) | |
1044 | return 0; | |
1045 | if (bl->target_info.shadow_len == 0) | |
e5dd4106 | 1046 | /* BL isn't valid, or doesn't shadow memory. */ |
876fa593 JK |
1047 | return 0; |
1048 | return 1; | |
1049 | } | |
1050 | ||
8defab1a | 1051 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1052 | by replacing any memory breakpoints with their shadowed contents. |
1053 | ||
1054 | The range of shadowed area by each bp_location is: | |
35df4500 TJB |
1055 | bl->address - bp_location_placed_address_before_address_max |
1056 | up to bl->address + bp_location_shadow_len_after_address_max | |
876fa593 JK |
1057 | The range we were requested to resolve shadows for is: |
1058 | memaddr ... memaddr + len | |
1059 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 TJB |
1060 | memaddr + len <= (bl->address |
1061 | - bp_location_placed_address_before_address_max) | |
876fa593 | 1062 | and: |
35df4500 | 1063 | bl->address + bp_location_shadow_len_after_address_max <= memaddr */ |
c906108c | 1064 | |
8defab1a | 1065 | void |
f0ba3972 PA |
1066 | breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, |
1067 | const gdb_byte *writebuf_org, | |
1068 | ULONGEST memaddr, LONGEST len) | |
c906108c | 1069 | { |
4a64f543 MS |
1070 | /* Left boundary, right boundary and median element of our binary |
1071 | search. */ | |
876fa593 JK |
1072 | unsigned bc_l, bc_r, bc; |
1073 | ||
4a64f543 MS |
1074 | /* Find BC_L which is a leftmost element which may affect BUF |
1075 | content. It is safe to report lower value but a failure to | |
1076 | report higher one. */ | |
876fa593 JK |
1077 | |
1078 | bc_l = 0; | |
1079 | bc_r = bp_location_count; | |
1080 | while (bc_l + 1 < bc_r) | |
1081 | { | |
35df4500 | 1082 | struct bp_location *bl; |
876fa593 JK |
1083 | |
1084 | bc = (bc_l + bc_r) / 2; | |
35df4500 | 1085 | bl = bp_location[bc]; |
876fa593 | 1086 | |
4a64f543 MS |
1087 | /* Check first BL->ADDRESS will not overflow due to the added |
1088 | constant. Then advance the left boundary only if we are sure | |
1089 | the BC element can in no way affect the BUF content (MEMADDR | |
1090 | to MEMADDR + LEN range). | |
876fa593 | 1091 | |
4a64f543 MS |
1092 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
1093 | offset so that we cannot miss a breakpoint with its shadow | |
1094 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1095 | |
35df4500 TJB |
1096 | if ((bl->address + bp_location_shadow_len_after_address_max |
1097 | >= bl->address) | |
1098 | && (bl->address + bp_location_shadow_len_after_address_max | |
1099 | <= memaddr)) | |
876fa593 JK |
1100 | bc_l = bc; |
1101 | else | |
1102 | bc_r = bc; | |
1103 | } | |
1104 | ||
128070bb PA |
1105 | /* Due to the binary search above, we need to make sure we pick the |
1106 | first location that's at BC_L's address. E.g., if there are | |
1107 | multiple locations at the same address, BC_L may end up pointing | |
1108 | at a duplicate location, and miss the "master"/"inserted" | |
1109 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1110 | B: | |
1111 | ||
1112 | L1@A, L2@A, L3@B, ... | |
1113 | ||
1114 | BC_L could end up pointing at location L2, while the "master" | |
1115 | location could be L1. Since the `loc->inserted' flag is only set | |
1116 | on "master" locations, we'd forget to restore the shadow of L1 | |
1117 | and L2. */ | |
1118 | while (bc_l > 0 | |
1119 | && bp_location[bc_l]->address == bp_location[bc_l - 1]->address) | |
1120 | bc_l--; | |
1121 | ||
876fa593 JK |
1122 | /* Now do full processing of the found relevant range of elements. */ |
1123 | ||
1124 | for (bc = bc_l; bc < bp_location_count; bc++) | |
c5aa993b | 1125 | { |
35df4500 | 1126 | struct bp_location *bl = bp_location[bc]; |
876fa593 JK |
1127 | CORE_ADDR bp_addr = 0; |
1128 | int bp_size = 0; | |
1129 | int bptoffset = 0; | |
1130 | ||
35df4500 TJB |
1131 | /* bp_location array has BL->OWNER always non-NULL. */ |
1132 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1133 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1134 | bl->owner->number); |
ffce0d52 | 1135 | |
e5dd4106 | 1136 | /* Performance optimization: any further element can no longer affect BUF |
876fa593 JK |
1137 | content. */ |
1138 | ||
35df4500 TJB |
1139 | if (bl->address >= bp_location_placed_address_before_address_max |
1140 | && memaddr + len <= (bl->address | |
1141 | - bp_location_placed_address_before_address_max)) | |
876fa593 JK |
1142 | break; |
1143 | ||
35df4500 | 1144 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1145 | continue; |
35df4500 | 1146 | if (!breakpoint_address_match (bl->target_info.placed_address_space, 0, |
6c95b8df PA |
1147 | current_program_space->aspace, 0)) |
1148 | continue; | |
1149 | ||
c5aa993b JM |
1150 | /* Addresses and length of the part of the breakpoint that |
1151 | we need to copy. */ | |
35df4500 TJB |
1152 | bp_addr = bl->target_info.placed_address; |
1153 | bp_size = bl->target_info.shadow_len; | |
8defab1a | 1154 | |
c5aa993b JM |
1155 | if (bp_addr + bp_size <= memaddr) |
1156 | /* The breakpoint is entirely before the chunk of memory we | |
1157 | are reading. */ | |
1158 | continue; | |
8defab1a | 1159 | |
c5aa993b JM |
1160 | if (bp_addr >= memaddr + len) |
1161 | /* The breakpoint is entirely after the chunk of memory we are | |
4a64f543 | 1162 | reading. */ |
c5aa993b | 1163 | continue; |
c5aa993b | 1164 | |
8defab1a DJ |
1165 | /* Offset within shadow_contents. */ |
1166 | if (bp_addr < memaddr) | |
1167 | { | |
1168 | /* Only copy the second part of the breakpoint. */ | |
1169 | bp_size -= memaddr - bp_addr; | |
1170 | bptoffset = memaddr - bp_addr; | |
1171 | bp_addr = memaddr; | |
1172 | } | |
c5aa993b | 1173 | |
8defab1a DJ |
1174 | if (bp_addr + bp_size > memaddr + len) |
1175 | { | |
1176 | /* Only copy the first part of the breakpoint. */ | |
1177 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1178 | } | |
c5aa993b | 1179 | |
f0ba3972 PA |
1180 | if (readbuf != NULL) |
1181 | { | |
1182 | /* Update the read buffer with this inserted breakpoint's | |
1183 | shadow. */ | |
1184 | memcpy (readbuf + bp_addr - memaddr, | |
1185 | bl->target_info.shadow_contents + bptoffset, bp_size); | |
1186 | } | |
1187 | else | |
1188 | { | |
1189 | struct gdbarch *gdbarch = bl->gdbarch; | |
1190 | const unsigned char *bp; | |
1191 | CORE_ADDR placed_address = bl->target_info.placed_address; | |
1192 | unsigned placed_size = bl->target_info.placed_size; | |
1193 | ||
1194 | /* Update the shadow with what we want to write to memory. */ | |
1195 | memcpy (bl->target_info.shadow_contents + bptoffset, | |
1196 | writebuf_org + bp_addr - memaddr, bp_size); | |
1197 | ||
1198 | /* Determine appropriate breakpoint contents and size for this | |
1199 | address. */ | |
1200 | bp = gdbarch_breakpoint_from_pc (gdbarch, &placed_address, &placed_size); | |
1201 | ||
1202 | /* Update the final write buffer with this inserted | |
1203 | breakpoint's INSN. */ | |
1204 | memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size); | |
1205 | } | |
c5aa993b | 1206 | } |
c906108c | 1207 | } |
c906108c | 1208 | \f |
c5aa993b | 1209 | |
60e1c644 PA |
1210 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1211 | ||
a5606eee | 1212 | static int |
d77f58be | 1213 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1214 | { |
1215 | return (bpt->type == bp_hardware_watchpoint | |
1216 | || bpt->type == bp_read_watchpoint | |
1217 | || bpt->type == bp_access_watchpoint); | |
1218 | } | |
7270d8f2 | 1219 | |
60e1c644 PA |
1220 | /* Return true if BPT is of any watchpoint kind, hardware or |
1221 | software. */ | |
1222 | ||
3a5c3e22 | 1223 | int |
d77f58be | 1224 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1225 | { |
1226 | return (is_hardware_watchpoint (bpt) | |
1227 | || bpt->type == bp_watchpoint); | |
1228 | } | |
1229 | ||
3a5c3e22 PA |
1230 | /* Returns true if the current thread and its running state are safe |
1231 | to evaluate or update watchpoint B. Watchpoints on local | |
1232 | expressions need to be evaluated in the context of the thread that | |
1233 | was current when the watchpoint was created, and, that thread needs | |
1234 | to be stopped to be able to select the correct frame context. | |
1235 | Watchpoints on global expressions can be evaluated on any thread, | |
1236 | and in any state. It is presently left to the target allowing | |
1237 | memory accesses when threads are running. */ | |
f6bc2008 PA |
1238 | |
1239 | static int | |
3a5c3e22 | 1240 | watchpoint_in_thread_scope (struct watchpoint *b) |
f6bc2008 | 1241 | { |
d0d8b0c6 JK |
1242 | return (b->base.pspace == current_program_space |
1243 | && (ptid_equal (b->watchpoint_thread, null_ptid) | |
1244 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1245 | && !is_executing (inferior_ptid)))); | |
f6bc2008 PA |
1246 | } |
1247 | ||
d0fb5eae JK |
1248 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
1249 | associated bp_watchpoint_scope breakpoint. */ | |
1250 | ||
1251 | static void | |
3a5c3e22 | 1252 | watchpoint_del_at_next_stop (struct watchpoint *w) |
d0fb5eae | 1253 | { |
3a5c3e22 | 1254 | struct breakpoint *b = &w->base; |
d0fb5eae JK |
1255 | |
1256 | if (b->related_breakpoint != b) | |
1257 | { | |
1258 | gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope); | |
1259 | gdb_assert (b->related_breakpoint->related_breakpoint == b); | |
1260 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1261 | b->related_breakpoint->related_breakpoint = b->related_breakpoint; | |
1262 | b->related_breakpoint = b; | |
1263 | } | |
1264 | b->disposition = disp_del_at_next_stop; | |
1265 | } | |
1266 | ||
567e1b4e JB |
1267 | /* Assuming that B is a watchpoint: |
1268 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1269 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1270 | - Evaluate the condition if there is one, and store the result |
1271 | in b->loc->cond. | |
a5606eee VP |
1272 | - Update the list of values that must be watched in B->loc. |
1273 | ||
4a64f543 MS |
1274 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1275 | nothing. If this is local watchpoint that is out of scope, delete | |
1276 | it. | |
1277 | ||
1278 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1279 | removed + inserted on each stop here. Normal breakpoints must | |
1280 | never be removed because they might be missed by a running thread | |
1281 | when debugging in non-stop mode. On the other hand, hardware | |
1282 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1283 | to each LWP since they are stored in each LWP's hardware debug | |
1284 | registers. Therefore, such LWP must be stopped first in order to | |
1285 | be able to modify its hardware watchpoints. | |
1286 | ||
1287 | Hardware watchpoints must be reset exactly once after being | |
1288 | presented to the user. It cannot be done sooner, because it would | |
1289 | reset the data used to present the watchpoint hit to the user. And | |
1290 | it must not be done later because it could display the same single | |
1291 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1292 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1293 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1294 | not user-visible - its hit is suppressed if the memory content has | |
1295 | not changed. | |
1296 | ||
1297 | The following constraints influence the location where we can reset | |
1298 | hardware watchpoints: | |
1299 | ||
1300 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1301 | called several times when GDB stops. | |
1302 | ||
1303 | [linux] | |
1304 | * Multiple hardware watchpoints can be hit at the same time, | |
1305 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1306 | hit at a time as the reason for stopping, and all the other hits | |
1307 | are presented later, one after the other, each time the user | |
1308 | requests the execution to be resumed. Execution is not resumed | |
1309 | for the threads still having pending hit event stored in | |
1310 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1311 | the inferior on the first stop the thread hit event is kept being | |
1312 | reported from its cached value by linux_nat_stopped_data_address | |
1313 | until the real thread resume happens after the watchpoint gets | |
1314 | presented and thus its LWP_INFO->STATUS gets reset. | |
1315 | ||
1316 | Therefore the hardware watchpoint hit can get safely reset on the | |
1317 | watchpoint removal from inferior. */ | |
a79d3c27 | 1318 | |
b40ce68a | 1319 | static void |
3a5c3e22 | 1320 | update_watchpoint (struct watchpoint *b, int reparse) |
7270d8f2 | 1321 | { |
a5606eee | 1322 | int within_current_scope; |
a5606eee | 1323 | struct frame_id saved_frame_id; |
66076460 | 1324 | int frame_saved; |
a5606eee | 1325 | |
f6bc2008 PA |
1326 | /* If this is a local watchpoint, we only want to check if the |
1327 | watchpoint frame is in scope if the current thread is the thread | |
1328 | that was used to create the watchpoint. */ | |
1329 | if (!watchpoint_in_thread_scope (b)) | |
1330 | return; | |
1331 | ||
3a5c3e22 | 1332 | if (b->base.disposition == disp_del_at_next_stop) |
a5606eee VP |
1333 | return; |
1334 | ||
66076460 | 1335 | frame_saved = 0; |
a5606eee VP |
1336 | |
1337 | /* Determine if the watchpoint is within scope. */ | |
1338 | if (b->exp_valid_block == NULL) | |
1339 | within_current_scope = 1; | |
1340 | else | |
1341 | { | |
b5db5dfc UW |
1342 | struct frame_info *fi = get_current_frame (); |
1343 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1344 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1345 | ||
1346 | /* If we're in a function epilogue, unwinding may not work | |
1347 | properly, so do not attempt to recreate locations at this | |
1348 | point. See similar comments in watchpoint_check. */ | |
1349 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) | |
1350 | return; | |
66076460 DJ |
1351 | |
1352 | /* Save the current frame's ID so we can restore it after | |
1353 | evaluating the watchpoint expression on its own frame. */ | |
1354 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1355 | took a frame parameter, so that we didn't have to change the | |
1356 | selected frame. */ | |
1357 | frame_saved = 1; | |
1358 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1359 | ||
a5606eee VP |
1360 | fi = frame_find_by_id (b->watchpoint_frame); |
1361 | within_current_scope = (fi != NULL); | |
1362 | if (within_current_scope) | |
1363 | select_frame (fi); | |
1364 | } | |
1365 | ||
b5db5dfc UW |
1366 | /* We don't free locations. They are stored in the bp_location array |
1367 | and update_global_location_list will eventually delete them and | |
1368 | remove breakpoints if needed. */ | |
3a5c3e22 | 1369 | b->base.loc = NULL; |
b5db5dfc | 1370 | |
a5606eee VP |
1371 | if (within_current_scope && reparse) |
1372 | { | |
1373 | char *s; | |
d63d0675 | 1374 | |
a5606eee VP |
1375 | if (b->exp) |
1376 | { | |
1377 | xfree (b->exp); | |
1378 | b->exp = NULL; | |
1379 | } | |
d63d0675 | 1380 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
a5606eee VP |
1381 | b->exp = parse_exp_1 (&s, b->exp_valid_block, 0); |
1382 | /* If the meaning of expression itself changed, the old value is | |
1383 | no longer relevant. We don't want to report a watchpoint hit | |
1384 | to the user when the old value and the new value may actually | |
1385 | be completely different objects. */ | |
1386 | value_free (b->val); | |
fa4727a6 DJ |
1387 | b->val = NULL; |
1388 | b->val_valid = 0; | |
60e1c644 PA |
1389 | |
1390 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1391 | expression is stored in the breakpoint object, not in the | |
1392 | locations (re)created below. */ | |
3a5c3e22 | 1393 | if (b->base.cond_string != NULL) |
60e1c644 PA |
1394 | { |
1395 | if (b->cond_exp != NULL) | |
1396 | { | |
1397 | xfree (b->cond_exp); | |
1398 | b->cond_exp = NULL; | |
1399 | } | |
1400 | ||
3a5c3e22 | 1401 | s = b->base.cond_string; |
60e1c644 PA |
1402 | b->cond_exp = parse_exp_1 (&s, b->cond_exp_valid_block, 0); |
1403 | } | |
a5606eee | 1404 | } |
a5606eee VP |
1405 | |
1406 | /* If we failed to parse the expression, for example because | |
1407 | it refers to a global variable in a not-yet-loaded shared library, | |
1408 | don't try to insert watchpoint. We don't automatically delete | |
1409 | such watchpoint, though, since failure to parse expression | |
1410 | is different from out-of-scope watchpoint. */ | |
2d134ed3 PA |
1411 | if ( !target_has_execution) |
1412 | { | |
1413 | /* Without execution, memory can't change. No use to try and | |
1414 | set watchpoint locations. The watchpoint will be reset when | |
1415 | the target gains execution, through breakpoint_re_set. */ | |
1416 | } | |
1417 | else if (within_current_scope && b->exp) | |
a5606eee | 1418 | { |
0cf6dd15 | 1419 | int pc = 0; |
fa4727a6 | 1420 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1421 | struct program_space *frame_pspace; |
a5606eee | 1422 | |
0cf6dd15 | 1423 | fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain); |
a5606eee | 1424 | |
a5606eee VP |
1425 | /* Avoid setting b->val if it's already set. The meaning of |
1426 | b->val is 'the last value' user saw, and we should update | |
1427 | it only if we reported that last value to user. As it | |
9c06b0b4 TJB |
1428 | happens, the code that reports it updates b->val directly. |
1429 | We don't keep track of the memory value for masked | |
1430 | watchpoints. */ | |
3a5c3e22 | 1431 | if (!b->val_valid && !is_masked_watchpoint (&b->base)) |
fa4727a6 DJ |
1432 | { |
1433 | b->val = v; | |
1434 | b->val_valid = 1; | |
1435 | } | |
a5606eee | 1436 | |
2d134ed3 PA |
1437 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1438 | ||
a5606eee | 1439 | /* Look at each value on the value chain. */ |
9fa40276 | 1440 | for (v = val_chain; v; v = value_next (v)) |
a5606eee VP |
1441 | { |
1442 | /* If it's a memory location, and GDB actually needed | |
1443 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1444 | must watch it. If the first value returned is |
1445 | still lazy, that means an error occurred reading it; | |
1446 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1447 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1448 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1449 | { |
1450 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1451 | |
a5606eee VP |
1452 | /* We only watch structs and arrays if user asked |
1453 | for it explicitly, never if they just happen to | |
1454 | appear in the middle of some value chain. */ | |
fa4727a6 | 1455 | if (v == result |
a5606eee VP |
1456 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1457 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1458 | { | |
1459 | CORE_ADDR addr; | |
1460 | int len, type; | |
1461 | struct bp_location *loc, **tmp; | |
1462 | ||
42ae5230 | 1463 | addr = value_address (v); |
a5606eee VP |
1464 | len = TYPE_LENGTH (value_type (v)); |
1465 | type = hw_write; | |
3a5c3e22 | 1466 | if (b->base.type == bp_read_watchpoint) |
a5606eee | 1467 | type = hw_read; |
3a5c3e22 | 1468 | else if (b->base.type == bp_access_watchpoint) |
a5606eee | 1469 | type = hw_access; |
3a5c3e22 PA |
1470 | |
1471 | loc = allocate_bp_location (&b->base); | |
1472 | for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next)) | |
a5606eee VP |
1473 | ; |
1474 | *tmp = loc; | |
a6d9a66e | 1475 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1476 | |
1477 | loc->pspace = frame_pspace; | |
a5606eee VP |
1478 | loc->address = addr; |
1479 | loc->length = len; | |
1480 | loc->watchpoint_type = type; | |
1481 | } | |
1482 | } | |
9fa40276 TJB |
1483 | } |
1484 | ||
1485 | /* Change the type of breakpoint between hardware assisted or | |
1486 | an ordinary watchpoint depending on the hardware support | |
1487 | and free hardware slots. REPARSE is set when the inferior | |
1488 | is started. */ | |
a9634178 | 1489 | if (reparse) |
9fa40276 | 1490 | { |
e09342b5 | 1491 | int reg_cnt; |
9fa40276 TJB |
1492 | enum bp_loc_type loc_type; |
1493 | struct bp_location *bl; | |
a5606eee | 1494 | |
a9634178 | 1495 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
e09342b5 TJB |
1496 | |
1497 | if (reg_cnt) | |
9fa40276 TJB |
1498 | { |
1499 | int i, target_resources_ok, other_type_used; | |
a1398e0c | 1500 | enum bptype type; |
9fa40276 | 1501 | |
a9634178 TJB |
1502 | /* Use an exact watchpoint when there's only one memory region to be |
1503 | watched, and only one debug register is needed to watch it. */ | |
1504 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
1505 | ||
9fa40276 | 1506 | /* We need to determine how many resources are already |
e09342b5 TJB |
1507 | used for all other hardware watchpoints plus this one |
1508 | to see if we still have enough resources to also fit | |
a1398e0c PA |
1509 | this watchpoint in as well. */ |
1510 | ||
1511 | /* If this is a software watchpoint, we try to turn it | |
1512 | to a hardware one -- count resources as if B was of | |
1513 | hardware watchpoint type. */ | |
1514 | type = b->base.type; | |
1515 | if (type == bp_watchpoint) | |
1516 | type = bp_hardware_watchpoint; | |
1517 | ||
1518 | /* This watchpoint may or may not have been placed on | |
1519 | the list yet at this point (it won't be in the list | |
1520 | if we're trying to create it for the first time, | |
1521 | through watch_command), so always account for it | |
1522 | manually. */ | |
1523 | ||
1524 | /* Count resources used by all watchpoints except B. */ | |
1525 | i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used); | |
1526 | ||
1527 | /* Add in the resources needed for B. */ | |
1528 | i += hw_watchpoint_use_count (&b->base); | |
1529 | ||
1530 | target_resources_ok | |
1531 | = target_can_use_hardware_watchpoint (type, i, other_type_used); | |
e09342b5 | 1532 | if (target_resources_ok <= 0) |
a9634178 | 1533 | { |
3a5c3e22 | 1534 | int sw_mode = b->base.ops->works_in_software_mode (&b->base); |
9c06b0b4 TJB |
1535 | |
1536 | if (target_resources_ok == 0 && !sw_mode) | |
a9634178 TJB |
1537 | error (_("Target does not support this type of " |
1538 | "hardware watchpoint.")); | |
9c06b0b4 TJB |
1539 | else if (target_resources_ok < 0 && !sw_mode) |
1540 | error (_("There are not enough available hardware " | |
1541 | "resources for this watchpoint.")); | |
a1398e0c PA |
1542 | |
1543 | /* Downgrade to software watchpoint. */ | |
1544 | b->base.type = bp_watchpoint; | |
1545 | } | |
1546 | else | |
1547 | { | |
1548 | /* If this was a software watchpoint, we've just | |
1549 | found we have enough resources to turn it to a | |
1550 | hardware watchpoint. Otherwise, this is a | |
1551 | nop. */ | |
1552 | b->base.type = type; | |
a9634178 | 1553 | } |
9fa40276 | 1554 | } |
3a5c3e22 | 1555 | else if (!b->base.ops->works_in_software_mode (&b->base)) |
a9634178 TJB |
1556 | error (_("Expression cannot be implemented with " |
1557 | "read/access watchpoint.")); | |
9fa40276 | 1558 | else |
3a5c3e22 | 1559 | b->base.type = bp_watchpoint; |
9fa40276 | 1560 | |
3a5c3e22 | 1561 | loc_type = (b->base.type == bp_watchpoint? bp_loc_other |
9fa40276 | 1562 | : bp_loc_hardware_watchpoint); |
3a5c3e22 | 1563 | for (bl = b->base.loc; bl; bl = bl->next) |
9fa40276 TJB |
1564 | bl->loc_type = loc_type; |
1565 | } | |
1566 | ||
1567 | for (v = val_chain; v; v = next) | |
1568 | { | |
a5606eee VP |
1569 | next = value_next (v); |
1570 | if (v != b->val) | |
1571 | value_free (v); | |
1572 | } | |
1573 | ||
c7437ca6 PA |
1574 | /* If a software watchpoint is not watching any memory, then the |
1575 | above left it without any location set up. But, | |
1576 | bpstat_stop_status requires a location to be able to report | |
1577 | stops, so make sure there's at least a dummy one. */ | |
3a5c3e22 | 1578 | if (b->base.type == bp_watchpoint && b->base.loc == NULL) |
c7437ca6 | 1579 | { |
3a5c3e22 PA |
1580 | struct breakpoint *base = &b->base; |
1581 | base->loc = allocate_bp_location (base); | |
1582 | base->loc->pspace = frame_pspace; | |
1583 | base->loc->address = -1; | |
1584 | base->loc->length = -1; | |
1585 | base->loc->watchpoint_type = -1; | |
c7437ca6 | 1586 | } |
a5606eee VP |
1587 | } |
1588 | else if (!within_current_scope) | |
7270d8f2 | 1589 | { |
ac74f770 MS |
1590 | printf_filtered (_("\ |
1591 | Watchpoint %d deleted because the program has left the block\n\ | |
1592 | in which its expression is valid.\n"), | |
3a5c3e22 | 1593 | b->base.number); |
d0fb5eae | 1594 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 1595 | } |
a5606eee VP |
1596 | |
1597 | /* Restore the selected frame. */ | |
66076460 DJ |
1598 | if (frame_saved) |
1599 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
1600 | } |
1601 | ||
a5606eee | 1602 | |
74960c60 | 1603 | /* Returns 1 iff breakpoint location should be |
1e4d1764 YQ |
1604 | inserted in the inferior. We don't differentiate the type of BL's owner |
1605 | (breakpoint vs. tracepoint), although insert_location in tracepoint's | |
1606 | breakpoint_ops is not defined, because in insert_bp_location, | |
1607 | tracepoint's insert_location will not be called. */ | |
74960c60 | 1608 | static int |
35df4500 | 1609 | should_be_inserted (struct bp_location *bl) |
74960c60 | 1610 | { |
35df4500 | 1611 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
1612 | return 0; |
1613 | ||
35df4500 | 1614 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
1615 | return 0; |
1616 | ||
35df4500 | 1617 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
1618 | return 0; |
1619 | ||
f8eba3c6 TT |
1620 | if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup) |
1621 | return 0; | |
1622 | ||
56710373 PA |
1623 | /* This is set for example, when we're attached to the parent of a |
1624 | vfork, and have detached from the child. The child is running | |
1625 | free, and we expect it to do an exec or exit, at which point the | |
1626 | OS makes the parent schedulable again (and the target reports | |
1627 | that the vfork is done). Until the child is done with the shared | |
1628 | memory region, do not insert breakpoints in the parent, otherwise | |
1629 | the child could still trip on the parent's breakpoints. Since | |
1630 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 1631 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
1632 | return 0; |
1633 | ||
74960c60 VP |
1634 | return 1; |
1635 | } | |
1636 | ||
934709f0 PW |
1637 | /* Same as should_be_inserted but does the check assuming |
1638 | that the location is not duplicated. */ | |
1639 | ||
1640 | static int | |
1641 | unduplicated_should_be_inserted (struct bp_location *bl) | |
1642 | { | |
1643 | int result; | |
1644 | const int save_duplicate = bl->duplicate; | |
1645 | ||
1646 | bl->duplicate = 0; | |
1647 | result = should_be_inserted (bl); | |
1648 | bl->duplicate = save_duplicate; | |
1649 | return result; | |
1650 | } | |
1651 | ||
35df4500 TJB |
1652 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
1653 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
3fbb6ffa | 1654 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
c30eee59 TJB |
1655 | Returns 0 for success, 1 if the bp_location type is not supported or |
1656 | -1 for failure. | |
879bfdc2 | 1657 | |
4a64f543 MS |
1658 | NOTE drow/2003-09-09: This routine could be broken down to an |
1659 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 1660 | static int |
35df4500 | 1661 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 1662 | struct ui_file *tmp_error_stream, |
3fbb6ffa | 1663 | int *disabled_breaks, |
26bb91f3 | 1664 | int *hw_breakpoint_error) |
879bfdc2 DJ |
1665 | { |
1666 | int val = 0; | |
1667 | ||
35df4500 | 1668 | if (!should_be_inserted (bl) || bl->inserted) |
879bfdc2 DJ |
1669 | return 0; |
1670 | ||
8181d85f | 1671 | /* Initialize the target-specific information. */ |
35df4500 TJB |
1672 | memset (&bl->target_info, 0, sizeof (bl->target_info)); |
1673 | bl->target_info.placed_address = bl->address; | |
1674 | bl->target_info.placed_address_space = bl->pspace->aspace; | |
f1310107 | 1675 | bl->target_info.length = bl->length; |
8181d85f | 1676 | |
35df4500 TJB |
1677 | if (bl->loc_type == bp_loc_software_breakpoint |
1678 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 1679 | { |
35df4500 | 1680 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
1681 | { |
1682 | /* If the explicitly specified breakpoint type | |
1683 | is not hardware breakpoint, check the memory map to see | |
1684 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 1685 | |
765dc015 VP |
1686 | Two important cases are: |
1687 | - location type is not hardware breakpoint, memory | |
1688 | is readonly. We change the type of the location to | |
1689 | hardware breakpoint. | |
4a64f543 MS |
1690 | - location type is hardware breakpoint, memory is |
1691 | read-write. This means we've previously made the | |
1692 | location hardware one, but then the memory map changed, | |
1693 | so we undo. | |
765dc015 | 1694 | |
4a64f543 MS |
1695 | When breakpoints are removed, remove_breakpoints will use |
1696 | location types we've just set here, the only possible | |
1697 | problem is that memory map has changed during running | |
1698 | program, but it's not going to work anyway with current | |
1699 | gdb. */ | |
765dc015 | 1700 | struct mem_region *mr |
35df4500 | 1701 | = lookup_mem_region (bl->target_info.placed_address); |
765dc015 VP |
1702 | |
1703 | if (mr) | |
1704 | { | |
1705 | if (automatic_hardware_breakpoints) | |
1706 | { | |
765dc015 VP |
1707 | enum bp_loc_type new_type; |
1708 | ||
1709 | if (mr->attrib.mode != MEM_RW) | |
1710 | new_type = bp_loc_hardware_breakpoint; | |
1711 | else | |
1712 | new_type = bp_loc_software_breakpoint; | |
1713 | ||
35df4500 | 1714 | if (new_type != bl->loc_type) |
765dc015 VP |
1715 | { |
1716 | static int said = 0; | |
cc59ec59 | 1717 | |
35df4500 | 1718 | bl->loc_type = new_type; |
765dc015 VP |
1719 | if (!said) |
1720 | { | |
3e43a32a MS |
1721 | fprintf_filtered (gdb_stdout, |
1722 | _("Note: automatically using " | |
1723 | "hardware breakpoints for " | |
1724 | "read-only addresses.\n")); | |
765dc015 VP |
1725 | said = 1; |
1726 | } | |
1727 | } | |
1728 | } | |
35df4500 | 1729 | else if (bl->loc_type == bp_loc_software_breakpoint |
765dc015 | 1730 | && mr->attrib.mode != MEM_RW) |
3e43a32a MS |
1731 | warning (_("cannot set software breakpoint " |
1732 | "at readonly address %s"), | |
35df4500 | 1733 | paddress (bl->gdbarch, bl->address)); |
765dc015 VP |
1734 | } |
1735 | } | |
1736 | ||
879bfdc2 DJ |
1737 | /* First check to see if we have to handle an overlay. */ |
1738 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
1739 | || bl->section == NULL |
1740 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
1741 | { |
1742 | /* No overlay handling: just set the breakpoint. */ | |
1743 | ||
348d480f | 1744 | val = bl->owner->ops->insert_location (bl); |
879bfdc2 DJ |
1745 | } |
1746 | else | |
1747 | { | |
4a64f543 | 1748 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
1749 | Shall we set a breakpoint at the LMA? */ |
1750 | if (!overlay_events_enabled) | |
1751 | { | |
1752 | /* Yes -- overlay event support is not active, | |
1753 | so we must try to set a breakpoint at the LMA. | |
1754 | This will not work for a hardware breakpoint. */ | |
35df4500 | 1755 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 1756 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 1757 | bl->owner->number); |
879bfdc2 DJ |
1758 | else |
1759 | { | |
35df4500 TJB |
1760 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
1761 | bl->section); | |
879bfdc2 | 1762 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 TJB |
1763 | bl->overlay_target_info = bl->target_info; |
1764 | bl->overlay_target_info.placed_address = addr; | |
1765 | val = target_insert_breakpoint (bl->gdbarch, | |
1766 | &bl->overlay_target_info); | |
879bfdc2 | 1767 | if (val != 0) |
99361f52 | 1768 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
1769 | "Overlay breakpoint %d " |
1770 | "failed: in ROM?\n", | |
35df4500 | 1771 | bl->owner->number); |
879bfdc2 DJ |
1772 | } |
1773 | } | |
1774 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 1775 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
1776 | { |
1777 | /* Yes. This overlay section is mapped into memory. */ | |
348d480f | 1778 | val = bl->owner->ops->insert_location (bl); |
879bfdc2 DJ |
1779 | } |
1780 | else | |
1781 | { | |
1782 | /* No. This breakpoint will not be inserted. | |
1783 | No error, but do not mark the bp as 'inserted'. */ | |
1784 | return 0; | |
1785 | } | |
1786 | } | |
1787 | ||
1788 | if (val) | |
1789 | { | |
1790 | /* Can't set the breakpoint. */ | |
35df4500 | 1791 | if (solib_name_from_address (bl->pspace, bl->address)) |
879bfdc2 | 1792 | { |
4a64f543 | 1793 | /* See also: disable_breakpoints_in_shlibs. */ |
879bfdc2 | 1794 | val = 0; |
35df4500 | 1795 | bl->shlib_disabled = 1; |
8d3788bd | 1796 | observer_notify_breakpoint_modified (bl->owner); |
3fbb6ffa TJB |
1797 | if (!*disabled_breaks) |
1798 | { | |
1799 | fprintf_unfiltered (tmp_error_stream, | |
1800 | "Cannot insert breakpoint %d.\n", | |
1801 | bl->owner->number); | |
1802 | fprintf_unfiltered (tmp_error_stream, | |
1803 | "Temporarily disabling shared " | |
1804 | "library breakpoints:\n"); | |
1805 | } | |
1806 | *disabled_breaks = 1; | |
879bfdc2 | 1807 | fprintf_unfiltered (tmp_error_stream, |
35df4500 | 1808 | "breakpoint #%d\n", bl->owner->number); |
879bfdc2 DJ |
1809 | } |
1810 | else | |
879bfdc2 | 1811 | { |
35df4500 | 1812 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 DJ |
1813 | { |
1814 | *hw_breakpoint_error = 1; | |
3e43a32a MS |
1815 | fprintf_unfiltered (tmp_error_stream, |
1816 | "Cannot insert hardware " | |
1817 | "breakpoint %d.\n", | |
35df4500 | 1818 | bl->owner->number); |
879bfdc2 DJ |
1819 | } |
1820 | else | |
1821 | { | |
1822 | fprintf_unfiltered (tmp_error_stream, | |
1823 | "Cannot insert breakpoint %d.\n", | |
35df4500 | 1824 | bl->owner->number); |
879bfdc2 DJ |
1825 | fprintf_filtered (tmp_error_stream, |
1826 | "Error accessing memory address "); | |
35df4500 | 1827 | fputs_filtered (paddress (bl->gdbarch, bl->address), |
5af949e3 | 1828 | tmp_error_stream); |
879bfdc2 DJ |
1829 | fprintf_filtered (tmp_error_stream, ": %s.\n", |
1830 | safe_strerror (val)); | |
1831 | } | |
1832 | ||
1833 | } | |
1834 | } | |
1835 | else | |
35df4500 | 1836 | bl->inserted = 1; |
879bfdc2 DJ |
1837 | |
1838 | return val; | |
1839 | } | |
1840 | ||
35df4500 | 1841 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 1842 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 1843 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 1844 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 1845 | { |
77b06cd7 TJB |
1846 | gdb_assert (bl->owner->ops != NULL |
1847 | && bl->owner->ops->insert_location != NULL); | |
1848 | ||
1849 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
1850 | |
1851 | /* If trying to set a read-watchpoint, and it turns out it's not | |
1852 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 1853 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
1854 | { |
1855 | struct bp_location *loc, **loc_temp; | |
1856 | ||
1857 | /* But don't try to insert it, if there's already another | |
1858 | hw_access location that would be considered a duplicate | |
1859 | of this one. */ | |
1860 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 1861 | if (loc != bl |
85d721b8 | 1862 | && loc->watchpoint_type == hw_access |
35df4500 | 1863 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 1864 | { |
35df4500 TJB |
1865 | bl->duplicate = 1; |
1866 | bl->inserted = 1; | |
1867 | bl->target_info = loc->target_info; | |
1868 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
1869 | val = 0; |
1870 | break; | |
1871 | } | |
1872 | ||
1873 | if (val == 1) | |
1874 | { | |
77b06cd7 TJB |
1875 | bl->watchpoint_type = hw_access; |
1876 | val = bl->owner->ops->insert_location (bl); | |
1877 | ||
1878 | if (val) | |
1879 | /* Back to the original value. */ | |
1880 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
1881 | } |
1882 | } | |
1883 | ||
35df4500 | 1884 | bl->inserted = (val == 0); |
879bfdc2 DJ |
1885 | } |
1886 | ||
35df4500 | 1887 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 1888 | { |
77b06cd7 TJB |
1889 | gdb_assert (bl->owner->ops != NULL |
1890 | && bl->owner->ops->insert_location != NULL); | |
1891 | ||
1892 | val = bl->owner->ops->insert_location (bl); | |
1893 | if (val) | |
1894 | { | |
1895 | bl->owner->enable_state = bp_disabled; | |
1896 | ||
1897 | if (val == 1) | |
1898 | warning (_("\ | |
1899 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
1900 | of catchpoint."), bl->owner->number); | |
1901 | else | |
1902 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
1903 | } | |
1904 | ||
1905 | bl->inserted = (val == 0); | |
1640b821 DJ |
1906 | |
1907 | /* We've already printed an error message if there was a problem | |
1908 | inserting this catchpoint, and we've disabled the catchpoint, | |
1909 | so just return success. */ | |
1910 | return 0; | |
879bfdc2 DJ |
1911 | } |
1912 | ||
1913 | return 0; | |
1914 | } | |
1915 | ||
6c95b8df PA |
1916 | /* This function is called when program space PSPACE is about to be |
1917 | deleted. It takes care of updating breakpoints to not reference | |
1918 | PSPACE anymore. */ | |
1919 | ||
1920 | void | |
1921 | breakpoint_program_space_exit (struct program_space *pspace) | |
1922 | { | |
1923 | struct breakpoint *b, *b_temp; | |
876fa593 | 1924 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
1925 | |
1926 | /* Remove any breakpoint that was set through this program space. */ | |
1927 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
1928 | { | |
1929 | if (b->pspace == pspace) | |
1930 | delete_breakpoint (b); | |
1931 | } | |
1932 | ||
1933 | /* Breakpoints set through other program spaces could have locations | |
1934 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 1935 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
1936 | { |
1937 | struct bp_location *tmp; | |
1938 | ||
1939 | if (loc->pspace == pspace) | |
1940 | { | |
2bdf28a0 | 1941 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
1942 | if (loc->owner->loc == loc) |
1943 | loc->owner->loc = loc->next; | |
1944 | else | |
1945 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
1946 | if (tmp->next == loc) | |
1947 | { | |
1948 | tmp->next = loc->next; | |
1949 | break; | |
1950 | } | |
1951 | } | |
1952 | } | |
1953 | ||
1954 | /* Now update the global location list to permanently delete the | |
1955 | removed locations above. */ | |
1956 | update_global_location_list (0); | |
1957 | } | |
1958 | ||
74960c60 VP |
1959 | /* Make sure all breakpoints are inserted in inferior. |
1960 | Throws exception on any error. | |
1961 | A breakpoint that is already inserted won't be inserted | |
1962 | again, so calling this function twice is safe. */ | |
1963 | void | |
1964 | insert_breakpoints (void) | |
1965 | { | |
1966 | struct breakpoint *bpt; | |
1967 | ||
1968 | ALL_BREAKPOINTS (bpt) | |
1969 | if (is_hardware_watchpoint (bpt)) | |
3a5c3e22 PA |
1970 | { |
1971 | struct watchpoint *w = (struct watchpoint *) bpt; | |
1972 | ||
1973 | update_watchpoint (w, 0 /* don't reparse. */); | |
1974 | } | |
74960c60 | 1975 | |
b60e7edf | 1976 | update_global_location_list (1); |
74960c60 | 1977 | |
c35b1492 PA |
1978 | /* update_global_location_list does not insert breakpoints when |
1979 | always_inserted_mode is not enabled. Explicitly insert them | |
1980 | now. */ | |
1981 | if (!breakpoints_always_inserted_mode ()) | |
74960c60 VP |
1982 | insert_breakpoint_locations (); |
1983 | } | |
1984 | ||
c30eee59 | 1985 | /* Used when starting or continuing the program. */ |
c906108c | 1986 | |
74960c60 VP |
1987 | static void |
1988 | insert_breakpoint_locations (void) | |
c906108c | 1989 | { |
a5606eee | 1990 | struct breakpoint *bpt; |
35df4500 | 1991 | struct bp_location *bl, **blp_tmp; |
eacd795a | 1992 | int error_flag = 0; |
c906108c | 1993 | int val = 0; |
3fbb6ffa | 1994 | int disabled_breaks = 0; |
81d0cc19 | 1995 | int hw_breakpoint_error = 0; |
c906108c | 1996 | |
81d0cc19 | 1997 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 1998 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 1999 | |
81d0cc19 GS |
2000 | /* Explicitly mark the warning -- this will only be printed if |
2001 | there was an error. */ | |
2002 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
2003 | |
2004 | save_current_space_and_thread (); | |
2005 | ||
35df4500 | 2006 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 2007 | { |
35df4500 | 2008 | if (!should_be_inserted (bl) || bl->inserted) |
879bfdc2 DJ |
2009 | continue; |
2010 | ||
4a64f543 MS |
2011 | /* There is no point inserting thread-specific breakpoints if |
2012 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
2013 | has BL->OWNER always non-NULL. */ | |
35df4500 TJB |
2014 | if (bl->owner->thread != -1 |
2015 | && !valid_thread_id (bl->owner->thread)) | |
f365de73 AS |
2016 | continue; |
2017 | ||
35df4500 | 2018 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
2019 | |
2020 | /* For targets that support global breakpoints, there's no need | |
2021 | to select an inferior to insert breakpoint to. In fact, even | |
2022 | if we aren't attached to any process yet, we should still | |
2023 | insert breakpoints. */ | |
2024 | if (!gdbarch_has_global_breakpoints (target_gdbarch) | |
2025 | && ptid_equal (inferior_ptid, null_ptid)) | |
2026 | continue; | |
2027 | ||
3fbb6ffa TJB |
2028 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, |
2029 | &hw_breakpoint_error); | |
879bfdc2 | 2030 | if (val) |
eacd795a | 2031 | error_flag = val; |
879bfdc2 | 2032 | } |
c906108c | 2033 | |
4a64f543 MS |
2034 | /* If we failed to insert all locations of a watchpoint, remove |
2035 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
2036 | ALL_BREAKPOINTS (bpt) |
2037 | { | |
2038 | int some_failed = 0; | |
2039 | struct bp_location *loc; | |
2040 | ||
2041 | if (!is_hardware_watchpoint (bpt)) | |
2042 | continue; | |
2043 | ||
d6b74ac4 | 2044 | if (!breakpoint_enabled (bpt)) |
a5606eee | 2045 | continue; |
74960c60 VP |
2046 | |
2047 | if (bpt->disposition == disp_del_at_next_stop) | |
2048 | continue; | |
a5606eee VP |
2049 | |
2050 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 2051 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
2052 | { |
2053 | some_failed = 1; | |
2054 | break; | |
2055 | } | |
2056 | if (some_failed) | |
2057 | { | |
2058 | for (loc = bpt->loc; loc; loc = loc->next) | |
2059 | if (loc->inserted) | |
2060 | remove_breakpoint (loc, mark_uninserted); | |
2061 | ||
2062 | hw_breakpoint_error = 1; | |
2063 | fprintf_unfiltered (tmp_error_stream, | |
2064 | "Could not insert hardware watchpoint %d.\n", | |
2065 | bpt->number); | |
eacd795a | 2066 | error_flag = -1; |
a5606eee VP |
2067 | } |
2068 | } | |
2069 | ||
eacd795a | 2070 | if (error_flag) |
81d0cc19 GS |
2071 | { |
2072 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
2073 | message about possibly exhausted resources. */ | |
879bfdc2 | 2074 | if (hw_breakpoint_error) |
81d0cc19 | 2075 | { |
c6510018 MS |
2076 | fprintf_unfiltered (tmp_error_stream, |
2077 | "Could not insert hardware breakpoints:\n\ | |
2078 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 2079 | } |
81d0cc19 GS |
2080 | target_terminal_ours_for_output (); |
2081 | error_stream (tmp_error_stream); | |
2082 | } | |
f7545552 TT |
2083 | |
2084 | do_cleanups (cleanups); | |
c906108c SS |
2085 | } |
2086 | ||
c30eee59 TJB |
2087 | /* Used when the program stops. |
2088 | Returns zero if successful, or non-zero if there was a problem | |
2089 | removing a breakpoint location. */ | |
2090 | ||
c906108c | 2091 | int |
fba45db2 | 2092 | remove_breakpoints (void) |
c906108c | 2093 | { |
35df4500 | 2094 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 2095 | int val = 0; |
c906108c | 2096 | |
35df4500 | 2097 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2098 | { |
1e4d1764 | 2099 | if (bl->inserted && !is_tracepoint (bl->owner)) |
35df4500 | 2100 | val |= remove_breakpoint (bl, mark_uninserted); |
c5aa993b | 2101 | } |
3a1bae8e | 2102 | return val; |
c906108c SS |
2103 | } |
2104 | ||
6c95b8df PA |
2105 | /* Remove breakpoints of process PID. */ |
2106 | ||
2107 | int | |
2108 | remove_breakpoints_pid (int pid) | |
2109 | { | |
35df4500 | 2110 | struct bp_location *bl, **blp_tmp; |
6c95b8df PA |
2111 | int val; |
2112 | struct inferior *inf = find_inferior_pid (pid); | |
2113 | ||
35df4500 | 2114 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 2115 | { |
35df4500 | 2116 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2117 | continue; |
2118 | ||
35df4500 | 2119 | if (bl->inserted) |
6c95b8df | 2120 | { |
35df4500 | 2121 | val = remove_breakpoint (bl, mark_uninserted); |
6c95b8df PA |
2122 | if (val != 0) |
2123 | return val; | |
2124 | } | |
2125 | } | |
2126 | return 0; | |
2127 | } | |
2128 | ||
c906108c | 2129 | int |
fba45db2 | 2130 | reattach_breakpoints (int pid) |
c906108c | 2131 | { |
6c95b8df | 2132 | struct cleanup *old_chain; |
35df4500 | 2133 | struct bp_location *bl, **blp_tmp; |
c906108c | 2134 | int val; |
86b887df | 2135 | struct ui_file *tmp_error_stream; |
3fbb6ffa | 2136 | int dummy1 = 0, dummy2 = 0; |
6c95b8df PA |
2137 | struct inferior *inf; |
2138 | struct thread_info *tp; | |
2139 | ||
2140 | tp = any_live_thread_of_process (pid); | |
2141 | if (tp == NULL) | |
2142 | return 1; | |
2143 | ||
2144 | inf = find_inferior_pid (pid); | |
2145 | old_chain = save_inferior_ptid (); | |
2146 | ||
2147 | inferior_ptid = tp->ptid; | |
a4954f26 | 2148 | |
86b887df | 2149 | tmp_error_stream = mem_fileopen (); |
a4954f26 | 2150 | make_cleanup_ui_file_delete (tmp_error_stream); |
c906108c | 2151 | |
35df4500 | 2152 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2153 | { |
35df4500 | 2154 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2155 | continue; |
2156 | ||
35df4500 | 2157 | if (bl->inserted) |
c5aa993b | 2158 | { |
35df4500 | 2159 | bl->inserted = 0; |
3fbb6ffa | 2160 | val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2); |
c5aa993b JM |
2161 | if (val != 0) |
2162 | { | |
ce696e05 | 2163 | do_cleanups (old_chain); |
c5aa993b JM |
2164 | return val; |
2165 | } | |
2166 | } | |
2167 | } | |
ce696e05 | 2168 | do_cleanups (old_chain); |
c906108c SS |
2169 | return 0; |
2170 | } | |
2171 | ||
e58b0e63 PA |
2172 | static int internal_breakpoint_number = -1; |
2173 | ||
84f4c1fe PM |
2174 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
2175 | If INTERNAL is non-zero, the breakpoint number will be populated | |
2176 | from internal_breakpoint_number and that variable decremented. | |
e5dd4106 | 2177 | Otherwise the breakpoint number will be populated from |
84f4c1fe PM |
2178 | breakpoint_count and that value incremented. Internal breakpoints |
2179 | do not set the internal var bpnum. */ | |
2180 | static void | |
2181 | set_breakpoint_number (int internal, struct breakpoint *b) | |
2182 | { | |
2183 | if (internal) | |
2184 | b->number = internal_breakpoint_number--; | |
2185 | else | |
2186 | { | |
2187 | set_breakpoint_count (breakpoint_count + 1); | |
2188 | b->number = breakpoint_count; | |
2189 | } | |
2190 | } | |
2191 | ||
e62c965a | 2192 | static struct breakpoint * |
a6d9a66e | 2193 | create_internal_breakpoint (struct gdbarch *gdbarch, |
06edf0c0 | 2194 | CORE_ADDR address, enum bptype type, |
c0a91b2b | 2195 | const struct breakpoint_ops *ops) |
e62c965a | 2196 | { |
e62c965a PP |
2197 | struct symtab_and_line sal; |
2198 | struct breakpoint *b; | |
2199 | ||
4a64f543 | 2200 | init_sal (&sal); /* Initialize to zeroes. */ |
e62c965a PP |
2201 | |
2202 | sal.pc = address; | |
2203 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 2204 | sal.pspace = current_program_space; |
e62c965a | 2205 | |
06edf0c0 | 2206 | b = set_raw_breakpoint (gdbarch, sal, type, ops); |
e62c965a PP |
2207 | b->number = internal_breakpoint_number--; |
2208 | b->disposition = disp_donttouch; | |
2209 | ||
2210 | return b; | |
2211 | } | |
2212 | ||
17450429 PP |
2213 | static const char *const longjmp_names[] = |
2214 | { | |
2215 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
2216 | }; | |
2217 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
2218 | ||
2219 | /* Per-objfile data private to breakpoint.c. */ | |
2220 | struct breakpoint_objfile_data | |
2221 | { | |
2222 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
2223 | struct minimal_symbol *overlay_msym; | |
2224 | ||
2225 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
2226 | struct minimal_symbol *longjmp_msym[NUM_LONGJMP_NAMES]; | |
2227 | ||
2228 | /* Minimal symbol for "std::terminate()" (if any). */ | |
2229 | struct minimal_symbol *terminate_msym; | |
2230 | ||
2231 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
2232 | struct minimal_symbol *exception_msym; | |
2233 | }; | |
2234 | ||
2235 | static const struct objfile_data *breakpoint_objfile_key; | |
2236 | ||
2237 | /* Minimal symbol not found sentinel. */ | |
2238 | static struct minimal_symbol msym_not_found; | |
2239 | ||
2240 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
2241 | ||
2242 | static int | |
2243 | msym_not_found_p (const struct minimal_symbol *msym) | |
2244 | { | |
2245 | return msym == &msym_not_found; | |
2246 | } | |
2247 | ||
2248 | /* Return per-objfile data needed by breakpoint.c. | |
2249 | Allocate the data if necessary. */ | |
2250 | ||
2251 | static struct breakpoint_objfile_data * | |
2252 | get_breakpoint_objfile_data (struct objfile *objfile) | |
2253 | { | |
2254 | struct breakpoint_objfile_data *bp_objfile_data; | |
2255 | ||
2256 | bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key); | |
2257 | if (bp_objfile_data == NULL) | |
2258 | { | |
2259 | bp_objfile_data = obstack_alloc (&objfile->objfile_obstack, | |
2260 | sizeof (*bp_objfile_data)); | |
2261 | ||
2262 | memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); | |
2263 | set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); | |
2264 | } | |
2265 | return bp_objfile_data; | |
2266 | } | |
2267 | ||
e62c965a | 2268 | static void |
af02033e | 2269 | create_overlay_event_breakpoint (void) |
e62c965a | 2270 | { |
69de3c6a | 2271 | struct objfile *objfile; |
af02033e | 2272 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 2273 | |
69de3c6a PP |
2274 | ALL_OBJFILES (objfile) |
2275 | { | |
2276 | struct breakpoint *b; | |
17450429 PP |
2277 | struct breakpoint_objfile_data *bp_objfile_data; |
2278 | CORE_ADDR addr; | |
69de3c6a | 2279 | |
17450429 PP |
2280 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
2281 | ||
2282 | if (msym_not_found_p (bp_objfile_data->overlay_msym)) | |
2283 | continue; | |
2284 | ||
2285 | if (bp_objfile_data->overlay_msym == NULL) | |
2286 | { | |
2287 | struct minimal_symbol *m; | |
2288 | ||
2289 | m = lookup_minimal_symbol_text (func_name, objfile); | |
2290 | if (m == NULL) | |
2291 | { | |
2292 | /* Avoid future lookups in this objfile. */ | |
2293 | bp_objfile_data->overlay_msym = &msym_not_found; | |
2294 | continue; | |
2295 | } | |
2296 | bp_objfile_data->overlay_msym = m; | |
2297 | } | |
e62c965a | 2298 | |
17450429 PP |
2299 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
2300 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, | |
06edf0c0 PA |
2301 | bp_overlay_event, |
2302 | &internal_breakpoint_ops); | |
69de3c6a | 2303 | b->addr_string = xstrdup (func_name); |
e62c965a | 2304 | |
69de3c6a PP |
2305 | if (overlay_debugging == ovly_auto) |
2306 | { | |
2307 | b->enable_state = bp_enabled; | |
2308 | overlay_events_enabled = 1; | |
2309 | } | |
2310 | else | |
2311 | { | |
2312 | b->enable_state = bp_disabled; | |
2313 | overlay_events_enabled = 0; | |
2314 | } | |
e62c965a PP |
2315 | } |
2316 | update_global_location_list (1); | |
2317 | } | |
2318 | ||
0fd8e87f | 2319 | static void |
af02033e | 2320 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 2321 | { |
6c95b8df | 2322 | struct program_space *pspace; |
6c95b8df PA |
2323 | struct cleanup *old_chain; |
2324 | ||
2325 | old_chain = save_current_program_space (); | |
0fd8e87f | 2326 | |
6c95b8df | 2327 | ALL_PSPACES (pspace) |
af02033e PP |
2328 | { |
2329 | struct objfile *objfile; | |
2330 | ||
2331 | set_current_program_space (pspace); | |
2332 | ||
2333 | ALL_OBJFILES (objfile) | |
0fd8e87f | 2334 | { |
af02033e PP |
2335 | int i; |
2336 | struct gdbarch *gdbarch; | |
17450429 | 2337 | struct breakpoint_objfile_data *bp_objfile_data; |
0fd8e87f | 2338 | |
af02033e PP |
2339 | gdbarch = get_objfile_arch (objfile); |
2340 | if (!gdbarch_get_longjmp_target_p (gdbarch)) | |
0fd8e87f UW |
2341 | continue; |
2342 | ||
17450429 PP |
2343 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
2344 | ||
2345 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) | |
af02033e PP |
2346 | { |
2347 | struct breakpoint *b; | |
af02033e | 2348 | const char *func_name; |
17450429 | 2349 | CORE_ADDR addr; |
6c95b8df | 2350 | |
17450429 | 2351 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i])) |
af02033e | 2352 | continue; |
0fd8e87f | 2353 | |
17450429 PP |
2354 | func_name = longjmp_names[i]; |
2355 | if (bp_objfile_data->longjmp_msym[i] == NULL) | |
2356 | { | |
2357 | struct minimal_symbol *m; | |
2358 | ||
2359 | m = lookup_minimal_symbol_text (func_name, objfile); | |
2360 | if (m == NULL) | |
2361 | { | |
2362 | /* Prevent future lookups in this objfile. */ | |
2363 | bp_objfile_data->longjmp_msym[i] = &msym_not_found; | |
2364 | continue; | |
2365 | } | |
2366 | bp_objfile_data->longjmp_msym[i] = m; | |
2367 | } | |
2368 | ||
2369 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); | |
06edf0c0 PA |
2370 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, |
2371 | &internal_breakpoint_ops); | |
af02033e PP |
2372 | b->addr_string = xstrdup (func_name); |
2373 | b->enable_state = bp_disabled; | |
2374 | } | |
0fd8e87f | 2375 | } |
af02033e | 2376 | } |
0fd8e87f | 2377 | update_global_location_list (1); |
6c95b8df PA |
2378 | |
2379 | do_cleanups (old_chain); | |
0fd8e87f UW |
2380 | } |
2381 | ||
af02033e | 2382 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 2383 | static void |
af02033e | 2384 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
2385 | { |
2386 | struct program_space *pspace; | |
aa7d318d | 2387 | struct cleanup *old_chain; |
af02033e | 2388 | const char *const func_name = "std::terminate()"; |
aa7d318d TT |
2389 | |
2390 | old_chain = save_current_program_space (); | |
2391 | ||
2392 | ALL_PSPACES (pspace) | |
17450429 PP |
2393 | { |
2394 | struct objfile *objfile; | |
2395 | CORE_ADDR addr; | |
2396 | ||
2397 | set_current_program_space (pspace); | |
2398 | ||
aa7d318d TT |
2399 | ALL_OBJFILES (objfile) |
2400 | { | |
2401 | struct breakpoint *b; | |
17450429 | 2402 | struct breakpoint_objfile_data *bp_objfile_data; |
aa7d318d | 2403 | |
17450429 | 2404 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 2405 | |
17450429 PP |
2406 | if (msym_not_found_p (bp_objfile_data->terminate_msym)) |
2407 | continue; | |
2408 | ||
2409 | if (bp_objfile_data->terminate_msym == NULL) | |
2410 | { | |
2411 | struct minimal_symbol *m; | |
2412 | ||
2413 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
2414 | if (m == NULL || (MSYMBOL_TYPE (m) != mst_text | |
2415 | && MSYMBOL_TYPE (m) != mst_file_text)) | |
2416 | { | |
2417 | /* Prevent future lookups in this objfile. */ | |
2418 | bp_objfile_data->terminate_msym = &msym_not_found; | |
2419 | continue; | |
2420 | } | |
2421 | bp_objfile_data->terminate_msym = m; | |
2422 | } | |
aa7d318d | 2423 | |
17450429 PP |
2424 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
2425 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, | |
06edf0c0 PA |
2426 | bp_std_terminate_master, |
2427 | &internal_breakpoint_ops); | |
aa7d318d TT |
2428 | b->addr_string = xstrdup (func_name); |
2429 | b->enable_state = bp_disabled; | |
2430 | } | |
17450429 PP |
2431 | } |
2432 | ||
aa7d318d TT |
2433 | update_global_location_list (1); |
2434 | ||
2435 | do_cleanups (old_chain); | |
2436 | } | |
2437 | ||
186c406b TT |
2438 | /* Install a master breakpoint on the unwinder's debug hook. */ |
2439 | ||
2440 | void | |
2441 | create_exception_master_breakpoint (void) | |
2442 | { | |
2443 | struct objfile *objfile; | |
17450429 | 2444 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b TT |
2445 | |
2446 | ALL_OBJFILES (objfile) | |
2447 | { | |
17450429 PP |
2448 | struct breakpoint *b; |
2449 | struct gdbarch *gdbarch; | |
2450 | struct breakpoint_objfile_data *bp_objfile_data; | |
2451 | CORE_ADDR addr; | |
2452 | ||
2453 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
2454 | ||
2455 | if (msym_not_found_p (bp_objfile_data->exception_msym)) | |
2456 | continue; | |
2457 | ||
2458 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 2459 | |
17450429 | 2460 | if (bp_objfile_data->exception_msym == NULL) |
186c406b | 2461 | { |
17450429 | 2462 | struct minimal_symbol *debug_hook; |
186c406b | 2463 | |
17450429 PP |
2464 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
2465 | if (debug_hook == NULL) | |
2466 | { | |
2467 | bp_objfile_data->exception_msym = &msym_not_found; | |
2468 | continue; | |
2469 | } | |
2470 | ||
2471 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 2472 | } |
17450429 PP |
2473 | |
2474 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); | |
2475 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, | |
2476 | ¤t_target); | |
06edf0c0 PA |
2477 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
2478 | &internal_breakpoint_ops); | |
17450429 PP |
2479 | b->addr_string = xstrdup (func_name); |
2480 | b->enable_state = bp_disabled; | |
186c406b TT |
2481 | } |
2482 | ||
2483 | update_global_location_list (1); | |
2484 | } | |
2485 | ||
c906108c | 2486 | void |
fba45db2 | 2487 | update_breakpoints_after_exec (void) |
c906108c | 2488 | { |
35df4500 | 2489 | struct breakpoint *b, *b_tmp; |
876fa593 | 2490 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 2491 | |
25b22b0a PA |
2492 | /* We're about to delete breakpoints from GDB's lists. If the |
2493 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
2494 | writing the breakpoints' "shadow contents" back into memory. The | |
2495 | "shadow contents" are NOT valid after an exec, so GDB should not | |
2496 | do that. Instead, the target is responsible from marking | |
2497 | breakpoints out as soon as it detects an exec. We don't do that | |
2498 | here instead, because there may be other attempts to delete | |
2499 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 2500 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
2501 | if (bploc->pspace == current_program_space) |
2502 | gdb_assert (!bploc->inserted); | |
c906108c | 2503 | |
35df4500 | 2504 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 2505 | { |
6c95b8df PA |
2506 | if (b->pspace != current_program_space) |
2507 | continue; | |
2508 | ||
4a64f543 | 2509 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
2510 | if (b->type == bp_shlib_event) |
2511 | { | |
2512 | delete_breakpoint (b); | |
2513 | continue; | |
2514 | } | |
c906108c | 2515 | |
4a64f543 | 2516 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
2517 | if (b->type == bp_jit_event) |
2518 | { | |
2519 | delete_breakpoint (b); | |
2520 | continue; | |
2521 | } | |
2522 | ||
1900040c | 2523 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
2524 | as must overlay event and longjmp master breakpoints. */ |
2525 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
2526 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
2527 | || b->type == bp_exception_master) | |
c4093a6a JM |
2528 | { |
2529 | delete_breakpoint (b); | |
2530 | continue; | |
2531 | } | |
2532 | ||
4a64f543 | 2533 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2c03e5be | 2534 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
c5aa993b JM |
2535 | { |
2536 | delete_breakpoint (b); | |
2537 | continue; | |
2538 | } | |
2539 | ||
611c83ae PA |
2540 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
2541 | after an exec. */ | |
186c406b TT |
2542 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
2543 | || b->type == bp_exception || b->type == bp_exception_resume) | |
611c83ae PA |
2544 | { |
2545 | delete_breakpoint (b); | |
2546 | continue; | |
2547 | } | |
2548 | ||
ce78b96d JB |
2549 | if (b->type == bp_catchpoint) |
2550 | { | |
2551 | /* For now, none of the bp_catchpoint breakpoints need to | |
2552 | do anything at this point. In the future, if some of | |
2553 | the catchpoints need to something, we will need to add | |
2554 | a new method, and call this method from here. */ | |
2555 | continue; | |
2556 | } | |
2557 | ||
c5aa993b JM |
2558 | /* bp_finish is a special case. The only way we ought to be able |
2559 | to see one of these when an exec() has happened, is if the user | |
2560 | caught a vfork, and then said "finish". Ordinarily a finish just | |
2561 | carries them to the call-site of the current callee, by setting | |
2562 | a temporary bp there and resuming. But in this case, the finish | |
2563 | will carry them entirely through the vfork & exec. | |
2564 | ||
2565 | We don't want to allow a bp_finish to remain inserted now. But | |
2566 | we can't safely delete it, 'cause finish_command has a handle to | |
2567 | the bp on a bpstat, and will later want to delete it. There's a | |
2568 | chance (and I've seen it happen) that if we delete the bp_finish | |
2569 | here, that its storage will get reused by the time finish_command | |
2570 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
2571 | We really must allow finish_command to delete a bp_finish. | |
2572 | ||
e5dd4106 | 2573 | In the absence of a general solution for the "how do we know |
53a5351d JM |
2574 | it's safe to delete something others may have handles to?" |
2575 | problem, what we'll do here is just uninsert the bp_finish, and | |
2576 | let finish_command delete it. | |
2577 | ||
2578 | (We know the bp_finish is "doomed" in the sense that it's | |
2579 | momentary, and will be deleted as soon as finish_command sees | |
2580 | the inferior stopped. So it doesn't matter that the bp's | |
2581 | address is probably bogus in the new a.out, unlike e.g., the | |
2582 | solib breakpoints.) */ | |
c5aa993b | 2583 | |
c5aa993b JM |
2584 | if (b->type == bp_finish) |
2585 | { | |
2586 | continue; | |
2587 | } | |
2588 | ||
2589 | /* Without a symbolic address, we have little hope of the | |
2590 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 2591 | a.out. */ |
c5aa993b JM |
2592 | if (b->addr_string == NULL) |
2593 | { | |
2594 | delete_breakpoint (b); | |
2595 | continue; | |
2596 | } | |
c5aa993b | 2597 | } |
1900040c | 2598 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
af02033e PP |
2599 | create_overlay_event_breakpoint (); |
2600 | create_longjmp_master_breakpoint (); | |
2601 | create_std_terminate_master_breakpoint (); | |
186c406b | 2602 | create_exception_master_breakpoint (); |
c906108c SS |
2603 | } |
2604 | ||
2605 | int | |
fba45db2 | 2606 | detach_breakpoints (int pid) |
c906108c | 2607 | { |
35df4500 | 2608 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 2609 | int val = 0; |
ce696e05 | 2610 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 2611 | struct inferior *inf = current_inferior (); |
c5aa993b | 2612 | |
39f77062 | 2613 | if (pid == PIDGET (inferior_ptid)) |
8a3fe4f8 | 2614 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 2615 | |
6c95b8df | 2616 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
ce696e05 | 2617 | inferior_ptid = pid_to_ptid (pid); |
35df4500 | 2618 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2619 | { |
35df4500 | 2620 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2621 | continue; |
2622 | ||
35df4500 TJB |
2623 | if (bl->inserted) |
2624 | val |= remove_breakpoint_1 (bl, mark_inserted); | |
c5aa993b | 2625 | } |
d03285ec UW |
2626 | |
2627 | /* Detach single-step breakpoints as well. */ | |
2628 | detach_single_step_breakpoints (); | |
2629 | ||
ce696e05 | 2630 | do_cleanups (old_chain); |
3a1bae8e | 2631 | return val; |
c906108c SS |
2632 | } |
2633 | ||
35df4500 | 2634 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
2635 | Note that this is used to detach breakpoints from a child fork. |
2636 | When we get here, the child isn't in the inferior list, and neither | |
2637 | do we have objects to represent its address space --- we should | |
35df4500 | 2638 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 2639 | |
c906108c | 2640 | static int |
35df4500 | 2641 | remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is) |
c906108c SS |
2642 | { |
2643 | int val; | |
c5aa993b | 2644 | |
35df4500 TJB |
2645 | /* BL is never in moribund_locations by our callers. */ |
2646 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 2647 | |
35df4500 | 2648 | if (bl->owner->enable_state == bp_permanent) |
c2c6d25f JM |
2649 | /* Permanent breakpoints cannot be inserted or removed. */ |
2650 | return 0; | |
2651 | ||
74960c60 VP |
2652 | /* The type of none suggests that owner is actually deleted. |
2653 | This should not ever happen. */ | |
35df4500 | 2654 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 2655 | |
35df4500 TJB |
2656 | if (bl->loc_type == bp_loc_software_breakpoint |
2657 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 2658 | { |
c02f5703 MS |
2659 | /* "Normal" instruction breakpoint: either the standard |
2660 | trap-instruction bp (bp_breakpoint), or a | |
2661 | bp_hardware_breakpoint. */ | |
2662 | ||
2663 | /* First check to see if we have to handle an overlay. */ | |
2664 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2665 | || bl->section == NULL |
2666 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
2667 | { |
2668 | /* No overlay handling: just remove the breakpoint. */ | |
348d480f | 2669 | val = bl->owner->ops->remove_location (bl); |
c02f5703 | 2670 | } |
c906108c SS |
2671 | else |
2672 | { | |
4a64f543 | 2673 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
2674 | Did we set a breakpoint at the LMA? */ |
2675 | if (!overlay_events_enabled) | |
2676 | { | |
2677 | /* Yes -- overlay event support is not active, so we | |
2678 | should have set a breakpoint at the LMA. Remove it. | |
2679 | */ | |
c02f5703 MS |
2680 | /* Ignore any failures: if the LMA is in ROM, we will |
2681 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
2682 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
2683 | target_remove_hw_breakpoint (bl->gdbarch, | |
2684 | &bl->overlay_target_info); | |
c02f5703 | 2685 | else |
35df4500 TJB |
2686 | target_remove_breakpoint (bl->gdbarch, |
2687 | &bl->overlay_target_info); | |
c02f5703 MS |
2688 | } |
2689 | /* Did we set a breakpoint at the VMA? | |
2690 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 2691 | if (bl->inserted) |
c906108c | 2692 | { |
c02f5703 MS |
2693 | /* Yes -- remove it. Previously we did not bother to |
2694 | remove the breakpoint if the section had been | |
2695 | unmapped, but let's not rely on that being safe. We | |
2696 | don't know what the overlay manager might do. */ | |
aa67235e UW |
2697 | |
2698 | /* However, we should remove *software* breakpoints only | |
2699 | if the section is still mapped, or else we overwrite | |
2700 | wrong code with the saved shadow contents. */ | |
348d480f PA |
2701 | if (bl->loc_type == bp_loc_hardware_breakpoint |
2702 | || section_is_mapped (bl->section)) | |
2703 | val = bl->owner->ops->remove_location (bl); | |
aa67235e UW |
2704 | else |
2705 | val = 0; | |
c906108c | 2706 | } |
c02f5703 MS |
2707 | else |
2708 | { | |
2709 | /* No -- not inserted, so no need to remove. No error. */ | |
2710 | val = 0; | |
2711 | } | |
c906108c | 2712 | } |
879d1e6b UW |
2713 | |
2714 | /* In some cases, we might not be able to remove a breakpoint | |
2715 | in a shared library that has already been removed, but we | |
2716 | have not yet processed the shlib unload event. */ | |
35df4500 | 2717 | if (val && solib_name_from_address (bl->pspace, bl->address)) |
879d1e6b UW |
2718 | val = 0; |
2719 | ||
c906108c SS |
2720 | if (val) |
2721 | return val; | |
35df4500 | 2722 | bl->inserted = (is == mark_inserted); |
c906108c | 2723 | } |
35df4500 | 2724 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 2725 | { |
77b06cd7 TJB |
2726 | gdb_assert (bl->owner->ops != NULL |
2727 | && bl->owner->ops->remove_location != NULL); | |
2728 | ||
35df4500 | 2729 | bl->inserted = (is == mark_inserted); |
77b06cd7 | 2730 | bl->owner->ops->remove_location (bl); |
2e70b7b9 | 2731 | |
c906108c | 2732 | /* Failure to remove any of the hardware watchpoints comes here. */ |
35df4500 | 2733 | if ((is == mark_uninserted) && (bl->inserted)) |
8a3fe4f8 | 2734 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 2735 | bl->owner->number); |
c906108c | 2736 | } |
35df4500 TJB |
2737 | else if (bl->owner->type == bp_catchpoint |
2738 | && breakpoint_enabled (bl->owner) | |
2739 | && !bl->duplicate) | |
ce78b96d | 2740 | { |
77b06cd7 TJB |
2741 | gdb_assert (bl->owner->ops != NULL |
2742 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 2743 | |
77b06cd7 | 2744 | val = bl->owner->ops->remove_location (bl); |
ce78b96d JB |
2745 | if (val) |
2746 | return val; | |
77b06cd7 | 2747 | |
35df4500 | 2748 | bl->inserted = (is == mark_inserted); |
ce78b96d | 2749 | } |
c906108c SS |
2750 | |
2751 | return 0; | |
2752 | } | |
2753 | ||
6c95b8df | 2754 | static int |
35df4500 | 2755 | remove_breakpoint (struct bp_location *bl, insertion_state_t is) |
6c95b8df PA |
2756 | { |
2757 | int ret; | |
2758 | struct cleanup *old_chain; | |
2759 | ||
35df4500 TJB |
2760 | /* BL is never in moribund_locations by our callers. */ |
2761 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 2762 | |
35df4500 | 2763 | if (bl->owner->enable_state == bp_permanent) |
6c95b8df PA |
2764 | /* Permanent breakpoints cannot be inserted or removed. */ |
2765 | return 0; | |
2766 | ||
2767 | /* The type of none suggests that owner is actually deleted. | |
2768 | This should not ever happen. */ | |
35df4500 | 2769 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df PA |
2770 | |
2771 | old_chain = save_current_space_and_thread (); | |
2772 | ||
35df4500 | 2773 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 2774 | |
35df4500 | 2775 | ret = remove_breakpoint_1 (bl, is); |
6c95b8df PA |
2776 | |
2777 | do_cleanups (old_chain); | |
2778 | return ret; | |
2779 | } | |
2780 | ||
c906108c SS |
2781 | /* Clear the "inserted" flag in all breakpoints. */ |
2782 | ||
25b22b0a | 2783 | void |
fba45db2 | 2784 | mark_breakpoints_out (void) |
c906108c | 2785 | { |
35df4500 | 2786 | struct bp_location *bl, **blp_tmp; |
c906108c | 2787 | |
35df4500 TJB |
2788 | ALL_BP_LOCATIONS (bl, blp_tmp) |
2789 | if (bl->pspace == current_program_space) | |
2790 | bl->inserted = 0; | |
c906108c SS |
2791 | } |
2792 | ||
53a5351d JM |
2793 | /* Clear the "inserted" flag in all breakpoints and delete any |
2794 | breakpoints which should go away between runs of the program. | |
c906108c SS |
2795 | |
2796 | Plus other such housekeeping that has to be done for breakpoints | |
2797 | between runs. | |
2798 | ||
53a5351d JM |
2799 | Note: this function gets called at the end of a run (by |
2800 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 2801 | init_wait_for_inferior). */ |
c906108c SS |
2802 | |
2803 | ||
2804 | ||
2805 | void | |
fba45db2 | 2806 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 2807 | { |
35df4500 TJB |
2808 | struct breakpoint *b, *b_tmp; |
2809 | struct bp_location *bl, **blp_tmp; | |
1c5cfe86 | 2810 | int ix; |
6c95b8df | 2811 | struct program_space *pspace = current_program_space; |
c906108c | 2812 | |
50c71eaf PA |
2813 | /* If breakpoint locations are shared across processes, then there's |
2814 | nothing to do. */ | |
2567c7d9 | 2815 | if (gdbarch_has_global_breakpoints (target_gdbarch)) |
50c71eaf PA |
2816 | return; |
2817 | ||
35df4500 | 2818 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 2819 | { |
35df4500 TJB |
2820 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
2821 | if (bl->pspace == pspace | |
2822 | && bl->owner->enable_state != bp_permanent) | |
2823 | bl->inserted = 0; | |
6c95b8df | 2824 | } |
075f6582 | 2825 | |
35df4500 | 2826 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 2827 | { |
6c95b8df PA |
2828 | if (b->loc && b->loc->pspace != pspace) |
2829 | continue; | |
2830 | ||
c5aa993b JM |
2831 | switch (b->type) |
2832 | { | |
2833 | case bp_call_dummy: | |
c906108c | 2834 | |
c5aa993b | 2835 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
2836 | cause problems when the inferior is rerun, so we better get |
2837 | rid of it. */ | |
2838 | ||
2839 | case bp_watchpoint_scope: | |
2840 | ||
2841 | /* Also get rid of scope breakpoints. */ | |
2842 | ||
2843 | case bp_shlib_event: | |
2844 | ||
2845 | /* Also remove solib event breakpoints. Their addresses may | |
2846 | have changed since the last time we ran the program. | |
2847 | Actually we may now be debugging against different target; | |
2848 | and so the solib backend that installed this breakpoint may | |
2849 | not be used in by the target. E.g., | |
2850 | ||
2851 | (gdb) file prog-linux | |
2852 | (gdb) run # native linux target | |
2853 | ... | |
2854 | (gdb) kill | |
2855 | (gdb) file prog-win.exe | |
2856 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
2857 | */ | |
c906108c | 2858 | |
c5aa993b JM |
2859 | delete_breakpoint (b); |
2860 | break; | |
c906108c | 2861 | |
c5aa993b JM |
2862 | case bp_watchpoint: |
2863 | case bp_hardware_watchpoint: | |
2864 | case bp_read_watchpoint: | |
2865 | case bp_access_watchpoint: | |
3a5c3e22 PA |
2866 | { |
2867 | struct watchpoint *w = (struct watchpoint *) b; | |
c906108c | 2868 | |
3a5c3e22 PA |
2869 | /* Likewise for watchpoints on local expressions. */ |
2870 | if (w->exp_valid_block != NULL) | |
2871 | delete_breakpoint (b); | |
2872 | else if (context == inf_starting) | |
2873 | { | |
2874 | /* Reset val field to force reread of starting value in | |
2875 | insert_breakpoints. */ | |
2876 | if (w->val) | |
2877 | value_free (w->val); | |
2878 | w->val = NULL; | |
2879 | w->val_valid = 0; | |
c860120c | 2880 | } |
3a5c3e22 | 2881 | } |
c5aa993b JM |
2882 | break; |
2883 | default: | |
c5aa993b JM |
2884 | break; |
2885 | } | |
2886 | } | |
1c5cfe86 PA |
2887 | |
2888 | /* Get rid of the moribund locations. */ | |
35df4500 TJB |
2889 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
2890 | decref_bp_location (&bl); | |
1c5cfe86 | 2891 | VEC_free (bp_location_p, moribund_locations); |
c906108c SS |
2892 | } |
2893 | ||
6c95b8df PA |
2894 | /* These functions concern about actual breakpoints inserted in the |
2895 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
2896 | we need to hop over the bkpt --- so we check for address space | |
2897 | match, not program space. */ | |
2898 | ||
c2c6d25f JM |
2899 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
2900 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
2901 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
2902 | permanent breakpoint. | |
2903 | - When continuing from a location with an ordinary breakpoint, we | |
2904 | actually single step once before calling insert_breakpoints. | |
e5dd4106 | 2905 | - When continuing from a location with a permanent breakpoint, we |
c2c6d25f JM |
2906 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
2907 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 2908 | |
c2c6d25f | 2909 | enum breakpoint_here |
6c95b8df | 2910 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 2911 | { |
35df4500 | 2912 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 2913 | int any_breakpoint_here = 0; |
c906108c | 2914 | |
35df4500 | 2915 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 2916 | { |
35df4500 TJB |
2917 | if (bl->loc_type != bp_loc_software_breakpoint |
2918 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
2919 | continue; |
2920 | ||
f1310107 | 2921 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 TJB |
2922 | if ((breakpoint_enabled (bl->owner) |
2923 | || bl->owner->enable_state == bp_permanent) | |
f1310107 | 2924 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
2925 | { |
2926 | if (overlay_debugging | |
35df4500 TJB |
2927 | && section_is_overlay (bl->section) |
2928 | && !section_is_mapped (bl->section)) | |
075f6582 | 2929 | continue; /* unmapped overlay -- can't be a match */ |
35df4500 | 2930 | else if (bl->owner->enable_state == bp_permanent) |
075f6582 DJ |
2931 | return permanent_breakpoint_here; |
2932 | else | |
2933 | any_breakpoint_here = 1; | |
2934 | } | |
2935 | } | |
c906108c | 2936 | |
c2c6d25f | 2937 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
2938 | } |
2939 | ||
1c5cfe86 PA |
2940 | /* Return true if there's a moribund breakpoint at PC. */ |
2941 | ||
2942 | int | |
6c95b8df | 2943 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
2944 | { |
2945 | struct bp_location *loc; | |
2946 | int ix; | |
2947 | ||
2948 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
f1310107 | 2949 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
2950 | return 1; |
2951 | ||
2952 | return 0; | |
2953 | } | |
c2c6d25f | 2954 | |
c36b740a | 2955 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
4a64f543 MS |
2956 | inserted using regular breakpoint_chain / bp_location array |
2957 | mechanism. This does not check for single-step breakpoints, which | |
2958 | are inserted and removed using direct target manipulation. */ | |
c906108c SS |
2959 | |
2960 | int | |
4a64f543 MS |
2961 | regular_breakpoint_inserted_here_p (struct address_space *aspace, |
2962 | CORE_ADDR pc) | |
c906108c | 2963 | { |
35df4500 | 2964 | struct bp_location *bl, **blp_tmp; |
c906108c | 2965 | |
35df4500 | 2966 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2967 | { |
35df4500 TJB |
2968 | if (bl->loc_type != bp_loc_software_breakpoint |
2969 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
2970 | continue; |
2971 | ||
35df4500 | 2972 | if (bl->inserted |
f1310107 | 2973 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
2974 | { |
2975 | if (overlay_debugging | |
35df4500 TJB |
2976 | && section_is_overlay (bl->section) |
2977 | && !section_is_mapped (bl->section)) | |
075f6582 DJ |
2978 | continue; /* unmapped overlay -- can't be a match */ |
2979 | else | |
2980 | return 1; | |
2981 | } | |
c5aa993b | 2982 | } |
c36b740a VP |
2983 | return 0; |
2984 | } | |
2985 | ||
2986 | /* Returns non-zero iff there's either regular breakpoint | |
2987 | or a single step breakpoint inserted at PC. */ | |
2988 | ||
2989 | int | |
6c95b8df | 2990 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c36b740a | 2991 | { |
6c95b8df | 2992 | if (regular_breakpoint_inserted_here_p (aspace, pc)) |
c36b740a | 2993 | return 1; |
c906108c | 2994 | |
6c95b8df | 2995 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2996 | return 1; |
2997 | ||
c906108c SS |
2998 | return 0; |
2999 | } | |
3000 | ||
4fa8626c DJ |
3001 | /* This function returns non-zero iff there is a software breakpoint |
3002 | inserted at PC. */ | |
3003 | ||
3004 | int | |
3e43a32a MS |
3005 | software_breakpoint_inserted_here_p (struct address_space *aspace, |
3006 | CORE_ADDR pc) | |
4fa8626c | 3007 | { |
35df4500 | 3008 | struct bp_location *bl, **blp_tmp; |
4fa8626c | 3009 | |
35df4500 | 3010 | ALL_BP_LOCATIONS (bl, blp_tmp) |
4fa8626c | 3011 | { |
35df4500 | 3012 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
3013 | continue; |
3014 | ||
35df4500 TJB |
3015 | if (bl->inserted |
3016 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6c95b8df | 3017 | aspace, pc)) |
4fa8626c DJ |
3018 | { |
3019 | if (overlay_debugging | |
35df4500 TJB |
3020 | && section_is_overlay (bl->section) |
3021 | && !section_is_mapped (bl->section)) | |
4fa8626c DJ |
3022 | continue; /* unmapped overlay -- can't be a match */ |
3023 | else | |
3024 | return 1; | |
3025 | } | |
3026 | } | |
3027 | ||
1aafd4da | 3028 | /* Also check for software single-step breakpoints. */ |
6c95b8df | 3029 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
3030 | return 1; |
3031 | ||
4fa8626c DJ |
3032 | return 0; |
3033 | } | |
3034 | ||
9093389c PA |
3035 | int |
3036 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
3037 | CORE_ADDR addr, ULONGEST len) | |
3038 | { | |
3039 | struct breakpoint *bpt; | |
3040 | ||
3041 | ALL_BREAKPOINTS (bpt) | |
3042 | { | |
3043 | struct bp_location *loc; | |
3044 | ||
3045 | if (bpt->type != bp_hardware_watchpoint | |
3046 | && bpt->type != bp_access_watchpoint) | |
3047 | continue; | |
3048 | ||
3049 | if (!breakpoint_enabled (bpt)) | |
3050 | continue; | |
3051 | ||
3052 | for (loc = bpt->loc; loc; loc = loc->next) | |
3053 | if (loc->pspace->aspace == aspace && loc->inserted) | |
3054 | { | |
3055 | CORE_ADDR l, h; | |
3056 | ||
3057 | /* Check for intersection. */ | |
3058 | l = max (loc->address, addr); | |
3059 | h = min (loc->address + loc->length, addr + len); | |
3060 | if (l < h) | |
3061 | return 1; | |
3062 | } | |
3063 | } | |
3064 | return 0; | |
3065 | } | |
3066 | ||
075f6582 DJ |
3067 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
3068 | PC is valid for process/thread PTID. */ | |
c906108c SS |
3069 | |
3070 | int | |
6c95b8df PA |
3071 | breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc, |
3072 | ptid_t ptid) | |
c906108c | 3073 | { |
35df4500 | 3074 | struct bp_location *bl, **blp_tmp; |
4a306c9a | 3075 | /* The thread and task IDs associated to PTID, computed lazily. */ |
a6f1cd96 | 3076 | int thread = -1; |
4a306c9a | 3077 | int task = 0; |
a6f1cd96 | 3078 | |
35df4500 | 3079 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3080 | { |
35df4500 TJB |
3081 | if (bl->loc_type != bp_loc_software_breakpoint |
3082 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
3083 | continue; |
3084 | ||
35df4500 TJB |
3085 | /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */ |
3086 | if (!breakpoint_enabled (bl->owner) | |
3087 | && bl->owner->enable_state != bp_permanent) | |
a6f1cd96 JB |
3088 | continue; |
3089 | ||
f1310107 | 3090 | if (!breakpoint_location_address_match (bl, aspace, pc)) |
a6f1cd96 JB |
3091 | continue; |
3092 | ||
35df4500 | 3093 | if (bl->owner->thread != -1) |
075f6582 | 3094 | { |
a6f1cd96 JB |
3095 | /* This is a thread-specific breakpoint. Check that ptid |
3096 | matches that thread. If thread hasn't been computed yet, | |
3097 | it is now time to do so. */ | |
3098 | if (thread == -1) | |
3099 | thread = pid_to_thread_id (ptid); | |
35df4500 | 3100 | if (bl->owner->thread != thread) |
a6f1cd96 | 3101 | continue; |
075f6582 | 3102 | } |
a6f1cd96 | 3103 | |
35df4500 | 3104 | if (bl->owner->task != 0) |
4a306c9a JB |
3105 | { |
3106 | /* This is a task-specific breakpoint. Check that ptid | |
3107 | matches that task. If task hasn't been computed yet, | |
3108 | it is now time to do so. */ | |
3109 | if (task == 0) | |
3110 | task = ada_get_task_number (ptid); | |
35df4500 | 3111 | if (bl->owner->task != task) |
4a306c9a JB |
3112 | continue; |
3113 | } | |
3114 | ||
a6f1cd96 | 3115 | if (overlay_debugging |
35df4500 TJB |
3116 | && section_is_overlay (bl->section) |
3117 | && !section_is_mapped (bl->section)) | |
a6f1cd96 JB |
3118 | continue; /* unmapped overlay -- can't be a match */ |
3119 | ||
3120 | return 1; | |
c5aa993b | 3121 | } |
c906108c SS |
3122 | |
3123 | return 0; | |
3124 | } | |
c906108c | 3125 | \f |
c5aa993b | 3126 | |
c906108c SS |
3127 | /* bpstat stuff. External routines' interfaces are documented |
3128 | in breakpoint.h. */ | |
3129 | ||
3130 | int | |
fba45db2 | 3131 | ep_is_catchpoint (struct breakpoint *ep) |
c906108c | 3132 | { |
533be4dd | 3133 | return (ep->type == bp_catchpoint); |
c906108c SS |
3134 | } |
3135 | ||
f431efe5 PA |
3136 | /* Frees any storage that is part of a bpstat. Does not walk the |
3137 | 'next' chain. */ | |
3138 | ||
3139 | static void | |
198757a8 VP |
3140 | bpstat_free (bpstat bs) |
3141 | { | |
3142 | if (bs->old_val != NULL) | |
3143 | value_free (bs->old_val); | |
9add0f1b | 3144 | decref_counted_command_line (&bs->commands); |
f431efe5 | 3145 | decref_bp_location (&bs->bp_location_at); |
198757a8 VP |
3146 | xfree (bs); |
3147 | } | |
3148 | ||
c906108c SS |
3149 | /* Clear a bpstat so that it says we are not at any breakpoint. |
3150 | Also free any storage that is part of a bpstat. */ | |
3151 | ||
3152 | void | |
fba45db2 | 3153 | bpstat_clear (bpstat *bsp) |
c906108c SS |
3154 | { |
3155 | bpstat p; | |
3156 | bpstat q; | |
3157 | ||
3158 | if (bsp == 0) | |
3159 | return; | |
3160 | p = *bsp; | |
3161 | while (p != NULL) | |
3162 | { | |
3163 | q = p->next; | |
198757a8 | 3164 | bpstat_free (p); |
c906108c SS |
3165 | p = q; |
3166 | } | |
3167 | *bsp = NULL; | |
3168 | } | |
3169 | ||
3170 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
3171 | is part of the bpstat is copied as well. */ | |
3172 | ||
3173 | bpstat | |
fba45db2 | 3174 | bpstat_copy (bpstat bs) |
c906108c SS |
3175 | { |
3176 | bpstat p = NULL; | |
3177 | bpstat tmp; | |
3178 | bpstat retval = NULL; | |
3179 | ||
3180 | if (bs == NULL) | |
3181 | return bs; | |
3182 | ||
3183 | for (; bs != NULL; bs = bs->next) | |
3184 | { | |
3185 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
3186 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 3187 | incref_counted_command_line (tmp->commands); |
f431efe5 | 3188 | incref_bp_location (tmp->bp_location_at); |
31cc81e9 | 3189 | if (bs->old_val != NULL) |
3c3185ac JK |
3190 | { |
3191 | tmp->old_val = value_copy (bs->old_val); | |
3192 | release_value (tmp->old_val); | |
3193 | } | |
31cc81e9 | 3194 | |
c906108c SS |
3195 | if (p == NULL) |
3196 | /* This is the first thing in the chain. */ | |
3197 | retval = tmp; | |
3198 | else | |
3199 | p->next = tmp; | |
3200 | p = tmp; | |
3201 | } | |
3202 | p->next = NULL; | |
3203 | return retval; | |
3204 | } | |
3205 | ||
4a64f543 | 3206 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
3207 | |
3208 | bpstat | |
fba45db2 | 3209 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 3210 | { |
c5aa993b JM |
3211 | if (bsp == NULL) |
3212 | return NULL; | |
c906108c | 3213 | |
c5aa993b JM |
3214 | for (; bsp != NULL; bsp = bsp->next) |
3215 | { | |
f431efe5 | 3216 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
3217 | return bsp; |
3218 | } | |
c906108c SS |
3219 | return NULL; |
3220 | } | |
3221 | ||
4a64f543 MS |
3222 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
3223 | stopped at. *BSP upon return is a bpstat which points to the | |
3224 | remaining breakpoints stopped at (but which is not guaranteed to be | |
3225 | good for anything but further calls to bpstat_num). | |
3226 | ||
8671a17b PA |
3227 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
3228 | Return -1 if stopped at a breakpoint that has been deleted since | |
3229 | we set it. | |
3230 | Return 1 otherwise. */ | |
c906108c SS |
3231 | |
3232 | int | |
8671a17b | 3233 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
3234 | { |
3235 | struct breakpoint *b; | |
3236 | ||
3237 | if ((*bsp) == NULL) | |
3238 | return 0; /* No more breakpoint values */ | |
8671a17b | 3239 | |
4a64f543 MS |
3240 | /* We assume we'll never have several bpstats that correspond to a |
3241 | single breakpoint -- otherwise, this function might return the | |
3242 | same number more than once and this will look ugly. */ | |
f431efe5 | 3243 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
3244 | *bsp = (*bsp)->next; |
3245 | if (b == NULL) | |
3246 | return -1; /* breakpoint that's been deleted since */ | |
3247 | ||
3248 | *num = b->number; /* We have its number */ | |
3249 | return 1; | |
c906108c SS |
3250 | } |
3251 | ||
e93ca019 | 3252 | /* See breakpoint.h. */ |
c906108c SS |
3253 | |
3254 | void | |
e93ca019 | 3255 | bpstat_clear_actions (void) |
c906108c | 3256 | { |
e93ca019 JK |
3257 | struct thread_info *tp; |
3258 | bpstat bs; | |
3259 | ||
3260 | if (ptid_equal (inferior_ptid, null_ptid)) | |
3261 | return; | |
3262 | ||
3263 | tp = find_thread_ptid (inferior_ptid); | |
3264 | if (tp == NULL) | |
3265 | return; | |
3266 | ||
3267 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) | |
c906108c | 3268 | { |
9add0f1b | 3269 | decref_counted_command_line (&bs->commands); |
abf85f46 | 3270 | |
c906108c SS |
3271 | if (bs->old_val != NULL) |
3272 | { | |
3273 | value_free (bs->old_val); | |
3274 | bs->old_val = NULL; | |
3275 | } | |
3276 | } | |
3277 | } | |
3278 | ||
f3b1572e PA |
3279 | /* Called when a command is about to proceed the inferior. */ |
3280 | ||
3281 | static void | |
3282 | breakpoint_about_to_proceed (void) | |
3283 | { | |
3284 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
3285 | { | |
3286 | struct thread_info *tp = inferior_thread (); | |
3287 | ||
3288 | /* Allow inferior function calls in breakpoint commands to not | |
3289 | interrupt the command list. When the call finishes | |
3290 | successfully, the inferior will be standing at the same | |
3291 | breakpoint as if nothing happened. */ | |
16c381f0 | 3292 | if (tp->control.in_infcall) |
f3b1572e PA |
3293 | return; |
3294 | } | |
3295 | ||
3296 | breakpoint_proceeded = 1; | |
3297 | } | |
3298 | ||
4a64f543 MS |
3299 | /* Stub for cleaning up our state if we error-out of a breakpoint |
3300 | command. */ | |
c906108c | 3301 | static void |
4efb68b1 | 3302 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
3303 | { |
3304 | executing_breakpoint_commands = 0; | |
3305 | } | |
3306 | ||
abf85f46 JK |
3307 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
3308 | or its equivalent. */ | |
3309 | ||
3310 | static int | |
3311 | command_line_is_silent (struct command_line *cmd) | |
3312 | { | |
3313 | return cmd && (strcmp ("silent", cmd->line) == 0 | |
3314 | || (xdb_commands && strcmp ("Q", cmd->line) == 0)); | |
3315 | } | |
3316 | ||
4a64f543 MS |
3317 | /* Execute all the commands associated with all the breakpoints at |
3318 | this location. Any of these commands could cause the process to | |
3319 | proceed beyond this point, etc. We look out for such changes by | |
3320 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 3321 | |
347bddb7 PA |
3322 | Returns true if a breakpoint command resumed the inferior. In that |
3323 | case, it is the caller's responsibility to recall it again with the | |
3324 | bpstat of the current thread. */ | |
3325 | ||
3326 | static int | |
3327 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
3328 | { |
3329 | bpstat bs; | |
3330 | struct cleanup *old_chain; | |
347bddb7 | 3331 | int again = 0; |
c906108c SS |
3332 | |
3333 | /* Avoid endless recursion if a `source' command is contained | |
3334 | in bs->commands. */ | |
3335 | if (executing_breakpoint_commands) | |
347bddb7 | 3336 | return 0; |
c906108c SS |
3337 | |
3338 | executing_breakpoint_commands = 1; | |
3339 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
3340 | ||
cf6c5ffb TT |
3341 | prevent_dont_repeat (); |
3342 | ||
4a64f543 | 3343 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
3344 | bs = *bsp; |
3345 | ||
3346 | breakpoint_proceeded = 0; | |
3347 | for (; bs != NULL; bs = bs->next) | |
3348 | { | |
9add0f1b | 3349 | struct counted_command_line *ccmd; |
6c50ab1c JB |
3350 | struct command_line *cmd; |
3351 | struct cleanup *this_cmd_tree_chain; | |
3352 | ||
3353 | /* Take ownership of the BSP's command tree, if it has one. | |
3354 | ||
3355 | The command tree could legitimately contain commands like | |
3356 | 'step' and 'next', which call clear_proceed_status, which | |
3357 | frees stop_bpstat's command tree. To make sure this doesn't | |
3358 | free the tree we're executing out from under us, we need to | |
3359 | take ownership of the tree ourselves. Since a given bpstat's | |
3360 | commands are only executed once, we don't need to copy it; we | |
3361 | can clear the pointer in the bpstat, and make sure we free | |
3362 | the tree when we're done. */ | |
9add0f1b TT |
3363 | ccmd = bs->commands; |
3364 | bs->commands = NULL; | |
abf85f46 JK |
3365 | this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd); |
3366 | cmd = ccmd ? ccmd->commands : NULL; | |
3367 | if (command_line_is_silent (cmd)) | |
3368 | { | |
3369 | /* The action has been already done by bpstat_stop_status. */ | |
3370 | cmd = cmd->next; | |
3371 | } | |
6c50ab1c | 3372 | |
c906108c SS |
3373 | while (cmd != NULL) |
3374 | { | |
3375 | execute_control_command (cmd); | |
3376 | ||
3377 | if (breakpoint_proceeded) | |
3378 | break; | |
3379 | else | |
3380 | cmd = cmd->next; | |
3381 | } | |
6c50ab1c JB |
3382 | |
3383 | /* We can free this command tree now. */ | |
3384 | do_cleanups (this_cmd_tree_chain); | |
3385 | ||
c906108c | 3386 | if (breakpoint_proceeded) |
32c1e744 VP |
3387 | { |
3388 | if (target_can_async_p ()) | |
347bddb7 PA |
3389 | /* If we are in async mode, then the target might be still |
3390 | running, not stopped at any breakpoint, so nothing for | |
3391 | us to do here -- just return to the event loop. */ | |
3392 | ; | |
32c1e744 VP |
3393 | else |
3394 | /* In sync mode, when execute_control_command returns | |
3395 | we're already standing on the next breakpoint. | |
347bddb7 PA |
3396 | Breakpoint commands for that stop were not run, since |
3397 | execute_command does not run breakpoint commands -- | |
3398 | only command_line_handler does, but that one is not | |
3399 | involved in execution of breakpoint commands. So, we | |
3400 | can now execute breakpoint commands. It should be | |
3401 | noted that making execute_command do bpstat actions is | |
3402 | not an option -- in this case we'll have recursive | |
3403 | invocation of bpstat for each breakpoint with a | |
3404 | command, and can easily blow up GDB stack. Instead, we | |
3405 | return true, which will trigger the caller to recall us | |
3406 | with the new stop_bpstat. */ | |
3407 | again = 1; | |
3408 | break; | |
32c1e744 | 3409 | } |
c906108c | 3410 | } |
c2b8ed2c | 3411 | do_cleanups (old_chain); |
347bddb7 PA |
3412 | return again; |
3413 | } | |
3414 | ||
3415 | void | |
3416 | bpstat_do_actions (void) | |
3417 | { | |
353d1d73 JK |
3418 | struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup (); |
3419 | ||
347bddb7 PA |
3420 | /* Do any commands attached to breakpoint we are stopped at. */ |
3421 | while (!ptid_equal (inferior_ptid, null_ptid) | |
3422 | && target_has_execution | |
3423 | && !is_exited (inferior_ptid) | |
3424 | && !is_executing (inferior_ptid)) | |
3425 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
3426 | and only return when it is stopped at the next breakpoint, we | |
3427 | keep doing breakpoint actions until it returns false to | |
3428 | indicate the inferior was not resumed. */ | |
16c381f0 | 3429 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
347bddb7 | 3430 | break; |
353d1d73 JK |
3431 | |
3432 | discard_cleanups (cleanup_if_error); | |
c906108c SS |
3433 | } |
3434 | ||
fa4727a6 DJ |
3435 | /* Print out the (old or new) value associated with a watchpoint. */ |
3436 | ||
3437 | static void | |
3438 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
3439 | { | |
3440 | if (val == NULL) | |
3441 | fprintf_unfiltered (stream, _("<unreadable>")); | |
3442 | else | |
79a45b7d TT |
3443 | { |
3444 | struct value_print_options opts; | |
3445 | get_user_print_options (&opts); | |
3446 | value_print (val, stream, &opts); | |
3447 | } | |
fa4727a6 DJ |
3448 | } |
3449 | ||
e514a9d6 | 3450 | /* Generic routine for printing messages indicating why we |
4a64f543 | 3451 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
3452 | 'print_it' in the bpstat structure. Under some circumstances we |
3453 | may decide not to print anything here and delegate the task to | |
4a64f543 | 3454 | normal_stop(). */ |
e514a9d6 JM |
3455 | |
3456 | static enum print_stop_action | |
3457 | print_bp_stop_message (bpstat bs) | |
3458 | { | |
3459 | switch (bs->print_it) | |
3460 | { | |
3461 | case print_it_noop: | |
4a64f543 | 3462 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
3463 | return PRINT_UNKNOWN; |
3464 | break; | |
3465 | ||
3466 | case print_it_done: | |
3467 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 3468 | relevant messages. */ |
e514a9d6 JM |
3469 | return PRINT_SRC_AND_LOC; |
3470 | break; | |
3471 | ||
3472 | case print_it_normal: | |
4f8d1dc6 | 3473 | { |
f431efe5 PA |
3474 | struct breakpoint *b = bs->breakpoint_at; |
3475 | ||
1a6a67de TJB |
3476 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
3477 | which has since been deleted. */ | |
3478 | if (b == NULL) | |
3479 | return PRINT_UNKNOWN; | |
3480 | ||
348d480f PA |
3481 | /* Normal case. Call the breakpoint's print_it method. */ |
3482 | return b->ops->print_it (bs); | |
4f8d1dc6 | 3483 | } |
348d480f | 3484 | break; |
3086aeae | 3485 | |
e514a9d6 | 3486 | default: |
8e65ff28 | 3487 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 3488 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 3489 | break; |
c906108c | 3490 | } |
c906108c SS |
3491 | } |
3492 | ||
e514a9d6 JM |
3493 | /* Print a message indicating what happened. This is called from |
3494 | normal_stop(). The input to this routine is the head of the bpstat | |
36dfb11c TT |
3495 | list - a list of the eventpoints that caused this stop. KIND is |
3496 | the target_waitkind for the stopping event. This | |
e514a9d6 JM |
3497 | routine calls the generic print routine for printing a message |
3498 | about reasons for stopping. This will print (for example) the | |
3499 | "Breakpoint n," part of the output. The return value of this | |
3500 | routine is one of: | |
c906108c | 3501 | |
4a64f543 | 3502 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 3503 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 3504 | code to print the location. An example is |
c5aa993b JM |
3505 | "Breakpoint 1, " which should be followed by |
3506 | the location. | |
917317f4 | 3507 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
3508 | to also print the location part of the message. |
3509 | An example is the catch/throw messages, which | |
4a64f543 | 3510 | don't require a location appended to the end. |
917317f4 | 3511 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 3512 | further info to be printed. */ |
c906108c | 3513 | |
917317f4 | 3514 | enum print_stop_action |
36dfb11c | 3515 | bpstat_print (bpstat bs, int kind) |
c906108c SS |
3516 | { |
3517 | int val; | |
c5aa993b | 3518 | |
c906108c | 3519 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
3520 | (Currently all watchpoints go on the bpstat whether hit or not. |
3521 | That probably could (should) be changed, provided care is taken | |
c906108c | 3522 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
3523 | for (; bs; bs = bs->next) |
3524 | { | |
3525 | val = print_bp_stop_message (bs); | |
3526 | if (val == PRINT_SRC_ONLY | |
3527 | || val == PRINT_SRC_AND_LOC | |
3528 | || val == PRINT_NOTHING) | |
3529 | return val; | |
3530 | } | |
c906108c | 3531 | |
36dfb11c TT |
3532 | /* If we had hit a shared library event breakpoint, |
3533 | print_bp_stop_message would print out this message. If we hit an | |
3534 | OS-level shared library event, do the same thing. */ | |
3535 | if (kind == TARGET_WAITKIND_LOADED) | |
3536 | { | |
3537 | ui_out_text (current_uiout, _("Stopped due to shared library event\n")); | |
3538 | if (ui_out_is_mi_like_p (current_uiout)) | |
3539 | ui_out_field_string (current_uiout, "reason", | |
3540 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); | |
3541 | return PRINT_NOTHING; | |
3542 | } | |
3543 | ||
e514a9d6 | 3544 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 3545 | with and nothing was printed. */ |
917317f4 | 3546 | return PRINT_UNKNOWN; |
c906108c SS |
3547 | } |
3548 | ||
4a64f543 MS |
3549 | /* Evaluate the expression EXP and return 1 if value is zero. This is |
3550 | used inside a catch_errors to evaluate the breakpoint condition. | |
3551 | The argument is a "struct expression *" that has been cast to a | |
3552 | "char *" to make it pass through catch_errors. */ | |
c906108c SS |
3553 | |
3554 | static int | |
4efb68b1 | 3555 | breakpoint_cond_eval (void *exp) |
c906108c | 3556 | { |
278cd55f | 3557 | struct value *mark = value_mark (); |
c5aa993b | 3558 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 3559 | |
c906108c SS |
3560 | value_free_to_mark (mark); |
3561 | return i; | |
3562 | } | |
3563 | ||
5760d0ab | 3564 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c SS |
3565 | |
3566 | static bpstat | |
5760d0ab | 3567 | bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) |
c906108c SS |
3568 | { |
3569 | bpstat bs; | |
3570 | ||
3571 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
5760d0ab JK |
3572 | bs->next = NULL; |
3573 | **bs_link_pointer = bs; | |
3574 | *bs_link_pointer = &bs->next; | |
f431efe5 PA |
3575 | bs->breakpoint_at = bl->owner; |
3576 | bs->bp_location_at = bl; | |
3577 | incref_bp_location (bl); | |
c906108c SS |
3578 | /* If the condition is false, etc., don't do the commands. */ |
3579 | bs->commands = NULL; | |
3580 | bs->old_val = NULL; | |
3581 | bs->print_it = print_it_normal; | |
3582 | return bs; | |
3583 | } | |
3584 | \f | |
d983da9c DJ |
3585 | /* The target has stopped with waitstatus WS. Check if any hardware |
3586 | watchpoints have triggered, according to the target. */ | |
3587 | ||
3588 | int | |
3589 | watchpoints_triggered (struct target_waitstatus *ws) | |
3590 | { | |
d92524f1 | 3591 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
3592 | CORE_ADDR addr; |
3593 | struct breakpoint *b; | |
3594 | ||
3595 | if (!stopped_by_watchpoint) | |
3596 | { | |
3597 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
3598 | as not triggered. */ | |
3599 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3600 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
3601 | { |
3602 | struct watchpoint *w = (struct watchpoint *) b; | |
3603 | ||
3604 | w->watchpoint_triggered = watch_triggered_no; | |
3605 | } | |
d983da9c DJ |
3606 | |
3607 | return 0; | |
3608 | } | |
3609 | ||
3610 | if (!target_stopped_data_address (¤t_target, &addr)) | |
3611 | { | |
3612 | /* We were stopped by a watchpoint, but we don't know where. | |
3613 | Mark all watchpoints as unknown. */ | |
3614 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3615 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
3616 | { |
3617 | struct watchpoint *w = (struct watchpoint *) b; | |
3618 | ||
3619 | w->watchpoint_triggered = watch_triggered_unknown; | |
3620 | } | |
d983da9c DJ |
3621 | |
3622 | return stopped_by_watchpoint; | |
3623 | } | |
3624 | ||
3625 | /* The target could report the data address. Mark watchpoints | |
3626 | affected by this data address as triggered, and all others as not | |
3627 | triggered. */ | |
3628 | ||
3629 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3630 | if (is_hardware_watchpoint (b)) |
d983da9c | 3631 | { |
3a5c3e22 | 3632 | struct watchpoint *w = (struct watchpoint *) b; |
a5606eee | 3633 | struct bp_location *loc; |
d983da9c | 3634 | |
3a5c3e22 | 3635 | w->watchpoint_triggered = watch_triggered_no; |
a5606eee | 3636 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 | 3637 | { |
3a5c3e22 | 3638 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 3639 | { |
3a5c3e22 PA |
3640 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
3641 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
3642 | |
3643 | if (newaddr == start) | |
3644 | { | |
3a5c3e22 | 3645 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
3646 | break; |
3647 | } | |
3648 | } | |
3649 | /* Exact match not required. Within range is sufficient. */ | |
3650 | else if (target_watchpoint_addr_within_range (¤t_target, | |
3651 | addr, loc->address, | |
3652 | loc->length)) | |
3653 | { | |
3a5c3e22 | 3654 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
3655 | break; |
3656 | } | |
3657 | } | |
d983da9c DJ |
3658 | } |
3659 | ||
3660 | return 1; | |
3661 | } | |
3662 | ||
c906108c SS |
3663 | /* Possible return values for watchpoint_check (this can't be an enum |
3664 | because of check_errors). */ | |
3665 | /* The watchpoint has been deleted. */ | |
3666 | #define WP_DELETED 1 | |
3667 | /* The value has changed. */ | |
3668 | #define WP_VALUE_CHANGED 2 | |
3669 | /* The value has not changed. */ | |
3670 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
3671 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
3672 | #define WP_IGNORE 4 | |
c906108c SS |
3673 | |
3674 | #define BP_TEMPFLAG 1 | |
3675 | #define BP_HARDWAREFLAG 2 | |
3676 | ||
4a64f543 MS |
3677 | /* Evaluate watchpoint condition expression and check if its value |
3678 | changed. | |
553e4c11 JB |
3679 | |
3680 | P should be a pointer to struct bpstat, but is defined as a void * | |
3681 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
3682 | |
3683 | static int | |
4efb68b1 | 3684 | watchpoint_check (void *p) |
c906108c SS |
3685 | { |
3686 | bpstat bs = (bpstat) p; | |
3a5c3e22 | 3687 | struct watchpoint *b; |
c906108c SS |
3688 | struct frame_info *fr; |
3689 | int within_current_scope; | |
3690 | ||
f431efe5 | 3691 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 3692 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 3693 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 3694 | |
f6bc2008 PA |
3695 | /* If this is a local watchpoint, we only want to check if the |
3696 | watchpoint frame is in scope if the current thread is the thread | |
3697 | that was used to create the watchpoint. */ | |
3698 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 3699 | return WP_IGNORE; |
f6bc2008 | 3700 | |
c906108c SS |
3701 | if (b->exp_valid_block == NULL) |
3702 | within_current_scope = 1; | |
3703 | else | |
3704 | { | |
edb3359d DJ |
3705 | struct frame_info *frame = get_current_frame (); |
3706 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
3707 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
3708 | ||
4a64f543 MS |
3709 | /* in_function_epilogue_p() returns a non-zero value if we're |
3710 | still in the function but the stack frame has already been | |
3711 | invalidated. Since we can't rely on the values of local | |
3712 | variables after the stack has been destroyed, we are treating | |
3713 | the watchpoint in that state as `not changed' without further | |
3714 | checking. Don't mark watchpoints as changed if the current | |
3715 | frame is in an epilogue - even if they are in some other | |
3716 | frame, our view of the stack is likely to be wrong and | |
3717 | frame_find_by_id could error out. */ | |
a0f49112 | 3718 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) |
60e1c644 | 3719 | return WP_IGNORE; |
a0f49112 | 3720 | |
101dcfbe | 3721 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 3722 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
3723 | |
3724 | /* If we've gotten confused in the unwinder, we might have | |
3725 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
3726 | if (within_current_scope) |
3727 | { | |
3728 | struct symbol *function; | |
3729 | ||
3730 | function = get_frame_function (fr); | |
3731 | if (function == NULL | |
3732 | || !contained_in (b->exp_valid_block, | |
3733 | SYMBOL_BLOCK_VALUE (function))) | |
3734 | within_current_scope = 0; | |
3735 | } | |
69fbadd5 | 3736 | |
edb3359d | 3737 | if (within_current_scope) |
c906108c SS |
3738 | /* If we end up stopping, the current frame will get selected |
3739 | in normal_stop. So this call to select_frame won't affect | |
3740 | the user. */ | |
0f7d239c | 3741 | select_frame (fr); |
c906108c | 3742 | } |
c5aa993b | 3743 | |
c906108c SS |
3744 | if (within_current_scope) |
3745 | { | |
4a64f543 MS |
3746 | /* We use value_{,free_to_}mark because it could be a *long* |
3747 | time before we return to the command level and call | |
3748 | free_all_values. We can't call free_all_values because we | |
3749 | might be in the middle of evaluating a function call. */ | |
c906108c | 3750 | |
0cf6dd15 | 3751 | int pc = 0; |
9c06b0b4 | 3752 | struct value *mark; |
fa4727a6 DJ |
3753 | struct value *new_val; |
3754 | ||
3a5c3e22 | 3755 | if (is_masked_watchpoint (&b->base)) |
9c06b0b4 TJB |
3756 | /* Since we don't know the exact trigger address (from |
3757 | stopped_data_address), just tell the user we've triggered | |
3758 | a mask watchpoint. */ | |
3759 | return WP_VALUE_CHANGED; | |
3760 | ||
3761 | mark = value_mark (); | |
0cf6dd15 | 3762 | fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL); |
218d2fc6 | 3763 | |
4a64f543 MS |
3764 | /* We use value_equal_contents instead of value_equal because |
3765 | the latter coerces an array to a pointer, thus comparing just | |
3766 | the address of the array instead of its contents. This is | |
3767 | not what we want. */ | |
fa4727a6 | 3768 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 3769 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 3770 | { |
fa4727a6 DJ |
3771 | if (new_val != NULL) |
3772 | { | |
3773 | release_value (new_val); | |
3774 | value_free_to_mark (mark); | |
3775 | } | |
c906108c SS |
3776 | bs->old_val = b->val; |
3777 | b->val = new_val; | |
fa4727a6 | 3778 | b->val_valid = 1; |
c906108c SS |
3779 | return WP_VALUE_CHANGED; |
3780 | } | |
3781 | else | |
3782 | { | |
60e1c644 | 3783 | /* Nothing changed. */ |
c906108c | 3784 | value_free_to_mark (mark); |
c906108c SS |
3785 | return WP_VALUE_NOT_CHANGED; |
3786 | } | |
3787 | } | |
3788 | else | |
3789 | { | |
79a45e25 PA |
3790 | struct ui_out *uiout = current_uiout; |
3791 | ||
c906108c | 3792 | /* This seems like the only logical thing to do because |
c5aa993b JM |
3793 | if we temporarily ignored the watchpoint, then when |
3794 | we reenter the block in which it is valid it contains | |
3795 | garbage (in the case of a function, it may have two | |
3796 | garbage values, one before and one after the prologue). | |
3797 | So we can't even detect the first assignment to it and | |
3798 | watch after that (since the garbage may or may not equal | |
3799 | the first value assigned). */ | |
348d480f PA |
3800 | /* We print all the stop information in |
3801 | breakpoint_ops->print_it, but in this case, by the time we | |
3802 | call breakpoint_ops->print_it this bp will be deleted | |
3803 | already. So we have no choice but print the information | |
3804 | here. */ | |
9dc5e2a9 | 3805 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3806 | ui_out_field_string |
3807 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 3808 | ui_out_text (uiout, "\nWatchpoint "); |
3a5c3e22 | 3809 | ui_out_field_int (uiout, "wpnum", b->base.number); |
3e43a32a MS |
3810 | ui_out_text (uiout, |
3811 | " deleted because the program has left the block in\n\ | |
8b93c638 | 3812 | which its expression is valid.\n"); |
4ce44c66 | 3813 | |
cdac0397 | 3814 | /* Make sure the watchpoint's commands aren't executed. */ |
3a5c3e22 | 3815 | decref_counted_command_line (&b->base.commands); |
d0fb5eae | 3816 | watchpoint_del_at_next_stop (b); |
c906108c SS |
3817 | |
3818 | return WP_DELETED; | |
3819 | } | |
3820 | } | |
3821 | ||
18a18393 | 3822 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
3823 | breakpoint location BL. This function does not check if we should |
3824 | stop, only if BL explains the stop. */ | |
3825 | ||
18a18393 | 3826 | static int |
6c95b8df | 3827 | bpstat_check_location (const struct bp_location *bl, |
09ac7c10 TT |
3828 | struct address_space *aspace, CORE_ADDR bp_addr, |
3829 | const struct target_waitstatus *ws) | |
18a18393 VP |
3830 | { |
3831 | struct breakpoint *b = bl->owner; | |
3832 | ||
348d480f | 3833 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
3834 | gdb_assert (b != NULL); |
3835 | ||
09ac7c10 | 3836 | return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws); |
18a18393 VP |
3837 | } |
3838 | ||
3a5c3e22 PA |
3839 | /* Determine if the watched values have actually changed, and we |
3840 | should stop. If not, set BS->stop to 0. */ | |
3841 | ||
18a18393 VP |
3842 | static void |
3843 | bpstat_check_watchpoint (bpstat bs) | |
3844 | { | |
2bdf28a0 | 3845 | const struct bp_location *bl; |
3a5c3e22 | 3846 | struct watchpoint *b; |
2bdf28a0 JK |
3847 | |
3848 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 3849 | bl = bs->bp_location_at; |
2bdf28a0 | 3850 | gdb_assert (bl != NULL); |
3a5c3e22 | 3851 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 3852 | gdb_assert (b != NULL); |
18a18393 | 3853 | |
18a18393 | 3854 | { |
18a18393 VP |
3855 | int must_check_value = 0; |
3856 | ||
3a5c3e22 | 3857 | if (b->base.type == bp_watchpoint) |
18a18393 VP |
3858 | /* For a software watchpoint, we must always check the |
3859 | watched value. */ | |
3860 | must_check_value = 1; | |
3861 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
3862 | /* We have a hardware watchpoint (read, write, or access) | |
3863 | and the target earlier reported an address watched by | |
3864 | this watchpoint. */ | |
3865 | must_check_value = 1; | |
3866 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3a5c3e22 | 3867 | && b->base.type == bp_hardware_watchpoint) |
18a18393 VP |
3868 | /* We were stopped by a hardware watchpoint, but the target could |
3869 | not report the data address. We must check the watchpoint's | |
3870 | value. Access and read watchpoints are out of luck; without | |
3871 | a data address, we can't figure it out. */ | |
3872 | must_check_value = 1; | |
3a5c3e22 | 3873 | |
18a18393 VP |
3874 | if (must_check_value) |
3875 | { | |
3e43a32a MS |
3876 | char *message |
3877 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3a5c3e22 | 3878 | b->base.number); |
18a18393 VP |
3879 | struct cleanup *cleanups = make_cleanup (xfree, message); |
3880 | int e = catch_errors (watchpoint_check, bs, message, | |
3881 | RETURN_MASK_ALL); | |
3882 | do_cleanups (cleanups); | |
3883 | switch (e) | |
3884 | { | |
3885 | case WP_DELETED: | |
3886 | /* We've already printed what needs to be printed. */ | |
3887 | bs->print_it = print_it_done; | |
3888 | /* Stop. */ | |
3889 | break; | |
60e1c644 PA |
3890 | case WP_IGNORE: |
3891 | bs->print_it = print_it_noop; | |
3892 | bs->stop = 0; | |
3893 | break; | |
18a18393 | 3894 | case WP_VALUE_CHANGED: |
3a5c3e22 | 3895 | if (b->base.type == bp_read_watchpoint) |
18a18393 | 3896 | { |
85d721b8 PA |
3897 | /* There are two cases to consider here: |
3898 | ||
4a64f543 | 3899 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
3900 | In that case, trust the target, and always report |
3901 | the watchpoint hit to the user. Even though | |
3902 | reads don't cause value changes, the value may | |
3903 | have changed since the last time it was read, and | |
3904 | since we're not trapping writes, we will not see | |
3905 | those, and as such we should ignore our notion of | |
3906 | old value. | |
3907 | ||
4a64f543 | 3908 | 2. We're watching the triggered memory for both |
85d721b8 PA |
3909 | reads and writes. There are two ways this may |
3910 | happen: | |
3911 | ||
4a64f543 | 3912 | 2.1. This is a target that can't break on data |
85d721b8 PA |
3913 | reads only, but can break on accesses (reads or |
3914 | writes), such as e.g., x86. We detect this case | |
3915 | at the time we try to insert read watchpoints. | |
3916 | ||
4a64f543 | 3917 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
3918 | watchpoints, but, the user set an access or write |
3919 | watchpoint watching the same memory as this read | |
3920 | watchpoint. | |
3921 | ||
3922 | If we're watching memory writes as well as reads, | |
3923 | ignore watchpoint hits when we find that the | |
3924 | value hasn't changed, as reads don't cause | |
3925 | changes. This still gives false positives when | |
3926 | the program writes the same value to memory as | |
3927 | what there was already in memory (we will confuse | |
3928 | it for a read), but it's much better than | |
3929 | nothing. */ | |
3930 | ||
3931 | int other_write_watchpoint = 0; | |
3932 | ||
3933 | if (bl->watchpoint_type == hw_read) | |
3934 | { | |
3935 | struct breakpoint *other_b; | |
3936 | ||
3937 | ALL_BREAKPOINTS (other_b) | |
3a5c3e22 PA |
3938 | if (other_b->type == bp_hardware_watchpoint |
3939 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 3940 | { |
3a5c3e22 PA |
3941 | struct watchpoint *other_w = |
3942 | (struct watchpoint *) other_b; | |
3943 | ||
3944 | if (other_w->watchpoint_triggered | |
3945 | == watch_triggered_yes) | |
3946 | { | |
3947 | other_write_watchpoint = 1; | |
3948 | break; | |
3949 | } | |
85d721b8 PA |
3950 | } |
3951 | } | |
3952 | ||
3953 | if (other_write_watchpoint | |
3954 | || bl->watchpoint_type == hw_access) | |
3955 | { | |
3956 | /* We're watching the same memory for writes, | |
3957 | and the value changed since the last time we | |
3958 | updated it, so this trap must be for a write. | |
3959 | Ignore it. */ | |
3960 | bs->print_it = print_it_noop; | |
3961 | bs->stop = 0; | |
3962 | } | |
18a18393 VP |
3963 | } |
3964 | break; | |
3965 | case WP_VALUE_NOT_CHANGED: | |
3a5c3e22 PA |
3966 | if (b->base.type == bp_hardware_watchpoint |
3967 | || b->base.type == bp_watchpoint) | |
18a18393 VP |
3968 | { |
3969 | /* Don't stop: write watchpoints shouldn't fire if | |
3970 | the value hasn't changed. */ | |
3971 | bs->print_it = print_it_noop; | |
3972 | bs->stop = 0; | |
3973 | } | |
3974 | /* Stop. */ | |
3975 | break; | |
3976 | default: | |
3977 | /* Can't happen. */ | |
3978 | case 0: | |
3979 | /* Error from catch_errors. */ | |
3a5c3e22 | 3980 | printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number); |
d0fb5eae | 3981 | watchpoint_del_at_next_stop (b); |
18a18393 VP |
3982 | /* We've already printed what needs to be printed. */ |
3983 | bs->print_it = print_it_done; | |
3984 | break; | |
3985 | } | |
3986 | } | |
3987 | else /* must_check_value == 0 */ | |
3988 | { | |
3989 | /* This is a case where some watchpoint(s) triggered, but | |
3990 | not at the address of this watchpoint, or else no | |
3991 | watchpoint triggered after all. So don't print | |
3992 | anything for this watchpoint. */ | |
3993 | bs->print_it = print_it_noop; | |
3994 | bs->stop = 0; | |
3995 | } | |
3996 | } | |
3997 | } | |
3998 | ||
3999 | ||
4000 | /* Check conditions (condition proper, frame, thread and ignore count) | |
4001 | of breakpoint referred to by BS. If we should not stop for this | |
4002 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 4003 | |
18a18393 VP |
4004 | static void |
4005 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
4006 | { | |
4007 | int thread_id = pid_to_thread_id (ptid); | |
2bdf28a0 JK |
4008 | const struct bp_location *bl; |
4009 | struct breakpoint *b; | |
4010 | ||
4011 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 4012 | bl = bs->bp_location_at; |
2bdf28a0 | 4013 | gdb_assert (bl != NULL); |
f431efe5 | 4014 | b = bs->breakpoint_at; |
2bdf28a0 | 4015 | gdb_assert (b != NULL); |
18a18393 VP |
4016 | |
4017 | if (frame_id_p (b->frame_id) | |
edb3359d | 4018 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 VP |
4019 | bs->stop = 0; |
4020 | else if (bs->stop) | |
4021 | { | |
4022 | int value_is_zero = 0; | |
60e1c644 PA |
4023 | struct expression *cond; |
4024 | ||
7371cf6d PM |
4025 | /* Evaluate Python breakpoints that have a "stop" |
4026 | method implemented. */ | |
4027 | if (b->py_bp_object) | |
4028 | bs->stop = gdbpy_should_stop (b->py_bp_object); | |
4029 | ||
60e1c644 | 4030 | if (is_watchpoint (b)) |
3a5c3e22 PA |
4031 | { |
4032 | struct watchpoint *w = (struct watchpoint *) b; | |
4033 | ||
4034 | cond = w->cond_exp; | |
4035 | } | |
60e1c644 PA |
4036 | else |
4037 | cond = bl->cond; | |
4038 | ||
f431efe5 | 4039 | if (cond && b->disposition != disp_del_at_next_stop) |
18a18393 | 4040 | { |
60e1c644 | 4041 | int within_current_scope = 1; |
3a5c3e22 | 4042 | struct watchpoint * w; |
60e1c644 | 4043 | |
c5bc3a77 DJ |
4044 | /* We use value_mark and value_free_to_mark because it could |
4045 | be a long time before we return to the command level and | |
4046 | call free_all_values. We can't call free_all_values | |
4047 | because we might be in the middle of evaluating a | |
4048 | function call. */ | |
4049 | struct value *mark = value_mark (); | |
4050 | ||
3a5c3e22 PA |
4051 | if (is_watchpoint (b)) |
4052 | w = (struct watchpoint *) b; | |
4053 | else | |
4054 | w = NULL; | |
4055 | ||
edb3359d DJ |
4056 | /* Need to select the frame, with all that implies so that |
4057 | the conditions will have the right context. Because we | |
4058 | use the frame, we will not see an inlined function's | |
4059 | variables when we arrive at a breakpoint at the start | |
4060 | of the inlined function; the current frame will be the | |
4061 | call site. */ | |
3a5c3e22 | 4062 | if (w == NULL || w->cond_exp_valid_block == NULL) |
60e1c644 PA |
4063 | select_frame (get_current_frame ()); |
4064 | else | |
4065 | { | |
4066 | struct frame_info *frame; | |
4067 | ||
4068 | /* For local watchpoint expressions, which particular | |
4069 | instance of a local is being watched matters, so we | |
4070 | keep track of the frame to evaluate the expression | |
4071 | in. To evaluate the condition however, it doesn't | |
4072 | really matter which instantiation of the function | |
4073 | where the condition makes sense triggers the | |
4074 | watchpoint. This allows an expression like "watch | |
4075 | global if q > 10" set in `func', catch writes to | |
4076 | global on all threads that call `func', or catch | |
4077 | writes on all recursive calls of `func' by a single | |
4078 | thread. We simply always evaluate the condition in | |
4079 | the innermost frame that's executing where it makes | |
4080 | sense to evaluate the condition. It seems | |
4081 | intuitive. */ | |
3a5c3e22 | 4082 | frame = block_innermost_frame (w->cond_exp_valid_block); |
60e1c644 PA |
4083 | if (frame != NULL) |
4084 | select_frame (frame); | |
4085 | else | |
4086 | within_current_scope = 0; | |
4087 | } | |
4088 | if (within_current_scope) | |
4089 | value_is_zero | |
4090 | = catch_errors (breakpoint_cond_eval, cond, | |
4091 | "Error in testing breakpoint condition:\n", | |
4092 | RETURN_MASK_ALL); | |
4093 | else | |
4094 | { | |
4095 | warning (_("Watchpoint condition cannot be tested " | |
4096 | "in the current scope")); | |
4097 | /* If we failed to set the right context for this | |
4098 | watchpoint, unconditionally report it. */ | |
4099 | value_is_zero = 0; | |
4100 | } | |
4a64f543 | 4101 | /* FIXME-someday, should give breakpoint #. */ |
c5bc3a77 | 4102 | value_free_to_mark (mark); |
18a18393 | 4103 | } |
60e1c644 PA |
4104 | |
4105 | if (cond && value_is_zero) | |
18a18393 VP |
4106 | { |
4107 | bs->stop = 0; | |
4108 | } | |
4109 | else if (b->thread != -1 && b->thread != thread_id) | |
4110 | { | |
4111 | bs->stop = 0; | |
4112 | } | |
4113 | else if (b->ignore_count > 0) | |
4114 | { | |
4115 | b->ignore_count--; | |
4116 | annotate_ignore_count_change (); | |
4117 | bs->stop = 0; | |
4a64f543 | 4118 | /* Increase the hit count even though we don't stop. */ |
18a18393 | 4119 | ++(b->hit_count); |
8d3788bd | 4120 | observer_notify_breakpoint_modified (b); |
18a18393 VP |
4121 | } |
4122 | } | |
4123 | } | |
4124 | ||
4125 | ||
9709f61c | 4126 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 4127 | BP_ADDR in thread PTID. |
c906108c | 4128 | |
d983da9c | 4129 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
4130 | don't understand this stop. Result is a chain of bpstat's such |
4131 | that: | |
c906108c | 4132 | |
c5aa993b | 4133 | if we don't understand the stop, the result is a null pointer. |
c906108c | 4134 | |
c5aa993b | 4135 | if we understand why we stopped, the result is not null. |
c906108c | 4136 | |
c5aa993b JM |
4137 | Each element of the chain refers to a particular breakpoint or |
4138 | watchpoint at which we have stopped. (We may have stopped for | |
4139 | several reasons concurrently.) | |
c906108c | 4140 | |
c5aa993b JM |
4141 | Each element of the chain has valid next, breakpoint_at, |
4142 | commands, FIXME??? fields. */ | |
c906108c SS |
4143 | |
4144 | bpstat | |
6c95b8df | 4145 | bpstat_stop_status (struct address_space *aspace, |
09ac7c10 TT |
4146 | CORE_ADDR bp_addr, ptid_t ptid, |
4147 | const struct target_waitstatus *ws) | |
c906108c | 4148 | { |
0d381245 | 4149 | struct breakpoint *b = NULL; |
afe38095 | 4150 | struct bp_location *bl; |
20874c92 | 4151 | struct bp_location *loc; |
5760d0ab JK |
4152 | /* First item of allocated bpstat's. */ |
4153 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 4154 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 4155 | bpstat bs; |
20874c92 | 4156 | int ix; |
429374b8 | 4157 | int need_remove_insert; |
f431efe5 | 4158 | int removed_any; |
c906108c | 4159 | |
f431efe5 PA |
4160 | /* First, build the bpstat chain with locations that explain a |
4161 | target stop, while being careful to not set the target running, | |
4162 | as that may invalidate locations (in particular watchpoint | |
4163 | locations are recreated). Resuming will happen here with | |
4164 | breakpoint conditions or watchpoint expressions that include | |
4165 | inferior function calls. */ | |
c5aa993b | 4166 | |
429374b8 JK |
4167 | ALL_BREAKPOINTS (b) |
4168 | { | |
4169 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) | |
4170 | continue; | |
a5606eee | 4171 | |
429374b8 JK |
4172 | for (bl = b->loc; bl != NULL; bl = bl->next) |
4173 | { | |
4a64f543 MS |
4174 | /* For hardware watchpoints, we look only at the first |
4175 | location. The watchpoint_check function will work on the | |
4176 | entire expression, not the individual locations. For | |
4177 | read watchpoints, the watchpoints_triggered function has | |
4178 | checked all locations already. */ | |
429374b8 JK |
4179 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
4180 | break; | |
18a18393 | 4181 | |
429374b8 JK |
4182 | if (bl->shlib_disabled) |
4183 | continue; | |
c5aa993b | 4184 | |
09ac7c10 | 4185 | if (!bpstat_check_location (bl, aspace, bp_addr, ws)) |
429374b8 | 4186 | continue; |
c5aa993b | 4187 | |
4a64f543 MS |
4188 | /* Come here if it's a watchpoint, or if the break address |
4189 | matches. */ | |
c5aa993b | 4190 | |
4a64f543 MS |
4191 | bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to |
4192 | explain stop. */ | |
c5aa993b | 4193 | |
f431efe5 PA |
4194 | /* Assume we stop. Should we find a watchpoint that is not |
4195 | actually triggered, or if the condition of the breakpoint | |
4196 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
4197 | bs->stop = 1; |
4198 | bs->print = 1; | |
d983da9c | 4199 | |
f431efe5 PA |
4200 | /* If this is a scope breakpoint, mark the associated |
4201 | watchpoint as triggered so that we will handle the | |
4202 | out-of-scope event. We'll get to the watchpoint next | |
4203 | iteration. */ | |
d0fb5eae | 4204 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
4205 | { |
4206 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
4207 | ||
4208 | w->watchpoint_triggered = watch_triggered_yes; | |
4209 | } | |
f431efe5 PA |
4210 | } |
4211 | } | |
4212 | ||
4213 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
4214 | { | |
f1310107 | 4215 | if (breakpoint_location_address_match (loc, aspace, bp_addr)) |
f431efe5 | 4216 | { |
5760d0ab | 4217 | bs = bpstat_alloc (loc, &bs_link); |
f431efe5 PA |
4218 | /* For hits of moribund locations, we should just proceed. */ |
4219 | bs->stop = 0; | |
4220 | bs->print = 0; | |
4221 | bs->print_it = print_it_noop; | |
4222 | } | |
4223 | } | |
4224 | ||
f431efe5 PA |
4225 | /* Now go through the locations that caused the target to stop, and |
4226 | check whether we're interested in reporting this stop to higher | |
4227 | layers, or whether we should resume the target transparently. */ | |
4228 | ||
4229 | removed_any = 0; | |
4230 | ||
5760d0ab | 4231 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
4232 | { |
4233 | if (!bs->stop) | |
4234 | continue; | |
4235 | ||
f431efe5 | 4236 | b = bs->breakpoint_at; |
348d480f PA |
4237 | b->ops->check_status (bs); |
4238 | if (bs->stop) | |
28010a5d | 4239 | { |
348d480f | 4240 | bpstat_check_breakpoint_conditions (bs, ptid); |
f431efe5 | 4241 | |
429374b8 JK |
4242 | if (bs->stop) |
4243 | { | |
4244 | ++(b->hit_count); | |
8d3788bd | 4245 | observer_notify_breakpoint_modified (b); |
c906108c | 4246 | |
4a64f543 | 4247 | /* We will stop here. */ |
429374b8 JK |
4248 | if (b->disposition == disp_disable) |
4249 | { | |
4250 | if (b->enable_state != bp_permanent) | |
4251 | b->enable_state = bp_disabled; | |
f431efe5 | 4252 | removed_any = 1; |
429374b8 JK |
4253 | } |
4254 | if (b->silent) | |
4255 | bs->print = 0; | |
4256 | bs->commands = b->commands; | |
9add0f1b | 4257 | incref_counted_command_line (bs->commands); |
abf85f46 JK |
4258 | if (command_line_is_silent (bs->commands |
4259 | ? bs->commands->commands : NULL)) | |
4260 | bs->print = 0; | |
429374b8 JK |
4261 | } |
4262 | ||
348d480f | 4263 | } |
a9b3a50f PA |
4264 | |
4265 | /* Print nothing for this entry if we don't stop or don't | |
4266 | print. */ | |
4267 | if (!bs->stop || !bs->print) | |
4268 | bs->print_it = print_it_noop; | |
429374b8 | 4269 | } |
876fa593 | 4270 | |
d983da9c DJ |
4271 | /* If we aren't stopping, the value of some hardware watchpoint may |
4272 | not have changed, but the intermediate memory locations we are | |
4273 | watching may have. Don't bother if we're stopping; this will get | |
4274 | done later. */ | |
d832cb68 | 4275 | need_remove_insert = 0; |
5760d0ab JK |
4276 | if (! bpstat_causes_stop (bs_head)) |
4277 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 4278 | if (!bs->stop |
f431efe5 PA |
4279 | && bs->breakpoint_at |
4280 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 4281 | { |
3a5c3e22 PA |
4282 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
4283 | ||
4284 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 4285 | need_remove_insert = 1; |
d983da9c DJ |
4286 | } |
4287 | ||
d832cb68 | 4288 | if (need_remove_insert) |
2d134ed3 | 4289 | update_global_location_list (1); |
f431efe5 PA |
4290 | else if (removed_any) |
4291 | update_global_location_list (0); | |
d832cb68 | 4292 | |
5760d0ab | 4293 | return bs_head; |
c906108c | 4294 | } |
628fe4e4 JK |
4295 | |
4296 | static void | |
4297 | handle_jit_event (void) | |
4298 | { | |
4299 | struct frame_info *frame; | |
4300 | struct gdbarch *gdbarch; | |
4301 | ||
4302 | /* Switch terminal for any messages produced by | |
4303 | breakpoint_re_set. */ | |
4304 | target_terminal_ours_for_output (); | |
4305 | ||
4306 | frame = get_current_frame (); | |
4307 | gdbarch = get_frame_arch (frame); | |
4308 | ||
4309 | jit_event_handler (gdbarch); | |
4310 | ||
4311 | target_terminal_inferior (); | |
4312 | } | |
4313 | ||
4314 | /* Prepare WHAT final decision for infrun. */ | |
4315 | ||
4316 | /* Decide what infrun needs to do with this bpstat. */ | |
4317 | ||
c906108c | 4318 | struct bpstat_what |
0e30163f | 4319 | bpstat_what (bpstat bs_head) |
c906108c | 4320 | { |
c906108c | 4321 | struct bpstat_what retval; |
628fe4e4 JK |
4322 | /* We need to defer calling `solib_add', as adding new symbols |
4323 | resets breakpoints, which in turn deletes breakpoint locations, | |
4324 | and hence may clear unprocessed entries in the BS chain. */ | |
4325 | int shlib_event = 0; | |
4326 | int jit_event = 0; | |
0e30163f | 4327 | bpstat bs; |
c906108c | 4328 | |
628fe4e4 | 4329 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 4330 | retval.call_dummy = STOP_NONE; |
186c406b | 4331 | retval.is_longjmp = 0; |
628fe4e4 | 4332 | |
0e30163f | 4333 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 4334 | { |
628fe4e4 JK |
4335 | /* Extract this BS's action. After processing each BS, we check |
4336 | if its action overrides all we've seem so far. */ | |
4337 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
4338 | enum bptype bptype; | |
4339 | ||
c906108c | 4340 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
4341 | { |
4342 | /* I suspect this can happen if it was a momentary | |
4343 | breakpoint which has since been deleted. */ | |
4344 | bptype = bp_none; | |
4345 | } | |
20874c92 | 4346 | else |
f431efe5 | 4347 | bptype = bs->breakpoint_at->type; |
628fe4e4 | 4348 | |
a9b3a50f PA |
4349 | if (bptype == bp_shlib_event) |
4350 | shlib_event = 1; | |
4351 | ||
628fe4e4 | 4352 | switch (bptype) |
c906108c SS |
4353 | { |
4354 | case bp_none: | |
628fe4e4 | 4355 | break; |
c906108c SS |
4356 | case bp_breakpoint: |
4357 | case bp_hardware_breakpoint: | |
4358 | case bp_until: | |
4359 | case bp_finish: | |
a9b3a50f | 4360 | case bp_shlib_event: |
c906108c SS |
4361 | if (bs->stop) |
4362 | { | |
4363 | if (bs->print) | |
628fe4e4 | 4364 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 4365 | else |
628fe4e4 | 4366 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
4367 | } |
4368 | else | |
628fe4e4 | 4369 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
4370 | break; |
4371 | case bp_watchpoint: | |
4372 | case bp_hardware_watchpoint: | |
4373 | case bp_read_watchpoint: | |
4374 | case bp_access_watchpoint: | |
4375 | if (bs->stop) | |
4376 | { | |
4377 | if (bs->print) | |
628fe4e4 | 4378 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 4379 | else |
628fe4e4 | 4380 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
4381 | } |
4382 | else | |
628fe4e4 JK |
4383 | { |
4384 | /* There was a watchpoint, but we're not stopping. | |
4385 | This requires no further action. */ | |
4386 | } | |
c906108c SS |
4387 | break; |
4388 | case bp_longjmp: | |
186c406b | 4389 | case bp_exception: |
628fe4e4 | 4390 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; |
186c406b | 4391 | retval.is_longjmp = bptype == bp_longjmp; |
c906108c SS |
4392 | break; |
4393 | case bp_longjmp_resume: | |
186c406b | 4394 | case bp_exception_resume: |
628fe4e4 | 4395 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; |
186c406b | 4396 | retval.is_longjmp = bptype == bp_longjmp_resume; |
c906108c SS |
4397 | break; |
4398 | case bp_step_resume: | |
4399 | if (bs->stop) | |
628fe4e4 JK |
4400 | this_action = BPSTAT_WHAT_STEP_RESUME; |
4401 | else | |
c906108c | 4402 | { |
628fe4e4 JK |
4403 | /* It is for the wrong frame. */ |
4404 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 4405 | } |
c906108c | 4406 | break; |
2c03e5be PA |
4407 | case bp_hp_step_resume: |
4408 | if (bs->stop) | |
4409 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
4410 | else | |
4411 | { | |
4412 | /* It is for the wrong frame. */ | |
4413 | this_action = BPSTAT_WHAT_SINGLE; | |
4414 | } | |
4415 | break; | |
c906108c | 4416 | case bp_watchpoint_scope: |
c4093a6a | 4417 | case bp_thread_event: |
1900040c | 4418 | case bp_overlay_event: |
0fd8e87f | 4419 | case bp_longjmp_master: |
aa7d318d | 4420 | case bp_std_terminate_master: |
186c406b | 4421 | case bp_exception_master: |
628fe4e4 | 4422 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 4423 | break; |
ce78b96d | 4424 | case bp_catchpoint: |
c5aa993b JM |
4425 | if (bs->stop) |
4426 | { | |
4427 | if (bs->print) | |
628fe4e4 | 4428 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 4429 | else |
628fe4e4 | 4430 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
4431 | } |
4432 | else | |
628fe4e4 JK |
4433 | { |
4434 | /* There was a catchpoint, but we're not stopping. | |
4435 | This requires no further action. */ | |
4436 | } | |
4437 | break; | |
628fe4e4 JK |
4438 | case bp_jit_event: |
4439 | jit_event = 1; | |
4440 | this_action = BPSTAT_WHAT_SINGLE; | |
c5aa993b | 4441 | break; |
c906108c | 4442 | case bp_call_dummy: |
53a5351d JM |
4443 | /* Make sure the action is stop (silent or noisy), |
4444 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 4445 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 4446 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
4447 | break; |
4448 | case bp_std_terminate: | |
4449 | /* Make sure the action is stop (silent or noisy), | |
4450 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 4451 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 4452 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 4453 | break; |
1042e4c0 | 4454 | case bp_tracepoint: |
7a697b8d | 4455 | case bp_fast_tracepoint: |
0fb4aa4b | 4456 | case bp_static_tracepoint: |
1042e4c0 SS |
4457 | /* Tracepoint hits should not be reported back to GDB, and |
4458 | if one got through somehow, it should have been filtered | |
4459 | out already. */ | |
4460 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 4461 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
4462 | break; |
4463 | case bp_gnu_ifunc_resolver: | |
4464 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
4465 | this_action = BPSTAT_WHAT_SINGLE; | |
4466 | break; | |
4467 | case bp_gnu_ifunc_resolver_return: | |
4468 | /* The breakpoint will be removed, execution will restart from the | |
4469 | PC of the former breakpoint. */ | |
4470 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
4471 | break; | |
628fe4e4 JK |
4472 | default: |
4473 | internal_error (__FILE__, __LINE__, | |
4474 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 4475 | } |
628fe4e4 JK |
4476 | |
4477 | retval.main_action = max (retval.main_action, this_action); | |
c906108c | 4478 | } |
628fe4e4 | 4479 | |
0e30163f JK |
4480 | /* These operations may affect the bs->breakpoint_at state so they are |
4481 | delayed after MAIN_ACTION is decided above. */ | |
4482 | ||
628fe4e4 JK |
4483 | if (shlib_event) |
4484 | { | |
4485 | if (debug_infrun) | |
4486 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_shlib_event\n"); | |
4487 | ||
4488 | /* Check for any newly added shared libraries if we're supposed | |
4489 | to be adding them automatically. */ | |
4490 | ||
4491 | /* Switch terminal for any messages produced by | |
4492 | breakpoint_re_set. */ | |
4493 | target_terminal_ours_for_output (); | |
4494 | ||
4495 | #ifdef SOLIB_ADD | |
4496 | SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add); | |
4497 | #else | |
4498 | solib_add (NULL, 0, ¤t_target, auto_solib_add); | |
4499 | #endif | |
4500 | ||
4501 | target_terminal_inferior (); | |
4502 | } | |
4503 | ||
4504 | if (jit_event) | |
4505 | { | |
4506 | if (debug_infrun) | |
4507 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n"); | |
4508 | ||
4509 | handle_jit_event (); | |
4510 | } | |
4511 | ||
0e30163f JK |
4512 | for (bs = bs_head; bs != NULL; bs = bs->next) |
4513 | { | |
4514 | struct breakpoint *b = bs->breakpoint_at; | |
4515 | ||
4516 | if (b == NULL) | |
4517 | continue; | |
4518 | switch (b->type) | |
4519 | { | |
4520 | case bp_gnu_ifunc_resolver: | |
4521 | gnu_ifunc_resolver_stop (b); | |
4522 | break; | |
4523 | case bp_gnu_ifunc_resolver_return: | |
4524 | gnu_ifunc_resolver_return_stop (b); | |
4525 | break; | |
4526 | } | |
4527 | } | |
4528 | ||
c906108c SS |
4529 | return retval; |
4530 | } | |
4531 | ||
4532 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
4533 | without hardware support). This isn't related to a specific bpstat, | |
4534 | just to things like whether watchpoints are set. */ | |
4535 | ||
c5aa993b | 4536 | int |
fba45db2 | 4537 | bpstat_should_step (void) |
c906108c SS |
4538 | { |
4539 | struct breakpoint *b; | |
cc59ec59 | 4540 | |
c906108c | 4541 | ALL_BREAKPOINTS (b) |
717a8278 | 4542 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 4543 | return 1; |
c906108c SS |
4544 | return 0; |
4545 | } | |
4546 | ||
67822962 PA |
4547 | int |
4548 | bpstat_causes_stop (bpstat bs) | |
4549 | { | |
4550 | for (; bs != NULL; bs = bs->next) | |
4551 | if (bs->stop) | |
4552 | return 1; | |
4553 | ||
4554 | return 0; | |
4555 | } | |
4556 | ||
c906108c | 4557 | \f |
c5aa993b | 4558 | |
170b53b2 UW |
4559 | /* Compute a string of spaces suitable to indent the next line |
4560 | so it starts at the position corresponding to the table column | |
4561 | named COL_NAME in the currently active table of UIOUT. */ | |
4562 | ||
4563 | static char * | |
4564 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
4565 | { | |
4566 | static char wrap_indent[80]; | |
4567 | int i, total_width, width, align; | |
4568 | char *text; | |
4569 | ||
4570 | total_width = 0; | |
4571 | for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++) | |
4572 | { | |
4573 | if (strcmp (text, col_name) == 0) | |
4574 | { | |
4575 | gdb_assert (total_width < sizeof wrap_indent); | |
4576 | memset (wrap_indent, ' ', total_width); | |
4577 | wrap_indent[total_width] = 0; | |
4578 | ||
4579 | return wrap_indent; | |
4580 | } | |
4581 | ||
4582 | total_width += width + 1; | |
4583 | } | |
4584 | ||
4585 | return NULL; | |
4586 | } | |
4587 | ||
859825b8 JK |
4588 | /* Print the LOC location out of the list of B->LOC locations. */ |
4589 | ||
170b53b2 UW |
4590 | static void |
4591 | print_breakpoint_location (struct breakpoint *b, | |
4592 | struct bp_location *loc) | |
0d381245 | 4593 | { |
79a45e25 | 4594 | struct ui_out *uiout = current_uiout; |
6c95b8df PA |
4595 | struct cleanup *old_chain = save_current_program_space (); |
4596 | ||
859825b8 JK |
4597 | if (loc != NULL && loc->shlib_disabled) |
4598 | loc = NULL; | |
4599 | ||
6c95b8df PA |
4600 | if (loc != NULL) |
4601 | set_current_program_space (loc->pspace); | |
4602 | ||
56435ebe TT |
4603 | if (b->display_canonical) |
4604 | ui_out_field_string (uiout, "what", b->addr_string); | |
f8eba3c6 | 4605 | else if (loc && loc->source_file) |
0d381245 VP |
4606 | { |
4607 | struct symbol *sym | |
4608 | = find_pc_sect_function (loc->address, loc->section); | |
4609 | if (sym) | |
4610 | { | |
4611 | ui_out_text (uiout, "in "); | |
4612 | ui_out_field_string (uiout, "func", | |
4613 | SYMBOL_PRINT_NAME (sym)); | |
170b53b2 UW |
4614 | ui_out_text (uiout, " "); |
4615 | ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what")); | |
4616 | ui_out_text (uiout, "at "); | |
0d381245 | 4617 | } |
f8eba3c6 | 4618 | ui_out_field_string (uiout, "file", loc->source_file); |
0d381245 VP |
4619 | ui_out_text (uiout, ":"); |
4620 | ||
4621 | if (ui_out_is_mi_like_p (uiout)) | |
4622 | { | |
4623 | struct symtab_and_line sal = find_pc_line (loc->address, 0); | |
4624 | char *fullname = symtab_to_fullname (sal.symtab); | |
4625 | ||
4626 | if (fullname) | |
4627 | ui_out_field_string (uiout, "fullname", fullname); | |
4628 | } | |
4629 | ||
f8eba3c6 | 4630 | ui_out_field_int (uiout, "line", loc->line_number); |
0d381245 | 4631 | } |
859825b8 | 4632 | else if (loc) |
0d381245 | 4633 | { |
170b53b2 UW |
4634 | struct ui_stream *stb = ui_out_stream_new (uiout); |
4635 | struct cleanup *stb_chain = make_cleanup_ui_out_stream_delete (stb); | |
4636 | ||
22e722e1 DJ |
4637 | print_address_symbolic (loc->gdbarch, loc->address, stb->stream, |
4638 | demangle, ""); | |
0d381245 | 4639 | ui_out_field_stream (uiout, "at", stb); |
170b53b2 UW |
4640 | |
4641 | do_cleanups (stb_chain); | |
0d381245 | 4642 | } |
859825b8 JK |
4643 | else |
4644 | ui_out_field_string (uiout, "pending", b->addr_string); | |
6c95b8df PA |
4645 | |
4646 | do_cleanups (old_chain); | |
0d381245 VP |
4647 | } |
4648 | ||
269b11a2 PA |
4649 | static const char * |
4650 | bptype_string (enum bptype type) | |
c906108c | 4651 | { |
c4093a6a JM |
4652 | struct ep_type_description |
4653 | { | |
4654 | enum bptype type; | |
4655 | char *description; | |
4656 | }; | |
4657 | static struct ep_type_description bptypes[] = | |
c906108c | 4658 | { |
c5aa993b JM |
4659 | {bp_none, "?deleted?"}, |
4660 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 4661 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
4662 | {bp_until, "until"}, |
4663 | {bp_finish, "finish"}, | |
4664 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 4665 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
4666 | {bp_read_watchpoint, "read watchpoint"}, |
4667 | {bp_access_watchpoint, "acc watchpoint"}, | |
4668 | {bp_longjmp, "longjmp"}, | |
4669 | {bp_longjmp_resume, "longjmp resume"}, | |
186c406b TT |
4670 | {bp_exception, "exception"}, |
4671 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 4672 | {bp_step_resume, "step resume"}, |
2c03e5be | 4673 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
4674 | {bp_watchpoint_scope, "watchpoint scope"}, |
4675 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 4676 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 4677 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 4678 | {bp_thread_event, "thread events"}, |
1900040c | 4679 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 4680 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 4681 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 4682 | {bp_exception_master, "exception master"}, |
ce78b96d | 4683 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 4684 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 4685 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 4686 | {bp_static_tracepoint, "static tracepoint"}, |
4efc6507 | 4687 | {bp_jit_event, "jit events"}, |
0e30163f JK |
4688 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
4689 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 4690 | }; |
269b11a2 PA |
4691 | |
4692 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
4693 | || ((int) type != bptypes[(int) type].type)) | |
4694 | internal_error (__FILE__, __LINE__, | |
4695 | _("bptypes table does not describe type #%d."), | |
4696 | (int) type); | |
4697 | ||
4698 | return bptypes[(int) type].description; | |
4699 | } | |
4700 | ||
4701 | /* Print B to gdb_stdout. */ | |
4702 | ||
4703 | static void | |
4704 | print_one_breakpoint_location (struct breakpoint *b, | |
4705 | struct bp_location *loc, | |
4706 | int loc_number, | |
4707 | struct bp_location **last_loc, | |
269b11a2 PA |
4708 | int allflag) |
4709 | { | |
4710 | struct command_line *l; | |
c2c6d25f | 4711 | static char bpenables[] = "nynny"; |
c906108c | 4712 | |
79a45e25 | 4713 | struct ui_out *uiout = current_uiout; |
0d381245 VP |
4714 | int header_of_multiple = 0; |
4715 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
4716 | struct value_print_options opts; |
4717 | ||
4718 | get_user_print_options (&opts); | |
0d381245 VP |
4719 | |
4720 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
4721 | /* See comment in print_one_breakpoint concerning treatment of |
4722 | breakpoints with single disabled location. */ | |
0d381245 VP |
4723 | if (loc == NULL |
4724 | && (b->loc != NULL | |
4725 | && (b->loc->next != NULL || !b->loc->enabled))) | |
4726 | header_of_multiple = 1; | |
4727 | if (loc == NULL) | |
4728 | loc = b->loc; | |
4729 | ||
c4093a6a JM |
4730 | annotate_record (); |
4731 | ||
4732 | /* 1 */ | |
4733 | annotate_field (0); | |
0d381245 VP |
4734 | if (part_of_multiple) |
4735 | { | |
4736 | char *formatted; | |
0c6773c1 | 4737 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
4738 | ui_out_field_string (uiout, "number", formatted); |
4739 | xfree (formatted); | |
4740 | } | |
4741 | else | |
4742 | { | |
4743 | ui_out_field_int (uiout, "number", b->number); | |
4744 | } | |
c4093a6a JM |
4745 | |
4746 | /* 2 */ | |
4747 | annotate_field (1); | |
0d381245 VP |
4748 | if (part_of_multiple) |
4749 | ui_out_field_skip (uiout, "type"); | |
269b11a2 PA |
4750 | else |
4751 | ui_out_field_string (uiout, "type", bptype_string (b->type)); | |
c4093a6a JM |
4752 | |
4753 | /* 3 */ | |
4754 | annotate_field (2); | |
0d381245 VP |
4755 | if (part_of_multiple) |
4756 | ui_out_field_skip (uiout, "disp"); | |
4757 | else | |
2cec12e5 | 4758 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 4759 | |
c4093a6a JM |
4760 | |
4761 | /* 4 */ | |
4762 | annotate_field (3); | |
0d381245 | 4763 | if (part_of_multiple) |
54e52265 | 4764 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 4765 | else |
4a64f543 MS |
4766 | ui_out_field_fmt (uiout, "enabled", "%c", |
4767 | bpenables[(int) b->enable_state]); | |
54e52265 | 4768 | ui_out_spaces (uiout, 2); |
0d381245 | 4769 | |
c4093a6a JM |
4770 | |
4771 | /* 5 and 6 */ | |
3086aeae | 4772 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 4773 | { |
4a64f543 MS |
4774 | /* Although the print_one can possibly print all locations, |
4775 | calling it here is not likely to get any nice result. So, | |
4776 | make sure there's just one location. */ | |
0d381245 | 4777 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 4778 | b->ops->print_one (b, last_loc); |
0d381245 | 4779 | } |
3086aeae DJ |
4780 | else |
4781 | switch (b->type) | |
4782 | { | |
4783 | case bp_none: | |
4784 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 4785 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 4786 | break; |
c906108c | 4787 | |
3086aeae DJ |
4788 | case bp_watchpoint: |
4789 | case bp_hardware_watchpoint: | |
4790 | case bp_read_watchpoint: | |
4791 | case bp_access_watchpoint: | |
3a5c3e22 PA |
4792 | { |
4793 | struct watchpoint *w = (struct watchpoint *) b; | |
4794 | ||
4795 | /* Field 4, the address, is omitted (which makes the columns | |
4796 | not line up too nicely with the headers, but the effect | |
4797 | is relatively readable). */ | |
4798 | if (opts.addressprint) | |
4799 | ui_out_field_skip (uiout, "addr"); | |
4800 | annotate_field (5); | |
4801 | ui_out_field_string (uiout, "what", w->exp_string); | |
4802 | } | |
3086aeae DJ |
4803 | break; |
4804 | ||
3086aeae DJ |
4805 | case bp_breakpoint: |
4806 | case bp_hardware_breakpoint: | |
4807 | case bp_until: | |
4808 | case bp_finish: | |
4809 | case bp_longjmp: | |
4810 | case bp_longjmp_resume: | |
186c406b TT |
4811 | case bp_exception: |
4812 | case bp_exception_resume: | |
3086aeae | 4813 | case bp_step_resume: |
2c03e5be | 4814 | case bp_hp_step_resume: |
3086aeae DJ |
4815 | case bp_watchpoint_scope: |
4816 | case bp_call_dummy: | |
aa7d318d | 4817 | case bp_std_terminate: |
3086aeae DJ |
4818 | case bp_shlib_event: |
4819 | case bp_thread_event: | |
4820 | case bp_overlay_event: | |
0fd8e87f | 4821 | case bp_longjmp_master: |
aa7d318d | 4822 | case bp_std_terminate_master: |
186c406b | 4823 | case bp_exception_master: |
1042e4c0 | 4824 | case bp_tracepoint: |
7a697b8d | 4825 | case bp_fast_tracepoint: |
0fb4aa4b | 4826 | case bp_static_tracepoint: |
4efc6507 | 4827 | case bp_jit_event: |
0e30163f JK |
4828 | case bp_gnu_ifunc_resolver: |
4829 | case bp_gnu_ifunc_resolver_return: | |
79a45b7d | 4830 | if (opts.addressprint) |
3086aeae DJ |
4831 | { |
4832 | annotate_field (4); | |
54e52265 | 4833 | if (header_of_multiple) |
0d381245 | 4834 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 4835 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 4836 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 4837 | else |
5af949e3 UW |
4838 | ui_out_field_core_addr (uiout, "addr", |
4839 | loc->gdbarch, loc->address); | |
3086aeae DJ |
4840 | } |
4841 | annotate_field (5); | |
0d381245 | 4842 | if (!header_of_multiple) |
170b53b2 | 4843 | print_breakpoint_location (b, loc); |
0d381245 | 4844 | if (b->loc) |
a6d9a66e | 4845 | *last_loc = b->loc; |
3086aeae DJ |
4846 | break; |
4847 | } | |
c906108c | 4848 | |
6c95b8df PA |
4849 | |
4850 | /* For backward compatibility, don't display inferiors unless there | |
4851 | are several. */ | |
4852 | if (loc != NULL | |
4853 | && !header_of_multiple | |
4854 | && (allflag | |
4855 | || (!gdbarch_has_global_breakpoints (target_gdbarch) | |
4856 | && (number_of_program_spaces () > 1 | |
4857 | || number_of_inferiors () > 1) | |
4a64f543 MS |
4858 | /* LOC is for existing B, it cannot be in |
4859 | moribund_locations and thus having NULL OWNER. */ | |
6c95b8df PA |
4860 | && loc->owner->type != bp_catchpoint))) |
4861 | { | |
4862 | struct inferior *inf; | |
4863 | int first = 1; | |
4864 | ||
4865 | for (inf = inferior_list; inf != NULL; inf = inf->next) | |
4866 | { | |
4867 | if (inf->pspace == loc->pspace) | |
4868 | { | |
4869 | if (first) | |
4870 | { | |
4871 | first = 0; | |
4872 | ui_out_text (uiout, " inf "); | |
4873 | } | |
4874 | else | |
4875 | ui_out_text (uiout, ", "); | |
4876 | ui_out_text (uiout, plongest (inf->num)); | |
4877 | } | |
4878 | } | |
4879 | } | |
4880 | ||
4a306c9a | 4881 | if (!part_of_multiple) |
c4093a6a | 4882 | { |
4a306c9a JB |
4883 | if (b->thread != -1) |
4884 | { | |
4885 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 4886 | "stop only in" line a little further down. */ |
4a306c9a JB |
4887 | ui_out_text (uiout, " thread "); |
4888 | ui_out_field_int (uiout, "thread", b->thread); | |
4889 | } | |
4890 | else if (b->task != 0) | |
4891 | { | |
4892 | ui_out_text (uiout, " task "); | |
4893 | ui_out_field_int (uiout, "task", b->task); | |
4894 | } | |
c4093a6a | 4895 | } |
f1310107 | 4896 | |
8b93c638 | 4897 | ui_out_text (uiout, "\n"); |
f1310107 | 4898 | |
348d480f | 4899 | if (!part_of_multiple) |
f1310107 TJB |
4900 | b->ops->print_one_detail (b, uiout); |
4901 | ||
0d381245 | 4902 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
4903 | { |
4904 | annotate_field (6); | |
8b93c638 | 4905 | ui_out_text (uiout, "\tstop only in stack frame at "); |
e5dd4106 | 4906 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
818dd999 | 4907 | the frame ID. */ |
5af949e3 UW |
4908 | ui_out_field_core_addr (uiout, "frame", |
4909 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 4910 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
4911 | } |
4912 | ||
28010a5d | 4913 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
4914 | { |
4915 | annotate_field (7); | |
d77f58be | 4916 | if (is_tracepoint (b)) |
1042e4c0 SS |
4917 | ui_out_text (uiout, "\ttrace only if "); |
4918 | else | |
4919 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 JJ |
4920 | ui_out_field_string (uiout, "cond", b->cond_string); |
4921 | ui_out_text (uiout, "\n"); | |
4922 | } | |
4923 | ||
0d381245 | 4924 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 4925 | { |
4a64f543 | 4926 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
4927 | ui_out_text (uiout, "\tstop only in thread "); |
4928 | ui_out_field_int (uiout, "thread", b->thread); | |
4929 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
4930 | } |
4931 | ||
63c715c6 | 4932 | if (!part_of_multiple && b->hit_count) |
c4093a6a | 4933 | { |
4a64f543 | 4934 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
4935 | if (ep_is_catchpoint (b)) |
4936 | ui_out_text (uiout, "\tcatchpoint"); | |
f196051f SS |
4937 | else if (is_tracepoint (b)) |
4938 | ui_out_text (uiout, "\ttracepoint"); | |
8b93c638 JM |
4939 | else |
4940 | ui_out_text (uiout, "\tbreakpoint"); | |
4941 | ui_out_text (uiout, " already hit "); | |
4942 | ui_out_field_int (uiout, "times", b->hit_count); | |
4943 | if (b->hit_count == 1) | |
4944 | ui_out_text (uiout, " time\n"); | |
4945 | else | |
4946 | ui_out_text (uiout, " times\n"); | |
c4093a6a JM |
4947 | } |
4948 | ||
4a64f543 MS |
4949 | /* Output the count also if it is zero, but only if this is mi. |
4950 | FIXME: Should have a better test for this. */ | |
9dc5e2a9 | 4951 | if (ui_out_is_mi_like_p (uiout)) |
63c715c6 | 4952 | if (!part_of_multiple && b->hit_count == 0) |
fb40c209 | 4953 | ui_out_field_int (uiout, "times", b->hit_count); |
8b93c638 | 4954 | |
0d381245 | 4955 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
4956 | { |
4957 | annotate_field (8); | |
8b93c638 JM |
4958 | ui_out_text (uiout, "\tignore next "); |
4959 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
4960 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 4961 | } |
059fb39f | 4962 | |
f196051f SS |
4963 | if (!part_of_multiple && is_tracepoint (b)) |
4964 | { | |
4965 | struct tracepoint *tp = (struct tracepoint *) b; | |
4966 | ||
4967 | if (tp->traceframe_usage) | |
4968 | { | |
4969 | ui_out_text (uiout, "\ttrace buffer usage "); | |
4970 | ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage); | |
4971 | ui_out_text (uiout, " bytes\n"); | |
4972 | } | |
4973 | } | |
4974 | ||
9add0f1b | 4975 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 4976 | if (!part_of_multiple && l) |
c4093a6a | 4977 | { |
3b31d625 EZ |
4978 | struct cleanup *script_chain; |
4979 | ||
c4093a6a | 4980 | annotate_field (9); |
3b31d625 | 4981 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 4982 | print_command_lines (uiout, l, 4); |
3b31d625 | 4983 | do_cleanups (script_chain); |
c4093a6a | 4984 | } |
d24317b4 | 4985 | |
d9b3f62e | 4986 | if (is_tracepoint (b)) |
1042e4c0 | 4987 | { |
d9b3f62e PA |
4988 | struct tracepoint *t = (struct tracepoint *) b; |
4989 | ||
4990 | if (!part_of_multiple && t->pass_count) | |
4991 | { | |
4992 | annotate_field (10); | |
4993 | ui_out_text (uiout, "\tpass count "); | |
4994 | ui_out_field_int (uiout, "pass", t->pass_count); | |
4995 | ui_out_text (uiout, " \n"); | |
4996 | } | |
1042e4c0 SS |
4997 | } |
4998 | ||
d24317b4 VP |
4999 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
5000 | { | |
3a5c3e22 PA |
5001 | if (is_watchpoint (b)) |
5002 | { | |
5003 | struct watchpoint *w = (struct watchpoint *) b; | |
5004 | ||
5005 | ui_out_field_string (uiout, "original-location", w->exp_string); | |
5006 | } | |
5007 | else if (b->addr_string) | |
d24317b4 | 5008 | ui_out_field_string (uiout, "original-location", b->addr_string); |
d24317b4 | 5009 | } |
c4093a6a | 5010 | } |
c5aa993b | 5011 | |
0d381245 VP |
5012 | static void |
5013 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 5014 | struct bp_location **last_loc, |
6c95b8df | 5015 | int allflag) |
0d381245 | 5016 | { |
8d3788bd | 5017 | struct cleanup *bkpt_chain; |
79a45e25 | 5018 | struct ui_out *uiout = current_uiout; |
8d3788bd VP |
5019 | |
5020 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); | |
5021 | ||
12c5a436 | 5022 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); |
8d3788bd | 5023 | do_cleanups (bkpt_chain); |
0d381245 VP |
5024 | |
5025 | /* If this breakpoint has custom print function, | |
5026 | it's already printed. Otherwise, print individual | |
5027 | locations, if any. */ | |
5028 | if (b->ops == NULL || b->ops->print_one == NULL) | |
5029 | { | |
4a64f543 MS |
5030 | /* If breakpoint has a single location that is disabled, we |
5031 | print it as if it had several locations, since otherwise it's | |
5032 | hard to represent "breakpoint enabled, location disabled" | |
5033 | situation. | |
5034 | ||
5035 | Note that while hardware watchpoints have several locations | |
a3be7890 | 5036 | internally, that's not a property exposed to user. */ |
0d381245 | 5037 | if (b->loc |
a5606eee | 5038 | && !is_hardware_watchpoint (b) |
8d3788bd | 5039 | && (b->loc->next || !b->loc->enabled)) |
0d381245 VP |
5040 | { |
5041 | struct bp_location *loc; | |
5042 | int n = 1; | |
8d3788bd | 5043 | |
0d381245 | 5044 | for (loc = b->loc; loc; loc = loc->next, ++n) |
8d3788bd VP |
5045 | { |
5046 | struct cleanup *inner2 = | |
5047 | make_cleanup_ui_out_tuple_begin_end (uiout, NULL); | |
5048 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); | |
5049 | do_cleanups (inner2); | |
5050 | } | |
0d381245 VP |
5051 | } |
5052 | } | |
5053 | } | |
5054 | ||
a6d9a66e UW |
5055 | static int |
5056 | breakpoint_address_bits (struct breakpoint *b) | |
5057 | { | |
5058 | int print_address_bits = 0; | |
5059 | struct bp_location *loc; | |
5060 | ||
5061 | for (loc = b->loc; loc; loc = loc->next) | |
5062 | { | |
c7437ca6 PA |
5063 | int addr_bit; |
5064 | ||
5065 | /* Software watchpoints that aren't watching memory don't have | |
5066 | an address to print. */ | |
5067 | if (b->type == bp_watchpoint && loc->watchpoint_type == -1) | |
5068 | continue; | |
5069 | ||
5070 | addr_bit = gdbarch_addr_bit (loc->gdbarch); | |
a6d9a66e UW |
5071 | if (addr_bit > print_address_bits) |
5072 | print_address_bits = addr_bit; | |
5073 | } | |
5074 | ||
5075 | return print_address_bits; | |
5076 | } | |
0d381245 | 5077 | |
c4093a6a JM |
5078 | struct captured_breakpoint_query_args |
5079 | { | |
5080 | int bnum; | |
5081 | }; | |
c5aa993b | 5082 | |
c4093a6a | 5083 | static int |
2b65245e | 5084 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
5085 | { |
5086 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 5087 | struct breakpoint *b; |
a6d9a66e | 5088 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 5089 | |
c4093a6a JM |
5090 | ALL_BREAKPOINTS (b) |
5091 | { | |
5092 | if (args->bnum == b->number) | |
c5aa993b | 5093 | { |
12c5a436 | 5094 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 5095 | return GDB_RC_OK; |
c5aa993b | 5096 | } |
c4093a6a JM |
5097 | } |
5098 | return GDB_RC_NONE; | |
5099 | } | |
c5aa993b | 5100 | |
c4093a6a | 5101 | enum gdb_rc |
4a64f543 MS |
5102 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, |
5103 | char **error_message) | |
c4093a6a JM |
5104 | { |
5105 | struct captured_breakpoint_query_args args; | |
cc59ec59 | 5106 | |
c4093a6a JM |
5107 | args.bnum = bnum; |
5108 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4a64f543 | 5109 | an error. */ |
b0b13bb4 DJ |
5110 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
5111 | error_message, RETURN_MASK_ALL) < 0) | |
5112 | return GDB_RC_FAIL; | |
5113 | else | |
5114 | return GDB_RC_OK; | |
c4093a6a | 5115 | } |
c5aa993b | 5116 | |
09d682a4 TT |
5117 | /* Return true if this breakpoint was set by the user, false if it is |
5118 | internal or momentary. */ | |
5119 | ||
5120 | int | |
5121 | user_breakpoint_p (struct breakpoint *b) | |
5122 | { | |
46c6471b | 5123 | return b->number > 0; |
09d682a4 TT |
5124 | } |
5125 | ||
7f3b0473 | 5126 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
5127 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
5128 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
5129 | FILTER is non-NULL, call it on each breakpoint and only include the | |
5130 | ones for which it returns non-zero. Return the total number of | |
5131 | breakpoints listed. */ | |
c906108c | 5132 | |
d77f58be | 5133 | static int |
e5a67952 | 5134 | breakpoint_1 (char *args, int allflag, |
4a64f543 | 5135 | int (*filter) (const struct breakpoint *)) |
c4093a6a | 5136 | { |
52f0bd74 | 5137 | struct breakpoint *b; |
a6d9a66e | 5138 | struct bp_location *last_loc = NULL; |
7f3b0473 | 5139 | int nr_printable_breakpoints; |
3b31d625 | 5140 | struct cleanup *bkpttbl_chain; |
79a45b7d | 5141 | struct value_print_options opts; |
a6d9a66e | 5142 | int print_address_bits = 0; |
269b11a2 | 5143 | int print_type_col_width = 14; |
79a45e25 | 5144 | struct ui_out *uiout = current_uiout; |
269b11a2 | 5145 | |
79a45b7d TT |
5146 | get_user_print_options (&opts); |
5147 | ||
4a64f543 MS |
5148 | /* Compute the number of rows in the table, as well as the size |
5149 | required for address fields. */ | |
7f3b0473 AC |
5150 | nr_printable_breakpoints = 0; |
5151 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
5152 | { |
5153 | /* If we have a filter, only list the breakpoints it accepts. */ | |
5154 | if (filter && !filter (b)) | |
5155 | continue; | |
5156 | ||
5157 | /* If we have an "args" string, it is a list of breakpoints to | |
5158 | accept. Skip the others. */ | |
5159 | if (args != NULL && *args != '\0') | |
5160 | { | |
5161 | if (allflag && parse_and_eval_long (args) != b->number) | |
5162 | continue; | |
5163 | if (!allflag && !number_is_in_list (args, b->number)) | |
5164 | continue; | |
5165 | } | |
269b11a2 | 5166 | |
e5a67952 MS |
5167 | if (allflag || user_breakpoint_p (b)) |
5168 | { | |
5169 | int addr_bit, type_len; | |
a6d9a66e | 5170 | |
e5a67952 MS |
5171 | addr_bit = breakpoint_address_bits (b); |
5172 | if (addr_bit > print_address_bits) | |
5173 | print_address_bits = addr_bit; | |
269b11a2 | 5174 | |
e5a67952 MS |
5175 | type_len = strlen (bptype_string (b->type)); |
5176 | if (type_len > print_type_col_width) | |
5177 | print_type_col_width = type_len; | |
5178 | ||
5179 | nr_printable_breakpoints++; | |
5180 | } | |
5181 | } | |
7f3b0473 | 5182 | |
79a45b7d | 5183 | if (opts.addressprint) |
3b31d625 | 5184 | bkpttbl_chain |
3e43a32a MS |
5185 | = make_cleanup_ui_out_table_begin_end (uiout, 6, |
5186 | nr_printable_breakpoints, | |
3b31d625 | 5187 | "BreakpointTable"); |
8b93c638 | 5188 | else |
3b31d625 | 5189 | bkpttbl_chain |
3e43a32a MS |
5190 | = make_cleanup_ui_out_table_begin_end (uiout, 5, |
5191 | nr_printable_breakpoints, | |
3b31d625 | 5192 | "BreakpointTable"); |
8b93c638 | 5193 | |
7f3b0473 | 5194 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
5195 | annotate_breakpoints_headers (); |
5196 | if (nr_printable_breakpoints > 0) | |
5197 | annotate_field (0); | |
4a64f543 | 5198 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
5199 | if (nr_printable_breakpoints > 0) |
5200 | annotate_field (1); | |
269b11a2 | 5201 | ui_out_table_header (uiout, print_type_col_width, ui_left, |
4a64f543 | 5202 | "type", "Type"); /* 2 */ |
d7faa9e7 AC |
5203 | if (nr_printable_breakpoints > 0) |
5204 | annotate_field (2); | |
4a64f543 | 5205 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ |
d7faa9e7 AC |
5206 | if (nr_printable_breakpoints > 0) |
5207 | annotate_field (3); | |
54e52265 | 5208 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 5209 | if (opts.addressprint) |
e5a67952 MS |
5210 | { |
5211 | if (nr_printable_breakpoints > 0) | |
5212 | annotate_field (4); | |
5213 | if (print_address_bits <= 32) | |
5214 | ui_out_table_header (uiout, 10, ui_left, | |
5215 | "addr", "Address"); /* 5 */ | |
5216 | else | |
5217 | ui_out_table_header (uiout, 18, ui_left, | |
5218 | "addr", "Address"); /* 5 */ | |
5219 | } | |
d7faa9e7 AC |
5220 | if (nr_printable_breakpoints > 0) |
5221 | annotate_field (5); | |
5222 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
5223 | ui_out_table_body (uiout); | |
5224 | if (nr_printable_breakpoints > 0) | |
5225 | annotate_breakpoints_table (); | |
7f3b0473 | 5226 | |
c4093a6a | 5227 | ALL_BREAKPOINTS (b) |
e5a67952 MS |
5228 | { |
5229 | QUIT; | |
5230 | /* If we have a filter, only list the breakpoints it accepts. */ | |
5231 | if (filter && !filter (b)) | |
5232 | continue; | |
5233 | ||
5234 | /* If we have an "args" string, it is a list of breakpoints to | |
5235 | accept. Skip the others. */ | |
5236 | ||
5237 | if (args != NULL && *args != '\0') | |
5238 | { | |
5239 | if (allflag) /* maintenance info breakpoint */ | |
5240 | { | |
5241 | if (parse_and_eval_long (args) != b->number) | |
5242 | continue; | |
5243 | } | |
5244 | else /* all others */ | |
5245 | { | |
5246 | if (!number_is_in_list (args, b->number)) | |
5247 | continue; | |
5248 | } | |
5249 | } | |
5250 | /* We only print out user settable breakpoints unless the | |
5251 | allflag is set. */ | |
5252 | if (allflag || user_breakpoint_p (b)) | |
12c5a436 | 5253 | print_one_breakpoint (b, &last_loc, allflag); |
e5a67952 MS |
5254 | } |
5255 | ||
3b31d625 | 5256 | do_cleanups (bkpttbl_chain); |
698384cd | 5257 | |
7f3b0473 | 5258 | if (nr_printable_breakpoints == 0) |
c906108c | 5259 | { |
4a64f543 MS |
5260 | /* If there's a filter, let the caller decide how to report |
5261 | empty list. */ | |
d77f58be SS |
5262 | if (!filter) |
5263 | { | |
e5a67952 | 5264 | if (args == NULL || *args == '\0') |
d77f58be SS |
5265 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); |
5266 | else | |
4a64f543 | 5267 | ui_out_message (uiout, 0, |
e5a67952 MS |
5268 | "No breakpoint or watchpoint matching '%s'.\n", |
5269 | args); | |
d77f58be | 5270 | } |
c906108c SS |
5271 | } |
5272 | else | |
c4093a6a | 5273 | { |
a6d9a66e UW |
5274 | if (last_loc && !server_command) |
5275 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 5276 | } |
c906108c | 5277 | |
4a64f543 | 5278 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 5279 | there have been breakpoints? */ |
c906108c | 5280 | annotate_breakpoints_table_end (); |
d77f58be SS |
5281 | |
5282 | return nr_printable_breakpoints; | |
c906108c SS |
5283 | } |
5284 | ||
ad443146 SS |
5285 | /* Display the value of default-collect in a way that is generally |
5286 | compatible with the breakpoint list. */ | |
5287 | ||
5288 | static void | |
5289 | default_collect_info (void) | |
5290 | { | |
79a45e25 PA |
5291 | struct ui_out *uiout = current_uiout; |
5292 | ||
ad443146 SS |
5293 | /* If it has no value (which is frequently the case), say nothing; a |
5294 | message like "No default-collect." gets in user's face when it's | |
5295 | not wanted. */ | |
5296 | if (!*default_collect) | |
5297 | return; | |
5298 | ||
5299 | /* The following phrase lines up nicely with per-tracepoint collect | |
5300 | actions. */ | |
5301 | ui_out_text (uiout, "default collect "); | |
5302 | ui_out_field_string (uiout, "default-collect", default_collect); | |
5303 | ui_out_text (uiout, " \n"); | |
5304 | } | |
5305 | ||
c906108c | 5306 | static void |
e5a67952 | 5307 | breakpoints_info (char *args, int from_tty) |
c906108c | 5308 | { |
e5a67952 | 5309 | breakpoint_1 (args, 0, NULL); |
ad443146 SS |
5310 | |
5311 | default_collect_info (); | |
d77f58be SS |
5312 | } |
5313 | ||
5314 | static void | |
e5a67952 | 5315 | watchpoints_info (char *args, int from_tty) |
d77f58be | 5316 | { |
e5a67952 | 5317 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
79a45e25 | 5318 | struct ui_out *uiout = current_uiout; |
d77f58be SS |
5319 | |
5320 | if (num_printed == 0) | |
5321 | { | |
e5a67952 | 5322 | if (args == NULL || *args == '\0') |
d77f58be SS |
5323 | ui_out_message (uiout, 0, "No watchpoints.\n"); |
5324 | else | |
e5a67952 | 5325 | ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args); |
d77f58be | 5326 | } |
c906108c SS |
5327 | } |
5328 | ||
7a292a7a | 5329 | static void |
e5a67952 | 5330 | maintenance_info_breakpoints (char *args, int from_tty) |
c906108c | 5331 | { |
e5a67952 | 5332 | breakpoint_1 (args, 1, NULL); |
ad443146 SS |
5333 | |
5334 | default_collect_info (); | |
c906108c SS |
5335 | } |
5336 | ||
0d381245 | 5337 | static int |
714835d5 | 5338 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 5339 | struct program_space *pspace, |
714835d5 | 5340 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
5341 | { |
5342 | struct bp_location *bl = b->loc; | |
cc59ec59 | 5343 | |
0d381245 VP |
5344 | for (; bl; bl = bl->next) |
5345 | { | |
6c95b8df PA |
5346 | if (bl->pspace == pspace |
5347 | && bl->address == pc | |
0d381245 VP |
5348 | && (!overlay_debugging || bl->section == section)) |
5349 | return 1; | |
5350 | } | |
5351 | return 0; | |
5352 | } | |
5353 | ||
672f9b60 | 5354 | /* Print a message describing any user-breakpoints set at PC. This |
6c95b8df PA |
5355 | concerns with logical breakpoints, so we match program spaces, not |
5356 | address spaces. */ | |
c906108c SS |
5357 | |
5358 | static void | |
6c95b8df PA |
5359 | describe_other_breakpoints (struct gdbarch *gdbarch, |
5360 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 5361 | struct obj_section *section, int thread) |
c906108c | 5362 | { |
52f0bd74 AC |
5363 | int others = 0; |
5364 | struct breakpoint *b; | |
c906108c SS |
5365 | |
5366 | ALL_BREAKPOINTS (b) | |
672f9b60 KP |
5367 | others += (user_breakpoint_p (b) |
5368 | && breakpoint_has_pc (b, pspace, pc, section)); | |
c906108c SS |
5369 | if (others > 0) |
5370 | { | |
a3f17187 AC |
5371 | if (others == 1) |
5372 | printf_filtered (_("Note: breakpoint ")); | |
5373 | else /* if (others == ???) */ | |
5374 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 5375 | ALL_BREAKPOINTS (b) |
672f9b60 | 5376 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
5377 | { |
5378 | others--; | |
5379 | printf_filtered ("%d", b->number); | |
5380 | if (b->thread == -1 && thread != -1) | |
5381 | printf_filtered (" (all threads)"); | |
5382 | else if (b->thread != -1) | |
5383 | printf_filtered (" (thread %d)", b->thread); | |
5384 | printf_filtered ("%s%s ", | |
059fb39f | 5385 | ((b->enable_state == bp_disabled |
f8eba3c6 | 5386 | || b->enable_state == bp_call_disabled) |
0d381245 VP |
5387 | ? " (disabled)" |
5388 | : b->enable_state == bp_permanent | |
5389 | ? " (permanent)" | |
5390 | : ""), | |
5391 | (others > 1) ? "," | |
5392 | : ((others == 1) ? " and" : "")); | |
5393 | } | |
a3f17187 | 5394 | printf_filtered (_("also set at pc ")); |
5af949e3 | 5395 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
5396 | printf_filtered (".\n"); |
5397 | } | |
5398 | } | |
5399 | \f | |
c906108c | 5400 | |
e4f237da KB |
5401 | /* Return true iff it is meaningful to use the address member of |
5402 | BPT. For some breakpoint types, the address member is irrelevant | |
5403 | and it makes no sense to attempt to compare it to other addresses | |
5404 | (or use it for any other purpose either). | |
5405 | ||
4a64f543 MS |
5406 | More specifically, each of the following breakpoint types will |
5407 | always have a zero valued address and we don't want to mark | |
5408 | breakpoints of any of these types to be a duplicate of an actual | |
5409 | breakpoint at address zero: | |
e4f237da KB |
5410 | |
5411 | bp_watchpoint | |
2d134ed3 PA |
5412 | bp_catchpoint |
5413 | ||
5414 | */ | |
e4f237da KB |
5415 | |
5416 | static int | |
5417 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
5418 | { | |
5419 | enum bptype type = bpt->type; | |
5420 | ||
2d134ed3 PA |
5421 | return (type != bp_watchpoint && type != bp_catchpoint); |
5422 | } | |
5423 | ||
5424 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
5425 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
5426 | ||
5427 | static int | |
4a64f543 MS |
5428 | watchpoint_locations_match (struct bp_location *loc1, |
5429 | struct bp_location *loc2) | |
2d134ed3 | 5430 | { |
3a5c3e22 PA |
5431 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
5432 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
5433 | ||
5434 | /* Both of them must exist. */ | |
5435 | gdb_assert (w1 != NULL); | |
5436 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 5437 | |
4a64f543 MS |
5438 | /* If the target can evaluate the condition expression in hardware, |
5439 | then we we need to insert both watchpoints even if they are at | |
5440 | the same place. Otherwise the watchpoint will only trigger when | |
5441 | the condition of whichever watchpoint was inserted evaluates to | |
5442 | true, not giving a chance for GDB to check the condition of the | |
5443 | other watchpoint. */ | |
3a5c3e22 | 5444 | if ((w1->cond_exp |
4a64f543 MS |
5445 | && target_can_accel_watchpoint_condition (loc1->address, |
5446 | loc1->length, | |
0cf6dd15 | 5447 | loc1->watchpoint_type, |
3a5c3e22 PA |
5448 | w1->cond_exp)) |
5449 | || (w2->cond_exp | |
4a64f543 MS |
5450 | && target_can_accel_watchpoint_condition (loc2->address, |
5451 | loc2->length, | |
0cf6dd15 | 5452 | loc2->watchpoint_type, |
3a5c3e22 | 5453 | w2->cond_exp))) |
0cf6dd15 TJB |
5454 | return 0; |
5455 | ||
85d721b8 PA |
5456 | /* Note that this checks the owner's type, not the location's. In |
5457 | case the target does not support read watchpoints, but does | |
5458 | support access watchpoints, we'll have bp_read_watchpoint | |
5459 | watchpoints with hw_access locations. Those should be considered | |
5460 | duplicates of hw_read locations. The hw_read locations will | |
5461 | become hw_access locations later. */ | |
2d134ed3 PA |
5462 | return (loc1->owner->type == loc2->owner->type |
5463 | && loc1->pspace->aspace == loc2->pspace->aspace | |
5464 | && loc1->address == loc2->address | |
5465 | && loc1->length == loc2->length); | |
e4f237da KB |
5466 | } |
5467 | ||
6c95b8df PA |
5468 | /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the |
5469 | same breakpoint location. In most targets, this can only be true | |
5470 | if ASPACE1 matches ASPACE2. On targets that have global | |
5471 | breakpoints, the address space doesn't really matter. */ | |
5472 | ||
5473 | static int | |
5474 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, | |
5475 | struct address_space *aspace2, CORE_ADDR addr2) | |
5476 | { | |
5477 | return ((gdbarch_has_global_breakpoints (target_gdbarch) | |
5478 | || aspace1 == aspace2) | |
5479 | && addr1 == addr2); | |
5480 | } | |
5481 | ||
f1310107 TJB |
5482 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
5483 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
5484 | matches ASPACE2. On targets that have global breakpoints, the address | |
5485 | space doesn't really matter. */ | |
5486 | ||
5487 | static int | |
5488 | breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1, | |
5489 | int len1, struct address_space *aspace2, | |
5490 | CORE_ADDR addr2) | |
5491 | { | |
5492 | return ((gdbarch_has_global_breakpoints (target_gdbarch) | |
5493 | || aspace1 == aspace2) | |
5494 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
5495 | } | |
5496 | ||
5497 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
5498 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
5499 | matches the breakpoint's address space. On targets that have global | |
5500 | breakpoints, the address space doesn't really matter. */ | |
5501 | ||
5502 | static int | |
5503 | breakpoint_location_address_match (struct bp_location *bl, | |
5504 | struct address_space *aspace, | |
5505 | CORE_ADDR addr) | |
5506 | { | |
5507 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
5508 | aspace, addr) | |
5509 | || (bl->length | |
5510 | && breakpoint_address_match_range (bl->pspace->aspace, | |
5511 | bl->address, bl->length, | |
5512 | aspace, addr))); | |
5513 | } | |
5514 | ||
1e4d1764 YQ |
5515 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
5516 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns | |
5517 | true, otherwise returns false. */ | |
5518 | ||
5519 | static int | |
5520 | tracepoint_locations_match (struct bp_location *loc1, | |
5521 | struct bp_location *loc2) | |
5522 | { | |
5523 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) | |
5524 | /* Since tracepoint locations are never duplicated with others', tracepoint | |
5525 | locations at the same address of different tracepoints are regarded as | |
5526 | different locations. */ | |
5527 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); | |
5528 | else | |
5529 | return 0; | |
5530 | } | |
5531 | ||
2d134ed3 PA |
5532 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
5533 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
5534 | represent the same location. */ | |
5535 | ||
5536 | static int | |
4a64f543 MS |
5537 | breakpoint_locations_match (struct bp_location *loc1, |
5538 | struct bp_location *loc2) | |
2d134ed3 | 5539 | { |
2bdf28a0 JK |
5540 | int hw_point1, hw_point2; |
5541 | ||
5542 | /* Both of them must not be in moribund_locations. */ | |
5543 | gdb_assert (loc1->owner != NULL); | |
5544 | gdb_assert (loc2->owner != NULL); | |
5545 | ||
5546 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
5547 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
5548 | |
5549 | if (hw_point1 != hw_point2) | |
5550 | return 0; | |
5551 | else if (hw_point1) | |
5552 | return watchpoint_locations_match (loc1, loc2); | |
1e4d1764 YQ |
5553 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
5554 | return tracepoint_locations_match (loc1, loc2); | |
2d134ed3 | 5555 | else |
f1310107 TJB |
5556 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
5557 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
5558 | loc2->pspace->aspace, loc2->address) | |
5559 | && loc1->length == loc2->length); | |
2d134ed3 PA |
5560 | } |
5561 | ||
76897487 KB |
5562 | static void |
5563 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
5564 | int bnum, int have_bnum) | |
5565 | { | |
f63fbe86 MS |
5566 | /* The longest string possibly returned by hex_string_custom |
5567 | is 50 chars. These must be at least that big for safety. */ | |
5568 | char astr1[64]; | |
5569 | char astr2[64]; | |
76897487 | 5570 | |
bb599908 PH |
5571 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
5572 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 5573 | if (have_bnum) |
8a3fe4f8 | 5574 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
5575 | bnum, astr1, astr2); |
5576 | else | |
8a3fe4f8 | 5577 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
5578 | } |
5579 | ||
4a64f543 MS |
5580 | /* Adjust a breakpoint's address to account for architectural |
5581 | constraints on breakpoint placement. Return the adjusted address. | |
5582 | Note: Very few targets require this kind of adjustment. For most | |
5583 | targets, this function is simply the identity function. */ | |
76897487 KB |
5584 | |
5585 | static CORE_ADDR | |
a6d9a66e UW |
5586 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
5587 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 5588 | { |
a6d9a66e | 5589 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
5590 | { |
5591 | /* Very few targets need any kind of breakpoint adjustment. */ | |
5592 | return bpaddr; | |
5593 | } | |
88f7da05 KB |
5594 | else if (bptype == bp_watchpoint |
5595 | || bptype == bp_hardware_watchpoint | |
5596 | || bptype == bp_read_watchpoint | |
5597 | || bptype == bp_access_watchpoint | |
fe798b75 | 5598 | || bptype == bp_catchpoint) |
88f7da05 KB |
5599 | { |
5600 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
5601 | have their addresses modified. */ | |
5602 | return bpaddr; | |
5603 | } | |
76897487 KB |
5604 | else |
5605 | { | |
5606 | CORE_ADDR adjusted_bpaddr; | |
5607 | ||
5608 | /* Some targets have architectural constraints on the placement | |
5609 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 5610 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
5611 | |
5612 | /* An adjusted breakpoint address can significantly alter | |
5613 | a user's expectations. Print a warning if an adjustment | |
5614 | is required. */ | |
5615 | if (adjusted_bpaddr != bpaddr) | |
5616 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
5617 | ||
5618 | return adjusted_bpaddr; | |
5619 | } | |
5620 | } | |
5621 | ||
28010a5d PA |
5622 | void |
5623 | init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops, | |
5624 | struct breakpoint *owner) | |
7cc221ef | 5625 | { |
7cc221ef DJ |
5626 | memset (loc, 0, sizeof (*loc)); |
5627 | ||
348d480f PA |
5628 | gdb_assert (ops != NULL); |
5629 | ||
28010a5d PA |
5630 | loc->ops = ops; |
5631 | loc->owner = owner; | |
511a6cd4 | 5632 | loc->cond = NULL; |
0d381245 VP |
5633 | loc->shlib_disabled = 0; |
5634 | loc->enabled = 1; | |
e049a4b5 | 5635 | |
28010a5d | 5636 | switch (owner->type) |
e049a4b5 DJ |
5637 | { |
5638 | case bp_breakpoint: | |
5639 | case bp_until: | |
5640 | case bp_finish: | |
5641 | case bp_longjmp: | |
5642 | case bp_longjmp_resume: | |
186c406b TT |
5643 | case bp_exception: |
5644 | case bp_exception_resume: | |
e049a4b5 | 5645 | case bp_step_resume: |
2c03e5be | 5646 | case bp_hp_step_resume: |
e049a4b5 DJ |
5647 | case bp_watchpoint_scope: |
5648 | case bp_call_dummy: | |
aa7d318d | 5649 | case bp_std_terminate: |
e049a4b5 DJ |
5650 | case bp_shlib_event: |
5651 | case bp_thread_event: | |
5652 | case bp_overlay_event: | |
4efc6507 | 5653 | case bp_jit_event: |
0fd8e87f | 5654 | case bp_longjmp_master: |
aa7d318d | 5655 | case bp_std_terminate_master: |
186c406b | 5656 | case bp_exception_master: |
0e30163f JK |
5657 | case bp_gnu_ifunc_resolver: |
5658 | case bp_gnu_ifunc_resolver_return: | |
e049a4b5 DJ |
5659 | loc->loc_type = bp_loc_software_breakpoint; |
5660 | break; | |
5661 | case bp_hardware_breakpoint: | |
5662 | loc->loc_type = bp_loc_hardware_breakpoint; | |
5663 | break; | |
5664 | case bp_hardware_watchpoint: | |
5665 | case bp_read_watchpoint: | |
5666 | case bp_access_watchpoint: | |
5667 | loc->loc_type = bp_loc_hardware_watchpoint; | |
5668 | break; | |
5669 | case bp_watchpoint: | |
ce78b96d | 5670 | case bp_catchpoint: |
15c3d785 PA |
5671 | case bp_tracepoint: |
5672 | case bp_fast_tracepoint: | |
0fb4aa4b | 5673 | case bp_static_tracepoint: |
e049a4b5 DJ |
5674 | loc->loc_type = bp_loc_other; |
5675 | break; | |
5676 | default: | |
e2e0b3e5 | 5677 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
5678 | } |
5679 | ||
f431efe5 | 5680 | loc->refc = 1; |
28010a5d PA |
5681 | } |
5682 | ||
5683 | /* Allocate a struct bp_location. */ | |
5684 | ||
5685 | static struct bp_location * | |
5686 | allocate_bp_location (struct breakpoint *bpt) | |
5687 | { | |
348d480f PA |
5688 | return bpt->ops->allocate_location (bpt); |
5689 | } | |
7cc221ef | 5690 | |
f431efe5 PA |
5691 | static void |
5692 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 | 5693 | { |
348d480f | 5694 | loc->ops->dtor (loc); |
fe3f5fa8 VP |
5695 | xfree (loc); |
5696 | } | |
5697 | ||
f431efe5 PA |
5698 | /* Increment reference count. */ |
5699 | ||
5700 | static void | |
5701 | incref_bp_location (struct bp_location *bl) | |
5702 | { | |
5703 | ++bl->refc; | |
5704 | } | |
5705 | ||
5706 | /* Decrement reference count. If the reference count reaches 0, | |
5707 | destroy the bp_location. Sets *BLP to NULL. */ | |
5708 | ||
5709 | static void | |
5710 | decref_bp_location (struct bp_location **blp) | |
5711 | { | |
0807b50c PA |
5712 | gdb_assert ((*blp)->refc > 0); |
5713 | ||
f431efe5 PA |
5714 | if (--(*blp)->refc == 0) |
5715 | free_bp_location (*blp); | |
5716 | *blp = NULL; | |
5717 | } | |
5718 | ||
346774a9 | 5719 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 5720 | |
346774a9 PA |
5721 | static void |
5722 | add_to_breakpoint_chain (struct breakpoint *b) | |
c906108c | 5723 | { |
346774a9 | 5724 | struct breakpoint *b1; |
c906108c | 5725 | |
346774a9 PA |
5726 | /* Add this breakpoint to the end of the chain so that a list of |
5727 | breakpoints will come out in order of increasing numbers. */ | |
5728 | ||
5729 | b1 = breakpoint_chain; | |
5730 | if (b1 == 0) | |
5731 | breakpoint_chain = b; | |
5732 | else | |
5733 | { | |
5734 | while (b1->next) | |
5735 | b1 = b1->next; | |
5736 | b1->next = b; | |
5737 | } | |
5738 | } | |
5739 | ||
5740 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
5741 | ||
5742 | static void | |
5743 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
5744 | struct gdbarch *gdbarch, | |
28010a5d | 5745 | enum bptype bptype, |
c0a91b2b | 5746 | const struct breakpoint_ops *ops) |
346774a9 | 5747 | { |
c906108c | 5748 | memset (b, 0, sizeof (*b)); |
2219d63c | 5749 | |
348d480f PA |
5750 | gdb_assert (ops != NULL); |
5751 | ||
28010a5d | 5752 | b->ops = ops; |
4d28f7a8 | 5753 | b->type = bptype; |
a6d9a66e | 5754 | b->gdbarch = gdbarch; |
c906108c SS |
5755 | b->language = current_language->la_language; |
5756 | b->input_radix = input_radix; | |
5757 | b->thread = -1; | |
b5de0fa7 | 5758 | b->enable_state = bp_enabled; |
c906108c SS |
5759 | b->next = 0; |
5760 | b->silent = 0; | |
5761 | b->ignore_count = 0; | |
5762 | b->commands = NULL; | |
818dd999 | 5763 | b->frame_id = null_frame_id; |
0d381245 | 5764 | b->condition_not_parsed = 0; |
84f4c1fe | 5765 | b->py_bp_object = NULL; |
d0fb5eae | 5766 | b->related_breakpoint = b; |
346774a9 PA |
5767 | } |
5768 | ||
5769 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
5770 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
5771 | |
5772 | static struct breakpoint * | |
5773 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 5774 | enum bptype bptype, |
c0a91b2b | 5775 | const struct breakpoint_ops *ops) |
346774a9 PA |
5776 | { |
5777 | struct breakpoint *b = XNEW (struct breakpoint); | |
5778 | ||
348d480f | 5779 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
c56053d2 | 5780 | add_to_breakpoint_chain (b); |
0d381245 VP |
5781 | return b; |
5782 | } | |
5783 | ||
0e30163f JK |
5784 | /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function |
5785 | resolutions should be made as the user specified the location explicitly | |
5786 | enough. */ | |
5787 | ||
0d381245 | 5788 | static void |
0e30163f | 5789 | set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) |
0d381245 | 5790 | { |
2bdf28a0 JK |
5791 | gdb_assert (loc->owner != NULL); |
5792 | ||
0d381245 | 5793 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 5794 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 5795 | || is_tracepoint (loc->owner)) |
0d381245 | 5796 | { |
0e30163f JK |
5797 | int is_gnu_ifunc; |
5798 | ||
5799 | find_pc_partial_function_gnu_ifunc (loc->address, &loc->function_name, | |
5800 | NULL, NULL, &is_gnu_ifunc); | |
5801 | ||
5802 | if (is_gnu_ifunc && !explicit_loc) | |
5803 | { | |
5804 | struct breakpoint *b = loc->owner; | |
5805 | ||
5806 | gdb_assert (loc->pspace == current_program_space); | |
5807 | if (gnu_ifunc_resolve_name (loc->function_name, | |
5808 | &loc->requested_address)) | |
5809 | { | |
5810 | /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */ | |
5811 | loc->address = adjust_breakpoint_address (loc->gdbarch, | |
5812 | loc->requested_address, | |
5813 | b->type); | |
5814 | } | |
5815 | else if (b->type == bp_breakpoint && b->loc == loc | |
5816 | && loc->next == NULL && b->related_breakpoint == b) | |
5817 | { | |
5818 | /* Create only the whole new breakpoint of this type but do not | |
5819 | mess more complicated breakpoints with multiple locations. */ | |
5820 | b->type = bp_gnu_ifunc_resolver; | |
5821 | } | |
5822 | } | |
5823 | ||
0d381245 VP |
5824 | if (loc->function_name) |
5825 | loc->function_name = xstrdup (loc->function_name); | |
5826 | } | |
5827 | } | |
5828 | ||
a6d9a66e | 5829 | /* Attempt to determine architecture of location identified by SAL. */ |
1bfeeb0f | 5830 | struct gdbarch * |
a6d9a66e UW |
5831 | get_sal_arch (struct symtab_and_line sal) |
5832 | { | |
5833 | if (sal.section) | |
5834 | return get_objfile_arch (sal.section->objfile); | |
5835 | if (sal.symtab) | |
5836 | return get_objfile_arch (sal.symtab->objfile); | |
5837 | ||
5838 | return NULL; | |
5839 | } | |
5840 | ||
346774a9 PA |
5841 | /* Low level routine for partially initializing a breakpoint of type |
5842 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 5843 | file name, and line number are provided by SAL. |
0d381245 VP |
5844 | |
5845 | It is expected that the caller will complete the initialization of | |
5846 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 5847 | information regarding the creation of a new breakpoint. */ |
0d381245 | 5848 | |
346774a9 PA |
5849 | static void |
5850 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 5851 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 5852 | const struct breakpoint_ops *ops) |
0d381245 | 5853 | { |
28010a5d | 5854 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 5855 | |
3742cc8b | 5856 | add_location_to_breakpoint (b, &sal); |
0d381245 | 5857 | |
6c95b8df PA |
5858 | if (bptype != bp_catchpoint) |
5859 | gdb_assert (sal.pspace != NULL); | |
5860 | ||
f8eba3c6 TT |
5861 | /* Store the program space that was used to set the breakpoint, |
5862 | except for ordinary breakpoints, which are independent of the | |
5863 | program space. */ | |
5864 | if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) | |
5865 | b->pspace = sal.pspace; | |
0d381245 | 5866 | |
c906108c | 5867 | breakpoints_changed (); |
346774a9 | 5868 | } |
c906108c | 5869 | |
346774a9 PA |
5870 | /* set_raw_breakpoint is a low level routine for allocating and |
5871 | partially initializing a breakpoint of type BPTYPE. The newly | |
5872 | created breakpoint's address, section, source file name, and line | |
5873 | number are provided by SAL. The newly created and partially | |
5874 | initialized breakpoint is added to the breakpoint chain and | |
5875 | is also returned as the value of this function. | |
5876 | ||
5877 | It is expected that the caller will complete the initialization of | |
5878 | the newly created breakpoint struct as well as output any status | |
5879 | information regarding the creation of a new breakpoint. In | |
5880 | particular, set_raw_breakpoint does NOT set the breakpoint | |
5881 | number! Care should be taken to not allow an error to occur | |
5882 | prior to completing the initialization of the breakpoint. If this | |
5883 | should happen, a bogus breakpoint will be left on the chain. */ | |
5884 | ||
5885 | struct breakpoint * | |
5886 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
348d480f | 5887 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 5888 | const struct breakpoint_ops *ops) |
346774a9 PA |
5889 | { |
5890 | struct breakpoint *b = XNEW (struct breakpoint); | |
5891 | ||
348d480f | 5892 | init_raw_breakpoint (b, gdbarch, sal, bptype, ops); |
c56053d2 | 5893 | add_to_breakpoint_chain (b); |
c906108c SS |
5894 | return b; |
5895 | } | |
5896 | ||
c2c6d25f JM |
5897 | |
5898 | /* Note that the breakpoint object B describes a permanent breakpoint | |
5899 | instruction, hard-wired into the inferior's code. */ | |
5900 | void | |
5901 | make_breakpoint_permanent (struct breakpoint *b) | |
5902 | { | |
0d381245 | 5903 | struct bp_location *bl; |
cc59ec59 | 5904 | |
b5de0fa7 | 5905 | b->enable_state = bp_permanent; |
c2c6d25f | 5906 | |
4a64f543 MS |
5907 | /* By definition, permanent breakpoints are already present in the |
5908 | code. Mark all locations as inserted. For now, | |
5909 | make_breakpoint_permanent is called in just one place, so it's | |
5910 | hard to say if it's reasonable to have permanent breakpoint with | |
e5dd4106 | 5911 | multiple locations or not, but it's easy to implement. */ |
0d381245 VP |
5912 | for (bl = b->loc; bl; bl = bl->next) |
5913 | bl->inserted = 1; | |
c2c6d25f JM |
5914 | } |
5915 | ||
53a5351d | 5916 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
5917 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
5918 | initiated the operation. */ | |
c906108c SS |
5919 | |
5920 | void | |
186c406b | 5921 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 5922 | { |
35df4500 | 5923 | struct breakpoint *b, *b_tmp; |
186c406b | 5924 | int thread = tp->num; |
0fd8e87f UW |
5925 | |
5926 | /* To avoid having to rescan all objfile symbols at every step, | |
5927 | we maintain a list of continually-inserted but always disabled | |
5928 | longjmp "master" breakpoints. Here, we simply create momentary | |
5929 | clones of those and enable them for the requested thread. */ | |
35df4500 | 5930 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 5931 | if (b->pspace == current_program_space |
186c406b TT |
5932 | && (b->type == bp_longjmp_master |
5933 | || b->type == bp_exception_master)) | |
0fd8e87f | 5934 | { |
06edf0c0 PA |
5935 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
5936 | struct breakpoint *clone; | |
cc59ec59 | 5937 | |
06edf0c0 PA |
5938 | clone = momentary_breakpoint_from_master (b, type, |
5939 | &momentary_breakpoint_ops); | |
0fd8e87f UW |
5940 | clone->thread = thread; |
5941 | } | |
186c406b TT |
5942 | |
5943 | tp->initiating_frame = frame; | |
c906108c SS |
5944 | } |
5945 | ||
611c83ae | 5946 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 5947 | void |
611c83ae | 5948 | delete_longjmp_breakpoint (int thread) |
c906108c | 5949 | { |
35df4500 | 5950 | struct breakpoint *b, *b_tmp; |
c906108c | 5951 | |
35df4500 | 5952 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 5953 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
5954 | { |
5955 | if (b->thread == thread) | |
5956 | delete_breakpoint (b); | |
5957 | } | |
c906108c SS |
5958 | } |
5959 | ||
1900040c MS |
5960 | void |
5961 | enable_overlay_breakpoints (void) | |
5962 | { | |
52f0bd74 | 5963 | struct breakpoint *b; |
1900040c MS |
5964 | |
5965 | ALL_BREAKPOINTS (b) | |
5966 | if (b->type == bp_overlay_event) | |
5967 | { | |
5968 | b->enable_state = bp_enabled; | |
b60e7edf | 5969 | update_global_location_list (1); |
c02f5703 | 5970 | overlay_events_enabled = 1; |
1900040c MS |
5971 | } |
5972 | } | |
5973 | ||
5974 | void | |
5975 | disable_overlay_breakpoints (void) | |
5976 | { | |
52f0bd74 | 5977 | struct breakpoint *b; |
1900040c MS |
5978 | |
5979 | ALL_BREAKPOINTS (b) | |
5980 | if (b->type == bp_overlay_event) | |
5981 | { | |
5982 | b->enable_state = bp_disabled; | |
b60e7edf | 5983 | update_global_location_list (0); |
c02f5703 | 5984 | overlay_events_enabled = 0; |
1900040c MS |
5985 | } |
5986 | } | |
5987 | ||
aa7d318d TT |
5988 | /* Set an active std::terminate breakpoint for each std::terminate |
5989 | master breakpoint. */ | |
5990 | void | |
5991 | set_std_terminate_breakpoint (void) | |
5992 | { | |
35df4500 | 5993 | struct breakpoint *b, *b_tmp; |
aa7d318d | 5994 | |
35df4500 | 5995 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
5996 | if (b->pspace == current_program_space |
5997 | && b->type == bp_std_terminate_master) | |
5998 | { | |
06edf0c0 PA |
5999 | momentary_breakpoint_from_master (b, bp_std_terminate, |
6000 | &momentary_breakpoint_ops); | |
aa7d318d TT |
6001 | } |
6002 | } | |
6003 | ||
6004 | /* Delete all the std::terminate breakpoints. */ | |
6005 | void | |
6006 | delete_std_terminate_breakpoint (void) | |
6007 | { | |
35df4500 | 6008 | struct breakpoint *b, *b_tmp; |
aa7d318d | 6009 | |
35df4500 | 6010 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
6011 | if (b->type == bp_std_terminate) |
6012 | delete_breakpoint (b); | |
6013 | } | |
6014 | ||
c4093a6a | 6015 | struct breakpoint * |
a6d9a66e | 6016 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
6017 | { |
6018 | struct breakpoint *b; | |
c4093a6a | 6019 | |
06edf0c0 PA |
6020 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
6021 | &internal_breakpoint_ops); | |
6022 | ||
b5de0fa7 | 6023 | b->enable_state = bp_enabled; |
c4093a6a | 6024 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
6025 | b->addr_string |
6026 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 6027 | |
b60e7edf | 6028 | update_global_location_list_nothrow (1); |
74960c60 | 6029 | |
c4093a6a JM |
6030 | return b; |
6031 | } | |
6032 | ||
6033 | void | |
6034 | remove_thread_event_breakpoints (void) | |
6035 | { | |
35df4500 | 6036 | struct breakpoint *b, *b_tmp; |
c4093a6a | 6037 | |
35df4500 | 6038 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
6039 | if (b->type == bp_thread_event |
6040 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
6041 | delete_breakpoint (b); |
6042 | } | |
6043 | ||
0101ce28 JJ |
6044 | struct lang_and_radix |
6045 | { | |
6046 | enum language lang; | |
6047 | int radix; | |
6048 | }; | |
6049 | ||
4efc6507 DE |
6050 | /* Create a breakpoint for JIT code registration and unregistration. */ |
6051 | ||
6052 | struct breakpoint * | |
6053 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
6054 | { | |
6055 | struct breakpoint *b; | |
6056 | ||
06edf0c0 PA |
6057 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event, |
6058 | &internal_breakpoint_ops); | |
4efc6507 DE |
6059 | update_global_location_list_nothrow (1); |
6060 | return b; | |
6061 | } | |
0101ce28 | 6062 | |
03673fc7 PP |
6063 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
6064 | ||
6065 | void | |
6066 | remove_jit_event_breakpoints (void) | |
6067 | { | |
6068 | struct breakpoint *b, *b_tmp; | |
6069 | ||
6070 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
6071 | if (b->type == bp_jit_event | |
6072 | && b->loc->pspace == current_program_space) | |
6073 | delete_breakpoint (b); | |
6074 | } | |
6075 | ||
cae688ec JJ |
6076 | void |
6077 | remove_solib_event_breakpoints (void) | |
6078 | { | |
35df4500 | 6079 | struct breakpoint *b, *b_tmp; |
cae688ec | 6080 | |
35df4500 | 6081 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
6082 | if (b->type == bp_shlib_event |
6083 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
6084 | delete_breakpoint (b); |
6085 | } | |
6086 | ||
6087 | struct breakpoint * | |
a6d9a66e | 6088 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
cae688ec JJ |
6089 | { |
6090 | struct breakpoint *b; | |
6091 | ||
06edf0c0 PA |
6092 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
6093 | &internal_breakpoint_ops); | |
b60e7edf | 6094 | update_global_location_list_nothrow (1); |
cae688ec JJ |
6095 | return b; |
6096 | } | |
6097 | ||
6098 | /* Disable any breakpoints that are on code in shared libraries. Only | |
6099 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
6100 | ||
6101 | void | |
cb851954 | 6102 | disable_breakpoints_in_shlibs (void) |
cae688ec | 6103 | { |
876fa593 | 6104 | struct bp_location *loc, **locp_tmp; |
cae688ec | 6105 | |
876fa593 | 6106 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 6107 | { |
2bdf28a0 | 6108 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 6109 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 6110 | |
4a64f543 MS |
6111 | /* We apply the check to all breakpoints, including disabled for |
6112 | those with loc->duplicate set. This is so that when breakpoint | |
6113 | becomes enabled, or the duplicate is removed, gdb will try to | |
6114 | insert all breakpoints. If we don't set shlib_disabled here, | |
6115 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 6116 | if (((b->type == bp_breakpoint) |
508ccb1f | 6117 | || (b->type == bp_jit_event) |
1042e4c0 | 6118 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 6119 | || (is_tracepoint (b))) |
6c95b8df | 6120 | && loc->pspace == current_program_space |
0d381245 | 6121 | && !loc->shlib_disabled |
a77053c2 | 6122 | #ifdef PC_SOLIB |
0d381245 | 6123 | && PC_SOLIB (loc->address) |
a77053c2 | 6124 | #else |
6c95b8df | 6125 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 MK |
6126 | #endif |
6127 | ) | |
0d381245 VP |
6128 | { |
6129 | loc->shlib_disabled = 1; | |
6130 | } | |
cae688ec JJ |
6131 | } |
6132 | } | |
6133 | ||
1e4d1764 YQ |
6134 | /* Disable any breakpoints and tracepoints that are in an unloaded shared |
6135 | library. Only apply to enabled breakpoints, disabled ones can just stay | |
4a64f543 | 6136 | disabled. */ |
84acb35a | 6137 | |
75149521 | 6138 | static void |
84acb35a JJ |
6139 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
6140 | { | |
876fa593 | 6141 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
6142 | int disabled_shlib_breaks = 0; |
6143 | ||
c86cf029 VP |
6144 | /* SunOS a.out shared libraries are always mapped, so do not |
6145 | disable breakpoints; they will only be reported as unloaded | |
6146 | through clear_solib when GDB discards its shared library | |
6147 | list. See clear_solib for more information. */ | |
6148 | if (exec_bfd != NULL | |
6149 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
6150 | return; | |
6151 | ||
876fa593 | 6152 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 6153 | { |
2bdf28a0 | 6154 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 6155 | struct breakpoint *b = loc->owner; |
cc59ec59 | 6156 | |
1e4d1764 | 6157 | if (solib->pspace == loc->pspace |
e2dd7057 | 6158 | && !loc->shlib_disabled |
1e4d1764 YQ |
6159 | && (((b->type == bp_breakpoint |
6160 | || b->type == bp_jit_event | |
6161 | || b->type == bp_hardware_breakpoint) | |
6162 | && (loc->loc_type == bp_loc_hardware_breakpoint | |
6163 | || loc->loc_type == bp_loc_software_breakpoint)) | |
6164 | || is_tracepoint (b)) | |
e2dd7057 | 6165 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 6166 | { |
e2dd7057 PP |
6167 | loc->shlib_disabled = 1; |
6168 | /* At this point, we cannot rely on remove_breakpoint | |
6169 | succeeding so we must mark the breakpoint as not inserted | |
6170 | to prevent future errors occurring in remove_breakpoints. */ | |
6171 | loc->inserted = 0; | |
8d3788bd VP |
6172 | |
6173 | /* This may cause duplicate notifications for the same breakpoint. */ | |
6174 | observer_notify_breakpoint_modified (b); | |
6175 | ||
e2dd7057 PP |
6176 | if (!disabled_shlib_breaks) |
6177 | { | |
6178 | target_terminal_ours_for_output (); | |
3e43a32a MS |
6179 | warning (_("Temporarily disabling breakpoints " |
6180 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 6181 | solib->so_name); |
84acb35a | 6182 | } |
e2dd7057 | 6183 | disabled_shlib_breaks = 1; |
84acb35a JJ |
6184 | } |
6185 | } | |
84acb35a JJ |
6186 | } |
6187 | ||
ce78b96d JB |
6188 | /* FORK & VFORK catchpoints. */ |
6189 | ||
e29a4733 PA |
6190 | /* An instance of this type is used to represent a fork or vfork |
6191 | catchpoint. It includes a "struct breakpoint" as a kind of base | |
6192 | class; users downcast to "struct breakpoint *" when needed. A | |
6193 | breakpoint is really of this type iff its ops pointer points to | |
6194 | CATCH_FORK_BREAKPOINT_OPS. */ | |
6195 | ||
6196 | struct fork_catchpoint | |
6197 | { | |
6198 | /* The base class. */ | |
6199 | struct breakpoint base; | |
6200 | ||
6201 | /* Process id of a child process whose forking triggered this | |
6202 | catchpoint. This field is only valid immediately after this | |
6203 | catchpoint has triggered. */ | |
6204 | ptid_t forked_inferior_pid; | |
6205 | }; | |
6206 | ||
4a64f543 MS |
6207 | /* Implement the "insert" breakpoint_ops method for fork |
6208 | catchpoints. */ | |
ce78b96d | 6209 | |
77b06cd7 TJB |
6210 | static int |
6211 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 6212 | { |
77b06cd7 | 6213 | return target_insert_fork_catchpoint (PIDGET (inferior_ptid)); |
ce78b96d JB |
6214 | } |
6215 | ||
4a64f543 MS |
6216 | /* Implement the "remove" breakpoint_ops method for fork |
6217 | catchpoints. */ | |
ce78b96d JB |
6218 | |
6219 | static int | |
77b06cd7 | 6220 | remove_catch_fork (struct bp_location *bl) |
ce78b96d JB |
6221 | { |
6222 | return target_remove_fork_catchpoint (PIDGET (inferior_ptid)); | |
6223 | } | |
6224 | ||
6225 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
6226 | catchpoints. */ | |
6227 | ||
6228 | static int | |
f1310107 | 6229 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
09ac7c10 TT |
6230 | struct address_space *aspace, CORE_ADDR bp_addr, |
6231 | const struct target_waitstatus *ws) | |
ce78b96d | 6232 | { |
e29a4733 PA |
6233 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
6234 | ||
f90263c1 TT |
6235 | if (ws->kind != TARGET_WAITKIND_FORKED) |
6236 | return 0; | |
6237 | ||
6238 | c->forked_inferior_pid = ws->value.related_pid; | |
6239 | return 1; | |
ce78b96d JB |
6240 | } |
6241 | ||
4a64f543 MS |
6242 | /* Implement the "print_it" breakpoint_ops method for fork |
6243 | catchpoints. */ | |
ce78b96d JB |
6244 | |
6245 | static enum print_stop_action | |
348d480f | 6246 | print_it_catch_fork (bpstat bs) |
ce78b96d | 6247 | { |
36dfb11c | 6248 | struct ui_out *uiout = current_uiout; |
348d480f PA |
6249 | struct breakpoint *b = bs->breakpoint_at; |
6250 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; | |
e29a4733 | 6251 | |
ce78b96d | 6252 | annotate_catchpoint (b->number); |
36dfb11c TT |
6253 | if (b->disposition == disp_del) |
6254 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
6255 | else | |
6256 | ui_out_text (uiout, "\nCatchpoint "); | |
6257 | if (ui_out_is_mi_like_p (uiout)) | |
6258 | { | |
6259 | ui_out_field_string (uiout, "reason", | |
6260 | async_reason_lookup (EXEC_ASYNC_FORK)); | |
6261 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
6262 | } | |
6263 | ui_out_field_int (uiout, "bkptno", b->number); | |
6264 | ui_out_text (uiout, " (forked process "); | |
6265 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
6266 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
6267 | return PRINT_SRC_AND_LOC; |
6268 | } | |
6269 | ||
4a64f543 MS |
6270 | /* Implement the "print_one" breakpoint_ops method for fork |
6271 | catchpoints. */ | |
ce78b96d JB |
6272 | |
6273 | static void | |
a6d9a66e | 6274 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 6275 | { |
e29a4733 | 6276 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 6277 | struct value_print_options opts; |
79a45e25 | 6278 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
6279 | |
6280 | get_user_print_options (&opts); | |
6281 | ||
4a64f543 MS |
6282 | /* Field 4, the address, is omitted (which makes the columns not |
6283 | line up too nicely with the headers, but the effect is relatively | |
6284 | readable). */ | |
79a45b7d | 6285 | if (opts.addressprint) |
ce78b96d JB |
6286 | ui_out_field_skip (uiout, "addr"); |
6287 | annotate_field (5); | |
6288 | ui_out_text (uiout, "fork"); | |
e29a4733 | 6289 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
6290 | { |
6291 | ui_out_text (uiout, ", process "); | |
6292 | ui_out_field_int (uiout, "what", | |
e29a4733 | 6293 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
6294 | ui_out_spaces (uiout, 1); |
6295 | } | |
6296 | } | |
6297 | ||
6298 | /* Implement the "print_mention" breakpoint_ops method for fork | |
6299 | catchpoints. */ | |
6300 | ||
6301 | static void | |
6302 | print_mention_catch_fork (struct breakpoint *b) | |
6303 | { | |
6304 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
6305 | } | |
6306 | ||
6149aea9 PA |
6307 | /* Implement the "print_recreate" breakpoint_ops method for fork |
6308 | catchpoints. */ | |
6309 | ||
6310 | static void | |
6311 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
6312 | { | |
6313 | fprintf_unfiltered (fp, "catch fork"); | |
d9b3f62e | 6314 | print_recreate_thread (b, fp); |
6149aea9 PA |
6315 | } |
6316 | ||
ce78b96d JB |
6317 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
6318 | ||
2060206e | 6319 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
ce78b96d | 6320 | |
4a64f543 MS |
6321 | /* Implement the "insert" breakpoint_ops method for vfork |
6322 | catchpoints. */ | |
ce78b96d | 6323 | |
77b06cd7 TJB |
6324 | static int |
6325 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 6326 | { |
77b06cd7 | 6327 | return target_insert_vfork_catchpoint (PIDGET (inferior_ptid)); |
ce78b96d JB |
6328 | } |
6329 | ||
4a64f543 MS |
6330 | /* Implement the "remove" breakpoint_ops method for vfork |
6331 | catchpoints. */ | |
ce78b96d JB |
6332 | |
6333 | static int | |
77b06cd7 | 6334 | remove_catch_vfork (struct bp_location *bl) |
ce78b96d JB |
6335 | { |
6336 | return target_remove_vfork_catchpoint (PIDGET (inferior_ptid)); | |
6337 | } | |
6338 | ||
6339 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
6340 | catchpoints. */ | |
6341 | ||
6342 | static int | |
f1310107 | 6343 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
09ac7c10 TT |
6344 | struct address_space *aspace, CORE_ADDR bp_addr, |
6345 | const struct target_waitstatus *ws) | |
ce78b96d | 6346 | { |
e29a4733 PA |
6347 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
6348 | ||
f90263c1 TT |
6349 | if (ws->kind != TARGET_WAITKIND_VFORKED) |
6350 | return 0; | |
6351 | ||
6352 | c->forked_inferior_pid = ws->value.related_pid; | |
6353 | return 1; | |
ce78b96d JB |
6354 | } |
6355 | ||
4a64f543 MS |
6356 | /* Implement the "print_it" breakpoint_ops method for vfork |
6357 | catchpoints. */ | |
ce78b96d JB |
6358 | |
6359 | static enum print_stop_action | |
348d480f | 6360 | print_it_catch_vfork (bpstat bs) |
ce78b96d | 6361 | { |
36dfb11c | 6362 | struct ui_out *uiout = current_uiout; |
348d480f | 6363 | struct breakpoint *b = bs->breakpoint_at; |
e29a4733 PA |
6364 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
6365 | ||
ce78b96d | 6366 | annotate_catchpoint (b->number); |
36dfb11c TT |
6367 | if (b->disposition == disp_del) |
6368 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
6369 | else | |
6370 | ui_out_text (uiout, "\nCatchpoint "); | |
6371 | if (ui_out_is_mi_like_p (uiout)) | |
6372 | { | |
6373 | ui_out_field_string (uiout, "reason", | |
6374 | async_reason_lookup (EXEC_ASYNC_VFORK)); | |
6375 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
6376 | } | |
6377 | ui_out_field_int (uiout, "bkptno", b->number); | |
6378 | ui_out_text (uiout, " (vforked process "); | |
6379 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
6380 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
6381 | return PRINT_SRC_AND_LOC; |
6382 | } | |
6383 | ||
4a64f543 MS |
6384 | /* Implement the "print_one" breakpoint_ops method for vfork |
6385 | catchpoints. */ | |
ce78b96d JB |
6386 | |
6387 | static void | |
a6d9a66e | 6388 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 6389 | { |
e29a4733 | 6390 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 6391 | struct value_print_options opts; |
79a45e25 | 6392 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
6393 | |
6394 | get_user_print_options (&opts); | |
4a64f543 MS |
6395 | /* Field 4, the address, is omitted (which makes the columns not |
6396 | line up too nicely with the headers, but the effect is relatively | |
6397 | readable). */ | |
79a45b7d | 6398 | if (opts.addressprint) |
ce78b96d JB |
6399 | ui_out_field_skip (uiout, "addr"); |
6400 | annotate_field (5); | |
6401 | ui_out_text (uiout, "vfork"); | |
e29a4733 | 6402 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
6403 | { |
6404 | ui_out_text (uiout, ", process "); | |
6405 | ui_out_field_int (uiout, "what", | |
e29a4733 | 6406 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
6407 | ui_out_spaces (uiout, 1); |
6408 | } | |
6409 | } | |
6410 | ||
6411 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
6412 | catchpoints. */ | |
6413 | ||
6414 | static void | |
6415 | print_mention_catch_vfork (struct breakpoint *b) | |
6416 | { | |
6417 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
6418 | } | |
6419 | ||
6149aea9 PA |
6420 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
6421 | catchpoints. */ | |
6422 | ||
6423 | static void | |
6424 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
6425 | { | |
6426 | fprintf_unfiltered (fp, "catch vfork"); | |
d9b3f62e | 6427 | print_recreate_thread (b, fp); |
6149aea9 PA |
6428 | } |
6429 | ||
ce78b96d JB |
6430 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
6431 | ||
2060206e | 6432 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
ce78b96d | 6433 | |
be5c67c1 PA |
6434 | /* An instance of this type is used to represent a syscall catchpoint. |
6435 | It includes a "struct breakpoint" as a kind of base class; users | |
6436 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
6437 | really of this type iff its ops pointer points to | |
6438 | CATCH_SYSCALL_BREAKPOINT_OPS. */ | |
6439 | ||
6440 | struct syscall_catchpoint | |
6441 | { | |
6442 | /* The base class. */ | |
6443 | struct breakpoint base; | |
6444 | ||
6445 | /* Syscall numbers used for the 'catch syscall' feature. If no | |
6446 | syscall has been specified for filtering, its value is NULL. | |
6447 | Otherwise, it holds a list of all syscalls to be caught. The | |
6448 | list elements are allocated with xmalloc. */ | |
6449 | VEC(int) *syscalls_to_be_caught; | |
6450 | }; | |
6451 | ||
6452 | /* Implement the "dtor" breakpoint_ops method for syscall | |
6453 | catchpoints. */ | |
6454 | ||
6455 | static void | |
6456 | dtor_catch_syscall (struct breakpoint *b) | |
6457 | { | |
6458 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; | |
6459 | ||
6460 | VEC_free (int, c->syscalls_to_be_caught); | |
348d480f | 6461 | |
2060206e | 6462 | base_breakpoint_ops.dtor (b); |
be5c67c1 PA |
6463 | } |
6464 | ||
a96d9b2e SDJ |
6465 | /* Implement the "insert" breakpoint_ops method for syscall |
6466 | catchpoints. */ | |
6467 | ||
77b06cd7 TJB |
6468 | static int |
6469 | insert_catch_syscall (struct bp_location *bl) | |
a96d9b2e | 6470 | { |
be5c67c1 | 6471 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; |
a96d9b2e SDJ |
6472 | struct inferior *inf = current_inferior (); |
6473 | ||
6474 | ++inf->total_syscalls_count; | |
be5c67c1 | 6475 | if (!c->syscalls_to_be_caught) |
a96d9b2e SDJ |
6476 | ++inf->any_syscall_count; |
6477 | else | |
6478 | { | |
6479 | int i, iter; | |
cc59ec59 | 6480 | |
a96d9b2e | 6481 | for (i = 0; |
be5c67c1 | 6482 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6483 | i++) |
6484 | { | |
6485 | int elem; | |
cc59ec59 | 6486 | |
a96d9b2e SDJ |
6487 | if (iter >= VEC_length (int, inf->syscalls_counts)) |
6488 | { | |
6489 | int old_size = VEC_length (int, inf->syscalls_counts); | |
3e43a32a MS |
6490 | uintptr_t vec_addr_offset |
6491 | = old_size * ((uintptr_t) sizeof (int)); | |
a96d9b2e SDJ |
6492 | uintptr_t vec_addr; |
6493 | VEC_safe_grow (int, inf->syscalls_counts, iter + 1); | |
6494 | vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) + | |
6495 | vec_addr_offset; | |
6496 | memset ((void *) vec_addr, 0, | |
6497 | (iter + 1 - old_size) * sizeof (int)); | |
6498 | } | |
6499 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
6500 | VEC_replace (int, inf->syscalls_counts, iter, ++elem); | |
6501 | } | |
6502 | } | |
6503 | ||
77b06cd7 TJB |
6504 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), |
6505 | inf->total_syscalls_count != 0, | |
6506 | inf->any_syscall_count, | |
6507 | VEC_length (int, inf->syscalls_counts), | |
6508 | VEC_address (int, inf->syscalls_counts)); | |
a96d9b2e SDJ |
6509 | } |
6510 | ||
6511 | /* Implement the "remove" breakpoint_ops method for syscall | |
6512 | catchpoints. */ | |
6513 | ||
6514 | static int | |
77b06cd7 | 6515 | remove_catch_syscall (struct bp_location *bl) |
a96d9b2e | 6516 | { |
be5c67c1 | 6517 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; |
a96d9b2e SDJ |
6518 | struct inferior *inf = current_inferior (); |
6519 | ||
6520 | --inf->total_syscalls_count; | |
be5c67c1 | 6521 | if (!c->syscalls_to_be_caught) |
a96d9b2e SDJ |
6522 | --inf->any_syscall_count; |
6523 | else | |
6524 | { | |
6525 | int i, iter; | |
cc59ec59 | 6526 | |
a96d9b2e | 6527 | for (i = 0; |
be5c67c1 | 6528 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6529 | i++) |
6530 | { | |
6531 | int elem; | |
6532 | if (iter >= VEC_length (int, inf->syscalls_counts)) | |
6533 | /* Shouldn't happen. */ | |
6534 | continue; | |
6535 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
6536 | VEC_replace (int, inf->syscalls_counts, iter, --elem); | |
6537 | } | |
6538 | } | |
6539 | ||
6540 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
6541 | inf->total_syscalls_count != 0, | |
6542 | inf->any_syscall_count, | |
6543 | VEC_length (int, inf->syscalls_counts), | |
3e43a32a MS |
6544 | VEC_address (int, |
6545 | inf->syscalls_counts)); | |
a96d9b2e SDJ |
6546 | } |
6547 | ||
6548 | /* Implement the "breakpoint_hit" breakpoint_ops method for syscall | |
6549 | catchpoints. */ | |
6550 | ||
6551 | static int | |
f1310107 | 6552 | breakpoint_hit_catch_syscall (const struct bp_location *bl, |
09ac7c10 TT |
6553 | struct address_space *aspace, CORE_ADDR bp_addr, |
6554 | const struct target_waitstatus *ws) | |
a96d9b2e | 6555 | { |
4a64f543 MS |
6556 | /* We must check if we are catching specific syscalls in this |
6557 | breakpoint. If we are, then we must guarantee that the called | |
6558 | syscall is the same syscall we are catching. */ | |
a96d9b2e | 6559 | int syscall_number = 0; |
be5c67c1 PA |
6560 | const struct syscall_catchpoint *c |
6561 | = (const struct syscall_catchpoint *) bl->owner; | |
a96d9b2e | 6562 | |
f90263c1 TT |
6563 | if (ws->kind != TARGET_WAITKIND_SYSCALL_ENTRY |
6564 | && ws->kind != TARGET_WAITKIND_SYSCALL_RETURN) | |
a96d9b2e SDJ |
6565 | return 0; |
6566 | ||
f90263c1 TT |
6567 | syscall_number = ws->value.syscall_number; |
6568 | ||
a96d9b2e | 6569 | /* Now, checking if the syscall is the same. */ |
be5c67c1 | 6570 | if (c->syscalls_to_be_caught) |
a96d9b2e SDJ |
6571 | { |
6572 | int i, iter; | |
cc59ec59 | 6573 | |
a96d9b2e | 6574 | for (i = 0; |
be5c67c1 | 6575 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6576 | i++) |
6577 | if (syscall_number == iter) | |
6578 | break; | |
6579 | /* Not the same. */ | |
6580 | if (!iter) | |
6581 | return 0; | |
6582 | } | |
6583 | ||
6584 | return 1; | |
6585 | } | |
6586 | ||
6587 | /* Implement the "print_it" breakpoint_ops method for syscall | |
6588 | catchpoints. */ | |
6589 | ||
6590 | static enum print_stop_action | |
348d480f | 6591 | print_it_catch_syscall (bpstat bs) |
a96d9b2e | 6592 | { |
36dfb11c | 6593 | struct ui_out *uiout = current_uiout; |
348d480f | 6594 | struct breakpoint *b = bs->breakpoint_at; |
a96d9b2e SDJ |
6595 | /* These are needed because we want to know in which state a |
6596 | syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY | |
6597 | or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we | |
6598 | must print "called syscall" or "returned from syscall". */ | |
6599 | ptid_t ptid; | |
6600 | struct target_waitstatus last; | |
6601 | struct syscall s; | |
a96d9b2e SDJ |
6602 | char *syscall_id; |
6603 | ||
6604 | get_last_target_status (&ptid, &last); | |
6605 | ||
6606 | get_syscall_by_number (last.value.syscall_number, &s); | |
6607 | ||
6608 | annotate_catchpoint (b->number); | |
6609 | ||
36dfb11c TT |
6610 | if (b->disposition == disp_del) |
6611 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
a96d9b2e | 6612 | else |
36dfb11c TT |
6613 | ui_out_text (uiout, "\nCatchpoint "); |
6614 | if (ui_out_is_mi_like_p (uiout)) | |
6615 | { | |
6616 | ui_out_field_string (uiout, "reason", | |
6617 | async_reason_lookup (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY | |
6618 | ? EXEC_ASYNC_SYSCALL_ENTRY | |
6619 | : EXEC_ASYNC_SYSCALL_RETURN)); | |
6620 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
6621 | } | |
6622 | ui_out_field_int (uiout, "bkptno", b->number); | |
a96d9b2e SDJ |
6623 | |
6624 | if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) | |
36dfb11c TT |
6625 | ui_out_text (uiout, " (call to syscall "); |
6626 | else | |
6627 | ui_out_text (uiout, " (returned from syscall "); | |
a96d9b2e | 6628 | |
36dfb11c TT |
6629 | if (s.name == NULL || ui_out_is_mi_like_p (uiout)) |
6630 | ui_out_field_int (uiout, "syscall-number", last.value.syscall_number); | |
6631 | if (s.name != NULL) | |
6632 | ui_out_field_string (uiout, "syscall-name", s.name); | |
6633 | ||
6634 | ui_out_text (uiout, "), "); | |
a96d9b2e SDJ |
6635 | |
6636 | return PRINT_SRC_AND_LOC; | |
6637 | } | |
6638 | ||
6639 | /* Implement the "print_one" breakpoint_ops method for syscall | |
6640 | catchpoints. */ | |
6641 | ||
6642 | static void | |
6643 | print_one_catch_syscall (struct breakpoint *b, | |
f1310107 | 6644 | struct bp_location **last_loc) |
a96d9b2e | 6645 | { |
be5c67c1 | 6646 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
a96d9b2e | 6647 | struct value_print_options opts; |
79a45e25 | 6648 | struct ui_out *uiout = current_uiout; |
a96d9b2e SDJ |
6649 | |
6650 | get_user_print_options (&opts); | |
4a64f543 MS |
6651 | /* Field 4, the address, is omitted (which makes the columns not |
6652 | line up too nicely with the headers, but the effect is relatively | |
6653 | readable). */ | |
a96d9b2e SDJ |
6654 | if (opts.addressprint) |
6655 | ui_out_field_skip (uiout, "addr"); | |
6656 | annotate_field (5); | |
6657 | ||
be5c67c1 PA |
6658 | if (c->syscalls_to_be_caught |
6659 | && VEC_length (int, c->syscalls_to_be_caught) > 1) | |
a96d9b2e SDJ |
6660 | ui_out_text (uiout, "syscalls \""); |
6661 | else | |
6662 | ui_out_text (uiout, "syscall \""); | |
6663 | ||
be5c67c1 | 6664 | if (c->syscalls_to_be_caught) |
a96d9b2e SDJ |
6665 | { |
6666 | int i, iter; | |
6667 | char *text = xstrprintf ("%s", ""); | |
cc59ec59 | 6668 | |
a96d9b2e | 6669 | for (i = 0; |
be5c67c1 | 6670 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6671 | i++) |
6672 | { | |
6673 | char *x = text; | |
6674 | struct syscall s; | |
6675 | get_syscall_by_number (iter, &s); | |
6676 | ||
6677 | if (s.name != NULL) | |
6678 | text = xstrprintf ("%s%s, ", text, s.name); | |
6679 | else | |
6680 | text = xstrprintf ("%s%d, ", text, iter); | |
6681 | ||
6682 | /* We have to xfree the last 'text' (now stored at 'x') | |
e5dd4106 | 6683 | because xstrprintf dynamically allocates new space for it |
a96d9b2e SDJ |
6684 | on every call. */ |
6685 | xfree (x); | |
6686 | } | |
6687 | /* Remove the last comma. */ | |
6688 | text[strlen (text) - 2] = '\0'; | |
6689 | ui_out_field_string (uiout, "what", text); | |
6690 | } | |
6691 | else | |
6692 | ui_out_field_string (uiout, "what", "<any syscall>"); | |
6693 | ui_out_text (uiout, "\" "); | |
6694 | } | |
6695 | ||
6696 | /* Implement the "print_mention" breakpoint_ops method for syscall | |
6697 | catchpoints. */ | |
6698 | ||
6699 | static void | |
6700 | print_mention_catch_syscall (struct breakpoint *b) | |
6701 | { | |
be5c67c1 PA |
6702 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
6703 | ||
6704 | if (c->syscalls_to_be_caught) | |
a96d9b2e SDJ |
6705 | { |
6706 | int i, iter; | |
6707 | ||
be5c67c1 | 6708 | if (VEC_length (int, c->syscalls_to_be_caught) > 1) |
a96d9b2e SDJ |
6709 | printf_filtered (_("Catchpoint %d (syscalls"), b->number); |
6710 | else | |
6711 | printf_filtered (_("Catchpoint %d (syscall"), b->number); | |
6712 | ||
6713 | for (i = 0; | |
be5c67c1 | 6714 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6715 | i++) |
6716 | { | |
6717 | struct syscall s; | |
6718 | get_syscall_by_number (iter, &s); | |
6719 | ||
6720 | if (s.name) | |
6721 | printf_filtered (" '%s' [%d]", s.name, s.number); | |
6722 | else | |
6723 | printf_filtered (" %d", s.number); | |
6724 | } | |
6725 | printf_filtered (")"); | |
6726 | } | |
6727 | else | |
6728 | printf_filtered (_("Catchpoint %d (any syscall)"), | |
6729 | b->number); | |
6730 | } | |
6731 | ||
6149aea9 PA |
6732 | /* Implement the "print_recreate" breakpoint_ops method for syscall |
6733 | catchpoints. */ | |
6734 | ||
6735 | static void | |
6736 | print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp) | |
6737 | { | |
be5c67c1 PA |
6738 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
6739 | ||
6149aea9 PA |
6740 | fprintf_unfiltered (fp, "catch syscall"); |
6741 | ||
be5c67c1 | 6742 | if (c->syscalls_to_be_caught) |
6149aea9 PA |
6743 | { |
6744 | int i, iter; | |
6745 | ||
6746 | for (i = 0; | |
be5c67c1 | 6747 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
6149aea9 PA |
6748 | i++) |
6749 | { | |
6750 | struct syscall s; | |
6751 | ||
6752 | get_syscall_by_number (iter, &s); | |
6753 | if (s.name) | |
6754 | fprintf_unfiltered (fp, " %s", s.name); | |
6755 | else | |
6756 | fprintf_unfiltered (fp, " %d", s.number); | |
6757 | } | |
6758 | } | |
d9b3f62e | 6759 | print_recreate_thread (b, fp); |
6149aea9 PA |
6760 | } |
6761 | ||
a96d9b2e SDJ |
6762 | /* The breakpoint_ops structure to be used in syscall catchpoints. */ |
6763 | ||
2060206e | 6764 | static struct breakpoint_ops catch_syscall_breakpoint_ops; |
a96d9b2e SDJ |
6765 | |
6766 | /* Returns non-zero if 'b' is a syscall catchpoint. */ | |
6767 | ||
6768 | static int | |
6769 | syscall_catchpoint_p (struct breakpoint *b) | |
6770 | { | |
6771 | return (b->ops == &catch_syscall_breakpoint_ops); | |
6772 | } | |
6773 | ||
346774a9 PA |
6774 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
6775 | is non-zero, then make the breakpoint temporary. If COND_STRING is | |
6776 | not NULL, then store it in the breakpoint. OPS, if not NULL, is | |
6777 | the breakpoint_ops structure associated to the catchpoint. */ | |
ce78b96d | 6778 | |
346774a9 PA |
6779 | static void |
6780 | init_catchpoint (struct breakpoint *b, | |
6781 | struct gdbarch *gdbarch, int tempflag, | |
6782 | char *cond_string, | |
c0a91b2b | 6783 | const struct breakpoint_ops *ops) |
c906108c | 6784 | { |
c5aa993b | 6785 | struct symtab_and_line sal; |
346774a9 | 6786 | |
fe39c653 | 6787 | init_sal (&sal); |
6c95b8df | 6788 | sal.pspace = current_program_space; |
c5aa993b | 6789 | |
28010a5d | 6790 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 6791 | |
1b36a34b | 6792 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
b5de0fa7 | 6793 | b->disposition = tempflag ? disp_del : disp_donttouch; |
346774a9 PA |
6794 | } |
6795 | ||
28010a5d | 6796 | void |
3ea46bff | 6797 | install_breakpoint (int internal, struct breakpoint *b, int update_gll) |
c56053d2 PA |
6798 | { |
6799 | add_to_breakpoint_chain (b); | |
3a5c3e22 PA |
6800 | set_breakpoint_number (internal, b); |
6801 | if (!internal) | |
6802 | mention (b); | |
c56053d2 | 6803 | observer_notify_breakpoint_created (b); |
3ea46bff YQ |
6804 | |
6805 | if (update_gll) | |
6806 | update_global_location_list (1); | |
c56053d2 PA |
6807 | } |
6808 | ||
9b70b993 | 6809 | static void |
a6d9a66e UW |
6810 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
6811 | int tempflag, char *cond_string, | |
c0a91b2b | 6812 | const struct breakpoint_ops *ops) |
c906108c | 6813 | { |
e29a4733 | 6814 | struct fork_catchpoint *c = XNEW (struct fork_catchpoint); |
ce78b96d | 6815 | |
e29a4733 PA |
6816 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops); |
6817 | ||
6818 | c->forked_inferior_pid = null_ptid; | |
6819 | ||
3ea46bff | 6820 | install_breakpoint (0, &c->base, 1); |
c906108c SS |
6821 | } |
6822 | ||
fe798b75 JB |
6823 | /* Exec catchpoints. */ |
6824 | ||
b4d90040 PA |
6825 | /* An instance of this type is used to represent an exec catchpoint. |
6826 | It includes a "struct breakpoint" as a kind of base class; users | |
6827 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
6828 | really of this type iff its ops pointer points to | |
6829 | CATCH_EXEC_BREAKPOINT_OPS. */ | |
6830 | ||
6831 | struct exec_catchpoint | |
6832 | { | |
6833 | /* The base class. */ | |
6834 | struct breakpoint base; | |
6835 | ||
6836 | /* Filename of a program whose exec triggered this catchpoint. | |
6837 | This field is only valid immediately after this catchpoint has | |
6838 | triggered. */ | |
6839 | char *exec_pathname; | |
6840 | }; | |
6841 | ||
6842 | /* Implement the "dtor" breakpoint_ops method for exec | |
6843 | catchpoints. */ | |
6844 | ||
6845 | static void | |
6846 | dtor_catch_exec (struct breakpoint *b) | |
6847 | { | |
6848 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; | |
6849 | ||
6850 | xfree (c->exec_pathname); | |
348d480f | 6851 | |
2060206e | 6852 | base_breakpoint_ops.dtor (b); |
b4d90040 PA |
6853 | } |
6854 | ||
77b06cd7 TJB |
6855 | static int |
6856 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 6857 | { |
77b06cd7 | 6858 | return target_insert_exec_catchpoint (PIDGET (inferior_ptid)); |
fe798b75 | 6859 | } |
c906108c | 6860 | |
fe798b75 | 6861 | static int |
77b06cd7 | 6862 | remove_catch_exec (struct bp_location *bl) |
fe798b75 JB |
6863 | { |
6864 | return target_remove_exec_catchpoint (PIDGET (inferior_ptid)); | |
6865 | } | |
c906108c | 6866 | |
fe798b75 | 6867 | static int |
f1310107 | 6868 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
09ac7c10 TT |
6869 | struct address_space *aspace, CORE_ADDR bp_addr, |
6870 | const struct target_waitstatus *ws) | |
fe798b75 | 6871 | { |
b4d90040 PA |
6872 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
6873 | ||
f90263c1 TT |
6874 | if (ws->kind != TARGET_WAITKIND_EXECD) |
6875 | return 0; | |
6876 | ||
6877 | c->exec_pathname = xstrdup (ws->value.execd_pathname); | |
6878 | return 1; | |
fe798b75 | 6879 | } |
c906108c | 6880 | |
fe798b75 | 6881 | static enum print_stop_action |
348d480f | 6882 | print_it_catch_exec (bpstat bs) |
fe798b75 | 6883 | { |
36dfb11c | 6884 | struct ui_out *uiout = current_uiout; |
348d480f | 6885 | struct breakpoint *b = bs->breakpoint_at; |
b4d90040 PA |
6886 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
6887 | ||
fe798b75 | 6888 | annotate_catchpoint (b->number); |
36dfb11c TT |
6889 | if (b->disposition == disp_del) |
6890 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
6891 | else | |
6892 | ui_out_text (uiout, "\nCatchpoint "); | |
6893 | if (ui_out_is_mi_like_p (uiout)) | |
6894 | { | |
6895 | ui_out_field_string (uiout, "reason", | |
6896 | async_reason_lookup (EXEC_ASYNC_EXEC)); | |
6897 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
6898 | } | |
6899 | ui_out_field_int (uiout, "bkptno", b->number); | |
6900 | ui_out_text (uiout, " (exec'd "); | |
6901 | ui_out_field_string (uiout, "new-exec", c->exec_pathname); | |
6902 | ui_out_text (uiout, "), "); | |
6903 | ||
fe798b75 | 6904 | return PRINT_SRC_AND_LOC; |
c906108c SS |
6905 | } |
6906 | ||
fe798b75 | 6907 | static void |
a6d9a66e | 6908 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 | 6909 | { |
b4d90040 | 6910 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
fe798b75 | 6911 | struct value_print_options opts; |
79a45e25 | 6912 | struct ui_out *uiout = current_uiout; |
fe798b75 JB |
6913 | |
6914 | get_user_print_options (&opts); | |
6915 | ||
6916 | /* Field 4, the address, is omitted (which makes the columns | |
6917 | not line up too nicely with the headers, but the effect | |
6918 | is relatively readable). */ | |
6919 | if (opts.addressprint) | |
6920 | ui_out_field_skip (uiout, "addr"); | |
6921 | annotate_field (5); | |
6922 | ui_out_text (uiout, "exec"); | |
b4d90040 | 6923 | if (c->exec_pathname != NULL) |
fe798b75 JB |
6924 | { |
6925 | ui_out_text (uiout, ", program \""); | |
b4d90040 | 6926 | ui_out_field_string (uiout, "what", c->exec_pathname); |
fe798b75 JB |
6927 | ui_out_text (uiout, "\" "); |
6928 | } | |
6929 | } | |
6930 | ||
6931 | static void | |
6932 | print_mention_catch_exec (struct breakpoint *b) | |
6933 | { | |
6934 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
6935 | } | |
6936 | ||
6149aea9 PA |
6937 | /* Implement the "print_recreate" breakpoint_ops method for exec |
6938 | catchpoints. */ | |
6939 | ||
6940 | static void | |
6941 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
6942 | { | |
6943 | fprintf_unfiltered (fp, "catch exec"); | |
d9b3f62e | 6944 | print_recreate_thread (b, fp); |
6149aea9 PA |
6945 | } |
6946 | ||
2060206e | 6947 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
fe798b75 | 6948 | |
a96d9b2e SDJ |
6949 | static void |
6950 | create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, | |
c0a91b2b | 6951 | const struct breakpoint_ops *ops) |
a96d9b2e | 6952 | { |
be5c67c1 | 6953 | struct syscall_catchpoint *c; |
a96d9b2e | 6954 | struct gdbarch *gdbarch = get_current_arch (); |
a96d9b2e | 6955 | |
be5c67c1 PA |
6956 | c = XNEW (struct syscall_catchpoint); |
6957 | init_catchpoint (&c->base, gdbarch, tempflag, NULL, ops); | |
6958 | c->syscalls_to_be_caught = filter; | |
a96d9b2e | 6959 | |
3ea46bff | 6960 | install_breakpoint (0, &c->base, 1); |
a96d9b2e SDJ |
6961 | } |
6962 | ||
c906108c | 6963 | static int |
fba45db2 | 6964 | hw_breakpoint_used_count (void) |
c906108c | 6965 | { |
c906108c | 6966 | int i = 0; |
f1310107 TJB |
6967 | struct breakpoint *b; |
6968 | struct bp_location *bl; | |
c906108c SS |
6969 | |
6970 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6971 | { |
d6b74ac4 | 6972 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
6973 | for (bl = b->loc; bl; bl = bl->next) |
6974 | { | |
6975 | /* Special types of hardware breakpoints may use more than | |
6976 | one register. */ | |
348d480f | 6977 | i += b->ops->resources_needed (bl); |
f1310107 | 6978 | } |
c5aa993b | 6979 | } |
c906108c SS |
6980 | |
6981 | return i; | |
6982 | } | |
6983 | ||
a1398e0c PA |
6984 | /* Returns the resources B would use if it were a hardware |
6985 | watchpoint. */ | |
6986 | ||
c906108c | 6987 | static int |
a1398e0c | 6988 | hw_watchpoint_use_count (struct breakpoint *b) |
c906108c | 6989 | { |
c906108c | 6990 | int i = 0; |
e09342b5 | 6991 | struct bp_location *bl; |
c906108c | 6992 | |
a1398e0c PA |
6993 | if (!breakpoint_enabled (b)) |
6994 | return 0; | |
6995 | ||
6996 | for (bl = b->loc; bl; bl = bl->next) | |
6997 | { | |
6998 | /* Special types of hardware watchpoints may use more than | |
6999 | one register. */ | |
7000 | i += b->ops->resources_needed (bl); | |
7001 | } | |
7002 | ||
7003 | return i; | |
7004 | } | |
7005 | ||
7006 | /* Returns the sum the used resources of all hardware watchpoints of | |
7007 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED | |
7008 | the sum of the used resources of all hardware watchpoints of other | |
7009 | types _not_ TYPE. */ | |
7010 | ||
7011 | static int | |
7012 | hw_watchpoint_used_count_others (struct breakpoint *except, | |
7013 | enum bptype type, int *other_type_used) | |
7014 | { | |
7015 | int i = 0; | |
7016 | struct breakpoint *b; | |
7017 | ||
c906108c SS |
7018 | *other_type_used = 0; |
7019 | ALL_BREAKPOINTS (b) | |
e09342b5 | 7020 | { |
a1398e0c PA |
7021 | if (b == except) |
7022 | continue; | |
e09342b5 TJB |
7023 | if (!breakpoint_enabled (b)) |
7024 | continue; | |
7025 | ||
a1398e0c PA |
7026 | if (b->type == type) |
7027 | i += hw_watchpoint_use_count (b); | |
7028 | else if (is_hardware_watchpoint (b)) | |
7029 | *other_type_used = 1; | |
e09342b5 TJB |
7030 | } |
7031 | ||
c906108c SS |
7032 | return i; |
7033 | } | |
7034 | ||
c906108c | 7035 | void |
fba45db2 | 7036 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 7037 | { |
c5aa993b | 7038 | struct breakpoint *b; |
c906108c SS |
7039 | |
7040 | ALL_BREAKPOINTS (b) | |
c5aa993b | 7041 | { |
cc60f2e3 | 7042 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 7043 | { |
b5de0fa7 | 7044 | b->enable_state = bp_call_disabled; |
b60e7edf | 7045 | update_global_location_list (0); |
c5aa993b JM |
7046 | } |
7047 | } | |
c906108c SS |
7048 | } |
7049 | ||
7050 | void | |
fba45db2 | 7051 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 7052 | { |
c5aa993b | 7053 | struct breakpoint *b; |
c906108c SS |
7054 | |
7055 | ALL_BREAKPOINTS (b) | |
c5aa993b | 7056 | { |
cc60f2e3 | 7057 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 7058 | { |
b5de0fa7 | 7059 | b->enable_state = bp_enabled; |
b60e7edf | 7060 | update_global_location_list (1); |
c5aa993b JM |
7061 | } |
7062 | } | |
c906108c SS |
7063 | } |
7064 | ||
8bea4e01 UW |
7065 | void |
7066 | disable_breakpoints_before_startup (void) | |
7067 | { | |
6c95b8df | 7068 | current_program_space->executing_startup = 1; |
f8eba3c6 | 7069 | update_global_location_list (0); |
8bea4e01 UW |
7070 | } |
7071 | ||
7072 | void | |
7073 | enable_breakpoints_after_startup (void) | |
7074 | { | |
6c95b8df | 7075 | current_program_space->executing_startup = 0; |
f8eba3c6 | 7076 | breakpoint_re_set (); |
8bea4e01 UW |
7077 | } |
7078 | ||
c906108c SS |
7079 | |
7080 | /* Set a breakpoint that will evaporate an end of command | |
7081 | at address specified by SAL. | |
7082 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
7083 | ||
7084 | struct breakpoint * | |
a6d9a66e UW |
7085 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
7086 | struct frame_id frame_id, enum bptype type) | |
c906108c | 7087 | { |
52f0bd74 | 7088 | struct breakpoint *b; |
edb3359d DJ |
7089 | |
7090 | /* If FRAME_ID is valid, it should be a real frame, not an inlined | |
7091 | one. */ | |
7092 | gdb_assert (!frame_id_inlined_p (frame_id)); | |
7093 | ||
06edf0c0 | 7094 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
7095 | b->enable_state = bp_enabled; |
7096 | b->disposition = disp_donttouch; | |
818dd999 | 7097 | b->frame_id = frame_id; |
c906108c | 7098 | |
4a64f543 MS |
7099 | /* If we're debugging a multi-threaded program, then we want |
7100 | momentary breakpoints to be active in only a single thread of | |
7101 | control. */ | |
39f77062 KB |
7102 | if (in_thread_list (inferior_ptid)) |
7103 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 7104 | |
b60e7edf | 7105 | update_global_location_list_nothrow (1); |
74960c60 | 7106 | |
c906108c SS |
7107 | return b; |
7108 | } | |
611c83ae | 7109 | |
06edf0c0 PA |
7110 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
7111 | The new breakpoint will have type TYPE, and use OPS as it | |
7112 | breakpoint_ops. */ | |
e58b0e63 | 7113 | |
06edf0c0 PA |
7114 | static struct breakpoint * |
7115 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
7116 | enum bptype type, | |
c0a91b2b | 7117 | const struct breakpoint_ops *ops) |
e58b0e63 PA |
7118 | { |
7119 | struct breakpoint *copy; | |
7120 | ||
06edf0c0 | 7121 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 7122 | copy->loc = allocate_bp_location (copy); |
0e30163f | 7123 | set_breakpoint_location_function (copy->loc, 1); |
e58b0e63 | 7124 | |
a6d9a66e | 7125 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
7126 | copy->loc->requested_address = orig->loc->requested_address; |
7127 | copy->loc->address = orig->loc->address; | |
7128 | copy->loc->section = orig->loc->section; | |
6c95b8df | 7129 | copy->loc->pspace = orig->loc->pspace; |
e58b0e63 | 7130 | |
f8eba3c6 TT |
7131 | if (orig->loc->source_file != NULL) |
7132 | copy->loc->source_file = xstrdup (orig->loc->source_file); | |
e58b0e63 | 7133 | |
f8eba3c6 | 7134 | copy->loc->line_number = orig->loc->line_number; |
e58b0e63 PA |
7135 | copy->frame_id = orig->frame_id; |
7136 | copy->thread = orig->thread; | |
6c95b8df | 7137 | copy->pspace = orig->pspace; |
e58b0e63 PA |
7138 | |
7139 | copy->enable_state = bp_enabled; | |
7140 | copy->disposition = disp_donttouch; | |
7141 | copy->number = internal_breakpoint_number--; | |
7142 | ||
7143 | update_global_location_list_nothrow (0); | |
7144 | return copy; | |
7145 | } | |
7146 | ||
06edf0c0 PA |
7147 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
7148 | ORIG is NULL. */ | |
7149 | ||
7150 | struct breakpoint * | |
7151 | clone_momentary_breakpoint (struct breakpoint *orig) | |
7152 | { | |
7153 | /* If there's nothing to clone, then return nothing. */ | |
7154 | if (orig == NULL) | |
7155 | return NULL; | |
7156 | ||
7157 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops); | |
7158 | } | |
7159 | ||
611c83ae | 7160 | struct breakpoint * |
a6d9a66e UW |
7161 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
7162 | enum bptype type) | |
611c83ae PA |
7163 | { |
7164 | struct symtab_and_line sal; | |
7165 | ||
7166 | sal = find_pc_line (pc, 0); | |
7167 | sal.pc = pc; | |
7168 | sal.section = find_pc_overlay (pc); | |
7169 | sal.explicit_pc = 1; | |
7170 | ||
a6d9a66e | 7171 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 7172 | } |
c906108c | 7173 | \f |
c5aa993b | 7174 | |
c906108c SS |
7175 | /* Tell the user we have just set a breakpoint B. */ |
7176 | ||
7177 | static void | |
fba45db2 | 7178 | mention (struct breakpoint *b) |
c906108c | 7179 | { |
348d480f | 7180 | b->ops->print_mention (b); |
79a45e25 | 7181 | if (ui_out_is_mi_like_p (current_uiout)) |
fb40c209 | 7182 | return; |
c906108c SS |
7183 | printf_filtered ("\n"); |
7184 | } | |
c906108c | 7185 | \f |
c5aa993b | 7186 | |
0d381245 | 7187 | static struct bp_location * |
39d61571 | 7188 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
7189 | const struct symtab_and_line *sal) |
7190 | { | |
7191 | struct bp_location *loc, **tmp; | |
3742cc8b YQ |
7192 | CORE_ADDR adjusted_address; |
7193 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); | |
7194 | ||
7195 | if (loc_gdbarch == NULL) | |
7196 | loc_gdbarch = b->gdbarch; | |
7197 | ||
7198 | /* Adjust the breakpoint's address prior to allocating a location. | |
7199 | Once we call allocate_bp_location(), that mostly uninitialized | |
7200 | location will be placed on the location chain. Adjustment of the | |
7201 | breakpoint may cause target_read_memory() to be called and we do | |
7202 | not want its scan of the location chain to find a breakpoint and | |
7203 | location that's only been partially initialized. */ | |
7204 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, | |
7205 | sal->pc, b->type); | |
0d381245 | 7206 | |
39d61571 | 7207 | loc = allocate_bp_location (b); |
0d381245 VP |
7208 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
7209 | ; | |
7210 | *tmp = loc; | |
3742cc8b | 7211 | |
0d381245 | 7212 | loc->requested_address = sal->pc; |
3742cc8b | 7213 | loc->address = adjusted_address; |
6c95b8df PA |
7214 | loc->pspace = sal->pspace; |
7215 | gdb_assert (loc->pspace != NULL); | |
0d381245 | 7216 | loc->section = sal->section; |
3742cc8b | 7217 | loc->gdbarch = loc_gdbarch; |
f8eba3c6 TT |
7218 | |
7219 | if (sal->symtab != NULL) | |
7220 | loc->source_file = xstrdup (sal->symtab->filename); | |
7221 | loc->line_number = sal->line; | |
7222 | ||
0e30163f JK |
7223 | set_breakpoint_location_function (loc, |
7224 | sal->explicit_pc || sal->explicit_line); | |
0d381245 VP |
7225 | return loc; |
7226 | } | |
514f746b AR |
7227 | \f |
7228 | ||
7229 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
7230 | return 0 otherwise. */ | |
7231 | ||
7232 | static int | |
7233 | bp_loc_is_permanent (struct bp_location *loc) | |
7234 | { | |
7235 | int len; | |
7236 | CORE_ADDR addr; | |
1afeeb75 | 7237 | const gdb_byte *bpoint; |
514f746b | 7238 | gdb_byte *target_mem; |
939c61fa JK |
7239 | struct cleanup *cleanup; |
7240 | int retval = 0; | |
514f746b AR |
7241 | |
7242 | gdb_assert (loc != NULL); | |
7243 | ||
7244 | addr = loc->address; | |
1afeeb75 | 7245 | bpoint = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 7246 | |
939c61fa | 7247 | /* Software breakpoints unsupported? */ |
1afeeb75 | 7248 | if (bpoint == NULL) |
939c61fa JK |
7249 | return 0; |
7250 | ||
514f746b AR |
7251 | target_mem = alloca (len); |
7252 | ||
939c61fa JK |
7253 | /* Enable the automatic memory restoration from breakpoints while |
7254 | we read the memory. Otherwise we could say about our temporary | |
7255 | breakpoints they are permanent. */ | |
6c95b8df PA |
7256 | cleanup = save_current_space_and_thread (); |
7257 | ||
7258 | switch_to_program_space_and_thread (loc->pspace); | |
7259 | make_show_memory_breakpoints_cleanup (0); | |
939c61fa | 7260 | |
514f746b | 7261 | if (target_read_memory (loc->address, target_mem, len) == 0 |
1afeeb75 | 7262 | && memcmp (target_mem, bpoint, len) == 0) |
939c61fa | 7263 | retval = 1; |
514f746b | 7264 | |
939c61fa JK |
7265 | do_cleanups (cleanup); |
7266 | ||
7267 | return retval; | |
514f746b AR |
7268 | } |
7269 | ||
7270 | ||
c3f6f71d | 7271 | |
018d34a4 VP |
7272 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
7273 | as textual description of the location, and COND_STRING | |
db107f19 | 7274 | as condition expression. */ |
018d34a4 VP |
7275 | |
7276 | static void | |
d9b3f62e PA |
7277 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
7278 | struct symtabs_and_lines sals, char *addr_string, | |
f8eba3c6 | 7279 | char *filter, char *cond_string, |
d9b3f62e PA |
7280 | enum bptype type, enum bpdisp disposition, |
7281 | int thread, int task, int ignore_count, | |
c0a91b2b | 7282 | const struct breakpoint_ops *ops, int from_tty, |
d9b3f62e | 7283 | int enabled, int internal, int display_canonical) |
018d34a4 | 7284 | { |
0d381245 | 7285 | int i; |
018d34a4 VP |
7286 | |
7287 | if (type == bp_hardware_breakpoint) | |
7288 | { | |
fbbd034e AS |
7289 | int target_resources_ok; |
7290 | ||
7291 | i = hw_breakpoint_used_count (); | |
7292 | target_resources_ok = | |
7293 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
018d34a4 VP |
7294 | i + 1, 0); |
7295 | if (target_resources_ok == 0) | |
7296 | error (_("No hardware breakpoint support in the target.")); | |
7297 | else if (target_resources_ok < 0) | |
7298 | error (_("Hardware breakpoints used exceeds limit.")); | |
7299 | } | |
7300 | ||
6c95b8df PA |
7301 | gdb_assert (sals.nelts > 0); |
7302 | ||
0d381245 VP |
7303 | for (i = 0; i < sals.nelts; ++i) |
7304 | { | |
7305 | struct symtab_and_line sal = sals.sals[i]; | |
7306 | struct bp_location *loc; | |
7307 | ||
7308 | if (from_tty) | |
5af949e3 UW |
7309 | { |
7310 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
7311 | if (!loc_gdbarch) | |
7312 | loc_gdbarch = gdbarch; | |
7313 | ||
7314 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 7315 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 7316 | } |
0d381245 VP |
7317 | |
7318 | if (i == 0) | |
7319 | { | |
d9b3f62e | 7320 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 7321 | b->thread = thread; |
4a306c9a | 7322 | b->task = task; |
018d34a4 | 7323 | |
0d381245 VP |
7324 | b->cond_string = cond_string; |
7325 | b->ignore_count = ignore_count; | |
41447f92 | 7326 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 7327 | b->disposition = disposition; |
6c95b8df | 7328 | |
0fb4aa4b PA |
7329 | if (type == bp_static_tracepoint) |
7330 | { | |
d9b3f62e | 7331 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
7332 | struct static_tracepoint_marker marker; |
7333 | ||
983af33b | 7334 | if (strace_marker_p (b)) |
0fb4aa4b PA |
7335 | { |
7336 | /* We already know the marker exists, otherwise, we | |
7337 | wouldn't see a sal for it. */ | |
7338 | char *p = &addr_string[3]; | |
7339 | char *endp; | |
7340 | char *marker_str; | |
0fb4aa4b | 7341 | |
e9cafbcc | 7342 | p = skip_spaces (p); |
0fb4aa4b | 7343 | |
e9cafbcc | 7344 | endp = skip_to_space (p); |
0fb4aa4b PA |
7345 | |
7346 | marker_str = savestring (p, endp - p); | |
d9b3f62e | 7347 | t->static_trace_marker_id = marker_str; |
0fb4aa4b | 7348 | |
3e43a32a MS |
7349 | printf_filtered (_("Probed static tracepoint " |
7350 | "marker \"%s\"\n"), | |
d9b3f62e | 7351 | t->static_trace_marker_id); |
0fb4aa4b PA |
7352 | } |
7353 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
7354 | { | |
d9b3f62e | 7355 | t->static_trace_marker_id = xstrdup (marker.str_id); |
0fb4aa4b PA |
7356 | release_static_tracepoint_marker (&marker); |
7357 | ||
3e43a32a MS |
7358 | printf_filtered (_("Probed static tracepoint " |
7359 | "marker \"%s\"\n"), | |
d9b3f62e | 7360 | t->static_trace_marker_id); |
0fb4aa4b PA |
7361 | } |
7362 | else | |
3e43a32a MS |
7363 | warning (_("Couldn't determine the static " |
7364 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
7365 | } |
7366 | ||
0d381245 VP |
7367 | loc = b->loc; |
7368 | } | |
7369 | else | |
018d34a4 | 7370 | { |
39d61571 | 7371 | loc = add_location_to_breakpoint (b, &sal); |
0d381245 VP |
7372 | } |
7373 | ||
514f746b AR |
7374 | if (bp_loc_is_permanent (loc)) |
7375 | make_breakpoint_permanent (b); | |
7376 | ||
0d381245 VP |
7377 | if (b->cond_string) |
7378 | { | |
7379 | char *arg = b->cond_string; | |
d32a6982 | 7380 | loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0); |
0d381245 | 7381 | if (*arg) |
db107f19 | 7382 | error (_("Garbage %s follows condition"), arg); |
018d34a4 | 7383 | } |
0d381245 | 7384 | } |
018d34a4 | 7385 | |
56435ebe | 7386 | b->display_canonical = display_canonical; |
018d34a4 VP |
7387 | if (addr_string) |
7388 | b->addr_string = addr_string; | |
7389 | else | |
7390 | /* addr_string has to be used or breakpoint_re_set will delete | |
7391 | me. */ | |
5af949e3 UW |
7392 | b->addr_string |
7393 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
f8eba3c6 | 7394 | b->filter = filter; |
d9b3f62e | 7395 | } |
018d34a4 | 7396 | |
d9b3f62e PA |
7397 | static void |
7398 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
7399 | struct symtabs_and_lines sals, char *addr_string, | |
f8eba3c6 | 7400 | char *filter, char *cond_string, |
d9b3f62e PA |
7401 | enum bptype type, enum bpdisp disposition, |
7402 | int thread, int task, int ignore_count, | |
c0a91b2b | 7403 | const struct breakpoint_ops *ops, int from_tty, |
d9b3f62e PA |
7404 | int enabled, int internal, int display_canonical) |
7405 | { | |
7406 | struct breakpoint *b; | |
7407 | struct cleanup *old_chain; | |
7408 | ||
7409 | if (is_tracepoint_type (type)) | |
7410 | { | |
7411 | struct tracepoint *t; | |
7412 | ||
7413 | t = XCNEW (struct tracepoint); | |
7414 | b = &t->base; | |
7415 | } | |
7416 | else | |
7417 | b = XNEW (struct breakpoint); | |
7418 | ||
7419 | old_chain = make_cleanup (xfree, b); | |
7420 | ||
7421 | init_breakpoint_sal (b, gdbarch, | |
7422 | sals, addr_string, | |
f8eba3c6 | 7423 | filter, cond_string, |
d9b3f62e PA |
7424 | type, disposition, |
7425 | thread, task, ignore_count, | |
7426 | ops, from_tty, | |
7427 | enabled, internal, display_canonical); | |
7428 | discard_cleanups (old_chain); | |
7429 | ||
3ea46bff | 7430 | install_breakpoint (internal, b, 0); |
018d34a4 VP |
7431 | } |
7432 | ||
7433 | /* Add SALS.nelts breakpoints to the breakpoint table. For each | |
7434 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
7435 | value. COND_STRING, if not NULL, specified the condition to be | |
7436 | used for all breakpoints. Essentially the only case where | |
7437 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
7438 | function. In that case, it's still not possible to specify | |
7439 | separate conditions for different overloaded functions, so | |
7440 | we take just a single condition string. | |
7441 | ||
c3f6f71d | 7442 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 7443 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
7444 | array contents). If the function fails (error() is called), the |
7445 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 7446 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
7447 | |
7448 | static void | |
8cdf0e15 | 7449 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 | 7450 | struct linespec_result *canonical, |
8cdf0e15 VP |
7451 | char *cond_string, |
7452 | enum bptype type, enum bpdisp disposition, | |
7453 | int thread, int task, int ignore_count, | |
c0a91b2b | 7454 | const struct breakpoint_ops *ops, int from_tty, |
84f4c1fe | 7455 | int enabled, int internal) |
c906108c | 7456 | { |
018d34a4 | 7457 | int i; |
f8eba3c6 | 7458 | struct linespec_sals *lsal; |
cc59ec59 | 7459 | |
f8eba3c6 TT |
7460 | if (canonical->pre_expanded) |
7461 | gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1); | |
7462 | ||
7463 | for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i) | |
c3f6f71d | 7464 | { |
f8eba3c6 TT |
7465 | /* Note that 'addr_string' can be NULL in the case of a plain |
7466 | 'break', without arguments. */ | |
7467 | char *addr_string = (canonical->addr_string | |
7468 | ? xstrdup (canonical->addr_string) | |
7469 | : NULL); | |
7470 | char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL; | |
7471 | struct cleanup *inner = make_cleanup (xfree, addr_string); | |
0d381245 | 7472 | |
f8eba3c6 TT |
7473 | make_cleanup (xfree, filter_string); |
7474 | create_breakpoint_sal (gdbarch, lsal->sals, | |
7475 | addr_string, | |
7476 | filter_string, | |
8cdf0e15 | 7477 | cond_string, type, disposition, |
84f4c1fe | 7478 | thread, task, ignore_count, ops, |
56435ebe TT |
7479 | from_tty, enabled, internal, |
7480 | canonical->special_display); | |
f8eba3c6 | 7481 | discard_cleanups (inner); |
c3f6f71d | 7482 | } |
c3f6f71d | 7483 | } |
c906108c | 7484 | |
9998af43 | 7485 | /* Parse ADDRESS which is assumed to be a SAL specification possibly |
c3f6f71d | 7486 | followed by conditionals. On return, SALS contains an array of SAL |
4a64f543 | 7487 | addresses found. ADDR_STRING contains a vector of (canonical) |
9998af43 TJB |
7488 | address strings. ADDRESS points to the end of the SAL. |
7489 | ||
7490 | The array and the line spec strings are allocated on the heap, it is | |
7491 | the caller's responsibility to free them. */ | |
c906108c | 7492 | |
b9362cc7 | 7493 | static void |
c3f6f71d | 7494 | parse_breakpoint_sals (char **address, |
58438ac1 | 7495 | struct linespec_result *canonical) |
c3f6f71d JM |
7496 | { |
7497 | char *addr_start = *address; | |
cc59ec59 | 7498 | |
c3f6f71d | 7499 | /* If no arg given, or if first arg is 'if ', use the default |
4a64f543 | 7500 | breakpoint. */ |
c3f6f71d JM |
7501 | if ((*address) == NULL |
7502 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c | 7503 | { |
1bfeeb0f JL |
7504 | /* The last displayed codepoint, if it's valid, is our default breakpoint |
7505 | address. */ | |
7506 | if (last_displayed_sal_is_valid ()) | |
c906108c | 7507 | { |
f8eba3c6 | 7508 | struct linespec_sals lsal; |
c3f6f71d | 7509 | struct symtab_and_line sal; |
cc59ec59 | 7510 | |
4a64f543 | 7511 | init_sal (&sal); /* Initialize to zeroes. */ |
f8eba3c6 | 7512 | lsal.sals.sals = (struct symtab_and_line *) |
c906108c | 7513 | xmalloc (sizeof (struct symtab_and_line)); |
1bfeeb0f JL |
7514 | |
7515 | /* Set sal's pspace, pc, symtab, and line to the values | |
7516 | corresponding to the last call to print_frame_info. */ | |
7517 | get_last_displayed_sal (&sal); | |
7518 | sal.section = find_pc_overlay (sal.pc); | |
00903456 | 7519 | |
4a64f543 | 7520 | /* "break" without arguments is equivalent to "break *PC" |
1bfeeb0f JL |
7521 | where PC is the last displayed codepoint's address. So |
7522 | make sure to set sal.explicit_pc to prevent GDB from | |
7523 | trying to expand the list of sals to include all other | |
7524 | instances with the same symtab and line. */ | |
00903456 JK |
7525 | sal.explicit_pc = 1; |
7526 | ||
f8eba3c6 TT |
7527 | lsal.sals.sals[0] = sal; |
7528 | lsal.sals.nelts = 1; | |
7529 | lsal.canonical = NULL; | |
7530 | ||
7531 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
c906108c SS |
7532 | } |
7533 | else | |
8a3fe4f8 | 7534 | error (_("No default breakpoint address now.")); |
c906108c SS |
7535 | } |
7536 | else | |
7537 | { | |
c906108c | 7538 | /* Force almost all breakpoints to be in terms of the |
4a64f543 MS |
7539 | current_source_symtab (which is decode_line_1's default). |
7540 | This should produce the results we want almost all of the | |
f8eba3c6 TT |
7541 | time while leaving default_breakpoint_* alone. */ |
7542 | if (last_displayed_sal_is_valid ()) | |
7543 | decode_line_full (address, DECODE_LINE_FUNFIRSTLINE, | |
7544 | get_last_displayed_symtab (), | |
7545 | get_last_displayed_line (), | |
7546 | canonical, NULL, NULL); | |
c906108c | 7547 | else |
f8eba3c6 TT |
7548 | decode_line_full (address, DECODE_LINE_FUNFIRSTLINE, |
7549 | (struct symtab *) NULL, 0, | |
7550 | canonical, NULL, NULL); | |
c906108c | 7551 | } |
c3f6f71d | 7552 | } |
c906108c | 7553 | |
c906108c | 7554 | |
c3f6f71d | 7555 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 7556 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 7557 | |
b9362cc7 | 7558 | static void |
23e7acfb | 7559 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
c3f6f71d JM |
7560 | { |
7561 | int i; | |
cc59ec59 | 7562 | |
c3f6f71d | 7563 | for (i = 0; i < sals->nelts; i++) |
ee53e872 | 7564 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
7565 | } |
7566 | ||
7a697b8d SS |
7567 | /* Fast tracepoints may have restrictions on valid locations. For |
7568 | instance, a fast tracepoint using a jump instead of a trap will | |
7569 | likely have to overwrite more bytes than a trap would, and so can | |
7570 | only be placed where the instruction is longer than the jump, or a | |
7571 | multi-instruction sequence does not have a jump into the middle of | |
7572 | it, etc. */ | |
7573 | ||
7574 | static void | |
7575 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
7576 | struct symtabs_and_lines *sals) | |
7577 | { | |
7578 | int i, rslt; | |
7579 | struct symtab_and_line *sal; | |
7580 | char *msg; | |
7581 | struct cleanup *old_chain; | |
7582 | ||
7583 | for (i = 0; i < sals->nelts; i++) | |
7584 | { | |
f8eba3c6 TT |
7585 | struct gdbarch *sarch; |
7586 | ||
7a697b8d SS |
7587 | sal = &sals->sals[i]; |
7588 | ||
f8eba3c6 TT |
7589 | sarch = get_sal_arch (*sal); |
7590 | /* We fall back to GDBARCH if there is no architecture | |
7591 | associated with SAL. */ | |
7592 | if (sarch == NULL) | |
7593 | sarch = gdbarch; | |
7594 | rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc, | |
7a697b8d SS |
7595 | NULL, &msg); |
7596 | old_chain = make_cleanup (xfree, msg); | |
7597 | ||
7598 | if (!rslt) | |
7599 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
f8eba3c6 | 7600 | paddress (sarch, sal->pc), (msg ? msg : "")); |
7a697b8d SS |
7601 | |
7602 | do_cleanups (old_chain); | |
7603 | } | |
7604 | } | |
7605 | ||
018d34a4 VP |
7606 | /* Given TOK, a string specification of condition and thread, as |
7607 | accepted by the 'break' command, extract the condition | |
7608 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 7609 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
7610 | If no condition is found, *COND_STRING is set to NULL. |
7611 | If no thread is found, *THREAD is set to -1. */ | |
7612 | static void | |
7613 | find_condition_and_thread (char *tok, CORE_ADDR pc, | |
4a306c9a | 7614 | char **cond_string, int *thread, int *task) |
018d34a4 VP |
7615 | { |
7616 | *cond_string = NULL; | |
7617 | *thread = -1; | |
7618 | while (tok && *tok) | |
7619 | { | |
7620 | char *end_tok; | |
7621 | int toklen; | |
7622 | char *cond_start = NULL; | |
7623 | char *cond_end = NULL; | |
cc59ec59 | 7624 | |
e9cafbcc | 7625 | tok = skip_spaces (tok); |
018d34a4 | 7626 | |
e9cafbcc | 7627 | end_tok = skip_to_space (tok); |
018d34a4 VP |
7628 | |
7629 | toklen = end_tok - tok; | |
7630 | ||
7631 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
7632 | { | |
f7545552 TT |
7633 | struct expression *expr; |
7634 | ||
018d34a4 | 7635 | tok = cond_start = end_tok + 1; |
f7545552 TT |
7636 | expr = parse_exp_1 (&tok, block_for_pc (pc), 0); |
7637 | xfree (expr); | |
018d34a4 VP |
7638 | cond_end = tok; |
7639 | *cond_string = savestring (cond_start, | |
7640 | cond_end - cond_start); | |
7641 | } | |
7642 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
7643 | { | |
7644 | char *tmptok; | |
7645 | ||
7646 | tok = end_tok + 1; | |
7647 | tmptok = tok; | |
7648 | *thread = strtol (tok, &tok, 0); | |
7649 | if (tok == tmptok) | |
7650 | error (_("Junk after thread keyword.")); | |
7651 | if (!valid_thread_id (*thread)) | |
7652 | error (_("Unknown thread %d."), *thread); | |
7653 | } | |
4a306c9a JB |
7654 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
7655 | { | |
7656 | char *tmptok; | |
7657 | ||
7658 | tok = end_tok + 1; | |
7659 | tmptok = tok; | |
7660 | *task = strtol (tok, &tok, 0); | |
7661 | if (tok == tmptok) | |
7662 | error (_("Junk after task keyword.")); | |
7663 | if (!valid_task_id (*task)) | |
b6199126 | 7664 | error (_("Unknown task %d."), *task); |
4a306c9a | 7665 | } |
018d34a4 VP |
7666 | else |
7667 | error (_("Junk at end of arguments.")); | |
7668 | } | |
7669 | } | |
7670 | ||
0fb4aa4b PA |
7671 | /* Decode a static tracepoint marker spec. */ |
7672 | ||
7673 | static struct symtabs_and_lines | |
7674 | decode_static_tracepoint_spec (char **arg_p) | |
7675 | { | |
7676 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
7677 | struct symtabs_and_lines sals; | |
7678 | struct symtab_and_line sal; | |
7679 | struct symbol *sym; | |
7680 | struct cleanup *old_chain; | |
7681 | char *p = &(*arg_p)[3]; | |
7682 | char *endp; | |
7683 | char *marker_str; | |
7684 | int i; | |
7685 | ||
e9cafbcc | 7686 | p = skip_spaces (p); |
0fb4aa4b | 7687 | |
e9cafbcc | 7688 | endp = skip_to_space (p); |
0fb4aa4b PA |
7689 | |
7690 | marker_str = savestring (p, endp - p); | |
7691 | old_chain = make_cleanup (xfree, marker_str); | |
7692 | ||
7693 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
7694 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
7695 | error (_("No known static tracepoint marker named %s"), marker_str); | |
7696 | ||
7697 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); | |
7698 | sals.sals = xmalloc (sizeof *sals.sals * sals.nelts); | |
7699 | ||
7700 | for (i = 0; i < sals.nelts; i++) | |
7701 | { | |
7702 | struct static_tracepoint_marker *marker; | |
7703 | ||
7704 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
7705 | ||
7706 | init_sal (&sals.sals[i]); | |
7707 | ||
7708 | sals.sals[i] = find_pc_line (marker->address, 0); | |
7709 | sals.sals[i].pc = marker->address; | |
7710 | ||
7711 | release_static_tracepoint_marker (marker); | |
7712 | } | |
7713 | ||
7714 | do_cleanups (old_chain); | |
7715 | ||
7716 | *arg_p = endp; | |
7717 | return sals; | |
7718 | } | |
7719 | ||
fd9b8c24 PA |
7720 | /* Set a breakpoint. This function is shared between CLI and MI |
7721 | functions for setting a breakpoint. This function has two major | |
7722 | modes of operations, selected by the PARSE_CONDITION_AND_THREAD | |
7723 | parameter. If non-zero, the function will parse arg, extracting | |
4a64f543 MS |
7724 | breakpoint location, address and thread. Otherwise, ARG is just |
7725 | the location of breakpoint, with condition and thread specified by | |
7726 | the COND_STRING and THREAD parameters. If INTERNAL is non-zero, | |
7727 | the breakpoint number will be allocated from the internal | |
7728 | breakpoint count. Returns true if any breakpoint was created; | |
7729 | false otherwise. */ | |
0101ce28 | 7730 | |
8cdf0e15 VP |
7731 | int |
7732 | create_breakpoint (struct gdbarch *gdbarch, | |
7733 | char *arg, char *cond_string, int thread, | |
7734 | int parse_condition_and_thread, | |
0fb4aa4b | 7735 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
7736 | int ignore_count, |
7737 | enum auto_boolean pending_break_support, | |
c0a91b2b | 7738 | const struct breakpoint_ops *ops, |
84f4c1fe | 7739 | int from_tty, int enabled, int internal) |
c3f6f71d | 7740 | { |
b78a6381 | 7741 | volatile struct gdb_exception e; |
f8eba3c6 | 7742 | char *copy_arg = NULL; |
c3f6f71d | 7743 | char *addr_start = arg; |
7efd8fc2 | 7744 | struct linespec_result canonical; |
c3f6f71d | 7745 | struct cleanup *old_chain; |
80c99de1 | 7746 | struct cleanup *bkpt_chain = NULL; |
05ff989b | 7747 | int i; |
0101ce28 | 7748 | int pending = 0; |
4a306c9a | 7749 | int task = 0; |
86b17b60 | 7750 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 7751 | |
348d480f PA |
7752 | gdb_assert (ops != NULL); |
7753 | ||
7efd8fc2 | 7754 | init_linespec_result (&canonical); |
c3f6f71d | 7755 | |
b78a6381 TT |
7756 | TRY_CATCH (e, RETURN_MASK_ALL) |
7757 | { | |
983af33b SDJ |
7758 | ops->create_sals_from_address (&arg, &canonical, type_wanted, |
7759 | addr_start, ©_arg); | |
b78a6381 | 7760 | } |
0101ce28 JJ |
7761 | |
7762 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 7763 | switch (e.reason) |
0101ce28 | 7764 | { |
983af33b SDJ |
7765 | case GDB_NO_ERROR: |
7766 | if (VEC_empty (linespec_sals, canonical.sals)) | |
7767 | return 0; | |
7768 | break; | |
05ff989b AC |
7769 | case RETURN_ERROR: |
7770 | switch (e.error) | |
0101ce28 | 7771 | { |
05ff989b | 7772 | case NOT_FOUND_ERROR: |
0101ce28 | 7773 | |
05ff989b AC |
7774 | /* If pending breakpoint support is turned off, throw |
7775 | error. */ | |
fa8d40ab JJ |
7776 | |
7777 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
7778 | throw_exception (e); |
7779 | ||
7780 | exception_print (gdb_stderr, e); | |
fa8d40ab | 7781 | |
05ff989b AC |
7782 | /* If pending breakpoint support is auto query and the user |
7783 | selects no, then simply return the error code. */ | |
059fb39f | 7784 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
bfccc43c YQ |
7785 | && !nquery (_("Make %s pending on future shared library load? "), |
7786 | bptype_string (type_wanted))) | |
fd9b8c24 | 7787 | return 0; |
fa8d40ab | 7788 | |
05ff989b AC |
7789 | /* At this point, either the user was queried about setting |
7790 | a pending breakpoint and selected yes, or pending | |
7791 | breakpoint behavior is on and thus a pending breakpoint | |
7792 | is defaulted on behalf of the user. */ | |
f8eba3c6 TT |
7793 | { |
7794 | struct linespec_sals lsal; | |
7795 | ||
7796 | copy_arg = xstrdup (addr_start); | |
7797 | lsal.canonical = xstrdup (copy_arg); | |
7798 | lsal.sals.nelts = 1; | |
7799 | lsal.sals.sals = XNEW (struct symtab_and_line); | |
7800 | init_sal (&lsal.sals.sals[0]); | |
7801 | pending = 1; | |
7802 | VEC_safe_push (linespec_sals, canonical.sals, &lsal); | |
7803 | } | |
05ff989b AC |
7804 | break; |
7805 | default: | |
98deb0da | 7806 | throw_exception (e); |
0101ce28 | 7807 | } |
2abae994 | 7808 | break; |
05ff989b | 7809 | default: |
983af33b | 7810 | throw_exception (e); |
0101ce28 | 7811 | } |
c3f6f71d | 7812 | |
4a64f543 | 7813 | /* Create a chain of things that always need to be cleaned up. */ |
f8eba3c6 | 7814 | old_chain = make_cleanup_destroy_linespec_result (&canonical); |
c3f6f71d | 7815 | |
c3f6f71d JM |
7816 | /* ----------------------------- SNIP ----------------------------- |
7817 | Anything added to the cleanup chain beyond this point is assumed | |
7818 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
7819 | then the memory is not reclaimed. */ |
7820 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d | 7821 | |
c3f6f71d JM |
7822 | /* Resolve all line numbers to PC's and verify that the addresses |
7823 | are ok for the target. */ | |
0101ce28 | 7824 | if (!pending) |
f8eba3c6 TT |
7825 | { |
7826 | int ix; | |
7827 | struct linespec_sals *iter; | |
7828 | ||
7829 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
7830 | breakpoint_sals_to_pc (&iter->sals); | |
7831 | } | |
c3f6f71d | 7832 | |
7a697b8d | 7833 | /* Fast tracepoints may have additional restrictions on location. */ |
bfccc43c | 7834 | if (!pending && type_wanted == bp_fast_tracepoint) |
f8eba3c6 TT |
7835 | { |
7836 | int ix; | |
7837 | struct linespec_sals *iter; | |
7838 | ||
7839 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
7840 | check_fast_tracepoint_sals (gdbarch, &iter->sals); | |
7841 | } | |
7a697b8d | 7842 | |
c3f6f71d JM |
7843 | /* Verify that condition can be parsed, before setting any |
7844 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 7845 | breakpoint. */ |
0101ce28 | 7846 | if (!pending) |
c3f6f71d | 7847 | { |
f8eba3c6 TT |
7848 | struct linespec_sals *lsal; |
7849 | ||
7850 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
7851 | ||
2f069f6f | 7852 | if (parse_condition_and_thread) |
72b2ff0e VP |
7853 | { |
7854 | /* Here we only parse 'arg' to separate condition | |
7855 | from thread number, so parsing in context of first | |
7856 | sal is OK. When setting the breakpoint we'll | |
7857 | re-parse it in context of each sal. */ | |
7858 | cond_string = NULL; | |
7859 | thread = -1; | |
f8eba3c6 | 7860 | find_condition_and_thread (arg, lsal->sals.sals[0].pc, &cond_string, |
4a306c9a | 7861 | &thread, &task); |
72b2ff0e VP |
7862 | if (cond_string) |
7863 | make_cleanup (xfree, cond_string); | |
7864 | } | |
2f069f6f | 7865 | else |
72b2ff0e VP |
7866 | { |
7867 | /* Create a private copy of condition string. */ | |
7868 | if (cond_string) | |
7869 | { | |
7870 | cond_string = xstrdup (cond_string); | |
7871 | make_cleanup (xfree, cond_string); | |
7872 | } | |
7873 | } | |
0fb4aa4b | 7874 | |
983af33b | 7875 | ops->create_breakpoints_sal (gdbarch, &canonical, lsal, |
d9b3f62e PA |
7876 | cond_string, type_wanted, |
7877 | tempflag ? disp_del : disp_donttouch, | |
7878 | thread, task, ignore_count, ops, | |
983af33b | 7879 | from_tty, enabled, internal); |
c906108c | 7880 | } |
0101ce28 JJ |
7881 | else |
7882 | { | |
0101ce28 JJ |
7883 | struct breakpoint *b; |
7884 | ||
0101ce28 JJ |
7885 | make_cleanup (xfree, copy_arg); |
7886 | ||
bfccc43c YQ |
7887 | if (is_tracepoint_type (type_wanted)) |
7888 | { | |
7889 | struct tracepoint *t; | |
7890 | ||
7891 | t = XCNEW (struct tracepoint); | |
7892 | b = &t->base; | |
7893 | } | |
7894 | else | |
7895 | b = XNEW (struct breakpoint); | |
7896 | ||
7897 | init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops); | |
7898 | ||
f8eba3c6 | 7899 | b->addr_string = copy_arg; |
72b2ff0e | 7900 | b->cond_string = NULL; |
0101ce28 | 7901 | b->ignore_count = ignore_count; |
0101ce28 | 7902 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 7903 | b->condition_not_parsed = 1; |
41447f92 | 7904 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
cc72b2a2 KP |
7905 | if ((type_wanted != bp_breakpoint |
7906 | && type_wanted != bp_hardware_breakpoint) || thread != -1) | |
f8eba3c6 | 7907 | b->pspace = current_program_space; |
8bea4e01 | 7908 | |
bfccc43c | 7909 | install_breakpoint (internal, b, 0); |
0101ce28 JJ |
7910 | } |
7911 | ||
f8eba3c6 | 7912 | if (VEC_length (linespec_sals, canonical.sals) > 1) |
95a42b64 | 7913 | { |
3e43a32a MS |
7914 | warning (_("Multiple breakpoints were set.\nUse the " |
7915 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 7916 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
7917 | } |
7918 | ||
80c99de1 PA |
7919 | /* That's it. Discard the cleanups for data inserted into the |
7920 | breakpoint. */ | |
7921 | discard_cleanups (bkpt_chain); | |
7922 | /* But cleanup everything else. */ | |
c3f6f71d | 7923 | do_cleanups (old_chain); |
217dc9e2 | 7924 | |
80c99de1 | 7925 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
217dc9e2 | 7926 | update_global_location_list (1); |
fd9b8c24 PA |
7927 | |
7928 | return 1; | |
c3f6f71d | 7929 | } |
c906108c | 7930 | |
348d480f | 7931 | /* Set a breakpoint. |
72b2ff0e VP |
7932 | ARG is a string describing breakpoint address, |
7933 | condition, and thread. | |
7934 | FLAG specifies if a breakpoint is hardware on, | |
7935 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
7936 | and BP_TEMPFLAG. */ | |
348d480f | 7937 | |
98deb0da | 7938 | static void |
72b2ff0e | 7939 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 7940 | { |
72b2ff0e | 7941 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
7942 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
7943 | ? bp_hardware_breakpoint | |
7944 | : bp_breakpoint); | |
c3f6f71d | 7945 | |
8cdf0e15 VP |
7946 | create_breakpoint (get_current_arch (), |
7947 | arg, | |
7948 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b | 7949 | tempflag, type_wanted, |
8cdf0e15 VP |
7950 | 0 /* Ignore count */, |
7951 | pending_break_support, | |
348d480f | 7952 | &bkpt_breakpoint_ops, |
8cdf0e15 | 7953 | from_tty, |
84f4c1fe PM |
7954 | 1 /* enabled */, |
7955 | 0 /* internal */); | |
c906108c SS |
7956 | } |
7957 | ||
c906108c SS |
7958 | /* Helper function for break_command_1 and disassemble_command. */ |
7959 | ||
7960 | void | |
fba45db2 | 7961 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
7962 | { |
7963 | CORE_ADDR pc; | |
7964 | ||
7965 | if (sal->pc == 0 && sal->symtab != NULL) | |
7966 | { | |
7967 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 7968 | error (_("No line %d in file \"%s\"."), |
c906108c SS |
7969 | sal->line, sal->symtab->filename); |
7970 | sal->pc = pc; | |
6a048695 | 7971 | |
4a64f543 MS |
7972 | /* If this SAL corresponds to a breakpoint inserted using a line |
7973 | number, then skip the function prologue if necessary. */ | |
6a048695 | 7974 | if (sal->explicit_line) |
059acae7 | 7975 | skip_prologue_sal (sal); |
c906108c SS |
7976 | } |
7977 | ||
7978 | if (sal->section == 0 && sal->symtab != NULL) | |
7979 | { | |
7980 | struct blockvector *bv; | |
c5aa993b JM |
7981 | struct block *b; |
7982 | struct symbol *sym; | |
c906108c | 7983 | |
801e3a5b | 7984 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
7985 | if (bv != NULL) |
7986 | { | |
7f0df278 | 7987 | sym = block_linkage_function (b); |
c906108c SS |
7988 | if (sym != NULL) |
7989 | { | |
7990 | fixup_symbol_section (sym, sal->symtab->objfile); | |
714835d5 | 7991 | sal->section = SYMBOL_OBJ_SECTION (sym); |
c906108c SS |
7992 | } |
7993 | else | |
7994 | { | |
4a64f543 MS |
7995 | /* It really is worthwhile to have the section, so we'll |
7996 | just have to look harder. This case can be executed | |
7997 | if we have line numbers but no functions (as can | |
7998 | happen in assembly source). */ | |
c906108c | 7999 | |
c5aa993b | 8000 | struct minimal_symbol *msym; |
6c95b8df PA |
8001 | struct cleanup *old_chain = save_current_space_and_thread (); |
8002 | ||
8003 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
8004 | |
8005 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
8006 | if (msym) | |
714835d5 | 8007 | sal->section = SYMBOL_OBJ_SECTION (msym); |
6c95b8df PA |
8008 | |
8009 | do_cleanups (old_chain); | |
c906108c SS |
8010 | } |
8011 | } | |
8012 | } | |
8013 | } | |
8014 | ||
8015 | void | |
fba45db2 | 8016 | break_command (char *arg, int from_tty) |
c906108c | 8017 | { |
db107f19 | 8018 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8019 | } |
8020 | ||
c906108c | 8021 | void |
fba45db2 | 8022 | tbreak_command (char *arg, int from_tty) |
c906108c | 8023 | { |
db107f19 | 8024 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
8025 | } |
8026 | ||
c906108c | 8027 | static void |
fba45db2 | 8028 | hbreak_command (char *arg, int from_tty) |
c906108c | 8029 | { |
db107f19 | 8030 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
8031 | } |
8032 | ||
8033 | static void | |
fba45db2 | 8034 | thbreak_command (char *arg, int from_tty) |
c906108c | 8035 | { |
db107f19 | 8036 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
8037 | } |
8038 | ||
8039 | static void | |
fba45db2 | 8040 | stop_command (char *arg, int from_tty) |
c906108c | 8041 | { |
a3f17187 | 8042 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 8043 | Usage: stop in <function | address>\n\ |
a3f17187 | 8044 | stop at <line>\n")); |
c906108c SS |
8045 | } |
8046 | ||
8047 | static void | |
fba45db2 | 8048 | stopin_command (char *arg, int from_tty) |
c906108c SS |
8049 | { |
8050 | int badInput = 0; | |
8051 | ||
c5aa993b | 8052 | if (arg == (char *) NULL) |
c906108c SS |
8053 | badInput = 1; |
8054 | else if (*arg != '*') | |
8055 | { | |
8056 | char *argptr = arg; | |
8057 | int hasColon = 0; | |
8058 | ||
4a64f543 | 8059 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 8060 | say it is bad, otherwise, it should be an address or |
4a64f543 | 8061 | function/method name. */ |
c906108c | 8062 | while (*argptr && !hasColon) |
c5aa993b JM |
8063 | { |
8064 | hasColon = (*argptr == ':'); | |
8065 | argptr++; | |
8066 | } | |
c906108c SS |
8067 | |
8068 | if (hasColon) | |
c5aa993b | 8069 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 8070 | else |
c5aa993b | 8071 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
8072 | } |
8073 | ||
8074 | if (badInput) | |
a3f17187 | 8075 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 8076 | else |
db107f19 | 8077 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8078 | } |
8079 | ||
8080 | static void | |
fba45db2 | 8081 | stopat_command (char *arg, int from_tty) |
c906108c SS |
8082 | { |
8083 | int badInput = 0; | |
8084 | ||
c5aa993b | 8085 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
8086 | badInput = 1; |
8087 | else | |
8088 | { | |
8089 | char *argptr = arg; | |
8090 | int hasColon = 0; | |
8091 | ||
4a64f543 MS |
8092 | /* Look for a ':'. If there is a '::' then get out, otherwise |
8093 | it is probably a line number. */ | |
c906108c | 8094 | while (*argptr && !hasColon) |
c5aa993b JM |
8095 | { |
8096 | hasColon = (*argptr == ':'); | |
8097 | argptr++; | |
8098 | } | |
c906108c SS |
8099 | |
8100 | if (hasColon) | |
c5aa993b | 8101 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 8102 | else |
c5aa993b | 8103 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
8104 | } |
8105 | ||
8106 | if (badInput) | |
a3f17187 | 8107 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 8108 | else |
db107f19 | 8109 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8110 | } |
8111 | ||
f1310107 TJB |
8112 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
8113 | ranged breakpoints. */ | |
8114 | ||
8115 | static int | |
8116 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
8117 | struct address_space *aspace, | |
09ac7c10 TT |
8118 | CORE_ADDR bp_addr, |
8119 | const struct target_waitstatus *ws) | |
f1310107 | 8120 | { |
09ac7c10 TT |
8121 | if (ws->kind != TARGET_WAITKIND_STOPPED |
8122 | || ws->value.sig != TARGET_SIGNAL_TRAP) | |
8123 | return 0; | |
8124 | ||
f1310107 TJB |
8125 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, |
8126 | bl->length, aspace, bp_addr); | |
8127 | } | |
8128 | ||
8129 | /* Implement the "resources_needed" breakpoint_ops method for | |
8130 | ranged breakpoints. */ | |
8131 | ||
8132 | static int | |
8133 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
8134 | { | |
8135 | return target_ranged_break_num_registers (); | |
8136 | } | |
8137 | ||
8138 | /* Implement the "print_it" breakpoint_ops method for | |
8139 | ranged breakpoints. */ | |
8140 | ||
8141 | static enum print_stop_action | |
348d480f | 8142 | print_it_ranged_breakpoint (bpstat bs) |
f1310107 | 8143 | { |
348d480f | 8144 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 | 8145 | struct bp_location *bl = b->loc; |
79a45e25 | 8146 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
8147 | |
8148 | gdb_assert (b->type == bp_hardware_breakpoint); | |
8149 | ||
8150 | /* Ranged breakpoints have only one location. */ | |
8151 | gdb_assert (bl && bl->next == NULL); | |
8152 | ||
8153 | annotate_breakpoint (b->number); | |
8154 | if (b->disposition == disp_del) | |
8155 | ui_out_text (uiout, "\nTemporary ranged breakpoint "); | |
8156 | else | |
8157 | ui_out_text (uiout, "\nRanged breakpoint "); | |
8158 | if (ui_out_is_mi_like_p (uiout)) | |
8159 | { | |
8160 | ui_out_field_string (uiout, "reason", | |
8161 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
8162 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8163 | } | |
8164 | ui_out_field_int (uiout, "bkptno", b->number); | |
8165 | ui_out_text (uiout, ", "); | |
8166 | ||
8167 | return PRINT_SRC_AND_LOC; | |
8168 | } | |
8169 | ||
8170 | /* Implement the "print_one" breakpoint_ops method for | |
8171 | ranged breakpoints. */ | |
8172 | ||
8173 | static void | |
8174 | print_one_ranged_breakpoint (struct breakpoint *b, | |
8175 | struct bp_location **last_loc) | |
8176 | { | |
8177 | struct bp_location *bl = b->loc; | |
8178 | struct value_print_options opts; | |
79a45e25 | 8179 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
8180 | |
8181 | /* Ranged breakpoints have only one location. */ | |
8182 | gdb_assert (bl && bl->next == NULL); | |
8183 | ||
8184 | get_user_print_options (&opts); | |
8185 | ||
8186 | if (opts.addressprint) | |
8187 | /* We don't print the address range here, it will be printed later | |
8188 | by print_one_detail_ranged_breakpoint. */ | |
8189 | ui_out_field_skip (uiout, "addr"); | |
8190 | annotate_field (5); | |
8191 | print_breakpoint_location (b, bl); | |
8192 | *last_loc = bl; | |
8193 | } | |
8194 | ||
8195 | /* Implement the "print_one_detail" breakpoint_ops method for | |
8196 | ranged breakpoints. */ | |
8197 | ||
8198 | static void | |
8199 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
8200 | struct ui_out *uiout) | |
8201 | { | |
8202 | CORE_ADDR address_start, address_end; | |
8203 | struct bp_location *bl = b->loc; | |
8204 | struct ui_stream *stb = ui_out_stream_new (uiout); | |
8205 | struct cleanup *cleanup = make_cleanup_ui_out_stream_delete (stb); | |
8206 | ||
8207 | gdb_assert (bl); | |
8208 | ||
8209 | address_start = bl->address; | |
8210 | address_end = address_start + bl->length - 1; | |
8211 | ||
8212 | ui_out_text (uiout, "\taddress range: "); | |
8213 | fprintf_unfiltered (stb->stream, "[%s, %s]", | |
8214 | print_core_address (bl->gdbarch, address_start), | |
8215 | print_core_address (bl->gdbarch, address_end)); | |
8216 | ui_out_field_stream (uiout, "addr", stb); | |
8217 | ui_out_text (uiout, "\n"); | |
8218 | ||
8219 | do_cleanups (cleanup); | |
8220 | } | |
8221 | ||
8222 | /* Implement the "print_mention" breakpoint_ops method for | |
8223 | ranged breakpoints. */ | |
8224 | ||
8225 | static void | |
8226 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
8227 | { | |
8228 | struct bp_location *bl = b->loc; | |
79a45e25 | 8229 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
8230 | |
8231 | gdb_assert (bl); | |
8232 | gdb_assert (b->type == bp_hardware_breakpoint); | |
8233 | ||
8234 | if (ui_out_is_mi_like_p (uiout)) | |
8235 | return; | |
8236 | ||
8237 | printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."), | |
8238 | b->number, paddress (bl->gdbarch, bl->address), | |
8239 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
8240 | } | |
8241 | ||
8242 | /* Implement the "print_recreate" breakpoint_ops method for | |
8243 | ranged breakpoints. */ | |
8244 | ||
8245 | static void | |
8246 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
8247 | { | |
8248 | fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string, | |
8249 | b->addr_string_range_end); | |
d9b3f62e | 8250 | print_recreate_thread (b, fp); |
f1310107 TJB |
8251 | } |
8252 | ||
8253 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
8254 | ||
2060206e | 8255 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
8256 | |
8257 | /* Find the address where the end of the breakpoint range should be | |
8258 | placed, given the SAL of the end of the range. This is so that if | |
8259 | the user provides a line number, the end of the range is set to the | |
8260 | last instruction of the given line. */ | |
8261 | ||
8262 | static CORE_ADDR | |
8263 | find_breakpoint_range_end (struct symtab_and_line sal) | |
8264 | { | |
8265 | CORE_ADDR end; | |
8266 | ||
8267 | /* If the user provided a PC value, use it. Otherwise, | |
8268 | find the address of the end of the given location. */ | |
8269 | if (sal.explicit_pc) | |
8270 | end = sal.pc; | |
8271 | else | |
8272 | { | |
8273 | int ret; | |
8274 | CORE_ADDR start; | |
8275 | ||
8276 | ret = find_line_pc_range (sal, &start, &end); | |
8277 | if (!ret) | |
8278 | error (_("Could not find location of the end of the range.")); | |
8279 | ||
8280 | /* find_line_pc_range returns the start of the next line. */ | |
8281 | end--; | |
8282 | } | |
8283 | ||
8284 | return end; | |
8285 | } | |
8286 | ||
8287 | /* Implement the "break-range" CLI command. */ | |
8288 | ||
8289 | static void | |
8290 | break_range_command (char *arg, int from_tty) | |
8291 | { | |
8292 | char *arg_start, *addr_string_start, *addr_string_end; | |
8293 | struct linespec_result canonical_start, canonical_end; | |
8294 | int bp_count, can_use_bp, length; | |
8295 | CORE_ADDR end; | |
8296 | struct breakpoint *b; | |
8297 | struct symtab_and_line sal_start, sal_end; | |
f1310107 | 8298 | struct cleanup *cleanup_bkpt; |
f8eba3c6 | 8299 | struct linespec_sals *lsal_start, *lsal_end; |
f1310107 TJB |
8300 | |
8301 | /* We don't support software ranged breakpoints. */ | |
8302 | if (target_ranged_break_num_registers () < 0) | |
8303 | error (_("This target does not support hardware ranged breakpoints.")); | |
8304 | ||
8305 | bp_count = hw_breakpoint_used_count (); | |
8306 | bp_count += target_ranged_break_num_registers (); | |
8307 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
8308 | bp_count, 0); | |
8309 | if (can_use_bp < 0) | |
8310 | error (_("Hardware breakpoints used exceeds limit.")); | |
8311 | ||
f8eba3c6 | 8312 | arg = skip_spaces (arg); |
f1310107 TJB |
8313 | if (arg == NULL || arg[0] == '\0') |
8314 | error(_("No address range specified.")); | |
8315 | ||
f1310107 TJB |
8316 | init_linespec_result (&canonical_start); |
8317 | ||
f8eba3c6 TT |
8318 | arg_start = arg; |
8319 | parse_breakpoint_sals (&arg, &canonical_start); | |
f1310107 | 8320 | |
f8eba3c6 | 8321 | cleanup_bkpt = make_cleanup_destroy_linespec_result (&canonical_start); |
f1310107 TJB |
8322 | |
8323 | if (arg[0] != ',') | |
8324 | error (_("Too few arguments.")); | |
f8eba3c6 | 8325 | else if (VEC_empty (linespec_sals, canonical_start.sals)) |
f1310107 | 8326 | error (_("Could not find location of the beginning of the range.")); |
f8eba3c6 TT |
8327 | |
8328 | lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0); | |
8329 | ||
8330 | if (VEC_length (linespec_sals, canonical_start.sals) > 1 | |
8331 | || lsal_start->sals.nelts != 1) | |
f1310107 TJB |
8332 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
8333 | ||
f8eba3c6 TT |
8334 | sal_start = lsal_start->sals.sals[0]; |
8335 | addr_string_start = savestring (arg_start, arg - arg_start); | |
8336 | make_cleanup (xfree, addr_string_start); | |
f1310107 TJB |
8337 | |
8338 | arg++; /* Skip the comma. */ | |
f8eba3c6 | 8339 | arg = skip_spaces (arg); |
f1310107 TJB |
8340 | |
8341 | /* Parse the end location. */ | |
8342 | ||
f1310107 TJB |
8343 | init_linespec_result (&canonical_end); |
8344 | arg_start = arg; | |
8345 | ||
f8eba3c6 | 8346 | /* We call decode_line_full directly here instead of using |
f1310107 TJB |
8347 | parse_breakpoint_sals because we need to specify the start location's |
8348 | symtab and line as the default symtab and line for the end of the | |
8349 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
8350 | where +14 means 14 lines from the start location. */ | |
f8eba3c6 TT |
8351 | decode_line_full (&arg, DECODE_LINE_FUNFIRSTLINE, |
8352 | sal_start.symtab, sal_start.line, | |
8353 | &canonical_end, NULL, NULL); | |
8354 | ||
8355 | make_cleanup_destroy_linespec_result (&canonical_end); | |
f1310107 | 8356 | |
f8eba3c6 | 8357 | if (VEC_empty (linespec_sals, canonical_end.sals)) |
f1310107 | 8358 | error (_("Could not find location of the end of the range.")); |
f8eba3c6 TT |
8359 | |
8360 | lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0); | |
8361 | if (VEC_length (linespec_sals, canonical_end.sals) > 1 | |
8362 | || lsal_end->sals.nelts != 1) | |
f1310107 TJB |
8363 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
8364 | ||
f8eba3c6 TT |
8365 | sal_end = lsal_end->sals.sals[0]; |
8366 | addr_string_end = savestring (arg_start, arg - arg_start); | |
8367 | make_cleanup (xfree, addr_string_end); | |
f1310107 TJB |
8368 | |
8369 | end = find_breakpoint_range_end (sal_end); | |
8370 | if (sal_start.pc > end) | |
177b42fe | 8371 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
8372 | |
8373 | length = end - sal_start.pc + 1; | |
8374 | if (length < 0) | |
8375 | /* Length overflowed. */ | |
8376 | error (_("Address range too large.")); | |
8377 | else if (length == 1) | |
8378 | { | |
8379 | /* This range is simple enough to be handled by | |
8380 | the `hbreak' command. */ | |
8381 | hbreak_command (addr_string_start, 1); | |
8382 | ||
8383 | do_cleanups (cleanup_bkpt); | |
8384 | ||
8385 | return; | |
8386 | } | |
8387 | ||
8388 | /* Now set up the breakpoint. */ | |
8389 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 8390 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
8391 | set_breakpoint_count (breakpoint_count + 1); |
8392 | b->number = breakpoint_count; | |
8393 | b->disposition = disp_donttouch; | |
f8eba3c6 TT |
8394 | b->addr_string = xstrdup (addr_string_start); |
8395 | b->addr_string_range_end = xstrdup (addr_string_end); | |
f1310107 TJB |
8396 | b->loc->length = length; |
8397 | ||
f8eba3c6 | 8398 | do_cleanups (cleanup_bkpt); |
f1310107 TJB |
8399 | |
8400 | mention (b); | |
8d3788bd | 8401 | observer_notify_breakpoint_created (b); |
f1310107 TJB |
8402 | update_global_location_list (1); |
8403 | } | |
8404 | ||
4a64f543 MS |
8405 | /* Return non-zero if EXP is verified as constant. Returned zero |
8406 | means EXP is variable. Also the constant detection may fail for | |
8407 | some constant expressions and in such case still falsely return | |
8408 | zero. */ | |
65d79d4b SDJ |
8409 | static int |
8410 | watchpoint_exp_is_const (const struct expression *exp) | |
8411 | { | |
8412 | int i = exp->nelts; | |
8413 | ||
8414 | while (i > 0) | |
8415 | { | |
8416 | int oplenp, argsp; | |
8417 | ||
8418 | /* We are only interested in the descriptor of each element. */ | |
8419 | operator_length (exp, i, &oplenp, &argsp); | |
8420 | i -= oplenp; | |
8421 | ||
8422 | switch (exp->elts[i].opcode) | |
8423 | { | |
8424 | case BINOP_ADD: | |
8425 | case BINOP_SUB: | |
8426 | case BINOP_MUL: | |
8427 | case BINOP_DIV: | |
8428 | case BINOP_REM: | |
8429 | case BINOP_MOD: | |
8430 | case BINOP_LSH: | |
8431 | case BINOP_RSH: | |
8432 | case BINOP_LOGICAL_AND: | |
8433 | case BINOP_LOGICAL_OR: | |
8434 | case BINOP_BITWISE_AND: | |
8435 | case BINOP_BITWISE_IOR: | |
8436 | case BINOP_BITWISE_XOR: | |
8437 | case BINOP_EQUAL: | |
8438 | case BINOP_NOTEQUAL: | |
8439 | case BINOP_LESS: | |
8440 | case BINOP_GTR: | |
8441 | case BINOP_LEQ: | |
8442 | case BINOP_GEQ: | |
8443 | case BINOP_REPEAT: | |
8444 | case BINOP_COMMA: | |
8445 | case BINOP_EXP: | |
8446 | case BINOP_MIN: | |
8447 | case BINOP_MAX: | |
8448 | case BINOP_INTDIV: | |
8449 | case BINOP_CONCAT: | |
8450 | case BINOP_IN: | |
8451 | case BINOP_RANGE: | |
8452 | case TERNOP_COND: | |
8453 | case TERNOP_SLICE: | |
8454 | case TERNOP_SLICE_COUNT: | |
8455 | ||
8456 | case OP_LONG: | |
8457 | case OP_DOUBLE: | |
8458 | case OP_DECFLOAT: | |
8459 | case OP_LAST: | |
8460 | case OP_COMPLEX: | |
8461 | case OP_STRING: | |
8462 | case OP_BITSTRING: | |
8463 | case OP_ARRAY: | |
8464 | case OP_TYPE: | |
8465 | case OP_NAME: | |
8466 | case OP_OBJC_NSSTRING: | |
8467 | ||
8468 | case UNOP_NEG: | |
8469 | case UNOP_LOGICAL_NOT: | |
8470 | case UNOP_COMPLEMENT: | |
8471 | case UNOP_ADDR: | |
8472 | case UNOP_HIGH: | |
4a64f543 MS |
8473 | /* Unary, binary and ternary operators: We have to check |
8474 | their operands. If they are constant, then so is the | |
8475 | result of that operation. For instance, if A and B are | |
8476 | determined to be constants, then so is "A + B". | |
8477 | ||
8478 | UNOP_IND is one exception to the rule above, because the | |
8479 | value of *ADDR is not necessarily a constant, even when | |
8480 | ADDR is. */ | |
65d79d4b SDJ |
8481 | break; |
8482 | ||
8483 | case OP_VAR_VALUE: | |
8484 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 8485 | |
65d79d4b | 8486 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
8487 | possible that a buggy compiler could mark a variable as |
8488 | constant even when it is not, and TYPE_CONST would return | |
8489 | true in this case, while SYMBOL_CLASS wouldn't. | |
8490 | ||
8491 | We also have to check for function symbols because they | |
8492 | are always constant. */ | |
65d79d4b SDJ |
8493 | { |
8494 | struct symbol *s = exp->elts[i + 2].symbol; | |
8495 | ||
8496 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
8497 | && SYMBOL_CLASS (s) != LOC_CONST | |
8498 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
8499 | return 0; | |
8500 | break; | |
8501 | } | |
8502 | ||
8503 | /* The default action is to return 0 because we are using | |
8504 | the optimistic approach here: If we don't know something, | |
8505 | then it is not a constant. */ | |
8506 | default: | |
8507 | return 0; | |
8508 | } | |
8509 | } | |
8510 | ||
8511 | return 1; | |
8512 | } | |
8513 | ||
3a5c3e22 PA |
8514 | /* Implement the "dtor" breakpoint_ops method for watchpoints. */ |
8515 | ||
8516 | static void | |
8517 | dtor_watchpoint (struct breakpoint *self) | |
8518 | { | |
8519 | struct watchpoint *w = (struct watchpoint *) self; | |
8520 | ||
8521 | xfree (w->cond_exp); | |
8522 | xfree (w->exp); | |
8523 | xfree (w->exp_string); | |
8524 | xfree (w->exp_string_reparse); | |
8525 | value_free (w->val); | |
8526 | ||
8527 | base_breakpoint_ops.dtor (self); | |
8528 | } | |
8529 | ||
348d480f PA |
8530 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
8531 | ||
8532 | static void | |
8533 | re_set_watchpoint (struct breakpoint *b) | |
8534 | { | |
3a5c3e22 PA |
8535 | struct watchpoint *w = (struct watchpoint *) b; |
8536 | ||
348d480f PA |
8537 | /* Watchpoint can be either on expression using entirely global |
8538 | variables, or it can be on local variables. | |
8539 | ||
8540 | Watchpoints of the first kind are never auto-deleted, and even | |
8541 | persist across program restarts. Since they can use variables | |
8542 | from shared libraries, we need to reparse expression as libraries | |
8543 | are loaded and unloaded. | |
8544 | ||
8545 | Watchpoints on local variables can also change meaning as result | |
8546 | of solib event. For example, if a watchpoint uses both a local | |
8547 | and a global variables in expression, it's a local watchpoint, | |
8548 | but unloading of a shared library will make the expression | |
8549 | invalid. This is not a very common use case, but we still | |
8550 | re-evaluate expression, to avoid surprises to the user. | |
8551 | ||
8552 | Note that for local watchpoints, we re-evaluate it only if | |
8553 | watchpoints frame id is still valid. If it's not, it means the | |
8554 | watchpoint is out of scope and will be deleted soon. In fact, | |
8555 | I'm not sure we'll ever be called in this case. | |
8556 | ||
8557 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 8558 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 8559 | |
3a5c3e22 PA |
8560 | Don't do anything about disabled watchpoints, since they will be |
8561 | reevaluated again when enabled. */ | |
8562 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
8563 | } |
8564 | ||
77b06cd7 TJB |
8565 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
8566 | ||
8567 | static int | |
8568 | insert_watchpoint (struct bp_location *bl) | |
8569 | { | |
3a5c3e22 PA |
8570 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
8571 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
8572 | |
8573 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 8574 | w->cond_exp); |
77b06cd7 TJB |
8575 | } |
8576 | ||
8577 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
8578 | ||
8579 | static int | |
8580 | remove_watchpoint (struct bp_location *bl) | |
8581 | { | |
3a5c3e22 PA |
8582 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
8583 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
8584 | |
8585 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 8586 | w->cond_exp); |
e09342b5 TJB |
8587 | } |
8588 | ||
e09342b5 | 8589 | static int |
348d480f | 8590 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
09ac7c10 TT |
8591 | struct address_space *aspace, CORE_ADDR bp_addr, |
8592 | const struct target_waitstatus *ws) | |
e09342b5 | 8593 | { |
348d480f | 8594 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 8595 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 8596 | |
348d480f PA |
8597 | /* Continuable hardware watchpoints are treated as non-existent if the |
8598 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
8599 | some data address). Otherwise gdb won't stop on a break instruction | |
8600 | in the code (not from a breakpoint) when a hardware watchpoint has | |
8601 | been defined. Also skip watchpoints which we know did not trigger | |
8602 | (did not match the data address). */ | |
8603 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 8604 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 8605 | return 0; |
9c06b0b4 | 8606 | |
348d480f | 8607 | return 1; |
9c06b0b4 TJB |
8608 | } |
8609 | ||
348d480f PA |
8610 | static void |
8611 | check_status_watchpoint (bpstat bs) | |
9c06b0b4 | 8612 | { |
348d480f | 8613 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 8614 | |
348d480f | 8615 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
8616 | } |
8617 | ||
8618 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 8619 | hardware watchpoints. */ |
9c06b0b4 TJB |
8620 | |
8621 | static int | |
348d480f | 8622 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 8623 | { |
3a5c3e22 PA |
8624 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
8625 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
8626 | |
8627 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
8628 | } |
8629 | ||
8630 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 8631 | hardware watchpoints. */ |
9c06b0b4 TJB |
8632 | |
8633 | static int | |
348d480f | 8634 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 8635 | { |
efa80663 PA |
8636 | /* Read and access watchpoints only work with hardware support. */ |
8637 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
8638 | } |
8639 | ||
9c06b0b4 | 8640 | static enum print_stop_action |
348d480f | 8641 | print_it_watchpoint (bpstat bs) |
9c06b0b4 | 8642 | { |
348d480f PA |
8643 | struct cleanup *old_chain; |
8644 | struct breakpoint *b; | |
8645 | const struct bp_location *bl; | |
8646 | struct ui_stream *stb; | |
8647 | enum print_stop_action result; | |
3a5c3e22 | 8648 | struct watchpoint *w; |
79a45e25 | 8649 | struct ui_out *uiout = current_uiout; |
348d480f PA |
8650 | |
8651 | gdb_assert (bs->bp_location_at != NULL); | |
8652 | ||
8653 | bl = bs->bp_location_at; | |
8654 | b = bs->breakpoint_at; | |
3a5c3e22 | 8655 | w = (struct watchpoint *) b; |
348d480f PA |
8656 | |
8657 | stb = ui_out_stream_new (uiout); | |
8658 | old_chain = make_cleanup_ui_out_stream_delete (stb); | |
9c06b0b4 TJB |
8659 | |
8660 | switch (b->type) | |
8661 | { | |
348d480f | 8662 | case bp_watchpoint: |
9c06b0b4 TJB |
8663 | case bp_hardware_watchpoint: |
8664 | annotate_watchpoint (b->number); | |
8665 | if (ui_out_is_mi_like_p (uiout)) | |
8666 | ui_out_field_string | |
8667 | (uiout, "reason", | |
8668 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
8669 | mention (b); |
8670 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
8671 | ui_out_text (uiout, "\nOld value = "); | |
8672 | watchpoint_value_print (bs->old_val, stb->stream); | |
8673 | ui_out_field_stream (uiout, "old", stb); | |
8674 | ui_out_text (uiout, "\nNew value = "); | |
3a5c3e22 | 8675 | watchpoint_value_print (w->val, stb->stream); |
348d480f PA |
8676 | ui_out_field_stream (uiout, "new", stb); |
8677 | ui_out_text (uiout, "\n"); | |
8678 | /* More than one watchpoint may have been triggered. */ | |
8679 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
8680 | break; |
8681 | ||
8682 | case bp_read_watchpoint: | |
8683 | if (ui_out_is_mi_like_p (uiout)) | |
8684 | ui_out_field_string | |
8685 | (uiout, "reason", | |
8686 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
8687 | mention (b); |
8688 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
8689 | ui_out_text (uiout, "\nValue = "); | |
3a5c3e22 | 8690 | watchpoint_value_print (w->val, stb->stream); |
348d480f PA |
8691 | ui_out_field_stream (uiout, "value", stb); |
8692 | ui_out_text (uiout, "\n"); | |
8693 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
8694 | break; |
8695 | ||
8696 | case bp_access_watchpoint: | |
348d480f PA |
8697 | if (bs->old_val != NULL) |
8698 | { | |
8699 | annotate_watchpoint (b->number); | |
8700 | if (ui_out_is_mi_like_p (uiout)) | |
8701 | ui_out_field_string | |
8702 | (uiout, "reason", | |
8703 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
8704 | mention (b); | |
8705 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
8706 | ui_out_text (uiout, "\nOld value = "); | |
8707 | watchpoint_value_print (bs->old_val, stb->stream); | |
8708 | ui_out_field_stream (uiout, "old", stb); | |
8709 | ui_out_text (uiout, "\nNew value = "); | |
8710 | } | |
8711 | else | |
8712 | { | |
8713 | mention (b); | |
8714 | if (ui_out_is_mi_like_p (uiout)) | |
8715 | ui_out_field_string | |
8716 | (uiout, "reason", | |
8717 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
8718 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
8719 | ui_out_text (uiout, "\nValue = "); | |
8720 | } | |
3a5c3e22 | 8721 | watchpoint_value_print (w->val, stb->stream); |
348d480f PA |
8722 | ui_out_field_stream (uiout, "new", stb); |
8723 | ui_out_text (uiout, "\n"); | |
8724 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
8725 | break; |
8726 | default: | |
348d480f | 8727 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
8728 | } |
8729 | ||
348d480f PA |
8730 | do_cleanups (old_chain); |
8731 | return result; | |
8732 | } | |
8733 | ||
8734 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
8735 | watchpoints. */ | |
8736 | ||
8737 | static void | |
8738 | print_mention_watchpoint (struct breakpoint *b) | |
8739 | { | |
8740 | struct cleanup *ui_out_chain; | |
3a5c3e22 | 8741 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 8742 | struct ui_out *uiout = current_uiout; |
348d480f PA |
8743 | |
8744 | switch (b->type) | |
8745 | { | |
8746 | case bp_watchpoint: | |
8747 | ui_out_text (uiout, "Watchpoint "); | |
8748 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
8749 | break; | |
8750 | case bp_hardware_watchpoint: | |
8751 | ui_out_text (uiout, "Hardware watchpoint "); | |
8752 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
8753 | break; | |
8754 | case bp_read_watchpoint: | |
8755 | ui_out_text (uiout, "Hardware read watchpoint "); | |
8756 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
8757 | break; | |
8758 | case bp_access_watchpoint: | |
8759 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
8760 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
8761 | break; | |
8762 | default: | |
8763 | internal_error (__FILE__, __LINE__, | |
8764 | _("Invalid hardware watchpoint type.")); | |
8765 | } | |
8766 | ||
8767 | ui_out_field_int (uiout, "number", b->number); | |
8768 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 8769 | ui_out_field_string (uiout, "exp", w->exp_string); |
348d480f PA |
8770 | do_cleanups (ui_out_chain); |
8771 | } | |
8772 | ||
8773 | /* Implement the "print_recreate" breakpoint_ops method for | |
8774 | watchpoints. */ | |
8775 | ||
8776 | static void | |
8777 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
8778 | { | |
3a5c3e22 PA |
8779 | struct watchpoint *w = (struct watchpoint *) b; |
8780 | ||
348d480f PA |
8781 | switch (b->type) |
8782 | { | |
8783 | case bp_watchpoint: | |
8784 | case bp_hardware_watchpoint: | |
8785 | fprintf_unfiltered (fp, "watch"); | |
8786 | break; | |
8787 | case bp_read_watchpoint: | |
8788 | fprintf_unfiltered (fp, "rwatch"); | |
8789 | break; | |
8790 | case bp_access_watchpoint: | |
8791 | fprintf_unfiltered (fp, "awatch"); | |
8792 | break; | |
8793 | default: | |
8794 | internal_error (__FILE__, __LINE__, | |
8795 | _("Invalid watchpoint type.")); | |
8796 | } | |
8797 | ||
3a5c3e22 | 8798 | fprintf_unfiltered (fp, " %s", w->exp_string); |
d9b3f62e | 8799 | print_recreate_thread (b, fp); |
348d480f PA |
8800 | } |
8801 | ||
8802 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ | |
8803 | ||
2060206e | 8804 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
8805 | |
8806 | /* Implement the "insert" breakpoint_ops method for | |
8807 | masked hardware watchpoints. */ | |
8808 | ||
8809 | static int | |
8810 | insert_masked_watchpoint (struct bp_location *bl) | |
8811 | { | |
3a5c3e22 PA |
8812 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
8813 | ||
8814 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
8815 | bl->watchpoint_type); |
8816 | } | |
8817 | ||
8818 | /* Implement the "remove" breakpoint_ops method for | |
8819 | masked hardware watchpoints. */ | |
8820 | ||
8821 | static int | |
8822 | remove_masked_watchpoint (struct bp_location *bl) | |
8823 | { | |
3a5c3e22 PA |
8824 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
8825 | ||
8826 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
8827 | bl->watchpoint_type); |
8828 | } | |
8829 | ||
8830 | /* Implement the "resources_needed" breakpoint_ops method for | |
8831 | masked hardware watchpoints. */ | |
8832 | ||
8833 | static int | |
8834 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
8835 | { | |
3a5c3e22 PA |
8836 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
8837 | ||
8838 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
8839 | } |
8840 | ||
8841 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
8842 | masked hardware watchpoints. */ | |
8843 | ||
8844 | static int | |
8845 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
8846 | { | |
8847 | return 0; | |
8848 | } | |
8849 | ||
8850 | /* Implement the "print_it" breakpoint_ops method for | |
8851 | masked hardware watchpoints. */ | |
8852 | ||
8853 | static enum print_stop_action | |
8854 | print_it_masked_watchpoint (bpstat bs) | |
8855 | { | |
8856 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 8857 | struct ui_out *uiout = current_uiout; |
348d480f PA |
8858 | |
8859 | /* Masked watchpoints have only one location. */ | |
8860 | gdb_assert (b->loc && b->loc->next == NULL); | |
8861 | ||
8862 | switch (b->type) | |
8863 | { | |
8864 | case bp_hardware_watchpoint: | |
8865 | annotate_watchpoint (b->number); | |
8866 | if (ui_out_is_mi_like_p (uiout)) | |
8867 | ui_out_field_string | |
8868 | (uiout, "reason", | |
8869 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
8870 | break; | |
8871 | ||
8872 | case bp_read_watchpoint: | |
8873 | if (ui_out_is_mi_like_p (uiout)) | |
8874 | ui_out_field_string | |
8875 | (uiout, "reason", | |
8876 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
8877 | break; | |
8878 | ||
8879 | case bp_access_watchpoint: | |
8880 | if (ui_out_is_mi_like_p (uiout)) | |
8881 | ui_out_field_string | |
8882 | (uiout, "reason", | |
8883 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
8884 | break; | |
8885 | default: | |
8886 | internal_error (__FILE__, __LINE__, | |
8887 | _("Invalid hardware watchpoint type.")); | |
8888 | } | |
8889 | ||
8890 | mention (b); | |
9c06b0b4 TJB |
8891 | ui_out_text (uiout, _("\n\ |
8892 | Check the underlying instruction at PC for the memory\n\ | |
8893 | address and value which triggered this watchpoint.\n")); | |
8894 | ui_out_text (uiout, "\n"); | |
8895 | ||
8896 | /* More than one watchpoint may have been triggered. */ | |
8897 | return PRINT_UNKNOWN; | |
8898 | } | |
8899 | ||
8900 | /* Implement the "print_one_detail" breakpoint_ops method for | |
8901 | masked hardware watchpoints. */ | |
8902 | ||
8903 | static void | |
8904 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
8905 | struct ui_out *uiout) | |
8906 | { | |
3a5c3e22 PA |
8907 | struct watchpoint *w = (struct watchpoint *) b; |
8908 | ||
9c06b0b4 TJB |
8909 | /* Masked watchpoints have only one location. */ |
8910 | gdb_assert (b->loc && b->loc->next == NULL); | |
8911 | ||
8912 | ui_out_text (uiout, "\tmask "); | |
3a5c3e22 | 8913 | ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask); |
9c06b0b4 TJB |
8914 | ui_out_text (uiout, "\n"); |
8915 | } | |
8916 | ||
8917 | /* Implement the "print_mention" breakpoint_ops method for | |
8918 | masked hardware watchpoints. */ | |
8919 | ||
8920 | static void | |
8921 | print_mention_masked_watchpoint (struct breakpoint *b) | |
8922 | { | |
3a5c3e22 | 8923 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 8924 | struct ui_out *uiout = current_uiout; |
9c06b0b4 TJB |
8925 | struct cleanup *ui_out_chain; |
8926 | ||
8927 | switch (b->type) | |
8928 | { | |
8929 | case bp_hardware_watchpoint: | |
8930 | ui_out_text (uiout, "Masked hardware watchpoint "); | |
8931 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
8932 | break; | |
8933 | case bp_read_watchpoint: | |
8934 | ui_out_text (uiout, "Masked hardware read watchpoint "); | |
8935 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
8936 | break; | |
8937 | case bp_access_watchpoint: | |
8938 | ui_out_text (uiout, "Masked hardware access (read/write) watchpoint "); | |
8939 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
8940 | break; | |
8941 | default: | |
8942 | internal_error (__FILE__, __LINE__, | |
8943 | _("Invalid hardware watchpoint type.")); | |
8944 | } | |
8945 | ||
8946 | ui_out_field_int (uiout, "number", b->number); | |
8947 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 8948 | ui_out_field_string (uiout, "exp", w->exp_string); |
9c06b0b4 TJB |
8949 | do_cleanups (ui_out_chain); |
8950 | } | |
8951 | ||
8952 | /* Implement the "print_recreate" breakpoint_ops method for | |
8953 | masked hardware watchpoints. */ | |
8954 | ||
8955 | static void | |
8956 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
8957 | { | |
3a5c3e22 | 8958 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
8959 | char tmp[40]; |
8960 | ||
8961 | switch (b->type) | |
8962 | { | |
8963 | case bp_hardware_watchpoint: | |
8964 | fprintf_unfiltered (fp, "watch"); | |
8965 | break; | |
8966 | case bp_read_watchpoint: | |
8967 | fprintf_unfiltered (fp, "rwatch"); | |
8968 | break; | |
8969 | case bp_access_watchpoint: | |
8970 | fprintf_unfiltered (fp, "awatch"); | |
8971 | break; | |
8972 | default: | |
8973 | internal_error (__FILE__, __LINE__, | |
8974 | _("Invalid hardware watchpoint type.")); | |
8975 | } | |
8976 | ||
3a5c3e22 PA |
8977 | sprintf_vma (tmp, w->hw_wp_mask); |
8978 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); | |
d9b3f62e | 8979 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
8980 | } |
8981 | ||
8982 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
8983 | ||
2060206e | 8984 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
8985 | |
8986 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
8987 | ||
8988 | static int | |
8989 | is_masked_watchpoint (const struct breakpoint *b) | |
8990 | { | |
8991 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
8992 | } | |
8993 | ||
53a5351d JM |
8994 | /* accessflag: hw_write: watch write, |
8995 | hw_read: watch read, | |
8996 | hw_access: watch access (read or write) */ | |
c906108c | 8997 | static void |
84f4c1fe PM |
8998 | watch_command_1 (char *arg, int accessflag, int from_tty, |
8999 | int just_location, int internal) | |
c906108c | 9000 | { |
a9634178 | 9001 | volatile struct gdb_exception e; |
d983da9c | 9002 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c | 9003 | struct expression *exp; |
60e1c644 | 9004 | struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 9005 | struct value *val, *mark, *result; |
c906108c | 9006 | struct frame_info *frame; |
c906108c SS |
9007 | char *exp_start = NULL; |
9008 | char *exp_end = NULL; | |
9c06b0b4 TJB |
9009 | char *tok, *end_tok; |
9010 | int toklen = -1; | |
c906108c SS |
9011 | char *cond_start = NULL; |
9012 | char *cond_end = NULL; | |
c906108c | 9013 | enum bptype bp_type; |
37e4754d | 9014 | int thread = -1; |
0cf6dd15 | 9015 | int pc = 0; |
9c06b0b4 TJB |
9016 | /* Flag to indicate whether we are going to use masks for |
9017 | the hardware watchpoint. */ | |
9018 | int use_mask = 0; | |
9019 | CORE_ADDR mask = 0; | |
3a5c3e22 | 9020 | struct watchpoint *w; |
c906108c | 9021 | |
37e4754d LM |
9022 | /* Make sure that we actually have parameters to parse. */ |
9023 | if (arg != NULL && arg[0] != '\0') | |
9024 | { | |
9c06b0b4 | 9025 | char *value_start; |
37e4754d | 9026 | |
9c06b0b4 TJB |
9027 | /* Look for "parameter value" pairs at the end |
9028 | of the arguments string. */ | |
9029 | for (tok = arg + strlen (arg) - 1; tok > arg; tok--) | |
9030 | { | |
9031 | /* Skip whitespace at the end of the argument list. */ | |
9032 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
9033 | tok--; | |
9034 | ||
9035 | /* Find the beginning of the last token. | |
9036 | This is the value of the parameter. */ | |
9037 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
9038 | tok--; | |
9039 | value_start = tok + 1; | |
9040 | ||
9041 | /* Skip whitespace. */ | |
9042 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
9043 | tok--; | |
9044 | ||
9045 | end_tok = tok; | |
9046 | ||
9047 | /* Find the beginning of the second to last token. | |
9048 | This is the parameter itself. */ | |
9049 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
9050 | tok--; | |
9051 | tok++; | |
9052 | toklen = end_tok - tok + 1; | |
9053 | ||
9054 | if (toklen == 6 && !strncmp (tok, "thread", 6)) | |
9055 | { | |
9056 | /* At this point we've found a "thread" token, which means | |
9057 | the user is trying to set a watchpoint that triggers | |
9058 | only in a specific thread. */ | |
9059 | char *endp; | |
37e4754d | 9060 | |
9c06b0b4 TJB |
9061 | if (thread != -1) |
9062 | error(_("You can specify only one thread.")); | |
37e4754d | 9063 | |
9c06b0b4 TJB |
9064 | /* Extract the thread ID from the next token. */ |
9065 | thread = strtol (value_start, &endp, 0); | |
37e4754d | 9066 | |
9c06b0b4 TJB |
9067 | /* Check if the user provided a valid numeric value for the |
9068 | thread ID. */ | |
9069 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
9070 | error (_("Invalid thread ID specification %s."), value_start); | |
9071 | ||
9072 | /* Check if the thread actually exists. */ | |
9073 | if (!valid_thread_id (thread)) | |
9074 | error (_("Unknown thread %d."), thread); | |
9075 | } | |
9076 | else if (toklen == 4 && !strncmp (tok, "mask", 4)) | |
9077 | { | |
9078 | /* We've found a "mask" token, which means the user wants to | |
9079 | create a hardware watchpoint that is going to have the mask | |
9080 | facility. */ | |
9081 | struct value *mask_value, *mark; | |
37e4754d | 9082 | |
9c06b0b4 TJB |
9083 | if (use_mask) |
9084 | error(_("You can specify only one mask.")); | |
37e4754d | 9085 | |
9c06b0b4 | 9086 | use_mask = just_location = 1; |
37e4754d | 9087 | |
9c06b0b4 TJB |
9088 | mark = value_mark (); |
9089 | mask_value = parse_to_comma_and_eval (&value_start); | |
9090 | mask = value_as_address (mask_value); | |
9091 | value_free_to_mark (mark); | |
9092 | } | |
9093 | else | |
9094 | /* We didn't recognize what we found. We should stop here. */ | |
9095 | break; | |
37e4754d | 9096 | |
9c06b0b4 TJB |
9097 | /* Truncate the string and get rid of the "parameter value" pair before |
9098 | the arguments string is parsed by the parse_exp_1 function. */ | |
9099 | *tok = '\0'; | |
9100 | } | |
37e4754d LM |
9101 | } |
9102 | ||
9103 | /* Parse the rest of the arguments. */ | |
c906108c SS |
9104 | innermost_block = NULL; |
9105 | exp_start = arg; | |
9106 | exp = parse_exp_1 (&arg, 0, 0); | |
9107 | exp_end = arg; | |
fa8a61dc TT |
9108 | /* Remove trailing whitespace from the expression before saving it. |
9109 | This makes the eventual display of the expression string a bit | |
9110 | prettier. */ | |
9111 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
9112 | --exp_end; | |
9113 | ||
65d79d4b SDJ |
9114 | /* Checking if the expression is not constant. */ |
9115 | if (watchpoint_exp_is_const (exp)) | |
9116 | { | |
9117 | int len; | |
9118 | ||
9119 | len = exp_end - exp_start; | |
9120 | while (len > 0 && isspace (exp_start[len - 1])) | |
9121 | len--; | |
9122 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
9123 | } | |
9124 | ||
c906108c SS |
9125 | exp_valid_block = innermost_block; |
9126 | mark = value_mark (); | |
a1442452 | 9127 | fetch_subexp_value (exp, &pc, &val, &result, NULL); |
06a64a0b TT |
9128 | |
9129 | if (just_location) | |
9130 | { | |
9c06b0b4 TJB |
9131 | int ret; |
9132 | ||
06a64a0b | 9133 | exp_valid_block = NULL; |
a1442452 | 9134 | val = value_addr (result); |
06a64a0b TT |
9135 | release_value (val); |
9136 | value_free_to_mark (mark); | |
9c06b0b4 TJB |
9137 | |
9138 | if (use_mask) | |
9139 | { | |
9140 | ret = target_masked_watch_num_registers (value_as_address (val), | |
9141 | mask); | |
9142 | if (ret == -1) | |
9143 | error (_("This target does not support masked watchpoints.")); | |
9144 | else if (ret == -2) | |
9145 | error (_("Invalid mask or memory region.")); | |
9146 | } | |
06a64a0b TT |
9147 | } |
9148 | else if (val != NULL) | |
fa4727a6 | 9149 | release_value (val); |
c906108c | 9150 | |
e9cafbcc TT |
9151 | tok = skip_spaces (arg); |
9152 | end_tok = skip_to_space (tok); | |
c906108c SS |
9153 | |
9154 | toklen = end_tok - tok; | |
9155 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
9156 | { | |
2d134ed3 PA |
9157 | struct expression *cond; |
9158 | ||
60e1c644 | 9159 | innermost_block = NULL; |
c906108c SS |
9160 | tok = cond_start = end_tok + 1; |
9161 | cond = parse_exp_1 (&tok, 0, 0); | |
60e1c644 PA |
9162 | |
9163 | /* The watchpoint expression may not be local, but the condition | |
9164 | may still be. E.g.: `watch global if local > 0'. */ | |
9165 | cond_exp_valid_block = innermost_block; | |
9166 | ||
2d134ed3 | 9167 | xfree (cond); |
c906108c SS |
9168 | cond_end = tok; |
9169 | } | |
9170 | if (*tok) | |
8a3fe4f8 | 9171 | error (_("Junk at end of command.")); |
c906108c | 9172 | |
53a5351d | 9173 | if (accessflag == hw_read) |
c5aa993b | 9174 | bp_type = bp_read_watchpoint; |
53a5351d | 9175 | else if (accessflag == hw_access) |
c5aa993b JM |
9176 | bp_type = bp_access_watchpoint; |
9177 | else | |
9178 | bp_type = bp_hardware_watchpoint; | |
c906108c | 9179 | |
d983da9c | 9180 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
9181 | |
9182 | /* If the expression is "local", then set up a "watchpoint scope" | |
9183 | breakpoint at the point where we've left the scope of the watchpoint | |
9184 | expression. Create the scope breakpoint before the watchpoint, so | |
9185 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 9186 | if (exp_valid_block && frame) |
d983da9c | 9187 | { |
edb3359d DJ |
9188 | if (frame_id_p (frame_unwind_caller_id (frame))) |
9189 | { | |
9190 | scope_breakpoint | |
a6d9a66e UW |
9191 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
9192 | frame_unwind_caller_pc (frame), | |
06edf0c0 PA |
9193 | bp_watchpoint_scope, |
9194 | &momentary_breakpoint_ops); | |
d983da9c | 9195 | |
edb3359d | 9196 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 9197 | |
edb3359d DJ |
9198 | /* Automatically delete the breakpoint when it hits. */ |
9199 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 9200 | |
edb3359d DJ |
9201 | /* Only break in the proper frame (help with recursion). */ |
9202 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 9203 | |
edb3359d | 9204 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
9205 | scope_breakpoint->loc->gdbarch |
9206 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
9207 | scope_breakpoint->loc->requested_address |
9208 | = frame_unwind_caller_pc (frame); | |
9209 | scope_breakpoint->loc->address | |
a6d9a66e UW |
9210 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
9211 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
9212 | scope_breakpoint->type); |
9213 | } | |
d983da9c DJ |
9214 | } |
9215 | ||
c906108c | 9216 | /* Now set up the breakpoint. */ |
3a5c3e22 PA |
9217 | |
9218 | w = XCNEW (struct watchpoint); | |
9219 | b = &w->base; | |
348d480f | 9220 | if (use_mask) |
3a5c3e22 PA |
9221 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
9222 | &masked_watchpoint_breakpoint_ops); | |
348d480f | 9223 | else |
3a5c3e22 PA |
9224 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
9225 | &watchpoint_breakpoint_ops); | |
37e4754d | 9226 | b->thread = thread; |
b5de0fa7 | 9227 | b->disposition = disp_donttouch; |
348d480f | 9228 | b->pspace = current_program_space; |
3a5c3e22 PA |
9229 | w->exp = exp; |
9230 | w->exp_valid_block = exp_valid_block; | |
9231 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
9232 | if (just_location) |
9233 | { | |
9234 | struct type *t = value_type (val); | |
9235 | CORE_ADDR addr = value_as_address (val); | |
9236 | char *name; | |
9237 | ||
9238 | t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); | |
9239 | name = type_to_string (t); | |
9240 | ||
3a5c3e22 | 9241 | w->exp_string_reparse = xstrprintf ("* (%s *) %s", name, |
d63d0675 | 9242 | core_addr_to_string (addr)); |
06a64a0b TT |
9243 | xfree (name); |
9244 | ||
3a5c3e22 | 9245 | w->exp_string = xstrprintf ("-location %.*s", |
d63d0675 JK |
9246 | (int) (exp_end - exp_start), exp_start); |
9247 | ||
06a64a0b TT |
9248 | /* The above expression is in C. */ |
9249 | b->language = language_c; | |
9250 | } | |
9251 | else | |
3a5c3e22 | 9252 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
9c06b0b4 TJB |
9253 | |
9254 | if (use_mask) | |
9255 | { | |
3a5c3e22 | 9256 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
9257 | } |
9258 | else | |
9259 | { | |
3a5c3e22 PA |
9260 | w->val = val; |
9261 | w->val_valid = 1; | |
9c06b0b4 | 9262 | } |
77b06cd7 | 9263 | |
c906108c SS |
9264 | if (cond_start) |
9265 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
9266 | else | |
9267 | b->cond_string = 0; | |
c5aa993b | 9268 | |
c906108c | 9269 | if (frame) |
f6bc2008 | 9270 | { |
3a5c3e22 PA |
9271 | w->watchpoint_frame = get_frame_id (frame); |
9272 | w->watchpoint_thread = inferior_ptid; | |
f6bc2008 | 9273 | } |
c906108c | 9274 | else |
f6bc2008 | 9275 | { |
3a5c3e22 PA |
9276 | w->watchpoint_frame = null_frame_id; |
9277 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 9278 | } |
c906108c | 9279 | |
d983da9c | 9280 | if (scope_breakpoint != NULL) |
c906108c | 9281 | { |
d983da9c DJ |
9282 | /* The scope breakpoint is related to the watchpoint. We will |
9283 | need to act on them together. */ | |
9284 | b->related_breakpoint = scope_breakpoint; | |
9285 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 9286 | } |
d983da9c | 9287 | |
06a64a0b TT |
9288 | if (!just_location) |
9289 | value_free_to_mark (mark); | |
2d134ed3 | 9290 | |
a9634178 TJB |
9291 | TRY_CATCH (e, RETURN_MASK_ALL) |
9292 | { | |
9293 | /* Finally update the new watchpoint. This creates the locations | |
9294 | that should be inserted. */ | |
3a5c3e22 | 9295 | update_watchpoint (w, 1); |
a9634178 TJB |
9296 | } |
9297 | if (e.reason < 0) | |
9298 | { | |
9299 | delete_breakpoint (b); | |
9300 | throw_exception (e); | |
9301 | } | |
9302 | ||
3ea46bff | 9303 | install_breakpoint (internal, b, 1); |
c906108c SS |
9304 | } |
9305 | ||
e09342b5 | 9306 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 9307 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 9308 | |
c906108c | 9309 | static int |
a9634178 | 9310 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
9311 | { |
9312 | int found_memory_cnt = 0; | |
2e70b7b9 | 9313 | struct value *head = v; |
c906108c SS |
9314 | |
9315 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 9316 | if (!can_use_hw_watchpoints) |
c906108c | 9317 | return 0; |
c5aa993b | 9318 | |
5c44784c JM |
9319 | /* Make sure that the value of the expression depends only upon |
9320 | memory contents, and values computed from them within GDB. If we | |
9321 | find any register references or function calls, we can't use a | |
9322 | hardware watchpoint. | |
9323 | ||
9324 | The idea here is that evaluating an expression generates a series | |
9325 | of values, one holding the value of every subexpression. (The | |
9326 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
9327 | a*b+c.) GDB's values hold almost enough information to establish | |
9328 | the criteria given above --- they identify memory lvalues, | |
9329 | register lvalues, computed values, etcetera. So we can evaluate | |
9330 | the expression, and then scan the chain of values that leaves | |
9331 | behind to decide whether we can detect any possible change to the | |
9332 | expression's final value using only hardware watchpoints. | |
9333 | ||
9334 | However, I don't think that the values returned by inferior | |
9335 | function calls are special in any way. So this function may not | |
9336 | notice that an expression involving an inferior function call | |
9337 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 9338 | for (; v; v = value_next (v)) |
c906108c | 9339 | { |
5c44784c | 9340 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 9341 | { |
8464be76 DJ |
9342 | if (v != head && value_lazy (v)) |
9343 | /* A lazy memory lvalue in the chain is one that GDB never | |
9344 | needed to fetch; we either just used its address (e.g., | |
9345 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
9346 | in `a,b'). This doesn't apply to HEAD; if that is | |
9347 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 9348 | ; |
53a5351d | 9349 | else |
5c44784c JM |
9350 | { |
9351 | /* Ahh, memory we actually used! Check if we can cover | |
9352 | it with hardware watchpoints. */ | |
df407dfe | 9353 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
9354 | |
9355 | /* We only watch structs and arrays if user asked for it | |
9356 | explicitly, never if they just happen to appear in a | |
9357 | middle of some value chain. */ | |
9358 | if (v == head | |
9359 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
9360 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
9361 | { | |
42ae5230 | 9362 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
9363 | int len; |
9364 | int num_regs; | |
9365 | ||
a9634178 | 9366 | len = (target_exact_watchpoints |
e09342b5 TJB |
9367 | && is_scalar_type_recursive (vtype))? |
9368 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 9369 | |
e09342b5 TJB |
9370 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
9371 | if (!num_regs) | |
2e70b7b9 MS |
9372 | return 0; |
9373 | else | |
e09342b5 | 9374 | found_memory_cnt += num_regs; |
2e70b7b9 | 9375 | } |
5c44784c | 9376 | } |
c5aa993b | 9377 | } |
5086187c AC |
9378 | else if (VALUE_LVAL (v) != not_lval |
9379 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 9380 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 9381 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 9382 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
9383 | } |
9384 | ||
9385 | /* The expression itself looks suitable for using a hardware | |
9386 | watchpoint, but give the target machine a chance to reject it. */ | |
9387 | return found_memory_cnt; | |
9388 | } | |
9389 | ||
8b93c638 | 9390 | void |
84f4c1fe | 9391 | watch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 9392 | { |
84f4c1fe | 9393 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
9394 | } |
9395 | ||
9396 | /* A helper function that looks for an argument at the start of a | |
9397 | string. The argument must also either be at the end of the string, | |
9398 | or be followed by whitespace. Returns 1 if it finds the argument, | |
9399 | 0 otherwise. If the argument is found, it updates *STR. */ | |
9400 | ||
9401 | static int | |
9402 | check_for_argument (char **str, char *arg, int arg_len) | |
9403 | { | |
9404 | if (strncmp (*str, arg, arg_len) == 0 | |
9405 | && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len]))) | |
9406 | { | |
9407 | *str += arg_len; | |
9408 | return 1; | |
9409 | } | |
9410 | return 0; | |
9411 | } | |
9412 | ||
9413 | /* A helper function that looks for the "-location" argument and then | |
9414 | calls watch_command_1. */ | |
9415 | ||
9416 | static void | |
9417 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
9418 | { | |
9419 | int just_location = 0; | |
9420 | ||
9421 | if (arg | |
9422 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
9423 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
9424 | { | |
e9cafbcc | 9425 | arg = skip_spaces (arg); |
06a64a0b TT |
9426 | just_location = 1; |
9427 | } | |
9428 | ||
84f4c1fe | 9429 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 9430 | } |
8926118c | 9431 | |
c5aa993b | 9432 | static void |
fba45db2 | 9433 | watch_command (char *arg, int from_tty) |
c906108c | 9434 | { |
06a64a0b | 9435 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
9436 | } |
9437 | ||
8b93c638 | 9438 | void |
84f4c1fe | 9439 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 9440 | { |
84f4c1fe | 9441 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 9442 | } |
8926118c | 9443 | |
c5aa993b | 9444 | static void |
fba45db2 | 9445 | rwatch_command (char *arg, int from_tty) |
c906108c | 9446 | { |
06a64a0b | 9447 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
9448 | } |
9449 | ||
8b93c638 | 9450 | void |
84f4c1fe | 9451 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 9452 | { |
84f4c1fe | 9453 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 9454 | } |
8926118c | 9455 | |
c5aa993b | 9456 | static void |
fba45db2 | 9457 | awatch_command (char *arg, int from_tty) |
c906108c | 9458 | { |
06a64a0b | 9459 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 9460 | } |
c906108c | 9461 | \f |
c5aa993b | 9462 | |
43ff13b4 | 9463 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
9464 | because it uses the mechanisms of breakpoints. */ |
9465 | ||
bfec99b2 PA |
9466 | struct until_break_command_continuation_args |
9467 | { | |
9468 | struct breakpoint *breakpoint; | |
9469 | struct breakpoint *breakpoint2; | |
186c406b | 9470 | int thread_num; |
bfec99b2 PA |
9471 | }; |
9472 | ||
43ff13b4 | 9473 | /* This function is called by fetch_inferior_event via the |
4a64f543 | 9474 | cmd_continuation pointer, to complete the until command. It takes |
43ff13b4 | 9475 | care of cleaning up the temporary breakpoints set up by the until |
4a64f543 | 9476 | command. */ |
c2c6d25f | 9477 | static void |
fa4cd53f | 9478 | until_break_command_continuation (void *arg, int err) |
43ff13b4 | 9479 | { |
bfec99b2 PA |
9480 | struct until_break_command_continuation_args *a = arg; |
9481 | ||
9482 | delete_breakpoint (a->breakpoint); | |
9483 | if (a->breakpoint2) | |
9484 | delete_breakpoint (a->breakpoint2); | |
186c406b | 9485 | delete_longjmp_breakpoint (a->thread_num); |
43ff13b4 JM |
9486 | } |
9487 | ||
c906108c | 9488 | void |
ae66c1fc | 9489 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
9490 | { |
9491 | struct symtabs_and_lines sals; | |
9492 | struct symtab_and_line sal; | |
206415a3 | 9493 | struct frame_info *frame = get_selected_frame (NULL); |
c906108c | 9494 | struct breakpoint *breakpoint; |
f107f563 | 9495 | struct breakpoint *breakpoint2 = NULL; |
c906108c | 9496 | struct cleanup *old_chain; |
186c406b TT |
9497 | int thread; |
9498 | struct thread_info *tp; | |
c906108c SS |
9499 | |
9500 | clear_proceed_status (); | |
9501 | ||
9502 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 9503 | this function. */ |
c5aa993b | 9504 | |
1bfeeb0f | 9505 | if (last_displayed_sal_is_valid ()) |
f8eba3c6 | 9506 | sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE, |
1bfeeb0f | 9507 | get_last_displayed_symtab (), |
f8eba3c6 | 9508 | get_last_displayed_line ()); |
c906108c | 9509 | else |
f8eba3c6 TT |
9510 | sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE, |
9511 | (struct symtab *) NULL, 0); | |
c5aa993b | 9512 | |
c906108c | 9513 | if (sals.nelts != 1) |
8a3fe4f8 | 9514 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 9515 | |
c906108c | 9516 | sal = sals.sals[0]; |
4a64f543 | 9517 | xfree (sals.sals); /* malloc'd, so freed. */ |
c5aa993b | 9518 | |
c906108c | 9519 | if (*arg) |
8a3fe4f8 | 9520 | error (_("Junk at end of arguments.")); |
c5aa993b | 9521 | |
c906108c | 9522 | resolve_sal_pc (&sal); |
c5aa993b | 9523 | |
ae66c1fc EZ |
9524 | if (anywhere) |
9525 | /* If the user told us to continue until a specified location, | |
9526 | we don't specify a frame at which we need to stop. */ | |
a6d9a66e UW |
9527 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
9528 | null_frame_id, bp_until); | |
ae66c1fc | 9529 | else |
4a64f543 MS |
9530 | /* Otherwise, specify the selected frame, because we want to stop |
9531 | only at the very same frame. */ | |
a6d9a66e UW |
9532 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
9533 | get_stack_frame_id (frame), | |
ae66c1fc | 9534 | bp_until); |
c5aa993b | 9535 | |
f107f563 | 9536 | old_chain = make_cleanup_delete_breakpoint (breakpoint); |
c906108c | 9537 | |
186c406b TT |
9538 | tp = inferior_thread (); |
9539 | thread = tp->num; | |
9540 | ||
ae66c1fc EZ |
9541 | /* Keep within the current frame, or in frames called by the current |
9542 | one. */ | |
edb3359d DJ |
9543 | |
9544 | if (frame_id_p (frame_unwind_caller_id (frame))) | |
c906108c | 9545 | { |
edb3359d DJ |
9546 | sal = find_pc_line (frame_unwind_caller_pc (frame), 0); |
9547 | sal.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e UW |
9548 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
9549 | sal, | |
edb3359d | 9550 | frame_unwind_caller_id (frame), |
f107f563 VP |
9551 | bp_until); |
9552 | make_cleanup_delete_breakpoint (breakpoint2); | |
186c406b TT |
9553 | |
9554 | set_longjmp_breakpoint (tp, frame_unwind_caller_id (frame)); | |
9555 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); | |
c906108c | 9556 | } |
c5aa993b | 9557 | |
c906108c | 9558 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
f107f563 | 9559 | |
4a64f543 MS |
9560 | /* If we are running asynchronously, and proceed call above has |
9561 | actually managed to start the target, arrange for breakpoints to | |
9562 | be deleted when the target stops. Otherwise, we're already | |
9563 | stopped and delete breakpoints via cleanup chain. */ | |
f107f563 | 9564 | |
8ea051c5 | 9565 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 9566 | { |
bfec99b2 PA |
9567 | struct until_break_command_continuation_args *args; |
9568 | args = xmalloc (sizeof (*args)); | |
f107f563 | 9569 | |
bfec99b2 PA |
9570 | args->breakpoint = breakpoint; |
9571 | args->breakpoint2 = breakpoint2; | |
186c406b | 9572 | args->thread_num = thread; |
f107f563 VP |
9573 | |
9574 | discard_cleanups (old_chain); | |
95e54da7 PA |
9575 | add_continuation (inferior_thread (), |
9576 | until_break_command_continuation, args, | |
604ead4a | 9577 | xfree); |
f107f563 VP |
9578 | } |
9579 | else | |
c5aa993b | 9580 | do_cleanups (old_chain); |
c906108c | 9581 | } |
ae66c1fc | 9582 | |
c906108c SS |
9583 | /* This function attempts to parse an optional "if <cond>" clause |
9584 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 9585 | |
c906108c SS |
9586 | Else, it returns a pointer to the condition string. (It does not |
9587 | attempt to evaluate the string against a particular block.) And, | |
9588 | it updates arg to point to the first character following the parsed | |
4a64f543 | 9589 | if clause in the arg string. */ |
53a5351d | 9590 | |
c906108c | 9591 | static char * |
fba45db2 | 9592 | ep_parse_optional_if_clause (char **arg) |
c906108c | 9593 | { |
c5aa993b JM |
9594 | char *cond_string; |
9595 | ||
9596 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 9597 | return NULL; |
c5aa993b | 9598 | |
4a64f543 | 9599 | /* Skip the "if" keyword. */ |
c906108c | 9600 | (*arg) += 2; |
c5aa993b | 9601 | |
c906108c | 9602 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 9603 | condition string. */ |
e9cafbcc | 9604 | *arg = skip_spaces (*arg); |
c906108c | 9605 | cond_string = *arg; |
c5aa993b | 9606 | |
4a64f543 MS |
9607 | /* Assume that the condition occupies the remainder of the arg |
9608 | string. */ | |
c906108c | 9609 | (*arg) += strlen (cond_string); |
c5aa993b | 9610 | |
c906108c SS |
9611 | return cond_string; |
9612 | } | |
c5aa993b | 9613 | |
c906108c SS |
9614 | /* Commands to deal with catching events, such as signals, exceptions, |
9615 | process start/exit, etc. */ | |
c5aa993b JM |
9616 | |
9617 | typedef enum | |
9618 | { | |
44feb3ce TT |
9619 | catch_fork_temporary, catch_vfork_temporary, |
9620 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
9621 | } |
9622 | catch_fork_kind; | |
9623 | ||
c906108c | 9624 | static void |
cc59ec59 MS |
9625 | catch_fork_command_1 (char *arg, int from_tty, |
9626 | struct cmd_list_element *command) | |
c906108c | 9627 | { |
a6d9a66e | 9628 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 9629 | char *cond_string = NULL; |
44feb3ce TT |
9630 | catch_fork_kind fork_kind; |
9631 | int tempflag; | |
9632 | ||
9633 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
9634 | tempflag = (fork_kind == catch_fork_temporary | |
9635 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 9636 | |
44feb3ce TT |
9637 | if (!arg) |
9638 | arg = ""; | |
e9cafbcc | 9639 | arg = skip_spaces (arg); |
c5aa993b | 9640 | |
c906108c | 9641 | /* The allowed syntax is: |
c5aa993b JM |
9642 | catch [v]fork |
9643 | catch [v]fork if <cond> | |
9644 | ||
4a64f543 | 9645 | First, check if there's an if clause. */ |
c906108c | 9646 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 9647 | |
c906108c | 9648 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 9649 | error (_("Junk at end of arguments.")); |
c5aa993b | 9650 | |
c906108c | 9651 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 9652 | and enable reporting of such events. */ |
c5aa993b JM |
9653 | switch (fork_kind) |
9654 | { | |
44feb3ce TT |
9655 | case catch_fork_temporary: |
9656 | case catch_fork_permanent: | |
a6d9a66e | 9657 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 9658 | &catch_fork_breakpoint_ops); |
c906108c | 9659 | break; |
44feb3ce TT |
9660 | case catch_vfork_temporary: |
9661 | case catch_vfork_permanent: | |
a6d9a66e | 9662 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 9663 | &catch_vfork_breakpoint_ops); |
c906108c | 9664 | break; |
c5aa993b | 9665 | default: |
8a3fe4f8 | 9666 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 9667 | break; |
c5aa993b | 9668 | } |
c906108c SS |
9669 | } |
9670 | ||
9671 | static void | |
cc59ec59 MS |
9672 | catch_exec_command_1 (char *arg, int from_tty, |
9673 | struct cmd_list_element *command) | |
c906108c | 9674 | { |
b4d90040 | 9675 | struct exec_catchpoint *c; |
a6d9a66e | 9676 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 9677 | int tempflag; |
c5aa993b | 9678 | char *cond_string = NULL; |
c906108c | 9679 | |
44feb3ce TT |
9680 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
9681 | ||
9682 | if (!arg) | |
9683 | arg = ""; | |
e9cafbcc | 9684 | arg = skip_spaces (arg); |
c906108c SS |
9685 | |
9686 | /* The allowed syntax is: | |
c5aa993b JM |
9687 | catch exec |
9688 | catch exec if <cond> | |
c906108c | 9689 | |
4a64f543 | 9690 | First, check if there's an if clause. */ |
c906108c SS |
9691 | cond_string = ep_parse_optional_if_clause (&arg); |
9692 | ||
9693 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 9694 | error (_("Junk at end of arguments.")); |
c906108c | 9695 | |
b4d90040 PA |
9696 | c = XNEW (struct exec_catchpoint); |
9697 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, | |
9698 | &catch_exec_breakpoint_ops); | |
9699 | c->exec_pathname = NULL; | |
9700 | ||
3ea46bff | 9701 | install_breakpoint (0, &c->base, 1); |
c906108c | 9702 | } |
c5aa993b | 9703 | |
3086aeae | 9704 | static enum print_stop_action |
348d480f | 9705 | print_it_exception_catchpoint (bpstat bs) |
3086aeae | 9706 | { |
79a45e25 | 9707 | struct ui_out *uiout = current_uiout; |
348d480f | 9708 | struct breakpoint *b = bs->breakpoint_at; |
ade92717 | 9709 | int bp_temp, bp_throw; |
3086aeae | 9710 | |
ade92717 | 9711 | annotate_catchpoint (b->number); |
3086aeae | 9712 | |
ade92717 AR |
9713 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
9714 | if (b->loc->address != b->loc->requested_address) | |
9715 | breakpoint_adjustment_warning (b->loc->requested_address, | |
9716 | b->loc->address, | |
9717 | b->number, 1); | |
df2b6d2d | 9718 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
9719 | ui_out_text (uiout, |
9720 | bp_temp ? "Temporary catchpoint " | |
9721 | : "Catchpoint "); | |
9722 | if (!ui_out_is_mi_like_p (uiout)) | |
9723 | ui_out_field_int (uiout, "bkptno", b->number); | |
9724 | ui_out_text (uiout, | |
c0b37c48 AR |
9725 | bp_throw ? " (exception thrown), " |
9726 | : " (exception caught), "); | |
ade92717 AR |
9727 | if (ui_out_is_mi_like_p (uiout)) |
9728 | { | |
9729 | ui_out_field_string (uiout, "reason", | |
9730 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
9731 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
9732 | ui_out_field_int (uiout, "bkptno", b->number); | |
9733 | } | |
3086aeae DJ |
9734 | return PRINT_SRC_AND_LOC; |
9735 | } | |
9736 | ||
9737 | static void | |
cc59ec59 MS |
9738 | print_one_exception_catchpoint (struct breakpoint *b, |
9739 | struct bp_location **last_loc) | |
3086aeae | 9740 | { |
79a45b7d | 9741 | struct value_print_options opts; |
79a45e25 | 9742 | struct ui_out *uiout = current_uiout; |
cc59ec59 | 9743 | |
79a45b7d TT |
9744 | get_user_print_options (&opts); |
9745 | if (opts.addressprint) | |
3086aeae DJ |
9746 | { |
9747 | annotate_field (4); | |
604133b5 AR |
9748 | if (b->loc == NULL || b->loc->shlib_disabled) |
9749 | ui_out_field_string (uiout, "addr", "<PENDING>"); | |
9750 | else | |
5af949e3 UW |
9751 | ui_out_field_core_addr (uiout, "addr", |
9752 | b->loc->gdbarch, b->loc->address); | |
3086aeae DJ |
9753 | } |
9754 | annotate_field (5); | |
604133b5 | 9755 | if (b->loc) |
a6d9a66e | 9756 | *last_loc = b->loc; |
3086aeae DJ |
9757 | if (strstr (b->addr_string, "throw") != NULL) |
9758 | ui_out_field_string (uiout, "what", "exception throw"); | |
9759 | else | |
9760 | ui_out_field_string (uiout, "what", "exception catch"); | |
9761 | } | |
9762 | ||
9763 | static void | |
9764 | print_mention_exception_catchpoint (struct breakpoint *b) | |
9765 | { | |
79a45e25 | 9766 | struct ui_out *uiout = current_uiout; |
ade92717 AR |
9767 | int bp_temp; |
9768 | int bp_throw; | |
9769 | ||
df2b6d2d | 9770 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
9771 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
9772 | ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ") | |
9773 | : _("Catchpoint ")); | |
9774 | ui_out_field_int (uiout, "bkptno", b->number); | |
9775 | ui_out_text (uiout, bp_throw ? _(" (throw)") | |
9776 | : _(" (catch)")); | |
3086aeae DJ |
9777 | } |
9778 | ||
6149aea9 PA |
9779 | /* Implement the "print_recreate" breakpoint_ops method for throw and |
9780 | catch catchpoints. */ | |
9781 | ||
9782 | static void | |
4a64f543 MS |
9783 | print_recreate_exception_catchpoint (struct breakpoint *b, |
9784 | struct ui_file *fp) | |
6149aea9 PA |
9785 | { |
9786 | int bp_temp; | |
9787 | int bp_throw; | |
9788 | ||
9789 | bp_temp = b->disposition == disp_del; | |
9790 | bp_throw = strstr (b->addr_string, "throw") != NULL; | |
9791 | fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch "); | |
9792 | fprintf_unfiltered (fp, bp_throw ? "throw" : "catch"); | |
d9b3f62e | 9793 | print_recreate_thread (b, fp); |
6149aea9 PA |
9794 | } |
9795 | ||
2060206e | 9796 | static struct breakpoint_ops gnu_v3_exception_catchpoint_ops; |
3086aeae DJ |
9797 | |
9798 | static int | |
9799 | handle_gnu_v3_exceptions (int tempflag, char *cond_string, | |
9800 | enum exception_event_kind ex_event, int from_tty) | |
9801 | { | |
604133b5 AR |
9802 | char *trigger_func_name; |
9803 | ||
3086aeae | 9804 | if (ex_event == EX_EVENT_CATCH) |
604133b5 | 9805 | trigger_func_name = "__cxa_begin_catch"; |
3086aeae | 9806 | else |
604133b5 | 9807 | trigger_func_name = "__cxa_throw"; |
3086aeae | 9808 | |
8cdf0e15 VP |
9809 | create_breakpoint (get_current_arch (), |
9810 | trigger_func_name, cond_string, -1, | |
9811 | 0 /* condition and thread are valid. */, | |
0fb4aa4b | 9812 | tempflag, bp_breakpoint, |
8cdf0e15 VP |
9813 | 0, |
9814 | AUTO_BOOLEAN_TRUE /* pending */, | |
9815 | &gnu_v3_exception_catchpoint_ops, from_tty, | |
84f4c1fe PM |
9816 | 1 /* enabled */, |
9817 | 0 /* internal */); | |
3086aeae | 9818 | |
3086aeae DJ |
9819 | return 1; |
9820 | } | |
9821 | ||
4a64f543 | 9822 | /* Deal with "catch catch" and "catch throw" commands. */ |
c906108c SS |
9823 | |
9824 | static void | |
fba45db2 KB |
9825 | catch_exception_command_1 (enum exception_event_kind ex_event, char *arg, |
9826 | int tempflag, int from_tty) | |
c906108c | 9827 | { |
c5aa993b | 9828 | char *cond_string = NULL; |
c5aa993b | 9829 | |
44feb3ce TT |
9830 | if (!arg) |
9831 | arg = ""; | |
e9cafbcc | 9832 | arg = skip_spaces (arg); |
c5aa993b | 9833 | |
c906108c SS |
9834 | cond_string = ep_parse_optional_if_clause (&arg); |
9835 | ||
9836 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 9837 | error (_("Junk at end of arguments.")); |
c906108c | 9838 | |
059fb39f PM |
9839 | if (ex_event != EX_EVENT_THROW |
9840 | && ex_event != EX_EVENT_CATCH) | |
8a3fe4f8 | 9841 | error (_("Unsupported or unknown exception event; cannot catch it")); |
c906108c | 9842 | |
3086aeae DJ |
9843 | if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty)) |
9844 | return; | |
9845 | ||
8a3fe4f8 | 9846 | warning (_("Unsupported with this platform/compiler combination.")); |
c906108c SS |
9847 | } |
9848 | ||
44feb3ce TT |
9849 | /* Implementation of "catch catch" command. */ |
9850 | ||
9851 | static void | |
9852 | catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command) | |
9853 | { | |
9854 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
cc59ec59 | 9855 | |
44feb3ce TT |
9856 | catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty); |
9857 | } | |
9858 | ||
9859 | /* Implementation of "catch throw" command. */ | |
9860 | ||
9861 | static void | |
9862 | catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command) | |
9863 | { | |
9864 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
cc59ec59 | 9865 | |
44feb3ce TT |
9866 | catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty); |
9867 | } | |
9868 | ||
9ac4176b | 9869 | void |
28010a5d PA |
9870 | init_ada_exception_breakpoint (struct breakpoint *b, |
9871 | struct gdbarch *gdbarch, | |
9872 | struct symtab_and_line sal, | |
9873 | char *addr_string, | |
c0a91b2b | 9874 | const struct breakpoint_ops *ops, |
28010a5d PA |
9875 | int tempflag, |
9876 | int from_tty) | |
f7f9143b | 9877 | { |
f7f9143b JB |
9878 | if (from_tty) |
9879 | { | |
5af949e3 UW |
9880 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
9881 | if (!loc_gdbarch) | |
9882 | loc_gdbarch = gdbarch; | |
9883 | ||
6c95b8df PA |
9884 | describe_other_breakpoints (loc_gdbarch, |
9885 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
9886 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
9887 | version for exception catchpoints, because two catchpoints | |
9888 | used for different exception names will use the same address. | |
9889 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 9890 | unproductive. Besides, the warning phrasing is also a bit |
e5dd4106 | 9891 | inappropriate, we should use the word catchpoint, and tell |
f7f9143b JB |
9892 | the user what type of catchpoint it is. The above is good |
9893 | enough for now, though. */ | |
9894 | } | |
9895 | ||
28010a5d | 9896 | init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops); |
f7f9143b JB |
9897 | |
9898 | b->enable_state = bp_enabled; | |
9899 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
f7f9143b JB |
9900 | b->addr_string = addr_string; |
9901 | b->language = language_ada; | |
f7f9143b JB |
9902 | } |
9903 | ||
a96d9b2e SDJ |
9904 | /* Splits the argument using space as delimiter. Returns an xmalloc'd |
9905 | filter list, or NULL if no filtering is required. */ | |
9906 | static VEC(int) * | |
9907 | catch_syscall_split_args (char *arg) | |
9908 | { | |
9909 | VEC(int) *result = NULL; | |
29d0bb3d | 9910 | struct cleanup *cleanup = make_cleanup (VEC_cleanup (int), &result); |
a96d9b2e SDJ |
9911 | |
9912 | while (*arg != '\0') | |
9913 | { | |
9914 | int i, syscall_number; | |
9915 | char *endptr; | |
9916 | char cur_name[128]; | |
9917 | struct syscall s; | |
9918 | ||
9919 | /* Skip whitespace. */ | |
9920 | while (isspace (*arg)) | |
9921 | arg++; | |
9922 | ||
9923 | for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) | |
9924 | cur_name[i] = arg[i]; | |
9925 | cur_name[i] = '\0'; | |
9926 | arg += i; | |
9927 | ||
9928 | /* Check if the user provided a syscall name or a number. */ | |
9929 | syscall_number = (int) strtol (cur_name, &endptr, 0); | |
9930 | if (*endptr == '\0') | |
bccd0dd2 | 9931 | get_syscall_by_number (syscall_number, &s); |
a96d9b2e SDJ |
9932 | else |
9933 | { | |
9934 | /* We have a name. Let's check if it's valid and convert it | |
9935 | to a number. */ | |
9936 | get_syscall_by_name (cur_name, &s); | |
9937 | ||
9938 | if (s.number == UNKNOWN_SYSCALL) | |
4a64f543 MS |
9939 | /* Here we have to issue an error instead of a warning, |
9940 | because GDB cannot do anything useful if there's no | |
9941 | syscall number to be caught. */ | |
a96d9b2e SDJ |
9942 | error (_("Unknown syscall name '%s'."), cur_name); |
9943 | } | |
9944 | ||
9945 | /* Ok, it's valid. */ | |
9946 | VEC_safe_push (int, result, s.number); | |
9947 | } | |
9948 | ||
9949 | discard_cleanups (cleanup); | |
9950 | return result; | |
9951 | } | |
9952 | ||
9953 | /* Implement the "catch syscall" command. */ | |
9954 | ||
9955 | static void | |
cc59ec59 MS |
9956 | catch_syscall_command_1 (char *arg, int from_tty, |
9957 | struct cmd_list_element *command) | |
a96d9b2e SDJ |
9958 | { |
9959 | int tempflag; | |
9960 | VEC(int) *filter; | |
9961 | struct syscall s; | |
9962 | struct gdbarch *gdbarch = get_current_arch (); | |
9963 | ||
9964 | /* Checking if the feature if supported. */ | |
9965 | if (gdbarch_get_syscall_number_p (gdbarch) == 0) | |
9966 | error (_("The feature 'catch syscall' is not supported on \ | |
ea666128 | 9967 | this architecture yet.")); |
a96d9b2e SDJ |
9968 | |
9969 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
9970 | ||
e9cafbcc | 9971 | arg = skip_spaces (arg); |
a96d9b2e SDJ |
9972 | |
9973 | /* We need to do this first "dummy" translation in order | |
9974 | to get the syscall XML file loaded or, most important, | |
9975 | to display a warning to the user if there's no XML file | |
9976 | for his/her architecture. */ | |
9977 | get_syscall_by_number (0, &s); | |
9978 | ||
9979 | /* The allowed syntax is: | |
9980 | catch syscall | |
9981 | catch syscall <name | number> [<name | number> ... <name | number>] | |
9982 | ||
9983 | Let's check if there's a syscall name. */ | |
9984 | ||
9985 | if (arg != NULL) | |
9986 | filter = catch_syscall_split_args (arg); | |
9987 | else | |
9988 | filter = NULL; | |
9989 | ||
9990 | create_syscall_event_catchpoint (tempflag, filter, | |
9991 | &catch_syscall_breakpoint_ops); | |
9992 | } | |
9993 | ||
c906108c | 9994 | static void |
fba45db2 | 9995 | catch_command (char *arg, int from_tty) |
c906108c | 9996 | { |
44feb3ce | 9997 | error (_("Catch requires an event name.")); |
c906108c SS |
9998 | } |
9999 | \f | |
10000 | ||
10001 | static void | |
fba45db2 | 10002 | tcatch_command (char *arg, int from_tty) |
c906108c | 10003 | { |
44feb3ce | 10004 | error (_("Catch requires an event name.")); |
c906108c SS |
10005 | } |
10006 | ||
8a2c437b TT |
10007 | /* A qsort comparison function that sorts breakpoints in order. */ |
10008 | ||
10009 | static int | |
10010 | compare_breakpoints (const void *a, const void *b) | |
10011 | { | |
10012 | const breakpoint_p *ba = a; | |
10013 | uintptr_t ua = (uintptr_t) *ba; | |
10014 | const breakpoint_p *bb = b; | |
10015 | uintptr_t ub = (uintptr_t) *bb; | |
10016 | ||
10017 | if ((*ba)->number < (*bb)->number) | |
10018 | return -1; | |
10019 | else if ((*ba)->number > (*bb)->number) | |
10020 | return 1; | |
10021 | ||
10022 | /* Now sort by address, in case we see, e..g, two breakpoints with | |
10023 | the number 0. */ | |
10024 | if (ua < ub) | |
10025 | return -1; | |
10026 | return ub > ub ? 1 : 0; | |
10027 | } | |
10028 | ||
80f8a6eb | 10029 | /* Delete breakpoints by address or line. */ |
c906108c SS |
10030 | |
10031 | static void | |
fba45db2 | 10032 | clear_command (char *arg, int from_tty) |
c906108c | 10033 | { |
8a2c437b | 10034 | struct breakpoint *b, *prev; |
d6e956e5 VP |
10035 | VEC(breakpoint_p) *found = 0; |
10036 | int ix; | |
c906108c SS |
10037 | int default_match; |
10038 | struct symtabs_and_lines sals; | |
10039 | struct symtab_and_line sal; | |
c906108c | 10040 | int i; |
8a2c437b | 10041 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
c906108c SS |
10042 | |
10043 | if (arg) | |
10044 | { | |
f8eba3c6 TT |
10045 | sals = decode_line_spec (arg, (DECODE_LINE_FUNFIRSTLINE |
10046 | | DECODE_LINE_LIST_MODE)); | |
c906108c SS |
10047 | default_match = 0; |
10048 | } | |
10049 | else | |
10050 | { | |
c5aa993b | 10051 | sals.sals = (struct symtab_and_line *) |
c906108c | 10052 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 10053 | make_cleanup (xfree, sals.sals); |
4a64f543 | 10054 | init_sal (&sal); /* Initialize to zeroes. */ |
1bfeeb0f JL |
10055 | |
10056 | /* Set sal's line, symtab, pc, and pspace to the values | |
10057 | corresponding to the last call to print_frame_info. If the | |
10058 | codepoint is not valid, this will set all the fields to 0. */ | |
10059 | get_last_displayed_sal (&sal); | |
c906108c | 10060 | if (sal.symtab == 0) |
8a3fe4f8 | 10061 | error (_("No source file specified.")); |
c906108c SS |
10062 | |
10063 | sals.sals[0] = sal; | |
10064 | sals.nelts = 1; | |
10065 | ||
10066 | default_match = 1; | |
10067 | } | |
10068 | ||
4a64f543 MS |
10069 | /* We don't call resolve_sal_pc here. That's not as bad as it |
10070 | seems, because all existing breakpoints typically have both | |
10071 | file/line and pc set. So, if clear is given file/line, we can | |
10072 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
10073 | |
10074 | We only support clearing given the address explicitly | |
10075 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 10076 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 10077 | due to optimization, all in one block. |
4a64f543 MS |
10078 | |
10079 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
10080 | PC corresponding to the same file:line, the breakpoint won't |
10081 | be cleared. We probably can still clear the breakpoint, but | |
10082 | since the other PC value is never presented to user, user | |
10083 | can only find it by guessing, and it does not seem important | |
10084 | to support that. */ | |
10085 | ||
4a64f543 MS |
10086 | /* For each line spec given, delete bps which correspond to it. Do |
10087 | it in two passes, solely to preserve the current behavior that | |
10088 | from_tty is forced true if we delete more than one | |
10089 | breakpoint. */ | |
c906108c | 10090 | |
80f8a6eb | 10091 | found = NULL; |
8a2c437b | 10092 | make_cleanup (VEC_cleanup (breakpoint_p), &found); |
c906108c SS |
10093 | for (i = 0; i < sals.nelts; i++) |
10094 | { | |
4aac40c8 TT |
10095 | int is_abs, sal_name_len; |
10096 | ||
c906108c | 10097 | /* If exact pc given, clear bpts at that pc. |
c5aa993b JM |
10098 | If line given (pc == 0), clear all bpts on specified line. |
10099 | If defaulting, clear all bpts on default line | |
c906108c | 10100 | or at default pc. |
c5aa993b JM |
10101 | |
10102 | defaulting sal.pc != 0 tests to do | |
10103 | ||
10104 | 0 1 pc | |
10105 | 1 1 pc _and_ line | |
10106 | 0 0 line | |
10107 | 1 0 <can't happen> */ | |
c906108c SS |
10108 | |
10109 | sal = sals.sals[i]; | |
4aac40c8 TT |
10110 | is_abs = sal.symtab == NULL ? 1 : IS_ABSOLUTE_PATH (sal.symtab->filename); |
10111 | sal_name_len = is_abs ? 0 : strlen (sal.symtab->filename); | |
c906108c | 10112 | |
4a64f543 | 10113 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 10114 | ALL_BREAKPOINTS (b) |
c5aa993b | 10115 | { |
0d381245 | 10116 | int match = 0; |
4a64f543 | 10117 | /* Are we going to delete b? */ |
cc60f2e3 | 10118 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
10119 | { |
10120 | struct bp_location *loc = b->loc; | |
10121 | for (; loc; loc = loc->next) | |
10122 | { | |
f8eba3c6 TT |
10123 | /* If the user specified file:line, don't allow a PC |
10124 | match. This matches historical gdb behavior. */ | |
10125 | int pc_match = (!sal.explicit_line | |
10126 | && sal.pc | |
10127 | && (loc->pspace == sal.pspace) | |
10128 | && (loc->address == sal.pc) | |
10129 | && (!section_is_overlay (loc->section) | |
10130 | || loc->section == sal.section)); | |
4aac40c8 TT |
10131 | int line_match = 0; |
10132 | ||
10133 | if ((default_match || sal.explicit_line) | |
10134 | && loc->source_file != NULL | |
10135 | && sal.symtab != NULL | |
10136 | && sal.pspace == loc->pspace | |
10137 | && loc->line_number == sal.line) | |
10138 | { | |
10139 | if (filename_cmp (loc->source_file, | |
10140 | sal.symtab->filename) == 0) | |
10141 | line_match = 1; | |
10142 | else if (!IS_ABSOLUTE_PATH (sal.symtab->filename) | |
10143 | && compare_filenames_for_search (loc->source_file, | |
10144 | sal.symtab->filename, | |
10145 | sal_name_len)) | |
10146 | line_match = 1; | |
10147 | } | |
10148 | ||
0d381245 VP |
10149 | if (pc_match || line_match) |
10150 | { | |
10151 | match = 1; | |
10152 | break; | |
10153 | } | |
10154 | } | |
10155 | } | |
10156 | ||
10157 | if (match) | |
d6e956e5 | 10158 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 10159 | } |
80f8a6eb | 10160 | } |
8a2c437b | 10161 | |
80f8a6eb | 10162 | /* Now go thru the 'found' chain and delete them. */ |
d6e956e5 | 10163 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
10164 | { |
10165 | if (arg) | |
8a3fe4f8 | 10166 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 10167 | else |
8a3fe4f8 | 10168 | error (_("No breakpoint at this line.")); |
80f8a6eb | 10169 | } |
c906108c | 10170 | |
8a2c437b TT |
10171 | /* Remove duplicates from the vec. */ |
10172 | qsort (VEC_address (breakpoint_p, found), | |
10173 | VEC_length (breakpoint_p, found), | |
10174 | sizeof (breakpoint_p), | |
10175 | compare_breakpoints); | |
10176 | prev = VEC_index (breakpoint_p, found, 0); | |
10177 | for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix) | |
10178 | { | |
10179 | if (b == prev) | |
10180 | { | |
10181 | VEC_ordered_remove (breakpoint_p, found, ix); | |
10182 | --ix; | |
10183 | } | |
10184 | } | |
10185 | ||
d6e956e5 | 10186 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 10187 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 10188 | if (from_tty) |
a3f17187 | 10189 | { |
d6e956e5 | 10190 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
10191 | printf_unfiltered (_("Deleted breakpoint ")); |
10192 | else | |
10193 | printf_unfiltered (_("Deleted breakpoints ")); | |
10194 | } | |
80f8a6eb | 10195 | breakpoints_changed (); |
d6e956e5 VP |
10196 | |
10197 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 10198 | { |
c5aa993b | 10199 | if (from_tty) |
d6e956e5 VP |
10200 | printf_unfiltered ("%d ", b->number); |
10201 | delete_breakpoint (b); | |
c906108c | 10202 | } |
80f8a6eb MS |
10203 | if (from_tty) |
10204 | putchar_unfiltered ('\n'); | |
8a2c437b TT |
10205 | |
10206 | do_cleanups (cleanups); | |
c906108c SS |
10207 | } |
10208 | \f | |
10209 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
10210 | all breakpoints that are marked for deletion, whether hit or not. | |
10211 | This is called after any breakpoint is hit, or after errors. */ | |
10212 | ||
10213 | void | |
fba45db2 | 10214 | breakpoint_auto_delete (bpstat bs) |
c906108c | 10215 | { |
35df4500 | 10216 | struct breakpoint *b, *b_tmp; |
c906108c SS |
10217 | |
10218 | for (; bs; bs = bs->next) | |
f431efe5 PA |
10219 | if (bs->breakpoint_at |
10220 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 10221 | && bs->stop) |
f431efe5 | 10222 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 10223 | |
35df4500 | 10224 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 10225 | { |
b5de0fa7 | 10226 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
10227 | delete_breakpoint (b); |
10228 | } | |
c906108c SS |
10229 | } |
10230 | ||
4a64f543 MS |
10231 | /* A comparison function for bp_location AP and BP being interfaced to |
10232 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
10233 | does breakpoint_address_is_meaningful say for its OWNER), | |
10234 | secondarily by ordering first bp_permanent OWNERed elements and | |
10235 | terciarily just ensuring the array is sorted stable way despite | |
e5dd4106 | 10236 | qsort being an unstable algorithm. */ |
876fa593 JK |
10237 | |
10238 | static int | |
494cfb0f | 10239 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 10240 | { |
494cfb0f JK |
10241 | struct bp_location *a = *(void **) ap; |
10242 | struct bp_location *b = *(void **) bp; | |
2bdf28a0 | 10243 | /* A and B come from existing breakpoints having non-NULL OWNER. */ |
876fa593 JK |
10244 | int a_perm = a->owner->enable_state == bp_permanent; |
10245 | int b_perm = b->owner->enable_state == bp_permanent; | |
10246 | ||
10247 | if (a->address != b->address) | |
10248 | return (a->address > b->address) - (a->address < b->address); | |
10249 | ||
10250 | /* Sort permanent breakpoints first. */ | |
10251 | if (a_perm != b_perm) | |
10252 | return (a_perm < b_perm) - (a_perm > b_perm); | |
10253 | ||
4a64f543 MS |
10254 | /* Make the user-visible order stable across GDB runs. Locations of |
10255 | the same breakpoint can be sorted in arbitrary order. */ | |
876fa593 JK |
10256 | |
10257 | if (a->owner->number != b->owner->number) | |
10258 | return (a->owner->number > b->owner->number) | |
10259 | - (a->owner->number < b->owner->number); | |
10260 | ||
10261 | return (a > b) - (a < b); | |
10262 | } | |
10263 | ||
876fa593 | 10264 | /* Set bp_location_placed_address_before_address_max and |
4a64f543 MS |
10265 | bp_location_shadow_len_after_address_max according to the current |
10266 | content of the bp_location array. */ | |
f7545552 TT |
10267 | |
10268 | static void | |
876fa593 | 10269 | bp_location_target_extensions_update (void) |
f7545552 | 10270 | { |
876fa593 JK |
10271 | struct bp_location *bl, **blp_tmp; |
10272 | ||
10273 | bp_location_placed_address_before_address_max = 0; | |
10274 | bp_location_shadow_len_after_address_max = 0; | |
10275 | ||
10276 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
10277 | { | |
10278 | CORE_ADDR start, end, addr; | |
10279 | ||
10280 | if (!bp_location_has_shadow (bl)) | |
10281 | continue; | |
10282 | ||
10283 | start = bl->target_info.placed_address; | |
10284 | end = start + bl->target_info.shadow_len; | |
10285 | ||
10286 | gdb_assert (bl->address >= start); | |
10287 | addr = bl->address - start; | |
10288 | if (addr > bp_location_placed_address_before_address_max) | |
10289 | bp_location_placed_address_before_address_max = addr; | |
10290 | ||
10291 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
10292 | ||
10293 | gdb_assert (bl->address < end); | |
10294 | addr = end - bl->address; | |
10295 | if (addr > bp_location_shadow_len_after_address_max) | |
10296 | bp_location_shadow_len_after_address_max = addr; | |
10297 | } | |
f7545552 TT |
10298 | } |
10299 | ||
1e4d1764 YQ |
10300 | /* Download tracepoint locations if they haven't been. */ |
10301 | ||
10302 | static void | |
10303 | download_tracepoint_locations (void) | |
10304 | { | |
10305 | struct bp_location *bl, **blp_tmp; | |
10306 | struct cleanup *old_chain; | |
10307 | ||
10308 | if (!target_can_download_tracepoint ()) | |
10309 | return; | |
10310 | ||
10311 | old_chain = save_current_space_and_thread (); | |
10312 | ||
10313 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
10314 | { | |
10315 | struct tracepoint *t; | |
10316 | ||
10317 | if (!is_tracepoint (bl->owner)) | |
10318 | continue; | |
10319 | ||
10320 | if ((bl->owner->type == bp_fast_tracepoint | |
10321 | ? !may_insert_fast_tracepoints | |
10322 | : !may_insert_tracepoints)) | |
10323 | continue; | |
10324 | ||
10325 | /* In tracepoint, locations are _never_ duplicated, so | |
10326 | should_be_inserted is equivalent to | |
10327 | unduplicated_should_be_inserted. */ | |
10328 | if (!should_be_inserted (bl) || bl->inserted) | |
10329 | continue; | |
10330 | ||
10331 | switch_to_program_space_and_thread (bl->pspace); | |
10332 | ||
10333 | target_download_tracepoint (bl); | |
10334 | ||
10335 | bl->inserted = 1; | |
10336 | t = (struct tracepoint *) bl->owner; | |
10337 | t->number_on_target = bl->owner->number; | |
10338 | } | |
10339 | ||
10340 | do_cleanups (old_chain); | |
10341 | } | |
10342 | ||
934709f0 PW |
10343 | /* Swap the insertion/duplication state between two locations. */ |
10344 | ||
10345 | static void | |
10346 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
10347 | { | |
10348 | const int left_inserted = left->inserted; | |
10349 | const int left_duplicate = left->duplicate; | |
10350 | const struct bp_target_info left_target_info = left->target_info; | |
10351 | ||
1e4d1764 YQ |
10352 | /* Locations of tracepoints can never be duplicated. */ |
10353 | if (is_tracepoint (left->owner)) | |
10354 | gdb_assert (!left->duplicate); | |
10355 | if (is_tracepoint (right->owner)) | |
10356 | gdb_assert (!right->duplicate); | |
10357 | ||
934709f0 PW |
10358 | left->inserted = right->inserted; |
10359 | left->duplicate = right->duplicate; | |
10360 | left->target_info = right->target_info; | |
10361 | right->inserted = left_inserted; | |
10362 | right->duplicate = left_duplicate; | |
10363 | right->target_info = left_target_info; | |
10364 | } | |
10365 | ||
4cd9bd08 | 10366 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
b60e7edf PA |
10367 | into the inferior, only remove already-inserted locations that no |
10368 | longer should be inserted. Functions that delete a breakpoint or | |
10369 | breakpoints should pass false, so that deleting a breakpoint | |
10370 | doesn't have the side effect of inserting the locations of other | |
10371 | breakpoints that are marked not-inserted, but should_be_inserted | |
10372 | returns true on them. | |
10373 | ||
10374 | This behaviour is useful is situations close to tear-down -- e.g., | |
10375 | after an exec, while the target still has execution, but breakpoint | |
10376 | shadows of the previous executable image should *NOT* be restored | |
10377 | to the new image; or before detaching, where the target still has | |
10378 | execution and wants to delete breakpoints from GDB's lists, and all | |
10379 | breakpoints had already been removed from the inferior. */ | |
10380 | ||
0d381245 | 10381 | static void |
b60e7edf | 10382 | update_global_location_list (int should_insert) |
0d381245 | 10383 | { |
74960c60 | 10384 | struct breakpoint *b; |
876fa593 | 10385 | struct bp_location **locp, *loc; |
f7545552 TT |
10386 | struct cleanup *cleanups; |
10387 | ||
2d134ed3 PA |
10388 | /* Used in the duplicates detection below. When iterating over all |
10389 | bp_locations, points to the first bp_location of a given address. | |
10390 | Breakpoints and watchpoints of different types are never | |
10391 | duplicates of each other. Keep one pointer for each type of | |
10392 | breakpoint/watchpoint, so we only need to loop over all locations | |
10393 | once. */ | |
10394 | struct bp_location *bp_loc_first; /* breakpoint */ | |
10395 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
10396 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
10397 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 10398 | |
4a64f543 MS |
10399 | /* Saved former bp_location array which we compare against the newly |
10400 | built bp_location from the current state of ALL_BREAKPOINTS. */ | |
876fa593 JK |
10401 | struct bp_location **old_location, **old_locp; |
10402 | unsigned old_location_count; | |
10403 | ||
10404 | old_location = bp_location; | |
10405 | old_location_count = bp_location_count; | |
10406 | bp_location = NULL; | |
10407 | bp_location_count = 0; | |
10408 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 10409 | |
74960c60 | 10410 | ALL_BREAKPOINTS (b) |
876fa593 JK |
10411 | for (loc = b->loc; loc; loc = loc->next) |
10412 | bp_location_count++; | |
10413 | ||
10414 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); | |
10415 | locp = bp_location; | |
10416 | ALL_BREAKPOINTS (b) | |
10417 | for (loc = b->loc; loc; loc = loc->next) | |
10418 | *locp++ = loc; | |
10419 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 10420 | bp_location_compare); |
876fa593 JK |
10421 | |
10422 | bp_location_target_extensions_update (); | |
74960c60 | 10423 | |
4a64f543 MS |
10424 | /* Identify bp_location instances that are no longer present in the |
10425 | new list, and therefore should be freed. Note that it's not | |
10426 | necessary that those locations should be removed from inferior -- | |
10427 | if there's another location at the same address (previously | |
10428 | marked as duplicate), we don't need to remove/insert the | |
10429 | location. | |
876fa593 | 10430 | |
4a64f543 MS |
10431 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
10432 | and former bp_location array state respectively. */ | |
876fa593 JK |
10433 | |
10434 | locp = bp_location; | |
10435 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
10436 | old_locp++) | |
74960c60 | 10437 | { |
876fa593 | 10438 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 10439 | struct bp_location **loc2p; |
876fa593 | 10440 | |
e5dd4106 | 10441 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 10442 | not, we have to free it. */ |
c7d46a38 | 10443 | int found_object = 0; |
20874c92 VP |
10444 | /* Tells if the location should remain inserted in the target. */ |
10445 | int keep_in_target = 0; | |
10446 | int removed = 0; | |
876fa593 | 10447 | |
4a64f543 MS |
10448 | /* Skip LOCP entries which will definitely never be needed. |
10449 | Stop either at or being the one matching OLD_LOC. */ | |
876fa593 | 10450 | while (locp < bp_location + bp_location_count |
c7d46a38 | 10451 | && (*locp)->address < old_loc->address) |
876fa593 | 10452 | locp++; |
c7d46a38 PA |
10453 | |
10454 | for (loc2p = locp; | |
10455 | (loc2p < bp_location + bp_location_count | |
10456 | && (*loc2p)->address == old_loc->address); | |
10457 | loc2p++) | |
10458 | { | |
10459 | if (*loc2p == old_loc) | |
10460 | { | |
10461 | found_object = 1; | |
10462 | break; | |
10463 | } | |
10464 | } | |
74960c60 | 10465 | |
4a64f543 MS |
10466 | /* If this location is no longer present, and inserted, look if |
10467 | there's maybe a new location at the same address. If so, | |
10468 | mark that one inserted, and don't remove this one. This is | |
10469 | needed so that we don't have a time window where a breakpoint | |
10470 | at certain location is not inserted. */ | |
74960c60 | 10471 | |
876fa593 | 10472 | if (old_loc->inserted) |
0d381245 | 10473 | { |
4a64f543 MS |
10474 | /* If the location is inserted now, we might have to remove |
10475 | it. */ | |
74960c60 | 10476 | |
876fa593 | 10477 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 10478 | { |
4a64f543 MS |
10479 | /* The location is still present in the location list, |
10480 | and still should be inserted. Don't do anything. */ | |
20874c92 | 10481 | keep_in_target = 1; |
74960c60 VP |
10482 | } |
10483 | else | |
10484 | { | |
4a64f543 MS |
10485 | /* The location is either no longer present, or got |
10486 | disabled. See if there's another location at the | |
10487 | same address, in which case we don't need to remove | |
10488 | this one from the target. */ | |
876fa593 | 10489 | |
2bdf28a0 | 10490 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
10491 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
10492 | { | |
876fa593 | 10493 | for (loc2p = locp; |
c7d46a38 PA |
10494 | (loc2p < bp_location + bp_location_count |
10495 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
10496 | loc2p++) |
10497 | { | |
10498 | struct bp_location *loc2 = *loc2p; | |
10499 | ||
2d134ed3 | 10500 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 10501 | { |
85d721b8 PA |
10502 | /* Read watchpoint locations are switched to |
10503 | access watchpoints, if the former are not | |
10504 | supported, but the latter are. */ | |
10505 | if (is_hardware_watchpoint (old_loc->owner)) | |
10506 | { | |
10507 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
10508 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
10509 | } | |
10510 | ||
934709f0 PW |
10511 | /* loc2 is a duplicated location. We need to check |
10512 | if it should be inserted in case it will be | |
10513 | unduplicated. */ | |
10514 | if (loc2 != old_loc | |
10515 | && unduplicated_should_be_inserted (loc2)) | |
c7d46a38 | 10516 | { |
934709f0 | 10517 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
10518 | keep_in_target = 1; |
10519 | break; | |
10520 | } | |
876fa593 JK |
10521 | } |
10522 | } | |
10523 | } | |
74960c60 VP |
10524 | } |
10525 | ||
20874c92 VP |
10526 | if (!keep_in_target) |
10527 | { | |
876fa593 | 10528 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 | 10529 | { |
4a64f543 MS |
10530 | /* This is just about all we can do. We could keep |
10531 | this location on the global list, and try to | |
10532 | remove it next time, but there's no particular | |
10533 | reason why we will succeed next time. | |
20874c92 | 10534 | |
4a64f543 MS |
10535 | Note that at this point, old_loc->owner is still |
10536 | valid, as delete_breakpoint frees the breakpoint | |
10537 | only after calling us. */ | |
3e43a32a MS |
10538 | printf_filtered (_("warning: Error removing " |
10539 | "breakpoint %d\n"), | |
876fa593 | 10540 | old_loc->owner->number); |
20874c92 VP |
10541 | } |
10542 | removed = 1; | |
10543 | } | |
0d381245 | 10544 | } |
74960c60 VP |
10545 | |
10546 | if (!found_object) | |
1c5cfe86 | 10547 | { |
db82e815 PA |
10548 | if (removed && non_stop |
10549 | && breakpoint_address_is_meaningful (old_loc->owner) | |
10550 | && !is_hardware_watchpoint (old_loc->owner)) | |
20874c92 | 10551 | { |
db82e815 PA |
10552 | /* This location was removed from the target. In |
10553 | non-stop mode, a race condition is possible where | |
10554 | we've removed a breakpoint, but stop events for that | |
10555 | breakpoint are already queued and will arrive later. | |
10556 | We apply an heuristic to be able to distinguish such | |
10557 | SIGTRAPs from other random SIGTRAPs: we keep this | |
10558 | breakpoint location for a bit, and will retire it | |
10559 | after we see some number of events. The theory here | |
10560 | is that reporting of events should, "on the average", | |
10561 | be fair, so after a while we'll see events from all | |
10562 | threads that have anything of interest, and no longer | |
10563 | need to keep this breakpoint location around. We | |
10564 | don't hold locations forever so to reduce chances of | |
10565 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
10566 | SIGTRAP. | |
10567 | ||
10568 | The heuristic failing can be disastrous on | |
10569 | decr_pc_after_break targets. | |
10570 | ||
10571 | On decr_pc_after_break targets, like e.g., x86-linux, | |
10572 | if we fail to recognize a late breakpoint SIGTRAP, | |
10573 | because events_till_retirement has reached 0 too | |
10574 | soon, we'll fail to do the PC adjustment, and report | |
10575 | a random SIGTRAP to the user. When the user resumes | |
10576 | the inferior, it will most likely immediately crash | |
2dec564e | 10577 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
10578 | corrupted, because of being resumed e.g., in the |
10579 | middle of a multi-byte instruction, or skipped a | |
10580 | one-byte instruction. This was actually seen happen | |
10581 | on native x86-linux, and should be less rare on | |
10582 | targets that do not support new thread events, like | |
10583 | remote, due to the heuristic depending on | |
10584 | thread_count. | |
10585 | ||
10586 | Mistaking a random SIGTRAP for a breakpoint trap | |
10587 | causes similar symptoms (PC adjustment applied when | |
10588 | it shouldn't), but then again, playing with SIGTRAPs | |
10589 | behind the debugger's back is asking for trouble. | |
10590 | ||
10591 | Since hardware watchpoint traps are always | |
10592 | distinguishable from other traps, so we don't need to | |
10593 | apply keep hardware watchpoint moribund locations | |
10594 | around. We simply always ignore hardware watchpoint | |
10595 | traps we can no longer explain. */ | |
10596 | ||
876fa593 JK |
10597 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
10598 | old_loc->owner = NULL; | |
20874c92 | 10599 | |
876fa593 | 10600 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
10601 | } |
10602 | else | |
f431efe5 PA |
10603 | { |
10604 | old_loc->owner = NULL; | |
10605 | decref_bp_location (&old_loc); | |
10606 | } | |
20874c92 | 10607 | } |
74960c60 | 10608 | } |
1c5cfe86 | 10609 | |
348d480f PA |
10610 | /* Rescan breakpoints at the same address and section, marking the |
10611 | first one as "first" and any others as "duplicates". This is so | |
10612 | that the bpt instruction is only inserted once. If we have a | |
10613 | permanent breakpoint at the same place as BPT, make that one the | |
10614 | official one, and the rest as duplicates. Permanent breakpoints | |
10615 | are sorted first for the same address. | |
10616 | ||
10617 | Do the same for hardware watchpoints, but also considering the | |
10618 | watchpoint's type (regular/access/read) and length. */ | |
10619 | ||
10620 | bp_loc_first = NULL; | |
10621 | wp_loc_first = NULL; | |
10622 | awp_loc_first = NULL; | |
10623 | rwp_loc_first = NULL; | |
10624 | ALL_BP_LOCATIONS (loc, locp) | |
10625 | { | |
10626 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
10627 | non-NULL. */ | |
348d480f | 10628 | struct bp_location **loc_first_p; |
d3fbdd86 | 10629 | b = loc->owner; |
348d480f | 10630 | |
f8eba3c6 | 10631 | if (!should_be_inserted (loc) |
348d480f | 10632 | || !breakpoint_address_is_meaningful (b) |
1e4d1764 YQ |
10633 | /* Don't detect duplicate for tracepoint locations because they are |
10634 | never duplicated. See the comments in field `duplicate' of | |
10635 | `struct bp_location'. */ | |
348d480f PA |
10636 | || is_tracepoint (b)) |
10637 | continue; | |
10638 | ||
10639 | /* Permanent breakpoint should always be inserted. */ | |
10640 | if (b->enable_state == bp_permanent && ! loc->inserted) | |
10641 | internal_error (__FILE__, __LINE__, | |
10642 | _("allegedly permanent breakpoint is not " | |
10643 | "actually inserted")); | |
10644 | ||
10645 | if (b->type == bp_hardware_watchpoint) | |
10646 | loc_first_p = &wp_loc_first; | |
10647 | else if (b->type == bp_read_watchpoint) | |
10648 | loc_first_p = &rwp_loc_first; | |
10649 | else if (b->type == bp_access_watchpoint) | |
10650 | loc_first_p = &awp_loc_first; | |
10651 | else | |
10652 | loc_first_p = &bp_loc_first; | |
10653 | ||
10654 | if (*loc_first_p == NULL | |
10655 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
10656 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
10657 | { | |
10658 | *loc_first_p = loc; | |
10659 | loc->duplicate = 0; | |
10660 | continue; | |
10661 | } | |
10662 | ||
934709f0 PW |
10663 | |
10664 | /* This and the above ensure the invariant that the first location | |
10665 | is not duplicated, and is the inserted one. | |
10666 | All following are marked as duplicated, and are not inserted. */ | |
10667 | if (loc->inserted) | |
10668 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
10669 | loc->duplicate = 1; |
10670 | ||
10671 | if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted | |
10672 | && b->enable_state != bp_permanent) | |
10673 | internal_error (__FILE__, __LINE__, | |
10674 | _("another breakpoint was inserted on top of " | |
10675 | "a permanent breakpoint")); | |
10676 | } | |
10677 | ||
10678 | if (breakpoints_always_inserted_mode () && should_insert | |
10679 | && (have_live_inferiors () | |
10680 | || (gdbarch_has_global_breakpoints (target_gdbarch)))) | |
10681 | insert_breakpoint_locations (); | |
10682 | ||
1e4d1764 YQ |
10683 | if (should_insert) |
10684 | download_tracepoint_locations (); | |
10685 | ||
348d480f PA |
10686 | do_cleanups (cleanups); |
10687 | } | |
10688 | ||
10689 | void | |
10690 | breakpoint_retire_moribund (void) | |
10691 | { | |
10692 | struct bp_location *loc; | |
10693 | int ix; | |
10694 | ||
10695 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
10696 | if (--(loc->events_till_retirement) == 0) | |
10697 | { | |
10698 | decref_bp_location (&loc); | |
10699 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
10700 | --ix; | |
10701 | } | |
10702 | } | |
10703 | ||
10704 | static void | |
10705 | update_global_location_list_nothrow (int inserting) | |
10706 | { | |
bfd189b1 | 10707 | volatile struct gdb_exception e; |
348d480f PA |
10708 | |
10709 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
10710 | update_global_location_list (inserting); | |
10711 | } | |
10712 | ||
10713 | /* Clear BKP from a BPS. */ | |
10714 | ||
10715 | static void | |
10716 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) | |
10717 | { | |
10718 | bpstat bs; | |
10719 | ||
10720 | for (bs = bps; bs; bs = bs->next) | |
10721 | if (bs->breakpoint_at == bpt) | |
10722 | { | |
10723 | bs->breakpoint_at = NULL; | |
10724 | bs->old_val = NULL; | |
10725 | /* bs->commands will be freed later. */ | |
10726 | } | |
10727 | } | |
10728 | ||
10729 | /* Callback for iterate_over_threads. */ | |
10730 | static int | |
10731 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
10732 | { | |
10733 | struct breakpoint *bpt = data; | |
10734 | ||
10735 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
10736 | return 0; | |
10737 | } | |
10738 | ||
10739 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
10740 | callbacks. */ | |
10741 | ||
10742 | static void | |
10743 | say_where (struct breakpoint *b) | |
10744 | { | |
79a45e25 | 10745 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10746 | struct value_print_options opts; |
10747 | ||
10748 | get_user_print_options (&opts); | |
10749 | ||
10750 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
10751 | single string. */ | |
10752 | if (b->loc == NULL) | |
10753 | { | |
10754 | printf_filtered (_(" (%s) pending."), b->addr_string); | |
10755 | } | |
10756 | else | |
10757 | { | |
f8eba3c6 | 10758 | if (opts.addressprint || b->loc->source_file == NULL) |
348d480f PA |
10759 | { |
10760 | printf_filtered (" at "); | |
10761 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), | |
10762 | gdb_stdout); | |
10763 | } | |
f8eba3c6 TT |
10764 | if (b->loc->source_file) |
10765 | { | |
10766 | /* If there is a single location, we can print the location | |
10767 | more nicely. */ | |
10768 | if (b->loc->next == NULL) | |
10769 | printf_filtered (": file %s, line %d.", | |
10770 | b->loc->source_file, b->loc->line_number); | |
10771 | else | |
10772 | /* This is not ideal, but each location may have a | |
10773 | different file name, and this at least reflects the | |
10774 | real situation somewhat. */ | |
10775 | printf_filtered (": %s.", b->addr_string); | |
10776 | } | |
348d480f PA |
10777 | |
10778 | if (b->loc->next) | |
10779 | { | |
10780 | struct bp_location *loc = b->loc; | |
10781 | int n = 0; | |
10782 | for (; loc; loc = loc->next) | |
10783 | ++n; | |
10784 | printf_filtered (" (%d locations)", n); | |
10785 | } | |
10786 | } | |
10787 | } | |
10788 | ||
348d480f PA |
10789 | /* Default bp_location_ops methods. */ |
10790 | ||
10791 | static void | |
10792 | bp_location_dtor (struct bp_location *self) | |
10793 | { | |
10794 | xfree (self->cond); | |
10795 | xfree (self->function_name); | |
f8eba3c6 | 10796 | xfree (self->source_file); |
348d480f PA |
10797 | } |
10798 | ||
10799 | static const struct bp_location_ops bp_location_ops = | |
10800 | { | |
10801 | bp_location_dtor | |
10802 | }; | |
10803 | ||
2060206e PA |
10804 | /* Default breakpoint_ops methods all breakpoint_ops ultimately |
10805 | inherit from. */ | |
348d480f | 10806 | |
2060206e PA |
10807 | static void |
10808 | base_breakpoint_dtor (struct breakpoint *self) | |
348d480f PA |
10809 | { |
10810 | decref_counted_command_line (&self->commands); | |
10811 | xfree (self->cond_string); | |
348d480f | 10812 | xfree (self->addr_string); |
f8eba3c6 | 10813 | xfree (self->filter); |
348d480f | 10814 | xfree (self->addr_string_range_end); |
348d480f PA |
10815 | } |
10816 | ||
2060206e PA |
10817 | static struct bp_location * |
10818 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f PA |
10819 | { |
10820 | struct bp_location *loc; | |
10821 | ||
10822 | loc = XNEW (struct bp_location); | |
10823 | init_bp_location (loc, &bp_location_ops, self); | |
10824 | return loc; | |
10825 | } | |
10826 | ||
2060206e PA |
10827 | static void |
10828 | base_breakpoint_re_set (struct breakpoint *b) | |
10829 | { | |
10830 | /* Nothing to re-set. */ | |
10831 | } | |
10832 | ||
10833 | #define internal_error_pure_virtual_called() \ | |
10834 | gdb_assert_not_reached ("pure virtual function called") | |
10835 | ||
10836 | static int | |
10837 | base_breakpoint_insert_location (struct bp_location *bl) | |
10838 | { | |
10839 | internal_error_pure_virtual_called (); | |
10840 | } | |
10841 | ||
10842 | static int | |
10843 | base_breakpoint_remove_location (struct bp_location *bl) | |
10844 | { | |
10845 | internal_error_pure_virtual_called (); | |
10846 | } | |
10847 | ||
10848 | static int | |
10849 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
10850 | struct address_space *aspace, | |
09ac7c10 TT |
10851 | CORE_ADDR bp_addr, |
10852 | const struct target_waitstatus *ws) | |
2060206e PA |
10853 | { |
10854 | internal_error_pure_virtual_called (); | |
10855 | } | |
10856 | ||
10857 | static void | |
10858 | base_breakpoint_check_status (bpstat bs) | |
10859 | { | |
10860 | /* Always stop. */ | |
10861 | } | |
10862 | ||
10863 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
10864 | errors. */ | |
10865 | ||
10866 | static int | |
10867 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
10868 | { | |
10869 | internal_error_pure_virtual_called (); | |
10870 | } | |
10871 | ||
10872 | /* A "resources_needed" breakpoint_ops method that just internal | |
10873 | errors. */ | |
10874 | ||
10875 | static int | |
10876 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
10877 | { | |
10878 | internal_error_pure_virtual_called (); | |
10879 | } | |
10880 | ||
10881 | static enum print_stop_action | |
10882 | base_breakpoint_print_it (bpstat bs) | |
10883 | { | |
10884 | internal_error_pure_virtual_called (); | |
10885 | } | |
10886 | ||
10887 | static void | |
10888 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
10889 | struct ui_out *uiout) | |
10890 | { | |
10891 | /* nothing */ | |
10892 | } | |
10893 | ||
10894 | static void | |
10895 | base_breakpoint_print_mention (struct breakpoint *b) | |
10896 | { | |
10897 | internal_error_pure_virtual_called (); | |
10898 | } | |
10899 | ||
10900 | static void | |
10901 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
10902 | { | |
10903 | internal_error_pure_virtual_called (); | |
10904 | } | |
10905 | ||
983af33b SDJ |
10906 | static void |
10907 | base_breakpoint_create_sals_from_address (char **arg, | |
10908 | struct linespec_result *canonical, | |
10909 | enum bptype type_wanted, | |
10910 | char *addr_start, | |
10911 | char **copy_arg) | |
10912 | { | |
10913 | internal_error_pure_virtual_called (); | |
10914 | } | |
10915 | ||
10916 | static void | |
10917 | base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
10918 | struct linespec_result *c, | |
10919 | struct linespec_sals *lsal, | |
10920 | char *cond_string, | |
10921 | enum bptype type_wanted, | |
10922 | enum bpdisp disposition, | |
10923 | int thread, | |
10924 | int task, int ignore_count, | |
10925 | const struct breakpoint_ops *o, | |
10926 | int from_tty, int enabled, | |
10927 | int internal) | |
10928 | { | |
10929 | internal_error_pure_virtual_called (); | |
10930 | } | |
10931 | ||
10932 | static void | |
10933 | base_breakpoint_decode_linespec (struct breakpoint *b, char **s, | |
10934 | struct symtabs_and_lines *sals) | |
10935 | { | |
10936 | internal_error_pure_virtual_called (); | |
10937 | } | |
10938 | ||
2060206e PA |
10939 | static struct breakpoint_ops base_breakpoint_ops = |
10940 | { | |
10941 | base_breakpoint_dtor, | |
10942 | base_breakpoint_allocate_location, | |
10943 | base_breakpoint_re_set, | |
10944 | base_breakpoint_insert_location, | |
10945 | base_breakpoint_remove_location, | |
10946 | base_breakpoint_breakpoint_hit, | |
10947 | base_breakpoint_check_status, | |
10948 | base_breakpoint_resources_needed, | |
10949 | base_breakpoint_works_in_software_mode, | |
10950 | base_breakpoint_print_it, | |
10951 | NULL, | |
10952 | base_breakpoint_print_one_detail, | |
10953 | base_breakpoint_print_mention, | |
983af33b SDJ |
10954 | base_breakpoint_print_recreate, |
10955 | base_breakpoint_create_sals_from_address, | |
10956 | base_breakpoint_create_breakpoints_sal, | |
10957 | base_breakpoint_decode_linespec, | |
2060206e PA |
10958 | }; |
10959 | ||
10960 | /* Default breakpoint_ops methods. */ | |
10961 | ||
10962 | static void | |
348d480f PA |
10963 | bkpt_re_set (struct breakpoint *b) |
10964 | { | |
06edf0c0 PA |
10965 | /* FIXME: is this still reachable? */ |
10966 | if (b->addr_string == NULL) | |
10967 | { | |
10968 | /* Anything without a string can't be re-set. */ | |
348d480f | 10969 | delete_breakpoint (b); |
06edf0c0 | 10970 | return; |
348d480f | 10971 | } |
06edf0c0 PA |
10972 | |
10973 | breakpoint_re_set_default (b); | |
348d480f PA |
10974 | } |
10975 | ||
2060206e | 10976 | static int |
348d480f PA |
10977 | bkpt_insert_location (struct bp_location *bl) |
10978 | { | |
10979 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
10980 | return target_insert_hw_breakpoint (bl->gdbarch, | |
10981 | &bl->target_info); | |
10982 | else | |
10983 | return target_insert_breakpoint (bl->gdbarch, | |
10984 | &bl->target_info); | |
10985 | } | |
10986 | ||
2060206e | 10987 | static int |
348d480f PA |
10988 | bkpt_remove_location (struct bp_location *bl) |
10989 | { | |
10990 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
10991 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
10992 | else | |
10993 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info); | |
10994 | } | |
10995 | ||
2060206e | 10996 | static int |
348d480f | 10997 | bkpt_breakpoint_hit (const struct bp_location *bl, |
09ac7c10 TT |
10998 | struct address_space *aspace, CORE_ADDR bp_addr, |
10999 | const struct target_waitstatus *ws) | |
348d480f PA |
11000 | { |
11001 | struct breakpoint *b = bl->owner; | |
11002 | ||
09ac7c10 TT |
11003 | if (ws->kind != TARGET_WAITKIND_STOPPED |
11004 | || ws->value.sig != TARGET_SIGNAL_TRAP) | |
11005 | return 0; | |
11006 | ||
348d480f PA |
11007 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
11008 | aspace, bp_addr)) | |
11009 | return 0; | |
11010 | ||
11011 | if (overlay_debugging /* unmapped overlay section */ | |
11012 | && section_is_overlay (bl->section) | |
11013 | && !section_is_mapped (bl->section)) | |
11014 | return 0; | |
11015 | ||
11016 | return 1; | |
11017 | } | |
11018 | ||
2060206e | 11019 | static int |
348d480f PA |
11020 | bkpt_resources_needed (const struct bp_location *bl) |
11021 | { | |
11022 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
11023 | ||
11024 | return 1; | |
11025 | } | |
11026 | ||
2060206e | 11027 | static enum print_stop_action |
348d480f PA |
11028 | bkpt_print_it (bpstat bs) |
11029 | { | |
348d480f PA |
11030 | struct breakpoint *b; |
11031 | const struct bp_location *bl; | |
001c8c33 | 11032 | int bp_temp; |
79a45e25 | 11033 | struct ui_out *uiout = current_uiout; |
348d480f PA |
11034 | |
11035 | gdb_assert (bs->bp_location_at != NULL); | |
11036 | ||
11037 | bl = bs->bp_location_at; | |
11038 | b = bs->breakpoint_at; | |
11039 | ||
001c8c33 PA |
11040 | bp_temp = b->disposition == disp_del; |
11041 | if (bl->address != bl->requested_address) | |
11042 | breakpoint_adjustment_warning (bl->requested_address, | |
11043 | bl->address, | |
11044 | b->number, 1); | |
11045 | annotate_breakpoint (b->number); | |
11046 | if (bp_temp) | |
11047 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
11048 | else | |
11049 | ui_out_text (uiout, "\nBreakpoint "); | |
11050 | if (ui_out_is_mi_like_p (uiout)) | |
348d480f | 11051 | { |
001c8c33 PA |
11052 | ui_out_field_string (uiout, "reason", |
11053 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
11054 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
06edf0c0 | 11055 | } |
001c8c33 PA |
11056 | ui_out_field_int (uiout, "bkptno", b->number); |
11057 | ui_out_text (uiout, ", "); | |
06edf0c0 | 11058 | |
001c8c33 | 11059 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
11060 | } |
11061 | ||
2060206e | 11062 | static void |
06edf0c0 PA |
11063 | bkpt_print_mention (struct breakpoint *b) |
11064 | { | |
79a45e25 | 11065 | if (ui_out_is_mi_like_p (current_uiout)) |
06edf0c0 PA |
11066 | return; |
11067 | ||
11068 | switch (b->type) | |
11069 | { | |
11070 | case bp_breakpoint: | |
11071 | case bp_gnu_ifunc_resolver: | |
11072 | if (b->disposition == disp_del) | |
11073 | printf_filtered (_("Temporary breakpoint")); | |
11074 | else | |
11075 | printf_filtered (_("Breakpoint")); | |
11076 | printf_filtered (_(" %d"), b->number); | |
11077 | if (b->type == bp_gnu_ifunc_resolver) | |
11078 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
11079 | break; | |
11080 | case bp_hardware_breakpoint: | |
11081 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
11082 | break; | |
11083 | } | |
11084 | ||
11085 | say_where (b); | |
11086 | } | |
11087 | ||
2060206e | 11088 | static void |
06edf0c0 PA |
11089 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
11090 | { | |
11091 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
11092 | fprintf_unfiltered (fp, "tbreak"); | |
11093 | else if (tp->type == bp_breakpoint) | |
11094 | fprintf_unfiltered (fp, "break"); | |
11095 | else if (tp->type == bp_hardware_breakpoint | |
11096 | && tp->disposition == disp_del) | |
11097 | fprintf_unfiltered (fp, "thbreak"); | |
11098 | else if (tp->type == bp_hardware_breakpoint) | |
11099 | fprintf_unfiltered (fp, "hbreak"); | |
11100 | else | |
11101 | internal_error (__FILE__, __LINE__, | |
11102 | _("unhandled breakpoint type %d"), (int) tp->type); | |
11103 | ||
2060206e | 11104 | fprintf_unfiltered (fp, " %s", tp->addr_string); |
dd11a36c | 11105 | print_recreate_thread (tp, fp); |
06edf0c0 PA |
11106 | } |
11107 | ||
983af33b SDJ |
11108 | static void |
11109 | bkpt_create_sals_from_address (char **arg, | |
11110 | struct linespec_result *canonical, | |
11111 | enum bptype type_wanted, | |
11112 | char *addr_start, char **copy_arg) | |
11113 | { | |
11114 | create_sals_from_address_default (arg, canonical, type_wanted, | |
11115 | addr_start, copy_arg); | |
11116 | } | |
11117 | ||
11118 | static void | |
11119 | bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, | |
11120 | struct linespec_result *canonical, | |
11121 | struct linespec_sals *lsal, | |
11122 | char *cond_string, | |
11123 | enum bptype type_wanted, | |
11124 | enum bpdisp disposition, | |
11125 | int thread, | |
11126 | int task, int ignore_count, | |
11127 | const struct breakpoint_ops *ops, | |
11128 | int from_tty, int enabled, | |
11129 | int internal) | |
11130 | { | |
11131 | create_breakpoints_sal_default (gdbarch, canonical, lsal, | |
11132 | cond_string, type_wanted, | |
11133 | disposition, thread, task, | |
11134 | ignore_count, ops, from_tty, | |
11135 | enabled, internal); | |
11136 | } | |
11137 | ||
11138 | static void | |
11139 | bkpt_decode_linespec (struct breakpoint *b, char **s, | |
11140 | struct symtabs_and_lines *sals) | |
11141 | { | |
11142 | decode_linespec_default (b, s, sals); | |
11143 | } | |
11144 | ||
06edf0c0 PA |
11145 | /* Virtual table for internal breakpoints. */ |
11146 | ||
11147 | static void | |
11148 | internal_bkpt_re_set (struct breakpoint *b) | |
11149 | { | |
11150 | switch (b->type) | |
11151 | { | |
11152 | /* Delete overlay event and longjmp master breakpoints; they | |
11153 | will be reset later by breakpoint_re_set. */ | |
11154 | case bp_overlay_event: | |
11155 | case bp_longjmp_master: | |
11156 | case bp_std_terminate_master: | |
11157 | case bp_exception_master: | |
11158 | delete_breakpoint (b); | |
11159 | break; | |
11160 | ||
11161 | /* This breakpoint is special, it's set up when the inferior | |
11162 | starts and we really don't want to touch it. */ | |
11163 | case bp_shlib_event: | |
11164 | ||
11165 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
11166 | it is set up, we do not want to touch it. */ | |
11167 | case bp_thread_event: | |
11168 | break; | |
11169 | } | |
11170 | } | |
11171 | ||
11172 | static void | |
11173 | internal_bkpt_check_status (bpstat bs) | |
11174 | { | |
a9b3a50f PA |
11175 | if (bs->breakpoint_at->type == bp_shlib_event) |
11176 | { | |
11177 | /* If requested, stop when the dynamic linker notifies GDB of | |
11178 | events. This allows the user to get control and place | |
11179 | breakpoints in initializer routines for dynamically loaded | |
11180 | objects (among other things). */ | |
11181 | bs->stop = stop_on_solib_events; | |
11182 | bs->print = stop_on_solib_events; | |
11183 | } | |
11184 | else | |
11185 | bs->stop = 0; | |
06edf0c0 PA |
11186 | } |
11187 | ||
11188 | static enum print_stop_action | |
11189 | internal_bkpt_print_it (bpstat bs) | |
11190 | { | |
36dfb11c | 11191 | struct ui_out *uiout = current_uiout; |
06edf0c0 | 11192 | struct breakpoint *b; |
06edf0c0 | 11193 | |
06edf0c0 PA |
11194 | b = bs->breakpoint_at; |
11195 | ||
06edf0c0 PA |
11196 | switch (b->type) |
11197 | { | |
348d480f PA |
11198 | case bp_shlib_event: |
11199 | /* Did we stop because the user set the stop_on_solib_events | |
11200 | variable? (If so, we report this as a generic, "Stopped due | |
11201 | to shlib event" message.) */ | |
36dfb11c TT |
11202 | ui_out_text (uiout, _("Stopped due to shared library event\n")); |
11203 | if (ui_out_is_mi_like_p (uiout)) | |
11204 | ui_out_field_string (uiout, "reason", | |
11205 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); | |
348d480f PA |
11206 | break; |
11207 | ||
11208 | case bp_thread_event: | |
11209 | /* Not sure how we will get here. | |
11210 | GDB should not stop for these breakpoints. */ | |
11211 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
11212 | break; |
11213 | ||
11214 | case bp_overlay_event: | |
11215 | /* By analogy with the thread event, GDB should not stop for these. */ | |
11216 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
11217 | break; |
11218 | ||
11219 | case bp_longjmp_master: | |
11220 | /* These should never be enabled. */ | |
11221 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
11222 | break; |
11223 | ||
11224 | case bp_std_terminate_master: | |
11225 | /* These should never be enabled. */ | |
11226 | printf_filtered (_("std::terminate Master Breakpoint: " | |
11227 | "gdb should not stop!\n")); | |
348d480f PA |
11228 | break; |
11229 | ||
11230 | case bp_exception_master: | |
11231 | /* These should never be enabled. */ | |
11232 | printf_filtered (_("Exception Master Breakpoint: " | |
11233 | "gdb should not stop!\n")); | |
06edf0c0 PA |
11234 | break; |
11235 | } | |
11236 | ||
001c8c33 | 11237 | return PRINT_NOTHING; |
06edf0c0 PA |
11238 | } |
11239 | ||
11240 | static void | |
11241 | internal_bkpt_print_mention (struct breakpoint *b) | |
11242 | { | |
11243 | /* Nothing to mention. These breakpoints are internal. */ | |
11244 | } | |
11245 | ||
06edf0c0 PA |
11246 | /* Virtual table for momentary breakpoints */ |
11247 | ||
11248 | static void | |
11249 | momentary_bkpt_re_set (struct breakpoint *b) | |
11250 | { | |
11251 | /* Keep temporary breakpoints, which can be encountered when we step | |
11252 | over a dlopen call and SOLIB_ADD is resetting the breakpoints. | |
11253 | Otherwise these should have been blown away via the cleanup chain | |
11254 | or by breakpoint_init_inferior when we rerun the executable. */ | |
11255 | } | |
11256 | ||
11257 | static void | |
11258 | momentary_bkpt_check_status (bpstat bs) | |
11259 | { | |
11260 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
11261 | } | |
11262 | ||
11263 | static enum print_stop_action | |
11264 | momentary_bkpt_print_it (bpstat bs) | |
11265 | { | |
79a45e25 PA |
11266 | struct ui_out *uiout = current_uiout; |
11267 | ||
001c8c33 | 11268 | if (ui_out_is_mi_like_p (uiout)) |
06edf0c0 | 11269 | { |
001c8c33 | 11270 | struct breakpoint *b = bs->breakpoint_at; |
348d480f | 11271 | |
001c8c33 PA |
11272 | switch (b->type) |
11273 | { | |
11274 | case bp_finish: | |
11275 | ui_out_field_string | |
11276 | (uiout, "reason", | |
11277 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
11278 | break; | |
348d480f | 11279 | |
001c8c33 PA |
11280 | case bp_until: |
11281 | ui_out_field_string | |
11282 | (uiout, "reason", | |
11283 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
11284 | break; | |
11285 | } | |
348d480f PA |
11286 | } |
11287 | ||
001c8c33 | 11288 | return PRINT_UNKNOWN; |
348d480f PA |
11289 | } |
11290 | ||
06edf0c0 PA |
11291 | static void |
11292 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 11293 | { |
06edf0c0 | 11294 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
11295 | } |
11296 | ||
348d480f | 11297 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 11298 | |
348d480f PA |
11299 | static void |
11300 | tracepoint_re_set (struct breakpoint *b) | |
11301 | { | |
11302 | breakpoint_re_set_default (b); | |
11303 | } | |
876fa593 | 11304 | |
348d480f PA |
11305 | static int |
11306 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
09ac7c10 TT |
11307 | struct address_space *aspace, CORE_ADDR bp_addr, |
11308 | const struct target_waitstatus *ws) | |
348d480f PA |
11309 | { |
11310 | /* By definition, the inferior does not report stops at | |
11311 | tracepoints. */ | |
11312 | return 0; | |
74960c60 VP |
11313 | } |
11314 | ||
11315 | static void | |
348d480f PA |
11316 | tracepoint_print_one_detail (const struct breakpoint *self, |
11317 | struct ui_out *uiout) | |
74960c60 | 11318 | { |
d9b3f62e PA |
11319 | struct tracepoint *tp = (struct tracepoint *) self; |
11320 | if (tp->static_trace_marker_id) | |
348d480f PA |
11321 | { |
11322 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 11323 | |
348d480f PA |
11324 | ui_out_text (uiout, "\tmarker id is "); |
11325 | ui_out_field_string (uiout, "static-tracepoint-marker-string-id", | |
d9b3f62e | 11326 | tp->static_trace_marker_id); |
348d480f PA |
11327 | ui_out_text (uiout, "\n"); |
11328 | } | |
0d381245 VP |
11329 | } |
11330 | ||
a474d7c2 | 11331 | static void |
348d480f | 11332 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 11333 | { |
79a45e25 | 11334 | if (ui_out_is_mi_like_p (current_uiout)) |
348d480f | 11335 | return; |
cc59ec59 | 11336 | |
348d480f PA |
11337 | switch (b->type) |
11338 | { | |
11339 | case bp_tracepoint: | |
11340 | printf_filtered (_("Tracepoint")); | |
11341 | printf_filtered (_(" %d"), b->number); | |
11342 | break; | |
11343 | case bp_fast_tracepoint: | |
11344 | printf_filtered (_("Fast tracepoint")); | |
11345 | printf_filtered (_(" %d"), b->number); | |
11346 | break; | |
11347 | case bp_static_tracepoint: | |
11348 | printf_filtered (_("Static tracepoint")); | |
11349 | printf_filtered (_(" %d"), b->number); | |
11350 | break; | |
11351 | default: | |
11352 | internal_error (__FILE__, __LINE__, | |
11353 | _("unhandled tracepoint type %d"), (int) b->type); | |
11354 | } | |
11355 | ||
11356 | say_where (b); | |
a474d7c2 PA |
11357 | } |
11358 | ||
348d480f | 11359 | static void |
d9b3f62e | 11360 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 11361 | { |
d9b3f62e PA |
11362 | struct tracepoint *tp = (struct tracepoint *) self; |
11363 | ||
11364 | if (self->type == bp_fast_tracepoint) | |
348d480f | 11365 | fprintf_unfiltered (fp, "ftrace"); |
d9b3f62e | 11366 | if (self->type == bp_static_tracepoint) |
348d480f | 11367 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 11368 | else if (self->type == bp_tracepoint) |
348d480f PA |
11369 | fprintf_unfiltered (fp, "trace"); |
11370 | else | |
11371 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 11372 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 11373 | |
d9b3f62e PA |
11374 | fprintf_unfiltered (fp, " %s", self->addr_string); |
11375 | print_recreate_thread (self, fp); | |
11376 | ||
11377 | if (tp->pass_count) | |
11378 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
11379 | } |
11380 | ||
983af33b SDJ |
11381 | static void |
11382 | tracepoint_create_sals_from_address (char **arg, | |
11383 | struct linespec_result *canonical, | |
11384 | enum bptype type_wanted, | |
11385 | char *addr_start, char **copy_arg) | |
11386 | { | |
11387 | create_sals_from_address_default (arg, canonical, type_wanted, | |
11388 | addr_start, copy_arg); | |
11389 | } | |
11390 | ||
11391 | static void | |
11392 | tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
11393 | struct linespec_result *canonical, | |
11394 | struct linespec_sals *lsal, | |
11395 | char *cond_string, | |
11396 | enum bptype type_wanted, | |
11397 | enum bpdisp disposition, | |
11398 | int thread, | |
11399 | int task, int ignore_count, | |
11400 | const struct breakpoint_ops *ops, | |
11401 | int from_tty, int enabled, | |
11402 | int internal) | |
11403 | { | |
11404 | create_breakpoints_sal_default (gdbarch, canonical, lsal, | |
11405 | cond_string, type_wanted, | |
11406 | disposition, thread, task, | |
11407 | ignore_count, ops, from_tty, | |
11408 | enabled, internal); | |
11409 | } | |
11410 | ||
11411 | static void | |
11412 | tracepoint_decode_linespec (struct breakpoint *b, char **s, | |
11413 | struct symtabs_and_lines *sals) | |
11414 | { | |
11415 | decode_linespec_default (b, s, sals); | |
11416 | } | |
11417 | ||
2060206e | 11418 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 11419 | |
983af33b SDJ |
11420 | /* The breakpoint_ops structure to be used on static tracepoints with |
11421 | markers (`-m'). */ | |
11422 | ||
11423 | static void | |
11424 | strace_marker_create_sals_from_address (char **arg, | |
11425 | struct linespec_result *canonical, | |
11426 | enum bptype type_wanted, | |
11427 | char *addr_start, char **copy_arg) | |
11428 | { | |
11429 | struct linespec_sals lsal; | |
11430 | ||
11431 | lsal.sals = decode_static_tracepoint_spec (arg); | |
11432 | ||
11433 | *copy_arg = savestring (addr_start, *arg - addr_start); | |
11434 | ||
11435 | canonical->addr_string = xstrdup (*copy_arg); | |
11436 | lsal.canonical = xstrdup (*copy_arg); | |
11437 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
11438 | } | |
11439 | ||
11440 | static void | |
11441 | strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, | |
11442 | struct linespec_result *canonical, | |
11443 | struct linespec_sals *lsal, | |
11444 | char *cond_string, | |
11445 | enum bptype type_wanted, | |
11446 | enum bpdisp disposition, | |
11447 | int thread, | |
11448 | int task, int ignore_count, | |
11449 | const struct breakpoint_ops *ops, | |
11450 | int from_tty, int enabled, | |
11451 | int internal) | |
11452 | { | |
11453 | int i; | |
11454 | ||
11455 | /* If the user is creating a static tracepoint by marker id | |
11456 | (strace -m MARKER_ID), then store the sals index, so that | |
11457 | breakpoint_re_set can try to match up which of the newly | |
11458 | found markers corresponds to this one, and, don't try to | |
11459 | expand multiple locations for each sal, given than SALS | |
11460 | already should contain all sals for MARKER_ID. */ | |
11461 | ||
11462 | for (i = 0; i < lsal->sals.nelts; ++i) | |
11463 | { | |
11464 | struct symtabs_and_lines expanded; | |
11465 | struct tracepoint *tp; | |
11466 | struct cleanup *old_chain; | |
11467 | char *addr_string; | |
11468 | ||
11469 | expanded.nelts = 1; | |
11470 | expanded.sals = &lsal->sals.sals[i]; | |
11471 | ||
11472 | addr_string = xstrdup (canonical->addr_string); | |
11473 | old_chain = make_cleanup (xfree, addr_string); | |
11474 | ||
11475 | tp = XCNEW (struct tracepoint); | |
11476 | init_breakpoint_sal (&tp->base, gdbarch, expanded, | |
11477 | addr_string, NULL, | |
11478 | cond_string, type_wanted, disposition, | |
11479 | thread, task, ignore_count, ops, | |
11480 | from_tty, enabled, internal, | |
11481 | canonical->special_display); | |
11482 | /* Given that its possible to have multiple markers with | |
11483 | the same string id, if the user is creating a static | |
11484 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
11485 | store the sals index, so that breakpoint_re_set can | |
11486 | try to match up which of the newly found markers | |
11487 | corresponds to this one */ | |
11488 | tp->static_trace_marker_id_idx = i; | |
11489 | ||
11490 | install_breakpoint (internal, &tp->base, 0); | |
11491 | ||
11492 | discard_cleanups (old_chain); | |
11493 | } | |
11494 | } | |
11495 | ||
11496 | static void | |
11497 | strace_marker_decode_linespec (struct breakpoint *b, char **s, | |
11498 | struct symtabs_and_lines *sals) | |
11499 | { | |
11500 | struct tracepoint *tp = (struct tracepoint *) b; | |
11501 | ||
11502 | *sals = decode_static_tracepoint_spec (s); | |
11503 | if (sals->nelts > tp->static_trace_marker_id_idx) | |
11504 | { | |
11505 | sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx]; | |
11506 | sals->nelts = 1; | |
11507 | } | |
11508 | else | |
11509 | error (_("marker %s not found"), tp->static_trace_marker_id); | |
11510 | } | |
11511 | ||
11512 | static struct breakpoint_ops strace_marker_breakpoint_ops; | |
11513 | ||
11514 | static int | |
11515 | strace_marker_p (struct breakpoint *b) | |
11516 | { | |
11517 | return b->ops == &strace_marker_breakpoint_ops; | |
11518 | } | |
11519 | ||
53a5351d | 11520 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 11521 | structures. */ |
c906108c SS |
11522 | |
11523 | void | |
fba45db2 | 11524 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 11525 | { |
52f0bd74 | 11526 | struct breakpoint *b; |
c906108c | 11527 | |
8a3fe4f8 | 11528 | gdb_assert (bpt != NULL); |
c906108c | 11529 | |
4a64f543 MS |
11530 | /* Has this bp already been deleted? This can happen because |
11531 | multiple lists can hold pointers to bp's. bpstat lists are | |
11532 | especial culprits. | |
11533 | ||
11534 | One example of this happening is a watchpoint's scope bp. When | |
11535 | the scope bp triggers, we notice that the watchpoint is out of | |
11536 | scope, and delete it. We also delete its scope bp. But the | |
11537 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
11538 | That bpstat is then checked for auto-deleting bp's, which are | |
11539 | deleted. | |
11540 | ||
11541 | A real solution to this problem might involve reference counts in | |
11542 | bp's, and/or giving them pointers back to their referencing | |
11543 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
11544 | storage when no more references were extent. A cheaper bandaid | |
11545 | was chosen. */ | |
c906108c SS |
11546 | if (bpt->type == bp_none) |
11547 | return; | |
11548 | ||
4a64f543 MS |
11549 | /* At least avoid this stale reference until the reference counting |
11550 | of breakpoints gets resolved. */ | |
d0fb5eae | 11551 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 11552 | { |
d0fb5eae | 11553 | struct breakpoint *related; |
3a5c3e22 | 11554 | struct watchpoint *w; |
d0fb5eae JK |
11555 | |
11556 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 11557 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 11558 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
11559 | w = (struct watchpoint *) bpt; |
11560 | else | |
11561 | w = NULL; | |
11562 | if (w != NULL) | |
11563 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
11564 | |
11565 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
11566 | for (related = bpt; related->related_breakpoint != bpt; | |
11567 | related = related->related_breakpoint); | |
11568 | related->related_breakpoint = bpt->related_breakpoint; | |
11569 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
11570 | } |
11571 | ||
a9634178 TJB |
11572 | /* watch_command_1 creates a watchpoint but only sets its number if |
11573 | update_watchpoint succeeds in creating its bp_locations. If there's | |
11574 | a problem in that process, we'll be asked to delete the half-created | |
11575 | watchpoint. In that case, don't announce the deletion. */ | |
11576 | if (bpt->number) | |
11577 | observer_notify_breakpoint_deleted (bpt); | |
c906108c | 11578 | |
c906108c SS |
11579 | if (breakpoint_chain == bpt) |
11580 | breakpoint_chain = bpt->next; | |
11581 | ||
c906108c SS |
11582 | ALL_BREAKPOINTS (b) |
11583 | if (b->next == bpt) | |
c5aa993b JM |
11584 | { |
11585 | b->next = bpt->next; | |
11586 | break; | |
11587 | } | |
c906108c | 11588 | |
f431efe5 PA |
11589 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
11590 | been freed. */ | |
11591 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 11592 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
11593 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
11594 | commands are associated with the bpstat; if we remove it here, | |
11595 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
11596 | event-top.c won't do anything, and temporary breakpoints with | |
11597 | commands won't work. */ | |
11598 | ||
11599 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
11600 | ||
4a64f543 MS |
11601 | /* Now that breakpoint is removed from breakpoint list, update the |
11602 | global location list. This will remove locations that used to | |
11603 | belong to this breakpoint. Do this before freeing the breakpoint | |
11604 | itself, since remove_breakpoint looks at location's owner. It | |
11605 | might be better design to have location completely | |
11606 | self-contained, but it's not the case now. */ | |
b60e7edf | 11607 | update_global_location_list (0); |
74960c60 | 11608 | |
348d480f | 11609 | bpt->ops->dtor (bpt); |
4a64f543 MS |
11610 | /* On the chance that someone will soon try again to delete this |
11611 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 11612 | bpt->type = bp_none; |
b8c9b27d | 11613 | xfree (bpt); |
c906108c SS |
11614 | } |
11615 | ||
4d6140d9 AC |
11616 | static void |
11617 | do_delete_breakpoint_cleanup (void *b) | |
11618 | { | |
11619 | delete_breakpoint (b); | |
11620 | } | |
11621 | ||
11622 | struct cleanup * | |
11623 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
11624 | { | |
11625 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
11626 | } | |
11627 | ||
51be5b68 PA |
11628 | /* Iterator function to call a user-provided callback function once |
11629 | for each of B and its related breakpoints. */ | |
11630 | ||
11631 | static void | |
11632 | iterate_over_related_breakpoints (struct breakpoint *b, | |
11633 | void (*function) (struct breakpoint *, | |
11634 | void *), | |
11635 | void *data) | |
11636 | { | |
11637 | struct breakpoint *related; | |
11638 | ||
11639 | related = b; | |
11640 | do | |
11641 | { | |
11642 | struct breakpoint *next; | |
11643 | ||
11644 | /* FUNCTION may delete RELATED. */ | |
11645 | next = related->related_breakpoint; | |
11646 | ||
11647 | if (next == related) | |
11648 | { | |
11649 | /* RELATED is the last ring entry. */ | |
11650 | function (related, data); | |
11651 | ||
11652 | /* FUNCTION may have deleted it, so we'd never reach back to | |
11653 | B. There's nothing left to do anyway, so just break | |
11654 | out. */ | |
11655 | break; | |
11656 | } | |
11657 | else | |
11658 | function (related, data); | |
11659 | ||
11660 | related = next; | |
11661 | } | |
11662 | while (related != b); | |
11663 | } | |
95a42b64 TT |
11664 | |
11665 | static void | |
11666 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
11667 | { | |
11668 | delete_breakpoint (b); | |
11669 | } | |
11670 | ||
51be5b68 PA |
11671 | /* A callback for map_breakpoint_numbers that calls |
11672 | delete_breakpoint. */ | |
11673 | ||
11674 | static void | |
11675 | do_map_delete_breakpoint (struct breakpoint *b, void *ignore) | |
11676 | { | |
11677 | iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL); | |
11678 | } | |
11679 | ||
c906108c | 11680 | void |
fba45db2 | 11681 | delete_command (char *arg, int from_tty) |
c906108c | 11682 | { |
35df4500 | 11683 | struct breakpoint *b, *b_tmp; |
c906108c | 11684 | |
ea9365bb TT |
11685 | dont_repeat (); |
11686 | ||
c906108c SS |
11687 | if (arg == 0) |
11688 | { | |
11689 | int breaks_to_delete = 0; | |
11690 | ||
46c6471b PA |
11691 | /* Delete all breakpoints if no argument. Do not delete |
11692 | internal breakpoints, these have to be deleted with an | |
11693 | explicit breakpoint number argument. */ | |
c5aa993b | 11694 | ALL_BREAKPOINTS (b) |
46c6471b | 11695 | if (user_breakpoint_p (b)) |
973d738b DJ |
11696 | { |
11697 | breaks_to_delete = 1; | |
11698 | break; | |
11699 | } | |
c906108c SS |
11700 | |
11701 | /* Ask user only if there are some breakpoints to delete. */ | |
11702 | if (!from_tty | |
e2e0b3e5 | 11703 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 11704 | { |
35df4500 | 11705 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 11706 | if (user_breakpoint_p (b)) |
c5aa993b | 11707 | delete_breakpoint (b); |
c906108c SS |
11708 | } |
11709 | } | |
11710 | else | |
51be5b68 | 11711 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
c906108c SS |
11712 | } |
11713 | ||
0d381245 VP |
11714 | static int |
11715 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 11716 | { |
0d381245 | 11717 | for (; loc; loc = loc->next) |
8645ff69 UW |
11718 | if (!loc->shlib_disabled |
11719 | && !loc->pspace->executing_startup) | |
0d381245 VP |
11720 | return 0; |
11721 | return 1; | |
fe3f5fa8 VP |
11722 | } |
11723 | ||
776592bf DE |
11724 | /* Subroutine of update_breakpoint_locations to simplify it. |
11725 | Return non-zero if multiple fns in list LOC have the same name. | |
11726 | Null names are ignored. */ | |
11727 | ||
11728 | static int | |
11729 | ambiguous_names_p (struct bp_location *loc) | |
11730 | { | |
11731 | struct bp_location *l; | |
11732 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
11733 | (int (*) (const void *, |
11734 | const void *)) streq, | |
776592bf DE |
11735 | NULL, xcalloc, xfree); |
11736 | ||
11737 | for (l = loc; l != NULL; l = l->next) | |
11738 | { | |
11739 | const char **slot; | |
11740 | const char *name = l->function_name; | |
11741 | ||
11742 | /* Allow for some names to be NULL, ignore them. */ | |
11743 | if (name == NULL) | |
11744 | continue; | |
11745 | ||
11746 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
11747 | INSERT); | |
4a64f543 MS |
11748 | /* NOTE: We can assume slot != NULL here because xcalloc never |
11749 | returns NULL. */ | |
776592bf DE |
11750 | if (*slot != NULL) |
11751 | { | |
11752 | htab_delete (htab); | |
11753 | return 1; | |
11754 | } | |
11755 | *slot = name; | |
11756 | } | |
11757 | ||
11758 | htab_delete (htab); | |
11759 | return 0; | |
11760 | } | |
11761 | ||
0fb4aa4b PA |
11762 | /* When symbols change, it probably means the sources changed as well, |
11763 | and it might mean the static tracepoint markers are no longer at | |
11764 | the same address or line numbers they used to be at last we | |
11765 | checked. Losing your static tracepoints whenever you rebuild is | |
11766 | undesirable. This function tries to resync/rematch gdb static | |
11767 | tracepoints with the markers on the target, for static tracepoints | |
11768 | that have not been set by marker id. Static tracepoint that have | |
11769 | been set by marker id are reset by marker id in breakpoint_re_set. | |
11770 | The heuristic is: | |
11771 | ||
11772 | 1) For a tracepoint set at a specific address, look for a marker at | |
11773 | the old PC. If one is found there, assume to be the same marker. | |
11774 | If the name / string id of the marker found is different from the | |
11775 | previous known name, assume that means the user renamed the marker | |
11776 | in the sources, and output a warning. | |
11777 | ||
11778 | 2) For a tracepoint set at a given line number, look for a marker | |
11779 | at the new address of the old line number. If one is found there, | |
11780 | assume to be the same marker. If the name / string id of the | |
11781 | marker found is different from the previous known name, assume that | |
11782 | means the user renamed the marker in the sources, and output a | |
11783 | warning. | |
11784 | ||
11785 | 3) If a marker is no longer found at the same address or line, it | |
11786 | may mean the marker no longer exists. But it may also just mean | |
11787 | the code changed a bit. Maybe the user added a few lines of code | |
11788 | that made the marker move up or down (in line number terms). Ask | |
11789 | the target for info about the marker with the string id as we knew | |
11790 | it. If found, update line number and address in the matching | |
11791 | static tracepoint. This will get confused if there's more than one | |
11792 | marker with the same ID (possible in UST, although unadvised | |
11793 | precisely because it confuses tools). */ | |
11794 | ||
11795 | static struct symtab_and_line | |
11796 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
11797 | { | |
d9b3f62e | 11798 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
11799 | struct static_tracepoint_marker marker; |
11800 | CORE_ADDR pc; | |
11801 | int i; | |
11802 | ||
11803 | pc = sal.pc; | |
11804 | if (sal.line) | |
11805 | find_line_pc (sal.symtab, sal.line, &pc); | |
11806 | ||
11807 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
11808 | { | |
d9b3f62e | 11809 | if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0) |
0fb4aa4b PA |
11810 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
11811 | b->number, | |
d9b3f62e | 11812 | tp->static_trace_marker_id, marker.str_id); |
0fb4aa4b | 11813 | |
d9b3f62e PA |
11814 | xfree (tp->static_trace_marker_id); |
11815 | tp->static_trace_marker_id = xstrdup (marker.str_id); | |
0fb4aa4b PA |
11816 | release_static_tracepoint_marker (&marker); |
11817 | ||
11818 | return sal; | |
11819 | } | |
11820 | ||
11821 | /* Old marker wasn't found on target at lineno. Try looking it up | |
11822 | by string ID. */ | |
11823 | if (!sal.explicit_pc | |
11824 | && sal.line != 0 | |
11825 | && sal.symtab != NULL | |
d9b3f62e | 11826 | && tp->static_trace_marker_id != NULL) |
0fb4aa4b PA |
11827 | { |
11828 | VEC(static_tracepoint_marker_p) *markers; | |
11829 | ||
11830 | markers | |
d9b3f62e | 11831 | = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id); |
0fb4aa4b PA |
11832 | |
11833 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
11834 | { | |
80e1d417 | 11835 | struct symtab_and_line sal2; |
0fb4aa4b | 11836 | struct symbol *sym; |
80e1d417 | 11837 | struct static_tracepoint_marker *tpmarker; |
79a45e25 | 11838 | struct ui_out *uiout = current_uiout; |
0fb4aa4b | 11839 | |
80e1d417 | 11840 | tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0); |
0fb4aa4b | 11841 | |
d9b3f62e | 11842 | xfree (tp->static_trace_marker_id); |
80e1d417 | 11843 | tp->static_trace_marker_id = xstrdup (tpmarker->str_id); |
0fb4aa4b PA |
11844 | |
11845 | warning (_("marker for static tracepoint %d (%s) not " | |
11846 | "found at previous line number"), | |
d9b3f62e | 11847 | b->number, tp->static_trace_marker_id); |
0fb4aa4b | 11848 | |
80e1d417 | 11849 | init_sal (&sal2); |
0fb4aa4b | 11850 | |
80e1d417 | 11851 | sal2.pc = tpmarker->address; |
0fb4aa4b | 11852 | |
80e1d417 AS |
11853 | sal2 = find_pc_line (tpmarker->address, 0); |
11854 | sym = find_pc_sect_function (tpmarker->address, NULL); | |
0fb4aa4b PA |
11855 | ui_out_text (uiout, "Now in "); |
11856 | if (sym) | |
11857 | { | |
11858 | ui_out_field_string (uiout, "func", | |
11859 | SYMBOL_PRINT_NAME (sym)); | |
11860 | ui_out_text (uiout, " at "); | |
11861 | } | |
80e1d417 | 11862 | ui_out_field_string (uiout, "file", sal2.symtab->filename); |
0fb4aa4b PA |
11863 | ui_out_text (uiout, ":"); |
11864 | ||
11865 | if (ui_out_is_mi_like_p (uiout)) | |
11866 | { | |
80e1d417 | 11867 | char *fullname = symtab_to_fullname (sal2.symtab); |
0fb4aa4b PA |
11868 | |
11869 | if (fullname) | |
11870 | ui_out_field_string (uiout, "fullname", fullname); | |
11871 | } | |
11872 | ||
80e1d417 | 11873 | ui_out_field_int (uiout, "line", sal2.line); |
0fb4aa4b PA |
11874 | ui_out_text (uiout, "\n"); |
11875 | ||
80e1d417 | 11876 | b->loc->line_number = sal2.line; |
0fb4aa4b | 11877 | |
f8eba3c6 | 11878 | xfree (b->loc->source_file); |
0fb4aa4b | 11879 | if (sym) |
80e1d417 | 11880 | b->loc->source_file = xstrdup (sal2.symtab->filename); |
0fb4aa4b | 11881 | else |
f8eba3c6 | 11882 | b->loc->source_file = NULL; |
0fb4aa4b PA |
11883 | |
11884 | xfree (b->addr_string); | |
11885 | b->addr_string = xstrprintf ("%s:%d", | |
80e1d417 | 11886 | sal2.symtab->filename, |
f8eba3c6 | 11887 | b->loc->line_number); |
0fb4aa4b PA |
11888 | |
11889 | /* Might be nice to check if function changed, and warn if | |
11890 | so. */ | |
11891 | ||
80e1d417 | 11892 | release_static_tracepoint_marker (tpmarker); |
0fb4aa4b PA |
11893 | } |
11894 | } | |
11895 | return sal; | |
11896 | } | |
11897 | ||
8d3788bd VP |
11898 | /* Returns 1 iff locations A and B are sufficiently same that |
11899 | we don't need to report breakpoint as changed. */ | |
11900 | ||
11901 | static int | |
11902 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
11903 | { | |
11904 | while (a && b) | |
11905 | { | |
11906 | if (a->address != b->address) | |
11907 | return 0; | |
11908 | ||
11909 | if (a->shlib_disabled != b->shlib_disabled) | |
11910 | return 0; | |
11911 | ||
11912 | if (a->enabled != b->enabled) | |
11913 | return 0; | |
11914 | ||
11915 | a = a->next; | |
11916 | b = b->next; | |
11917 | } | |
11918 | ||
11919 | if ((a == NULL) != (b == NULL)) | |
11920 | return 0; | |
11921 | ||
11922 | return 1; | |
11923 | } | |
11924 | ||
f1310107 TJB |
11925 | /* Create new breakpoint locations for B (a hardware or software breakpoint) |
11926 | based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is | |
11927 | a ranged breakpoint. */ | |
11928 | ||
0e30163f | 11929 | void |
0d381245 | 11930 | update_breakpoint_locations (struct breakpoint *b, |
f1310107 TJB |
11931 | struct symtabs_and_lines sals, |
11932 | struct symtabs_and_lines sals_end) | |
fe3f5fa8 VP |
11933 | { |
11934 | int i; | |
0d381245 VP |
11935 | struct bp_location *existing_locations = b->loc; |
11936 | ||
f8eba3c6 TT |
11937 | if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1)) |
11938 | { | |
11939 | /* Ranged breakpoints have only one start location and one end | |
11940 | location. */ | |
11941 | b->enable_state = bp_disabled; | |
11942 | update_global_location_list (1); | |
11943 | printf_unfiltered (_("Could not reset ranged breakpoint %d: " | |
11944 | "multiple locations found\n"), | |
11945 | b->number); | |
11946 | return; | |
11947 | } | |
f1310107 | 11948 | |
4a64f543 MS |
11949 | /* If there's no new locations, and all existing locations are |
11950 | pending, don't do anything. This optimizes the common case where | |
11951 | all locations are in the same shared library, that was unloaded. | |
11952 | We'd like to retain the location, so that when the library is | |
11953 | loaded again, we don't loose the enabled/disabled status of the | |
11954 | individual locations. */ | |
0d381245 | 11955 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) |
fe3f5fa8 VP |
11956 | return; |
11957 | ||
fe3f5fa8 VP |
11958 | b->loc = NULL; |
11959 | ||
0d381245 | 11960 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 11961 | { |
f8eba3c6 TT |
11962 | struct bp_location *new_loc; |
11963 | ||
11964 | switch_to_program_space_and_thread (sals.sals[i].pspace); | |
11965 | ||
11966 | new_loc = add_location_to_breakpoint (b, &(sals.sals[i])); | |
fe3f5fa8 | 11967 | |
0d381245 VP |
11968 | /* Reparse conditions, they might contain references to the |
11969 | old symtab. */ | |
11970 | if (b->cond_string != NULL) | |
11971 | { | |
f1310107 | 11972 | char *s; |
bfd189b1 | 11973 | volatile struct gdb_exception e; |
fe3f5fa8 | 11974 | |
0d381245 VP |
11975 | s = b->cond_string; |
11976 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
11977 | { | |
11978 | new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), | |
11979 | 0); | |
11980 | } | |
11981 | if (e.reason < 0) | |
11982 | { | |
3e43a32a MS |
11983 | warning (_("failed to reevaluate condition " |
11984 | "for breakpoint %d: %s"), | |
0d381245 VP |
11985 | b->number, e.message); |
11986 | new_loc->enabled = 0; | |
11987 | } | |
11988 | } | |
fe3f5fa8 | 11989 | |
f1310107 TJB |
11990 | if (sals_end.nelts) |
11991 | { | |
11992 | CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]); | |
11993 | ||
11994 | new_loc->length = end - sals.sals[0].pc + 1; | |
11995 | } | |
0d381245 | 11996 | } |
fe3f5fa8 | 11997 | |
514f746b AR |
11998 | /* Update locations of permanent breakpoints. */ |
11999 | if (b->enable_state == bp_permanent) | |
12000 | make_breakpoint_permanent (b); | |
12001 | ||
4a64f543 MS |
12002 | /* If possible, carry over 'disable' status from existing |
12003 | breakpoints. */ | |
0d381245 VP |
12004 | { |
12005 | struct bp_location *e = existing_locations; | |
776592bf DE |
12006 | /* If there are multiple breakpoints with the same function name, |
12007 | e.g. for inline functions, comparing function names won't work. | |
12008 | Instead compare pc addresses; this is just a heuristic as things | |
12009 | may have moved, but in practice it gives the correct answer | |
12010 | often enough until a better solution is found. */ | |
12011 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
12012 | ||
0d381245 VP |
12013 | for (; e; e = e->next) |
12014 | { | |
12015 | if (!e->enabled && e->function_name) | |
12016 | { | |
12017 | struct bp_location *l = b->loc; | |
776592bf DE |
12018 | if (have_ambiguous_names) |
12019 | { | |
12020 | for (; l; l = l->next) | |
f1310107 | 12021 | if (breakpoint_locations_match (e, l)) |
776592bf DE |
12022 | { |
12023 | l->enabled = 0; | |
12024 | break; | |
12025 | } | |
12026 | } | |
12027 | else | |
12028 | { | |
12029 | for (; l; l = l->next) | |
12030 | if (l->function_name | |
12031 | && strcmp (e->function_name, l->function_name) == 0) | |
12032 | { | |
12033 | l->enabled = 0; | |
12034 | break; | |
12035 | } | |
12036 | } | |
0d381245 VP |
12037 | } |
12038 | } | |
12039 | } | |
fe3f5fa8 | 12040 | |
8d3788bd VP |
12041 | if (!locations_are_equal (existing_locations, b->loc)) |
12042 | observer_notify_breakpoint_modified (b); | |
12043 | ||
b60e7edf | 12044 | update_global_location_list (1); |
fe3f5fa8 VP |
12045 | } |
12046 | ||
ef23e705 TJB |
12047 | /* Find the SaL locations corresponding to the given ADDR_STRING. |
12048 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ | |
12049 | ||
12050 | static struct symtabs_and_lines | |
12051 | addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found) | |
12052 | { | |
12053 | char *s; | |
02d20e4a | 12054 | struct symtabs_and_lines sals = {0}; |
f8eba3c6 | 12055 | volatile struct gdb_exception e; |
ef23e705 | 12056 | |
983af33b | 12057 | gdb_assert (b->ops != NULL); |
ef23e705 | 12058 | s = addr_string; |
ef23e705 TJB |
12059 | |
12060 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
12061 | { | |
983af33b | 12062 | b->ops->decode_linespec (b, &s, &sals); |
ef23e705 TJB |
12063 | } |
12064 | if (e.reason < 0) | |
12065 | { | |
12066 | int not_found_and_ok = 0; | |
12067 | /* For pending breakpoints, it's expected that parsing will | |
12068 | fail until the right shared library is loaded. User has | |
12069 | already told to create pending breakpoints and don't need | |
12070 | extra messages. If breakpoint is in bp_shlib_disabled | |
12071 | state, then user already saw the message about that | |
12072 | breakpoint being disabled, and don't want to see more | |
12073 | errors. */ | |
58438ac1 | 12074 | if (e.error == NOT_FOUND_ERROR |
ef23e705 TJB |
12075 | && (b->condition_not_parsed |
12076 | || (b->loc && b->loc->shlib_disabled) | |
f8eba3c6 | 12077 | || (b->loc && b->loc->pspace->executing_startup) |
ef23e705 TJB |
12078 | || b->enable_state == bp_disabled)) |
12079 | not_found_and_ok = 1; | |
12080 | ||
12081 | if (!not_found_and_ok) | |
12082 | { | |
12083 | /* We surely don't want to warn about the same breakpoint | |
12084 | 10 times. One solution, implemented here, is disable | |
12085 | the breakpoint on error. Another solution would be to | |
12086 | have separate 'warning emitted' flag. Since this | |
12087 | happens only when a binary has changed, I don't know | |
12088 | which approach is better. */ | |
12089 | b->enable_state = bp_disabled; | |
12090 | throw_exception (e); | |
12091 | } | |
12092 | } | |
12093 | ||
58438ac1 | 12094 | if (e.reason == 0 || e.error != NOT_FOUND_ERROR) |
ef23e705 | 12095 | { |
f8eba3c6 | 12096 | int i; |
ef23e705 | 12097 | |
f8eba3c6 TT |
12098 | for (i = 0; i < sals.nelts; ++i) |
12099 | resolve_sal_pc (&sals.sals[i]); | |
ef23e705 TJB |
12100 | if (b->condition_not_parsed && s && s[0]) |
12101 | { | |
12102 | char *cond_string = 0; | |
12103 | int thread = -1; | |
12104 | int task = 0; | |
12105 | ||
12106 | find_condition_and_thread (s, sals.sals[0].pc, | |
12107 | &cond_string, &thread, &task); | |
12108 | if (cond_string) | |
12109 | b->cond_string = cond_string; | |
12110 | b->thread = thread; | |
12111 | b->task = task; | |
12112 | b->condition_not_parsed = 0; | |
12113 | } | |
12114 | ||
983af33b | 12115 | if (b->type == bp_static_tracepoint && !strace_marker_p (b)) |
ef23e705 | 12116 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); |
ef23e705 | 12117 | |
58438ac1 TT |
12118 | *found = 1; |
12119 | } | |
12120 | else | |
12121 | *found = 0; | |
ef23e705 TJB |
12122 | |
12123 | return sals; | |
12124 | } | |
12125 | ||
348d480f PA |
12126 | /* The default re_set method, for typical hardware or software |
12127 | breakpoints. Reevaluate the breakpoint and recreate its | |
12128 | locations. */ | |
12129 | ||
12130 | static void | |
28010a5d | 12131 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 TJB |
12132 | { |
12133 | int found; | |
f1310107 | 12134 | struct symtabs_and_lines sals, sals_end; |
ef23e705 | 12135 | struct symtabs_and_lines expanded = {0}; |
f1310107 | 12136 | struct symtabs_and_lines expanded_end = {0}; |
ef23e705 TJB |
12137 | |
12138 | sals = addr_string_to_sals (b, b->addr_string, &found); | |
12139 | if (found) | |
12140 | { | |
12141 | make_cleanup (xfree, sals.sals); | |
f8eba3c6 | 12142 | expanded = sals; |
ef23e705 TJB |
12143 | } |
12144 | ||
f1310107 TJB |
12145 | if (b->addr_string_range_end) |
12146 | { | |
12147 | sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found); | |
12148 | if (found) | |
12149 | { | |
12150 | make_cleanup (xfree, sals_end.sals); | |
f8eba3c6 | 12151 | expanded_end = sals_end; |
f1310107 TJB |
12152 | } |
12153 | } | |
12154 | ||
12155 | update_breakpoint_locations (b, expanded, expanded_end); | |
28010a5d PA |
12156 | } |
12157 | ||
983af33b SDJ |
12158 | /* Default method for creating SALs from an address string. It basically |
12159 | calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ | |
12160 | ||
12161 | static void | |
12162 | create_sals_from_address_default (char **arg, | |
12163 | struct linespec_result *canonical, | |
12164 | enum bptype type_wanted, | |
12165 | char *addr_start, char **copy_arg) | |
12166 | { | |
12167 | parse_breakpoint_sals (arg, canonical); | |
12168 | } | |
12169 | ||
12170 | /* Call create_breakpoints_sal for the given arguments. This is the default | |
12171 | function for the `create_breakpoints_sal' method of | |
12172 | breakpoint_ops. */ | |
12173 | ||
12174 | static void | |
12175 | create_breakpoints_sal_default (struct gdbarch *gdbarch, | |
12176 | struct linespec_result *canonical, | |
12177 | struct linespec_sals *lsal, | |
12178 | char *cond_string, | |
12179 | enum bptype type_wanted, | |
12180 | enum bpdisp disposition, | |
12181 | int thread, | |
12182 | int task, int ignore_count, | |
12183 | const struct breakpoint_ops *ops, | |
12184 | int from_tty, int enabled, | |
12185 | int internal) | |
12186 | { | |
12187 | create_breakpoints_sal (gdbarch, canonical, cond_string, | |
12188 | type_wanted, disposition, | |
12189 | thread, task, ignore_count, ops, from_tty, | |
12190 | enabled, internal); | |
12191 | } | |
12192 | ||
12193 | /* Decode the line represented by S by calling decode_line_full. This is the | |
12194 | default function for the `decode_linespec' method of breakpoint_ops. */ | |
12195 | ||
12196 | static void | |
12197 | decode_linespec_default (struct breakpoint *b, char **s, | |
12198 | struct symtabs_and_lines *sals) | |
12199 | { | |
12200 | struct linespec_result canonical; | |
12201 | ||
12202 | init_linespec_result (&canonical); | |
12203 | decode_line_full (s, DECODE_LINE_FUNFIRSTLINE, | |
12204 | (struct symtab *) NULL, 0, | |
12205 | &canonical, multiple_symbols_all, | |
12206 | b->filter); | |
12207 | ||
12208 | /* We should get 0 or 1 resulting SALs. */ | |
12209 | gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2); | |
12210 | ||
12211 | if (VEC_length (linespec_sals, canonical.sals) > 0) | |
12212 | { | |
12213 | struct linespec_sals *lsal; | |
12214 | ||
12215 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
12216 | *sals = lsal->sals; | |
12217 | /* Arrange it so the destructor does not free the | |
12218 | contents. */ | |
12219 | lsal->sals.sals = NULL; | |
12220 | } | |
12221 | ||
12222 | destroy_linespec_result (&canonical); | |
12223 | } | |
12224 | ||
28010a5d PA |
12225 | /* Prepare the global context for a re-set of breakpoint B. */ |
12226 | ||
12227 | static struct cleanup * | |
12228 | prepare_re_set_context (struct breakpoint *b) | |
12229 | { | |
12230 | struct cleanup *cleanups; | |
12231 | ||
12232 | input_radix = b->input_radix; | |
12233 | cleanups = save_current_space_and_thread (); | |
f8eba3c6 TT |
12234 | if (b->pspace != NULL) |
12235 | switch_to_program_space_and_thread (b->pspace); | |
28010a5d PA |
12236 | set_language (b->language); |
12237 | ||
12238 | return cleanups; | |
ef23e705 TJB |
12239 | } |
12240 | ||
c906108c SS |
12241 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
12242 | The value we return ends up being the return value from catch_errors. | |
12243 | Unused in this case. */ | |
12244 | ||
12245 | static int | |
4efb68b1 | 12246 | breakpoint_re_set_one (void *bint) |
c906108c | 12247 | { |
4a64f543 | 12248 | /* Get past catch_errs. */ |
53a5351d | 12249 | struct breakpoint *b = (struct breakpoint *) bint; |
348d480f | 12250 | struct cleanup *cleanups; |
c906108c | 12251 | |
348d480f PA |
12252 | cleanups = prepare_re_set_context (b); |
12253 | b->ops->re_set (b); | |
12254 | do_cleanups (cleanups); | |
c906108c SS |
12255 | return 0; |
12256 | } | |
12257 | ||
69de3c6a | 12258 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 12259 | void |
69de3c6a | 12260 | breakpoint_re_set (void) |
c906108c | 12261 | { |
35df4500 | 12262 | struct breakpoint *b, *b_tmp; |
c906108c SS |
12263 | enum language save_language; |
12264 | int save_input_radix; | |
6c95b8df | 12265 | struct cleanup *old_chain; |
c5aa993b | 12266 | |
c906108c SS |
12267 | save_language = current_language->la_language; |
12268 | save_input_radix = input_radix; | |
6c95b8df PA |
12269 | old_chain = save_current_program_space (); |
12270 | ||
35df4500 | 12271 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 12272 | { |
4a64f543 | 12273 | /* Format possible error msg. */ |
fe3f5fa8 | 12274 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
12275 | b->number); |
12276 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 12277 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 12278 | do_cleanups (cleanups); |
c5aa993b | 12279 | } |
c906108c SS |
12280 | set_language (save_language); |
12281 | input_radix = save_input_radix; | |
e62c965a | 12282 | |
0756c555 | 12283 | jit_breakpoint_re_set (); |
4efc6507 | 12284 | |
6c95b8df PA |
12285 | do_cleanups (old_chain); |
12286 | ||
af02033e PP |
12287 | create_overlay_event_breakpoint (); |
12288 | create_longjmp_master_breakpoint (); | |
12289 | create_std_terminate_master_breakpoint (); | |
186c406b | 12290 | create_exception_master_breakpoint (); |
1bfeeb0f JL |
12291 | |
12292 | /* While we're at it, reset the skip list too. */ | |
12293 | skip_re_set (); | |
c906108c SS |
12294 | } |
12295 | \f | |
c906108c SS |
12296 | /* Reset the thread number of this breakpoint: |
12297 | ||
12298 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 12299 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 12300 | void |
fba45db2 | 12301 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
12302 | { |
12303 | if (b->thread != -1) | |
12304 | { | |
39f77062 KB |
12305 | if (in_thread_list (inferior_ptid)) |
12306 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
12307 | |
12308 | /* We're being called after following a fork. The new fork is | |
12309 | selected as current, and unless this was a vfork will have a | |
12310 | different program space from the original thread. Reset that | |
12311 | as well. */ | |
12312 | b->loc->pspace = current_program_space; | |
c906108c SS |
12313 | } |
12314 | } | |
12315 | ||
03ac34d5 MS |
12316 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
12317 | If from_tty is nonzero, it prints a message to that effect, | |
12318 | which ends with a period (no newline). */ | |
12319 | ||
c906108c | 12320 | void |
fba45db2 | 12321 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 12322 | { |
52f0bd74 | 12323 | struct breakpoint *b; |
c906108c SS |
12324 | |
12325 | if (count < 0) | |
12326 | count = 0; | |
12327 | ||
12328 | ALL_BREAKPOINTS (b) | |
12329 | if (b->number == bptnum) | |
c5aa993b | 12330 | { |
d77f58be SS |
12331 | if (is_tracepoint (b)) |
12332 | { | |
12333 | if (from_tty && count != 0) | |
12334 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
12335 | bptnum); | |
12336 | return; | |
12337 | } | |
12338 | ||
c5aa993b | 12339 | b->ignore_count = count; |
221ea385 KS |
12340 | if (from_tty) |
12341 | { | |
12342 | if (count == 0) | |
3e43a32a MS |
12343 | printf_filtered (_("Will stop next time " |
12344 | "breakpoint %d is reached."), | |
221ea385 KS |
12345 | bptnum); |
12346 | else if (count == 1) | |
a3f17187 | 12347 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
12348 | bptnum); |
12349 | else | |
3e43a32a MS |
12350 | printf_filtered (_("Will ignore next %d " |
12351 | "crossings of breakpoint %d."), | |
221ea385 KS |
12352 | count, bptnum); |
12353 | } | |
c5aa993b | 12354 | breakpoints_changed (); |
8d3788bd | 12355 | observer_notify_breakpoint_modified (b); |
c5aa993b JM |
12356 | return; |
12357 | } | |
c906108c | 12358 | |
8a3fe4f8 | 12359 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
12360 | } |
12361 | ||
c906108c SS |
12362 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
12363 | ||
12364 | static void | |
fba45db2 | 12365 | ignore_command (char *args, int from_tty) |
c906108c SS |
12366 | { |
12367 | char *p = args; | |
52f0bd74 | 12368 | int num; |
c906108c SS |
12369 | |
12370 | if (p == 0) | |
e2e0b3e5 | 12371 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 12372 | |
c906108c | 12373 | num = get_number (&p); |
5c44784c | 12374 | if (num == 0) |
8a3fe4f8 | 12375 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 12376 | if (*p == 0) |
8a3fe4f8 | 12377 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
12378 | |
12379 | set_ignore_count (num, | |
12380 | longest_to_int (value_as_long (parse_and_eval (p))), | |
12381 | from_tty); | |
221ea385 KS |
12382 | if (from_tty) |
12383 | printf_filtered ("\n"); | |
c906108c SS |
12384 | } |
12385 | \f | |
12386 | /* Call FUNCTION on each of the breakpoints | |
12387 | whose numbers are given in ARGS. */ | |
12388 | ||
12389 | static void | |
95a42b64 TT |
12390 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
12391 | void *), | |
12392 | void *data) | |
c906108c | 12393 | { |
52f0bd74 AC |
12394 | int num; |
12395 | struct breakpoint *b, *tmp; | |
11cf8741 | 12396 | int match; |
197f0a60 | 12397 | struct get_number_or_range_state state; |
c906108c | 12398 | |
197f0a60 | 12399 | if (args == 0) |
e2e0b3e5 | 12400 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c | 12401 | |
197f0a60 TT |
12402 | init_number_or_range (&state, args); |
12403 | ||
12404 | while (!state.finished) | |
c906108c | 12405 | { |
197f0a60 TT |
12406 | char *p = state.string; |
12407 | ||
11cf8741 | 12408 | match = 0; |
c5aa993b | 12409 | |
197f0a60 | 12410 | num = get_number_or_range (&state); |
5c44784c | 12411 | if (num == 0) |
c5aa993b | 12412 | { |
8a3fe4f8 | 12413 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
12414 | } |
12415 | else | |
12416 | { | |
12417 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
12418 | if (b->number == num) | |
12419 | { | |
11cf8741 | 12420 | match = 1; |
cdac0397 | 12421 | function (b, data); |
11cf8741 | 12422 | break; |
5c44784c | 12423 | } |
11cf8741 | 12424 | if (match == 0) |
a3f17187 | 12425 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 12426 | } |
c906108c SS |
12427 | } |
12428 | } | |
12429 | ||
0d381245 VP |
12430 | static struct bp_location * |
12431 | find_location_by_number (char *number) | |
12432 | { | |
12433 | char *dot = strchr (number, '.'); | |
12434 | char *p1; | |
12435 | int bp_num; | |
12436 | int loc_num; | |
12437 | struct breakpoint *b; | |
12438 | struct bp_location *loc; | |
12439 | ||
12440 | *dot = '\0'; | |
12441 | ||
12442 | p1 = number; | |
197f0a60 | 12443 | bp_num = get_number (&p1); |
0d381245 VP |
12444 | if (bp_num == 0) |
12445 | error (_("Bad breakpoint number '%s'"), number); | |
12446 | ||
12447 | ALL_BREAKPOINTS (b) | |
12448 | if (b->number == bp_num) | |
12449 | { | |
12450 | break; | |
12451 | } | |
12452 | ||
12453 | if (!b || b->number != bp_num) | |
12454 | error (_("Bad breakpoint number '%s'"), number); | |
12455 | ||
12456 | p1 = dot+1; | |
197f0a60 | 12457 | loc_num = get_number (&p1); |
0d381245 VP |
12458 | if (loc_num == 0) |
12459 | error (_("Bad breakpoint location number '%s'"), number); | |
12460 | ||
12461 | --loc_num; | |
12462 | loc = b->loc; | |
12463 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
12464 | ; | |
12465 | if (!loc) | |
12466 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
12467 | ||
12468 | return loc; | |
12469 | } | |
12470 | ||
12471 | ||
1900040c MS |
12472 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
12473 | If from_tty is nonzero, it prints a message to that effect, | |
12474 | which ends with a period (no newline). */ | |
12475 | ||
c906108c | 12476 | void |
fba45db2 | 12477 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
12478 | { |
12479 | /* Never disable a watchpoint scope breakpoint; we want to | |
12480 | hit them when we leave scope so we can delete both the | |
12481 | watchpoint and its scope breakpoint at that time. */ | |
12482 | if (bpt->type == bp_watchpoint_scope) | |
12483 | return; | |
12484 | ||
c2c6d25f | 12485 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 12486 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
12487 | return; |
12488 | ||
b5de0fa7 | 12489 | bpt->enable_state = bp_disabled; |
c906108c | 12490 | |
d248b706 KY |
12491 | if (target_supports_enable_disable_tracepoint () |
12492 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
12493 | { | |
12494 | struct bp_location *location; | |
12495 | ||
12496 | for (location = bpt->loc; location; location = location->next) | |
12497 | target_disable_tracepoint (location); | |
12498 | } | |
12499 | ||
b60e7edf | 12500 | update_global_location_list (0); |
c906108c | 12501 | |
8d3788bd | 12502 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
12503 | } |
12504 | ||
51be5b68 PA |
12505 | /* A callback for iterate_over_related_breakpoints. */ |
12506 | ||
12507 | static void | |
12508 | do_disable_breakpoint (struct breakpoint *b, void *ignore) | |
12509 | { | |
12510 | disable_breakpoint (b); | |
12511 | } | |
12512 | ||
95a42b64 TT |
12513 | /* A callback for map_breakpoint_numbers that calls |
12514 | disable_breakpoint. */ | |
12515 | ||
12516 | static void | |
12517 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
12518 | { | |
51be5b68 | 12519 | iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL); |
95a42b64 TT |
12520 | } |
12521 | ||
c906108c | 12522 | static void |
fba45db2 | 12523 | disable_command (char *args, int from_tty) |
c906108c | 12524 | { |
c906108c | 12525 | if (args == 0) |
46c6471b PA |
12526 | { |
12527 | struct breakpoint *bpt; | |
12528 | ||
12529 | ALL_BREAKPOINTS (bpt) | |
12530 | if (user_breakpoint_p (bpt)) | |
12531 | disable_breakpoint (bpt); | |
12532 | } | |
0d381245 VP |
12533 | else if (strchr (args, '.')) |
12534 | { | |
12535 | struct bp_location *loc = find_location_by_number (args); | |
12536 | if (loc) | |
d248b706 KY |
12537 | { |
12538 | loc->enabled = 0; | |
12539 | if (target_supports_enable_disable_tracepoint () | |
12540 | && current_trace_status ()->running && loc->owner | |
12541 | && is_tracepoint (loc->owner)) | |
12542 | target_disable_tracepoint (loc); | |
12543 | } | |
b60e7edf | 12544 | update_global_location_list (0); |
0d381245 | 12545 | } |
c906108c | 12546 | else |
95a42b64 | 12547 | map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL); |
c906108c SS |
12548 | } |
12549 | ||
12550 | static void | |
51be5b68 | 12551 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition) |
c906108c | 12552 | { |
afe38095 | 12553 | int target_resources_ok; |
c906108c SS |
12554 | |
12555 | if (bpt->type == bp_hardware_breakpoint) | |
12556 | { | |
12557 | int i; | |
c5aa993b | 12558 | i = hw_breakpoint_used_count (); |
53a5351d | 12559 | target_resources_ok = |
d92524f1 | 12560 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 12561 | i + 1, 0); |
c906108c | 12562 | if (target_resources_ok == 0) |
8a3fe4f8 | 12563 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 12564 | else if (target_resources_ok < 0) |
8a3fe4f8 | 12565 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
12566 | } |
12567 | ||
cc60f2e3 | 12568 | if (is_watchpoint (bpt)) |
c906108c | 12569 | { |
d07205c2 JK |
12570 | /* Initialize it just to avoid a GCC false warning. */ |
12571 | enum enable_state orig_enable_state = 0; | |
bfd189b1 | 12572 | volatile struct gdb_exception e; |
dde02812 ES |
12573 | |
12574 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 12575 | { |
3a5c3e22 PA |
12576 | struct watchpoint *w = (struct watchpoint *) bpt; |
12577 | ||
1e718ff1 TJB |
12578 | orig_enable_state = bpt->enable_state; |
12579 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 12580 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 12581 | } |
dde02812 | 12582 | if (e.reason < 0) |
c5aa993b | 12583 | { |
1e718ff1 | 12584 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
12585 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
12586 | bpt->number); | |
12587 | return; | |
c5aa993b | 12588 | } |
c906108c | 12589 | } |
0101ce28 | 12590 | |
b4c291bb KH |
12591 | if (bpt->enable_state != bp_permanent) |
12592 | bpt->enable_state = bp_enabled; | |
d248b706 KY |
12593 | |
12594 | if (target_supports_enable_disable_tracepoint () | |
12595 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
12596 | { | |
12597 | struct bp_location *location; | |
12598 | ||
12599 | for (location = bpt->loc; location; location = location->next) | |
12600 | target_enable_tracepoint (location); | |
12601 | } | |
12602 | ||
b4c291bb | 12603 | bpt->disposition = disposition; |
b60e7edf | 12604 | update_global_location_list (1); |
b4c291bb KH |
12605 | breakpoints_changed (); |
12606 | ||
8d3788bd | 12607 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
12608 | } |
12609 | ||
fe3f5fa8 | 12610 | |
c906108c | 12611 | void |
fba45db2 | 12612 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 12613 | { |
51be5b68 PA |
12614 | enable_breakpoint_disp (bpt, bpt->disposition); |
12615 | } | |
12616 | ||
12617 | static void | |
12618 | do_enable_breakpoint (struct breakpoint *bpt, void *arg) | |
12619 | { | |
12620 | enable_breakpoint (bpt); | |
c906108c SS |
12621 | } |
12622 | ||
95a42b64 TT |
12623 | /* A callback for map_breakpoint_numbers that calls |
12624 | enable_breakpoint. */ | |
12625 | ||
12626 | static void | |
12627 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
12628 | { | |
51be5b68 | 12629 | iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL); |
95a42b64 TT |
12630 | } |
12631 | ||
c906108c SS |
12632 | /* The enable command enables the specified breakpoints (or all defined |
12633 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 12634 | in stopping the inferior. */ |
c906108c | 12635 | |
c906108c | 12636 | static void |
fba45db2 | 12637 | enable_command (char *args, int from_tty) |
c906108c | 12638 | { |
c906108c | 12639 | if (args == 0) |
46c6471b PA |
12640 | { |
12641 | struct breakpoint *bpt; | |
12642 | ||
12643 | ALL_BREAKPOINTS (bpt) | |
12644 | if (user_breakpoint_p (bpt)) | |
12645 | enable_breakpoint (bpt); | |
12646 | } | |
0d381245 VP |
12647 | else if (strchr (args, '.')) |
12648 | { | |
12649 | struct bp_location *loc = find_location_by_number (args); | |
12650 | if (loc) | |
d248b706 KY |
12651 | { |
12652 | loc->enabled = 1; | |
12653 | if (target_supports_enable_disable_tracepoint () | |
12654 | && current_trace_status ()->running && loc->owner | |
12655 | && is_tracepoint (loc->owner)) | |
12656 | target_enable_tracepoint (loc); | |
12657 | } | |
b60e7edf | 12658 | update_global_location_list (1); |
0d381245 | 12659 | } |
c906108c | 12660 | else |
95a42b64 | 12661 | map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL); |
c906108c SS |
12662 | } |
12663 | ||
12664 | static void | |
51be5b68 PA |
12665 | do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg) |
12666 | { | |
12667 | enum bpdisp disp = *(enum bpdisp *) arg; | |
12668 | ||
12669 | enable_breakpoint_disp (bpt, disp); | |
12670 | } | |
12671 | ||
12672 | static void | |
12673 | do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore) | |
c906108c | 12674 | { |
51be5b68 PA |
12675 | enum bpdisp disp = disp_disable; |
12676 | ||
12677 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
12678 | } |
12679 | ||
c906108c | 12680 | static void |
fba45db2 | 12681 | enable_once_command (char *args, int from_tty) |
c906108c | 12682 | { |
51be5b68 | 12683 | map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL); |
c906108c SS |
12684 | } |
12685 | ||
12686 | static void | |
51be5b68 | 12687 | do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 12688 | { |
51be5b68 PA |
12689 | enum bpdisp disp = disp_del; |
12690 | ||
12691 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
12692 | } |
12693 | ||
c906108c | 12694 | static void |
fba45db2 | 12695 | enable_delete_command (char *args, int from_tty) |
c906108c | 12696 | { |
51be5b68 | 12697 | map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL); |
c906108c SS |
12698 | } |
12699 | \f | |
fa8d40ab JJ |
12700 | static void |
12701 | set_breakpoint_cmd (char *args, int from_tty) | |
12702 | { | |
12703 | } | |
12704 | ||
12705 | static void | |
12706 | show_breakpoint_cmd (char *args, int from_tty) | |
12707 | { | |
12708 | } | |
12709 | ||
1f3b5d1b PP |
12710 | /* Invalidate last known value of any hardware watchpoint if |
12711 | the memory which that value represents has been written to by | |
12712 | GDB itself. */ | |
12713 | ||
12714 | static void | |
12715 | invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len, | |
12716 | const bfd_byte *data) | |
12717 | { | |
12718 | struct breakpoint *bp; | |
12719 | ||
12720 | ALL_BREAKPOINTS (bp) | |
12721 | if (bp->enable_state == bp_enabled | |
3a5c3e22 | 12722 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 12723 | { |
3a5c3e22 | 12724 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 12725 | |
3a5c3e22 PA |
12726 | if (wp->val_valid && wp->val) |
12727 | { | |
12728 | struct bp_location *loc; | |
12729 | ||
12730 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
12731 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
12732 | && loc->address + loc->length > addr | |
12733 | && addr + len > loc->address) | |
12734 | { | |
12735 | value_free (wp->val); | |
12736 | wp->val = NULL; | |
12737 | wp->val_valid = 0; | |
12738 | } | |
12739 | } | |
1f3b5d1b PP |
12740 | } |
12741 | } | |
12742 | ||
1bfeeb0f JL |
12743 | /* Use the last displayed codepoint's values, or nothing |
12744 | if they aren't valid. */ | |
c906108c SS |
12745 | |
12746 | struct symtabs_and_lines | |
f8eba3c6 | 12747 | decode_line_spec_1 (char *string, int flags) |
c906108c SS |
12748 | { |
12749 | struct symtabs_and_lines sals; | |
cc59ec59 | 12750 | |
c906108c | 12751 | if (string == 0) |
8a3fe4f8 | 12752 | error (_("Empty line specification.")); |
1bfeeb0f | 12753 | if (last_displayed_sal_is_valid ()) |
f8eba3c6 | 12754 | sals = decode_line_1 (&string, flags, |
1bfeeb0f | 12755 | get_last_displayed_symtab (), |
f8eba3c6 | 12756 | get_last_displayed_line ()); |
c906108c | 12757 | else |
f8eba3c6 | 12758 | sals = decode_line_1 (&string, flags, (struct symtab *) NULL, 0); |
c906108c | 12759 | if (*string) |
8a3fe4f8 | 12760 | error (_("Junk at end of line specification: %s"), string); |
c906108c SS |
12761 | return sals; |
12762 | } | |
8181d85f DJ |
12763 | |
12764 | /* Create and insert a raw software breakpoint at PC. Return an | |
12765 | identifier, which should be used to remove the breakpoint later. | |
12766 | In general, places which call this should be using something on the | |
12767 | breakpoint chain instead; this function should be eliminated | |
12768 | someday. */ | |
12769 | ||
12770 | void * | |
6c95b8df PA |
12771 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, |
12772 | struct address_space *aspace, CORE_ADDR pc) | |
8181d85f DJ |
12773 | { |
12774 | struct bp_target_info *bp_tgt; | |
12775 | ||
6c95b8df | 12776 | bp_tgt = XZALLOC (struct bp_target_info); |
8181d85f | 12777 | |
6c95b8df | 12778 | bp_tgt->placed_address_space = aspace; |
8181d85f | 12779 | bp_tgt->placed_address = pc; |
6c95b8df | 12780 | |
a6d9a66e | 12781 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
8181d85f DJ |
12782 | { |
12783 | /* Could not insert the breakpoint. */ | |
12784 | xfree (bp_tgt); | |
12785 | return NULL; | |
12786 | } | |
12787 | ||
12788 | return bp_tgt; | |
12789 | } | |
12790 | ||
4a64f543 MS |
12791 | /* Remove a breakpoint BP inserted by |
12792 | deprecated_insert_raw_breakpoint. */ | |
8181d85f DJ |
12793 | |
12794 | int | |
a6d9a66e | 12795 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
8181d85f DJ |
12796 | { |
12797 | struct bp_target_info *bp_tgt = bp; | |
12798 | int ret; | |
12799 | ||
a6d9a66e | 12800 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
8181d85f DJ |
12801 | xfree (bp_tgt); |
12802 | ||
12803 | return ret; | |
12804 | } | |
12805 | ||
4a64f543 MS |
12806 | /* One (or perhaps two) breakpoints used for software single |
12807 | stepping. */ | |
8181d85f DJ |
12808 | |
12809 | static void *single_step_breakpoints[2]; | |
a6d9a66e | 12810 | static struct gdbarch *single_step_gdbarch[2]; |
8181d85f DJ |
12811 | |
12812 | /* Create and insert a breakpoint for software single step. */ | |
12813 | ||
12814 | void | |
6c95b8df | 12815 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
12816 | struct address_space *aspace, |
12817 | CORE_ADDR next_pc) | |
8181d85f DJ |
12818 | { |
12819 | void **bpt_p; | |
12820 | ||
12821 | if (single_step_breakpoints[0] == NULL) | |
a6d9a66e UW |
12822 | { |
12823 | bpt_p = &single_step_breakpoints[0]; | |
12824 | single_step_gdbarch[0] = gdbarch; | |
12825 | } | |
8181d85f DJ |
12826 | else |
12827 | { | |
12828 | gdb_assert (single_step_breakpoints[1] == NULL); | |
12829 | bpt_p = &single_step_breakpoints[1]; | |
a6d9a66e | 12830 | single_step_gdbarch[1] = gdbarch; |
8181d85f DJ |
12831 | } |
12832 | ||
4a64f543 MS |
12833 | /* NOTE drow/2006-04-11: A future improvement to this function would |
12834 | be to only create the breakpoints once, and actually put them on | |
12835 | the breakpoint chain. That would let us use set_raw_breakpoint. | |
12836 | We could adjust the addresses each time they were needed. Doing | |
12837 | this requires corresponding changes elsewhere where single step | |
12838 | breakpoints are handled, however. So, for now, we use this. */ | |
8181d85f | 12839 | |
6c95b8df | 12840 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc); |
8181d85f | 12841 | if (*bpt_p == NULL) |
5af949e3 UW |
12842 | error (_("Could not insert single-step breakpoint at %s"), |
12843 | paddress (gdbarch, next_pc)); | |
8181d85f DJ |
12844 | } |
12845 | ||
f02253f1 HZ |
12846 | /* Check if the breakpoints used for software single stepping |
12847 | were inserted or not. */ | |
12848 | ||
12849 | int | |
12850 | single_step_breakpoints_inserted (void) | |
12851 | { | |
12852 | return (single_step_breakpoints[0] != NULL | |
12853 | || single_step_breakpoints[1] != NULL); | |
12854 | } | |
12855 | ||
8181d85f DJ |
12856 | /* Remove and delete any breakpoints used for software single step. */ |
12857 | ||
12858 | void | |
12859 | remove_single_step_breakpoints (void) | |
12860 | { | |
12861 | gdb_assert (single_step_breakpoints[0] != NULL); | |
12862 | ||
12863 | /* See insert_single_step_breakpoint for more about this deprecated | |
12864 | call. */ | |
a6d9a66e UW |
12865 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
12866 | single_step_breakpoints[0]); | |
12867 | single_step_gdbarch[0] = NULL; | |
8181d85f DJ |
12868 | single_step_breakpoints[0] = NULL; |
12869 | ||
12870 | if (single_step_breakpoints[1] != NULL) | |
12871 | { | |
a6d9a66e UW |
12872 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
12873 | single_step_breakpoints[1]); | |
12874 | single_step_gdbarch[1] = NULL; | |
8181d85f DJ |
12875 | single_step_breakpoints[1] = NULL; |
12876 | } | |
12877 | } | |
12878 | ||
d03285ec UW |
12879 | /* Delete software single step breakpoints without removing them from |
12880 | the inferior. This is intended to be used if the inferior's address | |
12881 | space where they were inserted is already gone, e.g. after exit or | |
12882 | exec. */ | |
12883 | ||
12884 | void | |
12885 | cancel_single_step_breakpoints (void) | |
12886 | { | |
12887 | int i; | |
12888 | ||
12889 | for (i = 0; i < 2; i++) | |
12890 | if (single_step_breakpoints[i]) | |
12891 | { | |
12892 | xfree (single_step_breakpoints[i]); | |
12893 | single_step_breakpoints[i] = NULL; | |
12894 | single_step_gdbarch[i] = NULL; | |
12895 | } | |
12896 | } | |
12897 | ||
12898 | /* Detach software single-step breakpoints from INFERIOR_PTID without | |
12899 | removing them. */ | |
12900 | ||
12901 | static void | |
12902 | detach_single_step_breakpoints (void) | |
12903 | { | |
12904 | int i; | |
12905 | ||
12906 | for (i = 0; i < 2; i++) | |
12907 | if (single_step_breakpoints[i]) | |
12908 | target_remove_breakpoint (single_step_gdbarch[i], | |
12909 | single_step_breakpoints[i]); | |
12910 | } | |
12911 | ||
4a64f543 MS |
12912 | /* Check whether a software single-step breakpoint is inserted at |
12913 | PC. */ | |
1aafd4da UW |
12914 | |
12915 | static int | |
cc59ec59 MS |
12916 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, |
12917 | CORE_ADDR pc) | |
1aafd4da UW |
12918 | { |
12919 | int i; | |
12920 | ||
12921 | for (i = 0; i < 2; i++) | |
12922 | { | |
12923 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
6c95b8df PA |
12924 | if (bp_tgt |
12925 | && breakpoint_address_match (bp_tgt->placed_address_space, | |
12926 | bp_tgt->placed_address, | |
12927 | aspace, pc)) | |
1aafd4da UW |
12928 | return 1; |
12929 | } | |
12930 | ||
12931 | return 0; | |
12932 | } | |
12933 | ||
a96d9b2e SDJ |
12934 | /* Returns 0 if 'bp' is NOT a syscall catchpoint, |
12935 | non-zero otherwise. */ | |
12936 | static int | |
12937 | is_syscall_catchpoint_enabled (struct breakpoint *bp) | |
12938 | { | |
12939 | if (syscall_catchpoint_p (bp) | |
12940 | && bp->enable_state != bp_disabled | |
12941 | && bp->enable_state != bp_call_disabled) | |
12942 | return 1; | |
12943 | else | |
12944 | return 0; | |
12945 | } | |
12946 | ||
12947 | int | |
12948 | catch_syscall_enabled (void) | |
12949 | { | |
12950 | struct inferior *inf = current_inferior (); | |
12951 | ||
12952 | return inf->total_syscalls_count != 0; | |
12953 | } | |
12954 | ||
12955 | int | |
12956 | catching_syscall_number (int syscall_number) | |
12957 | { | |
12958 | struct breakpoint *bp; | |
12959 | ||
12960 | ALL_BREAKPOINTS (bp) | |
12961 | if (is_syscall_catchpoint_enabled (bp)) | |
12962 | { | |
be5c67c1 PA |
12963 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bp; |
12964 | ||
12965 | if (c->syscalls_to_be_caught) | |
a96d9b2e SDJ |
12966 | { |
12967 | int i, iter; | |
12968 | for (i = 0; | |
be5c67c1 | 12969 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
12970 | i++) |
12971 | if (syscall_number == iter) | |
12972 | return 1; | |
12973 | } | |
12974 | else | |
12975 | return 1; | |
12976 | } | |
12977 | ||
12978 | return 0; | |
12979 | } | |
12980 | ||
12981 | /* Complete syscall names. Used by "catch syscall". */ | |
12982 | static char ** | |
12983 | catch_syscall_completer (struct cmd_list_element *cmd, | |
12984 | char *text, char *word) | |
12985 | { | |
12986 | const char **list = get_syscall_names (); | |
c38eea1a MS |
12987 | char **retlist |
12988 | = (list == NULL) ? NULL : complete_on_enum (list, text, word); | |
cc59ec59 | 12989 | |
c38eea1a MS |
12990 | xfree (list); |
12991 | return retlist; | |
a96d9b2e SDJ |
12992 | } |
12993 | ||
1042e4c0 SS |
12994 | /* Tracepoint-specific operations. */ |
12995 | ||
12996 | /* Set tracepoint count to NUM. */ | |
12997 | static void | |
12998 | set_tracepoint_count (int num) | |
12999 | { | |
13000 | tracepoint_count = num; | |
4fa62494 | 13001 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
13002 | } |
13003 | ||
13004 | void | |
13005 | trace_command (char *arg, int from_tty) | |
13006 | { | |
8cdf0e15 VP |
13007 | if (create_breakpoint (get_current_arch (), |
13008 | arg, | |
13009 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b PA |
13010 | 0 /* tempflag */, |
13011 | bp_tracepoint /* type_wanted */, | |
8cdf0e15 VP |
13012 | 0 /* Ignore count */, |
13013 | pending_break_support, | |
348d480f | 13014 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 13015 | from_tty, |
84f4c1fe PM |
13016 | 1 /* enabled */, |
13017 | 0 /* internal */)) | |
fd9b8c24 | 13018 | set_tracepoint_count (breakpoint_count); |
1042e4c0 SS |
13019 | } |
13020 | ||
7a697b8d SS |
13021 | void |
13022 | ftrace_command (char *arg, int from_tty) | |
13023 | { | |
8cdf0e15 VP |
13024 | if (create_breakpoint (get_current_arch (), |
13025 | arg, | |
13026 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b PA |
13027 | 0 /* tempflag */, |
13028 | bp_fast_tracepoint /* type_wanted */, | |
13029 | 0 /* Ignore count */, | |
13030 | pending_break_support, | |
348d480f | 13031 | &tracepoint_breakpoint_ops, |
0fb4aa4b | 13032 | from_tty, |
84f4c1fe PM |
13033 | 1 /* enabled */, |
13034 | 0 /* internal */)) | |
0fb4aa4b PA |
13035 | set_tracepoint_count (breakpoint_count); |
13036 | } | |
13037 | ||
13038 | /* strace command implementation. Creates a static tracepoint. */ | |
13039 | ||
13040 | void | |
13041 | strace_command (char *arg, int from_tty) | |
13042 | { | |
983af33b SDJ |
13043 | struct breakpoint_ops *ops; |
13044 | ||
13045 | /* Decide if we are dealing with a static tracepoint marker (`-m'), | |
13046 | or with a normal static tracepoint. */ | |
13047 | if (arg && strncmp (arg, "-m", 2) == 0 && isspace (arg[2])) | |
13048 | ops = &strace_marker_breakpoint_ops; | |
13049 | else | |
13050 | ops = &tracepoint_breakpoint_ops; | |
13051 | ||
0fb4aa4b PA |
13052 | if (create_breakpoint (get_current_arch (), |
13053 | arg, | |
13054 | NULL, 0, 1 /* parse arg */, | |
13055 | 0 /* tempflag */, | |
13056 | bp_static_tracepoint /* type_wanted */, | |
8cdf0e15 VP |
13057 | 0 /* Ignore count */, |
13058 | pending_break_support, | |
983af33b | 13059 | ops, |
8cdf0e15 | 13060 | from_tty, |
84f4c1fe PM |
13061 | 1 /* enabled */, |
13062 | 0 /* internal */)) | |
fd9b8c24 | 13063 | set_tracepoint_count (breakpoint_count); |
7a697b8d SS |
13064 | } |
13065 | ||
409873ef SS |
13066 | /* Set up a fake reader function that gets command lines from a linked |
13067 | list that was acquired during tracepoint uploading. */ | |
13068 | ||
13069 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 13070 | static int next_cmd; |
409873ef SS |
13071 | |
13072 | static char * | |
13073 | read_uploaded_action (void) | |
13074 | { | |
13075 | char *rslt; | |
13076 | ||
3149d8c1 | 13077 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 13078 | |
3149d8c1 | 13079 | next_cmd++; |
409873ef SS |
13080 | |
13081 | return rslt; | |
13082 | } | |
13083 | ||
00bf0b85 SS |
13084 | /* Given information about a tracepoint as recorded on a target (which |
13085 | can be either a live system or a trace file), attempt to create an | |
13086 | equivalent GDB tracepoint. This is not a reliable process, since | |
13087 | the target does not necessarily have all the information used when | |
13088 | the tracepoint was originally defined. */ | |
13089 | ||
d9b3f62e | 13090 | struct tracepoint * |
00bf0b85 | 13091 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 13092 | { |
409873ef | 13093 | char *addr_str, small_buf[100]; |
d9b3f62e | 13094 | struct tracepoint *tp; |
fd9b8c24 | 13095 | |
409873ef SS |
13096 | if (utp->at_string) |
13097 | addr_str = utp->at_string; | |
13098 | else | |
13099 | { | |
13100 | /* In the absence of a source location, fall back to raw | |
13101 | address. Since there is no way to confirm that the address | |
13102 | means the same thing as when the trace was started, warn the | |
13103 | user. */ | |
3e43a32a MS |
13104 | warning (_("Uploaded tracepoint %d has no " |
13105 | "source location, using raw address"), | |
409873ef SS |
13106 | utp->number); |
13107 | sprintf (small_buf, "*%s", hex_string (utp->addr)); | |
13108 | addr_str = small_buf; | |
13109 | } | |
13110 | ||
13111 | /* There's not much we can do with a sequence of bytecodes. */ | |
13112 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
13113 | warning (_("Uploaded tracepoint %d condition " |
13114 | "has no source form, ignoring it"), | |
409873ef | 13115 | utp->number); |
d5551862 | 13116 | |
8cdf0e15 | 13117 | if (!create_breakpoint (get_current_arch (), |
409873ef SS |
13118 | addr_str, |
13119 | utp->cond_string, -1, 0 /* parse cond/thread */, | |
8cdf0e15 | 13120 | 0 /* tempflag */, |
0fb4aa4b | 13121 | utp->type /* type_wanted */, |
8cdf0e15 VP |
13122 | 0 /* Ignore count */, |
13123 | pending_break_support, | |
348d480f | 13124 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 13125 | 0 /* from_tty */, |
84f4c1fe PM |
13126 | utp->enabled /* enabled */, |
13127 | 0 /* internal */)) | |
fd9b8c24 PA |
13128 | return NULL; |
13129 | ||
00bf0b85 SS |
13130 | set_tracepoint_count (breakpoint_count); |
13131 | ||
409873ef | 13132 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
13133 | tp = get_tracepoint (tracepoint_count); |
13134 | gdb_assert (tp != NULL); | |
d5551862 | 13135 | |
00bf0b85 SS |
13136 | if (utp->pass > 0) |
13137 | { | |
d9b3f62e | 13138 | sprintf (small_buf, "%d %d", utp->pass, tp->base.number); |
00bf0b85 | 13139 | |
409873ef | 13140 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
13141 | } |
13142 | ||
409873ef SS |
13143 | /* If we have uploaded versions of the original commands, set up a |
13144 | special-purpose "reader" function and call the usual command line | |
13145 | reader, then pass the result to the breakpoint command-setting | |
13146 | function. */ | |
3149d8c1 | 13147 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 13148 | { |
409873ef | 13149 | struct command_line *cmd_list; |
00bf0b85 | 13150 | |
409873ef | 13151 | this_utp = utp; |
3149d8c1 | 13152 | next_cmd = 0; |
d5551862 | 13153 | |
409873ef SS |
13154 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
13155 | ||
d9b3f62e | 13156 | breakpoint_set_commands (&tp->base, cmd_list); |
00bf0b85 | 13157 | } |
3149d8c1 SS |
13158 | else if (!VEC_empty (char_ptr, utp->actions) |
13159 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
13160 | warning (_("Uploaded tracepoint %d actions " |
13161 | "have no source form, ignoring them"), | |
409873ef | 13162 | utp->number); |
00bf0b85 | 13163 | |
f196051f SS |
13164 | /* Copy any status information that might be available. */ |
13165 | tp->base.hit_count = utp->hit_count; | |
13166 | tp->traceframe_usage = utp->traceframe_usage; | |
13167 | ||
00bf0b85 | 13168 | return tp; |
d9b3f62e | 13169 | } |
00bf0b85 | 13170 | |
1042e4c0 SS |
13171 | /* Print information on tracepoint number TPNUM_EXP, or all if |
13172 | omitted. */ | |
13173 | ||
13174 | static void | |
e5a67952 | 13175 | tracepoints_info (char *args, int from_tty) |
1042e4c0 | 13176 | { |
79a45e25 | 13177 | struct ui_out *uiout = current_uiout; |
e5a67952 | 13178 | int num_printed; |
1042e4c0 | 13179 | |
e5a67952 | 13180 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
13181 | |
13182 | if (num_printed == 0) | |
1042e4c0 | 13183 | { |
e5a67952 | 13184 | if (args == NULL || *args == '\0') |
d77f58be SS |
13185 | ui_out_message (uiout, 0, "No tracepoints.\n"); |
13186 | else | |
e5a67952 | 13187 | ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args); |
1042e4c0 | 13188 | } |
ad443146 SS |
13189 | |
13190 | default_collect_info (); | |
1042e4c0 SS |
13191 | } |
13192 | ||
4a64f543 | 13193 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
13194 | Not supported by all targets. */ |
13195 | static void | |
13196 | enable_trace_command (char *args, int from_tty) | |
13197 | { | |
13198 | enable_command (args, from_tty); | |
13199 | } | |
13200 | ||
4a64f543 | 13201 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
13202 | Not supported by all targets. */ |
13203 | static void | |
13204 | disable_trace_command (char *args, int from_tty) | |
13205 | { | |
13206 | disable_command (args, from_tty); | |
13207 | } | |
13208 | ||
4a64f543 | 13209 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 SS |
13210 | static void |
13211 | delete_trace_command (char *arg, int from_tty) | |
13212 | { | |
35df4500 | 13213 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
13214 | |
13215 | dont_repeat (); | |
13216 | ||
13217 | if (arg == 0) | |
13218 | { | |
13219 | int breaks_to_delete = 0; | |
13220 | ||
13221 | /* Delete all breakpoints if no argument. | |
13222 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
13223 | have to be deleted with an explicit breakpoint number |
13224 | argument. */ | |
1042e4c0 | 13225 | ALL_TRACEPOINTS (b) |
46c6471b | 13226 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
13227 | { |
13228 | breaks_to_delete = 1; | |
13229 | break; | |
13230 | } | |
1042e4c0 SS |
13231 | |
13232 | /* Ask user only if there are some breakpoints to delete. */ | |
13233 | if (!from_tty | |
13234 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
13235 | { | |
35df4500 | 13236 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 13237 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 13238 | delete_breakpoint (b); |
1042e4c0 SS |
13239 | } |
13240 | } | |
13241 | else | |
51be5b68 | 13242 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
1042e4c0 SS |
13243 | } |
13244 | ||
197f0a60 TT |
13245 | /* Helper function for trace_pass_command. */ |
13246 | ||
13247 | static void | |
d9b3f62e | 13248 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 13249 | { |
d9b3f62e PA |
13250 | tp->pass_count = count; |
13251 | observer_notify_tracepoint_modified (tp->base.number); | |
197f0a60 TT |
13252 | if (from_tty) |
13253 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
d9b3f62e | 13254 | tp->base.number, count); |
197f0a60 TT |
13255 | } |
13256 | ||
1042e4c0 SS |
13257 | /* Set passcount for tracepoint. |
13258 | ||
13259 | First command argument is passcount, second is tracepoint number. | |
13260 | If tracepoint number omitted, apply to most recently defined. | |
13261 | Also accepts special argument "all". */ | |
13262 | ||
13263 | static void | |
13264 | trace_pass_command (char *args, int from_tty) | |
13265 | { | |
d9b3f62e | 13266 | struct tracepoint *t1; |
1042e4c0 | 13267 | unsigned int count; |
1042e4c0 SS |
13268 | |
13269 | if (args == 0 || *args == 0) | |
3e43a32a MS |
13270 | error (_("passcount command requires an " |
13271 | "argument (count + optional TP num)")); | |
1042e4c0 | 13272 | |
4a64f543 | 13273 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 SS |
13274 | |
13275 | while (*args && isspace ((int) *args)) | |
13276 | args++; | |
13277 | ||
13278 | if (*args && strncasecmp (args, "all", 3) == 0) | |
13279 | { | |
d9b3f62e PA |
13280 | struct breakpoint *b; |
13281 | ||
1042e4c0 | 13282 | args += 3; /* Skip special argument "all". */ |
1042e4c0 SS |
13283 | if (*args) |
13284 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 13285 | |
d9b3f62e | 13286 | ALL_TRACEPOINTS (b) |
197f0a60 | 13287 | { |
d9b3f62e | 13288 | t1 = (struct tracepoint *) b; |
197f0a60 TT |
13289 | trace_pass_set_count (t1, count, from_tty); |
13290 | } | |
13291 | } | |
13292 | else if (*args == '\0') | |
1042e4c0 | 13293 | { |
197f0a60 | 13294 | t1 = get_tracepoint_by_number (&args, NULL, 1); |
1042e4c0 | 13295 | if (t1) |
197f0a60 TT |
13296 | trace_pass_set_count (t1, count, from_tty); |
13297 | } | |
13298 | else | |
13299 | { | |
13300 | struct get_number_or_range_state state; | |
13301 | ||
13302 | init_number_or_range (&state, args); | |
13303 | while (!state.finished) | |
1042e4c0 | 13304 | { |
197f0a60 TT |
13305 | t1 = get_tracepoint_by_number (&args, &state, 1); |
13306 | if (t1) | |
13307 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
13308 | } |
13309 | } | |
1042e4c0 SS |
13310 | } |
13311 | ||
d9b3f62e | 13312 | struct tracepoint * |
1042e4c0 SS |
13313 | get_tracepoint (int num) |
13314 | { | |
13315 | struct breakpoint *t; | |
13316 | ||
13317 | ALL_TRACEPOINTS (t) | |
13318 | if (t->number == num) | |
d9b3f62e | 13319 | return (struct tracepoint *) t; |
1042e4c0 SS |
13320 | |
13321 | return NULL; | |
13322 | } | |
13323 | ||
d5551862 SS |
13324 | /* Find the tracepoint with the given target-side number (which may be |
13325 | different from the tracepoint number after disconnecting and | |
13326 | reconnecting). */ | |
13327 | ||
d9b3f62e | 13328 | struct tracepoint * |
d5551862 SS |
13329 | get_tracepoint_by_number_on_target (int num) |
13330 | { | |
d9b3f62e | 13331 | struct breakpoint *b; |
d5551862 | 13332 | |
d9b3f62e PA |
13333 | ALL_TRACEPOINTS (b) |
13334 | { | |
13335 | struct tracepoint *t = (struct tracepoint *) b; | |
13336 | ||
13337 | if (t->number_on_target == num) | |
13338 | return t; | |
13339 | } | |
d5551862 SS |
13340 | |
13341 | return NULL; | |
13342 | } | |
13343 | ||
1042e4c0 | 13344 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 TT |
13345 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
13346 | If OPTIONAL_P is true, then if the argument is missing, the most | |
1042e4c0 | 13347 | recent tracepoint (tracepoint_count) is returned. */ |
d9b3f62e | 13348 | struct tracepoint * |
197f0a60 TT |
13349 | get_tracepoint_by_number (char **arg, |
13350 | struct get_number_or_range_state *state, | |
13351 | int optional_p) | |
1042e4c0 SS |
13352 | { |
13353 | extern int tracepoint_count; | |
13354 | struct breakpoint *t; | |
13355 | int tpnum; | |
13356 | char *instring = arg == NULL ? NULL : *arg; | |
13357 | ||
197f0a60 TT |
13358 | if (state) |
13359 | { | |
13360 | gdb_assert (!state->finished); | |
13361 | tpnum = get_number_or_range (state); | |
13362 | } | |
13363 | else if (arg == NULL || *arg == NULL || ! **arg) | |
1042e4c0 SS |
13364 | { |
13365 | if (optional_p) | |
13366 | tpnum = tracepoint_count; | |
13367 | else | |
13368 | error_no_arg (_("tracepoint number")); | |
13369 | } | |
13370 | else | |
197f0a60 | 13371 | tpnum = get_number (arg); |
1042e4c0 SS |
13372 | |
13373 | if (tpnum <= 0) | |
13374 | { | |
13375 | if (instring && *instring) | |
13376 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
13377 | instring); | |
13378 | else | |
3e43a32a MS |
13379 | printf_filtered (_("Tracepoint argument missing " |
13380 | "and no previous tracepoint\n")); | |
1042e4c0 SS |
13381 | return NULL; |
13382 | } | |
13383 | ||
13384 | ALL_TRACEPOINTS (t) | |
13385 | if (t->number == tpnum) | |
13386 | { | |
d9b3f62e | 13387 | return (struct tracepoint *) t; |
1042e4c0 SS |
13388 | } |
13389 | ||
1042e4c0 SS |
13390 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
13391 | return NULL; | |
13392 | } | |
13393 | ||
d9b3f62e PA |
13394 | void |
13395 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
13396 | { | |
13397 | if (b->thread != -1) | |
13398 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
13399 | ||
13400 | if (b->task != 0) | |
13401 | fprintf_unfiltered (fp, " task %d", b->task); | |
13402 | ||
13403 | fprintf_unfiltered (fp, "\n"); | |
13404 | } | |
13405 | ||
6149aea9 PA |
13406 | /* Save information on user settable breakpoints (watchpoints, etc) to |
13407 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
13408 | on each breakpoint and only include the ones for which it returns | |
13409 | non-zero. */ | |
13410 | ||
1042e4c0 | 13411 | static void |
6149aea9 PA |
13412 | save_breakpoints (char *filename, int from_tty, |
13413 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
13414 | { |
13415 | struct breakpoint *tp; | |
6149aea9 | 13416 | int any = 0; |
a7bdde9e | 13417 | char *pathname; |
1042e4c0 | 13418 | struct cleanup *cleanup; |
a7bdde9e | 13419 | struct ui_file *fp; |
6149aea9 | 13420 | int extra_trace_bits = 0; |
1042e4c0 | 13421 | |
6149aea9 PA |
13422 | if (filename == 0 || *filename == 0) |
13423 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
13424 | |
13425 | /* See if we have anything to save. */ | |
6149aea9 | 13426 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 13427 | { |
6149aea9 | 13428 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 13429 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
13430 | continue; |
13431 | ||
13432 | /* If we have a filter, only save the breakpoints it accepts. */ | |
13433 | if (filter && !filter (tp)) | |
13434 | continue; | |
13435 | ||
13436 | any = 1; | |
13437 | ||
13438 | if (is_tracepoint (tp)) | |
13439 | { | |
13440 | extra_trace_bits = 1; | |
13441 | ||
13442 | /* We can stop searching. */ | |
13443 | break; | |
13444 | } | |
1042e4c0 | 13445 | } |
6149aea9 PA |
13446 | |
13447 | if (!any) | |
1042e4c0 | 13448 | { |
6149aea9 | 13449 | warning (_("Nothing to save.")); |
1042e4c0 SS |
13450 | return; |
13451 | } | |
13452 | ||
6149aea9 | 13453 | pathname = tilde_expand (filename); |
1042e4c0 | 13454 | cleanup = make_cleanup (xfree, pathname); |
a7bdde9e | 13455 | fp = gdb_fopen (pathname, "w"); |
059fb39f | 13456 | if (!fp) |
6149aea9 PA |
13457 | error (_("Unable to open file '%s' for saving (%s)"), |
13458 | filename, safe_strerror (errno)); | |
a7bdde9e | 13459 | make_cleanup_ui_file_delete (fp); |
8bf6485c | 13460 | |
6149aea9 PA |
13461 | if (extra_trace_bits) |
13462 | save_trace_state_variables (fp); | |
8bf6485c | 13463 | |
6149aea9 | 13464 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 13465 | { |
6149aea9 | 13466 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 13467 | if (!user_breakpoint_p (tp)) |
6149aea9 | 13468 | continue; |
8bf6485c | 13469 | |
6149aea9 PA |
13470 | /* If we have a filter, only save the breakpoints it accepts. */ |
13471 | if (filter && !filter (tp)) | |
13472 | continue; | |
13473 | ||
348d480f | 13474 | tp->ops->print_recreate (tp, fp); |
1042e4c0 | 13475 | |
6149aea9 PA |
13476 | /* Note, we can't rely on tp->number for anything, as we can't |
13477 | assume the recreated breakpoint numbers will match. Use $bpnum | |
13478 | instead. */ | |
13479 | ||
13480 | if (tp->cond_string) | |
13481 | fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); | |
13482 | ||
13483 | if (tp->ignore_count) | |
13484 | fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); | |
13485 | ||
a7bdde9e | 13486 | if (tp->commands) |
1042e4c0 | 13487 | { |
a7bdde9e VP |
13488 | volatile struct gdb_exception ex; |
13489 | ||
6149aea9 | 13490 | fprintf_unfiltered (fp, " commands\n"); |
a7bdde9e | 13491 | |
79a45e25 | 13492 | ui_out_redirect (current_uiout, fp); |
14dba4b4 | 13493 | TRY_CATCH (ex, RETURN_MASK_ALL) |
1042e4c0 | 13494 | { |
79a45e25 | 13495 | print_command_lines (current_uiout, tp->commands->commands, 2); |
a7bdde9e | 13496 | } |
79a45e25 | 13497 | ui_out_redirect (current_uiout, NULL); |
1042e4c0 | 13498 | |
a7bdde9e VP |
13499 | if (ex.reason < 0) |
13500 | throw_exception (ex); | |
1042e4c0 | 13501 | |
a7bdde9e | 13502 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 | 13503 | } |
6149aea9 PA |
13504 | |
13505 | if (tp->enable_state == bp_disabled) | |
13506 | fprintf_unfiltered (fp, "disable\n"); | |
13507 | ||
13508 | /* If this is a multi-location breakpoint, check if the locations | |
13509 | should be individually disabled. Watchpoint locations are | |
13510 | special, and not user visible. */ | |
13511 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
13512 | { | |
13513 | struct bp_location *loc; | |
13514 | int n = 1; | |
13515 | ||
13516 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
13517 | if (!loc->enabled) | |
13518 | fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); | |
13519 | } | |
1042e4c0 | 13520 | } |
8bf6485c | 13521 | |
6149aea9 | 13522 | if (extra_trace_bits && *default_collect) |
8bf6485c SS |
13523 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); |
13524 | ||
1042e4c0 SS |
13525 | do_cleanups (cleanup); |
13526 | if (from_tty) | |
6149aea9 PA |
13527 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
13528 | } | |
13529 | ||
13530 | /* The `save breakpoints' command. */ | |
13531 | ||
13532 | static void | |
13533 | save_breakpoints_command (char *args, int from_tty) | |
13534 | { | |
13535 | save_breakpoints (args, from_tty, NULL); | |
13536 | } | |
13537 | ||
13538 | /* The `save tracepoints' command. */ | |
13539 | ||
13540 | static void | |
13541 | save_tracepoints_command (char *args, int from_tty) | |
13542 | { | |
13543 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
13544 | } |
13545 | ||
13546 | /* Create a vector of all tracepoints. */ | |
13547 | ||
13548 | VEC(breakpoint_p) * | |
eeae04df | 13549 | all_tracepoints (void) |
1042e4c0 SS |
13550 | { |
13551 | VEC(breakpoint_p) *tp_vec = 0; | |
13552 | struct breakpoint *tp; | |
13553 | ||
13554 | ALL_TRACEPOINTS (tp) | |
13555 | { | |
13556 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
13557 | } | |
13558 | ||
13559 | return tp_vec; | |
13560 | } | |
13561 | ||
c906108c | 13562 | \f |
4a64f543 MS |
13563 | /* This help string is used for the break, hbreak, tbreak and thbreak |
13564 | commands. It is defined as a macro to prevent duplication. | |
13565 | COMMAND should be a string constant containing the name of the | |
13566 | command. */ | |
31e2b00f AS |
13567 | #define BREAK_ARGS_HELP(command) \ |
13568 | command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\ | |
13569 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ | |
13570 | If a line number is specified, break at start of code for that line.\n\ | |
13571 | If a function is specified, break at start of code for that function.\n\ | |
13572 | If an address is specified, break at that exact address.\n\ | |
dc10affe PA |
13573 | With no LOCATION, uses current execution address of the selected\n\ |
13574 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
13575 | \n\ |
13576 | THREADNUM is the number from \"info threads\".\n\ | |
13577 | CONDITION is a boolean expression.\n\ | |
13578 | \n\ | |
d41c0fc8 PA |
13579 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
13580 | conditions are different.\n\ | |
31e2b00f AS |
13581 | \n\ |
13582 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
13583 | ||
44feb3ce TT |
13584 | /* List of subcommands for "catch". */ |
13585 | static struct cmd_list_element *catch_cmdlist; | |
13586 | ||
13587 | /* List of subcommands for "tcatch". */ | |
13588 | static struct cmd_list_element *tcatch_cmdlist; | |
13589 | ||
9ac4176b | 13590 | void |
44feb3ce TT |
13591 | add_catch_command (char *name, char *docstring, |
13592 | void (*sfunc) (char *args, int from_tty, | |
13593 | struct cmd_list_element *command), | |
a96d9b2e SDJ |
13594 | char **(*completer) (struct cmd_list_element *cmd, |
13595 | char *text, char *word), | |
44feb3ce TT |
13596 | void *user_data_catch, |
13597 | void *user_data_tcatch) | |
13598 | { | |
13599 | struct cmd_list_element *command; | |
13600 | ||
13601 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
13602 | &catch_cmdlist); | |
13603 | set_cmd_sfunc (command, sfunc); | |
13604 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 13605 | set_cmd_completer (command, completer); |
44feb3ce TT |
13606 | |
13607 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
13608 | &tcatch_cmdlist); | |
13609 | set_cmd_sfunc (command, sfunc); | |
13610 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 13611 | set_cmd_completer (command, completer); |
44feb3ce TT |
13612 | } |
13613 | ||
6c95b8df | 13614 | static void |
a79b8f6e | 13615 | clear_syscall_counts (struct inferior *inf) |
6c95b8df | 13616 | { |
6c95b8df PA |
13617 | inf->total_syscalls_count = 0; |
13618 | inf->any_syscall_count = 0; | |
13619 | VEC_free (int, inf->syscalls_counts); | |
13620 | } | |
13621 | ||
6149aea9 PA |
13622 | static void |
13623 | save_command (char *arg, int from_tty) | |
13624 | { | |
3e43a32a MS |
13625 | printf_unfiltered (_("\"save\" must be followed by " |
13626 | "the name of a save subcommand.\n")); | |
6149aea9 PA |
13627 | help_list (save_cmdlist, "save ", -1, gdb_stdout); |
13628 | } | |
13629 | ||
84f4c1fe PM |
13630 | struct breakpoint * |
13631 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
13632 | void *data) | |
13633 | { | |
35df4500 | 13634 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 13635 | |
35df4500 | 13636 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
13637 | { |
13638 | if ((*callback) (b, data)) | |
13639 | return b; | |
13640 | } | |
13641 | ||
13642 | return NULL; | |
13643 | } | |
13644 | ||
0574c78f GB |
13645 | /* Zero if any of the breakpoint's locations could be a location where |
13646 | functions have been inlined, nonzero otherwise. */ | |
13647 | ||
13648 | static int | |
13649 | is_non_inline_function (struct breakpoint *b) | |
13650 | { | |
13651 | /* The shared library event breakpoint is set on the address of a | |
13652 | non-inline function. */ | |
13653 | if (b->type == bp_shlib_event) | |
13654 | return 1; | |
13655 | ||
13656 | return 0; | |
13657 | } | |
13658 | ||
13659 | /* Nonzero if the specified PC cannot be a location where functions | |
13660 | have been inlined. */ | |
13661 | ||
13662 | int | |
09ac7c10 TT |
13663 | pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc, |
13664 | const struct target_waitstatus *ws) | |
0574c78f GB |
13665 | { |
13666 | struct breakpoint *b; | |
13667 | struct bp_location *bl; | |
13668 | ||
13669 | ALL_BREAKPOINTS (b) | |
13670 | { | |
13671 | if (!is_non_inline_function (b)) | |
13672 | continue; | |
13673 | ||
13674 | for (bl = b->loc; bl != NULL; bl = bl->next) | |
13675 | { | |
13676 | if (!bl->shlib_disabled | |
09ac7c10 | 13677 | && bpstat_check_location (bl, aspace, pc, ws)) |
0574c78f GB |
13678 | return 1; |
13679 | } | |
13680 | } | |
13681 | ||
13682 | return 0; | |
13683 | } | |
13684 | ||
2060206e PA |
13685 | void |
13686 | initialize_breakpoint_ops (void) | |
13687 | { | |
13688 | static int initialized = 0; | |
13689 | ||
13690 | struct breakpoint_ops *ops; | |
13691 | ||
13692 | if (initialized) | |
13693 | return; | |
13694 | initialized = 1; | |
13695 | ||
13696 | /* The breakpoint_ops structure to be inherit by all kinds of | |
13697 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
13698 | internal and momentary breakpoints, etc.). */ | |
13699 | ops = &bkpt_base_breakpoint_ops; | |
13700 | *ops = base_breakpoint_ops; | |
13701 | ops->re_set = bkpt_re_set; | |
13702 | ops->insert_location = bkpt_insert_location; | |
13703 | ops->remove_location = bkpt_remove_location; | |
13704 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
983af33b SDJ |
13705 | ops->create_sals_from_address = bkpt_create_sals_from_address; |
13706 | ops->create_breakpoints_sal = bkpt_create_breakpoints_sal; | |
13707 | ops->decode_linespec = bkpt_decode_linespec; | |
2060206e PA |
13708 | |
13709 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
13710 | ops = &bkpt_breakpoint_ops; | |
13711 | *ops = bkpt_base_breakpoint_ops; | |
13712 | ops->re_set = bkpt_re_set; | |
13713 | ops->resources_needed = bkpt_resources_needed; | |
13714 | ops->print_it = bkpt_print_it; | |
13715 | ops->print_mention = bkpt_print_mention; | |
13716 | ops->print_recreate = bkpt_print_recreate; | |
13717 | ||
13718 | /* Ranged breakpoints. */ | |
13719 | ops = &ranged_breakpoint_ops; | |
13720 | *ops = bkpt_breakpoint_ops; | |
13721 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
13722 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
13723 | ops->print_it = print_it_ranged_breakpoint; | |
13724 | ops->print_one = print_one_ranged_breakpoint; | |
13725 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
13726 | ops->print_mention = print_mention_ranged_breakpoint; | |
13727 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
13728 | ||
13729 | /* Internal breakpoints. */ | |
13730 | ops = &internal_breakpoint_ops; | |
13731 | *ops = bkpt_base_breakpoint_ops; | |
13732 | ops->re_set = internal_bkpt_re_set; | |
13733 | ops->check_status = internal_bkpt_check_status; | |
13734 | ops->print_it = internal_bkpt_print_it; | |
13735 | ops->print_mention = internal_bkpt_print_mention; | |
13736 | ||
13737 | /* Momentary breakpoints. */ | |
13738 | ops = &momentary_breakpoint_ops; | |
13739 | *ops = bkpt_base_breakpoint_ops; | |
13740 | ops->re_set = momentary_bkpt_re_set; | |
13741 | ops->check_status = momentary_bkpt_check_status; | |
13742 | ops->print_it = momentary_bkpt_print_it; | |
13743 | ops->print_mention = momentary_bkpt_print_mention; | |
13744 | ||
13745 | /* GNU v3 exception catchpoints. */ | |
13746 | ops = &gnu_v3_exception_catchpoint_ops; | |
13747 | *ops = bkpt_breakpoint_ops; | |
13748 | ops->print_it = print_it_exception_catchpoint; | |
13749 | ops->print_one = print_one_exception_catchpoint; | |
13750 | ops->print_mention = print_mention_exception_catchpoint; | |
13751 | ops->print_recreate = print_recreate_exception_catchpoint; | |
13752 | ||
13753 | /* Watchpoints. */ | |
13754 | ops = &watchpoint_breakpoint_ops; | |
13755 | *ops = base_breakpoint_ops; | |
3a5c3e22 | 13756 | ops->dtor = dtor_watchpoint; |
2060206e PA |
13757 | ops->re_set = re_set_watchpoint; |
13758 | ops->insert_location = insert_watchpoint; | |
13759 | ops->remove_location = remove_watchpoint; | |
13760 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
13761 | ops->check_status = check_status_watchpoint; | |
13762 | ops->resources_needed = resources_needed_watchpoint; | |
13763 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
13764 | ops->print_it = print_it_watchpoint; | |
13765 | ops->print_mention = print_mention_watchpoint; | |
13766 | ops->print_recreate = print_recreate_watchpoint; | |
13767 | ||
13768 | /* Masked watchpoints. */ | |
13769 | ops = &masked_watchpoint_breakpoint_ops; | |
13770 | *ops = watchpoint_breakpoint_ops; | |
13771 | ops->insert_location = insert_masked_watchpoint; | |
13772 | ops->remove_location = remove_masked_watchpoint; | |
13773 | ops->resources_needed = resources_needed_masked_watchpoint; | |
13774 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
13775 | ops->print_it = print_it_masked_watchpoint; | |
13776 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
13777 | ops->print_mention = print_mention_masked_watchpoint; | |
13778 | ops->print_recreate = print_recreate_masked_watchpoint; | |
13779 | ||
13780 | /* Tracepoints. */ | |
13781 | ops = &tracepoint_breakpoint_ops; | |
13782 | *ops = base_breakpoint_ops; | |
13783 | ops->re_set = tracepoint_re_set; | |
13784 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
13785 | ops->print_one_detail = tracepoint_print_one_detail; | |
13786 | ops->print_mention = tracepoint_print_mention; | |
13787 | ops->print_recreate = tracepoint_print_recreate; | |
983af33b SDJ |
13788 | ops->create_sals_from_address = tracepoint_create_sals_from_address; |
13789 | ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal; | |
13790 | ops->decode_linespec = tracepoint_decode_linespec; | |
13791 | ||
13792 | /* Static tracepoints with marker (`-m'). */ | |
13793 | ops = &strace_marker_breakpoint_ops; | |
13794 | *ops = tracepoint_breakpoint_ops; | |
13795 | ops->create_sals_from_address = strace_marker_create_sals_from_address; | |
13796 | ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal; | |
13797 | ops->decode_linespec = strace_marker_decode_linespec; | |
2060206e PA |
13798 | |
13799 | /* Fork catchpoints. */ | |
13800 | ops = &catch_fork_breakpoint_ops; | |
13801 | *ops = base_breakpoint_ops; | |
13802 | ops->insert_location = insert_catch_fork; | |
13803 | ops->remove_location = remove_catch_fork; | |
13804 | ops->breakpoint_hit = breakpoint_hit_catch_fork; | |
13805 | ops->print_it = print_it_catch_fork; | |
13806 | ops->print_one = print_one_catch_fork; | |
13807 | ops->print_mention = print_mention_catch_fork; | |
13808 | ops->print_recreate = print_recreate_catch_fork; | |
13809 | ||
13810 | /* Vfork catchpoints. */ | |
13811 | ops = &catch_vfork_breakpoint_ops; | |
13812 | *ops = base_breakpoint_ops; | |
13813 | ops->insert_location = insert_catch_vfork; | |
13814 | ops->remove_location = remove_catch_vfork; | |
13815 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; | |
13816 | ops->print_it = print_it_catch_vfork; | |
13817 | ops->print_one = print_one_catch_vfork; | |
13818 | ops->print_mention = print_mention_catch_vfork; | |
13819 | ops->print_recreate = print_recreate_catch_vfork; | |
13820 | ||
13821 | /* Exec catchpoints. */ | |
13822 | ops = &catch_exec_breakpoint_ops; | |
13823 | *ops = base_breakpoint_ops; | |
13824 | ops->dtor = dtor_catch_exec; | |
13825 | ops->insert_location = insert_catch_exec; | |
13826 | ops->remove_location = remove_catch_exec; | |
13827 | ops->breakpoint_hit = breakpoint_hit_catch_exec; | |
13828 | ops->print_it = print_it_catch_exec; | |
13829 | ops->print_one = print_one_catch_exec; | |
13830 | ops->print_mention = print_mention_catch_exec; | |
13831 | ops->print_recreate = print_recreate_catch_exec; | |
13832 | ||
13833 | /* Syscall catchpoints. */ | |
13834 | ops = &catch_syscall_breakpoint_ops; | |
13835 | *ops = base_breakpoint_ops; | |
13836 | ops->dtor = dtor_catch_syscall; | |
13837 | ops->insert_location = insert_catch_syscall; | |
13838 | ops->remove_location = remove_catch_syscall; | |
13839 | ops->breakpoint_hit = breakpoint_hit_catch_syscall; | |
13840 | ops->print_it = print_it_catch_syscall; | |
13841 | ops->print_one = print_one_catch_syscall; | |
13842 | ops->print_mention = print_mention_catch_syscall; | |
13843 | ops->print_recreate = print_recreate_catch_syscall; | |
13844 | } | |
13845 | ||
c906108c | 13846 | void |
fba45db2 | 13847 | _initialize_breakpoint (void) |
c906108c SS |
13848 | { |
13849 | struct cmd_list_element *c; | |
13850 | ||
2060206e PA |
13851 | initialize_breakpoint_ops (); |
13852 | ||
84acb35a | 13853 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
6c95b8df | 13854 | observer_attach_inferior_exit (clear_syscall_counts); |
1f3b5d1b | 13855 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 13856 | |
17450429 PP |
13857 | breakpoint_objfile_key = register_objfile_data (); |
13858 | ||
c906108c SS |
13859 | breakpoint_chain = 0; |
13860 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
13861 | before a breakpoint is set. */ | |
13862 | breakpoint_count = 0; | |
13863 | ||
1042e4c0 SS |
13864 | tracepoint_count = 0; |
13865 | ||
1bedd215 AC |
13866 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
13867 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
13868 | Usage is `ignore N COUNT'.")); | |
c906108c | 13869 | if (xdb_commands) |
c5aa993b | 13870 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 13871 | |
1bedd215 AC |
13872 | add_com ("commands", class_breakpoint, commands_command, _("\ |
13873 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
13874 | Give breakpoint number as argument after \"commands\".\n\ |
13875 | With no argument, the targeted breakpoint is the last one set.\n\ | |
13876 | The commands themselves follow starting on the next line.\n\ | |
13877 | Type a line containing \"end\" to indicate the end of them.\n\ | |
13878 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 13879 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 13880 | |
1bedd215 AC |
13881 | add_com ("condition", class_breakpoint, condition_command, _("\ |
13882 | Specify breakpoint number N to break only if COND is true.\n\ | |
c906108c | 13883 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 13884 | expression to be evaluated whenever breakpoint N is reached.")); |
c906108c | 13885 | |
1bedd215 | 13886 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 13887 | Set a temporary breakpoint.\n\ |
c906108c SS |
13888 | Like \"break\" except the breakpoint is only temporary,\n\ |
13889 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
13890 | by using \"enable delete\" on the breakpoint number.\n\ |
13891 | \n" | |
13892 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 13893 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 13894 | |
1bedd215 | 13895 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 13896 | Set a hardware assisted breakpoint.\n\ |
c906108c | 13897 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
13898 | some target hardware may not have this support.\n\ |
13899 | \n" | |
13900 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 13901 | set_cmd_completer (c, location_completer); |
c906108c | 13902 | |
1bedd215 | 13903 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 13904 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 13905 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
13906 | so it will be deleted when hit.\n\ |
13907 | \n" | |
13908 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 13909 | set_cmd_completer (c, location_completer); |
c906108c | 13910 | |
1bedd215 AC |
13911 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
13912 | Enable some breakpoints.\n\ | |
c906108c SS |
13913 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
13914 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
13915 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 13916 | With a subcommand you can enable temporarily."), |
c906108c SS |
13917 | &enablelist, "enable ", 1, &cmdlist); |
13918 | if (xdb_commands) | |
1bedd215 AC |
13919 | add_com ("ab", class_breakpoint, enable_command, _("\ |
13920 | Enable some breakpoints.\n\ | |
c906108c SS |
13921 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
13922 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
13923 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 13924 | With a subcommand you can enable temporarily.")); |
c906108c SS |
13925 | |
13926 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
13927 | ||
84951ab5 | 13928 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 13929 | Enable some breakpoints.\n\ |
c906108c SS |
13930 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
13931 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 13932 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 13933 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 13934 | |
1a966eab AC |
13935 | add_cmd ("once", no_class, enable_once_command, _("\ |
13936 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
13937 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
13938 | &enablebreaklist); |
13939 | ||
1a966eab AC |
13940 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
13941 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
13942 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
13943 | &enablebreaklist); |
13944 | ||
1a966eab AC |
13945 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
13946 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
13947 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
13948 | &enablelist); |
13949 | ||
1a966eab AC |
13950 | add_cmd ("once", no_class, enable_once_command, _("\ |
13951 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
13952 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
13953 | &enablelist); |
13954 | ||
1bedd215 AC |
13955 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
13956 | Disable some breakpoints.\n\ | |
c906108c SS |
13957 | Arguments are breakpoint numbers with spaces in between.\n\ |
13958 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 13959 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
c906108c SS |
13960 | &disablelist, "disable ", 1, &cmdlist); |
13961 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
13962 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
13963 | if (xdb_commands) | |
1bedd215 AC |
13964 | add_com ("sb", class_breakpoint, disable_command, _("\ |
13965 | Disable some breakpoints.\n\ | |
c906108c SS |
13966 | Arguments are breakpoint numbers with spaces in between.\n\ |
13967 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 13968 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.")); |
c906108c | 13969 | |
1a966eab AC |
13970 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
13971 | Disable some breakpoints.\n\ | |
c906108c SS |
13972 | Arguments are breakpoint numbers with spaces in between.\n\ |
13973 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 13974 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 13975 | This command may be abbreviated \"disable\"."), |
c906108c SS |
13976 | &disablelist); |
13977 | ||
1bedd215 AC |
13978 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
13979 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
13980 | Arguments are breakpoint numbers with spaces in between.\n\ |
13981 | To delete all breakpoints, give no argument.\n\ | |
13982 | \n\ | |
13983 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 13984 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
13985 | &deletelist, "delete ", 1, &cmdlist); |
13986 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 13987 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 13988 | if (xdb_commands) |
1bedd215 AC |
13989 | add_com ("db", class_breakpoint, delete_command, _("\ |
13990 | Delete some breakpoints.\n\ | |
c906108c | 13991 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 13992 | To delete all breakpoints, give no argument.\n")); |
c906108c | 13993 | |
1a966eab AC |
13994 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
13995 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
13996 | Arguments are breakpoint numbers with spaces in between.\n\ |
13997 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 13998 | This command may be abbreviated \"delete\"."), |
c906108c SS |
13999 | &deletelist); |
14000 | ||
1bedd215 AC |
14001 | add_com ("clear", class_breakpoint, clear_command, _("\ |
14002 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
14003 | Argument may be line number, function name, or \"*\" and an address.\n\ |
14004 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
14005 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
14006 | If an address is specified, breakpoints at that address are cleared.\n\ |
14007 | \n\ | |
14008 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
14009 | is executing in.\n\ |
14010 | \n\ | |
1bedd215 | 14011 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 14012 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 14013 | |
1bedd215 | 14014 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
14015 | Set breakpoint at specified line or function.\n" |
14016 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 14017 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 14018 | |
c906108c SS |
14019 | add_com_alias ("b", "break", class_run, 1); |
14020 | add_com_alias ("br", "break", class_run, 1); | |
14021 | add_com_alias ("bre", "break", class_run, 1); | |
14022 | add_com_alias ("brea", "break", class_run, 1); | |
14023 | ||
7681d515 PM |
14024 | if (xdb_commands) |
14025 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
14026 | |
14027 | if (dbx_commands) | |
14028 | { | |
1bedd215 AC |
14029 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
14030 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
14031 | &stoplist, "stop ", 1, &cmdlist); |
14032 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 14033 | _("Break in function or address."), &stoplist); |
c5aa993b | 14034 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 14035 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
14036 | add_com ("status", class_info, breakpoints_info, _("\ |
14037 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
14038 | The \"Type\" column indicates one of:\n\ |
14039 | \tbreakpoint - normal breakpoint\n\ | |
14040 | \twatchpoint - watchpoint\n\ | |
14041 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
14042 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
14043 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
14044 | address and file/line number respectively.\n\ |
14045 | \n\ | |
14046 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
14047 | are set to the address of the last breakpoint listed unless the command\n\ |
14048 | is prefixed with \"server \".\n\n\ | |
c906108c | 14049 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 14050 | breakpoint set.")); |
c906108c SS |
14051 | } |
14052 | ||
1bedd215 | 14053 | add_info ("breakpoints", breakpoints_info, _("\ |
e5a67952 | 14054 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
14055 | The \"Type\" column indicates one of:\n\ |
14056 | \tbreakpoint - normal breakpoint\n\ | |
14057 | \twatchpoint - watchpoint\n\ | |
14058 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
14059 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
14060 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
14061 | address and file/line number respectively.\n\ |
14062 | \n\ | |
14063 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
14064 | are set to the address of the last breakpoint listed unless the command\n\ |
14065 | is prefixed with \"server \".\n\n\ | |
c906108c | 14066 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 14067 | breakpoint set.")); |
c906108c | 14068 | |
6b04bdb7 MS |
14069 | add_info_alias ("b", "breakpoints", 1); |
14070 | ||
c906108c | 14071 | if (xdb_commands) |
1bedd215 AC |
14072 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
14073 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
14074 | The \"Type\" column indicates one of:\n\ |
14075 | \tbreakpoint - normal breakpoint\n\ | |
14076 | \twatchpoint - watchpoint\n\ | |
14077 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
14078 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
14079 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
14080 | address and file/line number respectively.\n\ |
14081 | \n\ | |
14082 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
14083 | are set to the address of the last breakpoint listed unless the command\n\ |
14084 | is prefixed with \"server \".\n\n\ | |
c906108c | 14085 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 14086 | breakpoint set.")); |
c906108c | 14087 | |
1a966eab AC |
14088 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
14089 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
14090 | The \"Type\" column indicates one of:\n\ |
14091 | \tbreakpoint - normal breakpoint\n\ | |
14092 | \twatchpoint - watchpoint\n\ | |
14093 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
14094 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
14095 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
14096 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
14097 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
14098 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
14099 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
14100 | address and file/line number respectively.\n\ |
14101 | \n\ | |
14102 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
14103 | are set to the address of the last breakpoint listed unless the command\n\ |
14104 | is prefixed with \"server \".\n\n\ | |
c906108c | 14105 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 14106 | breakpoint set."), |
c906108c SS |
14107 | &maintenanceinfolist); |
14108 | ||
44feb3ce TT |
14109 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
14110 | Set catchpoints to catch events."), | |
14111 | &catch_cmdlist, "catch ", | |
14112 | 0/*allow-unknown*/, &cmdlist); | |
14113 | ||
14114 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
14115 | Set temporary catchpoints to catch events."), | |
14116 | &tcatch_cmdlist, "tcatch ", | |
14117 | 0/*allow-unknown*/, &cmdlist); | |
14118 | ||
14119 | /* Add catch and tcatch sub-commands. */ | |
14120 | add_catch_command ("catch", _("\ | |
88e7d25d | 14121 | Catch an exception, when caught."), |
44feb3ce | 14122 | catch_catch_command, |
a96d9b2e | 14123 | NULL, |
44feb3ce TT |
14124 | CATCH_PERMANENT, |
14125 | CATCH_TEMPORARY); | |
14126 | add_catch_command ("throw", _("\ | |
88e7d25d | 14127 | Catch an exception, when thrown."), |
44feb3ce | 14128 | catch_throw_command, |
a96d9b2e | 14129 | NULL, |
44feb3ce TT |
14130 | CATCH_PERMANENT, |
14131 | CATCH_TEMPORARY); | |
14132 | add_catch_command ("fork", _("Catch calls to fork."), | |
14133 | catch_fork_command_1, | |
a96d9b2e | 14134 | NULL, |
44feb3ce TT |
14135 | (void *) (uintptr_t) catch_fork_permanent, |
14136 | (void *) (uintptr_t) catch_fork_temporary); | |
14137 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
14138 | catch_fork_command_1, | |
a96d9b2e | 14139 | NULL, |
44feb3ce TT |
14140 | (void *) (uintptr_t) catch_vfork_permanent, |
14141 | (void *) (uintptr_t) catch_vfork_temporary); | |
14142 | add_catch_command ("exec", _("Catch calls to exec."), | |
14143 | catch_exec_command_1, | |
a96d9b2e SDJ |
14144 | NULL, |
14145 | CATCH_PERMANENT, | |
14146 | CATCH_TEMPORARY); | |
14147 | add_catch_command ("syscall", _("\ | |
14148 | Catch system calls by their names and/or numbers.\n\ | |
14149 | Arguments say which system calls to catch. If no arguments\n\ | |
14150 | are given, every system call will be caught.\n\ | |
14151 | Arguments, if given, should be one or more system call names\n\ | |
14152 | (if your system supports that), or system call numbers."), | |
14153 | catch_syscall_command_1, | |
14154 | catch_syscall_completer, | |
44feb3ce TT |
14155 | CATCH_PERMANENT, |
14156 | CATCH_TEMPORARY); | |
c5aa993b | 14157 | |
1bedd215 AC |
14158 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
14159 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 14160 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 14161 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
14162 | an expression changes.\n\ |
14163 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
14164 | the memory to which it refers.")); | |
65d12d83 | 14165 | set_cmd_completer (c, expression_completer); |
c906108c | 14166 | |
1bedd215 AC |
14167 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
14168 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 14169 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 14170 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
14171 | an expression is read.\n\ |
14172 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
14173 | the memory to which it refers.")); | |
65d12d83 | 14174 | set_cmd_completer (c, expression_completer); |
c906108c | 14175 | |
1bedd215 AC |
14176 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
14177 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 14178 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 14179 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
14180 | an expression is either read or written.\n\ |
14181 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
14182 | the memory to which it refers.")); | |
65d12d83 | 14183 | set_cmd_completer (c, expression_completer); |
c906108c | 14184 | |
d77f58be | 14185 | add_info ("watchpoints", watchpoints_info, _("\ |
e5a67952 | 14186 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 14187 | |
920d2a44 AC |
14188 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
14189 | respond to changes - contrary to the description. */ | |
85c07804 AC |
14190 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
14191 | &can_use_hw_watchpoints, _("\ | |
14192 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
14193 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
14194 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
14195 | such is available. (However, any hardware watchpoints that were\n\ | |
14196 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
14197 | hardware.)"), |
14198 | NULL, | |
920d2a44 | 14199 | show_can_use_hw_watchpoints, |
85c07804 | 14200 | &setlist, &showlist); |
c906108c SS |
14201 | |
14202 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 14203 | |
1042e4c0 SS |
14204 | /* Tracepoint manipulation commands. */ |
14205 | ||
14206 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
14207 | Set a tracepoint at specified line or function.\n\ | |
14208 | \n" | |
14209 | BREAK_ARGS_HELP ("trace") "\n\ | |
14210 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
14211 | set_cmd_completer (c, location_completer); | |
14212 | ||
14213 | add_com_alias ("tp", "trace", class_alias, 0); | |
14214 | add_com_alias ("tr", "trace", class_alias, 1); | |
14215 | add_com_alias ("tra", "trace", class_alias, 1); | |
14216 | add_com_alias ("trac", "trace", class_alias, 1); | |
14217 | ||
7a697b8d SS |
14218 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
14219 | Set a fast tracepoint at specified line or function.\n\ | |
14220 | \n" | |
14221 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
14222 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
14223 | set_cmd_completer (c, location_completer); | |
14224 | ||
0fb4aa4b PA |
14225 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
14226 | Set a static tracepoint at specified line, function or marker.\n\ | |
14227 | \n\ | |
14228 | strace [LOCATION] [if CONDITION]\n\ | |
14229 | LOCATION may be a line number, function name, \"*\" and an address,\n\ | |
14230 | or -m MARKER_ID.\n\ | |
14231 | If a line number is specified, probe the marker at start of code\n\ | |
14232 | for that line. If a function is specified, probe the marker at start\n\ | |
14233 | of code for that function. If an address is specified, probe the marker\n\ | |
14234 | at that exact address. If a marker id is specified, probe the marker\n\ | |
14235 | with that name. With no LOCATION, uses current execution address of\n\ | |
14236 | the selected stack frame.\n\ | |
14237 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ | |
14238 | This collects arbitrary user data passed in the probe point call to the\n\ | |
14239 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
14240 | by printing the $_sdata variable like any other convenience variable.\n\ | |
14241 | \n\ | |
14242 | CONDITION is a boolean expression.\n\ | |
14243 | \n\ | |
d41c0fc8 PA |
14244 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
14245 | conditions are different.\n\ | |
0fb4aa4b PA |
14246 | \n\ |
14247 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
14248 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
14249 | set_cmd_completer (c, location_completer); | |
14250 | ||
1042e4c0 | 14251 | add_info ("tracepoints", tracepoints_info, _("\ |
e5a67952 | 14252 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
14253 | Convenience variable \"$tpnum\" contains the number of the\n\ |
14254 | last tracepoint set.")); | |
14255 | ||
14256 | add_info_alias ("tp", "tracepoints", 1); | |
14257 | ||
14258 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
14259 | Delete specified tracepoints.\n\ | |
14260 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
14261 | No argument means delete all tracepoints."), | |
14262 | &deletelist); | |
14263 | ||
14264 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
14265 | Disable specified tracepoints.\n\ | |
14266 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
14267 | No argument means disable all tracepoints."), | |
14268 | &disablelist); | |
14269 | deprecate_cmd (c, "disable"); | |
14270 | ||
14271 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
14272 | Enable specified tracepoints.\n\ | |
14273 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
14274 | No argument means enable all tracepoints."), | |
14275 | &enablelist); | |
14276 | deprecate_cmd (c, "enable"); | |
14277 | ||
14278 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
14279 | Set the passcount for a tracepoint.\n\ | |
14280 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
14281 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
14282 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
14283 | ||
6149aea9 PA |
14284 | add_prefix_cmd ("save", class_breakpoint, save_command, |
14285 | _("Save breakpoint definitions as a script."), | |
14286 | &save_cmdlist, "save ", | |
14287 | 0/*allow-unknown*/, &cmdlist); | |
14288 | ||
14289 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
14290 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 14291 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
14292 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
14293 | session to restore them."), | |
14294 | &save_cmdlist); | |
14295 | set_cmd_completer (c, filename_completer); | |
14296 | ||
14297 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 14298 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
14299 | Use the 'source' command in another debug session to restore them."), |
14300 | &save_cmdlist); | |
1042e4c0 SS |
14301 | set_cmd_completer (c, filename_completer); |
14302 | ||
6149aea9 PA |
14303 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
14304 | deprecate_cmd (c, "save tracepoints"); | |
14305 | ||
1bedd215 | 14306 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
14307 | Breakpoint specific settings\n\ |
14308 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 14309 | pending breakpoint behavior"), |
fa8d40ab JJ |
14310 | &breakpoint_set_cmdlist, "set breakpoint ", |
14311 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 14312 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
14313 | Breakpoint specific settings\n\ |
14314 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 14315 | pending breakpoint behavior"), |
fa8d40ab JJ |
14316 | &breakpoint_show_cmdlist, "show breakpoint ", |
14317 | 0/*allow-unknown*/, &showlist); | |
14318 | ||
7915a72c AC |
14319 | add_setshow_auto_boolean_cmd ("pending", no_class, |
14320 | &pending_break_support, _("\ | |
14321 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
14322 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
14323 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
14324 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
14325 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 14326 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 14327 | NULL, |
920d2a44 | 14328 | show_pending_break_support, |
6e1d7d6c AC |
14329 | &breakpoint_set_cmdlist, |
14330 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
14331 | |
14332 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
14333 | |
14334 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
14335 | &automatic_hardware_breakpoints, _("\ | |
14336 | Set automatic usage of hardware breakpoints."), _("\ | |
14337 | Show automatic usage of hardware breakpoints."), _("\ | |
14338 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
14339 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
14340 | a warning will be emitted for such breakpoints."), | |
14341 | NULL, | |
14342 | show_automatic_hardware_breakpoints, | |
14343 | &breakpoint_set_cmdlist, | |
14344 | &breakpoint_show_cmdlist); | |
74960c60 | 14345 | |
33e5cbd6 PA |
14346 | add_setshow_enum_cmd ("always-inserted", class_support, |
14347 | always_inserted_enums, &always_inserted_mode, _("\ | |
74960c60 VP |
14348 | Set mode for inserting breakpoints."), _("\ |
14349 | Show mode for inserting breakpoints."), _("\ | |
33e5cbd6 PA |
14350 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
14351 | resumed, and removed when execution stops. When this mode is on,\n\ | |
14352 | breakpoints are inserted immediately and removed only when the user\n\ | |
14353 | deletes the breakpoint. When this mode is auto (which is the default),\n\ | |
14354 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ | |
14355 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ | |
14356 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ | |
14357 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), | |
74960c60 VP |
14358 | NULL, |
14359 | &show_always_inserted_mode, | |
14360 | &breakpoint_set_cmdlist, | |
14361 | &breakpoint_show_cmdlist); | |
f1310107 TJB |
14362 | |
14363 | add_com ("break-range", class_breakpoint, break_range_command, _("\ | |
14364 | Set a breakpoint for an address range.\n\ | |
14365 | break-range START-LOCATION, END-LOCATION\n\ | |
14366 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
14367 | LINENUM, for that line in the current file,\n\ | |
14368 | FILE:LINENUM, for that line in that file,\n\ | |
14369 | +OFFSET, for that number of lines after the current line\n\ | |
14370 | or the start of the range\n\ | |
14371 | FUNCTION, for the first line in that function,\n\ | |
14372 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
14373 | *ADDRESS, for the instruction at that address.\n\ | |
14374 | \n\ | |
14375 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
14376 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
14377 | range (including START-LOCATION and END-LOCATION).")); | |
14378 | ||
765dc015 | 14379 | automatic_hardware_breakpoints = 1; |
f3b1572e PA |
14380 | |
14381 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
c906108c | 14382 | } |