Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Everything about breakpoints, for GDB. |
8926118c | 2 | |
0b302171 | 3 | Copyright (C) 1986-2012 Free Software Foundation, Inc. |
c906108c | 4 | |
c5aa993b | 5 | This file is part of GDB. |
c906108c | 6 | |
c5aa993b JM |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 10 | (at your option) any later version. |
c906108c | 11 | |
c5aa993b JM |
12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
c906108c | 16 | |
c5aa993b | 17 | You should have received a copy of the GNU General Public License |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
19 | |
20 | #include "defs.h" | |
a6d9a66e | 21 | #include "arch-utils.h" |
c906108c | 22 | #include <ctype.h> |
776592bf | 23 | #include "hashtab.h" |
c906108c SS |
24 | #include "symtab.h" |
25 | #include "frame.h" | |
26 | #include "breakpoint.h" | |
1042e4c0 | 27 | #include "tracepoint.h" |
c906108c SS |
28 | #include "gdbtypes.h" |
29 | #include "expression.h" | |
30 | #include "gdbcore.h" | |
31 | #include "gdbcmd.h" | |
32 | #include "value.h" | |
33 | #include "command.h" | |
34 | #include "inferior.h" | |
35 | #include "gdbthread.h" | |
36 | #include "target.h" | |
37 | #include "language.h" | |
38 | #include "gdb_string.h" | |
50f182aa | 39 | #include "gdb-demangle.h" |
0ba1096a | 40 | #include "filenames.h" |
c906108c SS |
41 | #include "annotate.h" |
42 | #include "symfile.h" | |
43 | #include "objfiles.h" | |
0378c332 | 44 | #include "source.h" |
c5f0f3d0 | 45 | #include "linespec.h" |
c94fdfd0 | 46 | #include "completer.h" |
5b7f31a4 | 47 | #include "gdb.h" |
8b93c638 | 48 | #include "ui-out.h" |
e1507482 | 49 | #include "cli/cli-script.h" |
0225421b | 50 | #include "gdb_assert.h" |
fe898f56 | 51 | #include "block.h" |
a77053c2 | 52 | #include "solib.h" |
84acb35a JJ |
53 | #include "solist.h" |
54 | #include "observer.h" | |
60250e8b | 55 | #include "exceptions.h" |
765dc015 | 56 | #include "memattr.h" |
f7f9143b | 57 | #include "ada-lang.h" |
d1aa2f50 | 58 | #include "top.h" |
79a45b7d | 59 | #include "valprint.h" |
4efc6507 | 60 | #include "jit.h" |
a96d9b2e | 61 | #include "xml-syscall.h" |
65d79d4b | 62 | #include "parser-defs.h" |
e9cafbcc | 63 | #include "cli/cli-utils.h" |
be34f849 | 64 | #include "continuations.h" |
1bfeeb0f JL |
65 | #include "stack.h" |
66 | #include "skip.h" | |
049e32d3 | 67 | #include "record.h" |
edcc5120 | 68 | #include "gdb_regex.h" |
b775012e | 69 | #include "ax-gdb.h" |
c906108c | 70 | |
1042e4c0 SS |
71 | /* readline include files */ |
72 | #include "readline/readline.h" | |
73 | #include "readline/history.h" | |
74 | ||
75 | /* readline defines this. */ | |
76 | #undef savestring | |
77 | ||
034dad6f | 78 | #include "mi/mi-common.h" |
7371cf6d | 79 | #include "python/python.h" |
104c1213 | 80 | |
4a64f543 | 81 | /* Prototypes for local functions. */ |
c906108c | 82 | |
a14ed312 | 83 | static void enable_delete_command (char *, int); |
c906108c | 84 | |
a14ed312 | 85 | static void enable_once_command (char *, int); |
c906108c | 86 | |
816338b5 SS |
87 | static void enable_count_command (char *, int); |
88 | ||
a14ed312 | 89 | static void disable_command (char *, int); |
c906108c | 90 | |
a14ed312 | 91 | static void enable_command (char *, int); |
c906108c | 92 | |
95a42b64 TT |
93 | static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *, |
94 | void *), | |
95 | void *); | |
c906108c | 96 | |
a14ed312 | 97 | static void ignore_command (char *, int); |
c906108c | 98 | |
4efb68b1 | 99 | static int breakpoint_re_set_one (void *); |
c906108c | 100 | |
348d480f PA |
101 | static void breakpoint_re_set_default (struct breakpoint *); |
102 | ||
983af33b SDJ |
103 | static void create_sals_from_address_default (char **, |
104 | struct linespec_result *, | |
105 | enum bptype, char *, | |
106 | char **); | |
107 | ||
108 | static void create_breakpoints_sal_default (struct gdbarch *, | |
109 | struct linespec_result *, | |
110 | struct linespec_sals *, | |
111 | char *, enum bptype, | |
112 | enum bpdisp, int, int, | |
113 | int, | |
114 | const struct breakpoint_ops *, | |
115 | int, int, int); | |
116 | ||
117 | static void decode_linespec_default (struct breakpoint *, char **, | |
118 | struct symtabs_and_lines *); | |
119 | ||
a14ed312 | 120 | static void clear_command (char *, int); |
c906108c | 121 | |
a14ed312 | 122 | static void catch_command (char *, int); |
c906108c | 123 | |
a9634178 | 124 | static int can_use_hardware_watchpoint (struct value *); |
c906108c | 125 | |
98deb0da | 126 | static void break_command_1 (char *, int, int); |
c906108c | 127 | |
a14ed312 | 128 | static void mention (struct breakpoint *); |
c906108c | 129 | |
348d480f PA |
130 | static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *, |
131 | enum bptype, | |
c0a91b2b | 132 | const struct breakpoint_ops *); |
3742cc8b YQ |
133 | static struct bp_location *add_location_to_breakpoint (struct breakpoint *, |
134 | const struct symtab_and_line *); | |
135 | ||
4a64f543 MS |
136 | /* This function is used in gdbtk sources and thus can not be made |
137 | static. */ | |
63c252f8 | 138 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
348d480f | 139 | struct symtab_and_line, |
c0a91b2b TT |
140 | enum bptype, |
141 | const struct breakpoint_ops *); | |
c906108c | 142 | |
06edf0c0 PA |
143 | static struct breakpoint * |
144 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
145 | enum bptype type, | |
c0a91b2b | 146 | const struct breakpoint_ops *ops); |
06edf0c0 | 147 | |
76897487 KB |
148 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
149 | ||
a6d9a66e UW |
150 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
151 | CORE_ADDR bpaddr, | |
88f7da05 | 152 | enum bptype bptype); |
76897487 | 153 | |
6c95b8df PA |
154 | static void describe_other_breakpoints (struct gdbarch *, |
155 | struct program_space *, CORE_ADDR, | |
5af949e3 | 156 | struct obj_section *, int); |
c906108c | 157 | |
6c95b8df PA |
158 | static int breakpoint_address_match (struct address_space *aspace1, |
159 | CORE_ADDR addr1, | |
160 | struct address_space *aspace2, | |
161 | CORE_ADDR addr2); | |
162 | ||
85d721b8 PA |
163 | static int watchpoint_locations_match (struct bp_location *loc1, |
164 | struct bp_location *loc2); | |
165 | ||
f1310107 TJB |
166 | static int breakpoint_location_address_match (struct bp_location *bl, |
167 | struct address_space *aspace, | |
168 | CORE_ADDR addr); | |
169 | ||
a14ed312 | 170 | static void breakpoints_info (char *, int); |
c906108c | 171 | |
d77f58be SS |
172 | static void watchpoints_info (char *, int); |
173 | ||
e5a67952 MS |
174 | static int breakpoint_1 (char *, int, |
175 | int (*) (const struct breakpoint *)); | |
c906108c | 176 | |
4efb68b1 | 177 | static int breakpoint_cond_eval (void *); |
c906108c | 178 | |
4efb68b1 | 179 | static void cleanup_executing_breakpoints (void *); |
c906108c | 180 | |
a14ed312 | 181 | static void commands_command (char *, int); |
c906108c | 182 | |
a14ed312 | 183 | static void condition_command (char *, int); |
c906108c | 184 | |
c5aa993b JM |
185 | typedef enum |
186 | { | |
187 | mark_inserted, | |
188 | mark_uninserted | |
189 | } | |
190 | insertion_state_t; | |
c906108c | 191 | |
0bde7532 | 192 | static int remove_breakpoint (struct bp_location *, insertion_state_t); |
6c95b8df | 193 | static int remove_breakpoint_1 (struct bp_location *, insertion_state_t); |
c906108c | 194 | |
e514a9d6 | 195 | static enum print_stop_action print_bp_stop_message (bpstat bs); |
c906108c | 196 | |
4efb68b1 | 197 | static int watchpoint_check (void *); |
c906108c | 198 | |
a14ed312 | 199 | static void maintenance_info_breakpoints (char *, int); |
c906108c | 200 | |
a14ed312 | 201 | static int hw_breakpoint_used_count (void); |
c906108c | 202 | |
a1398e0c PA |
203 | static int hw_watchpoint_use_count (struct breakpoint *); |
204 | ||
205 | static int hw_watchpoint_used_count_others (struct breakpoint *except, | |
206 | enum bptype type, | |
207 | int *other_type_used); | |
c906108c | 208 | |
a14ed312 | 209 | static void hbreak_command (char *, int); |
c906108c | 210 | |
a14ed312 | 211 | static void thbreak_command (char *, int); |
c906108c | 212 | |
816338b5 SS |
213 | static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp, |
214 | int count); | |
c906108c | 215 | |
a14ed312 | 216 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 217 | |
a14ed312 | 218 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 219 | |
a14ed312 | 220 | static void stopat_command (char *arg, int from_tty); |
7a292a7a | 221 | |
a14ed312 | 222 | static char *ep_parse_optional_if_clause (char **arg); |
7a292a7a | 223 | |
d85310f7 MS |
224 | static void catch_exception_command_1 (enum exception_event_kind ex_event, |
225 | char *arg, int tempflag, int from_tty); | |
7a292a7a | 226 | |
a14ed312 | 227 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 228 | |
d03285ec UW |
229 | static void detach_single_step_breakpoints (void); |
230 | ||
6c95b8df PA |
231 | static int single_step_breakpoint_inserted_here_p (struct address_space *, |
232 | CORE_ADDR pc); | |
1aafd4da | 233 | |
fe3f5fa8 | 234 | static void free_bp_location (struct bp_location *loc); |
f431efe5 PA |
235 | static void incref_bp_location (struct bp_location *loc); |
236 | static void decref_bp_location (struct bp_location **loc); | |
fe3f5fa8 | 237 | |
39d61571 | 238 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 239 | |
b60e7edf | 240 | static void update_global_location_list (int); |
a5606eee | 241 | |
b60e7edf | 242 | static void update_global_location_list_nothrow (int); |
74960c60 | 243 | |
d77f58be | 244 | static int is_hardware_watchpoint (const struct breakpoint *bpt); |
74960c60 VP |
245 | |
246 | static void insert_breakpoint_locations (void); | |
a5606eee | 247 | |
a96d9b2e SDJ |
248 | static int syscall_catchpoint_p (struct breakpoint *b); |
249 | ||
1042e4c0 SS |
250 | static void tracepoints_info (char *, int); |
251 | ||
252 | static void delete_trace_command (char *, int); | |
253 | ||
254 | static void enable_trace_command (char *, int); | |
255 | ||
256 | static void disable_trace_command (char *, int); | |
257 | ||
258 | static void trace_pass_command (char *, int); | |
259 | ||
9c06b0b4 TJB |
260 | static int is_masked_watchpoint (const struct breakpoint *b); |
261 | ||
b775012e LM |
262 | static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address); |
263 | ||
983af33b SDJ |
264 | /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero |
265 | otherwise. */ | |
266 | ||
267 | static int strace_marker_p (struct breakpoint *b); | |
0fb4aa4b | 268 | |
edcc5120 TT |
269 | static void init_catchpoint (struct breakpoint *b, |
270 | struct gdbarch *gdbarch, int tempflag, | |
271 | char *cond_string, | |
272 | const struct breakpoint_ops *ops); | |
273 | ||
2060206e PA |
274 | /* The abstract base class all breakpoint_ops structures inherit |
275 | from. */ | |
276 | static struct breakpoint_ops base_breakpoint_ops; | |
277 | ||
278 | /* The breakpoint_ops structure to be inherited by all breakpoint_ops | |
279 | that are implemented on top of software or hardware breakpoints | |
280 | (user breakpoints, internal and momentary breakpoints, etc.). */ | |
281 | static struct breakpoint_ops bkpt_base_breakpoint_ops; | |
282 | ||
283 | /* Internal breakpoints class type. */ | |
06edf0c0 | 284 | static struct breakpoint_ops internal_breakpoint_ops; |
2060206e PA |
285 | |
286 | /* Momentary breakpoints class type. */ | |
06edf0c0 PA |
287 | static struct breakpoint_ops momentary_breakpoint_ops; |
288 | ||
2060206e PA |
289 | /* The breakpoint_ops structure to be used in regular user created |
290 | breakpoints. */ | |
291 | struct breakpoint_ops bkpt_breakpoint_ops; | |
292 | ||
5cea2a26 PA |
293 | /* A reference-counted struct command_line. This lets multiple |
294 | breakpoints share a single command list. */ | |
295 | struct counted_command_line | |
296 | { | |
297 | /* The reference count. */ | |
298 | int refc; | |
299 | ||
300 | /* The command list. */ | |
301 | struct command_line *commands; | |
302 | }; | |
303 | ||
304 | struct command_line * | |
305 | breakpoint_commands (struct breakpoint *b) | |
306 | { | |
307 | return b->commands ? b->commands->commands : NULL; | |
308 | } | |
3daf8fe5 | 309 | |
f3b1572e PA |
310 | /* Flag indicating that a command has proceeded the inferior past the |
311 | current breakpoint. */ | |
312 | ||
313 | static int breakpoint_proceeded; | |
314 | ||
956a9fb9 | 315 | const char * |
2cec12e5 AR |
316 | bpdisp_text (enum bpdisp disp) |
317 | { | |
4a64f543 MS |
318 | /* NOTE: the following values are a part of MI protocol and |
319 | represent values of 'disp' field returned when inferior stops at | |
320 | a breakpoint. */ | |
bc043ef3 | 321 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
cc59ec59 | 322 | |
2cec12e5 AR |
323 | return bpdisps[(int) disp]; |
324 | } | |
c906108c | 325 | |
4a64f543 | 326 | /* Prototypes for exported functions. */ |
c906108c | 327 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
4a64f543 | 328 | if such is available. */ |
c906108c SS |
329 | static int can_use_hw_watchpoints; |
330 | ||
920d2a44 AC |
331 | static void |
332 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
333 | struct cmd_list_element *c, | |
334 | const char *value) | |
335 | { | |
3e43a32a MS |
336 | fprintf_filtered (file, |
337 | _("Debugger's willingness to use " | |
338 | "watchpoint hardware is %s.\n"), | |
920d2a44 AC |
339 | value); |
340 | } | |
341 | ||
fa8d40ab JJ |
342 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
343 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
4a64f543 | 344 | for unrecognized breakpoint locations. |
fa8d40ab JJ |
345 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
346 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
347 | static void |
348 | show_pending_break_support (struct ui_file *file, int from_tty, | |
349 | struct cmd_list_element *c, | |
350 | const char *value) | |
351 | { | |
3e43a32a MS |
352 | fprintf_filtered (file, |
353 | _("Debugger's behavior regarding " | |
354 | "pending breakpoints is %s.\n"), | |
920d2a44 AC |
355 | value); |
356 | } | |
fa8d40ab | 357 | |
765dc015 | 358 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
4a64f543 | 359 | set with "break" but falling in read-only memory. |
765dc015 VP |
360 | If 0, gdb will warn about such breakpoints, but won't automatically |
361 | use hardware breakpoints. */ | |
362 | static int automatic_hardware_breakpoints; | |
363 | static void | |
364 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
365 | struct cmd_list_element *c, | |
366 | const char *value) | |
367 | { | |
3e43a32a MS |
368 | fprintf_filtered (file, |
369 | _("Automatic usage of hardware breakpoints is %s.\n"), | |
765dc015 VP |
370 | value); |
371 | } | |
372 | ||
33e5cbd6 PA |
373 | /* If on, gdb will keep breakpoints inserted even as inferior is |
374 | stopped, and immediately insert any new breakpoints. If off, gdb | |
375 | will insert breakpoints into inferior only when resuming it, and | |
376 | will remove breakpoints upon stop. If auto, GDB will behave as ON | |
377 | if in non-stop mode, and as OFF if all-stop mode.*/ | |
378 | ||
379 | static const char always_inserted_auto[] = "auto"; | |
380 | static const char always_inserted_on[] = "on"; | |
381 | static const char always_inserted_off[] = "off"; | |
40478521 | 382 | static const char *const always_inserted_enums[] = { |
33e5cbd6 PA |
383 | always_inserted_auto, |
384 | always_inserted_off, | |
385 | always_inserted_on, | |
386 | NULL | |
387 | }; | |
388 | static const char *always_inserted_mode = always_inserted_auto; | |
389 | static void | |
74960c60 | 390 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 391 | struct cmd_list_element *c, const char *value) |
74960c60 | 392 | { |
33e5cbd6 | 393 | if (always_inserted_mode == always_inserted_auto) |
3e43a32a MS |
394 | fprintf_filtered (file, |
395 | _("Always inserted breakpoint " | |
396 | "mode is %s (currently %s).\n"), | |
33e5cbd6 PA |
397 | value, |
398 | breakpoints_always_inserted_mode () ? "on" : "off"); | |
399 | else | |
3e43a32a MS |
400 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), |
401 | value); | |
74960c60 VP |
402 | } |
403 | ||
33e5cbd6 PA |
404 | int |
405 | breakpoints_always_inserted_mode (void) | |
406 | { | |
049e32d3 PA |
407 | return ((always_inserted_mode == always_inserted_on |
408 | || (always_inserted_mode == always_inserted_auto && non_stop)) | |
409 | && !RECORD_IS_USED); | |
33e5cbd6 | 410 | } |
765dc015 | 411 | |
b775012e LM |
412 | static const char condition_evaluation_both[] = "host or target"; |
413 | ||
414 | /* Modes for breakpoint condition evaluation. */ | |
415 | static const char condition_evaluation_auto[] = "auto"; | |
416 | static const char condition_evaluation_host[] = "host"; | |
417 | static const char condition_evaluation_target[] = "target"; | |
418 | static const char *const condition_evaluation_enums[] = { | |
419 | condition_evaluation_auto, | |
420 | condition_evaluation_host, | |
421 | condition_evaluation_target, | |
422 | NULL | |
423 | }; | |
424 | ||
425 | /* Global that holds the current mode for breakpoint condition evaluation. */ | |
426 | static const char *condition_evaluation_mode_1 = condition_evaluation_auto; | |
427 | ||
428 | /* Global that we use to display information to the user (gets its value from | |
429 | condition_evaluation_mode_1. */ | |
430 | static const char *condition_evaluation_mode = condition_evaluation_auto; | |
431 | ||
432 | /* Translate a condition evaluation mode MODE into either "host" | |
433 | or "target". This is used mostly to translate from "auto" to the | |
434 | real setting that is being used. It returns the translated | |
435 | evaluation mode. */ | |
436 | ||
437 | static const char * | |
438 | translate_condition_evaluation_mode (const char *mode) | |
439 | { | |
440 | if (mode == condition_evaluation_auto) | |
441 | { | |
442 | if (target_supports_evaluation_of_breakpoint_conditions ()) | |
443 | return condition_evaluation_target; | |
444 | else | |
445 | return condition_evaluation_host; | |
446 | } | |
447 | else | |
448 | return mode; | |
449 | } | |
450 | ||
451 | /* Discovers what condition_evaluation_auto translates to. */ | |
452 | ||
453 | static const char * | |
454 | breakpoint_condition_evaluation_mode (void) | |
455 | { | |
456 | return translate_condition_evaluation_mode (condition_evaluation_mode); | |
457 | } | |
458 | ||
459 | /* Return true if GDB should evaluate breakpoint conditions or false | |
460 | otherwise. */ | |
461 | ||
462 | static int | |
463 | gdb_evaluates_breakpoint_condition_p (void) | |
464 | { | |
465 | const char *mode = breakpoint_condition_evaluation_mode (); | |
466 | ||
467 | return (mode == condition_evaluation_host); | |
468 | } | |
469 | ||
a14ed312 | 470 | void _initialize_breakpoint (void); |
c906108c | 471 | |
c906108c SS |
472 | /* Are we executing breakpoint commands? */ |
473 | static int executing_breakpoint_commands; | |
474 | ||
c02f5703 MS |
475 | /* Are overlay event breakpoints enabled? */ |
476 | static int overlay_events_enabled; | |
477 | ||
e09342b5 TJB |
478 | /* See description in breakpoint.h. */ |
479 | int target_exact_watchpoints = 0; | |
480 | ||
c906108c | 481 | /* Walk the following statement or block through all breakpoints. |
e5dd4106 | 482 | ALL_BREAKPOINTS_SAFE does so even if the statement deletes the |
4a64f543 | 483 | current breakpoint. */ |
c906108c | 484 | |
5c44784c | 485 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 486 | |
5c44784c JM |
487 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
488 | for (B = breakpoint_chain; \ | |
489 | B ? (TMP=B->next, 1): 0; \ | |
490 | B = TMP) | |
c906108c | 491 | |
4a64f543 MS |
492 | /* Similar iterator for the low-level breakpoints. SAFE variant is |
493 | not provided so update_global_location_list must not be called | |
494 | while executing the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 495 | |
876fa593 JK |
496 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
497 | for (BP_TMP = bp_location; \ | |
498 | BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \ | |
499 | BP_TMP++) | |
7cc221ef | 500 | |
b775012e LM |
501 | /* Iterates through locations with address ADDRESS for the currently selected |
502 | program space. BP_LOCP_TMP points to each object. BP_LOCP_START points | |
503 | to where the loop should start from. | |
504 | If BP_LOCP_START is a NULL pointer, the macro automatically seeks the | |
505 | appropriate location to start with. */ | |
506 | ||
507 | #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \ | |
508 | for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \ | |
509 | BP_LOCP_TMP = BP_LOCP_START; \ | |
510 | BP_LOCP_START \ | |
511 | && (BP_LOCP_TMP < bp_location + bp_location_count \ | |
512 | && (*BP_LOCP_TMP)->address == ADDRESS); \ | |
513 | BP_LOCP_TMP++) | |
514 | ||
1042e4c0 SS |
515 | /* Iterator for tracepoints only. */ |
516 | ||
517 | #define ALL_TRACEPOINTS(B) \ | |
518 | for (B = breakpoint_chain; B; B = B->next) \ | |
d77f58be | 519 | if (is_tracepoint (B)) |
1042e4c0 | 520 | |
7cc221ef | 521 | /* Chains of all breakpoints defined. */ |
c906108c SS |
522 | |
523 | struct breakpoint *breakpoint_chain; | |
524 | ||
876fa593 JK |
525 | /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */ |
526 | ||
527 | static struct bp_location **bp_location; | |
528 | ||
529 | /* Number of elements of BP_LOCATION. */ | |
530 | ||
531 | static unsigned bp_location_count; | |
532 | ||
4a64f543 MS |
533 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
534 | ADDRESS for the current elements of BP_LOCATION which get a valid | |
535 | result from bp_location_has_shadow. You can use it for roughly | |
536 | limiting the subrange of BP_LOCATION to scan for shadow bytes for | |
537 | an address you need to read. */ | |
876fa593 JK |
538 | |
539 | static CORE_ADDR bp_location_placed_address_before_address_max; | |
540 | ||
4a64f543 MS |
541 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
542 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of | |
543 | BP_LOCATION which get a valid result from bp_location_has_shadow. | |
544 | You can use it for roughly limiting the subrange of BP_LOCATION to | |
545 | scan for shadow bytes for an address you need to read. */ | |
876fa593 JK |
546 | |
547 | static CORE_ADDR bp_location_shadow_len_after_address_max; | |
7cc221ef | 548 | |
4a64f543 MS |
549 | /* The locations that no longer correspond to any breakpoint, unlinked |
550 | from bp_location array, but for which a hit may still be reported | |
551 | by a target. */ | |
20874c92 VP |
552 | VEC(bp_location_p) *moribund_locations = NULL; |
553 | ||
c906108c SS |
554 | /* Number of last breakpoint made. */ |
555 | ||
95a42b64 TT |
556 | static int breakpoint_count; |
557 | ||
86b17b60 PA |
558 | /* The value of `breakpoint_count' before the last command that |
559 | created breakpoints. If the last (break-like) command created more | |
560 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
561 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
562 | static int prev_breakpoint_count; | |
c906108c | 563 | |
1042e4c0 SS |
564 | /* Number of last tracepoint made. */ |
565 | ||
95a42b64 | 566 | static int tracepoint_count; |
1042e4c0 | 567 | |
6149aea9 PA |
568 | static struct cmd_list_element *breakpoint_set_cmdlist; |
569 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
9291a0cd | 570 | struct cmd_list_element *save_cmdlist; |
6149aea9 | 571 | |
468d015d JJ |
572 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
573 | static int | |
574 | breakpoint_enabled (struct breakpoint *b) | |
575 | { | |
0d381245 | 576 | return (b->enable_state == bp_enabled); |
468d015d JJ |
577 | } |
578 | ||
c906108c SS |
579 | /* Set breakpoint count to NUM. */ |
580 | ||
95a42b64 | 581 | static void |
fba45db2 | 582 | set_breakpoint_count (int num) |
c906108c | 583 | { |
86b17b60 | 584 | prev_breakpoint_count = breakpoint_count; |
c906108c | 585 | breakpoint_count = num; |
4fa62494 | 586 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
587 | } |
588 | ||
86b17b60 PA |
589 | /* Used by `start_rbreak_breakpoints' below, to record the current |
590 | breakpoint count before "rbreak" creates any breakpoint. */ | |
591 | static int rbreak_start_breakpoint_count; | |
592 | ||
95a42b64 TT |
593 | /* Called at the start an "rbreak" command to record the first |
594 | breakpoint made. */ | |
86b17b60 | 595 | |
95a42b64 TT |
596 | void |
597 | start_rbreak_breakpoints (void) | |
598 | { | |
86b17b60 | 599 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
600 | } |
601 | ||
602 | /* Called at the end of an "rbreak" command to record the last | |
603 | breakpoint made. */ | |
86b17b60 | 604 | |
95a42b64 TT |
605 | void |
606 | end_rbreak_breakpoints (void) | |
607 | { | |
86b17b60 | 608 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
609 | } |
610 | ||
4a64f543 | 611 | /* Used in run_command to zero the hit count when a new run starts. */ |
c906108c SS |
612 | |
613 | void | |
fba45db2 | 614 | clear_breakpoint_hit_counts (void) |
c906108c SS |
615 | { |
616 | struct breakpoint *b; | |
617 | ||
618 | ALL_BREAKPOINTS (b) | |
619 | b->hit_count = 0; | |
620 | } | |
621 | ||
9add0f1b TT |
622 | /* Allocate a new counted_command_line with reference count of 1. |
623 | The new structure owns COMMANDS. */ | |
624 | ||
625 | static struct counted_command_line * | |
626 | alloc_counted_command_line (struct command_line *commands) | |
627 | { | |
628 | struct counted_command_line *result | |
629 | = xmalloc (sizeof (struct counted_command_line)); | |
cc59ec59 | 630 | |
9add0f1b TT |
631 | result->refc = 1; |
632 | result->commands = commands; | |
633 | return result; | |
634 | } | |
635 | ||
636 | /* Increment reference count. This does nothing if CMD is NULL. */ | |
637 | ||
638 | static void | |
639 | incref_counted_command_line (struct counted_command_line *cmd) | |
640 | { | |
641 | if (cmd) | |
642 | ++cmd->refc; | |
643 | } | |
644 | ||
645 | /* Decrement reference count. If the reference count reaches 0, | |
646 | destroy the counted_command_line. Sets *CMDP to NULL. This does | |
647 | nothing if *CMDP is NULL. */ | |
648 | ||
649 | static void | |
650 | decref_counted_command_line (struct counted_command_line **cmdp) | |
651 | { | |
652 | if (*cmdp) | |
653 | { | |
654 | if (--(*cmdp)->refc == 0) | |
655 | { | |
656 | free_command_lines (&(*cmdp)->commands); | |
657 | xfree (*cmdp); | |
658 | } | |
659 | *cmdp = NULL; | |
660 | } | |
661 | } | |
662 | ||
663 | /* A cleanup function that calls decref_counted_command_line. */ | |
664 | ||
665 | static void | |
666 | do_cleanup_counted_command_line (void *arg) | |
667 | { | |
668 | decref_counted_command_line (arg); | |
669 | } | |
670 | ||
671 | /* Create a cleanup that calls decref_counted_command_line on the | |
672 | argument. */ | |
673 | ||
674 | static struct cleanup * | |
675 | make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp) | |
676 | { | |
677 | return make_cleanup (do_cleanup_counted_command_line, cmdp); | |
678 | } | |
679 | ||
c906108c | 680 | \f |
48cb2d85 VP |
681 | /* Return the breakpoint with the specified number, or NULL |
682 | if the number does not refer to an existing breakpoint. */ | |
683 | ||
684 | struct breakpoint * | |
685 | get_breakpoint (int num) | |
686 | { | |
687 | struct breakpoint *b; | |
688 | ||
689 | ALL_BREAKPOINTS (b) | |
690 | if (b->number == num) | |
691 | return b; | |
692 | ||
693 | return NULL; | |
694 | } | |
5c44784c | 695 | |
c906108c | 696 | \f |
adc36818 | 697 | |
b775012e LM |
698 | /* Mark locations as "conditions have changed" in case the target supports |
699 | evaluating conditions on its side. */ | |
700 | ||
701 | static void | |
702 | mark_breakpoint_modified (struct breakpoint *b) | |
703 | { | |
704 | struct bp_location *loc; | |
705 | ||
706 | /* This is only meaningful if the target is | |
707 | evaluating conditions and if the user has | |
708 | opted for condition evaluation on the target's | |
709 | side. */ | |
710 | if (gdb_evaluates_breakpoint_condition_p () | |
711 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
712 | return; | |
713 | ||
714 | if (!is_breakpoint (b)) | |
715 | return; | |
716 | ||
717 | for (loc = b->loc; loc; loc = loc->next) | |
718 | loc->condition_changed = condition_modified; | |
719 | } | |
720 | ||
721 | /* Mark location as "conditions have changed" in case the target supports | |
722 | evaluating conditions on its side. */ | |
723 | ||
724 | static void | |
725 | mark_breakpoint_location_modified (struct bp_location *loc) | |
726 | { | |
727 | /* This is only meaningful if the target is | |
728 | evaluating conditions and if the user has | |
729 | opted for condition evaluation on the target's | |
730 | side. */ | |
731 | if (gdb_evaluates_breakpoint_condition_p () | |
732 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
733 | ||
734 | return; | |
735 | ||
736 | if (!is_breakpoint (loc->owner)) | |
737 | return; | |
738 | ||
739 | loc->condition_changed = condition_modified; | |
740 | } | |
741 | ||
742 | /* Sets the condition-evaluation mode using the static global | |
743 | condition_evaluation_mode. */ | |
744 | ||
745 | static void | |
746 | set_condition_evaluation_mode (char *args, int from_tty, | |
747 | struct cmd_list_element *c) | |
748 | { | |
749 | struct breakpoint *b; | |
750 | const char *old_mode, *new_mode; | |
751 | ||
752 | if ((condition_evaluation_mode_1 == condition_evaluation_target) | |
753 | && !target_supports_evaluation_of_breakpoint_conditions ()) | |
754 | { | |
755 | condition_evaluation_mode_1 = condition_evaluation_mode; | |
756 | warning (_("Target does not support breakpoint condition evaluation.\n" | |
757 | "Using host evaluation mode instead.")); | |
758 | return; | |
759 | } | |
760 | ||
761 | new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1); | |
762 | old_mode = translate_condition_evaluation_mode (condition_evaluation_mode); | |
763 | ||
764 | /* Only update the mode if the user picked a different one. */ | |
765 | if (new_mode != old_mode) | |
766 | { | |
767 | struct bp_location *loc, **loc_tmp; | |
768 | /* If the user switched to a different evaluation mode, we | |
769 | need to synch the changes with the target as follows: | |
770 | ||
771 | "host" -> "target": Send all (valid) conditions to the target. | |
772 | "target" -> "host": Remove all the conditions from the target. | |
773 | */ | |
774 | ||
775 | /* Flip the switch. */ | |
776 | condition_evaluation_mode = condition_evaluation_mode_1; | |
777 | ||
778 | if (new_mode == condition_evaluation_target) | |
779 | { | |
780 | /* Mark everything modified and synch conditions with the | |
781 | target. */ | |
782 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
783 | mark_breakpoint_location_modified (loc); | |
784 | } | |
785 | else | |
786 | { | |
787 | /* Manually mark non-duplicate locations to synch conditions | |
788 | with the target. We do this to remove all the conditions the | |
789 | target knows about. */ | |
790 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
791 | if (is_breakpoint (loc->owner) && loc->inserted) | |
792 | loc->needs_update = 1; | |
793 | } | |
794 | ||
795 | /* Do the update. */ | |
796 | update_global_location_list (1); | |
797 | } | |
798 | ||
799 | return; | |
800 | } | |
801 | ||
802 | /* Shows the current mode of breakpoint condition evaluation. Explicitly shows | |
803 | what "auto" is translating to. */ | |
804 | ||
805 | static void | |
806 | show_condition_evaluation_mode (struct ui_file *file, int from_tty, | |
807 | struct cmd_list_element *c, const char *value) | |
808 | { | |
809 | if (condition_evaluation_mode == condition_evaluation_auto) | |
810 | fprintf_filtered (file, | |
811 | _("Breakpoint condition evaluation " | |
812 | "mode is %s (currently %s).\n"), | |
813 | value, | |
814 | breakpoint_condition_evaluation_mode ()); | |
815 | else | |
816 | fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"), | |
817 | value); | |
818 | } | |
819 | ||
820 | /* A comparison function for bp_location AP and BP that is used by | |
821 | bsearch. This comparison function only cares about addresses, unlike | |
822 | the more general bp_location_compare function. */ | |
823 | ||
824 | static int | |
825 | bp_location_compare_addrs (const void *ap, const void *bp) | |
826 | { | |
827 | struct bp_location *a = *(void **) ap; | |
828 | struct bp_location *b = *(void **) bp; | |
829 | ||
830 | if (a->address == b->address) | |
831 | return 0; | |
832 | else | |
833 | return ((a->address > b->address) - (a->address < b->address)); | |
834 | } | |
835 | ||
836 | /* Helper function to skip all bp_locations with addresses | |
837 | less than ADDRESS. It returns the first bp_location that | |
838 | is greater than or equal to ADDRESS. If none is found, just | |
839 | return NULL. */ | |
840 | ||
841 | static struct bp_location ** | |
842 | get_first_locp_gte_addr (CORE_ADDR address) | |
843 | { | |
844 | struct bp_location dummy_loc; | |
845 | struct bp_location *dummy_locp = &dummy_loc; | |
846 | struct bp_location **locp_found = NULL; | |
847 | ||
848 | /* Initialize the dummy location's address field. */ | |
849 | memset (&dummy_loc, 0, sizeof (struct bp_location)); | |
850 | dummy_loc.address = address; | |
851 | ||
852 | /* Find a close match to the first location at ADDRESS. */ | |
853 | locp_found = bsearch (&dummy_locp, bp_location, bp_location_count, | |
854 | sizeof (struct bp_location **), | |
855 | bp_location_compare_addrs); | |
856 | ||
857 | /* Nothing was found, nothing left to do. */ | |
858 | if (locp_found == NULL) | |
859 | return NULL; | |
860 | ||
861 | /* We may have found a location that is at ADDRESS but is not the first in the | |
862 | location's list. Go backwards (if possible) and locate the first one. */ | |
863 | while ((locp_found - 1) >= bp_location | |
864 | && (*(locp_found - 1))->address == address) | |
865 | locp_found--; | |
866 | ||
867 | return locp_found; | |
868 | } | |
869 | ||
adc36818 PM |
870 | void |
871 | set_breakpoint_condition (struct breakpoint *b, char *exp, | |
872 | int from_tty) | |
873 | { | |
3a5c3e22 PA |
874 | xfree (b->cond_string); |
875 | b->cond_string = NULL; | |
adc36818 | 876 | |
3a5c3e22 | 877 | if (is_watchpoint (b)) |
adc36818 | 878 | { |
3a5c3e22 PA |
879 | struct watchpoint *w = (struct watchpoint *) b; |
880 | ||
881 | xfree (w->cond_exp); | |
882 | w->cond_exp = NULL; | |
883 | } | |
884 | else | |
885 | { | |
886 | struct bp_location *loc; | |
887 | ||
888 | for (loc = b->loc; loc; loc = loc->next) | |
889 | { | |
890 | xfree (loc->cond); | |
891 | loc->cond = NULL; | |
b775012e LM |
892 | |
893 | /* No need to free the condition agent expression | |
894 | bytecode (if we have one). We will handle this | |
895 | when we go through update_global_location_list. */ | |
3a5c3e22 | 896 | } |
adc36818 | 897 | } |
adc36818 PM |
898 | |
899 | if (*exp == 0) | |
900 | { | |
901 | if (from_tty) | |
902 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
903 | } | |
904 | else | |
905 | { | |
906 | char *arg = exp; | |
cc59ec59 | 907 | |
adc36818 PM |
908 | /* I don't know if it matters whether this is the string the user |
909 | typed in or the decompiled expression. */ | |
910 | b->cond_string = xstrdup (arg); | |
911 | b->condition_not_parsed = 0; | |
912 | ||
913 | if (is_watchpoint (b)) | |
914 | { | |
3a5c3e22 PA |
915 | struct watchpoint *w = (struct watchpoint *) b; |
916 | ||
adc36818 PM |
917 | innermost_block = NULL; |
918 | arg = exp; | |
3a5c3e22 | 919 | w->cond_exp = parse_exp_1 (&arg, 0, 0); |
adc36818 PM |
920 | if (*arg) |
921 | error (_("Junk at end of expression")); | |
3a5c3e22 | 922 | w->cond_exp_valid_block = innermost_block; |
adc36818 PM |
923 | } |
924 | else | |
925 | { | |
3a5c3e22 PA |
926 | struct bp_location *loc; |
927 | ||
adc36818 PM |
928 | for (loc = b->loc; loc; loc = loc->next) |
929 | { | |
930 | arg = exp; | |
931 | loc->cond = | |
932 | parse_exp_1 (&arg, block_for_pc (loc->address), 0); | |
933 | if (*arg) | |
934 | error (_("Junk at end of expression")); | |
935 | } | |
936 | } | |
937 | } | |
b775012e LM |
938 | mark_breakpoint_modified (b); |
939 | ||
adc36818 | 940 | breakpoints_changed (); |
8d3788bd | 941 | observer_notify_breakpoint_modified (b); |
adc36818 PM |
942 | } |
943 | ||
c906108c SS |
944 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
945 | ||
946 | static void | |
fba45db2 | 947 | condition_command (char *arg, int from_tty) |
c906108c | 948 | { |
52f0bd74 | 949 | struct breakpoint *b; |
c906108c | 950 | char *p; |
52f0bd74 | 951 | int bnum; |
c906108c SS |
952 | |
953 | if (arg == 0) | |
e2e0b3e5 | 954 | error_no_arg (_("breakpoint number")); |
c906108c SS |
955 | |
956 | p = arg; | |
957 | bnum = get_number (&p); | |
5c44784c | 958 | if (bnum == 0) |
8a3fe4f8 | 959 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
960 | |
961 | ALL_BREAKPOINTS (b) | |
962 | if (b->number == bnum) | |
2f069f6f | 963 | { |
7371cf6d PM |
964 | /* Check if this breakpoint has a Python object assigned to |
965 | it, and if it has a definition of the "stop" | |
966 | method. This method and conditions entered into GDB from | |
967 | the CLI are mutually exclusive. */ | |
968 | if (b->py_bp_object | |
969 | && gdbpy_breakpoint_has_py_cond (b->py_bp_object)) | |
970 | error (_("Cannot set a condition where a Python 'stop' " | |
971 | "method has been defined in the breakpoint.")); | |
2566ad2d | 972 | set_breakpoint_condition (b, p, from_tty); |
b775012e LM |
973 | |
974 | if (is_breakpoint (b)) | |
975 | update_global_location_list (1); | |
976 | ||
2f069f6f JB |
977 | return; |
978 | } | |
c906108c | 979 | |
8a3fe4f8 | 980 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
981 | } |
982 | ||
a7bdde9e VP |
983 | /* Check that COMMAND do not contain commands that are suitable |
984 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
985 | Throw if any such commands is found. */ |
986 | ||
a7bdde9e VP |
987 | static void |
988 | check_no_tracepoint_commands (struct command_line *commands) | |
989 | { | |
990 | struct command_line *c; | |
cc59ec59 | 991 | |
a7bdde9e VP |
992 | for (c = commands; c; c = c->next) |
993 | { | |
994 | int i; | |
995 | ||
996 | if (c->control_type == while_stepping_control) | |
3e43a32a MS |
997 | error (_("The 'while-stepping' command can " |
998 | "only be used for tracepoints")); | |
a7bdde9e VP |
999 | |
1000 | for (i = 0; i < c->body_count; ++i) | |
1001 | check_no_tracepoint_commands ((c->body_list)[i]); | |
1002 | ||
1003 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 1004 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
1005 | command directly. */ |
1006 | if (strstr (c->line, "collect ") == c->line) | |
1007 | error (_("The 'collect' command can only be used for tracepoints")); | |
1008 | ||
51661e93 VP |
1009 | if (strstr (c->line, "teval ") == c->line) |
1010 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
1011 | } |
1012 | } | |
1013 | ||
d77f58be SS |
1014 | /* Encapsulate tests for different types of tracepoints. */ |
1015 | ||
d9b3f62e PA |
1016 | static int |
1017 | is_tracepoint_type (enum bptype type) | |
1018 | { | |
1019 | return (type == bp_tracepoint | |
1020 | || type == bp_fast_tracepoint | |
1021 | || type == bp_static_tracepoint); | |
1022 | } | |
1023 | ||
a7bdde9e | 1024 | int |
d77f58be | 1025 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 1026 | { |
d9b3f62e | 1027 | return is_tracepoint_type (b->type); |
a7bdde9e | 1028 | } |
d9b3f62e | 1029 | |
e5dd4106 | 1030 | /* A helper function that validates that COMMANDS are valid for a |
95a42b64 TT |
1031 | breakpoint. This function will throw an exception if a problem is |
1032 | found. */ | |
48cb2d85 | 1033 | |
95a42b64 TT |
1034 | static void |
1035 | validate_commands_for_breakpoint (struct breakpoint *b, | |
1036 | struct command_line *commands) | |
48cb2d85 | 1037 | { |
d77f58be | 1038 | if (is_tracepoint (b)) |
a7bdde9e | 1039 | { |
4a64f543 MS |
1040 | /* We need to verify that each top-level element of commands is |
1041 | valid for tracepoints, that there's at most one | |
1042 | while-stepping element, and that while-stepping's body has | |
1043 | valid tracing commands excluding nested while-stepping. */ | |
a7bdde9e VP |
1044 | struct command_line *c; |
1045 | struct command_line *while_stepping = 0; | |
1046 | for (c = commands; c; c = c->next) | |
1047 | { | |
a7bdde9e VP |
1048 | if (c->control_type == while_stepping_control) |
1049 | { | |
1050 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
1051 | error (_("The 'while-stepping' command " |
1052 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 1053 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
1054 | error (_("The 'while-stepping' command " |
1055 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
1056 | |
1057 | if (while_stepping) | |
3e43a32a MS |
1058 | error (_("The 'while-stepping' command " |
1059 | "can be used only once")); | |
a7bdde9e VP |
1060 | else |
1061 | while_stepping = c; | |
1062 | } | |
1063 | } | |
1064 | if (while_stepping) | |
1065 | { | |
1066 | struct command_line *c2; | |
1067 | ||
1068 | gdb_assert (while_stepping->body_count == 1); | |
1069 | c2 = while_stepping->body_list[0]; | |
1070 | for (; c2; c2 = c2->next) | |
1071 | { | |
a7bdde9e VP |
1072 | if (c2->control_type == while_stepping_control) |
1073 | error (_("The 'while-stepping' command cannot be nested")); | |
1074 | } | |
1075 | } | |
1076 | } | |
1077 | else | |
1078 | { | |
1079 | check_no_tracepoint_commands (commands); | |
1080 | } | |
95a42b64 TT |
1081 | } |
1082 | ||
0fb4aa4b PA |
1083 | /* Return a vector of all the static tracepoints set at ADDR. The |
1084 | caller is responsible for releasing the vector. */ | |
1085 | ||
1086 | VEC(breakpoint_p) * | |
1087 | static_tracepoints_here (CORE_ADDR addr) | |
1088 | { | |
1089 | struct breakpoint *b; | |
1090 | VEC(breakpoint_p) *found = 0; | |
1091 | struct bp_location *loc; | |
1092 | ||
1093 | ALL_BREAKPOINTS (b) | |
1094 | if (b->type == bp_static_tracepoint) | |
1095 | { | |
1096 | for (loc = b->loc; loc; loc = loc->next) | |
1097 | if (loc->address == addr) | |
1098 | VEC_safe_push(breakpoint_p, found, b); | |
1099 | } | |
1100 | ||
1101 | return found; | |
1102 | } | |
1103 | ||
95a42b64 | 1104 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 1105 | validate that only allowed commands are included. */ |
95a42b64 TT |
1106 | |
1107 | void | |
4a64f543 MS |
1108 | breakpoint_set_commands (struct breakpoint *b, |
1109 | struct command_line *commands) | |
95a42b64 TT |
1110 | { |
1111 | validate_commands_for_breakpoint (b, commands); | |
a7bdde9e | 1112 | |
9add0f1b TT |
1113 | decref_counted_command_line (&b->commands); |
1114 | b->commands = alloc_counted_command_line (commands); | |
48cb2d85 | 1115 | breakpoints_changed (); |
8d3788bd | 1116 | observer_notify_breakpoint_modified (b); |
48cb2d85 VP |
1117 | } |
1118 | ||
45a43567 TT |
1119 | /* Set the internal `silent' flag on the breakpoint. Note that this |
1120 | is not the same as the "silent" that may appear in the breakpoint's | |
1121 | commands. */ | |
1122 | ||
1123 | void | |
1124 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
1125 | { | |
1126 | int old_silent = b->silent; | |
1127 | ||
1128 | b->silent = silent; | |
1129 | if (old_silent != silent) | |
8d3788bd | 1130 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1131 | } |
1132 | ||
1133 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
1134 | breakpoint work for any thread. */ | |
1135 | ||
1136 | void | |
1137 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
1138 | { | |
1139 | int old_thread = b->thread; | |
1140 | ||
1141 | b->thread = thread; | |
1142 | if (old_thread != thread) | |
8d3788bd | 1143 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1144 | } |
1145 | ||
1146 | /* Set the task for this breakpoint. If TASK is 0, make the | |
1147 | breakpoint work for any task. */ | |
1148 | ||
1149 | void | |
1150 | breakpoint_set_task (struct breakpoint *b, int task) | |
1151 | { | |
1152 | int old_task = b->task; | |
1153 | ||
1154 | b->task = task; | |
1155 | if (old_task != task) | |
8d3788bd | 1156 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1157 | } |
1158 | ||
95a42b64 TT |
1159 | void |
1160 | check_tracepoint_command (char *line, void *closure) | |
a7bdde9e VP |
1161 | { |
1162 | struct breakpoint *b = closure; | |
cc59ec59 | 1163 | |
a7bdde9e VP |
1164 | validate_actionline (&line, b); |
1165 | } | |
1166 | ||
95a42b64 TT |
1167 | /* A structure used to pass information through |
1168 | map_breakpoint_numbers. */ | |
1169 | ||
1170 | struct commands_info | |
1171 | { | |
1172 | /* True if the command was typed at a tty. */ | |
1173 | int from_tty; | |
86b17b60 PA |
1174 | |
1175 | /* The breakpoint range spec. */ | |
1176 | char *arg; | |
1177 | ||
95a42b64 TT |
1178 | /* Non-NULL if the body of the commands are being read from this |
1179 | already-parsed command. */ | |
1180 | struct command_line *control; | |
86b17b60 | 1181 | |
95a42b64 TT |
1182 | /* The command lines read from the user, or NULL if they have not |
1183 | yet been read. */ | |
1184 | struct counted_command_line *cmd; | |
1185 | }; | |
1186 | ||
1187 | /* A callback for map_breakpoint_numbers that sets the commands for | |
1188 | commands_command. */ | |
1189 | ||
c906108c | 1190 | static void |
95a42b64 | 1191 | do_map_commands_command (struct breakpoint *b, void *data) |
c906108c | 1192 | { |
95a42b64 | 1193 | struct commands_info *info = data; |
c906108c | 1194 | |
95a42b64 TT |
1195 | if (info->cmd == NULL) |
1196 | { | |
1197 | struct command_line *l; | |
5c44784c | 1198 | |
95a42b64 TT |
1199 | if (info->control != NULL) |
1200 | l = copy_command_lines (info->control->body_list[0]); | |
1201 | else | |
86b17b60 PA |
1202 | { |
1203 | struct cleanup *old_chain; | |
1204 | char *str; | |
c5aa993b | 1205 | |
3e43a32a MS |
1206 | str = xstrprintf (_("Type commands for breakpoint(s) " |
1207 | "%s, one per line."), | |
86b17b60 PA |
1208 | info->arg); |
1209 | ||
1210 | old_chain = make_cleanup (xfree, str); | |
1211 | ||
1212 | l = read_command_lines (str, | |
1213 | info->from_tty, 1, | |
d77f58be | 1214 | (is_tracepoint (b) |
86b17b60 PA |
1215 | ? check_tracepoint_command : 0), |
1216 | b); | |
1217 | ||
1218 | do_cleanups (old_chain); | |
1219 | } | |
a7bdde9e | 1220 | |
95a42b64 TT |
1221 | info->cmd = alloc_counted_command_line (l); |
1222 | } | |
1223 | ||
1224 | /* If a breakpoint was on the list more than once, we don't need to | |
1225 | do anything. */ | |
1226 | if (b->commands != info->cmd) | |
1227 | { | |
1228 | validate_commands_for_breakpoint (b, info->cmd->commands); | |
1229 | incref_counted_command_line (info->cmd); | |
1230 | decref_counted_command_line (&b->commands); | |
1231 | b->commands = info->cmd; | |
1232 | breakpoints_changed (); | |
8d3788bd | 1233 | observer_notify_breakpoint_modified (b); |
c5aa993b | 1234 | } |
95a42b64 TT |
1235 | } |
1236 | ||
1237 | static void | |
4a64f543 MS |
1238 | commands_command_1 (char *arg, int from_tty, |
1239 | struct command_line *control) | |
95a42b64 TT |
1240 | { |
1241 | struct cleanup *cleanups; | |
1242 | struct commands_info info; | |
1243 | ||
1244 | info.from_tty = from_tty; | |
1245 | info.control = control; | |
1246 | info.cmd = NULL; | |
1247 | /* If we read command lines from the user, then `info' will hold an | |
1248 | extra reference to the commands that we must clean up. */ | |
1249 | cleanups = make_cleanup_decref_counted_command_line (&info.cmd); | |
1250 | ||
1251 | if (arg == NULL || !*arg) | |
1252 | { | |
86b17b60 | 1253 | if (breakpoint_count - prev_breakpoint_count > 1) |
4a64f543 MS |
1254 | arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1, |
1255 | breakpoint_count); | |
95a42b64 TT |
1256 | else if (breakpoint_count > 0) |
1257 | arg = xstrprintf ("%d", breakpoint_count); | |
86b17b60 PA |
1258 | else |
1259 | { | |
1260 | /* So that we don't try to free the incoming non-NULL | |
1261 | argument in the cleanup below. Mapping breakpoint | |
1262 | numbers will fail in this case. */ | |
1263 | arg = NULL; | |
1264 | } | |
95a42b64 | 1265 | } |
9766ced4 SS |
1266 | else |
1267 | /* The command loop has some static state, so we need to preserve | |
1268 | our argument. */ | |
1269 | arg = xstrdup (arg); | |
86b17b60 PA |
1270 | |
1271 | if (arg != NULL) | |
1272 | make_cleanup (xfree, arg); | |
1273 | ||
1274 | info.arg = arg; | |
95a42b64 TT |
1275 | |
1276 | map_breakpoint_numbers (arg, do_map_commands_command, &info); | |
1277 | ||
1278 | if (info.cmd == NULL) | |
1279 | error (_("No breakpoints specified.")); | |
1280 | ||
1281 | do_cleanups (cleanups); | |
1282 | } | |
1283 | ||
1284 | static void | |
1285 | commands_command (char *arg, int from_tty) | |
1286 | { | |
1287 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1288 | } |
40c03ae8 EZ |
1289 | |
1290 | /* Like commands_command, but instead of reading the commands from | |
1291 | input stream, takes them from an already parsed command structure. | |
1292 | ||
1293 | This is used by cli-script.c to DTRT with breakpoint commands | |
1294 | that are part of if and while bodies. */ | |
1295 | enum command_control_type | |
1296 | commands_from_control_command (char *arg, struct command_line *cmd) | |
1297 | { | |
95a42b64 TT |
1298 | commands_command_1 (arg, 0, cmd); |
1299 | return simple_control; | |
40c03ae8 | 1300 | } |
876fa593 JK |
1301 | |
1302 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1303 | ||
1304 | static int | |
1305 | bp_location_has_shadow (struct bp_location *bl) | |
1306 | { | |
1307 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1308 | return 0; | |
1309 | if (!bl->inserted) | |
1310 | return 0; | |
1311 | if (bl->target_info.shadow_len == 0) | |
e5dd4106 | 1312 | /* BL isn't valid, or doesn't shadow memory. */ |
876fa593 JK |
1313 | return 0; |
1314 | return 1; | |
1315 | } | |
1316 | ||
8defab1a | 1317 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1318 | by replacing any memory breakpoints with their shadowed contents. |
1319 | ||
1320 | The range of shadowed area by each bp_location is: | |
35df4500 TJB |
1321 | bl->address - bp_location_placed_address_before_address_max |
1322 | up to bl->address + bp_location_shadow_len_after_address_max | |
876fa593 JK |
1323 | The range we were requested to resolve shadows for is: |
1324 | memaddr ... memaddr + len | |
1325 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 TJB |
1326 | memaddr + len <= (bl->address |
1327 | - bp_location_placed_address_before_address_max) | |
876fa593 | 1328 | and: |
35df4500 | 1329 | bl->address + bp_location_shadow_len_after_address_max <= memaddr */ |
c906108c | 1330 | |
8defab1a | 1331 | void |
f0ba3972 PA |
1332 | breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, |
1333 | const gdb_byte *writebuf_org, | |
1334 | ULONGEST memaddr, LONGEST len) | |
c906108c | 1335 | { |
4a64f543 MS |
1336 | /* Left boundary, right boundary and median element of our binary |
1337 | search. */ | |
876fa593 JK |
1338 | unsigned bc_l, bc_r, bc; |
1339 | ||
4a64f543 MS |
1340 | /* Find BC_L which is a leftmost element which may affect BUF |
1341 | content. It is safe to report lower value but a failure to | |
1342 | report higher one. */ | |
876fa593 JK |
1343 | |
1344 | bc_l = 0; | |
1345 | bc_r = bp_location_count; | |
1346 | while (bc_l + 1 < bc_r) | |
1347 | { | |
35df4500 | 1348 | struct bp_location *bl; |
876fa593 JK |
1349 | |
1350 | bc = (bc_l + bc_r) / 2; | |
35df4500 | 1351 | bl = bp_location[bc]; |
876fa593 | 1352 | |
4a64f543 MS |
1353 | /* Check first BL->ADDRESS will not overflow due to the added |
1354 | constant. Then advance the left boundary only if we are sure | |
1355 | the BC element can in no way affect the BUF content (MEMADDR | |
1356 | to MEMADDR + LEN range). | |
876fa593 | 1357 | |
4a64f543 MS |
1358 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
1359 | offset so that we cannot miss a breakpoint with its shadow | |
1360 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1361 | |
35df4500 TJB |
1362 | if ((bl->address + bp_location_shadow_len_after_address_max |
1363 | >= bl->address) | |
1364 | && (bl->address + bp_location_shadow_len_after_address_max | |
1365 | <= memaddr)) | |
876fa593 JK |
1366 | bc_l = bc; |
1367 | else | |
1368 | bc_r = bc; | |
1369 | } | |
1370 | ||
128070bb PA |
1371 | /* Due to the binary search above, we need to make sure we pick the |
1372 | first location that's at BC_L's address. E.g., if there are | |
1373 | multiple locations at the same address, BC_L may end up pointing | |
1374 | at a duplicate location, and miss the "master"/"inserted" | |
1375 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1376 | B: | |
1377 | ||
1378 | L1@A, L2@A, L3@B, ... | |
1379 | ||
1380 | BC_L could end up pointing at location L2, while the "master" | |
1381 | location could be L1. Since the `loc->inserted' flag is only set | |
1382 | on "master" locations, we'd forget to restore the shadow of L1 | |
1383 | and L2. */ | |
1384 | while (bc_l > 0 | |
1385 | && bp_location[bc_l]->address == bp_location[bc_l - 1]->address) | |
1386 | bc_l--; | |
1387 | ||
876fa593 JK |
1388 | /* Now do full processing of the found relevant range of elements. */ |
1389 | ||
1390 | for (bc = bc_l; bc < bp_location_count; bc++) | |
c5aa993b | 1391 | { |
35df4500 | 1392 | struct bp_location *bl = bp_location[bc]; |
876fa593 JK |
1393 | CORE_ADDR bp_addr = 0; |
1394 | int bp_size = 0; | |
1395 | int bptoffset = 0; | |
1396 | ||
35df4500 TJB |
1397 | /* bp_location array has BL->OWNER always non-NULL. */ |
1398 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1399 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1400 | bl->owner->number); |
ffce0d52 | 1401 | |
e5dd4106 | 1402 | /* Performance optimization: any further element can no longer affect BUF |
876fa593 JK |
1403 | content. */ |
1404 | ||
35df4500 TJB |
1405 | if (bl->address >= bp_location_placed_address_before_address_max |
1406 | && memaddr + len <= (bl->address | |
1407 | - bp_location_placed_address_before_address_max)) | |
876fa593 JK |
1408 | break; |
1409 | ||
35df4500 | 1410 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1411 | continue; |
35df4500 | 1412 | if (!breakpoint_address_match (bl->target_info.placed_address_space, 0, |
6c95b8df PA |
1413 | current_program_space->aspace, 0)) |
1414 | continue; | |
1415 | ||
c5aa993b JM |
1416 | /* Addresses and length of the part of the breakpoint that |
1417 | we need to copy. */ | |
35df4500 TJB |
1418 | bp_addr = bl->target_info.placed_address; |
1419 | bp_size = bl->target_info.shadow_len; | |
8defab1a | 1420 | |
c5aa993b JM |
1421 | if (bp_addr + bp_size <= memaddr) |
1422 | /* The breakpoint is entirely before the chunk of memory we | |
1423 | are reading. */ | |
1424 | continue; | |
8defab1a | 1425 | |
c5aa993b JM |
1426 | if (bp_addr >= memaddr + len) |
1427 | /* The breakpoint is entirely after the chunk of memory we are | |
4a64f543 | 1428 | reading. */ |
c5aa993b | 1429 | continue; |
c5aa993b | 1430 | |
8defab1a DJ |
1431 | /* Offset within shadow_contents. */ |
1432 | if (bp_addr < memaddr) | |
1433 | { | |
1434 | /* Only copy the second part of the breakpoint. */ | |
1435 | bp_size -= memaddr - bp_addr; | |
1436 | bptoffset = memaddr - bp_addr; | |
1437 | bp_addr = memaddr; | |
1438 | } | |
c5aa993b | 1439 | |
8defab1a DJ |
1440 | if (bp_addr + bp_size > memaddr + len) |
1441 | { | |
1442 | /* Only copy the first part of the breakpoint. */ | |
1443 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1444 | } | |
c5aa993b | 1445 | |
f0ba3972 PA |
1446 | if (readbuf != NULL) |
1447 | { | |
1448 | /* Update the read buffer with this inserted breakpoint's | |
1449 | shadow. */ | |
1450 | memcpy (readbuf + bp_addr - memaddr, | |
1451 | bl->target_info.shadow_contents + bptoffset, bp_size); | |
1452 | } | |
1453 | else | |
1454 | { | |
1455 | struct gdbarch *gdbarch = bl->gdbarch; | |
1456 | const unsigned char *bp; | |
1457 | CORE_ADDR placed_address = bl->target_info.placed_address; | |
1458 | unsigned placed_size = bl->target_info.placed_size; | |
1459 | ||
1460 | /* Update the shadow with what we want to write to memory. */ | |
1461 | memcpy (bl->target_info.shadow_contents + bptoffset, | |
1462 | writebuf_org + bp_addr - memaddr, bp_size); | |
1463 | ||
1464 | /* Determine appropriate breakpoint contents and size for this | |
1465 | address. */ | |
1466 | bp = gdbarch_breakpoint_from_pc (gdbarch, &placed_address, &placed_size); | |
1467 | ||
1468 | /* Update the final write buffer with this inserted | |
1469 | breakpoint's INSN. */ | |
1470 | memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size); | |
1471 | } | |
c5aa993b | 1472 | } |
c906108c | 1473 | } |
c906108c | 1474 | \f |
c5aa993b | 1475 | |
b775012e LM |
1476 | /* Return true if BPT is either a software breakpoint or a hardware |
1477 | breakpoint. */ | |
1478 | ||
1479 | int | |
1480 | is_breakpoint (const struct breakpoint *bpt) | |
1481 | { | |
1482 | return (bpt->type == bp_breakpoint | |
1483 | || bpt->type == bp_hardware_breakpoint); | |
1484 | } | |
1485 | ||
60e1c644 PA |
1486 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1487 | ||
a5606eee | 1488 | static int |
d77f58be | 1489 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1490 | { |
1491 | return (bpt->type == bp_hardware_watchpoint | |
1492 | || bpt->type == bp_read_watchpoint | |
1493 | || bpt->type == bp_access_watchpoint); | |
1494 | } | |
7270d8f2 | 1495 | |
60e1c644 PA |
1496 | /* Return true if BPT is of any watchpoint kind, hardware or |
1497 | software. */ | |
1498 | ||
3a5c3e22 | 1499 | int |
d77f58be | 1500 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1501 | { |
1502 | return (is_hardware_watchpoint (bpt) | |
1503 | || bpt->type == bp_watchpoint); | |
1504 | } | |
1505 | ||
3a5c3e22 PA |
1506 | /* Returns true if the current thread and its running state are safe |
1507 | to evaluate or update watchpoint B. Watchpoints on local | |
1508 | expressions need to be evaluated in the context of the thread that | |
1509 | was current when the watchpoint was created, and, that thread needs | |
1510 | to be stopped to be able to select the correct frame context. | |
1511 | Watchpoints on global expressions can be evaluated on any thread, | |
1512 | and in any state. It is presently left to the target allowing | |
1513 | memory accesses when threads are running. */ | |
f6bc2008 PA |
1514 | |
1515 | static int | |
3a5c3e22 | 1516 | watchpoint_in_thread_scope (struct watchpoint *b) |
f6bc2008 | 1517 | { |
d0d8b0c6 JK |
1518 | return (b->base.pspace == current_program_space |
1519 | && (ptid_equal (b->watchpoint_thread, null_ptid) | |
1520 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1521 | && !is_executing (inferior_ptid)))); | |
f6bc2008 PA |
1522 | } |
1523 | ||
d0fb5eae JK |
1524 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
1525 | associated bp_watchpoint_scope breakpoint. */ | |
1526 | ||
1527 | static void | |
3a5c3e22 | 1528 | watchpoint_del_at_next_stop (struct watchpoint *w) |
d0fb5eae | 1529 | { |
3a5c3e22 | 1530 | struct breakpoint *b = &w->base; |
d0fb5eae JK |
1531 | |
1532 | if (b->related_breakpoint != b) | |
1533 | { | |
1534 | gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope); | |
1535 | gdb_assert (b->related_breakpoint->related_breakpoint == b); | |
1536 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1537 | b->related_breakpoint->related_breakpoint = b->related_breakpoint; | |
1538 | b->related_breakpoint = b; | |
1539 | } | |
1540 | b->disposition = disp_del_at_next_stop; | |
1541 | } | |
1542 | ||
567e1b4e JB |
1543 | /* Assuming that B is a watchpoint: |
1544 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1545 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1546 | - Evaluate the condition if there is one, and store the result |
1547 | in b->loc->cond. | |
a5606eee VP |
1548 | - Update the list of values that must be watched in B->loc. |
1549 | ||
4a64f543 MS |
1550 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1551 | nothing. If this is local watchpoint that is out of scope, delete | |
1552 | it. | |
1553 | ||
1554 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1555 | removed + inserted on each stop here. Normal breakpoints must | |
1556 | never be removed because they might be missed by a running thread | |
1557 | when debugging in non-stop mode. On the other hand, hardware | |
1558 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1559 | to each LWP since they are stored in each LWP's hardware debug | |
1560 | registers. Therefore, such LWP must be stopped first in order to | |
1561 | be able to modify its hardware watchpoints. | |
1562 | ||
1563 | Hardware watchpoints must be reset exactly once after being | |
1564 | presented to the user. It cannot be done sooner, because it would | |
1565 | reset the data used to present the watchpoint hit to the user. And | |
1566 | it must not be done later because it could display the same single | |
1567 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1568 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1569 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1570 | not user-visible - its hit is suppressed if the memory content has | |
1571 | not changed. | |
1572 | ||
1573 | The following constraints influence the location where we can reset | |
1574 | hardware watchpoints: | |
1575 | ||
1576 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1577 | called several times when GDB stops. | |
1578 | ||
1579 | [linux] | |
1580 | * Multiple hardware watchpoints can be hit at the same time, | |
1581 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1582 | hit at a time as the reason for stopping, and all the other hits | |
1583 | are presented later, one after the other, each time the user | |
1584 | requests the execution to be resumed. Execution is not resumed | |
1585 | for the threads still having pending hit event stored in | |
1586 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1587 | the inferior on the first stop the thread hit event is kept being | |
1588 | reported from its cached value by linux_nat_stopped_data_address | |
1589 | until the real thread resume happens after the watchpoint gets | |
1590 | presented and thus its LWP_INFO->STATUS gets reset. | |
1591 | ||
1592 | Therefore the hardware watchpoint hit can get safely reset on the | |
1593 | watchpoint removal from inferior. */ | |
a79d3c27 | 1594 | |
b40ce68a | 1595 | static void |
3a5c3e22 | 1596 | update_watchpoint (struct watchpoint *b, int reparse) |
7270d8f2 | 1597 | { |
a5606eee | 1598 | int within_current_scope; |
a5606eee | 1599 | struct frame_id saved_frame_id; |
66076460 | 1600 | int frame_saved; |
a5606eee | 1601 | |
f6bc2008 PA |
1602 | /* If this is a local watchpoint, we only want to check if the |
1603 | watchpoint frame is in scope if the current thread is the thread | |
1604 | that was used to create the watchpoint. */ | |
1605 | if (!watchpoint_in_thread_scope (b)) | |
1606 | return; | |
1607 | ||
3a5c3e22 | 1608 | if (b->base.disposition == disp_del_at_next_stop) |
a5606eee VP |
1609 | return; |
1610 | ||
66076460 | 1611 | frame_saved = 0; |
a5606eee VP |
1612 | |
1613 | /* Determine if the watchpoint is within scope. */ | |
1614 | if (b->exp_valid_block == NULL) | |
1615 | within_current_scope = 1; | |
1616 | else | |
1617 | { | |
b5db5dfc UW |
1618 | struct frame_info *fi = get_current_frame (); |
1619 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1620 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1621 | ||
1622 | /* If we're in a function epilogue, unwinding may not work | |
1623 | properly, so do not attempt to recreate locations at this | |
1624 | point. See similar comments in watchpoint_check. */ | |
1625 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) | |
1626 | return; | |
66076460 DJ |
1627 | |
1628 | /* Save the current frame's ID so we can restore it after | |
1629 | evaluating the watchpoint expression on its own frame. */ | |
1630 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1631 | took a frame parameter, so that we didn't have to change the | |
1632 | selected frame. */ | |
1633 | frame_saved = 1; | |
1634 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1635 | ||
a5606eee VP |
1636 | fi = frame_find_by_id (b->watchpoint_frame); |
1637 | within_current_scope = (fi != NULL); | |
1638 | if (within_current_scope) | |
1639 | select_frame (fi); | |
1640 | } | |
1641 | ||
b5db5dfc UW |
1642 | /* We don't free locations. They are stored in the bp_location array |
1643 | and update_global_location_list will eventually delete them and | |
1644 | remove breakpoints if needed. */ | |
3a5c3e22 | 1645 | b->base.loc = NULL; |
b5db5dfc | 1646 | |
a5606eee VP |
1647 | if (within_current_scope && reparse) |
1648 | { | |
1649 | char *s; | |
d63d0675 | 1650 | |
a5606eee VP |
1651 | if (b->exp) |
1652 | { | |
1653 | xfree (b->exp); | |
1654 | b->exp = NULL; | |
1655 | } | |
d63d0675 | 1656 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
a5606eee VP |
1657 | b->exp = parse_exp_1 (&s, b->exp_valid_block, 0); |
1658 | /* If the meaning of expression itself changed, the old value is | |
1659 | no longer relevant. We don't want to report a watchpoint hit | |
1660 | to the user when the old value and the new value may actually | |
1661 | be completely different objects. */ | |
1662 | value_free (b->val); | |
fa4727a6 DJ |
1663 | b->val = NULL; |
1664 | b->val_valid = 0; | |
60e1c644 PA |
1665 | |
1666 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1667 | expression is stored in the breakpoint object, not in the | |
1668 | locations (re)created below. */ | |
3a5c3e22 | 1669 | if (b->base.cond_string != NULL) |
60e1c644 PA |
1670 | { |
1671 | if (b->cond_exp != NULL) | |
1672 | { | |
1673 | xfree (b->cond_exp); | |
1674 | b->cond_exp = NULL; | |
1675 | } | |
1676 | ||
3a5c3e22 | 1677 | s = b->base.cond_string; |
60e1c644 PA |
1678 | b->cond_exp = parse_exp_1 (&s, b->cond_exp_valid_block, 0); |
1679 | } | |
a5606eee | 1680 | } |
a5606eee VP |
1681 | |
1682 | /* If we failed to parse the expression, for example because | |
1683 | it refers to a global variable in a not-yet-loaded shared library, | |
1684 | don't try to insert watchpoint. We don't automatically delete | |
1685 | such watchpoint, though, since failure to parse expression | |
1686 | is different from out-of-scope watchpoint. */ | |
2d134ed3 PA |
1687 | if ( !target_has_execution) |
1688 | { | |
1689 | /* Without execution, memory can't change. No use to try and | |
1690 | set watchpoint locations. The watchpoint will be reset when | |
1691 | the target gains execution, through breakpoint_re_set. */ | |
1692 | } | |
1693 | else if (within_current_scope && b->exp) | |
a5606eee | 1694 | { |
0cf6dd15 | 1695 | int pc = 0; |
fa4727a6 | 1696 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1697 | struct program_space *frame_pspace; |
a5606eee | 1698 | |
0cf6dd15 | 1699 | fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain); |
a5606eee | 1700 | |
a5606eee VP |
1701 | /* Avoid setting b->val if it's already set. The meaning of |
1702 | b->val is 'the last value' user saw, and we should update | |
1703 | it only if we reported that last value to user. As it | |
9c06b0b4 TJB |
1704 | happens, the code that reports it updates b->val directly. |
1705 | We don't keep track of the memory value for masked | |
1706 | watchpoints. */ | |
3a5c3e22 | 1707 | if (!b->val_valid && !is_masked_watchpoint (&b->base)) |
fa4727a6 DJ |
1708 | { |
1709 | b->val = v; | |
1710 | b->val_valid = 1; | |
1711 | } | |
a5606eee | 1712 | |
2d134ed3 PA |
1713 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1714 | ||
a5606eee | 1715 | /* Look at each value on the value chain. */ |
9fa40276 | 1716 | for (v = val_chain; v; v = value_next (v)) |
a5606eee VP |
1717 | { |
1718 | /* If it's a memory location, and GDB actually needed | |
1719 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1720 | must watch it. If the first value returned is |
1721 | still lazy, that means an error occurred reading it; | |
1722 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1723 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1724 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1725 | { |
1726 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1727 | |
a5606eee VP |
1728 | /* We only watch structs and arrays if user asked |
1729 | for it explicitly, never if they just happen to | |
1730 | appear in the middle of some value chain. */ | |
fa4727a6 | 1731 | if (v == result |
a5606eee VP |
1732 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1733 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1734 | { | |
1735 | CORE_ADDR addr; | |
1736 | int len, type; | |
1737 | struct bp_location *loc, **tmp; | |
1738 | ||
42ae5230 | 1739 | addr = value_address (v); |
a5606eee VP |
1740 | len = TYPE_LENGTH (value_type (v)); |
1741 | type = hw_write; | |
3a5c3e22 | 1742 | if (b->base.type == bp_read_watchpoint) |
a5606eee | 1743 | type = hw_read; |
3a5c3e22 | 1744 | else if (b->base.type == bp_access_watchpoint) |
a5606eee | 1745 | type = hw_access; |
3a5c3e22 PA |
1746 | |
1747 | loc = allocate_bp_location (&b->base); | |
1748 | for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next)) | |
a5606eee VP |
1749 | ; |
1750 | *tmp = loc; | |
a6d9a66e | 1751 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1752 | |
1753 | loc->pspace = frame_pspace; | |
a5606eee VP |
1754 | loc->address = addr; |
1755 | loc->length = len; | |
1756 | loc->watchpoint_type = type; | |
1757 | } | |
1758 | } | |
9fa40276 TJB |
1759 | } |
1760 | ||
1761 | /* Change the type of breakpoint between hardware assisted or | |
1762 | an ordinary watchpoint depending on the hardware support | |
1763 | and free hardware slots. REPARSE is set when the inferior | |
1764 | is started. */ | |
a9634178 | 1765 | if (reparse) |
9fa40276 | 1766 | { |
e09342b5 | 1767 | int reg_cnt; |
9fa40276 TJB |
1768 | enum bp_loc_type loc_type; |
1769 | struct bp_location *bl; | |
a5606eee | 1770 | |
a9634178 | 1771 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
e09342b5 TJB |
1772 | |
1773 | if (reg_cnt) | |
9fa40276 TJB |
1774 | { |
1775 | int i, target_resources_ok, other_type_used; | |
a1398e0c | 1776 | enum bptype type; |
9fa40276 | 1777 | |
a9634178 TJB |
1778 | /* Use an exact watchpoint when there's only one memory region to be |
1779 | watched, and only one debug register is needed to watch it. */ | |
1780 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
1781 | ||
9fa40276 | 1782 | /* We need to determine how many resources are already |
e09342b5 TJB |
1783 | used for all other hardware watchpoints plus this one |
1784 | to see if we still have enough resources to also fit | |
a1398e0c PA |
1785 | this watchpoint in as well. */ |
1786 | ||
1787 | /* If this is a software watchpoint, we try to turn it | |
1788 | to a hardware one -- count resources as if B was of | |
1789 | hardware watchpoint type. */ | |
1790 | type = b->base.type; | |
1791 | if (type == bp_watchpoint) | |
1792 | type = bp_hardware_watchpoint; | |
1793 | ||
1794 | /* This watchpoint may or may not have been placed on | |
1795 | the list yet at this point (it won't be in the list | |
1796 | if we're trying to create it for the first time, | |
1797 | through watch_command), so always account for it | |
1798 | manually. */ | |
1799 | ||
1800 | /* Count resources used by all watchpoints except B. */ | |
1801 | i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used); | |
1802 | ||
1803 | /* Add in the resources needed for B. */ | |
1804 | i += hw_watchpoint_use_count (&b->base); | |
1805 | ||
1806 | target_resources_ok | |
1807 | = target_can_use_hardware_watchpoint (type, i, other_type_used); | |
e09342b5 | 1808 | if (target_resources_ok <= 0) |
a9634178 | 1809 | { |
3a5c3e22 | 1810 | int sw_mode = b->base.ops->works_in_software_mode (&b->base); |
9c06b0b4 TJB |
1811 | |
1812 | if (target_resources_ok == 0 && !sw_mode) | |
a9634178 TJB |
1813 | error (_("Target does not support this type of " |
1814 | "hardware watchpoint.")); | |
9c06b0b4 TJB |
1815 | else if (target_resources_ok < 0 && !sw_mode) |
1816 | error (_("There are not enough available hardware " | |
1817 | "resources for this watchpoint.")); | |
a1398e0c PA |
1818 | |
1819 | /* Downgrade to software watchpoint. */ | |
1820 | b->base.type = bp_watchpoint; | |
1821 | } | |
1822 | else | |
1823 | { | |
1824 | /* If this was a software watchpoint, we've just | |
1825 | found we have enough resources to turn it to a | |
1826 | hardware watchpoint. Otherwise, this is a | |
1827 | nop. */ | |
1828 | b->base.type = type; | |
a9634178 | 1829 | } |
9fa40276 | 1830 | } |
3a5c3e22 | 1831 | else if (!b->base.ops->works_in_software_mode (&b->base)) |
a9634178 TJB |
1832 | error (_("Expression cannot be implemented with " |
1833 | "read/access watchpoint.")); | |
9fa40276 | 1834 | else |
3a5c3e22 | 1835 | b->base.type = bp_watchpoint; |
9fa40276 | 1836 | |
3a5c3e22 | 1837 | loc_type = (b->base.type == bp_watchpoint? bp_loc_other |
9fa40276 | 1838 | : bp_loc_hardware_watchpoint); |
3a5c3e22 | 1839 | for (bl = b->base.loc; bl; bl = bl->next) |
9fa40276 TJB |
1840 | bl->loc_type = loc_type; |
1841 | } | |
1842 | ||
1843 | for (v = val_chain; v; v = next) | |
1844 | { | |
a5606eee VP |
1845 | next = value_next (v); |
1846 | if (v != b->val) | |
1847 | value_free (v); | |
1848 | } | |
1849 | ||
c7437ca6 PA |
1850 | /* If a software watchpoint is not watching any memory, then the |
1851 | above left it without any location set up. But, | |
1852 | bpstat_stop_status requires a location to be able to report | |
1853 | stops, so make sure there's at least a dummy one. */ | |
3a5c3e22 | 1854 | if (b->base.type == bp_watchpoint && b->base.loc == NULL) |
c7437ca6 | 1855 | { |
3a5c3e22 PA |
1856 | struct breakpoint *base = &b->base; |
1857 | base->loc = allocate_bp_location (base); | |
1858 | base->loc->pspace = frame_pspace; | |
1859 | base->loc->address = -1; | |
1860 | base->loc->length = -1; | |
1861 | base->loc->watchpoint_type = -1; | |
c7437ca6 | 1862 | } |
a5606eee VP |
1863 | } |
1864 | else if (!within_current_scope) | |
7270d8f2 | 1865 | { |
ac74f770 MS |
1866 | printf_filtered (_("\ |
1867 | Watchpoint %d deleted because the program has left the block\n\ | |
1868 | in which its expression is valid.\n"), | |
3a5c3e22 | 1869 | b->base.number); |
d0fb5eae | 1870 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 1871 | } |
a5606eee VP |
1872 | |
1873 | /* Restore the selected frame. */ | |
66076460 DJ |
1874 | if (frame_saved) |
1875 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
1876 | } |
1877 | ||
a5606eee | 1878 | |
74960c60 | 1879 | /* Returns 1 iff breakpoint location should be |
1e4d1764 YQ |
1880 | inserted in the inferior. We don't differentiate the type of BL's owner |
1881 | (breakpoint vs. tracepoint), although insert_location in tracepoint's | |
1882 | breakpoint_ops is not defined, because in insert_bp_location, | |
1883 | tracepoint's insert_location will not be called. */ | |
74960c60 | 1884 | static int |
35df4500 | 1885 | should_be_inserted (struct bp_location *bl) |
74960c60 | 1886 | { |
35df4500 | 1887 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
1888 | return 0; |
1889 | ||
35df4500 | 1890 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
1891 | return 0; |
1892 | ||
35df4500 | 1893 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
1894 | return 0; |
1895 | ||
f8eba3c6 TT |
1896 | if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup) |
1897 | return 0; | |
1898 | ||
56710373 PA |
1899 | /* This is set for example, when we're attached to the parent of a |
1900 | vfork, and have detached from the child. The child is running | |
1901 | free, and we expect it to do an exec or exit, at which point the | |
1902 | OS makes the parent schedulable again (and the target reports | |
1903 | that the vfork is done). Until the child is done with the shared | |
1904 | memory region, do not insert breakpoints in the parent, otherwise | |
1905 | the child could still trip on the parent's breakpoints. Since | |
1906 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 1907 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
1908 | return 0; |
1909 | ||
74960c60 VP |
1910 | return 1; |
1911 | } | |
1912 | ||
934709f0 PW |
1913 | /* Same as should_be_inserted but does the check assuming |
1914 | that the location is not duplicated. */ | |
1915 | ||
1916 | static int | |
1917 | unduplicated_should_be_inserted (struct bp_location *bl) | |
1918 | { | |
1919 | int result; | |
1920 | const int save_duplicate = bl->duplicate; | |
1921 | ||
1922 | bl->duplicate = 0; | |
1923 | result = should_be_inserted (bl); | |
1924 | bl->duplicate = save_duplicate; | |
1925 | return result; | |
1926 | } | |
1927 | ||
b775012e LM |
1928 | /* Parses a conditional described by an expression COND into an |
1929 | agent expression bytecode suitable for evaluation | |
1930 | by the bytecode interpreter. Return NULL if there was | |
1931 | any error during parsing. */ | |
1932 | ||
1933 | static struct agent_expr * | |
1934 | parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond) | |
1935 | { | |
1936 | struct agent_expr *aexpr = NULL; | |
1937 | struct cleanup *old_chain = NULL; | |
1938 | volatile struct gdb_exception ex; | |
1939 | ||
1940 | if (!cond) | |
1941 | return NULL; | |
1942 | ||
1943 | /* We don't want to stop processing, so catch any errors | |
1944 | that may show up. */ | |
1945 | TRY_CATCH (ex, RETURN_MASK_ERROR) | |
1946 | { | |
1947 | aexpr = gen_eval_for_expr (scope, cond); | |
1948 | } | |
1949 | ||
1950 | if (ex.reason < 0) | |
1951 | { | |
1952 | /* If we got here, it means the condition could not be parsed to a valid | |
1953 | bytecode expression and thus can't be evaluated on the target's side. | |
1954 | It's no use iterating through the conditions. */ | |
1955 | return NULL; | |
1956 | } | |
1957 | ||
1958 | /* We have a valid agent expression. */ | |
1959 | return aexpr; | |
1960 | } | |
1961 | ||
1962 | /* Based on location BL, create a list of breakpoint conditions to be | |
1963 | passed on to the target. If we have duplicated locations with different | |
1964 | conditions, we will add such conditions to the list. The idea is that the | |
1965 | target will evaluate the list of conditions and will only notify GDB when | |
1966 | one of them is true. */ | |
1967 | ||
1968 | static void | |
1969 | build_target_condition_list (struct bp_location *bl) | |
1970 | { | |
1971 | struct bp_location **locp = NULL, **loc2p; | |
1972 | int null_condition_or_parse_error = 0; | |
1973 | int modified = bl->needs_update; | |
1974 | struct bp_location *loc; | |
1975 | ||
1976 | /* This is only meaningful if the target is | |
1977 | evaluating conditions and if the user has | |
1978 | opted for condition evaluation on the target's | |
1979 | side. */ | |
1980 | if (gdb_evaluates_breakpoint_condition_p () | |
1981 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
1982 | return; | |
1983 | ||
1984 | /* Do a first pass to check for locations with no assigned | |
1985 | conditions or conditions that fail to parse to a valid agent expression | |
1986 | bytecode. If any of these happen, then it's no use to send conditions | |
1987 | to the target since this location will always trigger and generate a | |
1988 | response back to GDB. */ | |
1989 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
1990 | { | |
1991 | loc = (*loc2p); | |
1992 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
1993 | { | |
1994 | if (modified) | |
1995 | { | |
1996 | struct agent_expr *aexpr; | |
1997 | ||
1998 | /* Re-parse the conditions since something changed. In that | |
1999 | case we already freed the condition bytecodes (see | |
2000 | force_breakpoint_reinsertion). We just | |
2001 | need to parse the condition to bytecodes again. */ | |
2002 | aexpr = parse_cond_to_aexpr (bl->address, loc->cond); | |
2003 | loc->cond_bytecode = aexpr; | |
2004 | ||
2005 | /* Check if we managed to parse the conditional expression | |
2006 | correctly. If not, we will not send this condition | |
2007 | to the target. */ | |
2008 | if (aexpr) | |
2009 | continue; | |
2010 | } | |
2011 | ||
2012 | /* If we have a NULL bytecode expression, it means something | |
2013 | went wrong or we have a null condition expression. */ | |
2014 | if (!loc->cond_bytecode) | |
2015 | { | |
2016 | null_condition_or_parse_error = 1; | |
2017 | break; | |
2018 | } | |
2019 | } | |
2020 | } | |
2021 | ||
2022 | /* If any of these happened, it means we will have to evaluate the conditions | |
2023 | for the location's address on gdb's side. It is no use keeping bytecodes | |
2024 | for all the other duplicate locations, thus we free all of them here. | |
2025 | ||
2026 | This is so we have a finer control over which locations' conditions are | |
2027 | being evaluated by GDB or the remote stub. */ | |
2028 | if (null_condition_or_parse_error) | |
2029 | { | |
2030 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2031 | { | |
2032 | loc = (*loc2p); | |
2033 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2034 | { | |
2035 | /* Only go as far as the first NULL bytecode is | |
2036 | located. */ | |
2037 | if (!loc->cond_bytecode) | |
2038 | return; | |
2039 | ||
2040 | free_agent_expr (loc->cond_bytecode); | |
2041 | loc->cond_bytecode = NULL; | |
2042 | } | |
2043 | } | |
2044 | } | |
2045 | ||
2046 | /* No NULL conditions or failed bytecode generation. Build a condition list | |
2047 | for this location's address. */ | |
2048 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2049 | { | |
2050 | loc = (*loc2p); | |
2051 | if (loc->cond | |
2052 | && is_breakpoint (loc->owner) | |
2053 | && loc->pspace->num == bl->pspace->num | |
2054 | && loc->owner->enable_state == bp_enabled | |
2055 | && loc->enabled) | |
2056 | /* Add the condition to the vector. This will be used later to send the | |
2057 | conditions to the target. */ | |
2058 | VEC_safe_push (agent_expr_p, bl->target_info.conditions, | |
2059 | loc->cond_bytecode); | |
2060 | } | |
2061 | ||
2062 | return; | |
2063 | } | |
2064 | ||
35df4500 TJB |
2065 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
2066 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
3fbb6ffa | 2067 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
c30eee59 TJB |
2068 | Returns 0 for success, 1 if the bp_location type is not supported or |
2069 | -1 for failure. | |
879bfdc2 | 2070 | |
4a64f543 MS |
2071 | NOTE drow/2003-09-09: This routine could be broken down to an |
2072 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 2073 | static int |
35df4500 | 2074 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 2075 | struct ui_file *tmp_error_stream, |
3fbb6ffa | 2076 | int *disabled_breaks, |
26bb91f3 | 2077 | int *hw_breakpoint_error) |
879bfdc2 DJ |
2078 | { |
2079 | int val = 0; | |
2080 | ||
b775012e | 2081 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2082 | return 0; |
2083 | ||
8181d85f | 2084 | /* Initialize the target-specific information. */ |
35df4500 TJB |
2085 | memset (&bl->target_info, 0, sizeof (bl->target_info)); |
2086 | bl->target_info.placed_address = bl->address; | |
2087 | bl->target_info.placed_address_space = bl->pspace->aspace; | |
f1310107 | 2088 | bl->target_info.length = bl->length; |
8181d85f | 2089 | |
b775012e LM |
2090 | /* When working with target-side conditions, we must pass all the conditions |
2091 | for the same breakpoint address down to the target since GDB will not | |
2092 | insert those locations. With a list of breakpoint conditions, the target | |
2093 | can decide when to stop and notify GDB. */ | |
2094 | ||
2095 | if (is_breakpoint (bl->owner)) | |
2096 | { | |
2097 | build_target_condition_list (bl); | |
2098 | /* Reset the condition modification marker. */ | |
2099 | bl->needs_update = 0; | |
2100 | } | |
2101 | ||
35df4500 TJB |
2102 | if (bl->loc_type == bp_loc_software_breakpoint |
2103 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 2104 | { |
35df4500 | 2105 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
2106 | { |
2107 | /* If the explicitly specified breakpoint type | |
2108 | is not hardware breakpoint, check the memory map to see | |
2109 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 2110 | |
765dc015 VP |
2111 | Two important cases are: |
2112 | - location type is not hardware breakpoint, memory | |
2113 | is readonly. We change the type of the location to | |
2114 | hardware breakpoint. | |
4a64f543 MS |
2115 | - location type is hardware breakpoint, memory is |
2116 | read-write. This means we've previously made the | |
2117 | location hardware one, but then the memory map changed, | |
2118 | so we undo. | |
765dc015 | 2119 | |
4a64f543 MS |
2120 | When breakpoints are removed, remove_breakpoints will use |
2121 | location types we've just set here, the only possible | |
2122 | problem is that memory map has changed during running | |
2123 | program, but it's not going to work anyway with current | |
2124 | gdb. */ | |
765dc015 | 2125 | struct mem_region *mr |
35df4500 | 2126 | = lookup_mem_region (bl->target_info.placed_address); |
765dc015 VP |
2127 | |
2128 | if (mr) | |
2129 | { | |
2130 | if (automatic_hardware_breakpoints) | |
2131 | { | |
765dc015 VP |
2132 | enum bp_loc_type new_type; |
2133 | ||
2134 | if (mr->attrib.mode != MEM_RW) | |
2135 | new_type = bp_loc_hardware_breakpoint; | |
2136 | else | |
2137 | new_type = bp_loc_software_breakpoint; | |
2138 | ||
35df4500 | 2139 | if (new_type != bl->loc_type) |
765dc015 VP |
2140 | { |
2141 | static int said = 0; | |
cc59ec59 | 2142 | |
35df4500 | 2143 | bl->loc_type = new_type; |
765dc015 VP |
2144 | if (!said) |
2145 | { | |
3e43a32a MS |
2146 | fprintf_filtered (gdb_stdout, |
2147 | _("Note: automatically using " | |
2148 | "hardware breakpoints for " | |
2149 | "read-only addresses.\n")); | |
765dc015 VP |
2150 | said = 1; |
2151 | } | |
2152 | } | |
2153 | } | |
35df4500 | 2154 | else if (bl->loc_type == bp_loc_software_breakpoint |
765dc015 | 2155 | && mr->attrib.mode != MEM_RW) |
3e43a32a MS |
2156 | warning (_("cannot set software breakpoint " |
2157 | "at readonly address %s"), | |
35df4500 | 2158 | paddress (bl->gdbarch, bl->address)); |
765dc015 VP |
2159 | } |
2160 | } | |
2161 | ||
879bfdc2 DJ |
2162 | /* First check to see if we have to handle an overlay. */ |
2163 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2164 | || bl->section == NULL |
2165 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
2166 | { |
2167 | /* No overlay handling: just set the breakpoint. */ | |
2168 | ||
348d480f | 2169 | val = bl->owner->ops->insert_location (bl); |
879bfdc2 DJ |
2170 | } |
2171 | else | |
2172 | { | |
4a64f543 | 2173 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
2174 | Shall we set a breakpoint at the LMA? */ |
2175 | if (!overlay_events_enabled) | |
2176 | { | |
2177 | /* Yes -- overlay event support is not active, | |
2178 | so we must try to set a breakpoint at the LMA. | |
2179 | This will not work for a hardware breakpoint. */ | |
35df4500 | 2180 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 2181 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 2182 | bl->owner->number); |
879bfdc2 DJ |
2183 | else |
2184 | { | |
35df4500 TJB |
2185 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
2186 | bl->section); | |
879bfdc2 | 2187 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 TJB |
2188 | bl->overlay_target_info = bl->target_info; |
2189 | bl->overlay_target_info.placed_address = addr; | |
2190 | val = target_insert_breakpoint (bl->gdbarch, | |
2191 | &bl->overlay_target_info); | |
879bfdc2 | 2192 | if (val != 0) |
99361f52 | 2193 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
2194 | "Overlay breakpoint %d " |
2195 | "failed: in ROM?\n", | |
35df4500 | 2196 | bl->owner->number); |
879bfdc2 DJ |
2197 | } |
2198 | } | |
2199 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 2200 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
2201 | { |
2202 | /* Yes. This overlay section is mapped into memory. */ | |
348d480f | 2203 | val = bl->owner->ops->insert_location (bl); |
879bfdc2 DJ |
2204 | } |
2205 | else | |
2206 | { | |
2207 | /* No. This breakpoint will not be inserted. | |
2208 | No error, but do not mark the bp as 'inserted'. */ | |
2209 | return 0; | |
2210 | } | |
2211 | } | |
2212 | ||
2213 | if (val) | |
2214 | { | |
2215 | /* Can't set the breakpoint. */ | |
35df4500 | 2216 | if (solib_name_from_address (bl->pspace, bl->address)) |
879bfdc2 | 2217 | { |
4a64f543 | 2218 | /* See also: disable_breakpoints_in_shlibs. */ |
879bfdc2 | 2219 | val = 0; |
35df4500 | 2220 | bl->shlib_disabled = 1; |
8d3788bd | 2221 | observer_notify_breakpoint_modified (bl->owner); |
3fbb6ffa TJB |
2222 | if (!*disabled_breaks) |
2223 | { | |
2224 | fprintf_unfiltered (tmp_error_stream, | |
2225 | "Cannot insert breakpoint %d.\n", | |
2226 | bl->owner->number); | |
2227 | fprintf_unfiltered (tmp_error_stream, | |
2228 | "Temporarily disabling shared " | |
2229 | "library breakpoints:\n"); | |
2230 | } | |
2231 | *disabled_breaks = 1; | |
879bfdc2 | 2232 | fprintf_unfiltered (tmp_error_stream, |
35df4500 | 2233 | "breakpoint #%d\n", bl->owner->number); |
879bfdc2 DJ |
2234 | } |
2235 | else | |
879bfdc2 | 2236 | { |
35df4500 | 2237 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 DJ |
2238 | { |
2239 | *hw_breakpoint_error = 1; | |
3e43a32a MS |
2240 | fprintf_unfiltered (tmp_error_stream, |
2241 | "Cannot insert hardware " | |
2242 | "breakpoint %d.\n", | |
35df4500 | 2243 | bl->owner->number); |
879bfdc2 DJ |
2244 | } |
2245 | else | |
2246 | { | |
2247 | fprintf_unfiltered (tmp_error_stream, | |
2248 | "Cannot insert breakpoint %d.\n", | |
35df4500 | 2249 | bl->owner->number); |
879bfdc2 DJ |
2250 | fprintf_filtered (tmp_error_stream, |
2251 | "Error accessing memory address "); | |
35df4500 | 2252 | fputs_filtered (paddress (bl->gdbarch, bl->address), |
5af949e3 | 2253 | tmp_error_stream); |
879bfdc2 DJ |
2254 | fprintf_filtered (tmp_error_stream, ": %s.\n", |
2255 | safe_strerror (val)); | |
2256 | } | |
2257 | ||
2258 | } | |
2259 | } | |
2260 | else | |
35df4500 | 2261 | bl->inserted = 1; |
879bfdc2 DJ |
2262 | |
2263 | return val; | |
2264 | } | |
2265 | ||
35df4500 | 2266 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 2267 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 2268 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 2269 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 2270 | { |
77b06cd7 TJB |
2271 | gdb_assert (bl->owner->ops != NULL |
2272 | && bl->owner->ops->insert_location != NULL); | |
2273 | ||
2274 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
2275 | |
2276 | /* If trying to set a read-watchpoint, and it turns out it's not | |
2277 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 2278 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
2279 | { |
2280 | struct bp_location *loc, **loc_temp; | |
2281 | ||
2282 | /* But don't try to insert it, if there's already another | |
2283 | hw_access location that would be considered a duplicate | |
2284 | of this one. */ | |
2285 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 2286 | if (loc != bl |
85d721b8 | 2287 | && loc->watchpoint_type == hw_access |
35df4500 | 2288 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 2289 | { |
35df4500 TJB |
2290 | bl->duplicate = 1; |
2291 | bl->inserted = 1; | |
2292 | bl->target_info = loc->target_info; | |
2293 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
2294 | val = 0; |
2295 | break; | |
2296 | } | |
2297 | ||
2298 | if (val == 1) | |
2299 | { | |
77b06cd7 TJB |
2300 | bl->watchpoint_type = hw_access; |
2301 | val = bl->owner->ops->insert_location (bl); | |
2302 | ||
2303 | if (val) | |
2304 | /* Back to the original value. */ | |
2305 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
2306 | } |
2307 | } | |
2308 | ||
35df4500 | 2309 | bl->inserted = (val == 0); |
879bfdc2 DJ |
2310 | } |
2311 | ||
35df4500 | 2312 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 2313 | { |
77b06cd7 TJB |
2314 | gdb_assert (bl->owner->ops != NULL |
2315 | && bl->owner->ops->insert_location != NULL); | |
2316 | ||
2317 | val = bl->owner->ops->insert_location (bl); | |
2318 | if (val) | |
2319 | { | |
2320 | bl->owner->enable_state = bp_disabled; | |
2321 | ||
2322 | if (val == 1) | |
2323 | warning (_("\ | |
2324 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
2325 | of catchpoint."), bl->owner->number); | |
2326 | else | |
2327 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
2328 | } | |
2329 | ||
2330 | bl->inserted = (val == 0); | |
1640b821 DJ |
2331 | |
2332 | /* We've already printed an error message if there was a problem | |
2333 | inserting this catchpoint, and we've disabled the catchpoint, | |
2334 | so just return success. */ | |
2335 | return 0; | |
879bfdc2 DJ |
2336 | } |
2337 | ||
2338 | return 0; | |
2339 | } | |
2340 | ||
6c95b8df PA |
2341 | /* This function is called when program space PSPACE is about to be |
2342 | deleted. It takes care of updating breakpoints to not reference | |
2343 | PSPACE anymore. */ | |
2344 | ||
2345 | void | |
2346 | breakpoint_program_space_exit (struct program_space *pspace) | |
2347 | { | |
2348 | struct breakpoint *b, *b_temp; | |
876fa593 | 2349 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
2350 | |
2351 | /* Remove any breakpoint that was set through this program space. */ | |
2352 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
2353 | { | |
2354 | if (b->pspace == pspace) | |
2355 | delete_breakpoint (b); | |
2356 | } | |
2357 | ||
2358 | /* Breakpoints set through other program spaces could have locations | |
2359 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 2360 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
2361 | { |
2362 | struct bp_location *tmp; | |
2363 | ||
2364 | if (loc->pspace == pspace) | |
2365 | { | |
2bdf28a0 | 2366 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
2367 | if (loc->owner->loc == loc) |
2368 | loc->owner->loc = loc->next; | |
2369 | else | |
2370 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
2371 | if (tmp->next == loc) | |
2372 | { | |
2373 | tmp->next = loc->next; | |
2374 | break; | |
2375 | } | |
2376 | } | |
2377 | } | |
2378 | ||
2379 | /* Now update the global location list to permanently delete the | |
2380 | removed locations above. */ | |
2381 | update_global_location_list (0); | |
2382 | } | |
2383 | ||
74960c60 VP |
2384 | /* Make sure all breakpoints are inserted in inferior. |
2385 | Throws exception on any error. | |
2386 | A breakpoint that is already inserted won't be inserted | |
2387 | again, so calling this function twice is safe. */ | |
2388 | void | |
2389 | insert_breakpoints (void) | |
2390 | { | |
2391 | struct breakpoint *bpt; | |
2392 | ||
2393 | ALL_BREAKPOINTS (bpt) | |
2394 | if (is_hardware_watchpoint (bpt)) | |
3a5c3e22 PA |
2395 | { |
2396 | struct watchpoint *w = (struct watchpoint *) bpt; | |
2397 | ||
2398 | update_watchpoint (w, 0 /* don't reparse. */); | |
2399 | } | |
74960c60 | 2400 | |
b60e7edf | 2401 | update_global_location_list (1); |
74960c60 | 2402 | |
c35b1492 PA |
2403 | /* update_global_location_list does not insert breakpoints when |
2404 | always_inserted_mode is not enabled. Explicitly insert them | |
2405 | now. */ | |
2406 | if (!breakpoints_always_inserted_mode ()) | |
74960c60 VP |
2407 | insert_breakpoint_locations (); |
2408 | } | |
2409 | ||
b775012e LM |
2410 | /* This is used when we need to synch breakpoint conditions between GDB and the |
2411 | target. It is the case with deleting and disabling of breakpoints when using | |
2412 | always-inserted mode. */ | |
2413 | ||
2414 | static void | |
2415 | update_inserted_breakpoint_locations (void) | |
2416 | { | |
2417 | struct bp_location *bl, **blp_tmp; | |
2418 | int error_flag = 0; | |
2419 | int val = 0; | |
2420 | int disabled_breaks = 0; | |
2421 | int hw_breakpoint_error = 0; | |
2422 | ||
2423 | struct ui_file *tmp_error_stream = mem_fileopen (); | |
2424 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); | |
2425 | ||
2426 | /* Explicitly mark the warning -- this will only be printed if | |
2427 | there was an error. */ | |
2428 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
2429 | ||
2430 | save_current_space_and_thread (); | |
2431 | ||
2432 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
2433 | { | |
2434 | /* We only want to update software breakpoints and hardware | |
2435 | breakpoints. */ | |
2436 | if (!is_breakpoint (bl->owner)) | |
2437 | continue; | |
2438 | ||
2439 | /* We only want to update locations that are already inserted | |
2440 | and need updating. This is to avoid unwanted insertion during | |
2441 | deletion of breakpoints. */ | |
2442 | if (!bl->inserted || (bl->inserted && !bl->needs_update)) | |
2443 | continue; | |
2444 | ||
2445 | switch_to_program_space_and_thread (bl->pspace); | |
2446 | ||
2447 | /* For targets that support global breakpoints, there's no need | |
2448 | to select an inferior to insert breakpoint to. In fact, even | |
2449 | if we aren't attached to any process yet, we should still | |
2450 | insert breakpoints. */ | |
2451 | if (!gdbarch_has_global_breakpoints (target_gdbarch) | |
2452 | && ptid_equal (inferior_ptid, null_ptid)) | |
2453 | continue; | |
2454 | ||
2455 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, | |
2456 | &hw_breakpoint_error); | |
2457 | if (val) | |
2458 | error_flag = val; | |
2459 | } | |
2460 | ||
2461 | if (error_flag) | |
2462 | { | |
2463 | target_terminal_ours_for_output (); | |
2464 | error_stream (tmp_error_stream); | |
2465 | } | |
2466 | ||
2467 | do_cleanups (cleanups); | |
2468 | } | |
2469 | ||
c30eee59 | 2470 | /* Used when starting or continuing the program. */ |
c906108c | 2471 | |
74960c60 VP |
2472 | static void |
2473 | insert_breakpoint_locations (void) | |
c906108c | 2474 | { |
a5606eee | 2475 | struct breakpoint *bpt; |
35df4500 | 2476 | struct bp_location *bl, **blp_tmp; |
eacd795a | 2477 | int error_flag = 0; |
c906108c | 2478 | int val = 0; |
3fbb6ffa | 2479 | int disabled_breaks = 0; |
81d0cc19 | 2480 | int hw_breakpoint_error = 0; |
c906108c | 2481 | |
81d0cc19 | 2482 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 2483 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 2484 | |
81d0cc19 GS |
2485 | /* Explicitly mark the warning -- this will only be printed if |
2486 | there was an error. */ | |
2487 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
2488 | |
2489 | save_current_space_and_thread (); | |
2490 | ||
35df4500 | 2491 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 2492 | { |
b775012e | 2493 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2494 | continue; |
2495 | ||
4a64f543 MS |
2496 | /* There is no point inserting thread-specific breakpoints if |
2497 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
2498 | has BL->OWNER always non-NULL. */ | |
35df4500 TJB |
2499 | if (bl->owner->thread != -1 |
2500 | && !valid_thread_id (bl->owner->thread)) | |
f365de73 AS |
2501 | continue; |
2502 | ||
35df4500 | 2503 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
2504 | |
2505 | /* For targets that support global breakpoints, there's no need | |
2506 | to select an inferior to insert breakpoint to. In fact, even | |
2507 | if we aren't attached to any process yet, we should still | |
2508 | insert breakpoints. */ | |
2509 | if (!gdbarch_has_global_breakpoints (target_gdbarch) | |
2510 | && ptid_equal (inferior_ptid, null_ptid)) | |
2511 | continue; | |
2512 | ||
3fbb6ffa TJB |
2513 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, |
2514 | &hw_breakpoint_error); | |
879bfdc2 | 2515 | if (val) |
eacd795a | 2516 | error_flag = val; |
879bfdc2 | 2517 | } |
c906108c | 2518 | |
4a64f543 MS |
2519 | /* If we failed to insert all locations of a watchpoint, remove |
2520 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
2521 | ALL_BREAKPOINTS (bpt) |
2522 | { | |
2523 | int some_failed = 0; | |
2524 | struct bp_location *loc; | |
2525 | ||
2526 | if (!is_hardware_watchpoint (bpt)) | |
2527 | continue; | |
2528 | ||
d6b74ac4 | 2529 | if (!breakpoint_enabled (bpt)) |
a5606eee | 2530 | continue; |
74960c60 VP |
2531 | |
2532 | if (bpt->disposition == disp_del_at_next_stop) | |
2533 | continue; | |
a5606eee VP |
2534 | |
2535 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 2536 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
2537 | { |
2538 | some_failed = 1; | |
2539 | break; | |
2540 | } | |
2541 | if (some_failed) | |
2542 | { | |
2543 | for (loc = bpt->loc; loc; loc = loc->next) | |
2544 | if (loc->inserted) | |
2545 | remove_breakpoint (loc, mark_uninserted); | |
2546 | ||
2547 | hw_breakpoint_error = 1; | |
2548 | fprintf_unfiltered (tmp_error_stream, | |
2549 | "Could not insert hardware watchpoint %d.\n", | |
2550 | bpt->number); | |
eacd795a | 2551 | error_flag = -1; |
a5606eee VP |
2552 | } |
2553 | } | |
2554 | ||
eacd795a | 2555 | if (error_flag) |
81d0cc19 GS |
2556 | { |
2557 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
2558 | message about possibly exhausted resources. */ | |
879bfdc2 | 2559 | if (hw_breakpoint_error) |
81d0cc19 | 2560 | { |
c6510018 MS |
2561 | fprintf_unfiltered (tmp_error_stream, |
2562 | "Could not insert hardware breakpoints:\n\ | |
2563 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 2564 | } |
81d0cc19 GS |
2565 | target_terminal_ours_for_output (); |
2566 | error_stream (tmp_error_stream); | |
2567 | } | |
f7545552 TT |
2568 | |
2569 | do_cleanups (cleanups); | |
c906108c SS |
2570 | } |
2571 | ||
c30eee59 TJB |
2572 | /* Used when the program stops. |
2573 | Returns zero if successful, or non-zero if there was a problem | |
2574 | removing a breakpoint location. */ | |
2575 | ||
c906108c | 2576 | int |
fba45db2 | 2577 | remove_breakpoints (void) |
c906108c | 2578 | { |
35df4500 | 2579 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 2580 | int val = 0; |
c906108c | 2581 | |
35df4500 | 2582 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2583 | { |
1e4d1764 | 2584 | if (bl->inserted && !is_tracepoint (bl->owner)) |
35df4500 | 2585 | val |= remove_breakpoint (bl, mark_uninserted); |
c5aa993b | 2586 | } |
3a1bae8e | 2587 | return val; |
c906108c SS |
2588 | } |
2589 | ||
6c95b8df PA |
2590 | /* Remove breakpoints of process PID. */ |
2591 | ||
2592 | int | |
2593 | remove_breakpoints_pid (int pid) | |
2594 | { | |
35df4500 | 2595 | struct bp_location *bl, **blp_tmp; |
6c95b8df PA |
2596 | int val; |
2597 | struct inferior *inf = find_inferior_pid (pid); | |
2598 | ||
35df4500 | 2599 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 2600 | { |
35df4500 | 2601 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2602 | continue; |
2603 | ||
35df4500 | 2604 | if (bl->inserted) |
6c95b8df | 2605 | { |
35df4500 | 2606 | val = remove_breakpoint (bl, mark_uninserted); |
6c95b8df PA |
2607 | if (val != 0) |
2608 | return val; | |
2609 | } | |
2610 | } | |
2611 | return 0; | |
2612 | } | |
2613 | ||
c906108c | 2614 | int |
fba45db2 | 2615 | reattach_breakpoints (int pid) |
c906108c | 2616 | { |
6c95b8df | 2617 | struct cleanup *old_chain; |
35df4500 | 2618 | struct bp_location *bl, **blp_tmp; |
c906108c | 2619 | int val; |
86b887df | 2620 | struct ui_file *tmp_error_stream; |
3fbb6ffa | 2621 | int dummy1 = 0, dummy2 = 0; |
6c95b8df PA |
2622 | struct inferior *inf; |
2623 | struct thread_info *tp; | |
2624 | ||
2625 | tp = any_live_thread_of_process (pid); | |
2626 | if (tp == NULL) | |
2627 | return 1; | |
2628 | ||
2629 | inf = find_inferior_pid (pid); | |
2630 | old_chain = save_inferior_ptid (); | |
2631 | ||
2632 | inferior_ptid = tp->ptid; | |
a4954f26 | 2633 | |
86b887df | 2634 | tmp_error_stream = mem_fileopen (); |
a4954f26 | 2635 | make_cleanup_ui_file_delete (tmp_error_stream); |
c906108c | 2636 | |
35df4500 | 2637 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2638 | { |
35df4500 | 2639 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2640 | continue; |
2641 | ||
35df4500 | 2642 | if (bl->inserted) |
c5aa993b | 2643 | { |
35df4500 | 2644 | bl->inserted = 0; |
3fbb6ffa | 2645 | val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2); |
c5aa993b JM |
2646 | if (val != 0) |
2647 | { | |
ce696e05 | 2648 | do_cleanups (old_chain); |
c5aa993b JM |
2649 | return val; |
2650 | } | |
2651 | } | |
2652 | } | |
ce696e05 | 2653 | do_cleanups (old_chain); |
c906108c SS |
2654 | return 0; |
2655 | } | |
2656 | ||
e58b0e63 PA |
2657 | static int internal_breakpoint_number = -1; |
2658 | ||
84f4c1fe PM |
2659 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
2660 | If INTERNAL is non-zero, the breakpoint number will be populated | |
2661 | from internal_breakpoint_number and that variable decremented. | |
e5dd4106 | 2662 | Otherwise the breakpoint number will be populated from |
84f4c1fe PM |
2663 | breakpoint_count and that value incremented. Internal breakpoints |
2664 | do not set the internal var bpnum. */ | |
2665 | static void | |
2666 | set_breakpoint_number (int internal, struct breakpoint *b) | |
2667 | { | |
2668 | if (internal) | |
2669 | b->number = internal_breakpoint_number--; | |
2670 | else | |
2671 | { | |
2672 | set_breakpoint_count (breakpoint_count + 1); | |
2673 | b->number = breakpoint_count; | |
2674 | } | |
2675 | } | |
2676 | ||
e62c965a | 2677 | static struct breakpoint * |
a6d9a66e | 2678 | create_internal_breakpoint (struct gdbarch *gdbarch, |
06edf0c0 | 2679 | CORE_ADDR address, enum bptype type, |
c0a91b2b | 2680 | const struct breakpoint_ops *ops) |
e62c965a | 2681 | { |
e62c965a PP |
2682 | struct symtab_and_line sal; |
2683 | struct breakpoint *b; | |
2684 | ||
4a64f543 | 2685 | init_sal (&sal); /* Initialize to zeroes. */ |
e62c965a PP |
2686 | |
2687 | sal.pc = address; | |
2688 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 2689 | sal.pspace = current_program_space; |
e62c965a | 2690 | |
06edf0c0 | 2691 | b = set_raw_breakpoint (gdbarch, sal, type, ops); |
e62c965a PP |
2692 | b->number = internal_breakpoint_number--; |
2693 | b->disposition = disp_donttouch; | |
2694 | ||
2695 | return b; | |
2696 | } | |
2697 | ||
17450429 PP |
2698 | static const char *const longjmp_names[] = |
2699 | { | |
2700 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
2701 | }; | |
2702 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
2703 | ||
2704 | /* Per-objfile data private to breakpoint.c. */ | |
2705 | struct breakpoint_objfile_data | |
2706 | { | |
2707 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
2708 | struct minimal_symbol *overlay_msym; | |
2709 | ||
2710 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
2711 | struct minimal_symbol *longjmp_msym[NUM_LONGJMP_NAMES]; | |
2712 | ||
2713 | /* Minimal symbol for "std::terminate()" (if any). */ | |
2714 | struct minimal_symbol *terminate_msym; | |
2715 | ||
2716 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
2717 | struct minimal_symbol *exception_msym; | |
2718 | }; | |
2719 | ||
2720 | static const struct objfile_data *breakpoint_objfile_key; | |
2721 | ||
2722 | /* Minimal symbol not found sentinel. */ | |
2723 | static struct minimal_symbol msym_not_found; | |
2724 | ||
2725 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
2726 | ||
2727 | static int | |
2728 | msym_not_found_p (const struct minimal_symbol *msym) | |
2729 | { | |
2730 | return msym == &msym_not_found; | |
2731 | } | |
2732 | ||
2733 | /* Return per-objfile data needed by breakpoint.c. | |
2734 | Allocate the data if necessary. */ | |
2735 | ||
2736 | static struct breakpoint_objfile_data * | |
2737 | get_breakpoint_objfile_data (struct objfile *objfile) | |
2738 | { | |
2739 | struct breakpoint_objfile_data *bp_objfile_data; | |
2740 | ||
2741 | bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key); | |
2742 | if (bp_objfile_data == NULL) | |
2743 | { | |
2744 | bp_objfile_data = obstack_alloc (&objfile->objfile_obstack, | |
2745 | sizeof (*bp_objfile_data)); | |
2746 | ||
2747 | memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); | |
2748 | set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); | |
2749 | } | |
2750 | return bp_objfile_data; | |
2751 | } | |
2752 | ||
e62c965a | 2753 | static void |
af02033e | 2754 | create_overlay_event_breakpoint (void) |
e62c965a | 2755 | { |
69de3c6a | 2756 | struct objfile *objfile; |
af02033e | 2757 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 2758 | |
69de3c6a PP |
2759 | ALL_OBJFILES (objfile) |
2760 | { | |
2761 | struct breakpoint *b; | |
17450429 PP |
2762 | struct breakpoint_objfile_data *bp_objfile_data; |
2763 | CORE_ADDR addr; | |
69de3c6a | 2764 | |
17450429 PP |
2765 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
2766 | ||
2767 | if (msym_not_found_p (bp_objfile_data->overlay_msym)) | |
2768 | continue; | |
2769 | ||
2770 | if (bp_objfile_data->overlay_msym == NULL) | |
2771 | { | |
2772 | struct minimal_symbol *m; | |
2773 | ||
2774 | m = lookup_minimal_symbol_text (func_name, objfile); | |
2775 | if (m == NULL) | |
2776 | { | |
2777 | /* Avoid future lookups in this objfile. */ | |
2778 | bp_objfile_data->overlay_msym = &msym_not_found; | |
2779 | continue; | |
2780 | } | |
2781 | bp_objfile_data->overlay_msym = m; | |
2782 | } | |
e62c965a | 2783 | |
17450429 PP |
2784 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
2785 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, | |
06edf0c0 PA |
2786 | bp_overlay_event, |
2787 | &internal_breakpoint_ops); | |
69de3c6a | 2788 | b->addr_string = xstrdup (func_name); |
e62c965a | 2789 | |
69de3c6a PP |
2790 | if (overlay_debugging == ovly_auto) |
2791 | { | |
2792 | b->enable_state = bp_enabled; | |
2793 | overlay_events_enabled = 1; | |
2794 | } | |
2795 | else | |
2796 | { | |
2797 | b->enable_state = bp_disabled; | |
2798 | overlay_events_enabled = 0; | |
2799 | } | |
e62c965a PP |
2800 | } |
2801 | update_global_location_list (1); | |
2802 | } | |
2803 | ||
0fd8e87f | 2804 | static void |
af02033e | 2805 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 2806 | { |
6c95b8df | 2807 | struct program_space *pspace; |
6c95b8df PA |
2808 | struct cleanup *old_chain; |
2809 | ||
2810 | old_chain = save_current_program_space (); | |
0fd8e87f | 2811 | |
6c95b8df | 2812 | ALL_PSPACES (pspace) |
af02033e PP |
2813 | { |
2814 | struct objfile *objfile; | |
2815 | ||
2816 | set_current_program_space (pspace); | |
2817 | ||
2818 | ALL_OBJFILES (objfile) | |
0fd8e87f | 2819 | { |
af02033e PP |
2820 | int i; |
2821 | struct gdbarch *gdbarch; | |
17450429 | 2822 | struct breakpoint_objfile_data *bp_objfile_data; |
0fd8e87f | 2823 | |
af02033e PP |
2824 | gdbarch = get_objfile_arch (objfile); |
2825 | if (!gdbarch_get_longjmp_target_p (gdbarch)) | |
0fd8e87f UW |
2826 | continue; |
2827 | ||
17450429 PP |
2828 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
2829 | ||
2830 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) | |
af02033e PP |
2831 | { |
2832 | struct breakpoint *b; | |
af02033e | 2833 | const char *func_name; |
17450429 | 2834 | CORE_ADDR addr; |
6c95b8df | 2835 | |
17450429 | 2836 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i])) |
af02033e | 2837 | continue; |
0fd8e87f | 2838 | |
17450429 PP |
2839 | func_name = longjmp_names[i]; |
2840 | if (bp_objfile_data->longjmp_msym[i] == NULL) | |
2841 | { | |
2842 | struct minimal_symbol *m; | |
2843 | ||
2844 | m = lookup_minimal_symbol_text (func_name, objfile); | |
2845 | if (m == NULL) | |
2846 | { | |
2847 | /* Prevent future lookups in this objfile. */ | |
2848 | bp_objfile_data->longjmp_msym[i] = &msym_not_found; | |
2849 | continue; | |
2850 | } | |
2851 | bp_objfile_data->longjmp_msym[i] = m; | |
2852 | } | |
2853 | ||
2854 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); | |
06edf0c0 PA |
2855 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, |
2856 | &internal_breakpoint_ops); | |
af02033e PP |
2857 | b->addr_string = xstrdup (func_name); |
2858 | b->enable_state = bp_disabled; | |
2859 | } | |
0fd8e87f | 2860 | } |
af02033e | 2861 | } |
0fd8e87f | 2862 | update_global_location_list (1); |
6c95b8df PA |
2863 | |
2864 | do_cleanups (old_chain); | |
0fd8e87f UW |
2865 | } |
2866 | ||
af02033e | 2867 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 2868 | static void |
af02033e | 2869 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
2870 | { |
2871 | struct program_space *pspace; | |
aa7d318d | 2872 | struct cleanup *old_chain; |
af02033e | 2873 | const char *const func_name = "std::terminate()"; |
aa7d318d TT |
2874 | |
2875 | old_chain = save_current_program_space (); | |
2876 | ||
2877 | ALL_PSPACES (pspace) | |
17450429 PP |
2878 | { |
2879 | struct objfile *objfile; | |
2880 | CORE_ADDR addr; | |
2881 | ||
2882 | set_current_program_space (pspace); | |
2883 | ||
aa7d318d TT |
2884 | ALL_OBJFILES (objfile) |
2885 | { | |
2886 | struct breakpoint *b; | |
17450429 | 2887 | struct breakpoint_objfile_data *bp_objfile_data; |
aa7d318d | 2888 | |
17450429 | 2889 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 2890 | |
17450429 PP |
2891 | if (msym_not_found_p (bp_objfile_data->terminate_msym)) |
2892 | continue; | |
2893 | ||
2894 | if (bp_objfile_data->terminate_msym == NULL) | |
2895 | { | |
2896 | struct minimal_symbol *m; | |
2897 | ||
2898 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
2899 | if (m == NULL || (MSYMBOL_TYPE (m) != mst_text | |
2900 | && MSYMBOL_TYPE (m) != mst_file_text)) | |
2901 | { | |
2902 | /* Prevent future lookups in this objfile. */ | |
2903 | bp_objfile_data->terminate_msym = &msym_not_found; | |
2904 | continue; | |
2905 | } | |
2906 | bp_objfile_data->terminate_msym = m; | |
2907 | } | |
aa7d318d | 2908 | |
17450429 PP |
2909 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
2910 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, | |
06edf0c0 PA |
2911 | bp_std_terminate_master, |
2912 | &internal_breakpoint_ops); | |
aa7d318d TT |
2913 | b->addr_string = xstrdup (func_name); |
2914 | b->enable_state = bp_disabled; | |
2915 | } | |
17450429 PP |
2916 | } |
2917 | ||
aa7d318d TT |
2918 | update_global_location_list (1); |
2919 | ||
2920 | do_cleanups (old_chain); | |
2921 | } | |
2922 | ||
186c406b TT |
2923 | /* Install a master breakpoint on the unwinder's debug hook. */ |
2924 | ||
2925 | void | |
2926 | create_exception_master_breakpoint (void) | |
2927 | { | |
2928 | struct objfile *objfile; | |
17450429 | 2929 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b TT |
2930 | |
2931 | ALL_OBJFILES (objfile) | |
2932 | { | |
17450429 PP |
2933 | struct breakpoint *b; |
2934 | struct gdbarch *gdbarch; | |
2935 | struct breakpoint_objfile_data *bp_objfile_data; | |
2936 | CORE_ADDR addr; | |
2937 | ||
2938 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
2939 | ||
2940 | if (msym_not_found_p (bp_objfile_data->exception_msym)) | |
2941 | continue; | |
2942 | ||
2943 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 2944 | |
17450429 | 2945 | if (bp_objfile_data->exception_msym == NULL) |
186c406b | 2946 | { |
17450429 | 2947 | struct minimal_symbol *debug_hook; |
186c406b | 2948 | |
17450429 PP |
2949 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
2950 | if (debug_hook == NULL) | |
2951 | { | |
2952 | bp_objfile_data->exception_msym = &msym_not_found; | |
2953 | continue; | |
2954 | } | |
2955 | ||
2956 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 2957 | } |
17450429 PP |
2958 | |
2959 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); | |
2960 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, | |
2961 | ¤t_target); | |
06edf0c0 PA |
2962 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
2963 | &internal_breakpoint_ops); | |
17450429 PP |
2964 | b->addr_string = xstrdup (func_name); |
2965 | b->enable_state = bp_disabled; | |
186c406b TT |
2966 | } |
2967 | ||
2968 | update_global_location_list (1); | |
2969 | } | |
2970 | ||
c906108c | 2971 | void |
fba45db2 | 2972 | update_breakpoints_after_exec (void) |
c906108c | 2973 | { |
35df4500 | 2974 | struct breakpoint *b, *b_tmp; |
876fa593 | 2975 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 2976 | |
25b22b0a PA |
2977 | /* We're about to delete breakpoints from GDB's lists. If the |
2978 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
2979 | writing the breakpoints' "shadow contents" back into memory. The | |
2980 | "shadow contents" are NOT valid after an exec, so GDB should not | |
2981 | do that. Instead, the target is responsible from marking | |
2982 | breakpoints out as soon as it detects an exec. We don't do that | |
2983 | here instead, because there may be other attempts to delete | |
2984 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 2985 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
2986 | if (bploc->pspace == current_program_space) |
2987 | gdb_assert (!bploc->inserted); | |
c906108c | 2988 | |
35df4500 | 2989 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 2990 | { |
6c95b8df PA |
2991 | if (b->pspace != current_program_space) |
2992 | continue; | |
2993 | ||
4a64f543 | 2994 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
2995 | if (b->type == bp_shlib_event) |
2996 | { | |
2997 | delete_breakpoint (b); | |
2998 | continue; | |
2999 | } | |
c906108c | 3000 | |
4a64f543 | 3001 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
3002 | if (b->type == bp_jit_event) |
3003 | { | |
3004 | delete_breakpoint (b); | |
3005 | continue; | |
3006 | } | |
3007 | ||
1900040c | 3008 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
3009 | as must overlay event and longjmp master breakpoints. */ |
3010 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
3011 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
3012 | || b->type == bp_exception_master) | |
c4093a6a JM |
3013 | { |
3014 | delete_breakpoint (b); | |
3015 | continue; | |
3016 | } | |
3017 | ||
4a64f543 | 3018 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2c03e5be | 3019 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
c5aa993b JM |
3020 | { |
3021 | delete_breakpoint (b); | |
3022 | continue; | |
3023 | } | |
3024 | ||
611c83ae PA |
3025 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
3026 | after an exec. */ | |
186c406b TT |
3027 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
3028 | || b->type == bp_exception || b->type == bp_exception_resume) | |
611c83ae PA |
3029 | { |
3030 | delete_breakpoint (b); | |
3031 | continue; | |
3032 | } | |
3033 | ||
ce78b96d JB |
3034 | if (b->type == bp_catchpoint) |
3035 | { | |
3036 | /* For now, none of the bp_catchpoint breakpoints need to | |
3037 | do anything at this point. In the future, if some of | |
3038 | the catchpoints need to something, we will need to add | |
3039 | a new method, and call this method from here. */ | |
3040 | continue; | |
3041 | } | |
3042 | ||
c5aa993b JM |
3043 | /* bp_finish is a special case. The only way we ought to be able |
3044 | to see one of these when an exec() has happened, is if the user | |
3045 | caught a vfork, and then said "finish". Ordinarily a finish just | |
3046 | carries them to the call-site of the current callee, by setting | |
3047 | a temporary bp there and resuming. But in this case, the finish | |
3048 | will carry them entirely through the vfork & exec. | |
3049 | ||
3050 | We don't want to allow a bp_finish to remain inserted now. But | |
3051 | we can't safely delete it, 'cause finish_command has a handle to | |
3052 | the bp on a bpstat, and will later want to delete it. There's a | |
3053 | chance (and I've seen it happen) that if we delete the bp_finish | |
3054 | here, that its storage will get reused by the time finish_command | |
3055 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
3056 | We really must allow finish_command to delete a bp_finish. | |
3057 | ||
e5dd4106 | 3058 | In the absence of a general solution for the "how do we know |
53a5351d JM |
3059 | it's safe to delete something others may have handles to?" |
3060 | problem, what we'll do here is just uninsert the bp_finish, and | |
3061 | let finish_command delete it. | |
3062 | ||
3063 | (We know the bp_finish is "doomed" in the sense that it's | |
3064 | momentary, and will be deleted as soon as finish_command sees | |
3065 | the inferior stopped. So it doesn't matter that the bp's | |
3066 | address is probably bogus in the new a.out, unlike e.g., the | |
3067 | solib breakpoints.) */ | |
c5aa993b | 3068 | |
c5aa993b JM |
3069 | if (b->type == bp_finish) |
3070 | { | |
3071 | continue; | |
3072 | } | |
3073 | ||
3074 | /* Without a symbolic address, we have little hope of the | |
3075 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 3076 | a.out. */ |
c5aa993b JM |
3077 | if (b->addr_string == NULL) |
3078 | { | |
3079 | delete_breakpoint (b); | |
3080 | continue; | |
3081 | } | |
c5aa993b | 3082 | } |
1900040c | 3083 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
af02033e PP |
3084 | create_overlay_event_breakpoint (); |
3085 | create_longjmp_master_breakpoint (); | |
3086 | create_std_terminate_master_breakpoint (); | |
186c406b | 3087 | create_exception_master_breakpoint (); |
c906108c SS |
3088 | } |
3089 | ||
3090 | int | |
fba45db2 | 3091 | detach_breakpoints (int pid) |
c906108c | 3092 | { |
35df4500 | 3093 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3094 | int val = 0; |
ce696e05 | 3095 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 3096 | struct inferior *inf = current_inferior (); |
c5aa993b | 3097 | |
39f77062 | 3098 | if (pid == PIDGET (inferior_ptid)) |
8a3fe4f8 | 3099 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 3100 | |
6c95b8df | 3101 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
ce696e05 | 3102 | inferior_ptid = pid_to_ptid (pid); |
35df4500 | 3103 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3104 | { |
35df4500 | 3105 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3106 | continue; |
3107 | ||
35df4500 TJB |
3108 | if (bl->inserted) |
3109 | val |= remove_breakpoint_1 (bl, mark_inserted); | |
c5aa993b | 3110 | } |
d03285ec UW |
3111 | |
3112 | /* Detach single-step breakpoints as well. */ | |
3113 | detach_single_step_breakpoints (); | |
3114 | ||
ce696e05 | 3115 | do_cleanups (old_chain); |
3a1bae8e | 3116 | return val; |
c906108c SS |
3117 | } |
3118 | ||
35df4500 | 3119 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
3120 | Note that this is used to detach breakpoints from a child fork. |
3121 | When we get here, the child isn't in the inferior list, and neither | |
3122 | do we have objects to represent its address space --- we should | |
35df4500 | 3123 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 3124 | |
c906108c | 3125 | static int |
35df4500 | 3126 | remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is) |
c906108c SS |
3127 | { |
3128 | int val; | |
c5aa993b | 3129 | |
35df4500 TJB |
3130 | /* BL is never in moribund_locations by our callers. */ |
3131 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3132 | |
35df4500 | 3133 | if (bl->owner->enable_state == bp_permanent) |
c2c6d25f JM |
3134 | /* Permanent breakpoints cannot be inserted or removed. */ |
3135 | return 0; | |
3136 | ||
74960c60 VP |
3137 | /* The type of none suggests that owner is actually deleted. |
3138 | This should not ever happen. */ | |
35df4500 | 3139 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 3140 | |
35df4500 TJB |
3141 | if (bl->loc_type == bp_loc_software_breakpoint |
3142 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 3143 | { |
c02f5703 MS |
3144 | /* "Normal" instruction breakpoint: either the standard |
3145 | trap-instruction bp (bp_breakpoint), or a | |
3146 | bp_hardware_breakpoint. */ | |
3147 | ||
3148 | /* First check to see if we have to handle an overlay. */ | |
3149 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
3150 | || bl->section == NULL |
3151 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
3152 | { |
3153 | /* No overlay handling: just remove the breakpoint. */ | |
348d480f | 3154 | val = bl->owner->ops->remove_location (bl); |
c02f5703 | 3155 | } |
c906108c SS |
3156 | else |
3157 | { | |
4a64f543 | 3158 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
3159 | Did we set a breakpoint at the LMA? */ |
3160 | if (!overlay_events_enabled) | |
3161 | { | |
3162 | /* Yes -- overlay event support is not active, so we | |
3163 | should have set a breakpoint at the LMA. Remove it. | |
3164 | */ | |
c02f5703 MS |
3165 | /* Ignore any failures: if the LMA is in ROM, we will |
3166 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
3167 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
3168 | target_remove_hw_breakpoint (bl->gdbarch, | |
3169 | &bl->overlay_target_info); | |
c02f5703 | 3170 | else |
35df4500 TJB |
3171 | target_remove_breakpoint (bl->gdbarch, |
3172 | &bl->overlay_target_info); | |
c02f5703 MS |
3173 | } |
3174 | /* Did we set a breakpoint at the VMA? | |
3175 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 3176 | if (bl->inserted) |
c906108c | 3177 | { |
c02f5703 MS |
3178 | /* Yes -- remove it. Previously we did not bother to |
3179 | remove the breakpoint if the section had been | |
3180 | unmapped, but let's not rely on that being safe. We | |
3181 | don't know what the overlay manager might do. */ | |
aa67235e UW |
3182 | |
3183 | /* However, we should remove *software* breakpoints only | |
3184 | if the section is still mapped, or else we overwrite | |
3185 | wrong code with the saved shadow contents. */ | |
348d480f PA |
3186 | if (bl->loc_type == bp_loc_hardware_breakpoint |
3187 | || section_is_mapped (bl->section)) | |
3188 | val = bl->owner->ops->remove_location (bl); | |
aa67235e UW |
3189 | else |
3190 | val = 0; | |
c906108c | 3191 | } |
c02f5703 MS |
3192 | else |
3193 | { | |
3194 | /* No -- not inserted, so no need to remove. No error. */ | |
3195 | val = 0; | |
3196 | } | |
c906108c | 3197 | } |
879d1e6b UW |
3198 | |
3199 | /* In some cases, we might not be able to remove a breakpoint | |
3200 | in a shared library that has already been removed, but we | |
3201 | have not yet processed the shlib unload event. */ | |
35df4500 | 3202 | if (val && solib_name_from_address (bl->pspace, bl->address)) |
879d1e6b UW |
3203 | val = 0; |
3204 | ||
c906108c SS |
3205 | if (val) |
3206 | return val; | |
35df4500 | 3207 | bl->inserted = (is == mark_inserted); |
c906108c | 3208 | } |
35df4500 | 3209 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 3210 | { |
77b06cd7 TJB |
3211 | gdb_assert (bl->owner->ops != NULL |
3212 | && bl->owner->ops->remove_location != NULL); | |
3213 | ||
35df4500 | 3214 | bl->inserted = (is == mark_inserted); |
77b06cd7 | 3215 | bl->owner->ops->remove_location (bl); |
2e70b7b9 | 3216 | |
c906108c | 3217 | /* Failure to remove any of the hardware watchpoints comes here. */ |
35df4500 | 3218 | if ((is == mark_uninserted) && (bl->inserted)) |
8a3fe4f8 | 3219 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 3220 | bl->owner->number); |
c906108c | 3221 | } |
35df4500 TJB |
3222 | else if (bl->owner->type == bp_catchpoint |
3223 | && breakpoint_enabled (bl->owner) | |
3224 | && !bl->duplicate) | |
ce78b96d | 3225 | { |
77b06cd7 TJB |
3226 | gdb_assert (bl->owner->ops != NULL |
3227 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 3228 | |
77b06cd7 | 3229 | val = bl->owner->ops->remove_location (bl); |
ce78b96d JB |
3230 | if (val) |
3231 | return val; | |
77b06cd7 | 3232 | |
35df4500 | 3233 | bl->inserted = (is == mark_inserted); |
ce78b96d | 3234 | } |
c906108c SS |
3235 | |
3236 | return 0; | |
3237 | } | |
3238 | ||
6c95b8df | 3239 | static int |
35df4500 | 3240 | remove_breakpoint (struct bp_location *bl, insertion_state_t is) |
6c95b8df PA |
3241 | { |
3242 | int ret; | |
3243 | struct cleanup *old_chain; | |
3244 | ||
35df4500 TJB |
3245 | /* BL is never in moribund_locations by our callers. */ |
3246 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3247 | |
35df4500 | 3248 | if (bl->owner->enable_state == bp_permanent) |
6c95b8df PA |
3249 | /* Permanent breakpoints cannot be inserted or removed. */ |
3250 | return 0; | |
3251 | ||
3252 | /* The type of none suggests that owner is actually deleted. | |
3253 | This should not ever happen. */ | |
35df4500 | 3254 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df PA |
3255 | |
3256 | old_chain = save_current_space_and_thread (); | |
3257 | ||
35df4500 | 3258 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 3259 | |
35df4500 | 3260 | ret = remove_breakpoint_1 (bl, is); |
6c95b8df PA |
3261 | |
3262 | do_cleanups (old_chain); | |
3263 | return ret; | |
3264 | } | |
3265 | ||
c906108c SS |
3266 | /* Clear the "inserted" flag in all breakpoints. */ |
3267 | ||
25b22b0a | 3268 | void |
fba45db2 | 3269 | mark_breakpoints_out (void) |
c906108c | 3270 | { |
35df4500 | 3271 | struct bp_location *bl, **blp_tmp; |
c906108c | 3272 | |
35df4500 TJB |
3273 | ALL_BP_LOCATIONS (bl, blp_tmp) |
3274 | if (bl->pspace == current_program_space) | |
3275 | bl->inserted = 0; | |
c906108c SS |
3276 | } |
3277 | ||
53a5351d JM |
3278 | /* Clear the "inserted" flag in all breakpoints and delete any |
3279 | breakpoints which should go away between runs of the program. | |
c906108c SS |
3280 | |
3281 | Plus other such housekeeping that has to be done for breakpoints | |
3282 | between runs. | |
3283 | ||
53a5351d JM |
3284 | Note: this function gets called at the end of a run (by |
3285 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 3286 | init_wait_for_inferior). */ |
c906108c SS |
3287 | |
3288 | ||
3289 | ||
3290 | void | |
fba45db2 | 3291 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 3292 | { |
35df4500 TJB |
3293 | struct breakpoint *b, *b_tmp; |
3294 | struct bp_location *bl, **blp_tmp; | |
1c5cfe86 | 3295 | int ix; |
6c95b8df | 3296 | struct program_space *pspace = current_program_space; |
c906108c | 3297 | |
50c71eaf PA |
3298 | /* If breakpoint locations are shared across processes, then there's |
3299 | nothing to do. */ | |
2567c7d9 | 3300 | if (gdbarch_has_global_breakpoints (target_gdbarch)) |
50c71eaf PA |
3301 | return; |
3302 | ||
35df4500 | 3303 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 3304 | { |
35df4500 TJB |
3305 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
3306 | if (bl->pspace == pspace | |
3307 | && bl->owner->enable_state != bp_permanent) | |
3308 | bl->inserted = 0; | |
6c95b8df | 3309 | } |
075f6582 | 3310 | |
35df4500 | 3311 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3312 | { |
6c95b8df PA |
3313 | if (b->loc && b->loc->pspace != pspace) |
3314 | continue; | |
3315 | ||
c5aa993b JM |
3316 | switch (b->type) |
3317 | { | |
3318 | case bp_call_dummy: | |
c906108c | 3319 | |
c5aa993b | 3320 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
3321 | cause problems when the inferior is rerun, so we better get |
3322 | rid of it. */ | |
3323 | ||
3324 | case bp_watchpoint_scope: | |
3325 | ||
3326 | /* Also get rid of scope breakpoints. */ | |
3327 | ||
3328 | case bp_shlib_event: | |
3329 | ||
3330 | /* Also remove solib event breakpoints. Their addresses may | |
3331 | have changed since the last time we ran the program. | |
3332 | Actually we may now be debugging against different target; | |
3333 | and so the solib backend that installed this breakpoint may | |
3334 | not be used in by the target. E.g., | |
3335 | ||
3336 | (gdb) file prog-linux | |
3337 | (gdb) run # native linux target | |
3338 | ... | |
3339 | (gdb) kill | |
3340 | (gdb) file prog-win.exe | |
3341 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
3342 | */ | |
c906108c | 3343 | |
c5aa993b JM |
3344 | delete_breakpoint (b); |
3345 | break; | |
c906108c | 3346 | |
c5aa993b JM |
3347 | case bp_watchpoint: |
3348 | case bp_hardware_watchpoint: | |
3349 | case bp_read_watchpoint: | |
3350 | case bp_access_watchpoint: | |
3a5c3e22 PA |
3351 | { |
3352 | struct watchpoint *w = (struct watchpoint *) b; | |
c906108c | 3353 | |
3a5c3e22 PA |
3354 | /* Likewise for watchpoints on local expressions. */ |
3355 | if (w->exp_valid_block != NULL) | |
3356 | delete_breakpoint (b); | |
3357 | else if (context == inf_starting) | |
3358 | { | |
3359 | /* Reset val field to force reread of starting value in | |
3360 | insert_breakpoints. */ | |
3361 | if (w->val) | |
3362 | value_free (w->val); | |
3363 | w->val = NULL; | |
3364 | w->val_valid = 0; | |
c860120c | 3365 | } |
3a5c3e22 | 3366 | } |
c5aa993b JM |
3367 | break; |
3368 | default: | |
c5aa993b JM |
3369 | break; |
3370 | } | |
3371 | } | |
1c5cfe86 PA |
3372 | |
3373 | /* Get rid of the moribund locations. */ | |
35df4500 TJB |
3374 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
3375 | decref_bp_location (&bl); | |
1c5cfe86 | 3376 | VEC_free (bp_location_p, moribund_locations); |
c906108c SS |
3377 | } |
3378 | ||
6c95b8df PA |
3379 | /* These functions concern about actual breakpoints inserted in the |
3380 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
3381 | we need to hop over the bkpt --- so we check for address space | |
3382 | match, not program space. */ | |
3383 | ||
c2c6d25f JM |
3384 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
3385 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
3386 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
3387 | permanent breakpoint. | |
3388 | - When continuing from a location with an ordinary breakpoint, we | |
3389 | actually single step once before calling insert_breakpoints. | |
e5dd4106 | 3390 | - When continuing from a location with a permanent breakpoint, we |
c2c6d25f JM |
3391 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
3392 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 3393 | |
c2c6d25f | 3394 | enum breakpoint_here |
6c95b8df | 3395 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 3396 | { |
35df4500 | 3397 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 3398 | int any_breakpoint_here = 0; |
c906108c | 3399 | |
35df4500 | 3400 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 3401 | { |
35df4500 TJB |
3402 | if (bl->loc_type != bp_loc_software_breakpoint |
3403 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
3404 | continue; |
3405 | ||
f1310107 | 3406 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 TJB |
3407 | if ((breakpoint_enabled (bl->owner) |
3408 | || bl->owner->enable_state == bp_permanent) | |
f1310107 | 3409 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
3410 | { |
3411 | if (overlay_debugging | |
35df4500 TJB |
3412 | && section_is_overlay (bl->section) |
3413 | && !section_is_mapped (bl->section)) | |
075f6582 | 3414 | continue; /* unmapped overlay -- can't be a match */ |
35df4500 | 3415 | else if (bl->owner->enable_state == bp_permanent) |
075f6582 DJ |
3416 | return permanent_breakpoint_here; |
3417 | else | |
3418 | any_breakpoint_here = 1; | |
3419 | } | |
3420 | } | |
c906108c | 3421 | |
c2c6d25f | 3422 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
3423 | } |
3424 | ||
1c5cfe86 PA |
3425 | /* Return true if there's a moribund breakpoint at PC. */ |
3426 | ||
3427 | int | |
6c95b8df | 3428 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
3429 | { |
3430 | struct bp_location *loc; | |
3431 | int ix; | |
3432 | ||
3433 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
f1310107 | 3434 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
3435 | return 1; |
3436 | ||
3437 | return 0; | |
3438 | } | |
c2c6d25f | 3439 | |
c36b740a | 3440 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
4a64f543 MS |
3441 | inserted using regular breakpoint_chain / bp_location array |
3442 | mechanism. This does not check for single-step breakpoints, which | |
3443 | are inserted and removed using direct target manipulation. */ | |
c906108c SS |
3444 | |
3445 | int | |
4a64f543 MS |
3446 | regular_breakpoint_inserted_here_p (struct address_space *aspace, |
3447 | CORE_ADDR pc) | |
c906108c | 3448 | { |
35df4500 | 3449 | struct bp_location *bl, **blp_tmp; |
c906108c | 3450 | |
35df4500 | 3451 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3452 | { |
35df4500 TJB |
3453 | if (bl->loc_type != bp_loc_software_breakpoint |
3454 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
3455 | continue; |
3456 | ||
35df4500 | 3457 | if (bl->inserted |
f1310107 | 3458 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
3459 | { |
3460 | if (overlay_debugging | |
35df4500 TJB |
3461 | && section_is_overlay (bl->section) |
3462 | && !section_is_mapped (bl->section)) | |
075f6582 DJ |
3463 | continue; /* unmapped overlay -- can't be a match */ |
3464 | else | |
3465 | return 1; | |
3466 | } | |
c5aa993b | 3467 | } |
c36b740a VP |
3468 | return 0; |
3469 | } | |
3470 | ||
3471 | /* Returns non-zero iff there's either regular breakpoint | |
3472 | or a single step breakpoint inserted at PC. */ | |
3473 | ||
3474 | int | |
6c95b8df | 3475 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c36b740a | 3476 | { |
6c95b8df | 3477 | if (regular_breakpoint_inserted_here_p (aspace, pc)) |
c36b740a | 3478 | return 1; |
c906108c | 3479 | |
6c95b8df | 3480 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
3481 | return 1; |
3482 | ||
c906108c SS |
3483 | return 0; |
3484 | } | |
3485 | ||
4fa8626c DJ |
3486 | /* This function returns non-zero iff there is a software breakpoint |
3487 | inserted at PC. */ | |
3488 | ||
3489 | int | |
3e43a32a MS |
3490 | software_breakpoint_inserted_here_p (struct address_space *aspace, |
3491 | CORE_ADDR pc) | |
4fa8626c | 3492 | { |
35df4500 | 3493 | struct bp_location *bl, **blp_tmp; |
4fa8626c | 3494 | |
35df4500 | 3495 | ALL_BP_LOCATIONS (bl, blp_tmp) |
4fa8626c | 3496 | { |
35df4500 | 3497 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
3498 | continue; |
3499 | ||
35df4500 TJB |
3500 | if (bl->inserted |
3501 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6c95b8df | 3502 | aspace, pc)) |
4fa8626c DJ |
3503 | { |
3504 | if (overlay_debugging | |
35df4500 TJB |
3505 | && section_is_overlay (bl->section) |
3506 | && !section_is_mapped (bl->section)) | |
4fa8626c DJ |
3507 | continue; /* unmapped overlay -- can't be a match */ |
3508 | else | |
3509 | return 1; | |
3510 | } | |
3511 | } | |
3512 | ||
1aafd4da | 3513 | /* Also check for software single-step breakpoints. */ |
6c95b8df | 3514 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
3515 | return 1; |
3516 | ||
4fa8626c DJ |
3517 | return 0; |
3518 | } | |
3519 | ||
9093389c PA |
3520 | int |
3521 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
3522 | CORE_ADDR addr, ULONGEST len) | |
3523 | { | |
3524 | struct breakpoint *bpt; | |
3525 | ||
3526 | ALL_BREAKPOINTS (bpt) | |
3527 | { | |
3528 | struct bp_location *loc; | |
3529 | ||
3530 | if (bpt->type != bp_hardware_watchpoint | |
3531 | && bpt->type != bp_access_watchpoint) | |
3532 | continue; | |
3533 | ||
3534 | if (!breakpoint_enabled (bpt)) | |
3535 | continue; | |
3536 | ||
3537 | for (loc = bpt->loc; loc; loc = loc->next) | |
3538 | if (loc->pspace->aspace == aspace && loc->inserted) | |
3539 | { | |
3540 | CORE_ADDR l, h; | |
3541 | ||
3542 | /* Check for intersection. */ | |
3543 | l = max (loc->address, addr); | |
3544 | h = min (loc->address + loc->length, addr + len); | |
3545 | if (l < h) | |
3546 | return 1; | |
3547 | } | |
3548 | } | |
3549 | return 0; | |
3550 | } | |
3551 | ||
075f6582 DJ |
3552 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
3553 | PC is valid for process/thread PTID. */ | |
c906108c SS |
3554 | |
3555 | int | |
6c95b8df PA |
3556 | breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc, |
3557 | ptid_t ptid) | |
c906108c | 3558 | { |
35df4500 | 3559 | struct bp_location *bl, **blp_tmp; |
4a306c9a | 3560 | /* The thread and task IDs associated to PTID, computed lazily. */ |
a6f1cd96 | 3561 | int thread = -1; |
4a306c9a | 3562 | int task = 0; |
a6f1cd96 | 3563 | |
35df4500 | 3564 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3565 | { |
35df4500 TJB |
3566 | if (bl->loc_type != bp_loc_software_breakpoint |
3567 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
3568 | continue; |
3569 | ||
35df4500 TJB |
3570 | /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */ |
3571 | if (!breakpoint_enabled (bl->owner) | |
3572 | && bl->owner->enable_state != bp_permanent) | |
a6f1cd96 JB |
3573 | continue; |
3574 | ||
f1310107 | 3575 | if (!breakpoint_location_address_match (bl, aspace, pc)) |
a6f1cd96 JB |
3576 | continue; |
3577 | ||
35df4500 | 3578 | if (bl->owner->thread != -1) |
075f6582 | 3579 | { |
a6f1cd96 JB |
3580 | /* This is a thread-specific breakpoint. Check that ptid |
3581 | matches that thread. If thread hasn't been computed yet, | |
3582 | it is now time to do so. */ | |
3583 | if (thread == -1) | |
3584 | thread = pid_to_thread_id (ptid); | |
35df4500 | 3585 | if (bl->owner->thread != thread) |
a6f1cd96 | 3586 | continue; |
075f6582 | 3587 | } |
a6f1cd96 | 3588 | |
35df4500 | 3589 | if (bl->owner->task != 0) |
4a306c9a JB |
3590 | { |
3591 | /* This is a task-specific breakpoint. Check that ptid | |
3592 | matches that task. If task hasn't been computed yet, | |
3593 | it is now time to do so. */ | |
3594 | if (task == 0) | |
3595 | task = ada_get_task_number (ptid); | |
35df4500 | 3596 | if (bl->owner->task != task) |
4a306c9a JB |
3597 | continue; |
3598 | } | |
3599 | ||
a6f1cd96 | 3600 | if (overlay_debugging |
35df4500 TJB |
3601 | && section_is_overlay (bl->section) |
3602 | && !section_is_mapped (bl->section)) | |
a6f1cd96 JB |
3603 | continue; /* unmapped overlay -- can't be a match */ |
3604 | ||
3605 | return 1; | |
c5aa993b | 3606 | } |
c906108c SS |
3607 | |
3608 | return 0; | |
3609 | } | |
c906108c | 3610 | \f |
c5aa993b | 3611 | |
c906108c SS |
3612 | /* bpstat stuff. External routines' interfaces are documented |
3613 | in breakpoint.h. */ | |
3614 | ||
3615 | int | |
fba45db2 | 3616 | ep_is_catchpoint (struct breakpoint *ep) |
c906108c | 3617 | { |
533be4dd | 3618 | return (ep->type == bp_catchpoint); |
c906108c SS |
3619 | } |
3620 | ||
f431efe5 PA |
3621 | /* Frees any storage that is part of a bpstat. Does not walk the |
3622 | 'next' chain. */ | |
3623 | ||
3624 | static void | |
198757a8 VP |
3625 | bpstat_free (bpstat bs) |
3626 | { | |
3627 | if (bs->old_val != NULL) | |
3628 | value_free (bs->old_val); | |
9add0f1b | 3629 | decref_counted_command_line (&bs->commands); |
f431efe5 | 3630 | decref_bp_location (&bs->bp_location_at); |
198757a8 VP |
3631 | xfree (bs); |
3632 | } | |
3633 | ||
c906108c SS |
3634 | /* Clear a bpstat so that it says we are not at any breakpoint. |
3635 | Also free any storage that is part of a bpstat. */ | |
3636 | ||
3637 | void | |
fba45db2 | 3638 | bpstat_clear (bpstat *bsp) |
c906108c SS |
3639 | { |
3640 | bpstat p; | |
3641 | bpstat q; | |
3642 | ||
3643 | if (bsp == 0) | |
3644 | return; | |
3645 | p = *bsp; | |
3646 | while (p != NULL) | |
3647 | { | |
3648 | q = p->next; | |
198757a8 | 3649 | bpstat_free (p); |
c906108c SS |
3650 | p = q; |
3651 | } | |
3652 | *bsp = NULL; | |
3653 | } | |
3654 | ||
3655 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
3656 | is part of the bpstat is copied as well. */ | |
3657 | ||
3658 | bpstat | |
fba45db2 | 3659 | bpstat_copy (bpstat bs) |
c906108c SS |
3660 | { |
3661 | bpstat p = NULL; | |
3662 | bpstat tmp; | |
3663 | bpstat retval = NULL; | |
3664 | ||
3665 | if (bs == NULL) | |
3666 | return bs; | |
3667 | ||
3668 | for (; bs != NULL; bs = bs->next) | |
3669 | { | |
3670 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
3671 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 3672 | incref_counted_command_line (tmp->commands); |
f431efe5 | 3673 | incref_bp_location (tmp->bp_location_at); |
31cc81e9 | 3674 | if (bs->old_val != NULL) |
3c3185ac JK |
3675 | { |
3676 | tmp->old_val = value_copy (bs->old_val); | |
3677 | release_value (tmp->old_val); | |
3678 | } | |
31cc81e9 | 3679 | |
c906108c SS |
3680 | if (p == NULL) |
3681 | /* This is the first thing in the chain. */ | |
3682 | retval = tmp; | |
3683 | else | |
3684 | p->next = tmp; | |
3685 | p = tmp; | |
3686 | } | |
3687 | p->next = NULL; | |
3688 | return retval; | |
3689 | } | |
3690 | ||
4a64f543 | 3691 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
3692 | |
3693 | bpstat | |
fba45db2 | 3694 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 3695 | { |
c5aa993b JM |
3696 | if (bsp == NULL) |
3697 | return NULL; | |
c906108c | 3698 | |
c5aa993b JM |
3699 | for (; bsp != NULL; bsp = bsp->next) |
3700 | { | |
f431efe5 | 3701 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
3702 | return bsp; |
3703 | } | |
c906108c SS |
3704 | return NULL; |
3705 | } | |
3706 | ||
4a64f543 MS |
3707 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
3708 | stopped at. *BSP upon return is a bpstat which points to the | |
3709 | remaining breakpoints stopped at (but which is not guaranteed to be | |
3710 | good for anything but further calls to bpstat_num). | |
3711 | ||
8671a17b PA |
3712 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
3713 | Return -1 if stopped at a breakpoint that has been deleted since | |
3714 | we set it. | |
3715 | Return 1 otherwise. */ | |
c906108c SS |
3716 | |
3717 | int | |
8671a17b | 3718 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
3719 | { |
3720 | struct breakpoint *b; | |
3721 | ||
3722 | if ((*bsp) == NULL) | |
3723 | return 0; /* No more breakpoint values */ | |
8671a17b | 3724 | |
4a64f543 MS |
3725 | /* We assume we'll never have several bpstats that correspond to a |
3726 | single breakpoint -- otherwise, this function might return the | |
3727 | same number more than once and this will look ugly. */ | |
f431efe5 | 3728 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
3729 | *bsp = (*bsp)->next; |
3730 | if (b == NULL) | |
3731 | return -1; /* breakpoint that's been deleted since */ | |
3732 | ||
3733 | *num = b->number; /* We have its number */ | |
3734 | return 1; | |
c906108c SS |
3735 | } |
3736 | ||
e93ca019 | 3737 | /* See breakpoint.h. */ |
c906108c SS |
3738 | |
3739 | void | |
e93ca019 | 3740 | bpstat_clear_actions (void) |
c906108c | 3741 | { |
e93ca019 JK |
3742 | struct thread_info *tp; |
3743 | bpstat bs; | |
3744 | ||
3745 | if (ptid_equal (inferior_ptid, null_ptid)) | |
3746 | return; | |
3747 | ||
3748 | tp = find_thread_ptid (inferior_ptid); | |
3749 | if (tp == NULL) | |
3750 | return; | |
3751 | ||
3752 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) | |
c906108c | 3753 | { |
9add0f1b | 3754 | decref_counted_command_line (&bs->commands); |
abf85f46 | 3755 | |
c906108c SS |
3756 | if (bs->old_val != NULL) |
3757 | { | |
3758 | value_free (bs->old_val); | |
3759 | bs->old_val = NULL; | |
3760 | } | |
3761 | } | |
3762 | } | |
3763 | ||
f3b1572e PA |
3764 | /* Called when a command is about to proceed the inferior. */ |
3765 | ||
3766 | static void | |
3767 | breakpoint_about_to_proceed (void) | |
3768 | { | |
3769 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
3770 | { | |
3771 | struct thread_info *tp = inferior_thread (); | |
3772 | ||
3773 | /* Allow inferior function calls in breakpoint commands to not | |
3774 | interrupt the command list. When the call finishes | |
3775 | successfully, the inferior will be standing at the same | |
3776 | breakpoint as if nothing happened. */ | |
16c381f0 | 3777 | if (tp->control.in_infcall) |
f3b1572e PA |
3778 | return; |
3779 | } | |
3780 | ||
3781 | breakpoint_proceeded = 1; | |
3782 | } | |
3783 | ||
4a64f543 MS |
3784 | /* Stub for cleaning up our state if we error-out of a breakpoint |
3785 | command. */ | |
c906108c | 3786 | static void |
4efb68b1 | 3787 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
3788 | { |
3789 | executing_breakpoint_commands = 0; | |
3790 | } | |
3791 | ||
abf85f46 JK |
3792 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
3793 | or its equivalent. */ | |
3794 | ||
3795 | static int | |
3796 | command_line_is_silent (struct command_line *cmd) | |
3797 | { | |
3798 | return cmd && (strcmp ("silent", cmd->line) == 0 | |
3799 | || (xdb_commands && strcmp ("Q", cmd->line) == 0)); | |
3800 | } | |
3801 | ||
4a64f543 MS |
3802 | /* Execute all the commands associated with all the breakpoints at |
3803 | this location. Any of these commands could cause the process to | |
3804 | proceed beyond this point, etc. We look out for such changes by | |
3805 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 3806 | |
347bddb7 PA |
3807 | Returns true if a breakpoint command resumed the inferior. In that |
3808 | case, it is the caller's responsibility to recall it again with the | |
3809 | bpstat of the current thread. */ | |
3810 | ||
3811 | static int | |
3812 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
3813 | { |
3814 | bpstat bs; | |
3815 | struct cleanup *old_chain; | |
347bddb7 | 3816 | int again = 0; |
c906108c SS |
3817 | |
3818 | /* Avoid endless recursion if a `source' command is contained | |
3819 | in bs->commands. */ | |
3820 | if (executing_breakpoint_commands) | |
347bddb7 | 3821 | return 0; |
c906108c SS |
3822 | |
3823 | executing_breakpoint_commands = 1; | |
3824 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
3825 | ||
cf6c5ffb TT |
3826 | prevent_dont_repeat (); |
3827 | ||
4a64f543 | 3828 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
3829 | bs = *bsp; |
3830 | ||
3831 | breakpoint_proceeded = 0; | |
3832 | for (; bs != NULL; bs = bs->next) | |
3833 | { | |
9add0f1b | 3834 | struct counted_command_line *ccmd; |
6c50ab1c JB |
3835 | struct command_line *cmd; |
3836 | struct cleanup *this_cmd_tree_chain; | |
3837 | ||
3838 | /* Take ownership of the BSP's command tree, if it has one. | |
3839 | ||
3840 | The command tree could legitimately contain commands like | |
3841 | 'step' and 'next', which call clear_proceed_status, which | |
3842 | frees stop_bpstat's command tree. To make sure this doesn't | |
3843 | free the tree we're executing out from under us, we need to | |
3844 | take ownership of the tree ourselves. Since a given bpstat's | |
3845 | commands are only executed once, we don't need to copy it; we | |
3846 | can clear the pointer in the bpstat, and make sure we free | |
3847 | the tree when we're done. */ | |
9add0f1b TT |
3848 | ccmd = bs->commands; |
3849 | bs->commands = NULL; | |
abf85f46 JK |
3850 | this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd); |
3851 | cmd = ccmd ? ccmd->commands : NULL; | |
3852 | if (command_line_is_silent (cmd)) | |
3853 | { | |
3854 | /* The action has been already done by bpstat_stop_status. */ | |
3855 | cmd = cmd->next; | |
3856 | } | |
6c50ab1c | 3857 | |
c906108c SS |
3858 | while (cmd != NULL) |
3859 | { | |
3860 | execute_control_command (cmd); | |
3861 | ||
3862 | if (breakpoint_proceeded) | |
3863 | break; | |
3864 | else | |
3865 | cmd = cmd->next; | |
3866 | } | |
6c50ab1c JB |
3867 | |
3868 | /* We can free this command tree now. */ | |
3869 | do_cleanups (this_cmd_tree_chain); | |
3870 | ||
c906108c | 3871 | if (breakpoint_proceeded) |
32c1e744 VP |
3872 | { |
3873 | if (target_can_async_p ()) | |
347bddb7 PA |
3874 | /* If we are in async mode, then the target might be still |
3875 | running, not stopped at any breakpoint, so nothing for | |
3876 | us to do here -- just return to the event loop. */ | |
3877 | ; | |
32c1e744 VP |
3878 | else |
3879 | /* In sync mode, when execute_control_command returns | |
3880 | we're already standing on the next breakpoint. | |
347bddb7 PA |
3881 | Breakpoint commands for that stop were not run, since |
3882 | execute_command does not run breakpoint commands -- | |
3883 | only command_line_handler does, but that one is not | |
3884 | involved in execution of breakpoint commands. So, we | |
3885 | can now execute breakpoint commands. It should be | |
3886 | noted that making execute_command do bpstat actions is | |
3887 | not an option -- in this case we'll have recursive | |
3888 | invocation of bpstat for each breakpoint with a | |
3889 | command, and can easily blow up GDB stack. Instead, we | |
3890 | return true, which will trigger the caller to recall us | |
3891 | with the new stop_bpstat. */ | |
3892 | again = 1; | |
3893 | break; | |
32c1e744 | 3894 | } |
c906108c | 3895 | } |
c2b8ed2c | 3896 | do_cleanups (old_chain); |
347bddb7 PA |
3897 | return again; |
3898 | } | |
3899 | ||
3900 | void | |
3901 | bpstat_do_actions (void) | |
3902 | { | |
353d1d73 JK |
3903 | struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup (); |
3904 | ||
347bddb7 PA |
3905 | /* Do any commands attached to breakpoint we are stopped at. */ |
3906 | while (!ptid_equal (inferior_ptid, null_ptid) | |
3907 | && target_has_execution | |
3908 | && !is_exited (inferior_ptid) | |
3909 | && !is_executing (inferior_ptid)) | |
3910 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
3911 | and only return when it is stopped at the next breakpoint, we | |
3912 | keep doing breakpoint actions until it returns false to | |
3913 | indicate the inferior was not resumed. */ | |
16c381f0 | 3914 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
347bddb7 | 3915 | break; |
353d1d73 JK |
3916 | |
3917 | discard_cleanups (cleanup_if_error); | |
c906108c SS |
3918 | } |
3919 | ||
fa4727a6 DJ |
3920 | /* Print out the (old or new) value associated with a watchpoint. */ |
3921 | ||
3922 | static void | |
3923 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
3924 | { | |
3925 | if (val == NULL) | |
3926 | fprintf_unfiltered (stream, _("<unreadable>")); | |
3927 | else | |
79a45b7d TT |
3928 | { |
3929 | struct value_print_options opts; | |
3930 | get_user_print_options (&opts); | |
3931 | value_print (val, stream, &opts); | |
3932 | } | |
fa4727a6 DJ |
3933 | } |
3934 | ||
e514a9d6 | 3935 | /* Generic routine for printing messages indicating why we |
4a64f543 | 3936 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
3937 | 'print_it' in the bpstat structure. Under some circumstances we |
3938 | may decide not to print anything here and delegate the task to | |
4a64f543 | 3939 | normal_stop(). */ |
e514a9d6 JM |
3940 | |
3941 | static enum print_stop_action | |
3942 | print_bp_stop_message (bpstat bs) | |
3943 | { | |
3944 | switch (bs->print_it) | |
3945 | { | |
3946 | case print_it_noop: | |
4a64f543 | 3947 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
3948 | return PRINT_UNKNOWN; |
3949 | break; | |
3950 | ||
3951 | case print_it_done: | |
3952 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 3953 | relevant messages. */ |
e514a9d6 JM |
3954 | return PRINT_SRC_AND_LOC; |
3955 | break; | |
3956 | ||
3957 | case print_it_normal: | |
4f8d1dc6 | 3958 | { |
f431efe5 PA |
3959 | struct breakpoint *b = bs->breakpoint_at; |
3960 | ||
1a6a67de TJB |
3961 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
3962 | which has since been deleted. */ | |
3963 | if (b == NULL) | |
3964 | return PRINT_UNKNOWN; | |
3965 | ||
348d480f PA |
3966 | /* Normal case. Call the breakpoint's print_it method. */ |
3967 | return b->ops->print_it (bs); | |
4f8d1dc6 | 3968 | } |
348d480f | 3969 | break; |
3086aeae | 3970 | |
e514a9d6 | 3971 | default: |
8e65ff28 | 3972 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 3973 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 3974 | break; |
c906108c | 3975 | } |
c906108c SS |
3976 | } |
3977 | ||
edcc5120 TT |
3978 | /* A helper function that prints a shared library stopped event. */ |
3979 | ||
3980 | static void | |
3981 | print_solib_event (int is_catchpoint) | |
3982 | { | |
3983 | int any_deleted | |
3984 | = !VEC_empty (char_ptr, current_program_space->deleted_solibs); | |
3985 | int any_added | |
3986 | = !VEC_empty (so_list_ptr, current_program_space->added_solibs); | |
3987 | ||
3988 | if (!is_catchpoint) | |
3989 | { | |
3990 | if (any_added || any_deleted) | |
3991 | ui_out_text (current_uiout, | |
3992 | _("Stopped due to shared library event:\n")); | |
3993 | else | |
3994 | ui_out_text (current_uiout, | |
3995 | _("Stopped due to shared library event (no " | |
3996 | "libraries added or removed)\n")); | |
3997 | } | |
3998 | ||
3999 | if (ui_out_is_mi_like_p (current_uiout)) | |
4000 | ui_out_field_string (current_uiout, "reason", | |
4001 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); | |
4002 | ||
4003 | if (any_deleted) | |
4004 | { | |
4005 | struct cleanup *cleanup; | |
4006 | char *name; | |
4007 | int ix; | |
4008 | ||
4009 | ui_out_text (current_uiout, _(" Inferior unloaded ")); | |
4010 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
4011 | "removed"); | |
4012 | for (ix = 0; | |
4013 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
4014 | ix, name); | |
4015 | ++ix) | |
4016 | { | |
4017 | if (ix > 0) | |
4018 | ui_out_text (current_uiout, " "); | |
4019 | ui_out_field_string (current_uiout, "library", name); | |
4020 | ui_out_text (current_uiout, "\n"); | |
4021 | } | |
4022 | ||
4023 | do_cleanups (cleanup); | |
4024 | } | |
4025 | ||
4026 | if (any_added) | |
4027 | { | |
4028 | struct so_list *iter; | |
4029 | int ix; | |
4030 | struct cleanup *cleanup; | |
4031 | ||
4032 | ui_out_text (current_uiout, _(" Inferior loaded ")); | |
4033 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
4034 | "added"); | |
4035 | for (ix = 0; | |
4036 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
4037 | ix, iter); | |
4038 | ++ix) | |
4039 | { | |
4040 | if (ix > 0) | |
4041 | ui_out_text (current_uiout, " "); | |
4042 | ui_out_field_string (current_uiout, "library", iter->so_name); | |
4043 | ui_out_text (current_uiout, "\n"); | |
4044 | } | |
4045 | ||
4046 | do_cleanups (cleanup); | |
4047 | } | |
4048 | } | |
4049 | ||
e514a9d6 JM |
4050 | /* Print a message indicating what happened. This is called from |
4051 | normal_stop(). The input to this routine is the head of the bpstat | |
36dfb11c TT |
4052 | list - a list of the eventpoints that caused this stop. KIND is |
4053 | the target_waitkind for the stopping event. This | |
e514a9d6 JM |
4054 | routine calls the generic print routine for printing a message |
4055 | about reasons for stopping. This will print (for example) the | |
4056 | "Breakpoint n," part of the output. The return value of this | |
4057 | routine is one of: | |
c906108c | 4058 | |
4a64f543 | 4059 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 4060 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 4061 | code to print the location. An example is |
c5aa993b JM |
4062 | "Breakpoint 1, " which should be followed by |
4063 | the location. | |
917317f4 | 4064 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
4065 | to also print the location part of the message. |
4066 | An example is the catch/throw messages, which | |
4a64f543 | 4067 | don't require a location appended to the end. |
917317f4 | 4068 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 4069 | further info to be printed. */ |
c906108c | 4070 | |
917317f4 | 4071 | enum print_stop_action |
36dfb11c | 4072 | bpstat_print (bpstat bs, int kind) |
c906108c SS |
4073 | { |
4074 | int val; | |
c5aa993b | 4075 | |
c906108c | 4076 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
4077 | (Currently all watchpoints go on the bpstat whether hit or not. |
4078 | That probably could (should) be changed, provided care is taken | |
c906108c | 4079 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
4080 | for (; bs; bs = bs->next) |
4081 | { | |
4082 | val = print_bp_stop_message (bs); | |
4083 | if (val == PRINT_SRC_ONLY | |
4084 | || val == PRINT_SRC_AND_LOC | |
4085 | || val == PRINT_NOTHING) | |
4086 | return val; | |
4087 | } | |
c906108c | 4088 | |
36dfb11c TT |
4089 | /* If we had hit a shared library event breakpoint, |
4090 | print_bp_stop_message would print out this message. If we hit an | |
4091 | OS-level shared library event, do the same thing. */ | |
4092 | if (kind == TARGET_WAITKIND_LOADED) | |
4093 | { | |
edcc5120 | 4094 | print_solib_event (0); |
36dfb11c TT |
4095 | return PRINT_NOTHING; |
4096 | } | |
4097 | ||
e514a9d6 | 4098 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 4099 | with and nothing was printed. */ |
917317f4 | 4100 | return PRINT_UNKNOWN; |
c906108c SS |
4101 | } |
4102 | ||
4a64f543 MS |
4103 | /* Evaluate the expression EXP and return 1 if value is zero. This is |
4104 | used inside a catch_errors to evaluate the breakpoint condition. | |
4105 | The argument is a "struct expression *" that has been cast to a | |
4106 | "char *" to make it pass through catch_errors. */ | |
c906108c SS |
4107 | |
4108 | static int | |
4efb68b1 | 4109 | breakpoint_cond_eval (void *exp) |
c906108c | 4110 | { |
278cd55f | 4111 | struct value *mark = value_mark (); |
c5aa993b | 4112 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 4113 | |
c906108c SS |
4114 | value_free_to_mark (mark); |
4115 | return i; | |
4116 | } | |
4117 | ||
5760d0ab | 4118 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c SS |
4119 | |
4120 | static bpstat | |
5760d0ab | 4121 | bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) |
c906108c SS |
4122 | { |
4123 | bpstat bs; | |
4124 | ||
4125 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
5760d0ab JK |
4126 | bs->next = NULL; |
4127 | **bs_link_pointer = bs; | |
4128 | *bs_link_pointer = &bs->next; | |
f431efe5 PA |
4129 | bs->breakpoint_at = bl->owner; |
4130 | bs->bp_location_at = bl; | |
4131 | incref_bp_location (bl); | |
c906108c SS |
4132 | /* If the condition is false, etc., don't do the commands. */ |
4133 | bs->commands = NULL; | |
4134 | bs->old_val = NULL; | |
4135 | bs->print_it = print_it_normal; | |
4136 | return bs; | |
4137 | } | |
4138 | \f | |
d983da9c DJ |
4139 | /* The target has stopped with waitstatus WS. Check if any hardware |
4140 | watchpoints have triggered, according to the target. */ | |
4141 | ||
4142 | int | |
4143 | watchpoints_triggered (struct target_waitstatus *ws) | |
4144 | { | |
d92524f1 | 4145 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
4146 | CORE_ADDR addr; |
4147 | struct breakpoint *b; | |
4148 | ||
4149 | if (!stopped_by_watchpoint) | |
4150 | { | |
4151 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
4152 | as not triggered. */ | |
4153 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4154 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4155 | { |
4156 | struct watchpoint *w = (struct watchpoint *) b; | |
4157 | ||
4158 | w->watchpoint_triggered = watch_triggered_no; | |
4159 | } | |
d983da9c DJ |
4160 | |
4161 | return 0; | |
4162 | } | |
4163 | ||
4164 | if (!target_stopped_data_address (¤t_target, &addr)) | |
4165 | { | |
4166 | /* We were stopped by a watchpoint, but we don't know where. | |
4167 | Mark all watchpoints as unknown. */ | |
4168 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4169 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4170 | { |
4171 | struct watchpoint *w = (struct watchpoint *) b; | |
4172 | ||
4173 | w->watchpoint_triggered = watch_triggered_unknown; | |
4174 | } | |
d983da9c DJ |
4175 | |
4176 | return stopped_by_watchpoint; | |
4177 | } | |
4178 | ||
4179 | /* The target could report the data address. Mark watchpoints | |
4180 | affected by this data address as triggered, and all others as not | |
4181 | triggered. */ | |
4182 | ||
4183 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4184 | if (is_hardware_watchpoint (b)) |
d983da9c | 4185 | { |
3a5c3e22 | 4186 | struct watchpoint *w = (struct watchpoint *) b; |
a5606eee | 4187 | struct bp_location *loc; |
d983da9c | 4188 | |
3a5c3e22 | 4189 | w->watchpoint_triggered = watch_triggered_no; |
a5606eee | 4190 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 | 4191 | { |
3a5c3e22 | 4192 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 4193 | { |
3a5c3e22 PA |
4194 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
4195 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
4196 | |
4197 | if (newaddr == start) | |
4198 | { | |
3a5c3e22 | 4199 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4200 | break; |
4201 | } | |
4202 | } | |
4203 | /* Exact match not required. Within range is sufficient. */ | |
4204 | else if (target_watchpoint_addr_within_range (¤t_target, | |
4205 | addr, loc->address, | |
4206 | loc->length)) | |
4207 | { | |
3a5c3e22 | 4208 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4209 | break; |
4210 | } | |
4211 | } | |
d983da9c DJ |
4212 | } |
4213 | ||
4214 | return 1; | |
4215 | } | |
4216 | ||
c906108c SS |
4217 | /* Possible return values for watchpoint_check (this can't be an enum |
4218 | because of check_errors). */ | |
4219 | /* The watchpoint has been deleted. */ | |
4220 | #define WP_DELETED 1 | |
4221 | /* The value has changed. */ | |
4222 | #define WP_VALUE_CHANGED 2 | |
4223 | /* The value has not changed. */ | |
4224 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
4225 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
4226 | #define WP_IGNORE 4 | |
c906108c SS |
4227 | |
4228 | #define BP_TEMPFLAG 1 | |
4229 | #define BP_HARDWAREFLAG 2 | |
4230 | ||
4a64f543 MS |
4231 | /* Evaluate watchpoint condition expression and check if its value |
4232 | changed. | |
553e4c11 JB |
4233 | |
4234 | P should be a pointer to struct bpstat, but is defined as a void * | |
4235 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
4236 | |
4237 | static int | |
4efb68b1 | 4238 | watchpoint_check (void *p) |
c906108c SS |
4239 | { |
4240 | bpstat bs = (bpstat) p; | |
3a5c3e22 | 4241 | struct watchpoint *b; |
c906108c SS |
4242 | struct frame_info *fr; |
4243 | int within_current_scope; | |
4244 | ||
f431efe5 | 4245 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 4246 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 4247 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 4248 | |
f6bc2008 PA |
4249 | /* If this is a local watchpoint, we only want to check if the |
4250 | watchpoint frame is in scope if the current thread is the thread | |
4251 | that was used to create the watchpoint. */ | |
4252 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 4253 | return WP_IGNORE; |
f6bc2008 | 4254 | |
c906108c SS |
4255 | if (b->exp_valid_block == NULL) |
4256 | within_current_scope = 1; | |
4257 | else | |
4258 | { | |
edb3359d DJ |
4259 | struct frame_info *frame = get_current_frame (); |
4260 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
4261 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
4262 | ||
4a64f543 MS |
4263 | /* in_function_epilogue_p() returns a non-zero value if we're |
4264 | still in the function but the stack frame has already been | |
4265 | invalidated. Since we can't rely on the values of local | |
4266 | variables after the stack has been destroyed, we are treating | |
4267 | the watchpoint in that state as `not changed' without further | |
4268 | checking. Don't mark watchpoints as changed if the current | |
4269 | frame is in an epilogue - even if they are in some other | |
4270 | frame, our view of the stack is likely to be wrong and | |
4271 | frame_find_by_id could error out. */ | |
a0f49112 | 4272 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) |
60e1c644 | 4273 | return WP_IGNORE; |
a0f49112 | 4274 | |
101dcfbe | 4275 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 4276 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
4277 | |
4278 | /* If we've gotten confused in the unwinder, we might have | |
4279 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
4280 | if (within_current_scope) |
4281 | { | |
4282 | struct symbol *function; | |
4283 | ||
4284 | function = get_frame_function (fr); | |
4285 | if (function == NULL | |
4286 | || !contained_in (b->exp_valid_block, | |
4287 | SYMBOL_BLOCK_VALUE (function))) | |
4288 | within_current_scope = 0; | |
4289 | } | |
69fbadd5 | 4290 | |
edb3359d | 4291 | if (within_current_scope) |
c906108c SS |
4292 | /* If we end up stopping, the current frame will get selected |
4293 | in normal_stop. So this call to select_frame won't affect | |
4294 | the user. */ | |
0f7d239c | 4295 | select_frame (fr); |
c906108c | 4296 | } |
c5aa993b | 4297 | |
c906108c SS |
4298 | if (within_current_scope) |
4299 | { | |
4a64f543 MS |
4300 | /* We use value_{,free_to_}mark because it could be a *long* |
4301 | time before we return to the command level and call | |
4302 | free_all_values. We can't call free_all_values because we | |
4303 | might be in the middle of evaluating a function call. */ | |
c906108c | 4304 | |
0cf6dd15 | 4305 | int pc = 0; |
9c06b0b4 | 4306 | struct value *mark; |
fa4727a6 DJ |
4307 | struct value *new_val; |
4308 | ||
3a5c3e22 | 4309 | if (is_masked_watchpoint (&b->base)) |
9c06b0b4 TJB |
4310 | /* Since we don't know the exact trigger address (from |
4311 | stopped_data_address), just tell the user we've triggered | |
4312 | a mask watchpoint. */ | |
4313 | return WP_VALUE_CHANGED; | |
4314 | ||
4315 | mark = value_mark (); | |
0cf6dd15 | 4316 | fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL); |
218d2fc6 | 4317 | |
4a64f543 MS |
4318 | /* We use value_equal_contents instead of value_equal because |
4319 | the latter coerces an array to a pointer, thus comparing just | |
4320 | the address of the array instead of its contents. This is | |
4321 | not what we want. */ | |
fa4727a6 | 4322 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 4323 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 4324 | { |
fa4727a6 DJ |
4325 | if (new_val != NULL) |
4326 | { | |
4327 | release_value (new_val); | |
4328 | value_free_to_mark (mark); | |
4329 | } | |
c906108c SS |
4330 | bs->old_val = b->val; |
4331 | b->val = new_val; | |
fa4727a6 | 4332 | b->val_valid = 1; |
c906108c SS |
4333 | return WP_VALUE_CHANGED; |
4334 | } | |
4335 | else | |
4336 | { | |
60e1c644 | 4337 | /* Nothing changed. */ |
c906108c | 4338 | value_free_to_mark (mark); |
c906108c SS |
4339 | return WP_VALUE_NOT_CHANGED; |
4340 | } | |
4341 | } | |
4342 | else | |
4343 | { | |
79a45e25 PA |
4344 | struct ui_out *uiout = current_uiout; |
4345 | ||
c906108c | 4346 | /* This seems like the only logical thing to do because |
c5aa993b JM |
4347 | if we temporarily ignored the watchpoint, then when |
4348 | we reenter the block in which it is valid it contains | |
4349 | garbage (in the case of a function, it may have two | |
4350 | garbage values, one before and one after the prologue). | |
4351 | So we can't even detect the first assignment to it and | |
4352 | watch after that (since the garbage may or may not equal | |
4353 | the first value assigned). */ | |
348d480f PA |
4354 | /* We print all the stop information in |
4355 | breakpoint_ops->print_it, but in this case, by the time we | |
4356 | call breakpoint_ops->print_it this bp will be deleted | |
4357 | already. So we have no choice but print the information | |
4358 | here. */ | |
9dc5e2a9 | 4359 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
4360 | ui_out_field_string |
4361 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 4362 | ui_out_text (uiout, "\nWatchpoint "); |
3a5c3e22 | 4363 | ui_out_field_int (uiout, "wpnum", b->base.number); |
3e43a32a MS |
4364 | ui_out_text (uiout, |
4365 | " deleted because the program has left the block in\n\ | |
8b93c638 | 4366 | which its expression is valid.\n"); |
4ce44c66 | 4367 | |
cdac0397 | 4368 | /* Make sure the watchpoint's commands aren't executed. */ |
3a5c3e22 | 4369 | decref_counted_command_line (&b->base.commands); |
d0fb5eae | 4370 | watchpoint_del_at_next_stop (b); |
c906108c SS |
4371 | |
4372 | return WP_DELETED; | |
4373 | } | |
4374 | } | |
4375 | ||
18a18393 | 4376 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
4377 | breakpoint location BL. This function does not check if we should |
4378 | stop, only if BL explains the stop. */ | |
4379 | ||
18a18393 | 4380 | static int |
6c95b8df | 4381 | bpstat_check_location (const struct bp_location *bl, |
09ac7c10 TT |
4382 | struct address_space *aspace, CORE_ADDR bp_addr, |
4383 | const struct target_waitstatus *ws) | |
18a18393 VP |
4384 | { |
4385 | struct breakpoint *b = bl->owner; | |
4386 | ||
348d480f | 4387 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
4388 | gdb_assert (b != NULL); |
4389 | ||
09ac7c10 | 4390 | return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws); |
18a18393 VP |
4391 | } |
4392 | ||
3a5c3e22 PA |
4393 | /* Determine if the watched values have actually changed, and we |
4394 | should stop. If not, set BS->stop to 0. */ | |
4395 | ||
18a18393 VP |
4396 | static void |
4397 | bpstat_check_watchpoint (bpstat bs) | |
4398 | { | |
2bdf28a0 | 4399 | const struct bp_location *bl; |
3a5c3e22 | 4400 | struct watchpoint *b; |
2bdf28a0 JK |
4401 | |
4402 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 4403 | bl = bs->bp_location_at; |
2bdf28a0 | 4404 | gdb_assert (bl != NULL); |
3a5c3e22 | 4405 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 4406 | gdb_assert (b != NULL); |
18a18393 | 4407 | |
18a18393 | 4408 | { |
18a18393 VP |
4409 | int must_check_value = 0; |
4410 | ||
3a5c3e22 | 4411 | if (b->base.type == bp_watchpoint) |
18a18393 VP |
4412 | /* For a software watchpoint, we must always check the |
4413 | watched value. */ | |
4414 | must_check_value = 1; | |
4415 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
4416 | /* We have a hardware watchpoint (read, write, or access) | |
4417 | and the target earlier reported an address watched by | |
4418 | this watchpoint. */ | |
4419 | must_check_value = 1; | |
4420 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3a5c3e22 | 4421 | && b->base.type == bp_hardware_watchpoint) |
18a18393 VP |
4422 | /* We were stopped by a hardware watchpoint, but the target could |
4423 | not report the data address. We must check the watchpoint's | |
4424 | value. Access and read watchpoints are out of luck; without | |
4425 | a data address, we can't figure it out. */ | |
4426 | must_check_value = 1; | |
3a5c3e22 | 4427 | |
18a18393 VP |
4428 | if (must_check_value) |
4429 | { | |
3e43a32a MS |
4430 | char *message |
4431 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3a5c3e22 | 4432 | b->base.number); |
18a18393 VP |
4433 | struct cleanup *cleanups = make_cleanup (xfree, message); |
4434 | int e = catch_errors (watchpoint_check, bs, message, | |
4435 | RETURN_MASK_ALL); | |
4436 | do_cleanups (cleanups); | |
4437 | switch (e) | |
4438 | { | |
4439 | case WP_DELETED: | |
4440 | /* We've already printed what needs to be printed. */ | |
4441 | bs->print_it = print_it_done; | |
4442 | /* Stop. */ | |
4443 | break; | |
60e1c644 PA |
4444 | case WP_IGNORE: |
4445 | bs->print_it = print_it_noop; | |
4446 | bs->stop = 0; | |
4447 | break; | |
18a18393 | 4448 | case WP_VALUE_CHANGED: |
3a5c3e22 | 4449 | if (b->base.type == bp_read_watchpoint) |
18a18393 | 4450 | { |
85d721b8 PA |
4451 | /* There are two cases to consider here: |
4452 | ||
4a64f543 | 4453 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
4454 | In that case, trust the target, and always report |
4455 | the watchpoint hit to the user. Even though | |
4456 | reads don't cause value changes, the value may | |
4457 | have changed since the last time it was read, and | |
4458 | since we're not trapping writes, we will not see | |
4459 | those, and as such we should ignore our notion of | |
4460 | old value. | |
4461 | ||
4a64f543 | 4462 | 2. We're watching the triggered memory for both |
85d721b8 PA |
4463 | reads and writes. There are two ways this may |
4464 | happen: | |
4465 | ||
4a64f543 | 4466 | 2.1. This is a target that can't break on data |
85d721b8 PA |
4467 | reads only, but can break on accesses (reads or |
4468 | writes), such as e.g., x86. We detect this case | |
4469 | at the time we try to insert read watchpoints. | |
4470 | ||
4a64f543 | 4471 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
4472 | watchpoints, but, the user set an access or write |
4473 | watchpoint watching the same memory as this read | |
4474 | watchpoint. | |
4475 | ||
4476 | If we're watching memory writes as well as reads, | |
4477 | ignore watchpoint hits when we find that the | |
4478 | value hasn't changed, as reads don't cause | |
4479 | changes. This still gives false positives when | |
4480 | the program writes the same value to memory as | |
4481 | what there was already in memory (we will confuse | |
4482 | it for a read), but it's much better than | |
4483 | nothing. */ | |
4484 | ||
4485 | int other_write_watchpoint = 0; | |
4486 | ||
4487 | if (bl->watchpoint_type == hw_read) | |
4488 | { | |
4489 | struct breakpoint *other_b; | |
4490 | ||
4491 | ALL_BREAKPOINTS (other_b) | |
3a5c3e22 PA |
4492 | if (other_b->type == bp_hardware_watchpoint |
4493 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 4494 | { |
3a5c3e22 PA |
4495 | struct watchpoint *other_w = |
4496 | (struct watchpoint *) other_b; | |
4497 | ||
4498 | if (other_w->watchpoint_triggered | |
4499 | == watch_triggered_yes) | |
4500 | { | |
4501 | other_write_watchpoint = 1; | |
4502 | break; | |
4503 | } | |
85d721b8 PA |
4504 | } |
4505 | } | |
4506 | ||
4507 | if (other_write_watchpoint | |
4508 | || bl->watchpoint_type == hw_access) | |
4509 | { | |
4510 | /* We're watching the same memory for writes, | |
4511 | and the value changed since the last time we | |
4512 | updated it, so this trap must be for a write. | |
4513 | Ignore it. */ | |
4514 | bs->print_it = print_it_noop; | |
4515 | bs->stop = 0; | |
4516 | } | |
18a18393 VP |
4517 | } |
4518 | break; | |
4519 | case WP_VALUE_NOT_CHANGED: | |
3a5c3e22 PA |
4520 | if (b->base.type == bp_hardware_watchpoint |
4521 | || b->base.type == bp_watchpoint) | |
18a18393 VP |
4522 | { |
4523 | /* Don't stop: write watchpoints shouldn't fire if | |
4524 | the value hasn't changed. */ | |
4525 | bs->print_it = print_it_noop; | |
4526 | bs->stop = 0; | |
4527 | } | |
4528 | /* Stop. */ | |
4529 | break; | |
4530 | default: | |
4531 | /* Can't happen. */ | |
4532 | case 0: | |
4533 | /* Error from catch_errors. */ | |
3a5c3e22 | 4534 | printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number); |
d0fb5eae | 4535 | watchpoint_del_at_next_stop (b); |
18a18393 VP |
4536 | /* We've already printed what needs to be printed. */ |
4537 | bs->print_it = print_it_done; | |
4538 | break; | |
4539 | } | |
4540 | } | |
4541 | else /* must_check_value == 0 */ | |
4542 | { | |
4543 | /* This is a case where some watchpoint(s) triggered, but | |
4544 | not at the address of this watchpoint, or else no | |
4545 | watchpoint triggered after all. So don't print | |
4546 | anything for this watchpoint. */ | |
4547 | bs->print_it = print_it_noop; | |
4548 | bs->stop = 0; | |
4549 | } | |
4550 | } | |
4551 | } | |
4552 | ||
4553 | ||
4554 | /* Check conditions (condition proper, frame, thread and ignore count) | |
4555 | of breakpoint referred to by BS. If we should not stop for this | |
4556 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 4557 | |
18a18393 VP |
4558 | static void |
4559 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
4560 | { | |
4561 | int thread_id = pid_to_thread_id (ptid); | |
2bdf28a0 JK |
4562 | const struct bp_location *bl; |
4563 | struct breakpoint *b; | |
4564 | ||
4565 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 4566 | bl = bs->bp_location_at; |
2bdf28a0 | 4567 | gdb_assert (bl != NULL); |
f431efe5 | 4568 | b = bs->breakpoint_at; |
2bdf28a0 | 4569 | gdb_assert (b != NULL); |
18a18393 | 4570 | |
b775012e LM |
4571 | /* Even if the target evaluated the condition on its end and notified GDB, we |
4572 | need to do so again since GDB does not know if we stopped due to a | |
4573 | breakpoint or a single step breakpoint. */ | |
4574 | ||
18a18393 | 4575 | if (frame_id_p (b->frame_id) |
edb3359d | 4576 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 VP |
4577 | bs->stop = 0; |
4578 | else if (bs->stop) | |
4579 | { | |
4580 | int value_is_zero = 0; | |
60e1c644 PA |
4581 | struct expression *cond; |
4582 | ||
7371cf6d PM |
4583 | /* Evaluate Python breakpoints that have a "stop" |
4584 | method implemented. */ | |
4585 | if (b->py_bp_object) | |
4586 | bs->stop = gdbpy_should_stop (b->py_bp_object); | |
4587 | ||
60e1c644 | 4588 | if (is_watchpoint (b)) |
3a5c3e22 PA |
4589 | { |
4590 | struct watchpoint *w = (struct watchpoint *) b; | |
4591 | ||
4592 | cond = w->cond_exp; | |
4593 | } | |
60e1c644 PA |
4594 | else |
4595 | cond = bl->cond; | |
4596 | ||
f431efe5 | 4597 | if (cond && b->disposition != disp_del_at_next_stop) |
18a18393 | 4598 | { |
60e1c644 | 4599 | int within_current_scope = 1; |
3a5c3e22 | 4600 | struct watchpoint * w; |
60e1c644 | 4601 | |
c5bc3a77 DJ |
4602 | /* We use value_mark and value_free_to_mark because it could |
4603 | be a long time before we return to the command level and | |
4604 | call free_all_values. We can't call free_all_values | |
4605 | because we might be in the middle of evaluating a | |
4606 | function call. */ | |
4607 | struct value *mark = value_mark (); | |
4608 | ||
3a5c3e22 PA |
4609 | if (is_watchpoint (b)) |
4610 | w = (struct watchpoint *) b; | |
4611 | else | |
4612 | w = NULL; | |
4613 | ||
edb3359d DJ |
4614 | /* Need to select the frame, with all that implies so that |
4615 | the conditions will have the right context. Because we | |
4616 | use the frame, we will not see an inlined function's | |
4617 | variables when we arrive at a breakpoint at the start | |
4618 | of the inlined function; the current frame will be the | |
4619 | call site. */ | |
3a5c3e22 | 4620 | if (w == NULL || w->cond_exp_valid_block == NULL) |
60e1c644 PA |
4621 | select_frame (get_current_frame ()); |
4622 | else | |
4623 | { | |
4624 | struct frame_info *frame; | |
4625 | ||
4626 | /* For local watchpoint expressions, which particular | |
4627 | instance of a local is being watched matters, so we | |
4628 | keep track of the frame to evaluate the expression | |
4629 | in. To evaluate the condition however, it doesn't | |
4630 | really matter which instantiation of the function | |
4631 | where the condition makes sense triggers the | |
4632 | watchpoint. This allows an expression like "watch | |
4633 | global if q > 10" set in `func', catch writes to | |
4634 | global on all threads that call `func', or catch | |
4635 | writes on all recursive calls of `func' by a single | |
4636 | thread. We simply always evaluate the condition in | |
4637 | the innermost frame that's executing where it makes | |
4638 | sense to evaluate the condition. It seems | |
4639 | intuitive. */ | |
3a5c3e22 | 4640 | frame = block_innermost_frame (w->cond_exp_valid_block); |
60e1c644 PA |
4641 | if (frame != NULL) |
4642 | select_frame (frame); | |
4643 | else | |
4644 | within_current_scope = 0; | |
4645 | } | |
4646 | if (within_current_scope) | |
4647 | value_is_zero | |
4648 | = catch_errors (breakpoint_cond_eval, cond, | |
4649 | "Error in testing breakpoint condition:\n", | |
4650 | RETURN_MASK_ALL); | |
4651 | else | |
4652 | { | |
4653 | warning (_("Watchpoint condition cannot be tested " | |
4654 | "in the current scope")); | |
4655 | /* If we failed to set the right context for this | |
4656 | watchpoint, unconditionally report it. */ | |
4657 | value_is_zero = 0; | |
4658 | } | |
4a64f543 | 4659 | /* FIXME-someday, should give breakpoint #. */ |
c5bc3a77 | 4660 | value_free_to_mark (mark); |
18a18393 | 4661 | } |
60e1c644 PA |
4662 | |
4663 | if (cond && value_is_zero) | |
18a18393 VP |
4664 | { |
4665 | bs->stop = 0; | |
4666 | } | |
4667 | else if (b->thread != -1 && b->thread != thread_id) | |
4668 | { | |
4669 | bs->stop = 0; | |
4670 | } | |
4671 | else if (b->ignore_count > 0) | |
4672 | { | |
4673 | b->ignore_count--; | |
4674 | annotate_ignore_count_change (); | |
4675 | bs->stop = 0; | |
4a64f543 | 4676 | /* Increase the hit count even though we don't stop. */ |
18a18393 | 4677 | ++(b->hit_count); |
8d3788bd | 4678 | observer_notify_breakpoint_modified (b); |
18a18393 VP |
4679 | } |
4680 | } | |
4681 | } | |
4682 | ||
4683 | ||
9709f61c | 4684 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 4685 | BP_ADDR in thread PTID. |
c906108c | 4686 | |
d983da9c | 4687 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
4688 | don't understand this stop. Result is a chain of bpstat's such |
4689 | that: | |
c906108c | 4690 | |
c5aa993b | 4691 | if we don't understand the stop, the result is a null pointer. |
c906108c | 4692 | |
c5aa993b | 4693 | if we understand why we stopped, the result is not null. |
c906108c | 4694 | |
c5aa993b JM |
4695 | Each element of the chain refers to a particular breakpoint or |
4696 | watchpoint at which we have stopped. (We may have stopped for | |
4697 | several reasons concurrently.) | |
c906108c | 4698 | |
c5aa993b JM |
4699 | Each element of the chain has valid next, breakpoint_at, |
4700 | commands, FIXME??? fields. */ | |
c906108c SS |
4701 | |
4702 | bpstat | |
6c95b8df | 4703 | bpstat_stop_status (struct address_space *aspace, |
09ac7c10 TT |
4704 | CORE_ADDR bp_addr, ptid_t ptid, |
4705 | const struct target_waitstatus *ws) | |
c906108c | 4706 | { |
0d381245 | 4707 | struct breakpoint *b = NULL; |
afe38095 | 4708 | struct bp_location *bl; |
20874c92 | 4709 | struct bp_location *loc; |
5760d0ab JK |
4710 | /* First item of allocated bpstat's. */ |
4711 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 4712 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 4713 | bpstat bs; |
20874c92 | 4714 | int ix; |
429374b8 | 4715 | int need_remove_insert; |
f431efe5 | 4716 | int removed_any; |
c906108c | 4717 | |
f431efe5 PA |
4718 | /* First, build the bpstat chain with locations that explain a |
4719 | target stop, while being careful to not set the target running, | |
4720 | as that may invalidate locations (in particular watchpoint | |
4721 | locations are recreated). Resuming will happen here with | |
4722 | breakpoint conditions or watchpoint expressions that include | |
4723 | inferior function calls. */ | |
c5aa993b | 4724 | |
429374b8 JK |
4725 | ALL_BREAKPOINTS (b) |
4726 | { | |
4727 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) | |
4728 | continue; | |
a5606eee | 4729 | |
429374b8 JK |
4730 | for (bl = b->loc; bl != NULL; bl = bl->next) |
4731 | { | |
4a64f543 MS |
4732 | /* For hardware watchpoints, we look only at the first |
4733 | location. The watchpoint_check function will work on the | |
4734 | entire expression, not the individual locations. For | |
4735 | read watchpoints, the watchpoints_triggered function has | |
4736 | checked all locations already. */ | |
429374b8 JK |
4737 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
4738 | break; | |
18a18393 | 4739 | |
429374b8 JK |
4740 | if (bl->shlib_disabled) |
4741 | continue; | |
c5aa993b | 4742 | |
09ac7c10 | 4743 | if (!bpstat_check_location (bl, aspace, bp_addr, ws)) |
429374b8 | 4744 | continue; |
c5aa993b | 4745 | |
4a64f543 MS |
4746 | /* Come here if it's a watchpoint, or if the break address |
4747 | matches. */ | |
c5aa993b | 4748 | |
4a64f543 MS |
4749 | bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to |
4750 | explain stop. */ | |
c5aa993b | 4751 | |
f431efe5 PA |
4752 | /* Assume we stop. Should we find a watchpoint that is not |
4753 | actually triggered, or if the condition of the breakpoint | |
4754 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
4755 | bs->stop = 1; |
4756 | bs->print = 1; | |
d983da9c | 4757 | |
f431efe5 PA |
4758 | /* If this is a scope breakpoint, mark the associated |
4759 | watchpoint as triggered so that we will handle the | |
4760 | out-of-scope event. We'll get to the watchpoint next | |
4761 | iteration. */ | |
d0fb5eae | 4762 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
4763 | { |
4764 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
4765 | ||
4766 | w->watchpoint_triggered = watch_triggered_yes; | |
4767 | } | |
f431efe5 PA |
4768 | } |
4769 | } | |
4770 | ||
4771 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
4772 | { | |
f1310107 | 4773 | if (breakpoint_location_address_match (loc, aspace, bp_addr)) |
f431efe5 | 4774 | { |
5760d0ab | 4775 | bs = bpstat_alloc (loc, &bs_link); |
f431efe5 PA |
4776 | /* For hits of moribund locations, we should just proceed. */ |
4777 | bs->stop = 0; | |
4778 | bs->print = 0; | |
4779 | bs->print_it = print_it_noop; | |
4780 | } | |
4781 | } | |
4782 | ||
edcc5120 TT |
4783 | /* A bit of special processing for shlib breakpoints. We need to |
4784 | process solib loading here, so that the lists of loaded and | |
4785 | unloaded libraries are correct before we handle "catch load" and | |
4786 | "catch unload". */ | |
4787 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
4788 | { | |
5d268276 | 4789 | if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event) |
edcc5120 TT |
4790 | { |
4791 | handle_solib_event (); | |
4792 | break; | |
4793 | } | |
4794 | } | |
4795 | ||
f431efe5 PA |
4796 | /* Now go through the locations that caused the target to stop, and |
4797 | check whether we're interested in reporting this stop to higher | |
4798 | layers, or whether we should resume the target transparently. */ | |
4799 | ||
4800 | removed_any = 0; | |
4801 | ||
5760d0ab | 4802 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
4803 | { |
4804 | if (!bs->stop) | |
4805 | continue; | |
4806 | ||
f431efe5 | 4807 | b = bs->breakpoint_at; |
348d480f PA |
4808 | b->ops->check_status (bs); |
4809 | if (bs->stop) | |
28010a5d | 4810 | { |
348d480f | 4811 | bpstat_check_breakpoint_conditions (bs, ptid); |
f431efe5 | 4812 | |
429374b8 JK |
4813 | if (bs->stop) |
4814 | { | |
4815 | ++(b->hit_count); | |
8d3788bd | 4816 | observer_notify_breakpoint_modified (b); |
c906108c | 4817 | |
4a64f543 | 4818 | /* We will stop here. */ |
429374b8 JK |
4819 | if (b->disposition == disp_disable) |
4820 | { | |
816338b5 SS |
4821 | --(b->enable_count); |
4822 | if (b->enable_count <= 0 | |
4823 | && b->enable_state != bp_permanent) | |
429374b8 | 4824 | b->enable_state = bp_disabled; |
f431efe5 | 4825 | removed_any = 1; |
429374b8 JK |
4826 | } |
4827 | if (b->silent) | |
4828 | bs->print = 0; | |
4829 | bs->commands = b->commands; | |
9add0f1b | 4830 | incref_counted_command_line (bs->commands); |
abf85f46 JK |
4831 | if (command_line_is_silent (bs->commands |
4832 | ? bs->commands->commands : NULL)) | |
4833 | bs->print = 0; | |
429374b8 JK |
4834 | } |
4835 | ||
348d480f | 4836 | } |
a9b3a50f PA |
4837 | |
4838 | /* Print nothing for this entry if we don't stop or don't | |
4839 | print. */ | |
4840 | if (!bs->stop || !bs->print) | |
4841 | bs->print_it = print_it_noop; | |
429374b8 | 4842 | } |
876fa593 | 4843 | |
d983da9c DJ |
4844 | /* If we aren't stopping, the value of some hardware watchpoint may |
4845 | not have changed, but the intermediate memory locations we are | |
4846 | watching may have. Don't bother if we're stopping; this will get | |
4847 | done later. */ | |
d832cb68 | 4848 | need_remove_insert = 0; |
5760d0ab JK |
4849 | if (! bpstat_causes_stop (bs_head)) |
4850 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 4851 | if (!bs->stop |
f431efe5 PA |
4852 | && bs->breakpoint_at |
4853 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 4854 | { |
3a5c3e22 PA |
4855 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
4856 | ||
4857 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 4858 | need_remove_insert = 1; |
d983da9c DJ |
4859 | } |
4860 | ||
d832cb68 | 4861 | if (need_remove_insert) |
2d134ed3 | 4862 | update_global_location_list (1); |
f431efe5 PA |
4863 | else if (removed_any) |
4864 | update_global_location_list (0); | |
d832cb68 | 4865 | |
5760d0ab | 4866 | return bs_head; |
c906108c | 4867 | } |
628fe4e4 JK |
4868 | |
4869 | static void | |
4870 | handle_jit_event (void) | |
4871 | { | |
4872 | struct frame_info *frame; | |
4873 | struct gdbarch *gdbarch; | |
4874 | ||
4875 | /* Switch terminal for any messages produced by | |
4876 | breakpoint_re_set. */ | |
4877 | target_terminal_ours_for_output (); | |
4878 | ||
4879 | frame = get_current_frame (); | |
4880 | gdbarch = get_frame_arch (frame); | |
4881 | ||
4882 | jit_event_handler (gdbarch); | |
4883 | ||
4884 | target_terminal_inferior (); | |
4885 | } | |
4886 | ||
edcc5120 TT |
4887 | /* Handle an solib event by calling solib_add. */ |
4888 | ||
4889 | void | |
4890 | handle_solib_event (void) | |
4891 | { | |
4892 | clear_program_space_solib_cache (current_inferior ()->pspace); | |
4893 | ||
4894 | /* Check for any newly added shared libraries if we're supposed to | |
4895 | be adding them automatically. Switch terminal for any messages | |
4896 | produced by breakpoint_re_set. */ | |
4897 | target_terminal_ours_for_output (); | |
4898 | #ifdef SOLIB_ADD | |
4899 | SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add); | |
4900 | #else | |
4901 | solib_add (NULL, 0, ¤t_target, auto_solib_add); | |
4902 | #endif | |
4903 | target_terminal_inferior (); | |
4904 | } | |
4905 | ||
628fe4e4 JK |
4906 | /* Prepare WHAT final decision for infrun. */ |
4907 | ||
4908 | /* Decide what infrun needs to do with this bpstat. */ | |
4909 | ||
c906108c | 4910 | struct bpstat_what |
0e30163f | 4911 | bpstat_what (bpstat bs_head) |
c906108c | 4912 | { |
c906108c | 4913 | struct bpstat_what retval; |
628fe4e4 | 4914 | int jit_event = 0; |
0e30163f | 4915 | bpstat bs; |
c906108c | 4916 | |
628fe4e4 | 4917 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 4918 | retval.call_dummy = STOP_NONE; |
186c406b | 4919 | retval.is_longjmp = 0; |
628fe4e4 | 4920 | |
0e30163f | 4921 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 4922 | { |
628fe4e4 JK |
4923 | /* Extract this BS's action. After processing each BS, we check |
4924 | if its action overrides all we've seem so far. */ | |
4925 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
4926 | enum bptype bptype; | |
4927 | ||
c906108c | 4928 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
4929 | { |
4930 | /* I suspect this can happen if it was a momentary | |
4931 | breakpoint which has since been deleted. */ | |
4932 | bptype = bp_none; | |
4933 | } | |
20874c92 | 4934 | else |
f431efe5 | 4935 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
4936 | |
4937 | switch (bptype) | |
c906108c SS |
4938 | { |
4939 | case bp_none: | |
628fe4e4 | 4940 | break; |
c906108c SS |
4941 | case bp_breakpoint: |
4942 | case bp_hardware_breakpoint: | |
4943 | case bp_until: | |
4944 | case bp_finish: | |
a9b3a50f | 4945 | case bp_shlib_event: |
c906108c SS |
4946 | if (bs->stop) |
4947 | { | |
4948 | if (bs->print) | |
628fe4e4 | 4949 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 4950 | else |
628fe4e4 | 4951 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
4952 | } |
4953 | else | |
628fe4e4 | 4954 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
4955 | break; |
4956 | case bp_watchpoint: | |
4957 | case bp_hardware_watchpoint: | |
4958 | case bp_read_watchpoint: | |
4959 | case bp_access_watchpoint: | |
4960 | if (bs->stop) | |
4961 | { | |
4962 | if (bs->print) | |
628fe4e4 | 4963 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 4964 | else |
628fe4e4 | 4965 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
4966 | } |
4967 | else | |
628fe4e4 JK |
4968 | { |
4969 | /* There was a watchpoint, but we're not stopping. | |
4970 | This requires no further action. */ | |
4971 | } | |
c906108c SS |
4972 | break; |
4973 | case bp_longjmp: | |
186c406b | 4974 | case bp_exception: |
628fe4e4 | 4975 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; |
186c406b | 4976 | retval.is_longjmp = bptype == bp_longjmp; |
c906108c SS |
4977 | break; |
4978 | case bp_longjmp_resume: | |
186c406b | 4979 | case bp_exception_resume: |
628fe4e4 | 4980 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; |
186c406b | 4981 | retval.is_longjmp = bptype == bp_longjmp_resume; |
c906108c SS |
4982 | break; |
4983 | case bp_step_resume: | |
4984 | if (bs->stop) | |
628fe4e4 JK |
4985 | this_action = BPSTAT_WHAT_STEP_RESUME; |
4986 | else | |
c906108c | 4987 | { |
628fe4e4 JK |
4988 | /* It is for the wrong frame. */ |
4989 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 4990 | } |
c906108c | 4991 | break; |
2c03e5be PA |
4992 | case bp_hp_step_resume: |
4993 | if (bs->stop) | |
4994 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
4995 | else | |
4996 | { | |
4997 | /* It is for the wrong frame. */ | |
4998 | this_action = BPSTAT_WHAT_SINGLE; | |
4999 | } | |
5000 | break; | |
c906108c | 5001 | case bp_watchpoint_scope: |
c4093a6a | 5002 | case bp_thread_event: |
1900040c | 5003 | case bp_overlay_event: |
0fd8e87f | 5004 | case bp_longjmp_master: |
aa7d318d | 5005 | case bp_std_terminate_master: |
186c406b | 5006 | case bp_exception_master: |
628fe4e4 | 5007 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 5008 | break; |
ce78b96d | 5009 | case bp_catchpoint: |
c5aa993b JM |
5010 | if (bs->stop) |
5011 | { | |
5012 | if (bs->print) | |
628fe4e4 | 5013 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 5014 | else |
628fe4e4 | 5015 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
5016 | } |
5017 | else | |
628fe4e4 JK |
5018 | { |
5019 | /* There was a catchpoint, but we're not stopping. | |
5020 | This requires no further action. */ | |
5021 | } | |
5022 | break; | |
628fe4e4 JK |
5023 | case bp_jit_event: |
5024 | jit_event = 1; | |
5025 | this_action = BPSTAT_WHAT_SINGLE; | |
c5aa993b | 5026 | break; |
c906108c | 5027 | case bp_call_dummy: |
53a5351d JM |
5028 | /* Make sure the action is stop (silent or noisy), |
5029 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5030 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 5031 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
5032 | break; |
5033 | case bp_std_terminate: | |
5034 | /* Make sure the action is stop (silent or noisy), | |
5035 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5036 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 5037 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 5038 | break; |
1042e4c0 | 5039 | case bp_tracepoint: |
7a697b8d | 5040 | case bp_fast_tracepoint: |
0fb4aa4b | 5041 | case bp_static_tracepoint: |
1042e4c0 SS |
5042 | /* Tracepoint hits should not be reported back to GDB, and |
5043 | if one got through somehow, it should have been filtered | |
5044 | out already. */ | |
5045 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 5046 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
5047 | break; |
5048 | case bp_gnu_ifunc_resolver: | |
5049 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
5050 | this_action = BPSTAT_WHAT_SINGLE; | |
5051 | break; | |
5052 | case bp_gnu_ifunc_resolver_return: | |
5053 | /* The breakpoint will be removed, execution will restart from the | |
5054 | PC of the former breakpoint. */ | |
5055 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5056 | break; | |
628fe4e4 JK |
5057 | default: |
5058 | internal_error (__FILE__, __LINE__, | |
5059 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 5060 | } |
628fe4e4 JK |
5061 | |
5062 | retval.main_action = max (retval.main_action, this_action); | |
c906108c | 5063 | } |
628fe4e4 | 5064 | |
0e30163f JK |
5065 | /* These operations may affect the bs->breakpoint_at state so they are |
5066 | delayed after MAIN_ACTION is decided above. */ | |
5067 | ||
628fe4e4 JK |
5068 | if (jit_event) |
5069 | { | |
5070 | if (debug_infrun) | |
5071 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n"); | |
5072 | ||
5073 | handle_jit_event (); | |
5074 | } | |
5075 | ||
0e30163f JK |
5076 | for (bs = bs_head; bs != NULL; bs = bs->next) |
5077 | { | |
5078 | struct breakpoint *b = bs->breakpoint_at; | |
5079 | ||
5080 | if (b == NULL) | |
5081 | continue; | |
5082 | switch (b->type) | |
5083 | { | |
5084 | case bp_gnu_ifunc_resolver: | |
5085 | gnu_ifunc_resolver_stop (b); | |
5086 | break; | |
5087 | case bp_gnu_ifunc_resolver_return: | |
5088 | gnu_ifunc_resolver_return_stop (b); | |
5089 | break; | |
5090 | } | |
5091 | } | |
5092 | ||
c906108c SS |
5093 | return retval; |
5094 | } | |
5095 | ||
5096 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
5097 | without hardware support). This isn't related to a specific bpstat, | |
5098 | just to things like whether watchpoints are set. */ | |
5099 | ||
c5aa993b | 5100 | int |
fba45db2 | 5101 | bpstat_should_step (void) |
c906108c SS |
5102 | { |
5103 | struct breakpoint *b; | |
cc59ec59 | 5104 | |
c906108c | 5105 | ALL_BREAKPOINTS (b) |
717a8278 | 5106 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 5107 | return 1; |
c906108c SS |
5108 | return 0; |
5109 | } | |
5110 | ||
67822962 PA |
5111 | int |
5112 | bpstat_causes_stop (bpstat bs) | |
5113 | { | |
5114 | for (; bs != NULL; bs = bs->next) | |
5115 | if (bs->stop) | |
5116 | return 1; | |
5117 | ||
5118 | return 0; | |
5119 | } | |
5120 | ||
c906108c | 5121 | \f |
c5aa993b | 5122 | |
170b53b2 UW |
5123 | /* Compute a string of spaces suitable to indent the next line |
5124 | so it starts at the position corresponding to the table column | |
5125 | named COL_NAME in the currently active table of UIOUT. */ | |
5126 | ||
5127 | static char * | |
5128 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
5129 | { | |
5130 | static char wrap_indent[80]; | |
5131 | int i, total_width, width, align; | |
5132 | char *text; | |
5133 | ||
5134 | total_width = 0; | |
5135 | for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++) | |
5136 | { | |
5137 | if (strcmp (text, col_name) == 0) | |
5138 | { | |
5139 | gdb_assert (total_width < sizeof wrap_indent); | |
5140 | memset (wrap_indent, ' ', total_width); | |
5141 | wrap_indent[total_width] = 0; | |
5142 | ||
5143 | return wrap_indent; | |
5144 | } | |
5145 | ||
5146 | total_width += width + 1; | |
5147 | } | |
5148 | ||
5149 | return NULL; | |
5150 | } | |
5151 | ||
b775012e LM |
5152 | /* Determine if the locations of this breakpoint will have their conditions |
5153 | evaluated by the target, host or a mix of both. Returns the following: | |
5154 | ||
5155 | "host": Host evals condition. | |
5156 | "host or target": Host or Target evals condition. | |
5157 | "target": Target evals condition. | |
5158 | */ | |
5159 | ||
5160 | static const char * | |
5161 | bp_condition_evaluator (struct breakpoint *b) | |
5162 | { | |
5163 | struct bp_location *bl; | |
5164 | char host_evals = 0; | |
5165 | char target_evals = 0; | |
5166 | ||
5167 | if (!b) | |
5168 | return NULL; | |
5169 | ||
5170 | if (!is_breakpoint (b)) | |
5171 | return NULL; | |
5172 | ||
5173 | if (gdb_evaluates_breakpoint_condition_p () | |
5174 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5175 | return condition_evaluation_host; | |
5176 | ||
5177 | for (bl = b->loc; bl; bl = bl->next) | |
5178 | { | |
5179 | if (bl->cond_bytecode) | |
5180 | target_evals++; | |
5181 | else | |
5182 | host_evals++; | |
5183 | } | |
5184 | ||
5185 | if (host_evals && target_evals) | |
5186 | return condition_evaluation_both; | |
5187 | else if (target_evals) | |
5188 | return condition_evaluation_target; | |
5189 | else | |
5190 | return condition_evaluation_host; | |
5191 | } | |
5192 | ||
5193 | /* Determine the breakpoint location's condition evaluator. This is | |
5194 | similar to bp_condition_evaluator, but for locations. */ | |
5195 | ||
5196 | static const char * | |
5197 | bp_location_condition_evaluator (struct bp_location *bl) | |
5198 | { | |
5199 | if (bl && !is_breakpoint (bl->owner)) | |
5200 | return NULL; | |
5201 | ||
5202 | if (gdb_evaluates_breakpoint_condition_p () | |
5203 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5204 | return condition_evaluation_host; | |
5205 | ||
5206 | if (bl && bl->cond_bytecode) | |
5207 | return condition_evaluation_target; | |
5208 | else | |
5209 | return condition_evaluation_host; | |
5210 | } | |
5211 | ||
859825b8 JK |
5212 | /* Print the LOC location out of the list of B->LOC locations. */ |
5213 | ||
170b53b2 UW |
5214 | static void |
5215 | print_breakpoint_location (struct breakpoint *b, | |
5216 | struct bp_location *loc) | |
0d381245 | 5217 | { |
79a45e25 | 5218 | struct ui_out *uiout = current_uiout; |
6c95b8df PA |
5219 | struct cleanup *old_chain = save_current_program_space (); |
5220 | ||
859825b8 JK |
5221 | if (loc != NULL && loc->shlib_disabled) |
5222 | loc = NULL; | |
5223 | ||
6c95b8df PA |
5224 | if (loc != NULL) |
5225 | set_current_program_space (loc->pspace); | |
5226 | ||
56435ebe TT |
5227 | if (b->display_canonical) |
5228 | ui_out_field_string (uiout, "what", b->addr_string); | |
f8eba3c6 | 5229 | else if (loc && loc->source_file) |
0d381245 VP |
5230 | { |
5231 | struct symbol *sym | |
5232 | = find_pc_sect_function (loc->address, loc->section); | |
5233 | if (sym) | |
5234 | { | |
5235 | ui_out_text (uiout, "in "); | |
5236 | ui_out_field_string (uiout, "func", | |
5237 | SYMBOL_PRINT_NAME (sym)); | |
170b53b2 UW |
5238 | ui_out_text (uiout, " "); |
5239 | ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what")); | |
5240 | ui_out_text (uiout, "at "); | |
0d381245 | 5241 | } |
f8eba3c6 | 5242 | ui_out_field_string (uiout, "file", loc->source_file); |
0d381245 VP |
5243 | ui_out_text (uiout, ":"); |
5244 | ||
5245 | if (ui_out_is_mi_like_p (uiout)) | |
5246 | { | |
5247 | struct symtab_and_line sal = find_pc_line (loc->address, 0); | |
5248 | char *fullname = symtab_to_fullname (sal.symtab); | |
5249 | ||
5250 | if (fullname) | |
5251 | ui_out_field_string (uiout, "fullname", fullname); | |
5252 | } | |
5253 | ||
f8eba3c6 | 5254 | ui_out_field_int (uiout, "line", loc->line_number); |
0d381245 | 5255 | } |
859825b8 | 5256 | else if (loc) |
0d381245 | 5257 | { |
170b53b2 UW |
5258 | struct ui_stream *stb = ui_out_stream_new (uiout); |
5259 | struct cleanup *stb_chain = make_cleanup_ui_out_stream_delete (stb); | |
5260 | ||
22e722e1 DJ |
5261 | print_address_symbolic (loc->gdbarch, loc->address, stb->stream, |
5262 | demangle, ""); | |
0d381245 | 5263 | ui_out_field_stream (uiout, "at", stb); |
170b53b2 UW |
5264 | |
5265 | do_cleanups (stb_chain); | |
0d381245 | 5266 | } |
859825b8 JK |
5267 | else |
5268 | ui_out_field_string (uiout, "pending", b->addr_string); | |
6c95b8df | 5269 | |
b775012e LM |
5270 | if (loc && is_breakpoint (b) |
5271 | && breakpoint_condition_evaluation_mode () == condition_evaluation_target | |
5272 | && bp_condition_evaluator (b) == condition_evaluation_both) | |
5273 | { | |
5274 | ui_out_text (uiout, " ("); | |
5275 | ui_out_field_string (uiout, "evaluated-by", | |
5276 | bp_location_condition_evaluator (loc)); | |
5277 | ui_out_text (uiout, ")"); | |
5278 | } | |
5279 | ||
6c95b8df | 5280 | do_cleanups (old_chain); |
0d381245 VP |
5281 | } |
5282 | ||
269b11a2 PA |
5283 | static const char * |
5284 | bptype_string (enum bptype type) | |
c906108c | 5285 | { |
c4093a6a JM |
5286 | struct ep_type_description |
5287 | { | |
5288 | enum bptype type; | |
5289 | char *description; | |
5290 | }; | |
5291 | static struct ep_type_description bptypes[] = | |
c906108c | 5292 | { |
c5aa993b JM |
5293 | {bp_none, "?deleted?"}, |
5294 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 5295 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
5296 | {bp_until, "until"}, |
5297 | {bp_finish, "finish"}, | |
5298 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 5299 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
5300 | {bp_read_watchpoint, "read watchpoint"}, |
5301 | {bp_access_watchpoint, "acc watchpoint"}, | |
5302 | {bp_longjmp, "longjmp"}, | |
5303 | {bp_longjmp_resume, "longjmp resume"}, | |
186c406b TT |
5304 | {bp_exception, "exception"}, |
5305 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 5306 | {bp_step_resume, "step resume"}, |
2c03e5be | 5307 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
5308 | {bp_watchpoint_scope, "watchpoint scope"}, |
5309 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 5310 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 5311 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 5312 | {bp_thread_event, "thread events"}, |
1900040c | 5313 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 5314 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 5315 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 5316 | {bp_exception_master, "exception master"}, |
ce78b96d | 5317 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 5318 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 5319 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 5320 | {bp_static_tracepoint, "static tracepoint"}, |
4efc6507 | 5321 | {bp_jit_event, "jit events"}, |
0e30163f JK |
5322 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
5323 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 5324 | }; |
269b11a2 PA |
5325 | |
5326 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
5327 | || ((int) type != bptypes[(int) type].type)) | |
5328 | internal_error (__FILE__, __LINE__, | |
5329 | _("bptypes table does not describe type #%d."), | |
5330 | (int) type); | |
5331 | ||
5332 | return bptypes[(int) type].description; | |
5333 | } | |
5334 | ||
5335 | /* Print B to gdb_stdout. */ | |
5336 | ||
5337 | static void | |
5338 | print_one_breakpoint_location (struct breakpoint *b, | |
5339 | struct bp_location *loc, | |
5340 | int loc_number, | |
5341 | struct bp_location **last_loc, | |
269b11a2 PA |
5342 | int allflag) |
5343 | { | |
5344 | struct command_line *l; | |
c2c6d25f | 5345 | static char bpenables[] = "nynny"; |
c906108c | 5346 | |
79a45e25 | 5347 | struct ui_out *uiout = current_uiout; |
0d381245 VP |
5348 | int header_of_multiple = 0; |
5349 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
5350 | struct value_print_options opts; |
5351 | ||
5352 | get_user_print_options (&opts); | |
0d381245 VP |
5353 | |
5354 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
5355 | /* See comment in print_one_breakpoint concerning treatment of |
5356 | breakpoints with single disabled location. */ | |
0d381245 VP |
5357 | if (loc == NULL |
5358 | && (b->loc != NULL | |
5359 | && (b->loc->next != NULL || !b->loc->enabled))) | |
5360 | header_of_multiple = 1; | |
5361 | if (loc == NULL) | |
5362 | loc = b->loc; | |
5363 | ||
c4093a6a JM |
5364 | annotate_record (); |
5365 | ||
5366 | /* 1 */ | |
5367 | annotate_field (0); | |
0d381245 VP |
5368 | if (part_of_multiple) |
5369 | { | |
5370 | char *formatted; | |
0c6773c1 | 5371 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
5372 | ui_out_field_string (uiout, "number", formatted); |
5373 | xfree (formatted); | |
5374 | } | |
5375 | else | |
5376 | { | |
5377 | ui_out_field_int (uiout, "number", b->number); | |
5378 | } | |
c4093a6a JM |
5379 | |
5380 | /* 2 */ | |
5381 | annotate_field (1); | |
0d381245 VP |
5382 | if (part_of_multiple) |
5383 | ui_out_field_skip (uiout, "type"); | |
269b11a2 PA |
5384 | else |
5385 | ui_out_field_string (uiout, "type", bptype_string (b->type)); | |
c4093a6a JM |
5386 | |
5387 | /* 3 */ | |
5388 | annotate_field (2); | |
0d381245 VP |
5389 | if (part_of_multiple) |
5390 | ui_out_field_skip (uiout, "disp"); | |
5391 | else | |
2cec12e5 | 5392 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 5393 | |
c4093a6a JM |
5394 | |
5395 | /* 4 */ | |
5396 | annotate_field (3); | |
0d381245 | 5397 | if (part_of_multiple) |
54e52265 | 5398 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 5399 | else |
4a64f543 MS |
5400 | ui_out_field_fmt (uiout, "enabled", "%c", |
5401 | bpenables[(int) b->enable_state]); | |
54e52265 | 5402 | ui_out_spaces (uiout, 2); |
0d381245 | 5403 | |
c4093a6a JM |
5404 | |
5405 | /* 5 and 6 */ | |
3086aeae | 5406 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 5407 | { |
4a64f543 MS |
5408 | /* Although the print_one can possibly print all locations, |
5409 | calling it here is not likely to get any nice result. So, | |
5410 | make sure there's just one location. */ | |
0d381245 | 5411 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 5412 | b->ops->print_one (b, last_loc); |
0d381245 | 5413 | } |
3086aeae DJ |
5414 | else |
5415 | switch (b->type) | |
5416 | { | |
5417 | case bp_none: | |
5418 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 5419 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 5420 | break; |
c906108c | 5421 | |
3086aeae DJ |
5422 | case bp_watchpoint: |
5423 | case bp_hardware_watchpoint: | |
5424 | case bp_read_watchpoint: | |
5425 | case bp_access_watchpoint: | |
3a5c3e22 PA |
5426 | { |
5427 | struct watchpoint *w = (struct watchpoint *) b; | |
5428 | ||
5429 | /* Field 4, the address, is omitted (which makes the columns | |
5430 | not line up too nicely with the headers, but the effect | |
5431 | is relatively readable). */ | |
5432 | if (opts.addressprint) | |
5433 | ui_out_field_skip (uiout, "addr"); | |
5434 | annotate_field (5); | |
5435 | ui_out_field_string (uiout, "what", w->exp_string); | |
5436 | } | |
3086aeae DJ |
5437 | break; |
5438 | ||
3086aeae DJ |
5439 | case bp_breakpoint: |
5440 | case bp_hardware_breakpoint: | |
5441 | case bp_until: | |
5442 | case bp_finish: | |
5443 | case bp_longjmp: | |
5444 | case bp_longjmp_resume: | |
186c406b TT |
5445 | case bp_exception: |
5446 | case bp_exception_resume: | |
3086aeae | 5447 | case bp_step_resume: |
2c03e5be | 5448 | case bp_hp_step_resume: |
3086aeae DJ |
5449 | case bp_watchpoint_scope: |
5450 | case bp_call_dummy: | |
aa7d318d | 5451 | case bp_std_terminate: |
3086aeae DJ |
5452 | case bp_shlib_event: |
5453 | case bp_thread_event: | |
5454 | case bp_overlay_event: | |
0fd8e87f | 5455 | case bp_longjmp_master: |
aa7d318d | 5456 | case bp_std_terminate_master: |
186c406b | 5457 | case bp_exception_master: |
1042e4c0 | 5458 | case bp_tracepoint: |
7a697b8d | 5459 | case bp_fast_tracepoint: |
0fb4aa4b | 5460 | case bp_static_tracepoint: |
4efc6507 | 5461 | case bp_jit_event: |
0e30163f JK |
5462 | case bp_gnu_ifunc_resolver: |
5463 | case bp_gnu_ifunc_resolver_return: | |
79a45b7d | 5464 | if (opts.addressprint) |
3086aeae DJ |
5465 | { |
5466 | annotate_field (4); | |
54e52265 | 5467 | if (header_of_multiple) |
0d381245 | 5468 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 5469 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 5470 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 5471 | else |
5af949e3 UW |
5472 | ui_out_field_core_addr (uiout, "addr", |
5473 | loc->gdbarch, loc->address); | |
3086aeae DJ |
5474 | } |
5475 | annotate_field (5); | |
0d381245 | 5476 | if (!header_of_multiple) |
170b53b2 | 5477 | print_breakpoint_location (b, loc); |
0d381245 | 5478 | if (b->loc) |
a6d9a66e | 5479 | *last_loc = b->loc; |
3086aeae DJ |
5480 | break; |
5481 | } | |
c906108c | 5482 | |
6c95b8df PA |
5483 | |
5484 | /* For backward compatibility, don't display inferiors unless there | |
5485 | are several. */ | |
5486 | if (loc != NULL | |
5487 | && !header_of_multiple | |
5488 | && (allflag | |
5489 | || (!gdbarch_has_global_breakpoints (target_gdbarch) | |
5490 | && (number_of_program_spaces () > 1 | |
5491 | || number_of_inferiors () > 1) | |
4a64f543 MS |
5492 | /* LOC is for existing B, it cannot be in |
5493 | moribund_locations and thus having NULL OWNER. */ | |
6c95b8df PA |
5494 | && loc->owner->type != bp_catchpoint))) |
5495 | { | |
5496 | struct inferior *inf; | |
5497 | int first = 1; | |
5498 | ||
5499 | for (inf = inferior_list; inf != NULL; inf = inf->next) | |
5500 | { | |
5501 | if (inf->pspace == loc->pspace) | |
5502 | { | |
5503 | if (first) | |
5504 | { | |
5505 | first = 0; | |
5506 | ui_out_text (uiout, " inf "); | |
5507 | } | |
5508 | else | |
5509 | ui_out_text (uiout, ", "); | |
5510 | ui_out_text (uiout, plongest (inf->num)); | |
5511 | } | |
5512 | } | |
5513 | } | |
5514 | ||
4a306c9a | 5515 | if (!part_of_multiple) |
c4093a6a | 5516 | { |
4a306c9a JB |
5517 | if (b->thread != -1) |
5518 | { | |
5519 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 5520 | "stop only in" line a little further down. */ |
4a306c9a JB |
5521 | ui_out_text (uiout, " thread "); |
5522 | ui_out_field_int (uiout, "thread", b->thread); | |
5523 | } | |
5524 | else if (b->task != 0) | |
5525 | { | |
5526 | ui_out_text (uiout, " task "); | |
5527 | ui_out_field_int (uiout, "task", b->task); | |
5528 | } | |
c4093a6a | 5529 | } |
f1310107 | 5530 | |
8b93c638 | 5531 | ui_out_text (uiout, "\n"); |
f1310107 | 5532 | |
348d480f | 5533 | if (!part_of_multiple) |
f1310107 TJB |
5534 | b->ops->print_one_detail (b, uiout); |
5535 | ||
0d381245 | 5536 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
5537 | { |
5538 | annotate_field (6); | |
8b93c638 | 5539 | ui_out_text (uiout, "\tstop only in stack frame at "); |
e5dd4106 | 5540 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
818dd999 | 5541 | the frame ID. */ |
5af949e3 UW |
5542 | ui_out_field_core_addr (uiout, "frame", |
5543 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 5544 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
5545 | } |
5546 | ||
28010a5d | 5547 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
5548 | { |
5549 | annotate_field (7); | |
d77f58be | 5550 | if (is_tracepoint (b)) |
1042e4c0 SS |
5551 | ui_out_text (uiout, "\ttrace only if "); |
5552 | else | |
5553 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 | 5554 | ui_out_field_string (uiout, "cond", b->cond_string); |
b775012e LM |
5555 | |
5556 | /* Print whether the target is doing the breakpoint's condition | |
5557 | evaluation. If GDB is doing the evaluation, don't print anything. */ | |
5558 | if (is_breakpoint (b) | |
5559 | && breakpoint_condition_evaluation_mode () | |
5560 | == condition_evaluation_target) | |
5561 | { | |
5562 | ui_out_text (uiout, " ("); | |
5563 | ui_out_field_string (uiout, "evaluated-by", | |
5564 | bp_condition_evaluator (b)); | |
5565 | ui_out_text (uiout, " evals)"); | |
5566 | } | |
0101ce28 JJ |
5567 | ui_out_text (uiout, "\n"); |
5568 | } | |
5569 | ||
0d381245 | 5570 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 5571 | { |
4a64f543 | 5572 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
5573 | ui_out_text (uiout, "\tstop only in thread "); |
5574 | ui_out_field_int (uiout, "thread", b->thread); | |
5575 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
5576 | } |
5577 | ||
63c715c6 | 5578 | if (!part_of_multiple && b->hit_count) |
c4093a6a | 5579 | { |
4a64f543 | 5580 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
5581 | if (ep_is_catchpoint (b)) |
5582 | ui_out_text (uiout, "\tcatchpoint"); | |
f196051f SS |
5583 | else if (is_tracepoint (b)) |
5584 | ui_out_text (uiout, "\ttracepoint"); | |
8b93c638 JM |
5585 | else |
5586 | ui_out_text (uiout, "\tbreakpoint"); | |
5587 | ui_out_text (uiout, " already hit "); | |
5588 | ui_out_field_int (uiout, "times", b->hit_count); | |
5589 | if (b->hit_count == 1) | |
5590 | ui_out_text (uiout, " time\n"); | |
5591 | else | |
5592 | ui_out_text (uiout, " times\n"); | |
c4093a6a JM |
5593 | } |
5594 | ||
4a64f543 MS |
5595 | /* Output the count also if it is zero, but only if this is mi. |
5596 | FIXME: Should have a better test for this. */ | |
9dc5e2a9 | 5597 | if (ui_out_is_mi_like_p (uiout)) |
63c715c6 | 5598 | if (!part_of_multiple && b->hit_count == 0) |
fb40c209 | 5599 | ui_out_field_int (uiout, "times", b->hit_count); |
8b93c638 | 5600 | |
0d381245 | 5601 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
5602 | { |
5603 | annotate_field (8); | |
8b93c638 JM |
5604 | ui_out_text (uiout, "\tignore next "); |
5605 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
5606 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 5607 | } |
059fb39f | 5608 | |
816338b5 SS |
5609 | /* Note that an enable count of 1 corresponds to "enable once" |
5610 | behavior, which is reported by the combination of enablement and | |
5611 | disposition, so we don't need to mention it here. */ | |
5612 | if (!part_of_multiple && b->enable_count > 1) | |
5613 | { | |
5614 | annotate_field (8); | |
5615 | ui_out_text (uiout, "\tdisable after "); | |
5616 | /* Tweak the wording to clarify that ignore and enable counts | |
5617 | are distinct, and have additive effect. */ | |
5618 | if (b->ignore_count) | |
5619 | ui_out_text (uiout, "additional "); | |
5620 | else | |
5621 | ui_out_text (uiout, "next "); | |
5622 | ui_out_field_int (uiout, "enable", b->enable_count); | |
5623 | ui_out_text (uiout, " hits\n"); | |
5624 | } | |
5625 | ||
f196051f SS |
5626 | if (!part_of_multiple && is_tracepoint (b)) |
5627 | { | |
5628 | struct tracepoint *tp = (struct tracepoint *) b; | |
5629 | ||
5630 | if (tp->traceframe_usage) | |
5631 | { | |
5632 | ui_out_text (uiout, "\ttrace buffer usage "); | |
5633 | ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage); | |
5634 | ui_out_text (uiout, " bytes\n"); | |
5635 | } | |
5636 | } | |
5637 | ||
9add0f1b | 5638 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 5639 | if (!part_of_multiple && l) |
c4093a6a | 5640 | { |
3b31d625 EZ |
5641 | struct cleanup *script_chain; |
5642 | ||
c4093a6a | 5643 | annotate_field (9); |
3b31d625 | 5644 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 5645 | print_command_lines (uiout, l, 4); |
3b31d625 | 5646 | do_cleanups (script_chain); |
c4093a6a | 5647 | } |
d24317b4 | 5648 | |
d9b3f62e | 5649 | if (is_tracepoint (b)) |
1042e4c0 | 5650 | { |
d9b3f62e PA |
5651 | struct tracepoint *t = (struct tracepoint *) b; |
5652 | ||
5653 | if (!part_of_multiple && t->pass_count) | |
5654 | { | |
5655 | annotate_field (10); | |
5656 | ui_out_text (uiout, "\tpass count "); | |
5657 | ui_out_field_int (uiout, "pass", t->pass_count); | |
5658 | ui_out_text (uiout, " \n"); | |
5659 | } | |
1042e4c0 SS |
5660 | } |
5661 | ||
d24317b4 VP |
5662 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
5663 | { | |
3a5c3e22 PA |
5664 | if (is_watchpoint (b)) |
5665 | { | |
5666 | struct watchpoint *w = (struct watchpoint *) b; | |
5667 | ||
5668 | ui_out_field_string (uiout, "original-location", w->exp_string); | |
5669 | } | |
5670 | else if (b->addr_string) | |
d24317b4 | 5671 | ui_out_field_string (uiout, "original-location", b->addr_string); |
d24317b4 | 5672 | } |
c4093a6a | 5673 | } |
c5aa993b | 5674 | |
0d381245 VP |
5675 | static void |
5676 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 5677 | struct bp_location **last_loc, |
6c95b8df | 5678 | int allflag) |
0d381245 | 5679 | { |
8d3788bd | 5680 | struct cleanup *bkpt_chain; |
79a45e25 | 5681 | struct ui_out *uiout = current_uiout; |
8d3788bd VP |
5682 | |
5683 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); | |
5684 | ||
12c5a436 | 5685 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); |
8d3788bd | 5686 | do_cleanups (bkpt_chain); |
0d381245 VP |
5687 | |
5688 | /* If this breakpoint has custom print function, | |
5689 | it's already printed. Otherwise, print individual | |
5690 | locations, if any. */ | |
5691 | if (b->ops == NULL || b->ops->print_one == NULL) | |
5692 | { | |
4a64f543 MS |
5693 | /* If breakpoint has a single location that is disabled, we |
5694 | print it as if it had several locations, since otherwise it's | |
5695 | hard to represent "breakpoint enabled, location disabled" | |
5696 | situation. | |
5697 | ||
5698 | Note that while hardware watchpoints have several locations | |
a3be7890 | 5699 | internally, that's not a property exposed to user. */ |
0d381245 | 5700 | if (b->loc |
a5606eee | 5701 | && !is_hardware_watchpoint (b) |
8d3788bd | 5702 | && (b->loc->next || !b->loc->enabled)) |
0d381245 VP |
5703 | { |
5704 | struct bp_location *loc; | |
5705 | int n = 1; | |
8d3788bd | 5706 | |
0d381245 | 5707 | for (loc = b->loc; loc; loc = loc->next, ++n) |
8d3788bd VP |
5708 | { |
5709 | struct cleanup *inner2 = | |
5710 | make_cleanup_ui_out_tuple_begin_end (uiout, NULL); | |
5711 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); | |
5712 | do_cleanups (inner2); | |
5713 | } | |
0d381245 VP |
5714 | } |
5715 | } | |
5716 | } | |
5717 | ||
a6d9a66e UW |
5718 | static int |
5719 | breakpoint_address_bits (struct breakpoint *b) | |
5720 | { | |
5721 | int print_address_bits = 0; | |
5722 | struct bp_location *loc; | |
5723 | ||
5724 | for (loc = b->loc; loc; loc = loc->next) | |
5725 | { | |
c7437ca6 PA |
5726 | int addr_bit; |
5727 | ||
5728 | /* Software watchpoints that aren't watching memory don't have | |
5729 | an address to print. */ | |
5730 | if (b->type == bp_watchpoint && loc->watchpoint_type == -1) | |
5731 | continue; | |
5732 | ||
5733 | addr_bit = gdbarch_addr_bit (loc->gdbarch); | |
a6d9a66e UW |
5734 | if (addr_bit > print_address_bits) |
5735 | print_address_bits = addr_bit; | |
5736 | } | |
5737 | ||
5738 | return print_address_bits; | |
5739 | } | |
0d381245 | 5740 | |
c4093a6a JM |
5741 | struct captured_breakpoint_query_args |
5742 | { | |
5743 | int bnum; | |
5744 | }; | |
c5aa993b | 5745 | |
c4093a6a | 5746 | static int |
2b65245e | 5747 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
5748 | { |
5749 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 5750 | struct breakpoint *b; |
a6d9a66e | 5751 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 5752 | |
c4093a6a JM |
5753 | ALL_BREAKPOINTS (b) |
5754 | { | |
5755 | if (args->bnum == b->number) | |
c5aa993b | 5756 | { |
12c5a436 | 5757 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 5758 | return GDB_RC_OK; |
c5aa993b | 5759 | } |
c4093a6a JM |
5760 | } |
5761 | return GDB_RC_NONE; | |
5762 | } | |
c5aa993b | 5763 | |
c4093a6a | 5764 | enum gdb_rc |
4a64f543 MS |
5765 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, |
5766 | char **error_message) | |
c4093a6a JM |
5767 | { |
5768 | struct captured_breakpoint_query_args args; | |
cc59ec59 | 5769 | |
c4093a6a JM |
5770 | args.bnum = bnum; |
5771 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4a64f543 | 5772 | an error. */ |
b0b13bb4 DJ |
5773 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
5774 | error_message, RETURN_MASK_ALL) < 0) | |
5775 | return GDB_RC_FAIL; | |
5776 | else | |
5777 | return GDB_RC_OK; | |
c4093a6a | 5778 | } |
c5aa993b | 5779 | |
09d682a4 TT |
5780 | /* Return true if this breakpoint was set by the user, false if it is |
5781 | internal or momentary. */ | |
5782 | ||
5783 | int | |
5784 | user_breakpoint_p (struct breakpoint *b) | |
5785 | { | |
46c6471b | 5786 | return b->number > 0; |
09d682a4 TT |
5787 | } |
5788 | ||
7f3b0473 | 5789 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
5790 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
5791 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
5792 | FILTER is non-NULL, call it on each breakpoint and only include the | |
5793 | ones for which it returns non-zero. Return the total number of | |
5794 | breakpoints listed. */ | |
c906108c | 5795 | |
d77f58be | 5796 | static int |
e5a67952 | 5797 | breakpoint_1 (char *args, int allflag, |
4a64f543 | 5798 | int (*filter) (const struct breakpoint *)) |
c4093a6a | 5799 | { |
52f0bd74 | 5800 | struct breakpoint *b; |
a6d9a66e | 5801 | struct bp_location *last_loc = NULL; |
7f3b0473 | 5802 | int nr_printable_breakpoints; |
3b31d625 | 5803 | struct cleanup *bkpttbl_chain; |
79a45b7d | 5804 | struct value_print_options opts; |
a6d9a66e | 5805 | int print_address_bits = 0; |
269b11a2 | 5806 | int print_type_col_width = 14; |
79a45e25 | 5807 | struct ui_out *uiout = current_uiout; |
269b11a2 | 5808 | |
79a45b7d TT |
5809 | get_user_print_options (&opts); |
5810 | ||
4a64f543 MS |
5811 | /* Compute the number of rows in the table, as well as the size |
5812 | required for address fields. */ | |
7f3b0473 AC |
5813 | nr_printable_breakpoints = 0; |
5814 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
5815 | { |
5816 | /* If we have a filter, only list the breakpoints it accepts. */ | |
5817 | if (filter && !filter (b)) | |
5818 | continue; | |
5819 | ||
5820 | /* If we have an "args" string, it is a list of breakpoints to | |
5821 | accept. Skip the others. */ | |
5822 | if (args != NULL && *args != '\0') | |
5823 | { | |
5824 | if (allflag && parse_and_eval_long (args) != b->number) | |
5825 | continue; | |
5826 | if (!allflag && !number_is_in_list (args, b->number)) | |
5827 | continue; | |
5828 | } | |
269b11a2 | 5829 | |
e5a67952 MS |
5830 | if (allflag || user_breakpoint_p (b)) |
5831 | { | |
5832 | int addr_bit, type_len; | |
a6d9a66e | 5833 | |
e5a67952 MS |
5834 | addr_bit = breakpoint_address_bits (b); |
5835 | if (addr_bit > print_address_bits) | |
5836 | print_address_bits = addr_bit; | |
269b11a2 | 5837 | |
e5a67952 MS |
5838 | type_len = strlen (bptype_string (b->type)); |
5839 | if (type_len > print_type_col_width) | |
5840 | print_type_col_width = type_len; | |
5841 | ||
5842 | nr_printable_breakpoints++; | |
5843 | } | |
5844 | } | |
7f3b0473 | 5845 | |
79a45b7d | 5846 | if (opts.addressprint) |
3b31d625 | 5847 | bkpttbl_chain |
3e43a32a MS |
5848 | = make_cleanup_ui_out_table_begin_end (uiout, 6, |
5849 | nr_printable_breakpoints, | |
3b31d625 | 5850 | "BreakpointTable"); |
8b93c638 | 5851 | else |
3b31d625 | 5852 | bkpttbl_chain |
3e43a32a MS |
5853 | = make_cleanup_ui_out_table_begin_end (uiout, 5, |
5854 | nr_printable_breakpoints, | |
3b31d625 | 5855 | "BreakpointTable"); |
8b93c638 | 5856 | |
7f3b0473 | 5857 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
5858 | annotate_breakpoints_headers (); |
5859 | if (nr_printable_breakpoints > 0) | |
5860 | annotate_field (0); | |
4a64f543 | 5861 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
5862 | if (nr_printable_breakpoints > 0) |
5863 | annotate_field (1); | |
269b11a2 | 5864 | ui_out_table_header (uiout, print_type_col_width, ui_left, |
4a64f543 | 5865 | "type", "Type"); /* 2 */ |
d7faa9e7 AC |
5866 | if (nr_printable_breakpoints > 0) |
5867 | annotate_field (2); | |
4a64f543 | 5868 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ |
d7faa9e7 AC |
5869 | if (nr_printable_breakpoints > 0) |
5870 | annotate_field (3); | |
54e52265 | 5871 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 5872 | if (opts.addressprint) |
e5a67952 MS |
5873 | { |
5874 | if (nr_printable_breakpoints > 0) | |
5875 | annotate_field (4); | |
5876 | if (print_address_bits <= 32) | |
5877 | ui_out_table_header (uiout, 10, ui_left, | |
5878 | "addr", "Address"); /* 5 */ | |
5879 | else | |
5880 | ui_out_table_header (uiout, 18, ui_left, | |
5881 | "addr", "Address"); /* 5 */ | |
5882 | } | |
d7faa9e7 AC |
5883 | if (nr_printable_breakpoints > 0) |
5884 | annotate_field (5); | |
5885 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
5886 | ui_out_table_body (uiout); | |
5887 | if (nr_printable_breakpoints > 0) | |
5888 | annotate_breakpoints_table (); | |
7f3b0473 | 5889 | |
c4093a6a | 5890 | ALL_BREAKPOINTS (b) |
e5a67952 MS |
5891 | { |
5892 | QUIT; | |
5893 | /* If we have a filter, only list the breakpoints it accepts. */ | |
5894 | if (filter && !filter (b)) | |
5895 | continue; | |
5896 | ||
5897 | /* If we have an "args" string, it is a list of breakpoints to | |
5898 | accept. Skip the others. */ | |
5899 | ||
5900 | if (args != NULL && *args != '\0') | |
5901 | { | |
5902 | if (allflag) /* maintenance info breakpoint */ | |
5903 | { | |
5904 | if (parse_and_eval_long (args) != b->number) | |
5905 | continue; | |
5906 | } | |
5907 | else /* all others */ | |
5908 | { | |
5909 | if (!number_is_in_list (args, b->number)) | |
5910 | continue; | |
5911 | } | |
5912 | } | |
5913 | /* We only print out user settable breakpoints unless the | |
5914 | allflag is set. */ | |
5915 | if (allflag || user_breakpoint_p (b)) | |
12c5a436 | 5916 | print_one_breakpoint (b, &last_loc, allflag); |
e5a67952 MS |
5917 | } |
5918 | ||
3b31d625 | 5919 | do_cleanups (bkpttbl_chain); |
698384cd | 5920 | |
7f3b0473 | 5921 | if (nr_printable_breakpoints == 0) |
c906108c | 5922 | { |
4a64f543 MS |
5923 | /* If there's a filter, let the caller decide how to report |
5924 | empty list. */ | |
d77f58be SS |
5925 | if (!filter) |
5926 | { | |
e5a67952 | 5927 | if (args == NULL || *args == '\0') |
d77f58be SS |
5928 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); |
5929 | else | |
4a64f543 | 5930 | ui_out_message (uiout, 0, |
e5a67952 MS |
5931 | "No breakpoint or watchpoint matching '%s'.\n", |
5932 | args); | |
d77f58be | 5933 | } |
c906108c SS |
5934 | } |
5935 | else | |
c4093a6a | 5936 | { |
a6d9a66e UW |
5937 | if (last_loc && !server_command) |
5938 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 5939 | } |
c906108c | 5940 | |
4a64f543 | 5941 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 5942 | there have been breakpoints? */ |
c906108c | 5943 | annotate_breakpoints_table_end (); |
d77f58be SS |
5944 | |
5945 | return nr_printable_breakpoints; | |
c906108c SS |
5946 | } |
5947 | ||
ad443146 SS |
5948 | /* Display the value of default-collect in a way that is generally |
5949 | compatible with the breakpoint list. */ | |
5950 | ||
5951 | static void | |
5952 | default_collect_info (void) | |
5953 | { | |
79a45e25 PA |
5954 | struct ui_out *uiout = current_uiout; |
5955 | ||
ad443146 SS |
5956 | /* If it has no value (which is frequently the case), say nothing; a |
5957 | message like "No default-collect." gets in user's face when it's | |
5958 | not wanted. */ | |
5959 | if (!*default_collect) | |
5960 | return; | |
5961 | ||
5962 | /* The following phrase lines up nicely with per-tracepoint collect | |
5963 | actions. */ | |
5964 | ui_out_text (uiout, "default collect "); | |
5965 | ui_out_field_string (uiout, "default-collect", default_collect); | |
5966 | ui_out_text (uiout, " \n"); | |
5967 | } | |
5968 | ||
c906108c | 5969 | static void |
e5a67952 | 5970 | breakpoints_info (char *args, int from_tty) |
c906108c | 5971 | { |
e5a67952 | 5972 | breakpoint_1 (args, 0, NULL); |
ad443146 SS |
5973 | |
5974 | default_collect_info (); | |
d77f58be SS |
5975 | } |
5976 | ||
5977 | static void | |
e5a67952 | 5978 | watchpoints_info (char *args, int from_tty) |
d77f58be | 5979 | { |
e5a67952 | 5980 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
79a45e25 | 5981 | struct ui_out *uiout = current_uiout; |
d77f58be SS |
5982 | |
5983 | if (num_printed == 0) | |
5984 | { | |
e5a67952 | 5985 | if (args == NULL || *args == '\0') |
d77f58be SS |
5986 | ui_out_message (uiout, 0, "No watchpoints.\n"); |
5987 | else | |
e5a67952 | 5988 | ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args); |
d77f58be | 5989 | } |
c906108c SS |
5990 | } |
5991 | ||
7a292a7a | 5992 | static void |
e5a67952 | 5993 | maintenance_info_breakpoints (char *args, int from_tty) |
c906108c | 5994 | { |
e5a67952 | 5995 | breakpoint_1 (args, 1, NULL); |
ad443146 SS |
5996 | |
5997 | default_collect_info (); | |
c906108c SS |
5998 | } |
5999 | ||
0d381245 | 6000 | static int |
714835d5 | 6001 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 6002 | struct program_space *pspace, |
714835d5 | 6003 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
6004 | { |
6005 | struct bp_location *bl = b->loc; | |
cc59ec59 | 6006 | |
0d381245 VP |
6007 | for (; bl; bl = bl->next) |
6008 | { | |
6c95b8df PA |
6009 | if (bl->pspace == pspace |
6010 | && bl->address == pc | |
0d381245 VP |
6011 | && (!overlay_debugging || bl->section == section)) |
6012 | return 1; | |
6013 | } | |
6014 | return 0; | |
6015 | } | |
6016 | ||
672f9b60 | 6017 | /* Print a message describing any user-breakpoints set at PC. This |
6c95b8df PA |
6018 | concerns with logical breakpoints, so we match program spaces, not |
6019 | address spaces. */ | |
c906108c SS |
6020 | |
6021 | static void | |
6c95b8df PA |
6022 | describe_other_breakpoints (struct gdbarch *gdbarch, |
6023 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 6024 | struct obj_section *section, int thread) |
c906108c | 6025 | { |
52f0bd74 AC |
6026 | int others = 0; |
6027 | struct breakpoint *b; | |
c906108c SS |
6028 | |
6029 | ALL_BREAKPOINTS (b) | |
672f9b60 KP |
6030 | others += (user_breakpoint_p (b) |
6031 | && breakpoint_has_pc (b, pspace, pc, section)); | |
c906108c SS |
6032 | if (others > 0) |
6033 | { | |
a3f17187 AC |
6034 | if (others == 1) |
6035 | printf_filtered (_("Note: breakpoint ")); | |
6036 | else /* if (others == ???) */ | |
6037 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 6038 | ALL_BREAKPOINTS (b) |
672f9b60 | 6039 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
6040 | { |
6041 | others--; | |
6042 | printf_filtered ("%d", b->number); | |
6043 | if (b->thread == -1 && thread != -1) | |
6044 | printf_filtered (" (all threads)"); | |
6045 | else if (b->thread != -1) | |
6046 | printf_filtered (" (thread %d)", b->thread); | |
6047 | printf_filtered ("%s%s ", | |
059fb39f | 6048 | ((b->enable_state == bp_disabled |
f8eba3c6 | 6049 | || b->enable_state == bp_call_disabled) |
0d381245 VP |
6050 | ? " (disabled)" |
6051 | : b->enable_state == bp_permanent | |
6052 | ? " (permanent)" | |
6053 | : ""), | |
6054 | (others > 1) ? "," | |
6055 | : ((others == 1) ? " and" : "")); | |
6056 | } | |
a3f17187 | 6057 | printf_filtered (_("also set at pc ")); |
5af949e3 | 6058 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
6059 | printf_filtered (".\n"); |
6060 | } | |
6061 | } | |
6062 | \f | |
c906108c | 6063 | |
e4f237da KB |
6064 | /* Return true iff it is meaningful to use the address member of |
6065 | BPT. For some breakpoint types, the address member is irrelevant | |
6066 | and it makes no sense to attempt to compare it to other addresses | |
6067 | (or use it for any other purpose either). | |
6068 | ||
4a64f543 MS |
6069 | More specifically, each of the following breakpoint types will |
6070 | always have a zero valued address and we don't want to mark | |
6071 | breakpoints of any of these types to be a duplicate of an actual | |
6072 | breakpoint at address zero: | |
e4f237da KB |
6073 | |
6074 | bp_watchpoint | |
2d134ed3 PA |
6075 | bp_catchpoint |
6076 | ||
6077 | */ | |
e4f237da KB |
6078 | |
6079 | static int | |
6080 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
6081 | { | |
6082 | enum bptype type = bpt->type; | |
6083 | ||
2d134ed3 PA |
6084 | return (type != bp_watchpoint && type != bp_catchpoint); |
6085 | } | |
6086 | ||
6087 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
6088 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
6089 | ||
6090 | static int | |
4a64f543 MS |
6091 | watchpoint_locations_match (struct bp_location *loc1, |
6092 | struct bp_location *loc2) | |
2d134ed3 | 6093 | { |
3a5c3e22 PA |
6094 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
6095 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
6096 | ||
6097 | /* Both of them must exist. */ | |
6098 | gdb_assert (w1 != NULL); | |
6099 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 6100 | |
4a64f543 MS |
6101 | /* If the target can evaluate the condition expression in hardware, |
6102 | then we we need to insert both watchpoints even if they are at | |
6103 | the same place. Otherwise the watchpoint will only trigger when | |
6104 | the condition of whichever watchpoint was inserted evaluates to | |
6105 | true, not giving a chance for GDB to check the condition of the | |
6106 | other watchpoint. */ | |
3a5c3e22 | 6107 | if ((w1->cond_exp |
4a64f543 MS |
6108 | && target_can_accel_watchpoint_condition (loc1->address, |
6109 | loc1->length, | |
0cf6dd15 | 6110 | loc1->watchpoint_type, |
3a5c3e22 PA |
6111 | w1->cond_exp)) |
6112 | || (w2->cond_exp | |
4a64f543 MS |
6113 | && target_can_accel_watchpoint_condition (loc2->address, |
6114 | loc2->length, | |
0cf6dd15 | 6115 | loc2->watchpoint_type, |
3a5c3e22 | 6116 | w2->cond_exp))) |
0cf6dd15 TJB |
6117 | return 0; |
6118 | ||
85d721b8 PA |
6119 | /* Note that this checks the owner's type, not the location's. In |
6120 | case the target does not support read watchpoints, but does | |
6121 | support access watchpoints, we'll have bp_read_watchpoint | |
6122 | watchpoints with hw_access locations. Those should be considered | |
6123 | duplicates of hw_read locations. The hw_read locations will | |
6124 | become hw_access locations later. */ | |
2d134ed3 PA |
6125 | return (loc1->owner->type == loc2->owner->type |
6126 | && loc1->pspace->aspace == loc2->pspace->aspace | |
6127 | && loc1->address == loc2->address | |
6128 | && loc1->length == loc2->length); | |
e4f237da KB |
6129 | } |
6130 | ||
6c95b8df PA |
6131 | /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the |
6132 | same breakpoint location. In most targets, this can only be true | |
6133 | if ASPACE1 matches ASPACE2. On targets that have global | |
6134 | breakpoints, the address space doesn't really matter. */ | |
6135 | ||
6136 | static int | |
6137 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, | |
6138 | struct address_space *aspace2, CORE_ADDR addr2) | |
6139 | { | |
6140 | return ((gdbarch_has_global_breakpoints (target_gdbarch) | |
6141 | || aspace1 == aspace2) | |
6142 | && addr1 == addr2); | |
6143 | } | |
6144 | ||
f1310107 TJB |
6145 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
6146 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
6147 | matches ASPACE2. On targets that have global breakpoints, the address | |
6148 | space doesn't really matter. */ | |
6149 | ||
6150 | static int | |
6151 | breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1, | |
6152 | int len1, struct address_space *aspace2, | |
6153 | CORE_ADDR addr2) | |
6154 | { | |
6155 | return ((gdbarch_has_global_breakpoints (target_gdbarch) | |
6156 | || aspace1 == aspace2) | |
6157 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
6158 | } | |
6159 | ||
6160 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
6161 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
6162 | matches the breakpoint's address space. On targets that have global | |
6163 | breakpoints, the address space doesn't really matter. */ | |
6164 | ||
6165 | static int | |
6166 | breakpoint_location_address_match (struct bp_location *bl, | |
6167 | struct address_space *aspace, | |
6168 | CORE_ADDR addr) | |
6169 | { | |
6170 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6171 | aspace, addr) | |
6172 | || (bl->length | |
6173 | && breakpoint_address_match_range (bl->pspace->aspace, | |
6174 | bl->address, bl->length, | |
6175 | aspace, addr))); | |
6176 | } | |
6177 | ||
1e4d1764 YQ |
6178 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
6179 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns | |
6180 | true, otherwise returns false. */ | |
6181 | ||
6182 | static int | |
6183 | tracepoint_locations_match (struct bp_location *loc1, | |
6184 | struct bp_location *loc2) | |
6185 | { | |
6186 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) | |
6187 | /* Since tracepoint locations are never duplicated with others', tracepoint | |
6188 | locations at the same address of different tracepoints are regarded as | |
6189 | different locations. */ | |
6190 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); | |
6191 | else | |
6192 | return 0; | |
6193 | } | |
6194 | ||
2d134ed3 PA |
6195 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
6196 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
6197 | represent the same location. */ | |
6198 | ||
6199 | static int | |
4a64f543 MS |
6200 | breakpoint_locations_match (struct bp_location *loc1, |
6201 | struct bp_location *loc2) | |
2d134ed3 | 6202 | { |
2bdf28a0 JK |
6203 | int hw_point1, hw_point2; |
6204 | ||
6205 | /* Both of them must not be in moribund_locations. */ | |
6206 | gdb_assert (loc1->owner != NULL); | |
6207 | gdb_assert (loc2->owner != NULL); | |
6208 | ||
6209 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
6210 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
6211 | |
6212 | if (hw_point1 != hw_point2) | |
6213 | return 0; | |
6214 | else if (hw_point1) | |
6215 | return watchpoint_locations_match (loc1, loc2); | |
1e4d1764 YQ |
6216 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
6217 | return tracepoint_locations_match (loc1, loc2); | |
2d134ed3 | 6218 | else |
f1310107 TJB |
6219 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
6220 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
6221 | loc2->pspace->aspace, loc2->address) | |
6222 | && loc1->length == loc2->length); | |
2d134ed3 PA |
6223 | } |
6224 | ||
76897487 KB |
6225 | static void |
6226 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
6227 | int bnum, int have_bnum) | |
6228 | { | |
f63fbe86 MS |
6229 | /* The longest string possibly returned by hex_string_custom |
6230 | is 50 chars. These must be at least that big for safety. */ | |
6231 | char astr1[64]; | |
6232 | char astr2[64]; | |
76897487 | 6233 | |
bb599908 PH |
6234 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
6235 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 6236 | if (have_bnum) |
8a3fe4f8 | 6237 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
6238 | bnum, astr1, astr2); |
6239 | else | |
8a3fe4f8 | 6240 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
6241 | } |
6242 | ||
4a64f543 MS |
6243 | /* Adjust a breakpoint's address to account for architectural |
6244 | constraints on breakpoint placement. Return the adjusted address. | |
6245 | Note: Very few targets require this kind of adjustment. For most | |
6246 | targets, this function is simply the identity function. */ | |
76897487 KB |
6247 | |
6248 | static CORE_ADDR | |
a6d9a66e UW |
6249 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
6250 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 6251 | { |
a6d9a66e | 6252 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
6253 | { |
6254 | /* Very few targets need any kind of breakpoint adjustment. */ | |
6255 | return bpaddr; | |
6256 | } | |
88f7da05 KB |
6257 | else if (bptype == bp_watchpoint |
6258 | || bptype == bp_hardware_watchpoint | |
6259 | || bptype == bp_read_watchpoint | |
6260 | || bptype == bp_access_watchpoint | |
fe798b75 | 6261 | || bptype == bp_catchpoint) |
88f7da05 KB |
6262 | { |
6263 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
6264 | have their addresses modified. */ | |
6265 | return bpaddr; | |
6266 | } | |
76897487 KB |
6267 | else |
6268 | { | |
6269 | CORE_ADDR adjusted_bpaddr; | |
6270 | ||
6271 | /* Some targets have architectural constraints on the placement | |
6272 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 6273 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
6274 | |
6275 | /* An adjusted breakpoint address can significantly alter | |
6276 | a user's expectations. Print a warning if an adjustment | |
6277 | is required. */ | |
6278 | if (adjusted_bpaddr != bpaddr) | |
6279 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
6280 | ||
6281 | return adjusted_bpaddr; | |
6282 | } | |
6283 | } | |
6284 | ||
28010a5d PA |
6285 | void |
6286 | init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops, | |
6287 | struct breakpoint *owner) | |
7cc221ef | 6288 | { |
7cc221ef DJ |
6289 | memset (loc, 0, sizeof (*loc)); |
6290 | ||
348d480f PA |
6291 | gdb_assert (ops != NULL); |
6292 | ||
28010a5d PA |
6293 | loc->ops = ops; |
6294 | loc->owner = owner; | |
511a6cd4 | 6295 | loc->cond = NULL; |
b775012e | 6296 | loc->cond_bytecode = NULL; |
0d381245 VP |
6297 | loc->shlib_disabled = 0; |
6298 | loc->enabled = 1; | |
e049a4b5 | 6299 | |
28010a5d | 6300 | switch (owner->type) |
e049a4b5 DJ |
6301 | { |
6302 | case bp_breakpoint: | |
6303 | case bp_until: | |
6304 | case bp_finish: | |
6305 | case bp_longjmp: | |
6306 | case bp_longjmp_resume: | |
186c406b TT |
6307 | case bp_exception: |
6308 | case bp_exception_resume: | |
e049a4b5 | 6309 | case bp_step_resume: |
2c03e5be | 6310 | case bp_hp_step_resume: |
e049a4b5 DJ |
6311 | case bp_watchpoint_scope: |
6312 | case bp_call_dummy: | |
aa7d318d | 6313 | case bp_std_terminate: |
e049a4b5 DJ |
6314 | case bp_shlib_event: |
6315 | case bp_thread_event: | |
6316 | case bp_overlay_event: | |
4efc6507 | 6317 | case bp_jit_event: |
0fd8e87f | 6318 | case bp_longjmp_master: |
aa7d318d | 6319 | case bp_std_terminate_master: |
186c406b | 6320 | case bp_exception_master: |
0e30163f JK |
6321 | case bp_gnu_ifunc_resolver: |
6322 | case bp_gnu_ifunc_resolver_return: | |
e049a4b5 | 6323 | loc->loc_type = bp_loc_software_breakpoint; |
b775012e | 6324 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
6325 | break; |
6326 | case bp_hardware_breakpoint: | |
6327 | loc->loc_type = bp_loc_hardware_breakpoint; | |
b775012e | 6328 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
6329 | break; |
6330 | case bp_hardware_watchpoint: | |
6331 | case bp_read_watchpoint: | |
6332 | case bp_access_watchpoint: | |
6333 | loc->loc_type = bp_loc_hardware_watchpoint; | |
6334 | break; | |
6335 | case bp_watchpoint: | |
ce78b96d | 6336 | case bp_catchpoint: |
15c3d785 PA |
6337 | case bp_tracepoint: |
6338 | case bp_fast_tracepoint: | |
0fb4aa4b | 6339 | case bp_static_tracepoint: |
e049a4b5 DJ |
6340 | loc->loc_type = bp_loc_other; |
6341 | break; | |
6342 | default: | |
e2e0b3e5 | 6343 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
6344 | } |
6345 | ||
f431efe5 | 6346 | loc->refc = 1; |
28010a5d PA |
6347 | } |
6348 | ||
6349 | /* Allocate a struct bp_location. */ | |
6350 | ||
6351 | static struct bp_location * | |
6352 | allocate_bp_location (struct breakpoint *bpt) | |
6353 | { | |
348d480f PA |
6354 | return bpt->ops->allocate_location (bpt); |
6355 | } | |
7cc221ef | 6356 | |
f431efe5 PA |
6357 | static void |
6358 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 | 6359 | { |
348d480f | 6360 | loc->ops->dtor (loc); |
fe3f5fa8 VP |
6361 | xfree (loc); |
6362 | } | |
6363 | ||
f431efe5 PA |
6364 | /* Increment reference count. */ |
6365 | ||
6366 | static void | |
6367 | incref_bp_location (struct bp_location *bl) | |
6368 | { | |
6369 | ++bl->refc; | |
6370 | } | |
6371 | ||
6372 | /* Decrement reference count. If the reference count reaches 0, | |
6373 | destroy the bp_location. Sets *BLP to NULL. */ | |
6374 | ||
6375 | static void | |
6376 | decref_bp_location (struct bp_location **blp) | |
6377 | { | |
0807b50c PA |
6378 | gdb_assert ((*blp)->refc > 0); |
6379 | ||
f431efe5 PA |
6380 | if (--(*blp)->refc == 0) |
6381 | free_bp_location (*blp); | |
6382 | *blp = NULL; | |
6383 | } | |
6384 | ||
346774a9 | 6385 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 6386 | |
346774a9 PA |
6387 | static void |
6388 | add_to_breakpoint_chain (struct breakpoint *b) | |
c906108c | 6389 | { |
346774a9 | 6390 | struct breakpoint *b1; |
c906108c | 6391 | |
346774a9 PA |
6392 | /* Add this breakpoint to the end of the chain so that a list of |
6393 | breakpoints will come out in order of increasing numbers. */ | |
6394 | ||
6395 | b1 = breakpoint_chain; | |
6396 | if (b1 == 0) | |
6397 | breakpoint_chain = b; | |
6398 | else | |
6399 | { | |
6400 | while (b1->next) | |
6401 | b1 = b1->next; | |
6402 | b1->next = b; | |
6403 | } | |
6404 | } | |
6405 | ||
6406 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
6407 | ||
6408 | static void | |
6409 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
6410 | struct gdbarch *gdbarch, | |
28010a5d | 6411 | enum bptype bptype, |
c0a91b2b | 6412 | const struct breakpoint_ops *ops) |
346774a9 | 6413 | { |
c906108c | 6414 | memset (b, 0, sizeof (*b)); |
2219d63c | 6415 | |
348d480f PA |
6416 | gdb_assert (ops != NULL); |
6417 | ||
28010a5d | 6418 | b->ops = ops; |
4d28f7a8 | 6419 | b->type = bptype; |
a6d9a66e | 6420 | b->gdbarch = gdbarch; |
c906108c SS |
6421 | b->language = current_language->la_language; |
6422 | b->input_radix = input_radix; | |
6423 | b->thread = -1; | |
b5de0fa7 | 6424 | b->enable_state = bp_enabled; |
c906108c SS |
6425 | b->next = 0; |
6426 | b->silent = 0; | |
6427 | b->ignore_count = 0; | |
6428 | b->commands = NULL; | |
818dd999 | 6429 | b->frame_id = null_frame_id; |
0d381245 | 6430 | b->condition_not_parsed = 0; |
84f4c1fe | 6431 | b->py_bp_object = NULL; |
d0fb5eae | 6432 | b->related_breakpoint = b; |
346774a9 PA |
6433 | } |
6434 | ||
6435 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
6436 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
6437 | |
6438 | static struct breakpoint * | |
6439 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 6440 | enum bptype bptype, |
c0a91b2b | 6441 | const struct breakpoint_ops *ops) |
346774a9 PA |
6442 | { |
6443 | struct breakpoint *b = XNEW (struct breakpoint); | |
6444 | ||
348d480f | 6445 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
c56053d2 | 6446 | add_to_breakpoint_chain (b); |
0d381245 VP |
6447 | return b; |
6448 | } | |
6449 | ||
0e30163f JK |
6450 | /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function |
6451 | resolutions should be made as the user specified the location explicitly | |
6452 | enough. */ | |
6453 | ||
0d381245 | 6454 | static void |
0e30163f | 6455 | set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) |
0d381245 | 6456 | { |
2bdf28a0 JK |
6457 | gdb_assert (loc->owner != NULL); |
6458 | ||
0d381245 | 6459 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 6460 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 6461 | || is_tracepoint (loc->owner)) |
0d381245 | 6462 | { |
0e30163f | 6463 | int is_gnu_ifunc; |
2c02bd72 | 6464 | const char *function_name; |
0e30163f | 6465 | |
2c02bd72 | 6466 | find_pc_partial_function_gnu_ifunc (loc->address, &function_name, |
0e30163f JK |
6467 | NULL, NULL, &is_gnu_ifunc); |
6468 | ||
6469 | if (is_gnu_ifunc && !explicit_loc) | |
6470 | { | |
6471 | struct breakpoint *b = loc->owner; | |
6472 | ||
6473 | gdb_assert (loc->pspace == current_program_space); | |
2c02bd72 | 6474 | if (gnu_ifunc_resolve_name (function_name, |
0e30163f JK |
6475 | &loc->requested_address)) |
6476 | { | |
6477 | /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */ | |
6478 | loc->address = adjust_breakpoint_address (loc->gdbarch, | |
6479 | loc->requested_address, | |
6480 | b->type); | |
6481 | } | |
6482 | else if (b->type == bp_breakpoint && b->loc == loc | |
6483 | && loc->next == NULL && b->related_breakpoint == b) | |
6484 | { | |
6485 | /* Create only the whole new breakpoint of this type but do not | |
6486 | mess more complicated breakpoints with multiple locations. */ | |
6487 | b->type = bp_gnu_ifunc_resolver; | |
6488 | } | |
6489 | } | |
6490 | ||
2c02bd72 DE |
6491 | if (function_name) |
6492 | loc->function_name = xstrdup (function_name); | |
0d381245 VP |
6493 | } |
6494 | } | |
6495 | ||
a6d9a66e | 6496 | /* Attempt to determine architecture of location identified by SAL. */ |
1bfeeb0f | 6497 | struct gdbarch * |
a6d9a66e UW |
6498 | get_sal_arch (struct symtab_and_line sal) |
6499 | { | |
6500 | if (sal.section) | |
6501 | return get_objfile_arch (sal.section->objfile); | |
6502 | if (sal.symtab) | |
6503 | return get_objfile_arch (sal.symtab->objfile); | |
6504 | ||
6505 | return NULL; | |
6506 | } | |
6507 | ||
346774a9 PA |
6508 | /* Low level routine for partially initializing a breakpoint of type |
6509 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 6510 | file name, and line number are provided by SAL. |
0d381245 VP |
6511 | |
6512 | It is expected that the caller will complete the initialization of | |
6513 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 6514 | information regarding the creation of a new breakpoint. */ |
0d381245 | 6515 | |
346774a9 PA |
6516 | static void |
6517 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 6518 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 6519 | const struct breakpoint_ops *ops) |
0d381245 | 6520 | { |
28010a5d | 6521 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 6522 | |
3742cc8b | 6523 | add_location_to_breakpoint (b, &sal); |
0d381245 | 6524 | |
6c95b8df PA |
6525 | if (bptype != bp_catchpoint) |
6526 | gdb_assert (sal.pspace != NULL); | |
6527 | ||
f8eba3c6 TT |
6528 | /* Store the program space that was used to set the breakpoint, |
6529 | except for ordinary breakpoints, which are independent of the | |
6530 | program space. */ | |
6531 | if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) | |
6532 | b->pspace = sal.pspace; | |
0d381245 | 6533 | |
c906108c | 6534 | breakpoints_changed (); |
346774a9 | 6535 | } |
c906108c | 6536 | |
346774a9 PA |
6537 | /* set_raw_breakpoint is a low level routine for allocating and |
6538 | partially initializing a breakpoint of type BPTYPE. The newly | |
6539 | created breakpoint's address, section, source file name, and line | |
6540 | number are provided by SAL. The newly created and partially | |
6541 | initialized breakpoint is added to the breakpoint chain and | |
6542 | is also returned as the value of this function. | |
6543 | ||
6544 | It is expected that the caller will complete the initialization of | |
6545 | the newly created breakpoint struct as well as output any status | |
6546 | information regarding the creation of a new breakpoint. In | |
6547 | particular, set_raw_breakpoint does NOT set the breakpoint | |
6548 | number! Care should be taken to not allow an error to occur | |
6549 | prior to completing the initialization of the breakpoint. If this | |
6550 | should happen, a bogus breakpoint will be left on the chain. */ | |
6551 | ||
6552 | struct breakpoint * | |
6553 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
348d480f | 6554 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 6555 | const struct breakpoint_ops *ops) |
346774a9 PA |
6556 | { |
6557 | struct breakpoint *b = XNEW (struct breakpoint); | |
6558 | ||
348d480f | 6559 | init_raw_breakpoint (b, gdbarch, sal, bptype, ops); |
c56053d2 | 6560 | add_to_breakpoint_chain (b); |
c906108c SS |
6561 | return b; |
6562 | } | |
6563 | ||
c2c6d25f JM |
6564 | |
6565 | /* Note that the breakpoint object B describes a permanent breakpoint | |
6566 | instruction, hard-wired into the inferior's code. */ | |
6567 | void | |
6568 | make_breakpoint_permanent (struct breakpoint *b) | |
6569 | { | |
0d381245 | 6570 | struct bp_location *bl; |
cc59ec59 | 6571 | |
b5de0fa7 | 6572 | b->enable_state = bp_permanent; |
c2c6d25f | 6573 | |
4a64f543 MS |
6574 | /* By definition, permanent breakpoints are already present in the |
6575 | code. Mark all locations as inserted. For now, | |
6576 | make_breakpoint_permanent is called in just one place, so it's | |
6577 | hard to say if it's reasonable to have permanent breakpoint with | |
e5dd4106 | 6578 | multiple locations or not, but it's easy to implement. */ |
0d381245 VP |
6579 | for (bl = b->loc; bl; bl = bl->next) |
6580 | bl->inserted = 1; | |
c2c6d25f JM |
6581 | } |
6582 | ||
53a5351d | 6583 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
6584 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
6585 | initiated the operation. */ | |
c906108c SS |
6586 | |
6587 | void | |
186c406b | 6588 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 6589 | { |
35df4500 | 6590 | struct breakpoint *b, *b_tmp; |
186c406b | 6591 | int thread = tp->num; |
0fd8e87f UW |
6592 | |
6593 | /* To avoid having to rescan all objfile symbols at every step, | |
6594 | we maintain a list of continually-inserted but always disabled | |
6595 | longjmp "master" breakpoints. Here, we simply create momentary | |
6596 | clones of those and enable them for the requested thread. */ | |
35df4500 | 6597 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 6598 | if (b->pspace == current_program_space |
186c406b TT |
6599 | && (b->type == bp_longjmp_master |
6600 | || b->type == bp_exception_master)) | |
0fd8e87f | 6601 | { |
06edf0c0 PA |
6602 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
6603 | struct breakpoint *clone; | |
cc59ec59 | 6604 | |
06edf0c0 PA |
6605 | clone = momentary_breakpoint_from_master (b, type, |
6606 | &momentary_breakpoint_ops); | |
0fd8e87f UW |
6607 | clone->thread = thread; |
6608 | } | |
186c406b TT |
6609 | |
6610 | tp->initiating_frame = frame; | |
c906108c SS |
6611 | } |
6612 | ||
611c83ae | 6613 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 6614 | void |
611c83ae | 6615 | delete_longjmp_breakpoint (int thread) |
c906108c | 6616 | { |
35df4500 | 6617 | struct breakpoint *b, *b_tmp; |
c906108c | 6618 | |
35df4500 | 6619 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 6620 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
6621 | { |
6622 | if (b->thread == thread) | |
6623 | delete_breakpoint (b); | |
6624 | } | |
c906108c SS |
6625 | } |
6626 | ||
1900040c MS |
6627 | void |
6628 | enable_overlay_breakpoints (void) | |
6629 | { | |
52f0bd74 | 6630 | struct breakpoint *b; |
1900040c MS |
6631 | |
6632 | ALL_BREAKPOINTS (b) | |
6633 | if (b->type == bp_overlay_event) | |
6634 | { | |
6635 | b->enable_state = bp_enabled; | |
b60e7edf | 6636 | update_global_location_list (1); |
c02f5703 | 6637 | overlay_events_enabled = 1; |
1900040c MS |
6638 | } |
6639 | } | |
6640 | ||
6641 | void | |
6642 | disable_overlay_breakpoints (void) | |
6643 | { | |
52f0bd74 | 6644 | struct breakpoint *b; |
1900040c MS |
6645 | |
6646 | ALL_BREAKPOINTS (b) | |
6647 | if (b->type == bp_overlay_event) | |
6648 | { | |
6649 | b->enable_state = bp_disabled; | |
b60e7edf | 6650 | update_global_location_list (0); |
c02f5703 | 6651 | overlay_events_enabled = 0; |
1900040c MS |
6652 | } |
6653 | } | |
6654 | ||
aa7d318d TT |
6655 | /* Set an active std::terminate breakpoint for each std::terminate |
6656 | master breakpoint. */ | |
6657 | void | |
6658 | set_std_terminate_breakpoint (void) | |
6659 | { | |
35df4500 | 6660 | struct breakpoint *b, *b_tmp; |
aa7d318d | 6661 | |
35df4500 | 6662 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
6663 | if (b->pspace == current_program_space |
6664 | && b->type == bp_std_terminate_master) | |
6665 | { | |
06edf0c0 PA |
6666 | momentary_breakpoint_from_master (b, bp_std_terminate, |
6667 | &momentary_breakpoint_ops); | |
aa7d318d TT |
6668 | } |
6669 | } | |
6670 | ||
6671 | /* Delete all the std::terminate breakpoints. */ | |
6672 | void | |
6673 | delete_std_terminate_breakpoint (void) | |
6674 | { | |
35df4500 | 6675 | struct breakpoint *b, *b_tmp; |
aa7d318d | 6676 | |
35df4500 | 6677 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
6678 | if (b->type == bp_std_terminate) |
6679 | delete_breakpoint (b); | |
6680 | } | |
6681 | ||
c4093a6a | 6682 | struct breakpoint * |
a6d9a66e | 6683 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
6684 | { |
6685 | struct breakpoint *b; | |
c4093a6a | 6686 | |
06edf0c0 PA |
6687 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
6688 | &internal_breakpoint_ops); | |
6689 | ||
b5de0fa7 | 6690 | b->enable_state = bp_enabled; |
c4093a6a | 6691 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
6692 | b->addr_string |
6693 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 6694 | |
b60e7edf | 6695 | update_global_location_list_nothrow (1); |
74960c60 | 6696 | |
c4093a6a JM |
6697 | return b; |
6698 | } | |
6699 | ||
6700 | void | |
6701 | remove_thread_event_breakpoints (void) | |
6702 | { | |
35df4500 | 6703 | struct breakpoint *b, *b_tmp; |
c4093a6a | 6704 | |
35df4500 | 6705 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
6706 | if (b->type == bp_thread_event |
6707 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
6708 | delete_breakpoint (b); |
6709 | } | |
6710 | ||
0101ce28 JJ |
6711 | struct lang_and_radix |
6712 | { | |
6713 | enum language lang; | |
6714 | int radix; | |
6715 | }; | |
6716 | ||
4efc6507 DE |
6717 | /* Create a breakpoint for JIT code registration and unregistration. */ |
6718 | ||
6719 | struct breakpoint * | |
6720 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
6721 | { | |
6722 | struct breakpoint *b; | |
6723 | ||
06edf0c0 PA |
6724 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event, |
6725 | &internal_breakpoint_ops); | |
4efc6507 DE |
6726 | update_global_location_list_nothrow (1); |
6727 | return b; | |
6728 | } | |
0101ce28 | 6729 | |
03673fc7 PP |
6730 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
6731 | ||
6732 | void | |
6733 | remove_jit_event_breakpoints (void) | |
6734 | { | |
6735 | struct breakpoint *b, *b_tmp; | |
6736 | ||
6737 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
6738 | if (b->type == bp_jit_event | |
6739 | && b->loc->pspace == current_program_space) | |
6740 | delete_breakpoint (b); | |
6741 | } | |
6742 | ||
cae688ec JJ |
6743 | void |
6744 | remove_solib_event_breakpoints (void) | |
6745 | { | |
35df4500 | 6746 | struct breakpoint *b, *b_tmp; |
cae688ec | 6747 | |
35df4500 | 6748 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
6749 | if (b->type == bp_shlib_event |
6750 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
6751 | delete_breakpoint (b); |
6752 | } | |
6753 | ||
6754 | struct breakpoint * | |
a6d9a66e | 6755 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
cae688ec JJ |
6756 | { |
6757 | struct breakpoint *b; | |
6758 | ||
06edf0c0 PA |
6759 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
6760 | &internal_breakpoint_ops); | |
b60e7edf | 6761 | update_global_location_list_nothrow (1); |
cae688ec JJ |
6762 | return b; |
6763 | } | |
6764 | ||
6765 | /* Disable any breakpoints that are on code in shared libraries. Only | |
6766 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
6767 | ||
6768 | void | |
cb851954 | 6769 | disable_breakpoints_in_shlibs (void) |
cae688ec | 6770 | { |
876fa593 | 6771 | struct bp_location *loc, **locp_tmp; |
cae688ec | 6772 | |
876fa593 | 6773 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 6774 | { |
2bdf28a0 | 6775 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 6776 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 6777 | |
4a64f543 MS |
6778 | /* We apply the check to all breakpoints, including disabled for |
6779 | those with loc->duplicate set. This is so that when breakpoint | |
6780 | becomes enabled, or the duplicate is removed, gdb will try to | |
6781 | insert all breakpoints. If we don't set shlib_disabled here, | |
6782 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 6783 | if (((b->type == bp_breakpoint) |
508ccb1f | 6784 | || (b->type == bp_jit_event) |
1042e4c0 | 6785 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 6786 | || (is_tracepoint (b))) |
6c95b8df | 6787 | && loc->pspace == current_program_space |
0d381245 | 6788 | && !loc->shlib_disabled |
a77053c2 | 6789 | #ifdef PC_SOLIB |
0d381245 | 6790 | && PC_SOLIB (loc->address) |
a77053c2 | 6791 | #else |
6c95b8df | 6792 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 MK |
6793 | #endif |
6794 | ) | |
0d381245 VP |
6795 | { |
6796 | loc->shlib_disabled = 1; | |
6797 | } | |
cae688ec JJ |
6798 | } |
6799 | } | |
6800 | ||
1e4d1764 YQ |
6801 | /* Disable any breakpoints and tracepoints that are in an unloaded shared |
6802 | library. Only apply to enabled breakpoints, disabled ones can just stay | |
4a64f543 | 6803 | disabled. */ |
84acb35a | 6804 | |
75149521 | 6805 | static void |
84acb35a JJ |
6806 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
6807 | { | |
876fa593 | 6808 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
6809 | int disabled_shlib_breaks = 0; |
6810 | ||
c86cf029 VP |
6811 | /* SunOS a.out shared libraries are always mapped, so do not |
6812 | disable breakpoints; they will only be reported as unloaded | |
6813 | through clear_solib when GDB discards its shared library | |
6814 | list. See clear_solib for more information. */ | |
6815 | if (exec_bfd != NULL | |
6816 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
6817 | return; | |
6818 | ||
876fa593 | 6819 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 6820 | { |
2bdf28a0 | 6821 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 6822 | struct breakpoint *b = loc->owner; |
cc59ec59 | 6823 | |
1e4d1764 | 6824 | if (solib->pspace == loc->pspace |
e2dd7057 | 6825 | && !loc->shlib_disabled |
1e4d1764 YQ |
6826 | && (((b->type == bp_breakpoint |
6827 | || b->type == bp_jit_event | |
6828 | || b->type == bp_hardware_breakpoint) | |
6829 | && (loc->loc_type == bp_loc_hardware_breakpoint | |
6830 | || loc->loc_type == bp_loc_software_breakpoint)) | |
6831 | || is_tracepoint (b)) | |
e2dd7057 | 6832 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 6833 | { |
e2dd7057 PP |
6834 | loc->shlib_disabled = 1; |
6835 | /* At this point, we cannot rely on remove_breakpoint | |
6836 | succeeding so we must mark the breakpoint as not inserted | |
6837 | to prevent future errors occurring in remove_breakpoints. */ | |
6838 | loc->inserted = 0; | |
8d3788bd VP |
6839 | |
6840 | /* This may cause duplicate notifications for the same breakpoint. */ | |
6841 | observer_notify_breakpoint_modified (b); | |
6842 | ||
e2dd7057 PP |
6843 | if (!disabled_shlib_breaks) |
6844 | { | |
6845 | target_terminal_ours_for_output (); | |
3e43a32a MS |
6846 | warning (_("Temporarily disabling breakpoints " |
6847 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 6848 | solib->so_name); |
84acb35a | 6849 | } |
e2dd7057 | 6850 | disabled_shlib_breaks = 1; |
84acb35a JJ |
6851 | } |
6852 | } | |
84acb35a JJ |
6853 | } |
6854 | ||
ce78b96d JB |
6855 | /* FORK & VFORK catchpoints. */ |
6856 | ||
e29a4733 PA |
6857 | /* An instance of this type is used to represent a fork or vfork |
6858 | catchpoint. It includes a "struct breakpoint" as a kind of base | |
6859 | class; users downcast to "struct breakpoint *" when needed. A | |
6860 | breakpoint is really of this type iff its ops pointer points to | |
6861 | CATCH_FORK_BREAKPOINT_OPS. */ | |
6862 | ||
6863 | struct fork_catchpoint | |
6864 | { | |
6865 | /* The base class. */ | |
6866 | struct breakpoint base; | |
6867 | ||
6868 | /* Process id of a child process whose forking triggered this | |
6869 | catchpoint. This field is only valid immediately after this | |
6870 | catchpoint has triggered. */ | |
6871 | ptid_t forked_inferior_pid; | |
6872 | }; | |
6873 | ||
4a64f543 MS |
6874 | /* Implement the "insert" breakpoint_ops method for fork |
6875 | catchpoints. */ | |
ce78b96d | 6876 | |
77b06cd7 TJB |
6877 | static int |
6878 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 6879 | { |
77b06cd7 | 6880 | return target_insert_fork_catchpoint (PIDGET (inferior_ptid)); |
ce78b96d JB |
6881 | } |
6882 | ||
4a64f543 MS |
6883 | /* Implement the "remove" breakpoint_ops method for fork |
6884 | catchpoints. */ | |
ce78b96d JB |
6885 | |
6886 | static int | |
77b06cd7 | 6887 | remove_catch_fork (struct bp_location *bl) |
ce78b96d JB |
6888 | { |
6889 | return target_remove_fork_catchpoint (PIDGET (inferior_ptid)); | |
6890 | } | |
6891 | ||
6892 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
6893 | catchpoints. */ | |
6894 | ||
6895 | static int | |
f1310107 | 6896 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
09ac7c10 TT |
6897 | struct address_space *aspace, CORE_ADDR bp_addr, |
6898 | const struct target_waitstatus *ws) | |
ce78b96d | 6899 | { |
e29a4733 PA |
6900 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
6901 | ||
f90263c1 TT |
6902 | if (ws->kind != TARGET_WAITKIND_FORKED) |
6903 | return 0; | |
6904 | ||
6905 | c->forked_inferior_pid = ws->value.related_pid; | |
6906 | return 1; | |
ce78b96d JB |
6907 | } |
6908 | ||
4a64f543 MS |
6909 | /* Implement the "print_it" breakpoint_ops method for fork |
6910 | catchpoints. */ | |
ce78b96d JB |
6911 | |
6912 | static enum print_stop_action | |
348d480f | 6913 | print_it_catch_fork (bpstat bs) |
ce78b96d | 6914 | { |
36dfb11c | 6915 | struct ui_out *uiout = current_uiout; |
348d480f PA |
6916 | struct breakpoint *b = bs->breakpoint_at; |
6917 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; | |
e29a4733 | 6918 | |
ce78b96d | 6919 | annotate_catchpoint (b->number); |
36dfb11c TT |
6920 | if (b->disposition == disp_del) |
6921 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
6922 | else | |
6923 | ui_out_text (uiout, "\nCatchpoint "); | |
6924 | if (ui_out_is_mi_like_p (uiout)) | |
6925 | { | |
6926 | ui_out_field_string (uiout, "reason", | |
6927 | async_reason_lookup (EXEC_ASYNC_FORK)); | |
6928 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
6929 | } | |
6930 | ui_out_field_int (uiout, "bkptno", b->number); | |
6931 | ui_out_text (uiout, " (forked process "); | |
6932 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
6933 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
6934 | return PRINT_SRC_AND_LOC; |
6935 | } | |
6936 | ||
4a64f543 MS |
6937 | /* Implement the "print_one" breakpoint_ops method for fork |
6938 | catchpoints. */ | |
ce78b96d JB |
6939 | |
6940 | static void | |
a6d9a66e | 6941 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 6942 | { |
e29a4733 | 6943 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 6944 | struct value_print_options opts; |
79a45e25 | 6945 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
6946 | |
6947 | get_user_print_options (&opts); | |
6948 | ||
4a64f543 MS |
6949 | /* Field 4, the address, is omitted (which makes the columns not |
6950 | line up too nicely with the headers, but the effect is relatively | |
6951 | readable). */ | |
79a45b7d | 6952 | if (opts.addressprint) |
ce78b96d JB |
6953 | ui_out_field_skip (uiout, "addr"); |
6954 | annotate_field (5); | |
6955 | ui_out_text (uiout, "fork"); | |
e29a4733 | 6956 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
6957 | { |
6958 | ui_out_text (uiout, ", process "); | |
6959 | ui_out_field_int (uiout, "what", | |
e29a4733 | 6960 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
6961 | ui_out_spaces (uiout, 1); |
6962 | } | |
6963 | } | |
6964 | ||
6965 | /* Implement the "print_mention" breakpoint_ops method for fork | |
6966 | catchpoints. */ | |
6967 | ||
6968 | static void | |
6969 | print_mention_catch_fork (struct breakpoint *b) | |
6970 | { | |
6971 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
6972 | } | |
6973 | ||
6149aea9 PA |
6974 | /* Implement the "print_recreate" breakpoint_ops method for fork |
6975 | catchpoints. */ | |
6976 | ||
6977 | static void | |
6978 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
6979 | { | |
6980 | fprintf_unfiltered (fp, "catch fork"); | |
d9b3f62e | 6981 | print_recreate_thread (b, fp); |
6149aea9 PA |
6982 | } |
6983 | ||
ce78b96d JB |
6984 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
6985 | ||
2060206e | 6986 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
ce78b96d | 6987 | |
4a64f543 MS |
6988 | /* Implement the "insert" breakpoint_ops method for vfork |
6989 | catchpoints. */ | |
ce78b96d | 6990 | |
77b06cd7 TJB |
6991 | static int |
6992 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 6993 | { |
77b06cd7 | 6994 | return target_insert_vfork_catchpoint (PIDGET (inferior_ptid)); |
ce78b96d JB |
6995 | } |
6996 | ||
4a64f543 MS |
6997 | /* Implement the "remove" breakpoint_ops method for vfork |
6998 | catchpoints. */ | |
ce78b96d JB |
6999 | |
7000 | static int | |
77b06cd7 | 7001 | remove_catch_vfork (struct bp_location *bl) |
ce78b96d JB |
7002 | { |
7003 | return target_remove_vfork_catchpoint (PIDGET (inferior_ptid)); | |
7004 | } | |
7005 | ||
7006 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
7007 | catchpoints. */ | |
7008 | ||
7009 | static int | |
f1310107 | 7010 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
09ac7c10 TT |
7011 | struct address_space *aspace, CORE_ADDR bp_addr, |
7012 | const struct target_waitstatus *ws) | |
ce78b96d | 7013 | { |
e29a4733 PA |
7014 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
7015 | ||
f90263c1 TT |
7016 | if (ws->kind != TARGET_WAITKIND_VFORKED) |
7017 | return 0; | |
7018 | ||
7019 | c->forked_inferior_pid = ws->value.related_pid; | |
7020 | return 1; | |
ce78b96d JB |
7021 | } |
7022 | ||
4a64f543 MS |
7023 | /* Implement the "print_it" breakpoint_ops method for vfork |
7024 | catchpoints. */ | |
ce78b96d JB |
7025 | |
7026 | static enum print_stop_action | |
348d480f | 7027 | print_it_catch_vfork (bpstat bs) |
ce78b96d | 7028 | { |
36dfb11c | 7029 | struct ui_out *uiout = current_uiout; |
348d480f | 7030 | struct breakpoint *b = bs->breakpoint_at; |
e29a4733 PA |
7031 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
7032 | ||
ce78b96d | 7033 | annotate_catchpoint (b->number); |
36dfb11c TT |
7034 | if (b->disposition == disp_del) |
7035 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
7036 | else | |
7037 | ui_out_text (uiout, "\nCatchpoint "); | |
7038 | if (ui_out_is_mi_like_p (uiout)) | |
7039 | { | |
7040 | ui_out_field_string (uiout, "reason", | |
7041 | async_reason_lookup (EXEC_ASYNC_VFORK)); | |
7042 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
7043 | } | |
7044 | ui_out_field_int (uiout, "bkptno", b->number); | |
7045 | ui_out_text (uiout, " (vforked process "); | |
7046 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
7047 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
7048 | return PRINT_SRC_AND_LOC; |
7049 | } | |
7050 | ||
4a64f543 MS |
7051 | /* Implement the "print_one" breakpoint_ops method for vfork |
7052 | catchpoints. */ | |
ce78b96d JB |
7053 | |
7054 | static void | |
a6d9a66e | 7055 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 7056 | { |
e29a4733 | 7057 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 7058 | struct value_print_options opts; |
79a45e25 | 7059 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
7060 | |
7061 | get_user_print_options (&opts); | |
4a64f543 MS |
7062 | /* Field 4, the address, is omitted (which makes the columns not |
7063 | line up too nicely with the headers, but the effect is relatively | |
7064 | readable). */ | |
79a45b7d | 7065 | if (opts.addressprint) |
ce78b96d JB |
7066 | ui_out_field_skip (uiout, "addr"); |
7067 | annotate_field (5); | |
7068 | ui_out_text (uiout, "vfork"); | |
e29a4733 | 7069 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
7070 | { |
7071 | ui_out_text (uiout, ", process "); | |
7072 | ui_out_field_int (uiout, "what", | |
e29a4733 | 7073 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
7074 | ui_out_spaces (uiout, 1); |
7075 | } | |
7076 | } | |
7077 | ||
7078 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
7079 | catchpoints. */ | |
7080 | ||
7081 | static void | |
7082 | print_mention_catch_vfork (struct breakpoint *b) | |
7083 | { | |
7084 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
7085 | } | |
7086 | ||
6149aea9 PA |
7087 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
7088 | catchpoints. */ | |
7089 | ||
7090 | static void | |
7091 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
7092 | { | |
7093 | fprintf_unfiltered (fp, "catch vfork"); | |
d9b3f62e | 7094 | print_recreate_thread (b, fp); |
6149aea9 PA |
7095 | } |
7096 | ||
ce78b96d JB |
7097 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
7098 | ||
2060206e | 7099 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
ce78b96d | 7100 | |
edcc5120 TT |
7101 | /* An instance of this type is used to represent an solib catchpoint. |
7102 | It includes a "struct breakpoint" as a kind of base class; users | |
7103 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
7104 | really of this type iff its ops pointer points to | |
7105 | CATCH_SOLIB_BREAKPOINT_OPS. */ | |
7106 | ||
7107 | struct solib_catchpoint | |
7108 | { | |
7109 | /* The base class. */ | |
7110 | struct breakpoint base; | |
7111 | ||
7112 | /* True for "catch load", false for "catch unload". */ | |
7113 | unsigned char is_load; | |
7114 | ||
7115 | /* Regular expression to match, if any. COMPILED is only valid when | |
7116 | REGEX is non-NULL. */ | |
7117 | char *regex; | |
7118 | regex_t compiled; | |
7119 | }; | |
7120 | ||
7121 | static void | |
7122 | dtor_catch_solib (struct breakpoint *b) | |
7123 | { | |
7124 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
7125 | ||
7126 | if (self->regex) | |
7127 | regfree (&self->compiled); | |
7128 | xfree (self->regex); | |
7129 | ||
7130 | base_breakpoint_ops.dtor (b); | |
7131 | } | |
7132 | ||
7133 | static int | |
7134 | insert_catch_solib (struct bp_location *ignore) | |
7135 | { | |
7136 | return 0; | |
7137 | } | |
7138 | ||
7139 | static int | |
7140 | remove_catch_solib (struct bp_location *ignore) | |
7141 | { | |
7142 | return 0; | |
7143 | } | |
7144 | ||
7145 | static int | |
7146 | breakpoint_hit_catch_solib (const struct bp_location *bl, | |
7147 | struct address_space *aspace, | |
7148 | CORE_ADDR bp_addr, | |
7149 | const struct target_waitstatus *ws) | |
7150 | { | |
7151 | struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner; | |
7152 | struct breakpoint *other; | |
7153 | ||
7154 | if (ws->kind == TARGET_WAITKIND_LOADED) | |
7155 | return 1; | |
7156 | ||
7157 | ALL_BREAKPOINTS (other) | |
7158 | { | |
7159 | struct bp_location *other_bl; | |
7160 | ||
7161 | if (other == bl->owner) | |
7162 | continue; | |
7163 | ||
7164 | if (other->type != bp_shlib_event) | |
7165 | continue; | |
7166 | ||
7167 | if (self->base.pspace != NULL && other->pspace != self->base.pspace) | |
7168 | continue; | |
7169 | ||
7170 | for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next) | |
7171 | { | |
7172 | if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) | |
7173 | return 1; | |
7174 | } | |
7175 | } | |
7176 | ||
7177 | return 0; | |
7178 | } | |
7179 | ||
7180 | static void | |
7181 | check_status_catch_solib (struct bpstats *bs) | |
7182 | { | |
7183 | struct solib_catchpoint *self | |
7184 | = (struct solib_catchpoint *) bs->breakpoint_at; | |
7185 | int ix; | |
7186 | ||
7187 | if (self->is_load) | |
7188 | { | |
7189 | struct so_list *iter; | |
7190 | ||
7191 | for (ix = 0; | |
7192 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
7193 | ix, iter); | |
7194 | ++ix) | |
7195 | { | |
7196 | if (!self->regex | |
7197 | || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0) | |
7198 | return; | |
7199 | } | |
7200 | } | |
7201 | else | |
7202 | { | |
7203 | char *iter; | |
7204 | ||
7205 | for (ix = 0; | |
7206 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
7207 | ix, iter); | |
7208 | ++ix) | |
7209 | { | |
7210 | if (!self->regex | |
7211 | || regexec (&self->compiled, iter, 0, NULL, 0) == 0) | |
7212 | return; | |
7213 | } | |
7214 | } | |
7215 | ||
7216 | bs->stop = 0; | |
7217 | bs->print_it = print_it_noop; | |
7218 | } | |
7219 | ||
7220 | static enum print_stop_action | |
7221 | print_it_catch_solib (bpstat bs) | |
7222 | { | |
7223 | struct breakpoint *b = bs->breakpoint_at; | |
7224 | struct ui_out *uiout = current_uiout; | |
7225 | ||
7226 | annotate_catchpoint (b->number); | |
7227 | if (b->disposition == disp_del) | |
7228 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
7229 | else | |
7230 | ui_out_text (uiout, "\nCatchpoint "); | |
7231 | ui_out_field_int (uiout, "bkptno", b->number); | |
7232 | ui_out_text (uiout, "\n"); | |
7233 | if (ui_out_is_mi_like_p (uiout)) | |
7234 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
7235 | print_solib_event (1); | |
7236 | return PRINT_SRC_AND_LOC; | |
7237 | } | |
7238 | ||
7239 | static void | |
7240 | print_one_catch_solib (struct breakpoint *b, struct bp_location **locs) | |
7241 | { | |
7242 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
7243 | struct value_print_options opts; | |
7244 | struct ui_out *uiout = current_uiout; | |
7245 | char *msg; | |
7246 | ||
7247 | get_user_print_options (&opts); | |
7248 | /* Field 4, the address, is omitted (which makes the columns not | |
7249 | line up too nicely with the headers, but the effect is relatively | |
7250 | readable). */ | |
7251 | if (opts.addressprint) | |
7252 | { | |
7253 | annotate_field (4); | |
7254 | ui_out_field_skip (uiout, "addr"); | |
7255 | } | |
7256 | ||
7257 | annotate_field (5); | |
7258 | if (self->is_load) | |
7259 | { | |
7260 | if (self->regex) | |
7261 | msg = xstrprintf (_("load of library matching %s"), self->regex); | |
7262 | else | |
7263 | msg = xstrdup (_("load of library")); | |
7264 | } | |
7265 | else | |
7266 | { | |
7267 | if (self->regex) | |
7268 | msg = xstrprintf (_("unload of library matching %s"), self->regex); | |
7269 | else | |
7270 | msg = xstrdup (_("unload of library")); | |
7271 | } | |
7272 | ui_out_field_string (uiout, "what", msg); | |
7273 | xfree (msg); | |
7274 | } | |
7275 | ||
7276 | static void | |
7277 | print_mention_catch_solib (struct breakpoint *b) | |
7278 | { | |
7279 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
7280 | ||
7281 | printf_filtered (_("Catchpoint %d (%s)"), b->number, | |
7282 | self->is_load ? "load" : "unload"); | |
7283 | } | |
7284 | ||
7285 | static void | |
7286 | print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp) | |
7287 | { | |
7288 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
7289 | ||
7290 | fprintf_unfiltered (fp, "%s %s", | |
7291 | b->disposition == disp_del ? "tcatch" : "catch", | |
7292 | self->is_load ? "load" : "unload"); | |
7293 | if (self->regex) | |
7294 | fprintf_unfiltered (fp, " %s", self->regex); | |
7295 | fprintf_unfiltered (fp, "\n"); | |
7296 | } | |
7297 | ||
7298 | static struct breakpoint_ops catch_solib_breakpoint_ops; | |
7299 | ||
7300 | /* A helper function that does all the work for "catch load" and | |
7301 | "catch unload". */ | |
7302 | ||
7303 | static void | |
7304 | catch_load_or_unload (char *arg, int from_tty, int is_load, | |
7305 | struct cmd_list_element *command) | |
7306 | { | |
7307 | struct solib_catchpoint *c; | |
7308 | struct gdbarch *gdbarch = get_current_arch (); | |
7309 | int tempflag; | |
7310 | regex_t compiled; | |
7311 | struct cleanup *cleanup; | |
7312 | ||
7313 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
7314 | ||
7315 | if (!arg) | |
7316 | arg = ""; | |
7317 | arg = skip_spaces (arg); | |
7318 | ||
7319 | c = XCNEW (struct solib_catchpoint); | |
7320 | cleanup = make_cleanup (xfree, c); | |
7321 | ||
7322 | if (*arg != '\0') | |
7323 | { | |
7324 | int errcode; | |
7325 | ||
7326 | errcode = regcomp (&c->compiled, arg, REG_NOSUB); | |
7327 | if (errcode != 0) | |
7328 | { | |
7329 | char *err = get_regcomp_error (errcode, &c->compiled); | |
7330 | ||
7331 | make_cleanup (xfree, err); | |
7332 | error (_("Invalid regexp (%s): %s"), err, arg); | |
7333 | } | |
7334 | c->regex = xstrdup (arg); | |
7335 | } | |
7336 | ||
7337 | c->is_load = is_load; | |
7338 | init_catchpoint (&c->base, gdbarch, tempflag, NULL, | |
7339 | &catch_solib_breakpoint_ops); | |
7340 | ||
7341 | discard_cleanups (cleanup); | |
7342 | install_breakpoint (0, &c->base, 1); | |
7343 | } | |
7344 | ||
7345 | static void | |
7346 | catch_load_command_1 (char *arg, int from_tty, | |
7347 | struct cmd_list_element *command) | |
7348 | { | |
7349 | catch_load_or_unload (arg, from_tty, 1, command); | |
7350 | } | |
7351 | ||
7352 | static void | |
7353 | catch_unload_command_1 (char *arg, int from_tty, | |
7354 | struct cmd_list_element *command) | |
7355 | { | |
7356 | catch_load_or_unload (arg, from_tty, 0, command); | |
7357 | } | |
7358 | ||
be5c67c1 PA |
7359 | /* An instance of this type is used to represent a syscall catchpoint. |
7360 | It includes a "struct breakpoint" as a kind of base class; users | |
7361 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
7362 | really of this type iff its ops pointer points to | |
7363 | CATCH_SYSCALL_BREAKPOINT_OPS. */ | |
7364 | ||
7365 | struct syscall_catchpoint | |
7366 | { | |
7367 | /* The base class. */ | |
7368 | struct breakpoint base; | |
7369 | ||
7370 | /* Syscall numbers used for the 'catch syscall' feature. If no | |
7371 | syscall has been specified for filtering, its value is NULL. | |
7372 | Otherwise, it holds a list of all syscalls to be caught. The | |
7373 | list elements are allocated with xmalloc. */ | |
7374 | VEC(int) *syscalls_to_be_caught; | |
7375 | }; | |
7376 | ||
7377 | /* Implement the "dtor" breakpoint_ops method for syscall | |
7378 | catchpoints. */ | |
7379 | ||
7380 | static void | |
7381 | dtor_catch_syscall (struct breakpoint *b) | |
7382 | { | |
7383 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; | |
7384 | ||
7385 | VEC_free (int, c->syscalls_to_be_caught); | |
348d480f | 7386 | |
2060206e | 7387 | base_breakpoint_ops.dtor (b); |
be5c67c1 PA |
7388 | } |
7389 | ||
a96d9b2e SDJ |
7390 | /* Implement the "insert" breakpoint_ops method for syscall |
7391 | catchpoints. */ | |
7392 | ||
77b06cd7 TJB |
7393 | static int |
7394 | insert_catch_syscall (struct bp_location *bl) | |
a96d9b2e | 7395 | { |
be5c67c1 | 7396 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; |
a96d9b2e SDJ |
7397 | struct inferior *inf = current_inferior (); |
7398 | ||
7399 | ++inf->total_syscalls_count; | |
be5c67c1 | 7400 | if (!c->syscalls_to_be_caught) |
a96d9b2e SDJ |
7401 | ++inf->any_syscall_count; |
7402 | else | |
7403 | { | |
7404 | int i, iter; | |
cc59ec59 | 7405 | |
a96d9b2e | 7406 | for (i = 0; |
be5c67c1 | 7407 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
7408 | i++) |
7409 | { | |
7410 | int elem; | |
cc59ec59 | 7411 | |
a96d9b2e SDJ |
7412 | if (iter >= VEC_length (int, inf->syscalls_counts)) |
7413 | { | |
7414 | int old_size = VEC_length (int, inf->syscalls_counts); | |
3e43a32a MS |
7415 | uintptr_t vec_addr_offset |
7416 | = old_size * ((uintptr_t) sizeof (int)); | |
a96d9b2e SDJ |
7417 | uintptr_t vec_addr; |
7418 | VEC_safe_grow (int, inf->syscalls_counts, iter + 1); | |
7419 | vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) + | |
7420 | vec_addr_offset; | |
7421 | memset ((void *) vec_addr, 0, | |
7422 | (iter + 1 - old_size) * sizeof (int)); | |
7423 | } | |
7424 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
7425 | VEC_replace (int, inf->syscalls_counts, iter, ++elem); | |
7426 | } | |
7427 | } | |
7428 | ||
77b06cd7 TJB |
7429 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), |
7430 | inf->total_syscalls_count != 0, | |
7431 | inf->any_syscall_count, | |
7432 | VEC_length (int, inf->syscalls_counts), | |
7433 | VEC_address (int, inf->syscalls_counts)); | |
a96d9b2e SDJ |
7434 | } |
7435 | ||
7436 | /* Implement the "remove" breakpoint_ops method for syscall | |
7437 | catchpoints. */ | |
7438 | ||
7439 | static int | |
77b06cd7 | 7440 | remove_catch_syscall (struct bp_location *bl) |
a96d9b2e | 7441 | { |
be5c67c1 | 7442 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; |
a96d9b2e SDJ |
7443 | struct inferior *inf = current_inferior (); |
7444 | ||
7445 | --inf->total_syscalls_count; | |
be5c67c1 | 7446 | if (!c->syscalls_to_be_caught) |
a96d9b2e SDJ |
7447 | --inf->any_syscall_count; |
7448 | else | |
7449 | { | |
7450 | int i, iter; | |
cc59ec59 | 7451 | |
a96d9b2e | 7452 | for (i = 0; |
be5c67c1 | 7453 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
7454 | i++) |
7455 | { | |
7456 | int elem; | |
7457 | if (iter >= VEC_length (int, inf->syscalls_counts)) | |
7458 | /* Shouldn't happen. */ | |
7459 | continue; | |
7460 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
7461 | VEC_replace (int, inf->syscalls_counts, iter, --elem); | |
7462 | } | |
7463 | } | |
7464 | ||
7465 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
7466 | inf->total_syscalls_count != 0, | |
7467 | inf->any_syscall_count, | |
7468 | VEC_length (int, inf->syscalls_counts), | |
3e43a32a MS |
7469 | VEC_address (int, |
7470 | inf->syscalls_counts)); | |
a96d9b2e SDJ |
7471 | } |
7472 | ||
7473 | /* Implement the "breakpoint_hit" breakpoint_ops method for syscall | |
7474 | catchpoints. */ | |
7475 | ||
7476 | static int | |
f1310107 | 7477 | breakpoint_hit_catch_syscall (const struct bp_location *bl, |
09ac7c10 TT |
7478 | struct address_space *aspace, CORE_ADDR bp_addr, |
7479 | const struct target_waitstatus *ws) | |
a96d9b2e | 7480 | { |
4a64f543 MS |
7481 | /* We must check if we are catching specific syscalls in this |
7482 | breakpoint. If we are, then we must guarantee that the called | |
7483 | syscall is the same syscall we are catching. */ | |
a96d9b2e | 7484 | int syscall_number = 0; |
be5c67c1 PA |
7485 | const struct syscall_catchpoint *c |
7486 | = (const struct syscall_catchpoint *) bl->owner; | |
a96d9b2e | 7487 | |
f90263c1 TT |
7488 | if (ws->kind != TARGET_WAITKIND_SYSCALL_ENTRY |
7489 | && ws->kind != TARGET_WAITKIND_SYSCALL_RETURN) | |
a96d9b2e SDJ |
7490 | return 0; |
7491 | ||
f90263c1 TT |
7492 | syscall_number = ws->value.syscall_number; |
7493 | ||
a96d9b2e | 7494 | /* Now, checking if the syscall is the same. */ |
be5c67c1 | 7495 | if (c->syscalls_to_be_caught) |
a96d9b2e SDJ |
7496 | { |
7497 | int i, iter; | |
cc59ec59 | 7498 | |
a96d9b2e | 7499 | for (i = 0; |
be5c67c1 | 7500 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
7501 | i++) |
7502 | if (syscall_number == iter) | |
7503 | break; | |
7504 | /* Not the same. */ | |
7505 | if (!iter) | |
7506 | return 0; | |
7507 | } | |
7508 | ||
7509 | return 1; | |
7510 | } | |
7511 | ||
7512 | /* Implement the "print_it" breakpoint_ops method for syscall | |
7513 | catchpoints. */ | |
7514 | ||
7515 | static enum print_stop_action | |
348d480f | 7516 | print_it_catch_syscall (bpstat bs) |
a96d9b2e | 7517 | { |
36dfb11c | 7518 | struct ui_out *uiout = current_uiout; |
348d480f | 7519 | struct breakpoint *b = bs->breakpoint_at; |
a96d9b2e SDJ |
7520 | /* These are needed because we want to know in which state a |
7521 | syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY | |
7522 | or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we | |
7523 | must print "called syscall" or "returned from syscall". */ | |
7524 | ptid_t ptid; | |
7525 | struct target_waitstatus last; | |
7526 | struct syscall s; | |
a96d9b2e SDJ |
7527 | char *syscall_id; |
7528 | ||
7529 | get_last_target_status (&ptid, &last); | |
7530 | ||
7531 | get_syscall_by_number (last.value.syscall_number, &s); | |
7532 | ||
7533 | annotate_catchpoint (b->number); | |
7534 | ||
36dfb11c TT |
7535 | if (b->disposition == disp_del) |
7536 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
a96d9b2e | 7537 | else |
36dfb11c TT |
7538 | ui_out_text (uiout, "\nCatchpoint "); |
7539 | if (ui_out_is_mi_like_p (uiout)) | |
7540 | { | |
7541 | ui_out_field_string (uiout, "reason", | |
7542 | async_reason_lookup (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY | |
7543 | ? EXEC_ASYNC_SYSCALL_ENTRY | |
7544 | : EXEC_ASYNC_SYSCALL_RETURN)); | |
7545 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
7546 | } | |
7547 | ui_out_field_int (uiout, "bkptno", b->number); | |
a96d9b2e SDJ |
7548 | |
7549 | if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) | |
36dfb11c TT |
7550 | ui_out_text (uiout, " (call to syscall "); |
7551 | else | |
7552 | ui_out_text (uiout, " (returned from syscall "); | |
a96d9b2e | 7553 | |
36dfb11c TT |
7554 | if (s.name == NULL || ui_out_is_mi_like_p (uiout)) |
7555 | ui_out_field_int (uiout, "syscall-number", last.value.syscall_number); | |
7556 | if (s.name != NULL) | |
7557 | ui_out_field_string (uiout, "syscall-name", s.name); | |
7558 | ||
7559 | ui_out_text (uiout, "), "); | |
a96d9b2e SDJ |
7560 | |
7561 | return PRINT_SRC_AND_LOC; | |
7562 | } | |
7563 | ||
7564 | /* Implement the "print_one" breakpoint_ops method for syscall | |
7565 | catchpoints. */ | |
7566 | ||
7567 | static void | |
7568 | print_one_catch_syscall (struct breakpoint *b, | |
f1310107 | 7569 | struct bp_location **last_loc) |
a96d9b2e | 7570 | { |
be5c67c1 | 7571 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
a96d9b2e | 7572 | struct value_print_options opts; |
79a45e25 | 7573 | struct ui_out *uiout = current_uiout; |
a96d9b2e SDJ |
7574 | |
7575 | get_user_print_options (&opts); | |
4a64f543 MS |
7576 | /* Field 4, the address, is omitted (which makes the columns not |
7577 | line up too nicely with the headers, but the effect is relatively | |
7578 | readable). */ | |
a96d9b2e SDJ |
7579 | if (opts.addressprint) |
7580 | ui_out_field_skip (uiout, "addr"); | |
7581 | annotate_field (5); | |
7582 | ||
be5c67c1 PA |
7583 | if (c->syscalls_to_be_caught |
7584 | && VEC_length (int, c->syscalls_to_be_caught) > 1) | |
a96d9b2e SDJ |
7585 | ui_out_text (uiout, "syscalls \""); |
7586 | else | |
7587 | ui_out_text (uiout, "syscall \""); | |
7588 | ||
be5c67c1 | 7589 | if (c->syscalls_to_be_caught) |
a96d9b2e SDJ |
7590 | { |
7591 | int i, iter; | |
7592 | char *text = xstrprintf ("%s", ""); | |
cc59ec59 | 7593 | |
a96d9b2e | 7594 | for (i = 0; |
be5c67c1 | 7595 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
7596 | i++) |
7597 | { | |
7598 | char *x = text; | |
7599 | struct syscall s; | |
7600 | get_syscall_by_number (iter, &s); | |
7601 | ||
7602 | if (s.name != NULL) | |
7603 | text = xstrprintf ("%s%s, ", text, s.name); | |
7604 | else | |
7605 | text = xstrprintf ("%s%d, ", text, iter); | |
7606 | ||
7607 | /* We have to xfree the last 'text' (now stored at 'x') | |
e5dd4106 | 7608 | because xstrprintf dynamically allocates new space for it |
a96d9b2e SDJ |
7609 | on every call. */ |
7610 | xfree (x); | |
7611 | } | |
7612 | /* Remove the last comma. */ | |
7613 | text[strlen (text) - 2] = '\0'; | |
7614 | ui_out_field_string (uiout, "what", text); | |
7615 | } | |
7616 | else | |
7617 | ui_out_field_string (uiout, "what", "<any syscall>"); | |
7618 | ui_out_text (uiout, "\" "); | |
7619 | } | |
7620 | ||
7621 | /* Implement the "print_mention" breakpoint_ops method for syscall | |
7622 | catchpoints. */ | |
7623 | ||
7624 | static void | |
7625 | print_mention_catch_syscall (struct breakpoint *b) | |
7626 | { | |
be5c67c1 PA |
7627 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
7628 | ||
7629 | if (c->syscalls_to_be_caught) | |
a96d9b2e SDJ |
7630 | { |
7631 | int i, iter; | |
7632 | ||
be5c67c1 | 7633 | if (VEC_length (int, c->syscalls_to_be_caught) > 1) |
a96d9b2e SDJ |
7634 | printf_filtered (_("Catchpoint %d (syscalls"), b->number); |
7635 | else | |
7636 | printf_filtered (_("Catchpoint %d (syscall"), b->number); | |
7637 | ||
7638 | for (i = 0; | |
be5c67c1 | 7639 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
7640 | i++) |
7641 | { | |
7642 | struct syscall s; | |
7643 | get_syscall_by_number (iter, &s); | |
7644 | ||
7645 | if (s.name) | |
7646 | printf_filtered (" '%s' [%d]", s.name, s.number); | |
7647 | else | |
7648 | printf_filtered (" %d", s.number); | |
7649 | } | |
7650 | printf_filtered (")"); | |
7651 | } | |
7652 | else | |
7653 | printf_filtered (_("Catchpoint %d (any syscall)"), | |
7654 | b->number); | |
7655 | } | |
7656 | ||
6149aea9 PA |
7657 | /* Implement the "print_recreate" breakpoint_ops method for syscall |
7658 | catchpoints. */ | |
7659 | ||
7660 | static void | |
7661 | print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp) | |
7662 | { | |
be5c67c1 PA |
7663 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
7664 | ||
6149aea9 PA |
7665 | fprintf_unfiltered (fp, "catch syscall"); |
7666 | ||
be5c67c1 | 7667 | if (c->syscalls_to_be_caught) |
6149aea9 PA |
7668 | { |
7669 | int i, iter; | |
7670 | ||
7671 | for (i = 0; | |
be5c67c1 | 7672 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
6149aea9 PA |
7673 | i++) |
7674 | { | |
7675 | struct syscall s; | |
7676 | ||
7677 | get_syscall_by_number (iter, &s); | |
7678 | if (s.name) | |
7679 | fprintf_unfiltered (fp, " %s", s.name); | |
7680 | else | |
7681 | fprintf_unfiltered (fp, " %d", s.number); | |
7682 | } | |
7683 | } | |
d9b3f62e | 7684 | print_recreate_thread (b, fp); |
6149aea9 PA |
7685 | } |
7686 | ||
a96d9b2e SDJ |
7687 | /* The breakpoint_ops structure to be used in syscall catchpoints. */ |
7688 | ||
2060206e | 7689 | static struct breakpoint_ops catch_syscall_breakpoint_ops; |
a96d9b2e SDJ |
7690 | |
7691 | /* Returns non-zero if 'b' is a syscall catchpoint. */ | |
7692 | ||
7693 | static int | |
7694 | syscall_catchpoint_p (struct breakpoint *b) | |
7695 | { | |
7696 | return (b->ops == &catch_syscall_breakpoint_ops); | |
7697 | } | |
7698 | ||
346774a9 PA |
7699 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
7700 | is non-zero, then make the breakpoint temporary. If COND_STRING is | |
7701 | not NULL, then store it in the breakpoint. OPS, if not NULL, is | |
7702 | the breakpoint_ops structure associated to the catchpoint. */ | |
ce78b96d | 7703 | |
346774a9 PA |
7704 | static void |
7705 | init_catchpoint (struct breakpoint *b, | |
7706 | struct gdbarch *gdbarch, int tempflag, | |
7707 | char *cond_string, | |
c0a91b2b | 7708 | const struct breakpoint_ops *ops) |
c906108c | 7709 | { |
c5aa993b | 7710 | struct symtab_and_line sal; |
346774a9 | 7711 | |
fe39c653 | 7712 | init_sal (&sal); |
6c95b8df | 7713 | sal.pspace = current_program_space; |
c5aa993b | 7714 | |
28010a5d | 7715 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 7716 | |
1b36a34b | 7717 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
b5de0fa7 | 7718 | b->disposition = tempflag ? disp_del : disp_donttouch; |
346774a9 PA |
7719 | } |
7720 | ||
28010a5d | 7721 | void |
3ea46bff | 7722 | install_breakpoint (int internal, struct breakpoint *b, int update_gll) |
c56053d2 PA |
7723 | { |
7724 | add_to_breakpoint_chain (b); | |
3a5c3e22 PA |
7725 | set_breakpoint_number (internal, b); |
7726 | if (!internal) | |
7727 | mention (b); | |
c56053d2 | 7728 | observer_notify_breakpoint_created (b); |
3ea46bff YQ |
7729 | |
7730 | if (update_gll) | |
7731 | update_global_location_list (1); | |
c56053d2 PA |
7732 | } |
7733 | ||
9b70b993 | 7734 | static void |
a6d9a66e UW |
7735 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
7736 | int tempflag, char *cond_string, | |
c0a91b2b | 7737 | const struct breakpoint_ops *ops) |
c906108c | 7738 | { |
e29a4733 | 7739 | struct fork_catchpoint *c = XNEW (struct fork_catchpoint); |
ce78b96d | 7740 | |
e29a4733 PA |
7741 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops); |
7742 | ||
7743 | c->forked_inferior_pid = null_ptid; | |
7744 | ||
3ea46bff | 7745 | install_breakpoint (0, &c->base, 1); |
c906108c SS |
7746 | } |
7747 | ||
fe798b75 JB |
7748 | /* Exec catchpoints. */ |
7749 | ||
b4d90040 PA |
7750 | /* An instance of this type is used to represent an exec catchpoint. |
7751 | It includes a "struct breakpoint" as a kind of base class; users | |
7752 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
7753 | really of this type iff its ops pointer points to | |
7754 | CATCH_EXEC_BREAKPOINT_OPS. */ | |
7755 | ||
7756 | struct exec_catchpoint | |
7757 | { | |
7758 | /* The base class. */ | |
7759 | struct breakpoint base; | |
7760 | ||
7761 | /* Filename of a program whose exec triggered this catchpoint. | |
7762 | This field is only valid immediately after this catchpoint has | |
7763 | triggered. */ | |
7764 | char *exec_pathname; | |
7765 | }; | |
7766 | ||
7767 | /* Implement the "dtor" breakpoint_ops method for exec | |
7768 | catchpoints. */ | |
7769 | ||
7770 | static void | |
7771 | dtor_catch_exec (struct breakpoint *b) | |
7772 | { | |
7773 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; | |
7774 | ||
7775 | xfree (c->exec_pathname); | |
348d480f | 7776 | |
2060206e | 7777 | base_breakpoint_ops.dtor (b); |
b4d90040 PA |
7778 | } |
7779 | ||
77b06cd7 TJB |
7780 | static int |
7781 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 7782 | { |
77b06cd7 | 7783 | return target_insert_exec_catchpoint (PIDGET (inferior_ptid)); |
fe798b75 | 7784 | } |
c906108c | 7785 | |
fe798b75 | 7786 | static int |
77b06cd7 | 7787 | remove_catch_exec (struct bp_location *bl) |
fe798b75 JB |
7788 | { |
7789 | return target_remove_exec_catchpoint (PIDGET (inferior_ptid)); | |
7790 | } | |
c906108c | 7791 | |
fe798b75 | 7792 | static int |
f1310107 | 7793 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
09ac7c10 TT |
7794 | struct address_space *aspace, CORE_ADDR bp_addr, |
7795 | const struct target_waitstatus *ws) | |
fe798b75 | 7796 | { |
b4d90040 PA |
7797 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
7798 | ||
f90263c1 TT |
7799 | if (ws->kind != TARGET_WAITKIND_EXECD) |
7800 | return 0; | |
7801 | ||
7802 | c->exec_pathname = xstrdup (ws->value.execd_pathname); | |
7803 | return 1; | |
fe798b75 | 7804 | } |
c906108c | 7805 | |
fe798b75 | 7806 | static enum print_stop_action |
348d480f | 7807 | print_it_catch_exec (bpstat bs) |
fe798b75 | 7808 | { |
36dfb11c | 7809 | struct ui_out *uiout = current_uiout; |
348d480f | 7810 | struct breakpoint *b = bs->breakpoint_at; |
b4d90040 PA |
7811 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
7812 | ||
fe798b75 | 7813 | annotate_catchpoint (b->number); |
36dfb11c TT |
7814 | if (b->disposition == disp_del) |
7815 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
7816 | else | |
7817 | ui_out_text (uiout, "\nCatchpoint "); | |
7818 | if (ui_out_is_mi_like_p (uiout)) | |
7819 | { | |
7820 | ui_out_field_string (uiout, "reason", | |
7821 | async_reason_lookup (EXEC_ASYNC_EXEC)); | |
7822 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
7823 | } | |
7824 | ui_out_field_int (uiout, "bkptno", b->number); | |
7825 | ui_out_text (uiout, " (exec'd "); | |
7826 | ui_out_field_string (uiout, "new-exec", c->exec_pathname); | |
7827 | ui_out_text (uiout, "), "); | |
7828 | ||
fe798b75 | 7829 | return PRINT_SRC_AND_LOC; |
c906108c SS |
7830 | } |
7831 | ||
fe798b75 | 7832 | static void |
a6d9a66e | 7833 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 | 7834 | { |
b4d90040 | 7835 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
fe798b75 | 7836 | struct value_print_options opts; |
79a45e25 | 7837 | struct ui_out *uiout = current_uiout; |
fe798b75 JB |
7838 | |
7839 | get_user_print_options (&opts); | |
7840 | ||
7841 | /* Field 4, the address, is omitted (which makes the columns | |
7842 | not line up too nicely with the headers, but the effect | |
7843 | is relatively readable). */ | |
7844 | if (opts.addressprint) | |
7845 | ui_out_field_skip (uiout, "addr"); | |
7846 | annotate_field (5); | |
7847 | ui_out_text (uiout, "exec"); | |
b4d90040 | 7848 | if (c->exec_pathname != NULL) |
fe798b75 JB |
7849 | { |
7850 | ui_out_text (uiout, ", program \""); | |
b4d90040 | 7851 | ui_out_field_string (uiout, "what", c->exec_pathname); |
fe798b75 JB |
7852 | ui_out_text (uiout, "\" "); |
7853 | } | |
7854 | } | |
7855 | ||
7856 | static void | |
7857 | print_mention_catch_exec (struct breakpoint *b) | |
7858 | { | |
7859 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
7860 | } | |
7861 | ||
6149aea9 PA |
7862 | /* Implement the "print_recreate" breakpoint_ops method for exec |
7863 | catchpoints. */ | |
7864 | ||
7865 | static void | |
7866 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
7867 | { | |
7868 | fprintf_unfiltered (fp, "catch exec"); | |
d9b3f62e | 7869 | print_recreate_thread (b, fp); |
6149aea9 PA |
7870 | } |
7871 | ||
2060206e | 7872 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
fe798b75 | 7873 | |
a96d9b2e SDJ |
7874 | static void |
7875 | create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, | |
c0a91b2b | 7876 | const struct breakpoint_ops *ops) |
a96d9b2e | 7877 | { |
be5c67c1 | 7878 | struct syscall_catchpoint *c; |
a96d9b2e | 7879 | struct gdbarch *gdbarch = get_current_arch (); |
a96d9b2e | 7880 | |
be5c67c1 PA |
7881 | c = XNEW (struct syscall_catchpoint); |
7882 | init_catchpoint (&c->base, gdbarch, tempflag, NULL, ops); | |
7883 | c->syscalls_to_be_caught = filter; | |
a96d9b2e | 7884 | |
3ea46bff | 7885 | install_breakpoint (0, &c->base, 1); |
a96d9b2e SDJ |
7886 | } |
7887 | ||
c906108c | 7888 | static int |
fba45db2 | 7889 | hw_breakpoint_used_count (void) |
c906108c | 7890 | { |
c906108c | 7891 | int i = 0; |
f1310107 TJB |
7892 | struct breakpoint *b; |
7893 | struct bp_location *bl; | |
c906108c SS |
7894 | |
7895 | ALL_BREAKPOINTS (b) | |
c5aa993b | 7896 | { |
d6b74ac4 | 7897 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
7898 | for (bl = b->loc; bl; bl = bl->next) |
7899 | { | |
7900 | /* Special types of hardware breakpoints may use more than | |
7901 | one register. */ | |
348d480f | 7902 | i += b->ops->resources_needed (bl); |
f1310107 | 7903 | } |
c5aa993b | 7904 | } |
c906108c SS |
7905 | |
7906 | return i; | |
7907 | } | |
7908 | ||
a1398e0c PA |
7909 | /* Returns the resources B would use if it were a hardware |
7910 | watchpoint. */ | |
7911 | ||
c906108c | 7912 | static int |
a1398e0c | 7913 | hw_watchpoint_use_count (struct breakpoint *b) |
c906108c | 7914 | { |
c906108c | 7915 | int i = 0; |
e09342b5 | 7916 | struct bp_location *bl; |
c906108c | 7917 | |
a1398e0c PA |
7918 | if (!breakpoint_enabled (b)) |
7919 | return 0; | |
7920 | ||
7921 | for (bl = b->loc; bl; bl = bl->next) | |
7922 | { | |
7923 | /* Special types of hardware watchpoints may use more than | |
7924 | one register. */ | |
7925 | i += b->ops->resources_needed (bl); | |
7926 | } | |
7927 | ||
7928 | return i; | |
7929 | } | |
7930 | ||
7931 | /* Returns the sum the used resources of all hardware watchpoints of | |
7932 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED | |
7933 | the sum of the used resources of all hardware watchpoints of other | |
7934 | types _not_ TYPE. */ | |
7935 | ||
7936 | static int | |
7937 | hw_watchpoint_used_count_others (struct breakpoint *except, | |
7938 | enum bptype type, int *other_type_used) | |
7939 | { | |
7940 | int i = 0; | |
7941 | struct breakpoint *b; | |
7942 | ||
c906108c SS |
7943 | *other_type_used = 0; |
7944 | ALL_BREAKPOINTS (b) | |
e09342b5 | 7945 | { |
a1398e0c PA |
7946 | if (b == except) |
7947 | continue; | |
e09342b5 TJB |
7948 | if (!breakpoint_enabled (b)) |
7949 | continue; | |
7950 | ||
a1398e0c PA |
7951 | if (b->type == type) |
7952 | i += hw_watchpoint_use_count (b); | |
7953 | else if (is_hardware_watchpoint (b)) | |
7954 | *other_type_used = 1; | |
e09342b5 TJB |
7955 | } |
7956 | ||
c906108c SS |
7957 | return i; |
7958 | } | |
7959 | ||
c906108c | 7960 | void |
fba45db2 | 7961 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 7962 | { |
c5aa993b | 7963 | struct breakpoint *b; |
c906108c SS |
7964 | |
7965 | ALL_BREAKPOINTS (b) | |
c5aa993b | 7966 | { |
cc60f2e3 | 7967 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 7968 | { |
b5de0fa7 | 7969 | b->enable_state = bp_call_disabled; |
b60e7edf | 7970 | update_global_location_list (0); |
c5aa993b JM |
7971 | } |
7972 | } | |
c906108c SS |
7973 | } |
7974 | ||
7975 | void | |
fba45db2 | 7976 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 7977 | { |
c5aa993b | 7978 | struct breakpoint *b; |
c906108c SS |
7979 | |
7980 | ALL_BREAKPOINTS (b) | |
c5aa993b | 7981 | { |
cc60f2e3 | 7982 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 7983 | { |
b5de0fa7 | 7984 | b->enable_state = bp_enabled; |
b60e7edf | 7985 | update_global_location_list (1); |
c5aa993b JM |
7986 | } |
7987 | } | |
c906108c SS |
7988 | } |
7989 | ||
8bea4e01 UW |
7990 | void |
7991 | disable_breakpoints_before_startup (void) | |
7992 | { | |
6c95b8df | 7993 | current_program_space->executing_startup = 1; |
f8eba3c6 | 7994 | update_global_location_list (0); |
8bea4e01 UW |
7995 | } |
7996 | ||
7997 | void | |
7998 | enable_breakpoints_after_startup (void) | |
7999 | { | |
6c95b8df | 8000 | current_program_space->executing_startup = 0; |
f8eba3c6 | 8001 | breakpoint_re_set (); |
8bea4e01 UW |
8002 | } |
8003 | ||
c906108c SS |
8004 | |
8005 | /* Set a breakpoint that will evaporate an end of command | |
8006 | at address specified by SAL. | |
8007 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
8008 | ||
8009 | struct breakpoint * | |
a6d9a66e UW |
8010 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
8011 | struct frame_id frame_id, enum bptype type) | |
c906108c | 8012 | { |
52f0bd74 | 8013 | struct breakpoint *b; |
edb3359d DJ |
8014 | |
8015 | /* If FRAME_ID is valid, it should be a real frame, not an inlined | |
8016 | one. */ | |
8017 | gdb_assert (!frame_id_inlined_p (frame_id)); | |
8018 | ||
06edf0c0 | 8019 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
8020 | b->enable_state = bp_enabled; |
8021 | b->disposition = disp_donttouch; | |
818dd999 | 8022 | b->frame_id = frame_id; |
c906108c | 8023 | |
4a64f543 MS |
8024 | /* If we're debugging a multi-threaded program, then we want |
8025 | momentary breakpoints to be active in only a single thread of | |
8026 | control. */ | |
39f77062 KB |
8027 | if (in_thread_list (inferior_ptid)) |
8028 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 8029 | |
b60e7edf | 8030 | update_global_location_list_nothrow (1); |
74960c60 | 8031 | |
c906108c SS |
8032 | return b; |
8033 | } | |
611c83ae | 8034 | |
06edf0c0 PA |
8035 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
8036 | The new breakpoint will have type TYPE, and use OPS as it | |
8037 | breakpoint_ops. */ | |
e58b0e63 | 8038 | |
06edf0c0 PA |
8039 | static struct breakpoint * |
8040 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
8041 | enum bptype type, | |
c0a91b2b | 8042 | const struct breakpoint_ops *ops) |
e58b0e63 PA |
8043 | { |
8044 | struct breakpoint *copy; | |
8045 | ||
06edf0c0 | 8046 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 8047 | copy->loc = allocate_bp_location (copy); |
0e30163f | 8048 | set_breakpoint_location_function (copy->loc, 1); |
e58b0e63 | 8049 | |
a6d9a66e | 8050 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
8051 | copy->loc->requested_address = orig->loc->requested_address; |
8052 | copy->loc->address = orig->loc->address; | |
8053 | copy->loc->section = orig->loc->section; | |
6c95b8df | 8054 | copy->loc->pspace = orig->loc->pspace; |
e58b0e63 | 8055 | |
f8eba3c6 TT |
8056 | if (orig->loc->source_file != NULL) |
8057 | copy->loc->source_file = xstrdup (orig->loc->source_file); | |
e58b0e63 | 8058 | |
f8eba3c6 | 8059 | copy->loc->line_number = orig->loc->line_number; |
e58b0e63 PA |
8060 | copy->frame_id = orig->frame_id; |
8061 | copy->thread = orig->thread; | |
6c95b8df | 8062 | copy->pspace = orig->pspace; |
e58b0e63 PA |
8063 | |
8064 | copy->enable_state = bp_enabled; | |
8065 | copy->disposition = disp_donttouch; | |
8066 | copy->number = internal_breakpoint_number--; | |
8067 | ||
8068 | update_global_location_list_nothrow (0); | |
8069 | return copy; | |
8070 | } | |
8071 | ||
06edf0c0 PA |
8072 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
8073 | ORIG is NULL. */ | |
8074 | ||
8075 | struct breakpoint * | |
8076 | clone_momentary_breakpoint (struct breakpoint *orig) | |
8077 | { | |
8078 | /* If there's nothing to clone, then return nothing. */ | |
8079 | if (orig == NULL) | |
8080 | return NULL; | |
8081 | ||
8082 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops); | |
8083 | } | |
8084 | ||
611c83ae | 8085 | struct breakpoint * |
a6d9a66e UW |
8086 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
8087 | enum bptype type) | |
611c83ae PA |
8088 | { |
8089 | struct symtab_and_line sal; | |
8090 | ||
8091 | sal = find_pc_line (pc, 0); | |
8092 | sal.pc = pc; | |
8093 | sal.section = find_pc_overlay (pc); | |
8094 | sal.explicit_pc = 1; | |
8095 | ||
a6d9a66e | 8096 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 8097 | } |
c906108c | 8098 | \f |
c5aa993b | 8099 | |
c906108c SS |
8100 | /* Tell the user we have just set a breakpoint B. */ |
8101 | ||
8102 | static void | |
fba45db2 | 8103 | mention (struct breakpoint *b) |
c906108c | 8104 | { |
348d480f | 8105 | b->ops->print_mention (b); |
79a45e25 | 8106 | if (ui_out_is_mi_like_p (current_uiout)) |
fb40c209 | 8107 | return; |
c906108c SS |
8108 | printf_filtered ("\n"); |
8109 | } | |
c906108c | 8110 | \f |
c5aa993b | 8111 | |
0d381245 | 8112 | static struct bp_location * |
39d61571 | 8113 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
8114 | const struct symtab_and_line *sal) |
8115 | { | |
8116 | struct bp_location *loc, **tmp; | |
3742cc8b YQ |
8117 | CORE_ADDR adjusted_address; |
8118 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); | |
8119 | ||
8120 | if (loc_gdbarch == NULL) | |
8121 | loc_gdbarch = b->gdbarch; | |
8122 | ||
8123 | /* Adjust the breakpoint's address prior to allocating a location. | |
8124 | Once we call allocate_bp_location(), that mostly uninitialized | |
8125 | location will be placed on the location chain. Adjustment of the | |
8126 | breakpoint may cause target_read_memory() to be called and we do | |
8127 | not want its scan of the location chain to find a breakpoint and | |
8128 | location that's only been partially initialized. */ | |
8129 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, | |
8130 | sal->pc, b->type); | |
0d381245 | 8131 | |
39d61571 | 8132 | loc = allocate_bp_location (b); |
0d381245 VP |
8133 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
8134 | ; | |
8135 | *tmp = loc; | |
3742cc8b | 8136 | |
0d381245 | 8137 | loc->requested_address = sal->pc; |
3742cc8b | 8138 | loc->address = adjusted_address; |
6c95b8df PA |
8139 | loc->pspace = sal->pspace; |
8140 | gdb_assert (loc->pspace != NULL); | |
0d381245 | 8141 | loc->section = sal->section; |
3742cc8b | 8142 | loc->gdbarch = loc_gdbarch; |
f8eba3c6 TT |
8143 | |
8144 | if (sal->symtab != NULL) | |
8145 | loc->source_file = xstrdup (sal->symtab->filename); | |
8146 | loc->line_number = sal->line; | |
8147 | ||
0e30163f JK |
8148 | set_breakpoint_location_function (loc, |
8149 | sal->explicit_pc || sal->explicit_line); | |
0d381245 VP |
8150 | return loc; |
8151 | } | |
514f746b AR |
8152 | \f |
8153 | ||
8154 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
8155 | return 0 otherwise. */ | |
8156 | ||
8157 | static int | |
8158 | bp_loc_is_permanent (struct bp_location *loc) | |
8159 | { | |
8160 | int len; | |
8161 | CORE_ADDR addr; | |
1afeeb75 | 8162 | const gdb_byte *bpoint; |
514f746b | 8163 | gdb_byte *target_mem; |
939c61fa JK |
8164 | struct cleanup *cleanup; |
8165 | int retval = 0; | |
514f746b AR |
8166 | |
8167 | gdb_assert (loc != NULL); | |
8168 | ||
8169 | addr = loc->address; | |
1afeeb75 | 8170 | bpoint = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 8171 | |
939c61fa | 8172 | /* Software breakpoints unsupported? */ |
1afeeb75 | 8173 | if (bpoint == NULL) |
939c61fa JK |
8174 | return 0; |
8175 | ||
514f746b AR |
8176 | target_mem = alloca (len); |
8177 | ||
939c61fa JK |
8178 | /* Enable the automatic memory restoration from breakpoints while |
8179 | we read the memory. Otherwise we could say about our temporary | |
8180 | breakpoints they are permanent. */ | |
6c95b8df PA |
8181 | cleanup = save_current_space_and_thread (); |
8182 | ||
8183 | switch_to_program_space_and_thread (loc->pspace); | |
8184 | make_show_memory_breakpoints_cleanup (0); | |
939c61fa | 8185 | |
514f746b | 8186 | if (target_read_memory (loc->address, target_mem, len) == 0 |
1afeeb75 | 8187 | && memcmp (target_mem, bpoint, len) == 0) |
939c61fa | 8188 | retval = 1; |
514f746b | 8189 | |
939c61fa JK |
8190 | do_cleanups (cleanup); |
8191 | ||
8192 | return retval; | |
514f746b AR |
8193 | } |
8194 | ||
8195 | ||
c3f6f71d | 8196 | |
018d34a4 VP |
8197 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
8198 | as textual description of the location, and COND_STRING | |
db107f19 | 8199 | as condition expression. */ |
018d34a4 VP |
8200 | |
8201 | static void | |
d9b3f62e PA |
8202 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
8203 | struct symtabs_and_lines sals, char *addr_string, | |
f8eba3c6 | 8204 | char *filter, char *cond_string, |
d9b3f62e PA |
8205 | enum bptype type, enum bpdisp disposition, |
8206 | int thread, int task, int ignore_count, | |
c0a91b2b | 8207 | const struct breakpoint_ops *ops, int from_tty, |
d9b3f62e | 8208 | int enabled, int internal, int display_canonical) |
018d34a4 | 8209 | { |
0d381245 | 8210 | int i; |
018d34a4 VP |
8211 | |
8212 | if (type == bp_hardware_breakpoint) | |
8213 | { | |
fbbd034e AS |
8214 | int target_resources_ok; |
8215 | ||
8216 | i = hw_breakpoint_used_count (); | |
8217 | target_resources_ok = | |
8218 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
018d34a4 VP |
8219 | i + 1, 0); |
8220 | if (target_resources_ok == 0) | |
8221 | error (_("No hardware breakpoint support in the target.")); | |
8222 | else if (target_resources_ok < 0) | |
8223 | error (_("Hardware breakpoints used exceeds limit.")); | |
8224 | } | |
8225 | ||
6c95b8df PA |
8226 | gdb_assert (sals.nelts > 0); |
8227 | ||
0d381245 VP |
8228 | for (i = 0; i < sals.nelts; ++i) |
8229 | { | |
8230 | struct symtab_and_line sal = sals.sals[i]; | |
8231 | struct bp_location *loc; | |
8232 | ||
8233 | if (from_tty) | |
5af949e3 UW |
8234 | { |
8235 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
8236 | if (!loc_gdbarch) | |
8237 | loc_gdbarch = gdbarch; | |
8238 | ||
8239 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 8240 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 8241 | } |
0d381245 VP |
8242 | |
8243 | if (i == 0) | |
8244 | { | |
d9b3f62e | 8245 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 8246 | b->thread = thread; |
4a306c9a | 8247 | b->task = task; |
018d34a4 | 8248 | |
0d381245 VP |
8249 | b->cond_string = cond_string; |
8250 | b->ignore_count = ignore_count; | |
41447f92 | 8251 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 8252 | b->disposition = disposition; |
6c95b8df | 8253 | |
0fb4aa4b PA |
8254 | if (type == bp_static_tracepoint) |
8255 | { | |
d9b3f62e | 8256 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
8257 | struct static_tracepoint_marker marker; |
8258 | ||
983af33b | 8259 | if (strace_marker_p (b)) |
0fb4aa4b PA |
8260 | { |
8261 | /* We already know the marker exists, otherwise, we | |
8262 | wouldn't see a sal for it. */ | |
8263 | char *p = &addr_string[3]; | |
8264 | char *endp; | |
8265 | char *marker_str; | |
0fb4aa4b | 8266 | |
e9cafbcc | 8267 | p = skip_spaces (p); |
0fb4aa4b | 8268 | |
e9cafbcc | 8269 | endp = skip_to_space (p); |
0fb4aa4b PA |
8270 | |
8271 | marker_str = savestring (p, endp - p); | |
d9b3f62e | 8272 | t->static_trace_marker_id = marker_str; |
0fb4aa4b | 8273 | |
3e43a32a MS |
8274 | printf_filtered (_("Probed static tracepoint " |
8275 | "marker \"%s\"\n"), | |
d9b3f62e | 8276 | t->static_trace_marker_id); |
0fb4aa4b PA |
8277 | } |
8278 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
8279 | { | |
d9b3f62e | 8280 | t->static_trace_marker_id = xstrdup (marker.str_id); |
0fb4aa4b PA |
8281 | release_static_tracepoint_marker (&marker); |
8282 | ||
3e43a32a MS |
8283 | printf_filtered (_("Probed static tracepoint " |
8284 | "marker \"%s\"\n"), | |
d9b3f62e | 8285 | t->static_trace_marker_id); |
0fb4aa4b PA |
8286 | } |
8287 | else | |
3e43a32a MS |
8288 | warning (_("Couldn't determine the static " |
8289 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
8290 | } |
8291 | ||
0d381245 VP |
8292 | loc = b->loc; |
8293 | } | |
8294 | else | |
018d34a4 | 8295 | { |
39d61571 | 8296 | loc = add_location_to_breakpoint (b, &sal); |
0d381245 VP |
8297 | } |
8298 | ||
514f746b AR |
8299 | if (bp_loc_is_permanent (loc)) |
8300 | make_breakpoint_permanent (b); | |
8301 | ||
0d381245 VP |
8302 | if (b->cond_string) |
8303 | { | |
8304 | char *arg = b->cond_string; | |
d32a6982 | 8305 | loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0); |
0d381245 | 8306 | if (*arg) |
db107f19 | 8307 | error (_("Garbage %s follows condition"), arg); |
018d34a4 | 8308 | } |
0d381245 | 8309 | } |
018d34a4 | 8310 | |
56435ebe | 8311 | b->display_canonical = display_canonical; |
018d34a4 VP |
8312 | if (addr_string) |
8313 | b->addr_string = addr_string; | |
8314 | else | |
8315 | /* addr_string has to be used or breakpoint_re_set will delete | |
8316 | me. */ | |
5af949e3 UW |
8317 | b->addr_string |
8318 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
f8eba3c6 | 8319 | b->filter = filter; |
d9b3f62e | 8320 | } |
018d34a4 | 8321 | |
d9b3f62e PA |
8322 | static void |
8323 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
8324 | struct symtabs_and_lines sals, char *addr_string, | |
f8eba3c6 | 8325 | char *filter, char *cond_string, |
d9b3f62e PA |
8326 | enum bptype type, enum bpdisp disposition, |
8327 | int thread, int task, int ignore_count, | |
c0a91b2b | 8328 | const struct breakpoint_ops *ops, int from_tty, |
d9b3f62e PA |
8329 | int enabled, int internal, int display_canonical) |
8330 | { | |
8331 | struct breakpoint *b; | |
8332 | struct cleanup *old_chain; | |
8333 | ||
8334 | if (is_tracepoint_type (type)) | |
8335 | { | |
8336 | struct tracepoint *t; | |
8337 | ||
8338 | t = XCNEW (struct tracepoint); | |
8339 | b = &t->base; | |
8340 | } | |
8341 | else | |
8342 | b = XNEW (struct breakpoint); | |
8343 | ||
8344 | old_chain = make_cleanup (xfree, b); | |
8345 | ||
8346 | init_breakpoint_sal (b, gdbarch, | |
8347 | sals, addr_string, | |
f8eba3c6 | 8348 | filter, cond_string, |
d9b3f62e PA |
8349 | type, disposition, |
8350 | thread, task, ignore_count, | |
8351 | ops, from_tty, | |
8352 | enabled, internal, display_canonical); | |
8353 | discard_cleanups (old_chain); | |
8354 | ||
3ea46bff | 8355 | install_breakpoint (internal, b, 0); |
018d34a4 VP |
8356 | } |
8357 | ||
8358 | /* Add SALS.nelts breakpoints to the breakpoint table. For each | |
8359 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
8360 | value. COND_STRING, if not NULL, specified the condition to be | |
8361 | used for all breakpoints. Essentially the only case where | |
8362 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
8363 | function. In that case, it's still not possible to specify | |
8364 | separate conditions for different overloaded functions, so | |
8365 | we take just a single condition string. | |
8366 | ||
c3f6f71d | 8367 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 8368 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
8369 | array contents). If the function fails (error() is called), the |
8370 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 8371 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
8372 | |
8373 | static void | |
8cdf0e15 | 8374 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 | 8375 | struct linespec_result *canonical, |
8cdf0e15 VP |
8376 | char *cond_string, |
8377 | enum bptype type, enum bpdisp disposition, | |
8378 | int thread, int task, int ignore_count, | |
c0a91b2b | 8379 | const struct breakpoint_ops *ops, int from_tty, |
84f4c1fe | 8380 | int enabled, int internal) |
c906108c | 8381 | { |
018d34a4 | 8382 | int i; |
f8eba3c6 | 8383 | struct linespec_sals *lsal; |
cc59ec59 | 8384 | |
f8eba3c6 TT |
8385 | if (canonical->pre_expanded) |
8386 | gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1); | |
8387 | ||
8388 | for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i) | |
c3f6f71d | 8389 | { |
f8eba3c6 TT |
8390 | /* Note that 'addr_string' can be NULL in the case of a plain |
8391 | 'break', without arguments. */ | |
8392 | char *addr_string = (canonical->addr_string | |
8393 | ? xstrdup (canonical->addr_string) | |
8394 | : NULL); | |
8395 | char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL; | |
8396 | struct cleanup *inner = make_cleanup (xfree, addr_string); | |
0d381245 | 8397 | |
f8eba3c6 TT |
8398 | make_cleanup (xfree, filter_string); |
8399 | create_breakpoint_sal (gdbarch, lsal->sals, | |
8400 | addr_string, | |
8401 | filter_string, | |
8cdf0e15 | 8402 | cond_string, type, disposition, |
84f4c1fe | 8403 | thread, task, ignore_count, ops, |
56435ebe TT |
8404 | from_tty, enabled, internal, |
8405 | canonical->special_display); | |
f8eba3c6 | 8406 | discard_cleanups (inner); |
c3f6f71d | 8407 | } |
c3f6f71d | 8408 | } |
c906108c | 8409 | |
9998af43 | 8410 | /* Parse ADDRESS which is assumed to be a SAL specification possibly |
c3f6f71d | 8411 | followed by conditionals. On return, SALS contains an array of SAL |
4a64f543 | 8412 | addresses found. ADDR_STRING contains a vector of (canonical) |
9998af43 TJB |
8413 | address strings. ADDRESS points to the end of the SAL. |
8414 | ||
8415 | The array and the line spec strings are allocated on the heap, it is | |
8416 | the caller's responsibility to free them. */ | |
c906108c | 8417 | |
b9362cc7 | 8418 | static void |
c3f6f71d | 8419 | parse_breakpoint_sals (char **address, |
58438ac1 | 8420 | struct linespec_result *canonical) |
c3f6f71d JM |
8421 | { |
8422 | char *addr_start = *address; | |
cc59ec59 | 8423 | |
c3f6f71d | 8424 | /* If no arg given, or if first arg is 'if ', use the default |
4a64f543 | 8425 | breakpoint. */ |
c3f6f71d JM |
8426 | if ((*address) == NULL |
8427 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c | 8428 | { |
1bfeeb0f JL |
8429 | /* The last displayed codepoint, if it's valid, is our default breakpoint |
8430 | address. */ | |
8431 | if (last_displayed_sal_is_valid ()) | |
c906108c | 8432 | { |
f8eba3c6 | 8433 | struct linespec_sals lsal; |
c3f6f71d | 8434 | struct symtab_and_line sal; |
cc59ec59 | 8435 | |
4a64f543 | 8436 | init_sal (&sal); /* Initialize to zeroes. */ |
f8eba3c6 | 8437 | lsal.sals.sals = (struct symtab_and_line *) |
c906108c | 8438 | xmalloc (sizeof (struct symtab_and_line)); |
1bfeeb0f JL |
8439 | |
8440 | /* Set sal's pspace, pc, symtab, and line to the values | |
8441 | corresponding to the last call to print_frame_info. */ | |
8442 | get_last_displayed_sal (&sal); | |
8443 | sal.section = find_pc_overlay (sal.pc); | |
00903456 | 8444 | |
4a64f543 | 8445 | /* "break" without arguments is equivalent to "break *PC" |
1bfeeb0f JL |
8446 | where PC is the last displayed codepoint's address. So |
8447 | make sure to set sal.explicit_pc to prevent GDB from | |
8448 | trying to expand the list of sals to include all other | |
8449 | instances with the same symtab and line. */ | |
00903456 JK |
8450 | sal.explicit_pc = 1; |
8451 | ||
f8eba3c6 TT |
8452 | lsal.sals.sals[0] = sal; |
8453 | lsal.sals.nelts = 1; | |
8454 | lsal.canonical = NULL; | |
8455 | ||
8456 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
c906108c SS |
8457 | } |
8458 | else | |
8a3fe4f8 | 8459 | error (_("No default breakpoint address now.")); |
c906108c SS |
8460 | } |
8461 | else | |
8462 | { | |
c906108c | 8463 | /* Force almost all breakpoints to be in terms of the |
4a64f543 MS |
8464 | current_source_symtab (which is decode_line_1's default). |
8465 | This should produce the results we want almost all of the | |
f8eba3c6 TT |
8466 | time while leaving default_breakpoint_* alone. */ |
8467 | if (last_displayed_sal_is_valid ()) | |
8468 | decode_line_full (address, DECODE_LINE_FUNFIRSTLINE, | |
8469 | get_last_displayed_symtab (), | |
8470 | get_last_displayed_line (), | |
8471 | canonical, NULL, NULL); | |
c906108c | 8472 | else |
f8eba3c6 TT |
8473 | decode_line_full (address, DECODE_LINE_FUNFIRSTLINE, |
8474 | (struct symtab *) NULL, 0, | |
8475 | canonical, NULL, NULL); | |
c906108c | 8476 | } |
c3f6f71d | 8477 | } |
c906108c | 8478 | |
c906108c | 8479 | |
c3f6f71d | 8480 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 8481 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 8482 | |
b9362cc7 | 8483 | static void |
23e7acfb | 8484 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
c3f6f71d JM |
8485 | { |
8486 | int i; | |
cc59ec59 | 8487 | |
c3f6f71d | 8488 | for (i = 0; i < sals->nelts; i++) |
ee53e872 | 8489 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
8490 | } |
8491 | ||
7a697b8d SS |
8492 | /* Fast tracepoints may have restrictions on valid locations. For |
8493 | instance, a fast tracepoint using a jump instead of a trap will | |
8494 | likely have to overwrite more bytes than a trap would, and so can | |
8495 | only be placed where the instruction is longer than the jump, or a | |
8496 | multi-instruction sequence does not have a jump into the middle of | |
8497 | it, etc. */ | |
8498 | ||
8499 | static void | |
8500 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
8501 | struct symtabs_and_lines *sals) | |
8502 | { | |
8503 | int i, rslt; | |
8504 | struct symtab_and_line *sal; | |
8505 | char *msg; | |
8506 | struct cleanup *old_chain; | |
8507 | ||
8508 | for (i = 0; i < sals->nelts; i++) | |
8509 | { | |
f8eba3c6 TT |
8510 | struct gdbarch *sarch; |
8511 | ||
7a697b8d SS |
8512 | sal = &sals->sals[i]; |
8513 | ||
f8eba3c6 TT |
8514 | sarch = get_sal_arch (*sal); |
8515 | /* We fall back to GDBARCH if there is no architecture | |
8516 | associated with SAL. */ | |
8517 | if (sarch == NULL) | |
8518 | sarch = gdbarch; | |
8519 | rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc, | |
7a697b8d SS |
8520 | NULL, &msg); |
8521 | old_chain = make_cleanup (xfree, msg); | |
8522 | ||
8523 | if (!rslt) | |
8524 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
f8eba3c6 | 8525 | paddress (sarch, sal->pc), (msg ? msg : "")); |
7a697b8d SS |
8526 | |
8527 | do_cleanups (old_chain); | |
8528 | } | |
8529 | } | |
8530 | ||
018d34a4 VP |
8531 | /* Given TOK, a string specification of condition and thread, as |
8532 | accepted by the 'break' command, extract the condition | |
8533 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 8534 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
8535 | If no condition is found, *COND_STRING is set to NULL. |
8536 | If no thread is found, *THREAD is set to -1. */ | |
8537 | static void | |
8538 | find_condition_and_thread (char *tok, CORE_ADDR pc, | |
4a306c9a | 8539 | char **cond_string, int *thread, int *task) |
018d34a4 VP |
8540 | { |
8541 | *cond_string = NULL; | |
8542 | *thread = -1; | |
8543 | while (tok && *tok) | |
8544 | { | |
8545 | char *end_tok; | |
8546 | int toklen; | |
8547 | char *cond_start = NULL; | |
8548 | char *cond_end = NULL; | |
cc59ec59 | 8549 | |
e9cafbcc | 8550 | tok = skip_spaces (tok); |
018d34a4 | 8551 | |
e9cafbcc | 8552 | end_tok = skip_to_space (tok); |
018d34a4 VP |
8553 | |
8554 | toklen = end_tok - tok; | |
8555 | ||
8556 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
8557 | { | |
f7545552 TT |
8558 | struct expression *expr; |
8559 | ||
018d34a4 | 8560 | tok = cond_start = end_tok + 1; |
f7545552 TT |
8561 | expr = parse_exp_1 (&tok, block_for_pc (pc), 0); |
8562 | xfree (expr); | |
018d34a4 VP |
8563 | cond_end = tok; |
8564 | *cond_string = savestring (cond_start, | |
8565 | cond_end - cond_start); | |
8566 | } | |
8567 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
8568 | { | |
8569 | char *tmptok; | |
8570 | ||
8571 | tok = end_tok + 1; | |
8572 | tmptok = tok; | |
8573 | *thread = strtol (tok, &tok, 0); | |
8574 | if (tok == tmptok) | |
8575 | error (_("Junk after thread keyword.")); | |
8576 | if (!valid_thread_id (*thread)) | |
8577 | error (_("Unknown thread %d."), *thread); | |
8578 | } | |
4a306c9a JB |
8579 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
8580 | { | |
8581 | char *tmptok; | |
8582 | ||
8583 | tok = end_tok + 1; | |
8584 | tmptok = tok; | |
8585 | *task = strtol (tok, &tok, 0); | |
8586 | if (tok == tmptok) | |
8587 | error (_("Junk after task keyword.")); | |
8588 | if (!valid_task_id (*task)) | |
b6199126 | 8589 | error (_("Unknown task %d."), *task); |
4a306c9a | 8590 | } |
018d34a4 VP |
8591 | else |
8592 | error (_("Junk at end of arguments.")); | |
8593 | } | |
8594 | } | |
8595 | ||
0fb4aa4b PA |
8596 | /* Decode a static tracepoint marker spec. */ |
8597 | ||
8598 | static struct symtabs_and_lines | |
8599 | decode_static_tracepoint_spec (char **arg_p) | |
8600 | { | |
8601 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
8602 | struct symtabs_and_lines sals; | |
8603 | struct symtab_and_line sal; | |
8604 | struct symbol *sym; | |
8605 | struct cleanup *old_chain; | |
8606 | char *p = &(*arg_p)[3]; | |
8607 | char *endp; | |
8608 | char *marker_str; | |
8609 | int i; | |
8610 | ||
e9cafbcc | 8611 | p = skip_spaces (p); |
0fb4aa4b | 8612 | |
e9cafbcc | 8613 | endp = skip_to_space (p); |
0fb4aa4b PA |
8614 | |
8615 | marker_str = savestring (p, endp - p); | |
8616 | old_chain = make_cleanup (xfree, marker_str); | |
8617 | ||
8618 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
8619 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
8620 | error (_("No known static tracepoint marker named %s"), marker_str); | |
8621 | ||
8622 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); | |
8623 | sals.sals = xmalloc (sizeof *sals.sals * sals.nelts); | |
8624 | ||
8625 | for (i = 0; i < sals.nelts; i++) | |
8626 | { | |
8627 | struct static_tracepoint_marker *marker; | |
8628 | ||
8629 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
8630 | ||
8631 | init_sal (&sals.sals[i]); | |
8632 | ||
8633 | sals.sals[i] = find_pc_line (marker->address, 0); | |
8634 | sals.sals[i].pc = marker->address; | |
8635 | ||
8636 | release_static_tracepoint_marker (marker); | |
8637 | } | |
8638 | ||
8639 | do_cleanups (old_chain); | |
8640 | ||
8641 | *arg_p = endp; | |
8642 | return sals; | |
8643 | } | |
8644 | ||
fd9b8c24 PA |
8645 | /* Set a breakpoint. This function is shared between CLI and MI |
8646 | functions for setting a breakpoint. This function has two major | |
8647 | modes of operations, selected by the PARSE_CONDITION_AND_THREAD | |
8648 | parameter. If non-zero, the function will parse arg, extracting | |
4a64f543 MS |
8649 | breakpoint location, address and thread. Otherwise, ARG is just |
8650 | the location of breakpoint, with condition and thread specified by | |
8651 | the COND_STRING and THREAD parameters. If INTERNAL is non-zero, | |
8652 | the breakpoint number will be allocated from the internal | |
8653 | breakpoint count. Returns true if any breakpoint was created; | |
8654 | false otherwise. */ | |
0101ce28 | 8655 | |
8cdf0e15 VP |
8656 | int |
8657 | create_breakpoint (struct gdbarch *gdbarch, | |
8658 | char *arg, char *cond_string, int thread, | |
8659 | int parse_condition_and_thread, | |
0fb4aa4b | 8660 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
8661 | int ignore_count, |
8662 | enum auto_boolean pending_break_support, | |
c0a91b2b | 8663 | const struct breakpoint_ops *ops, |
84f4c1fe | 8664 | int from_tty, int enabled, int internal) |
c3f6f71d | 8665 | { |
b78a6381 | 8666 | volatile struct gdb_exception e; |
f8eba3c6 | 8667 | char *copy_arg = NULL; |
c3f6f71d | 8668 | char *addr_start = arg; |
7efd8fc2 | 8669 | struct linespec_result canonical; |
c3f6f71d | 8670 | struct cleanup *old_chain; |
80c99de1 | 8671 | struct cleanup *bkpt_chain = NULL; |
05ff989b | 8672 | int i; |
0101ce28 | 8673 | int pending = 0; |
4a306c9a | 8674 | int task = 0; |
86b17b60 | 8675 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 8676 | |
348d480f PA |
8677 | gdb_assert (ops != NULL); |
8678 | ||
7efd8fc2 | 8679 | init_linespec_result (&canonical); |
c3f6f71d | 8680 | |
b78a6381 TT |
8681 | TRY_CATCH (e, RETURN_MASK_ALL) |
8682 | { | |
983af33b SDJ |
8683 | ops->create_sals_from_address (&arg, &canonical, type_wanted, |
8684 | addr_start, ©_arg); | |
b78a6381 | 8685 | } |
0101ce28 JJ |
8686 | |
8687 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 8688 | switch (e.reason) |
0101ce28 | 8689 | { |
983af33b SDJ |
8690 | case GDB_NO_ERROR: |
8691 | if (VEC_empty (linespec_sals, canonical.sals)) | |
8692 | return 0; | |
8693 | break; | |
05ff989b AC |
8694 | case RETURN_ERROR: |
8695 | switch (e.error) | |
0101ce28 | 8696 | { |
05ff989b | 8697 | case NOT_FOUND_ERROR: |
0101ce28 | 8698 | |
05ff989b AC |
8699 | /* If pending breakpoint support is turned off, throw |
8700 | error. */ | |
fa8d40ab JJ |
8701 | |
8702 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
8703 | throw_exception (e); |
8704 | ||
8705 | exception_print (gdb_stderr, e); | |
fa8d40ab | 8706 | |
05ff989b AC |
8707 | /* If pending breakpoint support is auto query and the user |
8708 | selects no, then simply return the error code. */ | |
059fb39f | 8709 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
bfccc43c YQ |
8710 | && !nquery (_("Make %s pending on future shared library load? "), |
8711 | bptype_string (type_wanted))) | |
fd9b8c24 | 8712 | return 0; |
fa8d40ab | 8713 | |
05ff989b AC |
8714 | /* At this point, either the user was queried about setting |
8715 | a pending breakpoint and selected yes, or pending | |
8716 | breakpoint behavior is on and thus a pending breakpoint | |
8717 | is defaulted on behalf of the user. */ | |
f8eba3c6 TT |
8718 | { |
8719 | struct linespec_sals lsal; | |
8720 | ||
8721 | copy_arg = xstrdup (addr_start); | |
8722 | lsal.canonical = xstrdup (copy_arg); | |
8723 | lsal.sals.nelts = 1; | |
8724 | lsal.sals.sals = XNEW (struct symtab_and_line); | |
8725 | init_sal (&lsal.sals.sals[0]); | |
8726 | pending = 1; | |
8727 | VEC_safe_push (linespec_sals, canonical.sals, &lsal); | |
8728 | } | |
05ff989b AC |
8729 | break; |
8730 | default: | |
98deb0da | 8731 | throw_exception (e); |
0101ce28 | 8732 | } |
2abae994 | 8733 | break; |
05ff989b | 8734 | default: |
983af33b | 8735 | throw_exception (e); |
0101ce28 | 8736 | } |
c3f6f71d | 8737 | |
4a64f543 | 8738 | /* Create a chain of things that always need to be cleaned up. */ |
f8eba3c6 | 8739 | old_chain = make_cleanup_destroy_linespec_result (&canonical); |
c3f6f71d | 8740 | |
c3f6f71d JM |
8741 | /* ----------------------------- SNIP ----------------------------- |
8742 | Anything added to the cleanup chain beyond this point is assumed | |
8743 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
8744 | then the memory is not reclaimed. */ |
8745 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d | 8746 | |
c3f6f71d JM |
8747 | /* Resolve all line numbers to PC's and verify that the addresses |
8748 | are ok for the target. */ | |
0101ce28 | 8749 | if (!pending) |
f8eba3c6 TT |
8750 | { |
8751 | int ix; | |
8752 | struct linespec_sals *iter; | |
8753 | ||
8754 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
8755 | breakpoint_sals_to_pc (&iter->sals); | |
8756 | } | |
c3f6f71d | 8757 | |
7a697b8d | 8758 | /* Fast tracepoints may have additional restrictions on location. */ |
bfccc43c | 8759 | if (!pending && type_wanted == bp_fast_tracepoint) |
f8eba3c6 TT |
8760 | { |
8761 | int ix; | |
8762 | struct linespec_sals *iter; | |
8763 | ||
8764 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
8765 | check_fast_tracepoint_sals (gdbarch, &iter->sals); | |
8766 | } | |
7a697b8d | 8767 | |
c3f6f71d JM |
8768 | /* Verify that condition can be parsed, before setting any |
8769 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 8770 | breakpoint. */ |
0101ce28 | 8771 | if (!pending) |
c3f6f71d | 8772 | { |
f8eba3c6 TT |
8773 | struct linespec_sals *lsal; |
8774 | ||
8775 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
8776 | ||
2f069f6f | 8777 | if (parse_condition_and_thread) |
72b2ff0e VP |
8778 | { |
8779 | /* Here we only parse 'arg' to separate condition | |
8780 | from thread number, so parsing in context of first | |
8781 | sal is OK. When setting the breakpoint we'll | |
8782 | re-parse it in context of each sal. */ | |
8783 | cond_string = NULL; | |
8784 | thread = -1; | |
f8eba3c6 | 8785 | find_condition_and_thread (arg, lsal->sals.sals[0].pc, &cond_string, |
4a306c9a | 8786 | &thread, &task); |
72b2ff0e VP |
8787 | if (cond_string) |
8788 | make_cleanup (xfree, cond_string); | |
8789 | } | |
2f069f6f | 8790 | else |
72b2ff0e VP |
8791 | { |
8792 | /* Create a private copy of condition string. */ | |
8793 | if (cond_string) | |
8794 | { | |
8795 | cond_string = xstrdup (cond_string); | |
8796 | make_cleanup (xfree, cond_string); | |
8797 | } | |
8798 | } | |
0fb4aa4b | 8799 | |
983af33b | 8800 | ops->create_breakpoints_sal (gdbarch, &canonical, lsal, |
d9b3f62e PA |
8801 | cond_string, type_wanted, |
8802 | tempflag ? disp_del : disp_donttouch, | |
8803 | thread, task, ignore_count, ops, | |
983af33b | 8804 | from_tty, enabled, internal); |
c906108c | 8805 | } |
0101ce28 JJ |
8806 | else |
8807 | { | |
0101ce28 JJ |
8808 | struct breakpoint *b; |
8809 | ||
0101ce28 JJ |
8810 | make_cleanup (xfree, copy_arg); |
8811 | ||
bfccc43c YQ |
8812 | if (is_tracepoint_type (type_wanted)) |
8813 | { | |
8814 | struct tracepoint *t; | |
8815 | ||
8816 | t = XCNEW (struct tracepoint); | |
8817 | b = &t->base; | |
8818 | } | |
8819 | else | |
8820 | b = XNEW (struct breakpoint); | |
8821 | ||
8822 | init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops); | |
8823 | ||
f8eba3c6 | 8824 | b->addr_string = copy_arg; |
72b2ff0e | 8825 | b->cond_string = NULL; |
0101ce28 | 8826 | b->ignore_count = ignore_count; |
0101ce28 | 8827 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 8828 | b->condition_not_parsed = 1; |
41447f92 | 8829 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
cc72b2a2 KP |
8830 | if ((type_wanted != bp_breakpoint |
8831 | && type_wanted != bp_hardware_breakpoint) || thread != -1) | |
f8eba3c6 | 8832 | b->pspace = current_program_space; |
8bea4e01 | 8833 | |
bfccc43c | 8834 | install_breakpoint (internal, b, 0); |
0101ce28 JJ |
8835 | } |
8836 | ||
f8eba3c6 | 8837 | if (VEC_length (linespec_sals, canonical.sals) > 1) |
95a42b64 | 8838 | { |
3e43a32a MS |
8839 | warning (_("Multiple breakpoints were set.\nUse the " |
8840 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 8841 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
8842 | } |
8843 | ||
80c99de1 PA |
8844 | /* That's it. Discard the cleanups for data inserted into the |
8845 | breakpoint. */ | |
8846 | discard_cleanups (bkpt_chain); | |
8847 | /* But cleanup everything else. */ | |
c3f6f71d | 8848 | do_cleanups (old_chain); |
217dc9e2 | 8849 | |
80c99de1 | 8850 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
217dc9e2 | 8851 | update_global_location_list (1); |
fd9b8c24 PA |
8852 | |
8853 | return 1; | |
c3f6f71d | 8854 | } |
c906108c | 8855 | |
348d480f | 8856 | /* Set a breakpoint. |
72b2ff0e VP |
8857 | ARG is a string describing breakpoint address, |
8858 | condition, and thread. | |
8859 | FLAG specifies if a breakpoint is hardware on, | |
8860 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
8861 | and BP_TEMPFLAG. */ | |
348d480f | 8862 | |
98deb0da | 8863 | static void |
72b2ff0e | 8864 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 8865 | { |
72b2ff0e | 8866 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
8867 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
8868 | ? bp_hardware_breakpoint | |
8869 | : bp_breakpoint); | |
c3f6f71d | 8870 | |
8cdf0e15 VP |
8871 | create_breakpoint (get_current_arch (), |
8872 | arg, | |
8873 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b | 8874 | tempflag, type_wanted, |
8cdf0e15 VP |
8875 | 0 /* Ignore count */, |
8876 | pending_break_support, | |
348d480f | 8877 | &bkpt_breakpoint_ops, |
8cdf0e15 | 8878 | from_tty, |
84f4c1fe PM |
8879 | 1 /* enabled */, |
8880 | 0 /* internal */); | |
c906108c SS |
8881 | } |
8882 | ||
c906108c SS |
8883 | /* Helper function for break_command_1 and disassemble_command. */ |
8884 | ||
8885 | void | |
fba45db2 | 8886 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
8887 | { |
8888 | CORE_ADDR pc; | |
8889 | ||
8890 | if (sal->pc == 0 && sal->symtab != NULL) | |
8891 | { | |
8892 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 8893 | error (_("No line %d in file \"%s\"."), |
c906108c SS |
8894 | sal->line, sal->symtab->filename); |
8895 | sal->pc = pc; | |
6a048695 | 8896 | |
4a64f543 MS |
8897 | /* If this SAL corresponds to a breakpoint inserted using a line |
8898 | number, then skip the function prologue if necessary. */ | |
6a048695 | 8899 | if (sal->explicit_line) |
059acae7 | 8900 | skip_prologue_sal (sal); |
c906108c SS |
8901 | } |
8902 | ||
8903 | if (sal->section == 0 && sal->symtab != NULL) | |
8904 | { | |
8905 | struct blockvector *bv; | |
c5aa993b JM |
8906 | struct block *b; |
8907 | struct symbol *sym; | |
c906108c | 8908 | |
801e3a5b | 8909 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
8910 | if (bv != NULL) |
8911 | { | |
7f0df278 | 8912 | sym = block_linkage_function (b); |
c906108c SS |
8913 | if (sym != NULL) |
8914 | { | |
8915 | fixup_symbol_section (sym, sal->symtab->objfile); | |
714835d5 | 8916 | sal->section = SYMBOL_OBJ_SECTION (sym); |
c906108c SS |
8917 | } |
8918 | else | |
8919 | { | |
4a64f543 MS |
8920 | /* It really is worthwhile to have the section, so we'll |
8921 | just have to look harder. This case can be executed | |
8922 | if we have line numbers but no functions (as can | |
8923 | happen in assembly source). */ | |
c906108c | 8924 | |
c5aa993b | 8925 | struct minimal_symbol *msym; |
6c95b8df PA |
8926 | struct cleanup *old_chain = save_current_space_and_thread (); |
8927 | ||
8928 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
8929 | |
8930 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
8931 | if (msym) | |
714835d5 | 8932 | sal->section = SYMBOL_OBJ_SECTION (msym); |
6c95b8df PA |
8933 | |
8934 | do_cleanups (old_chain); | |
c906108c SS |
8935 | } |
8936 | } | |
8937 | } | |
8938 | } | |
8939 | ||
8940 | void | |
fba45db2 | 8941 | break_command (char *arg, int from_tty) |
c906108c | 8942 | { |
db107f19 | 8943 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8944 | } |
8945 | ||
c906108c | 8946 | void |
fba45db2 | 8947 | tbreak_command (char *arg, int from_tty) |
c906108c | 8948 | { |
db107f19 | 8949 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
8950 | } |
8951 | ||
c906108c | 8952 | static void |
fba45db2 | 8953 | hbreak_command (char *arg, int from_tty) |
c906108c | 8954 | { |
db107f19 | 8955 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
8956 | } |
8957 | ||
8958 | static void | |
fba45db2 | 8959 | thbreak_command (char *arg, int from_tty) |
c906108c | 8960 | { |
db107f19 | 8961 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
8962 | } |
8963 | ||
8964 | static void | |
fba45db2 | 8965 | stop_command (char *arg, int from_tty) |
c906108c | 8966 | { |
a3f17187 | 8967 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 8968 | Usage: stop in <function | address>\n\ |
a3f17187 | 8969 | stop at <line>\n")); |
c906108c SS |
8970 | } |
8971 | ||
8972 | static void | |
fba45db2 | 8973 | stopin_command (char *arg, int from_tty) |
c906108c SS |
8974 | { |
8975 | int badInput = 0; | |
8976 | ||
c5aa993b | 8977 | if (arg == (char *) NULL) |
c906108c SS |
8978 | badInput = 1; |
8979 | else if (*arg != '*') | |
8980 | { | |
8981 | char *argptr = arg; | |
8982 | int hasColon = 0; | |
8983 | ||
4a64f543 | 8984 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 8985 | say it is bad, otherwise, it should be an address or |
4a64f543 | 8986 | function/method name. */ |
c906108c | 8987 | while (*argptr && !hasColon) |
c5aa993b JM |
8988 | { |
8989 | hasColon = (*argptr == ':'); | |
8990 | argptr++; | |
8991 | } | |
c906108c SS |
8992 | |
8993 | if (hasColon) | |
c5aa993b | 8994 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 8995 | else |
c5aa993b | 8996 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
8997 | } |
8998 | ||
8999 | if (badInput) | |
a3f17187 | 9000 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 9001 | else |
db107f19 | 9002 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9003 | } |
9004 | ||
9005 | static void | |
fba45db2 | 9006 | stopat_command (char *arg, int from_tty) |
c906108c SS |
9007 | { |
9008 | int badInput = 0; | |
9009 | ||
c5aa993b | 9010 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
9011 | badInput = 1; |
9012 | else | |
9013 | { | |
9014 | char *argptr = arg; | |
9015 | int hasColon = 0; | |
9016 | ||
4a64f543 MS |
9017 | /* Look for a ':'. If there is a '::' then get out, otherwise |
9018 | it is probably a line number. */ | |
c906108c | 9019 | while (*argptr && !hasColon) |
c5aa993b JM |
9020 | { |
9021 | hasColon = (*argptr == ':'); | |
9022 | argptr++; | |
9023 | } | |
c906108c SS |
9024 | |
9025 | if (hasColon) | |
c5aa993b | 9026 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 9027 | else |
c5aa993b | 9028 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
9029 | } |
9030 | ||
9031 | if (badInput) | |
a3f17187 | 9032 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 9033 | else |
db107f19 | 9034 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9035 | } |
9036 | ||
f1310107 TJB |
9037 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
9038 | ranged breakpoints. */ | |
9039 | ||
9040 | static int | |
9041 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
9042 | struct address_space *aspace, | |
09ac7c10 TT |
9043 | CORE_ADDR bp_addr, |
9044 | const struct target_waitstatus *ws) | |
f1310107 | 9045 | { |
09ac7c10 TT |
9046 | if (ws->kind != TARGET_WAITKIND_STOPPED |
9047 | || ws->value.sig != TARGET_SIGNAL_TRAP) | |
9048 | return 0; | |
9049 | ||
f1310107 TJB |
9050 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, |
9051 | bl->length, aspace, bp_addr); | |
9052 | } | |
9053 | ||
9054 | /* Implement the "resources_needed" breakpoint_ops method for | |
9055 | ranged breakpoints. */ | |
9056 | ||
9057 | static int | |
9058 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
9059 | { | |
9060 | return target_ranged_break_num_registers (); | |
9061 | } | |
9062 | ||
9063 | /* Implement the "print_it" breakpoint_ops method for | |
9064 | ranged breakpoints. */ | |
9065 | ||
9066 | static enum print_stop_action | |
348d480f | 9067 | print_it_ranged_breakpoint (bpstat bs) |
f1310107 | 9068 | { |
348d480f | 9069 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 | 9070 | struct bp_location *bl = b->loc; |
79a45e25 | 9071 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
9072 | |
9073 | gdb_assert (b->type == bp_hardware_breakpoint); | |
9074 | ||
9075 | /* Ranged breakpoints have only one location. */ | |
9076 | gdb_assert (bl && bl->next == NULL); | |
9077 | ||
9078 | annotate_breakpoint (b->number); | |
9079 | if (b->disposition == disp_del) | |
9080 | ui_out_text (uiout, "\nTemporary ranged breakpoint "); | |
9081 | else | |
9082 | ui_out_text (uiout, "\nRanged breakpoint "); | |
9083 | if (ui_out_is_mi_like_p (uiout)) | |
9084 | { | |
9085 | ui_out_field_string (uiout, "reason", | |
9086 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
9087 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
9088 | } | |
9089 | ui_out_field_int (uiout, "bkptno", b->number); | |
9090 | ui_out_text (uiout, ", "); | |
9091 | ||
9092 | return PRINT_SRC_AND_LOC; | |
9093 | } | |
9094 | ||
9095 | /* Implement the "print_one" breakpoint_ops method for | |
9096 | ranged breakpoints. */ | |
9097 | ||
9098 | static void | |
9099 | print_one_ranged_breakpoint (struct breakpoint *b, | |
9100 | struct bp_location **last_loc) | |
9101 | { | |
9102 | struct bp_location *bl = b->loc; | |
9103 | struct value_print_options opts; | |
79a45e25 | 9104 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
9105 | |
9106 | /* Ranged breakpoints have only one location. */ | |
9107 | gdb_assert (bl && bl->next == NULL); | |
9108 | ||
9109 | get_user_print_options (&opts); | |
9110 | ||
9111 | if (opts.addressprint) | |
9112 | /* We don't print the address range here, it will be printed later | |
9113 | by print_one_detail_ranged_breakpoint. */ | |
9114 | ui_out_field_skip (uiout, "addr"); | |
9115 | annotate_field (5); | |
9116 | print_breakpoint_location (b, bl); | |
9117 | *last_loc = bl; | |
9118 | } | |
9119 | ||
9120 | /* Implement the "print_one_detail" breakpoint_ops method for | |
9121 | ranged breakpoints. */ | |
9122 | ||
9123 | static void | |
9124 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
9125 | struct ui_out *uiout) | |
9126 | { | |
9127 | CORE_ADDR address_start, address_end; | |
9128 | struct bp_location *bl = b->loc; | |
9129 | struct ui_stream *stb = ui_out_stream_new (uiout); | |
9130 | struct cleanup *cleanup = make_cleanup_ui_out_stream_delete (stb); | |
9131 | ||
9132 | gdb_assert (bl); | |
9133 | ||
9134 | address_start = bl->address; | |
9135 | address_end = address_start + bl->length - 1; | |
9136 | ||
9137 | ui_out_text (uiout, "\taddress range: "); | |
9138 | fprintf_unfiltered (stb->stream, "[%s, %s]", | |
9139 | print_core_address (bl->gdbarch, address_start), | |
9140 | print_core_address (bl->gdbarch, address_end)); | |
9141 | ui_out_field_stream (uiout, "addr", stb); | |
9142 | ui_out_text (uiout, "\n"); | |
9143 | ||
9144 | do_cleanups (cleanup); | |
9145 | } | |
9146 | ||
9147 | /* Implement the "print_mention" breakpoint_ops method for | |
9148 | ranged breakpoints. */ | |
9149 | ||
9150 | static void | |
9151 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
9152 | { | |
9153 | struct bp_location *bl = b->loc; | |
79a45e25 | 9154 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
9155 | |
9156 | gdb_assert (bl); | |
9157 | gdb_assert (b->type == bp_hardware_breakpoint); | |
9158 | ||
9159 | if (ui_out_is_mi_like_p (uiout)) | |
9160 | return; | |
9161 | ||
9162 | printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."), | |
9163 | b->number, paddress (bl->gdbarch, bl->address), | |
9164 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
9165 | } | |
9166 | ||
9167 | /* Implement the "print_recreate" breakpoint_ops method for | |
9168 | ranged breakpoints. */ | |
9169 | ||
9170 | static void | |
9171 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
9172 | { | |
9173 | fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string, | |
9174 | b->addr_string_range_end); | |
d9b3f62e | 9175 | print_recreate_thread (b, fp); |
f1310107 TJB |
9176 | } |
9177 | ||
9178 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
9179 | ||
2060206e | 9180 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
9181 | |
9182 | /* Find the address where the end of the breakpoint range should be | |
9183 | placed, given the SAL of the end of the range. This is so that if | |
9184 | the user provides a line number, the end of the range is set to the | |
9185 | last instruction of the given line. */ | |
9186 | ||
9187 | static CORE_ADDR | |
9188 | find_breakpoint_range_end (struct symtab_and_line sal) | |
9189 | { | |
9190 | CORE_ADDR end; | |
9191 | ||
9192 | /* If the user provided a PC value, use it. Otherwise, | |
9193 | find the address of the end of the given location. */ | |
9194 | if (sal.explicit_pc) | |
9195 | end = sal.pc; | |
9196 | else | |
9197 | { | |
9198 | int ret; | |
9199 | CORE_ADDR start; | |
9200 | ||
9201 | ret = find_line_pc_range (sal, &start, &end); | |
9202 | if (!ret) | |
9203 | error (_("Could not find location of the end of the range.")); | |
9204 | ||
9205 | /* find_line_pc_range returns the start of the next line. */ | |
9206 | end--; | |
9207 | } | |
9208 | ||
9209 | return end; | |
9210 | } | |
9211 | ||
9212 | /* Implement the "break-range" CLI command. */ | |
9213 | ||
9214 | static void | |
9215 | break_range_command (char *arg, int from_tty) | |
9216 | { | |
9217 | char *arg_start, *addr_string_start, *addr_string_end; | |
9218 | struct linespec_result canonical_start, canonical_end; | |
9219 | int bp_count, can_use_bp, length; | |
9220 | CORE_ADDR end; | |
9221 | struct breakpoint *b; | |
9222 | struct symtab_and_line sal_start, sal_end; | |
f1310107 | 9223 | struct cleanup *cleanup_bkpt; |
f8eba3c6 | 9224 | struct linespec_sals *lsal_start, *lsal_end; |
f1310107 TJB |
9225 | |
9226 | /* We don't support software ranged breakpoints. */ | |
9227 | if (target_ranged_break_num_registers () < 0) | |
9228 | error (_("This target does not support hardware ranged breakpoints.")); | |
9229 | ||
9230 | bp_count = hw_breakpoint_used_count (); | |
9231 | bp_count += target_ranged_break_num_registers (); | |
9232 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
9233 | bp_count, 0); | |
9234 | if (can_use_bp < 0) | |
9235 | error (_("Hardware breakpoints used exceeds limit.")); | |
9236 | ||
f8eba3c6 | 9237 | arg = skip_spaces (arg); |
f1310107 TJB |
9238 | if (arg == NULL || arg[0] == '\0') |
9239 | error(_("No address range specified.")); | |
9240 | ||
f1310107 TJB |
9241 | init_linespec_result (&canonical_start); |
9242 | ||
f8eba3c6 TT |
9243 | arg_start = arg; |
9244 | parse_breakpoint_sals (&arg, &canonical_start); | |
f1310107 | 9245 | |
f8eba3c6 | 9246 | cleanup_bkpt = make_cleanup_destroy_linespec_result (&canonical_start); |
f1310107 TJB |
9247 | |
9248 | if (arg[0] != ',') | |
9249 | error (_("Too few arguments.")); | |
f8eba3c6 | 9250 | else if (VEC_empty (linespec_sals, canonical_start.sals)) |
f1310107 | 9251 | error (_("Could not find location of the beginning of the range.")); |
f8eba3c6 TT |
9252 | |
9253 | lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0); | |
9254 | ||
9255 | if (VEC_length (linespec_sals, canonical_start.sals) > 1 | |
9256 | || lsal_start->sals.nelts != 1) | |
f1310107 TJB |
9257 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
9258 | ||
f8eba3c6 TT |
9259 | sal_start = lsal_start->sals.sals[0]; |
9260 | addr_string_start = savestring (arg_start, arg - arg_start); | |
9261 | make_cleanup (xfree, addr_string_start); | |
f1310107 TJB |
9262 | |
9263 | arg++; /* Skip the comma. */ | |
f8eba3c6 | 9264 | arg = skip_spaces (arg); |
f1310107 TJB |
9265 | |
9266 | /* Parse the end location. */ | |
9267 | ||
f1310107 TJB |
9268 | init_linespec_result (&canonical_end); |
9269 | arg_start = arg; | |
9270 | ||
f8eba3c6 | 9271 | /* We call decode_line_full directly here instead of using |
f1310107 TJB |
9272 | parse_breakpoint_sals because we need to specify the start location's |
9273 | symtab and line as the default symtab and line for the end of the | |
9274 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
9275 | where +14 means 14 lines from the start location. */ | |
f8eba3c6 TT |
9276 | decode_line_full (&arg, DECODE_LINE_FUNFIRSTLINE, |
9277 | sal_start.symtab, sal_start.line, | |
9278 | &canonical_end, NULL, NULL); | |
9279 | ||
9280 | make_cleanup_destroy_linespec_result (&canonical_end); | |
f1310107 | 9281 | |
f8eba3c6 | 9282 | if (VEC_empty (linespec_sals, canonical_end.sals)) |
f1310107 | 9283 | error (_("Could not find location of the end of the range.")); |
f8eba3c6 TT |
9284 | |
9285 | lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0); | |
9286 | if (VEC_length (linespec_sals, canonical_end.sals) > 1 | |
9287 | || lsal_end->sals.nelts != 1) | |
f1310107 TJB |
9288 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
9289 | ||
f8eba3c6 TT |
9290 | sal_end = lsal_end->sals.sals[0]; |
9291 | addr_string_end = savestring (arg_start, arg - arg_start); | |
9292 | make_cleanup (xfree, addr_string_end); | |
f1310107 TJB |
9293 | |
9294 | end = find_breakpoint_range_end (sal_end); | |
9295 | if (sal_start.pc > end) | |
177b42fe | 9296 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
9297 | |
9298 | length = end - sal_start.pc + 1; | |
9299 | if (length < 0) | |
9300 | /* Length overflowed. */ | |
9301 | error (_("Address range too large.")); | |
9302 | else if (length == 1) | |
9303 | { | |
9304 | /* This range is simple enough to be handled by | |
9305 | the `hbreak' command. */ | |
9306 | hbreak_command (addr_string_start, 1); | |
9307 | ||
9308 | do_cleanups (cleanup_bkpt); | |
9309 | ||
9310 | return; | |
9311 | } | |
9312 | ||
9313 | /* Now set up the breakpoint. */ | |
9314 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 9315 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
9316 | set_breakpoint_count (breakpoint_count + 1); |
9317 | b->number = breakpoint_count; | |
9318 | b->disposition = disp_donttouch; | |
f8eba3c6 TT |
9319 | b->addr_string = xstrdup (addr_string_start); |
9320 | b->addr_string_range_end = xstrdup (addr_string_end); | |
f1310107 TJB |
9321 | b->loc->length = length; |
9322 | ||
f8eba3c6 | 9323 | do_cleanups (cleanup_bkpt); |
f1310107 TJB |
9324 | |
9325 | mention (b); | |
8d3788bd | 9326 | observer_notify_breakpoint_created (b); |
f1310107 TJB |
9327 | update_global_location_list (1); |
9328 | } | |
9329 | ||
4a64f543 MS |
9330 | /* Return non-zero if EXP is verified as constant. Returned zero |
9331 | means EXP is variable. Also the constant detection may fail for | |
9332 | some constant expressions and in such case still falsely return | |
9333 | zero. */ | |
2e6e3d9c | 9334 | |
65d79d4b SDJ |
9335 | static int |
9336 | watchpoint_exp_is_const (const struct expression *exp) | |
9337 | { | |
9338 | int i = exp->nelts; | |
9339 | ||
9340 | while (i > 0) | |
9341 | { | |
9342 | int oplenp, argsp; | |
9343 | ||
9344 | /* We are only interested in the descriptor of each element. */ | |
9345 | operator_length (exp, i, &oplenp, &argsp); | |
9346 | i -= oplenp; | |
9347 | ||
9348 | switch (exp->elts[i].opcode) | |
9349 | { | |
9350 | case BINOP_ADD: | |
9351 | case BINOP_SUB: | |
9352 | case BINOP_MUL: | |
9353 | case BINOP_DIV: | |
9354 | case BINOP_REM: | |
9355 | case BINOP_MOD: | |
9356 | case BINOP_LSH: | |
9357 | case BINOP_RSH: | |
9358 | case BINOP_LOGICAL_AND: | |
9359 | case BINOP_LOGICAL_OR: | |
9360 | case BINOP_BITWISE_AND: | |
9361 | case BINOP_BITWISE_IOR: | |
9362 | case BINOP_BITWISE_XOR: | |
9363 | case BINOP_EQUAL: | |
9364 | case BINOP_NOTEQUAL: | |
9365 | case BINOP_LESS: | |
9366 | case BINOP_GTR: | |
9367 | case BINOP_LEQ: | |
9368 | case BINOP_GEQ: | |
9369 | case BINOP_REPEAT: | |
9370 | case BINOP_COMMA: | |
9371 | case BINOP_EXP: | |
9372 | case BINOP_MIN: | |
9373 | case BINOP_MAX: | |
9374 | case BINOP_INTDIV: | |
9375 | case BINOP_CONCAT: | |
9376 | case BINOP_IN: | |
9377 | case BINOP_RANGE: | |
9378 | case TERNOP_COND: | |
9379 | case TERNOP_SLICE: | |
9380 | case TERNOP_SLICE_COUNT: | |
9381 | ||
9382 | case OP_LONG: | |
9383 | case OP_DOUBLE: | |
9384 | case OP_DECFLOAT: | |
9385 | case OP_LAST: | |
9386 | case OP_COMPLEX: | |
9387 | case OP_STRING: | |
9388 | case OP_BITSTRING: | |
9389 | case OP_ARRAY: | |
9390 | case OP_TYPE: | |
9391 | case OP_NAME: | |
9392 | case OP_OBJC_NSSTRING: | |
9393 | ||
9394 | case UNOP_NEG: | |
9395 | case UNOP_LOGICAL_NOT: | |
9396 | case UNOP_COMPLEMENT: | |
9397 | case UNOP_ADDR: | |
9398 | case UNOP_HIGH: | |
aeaa2474 | 9399 | case UNOP_CAST: |
4a64f543 MS |
9400 | /* Unary, binary and ternary operators: We have to check |
9401 | their operands. If they are constant, then so is the | |
9402 | result of that operation. For instance, if A and B are | |
9403 | determined to be constants, then so is "A + B". | |
9404 | ||
9405 | UNOP_IND is one exception to the rule above, because the | |
9406 | value of *ADDR is not necessarily a constant, even when | |
9407 | ADDR is. */ | |
65d79d4b SDJ |
9408 | break; |
9409 | ||
9410 | case OP_VAR_VALUE: | |
9411 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 9412 | |
65d79d4b | 9413 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
9414 | possible that a buggy compiler could mark a variable as |
9415 | constant even when it is not, and TYPE_CONST would return | |
9416 | true in this case, while SYMBOL_CLASS wouldn't. | |
9417 | ||
9418 | We also have to check for function symbols because they | |
9419 | are always constant. */ | |
65d79d4b SDJ |
9420 | { |
9421 | struct symbol *s = exp->elts[i + 2].symbol; | |
9422 | ||
9423 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
9424 | && SYMBOL_CLASS (s) != LOC_CONST | |
9425 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
9426 | return 0; | |
9427 | break; | |
9428 | } | |
9429 | ||
9430 | /* The default action is to return 0 because we are using | |
9431 | the optimistic approach here: If we don't know something, | |
9432 | then it is not a constant. */ | |
9433 | default: | |
9434 | return 0; | |
9435 | } | |
9436 | } | |
9437 | ||
9438 | return 1; | |
9439 | } | |
9440 | ||
3a5c3e22 PA |
9441 | /* Implement the "dtor" breakpoint_ops method for watchpoints. */ |
9442 | ||
9443 | static void | |
9444 | dtor_watchpoint (struct breakpoint *self) | |
9445 | { | |
9446 | struct watchpoint *w = (struct watchpoint *) self; | |
9447 | ||
9448 | xfree (w->cond_exp); | |
9449 | xfree (w->exp); | |
9450 | xfree (w->exp_string); | |
9451 | xfree (w->exp_string_reparse); | |
9452 | value_free (w->val); | |
9453 | ||
9454 | base_breakpoint_ops.dtor (self); | |
9455 | } | |
9456 | ||
348d480f PA |
9457 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
9458 | ||
9459 | static void | |
9460 | re_set_watchpoint (struct breakpoint *b) | |
9461 | { | |
3a5c3e22 PA |
9462 | struct watchpoint *w = (struct watchpoint *) b; |
9463 | ||
348d480f PA |
9464 | /* Watchpoint can be either on expression using entirely global |
9465 | variables, or it can be on local variables. | |
9466 | ||
9467 | Watchpoints of the first kind are never auto-deleted, and even | |
9468 | persist across program restarts. Since they can use variables | |
9469 | from shared libraries, we need to reparse expression as libraries | |
9470 | are loaded and unloaded. | |
9471 | ||
9472 | Watchpoints on local variables can also change meaning as result | |
9473 | of solib event. For example, if a watchpoint uses both a local | |
9474 | and a global variables in expression, it's a local watchpoint, | |
9475 | but unloading of a shared library will make the expression | |
9476 | invalid. This is not a very common use case, but we still | |
9477 | re-evaluate expression, to avoid surprises to the user. | |
9478 | ||
9479 | Note that for local watchpoints, we re-evaluate it only if | |
9480 | watchpoints frame id is still valid. If it's not, it means the | |
9481 | watchpoint is out of scope and will be deleted soon. In fact, | |
9482 | I'm not sure we'll ever be called in this case. | |
9483 | ||
9484 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 9485 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 9486 | |
3a5c3e22 PA |
9487 | Don't do anything about disabled watchpoints, since they will be |
9488 | reevaluated again when enabled. */ | |
9489 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
9490 | } |
9491 | ||
77b06cd7 TJB |
9492 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
9493 | ||
9494 | static int | |
9495 | insert_watchpoint (struct bp_location *bl) | |
9496 | { | |
3a5c3e22 PA |
9497 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
9498 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
9499 | |
9500 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 9501 | w->cond_exp); |
77b06cd7 TJB |
9502 | } |
9503 | ||
9504 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
9505 | ||
9506 | static int | |
9507 | remove_watchpoint (struct bp_location *bl) | |
9508 | { | |
3a5c3e22 PA |
9509 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
9510 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
9511 | |
9512 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 9513 | w->cond_exp); |
e09342b5 TJB |
9514 | } |
9515 | ||
e09342b5 | 9516 | static int |
348d480f | 9517 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
09ac7c10 TT |
9518 | struct address_space *aspace, CORE_ADDR bp_addr, |
9519 | const struct target_waitstatus *ws) | |
e09342b5 | 9520 | { |
348d480f | 9521 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 9522 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 9523 | |
348d480f PA |
9524 | /* Continuable hardware watchpoints are treated as non-existent if the |
9525 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
9526 | some data address). Otherwise gdb won't stop on a break instruction | |
9527 | in the code (not from a breakpoint) when a hardware watchpoint has | |
9528 | been defined. Also skip watchpoints which we know did not trigger | |
9529 | (did not match the data address). */ | |
9530 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 9531 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 9532 | return 0; |
9c06b0b4 | 9533 | |
348d480f | 9534 | return 1; |
9c06b0b4 TJB |
9535 | } |
9536 | ||
348d480f PA |
9537 | static void |
9538 | check_status_watchpoint (bpstat bs) | |
9c06b0b4 | 9539 | { |
348d480f | 9540 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 9541 | |
348d480f | 9542 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
9543 | } |
9544 | ||
9545 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 9546 | hardware watchpoints. */ |
9c06b0b4 TJB |
9547 | |
9548 | static int | |
348d480f | 9549 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 9550 | { |
3a5c3e22 PA |
9551 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
9552 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
9553 | |
9554 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
9555 | } |
9556 | ||
9557 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 9558 | hardware watchpoints. */ |
9c06b0b4 TJB |
9559 | |
9560 | static int | |
348d480f | 9561 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 9562 | { |
efa80663 PA |
9563 | /* Read and access watchpoints only work with hardware support. */ |
9564 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
9565 | } |
9566 | ||
9c06b0b4 | 9567 | static enum print_stop_action |
348d480f | 9568 | print_it_watchpoint (bpstat bs) |
9c06b0b4 | 9569 | { |
348d480f PA |
9570 | struct cleanup *old_chain; |
9571 | struct breakpoint *b; | |
9572 | const struct bp_location *bl; | |
9573 | struct ui_stream *stb; | |
9574 | enum print_stop_action result; | |
3a5c3e22 | 9575 | struct watchpoint *w; |
79a45e25 | 9576 | struct ui_out *uiout = current_uiout; |
348d480f PA |
9577 | |
9578 | gdb_assert (bs->bp_location_at != NULL); | |
9579 | ||
9580 | bl = bs->bp_location_at; | |
9581 | b = bs->breakpoint_at; | |
3a5c3e22 | 9582 | w = (struct watchpoint *) b; |
348d480f PA |
9583 | |
9584 | stb = ui_out_stream_new (uiout); | |
9585 | old_chain = make_cleanup_ui_out_stream_delete (stb); | |
9c06b0b4 TJB |
9586 | |
9587 | switch (b->type) | |
9588 | { | |
348d480f | 9589 | case bp_watchpoint: |
9c06b0b4 TJB |
9590 | case bp_hardware_watchpoint: |
9591 | annotate_watchpoint (b->number); | |
9592 | if (ui_out_is_mi_like_p (uiout)) | |
9593 | ui_out_field_string | |
9594 | (uiout, "reason", | |
9595 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
9596 | mention (b); |
9597 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
9598 | ui_out_text (uiout, "\nOld value = "); | |
9599 | watchpoint_value_print (bs->old_val, stb->stream); | |
9600 | ui_out_field_stream (uiout, "old", stb); | |
9601 | ui_out_text (uiout, "\nNew value = "); | |
3a5c3e22 | 9602 | watchpoint_value_print (w->val, stb->stream); |
348d480f PA |
9603 | ui_out_field_stream (uiout, "new", stb); |
9604 | ui_out_text (uiout, "\n"); | |
9605 | /* More than one watchpoint may have been triggered. */ | |
9606 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
9607 | break; |
9608 | ||
9609 | case bp_read_watchpoint: | |
9610 | if (ui_out_is_mi_like_p (uiout)) | |
9611 | ui_out_field_string | |
9612 | (uiout, "reason", | |
9613 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
9614 | mention (b); |
9615 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
9616 | ui_out_text (uiout, "\nValue = "); | |
3a5c3e22 | 9617 | watchpoint_value_print (w->val, stb->stream); |
348d480f PA |
9618 | ui_out_field_stream (uiout, "value", stb); |
9619 | ui_out_text (uiout, "\n"); | |
9620 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
9621 | break; |
9622 | ||
9623 | case bp_access_watchpoint: | |
348d480f PA |
9624 | if (bs->old_val != NULL) |
9625 | { | |
9626 | annotate_watchpoint (b->number); | |
9627 | if (ui_out_is_mi_like_p (uiout)) | |
9628 | ui_out_field_string | |
9629 | (uiout, "reason", | |
9630 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
9631 | mention (b); | |
9632 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
9633 | ui_out_text (uiout, "\nOld value = "); | |
9634 | watchpoint_value_print (bs->old_val, stb->stream); | |
9635 | ui_out_field_stream (uiout, "old", stb); | |
9636 | ui_out_text (uiout, "\nNew value = "); | |
9637 | } | |
9638 | else | |
9639 | { | |
9640 | mention (b); | |
9641 | if (ui_out_is_mi_like_p (uiout)) | |
9642 | ui_out_field_string | |
9643 | (uiout, "reason", | |
9644 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
9645 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
9646 | ui_out_text (uiout, "\nValue = "); | |
9647 | } | |
3a5c3e22 | 9648 | watchpoint_value_print (w->val, stb->stream); |
348d480f PA |
9649 | ui_out_field_stream (uiout, "new", stb); |
9650 | ui_out_text (uiout, "\n"); | |
9651 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
9652 | break; |
9653 | default: | |
348d480f | 9654 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
9655 | } |
9656 | ||
348d480f PA |
9657 | do_cleanups (old_chain); |
9658 | return result; | |
9659 | } | |
9660 | ||
9661 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
9662 | watchpoints. */ | |
9663 | ||
9664 | static void | |
9665 | print_mention_watchpoint (struct breakpoint *b) | |
9666 | { | |
9667 | struct cleanup *ui_out_chain; | |
3a5c3e22 | 9668 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 9669 | struct ui_out *uiout = current_uiout; |
348d480f PA |
9670 | |
9671 | switch (b->type) | |
9672 | { | |
9673 | case bp_watchpoint: | |
9674 | ui_out_text (uiout, "Watchpoint "); | |
9675 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
9676 | break; | |
9677 | case bp_hardware_watchpoint: | |
9678 | ui_out_text (uiout, "Hardware watchpoint "); | |
9679 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
9680 | break; | |
9681 | case bp_read_watchpoint: | |
9682 | ui_out_text (uiout, "Hardware read watchpoint "); | |
9683 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
9684 | break; | |
9685 | case bp_access_watchpoint: | |
9686 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
9687 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
9688 | break; | |
9689 | default: | |
9690 | internal_error (__FILE__, __LINE__, | |
9691 | _("Invalid hardware watchpoint type.")); | |
9692 | } | |
9693 | ||
9694 | ui_out_field_int (uiout, "number", b->number); | |
9695 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 9696 | ui_out_field_string (uiout, "exp", w->exp_string); |
348d480f PA |
9697 | do_cleanups (ui_out_chain); |
9698 | } | |
9699 | ||
9700 | /* Implement the "print_recreate" breakpoint_ops method for | |
9701 | watchpoints. */ | |
9702 | ||
9703 | static void | |
9704 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
9705 | { | |
3a5c3e22 PA |
9706 | struct watchpoint *w = (struct watchpoint *) b; |
9707 | ||
348d480f PA |
9708 | switch (b->type) |
9709 | { | |
9710 | case bp_watchpoint: | |
9711 | case bp_hardware_watchpoint: | |
9712 | fprintf_unfiltered (fp, "watch"); | |
9713 | break; | |
9714 | case bp_read_watchpoint: | |
9715 | fprintf_unfiltered (fp, "rwatch"); | |
9716 | break; | |
9717 | case bp_access_watchpoint: | |
9718 | fprintf_unfiltered (fp, "awatch"); | |
9719 | break; | |
9720 | default: | |
9721 | internal_error (__FILE__, __LINE__, | |
9722 | _("Invalid watchpoint type.")); | |
9723 | } | |
9724 | ||
3a5c3e22 | 9725 | fprintf_unfiltered (fp, " %s", w->exp_string); |
d9b3f62e | 9726 | print_recreate_thread (b, fp); |
348d480f PA |
9727 | } |
9728 | ||
9729 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ | |
9730 | ||
2060206e | 9731 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
9732 | |
9733 | /* Implement the "insert" breakpoint_ops method for | |
9734 | masked hardware watchpoints. */ | |
9735 | ||
9736 | static int | |
9737 | insert_masked_watchpoint (struct bp_location *bl) | |
9738 | { | |
3a5c3e22 PA |
9739 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
9740 | ||
9741 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
9742 | bl->watchpoint_type); |
9743 | } | |
9744 | ||
9745 | /* Implement the "remove" breakpoint_ops method for | |
9746 | masked hardware watchpoints. */ | |
9747 | ||
9748 | static int | |
9749 | remove_masked_watchpoint (struct bp_location *bl) | |
9750 | { | |
3a5c3e22 PA |
9751 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
9752 | ||
9753 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
9754 | bl->watchpoint_type); |
9755 | } | |
9756 | ||
9757 | /* Implement the "resources_needed" breakpoint_ops method for | |
9758 | masked hardware watchpoints. */ | |
9759 | ||
9760 | static int | |
9761 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
9762 | { | |
3a5c3e22 PA |
9763 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
9764 | ||
9765 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
9766 | } |
9767 | ||
9768 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
9769 | masked hardware watchpoints. */ | |
9770 | ||
9771 | static int | |
9772 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
9773 | { | |
9774 | return 0; | |
9775 | } | |
9776 | ||
9777 | /* Implement the "print_it" breakpoint_ops method for | |
9778 | masked hardware watchpoints. */ | |
9779 | ||
9780 | static enum print_stop_action | |
9781 | print_it_masked_watchpoint (bpstat bs) | |
9782 | { | |
9783 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 9784 | struct ui_out *uiout = current_uiout; |
348d480f PA |
9785 | |
9786 | /* Masked watchpoints have only one location. */ | |
9787 | gdb_assert (b->loc && b->loc->next == NULL); | |
9788 | ||
9789 | switch (b->type) | |
9790 | { | |
9791 | case bp_hardware_watchpoint: | |
9792 | annotate_watchpoint (b->number); | |
9793 | if (ui_out_is_mi_like_p (uiout)) | |
9794 | ui_out_field_string | |
9795 | (uiout, "reason", | |
9796 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
9797 | break; | |
9798 | ||
9799 | case bp_read_watchpoint: | |
9800 | if (ui_out_is_mi_like_p (uiout)) | |
9801 | ui_out_field_string | |
9802 | (uiout, "reason", | |
9803 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
9804 | break; | |
9805 | ||
9806 | case bp_access_watchpoint: | |
9807 | if (ui_out_is_mi_like_p (uiout)) | |
9808 | ui_out_field_string | |
9809 | (uiout, "reason", | |
9810 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
9811 | break; | |
9812 | default: | |
9813 | internal_error (__FILE__, __LINE__, | |
9814 | _("Invalid hardware watchpoint type.")); | |
9815 | } | |
9816 | ||
9817 | mention (b); | |
9c06b0b4 TJB |
9818 | ui_out_text (uiout, _("\n\ |
9819 | Check the underlying instruction at PC for the memory\n\ | |
9820 | address and value which triggered this watchpoint.\n")); | |
9821 | ui_out_text (uiout, "\n"); | |
9822 | ||
9823 | /* More than one watchpoint may have been triggered. */ | |
9824 | return PRINT_UNKNOWN; | |
9825 | } | |
9826 | ||
9827 | /* Implement the "print_one_detail" breakpoint_ops method for | |
9828 | masked hardware watchpoints. */ | |
9829 | ||
9830 | static void | |
9831 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
9832 | struct ui_out *uiout) | |
9833 | { | |
3a5c3e22 PA |
9834 | struct watchpoint *w = (struct watchpoint *) b; |
9835 | ||
9c06b0b4 TJB |
9836 | /* Masked watchpoints have only one location. */ |
9837 | gdb_assert (b->loc && b->loc->next == NULL); | |
9838 | ||
9839 | ui_out_text (uiout, "\tmask "); | |
3a5c3e22 | 9840 | ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask); |
9c06b0b4 TJB |
9841 | ui_out_text (uiout, "\n"); |
9842 | } | |
9843 | ||
9844 | /* Implement the "print_mention" breakpoint_ops method for | |
9845 | masked hardware watchpoints. */ | |
9846 | ||
9847 | static void | |
9848 | print_mention_masked_watchpoint (struct breakpoint *b) | |
9849 | { | |
3a5c3e22 | 9850 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 9851 | struct ui_out *uiout = current_uiout; |
9c06b0b4 TJB |
9852 | struct cleanup *ui_out_chain; |
9853 | ||
9854 | switch (b->type) | |
9855 | { | |
9856 | case bp_hardware_watchpoint: | |
9857 | ui_out_text (uiout, "Masked hardware watchpoint "); | |
9858 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
9859 | break; | |
9860 | case bp_read_watchpoint: | |
9861 | ui_out_text (uiout, "Masked hardware read watchpoint "); | |
9862 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
9863 | break; | |
9864 | case bp_access_watchpoint: | |
9865 | ui_out_text (uiout, "Masked hardware access (read/write) watchpoint "); | |
9866 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
9867 | break; | |
9868 | default: | |
9869 | internal_error (__FILE__, __LINE__, | |
9870 | _("Invalid hardware watchpoint type.")); | |
9871 | } | |
9872 | ||
9873 | ui_out_field_int (uiout, "number", b->number); | |
9874 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 9875 | ui_out_field_string (uiout, "exp", w->exp_string); |
9c06b0b4 TJB |
9876 | do_cleanups (ui_out_chain); |
9877 | } | |
9878 | ||
9879 | /* Implement the "print_recreate" breakpoint_ops method for | |
9880 | masked hardware watchpoints. */ | |
9881 | ||
9882 | static void | |
9883 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
9884 | { | |
3a5c3e22 | 9885 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
9886 | char tmp[40]; |
9887 | ||
9888 | switch (b->type) | |
9889 | { | |
9890 | case bp_hardware_watchpoint: | |
9891 | fprintf_unfiltered (fp, "watch"); | |
9892 | break; | |
9893 | case bp_read_watchpoint: | |
9894 | fprintf_unfiltered (fp, "rwatch"); | |
9895 | break; | |
9896 | case bp_access_watchpoint: | |
9897 | fprintf_unfiltered (fp, "awatch"); | |
9898 | break; | |
9899 | default: | |
9900 | internal_error (__FILE__, __LINE__, | |
9901 | _("Invalid hardware watchpoint type.")); | |
9902 | } | |
9903 | ||
3a5c3e22 PA |
9904 | sprintf_vma (tmp, w->hw_wp_mask); |
9905 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); | |
d9b3f62e | 9906 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
9907 | } |
9908 | ||
9909 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
9910 | ||
2060206e | 9911 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
9912 | |
9913 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
9914 | ||
9915 | static int | |
9916 | is_masked_watchpoint (const struct breakpoint *b) | |
9917 | { | |
9918 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
9919 | } | |
9920 | ||
53a5351d JM |
9921 | /* accessflag: hw_write: watch write, |
9922 | hw_read: watch read, | |
9923 | hw_access: watch access (read or write) */ | |
c906108c | 9924 | static void |
84f4c1fe PM |
9925 | watch_command_1 (char *arg, int accessflag, int from_tty, |
9926 | int just_location, int internal) | |
c906108c | 9927 | { |
a9634178 | 9928 | volatile struct gdb_exception e; |
d983da9c | 9929 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c | 9930 | struct expression *exp; |
60e1c644 | 9931 | struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 9932 | struct value *val, *mark, *result; |
c906108c | 9933 | struct frame_info *frame; |
c906108c SS |
9934 | char *exp_start = NULL; |
9935 | char *exp_end = NULL; | |
9c06b0b4 TJB |
9936 | char *tok, *end_tok; |
9937 | int toklen = -1; | |
c906108c SS |
9938 | char *cond_start = NULL; |
9939 | char *cond_end = NULL; | |
c906108c | 9940 | enum bptype bp_type; |
37e4754d | 9941 | int thread = -1; |
0cf6dd15 | 9942 | int pc = 0; |
9c06b0b4 TJB |
9943 | /* Flag to indicate whether we are going to use masks for |
9944 | the hardware watchpoint. */ | |
9945 | int use_mask = 0; | |
9946 | CORE_ADDR mask = 0; | |
3a5c3e22 | 9947 | struct watchpoint *w; |
c906108c | 9948 | |
37e4754d LM |
9949 | /* Make sure that we actually have parameters to parse. */ |
9950 | if (arg != NULL && arg[0] != '\0') | |
9951 | { | |
9c06b0b4 | 9952 | char *value_start; |
37e4754d | 9953 | |
9c06b0b4 TJB |
9954 | /* Look for "parameter value" pairs at the end |
9955 | of the arguments string. */ | |
9956 | for (tok = arg + strlen (arg) - 1; tok > arg; tok--) | |
9957 | { | |
9958 | /* Skip whitespace at the end of the argument list. */ | |
9959 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
9960 | tok--; | |
9961 | ||
9962 | /* Find the beginning of the last token. | |
9963 | This is the value of the parameter. */ | |
9964 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
9965 | tok--; | |
9966 | value_start = tok + 1; | |
9967 | ||
9968 | /* Skip whitespace. */ | |
9969 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
9970 | tok--; | |
9971 | ||
9972 | end_tok = tok; | |
9973 | ||
9974 | /* Find the beginning of the second to last token. | |
9975 | This is the parameter itself. */ | |
9976 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
9977 | tok--; | |
9978 | tok++; | |
9979 | toklen = end_tok - tok + 1; | |
9980 | ||
9981 | if (toklen == 6 && !strncmp (tok, "thread", 6)) | |
9982 | { | |
9983 | /* At this point we've found a "thread" token, which means | |
9984 | the user is trying to set a watchpoint that triggers | |
9985 | only in a specific thread. */ | |
9986 | char *endp; | |
37e4754d | 9987 | |
9c06b0b4 TJB |
9988 | if (thread != -1) |
9989 | error(_("You can specify only one thread.")); | |
37e4754d | 9990 | |
9c06b0b4 TJB |
9991 | /* Extract the thread ID from the next token. */ |
9992 | thread = strtol (value_start, &endp, 0); | |
37e4754d | 9993 | |
9c06b0b4 TJB |
9994 | /* Check if the user provided a valid numeric value for the |
9995 | thread ID. */ | |
9996 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
9997 | error (_("Invalid thread ID specification %s."), value_start); | |
9998 | ||
9999 | /* Check if the thread actually exists. */ | |
10000 | if (!valid_thread_id (thread)) | |
10001 | error (_("Unknown thread %d."), thread); | |
10002 | } | |
10003 | else if (toklen == 4 && !strncmp (tok, "mask", 4)) | |
10004 | { | |
10005 | /* We've found a "mask" token, which means the user wants to | |
10006 | create a hardware watchpoint that is going to have the mask | |
10007 | facility. */ | |
10008 | struct value *mask_value, *mark; | |
37e4754d | 10009 | |
9c06b0b4 TJB |
10010 | if (use_mask) |
10011 | error(_("You can specify only one mask.")); | |
37e4754d | 10012 | |
9c06b0b4 | 10013 | use_mask = just_location = 1; |
37e4754d | 10014 | |
9c06b0b4 TJB |
10015 | mark = value_mark (); |
10016 | mask_value = parse_to_comma_and_eval (&value_start); | |
10017 | mask = value_as_address (mask_value); | |
10018 | value_free_to_mark (mark); | |
10019 | } | |
10020 | else | |
10021 | /* We didn't recognize what we found. We should stop here. */ | |
10022 | break; | |
37e4754d | 10023 | |
9c06b0b4 TJB |
10024 | /* Truncate the string and get rid of the "parameter value" pair before |
10025 | the arguments string is parsed by the parse_exp_1 function. */ | |
10026 | *tok = '\0'; | |
10027 | } | |
37e4754d LM |
10028 | } |
10029 | ||
10030 | /* Parse the rest of the arguments. */ | |
c906108c SS |
10031 | innermost_block = NULL; |
10032 | exp_start = arg; | |
10033 | exp = parse_exp_1 (&arg, 0, 0); | |
10034 | exp_end = arg; | |
fa8a61dc TT |
10035 | /* Remove trailing whitespace from the expression before saving it. |
10036 | This makes the eventual display of the expression string a bit | |
10037 | prettier. */ | |
10038 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
10039 | --exp_end; | |
10040 | ||
65d79d4b SDJ |
10041 | /* Checking if the expression is not constant. */ |
10042 | if (watchpoint_exp_is_const (exp)) | |
10043 | { | |
10044 | int len; | |
10045 | ||
10046 | len = exp_end - exp_start; | |
10047 | while (len > 0 && isspace (exp_start[len - 1])) | |
10048 | len--; | |
10049 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
10050 | } | |
10051 | ||
c906108c SS |
10052 | exp_valid_block = innermost_block; |
10053 | mark = value_mark (); | |
a1442452 | 10054 | fetch_subexp_value (exp, &pc, &val, &result, NULL); |
06a64a0b TT |
10055 | |
10056 | if (just_location) | |
10057 | { | |
9c06b0b4 TJB |
10058 | int ret; |
10059 | ||
06a64a0b | 10060 | exp_valid_block = NULL; |
a1442452 | 10061 | val = value_addr (result); |
06a64a0b TT |
10062 | release_value (val); |
10063 | value_free_to_mark (mark); | |
9c06b0b4 TJB |
10064 | |
10065 | if (use_mask) | |
10066 | { | |
10067 | ret = target_masked_watch_num_registers (value_as_address (val), | |
10068 | mask); | |
10069 | if (ret == -1) | |
10070 | error (_("This target does not support masked watchpoints.")); | |
10071 | else if (ret == -2) | |
10072 | error (_("Invalid mask or memory region.")); | |
10073 | } | |
06a64a0b TT |
10074 | } |
10075 | else if (val != NULL) | |
fa4727a6 | 10076 | release_value (val); |
c906108c | 10077 | |
e9cafbcc TT |
10078 | tok = skip_spaces (arg); |
10079 | end_tok = skip_to_space (tok); | |
c906108c SS |
10080 | |
10081 | toklen = end_tok - tok; | |
10082 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
10083 | { | |
2d134ed3 PA |
10084 | struct expression *cond; |
10085 | ||
60e1c644 | 10086 | innermost_block = NULL; |
c906108c SS |
10087 | tok = cond_start = end_tok + 1; |
10088 | cond = parse_exp_1 (&tok, 0, 0); | |
60e1c644 PA |
10089 | |
10090 | /* The watchpoint expression may not be local, but the condition | |
10091 | may still be. E.g.: `watch global if local > 0'. */ | |
10092 | cond_exp_valid_block = innermost_block; | |
10093 | ||
2d134ed3 | 10094 | xfree (cond); |
c906108c SS |
10095 | cond_end = tok; |
10096 | } | |
10097 | if (*tok) | |
8a3fe4f8 | 10098 | error (_("Junk at end of command.")); |
c906108c | 10099 | |
53a5351d | 10100 | if (accessflag == hw_read) |
c5aa993b | 10101 | bp_type = bp_read_watchpoint; |
53a5351d | 10102 | else if (accessflag == hw_access) |
c5aa993b JM |
10103 | bp_type = bp_access_watchpoint; |
10104 | else | |
10105 | bp_type = bp_hardware_watchpoint; | |
c906108c | 10106 | |
d983da9c | 10107 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
10108 | |
10109 | /* If the expression is "local", then set up a "watchpoint scope" | |
10110 | breakpoint at the point where we've left the scope of the watchpoint | |
10111 | expression. Create the scope breakpoint before the watchpoint, so | |
10112 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 10113 | if (exp_valid_block && frame) |
d983da9c | 10114 | { |
edb3359d DJ |
10115 | if (frame_id_p (frame_unwind_caller_id (frame))) |
10116 | { | |
10117 | scope_breakpoint | |
a6d9a66e UW |
10118 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
10119 | frame_unwind_caller_pc (frame), | |
06edf0c0 PA |
10120 | bp_watchpoint_scope, |
10121 | &momentary_breakpoint_ops); | |
d983da9c | 10122 | |
edb3359d | 10123 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 10124 | |
edb3359d DJ |
10125 | /* Automatically delete the breakpoint when it hits. */ |
10126 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 10127 | |
edb3359d DJ |
10128 | /* Only break in the proper frame (help with recursion). */ |
10129 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 10130 | |
edb3359d | 10131 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
10132 | scope_breakpoint->loc->gdbarch |
10133 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
10134 | scope_breakpoint->loc->requested_address |
10135 | = frame_unwind_caller_pc (frame); | |
10136 | scope_breakpoint->loc->address | |
a6d9a66e UW |
10137 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
10138 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
10139 | scope_breakpoint->type); |
10140 | } | |
d983da9c DJ |
10141 | } |
10142 | ||
c906108c | 10143 | /* Now set up the breakpoint. */ |
3a5c3e22 PA |
10144 | |
10145 | w = XCNEW (struct watchpoint); | |
10146 | b = &w->base; | |
348d480f | 10147 | if (use_mask) |
3a5c3e22 PA |
10148 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
10149 | &masked_watchpoint_breakpoint_ops); | |
348d480f | 10150 | else |
3a5c3e22 PA |
10151 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
10152 | &watchpoint_breakpoint_ops); | |
37e4754d | 10153 | b->thread = thread; |
b5de0fa7 | 10154 | b->disposition = disp_donttouch; |
348d480f | 10155 | b->pspace = current_program_space; |
3a5c3e22 PA |
10156 | w->exp = exp; |
10157 | w->exp_valid_block = exp_valid_block; | |
10158 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
10159 | if (just_location) |
10160 | { | |
10161 | struct type *t = value_type (val); | |
10162 | CORE_ADDR addr = value_as_address (val); | |
10163 | char *name; | |
10164 | ||
10165 | t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); | |
10166 | name = type_to_string (t); | |
10167 | ||
3a5c3e22 | 10168 | w->exp_string_reparse = xstrprintf ("* (%s *) %s", name, |
d63d0675 | 10169 | core_addr_to_string (addr)); |
06a64a0b TT |
10170 | xfree (name); |
10171 | ||
3a5c3e22 | 10172 | w->exp_string = xstrprintf ("-location %.*s", |
d63d0675 JK |
10173 | (int) (exp_end - exp_start), exp_start); |
10174 | ||
06a64a0b TT |
10175 | /* The above expression is in C. */ |
10176 | b->language = language_c; | |
10177 | } | |
10178 | else | |
3a5c3e22 | 10179 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
9c06b0b4 TJB |
10180 | |
10181 | if (use_mask) | |
10182 | { | |
3a5c3e22 | 10183 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
10184 | } |
10185 | else | |
10186 | { | |
3a5c3e22 PA |
10187 | w->val = val; |
10188 | w->val_valid = 1; | |
9c06b0b4 | 10189 | } |
77b06cd7 | 10190 | |
c906108c SS |
10191 | if (cond_start) |
10192 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
10193 | else | |
10194 | b->cond_string = 0; | |
c5aa993b | 10195 | |
c906108c | 10196 | if (frame) |
f6bc2008 | 10197 | { |
3a5c3e22 PA |
10198 | w->watchpoint_frame = get_frame_id (frame); |
10199 | w->watchpoint_thread = inferior_ptid; | |
f6bc2008 | 10200 | } |
c906108c | 10201 | else |
f6bc2008 | 10202 | { |
3a5c3e22 PA |
10203 | w->watchpoint_frame = null_frame_id; |
10204 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 10205 | } |
c906108c | 10206 | |
d983da9c | 10207 | if (scope_breakpoint != NULL) |
c906108c | 10208 | { |
d983da9c DJ |
10209 | /* The scope breakpoint is related to the watchpoint. We will |
10210 | need to act on them together. */ | |
10211 | b->related_breakpoint = scope_breakpoint; | |
10212 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 10213 | } |
d983da9c | 10214 | |
06a64a0b TT |
10215 | if (!just_location) |
10216 | value_free_to_mark (mark); | |
2d134ed3 | 10217 | |
a9634178 TJB |
10218 | TRY_CATCH (e, RETURN_MASK_ALL) |
10219 | { | |
10220 | /* Finally update the new watchpoint. This creates the locations | |
10221 | that should be inserted. */ | |
3a5c3e22 | 10222 | update_watchpoint (w, 1); |
a9634178 TJB |
10223 | } |
10224 | if (e.reason < 0) | |
10225 | { | |
10226 | delete_breakpoint (b); | |
10227 | throw_exception (e); | |
10228 | } | |
10229 | ||
3ea46bff | 10230 | install_breakpoint (internal, b, 1); |
c906108c SS |
10231 | } |
10232 | ||
e09342b5 | 10233 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 10234 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 10235 | |
c906108c | 10236 | static int |
a9634178 | 10237 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
10238 | { |
10239 | int found_memory_cnt = 0; | |
2e70b7b9 | 10240 | struct value *head = v; |
c906108c SS |
10241 | |
10242 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 10243 | if (!can_use_hw_watchpoints) |
c906108c | 10244 | return 0; |
c5aa993b | 10245 | |
5c44784c JM |
10246 | /* Make sure that the value of the expression depends only upon |
10247 | memory contents, and values computed from them within GDB. If we | |
10248 | find any register references or function calls, we can't use a | |
10249 | hardware watchpoint. | |
10250 | ||
10251 | The idea here is that evaluating an expression generates a series | |
10252 | of values, one holding the value of every subexpression. (The | |
10253 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
10254 | a*b+c.) GDB's values hold almost enough information to establish | |
10255 | the criteria given above --- they identify memory lvalues, | |
10256 | register lvalues, computed values, etcetera. So we can evaluate | |
10257 | the expression, and then scan the chain of values that leaves | |
10258 | behind to decide whether we can detect any possible change to the | |
10259 | expression's final value using only hardware watchpoints. | |
10260 | ||
10261 | However, I don't think that the values returned by inferior | |
10262 | function calls are special in any way. So this function may not | |
10263 | notice that an expression involving an inferior function call | |
10264 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 10265 | for (; v; v = value_next (v)) |
c906108c | 10266 | { |
5c44784c | 10267 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 10268 | { |
8464be76 DJ |
10269 | if (v != head && value_lazy (v)) |
10270 | /* A lazy memory lvalue in the chain is one that GDB never | |
10271 | needed to fetch; we either just used its address (e.g., | |
10272 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
10273 | in `a,b'). This doesn't apply to HEAD; if that is | |
10274 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 10275 | ; |
53a5351d | 10276 | else |
5c44784c JM |
10277 | { |
10278 | /* Ahh, memory we actually used! Check if we can cover | |
10279 | it with hardware watchpoints. */ | |
df407dfe | 10280 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
10281 | |
10282 | /* We only watch structs and arrays if user asked for it | |
10283 | explicitly, never if they just happen to appear in a | |
10284 | middle of some value chain. */ | |
10285 | if (v == head | |
10286 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
10287 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
10288 | { | |
42ae5230 | 10289 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
10290 | int len; |
10291 | int num_regs; | |
10292 | ||
a9634178 | 10293 | len = (target_exact_watchpoints |
e09342b5 TJB |
10294 | && is_scalar_type_recursive (vtype))? |
10295 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 10296 | |
e09342b5 TJB |
10297 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
10298 | if (!num_regs) | |
2e70b7b9 MS |
10299 | return 0; |
10300 | else | |
e09342b5 | 10301 | found_memory_cnt += num_regs; |
2e70b7b9 | 10302 | } |
5c44784c | 10303 | } |
c5aa993b | 10304 | } |
5086187c AC |
10305 | else if (VALUE_LVAL (v) != not_lval |
10306 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 10307 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 10308 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 10309 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
10310 | } |
10311 | ||
10312 | /* The expression itself looks suitable for using a hardware | |
10313 | watchpoint, but give the target machine a chance to reject it. */ | |
10314 | return found_memory_cnt; | |
10315 | } | |
10316 | ||
8b93c638 | 10317 | void |
84f4c1fe | 10318 | watch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 10319 | { |
84f4c1fe | 10320 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
10321 | } |
10322 | ||
10323 | /* A helper function that looks for an argument at the start of a | |
10324 | string. The argument must also either be at the end of the string, | |
10325 | or be followed by whitespace. Returns 1 if it finds the argument, | |
10326 | 0 otherwise. If the argument is found, it updates *STR. */ | |
10327 | ||
10328 | static int | |
10329 | check_for_argument (char **str, char *arg, int arg_len) | |
10330 | { | |
10331 | if (strncmp (*str, arg, arg_len) == 0 | |
10332 | && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len]))) | |
10333 | { | |
10334 | *str += arg_len; | |
10335 | return 1; | |
10336 | } | |
10337 | return 0; | |
10338 | } | |
10339 | ||
10340 | /* A helper function that looks for the "-location" argument and then | |
10341 | calls watch_command_1. */ | |
10342 | ||
10343 | static void | |
10344 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
10345 | { | |
10346 | int just_location = 0; | |
10347 | ||
10348 | if (arg | |
10349 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
10350 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
10351 | { | |
e9cafbcc | 10352 | arg = skip_spaces (arg); |
06a64a0b TT |
10353 | just_location = 1; |
10354 | } | |
10355 | ||
84f4c1fe | 10356 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 10357 | } |
8926118c | 10358 | |
c5aa993b | 10359 | static void |
fba45db2 | 10360 | watch_command (char *arg, int from_tty) |
c906108c | 10361 | { |
06a64a0b | 10362 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
10363 | } |
10364 | ||
8b93c638 | 10365 | void |
84f4c1fe | 10366 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 10367 | { |
84f4c1fe | 10368 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 10369 | } |
8926118c | 10370 | |
c5aa993b | 10371 | static void |
fba45db2 | 10372 | rwatch_command (char *arg, int from_tty) |
c906108c | 10373 | { |
06a64a0b | 10374 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
10375 | } |
10376 | ||
8b93c638 | 10377 | void |
84f4c1fe | 10378 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 10379 | { |
84f4c1fe | 10380 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 10381 | } |
8926118c | 10382 | |
c5aa993b | 10383 | static void |
fba45db2 | 10384 | awatch_command (char *arg, int from_tty) |
c906108c | 10385 | { |
06a64a0b | 10386 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 10387 | } |
c906108c | 10388 | \f |
c5aa993b | 10389 | |
43ff13b4 | 10390 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
10391 | because it uses the mechanisms of breakpoints. */ |
10392 | ||
bfec99b2 PA |
10393 | struct until_break_command_continuation_args |
10394 | { | |
10395 | struct breakpoint *breakpoint; | |
10396 | struct breakpoint *breakpoint2; | |
186c406b | 10397 | int thread_num; |
bfec99b2 PA |
10398 | }; |
10399 | ||
43ff13b4 | 10400 | /* This function is called by fetch_inferior_event via the |
4a64f543 | 10401 | cmd_continuation pointer, to complete the until command. It takes |
43ff13b4 | 10402 | care of cleaning up the temporary breakpoints set up by the until |
4a64f543 | 10403 | command. */ |
c2c6d25f | 10404 | static void |
fa4cd53f | 10405 | until_break_command_continuation (void *arg, int err) |
43ff13b4 | 10406 | { |
bfec99b2 PA |
10407 | struct until_break_command_continuation_args *a = arg; |
10408 | ||
10409 | delete_breakpoint (a->breakpoint); | |
10410 | if (a->breakpoint2) | |
10411 | delete_breakpoint (a->breakpoint2); | |
186c406b | 10412 | delete_longjmp_breakpoint (a->thread_num); |
43ff13b4 JM |
10413 | } |
10414 | ||
c906108c | 10415 | void |
ae66c1fc | 10416 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
10417 | { |
10418 | struct symtabs_and_lines sals; | |
10419 | struct symtab_and_line sal; | |
206415a3 | 10420 | struct frame_info *frame = get_selected_frame (NULL); |
883bc8d1 PA |
10421 | struct gdbarch *frame_gdbarch = get_frame_arch (frame); |
10422 | struct frame_id stack_frame_id = get_stack_frame_id (frame); | |
10423 | struct frame_id caller_frame_id = frame_unwind_caller_id (frame); | |
c906108c | 10424 | struct breakpoint *breakpoint; |
f107f563 | 10425 | struct breakpoint *breakpoint2 = NULL; |
c906108c | 10426 | struct cleanup *old_chain; |
186c406b TT |
10427 | int thread; |
10428 | struct thread_info *tp; | |
c906108c SS |
10429 | |
10430 | clear_proceed_status (); | |
10431 | ||
10432 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 10433 | this function. */ |
c5aa993b | 10434 | |
1bfeeb0f | 10435 | if (last_displayed_sal_is_valid ()) |
f8eba3c6 | 10436 | sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE, |
1bfeeb0f | 10437 | get_last_displayed_symtab (), |
f8eba3c6 | 10438 | get_last_displayed_line ()); |
c906108c | 10439 | else |
f8eba3c6 TT |
10440 | sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE, |
10441 | (struct symtab *) NULL, 0); | |
c5aa993b | 10442 | |
c906108c | 10443 | if (sals.nelts != 1) |
8a3fe4f8 | 10444 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 10445 | |
c906108c | 10446 | sal = sals.sals[0]; |
4a64f543 | 10447 | xfree (sals.sals); /* malloc'd, so freed. */ |
c5aa993b | 10448 | |
c906108c | 10449 | if (*arg) |
8a3fe4f8 | 10450 | error (_("Junk at end of arguments.")); |
c5aa993b | 10451 | |
c906108c | 10452 | resolve_sal_pc (&sal); |
c5aa993b | 10453 | |
186c406b TT |
10454 | tp = inferior_thread (); |
10455 | thread = tp->num; | |
10456 | ||
883bc8d1 PA |
10457 | old_chain = make_cleanup (null_cleanup, NULL); |
10458 | ||
10459 | /* Installing a breakpoint invalidates the frame chain (as it may | |
10460 | need to switch threads), so do any frame handling first. */ | |
10461 | ||
ae66c1fc EZ |
10462 | /* Keep within the current frame, or in frames called by the current |
10463 | one. */ | |
edb3359d | 10464 | |
883bc8d1 | 10465 | if (frame_id_p (caller_frame_id)) |
c906108c | 10466 | { |
883bc8d1 PA |
10467 | struct symtab_and_line sal2; |
10468 | ||
10469 | sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0); | |
10470 | sal2.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e | 10471 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
883bc8d1 PA |
10472 | sal2, |
10473 | caller_frame_id, | |
f107f563 VP |
10474 | bp_until); |
10475 | make_cleanup_delete_breakpoint (breakpoint2); | |
186c406b | 10476 | |
883bc8d1 | 10477 | set_longjmp_breakpoint (tp, caller_frame_id); |
186c406b | 10478 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); |
c906108c | 10479 | } |
c5aa993b | 10480 | |
c70a6932 JK |
10481 | /* set_momentary_breakpoint could invalidate FRAME. */ |
10482 | frame = NULL; | |
10483 | ||
883bc8d1 PA |
10484 | if (anywhere) |
10485 | /* If the user told us to continue until a specified location, | |
10486 | we don't specify a frame at which we need to stop. */ | |
10487 | breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, | |
10488 | null_frame_id, bp_until); | |
10489 | else | |
10490 | /* Otherwise, specify the selected frame, because we want to stop | |
10491 | only at the very same frame. */ | |
10492 | breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, | |
10493 | stack_frame_id, bp_until); | |
10494 | make_cleanup_delete_breakpoint (breakpoint); | |
10495 | ||
c906108c | 10496 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
f107f563 | 10497 | |
4a64f543 MS |
10498 | /* If we are running asynchronously, and proceed call above has |
10499 | actually managed to start the target, arrange for breakpoints to | |
10500 | be deleted when the target stops. Otherwise, we're already | |
10501 | stopped and delete breakpoints via cleanup chain. */ | |
f107f563 | 10502 | |
8ea051c5 | 10503 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 10504 | { |
bfec99b2 PA |
10505 | struct until_break_command_continuation_args *args; |
10506 | args = xmalloc (sizeof (*args)); | |
f107f563 | 10507 | |
bfec99b2 PA |
10508 | args->breakpoint = breakpoint; |
10509 | args->breakpoint2 = breakpoint2; | |
186c406b | 10510 | args->thread_num = thread; |
f107f563 VP |
10511 | |
10512 | discard_cleanups (old_chain); | |
95e54da7 PA |
10513 | add_continuation (inferior_thread (), |
10514 | until_break_command_continuation, args, | |
604ead4a | 10515 | xfree); |
f107f563 VP |
10516 | } |
10517 | else | |
c5aa993b | 10518 | do_cleanups (old_chain); |
c906108c | 10519 | } |
ae66c1fc | 10520 | |
c906108c SS |
10521 | /* This function attempts to parse an optional "if <cond>" clause |
10522 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 10523 | |
c906108c SS |
10524 | Else, it returns a pointer to the condition string. (It does not |
10525 | attempt to evaluate the string against a particular block.) And, | |
10526 | it updates arg to point to the first character following the parsed | |
4a64f543 | 10527 | if clause in the arg string. */ |
53a5351d | 10528 | |
c906108c | 10529 | static char * |
fba45db2 | 10530 | ep_parse_optional_if_clause (char **arg) |
c906108c | 10531 | { |
c5aa993b JM |
10532 | char *cond_string; |
10533 | ||
10534 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 10535 | return NULL; |
c5aa993b | 10536 | |
4a64f543 | 10537 | /* Skip the "if" keyword. */ |
c906108c | 10538 | (*arg) += 2; |
c5aa993b | 10539 | |
c906108c | 10540 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 10541 | condition string. */ |
e9cafbcc | 10542 | *arg = skip_spaces (*arg); |
c906108c | 10543 | cond_string = *arg; |
c5aa993b | 10544 | |
4a64f543 MS |
10545 | /* Assume that the condition occupies the remainder of the arg |
10546 | string. */ | |
c906108c | 10547 | (*arg) += strlen (cond_string); |
c5aa993b | 10548 | |
c906108c SS |
10549 | return cond_string; |
10550 | } | |
c5aa993b | 10551 | |
c906108c SS |
10552 | /* Commands to deal with catching events, such as signals, exceptions, |
10553 | process start/exit, etc. */ | |
c5aa993b JM |
10554 | |
10555 | typedef enum | |
10556 | { | |
44feb3ce TT |
10557 | catch_fork_temporary, catch_vfork_temporary, |
10558 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
10559 | } |
10560 | catch_fork_kind; | |
10561 | ||
c906108c | 10562 | static void |
cc59ec59 MS |
10563 | catch_fork_command_1 (char *arg, int from_tty, |
10564 | struct cmd_list_element *command) | |
c906108c | 10565 | { |
a6d9a66e | 10566 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 10567 | char *cond_string = NULL; |
44feb3ce TT |
10568 | catch_fork_kind fork_kind; |
10569 | int tempflag; | |
10570 | ||
10571 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
10572 | tempflag = (fork_kind == catch_fork_temporary | |
10573 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 10574 | |
44feb3ce TT |
10575 | if (!arg) |
10576 | arg = ""; | |
e9cafbcc | 10577 | arg = skip_spaces (arg); |
c5aa993b | 10578 | |
c906108c | 10579 | /* The allowed syntax is: |
c5aa993b JM |
10580 | catch [v]fork |
10581 | catch [v]fork if <cond> | |
10582 | ||
4a64f543 | 10583 | First, check if there's an if clause. */ |
c906108c | 10584 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 10585 | |
c906108c | 10586 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 10587 | error (_("Junk at end of arguments.")); |
c5aa993b | 10588 | |
c906108c | 10589 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 10590 | and enable reporting of such events. */ |
c5aa993b JM |
10591 | switch (fork_kind) |
10592 | { | |
44feb3ce TT |
10593 | case catch_fork_temporary: |
10594 | case catch_fork_permanent: | |
a6d9a66e | 10595 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 10596 | &catch_fork_breakpoint_ops); |
c906108c | 10597 | break; |
44feb3ce TT |
10598 | case catch_vfork_temporary: |
10599 | case catch_vfork_permanent: | |
a6d9a66e | 10600 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 10601 | &catch_vfork_breakpoint_ops); |
c906108c | 10602 | break; |
c5aa993b | 10603 | default: |
8a3fe4f8 | 10604 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 10605 | break; |
c5aa993b | 10606 | } |
c906108c SS |
10607 | } |
10608 | ||
10609 | static void | |
cc59ec59 MS |
10610 | catch_exec_command_1 (char *arg, int from_tty, |
10611 | struct cmd_list_element *command) | |
c906108c | 10612 | { |
b4d90040 | 10613 | struct exec_catchpoint *c; |
a6d9a66e | 10614 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 10615 | int tempflag; |
c5aa993b | 10616 | char *cond_string = NULL; |
c906108c | 10617 | |
44feb3ce TT |
10618 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
10619 | ||
10620 | if (!arg) | |
10621 | arg = ""; | |
e9cafbcc | 10622 | arg = skip_spaces (arg); |
c906108c SS |
10623 | |
10624 | /* The allowed syntax is: | |
c5aa993b JM |
10625 | catch exec |
10626 | catch exec if <cond> | |
c906108c | 10627 | |
4a64f543 | 10628 | First, check if there's an if clause. */ |
c906108c SS |
10629 | cond_string = ep_parse_optional_if_clause (&arg); |
10630 | ||
10631 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 10632 | error (_("Junk at end of arguments.")); |
c906108c | 10633 | |
b4d90040 PA |
10634 | c = XNEW (struct exec_catchpoint); |
10635 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, | |
10636 | &catch_exec_breakpoint_ops); | |
10637 | c->exec_pathname = NULL; | |
10638 | ||
3ea46bff | 10639 | install_breakpoint (0, &c->base, 1); |
c906108c | 10640 | } |
c5aa993b | 10641 | |
3086aeae | 10642 | static enum print_stop_action |
348d480f | 10643 | print_it_exception_catchpoint (bpstat bs) |
3086aeae | 10644 | { |
79a45e25 | 10645 | struct ui_out *uiout = current_uiout; |
348d480f | 10646 | struct breakpoint *b = bs->breakpoint_at; |
ade92717 | 10647 | int bp_temp, bp_throw; |
3086aeae | 10648 | |
ade92717 | 10649 | annotate_catchpoint (b->number); |
3086aeae | 10650 | |
ade92717 AR |
10651 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
10652 | if (b->loc->address != b->loc->requested_address) | |
10653 | breakpoint_adjustment_warning (b->loc->requested_address, | |
10654 | b->loc->address, | |
10655 | b->number, 1); | |
df2b6d2d | 10656 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
10657 | ui_out_text (uiout, |
10658 | bp_temp ? "Temporary catchpoint " | |
10659 | : "Catchpoint "); | |
10660 | if (!ui_out_is_mi_like_p (uiout)) | |
10661 | ui_out_field_int (uiout, "bkptno", b->number); | |
10662 | ui_out_text (uiout, | |
c0b37c48 AR |
10663 | bp_throw ? " (exception thrown), " |
10664 | : " (exception caught), "); | |
ade92717 AR |
10665 | if (ui_out_is_mi_like_p (uiout)) |
10666 | { | |
10667 | ui_out_field_string (uiout, "reason", | |
10668 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
10669 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
10670 | ui_out_field_int (uiout, "bkptno", b->number); | |
10671 | } | |
3086aeae DJ |
10672 | return PRINT_SRC_AND_LOC; |
10673 | } | |
10674 | ||
10675 | static void | |
cc59ec59 MS |
10676 | print_one_exception_catchpoint (struct breakpoint *b, |
10677 | struct bp_location **last_loc) | |
3086aeae | 10678 | { |
79a45b7d | 10679 | struct value_print_options opts; |
79a45e25 | 10680 | struct ui_out *uiout = current_uiout; |
cc59ec59 | 10681 | |
79a45b7d TT |
10682 | get_user_print_options (&opts); |
10683 | if (opts.addressprint) | |
3086aeae DJ |
10684 | { |
10685 | annotate_field (4); | |
604133b5 AR |
10686 | if (b->loc == NULL || b->loc->shlib_disabled) |
10687 | ui_out_field_string (uiout, "addr", "<PENDING>"); | |
10688 | else | |
5af949e3 UW |
10689 | ui_out_field_core_addr (uiout, "addr", |
10690 | b->loc->gdbarch, b->loc->address); | |
3086aeae DJ |
10691 | } |
10692 | annotate_field (5); | |
604133b5 | 10693 | if (b->loc) |
a6d9a66e | 10694 | *last_loc = b->loc; |
3086aeae DJ |
10695 | if (strstr (b->addr_string, "throw") != NULL) |
10696 | ui_out_field_string (uiout, "what", "exception throw"); | |
10697 | else | |
10698 | ui_out_field_string (uiout, "what", "exception catch"); | |
10699 | } | |
10700 | ||
10701 | static void | |
10702 | print_mention_exception_catchpoint (struct breakpoint *b) | |
10703 | { | |
79a45e25 | 10704 | struct ui_out *uiout = current_uiout; |
ade92717 AR |
10705 | int bp_temp; |
10706 | int bp_throw; | |
10707 | ||
df2b6d2d | 10708 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
10709 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
10710 | ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ") | |
10711 | : _("Catchpoint ")); | |
10712 | ui_out_field_int (uiout, "bkptno", b->number); | |
10713 | ui_out_text (uiout, bp_throw ? _(" (throw)") | |
10714 | : _(" (catch)")); | |
3086aeae DJ |
10715 | } |
10716 | ||
6149aea9 PA |
10717 | /* Implement the "print_recreate" breakpoint_ops method for throw and |
10718 | catch catchpoints. */ | |
10719 | ||
10720 | static void | |
4a64f543 MS |
10721 | print_recreate_exception_catchpoint (struct breakpoint *b, |
10722 | struct ui_file *fp) | |
6149aea9 PA |
10723 | { |
10724 | int bp_temp; | |
10725 | int bp_throw; | |
10726 | ||
10727 | bp_temp = b->disposition == disp_del; | |
10728 | bp_throw = strstr (b->addr_string, "throw") != NULL; | |
10729 | fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch "); | |
10730 | fprintf_unfiltered (fp, bp_throw ? "throw" : "catch"); | |
d9b3f62e | 10731 | print_recreate_thread (b, fp); |
6149aea9 PA |
10732 | } |
10733 | ||
2060206e | 10734 | static struct breakpoint_ops gnu_v3_exception_catchpoint_ops; |
3086aeae DJ |
10735 | |
10736 | static int | |
10737 | handle_gnu_v3_exceptions (int tempflag, char *cond_string, | |
10738 | enum exception_event_kind ex_event, int from_tty) | |
10739 | { | |
604133b5 AR |
10740 | char *trigger_func_name; |
10741 | ||
3086aeae | 10742 | if (ex_event == EX_EVENT_CATCH) |
604133b5 | 10743 | trigger_func_name = "__cxa_begin_catch"; |
3086aeae | 10744 | else |
604133b5 | 10745 | trigger_func_name = "__cxa_throw"; |
3086aeae | 10746 | |
8cdf0e15 VP |
10747 | create_breakpoint (get_current_arch (), |
10748 | trigger_func_name, cond_string, -1, | |
10749 | 0 /* condition and thread are valid. */, | |
0fb4aa4b | 10750 | tempflag, bp_breakpoint, |
8cdf0e15 VP |
10751 | 0, |
10752 | AUTO_BOOLEAN_TRUE /* pending */, | |
10753 | &gnu_v3_exception_catchpoint_ops, from_tty, | |
84f4c1fe PM |
10754 | 1 /* enabled */, |
10755 | 0 /* internal */); | |
3086aeae | 10756 | |
3086aeae DJ |
10757 | return 1; |
10758 | } | |
10759 | ||
4a64f543 | 10760 | /* Deal with "catch catch" and "catch throw" commands. */ |
c906108c SS |
10761 | |
10762 | static void | |
fba45db2 KB |
10763 | catch_exception_command_1 (enum exception_event_kind ex_event, char *arg, |
10764 | int tempflag, int from_tty) | |
c906108c | 10765 | { |
c5aa993b | 10766 | char *cond_string = NULL; |
c5aa993b | 10767 | |
44feb3ce TT |
10768 | if (!arg) |
10769 | arg = ""; | |
e9cafbcc | 10770 | arg = skip_spaces (arg); |
c5aa993b | 10771 | |
c906108c SS |
10772 | cond_string = ep_parse_optional_if_clause (&arg); |
10773 | ||
10774 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 10775 | error (_("Junk at end of arguments.")); |
c906108c | 10776 | |
059fb39f PM |
10777 | if (ex_event != EX_EVENT_THROW |
10778 | && ex_event != EX_EVENT_CATCH) | |
8a3fe4f8 | 10779 | error (_("Unsupported or unknown exception event; cannot catch it")); |
c906108c | 10780 | |
3086aeae DJ |
10781 | if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty)) |
10782 | return; | |
10783 | ||
8a3fe4f8 | 10784 | warning (_("Unsupported with this platform/compiler combination.")); |
c906108c SS |
10785 | } |
10786 | ||
44feb3ce TT |
10787 | /* Implementation of "catch catch" command. */ |
10788 | ||
10789 | static void | |
10790 | catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command) | |
10791 | { | |
10792 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
cc59ec59 | 10793 | |
44feb3ce TT |
10794 | catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty); |
10795 | } | |
10796 | ||
10797 | /* Implementation of "catch throw" command. */ | |
10798 | ||
10799 | static void | |
10800 | catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command) | |
10801 | { | |
10802 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
cc59ec59 | 10803 | |
44feb3ce TT |
10804 | catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty); |
10805 | } | |
10806 | ||
9ac4176b | 10807 | void |
28010a5d PA |
10808 | init_ada_exception_breakpoint (struct breakpoint *b, |
10809 | struct gdbarch *gdbarch, | |
10810 | struct symtab_and_line sal, | |
10811 | char *addr_string, | |
c0a91b2b | 10812 | const struct breakpoint_ops *ops, |
28010a5d PA |
10813 | int tempflag, |
10814 | int from_tty) | |
f7f9143b | 10815 | { |
f7f9143b JB |
10816 | if (from_tty) |
10817 | { | |
5af949e3 UW |
10818 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
10819 | if (!loc_gdbarch) | |
10820 | loc_gdbarch = gdbarch; | |
10821 | ||
6c95b8df PA |
10822 | describe_other_breakpoints (loc_gdbarch, |
10823 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
10824 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
10825 | version for exception catchpoints, because two catchpoints | |
10826 | used for different exception names will use the same address. | |
10827 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 10828 | unproductive. Besides, the warning phrasing is also a bit |
e5dd4106 | 10829 | inappropriate, we should use the word catchpoint, and tell |
f7f9143b JB |
10830 | the user what type of catchpoint it is. The above is good |
10831 | enough for now, though. */ | |
10832 | } | |
10833 | ||
28010a5d | 10834 | init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops); |
f7f9143b JB |
10835 | |
10836 | b->enable_state = bp_enabled; | |
10837 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
f7f9143b JB |
10838 | b->addr_string = addr_string; |
10839 | b->language = language_ada; | |
f7f9143b JB |
10840 | } |
10841 | ||
a96d9b2e SDJ |
10842 | /* Splits the argument using space as delimiter. Returns an xmalloc'd |
10843 | filter list, or NULL if no filtering is required. */ | |
10844 | static VEC(int) * | |
10845 | catch_syscall_split_args (char *arg) | |
10846 | { | |
10847 | VEC(int) *result = NULL; | |
29d0bb3d | 10848 | struct cleanup *cleanup = make_cleanup (VEC_cleanup (int), &result); |
a96d9b2e SDJ |
10849 | |
10850 | while (*arg != '\0') | |
10851 | { | |
10852 | int i, syscall_number; | |
10853 | char *endptr; | |
10854 | char cur_name[128]; | |
10855 | struct syscall s; | |
10856 | ||
10857 | /* Skip whitespace. */ | |
10858 | while (isspace (*arg)) | |
10859 | arg++; | |
10860 | ||
10861 | for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) | |
10862 | cur_name[i] = arg[i]; | |
10863 | cur_name[i] = '\0'; | |
10864 | arg += i; | |
10865 | ||
10866 | /* Check if the user provided a syscall name or a number. */ | |
10867 | syscall_number = (int) strtol (cur_name, &endptr, 0); | |
10868 | if (*endptr == '\0') | |
bccd0dd2 | 10869 | get_syscall_by_number (syscall_number, &s); |
a96d9b2e SDJ |
10870 | else |
10871 | { | |
10872 | /* We have a name. Let's check if it's valid and convert it | |
10873 | to a number. */ | |
10874 | get_syscall_by_name (cur_name, &s); | |
10875 | ||
10876 | if (s.number == UNKNOWN_SYSCALL) | |
4a64f543 MS |
10877 | /* Here we have to issue an error instead of a warning, |
10878 | because GDB cannot do anything useful if there's no | |
10879 | syscall number to be caught. */ | |
a96d9b2e SDJ |
10880 | error (_("Unknown syscall name '%s'."), cur_name); |
10881 | } | |
10882 | ||
10883 | /* Ok, it's valid. */ | |
10884 | VEC_safe_push (int, result, s.number); | |
10885 | } | |
10886 | ||
10887 | discard_cleanups (cleanup); | |
10888 | return result; | |
10889 | } | |
10890 | ||
10891 | /* Implement the "catch syscall" command. */ | |
10892 | ||
10893 | static void | |
cc59ec59 MS |
10894 | catch_syscall_command_1 (char *arg, int from_tty, |
10895 | struct cmd_list_element *command) | |
a96d9b2e SDJ |
10896 | { |
10897 | int tempflag; | |
10898 | VEC(int) *filter; | |
10899 | struct syscall s; | |
10900 | struct gdbarch *gdbarch = get_current_arch (); | |
10901 | ||
10902 | /* Checking if the feature if supported. */ | |
10903 | if (gdbarch_get_syscall_number_p (gdbarch) == 0) | |
10904 | error (_("The feature 'catch syscall' is not supported on \ | |
ea666128 | 10905 | this architecture yet.")); |
a96d9b2e SDJ |
10906 | |
10907 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
10908 | ||
e9cafbcc | 10909 | arg = skip_spaces (arg); |
a96d9b2e SDJ |
10910 | |
10911 | /* We need to do this first "dummy" translation in order | |
10912 | to get the syscall XML file loaded or, most important, | |
10913 | to display a warning to the user if there's no XML file | |
10914 | for his/her architecture. */ | |
10915 | get_syscall_by_number (0, &s); | |
10916 | ||
10917 | /* The allowed syntax is: | |
10918 | catch syscall | |
10919 | catch syscall <name | number> [<name | number> ... <name | number>] | |
10920 | ||
10921 | Let's check if there's a syscall name. */ | |
10922 | ||
10923 | if (arg != NULL) | |
10924 | filter = catch_syscall_split_args (arg); | |
10925 | else | |
10926 | filter = NULL; | |
10927 | ||
10928 | create_syscall_event_catchpoint (tempflag, filter, | |
10929 | &catch_syscall_breakpoint_ops); | |
10930 | } | |
10931 | ||
c906108c | 10932 | static void |
fba45db2 | 10933 | catch_command (char *arg, int from_tty) |
c906108c | 10934 | { |
44feb3ce | 10935 | error (_("Catch requires an event name.")); |
c906108c SS |
10936 | } |
10937 | \f | |
10938 | ||
10939 | static void | |
fba45db2 | 10940 | tcatch_command (char *arg, int from_tty) |
c906108c | 10941 | { |
44feb3ce | 10942 | error (_("Catch requires an event name.")); |
c906108c SS |
10943 | } |
10944 | ||
8a2c437b TT |
10945 | /* A qsort comparison function that sorts breakpoints in order. */ |
10946 | ||
10947 | static int | |
10948 | compare_breakpoints (const void *a, const void *b) | |
10949 | { | |
10950 | const breakpoint_p *ba = a; | |
10951 | uintptr_t ua = (uintptr_t) *ba; | |
10952 | const breakpoint_p *bb = b; | |
10953 | uintptr_t ub = (uintptr_t) *bb; | |
10954 | ||
10955 | if ((*ba)->number < (*bb)->number) | |
10956 | return -1; | |
10957 | else if ((*ba)->number > (*bb)->number) | |
10958 | return 1; | |
10959 | ||
10960 | /* Now sort by address, in case we see, e..g, two breakpoints with | |
10961 | the number 0. */ | |
10962 | if (ua < ub) | |
10963 | return -1; | |
10964 | return ub > ub ? 1 : 0; | |
10965 | } | |
10966 | ||
80f8a6eb | 10967 | /* Delete breakpoints by address or line. */ |
c906108c SS |
10968 | |
10969 | static void | |
fba45db2 | 10970 | clear_command (char *arg, int from_tty) |
c906108c | 10971 | { |
8a2c437b | 10972 | struct breakpoint *b, *prev; |
d6e956e5 VP |
10973 | VEC(breakpoint_p) *found = 0; |
10974 | int ix; | |
c906108c SS |
10975 | int default_match; |
10976 | struct symtabs_and_lines sals; | |
10977 | struct symtab_and_line sal; | |
c906108c | 10978 | int i; |
8a2c437b | 10979 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
c906108c SS |
10980 | |
10981 | if (arg) | |
10982 | { | |
f8eba3c6 TT |
10983 | sals = decode_line_spec (arg, (DECODE_LINE_FUNFIRSTLINE |
10984 | | DECODE_LINE_LIST_MODE)); | |
c906108c SS |
10985 | default_match = 0; |
10986 | } | |
10987 | else | |
10988 | { | |
c5aa993b | 10989 | sals.sals = (struct symtab_and_line *) |
c906108c | 10990 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 10991 | make_cleanup (xfree, sals.sals); |
4a64f543 | 10992 | init_sal (&sal); /* Initialize to zeroes. */ |
1bfeeb0f JL |
10993 | |
10994 | /* Set sal's line, symtab, pc, and pspace to the values | |
10995 | corresponding to the last call to print_frame_info. If the | |
10996 | codepoint is not valid, this will set all the fields to 0. */ | |
10997 | get_last_displayed_sal (&sal); | |
c906108c | 10998 | if (sal.symtab == 0) |
8a3fe4f8 | 10999 | error (_("No source file specified.")); |
c906108c SS |
11000 | |
11001 | sals.sals[0] = sal; | |
11002 | sals.nelts = 1; | |
11003 | ||
11004 | default_match = 1; | |
11005 | } | |
11006 | ||
4a64f543 MS |
11007 | /* We don't call resolve_sal_pc here. That's not as bad as it |
11008 | seems, because all existing breakpoints typically have both | |
11009 | file/line and pc set. So, if clear is given file/line, we can | |
11010 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
11011 | |
11012 | We only support clearing given the address explicitly | |
11013 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 11014 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 11015 | due to optimization, all in one block. |
4a64f543 MS |
11016 | |
11017 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
11018 | PC corresponding to the same file:line, the breakpoint won't |
11019 | be cleared. We probably can still clear the breakpoint, but | |
11020 | since the other PC value is never presented to user, user | |
11021 | can only find it by guessing, and it does not seem important | |
11022 | to support that. */ | |
11023 | ||
4a64f543 MS |
11024 | /* For each line spec given, delete bps which correspond to it. Do |
11025 | it in two passes, solely to preserve the current behavior that | |
11026 | from_tty is forced true if we delete more than one | |
11027 | breakpoint. */ | |
c906108c | 11028 | |
80f8a6eb | 11029 | found = NULL; |
8a2c437b | 11030 | make_cleanup (VEC_cleanup (breakpoint_p), &found); |
c906108c SS |
11031 | for (i = 0; i < sals.nelts; i++) |
11032 | { | |
4aac40c8 TT |
11033 | int is_abs, sal_name_len; |
11034 | ||
c906108c | 11035 | /* If exact pc given, clear bpts at that pc. |
c5aa993b JM |
11036 | If line given (pc == 0), clear all bpts on specified line. |
11037 | If defaulting, clear all bpts on default line | |
c906108c | 11038 | or at default pc. |
c5aa993b JM |
11039 | |
11040 | defaulting sal.pc != 0 tests to do | |
11041 | ||
11042 | 0 1 pc | |
11043 | 1 1 pc _and_ line | |
11044 | 0 0 line | |
11045 | 1 0 <can't happen> */ | |
c906108c SS |
11046 | |
11047 | sal = sals.sals[i]; | |
4aac40c8 TT |
11048 | is_abs = sal.symtab == NULL ? 1 : IS_ABSOLUTE_PATH (sal.symtab->filename); |
11049 | sal_name_len = is_abs ? 0 : strlen (sal.symtab->filename); | |
c906108c | 11050 | |
4a64f543 | 11051 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 11052 | ALL_BREAKPOINTS (b) |
c5aa993b | 11053 | { |
0d381245 | 11054 | int match = 0; |
4a64f543 | 11055 | /* Are we going to delete b? */ |
cc60f2e3 | 11056 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
11057 | { |
11058 | struct bp_location *loc = b->loc; | |
11059 | for (; loc; loc = loc->next) | |
11060 | { | |
f8eba3c6 TT |
11061 | /* If the user specified file:line, don't allow a PC |
11062 | match. This matches historical gdb behavior. */ | |
11063 | int pc_match = (!sal.explicit_line | |
11064 | && sal.pc | |
11065 | && (loc->pspace == sal.pspace) | |
11066 | && (loc->address == sal.pc) | |
11067 | && (!section_is_overlay (loc->section) | |
11068 | || loc->section == sal.section)); | |
4aac40c8 TT |
11069 | int line_match = 0; |
11070 | ||
11071 | if ((default_match || sal.explicit_line) | |
11072 | && loc->source_file != NULL | |
11073 | && sal.symtab != NULL | |
11074 | && sal.pspace == loc->pspace | |
11075 | && loc->line_number == sal.line) | |
11076 | { | |
11077 | if (filename_cmp (loc->source_file, | |
11078 | sal.symtab->filename) == 0) | |
11079 | line_match = 1; | |
11080 | else if (!IS_ABSOLUTE_PATH (sal.symtab->filename) | |
11081 | && compare_filenames_for_search (loc->source_file, | |
11082 | sal.symtab->filename, | |
11083 | sal_name_len)) | |
11084 | line_match = 1; | |
11085 | } | |
11086 | ||
0d381245 VP |
11087 | if (pc_match || line_match) |
11088 | { | |
11089 | match = 1; | |
11090 | break; | |
11091 | } | |
11092 | } | |
11093 | } | |
11094 | ||
11095 | if (match) | |
d6e956e5 | 11096 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 11097 | } |
80f8a6eb | 11098 | } |
8a2c437b | 11099 | |
80f8a6eb | 11100 | /* Now go thru the 'found' chain and delete them. */ |
d6e956e5 | 11101 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
11102 | { |
11103 | if (arg) | |
8a3fe4f8 | 11104 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 11105 | else |
8a3fe4f8 | 11106 | error (_("No breakpoint at this line.")); |
80f8a6eb | 11107 | } |
c906108c | 11108 | |
8a2c437b TT |
11109 | /* Remove duplicates from the vec. */ |
11110 | qsort (VEC_address (breakpoint_p, found), | |
11111 | VEC_length (breakpoint_p, found), | |
11112 | sizeof (breakpoint_p), | |
11113 | compare_breakpoints); | |
11114 | prev = VEC_index (breakpoint_p, found, 0); | |
11115 | for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix) | |
11116 | { | |
11117 | if (b == prev) | |
11118 | { | |
11119 | VEC_ordered_remove (breakpoint_p, found, ix); | |
11120 | --ix; | |
11121 | } | |
11122 | } | |
11123 | ||
d6e956e5 | 11124 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 11125 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 11126 | if (from_tty) |
a3f17187 | 11127 | { |
d6e956e5 | 11128 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
11129 | printf_unfiltered (_("Deleted breakpoint ")); |
11130 | else | |
11131 | printf_unfiltered (_("Deleted breakpoints ")); | |
11132 | } | |
80f8a6eb | 11133 | breakpoints_changed (); |
d6e956e5 VP |
11134 | |
11135 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 11136 | { |
c5aa993b | 11137 | if (from_tty) |
d6e956e5 VP |
11138 | printf_unfiltered ("%d ", b->number); |
11139 | delete_breakpoint (b); | |
c906108c | 11140 | } |
80f8a6eb MS |
11141 | if (from_tty) |
11142 | putchar_unfiltered ('\n'); | |
8a2c437b TT |
11143 | |
11144 | do_cleanups (cleanups); | |
c906108c SS |
11145 | } |
11146 | \f | |
11147 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
11148 | all breakpoints that are marked for deletion, whether hit or not. | |
11149 | This is called after any breakpoint is hit, or after errors. */ | |
11150 | ||
11151 | void | |
fba45db2 | 11152 | breakpoint_auto_delete (bpstat bs) |
c906108c | 11153 | { |
35df4500 | 11154 | struct breakpoint *b, *b_tmp; |
c906108c SS |
11155 | |
11156 | for (; bs; bs = bs->next) | |
f431efe5 PA |
11157 | if (bs->breakpoint_at |
11158 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 11159 | && bs->stop) |
f431efe5 | 11160 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 11161 | |
35df4500 | 11162 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 11163 | { |
b5de0fa7 | 11164 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
11165 | delete_breakpoint (b); |
11166 | } | |
c906108c SS |
11167 | } |
11168 | ||
4a64f543 MS |
11169 | /* A comparison function for bp_location AP and BP being interfaced to |
11170 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
11171 | does breakpoint_address_is_meaningful say for its OWNER), | |
11172 | secondarily by ordering first bp_permanent OWNERed elements and | |
11173 | terciarily just ensuring the array is sorted stable way despite | |
e5dd4106 | 11174 | qsort being an unstable algorithm. */ |
876fa593 JK |
11175 | |
11176 | static int | |
494cfb0f | 11177 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 11178 | { |
494cfb0f JK |
11179 | struct bp_location *a = *(void **) ap; |
11180 | struct bp_location *b = *(void **) bp; | |
2bdf28a0 | 11181 | /* A and B come from existing breakpoints having non-NULL OWNER. */ |
876fa593 JK |
11182 | int a_perm = a->owner->enable_state == bp_permanent; |
11183 | int b_perm = b->owner->enable_state == bp_permanent; | |
11184 | ||
11185 | if (a->address != b->address) | |
11186 | return (a->address > b->address) - (a->address < b->address); | |
11187 | ||
dea2aa5f LM |
11188 | /* Sort locations at the same address by their pspace number, keeping |
11189 | locations of the same inferior (in a multi-inferior environment) | |
11190 | grouped. */ | |
11191 | ||
11192 | if (a->pspace->num != b->pspace->num) | |
11193 | return ((a->pspace->num > b->pspace->num) | |
11194 | - (a->pspace->num < b->pspace->num)); | |
11195 | ||
876fa593 JK |
11196 | /* Sort permanent breakpoints first. */ |
11197 | if (a_perm != b_perm) | |
11198 | return (a_perm < b_perm) - (a_perm > b_perm); | |
11199 | ||
c56a97f9 JK |
11200 | /* Make the internal GDB representation stable across GDB runs |
11201 | where A and B memory inside GDB can differ. Breakpoint locations of | |
11202 | the same type at the same address can be sorted in arbitrary order. */ | |
876fa593 JK |
11203 | |
11204 | if (a->owner->number != b->owner->number) | |
c56a97f9 JK |
11205 | return ((a->owner->number > b->owner->number) |
11206 | - (a->owner->number < b->owner->number)); | |
876fa593 JK |
11207 | |
11208 | return (a > b) - (a < b); | |
11209 | } | |
11210 | ||
876fa593 | 11211 | /* Set bp_location_placed_address_before_address_max and |
4a64f543 MS |
11212 | bp_location_shadow_len_after_address_max according to the current |
11213 | content of the bp_location array. */ | |
f7545552 TT |
11214 | |
11215 | static void | |
876fa593 | 11216 | bp_location_target_extensions_update (void) |
f7545552 | 11217 | { |
876fa593 JK |
11218 | struct bp_location *bl, **blp_tmp; |
11219 | ||
11220 | bp_location_placed_address_before_address_max = 0; | |
11221 | bp_location_shadow_len_after_address_max = 0; | |
11222 | ||
11223 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
11224 | { | |
11225 | CORE_ADDR start, end, addr; | |
11226 | ||
11227 | if (!bp_location_has_shadow (bl)) | |
11228 | continue; | |
11229 | ||
11230 | start = bl->target_info.placed_address; | |
11231 | end = start + bl->target_info.shadow_len; | |
11232 | ||
11233 | gdb_assert (bl->address >= start); | |
11234 | addr = bl->address - start; | |
11235 | if (addr > bp_location_placed_address_before_address_max) | |
11236 | bp_location_placed_address_before_address_max = addr; | |
11237 | ||
11238 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
11239 | ||
11240 | gdb_assert (bl->address < end); | |
11241 | addr = end - bl->address; | |
11242 | if (addr > bp_location_shadow_len_after_address_max) | |
11243 | bp_location_shadow_len_after_address_max = addr; | |
11244 | } | |
f7545552 TT |
11245 | } |
11246 | ||
1e4d1764 YQ |
11247 | /* Download tracepoint locations if they haven't been. */ |
11248 | ||
11249 | static void | |
11250 | download_tracepoint_locations (void) | |
11251 | { | |
11252 | struct bp_location *bl, **blp_tmp; | |
11253 | struct cleanup *old_chain; | |
11254 | ||
11255 | if (!target_can_download_tracepoint ()) | |
11256 | return; | |
11257 | ||
11258 | old_chain = save_current_space_and_thread (); | |
11259 | ||
11260 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
11261 | { | |
11262 | struct tracepoint *t; | |
11263 | ||
11264 | if (!is_tracepoint (bl->owner)) | |
11265 | continue; | |
11266 | ||
11267 | if ((bl->owner->type == bp_fast_tracepoint | |
11268 | ? !may_insert_fast_tracepoints | |
11269 | : !may_insert_tracepoints)) | |
11270 | continue; | |
11271 | ||
11272 | /* In tracepoint, locations are _never_ duplicated, so | |
11273 | should_be_inserted is equivalent to | |
11274 | unduplicated_should_be_inserted. */ | |
11275 | if (!should_be_inserted (bl) || bl->inserted) | |
11276 | continue; | |
11277 | ||
11278 | switch_to_program_space_and_thread (bl->pspace); | |
11279 | ||
11280 | target_download_tracepoint (bl); | |
11281 | ||
11282 | bl->inserted = 1; | |
11283 | t = (struct tracepoint *) bl->owner; | |
11284 | t->number_on_target = bl->owner->number; | |
11285 | } | |
11286 | ||
11287 | do_cleanups (old_chain); | |
11288 | } | |
11289 | ||
934709f0 PW |
11290 | /* Swap the insertion/duplication state between two locations. */ |
11291 | ||
11292 | static void | |
11293 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
11294 | { | |
11295 | const int left_inserted = left->inserted; | |
11296 | const int left_duplicate = left->duplicate; | |
b775012e | 11297 | const int left_needs_update = left->needs_update; |
934709f0 PW |
11298 | const struct bp_target_info left_target_info = left->target_info; |
11299 | ||
1e4d1764 YQ |
11300 | /* Locations of tracepoints can never be duplicated. */ |
11301 | if (is_tracepoint (left->owner)) | |
11302 | gdb_assert (!left->duplicate); | |
11303 | if (is_tracepoint (right->owner)) | |
11304 | gdb_assert (!right->duplicate); | |
11305 | ||
934709f0 PW |
11306 | left->inserted = right->inserted; |
11307 | left->duplicate = right->duplicate; | |
b775012e | 11308 | left->needs_update = right->needs_update; |
934709f0 PW |
11309 | left->target_info = right->target_info; |
11310 | right->inserted = left_inserted; | |
11311 | right->duplicate = left_duplicate; | |
b775012e | 11312 | right->needs_update = left_needs_update; |
934709f0 PW |
11313 | right->target_info = left_target_info; |
11314 | } | |
11315 | ||
b775012e LM |
11316 | /* Force the re-insertion of the locations at ADDRESS. This is called |
11317 | once a new/deleted/modified duplicate location is found and we are evaluating | |
11318 | conditions on the target's side. Such conditions need to be updated on | |
11319 | the target. */ | |
11320 | ||
11321 | static void | |
11322 | force_breakpoint_reinsertion (struct bp_location *bl) | |
11323 | { | |
11324 | struct bp_location **locp = NULL, **loc2p; | |
11325 | struct bp_location *loc; | |
11326 | CORE_ADDR address = 0; | |
11327 | int pspace_num; | |
11328 | ||
11329 | address = bl->address; | |
11330 | pspace_num = bl->pspace->num; | |
11331 | ||
11332 | /* This is only meaningful if the target is | |
11333 | evaluating conditions and if the user has | |
11334 | opted for condition evaluation on the target's | |
11335 | side. */ | |
11336 | if (gdb_evaluates_breakpoint_condition_p () | |
11337 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
11338 | return; | |
11339 | ||
11340 | /* Flag all breakpoint locations with this address and | |
11341 | the same program space as the location | |
11342 | as "its condition has changed". We need to | |
11343 | update the conditions on the target's side. */ | |
11344 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address) | |
11345 | { | |
11346 | loc = *loc2p; | |
11347 | ||
11348 | if (!is_breakpoint (loc->owner) | |
11349 | || pspace_num != loc->pspace->num) | |
11350 | continue; | |
11351 | ||
11352 | /* Flag the location appropriately. We use a different state to | |
11353 | let everyone know that we already updated the set of locations | |
11354 | with addr bl->address and program space bl->pspace. This is so | |
11355 | we don't have to keep calling these functions just to mark locations | |
11356 | that have already been marked. */ | |
11357 | loc->condition_changed = condition_updated; | |
11358 | ||
11359 | /* Free the agent expression bytecode as well. We will compute | |
11360 | it later on. */ | |
11361 | if (loc->cond_bytecode) | |
11362 | { | |
11363 | free_agent_expr (loc->cond_bytecode); | |
11364 | loc->cond_bytecode = NULL; | |
11365 | } | |
11366 | } | |
11367 | } | |
11368 | ||
4cd9bd08 | 11369 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
b60e7edf PA |
11370 | into the inferior, only remove already-inserted locations that no |
11371 | longer should be inserted. Functions that delete a breakpoint or | |
11372 | breakpoints should pass false, so that deleting a breakpoint | |
11373 | doesn't have the side effect of inserting the locations of other | |
11374 | breakpoints that are marked not-inserted, but should_be_inserted | |
11375 | returns true on them. | |
11376 | ||
11377 | This behaviour is useful is situations close to tear-down -- e.g., | |
11378 | after an exec, while the target still has execution, but breakpoint | |
11379 | shadows of the previous executable image should *NOT* be restored | |
11380 | to the new image; or before detaching, where the target still has | |
11381 | execution and wants to delete breakpoints from GDB's lists, and all | |
11382 | breakpoints had already been removed from the inferior. */ | |
11383 | ||
0d381245 | 11384 | static void |
b60e7edf | 11385 | update_global_location_list (int should_insert) |
0d381245 | 11386 | { |
74960c60 | 11387 | struct breakpoint *b; |
876fa593 | 11388 | struct bp_location **locp, *loc; |
f7545552 | 11389 | struct cleanup *cleanups; |
b775012e LM |
11390 | /* Last breakpoint location address that was marked for update. */ |
11391 | CORE_ADDR last_addr = 0; | |
11392 | /* Last breakpoint location program space that was marked for update. */ | |
11393 | int last_pspace_num = -1; | |
f7545552 | 11394 | |
2d134ed3 PA |
11395 | /* Used in the duplicates detection below. When iterating over all |
11396 | bp_locations, points to the first bp_location of a given address. | |
11397 | Breakpoints and watchpoints of different types are never | |
11398 | duplicates of each other. Keep one pointer for each type of | |
11399 | breakpoint/watchpoint, so we only need to loop over all locations | |
11400 | once. */ | |
11401 | struct bp_location *bp_loc_first; /* breakpoint */ | |
11402 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
11403 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
11404 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 11405 | |
4a64f543 MS |
11406 | /* Saved former bp_location array which we compare against the newly |
11407 | built bp_location from the current state of ALL_BREAKPOINTS. */ | |
876fa593 JK |
11408 | struct bp_location **old_location, **old_locp; |
11409 | unsigned old_location_count; | |
11410 | ||
11411 | old_location = bp_location; | |
11412 | old_location_count = bp_location_count; | |
11413 | bp_location = NULL; | |
11414 | bp_location_count = 0; | |
11415 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 11416 | |
74960c60 | 11417 | ALL_BREAKPOINTS (b) |
876fa593 JK |
11418 | for (loc = b->loc; loc; loc = loc->next) |
11419 | bp_location_count++; | |
11420 | ||
11421 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); | |
11422 | locp = bp_location; | |
11423 | ALL_BREAKPOINTS (b) | |
11424 | for (loc = b->loc; loc; loc = loc->next) | |
11425 | *locp++ = loc; | |
11426 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 11427 | bp_location_compare); |
876fa593 JK |
11428 | |
11429 | bp_location_target_extensions_update (); | |
74960c60 | 11430 | |
4a64f543 MS |
11431 | /* Identify bp_location instances that are no longer present in the |
11432 | new list, and therefore should be freed. Note that it's not | |
11433 | necessary that those locations should be removed from inferior -- | |
11434 | if there's another location at the same address (previously | |
11435 | marked as duplicate), we don't need to remove/insert the | |
11436 | location. | |
876fa593 | 11437 | |
4a64f543 MS |
11438 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
11439 | and former bp_location array state respectively. */ | |
876fa593 JK |
11440 | |
11441 | locp = bp_location; | |
11442 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
11443 | old_locp++) | |
74960c60 | 11444 | { |
876fa593 | 11445 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 11446 | struct bp_location **loc2p; |
876fa593 | 11447 | |
e5dd4106 | 11448 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 11449 | not, we have to free it. */ |
c7d46a38 | 11450 | int found_object = 0; |
20874c92 VP |
11451 | /* Tells if the location should remain inserted in the target. */ |
11452 | int keep_in_target = 0; | |
11453 | int removed = 0; | |
876fa593 | 11454 | |
4a64f543 MS |
11455 | /* Skip LOCP entries which will definitely never be needed. |
11456 | Stop either at or being the one matching OLD_LOC. */ | |
876fa593 | 11457 | while (locp < bp_location + bp_location_count |
c7d46a38 | 11458 | && (*locp)->address < old_loc->address) |
876fa593 | 11459 | locp++; |
c7d46a38 PA |
11460 | |
11461 | for (loc2p = locp; | |
11462 | (loc2p < bp_location + bp_location_count | |
11463 | && (*loc2p)->address == old_loc->address); | |
11464 | loc2p++) | |
11465 | { | |
b775012e LM |
11466 | /* Check if this is a new/duplicated location or a duplicated |
11467 | location that had its condition modified. If so, we want to send | |
11468 | its condition to the target if evaluation of conditions is taking | |
11469 | place there. */ | |
11470 | if ((*loc2p)->condition_changed == condition_modified | |
11471 | && (last_addr != old_loc->address | |
11472 | || last_pspace_num != old_loc->pspace->num)) | |
c7d46a38 | 11473 | { |
b775012e LM |
11474 | force_breakpoint_reinsertion (*loc2p); |
11475 | last_pspace_num = old_loc->pspace->num; | |
c7d46a38 | 11476 | } |
b775012e LM |
11477 | |
11478 | if (*loc2p == old_loc) | |
11479 | found_object = 1; | |
c7d46a38 | 11480 | } |
74960c60 | 11481 | |
b775012e LM |
11482 | /* We have already handled this address, update it so that we don't |
11483 | have to go through updates again. */ | |
11484 | last_addr = old_loc->address; | |
11485 | ||
11486 | /* Target-side condition evaluation: Handle deleted locations. */ | |
11487 | if (!found_object) | |
11488 | force_breakpoint_reinsertion (old_loc); | |
11489 | ||
4a64f543 MS |
11490 | /* If this location is no longer present, and inserted, look if |
11491 | there's maybe a new location at the same address. If so, | |
11492 | mark that one inserted, and don't remove this one. This is | |
11493 | needed so that we don't have a time window where a breakpoint | |
11494 | at certain location is not inserted. */ | |
74960c60 | 11495 | |
876fa593 | 11496 | if (old_loc->inserted) |
0d381245 | 11497 | { |
4a64f543 MS |
11498 | /* If the location is inserted now, we might have to remove |
11499 | it. */ | |
74960c60 | 11500 | |
876fa593 | 11501 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 11502 | { |
4a64f543 MS |
11503 | /* The location is still present in the location list, |
11504 | and still should be inserted. Don't do anything. */ | |
20874c92 | 11505 | keep_in_target = 1; |
74960c60 VP |
11506 | } |
11507 | else | |
11508 | { | |
b775012e LM |
11509 | /* This location still exists, but it won't be kept in the |
11510 | target since it may have been disabled. We proceed to | |
11511 | remove its target-side condition. */ | |
11512 | ||
4a64f543 MS |
11513 | /* The location is either no longer present, or got |
11514 | disabled. See if there's another location at the | |
11515 | same address, in which case we don't need to remove | |
11516 | this one from the target. */ | |
876fa593 | 11517 | |
2bdf28a0 | 11518 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
11519 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
11520 | { | |
876fa593 | 11521 | for (loc2p = locp; |
c7d46a38 PA |
11522 | (loc2p < bp_location + bp_location_count |
11523 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
11524 | loc2p++) |
11525 | { | |
11526 | struct bp_location *loc2 = *loc2p; | |
11527 | ||
2d134ed3 | 11528 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 11529 | { |
85d721b8 PA |
11530 | /* Read watchpoint locations are switched to |
11531 | access watchpoints, if the former are not | |
11532 | supported, but the latter are. */ | |
11533 | if (is_hardware_watchpoint (old_loc->owner)) | |
11534 | { | |
11535 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
11536 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
11537 | } | |
11538 | ||
934709f0 PW |
11539 | /* loc2 is a duplicated location. We need to check |
11540 | if it should be inserted in case it will be | |
11541 | unduplicated. */ | |
11542 | if (loc2 != old_loc | |
11543 | && unduplicated_should_be_inserted (loc2)) | |
c7d46a38 | 11544 | { |
934709f0 | 11545 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
11546 | keep_in_target = 1; |
11547 | break; | |
11548 | } | |
876fa593 JK |
11549 | } |
11550 | } | |
11551 | } | |
74960c60 VP |
11552 | } |
11553 | ||
20874c92 VP |
11554 | if (!keep_in_target) |
11555 | { | |
876fa593 | 11556 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 | 11557 | { |
4a64f543 MS |
11558 | /* This is just about all we can do. We could keep |
11559 | this location on the global list, and try to | |
11560 | remove it next time, but there's no particular | |
11561 | reason why we will succeed next time. | |
20874c92 | 11562 | |
4a64f543 MS |
11563 | Note that at this point, old_loc->owner is still |
11564 | valid, as delete_breakpoint frees the breakpoint | |
11565 | only after calling us. */ | |
3e43a32a MS |
11566 | printf_filtered (_("warning: Error removing " |
11567 | "breakpoint %d\n"), | |
876fa593 | 11568 | old_loc->owner->number); |
20874c92 VP |
11569 | } |
11570 | removed = 1; | |
11571 | } | |
0d381245 | 11572 | } |
74960c60 VP |
11573 | |
11574 | if (!found_object) | |
1c5cfe86 | 11575 | { |
db82e815 PA |
11576 | if (removed && non_stop |
11577 | && breakpoint_address_is_meaningful (old_loc->owner) | |
11578 | && !is_hardware_watchpoint (old_loc->owner)) | |
20874c92 | 11579 | { |
db82e815 PA |
11580 | /* This location was removed from the target. In |
11581 | non-stop mode, a race condition is possible where | |
11582 | we've removed a breakpoint, but stop events for that | |
11583 | breakpoint are already queued and will arrive later. | |
11584 | We apply an heuristic to be able to distinguish such | |
11585 | SIGTRAPs from other random SIGTRAPs: we keep this | |
11586 | breakpoint location for a bit, and will retire it | |
11587 | after we see some number of events. The theory here | |
11588 | is that reporting of events should, "on the average", | |
11589 | be fair, so after a while we'll see events from all | |
11590 | threads that have anything of interest, and no longer | |
11591 | need to keep this breakpoint location around. We | |
11592 | don't hold locations forever so to reduce chances of | |
11593 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
11594 | SIGTRAP. | |
11595 | ||
11596 | The heuristic failing can be disastrous on | |
11597 | decr_pc_after_break targets. | |
11598 | ||
11599 | On decr_pc_after_break targets, like e.g., x86-linux, | |
11600 | if we fail to recognize a late breakpoint SIGTRAP, | |
11601 | because events_till_retirement has reached 0 too | |
11602 | soon, we'll fail to do the PC adjustment, and report | |
11603 | a random SIGTRAP to the user. When the user resumes | |
11604 | the inferior, it will most likely immediately crash | |
2dec564e | 11605 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
11606 | corrupted, because of being resumed e.g., in the |
11607 | middle of a multi-byte instruction, or skipped a | |
11608 | one-byte instruction. This was actually seen happen | |
11609 | on native x86-linux, and should be less rare on | |
11610 | targets that do not support new thread events, like | |
11611 | remote, due to the heuristic depending on | |
11612 | thread_count. | |
11613 | ||
11614 | Mistaking a random SIGTRAP for a breakpoint trap | |
11615 | causes similar symptoms (PC adjustment applied when | |
11616 | it shouldn't), but then again, playing with SIGTRAPs | |
11617 | behind the debugger's back is asking for trouble. | |
11618 | ||
11619 | Since hardware watchpoint traps are always | |
11620 | distinguishable from other traps, so we don't need to | |
11621 | apply keep hardware watchpoint moribund locations | |
11622 | around. We simply always ignore hardware watchpoint | |
11623 | traps we can no longer explain. */ | |
11624 | ||
876fa593 JK |
11625 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
11626 | old_loc->owner = NULL; | |
20874c92 | 11627 | |
876fa593 | 11628 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
11629 | } |
11630 | else | |
f431efe5 PA |
11631 | { |
11632 | old_loc->owner = NULL; | |
11633 | decref_bp_location (&old_loc); | |
11634 | } | |
20874c92 | 11635 | } |
74960c60 | 11636 | } |
1c5cfe86 | 11637 | |
348d480f PA |
11638 | /* Rescan breakpoints at the same address and section, marking the |
11639 | first one as "first" and any others as "duplicates". This is so | |
11640 | that the bpt instruction is only inserted once. If we have a | |
11641 | permanent breakpoint at the same place as BPT, make that one the | |
11642 | official one, and the rest as duplicates. Permanent breakpoints | |
11643 | are sorted first for the same address. | |
11644 | ||
11645 | Do the same for hardware watchpoints, but also considering the | |
11646 | watchpoint's type (regular/access/read) and length. */ | |
11647 | ||
11648 | bp_loc_first = NULL; | |
11649 | wp_loc_first = NULL; | |
11650 | awp_loc_first = NULL; | |
11651 | rwp_loc_first = NULL; | |
11652 | ALL_BP_LOCATIONS (loc, locp) | |
11653 | { | |
11654 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
11655 | non-NULL. */ | |
348d480f | 11656 | struct bp_location **loc_first_p; |
d3fbdd86 | 11657 | b = loc->owner; |
348d480f | 11658 | |
f8eba3c6 | 11659 | if (!should_be_inserted (loc) |
348d480f | 11660 | || !breakpoint_address_is_meaningful (b) |
1e4d1764 YQ |
11661 | /* Don't detect duplicate for tracepoint locations because they are |
11662 | never duplicated. See the comments in field `duplicate' of | |
11663 | `struct bp_location'. */ | |
348d480f | 11664 | || is_tracepoint (b)) |
b775012e LM |
11665 | { |
11666 | /* Clear the condition modification flag. */ | |
11667 | loc->condition_changed = condition_unchanged; | |
11668 | continue; | |
11669 | } | |
348d480f PA |
11670 | |
11671 | /* Permanent breakpoint should always be inserted. */ | |
11672 | if (b->enable_state == bp_permanent && ! loc->inserted) | |
11673 | internal_error (__FILE__, __LINE__, | |
11674 | _("allegedly permanent breakpoint is not " | |
11675 | "actually inserted")); | |
11676 | ||
11677 | if (b->type == bp_hardware_watchpoint) | |
11678 | loc_first_p = &wp_loc_first; | |
11679 | else if (b->type == bp_read_watchpoint) | |
11680 | loc_first_p = &rwp_loc_first; | |
11681 | else if (b->type == bp_access_watchpoint) | |
11682 | loc_first_p = &awp_loc_first; | |
11683 | else | |
11684 | loc_first_p = &bp_loc_first; | |
11685 | ||
11686 | if (*loc_first_p == NULL | |
11687 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
11688 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
11689 | { | |
11690 | *loc_first_p = loc; | |
11691 | loc->duplicate = 0; | |
b775012e LM |
11692 | |
11693 | if (is_breakpoint (loc->owner) && loc->condition_changed) | |
11694 | { | |
11695 | loc->needs_update = 1; | |
11696 | /* Clear the condition modification flag. */ | |
11697 | loc->condition_changed = condition_unchanged; | |
11698 | } | |
348d480f PA |
11699 | continue; |
11700 | } | |
11701 | ||
934709f0 PW |
11702 | |
11703 | /* This and the above ensure the invariant that the first location | |
11704 | is not duplicated, and is the inserted one. | |
11705 | All following are marked as duplicated, and are not inserted. */ | |
11706 | if (loc->inserted) | |
11707 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
11708 | loc->duplicate = 1; |
11709 | ||
b775012e LM |
11710 | /* Clear the condition modification flag. */ |
11711 | loc->condition_changed = condition_unchanged; | |
11712 | ||
348d480f PA |
11713 | if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted |
11714 | && b->enable_state != bp_permanent) | |
11715 | internal_error (__FILE__, __LINE__, | |
11716 | _("another breakpoint was inserted on top of " | |
11717 | "a permanent breakpoint")); | |
11718 | } | |
11719 | ||
b775012e | 11720 | if (breakpoints_always_inserted_mode () |
348d480f PA |
11721 | && (have_live_inferiors () |
11722 | || (gdbarch_has_global_breakpoints (target_gdbarch)))) | |
b775012e LM |
11723 | { |
11724 | if (should_insert) | |
11725 | insert_breakpoint_locations (); | |
11726 | else | |
11727 | { | |
11728 | /* Though should_insert is false, we may need to update conditions | |
11729 | on the target's side if it is evaluating such conditions. We | |
11730 | only update conditions for locations that are marked | |
11731 | "needs_update". */ | |
11732 | update_inserted_breakpoint_locations (); | |
11733 | } | |
11734 | } | |
348d480f | 11735 | |
1e4d1764 YQ |
11736 | if (should_insert) |
11737 | download_tracepoint_locations (); | |
11738 | ||
348d480f PA |
11739 | do_cleanups (cleanups); |
11740 | } | |
11741 | ||
11742 | void | |
11743 | breakpoint_retire_moribund (void) | |
11744 | { | |
11745 | struct bp_location *loc; | |
11746 | int ix; | |
11747 | ||
11748 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
11749 | if (--(loc->events_till_retirement) == 0) | |
11750 | { | |
11751 | decref_bp_location (&loc); | |
11752 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
11753 | --ix; | |
11754 | } | |
11755 | } | |
11756 | ||
11757 | static void | |
11758 | update_global_location_list_nothrow (int inserting) | |
11759 | { | |
bfd189b1 | 11760 | volatile struct gdb_exception e; |
348d480f PA |
11761 | |
11762 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
11763 | update_global_location_list (inserting); | |
11764 | } | |
11765 | ||
11766 | /* Clear BKP from a BPS. */ | |
11767 | ||
11768 | static void | |
11769 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) | |
11770 | { | |
11771 | bpstat bs; | |
11772 | ||
11773 | for (bs = bps; bs; bs = bs->next) | |
11774 | if (bs->breakpoint_at == bpt) | |
11775 | { | |
11776 | bs->breakpoint_at = NULL; | |
11777 | bs->old_val = NULL; | |
11778 | /* bs->commands will be freed later. */ | |
11779 | } | |
11780 | } | |
11781 | ||
11782 | /* Callback for iterate_over_threads. */ | |
11783 | static int | |
11784 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
11785 | { | |
11786 | struct breakpoint *bpt = data; | |
11787 | ||
11788 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
11789 | return 0; | |
11790 | } | |
11791 | ||
11792 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
11793 | callbacks. */ | |
11794 | ||
11795 | static void | |
11796 | say_where (struct breakpoint *b) | |
11797 | { | |
79a45e25 | 11798 | struct ui_out *uiout = current_uiout; |
348d480f PA |
11799 | struct value_print_options opts; |
11800 | ||
11801 | get_user_print_options (&opts); | |
11802 | ||
11803 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
11804 | single string. */ | |
11805 | if (b->loc == NULL) | |
11806 | { | |
11807 | printf_filtered (_(" (%s) pending."), b->addr_string); | |
11808 | } | |
11809 | else | |
11810 | { | |
f8eba3c6 | 11811 | if (opts.addressprint || b->loc->source_file == NULL) |
348d480f PA |
11812 | { |
11813 | printf_filtered (" at "); | |
11814 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), | |
11815 | gdb_stdout); | |
11816 | } | |
f8eba3c6 TT |
11817 | if (b->loc->source_file) |
11818 | { | |
11819 | /* If there is a single location, we can print the location | |
11820 | more nicely. */ | |
11821 | if (b->loc->next == NULL) | |
11822 | printf_filtered (": file %s, line %d.", | |
11823 | b->loc->source_file, b->loc->line_number); | |
11824 | else | |
11825 | /* This is not ideal, but each location may have a | |
11826 | different file name, and this at least reflects the | |
11827 | real situation somewhat. */ | |
11828 | printf_filtered (": %s.", b->addr_string); | |
11829 | } | |
348d480f PA |
11830 | |
11831 | if (b->loc->next) | |
11832 | { | |
11833 | struct bp_location *loc = b->loc; | |
11834 | int n = 0; | |
11835 | for (; loc; loc = loc->next) | |
11836 | ++n; | |
11837 | printf_filtered (" (%d locations)", n); | |
11838 | } | |
11839 | } | |
11840 | } | |
11841 | ||
348d480f PA |
11842 | /* Default bp_location_ops methods. */ |
11843 | ||
11844 | static void | |
11845 | bp_location_dtor (struct bp_location *self) | |
11846 | { | |
11847 | xfree (self->cond); | |
b775012e LM |
11848 | if (self->cond_bytecode) |
11849 | free_agent_expr (self->cond_bytecode); | |
348d480f | 11850 | xfree (self->function_name); |
f8eba3c6 | 11851 | xfree (self->source_file); |
348d480f PA |
11852 | } |
11853 | ||
11854 | static const struct bp_location_ops bp_location_ops = | |
11855 | { | |
11856 | bp_location_dtor | |
11857 | }; | |
11858 | ||
2060206e PA |
11859 | /* Default breakpoint_ops methods all breakpoint_ops ultimately |
11860 | inherit from. */ | |
348d480f | 11861 | |
2060206e PA |
11862 | static void |
11863 | base_breakpoint_dtor (struct breakpoint *self) | |
348d480f PA |
11864 | { |
11865 | decref_counted_command_line (&self->commands); | |
11866 | xfree (self->cond_string); | |
348d480f | 11867 | xfree (self->addr_string); |
f8eba3c6 | 11868 | xfree (self->filter); |
348d480f | 11869 | xfree (self->addr_string_range_end); |
348d480f PA |
11870 | } |
11871 | ||
2060206e PA |
11872 | static struct bp_location * |
11873 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f PA |
11874 | { |
11875 | struct bp_location *loc; | |
11876 | ||
11877 | loc = XNEW (struct bp_location); | |
11878 | init_bp_location (loc, &bp_location_ops, self); | |
11879 | return loc; | |
11880 | } | |
11881 | ||
2060206e PA |
11882 | static void |
11883 | base_breakpoint_re_set (struct breakpoint *b) | |
11884 | { | |
11885 | /* Nothing to re-set. */ | |
11886 | } | |
11887 | ||
11888 | #define internal_error_pure_virtual_called() \ | |
11889 | gdb_assert_not_reached ("pure virtual function called") | |
11890 | ||
11891 | static int | |
11892 | base_breakpoint_insert_location (struct bp_location *bl) | |
11893 | { | |
11894 | internal_error_pure_virtual_called (); | |
11895 | } | |
11896 | ||
11897 | static int | |
11898 | base_breakpoint_remove_location (struct bp_location *bl) | |
11899 | { | |
11900 | internal_error_pure_virtual_called (); | |
11901 | } | |
11902 | ||
11903 | static int | |
11904 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
11905 | struct address_space *aspace, | |
09ac7c10 TT |
11906 | CORE_ADDR bp_addr, |
11907 | const struct target_waitstatus *ws) | |
2060206e PA |
11908 | { |
11909 | internal_error_pure_virtual_called (); | |
11910 | } | |
11911 | ||
11912 | static void | |
11913 | base_breakpoint_check_status (bpstat bs) | |
11914 | { | |
11915 | /* Always stop. */ | |
11916 | } | |
11917 | ||
11918 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
11919 | errors. */ | |
11920 | ||
11921 | static int | |
11922 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
11923 | { | |
11924 | internal_error_pure_virtual_called (); | |
11925 | } | |
11926 | ||
11927 | /* A "resources_needed" breakpoint_ops method that just internal | |
11928 | errors. */ | |
11929 | ||
11930 | static int | |
11931 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
11932 | { | |
11933 | internal_error_pure_virtual_called (); | |
11934 | } | |
11935 | ||
11936 | static enum print_stop_action | |
11937 | base_breakpoint_print_it (bpstat bs) | |
11938 | { | |
11939 | internal_error_pure_virtual_called (); | |
11940 | } | |
11941 | ||
11942 | static void | |
11943 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
11944 | struct ui_out *uiout) | |
11945 | { | |
11946 | /* nothing */ | |
11947 | } | |
11948 | ||
11949 | static void | |
11950 | base_breakpoint_print_mention (struct breakpoint *b) | |
11951 | { | |
11952 | internal_error_pure_virtual_called (); | |
11953 | } | |
11954 | ||
11955 | static void | |
11956 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
11957 | { | |
11958 | internal_error_pure_virtual_called (); | |
11959 | } | |
11960 | ||
983af33b SDJ |
11961 | static void |
11962 | base_breakpoint_create_sals_from_address (char **arg, | |
11963 | struct linespec_result *canonical, | |
11964 | enum bptype type_wanted, | |
11965 | char *addr_start, | |
11966 | char **copy_arg) | |
11967 | { | |
11968 | internal_error_pure_virtual_called (); | |
11969 | } | |
11970 | ||
11971 | static void | |
11972 | base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
11973 | struct linespec_result *c, | |
11974 | struct linespec_sals *lsal, | |
11975 | char *cond_string, | |
11976 | enum bptype type_wanted, | |
11977 | enum bpdisp disposition, | |
11978 | int thread, | |
11979 | int task, int ignore_count, | |
11980 | const struct breakpoint_ops *o, | |
11981 | int from_tty, int enabled, | |
11982 | int internal) | |
11983 | { | |
11984 | internal_error_pure_virtual_called (); | |
11985 | } | |
11986 | ||
11987 | static void | |
11988 | base_breakpoint_decode_linespec (struct breakpoint *b, char **s, | |
11989 | struct symtabs_and_lines *sals) | |
11990 | { | |
11991 | internal_error_pure_virtual_called (); | |
11992 | } | |
11993 | ||
2060206e PA |
11994 | static struct breakpoint_ops base_breakpoint_ops = |
11995 | { | |
11996 | base_breakpoint_dtor, | |
11997 | base_breakpoint_allocate_location, | |
11998 | base_breakpoint_re_set, | |
11999 | base_breakpoint_insert_location, | |
12000 | base_breakpoint_remove_location, | |
12001 | base_breakpoint_breakpoint_hit, | |
12002 | base_breakpoint_check_status, | |
12003 | base_breakpoint_resources_needed, | |
12004 | base_breakpoint_works_in_software_mode, | |
12005 | base_breakpoint_print_it, | |
12006 | NULL, | |
12007 | base_breakpoint_print_one_detail, | |
12008 | base_breakpoint_print_mention, | |
983af33b SDJ |
12009 | base_breakpoint_print_recreate, |
12010 | base_breakpoint_create_sals_from_address, | |
12011 | base_breakpoint_create_breakpoints_sal, | |
12012 | base_breakpoint_decode_linespec, | |
2060206e PA |
12013 | }; |
12014 | ||
12015 | /* Default breakpoint_ops methods. */ | |
12016 | ||
12017 | static void | |
348d480f PA |
12018 | bkpt_re_set (struct breakpoint *b) |
12019 | { | |
06edf0c0 PA |
12020 | /* FIXME: is this still reachable? */ |
12021 | if (b->addr_string == NULL) | |
12022 | { | |
12023 | /* Anything without a string can't be re-set. */ | |
348d480f | 12024 | delete_breakpoint (b); |
06edf0c0 | 12025 | return; |
348d480f | 12026 | } |
06edf0c0 PA |
12027 | |
12028 | breakpoint_re_set_default (b); | |
348d480f PA |
12029 | } |
12030 | ||
2060206e | 12031 | static int |
348d480f PA |
12032 | bkpt_insert_location (struct bp_location *bl) |
12033 | { | |
12034 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
12035 | return target_insert_hw_breakpoint (bl->gdbarch, | |
12036 | &bl->target_info); | |
12037 | else | |
12038 | return target_insert_breakpoint (bl->gdbarch, | |
12039 | &bl->target_info); | |
12040 | } | |
12041 | ||
2060206e | 12042 | static int |
348d480f PA |
12043 | bkpt_remove_location (struct bp_location *bl) |
12044 | { | |
12045 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
12046 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
12047 | else | |
12048 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info); | |
12049 | } | |
12050 | ||
2060206e | 12051 | static int |
348d480f | 12052 | bkpt_breakpoint_hit (const struct bp_location *bl, |
09ac7c10 TT |
12053 | struct address_space *aspace, CORE_ADDR bp_addr, |
12054 | const struct target_waitstatus *ws) | |
348d480f PA |
12055 | { |
12056 | struct breakpoint *b = bl->owner; | |
12057 | ||
09ac7c10 TT |
12058 | if (ws->kind != TARGET_WAITKIND_STOPPED |
12059 | || ws->value.sig != TARGET_SIGNAL_TRAP) | |
12060 | return 0; | |
12061 | ||
348d480f PA |
12062 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
12063 | aspace, bp_addr)) | |
12064 | return 0; | |
12065 | ||
12066 | if (overlay_debugging /* unmapped overlay section */ | |
12067 | && section_is_overlay (bl->section) | |
12068 | && !section_is_mapped (bl->section)) | |
12069 | return 0; | |
12070 | ||
12071 | return 1; | |
12072 | } | |
12073 | ||
2060206e | 12074 | static int |
348d480f PA |
12075 | bkpt_resources_needed (const struct bp_location *bl) |
12076 | { | |
12077 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
12078 | ||
12079 | return 1; | |
12080 | } | |
12081 | ||
2060206e | 12082 | static enum print_stop_action |
348d480f PA |
12083 | bkpt_print_it (bpstat bs) |
12084 | { | |
348d480f PA |
12085 | struct breakpoint *b; |
12086 | const struct bp_location *bl; | |
001c8c33 | 12087 | int bp_temp; |
79a45e25 | 12088 | struct ui_out *uiout = current_uiout; |
348d480f PA |
12089 | |
12090 | gdb_assert (bs->bp_location_at != NULL); | |
12091 | ||
12092 | bl = bs->bp_location_at; | |
12093 | b = bs->breakpoint_at; | |
12094 | ||
001c8c33 PA |
12095 | bp_temp = b->disposition == disp_del; |
12096 | if (bl->address != bl->requested_address) | |
12097 | breakpoint_adjustment_warning (bl->requested_address, | |
12098 | bl->address, | |
12099 | b->number, 1); | |
12100 | annotate_breakpoint (b->number); | |
12101 | if (bp_temp) | |
12102 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
12103 | else | |
12104 | ui_out_text (uiout, "\nBreakpoint "); | |
12105 | if (ui_out_is_mi_like_p (uiout)) | |
348d480f | 12106 | { |
001c8c33 PA |
12107 | ui_out_field_string (uiout, "reason", |
12108 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
12109 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
06edf0c0 | 12110 | } |
001c8c33 PA |
12111 | ui_out_field_int (uiout, "bkptno", b->number); |
12112 | ui_out_text (uiout, ", "); | |
06edf0c0 | 12113 | |
001c8c33 | 12114 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
12115 | } |
12116 | ||
2060206e | 12117 | static void |
06edf0c0 PA |
12118 | bkpt_print_mention (struct breakpoint *b) |
12119 | { | |
79a45e25 | 12120 | if (ui_out_is_mi_like_p (current_uiout)) |
06edf0c0 PA |
12121 | return; |
12122 | ||
12123 | switch (b->type) | |
12124 | { | |
12125 | case bp_breakpoint: | |
12126 | case bp_gnu_ifunc_resolver: | |
12127 | if (b->disposition == disp_del) | |
12128 | printf_filtered (_("Temporary breakpoint")); | |
12129 | else | |
12130 | printf_filtered (_("Breakpoint")); | |
12131 | printf_filtered (_(" %d"), b->number); | |
12132 | if (b->type == bp_gnu_ifunc_resolver) | |
12133 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
12134 | break; | |
12135 | case bp_hardware_breakpoint: | |
12136 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
12137 | break; | |
12138 | } | |
12139 | ||
12140 | say_where (b); | |
12141 | } | |
12142 | ||
2060206e | 12143 | static void |
06edf0c0 PA |
12144 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
12145 | { | |
12146 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
12147 | fprintf_unfiltered (fp, "tbreak"); | |
12148 | else if (tp->type == bp_breakpoint) | |
12149 | fprintf_unfiltered (fp, "break"); | |
12150 | else if (tp->type == bp_hardware_breakpoint | |
12151 | && tp->disposition == disp_del) | |
12152 | fprintf_unfiltered (fp, "thbreak"); | |
12153 | else if (tp->type == bp_hardware_breakpoint) | |
12154 | fprintf_unfiltered (fp, "hbreak"); | |
12155 | else | |
12156 | internal_error (__FILE__, __LINE__, | |
12157 | _("unhandled breakpoint type %d"), (int) tp->type); | |
12158 | ||
2060206e | 12159 | fprintf_unfiltered (fp, " %s", tp->addr_string); |
dd11a36c | 12160 | print_recreate_thread (tp, fp); |
06edf0c0 PA |
12161 | } |
12162 | ||
983af33b SDJ |
12163 | static void |
12164 | bkpt_create_sals_from_address (char **arg, | |
12165 | struct linespec_result *canonical, | |
12166 | enum bptype type_wanted, | |
12167 | char *addr_start, char **copy_arg) | |
12168 | { | |
12169 | create_sals_from_address_default (arg, canonical, type_wanted, | |
12170 | addr_start, copy_arg); | |
12171 | } | |
12172 | ||
12173 | static void | |
12174 | bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12175 | struct linespec_result *canonical, | |
12176 | struct linespec_sals *lsal, | |
12177 | char *cond_string, | |
12178 | enum bptype type_wanted, | |
12179 | enum bpdisp disposition, | |
12180 | int thread, | |
12181 | int task, int ignore_count, | |
12182 | const struct breakpoint_ops *ops, | |
12183 | int from_tty, int enabled, | |
12184 | int internal) | |
12185 | { | |
12186 | create_breakpoints_sal_default (gdbarch, canonical, lsal, | |
12187 | cond_string, type_wanted, | |
12188 | disposition, thread, task, | |
12189 | ignore_count, ops, from_tty, | |
12190 | enabled, internal); | |
12191 | } | |
12192 | ||
12193 | static void | |
12194 | bkpt_decode_linespec (struct breakpoint *b, char **s, | |
12195 | struct symtabs_and_lines *sals) | |
12196 | { | |
12197 | decode_linespec_default (b, s, sals); | |
12198 | } | |
12199 | ||
06edf0c0 PA |
12200 | /* Virtual table for internal breakpoints. */ |
12201 | ||
12202 | static void | |
12203 | internal_bkpt_re_set (struct breakpoint *b) | |
12204 | { | |
12205 | switch (b->type) | |
12206 | { | |
12207 | /* Delete overlay event and longjmp master breakpoints; they | |
12208 | will be reset later by breakpoint_re_set. */ | |
12209 | case bp_overlay_event: | |
12210 | case bp_longjmp_master: | |
12211 | case bp_std_terminate_master: | |
12212 | case bp_exception_master: | |
12213 | delete_breakpoint (b); | |
12214 | break; | |
12215 | ||
12216 | /* This breakpoint is special, it's set up when the inferior | |
12217 | starts and we really don't want to touch it. */ | |
12218 | case bp_shlib_event: | |
12219 | ||
12220 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
12221 | it is set up, we do not want to touch it. */ | |
12222 | case bp_thread_event: | |
12223 | break; | |
12224 | } | |
12225 | } | |
12226 | ||
12227 | static void | |
12228 | internal_bkpt_check_status (bpstat bs) | |
12229 | { | |
a9b3a50f PA |
12230 | if (bs->breakpoint_at->type == bp_shlib_event) |
12231 | { | |
12232 | /* If requested, stop when the dynamic linker notifies GDB of | |
12233 | events. This allows the user to get control and place | |
12234 | breakpoints in initializer routines for dynamically loaded | |
12235 | objects (among other things). */ | |
12236 | bs->stop = stop_on_solib_events; | |
12237 | bs->print = stop_on_solib_events; | |
12238 | } | |
12239 | else | |
12240 | bs->stop = 0; | |
06edf0c0 PA |
12241 | } |
12242 | ||
12243 | static enum print_stop_action | |
12244 | internal_bkpt_print_it (bpstat bs) | |
12245 | { | |
36dfb11c | 12246 | struct ui_out *uiout = current_uiout; |
06edf0c0 | 12247 | struct breakpoint *b; |
06edf0c0 | 12248 | |
06edf0c0 PA |
12249 | b = bs->breakpoint_at; |
12250 | ||
06edf0c0 PA |
12251 | switch (b->type) |
12252 | { | |
348d480f PA |
12253 | case bp_shlib_event: |
12254 | /* Did we stop because the user set the stop_on_solib_events | |
12255 | variable? (If so, we report this as a generic, "Stopped due | |
12256 | to shlib event" message.) */ | |
edcc5120 | 12257 | print_solib_event (0); |
348d480f PA |
12258 | break; |
12259 | ||
12260 | case bp_thread_event: | |
12261 | /* Not sure how we will get here. | |
12262 | GDB should not stop for these breakpoints. */ | |
12263 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
12264 | break; |
12265 | ||
12266 | case bp_overlay_event: | |
12267 | /* By analogy with the thread event, GDB should not stop for these. */ | |
12268 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
12269 | break; |
12270 | ||
12271 | case bp_longjmp_master: | |
12272 | /* These should never be enabled. */ | |
12273 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
12274 | break; |
12275 | ||
12276 | case bp_std_terminate_master: | |
12277 | /* These should never be enabled. */ | |
12278 | printf_filtered (_("std::terminate Master Breakpoint: " | |
12279 | "gdb should not stop!\n")); | |
348d480f PA |
12280 | break; |
12281 | ||
12282 | case bp_exception_master: | |
12283 | /* These should never be enabled. */ | |
12284 | printf_filtered (_("Exception Master Breakpoint: " | |
12285 | "gdb should not stop!\n")); | |
06edf0c0 PA |
12286 | break; |
12287 | } | |
12288 | ||
001c8c33 | 12289 | return PRINT_NOTHING; |
06edf0c0 PA |
12290 | } |
12291 | ||
12292 | static void | |
12293 | internal_bkpt_print_mention (struct breakpoint *b) | |
12294 | { | |
12295 | /* Nothing to mention. These breakpoints are internal. */ | |
12296 | } | |
12297 | ||
06edf0c0 PA |
12298 | /* Virtual table for momentary breakpoints */ |
12299 | ||
12300 | static void | |
12301 | momentary_bkpt_re_set (struct breakpoint *b) | |
12302 | { | |
12303 | /* Keep temporary breakpoints, which can be encountered when we step | |
12304 | over a dlopen call and SOLIB_ADD is resetting the breakpoints. | |
12305 | Otherwise these should have been blown away via the cleanup chain | |
12306 | or by breakpoint_init_inferior when we rerun the executable. */ | |
12307 | } | |
12308 | ||
12309 | static void | |
12310 | momentary_bkpt_check_status (bpstat bs) | |
12311 | { | |
12312 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
12313 | } | |
12314 | ||
12315 | static enum print_stop_action | |
12316 | momentary_bkpt_print_it (bpstat bs) | |
12317 | { | |
79a45e25 PA |
12318 | struct ui_out *uiout = current_uiout; |
12319 | ||
001c8c33 | 12320 | if (ui_out_is_mi_like_p (uiout)) |
06edf0c0 | 12321 | { |
001c8c33 | 12322 | struct breakpoint *b = bs->breakpoint_at; |
348d480f | 12323 | |
001c8c33 PA |
12324 | switch (b->type) |
12325 | { | |
12326 | case bp_finish: | |
12327 | ui_out_field_string | |
12328 | (uiout, "reason", | |
12329 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
12330 | break; | |
348d480f | 12331 | |
001c8c33 PA |
12332 | case bp_until: |
12333 | ui_out_field_string | |
12334 | (uiout, "reason", | |
12335 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
12336 | break; | |
12337 | } | |
348d480f PA |
12338 | } |
12339 | ||
001c8c33 | 12340 | return PRINT_UNKNOWN; |
348d480f PA |
12341 | } |
12342 | ||
06edf0c0 PA |
12343 | static void |
12344 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 12345 | { |
06edf0c0 | 12346 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
12347 | } |
12348 | ||
348d480f | 12349 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 12350 | |
348d480f PA |
12351 | static void |
12352 | tracepoint_re_set (struct breakpoint *b) | |
12353 | { | |
12354 | breakpoint_re_set_default (b); | |
12355 | } | |
876fa593 | 12356 | |
348d480f PA |
12357 | static int |
12358 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
09ac7c10 TT |
12359 | struct address_space *aspace, CORE_ADDR bp_addr, |
12360 | const struct target_waitstatus *ws) | |
348d480f PA |
12361 | { |
12362 | /* By definition, the inferior does not report stops at | |
12363 | tracepoints. */ | |
12364 | return 0; | |
74960c60 VP |
12365 | } |
12366 | ||
12367 | static void | |
348d480f PA |
12368 | tracepoint_print_one_detail (const struct breakpoint *self, |
12369 | struct ui_out *uiout) | |
74960c60 | 12370 | { |
d9b3f62e PA |
12371 | struct tracepoint *tp = (struct tracepoint *) self; |
12372 | if (tp->static_trace_marker_id) | |
348d480f PA |
12373 | { |
12374 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 12375 | |
348d480f PA |
12376 | ui_out_text (uiout, "\tmarker id is "); |
12377 | ui_out_field_string (uiout, "static-tracepoint-marker-string-id", | |
d9b3f62e | 12378 | tp->static_trace_marker_id); |
348d480f PA |
12379 | ui_out_text (uiout, "\n"); |
12380 | } | |
0d381245 VP |
12381 | } |
12382 | ||
a474d7c2 | 12383 | static void |
348d480f | 12384 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 12385 | { |
79a45e25 | 12386 | if (ui_out_is_mi_like_p (current_uiout)) |
348d480f | 12387 | return; |
cc59ec59 | 12388 | |
348d480f PA |
12389 | switch (b->type) |
12390 | { | |
12391 | case bp_tracepoint: | |
12392 | printf_filtered (_("Tracepoint")); | |
12393 | printf_filtered (_(" %d"), b->number); | |
12394 | break; | |
12395 | case bp_fast_tracepoint: | |
12396 | printf_filtered (_("Fast tracepoint")); | |
12397 | printf_filtered (_(" %d"), b->number); | |
12398 | break; | |
12399 | case bp_static_tracepoint: | |
12400 | printf_filtered (_("Static tracepoint")); | |
12401 | printf_filtered (_(" %d"), b->number); | |
12402 | break; | |
12403 | default: | |
12404 | internal_error (__FILE__, __LINE__, | |
12405 | _("unhandled tracepoint type %d"), (int) b->type); | |
12406 | } | |
12407 | ||
12408 | say_where (b); | |
a474d7c2 PA |
12409 | } |
12410 | ||
348d480f | 12411 | static void |
d9b3f62e | 12412 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 12413 | { |
d9b3f62e PA |
12414 | struct tracepoint *tp = (struct tracepoint *) self; |
12415 | ||
12416 | if (self->type == bp_fast_tracepoint) | |
348d480f | 12417 | fprintf_unfiltered (fp, "ftrace"); |
d9b3f62e | 12418 | if (self->type == bp_static_tracepoint) |
348d480f | 12419 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 12420 | else if (self->type == bp_tracepoint) |
348d480f PA |
12421 | fprintf_unfiltered (fp, "trace"); |
12422 | else | |
12423 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 12424 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 12425 | |
d9b3f62e PA |
12426 | fprintf_unfiltered (fp, " %s", self->addr_string); |
12427 | print_recreate_thread (self, fp); | |
12428 | ||
12429 | if (tp->pass_count) | |
12430 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
12431 | } |
12432 | ||
983af33b SDJ |
12433 | static void |
12434 | tracepoint_create_sals_from_address (char **arg, | |
12435 | struct linespec_result *canonical, | |
12436 | enum bptype type_wanted, | |
12437 | char *addr_start, char **copy_arg) | |
12438 | { | |
12439 | create_sals_from_address_default (arg, canonical, type_wanted, | |
12440 | addr_start, copy_arg); | |
12441 | } | |
12442 | ||
12443 | static void | |
12444 | tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12445 | struct linespec_result *canonical, | |
12446 | struct linespec_sals *lsal, | |
12447 | char *cond_string, | |
12448 | enum bptype type_wanted, | |
12449 | enum bpdisp disposition, | |
12450 | int thread, | |
12451 | int task, int ignore_count, | |
12452 | const struct breakpoint_ops *ops, | |
12453 | int from_tty, int enabled, | |
12454 | int internal) | |
12455 | { | |
12456 | create_breakpoints_sal_default (gdbarch, canonical, lsal, | |
12457 | cond_string, type_wanted, | |
12458 | disposition, thread, task, | |
12459 | ignore_count, ops, from_tty, | |
12460 | enabled, internal); | |
12461 | } | |
12462 | ||
12463 | static void | |
12464 | tracepoint_decode_linespec (struct breakpoint *b, char **s, | |
12465 | struct symtabs_and_lines *sals) | |
12466 | { | |
12467 | decode_linespec_default (b, s, sals); | |
12468 | } | |
12469 | ||
2060206e | 12470 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 12471 | |
983af33b SDJ |
12472 | /* The breakpoint_ops structure to be used on static tracepoints with |
12473 | markers (`-m'). */ | |
12474 | ||
12475 | static void | |
12476 | strace_marker_create_sals_from_address (char **arg, | |
12477 | struct linespec_result *canonical, | |
12478 | enum bptype type_wanted, | |
12479 | char *addr_start, char **copy_arg) | |
12480 | { | |
12481 | struct linespec_sals lsal; | |
12482 | ||
12483 | lsal.sals = decode_static_tracepoint_spec (arg); | |
12484 | ||
12485 | *copy_arg = savestring (addr_start, *arg - addr_start); | |
12486 | ||
12487 | canonical->addr_string = xstrdup (*copy_arg); | |
12488 | lsal.canonical = xstrdup (*copy_arg); | |
12489 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
12490 | } | |
12491 | ||
12492 | static void | |
12493 | strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12494 | struct linespec_result *canonical, | |
12495 | struct linespec_sals *lsal, | |
12496 | char *cond_string, | |
12497 | enum bptype type_wanted, | |
12498 | enum bpdisp disposition, | |
12499 | int thread, | |
12500 | int task, int ignore_count, | |
12501 | const struct breakpoint_ops *ops, | |
12502 | int from_tty, int enabled, | |
12503 | int internal) | |
12504 | { | |
12505 | int i; | |
12506 | ||
12507 | /* If the user is creating a static tracepoint by marker id | |
12508 | (strace -m MARKER_ID), then store the sals index, so that | |
12509 | breakpoint_re_set can try to match up which of the newly | |
12510 | found markers corresponds to this one, and, don't try to | |
12511 | expand multiple locations for each sal, given than SALS | |
12512 | already should contain all sals for MARKER_ID. */ | |
12513 | ||
12514 | for (i = 0; i < lsal->sals.nelts; ++i) | |
12515 | { | |
12516 | struct symtabs_and_lines expanded; | |
12517 | struct tracepoint *tp; | |
12518 | struct cleanup *old_chain; | |
12519 | char *addr_string; | |
12520 | ||
12521 | expanded.nelts = 1; | |
12522 | expanded.sals = &lsal->sals.sals[i]; | |
12523 | ||
12524 | addr_string = xstrdup (canonical->addr_string); | |
12525 | old_chain = make_cleanup (xfree, addr_string); | |
12526 | ||
12527 | tp = XCNEW (struct tracepoint); | |
12528 | init_breakpoint_sal (&tp->base, gdbarch, expanded, | |
12529 | addr_string, NULL, | |
12530 | cond_string, type_wanted, disposition, | |
12531 | thread, task, ignore_count, ops, | |
12532 | from_tty, enabled, internal, | |
12533 | canonical->special_display); | |
12534 | /* Given that its possible to have multiple markers with | |
12535 | the same string id, if the user is creating a static | |
12536 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
12537 | store the sals index, so that breakpoint_re_set can | |
12538 | try to match up which of the newly found markers | |
12539 | corresponds to this one */ | |
12540 | tp->static_trace_marker_id_idx = i; | |
12541 | ||
12542 | install_breakpoint (internal, &tp->base, 0); | |
12543 | ||
12544 | discard_cleanups (old_chain); | |
12545 | } | |
12546 | } | |
12547 | ||
12548 | static void | |
12549 | strace_marker_decode_linespec (struct breakpoint *b, char **s, | |
12550 | struct symtabs_and_lines *sals) | |
12551 | { | |
12552 | struct tracepoint *tp = (struct tracepoint *) b; | |
12553 | ||
12554 | *sals = decode_static_tracepoint_spec (s); | |
12555 | if (sals->nelts > tp->static_trace_marker_id_idx) | |
12556 | { | |
12557 | sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx]; | |
12558 | sals->nelts = 1; | |
12559 | } | |
12560 | else | |
12561 | error (_("marker %s not found"), tp->static_trace_marker_id); | |
12562 | } | |
12563 | ||
12564 | static struct breakpoint_ops strace_marker_breakpoint_ops; | |
12565 | ||
12566 | static int | |
12567 | strace_marker_p (struct breakpoint *b) | |
12568 | { | |
12569 | return b->ops == &strace_marker_breakpoint_ops; | |
12570 | } | |
12571 | ||
53a5351d | 12572 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 12573 | structures. */ |
c906108c SS |
12574 | |
12575 | void | |
fba45db2 | 12576 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 12577 | { |
52f0bd74 | 12578 | struct breakpoint *b; |
c906108c | 12579 | |
8a3fe4f8 | 12580 | gdb_assert (bpt != NULL); |
c906108c | 12581 | |
4a64f543 MS |
12582 | /* Has this bp already been deleted? This can happen because |
12583 | multiple lists can hold pointers to bp's. bpstat lists are | |
12584 | especial culprits. | |
12585 | ||
12586 | One example of this happening is a watchpoint's scope bp. When | |
12587 | the scope bp triggers, we notice that the watchpoint is out of | |
12588 | scope, and delete it. We also delete its scope bp. But the | |
12589 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
12590 | That bpstat is then checked for auto-deleting bp's, which are | |
12591 | deleted. | |
12592 | ||
12593 | A real solution to this problem might involve reference counts in | |
12594 | bp's, and/or giving them pointers back to their referencing | |
12595 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
12596 | storage when no more references were extent. A cheaper bandaid | |
12597 | was chosen. */ | |
c906108c SS |
12598 | if (bpt->type == bp_none) |
12599 | return; | |
12600 | ||
4a64f543 MS |
12601 | /* At least avoid this stale reference until the reference counting |
12602 | of breakpoints gets resolved. */ | |
d0fb5eae | 12603 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 12604 | { |
d0fb5eae | 12605 | struct breakpoint *related; |
3a5c3e22 | 12606 | struct watchpoint *w; |
d0fb5eae JK |
12607 | |
12608 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 12609 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 12610 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
12611 | w = (struct watchpoint *) bpt; |
12612 | else | |
12613 | w = NULL; | |
12614 | if (w != NULL) | |
12615 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
12616 | |
12617 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
12618 | for (related = bpt; related->related_breakpoint != bpt; | |
12619 | related = related->related_breakpoint); | |
12620 | related->related_breakpoint = bpt->related_breakpoint; | |
12621 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
12622 | } |
12623 | ||
a9634178 TJB |
12624 | /* watch_command_1 creates a watchpoint but only sets its number if |
12625 | update_watchpoint succeeds in creating its bp_locations. If there's | |
12626 | a problem in that process, we'll be asked to delete the half-created | |
12627 | watchpoint. In that case, don't announce the deletion. */ | |
12628 | if (bpt->number) | |
12629 | observer_notify_breakpoint_deleted (bpt); | |
c906108c | 12630 | |
c906108c SS |
12631 | if (breakpoint_chain == bpt) |
12632 | breakpoint_chain = bpt->next; | |
12633 | ||
c906108c SS |
12634 | ALL_BREAKPOINTS (b) |
12635 | if (b->next == bpt) | |
c5aa993b JM |
12636 | { |
12637 | b->next = bpt->next; | |
12638 | break; | |
12639 | } | |
c906108c | 12640 | |
f431efe5 PA |
12641 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
12642 | been freed. */ | |
12643 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 12644 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
12645 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
12646 | commands are associated with the bpstat; if we remove it here, | |
12647 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
12648 | event-top.c won't do anything, and temporary breakpoints with | |
12649 | commands won't work. */ | |
12650 | ||
12651 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
12652 | ||
4a64f543 MS |
12653 | /* Now that breakpoint is removed from breakpoint list, update the |
12654 | global location list. This will remove locations that used to | |
12655 | belong to this breakpoint. Do this before freeing the breakpoint | |
12656 | itself, since remove_breakpoint looks at location's owner. It | |
12657 | might be better design to have location completely | |
12658 | self-contained, but it's not the case now. */ | |
b60e7edf | 12659 | update_global_location_list (0); |
74960c60 | 12660 | |
348d480f | 12661 | bpt->ops->dtor (bpt); |
4a64f543 MS |
12662 | /* On the chance that someone will soon try again to delete this |
12663 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 12664 | bpt->type = bp_none; |
b8c9b27d | 12665 | xfree (bpt); |
c906108c SS |
12666 | } |
12667 | ||
4d6140d9 AC |
12668 | static void |
12669 | do_delete_breakpoint_cleanup (void *b) | |
12670 | { | |
12671 | delete_breakpoint (b); | |
12672 | } | |
12673 | ||
12674 | struct cleanup * | |
12675 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
12676 | { | |
12677 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
12678 | } | |
12679 | ||
51be5b68 PA |
12680 | /* Iterator function to call a user-provided callback function once |
12681 | for each of B and its related breakpoints. */ | |
12682 | ||
12683 | static void | |
12684 | iterate_over_related_breakpoints (struct breakpoint *b, | |
12685 | void (*function) (struct breakpoint *, | |
12686 | void *), | |
12687 | void *data) | |
12688 | { | |
12689 | struct breakpoint *related; | |
12690 | ||
12691 | related = b; | |
12692 | do | |
12693 | { | |
12694 | struct breakpoint *next; | |
12695 | ||
12696 | /* FUNCTION may delete RELATED. */ | |
12697 | next = related->related_breakpoint; | |
12698 | ||
12699 | if (next == related) | |
12700 | { | |
12701 | /* RELATED is the last ring entry. */ | |
12702 | function (related, data); | |
12703 | ||
12704 | /* FUNCTION may have deleted it, so we'd never reach back to | |
12705 | B. There's nothing left to do anyway, so just break | |
12706 | out. */ | |
12707 | break; | |
12708 | } | |
12709 | else | |
12710 | function (related, data); | |
12711 | ||
12712 | related = next; | |
12713 | } | |
12714 | while (related != b); | |
12715 | } | |
95a42b64 TT |
12716 | |
12717 | static void | |
12718 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
12719 | { | |
12720 | delete_breakpoint (b); | |
12721 | } | |
12722 | ||
51be5b68 PA |
12723 | /* A callback for map_breakpoint_numbers that calls |
12724 | delete_breakpoint. */ | |
12725 | ||
12726 | static void | |
12727 | do_map_delete_breakpoint (struct breakpoint *b, void *ignore) | |
12728 | { | |
12729 | iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL); | |
12730 | } | |
12731 | ||
c906108c | 12732 | void |
fba45db2 | 12733 | delete_command (char *arg, int from_tty) |
c906108c | 12734 | { |
35df4500 | 12735 | struct breakpoint *b, *b_tmp; |
c906108c | 12736 | |
ea9365bb TT |
12737 | dont_repeat (); |
12738 | ||
c906108c SS |
12739 | if (arg == 0) |
12740 | { | |
12741 | int breaks_to_delete = 0; | |
12742 | ||
46c6471b PA |
12743 | /* Delete all breakpoints if no argument. Do not delete |
12744 | internal breakpoints, these have to be deleted with an | |
12745 | explicit breakpoint number argument. */ | |
c5aa993b | 12746 | ALL_BREAKPOINTS (b) |
46c6471b | 12747 | if (user_breakpoint_p (b)) |
973d738b DJ |
12748 | { |
12749 | breaks_to_delete = 1; | |
12750 | break; | |
12751 | } | |
c906108c SS |
12752 | |
12753 | /* Ask user only if there are some breakpoints to delete. */ | |
12754 | if (!from_tty | |
e2e0b3e5 | 12755 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 12756 | { |
35df4500 | 12757 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 12758 | if (user_breakpoint_p (b)) |
c5aa993b | 12759 | delete_breakpoint (b); |
c906108c SS |
12760 | } |
12761 | } | |
12762 | else | |
51be5b68 | 12763 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
c906108c SS |
12764 | } |
12765 | ||
0d381245 VP |
12766 | static int |
12767 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 12768 | { |
0d381245 | 12769 | for (; loc; loc = loc->next) |
8645ff69 UW |
12770 | if (!loc->shlib_disabled |
12771 | && !loc->pspace->executing_startup) | |
0d381245 VP |
12772 | return 0; |
12773 | return 1; | |
fe3f5fa8 VP |
12774 | } |
12775 | ||
776592bf DE |
12776 | /* Subroutine of update_breakpoint_locations to simplify it. |
12777 | Return non-zero if multiple fns in list LOC have the same name. | |
12778 | Null names are ignored. */ | |
12779 | ||
12780 | static int | |
12781 | ambiguous_names_p (struct bp_location *loc) | |
12782 | { | |
12783 | struct bp_location *l; | |
12784 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
12785 | (int (*) (const void *, |
12786 | const void *)) streq, | |
776592bf DE |
12787 | NULL, xcalloc, xfree); |
12788 | ||
12789 | for (l = loc; l != NULL; l = l->next) | |
12790 | { | |
12791 | const char **slot; | |
12792 | const char *name = l->function_name; | |
12793 | ||
12794 | /* Allow for some names to be NULL, ignore them. */ | |
12795 | if (name == NULL) | |
12796 | continue; | |
12797 | ||
12798 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
12799 | INSERT); | |
4a64f543 MS |
12800 | /* NOTE: We can assume slot != NULL here because xcalloc never |
12801 | returns NULL. */ | |
776592bf DE |
12802 | if (*slot != NULL) |
12803 | { | |
12804 | htab_delete (htab); | |
12805 | return 1; | |
12806 | } | |
12807 | *slot = name; | |
12808 | } | |
12809 | ||
12810 | htab_delete (htab); | |
12811 | return 0; | |
12812 | } | |
12813 | ||
0fb4aa4b PA |
12814 | /* When symbols change, it probably means the sources changed as well, |
12815 | and it might mean the static tracepoint markers are no longer at | |
12816 | the same address or line numbers they used to be at last we | |
12817 | checked. Losing your static tracepoints whenever you rebuild is | |
12818 | undesirable. This function tries to resync/rematch gdb static | |
12819 | tracepoints with the markers on the target, for static tracepoints | |
12820 | that have not been set by marker id. Static tracepoint that have | |
12821 | been set by marker id are reset by marker id in breakpoint_re_set. | |
12822 | The heuristic is: | |
12823 | ||
12824 | 1) For a tracepoint set at a specific address, look for a marker at | |
12825 | the old PC. If one is found there, assume to be the same marker. | |
12826 | If the name / string id of the marker found is different from the | |
12827 | previous known name, assume that means the user renamed the marker | |
12828 | in the sources, and output a warning. | |
12829 | ||
12830 | 2) For a tracepoint set at a given line number, look for a marker | |
12831 | at the new address of the old line number. If one is found there, | |
12832 | assume to be the same marker. If the name / string id of the | |
12833 | marker found is different from the previous known name, assume that | |
12834 | means the user renamed the marker in the sources, and output a | |
12835 | warning. | |
12836 | ||
12837 | 3) If a marker is no longer found at the same address or line, it | |
12838 | may mean the marker no longer exists. But it may also just mean | |
12839 | the code changed a bit. Maybe the user added a few lines of code | |
12840 | that made the marker move up or down (in line number terms). Ask | |
12841 | the target for info about the marker with the string id as we knew | |
12842 | it. If found, update line number and address in the matching | |
12843 | static tracepoint. This will get confused if there's more than one | |
12844 | marker with the same ID (possible in UST, although unadvised | |
12845 | precisely because it confuses tools). */ | |
12846 | ||
12847 | static struct symtab_and_line | |
12848 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
12849 | { | |
d9b3f62e | 12850 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
12851 | struct static_tracepoint_marker marker; |
12852 | CORE_ADDR pc; | |
12853 | int i; | |
12854 | ||
12855 | pc = sal.pc; | |
12856 | if (sal.line) | |
12857 | find_line_pc (sal.symtab, sal.line, &pc); | |
12858 | ||
12859 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
12860 | { | |
d9b3f62e | 12861 | if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0) |
0fb4aa4b PA |
12862 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
12863 | b->number, | |
d9b3f62e | 12864 | tp->static_trace_marker_id, marker.str_id); |
0fb4aa4b | 12865 | |
d9b3f62e PA |
12866 | xfree (tp->static_trace_marker_id); |
12867 | tp->static_trace_marker_id = xstrdup (marker.str_id); | |
0fb4aa4b PA |
12868 | release_static_tracepoint_marker (&marker); |
12869 | ||
12870 | return sal; | |
12871 | } | |
12872 | ||
12873 | /* Old marker wasn't found on target at lineno. Try looking it up | |
12874 | by string ID. */ | |
12875 | if (!sal.explicit_pc | |
12876 | && sal.line != 0 | |
12877 | && sal.symtab != NULL | |
d9b3f62e | 12878 | && tp->static_trace_marker_id != NULL) |
0fb4aa4b PA |
12879 | { |
12880 | VEC(static_tracepoint_marker_p) *markers; | |
12881 | ||
12882 | markers | |
d9b3f62e | 12883 | = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id); |
0fb4aa4b PA |
12884 | |
12885 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
12886 | { | |
80e1d417 | 12887 | struct symtab_and_line sal2; |
0fb4aa4b | 12888 | struct symbol *sym; |
80e1d417 | 12889 | struct static_tracepoint_marker *tpmarker; |
79a45e25 | 12890 | struct ui_out *uiout = current_uiout; |
0fb4aa4b | 12891 | |
80e1d417 | 12892 | tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0); |
0fb4aa4b | 12893 | |
d9b3f62e | 12894 | xfree (tp->static_trace_marker_id); |
80e1d417 | 12895 | tp->static_trace_marker_id = xstrdup (tpmarker->str_id); |
0fb4aa4b PA |
12896 | |
12897 | warning (_("marker for static tracepoint %d (%s) not " | |
12898 | "found at previous line number"), | |
d9b3f62e | 12899 | b->number, tp->static_trace_marker_id); |
0fb4aa4b | 12900 | |
80e1d417 | 12901 | init_sal (&sal2); |
0fb4aa4b | 12902 | |
80e1d417 | 12903 | sal2.pc = tpmarker->address; |
0fb4aa4b | 12904 | |
80e1d417 AS |
12905 | sal2 = find_pc_line (tpmarker->address, 0); |
12906 | sym = find_pc_sect_function (tpmarker->address, NULL); | |
0fb4aa4b PA |
12907 | ui_out_text (uiout, "Now in "); |
12908 | if (sym) | |
12909 | { | |
12910 | ui_out_field_string (uiout, "func", | |
12911 | SYMBOL_PRINT_NAME (sym)); | |
12912 | ui_out_text (uiout, " at "); | |
12913 | } | |
80e1d417 | 12914 | ui_out_field_string (uiout, "file", sal2.symtab->filename); |
0fb4aa4b PA |
12915 | ui_out_text (uiout, ":"); |
12916 | ||
12917 | if (ui_out_is_mi_like_p (uiout)) | |
12918 | { | |
80e1d417 | 12919 | char *fullname = symtab_to_fullname (sal2.symtab); |
0fb4aa4b PA |
12920 | |
12921 | if (fullname) | |
12922 | ui_out_field_string (uiout, "fullname", fullname); | |
12923 | } | |
12924 | ||
80e1d417 | 12925 | ui_out_field_int (uiout, "line", sal2.line); |
0fb4aa4b PA |
12926 | ui_out_text (uiout, "\n"); |
12927 | ||
80e1d417 | 12928 | b->loc->line_number = sal2.line; |
0fb4aa4b | 12929 | |
f8eba3c6 | 12930 | xfree (b->loc->source_file); |
0fb4aa4b | 12931 | if (sym) |
80e1d417 | 12932 | b->loc->source_file = xstrdup (sal2.symtab->filename); |
0fb4aa4b | 12933 | else |
f8eba3c6 | 12934 | b->loc->source_file = NULL; |
0fb4aa4b PA |
12935 | |
12936 | xfree (b->addr_string); | |
12937 | b->addr_string = xstrprintf ("%s:%d", | |
80e1d417 | 12938 | sal2.symtab->filename, |
f8eba3c6 | 12939 | b->loc->line_number); |
0fb4aa4b PA |
12940 | |
12941 | /* Might be nice to check if function changed, and warn if | |
12942 | so. */ | |
12943 | ||
80e1d417 | 12944 | release_static_tracepoint_marker (tpmarker); |
0fb4aa4b PA |
12945 | } |
12946 | } | |
12947 | return sal; | |
12948 | } | |
12949 | ||
8d3788bd VP |
12950 | /* Returns 1 iff locations A and B are sufficiently same that |
12951 | we don't need to report breakpoint as changed. */ | |
12952 | ||
12953 | static int | |
12954 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
12955 | { | |
12956 | while (a && b) | |
12957 | { | |
12958 | if (a->address != b->address) | |
12959 | return 0; | |
12960 | ||
12961 | if (a->shlib_disabled != b->shlib_disabled) | |
12962 | return 0; | |
12963 | ||
12964 | if (a->enabled != b->enabled) | |
12965 | return 0; | |
12966 | ||
12967 | a = a->next; | |
12968 | b = b->next; | |
12969 | } | |
12970 | ||
12971 | if ((a == NULL) != (b == NULL)) | |
12972 | return 0; | |
12973 | ||
12974 | return 1; | |
12975 | } | |
12976 | ||
f1310107 TJB |
12977 | /* Create new breakpoint locations for B (a hardware or software breakpoint) |
12978 | based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is | |
12979 | a ranged breakpoint. */ | |
12980 | ||
0e30163f | 12981 | void |
0d381245 | 12982 | update_breakpoint_locations (struct breakpoint *b, |
f1310107 TJB |
12983 | struct symtabs_and_lines sals, |
12984 | struct symtabs_and_lines sals_end) | |
fe3f5fa8 VP |
12985 | { |
12986 | int i; | |
0d381245 VP |
12987 | struct bp_location *existing_locations = b->loc; |
12988 | ||
f8eba3c6 TT |
12989 | if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1)) |
12990 | { | |
12991 | /* Ranged breakpoints have only one start location and one end | |
12992 | location. */ | |
12993 | b->enable_state = bp_disabled; | |
12994 | update_global_location_list (1); | |
12995 | printf_unfiltered (_("Could not reset ranged breakpoint %d: " | |
12996 | "multiple locations found\n"), | |
12997 | b->number); | |
12998 | return; | |
12999 | } | |
f1310107 | 13000 | |
4a64f543 MS |
13001 | /* If there's no new locations, and all existing locations are |
13002 | pending, don't do anything. This optimizes the common case where | |
13003 | all locations are in the same shared library, that was unloaded. | |
13004 | We'd like to retain the location, so that when the library is | |
13005 | loaded again, we don't loose the enabled/disabled status of the | |
13006 | individual locations. */ | |
0d381245 | 13007 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) |
fe3f5fa8 VP |
13008 | return; |
13009 | ||
fe3f5fa8 VP |
13010 | b->loc = NULL; |
13011 | ||
0d381245 | 13012 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 13013 | { |
f8eba3c6 TT |
13014 | struct bp_location *new_loc; |
13015 | ||
13016 | switch_to_program_space_and_thread (sals.sals[i].pspace); | |
13017 | ||
13018 | new_loc = add_location_to_breakpoint (b, &(sals.sals[i])); | |
fe3f5fa8 | 13019 | |
0d381245 VP |
13020 | /* Reparse conditions, they might contain references to the |
13021 | old symtab. */ | |
13022 | if (b->cond_string != NULL) | |
13023 | { | |
f1310107 | 13024 | char *s; |
bfd189b1 | 13025 | volatile struct gdb_exception e; |
fe3f5fa8 | 13026 | |
0d381245 VP |
13027 | s = b->cond_string; |
13028 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
13029 | { | |
13030 | new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), | |
13031 | 0); | |
13032 | } | |
13033 | if (e.reason < 0) | |
13034 | { | |
3e43a32a MS |
13035 | warning (_("failed to reevaluate condition " |
13036 | "for breakpoint %d: %s"), | |
0d381245 VP |
13037 | b->number, e.message); |
13038 | new_loc->enabled = 0; | |
13039 | } | |
13040 | } | |
fe3f5fa8 | 13041 | |
f1310107 TJB |
13042 | if (sals_end.nelts) |
13043 | { | |
13044 | CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]); | |
13045 | ||
13046 | new_loc->length = end - sals.sals[0].pc + 1; | |
13047 | } | |
0d381245 | 13048 | } |
fe3f5fa8 | 13049 | |
514f746b AR |
13050 | /* Update locations of permanent breakpoints. */ |
13051 | if (b->enable_state == bp_permanent) | |
13052 | make_breakpoint_permanent (b); | |
13053 | ||
4a64f543 MS |
13054 | /* If possible, carry over 'disable' status from existing |
13055 | breakpoints. */ | |
0d381245 VP |
13056 | { |
13057 | struct bp_location *e = existing_locations; | |
776592bf DE |
13058 | /* If there are multiple breakpoints with the same function name, |
13059 | e.g. for inline functions, comparing function names won't work. | |
13060 | Instead compare pc addresses; this is just a heuristic as things | |
13061 | may have moved, but in practice it gives the correct answer | |
13062 | often enough until a better solution is found. */ | |
13063 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
13064 | ||
0d381245 VP |
13065 | for (; e; e = e->next) |
13066 | { | |
13067 | if (!e->enabled && e->function_name) | |
13068 | { | |
13069 | struct bp_location *l = b->loc; | |
776592bf DE |
13070 | if (have_ambiguous_names) |
13071 | { | |
13072 | for (; l; l = l->next) | |
f1310107 | 13073 | if (breakpoint_locations_match (e, l)) |
776592bf DE |
13074 | { |
13075 | l->enabled = 0; | |
13076 | break; | |
13077 | } | |
13078 | } | |
13079 | else | |
13080 | { | |
13081 | for (; l; l = l->next) | |
13082 | if (l->function_name | |
13083 | && strcmp (e->function_name, l->function_name) == 0) | |
13084 | { | |
13085 | l->enabled = 0; | |
13086 | break; | |
13087 | } | |
13088 | } | |
0d381245 VP |
13089 | } |
13090 | } | |
13091 | } | |
fe3f5fa8 | 13092 | |
8d3788bd VP |
13093 | if (!locations_are_equal (existing_locations, b->loc)) |
13094 | observer_notify_breakpoint_modified (b); | |
13095 | ||
b60e7edf | 13096 | update_global_location_list (1); |
fe3f5fa8 VP |
13097 | } |
13098 | ||
ef23e705 TJB |
13099 | /* Find the SaL locations corresponding to the given ADDR_STRING. |
13100 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ | |
13101 | ||
13102 | static struct symtabs_and_lines | |
13103 | addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found) | |
13104 | { | |
13105 | char *s; | |
02d20e4a | 13106 | struct symtabs_and_lines sals = {0}; |
f8eba3c6 | 13107 | volatile struct gdb_exception e; |
ef23e705 | 13108 | |
983af33b | 13109 | gdb_assert (b->ops != NULL); |
ef23e705 | 13110 | s = addr_string; |
ef23e705 TJB |
13111 | |
13112 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
13113 | { | |
983af33b | 13114 | b->ops->decode_linespec (b, &s, &sals); |
ef23e705 TJB |
13115 | } |
13116 | if (e.reason < 0) | |
13117 | { | |
13118 | int not_found_and_ok = 0; | |
13119 | /* For pending breakpoints, it's expected that parsing will | |
13120 | fail until the right shared library is loaded. User has | |
13121 | already told to create pending breakpoints and don't need | |
13122 | extra messages. If breakpoint is in bp_shlib_disabled | |
13123 | state, then user already saw the message about that | |
13124 | breakpoint being disabled, and don't want to see more | |
13125 | errors. */ | |
58438ac1 | 13126 | if (e.error == NOT_FOUND_ERROR |
ef23e705 TJB |
13127 | && (b->condition_not_parsed |
13128 | || (b->loc && b->loc->shlib_disabled) | |
f8eba3c6 | 13129 | || (b->loc && b->loc->pspace->executing_startup) |
ef23e705 TJB |
13130 | || b->enable_state == bp_disabled)) |
13131 | not_found_and_ok = 1; | |
13132 | ||
13133 | if (!not_found_and_ok) | |
13134 | { | |
13135 | /* We surely don't want to warn about the same breakpoint | |
13136 | 10 times. One solution, implemented here, is disable | |
13137 | the breakpoint on error. Another solution would be to | |
13138 | have separate 'warning emitted' flag. Since this | |
13139 | happens only when a binary has changed, I don't know | |
13140 | which approach is better. */ | |
13141 | b->enable_state = bp_disabled; | |
13142 | throw_exception (e); | |
13143 | } | |
13144 | } | |
13145 | ||
58438ac1 | 13146 | if (e.reason == 0 || e.error != NOT_FOUND_ERROR) |
ef23e705 | 13147 | { |
f8eba3c6 | 13148 | int i; |
ef23e705 | 13149 | |
f8eba3c6 TT |
13150 | for (i = 0; i < sals.nelts; ++i) |
13151 | resolve_sal_pc (&sals.sals[i]); | |
ef23e705 TJB |
13152 | if (b->condition_not_parsed && s && s[0]) |
13153 | { | |
13154 | char *cond_string = 0; | |
13155 | int thread = -1; | |
13156 | int task = 0; | |
13157 | ||
13158 | find_condition_and_thread (s, sals.sals[0].pc, | |
13159 | &cond_string, &thread, &task); | |
13160 | if (cond_string) | |
13161 | b->cond_string = cond_string; | |
13162 | b->thread = thread; | |
13163 | b->task = task; | |
13164 | b->condition_not_parsed = 0; | |
13165 | } | |
13166 | ||
983af33b | 13167 | if (b->type == bp_static_tracepoint && !strace_marker_p (b)) |
ef23e705 | 13168 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); |
ef23e705 | 13169 | |
58438ac1 TT |
13170 | *found = 1; |
13171 | } | |
13172 | else | |
13173 | *found = 0; | |
ef23e705 TJB |
13174 | |
13175 | return sals; | |
13176 | } | |
13177 | ||
348d480f PA |
13178 | /* The default re_set method, for typical hardware or software |
13179 | breakpoints. Reevaluate the breakpoint and recreate its | |
13180 | locations. */ | |
13181 | ||
13182 | static void | |
28010a5d | 13183 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 TJB |
13184 | { |
13185 | int found; | |
f1310107 | 13186 | struct symtabs_and_lines sals, sals_end; |
ef23e705 | 13187 | struct symtabs_and_lines expanded = {0}; |
f1310107 | 13188 | struct symtabs_and_lines expanded_end = {0}; |
ef23e705 TJB |
13189 | |
13190 | sals = addr_string_to_sals (b, b->addr_string, &found); | |
13191 | if (found) | |
13192 | { | |
13193 | make_cleanup (xfree, sals.sals); | |
f8eba3c6 | 13194 | expanded = sals; |
ef23e705 TJB |
13195 | } |
13196 | ||
f1310107 TJB |
13197 | if (b->addr_string_range_end) |
13198 | { | |
13199 | sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found); | |
13200 | if (found) | |
13201 | { | |
13202 | make_cleanup (xfree, sals_end.sals); | |
f8eba3c6 | 13203 | expanded_end = sals_end; |
f1310107 TJB |
13204 | } |
13205 | } | |
13206 | ||
13207 | update_breakpoint_locations (b, expanded, expanded_end); | |
28010a5d PA |
13208 | } |
13209 | ||
983af33b SDJ |
13210 | /* Default method for creating SALs from an address string. It basically |
13211 | calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ | |
13212 | ||
13213 | static void | |
13214 | create_sals_from_address_default (char **arg, | |
13215 | struct linespec_result *canonical, | |
13216 | enum bptype type_wanted, | |
13217 | char *addr_start, char **copy_arg) | |
13218 | { | |
13219 | parse_breakpoint_sals (arg, canonical); | |
13220 | } | |
13221 | ||
13222 | /* Call create_breakpoints_sal for the given arguments. This is the default | |
13223 | function for the `create_breakpoints_sal' method of | |
13224 | breakpoint_ops. */ | |
13225 | ||
13226 | static void | |
13227 | create_breakpoints_sal_default (struct gdbarch *gdbarch, | |
13228 | struct linespec_result *canonical, | |
13229 | struct linespec_sals *lsal, | |
13230 | char *cond_string, | |
13231 | enum bptype type_wanted, | |
13232 | enum bpdisp disposition, | |
13233 | int thread, | |
13234 | int task, int ignore_count, | |
13235 | const struct breakpoint_ops *ops, | |
13236 | int from_tty, int enabled, | |
13237 | int internal) | |
13238 | { | |
13239 | create_breakpoints_sal (gdbarch, canonical, cond_string, | |
13240 | type_wanted, disposition, | |
13241 | thread, task, ignore_count, ops, from_tty, | |
13242 | enabled, internal); | |
13243 | } | |
13244 | ||
13245 | /* Decode the line represented by S by calling decode_line_full. This is the | |
13246 | default function for the `decode_linespec' method of breakpoint_ops. */ | |
13247 | ||
13248 | static void | |
13249 | decode_linespec_default (struct breakpoint *b, char **s, | |
13250 | struct symtabs_and_lines *sals) | |
13251 | { | |
13252 | struct linespec_result canonical; | |
13253 | ||
13254 | init_linespec_result (&canonical); | |
13255 | decode_line_full (s, DECODE_LINE_FUNFIRSTLINE, | |
13256 | (struct symtab *) NULL, 0, | |
13257 | &canonical, multiple_symbols_all, | |
13258 | b->filter); | |
13259 | ||
13260 | /* We should get 0 or 1 resulting SALs. */ | |
13261 | gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2); | |
13262 | ||
13263 | if (VEC_length (linespec_sals, canonical.sals) > 0) | |
13264 | { | |
13265 | struct linespec_sals *lsal; | |
13266 | ||
13267 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
13268 | *sals = lsal->sals; | |
13269 | /* Arrange it so the destructor does not free the | |
13270 | contents. */ | |
13271 | lsal->sals.sals = NULL; | |
13272 | } | |
13273 | ||
13274 | destroy_linespec_result (&canonical); | |
13275 | } | |
13276 | ||
28010a5d PA |
13277 | /* Prepare the global context for a re-set of breakpoint B. */ |
13278 | ||
13279 | static struct cleanup * | |
13280 | prepare_re_set_context (struct breakpoint *b) | |
13281 | { | |
13282 | struct cleanup *cleanups; | |
13283 | ||
13284 | input_radix = b->input_radix; | |
13285 | cleanups = save_current_space_and_thread (); | |
f8eba3c6 TT |
13286 | if (b->pspace != NULL) |
13287 | switch_to_program_space_and_thread (b->pspace); | |
28010a5d PA |
13288 | set_language (b->language); |
13289 | ||
13290 | return cleanups; | |
ef23e705 TJB |
13291 | } |
13292 | ||
c906108c SS |
13293 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
13294 | The value we return ends up being the return value from catch_errors. | |
13295 | Unused in this case. */ | |
13296 | ||
13297 | static int | |
4efb68b1 | 13298 | breakpoint_re_set_one (void *bint) |
c906108c | 13299 | { |
4a64f543 | 13300 | /* Get past catch_errs. */ |
53a5351d | 13301 | struct breakpoint *b = (struct breakpoint *) bint; |
348d480f | 13302 | struct cleanup *cleanups; |
c906108c | 13303 | |
348d480f PA |
13304 | cleanups = prepare_re_set_context (b); |
13305 | b->ops->re_set (b); | |
13306 | do_cleanups (cleanups); | |
c906108c SS |
13307 | return 0; |
13308 | } | |
13309 | ||
69de3c6a | 13310 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 13311 | void |
69de3c6a | 13312 | breakpoint_re_set (void) |
c906108c | 13313 | { |
35df4500 | 13314 | struct breakpoint *b, *b_tmp; |
c906108c SS |
13315 | enum language save_language; |
13316 | int save_input_radix; | |
6c95b8df | 13317 | struct cleanup *old_chain; |
c5aa993b | 13318 | |
c906108c SS |
13319 | save_language = current_language->la_language; |
13320 | save_input_radix = input_radix; | |
6c95b8df PA |
13321 | old_chain = save_current_program_space (); |
13322 | ||
35df4500 | 13323 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 13324 | { |
4a64f543 | 13325 | /* Format possible error msg. */ |
fe3f5fa8 | 13326 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
13327 | b->number); |
13328 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 13329 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 13330 | do_cleanups (cleanups); |
c5aa993b | 13331 | } |
c906108c SS |
13332 | set_language (save_language); |
13333 | input_radix = save_input_radix; | |
e62c965a | 13334 | |
0756c555 | 13335 | jit_breakpoint_re_set (); |
4efc6507 | 13336 | |
6c95b8df PA |
13337 | do_cleanups (old_chain); |
13338 | ||
af02033e PP |
13339 | create_overlay_event_breakpoint (); |
13340 | create_longjmp_master_breakpoint (); | |
13341 | create_std_terminate_master_breakpoint (); | |
186c406b | 13342 | create_exception_master_breakpoint (); |
1bfeeb0f JL |
13343 | |
13344 | /* While we're at it, reset the skip list too. */ | |
13345 | skip_re_set (); | |
c906108c SS |
13346 | } |
13347 | \f | |
c906108c SS |
13348 | /* Reset the thread number of this breakpoint: |
13349 | ||
13350 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 13351 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 13352 | void |
fba45db2 | 13353 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
13354 | { |
13355 | if (b->thread != -1) | |
13356 | { | |
39f77062 KB |
13357 | if (in_thread_list (inferior_ptid)) |
13358 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
13359 | |
13360 | /* We're being called after following a fork. The new fork is | |
13361 | selected as current, and unless this was a vfork will have a | |
13362 | different program space from the original thread. Reset that | |
13363 | as well. */ | |
13364 | b->loc->pspace = current_program_space; | |
c906108c SS |
13365 | } |
13366 | } | |
13367 | ||
03ac34d5 MS |
13368 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
13369 | If from_tty is nonzero, it prints a message to that effect, | |
13370 | which ends with a period (no newline). */ | |
13371 | ||
c906108c | 13372 | void |
fba45db2 | 13373 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 13374 | { |
52f0bd74 | 13375 | struct breakpoint *b; |
c906108c SS |
13376 | |
13377 | if (count < 0) | |
13378 | count = 0; | |
13379 | ||
13380 | ALL_BREAKPOINTS (b) | |
13381 | if (b->number == bptnum) | |
c5aa993b | 13382 | { |
d77f58be SS |
13383 | if (is_tracepoint (b)) |
13384 | { | |
13385 | if (from_tty && count != 0) | |
13386 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
13387 | bptnum); | |
13388 | return; | |
13389 | } | |
13390 | ||
c5aa993b | 13391 | b->ignore_count = count; |
221ea385 KS |
13392 | if (from_tty) |
13393 | { | |
13394 | if (count == 0) | |
3e43a32a MS |
13395 | printf_filtered (_("Will stop next time " |
13396 | "breakpoint %d is reached."), | |
221ea385 KS |
13397 | bptnum); |
13398 | else if (count == 1) | |
a3f17187 | 13399 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
13400 | bptnum); |
13401 | else | |
3e43a32a MS |
13402 | printf_filtered (_("Will ignore next %d " |
13403 | "crossings of breakpoint %d."), | |
221ea385 KS |
13404 | count, bptnum); |
13405 | } | |
c5aa993b | 13406 | breakpoints_changed (); |
8d3788bd | 13407 | observer_notify_breakpoint_modified (b); |
c5aa993b JM |
13408 | return; |
13409 | } | |
c906108c | 13410 | |
8a3fe4f8 | 13411 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
13412 | } |
13413 | ||
c906108c SS |
13414 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
13415 | ||
13416 | static void | |
fba45db2 | 13417 | ignore_command (char *args, int from_tty) |
c906108c SS |
13418 | { |
13419 | char *p = args; | |
52f0bd74 | 13420 | int num; |
c906108c SS |
13421 | |
13422 | if (p == 0) | |
e2e0b3e5 | 13423 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 13424 | |
c906108c | 13425 | num = get_number (&p); |
5c44784c | 13426 | if (num == 0) |
8a3fe4f8 | 13427 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 13428 | if (*p == 0) |
8a3fe4f8 | 13429 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
13430 | |
13431 | set_ignore_count (num, | |
13432 | longest_to_int (value_as_long (parse_and_eval (p))), | |
13433 | from_tty); | |
221ea385 KS |
13434 | if (from_tty) |
13435 | printf_filtered ("\n"); | |
c906108c SS |
13436 | } |
13437 | \f | |
13438 | /* Call FUNCTION on each of the breakpoints | |
13439 | whose numbers are given in ARGS. */ | |
13440 | ||
13441 | static void | |
95a42b64 TT |
13442 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
13443 | void *), | |
13444 | void *data) | |
c906108c | 13445 | { |
52f0bd74 AC |
13446 | int num; |
13447 | struct breakpoint *b, *tmp; | |
11cf8741 | 13448 | int match; |
197f0a60 | 13449 | struct get_number_or_range_state state; |
c906108c | 13450 | |
197f0a60 | 13451 | if (args == 0) |
e2e0b3e5 | 13452 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c | 13453 | |
197f0a60 TT |
13454 | init_number_or_range (&state, args); |
13455 | ||
13456 | while (!state.finished) | |
c906108c | 13457 | { |
197f0a60 TT |
13458 | char *p = state.string; |
13459 | ||
11cf8741 | 13460 | match = 0; |
c5aa993b | 13461 | |
197f0a60 | 13462 | num = get_number_or_range (&state); |
5c44784c | 13463 | if (num == 0) |
c5aa993b | 13464 | { |
8a3fe4f8 | 13465 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
13466 | } |
13467 | else | |
13468 | { | |
13469 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
13470 | if (b->number == num) | |
13471 | { | |
11cf8741 | 13472 | match = 1; |
cdac0397 | 13473 | function (b, data); |
11cf8741 | 13474 | break; |
5c44784c | 13475 | } |
11cf8741 | 13476 | if (match == 0) |
a3f17187 | 13477 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 13478 | } |
c906108c SS |
13479 | } |
13480 | } | |
13481 | ||
0d381245 VP |
13482 | static struct bp_location * |
13483 | find_location_by_number (char *number) | |
13484 | { | |
13485 | char *dot = strchr (number, '.'); | |
13486 | char *p1; | |
13487 | int bp_num; | |
13488 | int loc_num; | |
13489 | struct breakpoint *b; | |
13490 | struct bp_location *loc; | |
13491 | ||
13492 | *dot = '\0'; | |
13493 | ||
13494 | p1 = number; | |
197f0a60 | 13495 | bp_num = get_number (&p1); |
0d381245 VP |
13496 | if (bp_num == 0) |
13497 | error (_("Bad breakpoint number '%s'"), number); | |
13498 | ||
13499 | ALL_BREAKPOINTS (b) | |
13500 | if (b->number == bp_num) | |
13501 | { | |
13502 | break; | |
13503 | } | |
13504 | ||
13505 | if (!b || b->number != bp_num) | |
13506 | error (_("Bad breakpoint number '%s'"), number); | |
13507 | ||
13508 | p1 = dot+1; | |
197f0a60 | 13509 | loc_num = get_number (&p1); |
0d381245 VP |
13510 | if (loc_num == 0) |
13511 | error (_("Bad breakpoint location number '%s'"), number); | |
13512 | ||
13513 | --loc_num; | |
13514 | loc = b->loc; | |
13515 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
13516 | ; | |
13517 | if (!loc) | |
13518 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
13519 | ||
13520 | return loc; | |
13521 | } | |
13522 | ||
13523 | ||
1900040c MS |
13524 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
13525 | If from_tty is nonzero, it prints a message to that effect, | |
13526 | which ends with a period (no newline). */ | |
13527 | ||
c906108c | 13528 | void |
fba45db2 | 13529 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
13530 | { |
13531 | /* Never disable a watchpoint scope breakpoint; we want to | |
13532 | hit them when we leave scope so we can delete both the | |
13533 | watchpoint and its scope breakpoint at that time. */ | |
13534 | if (bpt->type == bp_watchpoint_scope) | |
13535 | return; | |
13536 | ||
c2c6d25f | 13537 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 13538 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
13539 | return; |
13540 | ||
b5de0fa7 | 13541 | bpt->enable_state = bp_disabled; |
c906108c | 13542 | |
b775012e LM |
13543 | /* Mark breakpoint locations modified. */ |
13544 | mark_breakpoint_modified (bpt); | |
13545 | ||
d248b706 KY |
13546 | if (target_supports_enable_disable_tracepoint () |
13547 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
13548 | { | |
13549 | struct bp_location *location; | |
13550 | ||
13551 | for (location = bpt->loc; location; location = location->next) | |
13552 | target_disable_tracepoint (location); | |
13553 | } | |
13554 | ||
b60e7edf | 13555 | update_global_location_list (0); |
c906108c | 13556 | |
8d3788bd | 13557 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
13558 | } |
13559 | ||
51be5b68 PA |
13560 | /* A callback for iterate_over_related_breakpoints. */ |
13561 | ||
13562 | static void | |
13563 | do_disable_breakpoint (struct breakpoint *b, void *ignore) | |
13564 | { | |
13565 | disable_breakpoint (b); | |
13566 | } | |
13567 | ||
95a42b64 TT |
13568 | /* A callback for map_breakpoint_numbers that calls |
13569 | disable_breakpoint. */ | |
13570 | ||
13571 | static void | |
13572 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
13573 | { | |
51be5b68 | 13574 | iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL); |
95a42b64 TT |
13575 | } |
13576 | ||
c906108c | 13577 | static void |
fba45db2 | 13578 | disable_command (char *args, int from_tty) |
c906108c | 13579 | { |
c906108c | 13580 | if (args == 0) |
46c6471b PA |
13581 | { |
13582 | struct breakpoint *bpt; | |
13583 | ||
13584 | ALL_BREAKPOINTS (bpt) | |
13585 | if (user_breakpoint_p (bpt)) | |
13586 | disable_breakpoint (bpt); | |
13587 | } | |
0d381245 VP |
13588 | else if (strchr (args, '.')) |
13589 | { | |
13590 | struct bp_location *loc = find_location_by_number (args); | |
13591 | if (loc) | |
d248b706 | 13592 | { |
b775012e LM |
13593 | if (loc->enabled) |
13594 | { | |
13595 | loc->enabled = 0; | |
13596 | mark_breakpoint_location_modified (loc); | |
13597 | } | |
d248b706 KY |
13598 | if (target_supports_enable_disable_tracepoint () |
13599 | && current_trace_status ()->running && loc->owner | |
13600 | && is_tracepoint (loc->owner)) | |
13601 | target_disable_tracepoint (loc); | |
13602 | } | |
b60e7edf | 13603 | update_global_location_list (0); |
0d381245 | 13604 | } |
c906108c | 13605 | else |
95a42b64 | 13606 | map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL); |
c906108c SS |
13607 | } |
13608 | ||
13609 | static void | |
816338b5 SS |
13610 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, |
13611 | int count) | |
c906108c | 13612 | { |
afe38095 | 13613 | int target_resources_ok; |
c906108c SS |
13614 | |
13615 | if (bpt->type == bp_hardware_breakpoint) | |
13616 | { | |
13617 | int i; | |
c5aa993b | 13618 | i = hw_breakpoint_used_count (); |
53a5351d | 13619 | target_resources_ok = |
d92524f1 | 13620 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 13621 | i + 1, 0); |
c906108c | 13622 | if (target_resources_ok == 0) |
8a3fe4f8 | 13623 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 13624 | else if (target_resources_ok < 0) |
8a3fe4f8 | 13625 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
13626 | } |
13627 | ||
cc60f2e3 | 13628 | if (is_watchpoint (bpt)) |
c906108c | 13629 | { |
d07205c2 JK |
13630 | /* Initialize it just to avoid a GCC false warning. */ |
13631 | enum enable_state orig_enable_state = 0; | |
bfd189b1 | 13632 | volatile struct gdb_exception e; |
dde02812 ES |
13633 | |
13634 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 13635 | { |
3a5c3e22 PA |
13636 | struct watchpoint *w = (struct watchpoint *) bpt; |
13637 | ||
1e718ff1 TJB |
13638 | orig_enable_state = bpt->enable_state; |
13639 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 13640 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 13641 | } |
dde02812 | 13642 | if (e.reason < 0) |
c5aa993b | 13643 | { |
1e718ff1 | 13644 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
13645 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
13646 | bpt->number); | |
13647 | return; | |
c5aa993b | 13648 | } |
c906108c | 13649 | } |
0101ce28 | 13650 | |
b4c291bb KH |
13651 | if (bpt->enable_state != bp_permanent) |
13652 | bpt->enable_state = bp_enabled; | |
d248b706 | 13653 | |
b775012e LM |
13654 | bpt->enable_state = bp_enabled; |
13655 | ||
13656 | /* Mark breakpoint locations modified. */ | |
13657 | mark_breakpoint_modified (bpt); | |
13658 | ||
d248b706 KY |
13659 | if (target_supports_enable_disable_tracepoint () |
13660 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
13661 | { | |
13662 | struct bp_location *location; | |
13663 | ||
13664 | for (location = bpt->loc; location; location = location->next) | |
13665 | target_enable_tracepoint (location); | |
13666 | } | |
13667 | ||
b4c291bb | 13668 | bpt->disposition = disposition; |
816338b5 | 13669 | bpt->enable_count = count; |
b60e7edf | 13670 | update_global_location_list (1); |
b4c291bb KH |
13671 | breakpoints_changed (); |
13672 | ||
8d3788bd | 13673 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
13674 | } |
13675 | ||
fe3f5fa8 | 13676 | |
c906108c | 13677 | void |
fba45db2 | 13678 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 13679 | { |
816338b5 | 13680 | enable_breakpoint_disp (bpt, bpt->disposition, 0); |
51be5b68 PA |
13681 | } |
13682 | ||
13683 | static void | |
13684 | do_enable_breakpoint (struct breakpoint *bpt, void *arg) | |
13685 | { | |
13686 | enable_breakpoint (bpt); | |
c906108c SS |
13687 | } |
13688 | ||
95a42b64 TT |
13689 | /* A callback for map_breakpoint_numbers that calls |
13690 | enable_breakpoint. */ | |
13691 | ||
13692 | static void | |
13693 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
13694 | { | |
51be5b68 | 13695 | iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL); |
95a42b64 TT |
13696 | } |
13697 | ||
c906108c SS |
13698 | /* The enable command enables the specified breakpoints (or all defined |
13699 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 13700 | in stopping the inferior. */ |
c906108c | 13701 | |
c906108c | 13702 | static void |
fba45db2 | 13703 | enable_command (char *args, int from_tty) |
c906108c | 13704 | { |
c906108c | 13705 | if (args == 0) |
46c6471b PA |
13706 | { |
13707 | struct breakpoint *bpt; | |
13708 | ||
13709 | ALL_BREAKPOINTS (bpt) | |
13710 | if (user_breakpoint_p (bpt)) | |
13711 | enable_breakpoint (bpt); | |
13712 | } | |
0d381245 VP |
13713 | else if (strchr (args, '.')) |
13714 | { | |
13715 | struct bp_location *loc = find_location_by_number (args); | |
13716 | if (loc) | |
d248b706 | 13717 | { |
b775012e LM |
13718 | if (!loc->enabled) |
13719 | { | |
13720 | loc->enabled = 1; | |
13721 | mark_breakpoint_location_modified (loc); | |
13722 | } | |
d248b706 KY |
13723 | if (target_supports_enable_disable_tracepoint () |
13724 | && current_trace_status ()->running && loc->owner | |
13725 | && is_tracepoint (loc->owner)) | |
13726 | target_enable_tracepoint (loc); | |
13727 | } | |
b60e7edf | 13728 | update_global_location_list (1); |
0d381245 | 13729 | } |
c906108c | 13730 | else |
95a42b64 | 13731 | map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL); |
c906108c SS |
13732 | } |
13733 | ||
816338b5 SS |
13734 | /* This struct packages up disposition data for application to multiple |
13735 | breakpoints. */ | |
13736 | ||
13737 | struct disp_data | |
13738 | { | |
13739 | enum bpdisp disp; | |
13740 | int count; | |
13741 | }; | |
13742 | ||
c906108c | 13743 | static void |
51be5b68 PA |
13744 | do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg) |
13745 | { | |
816338b5 | 13746 | struct disp_data disp_data = *(struct disp_data *) arg; |
51be5b68 | 13747 | |
816338b5 | 13748 | enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count); |
51be5b68 PA |
13749 | } |
13750 | ||
13751 | static void | |
13752 | do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore) | |
c906108c | 13753 | { |
816338b5 | 13754 | struct disp_data disp = { disp_disable, 1 }; |
51be5b68 PA |
13755 | |
13756 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
13757 | } |
13758 | ||
c906108c | 13759 | static void |
fba45db2 | 13760 | enable_once_command (char *args, int from_tty) |
c906108c | 13761 | { |
51be5b68 | 13762 | map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL); |
c906108c SS |
13763 | } |
13764 | ||
816338b5 SS |
13765 | static void |
13766 | do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr) | |
13767 | { | |
13768 | struct disp_data disp = { disp_disable, *(int *) countptr }; | |
13769 | ||
13770 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
13771 | } | |
13772 | ||
13773 | static void | |
13774 | enable_count_command (char *args, int from_tty) | |
13775 | { | |
13776 | int count = get_number (&args); | |
13777 | ||
13778 | map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count); | |
13779 | } | |
13780 | ||
c906108c | 13781 | static void |
51be5b68 | 13782 | do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 13783 | { |
816338b5 | 13784 | struct disp_data disp = { disp_del, 1 }; |
51be5b68 PA |
13785 | |
13786 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
13787 | } |
13788 | ||
c906108c | 13789 | static void |
fba45db2 | 13790 | enable_delete_command (char *args, int from_tty) |
c906108c | 13791 | { |
51be5b68 | 13792 | map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL); |
c906108c SS |
13793 | } |
13794 | \f | |
fa8d40ab JJ |
13795 | static void |
13796 | set_breakpoint_cmd (char *args, int from_tty) | |
13797 | { | |
13798 | } | |
13799 | ||
13800 | static void | |
13801 | show_breakpoint_cmd (char *args, int from_tty) | |
13802 | { | |
13803 | } | |
13804 | ||
1f3b5d1b PP |
13805 | /* Invalidate last known value of any hardware watchpoint if |
13806 | the memory which that value represents has been written to by | |
13807 | GDB itself. */ | |
13808 | ||
13809 | static void | |
13810 | invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len, | |
13811 | const bfd_byte *data) | |
13812 | { | |
13813 | struct breakpoint *bp; | |
13814 | ||
13815 | ALL_BREAKPOINTS (bp) | |
13816 | if (bp->enable_state == bp_enabled | |
3a5c3e22 | 13817 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 13818 | { |
3a5c3e22 | 13819 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 13820 | |
3a5c3e22 PA |
13821 | if (wp->val_valid && wp->val) |
13822 | { | |
13823 | struct bp_location *loc; | |
13824 | ||
13825 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
13826 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
13827 | && loc->address + loc->length > addr | |
13828 | && addr + len > loc->address) | |
13829 | { | |
13830 | value_free (wp->val); | |
13831 | wp->val = NULL; | |
13832 | wp->val_valid = 0; | |
13833 | } | |
13834 | } | |
1f3b5d1b PP |
13835 | } |
13836 | } | |
13837 | ||
1bfeeb0f JL |
13838 | /* Use the last displayed codepoint's values, or nothing |
13839 | if they aren't valid. */ | |
c906108c SS |
13840 | |
13841 | struct symtabs_and_lines | |
f8eba3c6 | 13842 | decode_line_spec_1 (char *string, int flags) |
c906108c SS |
13843 | { |
13844 | struct symtabs_and_lines sals; | |
cc59ec59 | 13845 | |
c906108c | 13846 | if (string == 0) |
8a3fe4f8 | 13847 | error (_("Empty line specification.")); |
1bfeeb0f | 13848 | if (last_displayed_sal_is_valid ()) |
f8eba3c6 | 13849 | sals = decode_line_1 (&string, flags, |
1bfeeb0f | 13850 | get_last_displayed_symtab (), |
f8eba3c6 | 13851 | get_last_displayed_line ()); |
c906108c | 13852 | else |
f8eba3c6 | 13853 | sals = decode_line_1 (&string, flags, (struct symtab *) NULL, 0); |
c906108c | 13854 | if (*string) |
8a3fe4f8 | 13855 | error (_("Junk at end of line specification: %s"), string); |
c906108c SS |
13856 | return sals; |
13857 | } | |
8181d85f DJ |
13858 | |
13859 | /* Create and insert a raw software breakpoint at PC. Return an | |
13860 | identifier, which should be used to remove the breakpoint later. | |
13861 | In general, places which call this should be using something on the | |
13862 | breakpoint chain instead; this function should be eliminated | |
13863 | someday. */ | |
13864 | ||
13865 | void * | |
6c95b8df PA |
13866 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, |
13867 | struct address_space *aspace, CORE_ADDR pc) | |
8181d85f DJ |
13868 | { |
13869 | struct bp_target_info *bp_tgt; | |
13870 | ||
6c95b8df | 13871 | bp_tgt = XZALLOC (struct bp_target_info); |
8181d85f | 13872 | |
6c95b8df | 13873 | bp_tgt->placed_address_space = aspace; |
8181d85f | 13874 | bp_tgt->placed_address = pc; |
6c95b8df | 13875 | |
a6d9a66e | 13876 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
8181d85f DJ |
13877 | { |
13878 | /* Could not insert the breakpoint. */ | |
13879 | xfree (bp_tgt); | |
13880 | return NULL; | |
13881 | } | |
13882 | ||
13883 | return bp_tgt; | |
13884 | } | |
13885 | ||
4a64f543 MS |
13886 | /* Remove a breakpoint BP inserted by |
13887 | deprecated_insert_raw_breakpoint. */ | |
8181d85f DJ |
13888 | |
13889 | int | |
a6d9a66e | 13890 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
8181d85f DJ |
13891 | { |
13892 | struct bp_target_info *bp_tgt = bp; | |
13893 | int ret; | |
13894 | ||
a6d9a66e | 13895 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
8181d85f DJ |
13896 | xfree (bp_tgt); |
13897 | ||
13898 | return ret; | |
13899 | } | |
13900 | ||
4a64f543 MS |
13901 | /* One (or perhaps two) breakpoints used for software single |
13902 | stepping. */ | |
8181d85f DJ |
13903 | |
13904 | static void *single_step_breakpoints[2]; | |
a6d9a66e | 13905 | static struct gdbarch *single_step_gdbarch[2]; |
8181d85f DJ |
13906 | |
13907 | /* Create and insert a breakpoint for software single step. */ | |
13908 | ||
13909 | void | |
6c95b8df | 13910 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
13911 | struct address_space *aspace, |
13912 | CORE_ADDR next_pc) | |
8181d85f DJ |
13913 | { |
13914 | void **bpt_p; | |
13915 | ||
13916 | if (single_step_breakpoints[0] == NULL) | |
a6d9a66e UW |
13917 | { |
13918 | bpt_p = &single_step_breakpoints[0]; | |
13919 | single_step_gdbarch[0] = gdbarch; | |
13920 | } | |
8181d85f DJ |
13921 | else |
13922 | { | |
13923 | gdb_assert (single_step_breakpoints[1] == NULL); | |
13924 | bpt_p = &single_step_breakpoints[1]; | |
a6d9a66e | 13925 | single_step_gdbarch[1] = gdbarch; |
8181d85f DJ |
13926 | } |
13927 | ||
4a64f543 MS |
13928 | /* NOTE drow/2006-04-11: A future improvement to this function would |
13929 | be to only create the breakpoints once, and actually put them on | |
13930 | the breakpoint chain. That would let us use set_raw_breakpoint. | |
13931 | We could adjust the addresses each time they were needed. Doing | |
13932 | this requires corresponding changes elsewhere where single step | |
13933 | breakpoints are handled, however. So, for now, we use this. */ | |
8181d85f | 13934 | |
6c95b8df | 13935 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc); |
8181d85f | 13936 | if (*bpt_p == NULL) |
5af949e3 UW |
13937 | error (_("Could not insert single-step breakpoint at %s"), |
13938 | paddress (gdbarch, next_pc)); | |
8181d85f DJ |
13939 | } |
13940 | ||
f02253f1 HZ |
13941 | /* Check if the breakpoints used for software single stepping |
13942 | were inserted or not. */ | |
13943 | ||
13944 | int | |
13945 | single_step_breakpoints_inserted (void) | |
13946 | { | |
13947 | return (single_step_breakpoints[0] != NULL | |
13948 | || single_step_breakpoints[1] != NULL); | |
13949 | } | |
13950 | ||
8181d85f DJ |
13951 | /* Remove and delete any breakpoints used for software single step. */ |
13952 | ||
13953 | void | |
13954 | remove_single_step_breakpoints (void) | |
13955 | { | |
13956 | gdb_assert (single_step_breakpoints[0] != NULL); | |
13957 | ||
13958 | /* See insert_single_step_breakpoint for more about this deprecated | |
13959 | call. */ | |
a6d9a66e UW |
13960 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
13961 | single_step_breakpoints[0]); | |
13962 | single_step_gdbarch[0] = NULL; | |
8181d85f DJ |
13963 | single_step_breakpoints[0] = NULL; |
13964 | ||
13965 | if (single_step_breakpoints[1] != NULL) | |
13966 | { | |
a6d9a66e UW |
13967 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
13968 | single_step_breakpoints[1]); | |
13969 | single_step_gdbarch[1] = NULL; | |
8181d85f DJ |
13970 | single_step_breakpoints[1] = NULL; |
13971 | } | |
13972 | } | |
13973 | ||
d03285ec UW |
13974 | /* Delete software single step breakpoints without removing them from |
13975 | the inferior. This is intended to be used if the inferior's address | |
13976 | space where they were inserted is already gone, e.g. after exit or | |
13977 | exec. */ | |
13978 | ||
13979 | void | |
13980 | cancel_single_step_breakpoints (void) | |
13981 | { | |
13982 | int i; | |
13983 | ||
13984 | for (i = 0; i < 2; i++) | |
13985 | if (single_step_breakpoints[i]) | |
13986 | { | |
13987 | xfree (single_step_breakpoints[i]); | |
13988 | single_step_breakpoints[i] = NULL; | |
13989 | single_step_gdbarch[i] = NULL; | |
13990 | } | |
13991 | } | |
13992 | ||
13993 | /* Detach software single-step breakpoints from INFERIOR_PTID without | |
13994 | removing them. */ | |
13995 | ||
13996 | static void | |
13997 | detach_single_step_breakpoints (void) | |
13998 | { | |
13999 | int i; | |
14000 | ||
14001 | for (i = 0; i < 2; i++) | |
14002 | if (single_step_breakpoints[i]) | |
14003 | target_remove_breakpoint (single_step_gdbarch[i], | |
14004 | single_step_breakpoints[i]); | |
14005 | } | |
14006 | ||
4a64f543 MS |
14007 | /* Check whether a software single-step breakpoint is inserted at |
14008 | PC. */ | |
1aafd4da UW |
14009 | |
14010 | static int | |
cc59ec59 MS |
14011 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, |
14012 | CORE_ADDR pc) | |
1aafd4da UW |
14013 | { |
14014 | int i; | |
14015 | ||
14016 | for (i = 0; i < 2; i++) | |
14017 | { | |
14018 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
6c95b8df PA |
14019 | if (bp_tgt |
14020 | && breakpoint_address_match (bp_tgt->placed_address_space, | |
14021 | bp_tgt->placed_address, | |
14022 | aspace, pc)) | |
1aafd4da UW |
14023 | return 1; |
14024 | } | |
14025 | ||
14026 | return 0; | |
14027 | } | |
14028 | ||
a96d9b2e SDJ |
14029 | /* Returns 0 if 'bp' is NOT a syscall catchpoint, |
14030 | non-zero otherwise. */ | |
14031 | static int | |
14032 | is_syscall_catchpoint_enabled (struct breakpoint *bp) | |
14033 | { | |
14034 | if (syscall_catchpoint_p (bp) | |
14035 | && bp->enable_state != bp_disabled | |
14036 | && bp->enable_state != bp_call_disabled) | |
14037 | return 1; | |
14038 | else | |
14039 | return 0; | |
14040 | } | |
14041 | ||
14042 | int | |
14043 | catch_syscall_enabled (void) | |
14044 | { | |
14045 | struct inferior *inf = current_inferior (); | |
14046 | ||
14047 | return inf->total_syscalls_count != 0; | |
14048 | } | |
14049 | ||
14050 | int | |
14051 | catching_syscall_number (int syscall_number) | |
14052 | { | |
14053 | struct breakpoint *bp; | |
14054 | ||
14055 | ALL_BREAKPOINTS (bp) | |
14056 | if (is_syscall_catchpoint_enabled (bp)) | |
14057 | { | |
be5c67c1 PA |
14058 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bp; |
14059 | ||
14060 | if (c->syscalls_to_be_caught) | |
a96d9b2e SDJ |
14061 | { |
14062 | int i, iter; | |
14063 | for (i = 0; | |
be5c67c1 | 14064 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
14065 | i++) |
14066 | if (syscall_number == iter) | |
14067 | return 1; | |
14068 | } | |
14069 | else | |
14070 | return 1; | |
14071 | } | |
14072 | ||
14073 | return 0; | |
14074 | } | |
14075 | ||
14076 | /* Complete syscall names. Used by "catch syscall". */ | |
14077 | static char ** | |
14078 | catch_syscall_completer (struct cmd_list_element *cmd, | |
14079 | char *text, char *word) | |
14080 | { | |
14081 | const char **list = get_syscall_names (); | |
c38eea1a MS |
14082 | char **retlist |
14083 | = (list == NULL) ? NULL : complete_on_enum (list, text, word); | |
cc59ec59 | 14084 | |
c38eea1a MS |
14085 | xfree (list); |
14086 | return retlist; | |
a96d9b2e SDJ |
14087 | } |
14088 | ||
1042e4c0 SS |
14089 | /* Tracepoint-specific operations. */ |
14090 | ||
14091 | /* Set tracepoint count to NUM. */ | |
14092 | static void | |
14093 | set_tracepoint_count (int num) | |
14094 | { | |
14095 | tracepoint_count = num; | |
4fa62494 | 14096 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
14097 | } |
14098 | ||
14099 | void | |
14100 | trace_command (char *arg, int from_tty) | |
14101 | { | |
8cdf0e15 VP |
14102 | if (create_breakpoint (get_current_arch (), |
14103 | arg, | |
14104 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b PA |
14105 | 0 /* tempflag */, |
14106 | bp_tracepoint /* type_wanted */, | |
8cdf0e15 VP |
14107 | 0 /* Ignore count */, |
14108 | pending_break_support, | |
348d480f | 14109 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 14110 | from_tty, |
84f4c1fe PM |
14111 | 1 /* enabled */, |
14112 | 0 /* internal */)) | |
fd9b8c24 | 14113 | set_tracepoint_count (breakpoint_count); |
1042e4c0 SS |
14114 | } |
14115 | ||
7a697b8d SS |
14116 | void |
14117 | ftrace_command (char *arg, int from_tty) | |
14118 | { | |
8cdf0e15 VP |
14119 | if (create_breakpoint (get_current_arch (), |
14120 | arg, | |
14121 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b PA |
14122 | 0 /* tempflag */, |
14123 | bp_fast_tracepoint /* type_wanted */, | |
14124 | 0 /* Ignore count */, | |
14125 | pending_break_support, | |
348d480f | 14126 | &tracepoint_breakpoint_ops, |
0fb4aa4b | 14127 | from_tty, |
84f4c1fe PM |
14128 | 1 /* enabled */, |
14129 | 0 /* internal */)) | |
0fb4aa4b PA |
14130 | set_tracepoint_count (breakpoint_count); |
14131 | } | |
14132 | ||
14133 | /* strace command implementation. Creates a static tracepoint. */ | |
14134 | ||
14135 | void | |
14136 | strace_command (char *arg, int from_tty) | |
14137 | { | |
983af33b SDJ |
14138 | struct breakpoint_ops *ops; |
14139 | ||
14140 | /* Decide if we are dealing with a static tracepoint marker (`-m'), | |
14141 | or with a normal static tracepoint. */ | |
14142 | if (arg && strncmp (arg, "-m", 2) == 0 && isspace (arg[2])) | |
14143 | ops = &strace_marker_breakpoint_ops; | |
14144 | else | |
14145 | ops = &tracepoint_breakpoint_ops; | |
14146 | ||
0fb4aa4b PA |
14147 | if (create_breakpoint (get_current_arch (), |
14148 | arg, | |
14149 | NULL, 0, 1 /* parse arg */, | |
14150 | 0 /* tempflag */, | |
14151 | bp_static_tracepoint /* type_wanted */, | |
8cdf0e15 VP |
14152 | 0 /* Ignore count */, |
14153 | pending_break_support, | |
983af33b | 14154 | ops, |
8cdf0e15 | 14155 | from_tty, |
84f4c1fe PM |
14156 | 1 /* enabled */, |
14157 | 0 /* internal */)) | |
fd9b8c24 | 14158 | set_tracepoint_count (breakpoint_count); |
7a697b8d SS |
14159 | } |
14160 | ||
409873ef SS |
14161 | /* Set up a fake reader function that gets command lines from a linked |
14162 | list that was acquired during tracepoint uploading. */ | |
14163 | ||
14164 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 14165 | static int next_cmd; |
409873ef SS |
14166 | |
14167 | static char * | |
14168 | read_uploaded_action (void) | |
14169 | { | |
14170 | char *rslt; | |
14171 | ||
3149d8c1 | 14172 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 14173 | |
3149d8c1 | 14174 | next_cmd++; |
409873ef SS |
14175 | |
14176 | return rslt; | |
14177 | } | |
14178 | ||
00bf0b85 SS |
14179 | /* Given information about a tracepoint as recorded on a target (which |
14180 | can be either a live system or a trace file), attempt to create an | |
14181 | equivalent GDB tracepoint. This is not a reliable process, since | |
14182 | the target does not necessarily have all the information used when | |
14183 | the tracepoint was originally defined. */ | |
14184 | ||
d9b3f62e | 14185 | struct tracepoint * |
00bf0b85 | 14186 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 14187 | { |
409873ef | 14188 | char *addr_str, small_buf[100]; |
d9b3f62e | 14189 | struct tracepoint *tp; |
fd9b8c24 | 14190 | |
409873ef SS |
14191 | if (utp->at_string) |
14192 | addr_str = utp->at_string; | |
14193 | else | |
14194 | { | |
14195 | /* In the absence of a source location, fall back to raw | |
14196 | address. Since there is no way to confirm that the address | |
14197 | means the same thing as when the trace was started, warn the | |
14198 | user. */ | |
3e43a32a MS |
14199 | warning (_("Uploaded tracepoint %d has no " |
14200 | "source location, using raw address"), | |
409873ef SS |
14201 | utp->number); |
14202 | sprintf (small_buf, "*%s", hex_string (utp->addr)); | |
14203 | addr_str = small_buf; | |
14204 | } | |
14205 | ||
14206 | /* There's not much we can do with a sequence of bytecodes. */ | |
14207 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
14208 | warning (_("Uploaded tracepoint %d condition " |
14209 | "has no source form, ignoring it"), | |
409873ef | 14210 | utp->number); |
d5551862 | 14211 | |
8cdf0e15 | 14212 | if (!create_breakpoint (get_current_arch (), |
409873ef SS |
14213 | addr_str, |
14214 | utp->cond_string, -1, 0 /* parse cond/thread */, | |
8cdf0e15 | 14215 | 0 /* tempflag */, |
0fb4aa4b | 14216 | utp->type /* type_wanted */, |
8cdf0e15 VP |
14217 | 0 /* Ignore count */, |
14218 | pending_break_support, | |
348d480f | 14219 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 14220 | 0 /* from_tty */, |
84f4c1fe PM |
14221 | utp->enabled /* enabled */, |
14222 | 0 /* internal */)) | |
fd9b8c24 PA |
14223 | return NULL; |
14224 | ||
00bf0b85 SS |
14225 | set_tracepoint_count (breakpoint_count); |
14226 | ||
409873ef | 14227 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
14228 | tp = get_tracepoint (tracepoint_count); |
14229 | gdb_assert (tp != NULL); | |
d5551862 | 14230 | |
00bf0b85 SS |
14231 | if (utp->pass > 0) |
14232 | { | |
d9b3f62e | 14233 | sprintf (small_buf, "%d %d", utp->pass, tp->base.number); |
00bf0b85 | 14234 | |
409873ef | 14235 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
14236 | } |
14237 | ||
409873ef SS |
14238 | /* If we have uploaded versions of the original commands, set up a |
14239 | special-purpose "reader" function and call the usual command line | |
14240 | reader, then pass the result to the breakpoint command-setting | |
14241 | function. */ | |
3149d8c1 | 14242 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 14243 | { |
409873ef | 14244 | struct command_line *cmd_list; |
00bf0b85 | 14245 | |
409873ef | 14246 | this_utp = utp; |
3149d8c1 | 14247 | next_cmd = 0; |
d5551862 | 14248 | |
409873ef SS |
14249 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
14250 | ||
d9b3f62e | 14251 | breakpoint_set_commands (&tp->base, cmd_list); |
00bf0b85 | 14252 | } |
3149d8c1 SS |
14253 | else if (!VEC_empty (char_ptr, utp->actions) |
14254 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
14255 | warning (_("Uploaded tracepoint %d actions " |
14256 | "have no source form, ignoring them"), | |
409873ef | 14257 | utp->number); |
00bf0b85 | 14258 | |
f196051f SS |
14259 | /* Copy any status information that might be available. */ |
14260 | tp->base.hit_count = utp->hit_count; | |
14261 | tp->traceframe_usage = utp->traceframe_usage; | |
14262 | ||
00bf0b85 | 14263 | return tp; |
d9b3f62e | 14264 | } |
00bf0b85 | 14265 | |
1042e4c0 SS |
14266 | /* Print information on tracepoint number TPNUM_EXP, or all if |
14267 | omitted. */ | |
14268 | ||
14269 | static void | |
e5a67952 | 14270 | tracepoints_info (char *args, int from_tty) |
1042e4c0 | 14271 | { |
79a45e25 | 14272 | struct ui_out *uiout = current_uiout; |
e5a67952 | 14273 | int num_printed; |
1042e4c0 | 14274 | |
e5a67952 | 14275 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
14276 | |
14277 | if (num_printed == 0) | |
1042e4c0 | 14278 | { |
e5a67952 | 14279 | if (args == NULL || *args == '\0') |
d77f58be SS |
14280 | ui_out_message (uiout, 0, "No tracepoints.\n"); |
14281 | else | |
e5a67952 | 14282 | ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args); |
1042e4c0 | 14283 | } |
ad443146 SS |
14284 | |
14285 | default_collect_info (); | |
1042e4c0 SS |
14286 | } |
14287 | ||
4a64f543 | 14288 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
14289 | Not supported by all targets. */ |
14290 | static void | |
14291 | enable_trace_command (char *args, int from_tty) | |
14292 | { | |
14293 | enable_command (args, from_tty); | |
14294 | } | |
14295 | ||
4a64f543 | 14296 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
14297 | Not supported by all targets. */ |
14298 | static void | |
14299 | disable_trace_command (char *args, int from_tty) | |
14300 | { | |
14301 | disable_command (args, from_tty); | |
14302 | } | |
14303 | ||
4a64f543 | 14304 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 SS |
14305 | static void |
14306 | delete_trace_command (char *arg, int from_tty) | |
14307 | { | |
35df4500 | 14308 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
14309 | |
14310 | dont_repeat (); | |
14311 | ||
14312 | if (arg == 0) | |
14313 | { | |
14314 | int breaks_to_delete = 0; | |
14315 | ||
14316 | /* Delete all breakpoints if no argument. | |
14317 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
14318 | have to be deleted with an explicit breakpoint number |
14319 | argument. */ | |
1042e4c0 | 14320 | ALL_TRACEPOINTS (b) |
46c6471b | 14321 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
14322 | { |
14323 | breaks_to_delete = 1; | |
14324 | break; | |
14325 | } | |
1042e4c0 SS |
14326 | |
14327 | /* Ask user only if there are some breakpoints to delete. */ | |
14328 | if (!from_tty | |
14329 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
14330 | { | |
35df4500 | 14331 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 14332 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 14333 | delete_breakpoint (b); |
1042e4c0 SS |
14334 | } |
14335 | } | |
14336 | else | |
51be5b68 | 14337 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
1042e4c0 SS |
14338 | } |
14339 | ||
197f0a60 TT |
14340 | /* Helper function for trace_pass_command. */ |
14341 | ||
14342 | static void | |
d9b3f62e | 14343 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 14344 | { |
d9b3f62e PA |
14345 | tp->pass_count = count; |
14346 | observer_notify_tracepoint_modified (tp->base.number); | |
197f0a60 TT |
14347 | if (from_tty) |
14348 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
d9b3f62e | 14349 | tp->base.number, count); |
197f0a60 TT |
14350 | } |
14351 | ||
1042e4c0 SS |
14352 | /* Set passcount for tracepoint. |
14353 | ||
14354 | First command argument is passcount, second is tracepoint number. | |
14355 | If tracepoint number omitted, apply to most recently defined. | |
14356 | Also accepts special argument "all". */ | |
14357 | ||
14358 | static void | |
14359 | trace_pass_command (char *args, int from_tty) | |
14360 | { | |
d9b3f62e | 14361 | struct tracepoint *t1; |
1042e4c0 | 14362 | unsigned int count; |
1042e4c0 SS |
14363 | |
14364 | if (args == 0 || *args == 0) | |
3e43a32a MS |
14365 | error (_("passcount command requires an " |
14366 | "argument (count + optional TP num)")); | |
1042e4c0 | 14367 | |
4a64f543 | 14368 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 SS |
14369 | |
14370 | while (*args && isspace ((int) *args)) | |
14371 | args++; | |
14372 | ||
14373 | if (*args && strncasecmp (args, "all", 3) == 0) | |
14374 | { | |
d9b3f62e PA |
14375 | struct breakpoint *b; |
14376 | ||
1042e4c0 | 14377 | args += 3; /* Skip special argument "all". */ |
1042e4c0 SS |
14378 | if (*args) |
14379 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 14380 | |
d9b3f62e | 14381 | ALL_TRACEPOINTS (b) |
197f0a60 | 14382 | { |
d9b3f62e | 14383 | t1 = (struct tracepoint *) b; |
197f0a60 TT |
14384 | trace_pass_set_count (t1, count, from_tty); |
14385 | } | |
14386 | } | |
14387 | else if (*args == '\0') | |
1042e4c0 | 14388 | { |
197f0a60 | 14389 | t1 = get_tracepoint_by_number (&args, NULL, 1); |
1042e4c0 | 14390 | if (t1) |
197f0a60 TT |
14391 | trace_pass_set_count (t1, count, from_tty); |
14392 | } | |
14393 | else | |
14394 | { | |
14395 | struct get_number_or_range_state state; | |
14396 | ||
14397 | init_number_or_range (&state, args); | |
14398 | while (!state.finished) | |
1042e4c0 | 14399 | { |
197f0a60 TT |
14400 | t1 = get_tracepoint_by_number (&args, &state, 1); |
14401 | if (t1) | |
14402 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
14403 | } |
14404 | } | |
1042e4c0 SS |
14405 | } |
14406 | ||
d9b3f62e | 14407 | struct tracepoint * |
1042e4c0 SS |
14408 | get_tracepoint (int num) |
14409 | { | |
14410 | struct breakpoint *t; | |
14411 | ||
14412 | ALL_TRACEPOINTS (t) | |
14413 | if (t->number == num) | |
d9b3f62e | 14414 | return (struct tracepoint *) t; |
1042e4c0 SS |
14415 | |
14416 | return NULL; | |
14417 | } | |
14418 | ||
d5551862 SS |
14419 | /* Find the tracepoint with the given target-side number (which may be |
14420 | different from the tracepoint number after disconnecting and | |
14421 | reconnecting). */ | |
14422 | ||
d9b3f62e | 14423 | struct tracepoint * |
d5551862 SS |
14424 | get_tracepoint_by_number_on_target (int num) |
14425 | { | |
d9b3f62e | 14426 | struct breakpoint *b; |
d5551862 | 14427 | |
d9b3f62e PA |
14428 | ALL_TRACEPOINTS (b) |
14429 | { | |
14430 | struct tracepoint *t = (struct tracepoint *) b; | |
14431 | ||
14432 | if (t->number_on_target == num) | |
14433 | return t; | |
14434 | } | |
d5551862 SS |
14435 | |
14436 | return NULL; | |
14437 | } | |
14438 | ||
1042e4c0 | 14439 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 TT |
14440 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
14441 | If OPTIONAL_P is true, then if the argument is missing, the most | |
1042e4c0 | 14442 | recent tracepoint (tracepoint_count) is returned. */ |
d9b3f62e | 14443 | struct tracepoint * |
197f0a60 TT |
14444 | get_tracepoint_by_number (char **arg, |
14445 | struct get_number_or_range_state *state, | |
14446 | int optional_p) | |
1042e4c0 SS |
14447 | { |
14448 | extern int tracepoint_count; | |
14449 | struct breakpoint *t; | |
14450 | int tpnum; | |
14451 | char *instring = arg == NULL ? NULL : *arg; | |
14452 | ||
197f0a60 TT |
14453 | if (state) |
14454 | { | |
14455 | gdb_assert (!state->finished); | |
14456 | tpnum = get_number_or_range (state); | |
14457 | } | |
14458 | else if (arg == NULL || *arg == NULL || ! **arg) | |
1042e4c0 SS |
14459 | { |
14460 | if (optional_p) | |
14461 | tpnum = tracepoint_count; | |
14462 | else | |
14463 | error_no_arg (_("tracepoint number")); | |
14464 | } | |
14465 | else | |
197f0a60 | 14466 | tpnum = get_number (arg); |
1042e4c0 SS |
14467 | |
14468 | if (tpnum <= 0) | |
14469 | { | |
14470 | if (instring && *instring) | |
14471 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
14472 | instring); | |
14473 | else | |
3e43a32a MS |
14474 | printf_filtered (_("Tracepoint argument missing " |
14475 | "and no previous tracepoint\n")); | |
1042e4c0 SS |
14476 | return NULL; |
14477 | } | |
14478 | ||
14479 | ALL_TRACEPOINTS (t) | |
14480 | if (t->number == tpnum) | |
14481 | { | |
d9b3f62e | 14482 | return (struct tracepoint *) t; |
1042e4c0 SS |
14483 | } |
14484 | ||
1042e4c0 SS |
14485 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
14486 | return NULL; | |
14487 | } | |
14488 | ||
d9b3f62e PA |
14489 | void |
14490 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
14491 | { | |
14492 | if (b->thread != -1) | |
14493 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
14494 | ||
14495 | if (b->task != 0) | |
14496 | fprintf_unfiltered (fp, " task %d", b->task); | |
14497 | ||
14498 | fprintf_unfiltered (fp, "\n"); | |
14499 | } | |
14500 | ||
6149aea9 PA |
14501 | /* Save information on user settable breakpoints (watchpoints, etc) to |
14502 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
14503 | on each breakpoint and only include the ones for which it returns | |
14504 | non-zero. */ | |
14505 | ||
1042e4c0 | 14506 | static void |
6149aea9 PA |
14507 | save_breakpoints (char *filename, int from_tty, |
14508 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
14509 | { |
14510 | struct breakpoint *tp; | |
6149aea9 | 14511 | int any = 0; |
a7bdde9e | 14512 | char *pathname; |
1042e4c0 | 14513 | struct cleanup *cleanup; |
a7bdde9e | 14514 | struct ui_file *fp; |
6149aea9 | 14515 | int extra_trace_bits = 0; |
1042e4c0 | 14516 | |
6149aea9 PA |
14517 | if (filename == 0 || *filename == 0) |
14518 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
14519 | |
14520 | /* See if we have anything to save. */ | |
6149aea9 | 14521 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 14522 | { |
6149aea9 | 14523 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 14524 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
14525 | continue; |
14526 | ||
14527 | /* If we have a filter, only save the breakpoints it accepts. */ | |
14528 | if (filter && !filter (tp)) | |
14529 | continue; | |
14530 | ||
14531 | any = 1; | |
14532 | ||
14533 | if (is_tracepoint (tp)) | |
14534 | { | |
14535 | extra_trace_bits = 1; | |
14536 | ||
14537 | /* We can stop searching. */ | |
14538 | break; | |
14539 | } | |
1042e4c0 | 14540 | } |
6149aea9 PA |
14541 | |
14542 | if (!any) | |
1042e4c0 | 14543 | { |
6149aea9 | 14544 | warning (_("Nothing to save.")); |
1042e4c0 SS |
14545 | return; |
14546 | } | |
14547 | ||
6149aea9 | 14548 | pathname = tilde_expand (filename); |
1042e4c0 | 14549 | cleanup = make_cleanup (xfree, pathname); |
a7bdde9e | 14550 | fp = gdb_fopen (pathname, "w"); |
059fb39f | 14551 | if (!fp) |
6149aea9 PA |
14552 | error (_("Unable to open file '%s' for saving (%s)"), |
14553 | filename, safe_strerror (errno)); | |
a7bdde9e | 14554 | make_cleanup_ui_file_delete (fp); |
8bf6485c | 14555 | |
6149aea9 PA |
14556 | if (extra_trace_bits) |
14557 | save_trace_state_variables (fp); | |
8bf6485c | 14558 | |
6149aea9 | 14559 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 14560 | { |
6149aea9 | 14561 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 14562 | if (!user_breakpoint_p (tp)) |
6149aea9 | 14563 | continue; |
8bf6485c | 14564 | |
6149aea9 PA |
14565 | /* If we have a filter, only save the breakpoints it accepts. */ |
14566 | if (filter && !filter (tp)) | |
14567 | continue; | |
14568 | ||
348d480f | 14569 | tp->ops->print_recreate (tp, fp); |
1042e4c0 | 14570 | |
6149aea9 PA |
14571 | /* Note, we can't rely on tp->number for anything, as we can't |
14572 | assume the recreated breakpoint numbers will match. Use $bpnum | |
14573 | instead. */ | |
14574 | ||
14575 | if (tp->cond_string) | |
14576 | fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); | |
14577 | ||
14578 | if (tp->ignore_count) | |
14579 | fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); | |
14580 | ||
a7bdde9e | 14581 | if (tp->commands) |
1042e4c0 | 14582 | { |
a7bdde9e VP |
14583 | volatile struct gdb_exception ex; |
14584 | ||
6149aea9 | 14585 | fprintf_unfiltered (fp, " commands\n"); |
a7bdde9e | 14586 | |
79a45e25 | 14587 | ui_out_redirect (current_uiout, fp); |
14dba4b4 | 14588 | TRY_CATCH (ex, RETURN_MASK_ALL) |
1042e4c0 | 14589 | { |
79a45e25 | 14590 | print_command_lines (current_uiout, tp->commands->commands, 2); |
a7bdde9e | 14591 | } |
79a45e25 | 14592 | ui_out_redirect (current_uiout, NULL); |
1042e4c0 | 14593 | |
a7bdde9e VP |
14594 | if (ex.reason < 0) |
14595 | throw_exception (ex); | |
1042e4c0 | 14596 | |
a7bdde9e | 14597 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 | 14598 | } |
6149aea9 PA |
14599 | |
14600 | if (tp->enable_state == bp_disabled) | |
14601 | fprintf_unfiltered (fp, "disable\n"); | |
14602 | ||
14603 | /* If this is a multi-location breakpoint, check if the locations | |
14604 | should be individually disabled. Watchpoint locations are | |
14605 | special, and not user visible. */ | |
14606 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
14607 | { | |
14608 | struct bp_location *loc; | |
14609 | int n = 1; | |
14610 | ||
14611 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
14612 | if (!loc->enabled) | |
14613 | fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); | |
14614 | } | |
1042e4c0 | 14615 | } |
8bf6485c | 14616 | |
6149aea9 | 14617 | if (extra_trace_bits && *default_collect) |
8bf6485c SS |
14618 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); |
14619 | ||
1042e4c0 SS |
14620 | do_cleanups (cleanup); |
14621 | if (from_tty) | |
6149aea9 PA |
14622 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
14623 | } | |
14624 | ||
14625 | /* The `save breakpoints' command. */ | |
14626 | ||
14627 | static void | |
14628 | save_breakpoints_command (char *args, int from_tty) | |
14629 | { | |
14630 | save_breakpoints (args, from_tty, NULL); | |
14631 | } | |
14632 | ||
14633 | /* The `save tracepoints' command. */ | |
14634 | ||
14635 | static void | |
14636 | save_tracepoints_command (char *args, int from_tty) | |
14637 | { | |
14638 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
14639 | } |
14640 | ||
14641 | /* Create a vector of all tracepoints. */ | |
14642 | ||
14643 | VEC(breakpoint_p) * | |
eeae04df | 14644 | all_tracepoints (void) |
1042e4c0 SS |
14645 | { |
14646 | VEC(breakpoint_p) *tp_vec = 0; | |
14647 | struct breakpoint *tp; | |
14648 | ||
14649 | ALL_TRACEPOINTS (tp) | |
14650 | { | |
14651 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
14652 | } | |
14653 | ||
14654 | return tp_vec; | |
14655 | } | |
14656 | ||
c906108c | 14657 | \f |
4a64f543 MS |
14658 | /* This help string is used for the break, hbreak, tbreak and thbreak |
14659 | commands. It is defined as a macro to prevent duplication. | |
14660 | COMMAND should be a string constant containing the name of the | |
14661 | command. */ | |
31e2b00f AS |
14662 | #define BREAK_ARGS_HELP(command) \ |
14663 | command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\ | |
14664 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ | |
14665 | If a line number is specified, break at start of code for that line.\n\ | |
14666 | If a function is specified, break at start of code for that function.\n\ | |
14667 | If an address is specified, break at that exact address.\n\ | |
dc10affe PA |
14668 | With no LOCATION, uses current execution address of the selected\n\ |
14669 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
14670 | \n\ |
14671 | THREADNUM is the number from \"info threads\".\n\ | |
14672 | CONDITION is a boolean expression.\n\ | |
14673 | \n\ | |
d41c0fc8 PA |
14674 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
14675 | conditions are different.\n\ | |
31e2b00f AS |
14676 | \n\ |
14677 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
14678 | ||
44feb3ce TT |
14679 | /* List of subcommands for "catch". */ |
14680 | static struct cmd_list_element *catch_cmdlist; | |
14681 | ||
14682 | /* List of subcommands for "tcatch". */ | |
14683 | static struct cmd_list_element *tcatch_cmdlist; | |
14684 | ||
9ac4176b | 14685 | void |
44feb3ce TT |
14686 | add_catch_command (char *name, char *docstring, |
14687 | void (*sfunc) (char *args, int from_tty, | |
14688 | struct cmd_list_element *command), | |
a96d9b2e SDJ |
14689 | char **(*completer) (struct cmd_list_element *cmd, |
14690 | char *text, char *word), | |
44feb3ce TT |
14691 | void *user_data_catch, |
14692 | void *user_data_tcatch) | |
14693 | { | |
14694 | struct cmd_list_element *command; | |
14695 | ||
14696 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
14697 | &catch_cmdlist); | |
14698 | set_cmd_sfunc (command, sfunc); | |
14699 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 14700 | set_cmd_completer (command, completer); |
44feb3ce TT |
14701 | |
14702 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
14703 | &tcatch_cmdlist); | |
14704 | set_cmd_sfunc (command, sfunc); | |
14705 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 14706 | set_cmd_completer (command, completer); |
44feb3ce TT |
14707 | } |
14708 | ||
6c95b8df | 14709 | static void |
a79b8f6e | 14710 | clear_syscall_counts (struct inferior *inf) |
6c95b8df | 14711 | { |
6c95b8df PA |
14712 | inf->total_syscalls_count = 0; |
14713 | inf->any_syscall_count = 0; | |
14714 | VEC_free (int, inf->syscalls_counts); | |
14715 | } | |
14716 | ||
6149aea9 PA |
14717 | static void |
14718 | save_command (char *arg, int from_tty) | |
14719 | { | |
3e43a32a MS |
14720 | printf_unfiltered (_("\"save\" must be followed by " |
14721 | "the name of a save subcommand.\n")); | |
6149aea9 PA |
14722 | help_list (save_cmdlist, "save ", -1, gdb_stdout); |
14723 | } | |
14724 | ||
84f4c1fe PM |
14725 | struct breakpoint * |
14726 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
14727 | void *data) | |
14728 | { | |
35df4500 | 14729 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 14730 | |
35df4500 | 14731 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
14732 | { |
14733 | if ((*callback) (b, data)) | |
14734 | return b; | |
14735 | } | |
14736 | ||
14737 | return NULL; | |
14738 | } | |
14739 | ||
0574c78f GB |
14740 | /* Zero if any of the breakpoint's locations could be a location where |
14741 | functions have been inlined, nonzero otherwise. */ | |
14742 | ||
14743 | static int | |
14744 | is_non_inline_function (struct breakpoint *b) | |
14745 | { | |
14746 | /* The shared library event breakpoint is set on the address of a | |
14747 | non-inline function. */ | |
14748 | if (b->type == bp_shlib_event) | |
14749 | return 1; | |
14750 | ||
14751 | return 0; | |
14752 | } | |
14753 | ||
14754 | /* Nonzero if the specified PC cannot be a location where functions | |
14755 | have been inlined. */ | |
14756 | ||
14757 | int | |
09ac7c10 TT |
14758 | pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc, |
14759 | const struct target_waitstatus *ws) | |
0574c78f GB |
14760 | { |
14761 | struct breakpoint *b; | |
14762 | struct bp_location *bl; | |
14763 | ||
14764 | ALL_BREAKPOINTS (b) | |
14765 | { | |
14766 | if (!is_non_inline_function (b)) | |
14767 | continue; | |
14768 | ||
14769 | for (bl = b->loc; bl != NULL; bl = bl->next) | |
14770 | { | |
14771 | if (!bl->shlib_disabled | |
09ac7c10 | 14772 | && bpstat_check_location (bl, aspace, pc, ws)) |
0574c78f GB |
14773 | return 1; |
14774 | } | |
14775 | } | |
14776 | ||
14777 | return 0; | |
14778 | } | |
14779 | ||
2060206e PA |
14780 | void |
14781 | initialize_breakpoint_ops (void) | |
14782 | { | |
14783 | static int initialized = 0; | |
14784 | ||
14785 | struct breakpoint_ops *ops; | |
14786 | ||
14787 | if (initialized) | |
14788 | return; | |
14789 | initialized = 1; | |
14790 | ||
14791 | /* The breakpoint_ops structure to be inherit by all kinds of | |
14792 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
14793 | internal and momentary breakpoints, etc.). */ | |
14794 | ops = &bkpt_base_breakpoint_ops; | |
14795 | *ops = base_breakpoint_ops; | |
14796 | ops->re_set = bkpt_re_set; | |
14797 | ops->insert_location = bkpt_insert_location; | |
14798 | ops->remove_location = bkpt_remove_location; | |
14799 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
983af33b SDJ |
14800 | ops->create_sals_from_address = bkpt_create_sals_from_address; |
14801 | ops->create_breakpoints_sal = bkpt_create_breakpoints_sal; | |
14802 | ops->decode_linespec = bkpt_decode_linespec; | |
2060206e PA |
14803 | |
14804 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
14805 | ops = &bkpt_breakpoint_ops; | |
14806 | *ops = bkpt_base_breakpoint_ops; | |
14807 | ops->re_set = bkpt_re_set; | |
14808 | ops->resources_needed = bkpt_resources_needed; | |
14809 | ops->print_it = bkpt_print_it; | |
14810 | ops->print_mention = bkpt_print_mention; | |
14811 | ops->print_recreate = bkpt_print_recreate; | |
14812 | ||
14813 | /* Ranged breakpoints. */ | |
14814 | ops = &ranged_breakpoint_ops; | |
14815 | *ops = bkpt_breakpoint_ops; | |
14816 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
14817 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
14818 | ops->print_it = print_it_ranged_breakpoint; | |
14819 | ops->print_one = print_one_ranged_breakpoint; | |
14820 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
14821 | ops->print_mention = print_mention_ranged_breakpoint; | |
14822 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
14823 | ||
14824 | /* Internal breakpoints. */ | |
14825 | ops = &internal_breakpoint_ops; | |
14826 | *ops = bkpt_base_breakpoint_ops; | |
14827 | ops->re_set = internal_bkpt_re_set; | |
14828 | ops->check_status = internal_bkpt_check_status; | |
14829 | ops->print_it = internal_bkpt_print_it; | |
14830 | ops->print_mention = internal_bkpt_print_mention; | |
14831 | ||
14832 | /* Momentary breakpoints. */ | |
14833 | ops = &momentary_breakpoint_ops; | |
14834 | *ops = bkpt_base_breakpoint_ops; | |
14835 | ops->re_set = momentary_bkpt_re_set; | |
14836 | ops->check_status = momentary_bkpt_check_status; | |
14837 | ops->print_it = momentary_bkpt_print_it; | |
14838 | ops->print_mention = momentary_bkpt_print_mention; | |
14839 | ||
14840 | /* GNU v3 exception catchpoints. */ | |
14841 | ops = &gnu_v3_exception_catchpoint_ops; | |
14842 | *ops = bkpt_breakpoint_ops; | |
14843 | ops->print_it = print_it_exception_catchpoint; | |
14844 | ops->print_one = print_one_exception_catchpoint; | |
14845 | ops->print_mention = print_mention_exception_catchpoint; | |
14846 | ops->print_recreate = print_recreate_exception_catchpoint; | |
14847 | ||
14848 | /* Watchpoints. */ | |
14849 | ops = &watchpoint_breakpoint_ops; | |
14850 | *ops = base_breakpoint_ops; | |
3a5c3e22 | 14851 | ops->dtor = dtor_watchpoint; |
2060206e PA |
14852 | ops->re_set = re_set_watchpoint; |
14853 | ops->insert_location = insert_watchpoint; | |
14854 | ops->remove_location = remove_watchpoint; | |
14855 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
14856 | ops->check_status = check_status_watchpoint; | |
14857 | ops->resources_needed = resources_needed_watchpoint; | |
14858 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
14859 | ops->print_it = print_it_watchpoint; | |
14860 | ops->print_mention = print_mention_watchpoint; | |
14861 | ops->print_recreate = print_recreate_watchpoint; | |
14862 | ||
14863 | /* Masked watchpoints. */ | |
14864 | ops = &masked_watchpoint_breakpoint_ops; | |
14865 | *ops = watchpoint_breakpoint_ops; | |
14866 | ops->insert_location = insert_masked_watchpoint; | |
14867 | ops->remove_location = remove_masked_watchpoint; | |
14868 | ops->resources_needed = resources_needed_masked_watchpoint; | |
14869 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
14870 | ops->print_it = print_it_masked_watchpoint; | |
14871 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
14872 | ops->print_mention = print_mention_masked_watchpoint; | |
14873 | ops->print_recreate = print_recreate_masked_watchpoint; | |
14874 | ||
14875 | /* Tracepoints. */ | |
14876 | ops = &tracepoint_breakpoint_ops; | |
14877 | *ops = base_breakpoint_ops; | |
14878 | ops->re_set = tracepoint_re_set; | |
14879 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
14880 | ops->print_one_detail = tracepoint_print_one_detail; | |
14881 | ops->print_mention = tracepoint_print_mention; | |
14882 | ops->print_recreate = tracepoint_print_recreate; | |
983af33b SDJ |
14883 | ops->create_sals_from_address = tracepoint_create_sals_from_address; |
14884 | ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal; | |
14885 | ops->decode_linespec = tracepoint_decode_linespec; | |
14886 | ||
14887 | /* Static tracepoints with marker (`-m'). */ | |
14888 | ops = &strace_marker_breakpoint_ops; | |
14889 | *ops = tracepoint_breakpoint_ops; | |
14890 | ops->create_sals_from_address = strace_marker_create_sals_from_address; | |
14891 | ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal; | |
14892 | ops->decode_linespec = strace_marker_decode_linespec; | |
2060206e PA |
14893 | |
14894 | /* Fork catchpoints. */ | |
14895 | ops = &catch_fork_breakpoint_ops; | |
14896 | *ops = base_breakpoint_ops; | |
14897 | ops->insert_location = insert_catch_fork; | |
14898 | ops->remove_location = remove_catch_fork; | |
14899 | ops->breakpoint_hit = breakpoint_hit_catch_fork; | |
14900 | ops->print_it = print_it_catch_fork; | |
14901 | ops->print_one = print_one_catch_fork; | |
14902 | ops->print_mention = print_mention_catch_fork; | |
14903 | ops->print_recreate = print_recreate_catch_fork; | |
14904 | ||
14905 | /* Vfork catchpoints. */ | |
14906 | ops = &catch_vfork_breakpoint_ops; | |
14907 | *ops = base_breakpoint_ops; | |
14908 | ops->insert_location = insert_catch_vfork; | |
14909 | ops->remove_location = remove_catch_vfork; | |
14910 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; | |
14911 | ops->print_it = print_it_catch_vfork; | |
14912 | ops->print_one = print_one_catch_vfork; | |
14913 | ops->print_mention = print_mention_catch_vfork; | |
14914 | ops->print_recreate = print_recreate_catch_vfork; | |
14915 | ||
14916 | /* Exec catchpoints. */ | |
14917 | ops = &catch_exec_breakpoint_ops; | |
14918 | *ops = base_breakpoint_ops; | |
14919 | ops->dtor = dtor_catch_exec; | |
14920 | ops->insert_location = insert_catch_exec; | |
14921 | ops->remove_location = remove_catch_exec; | |
14922 | ops->breakpoint_hit = breakpoint_hit_catch_exec; | |
14923 | ops->print_it = print_it_catch_exec; | |
14924 | ops->print_one = print_one_catch_exec; | |
14925 | ops->print_mention = print_mention_catch_exec; | |
14926 | ops->print_recreate = print_recreate_catch_exec; | |
14927 | ||
14928 | /* Syscall catchpoints. */ | |
14929 | ops = &catch_syscall_breakpoint_ops; | |
14930 | *ops = base_breakpoint_ops; | |
14931 | ops->dtor = dtor_catch_syscall; | |
14932 | ops->insert_location = insert_catch_syscall; | |
14933 | ops->remove_location = remove_catch_syscall; | |
14934 | ops->breakpoint_hit = breakpoint_hit_catch_syscall; | |
14935 | ops->print_it = print_it_catch_syscall; | |
14936 | ops->print_one = print_one_catch_syscall; | |
14937 | ops->print_mention = print_mention_catch_syscall; | |
14938 | ops->print_recreate = print_recreate_catch_syscall; | |
edcc5120 TT |
14939 | |
14940 | /* Solib-related catchpoints. */ | |
14941 | ops = &catch_solib_breakpoint_ops; | |
14942 | *ops = base_breakpoint_ops; | |
14943 | ops->dtor = dtor_catch_solib; | |
14944 | ops->insert_location = insert_catch_solib; | |
14945 | ops->remove_location = remove_catch_solib; | |
14946 | ops->breakpoint_hit = breakpoint_hit_catch_solib; | |
14947 | ops->check_status = check_status_catch_solib; | |
14948 | ops->print_it = print_it_catch_solib; | |
14949 | ops->print_one = print_one_catch_solib; | |
14950 | ops->print_mention = print_mention_catch_solib; | |
14951 | ops->print_recreate = print_recreate_catch_solib; | |
2060206e PA |
14952 | } |
14953 | ||
c906108c | 14954 | void |
fba45db2 | 14955 | _initialize_breakpoint (void) |
c906108c SS |
14956 | { |
14957 | struct cmd_list_element *c; | |
14958 | ||
2060206e PA |
14959 | initialize_breakpoint_ops (); |
14960 | ||
84acb35a | 14961 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
6c95b8df | 14962 | observer_attach_inferior_exit (clear_syscall_counts); |
1f3b5d1b | 14963 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 14964 | |
17450429 PP |
14965 | breakpoint_objfile_key = register_objfile_data (); |
14966 | ||
c906108c SS |
14967 | breakpoint_chain = 0; |
14968 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
14969 | before a breakpoint is set. */ | |
14970 | breakpoint_count = 0; | |
14971 | ||
1042e4c0 SS |
14972 | tracepoint_count = 0; |
14973 | ||
1bedd215 AC |
14974 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
14975 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
14976 | Usage is `ignore N COUNT'.")); | |
c906108c | 14977 | if (xdb_commands) |
c5aa993b | 14978 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 14979 | |
1bedd215 AC |
14980 | add_com ("commands", class_breakpoint, commands_command, _("\ |
14981 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
14982 | Give breakpoint number as argument after \"commands\".\n\ |
14983 | With no argument, the targeted breakpoint is the last one set.\n\ | |
14984 | The commands themselves follow starting on the next line.\n\ | |
14985 | Type a line containing \"end\" to indicate the end of them.\n\ | |
14986 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 14987 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 14988 | |
1bedd215 AC |
14989 | add_com ("condition", class_breakpoint, condition_command, _("\ |
14990 | Specify breakpoint number N to break only if COND is true.\n\ | |
c906108c | 14991 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 14992 | expression to be evaluated whenever breakpoint N is reached.")); |
c906108c | 14993 | |
1bedd215 | 14994 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 14995 | Set a temporary breakpoint.\n\ |
c906108c SS |
14996 | Like \"break\" except the breakpoint is only temporary,\n\ |
14997 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
14998 | by using \"enable delete\" on the breakpoint number.\n\ |
14999 | \n" | |
15000 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 15001 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 15002 | |
1bedd215 | 15003 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 15004 | Set a hardware assisted breakpoint.\n\ |
c906108c | 15005 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
15006 | some target hardware may not have this support.\n\ |
15007 | \n" | |
15008 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 15009 | set_cmd_completer (c, location_completer); |
c906108c | 15010 | |
1bedd215 | 15011 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 15012 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 15013 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
15014 | so it will be deleted when hit.\n\ |
15015 | \n" | |
15016 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 15017 | set_cmd_completer (c, location_completer); |
c906108c | 15018 | |
1bedd215 AC |
15019 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
15020 | Enable some breakpoints.\n\ | |
c906108c SS |
15021 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
15022 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
15023 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 15024 | With a subcommand you can enable temporarily."), |
c906108c SS |
15025 | &enablelist, "enable ", 1, &cmdlist); |
15026 | if (xdb_commands) | |
1bedd215 AC |
15027 | add_com ("ab", class_breakpoint, enable_command, _("\ |
15028 | Enable some breakpoints.\n\ | |
c906108c SS |
15029 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
15030 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
15031 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 15032 | With a subcommand you can enable temporarily.")); |
c906108c SS |
15033 | |
15034 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
15035 | ||
84951ab5 | 15036 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 15037 | Enable some breakpoints.\n\ |
c906108c SS |
15038 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
15039 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 15040 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 15041 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 15042 | |
1a966eab AC |
15043 | add_cmd ("once", no_class, enable_once_command, _("\ |
15044 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
15045 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
15046 | &enablebreaklist); |
15047 | ||
1a966eab AC |
15048 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
15049 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
15050 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
15051 | &enablebreaklist); |
15052 | ||
816338b5 SS |
15053 | add_cmd ("count", no_class, enable_count_command, _("\ |
15054 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
15055 | If a breakpoint is hit while enabled in this fashion,\n\ | |
15056 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
15057 | &enablebreaklist); | |
15058 | ||
1a966eab AC |
15059 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
15060 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
15061 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
15062 | &enablelist); |
15063 | ||
1a966eab AC |
15064 | add_cmd ("once", no_class, enable_once_command, _("\ |
15065 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
15066 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
816338b5 SS |
15067 | &enablelist); |
15068 | ||
15069 | add_cmd ("count", no_class, enable_count_command, _("\ | |
15070 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
15071 | If a breakpoint is hit while enabled in this fashion,\n\ | |
15072 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
c906108c SS |
15073 | &enablelist); |
15074 | ||
1bedd215 AC |
15075 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
15076 | Disable some breakpoints.\n\ | |
c906108c SS |
15077 | Arguments are breakpoint numbers with spaces in between.\n\ |
15078 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 15079 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
c906108c SS |
15080 | &disablelist, "disable ", 1, &cmdlist); |
15081 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
15082 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
15083 | if (xdb_commands) | |
1bedd215 AC |
15084 | add_com ("sb", class_breakpoint, disable_command, _("\ |
15085 | Disable some breakpoints.\n\ | |
c906108c SS |
15086 | Arguments are breakpoint numbers with spaces in between.\n\ |
15087 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 15088 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.")); |
c906108c | 15089 | |
1a966eab AC |
15090 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
15091 | Disable some breakpoints.\n\ | |
c906108c SS |
15092 | Arguments are breakpoint numbers with spaces in between.\n\ |
15093 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 15094 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 15095 | This command may be abbreviated \"disable\"."), |
c906108c SS |
15096 | &disablelist); |
15097 | ||
1bedd215 AC |
15098 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
15099 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
15100 | Arguments are breakpoint numbers with spaces in between.\n\ |
15101 | To delete all breakpoints, give no argument.\n\ | |
15102 | \n\ | |
15103 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 15104 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
15105 | &deletelist, "delete ", 1, &cmdlist); |
15106 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 15107 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 15108 | if (xdb_commands) |
1bedd215 AC |
15109 | add_com ("db", class_breakpoint, delete_command, _("\ |
15110 | Delete some breakpoints.\n\ | |
c906108c | 15111 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 15112 | To delete all breakpoints, give no argument.\n")); |
c906108c | 15113 | |
1a966eab AC |
15114 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
15115 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
15116 | Arguments are breakpoint numbers with spaces in between.\n\ |
15117 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 15118 | This command may be abbreviated \"delete\"."), |
c906108c SS |
15119 | &deletelist); |
15120 | ||
1bedd215 AC |
15121 | add_com ("clear", class_breakpoint, clear_command, _("\ |
15122 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
15123 | Argument may be line number, function name, or \"*\" and an address.\n\ |
15124 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
15125 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
15126 | If an address is specified, breakpoints at that address are cleared.\n\ |
15127 | \n\ | |
15128 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
15129 | is executing in.\n\ |
15130 | \n\ | |
1bedd215 | 15131 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 15132 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 15133 | |
1bedd215 | 15134 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
15135 | Set breakpoint at specified line or function.\n" |
15136 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 15137 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 15138 | |
c906108c SS |
15139 | add_com_alias ("b", "break", class_run, 1); |
15140 | add_com_alias ("br", "break", class_run, 1); | |
15141 | add_com_alias ("bre", "break", class_run, 1); | |
15142 | add_com_alias ("brea", "break", class_run, 1); | |
15143 | ||
7681d515 PM |
15144 | if (xdb_commands) |
15145 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
15146 | |
15147 | if (dbx_commands) | |
15148 | { | |
1bedd215 AC |
15149 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
15150 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
15151 | &stoplist, "stop ", 1, &cmdlist); |
15152 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 15153 | _("Break in function or address."), &stoplist); |
c5aa993b | 15154 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 15155 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
15156 | add_com ("status", class_info, breakpoints_info, _("\ |
15157 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
15158 | The \"Type\" column indicates one of:\n\ |
15159 | \tbreakpoint - normal breakpoint\n\ | |
15160 | \twatchpoint - watchpoint\n\ | |
15161 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
15162 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
15163 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
15164 | address and file/line number respectively.\n\ |
15165 | \n\ | |
15166 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15167 | are set to the address of the last breakpoint listed unless the command\n\ |
15168 | is prefixed with \"server \".\n\n\ | |
c906108c | 15169 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 15170 | breakpoint set.")); |
c906108c SS |
15171 | } |
15172 | ||
1bedd215 | 15173 | add_info ("breakpoints", breakpoints_info, _("\ |
e5a67952 | 15174 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
15175 | The \"Type\" column indicates one of:\n\ |
15176 | \tbreakpoint - normal breakpoint\n\ | |
15177 | \twatchpoint - watchpoint\n\ | |
15178 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
15179 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
15180 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
15181 | address and file/line number respectively.\n\ |
15182 | \n\ | |
15183 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15184 | are set to the address of the last breakpoint listed unless the command\n\ |
15185 | is prefixed with \"server \".\n\n\ | |
c906108c | 15186 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 15187 | breakpoint set.")); |
c906108c | 15188 | |
6b04bdb7 MS |
15189 | add_info_alias ("b", "breakpoints", 1); |
15190 | ||
c906108c | 15191 | if (xdb_commands) |
1bedd215 AC |
15192 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
15193 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
15194 | The \"Type\" column indicates one of:\n\ |
15195 | \tbreakpoint - normal breakpoint\n\ | |
15196 | \twatchpoint - watchpoint\n\ | |
15197 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
15198 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
15199 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
15200 | address and file/line number respectively.\n\ |
15201 | \n\ | |
15202 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15203 | are set to the address of the last breakpoint listed unless the command\n\ |
15204 | is prefixed with \"server \".\n\n\ | |
c906108c | 15205 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 15206 | breakpoint set.")); |
c906108c | 15207 | |
1a966eab AC |
15208 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
15209 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
15210 | The \"Type\" column indicates one of:\n\ |
15211 | \tbreakpoint - normal breakpoint\n\ | |
15212 | \twatchpoint - watchpoint\n\ | |
15213 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
15214 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
15215 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
15216 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
15217 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
15218 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
15219 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
15220 | address and file/line number respectively.\n\ |
15221 | \n\ | |
15222 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15223 | are set to the address of the last breakpoint listed unless the command\n\ |
15224 | is prefixed with \"server \".\n\n\ | |
c906108c | 15225 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 15226 | breakpoint set."), |
c906108c SS |
15227 | &maintenanceinfolist); |
15228 | ||
44feb3ce TT |
15229 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
15230 | Set catchpoints to catch events."), | |
15231 | &catch_cmdlist, "catch ", | |
15232 | 0/*allow-unknown*/, &cmdlist); | |
15233 | ||
15234 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
15235 | Set temporary catchpoints to catch events."), | |
15236 | &tcatch_cmdlist, "tcatch ", | |
15237 | 0/*allow-unknown*/, &cmdlist); | |
15238 | ||
15239 | /* Add catch and tcatch sub-commands. */ | |
15240 | add_catch_command ("catch", _("\ | |
88e7d25d | 15241 | Catch an exception, when caught."), |
44feb3ce | 15242 | catch_catch_command, |
a96d9b2e | 15243 | NULL, |
44feb3ce TT |
15244 | CATCH_PERMANENT, |
15245 | CATCH_TEMPORARY); | |
15246 | add_catch_command ("throw", _("\ | |
88e7d25d | 15247 | Catch an exception, when thrown."), |
44feb3ce | 15248 | catch_throw_command, |
a96d9b2e | 15249 | NULL, |
44feb3ce TT |
15250 | CATCH_PERMANENT, |
15251 | CATCH_TEMPORARY); | |
15252 | add_catch_command ("fork", _("Catch calls to fork."), | |
15253 | catch_fork_command_1, | |
a96d9b2e | 15254 | NULL, |
44feb3ce TT |
15255 | (void *) (uintptr_t) catch_fork_permanent, |
15256 | (void *) (uintptr_t) catch_fork_temporary); | |
15257 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
15258 | catch_fork_command_1, | |
a96d9b2e | 15259 | NULL, |
44feb3ce TT |
15260 | (void *) (uintptr_t) catch_vfork_permanent, |
15261 | (void *) (uintptr_t) catch_vfork_temporary); | |
15262 | add_catch_command ("exec", _("Catch calls to exec."), | |
15263 | catch_exec_command_1, | |
a96d9b2e SDJ |
15264 | NULL, |
15265 | CATCH_PERMANENT, | |
15266 | CATCH_TEMPORARY); | |
edcc5120 TT |
15267 | add_catch_command ("load", _("Catch loads of shared libraries.\n\ |
15268 | Usage: catch load [REGEX]\n\ | |
15269 | If REGEX is given, only stop for libraries matching the regular expression."), | |
15270 | catch_load_command_1, | |
15271 | NULL, | |
15272 | CATCH_PERMANENT, | |
15273 | CATCH_TEMPORARY); | |
15274 | add_catch_command ("unload", _("Catch unloads of shared libraries.\n\ | |
15275 | Usage: catch unload [REGEX]\n\ | |
15276 | If REGEX is given, only stop for libraries matching the regular expression."), | |
15277 | catch_unload_command_1, | |
15278 | NULL, | |
15279 | CATCH_PERMANENT, | |
15280 | CATCH_TEMPORARY); | |
a96d9b2e SDJ |
15281 | add_catch_command ("syscall", _("\ |
15282 | Catch system calls by their names and/or numbers.\n\ | |
15283 | Arguments say which system calls to catch. If no arguments\n\ | |
15284 | are given, every system call will be caught.\n\ | |
15285 | Arguments, if given, should be one or more system call names\n\ | |
15286 | (if your system supports that), or system call numbers."), | |
15287 | catch_syscall_command_1, | |
15288 | catch_syscall_completer, | |
44feb3ce TT |
15289 | CATCH_PERMANENT, |
15290 | CATCH_TEMPORARY); | |
c5aa993b | 15291 | |
1bedd215 AC |
15292 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
15293 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 15294 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 15295 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
15296 | an expression changes.\n\ |
15297 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
15298 | the memory to which it refers.")); | |
65d12d83 | 15299 | set_cmd_completer (c, expression_completer); |
c906108c | 15300 | |
1bedd215 AC |
15301 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
15302 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 15303 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 15304 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
15305 | an expression is read.\n\ |
15306 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
15307 | the memory to which it refers.")); | |
65d12d83 | 15308 | set_cmd_completer (c, expression_completer); |
c906108c | 15309 | |
1bedd215 AC |
15310 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
15311 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 15312 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 15313 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
15314 | an expression is either read or written.\n\ |
15315 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
15316 | the memory to which it refers.")); | |
65d12d83 | 15317 | set_cmd_completer (c, expression_completer); |
c906108c | 15318 | |
d77f58be | 15319 | add_info ("watchpoints", watchpoints_info, _("\ |
e5a67952 | 15320 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 15321 | |
920d2a44 AC |
15322 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
15323 | respond to changes - contrary to the description. */ | |
85c07804 AC |
15324 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
15325 | &can_use_hw_watchpoints, _("\ | |
15326 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
15327 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
15328 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
15329 | such is available. (However, any hardware watchpoints that were\n\ | |
15330 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
15331 | hardware.)"), |
15332 | NULL, | |
920d2a44 | 15333 | show_can_use_hw_watchpoints, |
85c07804 | 15334 | &setlist, &showlist); |
c906108c SS |
15335 | |
15336 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 15337 | |
1042e4c0 SS |
15338 | /* Tracepoint manipulation commands. */ |
15339 | ||
15340 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
15341 | Set a tracepoint at specified line or function.\n\ | |
15342 | \n" | |
15343 | BREAK_ARGS_HELP ("trace") "\n\ | |
15344 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
15345 | set_cmd_completer (c, location_completer); | |
15346 | ||
15347 | add_com_alias ("tp", "trace", class_alias, 0); | |
15348 | add_com_alias ("tr", "trace", class_alias, 1); | |
15349 | add_com_alias ("tra", "trace", class_alias, 1); | |
15350 | add_com_alias ("trac", "trace", class_alias, 1); | |
15351 | ||
7a697b8d SS |
15352 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
15353 | Set a fast tracepoint at specified line or function.\n\ | |
15354 | \n" | |
15355 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
15356 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
15357 | set_cmd_completer (c, location_completer); | |
15358 | ||
0fb4aa4b PA |
15359 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
15360 | Set a static tracepoint at specified line, function or marker.\n\ | |
15361 | \n\ | |
15362 | strace [LOCATION] [if CONDITION]\n\ | |
15363 | LOCATION may be a line number, function name, \"*\" and an address,\n\ | |
15364 | or -m MARKER_ID.\n\ | |
15365 | If a line number is specified, probe the marker at start of code\n\ | |
15366 | for that line. If a function is specified, probe the marker at start\n\ | |
15367 | of code for that function. If an address is specified, probe the marker\n\ | |
15368 | at that exact address. If a marker id is specified, probe the marker\n\ | |
15369 | with that name. With no LOCATION, uses current execution address of\n\ | |
15370 | the selected stack frame.\n\ | |
15371 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ | |
15372 | This collects arbitrary user data passed in the probe point call to the\n\ | |
15373 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
15374 | by printing the $_sdata variable like any other convenience variable.\n\ | |
15375 | \n\ | |
15376 | CONDITION is a boolean expression.\n\ | |
15377 | \n\ | |
d41c0fc8 PA |
15378 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
15379 | conditions are different.\n\ | |
0fb4aa4b PA |
15380 | \n\ |
15381 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
15382 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
15383 | set_cmd_completer (c, location_completer); | |
15384 | ||
1042e4c0 | 15385 | add_info ("tracepoints", tracepoints_info, _("\ |
e5a67952 | 15386 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
15387 | Convenience variable \"$tpnum\" contains the number of the\n\ |
15388 | last tracepoint set.")); | |
15389 | ||
15390 | add_info_alias ("tp", "tracepoints", 1); | |
15391 | ||
15392 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
15393 | Delete specified tracepoints.\n\ | |
15394 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
15395 | No argument means delete all tracepoints."), | |
15396 | &deletelist); | |
15397 | ||
15398 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
15399 | Disable specified tracepoints.\n\ | |
15400 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
15401 | No argument means disable all tracepoints."), | |
15402 | &disablelist); | |
15403 | deprecate_cmd (c, "disable"); | |
15404 | ||
15405 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
15406 | Enable specified tracepoints.\n\ | |
15407 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
15408 | No argument means enable all tracepoints."), | |
15409 | &enablelist); | |
15410 | deprecate_cmd (c, "enable"); | |
15411 | ||
15412 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
15413 | Set the passcount for a tracepoint.\n\ | |
15414 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
15415 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
15416 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
15417 | ||
6149aea9 PA |
15418 | add_prefix_cmd ("save", class_breakpoint, save_command, |
15419 | _("Save breakpoint definitions as a script."), | |
15420 | &save_cmdlist, "save ", | |
15421 | 0/*allow-unknown*/, &cmdlist); | |
15422 | ||
15423 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
15424 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 15425 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
15426 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
15427 | session to restore them."), | |
15428 | &save_cmdlist); | |
15429 | set_cmd_completer (c, filename_completer); | |
15430 | ||
15431 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 15432 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
15433 | Use the 'source' command in another debug session to restore them."), |
15434 | &save_cmdlist); | |
1042e4c0 SS |
15435 | set_cmd_completer (c, filename_completer); |
15436 | ||
6149aea9 PA |
15437 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
15438 | deprecate_cmd (c, "save tracepoints"); | |
15439 | ||
1bedd215 | 15440 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
15441 | Breakpoint specific settings\n\ |
15442 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 15443 | pending breakpoint behavior"), |
fa8d40ab JJ |
15444 | &breakpoint_set_cmdlist, "set breakpoint ", |
15445 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 15446 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
15447 | Breakpoint specific settings\n\ |
15448 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 15449 | pending breakpoint behavior"), |
fa8d40ab JJ |
15450 | &breakpoint_show_cmdlist, "show breakpoint ", |
15451 | 0/*allow-unknown*/, &showlist); | |
15452 | ||
7915a72c AC |
15453 | add_setshow_auto_boolean_cmd ("pending", no_class, |
15454 | &pending_break_support, _("\ | |
15455 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
15456 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
15457 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
15458 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
15459 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 15460 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 15461 | NULL, |
920d2a44 | 15462 | show_pending_break_support, |
6e1d7d6c AC |
15463 | &breakpoint_set_cmdlist, |
15464 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
15465 | |
15466 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
15467 | |
15468 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
15469 | &automatic_hardware_breakpoints, _("\ | |
15470 | Set automatic usage of hardware breakpoints."), _("\ | |
15471 | Show automatic usage of hardware breakpoints."), _("\ | |
15472 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
15473 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
15474 | a warning will be emitted for such breakpoints."), | |
15475 | NULL, | |
15476 | show_automatic_hardware_breakpoints, | |
15477 | &breakpoint_set_cmdlist, | |
15478 | &breakpoint_show_cmdlist); | |
74960c60 | 15479 | |
33e5cbd6 PA |
15480 | add_setshow_enum_cmd ("always-inserted", class_support, |
15481 | always_inserted_enums, &always_inserted_mode, _("\ | |
74960c60 VP |
15482 | Set mode for inserting breakpoints."), _("\ |
15483 | Show mode for inserting breakpoints."), _("\ | |
33e5cbd6 PA |
15484 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
15485 | resumed, and removed when execution stops. When this mode is on,\n\ | |
15486 | breakpoints are inserted immediately and removed only when the user\n\ | |
15487 | deletes the breakpoint. When this mode is auto (which is the default),\n\ | |
15488 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ | |
15489 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ | |
15490 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ | |
15491 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), | |
74960c60 VP |
15492 | NULL, |
15493 | &show_always_inserted_mode, | |
15494 | &breakpoint_set_cmdlist, | |
15495 | &breakpoint_show_cmdlist); | |
f1310107 | 15496 | |
b775012e LM |
15497 | add_setshow_enum_cmd ("condition-evaluation", class_breakpoint, |
15498 | condition_evaluation_enums, | |
15499 | &condition_evaluation_mode_1, _("\ | |
15500 | Set mode of breakpoint condition evaluation."), _("\ | |
15501 | Show mode of breakpoint condition evaluation."), _("\ | |
15502 | When this is set to \"gdb\", breakpoint conditions will be\n\ | |
15503 | evaluated on the host's side by GDB. When it is set to \"target\",\n\ | |
15504 | breakpoint conditions will be downloaded to the target (if the target\n\ | |
15505 | supports such feature) and conditions will be evaluated on the target's side.\n\ | |
15506 | If this is set to \"auto\" (default), this will be automatically set to\n\ | |
15507 | \"target\" if it supports condition evaluation, otherwise it will\n\ | |
15508 | be set to \"gdb\""), | |
15509 | &set_condition_evaluation_mode, | |
15510 | &show_condition_evaluation_mode, | |
15511 | &breakpoint_set_cmdlist, | |
15512 | &breakpoint_show_cmdlist); | |
15513 | ||
f1310107 TJB |
15514 | add_com ("break-range", class_breakpoint, break_range_command, _("\ |
15515 | Set a breakpoint for an address range.\n\ | |
15516 | break-range START-LOCATION, END-LOCATION\n\ | |
15517 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
15518 | LINENUM, for that line in the current file,\n\ | |
15519 | FILE:LINENUM, for that line in that file,\n\ | |
15520 | +OFFSET, for that number of lines after the current line\n\ | |
15521 | or the start of the range\n\ | |
15522 | FUNCTION, for the first line in that function,\n\ | |
15523 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
15524 | *ADDRESS, for the instruction at that address.\n\ | |
15525 | \n\ | |
15526 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
15527 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
15528 | range (including START-LOCATION and END-LOCATION).")); | |
15529 | ||
765dc015 | 15530 | automatic_hardware_breakpoints = 1; |
f3b1572e PA |
15531 | |
15532 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
c906108c | 15533 | } |