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" | |
edcc5120 | 67 | #include "gdb_regex.h" |
b775012e | 68 | #include "ax-gdb.h" |
c906108c | 69 | |
1042e4c0 SS |
70 | /* readline include files */ |
71 | #include "readline/readline.h" | |
72 | #include "readline/history.h" | |
73 | ||
74 | /* readline defines this. */ | |
75 | #undef savestring | |
76 | ||
034dad6f | 77 | #include "mi/mi-common.h" |
7371cf6d | 78 | #include "python/python.h" |
104c1213 | 79 | |
4a64f543 | 80 | /* Prototypes for local functions. */ |
c906108c | 81 | |
a14ed312 | 82 | static void enable_delete_command (char *, int); |
c906108c | 83 | |
a14ed312 | 84 | static void enable_once_command (char *, int); |
c906108c | 85 | |
816338b5 SS |
86 | static void enable_count_command (char *, int); |
87 | ||
a14ed312 | 88 | static void disable_command (char *, int); |
c906108c | 89 | |
a14ed312 | 90 | static void enable_command (char *, int); |
c906108c | 91 | |
95a42b64 TT |
92 | static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *, |
93 | void *), | |
94 | void *); | |
c906108c | 95 | |
a14ed312 | 96 | static void ignore_command (char *, int); |
c906108c | 97 | |
4efb68b1 | 98 | static int breakpoint_re_set_one (void *); |
c906108c | 99 | |
348d480f PA |
100 | static void breakpoint_re_set_default (struct breakpoint *); |
101 | ||
983af33b SDJ |
102 | static void create_sals_from_address_default (char **, |
103 | struct linespec_result *, | |
104 | enum bptype, char *, | |
105 | char **); | |
106 | ||
107 | static void create_breakpoints_sal_default (struct gdbarch *, | |
108 | struct linespec_result *, | |
109 | struct linespec_sals *, | |
110 | char *, enum bptype, | |
111 | enum bpdisp, int, int, | |
112 | int, | |
113 | const struct breakpoint_ops *, | |
44f238bb | 114 | int, int, int, unsigned); |
983af33b SDJ |
115 | |
116 | static void decode_linespec_default (struct breakpoint *, char **, | |
117 | struct symtabs_and_lines *); | |
118 | ||
a14ed312 | 119 | static void clear_command (char *, int); |
c906108c | 120 | |
a14ed312 | 121 | static void catch_command (char *, int); |
c906108c | 122 | |
a9634178 | 123 | static int can_use_hardware_watchpoint (struct value *); |
c906108c | 124 | |
98deb0da | 125 | static void break_command_1 (char *, int, int); |
c906108c | 126 | |
a14ed312 | 127 | static void mention (struct breakpoint *); |
c906108c | 128 | |
348d480f PA |
129 | static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *, |
130 | enum bptype, | |
c0a91b2b | 131 | const struct breakpoint_ops *); |
3742cc8b YQ |
132 | static struct bp_location *add_location_to_breakpoint (struct breakpoint *, |
133 | const struct symtab_and_line *); | |
134 | ||
4a64f543 MS |
135 | /* This function is used in gdbtk sources and thus can not be made |
136 | static. */ | |
63c252f8 | 137 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
348d480f | 138 | struct symtab_and_line, |
c0a91b2b TT |
139 | enum bptype, |
140 | const struct breakpoint_ops *); | |
c906108c | 141 | |
06edf0c0 PA |
142 | static struct breakpoint * |
143 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
144 | enum bptype type, | |
c0a91b2b | 145 | const struct breakpoint_ops *ops); |
06edf0c0 | 146 | |
76897487 KB |
147 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
148 | ||
a6d9a66e UW |
149 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
150 | CORE_ADDR bpaddr, | |
88f7da05 | 151 | enum bptype bptype); |
76897487 | 152 | |
6c95b8df PA |
153 | static void describe_other_breakpoints (struct gdbarch *, |
154 | struct program_space *, CORE_ADDR, | |
5af949e3 | 155 | struct obj_section *, int); |
c906108c | 156 | |
6c95b8df PA |
157 | static int breakpoint_address_match (struct address_space *aspace1, |
158 | CORE_ADDR addr1, | |
159 | struct address_space *aspace2, | |
160 | CORE_ADDR addr2); | |
161 | ||
85d721b8 PA |
162 | static int watchpoint_locations_match (struct bp_location *loc1, |
163 | struct bp_location *loc2); | |
164 | ||
f1310107 TJB |
165 | static int breakpoint_location_address_match (struct bp_location *bl, |
166 | struct address_space *aspace, | |
167 | CORE_ADDR addr); | |
168 | ||
a14ed312 | 169 | static void breakpoints_info (char *, int); |
c906108c | 170 | |
d77f58be SS |
171 | static void watchpoints_info (char *, int); |
172 | ||
e5a67952 MS |
173 | static int breakpoint_1 (char *, int, |
174 | int (*) (const struct breakpoint *)); | |
c906108c | 175 | |
4efb68b1 | 176 | static int breakpoint_cond_eval (void *); |
c906108c | 177 | |
4efb68b1 | 178 | static void cleanup_executing_breakpoints (void *); |
c906108c | 179 | |
a14ed312 | 180 | static void commands_command (char *, int); |
c906108c | 181 | |
a14ed312 | 182 | static void condition_command (char *, int); |
c906108c | 183 | |
c5aa993b JM |
184 | typedef enum |
185 | { | |
186 | mark_inserted, | |
187 | mark_uninserted | |
188 | } | |
189 | insertion_state_t; | |
c906108c | 190 | |
0bde7532 | 191 | static int remove_breakpoint (struct bp_location *, insertion_state_t); |
6c95b8df | 192 | static int remove_breakpoint_1 (struct bp_location *, insertion_state_t); |
c906108c | 193 | |
e514a9d6 | 194 | static enum print_stop_action print_bp_stop_message (bpstat bs); |
c906108c | 195 | |
4efb68b1 | 196 | static int watchpoint_check (void *); |
c906108c | 197 | |
a14ed312 | 198 | static void maintenance_info_breakpoints (char *, int); |
c906108c | 199 | |
a14ed312 | 200 | static int hw_breakpoint_used_count (void); |
c906108c | 201 | |
a1398e0c PA |
202 | static int hw_watchpoint_use_count (struct breakpoint *); |
203 | ||
204 | static int hw_watchpoint_used_count_others (struct breakpoint *except, | |
205 | enum bptype type, | |
206 | int *other_type_used); | |
c906108c | 207 | |
a14ed312 | 208 | static void hbreak_command (char *, int); |
c906108c | 209 | |
a14ed312 | 210 | static void thbreak_command (char *, int); |
c906108c | 211 | |
816338b5 SS |
212 | static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp, |
213 | int count); | |
c906108c | 214 | |
a14ed312 | 215 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 216 | |
a14ed312 | 217 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 218 | |
a14ed312 | 219 | static void stopat_command (char *arg, int from_tty); |
7a292a7a | 220 | |
a14ed312 | 221 | static char *ep_parse_optional_if_clause (char **arg); |
7a292a7a | 222 | |
d85310f7 MS |
223 | static void catch_exception_command_1 (enum exception_event_kind ex_event, |
224 | char *arg, int tempflag, int from_tty); | |
7a292a7a | 225 | |
a14ed312 | 226 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 227 | |
d03285ec UW |
228 | static void detach_single_step_breakpoints (void); |
229 | ||
6c95b8df PA |
230 | static int single_step_breakpoint_inserted_here_p (struct address_space *, |
231 | CORE_ADDR pc); | |
1aafd4da | 232 | |
fe3f5fa8 | 233 | static void free_bp_location (struct bp_location *loc); |
f431efe5 PA |
234 | static void incref_bp_location (struct bp_location *loc); |
235 | static void decref_bp_location (struct bp_location **loc); | |
fe3f5fa8 | 236 | |
39d61571 | 237 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 238 | |
b60e7edf | 239 | static void update_global_location_list (int); |
a5606eee | 240 | |
b60e7edf | 241 | static void update_global_location_list_nothrow (int); |
74960c60 | 242 | |
d77f58be | 243 | static int is_hardware_watchpoint (const struct breakpoint *bpt); |
74960c60 VP |
244 | |
245 | static void insert_breakpoint_locations (void); | |
a5606eee | 246 | |
a96d9b2e SDJ |
247 | static int syscall_catchpoint_p (struct breakpoint *b); |
248 | ||
1042e4c0 SS |
249 | static void tracepoints_info (char *, int); |
250 | ||
251 | static void delete_trace_command (char *, int); | |
252 | ||
253 | static void enable_trace_command (char *, int); | |
254 | ||
255 | static void disable_trace_command (char *, int); | |
256 | ||
257 | static void trace_pass_command (char *, int); | |
258 | ||
9c06b0b4 TJB |
259 | static int is_masked_watchpoint (const struct breakpoint *b); |
260 | ||
b775012e LM |
261 | static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address); |
262 | ||
983af33b SDJ |
263 | /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero |
264 | otherwise. */ | |
265 | ||
266 | static int strace_marker_p (struct breakpoint *b); | |
0fb4aa4b | 267 | |
edcc5120 TT |
268 | static void init_catchpoint (struct breakpoint *b, |
269 | struct gdbarch *gdbarch, int tempflag, | |
270 | char *cond_string, | |
271 | const struct breakpoint_ops *ops); | |
272 | ||
2060206e PA |
273 | /* The abstract base class all breakpoint_ops structures inherit |
274 | from. */ | |
275 | static struct breakpoint_ops base_breakpoint_ops; | |
276 | ||
277 | /* The breakpoint_ops structure to be inherited by all breakpoint_ops | |
278 | that are implemented on top of software or hardware breakpoints | |
279 | (user breakpoints, internal and momentary breakpoints, etc.). */ | |
280 | static struct breakpoint_ops bkpt_base_breakpoint_ops; | |
281 | ||
282 | /* Internal breakpoints class type. */ | |
06edf0c0 | 283 | static struct breakpoint_ops internal_breakpoint_ops; |
2060206e PA |
284 | |
285 | /* Momentary breakpoints class type. */ | |
06edf0c0 PA |
286 | static struct breakpoint_ops momentary_breakpoint_ops; |
287 | ||
2060206e PA |
288 | /* The breakpoint_ops structure to be used in regular user created |
289 | breakpoints. */ | |
290 | struct breakpoint_ops bkpt_breakpoint_ops; | |
291 | ||
5cea2a26 PA |
292 | /* A reference-counted struct command_line. This lets multiple |
293 | breakpoints share a single command list. */ | |
294 | struct counted_command_line | |
295 | { | |
296 | /* The reference count. */ | |
297 | int refc; | |
298 | ||
299 | /* The command list. */ | |
300 | struct command_line *commands; | |
301 | }; | |
302 | ||
303 | struct command_line * | |
304 | breakpoint_commands (struct breakpoint *b) | |
305 | { | |
306 | return b->commands ? b->commands->commands : NULL; | |
307 | } | |
3daf8fe5 | 308 | |
f3b1572e PA |
309 | /* Flag indicating that a command has proceeded the inferior past the |
310 | current breakpoint. */ | |
311 | ||
312 | static int breakpoint_proceeded; | |
313 | ||
956a9fb9 | 314 | const char * |
2cec12e5 AR |
315 | bpdisp_text (enum bpdisp disp) |
316 | { | |
4a64f543 MS |
317 | /* NOTE: the following values are a part of MI protocol and |
318 | represent values of 'disp' field returned when inferior stops at | |
319 | a breakpoint. */ | |
bc043ef3 | 320 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
cc59ec59 | 321 | |
2cec12e5 AR |
322 | return bpdisps[(int) disp]; |
323 | } | |
c906108c | 324 | |
4a64f543 | 325 | /* Prototypes for exported functions. */ |
c906108c | 326 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
4a64f543 | 327 | if such is available. */ |
c906108c SS |
328 | static int can_use_hw_watchpoints; |
329 | ||
920d2a44 AC |
330 | static void |
331 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
332 | struct cmd_list_element *c, | |
333 | const char *value) | |
334 | { | |
3e43a32a MS |
335 | fprintf_filtered (file, |
336 | _("Debugger's willingness to use " | |
337 | "watchpoint hardware is %s.\n"), | |
920d2a44 AC |
338 | value); |
339 | } | |
340 | ||
fa8d40ab JJ |
341 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
342 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
4a64f543 | 343 | for unrecognized breakpoint locations. |
fa8d40ab JJ |
344 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
345 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
346 | static void |
347 | show_pending_break_support (struct ui_file *file, int from_tty, | |
348 | struct cmd_list_element *c, | |
349 | const char *value) | |
350 | { | |
3e43a32a MS |
351 | fprintf_filtered (file, |
352 | _("Debugger's behavior regarding " | |
353 | "pending breakpoints is %s.\n"), | |
920d2a44 AC |
354 | value); |
355 | } | |
fa8d40ab | 356 | |
765dc015 | 357 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
4a64f543 | 358 | set with "break" but falling in read-only memory. |
765dc015 VP |
359 | If 0, gdb will warn about such breakpoints, but won't automatically |
360 | use hardware breakpoints. */ | |
361 | static int automatic_hardware_breakpoints; | |
362 | static void | |
363 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
364 | struct cmd_list_element *c, | |
365 | const char *value) | |
366 | { | |
3e43a32a MS |
367 | fprintf_filtered (file, |
368 | _("Automatic usage of hardware breakpoints is %s.\n"), | |
765dc015 VP |
369 | value); |
370 | } | |
371 | ||
33e5cbd6 PA |
372 | /* If on, gdb will keep breakpoints inserted even as inferior is |
373 | stopped, and immediately insert any new breakpoints. If off, gdb | |
374 | will insert breakpoints into inferior only when resuming it, and | |
375 | will remove breakpoints upon stop. If auto, GDB will behave as ON | |
376 | if in non-stop mode, and as OFF if all-stop mode.*/ | |
377 | ||
378 | static const char always_inserted_auto[] = "auto"; | |
379 | static const char always_inserted_on[] = "on"; | |
380 | static const char always_inserted_off[] = "off"; | |
40478521 | 381 | static const char *const always_inserted_enums[] = { |
33e5cbd6 PA |
382 | always_inserted_auto, |
383 | always_inserted_off, | |
384 | always_inserted_on, | |
385 | NULL | |
386 | }; | |
387 | static const char *always_inserted_mode = always_inserted_auto; | |
388 | static void | |
74960c60 | 389 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 390 | struct cmd_list_element *c, const char *value) |
74960c60 | 391 | { |
33e5cbd6 | 392 | if (always_inserted_mode == always_inserted_auto) |
3e43a32a MS |
393 | fprintf_filtered (file, |
394 | _("Always inserted breakpoint " | |
395 | "mode is %s (currently %s).\n"), | |
33e5cbd6 PA |
396 | value, |
397 | breakpoints_always_inserted_mode () ? "on" : "off"); | |
398 | else | |
3e43a32a MS |
399 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), |
400 | value); | |
74960c60 VP |
401 | } |
402 | ||
33e5cbd6 PA |
403 | int |
404 | breakpoints_always_inserted_mode (void) | |
405 | { | |
20388dd6 YQ |
406 | return (always_inserted_mode == always_inserted_on |
407 | || (always_inserted_mode == always_inserted_auto && non_stop)); | |
33e5cbd6 | 408 | } |
765dc015 | 409 | |
b775012e LM |
410 | static const char condition_evaluation_both[] = "host or target"; |
411 | ||
412 | /* Modes for breakpoint condition evaluation. */ | |
413 | static const char condition_evaluation_auto[] = "auto"; | |
414 | static const char condition_evaluation_host[] = "host"; | |
415 | static const char condition_evaluation_target[] = "target"; | |
416 | static const char *const condition_evaluation_enums[] = { | |
417 | condition_evaluation_auto, | |
418 | condition_evaluation_host, | |
419 | condition_evaluation_target, | |
420 | NULL | |
421 | }; | |
422 | ||
423 | /* Global that holds the current mode for breakpoint condition evaluation. */ | |
424 | static const char *condition_evaluation_mode_1 = condition_evaluation_auto; | |
425 | ||
426 | /* Global that we use to display information to the user (gets its value from | |
427 | condition_evaluation_mode_1. */ | |
428 | static const char *condition_evaluation_mode = condition_evaluation_auto; | |
429 | ||
430 | /* Translate a condition evaluation mode MODE into either "host" | |
431 | or "target". This is used mostly to translate from "auto" to the | |
432 | real setting that is being used. It returns the translated | |
433 | evaluation mode. */ | |
434 | ||
435 | static const char * | |
436 | translate_condition_evaluation_mode (const char *mode) | |
437 | { | |
438 | if (mode == condition_evaluation_auto) | |
439 | { | |
440 | if (target_supports_evaluation_of_breakpoint_conditions ()) | |
441 | return condition_evaluation_target; | |
442 | else | |
443 | return condition_evaluation_host; | |
444 | } | |
445 | else | |
446 | return mode; | |
447 | } | |
448 | ||
449 | /* Discovers what condition_evaluation_auto translates to. */ | |
450 | ||
451 | static const char * | |
452 | breakpoint_condition_evaluation_mode (void) | |
453 | { | |
454 | return translate_condition_evaluation_mode (condition_evaluation_mode); | |
455 | } | |
456 | ||
457 | /* Return true if GDB should evaluate breakpoint conditions or false | |
458 | otherwise. */ | |
459 | ||
460 | static int | |
461 | gdb_evaluates_breakpoint_condition_p (void) | |
462 | { | |
463 | const char *mode = breakpoint_condition_evaluation_mode (); | |
464 | ||
465 | return (mode == condition_evaluation_host); | |
466 | } | |
467 | ||
a14ed312 | 468 | void _initialize_breakpoint (void); |
c906108c | 469 | |
c906108c SS |
470 | /* Are we executing breakpoint commands? */ |
471 | static int executing_breakpoint_commands; | |
472 | ||
c02f5703 MS |
473 | /* Are overlay event breakpoints enabled? */ |
474 | static int overlay_events_enabled; | |
475 | ||
e09342b5 TJB |
476 | /* See description in breakpoint.h. */ |
477 | int target_exact_watchpoints = 0; | |
478 | ||
c906108c | 479 | /* Walk the following statement or block through all breakpoints. |
e5dd4106 | 480 | ALL_BREAKPOINTS_SAFE does so even if the statement deletes the |
4a64f543 | 481 | current breakpoint. */ |
c906108c | 482 | |
5c44784c | 483 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 484 | |
5c44784c JM |
485 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
486 | for (B = breakpoint_chain; \ | |
487 | B ? (TMP=B->next, 1): 0; \ | |
488 | B = TMP) | |
c906108c | 489 | |
4a64f543 MS |
490 | /* Similar iterator for the low-level breakpoints. SAFE variant is |
491 | not provided so update_global_location_list must not be called | |
492 | while executing the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 493 | |
876fa593 JK |
494 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
495 | for (BP_TMP = bp_location; \ | |
496 | BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \ | |
497 | BP_TMP++) | |
7cc221ef | 498 | |
b775012e LM |
499 | /* Iterates through locations with address ADDRESS for the currently selected |
500 | program space. BP_LOCP_TMP points to each object. BP_LOCP_START points | |
501 | to where the loop should start from. | |
502 | If BP_LOCP_START is a NULL pointer, the macro automatically seeks the | |
503 | appropriate location to start with. */ | |
504 | ||
505 | #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \ | |
506 | for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \ | |
507 | BP_LOCP_TMP = BP_LOCP_START; \ | |
508 | BP_LOCP_START \ | |
509 | && (BP_LOCP_TMP < bp_location + bp_location_count \ | |
510 | && (*BP_LOCP_TMP)->address == ADDRESS); \ | |
511 | BP_LOCP_TMP++) | |
512 | ||
1042e4c0 SS |
513 | /* Iterator for tracepoints only. */ |
514 | ||
515 | #define ALL_TRACEPOINTS(B) \ | |
516 | for (B = breakpoint_chain; B; B = B->next) \ | |
d77f58be | 517 | if (is_tracepoint (B)) |
1042e4c0 | 518 | |
7cc221ef | 519 | /* Chains of all breakpoints defined. */ |
c906108c SS |
520 | |
521 | struct breakpoint *breakpoint_chain; | |
522 | ||
876fa593 JK |
523 | /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */ |
524 | ||
525 | static struct bp_location **bp_location; | |
526 | ||
527 | /* Number of elements of BP_LOCATION. */ | |
528 | ||
529 | static unsigned bp_location_count; | |
530 | ||
4a64f543 MS |
531 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
532 | ADDRESS for the current elements of BP_LOCATION which get a valid | |
533 | result from bp_location_has_shadow. You can use it for roughly | |
534 | limiting the subrange of BP_LOCATION to scan for shadow bytes for | |
535 | an address you need to read. */ | |
876fa593 JK |
536 | |
537 | static CORE_ADDR bp_location_placed_address_before_address_max; | |
538 | ||
4a64f543 MS |
539 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
540 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of | |
541 | BP_LOCATION which get a valid result from bp_location_has_shadow. | |
542 | You can use it for roughly limiting the subrange of BP_LOCATION to | |
543 | scan for shadow bytes for an address you need to read. */ | |
876fa593 JK |
544 | |
545 | static CORE_ADDR bp_location_shadow_len_after_address_max; | |
7cc221ef | 546 | |
4a64f543 MS |
547 | /* The locations that no longer correspond to any breakpoint, unlinked |
548 | from bp_location array, but for which a hit may still be reported | |
549 | by a target. */ | |
20874c92 VP |
550 | VEC(bp_location_p) *moribund_locations = NULL; |
551 | ||
c906108c SS |
552 | /* Number of last breakpoint made. */ |
553 | ||
95a42b64 TT |
554 | static int breakpoint_count; |
555 | ||
86b17b60 PA |
556 | /* The value of `breakpoint_count' before the last command that |
557 | created breakpoints. If the last (break-like) command created more | |
558 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
559 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
560 | static int prev_breakpoint_count; | |
c906108c | 561 | |
1042e4c0 SS |
562 | /* Number of last tracepoint made. */ |
563 | ||
95a42b64 | 564 | static int tracepoint_count; |
1042e4c0 | 565 | |
6149aea9 PA |
566 | static struct cmd_list_element *breakpoint_set_cmdlist; |
567 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
9291a0cd | 568 | struct cmd_list_element *save_cmdlist; |
6149aea9 | 569 | |
468d015d JJ |
570 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
571 | static int | |
572 | breakpoint_enabled (struct breakpoint *b) | |
573 | { | |
0d381245 | 574 | return (b->enable_state == bp_enabled); |
468d015d JJ |
575 | } |
576 | ||
c906108c SS |
577 | /* Set breakpoint count to NUM. */ |
578 | ||
95a42b64 | 579 | static void |
fba45db2 | 580 | set_breakpoint_count (int num) |
c906108c | 581 | { |
86b17b60 | 582 | prev_breakpoint_count = breakpoint_count; |
c906108c | 583 | breakpoint_count = num; |
4fa62494 | 584 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
585 | } |
586 | ||
86b17b60 PA |
587 | /* Used by `start_rbreak_breakpoints' below, to record the current |
588 | breakpoint count before "rbreak" creates any breakpoint. */ | |
589 | static int rbreak_start_breakpoint_count; | |
590 | ||
95a42b64 TT |
591 | /* Called at the start an "rbreak" command to record the first |
592 | breakpoint made. */ | |
86b17b60 | 593 | |
95a42b64 TT |
594 | void |
595 | start_rbreak_breakpoints (void) | |
596 | { | |
86b17b60 | 597 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
598 | } |
599 | ||
600 | /* Called at the end of an "rbreak" command to record the last | |
601 | breakpoint made. */ | |
86b17b60 | 602 | |
95a42b64 TT |
603 | void |
604 | end_rbreak_breakpoints (void) | |
605 | { | |
86b17b60 | 606 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
607 | } |
608 | ||
4a64f543 | 609 | /* Used in run_command to zero the hit count when a new run starts. */ |
c906108c SS |
610 | |
611 | void | |
fba45db2 | 612 | clear_breakpoint_hit_counts (void) |
c906108c SS |
613 | { |
614 | struct breakpoint *b; | |
615 | ||
616 | ALL_BREAKPOINTS (b) | |
617 | b->hit_count = 0; | |
618 | } | |
619 | ||
9add0f1b TT |
620 | /* Allocate a new counted_command_line with reference count of 1. |
621 | The new structure owns COMMANDS. */ | |
622 | ||
623 | static struct counted_command_line * | |
624 | alloc_counted_command_line (struct command_line *commands) | |
625 | { | |
626 | struct counted_command_line *result | |
627 | = xmalloc (sizeof (struct counted_command_line)); | |
cc59ec59 | 628 | |
9add0f1b TT |
629 | result->refc = 1; |
630 | result->commands = commands; | |
631 | return result; | |
632 | } | |
633 | ||
634 | /* Increment reference count. This does nothing if CMD is NULL. */ | |
635 | ||
636 | static void | |
637 | incref_counted_command_line (struct counted_command_line *cmd) | |
638 | { | |
639 | if (cmd) | |
640 | ++cmd->refc; | |
641 | } | |
642 | ||
643 | /* Decrement reference count. If the reference count reaches 0, | |
644 | destroy the counted_command_line. Sets *CMDP to NULL. This does | |
645 | nothing if *CMDP is NULL. */ | |
646 | ||
647 | static void | |
648 | decref_counted_command_line (struct counted_command_line **cmdp) | |
649 | { | |
650 | if (*cmdp) | |
651 | { | |
652 | if (--(*cmdp)->refc == 0) | |
653 | { | |
654 | free_command_lines (&(*cmdp)->commands); | |
655 | xfree (*cmdp); | |
656 | } | |
657 | *cmdp = NULL; | |
658 | } | |
659 | } | |
660 | ||
661 | /* A cleanup function that calls decref_counted_command_line. */ | |
662 | ||
663 | static void | |
664 | do_cleanup_counted_command_line (void *arg) | |
665 | { | |
666 | decref_counted_command_line (arg); | |
667 | } | |
668 | ||
669 | /* Create a cleanup that calls decref_counted_command_line on the | |
670 | argument. */ | |
671 | ||
672 | static struct cleanup * | |
673 | make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp) | |
674 | { | |
675 | return make_cleanup (do_cleanup_counted_command_line, cmdp); | |
676 | } | |
677 | ||
c906108c | 678 | \f |
48cb2d85 VP |
679 | /* Return the breakpoint with the specified number, or NULL |
680 | if the number does not refer to an existing breakpoint. */ | |
681 | ||
682 | struct breakpoint * | |
683 | get_breakpoint (int num) | |
684 | { | |
685 | struct breakpoint *b; | |
686 | ||
687 | ALL_BREAKPOINTS (b) | |
688 | if (b->number == num) | |
689 | return b; | |
690 | ||
691 | return NULL; | |
692 | } | |
5c44784c | 693 | |
c906108c | 694 | \f |
adc36818 | 695 | |
b775012e LM |
696 | /* Mark locations as "conditions have changed" in case the target supports |
697 | evaluating conditions on its side. */ | |
698 | ||
699 | static void | |
700 | mark_breakpoint_modified (struct breakpoint *b) | |
701 | { | |
702 | struct bp_location *loc; | |
703 | ||
704 | /* This is only meaningful if the target is | |
705 | evaluating conditions and if the user has | |
706 | opted for condition evaluation on the target's | |
707 | side. */ | |
708 | if (gdb_evaluates_breakpoint_condition_p () | |
709 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
710 | return; | |
711 | ||
712 | if (!is_breakpoint (b)) | |
713 | return; | |
714 | ||
715 | for (loc = b->loc; loc; loc = loc->next) | |
716 | loc->condition_changed = condition_modified; | |
717 | } | |
718 | ||
719 | /* Mark location as "conditions have changed" in case the target supports | |
720 | evaluating conditions on its side. */ | |
721 | ||
722 | static void | |
723 | mark_breakpoint_location_modified (struct bp_location *loc) | |
724 | { | |
725 | /* This is only meaningful if the target is | |
726 | evaluating conditions and if the user has | |
727 | opted for condition evaluation on the target's | |
728 | side. */ | |
729 | if (gdb_evaluates_breakpoint_condition_p () | |
730 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
731 | ||
732 | return; | |
733 | ||
734 | if (!is_breakpoint (loc->owner)) | |
735 | return; | |
736 | ||
737 | loc->condition_changed = condition_modified; | |
738 | } | |
739 | ||
740 | /* Sets the condition-evaluation mode using the static global | |
741 | condition_evaluation_mode. */ | |
742 | ||
743 | static void | |
744 | set_condition_evaluation_mode (char *args, int from_tty, | |
745 | struct cmd_list_element *c) | |
746 | { | |
747 | struct breakpoint *b; | |
748 | const char *old_mode, *new_mode; | |
749 | ||
750 | if ((condition_evaluation_mode_1 == condition_evaluation_target) | |
751 | && !target_supports_evaluation_of_breakpoint_conditions ()) | |
752 | { | |
753 | condition_evaluation_mode_1 = condition_evaluation_mode; | |
754 | warning (_("Target does not support breakpoint condition evaluation.\n" | |
755 | "Using host evaluation mode instead.")); | |
756 | return; | |
757 | } | |
758 | ||
759 | new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1); | |
760 | old_mode = translate_condition_evaluation_mode (condition_evaluation_mode); | |
761 | ||
abf1152a JK |
762 | /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the |
763 | settings was "auto". */ | |
764 | condition_evaluation_mode = condition_evaluation_mode_1; | |
765 | ||
b775012e LM |
766 | /* Only update the mode if the user picked a different one. */ |
767 | if (new_mode != old_mode) | |
768 | { | |
769 | struct bp_location *loc, **loc_tmp; | |
770 | /* If the user switched to a different evaluation mode, we | |
771 | need to synch the changes with the target as follows: | |
772 | ||
773 | "host" -> "target": Send all (valid) conditions to the target. | |
774 | "target" -> "host": Remove all the conditions from the target. | |
775 | */ | |
776 | ||
b775012e LM |
777 | if (new_mode == condition_evaluation_target) |
778 | { | |
779 | /* Mark everything modified and synch conditions with the | |
780 | target. */ | |
781 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
782 | mark_breakpoint_location_modified (loc); | |
783 | } | |
784 | else | |
785 | { | |
786 | /* Manually mark non-duplicate locations to synch conditions | |
787 | with the target. We do this to remove all the conditions the | |
788 | target knows about. */ | |
789 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
790 | if (is_breakpoint (loc->owner) && loc->inserted) | |
791 | loc->needs_update = 1; | |
792 | } | |
793 | ||
794 | /* Do the update. */ | |
795 | update_global_location_list (1); | |
796 | } | |
797 | ||
798 | return; | |
799 | } | |
800 | ||
801 | /* Shows the current mode of breakpoint condition evaluation. Explicitly shows | |
802 | what "auto" is translating to. */ | |
803 | ||
804 | static void | |
805 | show_condition_evaluation_mode (struct ui_file *file, int from_tty, | |
806 | struct cmd_list_element *c, const char *value) | |
807 | { | |
808 | if (condition_evaluation_mode == condition_evaluation_auto) | |
809 | fprintf_filtered (file, | |
810 | _("Breakpoint condition evaluation " | |
811 | "mode is %s (currently %s).\n"), | |
812 | value, | |
813 | breakpoint_condition_evaluation_mode ()); | |
814 | else | |
815 | fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"), | |
816 | value); | |
817 | } | |
818 | ||
819 | /* A comparison function for bp_location AP and BP that is used by | |
820 | bsearch. This comparison function only cares about addresses, unlike | |
821 | the more general bp_location_compare function. */ | |
822 | ||
823 | static int | |
824 | bp_location_compare_addrs (const void *ap, const void *bp) | |
825 | { | |
826 | struct bp_location *a = *(void **) ap; | |
827 | struct bp_location *b = *(void **) bp; | |
828 | ||
829 | if (a->address == b->address) | |
830 | return 0; | |
831 | else | |
832 | return ((a->address > b->address) - (a->address < b->address)); | |
833 | } | |
834 | ||
835 | /* Helper function to skip all bp_locations with addresses | |
836 | less than ADDRESS. It returns the first bp_location that | |
837 | is greater than or equal to ADDRESS. If none is found, just | |
838 | return NULL. */ | |
839 | ||
840 | static struct bp_location ** | |
841 | get_first_locp_gte_addr (CORE_ADDR address) | |
842 | { | |
843 | struct bp_location dummy_loc; | |
844 | struct bp_location *dummy_locp = &dummy_loc; | |
845 | struct bp_location **locp_found = NULL; | |
846 | ||
847 | /* Initialize the dummy location's address field. */ | |
848 | memset (&dummy_loc, 0, sizeof (struct bp_location)); | |
849 | dummy_loc.address = address; | |
850 | ||
851 | /* Find a close match to the first location at ADDRESS. */ | |
852 | locp_found = bsearch (&dummy_locp, bp_location, bp_location_count, | |
853 | sizeof (struct bp_location **), | |
854 | bp_location_compare_addrs); | |
855 | ||
856 | /* Nothing was found, nothing left to do. */ | |
857 | if (locp_found == NULL) | |
858 | return NULL; | |
859 | ||
860 | /* We may have found a location that is at ADDRESS but is not the first in the | |
861 | location's list. Go backwards (if possible) and locate the first one. */ | |
862 | while ((locp_found - 1) >= bp_location | |
863 | && (*(locp_found - 1))->address == address) | |
864 | locp_found--; | |
865 | ||
866 | return locp_found; | |
867 | } | |
868 | ||
adc36818 PM |
869 | void |
870 | set_breakpoint_condition (struct breakpoint *b, char *exp, | |
871 | int from_tty) | |
872 | { | |
3a5c3e22 PA |
873 | xfree (b->cond_string); |
874 | b->cond_string = NULL; | |
adc36818 | 875 | |
3a5c3e22 | 876 | if (is_watchpoint (b)) |
adc36818 | 877 | { |
3a5c3e22 PA |
878 | struct watchpoint *w = (struct watchpoint *) b; |
879 | ||
880 | xfree (w->cond_exp); | |
881 | w->cond_exp = NULL; | |
882 | } | |
883 | else | |
884 | { | |
885 | struct bp_location *loc; | |
886 | ||
887 | for (loc = b->loc; loc; loc = loc->next) | |
888 | { | |
889 | xfree (loc->cond); | |
890 | loc->cond = NULL; | |
b775012e LM |
891 | |
892 | /* No need to free the condition agent expression | |
893 | bytecode (if we have one). We will handle this | |
894 | when we go through update_global_location_list. */ | |
3a5c3e22 | 895 | } |
adc36818 | 896 | } |
adc36818 PM |
897 | |
898 | if (*exp == 0) | |
899 | { | |
900 | if (from_tty) | |
901 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
902 | } | |
903 | else | |
904 | { | |
905 | char *arg = exp; | |
cc59ec59 | 906 | |
adc36818 PM |
907 | /* I don't know if it matters whether this is the string the user |
908 | typed in or the decompiled expression. */ | |
909 | b->cond_string = xstrdup (arg); | |
910 | b->condition_not_parsed = 0; | |
911 | ||
912 | if (is_watchpoint (b)) | |
913 | { | |
3a5c3e22 PA |
914 | struct watchpoint *w = (struct watchpoint *) b; |
915 | ||
adc36818 PM |
916 | innermost_block = NULL; |
917 | arg = exp; | |
3a5c3e22 | 918 | w->cond_exp = parse_exp_1 (&arg, 0, 0); |
adc36818 PM |
919 | if (*arg) |
920 | error (_("Junk at end of expression")); | |
3a5c3e22 | 921 | w->cond_exp_valid_block = innermost_block; |
adc36818 PM |
922 | } |
923 | else | |
924 | { | |
3a5c3e22 PA |
925 | struct bp_location *loc; |
926 | ||
adc36818 PM |
927 | for (loc = b->loc; loc; loc = loc->next) |
928 | { | |
929 | arg = exp; | |
930 | loc->cond = | |
931 | parse_exp_1 (&arg, block_for_pc (loc->address), 0); | |
932 | if (*arg) | |
933 | error (_("Junk at end of expression")); | |
934 | } | |
935 | } | |
936 | } | |
b775012e LM |
937 | mark_breakpoint_modified (b); |
938 | ||
adc36818 | 939 | breakpoints_changed (); |
8d3788bd | 940 | observer_notify_breakpoint_modified (b); |
adc36818 PM |
941 | } |
942 | ||
c906108c SS |
943 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
944 | ||
945 | static void | |
fba45db2 | 946 | condition_command (char *arg, int from_tty) |
c906108c | 947 | { |
52f0bd74 | 948 | struct breakpoint *b; |
c906108c | 949 | char *p; |
52f0bd74 | 950 | int bnum; |
c906108c SS |
951 | |
952 | if (arg == 0) | |
e2e0b3e5 | 953 | error_no_arg (_("breakpoint number")); |
c906108c SS |
954 | |
955 | p = arg; | |
956 | bnum = get_number (&p); | |
5c44784c | 957 | if (bnum == 0) |
8a3fe4f8 | 958 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
959 | |
960 | ALL_BREAKPOINTS (b) | |
961 | if (b->number == bnum) | |
2f069f6f | 962 | { |
7371cf6d PM |
963 | /* Check if this breakpoint has a Python object assigned to |
964 | it, and if it has a definition of the "stop" | |
965 | method. This method and conditions entered into GDB from | |
966 | the CLI are mutually exclusive. */ | |
967 | if (b->py_bp_object | |
968 | && gdbpy_breakpoint_has_py_cond (b->py_bp_object)) | |
969 | error (_("Cannot set a condition where a Python 'stop' " | |
970 | "method has been defined in the breakpoint.")); | |
2566ad2d | 971 | set_breakpoint_condition (b, p, from_tty); |
b775012e LM |
972 | |
973 | if (is_breakpoint (b)) | |
974 | update_global_location_list (1); | |
975 | ||
2f069f6f JB |
976 | return; |
977 | } | |
c906108c | 978 | |
8a3fe4f8 | 979 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
980 | } |
981 | ||
a7bdde9e VP |
982 | /* Check that COMMAND do not contain commands that are suitable |
983 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
984 | Throw if any such commands is found. */ |
985 | ||
a7bdde9e VP |
986 | static void |
987 | check_no_tracepoint_commands (struct command_line *commands) | |
988 | { | |
989 | struct command_line *c; | |
cc59ec59 | 990 | |
a7bdde9e VP |
991 | for (c = commands; c; c = c->next) |
992 | { | |
993 | int i; | |
994 | ||
995 | if (c->control_type == while_stepping_control) | |
3e43a32a MS |
996 | error (_("The 'while-stepping' command can " |
997 | "only be used for tracepoints")); | |
a7bdde9e VP |
998 | |
999 | for (i = 0; i < c->body_count; ++i) | |
1000 | check_no_tracepoint_commands ((c->body_list)[i]); | |
1001 | ||
1002 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 1003 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
1004 | command directly. */ |
1005 | if (strstr (c->line, "collect ") == c->line) | |
1006 | error (_("The 'collect' command can only be used for tracepoints")); | |
1007 | ||
51661e93 VP |
1008 | if (strstr (c->line, "teval ") == c->line) |
1009 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
1010 | } |
1011 | } | |
1012 | ||
d77f58be SS |
1013 | /* Encapsulate tests for different types of tracepoints. */ |
1014 | ||
d9b3f62e PA |
1015 | static int |
1016 | is_tracepoint_type (enum bptype type) | |
1017 | { | |
1018 | return (type == bp_tracepoint | |
1019 | || type == bp_fast_tracepoint | |
1020 | || type == bp_static_tracepoint); | |
1021 | } | |
1022 | ||
a7bdde9e | 1023 | int |
d77f58be | 1024 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 1025 | { |
d9b3f62e | 1026 | return is_tracepoint_type (b->type); |
a7bdde9e | 1027 | } |
d9b3f62e | 1028 | |
e5dd4106 | 1029 | /* A helper function that validates that COMMANDS are valid for a |
95a42b64 TT |
1030 | breakpoint. This function will throw an exception if a problem is |
1031 | found. */ | |
48cb2d85 | 1032 | |
95a42b64 TT |
1033 | static void |
1034 | validate_commands_for_breakpoint (struct breakpoint *b, | |
1035 | struct command_line *commands) | |
48cb2d85 | 1036 | { |
d77f58be | 1037 | if (is_tracepoint (b)) |
a7bdde9e | 1038 | { |
4a64f543 MS |
1039 | /* We need to verify that each top-level element of commands is |
1040 | valid for tracepoints, that there's at most one | |
1041 | while-stepping element, and that while-stepping's body has | |
1042 | valid tracing commands excluding nested while-stepping. */ | |
a7bdde9e VP |
1043 | struct command_line *c; |
1044 | struct command_line *while_stepping = 0; | |
1045 | for (c = commands; c; c = c->next) | |
1046 | { | |
a7bdde9e VP |
1047 | if (c->control_type == while_stepping_control) |
1048 | { | |
1049 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
1050 | error (_("The 'while-stepping' command " |
1051 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 1052 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
1053 | error (_("The 'while-stepping' command " |
1054 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
1055 | |
1056 | if (while_stepping) | |
3e43a32a MS |
1057 | error (_("The 'while-stepping' command " |
1058 | "can be used only once")); | |
a7bdde9e VP |
1059 | else |
1060 | while_stepping = c; | |
1061 | } | |
1062 | } | |
1063 | if (while_stepping) | |
1064 | { | |
1065 | struct command_line *c2; | |
1066 | ||
1067 | gdb_assert (while_stepping->body_count == 1); | |
1068 | c2 = while_stepping->body_list[0]; | |
1069 | for (; c2; c2 = c2->next) | |
1070 | { | |
a7bdde9e VP |
1071 | if (c2->control_type == while_stepping_control) |
1072 | error (_("The 'while-stepping' command cannot be nested")); | |
1073 | } | |
1074 | } | |
1075 | } | |
1076 | else | |
1077 | { | |
1078 | check_no_tracepoint_commands (commands); | |
1079 | } | |
95a42b64 TT |
1080 | } |
1081 | ||
0fb4aa4b PA |
1082 | /* Return a vector of all the static tracepoints set at ADDR. The |
1083 | caller is responsible for releasing the vector. */ | |
1084 | ||
1085 | VEC(breakpoint_p) * | |
1086 | static_tracepoints_here (CORE_ADDR addr) | |
1087 | { | |
1088 | struct breakpoint *b; | |
1089 | VEC(breakpoint_p) *found = 0; | |
1090 | struct bp_location *loc; | |
1091 | ||
1092 | ALL_BREAKPOINTS (b) | |
1093 | if (b->type == bp_static_tracepoint) | |
1094 | { | |
1095 | for (loc = b->loc; loc; loc = loc->next) | |
1096 | if (loc->address == addr) | |
1097 | VEC_safe_push(breakpoint_p, found, b); | |
1098 | } | |
1099 | ||
1100 | return found; | |
1101 | } | |
1102 | ||
95a42b64 | 1103 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 1104 | validate that only allowed commands are included. */ |
95a42b64 TT |
1105 | |
1106 | void | |
4a64f543 MS |
1107 | breakpoint_set_commands (struct breakpoint *b, |
1108 | struct command_line *commands) | |
95a42b64 TT |
1109 | { |
1110 | validate_commands_for_breakpoint (b, commands); | |
a7bdde9e | 1111 | |
9add0f1b TT |
1112 | decref_counted_command_line (&b->commands); |
1113 | b->commands = alloc_counted_command_line (commands); | |
48cb2d85 | 1114 | breakpoints_changed (); |
8d3788bd | 1115 | observer_notify_breakpoint_modified (b); |
48cb2d85 VP |
1116 | } |
1117 | ||
45a43567 TT |
1118 | /* Set the internal `silent' flag on the breakpoint. Note that this |
1119 | is not the same as the "silent" that may appear in the breakpoint's | |
1120 | commands. */ | |
1121 | ||
1122 | void | |
1123 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
1124 | { | |
1125 | int old_silent = b->silent; | |
1126 | ||
1127 | b->silent = silent; | |
1128 | if (old_silent != silent) | |
8d3788bd | 1129 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1130 | } |
1131 | ||
1132 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
1133 | breakpoint work for any thread. */ | |
1134 | ||
1135 | void | |
1136 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
1137 | { | |
1138 | int old_thread = b->thread; | |
1139 | ||
1140 | b->thread = thread; | |
1141 | if (old_thread != thread) | |
8d3788bd | 1142 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1143 | } |
1144 | ||
1145 | /* Set the task for this breakpoint. If TASK is 0, make the | |
1146 | breakpoint work for any task. */ | |
1147 | ||
1148 | void | |
1149 | breakpoint_set_task (struct breakpoint *b, int task) | |
1150 | { | |
1151 | int old_task = b->task; | |
1152 | ||
1153 | b->task = task; | |
1154 | if (old_task != task) | |
8d3788bd | 1155 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1156 | } |
1157 | ||
95a42b64 TT |
1158 | void |
1159 | check_tracepoint_command (char *line, void *closure) | |
a7bdde9e VP |
1160 | { |
1161 | struct breakpoint *b = closure; | |
cc59ec59 | 1162 | |
a7bdde9e VP |
1163 | validate_actionline (&line, b); |
1164 | } | |
1165 | ||
95a42b64 TT |
1166 | /* A structure used to pass information through |
1167 | map_breakpoint_numbers. */ | |
1168 | ||
1169 | struct commands_info | |
1170 | { | |
1171 | /* True if the command was typed at a tty. */ | |
1172 | int from_tty; | |
86b17b60 PA |
1173 | |
1174 | /* The breakpoint range spec. */ | |
1175 | char *arg; | |
1176 | ||
95a42b64 TT |
1177 | /* Non-NULL if the body of the commands are being read from this |
1178 | already-parsed command. */ | |
1179 | struct command_line *control; | |
86b17b60 | 1180 | |
95a42b64 TT |
1181 | /* The command lines read from the user, or NULL if they have not |
1182 | yet been read. */ | |
1183 | struct counted_command_line *cmd; | |
1184 | }; | |
1185 | ||
1186 | /* A callback for map_breakpoint_numbers that sets the commands for | |
1187 | commands_command. */ | |
1188 | ||
c906108c | 1189 | static void |
95a42b64 | 1190 | do_map_commands_command (struct breakpoint *b, void *data) |
c906108c | 1191 | { |
95a42b64 | 1192 | struct commands_info *info = data; |
c906108c | 1193 | |
95a42b64 TT |
1194 | if (info->cmd == NULL) |
1195 | { | |
1196 | struct command_line *l; | |
5c44784c | 1197 | |
95a42b64 TT |
1198 | if (info->control != NULL) |
1199 | l = copy_command_lines (info->control->body_list[0]); | |
1200 | else | |
86b17b60 PA |
1201 | { |
1202 | struct cleanup *old_chain; | |
1203 | char *str; | |
c5aa993b | 1204 | |
3e43a32a MS |
1205 | str = xstrprintf (_("Type commands for breakpoint(s) " |
1206 | "%s, one per line."), | |
86b17b60 PA |
1207 | info->arg); |
1208 | ||
1209 | old_chain = make_cleanup (xfree, str); | |
1210 | ||
1211 | l = read_command_lines (str, | |
1212 | info->from_tty, 1, | |
d77f58be | 1213 | (is_tracepoint (b) |
86b17b60 PA |
1214 | ? check_tracepoint_command : 0), |
1215 | b); | |
1216 | ||
1217 | do_cleanups (old_chain); | |
1218 | } | |
a7bdde9e | 1219 | |
95a42b64 TT |
1220 | info->cmd = alloc_counted_command_line (l); |
1221 | } | |
1222 | ||
1223 | /* If a breakpoint was on the list more than once, we don't need to | |
1224 | do anything. */ | |
1225 | if (b->commands != info->cmd) | |
1226 | { | |
1227 | validate_commands_for_breakpoint (b, info->cmd->commands); | |
1228 | incref_counted_command_line (info->cmd); | |
1229 | decref_counted_command_line (&b->commands); | |
1230 | b->commands = info->cmd; | |
1231 | breakpoints_changed (); | |
8d3788bd | 1232 | observer_notify_breakpoint_modified (b); |
c5aa993b | 1233 | } |
95a42b64 TT |
1234 | } |
1235 | ||
1236 | static void | |
4a64f543 MS |
1237 | commands_command_1 (char *arg, int from_tty, |
1238 | struct command_line *control) | |
95a42b64 TT |
1239 | { |
1240 | struct cleanup *cleanups; | |
1241 | struct commands_info info; | |
1242 | ||
1243 | info.from_tty = from_tty; | |
1244 | info.control = control; | |
1245 | info.cmd = NULL; | |
1246 | /* If we read command lines from the user, then `info' will hold an | |
1247 | extra reference to the commands that we must clean up. */ | |
1248 | cleanups = make_cleanup_decref_counted_command_line (&info.cmd); | |
1249 | ||
1250 | if (arg == NULL || !*arg) | |
1251 | { | |
86b17b60 | 1252 | if (breakpoint_count - prev_breakpoint_count > 1) |
4a64f543 MS |
1253 | arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1, |
1254 | breakpoint_count); | |
95a42b64 TT |
1255 | else if (breakpoint_count > 0) |
1256 | arg = xstrprintf ("%d", breakpoint_count); | |
86b17b60 PA |
1257 | else |
1258 | { | |
1259 | /* So that we don't try to free the incoming non-NULL | |
1260 | argument in the cleanup below. Mapping breakpoint | |
1261 | numbers will fail in this case. */ | |
1262 | arg = NULL; | |
1263 | } | |
95a42b64 | 1264 | } |
9766ced4 SS |
1265 | else |
1266 | /* The command loop has some static state, so we need to preserve | |
1267 | our argument. */ | |
1268 | arg = xstrdup (arg); | |
86b17b60 PA |
1269 | |
1270 | if (arg != NULL) | |
1271 | make_cleanup (xfree, arg); | |
1272 | ||
1273 | info.arg = arg; | |
95a42b64 TT |
1274 | |
1275 | map_breakpoint_numbers (arg, do_map_commands_command, &info); | |
1276 | ||
1277 | if (info.cmd == NULL) | |
1278 | error (_("No breakpoints specified.")); | |
1279 | ||
1280 | do_cleanups (cleanups); | |
1281 | } | |
1282 | ||
1283 | static void | |
1284 | commands_command (char *arg, int from_tty) | |
1285 | { | |
1286 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1287 | } |
40c03ae8 EZ |
1288 | |
1289 | /* Like commands_command, but instead of reading the commands from | |
1290 | input stream, takes them from an already parsed command structure. | |
1291 | ||
1292 | This is used by cli-script.c to DTRT with breakpoint commands | |
1293 | that are part of if and while bodies. */ | |
1294 | enum command_control_type | |
1295 | commands_from_control_command (char *arg, struct command_line *cmd) | |
1296 | { | |
95a42b64 TT |
1297 | commands_command_1 (arg, 0, cmd); |
1298 | return simple_control; | |
40c03ae8 | 1299 | } |
876fa593 JK |
1300 | |
1301 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1302 | ||
1303 | static int | |
1304 | bp_location_has_shadow (struct bp_location *bl) | |
1305 | { | |
1306 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1307 | return 0; | |
1308 | if (!bl->inserted) | |
1309 | return 0; | |
1310 | if (bl->target_info.shadow_len == 0) | |
e5dd4106 | 1311 | /* BL isn't valid, or doesn't shadow memory. */ |
876fa593 JK |
1312 | return 0; |
1313 | return 1; | |
1314 | } | |
1315 | ||
8defab1a | 1316 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1317 | by replacing any memory breakpoints with their shadowed contents. |
1318 | ||
35c63cd8 JB |
1319 | If READBUF is not NULL, this buffer must not overlap with any of |
1320 | the breakpoint location's shadow_contents buffers. Otherwise, | |
1321 | a failed assertion internal error will be raised. | |
1322 | ||
876fa593 | 1323 | The range of shadowed area by each bp_location is: |
35df4500 TJB |
1324 | bl->address - bp_location_placed_address_before_address_max |
1325 | up to bl->address + bp_location_shadow_len_after_address_max | |
876fa593 JK |
1326 | The range we were requested to resolve shadows for is: |
1327 | memaddr ... memaddr + len | |
1328 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 TJB |
1329 | memaddr + len <= (bl->address |
1330 | - bp_location_placed_address_before_address_max) | |
876fa593 | 1331 | and: |
35df4500 | 1332 | bl->address + bp_location_shadow_len_after_address_max <= memaddr */ |
c906108c | 1333 | |
8defab1a | 1334 | void |
f0ba3972 PA |
1335 | breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, |
1336 | const gdb_byte *writebuf_org, | |
1337 | ULONGEST memaddr, LONGEST len) | |
c906108c | 1338 | { |
4a64f543 MS |
1339 | /* Left boundary, right boundary and median element of our binary |
1340 | search. */ | |
876fa593 JK |
1341 | unsigned bc_l, bc_r, bc; |
1342 | ||
4a64f543 MS |
1343 | /* Find BC_L which is a leftmost element which may affect BUF |
1344 | content. It is safe to report lower value but a failure to | |
1345 | report higher one. */ | |
876fa593 JK |
1346 | |
1347 | bc_l = 0; | |
1348 | bc_r = bp_location_count; | |
1349 | while (bc_l + 1 < bc_r) | |
1350 | { | |
35df4500 | 1351 | struct bp_location *bl; |
876fa593 JK |
1352 | |
1353 | bc = (bc_l + bc_r) / 2; | |
35df4500 | 1354 | bl = bp_location[bc]; |
876fa593 | 1355 | |
4a64f543 MS |
1356 | /* Check first BL->ADDRESS will not overflow due to the added |
1357 | constant. Then advance the left boundary only if we are sure | |
1358 | the BC element can in no way affect the BUF content (MEMADDR | |
1359 | to MEMADDR + LEN range). | |
876fa593 | 1360 | |
4a64f543 MS |
1361 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
1362 | offset so that we cannot miss a breakpoint with its shadow | |
1363 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1364 | |
35df4500 TJB |
1365 | if ((bl->address + bp_location_shadow_len_after_address_max |
1366 | >= bl->address) | |
1367 | && (bl->address + bp_location_shadow_len_after_address_max | |
1368 | <= memaddr)) | |
876fa593 JK |
1369 | bc_l = bc; |
1370 | else | |
1371 | bc_r = bc; | |
1372 | } | |
1373 | ||
128070bb PA |
1374 | /* Due to the binary search above, we need to make sure we pick the |
1375 | first location that's at BC_L's address. E.g., if there are | |
1376 | multiple locations at the same address, BC_L may end up pointing | |
1377 | at a duplicate location, and miss the "master"/"inserted" | |
1378 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1379 | B: | |
1380 | ||
1381 | L1@A, L2@A, L3@B, ... | |
1382 | ||
1383 | BC_L could end up pointing at location L2, while the "master" | |
1384 | location could be L1. Since the `loc->inserted' flag is only set | |
1385 | on "master" locations, we'd forget to restore the shadow of L1 | |
1386 | and L2. */ | |
1387 | while (bc_l > 0 | |
1388 | && bp_location[bc_l]->address == bp_location[bc_l - 1]->address) | |
1389 | bc_l--; | |
1390 | ||
876fa593 JK |
1391 | /* Now do full processing of the found relevant range of elements. */ |
1392 | ||
1393 | for (bc = bc_l; bc < bp_location_count; bc++) | |
c5aa993b | 1394 | { |
35df4500 | 1395 | struct bp_location *bl = bp_location[bc]; |
876fa593 JK |
1396 | CORE_ADDR bp_addr = 0; |
1397 | int bp_size = 0; | |
1398 | int bptoffset = 0; | |
1399 | ||
35df4500 TJB |
1400 | /* bp_location array has BL->OWNER always non-NULL. */ |
1401 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1402 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1403 | bl->owner->number); |
ffce0d52 | 1404 | |
e5dd4106 | 1405 | /* Performance optimization: any further element can no longer affect BUF |
876fa593 JK |
1406 | content. */ |
1407 | ||
35df4500 TJB |
1408 | if (bl->address >= bp_location_placed_address_before_address_max |
1409 | && memaddr + len <= (bl->address | |
1410 | - bp_location_placed_address_before_address_max)) | |
876fa593 JK |
1411 | break; |
1412 | ||
35df4500 | 1413 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1414 | continue; |
35df4500 | 1415 | if (!breakpoint_address_match (bl->target_info.placed_address_space, 0, |
6c95b8df PA |
1416 | current_program_space->aspace, 0)) |
1417 | continue; | |
1418 | ||
c5aa993b JM |
1419 | /* Addresses and length of the part of the breakpoint that |
1420 | we need to copy. */ | |
35df4500 TJB |
1421 | bp_addr = bl->target_info.placed_address; |
1422 | bp_size = bl->target_info.shadow_len; | |
8defab1a | 1423 | |
c5aa993b JM |
1424 | if (bp_addr + bp_size <= memaddr) |
1425 | /* The breakpoint is entirely before the chunk of memory we | |
1426 | are reading. */ | |
1427 | continue; | |
8defab1a | 1428 | |
c5aa993b JM |
1429 | if (bp_addr >= memaddr + len) |
1430 | /* The breakpoint is entirely after the chunk of memory we are | |
4a64f543 | 1431 | reading. */ |
c5aa993b | 1432 | continue; |
c5aa993b | 1433 | |
8defab1a DJ |
1434 | /* Offset within shadow_contents. */ |
1435 | if (bp_addr < memaddr) | |
1436 | { | |
1437 | /* Only copy the second part of the breakpoint. */ | |
1438 | bp_size -= memaddr - bp_addr; | |
1439 | bptoffset = memaddr - bp_addr; | |
1440 | bp_addr = memaddr; | |
1441 | } | |
c5aa993b | 1442 | |
8defab1a DJ |
1443 | if (bp_addr + bp_size > memaddr + len) |
1444 | { | |
1445 | /* Only copy the first part of the breakpoint. */ | |
1446 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1447 | } | |
c5aa993b | 1448 | |
f0ba3972 PA |
1449 | if (readbuf != NULL) |
1450 | { | |
35c63cd8 JB |
1451 | /* Verify that the readbuf buffer does not overlap with |
1452 | the shadow_contents buffer. */ | |
1453 | gdb_assert (bl->target_info.shadow_contents >= readbuf + len | |
1454 | || readbuf >= (bl->target_info.shadow_contents | |
1455 | + bl->target_info.shadow_len)); | |
1456 | ||
f0ba3972 PA |
1457 | /* Update the read buffer with this inserted breakpoint's |
1458 | shadow. */ | |
1459 | memcpy (readbuf + bp_addr - memaddr, | |
1460 | bl->target_info.shadow_contents + bptoffset, bp_size); | |
1461 | } | |
1462 | else | |
1463 | { | |
1464 | struct gdbarch *gdbarch = bl->gdbarch; | |
1465 | const unsigned char *bp; | |
1466 | CORE_ADDR placed_address = bl->target_info.placed_address; | |
1467 | unsigned placed_size = bl->target_info.placed_size; | |
1468 | ||
1469 | /* Update the shadow with what we want to write to memory. */ | |
1470 | memcpy (bl->target_info.shadow_contents + bptoffset, | |
1471 | writebuf_org + bp_addr - memaddr, bp_size); | |
1472 | ||
1473 | /* Determine appropriate breakpoint contents and size for this | |
1474 | address. */ | |
1475 | bp = gdbarch_breakpoint_from_pc (gdbarch, &placed_address, &placed_size); | |
1476 | ||
1477 | /* Update the final write buffer with this inserted | |
1478 | breakpoint's INSN. */ | |
1479 | memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size); | |
1480 | } | |
c5aa993b | 1481 | } |
c906108c | 1482 | } |
c906108c | 1483 | \f |
c5aa993b | 1484 | |
b775012e LM |
1485 | /* Return true if BPT is either a software breakpoint or a hardware |
1486 | breakpoint. */ | |
1487 | ||
1488 | int | |
1489 | is_breakpoint (const struct breakpoint *bpt) | |
1490 | { | |
1491 | return (bpt->type == bp_breakpoint | |
1492 | || bpt->type == bp_hardware_breakpoint); | |
1493 | } | |
1494 | ||
60e1c644 PA |
1495 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1496 | ||
a5606eee | 1497 | static int |
d77f58be | 1498 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1499 | { |
1500 | return (bpt->type == bp_hardware_watchpoint | |
1501 | || bpt->type == bp_read_watchpoint | |
1502 | || bpt->type == bp_access_watchpoint); | |
1503 | } | |
7270d8f2 | 1504 | |
60e1c644 PA |
1505 | /* Return true if BPT is of any watchpoint kind, hardware or |
1506 | software. */ | |
1507 | ||
3a5c3e22 | 1508 | int |
d77f58be | 1509 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1510 | { |
1511 | return (is_hardware_watchpoint (bpt) | |
1512 | || bpt->type == bp_watchpoint); | |
1513 | } | |
1514 | ||
3a5c3e22 PA |
1515 | /* Returns true if the current thread and its running state are safe |
1516 | to evaluate or update watchpoint B. Watchpoints on local | |
1517 | expressions need to be evaluated in the context of the thread that | |
1518 | was current when the watchpoint was created, and, that thread needs | |
1519 | to be stopped to be able to select the correct frame context. | |
1520 | Watchpoints on global expressions can be evaluated on any thread, | |
1521 | and in any state. It is presently left to the target allowing | |
1522 | memory accesses when threads are running. */ | |
f6bc2008 PA |
1523 | |
1524 | static int | |
3a5c3e22 | 1525 | watchpoint_in_thread_scope (struct watchpoint *b) |
f6bc2008 | 1526 | { |
d0d8b0c6 JK |
1527 | return (b->base.pspace == current_program_space |
1528 | && (ptid_equal (b->watchpoint_thread, null_ptid) | |
1529 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1530 | && !is_executing (inferior_ptid)))); | |
f6bc2008 PA |
1531 | } |
1532 | ||
d0fb5eae JK |
1533 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
1534 | associated bp_watchpoint_scope breakpoint. */ | |
1535 | ||
1536 | static void | |
3a5c3e22 | 1537 | watchpoint_del_at_next_stop (struct watchpoint *w) |
d0fb5eae | 1538 | { |
3a5c3e22 | 1539 | struct breakpoint *b = &w->base; |
d0fb5eae JK |
1540 | |
1541 | if (b->related_breakpoint != b) | |
1542 | { | |
1543 | gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope); | |
1544 | gdb_assert (b->related_breakpoint->related_breakpoint == b); | |
1545 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1546 | b->related_breakpoint->related_breakpoint = b->related_breakpoint; | |
1547 | b->related_breakpoint = b; | |
1548 | } | |
1549 | b->disposition = disp_del_at_next_stop; | |
1550 | } | |
1551 | ||
567e1b4e JB |
1552 | /* Assuming that B is a watchpoint: |
1553 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1554 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1555 | - Evaluate the condition if there is one, and store the result |
1556 | in b->loc->cond. | |
a5606eee VP |
1557 | - Update the list of values that must be watched in B->loc. |
1558 | ||
4a64f543 MS |
1559 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1560 | nothing. If this is local watchpoint that is out of scope, delete | |
1561 | it. | |
1562 | ||
1563 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1564 | removed + inserted on each stop here. Normal breakpoints must | |
1565 | never be removed because they might be missed by a running thread | |
1566 | when debugging in non-stop mode. On the other hand, hardware | |
1567 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1568 | to each LWP since they are stored in each LWP's hardware debug | |
1569 | registers. Therefore, such LWP must be stopped first in order to | |
1570 | be able to modify its hardware watchpoints. | |
1571 | ||
1572 | Hardware watchpoints must be reset exactly once after being | |
1573 | presented to the user. It cannot be done sooner, because it would | |
1574 | reset the data used to present the watchpoint hit to the user. And | |
1575 | it must not be done later because it could display the same single | |
1576 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1577 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1578 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1579 | not user-visible - its hit is suppressed if the memory content has | |
1580 | not changed. | |
1581 | ||
1582 | The following constraints influence the location where we can reset | |
1583 | hardware watchpoints: | |
1584 | ||
1585 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1586 | called several times when GDB stops. | |
1587 | ||
1588 | [linux] | |
1589 | * Multiple hardware watchpoints can be hit at the same time, | |
1590 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1591 | hit at a time as the reason for stopping, and all the other hits | |
1592 | are presented later, one after the other, each time the user | |
1593 | requests the execution to be resumed. Execution is not resumed | |
1594 | for the threads still having pending hit event stored in | |
1595 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1596 | the inferior on the first stop the thread hit event is kept being | |
1597 | reported from its cached value by linux_nat_stopped_data_address | |
1598 | until the real thread resume happens after the watchpoint gets | |
1599 | presented and thus its LWP_INFO->STATUS gets reset. | |
1600 | ||
1601 | Therefore the hardware watchpoint hit can get safely reset on the | |
1602 | watchpoint removal from inferior. */ | |
a79d3c27 | 1603 | |
b40ce68a | 1604 | static void |
3a5c3e22 | 1605 | update_watchpoint (struct watchpoint *b, int reparse) |
7270d8f2 | 1606 | { |
a5606eee | 1607 | int within_current_scope; |
a5606eee | 1608 | struct frame_id saved_frame_id; |
66076460 | 1609 | int frame_saved; |
a5606eee | 1610 | |
f6bc2008 PA |
1611 | /* If this is a local watchpoint, we only want to check if the |
1612 | watchpoint frame is in scope if the current thread is the thread | |
1613 | that was used to create the watchpoint. */ | |
1614 | if (!watchpoint_in_thread_scope (b)) | |
1615 | return; | |
1616 | ||
3a5c3e22 | 1617 | if (b->base.disposition == disp_del_at_next_stop) |
a5606eee VP |
1618 | return; |
1619 | ||
66076460 | 1620 | frame_saved = 0; |
a5606eee VP |
1621 | |
1622 | /* Determine if the watchpoint is within scope. */ | |
1623 | if (b->exp_valid_block == NULL) | |
1624 | within_current_scope = 1; | |
1625 | else | |
1626 | { | |
b5db5dfc UW |
1627 | struct frame_info *fi = get_current_frame (); |
1628 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1629 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1630 | ||
1631 | /* If we're in a function epilogue, unwinding may not work | |
1632 | properly, so do not attempt to recreate locations at this | |
1633 | point. See similar comments in watchpoint_check. */ | |
1634 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) | |
1635 | return; | |
66076460 DJ |
1636 | |
1637 | /* Save the current frame's ID so we can restore it after | |
1638 | evaluating the watchpoint expression on its own frame. */ | |
1639 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1640 | took a frame parameter, so that we didn't have to change the | |
1641 | selected frame. */ | |
1642 | frame_saved = 1; | |
1643 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1644 | ||
a5606eee VP |
1645 | fi = frame_find_by_id (b->watchpoint_frame); |
1646 | within_current_scope = (fi != NULL); | |
1647 | if (within_current_scope) | |
1648 | select_frame (fi); | |
1649 | } | |
1650 | ||
b5db5dfc UW |
1651 | /* We don't free locations. They are stored in the bp_location array |
1652 | and update_global_location_list will eventually delete them and | |
1653 | remove breakpoints if needed. */ | |
3a5c3e22 | 1654 | b->base.loc = NULL; |
b5db5dfc | 1655 | |
a5606eee VP |
1656 | if (within_current_scope && reparse) |
1657 | { | |
1658 | char *s; | |
d63d0675 | 1659 | |
a5606eee VP |
1660 | if (b->exp) |
1661 | { | |
1662 | xfree (b->exp); | |
1663 | b->exp = NULL; | |
1664 | } | |
d63d0675 | 1665 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
a5606eee VP |
1666 | b->exp = parse_exp_1 (&s, b->exp_valid_block, 0); |
1667 | /* If the meaning of expression itself changed, the old value is | |
1668 | no longer relevant. We don't want to report a watchpoint hit | |
1669 | to the user when the old value and the new value may actually | |
1670 | be completely different objects. */ | |
1671 | value_free (b->val); | |
fa4727a6 DJ |
1672 | b->val = NULL; |
1673 | b->val_valid = 0; | |
60e1c644 PA |
1674 | |
1675 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1676 | expression is stored in the breakpoint object, not in the | |
1677 | locations (re)created below. */ | |
3a5c3e22 | 1678 | if (b->base.cond_string != NULL) |
60e1c644 PA |
1679 | { |
1680 | if (b->cond_exp != NULL) | |
1681 | { | |
1682 | xfree (b->cond_exp); | |
1683 | b->cond_exp = NULL; | |
1684 | } | |
1685 | ||
3a5c3e22 | 1686 | s = b->base.cond_string; |
60e1c644 PA |
1687 | b->cond_exp = parse_exp_1 (&s, b->cond_exp_valid_block, 0); |
1688 | } | |
a5606eee | 1689 | } |
a5606eee VP |
1690 | |
1691 | /* If we failed to parse the expression, for example because | |
1692 | it refers to a global variable in a not-yet-loaded shared library, | |
1693 | don't try to insert watchpoint. We don't automatically delete | |
1694 | such watchpoint, though, since failure to parse expression | |
1695 | is different from out-of-scope watchpoint. */ | |
2d134ed3 PA |
1696 | if ( !target_has_execution) |
1697 | { | |
1698 | /* Without execution, memory can't change. No use to try and | |
1699 | set watchpoint locations. The watchpoint will be reset when | |
1700 | the target gains execution, through breakpoint_re_set. */ | |
1701 | } | |
1702 | else if (within_current_scope && b->exp) | |
a5606eee | 1703 | { |
0cf6dd15 | 1704 | int pc = 0; |
fa4727a6 | 1705 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1706 | struct program_space *frame_pspace; |
a5606eee | 1707 | |
0cf6dd15 | 1708 | fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain); |
a5606eee | 1709 | |
a5606eee VP |
1710 | /* Avoid setting b->val if it's already set. The meaning of |
1711 | b->val is 'the last value' user saw, and we should update | |
1712 | it only if we reported that last value to user. As it | |
9c06b0b4 TJB |
1713 | happens, the code that reports it updates b->val directly. |
1714 | We don't keep track of the memory value for masked | |
1715 | watchpoints. */ | |
3a5c3e22 | 1716 | if (!b->val_valid && !is_masked_watchpoint (&b->base)) |
fa4727a6 DJ |
1717 | { |
1718 | b->val = v; | |
1719 | b->val_valid = 1; | |
1720 | } | |
a5606eee | 1721 | |
2d134ed3 PA |
1722 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1723 | ||
a5606eee | 1724 | /* Look at each value on the value chain. */ |
9fa40276 | 1725 | for (v = val_chain; v; v = value_next (v)) |
a5606eee VP |
1726 | { |
1727 | /* If it's a memory location, and GDB actually needed | |
1728 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1729 | must watch it. If the first value returned is |
1730 | still lazy, that means an error occurred reading it; | |
1731 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1732 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1733 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1734 | { |
1735 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1736 | |
a5606eee VP |
1737 | /* We only watch structs and arrays if user asked |
1738 | for it explicitly, never if they just happen to | |
1739 | appear in the middle of some value chain. */ | |
fa4727a6 | 1740 | if (v == result |
a5606eee VP |
1741 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1742 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1743 | { | |
1744 | CORE_ADDR addr; | |
1745 | int len, type; | |
1746 | struct bp_location *loc, **tmp; | |
1747 | ||
42ae5230 | 1748 | addr = value_address (v); |
a5606eee VP |
1749 | len = TYPE_LENGTH (value_type (v)); |
1750 | type = hw_write; | |
3a5c3e22 | 1751 | if (b->base.type == bp_read_watchpoint) |
a5606eee | 1752 | type = hw_read; |
3a5c3e22 | 1753 | else if (b->base.type == bp_access_watchpoint) |
a5606eee | 1754 | type = hw_access; |
3a5c3e22 PA |
1755 | |
1756 | loc = allocate_bp_location (&b->base); | |
1757 | for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next)) | |
a5606eee VP |
1758 | ; |
1759 | *tmp = loc; | |
a6d9a66e | 1760 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1761 | |
1762 | loc->pspace = frame_pspace; | |
a5606eee VP |
1763 | loc->address = addr; |
1764 | loc->length = len; | |
1765 | loc->watchpoint_type = type; | |
1766 | } | |
1767 | } | |
9fa40276 TJB |
1768 | } |
1769 | ||
1770 | /* Change the type of breakpoint between hardware assisted or | |
1771 | an ordinary watchpoint depending on the hardware support | |
1772 | and free hardware slots. REPARSE is set when the inferior | |
1773 | is started. */ | |
a9634178 | 1774 | if (reparse) |
9fa40276 | 1775 | { |
e09342b5 | 1776 | int reg_cnt; |
9fa40276 TJB |
1777 | enum bp_loc_type loc_type; |
1778 | struct bp_location *bl; | |
a5606eee | 1779 | |
a9634178 | 1780 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
e09342b5 TJB |
1781 | |
1782 | if (reg_cnt) | |
9fa40276 TJB |
1783 | { |
1784 | int i, target_resources_ok, other_type_used; | |
a1398e0c | 1785 | enum bptype type; |
9fa40276 | 1786 | |
a9634178 TJB |
1787 | /* Use an exact watchpoint when there's only one memory region to be |
1788 | watched, and only one debug register is needed to watch it. */ | |
1789 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
1790 | ||
9fa40276 | 1791 | /* We need to determine how many resources are already |
e09342b5 TJB |
1792 | used for all other hardware watchpoints plus this one |
1793 | to see if we still have enough resources to also fit | |
a1398e0c PA |
1794 | this watchpoint in as well. */ |
1795 | ||
1796 | /* If this is a software watchpoint, we try to turn it | |
1797 | to a hardware one -- count resources as if B was of | |
1798 | hardware watchpoint type. */ | |
1799 | type = b->base.type; | |
1800 | if (type == bp_watchpoint) | |
1801 | type = bp_hardware_watchpoint; | |
1802 | ||
1803 | /* This watchpoint may or may not have been placed on | |
1804 | the list yet at this point (it won't be in the list | |
1805 | if we're trying to create it for the first time, | |
1806 | through watch_command), so always account for it | |
1807 | manually. */ | |
1808 | ||
1809 | /* Count resources used by all watchpoints except B. */ | |
1810 | i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used); | |
1811 | ||
1812 | /* Add in the resources needed for B. */ | |
1813 | i += hw_watchpoint_use_count (&b->base); | |
1814 | ||
1815 | target_resources_ok | |
1816 | = target_can_use_hardware_watchpoint (type, i, other_type_used); | |
e09342b5 | 1817 | if (target_resources_ok <= 0) |
a9634178 | 1818 | { |
3a5c3e22 | 1819 | int sw_mode = b->base.ops->works_in_software_mode (&b->base); |
9c06b0b4 TJB |
1820 | |
1821 | if (target_resources_ok == 0 && !sw_mode) | |
a9634178 TJB |
1822 | error (_("Target does not support this type of " |
1823 | "hardware watchpoint.")); | |
9c06b0b4 TJB |
1824 | else if (target_resources_ok < 0 && !sw_mode) |
1825 | error (_("There are not enough available hardware " | |
1826 | "resources for this watchpoint.")); | |
a1398e0c PA |
1827 | |
1828 | /* Downgrade to software watchpoint. */ | |
1829 | b->base.type = bp_watchpoint; | |
1830 | } | |
1831 | else | |
1832 | { | |
1833 | /* If this was a software watchpoint, we've just | |
1834 | found we have enough resources to turn it to a | |
1835 | hardware watchpoint. Otherwise, this is a | |
1836 | nop. */ | |
1837 | b->base.type = type; | |
a9634178 | 1838 | } |
9fa40276 | 1839 | } |
3a5c3e22 | 1840 | else if (!b->base.ops->works_in_software_mode (&b->base)) |
a9634178 TJB |
1841 | error (_("Expression cannot be implemented with " |
1842 | "read/access watchpoint.")); | |
9fa40276 | 1843 | else |
3a5c3e22 | 1844 | b->base.type = bp_watchpoint; |
9fa40276 | 1845 | |
3a5c3e22 | 1846 | loc_type = (b->base.type == bp_watchpoint? bp_loc_other |
9fa40276 | 1847 | : bp_loc_hardware_watchpoint); |
3a5c3e22 | 1848 | for (bl = b->base.loc; bl; bl = bl->next) |
9fa40276 TJB |
1849 | bl->loc_type = loc_type; |
1850 | } | |
1851 | ||
1852 | for (v = val_chain; v; v = next) | |
1853 | { | |
a5606eee VP |
1854 | next = value_next (v); |
1855 | if (v != b->val) | |
1856 | value_free (v); | |
1857 | } | |
1858 | ||
c7437ca6 PA |
1859 | /* If a software watchpoint is not watching any memory, then the |
1860 | above left it without any location set up. But, | |
1861 | bpstat_stop_status requires a location to be able to report | |
1862 | stops, so make sure there's at least a dummy one. */ | |
3a5c3e22 | 1863 | if (b->base.type == bp_watchpoint && b->base.loc == NULL) |
c7437ca6 | 1864 | { |
3a5c3e22 PA |
1865 | struct breakpoint *base = &b->base; |
1866 | base->loc = allocate_bp_location (base); | |
1867 | base->loc->pspace = frame_pspace; | |
1868 | base->loc->address = -1; | |
1869 | base->loc->length = -1; | |
1870 | base->loc->watchpoint_type = -1; | |
c7437ca6 | 1871 | } |
a5606eee VP |
1872 | } |
1873 | else if (!within_current_scope) | |
7270d8f2 | 1874 | { |
ac74f770 MS |
1875 | printf_filtered (_("\ |
1876 | Watchpoint %d deleted because the program has left the block\n\ | |
1877 | in which its expression is valid.\n"), | |
3a5c3e22 | 1878 | b->base.number); |
d0fb5eae | 1879 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 1880 | } |
a5606eee VP |
1881 | |
1882 | /* Restore the selected frame. */ | |
66076460 DJ |
1883 | if (frame_saved) |
1884 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
1885 | } |
1886 | ||
a5606eee | 1887 | |
74960c60 | 1888 | /* Returns 1 iff breakpoint location should be |
1e4d1764 YQ |
1889 | inserted in the inferior. We don't differentiate the type of BL's owner |
1890 | (breakpoint vs. tracepoint), although insert_location in tracepoint's | |
1891 | breakpoint_ops is not defined, because in insert_bp_location, | |
1892 | tracepoint's insert_location will not be called. */ | |
74960c60 | 1893 | static int |
35df4500 | 1894 | should_be_inserted (struct bp_location *bl) |
74960c60 | 1895 | { |
35df4500 | 1896 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
1897 | return 0; |
1898 | ||
35df4500 | 1899 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
1900 | return 0; |
1901 | ||
35df4500 | 1902 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
1903 | return 0; |
1904 | ||
f8eba3c6 TT |
1905 | if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup) |
1906 | return 0; | |
1907 | ||
56710373 PA |
1908 | /* This is set for example, when we're attached to the parent of a |
1909 | vfork, and have detached from the child. The child is running | |
1910 | free, and we expect it to do an exec or exit, at which point the | |
1911 | OS makes the parent schedulable again (and the target reports | |
1912 | that the vfork is done). Until the child is done with the shared | |
1913 | memory region, do not insert breakpoints in the parent, otherwise | |
1914 | the child could still trip on the parent's breakpoints. Since | |
1915 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 1916 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
1917 | return 0; |
1918 | ||
74960c60 VP |
1919 | return 1; |
1920 | } | |
1921 | ||
934709f0 PW |
1922 | /* Same as should_be_inserted but does the check assuming |
1923 | that the location is not duplicated. */ | |
1924 | ||
1925 | static int | |
1926 | unduplicated_should_be_inserted (struct bp_location *bl) | |
1927 | { | |
1928 | int result; | |
1929 | const int save_duplicate = bl->duplicate; | |
1930 | ||
1931 | bl->duplicate = 0; | |
1932 | result = should_be_inserted (bl); | |
1933 | bl->duplicate = save_duplicate; | |
1934 | return result; | |
1935 | } | |
1936 | ||
b775012e LM |
1937 | /* Parses a conditional described by an expression COND into an |
1938 | agent expression bytecode suitable for evaluation | |
1939 | by the bytecode interpreter. Return NULL if there was | |
1940 | any error during parsing. */ | |
1941 | ||
1942 | static struct agent_expr * | |
1943 | parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond) | |
1944 | { | |
1945 | struct agent_expr *aexpr = NULL; | |
1946 | struct cleanup *old_chain = NULL; | |
1947 | volatile struct gdb_exception ex; | |
1948 | ||
1949 | if (!cond) | |
1950 | return NULL; | |
1951 | ||
1952 | /* We don't want to stop processing, so catch any errors | |
1953 | that may show up. */ | |
1954 | TRY_CATCH (ex, RETURN_MASK_ERROR) | |
1955 | { | |
1956 | aexpr = gen_eval_for_expr (scope, cond); | |
1957 | } | |
1958 | ||
1959 | if (ex.reason < 0) | |
1960 | { | |
1961 | /* If we got here, it means the condition could not be parsed to a valid | |
1962 | bytecode expression and thus can't be evaluated on the target's side. | |
1963 | It's no use iterating through the conditions. */ | |
1964 | return NULL; | |
1965 | } | |
1966 | ||
1967 | /* We have a valid agent expression. */ | |
1968 | return aexpr; | |
1969 | } | |
1970 | ||
1971 | /* Based on location BL, create a list of breakpoint conditions to be | |
1972 | passed on to the target. If we have duplicated locations with different | |
1973 | conditions, we will add such conditions to the list. The idea is that the | |
1974 | target will evaluate the list of conditions and will only notify GDB when | |
1975 | one of them is true. */ | |
1976 | ||
1977 | static void | |
1978 | build_target_condition_list (struct bp_location *bl) | |
1979 | { | |
1980 | struct bp_location **locp = NULL, **loc2p; | |
1981 | int null_condition_or_parse_error = 0; | |
1982 | int modified = bl->needs_update; | |
1983 | struct bp_location *loc; | |
1984 | ||
1985 | /* This is only meaningful if the target is | |
1986 | evaluating conditions and if the user has | |
1987 | opted for condition evaluation on the target's | |
1988 | side. */ | |
1989 | if (gdb_evaluates_breakpoint_condition_p () | |
1990 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
1991 | return; | |
1992 | ||
1993 | /* Do a first pass to check for locations with no assigned | |
1994 | conditions or conditions that fail to parse to a valid agent expression | |
1995 | bytecode. If any of these happen, then it's no use to send conditions | |
1996 | to the target since this location will always trigger and generate a | |
1997 | response back to GDB. */ | |
1998 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
1999 | { | |
2000 | loc = (*loc2p); | |
2001 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2002 | { | |
2003 | if (modified) | |
2004 | { | |
2005 | struct agent_expr *aexpr; | |
2006 | ||
2007 | /* Re-parse the conditions since something changed. In that | |
2008 | case we already freed the condition bytecodes (see | |
2009 | force_breakpoint_reinsertion). We just | |
2010 | need to parse the condition to bytecodes again. */ | |
2011 | aexpr = parse_cond_to_aexpr (bl->address, loc->cond); | |
2012 | loc->cond_bytecode = aexpr; | |
2013 | ||
2014 | /* Check if we managed to parse the conditional expression | |
2015 | correctly. If not, we will not send this condition | |
2016 | to the target. */ | |
2017 | if (aexpr) | |
2018 | continue; | |
2019 | } | |
2020 | ||
2021 | /* If we have a NULL bytecode expression, it means something | |
2022 | went wrong or we have a null condition expression. */ | |
2023 | if (!loc->cond_bytecode) | |
2024 | { | |
2025 | null_condition_or_parse_error = 1; | |
2026 | break; | |
2027 | } | |
2028 | } | |
2029 | } | |
2030 | ||
2031 | /* If any of these happened, it means we will have to evaluate the conditions | |
2032 | for the location's address on gdb's side. It is no use keeping bytecodes | |
2033 | for all the other duplicate locations, thus we free all of them here. | |
2034 | ||
2035 | This is so we have a finer control over which locations' conditions are | |
2036 | being evaluated by GDB or the remote stub. */ | |
2037 | if (null_condition_or_parse_error) | |
2038 | { | |
2039 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2040 | { | |
2041 | loc = (*loc2p); | |
2042 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2043 | { | |
2044 | /* Only go as far as the first NULL bytecode is | |
2045 | located. */ | |
2046 | if (!loc->cond_bytecode) | |
2047 | return; | |
2048 | ||
2049 | free_agent_expr (loc->cond_bytecode); | |
2050 | loc->cond_bytecode = NULL; | |
2051 | } | |
2052 | } | |
2053 | } | |
2054 | ||
2055 | /* No NULL conditions or failed bytecode generation. Build a condition list | |
2056 | for this location's address. */ | |
2057 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2058 | { | |
2059 | loc = (*loc2p); | |
2060 | if (loc->cond | |
2061 | && is_breakpoint (loc->owner) | |
2062 | && loc->pspace->num == bl->pspace->num | |
2063 | && loc->owner->enable_state == bp_enabled | |
2064 | && loc->enabled) | |
2065 | /* Add the condition to the vector. This will be used later to send the | |
2066 | conditions to the target. */ | |
2067 | VEC_safe_push (agent_expr_p, bl->target_info.conditions, | |
2068 | loc->cond_bytecode); | |
2069 | } | |
2070 | ||
2071 | return; | |
2072 | } | |
2073 | ||
35df4500 TJB |
2074 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
2075 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
3fbb6ffa | 2076 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
c30eee59 TJB |
2077 | Returns 0 for success, 1 if the bp_location type is not supported or |
2078 | -1 for failure. | |
879bfdc2 | 2079 | |
4a64f543 MS |
2080 | NOTE drow/2003-09-09: This routine could be broken down to an |
2081 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 2082 | static int |
35df4500 | 2083 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 2084 | struct ui_file *tmp_error_stream, |
3fbb6ffa | 2085 | int *disabled_breaks, |
26bb91f3 | 2086 | int *hw_breakpoint_error) |
879bfdc2 DJ |
2087 | { |
2088 | int val = 0; | |
2089 | ||
b775012e | 2090 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2091 | return 0; |
2092 | ||
35c63cd8 JB |
2093 | /* Note we don't initialize bl->target_info, as that wipes out |
2094 | the breakpoint location's shadow_contents if the breakpoint | |
2095 | is still inserted at that location. This in turn breaks | |
2096 | target_read_memory which depends on these buffers when | |
2097 | a memory read is requested at the breakpoint location: | |
2098 | Once the target_info has been wiped, we fail to see that | |
2099 | we have a breakpoint inserted at that address and thus | |
2100 | read the breakpoint instead of returning the data saved in | |
2101 | the breakpoint location's shadow contents. */ | |
35df4500 TJB |
2102 | bl->target_info.placed_address = bl->address; |
2103 | bl->target_info.placed_address_space = bl->pspace->aspace; | |
f1310107 | 2104 | bl->target_info.length = bl->length; |
8181d85f | 2105 | |
b775012e LM |
2106 | /* When working with target-side conditions, we must pass all the conditions |
2107 | for the same breakpoint address down to the target since GDB will not | |
2108 | insert those locations. With a list of breakpoint conditions, the target | |
2109 | can decide when to stop and notify GDB. */ | |
2110 | ||
2111 | if (is_breakpoint (bl->owner)) | |
2112 | { | |
2113 | build_target_condition_list (bl); | |
2114 | /* Reset the condition modification marker. */ | |
2115 | bl->needs_update = 0; | |
2116 | } | |
2117 | ||
35df4500 TJB |
2118 | if (bl->loc_type == bp_loc_software_breakpoint |
2119 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 2120 | { |
35df4500 | 2121 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
2122 | { |
2123 | /* If the explicitly specified breakpoint type | |
2124 | is not hardware breakpoint, check the memory map to see | |
2125 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 2126 | |
765dc015 VP |
2127 | Two important cases are: |
2128 | - location type is not hardware breakpoint, memory | |
2129 | is readonly. We change the type of the location to | |
2130 | hardware breakpoint. | |
4a64f543 MS |
2131 | - location type is hardware breakpoint, memory is |
2132 | read-write. This means we've previously made the | |
2133 | location hardware one, but then the memory map changed, | |
2134 | so we undo. | |
765dc015 | 2135 | |
4a64f543 MS |
2136 | When breakpoints are removed, remove_breakpoints will use |
2137 | location types we've just set here, the only possible | |
2138 | problem is that memory map has changed during running | |
2139 | program, but it's not going to work anyway with current | |
2140 | gdb. */ | |
765dc015 | 2141 | struct mem_region *mr |
35df4500 | 2142 | = lookup_mem_region (bl->target_info.placed_address); |
765dc015 VP |
2143 | |
2144 | if (mr) | |
2145 | { | |
2146 | if (automatic_hardware_breakpoints) | |
2147 | { | |
765dc015 VP |
2148 | enum bp_loc_type new_type; |
2149 | ||
2150 | if (mr->attrib.mode != MEM_RW) | |
2151 | new_type = bp_loc_hardware_breakpoint; | |
2152 | else | |
2153 | new_type = bp_loc_software_breakpoint; | |
2154 | ||
35df4500 | 2155 | if (new_type != bl->loc_type) |
765dc015 VP |
2156 | { |
2157 | static int said = 0; | |
cc59ec59 | 2158 | |
35df4500 | 2159 | bl->loc_type = new_type; |
765dc015 VP |
2160 | if (!said) |
2161 | { | |
3e43a32a MS |
2162 | fprintf_filtered (gdb_stdout, |
2163 | _("Note: automatically using " | |
2164 | "hardware breakpoints for " | |
2165 | "read-only addresses.\n")); | |
765dc015 VP |
2166 | said = 1; |
2167 | } | |
2168 | } | |
2169 | } | |
35df4500 | 2170 | else if (bl->loc_type == bp_loc_software_breakpoint |
765dc015 | 2171 | && mr->attrib.mode != MEM_RW) |
3e43a32a MS |
2172 | warning (_("cannot set software breakpoint " |
2173 | "at readonly address %s"), | |
35df4500 | 2174 | paddress (bl->gdbarch, bl->address)); |
765dc015 VP |
2175 | } |
2176 | } | |
2177 | ||
879bfdc2 DJ |
2178 | /* First check to see if we have to handle an overlay. */ |
2179 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2180 | || bl->section == NULL |
2181 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
2182 | { |
2183 | /* No overlay handling: just set the breakpoint. */ | |
2184 | ||
348d480f | 2185 | val = bl->owner->ops->insert_location (bl); |
879bfdc2 DJ |
2186 | } |
2187 | else | |
2188 | { | |
4a64f543 | 2189 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
2190 | Shall we set a breakpoint at the LMA? */ |
2191 | if (!overlay_events_enabled) | |
2192 | { | |
2193 | /* Yes -- overlay event support is not active, | |
2194 | so we must try to set a breakpoint at the LMA. | |
2195 | This will not work for a hardware breakpoint. */ | |
35df4500 | 2196 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 2197 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 2198 | bl->owner->number); |
879bfdc2 DJ |
2199 | else |
2200 | { | |
35df4500 TJB |
2201 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
2202 | bl->section); | |
879bfdc2 | 2203 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 TJB |
2204 | bl->overlay_target_info = bl->target_info; |
2205 | bl->overlay_target_info.placed_address = addr; | |
2206 | val = target_insert_breakpoint (bl->gdbarch, | |
2207 | &bl->overlay_target_info); | |
879bfdc2 | 2208 | if (val != 0) |
99361f52 | 2209 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
2210 | "Overlay breakpoint %d " |
2211 | "failed: in ROM?\n", | |
35df4500 | 2212 | bl->owner->number); |
879bfdc2 DJ |
2213 | } |
2214 | } | |
2215 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 2216 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
2217 | { |
2218 | /* Yes. This overlay section is mapped into memory. */ | |
348d480f | 2219 | val = bl->owner->ops->insert_location (bl); |
879bfdc2 DJ |
2220 | } |
2221 | else | |
2222 | { | |
2223 | /* No. This breakpoint will not be inserted. | |
2224 | No error, but do not mark the bp as 'inserted'. */ | |
2225 | return 0; | |
2226 | } | |
2227 | } | |
2228 | ||
2229 | if (val) | |
2230 | { | |
2231 | /* Can't set the breakpoint. */ | |
35df4500 | 2232 | if (solib_name_from_address (bl->pspace, bl->address)) |
879bfdc2 | 2233 | { |
4a64f543 | 2234 | /* See also: disable_breakpoints_in_shlibs. */ |
879bfdc2 | 2235 | val = 0; |
35df4500 | 2236 | bl->shlib_disabled = 1; |
8d3788bd | 2237 | observer_notify_breakpoint_modified (bl->owner); |
3fbb6ffa TJB |
2238 | if (!*disabled_breaks) |
2239 | { | |
2240 | fprintf_unfiltered (tmp_error_stream, | |
2241 | "Cannot insert breakpoint %d.\n", | |
2242 | bl->owner->number); | |
2243 | fprintf_unfiltered (tmp_error_stream, | |
2244 | "Temporarily disabling shared " | |
2245 | "library breakpoints:\n"); | |
2246 | } | |
2247 | *disabled_breaks = 1; | |
879bfdc2 | 2248 | fprintf_unfiltered (tmp_error_stream, |
35df4500 | 2249 | "breakpoint #%d\n", bl->owner->number); |
879bfdc2 DJ |
2250 | } |
2251 | else | |
879bfdc2 | 2252 | { |
35df4500 | 2253 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 DJ |
2254 | { |
2255 | *hw_breakpoint_error = 1; | |
3e43a32a MS |
2256 | fprintf_unfiltered (tmp_error_stream, |
2257 | "Cannot insert hardware " | |
2258 | "breakpoint %d.\n", | |
35df4500 | 2259 | bl->owner->number); |
879bfdc2 DJ |
2260 | } |
2261 | else | |
2262 | { | |
2263 | fprintf_unfiltered (tmp_error_stream, | |
2264 | "Cannot insert breakpoint %d.\n", | |
35df4500 | 2265 | bl->owner->number); |
879bfdc2 DJ |
2266 | fprintf_filtered (tmp_error_stream, |
2267 | "Error accessing memory address "); | |
35df4500 | 2268 | fputs_filtered (paddress (bl->gdbarch, bl->address), |
5af949e3 | 2269 | tmp_error_stream); |
879bfdc2 DJ |
2270 | fprintf_filtered (tmp_error_stream, ": %s.\n", |
2271 | safe_strerror (val)); | |
2272 | } | |
2273 | ||
2274 | } | |
2275 | } | |
2276 | else | |
35df4500 | 2277 | bl->inserted = 1; |
879bfdc2 DJ |
2278 | |
2279 | return val; | |
2280 | } | |
2281 | ||
35df4500 | 2282 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 2283 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 2284 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 2285 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 2286 | { |
77b06cd7 TJB |
2287 | gdb_assert (bl->owner->ops != NULL |
2288 | && bl->owner->ops->insert_location != NULL); | |
2289 | ||
2290 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
2291 | |
2292 | /* If trying to set a read-watchpoint, and it turns out it's not | |
2293 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 2294 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
2295 | { |
2296 | struct bp_location *loc, **loc_temp; | |
2297 | ||
2298 | /* But don't try to insert it, if there's already another | |
2299 | hw_access location that would be considered a duplicate | |
2300 | of this one. */ | |
2301 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 2302 | if (loc != bl |
85d721b8 | 2303 | && loc->watchpoint_type == hw_access |
35df4500 | 2304 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 2305 | { |
35df4500 TJB |
2306 | bl->duplicate = 1; |
2307 | bl->inserted = 1; | |
2308 | bl->target_info = loc->target_info; | |
2309 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
2310 | val = 0; |
2311 | break; | |
2312 | } | |
2313 | ||
2314 | if (val == 1) | |
2315 | { | |
77b06cd7 TJB |
2316 | bl->watchpoint_type = hw_access; |
2317 | val = bl->owner->ops->insert_location (bl); | |
2318 | ||
2319 | if (val) | |
2320 | /* Back to the original value. */ | |
2321 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
2322 | } |
2323 | } | |
2324 | ||
35df4500 | 2325 | bl->inserted = (val == 0); |
879bfdc2 DJ |
2326 | } |
2327 | ||
35df4500 | 2328 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 2329 | { |
77b06cd7 TJB |
2330 | gdb_assert (bl->owner->ops != NULL |
2331 | && bl->owner->ops->insert_location != NULL); | |
2332 | ||
2333 | val = bl->owner->ops->insert_location (bl); | |
2334 | if (val) | |
2335 | { | |
2336 | bl->owner->enable_state = bp_disabled; | |
2337 | ||
2338 | if (val == 1) | |
2339 | warning (_("\ | |
2340 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
2341 | of catchpoint."), bl->owner->number); | |
2342 | else | |
2343 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
2344 | } | |
2345 | ||
2346 | bl->inserted = (val == 0); | |
1640b821 DJ |
2347 | |
2348 | /* We've already printed an error message if there was a problem | |
2349 | inserting this catchpoint, and we've disabled the catchpoint, | |
2350 | so just return success. */ | |
2351 | return 0; | |
879bfdc2 DJ |
2352 | } |
2353 | ||
2354 | return 0; | |
2355 | } | |
2356 | ||
6c95b8df PA |
2357 | /* This function is called when program space PSPACE is about to be |
2358 | deleted. It takes care of updating breakpoints to not reference | |
2359 | PSPACE anymore. */ | |
2360 | ||
2361 | void | |
2362 | breakpoint_program_space_exit (struct program_space *pspace) | |
2363 | { | |
2364 | struct breakpoint *b, *b_temp; | |
876fa593 | 2365 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
2366 | |
2367 | /* Remove any breakpoint that was set through this program space. */ | |
2368 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
2369 | { | |
2370 | if (b->pspace == pspace) | |
2371 | delete_breakpoint (b); | |
2372 | } | |
2373 | ||
2374 | /* Breakpoints set through other program spaces could have locations | |
2375 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 2376 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
2377 | { |
2378 | struct bp_location *tmp; | |
2379 | ||
2380 | if (loc->pspace == pspace) | |
2381 | { | |
2bdf28a0 | 2382 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
2383 | if (loc->owner->loc == loc) |
2384 | loc->owner->loc = loc->next; | |
2385 | else | |
2386 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
2387 | if (tmp->next == loc) | |
2388 | { | |
2389 | tmp->next = loc->next; | |
2390 | break; | |
2391 | } | |
2392 | } | |
2393 | } | |
2394 | ||
2395 | /* Now update the global location list to permanently delete the | |
2396 | removed locations above. */ | |
2397 | update_global_location_list (0); | |
2398 | } | |
2399 | ||
74960c60 VP |
2400 | /* Make sure all breakpoints are inserted in inferior. |
2401 | Throws exception on any error. | |
2402 | A breakpoint that is already inserted won't be inserted | |
2403 | again, so calling this function twice is safe. */ | |
2404 | void | |
2405 | insert_breakpoints (void) | |
2406 | { | |
2407 | struct breakpoint *bpt; | |
2408 | ||
2409 | ALL_BREAKPOINTS (bpt) | |
2410 | if (is_hardware_watchpoint (bpt)) | |
3a5c3e22 PA |
2411 | { |
2412 | struct watchpoint *w = (struct watchpoint *) bpt; | |
2413 | ||
2414 | update_watchpoint (w, 0 /* don't reparse. */); | |
2415 | } | |
74960c60 | 2416 | |
b60e7edf | 2417 | update_global_location_list (1); |
74960c60 | 2418 | |
c35b1492 PA |
2419 | /* update_global_location_list does not insert breakpoints when |
2420 | always_inserted_mode is not enabled. Explicitly insert them | |
2421 | now. */ | |
2422 | if (!breakpoints_always_inserted_mode ()) | |
74960c60 VP |
2423 | insert_breakpoint_locations (); |
2424 | } | |
2425 | ||
20388dd6 YQ |
2426 | /* Invoke CALLBACK for each of bp_location. */ |
2427 | ||
2428 | void | |
2429 | iterate_over_bp_locations (walk_bp_location_callback callback) | |
2430 | { | |
2431 | struct bp_location *loc, **loc_tmp; | |
2432 | ||
2433 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
2434 | { | |
2435 | callback (loc, NULL); | |
2436 | } | |
2437 | } | |
2438 | ||
b775012e LM |
2439 | /* This is used when we need to synch breakpoint conditions between GDB and the |
2440 | target. It is the case with deleting and disabling of breakpoints when using | |
2441 | always-inserted mode. */ | |
2442 | ||
2443 | static void | |
2444 | update_inserted_breakpoint_locations (void) | |
2445 | { | |
2446 | struct bp_location *bl, **blp_tmp; | |
2447 | int error_flag = 0; | |
2448 | int val = 0; | |
2449 | int disabled_breaks = 0; | |
2450 | int hw_breakpoint_error = 0; | |
2451 | ||
2452 | struct ui_file *tmp_error_stream = mem_fileopen (); | |
2453 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); | |
2454 | ||
2455 | /* Explicitly mark the warning -- this will only be printed if | |
2456 | there was an error. */ | |
2457 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
2458 | ||
2459 | save_current_space_and_thread (); | |
2460 | ||
2461 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
2462 | { | |
2463 | /* We only want to update software breakpoints and hardware | |
2464 | breakpoints. */ | |
2465 | if (!is_breakpoint (bl->owner)) | |
2466 | continue; | |
2467 | ||
2468 | /* We only want to update locations that are already inserted | |
2469 | and need updating. This is to avoid unwanted insertion during | |
2470 | deletion of breakpoints. */ | |
2471 | if (!bl->inserted || (bl->inserted && !bl->needs_update)) | |
2472 | continue; | |
2473 | ||
2474 | switch_to_program_space_and_thread (bl->pspace); | |
2475 | ||
2476 | /* For targets that support global breakpoints, there's no need | |
2477 | to select an inferior to insert breakpoint to. In fact, even | |
2478 | if we aren't attached to any process yet, we should still | |
2479 | insert breakpoints. */ | |
2480 | if (!gdbarch_has_global_breakpoints (target_gdbarch) | |
2481 | && ptid_equal (inferior_ptid, null_ptid)) | |
2482 | continue; | |
2483 | ||
2484 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, | |
2485 | &hw_breakpoint_error); | |
2486 | if (val) | |
2487 | error_flag = val; | |
2488 | } | |
2489 | ||
2490 | if (error_flag) | |
2491 | { | |
2492 | target_terminal_ours_for_output (); | |
2493 | error_stream (tmp_error_stream); | |
2494 | } | |
2495 | ||
2496 | do_cleanups (cleanups); | |
2497 | } | |
2498 | ||
c30eee59 | 2499 | /* Used when starting or continuing the program. */ |
c906108c | 2500 | |
74960c60 VP |
2501 | static void |
2502 | insert_breakpoint_locations (void) | |
c906108c | 2503 | { |
a5606eee | 2504 | struct breakpoint *bpt; |
35df4500 | 2505 | struct bp_location *bl, **blp_tmp; |
eacd795a | 2506 | int error_flag = 0; |
c906108c | 2507 | int val = 0; |
3fbb6ffa | 2508 | int disabled_breaks = 0; |
81d0cc19 | 2509 | int hw_breakpoint_error = 0; |
c906108c | 2510 | |
81d0cc19 | 2511 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 2512 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 2513 | |
81d0cc19 GS |
2514 | /* Explicitly mark the warning -- this will only be printed if |
2515 | there was an error. */ | |
2516 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
2517 | |
2518 | save_current_space_and_thread (); | |
2519 | ||
35df4500 | 2520 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 2521 | { |
b775012e | 2522 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2523 | continue; |
2524 | ||
4a64f543 MS |
2525 | /* There is no point inserting thread-specific breakpoints if |
2526 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
2527 | has BL->OWNER always non-NULL. */ | |
35df4500 TJB |
2528 | if (bl->owner->thread != -1 |
2529 | && !valid_thread_id (bl->owner->thread)) | |
f365de73 AS |
2530 | continue; |
2531 | ||
35df4500 | 2532 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
2533 | |
2534 | /* For targets that support global breakpoints, there's no need | |
2535 | to select an inferior to insert breakpoint to. In fact, even | |
2536 | if we aren't attached to any process yet, we should still | |
2537 | insert breakpoints. */ | |
2538 | if (!gdbarch_has_global_breakpoints (target_gdbarch) | |
2539 | && ptid_equal (inferior_ptid, null_ptid)) | |
2540 | continue; | |
2541 | ||
3fbb6ffa TJB |
2542 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, |
2543 | &hw_breakpoint_error); | |
879bfdc2 | 2544 | if (val) |
eacd795a | 2545 | error_flag = val; |
879bfdc2 | 2546 | } |
c906108c | 2547 | |
4a64f543 MS |
2548 | /* If we failed to insert all locations of a watchpoint, remove |
2549 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
2550 | ALL_BREAKPOINTS (bpt) |
2551 | { | |
2552 | int some_failed = 0; | |
2553 | struct bp_location *loc; | |
2554 | ||
2555 | if (!is_hardware_watchpoint (bpt)) | |
2556 | continue; | |
2557 | ||
d6b74ac4 | 2558 | if (!breakpoint_enabled (bpt)) |
a5606eee | 2559 | continue; |
74960c60 VP |
2560 | |
2561 | if (bpt->disposition == disp_del_at_next_stop) | |
2562 | continue; | |
a5606eee VP |
2563 | |
2564 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 2565 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
2566 | { |
2567 | some_failed = 1; | |
2568 | break; | |
2569 | } | |
2570 | if (some_failed) | |
2571 | { | |
2572 | for (loc = bpt->loc; loc; loc = loc->next) | |
2573 | if (loc->inserted) | |
2574 | remove_breakpoint (loc, mark_uninserted); | |
2575 | ||
2576 | hw_breakpoint_error = 1; | |
2577 | fprintf_unfiltered (tmp_error_stream, | |
2578 | "Could not insert hardware watchpoint %d.\n", | |
2579 | bpt->number); | |
eacd795a | 2580 | error_flag = -1; |
a5606eee VP |
2581 | } |
2582 | } | |
2583 | ||
eacd795a | 2584 | if (error_flag) |
81d0cc19 GS |
2585 | { |
2586 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
2587 | message about possibly exhausted resources. */ | |
879bfdc2 | 2588 | if (hw_breakpoint_error) |
81d0cc19 | 2589 | { |
c6510018 MS |
2590 | fprintf_unfiltered (tmp_error_stream, |
2591 | "Could not insert hardware breakpoints:\n\ | |
2592 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 2593 | } |
81d0cc19 GS |
2594 | target_terminal_ours_for_output (); |
2595 | error_stream (tmp_error_stream); | |
2596 | } | |
f7545552 TT |
2597 | |
2598 | do_cleanups (cleanups); | |
c906108c SS |
2599 | } |
2600 | ||
c30eee59 TJB |
2601 | /* Used when the program stops. |
2602 | Returns zero if successful, or non-zero if there was a problem | |
2603 | removing a breakpoint location. */ | |
2604 | ||
c906108c | 2605 | int |
fba45db2 | 2606 | remove_breakpoints (void) |
c906108c | 2607 | { |
35df4500 | 2608 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 2609 | int val = 0; |
c906108c | 2610 | |
35df4500 | 2611 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2612 | { |
1e4d1764 | 2613 | if (bl->inserted && !is_tracepoint (bl->owner)) |
35df4500 | 2614 | val |= remove_breakpoint (bl, mark_uninserted); |
c5aa993b | 2615 | } |
3a1bae8e | 2616 | return val; |
c906108c SS |
2617 | } |
2618 | ||
6c95b8df PA |
2619 | /* Remove breakpoints of process PID. */ |
2620 | ||
2621 | int | |
2622 | remove_breakpoints_pid (int pid) | |
2623 | { | |
35df4500 | 2624 | struct bp_location *bl, **blp_tmp; |
6c95b8df PA |
2625 | int val; |
2626 | struct inferior *inf = find_inferior_pid (pid); | |
2627 | ||
35df4500 | 2628 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 2629 | { |
35df4500 | 2630 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2631 | continue; |
2632 | ||
35df4500 | 2633 | if (bl->inserted) |
6c95b8df | 2634 | { |
35df4500 | 2635 | val = remove_breakpoint (bl, mark_uninserted); |
6c95b8df PA |
2636 | if (val != 0) |
2637 | return val; | |
2638 | } | |
2639 | } | |
2640 | return 0; | |
2641 | } | |
2642 | ||
c906108c | 2643 | int |
fba45db2 | 2644 | reattach_breakpoints (int pid) |
c906108c | 2645 | { |
6c95b8df | 2646 | struct cleanup *old_chain; |
35df4500 | 2647 | struct bp_location *bl, **blp_tmp; |
c906108c | 2648 | int val; |
86b887df | 2649 | struct ui_file *tmp_error_stream; |
3fbb6ffa | 2650 | int dummy1 = 0, dummy2 = 0; |
6c95b8df PA |
2651 | struct inferior *inf; |
2652 | struct thread_info *tp; | |
2653 | ||
2654 | tp = any_live_thread_of_process (pid); | |
2655 | if (tp == NULL) | |
2656 | return 1; | |
2657 | ||
2658 | inf = find_inferior_pid (pid); | |
2659 | old_chain = save_inferior_ptid (); | |
2660 | ||
2661 | inferior_ptid = tp->ptid; | |
a4954f26 | 2662 | |
86b887df | 2663 | tmp_error_stream = mem_fileopen (); |
a4954f26 | 2664 | make_cleanup_ui_file_delete (tmp_error_stream); |
c906108c | 2665 | |
35df4500 | 2666 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2667 | { |
35df4500 | 2668 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2669 | continue; |
2670 | ||
35df4500 | 2671 | if (bl->inserted) |
c5aa993b | 2672 | { |
35df4500 | 2673 | bl->inserted = 0; |
3fbb6ffa | 2674 | val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2); |
c5aa993b JM |
2675 | if (val != 0) |
2676 | { | |
ce696e05 | 2677 | do_cleanups (old_chain); |
c5aa993b JM |
2678 | return val; |
2679 | } | |
2680 | } | |
2681 | } | |
ce696e05 | 2682 | do_cleanups (old_chain); |
c906108c SS |
2683 | return 0; |
2684 | } | |
2685 | ||
e58b0e63 PA |
2686 | static int internal_breakpoint_number = -1; |
2687 | ||
84f4c1fe PM |
2688 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
2689 | If INTERNAL is non-zero, the breakpoint number will be populated | |
2690 | from internal_breakpoint_number and that variable decremented. | |
e5dd4106 | 2691 | Otherwise the breakpoint number will be populated from |
84f4c1fe PM |
2692 | breakpoint_count and that value incremented. Internal breakpoints |
2693 | do not set the internal var bpnum. */ | |
2694 | static void | |
2695 | set_breakpoint_number (int internal, struct breakpoint *b) | |
2696 | { | |
2697 | if (internal) | |
2698 | b->number = internal_breakpoint_number--; | |
2699 | else | |
2700 | { | |
2701 | set_breakpoint_count (breakpoint_count + 1); | |
2702 | b->number = breakpoint_count; | |
2703 | } | |
2704 | } | |
2705 | ||
e62c965a | 2706 | static struct breakpoint * |
a6d9a66e | 2707 | create_internal_breakpoint (struct gdbarch *gdbarch, |
06edf0c0 | 2708 | CORE_ADDR address, enum bptype type, |
c0a91b2b | 2709 | const struct breakpoint_ops *ops) |
e62c965a | 2710 | { |
e62c965a PP |
2711 | struct symtab_and_line sal; |
2712 | struct breakpoint *b; | |
2713 | ||
4a64f543 | 2714 | init_sal (&sal); /* Initialize to zeroes. */ |
e62c965a PP |
2715 | |
2716 | sal.pc = address; | |
2717 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 2718 | sal.pspace = current_program_space; |
e62c965a | 2719 | |
06edf0c0 | 2720 | b = set_raw_breakpoint (gdbarch, sal, type, ops); |
e62c965a PP |
2721 | b->number = internal_breakpoint_number--; |
2722 | b->disposition = disp_donttouch; | |
2723 | ||
2724 | return b; | |
2725 | } | |
2726 | ||
17450429 PP |
2727 | static const char *const longjmp_names[] = |
2728 | { | |
2729 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
2730 | }; | |
2731 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
2732 | ||
2733 | /* Per-objfile data private to breakpoint.c. */ | |
2734 | struct breakpoint_objfile_data | |
2735 | { | |
2736 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
2737 | struct minimal_symbol *overlay_msym; | |
2738 | ||
2739 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
2740 | struct minimal_symbol *longjmp_msym[NUM_LONGJMP_NAMES]; | |
2741 | ||
2742 | /* Minimal symbol for "std::terminate()" (if any). */ | |
2743 | struct minimal_symbol *terminate_msym; | |
2744 | ||
2745 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
2746 | struct minimal_symbol *exception_msym; | |
2747 | }; | |
2748 | ||
2749 | static const struct objfile_data *breakpoint_objfile_key; | |
2750 | ||
2751 | /* Minimal symbol not found sentinel. */ | |
2752 | static struct minimal_symbol msym_not_found; | |
2753 | ||
2754 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
2755 | ||
2756 | static int | |
2757 | msym_not_found_p (const struct minimal_symbol *msym) | |
2758 | { | |
2759 | return msym == &msym_not_found; | |
2760 | } | |
2761 | ||
2762 | /* Return per-objfile data needed by breakpoint.c. | |
2763 | Allocate the data if necessary. */ | |
2764 | ||
2765 | static struct breakpoint_objfile_data * | |
2766 | get_breakpoint_objfile_data (struct objfile *objfile) | |
2767 | { | |
2768 | struct breakpoint_objfile_data *bp_objfile_data; | |
2769 | ||
2770 | bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key); | |
2771 | if (bp_objfile_data == NULL) | |
2772 | { | |
2773 | bp_objfile_data = obstack_alloc (&objfile->objfile_obstack, | |
2774 | sizeof (*bp_objfile_data)); | |
2775 | ||
2776 | memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); | |
2777 | set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); | |
2778 | } | |
2779 | return bp_objfile_data; | |
2780 | } | |
2781 | ||
e62c965a | 2782 | static void |
af02033e | 2783 | create_overlay_event_breakpoint (void) |
e62c965a | 2784 | { |
69de3c6a | 2785 | struct objfile *objfile; |
af02033e | 2786 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 2787 | |
69de3c6a PP |
2788 | ALL_OBJFILES (objfile) |
2789 | { | |
2790 | struct breakpoint *b; | |
17450429 PP |
2791 | struct breakpoint_objfile_data *bp_objfile_data; |
2792 | CORE_ADDR addr; | |
69de3c6a | 2793 | |
17450429 PP |
2794 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
2795 | ||
2796 | if (msym_not_found_p (bp_objfile_data->overlay_msym)) | |
2797 | continue; | |
2798 | ||
2799 | if (bp_objfile_data->overlay_msym == NULL) | |
2800 | { | |
2801 | struct minimal_symbol *m; | |
2802 | ||
2803 | m = lookup_minimal_symbol_text (func_name, objfile); | |
2804 | if (m == NULL) | |
2805 | { | |
2806 | /* Avoid future lookups in this objfile. */ | |
2807 | bp_objfile_data->overlay_msym = &msym_not_found; | |
2808 | continue; | |
2809 | } | |
2810 | bp_objfile_data->overlay_msym = m; | |
2811 | } | |
e62c965a | 2812 | |
17450429 PP |
2813 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
2814 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, | |
06edf0c0 PA |
2815 | bp_overlay_event, |
2816 | &internal_breakpoint_ops); | |
69de3c6a | 2817 | b->addr_string = xstrdup (func_name); |
e62c965a | 2818 | |
69de3c6a PP |
2819 | if (overlay_debugging == ovly_auto) |
2820 | { | |
2821 | b->enable_state = bp_enabled; | |
2822 | overlay_events_enabled = 1; | |
2823 | } | |
2824 | else | |
2825 | { | |
2826 | b->enable_state = bp_disabled; | |
2827 | overlay_events_enabled = 0; | |
2828 | } | |
e62c965a PP |
2829 | } |
2830 | update_global_location_list (1); | |
2831 | } | |
2832 | ||
0fd8e87f | 2833 | static void |
af02033e | 2834 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 2835 | { |
6c95b8df | 2836 | struct program_space *pspace; |
6c95b8df PA |
2837 | struct cleanup *old_chain; |
2838 | ||
2839 | old_chain = save_current_program_space (); | |
0fd8e87f | 2840 | |
6c95b8df | 2841 | ALL_PSPACES (pspace) |
af02033e PP |
2842 | { |
2843 | struct objfile *objfile; | |
2844 | ||
2845 | set_current_program_space (pspace); | |
2846 | ||
2847 | ALL_OBJFILES (objfile) | |
0fd8e87f | 2848 | { |
af02033e PP |
2849 | int i; |
2850 | struct gdbarch *gdbarch; | |
17450429 | 2851 | struct breakpoint_objfile_data *bp_objfile_data; |
0fd8e87f | 2852 | |
af02033e PP |
2853 | gdbarch = get_objfile_arch (objfile); |
2854 | if (!gdbarch_get_longjmp_target_p (gdbarch)) | |
0fd8e87f UW |
2855 | continue; |
2856 | ||
17450429 PP |
2857 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
2858 | ||
2859 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) | |
af02033e PP |
2860 | { |
2861 | struct breakpoint *b; | |
af02033e | 2862 | const char *func_name; |
17450429 | 2863 | CORE_ADDR addr; |
6c95b8df | 2864 | |
17450429 | 2865 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i])) |
af02033e | 2866 | continue; |
0fd8e87f | 2867 | |
17450429 PP |
2868 | func_name = longjmp_names[i]; |
2869 | if (bp_objfile_data->longjmp_msym[i] == NULL) | |
2870 | { | |
2871 | struct minimal_symbol *m; | |
2872 | ||
2873 | m = lookup_minimal_symbol_text (func_name, objfile); | |
2874 | if (m == NULL) | |
2875 | { | |
2876 | /* Prevent future lookups in this objfile. */ | |
2877 | bp_objfile_data->longjmp_msym[i] = &msym_not_found; | |
2878 | continue; | |
2879 | } | |
2880 | bp_objfile_data->longjmp_msym[i] = m; | |
2881 | } | |
2882 | ||
2883 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); | |
06edf0c0 PA |
2884 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, |
2885 | &internal_breakpoint_ops); | |
af02033e PP |
2886 | b->addr_string = xstrdup (func_name); |
2887 | b->enable_state = bp_disabled; | |
2888 | } | |
0fd8e87f | 2889 | } |
af02033e | 2890 | } |
0fd8e87f | 2891 | update_global_location_list (1); |
6c95b8df PA |
2892 | |
2893 | do_cleanups (old_chain); | |
0fd8e87f UW |
2894 | } |
2895 | ||
af02033e | 2896 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 2897 | static void |
af02033e | 2898 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
2899 | { |
2900 | struct program_space *pspace; | |
aa7d318d | 2901 | struct cleanup *old_chain; |
af02033e | 2902 | const char *const func_name = "std::terminate()"; |
aa7d318d TT |
2903 | |
2904 | old_chain = save_current_program_space (); | |
2905 | ||
2906 | ALL_PSPACES (pspace) | |
17450429 PP |
2907 | { |
2908 | struct objfile *objfile; | |
2909 | CORE_ADDR addr; | |
2910 | ||
2911 | set_current_program_space (pspace); | |
2912 | ||
aa7d318d TT |
2913 | ALL_OBJFILES (objfile) |
2914 | { | |
2915 | struct breakpoint *b; | |
17450429 | 2916 | struct breakpoint_objfile_data *bp_objfile_data; |
aa7d318d | 2917 | |
17450429 | 2918 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 2919 | |
17450429 PP |
2920 | if (msym_not_found_p (bp_objfile_data->terminate_msym)) |
2921 | continue; | |
2922 | ||
2923 | if (bp_objfile_data->terminate_msym == NULL) | |
2924 | { | |
2925 | struct minimal_symbol *m; | |
2926 | ||
2927 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
2928 | if (m == NULL || (MSYMBOL_TYPE (m) != mst_text | |
2929 | && MSYMBOL_TYPE (m) != mst_file_text)) | |
2930 | { | |
2931 | /* Prevent future lookups in this objfile. */ | |
2932 | bp_objfile_data->terminate_msym = &msym_not_found; | |
2933 | continue; | |
2934 | } | |
2935 | bp_objfile_data->terminate_msym = m; | |
2936 | } | |
aa7d318d | 2937 | |
17450429 PP |
2938 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
2939 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, | |
06edf0c0 PA |
2940 | bp_std_terminate_master, |
2941 | &internal_breakpoint_ops); | |
aa7d318d TT |
2942 | b->addr_string = xstrdup (func_name); |
2943 | b->enable_state = bp_disabled; | |
2944 | } | |
17450429 PP |
2945 | } |
2946 | ||
aa7d318d TT |
2947 | update_global_location_list (1); |
2948 | ||
2949 | do_cleanups (old_chain); | |
2950 | } | |
2951 | ||
186c406b TT |
2952 | /* Install a master breakpoint on the unwinder's debug hook. */ |
2953 | ||
70221824 | 2954 | static void |
186c406b TT |
2955 | create_exception_master_breakpoint (void) |
2956 | { | |
2957 | struct objfile *objfile; | |
17450429 | 2958 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b TT |
2959 | |
2960 | ALL_OBJFILES (objfile) | |
2961 | { | |
17450429 PP |
2962 | struct breakpoint *b; |
2963 | struct gdbarch *gdbarch; | |
2964 | struct breakpoint_objfile_data *bp_objfile_data; | |
2965 | CORE_ADDR addr; | |
2966 | ||
2967 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
2968 | ||
2969 | if (msym_not_found_p (bp_objfile_data->exception_msym)) | |
2970 | continue; | |
2971 | ||
2972 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 2973 | |
17450429 | 2974 | if (bp_objfile_data->exception_msym == NULL) |
186c406b | 2975 | { |
17450429 | 2976 | struct minimal_symbol *debug_hook; |
186c406b | 2977 | |
17450429 PP |
2978 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
2979 | if (debug_hook == NULL) | |
2980 | { | |
2981 | bp_objfile_data->exception_msym = &msym_not_found; | |
2982 | continue; | |
2983 | } | |
2984 | ||
2985 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 2986 | } |
17450429 PP |
2987 | |
2988 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); | |
2989 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, | |
2990 | ¤t_target); | |
06edf0c0 PA |
2991 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
2992 | &internal_breakpoint_ops); | |
17450429 PP |
2993 | b->addr_string = xstrdup (func_name); |
2994 | b->enable_state = bp_disabled; | |
186c406b TT |
2995 | } |
2996 | ||
2997 | update_global_location_list (1); | |
2998 | } | |
2999 | ||
c906108c | 3000 | void |
fba45db2 | 3001 | update_breakpoints_after_exec (void) |
c906108c | 3002 | { |
35df4500 | 3003 | struct breakpoint *b, *b_tmp; |
876fa593 | 3004 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 3005 | |
25b22b0a PA |
3006 | /* We're about to delete breakpoints from GDB's lists. If the |
3007 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
3008 | writing the breakpoints' "shadow contents" back into memory. The | |
3009 | "shadow contents" are NOT valid after an exec, so GDB should not | |
3010 | do that. Instead, the target is responsible from marking | |
3011 | breakpoints out as soon as it detects an exec. We don't do that | |
3012 | here instead, because there may be other attempts to delete | |
3013 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 3014 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
3015 | if (bploc->pspace == current_program_space) |
3016 | gdb_assert (!bploc->inserted); | |
c906108c | 3017 | |
35df4500 | 3018 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3019 | { |
6c95b8df PA |
3020 | if (b->pspace != current_program_space) |
3021 | continue; | |
3022 | ||
4a64f543 | 3023 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
3024 | if (b->type == bp_shlib_event) |
3025 | { | |
3026 | delete_breakpoint (b); | |
3027 | continue; | |
3028 | } | |
c906108c | 3029 | |
4a64f543 | 3030 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
3031 | if (b->type == bp_jit_event) |
3032 | { | |
3033 | delete_breakpoint (b); | |
3034 | continue; | |
3035 | } | |
3036 | ||
1900040c | 3037 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
3038 | as must overlay event and longjmp master breakpoints. */ |
3039 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
3040 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
3041 | || b->type == bp_exception_master) | |
c4093a6a JM |
3042 | { |
3043 | delete_breakpoint (b); | |
3044 | continue; | |
3045 | } | |
3046 | ||
4a64f543 | 3047 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2c03e5be | 3048 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
c5aa993b JM |
3049 | { |
3050 | delete_breakpoint (b); | |
3051 | continue; | |
3052 | } | |
3053 | ||
611c83ae PA |
3054 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
3055 | after an exec. */ | |
186c406b TT |
3056 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
3057 | || b->type == bp_exception || b->type == bp_exception_resume) | |
611c83ae PA |
3058 | { |
3059 | delete_breakpoint (b); | |
3060 | continue; | |
3061 | } | |
3062 | ||
ce78b96d JB |
3063 | if (b->type == bp_catchpoint) |
3064 | { | |
3065 | /* For now, none of the bp_catchpoint breakpoints need to | |
3066 | do anything at this point. In the future, if some of | |
3067 | the catchpoints need to something, we will need to add | |
3068 | a new method, and call this method from here. */ | |
3069 | continue; | |
3070 | } | |
3071 | ||
c5aa993b JM |
3072 | /* bp_finish is a special case. The only way we ought to be able |
3073 | to see one of these when an exec() has happened, is if the user | |
3074 | caught a vfork, and then said "finish". Ordinarily a finish just | |
3075 | carries them to the call-site of the current callee, by setting | |
3076 | a temporary bp there and resuming. But in this case, the finish | |
3077 | will carry them entirely through the vfork & exec. | |
3078 | ||
3079 | We don't want to allow a bp_finish to remain inserted now. But | |
3080 | we can't safely delete it, 'cause finish_command has a handle to | |
3081 | the bp on a bpstat, and will later want to delete it. There's a | |
3082 | chance (and I've seen it happen) that if we delete the bp_finish | |
3083 | here, that its storage will get reused by the time finish_command | |
3084 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
3085 | We really must allow finish_command to delete a bp_finish. | |
3086 | ||
e5dd4106 | 3087 | In the absence of a general solution for the "how do we know |
53a5351d JM |
3088 | it's safe to delete something others may have handles to?" |
3089 | problem, what we'll do here is just uninsert the bp_finish, and | |
3090 | let finish_command delete it. | |
3091 | ||
3092 | (We know the bp_finish is "doomed" in the sense that it's | |
3093 | momentary, and will be deleted as soon as finish_command sees | |
3094 | the inferior stopped. So it doesn't matter that the bp's | |
3095 | address is probably bogus in the new a.out, unlike e.g., the | |
3096 | solib breakpoints.) */ | |
c5aa993b | 3097 | |
c5aa993b JM |
3098 | if (b->type == bp_finish) |
3099 | { | |
3100 | continue; | |
3101 | } | |
3102 | ||
3103 | /* Without a symbolic address, we have little hope of the | |
3104 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 3105 | a.out. */ |
c5aa993b JM |
3106 | if (b->addr_string == NULL) |
3107 | { | |
3108 | delete_breakpoint (b); | |
3109 | continue; | |
3110 | } | |
c5aa993b | 3111 | } |
1900040c | 3112 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
af02033e PP |
3113 | create_overlay_event_breakpoint (); |
3114 | create_longjmp_master_breakpoint (); | |
3115 | create_std_terminate_master_breakpoint (); | |
186c406b | 3116 | create_exception_master_breakpoint (); |
c906108c SS |
3117 | } |
3118 | ||
3119 | int | |
fba45db2 | 3120 | detach_breakpoints (int pid) |
c906108c | 3121 | { |
35df4500 | 3122 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3123 | int val = 0; |
ce696e05 | 3124 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 3125 | struct inferior *inf = current_inferior (); |
c5aa993b | 3126 | |
39f77062 | 3127 | if (pid == PIDGET (inferior_ptid)) |
8a3fe4f8 | 3128 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 3129 | |
6c95b8df | 3130 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
ce696e05 | 3131 | inferior_ptid = pid_to_ptid (pid); |
35df4500 | 3132 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3133 | { |
35df4500 | 3134 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3135 | continue; |
3136 | ||
35df4500 TJB |
3137 | if (bl->inserted) |
3138 | val |= remove_breakpoint_1 (bl, mark_inserted); | |
c5aa993b | 3139 | } |
d03285ec UW |
3140 | |
3141 | /* Detach single-step breakpoints as well. */ | |
3142 | detach_single_step_breakpoints (); | |
3143 | ||
ce696e05 | 3144 | do_cleanups (old_chain); |
3a1bae8e | 3145 | return val; |
c906108c SS |
3146 | } |
3147 | ||
35df4500 | 3148 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
3149 | Note that this is used to detach breakpoints from a child fork. |
3150 | When we get here, the child isn't in the inferior list, and neither | |
3151 | do we have objects to represent its address space --- we should | |
35df4500 | 3152 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 3153 | |
c906108c | 3154 | static int |
35df4500 | 3155 | remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is) |
c906108c SS |
3156 | { |
3157 | int val; | |
c5aa993b | 3158 | |
35df4500 TJB |
3159 | /* BL is never in moribund_locations by our callers. */ |
3160 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3161 | |
35df4500 | 3162 | if (bl->owner->enable_state == bp_permanent) |
c2c6d25f JM |
3163 | /* Permanent breakpoints cannot be inserted or removed. */ |
3164 | return 0; | |
3165 | ||
74960c60 VP |
3166 | /* The type of none suggests that owner is actually deleted. |
3167 | This should not ever happen. */ | |
35df4500 | 3168 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 3169 | |
35df4500 TJB |
3170 | if (bl->loc_type == bp_loc_software_breakpoint |
3171 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 3172 | { |
c02f5703 MS |
3173 | /* "Normal" instruction breakpoint: either the standard |
3174 | trap-instruction bp (bp_breakpoint), or a | |
3175 | bp_hardware_breakpoint. */ | |
3176 | ||
3177 | /* First check to see if we have to handle an overlay. */ | |
3178 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
3179 | || bl->section == NULL |
3180 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
3181 | { |
3182 | /* No overlay handling: just remove the breakpoint. */ | |
348d480f | 3183 | val = bl->owner->ops->remove_location (bl); |
c02f5703 | 3184 | } |
c906108c SS |
3185 | else |
3186 | { | |
4a64f543 | 3187 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
3188 | Did we set a breakpoint at the LMA? */ |
3189 | if (!overlay_events_enabled) | |
3190 | { | |
3191 | /* Yes -- overlay event support is not active, so we | |
3192 | should have set a breakpoint at the LMA. Remove it. | |
3193 | */ | |
c02f5703 MS |
3194 | /* Ignore any failures: if the LMA is in ROM, we will |
3195 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
3196 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
3197 | target_remove_hw_breakpoint (bl->gdbarch, | |
3198 | &bl->overlay_target_info); | |
c02f5703 | 3199 | else |
35df4500 TJB |
3200 | target_remove_breakpoint (bl->gdbarch, |
3201 | &bl->overlay_target_info); | |
c02f5703 MS |
3202 | } |
3203 | /* Did we set a breakpoint at the VMA? | |
3204 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 3205 | if (bl->inserted) |
c906108c | 3206 | { |
c02f5703 MS |
3207 | /* Yes -- remove it. Previously we did not bother to |
3208 | remove the breakpoint if the section had been | |
3209 | unmapped, but let's not rely on that being safe. We | |
3210 | don't know what the overlay manager might do. */ | |
aa67235e UW |
3211 | |
3212 | /* However, we should remove *software* breakpoints only | |
3213 | if the section is still mapped, or else we overwrite | |
3214 | wrong code with the saved shadow contents. */ | |
348d480f PA |
3215 | if (bl->loc_type == bp_loc_hardware_breakpoint |
3216 | || section_is_mapped (bl->section)) | |
3217 | val = bl->owner->ops->remove_location (bl); | |
aa67235e UW |
3218 | else |
3219 | val = 0; | |
c906108c | 3220 | } |
c02f5703 MS |
3221 | else |
3222 | { | |
3223 | /* No -- not inserted, so no need to remove. No error. */ | |
3224 | val = 0; | |
3225 | } | |
c906108c | 3226 | } |
879d1e6b UW |
3227 | |
3228 | /* In some cases, we might not be able to remove a breakpoint | |
3229 | in a shared library that has already been removed, but we | |
3230 | have not yet processed the shlib unload event. */ | |
35df4500 | 3231 | if (val && solib_name_from_address (bl->pspace, bl->address)) |
879d1e6b UW |
3232 | val = 0; |
3233 | ||
c906108c SS |
3234 | if (val) |
3235 | return val; | |
35df4500 | 3236 | bl->inserted = (is == mark_inserted); |
c906108c | 3237 | } |
35df4500 | 3238 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 3239 | { |
77b06cd7 TJB |
3240 | gdb_assert (bl->owner->ops != NULL |
3241 | && bl->owner->ops->remove_location != NULL); | |
3242 | ||
35df4500 | 3243 | bl->inserted = (is == mark_inserted); |
77b06cd7 | 3244 | bl->owner->ops->remove_location (bl); |
2e70b7b9 | 3245 | |
c906108c | 3246 | /* Failure to remove any of the hardware watchpoints comes here. */ |
35df4500 | 3247 | if ((is == mark_uninserted) && (bl->inserted)) |
8a3fe4f8 | 3248 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 3249 | bl->owner->number); |
c906108c | 3250 | } |
35df4500 TJB |
3251 | else if (bl->owner->type == bp_catchpoint |
3252 | && breakpoint_enabled (bl->owner) | |
3253 | && !bl->duplicate) | |
ce78b96d | 3254 | { |
77b06cd7 TJB |
3255 | gdb_assert (bl->owner->ops != NULL |
3256 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 3257 | |
77b06cd7 | 3258 | val = bl->owner->ops->remove_location (bl); |
ce78b96d JB |
3259 | if (val) |
3260 | return val; | |
77b06cd7 | 3261 | |
35df4500 | 3262 | bl->inserted = (is == mark_inserted); |
ce78b96d | 3263 | } |
c906108c SS |
3264 | |
3265 | return 0; | |
3266 | } | |
3267 | ||
6c95b8df | 3268 | static int |
35df4500 | 3269 | remove_breakpoint (struct bp_location *bl, insertion_state_t is) |
6c95b8df PA |
3270 | { |
3271 | int ret; | |
3272 | struct cleanup *old_chain; | |
3273 | ||
35df4500 TJB |
3274 | /* BL is never in moribund_locations by our callers. */ |
3275 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3276 | |
35df4500 | 3277 | if (bl->owner->enable_state == bp_permanent) |
6c95b8df PA |
3278 | /* Permanent breakpoints cannot be inserted or removed. */ |
3279 | return 0; | |
3280 | ||
3281 | /* The type of none suggests that owner is actually deleted. | |
3282 | This should not ever happen. */ | |
35df4500 | 3283 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df PA |
3284 | |
3285 | old_chain = save_current_space_and_thread (); | |
3286 | ||
35df4500 | 3287 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 3288 | |
35df4500 | 3289 | ret = remove_breakpoint_1 (bl, is); |
6c95b8df PA |
3290 | |
3291 | do_cleanups (old_chain); | |
3292 | return ret; | |
3293 | } | |
3294 | ||
c906108c SS |
3295 | /* Clear the "inserted" flag in all breakpoints. */ |
3296 | ||
25b22b0a | 3297 | void |
fba45db2 | 3298 | mark_breakpoints_out (void) |
c906108c | 3299 | { |
35df4500 | 3300 | struct bp_location *bl, **blp_tmp; |
c906108c | 3301 | |
35df4500 TJB |
3302 | ALL_BP_LOCATIONS (bl, blp_tmp) |
3303 | if (bl->pspace == current_program_space) | |
3304 | bl->inserted = 0; | |
c906108c SS |
3305 | } |
3306 | ||
53a5351d JM |
3307 | /* Clear the "inserted" flag in all breakpoints and delete any |
3308 | breakpoints which should go away between runs of the program. | |
c906108c SS |
3309 | |
3310 | Plus other such housekeeping that has to be done for breakpoints | |
3311 | between runs. | |
3312 | ||
53a5351d JM |
3313 | Note: this function gets called at the end of a run (by |
3314 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 3315 | init_wait_for_inferior). */ |
c906108c SS |
3316 | |
3317 | ||
3318 | ||
3319 | void | |
fba45db2 | 3320 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 3321 | { |
35df4500 TJB |
3322 | struct breakpoint *b, *b_tmp; |
3323 | struct bp_location *bl, **blp_tmp; | |
1c5cfe86 | 3324 | int ix; |
6c95b8df | 3325 | struct program_space *pspace = current_program_space; |
c906108c | 3326 | |
50c71eaf PA |
3327 | /* If breakpoint locations are shared across processes, then there's |
3328 | nothing to do. */ | |
2567c7d9 | 3329 | if (gdbarch_has_global_breakpoints (target_gdbarch)) |
50c71eaf PA |
3330 | return; |
3331 | ||
35df4500 | 3332 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 3333 | { |
35df4500 TJB |
3334 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
3335 | if (bl->pspace == pspace | |
3336 | && bl->owner->enable_state != bp_permanent) | |
3337 | bl->inserted = 0; | |
6c95b8df | 3338 | } |
075f6582 | 3339 | |
35df4500 | 3340 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3341 | { |
6c95b8df PA |
3342 | if (b->loc && b->loc->pspace != pspace) |
3343 | continue; | |
3344 | ||
c5aa993b JM |
3345 | switch (b->type) |
3346 | { | |
3347 | case bp_call_dummy: | |
c906108c | 3348 | |
c5aa993b | 3349 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
3350 | cause problems when the inferior is rerun, so we better get |
3351 | rid of it. */ | |
3352 | ||
3353 | case bp_watchpoint_scope: | |
3354 | ||
3355 | /* Also get rid of scope breakpoints. */ | |
3356 | ||
3357 | case bp_shlib_event: | |
3358 | ||
3359 | /* Also remove solib event breakpoints. Their addresses may | |
3360 | have changed since the last time we ran the program. | |
3361 | Actually we may now be debugging against different target; | |
3362 | and so the solib backend that installed this breakpoint may | |
3363 | not be used in by the target. E.g., | |
3364 | ||
3365 | (gdb) file prog-linux | |
3366 | (gdb) run # native linux target | |
3367 | ... | |
3368 | (gdb) kill | |
3369 | (gdb) file prog-win.exe | |
3370 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
3371 | */ | |
c906108c | 3372 | |
f59f708a PA |
3373 | case bp_step_resume: |
3374 | ||
3375 | /* Also remove step-resume breakpoints. */ | |
3376 | ||
c5aa993b JM |
3377 | delete_breakpoint (b); |
3378 | break; | |
c906108c | 3379 | |
c5aa993b JM |
3380 | case bp_watchpoint: |
3381 | case bp_hardware_watchpoint: | |
3382 | case bp_read_watchpoint: | |
3383 | case bp_access_watchpoint: | |
3a5c3e22 PA |
3384 | { |
3385 | struct watchpoint *w = (struct watchpoint *) b; | |
c906108c | 3386 | |
3a5c3e22 PA |
3387 | /* Likewise for watchpoints on local expressions. */ |
3388 | if (w->exp_valid_block != NULL) | |
3389 | delete_breakpoint (b); | |
3390 | else if (context == inf_starting) | |
3391 | { | |
3392 | /* Reset val field to force reread of starting value in | |
3393 | insert_breakpoints. */ | |
3394 | if (w->val) | |
3395 | value_free (w->val); | |
3396 | w->val = NULL; | |
3397 | w->val_valid = 0; | |
c860120c | 3398 | } |
3a5c3e22 | 3399 | } |
c5aa993b JM |
3400 | break; |
3401 | default: | |
c5aa993b JM |
3402 | break; |
3403 | } | |
3404 | } | |
1c5cfe86 PA |
3405 | |
3406 | /* Get rid of the moribund locations. */ | |
35df4500 TJB |
3407 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
3408 | decref_bp_location (&bl); | |
1c5cfe86 | 3409 | VEC_free (bp_location_p, moribund_locations); |
c906108c SS |
3410 | } |
3411 | ||
6c95b8df PA |
3412 | /* These functions concern about actual breakpoints inserted in the |
3413 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
3414 | we need to hop over the bkpt --- so we check for address space | |
3415 | match, not program space. */ | |
3416 | ||
c2c6d25f JM |
3417 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
3418 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
3419 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
3420 | permanent breakpoint. | |
3421 | - When continuing from a location with an ordinary breakpoint, we | |
3422 | actually single step once before calling insert_breakpoints. | |
e5dd4106 | 3423 | - When continuing from a location with a permanent breakpoint, we |
c2c6d25f JM |
3424 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
3425 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 3426 | |
c2c6d25f | 3427 | enum breakpoint_here |
6c95b8df | 3428 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 3429 | { |
35df4500 | 3430 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 3431 | int any_breakpoint_here = 0; |
c906108c | 3432 | |
35df4500 | 3433 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 3434 | { |
35df4500 TJB |
3435 | if (bl->loc_type != bp_loc_software_breakpoint |
3436 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
3437 | continue; |
3438 | ||
f1310107 | 3439 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 TJB |
3440 | if ((breakpoint_enabled (bl->owner) |
3441 | || bl->owner->enable_state == bp_permanent) | |
f1310107 | 3442 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
3443 | { |
3444 | if (overlay_debugging | |
35df4500 TJB |
3445 | && section_is_overlay (bl->section) |
3446 | && !section_is_mapped (bl->section)) | |
075f6582 | 3447 | continue; /* unmapped overlay -- can't be a match */ |
35df4500 | 3448 | else if (bl->owner->enable_state == bp_permanent) |
075f6582 DJ |
3449 | return permanent_breakpoint_here; |
3450 | else | |
3451 | any_breakpoint_here = 1; | |
3452 | } | |
3453 | } | |
c906108c | 3454 | |
c2c6d25f | 3455 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
3456 | } |
3457 | ||
1c5cfe86 PA |
3458 | /* Return true if there's a moribund breakpoint at PC. */ |
3459 | ||
3460 | int | |
6c95b8df | 3461 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
3462 | { |
3463 | struct bp_location *loc; | |
3464 | int ix; | |
3465 | ||
3466 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
f1310107 | 3467 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
3468 | return 1; |
3469 | ||
3470 | return 0; | |
3471 | } | |
c2c6d25f | 3472 | |
c36b740a | 3473 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
4a64f543 MS |
3474 | inserted using regular breakpoint_chain / bp_location array |
3475 | mechanism. This does not check for single-step breakpoints, which | |
3476 | are inserted and removed using direct target manipulation. */ | |
c906108c SS |
3477 | |
3478 | int | |
4a64f543 MS |
3479 | regular_breakpoint_inserted_here_p (struct address_space *aspace, |
3480 | CORE_ADDR pc) | |
c906108c | 3481 | { |
35df4500 | 3482 | struct bp_location *bl, **blp_tmp; |
c906108c | 3483 | |
35df4500 | 3484 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3485 | { |
35df4500 TJB |
3486 | if (bl->loc_type != bp_loc_software_breakpoint |
3487 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
3488 | continue; |
3489 | ||
35df4500 | 3490 | if (bl->inserted |
f1310107 | 3491 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
3492 | { |
3493 | if (overlay_debugging | |
35df4500 TJB |
3494 | && section_is_overlay (bl->section) |
3495 | && !section_is_mapped (bl->section)) | |
075f6582 DJ |
3496 | continue; /* unmapped overlay -- can't be a match */ |
3497 | else | |
3498 | return 1; | |
3499 | } | |
c5aa993b | 3500 | } |
c36b740a VP |
3501 | return 0; |
3502 | } | |
3503 | ||
3504 | /* Returns non-zero iff there's either regular breakpoint | |
3505 | or a single step breakpoint inserted at PC. */ | |
3506 | ||
3507 | int | |
6c95b8df | 3508 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c36b740a | 3509 | { |
6c95b8df | 3510 | if (regular_breakpoint_inserted_here_p (aspace, pc)) |
c36b740a | 3511 | return 1; |
c906108c | 3512 | |
6c95b8df | 3513 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
3514 | return 1; |
3515 | ||
c906108c SS |
3516 | return 0; |
3517 | } | |
3518 | ||
4fa8626c DJ |
3519 | /* This function returns non-zero iff there is a software breakpoint |
3520 | inserted at PC. */ | |
3521 | ||
3522 | int | |
3e43a32a MS |
3523 | software_breakpoint_inserted_here_p (struct address_space *aspace, |
3524 | CORE_ADDR pc) | |
4fa8626c | 3525 | { |
35df4500 | 3526 | struct bp_location *bl, **blp_tmp; |
4fa8626c | 3527 | |
35df4500 | 3528 | ALL_BP_LOCATIONS (bl, blp_tmp) |
4fa8626c | 3529 | { |
35df4500 | 3530 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
3531 | continue; |
3532 | ||
35df4500 TJB |
3533 | if (bl->inserted |
3534 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6c95b8df | 3535 | aspace, pc)) |
4fa8626c DJ |
3536 | { |
3537 | if (overlay_debugging | |
35df4500 TJB |
3538 | && section_is_overlay (bl->section) |
3539 | && !section_is_mapped (bl->section)) | |
4fa8626c DJ |
3540 | continue; /* unmapped overlay -- can't be a match */ |
3541 | else | |
3542 | return 1; | |
3543 | } | |
3544 | } | |
3545 | ||
1aafd4da | 3546 | /* Also check for software single-step breakpoints. */ |
6c95b8df | 3547 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
3548 | return 1; |
3549 | ||
4fa8626c DJ |
3550 | return 0; |
3551 | } | |
3552 | ||
9093389c PA |
3553 | int |
3554 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
3555 | CORE_ADDR addr, ULONGEST len) | |
3556 | { | |
3557 | struct breakpoint *bpt; | |
3558 | ||
3559 | ALL_BREAKPOINTS (bpt) | |
3560 | { | |
3561 | struct bp_location *loc; | |
3562 | ||
3563 | if (bpt->type != bp_hardware_watchpoint | |
3564 | && bpt->type != bp_access_watchpoint) | |
3565 | continue; | |
3566 | ||
3567 | if (!breakpoint_enabled (bpt)) | |
3568 | continue; | |
3569 | ||
3570 | for (loc = bpt->loc; loc; loc = loc->next) | |
3571 | if (loc->pspace->aspace == aspace && loc->inserted) | |
3572 | { | |
3573 | CORE_ADDR l, h; | |
3574 | ||
3575 | /* Check for intersection. */ | |
3576 | l = max (loc->address, addr); | |
3577 | h = min (loc->address + loc->length, addr + len); | |
3578 | if (l < h) | |
3579 | return 1; | |
3580 | } | |
3581 | } | |
3582 | return 0; | |
3583 | } | |
3584 | ||
075f6582 DJ |
3585 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
3586 | PC is valid for process/thread PTID. */ | |
c906108c SS |
3587 | |
3588 | int | |
6c95b8df PA |
3589 | breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc, |
3590 | ptid_t ptid) | |
c906108c | 3591 | { |
35df4500 | 3592 | struct bp_location *bl, **blp_tmp; |
4a306c9a | 3593 | /* The thread and task IDs associated to PTID, computed lazily. */ |
a6f1cd96 | 3594 | int thread = -1; |
4a306c9a | 3595 | int task = 0; |
a6f1cd96 | 3596 | |
35df4500 | 3597 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3598 | { |
35df4500 TJB |
3599 | if (bl->loc_type != bp_loc_software_breakpoint |
3600 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
3601 | continue; |
3602 | ||
35df4500 TJB |
3603 | /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */ |
3604 | if (!breakpoint_enabled (bl->owner) | |
3605 | && bl->owner->enable_state != bp_permanent) | |
a6f1cd96 JB |
3606 | continue; |
3607 | ||
f1310107 | 3608 | if (!breakpoint_location_address_match (bl, aspace, pc)) |
a6f1cd96 JB |
3609 | continue; |
3610 | ||
35df4500 | 3611 | if (bl->owner->thread != -1) |
075f6582 | 3612 | { |
a6f1cd96 JB |
3613 | /* This is a thread-specific breakpoint. Check that ptid |
3614 | matches that thread. If thread hasn't been computed yet, | |
3615 | it is now time to do so. */ | |
3616 | if (thread == -1) | |
3617 | thread = pid_to_thread_id (ptid); | |
35df4500 | 3618 | if (bl->owner->thread != thread) |
a6f1cd96 | 3619 | continue; |
075f6582 | 3620 | } |
a6f1cd96 | 3621 | |
35df4500 | 3622 | if (bl->owner->task != 0) |
4a306c9a JB |
3623 | { |
3624 | /* This is a task-specific breakpoint. Check that ptid | |
3625 | matches that task. If task hasn't been computed yet, | |
3626 | it is now time to do so. */ | |
3627 | if (task == 0) | |
3628 | task = ada_get_task_number (ptid); | |
35df4500 | 3629 | if (bl->owner->task != task) |
4a306c9a JB |
3630 | continue; |
3631 | } | |
3632 | ||
a6f1cd96 | 3633 | if (overlay_debugging |
35df4500 TJB |
3634 | && section_is_overlay (bl->section) |
3635 | && !section_is_mapped (bl->section)) | |
a6f1cd96 JB |
3636 | continue; /* unmapped overlay -- can't be a match */ |
3637 | ||
3638 | return 1; | |
c5aa993b | 3639 | } |
c906108c SS |
3640 | |
3641 | return 0; | |
3642 | } | |
c906108c | 3643 | \f |
c5aa993b | 3644 | |
c906108c SS |
3645 | /* bpstat stuff. External routines' interfaces are documented |
3646 | in breakpoint.h. */ | |
3647 | ||
3648 | int | |
c326b90e | 3649 | is_catchpoint (struct breakpoint *ep) |
c906108c | 3650 | { |
533be4dd | 3651 | return (ep->type == bp_catchpoint); |
c906108c SS |
3652 | } |
3653 | ||
f431efe5 PA |
3654 | /* Frees any storage that is part of a bpstat. Does not walk the |
3655 | 'next' chain. */ | |
3656 | ||
3657 | static void | |
198757a8 VP |
3658 | bpstat_free (bpstat bs) |
3659 | { | |
3660 | if (bs->old_val != NULL) | |
3661 | value_free (bs->old_val); | |
9add0f1b | 3662 | decref_counted_command_line (&bs->commands); |
f431efe5 | 3663 | decref_bp_location (&bs->bp_location_at); |
198757a8 VP |
3664 | xfree (bs); |
3665 | } | |
3666 | ||
c906108c SS |
3667 | /* Clear a bpstat so that it says we are not at any breakpoint. |
3668 | Also free any storage that is part of a bpstat. */ | |
3669 | ||
3670 | void | |
fba45db2 | 3671 | bpstat_clear (bpstat *bsp) |
c906108c SS |
3672 | { |
3673 | bpstat p; | |
3674 | bpstat q; | |
3675 | ||
3676 | if (bsp == 0) | |
3677 | return; | |
3678 | p = *bsp; | |
3679 | while (p != NULL) | |
3680 | { | |
3681 | q = p->next; | |
198757a8 | 3682 | bpstat_free (p); |
c906108c SS |
3683 | p = q; |
3684 | } | |
3685 | *bsp = NULL; | |
3686 | } | |
3687 | ||
3688 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
3689 | is part of the bpstat is copied as well. */ | |
3690 | ||
3691 | bpstat | |
fba45db2 | 3692 | bpstat_copy (bpstat bs) |
c906108c SS |
3693 | { |
3694 | bpstat p = NULL; | |
3695 | bpstat tmp; | |
3696 | bpstat retval = NULL; | |
3697 | ||
3698 | if (bs == NULL) | |
3699 | return bs; | |
3700 | ||
3701 | for (; bs != NULL; bs = bs->next) | |
3702 | { | |
3703 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
3704 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 3705 | incref_counted_command_line (tmp->commands); |
f431efe5 | 3706 | incref_bp_location (tmp->bp_location_at); |
31cc81e9 | 3707 | if (bs->old_val != NULL) |
3c3185ac JK |
3708 | { |
3709 | tmp->old_val = value_copy (bs->old_val); | |
3710 | release_value (tmp->old_val); | |
3711 | } | |
31cc81e9 | 3712 | |
c906108c SS |
3713 | if (p == NULL) |
3714 | /* This is the first thing in the chain. */ | |
3715 | retval = tmp; | |
3716 | else | |
3717 | p->next = tmp; | |
3718 | p = tmp; | |
3719 | } | |
3720 | p->next = NULL; | |
3721 | return retval; | |
3722 | } | |
3723 | ||
4a64f543 | 3724 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
3725 | |
3726 | bpstat | |
fba45db2 | 3727 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 3728 | { |
c5aa993b JM |
3729 | if (bsp == NULL) |
3730 | return NULL; | |
c906108c | 3731 | |
c5aa993b JM |
3732 | for (; bsp != NULL; bsp = bsp->next) |
3733 | { | |
f431efe5 | 3734 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
3735 | return bsp; |
3736 | } | |
c906108c SS |
3737 | return NULL; |
3738 | } | |
3739 | ||
4a64f543 MS |
3740 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
3741 | stopped at. *BSP upon return is a bpstat which points to the | |
3742 | remaining breakpoints stopped at (but which is not guaranteed to be | |
3743 | good for anything but further calls to bpstat_num). | |
3744 | ||
8671a17b PA |
3745 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
3746 | Return -1 if stopped at a breakpoint that has been deleted since | |
3747 | we set it. | |
3748 | Return 1 otherwise. */ | |
c906108c SS |
3749 | |
3750 | int | |
8671a17b | 3751 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
3752 | { |
3753 | struct breakpoint *b; | |
3754 | ||
3755 | if ((*bsp) == NULL) | |
3756 | return 0; /* No more breakpoint values */ | |
8671a17b | 3757 | |
4a64f543 MS |
3758 | /* We assume we'll never have several bpstats that correspond to a |
3759 | single breakpoint -- otherwise, this function might return the | |
3760 | same number more than once and this will look ugly. */ | |
f431efe5 | 3761 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
3762 | *bsp = (*bsp)->next; |
3763 | if (b == NULL) | |
3764 | return -1; /* breakpoint that's been deleted since */ | |
3765 | ||
3766 | *num = b->number; /* We have its number */ | |
3767 | return 1; | |
c906108c SS |
3768 | } |
3769 | ||
e93ca019 | 3770 | /* See breakpoint.h. */ |
c906108c SS |
3771 | |
3772 | void | |
e93ca019 | 3773 | bpstat_clear_actions (void) |
c906108c | 3774 | { |
e93ca019 JK |
3775 | struct thread_info *tp; |
3776 | bpstat bs; | |
3777 | ||
3778 | if (ptid_equal (inferior_ptid, null_ptid)) | |
3779 | return; | |
3780 | ||
3781 | tp = find_thread_ptid (inferior_ptid); | |
3782 | if (tp == NULL) | |
3783 | return; | |
3784 | ||
3785 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) | |
c906108c | 3786 | { |
9add0f1b | 3787 | decref_counted_command_line (&bs->commands); |
abf85f46 | 3788 | |
c906108c SS |
3789 | if (bs->old_val != NULL) |
3790 | { | |
3791 | value_free (bs->old_val); | |
3792 | bs->old_val = NULL; | |
3793 | } | |
3794 | } | |
3795 | } | |
3796 | ||
f3b1572e PA |
3797 | /* Called when a command is about to proceed the inferior. */ |
3798 | ||
3799 | static void | |
3800 | breakpoint_about_to_proceed (void) | |
3801 | { | |
3802 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
3803 | { | |
3804 | struct thread_info *tp = inferior_thread (); | |
3805 | ||
3806 | /* Allow inferior function calls in breakpoint commands to not | |
3807 | interrupt the command list. When the call finishes | |
3808 | successfully, the inferior will be standing at the same | |
3809 | breakpoint as if nothing happened. */ | |
16c381f0 | 3810 | if (tp->control.in_infcall) |
f3b1572e PA |
3811 | return; |
3812 | } | |
3813 | ||
3814 | breakpoint_proceeded = 1; | |
3815 | } | |
3816 | ||
4a64f543 MS |
3817 | /* Stub for cleaning up our state if we error-out of a breakpoint |
3818 | command. */ | |
c906108c | 3819 | static void |
4efb68b1 | 3820 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
3821 | { |
3822 | executing_breakpoint_commands = 0; | |
3823 | } | |
3824 | ||
abf85f46 JK |
3825 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
3826 | or its equivalent. */ | |
3827 | ||
3828 | static int | |
3829 | command_line_is_silent (struct command_line *cmd) | |
3830 | { | |
3831 | return cmd && (strcmp ("silent", cmd->line) == 0 | |
3832 | || (xdb_commands && strcmp ("Q", cmd->line) == 0)); | |
3833 | } | |
3834 | ||
4a64f543 MS |
3835 | /* Execute all the commands associated with all the breakpoints at |
3836 | this location. Any of these commands could cause the process to | |
3837 | proceed beyond this point, etc. We look out for such changes by | |
3838 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 3839 | |
347bddb7 PA |
3840 | Returns true if a breakpoint command resumed the inferior. In that |
3841 | case, it is the caller's responsibility to recall it again with the | |
3842 | bpstat of the current thread. */ | |
3843 | ||
3844 | static int | |
3845 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
3846 | { |
3847 | bpstat bs; | |
3848 | struct cleanup *old_chain; | |
347bddb7 | 3849 | int again = 0; |
c906108c SS |
3850 | |
3851 | /* Avoid endless recursion if a `source' command is contained | |
3852 | in bs->commands. */ | |
3853 | if (executing_breakpoint_commands) | |
347bddb7 | 3854 | return 0; |
c906108c SS |
3855 | |
3856 | executing_breakpoint_commands = 1; | |
3857 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
3858 | ||
cf6c5ffb TT |
3859 | prevent_dont_repeat (); |
3860 | ||
4a64f543 | 3861 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
3862 | bs = *bsp; |
3863 | ||
3864 | breakpoint_proceeded = 0; | |
3865 | for (; bs != NULL; bs = bs->next) | |
3866 | { | |
9add0f1b | 3867 | struct counted_command_line *ccmd; |
6c50ab1c JB |
3868 | struct command_line *cmd; |
3869 | struct cleanup *this_cmd_tree_chain; | |
3870 | ||
3871 | /* Take ownership of the BSP's command tree, if it has one. | |
3872 | ||
3873 | The command tree could legitimately contain commands like | |
3874 | 'step' and 'next', which call clear_proceed_status, which | |
3875 | frees stop_bpstat's command tree. To make sure this doesn't | |
3876 | free the tree we're executing out from under us, we need to | |
3877 | take ownership of the tree ourselves. Since a given bpstat's | |
3878 | commands are only executed once, we don't need to copy it; we | |
3879 | can clear the pointer in the bpstat, and make sure we free | |
3880 | the tree when we're done. */ | |
9add0f1b TT |
3881 | ccmd = bs->commands; |
3882 | bs->commands = NULL; | |
abf85f46 JK |
3883 | this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd); |
3884 | cmd = ccmd ? ccmd->commands : NULL; | |
3885 | if (command_line_is_silent (cmd)) | |
3886 | { | |
3887 | /* The action has been already done by bpstat_stop_status. */ | |
3888 | cmd = cmd->next; | |
3889 | } | |
6c50ab1c | 3890 | |
c906108c SS |
3891 | while (cmd != NULL) |
3892 | { | |
3893 | execute_control_command (cmd); | |
3894 | ||
3895 | if (breakpoint_proceeded) | |
3896 | break; | |
3897 | else | |
3898 | cmd = cmd->next; | |
3899 | } | |
6c50ab1c JB |
3900 | |
3901 | /* We can free this command tree now. */ | |
3902 | do_cleanups (this_cmd_tree_chain); | |
3903 | ||
c906108c | 3904 | if (breakpoint_proceeded) |
32c1e744 VP |
3905 | { |
3906 | if (target_can_async_p ()) | |
347bddb7 PA |
3907 | /* If we are in async mode, then the target might be still |
3908 | running, not stopped at any breakpoint, so nothing for | |
3909 | us to do here -- just return to the event loop. */ | |
3910 | ; | |
32c1e744 VP |
3911 | else |
3912 | /* In sync mode, when execute_control_command returns | |
3913 | we're already standing on the next breakpoint. | |
347bddb7 PA |
3914 | Breakpoint commands for that stop were not run, since |
3915 | execute_command does not run breakpoint commands -- | |
3916 | only command_line_handler does, but that one is not | |
3917 | involved in execution of breakpoint commands. So, we | |
3918 | can now execute breakpoint commands. It should be | |
3919 | noted that making execute_command do bpstat actions is | |
3920 | not an option -- in this case we'll have recursive | |
3921 | invocation of bpstat for each breakpoint with a | |
3922 | command, and can easily blow up GDB stack. Instead, we | |
3923 | return true, which will trigger the caller to recall us | |
3924 | with the new stop_bpstat. */ | |
3925 | again = 1; | |
3926 | break; | |
32c1e744 | 3927 | } |
c906108c | 3928 | } |
c2b8ed2c | 3929 | do_cleanups (old_chain); |
347bddb7 PA |
3930 | return again; |
3931 | } | |
3932 | ||
3933 | void | |
3934 | bpstat_do_actions (void) | |
3935 | { | |
353d1d73 JK |
3936 | struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup (); |
3937 | ||
347bddb7 PA |
3938 | /* Do any commands attached to breakpoint we are stopped at. */ |
3939 | while (!ptid_equal (inferior_ptid, null_ptid) | |
3940 | && target_has_execution | |
3941 | && !is_exited (inferior_ptid) | |
3942 | && !is_executing (inferior_ptid)) | |
3943 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
3944 | and only return when it is stopped at the next breakpoint, we | |
3945 | keep doing breakpoint actions until it returns false to | |
3946 | indicate the inferior was not resumed. */ | |
16c381f0 | 3947 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
347bddb7 | 3948 | break; |
353d1d73 JK |
3949 | |
3950 | discard_cleanups (cleanup_if_error); | |
c906108c SS |
3951 | } |
3952 | ||
fa4727a6 DJ |
3953 | /* Print out the (old or new) value associated with a watchpoint. */ |
3954 | ||
3955 | static void | |
3956 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
3957 | { | |
3958 | if (val == NULL) | |
3959 | fprintf_unfiltered (stream, _("<unreadable>")); | |
3960 | else | |
79a45b7d TT |
3961 | { |
3962 | struct value_print_options opts; | |
3963 | get_user_print_options (&opts); | |
3964 | value_print (val, stream, &opts); | |
3965 | } | |
fa4727a6 DJ |
3966 | } |
3967 | ||
e514a9d6 | 3968 | /* Generic routine for printing messages indicating why we |
4a64f543 | 3969 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
3970 | 'print_it' in the bpstat structure. Under some circumstances we |
3971 | may decide not to print anything here and delegate the task to | |
4a64f543 | 3972 | normal_stop(). */ |
e514a9d6 JM |
3973 | |
3974 | static enum print_stop_action | |
3975 | print_bp_stop_message (bpstat bs) | |
3976 | { | |
3977 | switch (bs->print_it) | |
3978 | { | |
3979 | case print_it_noop: | |
4a64f543 | 3980 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
3981 | return PRINT_UNKNOWN; |
3982 | break; | |
3983 | ||
3984 | case print_it_done: | |
3985 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 3986 | relevant messages. */ |
e514a9d6 JM |
3987 | return PRINT_SRC_AND_LOC; |
3988 | break; | |
3989 | ||
3990 | case print_it_normal: | |
4f8d1dc6 | 3991 | { |
f431efe5 PA |
3992 | struct breakpoint *b = bs->breakpoint_at; |
3993 | ||
1a6a67de TJB |
3994 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
3995 | which has since been deleted. */ | |
3996 | if (b == NULL) | |
3997 | return PRINT_UNKNOWN; | |
3998 | ||
348d480f PA |
3999 | /* Normal case. Call the breakpoint's print_it method. */ |
4000 | return b->ops->print_it (bs); | |
4f8d1dc6 | 4001 | } |
348d480f | 4002 | break; |
3086aeae | 4003 | |
e514a9d6 | 4004 | default: |
8e65ff28 | 4005 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 4006 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 4007 | break; |
c906108c | 4008 | } |
c906108c SS |
4009 | } |
4010 | ||
edcc5120 TT |
4011 | /* A helper function that prints a shared library stopped event. */ |
4012 | ||
4013 | static void | |
4014 | print_solib_event (int is_catchpoint) | |
4015 | { | |
4016 | int any_deleted | |
4017 | = !VEC_empty (char_ptr, current_program_space->deleted_solibs); | |
4018 | int any_added | |
4019 | = !VEC_empty (so_list_ptr, current_program_space->added_solibs); | |
4020 | ||
4021 | if (!is_catchpoint) | |
4022 | { | |
4023 | if (any_added || any_deleted) | |
4024 | ui_out_text (current_uiout, | |
4025 | _("Stopped due to shared library event:\n")); | |
4026 | else | |
4027 | ui_out_text (current_uiout, | |
4028 | _("Stopped due to shared library event (no " | |
4029 | "libraries added or removed)\n")); | |
4030 | } | |
4031 | ||
4032 | if (ui_out_is_mi_like_p (current_uiout)) | |
4033 | ui_out_field_string (current_uiout, "reason", | |
4034 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); | |
4035 | ||
4036 | if (any_deleted) | |
4037 | { | |
4038 | struct cleanup *cleanup; | |
4039 | char *name; | |
4040 | int ix; | |
4041 | ||
4042 | ui_out_text (current_uiout, _(" Inferior unloaded ")); | |
4043 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
4044 | "removed"); | |
4045 | for (ix = 0; | |
4046 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
4047 | ix, name); | |
4048 | ++ix) | |
4049 | { | |
4050 | if (ix > 0) | |
4051 | ui_out_text (current_uiout, " "); | |
4052 | ui_out_field_string (current_uiout, "library", name); | |
4053 | ui_out_text (current_uiout, "\n"); | |
4054 | } | |
4055 | ||
4056 | do_cleanups (cleanup); | |
4057 | } | |
4058 | ||
4059 | if (any_added) | |
4060 | { | |
4061 | struct so_list *iter; | |
4062 | int ix; | |
4063 | struct cleanup *cleanup; | |
4064 | ||
4065 | ui_out_text (current_uiout, _(" Inferior loaded ")); | |
4066 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
4067 | "added"); | |
4068 | for (ix = 0; | |
4069 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
4070 | ix, iter); | |
4071 | ++ix) | |
4072 | { | |
4073 | if (ix > 0) | |
4074 | ui_out_text (current_uiout, " "); | |
4075 | ui_out_field_string (current_uiout, "library", iter->so_name); | |
4076 | ui_out_text (current_uiout, "\n"); | |
4077 | } | |
4078 | ||
4079 | do_cleanups (cleanup); | |
4080 | } | |
4081 | } | |
4082 | ||
e514a9d6 JM |
4083 | /* Print a message indicating what happened. This is called from |
4084 | normal_stop(). The input to this routine is the head of the bpstat | |
36dfb11c TT |
4085 | list - a list of the eventpoints that caused this stop. KIND is |
4086 | the target_waitkind for the stopping event. This | |
e514a9d6 JM |
4087 | routine calls the generic print routine for printing a message |
4088 | about reasons for stopping. This will print (for example) the | |
4089 | "Breakpoint n," part of the output. The return value of this | |
4090 | routine is one of: | |
c906108c | 4091 | |
4a64f543 | 4092 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 4093 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 4094 | code to print the location. An example is |
c5aa993b JM |
4095 | "Breakpoint 1, " which should be followed by |
4096 | the location. | |
917317f4 | 4097 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
4098 | to also print the location part of the message. |
4099 | An example is the catch/throw messages, which | |
4a64f543 | 4100 | don't require a location appended to the end. |
917317f4 | 4101 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 4102 | further info to be printed. */ |
c906108c | 4103 | |
917317f4 | 4104 | enum print_stop_action |
36dfb11c | 4105 | bpstat_print (bpstat bs, int kind) |
c906108c SS |
4106 | { |
4107 | int val; | |
c5aa993b | 4108 | |
c906108c | 4109 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
4110 | (Currently all watchpoints go on the bpstat whether hit or not. |
4111 | That probably could (should) be changed, provided care is taken | |
c906108c | 4112 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
4113 | for (; bs; bs = bs->next) |
4114 | { | |
4115 | val = print_bp_stop_message (bs); | |
4116 | if (val == PRINT_SRC_ONLY | |
4117 | || val == PRINT_SRC_AND_LOC | |
4118 | || val == PRINT_NOTHING) | |
4119 | return val; | |
4120 | } | |
c906108c | 4121 | |
36dfb11c TT |
4122 | /* If we had hit a shared library event breakpoint, |
4123 | print_bp_stop_message would print out this message. If we hit an | |
4124 | OS-level shared library event, do the same thing. */ | |
4125 | if (kind == TARGET_WAITKIND_LOADED) | |
4126 | { | |
edcc5120 | 4127 | print_solib_event (0); |
36dfb11c TT |
4128 | return PRINT_NOTHING; |
4129 | } | |
4130 | ||
e514a9d6 | 4131 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 4132 | with and nothing was printed. */ |
917317f4 | 4133 | return PRINT_UNKNOWN; |
c906108c SS |
4134 | } |
4135 | ||
4a64f543 MS |
4136 | /* Evaluate the expression EXP and return 1 if value is zero. This is |
4137 | used inside a catch_errors to evaluate the breakpoint condition. | |
4138 | The argument is a "struct expression *" that has been cast to a | |
4139 | "char *" to make it pass through catch_errors. */ | |
c906108c SS |
4140 | |
4141 | static int | |
4efb68b1 | 4142 | breakpoint_cond_eval (void *exp) |
c906108c | 4143 | { |
278cd55f | 4144 | struct value *mark = value_mark (); |
c5aa993b | 4145 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 4146 | |
c906108c SS |
4147 | value_free_to_mark (mark); |
4148 | return i; | |
4149 | } | |
4150 | ||
5760d0ab | 4151 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c SS |
4152 | |
4153 | static bpstat | |
5760d0ab | 4154 | bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) |
c906108c SS |
4155 | { |
4156 | bpstat bs; | |
4157 | ||
4158 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
5760d0ab JK |
4159 | bs->next = NULL; |
4160 | **bs_link_pointer = bs; | |
4161 | *bs_link_pointer = &bs->next; | |
f431efe5 PA |
4162 | bs->breakpoint_at = bl->owner; |
4163 | bs->bp_location_at = bl; | |
4164 | incref_bp_location (bl); | |
c906108c SS |
4165 | /* If the condition is false, etc., don't do the commands. */ |
4166 | bs->commands = NULL; | |
4167 | bs->old_val = NULL; | |
4168 | bs->print_it = print_it_normal; | |
4169 | return bs; | |
4170 | } | |
4171 | \f | |
d983da9c DJ |
4172 | /* The target has stopped with waitstatus WS. Check if any hardware |
4173 | watchpoints have triggered, according to the target. */ | |
4174 | ||
4175 | int | |
4176 | watchpoints_triggered (struct target_waitstatus *ws) | |
4177 | { | |
d92524f1 | 4178 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
4179 | CORE_ADDR addr; |
4180 | struct breakpoint *b; | |
4181 | ||
4182 | if (!stopped_by_watchpoint) | |
4183 | { | |
4184 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
4185 | as not triggered. */ | |
4186 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4187 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4188 | { |
4189 | struct watchpoint *w = (struct watchpoint *) b; | |
4190 | ||
4191 | w->watchpoint_triggered = watch_triggered_no; | |
4192 | } | |
d983da9c DJ |
4193 | |
4194 | return 0; | |
4195 | } | |
4196 | ||
4197 | if (!target_stopped_data_address (¤t_target, &addr)) | |
4198 | { | |
4199 | /* We were stopped by a watchpoint, but we don't know where. | |
4200 | Mark all watchpoints as unknown. */ | |
4201 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4202 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4203 | { |
4204 | struct watchpoint *w = (struct watchpoint *) b; | |
4205 | ||
4206 | w->watchpoint_triggered = watch_triggered_unknown; | |
4207 | } | |
d983da9c DJ |
4208 | |
4209 | return stopped_by_watchpoint; | |
4210 | } | |
4211 | ||
4212 | /* The target could report the data address. Mark watchpoints | |
4213 | affected by this data address as triggered, and all others as not | |
4214 | triggered. */ | |
4215 | ||
4216 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4217 | if (is_hardware_watchpoint (b)) |
d983da9c | 4218 | { |
3a5c3e22 | 4219 | struct watchpoint *w = (struct watchpoint *) b; |
a5606eee | 4220 | struct bp_location *loc; |
d983da9c | 4221 | |
3a5c3e22 | 4222 | w->watchpoint_triggered = watch_triggered_no; |
a5606eee | 4223 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 | 4224 | { |
3a5c3e22 | 4225 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 4226 | { |
3a5c3e22 PA |
4227 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
4228 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
4229 | |
4230 | if (newaddr == start) | |
4231 | { | |
3a5c3e22 | 4232 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4233 | break; |
4234 | } | |
4235 | } | |
4236 | /* Exact match not required. Within range is sufficient. */ | |
4237 | else if (target_watchpoint_addr_within_range (¤t_target, | |
4238 | addr, loc->address, | |
4239 | loc->length)) | |
4240 | { | |
3a5c3e22 | 4241 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4242 | break; |
4243 | } | |
4244 | } | |
d983da9c DJ |
4245 | } |
4246 | ||
4247 | return 1; | |
4248 | } | |
4249 | ||
c906108c SS |
4250 | /* Possible return values for watchpoint_check (this can't be an enum |
4251 | because of check_errors). */ | |
4252 | /* The watchpoint has been deleted. */ | |
4253 | #define WP_DELETED 1 | |
4254 | /* The value has changed. */ | |
4255 | #define WP_VALUE_CHANGED 2 | |
4256 | /* The value has not changed. */ | |
4257 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
4258 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
4259 | #define WP_IGNORE 4 | |
c906108c SS |
4260 | |
4261 | #define BP_TEMPFLAG 1 | |
4262 | #define BP_HARDWAREFLAG 2 | |
4263 | ||
4a64f543 MS |
4264 | /* Evaluate watchpoint condition expression and check if its value |
4265 | changed. | |
553e4c11 JB |
4266 | |
4267 | P should be a pointer to struct bpstat, but is defined as a void * | |
4268 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
4269 | |
4270 | static int | |
4efb68b1 | 4271 | watchpoint_check (void *p) |
c906108c SS |
4272 | { |
4273 | bpstat bs = (bpstat) p; | |
3a5c3e22 | 4274 | struct watchpoint *b; |
c906108c SS |
4275 | struct frame_info *fr; |
4276 | int within_current_scope; | |
4277 | ||
f431efe5 | 4278 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 4279 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 4280 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 4281 | |
f6bc2008 PA |
4282 | /* If this is a local watchpoint, we only want to check if the |
4283 | watchpoint frame is in scope if the current thread is the thread | |
4284 | that was used to create the watchpoint. */ | |
4285 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 4286 | return WP_IGNORE; |
f6bc2008 | 4287 | |
c906108c SS |
4288 | if (b->exp_valid_block == NULL) |
4289 | within_current_scope = 1; | |
4290 | else | |
4291 | { | |
edb3359d DJ |
4292 | struct frame_info *frame = get_current_frame (); |
4293 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
4294 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
4295 | ||
4a64f543 MS |
4296 | /* in_function_epilogue_p() returns a non-zero value if we're |
4297 | still in the function but the stack frame has already been | |
4298 | invalidated. Since we can't rely on the values of local | |
4299 | variables after the stack has been destroyed, we are treating | |
4300 | the watchpoint in that state as `not changed' without further | |
4301 | checking. Don't mark watchpoints as changed if the current | |
4302 | frame is in an epilogue - even if they are in some other | |
4303 | frame, our view of the stack is likely to be wrong and | |
4304 | frame_find_by_id could error out. */ | |
a0f49112 | 4305 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) |
60e1c644 | 4306 | return WP_IGNORE; |
a0f49112 | 4307 | |
101dcfbe | 4308 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 4309 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
4310 | |
4311 | /* If we've gotten confused in the unwinder, we might have | |
4312 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
4313 | if (within_current_scope) |
4314 | { | |
4315 | struct symbol *function; | |
4316 | ||
4317 | function = get_frame_function (fr); | |
4318 | if (function == NULL | |
4319 | || !contained_in (b->exp_valid_block, | |
4320 | SYMBOL_BLOCK_VALUE (function))) | |
4321 | within_current_scope = 0; | |
4322 | } | |
69fbadd5 | 4323 | |
edb3359d | 4324 | if (within_current_scope) |
c906108c SS |
4325 | /* If we end up stopping, the current frame will get selected |
4326 | in normal_stop. So this call to select_frame won't affect | |
4327 | the user. */ | |
0f7d239c | 4328 | select_frame (fr); |
c906108c | 4329 | } |
c5aa993b | 4330 | |
c906108c SS |
4331 | if (within_current_scope) |
4332 | { | |
4a64f543 MS |
4333 | /* We use value_{,free_to_}mark because it could be a *long* |
4334 | time before we return to the command level and call | |
4335 | free_all_values. We can't call free_all_values because we | |
4336 | might be in the middle of evaluating a function call. */ | |
c906108c | 4337 | |
0cf6dd15 | 4338 | int pc = 0; |
9c06b0b4 | 4339 | struct value *mark; |
fa4727a6 DJ |
4340 | struct value *new_val; |
4341 | ||
3a5c3e22 | 4342 | if (is_masked_watchpoint (&b->base)) |
9c06b0b4 TJB |
4343 | /* Since we don't know the exact trigger address (from |
4344 | stopped_data_address), just tell the user we've triggered | |
4345 | a mask watchpoint. */ | |
4346 | return WP_VALUE_CHANGED; | |
4347 | ||
4348 | mark = value_mark (); | |
0cf6dd15 | 4349 | fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL); |
218d2fc6 | 4350 | |
4a64f543 MS |
4351 | /* We use value_equal_contents instead of value_equal because |
4352 | the latter coerces an array to a pointer, thus comparing just | |
4353 | the address of the array instead of its contents. This is | |
4354 | not what we want. */ | |
fa4727a6 | 4355 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 4356 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 4357 | { |
fa4727a6 DJ |
4358 | if (new_val != NULL) |
4359 | { | |
4360 | release_value (new_val); | |
4361 | value_free_to_mark (mark); | |
4362 | } | |
c906108c SS |
4363 | bs->old_val = b->val; |
4364 | b->val = new_val; | |
fa4727a6 | 4365 | b->val_valid = 1; |
c906108c SS |
4366 | return WP_VALUE_CHANGED; |
4367 | } | |
4368 | else | |
4369 | { | |
60e1c644 | 4370 | /* Nothing changed. */ |
c906108c | 4371 | value_free_to_mark (mark); |
c906108c SS |
4372 | return WP_VALUE_NOT_CHANGED; |
4373 | } | |
4374 | } | |
4375 | else | |
4376 | { | |
79a45e25 PA |
4377 | struct ui_out *uiout = current_uiout; |
4378 | ||
c906108c | 4379 | /* This seems like the only logical thing to do because |
c5aa993b JM |
4380 | if we temporarily ignored the watchpoint, then when |
4381 | we reenter the block in which it is valid it contains | |
4382 | garbage (in the case of a function, it may have two | |
4383 | garbage values, one before and one after the prologue). | |
4384 | So we can't even detect the first assignment to it and | |
4385 | watch after that (since the garbage may or may not equal | |
4386 | the first value assigned). */ | |
348d480f PA |
4387 | /* We print all the stop information in |
4388 | breakpoint_ops->print_it, but in this case, by the time we | |
4389 | call breakpoint_ops->print_it this bp will be deleted | |
4390 | already. So we have no choice but print the information | |
4391 | here. */ | |
9dc5e2a9 | 4392 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
4393 | ui_out_field_string |
4394 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 4395 | ui_out_text (uiout, "\nWatchpoint "); |
3a5c3e22 | 4396 | ui_out_field_int (uiout, "wpnum", b->base.number); |
3e43a32a MS |
4397 | ui_out_text (uiout, |
4398 | " deleted because the program has left the block in\n\ | |
8b93c638 | 4399 | which its expression is valid.\n"); |
4ce44c66 | 4400 | |
cdac0397 | 4401 | /* Make sure the watchpoint's commands aren't executed. */ |
3a5c3e22 | 4402 | decref_counted_command_line (&b->base.commands); |
d0fb5eae | 4403 | watchpoint_del_at_next_stop (b); |
c906108c SS |
4404 | |
4405 | return WP_DELETED; | |
4406 | } | |
4407 | } | |
4408 | ||
18a18393 | 4409 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
4410 | breakpoint location BL. This function does not check if we should |
4411 | stop, only if BL explains the stop. */ | |
4412 | ||
18a18393 | 4413 | static int |
6c95b8df | 4414 | bpstat_check_location (const struct bp_location *bl, |
09ac7c10 TT |
4415 | struct address_space *aspace, CORE_ADDR bp_addr, |
4416 | const struct target_waitstatus *ws) | |
18a18393 VP |
4417 | { |
4418 | struct breakpoint *b = bl->owner; | |
4419 | ||
348d480f | 4420 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
4421 | gdb_assert (b != NULL); |
4422 | ||
09ac7c10 | 4423 | return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws); |
18a18393 VP |
4424 | } |
4425 | ||
3a5c3e22 PA |
4426 | /* Determine if the watched values have actually changed, and we |
4427 | should stop. If not, set BS->stop to 0. */ | |
4428 | ||
18a18393 VP |
4429 | static void |
4430 | bpstat_check_watchpoint (bpstat bs) | |
4431 | { | |
2bdf28a0 | 4432 | const struct bp_location *bl; |
3a5c3e22 | 4433 | struct watchpoint *b; |
2bdf28a0 JK |
4434 | |
4435 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 4436 | bl = bs->bp_location_at; |
2bdf28a0 | 4437 | gdb_assert (bl != NULL); |
3a5c3e22 | 4438 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 4439 | gdb_assert (b != NULL); |
18a18393 | 4440 | |
18a18393 | 4441 | { |
18a18393 VP |
4442 | int must_check_value = 0; |
4443 | ||
3a5c3e22 | 4444 | if (b->base.type == bp_watchpoint) |
18a18393 VP |
4445 | /* For a software watchpoint, we must always check the |
4446 | watched value. */ | |
4447 | must_check_value = 1; | |
4448 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
4449 | /* We have a hardware watchpoint (read, write, or access) | |
4450 | and the target earlier reported an address watched by | |
4451 | this watchpoint. */ | |
4452 | must_check_value = 1; | |
4453 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3a5c3e22 | 4454 | && b->base.type == bp_hardware_watchpoint) |
18a18393 VP |
4455 | /* We were stopped by a hardware watchpoint, but the target could |
4456 | not report the data address. We must check the watchpoint's | |
4457 | value. Access and read watchpoints are out of luck; without | |
4458 | a data address, we can't figure it out. */ | |
4459 | must_check_value = 1; | |
3a5c3e22 | 4460 | |
18a18393 VP |
4461 | if (must_check_value) |
4462 | { | |
3e43a32a MS |
4463 | char *message |
4464 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3a5c3e22 | 4465 | b->base.number); |
18a18393 VP |
4466 | struct cleanup *cleanups = make_cleanup (xfree, message); |
4467 | int e = catch_errors (watchpoint_check, bs, message, | |
4468 | RETURN_MASK_ALL); | |
4469 | do_cleanups (cleanups); | |
4470 | switch (e) | |
4471 | { | |
4472 | case WP_DELETED: | |
4473 | /* We've already printed what needs to be printed. */ | |
4474 | bs->print_it = print_it_done; | |
4475 | /* Stop. */ | |
4476 | break; | |
60e1c644 PA |
4477 | case WP_IGNORE: |
4478 | bs->print_it = print_it_noop; | |
4479 | bs->stop = 0; | |
4480 | break; | |
18a18393 | 4481 | case WP_VALUE_CHANGED: |
3a5c3e22 | 4482 | if (b->base.type == bp_read_watchpoint) |
18a18393 | 4483 | { |
85d721b8 PA |
4484 | /* There are two cases to consider here: |
4485 | ||
4a64f543 | 4486 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
4487 | In that case, trust the target, and always report |
4488 | the watchpoint hit to the user. Even though | |
4489 | reads don't cause value changes, the value may | |
4490 | have changed since the last time it was read, and | |
4491 | since we're not trapping writes, we will not see | |
4492 | those, and as such we should ignore our notion of | |
4493 | old value. | |
4494 | ||
4a64f543 | 4495 | 2. We're watching the triggered memory for both |
85d721b8 PA |
4496 | reads and writes. There are two ways this may |
4497 | happen: | |
4498 | ||
4a64f543 | 4499 | 2.1. This is a target that can't break on data |
85d721b8 PA |
4500 | reads only, but can break on accesses (reads or |
4501 | writes), such as e.g., x86. We detect this case | |
4502 | at the time we try to insert read watchpoints. | |
4503 | ||
4a64f543 | 4504 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
4505 | watchpoints, but, the user set an access or write |
4506 | watchpoint watching the same memory as this read | |
4507 | watchpoint. | |
4508 | ||
4509 | If we're watching memory writes as well as reads, | |
4510 | ignore watchpoint hits when we find that the | |
4511 | value hasn't changed, as reads don't cause | |
4512 | changes. This still gives false positives when | |
4513 | the program writes the same value to memory as | |
4514 | what there was already in memory (we will confuse | |
4515 | it for a read), but it's much better than | |
4516 | nothing. */ | |
4517 | ||
4518 | int other_write_watchpoint = 0; | |
4519 | ||
4520 | if (bl->watchpoint_type == hw_read) | |
4521 | { | |
4522 | struct breakpoint *other_b; | |
4523 | ||
4524 | ALL_BREAKPOINTS (other_b) | |
3a5c3e22 PA |
4525 | if (other_b->type == bp_hardware_watchpoint |
4526 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 4527 | { |
3a5c3e22 PA |
4528 | struct watchpoint *other_w = |
4529 | (struct watchpoint *) other_b; | |
4530 | ||
4531 | if (other_w->watchpoint_triggered | |
4532 | == watch_triggered_yes) | |
4533 | { | |
4534 | other_write_watchpoint = 1; | |
4535 | break; | |
4536 | } | |
85d721b8 PA |
4537 | } |
4538 | } | |
4539 | ||
4540 | if (other_write_watchpoint | |
4541 | || bl->watchpoint_type == hw_access) | |
4542 | { | |
4543 | /* We're watching the same memory for writes, | |
4544 | and the value changed since the last time we | |
4545 | updated it, so this trap must be for a write. | |
4546 | Ignore it. */ | |
4547 | bs->print_it = print_it_noop; | |
4548 | bs->stop = 0; | |
4549 | } | |
18a18393 VP |
4550 | } |
4551 | break; | |
4552 | case WP_VALUE_NOT_CHANGED: | |
3a5c3e22 PA |
4553 | if (b->base.type == bp_hardware_watchpoint |
4554 | || b->base.type == bp_watchpoint) | |
18a18393 VP |
4555 | { |
4556 | /* Don't stop: write watchpoints shouldn't fire if | |
4557 | the value hasn't changed. */ | |
4558 | bs->print_it = print_it_noop; | |
4559 | bs->stop = 0; | |
4560 | } | |
4561 | /* Stop. */ | |
4562 | break; | |
4563 | default: | |
4564 | /* Can't happen. */ | |
4565 | case 0: | |
4566 | /* Error from catch_errors. */ | |
3a5c3e22 | 4567 | printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number); |
d0fb5eae | 4568 | watchpoint_del_at_next_stop (b); |
18a18393 VP |
4569 | /* We've already printed what needs to be printed. */ |
4570 | bs->print_it = print_it_done; | |
4571 | break; | |
4572 | } | |
4573 | } | |
4574 | else /* must_check_value == 0 */ | |
4575 | { | |
4576 | /* This is a case where some watchpoint(s) triggered, but | |
4577 | not at the address of this watchpoint, or else no | |
4578 | watchpoint triggered after all. So don't print | |
4579 | anything for this watchpoint. */ | |
4580 | bs->print_it = print_it_noop; | |
4581 | bs->stop = 0; | |
4582 | } | |
4583 | } | |
4584 | } | |
4585 | ||
4586 | ||
4587 | /* Check conditions (condition proper, frame, thread and ignore count) | |
4588 | of breakpoint referred to by BS. If we should not stop for this | |
4589 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 4590 | |
18a18393 VP |
4591 | static void |
4592 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
4593 | { | |
4594 | int thread_id = pid_to_thread_id (ptid); | |
2bdf28a0 JK |
4595 | const struct bp_location *bl; |
4596 | struct breakpoint *b; | |
4597 | ||
4598 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 4599 | bl = bs->bp_location_at; |
2bdf28a0 | 4600 | gdb_assert (bl != NULL); |
f431efe5 | 4601 | b = bs->breakpoint_at; |
2bdf28a0 | 4602 | gdb_assert (b != NULL); |
18a18393 | 4603 | |
b775012e LM |
4604 | /* Even if the target evaluated the condition on its end and notified GDB, we |
4605 | need to do so again since GDB does not know if we stopped due to a | |
4606 | breakpoint or a single step breakpoint. */ | |
4607 | ||
18a18393 | 4608 | if (frame_id_p (b->frame_id) |
edb3359d | 4609 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 VP |
4610 | bs->stop = 0; |
4611 | else if (bs->stop) | |
4612 | { | |
4613 | int value_is_zero = 0; | |
60e1c644 PA |
4614 | struct expression *cond; |
4615 | ||
7371cf6d PM |
4616 | /* Evaluate Python breakpoints that have a "stop" |
4617 | method implemented. */ | |
4618 | if (b->py_bp_object) | |
4619 | bs->stop = gdbpy_should_stop (b->py_bp_object); | |
4620 | ||
60e1c644 | 4621 | if (is_watchpoint (b)) |
3a5c3e22 PA |
4622 | { |
4623 | struct watchpoint *w = (struct watchpoint *) b; | |
4624 | ||
4625 | cond = w->cond_exp; | |
4626 | } | |
60e1c644 PA |
4627 | else |
4628 | cond = bl->cond; | |
4629 | ||
f431efe5 | 4630 | if (cond && b->disposition != disp_del_at_next_stop) |
18a18393 | 4631 | { |
60e1c644 | 4632 | int within_current_scope = 1; |
3a5c3e22 | 4633 | struct watchpoint * w; |
60e1c644 | 4634 | |
c5bc3a77 DJ |
4635 | /* We use value_mark and value_free_to_mark because it could |
4636 | be a long time before we return to the command level and | |
4637 | call free_all_values. We can't call free_all_values | |
4638 | because we might be in the middle of evaluating a | |
4639 | function call. */ | |
4640 | struct value *mark = value_mark (); | |
4641 | ||
3a5c3e22 PA |
4642 | if (is_watchpoint (b)) |
4643 | w = (struct watchpoint *) b; | |
4644 | else | |
4645 | w = NULL; | |
4646 | ||
edb3359d DJ |
4647 | /* Need to select the frame, with all that implies so that |
4648 | the conditions will have the right context. Because we | |
4649 | use the frame, we will not see an inlined function's | |
4650 | variables when we arrive at a breakpoint at the start | |
4651 | of the inlined function; the current frame will be the | |
4652 | call site. */ | |
3a5c3e22 | 4653 | if (w == NULL || w->cond_exp_valid_block == NULL) |
60e1c644 PA |
4654 | select_frame (get_current_frame ()); |
4655 | else | |
4656 | { | |
4657 | struct frame_info *frame; | |
4658 | ||
4659 | /* For local watchpoint expressions, which particular | |
4660 | instance of a local is being watched matters, so we | |
4661 | keep track of the frame to evaluate the expression | |
4662 | in. To evaluate the condition however, it doesn't | |
4663 | really matter which instantiation of the function | |
4664 | where the condition makes sense triggers the | |
4665 | watchpoint. This allows an expression like "watch | |
4666 | global if q > 10" set in `func', catch writes to | |
4667 | global on all threads that call `func', or catch | |
4668 | writes on all recursive calls of `func' by a single | |
4669 | thread. We simply always evaluate the condition in | |
4670 | the innermost frame that's executing where it makes | |
4671 | sense to evaluate the condition. It seems | |
4672 | intuitive. */ | |
3a5c3e22 | 4673 | frame = block_innermost_frame (w->cond_exp_valid_block); |
60e1c644 PA |
4674 | if (frame != NULL) |
4675 | select_frame (frame); | |
4676 | else | |
4677 | within_current_scope = 0; | |
4678 | } | |
4679 | if (within_current_scope) | |
4680 | value_is_zero | |
4681 | = catch_errors (breakpoint_cond_eval, cond, | |
4682 | "Error in testing breakpoint condition:\n", | |
4683 | RETURN_MASK_ALL); | |
4684 | else | |
4685 | { | |
4686 | warning (_("Watchpoint condition cannot be tested " | |
4687 | "in the current scope")); | |
4688 | /* If we failed to set the right context for this | |
4689 | watchpoint, unconditionally report it. */ | |
4690 | value_is_zero = 0; | |
4691 | } | |
4a64f543 | 4692 | /* FIXME-someday, should give breakpoint #. */ |
c5bc3a77 | 4693 | value_free_to_mark (mark); |
18a18393 | 4694 | } |
60e1c644 PA |
4695 | |
4696 | if (cond && value_is_zero) | |
18a18393 VP |
4697 | { |
4698 | bs->stop = 0; | |
4699 | } | |
4700 | else if (b->thread != -1 && b->thread != thread_id) | |
4701 | { | |
4702 | bs->stop = 0; | |
4703 | } | |
4704 | else if (b->ignore_count > 0) | |
4705 | { | |
4706 | b->ignore_count--; | |
4707 | annotate_ignore_count_change (); | |
4708 | bs->stop = 0; | |
4a64f543 | 4709 | /* Increase the hit count even though we don't stop. */ |
18a18393 | 4710 | ++(b->hit_count); |
8d3788bd | 4711 | observer_notify_breakpoint_modified (b); |
18a18393 VP |
4712 | } |
4713 | } | |
4714 | } | |
4715 | ||
4716 | ||
9709f61c | 4717 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 4718 | BP_ADDR in thread PTID. |
c906108c | 4719 | |
d983da9c | 4720 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
4721 | don't understand this stop. Result is a chain of bpstat's such |
4722 | that: | |
c906108c | 4723 | |
c5aa993b | 4724 | if we don't understand the stop, the result is a null pointer. |
c906108c | 4725 | |
c5aa993b | 4726 | if we understand why we stopped, the result is not null. |
c906108c | 4727 | |
c5aa993b JM |
4728 | Each element of the chain refers to a particular breakpoint or |
4729 | watchpoint at which we have stopped. (We may have stopped for | |
4730 | several reasons concurrently.) | |
c906108c | 4731 | |
c5aa993b JM |
4732 | Each element of the chain has valid next, breakpoint_at, |
4733 | commands, FIXME??? fields. */ | |
c906108c SS |
4734 | |
4735 | bpstat | |
6c95b8df | 4736 | bpstat_stop_status (struct address_space *aspace, |
09ac7c10 TT |
4737 | CORE_ADDR bp_addr, ptid_t ptid, |
4738 | const struct target_waitstatus *ws) | |
c906108c | 4739 | { |
0d381245 | 4740 | struct breakpoint *b = NULL; |
afe38095 | 4741 | struct bp_location *bl; |
20874c92 | 4742 | struct bp_location *loc; |
5760d0ab JK |
4743 | /* First item of allocated bpstat's. */ |
4744 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 4745 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 4746 | bpstat bs; |
20874c92 | 4747 | int ix; |
429374b8 | 4748 | int need_remove_insert; |
f431efe5 | 4749 | int removed_any; |
c906108c | 4750 | |
f431efe5 PA |
4751 | /* First, build the bpstat chain with locations that explain a |
4752 | target stop, while being careful to not set the target running, | |
4753 | as that may invalidate locations (in particular watchpoint | |
4754 | locations are recreated). Resuming will happen here with | |
4755 | breakpoint conditions or watchpoint expressions that include | |
4756 | inferior function calls. */ | |
c5aa993b | 4757 | |
429374b8 JK |
4758 | ALL_BREAKPOINTS (b) |
4759 | { | |
4760 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) | |
4761 | continue; | |
a5606eee | 4762 | |
429374b8 JK |
4763 | for (bl = b->loc; bl != NULL; bl = bl->next) |
4764 | { | |
4a64f543 MS |
4765 | /* For hardware watchpoints, we look only at the first |
4766 | location. The watchpoint_check function will work on the | |
4767 | entire expression, not the individual locations. For | |
4768 | read watchpoints, the watchpoints_triggered function has | |
4769 | checked all locations already. */ | |
429374b8 JK |
4770 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
4771 | break; | |
18a18393 | 4772 | |
429374b8 JK |
4773 | if (bl->shlib_disabled) |
4774 | continue; | |
c5aa993b | 4775 | |
09ac7c10 | 4776 | if (!bpstat_check_location (bl, aspace, bp_addr, ws)) |
429374b8 | 4777 | continue; |
c5aa993b | 4778 | |
4a64f543 MS |
4779 | /* Come here if it's a watchpoint, or if the break address |
4780 | matches. */ | |
c5aa993b | 4781 | |
4a64f543 MS |
4782 | bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to |
4783 | explain stop. */ | |
c5aa993b | 4784 | |
f431efe5 PA |
4785 | /* Assume we stop. Should we find a watchpoint that is not |
4786 | actually triggered, or if the condition of the breakpoint | |
4787 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
4788 | bs->stop = 1; |
4789 | bs->print = 1; | |
d983da9c | 4790 | |
f431efe5 PA |
4791 | /* If this is a scope breakpoint, mark the associated |
4792 | watchpoint as triggered so that we will handle the | |
4793 | out-of-scope event. We'll get to the watchpoint next | |
4794 | iteration. */ | |
d0fb5eae | 4795 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
4796 | { |
4797 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
4798 | ||
4799 | w->watchpoint_triggered = watch_triggered_yes; | |
4800 | } | |
f431efe5 PA |
4801 | } |
4802 | } | |
4803 | ||
4804 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
4805 | { | |
f1310107 | 4806 | if (breakpoint_location_address_match (loc, aspace, bp_addr)) |
f431efe5 | 4807 | { |
5760d0ab | 4808 | bs = bpstat_alloc (loc, &bs_link); |
f431efe5 PA |
4809 | /* For hits of moribund locations, we should just proceed. */ |
4810 | bs->stop = 0; | |
4811 | bs->print = 0; | |
4812 | bs->print_it = print_it_noop; | |
4813 | } | |
4814 | } | |
4815 | ||
edcc5120 TT |
4816 | /* A bit of special processing for shlib breakpoints. We need to |
4817 | process solib loading here, so that the lists of loaded and | |
4818 | unloaded libraries are correct before we handle "catch load" and | |
4819 | "catch unload". */ | |
4820 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
4821 | { | |
5d268276 | 4822 | if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event) |
edcc5120 TT |
4823 | { |
4824 | handle_solib_event (); | |
4825 | break; | |
4826 | } | |
4827 | } | |
4828 | ||
f431efe5 PA |
4829 | /* Now go through the locations that caused the target to stop, and |
4830 | check whether we're interested in reporting this stop to higher | |
4831 | layers, or whether we should resume the target transparently. */ | |
4832 | ||
4833 | removed_any = 0; | |
4834 | ||
5760d0ab | 4835 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
4836 | { |
4837 | if (!bs->stop) | |
4838 | continue; | |
4839 | ||
f431efe5 | 4840 | b = bs->breakpoint_at; |
348d480f PA |
4841 | b->ops->check_status (bs); |
4842 | if (bs->stop) | |
28010a5d | 4843 | { |
348d480f | 4844 | bpstat_check_breakpoint_conditions (bs, ptid); |
f431efe5 | 4845 | |
429374b8 JK |
4846 | if (bs->stop) |
4847 | { | |
4848 | ++(b->hit_count); | |
8d3788bd | 4849 | observer_notify_breakpoint_modified (b); |
c906108c | 4850 | |
4a64f543 | 4851 | /* We will stop here. */ |
429374b8 JK |
4852 | if (b->disposition == disp_disable) |
4853 | { | |
816338b5 SS |
4854 | --(b->enable_count); |
4855 | if (b->enable_count <= 0 | |
4856 | && b->enable_state != bp_permanent) | |
429374b8 | 4857 | b->enable_state = bp_disabled; |
f431efe5 | 4858 | removed_any = 1; |
429374b8 JK |
4859 | } |
4860 | if (b->silent) | |
4861 | bs->print = 0; | |
4862 | bs->commands = b->commands; | |
9add0f1b | 4863 | incref_counted_command_line (bs->commands); |
abf85f46 JK |
4864 | if (command_line_is_silent (bs->commands |
4865 | ? bs->commands->commands : NULL)) | |
4866 | bs->print = 0; | |
429374b8 JK |
4867 | } |
4868 | ||
348d480f | 4869 | } |
a9b3a50f PA |
4870 | |
4871 | /* Print nothing for this entry if we don't stop or don't | |
4872 | print. */ | |
4873 | if (!bs->stop || !bs->print) | |
4874 | bs->print_it = print_it_noop; | |
429374b8 | 4875 | } |
876fa593 | 4876 | |
d983da9c DJ |
4877 | /* If we aren't stopping, the value of some hardware watchpoint may |
4878 | not have changed, but the intermediate memory locations we are | |
4879 | watching may have. Don't bother if we're stopping; this will get | |
4880 | done later. */ | |
d832cb68 | 4881 | need_remove_insert = 0; |
5760d0ab JK |
4882 | if (! bpstat_causes_stop (bs_head)) |
4883 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 4884 | if (!bs->stop |
f431efe5 PA |
4885 | && bs->breakpoint_at |
4886 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 4887 | { |
3a5c3e22 PA |
4888 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
4889 | ||
4890 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 4891 | need_remove_insert = 1; |
d983da9c DJ |
4892 | } |
4893 | ||
d832cb68 | 4894 | if (need_remove_insert) |
2d134ed3 | 4895 | update_global_location_list (1); |
f431efe5 PA |
4896 | else if (removed_any) |
4897 | update_global_location_list (0); | |
d832cb68 | 4898 | |
5760d0ab | 4899 | return bs_head; |
c906108c | 4900 | } |
628fe4e4 JK |
4901 | |
4902 | static void | |
4903 | handle_jit_event (void) | |
4904 | { | |
4905 | struct frame_info *frame; | |
4906 | struct gdbarch *gdbarch; | |
4907 | ||
4908 | /* Switch terminal for any messages produced by | |
4909 | breakpoint_re_set. */ | |
4910 | target_terminal_ours_for_output (); | |
4911 | ||
4912 | frame = get_current_frame (); | |
4913 | gdbarch = get_frame_arch (frame); | |
4914 | ||
4915 | jit_event_handler (gdbarch); | |
4916 | ||
4917 | target_terminal_inferior (); | |
4918 | } | |
4919 | ||
edcc5120 TT |
4920 | /* Handle an solib event by calling solib_add. */ |
4921 | ||
4922 | void | |
4923 | handle_solib_event (void) | |
4924 | { | |
4925 | clear_program_space_solib_cache (current_inferior ()->pspace); | |
4926 | ||
4927 | /* Check for any newly added shared libraries if we're supposed to | |
4928 | be adding them automatically. Switch terminal for any messages | |
4929 | produced by breakpoint_re_set. */ | |
4930 | target_terminal_ours_for_output (); | |
4931 | #ifdef SOLIB_ADD | |
4932 | SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add); | |
4933 | #else | |
4934 | solib_add (NULL, 0, ¤t_target, auto_solib_add); | |
4935 | #endif | |
4936 | target_terminal_inferior (); | |
4937 | } | |
4938 | ||
628fe4e4 JK |
4939 | /* Prepare WHAT final decision for infrun. */ |
4940 | ||
4941 | /* Decide what infrun needs to do with this bpstat. */ | |
4942 | ||
c906108c | 4943 | struct bpstat_what |
0e30163f | 4944 | bpstat_what (bpstat bs_head) |
c906108c | 4945 | { |
c906108c | 4946 | struct bpstat_what retval; |
628fe4e4 | 4947 | int jit_event = 0; |
0e30163f | 4948 | bpstat bs; |
c906108c | 4949 | |
628fe4e4 | 4950 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 4951 | retval.call_dummy = STOP_NONE; |
186c406b | 4952 | retval.is_longjmp = 0; |
628fe4e4 | 4953 | |
0e30163f | 4954 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 4955 | { |
628fe4e4 JK |
4956 | /* Extract this BS's action. After processing each BS, we check |
4957 | if its action overrides all we've seem so far. */ | |
4958 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
4959 | enum bptype bptype; | |
4960 | ||
c906108c | 4961 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
4962 | { |
4963 | /* I suspect this can happen if it was a momentary | |
4964 | breakpoint which has since been deleted. */ | |
4965 | bptype = bp_none; | |
4966 | } | |
20874c92 | 4967 | else |
f431efe5 | 4968 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
4969 | |
4970 | switch (bptype) | |
c906108c SS |
4971 | { |
4972 | case bp_none: | |
628fe4e4 | 4973 | break; |
c906108c SS |
4974 | case bp_breakpoint: |
4975 | case bp_hardware_breakpoint: | |
4976 | case bp_until: | |
4977 | case bp_finish: | |
a9b3a50f | 4978 | case bp_shlib_event: |
c906108c SS |
4979 | if (bs->stop) |
4980 | { | |
4981 | if (bs->print) | |
628fe4e4 | 4982 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 4983 | else |
628fe4e4 | 4984 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
4985 | } |
4986 | else | |
628fe4e4 | 4987 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
4988 | break; |
4989 | case bp_watchpoint: | |
4990 | case bp_hardware_watchpoint: | |
4991 | case bp_read_watchpoint: | |
4992 | case bp_access_watchpoint: | |
4993 | if (bs->stop) | |
4994 | { | |
4995 | if (bs->print) | |
628fe4e4 | 4996 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 4997 | else |
628fe4e4 | 4998 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
4999 | } |
5000 | else | |
628fe4e4 JK |
5001 | { |
5002 | /* There was a watchpoint, but we're not stopping. | |
5003 | This requires no further action. */ | |
5004 | } | |
c906108c SS |
5005 | break; |
5006 | case bp_longjmp: | |
186c406b | 5007 | case bp_exception: |
628fe4e4 | 5008 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; |
186c406b | 5009 | retval.is_longjmp = bptype == bp_longjmp; |
c906108c SS |
5010 | break; |
5011 | case bp_longjmp_resume: | |
186c406b | 5012 | case bp_exception_resume: |
628fe4e4 | 5013 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; |
186c406b | 5014 | retval.is_longjmp = bptype == bp_longjmp_resume; |
c906108c SS |
5015 | break; |
5016 | case bp_step_resume: | |
5017 | if (bs->stop) | |
628fe4e4 JK |
5018 | this_action = BPSTAT_WHAT_STEP_RESUME; |
5019 | else | |
c906108c | 5020 | { |
628fe4e4 JK |
5021 | /* It is for the wrong frame. */ |
5022 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 5023 | } |
c906108c | 5024 | break; |
2c03e5be PA |
5025 | case bp_hp_step_resume: |
5026 | if (bs->stop) | |
5027 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
5028 | else | |
5029 | { | |
5030 | /* It is for the wrong frame. */ | |
5031 | this_action = BPSTAT_WHAT_SINGLE; | |
5032 | } | |
5033 | break; | |
c906108c | 5034 | case bp_watchpoint_scope: |
c4093a6a | 5035 | case bp_thread_event: |
1900040c | 5036 | case bp_overlay_event: |
0fd8e87f | 5037 | case bp_longjmp_master: |
aa7d318d | 5038 | case bp_std_terminate_master: |
186c406b | 5039 | case bp_exception_master: |
628fe4e4 | 5040 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 5041 | break; |
ce78b96d | 5042 | case bp_catchpoint: |
c5aa993b JM |
5043 | if (bs->stop) |
5044 | { | |
5045 | if (bs->print) | |
628fe4e4 | 5046 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 5047 | else |
628fe4e4 | 5048 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
5049 | } |
5050 | else | |
628fe4e4 JK |
5051 | { |
5052 | /* There was a catchpoint, but we're not stopping. | |
5053 | This requires no further action. */ | |
5054 | } | |
5055 | break; | |
628fe4e4 JK |
5056 | case bp_jit_event: |
5057 | jit_event = 1; | |
5058 | this_action = BPSTAT_WHAT_SINGLE; | |
c5aa993b | 5059 | break; |
c906108c | 5060 | case bp_call_dummy: |
53a5351d JM |
5061 | /* Make sure the action is stop (silent or noisy), |
5062 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5063 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 5064 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
5065 | break; |
5066 | case bp_std_terminate: | |
5067 | /* Make sure the action is stop (silent or noisy), | |
5068 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5069 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 5070 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 5071 | break; |
1042e4c0 | 5072 | case bp_tracepoint: |
7a697b8d | 5073 | case bp_fast_tracepoint: |
0fb4aa4b | 5074 | case bp_static_tracepoint: |
1042e4c0 SS |
5075 | /* Tracepoint hits should not be reported back to GDB, and |
5076 | if one got through somehow, it should have been filtered | |
5077 | out already. */ | |
5078 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 5079 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
5080 | break; |
5081 | case bp_gnu_ifunc_resolver: | |
5082 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
5083 | this_action = BPSTAT_WHAT_SINGLE; | |
5084 | break; | |
5085 | case bp_gnu_ifunc_resolver_return: | |
5086 | /* The breakpoint will be removed, execution will restart from the | |
5087 | PC of the former breakpoint. */ | |
5088 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5089 | break; | |
628fe4e4 JK |
5090 | default: |
5091 | internal_error (__FILE__, __LINE__, | |
5092 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 5093 | } |
628fe4e4 JK |
5094 | |
5095 | retval.main_action = max (retval.main_action, this_action); | |
c906108c | 5096 | } |
628fe4e4 | 5097 | |
0e30163f JK |
5098 | /* These operations may affect the bs->breakpoint_at state so they are |
5099 | delayed after MAIN_ACTION is decided above. */ | |
5100 | ||
628fe4e4 JK |
5101 | if (jit_event) |
5102 | { | |
5103 | if (debug_infrun) | |
5104 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n"); | |
5105 | ||
5106 | handle_jit_event (); | |
5107 | } | |
5108 | ||
0e30163f JK |
5109 | for (bs = bs_head; bs != NULL; bs = bs->next) |
5110 | { | |
5111 | struct breakpoint *b = bs->breakpoint_at; | |
5112 | ||
5113 | if (b == NULL) | |
5114 | continue; | |
5115 | switch (b->type) | |
5116 | { | |
5117 | case bp_gnu_ifunc_resolver: | |
5118 | gnu_ifunc_resolver_stop (b); | |
5119 | break; | |
5120 | case bp_gnu_ifunc_resolver_return: | |
5121 | gnu_ifunc_resolver_return_stop (b); | |
5122 | break; | |
5123 | } | |
5124 | } | |
5125 | ||
c906108c SS |
5126 | return retval; |
5127 | } | |
5128 | ||
5129 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
5130 | without hardware support). This isn't related to a specific bpstat, | |
5131 | just to things like whether watchpoints are set. */ | |
5132 | ||
c5aa993b | 5133 | int |
fba45db2 | 5134 | bpstat_should_step (void) |
c906108c SS |
5135 | { |
5136 | struct breakpoint *b; | |
cc59ec59 | 5137 | |
c906108c | 5138 | ALL_BREAKPOINTS (b) |
717a8278 | 5139 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 5140 | return 1; |
c906108c SS |
5141 | return 0; |
5142 | } | |
5143 | ||
67822962 PA |
5144 | int |
5145 | bpstat_causes_stop (bpstat bs) | |
5146 | { | |
5147 | for (; bs != NULL; bs = bs->next) | |
5148 | if (bs->stop) | |
5149 | return 1; | |
5150 | ||
5151 | return 0; | |
5152 | } | |
5153 | ||
c906108c | 5154 | \f |
c5aa993b | 5155 | |
170b53b2 UW |
5156 | /* Compute a string of spaces suitable to indent the next line |
5157 | so it starts at the position corresponding to the table column | |
5158 | named COL_NAME in the currently active table of UIOUT. */ | |
5159 | ||
5160 | static char * | |
5161 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
5162 | { | |
5163 | static char wrap_indent[80]; | |
5164 | int i, total_width, width, align; | |
5165 | char *text; | |
5166 | ||
5167 | total_width = 0; | |
5168 | for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++) | |
5169 | { | |
5170 | if (strcmp (text, col_name) == 0) | |
5171 | { | |
5172 | gdb_assert (total_width < sizeof wrap_indent); | |
5173 | memset (wrap_indent, ' ', total_width); | |
5174 | wrap_indent[total_width] = 0; | |
5175 | ||
5176 | return wrap_indent; | |
5177 | } | |
5178 | ||
5179 | total_width += width + 1; | |
5180 | } | |
5181 | ||
5182 | return NULL; | |
5183 | } | |
5184 | ||
b775012e LM |
5185 | /* Determine if the locations of this breakpoint will have their conditions |
5186 | evaluated by the target, host or a mix of both. Returns the following: | |
5187 | ||
5188 | "host": Host evals condition. | |
5189 | "host or target": Host or Target evals condition. | |
5190 | "target": Target evals condition. | |
5191 | */ | |
5192 | ||
5193 | static const char * | |
5194 | bp_condition_evaluator (struct breakpoint *b) | |
5195 | { | |
5196 | struct bp_location *bl; | |
5197 | char host_evals = 0; | |
5198 | char target_evals = 0; | |
5199 | ||
5200 | if (!b) | |
5201 | return NULL; | |
5202 | ||
5203 | if (!is_breakpoint (b)) | |
5204 | return NULL; | |
5205 | ||
5206 | if (gdb_evaluates_breakpoint_condition_p () | |
5207 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5208 | return condition_evaluation_host; | |
5209 | ||
5210 | for (bl = b->loc; bl; bl = bl->next) | |
5211 | { | |
5212 | if (bl->cond_bytecode) | |
5213 | target_evals++; | |
5214 | else | |
5215 | host_evals++; | |
5216 | } | |
5217 | ||
5218 | if (host_evals && target_evals) | |
5219 | return condition_evaluation_both; | |
5220 | else if (target_evals) | |
5221 | return condition_evaluation_target; | |
5222 | else | |
5223 | return condition_evaluation_host; | |
5224 | } | |
5225 | ||
5226 | /* Determine the breakpoint location's condition evaluator. This is | |
5227 | similar to bp_condition_evaluator, but for locations. */ | |
5228 | ||
5229 | static const char * | |
5230 | bp_location_condition_evaluator (struct bp_location *bl) | |
5231 | { | |
5232 | if (bl && !is_breakpoint (bl->owner)) | |
5233 | return NULL; | |
5234 | ||
5235 | if (gdb_evaluates_breakpoint_condition_p () | |
5236 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5237 | return condition_evaluation_host; | |
5238 | ||
5239 | if (bl && bl->cond_bytecode) | |
5240 | return condition_evaluation_target; | |
5241 | else | |
5242 | return condition_evaluation_host; | |
5243 | } | |
5244 | ||
859825b8 JK |
5245 | /* Print the LOC location out of the list of B->LOC locations. */ |
5246 | ||
170b53b2 UW |
5247 | static void |
5248 | print_breakpoint_location (struct breakpoint *b, | |
5249 | struct bp_location *loc) | |
0d381245 | 5250 | { |
79a45e25 | 5251 | struct ui_out *uiout = current_uiout; |
6c95b8df PA |
5252 | struct cleanup *old_chain = save_current_program_space (); |
5253 | ||
859825b8 JK |
5254 | if (loc != NULL && loc->shlib_disabled) |
5255 | loc = NULL; | |
5256 | ||
6c95b8df PA |
5257 | if (loc != NULL) |
5258 | set_current_program_space (loc->pspace); | |
5259 | ||
56435ebe TT |
5260 | if (b->display_canonical) |
5261 | ui_out_field_string (uiout, "what", b->addr_string); | |
f8eba3c6 | 5262 | else if (loc && loc->source_file) |
0d381245 VP |
5263 | { |
5264 | struct symbol *sym | |
5265 | = find_pc_sect_function (loc->address, loc->section); | |
5266 | if (sym) | |
5267 | { | |
5268 | ui_out_text (uiout, "in "); | |
5269 | ui_out_field_string (uiout, "func", | |
5270 | SYMBOL_PRINT_NAME (sym)); | |
170b53b2 UW |
5271 | ui_out_text (uiout, " "); |
5272 | ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what")); | |
5273 | ui_out_text (uiout, "at "); | |
0d381245 | 5274 | } |
f8eba3c6 | 5275 | ui_out_field_string (uiout, "file", loc->source_file); |
0d381245 VP |
5276 | ui_out_text (uiout, ":"); |
5277 | ||
5278 | if (ui_out_is_mi_like_p (uiout)) | |
5279 | { | |
5280 | struct symtab_and_line sal = find_pc_line (loc->address, 0); | |
5281 | char *fullname = symtab_to_fullname (sal.symtab); | |
5282 | ||
5283 | if (fullname) | |
5284 | ui_out_field_string (uiout, "fullname", fullname); | |
5285 | } | |
5286 | ||
f8eba3c6 | 5287 | ui_out_field_int (uiout, "line", loc->line_number); |
0d381245 | 5288 | } |
859825b8 | 5289 | else if (loc) |
0d381245 | 5290 | { |
f99d8bf4 PA |
5291 | struct ui_file *stb = mem_fileopen (); |
5292 | struct cleanup *stb_chain = make_cleanup_ui_file_delete (stb); | |
170b53b2 | 5293 | |
f99d8bf4 | 5294 | print_address_symbolic (loc->gdbarch, loc->address, stb, |
22e722e1 | 5295 | demangle, ""); |
0d381245 | 5296 | ui_out_field_stream (uiout, "at", stb); |
170b53b2 UW |
5297 | |
5298 | do_cleanups (stb_chain); | |
0d381245 | 5299 | } |
859825b8 JK |
5300 | else |
5301 | ui_out_field_string (uiout, "pending", b->addr_string); | |
6c95b8df | 5302 | |
b775012e LM |
5303 | if (loc && is_breakpoint (b) |
5304 | && breakpoint_condition_evaluation_mode () == condition_evaluation_target | |
5305 | && bp_condition_evaluator (b) == condition_evaluation_both) | |
5306 | { | |
5307 | ui_out_text (uiout, " ("); | |
5308 | ui_out_field_string (uiout, "evaluated-by", | |
5309 | bp_location_condition_evaluator (loc)); | |
5310 | ui_out_text (uiout, ")"); | |
5311 | } | |
5312 | ||
6c95b8df | 5313 | do_cleanups (old_chain); |
0d381245 VP |
5314 | } |
5315 | ||
269b11a2 PA |
5316 | static const char * |
5317 | bptype_string (enum bptype type) | |
c906108c | 5318 | { |
c4093a6a JM |
5319 | struct ep_type_description |
5320 | { | |
5321 | enum bptype type; | |
5322 | char *description; | |
5323 | }; | |
5324 | static struct ep_type_description bptypes[] = | |
c906108c | 5325 | { |
c5aa993b JM |
5326 | {bp_none, "?deleted?"}, |
5327 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 5328 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
5329 | {bp_until, "until"}, |
5330 | {bp_finish, "finish"}, | |
5331 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 5332 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
5333 | {bp_read_watchpoint, "read watchpoint"}, |
5334 | {bp_access_watchpoint, "acc watchpoint"}, | |
5335 | {bp_longjmp, "longjmp"}, | |
5336 | {bp_longjmp_resume, "longjmp resume"}, | |
186c406b TT |
5337 | {bp_exception, "exception"}, |
5338 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 5339 | {bp_step_resume, "step resume"}, |
2c03e5be | 5340 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
5341 | {bp_watchpoint_scope, "watchpoint scope"}, |
5342 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 5343 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 5344 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 5345 | {bp_thread_event, "thread events"}, |
1900040c | 5346 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 5347 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 5348 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 5349 | {bp_exception_master, "exception master"}, |
ce78b96d | 5350 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 5351 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 5352 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 5353 | {bp_static_tracepoint, "static tracepoint"}, |
4efc6507 | 5354 | {bp_jit_event, "jit events"}, |
0e30163f JK |
5355 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
5356 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 5357 | }; |
269b11a2 PA |
5358 | |
5359 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
5360 | || ((int) type != bptypes[(int) type].type)) | |
5361 | internal_error (__FILE__, __LINE__, | |
5362 | _("bptypes table does not describe type #%d."), | |
5363 | (int) type); | |
5364 | ||
5365 | return bptypes[(int) type].description; | |
5366 | } | |
5367 | ||
5368 | /* Print B to gdb_stdout. */ | |
5369 | ||
5370 | static void | |
5371 | print_one_breakpoint_location (struct breakpoint *b, | |
5372 | struct bp_location *loc, | |
5373 | int loc_number, | |
5374 | struct bp_location **last_loc, | |
269b11a2 PA |
5375 | int allflag) |
5376 | { | |
5377 | struct command_line *l; | |
c2c6d25f | 5378 | static char bpenables[] = "nynny"; |
c906108c | 5379 | |
79a45e25 | 5380 | struct ui_out *uiout = current_uiout; |
0d381245 VP |
5381 | int header_of_multiple = 0; |
5382 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
5383 | struct value_print_options opts; |
5384 | ||
5385 | get_user_print_options (&opts); | |
0d381245 VP |
5386 | |
5387 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
5388 | /* See comment in print_one_breakpoint concerning treatment of |
5389 | breakpoints with single disabled location. */ | |
0d381245 VP |
5390 | if (loc == NULL |
5391 | && (b->loc != NULL | |
5392 | && (b->loc->next != NULL || !b->loc->enabled))) | |
5393 | header_of_multiple = 1; | |
5394 | if (loc == NULL) | |
5395 | loc = b->loc; | |
5396 | ||
c4093a6a JM |
5397 | annotate_record (); |
5398 | ||
5399 | /* 1 */ | |
5400 | annotate_field (0); | |
0d381245 VP |
5401 | if (part_of_multiple) |
5402 | { | |
5403 | char *formatted; | |
0c6773c1 | 5404 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
5405 | ui_out_field_string (uiout, "number", formatted); |
5406 | xfree (formatted); | |
5407 | } | |
5408 | else | |
5409 | { | |
5410 | ui_out_field_int (uiout, "number", b->number); | |
5411 | } | |
c4093a6a JM |
5412 | |
5413 | /* 2 */ | |
5414 | annotate_field (1); | |
0d381245 VP |
5415 | if (part_of_multiple) |
5416 | ui_out_field_skip (uiout, "type"); | |
269b11a2 PA |
5417 | else |
5418 | ui_out_field_string (uiout, "type", bptype_string (b->type)); | |
c4093a6a JM |
5419 | |
5420 | /* 3 */ | |
5421 | annotate_field (2); | |
0d381245 VP |
5422 | if (part_of_multiple) |
5423 | ui_out_field_skip (uiout, "disp"); | |
5424 | else | |
2cec12e5 | 5425 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 5426 | |
c4093a6a JM |
5427 | |
5428 | /* 4 */ | |
5429 | annotate_field (3); | |
0d381245 | 5430 | if (part_of_multiple) |
54e52265 | 5431 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 5432 | else |
4a64f543 MS |
5433 | ui_out_field_fmt (uiout, "enabled", "%c", |
5434 | bpenables[(int) b->enable_state]); | |
54e52265 | 5435 | ui_out_spaces (uiout, 2); |
0d381245 | 5436 | |
c4093a6a JM |
5437 | |
5438 | /* 5 and 6 */ | |
3086aeae | 5439 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 5440 | { |
4a64f543 MS |
5441 | /* Although the print_one can possibly print all locations, |
5442 | calling it here is not likely to get any nice result. So, | |
5443 | make sure there's just one location. */ | |
0d381245 | 5444 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 5445 | b->ops->print_one (b, last_loc); |
0d381245 | 5446 | } |
3086aeae DJ |
5447 | else |
5448 | switch (b->type) | |
5449 | { | |
5450 | case bp_none: | |
5451 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 5452 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 5453 | break; |
c906108c | 5454 | |
3086aeae DJ |
5455 | case bp_watchpoint: |
5456 | case bp_hardware_watchpoint: | |
5457 | case bp_read_watchpoint: | |
5458 | case bp_access_watchpoint: | |
3a5c3e22 PA |
5459 | { |
5460 | struct watchpoint *w = (struct watchpoint *) b; | |
5461 | ||
5462 | /* Field 4, the address, is omitted (which makes the columns | |
5463 | not line up too nicely with the headers, but the effect | |
5464 | is relatively readable). */ | |
5465 | if (opts.addressprint) | |
5466 | ui_out_field_skip (uiout, "addr"); | |
5467 | annotate_field (5); | |
5468 | ui_out_field_string (uiout, "what", w->exp_string); | |
5469 | } | |
3086aeae DJ |
5470 | break; |
5471 | ||
3086aeae DJ |
5472 | case bp_breakpoint: |
5473 | case bp_hardware_breakpoint: | |
5474 | case bp_until: | |
5475 | case bp_finish: | |
5476 | case bp_longjmp: | |
5477 | case bp_longjmp_resume: | |
186c406b TT |
5478 | case bp_exception: |
5479 | case bp_exception_resume: | |
3086aeae | 5480 | case bp_step_resume: |
2c03e5be | 5481 | case bp_hp_step_resume: |
3086aeae DJ |
5482 | case bp_watchpoint_scope: |
5483 | case bp_call_dummy: | |
aa7d318d | 5484 | case bp_std_terminate: |
3086aeae DJ |
5485 | case bp_shlib_event: |
5486 | case bp_thread_event: | |
5487 | case bp_overlay_event: | |
0fd8e87f | 5488 | case bp_longjmp_master: |
aa7d318d | 5489 | case bp_std_terminate_master: |
186c406b | 5490 | case bp_exception_master: |
1042e4c0 | 5491 | case bp_tracepoint: |
7a697b8d | 5492 | case bp_fast_tracepoint: |
0fb4aa4b | 5493 | case bp_static_tracepoint: |
4efc6507 | 5494 | case bp_jit_event: |
0e30163f JK |
5495 | case bp_gnu_ifunc_resolver: |
5496 | case bp_gnu_ifunc_resolver_return: | |
79a45b7d | 5497 | if (opts.addressprint) |
3086aeae DJ |
5498 | { |
5499 | annotate_field (4); | |
54e52265 | 5500 | if (header_of_multiple) |
0d381245 | 5501 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 5502 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 5503 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 5504 | else |
5af949e3 UW |
5505 | ui_out_field_core_addr (uiout, "addr", |
5506 | loc->gdbarch, loc->address); | |
3086aeae DJ |
5507 | } |
5508 | annotate_field (5); | |
0d381245 | 5509 | if (!header_of_multiple) |
170b53b2 | 5510 | print_breakpoint_location (b, loc); |
0d381245 | 5511 | if (b->loc) |
a6d9a66e | 5512 | *last_loc = b->loc; |
3086aeae DJ |
5513 | break; |
5514 | } | |
c906108c | 5515 | |
6c95b8df PA |
5516 | |
5517 | /* For backward compatibility, don't display inferiors unless there | |
5518 | are several. */ | |
5519 | if (loc != NULL | |
5520 | && !header_of_multiple | |
5521 | && (allflag | |
5522 | || (!gdbarch_has_global_breakpoints (target_gdbarch) | |
5523 | && (number_of_program_spaces () > 1 | |
5524 | || number_of_inferiors () > 1) | |
4a64f543 MS |
5525 | /* LOC is for existing B, it cannot be in |
5526 | moribund_locations and thus having NULL OWNER. */ | |
6c95b8df PA |
5527 | && loc->owner->type != bp_catchpoint))) |
5528 | { | |
5529 | struct inferior *inf; | |
5530 | int first = 1; | |
5531 | ||
5532 | for (inf = inferior_list; inf != NULL; inf = inf->next) | |
5533 | { | |
5534 | if (inf->pspace == loc->pspace) | |
5535 | { | |
5536 | if (first) | |
5537 | { | |
5538 | first = 0; | |
5539 | ui_out_text (uiout, " inf "); | |
5540 | } | |
5541 | else | |
5542 | ui_out_text (uiout, ", "); | |
5543 | ui_out_text (uiout, plongest (inf->num)); | |
5544 | } | |
5545 | } | |
5546 | } | |
5547 | ||
4a306c9a | 5548 | if (!part_of_multiple) |
c4093a6a | 5549 | { |
4a306c9a JB |
5550 | if (b->thread != -1) |
5551 | { | |
5552 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 5553 | "stop only in" line a little further down. */ |
4a306c9a JB |
5554 | ui_out_text (uiout, " thread "); |
5555 | ui_out_field_int (uiout, "thread", b->thread); | |
5556 | } | |
5557 | else if (b->task != 0) | |
5558 | { | |
5559 | ui_out_text (uiout, " task "); | |
5560 | ui_out_field_int (uiout, "task", b->task); | |
5561 | } | |
c4093a6a | 5562 | } |
f1310107 | 5563 | |
8b93c638 | 5564 | ui_out_text (uiout, "\n"); |
f1310107 | 5565 | |
348d480f | 5566 | if (!part_of_multiple) |
f1310107 TJB |
5567 | b->ops->print_one_detail (b, uiout); |
5568 | ||
0d381245 | 5569 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
5570 | { |
5571 | annotate_field (6); | |
8b93c638 | 5572 | ui_out_text (uiout, "\tstop only in stack frame at "); |
e5dd4106 | 5573 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
818dd999 | 5574 | the frame ID. */ |
5af949e3 UW |
5575 | ui_out_field_core_addr (uiout, "frame", |
5576 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 5577 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
5578 | } |
5579 | ||
28010a5d | 5580 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
5581 | { |
5582 | annotate_field (7); | |
d77f58be | 5583 | if (is_tracepoint (b)) |
1042e4c0 SS |
5584 | ui_out_text (uiout, "\ttrace only if "); |
5585 | else | |
5586 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 | 5587 | ui_out_field_string (uiout, "cond", b->cond_string); |
b775012e LM |
5588 | |
5589 | /* Print whether the target is doing the breakpoint's condition | |
5590 | evaluation. If GDB is doing the evaluation, don't print anything. */ | |
5591 | if (is_breakpoint (b) | |
5592 | && breakpoint_condition_evaluation_mode () | |
5593 | == condition_evaluation_target) | |
5594 | { | |
5595 | ui_out_text (uiout, " ("); | |
5596 | ui_out_field_string (uiout, "evaluated-by", | |
5597 | bp_condition_evaluator (b)); | |
5598 | ui_out_text (uiout, " evals)"); | |
5599 | } | |
0101ce28 JJ |
5600 | ui_out_text (uiout, "\n"); |
5601 | } | |
5602 | ||
0d381245 | 5603 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 5604 | { |
4a64f543 | 5605 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
5606 | ui_out_text (uiout, "\tstop only in thread "); |
5607 | ui_out_field_int (uiout, "thread", b->thread); | |
5608 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
5609 | } |
5610 | ||
63c715c6 | 5611 | if (!part_of_multiple && b->hit_count) |
c4093a6a | 5612 | { |
4a64f543 | 5613 | /* FIXME should make an annotation for this. */ |
c326b90e | 5614 | if (is_catchpoint (b)) |
8b93c638 | 5615 | ui_out_text (uiout, "\tcatchpoint"); |
f196051f SS |
5616 | else if (is_tracepoint (b)) |
5617 | ui_out_text (uiout, "\ttracepoint"); | |
8b93c638 JM |
5618 | else |
5619 | ui_out_text (uiout, "\tbreakpoint"); | |
5620 | ui_out_text (uiout, " already hit "); | |
5621 | ui_out_field_int (uiout, "times", b->hit_count); | |
5622 | if (b->hit_count == 1) | |
5623 | ui_out_text (uiout, " time\n"); | |
5624 | else | |
5625 | ui_out_text (uiout, " times\n"); | |
c4093a6a JM |
5626 | } |
5627 | ||
4a64f543 MS |
5628 | /* Output the count also if it is zero, but only if this is mi. |
5629 | FIXME: Should have a better test for this. */ | |
9dc5e2a9 | 5630 | if (ui_out_is_mi_like_p (uiout)) |
63c715c6 | 5631 | if (!part_of_multiple && b->hit_count == 0) |
fb40c209 | 5632 | ui_out_field_int (uiout, "times", b->hit_count); |
8b93c638 | 5633 | |
0d381245 | 5634 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
5635 | { |
5636 | annotate_field (8); | |
8b93c638 JM |
5637 | ui_out_text (uiout, "\tignore next "); |
5638 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
5639 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 5640 | } |
059fb39f | 5641 | |
816338b5 SS |
5642 | /* Note that an enable count of 1 corresponds to "enable once" |
5643 | behavior, which is reported by the combination of enablement and | |
5644 | disposition, so we don't need to mention it here. */ | |
5645 | if (!part_of_multiple && b->enable_count > 1) | |
5646 | { | |
5647 | annotate_field (8); | |
5648 | ui_out_text (uiout, "\tdisable after "); | |
5649 | /* Tweak the wording to clarify that ignore and enable counts | |
5650 | are distinct, and have additive effect. */ | |
5651 | if (b->ignore_count) | |
5652 | ui_out_text (uiout, "additional "); | |
5653 | else | |
5654 | ui_out_text (uiout, "next "); | |
5655 | ui_out_field_int (uiout, "enable", b->enable_count); | |
5656 | ui_out_text (uiout, " hits\n"); | |
5657 | } | |
5658 | ||
f196051f SS |
5659 | if (!part_of_multiple && is_tracepoint (b)) |
5660 | { | |
5661 | struct tracepoint *tp = (struct tracepoint *) b; | |
5662 | ||
5663 | if (tp->traceframe_usage) | |
5664 | { | |
5665 | ui_out_text (uiout, "\ttrace buffer usage "); | |
5666 | ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage); | |
5667 | ui_out_text (uiout, " bytes\n"); | |
5668 | } | |
5669 | } | |
5670 | ||
9add0f1b | 5671 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 5672 | if (!part_of_multiple && l) |
c4093a6a | 5673 | { |
3b31d625 EZ |
5674 | struct cleanup *script_chain; |
5675 | ||
c4093a6a | 5676 | annotate_field (9); |
3b31d625 | 5677 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 5678 | print_command_lines (uiout, l, 4); |
3b31d625 | 5679 | do_cleanups (script_chain); |
c4093a6a | 5680 | } |
d24317b4 | 5681 | |
d9b3f62e | 5682 | if (is_tracepoint (b)) |
1042e4c0 | 5683 | { |
d9b3f62e PA |
5684 | struct tracepoint *t = (struct tracepoint *) b; |
5685 | ||
5686 | if (!part_of_multiple && t->pass_count) | |
5687 | { | |
5688 | annotate_field (10); | |
5689 | ui_out_text (uiout, "\tpass count "); | |
5690 | ui_out_field_int (uiout, "pass", t->pass_count); | |
5691 | ui_out_text (uiout, " \n"); | |
5692 | } | |
1042e4c0 SS |
5693 | } |
5694 | ||
d24317b4 VP |
5695 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
5696 | { | |
3a5c3e22 PA |
5697 | if (is_watchpoint (b)) |
5698 | { | |
5699 | struct watchpoint *w = (struct watchpoint *) b; | |
5700 | ||
5701 | ui_out_field_string (uiout, "original-location", w->exp_string); | |
5702 | } | |
5703 | else if (b->addr_string) | |
d24317b4 | 5704 | ui_out_field_string (uiout, "original-location", b->addr_string); |
d24317b4 | 5705 | } |
c4093a6a | 5706 | } |
c5aa993b | 5707 | |
0d381245 VP |
5708 | static void |
5709 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 5710 | struct bp_location **last_loc, |
6c95b8df | 5711 | int allflag) |
0d381245 | 5712 | { |
8d3788bd | 5713 | struct cleanup *bkpt_chain; |
79a45e25 | 5714 | struct ui_out *uiout = current_uiout; |
8d3788bd VP |
5715 | |
5716 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); | |
5717 | ||
12c5a436 | 5718 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); |
8d3788bd | 5719 | do_cleanups (bkpt_chain); |
0d381245 VP |
5720 | |
5721 | /* If this breakpoint has custom print function, | |
5722 | it's already printed. Otherwise, print individual | |
5723 | locations, if any. */ | |
5724 | if (b->ops == NULL || b->ops->print_one == NULL) | |
5725 | { | |
4a64f543 MS |
5726 | /* If breakpoint has a single location that is disabled, we |
5727 | print it as if it had several locations, since otherwise it's | |
5728 | hard to represent "breakpoint enabled, location disabled" | |
5729 | situation. | |
5730 | ||
5731 | Note that while hardware watchpoints have several locations | |
a3be7890 | 5732 | internally, that's not a property exposed to user. */ |
0d381245 | 5733 | if (b->loc |
a5606eee | 5734 | && !is_hardware_watchpoint (b) |
8d3788bd | 5735 | && (b->loc->next || !b->loc->enabled)) |
0d381245 VP |
5736 | { |
5737 | struct bp_location *loc; | |
5738 | int n = 1; | |
8d3788bd | 5739 | |
0d381245 | 5740 | for (loc = b->loc; loc; loc = loc->next, ++n) |
8d3788bd VP |
5741 | { |
5742 | struct cleanup *inner2 = | |
5743 | make_cleanup_ui_out_tuple_begin_end (uiout, NULL); | |
5744 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); | |
5745 | do_cleanups (inner2); | |
5746 | } | |
0d381245 VP |
5747 | } |
5748 | } | |
5749 | } | |
5750 | ||
a6d9a66e UW |
5751 | static int |
5752 | breakpoint_address_bits (struct breakpoint *b) | |
5753 | { | |
5754 | int print_address_bits = 0; | |
5755 | struct bp_location *loc; | |
5756 | ||
5757 | for (loc = b->loc; loc; loc = loc->next) | |
5758 | { | |
c7437ca6 PA |
5759 | int addr_bit; |
5760 | ||
5761 | /* Software watchpoints that aren't watching memory don't have | |
5762 | an address to print. */ | |
5763 | if (b->type == bp_watchpoint && loc->watchpoint_type == -1) | |
5764 | continue; | |
5765 | ||
5766 | addr_bit = gdbarch_addr_bit (loc->gdbarch); | |
a6d9a66e UW |
5767 | if (addr_bit > print_address_bits) |
5768 | print_address_bits = addr_bit; | |
5769 | } | |
5770 | ||
5771 | return print_address_bits; | |
5772 | } | |
0d381245 | 5773 | |
c4093a6a JM |
5774 | struct captured_breakpoint_query_args |
5775 | { | |
5776 | int bnum; | |
5777 | }; | |
c5aa993b | 5778 | |
c4093a6a | 5779 | static int |
2b65245e | 5780 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
5781 | { |
5782 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 5783 | struct breakpoint *b; |
a6d9a66e | 5784 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 5785 | |
c4093a6a JM |
5786 | ALL_BREAKPOINTS (b) |
5787 | { | |
5788 | if (args->bnum == b->number) | |
c5aa993b | 5789 | { |
12c5a436 | 5790 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 5791 | return GDB_RC_OK; |
c5aa993b | 5792 | } |
c4093a6a JM |
5793 | } |
5794 | return GDB_RC_NONE; | |
5795 | } | |
c5aa993b | 5796 | |
c4093a6a | 5797 | enum gdb_rc |
4a64f543 MS |
5798 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, |
5799 | char **error_message) | |
c4093a6a JM |
5800 | { |
5801 | struct captured_breakpoint_query_args args; | |
cc59ec59 | 5802 | |
c4093a6a JM |
5803 | args.bnum = bnum; |
5804 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4a64f543 | 5805 | an error. */ |
b0b13bb4 DJ |
5806 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
5807 | error_message, RETURN_MASK_ALL) < 0) | |
5808 | return GDB_RC_FAIL; | |
5809 | else | |
5810 | return GDB_RC_OK; | |
c4093a6a | 5811 | } |
c5aa993b | 5812 | |
09d682a4 TT |
5813 | /* Return true if this breakpoint was set by the user, false if it is |
5814 | internal or momentary. */ | |
5815 | ||
5816 | int | |
5817 | user_breakpoint_p (struct breakpoint *b) | |
5818 | { | |
46c6471b | 5819 | return b->number > 0; |
09d682a4 TT |
5820 | } |
5821 | ||
7f3b0473 | 5822 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
5823 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
5824 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
5825 | FILTER is non-NULL, call it on each breakpoint and only include the | |
5826 | ones for which it returns non-zero. Return the total number of | |
5827 | breakpoints listed. */ | |
c906108c | 5828 | |
d77f58be | 5829 | static int |
e5a67952 | 5830 | breakpoint_1 (char *args, int allflag, |
4a64f543 | 5831 | int (*filter) (const struct breakpoint *)) |
c4093a6a | 5832 | { |
52f0bd74 | 5833 | struct breakpoint *b; |
a6d9a66e | 5834 | struct bp_location *last_loc = NULL; |
7f3b0473 | 5835 | int nr_printable_breakpoints; |
3b31d625 | 5836 | struct cleanup *bkpttbl_chain; |
79a45b7d | 5837 | struct value_print_options opts; |
a6d9a66e | 5838 | int print_address_bits = 0; |
269b11a2 | 5839 | int print_type_col_width = 14; |
79a45e25 | 5840 | struct ui_out *uiout = current_uiout; |
269b11a2 | 5841 | |
79a45b7d TT |
5842 | get_user_print_options (&opts); |
5843 | ||
4a64f543 MS |
5844 | /* Compute the number of rows in the table, as well as the size |
5845 | required for address fields. */ | |
7f3b0473 AC |
5846 | nr_printable_breakpoints = 0; |
5847 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
5848 | { |
5849 | /* If we have a filter, only list the breakpoints it accepts. */ | |
5850 | if (filter && !filter (b)) | |
5851 | continue; | |
5852 | ||
5853 | /* If we have an "args" string, it is a list of breakpoints to | |
5854 | accept. Skip the others. */ | |
5855 | if (args != NULL && *args != '\0') | |
5856 | { | |
5857 | if (allflag && parse_and_eval_long (args) != b->number) | |
5858 | continue; | |
5859 | if (!allflag && !number_is_in_list (args, b->number)) | |
5860 | continue; | |
5861 | } | |
269b11a2 | 5862 | |
e5a67952 MS |
5863 | if (allflag || user_breakpoint_p (b)) |
5864 | { | |
5865 | int addr_bit, type_len; | |
a6d9a66e | 5866 | |
e5a67952 MS |
5867 | addr_bit = breakpoint_address_bits (b); |
5868 | if (addr_bit > print_address_bits) | |
5869 | print_address_bits = addr_bit; | |
269b11a2 | 5870 | |
e5a67952 MS |
5871 | type_len = strlen (bptype_string (b->type)); |
5872 | if (type_len > print_type_col_width) | |
5873 | print_type_col_width = type_len; | |
5874 | ||
5875 | nr_printable_breakpoints++; | |
5876 | } | |
5877 | } | |
7f3b0473 | 5878 | |
79a45b7d | 5879 | if (opts.addressprint) |
3b31d625 | 5880 | bkpttbl_chain |
3e43a32a MS |
5881 | = make_cleanup_ui_out_table_begin_end (uiout, 6, |
5882 | nr_printable_breakpoints, | |
3b31d625 | 5883 | "BreakpointTable"); |
8b93c638 | 5884 | else |
3b31d625 | 5885 | bkpttbl_chain |
3e43a32a MS |
5886 | = make_cleanup_ui_out_table_begin_end (uiout, 5, |
5887 | nr_printable_breakpoints, | |
3b31d625 | 5888 | "BreakpointTable"); |
8b93c638 | 5889 | |
7f3b0473 | 5890 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
5891 | annotate_breakpoints_headers (); |
5892 | if (nr_printable_breakpoints > 0) | |
5893 | annotate_field (0); | |
4a64f543 | 5894 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
5895 | if (nr_printable_breakpoints > 0) |
5896 | annotate_field (1); | |
269b11a2 | 5897 | ui_out_table_header (uiout, print_type_col_width, ui_left, |
4a64f543 | 5898 | "type", "Type"); /* 2 */ |
d7faa9e7 AC |
5899 | if (nr_printable_breakpoints > 0) |
5900 | annotate_field (2); | |
4a64f543 | 5901 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ |
d7faa9e7 AC |
5902 | if (nr_printable_breakpoints > 0) |
5903 | annotate_field (3); | |
54e52265 | 5904 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 5905 | if (opts.addressprint) |
e5a67952 MS |
5906 | { |
5907 | if (nr_printable_breakpoints > 0) | |
5908 | annotate_field (4); | |
5909 | if (print_address_bits <= 32) | |
5910 | ui_out_table_header (uiout, 10, ui_left, | |
5911 | "addr", "Address"); /* 5 */ | |
5912 | else | |
5913 | ui_out_table_header (uiout, 18, ui_left, | |
5914 | "addr", "Address"); /* 5 */ | |
5915 | } | |
d7faa9e7 AC |
5916 | if (nr_printable_breakpoints > 0) |
5917 | annotate_field (5); | |
5918 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
5919 | ui_out_table_body (uiout); | |
5920 | if (nr_printable_breakpoints > 0) | |
5921 | annotate_breakpoints_table (); | |
7f3b0473 | 5922 | |
c4093a6a | 5923 | ALL_BREAKPOINTS (b) |
e5a67952 MS |
5924 | { |
5925 | QUIT; | |
5926 | /* If we have a filter, only list the breakpoints it accepts. */ | |
5927 | if (filter && !filter (b)) | |
5928 | continue; | |
5929 | ||
5930 | /* If we have an "args" string, it is a list of breakpoints to | |
5931 | accept. Skip the others. */ | |
5932 | ||
5933 | if (args != NULL && *args != '\0') | |
5934 | { | |
5935 | if (allflag) /* maintenance info breakpoint */ | |
5936 | { | |
5937 | if (parse_and_eval_long (args) != b->number) | |
5938 | continue; | |
5939 | } | |
5940 | else /* all others */ | |
5941 | { | |
5942 | if (!number_is_in_list (args, b->number)) | |
5943 | continue; | |
5944 | } | |
5945 | } | |
5946 | /* We only print out user settable breakpoints unless the | |
5947 | allflag is set. */ | |
5948 | if (allflag || user_breakpoint_p (b)) | |
12c5a436 | 5949 | print_one_breakpoint (b, &last_loc, allflag); |
e5a67952 MS |
5950 | } |
5951 | ||
3b31d625 | 5952 | do_cleanups (bkpttbl_chain); |
698384cd | 5953 | |
7f3b0473 | 5954 | if (nr_printable_breakpoints == 0) |
c906108c | 5955 | { |
4a64f543 MS |
5956 | /* If there's a filter, let the caller decide how to report |
5957 | empty list. */ | |
d77f58be SS |
5958 | if (!filter) |
5959 | { | |
e5a67952 | 5960 | if (args == NULL || *args == '\0') |
d77f58be SS |
5961 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); |
5962 | else | |
4a64f543 | 5963 | ui_out_message (uiout, 0, |
e5a67952 MS |
5964 | "No breakpoint or watchpoint matching '%s'.\n", |
5965 | args); | |
d77f58be | 5966 | } |
c906108c SS |
5967 | } |
5968 | else | |
c4093a6a | 5969 | { |
a6d9a66e UW |
5970 | if (last_loc && !server_command) |
5971 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 5972 | } |
c906108c | 5973 | |
4a64f543 | 5974 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 5975 | there have been breakpoints? */ |
c906108c | 5976 | annotate_breakpoints_table_end (); |
d77f58be SS |
5977 | |
5978 | return nr_printable_breakpoints; | |
c906108c SS |
5979 | } |
5980 | ||
ad443146 SS |
5981 | /* Display the value of default-collect in a way that is generally |
5982 | compatible with the breakpoint list. */ | |
5983 | ||
5984 | static void | |
5985 | default_collect_info (void) | |
5986 | { | |
79a45e25 PA |
5987 | struct ui_out *uiout = current_uiout; |
5988 | ||
ad443146 SS |
5989 | /* If it has no value (which is frequently the case), say nothing; a |
5990 | message like "No default-collect." gets in user's face when it's | |
5991 | not wanted. */ | |
5992 | if (!*default_collect) | |
5993 | return; | |
5994 | ||
5995 | /* The following phrase lines up nicely with per-tracepoint collect | |
5996 | actions. */ | |
5997 | ui_out_text (uiout, "default collect "); | |
5998 | ui_out_field_string (uiout, "default-collect", default_collect); | |
5999 | ui_out_text (uiout, " \n"); | |
6000 | } | |
6001 | ||
c906108c | 6002 | static void |
e5a67952 | 6003 | breakpoints_info (char *args, int from_tty) |
c906108c | 6004 | { |
e5a67952 | 6005 | breakpoint_1 (args, 0, NULL); |
ad443146 SS |
6006 | |
6007 | default_collect_info (); | |
d77f58be SS |
6008 | } |
6009 | ||
6010 | static void | |
e5a67952 | 6011 | watchpoints_info (char *args, int from_tty) |
d77f58be | 6012 | { |
e5a67952 | 6013 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
79a45e25 | 6014 | struct ui_out *uiout = current_uiout; |
d77f58be SS |
6015 | |
6016 | if (num_printed == 0) | |
6017 | { | |
e5a67952 | 6018 | if (args == NULL || *args == '\0') |
d77f58be SS |
6019 | ui_out_message (uiout, 0, "No watchpoints.\n"); |
6020 | else | |
e5a67952 | 6021 | ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args); |
d77f58be | 6022 | } |
c906108c SS |
6023 | } |
6024 | ||
7a292a7a | 6025 | static void |
e5a67952 | 6026 | maintenance_info_breakpoints (char *args, int from_tty) |
c906108c | 6027 | { |
e5a67952 | 6028 | breakpoint_1 (args, 1, NULL); |
ad443146 SS |
6029 | |
6030 | default_collect_info (); | |
c906108c SS |
6031 | } |
6032 | ||
0d381245 | 6033 | static int |
714835d5 | 6034 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 6035 | struct program_space *pspace, |
714835d5 | 6036 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
6037 | { |
6038 | struct bp_location *bl = b->loc; | |
cc59ec59 | 6039 | |
0d381245 VP |
6040 | for (; bl; bl = bl->next) |
6041 | { | |
6c95b8df PA |
6042 | if (bl->pspace == pspace |
6043 | && bl->address == pc | |
0d381245 VP |
6044 | && (!overlay_debugging || bl->section == section)) |
6045 | return 1; | |
6046 | } | |
6047 | return 0; | |
6048 | } | |
6049 | ||
672f9b60 | 6050 | /* Print a message describing any user-breakpoints set at PC. This |
6c95b8df PA |
6051 | concerns with logical breakpoints, so we match program spaces, not |
6052 | address spaces. */ | |
c906108c SS |
6053 | |
6054 | static void | |
6c95b8df PA |
6055 | describe_other_breakpoints (struct gdbarch *gdbarch, |
6056 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 6057 | struct obj_section *section, int thread) |
c906108c | 6058 | { |
52f0bd74 AC |
6059 | int others = 0; |
6060 | struct breakpoint *b; | |
c906108c SS |
6061 | |
6062 | ALL_BREAKPOINTS (b) | |
672f9b60 KP |
6063 | others += (user_breakpoint_p (b) |
6064 | && breakpoint_has_pc (b, pspace, pc, section)); | |
c906108c SS |
6065 | if (others > 0) |
6066 | { | |
a3f17187 AC |
6067 | if (others == 1) |
6068 | printf_filtered (_("Note: breakpoint ")); | |
6069 | else /* if (others == ???) */ | |
6070 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 6071 | ALL_BREAKPOINTS (b) |
672f9b60 | 6072 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
6073 | { |
6074 | others--; | |
6075 | printf_filtered ("%d", b->number); | |
6076 | if (b->thread == -1 && thread != -1) | |
6077 | printf_filtered (" (all threads)"); | |
6078 | else if (b->thread != -1) | |
6079 | printf_filtered (" (thread %d)", b->thread); | |
6080 | printf_filtered ("%s%s ", | |
059fb39f | 6081 | ((b->enable_state == bp_disabled |
f8eba3c6 | 6082 | || b->enable_state == bp_call_disabled) |
0d381245 VP |
6083 | ? " (disabled)" |
6084 | : b->enable_state == bp_permanent | |
6085 | ? " (permanent)" | |
6086 | : ""), | |
6087 | (others > 1) ? "," | |
6088 | : ((others == 1) ? " and" : "")); | |
6089 | } | |
a3f17187 | 6090 | printf_filtered (_("also set at pc ")); |
5af949e3 | 6091 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
6092 | printf_filtered (".\n"); |
6093 | } | |
6094 | } | |
6095 | \f | |
c906108c | 6096 | |
e4f237da KB |
6097 | /* Return true iff it is meaningful to use the address member of |
6098 | BPT. For some breakpoint types, the address member is irrelevant | |
6099 | and it makes no sense to attempt to compare it to other addresses | |
6100 | (or use it for any other purpose either). | |
6101 | ||
4a64f543 MS |
6102 | More specifically, each of the following breakpoint types will |
6103 | always have a zero valued address and we don't want to mark | |
6104 | breakpoints of any of these types to be a duplicate of an actual | |
6105 | breakpoint at address zero: | |
e4f237da KB |
6106 | |
6107 | bp_watchpoint | |
2d134ed3 PA |
6108 | bp_catchpoint |
6109 | ||
6110 | */ | |
e4f237da KB |
6111 | |
6112 | static int | |
6113 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
6114 | { | |
6115 | enum bptype type = bpt->type; | |
6116 | ||
2d134ed3 PA |
6117 | return (type != bp_watchpoint && type != bp_catchpoint); |
6118 | } | |
6119 | ||
6120 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
6121 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
6122 | ||
6123 | static int | |
4a64f543 MS |
6124 | watchpoint_locations_match (struct bp_location *loc1, |
6125 | struct bp_location *loc2) | |
2d134ed3 | 6126 | { |
3a5c3e22 PA |
6127 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
6128 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
6129 | ||
6130 | /* Both of them must exist. */ | |
6131 | gdb_assert (w1 != NULL); | |
6132 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 6133 | |
4a64f543 MS |
6134 | /* If the target can evaluate the condition expression in hardware, |
6135 | then we we need to insert both watchpoints even if they are at | |
6136 | the same place. Otherwise the watchpoint will only trigger when | |
6137 | the condition of whichever watchpoint was inserted evaluates to | |
6138 | true, not giving a chance for GDB to check the condition of the | |
6139 | other watchpoint. */ | |
3a5c3e22 | 6140 | if ((w1->cond_exp |
4a64f543 MS |
6141 | && target_can_accel_watchpoint_condition (loc1->address, |
6142 | loc1->length, | |
0cf6dd15 | 6143 | loc1->watchpoint_type, |
3a5c3e22 PA |
6144 | w1->cond_exp)) |
6145 | || (w2->cond_exp | |
4a64f543 MS |
6146 | && target_can_accel_watchpoint_condition (loc2->address, |
6147 | loc2->length, | |
0cf6dd15 | 6148 | loc2->watchpoint_type, |
3a5c3e22 | 6149 | w2->cond_exp))) |
0cf6dd15 TJB |
6150 | return 0; |
6151 | ||
85d721b8 PA |
6152 | /* Note that this checks the owner's type, not the location's. In |
6153 | case the target does not support read watchpoints, but does | |
6154 | support access watchpoints, we'll have bp_read_watchpoint | |
6155 | watchpoints with hw_access locations. Those should be considered | |
6156 | duplicates of hw_read locations. The hw_read locations will | |
6157 | become hw_access locations later. */ | |
2d134ed3 PA |
6158 | return (loc1->owner->type == loc2->owner->type |
6159 | && loc1->pspace->aspace == loc2->pspace->aspace | |
6160 | && loc1->address == loc2->address | |
6161 | && loc1->length == loc2->length); | |
e4f237da KB |
6162 | } |
6163 | ||
6c95b8df PA |
6164 | /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the |
6165 | same breakpoint location. In most targets, this can only be true | |
6166 | if ASPACE1 matches ASPACE2. On targets that have global | |
6167 | breakpoints, the address space doesn't really matter. */ | |
6168 | ||
6169 | static int | |
6170 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, | |
6171 | struct address_space *aspace2, CORE_ADDR addr2) | |
6172 | { | |
6173 | return ((gdbarch_has_global_breakpoints (target_gdbarch) | |
6174 | || aspace1 == aspace2) | |
6175 | && addr1 == addr2); | |
6176 | } | |
6177 | ||
f1310107 TJB |
6178 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
6179 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
6180 | matches ASPACE2. On targets that have global breakpoints, the address | |
6181 | space doesn't really matter. */ | |
6182 | ||
6183 | static int | |
6184 | breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1, | |
6185 | int len1, struct address_space *aspace2, | |
6186 | CORE_ADDR addr2) | |
6187 | { | |
6188 | return ((gdbarch_has_global_breakpoints (target_gdbarch) | |
6189 | || aspace1 == aspace2) | |
6190 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
6191 | } | |
6192 | ||
6193 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
6194 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
6195 | matches the breakpoint's address space. On targets that have global | |
6196 | breakpoints, the address space doesn't really matter. */ | |
6197 | ||
6198 | static int | |
6199 | breakpoint_location_address_match (struct bp_location *bl, | |
6200 | struct address_space *aspace, | |
6201 | CORE_ADDR addr) | |
6202 | { | |
6203 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6204 | aspace, addr) | |
6205 | || (bl->length | |
6206 | && breakpoint_address_match_range (bl->pspace->aspace, | |
6207 | bl->address, bl->length, | |
6208 | aspace, addr))); | |
6209 | } | |
6210 | ||
1e4d1764 YQ |
6211 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
6212 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns | |
6213 | true, otherwise returns false. */ | |
6214 | ||
6215 | static int | |
6216 | tracepoint_locations_match (struct bp_location *loc1, | |
6217 | struct bp_location *loc2) | |
6218 | { | |
6219 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) | |
6220 | /* Since tracepoint locations are never duplicated with others', tracepoint | |
6221 | locations at the same address of different tracepoints are regarded as | |
6222 | different locations. */ | |
6223 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); | |
6224 | else | |
6225 | return 0; | |
6226 | } | |
6227 | ||
2d134ed3 PA |
6228 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
6229 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
6230 | represent the same location. */ | |
6231 | ||
6232 | static int | |
4a64f543 MS |
6233 | breakpoint_locations_match (struct bp_location *loc1, |
6234 | struct bp_location *loc2) | |
2d134ed3 | 6235 | { |
2bdf28a0 JK |
6236 | int hw_point1, hw_point2; |
6237 | ||
6238 | /* Both of them must not be in moribund_locations. */ | |
6239 | gdb_assert (loc1->owner != NULL); | |
6240 | gdb_assert (loc2->owner != NULL); | |
6241 | ||
6242 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
6243 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
6244 | |
6245 | if (hw_point1 != hw_point2) | |
6246 | return 0; | |
6247 | else if (hw_point1) | |
6248 | return watchpoint_locations_match (loc1, loc2); | |
1e4d1764 YQ |
6249 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
6250 | return tracepoint_locations_match (loc1, loc2); | |
2d134ed3 | 6251 | else |
f1310107 TJB |
6252 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
6253 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
6254 | loc2->pspace->aspace, loc2->address) | |
6255 | && loc1->length == loc2->length); | |
2d134ed3 PA |
6256 | } |
6257 | ||
76897487 KB |
6258 | static void |
6259 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
6260 | int bnum, int have_bnum) | |
6261 | { | |
f63fbe86 MS |
6262 | /* The longest string possibly returned by hex_string_custom |
6263 | is 50 chars. These must be at least that big for safety. */ | |
6264 | char astr1[64]; | |
6265 | char astr2[64]; | |
76897487 | 6266 | |
bb599908 PH |
6267 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
6268 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 6269 | if (have_bnum) |
8a3fe4f8 | 6270 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
6271 | bnum, astr1, astr2); |
6272 | else | |
8a3fe4f8 | 6273 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
6274 | } |
6275 | ||
4a64f543 MS |
6276 | /* Adjust a breakpoint's address to account for architectural |
6277 | constraints on breakpoint placement. Return the adjusted address. | |
6278 | Note: Very few targets require this kind of adjustment. For most | |
6279 | targets, this function is simply the identity function. */ | |
76897487 KB |
6280 | |
6281 | static CORE_ADDR | |
a6d9a66e UW |
6282 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
6283 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 6284 | { |
a6d9a66e | 6285 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
6286 | { |
6287 | /* Very few targets need any kind of breakpoint adjustment. */ | |
6288 | return bpaddr; | |
6289 | } | |
88f7da05 KB |
6290 | else if (bptype == bp_watchpoint |
6291 | || bptype == bp_hardware_watchpoint | |
6292 | || bptype == bp_read_watchpoint | |
6293 | || bptype == bp_access_watchpoint | |
fe798b75 | 6294 | || bptype == bp_catchpoint) |
88f7da05 KB |
6295 | { |
6296 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
6297 | have their addresses modified. */ | |
6298 | return bpaddr; | |
6299 | } | |
76897487 KB |
6300 | else |
6301 | { | |
6302 | CORE_ADDR adjusted_bpaddr; | |
6303 | ||
6304 | /* Some targets have architectural constraints on the placement | |
6305 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 6306 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
6307 | |
6308 | /* An adjusted breakpoint address can significantly alter | |
6309 | a user's expectations. Print a warning if an adjustment | |
6310 | is required. */ | |
6311 | if (adjusted_bpaddr != bpaddr) | |
6312 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
6313 | ||
6314 | return adjusted_bpaddr; | |
6315 | } | |
6316 | } | |
6317 | ||
28010a5d PA |
6318 | void |
6319 | init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops, | |
6320 | struct breakpoint *owner) | |
7cc221ef | 6321 | { |
7cc221ef DJ |
6322 | memset (loc, 0, sizeof (*loc)); |
6323 | ||
348d480f PA |
6324 | gdb_assert (ops != NULL); |
6325 | ||
28010a5d PA |
6326 | loc->ops = ops; |
6327 | loc->owner = owner; | |
511a6cd4 | 6328 | loc->cond = NULL; |
b775012e | 6329 | loc->cond_bytecode = NULL; |
0d381245 VP |
6330 | loc->shlib_disabled = 0; |
6331 | loc->enabled = 1; | |
e049a4b5 | 6332 | |
28010a5d | 6333 | switch (owner->type) |
e049a4b5 DJ |
6334 | { |
6335 | case bp_breakpoint: | |
6336 | case bp_until: | |
6337 | case bp_finish: | |
6338 | case bp_longjmp: | |
6339 | case bp_longjmp_resume: | |
186c406b TT |
6340 | case bp_exception: |
6341 | case bp_exception_resume: | |
e049a4b5 | 6342 | case bp_step_resume: |
2c03e5be | 6343 | case bp_hp_step_resume: |
e049a4b5 DJ |
6344 | case bp_watchpoint_scope: |
6345 | case bp_call_dummy: | |
aa7d318d | 6346 | case bp_std_terminate: |
e049a4b5 DJ |
6347 | case bp_shlib_event: |
6348 | case bp_thread_event: | |
6349 | case bp_overlay_event: | |
4efc6507 | 6350 | case bp_jit_event: |
0fd8e87f | 6351 | case bp_longjmp_master: |
aa7d318d | 6352 | case bp_std_terminate_master: |
186c406b | 6353 | case bp_exception_master: |
0e30163f JK |
6354 | case bp_gnu_ifunc_resolver: |
6355 | case bp_gnu_ifunc_resolver_return: | |
e049a4b5 | 6356 | loc->loc_type = bp_loc_software_breakpoint; |
b775012e | 6357 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
6358 | break; |
6359 | case bp_hardware_breakpoint: | |
6360 | loc->loc_type = bp_loc_hardware_breakpoint; | |
b775012e | 6361 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
6362 | break; |
6363 | case bp_hardware_watchpoint: | |
6364 | case bp_read_watchpoint: | |
6365 | case bp_access_watchpoint: | |
6366 | loc->loc_type = bp_loc_hardware_watchpoint; | |
6367 | break; | |
6368 | case bp_watchpoint: | |
ce78b96d | 6369 | case bp_catchpoint: |
15c3d785 PA |
6370 | case bp_tracepoint: |
6371 | case bp_fast_tracepoint: | |
0fb4aa4b | 6372 | case bp_static_tracepoint: |
e049a4b5 DJ |
6373 | loc->loc_type = bp_loc_other; |
6374 | break; | |
6375 | default: | |
e2e0b3e5 | 6376 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
6377 | } |
6378 | ||
f431efe5 | 6379 | loc->refc = 1; |
28010a5d PA |
6380 | } |
6381 | ||
6382 | /* Allocate a struct bp_location. */ | |
6383 | ||
6384 | static struct bp_location * | |
6385 | allocate_bp_location (struct breakpoint *bpt) | |
6386 | { | |
348d480f PA |
6387 | return bpt->ops->allocate_location (bpt); |
6388 | } | |
7cc221ef | 6389 | |
f431efe5 PA |
6390 | static void |
6391 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 | 6392 | { |
348d480f | 6393 | loc->ops->dtor (loc); |
fe3f5fa8 VP |
6394 | xfree (loc); |
6395 | } | |
6396 | ||
f431efe5 PA |
6397 | /* Increment reference count. */ |
6398 | ||
6399 | static void | |
6400 | incref_bp_location (struct bp_location *bl) | |
6401 | { | |
6402 | ++bl->refc; | |
6403 | } | |
6404 | ||
6405 | /* Decrement reference count. If the reference count reaches 0, | |
6406 | destroy the bp_location. Sets *BLP to NULL. */ | |
6407 | ||
6408 | static void | |
6409 | decref_bp_location (struct bp_location **blp) | |
6410 | { | |
0807b50c PA |
6411 | gdb_assert ((*blp)->refc > 0); |
6412 | ||
f431efe5 PA |
6413 | if (--(*blp)->refc == 0) |
6414 | free_bp_location (*blp); | |
6415 | *blp = NULL; | |
6416 | } | |
6417 | ||
346774a9 | 6418 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 6419 | |
346774a9 PA |
6420 | static void |
6421 | add_to_breakpoint_chain (struct breakpoint *b) | |
c906108c | 6422 | { |
346774a9 | 6423 | struct breakpoint *b1; |
c906108c | 6424 | |
346774a9 PA |
6425 | /* Add this breakpoint to the end of the chain so that a list of |
6426 | breakpoints will come out in order of increasing numbers. */ | |
6427 | ||
6428 | b1 = breakpoint_chain; | |
6429 | if (b1 == 0) | |
6430 | breakpoint_chain = b; | |
6431 | else | |
6432 | { | |
6433 | while (b1->next) | |
6434 | b1 = b1->next; | |
6435 | b1->next = b; | |
6436 | } | |
6437 | } | |
6438 | ||
6439 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
6440 | ||
6441 | static void | |
6442 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
6443 | struct gdbarch *gdbarch, | |
28010a5d | 6444 | enum bptype bptype, |
c0a91b2b | 6445 | const struct breakpoint_ops *ops) |
346774a9 | 6446 | { |
c906108c | 6447 | memset (b, 0, sizeof (*b)); |
2219d63c | 6448 | |
348d480f PA |
6449 | gdb_assert (ops != NULL); |
6450 | ||
28010a5d | 6451 | b->ops = ops; |
4d28f7a8 | 6452 | b->type = bptype; |
a6d9a66e | 6453 | b->gdbarch = gdbarch; |
c906108c SS |
6454 | b->language = current_language->la_language; |
6455 | b->input_radix = input_radix; | |
6456 | b->thread = -1; | |
b5de0fa7 | 6457 | b->enable_state = bp_enabled; |
c906108c SS |
6458 | b->next = 0; |
6459 | b->silent = 0; | |
6460 | b->ignore_count = 0; | |
6461 | b->commands = NULL; | |
818dd999 | 6462 | b->frame_id = null_frame_id; |
0d381245 | 6463 | b->condition_not_parsed = 0; |
84f4c1fe | 6464 | b->py_bp_object = NULL; |
d0fb5eae | 6465 | b->related_breakpoint = b; |
346774a9 PA |
6466 | } |
6467 | ||
6468 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
6469 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
6470 | |
6471 | static struct breakpoint * | |
6472 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 6473 | enum bptype bptype, |
c0a91b2b | 6474 | const struct breakpoint_ops *ops) |
346774a9 PA |
6475 | { |
6476 | struct breakpoint *b = XNEW (struct breakpoint); | |
6477 | ||
348d480f | 6478 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
c56053d2 | 6479 | add_to_breakpoint_chain (b); |
0d381245 VP |
6480 | return b; |
6481 | } | |
6482 | ||
0e30163f JK |
6483 | /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function |
6484 | resolutions should be made as the user specified the location explicitly | |
6485 | enough. */ | |
6486 | ||
0d381245 | 6487 | static void |
0e30163f | 6488 | set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) |
0d381245 | 6489 | { |
2bdf28a0 JK |
6490 | gdb_assert (loc->owner != NULL); |
6491 | ||
0d381245 | 6492 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 6493 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 6494 | || is_tracepoint (loc->owner)) |
0d381245 | 6495 | { |
0e30163f | 6496 | int is_gnu_ifunc; |
2c02bd72 | 6497 | const char *function_name; |
0e30163f | 6498 | |
2c02bd72 | 6499 | find_pc_partial_function_gnu_ifunc (loc->address, &function_name, |
0e30163f JK |
6500 | NULL, NULL, &is_gnu_ifunc); |
6501 | ||
6502 | if (is_gnu_ifunc && !explicit_loc) | |
6503 | { | |
6504 | struct breakpoint *b = loc->owner; | |
6505 | ||
6506 | gdb_assert (loc->pspace == current_program_space); | |
2c02bd72 | 6507 | if (gnu_ifunc_resolve_name (function_name, |
0e30163f JK |
6508 | &loc->requested_address)) |
6509 | { | |
6510 | /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */ | |
6511 | loc->address = adjust_breakpoint_address (loc->gdbarch, | |
6512 | loc->requested_address, | |
6513 | b->type); | |
6514 | } | |
6515 | else if (b->type == bp_breakpoint && b->loc == loc | |
6516 | && loc->next == NULL && b->related_breakpoint == b) | |
6517 | { | |
6518 | /* Create only the whole new breakpoint of this type but do not | |
6519 | mess more complicated breakpoints with multiple locations. */ | |
6520 | b->type = bp_gnu_ifunc_resolver; | |
6521 | } | |
6522 | } | |
6523 | ||
2c02bd72 DE |
6524 | if (function_name) |
6525 | loc->function_name = xstrdup (function_name); | |
0d381245 VP |
6526 | } |
6527 | } | |
6528 | ||
a6d9a66e | 6529 | /* Attempt to determine architecture of location identified by SAL. */ |
1bfeeb0f | 6530 | struct gdbarch * |
a6d9a66e UW |
6531 | get_sal_arch (struct symtab_and_line sal) |
6532 | { | |
6533 | if (sal.section) | |
6534 | return get_objfile_arch (sal.section->objfile); | |
6535 | if (sal.symtab) | |
6536 | return get_objfile_arch (sal.symtab->objfile); | |
6537 | ||
6538 | return NULL; | |
6539 | } | |
6540 | ||
346774a9 PA |
6541 | /* Low level routine for partially initializing a breakpoint of type |
6542 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 6543 | file name, and line number are provided by SAL. |
0d381245 VP |
6544 | |
6545 | It is expected that the caller will complete the initialization of | |
6546 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 6547 | information regarding the creation of a new breakpoint. */ |
0d381245 | 6548 | |
346774a9 PA |
6549 | static void |
6550 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 6551 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 6552 | const struct breakpoint_ops *ops) |
0d381245 | 6553 | { |
28010a5d | 6554 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 6555 | |
3742cc8b | 6556 | add_location_to_breakpoint (b, &sal); |
0d381245 | 6557 | |
6c95b8df PA |
6558 | if (bptype != bp_catchpoint) |
6559 | gdb_assert (sal.pspace != NULL); | |
6560 | ||
f8eba3c6 TT |
6561 | /* Store the program space that was used to set the breakpoint, |
6562 | except for ordinary breakpoints, which are independent of the | |
6563 | program space. */ | |
6564 | if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) | |
6565 | b->pspace = sal.pspace; | |
0d381245 | 6566 | |
c906108c | 6567 | breakpoints_changed (); |
346774a9 | 6568 | } |
c906108c | 6569 | |
346774a9 PA |
6570 | /* set_raw_breakpoint is a low level routine for allocating and |
6571 | partially initializing a breakpoint of type BPTYPE. The newly | |
6572 | created breakpoint's address, section, source file name, and line | |
6573 | number are provided by SAL. The newly created and partially | |
6574 | initialized breakpoint is added to the breakpoint chain and | |
6575 | is also returned as the value of this function. | |
6576 | ||
6577 | It is expected that the caller will complete the initialization of | |
6578 | the newly created breakpoint struct as well as output any status | |
6579 | information regarding the creation of a new breakpoint. In | |
6580 | particular, set_raw_breakpoint does NOT set the breakpoint | |
6581 | number! Care should be taken to not allow an error to occur | |
6582 | prior to completing the initialization of the breakpoint. If this | |
6583 | should happen, a bogus breakpoint will be left on the chain. */ | |
6584 | ||
6585 | struct breakpoint * | |
6586 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
348d480f | 6587 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 6588 | const struct breakpoint_ops *ops) |
346774a9 PA |
6589 | { |
6590 | struct breakpoint *b = XNEW (struct breakpoint); | |
6591 | ||
348d480f | 6592 | init_raw_breakpoint (b, gdbarch, sal, bptype, ops); |
c56053d2 | 6593 | add_to_breakpoint_chain (b); |
c906108c SS |
6594 | return b; |
6595 | } | |
6596 | ||
c2c6d25f JM |
6597 | |
6598 | /* Note that the breakpoint object B describes a permanent breakpoint | |
6599 | instruction, hard-wired into the inferior's code. */ | |
6600 | void | |
6601 | make_breakpoint_permanent (struct breakpoint *b) | |
6602 | { | |
0d381245 | 6603 | struct bp_location *bl; |
cc59ec59 | 6604 | |
b5de0fa7 | 6605 | b->enable_state = bp_permanent; |
c2c6d25f | 6606 | |
4a64f543 MS |
6607 | /* By definition, permanent breakpoints are already present in the |
6608 | code. Mark all locations as inserted. For now, | |
6609 | make_breakpoint_permanent is called in just one place, so it's | |
6610 | hard to say if it's reasonable to have permanent breakpoint with | |
e5dd4106 | 6611 | multiple locations or not, but it's easy to implement. */ |
0d381245 VP |
6612 | for (bl = b->loc; bl; bl = bl->next) |
6613 | bl->inserted = 1; | |
c2c6d25f JM |
6614 | } |
6615 | ||
53a5351d | 6616 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
6617 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
6618 | initiated the operation. */ | |
c906108c SS |
6619 | |
6620 | void | |
186c406b | 6621 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 6622 | { |
35df4500 | 6623 | struct breakpoint *b, *b_tmp; |
186c406b | 6624 | int thread = tp->num; |
0fd8e87f UW |
6625 | |
6626 | /* To avoid having to rescan all objfile symbols at every step, | |
6627 | we maintain a list of continually-inserted but always disabled | |
6628 | longjmp "master" breakpoints. Here, we simply create momentary | |
6629 | clones of those and enable them for the requested thread. */ | |
35df4500 | 6630 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 6631 | if (b->pspace == current_program_space |
186c406b TT |
6632 | && (b->type == bp_longjmp_master |
6633 | || b->type == bp_exception_master)) | |
0fd8e87f | 6634 | { |
06edf0c0 PA |
6635 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
6636 | struct breakpoint *clone; | |
cc59ec59 | 6637 | |
06edf0c0 PA |
6638 | clone = momentary_breakpoint_from_master (b, type, |
6639 | &momentary_breakpoint_ops); | |
0fd8e87f UW |
6640 | clone->thread = thread; |
6641 | } | |
186c406b TT |
6642 | |
6643 | tp->initiating_frame = frame; | |
c906108c SS |
6644 | } |
6645 | ||
611c83ae | 6646 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 6647 | void |
611c83ae | 6648 | delete_longjmp_breakpoint (int thread) |
c906108c | 6649 | { |
35df4500 | 6650 | struct breakpoint *b, *b_tmp; |
c906108c | 6651 | |
35df4500 | 6652 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 6653 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
6654 | { |
6655 | if (b->thread == thread) | |
6656 | delete_breakpoint (b); | |
6657 | } | |
c906108c SS |
6658 | } |
6659 | ||
f59f708a PA |
6660 | void |
6661 | delete_longjmp_breakpoint_at_next_stop (int thread) | |
6662 | { | |
6663 | struct breakpoint *b, *b_tmp; | |
6664 | ||
6665 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
6666 | if (b->type == bp_longjmp || b->type == bp_exception) | |
6667 | { | |
6668 | if (b->thread == thread) | |
6669 | b->disposition = disp_del_at_next_stop; | |
6670 | } | |
6671 | } | |
6672 | ||
1900040c MS |
6673 | void |
6674 | enable_overlay_breakpoints (void) | |
6675 | { | |
52f0bd74 | 6676 | struct breakpoint *b; |
1900040c MS |
6677 | |
6678 | ALL_BREAKPOINTS (b) | |
6679 | if (b->type == bp_overlay_event) | |
6680 | { | |
6681 | b->enable_state = bp_enabled; | |
b60e7edf | 6682 | update_global_location_list (1); |
c02f5703 | 6683 | overlay_events_enabled = 1; |
1900040c MS |
6684 | } |
6685 | } | |
6686 | ||
6687 | void | |
6688 | disable_overlay_breakpoints (void) | |
6689 | { | |
52f0bd74 | 6690 | struct breakpoint *b; |
1900040c MS |
6691 | |
6692 | ALL_BREAKPOINTS (b) | |
6693 | if (b->type == bp_overlay_event) | |
6694 | { | |
6695 | b->enable_state = bp_disabled; | |
b60e7edf | 6696 | update_global_location_list (0); |
c02f5703 | 6697 | overlay_events_enabled = 0; |
1900040c MS |
6698 | } |
6699 | } | |
6700 | ||
aa7d318d TT |
6701 | /* Set an active std::terminate breakpoint for each std::terminate |
6702 | master breakpoint. */ | |
6703 | void | |
6704 | set_std_terminate_breakpoint (void) | |
6705 | { | |
35df4500 | 6706 | struct breakpoint *b, *b_tmp; |
aa7d318d | 6707 | |
35df4500 | 6708 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
6709 | if (b->pspace == current_program_space |
6710 | && b->type == bp_std_terminate_master) | |
6711 | { | |
06edf0c0 PA |
6712 | momentary_breakpoint_from_master (b, bp_std_terminate, |
6713 | &momentary_breakpoint_ops); | |
aa7d318d TT |
6714 | } |
6715 | } | |
6716 | ||
6717 | /* Delete all the std::terminate breakpoints. */ | |
6718 | void | |
6719 | delete_std_terminate_breakpoint (void) | |
6720 | { | |
35df4500 | 6721 | struct breakpoint *b, *b_tmp; |
aa7d318d | 6722 | |
35df4500 | 6723 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
6724 | if (b->type == bp_std_terminate) |
6725 | delete_breakpoint (b); | |
6726 | } | |
6727 | ||
c4093a6a | 6728 | struct breakpoint * |
a6d9a66e | 6729 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
6730 | { |
6731 | struct breakpoint *b; | |
c4093a6a | 6732 | |
06edf0c0 PA |
6733 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
6734 | &internal_breakpoint_ops); | |
6735 | ||
b5de0fa7 | 6736 | b->enable_state = bp_enabled; |
c4093a6a | 6737 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
6738 | b->addr_string |
6739 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 6740 | |
b60e7edf | 6741 | update_global_location_list_nothrow (1); |
74960c60 | 6742 | |
c4093a6a JM |
6743 | return b; |
6744 | } | |
6745 | ||
6746 | void | |
6747 | remove_thread_event_breakpoints (void) | |
6748 | { | |
35df4500 | 6749 | struct breakpoint *b, *b_tmp; |
c4093a6a | 6750 | |
35df4500 | 6751 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
6752 | if (b->type == bp_thread_event |
6753 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
6754 | delete_breakpoint (b); |
6755 | } | |
6756 | ||
0101ce28 JJ |
6757 | struct lang_and_radix |
6758 | { | |
6759 | enum language lang; | |
6760 | int radix; | |
6761 | }; | |
6762 | ||
4efc6507 DE |
6763 | /* Create a breakpoint for JIT code registration and unregistration. */ |
6764 | ||
6765 | struct breakpoint * | |
6766 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
6767 | { | |
6768 | struct breakpoint *b; | |
6769 | ||
06edf0c0 PA |
6770 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event, |
6771 | &internal_breakpoint_ops); | |
4efc6507 DE |
6772 | update_global_location_list_nothrow (1); |
6773 | return b; | |
6774 | } | |
0101ce28 | 6775 | |
03673fc7 PP |
6776 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
6777 | ||
6778 | void | |
6779 | remove_jit_event_breakpoints (void) | |
6780 | { | |
6781 | struct breakpoint *b, *b_tmp; | |
6782 | ||
6783 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
6784 | if (b->type == bp_jit_event | |
6785 | && b->loc->pspace == current_program_space) | |
6786 | delete_breakpoint (b); | |
6787 | } | |
6788 | ||
cae688ec JJ |
6789 | void |
6790 | remove_solib_event_breakpoints (void) | |
6791 | { | |
35df4500 | 6792 | struct breakpoint *b, *b_tmp; |
cae688ec | 6793 | |
35df4500 | 6794 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
6795 | if (b->type == bp_shlib_event |
6796 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
6797 | delete_breakpoint (b); |
6798 | } | |
6799 | ||
6800 | struct breakpoint * | |
a6d9a66e | 6801 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
cae688ec JJ |
6802 | { |
6803 | struct breakpoint *b; | |
6804 | ||
06edf0c0 PA |
6805 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
6806 | &internal_breakpoint_ops); | |
b60e7edf | 6807 | update_global_location_list_nothrow (1); |
cae688ec JJ |
6808 | return b; |
6809 | } | |
6810 | ||
6811 | /* Disable any breakpoints that are on code in shared libraries. Only | |
6812 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
6813 | ||
6814 | void | |
cb851954 | 6815 | disable_breakpoints_in_shlibs (void) |
cae688ec | 6816 | { |
876fa593 | 6817 | struct bp_location *loc, **locp_tmp; |
cae688ec | 6818 | |
876fa593 | 6819 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 6820 | { |
2bdf28a0 | 6821 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 6822 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 6823 | |
4a64f543 MS |
6824 | /* We apply the check to all breakpoints, including disabled for |
6825 | those with loc->duplicate set. This is so that when breakpoint | |
6826 | becomes enabled, or the duplicate is removed, gdb will try to | |
6827 | insert all breakpoints. If we don't set shlib_disabled here, | |
6828 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 6829 | if (((b->type == bp_breakpoint) |
508ccb1f | 6830 | || (b->type == bp_jit_event) |
1042e4c0 | 6831 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 6832 | || (is_tracepoint (b))) |
6c95b8df | 6833 | && loc->pspace == current_program_space |
0d381245 | 6834 | && !loc->shlib_disabled |
a77053c2 | 6835 | #ifdef PC_SOLIB |
0d381245 | 6836 | && PC_SOLIB (loc->address) |
a77053c2 | 6837 | #else |
6c95b8df | 6838 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 MK |
6839 | #endif |
6840 | ) | |
0d381245 VP |
6841 | { |
6842 | loc->shlib_disabled = 1; | |
6843 | } | |
cae688ec JJ |
6844 | } |
6845 | } | |
6846 | ||
1e4d1764 YQ |
6847 | /* Disable any breakpoints and tracepoints that are in an unloaded shared |
6848 | library. Only apply to enabled breakpoints, disabled ones can just stay | |
4a64f543 | 6849 | disabled. */ |
84acb35a | 6850 | |
75149521 | 6851 | static void |
84acb35a JJ |
6852 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
6853 | { | |
876fa593 | 6854 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
6855 | int disabled_shlib_breaks = 0; |
6856 | ||
c86cf029 VP |
6857 | /* SunOS a.out shared libraries are always mapped, so do not |
6858 | disable breakpoints; they will only be reported as unloaded | |
6859 | through clear_solib when GDB discards its shared library | |
6860 | list. See clear_solib for more information. */ | |
6861 | if (exec_bfd != NULL | |
6862 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
6863 | return; | |
6864 | ||
876fa593 | 6865 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 6866 | { |
2bdf28a0 | 6867 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 6868 | struct breakpoint *b = loc->owner; |
cc59ec59 | 6869 | |
1e4d1764 | 6870 | if (solib->pspace == loc->pspace |
e2dd7057 | 6871 | && !loc->shlib_disabled |
1e4d1764 YQ |
6872 | && (((b->type == bp_breakpoint |
6873 | || b->type == bp_jit_event | |
6874 | || b->type == bp_hardware_breakpoint) | |
6875 | && (loc->loc_type == bp_loc_hardware_breakpoint | |
6876 | || loc->loc_type == bp_loc_software_breakpoint)) | |
6877 | || is_tracepoint (b)) | |
e2dd7057 | 6878 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 6879 | { |
e2dd7057 PP |
6880 | loc->shlib_disabled = 1; |
6881 | /* At this point, we cannot rely on remove_breakpoint | |
6882 | succeeding so we must mark the breakpoint as not inserted | |
6883 | to prevent future errors occurring in remove_breakpoints. */ | |
6884 | loc->inserted = 0; | |
8d3788bd VP |
6885 | |
6886 | /* This may cause duplicate notifications for the same breakpoint. */ | |
6887 | observer_notify_breakpoint_modified (b); | |
6888 | ||
e2dd7057 PP |
6889 | if (!disabled_shlib_breaks) |
6890 | { | |
6891 | target_terminal_ours_for_output (); | |
3e43a32a MS |
6892 | warning (_("Temporarily disabling breakpoints " |
6893 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 6894 | solib->so_name); |
84acb35a | 6895 | } |
e2dd7057 | 6896 | disabled_shlib_breaks = 1; |
84acb35a JJ |
6897 | } |
6898 | } | |
84acb35a JJ |
6899 | } |
6900 | ||
ce78b96d JB |
6901 | /* FORK & VFORK catchpoints. */ |
6902 | ||
e29a4733 PA |
6903 | /* An instance of this type is used to represent a fork or vfork |
6904 | catchpoint. It includes a "struct breakpoint" as a kind of base | |
6905 | class; users downcast to "struct breakpoint *" when needed. A | |
6906 | breakpoint is really of this type iff its ops pointer points to | |
6907 | CATCH_FORK_BREAKPOINT_OPS. */ | |
6908 | ||
6909 | struct fork_catchpoint | |
6910 | { | |
6911 | /* The base class. */ | |
6912 | struct breakpoint base; | |
6913 | ||
6914 | /* Process id of a child process whose forking triggered this | |
6915 | catchpoint. This field is only valid immediately after this | |
6916 | catchpoint has triggered. */ | |
6917 | ptid_t forked_inferior_pid; | |
6918 | }; | |
6919 | ||
4a64f543 MS |
6920 | /* Implement the "insert" breakpoint_ops method for fork |
6921 | catchpoints. */ | |
ce78b96d | 6922 | |
77b06cd7 TJB |
6923 | static int |
6924 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 6925 | { |
77b06cd7 | 6926 | return target_insert_fork_catchpoint (PIDGET (inferior_ptid)); |
ce78b96d JB |
6927 | } |
6928 | ||
4a64f543 MS |
6929 | /* Implement the "remove" breakpoint_ops method for fork |
6930 | catchpoints. */ | |
ce78b96d JB |
6931 | |
6932 | static int | |
77b06cd7 | 6933 | remove_catch_fork (struct bp_location *bl) |
ce78b96d JB |
6934 | { |
6935 | return target_remove_fork_catchpoint (PIDGET (inferior_ptid)); | |
6936 | } | |
6937 | ||
6938 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
6939 | catchpoints. */ | |
6940 | ||
6941 | static int | |
f1310107 | 6942 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
09ac7c10 TT |
6943 | struct address_space *aspace, CORE_ADDR bp_addr, |
6944 | const struct target_waitstatus *ws) | |
ce78b96d | 6945 | { |
e29a4733 PA |
6946 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
6947 | ||
f90263c1 TT |
6948 | if (ws->kind != TARGET_WAITKIND_FORKED) |
6949 | return 0; | |
6950 | ||
6951 | c->forked_inferior_pid = ws->value.related_pid; | |
6952 | return 1; | |
ce78b96d JB |
6953 | } |
6954 | ||
4a64f543 MS |
6955 | /* Implement the "print_it" breakpoint_ops method for fork |
6956 | catchpoints. */ | |
ce78b96d JB |
6957 | |
6958 | static enum print_stop_action | |
348d480f | 6959 | print_it_catch_fork (bpstat bs) |
ce78b96d | 6960 | { |
36dfb11c | 6961 | struct ui_out *uiout = current_uiout; |
348d480f PA |
6962 | struct breakpoint *b = bs->breakpoint_at; |
6963 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; | |
e29a4733 | 6964 | |
ce78b96d | 6965 | annotate_catchpoint (b->number); |
36dfb11c TT |
6966 | if (b->disposition == disp_del) |
6967 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
6968 | else | |
6969 | ui_out_text (uiout, "\nCatchpoint "); | |
6970 | if (ui_out_is_mi_like_p (uiout)) | |
6971 | { | |
6972 | ui_out_field_string (uiout, "reason", | |
6973 | async_reason_lookup (EXEC_ASYNC_FORK)); | |
6974 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
6975 | } | |
6976 | ui_out_field_int (uiout, "bkptno", b->number); | |
6977 | ui_out_text (uiout, " (forked process "); | |
6978 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
6979 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
6980 | return PRINT_SRC_AND_LOC; |
6981 | } | |
6982 | ||
4a64f543 MS |
6983 | /* Implement the "print_one" breakpoint_ops method for fork |
6984 | catchpoints. */ | |
ce78b96d JB |
6985 | |
6986 | static void | |
a6d9a66e | 6987 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 6988 | { |
e29a4733 | 6989 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 6990 | struct value_print_options opts; |
79a45e25 | 6991 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
6992 | |
6993 | get_user_print_options (&opts); | |
6994 | ||
4a64f543 MS |
6995 | /* Field 4, the address, is omitted (which makes the columns not |
6996 | line up too nicely with the headers, but the effect is relatively | |
6997 | readable). */ | |
79a45b7d | 6998 | if (opts.addressprint) |
ce78b96d JB |
6999 | ui_out_field_skip (uiout, "addr"); |
7000 | annotate_field (5); | |
7001 | ui_out_text (uiout, "fork"); | |
e29a4733 | 7002 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
7003 | { |
7004 | ui_out_text (uiout, ", process "); | |
7005 | ui_out_field_int (uiout, "what", | |
e29a4733 | 7006 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
7007 | ui_out_spaces (uiout, 1); |
7008 | } | |
7009 | } | |
7010 | ||
7011 | /* Implement the "print_mention" breakpoint_ops method for fork | |
7012 | catchpoints. */ | |
7013 | ||
7014 | static void | |
7015 | print_mention_catch_fork (struct breakpoint *b) | |
7016 | { | |
7017 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
7018 | } | |
7019 | ||
6149aea9 PA |
7020 | /* Implement the "print_recreate" breakpoint_ops method for fork |
7021 | catchpoints. */ | |
7022 | ||
7023 | static void | |
7024 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
7025 | { | |
7026 | fprintf_unfiltered (fp, "catch fork"); | |
d9b3f62e | 7027 | print_recreate_thread (b, fp); |
6149aea9 PA |
7028 | } |
7029 | ||
ce78b96d JB |
7030 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
7031 | ||
2060206e | 7032 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
ce78b96d | 7033 | |
4a64f543 MS |
7034 | /* Implement the "insert" breakpoint_ops method for vfork |
7035 | catchpoints. */ | |
ce78b96d | 7036 | |
77b06cd7 TJB |
7037 | static int |
7038 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 7039 | { |
77b06cd7 | 7040 | return target_insert_vfork_catchpoint (PIDGET (inferior_ptid)); |
ce78b96d JB |
7041 | } |
7042 | ||
4a64f543 MS |
7043 | /* Implement the "remove" breakpoint_ops method for vfork |
7044 | catchpoints. */ | |
ce78b96d JB |
7045 | |
7046 | static int | |
77b06cd7 | 7047 | remove_catch_vfork (struct bp_location *bl) |
ce78b96d JB |
7048 | { |
7049 | return target_remove_vfork_catchpoint (PIDGET (inferior_ptid)); | |
7050 | } | |
7051 | ||
7052 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
7053 | catchpoints. */ | |
7054 | ||
7055 | static int | |
f1310107 | 7056 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
09ac7c10 TT |
7057 | struct address_space *aspace, CORE_ADDR bp_addr, |
7058 | const struct target_waitstatus *ws) | |
ce78b96d | 7059 | { |
e29a4733 PA |
7060 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
7061 | ||
f90263c1 TT |
7062 | if (ws->kind != TARGET_WAITKIND_VFORKED) |
7063 | return 0; | |
7064 | ||
7065 | c->forked_inferior_pid = ws->value.related_pid; | |
7066 | return 1; | |
ce78b96d JB |
7067 | } |
7068 | ||
4a64f543 MS |
7069 | /* Implement the "print_it" breakpoint_ops method for vfork |
7070 | catchpoints. */ | |
ce78b96d JB |
7071 | |
7072 | static enum print_stop_action | |
348d480f | 7073 | print_it_catch_vfork (bpstat bs) |
ce78b96d | 7074 | { |
36dfb11c | 7075 | struct ui_out *uiout = current_uiout; |
348d480f | 7076 | struct breakpoint *b = bs->breakpoint_at; |
e29a4733 PA |
7077 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
7078 | ||
ce78b96d | 7079 | annotate_catchpoint (b->number); |
36dfb11c TT |
7080 | if (b->disposition == disp_del) |
7081 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
7082 | else | |
7083 | ui_out_text (uiout, "\nCatchpoint "); | |
7084 | if (ui_out_is_mi_like_p (uiout)) | |
7085 | { | |
7086 | ui_out_field_string (uiout, "reason", | |
7087 | async_reason_lookup (EXEC_ASYNC_VFORK)); | |
7088 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
7089 | } | |
7090 | ui_out_field_int (uiout, "bkptno", b->number); | |
7091 | ui_out_text (uiout, " (vforked process "); | |
7092 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
7093 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
7094 | return PRINT_SRC_AND_LOC; |
7095 | } | |
7096 | ||
4a64f543 MS |
7097 | /* Implement the "print_one" breakpoint_ops method for vfork |
7098 | catchpoints. */ | |
ce78b96d JB |
7099 | |
7100 | static void | |
a6d9a66e | 7101 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 7102 | { |
e29a4733 | 7103 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 7104 | struct value_print_options opts; |
79a45e25 | 7105 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
7106 | |
7107 | get_user_print_options (&opts); | |
4a64f543 MS |
7108 | /* Field 4, the address, is omitted (which makes the columns not |
7109 | line up too nicely with the headers, but the effect is relatively | |
7110 | readable). */ | |
79a45b7d | 7111 | if (opts.addressprint) |
ce78b96d JB |
7112 | ui_out_field_skip (uiout, "addr"); |
7113 | annotate_field (5); | |
7114 | ui_out_text (uiout, "vfork"); | |
e29a4733 | 7115 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
7116 | { |
7117 | ui_out_text (uiout, ", process "); | |
7118 | ui_out_field_int (uiout, "what", | |
e29a4733 | 7119 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
7120 | ui_out_spaces (uiout, 1); |
7121 | } | |
7122 | } | |
7123 | ||
7124 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
7125 | catchpoints. */ | |
7126 | ||
7127 | static void | |
7128 | print_mention_catch_vfork (struct breakpoint *b) | |
7129 | { | |
7130 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
7131 | } | |
7132 | ||
6149aea9 PA |
7133 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
7134 | catchpoints. */ | |
7135 | ||
7136 | static void | |
7137 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
7138 | { | |
7139 | fprintf_unfiltered (fp, "catch vfork"); | |
d9b3f62e | 7140 | print_recreate_thread (b, fp); |
6149aea9 PA |
7141 | } |
7142 | ||
ce78b96d JB |
7143 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
7144 | ||
2060206e | 7145 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
ce78b96d | 7146 | |
edcc5120 TT |
7147 | /* An instance of this type is used to represent an solib catchpoint. |
7148 | It includes a "struct breakpoint" as a kind of base class; users | |
7149 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
7150 | really of this type iff its ops pointer points to | |
7151 | CATCH_SOLIB_BREAKPOINT_OPS. */ | |
7152 | ||
7153 | struct solib_catchpoint | |
7154 | { | |
7155 | /* The base class. */ | |
7156 | struct breakpoint base; | |
7157 | ||
7158 | /* True for "catch load", false for "catch unload". */ | |
7159 | unsigned char is_load; | |
7160 | ||
7161 | /* Regular expression to match, if any. COMPILED is only valid when | |
7162 | REGEX is non-NULL. */ | |
7163 | char *regex; | |
7164 | regex_t compiled; | |
7165 | }; | |
7166 | ||
7167 | static void | |
7168 | dtor_catch_solib (struct breakpoint *b) | |
7169 | { | |
7170 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
7171 | ||
7172 | if (self->regex) | |
7173 | regfree (&self->compiled); | |
7174 | xfree (self->regex); | |
7175 | ||
7176 | base_breakpoint_ops.dtor (b); | |
7177 | } | |
7178 | ||
7179 | static int | |
7180 | insert_catch_solib (struct bp_location *ignore) | |
7181 | { | |
7182 | return 0; | |
7183 | } | |
7184 | ||
7185 | static int | |
7186 | remove_catch_solib (struct bp_location *ignore) | |
7187 | { | |
7188 | return 0; | |
7189 | } | |
7190 | ||
7191 | static int | |
7192 | breakpoint_hit_catch_solib (const struct bp_location *bl, | |
7193 | struct address_space *aspace, | |
7194 | CORE_ADDR bp_addr, | |
7195 | const struct target_waitstatus *ws) | |
7196 | { | |
7197 | struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner; | |
7198 | struct breakpoint *other; | |
7199 | ||
7200 | if (ws->kind == TARGET_WAITKIND_LOADED) | |
7201 | return 1; | |
7202 | ||
7203 | ALL_BREAKPOINTS (other) | |
7204 | { | |
7205 | struct bp_location *other_bl; | |
7206 | ||
7207 | if (other == bl->owner) | |
7208 | continue; | |
7209 | ||
7210 | if (other->type != bp_shlib_event) | |
7211 | continue; | |
7212 | ||
7213 | if (self->base.pspace != NULL && other->pspace != self->base.pspace) | |
7214 | continue; | |
7215 | ||
7216 | for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next) | |
7217 | { | |
7218 | if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) | |
7219 | return 1; | |
7220 | } | |
7221 | } | |
7222 | ||
7223 | return 0; | |
7224 | } | |
7225 | ||
7226 | static void | |
7227 | check_status_catch_solib (struct bpstats *bs) | |
7228 | { | |
7229 | struct solib_catchpoint *self | |
7230 | = (struct solib_catchpoint *) bs->breakpoint_at; | |
7231 | int ix; | |
7232 | ||
7233 | if (self->is_load) | |
7234 | { | |
7235 | struct so_list *iter; | |
7236 | ||
7237 | for (ix = 0; | |
7238 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
7239 | ix, iter); | |
7240 | ++ix) | |
7241 | { | |
7242 | if (!self->regex | |
7243 | || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0) | |
7244 | return; | |
7245 | } | |
7246 | } | |
7247 | else | |
7248 | { | |
7249 | char *iter; | |
7250 | ||
7251 | for (ix = 0; | |
7252 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
7253 | ix, iter); | |
7254 | ++ix) | |
7255 | { | |
7256 | if (!self->regex | |
7257 | || regexec (&self->compiled, iter, 0, NULL, 0) == 0) | |
7258 | return; | |
7259 | } | |
7260 | } | |
7261 | ||
7262 | bs->stop = 0; | |
7263 | bs->print_it = print_it_noop; | |
7264 | } | |
7265 | ||
7266 | static enum print_stop_action | |
7267 | print_it_catch_solib (bpstat bs) | |
7268 | { | |
7269 | struct breakpoint *b = bs->breakpoint_at; | |
7270 | struct ui_out *uiout = current_uiout; | |
7271 | ||
7272 | annotate_catchpoint (b->number); | |
7273 | if (b->disposition == disp_del) | |
7274 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
7275 | else | |
7276 | ui_out_text (uiout, "\nCatchpoint "); | |
7277 | ui_out_field_int (uiout, "bkptno", b->number); | |
7278 | ui_out_text (uiout, "\n"); | |
7279 | if (ui_out_is_mi_like_p (uiout)) | |
7280 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
7281 | print_solib_event (1); | |
7282 | return PRINT_SRC_AND_LOC; | |
7283 | } | |
7284 | ||
7285 | static void | |
7286 | print_one_catch_solib (struct breakpoint *b, struct bp_location **locs) | |
7287 | { | |
7288 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
7289 | struct value_print_options opts; | |
7290 | struct ui_out *uiout = current_uiout; | |
7291 | char *msg; | |
7292 | ||
7293 | get_user_print_options (&opts); | |
7294 | /* Field 4, the address, is omitted (which makes the columns not | |
7295 | line up too nicely with the headers, but the effect is relatively | |
7296 | readable). */ | |
7297 | if (opts.addressprint) | |
7298 | { | |
7299 | annotate_field (4); | |
7300 | ui_out_field_skip (uiout, "addr"); | |
7301 | } | |
7302 | ||
7303 | annotate_field (5); | |
7304 | if (self->is_load) | |
7305 | { | |
7306 | if (self->regex) | |
7307 | msg = xstrprintf (_("load of library matching %s"), self->regex); | |
7308 | else | |
7309 | msg = xstrdup (_("load of library")); | |
7310 | } | |
7311 | else | |
7312 | { | |
7313 | if (self->regex) | |
7314 | msg = xstrprintf (_("unload of library matching %s"), self->regex); | |
7315 | else | |
7316 | msg = xstrdup (_("unload of library")); | |
7317 | } | |
7318 | ui_out_field_string (uiout, "what", msg); | |
7319 | xfree (msg); | |
7320 | } | |
7321 | ||
7322 | static void | |
7323 | print_mention_catch_solib (struct breakpoint *b) | |
7324 | { | |
7325 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
7326 | ||
7327 | printf_filtered (_("Catchpoint %d (%s)"), b->number, | |
7328 | self->is_load ? "load" : "unload"); | |
7329 | } | |
7330 | ||
7331 | static void | |
7332 | print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp) | |
7333 | { | |
7334 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
7335 | ||
7336 | fprintf_unfiltered (fp, "%s %s", | |
7337 | b->disposition == disp_del ? "tcatch" : "catch", | |
7338 | self->is_load ? "load" : "unload"); | |
7339 | if (self->regex) | |
7340 | fprintf_unfiltered (fp, " %s", self->regex); | |
7341 | fprintf_unfiltered (fp, "\n"); | |
7342 | } | |
7343 | ||
7344 | static struct breakpoint_ops catch_solib_breakpoint_ops; | |
7345 | ||
7346 | /* A helper function that does all the work for "catch load" and | |
7347 | "catch unload". */ | |
7348 | ||
7349 | static void | |
7350 | catch_load_or_unload (char *arg, int from_tty, int is_load, | |
7351 | struct cmd_list_element *command) | |
7352 | { | |
7353 | struct solib_catchpoint *c; | |
7354 | struct gdbarch *gdbarch = get_current_arch (); | |
7355 | int tempflag; | |
7356 | regex_t compiled; | |
7357 | struct cleanup *cleanup; | |
7358 | ||
7359 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
7360 | ||
7361 | if (!arg) | |
7362 | arg = ""; | |
7363 | arg = skip_spaces (arg); | |
7364 | ||
7365 | c = XCNEW (struct solib_catchpoint); | |
7366 | cleanup = make_cleanup (xfree, c); | |
7367 | ||
7368 | if (*arg != '\0') | |
7369 | { | |
7370 | int errcode; | |
7371 | ||
7372 | errcode = regcomp (&c->compiled, arg, REG_NOSUB); | |
7373 | if (errcode != 0) | |
7374 | { | |
7375 | char *err = get_regcomp_error (errcode, &c->compiled); | |
7376 | ||
7377 | make_cleanup (xfree, err); | |
7378 | error (_("Invalid regexp (%s): %s"), err, arg); | |
7379 | } | |
7380 | c->regex = xstrdup (arg); | |
7381 | } | |
7382 | ||
7383 | c->is_load = is_load; | |
7384 | init_catchpoint (&c->base, gdbarch, tempflag, NULL, | |
7385 | &catch_solib_breakpoint_ops); | |
7386 | ||
7387 | discard_cleanups (cleanup); | |
7388 | install_breakpoint (0, &c->base, 1); | |
7389 | } | |
7390 | ||
7391 | static void | |
7392 | catch_load_command_1 (char *arg, int from_tty, | |
7393 | struct cmd_list_element *command) | |
7394 | { | |
7395 | catch_load_or_unload (arg, from_tty, 1, command); | |
7396 | } | |
7397 | ||
7398 | static void | |
7399 | catch_unload_command_1 (char *arg, int from_tty, | |
7400 | struct cmd_list_element *command) | |
7401 | { | |
7402 | catch_load_or_unload (arg, from_tty, 0, command); | |
7403 | } | |
7404 | ||
fa3064dd YQ |
7405 | DEF_VEC_I(int); |
7406 | ||
be5c67c1 PA |
7407 | /* An instance of this type is used to represent a syscall catchpoint. |
7408 | It includes a "struct breakpoint" as a kind of base class; users | |
7409 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
7410 | really of this type iff its ops pointer points to | |
7411 | CATCH_SYSCALL_BREAKPOINT_OPS. */ | |
7412 | ||
7413 | struct syscall_catchpoint | |
7414 | { | |
7415 | /* The base class. */ | |
7416 | struct breakpoint base; | |
7417 | ||
7418 | /* Syscall numbers used for the 'catch syscall' feature. If no | |
7419 | syscall has been specified for filtering, its value is NULL. | |
7420 | Otherwise, it holds a list of all syscalls to be caught. The | |
7421 | list elements are allocated with xmalloc. */ | |
7422 | VEC(int) *syscalls_to_be_caught; | |
7423 | }; | |
7424 | ||
7425 | /* Implement the "dtor" breakpoint_ops method for syscall | |
7426 | catchpoints. */ | |
7427 | ||
7428 | static void | |
7429 | dtor_catch_syscall (struct breakpoint *b) | |
7430 | { | |
7431 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; | |
7432 | ||
7433 | VEC_free (int, c->syscalls_to_be_caught); | |
348d480f | 7434 | |
2060206e | 7435 | base_breakpoint_ops.dtor (b); |
be5c67c1 PA |
7436 | } |
7437 | ||
fa3064dd YQ |
7438 | static const struct inferior_data *catch_syscall_inferior_data = NULL; |
7439 | ||
7440 | struct catch_syscall_inferior_data | |
7441 | { | |
7442 | /* We keep a count of the number of times the user has requested a | |
7443 | particular syscall to be tracked, and pass this information to the | |
7444 | target. This lets capable targets implement filtering directly. */ | |
7445 | ||
7446 | /* Number of times that "any" syscall is requested. */ | |
7447 | int any_syscall_count; | |
7448 | ||
7449 | /* Count of each system call. */ | |
7450 | VEC(int) *syscalls_counts; | |
7451 | ||
7452 | /* This counts all syscall catch requests, so we can readily determine | |
7453 | if any catching is necessary. */ | |
7454 | int total_syscalls_count; | |
7455 | }; | |
7456 | ||
7457 | static struct catch_syscall_inferior_data* | |
7458 | get_catch_syscall_inferior_data (struct inferior *inf) | |
7459 | { | |
7460 | struct catch_syscall_inferior_data *inf_data; | |
7461 | ||
7462 | inf_data = inferior_data (inf, catch_syscall_inferior_data); | |
7463 | if (inf_data == NULL) | |
7464 | { | |
7465 | inf_data = XZALLOC (struct catch_syscall_inferior_data); | |
7466 | set_inferior_data (inf, catch_syscall_inferior_data, inf_data); | |
7467 | } | |
7468 | ||
7469 | return inf_data; | |
7470 | } | |
7471 | ||
7472 | static void | |
7473 | catch_syscall_inferior_data_cleanup (struct inferior *inf, void *arg) | |
7474 | { | |
7475 | xfree (arg); | |
7476 | } | |
7477 | ||
7478 | ||
a96d9b2e SDJ |
7479 | /* Implement the "insert" breakpoint_ops method for syscall |
7480 | catchpoints. */ | |
7481 | ||
77b06cd7 TJB |
7482 | static int |
7483 | insert_catch_syscall (struct bp_location *bl) | |
a96d9b2e | 7484 | { |
be5c67c1 | 7485 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; |
a96d9b2e | 7486 | struct inferior *inf = current_inferior (); |
fa3064dd YQ |
7487 | struct catch_syscall_inferior_data *inf_data |
7488 | = get_catch_syscall_inferior_data (inf); | |
a96d9b2e | 7489 | |
fa3064dd | 7490 | ++inf_data->total_syscalls_count; |
be5c67c1 | 7491 | if (!c->syscalls_to_be_caught) |
fa3064dd | 7492 | ++inf_data->any_syscall_count; |
a96d9b2e SDJ |
7493 | else |
7494 | { | |
7495 | int i, iter; | |
cc59ec59 | 7496 | |
a96d9b2e | 7497 | for (i = 0; |
be5c67c1 | 7498 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
7499 | i++) |
7500 | { | |
7501 | int elem; | |
cc59ec59 | 7502 | |
fa3064dd | 7503 | if (iter >= VEC_length (int, inf_data->syscalls_counts)) |
a96d9b2e | 7504 | { |
fa3064dd | 7505 | int old_size = VEC_length (int, inf_data->syscalls_counts); |
3e43a32a MS |
7506 | uintptr_t vec_addr_offset |
7507 | = old_size * ((uintptr_t) sizeof (int)); | |
a96d9b2e | 7508 | uintptr_t vec_addr; |
fa3064dd YQ |
7509 | VEC_safe_grow (int, inf_data->syscalls_counts, iter + 1); |
7510 | vec_addr = ((uintptr_t) VEC_address (int, | |
7511 | inf_data->syscalls_counts) | |
7512 | + vec_addr_offset); | |
a96d9b2e SDJ |
7513 | memset ((void *) vec_addr, 0, |
7514 | (iter + 1 - old_size) * sizeof (int)); | |
7515 | } | |
fa3064dd YQ |
7516 | elem = VEC_index (int, inf_data->syscalls_counts, iter); |
7517 | VEC_replace (int, inf_data->syscalls_counts, iter, ++elem); | |
a96d9b2e SDJ |
7518 | } |
7519 | } | |
7520 | ||
77b06cd7 | 7521 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), |
fa3064dd YQ |
7522 | inf_data->total_syscalls_count != 0, |
7523 | inf_data->any_syscall_count, | |
7524 | VEC_length (int, | |
7525 | inf_data->syscalls_counts), | |
7526 | VEC_address (int, | |
7527 | inf_data->syscalls_counts)); | |
a96d9b2e SDJ |
7528 | } |
7529 | ||
7530 | /* Implement the "remove" breakpoint_ops method for syscall | |
7531 | catchpoints. */ | |
7532 | ||
7533 | static int | |
77b06cd7 | 7534 | remove_catch_syscall (struct bp_location *bl) |
a96d9b2e | 7535 | { |
be5c67c1 | 7536 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; |
a96d9b2e | 7537 | struct inferior *inf = current_inferior (); |
fa3064dd YQ |
7538 | struct catch_syscall_inferior_data *inf_data |
7539 | = get_catch_syscall_inferior_data (inf); | |
a96d9b2e | 7540 | |
fa3064dd | 7541 | --inf_data->total_syscalls_count; |
be5c67c1 | 7542 | if (!c->syscalls_to_be_caught) |
fa3064dd | 7543 | --inf_data->any_syscall_count; |
a96d9b2e SDJ |
7544 | else |
7545 | { | |
7546 | int i, iter; | |
cc59ec59 | 7547 | |
a96d9b2e | 7548 | for (i = 0; |
be5c67c1 | 7549 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
7550 | i++) |
7551 | { | |
7552 | int elem; | |
fa3064dd | 7553 | if (iter >= VEC_length (int, inf_data->syscalls_counts)) |
a96d9b2e SDJ |
7554 | /* Shouldn't happen. */ |
7555 | continue; | |
fa3064dd YQ |
7556 | elem = VEC_index (int, inf_data->syscalls_counts, iter); |
7557 | VEC_replace (int, inf_data->syscalls_counts, iter, --elem); | |
a96d9b2e SDJ |
7558 | } |
7559 | } | |
7560 | ||
7561 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
fa3064dd YQ |
7562 | inf_data->total_syscalls_count != 0, |
7563 | inf_data->any_syscall_count, | |
7564 | VEC_length (int, | |
7565 | inf_data->syscalls_counts), | |
3e43a32a | 7566 | VEC_address (int, |
fa3064dd | 7567 | inf_data->syscalls_counts)); |
a96d9b2e SDJ |
7568 | } |
7569 | ||
7570 | /* Implement the "breakpoint_hit" breakpoint_ops method for syscall | |
7571 | catchpoints. */ | |
7572 | ||
7573 | static int | |
f1310107 | 7574 | breakpoint_hit_catch_syscall (const struct bp_location *bl, |
09ac7c10 TT |
7575 | struct address_space *aspace, CORE_ADDR bp_addr, |
7576 | const struct target_waitstatus *ws) | |
a96d9b2e | 7577 | { |
4a64f543 MS |
7578 | /* We must check if we are catching specific syscalls in this |
7579 | breakpoint. If we are, then we must guarantee that the called | |
7580 | syscall is the same syscall we are catching. */ | |
a96d9b2e | 7581 | int syscall_number = 0; |
be5c67c1 PA |
7582 | const struct syscall_catchpoint *c |
7583 | = (const struct syscall_catchpoint *) bl->owner; | |
a96d9b2e | 7584 | |
f90263c1 TT |
7585 | if (ws->kind != TARGET_WAITKIND_SYSCALL_ENTRY |
7586 | && ws->kind != TARGET_WAITKIND_SYSCALL_RETURN) | |
a96d9b2e SDJ |
7587 | return 0; |
7588 | ||
f90263c1 TT |
7589 | syscall_number = ws->value.syscall_number; |
7590 | ||
a96d9b2e | 7591 | /* Now, checking if the syscall is the same. */ |
be5c67c1 | 7592 | if (c->syscalls_to_be_caught) |
a96d9b2e SDJ |
7593 | { |
7594 | int i, iter; | |
cc59ec59 | 7595 | |
a96d9b2e | 7596 | for (i = 0; |
be5c67c1 | 7597 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
7598 | i++) |
7599 | if (syscall_number == iter) | |
7600 | break; | |
7601 | /* Not the same. */ | |
7602 | if (!iter) | |
7603 | return 0; | |
7604 | } | |
7605 | ||
7606 | return 1; | |
7607 | } | |
7608 | ||
7609 | /* Implement the "print_it" breakpoint_ops method for syscall | |
7610 | catchpoints. */ | |
7611 | ||
7612 | static enum print_stop_action | |
348d480f | 7613 | print_it_catch_syscall (bpstat bs) |
a96d9b2e | 7614 | { |
36dfb11c | 7615 | struct ui_out *uiout = current_uiout; |
348d480f | 7616 | struct breakpoint *b = bs->breakpoint_at; |
a96d9b2e SDJ |
7617 | /* These are needed because we want to know in which state a |
7618 | syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY | |
7619 | or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we | |
7620 | must print "called syscall" or "returned from syscall". */ | |
7621 | ptid_t ptid; | |
7622 | struct target_waitstatus last; | |
7623 | struct syscall s; | |
a96d9b2e SDJ |
7624 | char *syscall_id; |
7625 | ||
7626 | get_last_target_status (&ptid, &last); | |
7627 | ||
7628 | get_syscall_by_number (last.value.syscall_number, &s); | |
7629 | ||
7630 | annotate_catchpoint (b->number); | |
7631 | ||
36dfb11c TT |
7632 | if (b->disposition == disp_del) |
7633 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
a96d9b2e | 7634 | else |
36dfb11c TT |
7635 | ui_out_text (uiout, "\nCatchpoint "); |
7636 | if (ui_out_is_mi_like_p (uiout)) | |
7637 | { | |
7638 | ui_out_field_string (uiout, "reason", | |
7639 | async_reason_lookup (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY | |
7640 | ? EXEC_ASYNC_SYSCALL_ENTRY | |
7641 | : EXEC_ASYNC_SYSCALL_RETURN)); | |
7642 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
7643 | } | |
7644 | ui_out_field_int (uiout, "bkptno", b->number); | |
a96d9b2e SDJ |
7645 | |
7646 | if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) | |
36dfb11c TT |
7647 | ui_out_text (uiout, " (call to syscall "); |
7648 | else | |
7649 | ui_out_text (uiout, " (returned from syscall "); | |
a96d9b2e | 7650 | |
36dfb11c TT |
7651 | if (s.name == NULL || ui_out_is_mi_like_p (uiout)) |
7652 | ui_out_field_int (uiout, "syscall-number", last.value.syscall_number); | |
7653 | if (s.name != NULL) | |
7654 | ui_out_field_string (uiout, "syscall-name", s.name); | |
7655 | ||
7656 | ui_out_text (uiout, "), "); | |
a96d9b2e SDJ |
7657 | |
7658 | return PRINT_SRC_AND_LOC; | |
7659 | } | |
7660 | ||
7661 | /* Implement the "print_one" breakpoint_ops method for syscall | |
7662 | catchpoints. */ | |
7663 | ||
7664 | static void | |
7665 | print_one_catch_syscall (struct breakpoint *b, | |
f1310107 | 7666 | struct bp_location **last_loc) |
a96d9b2e | 7667 | { |
be5c67c1 | 7668 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
a96d9b2e | 7669 | struct value_print_options opts; |
79a45e25 | 7670 | struct ui_out *uiout = current_uiout; |
a96d9b2e SDJ |
7671 | |
7672 | get_user_print_options (&opts); | |
4a64f543 MS |
7673 | /* Field 4, the address, is omitted (which makes the columns not |
7674 | line up too nicely with the headers, but the effect is relatively | |
7675 | readable). */ | |
a96d9b2e SDJ |
7676 | if (opts.addressprint) |
7677 | ui_out_field_skip (uiout, "addr"); | |
7678 | annotate_field (5); | |
7679 | ||
be5c67c1 PA |
7680 | if (c->syscalls_to_be_caught |
7681 | && VEC_length (int, c->syscalls_to_be_caught) > 1) | |
a96d9b2e SDJ |
7682 | ui_out_text (uiout, "syscalls \""); |
7683 | else | |
7684 | ui_out_text (uiout, "syscall \""); | |
7685 | ||
be5c67c1 | 7686 | if (c->syscalls_to_be_caught) |
a96d9b2e SDJ |
7687 | { |
7688 | int i, iter; | |
7689 | char *text = xstrprintf ("%s", ""); | |
cc59ec59 | 7690 | |
a96d9b2e | 7691 | for (i = 0; |
be5c67c1 | 7692 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
7693 | i++) |
7694 | { | |
7695 | char *x = text; | |
7696 | struct syscall s; | |
7697 | get_syscall_by_number (iter, &s); | |
7698 | ||
7699 | if (s.name != NULL) | |
7700 | text = xstrprintf ("%s%s, ", text, s.name); | |
7701 | else | |
7702 | text = xstrprintf ("%s%d, ", text, iter); | |
7703 | ||
7704 | /* We have to xfree the last 'text' (now stored at 'x') | |
e5dd4106 | 7705 | because xstrprintf dynamically allocates new space for it |
a96d9b2e SDJ |
7706 | on every call. */ |
7707 | xfree (x); | |
7708 | } | |
7709 | /* Remove the last comma. */ | |
7710 | text[strlen (text) - 2] = '\0'; | |
7711 | ui_out_field_string (uiout, "what", text); | |
7712 | } | |
7713 | else | |
7714 | ui_out_field_string (uiout, "what", "<any syscall>"); | |
7715 | ui_out_text (uiout, "\" "); | |
7716 | } | |
7717 | ||
7718 | /* Implement the "print_mention" breakpoint_ops method for syscall | |
7719 | catchpoints. */ | |
7720 | ||
7721 | static void | |
7722 | print_mention_catch_syscall (struct breakpoint *b) | |
7723 | { | |
be5c67c1 PA |
7724 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
7725 | ||
7726 | if (c->syscalls_to_be_caught) | |
a96d9b2e SDJ |
7727 | { |
7728 | int i, iter; | |
7729 | ||
be5c67c1 | 7730 | if (VEC_length (int, c->syscalls_to_be_caught) > 1) |
a96d9b2e SDJ |
7731 | printf_filtered (_("Catchpoint %d (syscalls"), b->number); |
7732 | else | |
7733 | printf_filtered (_("Catchpoint %d (syscall"), b->number); | |
7734 | ||
7735 | for (i = 0; | |
be5c67c1 | 7736 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
7737 | i++) |
7738 | { | |
7739 | struct syscall s; | |
7740 | get_syscall_by_number (iter, &s); | |
7741 | ||
7742 | if (s.name) | |
7743 | printf_filtered (" '%s' [%d]", s.name, s.number); | |
7744 | else | |
7745 | printf_filtered (" %d", s.number); | |
7746 | } | |
7747 | printf_filtered (")"); | |
7748 | } | |
7749 | else | |
7750 | printf_filtered (_("Catchpoint %d (any syscall)"), | |
7751 | b->number); | |
7752 | } | |
7753 | ||
6149aea9 PA |
7754 | /* Implement the "print_recreate" breakpoint_ops method for syscall |
7755 | catchpoints. */ | |
7756 | ||
7757 | static void | |
7758 | print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp) | |
7759 | { | |
be5c67c1 PA |
7760 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
7761 | ||
6149aea9 PA |
7762 | fprintf_unfiltered (fp, "catch syscall"); |
7763 | ||
be5c67c1 | 7764 | if (c->syscalls_to_be_caught) |
6149aea9 PA |
7765 | { |
7766 | int i, iter; | |
7767 | ||
7768 | for (i = 0; | |
be5c67c1 | 7769 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
6149aea9 PA |
7770 | i++) |
7771 | { | |
7772 | struct syscall s; | |
7773 | ||
7774 | get_syscall_by_number (iter, &s); | |
7775 | if (s.name) | |
7776 | fprintf_unfiltered (fp, " %s", s.name); | |
7777 | else | |
7778 | fprintf_unfiltered (fp, " %d", s.number); | |
7779 | } | |
7780 | } | |
d9b3f62e | 7781 | print_recreate_thread (b, fp); |
6149aea9 PA |
7782 | } |
7783 | ||
a96d9b2e SDJ |
7784 | /* The breakpoint_ops structure to be used in syscall catchpoints. */ |
7785 | ||
2060206e | 7786 | static struct breakpoint_ops catch_syscall_breakpoint_ops; |
a96d9b2e SDJ |
7787 | |
7788 | /* Returns non-zero if 'b' is a syscall catchpoint. */ | |
7789 | ||
7790 | static int | |
7791 | syscall_catchpoint_p (struct breakpoint *b) | |
7792 | { | |
7793 | return (b->ops == &catch_syscall_breakpoint_ops); | |
7794 | } | |
7795 | ||
346774a9 PA |
7796 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
7797 | is non-zero, then make the breakpoint temporary. If COND_STRING is | |
7798 | not NULL, then store it in the breakpoint. OPS, if not NULL, is | |
7799 | the breakpoint_ops structure associated to the catchpoint. */ | |
ce78b96d | 7800 | |
346774a9 PA |
7801 | static void |
7802 | init_catchpoint (struct breakpoint *b, | |
7803 | struct gdbarch *gdbarch, int tempflag, | |
7804 | char *cond_string, | |
c0a91b2b | 7805 | const struct breakpoint_ops *ops) |
c906108c | 7806 | { |
c5aa993b | 7807 | struct symtab_and_line sal; |
346774a9 | 7808 | |
fe39c653 | 7809 | init_sal (&sal); |
6c95b8df | 7810 | sal.pspace = current_program_space; |
c5aa993b | 7811 | |
28010a5d | 7812 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 7813 | |
1b36a34b | 7814 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
b5de0fa7 | 7815 | b->disposition = tempflag ? disp_del : disp_donttouch; |
346774a9 PA |
7816 | } |
7817 | ||
28010a5d | 7818 | void |
3ea46bff | 7819 | install_breakpoint (int internal, struct breakpoint *b, int update_gll) |
c56053d2 PA |
7820 | { |
7821 | add_to_breakpoint_chain (b); | |
3a5c3e22 PA |
7822 | set_breakpoint_number (internal, b); |
7823 | if (!internal) | |
7824 | mention (b); | |
c56053d2 | 7825 | observer_notify_breakpoint_created (b); |
3ea46bff YQ |
7826 | |
7827 | if (update_gll) | |
7828 | update_global_location_list (1); | |
c56053d2 PA |
7829 | } |
7830 | ||
9b70b993 | 7831 | static void |
a6d9a66e UW |
7832 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
7833 | int tempflag, char *cond_string, | |
c0a91b2b | 7834 | const struct breakpoint_ops *ops) |
c906108c | 7835 | { |
e29a4733 | 7836 | struct fork_catchpoint *c = XNEW (struct fork_catchpoint); |
ce78b96d | 7837 | |
e29a4733 PA |
7838 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops); |
7839 | ||
7840 | c->forked_inferior_pid = null_ptid; | |
7841 | ||
3ea46bff | 7842 | install_breakpoint (0, &c->base, 1); |
c906108c SS |
7843 | } |
7844 | ||
fe798b75 JB |
7845 | /* Exec catchpoints. */ |
7846 | ||
b4d90040 PA |
7847 | /* An instance of this type is used to represent an exec catchpoint. |
7848 | It includes a "struct breakpoint" as a kind of base class; users | |
7849 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
7850 | really of this type iff its ops pointer points to | |
7851 | CATCH_EXEC_BREAKPOINT_OPS. */ | |
7852 | ||
7853 | struct exec_catchpoint | |
7854 | { | |
7855 | /* The base class. */ | |
7856 | struct breakpoint base; | |
7857 | ||
7858 | /* Filename of a program whose exec triggered this catchpoint. | |
7859 | This field is only valid immediately after this catchpoint has | |
7860 | triggered. */ | |
7861 | char *exec_pathname; | |
7862 | }; | |
7863 | ||
7864 | /* Implement the "dtor" breakpoint_ops method for exec | |
7865 | catchpoints. */ | |
7866 | ||
7867 | static void | |
7868 | dtor_catch_exec (struct breakpoint *b) | |
7869 | { | |
7870 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; | |
7871 | ||
7872 | xfree (c->exec_pathname); | |
348d480f | 7873 | |
2060206e | 7874 | base_breakpoint_ops.dtor (b); |
b4d90040 PA |
7875 | } |
7876 | ||
77b06cd7 TJB |
7877 | static int |
7878 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 7879 | { |
77b06cd7 | 7880 | return target_insert_exec_catchpoint (PIDGET (inferior_ptid)); |
fe798b75 | 7881 | } |
c906108c | 7882 | |
fe798b75 | 7883 | static int |
77b06cd7 | 7884 | remove_catch_exec (struct bp_location *bl) |
fe798b75 JB |
7885 | { |
7886 | return target_remove_exec_catchpoint (PIDGET (inferior_ptid)); | |
7887 | } | |
c906108c | 7888 | |
fe798b75 | 7889 | static int |
f1310107 | 7890 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
09ac7c10 TT |
7891 | struct address_space *aspace, CORE_ADDR bp_addr, |
7892 | const struct target_waitstatus *ws) | |
fe798b75 | 7893 | { |
b4d90040 PA |
7894 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
7895 | ||
f90263c1 TT |
7896 | if (ws->kind != TARGET_WAITKIND_EXECD) |
7897 | return 0; | |
7898 | ||
7899 | c->exec_pathname = xstrdup (ws->value.execd_pathname); | |
7900 | return 1; | |
fe798b75 | 7901 | } |
c906108c | 7902 | |
fe798b75 | 7903 | static enum print_stop_action |
348d480f | 7904 | print_it_catch_exec (bpstat bs) |
fe798b75 | 7905 | { |
36dfb11c | 7906 | struct ui_out *uiout = current_uiout; |
348d480f | 7907 | struct breakpoint *b = bs->breakpoint_at; |
b4d90040 PA |
7908 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
7909 | ||
fe798b75 | 7910 | annotate_catchpoint (b->number); |
36dfb11c TT |
7911 | if (b->disposition == disp_del) |
7912 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
7913 | else | |
7914 | ui_out_text (uiout, "\nCatchpoint "); | |
7915 | if (ui_out_is_mi_like_p (uiout)) | |
7916 | { | |
7917 | ui_out_field_string (uiout, "reason", | |
7918 | async_reason_lookup (EXEC_ASYNC_EXEC)); | |
7919 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
7920 | } | |
7921 | ui_out_field_int (uiout, "bkptno", b->number); | |
7922 | ui_out_text (uiout, " (exec'd "); | |
7923 | ui_out_field_string (uiout, "new-exec", c->exec_pathname); | |
7924 | ui_out_text (uiout, "), "); | |
7925 | ||
fe798b75 | 7926 | return PRINT_SRC_AND_LOC; |
c906108c SS |
7927 | } |
7928 | ||
fe798b75 | 7929 | static void |
a6d9a66e | 7930 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 | 7931 | { |
b4d90040 | 7932 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
fe798b75 | 7933 | struct value_print_options opts; |
79a45e25 | 7934 | struct ui_out *uiout = current_uiout; |
fe798b75 JB |
7935 | |
7936 | get_user_print_options (&opts); | |
7937 | ||
7938 | /* Field 4, the address, is omitted (which makes the columns | |
7939 | not line up too nicely with the headers, but the effect | |
7940 | is relatively readable). */ | |
7941 | if (opts.addressprint) | |
7942 | ui_out_field_skip (uiout, "addr"); | |
7943 | annotate_field (5); | |
7944 | ui_out_text (uiout, "exec"); | |
b4d90040 | 7945 | if (c->exec_pathname != NULL) |
fe798b75 JB |
7946 | { |
7947 | ui_out_text (uiout, ", program \""); | |
b4d90040 | 7948 | ui_out_field_string (uiout, "what", c->exec_pathname); |
fe798b75 JB |
7949 | ui_out_text (uiout, "\" "); |
7950 | } | |
7951 | } | |
7952 | ||
7953 | static void | |
7954 | print_mention_catch_exec (struct breakpoint *b) | |
7955 | { | |
7956 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
7957 | } | |
7958 | ||
6149aea9 PA |
7959 | /* Implement the "print_recreate" breakpoint_ops method for exec |
7960 | catchpoints. */ | |
7961 | ||
7962 | static void | |
7963 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
7964 | { | |
7965 | fprintf_unfiltered (fp, "catch exec"); | |
d9b3f62e | 7966 | print_recreate_thread (b, fp); |
6149aea9 PA |
7967 | } |
7968 | ||
2060206e | 7969 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
fe798b75 | 7970 | |
a96d9b2e SDJ |
7971 | static void |
7972 | create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, | |
c0a91b2b | 7973 | const struct breakpoint_ops *ops) |
a96d9b2e | 7974 | { |
be5c67c1 | 7975 | struct syscall_catchpoint *c; |
a96d9b2e | 7976 | struct gdbarch *gdbarch = get_current_arch (); |
a96d9b2e | 7977 | |
be5c67c1 PA |
7978 | c = XNEW (struct syscall_catchpoint); |
7979 | init_catchpoint (&c->base, gdbarch, tempflag, NULL, ops); | |
7980 | c->syscalls_to_be_caught = filter; | |
a96d9b2e | 7981 | |
3ea46bff | 7982 | install_breakpoint (0, &c->base, 1); |
a96d9b2e SDJ |
7983 | } |
7984 | ||
c906108c | 7985 | static int |
fba45db2 | 7986 | hw_breakpoint_used_count (void) |
c906108c | 7987 | { |
c906108c | 7988 | int i = 0; |
f1310107 TJB |
7989 | struct breakpoint *b; |
7990 | struct bp_location *bl; | |
c906108c SS |
7991 | |
7992 | ALL_BREAKPOINTS (b) | |
c5aa993b | 7993 | { |
d6b74ac4 | 7994 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
7995 | for (bl = b->loc; bl; bl = bl->next) |
7996 | { | |
7997 | /* Special types of hardware breakpoints may use more than | |
7998 | one register. */ | |
348d480f | 7999 | i += b->ops->resources_needed (bl); |
f1310107 | 8000 | } |
c5aa993b | 8001 | } |
c906108c SS |
8002 | |
8003 | return i; | |
8004 | } | |
8005 | ||
a1398e0c PA |
8006 | /* Returns the resources B would use if it were a hardware |
8007 | watchpoint. */ | |
8008 | ||
c906108c | 8009 | static int |
a1398e0c | 8010 | hw_watchpoint_use_count (struct breakpoint *b) |
c906108c | 8011 | { |
c906108c | 8012 | int i = 0; |
e09342b5 | 8013 | struct bp_location *bl; |
c906108c | 8014 | |
a1398e0c PA |
8015 | if (!breakpoint_enabled (b)) |
8016 | return 0; | |
8017 | ||
8018 | for (bl = b->loc; bl; bl = bl->next) | |
8019 | { | |
8020 | /* Special types of hardware watchpoints may use more than | |
8021 | one register. */ | |
8022 | i += b->ops->resources_needed (bl); | |
8023 | } | |
8024 | ||
8025 | return i; | |
8026 | } | |
8027 | ||
8028 | /* Returns the sum the used resources of all hardware watchpoints of | |
8029 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED | |
8030 | the sum of the used resources of all hardware watchpoints of other | |
8031 | types _not_ TYPE. */ | |
8032 | ||
8033 | static int | |
8034 | hw_watchpoint_used_count_others (struct breakpoint *except, | |
8035 | enum bptype type, int *other_type_used) | |
8036 | { | |
8037 | int i = 0; | |
8038 | struct breakpoint *b; | |
8039 | ||
c906108c SS |
8040 | *other_type_used = 0; |
8041 | ALL_BREAKPOINTS (b) | |
e09342b5 | 8042 | { |
a1398e0c PA |
8043 | if (b == except) |
8044 | continue; | |
e09342b5 TJB |
8045 | if (!breakpoint_enabled (b)) |
8046 | continue; | |
8047 | ||
a1398e0c PA |
8048 | if (b->type == type) |
8049 | i += hw_watchpoint_use_count (b); | |
8050 | else if (is_hardware_watchpoint (b)) | |
8051 | *other_type_used = 1; | |
e09342b5 TJB |
8052 | } |
8053 | ||
c906108c SS |
8054 | return i; |
8055 | } | |
8056 | ||
c906108c | 8057 | void |
fba45db2 | 8058 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 8059 | { |
c5aa993b | 8060 | struct breakpoint *b; |
c906108c SS |
8061 | |
8062 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8063 | { |
cc60f2e3 | 8064 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 8065 | { |
b5de0fa7 | 8066 | b->enable_state = bp_call_disabled; |
b60e7edf | 8067 | update_global_location_list (0); |
c5aa993b JM |
8068 | } |
8069 | } | |
c906108c SS |
8070 | } |
8071 | ||
8072 | void | |
fba45db2 | 8073 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 8074 | { |
c5aa993b | 8075 | struct breakpoint *b; |
c906108c SS |
8076 | |
8077 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8078 | { |
cc60f2e3 | 8079 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 8080 | { |
b5de0fa7 | 8081 | b->enable_state = bp_enabled; |
b60e7edf | 8082 | update_global_location_list (1); |
c5aa993b JM |
8083 | } |
8084 | } | |
c906108c SS |
8085 | } |
8086 | ||
8bea4e01 UW |
8087 | void |
8088 | disable_breakpoints_before_startup (void) | |
8089 | { | |
6c95b8df | 8090 | current_program_space->executing_startup = 1; |
f8eba3c6 | 8091 | update_global_location_list (0); |
8bea4e01 UW |
8092 | } |
8093 | ||
8094 | void | |
8095 | enable_breakpoints_after_startup (void) | |
8096 | { | |
6c95b8df | 8097 | current_program_space->executing_startup = 0; |
f8eba3c6 | 8098 | breakpoint_re_set (); |
8bea4e01 UW |
8099 | } |
8100 | ||
c906108c SS |
8101 | |
8102 | /* Set a breakpoint that will evaporate an end of command | |
8103 | at address specified by SAL. | |
8104 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
8105 | ||
8106 | struct breakpoint * | |
a6d9a66e UW |
8107 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
8108 | struct frame_id frame_id, enum bptype type) | |
c906108c | 8109 | { |
52f0bd74 | 8110 | struct breakpoint *b; |
edb3359d DJ |
8111 | |
8112 | /* If FRAME_ID is valid, it should be a real frame, not an inlined | |
8113 | one. */ | |
8114 | gdb_assert (!frame_id_inlined_p (frame_id)); | |
8115 | ||
06edf0c0 | 8116 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
8117 | b->enable_state = bp_enabled; |
8118 | b->disposition = disp_donttouch; | |
818dd999 | 8119 | b->frame_id = frame_id; |
c906108c | 8120 | |
4a64f543 MS |
8121 | /* If we're debugging a multi-threaded program, then we want |
8122 | momentary breakpoints to be active in only a single thread of | |
8123 | control. */ | |
39f77062 KB |
8124 | if (in_thread_list (inferior_ptid)) |
8125 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 8126 | |
b60e7edf | 8127 | update_global_location_list_nothrow (1); |
74960c60 | 8128 | |
c906108c SS |
8129 | return b; |
8130 | } | |
611c83ae | 8131 | |
06edf0c0 PA |
8132 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
8133 | The new breakpoint will have type TYPE, and use OPS as it | |
8134 | breakpoint_ops. */ | |
e58b0e63 | 8135 | |
06edf0c0 PA |
8136 | static struct breakpoint * |
8137 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
8138 | enum bptype type, | |
c0a91b2b | 8139 | const struct breakpoint_ops *ops) |
e58b0e63 PA |
8140 | { |
8141 | struct breakpoint *copy; | |
8142 | ||
06edf0c0 | 8143 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 8144 | copy->loc = allocate_bp_location (copy); |
0e30163f | 8145 | set_breakpoint_location_function (copy->loc, 1); |
e58b0e63 | 8146 | |
a6d9a66e | 8147 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
8148 | copy->loc->requested_address = orig->loc->requested_address; |
8149 | copy->loc->address = orig->loc->address; | |
8150 | copy->loc->section = orig->loc->section; | |
6c95b8df | 8151 | copy->loc->pspace = orig->loc->pspace; |
e58b0e63 | 8152 | |
f8eba3c6 TT |
8153 | if (orig->loc->source_file != NULL) |
8154 | copy->loc->source_file = xstrdup (orig->loc->source_file); | |
e58b0e63 | 8155 | |
f8eba3c6 | 8156 | copy->loc->line_number = orig->loc->line_number; |
e58b0e63 PA |
8157 | copy->frame_id = orig->frame_id; |
8158 | copy->thread = orig->thread; | |
6c95b8df | 8159 | copy->pspace = orig->pspace; |
e58b0e63 PA |
8160 | |
8161 | copy->enable_state = bp_enabled; | |
8162 | copy->disposition = disp_donttouch; | |
8163 | copy->number = internal_breakpoint_number--; | |
8164 | ||
8165 | update_global_location_list_nothrow (0); | |
8166 | return copy; | |
8167 | } | |
8168 | ||
06edf0c0 PA |
8169 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
8170 | ORIG is NULL. */ | |
8171 | ||
8172 | struct breakpoint * | |
8173 | clone_momentary_breakpoint (struct breakpoint *orig) | |
8174 | { | |
8175 | /* If there's nothing to clone, then return nothing. */ | |
8176 | if (orig == NULL) | |
8177 | return NULL; | |
8178 | ||
8179 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops); | |
8180 | } | |
8181 | ||
611c83ae | 8182 | struct breakpoint * |
a6d9a66e UW |
8183 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
8184 | enum bptype type) | |
611c83ae PA |
8185 | { |
8186 | struct symtab_and_line sal; | |
8187 | ||
8188 | sal = find_pc_line (pc, 0); | |
8189 | sal.pc = pc; | |
8190 | sal.section = find_pc_overlay (pc); | |
8191 | sal.explicit_pc = 1; | |
8192 | ||
a6d9a66e | 8193 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 8194 | } |
c906108c | 8195 | \f |
c5aa993b | 8196 | |
c906108c SS |
8197 | /* Tell the user we have just set a breakpoint B. */ |
8198 | ||
8199 | static void | |
fba45db2 | 8200 | mention (struct breakpoint *b) |
c906108c | 8201 | { |
348d480f | 8202 | b->ops->print_mention (b); |
79a45e25 | 8203 | if (ui_out_is_mi_like_p (current_uiout)) |
fb40c209 | 8204 | return; |
c906108c SS |
8205 | printf_filtered ("\n"); |
8206 | } | |
c906108c | 8207 | \f |
c5aa993b | 8208 | |
0d381245 | 8209 | static struct bp_location * |
39d61571 | 8210 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
8211 | const struct symtab_and_line *sal) |
8212 | { | |
8213 | struct bp_location *loc, **tmp; | |
3742cc8b YQ |
8214 | CORE_ADDR adjusted_address; |
8215 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); | |
8216 | ||
8217 | if (loc_gdbarch == NULL) | |
8218 | loc_gdbarch = b->gdbarch; | |
8219 | ||
8220 | /* Adjust the breakpoint's address prior to allocating a location. | |
8221 | Once we call allocate_bp_location(), that mostly uninitialized | |
8222 | location will be placed on the location chain. Adjustment of the | |
8223 | breakpoint may cause target_read_memory() to be called and we do | |
8224 | not want its scan of the location chain to find a breakpoint and | |
8225 | location that's only been partially initialized. */ | |
8226 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, | |
8227 | sal->pc, b->type); | |
0d381245 | 8228 | |
39d61571 | 8229 | loc = allocate_bp_location (b); |
0d381245 VP |
8230 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
8231 | ; | |
8232 | *tmp = loc; | |
3742cc8b | 8233 | |
0d381245 | 8234 | loc->requested_address = sal->pc; |
3742cc8b | 8235 | loc->address = adjusted_address; |
6c95b8df PA |
8236 | loc->pspace = sal->pspace; |
8237 | gdb_assert (loc->pspace != NULL); | |
0d381245 | 8238 | loc->section = sal->section; |
3742cc8b | 8239 | loc->gdbarch = loc_gdbarch; |
f8eba3c6 TT |
8240 | |
8241 | if (sal->symtab != NULL) | |
8242 | loc->source_file = xstrdup (sal->symtab->filename); | |
8243 | loc->line_number = sal->line; | |
8244 | ||
0e30163f JK |
8245 | set_breakpoint_location_function (loc, |
8246 | sal->explicit_pc || sal->explicit_line); | |
0d381245 VP |
8247 | return loc; |
8248 | } | |
514f746b AR |
8249 | \f |
8250 | ||
8251 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
8252 | return 0 otherwise. */ | |
8253 | ||
8254 | static int | |
8255 | bp_loc_is_permanent (struct bp_location *loc) | |
8256 | { | |
8257 | int len; | |
8258 | CORE_ADDR addr; | |
1afeeb75 | 8259 | const gdb_byte *bpoint; |
514f746b | 8260 | gdb_byte *target_mem; |
939c61fa JK |
8261 | struct cleanup *cleanup; |
8262 | int retval = 0; | |
514f746b AR |
8263 | |
8264 | gdb_assert (loc != NULL); | |
8265 | ||
8266 | addr = loc->address; | |
1afeeb75 | 8267 | bpoint = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 8268 | |
939c61fa | 8269 | /* Software breakpoints unsupported? */ |
1afeeb75 | 8270 | if (bpoint == NULL) |
939c61fa JK |
8271 | return 0; |
8272 | ||
514f746b AR |
8273 | target_mem = alloca (len); |
8274 | ||
939c61fa JK |
8275 | /* Enable the automatic memory restoration from breakpoints while |
8276 | we read the memory. Otherwise we could say about our temporary | |
8277 | breakpoints they are permanent. */ | |
6c95b8df PA |
8278 | cleanup = save_current_space_and_thread (); |
8279 | ||
8280 | switch_to_program_space_and_thread (loc->pspace); | |
8281 | make_show_memory_breakpoints_cleanup (0); | |
939c61fa | 8282 | |
514f746b | 8283 | if (target_read_memory (loc->address, target_mem, len) == 0 |
1afeeb75 | 8284 | && memcmp (target_mem, bpoint, len) == 0) |
939c61fa | 8285 | retval = 1; |
514f746b | 8286 | |
939c61fa JK |
8287 | do_cleanups (cleanup); |
8288 | ||
8289 | return retval; | |
514f746b AR |
8290 | } |
8291 | ||
8292 | ||
c3f6f71d | 8293 | |
018d34a4 VP |
8294 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
8295 | as textual description of the location, and COND_STRING | |
db107f19 | 8296 | as condition expression. */ |
018d34a4 VP |
8297 | |
8298 | static void | |
d9b3f62e PA |
8299 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
8300 | struct symtabs_and_lines sals, char *addr_string, | |
f8eba3c6 | 8301 | char *filter, char *cond_string, |
d9b3f62e PA |
8302 | enum bptype type, enum bpdisp disposition, |
8303 | int thread, int task, int ignore_count, | |
c0a91b2b | 8304 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
8305 | int enabled, int internal, unsigned flags, |
8306 | int display_canonical) | |
018d34a4 | 8307 | { |
0d381245 | 8308 | int i; |
018d34a4 VP |
8309 | |
8310 | if (type == bp_hardware_breakpoint) | |
8311 | { | |
fbbd034e AS |
8312 | int target_resources_ok; |
8313 | ||
8314 | i = hw_breakpoint_used_count (); | |
8315 | target_resources_ok = | |
8316 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
018d34a4 VP |
8317 | i + 1, 0); |
8318 | if (target_resources_ok == 0) | |
8319 | error (_("No hardware breakpoint support in the target.")); | |
8320 | else if (target_resources_ok < 0) | |
8321 | error (_("Hardware breakpoints used exceeds limit.")); | |
8322 | } | |
8323 | ||
6c95b8df PA |
8324 | gdb_assert (sals.nelts > 0); |
8325 | ||
0d381245 VP |
8326 | for (i = 0; i < sals.nelts; ++i) |
8327 | { | |
8328 | struct symtab_and_line sal = sals.sals[i]; | |
8329 | struct bp_location *loc; | |
8330 | ||
8331 | if (from_tty) | |
5af949e3 UW |
8332 | { |
8333 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
8334 | if (!loc_gdbarch) | |
8335 | loc_gdbarch = gdbarch; | |
8336 | ||
8337 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 8338 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 8339 | } |
0d381245 VP |
8340 | |
8341 | if (i == 0) | |
8342 | { | |
d9b3f62e | 8343 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 8344 | b->thread = thread; |
4a306c9a | 8345 | b->task = task; |
018d34a4 | 8346 | |
0d381245 VP |
8347 | b->cond_string = cond_string; |
8348 | b->ignore_count = ignore_count; | |
41447f92 | 8349 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 8350 | b->disposition = disposition; |
6c95b8df | 8351 | |
44f238bb PA |
8352 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
8353 | b->loc->inserted = 1; | |
8354 | ||
0fb4aa4b PA |
8355 | if (type == bp_static_tracepoint) |
8356 | { | |
d9b3f62e | 8357 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
8358 | struct static_tracepoint_marker marker; |
8359 | ||
983af33b | 8360 | if (strace_marker_p (b)) |
0fb4aa4b PA |
8361 | { |
8362 | /* We already know the marker exists, otherwise, we | |
8363 | wouldn't see a sal for it. */ | |
8364 | char *p = &addr_string[3]; | |
8365 | char *endp; | |
8366 | char *marker_str; | |
0fb4aa4b | 8367 | |
e9cafbcc | 8368 | p = skip_spaces (p); |
0fb4aa4b | 8369 | |
e9cafbcc | 8370 | endp = skip_to_space (p); |
0fb4aa4b PA |
8371 | |
8372 | marker_str = savestring (p, endp - p); | |
d9b3f62e | 8373 | t->static_trace_marker_id = marker_str; |
0fb4aa4b | 8374 | |
3e43a32a MS |
8375 | printf_filtered (_("Probed static tracepoint " |
8376 | "marker \"%s\"\n"), | |
d9b3f62e | 8377 | t->static_trace_marker_id); |
0fb4aa4b PA |
8378 | } |
8379 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
8380 | { | |
d9b3f62e | 8381 | t->static_trace_marker_id = xstrdup (marker.str_id); |
0fb4aa4b PA |
8382 | release_static_tracepoint_marker (&marker); |
8383 | ||
3e43a32a MS |
8384 | printf_filtered (_("Probed static tracepoint " |
8385 | "marker \"%s\"\n"), | |
d9b3f62e | 8386 | t->static_trace_marker_id); |
0fb4aa4b PA |
8387 | } |
8388 | else | |
3e43a32a MS |
8389 | warning (_("Couldn't determine the static " |
8390 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
8391 | } |
8392 | ||
0d381245 VP |
8393 | loc = b->loc; |
8394 | } | |
8395 | else | |
018d34a4 | 8396 | { |
39d61571 | 8397 | loc = add_location_to_breakpoint (b, &sal); |
44f238bb PA |
8398 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
8399 | loc->inserted = 1; | |
0d381245 VP |
8400 | } |
8401 | ||
514f746b AR |
8402 | if (bp_loc_is_permanent (loc)) |
8403 | make_breakpoint_permanent (b); | |
8404 | ||
0d381245 VP |
8405 | if (b->cond_string) |
8406 | { | |
8407 | char *arg = b->cond_string; | |
d32a6982 | 8408 | loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0); |
0d381245 | 8409 | if (*arg) |
db107f19 | 8410 | error (_("Garbage %s follows condition"), arg); |
018d34a4 | 8411 | } |
0d381245 | 8412 | } |
018d34a4 | 8413 | |
56435ebe | 8414 | b->display_canonical = display_canonical; |
018d34a4 VP |
8415 | if (addr_string) |
8416 | b->addr_string = addr_string; | |
8417 | else | |
8418 | /* addr_string has to be used or breakpoint_re_set will delete | |
8419 | me. */ | |
5af949e3 UW |
8420 | b->addr_string |
8421 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
f8eba3c6 | 8422 | b->filter = filter; |
d9b3f62e | 8423 | } |
018d34a4 | 8424 | |
d9b3f62e PA |
8425 | static void |
8426 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
8427 | struct symtabs_and_lines sals, char *addr_string, | |
f8eba3c6 | 8428 | char *filter, char *cond_string, |
d9b3f62e PA |
8429 | enum bptype type, enum bpdisp disposition, |
8430 | int thread, int task, int ignore_count, | |
c0a91b2b | 8431 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
8432 | int enabled, int internal, unsigned flags, |
8433 | int display_canonical) | |
d9b3f62e PA |
8434 | { |
8435 | struct breakpoint *b; | |
8436 | struct cleanup *old_chain; | |
8437 | ||
8438 | if (is_tracepoint_type (type)) | |
8439 | { | |
8440 | struct tracepoint *t; | |
8441 | ||
8442 | t = XCNEW (struct tracepoint); | |
8443 | b = &t->base; | |
8444 | } | |
8445 | else | |
8446 | b = XNEW (struct breakpoint); | |
8447 | ||
8448 | old_chain = make_cleanup (xfree, b); | |
8449 | ||
8450 | init_breakpoint_sal (b, gdbarch, | |
8451 | sals, addr_string, | |
f8eba3c6 | 8452 | filter, cond_string, |
d9b3f62e PA |
8453 | type, disposition, |
8454 | thread, task, ignore_count, | |
8455 | ops, from_tty, | |
44f238bb PA |
8456 | enabled, internal, flags, |
8457 | display_canonical); | |
d9b3f62e PA |
8458 | discard_cleanups (old_chain); |
8459 | ||
3ea46bff | 8460 | install_breakpoint (internal, b, 0); |
018d34a4 VP |
8461 | } |
8462 | ||
8463 | /* Add SALS.nelts breakpoints to the breakpoint table. For each | |
8464 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
8465 | value. COND_STRING, if not NULL, specified the condition to be | |
8466 | used for all breakpoints. Essentially the only case where | |
8467 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
8468 | function. In that case, it's still not possible to specify | |
8469 | separate conditions for different overloaded functions, so | |
8470 | we take just a single condition string. | |
8471 | ||
c3f6f71d | 8472 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 8473 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
8474 | array contents). If the function fails (error() is called), the |
8475 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 8476 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
8477 | |
8478 | static void | |
8cdf0e15 | 8479 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 | 8480 | struct linespec_result *canonical, |
8cdf0e15 VP |
8481 | char *cond_string, |
8482 | enum bptype type, enum bpdisp disposition, | |
8483 | int thread, int task, int ignore_count, | |
c0a91b2b | 8484 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb | 8485 | int enabled, int internal, unsigned flags) |
c906108c | 8486 | { |
018d34a4 | 8487 | int i; |
f8eba3c6 | 8488 | struct linespec_sals *lsal; |
cc59ec59 | 8489 | |
f8eba3c6 TT |
8490 | if (canonical->pre_expanded) |
8491 | gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1); | |
8492 | ||
8493 | for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i) | |
c3f6f71d | 8494 | { |
f8eba3c6 TT |
8495 | /* Note that 'addr_string' can be NULL in the case of a plain |
8496 | 'break', without arguments. */ | |
8497 | char *addr_string = (canonical->addr_string | |
8498 | ? xstrdup (canonical->addr_string) | |
8499 | : NULL); | |
8500 | char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL; | |
8501 | struct cleanup *inner = make_cleanup (xfree, addr_string); | |
0d381245 | 8502 | |
f8eba3c6 TT |
8503 | make_cleanup (xfree, filter_string); |
8504 | create_breakpoint_sal (gdbarch, lsal->sals, | |
8505 | addr_string, | |
8506 | filter_string, | |
8cdf0e15 | 8507 | cond_string, type, disposition, |
84f4c1fe | 8508 | thread, task, ignore_count, ops, |
44f238bb | 8509 | from_tty, enabled, internal, flags, |
56435ebe | 8510 | canonical->special_display); |
f8eba3c6 | 8511 | discard_cleanups (inner); |
c3f6f71d | 8512 | } |
c3f6f71d | 8513 | } |
c906108c | 8514 | |
9998af43 | 8515 | /* Parse ADDRESS which is assumed to be a SAL specification possibly |
c3f6f71d | 8516 | followed by conditionals. On return, SALS contains an array of SAL |
4a64f543 | 8517 | addresses found. ADDR_STRING contains a vector of (canonical) |
9998af43 TJB |
8518 | address strings. ADDRESS points to the end of the SAL. |
8519 | ||
8520 | The array and the line spec strings are allocated on the heap, it is | |
8521 | the caller's responsibility to free them. */ | |
c906108c | 8522 | |
b9362cc7 | 8523 | static void |
c3f6f71d | 8524 | parse_breakpoint_sals (char **address, |
58438ac1 | 8525 | struct linespec_result *canonical) |
c3f6f71d JM |
8526 | { |
8527 | char *addr_start = *address; | |
cc59ec59 | 8528 | |
c3f6f71d | 8529 | /* If no arg given, or if first arg is 'if ', use the default |
4a64f543 | 8530 | breakpoint. */ |
c3f6f71d JM |
8531 | if ((*address) == NULL |
8532 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c | 8533 | { |
1bfeeb0f JL |
8534 | /* The last displayed codepoint, if it's valid, is our default breakpoint |
8535 | address. */ | |
8536 | if (last_displayed_sal_is_valid ()) | |
c906108c | 8537 | { |
f8eba3c6 | 8538 | struct linespec_sals lsal; |
c3f6f71d | 8539 | struct symtab_and_line sal; |
cc59ec59 | 8540 | |
4a64f543 | 8541 | init_sal (&sal); /* Initialize to zeroes. */ |
f8eba3c6 | 8542 | lsal.sals.sals = (struct symtab_and_line *) |
c906108c | 8543 | xmalloc (sizeof (struct symtab_and_line)); |
1bfeeb0f JL |
8544 | |
8545 | /* Set sal's pspace, pc, symtab, and line to the values | |
8546 | corresponding to the last call to print_frame_info. */ | |
8547 | get_last_displayed_sal (&sal); | |
8548 | sal.section = find_pc_overlay (sal.pc); | |
00903456 | 8549 | |
4a64f543 | 8550 | /* "break" without arguments is equivalent to "break *PC" |
1bfeeb0f JL |
8551 | where PC is the last displayed codepoint's address. So |
8552 | make sure to set sal.explicit_pc to prevent GDB from | |
8553 | trying to expand the list of sals to include all other | |
8554 | instances with the same symtab and line. */ | |
00903456 JK |
8555 | sal.explicit_pc = 1; |
8556 | ||
f8eba3c6 TT |
8557 | lsal.sals.sals[0] = sal; |
8558 | lsal.sals.nelts = 1; | |
8559 | lsal.canonical = NULL; | |
8560 | ||
8561 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
c906108c SS |
8562 | } |
8563 | else | |
8a3fe4f8 | 8564 | error (_("No default breakpoint address now.")); |
c906108c SS |
8565 | } |
8566 | else | |
8567 | { | |
c906108c | 8568 | /* Force almost all breakpoints to be in terms of the |
4a64f543 MS |
8569 | current_source_symtab (which is decode_line_1's default). |
8570 | This should produce the results we want almost all of the | |
f8eba3c6 TT |
8571 | time while leaving default_breakpoint_* alone. */ |
8572 | if (last_displayed_sal_is_valid ()) | |
8573 | decode_line_full (address, DECODE_LINE_FUNFIRSTLINE, | |
8574 | get_last_displayed_symtab (), | |
8575 | get_last_displayed_line (), | |
8576 | canonical, NULL, NULL); | |
c906108c | 8577 | else |
f8eba3c6 TT |
8578 | decode_line_full (address, DECODE_LINE_FUNFIRSTLINE, |
8579 | (struct symtab *) NULL, 0, | |
8580 | canonical, NULL, NULL); | |
c906108c | 8581 | } |
c3f6f71d | 8582 | } |
c906108c | 8583 | |
c906108c | 8584 | |
c3f6f71d | 8585 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 8586 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 8587 | |
b9362cc7 | 8588 | static void |
23e7acfb | 8589 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
c3f6f71d JM |
8590 | { |
8591 | int i; | |
cc59ec59 | 8592 | |
c3f6f71d | 8593 | for (i = 0; i < sals->nelts; i++) |
ee53e872 | 8594 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
8595 | } |
8596 | ||
7a697b8d SS |
8597 | /* Fast tracepoints may have restrictions on valid locations. For |
8598 | instance, a fast tracepoint using a jump instead of a trap will | |
8599 | likely have to overwrite more bytes than a trap would, and so can | |
8600 | only be placed where the instruction is longer than the jump, or a | |
8601 | multi-instruction sequence does not have a jump into the middle of | |
8602 | it, etc. */ | |
8603 | ||
8604 | static void | |
8605 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
8606 | struct symtabs_and_lines *sals) | |
8607 | { | |
8608 | int i, rslt; | |
8609 | struct symtab_and_line *sal; | |
8610 | char *msg; | |
8611 | struct cleanup *old_chain; | |
8612 | ||
8613 | for (i = 0; i < sals->nelts; i++) | |
8614 | { | |
f8eba3c6 TT |
8615 | struct gdbarch *sarch; |
8616 | ||
7a697b8d SS |
8617 | sal = &sals->sals[i]; |
8618 | ||
f8eba3c6 TT |
8619 | sarch = get_sal_arch (*sal); |
8620 | /* We fall back to GDBARCH if there is no architecture | |
8621 | associated with SAL. */ | |
8622 | if (sarch == NULL) | |
8623 | sarch = gdbarch; | |
8624 | rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc, | |
7a697b8d SS |
8625 | NULL, &msg); |
8626 | old_chain = make_cleanup (xfree, msg); | |
8627 | ||
8628 | if (!rslt) | |
8629 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
f8eba3c6 | 8630 | paddress (sarch, sal->pc), (msg ? msg : "")); |
7a697b8d SS |
8631 | |
8632 | do_cleanups (old_chain); | |
8633 | } | |
8634 | } | |
8635 | ||
018d34a4 VP |
8636 | /* Given TOK, a string specification of condition and thread, as |
8637 | accepted by the 'break' command, extract the condition | |
8638 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 8639 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
8640 | If no condition is found, *COND_STRING is set to NULL. |
8641 | If no thread is found, *THREAD is set to -1. */ | |
8642 | static void | |
8643 | find_condition_and_thread (char *tok, CORE_ADDR pc, | |
4a306c9a | 8644 | char **cond_string, int *thread, int *task) |
018d34a4 VP |
8645 | { |
8646 | *cond_string = NULL; | |
8647 | *thread = -1; | |
8648 | while (tok && *tok) | |
8649 | { | |
8650 | char *end_tok; | |
8651 | int toklen; | |
8652 | char *cond_start = NULL; | |
8653 | char *cond_end = NULL; | |
cc59ec59 | 8654 | |
e9cafbcc | 8655 | tok = skip_spaces (tok); |
018d34a4 | 8656 | |
e9cafbcc | 8657 | end_tok = skip_to_space (tok); |
018d34a4 VP |
8658 | |
8659 | toklen = end_tok - tok; | |
8660 | ||
8661 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
8662 | { | |
f7545552 TT |
8663 | struct expression *expr; |
8664 | ||
018d34a4 | 8665 | tok = cond_start = end_tok + 1; |
f7545552 TT |
8666 | expr = parse_exp_1 (&tok, block_for_pc (pc), 0); |
8667 | xfree (expr); | |
018d34a4 VP |
8668 | cond_end = tok; |
8669 | *cond_string = savestring (cond_start, | |
8670 | cond_end - cond_start); | |
8671 | } | |
8672 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
8673 | { | |
8674 | char *tmptok; | |
8675 | ||
8676 | tok = end_tok + 1; | |
8677 | tmptok = tok; | |
8678 | *thread = strtol (tok, &tok, 0); | |
8679 | if (tok == tmptok) | |
8680 | error (_("Junk after thread keyword.")); | |
8681 | if (!valid_thread_id (*thread)) | |
8682 | error (_("Unknown thread %d."), *thread); | |
8683 | } | |
4a306c9a JB |
8684 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
8685 | { | |
8686 | char *tmptok; | |
8687 | ||
8688 | tok = end_tok + 1; | |
8689 | tmptok = tok; | |
8690 | *task = strtol (tok, &tok, 0); | |
8691 | if (tok == tmptok) | |
8692 | error (_("Junk after task keyword.")); | |
8693 | if (!valid_task_id (*task)) | |
b6199126 | 8694 | error (_("Unknown task %d."), *task); |
4a306c9a | 8695 | } |
018d34a4 VP |
8696 | else |
8697 | error (_("Junk at end of arguments.")); | |
8698 | } | |
8699 | } | |
8700 | ||
0fb4aa4b PA |
8701 | /* Decode a static tracepoint marker spec. */ |
8702 | ||
8703 | static struct symtabs_and_lines | |
8704 | decode_static_tracepoint_spec (char **arg_p) | |
8705 | { | |
8706 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
8707 | struct symtabs_and_lines sals; | |
8708 | struct symtab_and_line sal; | |
8709 | struct symbol *sym; | |
8710 | struct cleanup *old_chain; | |
8711 | char *p = &(*arg_p)[3]; | |
8712 | char *endp; | |
8713 | char *marker_str; | |
8714 | int i; | |
8715 | ||
e9cafbcc | 8716 | p = skip_spaces (p); |
0fb4aa4b | 8717 | |
e9cafbcc | 8718 | endp = skip_to_space (p); |
0fb4aa4b PA |
8719 | |
8720 | marker_str = savestring (p, endp - p); | |
8721 | old_chain = make_cleanup (xfree, marker_str); | |
8722 | ||
8723 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
8724 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
8725 | error (_("No known static tracepoint marker named %s"), marker_str); | |
8726 | ||
8727 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); | |
8728 | sals.sals = xmalloc (sizeof *sals.sals * sals.nelts); | |
8729 | ||
8730 | for (i = 0; i < sals.nelts; i++) | |
8731 | { | |
8732 | struct static_tracepoint_marker *marker; | |
8733 | ||
8734 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
8735 | ||
8736 | init_sal (&sals.sals[i]); | |
8737 | ||
8738 | sals.sals[i] = find_pc_line (marker->address, 0); | |
8739 | sals.sals[i].pc = marker->address; | |
8740 | ||
8741 | release_static_tracepoint_marker (marker); | |
8742 | } | |
8743 | ||
8744 | do_cleanups (old_chain); | |
8745 | ||
8746 | *arg_p = endp; | |
8747 | return sals; | |
8748 | } | |
8749 | ||
fd9b8c24 PA |
8750 | /* Set a breakpoint. This function is shared between CLI and MI |
8751 | functions for setting a breakpoint. This function has two major | |
8752 | modes of operations, selected by the PARSE_CONDITION_AND_THREAD | |
8753 | parameter. If non-zero, the function will parse arg, extracting | |
4a64f543 MS |
8754 | breakpoint location, address and thread. Otherwise, ARG is just |
8755 | the location of breakpoint, with condition and thread specified by | |
8756 | the COND_STRING and THREAD parameters. If INTERNAL is non-zero, | |
8757 | the breakpoint number will be allocated from the internal | |
8758 | breakpoint count. Returns true if any breakpoint was created; | |
8759 | false otherwise. */ | |
0101ce28 | 8760 | |
8cdf0e15 VP |
8761 | int |
8762 | create_breakpoint (struct gdbarch *gdbarch, | |
8763 | char *arg, char *cond_string, int thread, | |
8764 | int parse_condition_and_thread, | |
0fb4aa4b | 8765 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
8766 | int ignore_count, |
8767 | enum auto_boolean pending_break_support, | |
c0a91b2b | 8768 | const struct breakpoint_ops *ops, |
44f238bb PA |
8769 | int from_tty, int enabled, int internal, |
8770 | unsigned flags) | |
c3f6f71d | 8771 | { |
b78a6381 | 8772 | volatile struct gdb_exception e; |
f8eba3c6 | 8773 | char *copy_arg = NULL; |
c3f6f71d | 8774 | char *addr_start = arg; |
7efd8fc2 | 8775 | struct linespec_result canonical; |
c3f6f71d | 8776 | struct cleanup *old_chain; |
80c99de1 | 8777 | struct cleanup *bkpt_chain = NULL; |
05ff989b | 8778 | int i; |
0101ce28 | 8779 | int pending = 0; |
4a306c9a | 8780 | int task = 0; |
86b17b60 | 8781 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 8782 | |
348d480f PA |
8783 | gdb_assert (ops != NULL); |
8784 | ||
7efd8fc2 | 8785 | init_linespec_result (&canonical); |
c3f6f71d | 8786 | |
b78a6381 TT |
8787 | TRY_CATCH (e, RETURN_MASK_ALL) |
8788 | { | |
983af33b SDJ |
8789 | ops->create_sals_from_address (&arg, &canonical, type_wanted, |
8790 | addr_start, ©_arg); | |
b78a6381 | 8791 | } |
0101ce28 JJ |
8792 | |
8793 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 8794 | switch (e.reason) |
0101ce28 | 8795 | { |
983af33b SDJ |
8796 | case GDB_NO_ERROR: |
8797 | if (VEC_empty (linespec_sals, canonical.sals)) | |
8798 | return 0; | |
8799 | break; | |
05ff989b AC |
8800 | case RETURN_ERROR: |
8801 | switch (e.error) | |
0101ce28 | 8802 | { |
05ff989b | 8803 | case NOT_FOUND_ERROR: |
0101ce28 | 8804 | |
05ff989b AC |
8805 | /* If pending breakpoint support is turned off, throw |
8806 | error. */ | |
fa8d40ab JJ |
8807 | |
8808 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
8809 | throw_exception (e); |
8810 | ||
8811 | exception_print (gdb_stderr, e); | |
fa8d40ab | 8812 | |
05ff989b AC |
8813 | /* If pending breakpoint support is auto query and the user |
8814 | selects no, then simply return the error code. */ | |
059fb39f | 8815 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
bfccc43c YQ |
8816 | && !nquery (_("Make %s pending on future shared library load? "), |
8817 | bptype_string (type_wanted))) | |
fd9b8c24 | 8818 | return 0; |
fa8d40ab | 8819 | |
05ff989b AC |
8820 | /* At this point, either the user was queried about setting |
8821 | a pending breakpoint and selected yes, or pending | |
8822 | breakpoint behavior is on and thus a pending breakpoint | |
8823 | is defaulted on behalf of the user. */ | |
f8eba3c6 TT |
8824 | { |
8825 | struct linespec_sals lsal; | |
8826 | ||
8827 | copy_arg = xstrdup (addr_start); | |
8828 | lsal.canonical = xstrdup (copy_arg); | |
8829 | lsal.sals.nelts = 1; | |
8830 | lsal.sals.sals = XNEW (struct symtab_and_line); | |
8831 | init_sal (&lsal.sals.sals[0]); | |
8832 | pending = 1; | |
8833 | VEC_safe_push (linespec_sals, canonical.sals, &lsal); | |
8834 | } | |
05ff989b AC |
8835 | break; |
8836 | default: | |
98deb0da | 8837 | throw_exception (e); |
0101ce28 | 8838 | } |
2abae994 | 8839 | break; |
05ff989b | 8840 | default: |
983af33b | 8841 | throw_exception (e); |
0101ce28 | 8842 | } |
c3f6f71d | 8843 | |
4a64f543 | 8844 | /* Create a chain of things that always need to be cleaned up. */ |
f8eba3c6 | 8845 | old_chain = make_cleanup_destroy_linespec_result (&canonical); |
c3f6f71d | 8846 | |
c3f6f71d JM |
8847 | /* ----------------------------- SNIP ----------------------------- |
8848 | Anything added to the cleanup chain beyond this point is assumed | |
8849 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
8850 | then the memory is not reclaimed. */ |
8851 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d | 8852 | |
c3f6f71d JM |
8853 | /* Resolve all line numbers to PC's and verify that the addresses |
8854 | are ok for the target. */ | |
0101ce28 | 8855 | if (!pending) |
f8eba3c6 TT |
8856 | { |
8857 | int ix; | |
8858 | struct linespec_sals *iter; | |
8859 | ||
8860 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
8861 | breakpoint_sals_to_pc (&iter->sals); | |
8862 | } | |
c3f6f71d | 8863 | |
7a697b8d | 8864 | /* Fast tracepoints may have additional restrictions on location. */ |
bfccc43c | 8865 | if (!pending && type_wanted == bp_fast_tracepoint) |
f8eba3c6 TT |
8866 | { |
8867 | int ix; | |
8868 | struct linespec_sals *iter; | |
8869 | ||
8870 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
8871 | check_fast_tracepoint_sals (gdbarch, &iter->sals); | |
8872 | } | |
7a697b8d | 8873 | |
c3f6f71d JM |
8874 | /* Verify that condition can be parsed, before setting any |
8875 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 8876 | breakpoint. */ |
0101ce28 | 8877 | if (!pending) |
c3f6f71d | 8878 | { |
f8eba3c6 TT |
8879 | struct linespec_sals *lsal; |
8880 | ||
8881 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
8882 | ||
2f069f6f | 8883 | if (parse_condition_and_thread) |
72b2ff0e VP |
8884 | { |
8885 | /* Here we only parse 'arg' to separate condition | |
8886 | from thread number, so parsing in context of first | |
8887 | sal is OK. When setting the breakpoint we'll | |
8888 | re-parse it in context of each sal. */ | |
8889 | cond_string = NULL; | |
8890 | thread = -1; | |
f8eba3c6 | 8891 | find_condition_and_thread (arg, lsal->sals.sals[0].pc, &cond_string, |
4a306c9a | 8892 | &thread, &task); |
72b2ff0e VP |
8893 | if (cond_string) |
8894 | make_cleanup (xfree, cond_string); | |
8895 | } | |
2f069f6f | 8896 | else |
72b2ff0e VP |
8897 | { |
8898 | /* Create a private copy of condition string. */ | |
8899 | if (cond_string) | |
8900 | { | |
8901 | cond_string = xstrdup (cond_string); | |
8902 | make_cleanup (xfree, cond_string); | |
8903 | } | |
8904 | } | |
0fb4aa4b | 8905 | |
983af33b | 8906 | ops->create_breakpoints_sal (gdbarch, &canonical, lsal, |
d9b3f62e PA |
8907 | cond_string, type_wanted, |
8908 | tempflag ? disp_del : disp_donttouch, | |
8909 | thread, task, ignore_count, ops, | |
44f238bb | 8910 | from_tty, enabled, internal, flags); |
c906108c | 8911 | } |
0101ce28 JJ |
8912 | else |
8913 | { | |
0101ce28 JJ |
8914 | struct breakpoint *b; |
8915 | ||
0101ce28 JJ |
8916 | make_cleanup (xfree, copy_arg); |
8917 | ||
bfccc43c YQ |
8918 | if (is_tracepoint_type (type_wanted)) |
8919 | { | |
8920 | struct tracepoint *t; | |
8921 | ||
8922 | t = XCNEW (struct tracepoint); | |
8923 | b = &t->base; | |
8924 | } | |
8925 | else | |
8926 | b = XNEW (struct breakpoint); | |
8927 | ||
8928 | init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops); | |
8929 | ||
f8eba3c6 | 8930 | b->addr_string = copy_arg; |
72b2ff0e | 8931 | b->cond_string = NULL; |
0101ce28 | 8932 | b->ignore_count = ignore_count; |
0101ce28 | 8933 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 8934 | b->condition_not_parsed = 1; |
41447f92 | 8935 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
cc72b2a2 KP |
8936 | if ((type_wanted != bp_breakpoint |
8937 | && type_wanted != bp_hardware_breakpoint) || thread != -1) | |
f8eba3c6 | 8938 | b->pspace = current_program_space; |
8bea4e01 | 8939 | |
bfccc43c | 8940 | install_breakpoint (internal, b, 0); |
0101ce28 JJ |
8941 | } |
8942 | ||
f8eba3c6 | 8943 | if (VEC_length (linespec_sals, canonical.sals) > 1) |
95a42b64 | 8944 | { |
3e43a32a MS |
8945 | warning (_("Multiple breakpoints were set.\nUse the " |
8946 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 8947 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
8948 | } |
8949 | ||
80c99de1 PA |
8950 | /* That's it. Discard the cleanups for data inserted into the |
8951 | breakpoint. */ | |
8952 | discard_cleanups (bkpt_chain); | |
8953 | /* But cleanup everything else. */ | |
c3f6f71d | 8954 | do_cleanups (old_chain); |
217dc9e2 | 8955 | |
80c99de1 | 8956 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
217dc9e2 | 8957 | update_global_location_list (1); |
fd9b8c24 PA |
8958 | |
8959 | return 1; | |
c3f6f71d | 8960 | } |
c906108c | 8961 | |
348d480f | 8962 | /* Set a breakpoint. |
72b2ff0e VP |
8963 | ARG is a string describing breakpoint address, |
8964 | condition, and thread. | |
8965 | FLAG specifies if a breakpoint is hardware on, | |
8966 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
8967 | and BP_TEMPFLAG. */ | |
348d480f | 8968 | |
98deb0da | 8969 | static void |
72b2ff0e | 8970 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 8971 | { |
72b2ff0e | 8972 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
8973 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
8974 | ? bp_hardware_breakpoint | |
8975 | : bp_breakpoint); | |
c3f6f71d | 8976 | |
8cdf0e15 VP |
8977 | create_breakpoint (get_current_arch (), |
8978 | arg, | |
8979 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b | 8980 | tempflag, type_wanted, |
8cdf0e15 VP |
8981 | 0 /* Ignore count */, |
8982 | pending_break_support, | |
348d480f | 8983 | &bkpt_breakpoint_ops, |
8cdf0e15 | 8984 | from_tty, |
84f4c1fe | 8985 | 1 /* enabled */, |
44f238bb PA |
8986 | 0 /* internal */, |
8987 | 0); | |
c906108c SS |
8988 | } |
8989 | ||
c906108c SS |
8990 | /* Helper function for break_command_1 and disassemble_command. */ |
8991 | ||
8992 | void | |
fba45db2 | 8993 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
8994 | { |
8995 | CORE_ADDR pc; | |
8996 | ||
8997 | if (sal->pc == 0 && sal->symtab != NULL) | |
8998 | { | |
8999 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 9000 | error (_("No line %d in file \"%s\"."), |
c906108c SS |
9001 | sal->line, sal->symtab->filename); |
9002 | sal->pc = pc; | |
6a048695 | 9003 | |
4a64f543 MS |
9004 | /* If this SAL corresponds to a breakpoint inserted using a line |
9005 | number, then skip the function prologue if necessary. */ | |
6a048695 | 9006 | if (sal->explicit_line) |
059acae7 | 9007 | skip_prologue_sal (sal); |
c906108c SS |
9008 | } |
9009 | ||
9010 | if (sal->section == 0 && sal->symtab != NULL) | |
9011 | { | |
9012 | struct blockvector *bv; | |
c5aa993b JM |
9013 | struct block *b; |
9014 | struct symbol *sym; | |
c906108c | 9015 | |
801e3a5b | 9016 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
9017 | if (bv != NULL) |
9018 | { | |
7f0df278 | 9019 | sym = block_linkage_function (b); |
c906108c SS |
9020 | if (sym != NULL) |
9021 | { | |
9022 | fixup_symbol_section (sym, sal->symtab->objfile); | |
714835d5 | 9023 | sal->section = SYMBOL_OBJ_SECTION (sym); |
c906108c SS |
9024 | } |
9025 | else | |
9026 | { | |
4a64f543 MS |
9027 | /* It really is worthwhile to have the section, so we'll |
9028 | just have to look harder. This case can be executed | |
9029 | if we have line numbers but no functions (as can | |
9030 | happen in assembly source). */ | |
c906108c | 9031 | |
c5aa993b | 9032 | struct minimal_symbol *msym; |
6c95b8df PA |
9033 | struct cleanup *old_chain = save_current_space_and_thread (); |
9034 | ||
9035 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
9036 | |
9037 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
9038 | if (msym) | |
714835d5 | 9039 | sal->section = SYMBOL_OBJ_SECTION (msym); |
6c95b8df PA |
9040 | |
9041 | do_cleanups (old_chain); | |
c906108c SS |
9042 | } |
9043 | } | |
9044 | } | |
9045 | } | |
9046 | ||
9047 | void | |
fba45db2 | 9048 | break_command (char *arg, int from_tty) |
c906108c | 9049 | { |
db107f19 | 9050 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9051 | } |
9052 | ||
c906108c | 9053 | void |
fba45db2 | 9054 | tbreak_command (char *arg, int from_tty) |
c906108c | 9055 | { |
db107f19 | 9056 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
9057 | } |
9058 | ||
c906108c | 9059 | static void |
fba45db2 | 9060 | hbreak_command (char *arg, int from_tty) |
c906108c | 9061 | { |
db107f19 | 9062 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
9063 | } |
9064 | ||
9065 | static void | |
fba45db2 | 9066 | thbreak_command (char *arg, int from_tty) |
c906108c | 9067 | { |
db107f19 | 9068 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
9069 | } |
9070 | ||
9071 | static void | |
fba45db2 | 9072 | stop_command (char *arg, int from_tty) |
c906108c | 9073 | { |
a3f17187 | 9074 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 9075 | Usage: stop in <function | address>\n\ |
a3f17187 | 9076 | stop at <line>\n")); |
c906108c SS |
9077 | } |
9078 | ||
9079 | static void | |
fba45db2 | 9080 | stopin_command (char *arg, int from_tty) |
c906108c SS |
9081 | { |
9082 | int badInput = 0; | |
9083 | ||
c5aa993b | 9084 | if (arg == (char *) NULL) |
c906108c SS |
9085 | badInput = 1; |
9086 | else if (*arg != '*') | |
9087 | { | |
9088 | char *argptr = arg; | |
9089 | int hasColon = 0; | |
9090 | ||
4a64f543 | 9091 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 9092 | say it is bad, otherwise, it should be an address or |
4a64f543 | 9093 | function/method name. */ |
c906108c | 9094 | while (*argptr && !hasColon) |
c5aa993b JM |
9095 | { |
9096 | hasColon = (*argptr == ':'); | |
9097 | argptr++; | |
9098 | } | |
c906108c SS |
9099 | |
9100 | if (hasColon) | |
c5aa993b | 9101 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 9102 | else |
c5aa993b | 9103 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
9104 | } |
9105 | ||
9106 | if (badInput) | |
a3f17187 | 9107 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 9108 | else |
db107f19 | 9109 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9110 | } |
9111 | ||
9112 | static void | |
fba45db2 | 9113 | stopat_command (char *arg, int from_tty) |
c906108c SS |
9114 | { |
9115 | int badInput = 0; | |
9116 | ||
c5aa993b | 9117 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
9118 | badInput = 1; |
9119 | else | |
9120 | { | |
9121 | char *argptr = arg; | |
9122 | int hasColon = 0; | |
9123 | ||
4a64f543 MS |
9124 | /* Look for a ':'. If there is a '::' then get out, otherwise |
9125 | it is probably a line number. */ | |
c906108c | 9126 | while (*argptr && !hasColon) |
c5aa993b JM |
9127 | { |
9128 | hasColon = (*argptr == ':'); | |
9129 | argptr++; | |
9130 | } | |
c906108c SS |
9131 | |
9132 | if (hasColon) | |
c5aa993b | 9133 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 9134 | else |
c5aa993b | 9135 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
9136 | } |
9137 | ||
9138 | if (badInput) | |
a3f17187 | 9139 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 9140 | else |
db107f19 | 9141 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9142 | } |
9143 | ||
f1310107 TJB |
9144 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
9145 | ranged breakpoints. */ | |
9146 | ||
9147 | static int | |
9148 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
9149 | struct address_space *aspace, | |
09ac7c10 TT |
9150 | CORE_ADDR bp_addr, |
9151 | const struct target_waitstatus *ws) | |
f1310107 | 9152 | { |
09ac7c10 TT |
9153 | if (ws->kind != TARGET_WAITKIND_STOPPED |
9154 | || ws->value.sig != TARGET_SIGNAL_TRAP) | |
9155 | return 0; | |
9156 | ||
f1310107 TJB |
9157 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, |
9158 | bl->length, aspace, bp_addr); | |
9159 | } | |
9160 | ||
9161 | /* Implement the "resources_needed" breakpoint_ops method for | |
9162 | ranged breakpoints. */ | |
9163 | ||
9164 | static int | |
9165 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
9166 | { | |
9167 | return target_ranged_break_num_registers (); | |
9168 | } | |
9169 | ||
9170 | /* Implement the "print_it" breakpoint_ops method for | |
9171 | ranged breakpoints. */ | |
9172 | ||
9173 | static enum print_stop_action | |
348d480f | 9174 | print_it_ranged_breakpoint (bpstat bs) |
f1310107 | 9175 | { |
348d480f | 9176 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 | 9177 | struct bp_location *bl = b->loc; |
79a45e25 | 9178 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
9179 | |
9180 | gdb_assert (b->type == bp_hardware_breakpoint); | |
9181 | ||
9182 | /* Ranged breakpoints have only one location. */ | |
9183 | gdb_assert (bl && bl->next == NULL); | |
9184 | ||
9185 | annotate_breakpoint (b->number); | |
9186 | if (b->disposition == disp_del) | |
9187 | ui_out_text (uiout, "\nTemporary ranged breakpoint "); | |
9188 | else | |
9189 | ui_out_text (uiout, "\nRanged breakpoint "); | |
9190 | if (ui_out_is_mi_like_p (uiout)) | |
9191 | { | |
9192 | ui_out_field_string (uiout, "reason", | |
9193 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
9194 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
9195 | } | |
9196 | ui_out_field_int (uiout, "bkptno", b->number); | |
9197 | ui_out_text (uiout, ", "); | |
9198 | ||
9199 | return PRINT_SRC_AND_LOC; | |
9200 | } | |
9201 | ||
9202 | /* Implement the "print_one" breakpoint_ops method for | |
9203 | ranged breakpoints. */ | |
9204 | ||
9205 | static void | |
9206 | print_one_ranged_breakpoint (struct breakpoint *b, | |
9207 | struct bp_location **last_loc) | |
9208 | { | |
9209 | struct bp_location *bl = b->loc; | |
9210 | struct value_print_options opts; | |
79a45e25 | 9211 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
9212 | |
9213 | /* Ranged breakpoints have only one location. */ | |
9214 | gdb_assert (bl && bl->next == NULL); | |
9215 | ||
9216 | get_user_print_options (&opts); | |
9217 | ||
9218 | if (opts.addressprint) | |
9219 | /* We don't print the address range here, it will be printed later | |
9220 | by print_one_detail_ranged_breakpoint. */ | |
9221 | ui_out_field_skip (uiout, "addr"); | |
9222 | annotate_field (5); | |
9223 | print_breakpoint_location (b, bl); | |
9224 | *last_loc = bl; | |
9225 | } | |
9226 | ||
9227 | /* Implement the "print_one_detail" breakpoint_ops method for | |
9228 | ranged breakpoints. */ | |
9229 | ||
9230 | static void | |
9231 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
9232 | struct ui_out *uiout) | |
9233 | { | |
9234 | CORE_ADDR address_start, address_end; | |
9235 | struct bp_location *bl = b->loc; | |
f99d8bf4 PA |
9236 | struct ui_file *stb = mem_fileopen (); |
9237 | struct cleanup *cleanup = make_cleanup_ui_file_delete (stb); | |
f1310107 TJB |
9238 | |
9239 | gdb_assert (bl); | |
9240 | ||
9241 | address_start = bl->address; | |
9242 | address_end = address_start + bl->length - 1; | |
9243 | ||
9244 | ui_out_text (uiout, "\taddress range: "); | |
f99d8bf4 | 9245 | fprintf_unfiltered (stb, "[%s, %s]", |
f1310107 TJB |
9246 | print_core_address (bl->gdbarch, address_start), |
9247 | print_core_address (bl->gdbarch, address_end)); | |
9248 | ui_out_field_stream (uiout, "addr", stb); | |
9249 | ui_out_text (uiout, "\n"); | |
9250 | ||
9251 | do_cleanups (cleanup); | |
9252 | } | |
9253 | ||
9254 | /* Implement the "print_mention" breakpoint_ops method for | |
9255 | ranged breakpoints. */ | |
9256 | ||
9257 | static void | |
9258 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
9259 | { | |
9260 | struct bp_location *bl = b->loc; | |
79a45e25 | 9261 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
9262 | |
9263 | gdb_assert (bl); | |
9264 | gdb_assert (b->type == bp_hardware_breakpoint); | |
9265 | ||
9266 | if (ui_out_is_mi_like_p (uiout)) | |
9267 | return; | |
9268 | ||
9269 | printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."), | |
9270 | b->number, paddress (bl->gdbarch, bl->address), | |
9271 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
9272 | } | |
9273 | ||
9274 | /* Implement the "print_recreate" breakpoint_ops method for | |
9275 | ranged breakpoints. */ | |
9276 | ||
9277 | static void | |
9278 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
9279 | { | |
9280 | fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string, | |
9281 | b->addr_string_range_end); | |
d9b3f62e | 9282 | print_recreate_thread (b, fp); |
f1310107 TJB |
9283 | } |
9284 | ||
9285 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
9286 | ||
2060206e | 9287 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
9288 | |
9289 | /* Find the address where the end of the breakpoint range should be | |
9290 | placed, given the SAL of the end of the range. This is so that if | |
9291 | the user provides a line number, the end of the range is set to the | |
9292 | last instruction of the given line. */ | |
9293 | ||
9294 | static CORE_ADDR | |
9295 | find_breakpoint_range_end (struct symtab_and_line sal) | |
9296 | { | |
9297 | CORE_ADDR end; | |
9298 | ||
9299 | /* If the user provided a PC value, use it. Otherwise, | |
9300 | find the address of the end of the given location. */ | |
9301 | if (sal.explicit_pc) | |
9302 | end = sal.pc; | |
9303 | else | |
9304 | { | |
9305 | int ret; | |
9306 | CORE_ADDR start; | |
9307 | ||
9308 | ret = find_line_pc_range (sal, &start, &end); | |
9309 | if (!ret) | |
9310 | error (_("Could not find location of the end of the range.")); | |
9311 | ||
9312 | /* find_line_pc_range returns the start of the next line. */ | |
9313 | end--; | |
9314 | } | |
9315 | ||
9316 | return end; | |
9317 | } | |
9318 | ||
9319 | /* Implement the "break-range" CLI command. */ | |
9320 | ||
9321 | static void | |
9322 | break_range_command (char *arg, int from_tty) | |
9323 | { | |
9324 | char *arg_start, *addr_string_start, *addr_string_end; | |
9325 | struct linespec_result canonical_start, canonical_end; | |
9326 | int bp_count, can_use_bp, length; | |
9327 | CORE_ADDR end; | |
9328 | struct breakpoint *b; | |
9329 | struct symtab_and_line sal_start, sal_end; | |
f1310107 | 9330 | struct cleanup *cleanup_bkpt; |
f8eba3c6 | 9331 | struct linespec_sals *lsal_start, *lsal_end; |
f1310107 TJB |
9332 | |
9333 | /* We don't support software ranged breakpoints. */ | |
9334 | if (target_ranged_break_num_registers () < 0) | |
9335 | error (_("This target does not support hardware ranged breakpoints.")); | |
9336 | ||
9337 | bp_count = hw_breakpoint_used_count (); | |
9338 | bp_count += target_ranged_break_num_registers (); | |
9339 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
9340 | bp_count, 0); | |
9341 | if (can_use_bp < 0) | |
9342 | error (_("Hardware breakpoints used exceeds limit.")); | |
9343 | ||
f8eba3c6 | 9344 | arg = skip_spaces (arg); |
f1310107 TJB |
9345 | if (arg == NULL || arg[0] == '\0') |
9346 | error(_("No address range specified.")); | |
9347 | ||
f1310107 TJB |
9348 | init_linespec_result (&canonical_start); |
9349 | ||
f8eba3c6 TT |
9350 | arg_start = arg; |
9351 | parse_breakpoint_sals (&arg, &canonical_start); | |
f1310107 | 9352 | |
f8eba3c6 | 9353 | cleanup_bkpt = make_cleanup_destroy_linespec_result (&canonical_start); |
f1310107 TJB |
9354 | |
9355 | if (arg[0] != ',') | |
9356 | error (_("Too few arguments.")); | |
f8eba3c6 | 9357 | else if (VEC_empty (linespec_sals, canonical_start.sals)) |
f1310107 | 9358 | error (_("Could not find location of the beginning of the range.")); |
f8eba3c6 TT |
9359 | |
9360 | lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0); | |
9361 | ||
9362 | if (VEC_length (linespec_sals, canonical_start.sals) > 1 | |
9363 | || lsal_start->sals.nelts != 1) | |
f1310107 TJB |
9364 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
9365 | ||
f8eba3c6 TT |
9366 | sal_start = lsal_start->sals.sals[0]; |
9367 | addr_string_start = savestring (arg_start, arg - arg_start); | |
9368 | make_cleanup (xfree, addr_string_start); | |
f1310107 TJB |
9369 | |
9370 | arg++; /* Skip the comma. */ | |
f8eba3c6 | 9371 | arg = skip_spaces (arg); |
f1310107 TJB |
9372 | |
9373 | /* Parse the end location. */ | |
9374 | ||
f1310107 TJB |
9375 | init_linespec_result (&canonical_end); |
9376 | arg_start = arg; | |
9377 | ||
f8eba3c6 | 9378 | /* We call decode_line_full directly here instead of using |
f1310107 TJB |
9379 | parse_breakpoint_sals because we need to specify the start location's |
9380 | symtab and line as the default symtab and line for the end of the | |
9381 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
9382 | where +14 means 14 lines from the start location. */ | |
f8eba3c6 TT |
9383 | decode_line_full (&arg, DECODE_LINE_FUNFIRSTLINE, |
9384 | sal_start.symtab, sal_start.line, | |
9385 | &canonical_end, NULL, NULL); | |
9386 | ||
9387 | make_cleanup_destroy_linespec_result (&canonical_end); | |
f1310107 | 9388 | |
f8eba3c6 | 9389 | if (VEC_empty (linespec_sals, canonical_end.sals)) |
f1310107 | 9390 | error (_("Could not find location of the end of the range.")); |
f8eba3c6 TT |
9391 | |
9392 | lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0); | |
9393 | if (VEC_length (linespec_sals, canonical_end.sals) > 1 | |
9394 | || lsal_end->sals.nelts != 1) | |
f1310107 TJB |
9395 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
9396 | ||
f8eba3c6 TT |
9397 | sal_end = lsal_end->sals.sals[0]; |
9398 | addr_string_end = savestring (arg_start, arg - arg_start); | |
9399 | make_cleanup (xfree, addr_string_end); | |
f1310107 TJB |
9400 | |
9401 | end = find_breakpoint_range_end (sal_end); | |
9402 | if (sal_start.pc > end) | |
177b42fe | 9403 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
9404 | |
9405 | length = end - sal_start.pc + 1; | |
9406 | if (length < 0) | |
9407 | /* Length overflowed. */ | |
9408 | error (_("Address range too large.")); | |
9409 | else if (length == 1) | |
9410 | { | |
9411 | /* This range is simple enough to be handled by | |
9412 | the `hbreak' command. */ | |
9413 | hbreak_command (addr_string_start, 1); | |
9414 | ||
9415 | do_cleanups (cleanup_bkpt); | |
9416 | ||
9417 | return; | |
9418 | } | |
9419 | ||
9420 | /* Now set up the breakpoint. */ | |
9421 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 9422 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
9423 | set_breakpoint_count (breakpoint_count + 1); |
9424 | b->number = breakpoint_count; | |
9425 | b->disposition = disp_donttouch; | |
f8eba3c6 TT |
9426 | b->addr_string = xstrdup (addr_string_start); |
9427 | b->addr_string_range_end = xstrdup (addr_string_end); | |
f1310107 TJB |
9428 | b->loc->length = length; |
9429 | ||
f8eba3c6 | 9430 | do_cleanups (cleanup_bkpt); |
f1310107 TJB |
9431 | |
9432 | mention (b); | |
8d3788bd | 9433 | observer_notify_breakpoint_created (b); |
f1310107 TJB |
9434 | update_global_location_list (1); |
9435 | } | |
9436 | ||
4a64f543 MS |
9437 | /* Return non-zero if EXP is verified as constant. Returned zero |
9438 | means EXP is variable. Also the constant detection may fail for | |
9439 | some constant expressions and in such case still falsely return | |
9440 | zero. */ | |
2e6e3d9c | 9441 | |
65d79d4b SDJ |
9442 | static int |
9443 | watchpoint_exp_is_const (const struct expression *exp) | |
9444 | { | |
9445 | int i = exp->nelts; | |
9446 | ||
9447 | while (i > 0) | |
9448 | { | |
9449 | int oplenp, argsp; | |
9450 | ||
9451 | /* We are only interested in the descriptor of each element. */ | |
9452 | operator_length (exp, i, &oplenp, &argsp); | |
9453 | i -= oplenp; | |
9454 | ||
9455 | switch (exp->elts[i].opcode) | |
9456 | { | |
9457 | case BINOP_ADD: | |
9458 | case BINOP_SUB: | |
9459 | case BINOP_MUL: | |
9460 | case BINOP_DIV: | |
9461 | case BINOP_REM: | |
9462 | case BINOP_MOD: | |
9463 | case BINOP_LSH: | |
9464 | case BINOP_RSH: | |
9465 | case BINOP_LOGICAL_AND: | |
9466 | case BINOP_LOGICAL_OR: | |
9467 | case BINOP_BITWISE_AND: | |
9468 | case BINOP_BITWISE_IOR: | |
9469 | case BINOP_BITWISE_XOR: | |
9470 | case BINOP_EQUAL: | |
9471 | case BINOP_NOTEQUAL: | |
9472 | case BINOP_LESS: | |
9473 | case BINOP_GTR: | |
9474 | case BINOP_LEQ: | |
9475 | case BINOP_GEQ: | |
9476 | case BINOP_REPEAT: | |
9477 | case BINOP_COMMA: | |
9478 | case BINOP_EXP: | |
9479 | case BINOP_MIN: | |
9480 | case BINOP_MAX: | |
9481 | case BINOP_INTDIV: | |
9482 | case BINOP_CONCAT: | |
9483 | case BINOP_IN: | |
9484 | case BINOP_RANGE: | |
9485 | case TERNOP_COND: | |
9486 | case TERNOP_SLICE: | |
9487 | case TERNOP_SLICE_COUNT: | |
9488 | ||
9489 | case OP_LONG: | |
9490 | case OP_DOUBLE: | |
9491 | case OP_DECFLOAT: | |
9492 | case OP_LAST: | |
9493 | case OP_COMPLEX: | |
9494 | case OP_STRING: | |
9495 | case OP_BITSTRING: | |
9496 | case OP_ARRAY: | |
9497 | case OP_TYPE: | |
9498 | case OP_NAME: | |
9499 | case OP_OBJC_NSSTRING: | |
9500 | ||
9501 | case UNOP_NEG: | |
9502 | case UNOP_LOGICAL_NOT: | |
9503 | case UNOP_COMPLEMENT: | |
9504 | case UNOP_ADDR: | |
9505 | case UNOP_HIGH: | |
aeaa2474 | 9506 | case UNOP_CAST: |
4a64f543 MS |
9507 | /* Unary, binary and ternary operators: We have to check |
9508 | their operands. If they are constant, then so is the | |
9509 | result of that operation. For instance, if A and B are | |
9510 | determined to be constants, then so is "A + B". | |
9511 | ||
9512 | UNOP_IND is one exception to the rule above, because the | |
9513 | value of *ADDR is not necessarily a constant, even when | |
9514 | ADDR is. */ | |
65d79d4b SDJ |
9515 | break; |
9516 | ||
9517 | case OP_VAR_VALUE: | |
9518 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 9519 | |
65d79d4b | 9520 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
9521 | possible that a buggy compiler could mark a variable as |
9522 | constant even when it is not, and TYPE_CONST would return | |
9523 | true in this case, while SYMBOL_CLASS wouldn't. | |
9524 | ||
9525 | We also have to check for function symbols because they | |
9526 | are always constant. */ | |
65d79d4b SDJ |
9527 | { |
9528 | struct symbol *s = exp->elts[i + 2].symbol; | |
9529 | ||
9530 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
9531 | && SYMBOL_CLASS (s) != LOC_CONST | |
9532 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
9533 | return 0; | |
9534 | break; | |
9535 | } | |
9536 | ||
9537 | /* The default action is to return 0 because we are using | |
9538 | the optimistic approach here: If we don't know something, | |
9539 | then it is not a constant. */ | |
9540 | default: | |
9541 | return 0; | |
9542 | } | |
9543 | } | |
9544 | ||
9545 | return 1; | |
9546 | } | |
9547 | ||
3a5c3e22 PA |
9548 | /* Implement the "dtor" breakpoint_ops method for watchpoints. */ |
9549 | ||
9550 | static void | |
9551 | dtor_watchpoint (struct breakpoint *self) | |
9552 | { | |
9553 | struct watchpoint *w = (struct watchpoint *) self; | |
9554 | ||
9555 | xfree (w->cond_exp); | |
9556 | xfree (w->exp); | |
9557 | xfree (w->exp_string); | |
9558 | xfree (w->exp_string_reparse); | |
9559 | value_free (w->val); | |
9560 | ||
9561 | base_breakpoint_ops.dtor (self); | |
9562 | } | |
9563 | ||
348d480f PA |
9564 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
9565 | ||
9566 | static void | |
9567 | re_set_watchpoint (struct breakpoint *b) | |
9568 | { | |
3a5c3e22 PA |
9569 | struct watchpoint *w = (struct watchpoint *) b; |
9570 | ||
348d480f PA |
9571 | /* Watchpoint can be either on expression using entirely global |
9572 | variables, or it can be on local variables. | |
9573 | ||
9574 | Watchpoints of the first kind are never auto-deleted, and even | |
9575 | persist across program restarts. Since they can use variables | |
9576 | from shared libraries, we need to reparse expression as libraries | |
9577 | are loaded and unloaded. | |
9578 | ||
9579 | Watchpoints on local variables can also change meaning as result | |
9580 | of solib event. For example, if a watchpoint uses both a local | |
9581 | and a global variables in expression, it's a local watchpoint, | |
9582 | but unloading of a shared library will make the expression | |
9583 | invalid. This is not a very common use case, but we still | |
9584 | re-evaluate expression, to avoid surprises to the user. | |
9585 | ||
9586 | Note that for local watchpoints, we re-evaluate it only if | |
9587 | watchpoints frame id is still valid. If it's not, it means the | |
9588 | watchpoint is out of scope and will be deleted soon. In fact, | |
9589 | I'm not sure we'll ever be called in this case. | |
9590 | ||
9591 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 9592 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 9593 | |
3a5c3e22 PA |
9594 | Don't do anything about disabled watchpoints, since they will be |
9595 | reevaluated again when enabled. */ | |
9596 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
9597 | } |
9598 | ||
77b06cd7 TJB |
9599 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
9600 | ||
9601 | static int | |
9602 | insert_watchpoint (struct bp_location *bl) | |
9603 | { | |
3a5c3e22 PA |
9604 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
9605 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
9606 | |
9607 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 9608 | w->cond_exp); |
77b06cd7 TJB |
9609 | } |
9610 | ||
9611 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
9612 | ||
9613 | static int | |
9614 | remove_watchpoint (struct bp_location *bl) | |
9615 | { | |
3a5c3e22 PA |
9616 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
9617 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
9618 | |
9619 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 9620 | w->cond_exp); |
e09342b5 TJB |
9621 | } |
9622 | ||
e09342b5 | 9623 | static int |
348d480f | 9624 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
09ac7c10 TT |
9625 | struct address_space *aspace, CORE_ADDR bp_addr, |
9626 | const struct target_waitstatus *ws) | |
e09342b5 | 9627 | { |
348d480f | 9628 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 9629 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 9630 | |
348d480f PA |
9631 | /* Continuable hardware watchpoints are treated as non-existent if the |
9632 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
9633 | some data address). Otherwise gdb won't stop on a break instruction | |
9634 | in the code (not from a breakpoint) when a hardware watchpoint has | |
9635 | been defined. Also skip watchpoints which we know did not trigger | |
9636 | (did not match the data address). */ | |
9637 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 9638 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 9639 | return 0; |
9c06b0b4 | 9640 | |
348d480f | 9641 | return 1; |
9c06b0b4 TJB |
9642 | } |
9643 | ||
348d480f PA |
9644 | static void |
9645 | check_status_watchpoint (bpstat bs) | |
9c06b0b4 | 9646 | { |
348d480f | 9647 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 9648 | |
348d480f | 9649 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
9650 | } |
9651 | ||
9652 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 9653 | hardware watchpoints. */ |
9c06b0b4 TJB |
9654 | |
9655 | static int | |
348d480f | 9656 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 9657 | { |
3a5c3e22 PA |
9658 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
9659 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
9660 | |
9661 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
9662 | } |
9663 | ||
9664 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 9665 | hardware watchpoints. */ |
9c06b0b4 TJB |
9666 | |
9667 | static int | |
348d480f | 9668 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 9669 | { |
efa80663 PA |
9670 | /* Read and access watchpoints only work with hardware support. */ |
9671 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
9672 | } |
9673 | ||
9c06b0b4 | 9674 | static enum print_stop_action |
348d480f | 9675 | print_it_watchpoint (bpstat bs) |
9c06b0b4 | 9676 | { |
348d480f PA |
9677 | struct cleanup *old_chain; |
9678 | struct breakpoint *b; | |
9679 | const struct bp_location *bl; | |
f99d8bf4 | 9680 | struct ui_file *stb; |
348d480f | 9681 | enum print_stop_action result; |
3a5c3e22 | 9682 | struct watchpoint *w; |
79a45e25 | 9683 | struct ui_out *uiout = current_uiout; |
348d480f PA |
9684 | |
9685 | gdb_assert (bs->bp_location_at != NULL); | |
9686 | ||
9687 | bl = bs->bp_location_at; | |
9688 | b = bs->breakpoint_at; | |
3a5c3e22 | 9689 | w = (struct watchpoint *) b; |
348d480f | 9690 | |
f99d8bf4 PA |
9691 | stb = mem_fileopen (); |
9692 | old_chain = make_cleanup_ui_file_delete (stb); | |
9c06b0b4 TJB |
9693 | |
9694 | switch (b->type) | |
9695 | { | |
348d480f | 9696 | case bp_watchpoint: |
9c06b0b4 TJB |
9697 | case bp_hardware_watchpoint: |
9698 | annotate_watchpoint (b->number); | |
9699 | if (ui_out_is_mi_like_p (uiout)) | |
9700 | ui_out_field_string | |
9701 | (uiout, "reason", | |
9702 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
9703 | mention (b); |
9704 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
9705 | ui_out_text (uiout, "\nOld value = "); | |
f99d8bf4 | 9706 | watchpoint_value_print (bs->old_val, stb); |
348d480f PA |
9707 | ui_out_field_stream (uiout, "old", stb); |
9708 | ui_out_text (uiout, "\nNew value = "); | |
f99d8bf4 | 9709 | watchpoint_value_print (w->val, stb); |
348d480f PA |
9710 | ui_out_field_stream (uiout, "new", stb); |
9711 | ui_out_text (uiout, "\n"); | |
9712 | /* More than one watchpoint may have been triggered. */ | |
9713 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
9714 | break; |
9715 | ||
9716 | case bp_read_watchpoint: | |
9717 | if (ui_out_is_mi_like_p (uiout)) | |
9718 | ui_out_field_string | |
9719 | (uiout, "reason", | |
9720 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
9721 | mention (b); |
9722 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
9723 | ui_out_text (uiout, "\nValue = "); | |
f99d8bf4 | 9724 | watchpoint_value_print (w->val, stb); |
348d480f PA |
9725 | ui_out_field_stream (uiout, "value", stb); |
9726 | ui_out_text (uiout, "\n"); | |
9727 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
9728 | break; |
9729 | ||
9730 | case bp_access_watchpoint: | |
348d480f PA |
9731 | if (bs->old_val != NULL) |
9732 | { | |
9733 | annotate_watchpoint (b->number); | |
9734 | if (ui_out_is_mi_like_p (uiout)) | |
9735 | ui_out_field_string | |
9736 | (uiout, "reason", | |
9737 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
9738 | mention (b); | |
9739 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
9740 | ui_out_text (uiout, "\nOld value = "); | |
f99d8bf4 | 9741 | watchpoint_value_print (bs->old_val, stb); |
348d480f PA |
9742 | ui_out_field_stream (uiout, "old", stb); |
9743 | ui_out_text (uiout, "\nNew value = "); | |
9744 | } | |
9745 | else | |
9746 | { | |
9747 | mention (b); | |
9748 | if (ui_out_is_mi_like_p (uiout)) | |
9749 | ui_out_field_string | |
9750 | (uiout, "reason", | |
9751 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
9752 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
9753 | ui_out_text (uiout, "\nValue = "); | |
9754 | } | |
f99d8bf4 | 9755 | watchpoint_value_print (w->val, stb); |
348d480f PA |
9756 | ui_out_field_stream (uiout, "new", stb); |
9757 | ui_out_text (uiout, "\n"); | |
9758 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
9759 | break; |
9760 | default: | |
348d480f | 9761 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
9762 | } |
9763 | ||
348d480f PA |
9764 | do_cleanups (old_chain); |
9765 | return result; | |
9766 | } | |
9767 | ||
9768 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
9769 | watchpoints. */ | |
9770 | ||
9771 | static void | |
9772 | print_mention_watchpoint (struct breakpoint *b) | |
9773 | { | |
9774 | struct cleanup *ui_out_chain; | |
3a5c3e22 | 9775 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 9776 | struct ui_out *uiout = current_uiout; |
348d480f PA |
9777 | |
9778 | switch (b->type) | |
9779 | { | |
9780 | case bp_watchpoint: | |
9781 | ui_out_text (uiout, "Watchpoint "); | |
9782 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
9783 | break; | |
9784 | case bp_hardware_watchpoint: | |
9785 | ui_out_text (uiout, "Hardware watchpoint "); | |
9786 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
9787 | break; | |
9788 | case bp_read_watchpoint: | |
9789 | ui_out_text (uiout, "Hardware read watchpoint "); | |
9790 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
9791 | break; | |
9792 | case bp_access_watchpoint: | |
9793 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
9794 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
9795 | break; | |
9796 | default: | |
9797 | internal_error (__FILE__, __LINE__, | |
9798 | _("Invalid hardware watchpoint type.")); | |
9799 | } | |
9800 | ||
9801 | ui_out_field_int (uiout, "number", b->number); | |
9802 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 9803 | ui_out_field_string (uiout, "exp", w->exp_string); |
348d480f PA |
9804 | do_cleanups (ui_out_chain); |
9805 | } | |
9806 | ||
9807 | /* Implement the "print_recreate" breakpoint_ops method for | |
9808 | watchpoints. */ | |
9809 | ||
9810 | static void | |
9811 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
9812 | { | |
3a5c3e22 PA |
9813 | struct watchpoint *w = (struct watchpoint *) b; |
9814 | ||
348d480f PA |
9815 | switch (b->type) |
9816 | { | |
9817 | case bp_watchpoint: | |
9818 | case bp_hardware_watchpoint: | |
9819 | fprintf_unfiltered (fp, "watch"); | |
9820 | break; | |
9821 | case bp_read_watchpoint: | |
9822 | fprintf_unfiltered (fp, "rwatch"); | |
9823 | break; | |
9824 | case bp_access_watchpoint: | |
9825 | fprintf_unfiltered (fp, "awatch"); | |
9826 | break; | |
9827 | default: | |
9828 | internal_error (__FILE__, __LINE__, | |
9829 | _("Invalid watchpoint type.")); | |
9830 | } | |
9831 | ||
3a5c3e22 | 9832 | fprintf_unfiltered (fp, " %s", w->exp_string); |
d9b3f62e | 9833 | print_recreate_thread (b, fp); |
348d480f PA |
9834 | } |
9835 | ||
9836 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ | |
9837 | ||
2060206e | 9838 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
9839 | |
9840 | /* Implement the "insert" breakpoint_ops method for | |
9841 | masked hardware watchpoints. */ | |
9842 | ||
9843 | static int | |
9844 | insert_masked_watchpoint (struct bp_location *bl) | |
9845 | { | |
3a5c3e22 PA |
9846 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
9847 | ||
9848 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
9849 | bl->watchpoint_type); |
9850 | } | |
9851 | ||
9852 | /* Implement the "remove" breakpoint_ops method for | |
9853 | masked hardware watchpoints. */ | |
9854 | ||
9855 | static int | |
9856 | remove_masked_watchpoint (struct bp_location *bl) | |
9857 | { | |
3a5c3e22 PA |
9858 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
9859 | ||
9860 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
9861 | bl->watchpoint_type); |
9862 | } | |
9863 | ||
9864 | /* Implement the "resources_needed" breakpoint_ops method for | |
9865 | masked hardware watchpoints. */ | |
9866 | ||
9867 | static int | |
9868 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
9869 | { | |
3a5c3e22 PA |
9870 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
9871 | ||
9872 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
9873 | } |
9874 | ||
9875 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
9876 | masked hardware watchpoints. */ | |
9877 | ||
9878 | static int | |
9879 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
9880 | { | |
9881 | return 0; | |
9882 | } | |
9883 | ||
9884 | /* Implement the "print_it" breakpoint_ops method for | |
9885 | masked hardware watchpoints. */ | |
9886 | ||
9887 | static enum print_stop_action | |
9888 | print_it_masked_watchpoint (bpstat bs) | |
9889 | { | |
9890 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 9891 | struct ui_out *uiout = current_uiout; |
348d480f PA |
9892 | |
9893 | /* Masked watchpoints have only one location. */ | |
9894 | gdb_assert (b->loc && b->loc->next == NULL); | |
9895 | ||
9896 | switch (b->type) | |
9897 | { | |
9898 | case bp_hardware_watchpoint: | |
9899 | annotate_watchpoint (b->number); | |
9900 | if (ui_out_is_mi_like_p (uiout)) | |
9901 | ui_out_field_string | |
9902 | (uiout, "reason", | |
9903 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
9904 | break; | |
9905 | ||
9906 | case bp_read_watchpoint: | |
9907 | if (ui_out_is_mi_like_p (uiout)) | |
9908 | ui_out_field_string | |
9909 | (uiout, "reason", | |
9910 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
9911 | break; | |
9912 | ||
9913 | case bp_access_watchpoint: | |
9914 | if (ui_out_is_mi_like_p (uiout)) | |
9915 | ui_out_field_string | |
9916 | (uiout, "reason", | |
9917 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
9918 | break; | |
9919 | default: | |
9920 | internal_error (__FILE__, __LINE__, | |
9921 | _("Invalid hardware watchpoint type.")); | |
9922 | } | |
9923 | ||
9924 | mention (b); | |
9c06b0b4 TJB |
9925 | ui_out_text (uiout, _("\n\ |
9926 | Check the underlying instruction at PC for the memory\n\ | |
9927 | address and value which triggered this watchpoint.\n")); | |
9928 | ui_out_text (uiout, "\n"); | |
9929 | ||
9930 | /* More than one watchpoint may have been triggered. */ | |
9931 | return PRINT_UNKNOWN; | |
9932 | } | |
9933 | ||
9934 | /* Implement the "print_one_detail" breakpoint_ops method for | |
9935 | masked hardware watchpoints. */ | |
9936 | ||
9937 | static void | |
9938 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
9939 | struct ui_out *uiout) | |
9940 | { | |
3a5c3e22 PA |
9941 | struct watchpoint *w = (struct watchpoint *) b; |
9942 | ||
9c06b0b4 TJB |
9943 | /* Masked watchpoints have only one location. */ |
9944 | gdb_assert (b->loc && b->loc->next == NULL); | |
9945 | ||
9946 | ui_out_text (uiout, "\tmask "); | |
3a5c3e22 | 9947 | ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask); |
9c06b0b4 TJB |
9948 | ui_out_text (uiout, "\n"); |
9949 | } | |
9950 | ||
9951 | /* Implement the "print_mention" breakpoint_ops method for | |
9952 | masked hardware watchpoints. */ | |
9953 | ||
9954 | static void | |
9955 | print_mention_masked_watchpoint (struct breakpoint *b) | |
9956 | { | |
3a5c3e22 | 9957 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 9958 | struct ui_out *uiout = current_uiout; |
9c06b0b4 TJB |
9959 | struct cleanup *ui_out_chain; |
9960 | ||
9961 | switch (b->type) | |
9962 | { | |
9963 | case bp_hardware_watchpoint: | |
9964 | ui_out_text (uiout, "Masked hardware watchpoint "); | |
9965 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
9966 | break; | |
9967 | case bp_read_watchpoint: | |
9968 | ui_out_text (uiout, "Masked hardware read watchpoint "); | |
9969 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
9970 | break; | |
9971 | case bp_access_watchpoint: | |
9972 | ui_out_text (uiout, "Masked hardware access (read/write) watchpoint "); | |
9973 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
9974 | break; | |
9975 | default: | |
9976 | internal_error (__FILE__, __LINE__, | |
9977 | _("Invalid hardware watchpoint type.")); | |
9978 | } | |
9979 | ||
9980 | ui_out_field_int (uiout, "number", b->number); | |
9981 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 9982 | ui_out_field_string (uiout, "exp", w->exp_string); |
9c06b0b4 TJB |
9983 | do_cleanups (ui_out_chain); |
9984 | } | |
9985 | ||
9986 | /* Implement the "print_recreate" breakpoint_ops method for | |
9987 | masked hardware watchpoints. */ | |
9988 | ||
9989 | static void | |
9990 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
9991 | { | |
3a5c3e22 | 9992 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
9993 | char tmp[40]; |
9994 | ||
9995 | switch (b->type) | |
9996 | { | |
9997 | case bp_hardware_watchpoint: | |
9998 | fprintf_unfiltered (fp, "watch"); | |
9999 | break; | |
10000 | case bp_read_watchpoint: | |
10001 | fprintf_unfiltered (fp, "rwatch"); | |
10002 | break; | |
10003 | case bp_access_watchpoint: | |
10004 | fprintf_unfiltered (fp, "awatch"); | |
10005 | break; | |
10006 | default: | |
10007 | internal_error (__FILE__, __LINE__, | |
10008 | _("Invalid hardware watchpoint type.")); | |
10009 | } | |
10010 | ||
3a5c3e22 PA |
10011 | sprintf_vma (tmp, w->hw_wp_mask); |
10012 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); | |
d9b3f62e | 10013 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
10014 | } |
10015 | ||
10016 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
10017 | ||
2060206e | 10018 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
10019 | |
10020 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
10021 | ||
10022 | static int | |
10023 | is_masked_watchpoint (const struct breakpoint *b) | |
10024 | { | |
10025 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
10026 | } | |
10027 | ||
53a5351d JM |
10028 | /* accessflag: hw_write: watch write, |
10029 | hw_read: watch read, | |
10030 | hw_access: watch access (read or write) */ | |
c906108c | 10031 | static void |
84f4c1fe PM |
10032 | watch_command_1 (char *arg, int accessflag, int from_tty, |
10033 | int just_location, int internal) | |
c906108c | 10034 | { |
a9634178 | 10035 | volatile struct gdb_exception e; |
d983da9c | 10036 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c | 10037 | struct expression *exp; |
60e1c644 | 10038 | struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 10039 | struct value *val, *mark, *result; |
c906108c | 10040 | struct frame_info *frame; |
c906108c SS |
10041 | char *exp_start = NULL; |
10042 | char *exp_end = NULL; | |
9c06b0b4 TJB |
10043 | char *tok, *end_tok; |
10044 | int toklen = -1; | |
c906108c SS |
10045 | char *cond_start = NULL; |
10046 | char *cond_end = NULL; | |
c906108c | 10047 | enum bptype bp_type; |
37e4754d | 10048 | int thread = -1; |
0cf6dd15 | 10049 | int pc = 0; |
9c06b0b4 TJB |
10050 | /* Flag to indicate whether we are going to use masks for |
10051 | the hardware watchpoint. */ | |
10052 | int use_mask = 0; | |
10053 | CORE_ADDR mask = 0; | |
3a5c3e22 | 10054 | struct watchpoint *w; |
c906108c | 10055 | |
37e4754d LM |
10056 | /* Make sure that we actually have parameters to parse. */ |
10057 | if (arg != NULL && arg[0] != '\0') | |
10058 | { | |
9c06b0b4 | 10059 | char *value_start; |
37e4754d | 10060 | |
9c06b0b4 TJB |
10061 | /* Look for "parameter value" pairs at the end |
10062 | of the arguments string. */ | |
10063 | for (tok = arg + strlen (arg) - 1; tok > arg; tok--) | |
10064 | { | |
10065 | /* Skip whitespace at the end of the argument list. */ | |
10066 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
10067 | tok--; | |
10068 | ||
10069 | /* Find the beginning of the last token. | |
10070 | This is the value of the parameter. */ | |
10071 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
10072 | tok--; | |
10073 | value_start = tok + 1; | |
10074 | ||
10075 | /* Skip whitespace. */ | |
10076 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
10077 | tok--; | |
10078 | ||
10079 | end_tok = tok; | |
10080 | ||
10081 | /* Find the beginning of the second to last token. | |
10082 | This is the parameter itself. */ | |
10083 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
10084 | tok--; | |
10085 | tok++; | |
10086 | toklen = end_tok - tok + 1; | |
10087 | ||
10088 | if (toklen == 6 && !strncmp (tok, "thread", 6)) | |
10089 | { | |
10090 | /* At this point we've found a "thread" token, which means | |
10091 | the user is trying to set a watchpoint that triggers | |
10092 | only in a specific thread. */ | |
10093 | char *endp; | |
37e4754d | 10094 | |
9c06b0b4 TJB |
10095 | if (thread != -1) |
10096 | error(_("You can specify only one thread.")); | |
37e4754d | 10097 | |
9c06b0b4 TJB |
10098 | /* Extract the thread ID from the next token. */ |
10099 | thread = strtol (value_start, &endp, 0); | |
37e4754d | 10100 | |
9c06b0b4 TJB |
10101 | /* Check if the user provided a valid numeric value for the |
10102 | thread ID. */ | |
10103 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
10104 | error (_("Invalid thread ID specification %s."), value_start); | |
10105 | ||
10106 | /* Check if the thread actually exists. */ | |
10107 | if (!valid_thread_id (thread)) | |
10108 | error (_("Unknown thread %d."), thread); | |
10109 | } | |
10110 | else if (toklen == 4 && !strncmp (tok, "mask", 4)) | |
10111 | { | |
10112 | /* We've found a "mask" token, which means the user wants to | |
10113 | create a hardware watchpoint that is going to have the mask | |
10114 | facility. */ | |
10115 | struct value *mask_value, *mark; | |
37e4754d | 10116 | |
9c06b0b4 TJB |
10117 | if (use_mask) |
10118 | error(_("You can specify only one mask.")); | |
37e4754d | 10119 | |
9c06b0b4 | 10120 | use_mask = just_location = 1; |
37e4754d | 10121 | |
9c06b0b4 TJB |
10122 | mark = value_mark (); |
10123 | mask_value = parse_to_comma_and_eval (&value_start); | |
10124 | mask = value_as_address (mask_value); | |
10125 | value_free_to_mark (mark); | |
10126 | } | |
10127 | else | |
10128 | /* We didn't recognize what we found. We should stop here. */ | |
10129 | break; | |
37e4754d | 10130 | |
9c06b0b4 TJB |
10131 | /* Truncate the string and get rid of the "parameter value" pair before |
10132 | the arguments string is parsed by the parse_exp_1 function. */ | |
10133 | *tok = '\0'; | |
10134 | } | |
37e4754d LM |
10135 | } |
10136 | ||
10137 | /* Parse the rest of the arguments. */ | |
c906108c SS |
10138 | innermost_block = NULL; |
10139 | exp_start = arg; | |
10140 | exp = parse_exp_1 (&arg, 0, 0); | |
10141 | exp_end = arg; | |
fa8a61dc TT |
10142 | /* Remove trailing whitespace from the expression before saving it. |
10143 | This makes the eventual display of the expression string a bit | |
10144 | prettier. */ | |
10145 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
10146 | --exp_end; | |
10147 | ||
65d79d4b SDJ |
10148 | /* Checking if the expression is not constant. */ |
10149 | if (watchpoint_exp_is_const (exp)) | |
10150 | { | |
10151 | int len; | |
10152 | ||
10153 | len = exp_end - exp_start; | |
10154 | while (len > 0 && isspace (exp_start[len - 1])) | |
10155 | len--; | |
10156 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
10157 | } | |
10158 | ||
c906108c SS |
10159 | exp_valid_block = innermost_block; |
10160 | mark = value_mark (); | |
a1442452 | 10161 | fetch_subexp_value (exp, &pc, &val, &result, NULL); |
06a64a0b TT |
10162 | |
10163 | if (just_location) | |
10164 | { | |
9c06b0b4 TJB |
10165 | int ret; |
10166 | ||
06a64a0b | 10167 | exp_valid_block = NULL; |
a1442452 | 10168 | val = value_addr (result); |
06a64a0b TT |
10169 | release_value (val); |
10170 | value_free_to_mark (mark); | |
9c06b0b4 TJB |
10171 | |
10172 | if (use_mask) | |
10173 | { | |
10174 | ret = target_masked_watch_num_registers (value_as_address (val), | |
10175 | mask); | |
10176 | if (ret == -1) | |
10177 | error (_("This target does not support masked watchpoints.")); | |
10178 | else if (ret == -2) | |
10179 | error (_("Invalid mask or memory region.")); | |
10180 | } | |
06a64a0b TT |
10181 | } |
10182 | else if (val != NULL) | |
fa4727a6 | 10183 | release_value (val); |
c906108c | 10184 | |
e9cafbcc TT |
10185 | tok = skip_spaces (arg); |
10186 | end_tok = skip_to_space (tok); | |
c906108c SS |
10187 | |
10188 | toklen = end_tok - tok; | |
10189 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
10190 | { | |
2d134ed3 PA |
10191 | struct expression *cond; |
10192 | ||
60e1c644 | 10193 | innermost_block = NULL; |
c906108c SS |
10194 | tok = cond_start = end_tok + 1; |
10195 | cond = parse_exp_1 (&tok, 0, 0); | |
60e1c644 PA |
10196 | |
10197 | /* The watchpoint expression may not be local, but the condition | |
10198 | may still be. E.g.: `watch global if local > 0'. */ | |
10199 | cond_exp_valid_block = innermost_block; | |
10200 | ||
2d134ed3 | 10201 | xfree (cond); |
c906108c SS |
10202 | cond_end = tok; |
10203 | } | |
10204 | if (*tok) | |
8a3fe4f8 | 10205 | error (_("Junk at end of command.")); |
c906108c | 10206 | |
53a5351d | 10207 | if (accessflag == hw_read) |
c5aa993b | 10208 | bp_type = bp_read_watchpoint; |
53a5351d | 10209 | else if (accessflag == hw_access) |
c5aa993b JM |
10210 | bp_type = bp_access_watchpoint; |
10211 | else | |
10212 | bp_type = bp_hardware_watchpoint; | |
c906108c | 10213 | |
d983da9c | 10214 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
10215 | |
10216 | /* If the expression is "local", then set up a "watchpoint scope" | |
10217 | breakpoint at the point where we've left the scope of the watchpoint | |
10218 | expression. Create the scope breakpoint before the watchpoint, so | |
10219 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 10220 | if (exp_valid_block && frame) |
d983da9c | 10221 | { |
edb3359d DJ |
10222 | if (frame_id_p (frame_unwind_caller_id (frame))) |
10223 | { | |
10224 | scope_breakpoint | |
a6d9a66e UW |
10225 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
10226 | frame_unwind_caller_pc (frame), | |
06edf0c0 PA |
10227 | bp_watchpoint_scope, |
10228 | &momentary_breakpoint_ops); | |
d983da9c | 10229 | |
edb3359d | 10230 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 10231 | |
edb3359d DJ |
10232 | /* Automatically delete the breakpoint when it hits. */ |
10233 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 10234 | |
edb3359d DJ |
10235 | /* Only break in the proper frame (help with recursion). */ |
10236 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 10237 | |
edb3359d | 10238 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
10239 | scope_breakpoint->loc->gdbarch |
10240 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
10241 | scope_breakpoint->loc->requested_address |
10242 | = frame_unwind_caller_pc (frame); | |
10243 | scope_breakpoint->loc->address | |
a6d9a66e UW |
10244 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
10245 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
10246 | scope_breakpoint->type); |
10247 | } | |
d983da9c DJ |
10248 | } |
10249 | ||
c906108c | 10250 | /* Now set up the breakpoint. */ |
3a5c3e22 PA |
10251 | |
10252 | w = XCNEW (struct watchpoint); | |
10253 | b = &w->base; | |
348d480f | 10254 | if (use_mask) |
3a5c3e22 PA |
10255 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
10256 | &masked_watchpoint_breakpoint_ops); | |
348d480f | 10257 | else |
3a5c3e22 PA |
10258 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
10259 | &watchpoint_breakpoint_ops); | |
37e4754d | 10260 | b->thread = thread; |
b5de0fa7 | 10261 | b->disposition = disp_donttouch; |
348d480f | 10262 | b->pspace = current_program_space; |
3a5c3e22 PA |
10263 | w->exp = exp; |
10264 | w->exp_valid_block = exp_valid_block; | |
10265 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
10266 | if (just_location) |
10267 | { | |
10268 | struct type *t = value_type (val); | |
10269 | CORE_ADDR addr = value_as_address (val); | |
10270 | char *name; | |
10271 | ||
10272 | t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); | |
10273 | name = type_to_string (t); | |
10274 | ||
3a5c3e22 | 10275 | w->exp_string_reparse = xstrprintf ("* (%s *) %s", name, |
d63d0675 | 10276 | core_addr_to_string (addr)); |
06a64a0b TT |
10277 | xfree (name); |
10278 | ||
3a5c3e22 | 10279 | w->exp_string = xstrprintf ("-location %.*s", |
d63d0675 JK |
10280 | (int) (exp_end - exp_start), exp_start); |
10281 | ||
06a64a0b TT |
10282 | /* The above expression is in C. */ |
10283 | b->language = language_c; | |
10284 | } | |
10285 | else | |
3a5c3e22 | 10286 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
9c06b0b4 TJB |
10287 | |
10288 | if (use_mask) | |
10289 | { | |
3a5c3e22 | 10290 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
10291 | } |
10292 | else | |
10293 | { | |
3a5c3e22 PA |
10294 | w->val = val; |
10295 | w->val_valid = 1; | |
9c06b0b4 | 10296 | } |
77b06cd7 | 10297 | |
c906108c SS |
10298 | if (cond_start) |
10299 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
10300 | else | |
10301 | b->cond_string = 0; | |
c5aa993b | 10302 | |
c906108c | 10303 | if (frame) |
f6bc2008 | 10304 | { |
3a5c3e22 PA |
10305 | w->watchpoint_frame = get_frame_id (frame); |
10306 | w->watchpoint_thread = inferior_ptid; | |
f6bc2008 | 10307 | } |
c906108c | 10308 | else |
f6bc2008 | 10309 | { |
3a5c3e22 PA |
10310 | w->watchpoint_frame = null_frame_id; |
10311 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 10312 | } |
c906108c | 10313 | |
d983da9c | 10314 | if (scope_breakpoint != NULL) |
c906108c | 10315 | { |
d983da9c DJ |
10316 | /* The scope breakpoint is related to the watchpoint. We will |
10317 | need to act on them together. */ | |
10318 | b->related_breakpoint = scope_breakpoint; | |
10319 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 10320 | } |
d983da9c | 10321 | |
06a64a0b TT |
10322 | if (!just_location) |
10323 | value_free_to_mark (mark); | |
2d134ed3 | 10324 | |
a9634178 TJB |
10325 | TRY_CATCH (e, RETURN_MASK_ALL) |
10326 | { | |
10327 | /* Finally update the new watchpoint. This creates the locations | |
10328 | that should be inserted. */ | |
3a5c3e22 | 10329 | update_watchpoint (w, 1); |
a9634178 TJB |
10330 | } |
10331 | if (e.reason < 0) | |
10332 | { | |
10333 | delete_breakpoint (b); | |
10334 | throw_exception (e); | |
10335 | } | |
10336 | ||
3ea46bff | 10337 | install_breakpoint (internal, b, 1); |
c906108c SS |
10338 | } |
10339 | ||
e09342b5 | 10340 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 10341 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 10342 | |
c906108c | 10343 | static int |
a9634178 | 10344 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
10345 | { |
10346 | int found_memory_cnt = 0; | |
2e70b7b9 | 10347 | struct value *head = v; |
c906108c SS |
10348 | |
10349 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 10350 | if (!can_use_hw_watchpoints) |
c906108c | 10351 | return 0; |
c5aa993b | 10352 | |
5c44784c JM |
10353 | /* Make sure that the value of the expression depends only upon |
10354 | memory contents, and values computed from them within GDB. If we | |
10355 | find any register references or function calls, we can't use a | |
10356 | hardware watchpoint. | |
10357 | ||
10358 | The idea here is that evaluating an expression generates a series | |
10359 | of values, one holding the value of every subexpression. (The | |
10360 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
10361 | a*b+c.) GDB's values hold almost enough information to establish | |
10362 | the criteria given above --- they identify memory lvalues, | |
10363 | register lvalues, computed values, etcetera. So we can evaluate | |
10364 | the expression, and then scan the chain of values that leaves | |
10365 | behind to decide whether we can detect any possible change to the | |
10366 | expression's final value using only hardware watchpoints. | |
10367 | ||
10368 | However, I don't think that the values returned by inferior | |
10369 | function calls are special in any way. So this function may not | |
10370 | notice that an expression involving an inferior function call | |
10371 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 10372 | for (; v; v = value_next (v)) |
c906108c | 10373 | { |
5c44784c | 10374 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 10375 | { |
8464be76 DJ |
10376 | if (v != head && value_lazy (v)) |
10377 | /* A lazy memory lvalue in the chain is one that GDB never | |
10378 | needed to fetch; we either just used its address (e.g., | |
10379 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
10380 | in `a,b'). This doesn't apply to HEAD; if that is | |
10381 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 10382 | ; |
53a5351d | 10383 | else |
5c44784c JM |
10384 | { |
10385 | /* Ahh, memory we actually used! Check if we can cover | |
10386 | it with hardware watchpoints. */ | |
df407dfe | 10387 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
10388 | |
10389 | /* We only watch structs and arrays if user asked for it | |
10390 | explicitly, never if they just happen to appear in a | |
10391 | middle of some value chain. */ | |
10392 | if (v == head | |
10393 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
10394 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
10395 | { | |
42ae5230 | 10396 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
10397 | int len; |
10398 | int num_regs; | |
10399 | ||
a9634178 | 10400 | len = (target_exact_watchpoints |
e09342b5 TJB |
10401 | && is_scalar_type_recursive (vtype))? |
10402 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 10403 | |
e09342b5 TJB |
10404 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
10405 | if (!num_regs) | |
2e70b7b9 MS |
10406 | return 0; |
10407 | else | |
e09342b5 | 10408 | found_memory_cnt += num_regs; |
2e70b7b9 | 10409 | } |
5c44784c | 10410 | } |
c5aa993b | 10411 | } |
5086187c AC |
10412 | else if (VALUE_LVAL (v) != not_lval |
10413 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 10414 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 10415 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 10416 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
10417 | } |
10418 | ||
10419 | /* The expression itself looks suitable for using a hardware | |
10420 | watchpoint, but give the target machine a chance to reject it. */ | |
10421 | return found_memory_cnt; | |
10422 | } | |
10423 | ||
8b93c638 | 10424 | void |
84f4c1fe | 10425 | watch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 10426 | { |
84f4c1fe | 10427 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
10428 | } |
10429 | ||
10430 | /* A helper function that looks for an argument at the start of a | |
10431 | string. The argument must also either be at the end of the string, | |
10432 | or be followed by whitespace. Returns 1 if it finds the argument, | |
10433 | 0 otherwise. If the argument is found, it updates *STR. */ | |
10434 | ||
10435 | static int | |
10436 | check_for_argument (char **str, char *arg, int arg_len) | |
10437 | { | |
10438 | if (strncmp (*str, arg, arg_len) == 0 | |
10439 | && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len]))) | |
10440 | { | |
10441 | *str += arg_len; | |
10442 | return 1; | |
10443 | } | |
10444 | return 0; | |
10445 | } | |
10446 | ||
10447 | /* A helper function that looks for the "-location" argument and then | |
10448 | calls watch_command_1. */ | |
10449 | ||
10450 | static void | |
10451 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
10452 | { | |
10453 | int just_location = 0; | |
10454 | ||
10455 | if (arg | |
10456 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
10457 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
10458 | { | |
e9cafbcc | 10459 | arg = skip_spaces (arg); |
06a64a0b TT |
10460 | just_location = 1; |
10461 | } | |
10462 | ||
84f4c1fe | 10463 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 10464 | } |
8926118c | 10465 | |
c5aa993b | 10466 | static void |
fba45db2 | 10467 | watch_command (char *arg, int from_tty) |
c906108c | 10468 | { |
06a64a0b | 10469 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
10470 | } |
10471 | ||
8b93c638 | 10472 | void |
84f4c1fe | 10473 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 10474 | { |
84f4c1fe | 10475 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 10476 | } |
8926118c | 10477 | |
c5aa993b | 10478 | static void |
fba45db2 | 10479 | rwatch_command (char *arg, int from_tty) |
c906108c | 10480 | { |
06a64a0b | 10481 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
10482 | } |
10483 | ||
8b93c638 | 10484 | void |
84f4c1fe | 10485 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 10486 | { |
84f4c1fe | 10487 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 10488 | } |
8926118c | 10489 | |
c5aa993b | 10490 | static void |
fba45db2 | 10491 | awatch_command (char *arg, int from_tty) |
c906108c | 10492 | { |
06a64a0b | 10493 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 10494 | } |
c906108c | 10495 | \f |
c5aa993b | 10496 | |
43ff13b4 | 10497 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
10498 | because it uses the mechanisms of breakpoints. */ |
10499 | ||
bfec99b2 PA |
10500 | struct until_break_command_continuation_args |
10501 | { | |
10502 | struct breakpoint *breakpoint; | |
10503 | struct breakpoint *breakpoint2; | |
186c406b | 10504 | int thread_num; |
bfec99b2 PA |
10505 | }; |
10506 | ||
43ff13b4 | 10507 | /* This function is called by fetch_inferior_event via the |
4a64f543 | 10508 | cmd_continuation pointer, to complete the until command. It takes |
43ff13b4 | 10509 | care of cleaning up the temporary breakpoints set up by the until |
4a64f543 | 10510 | command. */ |
c2c6d25f | 10511 | static void |
fa4cd53f | 10512 | until_break_command_continuation (void *arg, int err) |
43ff13b4 | 10513 | { |
bfec99b2 PA |
10514 | struct until_break_command_continuation_args *a = arg; |
10515 | ||
10516 | delete_breakpoint (a->breakpoint); | |
10517 | if (a->breakpoint2) | |
10518 | delete_breakpoint (a->breakpoint2); | |
186c406b | 10519 | delete_longjmp_breakpoint (a->thread_num); |
43ff13b4 JM |
10520 | } |
10521 | ||
c906108c | 10522 | void |
ae66c1fc | 10523 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
10524 | { |
10525 | struct symtabs_and_lines sals; | |
10526 | struct symtab_and_line sal; | |
206415a3 | 10527 | struct frame_info *frame = get_selected_frame (NULL); |
883bc8d1 PA |
10528 | struct gdbarch *frame_gdbarch = get_frame_arch (frame); |
10529 | struct frame_id stack_frame_id = get_stack_frame_id (frame); | |
10530 | struct frame_id caller_frame_id = frame_unwind_caller_id (frame); | |
c906108c | 10531 | struct breakpoint *breakpoint; |
f107f563 | 10532 | struct breakpoint *breakpoint2 = NULL; |
c906108c | 10533 | struct cleanup *old_chain; |
186c406b TT |
10534 | int thread; |
10535 | struct thread_info *tp; | |
c906108c SS |
10536 | |
10537 | clear_proceed_status (); | |
10538 | ||
10539 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 10540 | this function. */ |
c5aa993b | 10541 | |
1bfeeb0f | 10542 | if (last_displayed_sal_is_valid ()) |
f8eba3c6 | 10543 | sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE, |
1bfeeb0f | 10544 | get_last_displayed_symtab (), |
f8eba3c6 | 10545 | get_last_displayed_line ()); |
c906108c | 10546 | else |
f8eba3c6 TT |
10547 | sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE, |
10548 | (struct symtab *) NULL, 0); | |
c5aa993b | 10549 | |
c906108c | 10550 | if (sals.nelts != 1) |
8a3fe4f8 | 10551 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 10552 | |
c906108c | 10553 | sal = sals.sals[0]; |
4a64f543 | 10554 | xfree (sals.sals); /* malloc'd, so freed. */ |
c5aa993b | 10555 | |
c906108c | 10556 | if (*arg) |
8a3fe4f8 | 10557 | error (_("Junk at end of arguments.")); |
c5aa993b | 10558 | |
c906108c | 10559 | resolve_sal_pc (&sal); |
c5aa993b | 10560 | |
186c406b TT |
10561 | tp = inferior_thread (); |
10562 | thread = tp->num; | |
10563 | ||
883bc8d1 PA |
10564 | old_chain = make_cleanup (null_cleanup, NULL); |
10565 | ||
10566 | /* Installing a breakpoint invalidates the frame chain (as it may | |
10567 | need to switch threads), so do any frame handling first. */ | |
10568 | ||
ae66c1fc EZ |
10569 | /* Keep within the current frame, or in frames called by the current |
10570 | one. */ | |
edb3359d | 10571 | |
883bc8d1 | 10572 | if (frame_id_p (caller_frame_id)) |
c906108c | 10573 | { |
883bc8d1 PA |
10574 | struct symtab_and_line sal2; |
10575 | ||
10576 | sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0); | |
10577 | sal2.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e | 10578 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
883bc8d1 PA |
10579 | sal2, |
10580 | caller_frame_id, | |
f107f563 VP |
10581 | bp_until); |
10582 | make_cleanup_delete_breakpoint (breakpoint2); | |
186c406b | 10583 | |
883bc8d1 | 10584 | set_longjmp_breakpoint (tp, caller_frame_id); |
186c406b | 10585 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); |
c906108c | 10586 | } |
c5aa993b | 10587 | |
c70a6932 JK |
10588 | /* set_momentary_breakpoint could invalidate FRAME. */ |
10589 | frame = NULL; | |
10590 | ||
883bc8d1 PA |
10591 | if (anywhere) |
10592 | /* If the user told us to continue until a specified location, | |
10593 | we don't specify a frame at which we need to stop. */ | |
10594 | breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, | |
10595 | null_frame_id, bp_until); | |
10596 | else | |
10597 | /* Otherwise, specify the selected frame, because we want to stop | |
10598 | only at the very same frame. */ | |
10599 | breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, | |
10600 | stack_frame_id, bp_until); | |
10601 | make_cleanup_delete_breakpoint (breakpoint); | |
10602 | ||
c906108c | 10603 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
f107f563 | 10604 | |
4a64f543 MS |
10605 | /* If we are running asynchronously, and proceed call above has |
10606 | actually managed to start the target, arrange for breakpoints to | |
10607 | be deleted when the target stops. Otherwise, we're already | |
10608 | stopped and delete breakpoints via cleanup chain. */ | |
f107f563 | 10609 | |
8ea051c5 | 10610 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 10611 | { |
bfec99b2 PA |
10612 | struct until_break_command_continuation_args *args; |
10613 | args = xmalloc (sizeof (*args)); | |
f107f563 | 10614 | |
bfec99b2 PA |
10615 | args->breakpoint = breakpoint; |
10616 | args->breakpoint2 = breakpoint2; | |
186c406b | 10617 | args->thread_num = thread; |
f107f563 VP |
10618 | |
10619 | discard_cleanups (old_chain); | |
95e54da7 PA |
10620 | add_continuation (inferior_thread (), |
10621 | until_break_command_continuation, args, | |
604ead4a | 10622 | xfree); |
f107f563 VP |
10623 | } |
10624 | else | |
c5aa993b | 10625 | do_cleanups (old_chain); |
c906108c | 10626 | } |
ae66c1fc | 10627 | |
c906108c SS |
10628 | /* This function attempts to parse an optional "if <cond>" clause |
10629 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 10630 | |
c906108c SS |
10631 | Else, it returns a pointer to the condition string. (It does not |
10632 | attempt to evaluate the string against a particular block.) And, | |
10633 | it updates arg to point to the first character following the parsed | |
4a64f543 | 10634 | if clause in the arg string. */ |
53a5351d | 10635 | |
c906108c | 10636 | static char * |
fba45db2 | 10637 | ep_parse_optional_if_clause (char **arg) |
c906108c | 10638 | { |
c5aa993b JM |
10639 | char *cond_string; |
10640 | ||
10641 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 10642 | return NULL; |
c5aa993b | 10643 | |
4a64f543 | 10644 | /* Skip the "if" keyword. */ |
c906108c | 10645 | (*arg) += 2; |
c5aa993b | 10646 | |
c906108c | 10647 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 10648 | condition string. */ |
e9cafbcc | 10649 | *arg = skip_spaces (*arg); |
c906108c | 10650 | cond_string = *arg; |
c5aa993b | 10651 | |
4a64f543 MS |
10652 | /* Assume that the condition occupies the remainder of the arg |
10653 | string. */ | |
c906108c | 10654 | (*arg) += strlen (cond_string); |
c5aa993b | 10655 | |
c906108c SS |
10656 | return cond_string; |
10657 | } | |
c5aa993b | 10658 | |
c906108c SS |
10659 | /* Commands to deal with catching events, such as signals, exceptions, |
10660 | process start/exit, etc. */ | |
c5aa993b JM |
10661 | |
10662 | typedef enum | |
10663 | { | |
44feb3ce TT |
10664 | catch_fork_temporary, catch_vfork_temporary, |
10665 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
10666 | } |
10667 | catch_fork_kind; | |
10668 | ||
c906108c | 10669 | static void |
cc59ec59 MS |
10670 | catch_fork_command_1 (char *arg, int from_tty, |
10671 | struct cmd_list_element *command) | |
c906108c | 10672 | { |
a6d9a66e | 10673 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 10674 | char *cond_string = NULL; |
44feb3ce TT |
10675 | catch_fork_kind fork_kind; |
10676 | int tempflag; | |
10677 | ||
10678 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
10679 | tempflag = (fork_kind == catch_fork_temporary | |
10680 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 10681 | |
44feb3ce TT |
10682 | if (!arg) |
10683 | arg = ""; | |
e9cafbcc | 10684 | arg = skip_spaces (arg); |
c5aa993b | 10685 | |
c906108c | 10686 | /* The allowed syntax is: |
c5aa993b JM |
10687 | catch [v]fork |
10688 | catch [v]fork if <cond> | |
10689 | ||
4a64f543 | 10690 | First, check if there's an if clause. */ |
c906108c | 10691 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 10692 | |
c906108c | 10693 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 10694 | error (_("Junk at end of arguments.")); |
c5aa993b | 10695 | |
c906108c | 10696 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 10697 | and enable reporting of such events. */ |
c5aa993b JM |
10698 | switch (fork_kind) |
10699 | { | |
44feb3ce TT |
10700 | case catch_fork_temporary: |
10701 | case catch_fork_permanent: | |
a6d9a66e | 10702 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 10703 | &catch_fork_breakpoint_ops); |
c906108c | 10704 | break; |
44feb3ce TT |
10705 | case catch_vfork_temporary: |
10706 | case catch_vfork_permanent: | |
a6d9a66e | 10707 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 10708 | &catch_vfork_breakpoint_ops); |
c906108c | 10709 | break; |
c5aa993b | 10710 | default: |
8a3fe4f8 | 10711 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 10712 | break; |
c5aa993b | 10713 | } |
c906108c SS |
10714 | } |
10715 | ||
10716 | static void | |
cc59ec59 MS |
10717 | catch_exec_command_1 (char *arg, int from_tty, |
10718 | struct cmd_list_element *command) | |
c906108c | 10719 | { |
b4d90040 | 10720 | struct exec_catchpoint *c; |
a6d9a66e | 10721 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 10722 | int tempflag; |
c5aa993b | 10723 | char *cond_string = NULL; |
c906108c | 10724 | |
44feb3ce TT |
10725 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
10726 | ||
10727 | if (!arg) | |
10728 | arg = ""; | |
e9cafbcc | 10729 | arg = skip_spaces (arg); |
c906108c SS |
10730 | |
10731 | /* The allowed syntax is: | |
c5aa993b JM |
10732 | catch exec |
10733 | catch exec if <cond> | |
c906108c | 10734 | |
4a64f543 | 10735 | First, check if there's an if clause. */ |
c906108c SS |
10736 | cond_string = ep_parse_optional_if_clause (&arg); |
10737 | ||
10738 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 10739 | error (_("Junk at end of arguments.")); |
c906108c | 10740 | |
b4d90040 PA |
10741 | c = XNEW (struct exec_catchpoint); |
10742 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, | |
10743 | &catch_exec_breakpoint_ops); | |
10744 | c->exec_pathname = NULL; | |
10745 | ||
3ea46bff | 10746 | install_breakpoint (0, &c->base, 1); |
c906108c | 10747 | } |
c5aa993b | 10748 | |
3086aeae | 10749 | static enum print_stop_action |
348d480f | 10750 | print_it_exception_catchpoint (bpstat bs) |
3086aeae | 10751 | { |
79a45e25 | 10752 | struct ui_out *uiout = current_uiout; |
348d480f | 10753 | struct breakpoint *b = bs->breakpoint_at; |
ade92717 | 10754 | int bp_temp, bp_throw; |
3086aeae | 10755 | |
ade92717 | 10756 | annotate_catchpoint (b->number); |
3086aeae | 10757 | |
ade92717 AR |
10758 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
10759 | if (b->loc->address != b->loc->requested_address) | |
10760 | breakpoint_adjustment_warning (b->loc->requested_address, | |
10761 | b->loc->address, | |
10762 | b->number, 1); | |
df2b6d2d | 10763 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
10764 | ui_out_text (uiout, |
10765 | bp_temp ? "Temporary catchpoint " | |
10766 | : "Catchpoint "); | |
10767 | if (!ui_out_is_mi_like_p (uiout)) | |
10768 | ui_out_field_int (uiout, "bkptno", b->number); | |
10769 | ui_out_text (uiout, | |
c0b37c48 AR |
10770 | bp_throw ? " (exception thrown), " |
10771 | : " (exception caught), "); | |
ade92717 AR |
10772 | if (ui_out_is_mi_like_p (uiout)) |
10773 | { | |
10774 | ui_out_field_string (uiout, "reason", | |
10775 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
10776 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
10777 | ui_out_field_int (uiout, "bkptno", b->number); | |
10778 | } | |
3086aeae DJ |
10779 | return PRINT_SRC_AND_LOC; |
10780 | } | |
10781 | ||
10782 | static void | |
cc59ec59 MS |
10783 | print_one_exception_catchpoint (struct breakpoint *b, |
10784 | struct bp_location **last_loc) | |
3086aeae | 10785 | { |
79a45b7d | 10786 | struct value_print_options opts; |
79a45e25 | 10787 | struct ui_out *uiout = current_uiout; |
cc59ec59 | 10788 | |
79a45b7d TT |
10789 | get_user_print_options (&opts); |
10790 | if (opts.addressprint) | |
3086aeae DJ |
10791 | { |
10792 | annotate_field (4); | |
604133b5 AR |
10793 | if (b->loc == NULL || b->loc->shlib_disabled) |
10794 | ui_out_field_string (uiout, "addr", "<PENDING>"); | |
10795 | else | |
5af949e3 UW |
10796 | ui_out_field_core_addr (uiout, "addr", |
10797 | b->loc->gdbarch, b->loc->address); | |
3086aeae DJ |
10798 | } |
10799 | annotate_field (5); | |
604133b5 | 10800 | if (b->loc) |
a6d9a66e | 10801 | *last_loc = b->loc; |
3086aeae DJ |
10802 | if (strstr (b->addr_string, "throw") != NULL) |
10803 | ui_out_field_string (uiout, "what", "exception throw"); | |
10804 | else | |
10805 | ui_out_field_string (uiout, "what", "exception catch"); | |
10806 | } | |
10807 | ||
10808 | static void | |
10809 | print_mention_exception_catchpoint (struct breakpoint *b) | |
10810 | { | |
79a45e25 | 10811 | struct ui_out *uiout = current_uiout; |
ade92717 AR |
10812 | int bp_temp; |
10813 | int bp_throw; | |
10814 | ||
df2b6d2d | 10815 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
10816 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
10817 | ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ") | |
10818 | : _("Catchpoint ")); | |
10819 | ui_out_field_int (uiout, "bkptno", b->number); | |
10820 | ui_out_text (uiout, bp_throw ? _(" (throw)") | |
10821 | : _(" (catch)")); | |
3086aeae DJ |
10822 | } |
10823 | ||
6149aea9 PA |
10824 | /* Implement the "print_recreate" breakpoint_ops method for throw and |
10825 | catch catchpoints. */ | |
10826 | ||
10827 | static void | |
4a64f543 MS |
10828 | print_recreate_exception_catchpoint (struct breakpoint *b, |
10829 | struct ui_file *fp) | |
6149aea9 PA |
10830 | { |
10831 | int bp_temp; | |
10832 | int bp_throw; | |
10833 | ||
10834 | bp_temp = b->disposition == disp_del; | |
10835 | bp_throw = strstr (b->addr_string, "throw") != NULL; | |
10836 | fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch "); | |
10837 | fprintf_unfiltered (fp, bp_throw ? "throw" : "catch"); | |
d9b3f62e | 10838 | print_recreate_thread (b, fp); |
6149aea9 PA |
10839 | } |
10840 | ||
2060206e | 10841 | static struct breakpoint_ops gnu_v3_exception_catchpoint_ops; |
3086aeae DJ |
10842 | |
10843 | static int | |
10844 | handle_gnu_v3_exceptions (int tempflag, char *cond_string, | |
10845 | enum exception_event_kind ex_event, int from_tty) | |
10846 | { | |
604133b5 AR |
10847 | char *trigger_func_name; |
10848 | ||
3086aeae | 10849 | if (ex_event == EX_EVENT_CATCH) |
604133b5 | 10850 | trigger_func_name = "__cxa_begin_catch"; |
3086aeae | 10851 | else |
604133b5 | 10852 | trigger_func_name = "__cxa_throw"; |
3086aeae | 10853 | |
8cdf0e15 VP |
10854 | create_breakpoint (get_current_arch (), |
10855 | trigger_func_name, cond_string, -1, | |
10856 | 0 /* condition and thread are valid. */, | |
0fb4aa4b | 10857 | tempflag, bp_breakpoint, |
8cdf0e15 VP |
10858 | 0, |
10859 | AUTO_BOOLEAN_TRUE /* pending */, | |
10860 | &gnu_v3_exception_catchpoint_ops, from_tty, | |
84f4c1fe | 10861 | 1 /* enabled */, |
44f238bb PA |
10862 | 0 /* internal */, |
10863 | 0); | |
3086aeae | 10864 | |
3086aeae DJ |
10865 | return 1; |
10866 | } | |
10867 | ||
4a64f543 | 10868 | /* Deal with "catch catch" and "catch throw" commands. */ |
c906108c SS |
10869 | |
10870 | static void | |
fba45db2 KB |
10871 | catch_exception_command_1 (enum exception_event_kind ex_event, char *arg, |
10872 | int tempflag, int from_tty) | |
c906108c | 10873 | { |
c5aa993b | 10874 | char *cond_string = NULL; |
c5aa993b | 10875 | |
44feb3ce TT |
10876 | if (!arg) |
10877 | arg = ""; | |
e9cafbcc | 10878 | arg = skip_spaces (arg); |
c5aa993b | 10879 | |
c906108c SS |
10880 | cond_string = ep_parse_optional_if_clause (&arg); |
10881 | ||
10882 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 10883 | error (_("Junk at end of arguments.")); |
c906108c | 10884 | |
059fb39f PM |
10885 | if (ex_event != EX_EVENT_THROW |
10886 | && ex_event != EX_EVENT_CATCH) | |
8a3fe4f8 | 10887 | error (_("Unsupported or unknown exception event; cannot catch it")); |
c906108c | 10888 | |
3086aeae DJ |
10889 | if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty)) |
10890 | return; | |
10891 | ||
8a3fe4f8 | 10892 | warning (_("Unsupported with this platform/compiler combination.")); |
c906108c SS |
10893 | } |
10894 | ||
44feb3ce TT |
10895 | /* Implementation of "catch catch" command. */ |
10896 | ||
10897 | static void | |
10898 | catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command) | |
10899 | { | |
10900 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
cc59ec59 | 10901 | |
44feb3ce TT |
10902 | catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty); |
10903 | } | |
10904 | ||
10905 | /* Implementation of "catch throw" command. */ | |
10906 | ||
10907 | static void | |
10908 | catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command) | |
10909 | { | |
10910 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
cc59ec59 | 10911 | |
44feb3ce TT |
10912 | catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty); |
10913 | } | |
10914 | ||
9ac4176b | 10915 | void |
28010a5d PA |
10916 | init_ada_exception_breakpoint (struct breakpoint *b, |
10917 | struct gdbarch *gdbarch, | |
10918 | struct symtab_and_line sal, | |
10919 | char *addr_string, | |
c0a91b2b | 10920 | const struct breakpoint_ops *ops, |
28010a5d PA |
10921 | int tempflag, |
10922 | int from_tty) | |
f7f9143b | 10923 | { |
f7f9143b JB |
10924 | if (from_tty) |
10925 | { | |
5af949e3 UW |
10926 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
10927 | if (!loc_gdbarch) | |
10928 | loc_gdbarch = gdbarch; | |
10929 | ||
6c95b8df PA |
10930 | describe_other_breakpoints (loc_gdbarch, |
10931 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
10932 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
10933 | version for exception catchpoints, because two catchpoints | |
10934 | used for different exception names will use the same address. | |
10935 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 10936 | unproductive. Besides, the warning phrasing is also a bit |
e5dd4106 | 10937 | inappropriate, we should use the word catchpoint, and tell |
f7f9143b JB |
10938 | the user what type of catchpoint it is. The above is good |
10939 | enough for now, though. */ | |
10940 | } | |
10941 | ||
28010a5d | 10942 | init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops); |
f7f9143b JB |
10943 | |
10944 | b->enable_state = bp_enabled; | |
10945 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
f7f9143b JB |
10946 | b->addr_string = addr_string; |
10947 | b->language = language_ada; | |
f7f9143b JB |
10948 | } |
10949 | ||
a96d9b2e SDJ |
10950 | /* Splits the argument using space as delimiter. Returns an xmalloc'd |
10951 | filter list, or NULL if no filtering is required. */ | |
10952 | static VEC(int) * | |
10953 | catch_syscall_split_args (char *arg) | |
10954 | { | |
10955 | VEC(int) *result = NULL; | |
29d0bb3d | 10956 | struct cleanup *cleanup = make_cleanup (VEC_cleanup (int), &result); |
a96d9b2e SDJ |
10957 | |
10958 | while (*arg != '\0') | |
10959 | { | |
10960 | int i, syscall_number; | |
10961 | char *endptr; | |
10962 | char cur_name[128]; | |
10963 | struct syscall s; | |
10964 | ||
10965 | /* Skip whitespace. */ | |
10966 | while (isspace (*arg)) | |
10967 | arg++; | |
10968 | ||
10969 | for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) | |
10970 | cur_name[i] = arg[i]; | |
10971 | cur_name[i] = '\0'; | |
10972 | arg += i; | |
10973 | ||
10974 | /* Check if the user provided a syscall name or a number. */ | |
10975 | syscall_number = (int) strtol (cur_name, &endptr, 0); | |
10976 | if (*endptr == '\0') | |
bccd0dd2 | 10977 | get_syscall_by_number (syscall_number, &s); |
a96d9b2e SDJ |
10978 | else |
10979 | { | |
10980 | /* We have a name. Let's check if it's valid and convert it | |
10981 | to a number. */ | |
10982 | get_syscall_by_name (cur_name, &s); | |
10983 | ||
10984 | if (s.number == UNKNOWN_SYSCALL) | |
4a64f543 MS |
10985 | /* Here we have to issue an error instead of a warning, |
10986 | because GDB cannot do anything useful if there's no | |
10987 | syscall number to be caught. */ | |
a96d9b2e SDJ |
10988 | error (_("Unknown syscall name '%s'."), cur_name); |
10989 | } | |
10990 | ||
10991 | /* Ok, it's valid. */ | |
10992 | VEC_safe_push (int, result, s.number); | |
10993 | } | |
10994 | ||
10995 | discard_cleanups (cleanup); | |
10996 | return result; | |
10997 | } | |
10998 | ||
10999 | /* Implement the "catch syscall" command. */ | |
11000 | ||
11001 | static void | |
cc59ec59 MS |
11002 | catch_syscall_command_1 (char *arg, int from_tty, |
11003 | struct cmd_list_element *command) | |
a96d9b2e SDJ |
11004 | { |
11005 | int tempflag; | |
11006 | VEC(int) *filter; | |
11007 | struct syscall s; | |
11008 | struct gdbarch *gdbarch = get_current_arch (); | |
11009 | ||
11010 | /* Checking if the feature if supported. */ | |
11011 | if (gdbarch_get_syscall_number_p (gdbarch) == 0) | |
11012 | error (_("The feature 'catch syscall' is not supported on \ | |
ea666128 | 11013 | this architecture yet.")); |
a96d9b2e SDJ |
11014 | |
11015 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
11016 | ||
e9cafbcc | 11017 | arg = skip_spaces (arg); |
a96d9b2e SDJ |
11018 | |
11019 | /* We need to do this first "dummy" translation in order | |
11020 | to get the syscall XML file loaded or, most important, | |
11021 | to display a warning to the user if there's no XML file | |
11022 | for his/her architecture. */ | |
11023 | get_syscall_by_number (0, &s); | |
11024 | ||
11025 | /* The allowed syntax is: | |
11026 | catch syscall | |
11027 | catch syscall <name | number> [<name | number> ... <name | number>] | |
11028 | ||
11029 | Let's check if there's a syscall name. */ | |
11030 | ||
11031 | if (arg != NULL) | |
11032 | filter = catch_syscall_split_args (arg); | |
11033 | else | |
11034 | filter = NULL; | |
11035 | ||
11036 | create_syscall_event_catchpoint (tempflag, filter, | |
11037 | &catch_syscall_breakpoint_ops); | |
11038 | } | |
11039 | ||
c906108c | 11040 | static void |
fba45db2 | 11041 | catch_command (char *arg, int from_tty) |
c906108c | 11042 | { |
44feb3ce | 11043 | error (_("Catch requires an event name.")); |
c906108c SS |
11044 | } |
11045 | \f | |
11046 | ||
11047 | static void | |
fba45db2 | 11048 | tcatch_command (char *arg, int from_tty) |
c906108c | 11049 | { |
44feb3ce | 11050 | error (_("Catch requires an event name.")); |
c906108c SS |
11051 | } |
11052 | ||
8a2c437b TT |
11053 | /* A qsort comparison function that sorts breakpoints in order. */ |
11054 | ||
11055 | static int | |
11056 | compare_breakpoints (const void *a, const void *b) | |
11057 | { | |
11058 | const breakpoint_p *ba = a; | |
11059 | uintptr_t ua = (uintptr_t) *ba; | |
11060 | const breakpoint_p *bb = b; | |
11061 | uintptr_t ub = (uintptr_t) *bb; | |
11062 | ||
11063 | if ((*ba)->number < (*bb)->number) | |
11064 | return -1; | |
11065 | else if ((*ba)->number > (*bb)->number) | |
11066 | return 1; | |
11067 | ||
11068 | /* Now sort by address, in case we see, e..g, two breakpoints with | |
11069 | the number 0. */ | |
11070 | if (ua < ub) | |
11071 | return -1; | |
11072 | return ub > ub ? 1 : 0; | |
11073 | } | |
11074 | ||
80f8a6eb | 11075 | /* Delete breakpoints by address or line. */ |
c906108c SS |
11076 | |
11077 | static void | |
fba45db2 | 11078 | clear_command (char *arg, int from_tty) |
c906108c | 11079 | { |
8a2c437b | 11080 | struct breakpoint *b, *prev; |
d6e956e5 VP |
11081 | VEC(breakpoint_p) *found = 0; |
11082 | int ix; | |
c906108c SS |
11083 | int default_match; |
11084 | struct symtabs_and_lines sals; | |
11085 | struct symtab_and_line sal; | |
c906108c | 11086 | int i; |
8a2c437b | 11087 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
c906108c SS |
11088 | |
11089 | if (arg) | |
11090 | { | |
f8eba3c6 TT |
11091 | sals = decode_line_spec (arg, (DECODE_LINE_FUNFIRSTLINE |
11092 | | DECODE_LINE_LIST_MODE)); | |
c906108c SS |
11093 | default_match = 0; |
11094 | } | |
11095 | else | |
11096 | { | |
c5aa993b | 11097 | sals.sals = (struct symtab_and_line *) |
c906108c | 11098 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 11099 | make_cleanup (xfree, sals.sals); |
4a64f543 | 11100 | init_sal (&sal); /* Initialize to zeroes. */ |
1bfeeb0f JL |
11101 | |
11102 | /* Set sal's line, symtab, pc, and pspace to the values | |
11103 | corresponding to the last call to print_frame_info. If the | |
11104 | codepoint is not valid, this will set all the fields to 0. */ | |
11105 | get_last_displayed_sal (&sal); | |
c906108c | 11106 | if (sal.symtab == 0) |
8a3fe4f8 | 11107 | error (_("No source file specified.")); |
c906108c SS |
11108 | |
11109 | sals.sals[0] = sal; | |
11110 | sals.nelts = 1; | |
11111 | ||
11112 | default_match = 1; | |
11113 | } | |
11114 | ||
4a64f543 MS |
11115 | /* We don't call resolve_sal_pc here. That's not as bad as it |
11116 | seems, because all existing breakpoints typically have both | |
11117 | file/line and pc set. So, if clear is given file/line, we can | |
11118 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
11119 | |
11120 | We only support clearing given the address explicitly | |
11121 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 11122 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 11123 | due to optimization, all in one block. |
4a64f543 MS |
11124 | |
11125 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
11126 | PC corresponding to the same file:line, the breakpoint won't |
11127 | be cleared. We probably can still clear the breakpoint, but | |
11128 | since the other PC value is never presented to user, user | |
11129 | can only find it by guessing, and it does not seem important | |
11130 | to support that. */ | |
11131 | ||
4a64f543 MS |
11132 | /* For each line spec given, delete bps which correspond to it. Do |
11133 | it in two passes, solely to preserve the current behavior that | |
11134 | from_tty is forced true if we delete more than one | |
11135 | breakpoint. */ | |
c906108c | 11136 | |
80f8a6eb | 11137 | found = NULL; |
8a2c437b | 11138 | make_cleanup (VEC_cleanup (breakpoint_p), &found); |
c906108c SS |
11139 | for (i = 0; i < sals.nelts; i++) |
11140 | { | |
4aac40c8 TT |
11141 | int is_abs, sal_name_len; |
11142 | ||
c906108c | 11143 | /* If exact pc given, clear bpts at that pc. |
c5aa993b JM |
11144 | If line given (pc == 0), clear all bpts on specified line. |
11145 | If defaulting, clear all bpts on default line | |
c906108c | 11146 | or at default pc. |
c5aa993b JM |
11147 | |
11148 | defaulting sal.pc != 0 tests to do | |
11149 | ||
11150 | 0 1 pc | |
11151 | 1 1 pc _and_ line | |
11152 | 0 0 line | |
11153 | 1 0 <can't happen> */ | |
c906108c SS |
11154 | |
11155 | sal = sals.sals[i]; | |
4aac40c8 TT |
11156 | is_abs = sal.symtab == NULL ? 1 : IS_ABSOLUTE_PATH (sal.symtab->filename); |
11157 | sal_name_len = is_abs ? 0 : strlen (sal.symtab->filename); | |
c906108c | 11158 | |
4a64f543 | 11159 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 11160 | ALL_BREAKPOINTS (b) |
c5aa993b | 11161 | { |
0d381245 | 11162 | int match = 0; |
4a64f543 | 11163 | /* Are we going to delete b? */ |
cc60f2e3 | 11164 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
11165 | { |
11166 | struct bp_location *loc = b->loc; | |
11167 | for (; loc; loc = loc->next) | |
11168 | { | |
f8eba3c6 TT |
11169 | /* If the user specified file:line, don't allow a PC |
11170 | match. This matches historical gdb behavior. */ | |
11171 | int pc_match = (!sal.explicit_line | |
11172 | && sal.pc | |
11173 | && (loc->pspace == sal.pspace) | |
11174 | && (loc->address == sal.pc) | |
11175 | && (!section_is_overlay (loc->section) | |
11176 | || loc->section == sal.section)); | |
4aac40c8 TT |
11177 | int line_match = 0; |
11178 | ||
11179 | if ((default_match || sal.explicit_line) | |
11180 | && loc->source_file != NULL | |
11181 | && sal.symtab != NULL | |
11182 | && sal.pspace == loc->pspace | |
11183 | && loc->line_number == sal.line) | |
11184 | { | |
11185 | if (filename_cmp (loc->source_file, | |
11186 | sal.symtab->filename) == 0) | |
11187 | line_match = 1; | |
11188 | else if (!IS_ABSOLUTE_PATH (sal.symtab->filename) | |
11189 | && compare_filenames_for_search (loc->source_file, | |
11190 | sal.symtab->filename, | |
11191 | sal_name_len)) | |
11192 | line_match = 1; | |
11193 | } | |
11194 | ||
0d381245 VP |
11195 | if (pc_match || line_match) |
11196 | { | |
11197 | match = 1; | |
11198 | break; | |
11199 | } | |
11200 | } | |
11201 | } | |
11202 | ||
11203 | if (match) | |
d6e956e5 | 11204 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 11205 | } |
80f8a6eb | 11206 | } |
8a2c437b | 11207 | |
80f8a6eb | 11208 | /* Now go thru the 'found' chain and delete them. */ |
d6e956e5 | 11209 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
11210 | { |
11211 | if (arg) | |
8a3fe4f8 | 11212 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 11213 | else |
8a3fe4f8 | 11214 | error (_("No breakpoint at this line.")); |
80f8a6eb | 11215 | } |
c906108c | 11216 | |
8a2c437b TT |
11217 | /* Remove duplicates from the vec. */ |
11218 | qsort (VEC_address (breakpoint_p, found), | |
11219 | VEC_length (breakpoint_p, found), | |
11220 | sizeof (breakpoint_p), | |
11221 | compare_breakpoints); | |
11222 | prev = VEC_index (breakpoint_p, found, 0); | |
11223 | for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix) | |
11224 | { | |
11225 | if (b == prev) | |
11226 | { | |
11227 | VEC_ordered_remove (breakpoint_p, found, ix); | |
11228 | --ix; | |
11229 | } | |
11230 | } | |
11231 | ||
d6e956e5 | 11232 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 11233 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 11234 | if (from_tty) |
a3f17187 | 11235 | { |
d6e956e5 | 11236 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
11237 | printf_unfiltered (_("Deleted breakpoint ")); |
11238 | else | |
11239 | printf_unfiltered (_("Deleted breakpoints ")); | |
11240 | } | |
80f8a6eb | 11241 | breakpoints_changed (); |
d6e956e5 VP |
11242 | |
11243 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 11244 | { |
c5aa993b | 11245 | if (from_tty) |
d6e956e5 VP |
11246 | printf_unfiltered ("%d ", b->number); |
11247 | delete_breakpoint (b); | |
c906108c | 11248 | } |
80f8a6eb MS |
11249 | if (from_tty) |
11250 | putchar_unfiltered ('\n'); | |
8a2c437b TT |
11251 | |
11252 | do_cleanups (cleanups); | |
c906108c SS |
11253 | } |
11254 | \f | |
11255 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
11256 | all breakpoints that are marked for deletion, whether hit or not. | |
11257 | This is called after any breakpoint is hit, or after errors. */ | |
11258 | ||
11259 | void | |
fba45db2 | 11260 | breakpoint_auto_delete (bpstat bs) |
c906108c | 11261 | { |
35df4500 | 11262 | struct breakpoint *b, *b_tmp; |
c906108c SS |
11263 | |
11264 | for (; bs; bs = bs->next) | |
f431efe5 PA |
11265 | if (bs->breakpoint_at |
11266 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 11267 | && bs->stop) |
f431efe5 | 11268 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 11269 | |
35df4500 | 11270 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 11271 | { |
b5de0fa7 | 11272 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
11273 | delete_breakpoint (b); |
11274 | } | |
c906108c SS |
11275 | } |
11276 | ||
4a64f543 MS |
11277 | /* A comparison function for bp_location AP and BP being interfaced to |
11278 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
11279 | does breakpoint_address_is_meaningful say for its OWNER), | |
11280 | secondarily by ordering first bp_permanent OWNERed elements and | |
11281 | terciarily just ensuring the array is sorted stable way despite | |
e5dd4106 | 11282 | qsort being an unstable algorithm. */ |
876fa593 JK |
11283 | |
11284 | static int | |
494cfb0f | 11285 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 11286 | { |
494cfb0f JK |
11287 | struct bp_location *a = *(void **) ap; |
11288 | struct bp_location *b = *(void **) bp; | |
2bdf28a0 | 11289 | /* A and B come from existing breakpoints having non-NULL OWNER. */ |
876fa593 JK |
11290 | int a_perm = a->owner->enable_state == bp_permanent; |
11291 | int b_perm = b->owner->enable_state == bp_permanent; | |
11292 | ||
11293 | if (a->address != b->address) | |
11294 | return (a->address > b->address) - (a->address < b->address); | |
11295 | ||
dea2aa5f LM |
11296 | /* Sort locations at the same address by their pspace number, keeping |
11297 | locations of the same inferior (in a multi-inferior environment) | |
11298 | grouped. */ | |
11299 | ||
11300 | if (a->pspace->num != b->pspace->num) | |
11301 | return ((a->pspace->num > b->pspace->num) | |
11302 | - (a->pspace->num < b->pspace->num)); | |
11303 | ||
876fa593 JK |
11304 | /* Sort permanent breakpoints first. */ |
11305 | if (a_perm != b_perm) | |
11306 | return (a_perm < b_perm) - (a_perm > b_perm); | |
11307 | ||
c56a97f9 JK |
11308 | /* Make the internal GDB representation stable across GDB runs |
11309 | where A and B memory inside GDB can differ. Breakpoint locations of | |
11310 | the same type at the same address can be sorted in arbitrary order. */ | |
876fa593 JK |
11311 | |
11312 | if (a->owner->number != b->owner->number) | |
c56a97f9 JK |
11313 | return ((a->owner->number > b->owner->number) |
11314 | - (a->owner->number < b->owner->number)); | |
876fa593 JK |
11315 | |
11316 | return (a > b) - (a < b); | |
11317 | } | |
11318 | ||
876fa593 | 11319 | /* Set bp_location_placed_address_before_address_max and |
4a64f543 MS |
11320 | bp_location_shadow_len_after_address_max according to the current |
11321 | content of the bp_location array. */ | |
f7545552 TT |
11322 | |
11323 | static void | |
876fa593 | 11324 | bp_location_target_extensions_update (void) |
f7545552 | 11325 | { |
876fa593 JK |
11326 | struct bp_location *bl, **blp_tmp; |
11327 | ||
11328 | bp_location_placed_address_before_address_max = 0; | |
11329 | bp_location_shadow_len_after_address_max = 0; | |
11330 | ||
11331 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
11332 | { | |
11333 | CORE_ADDR start, end, addr; | |
11334 | ||
11335 | if (!bp_location_has_shadow (bl)) | |
11336 | continue; | |
11337 | ||
11338 | start = bl->target_info.placed_address; | |
11339 | end = start + bl->target_info.shadow_len; | |
11340 | ||
11341 | gdb_assert (bl->address >= start); | |
11342 | addr = bl->address - start; | |
11343 | if (addr > bp_location_placed_address_before_address_max) | |
11344 | bp_location_placed_address_before_address_max = addr; | |
11345 | ||
11346 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
11347 | ||
11348 | gdb_assert (bl->address < end); | |
11349 | addr = end - bl->address; | |
11350 | if (addr > bp_location_shadow_len_after_address_max) | |
11351 | bp_location_shadow_len_after_address_max = addr; | |
11352 | } | |
f7545552 TT |
11353 | } |
11354 | ||
1e4d1764 YQ |
11355 | /* Download tracepoint locations if they haven't been. */ |
11356 | ||
11357 | static void | |
11358 | download_tracepoint_locations (void) | |
11359 | { | |
11360 | struct bp_location *bl, **blp_tmp; | |
11361 | struct cleanup *old_chain; | |
11362 | ||
11363 | if (!target_can_download_tracepoint ()) | |
11364 | return; | |
11365 | ||
11366 | old_chain = save_current_space_and_thread (); | |
11367 | ||
11368 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
11369 | { | |
11370 | struct tracepoint *t; | |
11371 | ||
11372 | if (!is_tracepoint (bl->owner)) | |
11373 | continue; | |
11374 | ||
11375 | if ((bl->owner->type == bp_fast_tracepoint | |
11376 | ? !may_insert_fast_tracepoints | |
11377 | : !may_insert_tracepoints)) | |
11378 | continue; | |
11379 | ||
11380 | /* In tracepoint, locations are _never_ duplicated, so | |
11381 | should_be_inserted is equivalent to | |
11382 | unduplicated_should_be_inserted. */ | |
11383 | if (!should_be_inserted (bl) || bl->inserted) | |
11384 | continue; | |
11385 | ||
11386 | switch_to_program_space_and_thread (bl->pspace); | |
11387 | ||
11388 | target_download_tracepoint (bl); | |
11389 | ||
11390 | bl->inserted = 1; | |
11391 | t = (struct tracepoint *) bl->owner; | |
11392 | t->number_on_target = bl->owner->number; | |
11393 | } | |
11394 | ||
11395 | do_cleanups (old_chain); | |
11396 | } | |
11397 | ||
934709f0 PW |
11398 | /* Swap the insertion/duplication state between two locations. */ |
11399 | ||
11400 | static void | |
11401 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
11402 | { | |
11403 | const int left_inserted = left->inserted; | |
11404 | const int left_duplicate = left->duplicate; | |
b775012e | 11405 | const int left_needs_update = left->needs_update; |
934709f0 PW |
11406 | const struct bp_target_info left_target_info = left->target_info; |
11407 | ||
1e4d1764 YQ |
11408 | /* Locations of tracepoints can never be duplicated. */ |
11409 | if (is_tracepoint (left->owner)) | |
11410 | gdb_assert (!left->duplicate); | |
11411 | if (is_tracepoint (right->owner)) | |
11412 | gdb_assert (!right->duplicate); | |
11413 | ||
934709f0 PW |
11414 | left->inserted = right->inserted; |
11415 | left->duplicate = right->duplicate; | |
b775012e | 11416 | left->needs_update = right->needs_update; |
934709f0 PW |
11417 | left->target_info = right->target_info; |
11418 | right->inserted = left_inserted; | |
11419 | right->duplicate = left_duplicate; | |
b775012e | 11420 | right->needs_update = left_needs_update; |
934709f0 PW |
11421 | right->target_info = left_target_info; |
11422 | } | |
11423 | ||
b775012e LM |
11424 | /* Force the re-insertion of the locations at ADDRESS. This is called |
11425 | once a new/deleted/modified duplicate location is found and we are evaluating | |
11426 | conditions on the target's side. Such conditions need to be updated on | |
11427 | the target. */ | |
11428 | ||
11429 | static void | |
11430 | force_breakpoint_reinsertion (struct bp_location *bl) | |
11431 | { | |
11432 | struct bp_location **locp = NULL, **loc2p; | |
11433 | struct bp_location *loc; | |
11434 | CORE_ADDR address = 0; | |
11435 | int pspace_num; | |
11436 | ||
11437 | address = bl->address; | |
11438 | pspace_num = bl->pspace->num; | |
11439 | ||
11440 | /* This is only meaningful if the target is | |
11441 | evaluating conditions and if the user has | |
11442 | opted for condition evaluation on the target's | |
11443 | side. */ | |
11444 | if (gdb_evaluates_breakpoint_condition_p () | |
11445 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
11446 | return; | |
11447 | ||
11448 | /* Flag all breakpoint locations with this address and | |
11449 | the same program space as the location | |
11450 | as "its condition has changed". We need to | |
11451 | update the conditions on the target's side. */ | |
11452 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address) | |
11453 | { | |
11454 | loc = *loc2p; | |
11455 | ||
11456 | if (!is_breakpoint (loc->owner) | |
11457 | || pspace_num != loc->pspace->num) | |
11458 | continue; | |
11459 | ||
11460 | /* Flag the location appropriately. We use a different state to | |
11461 | let everyone know that we already updated the set of locations | |
11462 | with addr bl->address and program space bl->pspace. This is so | |
11463 | we don't have to keep calling these functions just to mark locations | |
11464 | that have already been marked. */ | |
11465 | loc->condition_changed = condition_updated; | |
11466 | ||
11467 | /* Free the agent expression bytecode as well. We will compute | |
11468 | it later on. */ | |
11469 | if (loc->cond_bytecode) | |
11470 | { | |
11471 | free_agent_expr (loc->cond_bytecode); | |
11472 | loc->cond_bytecode = NULL; | |
11473 | } | |
11474 | } | |
11475 | } | |
11476 | ||
4cd9bd08 | 11477 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
b60e7edf PA |
11478 | into the inferior, only remove already-inserted locations that no |
11479 | longer should be inserted. Functions that delete a breakpoint or | |
11480 | breakpoints should pass false, so that deleting a breakpoint | |
11481 | doesn't have the side effect of inserting the locations of other | |
11482 | breakpoints that are marked not-inserted, but should_be_inserted | |
11483 | returns true on them. | |
11484 | ||
11485 | This behaviour is useful is situations close to tear-down -- e.g., | |
11486 | after an exec, while the target still has execution, but breakpoint | |
11487 | shadows of the previous executable image should *NOT* be restored | |
11488 | to the new image; or before detaching, where the target still has | |
11489 | execution and wants to delete breakpoints from GDB's lists, and all | |
11490 | breakpoints had already been removed from the inferior. */ | |
11491 | ||
0d381245 | 11492 | static void |
b60e7edf | 11493 | update_global_location_list (int should_insert) |
0d381245 | 11494 | { |
74960c60 | 11495 | struct breakpoint *b; |
876fa593 | 11496 | struct bp_location **locp, *loc; |
f7545552 | 11497 | struct cleanup *cleanups; |
b775012e LM |
11498 | /* Last breakpoint location address that was marked for update. */ |
11499 | CORE_ADDR last_addr = 0; | |
11500 | /* Last breakpoint location program space that was marked for update. */ | |
11501 | int last_pspace_num = -1; | |
f7545552 | 11502 | |
2d134ed3 PA |
11503 | /* Used in the duplicates detection below. When iterating over all |
11504 | bp_locations, points to the first bp_location of a given address. | |
11505 | Breakpoints and watchpoints of different types are never | |
11506 | duplicates of each other. Keep one pointer for each type of | |
11507 | breakpoint/watchpoint, so we only need to loop over all locations | |
11508 | once. */ | |
11509 | struct bp_location *bp_loc_first; /* breakpoint */ | |
11510 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
11511 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
11512 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 11513 | |
4a64f543 MS |
11514 | /* Saved former bp_location array which we compare against the newly |
11515 | built bp_location from the current state of ALL_BREAKPOINTS. */ | |
876fa593 JK |
11516 | struct bp_location **old_location, **old_locp; |
11517 | unsigned old_location_count; | |
11518 | ||
11519 | old_location = bp_location; | |
11520 | old_location_count = bp_location_count; | |
11521 | bp_location = NULL; | |
11522 | bp_location_count = 0; | |
11523 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 11524 | |
74960c60 | 11525 | ALL_BREAKPOINTS (b) |
876fa593 JK |
11526 | for (loc = b->loc; loc; loc = loc->next) |
11527 | bp_location_count++; | |
11528 | ||
11529 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); | |
11530 | locp = bp_location; | |
11531 | ALL_BREAKPOINTS (b) | |
11532 | for (loc = b->loc; loc; loc = loc->next) | |
11533 | *locp++ = loc; | |
11534 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 11535 | bp_location_compare); |
876fa593 JK |
11536 | |
11537 | bp_location_target_extensions_update (); | |
74960c60 | 11538 | |
4a64f543 MS |
11539 | /* Identify bp_location instances that are no longer present in the |
11540 | new list, and therefore should be freed. Note that it's not | |
11541 | necessary that those locations should be removed from inferior -- | |
11542 | if there's another location at the same address (previously | |
11543 | marked as duplicate), we don't need to remove/insert the | |
11544 | location. | |
876fa593 | 11545 | |
4a64f543 MS |
11546 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
11547 | and former bp_location array state respectively. */ | |
876fa593 JK |
11548 | |
11549 | locp = bp_location; | |
11550 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
11551 | old_locp++) | |
74960c60 | 11552 | { |
876fa593 | 11553 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 11554 | struct bp_location **loc2p; |
876fa593 | 11555 | |
e5dd4106 | 11556 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 11557 | not, we have to free it. */ |
c7d46a38 | 11558 | int found_object = 0; |
20874c92 VP |
11559 | /* Tells if the location should remain inserted in the target. */ |
11560 | int keep_in_target = 0; | |
11561 | int removed = 0; | |
876fa593 | 11562 | |
4a64f543 MS |
11563 | /* Skip LOCP entries which will definitely never be needed. |
11564 | Stop either at or being the one matching OLD_LOC. */ | |
876fa593 | 11565 | while (locp < bp_location + bp_location_count |
c7d46a38 | 11566 | && (*locp)->address < old_loc->address) |
876fa593 | 11567 | locp++; |
c7d46a38 PA |
11568 | |
11569 | for (loc2p = locp; | |
11570 | (loc2p < bp_location + bp_location_count | |
11571 | && (*loc2p)->address == old_loc->address); | |
11572 | loc2p++) | |
11573 | { | |
b775012e LM |
11574 | /* Check if this is a new/duplicated location or a duplicated |
11575 | location that had its condition modified. If so, we want to send | |
11576 | its condition to the target if evaluation of conditions is taking | |
11577 | place there. */ | |
11578 | if ((*loc2p)->condition_changed == condition_modified | |
11579 | && (last_addr != old_loc->address | |
11580 | || last_pspace_num != old_loc->pspace->num)) | |
c7d46a38 | 11581 | { |
b775012e LM |
11582 | force_breakpoint_reinsertion (*loc2p); |
11583 | last_pspace_num = old_loc->pspace->num; | |
c7d46a38 | 11584 | } |
b775012e LM |
11585 | |
11586 | if (*loc2p == old_loc) | |
11587 | found_object = 1; | |
c7d46a38 | 11588 | } |
74960c60 | 11589 | |
b775012e LM |
11590 | /* We have already handled this address, update it so that we don't |
11591 | have to go through updates again. */ | |
11592 | last_addr = old_loc->address; | |
11593 | ||
11594 | /* Target-side condition evaluation: Handle deleted locations. */ | |
11595 | if (!found_object) | |
11596 | force_breakpoint_reinsertion (old_loc); | |
11597 | ||
4a64f543 MS |
11598 | /* If this location is no longer present, and inserted, look if |
11599 | there's maybe a new location at the same address. If so, | |
11600 | mark that one inserted, and don't remove this one. This is | |
11601 | needed so that we don't have a time window where a breakpoint | |
11602 | at certain location is not inserted. */ | |
74960c60 | 11603 | |
876fa593 | 11604 | if (old_loc->inserted) |
0d381245 | 11605 | { |
4a64f543 MS |
11606 | /* If the location is inserted now, we might have to remove |
11607 | it. */ | |
74960c60 | 11608 | |
876fa593 | 11609 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 11610 | { |
4a64f543 MS |
11611 | /* The location is still present in the location list, |
11612 | and still should be inserted. Don't do anything. */ | |
20874c92 | 11613 | keep_in_target = 1; |
74960c60 VP |
11614 | } |
11615 | else | |
11616 | { | |
b775012e LM |
11617 | /* This location still exists, but it won't be kept in the |
11618 | target since it may have been disabled. We proceed to | |
11619 | remove its target-side condition. */ | |
11620 | ||
4a64f543 MS |
11621 | /* The location is either no longer present, or got |
11622 | disabled. See if there's another location at the | |
11623 | same address, in which case we don't need to remove | |
11624 | this one from the target. */ | |
876fa593 | 11625 | |
2bdf28a0 | 11626 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
11627 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
11628 | { | |
876fa593 | 11629 | for (loc2p = locp; |
c7d46a38 PA |
11630 | (loc2p < bp_location + bp_location_count |
11631 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
11632 | loc2p++) |
11633 | { | |
11634 | struct bp_location *loc2 = *loc2p; | |
11635 | ||
2d134ed3 | 11636 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 11637 | { |
85d721b8 PA |
11638 | /* Read watchpoint locations are switched to |
11639 | access watchpoints, if the former are not | |
11640 | supported, but the latter are. */ | |
11641 | if (is_hardware_watchpoint (old_loc->owner)) | |
11642 | { | |
11643 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
11644 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
11645 | } | |
11646 | ||
934709f0 PW |
11647 | /* loc2 is a duplicated location. We need to check |
11648 | if it should be inserted in case it will be | |
11649 | unduplicated. */ | |
11650 | if (loc2 != old_loc | |
11651 | && unduplicated_should_be_inserted (loc2)) | |
c7d46a38 | 11652 | { |
934709f0 | 11653 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
11654 | keep_in_target = 1; |
11655 | break; | |
11656 | } | |
876fa593 JK |
11657 | } |
11658 | } | |
11659 | } | |
74960c60 VP |
11660 | } |
11661 | ||
20874c92 VP |
11662 | if (!keep_in_target) |
11663 | { | |
876fa593 | 11664 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 | 11665 | { |
4a64f543 MS |
11666 | /* This is just about all we can do. We could keep |
11667 | this location on the global list, and try to | |
11668 | remove it next time, but there's no particular | |
11669 | reason why we will succeed next time. | |
20874c92 | 11670 | |
4a64f543 MS |
11671 | Note that at this point, old_loc->owner is still |
11672 | valid, as delete_breakpoint frees the breakpoint | |
11673 | only after calling us. */ | |
3e43a32a MS |
11674 | printf_filtered (_("warning: Error removing " |
11675 | "breakpoint %d\n"), | |
876fa593 | 11676 | old_loc->owner->number); |
20874c92 VP |
11677 | } |
11678 | removed = 1; | |
11679 | } | |
0d381245 | 11680 | } |
74960c60 VP |
11681 | |
11682 | if (!found_object) | |
1c5cfe86 | 11683 | { |
db82e815 PA |
11684 | if (removed && non_stop |
11685 | && breakpoint_address_is_meaningful (old_loc->owner) | |
11686 | && !is_hardware_watchpoint (old_loc->owner)) | |
20874c92 | 11687 | { |
db82e815 PA |
11688 | /* This location was removed from the target. In |
11689 | non-stop mode, a race condition is possible where | |
11690 | we've removed a breakpoint, but stop events for that | |
11691 | breakpoint are already queued and will arrive later. | |
11692 | We apply an heuristic to be able to distinguish such | |
11693 | SIGTRAPs from other random SIGTRAPs: we keep this | |
11694 | breakpoint location for a bit, and will retire it | |
11695 | after we see some number of events. The theory here | |
11696 | is that reporting of events should, "on the average", | |
11697 | be fair, so after a while we'll see events from all | |
11698 | threads that have anything of interest, and no longer | |
11699 | need to keep this breakpoint location around. We | |
11700 | don't hold locations forever so to reduce chances of | |
11701 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
11702 | SIGTRAP. | |
11703 | ||
11704 | The heuristic failing can be disastrous on | |
11705 | decr_pc_after_break targets. | |
11706 | ||
11707 | On decr_pc_after_break targets, like e.g., x86-linux, | |
11708 | if we fail to recognize a late breakpoint SIGTRAP, | |
11709 | because events_till_retirement has reached 0 too | |
11710 | soon, we'll fail to do the PC adjustment, and report | |
11711 | a random SIGTRAP to the user. When the user resumes | |
11712 | the inferior, it will most likely immediately crash | |
2dec564e | 11713 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
11714 | corrupted, because of being resumed e.g., in the |
11715 | middle of a multi-byte instruction, or skipped a | |
11716 | one-byte instruction. This was actually seen happen | |
11717 | on native x86-linux, and should be less rare on | |
11718 | targets that do not support new thread events, like | |
11719 | remote, due to the heuristic depending on | |
11720 | thread_count. | |
11721 | ||
11722 | Mistaking a random SIGTRAP for a breakpoint trap | |
11723 | causes similar symptoms (PC adjustment applied when | |
11724 | it shouldn't), but then again, playing with SIGTRAPs | |
11725 | behind the debugger's back is asking for trouble. | |
11726 | ||
11727 | Since hardware watchpoint traps are always | |
11728 | distinguishable from other traps, so we don't need to | |
11729 | apply keep hardware watchpoint moribund locations | |
11730 | around. We simply always ignore hardware watchpoint | |
11731 | traps we can no longer explain. */ | |
11732 | ||
876fa593 JK |
11733 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
11734 | old_loc->owner = NULL; | |
20874c92 | 11735 | |
876fa593 | 11736 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
11737 | } |
11738 | else | |
f431efe5 PA |
11739 | { |
11740 | old_loc->owner = NULL; | |
11741 | decref_bp_location (&old_loc); | |
11742 | } | |
20874c92 | 11743 | } |
74960c60 | 11744 | } |
1c5cfe86 | 11745 | |
348d480f PA |
11746 | /* Rescan breakpoints at the same address and section, marking the |
11747 | first one as "first" and any others as "duplicates". This is so | |
11748 | that the bpt instruction is only inserted once. If we have a | |
11749 | permanent breakpoint at the same place as BPT, make that one the | |
11750 | official one, and the rest as duplicates. Permanent breakpoints | |
11751 | are sorted first for the same address. | |
11752 | ||
11753 | Do the same for hardware watchpoints, but also considering the | |
11754 | watchpoint's type (regular/access/read) and length. */ | |
11755 | ||
11756 | bp_loc_first = NULL; | |
11757 | wp_loc_first = NULL; | |
11758 | awp_loc_first = NULL; | |
11759 | rwp_loc_first = NULL; | |
11760 | ALL_BP_LOCATIONS (loc, locp) | |
11761 | { | |
11762 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
11763 | non-NULL. */ | |
348d480f | 11764 | struct bp_location **loc_first_p; |
d3fbdd86 | 11765 | b = loc->owner; |
348d480f | 11766 | |
f8eba3c6 | 11767 | if (!should_be_inserted (loc) |
348d480f | 11768 | || !breakpoint_address_is_meaningful (b) |
1e4d1764 YQ |
11769 | /* Don't detect duplicate for tracepoint locations because they are |
11770 | never duplicated. See the comments in field `duplicate' of | |
11771 | `struct bp_location'. */ | |
348d480f | 11772 | || is_tracepoint (b)) |
b775012e LM |
11773 | { |
11774 | /* Clear the condition modification flag. */ | |
11775 | loc->condition_changed = condition_unchanged; | |
11776 | continue; | |
11777 | } | |
348d480f PA |
11778 | |
11779 | /* Permanent breakpoint should always be inserted. */ | |
11780 | if (b->enable_state == bp_permanent && ! loc->inserted) | |
11781 | internal_error (__FILE__, __LINE__, | |
11782 | _("allegedly permanent breakpoint is not " | |
11783 | "actually inserted")); | |
11784 | ||
11785 | if (b->type == bp_hardware_watchpoint) | |
11786 | loc_first_p = &wp_loc_first; | |
11787 | else if (b->type == bp_read_watchpoint) | |
11788 | loc_first_p = &rwp_loc_first; | |
11789 | else if (b->type == bp_access_watchpoint) | |
11790 | loc_first_p = &awp_loc_first; | |
11791 | else | |
11792 | loc_first_p = &bp_loc_first; | |
11793 | ||
11794 | if (*loc_first_p == NULL | |
11795 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
11796 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
11797 | { | |
11798 | *loc_first_p = loc; | |
11799 | loc->duplicate = 0; | |
b775012e LM |
11800 | |
11801 | if (is_breakpoint (loc->owner) && loc->condition_changed) | |
11802 | { | |
11803 | loc->needs_update = 1; | |
11804 | /* Clear the condition modification flag. */ | |
11805 | loc->condition_changed = condition_unchanged; | |
11806 | } | |
348d480f PA |
11807 | continue; |
11808 | } | |
11809 | ||
934709f0 PW |
11810 | |
11811 | /* This and the above ensure the invariant that the first location | |
11812 | is not duplicated, and is the inserted one. | |
11813 | All following are marked as duplicated, and are not inserted. */ | |
11814 | if (loc->inserted) | |
11815 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
11816 | loc->duplicate = 1; |
11817 | ||
b775012e LM |
11818 | /* Clear the condition modification flag. */ |
11819 | loc->condition_changed = condition_unchanged; | |
11820 | ||
348d480f PA |
11821 | if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted |
11822 | && b->enable_state != bp_permanent) | |
11823 | internal_error (__FILE__, __LINE__, | |
11824 | _("another breakpoint was inserted on top of " | |
11825 | "a permanent breakpoint")); | |
11826 | } | |
11827 | ||
b775012e | 11828 | if (breakpoints_always_inserted_mode () |
348d480f PA |
11829 | && (have_live_inferiors () |
11830 | || (gdbarch_has_global_breakpoints (target_gdbarch)))) | |
b775012e LM |
11831 | { |
11832 | if (should_insert) | |
11833 | insert_breakpoint_locations (); | |
11834 | else | |
11835 | { | |
11836 | /* Though should_insert is false, we may need to update conditions | |
11837 | on the target's side if it is evaluating such conditions. We | |
11838 | only update conditions for locations that are marked | |
11839 | "needs_update". */ | |
11840 | update_inserted_breakpoint_locations (); | |
11841 | } | |
11842 | } | |
348d480f | 11843 | |
1e4d1764 YQ |
11844 | if (should_insert) |
11845 | download_tracepoint_locations (); | |
11846 | ||
348d480f PA |
11847 | do_cleanups (cleanups); |
11848 | } | |
11849 | ||
11850 | void | |
11851 | breakpoint_retire_moribund (void) | |
11852 | { | |
11853 | struct bp_location *loc; | |
11854 | int ix; | |
11855 | ||
11856 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
11857 | if (--(loc->events_till_retirement) == 0) | |
11858 | { | |
11859 | decref_bp_location (&loc); | |
11860 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
11861 | --ix; | |
11862 | } | |
11863 | } | |
11864 | ||
11865 | static void | |
11866 | update_global_location_list_nothrow (int inserting) | |
11867 | { | |
bfd189b1 | 11868 | volatile struct gdb_exception e; |
348d480f PA |
11869 | |
11870 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
11871 | update_global_location_list (inserting); | |
11872 | } | |
11873 | ||
11874 | /* Clear BKP from a BPS. */ | |
11875 | ||
11876 | static void | |
11877 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) | |
11878 | { | |
11879 | bpstat bs; | |
11880 | ||
11881 | for (bs = bps; bs; bs = bs->next) | |
11882 | if (bs->breakpoint_at == bpt) | |
11883 | { | |
11884 | bs->breakpoint_at = NULL; | |
11885 | bs->old_val = NULL; | |
11886 | /* bs->commands will be freed later. */ | |
11887 | } | |
11888 | } | |
11889 | ||
11890 | /* Callback for iterate_over_threads. */ | |
11891 | static int | |
11892 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
11893 | { | |
11894 | struct breakpoint *bpt = data; | |
11895 | ||
11896 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
11897 | return 0; | |
11898 | } | |
11899 | ||
11900 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
11901 | callbacks. */ | |
11902 | ||
11903 | static void | |
11904 | say_where (struct breakpoint *b) | |
11905 | { | |
79a45e25 | 11906 | struct ui_out *uiout = current_uiout; |
348d480f PA |
11907 | struct value_print_options opts; |
11908 | ||
11909 | get_user_print_options (&opts); | |
11910 | ||
11911 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
11912 | single string. */ | |
11913 | if (b->loc == NULL) | |
11914 | { | |
11915 | printf_filtered (_(" (%s) pending."), b->addr_string); | |
11916 | } | |
11917 | else | |
11918 | { | |
f8eba3c6 | 11919 | if (opts.addressprint || b->loc->source_file == NULL) |
348d480f PA |
11920 | { |
11921 | printf_filtered (" at "); | |
11922 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), | |
11923 | gdb_stdout); | |
11924 | } | |
f8eba3c6 TT |
11925 | if (b->loc->source_file) |
11926 | { | |
11927 | /* If there is a single location, we can print the location | |
11928 | more nicely. */ | |
11929 | if (b->loc->next == NULL) | |
11930 | printf_filtered (": file %s, line %d.", | |
11931 | b->loc->source_file, b->loc->line_number); | |
11932 | else | |
11933 | /* This is not ideal, but each location may have a | |
11934 | different file name, and this at least reflects the | |
11935 | real situation somewhat. */ | |
11936 | printf_filtered (": %s.", b->addr_string); | |
11937 | } | |
348d480f PA |
11938 | |
11939 | if (b->loc->next) | |
11940 | { | |
11941 | struct bp_location *loc = b->loc; | |
11942 | int n = 0; | |
11943 | for (; loc; loc = loc->next) | |
11944 | ++n; | |
11945 | printf_filtered (" (%d locations)", n); | |
11946 | } | |
11947 | } | |
11948 | } | |
11949 | ||
348d480f PA |
11950 | /* Default bp_location_ops methods. */ |
11951 | ||
11952 | static void | |
11953 | bp_location_dtor (struct bp_location *self) | |
11954 | { | |
11955 | xfree (self->cond); | |
b775012e LM |
11956 | if (self->cond_bytecode) |
11957 | free_agent_expr (self->cond_bytecode); | |
348d480f | 11958 | xfree (self->function_name); |
f8eba3c6 | 11959 | xfree (self->source_file); |
348d480f PA |
11960 | } |
11961 | ||
11962 | static const struct bp_location_ops bp_location_ops = | |
11963 | { | |
11964 | bp_location_dtor | |
11965 | }; | |
11966 | ||
2060206e PA |
11967 | /* Default breakpoint_ops methods all breakpoint_ops ultimately |
11968 | inherit from. */ | |
348d480f | 11969 | |
2060206e PA |
11970 | static void |
11971 | base_breakpoint_dtor (struct breakpoint *self) | |
348d480f PA |
11972 | { |
11973 | decref_counted_command_line (&self->commands); | |
11974 | xfree (self->cond_string); | |
348d480f | 11975 | xfree (self->addr_string); |
f8eba3c6 | 11976 | xfree (self->filter); |
348d480f | 11977 | xfree (self->addr_string_range_end); |
348d480f PA |
11978 | } |
11979 | ||
2060206e PA |
11980 | static struct bp_location * |
11981 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f PA |
11982 | { |
11983 | struct bp_location *loc; | |
11984 | ||
11985 | loc = XNEW (struct bp_location); | |
11986 | init_bp_location (loc, &bp_location_ops, self); | |
11987 | return loc; | |
11988 | } | |
11989 | ||
2060206e PA |
11990 | static void |
11991 | base_breakpoint_re_set (struct breakpoint *b) | |
11992 | { | |
11993 | /* Nothing to re-set. */ | |
11994 | } | |
11995 | ||
11996 | #define internal_error_pure_virtual_called() \ | |
11997 | gdb_assert_not_reached ("pure virtual function called") | |
11998 | ||
11999 | static int | |
12000 | base_breakpoint_insert_location (struct bp_location *bl) | |
12001 | { | |
12002 | internal_error_pure_virtual_called (); | |
12003 | } | |
12004 | ||
12005 | static int | |
12006 | base_breakpoint_remove_location (struct bp_location *bl) | |
12007 | { | |
12008 | internal_error_pure_virtual_called (); | |
12009 | } | |
12010 | ||
12011 | static int | |
12012 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
12013 | struct address_space *aspace, | |
09ac7c10 TT |
12014 | CORE_ADDR bp_addr, |
12015 | const struct target_waitstatus *ws) | |
2060206e PA |
12016 | { |
12017 | internal_error_pure_virtual_called (); | |
12018 | } | |
12019 | ||
12020 | static void | |
12021 | base_breakpoint_check_status (bpstat bs) | |
12022 | { | |
12023 | /* Always stop. */ | |
12024 | } | |
12025 | ||
12026 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
12027 | errors. */ | |
12028 | ||
12029 | static int | |
12030 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
12031 | { | |
12032 | internal_error_pure_virtual_called (); | |
12033 | } | |
12034 | ||
12035 | /* A "resources_needed" breakpoint_ops method that just internal | |
12036 | errors. */ | |
12037 | ||
12038 | static int | |
12039 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
12040 | { | |
12041 | internal_error_pure_virtual_called (); | |
12042 | } | |
12043 | ||
12044 | static enum print_stop_action | |
12045 | base_breakpoint_print_it (bpstat bs) | |
12046 | { | |
12047 | internal_error_pure_virtual_called (); | |
12048 | } | |
12049 | ||
12050 | static void | |
12051 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
12052 | struct ui_out *uiout) | |
12053 | { | |
12054 | /* nothing */ | |
12055 | } | |
12056 | ||
12057 | static void | |
12058 | base_breakpoint_print_mention (struct breakpoint *b) | |
12059 | { | |
12060 | internal_error_pure_virtual_called (); | |
12061 | } | |
12062 | ||
12063 | static void | |
12064 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
12065 | { | |
12066 | internal_error_pure_virtual_called (); | |
12067 | } | |
12068 | ||
983af33b SDJ |
12069 | static void |
12070 | base_breakpoint_create_sals_from_address (char **arg, | |
12071 | struct linespec_result *canonical, | |
12072 | enum bptype type_wanted, | |
12073 | char *addr_start, | |
12074 | char **copy_arg) | |
12075 | { | |
12076 | internal_error_pure_virtual_called (); | |
12077 | } | |
12078 | ||
12079 | static void | |
12080 | base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12081 | struct linespec_result *c, | |
12082 | struct linespec_sals *lsal, | |
12083 | char *cond_string, | |
12084 | enum bptype type_wanted, | |
12085 | enum bpdisp disposition, | |
12086 | int thread, | |
12087 | int task, int ignore_count, | |
12088 | const struct breakpoint_ops *o, | |
12089 | int from_tty, int enabled, | |
44f238bb | 12090 | int internal, unsigned flags) |
983af33b SDJ |
12091 | { |
12092 | internal_error_pure_virtual_called (); | |
12093 | } | |
12094 | ||
12095 | static void | |
12096 | base_breakpoint_decode_linespec (struct breakpoint *b, char **s, | |
12097 | struct symtabs_and_lines *sals) | |
12098 | { | |
12099 | internal_error_pure_virtual_called (); | |
12100 | } | |
12101 | ||
2060206e PA |
12102 | static struct breakpoint_ops base_breakpoint_ops = |
12103 | { | |
12104 | base_breakpoint_dtor, | |
12105 | base_breakpoint_allocate_location, | |
12106 | base_breakpoint_re_set, | |
12107 | base_breakpoint_insert_location, | |
12108 | base_breakpoint_remove_location, | |
12109 | base_breakpoint_breakpoint_hit, | |
12110 | base_breakpoint_check_status, | |
12111 | base_breakpoint_resources_needed, | |
12112 | base_breakpoint_works_in_software_mode, | |
12113 | base_breakpoint_print_it, | |
12114 | NULL, | |
12115 | base_breakpoint_print_one_detail, | |
12116 | base_breakpoint_print_mention, | |
983af33b SDJ |
12117 | base_breakpoint_print_recreate, |
12118 | base_breakpoint_create_sals_from_address, | |
12119 | base_breakpoint_create_breakpoints_sal, | |
12120 | base_breakpoint_decode_linespec, | |
2060206e PA |
12121 | }; |
12122 | ||
12123 | /* Default breakpoint_ops methods. */ | |
12124 | ||
12125 | static void | |
348d480f PA |
12126 | bkpt_re_set (struct breakpoint *b) |
12127 | { | |
06edf0c0 PA |
12128 | /* FIXME: is this still reachable? */ |
12129 | if (b->addr_string == NULL) | |
12130 | { | |
12131 | /* Anything without a string can't be re-set. */ | |
348d480f | 12132 | delete_breakpoint (b); |
06edf0c0 | 12133 | return; |
348d480f | 12134 | } |
06edf0c0 PA |
12135 | |
12136 | breakpoint_re_set_default (b); | |
348d480f PA |
12137 | } |
12138 | ||
2060206e | 12139 | static int |
348d480f PA |
12140 | bkpt_insert_location (struct bp_location *bl) |
12141 | { | |
12142 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
12143 | return target_insert_hw_breakpoint (bl->gdbarch, | |
12144 | &bl->target_info); | |
12145 | else | |
12146 | return target_insert_breakpoint (bl->gdbarch, | |
12147 | &bl->target_info); | |
12148 | } | |
12149 | ||
2060206e | 12150 | static int |
348d480f PA |
12151 | bkpt_remove_location (struct bp_location *bl) |
12152 | { | |
12153 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
12154 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
12155 | else | |
12156 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info); | |
12157 | } | |
12158 | ||
2060206e | 12159 | static int |
348d480f | 12160 | bkpt_breakpoint_hit (const struct bp_location *bl, |
09ac7c10 TT |
12161 | struct address_space *aspace, CORE_ADDR bp_addr, |
12162 | const struct target_waitstatus *ws) | |
348d480f PA |
12163 | { |
12164 | struct breakpoint *b = bl->owner; | |
12165 | ||
09ac7c10 TT |
12166 | if (ws->kind != TARGET_WAITKIND_STOPPED |
12167 | || ws->value.sig != TARGET_SIGNAL_TRAP) | |
12168 | return 0; | |
12169 | ||
348d480f PA |
12170 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
12171 | aspace, bp_addr)) | |
12172 | return 0; | |
12173 | ||
12174 | if (overlay_debugging /* unmapped overlay section */ | |
12175 | && section_is_overlay (bl->section) | |
12176 | && !section_is_mapped (bl->section)) | |
12177 | return 0; | |
12178 | ||
12179 | return 1; | |
12180 | } | |
12181 | ||
2060206e | 12182 | static int |
348d480f PA |
12183 | bkpt_resources_needed (const struct bp_location *bl) |
12184 | { | |
12185 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
12186 | ||
12187 | return 1; | |
12188 | } | |
12189 | ||
2060206e | 12190 | static enum print_stop_action |
348d480f PA |
12191 | bkpt_print_it (bpstat bs) |
12192 | { | |
348d480f PA |
12193 | struct breakpoint *b; |
12194 | const struct bp_location *bl; | |
001c8c33 | 12195 | int bp_temp; |
79a45e25 | 12196 | struct ui_out *uiout = current_uiout; |
348d480f PA |
12197 | |
12198 | gdb_assert (bs->bp_location_at != NULL); | |
12199 | ||
12200 | bl = bs->bp_location_at; | |
12201 | b = bs->breakpoint_at; | |
12202 | ||
001c8c33 PA |
12203 | bp_temp = b->disposition == disp_del; |
12204 | if (bl->address != bl->requested_address) | |
12205 | breakpoint_adjustment_warning (bl->requested_address, | |
12206 | bl->address, | |
12207 | b->number, 1); | |
12208 | annotate_breakpoint (b->number); | |
12209 | if (bp_temp) | |
12210 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
12211 | else | |
12212 | ui_out_text (uiout, "\nBreakpoint "); | |
12213 | if (ui_out_is_mi_like_p (uiout)) | |
348d480f | 12214 | { |
001c8c33 PA |
12215 | ui_out_field_string (uiout, "reason", |
12216 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
12217 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
06edf0c0 | 12218 | } |
001c8c33 PA |
12219 | ui_out_field_int (uiout, "bkptno", b->number); |
12220 | ui_out_text (uiout, ", "); | |
06edf0c0 | 12221 | |
001c8c33 | 12222 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
12223 | } |
12224 | ||
2060206e | 12225 | static void |
06edf0c0 PA |
12226 | bkpt_print_mention (struct breakpoint *b) |
12227 | { | |
79a45e25 | 12228 | if (ui_out_is_mi_like_p (current_uiout)) |
06edf0c0 PA |
12229 | return; |
12230 | ||
12231 | switch (b->type) | |
12232 | { | |
12233 | case bp_breakpoint: | |
12234 | case bp_gnu_ifunc_resolver: | |
12235 | if (b->disposition == disp_del) | |
12236 | printf_filtered (_("Temporary breakpoint")); | |
12237 | else | |
12238 | printf_filtered (_("Breakpoint")); | |
12239 | printf_filtered (_(" %d"), b->number); | |
12240 | if (b->type == bp_gnu_ifunc_resolver) | |
12241 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
12242 | break; | |
12243 | case bp_hardware_breakpoint: | |
12244 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
12245 | break; | |
12246 | } | |
12247 | ||
12248 | say_where (b); | |
12249 | } | |
12250 | ||
2060206e | 12251 | static void |
06edf0c0 PA |
12252 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
12253 | { | |
12254 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
12255 | fprintf_unfiltered (fp, "tbreak"); | |
12256 | else if (tp->type == bp_breakpoint) | |
12257 | fprintf_unfiltered (fp, "break"); | |
12258 | else if (tp->type == bp_hardware_breakpoint | |
12259 | && tp->disposition == disp_del) | |
12260 | fprintf_unfiltered (fp, "thbreak"); | |
12261 | else if (tp->type == bp_hardware_breakpoint) | |
12262 | fprintf_unfiltered (fp, "hbreak"); | |
12263 | else | |
12264 | internal_error (__FILE__, __LINE__, | |
12265 | _("unhandled breakpoint type %d"), (int) tp->type); | |
12266 | ||
2060206e | 12267 | fprintf_unfiltered (fp, " %s", tp->addr_string); |
dd11a36c | 12268 | print_recreate_thread (tp, fp); |
06edf0c0 PA |
12269 | } |
12270 | ||
983af33b SDJ |
12271 | static void |
12272 | bkpt_create_sals_from_address (char **arg, | |
12273 | struct linespec_result *canonical, | |
12274 | enum bptype type_wanted, | |
12275 | char *addr_start, char **copy_arg) | |
12276 | { | |
12277 | create_sals_from_address_default (arg, canonical, type_wanted, | |
12278 | addr_start, copy_arg); | |
12279 | } | |
12280 | ||
12281 | static void | |
12282 | bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12283 | struct linespec_result *canonical, | |
12284 | struct linespec_sals *lsal, | |
12285 | char *cond_string, | |
12286 | enum bptype type_wanted, | |
12287 | enum bpdisp disposition, | |
12288 | int thread, | |
12289 | int task, int ignore_count, | |
12290 | const struct breakpoint_ops *ops, | |
12291 | int from_tty, int enabled, | |
44f238bb | 12292 | int internal, unsigned flags) |
983af33b SDJ |
12293 | { |
12294 | create_breakpoints_sal_default (gdbarch, canonical, lsal, | |
12295 | cond_string, type_wanted, | |
12296 | disposition, thread, task, | |
12297 | ignore_count, ops, from_tty, | |
44f238bb | 12298 | enabled, internal, flags); |
983af33b SDJ |
12299 | } |
12300 | ||
12301 | static void | |
12302 | bkpt_decode_linespec (struct breakpoint *b, char **s, | |
12303 | struct symtabs_and_lines *sals) | |
12304 | { | |
12305 | decode_linespec_default (b, s, sals); | |
12306 | } | |
12307 | ||
06edf0c0 PA |
12308 | /* Virtual table for internal breakpoints. */ |
12309 | ||
12310 | static void | |
12311 | internal_bkpt_re_set (struct breakpoint *b) | |
12312 | { | |
12313 | switch (b->type) | |
12314 | { | |
12315 | /* Delete overlay event and longjmp master breakpoints; they | |
12316 | will be reset later by breakpoint_re_set. */ | |
12317 | case bp_overlay_event: | |
12318 | case bp_longjmp_master: | |
12319 | case bp_std_terminate_master: | |
12320 | case bp_exception_master: | |
12321 | delete_breakpoint (b); | |
12322 | break; | |
12323 | ||
12324 | /* This breakpoint is special, it's set up when the inferior | |
12325 | starts and we really don't want to touch it. */ | |
12326 | case bp_shlib_event: | |
12327 | ||
12328 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
12329 | it is set up, we do not want to touch it. */ | |
12330 | case bp_thread_event: | |
12331 | break; | |
12332 | } | |
12333 | } | |
12334 | ||
12335 | static void | |
12336 | internal_bkpt_check_status (bpstat bs) | |
12337 | { | |
a9b3a50f PA |
12338 | if (bs->breakpoint_at->type == bp_shlib_event) |
12339 | { | |
12340 | /* If requested, stop when the dynamic linker notifies GDB of | |
12341 | events. This allows the user to get control and place | |
12342 | breakpoints in initializer routines for dynamically loaded | |
12343 | objects (among other things). */ | |
12344 | bs->stop = stop_on_solib_events; | |
12345 | bs->print = stop_on_solib_events; | |
12346 | } | |
12347 | else | |
12348 | bs->stop = 0; | |
06edf0c0 PA |
12349 | } |
12350 | ||
12351 | static enum print_stop_action | |
12352 | internal_bkpt_print_it (bpstat bs) | |
12353 | { | |
36dfb11c | 12354 | struct ui_out *uiout = current_uiout; |
06edf0c0 | 12355 | struct breakpoint *b; |
06edf0c0 | 12356 | |
06edf0c0 PA |
12357 | b = bs->breakpoint_at; |
12358 | ||
06edf0c0 PA |
12359 | switch (b->type) |
12360 | { | |
348d480f PA |
12361 | case bp_shlib_event: |
12362 | /* Did we stop because the user set the stop_on_solib_events | |
12363 | variable? (If so, we report this as a generic, "Stopped due | |
12364 | to shlib event" message.) */ | |
edcc5120 | 12365 | print_solib_event (0); |
348d480f PA |
12366 | break; |
12367 | ||
12368 | case bp_thread_event: | |
12369 | /* Not sure how we will get here. | |
12370 | GDB should not stop for these breakpoints. */ | |
12371 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
12372 | break; |
12373 | ||
12374 | case bp_overlay_event: | |
12375 | /* By analogy with the thread event, GDB should not stop for these. */ | |
12376 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
12377 | break; |
12378 | ||
12379 | case bp_longjmp_master: | |
12380 | /* These should never be enabled. */ | |
12381 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
12382 | break; |
12383 | ||
12384 | case bp_std_terminate_master: | |
12385 | /* These should never be enabled. */ | |
12386 | printf_filtered (_("std::terminate Master Breakpoint: " | |
12387 | "gdb should not stop!\n")); | |
348d480f PA |
12388 | break; |
12389 | ||
12390 | case bp_exception_master: | |
12391 | /* These should never be enabled. */ | |
12392 | printf_filtered (_("Exception Master Breakpoint: " | |
12393 | "gdb should not stop!\n")); | |
06edf0c0 PA |
12394 | break; |
12395 | } | |
12396 | ||
001c8c33 | 12397 | return PRINT_NOTHING; |
06edf0c0 PA |
12398 | } |
12399 | ||
12400 | static void | |
12401 | internal_bkpt_print_mention (struct breakpoint *b) | |
12402 | { | |
12403 | /* Nothing to mention. These breakpoints are internal. */ | |
12404 | } | |
12405 | ||
06edf0c0 PA |
12406 | /* Virtual table for momentary breakpoints */ |
12407 | ||
12408 | static void | |
12409 | momentary_bkpt_re_set (struct breakpoint *b) | |
12410 | { | |
12411 | /* Keep temporary breakpoints, which can be encountered when we step | |
12412 | over a dlopen call and SOLIB_ADD is resetting the breakpoints. | |
12413 | Otherwise these should have been blown away via the cleanup chain | |
12414 | or by breakpoint_init_inferior when we rerun the executable. */ | |
12415 | } | |
12416 | ||
12417 | static void | |
12418 | momentary_bkpt_check_status (bpstat bs) | |
12419 | { | |
12420 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
12421 | } | |
12422 | ||
12423 | static enum print_stop_action | |
12424 | momentary_bkpt_print_it (bpstat bs) | |
12425 | { | |
79a45e25 PA |
12426 | struct ui_out *uiout = current_uiout; |
12427 | ||
001c8c33 | 12428 | if (ui_out_is_mi_like_p (uiout)) |
06edf0c0 | 12429 | { |
001c8c33 | 12430 | struct breakpoint *b = bs->breakpoint_at; |
348d480f | 12431 | |
001c8c33 PA |
12432 | switch (b->type) |
12433 | { | |
12434 | case bp_finish: | |
12435 | ui_out_field_string | |
12436 | (uiout, "reason", | |
12437 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
12438 | break; | |
348d480f | 12439 | |
001c8c33 PA |
12440 | case bp_until: |
12441 | ui_out_field_string | |
12442 | (uiout, "reason", | |
12443 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
12444 | break; | |
12445 | } | |
348d480f PA |
12446 | } |
12447 | ||
001c8c33 | 12448 | return PRINT_UNKNOWN; |
348d480f PA |
12449 | } |
12450 | ||
06edf0c0 PA |
12451 | static void |
12452 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 12453 | { |
06edf0c0 | 12454 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
12455 | } |
12456 | ||
348d480f | 12457 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 12458 | |
348d480f PA |
12459 | static void |
12460 | tracepoint_re_set (struct breakpoint *b) | |
12461 | { | |
12462 | breakpoint_re_set_default (b); | |
12463 | } | |
876fa593 | 12464 | |
348d480f PA |
12465 | static int |
12466 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
09ac7c10 TT |
12467 | struct address_space *aspace, CORE_ADDR bp_addr, |
12468 | const struct target_waitstatus *ws) | |
348d480f PA |
12469 | { |
12470 | /* By definition, the inferior does not report stops at | |
12471 | tracepoints. */ | |
12472 | return 0; | |
74960c60 VP |
12473 | } |
12474 | ||
12475 | static void | |
348d480f PA |
12476 | tracepoint_print_one_detail (const struct breakpoint *self, |
12477 | struct ui_out *uiout) | |
74960c60 | 12478 | { |
d9b3f62e PA |
12479 | struct tracepoint *tp = (struct tracepoint *) self; |
12480 | if (tp->static_trace_marker_id) | |
348d480f PA |
12481 | { |
12482 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 12483 | |
348d480f PA |
12484 | ui_out_text (uiout, "\tmarker id is "); |
12485 | ui_out_field_string (uiout, "static-tracepoint-marker-string-id", | |
d9b3f62e | 12486 | tp->static_trace_marker_id); |
348d480f PA |
12487 | ui_out_text (uiout, "\n"); |
12488 | } | |
0d381245 VP |
12489 | } |
12490 | ||
a474d7c2 | 12491 | static void |
348d480f | 12492 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 12493 | { |
79a45e25 | 12494 | if (ui_out_is_mi_like_p (current_uiout)) |
348d480f | 12495 | return; |
cc59ec59 | 12496 | |
348d480f PA |
12497 | switch (b->type) |
12498 | { | |
12499 | case bp_tracepoint: | |
12500 | printf_filtered (_("Tracepoint")); | |
12501 | printf_filtered (_(" %d"), b->number); | |
12502 | break; | |
12503 | case bp_fast_tracepoint: | |
12504 | printf_filtered (_("Fast tracepoint")); | |
12505 | printf_filtered (_(" %d"), b->number); | |
12506 | break; | |
12507 | case bp_static_tracepoint: | |
12508 | printf_filtered (_("Static tracepoint")); | |
12509 | printf_filtered (_(" %d"), b->number); | |
12510 | break; | |
12511 | default: | |
12512 | internal_error (__FILE__, __LINE__, | |
12513 | _("unhandled tracepoint type %d"), (int) b->type); | |
12514 | } | |
12515 | ||
12516 | say_where (b); | |
a474d7c2 PA |
12517 | } |
12518 | ||
348d480f | 12519 | static void |
d9b3f62e | 12520 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 12521 | { |
d9b3f62e PA |
12522 | struct tracepoint *tp = (struct tracepoint *) self; |
12523 | ||
12524 | if (self->type == bp_fast_tracepoint) | |
348d480f | 12525 | fprintf_unfiltered (fp, "ftrace"); |
d9b3f62e | 12526 | if (self->type == bp_static_tracepoint) |
348d480f | 12527 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 12528 | else if (self->type == bp_tracepoint) |
348d480f PA |
12529 | fprintf_unfiltered (fp, "trace"); |
12530 | else | |
12531 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 12532 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 12533 | |
d9b3f62e PA |
12534 | fprintf_unfiltered (fp, " %s", self->addr_string); |
12535 | print_recreate_thread (self, fp); | |
12536 | ||
12537 | if (tp->pass_count) | |
12538 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
12539 | } |
12540 | ||
983af33b SDJ |
12541 | static void |
12542 | tracepoint_create_sals_from_address (char **arg, | |
12543 | struct linespec_result *canonical, | |
12544 | enum bptype type_wanted, | |
12545 | char *addr_start, char **copy_arg) | |
12546 | { | |
12547 | create_sals_from_address_default (arg, canonical, type_wanted, | |
12548 | addr_start, copy_arg); | |
12549 | } | |
12550 | ||
12551 | static void | |
12552 | tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12553 | struct linespec_result *canonical, | |
12554 | struct linespec_sals *lsal, | |
12555 | char *cond_string, | |
12556 | enum bptype type_wanted, | |
12557 | enum bpdisp disposition, | |
12558 | int thread, | |
12559 | int task, int ignore_count, | |
12560 | const struct breakpoint_ops *ops, | |
12561 | int from_tty, int enabled, | |
44f238bb | 12562 | int internal, unsigned flags) |
983af33b SDJ |
12563 | { |
12564 | create_breakpoints_sal_default (gdbarch, canonical, lsal, | |
12565 | cond_string, type_wanted, | |
12566 | disposition, thread, task, | |
12567 | ignore_count, ops, from_tty, | |
44f238bb | 12568 | enabled, internal, flags); |
983af33b SDJ |
12569 | } |
12570 | ||
12571 | static void | |
12572 | tracepoint_decode_linespec (struct breakpoint *b, char **s, | |
12573 | struct symtabs_and_lines *sals) | |
12574 | { | |
12575 | decode_linespec_default (b, s, sals); | |
12576 | } | |
12577 | ||
2060206e | 12578 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 12579 | |
983af33b SDJ |
12580 | /* The breakpoint_ops structure to be used on static tracepoints with |
12581 | markers (`-m'). */ | |
12582 | ||
12583 | static void | |
12584 | strace_marker_create_sals_from_address (char **arg, | |
12585 | struct linespec_result *canonical, | |
12586 | enum bptype type_wanted, | |
12587 | char *addr_start, char **copy_arg) | |
12588 | { | |
12589 | struct linespec_sals lsal; | |
12590 | ||
12591 | lsal.sals = decode_static_tracepoint_spec (arg); | |
12592 | ||
12593 | *copy_arg = savestring (addr_start, *arg - addr_start); | |
12594 | ||
12595 | canonical->addr_string = xstrdup (*copy_arg); | |
12596 | lsal.canonical = xstrdup (*copy_arg); | |
12597 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
12598 | } | |
12599 | ||
12600 | static void | |
12601 | strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12602 | struct linespec_result *canonical, | |
12603 | struct linespec_sals *lsal, | |
12604 | char *cond_string, | |
12605 | enum bptype type_wanted, | |
12606 | enum bpdisp disposition, | |
12607 | int thread, | |
12608 | int task, int ignore_count, | |
12609 | const struct breakpoint_ops *ops, | |
12610 | int from_tty, int enabled, | |
44f238bb | 12611 | int internal, unsigned flags) |
983af33b SDJ |
12612 | { |
12613 | int i; | |
12614 | ||
12615 | /* If the user is creating a static tracepoint by marker id | |
12616 | (strace -m MARKER_ID), then store the sals index, so that | |
12617 | breakpoint_re_set can try to match up which of the newly | |
12618 | found markers corresponds to this one, and, don't try to | |
12619 | expand multiple locations for each sal, given than SALS | |
12620 | already should contain all sals for MARKER_ID. */ | |
12621 | ||
12622 | for (i = 0; i < lsal->sals.nelts; ++i) | |
12623 | { | |
12624 | struct symtabs_and_lines expanded; | |
12625 | struct tracepoint *tp; | |
12626 | struct cleanup *old_chain; | |
12627 | char *addr_string; | |
12628 | ||
12629 | expanded.nelts = 1; | |
12630 | expanded.sals = &lsal->sals.sals[i]; | |
12631 | ||
12632 | addr_string = xstrdup (canonical->addr_string); | |
12633 | old_chain = make_cleanup (xfree, addr_string); | |
12634 | ||
12635 | tp = XCNEW (struct tracepoint); | |
12636 | init_breakpoint_sal (&tp->base, gdbarch, expanded, | |
12637 | addr_string, NULL, | |
12638 | cond_string, type_wanted, disposition, | |
12639 | thread, task, ignore_count, ops, | |
44f238bb | 12640 | from_tty, enabled, internal, flags, |
983af33b SDJ |
12641 | canonical->special_display); |
12642 | /* Given that its possible to have multiple markers with | |
12643 | the same string id, if the user is creating a static | |
12644 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
12645 | store the sals index, so that breakpoint_re_set can | |
12646 | try to match up which of the newly found markers | |
12647 | corresponds to this one */ | |
12648 | tp->static_trace_marker_id_idx = i; | |
12649 | ||
12650 | install_breakpoint (internal, &tp->base, 0); | |
12651 | ||
12652 | discard_cleanups (old_chain); | |
12653 | } | |
12654 | } | |
12655 | ||
12656 | static void | |
12657 | strace_marker_decode_linespec (struct breakpoint *b, char **s, | |
12658 | struct symtabs_and_lines *sals) | |
12659 | { | |
12660 | struct tracepoint *tp = (struct tracepoint *) b; | |
12661 | ||
12662 | *sals = decode_static_tracepoint_spec (s); | |
12663 | if (sals->nelts > tp->static_trace_marker_id_idx) | |
12664 | { | |
12665 | sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx]; | |
12666 | sals->nelts = 1; | |
12667 | } | |
12668 | else | |
12669 | error (_("marker %s not found"), tp->static_trace_marker_id); | |
12670 | } | |
12671 | ||
12672 | static struct breakpoint_ops strace_marker_breakpoint_ops; | |
12673 | ||
12674 | static int | |
12675 | strace_marker_p (struct breakpoint *b) | |
12676 | { | |
12677 | return b->ops == &strace_marker_breakpoint_ops; | |
12678 | } | |
12679 | ||
53a5351d | 12680 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 12681 | structures. */ |
c906108c SS |
12682 | |
12683 | void | |
fba45db2 | 12684 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 12685 | { |
52f0bd74 | 12686 | struct breakpoint *b; |
c906108c | 12687 | |
8a3fe4f8 | 12688 | gdb_assert (bpt != NULL); |
c906108c | 12689 | |
4a64f543 MS |
12690 | /* Has this bp already been deleted? This can happen because |
12691 | multiple lists can hold pointers to bp's. bpstat lists are | |
12692 | especial culprits. | |
12693 | ||
12694 | One example of this happening is a watchpoint's scope bp. When | |
12695 | the scope bp triggers, we notice that the watchpoint is out of | |
12696 | scope, and delete it. We also delete its scope bp. But the | |
12697 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
12698 | That bpstat is then checked for auto-deleting bp's, which are | |
12699 | deleted. | |
12700 | ||
12701 | A real solution to this problem might involve reference counts in | |
12702 | bp's, and/or giving them pointers back to their referencing | |
12703 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
12704 | storage when no more references were extent. A cheaper bandaid | |
12705 | was chosen. */ | |
c906108c SS |
12706 | if (bpt->type == bp_none) |
12707 | return; | |
12708 | ||
4a64f543 MS |
12709 | /* At least avoid this stale reference until the reference counting |
12710 | of breakpoints gets resolved. */ | |
d0fb5eae | 12711 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 12712 | { |
d0fb5eae | 12713 | struct breakpoint *related; |
3a5c3e22 | 12714 | struct watchpoint *w; |
d0fb5eae JK |
12715 | |
12716 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 12717 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 12718 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
12719 | w = (struct watchpoint *) bpt; |
12720 | else | |
12721 | w = NULL; | |
12722 | if (w != NULL) | |
12723 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
12724 | |
12725 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
12726 | for (related = bpt; related->related_breakpoint != bpt; | |
12727 | related = related->related_breakpoint); | |
12728 | related->related_breakpoint = bpt->related_breakpoint; | |
12729 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
12730 | } |
12731 | ||
a9634178 TJB |
12732 | /* watch_command_1 creates a watchpoint but only sets its number if |
12733 | update_watchpoint succeeds in creating its bp_locations. If there's | |
12734 | a problem in that process, we'll be asked to delete the half-created | |
12735 | watchpoint. In that case, don't announce the deletion. */ | |
12736 | if (bpt->number) | |
12737 | observer_notify_breakpoint_deleted (bpt); | |
c906108c | 12738 | |
c906108c SS |
12739 | if (breakpoint_chain == bpt) |
12740 | breakpoint_chain = bpt->next; | |
12741 | ||
c906108c SS |
12742 | ALL_BREAKPOINTS (b) |
12743 | if (b->next == bpt) | |
c5aa993b JM |
12744 | { |
12745 | b->next = bpt->next; | |
12746 | break; | |
12747 | } | |
c906108c | 12748 | |
f431efe5 PA |
12749 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
12750 | been freed. */ | |
12751 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 12752 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
12753 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
12754 | commands are associated with the bpstat; if we remove it here, | |
12755 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
12756 | event-top.c won't do anything, and temporary breakpoints with | |
12757 | commands won't work. */ | |
12758 | ||
12759 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
12760 | ||
4a64f543 MS |
12761 | /* Now that breakpoint is removed from breakpoint list, update the |
12762 | global location list. This will remove locations that used to | |
12763 | belong to this breakpoint. Do this before freeing the breakpoint | |
12764 | itself, since remove_breakpoint looks at location's owner. It | |
12765 | might be better design to have location completely | |
12766 | self-contained, but it's not the case now. */ | |
b60e7edf | 12767 | update_global_location_list (0); |
74960c60 | 12768 | |
348d480f | 12769 | bpt->ops->dtor (bpt); |
4a64f543 MS |
12770 | /* On the chance that someone will soon try again to delete this |
12771 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 12772 | bpt->type = bp_none; |
b8c9b27d | 12773 | xfree (bpt); |
c906108c SS |
12774 | } |
12775 | ||
4d6140d9 AC |
12776 | static void |
12777 | do_delete_breakpoint_cleanup (void *b) | |
12778 | { | |
12779 | delete_breakpoint (b); | |
12780 | } | |
12781 | ||
12782 | struct cleanup * | |
12783 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
12784 | { | |
12785 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
12786 | } | |
12787 | ||
51be5b68 PA |
12788 | /* Iterator function to call a user-provided callback function once |
12789 | for each of B and its related breakpoints. */ | |
12790 | ||
12791 | static void | |
12792 | iterate_over_related_breakpoints (struct breakpoint *b, | |
12793 | void (*function) (struct breakpoint *, | |
12794 | void *), | |
12795 | void *data) | |
12796 | { | |
12797 | struct breakpoint *related; | |
12798 | ||
12799 | related = b; | |
12800 | do | |
12801 | { | |
12802 | struct breakpoint *next; | |
12803 | ||
12804 | /* FUNCTION may delete RELATED. */ | |
12805 | next = related->related_breakpoint; | |
12806 | ||
12807 | if (next == related) | |
12808 | { | |
12809 | /* RELATED is the last ring entry. */ | |
12810 | function (related, data); | |
12811 | ||
12812 | /* FUNCTION may have deleted it, so we'd never reach back to | |
12813 | B. There's nothing left to do anyway, so just break | |
12814 | out. */ | |
12815 | break; | |
12816 | } | |
12817 | else | |
12818 | function (related, data); | |
12819 | ||
12820 | related = next; | |
12821 | } | |
12822 | while (related != b); | |
12823 | } | |
95a42b64 TT |
12824 | |
12825 | static void | |
12826 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
12827 | { | |
12828 | delete_breakpoint (b); | |
12829 | } | |
12830 | ||
51be5b68 PA |
12831 | /* A callback for map_breakpoint_numbers that calls |
12832 | delete_breakpoint. */ | |
12833 | ||
12834 | static void | |
12835 | do_map_delete_breakpoint (struct breakpoint *b, void *ignore) | |
12836 | { | |
12837 | iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL); | |
12838 | } | |
12839 | ||
c906108c | 12840 | void |
fba45db2 | 12841 | delete_command (char *arg, int from_tty) |
c906108c | 12842 | { |
35df4500 | 12843 | struct breakpoint *b, *b_tmp; |
c906108c | 12844 | |
ea9365bb TT |
12845 | dont_repeat (); |
12846 | ||
c906108c SS |
12847 | if (arg == 0) |
12848 | { | |
12849 | int breaks_to_delete = 0; | |
12850 | ||
46c6471b PA |
12851 | /* Delete all breakpoints if no argument. Do not delete |
12852 | internal breakpoints, these have to be deleted with an | |
12853 | explicit breakpoint number argument. */ | |
c5aa993b | 12854 | ALL_BREAKPOINTS (b) |
46c6471b | 12855 | if (user_breakpoint_p (b)) |
973d738b DJ |
12856 | { |
12857 | breaks_to_delete = 1; | |
12858 | break; | |
12859 | } | |
c906108c SS |
12860 | |
12861 | /* Ask user only if there are some breakpoints to delete. */ | |
12862 | if (!from_tty | |
e2e0b3e5 | 12863 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 12864 | { |
35df4500 | 12865 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 12866 | if (user_breakpoint_p (b)) |
c5aa993b | 12867 | delete_breakpoint (b); |
c906108c SS |
12868 | } |
12869 | } | |
12870 | else | |
51be5b68 | 12871 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
c906108c SS |
12872 | } |
12873 | ||
0d381245 VP |
12874 | static int |
12875 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 12876 | { |
0d381245 | 12877 | for (; loc; loc = loc->next) |
8645ff69 UW |
12878 | if (!loc->shlib_disabled |
12879 | && !loc->pspace->executing_startup) | |
0d381245 VP |
12880 | return 0; |
12881 | return 1; | |
fe3f5fa8 VP |
12882 | } |
12883 | ||
776592bf DE |
12884 | /* Subroutine of update_breakpoint_locations to simplify it. |
12885 | Return non-zero if multiple fns in list LOC have the same name. | |
12886 | Null names are ignored. */ | |
12887 | ||
12888 | static int | |
12889 | ambiguous_names_p (struct bp_location *loc) | |
12890 | { | |
12891 | struct bp_location *l; | |
12892 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
12893 | (int (*) (const void *, |
12894 | const void *)) streq, | |
776592bf DE |
12895 | NULL, xcalloc, xfree); |
12896 | ||
12897 | for (l = loc; l != NULL; l = l->next) | |
12898 | { | |
12899 | const char **slot; | |
12900 | const char *name = l->function_name; | |
12901 | ||
12902 | /* Allow for some names to be NULL, ignore them. */ | |
12903 | if (name == NULL) | |
12904 | continue; | |
12905 | ||
12906 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
12907 | INSERT); | |
4a64f543 MS |
12908 | /* NOTE: We can assume slot != NULL here because xcalloc never |
12909 | returns NULL. */ | |
776592bf DE |
12910 | if (*slot != NULL) |
12911 | { | |
12912 | htab_delete (htab); | |
12913 | return 1; | |
12914 | } | |
12915 | *slot = name; | |
12916 | } | |
12917 | ||
12918 | htab_delete (htab); | |
12919 | return 0; | |
12920 | } | |
12921 | ||
0fb4aa4b PA |
12922 | /* When symbols change, it probably means the sources changed as well, |
12923 | and it might mean the static tracepoint markers are no longer at | |
12924 | the same address or line numbers they used to be at last we | |
12925 | checked. Losing your static tracepoints whenever you rebuild is | |
12926 | undesirable. This function tries to resync/rematch gdb static | |
12927 | tracepoints with the markers on the target, for static tracepoints | |
12928 | that have not been set by marker id. Static tracepoint that have | |
12929 | been set by marker id are reset by marker id in breakpoint_re_set. | |
12930 | The heuristic is: | |
12931 | ||
12932 | 1) For a tracepoint set at a specific address, look for a marker at | |
12933 | the old PC. If one is found there, assume to be the same marker. | |
12934 | If the name / string id of the marker found is different from the | |
12935 | previous known name, assume that means the user renamed the marker | |
12936 | in the sources, and output a warning. | |
12937 | ||
12938 | 2) For a tracepoint set at a given line number, look for a marker | |
12939 | at the new address of the old line number. If one is found there, | |
12940 | assume to be the same marker. If the name / string id of the | |
12941 | marker found is different from the previous known name, assume that | |
12942 | means the user renamed the marker in the sources, and output a | |
12943 | warning. | |
12944 | ||
12945 | 3) If a marker is no longer found at the same address or line, it | |
12946 | may mean the marker no longer exists. But it may also just mean | |
12947 | the code changed a bit. Maybe the user added a few lines of code | |
12948 | that made the marker move up or down (in line number terms). Ask | |
12949 | the target for info about the marker with the string id as we knew | |
12950 | it. If found, update line number and address in the matching | |
12951 | static tracepoint. This will get confused if there's more than one | |
12952 | marker with the same ID (possible in UST, although unadvised | |
12953 | precisely because it confuses tools). */ | |
12954 | ||
12955 | static struct symtab_and_line | |
12956 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
12957 | { | |
d9b3f62e | 12958 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
12959 | struct static_tracepoint_marker marker; |
12960 | CORE_ADDR pc; | |
12961 | int i; | |
12962 | ||
12963 | pc = sal.pc; | |
12964 | if (sal.line) | |
12965 | find_line_pc (sal.symtab, sal.line, &pc); | |
12966 | ||
12967 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
12968 | { | |
d9b3f62e | 12969 | if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0) |
0fb4aa4b PA |
12970 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
12971 | b->number, | |
d9b3f62e | 12972 | tp->static_trace_marker_id, marker.str_id); |
0fb4aa4b | 12973 | |
d9b3f62e PA |
12974 | xfree (tp->static_trace_marker_id); |
12975 | tp->static_trace_marker_id = xstrdup (marker.str_id); | |
0fb4aa4b PA |
12976 | release_static_tracepoint_marker (&marker); |
12977 | ||
12978 | return sal; | |
12979 | } | |
12980 | ||
12981 | /* Old marker wasn't found on target at lineno. Try looking it up | |
12982 | by string ID. */ | |
12983 | if (!sal.explicit_pc | |
12984 | && sal.line != 0 | |
12985 | && sal.symtab != NULL | |
d9b3f62e | 12986 | && tp->static_trace_marker_id != NULL) |
0fb4aa4b PA |
12987 | { |
12988 | VEC(static_tracepoint_marker_p) *markers; | |
12989 | ||
12990 | markers | |
d9b3f62e | 12991 | = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id); |
0fb4aa4b PA |
12992 | |
12993 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
12994 | { | |
80e1d417 | 12995 | struct symtab_and_line sal2; |
0fb4aa4b | 12996 | struct symbol *sym; |
80e1d417 | 12997 | struct static_tracepoint_marker *tpmarker; |
79a45e25 | 12998 | struct ui_out *uiout = current_uiout; |
0fb4aa4b | 12999 | |
80e1d417 | 13000 | tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0); |
0fb4aa4b | 13001 | |
d9b3f62e | 13002 | xfree (tp->static_trace_marker_id); |
80e1d417 | 13003 | tp->static_trace_marker_id = xstrdup (tpmarker->str_id); |
0fb4aa4b PA |
13004 | |
13005 | warning (_("marker for static tracepoint %d (%s) not " | |
13006 | "found at previous line number"), | |
d9b3f62e | 13007 | b->number, tp->static_trace_marker_id); |
0fb4aa4b | 13008 | |
80e1d417 | 13009 | init_sal (&sal2); |
0fb4aa4b | 13010 | |
80e1d417 | 13011 | sal2.pc = tpmarker->address; |
0fb4aa4b | 13012 | |
80e1d417 AS |
13013 | sal2 = find_pc_line (tpmarker->address, 0); |
13014 | sym = find_pc_sect_function (tpmarker->address, NULL); | |
0fb4aa4b PA |
13015 | ui_out_text (uiout, "Now in "); |
13016 | if (sym) | |
13017 | { | |
13018 | ui_out_field_string (uiout, "func", | |
13019 | SYMBOL_PRINT_NAME (sym)); | |
13020 | ui_out_text (uiout, " at "); | |
13021 | } | |
80e1d417 | 13022 | ui_out_field_string (uiout, "file", sal2.symtab->filename); |
0fb4aa4b PA |
13023 | ui_out_text (uiout, ":"); |
13024 | ||
13025 | if (ui_out_is_mi_like_p (uiout)) | |
13026 | { | |
80e1d417 | 13027 | char *fullname = symtab_to_fullname (sal2.symtab); |
0fb4aa4b PA |
13028 | |
13029 | if (fullname) | |
13030 | ui_out_field_string (uiout, "fullname", fullname); | |
13031 | } | |
13032 | ||
80e1d417 | 13033 | ui_out_field_int (uiout, "line", sal2.line); |
0fb4aa4b PA |
13034 | ui_out_text (uiout, "\n"); |
13035 | ||
80e1d417 | 13036 | b->loc->line_number = sal2.line; |
0fb4aa4b | 13037 | |
f8eba3c6 | 13038 | xfree (b->loc->source_file); |
0fb4aa4b | 13039 | if (sym) |
80e1d417 | 13040 | b->loc->source_file = xstrdup (sal2.symtab->filename); |
0fb4aa4b | 13041 | else |
f8eba3c6 | 13042 | b->loc->source_file = NULL; |
0fb4aa4b PA |
13043 | |
13044 | xfree (b->addr_string); | |
13045 | b->addr_string = xstrprintf ("%s:%d", | |
80e1d417 | 13046 | sal2.symtab->filename, |
f8eba3c6 | 13047 | b->loc->line_number); |
0fb4aa4b PA |
13048 | |
13049 | /* Might be nice to check if function changed, and warn if | |
13050 | so. */ | |
13051 | ||
80e1d417 | 13052 | release_static_tracepoint_marker (tpmarker); |
0fb4aa4b PA |
13053 | } |
13054 | } | |
13055 | return sal; | |
13056 | } | |
13057 | ||
8d3788bd VP |
13058 | /* Returns 1 iff locations A and B are sufficiently same that |
13059 | we don't need to report breakpoint as changed. */ | |
13060 | ||
13061 | static int | |
13062 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
13063 | { | |
13064 | while (a && b) | |
13065 | { | |
13066 | if (a->address != b->address) | |
13067 | return 0; | |
13068 | ||
13069 | if (a->shlib_disabled != b->shlib_disabled) | |
13070 | return 0; | |
13071 | ||
13072 | if (a->enabled != b->enabled) | |
13073 | return 0; | |
13074 | ||
13075 | a = a->next; | |
13076 | b = b->next; | |
13077 | } | |
13078 | ||
13079 | if ((a == NULL) != (b == NULL)) | |
13080 | return 0; | |
13081 | ||
13082 | return 1; | |
13083 | } | |
13084 | ||
f1310107 TJB |
13085 | /* Create new breakpoint locations for B (a hardware or software breakpoint) |
13086 | based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is | |
13087 | a ranged breakpoint. */ | |
13088 | ||
0e30163f | 13089 | void |
0d381245 | 13090 | update_breakpoint_locations (struct breakpoint *b, |
f1310107 TJB |
13091 | struct symtabs_and_lines sals, |
13092 | struct symtabs_and_lines sals_end) | |
fe3f5fa8 VP |
13093 | { |
13094 | int i; | |
0d381245 VP |
13095 | struct bp_location *existing_locations = b->loc; |
13096 | ||
f8eba3c6 TT |
13097 | if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1)) |
13098 | { | |
13099 | /* Ranged breakpoints have only one start location and one end | |
13100 | location. */ | |
13101 | b->enable_state = bp_disabled; | |
13102 | update_global_location_list (1); | |
13103 | printf_unfiltered (_("Could not reset ranged breakpoint %d: " | |
13104 | "multiple locations found\n"), | |
13105 | b->number); | |
13106 | return; | |
13107 | } | |
f1310107 | 13108 | |
4a64f543 MS |
13109 | /* If there's no new locations, and all existing locations are |
13110 | pending, don't do anything. This optimizes the common case where | |
13111 | all locations are in the same shared library, that was unloaded. | |
13112 | We'd like to retain the location, so that when the library is | |
13113 | loaded again, we don't loose the enabled/disabled status of the | |
13114 | individual locations. */ | |
0d381245 | 13115 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) |
fe3f5fa8 VP |
13116 | return; |
13117 | ||
fe3f5fa8 VP |
13118 | b->loc = NULL; |
13119 | ||
0d381245 | 13120 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 13121 | { |
f8eba3c6 TT |
13122 | struct bp_location *new_loc; |
13123 | ||
13124 | switch_to_program_space_and_thread (sals.sals[i].pspace); | |
13125 | ||
13126 | new_loc = add_location_to_breakpoint (b, &(sals.sals[i])); | |
fe3f5fa8 | 13127 | |
0d381245 VP |
13128 | /* Reparse conditions, they might contain references to the |
13129 | old symtab. */ | |
13130 | if (b->cond_string != NULL) | |
13131 | { | |
f1310107 | 13132 | char *s; |
bfd189b1 | 13133 | volatile struct gdb_exception e; |
fe3f5fa8 | 13134 | |
0d381245 VP |
13135 | s = b->cond_string; |
13136 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
13137 | { | |
13138 | new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), | |
13139 | 0); | |
13140 | } | |
13141 | if (e.reason < 0) | |
13142 | { | |
3e43a32a MS |
13143 | warning (_("failed to reevaluate condition " |
13144 | "for breakpoint %d: %s"), | |
0d381245 VP |
13145 | b->number, e.message); |
13146 | new_loc->enabled = 0; | |
13147 | } | |
13148 | } | |
fe3f5fa8 | 13149 | |
f1310107 TJB |
13150 | if (sals_end.nelts) |
13151 | { | |
13152 | CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]); | |
13153 | ||
13154 | new_loc->length = end - sals.sals[0].pc + 1; | |
13155 | } | |
0d381245 | 13156 | } |
fe3f5fa8 | 13157 | |
514f746b AR |
13158 | /* Update locations of permanent breakpoints. */ |
13159 | if (b->enable_state == bp_permanent) | |
13160 | make_breakpoint_permanent (b); | |
13161 | ||
4a64f543 MS |
13162 | /* If possible, carry over 'disable' status from existing |
13163 | breakpoints. */ | |
0d381245 VP |
13164 | { |
13165 | struct bp_location *e = existing_locations; | |
776592bf DE |
13166 | /* If there are multiple breakpoints with the same function name, |
13167 | e.g. for inline functions, comparing function names won't work. | |
13168 | Instead compare pc addresses; this is just a heuristic as things | |
13169 | may have moved, but in practice it gives the correct answer | |
13170 | often enough until a better solution is found. */ | |
13171 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
13172 | ||
0d381245 VP |
13173 | for (; e; e = e->next) |
13174 | { | |
13175 | if (!e->enabled && e->function_name) | |
13176 | { | |
13177 | struct bp_location *l = b->loc; | |
776592bf DE |
13178 | if (have_ambiguous_names) |
13179 | { | |
13180 | for (; l; l = l->next) | |
f1310107 | 13181 | if (breakpoint_locations_match (e, l)) |
776592bf DE |
13182 | { |
13183 | l->enabled = 0; | |
13184 | break; | |
13185 | } | |
13186 | } | |
13187 | else | |
13188 | { | |
13189 | for (; l; l = l->next) | |
13190 | if (l->function_name | |
13191 | && strcmp (e->function_name, l->function_name) == 0) | |
13192 | { | |
13193 | l->enabled = 0; | |
13194 | break; | |
13195 | } | |
13196 | } | |
0d381245 VP |
13197 | } |
13198 | } | |
13199 | } | |
fe3f5fa8 | 13200 | |
8d3788bd VP |
13201 | if (!locations_are_equal (existing_locations, b->loc)) |
13202 | observer_notify_breakpoint_modified (b); | |
13203 | ||
b60e7edf | 13204 | update_global_location_list (1); |
fe3f5fa8 VP |
13205 | } |
13206 | ||
ef23e705 TJB |
13207 | /* Find the SaL locations corresponding to the given ADDR_STRING. |
13208 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ | |
13209 | ||
13210 | static struct symtabs_and_lines | |
13211 | addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found) | |
13212 | { | |
13213 | char *s; | |
02d20e4a | 13214 | struct symtabs_and_lines sals = {0}; |
f8eba3c6 | 13215 | volatile struct gdb_exception e; |
ef23e705 | 13216 | |
983af33b | 13217 | gdb_assert (b->ops != NULL); |
ef23e705 | 13218 | s = addr_string; |
ef23e705 TJB |
13219 | |
13220 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
13221 | { | |
983af33b | 13222 | b->ops->decode_linespec (b, &s, &sals); |
ef23e705 TJB |
13223 | } |
13224 | if (e.reason < 0) | |
13225 | { | |
13226 | int not_found_and_ok = 0; | |
13227 | /* For pending breakpoints, it's expected that parsing will | |
13228 | fail until the right shared library is loaded. User has | |
13229 | already told to create pending breakpoints and don't need | |
13230 | extra messages. If breakpoint is in bp_shlib_disabled | |
13231 | state, then user already saw the message about that | |
13232 | breakpoint being disabled, and don't want to see more | |
13233 | errors. */ | |
58438ac1 | 13234 | if (e.error == NOT_FOUND_ERROR |
ef23e705 TJB |
13235 | && (b->condition_not_parsed |
13236 | || (b->loc && b->loc->shlib_disabled) | |
f8eba3c6 | 13237 | || (b->loc && b->loc->pspace->executing_startup) |
ef23e705 TJB |
13238 | || b->enable_state == bp_disabled)) |
13239 | not_found_and_ok = 1; | |
13240 | ||
13241 | if (!not_found_and_ok) | |
13242 | { | |
13243 | /* We surely don't want to warn about the same breakpoint | |
13244 | 10 times. One solution, implemented here, is disable | |
13245 | the breakpoint on error. Another solution would be to | |
13246 | have separate 'warning emitted' flag. Since this | |
13247 | happens only when a binary has changed, I don't know | |
13248 | which approach is better. */ | |
13249 | b->enable_state = bp_disabled; | |
13250 | throw_exception (e); | |
13251 | } | |
13252 | } | |
13253 | ||
58438ac1 | 13254 | if (e.reason == 0 || e.error != NOT_FOUND_ERROR) |
ef23e705 | 13255 | { |
f8eba3c6 | 13256 | int i; |
ef23e705 | 13257 | |
f8eba3c6 TT |
13258 | for (i = 0; i < sals.nelts; ++i) |
13259 | resolve_sal_pc (&sals.sals[i]); | |
ef23e705 TJB |
13260 | if (b->condition_not_parsed && s && s[0]) |
13261 | { | |
13262 | char *cond_string = 0; | |
13263 | int thread = -1; | |
13264 | int task = 0; | |
13265 | ||
13266 | find_condition_and_thread (s, sals.sals[0].pc, | |
13267 | &cond_string, &thread, &task); | |
13268 | if (cond_string) | |
13269 | b->cond_string = cond_string; | |
13270 | b->thread = thread; | |
13271 | b->task = task; | |
13272 | b->condition_not_parsed = 0; | |
13273 | } | |
13274 | ||
983af33b | 13275 | if (b->type == bp_static_tracepoint && !strace_marker_p (b)) |
ef23e705 | 13276 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); |
ef23e705 | 13277 | |
58438ac1 TT |
13278 | *found = 1; |
13279 | } | |
13280 | else | |
13281 | *found = 0; | |
ef23e705 TJB |
13282 | |
13283 | return sals; | |
13284 | } | |
13285 | ||
348d480f PA |
13286 | /* The default re_set method, for typical hardware or software |
13287 | breakpoints. Reevaluate the breakpoint and recreate its | |
13288 | locations. */ | |
13289 | ||
13290 | static void | |
28010a5d | 13291 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 TJB |
13292 | { |
13293 | int found; | |
f1310107 | 13294 | struct symtabs_and_lines sals, sals_end; |
ef23e705 | 13295 | struct symtabs_and_lines expanded = {0}; |
f1310107 | 13296 | struct symtabs_and_lines expanded_end = {0}; |
ef23e705 TJB |
13297 | |
13298 | sals = addr_string_to_sals (b, b->addr_string, &found); | |
13299 | if (found) | |
13300 | { | |
13301 | make_cleanup (xfree, sals.sals); | |
f8eba3c6 | 13302 | expanded = sals; |
ef23e705 TJB |
13303 | } |
13304 | ||
f1310107 TJB |
13305 | if (b->addr_string_range_end) |
13306 | { | |
13307 | sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found); | |
13308 | if (found) | |
13309 | { | |
13310 | make_cleanup (xfree, sals_end.sals); | |
f8eba3c6 | 13311 | expanded_end = sals_end; |
f1310107 TJB |
13312 | } |
13313 | } | |
13314 | ||
13315 | update_breakpoint_locations (b, expanded, expanded_end); | |
28010a5d PA |
13316 | } |
13317 | ||
983af33b SDJ |
13318 | /* Default method for creating SALs from an address string. It basically |
13319 | calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ | |
13320 | ||
13321 | static void | |
13322 | create_sals_from_address_default (char **arg, | |
13323 | struct linespec_result *canonical, | |
13324 | enum bptype type_wanted, | |
13325 | char *addr_start, char **copy_arg) | |
13326 | { | |
13327 | parse_breakpoint_sals (arg, canonical); | |
13328 | } | |
13329 | ||
13330 | /* Call create_breakpoints_sal for the given arguments. This is the default | |
13331 | function for the `create_breakpoints_sal' method of | |
13332 | breakpoint_ops. */ | |
13333 | ||
13334 | static void | |
13335 | create_breakpoints_sal_default (struct gdbarch *gdbarch, | |
13336 | struct linespec_result *canonical, | |
13337 | struct linespec_sals *lsal, | |
13338 | char *cond_string, | |
13339 | enum bptype type_wanted, | |
13340 | enum bpdisp disposition, | |
13341 | int thread, | |
13342 | int task, int ignore_count, | |
13343 | const struct breakpoint_ops *ops, | |
13344 | int from_tty, int enabled, | |
44f238bb | 13345 | int internal, unsigned flags) |
983af33b SDJ |
13346 | { |
13347 | create_breakpoints_sal (gdbarch, canonical, cond_string, | |
13348 | type_wanted, disposition, | |
13349 | thread, task, ignore_count, ops, from_tty, | |
44f238bb | 13350 | enabled, internal, flags); |
983af33b SDJ |
13351 | } |
13352 | ||
13353 | /* Decode the line represented by S by calling decode_line_full. This is the | |
13354 | default function for the `decode_linespec' method of breakpoint_ops. */ | |
13355 | ||
13356 | static void | |
13357 | decode_linespec_default (struct breakpoint *b, char **s, | |
13358 | struct symtabs_and_lines *sals) | |
13359 | { | |
13360 | struct linespec_result canonical; | |
13361 | ||
13362 | init_linespec_result (&canonical); | |
13363 | decode_line_full (s, DECODE_LINE_FUNFIRSTLINE, | |
13364 | (struct symtab *) NULL, 0, | |
13365 | &canonical, multiple_symbols_all, | |
13366 | b->filter); | |
13367 | ||
13368 | /* We should get 0 or 1 resulting SALs. */ | |
13369 | gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2); | |
13370 | ||
13371 | if (VEC_length (linespec_sals, canonical.sals) > 0) | |
13372 | { | |
13373 | struct linespec_sals *lsal; | |
13374 | ||
13375 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
13376 | *sals = lsal->sals; | |
13377 | /* Arrange it so the destructor does not free the | |
13378 | contents. */ | |
13379 | lsal->sals.sals = NULL; | |
13380 | } | |
13381 | ||
13382 | destroy_linespec_result (&canonical); | |
13383 | } | |
13384 | ||
28010a5d PA |
13385 | /* Prepare the global context for a re-set of breakpoint B. */ |
13386 | ||
13387 | static struct cleanup * | |
13388 | prepare_re_set_context (struct breakpoint *b) | |
13389 | { | |
13390 | struct cleanup *cleanups; | |
13391 | ||
13392 | input_radix = b->input_radix; | |
13393 | cleanups = save_current_space_and_thread (); | |
f8eba3c6 TT |
13394 | if (b->pspace != NULL) |
13395 | switch_to_program_space_and_thread (b->pspace); | |
28010a5d PA |
13396 | set_language (b->language); |
13397 | ||
13398 | return cleanups; | |
ef23e705 TJB |
13399 | } |
13400 | ||
c906108c SS |
13401 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
13402 | The value we return ends up being the return value from catch_errors. | |
13403 | Unused in this case. */ | |
13404 | ||
13405 | static int | |
4efb68b1 | 13406 | breakpoint_re_set_one (void *bint) |
c906108c | 13407 | { |
4a64f543 | 13408 | /* Get past catch_errs. */ |
53a5351d | 13409 | struct breakpoint *b = (struct breakpoint *) bint; |
348d480f | 13410 | struct cleanup *cleanups; |
c906108c | 13411 | |
348d480f PA |
13412 | cleanups = prepare_re_set_context (b); |
13413 | b->ops->re_set (b); | |
13414 | do_cleanups (cleanups); | |
c906108c SS |
13415 | return 0; |
13416 | } | |
13417 | ||
69de3c6a | 13418 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 13419 | void |
69de3c6a | 13420 | breakpoint_re_set (void) |
c906108c | 13421 | { |
35df4500 | 13422 | struct breakpoint *b, *b_tmp; |
c906108c SS |
13423 | enum language save_language; |
13424 | int save_input_radix; | |
6c95b8df | 13425 | struct cleanup *old_chain; |
c5aa993b | 13426 | |
c906108c SS |
13427 | save_language = current_language->la_language; |
13428 | save_input_radix = input_radix; | |
6c95b8df PA |
13429 | old_chain = save_current_program_space (); |
13430 | ||
35df4500 | 13431 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 13432 | { |
4a64f543 | 13433 | /* Format possible error msg. */ |
fe3f5fa8 | 13434 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
13435 | b->number); |
13436 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 13437 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 13438 | do_cleanups (cleanups); |
c5aa993b | 13439 | } |
c906108c SS |
13440 | set_language (save_language); |
13441 | input_radix = save_input_radix; | |
e62c965a | 13442 | |
0756c555 | 13443 | jit_breakpoint_re_set (); |
4efc6507 | 13444 | |
6c95b8df PA |
13445 | do_cleanups (old_chain); |
13446 | ||
af02033e PP |
13447 | create_overlay_event_breakpoint (); |
13448 | create_longjmp_master_breakpoint (); | |
13449 | create_std_terminate_master_breakpoint (); | |
186c406b | 13450 | create_exception_master_breakpoint (); |
1bfeeb0f JL |
13451 | |
13452 | /* While we're at it, reset the skip list too. */ | |
13453 | skip_re_set (); | |
c906108c SS |
13454 | } |
13455 | \f | |
c906108c SS |
13456 | /* Reset the thread number of this breakpoint: |
13457 | ||
13458 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 13459 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 13460 | void |
fba45db2 | 13461 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
13462 | { |
13463 | if (b->thread != -1) | |
13464 | { | |
39f77062 KB |
13465 | if (in_thread_list (inferior_ptid)) |
13466 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
13467 | |
13468 | /* We're being called after following a fork. The new fork is | |
13469 | selected as current, and unless this was a vfork will have a | |
13470 | different program space from the original thread. Reset that | |
13471 | as well. */ | |
13472 | b->loc->pspace = current_program_space; | |
c906108c SS |
13473 | } |
13474 | } | |
13475 | ||
03ac34d5 MS |
13476 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
13477 | If from_tty is nonzero, it prints a message to that effect, | |
13478 | which ends with a period (no newline). */ | |
13479 | ||
c906108c | 13480 | void |
fba45db2 | 13481 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 13482 | { |
52f0bd74 | 13483 | struct breakpoint *b; |
c906108c SS |
13484 | |
13485 | if (count < 0) | |
13486 | count = 0; | |
13487 | ||
13488 | ALL_BREAKPOINTS (b) | |
13489 | if (b->number == bptnum) | |
c5aa993b | 13490 | { |
d77f58be SS |
13491 | if (is_tracepoint (b)) |
13492 | { | |
13493 | if (from_tty && count != 0) | |
13494 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
13495 | bptnum); | |
13496 | return; | |
13497 | } | |
13498 | ||
c5aa993b | 13499 | b->ignore_count = count; |
221ea385 KS |
13500 | if (from_tty) |
13501 | { | |
13502 | if (count == 0) | |
3e43a32a MS |
13503 | printf_filtered (_("Will stop next time " |
13504 | "breakpoint %d is reached."), | |
221ea385 KS |
13505 | bptnum); |
13506 | else if (count == 1) | |
a3f17187 | 13507 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
13508 | bptnum); |
13509 | else | |
3e43a32a MS |
13510 | printf_filtered (_("Will ignore next %d " |
13511 | "crossings of breakpoint %d."), | |
221ea385 KS |
13512 | count, bptnum); |
13513 | } | |
c5aa993b | 13514 | breakpoints_changed (); |
8d3788bd | 13515 | observer_notify_breakpoint_modified (b); |
c5aa993b JM |
13516 | return; |
13517 | } | |
c906108c | 13518 | |
8a3fe4f8 | 13519 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
13520 | } |
13521 | ||
c906108c SS |
13522 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
13523 | ||
13524 | static void | |
fba45db2 | 13525 | ignore_command (char *args, int from_tty) |
c906108c SS |
13526 | { |
13527 | char *p = args; | |
52f0bd74 | 13528 | int num; |
c906108c SS |
13529 | |
13530 | if (p == 0) | |
e2e0b3e5 | 13531 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 13532 | |
c906108c | 13533 | num = get_number (&p); |
5c44784c | 13534 | if (num == 0) |
8a3fe4f8 | 13535 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 13536 | if (*p == 0) |
8a3fe4f8 | 13537 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
13538 | |
13539 | set_ignore_count (num, | |
13540 | longest_to_int (value_as_long (parse_and_eval (p))), | |
13541 | from_tty); | |
221ea385 KS |
13542 | if (from_tty) |
13543 | printf_filtered ("\n"); | |
c906108c SS |
13544 | } |
13545 | \f | |
13546 | /* Call FUNCTION on each of the breakpoints | |
13547 | whose numbers are given in ARGS. */ | |
13548 | ||
13549 | static void | |
95a42b64 TT |
13550 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
13551 | void *), | |
13552 | void *data) | |
c906108c | 13553 | { |
52f0bd74 AC |
13554 | int num; |
13555 | struct breakpoint *b, *tmp; | |
11cf8741 | 13556 | int match; |
197f0a60 | 13557 | struct get_number_or_range_state state; |
c906108c | 13558 | |
197f0a60 | 13559 | if (args == 0) |
e2e0b3e5 | 13560 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c | 13561 | |
197f0a60 TT |
13562 | init_number_or_range (&state, args); |
13563 | ||
13564 | while (!state.finished) | |
c906108c | 13565 | { |
197f0a60 TT |
13566 | char *p = state.string; |
13567 | ||
11cf8741 | 13568 | match = 0; |
c5aa993b | 13569 | |
197f0a60 | 13570 | num = get_number_or_range (&state); |
5c44784c | 13571 | if (num == 0) |
c5aa993b | 13572 | { |
8a3fe4f8 | 13573 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
13574 | } |
13575 | else | |
13576 | { | |
13577 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
13578 | if (b->number == num) | |
13579 | { | |
11cf8741 | 13580 | match = 1; |
cdac0397 | 13581 | function (b, data); |
11cf8741 | 13582 | break; |
5c44784c | 13583 | } |
11cf8741 | 13584 | if (match == 0) |
a3f17187 | 13585 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 13586 | } |
c906108c SS |
13587 | } |
13588 | } | |
13589 | ||
0d381245 VP |
13590 | static struct bp_location * |
13591 | find_location_by_number (char *number) | |
13592 | { | |
13593 | char *dot = strchr (number, '.'); | |
13594 | char *p1; | |
13595 | int bp_num; | |
13596 | int loc_num; | |
13597 | struct breakpoint *b; | |
13598 | struct bp_location *loc; | |
13599 | ||
13600 | *dot = '\0'; | |
13601 | ||
13602 | p1 = number; | |
197f0a60 | 13603 | bp_num = get_number (&p1); |
0d381245 VP |
13604 | if (bp_num == 0) |
13605 | error (_("Bad breakpoint number '%s'"), number); | |
13606 | ||
13607 | ALL_BREAKPOINTS (b) | |
13608 | if (b->number == bp_num) | |
13609 | { | |
13610 | break; | |
13611 | } | |
13612 | ||
13613 | if (!b || b->number != bp_num) | |
13614 | error (_("Bad breakpoint number '%s'"), number); | |
13615 | ||
13616 | p1 = dot+1; | |
197f0a60 | 13617 | loc_num = get_number (&p1); |
0d381245 VP |
13618 | if (loc_num == 0) |
13619 | error (_("Bad breakpoint location number '%s'"), number); | |
13620 | ||
13621 | --loc_num; | |
13622 | loc = b->loc; | |
13623 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
13624 | ; | |
13625 | if (!loc) | |
13626 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
13627 | ||
13628 | return loc; | |
13629 | } | |
13630 | ||
13631 | ||
1900040c MS |
13632 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
13633 | If from_tty is nonzero, it prints a message to that effect, | |
13634 | which ends with a period (no newline). */ | |
13635 | ||
c906108c | 13636 | void |
fba45db2 | 13637 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
13638 | { |
13639 | /* Never disable a watchpoint scope breakpoint; we want to | |
13640 | hit them when we leave scope so we can delete both the | |
13641 | watchpoint and its scope breakpoint at that time. */ | |
13642 | if (bpt->type == bp_watchpoint_scope) | |
13643 | return; | |
13644 | ||
c2c6d25f | 13645 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 13646 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
13647 | return; |
13648 | ||
b5de0fa7 | 13649 | bpt->enable_state = bp_disabled; |
c906108c | 13650 | |
b775012e LM |
13651 | /* Mark breakpoint locations modified. */ |
13652 | mark_breakpoint_modified (bpt); | |
13653 | ||
d248b706 KY |
13654 | if (target_supports_enable_disable_tracepoint () |
13655 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
13656 | { | |
13657 | struct bp_location *location; | |
13658 | ||
13659 | for (location = bpt->loc; location; location = location->next) | |
13660 | target_disable_tracepoint (location); | |
13661 | } | |
13662 | ||
b60e7edf | 13663 | update_global_location_list (0); |
c906108c | 13664 | |
8d3788bd | 13665 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
13666 | } |
13667 | ||
51be5b68 PA |
13668 | /* A callback for iterate_over_related_breakpoints. */ |
13669 | ||
13670 | static void | |
13671 | do_disable_breakpoint (struct breakpoint *b, void *ignore) | |
13672 | { | |
13673 | disable_breakpoint (b); | |
13674 | } | |
13675 | ||
95a42b64 TT |
13676 | /* A callback for map_breakpoint_numbers that calls |
13677 | disable_breakpoint. */ | |
13678 | ||
13679 | static void | |
13680 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
13681 | { | |
51be5b68 | 13682 | iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL); |
95a42b64 TT |
13683 | } |
13684 | ||
c906108c | 13685 | static void |
fba45db2 | 13686 | disable_command (char *args, int from_tty) |
c906108c | 13687 | { |
c906108c | 13688 | if (args == 0) |
46c6471b PA |
13689 | { |
13690 | struct breakpoint *bpt; | |
13691 | ||
13692 | ALL_BREAKPOINTS (bpt) | |
13693 | if (user_breakpoint_p (bpt)) | |
13694 | disable_breakpoint (bpt); | |
13695 | } | |
0d381245 VP |
13696 | else if (strchr (args, '.')) |
13697 | { | |
13698 | struct bp_location *loc = find_location_by_number (args); | |
13699 | if (loc) | |
d248b706 | 13700 | { |
b775012e LM |
13701 | if (loc->enabled) |
13702 | { | |
13703 | loc->enabled = 0; | |
13704 | mark_breakpoint_location_modified (loc); | |
13705 | } | |
d248b706 KY |
13706 | if (target_supports_enable_disable_tracepoint () |
13707 | && current_trace_status ()->running && loc->owner | |
13708 | && is_tracepoint (loc->owner)) | |
13709 | target_disable_tracepoint (loc); | |
13710 | } | |
b60e7edf | 13711 | update_global_location_list (0); |
0d381245 | 13712 | } |
c906108c | 13713 | else |
95a42b64 | 13714 | map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL); |
c906108c SS |
13715 | } |
13716 | ||
13717 | static void | |
816338b5 SS |
13718 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, |
13719 | int count) | |
c906108c | 13720 | { |
afe38095 | 13721 | int target_resources_ok; |
c906108c SS |
13722 | |
13723 | if (bpt->type == bp_hardware_breakpoint) | |
13724 | { | |
13725 | int i; | |
c5aa993b | 13726 | i = hw_breakpoint_used_count (); |
53a5351d | 13727 | target_resources_ok = |
d92524f1 | 13728 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 13729 | i + 1, 0); |
c906108c | 13730 | if (target_resources_ok == 0) |
8a3fe4f8 | 13731 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 13732 | else if (target_resources_ok < 0) |
8a3fe4f8 | 13733 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
13734 | } |
13735 | ||
cc60f2e3 | 13736 | if (is_watchpoint (bpt)) |
c906108c | 13737 | { |
d07205c2 JK |
13738 | /* Initialize it just to avoid a GCC false warning. */ |
13739 | enum enable_state orig_enable_state = 0; | |
bfd189b1 | 13740 | volatile struct gdb_exception e; |
dde02812 ES |
13741 | |
13742 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 13743 | { |
3a5c3e22 PA |
13744 | struct watchpoint *w = (struct watchpoint *) bpt; |
13745 | ||
1e718ff1 TJB |
13746 | orig_enable_state = bpt->enable_state; |
13747 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 13748 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 13749 | } |
dde02812 | 13750 | if (e.reason < 0) |
c5aa993b | 13751 | { |
1e718ff1 | 13752 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
13753 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
13754 | bpt->number); | |
13755 | return; | |
c5aa993b | 13756 | } |
c906108c | 13757 | } |
0101ce28 | 13758 | |
b4c291bb KH |
13759 | if (bpt->enable_state != bp_permanent) |
13760 | bpt->enable_state = bp_enabled; | |
d248b706 | 13761 | |
b775012e LM |
13762 | bpt->enable_state = bp_enabled; |
13763 | ||
13764 | /* Mark breakpoint locations modified. */ | |
13765 | mark_breakpoint_modified (bpt); | |
13766 | ||
d248b706 KY |
13767 | if (target_supports_enable_disable_tracepoint () |
13768 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
13769 | { | |
13770 | struct bp_location *location; | |
13771 | ||
13772 | for (location = bpt->loc; location; location = location->next) | |
13773 | target_enable_tracepoint (location); | |
13774 | } | |
13775 | ||
b4c291bb | 13776 | bpt->disposition = disposition; |
816338b5 | 13777 | bpt->enable_count = count; |
b60e7edf | 13778 | update_global_location_list (1); |
b4c291bb KH |
13779 | breakpoints_changed (); |
13780 | ||
8d3788bd | 13781 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
13782 | } |
13783 | ||
fe3f5fa8 | 13784 | |
c906108c | 13785 | void |
fba45db2 | 13786 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 13787 | { |
816338b5 | 13788 | enable_breakpoint_disp (bpt, bpt->disposition, 0); |
51be5b68 PA |
13789 | } |
13790 | ||
13791 | static void | |
13792 | do_enable_breakpoint (struct breakpoint *bpt, void *arg) | |
13793 | { | |
13794 | enable_breakpoint (bpt); | |
c906108c SS |
13795 | } |
13796 | ||
95a42b64 TT |
13797 | /* A callback for map_breakpoint_numbers that calls |
13798 | enable_breakpoint. */ | |
13799 | ||
13800 | static void | |
13801 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
13802 | { | |
51be5b68 | 13803 | iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL); |
95a42b64 TT |
13804 | } |
13805 | ||
c906108c SS |
13806 | /* The enable command enables the specified breakpoints (or all defined |
13807 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 13808 | in stopping the inferior. */ |
c906108c | 13809 | |
c906108c | 13810 | static void |
fba45db2 | 13811 | enable_command (char *args, int from_tty) |
c906108c | 13812 | { |
c906108c | 13813 | if (args == 0) |
46c6471b PA |
13814 | { |
13815 | struct breakpoint *bpt; | |
13816 | ||
13817 | ALL_BREAKPOINTS (bpt) | |
13818 | if (user_breakpoint_p (bpt)) | |
13819 | enable_breakpoint (bpt); | |
13820 | } | |
0d381245 VP |
13821 | else if (strchr (args, '.')) |
13822 | { | |
13823 | struct bp_location *loc = find_location_by_number (args); | |
13824 | if (loc) | |
d248b706 | 13825 | { |
b775012e LM |
13826 | if (!loc->enabled) |
13827 | { | |
13828 | loc->enabled = 1; | |
13829 | mark_breakpoint_location_modified (loc); | |
13830 | } | |
d248b706 KY |
13831 | if (target_supports_enable_disable_tracepoint () |
13832 | && current_trace_status ()->running && loc->owner | |
13833 | && is_tracepoint (loc->owner)) | |
13834 | target_enable_tracepoint (loc); | |
13835 | } | |
b60e7edf | 13836 | update_global_location_list (1); |
0d381245 | 13837 | } |
c906108c | 13838 | else |
95a42b64 | 13839 | map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL); |
c906108c SS |
13840 | } |
13841 | ||
816338b5 SS |
13842 | /* This struct packages up disposition data for application to multiple |
13843 | breakpoints. */ | |
13844 | ||
13845 | struct disp_data | |
13846 | { | |
13847 | enum bpdisp disp; | |
13848 | int count; | |
13849 | }; | |
13850 | ||
c906108c | 13851 | static void |
51be5b68 PA |
13852 | do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg) |
13853 | { | |
816338b5 | 13854 | struct disp_data disp_data = *(struct disp_data *) arg; |
51be5b68 | 13855 | |
816338b5 | 13856 | enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count); |
51be5b68 PA |
13857 | } |
13858 | ||
13859 | static void | |
13860 | do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore) | |
c906108c | 13861 | { |
816338b5 | 13862 | struct disp_data disp = { disp_disable, 1 }; |
51be5b68 PA |
13863 | |
13864 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
13865 | } |
13866 | ||
c906108c | 13867 | static void |
fba45db2 | 13868 | enable_once_command (char *args, int from_tty) |
c906108c | 13869 | { |
51be5b68 | 13870 | map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL); |
c906108c SS |
13871 | } |
13872 | ||
816338b5 SS |
13873 | static void |
13874 | do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr) | |
13875 | { | |
13876 | struct disp_data disp = { disp_disable, *(int *) countptr }; | |
13877 | ||
13878 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
13879 | } | |
13880 | ||
13881 | static void | |
13882 | enable_count_command (char *args, int from_tty) | |
13883 | { | |
13884 | int count = get_number (&args); | |
13885 | ||
13886 | map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count); | |
13887 | } | |
13888 | ||
c906108c | 13889 | static void |
51be5b68 | 13890 | do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 13891 | { |
816338b5 | 13892 | struct disp_data disp = { disp_del, 1 }; |
51be5b68 PA |
13893 | |
13894 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
13895 | } |
13896 | ||
c906108c | 13897 | static void |
fba45db2 | 13898 | enable_delete_command (char *args, int from_tty) |
c906108c | 13899 | { |
51be5b68 | 13900 | map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL); |
c906108c SS |
13901 | } |
13902 | \f | |
fa8d40ab JJ |
13903 | static void |
13904 | set_breakpoint_cmd (char *args, int from_tty) | |
13905 | { | |
13906 | } | |
13907 | ||
13908 | static void | |
13909 | show_breakpoint_cmd (char *args, int from_tty) | |
13910 | { | |
13911 | } | |
13912 | ||
1f3b5d1b PP |
13913 | /* Invalidate last known value of any hardware watchpoint if |
13914 | the memory which that value represents has been written to by | |
13915 | GDB itself. */ | |
13916 | ||
13917 | static void | |
13918 | invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len, | |
13919 | const bfd_byte *data) | |
13920 | { | |
13921 | struct breakpoint *bp; | |
13922 | ||
13923 | ALL_BREAKPOINTS (bp) | |
13924 | if (bp->enable_state == bp_enabled | |
3a5c3e22 | 13925 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 13926 | { |
3a5c3e22 | 13927 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 13928 | |
3a5c3e22 PA |
13929 | if (wp->val_valid && wp->val) |
13930 | { | |
13931 | struct bp_location *loc; | |
13932 | ||
13933 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
13934 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
13935 | && loc->address + loc->length > addr | |
13936 | && addr + len > loc->address) | |
13937 | { | |
13938 | value_free (wp->val); | |
13939 | wp->val = NULL; | |
13940 | wp->val_valid = 0; | |
13941 | } | |
13942 | } | |
1f3b5d1b PP |
13943 | } |
13944 | } | |
13945 | ||
1bfeeb0f JL |
13946 | /* Use the last displayed codepoint's values, or nothing |
13947 | if they aren't valid. */ | |
c906108c SS |
13948 | |
13949 | struct symtabs_and_lines | |
f8eba3c6 | 13950 | decode_line_spec_1 (char *string, int flags) |
c906108c SS |
13951 | { |
13952 | struct symtabs_and_lines sals; | |
cc59ec59 | 13953 | |
c906108c | 13954 | if (string == 0) |
8a3fe4f8 | 13955 | error (_("Empty line specification.")); |
1bfeeb0f | 13956 | if (last_displayed_sal_is_valid ()) |
f8eba3c6 | 13957 | sals = decode_line_1 (&string, flags, |
1bfeeb0f | 13958 | get_last_displayed_symtab (), |
f8eba3c6 | 13959 | get_last_displayed_line ()); |
c906108c | 13960 | else |
f8eba3c6 | 13961 | sals = decode_line_1 (&string, flags, (struct symtab *) NULL, 0); |
c906108c | 13962 | if (*string) |
8a3fe4f8 | 13963 | error (_("Junk at end of line specification: %s"), string); |
c906108c SS |
13964 | return sals; |
13965 | } | |
8181d85f DJ |
13966 | |
13967 | /* Create and insert a raw software breakpoint at PC. Return an | |
13968 | identifier, which should be used to remove the breakpoint later. | |
13969 | In general, places which call this should be using something on the | |
13970 | breakpoint chain instead; this function should be eliminated | |
13971 | someday. */ | |
13972 | ||
13973 | void * | |
6c95b8df PA |
13974 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, |
13975 | struct address_space *aspace, CORE_ADDR pc) | |
8181d85f DJ |
13976 | { |
13977 | struct bp_target_info *bp_tgt; | |
13978 | ||
6c95b8df | 13979 | bp_tgt = XZALLOC (struct bp_target_info); |
8181d85f | 13980 | |
6c95b8df | 13981 | bp_tgt->placed_address_space = aspace; |
8181d85f | 13982 | bp_tgt->placed_address = pc; |
6c95b8df | 13983 | |
a6d9a66e | 13984 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
8181d85f DJ |
13985 | { |
13986 | /* Could not insert the breakpoint. */ | |
13987 | xfree (bp_tgt); | |
13988 | return NULL; | |
13989 | } | |
13990 | ||
13991 | return bp_tgt; | |
13992 | } | |
13993 | ||
4a64f543 MS |
13994 | /* Remove a breakpoint BP inserted by |
13995 | deprecated_insert_raw_breakpoint. */ | |
8181d85f DJ |
13996 | |
13997 | int | |
a6d9a66e | 13998 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
8181d85f DJ |
13999 | { |
14000 | struct bp_target_info *bp_tgt = bp; | |
14001 | int ret; | |
14002 | ||
a6d9a66e | 14003 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
8181d85f DJ |
14004 | xfree (bp_tgt); |
14005 | ||
14006 | return ret; | |
14007 | } | |
14008 | ||
4a64f543 MS |
14009 | /* One (or perhaps two) breakpoints used for software single |
14010 | stepping. */ | |
8181d85f DJ |
14011 | |
14012 | static void *single_step_breakpoints[2]; | |
a6d9a66e | 14013 | static struct gdbarch *single_step_gdbarch[2]; |
8181d85f DJ |
14014 | |
14015 | /* Create and insert a breakpoint for software single step. */ | |
14016 | ||
14017 | void | |
6c95b8df | 14018 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
14019 | struct address_space *aspace, |
14020 | CORE_ADDR next_pc) | |
8181d85f DJ |
14021 | { |
14022 | void **bpt_p; | |
14023 | ||
14024 | if (single_step_breakpoints[0] == NULL) | |
a6d9a66e UW |
14025 | { |
14026 | bpt_p = &single_step_breakpoints[0]; | |
14027 | single_step_gdbarch[0] = gdbarch; | |
14028 | } | |
8181d85f DJ |
14029 | else |
14030 | { | |
14031 | gdb_assert (single_step_breakpoints[1] == NULL); | |
14032 | bpt_p = &single_step_breakpoints[1]; | |
a6d9a66e | 14033 | single_step_gdbarch[1] = gdbarch; |
8181d85f DJ |
14034 | } |
14035 | ||
4a64f543 MS |
14036 | /* NOTE drow/2006-04-11: A future improvement to this function would |
14037 | be to only create the breakpoints once, and actually put them on | |
14038 | the breakpoint chain. That would let us use set_raw_breakpoint. | |
14039 | We could adjust the addresses each time they were needed. Doing | |
14040 | this requires corresponding changes elsewhere where single step | |
14041 | breakpoints are handled, however. So, for now, we use this. */ | |
8181d85f | 14042 | |
6c95b8df | 14043 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc); |
8181d85f | 14044 | if (*bpt_p == NULL) |
5af949e3 UW |
14045 | error (_("Could not insert single-step breakpoint at %s"), |
14046 | paddress (gdbarch, next_pc)); | |
8181d85f DJ |
14047 | } |
14048 | ||
f02253f1 HZ |
14049 | /* Check if the breakpoints used for software single stepping |
14050 | were inserted or not. */ | |
14051 | ||
14052 | int | |
14053 | single_step_breakpoints_inserted (void) | |
14054 | { | |
14055 | return (single_step_breakpoints[0] != NULL | |
14056 | || single_step_breakpoints[1] != NULL); | |
14057 | } | |
14058 | ||
8181d85f DJ |
14059 | /* Remove and delete any breakpoints used for software single step. */ |
14060 | ||
14061 | void | |
14062 | remove_single_step_breakpoints (void) | |
14063 | { | |
14064 | gdb_assert (single_step_breakpoints[0] != NULL); | |
14065 | ||
14066 | /* See insert_single_step_breakpoint for more about this deprecated | |
14067 | call. */ | |
a6d9a66e UW |
14068 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
14069 | single_step_breakpoints[0]); | |
14070 | single_step_gdbarch[0] = NULL; | |
8181d85f DJ |
14071 | single_step_breakpoints[0] = NULL; |
14072 | ||
14073 | if (single_step_breakpoints[1] != NULL) | |
14074 | { | |
a6d9a66e UW |
14075 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
14076 | single_step_breakpoints[1]); | |
14077 | single_step_gdbarch[1] = NULL; | |
8181d85f DJ |
14078 | single_step_breakpoints[1] = NULL; |
14079 | } | |
14080 | } | |
14081 | ||
d03285ec UW |
14082 | /* Delete software single step breakpoints without removing them from |
14083 | the inferior. This is intended to be used if the inferior's address | |
14084 | space where they were inserted is already gone, e.g. after exit or | |
14085 | exec. */ | |
14086 | ||
14087 | void | |
14088 | cancel_single_step_breakpoints (void) | |
14089 | { | |
14090 | int i; | |
14091 | ||
14092 | for (i = 0; i < 2; i++) | |
14093 | if (single_step_breakpoints[i]) | |
14094 | { | |
14095 | xfree (single_step_breakpoints[i]); | |
14096 | single_step_breakpoints[i] = NULL; | |
14097 | single_step_gdbarch[i] = NULL; | |
14098 | } | |
14099 | } | |
14100 | ||
14101 | /* Detach software single-step breakpoints from INFERIOR_PTID without | |
14102 | removing them. */ | |
14103 | ||
14104 | static void | |
14105 | detach_single_step_breakpoints (void) | |
14106 | { | |
14107 | int i; | |
14108 | ||
14109 | for (i = 0; i < 2; i++) | |
14110 | if (single_step_breakpoints[i]) | |
14111 | target_remove_breakpoint (single_step_gdbarch[i], | |
14112 | single_step_breakpoints[i]); | |
14113 | } | |
14114 | ||
4a64f543 MS |
14115 | /* Check whether a software single-step breakpoint is inserted at |
14116 | PC. */ | |
1aafd4da UW |
14117 | |
14118 | static int | |
cc59ec59 MS |
14119 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, |
14120 | CORE_ADDR pc) | |
1aafd4da UW |
14121 | { |
14122 | int i; | |
14123 | ||
14124 | for (i = 0; i < 2; i++) | |
14125 | { | |
14126 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
6c95b8df PA |
14127 | if (bp_tgt |
14128 | && breakpoint_address_match (bp_tgt->placed_address_space, | |
14129 | bp_tgt->placed_address, | |
14130 | aspace, pc)) | |
1aafd4da UW |
14131 | return 1; |
14132 | } | |
14133 | ||
14134 | return 0; | |
14135 | } | |
14136 | ||
a96d9b2e SDJ |
14137 | /* Returns 0 if 'bp' is NOT a syscall catchpoint, |
14138 | non-zero otherwise. */ | |
14139 | static int | |
14140 | is_syscall_catchpoint_enabled (struct breakpoint *bp) | |
14141 | { | |
14142 | if (syscall_catchpoint_p (bp) | |
14143 | && bp->enable_state != bp_disabled | |
14144 | && bp->enable_state != bp_call_disabled) | |
14145 | return 1; | |
14146 | else | |
14147 | return 0; | |
14148 | } | |
14149 | ||
14150 | int | |
14151 | catch_syscall_enabled (void) | |
14152 | { | |
fa3064dd YQ |
14153 | struct catch_syscall_inferior_data *inf_data |
14154 | = get_catch_syscall_inferior_data (current_inferior ()); | |
a96d9b2e | 14155 | |
fa3064dd | 14156 | return inf_data->total_syscalls_count != 0; |
a96d9b2e SDJ |
14157 | } |
14158 | ||
14159 | int | |
14160 | catching_syscall_number (int syscall_number) | |
14161 | { | |
14162 | struct breakpoint *bp; | |
14163 | ||
14164 | ALL_BREAKPOINTS (bp) | |
14165 | if (is_syscall_catchpoint_enabled (bp)) | |
14166 | { | |
be5c67c1 PA |
14167 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bp; |
14168 | ||
14169 | if (c->syscalls_to_be_caught) | |
a96d9b2e SDJ |
14170 | { |
14171 | int i, iter; | |
14172 | for (i = 0; | |
be5c67c1 | 14173 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
14174 | i++) |
14175 | if (syscall_number == iter) | |
14176 | return 1; | |
14177 | } | |
14178 | else | |
14179 | return 1; | |
14180 | } | |
14181 | ||
14182 | return 0; | |
14183 | } | |
14184 | ||
14185 | /* Complete syscall names. Used by "catch syscall". */ | |
14186 | static char ** | |
14187 | catch_syscall_completer (struct cmd_list_element *cmd, | |
14188 | char *text, char *word) | |
14189 | { | |
14190 | const char **list = get_syscall_names (); | |
c38eea1a MS |
14191 | char **retlist |
14192 | = (list == NULL) ? NULL : complete_on_enum (list, text, word); | |
cc59ec59 | 14193 | |
c38eea1a MS |
14194 | xfree (list); |
14195 | return retlist; | |
a96d9b2e SDJ |
14196 | } |
14197 | ||
1042e4c0 SS |
14198 | /* Tracepoint-specific operations. */ |
14199 | ||
14200 | /* Set tracepoint count to NUM. */ | |
14201 | static void | |
14202 | set_tracepoint_count (int num) | |
14203 | { | |
14204 | tracepoint_count = num; | |
4fa62494 | 14205 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
14206 | } |
14207 | ||
70221824 | 14208 | static void |
1042e4c0 SS |
14209 | trace_command (char *arg, int from_tty) |
14210 | { | |
8cdf0e15 VP |
14211 | if (create_breakpoint (get_current_arch (), |
14212 | arg, | |
14213 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b PA |
14214 | 0 /* tempflag */, |
14215 | bp_tracepoint /* type_wanted */, | |
8cdf0e15 VP |
14216 | 0 /* Ignore count */, |
14217 | pending_break_support, | |
348d480f | 14218 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 14219 | from_tty, |
84f4c1fe | 14220 | 1 /* enabled */, |
44f238bb | 14221 | 0 /* internal */, 0)) |
fd9b8c24 | 14222 | set_tracepoint_count (breakpoint_count); |
1042e4c0 SS |
14223 | } |
14224 | ||
70221824 | 14225 | static void |
7a697b8d SS |
14226 | ftrace_command (char *arg, int from_tty) |
14227 | { | |
8cdf0e15 VP |
14228 | if (create_breakpoint (get_current_arch (), |
14229 | arg, | |
14230 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b PA |
14231 | 0 /* tempflag */, |
14232 | bp_fast_tracepoint /* type_wanted */, | |
14233 | 0 /* Ignore count */, | |
14234 | pending_break_support, | |
348d480f | 14235 | &tracepoint_breakpoint_ops, |
0fb4aa4b | 14236 | from_tty, |
84f4c1fe | 14237 | 1 /* enabled */, |
44f238bb | 14238 | 0 /* internal */, 0)) |
0fb4aa4b PA |
14239 | set_tracepoint_count (breakpoint_count); |
14240 | } | |
14241 | ||
14242 | /* strace command implementation. Creates a static tracepoint. */ | |
14243 | ||
70221824 | 14244 | static void |
0fb4aa4b PA |
14245 | strace_command (char *arg, int from_tty) |
14246 | { | |
983af33b SDJ |
14247 | struct breakpoint_ops *ops; |
14248 | ||
14249 | /* Decide if we are dealing with a static tracepoint marker (`-m'), | |
14250 | or with a normal static tracepoint. */ | |
14251 | if (arg && strncmp (arg, "-m", 2) == 0 && isspace (arg[2])) | |
14252 | ops = &strace_marker_breakpoint_ops; | |
14253 | else | |
14254 | ops = &tracepoint_breakpoint_ops; | |
14255 | ||
0fb4aa4b PA |
14256 | if (create_breakpoint (get_current_arch (), |
14257 | arg, | |
14258 | NULL, 0, 1 /* parse arg */, | |
14259 | 0 /* tempflag */, | |
14260 | bp_static_tracepoint /* type_wanted */, | |
8cdf0e15 VP |
14261 | 0 /* Ignore count */, |
14262 | pending_break_support, | |
983af33b | 14263 | ops, |
8cdf0e15 | 14264 | from_tty, |
84f4c1fe | 14265 | 1 /* enabled */, |
44f238bb | 14266 | 0 /* internal */, 0)) |
fd9b8c24 | 14267 | set_tracepoint_count (breakpoint_count); |
7a697b8d SS |
14268 | } |
14269 | ||
409873ef SS |
14270 | /* Set up a fake reader function that gets command lines from a linked |
14271 | list that was acquired during tracepoint uploading. */ | |
14272 | ||
14273 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 14274 | static int next_cmd; |
409873ef SS |
14275 | |
14276 | static char * | |
14277 | read_uploaded_action (void) | |
14278 | { | |
14279 | char *rslt; | |
14280 | ||
3149d8c1 | 14281 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 14282 | |
3149d8c1 | 14283 | next_cmd++; |
409873ef SS |
14284 | |
14285 | return rslt; | |
14286 | } | |
14287 | ||
00bf0b85 SS |
14288 | /* Given information about a tracepoint as recorded on a target (which |
14289 | can be either a live system or a trace file), attempt to create an | |
14290 | equivalent GDB tracepoint. This is not a reliable process, since | |
14291 | the target does not necessarily have all the information used when | |
14292 | the tracepoint was originally defined. */ | |
14293 | ||
d9b3f62e | 14294 | struct tracepoint * |
00bf0b85 | 14295 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 14296 | { |
409873ef | 14297 | char *addr_str, small_buf[100]; |
d9b3f62e | 14298 | struct tracepoint *tp; |
fd9b8c24 | 14299 | |
409873ef SS |
14300 | if (utp->at_string) |
14301 | addr_str = utp->at_string; | |
14302 | else | |
14303 | { | |
14304 | /* In the absence of a source location, fall back to raw | |
14305 | address. Since there is no way to confirm that the address | |
14306 | means the same thing as when the trace was started, warn the | |
14307 | user. */ | |
3e43a32a MS |
14308 | warning (_("Uploaded tracepoint %d has no " |
14309 | "source location, using raw address"), | |
409873ef SS |
14310 | utp->number); |
14311 | sprintf (small_buf, "*%s", hex_string (utp->addr)); | |
14312 | addr_str = small_buf; | |
14313 | } | |
14314 | ||
14315 | /* There's not much we can do with a sequence of bytecodes. */ | |
14316 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
14317 | warning (_("Uploaded tracepoint %d condition " |
14318 | "has no source form, ignoring it"), | |
409873ef | 14319 | utp->number); |
d5551862 | 14320 | |
8cdf0e15 | 14321 | if (!create_breakpoint (get_current_arch (), |
409873ef SS |
14322 | addr_str, |
14323 | utp->cond_string, -1, 0 /* parse cond/thread */, | |
8cdf0e15 | 14324 | 0 /* tempflag */, |
0fb4aa4b | 14325 | utp->type /* type_wanted */, |
8cdf0e15 VP |
14326 | 0 /* Ignore count */, |
14327 | pending_break_support, | |
348d480f | 14328 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 14329 | 0 /* from_tty */, |
84f4c1fe | 14330 | utp->enabled /* enabled */, |
44f238bb PA |
14331 | 0 /* internal */, |
14332 | CREATE_BREAKPOINT_FLAGS_INSERTED)) | |
fd9b8c24 PA |
14333 | return NULL; |
14334 | ||
00bf0b85 SS |
14335 | set_tracepoint_count (breakpoint_count); |
14336 | ||
409873ef | 14337 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
14338 | tp = get_tracepoint (tracepoint_count); |
14339 | gdb_assert (tp != NULL); | |
d5551862 | 14340 | |
00bf0b85 SS |
14341 | if (utp->pass > 0) |
14342 | { | |
d9b3f62e | 14343 | sprintf (small_buf, "%d %d", utp->pass, tp->base.number); |
00bf0b85 | 14344 | |
409873ef | 14345 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
14346 | } |
14347 | ||
409873ef SS |
14348 | /* If we have uploaded versions of the original commands, set up a |
14349 | special-purpose "reader" function and call the usual command line | |
14350 | reader, then pass the result to the breakpoint command-setting | |
14351 | function. */ | |
3149d8c1 | 14352 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 14353 | { |
409873ef | 14354 | struct command_line *cmd_list; |
00bf0b85 | 14355 | |
409873ef | 14356 | this_utp = utp; |
3149d8c1 | 14357 | next_cmd = 0; |
d5551862 | 14358 | |
409873ef SS |
14359 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
14360 | ||
d9b3f62e | 14361 | breakpoint_set_commands (&tp->base, cmd_list); |
00bf0b85 | 14362 | } |
3149d8c1 SS |
14363 | else if (!VEC_empty (char_ptr, utp->actions) |
14364 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
14365 | warning (_("Uploaded tracepoint %d actions " |
14366 | "have no source form, ignoring them"), | |
409873ef | 14367 | utp->number); |
00bf0b85 | 14368 | |
f196051f SS |
14369 | /* Copy any status information that might be available. */ |
14370 | tp->base.hit_count = utp->hit_count; | |
14371 | tp->traceframe_usage = utp->traceframe_usage; | |
14372 | ||
00bf0b85 | 14373 | return tp; |
d9b3f62e | 14374 | } |
00bf0b85 | 14375 | |
1042e4c0 SS |
14376 | /* Print information on tracepoint number TPNUM_EXP, or all if |
14377 | omitted. */ | |
14378 | ||
14379 | static void | |
e5a67952 | 14380 | tracepoints_info (char *args, int from_tty) |
1042e4c0 | 14381 | { |
79a45e25 | 14382 | struct ui_out *uiout = current_uiout; |
e5a67952 | 14383 | int num_printed; |
1042e4c0 | 14384 | |
e5a67952 | 14385 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
14386 | |
14387 | if (num_printed == 0) | |
1042e4c0 | 14388 | { |
e5a67952 | 14389 | if (args == NULL || *args == '\0') |
d77f58be SS |
14390 | ui_out_message (uiout, 0, "No tracepoints.\n"); |
14391 | else | |
e5a67952 | 14392 | ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args); |
1042e4c0 | 14393 | } |
ad443146 SS |
14394 | |
14395 | default_collect_info (); | |
1042e4c0 SS |
14396 | } |
14397 | ||
4a64f543 | 14398 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
14399 | Not supported by all targets. */ |
14400 | static void | |
14401 | enable_trace_command (char *args, int from_tty) | |
14402 | { | |
14403 | enable_command (args, from_tty); | |
14404 | } | |
14405 | ||
4a64f543 | 14406 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
14407 | Not supported by all targets. */ |
14408 | static void | |
14409 | disable_trace_command (char *args, int from_tty) | |
14410 | { | |
14411 | disable_command (args, from_tty); | |
14412 | } | |
14413 | ||
4a64f543 | 14414 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 SS |
14415 | static void |
14416 | delete_trace_command (char *arg, int from_tty) | |
14417 | { | |
35df4500 | 14418 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
14419 | |
14420 | dont_repeat (); | |
14421 | ||
14422 | if (arg == 0) | |
14423 | { | |
14424 | int breaks_to_delete = 0; | |
14425 | ||
14426 | /* Delete all breakpoints if no argument. | |
14427 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
14428 | have to be deleted with an explicit breakpoint number |
14429 | argument. */ | |
1042e4c0 | 14430 | ALL_TRACEPOINTS (b) |
46c6471b | 14431 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
14432 | { |
14433 | breaks_to_delete = 1; | |
14434 | break; | |
14435 | } | |
1042e4c0 SS |
14436 | |
14437 | /* Ask user only if there are some breakpoints to delete. */ | |
14438 | if (!from_tty | |
14439 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
14440 | { | |
35df4500 | 14441 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 14442 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 14443 | delete_breakpoint (b); |
1042e4c0 SS |
14444 | } |
14445 | } | |
14446 | else | |
51be5b68 | 14447 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
1042e4c0 SS |
14448 | } |
14449 | ||
197f0a60 TT |
14450 | /* Helper function for trace_pass_command. */ |
14451 | ||
14452 | static void | |
d9b3f62e | 14453 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 14454 | { |
d9b3f62e PA |
14455 | tp->pass_count = count; |
14456 | observer_notify_tracepoint_modified (tp->base.number); | |
197f0a60 TT |
14457 | if (from_tty) |
14458 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
d9b3f62e | 14459 | tp->base.number, count); |
197f0a60 TT |
14460 | } |
14461 | ||
1042e4c0 SS |
14462 | /* Set passcount for tracepoint. |
14463 | ||
14464 | First command argument is passcount, second is tracepoint number. | |
14465 | If tracepoint number omitted, apply to most recently defined. | |
14466 | Also accepts special argument "all". */ | |
14467 | ||
14468 | static void | |
14469 | trace_pass_command (char *args, int from_tty) | |
14470 | { | |
d9b3f62e | 14471 | struct tracepoint *t1; |
1042e4c0 | 14472 | unsigned int count; |
1042e4c0 SS |
14473 | |
14474 | if (args == 0 || *args == 0) | |
3e43a32a MS |
14475 | error (_("passcount command requires an " |
14476 | "argument (count + optional TP num)")); | |
1042e4c0 | 14477 | |
4a64f543 | 14478 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 SS |
14479 | |
14480 | while (*args && isspace ((int) *args)) | |
14481 | args++; | |
14482 | ||
14483 | if (*args && strncasecmp (args, "all", 3) == 0) | |
14484 | { | |
d9b3f62e PA |
14485 | struct breakpoint *b; |
14486 | ||
1042e4c0 | 14487 | args += 3; /* Skip special argument "all". */ |
1042e4c0 SS |
14488 | if (*args) |
14489 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 14490 | |
d9b3f62e | 14491 | ALL_TRACEPOINTS (b) |
197f0a60 | 14492 | { |
d9b3f62e | 14493 | t1 = (struct tracepoint *) b; |
197f0a60 TT |
14494 | trace_pass_set_count (t1, count, from_tty); |
14495 | } | |
14496 | } | |
14497 | else if (*args == '\0') | |
1042e4c0 | 14498 | { |
197f0a60 | 14499 | t1 = get_tracepoint_by_number (&args, NULL, 1); |
1042e4c0 | 14500 | if (t1) |
197f0a60 TT |
14501 | trace_pass_set_count (t1, count, from_tty); |
14502 | } | |
14503 | else | |
14504 | { | |
14505 | struct get_number_or_range_state state; | |
14506 | ||
14507 | init_number_or_range (&state, args); | |
14508 | while (!state.finished) | |
1042e4c0 | 14509 | { |
197f0a60 TT |
14510 | t1 = get_tracepoint_by_number (&args, &state, 1); |
14511 | if (t1) | |
14512 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
14513 | } |
14514 | } | |
1042e4c0 SS |
14515 | } |
14516 | ||
d9b3f62e | 14517 | struct tracepoint * |
1042e4c0 SS |
14518 | get_tracepoint (int num) |
14519 | { | |
14520 | struct breakpoint *t; | |
14521 | ||
14522 | ALL_TRACEPOINTS (t) | |
14523 | if (t->number == num) | |
d9b3f62e | 14524 | return (struct tracepoint *) t; |
1042e4c0 SS |
14525 | |
14526 | return NULL; | |
14527 | } | |
14528 | ||
d5551862 SS |
14529 | /* Find the tracepoint with the given target-side number (which may be |
14530 | different from the tracepoint number after disconnecting and | |
14531 | reconnecting). */ | |
14532 | ||
d9b3f62e | 14533 | struct tracepoint * |
d5551862 SS |
14534 | get_tracepoint_by_number_on_target (int num) |
14535 | { | |
d9b3f62e | 14536 | struct breakpoint *b; |
d5551862 | 14537 | |
d9b3f62e PA |
14538 | ALL_TRACEPOINTS (b) |
14539 | { | |
14540 | struct tracepoint *t = (struct tracepoint *) b; | |
14541 | ||
14542 | if (t->number_on_target == num) | |
14543 | return t; | |
14544 | } | |
d5551862 SS |
14545 | |
14546 | return NULL; | |
14547 | } | |
14548 | ||
1042e4c0 | 14549 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 TT |
14550 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
14551 | If OPTIONAL_P is true, then if the argument is missing, the most | |
1042e4c0 | 14552 | recent tracepoint (tracepoint_count) is returned. */ |
d9b3f62e | 14553 | struct tracepoint * |
197f0a60 TT |
14554 | get_tracepoint_by_number (char **arg, |
14555 | struct get_number_or_range_state *state, | |
14556 | int optional_p) | |
1042e4c0 SS |
14557 | { |
14558 | extern int tracepoint_count; | |
14559 | struct breakpoint *t; | |
14560 | int tpnum; | |
14561 | char *instring = arg == NULL ? NULL : *arg; | |
14562 | ||
197f0a60 TT |
14563 | if (state) |
14564 | { | |
14565 | gdb_assert (!state->finished); | |
14566 | tpnum = get_number_or_range (state); | |
14567 | } | |
14568 | else if (arg == NULL || *arg == NULL || ! **arg) | |
1042e4c0 SS |
14569 | { |
14570 | if (optional_p) | |
14571 | tpnum = tracepoint_count; | |
14572 | else | |
14573 | error_no_arg (_("tracepoint number")); | |
14574 | } | |
14575 | else | |
197f0a60 | 14576 | tpnum = get_number (arg); |
1042e4c0 SS |
14577 | |
14578 | if (tpnum <= 0) | |
14579 | { | |
14580 | if (instring && *instring) | |
14581 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
14582 | instring); | |
14583 | else | |
3e43a32a MS |
14584 | printf_filtered (_("Tracepoint argument missing " |
14585 | "and no previous tracepoint\n")); | |
1042e4c0 SS |
14586 | return NULL; |
14587 | } | |
14588 | ||
14589 | ALL_TRACEPOINTS (t) | |
14590 | if (t->number == tpnum) | |
14591 | { | |
d9b3f62e | 14592 | return (struct tracepoint *) t; |
1042e4c0 SS |
14593 | } |
14594 | ||
1042e4c0 SS |
14595 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
14596 | return NULL; | |
14597 | } | |
14598 | ||
d9b3f62e PA |
14599 | void |
14600 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
14601 | { | |
14602 | if (b->thread != -1) | |
14603 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
14604 | ||
14605 | if (b->task != 0) | |
14606 | fprintf_unfiltered (fp, " task %d", b->task); | |
14607 | ||
14608 | fprintf_unfiltered (fp, "\n"); | |
14609 | } | |
14610 | ||
6149aea9 PA |
14611 | /* Save information on user settable breakpoints (watchpoints, etc) to |
14612 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
14613 | on each breakpoint and only include the ones for which it returns | |
14614 | non-zero. */ | |
14615 | ||
1042e4c0 | 14616 | static void |
6149aea9 PA |
14617 | save_breakpoints (char *filename, int from_tty, |
14618 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
14619 | { |
14620 | struct breakpoint *tp; | |
6149aea9 | 14621 | int any = 0; |
a7bdde9e | 14622 | char *pathname; |
1042e4c0 | 14623 | struct cleanup *cleanup; |
a7bdde9e | 14624 | struct ui_file *fp; |
6149aea9 | 14625 | int extra_trace_bits = 0; |
1042e4c0 | 14626 | |
6149aea9 PA |
14627 | if (filename == 0 || *filename == 0) |
14628 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
14629 | |
14630 | /* See if we have anything to save. */ | |
6149aea9 | 14631 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 14632 | { |
6149aea9 | 14633 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 14634 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
14635 | continue; |
14636 | ||
14637 | /* If we have a filter, only save the breakpoints it accepts. */ | |
14638 | if (filter && !filter (tp)) | |
14639 | continue; | |
14640 | ||
14641 | any = 1; | |
14642 | ||
14643 | if (is_tracepoint (tp)) | |
14644 | { | |
14645 | extra_trace_bits = 1; | |
14646 | ||
14647 | /* We can stop searching. */ | |
14648 | break; | |
14649 | } | |
1042e4c0 | 14650 | } |
6149aea9 PA |
14651 | |
14652 | if (!any) | |
1042e4c0 | 14653 | { |
6149aea9 | 14654 | warning (_("Nothing to save.")); |
1042e4c0 SS |
14655 | return; |
14656 | } | |
14657 | ||
6149aea9 | 14658 | pathname = tilde_expand (filename); |
1042e4c0 | 14659 | cleanup = make_cleanup (xfree, pathname); |
a7bdde9e | 14660 | fp = gdb_fopen (pathname, "w"); |
059fb39f | 14661 | if (!fp) |
6149aea9 PA |
14662 | error (_("Unable to open file '%s' for saving (%s)"), |
14663 | filename, safe_strerror (errno)); | |
a7bdde9e | 14664 | make_cleanup_ui_file_delete (fp); |
8bf6485c | 14665 | |
6149aea9 PA |
14666 | if (extra_trace_bits) |
14667 | save_trace_state_variables (fp); | |
8bf6485c | 14668 | |
6149aea9 | 14669 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 14670 | { |
6149aea9 | 14671 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 14672 | if (!user_breakpoint_p (tp)) |
6149aea9 | 14673 | continue; |
8bf6485c | 14674 | |
6149aea9 PA |
14675 | /* If we have a filter, only save the breakpoints it accepts. */ |
14676 | if (filter && !filter (tp)) | |
14677 | continue; | |
14678 | ||
348d480f | 14679 | tp->ops->print_recreate (tp, fp); |
1042e4c0 | 14680 | |
6149aea9 PA |
14681 | /* Note, we can't rely on tp->number for anything, as we can't |
14682 | assume the recreated breakpoint numbers will match. Use $bpnum | |
14683 | instead. */ | |
14684 | ||
14685 | if (tp->cond_string) | |
14686 | fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); | |
14687 | ||
14688 | if (tp->ignore_count) | |
14689 | fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); | |
14690 | ||
a7bdde9e | 14691 | if (tp->commands) |
1042e4c0 | 14692 | { |
a7bdde9e VP |
14693 | volatile struct gdb_exception ex; |
14694 | ||
6149aea9 | 14695 | fprintf_unfiltered (fp, " commands\n"); |
a7bdde9e | 14696 | |
79a45e25 | 14697 | ui_out_redirect (current_uiout, fp); |
14dba4b4 | 14698 | TRY_CATCH (ex, RETURN_MASK_ALL) |
1042e4c0 | 14699 | { |
79a45e25 | 14700 | print_command_lines (current_uiout, tp->commands->commands, 2); |
a7bdde9e | 14701 | } |
79a45e25 | 14702 | ui_out_redirect (current_uiout, NULL); |
1042e4c0 | 14703 | |
a7bdde9e VP |
14704 | if (ex.reason < 0) |
14705 | throw_exception (ex); | |
1042e4c0 | 14706 | |
a7bdde9e | 14707 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 | 14708 | } |
6149aea9 PA |
14709 | |
14710 | if (tp->enable_state == bp_disabled) | |
14711 | fprintf_unfiltered (fp, "disable\n"); | |
14712 | ||
14713 | /* If this is a multi-location breakpoint, check if the locations | |
14714 | should be individually disabled. Watchpoint locations are | |
14715 | special, and not user visible. */ | |
14716 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
14717 | { | |
14718 | struct bp_location *loc; | |
14719 | int n = 1; | |
14720 | ||
14721 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
14722 | if (!loc->enabled) | |
14723 | fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); | |
14724 | } | |
1042e4c0 | 14725 | } |
8bf6485c | 14726 | |
6149aea9 | 14727 | if (extra_trace_bits && *default_collect) |
8bf6485c SS |
14728 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); |
14729 | ||
1042e4c0 SS |
14730 | do_cleanups (cleanup); |
14731 | if (from_tty) | |
6149aea9 PA |
14732 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
14733 | } | |
14734 | ||
14735 | /* The `save breakpoints' command. */ | |
14736 | ||
14737 | static void | |
14738 | save_breakpoints_command (char *args, int from_tty) | |
14739 | { | |
14740 | save_breakpoints (args, from_tty, NULL); | |
14741 | } | |
14742 | ||
14743 | /* The `save tracepoints' command. */ | |
14744 | ||
14745 | static void | |
14746 | save_tracepoints_command (char *args, int from_tty) | |
14747 | { | |
14748 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
14749 | } |
14750 | ||
14751 | /* Create a vector of all tracepoints. */ | |
14752 | ||
14753 | VEC(breakpoint_p) * | |
eeae04df | 14754 | all_tracepoints (void) |
1042e4c0 SS |
14755 | { |
14756 | VEC(breakpoint_p) *tp_vec = 0; | |
14757 | struct breakpoint *tp; | |
14758 | ||
14759 | ALL_TRACEPOINTS (tp) | |
14760 | { | |
14761 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
14762 | } | |
14763 | ||
14764 | return tp_vec; | |
14765 | } | |
14766 | ||
c906108c | 14767 | \f |
4a64f543 MS |
14768 | /* This help string is used for the break, hbreak, tbreak and thbreak |
14769 | commands. It is defined as a macro to prevent duplication. | |
14770 | COMMAND should be a string constant containing the name of the | |
14771 | command. */ | |
31e2b00f AS |
14772 | #define BREAK_ARGS_HELP(command) \ |
14773 | command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\ | |
14774 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ | |
14775 | If a line number is specified, break at start of code for that line.\n\ | |
14776 | If a function is specified, break at start of code for that function.\n\ | |
14777 | If an address is specified, break at that exact address.\n\ | |
dc10affe PA |
14778 | With no LOCATION, uses current execution address of the selected\n\ |
14779 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
14780 | \n\ |
14781 | THREADNUM is the number from \"info threads\".\n\ | |
14782 | CONDITION is a boolean expression.\n\ | |
14783 | \n\ | |
d41c0fc8 PA |
14784 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
14785 | conditions are different.\n\ | |
31e2b00f AS |
14786 | \n\ |
14787 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
14788 | ||
44feb3ce TT |
14789 | /* List of subcommands for "catch". */ |
14790 | static struct cmd_list_element *catch_cmdlist; | |
14791 | ||
14792 | /* List of subcommands for "tcatch". */ | |
14793 | static struct cmd_list_element *tcatch_cmdlist; | |
14794 | ||
9ac4176b | 14795 | void |
44feb3ce TT |
14796 | add_catch_command (char *name, char *docstring, |
14797 | void (*sfunc) (char *args, int from_tty, | |
14798 | struct cmd_list_element *command), | |
a96d9b2e SDJ |
14799 | char **(*completer) (struct cmd_list_element *cmd, |
14800 | char *text, char *word), | |
44feb3ce TT |
14801 | void *user_data_catch, |
14802 | void *user_data_tcatch) | |
14803 | { | |
14804 | struct cmd_list_element *command; | |
14805 | ||
14806 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
14807 | &catch_cmdlist); | |
14808 | set_cmd_sfunc (command, sfunc); | |
14809 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 14810 | set_cmd_completer (command, completer); |
44feb3ce TT |
14811 | |
14812 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
14813 | &tcatch_cmdlist); | |
14814 | set_cmd_sfunc (command, sfunc); | |
14815 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 14816 | set_cmd_completer (command, completer); |
44feb3ce TT |
14817 | } |
14818 | ||
6c95b8df | 14819 | static void |
a79b8f6e | 14820 | clear_syscall_counts (struct inferior *inf) |
6c95b8df | 14821 | { |
fa3064dd YQ |
14822 | struct catch_syscall_inferior_data *inf_data |
14823 | = get_catch_syscall_inferior_data (inf); | |
14824 | ||
14825 | inf_data->total_syscalls_count = 0; | |
14826 | inf_data->any_syscall_count = 0; | |
14827 | VEC_free (int, inf_data->syscalls_counts); | |
6c95b8df PA |
14828 | } |
14829 | ||
6149aea9 PA |
14830 | static void |
14831 | save_command (char *arg, int from_tty) | |
14832 | { | |
3e43a32a MS |
14833 | printf_unfiltered (_("\"save\" must be followed by " |
14834 | "the name of a save subcommand.\n")); | |
6149aea9 PA |
14835 | help_list (save_cmdlist, "save ", -1, gdb_stdout); |
14836 | } | |
14837 | ||
84f4c1fe PM |
14838 | struct breakpoint * |
14839 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
14840 | void *data) | |
14841 | { | |
35df4500 | 14842 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 14843 | |
35df4500 | 14844 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
14845 | { |
14846 | if ((*callback) (b, data)) | |
14847 | return b; | |
14848 | } | |
14849 | ||
14850 | return NULL; | |
14851 | } | |
14852 | ||
0574c78f GB |
14853 | /* Zero if any of the breakpoint's locations could be a location where |
14854 | functions have been inlined, nonzero otherwise. */ | |
14855 | ||
14856 | static int | |
14857 | is_non_inline_function (struct breakpoint *b) | |
14858 | { | |
14859 | /* The shared library event breakpoint is set on the address of a | |
14860 | non-inline function. */ | |
14861 | if (b->type == bp_shlib_event) | |
14862 | return 1; | |
14863 | ||
14864 | return 0; | |
14865 | } | |
14866 | ||
14867 | /* Nonzero if the specified PC cannot be a location where functions | |
14868 | have been inlined. */ | |
14869 | ||
14870 | int | |
09ac7c10 TT |
14871 | pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc, |
14872 | const struct target_waitstatus *ws) | |
0574c78f GB |
14873 | { |
14874 | struct breakpoint *b; | |
14875 | struct bp_location *bl; | |
14876 | ||
14877 | ALL_BREAKPOINTS (b) | |
14878 | { | |
14879 | if (!is_non_inline_function (b)) | |
14880 | continue; | |
14881 | ||
14882 | for (bl = b->loc; bl != NULL; bl = bl->next) | |
14883 | { | |
14884 | if (!bl->shlib_disabled | |
09ac7c10 | 14885 | && bpstat_check_location (bl, aspace, pc, ws)) |
0574c78f GB |
14886 | return 1; |
14887 | } | |
14888 | } | |
14889 | ||
14890 | return 0; | |
14891 | } | |
14892 | ||
2060206e PA |
14893 | void |
14894 | initialize_breakpoint_ops (void) | |
14895 | { | |
14896 | static int initialized = 0; | |
14897 | ||
14898 | struct breakpoint_ops *ops; | |
14899 | ||
14900 | if (initialized) | |
14901 | return; | |
14902 | initialized = 1; | |
14903 | ||
14904 | /* The breakpoint_ops structure to be inherit by all kinds of | |
14905 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
14906 | internal and momentary breakpoints, etc.). */ | |
14907 | ops = &bkpt_base_breakpoint_ops; | |
14908 | *ops = base_breakpoint_ops; | |
14909 | ops->re_set = bkpt_re_set; | |
14910 | ops->insert_location = bkpt_insert_location; | |
14911 | ops->remove_location = bkpt_remove_location; | |
14912 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
983af33b SDJ |
14913 | ops->create_sals_from_address = bkpt_create_sals_from_address; |
14914 | ops->create_breakpoints_sal = bkpt_create_breakpoints_sal; | |
14915 | ops->decode_linespec = bkpt_decode_linespec; | |
2060206e PA |
14916 | |
14917 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
14918 | ops = &bkpt_breakpoint_ops; | |
14919 | *ops = bkpt_base_breakpoint_ops; | |
14920 | ops->re_set = bkpt_re_set; | |
14921 | ops->resources_needed = bkpt_resources_needed; | |
14922 | ops->print_it = bkpt_print_it; | |
14923 | ops->print_mention = bkpt_print_mention; | |
14924 | ops->print_recreate = bkpt_print_recreate; | |
14925 | ||
14926 | /* Ranged breakpoints. */ | |
14927 | ops = &ranged_breakpoint_ops; | |
14928 | *ops = bkpt_breakpoint_ops; | |
14929 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
14930 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
14931 | ops->print_it = print_it_ranged_breakpoint; | |
14932 | ops->print_one = print_one_ranged_breakpoint; | |
14933 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
14934 | ops->print_mention = print_mention_ranged_breakpoint; | |
14935 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
14936 | ||
14937 | /* Internal breakpoints. */ | |
14938 | ops = &internal_breakpoint_ops; | |
14939 | *ops = bkpt_base_breakpoint_ops; | |
14940 | ops->re_set = internal_bkpt_re_set; | |
14941 | ops->check_status = internal_bkpt_check_status; | |
14942 | ops->print_it = internal_bkpt_print_it; | |
14943 | ops->print_mention = internal_bkpt_print_mention; | |
14944 | ||
14945 | /* Momentary breakpoints. */ | |
14946 | ops = &momentary_breakpoint_ops; | |
14947 | *ops = bkpt_base_breakpoint_ops; | |
14948 | ops->re_set = momentary_bkpt_re_set; | |
14949 | ops->check_status = momentary_bkpt_check_status; | |
14950 | ops->print_it = momentary_bkpt_print_it; | |
14951 | ops->print_mention = momentary_bkpt_print_mention; | |
14952 | ||
14953 | /* GNU v3 exception catchpoints. */ | |
14954 | ops = &gnu_v3_exception_catchpoint_ops; | |
14955 | *ops = bkpt_breakpoint_ops; | |
14956 | ops->print_it = print_it_exception_catchpoint; | |
14957 | ops->print_one = print_one_exception_catchpoint; | |
14958 | ops->print_mention = print_mention_exception_catchpoint; | |
14959 | ops->print_recreate = print_recreate_exception_catchpoint; | |
14960 | ||
14961 | /* Watchpoints. */ | |
14962 | ops = &watchpoint_breakpoint_ops; | |
14963 | *ops = base_breakpoint_ops; | |
3a5c3e22 | 14964 | ops->dtor = dtor_watchpoint; |
2060206e PA |
14965 | ops->re_set = re_set_watchpoint; |
14966 | ops->insert_location = insert_watchpoint; | |
14967 | ops->remove_location = remove_watchpoint; | |
14968 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
14969 | ops->check_status = check_status_watchpoint; | |
14970 | ops->resources_needed = resources_needed_watchpoint; | |
14971 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
14972 | ops->print_it = print_it_watchpoint; | |
14973 | ops->print_mention = print_mention_watchpoint; | |
14974 | ops->print_recreate = print_recreate_watchpoint; | |
14975 | ||
14976 | /* Masked watchpoints. */ | |
14977 | ops = &masked_watchpoint_breakpoint_ops; | |
14978 | *ops = watchpoint_breakpoint_ops; | |
14979 | ops->insert_location = insert_masked_watchpoint; | |
14980 | ops->remove_location = remove_masked_watchpoint; | |
14981 | ops->resources_needed = resources_needed_masked_watchpoint; | |
14982 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
14983 | ops->print_it = print_it_masked_watchpoint; | |
14984 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
14985 | ops->print_mention = print_mention_masked_watchpoint; | |
14986 | ops->print_recreate = print_recreate_masked_watchpoint; | |
14987 | ||
14988 | /* Tracepoints. */ | |
14989 | ops = &tracepoint_breakpoint_ops; | |
14990 | *ops = base_breakpoint_ops; | |
14991 | ops->re_set = tracepoint_re_set; | |
14992 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
14993 | ops->print_one_detail = tracepoint_print_one_detail; | |
14994 | ops->print_mention = tracepoint_print_mention; | |
14995 | ops->print_recreate = tracepoint_print_recreate; | |
983af33b SDJ |
14996 | ops->create_sals_from_address = tracepoint_create_sals_from_address; |
14997 | ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal; | |
14998 | ops->decode_linespec = tracepoint_decode_linespec; | |
14999 | ||
15000 | /* Static tracepoints with marker (`-m'). */ | |
15001 | ops = &strace_marker_breakpoint_ops; | |
15002 | *ops = tracepoint_breakpoint_ops; | |
15003 | ops->create_sals_from_address = strace_marker_create_sals_from_address; | |
15004 | ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal; | |
15005 | ops->decode_linespec = strace_marker_decode_linespec; | |
2060206e PA |
15006 | |
15007 | /* Fork catchpoints. */ | |
15008 | ops = &catch_fork_breakpoint_ops; | |
15009 | *ops = base_breakpoint_ops; | |
15010 | ops->insert_location = insert_catch_fork; | |
15011 | ops->remove_location = remove_catch_fork; | |
15012 | ops->breakpoint_hit = breakpoint_hit_catch_fork; | |
15013 | ops->print_it = print_it_catch_fork; | |
15014 | ops->print_one = print_one_catch_fork; | |
15015 | ops->print_mention = print_mention_catch_fork; | |
15016 | ops->print_recreate = print_recreate_catch_fork; | |
15017 | ||
15018 | /* Vfork catchpoints. */ | |
15019 | ops = &catch_vfork_breakpoint_ops; | |
15020 | *ops = base_breakpoint_ops; | |
15021 | ops->insert_location = insert_catch_vfork; | |
15022 | ops->remove_location = remove_catch_vfork; | |
15023 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; | |
15024 | ops->print_it = print_it_catch_vfork; | |
15025 | ops->print_one = print_one_catch_vfork; | |
15026 | ops->print_mention = print_mention_catch_vfork; | |
15027 | ops->print_recreate = print_recreate_catch_vfork; | |
15028 | ||
15029 | /* Exec catchpoints. */ | |
15030 | ops = &catch_exec_breakpoint_ops; | |
15031 | *ops = base_breakpoint_ops; | |
15032 | ops->dtor = dtor_catch_exec; | |
15033 | ops->insert_location = insert_catch_exec; | |
15034 | ops->remove_location = remove_catch_exec; | |
15035 | ops->breakpoint_hit = breakpoint_hit_catch_exec; | |
15036 | ops->print_it = print_it_catch_exec; | |
15037 | ops->print_one = print_one_catch_exec; | |
15038 | ops->print_mention = print_mention_catch_exec; | |
15039 | ops->print_recreate = print_recreate_catch_exec; | |
15040 | ||
15041 | /* Syscall catchpoints. */ | |
15042 | ops = &catch_syscall_breakpoint_ops; | |
15043 | *ops = base_breakpoint_ops; | |
15044 | ops->dtor = dtor_catch_syscall; | |
15045 | ops->insert_location = insert_catch_syscall; | |
15046 | ops->remove_location = remove_catch_syscall; | |
15047 | ops->breakpoint_hit = breakpoint_hit_catch_syscall; | |
15048 | ops->print_it = print_it_catch_syscall; | |
15049 | ops->print_one = print_one_catch_syscall; | |
15050 | ops->print_mention = print_mention_catch_syscall; | |
15051 | ops->print_recreate = print_recreate_catch_syscall; | |
edcc5120 TT |
15052 | |
15053 | /* Solib-related catchpoints. */ | |
15054 | ops = &catch_solib_breakpoint_ops; | |
15055 | *ops = base_breakpoint_ops; | |
15056 | ops->dtor = dtor_catch_solib; | |
15057 | ops->insert_location = insert_catch_solib; | |
15058 | ops->remove_location = remove_catch_solib; | |
15059 | ops->breakpoint_hit = breakpoint_hit_catch_solib; | |
15060 | ops->check_status = check_status_catch_solib; | |
15061 | ops->print_it = print_it_catch_solib; | |
15062 | ops->print_one = print_one_catch_solib; | |
15063 | ops->print_mention = print_mention_catch_solib; | |
15064 | ops->print_recreate = print_recreate_catch_solib; | |
2060206e PA |
15065 | } |
15066 | ||
c906108c | 15067 | void |
fba45db2 | 15068 | _initialize_breakpoint (void) |
c906108c SS |
15069 | { |
15070 | struct cmd_list_element *c; | |
15071 | ||
2060206e PA |
15072 | initialize_breakpoint_ops (); |
15073 | ||
84acb35a | 15074 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
6c95b8df | 15075 | observer_attach_inferior_exit (clear_syscall_counts); |
1f3b5d1b | 15076 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 15077 | |
17450429 PP |
15078 | breakpoint_objfile_key = register_objfile_data (); |
15079 | ||
fa3064dd YQ |
15080 | catch_syscall_inferior_data |
15081 | = register_inferior_data_with_cleanup (catch_syscall_inferior_data_cleanup); | |
15082 | ||
c906108c SS |
15083 | breakpoint_chain = 0; |
15084 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
15085 | before a breakpoint is set. */ | |
15086 | breakpoint_count = 0; | |
15087 | ||
1042e4c0 SS |
15088 | tracepoint_count = 0; |
15089 | ||
1bedd215 AC |
15090 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
15091 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
15092 | Usage is `ignore N COUNT'.")); | |
c906108c | 15093 | if (xdb_commands) |
c5aa993b | 15094 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 15095 | |
1bedd215 AC |
15096 | add_com ("commands", class_breakpoint, commands_command, _("\ |
15097 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
15098 | Give breakpoint number as argument after \"commands\".\n\ |
15099 | With no argument, the targeted breakpoint is the last one set.\n\ | |
15100 | The commands themselves follow starting on the next line.\n\ | |
15101 | Type a line containing \"end\" to indicate the end of them.\n\ | |
15102 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 15103 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 15104 | |
1bedd215 AC |
15105 | add_com ("condition", class_breakpoint, condition_command, _("\ |
15106 | Specify breakpoint number N to break only if COND is true.\n\ | |
c906108c | 15107 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 15108 | expression to be evaluated whenever breakpoint N is reached.")); |
c906108c | 15109 | |
1bedd215 | 15110 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 15111 | Set a temporary breakpoint.\n\ |
c906108c SS |
15112 | Like \"break\" except the breakpoint is only temporary,\n\ |
15113 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
15114 | by using \"enable delete\" on the breakpoint number.\n\ |
15115 | \n" | |
15116 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 15117 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 15118 | |
1bedd215 | 15119 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 15120 | Set a hardware assisted breakpoint.\n\ |
c906108c | 15121 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
15122 | some target hardware may not have this support.\n\ |
15123 | \n" | |
15124 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 15125 | set_cmd_completer (c, location_completer); |
c906108c | 15126 | |
1bedd215 | 15127 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 15128 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 15129 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
15130 | so it will be deleted when hit.\n\ |
15131 | \n" | |
15132 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 15133 | set_cmd_completer (c, location_completer); |
c906108c | 15134 | |
1bedd215 AC |
15135 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
15136 | Enable some breakpoints.\n\ | |
c906108c SS |
15137 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
15138 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
15139 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 15140 | With a subcommand you can enable temporarily."), |
c906108c SS |
15141 | &enablelist, "enable ", 1, &cmdlist); |
15142 | if (xdb_commands) | |
1bedd215 AC |
15143 | add_com ("ab", class_breakpoint, enable_command, _("\ |
15144 | Enable some breakpoints.\n\ | |
c906108c SS |
15145 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
15146 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
15147 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 15148 | With a subcommand you can enable temporarily.")); |
c906108c SS |
15149 | |
15150 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
15151 | ||
84951ab5 | 15152 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 15153 | Enable some breakpoints.\n\ |
c906108c SS |
15154 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
15155 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 15156 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 15157 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 15158 | |
1a966eab AC |
15159 | add_cmd ("once", no_class, enable_once_command, _("\ |
15160 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
15161 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
15162 | &enablebreaklist); |
15163 | ||
1a966eab AC |
15164 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
15165 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
15166 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
15167 | &enablebreaklist); |
15168 | ||
816338b5 SS |
15169 | add_cmd ("count", no_class, enable_count_command, _("\ |
15170 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
15171 | If a breakpoint is hit while enabled in this fashion,\n\ | |
15172 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
15173 | &enablebreaklist); | |
15174 | ||
1a966eab AC |
15175 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
15176 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
15177 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
15178 | &enablelist); |
15179 | ||
1a966eab AC |
15180 | add_cmd ("once", no_class, enable_once_command, _("\ |
15181 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
15182 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
816338b5 SS |
15183 | &enablelist); |
15184 | ||
15185 | add_cmd ("count", no_class, enable_count_command, _("\ | |
15186 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
15187 | If a breakpoint is hit while enabled in this fashion,\n\ | |
15188 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
c906108c SS |
15189 | &enablelist); |
15190 | ||
1bedd215 AC |
15191 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
15192 | Disable some breakpoints.\n\ | |
c906108c SS |
15193 | Arguments are breakpoint numbers with spaces in between.\n\ |
15194 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 15195 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
c906108c SS |
15196 | &disablelist, "disable ", 1, &cmdlist); |
15197 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
15198 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
15199 | if (xdb_commands) | |
1bedd215 AC |
15200 | add_com ("sb", class_breakpoint, disable_command, _("\ |
15201 | Disable some breakpoints.\n\ | |
c906108c SS |
15202 | Arguments are breakpoint numbers with spaces in between.\n\ |
15203 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 15204 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.")); |
c906108c | 15205 | |
1a966eab AC |
15206 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
15207 | Disable some breakpoints.\n\ | |
c906108c SS |
15208 | Arguments are breakpoint numbers with spaces in between.\n\ |
15209 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 15210 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 15211 | This command may be abbreviated \"disable\"."), |
c906108c SS |
15212 | &disablelist); |
15213 | ||
1bedd215 AC |
15214 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
15215 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
15216 | Arguments are breakpoint numbers with spaces in between.\n\ |
15217 | To delete all breakpoints, give no argument.\n\ | |
15218 | \n\ | |
15219 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 15220 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
15221 | &deletelist, "delete ", 1, &cmdlist); |
15222 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 15223 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 15224 | if (xdb_commands) |
1bedd215 AC |
15225 | add_com ("db", class_breakpoint, delete_command, _("\ |
15226 | Delete some breakpoints.\n\ | |
c906108c | 15227 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 15228 | To delete all breakpoints, give no argument.\n")); |
c906108c | 15229 | |
1a966eab AC |
15230 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
15231 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
15232 | Arguments are breakpoint numbers with spaces in between.\n\ |
15233 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 15234 | This command may be abbreviated \"delete\"."), |
c906108c SS |
15235 | &deletelist); |
15236 | ||
1bedd215 AC |
15237 | add_com ("clear", class_breakpoint, clear_command, _("\ |
15238 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
15239 | Argument may be line number, function name, or \"*\" and an address.\n\ |
15240 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
15241 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
15242 | If an address is specified, breakpoints at that address are cleared.\n\ |
15243 | \n\ | |
15244 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
15245 | is executing in.\n\ |
15246 | \n\ | |
1bedd215 | 15247 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 15248 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 15249 | |
1bedd215 | 15250 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
15251 | Set breakpoint at specified line or function.\n" |
15252 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 15253 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 15254 | |
c906108c SS |
15255 | add_com_alias ("b", "break", class_run, 1); |
15256 | add_com_alias ("br", "break", class_run, 1); | |
15257 | add_com_alias ("bre", "break", class_run, 1); | |
15258 | add_com_alias ("brea", "break", class_run, 1); | |
15259 | ||
7681d515 PM |
15260 | if (xdb_commands) |
15261 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
15262 | |
15263 | if (dbx_commands) | |
15264 | { | |
1bedd215 AC |
15265 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
15266 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
15267 | &stoplist, "stop ", 1, &cmdlist); |
15268 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 15269 | _("Break in function or address."), &stoplist); |
c5aa993b | 15270 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 15271 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
15272 | add_com ("status", class_info, breakpoints_info, _("\ |
15273 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
15274 | The \"Type\" column indicates one of:\n\ |
15275 | \tbreakpoint - normal breakpoint\n\ | |
15276 | \twatchpoint - watchpoint\n\ | |
15277 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
15278 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
15279 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
15280 | address and file/line number respectively.\n\ |
15281 | \n\ | |
15282 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15283 | are set to the address of the last breakpoint listed unless the command\n\ |
15284 | is prefixed with \"server \".\n\n\ | |
c906108c | 15285 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 15286 | breakpoint set.")); |
c906108c SS |
15287 | } |
15288 | ||
1bedd215 | 15289 | add_info ("breakpoints", breakpoints_info, _("\ |
e5a67952 | 15290 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
15291 | The \"Type\" column indicates one of:\n\ |
15292 | \tbreakpoint - normal breakpoint\n\ | |
15293 | \twatchpoint - watchpoint\n\ | |
15294 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
15295 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
15296 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
15297 | address and file/line number respectively.\n\ |
15298 | \n\ | |
15299 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15300 | are set to the address of the last breakpoint listed unless the command\n\ |
15301 | is prefixed with \"server \".\n\n\ | |
c906108c | 15302 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 15303 | breakpoint set.")); |
c906108c | 15304 | |
6b04bdb7 MS |
15305 | add_info_alias ("b", "breakpoints", 1); |
15306 | ||
c906108c | 15307 | if (xdb_commands) |
1bedd215 AC |
15308 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
15309 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
15310 | The \"Type\" column indicates one of:\n\ |
15311 | \tbreakpoint - normal breakpoint\n\ | |
15312 | \twatchpoint - watchpoint\n\ | |
15313 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
15314 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
15315 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
15316 | address and file/line number respectively.\n\ |
15317 | \n\ | |
15318 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15319 | are set to the address of the last breakpoint listed unless the command\n\ |
15320 | is prefixed with \"server \".\n\n\ | |
c906108c | 15321 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 15322 | breakpoint set.")); |
c906108c | 15323 | |
1a966eab AC |
15324 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
15325 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
15326 | The \"Type\" column indicates one of:\n\ |
15327 | \tbreakpoint - normal breakpoint\n\ | |
15328 | \twatchpoint - watchpoint\n\ | |
15329 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
15330 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
15331 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
15332 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
15333 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
15334 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
15335 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
15336 | address and file/line number respectively.\n\ |
15337 | \n\ | |
15338 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15339 | are set to the address of the last breakpoint listed unless the command\n\ |
15340 | is prefixed with \"server \".\n\n\ | |
c906108c | 15341 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 15342 | breakpoint set."), |
c906108c SS |
15343 | &maintenanceinfolist); |
15344 | ||
44feb3ce TT |
15345 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
15346 | Set catchpoints to catch events."), | |
15347 | &catch_cmdlist, "catch ", | |
15348 | 0/*allow-unknown*/, &cmdlist); | |
15349 | ||
15350 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
15351 | Set temporary catchpoints to catch events."), | |
15352 | &tcatch_cmdlist, "tcatch ", | |
15353 | 0/*allow-unknown*/, &cmdlist); | |
15354 | ||
15355 | /* Add catch and tcatch sub-commands. */ | |
15356 | add_catch_command ("catch", _("\ | |
88e7d25d | 15357 | Catch an exception, when caught."), |
44feb3ce | 15358 | catch_catch_command, |
a96d9b2e | 15359 | NULL, |
44feb3ce TT |
15360 | CATCH_PERMANENT, |
15361 | CATCH_TEMPORARY); | |
15362 | add_catch_command ("throw", _("\ | |
88e7d25d | 15363 | Catch an exception, when thrown."), |
44feb3ce | 15364 | catch_throw_command, |
a96d9b2e | 15365 | NULL, |
44feb3ce TT |
15366 | CATCH_PERMANENT, |
15367 | CATCH_TEMPORARY); | |
15368 | add_catch_command ("fork", _("Catch calls to fork."), | |
15369 | catch_fork_command_1, | |
a96d9b2e | 15370 | NULL, |
44feb3ce TT |
15371 | (void *) (uintptr_t) catch_fork_permanent, |
15372 | (void *) (uintptr_t) catch_fork_temporary); | |
15373 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
15374 | catch_fork_command_1, | |
a96d9b2e | 15375 | NULL, |
44feb3ce TT |
15376 | (void *) (uintptr_t) catch_vfork_permanent, |
15377 | (void *) (uintptr_t) catch_vfork_temporary); | |
15378 | add_catch_command ("exec", _("Catch calls to exec."), | |
15379 | catch_exec_command_1, | |
a96d9b2e SDJ |
15380 | NULL, |
15381 | CATCH_PERMANENT, | |
15382 | CATCH_TEMPORARY); | |
edcc5120 TT |
15383 | add_catch_command ("load", _("Catch loads of shared libraries.\n\ |
15384 | Usage: catch load [REGEX]\n\ | |
15385 | If REGEX is given, only stop for libraries matching the regular expression."), | |
15386 | catch_load_command_1, | |
15387 | NULL, | |
15388 | CATCH_PERMANENT, | |
15389 | CATCH_TEMPORARY); | |
15390 | add_catch_command ("unload", _("Catch unloads of shared libraries.\n\ | |
15391 | Usage: catch unload [REGEX]\n\ | |
15392 | If REGEX is given, only stop for libraries matching the regular expression."), | |
15393 | catch_unload_command_1, | |
15394 | NULL, | |
15395 | CATCH_PERMANENT, | |
15396 | CATCH_TEMPORARY); | |
a96d9b2e SDJ |
15397 | add_catch_command ("syscall", _("\ |
15398 | Catch system calls by their names and/or numbers.\n\ | |
15399 | Arguments say which system calls to catch. If no arguments\n\ | |
15400 | are given, every system call will be caught.\n\ | |
15401 | Arguments, if given, should be one or more system call names\n\ | |
15402 | (if your system supports that), or system call numbers."), | |
15403 | catch_syscall_command_1, | |
15404 | catch_syscall_completer, | |
44feb3ce TT |
15405 | CATCH_PERMANENT, |
15406 | CATCH_TEMPORARY); | |
c5aa993b | 15407 | |
1bedd215 AC |
15408 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
15409 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 15410 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 15411 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
15412 | an expression changes.\n\ |
15413 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
15414 | the memory to which it refers.")); | |
65d12d83 | 15415 | set_cmd_completer (c, expression_completer); |
c906108c | 15416 | |
1bedd215 AC |
15417 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
15418 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 15419 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 15420 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
15421 | an expression is read.\n\ |
15422 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
15423 | the memory to which it refers.")); | |
65d12d83 | 15424 | set_cmd_completer (c, expression_completer); |
c906108c | 15425 | |
1bedd215 AC |
15426 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
15427 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 15428 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 15429 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
15430 | an expression is either read or written.\n\ |
15431 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
15432 | the memory to which it refers.")); | |
65d12d83 | 15433 | set_cmd_completer (c, expression_completer); |
c906108c | 15434 | |
d77f58be | 15435 | add_info ("watchpoints", watchpoints_info, _("\ |
e5a67952 | 15436 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 15437 | |
920d2a44 AC |
15438 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
15439 | respond to changes - contrary to the description. */ | |
85c07804 AC |
15440 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
15441 | &can_use_hw_watchpoints, _("\ | |
15442 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
15443 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
15444 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
15445 | such is available. (However, any hardware watchpoints that were\n\ | |
15446 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
15447 | hardware.)"), |
15448 | NULL, | |
920d2a44 | 15449 | show_can_use_hw_watchpoints, |
85c07804 | 15450 | &setlist, &showlist); |
c906108c SS |
15451 | |
15452 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 15453 | |
1042e4c0 SS |
15454 | /* Tracepoint manipulation commands. */ |
15455 | ||
15456 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
15457 | Set a tracepoint at specified line or function.\n\ | |
15458 | \n" | |
15459 | BREAK_ARGS_HELP ("trace") "\n\ | |
15460 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
15461 | set_cmd_completer (c, location_completer); | |
15462 | ||
15463 | add_com_alias ("tp", "trace", class_alias, 0); | |
15464 | add_com_alias ("tr", "trace", class_alias, 1); | |
15465 | add_com_alias ("tra", "trace", class_alias, 1); | |
15466 | add_com_alias ("trac", "trace", class_alias, 1); | |
15467 | ||
7a697b8d SS |
15468 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
15469 | Set a fast tracepoint at specified line or function.\n\ | |
15470 | \n" | |
15471 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
15472 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
15473 | set_cmd_completer (c, location_completer); | |
15474 | ||
0fb4aa4b PA |
15475 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
15476 | Set a static tracepoint at specified line, function or marker.\n\ | |
15477 | \n\ | |
15478 | strace [LOCATION] [if CONDITION]\n\ | |
15479 | LOCATION may be a line number, function name, \"*\" and an address,\n\ | |
15480 | or -m MARKER_ID.\n\ | |
15481 | If a line number is specified, probe the marker at start of code\n\ | |
15482 | for that line. If a function is specified, probe the marker at start\n\ | |
15483 | of code for that function. If an address is specified, probe the marker\n\ | |
15484 | at that exact address. If a marker id is specified, probe the marker\n\ | |
15485 | with that name. With no LOCATION, uses current execution address of\n\ | |
15486 | the selected stack frame.\n\ | |
15487 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ | |
15488 | This collects arbitrary user data passed in the probe point call to the\n\ | |
15489 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
15490 | by printing the $_sdata variable like any other convenience variable.\n\ | |
15491 | \n\ | |
15492 | CONDITION is a boolean expression.\n\ | |
15493 | \n\ | |
d41c0fc8 PA |
15494 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
15495 | conditions are different.\n\ | |
0fb4aa4b PA |
15496 | \n\ |
15497 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
15498 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
15499 | set_cmd_completer (c, location_completer); | |
15500 | ||
1042e4c0 | 15501 | add_info ("tracepoints", tracepoints_info, _("\ |
e5a67952 | 15502 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
15503 | Convenience variable \"$tpnum\" contains the number of the\n\ |
15504 | last tracepoint set.")); | |
15505 | ||
15506 | add_info_alias ("tp", "tracepoints", 1); | |
15507 | ||
15508 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
15509 | Delete specified tracepoints.\n\ | |
15510 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
15511 | No argument means delete all tracepoints."), | |
15512 | &deletelist); | |
15513 | ||
15514 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
15515 | Disable specified tracepoints.\n\ | |
15516 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
15517 | No argument means disable all tracepoints."), | |
15518 | &disablelist); | |
15519 | deprecate_cmd (c, "disable"); | |
15520 | ||
15521 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
15522 | Enable specified tracepoints.\n\ | |
15523 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
15524 | No argument means enable all tracepoints."), | |
15525 | &enablelist); | |
15526 | deprecate_cmd (c, "enable"); | |
15527 | ||
15528 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
15529 | Set the passcount for a tracepoint.\n\ | |
15530 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
15531 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
15532 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
15533 | ||
6149aea9 PA |
15534 | add_prefix_cmd ("save", class_breakpoint, save_command, |
15535 | _("Save breakpoint definitions as a script."), | |
15536 | &save_cmdlist, "save ", | |
15537 | 0/*allow-unknown*/, &cmdlist); | |
15538 | ||
15539 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
15540 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 15541 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
15542 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
15543 | session to restore them."), | |
15544 | &save_cmdlist); | |
15545 | set_cmd_completer (c, filename_completer); | |
15546 | ||
15547 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 15548 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
15549 | Use the 'source' command in another debug session to restore them."), |
15550 | &save_cmdlist); | |
1042e4c0 SS |
15551 | set_cmd_completer (c, filename_completer); |
15552 | ||
6149aea9 PA |
15553 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
15554 | deprecate_cmd (c, "save tracepoints"); | |
15555 | ||
1bedd215 | 15556 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
15557 | Breakpoint specific settings\n\ |
15558 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 15559 | pending breakpoint behavior"), |
fa8d40ab JJ |
15560 | &breakpoint_set_cmdlist, "set breakpoint ", |
15561 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 15562 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
15563 | Breakpoint specific settings\n\ |
15564 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 15565 | pending breakpoint behavior"), |
fa8d40ab JJ |
15566 | &breakpoint_show_cmdlist, "show breakpoint ", |
15567 | 0/*allow-unknown*/, &showlist); | |
15568 | ||
7915a72c AC |
15569 | add_setshow_auto_boolean_cmd ("pending", no_class, |
15570 | &pending_break_support, _("\ | |
15571 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
15572 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
15573 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
15574 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
15575 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 15576 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 15577 | NULL, |
920d2a44 | 15578 | show_pending_break_support, |
6e1d7d6c AC |
15579 | &breakpoint_set_cmdlist, |
15580 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
15581 | |
15582 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
15583 | |
15584 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
15585 | &automatic_hardware_breakpoints, _("\ | |
15586 | Set automatic usage of hardware breakpoints."), _("\ | |
15587 | Show automatic usage of hardware breakpoints."), _("\ | |
15588 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
15589 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
15590 | a warning will be emitted for such breakpoints."), | |
15591 | NULL, | |
15592 | show_automatic_hardware_breakpoints, | |
15593 | &breakpoint_set_cmdlist, | |
15594 | &breakpoint_show_cmdlist); | |
74960c60 | 15595 | |
33e5cbd6 PA |
15596 | add_setshow_enum_cmd ("always-inserted", class_support, |
15597 | always_inserted_enums, &always_inserted_mode, _("\ | |
74960c60 VP |
15598 | Set mode for inserting breakpoints."), _("\ |
15599 | Show mode for inserting breakpoints."), _("\ | |
33e5cbd6 PA |
15600 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
15601 | resumed, and removed when execution stops. When this mode is on,\n\ | |
15602 | breakpoints are inserted immediately and removed only when the user\n\ | |
15603 | deletes the breakpoint. When this mode is auto (which is the default),\n\ | |
15604 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ | |
15605 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ | |
15606 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ | |
15607 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), | |
74960c60 VP |
15608 | NULL, |
15609 | &show_always_inserted_mode, | |
15610 | &breakpoint_set_cmdlist, | |
15611 | &breakpoint_show_cmdlist); | |
f1310107 | 15612 | |
b775012e LM |
15613 | add_setshow_enum_cmd ("condition-evaluation", class_breakpoint, |
15614 | condition_evaluation_enums, | |
15615 | &condition_evaluation_mode_1, _("\ | |
15616 | Set mode of breakpoint condition evaluation."), _("\ | |
15617 | Show mode of breakpoint condition evaluation."), _("\ | |
d1cda5d9 | 15618 | When this is set to \"host\", breakpoint conditions will be\n\ |
b775012e LM |
15619 | evaluated on the host's side by GDB. When it is set to \"target\",\n\ |
15620 | breakpoint conditions will be downloaded to the target (if the target\n\ | |
15621 | supports such feature) and conditions will be evaluated on the target's side.\n\ | |
15622 | If this is set to \"auto\" (default), this will be automatically set to\n\ | |
15623 | \"target\" if it supports condition evaluation, otherwise it will\n\ | |
15624 | be set to \"gdb\""), | |
15625 | &set_condition_evaluation_mode, | |
15626 | &show_condition_evaluation_mode, | |
15627 | &breakpoint_set_cmdlist, | |
15628 | &breakpoint_show_cmdlist); | |
15629 | ||
f1310107 TJB |
15630 | add_com ("break-range", class_breakpoint, break_range_command, _("\ |
15631 | Set a breakpoint for an address range.\n\ | |
15632 | break-range START-LOCATION, END-LOCATION\n\ | |
15633 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
15634 | LINENUM, for that line in the current file,\n\ | |
15635 | FILE:LINENUM, for that line in that file,\n\ | |
15636 | +OFFSET, for that number of lines after the current line\n\ | |
15637 | or the start of the range\n\ | |
15638 | FUNCTION, for the first line in that function,\n\ | |
15639 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
15640 | *ADDRESS, for the instruction at that address.\n\ | |
15641 | \n\ | |
15642 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
15643 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
15644 | range (including START-LOCATION and END-LOCATION).")); | |
15645 | ||
765dc015 | 15646 | automatic_hardware_breakpoints = 1; |
f3b1572e PA |
15647 | |
15648 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
c906108c | 15649 | } |