Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Everything about breakpoints, for GDB. |
8926118c | 2 | |
0b302171 | 3 | Copyright (C) 1986-2012 Free Software Foundation, Inc. |
c906108c | 4 | |
c5aa993b | 5 | This file is part of GDB. |
c906108c | 6 | |
c5aa993b JM |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 10 | (at your option) any later version. |
c906108c | 11 | |
c5aa993b JM |
12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
c906108c | 16 | |
c5aa993b | 17 | You should have received a copy of the GNU General Public License |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
19 | |
20 | #include "defs.h" | |
a6d9a66e | 21 | #include "arch-utils.h" |
c906108c | 22 | #include <ctype.h> |
776592bf | 23 | #include "hashtab.h" |
c906108c SS |
24 | #include "symtab.h" |
25 | #include "frame.h" | |
26 | #include "breakpoint.h" | |
1042e4c0 | 27 | #include "tracepoint.h" |
c906108c SS |
28 | #include "gdbtypes.h" |
29 | #include "expression.h" | |
30 | #include "gdbcore.h" | |
31 | #include "gdbcmd.h" | |
32 | #include "value.h" | |
33 | #include "command.h" | |
34 | #include "inferior.h" | |
35 | #include "gdbthread.h" | |
36 | #include "target.h" | |
37 | #include "language.h" | |
38 | #include "gdb_string.h" | |
50f182aa | 39 | #include "gdb-demangle.h" |
0ba1096a | 40 | #include "filenames.h" |
c906108c SS |
41 | #include "annotate.h" |
42 | #include "symfile.h" | |
43 | #include "objfiles.h" | |
0378c332 | 44 | #include "source.h" |
c5f0f3d0 | 45 | #include "linespec.h" |
c94fdfd0 | 46 | #include "completer.h" |
5b7f31a4 | 47 | #include "gdb.h" |
8b93c638 | 48 | #include "ui-out.h" |
e1507482 | 49 | #include "cli/cli-script.h" |
0225421b | 50 | #include "gdb_assert.h" |
fe898f56 | 51 | #include "block.h" |
a77053c2 | 52 | #include "solib.h" |
84acb35a JJ |
53 | #include "solist.h" |
54 | #include "observer.h" | |
60250e8b | 55 | #include "exceptions.h" |
765dc015 | 56 | #include "memattr.h" |
f7f9143b | 57 | #include "ada-lang.h" |
d1aa2f50 | 58 | #include "top.h" |
79a45b7d | 59 | #include "valprint.h" |
4efc6507 | 60 | #include "jit.h" |
a96d9b2e | 61 | #include "xml-syscall.h" |
65d79d4b | 62 | #include "parser-defs.h" |
e9cafbcc | 63 | #include "cli/cli-utils.h" |
be34f849 | 64 | #include "continuations.h" |
1bfeeb0f JL |
65 | #include "stack.h" |
66 | #include "skip.h" | |
049e32d3 | 67 | #include "record.h" |
edcc5120 | 68 | #include "gdb_regex.h" |
b775012e | 69 | #include "ax-gdb.h" |
c906108c | 70 | |
1042e4c0 SS |
71 | /* readline include files */ |
72 | #include "readline/readline.h" | |
73 | #include "readline/history.h" | |
74 | ||
75 | /* readline defines this. */ | |
76 | #undef savestring | |
77 | ||
034dad6f | 78 | #include "mi/mi-common.h" |
7371cf6d | 79 | #include "python/python.h" |
104c1213 | 80 | |
4a64f543 | 81 | /* Prototypes for local functions. */ |
c906108c | 82 | |
a14ed312 | 83 | static void enable_delete_command (char *, int); |
c906108c | 84 | |
a14ed312 | 85 | static void enable_once_command (char *, int); |
c906108c | 86 | |
816338b5 SS |
87 | static void enable_count_command (char *, int); |
88 | ||
a14ed312 | 89 | static void disable_command (char *, int); |
c906108c | 90 | |
a14ed312 | 91 | static void enable_command (char *, int); |
c906108c | 92 | |
95a42b64 TT |
93 | static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *, |
94 | void *), | |
95 | void *); | |
c906108c | 96 | |
a14ed312 | 97 | static void ignore_command (char *, int); |
c906108c | 98 | |
4efb68b1 | 99 | static int breakpoint_re_set_one (void *); |
c906108c | 100 | |
348d480f PA |
101 | static void breakpoint_re_set_default (struct breakpoint *); |
102 | ||
983af33b SDJ |
103 | static void create_sals_from_address_default (char **, |
104 | struct linespec_result *, | |
105 | enum bptype, char *, | |
106 | char **); | |
107 | ||
108 | static void create_breakpoints_sal_default (struct gdbarch *, | |
109 | struct linespec_result *, | |
110 | struct linespec_sals *, | |
111 | char *, enum bptype, | |
112 | enum bpdisp, int, int, | |
113 | int, | |
114 | const struct breakpoint_ops *, | |
44f238bb | 115 | int, int, int, unsigned); |
983af33b SDJ |
116 | |
117 | static void decode_linespec_default (struct breakpoint *, char **, | |
118 | struct symtabs_and_lines *); | |
119 | ||
a14ed312 | 120 | static void clear_command (char *, int); |
c906108c | 121 | |
a14ed312 | 122 | static void catch_command (char *, int); |
c906108c | 123 | |
a9634178 | 124 | static int can_use_hardware_watchpoint (struct value *); |
c906108c | 125 | |
98deb0da | 126 | static void break_command_1 (char *, int, int); |
c906108c | 127 | |
a14ed312 | 128 | static void mention (struct breakpoint *); |
c906108c | 129 | |
348d480f PA |
130 | static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *, |
131 | enum bptype, | |
c0a91b2b | 132 | const struct breakpoint_ops *); |
3742cc8b YQ |
133 | static struct bp_location *add_location_to_breakpoint (struct breakpoint *, |
134 | const struct symtab_and_line *); | |
135 | ||
4a64f543 MS |
136 | /* This function is used in gdbtk sources and thus can not be made |
137 | static. */ | |
63c252f8 | 138 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
348d480f | 139 | struct symtab_and_line, |
c0a91b2b TT |
140 | enum bptype, |
141 | const struct breakpoint_ops *); | |
c906108c | 142 | |
06edf0c0 PA |
143 | static struct breakpoint * |
144 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
145 | enum bptype type, | |
c0a91b2b | 146 | const struct breakpoint_ops *ops); |
06edf0c0 | 147 | |
76897487 KB |
148 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
149 | ||
a6d9a66e UW |
150 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
151 | CORE_ADDR bpaddr, | |
88f7da05 | 152 | enum bptype bptype); |
76897487 | 153 | |
6c95b8df PA |
154 | static void describe_other_breakpoints (struct gdbarch *, |
155 | struct program_space *, CORE_ADDR, | |
5af949e3 | 156 | struct obj_section *, int); |
c906108c | 157 | |
6c95b8df PA |
158 | static int breakpoint_address_match (struct address_space *aspace1, |
159 | CORE_ADDR addr1, | |
160 | struct address_space *aspace2, | |
161 | CORE_ADDR addr2); | |
162 | ||
85d721b8 PA |
163 | static int watchpoint_locations_match (struct bp_location *loc1, |
164 | struct bp_location *loc2); | |
165 | ||
f1310107 TJB |
166 | static int breakpoint_location_address_match (struct bp_location *bl, |
167 | struct address_space *aspace, | |
168 | CORE_ADDR addr); | |
169 | ||
a14ed312 | 170 | static void breakpoints_info (char *, int); |
c906108c | 171 | |
d77f58be SS |
172 | static void watchpoints_info (char *, int); |
173 | ||
e5a67952 MS |
174 | static int breakpoint_1 (char *, int, |
175 | int (*) (const struct breakpoint *)); | |
c906108c | 176 | |
4efb68b1 | 177 | static int breakpoint_cond_eval (void *); |
c906108c | 178 | |
4efb68b1 | 179 | static void cleanup_executing_breakpoints (void *); |
c906108c | 180 | |
a14ed312 | 181 | static void commands_command (char *, int); |
c906108c | 182 | |
a14ed312 | 183 | static void condition_command (char *, int); |
c906108c | 184 | |
c5aa993b JM |
185 | typedef enum |
186 | { | |
187 | mark_inserted, | |
188 | mark_uninserted | |
189 | } | |
190 | insertion_state_t; | |
c906108c | 191 | |
0bde7532 | 192 | static int remove_breakpoint (struct bp_location *, insertion_state_t); |
6c95b8df | 193 | static int remove_breakpoint_1 (struct bp_location *, insertion_state_t); |
c906108c | 194 | |
e514a9d6 | 195 | static enum print_stop_action print_bp_stop_message (bpstat bs); |
c906108c | 196 | |
4efb68b1 | 197 | static int watchpoint_check (void *); |
c906108c | 198 | |
a14ed312 | 199 | static void maintenance_info_breakpoints (char *, int); |
c906108c | 200 | |
a14ed312 | 201 | static int hw_breakpoint_used_count (void); |
c906108c | 202 | |
a1398e0c PA |
203 | static int hw_watchpoint_use_count (struct breakpoint *); |
204 | ||
205 | static int hw_watchpoint_used_count_others (struct breakpoint *except, | |
206 | enum bptype type, | |
207 | int *other_type_used); | |
c906108c | 208 | |
a14ed312 | 209 | static void hbreak_command (char *, int); |
c906108c | 210 | |
a14ed312 | 211 | static void thbreak_command (char *, int); |
c906108c | 212 | |
816338b5 SS |
213 | static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp, |
214 | int count); | |
c906108c | 215 | |
a14ed312 | 216 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 217 | |
a14ed312 | 218 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 219 | |
a14ed312 | 220 | static void stopat_command (char *arg, int from_tty); |
7a292a7a | 221 | |
a14ed312 | 222 | static char *ep_parse_optional_if_clause (char **arg); |
7a292a7a | 223 | |
d85310f7 MS |
224 | static void catch_exception_command_1 (enum exception_event_kind ex_event, |
225 | char *arg, int tempflag, int from_tty); | |
7a292a7a | 226 | |
a14ed312 | 227 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 228 | |
d03285ec UW |
229 | static void detach_single_step_breakpoints (void); |
230 | ||
6c95b8df PA |
231 | static int single_step_breakpoint_inserted_here_p (struct address_space *, |
232 | CORE_ADDR pc); | |
1aafd4da | 233 | |
fe3f5fa8 | 234 | static void free_bp_location (struct bp_location *loc); |
f431efe5 PA |
235 | static void incref_bp_location (struct bp_location *loc); |
236 | static void decref_bp_location (struct bp_location **loc); | |
fe3f5fa8 | 237 | |
39d61571 | 238 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 239 | |
b60e7edf | 240 | static void update_global_location_list (int); |
a5606eee | 241 | |
b60e7edf | 242 | static void update_global_location_list_nothrow (int); |
74960c60 | 243 | |
d77f58be | 244 | static int is_hardware_watchpoint (const struct breakpoint *bpt); |
74960c60 VP |
245 | |
246 | static void insert_breakpoint_locations (void); | |
a5606eee | 247 | |
a96d9b2e SDJ |
248 | static int syscall_catchpoint_p (struct breakpoint *b); |
249 | ||
1042e4c0 SS |
250 | static void tracepoints_info (char *, int); |
251 | ||
252 | static void delete_trace_command (char *, int); | |
253 | ||
254 | static void enable_trace_command (char *, int); | |
255 | ||
256 | static void disable_trace_command (char *, int); | |
257 | ||
258 | static void trace_pass_command (char *, int); | |
259 | ||
9c06b0b4 TJB |
260 | static int is_masked_watchpoint (const struct breakpoint *b); |
261 | ||
b775012e LM |
262 | static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address); |
263 | ||
983af33b SDJ |
264 | /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero |
265 | otherwise. */ | |
266 | ||
267 | static int strace_marker_p (struct breakpoint *b); | |
0fb4aa4b | 268 | |
edcc5120 TT |
269 | static void init_catchpoint (struct breakpoint *b, |
270 | struct gdbarch *gdbarch, int tempflag, | |
271 | char *cond_string, | |
272 | const struct breakpoint_ops *ops); | |
273 | ||
2060206e PA |
274 | /* The abstract base class all breakpoint_ops structures inherit |
275 | from. */ | |
276 | static struct breakpoint_ops base_breakpoint_ops; | |
277 | ||
278 | /* The breakpoint_ops structure to be inherited by all breakpoint_ops | |
279 | that are implemented on top of software or hardware breakpoints | |
280 | (user breakpoints, internal and momentary breakpoints, etc.). */ | |
281 | static struct breakpoint_ops bkpt_base_breakpoint_ops; | |
282 | ||
283 | /* Internal breakpoints class type. */ | |
06edf0c0 | 284 | static struct breakpoint_ops internal_breakpoint_ops; |
2060206e PA |
285 | |
286 | /* Momentary breakpoints class type. */ | |
06edf0c0 PA |
287 | static struct breakpoint_ops momentary_breakpoint_ops; |
288 | ||
2060206e PA |
289 | /* The breakpoint_ops structure to be used in regular user created |
290 | breakpoints. */ | |
291 | struct breakpoint_ops bkpt_breakpoint_ops; | |
292 | ||
5cea2a26 PA |
293 | /* A reference-counted struct command_line. This lets multiple |
294 | breakpoints share a single command list. */ | |
295 | struct counted_command_line | |
296 | { | |
297 | /* The reference count. */ | |
298 | int refc; | |
299 | ||
300 | /* The command list. */ | |
301 | struct command_line *commands; | |
302 | }; | |
303 | ||
304 | struct command_line * | |
305 | breakpoint_commands (struct breakpoint *b) | |
306 | { | |
307 | return b->commands ? b->commands->commands : NULL; | |
308 | } | |
3daf8fe5 | 309 | |
f3b1572e PA |
310 | /* Flag indicating that a command has proceeded the inferior past the |
311 | current breakpoint. */ | |
312 | ||
313 | static int breakpoint_proceeded; | |
314 | ||
956a9fb9 | 315 | const char * |
2cec12e5 AR |
316 | bpdisp_text (enum bpdisp disp) |
317 | { | |
4a64f543 MS |
318 | /* NOTE: the following values are a part of MI protocol and |
319 | represent values of 'disp' field returned when inferior stops at | |
320 | a breakpoint. */ | |
bc043ef3 | 321 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
cc59ec59 | 322 | |
2cec12e5 AR |
323 | return bpdisps[(int) disp]; |
324 | } | |
c906108c | 325 | |
4a64f543 | 326 | /* Prototypes for exported functions. */ |
c906108c | 327 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
4a64f543 | 328 | if such is available. */ |
c906108c SS |
329 | static int can_use_hw_watchpoints; |
330 | ||
920d2a44 AC |
331 | static void |
332 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
333 | struct cmd_list_element *c, | |
334 | const char *value) | |
335 | { | |
3e43a32a MS |
336 | fprintf_filtered (file, |
337 | _("Debugger's willingness to use " | |
338 | "watchpoint hardware is %s.\n"), | |
920d2a44 AC |
339 | value); |
340 | } | |
341 | ||
fa8d40ab JJ |
342 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
343 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
4a64f543 | 344 | for unrecognized breakpoint locations. |
fa8d40ab JJ |
345 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
346 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
347 | static void |
348 | show_pending_break_support (struct ui_file *file, int from_tty, | |
349 | struct cmd_list_element *c, | |
350 | const char *value) | |
351 | { | |
3e43a32a MS |
352 | fprintf_filtered (file, |
353 | _("Debugger's behavior regarding " | |
354 | "pending breakpoints is %s.\n"), | |
920d2a44 AC |
355 | value); |
356 | } | |
fa8d40ab | 357 | |
765dc015 | 358 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
4a64f543 | 359 | set with "break" but falling in read-only memory. |
765dc015 VP |
360 | If 0, gdb will warn about such breakpoints, but won't automatically |
361 | use hardware breakpoints. */ | |
362 | static int automatic_hardware_breakpoints; | |
363 | static void | |
364 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
365 | struct cmd_list_element *c, | |
366 | const char *value) | |
367 | { | |
3e43a32a MS |
368 | fprintf_filtered (file, |
369 | _("Automatic usage of hardware breakpoints is %s.\n"), | |
765dc015 VP |
370 | value); |
371 | } | |
372 | ||
33e5cbd6 PA |
373 | /* If on, gdb will keep breakpoints inserted even as inferior is |
374 | stopped, and immediately insert any new breakpoints. If off, gdb | |
375 | will insert breakpoints into inferior only when resuming it, and | |
376 | will remove breakpoints upon stop. If auto, GDB will behave as ON | |
377 | if in non-stop mode, and as OFF if all-stop mode.*/ | |
378 | ||
379 | static const char always_inserted_auto[] = "auto"; | |
380 | static const char always_inserted_on[] = "on"; | |
381 | static const char always_inserted_off[] = "off"; | |
40478521 | 382 | static const char *const always_inserted_enums[] = { |
33e5cbd6 PA |
383 | always_inserted_auto, |
384 | always_inserted_off, | |
385 | always_inserted_on, | |
386 | NULL | |
387 | }; | |
388 | static const char *always_inserted_mode = always_inserted_auto; | |
389 | static void | |
74960c60 | 390 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 391 | struct cmd_list_element *c, const char *value) |
74960c60 | 392 | { |
33e5cbd6 | 393 | if (always_inserted_mode == always_inserted_auto) |
3e43a32a MS |
394 | fprintf_filtered (file, |
395 | _("Always inserted breakpoint " | |
396 | "mode is %s (currently %s).\n"), | |
33e5cbd6 PA |
397 | value, |
398 | breakpoints_always_inserted_mode () ? "on" : "off"); | |
399 | else | |
3e43a32a MS |
400 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), |
401 | value); | |
74960c60 VP |
402 | } |
403 | ||
33e5cbd6 PA |
404 | int |
405 | breakpoints_always_inserted_mode (void) | |
406 | { | |
049e32d3 PA |
407 | return ((always_inserted_mode == always_inserted_on |
408 | || (always_inserted_mode == always_inserted_auto && non_stop)) | |
409 | && !RECORD_IS_USED); | |
33e5cbd6 | 410 | } |
765dc015 | 411 | |
b775012e LM |
412 | static const char condition_evaluation_both[] = "host or target"; |
413 | ||
414 | /* Modes for breakpoint condition evaluation. */ | |
415 | static const char condition_evaluation_auto[] = "auto"; | |
416 | static const char condition_evaluation_host[] = "host"; | |
417 | static const char condition_evaluation_target[] = "target"; | |
418 | static const char *const condition_evaluation_enums[] = { | |
419 | condition_evaluation_auto, | |
420 | condition_evaluation_host, | |
421 | condition_evaluation_target, | |
422 | NULL | |
423 | }; | |
424 | ||
425 | /* Global that holds the current mode for breakpoint condition evaluation. */ | |
426 | static const char *condition_evaluation_mode_1 = condition_evaluation_auto; | |
427 | ||
428 | /* Global that we use to display information to the user (gets its value from | |
429 | condition_evaluation_mode_1. */ | |
430 | static const char *condition_evaluation_mode = condition_evaluation_auto; | |
431 | ||
432 | /* Translate a condition evaluation mode MODE into either "host" | |
433 | or "target". This is used mostly to translate from "auto" to the | |
434 | real setting that is being used. It returns the translated | |
435 | evaluation mode. */ | |
436 | ||
437 | static const char * | |
438 | translate_condition_evaluation_mode (const char *mode) | |
439 | { | |
440 | if (mode == condition_evaluation_auto) | |
441 | { | |
442 | if (target_supports_evaluation_of_breakpoint_conditions ()) | |
443 | return condition_evaluation_target; | |
444 | else | |
445 | return condition_evaluation_host; | |
446 | } | |
447 | else | |
448 | return mode; | |
449 | } | |
450 | ||
451 | /* Discovers what condition_evaluation_auto translates to. */ | |
452 | ||
453 | static const char * | |
454 | breakpoint_condition_evaluation_mode (void) | |
455 | { | |
456 | return translate_condition_evaluation_mode (condition_evaluation_mode); | |
457 | } | |
458 | ||
459 | /* Return true if GDB should evaluate breakpoint conditions or false | |
460 | otherwise. */ | |
461 | ||
462 | static int | |
463 | gdb_evaluates_breakpoint_condition_p (void) | |
464 | { | |
465 | const char *mode = breakpoint_condition_evaluation_mode (); | |
466 | ||
467 | return (mode == condition_evaluation_host); | |
468 | } | |
469 | ||
a14ed312 | 470 | void _initialize_breakpoint (void); |
c906108c | 471 | |
c906108c SS |
472 | /* Are we executing breakpoint commands? */ |
473 | static int executing_breakpoint_commands; | |
474 | ||
c02f5703 MS |
475 | /* Are overlay event breakpoints enabled? */ |
476 | static int overlay_events_enabled; | |
477 | ||
e09342b5 TJB |
478 | /* See description in breakpoint.h. */ |
479 | int target_exact_watchpoints = 0; | |
480 | ||
c906108c | 481 | /* Walk the following statement or block through all breakpoints. |
e5dd4106 | 482 | ALL_BREAKPOINTS_SAFE does so even if the statement deletes the |
4a64f543 | 483 | current breakpoint. */ |
c906108c | 484 | |
5c44784c | 485 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 486 | |
5c44784c JM |
487 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
488 | for (B = breakpoint_chain; \ | |
489 | B ? (TMP=B->next, 1): 0; \ | |
490 | B = TMP) | |
c906108c | 491 | |
4a64f543 MS |
492 | /* Similar iterator for the low-level breakpoints. SAFE variant is |
493 | not provided so update_global_location_list must not be called | |
494 | while executing the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 495 | |
876fa593 JK |
496 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
497 | for (BP_TMP = bp_location; \ | |
498 | BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \ | |
499 | BP_TMP++) | |
7cc221ef | 500 | |
b775012e LM |
501 | /* Iterates through locations with address ADDRESS for the currently selected |
502 | program space. BP_LOCP_TMP points to each object. BP_LOCP_START points | |
503 | to where the loop should start from. | |
504 | If BP_LOCP_START is a NULL pointer, the macro automatically seeks the | |
505 | appropriate location to start with. */ | |
506 | ||
507 | #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \ | |
508 | for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \ | |
509 | BP_LOCP_TMP = BP_LOCP_START; \ | |
510 | BP_LOCP_START \ | |
511 | && (BP_LOCP_TMP < bp_location + bp_location_count \ | |
512 | && (*BP_LOCP_TMP)->address == ADDRESS); \ | |
513 | BP_LOCP_TMP++) | |
514 | ||
1042e4c0 SS |
515 | /* Iterator for tracepoints only. */ |
516 | ||
517 | #define ALL_TRACEPOINTS(B) \ | |
518 | for (B = breakpoint_chain; B; B = B->next) \ | |
d77f58be | 519 | if (is_tracepoint (B)) |
1042e4c0 | 520 | |
7cc221ef | 521 | /* Chains of all breakpoints defined. */ |
c906108c SS |
522 | |
523 | struct breakpoint *breakpoint_chain; | |
524 | ||
876fa593 JK |
525 | /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */ |
526 | ||
527 | static struct bp_location **bp_location; | |
528 | ||
529 | /* Number of elements of BP_LOCATION. */ | |
530 | ||
531 | static unsigned bp_location_count; | |
532 | ||
4a64f543 MS |
533 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
534 | ADDRESS for the current elements of BP_LOCATION which get a valid | |
535 | result from bp_location_has_shadow. You can use it for roughly | |
536 | limiting the subrange of BP_LOCATION to scan for shadow bytes for | |
537 | an address you need to read. */ | |
876fa593 JK |
538 | |
539 | static CORE_ADDR bp_location_placed_address_before_address_max; | |
540 | ||
4a64f543 MS |
541 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
542 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of | |
543 | BP_LOCATION which get a valid result from bp_location_has_shadow. | |
544 | You can use it for roughly limiting the subrange of BP_LOCATION to | |
545 | scan for shadow bytes for an address you need to read. */ | |
876fa593 JK |
546 | |
547 | static CORE_ADDR bp_location_shadow_len_after_address_max; | |
7cc221ef | 548 | |
4a64f543 MS |
549 | /* The locations that no longer correspond to any breakpoint, unlinked |
550 | from bp_location array, but for which a hit may still be reported | |
551 | by a target. */ | |
20874c92 VP |
552 | VEC(bp_location_p) *moribund_locations = NULL; |
553 | ||
c906108c SS |
554 | /* Number of last breakpoint made. */ |
555 | ||
95a42b64 TT |
556 | static int breakpoint_count; |
557 | ||
86b17b60 PA |
558 | /* The value of `breakpoint_count' before the last command that |
559 | created breakpoints. If the last (break-like) command created more | |
560 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
561 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
562 | static int prev_breakpoint_count; | |
c906108c | 563 | |
1042e4c0 SS |
564 | /* Number of last tracepoint made. */ |
565 | ||
95a42b64 | 566 | static int tracepoint_count; |
1042e4c0 | 567 | |
6149aea9 PA |
568 | static struct cmd_list_element *breakpoint_set_cmdlist; |
569 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
9291a0cd | 570 | struct cmd_list_element *save_cmdlist; |
6149aea9 | 571 | |
468d015d JJ |
572 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
573 | static int | |
574 | breakpoint_enabled (struct breakpoint *b) | |
575 | { | |
0d381245 | 576 | return (b->enable_state == bp_enabled); |
468d015d JJ |
577 | } |
578 | ||
c906108c SS |
579 | /* Set breakpoint count to NUM. */ |
580 | ||
95a42b64 | 581 | static void |
fba45db2 | 582 | set_breakpoint_count (int num) |
c906108c | 583 | { |
86b17b60 | 584 | prev_breakpoint_count = breakpoint_count; |
c906108c | 585 | breakpoint_count = num; |
4fa62494 | 586 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
587 | } |
588 | ||
86b17b60 PA |
589 | /* Used by `start_rbreak_breakpoints' below, to record the current |
590 | breakpoint count before "rbreak" creates any breakpoint. */ | |
591 | static int rbreak_start_breakpoint_count; | |
592 | ||
95a42b64 TT |
593 | /* Called at the start an "rbreak" command to record the first |
594 | breakpoint made. */ | |
86b17b60 | 595 | |
95a42b64 TT |
596 | void |
597 | start_rbreak_breakpoints (void) | |
598 | { | |
86b17b60 | 599 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
600 | } |
601 | ||
602 | /* Called at the end of an "rbreak" command to record the last | |
603 | breakpoint made. */ | |
86b17b60 | 604 | |
95a42b64 TT |
605 | void |
606 | end_rbreak_breakpoints (void) | |
607 | { | |
86b17b60 | 608 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
609 | } |
610 | ||
4a64f543 | 611 | /* Used in run_command to zero the hit count when a new run starts. */ |
c906108c SS |
612 | |
613 | void | |
fba45db2 | 614 | clear_breakpoint_hit_counts (void) |
c906108c SS |
615 | { |
616 | struct breakpoint *b; | |
617 | ||
618 | ALL_BREAKPOINTS (b) | |
619 | b->hit_count = 0; | |
620 | } | |
621 | ||
9add0f1b TT |
622 | /* Allocate a new counted_command_line with reference count of 1. |
623 | The new structure owns COMMANDS. */ | |
624 | ||
625 | static struct counted_command_line * | |
626 | alloc_counted_command_line (struct command_line *commands) | |
627 | { | |
628 | struct counted_command_line *result | |
629 | = xmalloc (sizeof (struct counted_command_line)); | |
cc59ec59 | 630 | |
9add0f1b TT |
631 | result->refc = 1; |
632 | result->commands = commands; | |
633 | return result; | |
634 | } | |
635 | ||
636 | /* Increment reference count. This does nothing if CMD is NULL. */ | |
637 | ||
638 | static void | |
639 | incref_counted_command_line (struct counted_command_line *cmd) | |
640 | { | |
641 | if (cmd) | |
642 | ++cmd->refc; | |
643 | } | |
644 | ||
645 | /* Decrement reference count. If the reference count reaches 0, | |
646 | destroy the counted_command_line. Sets *CMDP to NULL. This does | |
647 | nothing if *CMDP is NULL. */ | |
648 | ||
649 | static void | |
650 | decref_counted_command_line (struct counted_command_line **cmdp) | |
651 | { | |
652 | if (*cmdp) | |
653 | { | |
654 | if (--(*cmdp)->refc == 0) | |
655 | { | |
656 | free_command_lines (&(*cmdp)->commands); | |
657 | xfree (*cmdp); | |
658 | } | |
659 | *cmdp = NULL; | |
660 | } | |
661 | } | |
662 | ||
663 | /* A cleanup function that calls decref_counted_command_line. */ | |
664 | ||
665 | static void | |
666 | do_cleanup_counted_command_line (void *arg) | |
667 | { | |
668 | decref_counted_command_line (arg); | |
669 | } | |
670 | ||
671 | /* Create a cleanup that calls decref_counted_command_line on the | |
672 | argument. */ | |
673 | ||
674 | static struct cleanup * | |
675 | make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp) | |
676 | { | |
677 | return make_cleanup (do_cleanup_counted_command_line, cmdp); | |
678 | } | |
679 | ||
c906108c | 680 | \f |
48cb2d85 VP |
681 | /* Return the breakpoint with the specified number, or NULL |
682 | if the number does not refer to an existing breakpoint. */ | |
683 | ||
684 | struct breakpoint * | |
685 | get_breakpoint (int num) | |
686 | { | |
687 | struct breakpoint *b; | |
688 | ||
689 | ALL_BREAKPOINTS (b) | |
690 | if (b->number == num) | |
691 | return b; | |
692 | ||
693 | return NULL; | |
694 | } | |
5c44784c | 695 | |
c906108c | 696 | \f |
adc36818 | 697 | |
b775012e LM |
698 | /* Mark locations as "conditions have changed" in case the target supports |
699 | evaluating conditions on its side. */ | |
700 | ||
701 | static void | |
702 | mark_breakpoint_modified (struct breakpoint *b) | |
703 | { | |
704 | struct bp_location *loc; | |
705 | ||
706 | /* This is only meaningful if the target is | |
707 | evaluating conditions and if the user has | |
708 | opted for condition evaluation on the target's | |
709 | side. */ | |
710 | if (gdb_evaluates_breakpoint_condition_p () | |
711 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
712 | return; | |
713 | ||
714 | if (!is_breakpoint (b)) | |
715 | return; | |
716 | ||
717 | for (loc = b->loc; loc; loc = loc->next) | |
718 | loc->condition_changed = condition_modified; | |
719 | } | |
720 | ||
721 | /* Mark location as "conditions have changed" in case the target supports | |
722 | evaluating conditions on its side. */ | |
723 | ||
724 | static void | |
725 | mark_breakpoint_location_modified (struct bp_location *loc) | |
726 | { | |
727 | /* This is only meaningful if the target is | |
728 | evaluating conditions and if the user has | |
729 | opted for condition evaluation on the target's | |
730 | side. */ | |
731 | if (gdb_evaluates_breakpoint_condition_p () | |
732 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
733 | ||
734 | return; | |
735 | ||
736 | if (!is_breakpoint (loc->owner)) | |
737 | return; | |
738 | ||
739 | loc->condition_changed = condition_modified; | |
740 | } | |
741 | ||
742 | /* Sets the condition-evaluation mode using the static global | |
743 | condition_evaluation_mode. */ | |
744 | ||
745 | static void | |
746 | set_condition_evaluation_mode (char *args, int from_tty, | |
747 | struct cmd_list_element *c) | |
748 | { | |
749 | struct breakpoint *b; | |
750 | const char *old_mode, *new_mode; | |
751 | ||
752 | if ((condition_evaluation_mode_1 == condition_evaluation_target) | |
753 | && !target_supports_evaluation_of_breakpoint_conditions ()) | |
754 | { | |
755 | condition_evaluation_mode_1 = condition_evaluation_mode; | |
756 | warning (_("Target does not support breakpoint condition evaluation.\n" | |
757 | "Using host evaluation mode instead.")); | |
758 | return; | |
759 | } | |
760 | ||
761 | new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1); | |
762 | old_mode = translate_condition_evaluation_mode (condition_evaluation_mode); | |
763 | ||
abf1152a JK |
764 | /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the |
765 | settings was "auto". */ | |
766 | condition_evaluation_mode = condition_evaluation_mode_1; | |
767 | ||
b775012e LM |
768 | /* Only update the mode if the user picked a different one. */ |
769 | if (new_mode != old_mode) | |
770 | { | |
771 | struct bp_location *loc, **loc_tmp; | |
772 | /* If the user switched to a different evaluation mode, we | |
773 | need to synch the changes with the target as follows: | |
774 | ||
775 | "host" -> "target": Send all (valid) conditions to the target. | |
776 | "target" -> "host": Remove all the conditions from the target. | |
777 | */ | |
778 | ||
b775012e LM |
779 | if (new_mode == condition_evaluation_target) |
780 | { | |
781 | /* Mark everything modified and synch conditions with the | |
782 | target. */ | |
783 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
784 | mark_breakpoint_location_modified (loc); | |
785 | } | |
786 | else | |
787 | { | |
788 | /* Manually mark non-duplicate locations to synch conditions | |
789 | with the target. We do this to remove all the conditions the | |
790 | target knows about. */ | |
791 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
792 | if (is_breakpoint (loc->owner) && loc->inserted) | |
793 | loc->needs_update = 1; | |
794 | } | |
795 | ||
796 | /* Do the update. */ | |
797 | update_global_location_list (1); | |
798 | } | |
799 | ||
800 | return; | |
801 | } | |
802 | ||
803 | /* Shows the current mode of breakpoint condition evaluation. Explicitly shows | |
804 | what "auto" is translating to. */ | |
805 | ||
806 | static void | |
807 | show_condition_evaluation_mode (struct ui_file *file, int from_tty, | |
808 | struct cmd_list_element *c, const char *value) | |
809 | { | |
810 | if (condition_evaluation_mode == condition_evaluation_auto) | |
811 | fprintf_filtered (file, | |
812 | _("Breakpoint condition evaluation " | |
813 | "mode is %s (currently %s).\n"), | |
814 | value, | |
815 | breakpoint_condition_evaluation_mode ()); | |
816 | else | |
817 | fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"), | |
818 | value); | |
819 | } | |
820 | ||
821 | /* A comparison function for bp_location AP and BP that is used by | |
822 | bsearch. This comparison function only cares about addresses, unlike | |
823 | the more general bp_location_compare function. */ | |
824 | ||
825 | static int | |
826 | bp_location_compare_addrs (const void *ap, const void *bp) | |
827 | { | |
828 | struct bp_location *a = *(void **) ap; | |
829 | struct bp_location *b = *(void **) bp; | |
830 | ||
831 | if (a->address == b->address) | |
832 | return 0; | |
833 | else | |
834 | return ((a->address > b->address) - (a->address < b->address)); | |
835 | } | |
836 | ||
837 | /* Helper function to skip all bp_locations with addresses | |
838 | less than ADDRESS. It returns the first bp_location that | |
839 | is greater than or equal to ADDRESS. If none is found, just | |
840 | return NULL. */ | |
841 | ||
842 | static struct bp_location ** | |
843 | get_first_locp_gte_addr (CORE_ADDR address) | |
844 | { | |
845 | struct bp_location dummy_loc; | |
846 | struct bp_location *dummy_locp = &dummy_loc; | |
847 | struct bp_location **locp_found = NULL; | |
848 | ||
849 | /* Initialize the dummy location's address field. */ | |
850 | memset (&dummy_loc, 0, sizeof (struct bp_location)); | |
851 | dummy_loc.address = address; | |
852 | ||
853 | /* Find a close match to the first location at ADDRESS. */ | |
854 | locp_found = bsearch (&dummy_locp, bp_location, bp_location_count, | |
855 | sizeof (struct bp_location **), | |
856 | bp_location_compare_addrs); | |
857 | ||
858 | /* Nothing was found, nothing left to do. */ | |
859 | if (locp_found == NULL) | |
860 | return NULL; | |
861 | ||
862 | /* We may have found a location that is at ADDRESS but is not the first in the | |
863 | location's list. Go backwards (if possible) and locate the first one. */ | |
864 | while ((locp_found - 1) >= bp_location | |
865 | && (*(locp_found - 1))->address == address) | |
866 | locp_found--; | |
867 | ||
868 | return locp_found; | |
869 | } | |
870 | ||
adc36818 PM |
871 | void |
872 | set_breakpoint_condition (struct breakpoint *b, char *exp, | |
873 | int from_tty) | |
874 | { | |
3a5c3e22 PA |
875 | xfree (b->cond_string); |
876 | b->cond_string = NULL; | |
adc36818 | 877 | |
3a5c3e22 | 878 | if (is_watchpoint (b)) |
adc36818 | 879 | { |
3a5c3e22 PA |
880 | struct watchpoint *w = (struct watchpoint *) b; |
881 | ||
882 | xfree (w->cond_exp); | |
883 | w->cond_exp = NULL; | |
884 | } | |
885 | else | |
886 | { | |
887 | struct bp_location *loc; | |
888 | ||
889 | for (loc = b->loc; loc; loc = loc->next) | |
890 | { | |
891 | xfree (loc->cond); | |
892 | loc->cond = NULL; | |
b775012e LM |
893 | |
894 | /* No need to free the condition agent expression | |
895 | bytecode (if we have one). We will handle this | |
896 | when we go through update_global_location_list. */ | |
3a5c3e22 | 897 | } |
adc36818 | 898 | } |
adc36818 PM |
899 | |
900 | if (*exp == 0) | |
901 | { | |
902 | if (from_tty) | |
903 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
904 | } | |
905 | else | |
906 | { | |
907 | char *arg = exp; | |
cc59ec59 | 908 | |
adc36818 PM |
909 | /* I don't know if it matters whether this is the string the user |
910 | typed in or the decompiled expression. */ | |
911 | b->cond_string = xstrdup (arg); | |
912 | b->condition_not_parsed = 0; | |
913 | ||
914 | if (is_watchpoint (b)) | |
915 | { | |
3a5c3e22 PA |
916 | struct watchpoint *w = (struct watchpoint *) b; |
917 | ||
adc36818 PM |
918 | innermost_block = NULL; |
919 | arg = exp; | |
3a5c3e22 | 920 | w->cond_exp = parse_exp_1 (&arg, 0, 0); |
adc36818 PM |
921 | if (*arg) |
922 | error (_("Junk at end of expression")); | |
3a5c3e22 | 923 | w->cond_exp_valid_block = innermost_block; |
adc36818 PM |
924 | } |
925 | else | |
926 | { | |
3a5c3e22 PA |
927 | struct bp_location *loc; |
928 | ||
adc36818 PM |
929 | for (loc = b->loc; loc; loc = loc->next) |
930 | { | |
931 | arg = exp; | |
932 | loc->cond = | |
933 | parse_exp_1 (&arg, block_for_pc (loc->address), 0); | |
934 | if (*arg) | |
935 | error (_("Junk at end of expression")); | |
936 | } | |
937 | } | |
938 | } | |
b775012e LM |
939 | mark_breakpoint_modified (b); |
940 | ||
adc36818 | 941 | breakpoints_changed (); |
8d3788bd | 942 | observer_notify_breakpoint_modified (b); |
adc36818 PM |
943 | } |
944 | ||
c906108c SS |
945 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
946 | ||
947 | static void | |
fba45db2 | 948 | condition_command (char *arg, int from_tty) |
c906108c | 949 | { |
52f0bd74 | 950 | struct breakpoint *b; |
c906108c | 951 | char *p; |
52f0bd74 | 952 | int bnum; |
c906108c SS |
953 | |
954 | if (arg == 0) | |
e2e0b3e5 | 955 | error_no_arg (_("breakpoint number")); |
c906108c SS |
956 | |
957 | p = arg; | |
958 | bnum = get_number (&p); | |
5c44784c | 959 | if (bnum == 0) |
8a3fe4f8 | 960 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
961 | |
962 | ALL_BREAKPOINTS (b) | |
963 | if (b->number == bnum) | |
2f069f6f | 964 | { |
7371cf6d PM |
965 | /* Check if this breakpoint has a Python object assigned to |
966 | it, and if it has a definition of the "stop" | |
967 | method. This method and conditions entered into GDB from | |
968 | the CLI are mutually exclusive. */ | |
969 | if (b->py_bp_object | |
970 | && gdbpy_breakpoint_has_py_cond (b->py_bp_object)) | |
971 | error (_("Cannot set a condition where a Python 'stop' " | |
972 | "method has been defined in the breakpoint.")); | |
2566ad2d | 973 | set_breakpoint_condition (b, p, from_tty); |
b775012e LM |
974 | |
975 | if (is_breakpoint (b)) | |
976 | update_global_location_list (1); | |
977 | ||
2f069f6f JB |
978 | return; |
979 | } | |
c906108c | 980 | |
8a3fe4f8 | 981 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
982 | } |
983 | ||
a7bdde9e VP |
984 | /* Check that COMMAND do not contain commands that are suitable |
985 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
986 | Throw if any such commands is found. */ |
987 | ||
a7bdde9e VP |
988 | static void |
989 | check_no_tracepoint_commands (struct command_line *commands) | |
990 | { | |
991 | struct command_line *c; | |
cc59ec59 | 992 | |
a7bdde9e VP |
993 | for (c = commands; c; c = c->next) |
994 | { | |
995 | int i; | |
996 | ||
997 | if (c->control_type == while_stepping_control) | |
3e43a32a MS |
998 | error (_("The 'while-stepping' command can " |
999 | "only be used for tracepoints")); | |
a7bdde9e VP |
1000 | |
1001 | for (i = 0; i < c->body_count; ++i) | |
1002 | check_no_tracepoint_commands ((c->body_list)[i]); | |
1003 | ||
1004 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 1005 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
1006 | command directly. */ |
1007 | if (strstr (c->line, "collect ") == c->line) | |
1008 | error (_("The 'collect' command can only be used for tracepoints")); | |
1009 | ||
51661e93 VP |
1010 | if (strstr (c->line, "teval ") == c->line) |
1011 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
1012 | } |
1013 | } | |
1014 | ||
d77f58be SS |
1015 | /* Encapsulate tests for different types of tracepoints. */ |
1016 | ||
d9b3f62e PA |
1017 | static int |
1018 | is_tracepoint_type (enum bptype type) | |
1019 | { | |
1020 | return (type == bp_tracepoint | |
1021 | || type == bp_fast_tracepoint | |
1022 | || type == bp_static_tracepoint); | |
1023 | } | |
1024 | ||
a7bdde9e | 1025 | int |
d77f58be | 1026 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 1027 | { |
d9b3f62e | 1028 | return is_tracepoint_type (b->type); |
a7bdde9e | 1029 | } |
d9b3f62e | 1030 | |
e5dd4106 | 1031 | /* A helper function that validates that COMMANDS are valid for a |
95a42b64 TT |
1032 | breakpoint. This function will throw an exception if a problem is |
1033 | found. */ | |
48cb2d85 | 1034 | |
95a42b64 TT |
1035 | static void |
1036 | validate_commands_for_breakpoint (struct breakpoint *b, | |
1037 | struct command_line *commands) | |
48cb2d85 | 1038 | { |
d77f58be | 1039 | if (is_tracepoint (b)) |
a7bdde9e | 1040 | { |
4a64f543 MS |
1041 | /* We need to verify that each top-level element of commands is |
1042 | valid for tracepoints, that there's at most one | |
1043 | while-stepping element, and that while-stepping's body has | |
1044 | valid tracing commands excluding nested while-stepping. */ | |
a7bdde9e VP |
1045 | struct command_line *c; |
1046 | struct command_line *while_stepping = 0; | |
1047 | for (c = commands; c; c = c->next) | |
1048 | { | |
a7bdde9e VP |
1049 | if (c->control_type == while_stepping_control) |
1050 | { | |
1051 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
1052 | error (_("The 'while-stepping' command " |
1053 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 1054 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
1055 | error (_("The 'while-stepping' command " |
1056 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
1057 | |
1058 | if (while_stepping) | |
3e43a32a MS |
1059 | error (_("The 'while-stepping' command " |
1060 | "can be used only once")); | |
a7bdde9e VP |
1061 | else |
1062 | while_stepping = c; | |
1063 | } | |
1064 | } | |
1065 | if (while_stepping) | |
1066 | { | |
1067 | struct command_line *c2; | |
1068 | ||
1069 | gdb_assert (while_stepping->body_count == 1); | |
1070 | c2 = while_stepping->body_list[0]; | |
1071 | for (; c2; c2 = c2->next) | |
1072 | { | |
a7bdde9e VP |
1073 | if (c2->control_type == while_stepping_control) |
1074 | error (_("The 'while-stepping' command cannot be nested")); | |
1075 | } | |
1076 | } | |
1077 | } | |
1078 | else | |
1079 | { | |
1080 | check_no_tracepoint_commands (commands); | |
1081 | } | |
95a42b64 TT |
1082 | } |
1083 | ||
0fb4aa4b PA |
1084 | /* Return a vector of all the static tracepoints set at ADDR. The |
1085 | caller is responsible for releasing the vector. */ | |
1086 | ||
1087 | VEC(breakpoint_p) * | |
1088 | static_tracepoints_here (CORE_ADDR addr) | |
1089 | { | |
1090 | struct breakpoint *b; | |
1091 | VEC(breakpoint_p) *found = 0; | |
1092 | struct bp_location *loc; | |
1093 | ||
1094 | ALL_BREAKPOINTS (b) | |
1095 | if (b->type == bp_static_tracepoint) | |
1096 | { | |
1097 | for (loc = b->loc; loc; loc = loc->next) | |
1098 | if (loc->address == addr) | |
1099 | VEC_safe_push(breakpoint_p, found, b); | |
1100 | } | |
1101 | ||
1102 | return found; | |
1103 | } | |
1104 | ||
95a42b64 | 1105 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 1106 | validate that only allowed commands are included. */ |
95a42b64 TT |
1107 | |
1108 | void | |
4a64f543 MS |
1109 | breakpoint_set_commands (struct breakpoint *b, |
1110 | struct command_line *commands) | |
95a42b64 TT |
1111 | { |
1112 | validate_commands_for_breakpoint (b, commands); | |
a7bdde9e | 1113 | |
9add0f1b TT |
1114 | decref_counted_command_line (&b->commands); |
1115 | b->commands = alloc_counted_command_line (commands); | |
48cb2d85 | 1116 | breakpoints_changed (); |
8d3788bd | 1117 | observer_notify_breakpoint_modified (b); |
48cb2d85 VP |
1118 | } |
1119 | ||
45a43567 TT |
1120 | /* Set the internal `silent' flag on the breakpoint. Note that this |
1121 | is not the same as the "silent" that may appear in the breakpoint's | |
1122 | commands. */ | |
1123 | ||
1124 | void | |
1125 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
1126 | { | |
1127 | int old_silent = b->silent; | |
1128 | ||
1129 | b->silent = silent; | |
1130 | if (old_silent != silent) | |
8d3788bd | 1131 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1132 | } |
1133 | ||
1134 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
1135 | breakpoint work for any thread. */ | |
1136 | ||
1137 | void | |
1138 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
1139 | { | |
1140 | int old_thread = b->thread; | |
1141 | ||
1142 | b->thread = thread; | |
1143 | if (old_thread != thread) | |
8d3788bd | 1144 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1145 | } |
1146 | ||
1147 | /* Set the task for this breakpoint. If TASK is 0, make the | |
1148 | breakpoint work for any task. */ | |
1149 | ||
1150 | void | |
1151 | breakpoint_set_task (struct breakpoint *b, int task) | |
1152 | { | |
1153 | int old_task = b->task; | |
1154 | ||
1155 | b->task = task; | |
1156 | if (old_task != task) | |
8d3788bd | 1157 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1158 | } |
1159 | ||
95a42b64 TT |
1160 | void |
1161 | check_tracepoint_command (char *line, void *closure) | |
a7bdde9e VP |
1162 | { |
1163 | struct breakpoint *b = closure; | |
cc59ec59 | 1164 | |
a7bdde9e VP |
1165 | validate_actionline (&line, b); |
1166 | } | |
1167 | ||
95a42b64 TT |
1168 | /* A structure used to pass information through |
1169 | map_breakpoint_numbers. */ | |
1170 | ||
1171 | struct commands_info | |
1172 | { | |
1173 | /* True if the command was typed at a tty. */ | |
1174 | int from_tty; | |
86b17b60 PA |
1175 | |
1176 | /* The breakpoint range spec. */ | |
1177 | char *arg; | |
1178 | ||
95a42b64 TT |
1179 | /* Non-NULL if the body of the commands are being read from this |
1180 | already-parsed command. */ | |
1181 | struct command_line *control; | |
86b17b60 | 1182 | |
95a42b64 TT |
1183 | /* The command lines read from the user, or NULL if they have not |
1184 | yet been read. */ | |
1185 | struct counted_command_line *cmd; | |
1186 | }; | |
1187 | ||
1188 | /* A callback for map_breakpoint_numbers that sets the commands for | |
1189 | commands_command. */ | |
1190 | ||
c906108c | 1191 | static void |
95a42b64 | 1192 | do_map_commands_command (struct breakpoint *b, void *data) |
c906108c | 1193 | { |
95a42b64 | 1194 | struct commands_info *info = data; |
c906108c | 1195 | |
95a42b64 TT |
1196 | if (info->cmd == NULL) |
1197 | { | |
1198 | struct command_line *l; | |
5c44784c | 1199 | |
95a42b64 TT |
1200 | if (info->control != NULL) |
1201 | l = copy_command_lines (info->control->body_list[0]); | |
1202 | else | |
86b17b60 PA |
1203 | { |
1204 | struct cleanup *old_chain; | |
1205 | char *str; | |
c5aa993b | 1206 | |
3e43a32a MS |
1207 | str = xstrprintf (_("Type commands for breakpoint(s) " |
1208 | "%s, one per line."), | |
86b17b60 PA |
1209 | info->arg); |
1210 | ||
1211 | old_chain = make_cleanup (xfree, str); | |
1212 | ||
1213 | l = read_command_lines (str, | |
1214 | info->from_tty, 1, | |
d77f58be | 1215 | (is_tracepoint (b) |
86b17b60 PA |
1216 | ? check_tracepoint_command : 0), |
1217 | b); | |
1218 | ||
1219 | do_cleanups (old_chain); | |
1220 | } | |
a7bdde9e | 1221 | |
95a42b64 TT |
1222 | info->cmd = alloc_counted_command_line (l); |
1223 | } | |
1224 | ||
1225 | /* If a breakpoint was on the list more than once, we don't need to | |
1226 | do anything. */ | |
1227 | if (b->commands != info->cmd) | |
1228 | { | |
1229 | validate_commands_for_breakpoint (b, info->cmd->commands); | |
1230 | incref_counted_command_line (info->cmd); | |
1231 | decref_counted_command_line (&b->commands); | |
1232 | b->commands = info->cmd; | |
1233 | breakpoints_changed (); | |
8d3788bd | 1234 | observer_notify_breakpoint_modified (b); |
c5aa993b | 1235 | } |
95a42b64 TT |
1236 | } |
1237 | ||
1238 | static void | |
4a64f543 MS |
1239 | commands_command_1 (char *arg, int from_tty, |
1240 | struct command_line *control) | |
95a42b64 TT |
1241 | { |
1242 | struct cleanup *cleanups; | |
1243 | struct commands_info info; | |
1244 | ||
1245 | info.from_tty = from_tty; | |
1246 | info.control = control; | |
1247 | info.cmd = NULL; | |
1248 | /* If we read command lines from the user, then `info' will hold an | |
1249 | extra reference to the commands that we must clean up. */ | |
1250 | cleanups = make_cleanup_decref_counted_command_line (&info.cmd); | |
1251 | ||
1252 | if (arg == NULL || !*arg) | |
1253 | { | |
86b17b60 | 1254 | if (breakpoint_count - prev_breakpoint_count > 1) |
4a64f543 MS |
1255 | arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1, |
1256 | breakpoint_count); | |
95a42b64 TT |
1257 | else if (breakpoint_count > 0) |
1258 | arg = xstrprintf ("%d", breakpoint_count); | |
86b17b60 PA |
1259 | else |
1260 | { | |
1261 | /* So that we don't try to free the incoming non-NULL | |
1262 | argument in the cleanup below. Mapping breakpoint | |
1263 | numbers will fail in this case. */ | |
1264 | arg = NULL; | |
1265 | } | |
95a42b64 | 1266 | } |
9766ced4 SS |
1267 | else |
1268 | /* The command loop has some static state, so we need to preserve | |
1269 | our argument. */ | |
1270 | arg = xstrdup (arg); | |
86b17b60 PA |
1271 | |
1272 | if (arg != NULL) | |
1273 | make_cleanup (xfree, arg); | |
1274 | ||
1275 | info.arg = arg; | |
95a42b64 TT |
1276 | |
1277 | map_breakpoint_numbers (arg, do_map_commands_command, &info); | |
1278 | ||
1279 | if (info.cmd == NULL) | |
1280 | error (_("No breakpoints specified.")); | |
1281 | ||
1282 | do_cleanups (cleanups); | |
1283 | } | |
1284 | ||
1285 | static void | |
1286 | commands_command (char *arg, int from_tty) | |
1287 | { | |
1288 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1289 | } |
40c03ae8 EZ |
1290 | |
1291 | /* Like commands_command, but instead of reading the commands from | |
1292 | input stream, takes them from an already parsed command structure. | |
1293 | ||
1294 | This is used by cli-script.c to DTRT with breakpoint commands | |
1295 | that are part of if and while bodies. */ | |
1296 | enum command_control_type | |
1297 | commands_from_control_command (char *arg, struct command_line *cmd) | |
1298 | { | |
95a42b64 TT |
1299 | commands_command_1 (arg, 0, cmd); |
1300 | return simple_control; | |
40c03ae8 | 1301 | } |
876fa593 JK |
1302 | |
1303 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1304 | ||
1305 | static int | |
1306 | bp_location_has_shadow (struct bp_location *bl) | |
1307 | { | |
1308 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1309 | return 0; | |
1310 | if (!bl->inserted) | |
1311 | return 0; | |
1312 | if (bl->target_info.shadow_len == 0) | |
e5dd4106 | 1313 | /* BL isn't valid, or doesn't shadow memory. */ |
876fa593 JK |
1314 | return 0; |
1315 | return 1; | |
1316 | } | |
1317 | ||
8defab1a | 1318 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1319 | by replacing any memory breakpoints with their shadowed contents. |
1320 | ||
1321 | The range of shadowed area by each bp_location is: | |
35df4500 TJB |
1322 | bl->address - bp_location_placed_address_before_address_max |
1323 | up to bl->address + bp_location_shadow_len_after_address_max | |
876fa593 JK |
1324 | The range we were requested to resolve shadows for is: |
1325 | memaddr ... memaddr + len | |
1326 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 TJB |
1327 | memaddr + len <= (bl->address |
1328 | - bp_location_placed_address_before_address_max) | |
876fa593 | 1329 | and: |
35df4500 | 1330 | bl->address + bp_location_shadow_len_after_address_max <= memaddr */ |
c906108c | 1331 | |
8defab1a | 1332 | void |
f0ba3972 PA |
1333 | breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, |
1334 | const gdb_byte *writebuf_org, | |
1335 | ULONGEST memaddr, LONGEST len) | |
c906108c | 1336 | { |
4a64f543 MS |
1337 | /* Left boundary, right boundary and median element of our binary |
1338 | search. */ | |
876fa593 JK |
1339 | unsigned bc_l, bc_r, bc; |
1340 | ||
4a64f543 MS |
1341 | /* Find BC_L which is a leftmost element which may affect BUF |
1342 | content. It is safe to report lower value but a failure to | |
1343 | report higher one. */ | |
876fa593 JK |
1344 | |
1345 | bc_l = 0; | |
1346 | bc_r = bp_location_count; | |
1347 | while (bc_l + 1 < bc_r) | |
1348 | { | |
35df4500 | 1349 | struct bp_location *bl; |
876fa593 JK |
1350 | |
1351 | bc = (bc_l + bc_r) / 2; | |
35df4500 | 1352 | bl = bp_location[bc]; |
876fa593 | 1353 | |
4a64f543 MS |
1354 | /* Check first BL->ADDRESS will not overflow due to the added |
1355 | constant. Then advance the left boundary only if we are sure | |
1356 | the BC element can in no way affect the BUF content (MEMADDR | |
1357 | to MEMADDR + LEN range). | |
876fa593 | 1358 | |
4a64f543 MS |
1359 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
1360 | offset so that we cannot miss a breakpoint with its shadow | |
1361 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1362 | |
35df4500 TJB |
1363 | if ((bl->address + bp_location_shadow_len_after_address_max |
1364 | >= bl->address) | |
1365 | && (bl->address + bp_location_shadow_len_after_address_max | |
1366 | <= memaddr)) | |
876fa593 JK |
1367 | bc_l = bc; |
1368 | else | |
1369 | bc_r = bc; | |
1370 | } | |
1371 | ||
128070bb PA |
1372 | /* Due to the binary search above, we need to make sure we pick the |
1373 | first location that's at BC_L's address. E.g., if there are | |
1374 | multiple locations at the same address, BC_L may end up pointing | |
1375 | at a duplicate location, and miss the "master"/"inserted" | |
1376 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1377 | B: | |
1378 | ||
1379 | L1@A, L2@A, L3@B, ... | |
1380 | ||
1381 | BC_L could end up pointing at location L2, while the "master" | |
1382 | location could be L1. Since the `loc->inserted' flag is only set | |
1383 | on "master" locations, we'd forget to restore the shadow of L1 | |
1384 | and L2. */ | |
1385 | while (bc_l > 0 | |
1386 | && bp_location[bc_l]->address == bp_location[bc_l - 1]->address) | |
1387 | bc_l--; | |
1388 | ||
876fa593 JK |
1389 | /* Now do full processing of the found relevant range of elements. */ |
1390 | ||
1391 | for (bc = bc_l; bc < bp_location_count; bc++) | |
c5aa993b | 1392 | { |
35df4500 | 1393 | struct bp_location *bl = bp_location[bc]; |
876fa593 JK |
1394 | CORE_ADDR bp_addr = 0; |
1395 | int bp_size = 0; | |
1396 | int bptoffset = 0; | |
1397 | ||
35df4500 TJB |
1398 | /* bp_location array has BL->OWNER always non-NULL. */ |
1399 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1400 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1401 | bl->owner->number); |
ffce0d52 | 1402 | |
e5dd4106 | 1403 | /* Performance optimization: any further element can no longer affect BUF |
876fa593 JK |
1404 | content. */ |
1405 | ||
35df4500 TJB |
1406 | if (bl->address >= bp_location_placed_address_before_address_max |
1407 | && memaddr + len <= (bl->address | |
1408 | - bp_location_placed_address_before_address_max)) | |
876fa593 JK |
1409 | break; |
1410 | ||
35df4500 | 1411 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1412 | continue; |
35df4500 | 1413 | if (!breakpoint_address_match (bl->target_info.placed_address_space, 0, |
6c95b8df PA |
1414 | current_program_space->aspace, 0)) |
1415 | continue; | |
1416 | ||
c5aa993b JM |
1417 | /* Addresses and length of the part of the breakpoint that |
1418 | we need to copy. */ | |
35df4500 TJB |
1419 | bp_addr = bl->target_info.placed_address; |
1420 | bp_size = bl->target_info.shadow_len; | |
8defab1a | 1421 | |
c5aa993b JM |
1422 | if (bp_addr + bp_size <= memaddr) |
1423 | /* The breakpoint is entirely before the chunk of memory we | |
1424 | are reading. */ | |
1425 | continue; | |
8defab1a | 1426 | |
c5aa993b JM |
1427 | if (bp_addr >= memaddr + len) |
1428 | /* The breakpoint is entirely after the chunk of memory we are | |
4a64f543 | 1429 | reading. */ |
c5aa993b | 1430 | continue; |
c5aa993b | 1431 | |
8defab1a DJ |
1432 | /* Offset within shadow_contents. */ |
1433 | if (bp_addr < memaddr) | |
1434 | { | |
1435 | /* Only copy the second part of the breakpoint. */ | |
1436 | bp_size -= memaddr - bp_addr; | |
1437 | bptoffset = memaddr - bp_addr; | |
1438 | bp_addr = memaddr; | |
1439 | } | |
c5aa993b | 1440 | |
8defab1a DJ |
1441 | if (bp_addr + bp_size > memaddr + len) |
1442 | { | |
1443 | /* Only copy the first part of the breakpoint. */ | |
1444 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1445 | } | |
c5aa993b | 1446 | |
f0ba3972 PA |
1447 | if (readbuf != NULL) |
1448 | { | |
1449 | /* Update the read buffer with this inserted breakpoint's | |
1450 | shadow. */ | |
1451 | memcpy (readbuf + bp_addr - memaddr, | |
1452 | bl->target_info.shadow_contents + bptoffset, bp_size); | |
1453 | } | |
1454 | else | |
1455 | { | |
1456 | struct gdbarch *gdbarch = bl->gdbarch; | |
1457 | const unsigned char *bp; | |
1458 | CORE_ADDR placed_address = bl->target_info.placed_address; | |
1459 | unsigned placed_size = bl->target_info.placed_size; | |
1460 | ||
1461 | /* Update the shadow with what we want to write to memory. */ | |
1462 | memcpy (bl->target_info.shadow_contents + bptoffset, | |
1463 | writebuf_org + bp_addr - memaddr, bp_size); | |
1464 | ||
1465 | /* Determine appropriate breakpoint contents and size for this | |
1466 | address. */ | |
1467 | bp = gdbarch_breakpoint_from_pc (gdbarch, &placed_address, &placed_size); | |
1468 | ||
1469 | /* Update the final write buffer with this inserted | |
1470 | breakpoint's INSN. */ | |
1471 | memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size); | |
1472 | } | |
c5aa993b | 1473 | } |
c906108c | 1474 | } |
c906108c | 1475 | \f |
c5aa993b | 1476 | |
b775012e LM |
1477 | /* Return true if BPT is either a software breakpoint or a hardware |
1478 | breakpoint. */ | |
1479 | ||
1480 | int | |
1481 | is_breakpoint (const struct breakpoint *bpt) | |
1482 | { | |
1483 | return (bpt->type == bp_breakpoint | |
1484 | || bpt->type == bp_hardware_breakpoint); | |
1485 | } | |
1486 | ||
60e1c644 PA |
1487 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1488 | ||
a5606eee | 1489 | static int |
d77f58be | 1490 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1491 | { |
1492 | return (bpt->type == bp_hardware_watchpoint | |
1493 | || bpt->type == bp_read_watchpoint | |
1494 | || bpt->type == bp_access_watchpoint); | |
1495 | } | |
7270d8f2 | 1496 | |
60e1c644 PA |
1497 | /* Return true if BPT is of any watchpoint kind, hardware or |
1498 | software. */ | |
1499 | ||
3a5c3e22 | 1500 | int |
d77f58be | 1501 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1502 | { |
1503 | return (is_hardware_watchpoint (bpt) | |
1504 | || bpt->type == bp_watchpoint); | |
1505 | } | |
1506 | ||
3a5c3e22 PA |
1507 | /* Returns true if the current thread and its running state are safe |
1508 | to evaluate or update watchpoint B. Watchpoints on local | |
1509 | expressions need to be evaluated in the context of the thread that | |
1510 | was current when the watchpoint was created, and, that thread needs | |
1511 | to be stopped to be able to select the correct frame context. | |
1512 | Watchpoints on global expressions can be evaluated on any thread, | |
1513 | and in any state. It is presently left to the target allowing | |
1514 | memory accesses when threads are running. */ | |
f6bc2008 PA |
1515 | |
1516 | static int | |
3a5c3e22 | 1517 | watchpoint_in_thread_scope (struct watchpoint *b) |
f6bc2008 | 1518 | { |
d0d8b0c6 JK |
1519 | return (b->base.pspace == current_program_space |
1520 | && (ptid_equal (b->watchpoint_thread, null_ptid) | |
1521 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1522 | && !is_executing (inferior_ptid)))); | |
f6bc2008 PA |
1523 | } |
1524 | ||
d0fb5eae JK |
1525 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
1526 | associated bp_watchpoint_scope breakpoint. */ | |
1527 | ||
1528 | static void | |
3a5c3e22 | 1529 | watchpoint_del_at_next_stop (struct watchpoint *w) |
d0fb5eae | 1530 | { |
3a5c3e22 | 1531 | struct breakpoint *b = &w->base; |
d0fb5eae JK |
1532 | |
1533 | if (b->related_breakpoint != b) | |
1534 | { | |
1535 | gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope); | |
1536 | gdb_assert (b->related_breakpoint->related_breakpoint == b); | |
1537 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1538 | b->related_breakpoint->related_breakpoint = b->related_breakpoint; | |
1539 | b->related_breakpoint = b; | |
1540 | } | |
1541 | b->disposition = disp_del_at_next_stop; | |
1542 | } | |
1543 | ||
567e1b4e JB |
1544 | /* Assuming that B is a watchpoint: |
1545 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1546 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1547 | - Evaluate the condition if there is one, and store the result |
1548 | in b->loc->cond. | |
a5606eee VP |
1549 | - Update the list of values that must be watched in B->loc. |
1550 | ||
4a64f543 MS |
1551 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1552 | nothing. If this is local watchpoint that is out of scope, delete | |
1553 | it. | |
1554 | ||
1555 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1556 | removed + inserted on each stop here. Normal breakpoints must | |
1557 | never be removed because they might be missed by a running thread | |
1558 | when debugging in non-stop mode. On the other hand, hardware | |
1559 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1560 | to each LWP since they are stored in each LWP's hardware debug | |
1561 | registers. Therefore, such LWP must be stopped first in order to | |
1562 | be able to modify its hardware watchpoints. | |
1563 | ||
1564 | Hardware watchpoints must be reset exactly once after being | |
1565 | presented to the user. It cannot be done sooner, because it would | |
1566 | reset the data used to present the watchpoint hit to the user. And | |
1567 | it must not be done later because it could display the same single | |
1568 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1569 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1570 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1571 | not user-visible - its hit is suppressed if the memory content has | |
1572 | not changed. | |
1573 | ||
1574 | The following constraints influence the location where we can reset | |
1575 | hardware watchpoints: | |
1576 | ||
1577 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1578 | called several times when GDB stops. | |
1579 | ||
1580 | [linux] | |
1581 | * Multiple hardware watchpoints can be hit at the same time, | |
1582 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1583 | hit at a time as the reason for stopping, and all the other hits | |
1584 | are presented later, one after the other, each time the user | |
1585 | requests the execution to be resumed. Execution is not resumed | |
1586 | for the threads still having pending hit event stored in | |
1587 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1588 | the inferior on the first stop the thread hit event is kept being | |
1589 | reported from its cached value by linux_nat_stopped_data_address | |
1590 | until the real thread resume happens after the watchpoint gets | |
1591 | presented and thus its LWP_INFO->STATUS gets reset. | |
1592 | ||
1593 | Therefore the hardware watchpoint hit can get safely reset on the | |
1594 | watchpoint removal from inferior. */ | |
a79d3c27 | 1595 | |
b40ce68a | 1596 | static void |
3a5c3e22 | 1597 | update_watchpoint (struct watchpoint *b, int reparse) |
7270d8f2 | 1598 | { |
a5606eee | 1599 | int within_current_scope; |
a5606eee | 1600 | struct frame_id saved_frame_id; |
66076460 | 1601 | int frame_saved; |
a5606eee | 1602 | |
f6bc2008 PA |
1603 | /* If this is a local watchpoint, we only want to check if the |
1604 | watchpoint frame is in scope if the current thread is the thread | |
1605 | that was used to create the watchpoint. */ | |
1606 | if (!watchpoint_in_thread_scope (b)) | |
1607 | return; | |
1608 | ||
3a5c3e22 | 1609 | if (b->base.disposition == disp_del_at_next_stop) |
a5606eee VP |
1610 | return; |
1611 | ||
66076460 | 1612 | frame_saved = 0; |
a5606eee VP |
1613 | |
1614 | /* Determine if the watchpoint is within scope. */ | |
1615 | if (b->exp_valid_block == NULL) | |
1616 | within_current_scope = 1; | |
1617 | else | |
1618 | { | |
b5db5dfc UW |
1619 | struct frame_info *fi = get_current_frame (); |
1620 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1621 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1622 | ||
1623 | /* If we're in a function epilogue, unwinding may not work | |
1624 | properly, so do not attempt to recreate locations at this | |
1625 | point. See similar comments in watchpoint_check. */ | |
1626 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) | |
1627 | return; | |
66076460 DJ |
1628 | |
1629 | /* Save the current frame's ID so we can restore it after | |
1630 | evaluating the watchpoint expression on its own frame. */ | |
1631 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1632 | took a frame parameter, so that we didn't have to change the | |
1633 | selected frame. */ | |
1634 | frame_saved = 1; | |
1635 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1636 | ||
a5606eee VP |
1637 | fi = frame_find_by_id (b->watchpoint_frame); |
1638 | within_current_scope = (fi != NULL); | |
1639 | if (within_current_scope) | |
1640 | select_frame (fi); | |
1641 | } | |
1642 | ||
b5db5dfc UW |
1643 | /* We don't free locations. They are stored in the bp_location array |
1644 | and update_global_location_list will eventually delete them and | |
1645 | remove breakpoints if needed. */ | |
3a5c3e22 | 1646 | b->base.loc = NULL; |
b5db5dfc | 1647 | |
a5606eee VP |
1648 | if (within_current_scope && reparse) |
1649 | { | |
1650 | char *s; | |
d63d0675 | 1651 | |
a5606eee VP |
1652 | if (b->exp) |
1653 | { | |
1654 | xfree (b->exp); | |
1655 | b->exp = NULL; | |
1656 | } | |
d63d0675 | 1657 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
a5606eee VP |
1658 | b->exp = parse_exp_1 (&s, b->exp_valid_block, 0); |
1659 | /* If the meaning of expression itself changed, the old value is | |
1660 | no longer relevant. We don't want to report a watchpoint hit | |
1661 | to the user when the old value and the new value may actually | |
1662 | be completely different objects. */ | |
1663 | value_free (b->val); | |
fa4727a6 DJ |
1664 | b->val = NULL; |
1665 | b->val_valid = 0; | |
60e1c644 PA |
1666 | |
1667 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1668 | expression is stored in the breakpoint object, not in the | |
1669 | locations (re)created below. */ | |
3a5c3e22 | 1670 | if (b->base.cond_string != NULL) |
60e1c644 PA |
1671 | { |
1672 | if (b->cond_exp != NULL) | |
1673 | { | |
1674 | xfree (b->cond_exp); | |
1675 | b->cond_exp = NULL; | |
1676 | } | |
1677 | ||
3a5c3e22 | 1678 | s = b->base.cond_string; |
60e1c644 PA |
1679 | b->cond_exp = parse_exp_1 (&s, b->cond_exp_valid_block, 0); |
1680 | } | |
a5606eee | 1681 | } |
a5606eee VP |
1682 | |
1683 | /* If we failed to parse the expression, for example because | |
1684 | it refers to a global variable in a not-yet-loaded shared library, | |
1685 | don't try to insert watchpoint. We don't automatically delete | |
1686 | such watchpoint, though, since failure to parse expression | |
1687 | is different from out-of-scope watchpoint. */ | |
2d134ed3 PA |
1688 | if ( !target_has_execution) |
1689 | { | |
1690 | /* Without execution, memory can't change. No use to try and | |
1691 | set watchpoint locations. The watchpoint will be reset when | |
1692 | the target gains execution, through breakpoint_re_set. */ | |
1693 | } | |
1694 | else if (within_current_scope && b->exp) | |
a5606eee | 1695 | { |
0cf6dd15 | 1696 | int pc = 0; |
fa4727a6 | 1697 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1698 | struct program_space *frame_pspace; |
a5606eee | 1699 | |
0cf6dd15 | 1700 | fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain); |
a5606eee | 1701 | |
a5606eee VP |
1702 | /* Avoid setting b->val if it's already set. The meaning of |
1703 | b->val is 'the last value' user saw, and we should update | |
1704 | it only if we reported that last value to user. As it | |
9c06b0b4 TJB |
1705 | happens, the code that reports it updates b->val directly. |
1706 | We don't keep track of the memory value for masked | |
1707 | watchpoints. */ | |
3a5c3e22 | 1708 | if (!b->val_valid && !is_masked_watchpoint (&b->base)) |
fa4727a6 DJ |
1709 | { |
1710 | b->val = v; | |
1711 | b->val_valid = 1; | |
1712 | } | |
a5606eee | 1713 | |
2d134ed3 PA |
1714 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1715 | ||
a5606eee | 1716 | /* Look at each value on the value chain. */ |
9fa40276 | 1717 | for (v = val_chain; v; v = value_next (v)) |
a5606eee VP |
1718 | { |
1719 | /* If it's a memory location, and GDB actually needed | |
1720 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1721 | must watch it. If the first value returned is |
1722 | still lazy, that means an error occurred reading it; | |
1723 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1724 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1725 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1726 | { |
1727 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1728 | |
a5606eee VP |
1729 | /* We only watch structs and arrays if user asked |
1730 | for it explicitly, never if they just happen to | |
1731 | appear in the middle of some value chain. */ | |
fa4727a6 | 1732 | if (v == result |
a5606eee VP |
1733 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1734 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1735 | { | |
1736 | CORE_ADDR addr; | |
1737 | int len, type; | |
1738 | struct bp_location *loc, **tmp; | |
1739 | ||
42ae5230 | 1740 | addr = value_address (v); |
a5606eee VP |
1741 | len = TYPE_LENGTH (value_type (v)); |
1742 | type = hw_write; | |
3a5c3e22 | 1743 | if (b->base.type == bp_read_watchpoint) |
a5606eee | 1744 | type = hw_read; |
3a5c3e22 | 1745 | else if (b->base.type == bp_access_watchpoint) |
a5606eee | 1746 | type = hw_access; |
3a5c3e22 PA |
1747 | |
1748 | loc = allocate_bp_location (&b->base); | |
1749 | for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next)) | |
a5606eee VP |
1750 | ; |
1751 | *tmp = loc; | |
a6d9a66e | 1752 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1753 | |
1754 | loc->pspace = frame_pspace; | |
a5606eee VP |
1755 | loc->address = addr; |
1756 | loc->length = len; | |
1757 | loc->watchpoint_type = type; | |
1758 | } | |
1759 | } | |
9fa40276 TJB |
1760 | } |
1761 | ||
1762 | /* Change the type of breakpoint between hardware assisted or | |
1763 | an ordinary watchpoint depending on the hardware support | |
1764 | and free hardware slots. REPARSE is set when the inferior | |
1765 | is started. */ | |
a9634178 | 1766 | if (reparse) |
9fa40276 | 1767 | { |
e09342b5 | 1768 | int reg_cnt; |
9fa40276 TJB |
1769 | enum bp_loc_type loc_type; |
1770 | struct bp_location *bl; | |
a5606eee | 1771 | |
a9634178 | 1772 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
e09342b5 TJB |
1773 | |
1774 | if (reg_cnt) | |
9fa40276 TJB |
1775 | { |
1776 | int i, target_resources_ok, other_type_used; | |
a1398e0c | 1777 | enum bptype type; |
9fa40276 | 1778 | |
a9634178 TJB |
1779 | /* Use an exact watchpoint when there's only one memory region to be |
1780 | watched, and only one debug register is needed to watch it. */ | |
1781 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
1782 | ||
9fa40276 | 1783 | /* We need to determine how many resources are already |
e09342b5 TJB |
1784 | used for all other hardware watchpoints plus this one |
1785 | to see if we still have enough resources to also fit | |
a1398e0c PA |
1786 | this watchpoint in as well. */ |
1787 | ||
1788 | /* If this is a software watchpoint, we try to turn it | |
1789 | to a hardware one -- count resources as if B was of | |
1790 | hardware watchpoint type. */ | |
1791 | type = b->base.type; | |
1792 | if (type == bp_watchpoint) | |
1793 | type = bp_hardware_watchpoint; | |
1794 | ||
1795 | /* This watchpoint may or may not have been placed on | |
1796 | the list yet at this point (it won't be in the list | |
1797 | if we're trying to create it for the first time, | |
1798 | through watch_command), so always account for it | |
1799 | manually. */ | |
1800 | ||
1801 | /* Count resources used by all watchpoints except B. */ | |
1802 | i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used); | |
1803 | ||
1804 | /* Add in the resources needed for B. */ | |
1805 | i += hw_watchpoint_use_count (&b->base); | |
1806 | ||
1807 | target_resources_ok | |
1808 | = target_can_use_hardware_watchpoint (type, i, other_type_used); | |
e09342b5 | 1809 | if (target_resources_ok <= 0) |
a9634178 | 1810 | { |
3a5c3e22 | 1811 | int sw_mode = b->base.ops->works_in_software_mode (&b->base); |
9c06b0b4 TJB |
1812 | |
1813 | if (target_resources_ok == 0 && !sw_mode) | |
a9634178 TJB |
1814 | error (_("Target does not support this type of " |
1815 | "hardware watchpoint.")); | |
9c06b0b4 TJB |
1816 | else if (target_resources_ok < 0 && !sw_mode) |
1817 | error (_("There are not enough available hardware " | |
1818 | "resources for this watchpoint.")); | |
a1398e0c PA |
1819 | |
1820 | /* Downgrade to software watchpoint. */ | |
1821 | b->base.type = bp_watchpoint; | |
1822 | } | |
1823 | else | |
1824 | { | |
1825 | /* If this was a software watchpoint, we've just | |
1826 | found we have enough resources to turn it to a | |
1827 | hardware watchpoint. Otherwise, this is a | |
1828 | nop. */ | |
1829 | b->base.type = type; | |
a9634178 | 1830 | } |
9fa40276 | 1831 | } |
3a5c3e22 | 1832 | else if (!b->base.ops->works_in_software_mode (&b->base)) |
a9634178 TJB |
1833 | error (_("Expression cannot be implemented with " |
1834 | "read/access watchpoint.")); | |
9fa40276 | 1835 | else |
3a5c3e22 | 1836 | b->base.type = bp_watchpoint; |
9fa40276 | 1837 | |
3a5c3e22 | 1838 | loc_type = (b->base.type == bp_watchpoint? bp_loc_other |
9fa40276 | 1839 | : bp_loc_hardware_watchpoint); |
3a5c3e22 | 1840 | for (bl = b->base.loc; bl; bl = bl->next) |
9fa40276 TJB |
1841 | bl->loc_type = loc_type; |
1842 | } | |
1843 | ||
1844 | for (v = val_chain; v; v = next) | |
1845 | { | |
a5606eee VP |
1846 | next = value_next (v); |
1847 | if (v != b->val) | |
1848 | value_free (v); | |
1849 | } | |
1850 | ||
c7437ca6 PA |
1851 | /* If a software watchpoint is not watching any memory, then the |
1852 | above left it without any location set up. But, | |
1853 | bpstat_stop_status requires a location to be able to report | |
1854 | stops, so make sure there's at least a dummy one. */ | |
3a5c3e22 | 1855 | if (b->base.type == bp_watchpoint && b->base.loc == NULL) |
c7437ca6 | 1856 | { |
3a5c3e22 PA |
1857 | struct breakpoint *base = &b->base; |
1858 | base->loc = allocate_bp_location (base); | |
1859 | base->loc->pspace = frame_pspace; | |
1860 | base->loc->address = -1; | |
1861 | base->loc->length = -1; | |
1862 | base->loc->watchpoint_type = -1; | |
c7437ca6 | 1863 | } |
a5606eee VP |
1864 | } |
1865 | else if (!within_current_scope) | |
7270d8f2 | 1866 | { |
ac74f770 MS |
1867 | printf_filtered (_("\ |
1868 | Watchpoint %d deleted because the program has left the block\n\ | |
1869 | in which its expression is valid.\n"), | |
3a5c3e22 | 1870 | b->base.number); |
d0fb5eae | 1871 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 1872 | } |
a5606eee VP |
1873 | |
1874 | /* Restore the selected frame. */ | |
66076460 DJ |
1875 | if (frame_saved) |
1876 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
1877 | } |
1878 | ||
a5606eee | 1879 | |
74960c60 | 1880 | /* Returns 1 iff breakpoint location should be |
1e4d1764 YQ |
1881 | inserted in the inferior. We don't differentiate the type of BL's owner |
1882 | (breakpoint vs. tracepoint), although insert_location in tracepoint's | |
1883 | breakpoint_ops is not defined, because in insert_bp_location, | |
1884 | tracepoint's insert_location will not be called. */ | |
74960c60 | 1885 | static int |
35df4500 | 1886 | should_be_inserted (struct bp_location *bl) |
74960c60 | 1887 | { |
35df4500 | 1888 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
1889 | return 0; |
1890 | ||
35df4500 | 1891 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
1892 | return 0; |
1893 | ||
35df4500 | 1894 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
1895 | return 0; |
1896 | ||
f8eba3c6 TT |
1897 | if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup) |
1898 | return 0; | |
1899 | ||
56710373 PA |
1900 | /* This is set for example, when we're attached to the parent of a |
1901 | vfork, and have detached from the child. The child is running | |
1902 | free, and we expect it to do an exec or exit, at which point the | |
1903 | OS makes the parent schedulable again (and the target reports | |
1904 | that the vfork is done). Until the child is done with the shared | |
1905 | memory region, do not insert breakpoints in the parent, otherwise | |
1906 | the child could still trip on the parent's breakpoints. Since | |
1907 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 1908 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
1909 | return 0; |
1910 | ||
74960c60 VP |
1911 | return 1; |
1912 | } | |
1913 | ||
934709f0 PW |
1914 | /* Same as should_be_inserted but does the check assuming |
1915 | that the location is not duplicated. */ | |
1916 | ||
1917 | static int | |
1918 | unduplicated_should_be_inserted (struct bp_location *bl) | |
1919 | { | |
1920 | int result; | |
1921 | const int save_duplicate = bl->duplicate; | |
1922 | ||
1923 | bl->duplicate = 0; | |
1924 | result = should_be_inserted (bl); | |
1925 | bl->duplicate = save_duplicate; | |
1926 | return result; | |
1927 | } | |
1928 | ||
b775012e LM |
1929 | /* Parses a conditional described by an expression COND into an |
1930 | agent expression bytecode suitable for evaluation | |
1931 | by the bytecode interpreter. Return NULL if there was | |
1932 | any error during parsing. */ | |
1933 | ||
1934 | static struct agent_expr * | |
1935 | parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond) | |
1936 | { | |
1937 | struct agent_expr *aexpr = NULL; | |
1938 | struct cleanup *old_chain = NULL; | |
1939 | volatile struct gdb_exception ex; | |
1940 | ||
1941 | if (!cond) | |
1942 | return NULL; | |
1943 | ||
1944 | /* We don't want to stop processing, so catch any errors | |
1945 | that may show up. */ | |
1946 | TRY_CATCH (ex, RETURN_MASK_ERROR) | |
1947 | { | |
1948 | aexpr = gen_eval_for_expr (scope, cond); | |
1949 | } | |
1950 | ||
1951 | if (ex.reason < 0) | |
1952 | { | |
1953 | /* If we got here, it means the condition could not be parsed to a valid | |
1954 | bytecode expression and thus can't be evaluated on the target's side. | |
1955 | It's no use iterating through the conditions. */ | |
1956 | return NULL; | |
1957 | } | |
1958 | ||
1959 | /* We have a valid agent expression. */ | |
1960 | return aexpr; | |
1961 | } | |
1962 | ||
1963 | /* Based on location BL, create a list of breakpoint conditions to be | |
1964 | passed on to the target. If we have duplicated locations with different | |
1965 | conditions, we will add such conditions to the list. The idea is that the | |
1966 | target will evaluate the list of conditions and will only notify GDB when | |
1967 | one of them is true. */ | |
1968 | ||
1969 | static void | |
1970 | build_target_condition_list (struct bp_location *bl) | |
1971 | { | |
1972 | struct bp_location **locp = NULL, **loc2p; | |
1973 | int null_condition_or_parse_error = 0; | |
1974 | int modified = bl->needs_update; | |
1975 | struct bp_location *loc; | |
1976 | ||
1977 | /* This is only meaningful if the target is | |
1978 | evaluating conditions and if the user has | |
1979 | opted for condition evaluation on the target's | |
1980 | side. */ | |
1981 | if (gdb_evaluates_breakpoint_condition_p () | |
1982 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
1983 | return; | |
1984 | ||
1985 | /* Do a first pass to check for locations with no assigned | |
1986 | conditions or conditions that fail to parse to a valid agent expression | |
1987 | bytecode. If any of these happen, then it's no use to send conditions | |
1988 | to the target since this location will always trigger and generate a | |
1989 | response back to GDB. */ | |
1990 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
1991 | { | |
1992 | loc = (*loc2p); | |
1993 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
1994 | { | |
1995 | if (modified) | |
1996 | { | |
1997 | struct agent_expr *aexpr; | |
1998 | ||
1999 | /* Re-parse the conditions since something changed. In that | |
2000 | case we already freed the condition bytecodes (see | |
2001 | force_breakpoint_reinsertion). We just | |
2002 | need to parse the condition to bytecodes again. */ | |
2003 | aexpr = parse_cond_to_aexpr (bl->address, loc->cond); | |
2004 | loc->cond_bytecode = aexpr; | |
2005 | ||
2006 | /* Check if we managed to parse the conditional expression | |
2007 | correctly. If not, we will not send this condition | |
2008 | to the target. */ | |
2009 | if (aexpr) | |
2010 | continue; | |
2011 | } | |
2012 | ||
2013 | /* If we have a NULL bytecode expression, it means something | |
2014 | went wrong or we have a null condition expression. */ | |
2015 | if (!loc->cond_bytecode) | |
2016 | { | |
2017 | null_condition_or_parse_error = 1; | |
2018 | break; | |
2019 | } | |
2020 | } | |
2021 | } | |
2022 | ||
2023 | /* If any of these happened, it means we will have to evaluate the conditions | |
2024 | for the location's address on gdb's side. It is no use keeping bytecodes | |
2025 | for all the other duplicate locations, thus we free all of them here. | |
2026 | ||
2027 | This is so we have a finer control over which locations' conditions are | |
2028 | being evaluated by GDB or the remote stub. */ | |
2029 | if (null_condition_or_parse_error) | |
2030 | { | |
2031 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2032 | { | |
2033 | loc = (*loc2p); | |
2034 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2035 | { | |
2036 | /* Only go as far as the first NULL bytecode is | |
2037 | located. */ | |
2038 | if (!loc->cond_bytecode) | |
2039 | return; | |
2040 | ||
2041 | free_agent_expr (loc->cond_bytecode); | |
2042 | loc->cond_bytecode = NULL; | |
2043 | } | |
2044 | } | |
2045 | } | |
2046 | ||
2047 | /* No NULL conditions or failed bytecode generation. Build a condition list | |
2048 | for this location's address. */ | |
2049 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2050 | { | |
2051 | loc = (*loc2p); | |
2052 | if (loc->cond | |
2053 | && is_breakpoint (loc->owner) | |
2054 | && loc->pspace->num == bl->pspace->num | |
2055 | && loc->owner->enable_state == bp_enabled | |
2056 | && loc->enabled) | |
2057 | /* Add the condition to the vector. This will be used later to send the | |
2058 | conditions to the target. */ | |
2059 | VEC_safe_push (agent_expr_p, bl->target_info.conditions, | |
2060 | loc->cond_bytecode); | |
2061 | } | |
2062 | ||
2063 | return; | |
2064 | } | |
2065 | ||
35df4500 TJB |
2066 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
2067 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
3fbb6ffa | 2068 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
c30eee59 TJB |
2069 | Returns 0 for success, 1 if the bp_location type is not supported or |
2070 | -1 for failure. | |
879bfdc2 | 2071 | |
4a64f543 MS |
2072 | NOTE drow/2003-09-09: This routine could be broken down to an |
2073 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 2074 | static int |
35df4500 | 2075 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 2076 | struct ui_file *tmp_error_stream, |
3fbb6ffa | 2077 | int *disabled_breaks, |
26bb91f3 | 2078 | int *hw_breakpoint_error) |
879bfdc2 DJ |
2079 | { |
2080 | int val = 0; | |
2081 | ||
b775012e | 2082 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2083 | return 0; |
2084 | ||
8181d85f | 2085 | /* Initialize the target-specific information. */ |
35df4500 TJB |
2086 | memset (&bl->target_info, 0, sizeof (bl->target_info)); |
2087 | bl->target_info.placed_address = bl->address; | |
2088 | bl->target_info.placed_address_space = bl->pspace->aspace; | |
f1310107 | 2089 | bl->target_info.length = bl->length; |
8181d85f | 2090 | |
b775012e LM |
2091 | /* When working with target-side conditions, we must pass all the conditions |
2092 | for the same breakpoint address down to the target since GDB will not | |
2093 | insert those locations. With a list of breakpoint conditions, the target | |
2094 | can decide when to stop and notify GDB. */ | |
2095 | ||
2096 | if (is_breakpoint (bl->owner)) | |
2097 | { | |
2098 | build_target_condition_list (bl); | |
2099 | /* Reset the condition modification marker. */ | |
2100 | bl->needs_update = 0; | |
2101 | } | |
2102 | ||
35df4500 TJB |
2103 | if (bl->loc_type == bp_loc_software_breakpoint |
2104 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 2105 | { |
35df4500 | 2106 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
2107 | { |
2108 | /* If the explicitly specified breakpoint type | |
2109 | is not hardware breakpoint, check the memory map to see | |
2110 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 2111 | |
765dc015 VP |
2112 | Two important cases are: |
2113 | - location type is not hardware breakpoint, memory | |
2114 | is readonly. We change the type of the location to | |
2115 | hardware breakpoint. | |
4a64f543 MS |
2116 | - location type is hardware breakpoint, memory is |
2117 | read-write. This means we've previously made the | |
2118 | location hardware one, but then the memory map changed, | |
2119 | so we undo. | |
765dc015 | 2120 | |
4a64f543 MS |
2121 | When breakpoints are removed, remove_breakpoints will use |
2122 | location types we've just set here, the only possible | |
2123 | problem is that memory map has changed during running | |
2124 | program, but it's not going to work anyway with current | |
2125 | gdb. */ | |
765dc015 | 2126 | struct mem_region *mr |
35df4500 | 2127 | = lookup_mem_region (bl->target_info.placed_address); |
765dc015 VP |
2128 | |
2129 | if (mr) | |
2130 | { | |
2131 | if (automatic_hardware_breakpoints) | |
2132 | { | |
765dc015 VP |
2133 | enum bp_loc_type new_type; |
2134 | ||
2135 | if (mr->attrib.mode != MEM_RW) | |
2136 | new_type = bp_loc_hardware_breakpoint; | |
2137 | else | |
2138 | new_type = bp_loc_software_breakpoint; | |
2139 | ||
35df4500 | 2140 | if (new_type != bl->loc_type) |
765dc015 VP |
2141 | { |
2142 | static int said = 0; | |
cc59ec59 | 2143 | |
35df4500 | 2144 | bl->loc_type = new_type; |
765dc015 VP |
2145 | if (!said) |
2146 | { | |
3e43a32a MS |
2147 | fprintf_filtered (gdb_stdout, |
2148 | _("Note: automatically using " | |
2149 | "hardware breakpoints for " | |
2150 | "read-only addresses.\n")); | |
765dc015 VP |
2151 | said = 1; |
2152 | } | |
2153 | } | |
2154 | } | |
35df4500 | 2155 | else if (bl->loc_type == bp_loc_software_breakpoint |
765dc015 | 2156 | && mr->attrib.mode != MEM_RW) |
3e43a32a MS |
2157 | warning (_("cannot set software breakpoint " |
2158 | "at readonly address %s"), | |
35df4500 | 2159 | paddress (bl->gdbarch, bl->address)); |
765dc015 VP |
2160 | } |
2161 | } | |
2162 | ||
879bfdc2 DJ |
2163 | /* First check to see if we have to handle an overlay. */ |
2164 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2165 | || bl->section == NULL |
2166 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
2167 | { |
2168 | /* No overlay handling: just set the breakpoint. */ | |
2169 | ||
348d480f | 2170 | val = bl->owner->ops->insert_location (bl); |
879bfdc2 DJ |
2171 | } |
2172 | else | |
2173 | { | |
4a64f543 | 2174 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
2175 | Shall we set a breakpoint at the LMA? */ |
2176 | if (!overlay_events_enabled) | |
2177 | { | |
2178 | /* Yes -- overlay event support is not active, | |
2179 | so we must try to set a breakpoint at the LMA. | |
2180 | This will not work for a hardware breakpoint. */ | |
35df4500 | 2181 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 2182 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 2183 | bl->owner->number); |
879bfdc2 DJ |
2184 | else |
2185 | { | |
35df4500 TJB |
2186 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
2187 | bl->section); | |
879bfdc2 | 2188 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 TJB |
2189 | bl->overlay_target_info = bl->target_info; |
2190 | bl->overlay_target_info.placed_address = addr; | |
2191 | val = target_insert_breakpoint (bl->gdbarch, | |
2192 | &bl->overlay_target_info); | |
879bfdc2 | 2193 | if (val != 0) |
99361f52 | 2194 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
2195 | "Overlay breakpoint %d " |
2196 | "failed: in ROM?\n", | |
35df4500 | 2197 | bl->owner->number); |
879bfdc2 DJ |
2198 | } |
2199 | } | |
2200 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 2201 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
2202 | { |
2203 | /* Yes. This overlay section is mapped into memory. */ | |
348d480f | 2204 | val = bl->owner->ops->insert_location (bl); |
879bfdc2 DJ |
2205 | } |
2206 | else | |
2207 | { | |
2208 | /* No. This breakpoint will not be inserted. | |
2209 | No error, but do not mark the bp as 'inserted'. */ | |
2210 | return 0; | |
2211 | } | |
2212 | } | |
2213 | ||
2214 | if (val) | |
2215 | { | |
2216 | /* Can't set the breakpoint. */ | |
35df4500 | 2217 | if (solib_name_from_address (bl->pspace, bl->address)) |
879bfdc2 | 2218 | { |
4a64f543 | 2219 | /* See also: disable_breakpoints_in_shlibs. */ |
879bfdc2 | 2220 | val = 0; |
35df4500 | 2221 | bl->shlib_disabled = 1; |
8d3788bd | 2222 | observer_notify_breakpoint_modified (bl->owner); |
3fbb6ffa TJB |
2223 | if (!*disabled_breaks) |
2224 | { | |
2225 | fprintf_unfiltered (tmp_error_stream, | |
2226 | "Cannot insert breakpoint %d.\n", | |
2227 | bl->owner->number); | |
2228 | fprintf_unfiltered (tmp_error_stream, | |
2229 | "Temporarily disabling shared " | |
2230 | "library breakpoints:\n"); | |
2231 | } | |
2232 | *disabled_breaks = 1; | |
879bfdc2 | 2233 | fprintf_unfiltered (tmp_error_stream, |
35df4500 | 2234 | "breakpoint #%d\n", bl->owner->number); |
879bfdc2 DJ |
2235 | } |
2236 | else | |
879bfdc2 | 2237 | { |
35df4500 | 2238 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 DJ |
2239 | { |
2240 | *hw_breakpoint_error = 1; | |
3e43a32a MS |
2241 | fprintf_unfiltered (tmp_error_stream, |
2242 | "Cannot insert hardware " | |
2243 | "breakpoint %d.\n", | |
35df4500 | 2244 | bl->owner->number); |
879bfdc2 DJ |
2245 | } |
2246 | else | |
2247 | { | |
2248 | fprintf_unfiltered (tmp_error_stream, | |
2249 | "Cannot insert breakpoint %d.\n", | |
35df4500 | 2250 | bl->owner->number); |
879bfdc2 DJ |
2251 | fprintf_filtered (tmp_error_stream, |
2252 | "Error accessing memory address "); | |
35df4500 | 2253 | fputs_filtered (paddress (bl->gdbarch, bl->address), |
5af949e3 | 2254 | tmp_error_stream); |
879bfdc2 DJ |
2255 | fprintf_filtered (tmp_error_stream, ": %s.\n", |
2256 | safe_strerror (val)); | |
2257 | } | |
2258 | ||
2259 | } | |
2260 | } | |
2261 | else | |
35df4500 | 2262 | bl->inserted = 1; |
879bfdc2 DJ |
2263 | |
2264 | return val; | |
2265 | } | |
2266 | ||
35df4500 | 2267 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 2268 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 2269 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 2270 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 2271 | { |
77b06cd7 TJB |
2272 | gdb_assert (bl->owner->ops != NULL |
2273 | && bl->owner->ops->insert_location != NULL); | |
2274 | ||
2275 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
2276 | |
2277 | /* If trying to set a read-watchpoint, and it turns out it's not | |
2278 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 2279 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
2280 | { |
2281 | struct bp_location *loc, **loc_temp; | |
2282 | ||
2283 | /* But don't try to insert it, if there's already another | |
2284 | hw_access location that would be considered a duplicate | |
2285 | of this one. */ | |
2286 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 2287 | if (loc != bl |
85d721b8 | 2288 | && loc->watchpoint_type == hw_access |
35df4500 | 2289 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 2290 | { |
35df4500 TJB |
2291 | bl->duplicate = 1; |
2292 | bl->inserted = 1; | |
2293 | bl->target_info = loc->target_info; | |
2294 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
2295 | val = 0; |
2296 | break; | |
2297 | } | |
2298 | ||
2299 | if (val == 1) | |
2300 | { | |
77b06cd7 TJB |
2301 | bl->watchpoint_type = hw_access; |
2302 | val = bl->owner->ops->insert_location (bl); | |
2303 | ||
2304 | if (val) | |
2305 | /* Back to the original value. */ | |
2306 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
2307 | } |
2308 | } | |
2309 | ||
35df4500 | 2310 | bl->inserted = (val == 0); |
879bfdc2 DJ |
2311 | } |
2312 | ||
35df4500 | 2313 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 2314 | { |
77b06cd7 TJB |
2315 | gdb_assert (bl->owner->ops != NULL |
2316 | && bl->owner->ops->insert_location != NULL); | |
2317 | ||
2318 | val = bl->owner->ops->insert_location (bl); | |
2319 | if (val) | |
2320 | { | |
2321 | bl->owner->enable_state = bp_disabled; | |
2322 | ||
2323 | if (val == 1) | |
2324 | warning (_("\ | |
2325 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
2326 | of catchpoint."), bl->owner->number); | |
2327 | else | |
2328 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
2329 | } | |
2330 | ||
2331 | bl->inserted = (val == 0); | |
1640b821 DJ |
2332 | |
2333 | /* We've already printed an error message if there was a problem | |
2334 | inserting this catchpoint, and we've disabled the catchpoint, | |
2335 | so just return success. */ | |
2336 | return 0; | |
879bfdc2 DJ |
2337 | } |
2338 | ||
2339 | return 0; | |
2340 | } | |
2341 | ||
6c95b8df PA |
2342 | /* This function is called when program space PSPACE is about to be |
2343 | deleted. It takes care of updating breakpoints to not reference | |
2344 | PSPACE anymore. */ | |
2345 | ||
2346 | void | |
2347 | breakpoint_program_space_exit (struct program_space *pspace) | |
2348 | { | |
2349 | struct breakpoint *b, *b_temp; | |
876fa593 | 2350 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
2351 | |
2352 | /* Remove any breakpoint that was set through this program space. */ | |
2353 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
2354 | { | |
2355 | if (b->pspace == pspace) | |
2356 | delete_breakpoint (b); | |
2357 | } | |
2358 | ||
2359 | /* Breakpoints set through other program spaces could have locations | |
2360 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 2361 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
2362 | { |
2363 | struct bp_location *tmp; | |
2364 | ||
2365 | if (loc->pspace == pspace) | |
2366 | { | |
2bdf28a0 | 2367 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
2368 | if (loc->owner->loc == loc) |
2369 | loc->owner->loc = loc->next; | |
2370 | else | |
2371 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
2372 | if (tmp->next == loc) | |
2373 | { | |
2374 | tmp->next = loc->next; | |
2375 | break; | |
2376 | } | |
2377 | } | |
2378 | } | |
2379 | ||
2380 | /* Now update the global location list to permanently delete the | |
2381 | removed locations above. */ | |
2382 | update_global_location_list (0); | |
2383 | } | |
2384 | ||
74960c60 VP |
2385 | /* Make sure all breakpoints are inserted in inferior. |
2386 | Throws exception on any error. | |
2387 | A breakpoint that is already inserted won't be inserted | |
2388 | again, so calling this function twice is safe. */ | |
2389 | void | |
2390 | insert_breakpoints (void) | |
2391 | { | |
2392 | struct breakpoint *bpt; | |
2393 | ||
2394 | ALL_BREAKPOINTS (bpt) | |
2395 | if (is_hardware_watchpoint (bpt)) | |
3a5c3e22 PA |
2396 | { |
2397 | struct watchpoint *w = (struct watchpoint *) bpt; | |
2398 | ||
2399 | update_watchpoint (w, 0 /* don't reparse. */); | |
2400 | } | |
74960c60 | 2401 | |
b60e7edf | 2402 | update_global_location_list (1); |
74960c60 | 2403 | |
c35b1492 PA |
2404 | /* update_global_location_list does not insert breakpoints when |
2405 | always_inserted_mode is not enabled. Explicitly insert them | |
2406 | now. */ | |
2407 | if (!breakpoints_always_inserted_mode ()) | |
74960c60 VP |
2408 | insert_breakpoint_locations (); |
2409 | } | |
2410 | ||
b775012e LM |
2411 | /* This is used when we need to synch breakpoint conditions between GDB and the |
2412 | target. It is the case with deleting and disabling of breakpoints when using | |
2413 | always-inserted mode. */ | |
2414 | ||
2415 | static void | |
2416 | update_inserted_breakpoint_locations (void) | |
2417 | { | |
2418 | struct bp_location *bl, **blp_tmp; | |
2419 | int error_flag = 0; | |
2420 | int val = 0; | |
2421 | int disabled_breaks = 0; | |
2422 | int hw_breakpoint_error = 0; | |
2423 | ||
2424 | struct ui_file *tmp_error_stream = mem_fileopen (); | |
2425 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); | |
2426 | ||
2427 | /* Explicitly mark the warning -- this will only be printed if | |
2428 | there was an error. */ | |
2429 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
2430 | ||
2431 | save_current_space_and_thread (); | |
2432 | ||
2433 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
2434 | { | |
2435 | /* We only want to update software breakpoints and hardware | |
2436 | breakpoints. */ | |
2437 | if (!is_breakpoint (bl->owner)) | |
2438 | continue; | |
2439 | ||
2440 | /* We only want to update locations that are already inserted | |
2441 | and need updating. This is to avoid unwanted insertion during | |
2442 | deletion of breakpoints. */ | |
2443 | if (!bl->inserted || (bl->inserted && !bl->needs_update)) | |
2444 | continue; | |
2445 | ||
2446 | switch_to_program_space_and_thread (bl->pspace); | |
2447 | ||
2448 | /* For targets that support global breakpoints, there's no need | |
2449 | to select an inferior to insert breakpoint to. In fact, even | |
2450 | if we aren't attached to any process yet, we should still | |
2451 | insert breakpoints. */ | |
2452 | if (!gdbarch_has_global_breakpoints (target_gdbarch) | |
2453 | && ptid_equal (inferior_ptid, null_ptid)) | |
2454 | continue; | |
2455 | ||
2456 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, | |
2457 | &hw_breakpoint_error); | |
2458 | if (val) | |
2459 | error_flag = val; | |
2460 | } | |
2461 | ||
2462 | if (error_flag) | |
2463 | { | |
2464 | target_terminal_ours_for_output (); | |
2465 | error_stream (tmp_error_stream); | |
2466 | } | |
2467 | ||
2468 | do_cleanups (cleanups); | |
2469 | } | |
2470 | ||
c30eee59 | 2471 | /* Used when starting or continuing the program. */ |
c906108c | 2472 | |
74960c60 VP |
2473 | static void |
2474 | insert_breakpoint_locations (void) | |
c906108c | 2475 | { |
a5606eee | 2476 | struct breakpoint *bpt; |
35df4500 | 2477 | struct bp_location *bl, **blp_tmp; |
eacd795a | 2478 | int error_flag = 0; |
c906108c | 2479 | int val = 0; |
3fbb6ffa | 2480 | int disabled_breaks = 0; |
81d0cc19 | 2481 | int hw_breakpoint_error = 0; |
c906108c | 2482 | |
81d0cc19 | 2483 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 2484 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 2485 | |
81d0cc19 GS |
2486 | /* Explicitly mark the warning -- this will only be printed if |
2487 | there was an error. */ | |
2488 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
2489 | |
2490 | save_current_space_and_thread (); | |
2491 | ||
35df4500 | 2492 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 2493 | { |
b775012e | 2494 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2495 | continue; |
2496 | ||
4a64f543 MS |
2497 | /* There is no point inserting thread-specific breakpoints if |
2498 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
2499 | has BL->OWNER always non-NULL. */ | |
35df4500 TJB |
2500 | if (bl->owner->thread != -1 |
2501 | && !valid_thread_id (bl->owner->thread)) | |
f365de73 AS |
2502 | continue; |
2503 | ||
35df4500 | 2504 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
2505 | |
2506 | /* For targets that support global breakpoints, there's no need | |
2507 | to select an inferior to insert breakpoint to. In fact, even | |
2508 | if we aren't attached to any process yet, we should still | |
2509 | insert breakpoints. */ | |
2510 | if (!gdbarch_has_global_breakpoints (target_gdbarch) | |
2511 | && ptid_equal (inferior_ptid, null_ptid)) | |
2512 | continue; | |
2513 | ||
3fbb6ffa TJB |
2514 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, |
2515 | &hw_breakpoint_error); | |
879bfdc2 | 2516 | if (val) |
eacd795a | 2517 | error_flag = val; |
879bfdc2 | 2518 | } |
c906108c | 2519 | |
4a64f543 MS |
2520 | /* If we failed to insert all locations of a watchpoint, remove |
2521 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
2522 | ALL_BREAKPOINTS (bpt) |
2523 | { | |
2524 | int some_failed = 0; | |
2525 | struct bp_location *loc; | |
2526 | ||
2527 | if (!is_hardware_watchpoint (bpt)) | |
2528 | continue; | |
2529 | ||
d6b74ac4 | 2530 | if (!breakpoint_enabled (bpt)) |
a5606eee | 2531 | continue; |
74960c60 VP |
2532 | |
2533 | if (bpt->disposition == disp_del_at_next_stop) | |
2534 | continue; | |
a5606eee VP |
2535 | |
2536 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 2537 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
2538 | { |
2539 | some_failed = 1; | |
2540 | break; | |
2541 | } | |
2542 | if (some_failed) | |
2543 | { | |
2544 | for (loc = bpt->loc; loc; loc = loc->next) | |
2545 | if (loc->inserted) | |
2546 | remove_breakpoint (loc, mark_uninserted); | |
2547 | ||
2548 | hw_breakpoint_error = 1; | |
2549 | fprintf_unfiltered (tmp_error_stream, | |
2550 | "Could not insert hardware watchpoint %d.\n", | |
2551 | bpt->number); | |
eacd795a | 2552 | error_flag = -1; |
a5606eee VP |
2553 | } |
2554 | } | |
2555 | ||
eacd795a | 2556 | if (error_flag) |
81d0cc19 GS |
2557 | { |
2558 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
2559 | message about possibly exhausted resources. */ | |
879bfdc2 | 2560 | if (hw_breakpoint_error) |
81d0cc19 | 2561 | { |
c6510018 MS |
2562 | fprintf_unfiltered (tmp_error_stream, |
2563 | "Could not insert hardware breakpoints:\n\ | |
2564 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 2565 | } |
81d0cc19 GS |
2566 | target_terminal_ours_for_output (); |
2567 | error_stream (tmp_error_stream); | |
2568 | } | |
f7545552 TT |
2569 | |
2570 | do_cleanups (cleanups); | |
c906108c SS |
2571 | } |
2572 | ||
c30eee59 TJB |
2573 | /* Used when the program stops. |
2574 | Returns zero if successful, or non-zero if there was a problem | |
2575 | removing a breakpoint location. */ | |
2576 | ||
c906108c | 2577 | int |
fba45db2 | 2578 | remove_breakpoints (void) |
c906108c | 2579 | { |
35df4500 | 2580 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 2581 | int val = 0; |
c906108c | 2582 | |
35df4500 | 2583 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2584 | { |
1e4d1764 | 2585 | if (bl->inserted && !is_tracepoint (bl->owner)) |
35df4500 | 2586 | val |= remove_breakpoint (bl, mark_uninserted); |
c5aa993b | 2587 | } |
3a1bae8e | 2588 | return val; |
c906108c SS |
2589 | } |
2590 | ||
6c95b8df PA |
2591 | /* Remove breakpoints of process PID. */ |
2592 | ||
2593 | int | |
2594 | remove_breakpoints_pid (int pid) | |
2595 | { | |
35df4500 | 2596 | struct bp_location *bl, **blp_tmp; |
6c95b8df PA |
2597 | int val; |
2598 | struct inferior *inf = find_inferior_pid (pid); | |
2599 | ||
35df4500 | 2600 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 2601 | { |
35df4500 | 2602 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2603 | continue; |
2604 | ||
35df4500 | 2605 | if (bl->inserted) |
6c95b8df | 2606 | { |
35df4500 | 2607 | val = remove_breakpoint (bl, mark_uninserted); |
6c95b8df PA |
2608 | if (val != 0) |
2609 | return val; | |
2610 | } | |
2611 | } | |
2612 | return 0; | |
2613 | } | |
2614 | ||
c906108c | 2615 | int |
fba45db2 | 2616 | reattach_breakpoints (int pid) |
c906108c | 2617 | { |
6c95b8df | 2618 | struct cleanup *old_chain; |
35df4500 | 2619 | struct bp_location *bl, **blp_tmp; |
c906108c | 2620 | int val; |
86b887df | 2621 | struct ui_file *tmp_error_stream; |
3fbb6ffa | 2622 | int dummy1 = 0, dummy2 = 0; |
6c95b8df PA |
2623 | struct inferior *inf; |
2624 | struct thread_info *tp; | |
2625 | ||
2626 | tp = any_live_thread_of_process (pid); | |
2627 | if (tp == NULL) | |
2628 | return 1; | |
2629 | ||
2630 | inf = find_inferior_pid (pid); | |
2631 | old_chain = save_inferior_ptid (); | |
2632 | ||
2633 | inferior_ptid = tp->ptid; | |
a4954f26 | 2634 | |
86b887df | 2635 | tmp_error_stream = mem_fileopen (); |
a4954f26 | 2636 | make_cleanup_ui_file_delete (tmp_error_stream); |
c906108c | 2637 | |
35df4500 | 2638 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2639 | { |
35df4500 | 2640 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2641 | continue; |
2642 | ||
35df4500 | 2643 | if (bl->inserted) |
c5aa993b | 2644 | { |
35df4500 | 2645 | bl->inserted = 0; |
3fbb6ffa | 2646 | val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2); |
c5aa993b JM |
2647 | if (val != 0) |
2648 | { | |
ce696e05 | 2649 | do_cleanups (old_chain); |
c5aa993b JM |
2650 | return val; |
2651 | } | |
2652 | } | |
2653 | } | |
ce696e05 | 2654 | do_cleanups (old_chain); |
c906108c SS |
2655 | return 0; |
2656 | } | |
2657 | ||
e58b0e63 PA |
2658 | static int internal_breakpoint_number = -1; |
2659 | ||
84f4c1fe PM |
2660 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
2661 | If INTERNAL is non-zero, the breakpoint number will be populated | |
2662 | from internal_breakpoint_number and that variable decremented. | |
e5dd4106 | 2663 | Otherwise the breakpoint number will be populated from |
84f4c1fe PM |
2664 | breakpoint_count and that value incremented. Internal breakpoints |
2665 | do not set the internal var bpnum. */ | |
2666 | static void | |
2667 | set_breakpoint_number (int internal, struct breakpoint *b) | |
2668 | { | |
2669 | if (internal) | |
2670 | b->number = internal_breakpoint_number--; | |
2671 | else | |
2672 | { | |
2673 | set_breakpoint_count (breakpoint_count + 1); | |
2674 | b->number = breakpoint_count; | |
2675 | } | |
2676 | } | |
2677 | ||
e62c965a | 2678 | static struct breakpoint * |
a6d9a66e | 2679 | create_internal_breakpoint (struct gdbarch *gdbarch, |
06edf0c0 | 2680 | CORE_ADDR address, enum bptype type, |
c0a91b2b | 2681 | const struct breakpoint_ops *ops) |
e62c965a | 2682 | { |
e62c965a PP |
2683 | struct symtab_and_line sal; |
2684 | struct breakpoint *b; | |
2685 | ||
4a64f543 | 2686 | init_sal (&sal); /* Initialize to zeroes. */ |
e62c965a PP |
2687 | |
2688 | sal.pc = address; | |
2689 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 2690 | sal.pspace = current_program_space; |
e62c965a | 2691 | |
06edf0c0 | 2692 | b = set_raw_breakpoint (gdbarch, sal, type, ops); |
e62c965a PP |
2693 | b->number = internal_breakpoint_number--; |
2694 | b->disposition = disp_donttouch; | |
2695 | ||
2696 | return b; | |
2697 | } | |
2698 | ||
17450429 PP |
2699 | static const char *const longjmp_names[] = |
2700 | { | |
2701 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
2702 | }; | |
2703 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
2704 | ||
2705 | /* Per-objfile data private to breakpoint.c. */ | |
2706 | struct breakpoint_objfile_data | |
2707 | { | |
2708 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
2709 | struct minimal_symbol *overlay_msym; | |
2710 | ||
2711 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
2712 | struct minimal_symbol *longjmp_msym[NUM_LONGJMP_NAMES]; | |
2713 | ||
2714 | /* Minimal symbol for "std::terminate()" (if any). */ | |
2715 | struct minimal_symbol *terminate_msym; | |
2716 | ||
2717 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
2718 | struct minimal_symbol *exception_msym; | |
2719 | }; | |
2720 | ||
2721 | static const struct objfile_data *breakpoint_objfile_key; | |
2722 | ||
2723 | /* Minimal symbol not found sentinel. */ | |
2724 | static struct minimal_symbol msym_not_found; | |
2725 | ||
2726 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
2727 | ||
2728 | static int | |
2729 | msym_not_found_p (const struct minimal_symbol *msym) | |
2730 | { | |
2731 | return msym == &msym_not_found; | |
2732 | } | |
2733 | ||
2734 | /* Return per-objfile data needed by breakpoint.c. | |
2735 | Allocate the data if necessary. */ | |
2736 | ||
2737 | static struct breakpoint_objfile_data * | |
2738 | get_breakpoint_objfile_data (struct objfile *objfile) | |
2739 | { | |
2740 | struct breakpoint_objfile_data *bp_objfile_data; | |
2741 | ||
2742 | bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key); | |
2743 | if (bp_objfile_data == NULL) | |
2744 | { | |
2745 | bp_objfile_data = obstack_alloc (&objfile->objfile_obstack, | |
2746 | sizeof (*bp_objfile_data)); | |
2747 | ||
2748 | memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); | |
2749 | set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); | |
2750 | } | |
2751 | return bp_objfile_data; | |
2752 | } | |
2753 | ||
e62c965a | 2754 | static void |
af02033e | 2755 | create_overlay_event_breakpoint (void) |
e62c965a | 2756 | { |
69de3c6a | 2757 | struct objfile *objfile; |
af02033e | 2758 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 2759 | |
69de3c6a PP |
2760 | ALL_OBJFILES (objfile) |
2761 | { | |
2762 | struct breakpoint *b; | |
17450429 PP |
2763 | struct breakpoint_objfile_data *bp_objfile_data; |
2764 | CORE_ADDR addr; | |
69de3c6a | 2765 | |
17450429 PP |
2766 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
2767 | ||
2768 | if (msym_not_found_p (bp_objfile_data->overlay_msym)) | |
2769 | continue; | |
2770 | ||
2771 | if (bp_objfile_data->overlay_msym == NULL) | |
2772 | { | |
2773 | struct minimal_symbol *m; | |
2774 | ||
2775 | m = lookup_minimal_symbol_text (func_name, objfile); | |
2776 | if (m == NULL) | |
2777 | { | |
2778 | /* Avoid future lookups in this objfile. */ | |
2779 | bp_objfile_data->overlay_msym = &msym_not_found; | |
2780 | continue; | |
2781 | } | |
2782 | bp_objfile_data->overlay_msym = m; | |
2783 | } | |
e62c965a | 2784 | |
17450429 PP |
2785 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
2786 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, | |
06edf0c0 PA |
2787 | bp_overlay_event, |
2788 | &internal_breakpoint_ops); | |
69de3c6a | 2789 | b->addr_string = xstrdup (func_name); |
e62c965a | 2790 | |
69de3c6a PP |
2791 | if (overlay_debugging == ovly_auto) |
2792 | { | |
2793 | b->enable_state = bp_enabled; | |
2794 | overlay_events_enabled = 1; | |
2795 | } | |
2796 | else | |
2797 | { | |
2798 | b->enable_state = bp_disabled; | |
2799 | overlay_events_enabled = 0; | |
2800 | } | |
e62c965a PP |
2801 | } |
2802 | update_global_location_list (1); | |
2803 | } | |
2804 | ||
0fd8e87f | 2805 | static void |
af02033e | 2806 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 2807 | { |
6c95b8df | 2808 | struct program_space *pspace; |
6c95b8df PA |
2809 | struct cleanup *old_chain; |
2810 | ||
2811 | old_chain = save_current_program_space (); | |
0fd8e87f | 2812 | |
6c95b8df | 2813 | ALL_PSPACES (pspace) |
af02033e PP |
2814 | { |
2815 | struct objfile *objfile; | |
2816 | ||
2817 | set_current_program_space (pspace); | |
2818 | ||
2819 | ALL_OBJFILES (objfile) | |
0fd8e87f | 2820 | { |
af02033e PP |
2821 | int i; |
2822 | struct gdbarch *gdbarch; | |
17450429 | 2823 | struct breakpoint_objfile_data *bp_objfile_data; |
0fd8e87f | 2824 | |
af02033e PP |
2825 | gdbarch = get_objfile_arch (objfile); |
2826 | if (!gdbarch_get_longjmp_target_p (gdbarch)) | |
0fd8e87f UW |
2827 | continue; |
2828 | ||
17450429 PP |
2829 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
2830 | ||
2831 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) | |
af02033e PP |
2832 | { |
2833 | struct breakpoint *b; | |
af02033e | 2834 | const char *func_name; |
17450429 | 2835 | CORE_ADDR addr; |
6c95b8df | 2836 | |
17450429 | 2837 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i])) |
af02033e | 2838 | continue; |
0fd8e87f | 2839 | |
17450429 PP |
2840 | func_name = longjmp_names[i]; |
2841 | if (bp_objfile_data->longjmp_msym[i] == NULL) | |
2842 | { | |
2843 | struct minimal_symbol *m; | |
2844 | ||
2845 | m = lookup_minimal_symbol_text (func_name, objfile); | |
2846 | if (m == NULL) | |
2847 | { | |
2848 | /* Prevent future lookups in this objfile. */ | |
2849 | bp_objfile_data->longjmp_msym[i] = &msym_not_found; | |
2850 | continue; | |
2851 | } | |
2852 | bp_objfile_data->longjmp_msym[i] = m; | |
2853 | } | |
2854 | ||
2855 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); | |
06edf0c0 PA |
2856 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, |
2857 | &internal_breakpoint_ops); | |
af02033e PP |
2858 | b->addr_string = xstrdup (func_name); |
2859 | b->enable_state = bp_disabled; | |
2860 | } | |
0fd8e87f | 2861 | } |
af02033e | 2862 | } |
0fd8e87f | 2863 | update_global_location_list (1); |
6c95b8df PA |
2864 | |
2865 | do_cleanups (old_chain); | |
0fd8e87f UW |
2866 | } |
2867 | ||
af02033e | 2868 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 2869 | static void |
af02033e | 2870 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
2871 | { |
2872 | struct program_space *pspace; | |
aa7d318d | 2873 | struct cleanup *old_chain; |
af02033e | 2874 | const char *const func_name = "std::terminate()"; |
aa7d318d TT |
2875 | |
2876 | old_chain = save_current_program_space (); | |
2877 | ||
2878 | ALL_PSPACES (pspace) | |
17450429 PP |
2879 | { |
2880 | struct objfile *objfile; | |
2881 | CORE_ADDR addr; | |
2882 | ||
2883 | set_current_program_space (pspace); | |
2884 | ||
aa7d318d TT |
2885 | ALL_OBJFILES (objfile) |
2886 | { | |
2887 | struct breakpoint *b; | |
17450429 | 2888 | struct breakpoint_objfile_data *bp_objfile_data; |
aa7d318d | 2889 | |
17450429 | 2890 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 2891 | |
17450429 PP |
2892 | if (msym_not_found_p (bp_objfile_data->terminate_msym)) |
2893 | continue; | |
2894 | ||
2895 | if (bp_objfile_data->terminate_msym == NULL) | |
2896 | { | |
2897 | struct minimal_symbol *m; | |
2898 | ||
2899 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
2900 | if (m == NULL || (MSYMBOL_TYPE (m) != mst_text | |
2901 | && MSYMBOL_TYPE (m) != mst_file_text)) | |
2902 | { | |
2903 | /* Prevent future lookups in this objfile. */ | |
2904 | bp_objfile_data->terminate_msym = &msym_not_found; | |
2905 | continue; | |
2906 | } | |
2907 | bp_objfile_data->terminate_msym = m; | |
2908 | } | |
aa7d318d | 2909 | |
17450429 PP |
2910 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
2911 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, | |
06edf0c0 PA |
2912 | bp_std_terminate_master, |
2913 | &internal_breakpoint_ops); | |
aa7d318d TT |
2914 | b->addr_string = xstrdup (func_name); |
2915 | b->enable_state = bp_disabled; | |
2916 | } | |
17450429 PP |
2917 | } |
2918 | ||
aa7d318d TT |
2919 | update_global_location_list (1); |
2920 | ||
2921 | do_cleanups (old_chain); | |
2922 | } | |
2923 | ||
186c406b TT |
2924 | /* Install a master breakpoint on the unwinder's debug hook. */ |
2925 | ||
70221824 | 2926 | static void |
186c406b TT |
2927 | create_exception_master_breakpoint (void) |
2928 | { | |
2929 | struct objfile *objfile; | |
17450429 | 2930 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b TT |
2931 | |
2932 | ALL_OBJFILES (objfile) | |
2933 | { | |
17450429 PP |
2934 | struct breakpoint *b; |
2935 | struct gdbarch *gdbarch; | |
2936 | struct breakpoint_objfile_data *bp_objfile_data; | |
2937 | CORE_ADDR addr; | |
2938 | ||
2939 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
2940 | ||
2941 | if (msym_not_found_p (bp_objfile_data->exception_msym)) | |
2942 | continue; | |
2943 | ||
2944 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 2945 | |
17450429 | 2946 | if (bp_objfile_data->exception_msym == NULL) |
186c406b | 2947 | { |
17450429 | 2948 | struct minimal_symbol *debug_hook; |
186c406b | 2949 | |
17450429 PP |
2950 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
2951 | if (debug_hook == NULL) | |
2952 | { | |
2953 | bp_objfile_data->exception_msym = &msym_not_found; | |
2954 | continue; | |
2955 | } | |
2956 | ||
2957 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 2958 | } |
17450429 PP |
2959 | |
2960 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); | |
2961 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, | |
2962 | ¤t_target); | |
06edf0c0 PA |
2963 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
2964 | &internal_breakpoint_ops); | |
17450429 PP |
2965 | b->addr_string = xstrdup (func_name); |
2966 | b->enable_state = bp_disabled; | |
186c406b TT |
2967 | } |
2968 | ||
2969 | update_global_location_list (1); | |
2970 | } | |
2971 | ||
c906108c | 2972 | void |
fba45db2 | 2973 | update_breakpoints_after_exec (void) |
c906108c | 2974 | { |
35df4500 | 2975 | struct breakpoint *b, *b_tmp; |
876fa593 | 2976 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 2977 | |
25b22b0a PA |
2978 | /* We're about to delete breakpoints from GDB's lists. If the |
2979 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
2980 | writing the breakpoints' "shadow contents" back into memory. The | |
2981 | "shadow contents" are NOT valid after an exec, so GDB should not | |
2982 | do that. Instead, the target is responsible from marking | |
2983 | breakpoints out as soon as it detects an exec. We don't do that | |
2984 | here instead, because there may be other attempts to delete | |
2985 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 2986 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
2987 | if (bploc->pspace == current_program_space) |
2988 | gdb_assert (!bploc->inserted); | |
c906108c | 2989 | |
35df4500 | 2990 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 2991 | { |
6c95b8df PA |
2992 | if (b->pspace != current_program_space) |
2993 | continue; | |
2994 | ||
4a64f543 | 2995 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
2996 | if (b->type == bp_shlib_event) |
2997 | { | |
2998 | delete_breakpoint (b); | |
2999 | continue; | |
3000 | } | |
c906108c | 3001 | |
4a64f543 | 3002 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
3003 | if (b->type == bp_jit_event) |
3004 | { | |
3005 | delete_breakpoint (b); | |
3006 | continue; | |
3007 | } | |
3008 | ||
1900040c | 3009 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
3010 | as must overlay event and longjmp master breakpoints. */ |
3011 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
3012 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
3013 | || b->type == bp_exception_master) | |
c4093a6a JM |
3014 | { |
3015 | delete_breakpoint (b); | |
3016 | continue; | |
3017 | } | |
3018 | ||
4a64f543 | 3019 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2c03e5be | 3020 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
c5aa993b JM |
3021 | { |
3022 | delete_breakpoint (b); | |
3023 | continue; | |
3024 | } | |
3025 | ||
611c83ae PA |
3026 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
3027 | after an exec. */ | |
186c406b TT |
3028 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
3029 | || b->type == bp_exception || b->type == bp_exception_resume) | |
611c83ae PA |
3030 | { |
3031 | delete_breakpoint (b); | |
3032 | continue; | |
3033 | } | |
3034 | ||
ce78b96d JB |
3035 | if (b->type == bp_catchpoint) |
3036 | { | |
3037 | /* For now, none of the bp_catchpoint breakpoints need to | |
3038 | do anything at this point. In the future, if some of | |
3039 | the catchpoints need to something, we will need to add | |
3040 | a new method, and call this method from here. */ | |
3041 | continue; | |
3042 | } | |
3043 | ||
c5aa993b JM |
3044 | /* bp_finish is a special case. The only way we ought to be able |
3045 | to see one of these when an exec() has happened, is if the user | |
3046 | caught a vfork, and then said "finish". Ordinarily a finish just | |
3047 | carries them to the call-site of the current callee, by setting | |
3048 | a temporary bp there and resuming. But in this case, the finish | |
3049 | will carry them entirely through the vfork & exec. | |
3050 | ||
3051 | We don't want to allow a bp_finish to remain inserted now. But | |
3052 | we can't safely delete it, 'cause finish_command has a handle to | |
3053 | the bp on a bpstat, and will later want to delete it. There's a | |
3054 | chance (and I've seen it happen) that if we delete the bp_finish | |
3055 | here, that its storage will get reused by the time finish_command | |
3056 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
3057 | We really must allow finish_command to delete a bp_finish. | |
3058 | ||
e5dd4106 | 3059 | In the absence of a general solution for the "how do we know |
53a5351d JM |
3060 | it's safe to delete something others may have handles to?" |
3061 | problem, what we'll do here is just uninsert the bp_finish, and | |
3062 | let finish_command delete it. | |
3063 | ||
3064 | (We know the bp_finish is "doomed" in the sense that it's | |
3065 | momentary, and will be deleted as soon as finish_command sees | |
3066 | the inferior stopped. So it doesn't matter that the bp's | |
3067 | address is probably bogus in the new a.out, unlike e.g., the | |
3068 | solib breakpoints.) */ | |
c5aa993b | 3069 | |
c5aa993b JM |
3070 | if (b->type == bp_finish) |
3071 | { | |
3072 | continue; | |
3073 | } | |
3074 | ||
3075 | /* Without a symbolic address, we have little hope of the | |
3076 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 3077 | a.out. */ |
c5aa993b JM |
3078 | if (b->addr_string == NULL) |
3079 | { | |
3080 | delete_breakpoint (b); | |
3081 | continue; | |
3082 | } | |
c5aa993b | 3083 | } |
1900040c | 3084 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
af02033e PP |
3085 | create_overlay_event_breakpoint (); |
3086 | create_longjmp_master_breakpoint (); | |
3087 | create_std_terminate_master_breakpoint (); | |
186c406b | 3088 | create_exception_master_breakpoint (); |
c906108c SS |
3089 | } |
3090 | ||
3091 | int | |
fba45db2 | 3092 | detach_breakpoints (int pid) |
c906108c | 3093 | { |
35df4500 | 3094 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3095 | int val = 0; |
ce696e05 | 3096 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 3097 | struct inferior *inf = current_inferior (); |
c5aa993b | 3098 | |
39f77062 | 3099 | if (pid == PIDGET (inferior_ptid)) |
8a3fe4f8 | 3100 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 3101 | |
6c95b8df | 3102 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
ce696e05 | 3103 | inferior_ptid = pid_to_ptid (pid); |
35df4500 | 3104 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3105 | { |
35df4500 | 3106 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3107 | continue; |
3108 | ||
35df4500 TJB |
3109 | if (bl->inserted) |
3110 | val |= remove_breakpoint_1 (bl, mark_inserted); | |
c5aa993b | 3111 | } |
d03285ec UW |
3112 | |
3113 | /* Detach single-step breakpoints as well. */ | |
3114 | detach_single_step_breakpoints (); | |
3115 | ||
ce696e05 | 3116 | do_cleanups (old_chain); |
3a1bae8e | 3117 | return val; |
c906108c SS |
3118 | } |
3119 | ||
35df4500 | 3120 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
3121 | Note that this is used to detach breakpoints from a child fork. |
3122 | When we get here, the child isn't in the inferior list, and neither | |
3123 | do we have objects to represent its address space --- we should | |
35df4500 | 3124 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 3125 | |
c906108c | 3126 | static int |
35df4500 | 3127 | remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is) |
c906108c SS |
3128 | { |
3129 | int val; | |
c5aa993b | 3130 | |
35df4500 TJB |
3131 | /* BL is never in moribund_locations by our callers. */ |
3132 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3133 | |
35df4500 | 3134 | if (bl->owner->enable_state == bp_permanent) |
c2c6d25f JM |
3135 | /* Permanent breakpoints cannot be inserted or removed. */ |
3136 | return 0; | |
3137 | ||
74960c60 VP |
3138 | /* The type of none suggests that owner is actually deleted. |
3139 | This should not ever happen. */ | |
35df4500 | 3140 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 3141 | |
35df4500 TJB |
3142 | if (bl->loc_type == bp_loc_software_breakpoint |
3143 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 3144 | { |
c02f5703 MS |
3145 | /* "Normal" instruction breakpoint: either the standard |
3146 | trap-instruction bp (bp_breakpoint), or a | |
3147 | bp_hardware_breakpoint. */ | |
3148 | ||
3149 | /* First check to see if we have to handle an overlay. */ | |
3150 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
3151 | || bl->section == NULL |
3152 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
3153 | { |
3154 | /* No overlay handling: just remove the breakpoint. */ | |
348d480f | 3155 | val = bl->owner->ops->remove_location (bl); |
c02f5703 | 3156 | } |
c906108c SS |
3157 | else |
3158 | { | |
4a64f543 | 3159 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
3160 | Did we set a breakpoint at the LMA? */ |
3161 | if (!overlay_events_enabled) | |
3162 | { | |
3163 | /* Yes -- overlay event support is not active, so we | |
3164 | should have set a breakpoint at the LMA. Remove it. | |
3165 | */ | |
c02f5703 MS |
3166 | /* Ignore any failures: if the LMA is in ROM, we will |
3167 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
3168 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
3169 | target_remove_hw_breakpoint (bl->gdbarch, | |
3170 | &bl->overlay_target_info); | |
c02f5703 | 3171 | else |
35df4500 TJB |
3172 | target_remove_breakpoint (bl->gdbarch, |
3173 | &bl->overlay_target_info); | |
c02f5703 MS |
3174 | } |
3175 | /* Did we set a breakpoint at the VMA? | |
3176 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 3177 | if (bl->inserted) |
c906108c | 3178 | { |
c02f5703 MS |
3179 | /* Yes -- remove it. Previously we did not bother to |
3180 | remove the breakpoint if the section had been | |
3181 | unmapped, but let's not rely on that being safe. We | |
3182 | don't know what the overlay manager might do. */ | |
aa67235e UW |
3183 | |
3184 | /* However, we should remove *software* breakpoints only | |
3185 | if the section is still mapped, or else we overwrite | |
3186 | wrong code with the saved shadow contents. */ | |
348d480f PA |
3187 | if (bl->loc_type == bp_loc_hardware_breakpoint |
3188 | || section_is_mapped (bl->section)) | |
3189 | val = bl->owner->ops->remove_location (bl); | |
aa67235e UW |
3190 | else |
3191 | val = 0; | |
c906108c | 3192 | } |
c02f5703 MS |
3193 | else |
3194 | { | |
3195 | /* No -- not inserted, so no need to remove. No error. */ | |
3196 | val = 0; | |
3197 | } | |
c906108c | 3198 | } |
879d1e6b UW |
3199 | |
3200 | /* In some cases, we might not be able to remove a breakpoint | |
3201 | in a shared library that has already been removed, but we | |
3202 | have not yet processed the shlib unload event. */ | |
35df4500 | 3203 | if (val && solib_name_from_address (bl->pspace, bl->address)) |
879d1e6b UW |
3204 | val = 0; |
3205 | ||
c906108c SS |
3206 | if (val) |
3207 | return val; | |
35df4500 | 3208 | bl->inserted = (is == mark_inserted); |
c906108c | 3209 | } |
35df4500 | 3210 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 3211 | { |
77b06cd7 TJB |
3212 | gdb_assert (bl->owner->ops != NULL |
3213 | && bl->owner->ops->remove_location != NULL); | |
3214 | ||
35df4500 | 3215 | bl->inserted = (is == mark_inserted); |
77b06cd7 | 3216 | bl->owner->ops->remove_location (bl); |
2e70b7b9 | 3217 | |
c906108c | 3218 | /* Failure to remove any of the hardware watchpoints comes here. */ |
35df4500 | 3219 | if ((is == mark_uninserted) && (bl->inserted)) |
8a3fe4f8 | 3220 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 3221 | bl->owner->number); |
c906108c | 3222 | } |
35df4500 TJB |
3223 | else if (bl->owner->type == bp_catchpoint |
3224 | && breakpoint_enabled (bl->owner) | |
3225 | && !bl->duplicate) | |
ce78b96d | 3226 | { |
77b06cd7 TJB |
3227 | gdb_assert (bl->owner->ops != NULL |
3228 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 3229 | |
77b06cd7 | 3230 | val = bl->owner->ops->remove_location (bl); |
ce78b96d JB |
3231 | if (val) |
3232 | return val; | |
77b06cd7 | 3233 | |
35df4500 | 3234 | bl->inserted = (is == mark_inserted); |
ce78b96d | 3235 | } |
c906108c SS |
3236 | |
3237 | return 0; | |
3238 | } | |
3239 | ||
6c95b8df | 3240 | static int |
35df4500 | 3241 | remove_breakpoint (struct bp_location *bl, insertion_state_t is) |
6c95b8df PA |
3242 | { |
3243 | int ret; | |
3244 | struct cleanup *old_chain; | |
3245 | ||
35df4500 TJB |
3246 | /* BL is never in moribund_locations by our callers. */ |
3247 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3248 | |
35df4500 | 3249 | if (bl->owner->enable_state == bp_permanent) |
6c95b8df PA |
3250 | /* Permanent breakpoints cannot be inserted or removed. */ |
3251 | return 0; | |
3252 | ||
3253 | /* The type of none suggests that owner is actually deleted. | |
3254 | This should not ever happen. */ | |
35df4500 | 3255 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df PA |
3256 | |
3257 | old_chain = save_current_space_and_thread (); | |
3258 | ||
35df4500 | 3259 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 3260 | |
35df4500 | 3261 | ret = remove_breakpoint_1 (bl, is); |
6c95b8df PA |
3262 | |
3263 | do_cleanups (old_chain); | |
3264 | return ret; | |
3265 | } | |
3266 | ||
c906108c SS |
3267 | /* Clear the "inserted" flag in all breakpoints. */ |
3268 | ||
25b22b0a | 3269 | void |
fba45db2 | 3270 | mark_breakpoints_out (void) |
c906108c | 3271 | { |
35df4500 | 3272 | struct bp_location *bl, **blp_tmp; |
c906108c | 3273 | |
35df4500 TJB |
3274 | ALL_BP_LOCATIONS (bl, blp_tmp) |
3275 | if (bl->pspace == current_program_space) | |
3276 | bl->inserted = 0; | |
c906108c SS |
3277 | } |
3278 | ||
53a5351d JM |
3279 | /* Clear the "inserted" flag in all breakpoints and delete any |
3280 | breakpoints which should go away between runs of the program. | |
c906108c SS |
3281 | |
3282 | Plus other such housekeeping that has to be done for breakpoints | |
3283 | between runs. | |
3284 | ||
53a5351d JM |
3285 | Note: this function gets called at the end of a run (by |
3286 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 3287 | init_wait_for_inferior). */ |
c906108c SS |
3288 | |
3289 | ||
3290 | ||
3291 | void | |
fba45db2 | 3292 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 3293 | { |
35df4500 TJB |
3294 | struct breakpoint *b, *b_tmp; |
3295 | struct bp_location *bl, **blp_tmp; | |
1c5cfe86 | 3296 | int ix; |
6c95b8df | 3297 | struct program_space *pspace = current_program_space; |
c906108c | 3298 | |
50c71eaf PA |
3299 | /* If breakpoint locations are shared across processes, then there's |
3300 | nothing to do. */ | |
2567c7d9 | 3301 | if (gdbarch_has_global_breakpoints (target_gdbarch)) |
50c71eaf PA |
3302 | return; |
3303 | ||
35df4500 | 3304 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 3305 | { |
35df4500 TJB |
3306 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
3307 | if (bl->pspace == pspace | |
3308 | && bl->owner->enable_state != bp_permanent) | |
3309 | bl->inserted = 0; | |
6c95b8df | 3310 | } |
075f6582 | 3311 | |
35df4500 | 3312 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3313 | { |
6c95b8df PA |
3314 | if (b->loc && b->loc->pspace != pspace) |
3315 | continue; | |
3316 | ||
c5aa993b JM |
3317 | switch (b->type) |
3318 | { | |
3319 | case bp_call_dummy: | |
c906108c | 3320 | |
c5aa993b | 3321 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
3322 | cause problems when the inferior is rerun, so we better get |
3323 | rid of it. */ | |
3324 | ||
3325 | case bp_watchpoint_scope: | |
3326 | ||
3327 | /* Also get rid of scope breakpoints. */ | |
3328 | ||
3329 | case bp_shlib_event: | |
3330 | ||
3331 | /* Also remove solib event breakpoints. Their addresses may | |
3332 | have changed since the last time we ran the program. | |
3333 | Actually we may now be debugging against different target; | |
3334 | and so the solib backend that installed this breakpoint may | |
3335 | not be used in by the target. E.g., | |
3336 | ||
3337 | (gdb) file prog-linux | |
3338 | (gdb) run # native linux target | |
3339 | ... | |
3340 | (gdb) kill | |
3341 | (gdb) file prog-win.exe | |
3342 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
3343 | */ | |
c906108c | 3344 | |
f59f708a PA |
3345 | case bp_step_resume: |
3346 | ||
3347 | /* Also remove step-resume breakpoints. */ | |
3348 | ||
c5aa993b JM |
3349 | delete_breakpoint (b); |
3350 | break; | |
c906108c | 3351 | |
c5aa993b JM |
3352 | case bp_watchpoint: |
3353 | case bp_hardware_watchpoint: | |
3354 | case bp_read_watchpoint: | |
3355 | case bp_access_watchpoint: | |
3a5c3e22 PA |
3356 | { |
3357 | struct watchpoint *w = (struct watchpoint *) b; | |
c906108c | 3358 | |
3a5c3e22 PA |
3359 | /* Likewise for watchpoints on local expressions. */ |
3360 | if (w->exp_valid_block != NULL) | |
3361 | delete_breakpoint (b); | |
3362 | else if (context == inf_starting) | |
3363 | { | |
3364 | /* Reset val field to force reread of starting value in | |
3365 | insert_breakpoints. */ | |
3366 | if (w->val) | |
3367 | value_free (w->val); | |
3368 | w->val = NULL; | |
3369 | w->val_valid = 0; | |
c860120c | 3370 | } |
3a5c3e22 | 3371 | } |
c5aa993b JM |
3372 | break; |
3373 | default: | |
c5aa993b JM |
3374 | break; |
3375 | } | |
3376 | } | |
1c5cfe86 PA |
3377 | |
3378 | /* Get rid of the moribund locations. */ | |
35df4500 TJB |
3379 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
3380 | decref_bp_location (&bl); | |
1c5cfe86 | 3381 | VEC_free (bp_location_p, moribund_locations); |
c906108c SS |
3382 | } |
3383 | ||
6c95b8df PA |
3384 | /* These functions concern about actual breakpoints inserted in the |
3385 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
3386 | we need to hop over the bkpt --- so we check for address space | |
3387 | match, not program space. */ | |
3388 | ||
c2c6d25f JM |
3389 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
3390 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
3391 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
3392 | permanent breakpoint. | |
3393 | - When continuing from a location with an ordinary breakpoint, we | |
3394 | actually single step once before calling insert_breakpoints. | |
e5dd4106 | 3395 | - When continuing from a location with a permanent breakpoint, we |
c2c6d25f JM |
3396 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
3397 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 3398 | |
c2c6d25f | 3399 | enum breakpoint_here |
6c95b8df | 3400 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 3401 | { |
35df4500 | 3402 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 3403 | int any_breakpoint_here = 0; |
c906108c | 3404 | |
35df4500 | 3405 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 3406 | { |
35df4500 TJB |
3407 | if (bl->loc_type != bp_loc_software_breakpoint |
3408 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
3409 | continue; |
3410 | ||
f1310107 | 3411 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 TJB |
3412 | if ((breakpoint_enabled (bl->owner) |
3413 | || bl->owner->enable_state == bp_permanent) | |
f1310107 | 3414 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
3415 | { |
3416 | if (overlay_debugging | |
35df4500 TJB |
3417 | && section_is_overlay (bl->section) |
3418 | && !section_is_mapped (bl->section)) | |
075f6582 | 3419 | continue; /* unmapped overlay -- can't be a match */ |
35df4500 | 3420 | else if (bl->owner->enable_state == bp_permanent) |
075f6582 DJ |
3421 | return permanent_breakpoint_here; |
3422 | else | |
3423 | any_breakpoint_here = 1; | |
3424 | } | |
3425 | } | |
c906108c | 3426 | |
c2c6d25f | 3427 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
3428 | } |
3429 | ||
1c5cfe86 PA |
3430 | /* Return true if there's a moribund breakpoint at PC. */ |
3431 | ||
3432 | int | |
6c95b8df | 3433 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
3434 | { |
3435 | struct bp_location *loc; | |
3436 | int ix; | |
3437 | ||
3438 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
f1310107 | 3439 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
3440 | return 1; |
3441 | ||
3442 | return 0; | |
3443 | } | |
c2c6d25f | 3444 | |
c36b740a | 3445 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
4a64f543 MS |
3446 | inserted using regular breakpoint_chain / bp_location array |
3447 | mechanism. This does not check for single-step breakpoints, which | |
3448 | are inserted and removed using direct target manipulation. */ | |
c906108c SS |
3449 | |
3450 | int | |
4a64f543 MS |
3451 | regular_breakpoint_inserted_here_p (struct address_space *aspace, |
3452 | CORE_ADDR pc) | |
c906108c | 3453 | { |
35df4500 | 3454 | struct bp_location *bl, **blp_tmp; |
c906108c | 3455 | |
35df4500 | 3456 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3457 | { |
35df4500 TJB |
3458 | if (bl->loc_type != bp_loc_software_breakpoint |
3459 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
3460 | continue; |
3461 | ||
35df4500 | 3462 | if (bl->inserted |
f1310107 | 3463 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
3464 | { |
3465 | if (overlay_debugging | |
35df4500 TJB |
3466 | && section_is_overlay (bl->section) |
3467 | && !section_is_mapped (bl->section)) | |
075f6582 DJ |
3468 | continue; /* unmapped overlay -- can't be a match */ |
3469 | else | |
3470 | return 1; | |
3471 | } | |
c5aa993b | 3472 | } |
c36b740a VP |
3473 | return 0; |
3474 | } | |
3475 | ||
3476 | /* Returns non-zero iff there's either regular breakpoint | |
3477 | or a single step breakpoint inserted at PC. */ | |
3478 | ||
3479 | int | |
6c95b8df | 3480 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c36b740a | 3481 | { |
6c95b8df | 3482 | if (regular_breakpoint_inserted_here_p (aspace, pc)) |
c36b740a | 3483 | return 1; |
c906108c | 3484 | |
6c95b8df | 3485 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
3486 | return 1; |
3487 | ||
c906108c SS |
3488 | return 0; |
3489 | } | |
3490 | ||
4fa8626c DJ |
3491 | /* This function returns non-zero iff there is a software breakpoint |
3492 | inserted at PC. */ | |
3493 | ||
3494 | int | |
3e43a32a MS |
3495 | software_breakpoint_inserted_here_p (struct address_space *aspace, |
3496 | CORE_ADDR pc) | |
4fa8626c | 3497 | { |
35df4500 | 3498 | struct bp_location *bl, **blp_tmp; |
4fa8626c | 3499 | |
35df4500 | 3500 | ALL_BP_LOCATIONS (bl, blp_tmp) |
4fa8626c | 3501 | { |
35df4500 | 3502 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
3503 | continue; |
3504 | ||
35df4500 TJB |
3505 | if (bl->inserted |
3506 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6c95b8df | 3507 | aspace, pc)) |
4fa8626c DJ |
3508 | { |
3509 | if (overlay_debugging | |
35df4500 TJB |
3510 | && section_is_overlay (bl->section) |
3511 | && !section_is_mapped (bl->section)) | |
4fa8626c DJ |
3512 | continue; /* unmapped overlay -- can't be a match */ |
3513 | else | |
3514 | return 1; | |
3515 | } | |
3516 | } | |
3517 | ||
1aafd4da | 3518 | /* Also check for software single-step breakpoints. */ |
6c95b8df | 3519 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
3520 | return 1; |
3521 | ||
4fa8626c DJ |
3522 | return 0; |
3523 | } | |
3524 | ||
9093389c PA |
3525 | int |
3526 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
3527 | CORE_ADDR addr, ULONGEST len) | |
3528 | { | |
3529 | struct breakpoint *bpt; | |
3530 | ||
3531 | ALL_BREAKPOINTS (bpt) | |
3532 | { | |
3533 | struct bp_location *loc; | |
3534 | ||
3535 | if (bpt->type != bp_hardware_watchpoint | |
3536 | && bpt->type != bp_access_watchpoint) | |
3537 | continue; | |
3538 | ||
3539 | if (!breakpoint_enabled (bpt)) | |
3540 | continue; | |
3541 | ||
3542 | for (loc = bpt->loc; loc; loc = loc->next) | |
3543 | if (loc->pspace->aspace == aspace && loc->inserted) | |
3544 | { | |
3545 | CORE_ADDR l, h; | |
3546 | ||
3547 | /* Check for intersection. */ | |
3548 | l = max (loc->address, addr); | |
3549 | h = min (loc->address + loc->length, addr + len); | |
3550 | if (l < h) | |
3551 | return 1; | |
3552 | } | |
3553 | } | |
3554 | return 0; | |
3555 | } | |
3556 | ||
075f6582 DJ |
3557 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
3558 | PC is valid for process/thread PTID. */ | |
c906108c SS |
3559 | |
3560 | int | |
6c95b8df PA |
3561 | breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc, |
3562 | ptid_t ptid) | |
c906108c | 3563 | { |
35df4500 | 3564 | struct bp_location *bl, **blp_tmp; |
4a306c9a | 3565 | /* The thread and task IDs associated to PTID, computed lazily. */ |
a6f1cd96 | 3566 | int thread = -1; |
4a306c9a | 3567 | int task = 0; |
a6f1cd96 | 3568 | |
35df4500 | 3569 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3570 | { |
35df4500 TJB |
3571 | if (bl->loc_type != bp_loc_software_breakpoint |
3572 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
3573 | continue; |
3574 | ||
35df4500 TJB |
3575 | /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */ |
3576 | if (!breakpoint_enabled (bl->owner) | |
3577 | && bl->owner->enable_state != bp_permanent) | |
a6f1cd96 JB |
3578 | continue; |
3579 | ||
f1310107 | 3580 | if (!breakpoint_location_address_match (bl, aspace, pc)) |
a6f1cd96 JB |
3581 | continue; |
3582 | ||
35df4500 | 3583 | if (bl->owner->thread != -1) |
075f6582 | 3584 | { |
a6f1cd96 JB |
3585 | /* This is a thread-specific breakpoint. Check that ptid |
3586 | matches that thread. If thread hasn't been computed yet, | |
3587 | it is now time to do so. */ | |
3588 | if (thread == -1) | |
3589 | thread = pid_to_thread_id (ptid); | |
35df4500 | 3590 | if (bl->owner->thread != thread) |
a6f1cd96 | 3591 | continue; |
075f6582 | 3592 | } |
a6f1cd96 | 3593 | |
35df4500 | 3594 | if (bl->owner->task != 0) |
4a306c9a JB |
3595 | { |
3596 | /* This is a task-specific breakpoint. Check that ptid | |
3597 | matches that task. If task hasn't been computed yet, | |
3598 | it is now time to do so. */ | |
3599 | if (task == 0) | |
3600 | task = ada_get_task_number (ptid); | |
35df4500 | 3601 | if (bl->owner->task != task) |
4a306c9a JB |
3602 | continue; |
3603 | } | |
3604 | ||
a6f1cd96 | 3605 | if (overlay_debugging |
35df4500 TJB |
3606 | && section_is_overlay (bl->section) |
3607 | && !section_is_mapped (bl->section)) | |
a6f1cd96 JB |
3608 | continue; /* unmapped overlay -- can't be a match */ |
3609 | ||
3610 | return 1; | |
c5aa993b | 3611 | } |
c906108c SS |
3612 | |
3613 | return 0; | |
3614 | } | |
c906108c | 3615 | \f |
c5aa993b | 3616 | |
c906108c SS |
3617 | /* bpstat stuff. External routines' interfaces are documented |
3618 | in breakpoint.h. */ | |
3619 | ||
3620 | int | |
fba45db2 | 3621 | ep_is_catchpoint (struct breakpoint *ep) |
c906108c | 3622 | { |
533be4dd | 3623 | return (ep->type == bp_catchpoint); |
c906108c SS |
3624 | } |
3625 | ||
f431efe5 PA |
3626 | /* Frees any storage that is part of a bpstat. Does not walk the |
3627 | 'next' chain. */ | |
3628 | ||
3629 | static void | |
198757a8 VP |
3630 | bpstat_free (bpstat bs) |
3631 | { | |
3632 | if (bs->old_val != NULL) | |
3633 | value_free (bs->old_val); | |
9add0f1b | 3634 | decref_counted_command_line (&bs->commands); |
f431efe5 | 3635 | decref_bp_location (&bs->bp_location_at); |
198757a8 VP |
3636 | xfree (bs); |
3637 | } | |
3638 | ||
c906108c SS |
3639 | /* Clear a bpstat so that it says we are not at any breakpoint. |
3640 | Also free any storage that is part of a bpstat. */ | |
3641 | ||
3642 | void | |
fba45db2 | 3643 | bpstat_clear (bpstat *bsp) |
c906108c SS |
3644 | { |
3645 | bpstat p; | |
3646 | bpstat q; | |
3647 | ||
3648 | if (bsp == 0) | |
3649 | return; | |
3650 | p = *bsp; | |
3651 | while (p != NULL) | |
3652 | { | |
3653 | q = p->next; | |
198757a8 | 3654 | bpstat_free (p); |
c906108c SS |
3655 | p = q; |
3656 | } | |
3657 | *bsp = NULL; | |
3658 | } | |
3659 | ||
3660 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
3661 | is part of the bpstat is copied as well. */ | |
3662 | ||
3663 | bpstat | |
fba45db2 | 3664 | bpstat_copy (bpstat bs) |
c906108c SS |
3665 | { |
3666 | bpstat p = NULL; | |
3667 | bpstat tmp; | |
3668 | bpstat retval = NULL; | |
3669 | ||
3670 | if (bs == NULL) | |
3671 | return bs; | |
3672 | ||
3673 | for (; bs != NULL; bs = bs->next) | |
3674 | { | |
3675 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
3676 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 3677 | incref_counted_command_line (tmp->commands); |
f431efe5 | 3678 | incref_bp_location (tmp->bp_location_at); |
31cc81e9 | 3679 | if (bs->old_val != NULL) |
3c3185ac JK |
3680 | { |
3681 | tmp->old_val = value_copy (bs->old_val); | |
3682 | release_value (tmp->old_val); | |
3683 | } | |
31cc81e9 | 3684 | |
c906108c SS |
3685 | if (p == NULL) |
3686 | /* This is the first thing in the chain. */ | |
3687 | retval = tmp; | |
3688 | else | |
3689 | p->next = tmp; | |
3690 | p = tmp; | |
3691 | } | |
3692 | p->next = NULL; | |
3693 | return retval; | |
3694 | } | |
3695 | ||
4a64f543 | 3696 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
3697 | |
3698 | bpstat | |
fba45db2 | 3699 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 3700 | { |
c5aa993b JM |
3701 | if (bsp == NULL) |
3702 | return NULL; | |
c906108c | 3703 | |
c5aa993b JM |
3704 | for (; bsp != NULL; bsp = bsp->next) |
3705 | { | |
f431efe5 | 3706 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
3707 | return bsp; |
3708 | } | |
c906108c SS |
3709 | return NULL; |
3710 | } | |
3711 | ||
4a64f543 MS |
3712 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
3713 | stopped at. *BSP upon return is a bpstat which points to the | |
3714 | remaining breakpoints stopped at (but which is not guaranteed to be | |
3715 | good for anything but further calls to bpstat_num). | |
3716 | ||
8671a17b PA |
3717 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
3718 | Return -1 if stopped at a breakpoint that has been deleted since | |
3719 | we set it. | |
3720 | Return 1 otherwise. */ | |
c906108c SS |
3721 | |
3722 | int | |
8671a17b | 3723 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
3724 | { |
3725 | struct breakpoint *b; | |
3726 | ||
3727 | if ((*bsp) == NULL) | |
3728 | return 0; /* No more breakpoint values */ | |
8671a17b | 3729 | |
4a64f543 MS |
3730 | /* We assume we'll never have several bpstats that correspond to a |
3731 | single breakpoint -- otherwise, this function might return the | |
3732 | same number more than once and this will look ugly. */ | |
f431efe5 | 3733 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
3734 | *bsp = (*bsp)->next; |
3735 | if (b == NULL) | |
3736 | return -1; /* breakpoint that's been deleted since */ | |
3737 | ||
3738 | *num = b->number; /* We have its number */ | |
3739 | return 1; | |
c906108c SS |
3740 | } |
3741 | ||
e93ca019 | 3742 | /* See breakpoint.h. */ |
c906108c SS |
3743 | |
3744 | void | |
e93ca019 | 3745 | bpstat_clear_actions (void) |
c906108c | 3746 | { |
e93ca019 JK |
3747 | struct thread_info *tp; |
3748 | bpstat bs; | |
3749 | ||
3750 | if (ptid_equal (inferior_ptid, null_ptid)) | |
3751 | return; | |
3752 | ||
3753 | tp = find_thread_ptid (inferior_ptid); | |
3754 | if (tp == NULL) | |
3755 | return; | |
3756 | ||
3757 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) | |
c906108c | 3758 | { |
9add0f1b | 3759 | decref_counted_command_line (&bs->commands); |
abf85f46 | 3760 | |
c906108c SS |
3761 | if (bs->old_val != NULL) |
3762 | { | |
3763 | value_free (bs->old_val); | |
3764 | bs->old_val = NULL; | |
3765 | } | |
3766 | } | |
3767 | } | |
3768 | ||
f3b1572e PA |
3769 | /* Called when a command is about to proceed the inferior. */ |
3770 | ||
3771 | static void | |
3772 | breakpoint_about_to_proceed (void) | |
3773 | { | |
3774 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
3775 | { | |
3776 | struct thread_info *tp = inferior_thread (); | |
3777 | ||
3778 | /* Allow inferior function calls in breakpoint commands to not | |
3779 | interrupt the command list. When the call finishes | |
3780 | successfully, the inferior will be standing at the same | |
3781 | breakpoint as if nothing happened. */ | |
16c381f0 | 3782 | if (tp->control.in_infcall) |
f3b1572e PA |
3783 | return; |
3784 | } | |
3785 | ||
3786 | breakpoint_proceeded = 1; | |
3787 | } | |
3788 | ||
4a64f543 MS |
3789 | /* Stub for cleaning up our state if we error-out of a breakpoint |
3790 | command. */ | |
c906108c | 3791 | static void |
4efb68b1 | 3792 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
3793 | { |
3794 | executing_breakpoint_commands = 0; | |
3795 | } | |
3796 | ||
abf85f46 JK |
3797 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
3798 | or its equivalent. */ | |
3799 | ||
3800 | static int | |
3801 | command_line_is_silent (struct command_line *cmd) | |
3802 | { | |
3803 | return cmd && (strcmp ("silent", cmd->line) == 0 | |
3804 | || (xdb_commands && strcmp ("Q", cmd->line) == 0)); | |
3805 | } | |
3806 | ||
4a64f543 MS |
3807 | /* Execute all the commands associated with all the breakpoints at |
3808 | this location. Any of these commands could cause the process to | |
3809 | proceed beyond this point, etc. We look out for such changes by | |
3810 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 3811 | |
347bddb7 PA |
3812 | Returns true if a breakpoint command resumed the inferior. In that |
3813 | case, it is the caller's responsibility to recall it again with the | |
3814 | bpstat of the current thread. */ | |
3815 | ||
3816 | static int | |
3817 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
3818 | { |
3819 | bpstat bs; | |
3820 | struct cleanup *old_chain; | |
347bddb7 | 3821 | int again = 0; |
c906108c SS |
3822 | |
3823 | /* Avoid endless recursion if a `source' command is contained | |
3824 | in bs->commands. */ | |
3825 | if (executing_breakpoint_commands) | |
347bddb7 | 3826 | return 0; |
c906108c SS |
3827 | |
3828 | executing_breakpoint_commands = 1; | |
3829 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
3830 | ||
cf6c5ffb TT |
3831 | prevent_dont_repeat (); |
3832 | ||
4a64f543 | 3833 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
3834 | bs = *bsp; |
3835 | ||
3836 | breakpoint_proceeded = 0; | |
3837 | for (; bs != NULL; bs = bs->next) | |
3838 | { | |
9add0f1b | 3839 | struct counted_command_line *ccmd; |
6c50ab1c JB |
3840 | struct command_line *cmd; |
3841 | struct cleanup *this_cmd_tree_chain; | |
3842 | ||
3843 | /* Take ownership of the BSP's command tree, if it has one. | |
3844 | ||
3845 | The command tree could legitimately contain commands like | |
3846 | 'step' and 'next', which call clear_proceed_status, which | |
3847 | frees stop_bpstat's command tree. To make sure this doesn't | |
3848 | free the tree we're executing out from under us, we need to | |
3849 | take ownership of the tree ourselves. Since a given bpstat's | |
3850 | commands are only executed once, we don't need to copy it; we | |
3851 | can clear the pointer in the bpstat, and make sure we free | |
3852 | the tree when we're done. */ | |
9add0f1b TT |
3853 | ccmd = bs->commands; |
3854 | bs->commands = NULL; | |
abf85f46 JK |
3855 | this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd); |
3856 | cmd = ccmd ? ccmd->commands : NULL; | |
3857 | if (command_line_is_silent (cmd)) | |
3858 | { | |
3859 | /* The action has been already done by bpstat_stop_status. */ | |
3860 | cmd = cmd->next; | |
3861 | } | |
6c50ab1c | 3862 | |
c906108c SS |
3863 | while (cmd != NULL) |
3864 | { | |
3865 | execute_control_command (cmd); | |
3866 | ||
3867 | if (breakpoint_proceeded) | |
3868 | break; | |
3869 | else | |
3870 | cmd = cmd->next; | |
3871 | } | |
6c50ab1c JB |
3872 | |
3873 | /* We can free this command tree now. */ | |
3874 | do_cleanups (this_cmd_tree_chain); | |
3875 | ||
c906108c | 3876 | if (breakpoint_proceeded) |
32c1e744 VP |
3877 | { |
3878 | if (target_can_async_p ()) | |
347bddb7 PA |
3879 | /* If we are in async mode, then the target might be still |
3880 | running, not stopped at any breakpoint, so nothing for | |
3881 | us to do here -- just return to the event loop. */ | |
3882 | ; | |
32c1e744 VP |
3883 | else |
3884 | /* In sync mode, when execute_control_command returns | |
3885 | we're already standing on the next breakpoint. | |
347bddb7 PA |
3886 | Breakpoint commands for that stop were not run, since |
3887 | execute_command does not run breakpoint commands -- | |
3888 | only command_line_handler does, but that one is not | |
3889 | involved in execution of breakpoint commands. So, we | |
3890 | can now execute breakpoint commands. It should be | |
3891 | noted that making execute_command do bpstat actions is | |
3892 | not an option -- in this case we'll have recursive | |
3893 | invocation of bpstat for each breakpoint with a | |
3894 | command, and can easily blow up GDB stack. Instead, we | |
3895 | return true, which will trigger the caller to recall us | |
3896 | with the new stop_bpstat. */ | |
3897 | again = 1; | |
3898 | break; | |
32c1e744 | 3899 | } |
c906108c | 3900 | } |
c2b8ed2c | 3901 | do_cleanups (old_chain); |
347bddb7 PA |
3902 | return again; |
3903 | } | |
3904 | ||
3905 | void | |
3906 | bpstat_do_actions (void) | |
3907 | { | |
353d1d73 JK |
3908 | struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup (); |
3909 | ||
347bddb7 PA |
3910 | /* Do any commands attached to breakpoint we are stopped at. */ |
3911 | while (!ptid_equal (inferior_ptid, null_ptid) | |
3912 | && target_has_execution | |
3913 | && !is_exited (inferior_ptid) | |
3914 | && !is_executing (inferior_ptid)) | |
3915 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
3916 | and only return when it is stopped at the next breakpoint, we | |
3917 | keep doing breakpoint actions until it returns false to | |
3918 | indicate the inferior was not resumed. */ | |
16c381f0 | 3919 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
347bddb7 | 3920 | break; |
353d1d73 JK |
3921 | |
3922 | discard_cleanups (cleanup_if_error); | |
c906108c SS |
3923 | } |
3924 | ||
fa4727a6 DJ |
3925 | /* Print out the (old or new) value associated with a watchpoint. */ |
3926 | ||
3927 | static void | |
3928 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
3929 | { | |
3930 | if (val == NULL) | |
3931 | fprintf_unfiltered (stream, _("<unreadable>")); | |
3932 | else | |
79a45b7d TT |
3933 | { |
3934 | struct value_print_options opts; | |
3935 | get_user_print_options (&opts); | |
3936 | value_print (val, stream, &opts); | |
3937 | } | |
fa4727a6 DJ |
3938 | } |
3939 | ||
e514a9d6 | 3940 | /* Generic routine for printing messages indicating why we |
4a64f543 | 3941 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
3942 | 'print_it' in the bpstat structure. Under some circumstances we |
3943 | may decide not to print anything here and delegate the task to | |
4a64f543 | 3944 | normal_stop(). */ |
e514a9d6 JM |
3945 | |
3946 | static enum print_stop_action | |
3947 | print_bp_stop_message (bpstat bs) | |
3948 | { | |
3949 | switch (bs->print_it) | |
3950 | { | |
3951 | case print_it_noop: | |
4a64f543 | 3952 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
3953 | return PRINT_UNKNOWN; |
3954 | break; | |
3955 | ||
3956 | case print_it_done: | |
3957 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 3958 | relevant messages. */ |
e514a9d6 JM |
3959 | return PRINT_SRC_AND_LOC; |
3960 | break; | |
3961 | ||
3962 | case print_it_normal: | |
4f8d1dc6 | 3963 | { |
f431efe5 PA |
3964 | struct breakpoint *b = bs->breakpoint_at; |
3965 | ||
1a6a67de TJB |
3966 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
3967 | which has since been deleted. */ | |
3968 | if (b == NULL) | |
3969 | return PRINT_UNKNOWN; | |
3970 | ||
348d480f PA |
3971 | /* Normal case. Call the breakpoint's print_it method. */ |
3972 | return b->ops->print_it (bs); | |
4f8d1dc6 | 3973 | } |
348d480f | 3974 | break; |
3086aeae | 3975 | |
e514a9d6 | 3976 | default: |
8e65ff28 | 3977 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 3978 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 3979 | break; |
c906108c | 3980 | } |
c906108c SS |
3981 | } |
3982 | ||
edcc5120 TT |
3983 | /* A helper function that prints a shared library stopped event. */ |
3984 | ||
3985 | static void | |
3986 | print_solib_event (int is_catchpoint) | |
3987 | { | |
3988 | int any_deleted | |
3989 | = !VEC_empty (char_ptr, current_program_space->deleted_solibs); | |
3990 | int any_added | |
3991 | = !VEC_empty (so_list_ptr, current_program_space->added_solibs); | |
3992 | ||
3993 | if (!is_catchpoint) | |
3994 | { | |
3995 | if (any_added || any_deleted) | |
3996 | ui_out_text (current_uiout, | |
3997 | _("Stopped due to shared library event:\n")); | |
3998 | else | |
3999 | ui_out_text (current_uiout, | |
4000 | _("Stopped due to shared library event (no " | |
4001 | "libraries added or removed)\n")); | |
4002 | } | |
4003 | ||
4004 | if (ui_out_is_mi_like_p (current_uiout)) | |
4005 | ui_out_field_string (current_uiout, "reason", | |
4006 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); | |
4007 | ||
4008 | if (any_deleted) | |
4009 | { | |
4010 | struct cleanup *cleanup; | |
4011 | char *name; | |
4012 | int ix; | |
4013 | ||
4014 | ui_out_text (current_uiout, _(" Inferior unloaded ")); | |
4015 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
4016 | "removed"); | |
4017 | for (ix = 0; | |
4018 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
4019 | ix, name); | |
4020 | ++ix) | |
4021 | { | |
4022 | if (ix > 0) | |
4023 | ui_out_text (current_uiout, " "); | |
4024 | ui_out_field_string (current_uiout, "library", name); | |
4025 | ui_out_text (current_uiout, "\n"); | |
4026 | } | |
4027 | ||
4028 | do_cleanups (cleanup); | |
4029 | } | |
4030 | ||
4031 | if (any_added) | |
4032 | { | |
4033 | struct so_list *iter; | |
4034 | int ix; | |
4035 | struct cleanup *cleanup; | |
4036 | ||
4037 | ui_out_text (current_uiout, _(" Inferior loaded ")); | |
4038 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
4039 | "added"); | |
4040 | for (ix = 0; | |
4041 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
4042 | ix, iter); | |
4043 | ++ix) | |
4044 | { | |
4045 | if (ix > 0) | |
4046 | ui_out_text (current_uiout, " "); | |
4047 | ui_out_field_string (current_uiout, "library", iter->so_name); | |
4048 | ui_out_text (current_uiout, "\n"); | |
4049 | } | |
4050 | ||
4051 | do_cleanups (cleanup); | |
4052 | } | |
4053 | } | |
4054 | ||
e514a9d6 JM |
4055 | /* Print a message indicating what happened. This is called from |
4056 | normal_stop(). The input to this routine is the head of the bpstat | |
36dfb11c TT |
4057 | list - a list of the eventpoints that caused this stop. KIND is |
4058 | the target_waitkind for the stopping event. This | |
e514a9d6 JM |
4059 | routine calls the generic print routine for printing a message |
4060 | about reasons for stopping. This will print (for example) the | |
4061 | "Breakpoint n," part of the output. The return value of this | |
4062 | routine is one of: | |
c906108c | 4063 | |
4a64f543 | 4064 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 4065 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 4066 | code to print the location. An example is |
c5aa993b JM |
4067 | "Breakpoint 1, " which should be followed by |
4068 | the location. | |
917317f4 | 4069 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
4070 | to also print the location part of the message. |
4071 | An example is the catch/throw messages, which | |
4a64f543 | 4072 | don't require a location appended to the end. |
917317f4 | 4073 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 4074 | further info to be printed. */ |
c906108c | 4075 | |
917317f4 | 4076 | enum print_stop_action |
36dfb11c | 4077 | bpstat_print (bpstat bs, int kind) |
c906108c SS |
4078 | { |
4079 | int val; | |
c5aa993b | 4080 | |
c906108c | 4081 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
4082 | (Currently all watchpoints go on the bpstat whether hit or not. |
4083 | That probably could (should) be changed, provided care is taken | |
c906108c | 4084 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
4085 | for (; bs; bs = bs->next) |
4086 | { | |
4087 | val = print_bp_stop_message (bs); | |
4088 | if (val == PRINT_SRC_ONLY | |
4089 | || val == PRINT_SRC_AND_LOC | |
4090 | || val == PRINT_NOTHING) | |
4091 | return val; | |
4092 | } | |
c906108c | 4093 | |
36dfb11c TT |
4094 | /* If we had hit a shared library event breakpoint, |
4095 | print_bp_stop_message would print out this message. If we hit an | |
4096 | OS-level shared library event, do the same thing. */ | |
4097 | if (kind == TARGET_WAITKIND_LOADED) | |
4098 | { | |
edcc5120 | 4099 | print_solib_event (0); |
36dfb11c TT |
4100 | return PRINT_NOTHING; |
4101 | } | |
4102 | ||
e514a9d6 | 4103 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 4104 | with and nothing was printed. */ |
917317f4 | 4105 | return PRINT_UNKNOWN; |
c906108c SS |
4106 | } |
4107 | ||
4a64f543 MS |
4108 | /* Evaluate the expression EXP and return 1 if value is zero. This is |
4109 | used inside a catch_errors to evaluate the breakpoint condition. | |
4110 | The argument is a "struct expression *" that has been cast to a | |
4111 | "char *" to make it pass through catch_errors. */ | |
c906108c SS |
4112 | |
4113 | static int | |
4efb68b1 | 4114 | breakpoint_cond_eval (void *exp) |
c906108c | 4115 | { |
278cd55f | 4116 | struct value *mark = value_mark (); |
c5aa993b | 4117 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 4118 | |
c906108c SS |
4119 | value_free_to_mark (mark); |
4120 | return i; | |
4121 | } | |
4122 | ||
5760d0ab | 4123 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c SS |
4124 | |
4125 | static bpstat | |
5760d0ab | 4126 | bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) |
c906108c SS |
4127 | { |
4128 | bpstat bs; | |
4129 | ||
4130 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
5760d0ab JK |
4131 | bs->next = NULL; |
4132 | **bs_link_pointer = bs; | |
4133 | *bs_link_pointer = &bs->next; | |
f431efe5 PA |
4134 | bs->breakpoint_at = bl->owner; |
4135 | bs->bp_location_at = bl; | |
4136 | incref_bp_location (bl); | |
c906108c SS |
4137 | /* If the condition is false, etc., don't do the commands. */ |
4138 | bs->commands = NULL; | |
4139 | bs->old_val = NULL; | |
4140 | bs->print_it = print_it_normal; | |
4141 | return bs; | |
4142 | } | |
4143 | \f | |
d983da9c DJ |
4144 | /* The target has stopped with waitstatus WS. Check if any hardware |
4145 | watchpoints have triggered, according to the target. */ | |
4146 | ||
4147 | int | |
4148 | watchpoints_triggered (struct target_waitstatus *ws) | |
4149 | { | |
d92524f1 | 4150 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
4151 | CORE_ADDR addr; |
4152 | struct breakpoint *b; | |
4153 | ||
4154 | if (!stopped_by_watchpoint) | |
4155 | { | |
4156 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
4157 | as not triggered. */ | |
4158 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4159 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4160 | { |
4161 | struct watchpoint *w = (struct watchpoint *) b; | |
4162 | ||
4163 | w->watchpoint_triggered = watch_triggered_no; | |
4164 | } | |
d983da9c DJ |
4165 | |
4166 | return 0; | |
4167 | } | |
4168 | ||
4169 | if (!target_stopped_data_address (¤t_target, &addr)) | |
4170 | { | |
4171 | /* We were stopped by a watchpoint, but we don't know where. | |
4172 | Mark all watchpoints as unknown. */ | |
4173 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4174 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4175 | { |
4176 | struct watchpoint *w = (struct watchpoint *) b; | |
4177 | ||
4178 | w->watchpoint_triggered = watch_triggered_unknown; | |
4179 | } | |
d983da9c DJ |
4180 | |
4181 | return stopped_by_watchpoint; | |
4182 | } | |
4183 | ||
4184 | /* The target could report the data address. Mark watchpoints | |
4185 | affected by this data address as triggered, and all others as not | |
4186 | triggered. */ | |
4187 | ||
4188 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4189 | if (is_hardware_watchpoint (b)) |
d983da9c | 4190 | { |
3a5c3e22 | 4191 | struct watchpoint *w = (struct watchpoint *) b; |
a5606eee | 4192 | struct bp_location *loc; |
d983da9c | 4193 | |
3a5c3e22 | 4194 | w->watchpoint_triggered = watch_triggered_no; |
a5606eee | 4195 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 | 4196 | { |
3a5c3e22 | 4197 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 4198 | { |
3a5c3e22 PA |
4199 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
4200 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
4201 | |
4202 | if (newaddr == start) | |
4203 | { | |
3a5c3e22 | 4204 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4205 | break; |
4206 | } | |
4207 | } | |
4208 | /* Exact match not required. Within range is sufficient. */ | |
4209 | else if (target_watchpoint_addr_within_range (¤t_target, | |
4210 | addr, loc->address, | |
4211 | loc->length)) | |
4212 | { | |
3a5c3e22 | 4213 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4214 | break; |
4215 | } | |
4216 | } | |
d983da9c DJ |
4217 | } |
4218 | ||
4219 | return 1; | |
4220 | } | |
4221 | ||
c906108c SS |
4222 | /* Possible return values for watchpoint_check (this can't be an enum |
4223 | because of check_errors). */ | |
4224 | /* The watchpoint has been deleted. */ | |
4225 | #define WP_DELETED 1 | |
4226 | /* The value has changed. */ | |
4227 | #define WP_VALUE_CHANGED 2 | |
4228 | /* The value has not changed. */ | |
4229 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
4230 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
4231 | #define WP_IGNORE 4 | |
c906108c SS |
4232 | |
4233 | #define BP_TEMPFLAG 1 | |
4234 | #define BP_HARDWAREFLAG 2 | |
4235 | ||
4a64f543 MS |
4236 | /* Evaluate watchpoint condition expression and check if its value |
4237 | changed. | |
553e4c11 JB |
4238 | |
4239 | P should be a pointer to struct bpstat, but is defined as a void * | |
4240 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
4241 | |
4242 | static int | |
4efb68b1 | 4243 | watchpoint_check (void *p) |
c906108c SS |
4244 | { |
4245 | bpstat bs = (bpstat) p; | |
3a5c3e22 | 4246 | struct watchpoint *b; |
c906108c SS |
4247 | struct frame_info *fr; |
4248 | int within_current_scope; | |
4249 | ||
f431efe5 | 4250 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 4251 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 4252 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 4253 | |
f6bc2008 PA |
4254 | /* If this is a local watchpoint, we only want to check if the |
4255 | watchpoint frame is in scope if the current thread is the thread | |
4256 | that was used to create the watchpoint. */ | |
4257 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 4258 | return WP_IGNORE; |
f6bc2008 | 4259 | |
c906108c SS |
4260 | if (b->exp_valid_block == NULL) |
4261 | within_current_scope = 1; | |
4262 | else | |
4263 | { | |
edb3359d DJ |
4264 | struct frame_info *frame = get_current_frame (); |
4265 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
4266 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
4267 | ||
4a64f543 MS |
4268 | /* in_function_epilogue_p() returns a non-zero value if we're |
4269 | still in the function but the stack frame has already been | |
4270 | invalidated. Since we can't rely on the values of local | |
4271 | variables after the stack has been destroyed, we are treating | |
4272 | the watchpoint in that state as `not changed' without further | |
4273 | checking. Don't mark watchpoints as changed if the current | |
4274 | frame is in an epilogue - even if they are in some other | |
4275 | frame, our view of the stack is likely to be wrong and | |
4276 | frame_find_by_id could error out. */ | |
a0f49112 | 4277 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) |
60e1c644 | 4278 | return WP_IGNORE; |
a0f49112 | 4279 | |
101dcfbe | 4280 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 4281 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
4282 | |
4283 | /* If we've gotten confused in the unwinder, we might have | |
4284 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
4285 | if (within_current_scope) |
4286 | { | |
4287 | struct symbol *function; | |
4288 | ||
4289 | function = get_frame_function (fr); | |
4290 | if (function == NULL | |
4291 | || !contained_in (b->exp_valid_block, | |
4292 | SYMBOL_BLOCK_VALUE (function))) | |
4293 | within_current_scope = 0; | |
4294 | } | |
69fbadd5 | 4295 | |
edb3359d | 4296 | if (within_current_scope) |
c906108c SS |
4297 | /* If we end up stopping, the current frame will get selected |
4298 | in normal_stop. So this call to select_frame won't affect | |
4299 | the user. */ | |
0f7d239c | 4300 | select_frame (fr); |
c906108c | 4301 | } |
c5aa993b | 4302 | |
c906108c SS |
4303 | if (within_current_scope) |
4304 | { | |
4a64f543 MS |
4305 | /* We use value_{,free_to_}mark because it could be a *long* |
4306 | time before we return to the command level and call | |
4307 | free_all_values. We can't call free_all_values because we | |
4308 | might be in the middle of evaluating a function call. */ | |
c906108c | 4309 | |
0cf6dd15 | 4310 | int pc = 0; |
9c06b0b4 | 4311 | struct value *mark; |
fa4727a6 DJ |
4312 | struct value *new_val; |
4313 | ||
3a5c3e22 | 4314 | if (is_masked_watchpoint (&b->base)) |
9c06b0b4 TJB |
4315 | /* Since we don't know the exact trigger address (from |
4316 | stopped_data_address), just tell the user we've triggered | |
4317 | a mask watchpoint. */ | |
4318 | return WP_VALUE_CHANGED; | |
4319 | ||
4320 | mark = value_mark (); | |
0cf6dd15 | 4321 | fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL); |
218d2fc6 | 4322 | |
4a64f543 MS |
4323 | /* We use value_equal_contents instead of value_equal because |
4324 | the latter coerces an array to a pointer, thus comparing just | |
4325 | the address of the array instead of its contents. This is | |
4326 | not what we want. */ | |
fa4727a6 | 4327 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 4328 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 4329 | { |
fa4727a6 DJ |
4330 | if (new_val != NULL) |
4331 | { | |
4332 | release_value (new_val); | |
4333 | value_free_to_mark (mark); | |
4334 | } | |
c906108c SS |
4335 | bs->old_val = b->val; |
4336 | b->val = new_val; | |
fa4727a6 | 4337 | b->val_valid = 1; |
c906108c SS |
4338 | return WP_VALUE_CHANGED; |
4339 | } | |
4340 | else | |
4341 | { | |
60e1c644 | 4342 | /* Nothing changed. */ |
c906108c | 4343 | value_free_to_mark (mark); |
c906108c SS |
4344 | return WP_VALUE_NOT_CHANGED; |
4345 | } | |
4346 | } | |
4347 | else | |
4348 | { | |
79a45e25 PA |
4349 | struct ui_out *uiout = current_uiout; |
4350 | ||
c906108c | 4351 | /* This seems like the only logical thing to do because |
c5aa993b JM |
4352 | if we temporarily ignored the watchpoint, then when |
4353 | we reenter the block in which it is valid it contains | |
4354 | garbage (in the case of a function, it may have two | |
4355 | garbage values, one before and one after the prologue). | |
4356 | So we can't even detect the first assignment to it and | |
4357 | watch after that (since the garbage may or may not equal | |
4358 | the first value assigned). */ | |
348d480f PA |
4359 | /* We print all the stop information in |
4360 | breakpoint_ops->print_it, but in this case, by the time we | |
4361 | call breakpoint_ops->print_it this bp will be deleted | |
4362 | already. So we have no choice but print the information | |
4363 | here. */ | |
9dc5e2a9 | 4364 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
4365 | ui_out_field_string |
4366 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 4367 | ui_out_text (uiout, "\nWatchpoint "); |
3a5c3e22 | 4368 | ui_out_field_int (uiout, "wpnum", b->base.number); |
3e43a32a MS |
4369 | ui_out_text (uiout, |
4370 | " deleted because the program has left the block in\n\ | |
8b93c638 | 4371 | which its expression is valid.\n"); |
4ce44c66 | 4372 | |
cdac0397 | 4373 | /* Make sure the watchpoint's commands aren't executed. */ |
3a5c3e22 | 4374 | decref_counted_command_line (&b->base.commands); |
d0fb5eae | 4375 | watchpoint_del_at_next_stop (b); |
c906108c SS |
4376 | |
4377 | return WP_DELETED; | |
4378 | } | |
4379 | } | |
4380 | ||
18a18393 | 4381 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
4382 | breakpoint location BL. This function does not check if we should |
4383 | stop, only if BL explains the stop. */ | |
4384 | ||
18a18393 | 4385 | static int |
6c95b8df | 4386 | bpstat_check_location (const struct bp_location *bl, |
09ac7c10 TT |
4387 | struct address_space *aspace, CORE_ADDR bp_addr, |
4388 | const struct target_waitstatus *ws) | |
18a18393 VP |
4389 | { |
4390 | struct breakpoint *b = bl->owner; | |
4391 | ||
348d480f | 4392 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
4393 | gdb_assert (b != NULL); |
4394 | ||
09ac7c10 | 4395 | return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws); |
18a18393 VP |
4396 | } |
4397 | ||
3a5c3e22 PA |
4398 | /* Determine if the watched values have actually changed, and we |
4399 | should stop. If not, set BS->stop to 0. */ | |
4400 | ||
18a18393 VP |
4401 | static void |
4402 | bpstat_check_watchpoint (bpstat bs) | |
4403 | { | |
2bdf28a0 | 4404 | const struct bp_location *bl; |
3a5c3e22 | 4405 | struct watchpoint *b; |
2bdf28a0 JK |
4406 | |
4407 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 4408 | bl = bs->bp_location_at; |
2bdf28a0 | 4409 | gdb_assert (bl != NULL); |
3a5c3e22 | 4410 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 4411 | gdb_assert (b != NULL); |
18a18393 | 4412 | |
18a18393 | 4413 | { |
18a18393 VP |
4414 | int must_check_value = 0; |
4415 | ||
3a5c3e22 | 4416 | if (b->base.type == bp_watchpoint) |
18a18393 VP |
4417 | /* For a software watchpoint, we must always check the |
4418 | watched value. */ | |
4419 | must_check_value = 1; | |
4420 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
4421 | /* We have a hardware watchpoint (read, write, or access) | |
4422 | and the target earlier reported an address watched by | |
4423 | this watchpoint. */ | |
4424 | must_check_value = 1; | |
4425 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3a5c3e22 | 4426 | && b->base.type == bp_hardware_watchpoint) |
18a18393 VP |
4427 | /* We were stopped by a hardware watchpoint, but the target could |
4428 | not report the data address. We must check the watchpoint's | |
4429 | value. Access and read watchpoints are out of luck; without | |
4430 | a data address, we can't figure it out. */ | |
4431 | must_check_value = 1; | |
3a5c3e22 | 4432 | |
18a18393 VP |
4433 | if (must_check_value) |
4434 | { | |
3e43a32a MS |
4435 | char *message |
4436 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3a5c3e22 | 4437 | b->base.number); |
18a18393 VP |
4438 | struct cleanup *cleanups = make_cleanup (xfree, message); |
4439 | int e = catch_errors (watchpoint_check, bs, message, | |
4440 | RETURN_MASK_ALL); | |
4441 | do_cleanups (cleanups); | |
4442 | switch (e) | |
4443 | { | |
4444 | case WP_DELETED: | |
4445 | /* We've already printed what needs to be printed. */ | |
4446 | bs->print_it = print_it_done; | |
4447 | /* Stop. */ | |
4448 | break; | |
60e1c644 PA |
4449 | case WP_IGNORE: |
4450 | bs->print_it = print_it_noop; | |
4451 | bs->stop = 0; | |
4452 | break; | |
18a18393 | 4453 | case WP_VALUE_CHANGED: |
3a5c3e22 | 4454 | if (b->base.type == bp_read_watchpoint) |
18a18393 | 4455 | { |
85d721b8 PA |
4456 | /* There are two cases to consider here: |
4457 | ||
4a64f543 | 4458 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
4459 | In that case, trust the target, and always report |
4460 | the watchpoint hit to the user. Even though | |
4461 | reads don't cause value changes, the value may | |
4462 | have changed since the last time it was read, and | |
4463 | since we're not trapping writes, we will not see | |
4464 | those, and as such we should ignore our notion of | |
4465 | old value. | |
4466 | ||
4a64f543 | 4467 | 2. We're watching the triggered memory for both |
85d721b8 PA |
4468 | reads and writes. There are two ways this may |
4469 | happen: | |
4470 | ||
4a64f543 | 4471 | 2.1. This is a target that can't break on data |
85d721b8 PA |
4472 | reads only, but can break on accesses (reads or |
4473 | writes), such as e.g., x86. We detect this case | |
4474 | at the time we try to insert read watchpoints. | |
4475 | ||
4a64f543 | 4476 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
4477 | watchpoints, but, the user set an access or write |
4478 | watchpoint watching the same memory as this read | |
4479 | watchpoint. | |
4480 | ||
4481 | If we're watching memory writes as well as reads, | |
4482 | ignore watchpoint hits when we find that the | |
4483 | value hasn't changed, as reads don't cause | |
4484 | changes. This still gives false positives when | |
4485 | the program writes the same value to memory as | |
4486 | what there was already in memory (we will confuse | |
4487 | it for a read), but it's much better than | |
4488 | nothing. */ | |
4489 | ||
4490 | int other_write_watchpoint = 0; | |
4491 | ||
4492 | if (bl->watchpoint_type == hw_read) | |
4493 | { | |
4494 | struct breakpoint *other_b; | |
4495 | ||
4496 | ALL_BREAKPOINTS (other_b) | |
3a5c3e22 PA |
4497 | if (other_b->type == bp_hardware_watchpoint |
4498 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 4499 | { |
3a5c3e22 PA |
4500 | struct watchpoint *other_w = |
4501 | (struct watchpoint *) other_b; | |
4502 | ||
4503 | if (other_w->watchpoint_triggered | |
4504 | == watch_triggered_yes) | |
4505 | { | |
4506 | other_write_watchpoint = 1; | |
4507 | break; | |
4508 | } | |
85d721b8 PA |
4509 | } |
4510 | } | |
4511 | ||
4512 | if (other_write_watchpoint | |
4513 | || bl->watchpoint_type == hw_access) | |
4514 | { | |
4515 | /* We're watching the same memory for writes, | |
4516 | and the value changed since the last time we | |
4517 | updated it, so this trap must be for a write. | |
4518 | Ignore it. */ | |
4519 | bs->print_it = print_it_noop; | |
4520 | bs->stop = 0; | |
4521 | } | |
18a18393 VP |
4522 | } |
4523 | break; | |
4524 | case WP_VALUE_NOT_CHANGED: | |
3a5c3e22 PA |
4525 | if (b->base.type == bp_hardware_watchpoint |
4526 | || b->base.type == bp_watchpoint) | |
18a18393 VP |
4527 | { |
4528 | /* Don't stop: write watchpoints shouldn't fire if | |
4529 | the value hasn't changed. */ | |
4530 | bs->print_it = print_it_noop; | |
4531 | bs->stop = 0; | |
4532 | } | |
4533 | /* Stop. */ | |
4534 | break; | |
4535 | default: | |
4536 | /* Can't happen. */ | |
4537 | case 0: | |
4538 | /* Error from catch_errors. */ | |
3a5c3e22 | 4539 | printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number); |
d0fb5eae | 4540 | watchpoint_del_at_next_stop (b); |
18a18393 VP |
4541 | /* We've already printed what needs to be printed. */ |
4542 | bs->print_it = print_it_done; | |
4543 | break; | |
4544 | } | |
4545 | } | |
4546 | else /* must_check_value == 0 */ | |
4547 | { | |
4548 | /* This is a case where some watchpoint(s) triggered, but | |
4549 | not at the address of this watchpoint, or else no | |
4550 | watchpoint triggered after all. So don't print | |
4551 | anything for this watchpoint. */ | |
4552 | bs->print_it = print_it_noop; | |
4553 | bs->stop = 0; | |
4554 | } | |
4555 | } | |
4556 | } | |
4557 | ||
4558 | ||
4559 | /* Check conditions (condition proper, frame, thread and ignore count) | |
4560 | of breakpoint referred to by BS. If we should not stop for this | |
4561 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 4562 | |
18a18393 VP |
4563 | static void |
4564 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
4565 | { | |
4566 | int thread_id = pid_to_thread_id (ptid); | |
2bdf28a0 JK |
4567 | const struct bp_location *bl; |
4568 | struct breakpoint *b; | |
4569 | ||
4570 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 4571 | bl = bs->bp_location_at; |
2bdf28a0 | 4572 | gdb_assert (bl != NULL); |
f431efe5 | 4573 | b = bs->breakpoint_at; |
2bdf28a0 | 4574 | gdb_assert (b != NULL); |
18a18393 | 4575 | |
b775012e LM |
4576 | /* Even if the target evaluated the condition on its end and notified GDB, we |
4577 | need to do so again since GDB does not know if we stopped due to a | |
4578 | breakpoint or a single step breakpoint. */ | |
4579 | ||
18a18393 | 4580 | if (frame_id_p (b->frame_id) |
edb3359d | 4581 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 VP |
4582 | bs->stop = 0; |
4583 | else if (bs->stop) | |
4584 | { | |
4585 | int value_is_zero = 0; | |
60e1c644 PA |
4586 | struct expression *cond; |
4587 | ||
7371cf6d PM |
4588 | /* Evaluate Python breakpoints that have a "stop" |
4589 | method implemented. */ | |
4590 | if (b->py_bp_object) | |
4591 | bs->stop = gdbpy_should_stop (b->py_bp_object); | |
4592 | ||
60e1c644 | 4593 | if (is_watchpoint (b)) |
3a5c3e22 PA |
4594 | { |
4595 | struct watchpoint *w = (struct watchpoint *) b; | |
4596 | ||
4597 | cond = w->cond_exp; | |
4598 | } | |
60e1c644 PA |
4599 | else |
4600 | cond = bl->cond; | |
4601 | ||
f431efe5 | 4602 | if (cond && b->disposition != disp_del_at_next_stop) |
18a18393 | 4603 | { |
60e1c644 | 4604 | int within_current_scope = 1; |
3a5c3e22 | 4605 | struct watchpoint * w; |
60e1c644 | 4606 | |
c5bc3a77 DJ |
4607 | /* We use value_mark and value_free_to_mark because it could |
4608 | be a long time before we return to the command level and | |
4609 | call free_all_values. We can't call free_all_values | |
4610 | because we might be in the middle of evaluating a | |
4611 | function call. */ | |
4612 | struct value *mark = value_mark (); | |
4613 | ||
3a5c3e22 PA |
4614 | if (is_watchpoint (b)) |
4615 | w = (struct watchpoint *) b; | |
4616 | else | |
4617 | w = NULL; | |
4618 | ||
edb3359d DJ |
4619 | /* Need to select the frame, with all that implies so that |
4620 | the conditions will have the right context. Because we | |
4621 | use the frame, we will not see an inlined function's | |
4622 | variables when we arrive at a breakpoint at the start | |
4623 | of the inlined function; the current frame will be the | |
4624 | call site. */ | |
3a5c3e22 | 4625 | if (w == NULL || w->cond_exp_valid_block == NULL) |
60e1c644 PA |
4626 | select_frame (get_current_frame ()); |
4627 | else | |
4628 | { | |
4629 | struct frame_info *frame; | |
4630 | ||
4631 | /* For local watchpoint expressions, which particular | |
4632 | instance of a local is being watched matters, so we | |
4633 | keep track of the frame to evaluate the expression | |
4634 | in. To evaluate the condition however, it doesn't | |
4635 | really matter which instantiation of the function | |
4636 | where the condition makes sense triggers the | |
4637 | watchpoint. This allows an expression like "watch | |
4638 | global if q > 10" set in `func', catch writes to | |
4639 | global on all threads that call `func', or catch | |
4640 | writes on all recursive calls of `func' by a single | |
4641 | thread. We simply always evaluate the condition in | |
4642 | the innermost frame that's executing where it makes | |
4643 | sense to evaluate the condition. It seems | |
4644 | intuitive. */ | |
3a5c3e22 | 4645 | frame = block_innermost_frame (w->cond_exp_valid_block); |
60e1c644 PA |
4646 | if (frame != NULL) |
4647 | select_frame (frame); | |
4648 | else | |
4649 | within_current_scope = 0; | |
4650 | } | |
4651 | if (within_current_scope) | |
4652 | value_is_zero | |
4653 | = catch_errors (breakpoint_cond_eval, cond, | |
4654 | "Error in testing breakpoint condition:\n", | |
4655 | RETURN_MASK_ALL); | |
4656 | else | |
4657 | { | |
4658 | warning (_("Watchpoint condition cannot be tested " | |
4659 | "in the current scope")); | |
4660 | /* If we failed to set the right context for this | |
4661 | watchpoint, unconditionally report it. */ | |
4662 | value_is_zero = 0; | |
4663 | } | |
4a64f543 | 4664 | /* FIXME-someday, should give breakpoint #. */ |
c5bc3a77 | 4665 | value_free_to_mark (mark); |
18a18393 | 4666 | } |
60e1c644 PA |
4667 | |
4668 | if (cond && value_is_zero) | |
18a18393 VP |
4669 | { |
4670 | bs->stop = 0; | |
4671 | } | |
4672 | else if (b->thread != -1 && b->thread != thread_id) | |
4673 | { | |
4674 | bs->stop = 0; | |
4675 | } | |
4676 | else if (b->ignore_count > 0) | |
4677 | { | |
4678 | b->ignore_count--; | |
4679 | annotate_ignore_count_change (); | |
4680 | bs->stop = 0; | |
4a64f543 | 4681 | /* Increase the hit count even though we don't stop. */ |
18a18393 | 4682 | ++(b->hit_count); |
8d3788bd | 4683 | observer_notify_breakpoint_modified (b); |
18a18393 VP |
4684 | } |
4685 | } | |
4686 | } | |
4687 | ||
4688 | ||
9709f61c | 4689 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 4690 | BP_ADDR in thread PTID. |
c906108c | 4691 | |
d983da9c | 4692 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
4693 | don't understand this stop. Result is a chain of bpstat's such |
4694 | that: | |
c906108c | 4695 | |
c5aa993b | 4696 | if we don't understand the stop, the result is a null pointer. |
c906108c | 4697 | |
c5aa993b | 4698 | if we understand why we stopped, the result is not null. |
c906108c | 4699 | |
c5aa993b JM |
4700 | Each element of the chain refers to a particular breakpoint or |
4701 | watchpoint at which we have stopped. (We may have stopped for | |
4702 | several reasons concurrently.) | |
c906108c | 4703 | |
c5aa993b JM |
4704 | Each element of the chain has valid next, breakpoint_at, |
4705 | commands, FIXME??? fields. */ | |
c906108c SS |
4706 | |
4707 | bpstat | |
6c95b8df | 4708 | bpstat_stop_status (struct address_space *aspace, |
09ac7c10 TT |
4709 | CORE_ADDR bp_addr, ptid_t ptid, |
4710 | const struct target_waitstatus *ws) | |
c906108c | 4711 | { |
0d381245 | 4712 | struct breakpoint *b = NULL; |
afe38095 | 4713 | struct bp_location *bl; |
20874c92 | 4714 | struct bp_location *loc; |
5760d0ab JK |
4715 | /* First item of allocated bpstat's. */ |
4716 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 4717 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 4718 | bpstat bs; |
20874c92 | 4719 | int ix; |
429374b8 | 4720 | int need_remove_insert; |
f431efe5 | 4721 | int removed_any; |
c906108c | 4722 | |
f431efe5 PA |
4723 | /* First, build the bpstat chain with locations that explain a |
4724 | target stop, while being careful to not set the target running, | |
4725 | as that may invalidate locations (in particular watchpoint | |
4726 | locations are recreated). Resuming will happen here with | |
4727 | breakpoint conditions or watchpoint expressions that include | |
4728 | inferior function calls. */ | |
c5aa993b | 4729 | |
429374b8 JK |
4730 | ALL_BREAKPOINTS (b) |
4731 | { | |
4732 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) | |
4733 | continue; | |
a5606eee | 4734 | |
429374b8 JK |
4735 | for (bl = b->loc; bl != NULL; bl = bl->next) |
4736 | { | |
4a64f543 MS |
4737 | /* For hardware watchpoints, we look only at the first |
4738 | location. The watchpoint_check function will work on the | |
4739 | entire expression, not the individual locations. For | |
4740 | read watchpoints, the watchpoints_triggered function has | |
4741 | checked all locations already. */ | |
429374b8 JK |
4742 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
4743 | break; | |
18a18393 | 4744 | |
429374b8 JK |
4745 | if (bl->shlib_disabled) |
4746 | continue; | |
c5aa993b | 4747 | |
09ac7c10 | 4748 | if (!bpstat_check_location (bl, aspace, bp_addr, ws)) |
429374b8 | 4749 | continue; |
c5aa993b | 4750 | |
4a64f543 MS |
4751 | /* Come here if it's a watchpoint, or if the break address |
4752 | matches. */ | |
c5aa993b | 4753 | |
4a64f543 MS |
4754 | bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to |
4755 | explain stop. */ | |
c5aa993b | 4756 | |
f431efe5 PA |
4757 | /* Assume we stop. Should we find a watchpoint that is not |
4758 | actually triggered, or if the condition of the breakpoint | |
4759 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
4760 | bs->stop = 1; |
4761 | bs->print = 1; | |
d983da9c | 4762 | |
f431efe5 PA |
4763 | /* If this is a scope breakpoint, mark the associated |
4764 | watchpoint as triggered so that we will handle the | |
4765 | out-of-scope event. We'll get to the watchpoint next | |
4766 | iteration. */ | |
d0fb5eae | 4767 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
4768 | { |
4769 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
4770 | ||
4771 | w->watchpoint_triggered = watch_triggered_yes; | |
4772 | } | |
f431efe5 PA |
4773 | } |
4774 | } | |
4775 | ||
4776 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
4777 | { | |
f1310107 | 4778 | if (breakpoint_location_address_match (loc, aspace, bp_addr)) |
f431efe5 | 4779 | { |
5760d0ab | 4780 | bs = bpstat_alloc (loc, &bs_link); |
f431efe5 PA |
4781 | /* For hits of moribund locations, we should just proceed. */ |
4782 | bs->stop = 0; | |
4783 | bs->print = 0; | |
4784 | bs->print_it = print_it_noop; | |
4785 | } | |
4786 | } | |
4787 | ||
edcc5120 TT |
4788 | /* A bit of special processing for shlib breakpoints. We need to |
4789 | process solib loading here, so that the lists of loaded and | |
4790 | unloaded libraries are correct before we handle "catch load" and | |
4791 | "catch unload". */ | |
4792 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
4793 | { | |
5d268276 | 4794 | if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event) |
edcc5120 TT |
4795 | { |
4796 | handle_solib_event (); | |
4797 | break; | |
4798 | } | |
4799 | } | |
4800 | ||
f431efe5 PA |
4801 | /* Now go through the locations that caused the target to stop, and |
4802 | check whether we're interested in reporting this stop to higher | |
4803 | layers, or whether we should resume the target transparently. */ | |
4804 | ||
4805 | removed_any = 0; | |
4806 | ||
5760d0ab | 4807 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
4808 | { |
4809 | if (!bs->stop) | |
4810 | continue; | |
4811 | ||
f431efe5 | 4812 | b = bs->breakpoint_at; |
348d480f PA |
4813 | b->ops->check_status (bs); |
4814 | if (bs->stop) | |
28010a5d | 4815 | { |
348d480f | 4816 | bpstat_check_breakpoint_conditions (bs, ptid); |
f431efe5 | 4817 | |
429374b8 JK |
4818 | if (bs->stop) |
4819 | { | |
4820 | ++(b->hit_count); | |
8d3788bd | 4821 | observer_notify_breakpoint_modified (b); |
c906108c | 4822 | |
4a64f543 | 4823 | /* We will stop here. */ |
429374b8 JK |
4824 | if (b->disposition == disp_disable) |
4825 | { | |
816338b5 SS |
4826 | --(b->enable_count); |
4827 | if (b->enable_count <= 0 | |
4828 | && b->enable_state != bp_permanent) | |
429374b8 | 4829 | b->enable_state = bp_disabled; |
f431efe5 | 4830 | removed_any = 1; |
429374b8 JK |
4831 | } |
4832 | if (b->silent) | |
4833 | bs->print = 0; | |
4834 | bs->commands = b->commands; | |
9add0f1b | 4835 | incref_counted_command_line (bs->commands); |
abf85f46 JK |
4836 | if (command_line_is_silent (bs->commands |
4837 | ? bs->commands->commands : NULL)) | |
4838 | bs->print = 0; | |
429374b8 JK |
4839 | } |
4840 | ||
348d480f | 4841 | } |
a9b3a50f PA |
4842 | |
4843 | /* Print nothing for this entry if we don't stop or don't | |
4844 | print. */ | |
4845 | if (!bs->stop || !bs->print) | |
4846 | bs->print_it = print_it_noop; | |
429374b8 | 4847 | } |
876fa593 | 4848 | |
d983da9c DJ |
4849 | /* If we aren't stopping, the value of some hardware watchpoint may |
4850 | not have changed, but the intermediate memory locations we are | |
4851 | watching may have. Don't bother if we're stopping; this will get | |
4852 | done later. */ | |
d832cb68 | 4853 | need_remove_insert = 0; |
5760d0ab JK |
4854 | if (! bpstat_causes_stop (bs_head)) |
4855 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 4856 | if (!bs->stop |
f431efe5 PA |
4857 | && bs->breakpoint_at |
4858 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 4859 | { |
3a5c3e22 PA |
4860 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
4861 | ||
4862 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 4863 | need_remove_insert = 1; |
d983da9c DJ |
4864 | } |
4865 | ||
d832cb68 | 4866 | if (need_remove_insert) |
2d134ed3 | 4867 | update_global_location_list (1); |
f431efe5 PA |
4868 | else if (removed_any) |
4869 | update_global_location_list (0); | |
d832cb68 | 4870 | |
5760d0ab | 4871 | return bs_head; |
c906108c | 4872 | } |
628fe4e4 JK |
4873 | |
4874 | static void | |
4875 | handle_jit_event (void) | |
4876 | { | |
4877 | struct frame_info *frame; | |
4878 | struct gdbarch *gdbarch; | |
4879 | ||
4880 | /* Switch terminal for any messages produced by | |
4881 | breakpoint_re_set. */ | |
4882 | target_terminal_ours_for_output (); | |
4883 | ||
4884 | frame = get_current_frame (); | |
4885 | gdbarch = get_frame_arch (frame); | |
4886 | ||
4887 | jit_event_handler (gdbarch); | |
4888 | ||
4889 | target_terminal_inferior (); | |
4890 | } | |
4891 | ||
edcc5120 TT |
4892 | /* Handle an solib event by calling solib_add. */ |
4893 | ||
4894 | void | |
4895 | handle_solib_event (void) | |
4896 | { | |
4897 | clear_program_space_solib_cache (current_inferior ()->pspace); | |
4898 | ||
4899 | /* Check for any newly added shared libraries if we're supposed to | |
4900 | be adding them automatically. Switch terminal for any messages | |
4901 | produced by breakpoint_re_set. */ | |
4902 | target_terminal_ours_for_output (); | |
4903 | #ifdef SOLIB_ADD | |
4904 | SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add); | |
4905 | #else | |
4906 | solib_add (NULL, 0, ¤t_target, auto_solib_add); | |
4907 | #endif | |
4908 | target_terminal_inferior (); | |
4909 | } | |
4910 | ||
628fe4e4 JK |
4911 | /* Prepare WHAT final decision for infrun. */ |
4912 | ||
4913 | /* Decide what infrun needs to do with this bpstat. */ | |
4914 | ||
c906108c | 4915 | struct bpstat_what |
0e30163f | 4916 | bpstat_what (bpstat bs_head) |
c906108c | 4917 | { |
c906108c | 4918 | struct bpstat_what retval; |
628fe4e4 | 4919 | int jit_event = 0; |
0e30163f | 4920 | bpstat bs; |
c906108c | 4921 | |
628fe4e4 | 4922 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 4923 | retval.call_dummy = STOP_NONE; |
186c406b | 4924 | retval.is_longjmp = 0; |
628fe4e4 | 4925 | |
0e30163f | 4926 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 4927 | { |
628fe4e4 JK |
4928 | /* Extract this BS's action. After processing each BS, we check |
4929 | if its action overrides all we've seem so far. */ | |
4930 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
4931 | enum bptype bptype; | |
4932 | ||
c906108c | 4933 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
4934 | { |
4935 | /* I suspect this can happen if it was a momentary | |
4936 | breakpoint which has since been deleted. */ | |
4937 | bptype = bp_none; | |
4938 | } | |
20874c92 | 4939 | else |
f431efe5 | 4940 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
4941 | |
4942 | switch (bptype) | |
c906108c SS |
4943 | { |
4944 | case bp_none: | |
628fe4e4 | 4945 | break; |
c906108c SS |
4946 | case bp_breakpoint: |
4947 | case bp_hardware_breakpoint: | |
4948 | case bp_until: | |
4949 | case bp_finish: | |
a9b3a50f | 4950 | case bp_shlib_event: |
c906108c SS |
4951 | if (bs->stop) |
4952 | { | |
4953 | if (bs->print) | |
628fe4e4 | 4954 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 4955 | else |
628fe4e4 | 4956 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
4957 | } |
4958 | else | |
628fe4e4 | 4959 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
4960 | break; |
4961 | case bp_watchpoint: | |
4962 | case bp_hardware_watchpoint: | |
4963 | case bp_read_watchpoint: | |
4964 | case bp_access_watchpoint: | |
4965 | if (bs->stop) | |
4966 | { | |
4967 | if (bs->print) | |
628fe4e4 | 4968 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 4969 | else |
628fe4e4 | 4970 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
4971 | } |
4972 | else | |
628fe4e4 JK |
4973 | { |
4974 | /* There was a watchpoint, but we're not stopping. | |
4975 | This requires no further action. */ | |
4976 | } | |
c906108c SS |
4977 | break; |
4978 | case bp_longjmp: | |
186c406b | 4979 | case bp_exception: |
628fe4e4 | 4980 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; |
186c406b | 4981 | retval.is_longjmp = bptype == bp_longjmp; |
c906108c SS |
4982 | break; |
4983 | case bp_longjmp_resume: | |
186c406b | 4984 | case bp_exception_resume: |
628fe4e4 | 4985 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; |
186c406b | 4986 | retval.is_longjmp = bptype == bp_longjmp_resume; |
c906108c SS |
4987 | break; |
4988 | case bp_step_resume: | |
4989 | if (bs->stop) | |
628fe4e4 JK |
4990 | this_action = BPSTAT_WHAT_STEP_RESUME; |
4991 | else | |
c906108c | 4992 | { |
628fe4e4 JK |
4993 | /* It is for the wrong frame. */ |
4994 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 4995 | } |
c906108c | 4996 | break; |
2c03e5be PA |
4997 | case bp_hp_step_resume: |
4998 | if (bs->stop) | |
4999 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
5000 | else | |
5001 | { | |
5002 | /* It is for the wrong frame. */ | |
5003 | this_action = BPSTAT_WHAT_SINGLE; | |
5004 | } | |
5005 | break; | |
c906108c | 5006 | case bp_watchpoint_scope: |
c4093a6a | 5007 | case bp_thread_event: |
1900040c | 5008 | case bp_overlay_event: |
0fd8e87f | 5009 | case bp_longjmp_master: |
aa7d318d | 5010 | case bp_std_terminate_master: |
186c406b | 5011 | case bp_exception_master: |
628fe4e4 | 5012 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 5013 | break; |
ce78b96d | 5014 | case bp_catchpoint: |
c5aa993b JM |
5015 | if (bs->stop) |
5016 | { | |
5017 | if (bs->print) | |
628fe4e4 | 5018 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 5019 | else |
628fe4e4 | 5020 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
5021 | } |
5022 | else | |
628fe4e4 JK |
5023 | { |
5024 | /* There was a catchpoint, but we're not stopping. | |
5025 | This requires no further action. */ | |
5026 | } | |
5027 | break; | |
628fe4e4 JK |
5028 | case bp_jit_event: |
5029 | jit_event = 1; | |
5030 | this_action = BPSTAT_WHAT_SINGLE; | |
c5aa993b | 5031 | break; |
c906108c | 5032 | case bp_call_dummy: |
53a5351d JM |
5033 | /* Make sure the action is stop (silent or noisy), |
5034 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5035 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 5036 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
5037 | break; |
5038 | case bp_std_terminate: | |
5039 | /* Make sure the action is stop (silent or noisy), | |
5040 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5041 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 5042 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 5043 | break; |
1042e4c0 | 5044 | case bp_tracepoint: |
7a697b8d | 5045 | case bp_fast_tracepoint: |
0fb4aa4b | 5046 | case bp_static_tracepoint: |
1042e4c0 SS |
5047 | /* Tracepoint hits should not be reported back to GDB, and |
5048 | if one got through somehow, it should have been filtered | |
5049 | out already. */ | |
5050 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 5051 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
5052 | break; |
5053 | case bp_gnu_ifunc_resolver: | |
5054 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
5055 | this_action = BPSTAT_WHAT_SINGLE; | |
5056 | break; | |
5057 | case bp_gnu_ifunc_resolver_return: | |
5058 | /* The breakpoint will be removed, execution will restart from the | |
5059 | PC of the former breakpoint. */ | |
5060 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5061 | break; | |
628fe4e4 JK |
5062 | default: |
5063 | internal_error (__FILE__, __LINE__, | |
5064 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 5065 | } |
628fe4e4 JK |
5066 | |
5067 | retval.main_action = max (retval.main_action, this_action); | |
c906108c | 5068 | } |
628fe4e4 | 5069 | |
0e30163f JK |
5070 | /* These operations may affect the bs->breakpoint_at state so they are |
5071 | delayed after MAIN_ACTION is decided above. */ | |
5072 | ||
628fe4e4 JK |
5073 | if (jit_event) |
5074 | { | |
5075 | if (debug_infrun) | |
5076 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n"); | |
5077 | ||
5078 | handle_jit_event (); | |
5079 | } | |
5080 | ||
0e30163f JK |
5081 | for (bs = bs_head; bs != NULL; bs = bs->next) |
5082 | { | |
5083 | struct breakpoint *b = bs->breakpoint_at; | |
5084 | ||
5085 | if (b == NULL) | |
5086 | continue; | |
5087 | switch (b->type) | |
5088 | { | |
5089 | case bp_gnu_ifunc_resolver: | |
5090 | gnu_ifunc_resolver_stop (b); | |
5091 | break; | |
5092 | case bp_gnu_ifunc_resolver_return: | |
5093 | gnu_ifunc_resolver_return_stop (b); | |
5094 | break; | |
5095 | } | |
5096 | } | |
5097 | ||
c906108c SS |
5098 | return retval; |
5099 | } | |
5100 | ||
5101 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
5102 | without hardware support). This isn't related to a specific bpstat, | |
5103 | just to things like whether watchpoints are set. */ | |
5104 | ||
c5aa993b | 5105 | int |
fba45db2 | 5106 | bpstat_should_step (void) |
c906108c SS |
5107 | { |
5108 | struct breakpoint *b; | |
cc59ec59 | 5109 | |
c906108c | 5110 | ALL_BREAKPOINTS (b) |
717a8278 | 5111 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 5112 | return 1; |
c906108c SS |
5113 | return 0; |
5114 | } | |
5115 | ||
67822962 PA |
5116 | int |
5117 | bpstat_causes_stop (bpstat bs) | |
5118 | { | |
5119 | for (; bs != NULL; bs = bs->next) | |
5120 | if (bs->stop) | |
5121 | return 1; | |
5122 | ||
5123 | return 0; | |
5124 | } | |
5125 | ||
c906108c | 5126 | \f |
c5aa993b | 5127 | |
170b53b2 UW |
5128 | /* Compute a string of spaces suitable to indent the next line |
5129 | so it starts at the position corresponding to the table column | |
5130 | named COL_NAME in the currently active table of UIOUT. */ | |
5131 | ||
5132 | static char * | |
5133 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
5134 | { | |
5135 | static char wrap_indent[80]; | |
5136 | int i, total_width, width, align; | |
5137 | char *text; | |
5138 | ||
5139 | total_width = 0; | |
5140 | for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++) | |
5141 | { | |
5142 | if (strcmp (text, col_name) == 0) | |
5143 | { | |
5144 | gdb_assert (total_width < sizeof wrap_indent); | |
5145 | memset (wrap_indent, ' ', total_width); | |
5146 | wrap_indent[total_width] = 0; | |
5147 | ||
5148 | return wrap_indent; | |
5149 | } | |
5150 | ||
5151 | total_width += width + 1; | |
5152 | } | |
5153 | ||
5154 | return NULL; | |
5155 | } | |
5156 | ||
b775012e LM |
5157 | /* Determine if the locations of this breakpoint will have their conditions |
5158 | evaluated by the target, host or a mix of both. Returns the following: | |
5159 | ||
5160 | "host": Host evals condition. | |
5161 | "host or target": Host or Target evals condition. | |
5162 | "target": Target evals condition. | |
5163 | */ | |
5164 | ||
5165 | static const char * | |
5166 | bp_condition_evaluator (struct breakpoint *b) | |
5167 | { | |
5168 | struct bp_location *bl; | |
5169 | char host_evals = 0; | |
5170 | char target_evals = 0; | |
5171 | ||
5172 | if (!b) | |
5173 | return NULL; | |
5174 | ||
5175 | if (!is_breakpoint (b)) | |
5176 | return NULL; | |
5177 | ||
5178 | if (gdb_evaluates_breakpoint_condition_p () | |
5179 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5180 | return condition_evaluation_host; | |
5181 | ||
5182 | for (bl = b->loc; bl; bl = bl->next) | |
5183 | { | |
5184 | if (bl->cond_bytecode) | |
5185 | target_evals++; | |
5186 | else | |
5187 | host_evals++; | |
5188 | } | |
5189 | ||
5190 | if (host_evals && target_evals) | |
5191 | return condition_evaluation_both; | |
5192 | else if (target_evals) | |
5193 | return condition_evaluation_target; | |
5194 | else | |
5195 | return condition_evaluation_host; | |
5196 | } | |
5197 | ||
5198 | /* Determine the breakpoint location's condition evaluator. This is | |
5199 | similar to bp_condition_evaluator, but for locations. */ | |
5200 | ||
5201 | static const char * | |
5202 | bp_location_condition_evaluator (struct bp_location *bl) | |
5203 | { | |
5204 | if (bl && !is_breakpoint (bl->owner)) | |
5205 | return NULL; | |
5206 | ||
5207 | if (gdb_evaluates_breakpoint_condition_p () | |
5208 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5209 | return condition_evaluation_host; | |
5210 | ||
5211 | if (bl && bl->cond_bytecode) | |
5212 | return condition_evaluation_target; | |
5213 | else | |
5214 | return condition_evaluation_host; | |
5215 | } | |
5216 | ||
859825b8 JK |
5217 | /* Print the LOC location out of the list of B->LOC locations. */ |
5218 | ||
170b53b2 UW |
5219 | static void |
5220 | print_breakpoint_location (struct breakpoint *b, | |
5221 | struct bp_location *loc) | |
0d381245 | 5222 | { |
79a45e25 | 5223 | struct ui_out *uiout = current_uiout; |
6c95b8df PA |
5224 | struct cleanup *old_chain = save_current_program_space (); |
5225 | ||
859825b8 JK |
5226 | if (loc != NULL && loc->shlib_disabled) |
5227 | loc = NULL; | |
5228 | ||
6c95b8df PA |
5229 | if (loc != NULL) |
5230 | set_current_program_space (loc->pspace); | |
5231 | ||
56435ebe TT |
5232 | if (b->display_canonical) |
5233 | ui_out_field_string (uiout, "what", b->addr_string); | |
f8eba3c6 | 5234 | else if (loc && loc->source_file) |
0d381245 VP |
5235 | { |
5236 | struct symbol *sym | |
5237 | = find_pc_sect_function (loc->address, loc->section); | |
5238 | if (sym) | |
5239 | { | |
5240 | ui_out_text (uiout, "in "); | |
5241 | ui_out_field_string (uiout, "func", | |
5242 | SYMBOL_PRINT_NAME (sym)); | |
170b53b2 UW |
5243 | ui_out_text (uiout, " "); |
5244 | ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what")); | |
5245 | ui_out_text (uiout, "at "); | |
0d381245 | 5246 | } |
f8eba3c6 | 5247 | ui_out_field_string (uiout, "file", loc->source_file); |
0d381245 VP |
5248 | ui_out_text (uiout, ":"); |
5249 | ||
5250 | if (ui_out_is_mi_like_p (uiout)) | |
5251 | { | |
5252 | struct symtab_and_line sal = find_pc_line (loc->address, 0); | |
5253 | char *fullname = symtab_to_fullname (sal.symtab); | |
5254 | ||
5255 | if (fullname) | |
5256 | ui_out_field_string (uiout, "fullname", fullname); | |
5257 | } | |
5258 | ||
f8eba3c6 | 5259 | ui_out_field_int (uiout, "line", loc->line_number); |
0d381245 | 5260 | } |
859825b8 | 5261 | else if (loc) |
0d381245 | 5262 | { |
170b53b2 UW |
5263 | struct ui_stream *stb = ui_out_stream_new (uiout); |
5264 | struct cleanup *stb_chain = make_cleanup_ui_out_stream_delete (stb); | |
5265 | ||
22e722e1 DJ |
5266 | print_address_symbolic (loc->gdbarch, loc->address, stb->stream, |
5267 | demangle, ""); | |
0d381245 | 5268 | ui_out_field_stream (uiout, "at", stb); |
170b53b2 UW |
5269 | |
5270 | do_cleanups (stb_chain); | |
0d381245 | 5271 | } |
859825b8 JK |
5272 | else |
5273 | ui_out_field_string (uiout, "pending", b->addr_string); | |
6c95b8df | 5274 | |
b775012e LM |
5275 | if (loc && is_breakpoint (b) |
5276 | && breakpoint_condition_evaluation_mode () == condition_evaluation_target | |
5277 | && bp_condition_evaluator (b) == condition_evaluation_both) | |
5278 | { | |
5279 | ui_out_text (uiout, " ("); | |
5280 | ui_out_field_string (uiout, "evaluated-by", | |
5281 | bp_location_condition_evaluator (loc)); | |
5282 | ui_out_text (uiout, ")"); | |
5283 | } | |
5284 | ||
6c95b8df | 5285 | do_cleanups (old_chain); |
0d381245 VP |
5286 | } |
5287 | ||
269b11a2 PA |
5288 | static const char * |
5289 | bptype_string (enum bptype type) | |
c906108c | 5290 | { |
c4093a6a JM |
5291 | struct ep_type_description |
5292 | { | |
5293 | enum bptype type; | |
5294 | char *description; | |
5295 | }; | |
5296 | static struct ep_type_description bptypes[] = | |
c906108c | 5297 | { |
c5aa993b JM |
5298 | {bp_none, "?deleted?"}, |
5299 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 5300 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
5301 | {bp_until, "until"}, |
5302 | {bp_finish, "finish"}, | |
5303 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 5304 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
5305 | {bp_read_watchpoint, "read watchpoint"}, |
5306 | {bp_access_watchpoint, "acc watchpoint"}, | |
5307 | {bp_longjmp, "longjmp"}, | |
5308 | {bp_longjmp_resume, "longjmp resume"}, | |
186c406b TT |
5309 | {bp_exception, "exception"}, |
5310 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 5311 | {bp_step_resume, "step resume"}, |
2c03e5be | 5312 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
5313 | {bp_watchpoint_scope, "watchpoint scope"}, |
5314 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 5315 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 5316 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 5317 | {bp_thread_event, "thread events"}, |
1900040c | 5318 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 5319 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 5320 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 5321 | {bp_exception_master, "exception master"}, |
ce78b96d | 5322 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 5323 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 5324 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 5325 | {bp_static_tracepoint, "static tracepoint"}, |
4efc6507 | 5326 | {bp_jit_event, "jit events"}, |
0e30163f JK |
5327 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
5328 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 5329 | }; |
269b11a2 PA |
5330 | |
5331 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
5332 | || ((int) type != bptypes[(int) type].type)) | |
5333 | internal_error (__FILE__, __LINE__, | |
5334 | _("bptypes table does not describe type #%d."), | |
5335 | (int) type); | |
5336 | ||
5337 | return bptypes[(int) type].description; | |
5338 | } | |
5339 | ||
5340 | /* Print B to gdb_stdout. */ | |
5341 | ||
5342 | static void | |
5343 | print_one_breakpoint_location (struct breakpoint *b, | |
5344 | struct bp_location *loc, | |
5345 | int loc_number, | |
5346 | struct bp_location **last_loc, | |
269b11a2 PA |
5347 | int allflag) |
5348 | { | |
5349 | struct command_line *l; | |
c2c6d25f | 5350 | static char bpenables[] = "nynny"; |
c906108c | 5351 | |
79a45e25 | 5352 | struct ui_out *uiout = current_uiout; |
0d381245 VP |
5353 | int header_of_multiple = 0; |
5354 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
5355 | struct value_print_options opts; |
5356 | ||
5357 | get_user_print_options (&opts); | |
0d381245 VP |
5358 | |
5359 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
5360 | /* See comment in print_one_breakpoint concerning treatment of |
5361 | breakpoints with single disabled location. */ | |
0d381245 VP |
5362 | if (loc == NULL |
5363 | && (b->loc != NULL | |
5364 | && (b->loc->next != NULL || !b->loc->enabled))) | |
5365 | header_of_multiple = 1; | |
5366 | if (loc == NULL) | |
5367 | loc = b->loc; | |
5368 | ||
c4093a6a JM |
5369 | annotate_record (); |
5370 | ||
5371 | /* 1 */ | |
5372 | annotate_field (0); | |
0d381245 VP |
5373 | if (part_of_multiple) |
5374 | { | |
5375 | char *formatted; | |
0c6773c1 | 5376 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
5377 | ui_out_field_string (uiout, "number", formatted); |
5378 | xfree (formatted); | |
5379 | } | |
5380 | else | |
5381 | { | |
5382 | ui_out_field_int (uiout, "number", b->number); | |
5383 | } | |
c4093a6a JM |
5384 | |
5385 | /* 2 */ | |
5386 | annotate_field (1); | |
0d381245 VP |
5387 | if (part_of_multiple) |
5388 | ui_out_field_skip (uiout, "type"); | |
269b11a2 PA |
5389 | else |
5390 | ui_out_field_string (uiout, "type", bptype_string (b->type)); | |
c4093a6a JM |
5391 | |
5392 | /* 3 */ | |
5393 | annotate_field (2); | |
0d381245 VP |
5394 | if (part_of_multiple) |
5395 | ui_out_field_skip (uiout, "disp"); | |
5396 | else | |
2cec12e5 | 5397 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 5398 | |
c4093a6a JM |
5399 | |
5400 | /* 4 */ | |
5401 | annotate_field (3); | |
0d381245 | 5402 | if (part_of_multiple) |
54e52265 | 5403 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 5404 | else |
4a64f543 MS |
5405 | ui_out_field_fmt (uiout, "enabled", "%c", |
5406 | bpenables[(int) b->enable_state]); | |
54e52265 | 5407 | ui_out_spaces (uiout, 2); |
0d381245 | 5408 | |
c4093a6a JM |
5409 | |
5410 | /* 5 and 6 */ | |
3086aeae | 5411 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 5412 | { |
4a64f543 MS |
5413 | /* Although the print_one can possibly print all locations, |
5414 | calling it here is not likely to get any nice result. So, | |
5415 | make sure there's just one location. */ | |
0d381245 | 5416 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 5417 | b->ops->print_one (b, last_loc); |
0d381245 | 5418 | } |
3086aeae DJ |
5419 | else |
5420 | switch (b->type) | |
5421 | { | |
5422 | case bp_none: | |
5423 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 5424 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 5425 | break; |
c906108c | 5426 | |
3086aeae DJ |
5427 | case bp_watchpoint: |
5428 | case bp_hardware_watchpoint: | |
5429 | case bp_read_watchpoint: | |
5430 | case bp_access_watchpoint: | |
3a5c3e22 PA |
5431 | { |
5432 | struct watchpoint *w = (struct watchpoint *) b; | |
5433 | ||
5434 | /* Field 4, the address, is omitted (which makes the columns | |
5435 | not line up too nicely with the headers, but the effect | |
5436 | is relatively readable). */ | |
5437 | if (opts.addressprint) | |
5438 | ui_out_field_skip (uiout, "addr"); | |
5439 | annotate_field (5); | |
5440 | ui_out_field_string (uiout, "what", w->exp_string); | |
5441 | } | |
3086aeae DJ |
5442 | break; |
5443 | ||
3086aeae DJ |
5444 | case bp_breakpoint: |
5445 | case bp_hardware_breakpoint: | |
5446 | case bp_until: | |
5447 | case bp_finish: | |
5448 | case bp_longjmp: | |
5449 | case bp_longjmp_resume: | |
186c406b TT |
5450 | case bp_exception: |
5451 | case bp_exception_resume: | |
3086aeae | 5452 | case bp_step_resume: |
2c03e5be | 5453 | case bp_hp_step_resume: |
3086aeae DJ |
5454 | case bp_watchpoint_scope: |
5455 | case bp_call_dummy: | |
aa7d318d | 5456 | case bp_std_terminate: |
3086aeae DJ |
5457 | case bp_shlib_event: |
5458 | case bp_thread_event: | |
5459 | case bp_overlay_event: | |
0fd8e87f | 5460 | case bp_longjmp_master: |
aa7d318d | 5461 | case bp_std_terminate_master: |
186c406b | 5462 | case bp_exception_master: |
1042e4c0 | 5463 | case bp_tracepoint: |
7a697b8d | 5464 | case bp_fast_tracepoint: |
0fb4aa4b | 5465 | case bp_static_tracepoint: |
4efc6507 | 5466 | case bp_jit_event: |
0e30163f JK |
5467 | case bp_gnu_ifunc_resolver: |
5468 | case bp_gnu_ifunc_resolver_return: | |
79a45b7d | 5469 | if (opts.addressprint) |
3086aeae DJ |
5470 | { |
5471 | annotate_field (4); | |
54e52265 | 5472 | if (header_of_multiple) |
0d381245 | 5473 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 5474 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 5475 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 5476 | else |
5af949e3 UW |
5477 | ui_out_field_core_addr (uiout, "addr", |
5478 | loc->gdbarch, loc->address); | |
3086aeae DJ |
5479 | } |
5480 | annotate_field (5); | |
0d381245 | 5481 | if (!header_of_multiple) |
170b53b2 | 5482 | print_breakpoint_location (b, loc); |
0d381245 | 5483 | if (b->loc) |
a6d9a66e | 5484 | *last_loc = b->loc; |
3086aeae DJ |
5485 | break; |
5486 | } | |
c906108c | 5487 | |
6c95b8df PA |
5488 | |
5489 | /* For backward compatibility, don't display inferiors unless there | |
5490 | are several. */ | |
5491 | if (loc != NULL | |
5492 | && !header_of_multiple | |
5493 | && (allflag | |
5494 | || (!gdbarch_has_global_breakpoints (target_gdbarch) | |
5495 | && (number_of_program_spaces () > 1 | |
5496 | || number_of_inferiors () > 1) | |
4a64f543 MS |
5497 | /* LOC is for existing B, it cannot be in |
5498 | moribund_locations and thus having NULL OWNER. */ | |
6c95b8df PA |
5499 | && loc->owner->type != bp_catchpoint))) |
5500 | { | |
5501 | struct inferior *inf; | |
5502 | int first = 1; | |
5503 | ||
5504 | for (inf = inferior_list; inf != NULL; inf = inf->next) | |
5505 | { | |
5506 | if (inf->pspace == loc->pspace) | |
5507 | { | |
5508 | if (first) | |
5509 | { | |
5510 | first = 0; | |
5511 | ui_out_text (uiout, " inf "); | |
5512 | } | |
5513 | else | |
5514 | ui_out_text (uiout, ", "); | |
5515 | ui_out_text (uiout, plongest (inf->num)); | |
5516 | } | |
5517 | } | |
5518 | } | |
5519 | ||
4a306c9a | 5520 | if (!part_of_multiple) |
c4093a6a | 5521 | { |
4a306c9a JB |
5522 | if (b->thread != -1) |
5523 | { | |
5524 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 5525 | "stop only in" line a little further down. */ |
4a306c9a JB |
5526 | ui_out_text (uiout, " thread "); |
5527 | ui_out_field_int (uiout, "thread", b->thread); | |
5528 | } | |
5529 | else if (b->task != 0) | |
5530 | { | |
5531 | ui_out_text (uiout, " task "); | |
5532 | ui_out_field_int (uiout, "task", b->task); | |
5533 | } | |
c4093a6a | 5534 | } |
f1310107 | 5535 | |
8b93c638 | 5536 | ui_out_text (uiout, "\n"); |
f1310107 | 5537 | |
348d480f | 5538 | if (!part_of_multiple) |
f1310107 TJB |
5539 | b->ops->print_one_detail (b, uiout); |
5540 | ||
0d381245 | 5541 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
5542 | { |
5543 | annotate_field (6); | |
8b93c638 | 5544 | ui_out_text (uiout, "\tstop only in stack frame at "); |
e5dd4106 | 5545 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
818dd999 | 5546 | the frame ID. */ |
5af949e3 UW |
5547 | ui_out_field_core_addr (uiout, "frame", |
5548 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 5549 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
5550 | } |
5551 | ||
28010a5d | 5552 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
5553 | { |
5554 | annotate_field (7); | |
d77f58be | 5555 | if (is_tracepoint (b)) |
1042e4c0 SS |
5556 | ui_out_text (uiout, "\ttrace only if "); |
5557 | else | |
5558 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 | 5559 | ui_out_field_string (uiout, "cond", b->cond_string); |
b775012e LM |
5560 | |
5561 | /* Print whether the target is doing the breakpoint's condition | |
5562 | evaluation. If GDB is doing the evaluation, don't print anything. */ | |
5563 | if (is_breakpoint (b) | |
5564 | && breakpoint_condition_evaluation_mode () | |
5565 | == condition_evaluation_target) | |
5566 | { | |
5567 | ui_out_text (uiout, " ("); | |
5568 | ui_out_field_string (uiout, "evaluated-by", | |
5569 | bp_condition_evaluator (b)); | |
5570 | ui_out_text (uiout, " evals)"); | |
5571 | } | |
0101ce28 JJ |
5572 | ui_out_text (uiout, "\n"); |
5573 | } | |
5574 | ||
0d381245 | 5575 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 5576 | { |
4a64f543 | 5577 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
5578 | ui_out_text (uiout, "\tstop only in thread "); |
5579 | ui_out_field_int (uiout, "thread", b->thread); | |
5580 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
5581 | } |
5582 | ||
63c715c6 | 5583 | if (!part_of_multiple && b->hit_count) |
c4093a6a | 5584 | { |
4a64f543 | 5585 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
5586 | if (ep_is_catchpoint (b)) |
5587 | ui_out_text (uiout, "\tcatchpoint"); | |
f196051f SS |
5588 | else if (is_tracepoint (b)) |
5589 | ui_out_text (uiout, "\ttracepoint"); | |
8b93c638 JM |
5590 | else |
5591 | ui_out_text (uiout, "\tbreakpoint"); | |
5592 | ui_out_text (uiout, " already hit "); | |
5593 | ui_out_field_int (uiout, "times", b->hit_count); | |
5594 | if (b->hit_count == 1) | |
5595 | ui_out_text (uiout, " time\n"); | |
5596 | else | |
5597 | ui_out_text (uiout, " times\n"); | |
c4093a6a JM |
5598 | } |
5599 | ||
4a64f543 MS |
5600 | /* Output the count also if it is zero, but only if this is mi. |
5601 | FIXME: Should have a better test for this. */ | |
9dc5e2a9 | 5602 | if (ui_out_is_mi_like_p (uiout)) |
63c715c6 | 5603 | if (!part_of_multiple && b->hit_count == 0) |
fb40c209 | 5604 | ui_out_field_int (uiout, "times", b->hit_count); |
8b93c638 | 5605 | |
0d381245 | 5606 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
5607 | { |
5608 | annotate_field (8); | |
8b93c638 JM |
5609 | ui_out_text (uiout, "\tignore next "); |
5610 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
5611 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 5612 | } |
059fb39f | 5613 | |
816338b5 SS |
5614 | /* Note that an enable count of 1 corresponds to "enable once" |
5615 | behavior, which is reported by the combination of enablement and | |
5616 | disposition, so we don't need to mention it here. */ | |
5617 | if (!part_of_multiple && b->enable_count > 1) | |
5618 | { | |
5619 | annotate_field (8); | |
5620 | ui_out_text (uiout, "\tdisable after "); | |
5621 | /* Tweak the wording to clarify that ignore and enable counts | |
5622 | are distinct, and have additive effect. */ | |
5623 | if (b->ignore_count) | |
5624 | ui_out_text (uiout, "additional "); | |
5625 | else | |
5626 | ui_out_text (uiout, "next "); | |
5627 | ui_out_field_int (uiout, "enable", b->enable_count); | |
5628 | ui_out_text (uiout, " hits\n"); | |
5629 | } | |
5630 | ||
f196051f SS |
5631 | if (!part_of_multiple && is_tracepoint (b)) |
5632 | { | |
5633 | struct tracepoint *tp = (struct tracepoint *) b; | |
5634 | ||
5635 | if (tp->traceframe_usage) | |
5636 | { | |
5637 | ui_out_text (uiout, "\ttrace buffer usage "); | |
5638 | ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage); | |
5639 | ui_out_text (uiout, " bytes\n"); | |
5640 | } | |
5641 | } | |
5642 | ||
9add0f1b | 5643 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 5644 | if (!part_of_multiple && l) |
c4093a6a | 5645 | { |
3b31d625 EZ |
5646 | struct cleanup *script_chain; |
5647 | ||
c4093a6a | 5648 | annotate_field (9); |
3b31d625 | 5649 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 5650 | print_command_lines (uiout, l, 4); |
3b31d625 | 5651 | do_cleanups (script_chain); |
c4093a6a | 5652 | } |
d24317b4 | 5653 | |
d9b3f62e | 5654 | if (is_tracepoint (b)) |
1042e4c0 | 5655 | { |
d9b3f62e PA |
5656 | struct tracepoint *t = (struct tracepoint *) b; |
5657 | ||
5658 | if (!part_of_multiple && t->pass_count) | |
5659 | { | |
5660 | annotate_field (10); | |
5661 | ui_out_text (uiout, "\tpass count "); | |
5662 | ui_out_field_int (uiout, "pass", t->pass_count); | |
5663 | ui_out_text (uiout, " \n"); | |
5664 | } | |
1042e4c0 SS |
5665 | } |
5666 | ||
d24317b4 VP |
5667 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
5668 | { | |
3a5c3e22 PA |
5669 | if (is_watchpoint (b)) |
5670 | { | |
5671 | struct watchpoint *w = (struct watchpoint *) b; | |
5672 | ||
5673 | ui_out_field_string (uiout, "original-location", w->exp_string); | |
5674 | } | |
5675 | else if (b->addr_string) | |
d24317b4 | 5676 | ui_out_field_string (uiout, "original-location", b->addr_string); |
d24317b4 | 5677 | } |
c4093a6a | 5678 | } |
c5aa993b | 5679 | |
0d381245 VP |
5680 | static void |
5681 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 5682 | struct bp_location **last_loc, |
6c95b8df | 5683 | int allflag) |
0d381245 | 5684 | { |
8d3788bd | 5685 | struct cleanup *bkpt_chain; |
79a45e25 | 5686 | struct ui_out *uiout = current_uiout; |
8d3788bd VP |
5687 | |
5688 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); | |
5689 | ||
12c5a436 | 5690 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); |
8d3788bd | 5691 | do_cleanups (bkpt_chain); |
0d381245 VP |
5692 | |
5693 | /* If this breakpoint has custom print function, | |
5694 | it's already printed. Otherwise, print individual | |
5695 | locations, if any. */ | |
5696 | if (b->ops == NULL || b->ops->print_one == NULL) | |
5697 | { | |
4a64f543 MS |
5698 | /* If breakpoint has a single location that is disabled, we |
5699 | print it as if it had several locations, since otherwise it's | |
5700 | hard to represent "breakpoint enabled, location disabled" | |
5701 | situation. | |
5702 | ||
5703 | Note that while hardware watchpoints have several locations | |
a3be7890 | 5704 | internally, that's not a property exposed to user. */ |
0d381245 | 5705 | if (b->loc |
a5606eee | 5706 | && !is_hardware_watchpoint (b) |
8d3788bd | 5707 | && (b->loc->next || !b->loc->enabled)) |
0d381245 VP |
5708 | { |
5709 | struct bp_location *loc; | |
5710 | int n = 1; | |
8d3788bd | 5711 | |
0d381245 | 5712 | for (loc = b->loc; loc; loc = loc->next, ++n) |
8d3788bd VP |
5713 | { |
5714 | struct cleanup *inner2 = | |
5715 | make_cleanup_ui_out_tuple_begin_end (uiout, NULL); | |
5716 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); | |
5717 | do_cleanups (inner2); | |
5718 | } | |
0d381245 VP |
5719 | } |
5720 | } | |
5721 | } | |
5722 | ||
a6d9a66e UW |
5723 | static int |
5724 | breakpoint_address_bits (struct breakpoint *b) | |
5725 | { | |
5726 | int print_address_bits = 0; | |
5727 | struct bp_location *loc; | |
5728 | ||
5729 | for (loc = b->loc; loc; loc = loc->next) | |
5730 | { | |
c7437ca6 PA |
5731 | int addr_bit; |
5732 | ||
5733 | /* Software watchpoints that aren't watching memory don't have | |
5734 | an address to print. */ | |
5735 | if (b->type == bp_watchpoint && loc->watchpoint_type == -1) | |
5736 | continue; | |
5737 | ||
5738 | addr_bit = gdbarch_addr_bit (loc->gdbarch); | |
a6d9a66e UW |
5739 | if (addr_bit > print_address_bits) |
5740 | print_address_bits = addr_bit; | |
5741 | } | |
5742 | ||
5743 | return print_address_bits; | |
5744 | } | |
0d381245 | 5745 | |
c4093a6a JM |
5746 | struct captured_breakpoint_query_args |
5747 | { | |
5748 | int bnum; | |
5749 | }; | |
c5aa993b | 5750 | |
c4093a6a | 5751 | static int |
2b65245e | 5752 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
5753 | { |
5754 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 5755 | struct breakpoint *b; |
a6d9a66e | 5756 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 5757 | |
c4093a6a JM |
5758 | ALL_BREAKPOINTS (b) |
5759 | { | |
5760 | if (args->bnum == b->number) | |
c5aa993b | 5761 | { |
12c5a436 | 5762 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 5763 | return GDB_RC_OK; |
c5aa993b | 5764 | } |
c4093a6a JM |
5765 | } |
5766 | return GDB_RC_NONE; | |
5767 | } | |
c5aa993b | 5768 | |
c4093a6a | 5769 | enum gdb_rc |
4a64f543 MS |
5770 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, |
5771 | char **error_message) | |
c4093a6a JM |
5772 | { |
5773 | struct captured_breakpoint_query_args args; | |
cc59ec59 | 5774 | |
c4093a6a JM |
5775 | args.bnum = bnum; |
5776 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4a64f543 | 5777 | an error. */ |
b0b13bb4 DJ |
5778 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
5779 | error_message, RETURN_MASK_ALL) < 0) | |
5780 | return GDB_RC_FAIL; | |
5781 | else | |
5782 | return GDB_RC_OK; | |
c4093a6a | 5783 | } |
c5aa993b | 5784 | |
09d682a4 TT |
5785 | /* Return true if this breakpoint was set by the user, false if it is |
5786 | internal or momentary. */ | |
5787 | ||
5788 | int | |
5789 | user_breakpoint_p (struct breakpoint *b) | |
5790 | { | |
46c6471b | 5791 | return b->number > 0; |
09d682a4 TT |
5792 | } |
5793 | ||
7f3b0473 | 5794 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
5795 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
5796 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
5797 | FILTER is non-NULL, call it on each breakpoint and only include the | |
5798 | ones for which it returns non-zero. Return the total number of | |
5799 | breakpoints listed. */ | |
c906108c | 5800 | |
d77f58be | 5801 | static int |
e5a67952 | 5802 | breakpoint_1 (char *args, int allflag, |
4a64f543 | 5803 | int (*filter) (const struct breakpoint *)) |
c4093a6a | 5804 | { |
52f0bd74 | 5805 | struct breakpoint *b; |
a6d9a66e | 5806 | struct bp_location *last_loc = NULL; |
7f3b0473 | 5807 | int nr_printable_breakpoints; |
3b31d625 | 5808 | struct cleanup *bkpttbl_chain; |
79a45b7d | 5809 | struct value_print_options opts; |
a6d9a66e | 5810 | int print_address_bits = 0; |
269b11a2 | 5811 | int print_type_col_width = 14; |
79a45e25 | 5812 | struct ui_out *uiout = current_uiout; |
269b11a2 | 5813 | |
79a45b7d TT |
5814 | get_user_print_options (&opts); |
5815 | ||
4a64f543 MS |
5816 | /* Compute the number of rows in the table, as well as the size |
5817 | required for address fields. */ | |
7f3b0473 AC |
5818 | nr_printable_breakpoints = 0; |
5819 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
5820 | { |
5821 | /* If we have a filter, only list the breakpoints it accepts. */ | |
5822 | if (filter && !filter (b)) | |
5823 | continue; | |
5824 | ||
5825 | /* If we have an "args" string, it is a list of breakpoints to | |
5826 | accept. Skip the others. */ | |
5827 | if (args != NULL && *args != '\0') | |
5828 | { | |
5829 | if (allflag && parse_and_eval_long (args) != b->number) | |
5830 | continue; | |
5831 | if (!allflag && !number_is_in_list (args, b->number)) | |
5832 | continue; | |
5833 | } | |
269b11a2 | 5834 | |
e5a67952 MS |
5835 | if (allflag || user_breakpoint_p (b)) |
5836 | { | |
5837 | int addr_bit, type_len; | |
a6d9a66e | 5838 | |
e5a67952 MS |
5839 | addr_bit = breakpoint_address_bits (b); |
5840 | if (addr_bit > print_address_bits) | |
5841 | print_address_bits = addr_bit; | |
269b11a2 | 5842 | |
e5a67952 MS |
5843 | type_len = strlen (bptype_string (b->type)); |
5844 | if (type_len > print_type_col_width) | |
5845 | print_type_col_width = type_len; | |
5846 | ||
5847 | nr_printable_breakpoints++; | |
5848 | } | |
5849 | } | |
7f3b0473 | 5850 | |
79a45b7d | 5851 | if (opts.addressprint) |
3b31d625 | 5852 | bkpttbl_chain |
3e43a32a MS |
5853 | = make_cleanup_ui_out_table_begin_end (uiout, 6, |
5854 | nr_printable_breakpoints, | |
3b31d625 | 5855 | "BreakpointTable"); |
8b93c638 | 5856 | else |
3b31d625 | 5857 | bkpttbl_chain |
3e43a32a MS |
5858 | = make_cleanup_ui_out_table_begin_end (uiout, 5, |
5859 | nr_printable_breakpoints, | |
3b31d625 | 5860 | "BreakpointTable"); |
8b93c638 | 5861 | |
7f3b0473 | 5862 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
5863 | annotate_breakpoints_headers (); |
5864 | if (nr_printable_breakpoints > 0) | |
5865 | annotate_field (0); | |
4a64f543 | 5866 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
5867 | if (nr_printable_breakpoints > 0) |
5868 | annotate_field (1); | |
269b11a2 | 5869 | ui_out_table_header (uiout, print_type_col_width, ui_left, |
4a64f543 | 5870 | "type", "Type"); /* 2 */ |
d7faa9e7 AC |
5871 | if (nr_printable_breakpoints > 0) |
5872 | annotate_field (2); | |
4a64f543 | 5873 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ |
d7faa9e7 AC |
5874 | if (nr_printable_breakpoints > 0) |
5875 | annotate_field (3); | |
54e52265 | 5876 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 5877 | if (opts.addressprint) |
e5a67952 MS |
5878 | { |
5879 | if (nr_printable_breakpoints > 0) | |
5880 | annotate_field (4); | |
5881 | if (print_address_bits <= 32) | |
5882 | ui_out_table_header (uiout, 10, ui_left, | |
5883 | "addr", "Address"); /* 5 */ | |
5884 | else | |
5885 | ui_out_table_header (uiout, 18, ui_left, | |
5886 | "addr", "Address"); /* 5 */ | |
5887 | } | |
d7faa9e7 AC |
5888 | if (nr_printable_breakpoints > 0) |
5889 | annotate_field (5); | |
5890 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
5891 | ui_out_table_body (uiout); | |
5892 | if (nr_printable_breakpoints > 0) | |
5893 | annotate_breakpoints_table (); | |
7f3b0473 | 5894 | |
c4093a6a | 5895 | ALL_BREAKPOINTS (b) |
e5a67952 MS |
5896 | { |
5897 | QUIT; | |
5898 | /* If we have a filter, only list the breakpoints it accepts. */ | |
5899 | if (filter && !filter (b)) | |
5900 | continue; | |
5901 | ||
5902 | /* If we have an "args" string, it is a list of breakpoints to | |
5903 | accept. Skip the others. */ | |
5904 | ||
5905 | if (args != NULL && *args != '\0') | |
5906 | { | |
5907 | if (allflag) /* maintenance info breakpoint */ | |
5908 | { | |
5909 | if (parse_and_eval_long (args) != b->number) | |
5910 | continue; | |
5911 | } | |
5912 | else /* all others */ | |
5913 | { | |
5914 | if (!number_is_in_list (args, b->number)) | |
5915 | continue; | |
5916 | } | |
5917 | } | |
5918 | /* We only print out user settable breakpoints unless the | |
5919 | allflag is set. */ | |
5920 | if (allflag || user_breakpoint_p (b)) | |
12c5a436 | 5921 | print_one_breakpoint (b, &last_loc, allflag); |
e5a67952 MS |
5922 | } |
5923 | ||
3b31d625 | 5924 | do_cleanups (bkpttbl_chain); |
698384cd | 5925 | |
7f3b0473 | 5926 | if (nr_printable_breakpoints == 0) |
c906108c | 5927 | { |
4a64f543 MS |
5928 | /* If there's a filter, let the caller decide how to report |
5929 | empty list. */ | |
d77f58be SS |
5930 | if (!filter) |
5931 | { | |
e5a67952 | 5932 | if (args == NULL || *args == '\0') |
d77f58be SS |
5933 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); |
5934 | else | |
4a64f543 | 5935 | ui_out_message (uiout, 0, |
e5a67952 MS |
5936 | "No breakpoint or watchpoint matching '%s'.\n", |
5937 | args); | |
d77f58be | 5938 | } |
c906108c SS |
5939 | } |
5940 | else | |
c4093a6a | 5941 | { |
a6d9a66e UW |
5942 | if (last_loc && !server_command) |
5943 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 5944 | } |
c906108c | 5945 | |
4a64f543 | 5946 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 5947 | there have been breakpoints? */ |
c906108c | 5948 | annotate_breakpoints_table_end (); |
d77f58be SS |
5949 | |
5950 | return nr_printable_breakpoints; | |
c906108c SS |
5951 | } |
5952 | ||
ad443146 SS |
5953 | /* Display the value of default-collect in a way that is generally |
5954 | compatible with the breakpoint list. */ | |
5955 | ||
5956 | static void | |
5957 | default_collect_info (void) | |
5958 | { | |
79a45e25 PA |
5959 | struct ui_out *uiout = current_uiout; |
5960 | ||
ad443146 SS |
5961 | /* If it has no value (which is frequently the case), say nothing; a |
5962 | message like "No default-collect." gets in user's face when it's | |
5963 | not wanted. */ | |
5964 | if (!*default_collect) | |
5965 | return; | |
5966 | ||
5967 | /* The following phrase lines up nicely with per-tracepoint collect | |
5968 | actions. */ | |
5969 | ui_out_text (uiout, "default collect "); | |
5970 | ui_out_field_string (uiout, "default-collect", default_collect); | |
5971 | ui_out_text (uiout, " \n"); | |
5972 | } | |
5973 | ||
c906108c | 5974 | static void |
e5a67952 | 5975 | breakpoints_info (char *args, int from_tty) |
c906108c | 5976 | { |
e5a67952 | 5977 | breakpoint_1 (args, 0, NULL); |
ad443146 SS |
5978 | |
5979 | default_collect_info (); | |
d77f58be SS |
5980 | } |
5981 | ||
5982 | static void | |
e5a67952 | 5983 | watchpoints_info (char *args, int from_tty) |
d77f58be | 5984 | { |
e5a67952 | 5985 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
79a45e25 | 5986 | struct ui_out *uiout = current_uiout; |
d77f58be SS |
5987 | |
5988 | if (num_printed == 0) | |
5989 | { | |
e5a67952 | 5990 | if (args == NULL || *args == '\0') |
d77f58be SS |
5991 | ui_out_message (uiout, 0, "No watchpoints.\n"); |
5992 | else | |
e5a67952 | 5993 | ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args); |
d77f58be | 5994 | } |
c906108c SS |
5995 | } |
5996 | ||
7a292a7a | 5997 | static void |
e5a67952 | 5998 | maintenance_info_breakpoints (char *args, int from_tty) |
c906108c | 5999 | { |
e5a67952 | 6000 | breakpoint_1 (args, 1, NULL); |
ad443146 SS |
6001 | |
6002 | default_collect_info (); | |
c906108c SS |
6003 | } |
6004 | ||
0d381245 | 6005 | static int |
714835d5 | 6006 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 6007 | struct program_space *pspace, |
714835d5 | 6008 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
6009 | { |
6010 | struct bp_location *bl = b->loc; | |
cc59ec59 | 6011 | |
0d381245 VP |
6012 | for (; bl; bl = bl->next) |
6013 | { | |
6c95b8df PA |
6014 | if (bl->pspace == pspace |
6015 | && bl->address == pc | |
0d381245 VP |
6016 | && (!overlay_debugging || bl->section == section)) |
6017 | return 1; | |
6018 | } | |
6019 | return 0; | |
6020 | } | |
6021 | ||
672f9b60 | 6022 | /* Print a message describing any user-breakpoints set at PC. This |
6c95b8df PA |
6023 | concerns with logical breakpoints, so we match program spaces, not |
6024 | address spaces. */ | |
c906108c SS |
6025 | |
6026 | static void | |
6c95b8df PA |
6027 | describe_other_breakpoints (struct gdbarch *gdbarch, |
6028 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 6029 | struct obj_section *section, int thread) |
c906108c | 6030 | { |
52f0bd74 AC |
6031 | int others = 0; |
6032 | struct breakpoint *b; | |
c906108c SS |
6033 | |
6034 | ALL_BREAKPOINTS (b) | |
672f9b60 KP |
6035 | others += (user_breakpoint_p (b) |
6036 | && breakpoint_has_pc (b, pspace, pc, section)); | |
c906108c SS |
6037 | if (others > 0) |
6038 | { | |
a3f17187 AC |
6039 | if (others == 1) |
6040 | printf_filtered (_("Note: breakpoint ")); | |
6041 | else /* if (others == ???) */ | |
6042 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 6043 | ALL_BREAKPOINTS (b) |
672f9b60 | 6044 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
6045 | { |
6046 | others--; | |
6047 | printf_filtered ("%d", b->number); | |
6048 | if (b->thread == -1 && thread != -1) | |
6049 | printf_filtered (" (all threads)"); | |
6050 | else if (b->thread != -1) | |
6051 | printf_filtered (" (thread %d)", b->thread); | |
6052 | printf_filtered ("%s%s ", | |
059fb39f | 6053 | ((b->enable_state == bp_disabled |
f8eba3c6 | 6054 | || b->enable_state == bp_call_disabled) |
0d381245 VP |
6055 | ? " (disabled)" |
6056 | : b->enable_state == bp_permanent | |
6057 | ? " (permanent)" | |
6058 | : ""), | |
6059 | (others > 1) ? "," | |
6060 | : ((others == 1) ? " and" : "")); | |
6061 | } | |
a3f17187 | 6062 | printf_filtered (_("also set at pc ")); |
5af949e3 | 6063 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
6064 | printf_filtered (".\n"); |
6065 | } | |
6066 | } | |
6067 | \f | |
c906108c | 6068 | |
e4f237da KB |
6069 | /* Return true iff it is meaningful to use the address member of |
6070 | BPT. For some breakpoint types, the address member is irrelevant | |
6071 | and it makes no sense to attempt to compare it to other addresses | |
6072 | (or use it for any other purpose either). | |
6073 | ||
4a64f543 MS |
6074 | More specifically, each of the following breakpoint types will |
6075 | always have a zero valued address and we don't want to mark | |
6076 | breakpoints of any of these types to be a duplicate of an actual | |
6077 | breakpoint at address zero: | |
e4f237da KB |
6078 | |
6079 | bp_watchpoint | |
2d134ed3 PA |
6080 | bp_catchpoint |
6081 | ||
6082 | */ | |
e4f237da KB |
6083 | |
6084 | static int | |
6085 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
6086 | { | |
6087 | enum bptype type = bpt->type; | |
6088 | ||
2d134ed3 PA |
6089 | return (type != bp_watchpoint && type != bp_catchpoint); |
6090 | } | |
6091 | ||
6092 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
6093 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
6094 | ||
6095 | static int | |
4a64f543 MS |
6096 | watchpoint_locations_match (struct bp_location *loc1, |
6097 | struct bp_location *loc2) | |
2d134ed3 | 6098 | { |
3a5c3e22 PA |
6099 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
6100 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
6101 | ||
6102 | /* Both of them must exist. */ | |
6103 | gdb_assert (w1 != NULL); | |
6104 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 6105 | |
4a64f543 MS |
6106 | /* If the target can evaluate the condition expression in hardware, |
6107 | then we we need to insert both watchpoints even if they are at | |
6108 | the same place. Otherwise the watchpoint will only trigger when | |
6109 | the condition of whichever watchpoint was inserted evaluates to | |
6110 | true, not giving a chance for GDB to check the condition of the | |
6111 | other watchpoint. */ | |
3a5c3e22 | 6112 | if ((w1->cond_exp |
4a64f543 MS |
6113 | && target_can_accel_watchpoint_condition (loc1->address, |
6114 | loc1->length, | |
0cf6dd15 | 6115 | loc1->watchpoint_type, |
3a5c3e22 PA |
6116 | w1->cond_exp)) |
6117 | || (w2->cond_exp | |
4a64f543 MS |
6118 | && target_can_accel_watchpoint_condition (loc2->address, |
6119 | loc2->length, | |
0cf6dd15 | 6120 | loc2->watchpoint_type, |
3a5c3e22 | 6121 | w2->cond_exp))) |
0cf6dd15 TJB |
6122 | return 0; |
6123 | ||
85d721b8 PA |
6124 | /* Note that this checks the owner's type, not the location's. In |
6125 | case the target does not support read watchpoints, but does | |
6126 | support access watchpoints, we'll have bp_read_watchpoint | |
6127 | watchpoints with hw_access locations. Those should be considered | |
6128 | duplicates of hw_read locations. The hw_read locations will | |
6129 | become hw_access locations later. */ | |
2d134ed3 PA |
6130 | return (loc1->owner->type == loc2->owner->type |
6131 | && loc1->pspace->aspace == loc2->pspace->aspace | |
6132 | && loc1->address == loc2->address | |
6133 | && loc1->length == loc2->length); | |
e4f237da KB |
6134 | } |
6135 | ||
6c95b8df PA |
6136 | /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the |
6137 | same breakpoint location. In most targets, this can only be true | |
6138 | if ASPACE1 matches ASPACE2. On targets that have global | |
6139 | breakpoints, the address space doesn't really matter. */ | |
6140 | ||
6141 | static int | |
6142 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, | |
6143 | struct address_space *aspace2, CORE_ADDR addr2) | |
6144 | { | |
6145 | return ((gdbarch_has_global_breakpoints (target_gdbarch) | |
6146 | || aspace1 == aspace2) | |
6147 | && addr1 == addr2); | |
6148 | } | |
6149 | ||
f1310107 TJB |
6150 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
6151 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
6152 | matches ASPACE2. On targets that have global breakpoints, the address | |
6153 | space doesn't really matter. */ | |
6154 | ||
6155 | static int | |
6156 | breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1, | |
6157 | int len1, struct address_space *aspace2, | |
6158 | CORE_ADDR addr2) | |
6159 | { | |
6160 | return ((gdbarch_has_global_breakpoints (target_gdbarch) | |
6161 | || aspace1 == aspace2) | |
6162 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
6163 | } | |
6164 | ||
6165 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
6166 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
6167 | matches the breakpoint's address space. On targets that have global | |
6168 | breakpoints, the address space doesn't really matter. */ | |
6169 | ||
6170 | static int | |
6171 | breakpoint_location_address_match (struct bp_location *bl, | |
6172 | struct address_space *aspace, | |
6173 | CORE_ADDR addr) | |
6174 | { | |
6175 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6176 | aspace, addr) | |
6177 | || (bl->length | |
6178 | && breakpoint_address_match_range (bl->pspace->aspace, | |
6179 | bl->address, bl->length, | |
6180 | aspace, addr))); | |
6181 | } | |
6182 | ||
1e4d1764 YQ |
6183 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
6184 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns | |
6185 | true, otherwise returns false. */ | |
6186 | ||
6187 | static int | |
6188 | tracepoint_locations_match (struct bp_location *loc1, | |
6189 | struct bp_location *loc2) | |
6190 | { | |
6191 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) | |
6192 | /* Since tracepoint locations are never duplicated with others', tracepoint | |
6193 | locations at the same address of different tracepoints are regarded as | |
6194 | different locations. */ | |
6195 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); | |
6196 | else | |
6197 | return 0; | |
6198 | } | |
6199 | ||
2d134ed3 PA |
6200 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
6201 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
6202 | represent the same location. */ | |
6203 | ||
6204 | static int | |
4a64f543 MS |
6205 | breakpoint_locations_match (struct bp_location *loc1, |
6206 | struct bp_location *loc2) | |
2d134ed3 | 6207 | { |
2bdf28a0 JK |
6208 | int hw_point1, hw_point2; |
6209 | ||
6210 | /* Both of them must not be in moribund_locations. */ | |
6211 | gdb_assert (loc1->owner != NULL); | |
6212 | gdb_assert (loc2->owner != NULL); | |
6213 | ||
6214 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
6215 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
6216 | |
6217 | if (hw_point1 != hw_point2) | |
6218 | return 0; | |
6219 | else if (hw_point1) | |
6220 | return watchpoint_locations_match (loc1, loc2); | |
1e4d1764 YQ |
6221 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
6222 | return tracepoint_locations_match (loc1, loc2); | |
2d134ed3 | 6223 | else |
f1310107 TJB |
6224 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
6225 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
6226 | loc2->pspace->aspace, loc2->address) | |
6227 | && loc1->length == loc2->length); | |
2d134ed3 PA |
6228 | } |
6229 | ||
76897487 KB |
6230 | static void |
6231 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
6232 | int bnum, int have_bnum) | |
6233 | { | |
f63fbe86 MS |
6234 | /* The longest string possibly returned by hex_string_custom |
6235 | is 50 chars. These must be at least that big for safety. */ | |
6236 | char astr1[64]; | |
6237 | char astr2[64]; | |
76897487 | 6238 | |
bb599908 PH |
6239 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
6240 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 6241 | if (have_bnum) |
8a3fe4f8 | 6242 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
6243 | bnum, astr1, astr2); |
6244 | else | |
8a3fe4f8 | 6245 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
6246 | } |
6247 | ||
4a64f543 MS |
6248 | /* Adjust a breakpoint's address to account for architectural |
6249 | constraints on breakpoint placement. Return the adjusted address. | |
6250 | Note: Very few targets require this kind of adjustment. For most | |
6251 | targets, this function is simply the identity function. */ | |
76897487 KB |
6252 | |
6253 | static CORE_ADDR | |
a6d9a66e UW |
6254 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
6255 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 6256 | { |
a6d9a66e | 6257 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
6258 | { |
6259 | /* Very few targets need any kind of breakpoint adjustment. */ | |
6260 | return bpaddr; | |
6261 | } | |
88f7da05 KB |
6262 | else if (bptype == bp_watchpoint |
6263 | || bptype == bp_hardware_watchpoint | |
6264 | || bptype == bp_read_watchpoint | |
6265 | || bptype == bp_access_watchpoint | |
fe798b75 | 6266 | || bptype == bp_catchpoint) |
88f7da05 KB |
6267 | { |
6268 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
6269 | have their addresses modified. */ | |
6270 | return bpaddr; | |
6271 | } | |
76897487 KB |
6272 | else |
6273 | { | |
6274 | CORE_ADDR adjusted_bpaddr; | |
6275 | ||
6276 | /* Some targets have architectural constraints on the placement | |
6277 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 6278 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
6279 | |
6280 | /* An adjusted breakpoint address can significantly alter | |
6281 | a user's expectations. Print a warning if an adjustment | |
6282 | is required. */ | |
6283 | if (adjusted_bpaddr != bpaddr) | |
6284 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
6285 | ||
6286 | return adjusted_bpaddr; | |
6287 | } | |
6288 | } | |
6289 | ||
28010a5d PA |
6290 | void |
6291 | init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops, | |
6292 | struct breakpoint *owner) | |
7cc221ef | 6293 | { |
7cc221ef DJ |
6294 | memset (loc, 0, sizeof (*loc)); |
6295 | ||
348d480f PA |
6296 | gdb_assert (ops != NULL); |
6297 | ||
28010a5d PA |
6298 | loc->ops = ops; |
6299 | loc->owner = owner; | |
511a6cd4 | 6300 | loc->cond = NULL; |
b775012e | 6301 | loc->cond_bytecode = NULL; |
0d381245 VP |
6302 | loc->shlib_disabled = 0; |
6303 | loc->enabled = 1; | |
e049a4b5 | 6304 | |
28010a5d | 6305 | switch (owner->type) |
e049a4b5 DJ |
6306 | { |
6307 | case bp_breakpoint: | |
6308 | case bp_until: | |
6309 | case bp_finish: | |
6310 | case bp_longjmp: | |
6311 | case bp_longjmp_resume: | |
186c406b TT |
6312 | case bp_exception: |
6313 | case bp_exception_resume: | |
e049a4b5 | 6314 | case bp_step_resume: |
2c03e5be | 6315 | case bp_hp_step_resume: |
e049a4b5 DJ |
6316 | case bp_watchpoint_scope: |
6317 | case bp_call_dummy: | |
aa7d318d | 6318 | case bp_std_terminate: |
e049a4b5 DJ |
6319 | case bp_shlib_event: |
6320 | case bp_thread_event: | |
6321 | case bp_overlay_event: | |
4efc6507 | 6322 | case bp_jit_event: |
0fd8e87f | 6323 | case bp_longjmp_master: |
aa7d318d | 6324 | case bp_std_terminate_master: |
186c406b | 6325 | case bp_exception_master: |
0e30163f JK |
6326 | case bp_gnu_ifunc_resolver: |
6327 | case bp_gnu_ifunc_resolver_return: | |
e049a4b5 | 6328 | loc->loc_type = bp_loc_software_breakpoint; |
b775012e | 6329 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
6330 | break; |
6331 | case bp_hardware_breakpoint: | |
6332 | loc->loc_type = bp_loc_hardware_breakpoint; | |
b775012e | 6333 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
6334 | break; |
6335 | case bp_hardware_watchpoint: | |
6336 | case bp_read_watchpoint: | |
6337 | case bp_access_watchpoint: | |
6338 | loc->loc_type = bp_loc_hardware_watchpoint; | |
6339 | break; | |
6340 | case bp_watchpoint: | |
ce78b96d | 6341 | case bp_catchpoint: |
15c3d785 PA |
6342 | case bp_tracepoint: |
6343 | case bp_fast_tracepoint: | |
0fb4aa4b | 6344 | case bp_static_tracepoint: |
e049a4b5 DJ |
6345 | loc->loc_type = bp_loc_other; |
6346 | break; | |
6347 | default: | |
e2e0b3e5 | 6348 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
6349 | } |
6350 | ||
f431efe5 | 6351 | loc->refc = 1; |
28010a5d PA |
6352 | } |
6353 | ||
6354 | /* Allocate a struct bp_location. */ | |
6355 | ||
6356 | static struct bp_location * | |
6357 | allocate_bp_location (struct breakpoint *bpt) | |
6358 | { | |
348d480f PA |
6359 | return bpt->ops->allocate_location (bpt); |
6360 | } | |
7cc221ef | 6361 | |
f431efe5 PA |
6362 | static void |
6363 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 | 6364 | { |
348d480f | 6365 | loc->ops->dtor (loc); |
fe3f5fa8 VP |
6366 | xfree (loc); |
6367 | } | |
6368 | ||
f431efe5 PA |
6369 | /* Increment reference count. */ |
6370 | ||
6371 | static void | |
6372 | incref_bp_location (struct bp_location *bl) | |
6373 | { | |
6374 | ++bl->refc; | |
6375 | } | |
6376 | ||
6377 | /* Decrement reference count. If the reference count reaches 0, | |
6378 | destroy the bp_location. Sets *BLP to NULL. */ | |
6379 | ||
6380 | static void | |
6381 | decref_bp_location (struct bp_location **blp) | |
6382 | { | |
0807b50c PA |
6383 | gdb_assert ((*blp)->refc > 0); |
6384 | ||
f431efe5 PA |
6385 | if (--(*blp)->refc == 0) |
6386 | free_bp_location (*blp); | |
6387 | *blp = NULL; | |
6388 | } | |
6389 | ||
346774a9 | 6390 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 6391 | |
346774a9 PA |
6392 | static void |
6393 | add_to_breakpoint_chain (struct breakpoint *b) | |
c906108c | 6394 | { |
346774a9 | 6395 | struct breakpoint *b1; |
c906108c | 6396 | |
346774a9 PA |
6397 | /* Add this breakpoint to the end of the chain so that a list of |
6398 | breakpoints will come out in order of increasing numbers. */ | |
6399 | ||
6400 | b1 = breakpoint_chain; | |
6401 | if (b1 == 0) | |
6402 | breakpoint_chain = b; | |
6403 | else | |
6404 | { | |
6405 | while (b1->next) | |
6406 | b1 = b1->next; | |
6407 | b1->next = b; | |
6408 | } | |
6409 | } | |
6410 | ||
6411 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
6412 | ||
6413 | static void | |
6414 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
6415 | struct gdbarch *gdbarch, | |
28010a5d | 6416 | enum bptype bptype, |
c0a91b2b | 6417 | const struct breakpoint_ops *ops) |
346774a9 | 6418 | { |
c906108c | 6419 | memset (b, 0, sizeof (*b)); |
2219d63c | 6420 | |
348d480f PA |
6421 | gdb_assert (ops != NULL); |
6422 | ||
28010a5d | 6423 | b->ops = ops; |
4d28f7a8 | 6424 | b->type = bptype; |
a6d9a66e | 6425 | b->gdbarch = gdbarch; |
c906108c SS |
6426 | b->language = current_language->la_language; |
6427 | b->input_radix = input_radix; | |
6428 | b->thread = -1; | |
b5de0fa7 | 6429 | b->enable_state = bp_enabled; |
c906108c SS |
6430 | b->next = 0; |
6431 | b->silent = 0; | |
6432 | b->ignore_count = 0; | |
6433 | b->commands = NULL; | |
818dd999 | 6434 | b->frame_id = null_frame_id; |
0d381245 | 6435 | b->condition_not_parsed = 0; |
84f4c1fe | 6436 | b->py_bp_object = NULL; |
d0fb5eae | 6437 | b->related_breakpoint = b; |
346774a9 PA |
6438 | } |
6439 | ||
6440 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
6441 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
6442 | |
6443 | static struct breakpoint * | |
6444 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 6445 | enum bptype bptype, |
c0a91b2b | 6446 | const struct breakpoint_ops *ops) |
346774a9 PA |
6447 | { |
6448 | struct breakpoint *b = XNEW (struct breakpoint); | |
6449 | ||
348d480f | 6450 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
c56053d2 | 6451 | add_to_breakpoint_chain (b); |
0d381245 VP |
6452 | return b; |
6453 | } | |
6454 | ||
0e30163f JK |
6455 | /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function |
6456 | resolutions should be made as the user specified the location explicitly | |
6457 | enough. */ | |
6458 | ||
0d381245 | 6459 | static void |
0e30163f | 6460 | set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) |
0d381245 | 6461 | { |
2bdf28a0 JK |
6462 | gdb_assert (loc->owner != NULL); |
6463 | ||
0d381245 | 6464 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 6465 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 6466 | || is_tracepoint (loc->owner)) |
0d381245 | 6467 | { |
0e30163f | 6468 | int is_gnu_ifunc; |
2c02bd72 | 6469 | const char *function_name; |
0e30163f | 6470 | |
2c02bd72 | 6471 | find_pc_partial_function_gnu_ifunc (loc->address, &function_name, |
0e30163f JK |
6472 | NULL, NULL, &is_gnu_ifunc); |
6473 | ||
6474 | if (is_gnu_ifunc && !explicit_loc) | |
6475 | { | |
6476 | struct breakpoint *b = loc->owner; | |
6477 | ||
6478 | gdb_assert (loc->pspace == current_program_space); | |
2c02bd72 | 6479 | if (gnu_ifunc_resolve_name (function_name, |
0e30163f JK |
6480 | &loc->requested_address)) |
6481 | { | |
6482 | /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */ | |
6483 | loc->address = adjust_breakpoint_address (loc->gdbarch, | |
6484 | loc->requested_address, | |
6485 | b->type); | |
6486 | } | |
6487 | else if (b->type == bp_breakpoint && b->loc == loc | |
6488 | && loc->next == NULL && b->related_breakpoint == b) | |
6489 | { | |
6490 | /* Create only the whole new breakpoint of this type but do not | |
6491 | mess more complicated breakpoints with multiple locations. */ | |
6492 | b->type = bp_gnu_ifunc_resolver; | |
6493 | } | |
6494 | } | |
6495 | ||
2c02bd72 DE |
6496 | if (function_name) |
6497 | loc->function_name = xstrdup (function_name); | |
0d381245 VP |
6498 | } |
6499 | } | |
6500 | ||
a6d9a66e | 6501 | /* Attempt to determine architecture of location identified by SAL. */ |
1bfeeb0f | 6502 | struct gdbarch * |
a6d9a66e UW |
6503 | get_sal_arch (struct symtab_and_line sal) |
6504 | { | |
6505 | if (sal.section) | |
6506 | return get_objfile_arch (sal.section->objfile); | |
6507 | if (sal.symtab) | |
6508 | return get_objfile_arch (sal.symtab->objfile); | |
6509 | ||
6510 | return NULL; | |
6511 | } | |
6512 | ||
346774a9 PA |
6513 | /* Low level routine for partially initializing a breakpoint of type |
6514 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 6515 | file name, and line number are provided by SAL. |
0d381245 VP |
6516 | |
6517 | It is expected that the caller will complete the initialization of | |
6518 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 6519 | information regarding the creation of a new breakpoint. */ |
0d381245 | 6520 | |
346774a9 PA |
6521 | static void |
6522 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 6523 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 6524 | const struct breakpoint_ops *ops) |
0d381245 | 6525 | { |
28010a5d | 6526 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 6527 | |
3742cc8b | 6528 | add_location_to_breakpoint (b, &sal); |
0d381245 | 6529 | |
6c95b8df PA |
6530 | if (bptype != bp_catchpoint) |
6531 | gdb_assert (sal.pspace != NULL); | |
6532 | ||
f8eba3c6 TT |
6533 | /* Store the program space that was used to set the breakpoint, |
6534 | except for ordinary breakpoints, which are independent of the | |
6535 | program space. */ | |
6536 | if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) | |
6537 | b->pspace = sal.pspace; | |
0d381245 | 6538 | |
c906108c | 6539 | breakpoints_changed (); |
346774a9 | 6540 | } |
c906108c | 6541 | |
346774a9 PA |
6542 | /* set_raw_breakpoint is a low level routine for allocating and |
6543 | partially initializing a breakpoint of type BPTYPE. The newly | |
6544 | created breakpoint's address, section, source file name, and line | |
6545 | number are provided by SAL. The newly created and partially | |
6546 | initialized breakpoint is added to the breakpoint chain and | |
6547 | is also returned as the value of this function. | |
6548 | ||
6549 | It is expected that the caller will complete the initialization of | |
6550 | the newly created breakpoint struct as well as output any status | |
6551 | information regarding the creation of a new breakpoint. In | |
6552 | particular, set_raw_breakpoint does NOT set the breakpoint | |
6553 | number! Care should be taken to not allow an error to occur | |
6554 | prior to completing the initialization of the breakpoint. If this | |
6555 | should happen, a bogus breakpoint will be left on the chain. */ | |
6556 | ||
6557 | struct breakpoint * | |
6558 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
348d480f | 6559 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 6560 | const struct breakpoint_ops *ops) |
346774a9 PA |
6561 | { |
6562 | struct breakpoint *b = XNEW (struct breakpoint); | |
6563 | ||
348d480f | 6564 | init_raw_breakpoint (b, gdbarch, sal, bptype, ops); |
c56053d2 | 6565 | add_to_breakpoint_chain (b); |
c906108c SS |
6566 | return b; |
6567 | } | |
6568 | ||
c2c6d25f JM |
6569 | |
6570 | /* Note that the breakpoint object B describes a permanent breakpoint | |
6571 | instruction, hard-wired into the inferior's code. */ | |
6572 | void | |
6573 | make_breakpoint_permanent (struct breakpoint *b) | |
6574 | { | |
0d381245 | 6575 | struct bp_location *bl; |
cc59ec59 | 6576 | |
b5de0fa7 | 6577 | b->enable_state = bp_permanent; |
c2c6d25f | 6578 | |
4a64f543 MS |
6579 | /* By definition, permanent breakpoints are already present in the |
6580 | code. Mark all locations as inserted. For now, | |
6581 | make_breakpoint_permanent is called in just one place, so it's | |
6582 | hard to say if it's reasonable to have permanent breakpoint with | |
e5dd4106 | 6583 | multiple locations or not, but it's easy to implement. */ |
0d381245 VP |
6584 | for (bl = b->loc; bl; bl = bl->next) |
6585 | bl->inserted = 1; | |
c2c6d25f JM |
6586 | } |
6587 | ||
53a5351d | 6588 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
6589 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
6590 | initiated the operation. */ | |
c906108c SS |
6591 | |
6592 | void | |
186c406b | 6593 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 6594 | { |
35df4500 | 6595 | struct breakpoint *b, *b_tmp; |
186c406b | 6596 | int thread = tp->num; |
0fd8e87f UW |
6597 | |
6598 | /* To avoid having to rescan all objfile symbols at every step, | |
6599 | we maintain a list of continually-inserted but always disabled | |
6600 | longjmp "master" breakpoints. Here, we simply create momentary | |
6601 | clones of those and enable them for the requested thread. */ | |
35df4500 | 6602 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 6603 | if (b->pspace == current_program_space |
186c406b TT |
6604 | && (b->type == bp_longjmp_master |
6605 | || b->type == bp_exception_master)) | |
0fd8e87f | 6606 | { |
06edf0c0 PA |
6607 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
6608 | struct breakpoint *clone; | |
cc59ec59 | 6609 | |
06edf0c0 PA |
6610 | clone = momentary_breakpoint_from_master (b, type, |
6611 | &momentary_breakpoint_ops); | |
0fd8e87f UW |
6612 | clone->thread = thread; |
6613 | } | |
186c406b TT |
6614 | |
6615 | tp->initiating_frame = frame; | |
c906108c SS |
6616 | } |
6617 | ||
611c83ae | 6618 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 6619 | void |
611c83ae | 6620 | delete_longjmp_breakpoint (int thread) |
c906108c | 6621 | { |
35df4500 | 6622 | struct breakpoint *b, *b_tmp; |
c906108c | 6623 | |
35df4500 | 6624 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 6625 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
6626 | { |
6627 | if (b->thread == thread) | |
6628 | delete_breakpoint (b); | |
6629 | } | |
c906108c SS |
6630 | } |
6631 | ||
f59f708a PA |
6632 | void |
6633 | delete_longjmp_breakpoint_at_next_stop (int thread) | |
6634 | { | |
6635 | struct breakpoint *b, *b_tmp; | |
6636 | ||
6637 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
6638 | if (b->type == bp_longjmp || b->type == bp_exception) | |
6639 | { | |
6640 | if (b->thread == thread) | |
6641 | b->disposition = disp_del_at_next_stop; | |
6642 | } | |
6643 | } | |
6644 | ||
1900040c MS |
6645 | void |
6646 | enable_overlay_breakpoints (void) | |
6647 | { | |
52f0bd74 | 6648 | struct breakpoint *b; |
1900040c MS |
6649 | |
6650 | ALL_BREAKPOINTS (b) | |
6651 | if (b->type == bp_overlay_event) | |
6652 | { | |
6653 | b->enable_state = bp_enabled; | |
b60e7edf | 6654 | update_global_location_list (1); |
c02f5703 | 6655 | overlay_events_enabled = 1; |
1900040c MS |
6656 | } |
6657 | } | |
6658 | ||
6659 | void | |
6660 | disable_overlay_breakpoints (void) | |
6661 | { | |
52f0bd74 | 6662 | struct breakpoint *b; |
1900040c MS |
6663 | |
6664 | ALL_BREAKPOINTS (b) | |
6665 | if (b->type == bp_overlay_event) | |
6666 | { | |
6667 | b->enable_state = bp_disabled; | |
b60e7edf | 6668 | update_global_location_list (0); |
c02f5703 | 6669 | overlay_events_enabled = 0; |
1900040c MS |
6670 | } |
6671 | } | |
6672 | ||
aa7d318d TT |
6673 | /* Set an active std::terminate breakpoint for each std::terminate |
6674 | master breakpoint. */ | |
6675 | void | |
6676 | set_std_terminate_breakpoint (void) | |
6677 | { | |
35df4500 | 6678 | struct breakpoint *b, *b_tmp; |
aa7d318d | 6679 | |
35df4500 | 6680 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
6681 | if (b->pspace == current_program_space |
6682 | && b->type == bp_std_terminate_master) | |
6683 | { | |
06edf0c0 PA |
6684 | momentary_breakpoint_from_master (b, bp_std_terminate, |
6685 | &momentary_breakpoint_ops); | |
aa7d318d TT |
6686 | } |
6687 | } | |
6688 | ||
6689 | /* Delete all the std::terminate breakpoints. */ | |
6690 | void | |
6691 | delete_std_terminate_breakpoint (void) | |
6692 | { | |
35df4500 | 6693 | struct breakpoint *b, *b_tmp; |
aa7d318d | 6694 | |
35df4500 | 6695 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
6696 | if (b->type == bp_std_terminate) |
6697 | delete_breakpoint (b); | |
6698 | } | |
6699 | ||
c4093a6a | 6700 | struct breakpoint * |
a6d9a66e | 6701 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
6702 | { |
6703 | struct breakpoint *b; | |
c4093a6a | 6704 | |
06edf0c0 PA |
6705 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
6706 | &internal_breakpoint_ops); | |
6707 | ||
b5de0fa7 | 6708 | b->enable_state = bp_enabled; |
c4093a6a | 6709 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
6710 | b->addr_string |
6711 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 6712 | |
b60e7edf | 6713 | update_global_location_list_nothrow (1); |
74960c60 | 6714 | |
c4093a6a JM |
6715 | return b; |
6716 | } | |
6717 | ||
6718 | void | |
6719 | remove_thread_event_breakpoints (void) | |
6720 | { | |
35df4500 | 6721 | struct breakpoint *b, *b_tmp; |
c4093a6a | 6722 | |
35df4500 | 6723 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
6724 | if (b->type == bp_thread_event |
6725 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
6726 | delete_breakpoint (b); |
6727 | } | |
6728 | ||
0101ce28 JJ |
6729 | struct lang_and_radix |
6730 | { | |
6731 | enum language lang; | |
6732 | int radix; | |
6733 | }; | |
6734 | ||
4efc6507 DE |
6735 | /* Create a breakpoint for JIT code registration and unregistration. */ |
6736 | ||
6737 | struct breakpoint * | |
6738 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
6739 | { | |
6740 | struct breakpoint *b; | |
6741 | ||
06edf0c0 PA |
6742 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event, |
6743 | &internal_breakpoint_ops); | |
4efc6507 DE |
6744 | update_global_location_list_nothrow (1); |
6745 | return b; | |
6746 | } | |
0101ce28 | 6747 | |
03673fc7 PP |
6748 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
6749 | ||
6750 | void | |
6751 | remove_jit_event_breakpoints (void) | |
6752 | { | |
6753 | struct breakpoint *b, *b_tmp; | |
6754 | ||
6755 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
6756 | if (b->type == bp_jit_event | |
6757 | && b->loc->pspace == current_program_space) | |
6758 | delete_breakpoint (b); | |
6759 | } | |
6760 | ||
cae688ec JJ |
6761 | void |
6762 | remove_solib_event_breakpoints (void) | |
6763 | { | |
35df4500 | 6764 | struct breakpoint *b, *b_tmp; |
cae688ec | 6765 | |
35df4500 | 6766 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
6767 | if (b->type == bp_shlib_event |
6768 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
6769 | delete_breakpoint (b); |
6770 | } | |
6771 | ||
6772 | struct breakpoint * | |
a6d9a66e | 6773 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
cae688ec JJ |
6774 | { |
6775 | struct breakpoint *b; | |
6776 | ||
06edf0c0 PA |
6777 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
6778 | &internal_breakpoint_ops); | |
b60e7edf | 6779 | update_global_location_list_nothrow (1); |
cae688ec JJ |
6780 | return b; |
6781 | } | |
6782 | ||
6783 | /* Disable any breakpoints that are on code in shared libraries. Only | |
6784 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
6785 | ||
6786 | void | |
cb851954 | 6787 | disable_breakpoints_in_shlibs (void) |
cae688ec | 6788 | { |
876fa593 | 6789 | struct bp_location *loc, **locp_tmp; |
cae688ec | 6790 | |
876fa593 | 6791 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 6792 | { |
2bdf28a0 | 6793 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 6794 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 6795 | |
4a64f543 MS |
6796 | /* We apply the check to all breakpoints, including disabled for |
6797 | those with loc->duplicate set. This is so that when breakpoint | |
6798 | becomes enabled, or the duplicate is removed, gdb will try to | |
6799 | insert all breakpoints. If we don't set shlib_disabled here, | |
6800 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 6801 | if (((b->type == bp_breakpoint) |
508ccb1f | 6802 | || (b->type == bp_jit_event) |
1042e4c0 | 6803 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 6804 | || (is_tracepoint (b))) |
6c95b8df | 6805 | && loc->pspace == current_program_space |
0d381245 | 6806 | && !loc->shlib_disabled |
a77053c2 | 6807 | #ifdef PC_SOLIB |
0d381245 | 6808 | && PC_SOLIB (loc->address) |
a77053c2 | 6809 | #else |
6c95b8df | 6810 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 MK |
6811 | #endif |
6812 | ) | |
0d381245 VP |
6813 | { |
6814 | loc->shlib_disabled = 1; | |
6815 | } | |
cae688ec JJ |
6816 | } |
6817 | } | |
6818 | ||
1e4d1764 YQ |
6819 | /* Disable any breakpoints and tracepoints that are in an unloaded shared |
6820 | library. Only apply to enabled breakpoints, disabled ones can just stay | |
4a64f543 | 6821 | disabled. */ |
84acb35a | 6822 | |
75149521 | 6823 | static void |
84acb35a JJ |
6824 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
6825 | { | |
876fa593 | 6826 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
6827 | int disabled_shlib_breaks = 0; |
6828 | ||
c86cf029 VP |
6829 | /* SunOS a.out shared libraries are always mapped, so do not |
6830 | disable breakpoints; they will only be reported as unloaded | |
6831 | through clear_solib when GDB discards its shared library | |
6832 | list. See clear_solib for more information. */ | |
6833 | if (exec_bfd != NULL | |
6834 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
6835 | return; | |
6836 | ||
876fa593 | 6837 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 6838 | { |
2bdf28a0 | 6839 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 6840 | struct breakpoint *b = loc->owner; |
cc59ec59 | 6841 | |
1e4d1764 | 6842 | if (solib->pspace == loc->pspace |
e2dd7057 | 6843 | && !loc->shlib_disabled |
1e4d1764 YQ |
6844 | && (((b->type == bp_breakpoint |
6845 | || b->type == bp_jit_event | |
6846 | || b->type == bp_hardware_breakpoint) | |
6847 | && (loc->loc_type == bp_loc_hardware_breakpoint | |
6848 | || loc->loc_type == bp_loc_software_breakpoint)) | |
6849 | || is_tracepoint (b)) | |
e2dd7057 | 6850 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 6851 | { |
e2dd7057 PP |
6852 | loc->shlib_disabled = 1; |
6853 | /* At this point, we cannot rely on remove_breakpoint | |
6854 | succeeding so we must mark the breakpoint as not inserted | |
6855 | to prevent future errors occurring in remove_breakpoints. */ | |
6856 | loc->inserted = 0; | |
8d3788bd VP |
6857 | |
6858 | /* This may cause duplicate notifications for the same breakpoint. */ | |
6859 | observer_notify_breakpoint_modified (b); | |
6860 | ||
e2dd7057 PP |
6861 | if (!disabled_shlib_breaks) |
6862 | { | |
6863 | target_terminal_ours_for_output (); | |
3e43a32a MS |
6864 | warning (_("Temporarily disabling breakpoints " |
6865 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 6866 | solib->so_name); |
84acb35a | 6867 | } |
e2dd7057 | 6868 | disabled_shlib_breaks = 1; |
84acb35a JJ |
6869 | } |
6870 | } | |
84acb35a JJ |
6871 | } |
6872 | ||
ce78b96d JB |
6873 | /* FORK & VFORK catchpoints. */ |
6874 | ||
e29a4733 PA |
6875 | /* An instance of this type is used to represent a fork or vfork |
6876 | catchpoint. It includes a "struct breakpoint" as a kind of base | |
6877 | class; users downcast to "struct breakpoint *" when needed. A | |
6878 | breakpoint is really of this type iff its ops pointer points to | |
6879 | CATCH_FORK_BREAKPOINT_OPS. */ | |
6880 | ||
6881 | struct fork_catchpoint | |
6882 | { | |
6883 | /* The base class. */ | |
6884 | struct breakpoint base; | |
6885 | ||
6886 | /* Process id of a child process whose forking triggered this | |
6887 | catchpoint. This field is only valid immediately after this | |
6888 | catchpoint has triggered. */ | |
6889 | ptid_t forked_inferior_pid; | |
6890 | }; | |
6891 | ||
4a64f543 MS |
6892 | /* Implement the "insert" breakpoint_ops method for fork |
6893 | catchpoints. */ | |
ce78b96d | 6894 | |
77b06cd7 TJB |
6895 | static int |
6896 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 6897 | { |
77b06cd7 | 6898 | return target_insert_fork_catchpoint (PIDGET (inferior_ptid)); |
ce78b96d JB |
6899 | } |
6900 | ||
4a64f543 MS |
6901 | /* Implement the "remove" breakpoint_ops method for fork |
6902 | catchpoints. */ | |
ce78b96d JB |
6903 | |
6904 | static int | |
77b06cd7 | 6905 | remove_catch_fork (struct bp_location *bl) |
ce78b96d JB |
6906 | { |
6907 | return target_remove_fork_catchpoint (PIDGET (inferior_ptid)); | |
6908 | } | |
6909 | ||
6910 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
6911 | catchpoints. */ | |
6912 | ||
6913 | static int | |
f1310107 | 6914 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
09ac7c10 TT |
6915 | struct address_space *aspace, CORE_ADDR bp_addr, |
6916 | const struct target_waitstatus *ws) | |
ce78b96d | 6917 | { |
e29a4733 PA |
6918 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
6919 | ||
f90263c1 TT |
6920 | if (ws->kind != TARGET_WAITKIND_FORKED) |
6921 | return 0; | |
6922 | ||
6923 | c->forked_inferior_pid = ws->value.related_pid; | |
6924 | return 1; | |
ce78b96d JB |
6925 | } |
6926 | ||
4a64f543 MS |
6927 | /* Implement the "print_it" breakpoint_ops method for fork |
6928 | catchpoints. */ | |
ce78b96d JB |
6929 | |
6930 | static enum print_stop_action | |
348d480f | 6931 | print_it_catch_fork (bpstat bs) |
ce78b96d | 6932 | { |
36dfb11c | 6933 | struct ui_out *uiout = current_uiout; |
348d480f PA |
6934 | struct breakpoint *b = bs->breakpoint_at; |
6935 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; | |
e29a4733 | 6936 | |
ce78b96d | 6937 | annotate_catchpoint (b->number); |
36dfb11c TT |
6938 | if (b->disposition == disp_del) |
6939 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
6940 | else | |
6941 | ui_out_text (uiout, "\nCatchpoint "); | |
6942 | if (ui_out_is_mi_like_p (uiout)) | |
6943 | { | |
6944 | ui_out_field_string (uiout, "reason", | |
6945 | async_reason_lookup (EXEC_ASYNC_FORK)); | |
6946 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
6947 | } | |
6948 | ui_out_field_int (uiout, "bkptno", b->number); | |
6949 | ui_out_text (uiout, " (forked process "); | |
6950 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
6951 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
6952 | return PRINT_SRC_AND_LOC; |
6953 | } | |
6954 | ||
4a64f543 MS |
6955 | /* Implement the "print_one" breakpoint_ops method for fork |
6956 | catchpoints. */ | |
ce78b96d JB |
6957 | |
6958 | static void | |
a6d9a66e | 6959 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 6960 | { |
e29a4733 | 6961 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 6962 | struct value_print_options opts; |
79a45e25 | 6963 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
6964 | |
6965 | get_user_print_options (&opts); | |
6966 | ||
4a64f543 MS |
6967 | /* Field 4, the address, is omitted (which makes the columns not |
6968 | line up too nicely with the headers, but the effect is relatively | |
6969 | readable). */ | |
79a45b7d | 6970 | if (opts.addressprint) |
ce78b96d JB |
6971 | ui_out_field_skip (uiout, "addr"); |
6972 | annotate_field (5); | |
6973 | ui_out_text (uiout, "fork"); | |
e29a4733 | 6974 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
6975 | { |
6976 | ui_out_text (uiout, ", process "); | |
6977 | ui_out_field_int (uiout, "what", | |
e29a4733 | 6978 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
6979 | ui_out_spaces (uiout, 1); |
6980 | } | |
6981 | } | |
6982 | ||
6983 | /* Implement the "print_mention" breakpoint_ops method for fork | |
6984 | catchpoints. */ | |
6985 | ||
6986 | static void | |
6987 | print_mention_catch_fork (struct breakpoint *b) | |
6988 | { | |
6989 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
6990 | } | |
6991 | ||
6149aea9 PA |
6992 | /* Implement the "print_recreate" breakpoint_ops method for fork |
6993 | catchpoints. */ | |
6994 | ||
6995 | static void | |
6996 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
6997 | { | |
6998 | fprintf_unfiltered (fp, "catch fork"); | |
d9b3f62e | 6999 | print_recreate_thread (b, fp); |
6149aea9 PA |
7000 | } |
7001 | ||
ce78b96d JB |
7002 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
7003 | ||
2060206e | 7004 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
ce78b96d | 7005 | |
4a64f543 MS |
7006 | /* Implement the "insert" breakpoint_ops method for vfork |
7007 | catchpoints. */ | |
ce78b96d | 7008 | |
77b06cd7 TJB |
7009 | static int |
7010 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 7011 | { |
77b06cd7 | 7012 | return target_insert_vfork_catchpoint (PIDGET (inferior_ptid)); |
ce78b96d JB |
7013 | } |
7014 | ||
4a64f543 MS |
7015 | /* Implement the "remove" breakpoint_ops method for vfork |
7016 | catchpoints. */ | |
ce78b96d JB |
7017 | |
7018 | static int | |
77b06cd7 | 7019 | remove_catch_vfork (struct bp_location *bl) |
ce78b96d JB |
7020 | { |
7021 | return target_remove_vfork_catchpoint (PIDGET (inferior_ptid)); | |
7022 | } | |
7023 | ||
7024 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
7025 | catchpoints. */ | |
7026 | ||
7027 | static int | |
f1310107 | 7028 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
09ac7c10 TT |
7029 | struct address_space *aspace, CORE_ADDR bp_addr, |
7030 | const struct target_waitstatus *ws) | |
ce78b96d | 7031 | { |
e29a4733 PA |
7032 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
7033 | ||
f90263c1 TT |
7034 | if (ws->kind != TARGET_WAITKIND_VFORKED) |
7035 | return 0; | |
7036 | ||
7037 | c->forked_inferior_pid = ws->value.related_pid; | |
7038 | return 1; | |
ce78b96d JB |
7039 | } |
7040 | ||
4a64f543 MS |
7041 | /* Implement the "print_it" breakpoint_ops method for vfork |
7042 | catchpoints. */ | |
ce78b96d JB |
7043 | |
7044 | static enum print_stop_action | |
348d480f | 7045 | print_it_catch_vfork (bpstat bs) |
ce78b96d | 7046 | { |
36dfb11c | 7047 | struct ui_out *uiout = current_uiout; |
348d480f | 7048 | struct breakpoint *b = bs->breakpoint_at; |
e29a4733 PA |
7049 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
7050 | ||
ce78b96d | 7051 | annotate_catchpoint (b->number); |
36dfb11c TT |
7052 | if (b->disposition == disp_del) |
7053 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
7054 | else | |
7055 | ui_out_text (uiout, "\nCatchpoint "); | |
7056 | if (ui_out_is_mi_like_p (uiout)) | |
7057 | { | |
7058 | ui_out_field_string (uiout, "reason", | |
7059 | async_reason_lookup (EXEC_ASYNC_VFORK)); | |
7060 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
7061 | } | |
7062 | ui_out_field_int (uiout, "bkptno", b->number); | |
7063 | ui_out_text (uiout, " (vforked process "); | |
7064 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
7065 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
7066 | return PRINT_SRC_AND_LOC; |
7067 | } | |
7068 | ||
4a64f543 MS |
7069 | /* Implement the "print_one" breakpoint_ops method for vfork |
7070 | catchpoints. */ | |
ce78b96d JB |
7071 | |
7072 | static void | |
a6d9a66e | 7073 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 7074 | { |
e29a4733 | 7075 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 7076 | struct value_print_options opts; |
79a45e25 | 7077 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
7078 | |
7079 | get_user_print_options (&opts); | |
4a64f543 MS |
7080 | /* Field 4, the address, is omitted (which makes the columns not |
7081 | line up too nicely with the headers, but the effect is relatively | |
7082 | readable). */ | |
79a45b7d | 7083 | if (opts.addressprint) |
ce78b96d JB |
7084 | ui_out_field_skip (uiout, "addr"); |
7085 | annotate_field (5); | |
7086 | ui_out_text (uiout, "vfork"); | |
e29a4733 | 7087 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
7088 | { |
7089 | ui_out_text (uiout, ", process "); | |
7090 | ui_out_field_int (uiout, "what", | |
e29a4733 | 7091 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
7092 | ui_out_spaces (uiout, 1); |
7093 | } | |
7094 | } | |
7095 | ||
7096 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
7097 | catchpoints. */ | |
7098 | ||
7099 | static void | |
7100 | print_mention_catch_vfork (struct breakpoint *b) | |
7101 | { | |
7102 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
7103 | } | |
7104 | ||
6149aea9 PA |
7105 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
7106 | catchpoints. */ | |
7107 | ||
7108 | static void | |
7109 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
7110 | { | |
7111 | fprintf_unfiltered (fp, "catch vfork"); | |
d9b3f62e | 7112 | print_recreate_thread (b, fp); |
6149aea9 PA |
7113 | } |
7114 | ||
ce78b96d JB |
7115 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
7116 | ||
2060206e | 7117 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
ce78b96d | 7118 | |
edcc5120 TT |
7119 | /* An instance of this type is used to represent an solib catchpoint. |
7120 | It includes a "struct breakpoint" as a kind of base class; users | |
7121 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
7122 | really of this type iff its ops pointer points to | |
7123 | CATCH_SOLIB_BREAKPOINT_OPS. */ | |
7124 | ||
7125 | struct solib_catchpoint | |
7126 | { | |
7127 | /* The base class. */ | |
7128 | struct breakpoint base; | |
7129 | ||
7130 | /* True for "catch load", false for "catch unload". */ | |
7131 | unsigned char is_load; | |
7132 | ||
7133 | /* Regular expression to match, if any. COMPILED is only valid when | |
7134 | REGEX is non-NULL. */ | |
7135 | char *regex; | |
7136 | regex_t compiled; | |
7137 | }; | |
7138 | ||
7139 | static void | |
7140 | dtor_catch_solib (struct breakpoint *b) | |
7141 | { | |
7142 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
7143 | ||
7144 | if (self->regex) | |
7145 | regfree (&self->compiled); | |
7146 | xfree (self->regex); | |
7147 | ||
7148 | base_breakpoint_ops.dtor (b); | |
7149 | } | |
7150 | ||
7151 | static int | |
7152 | insert_catch_solib (struct bp_location *ignore) | |
7153 | { | |
7154 | return 0; | |
7155 | } | |
7156 | ||
7157 | static int | |
7158 | remove_catch_solib (struct bp_location *ignore) | |
7159 | { | |
7160 | return 0; | |
7161 | } | |
7162 | ||
7163 | static int | |
7164 | breakpoint_hit_catch_solib (const struct bp_location *bl, | |
7165 | struct address_space *aspace, | |
7166 | CORE_ADDR bp_addr, | |
7167 | const struct target_waitstatus *ws) | |
7168 | { | |
7169 | struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner; | |
7170 | struct breakpoint *other; | |
7171 | ||
7172 | if (ws->kind == TARGET_WAITKIND_LOADED) | |
7173 | return 1; | |
7174 | ||
7175 | ALL_BREAKPOINTS (other) | |
7176 | { | |
7177 | struct bp_location *other_bl; | |
7178 | ||
7179 | if (other == bl->owner) | |
7180 | continue; | |
7181 | ||
7182 | if (other->type != bp_shlib_event) | |
7183 | continue; | |
7184 | ||
7185 | if (self->base.pspace != NULL && other->pspace != self->base.pspace) | |
7186 | continue; | |
7187 | ||
7188 | for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next) | |
7189 | { | |
7190 | if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) | |
7191 | return 1; | |
7192 | } | |
7193 | } | |
7194 | ||
7195 | return 0; | |
7196 | } | |
7197 | ||
7198 | static void | |
7199 | check_status_catch_solib (struct bpstats *bs) | |
7200 | { | |
7201 | struct solib_catchpoint *self | |
7202 | = (struct solib_catchpoint *) bs->breakpoint_at; | |
7203 | int ix; | |
7204 | ||
7205 | if (self->is_load) | |
7206 | { | |
7207 | struct so_list *iter; | |
7208 | ||
7209 | for (ix = 0; | |
7210 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
7211 | ix, iter); | |
7212 | ++ix) | |
7213 | { | |
7214 | if (!self->regex | |
7215 | || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0) | |
7216 | return; | |
7217 | } | |
7218 | } | |
7219 | else | |
7220 | { | |
7221 | char *iter; | |
7222 | ||
7223 | for (ix = 0; | |
7224 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
7225 | ix, iter); | |
7226 | ++ix) | |
7227 | { | |
7228 | if (!self->regex | |
7229 | || regexec (&self->compiled, iter, 0, NULL, 0) == 0) | |
7230 | return; | |
7231 | } | |
7232 | } | |
7233 | ||
7234 | bs->stop = 0; | |
7235 | bs->print_it = print_it_noop; | |
7236 | } | |
7237 | ||
7238 | static enum print_stop_action | |
7239 | print_it_catch_solib (bpstat bs) | |
7240 | { | |
7241 | struct breakpoint *b = bs->breakpoint_at; | |
7242 | struct ui_out *uiout = current_uiout; | |
7243 | ||
7244 | annotate_catchpoint (b->number); | |
7245 | if (b->disposition == disp_del) | |
7246 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
7247 | else | |
7248 | ui_out_text (uiout, "\nCatchpoint "); | |
7249 | ui_out_field_int (uiout, "bkptno", b->number); | |
7250 | ui_out_text (uiout, "\n"); | |
7251 | if (ui_out_is_mi_like_p (uiout)) | |
7252 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
7253 | print_solib_event (1); | |
7254 | return PRINT_SRC_AND_LOC; | |
7255 | } | |
7256 | ||
7257 | static void | |
7258 | print_one_catch_solib (struct breakpoint *b, struct bp_location **locs) | |
7259 | { | |
7260 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
7261 | struct value_print_options opts; | |
7262 | struct ui_out *uiout = current_uiout; | |
7263 | char *msg; | |
7264 | ||
7265 | get_user_print_options (&opts); | |
7266 | /* Field 4, the address, is omitted (which makes the columns not | |
7267 | line up too nicely with the headers, but the effect is relatively | |
7268 | readable). */ | |
7269 | if (opts.addressprint) | |
7270 | { | |
7271 | annotate_field (4); | |
7272 | ui_out_field_skip (uiout, "addr"); | |
7273 | } | |
7274 | ||
7275 | annotate_field (5); | |
7276 | if (self->is_load) | |
7277 | { | |
7278 | if (self->regex) | |
7279 | msg = xstrprintf (_("load of library matching %s"), self->regex); | |
7280 | else | |
7281 | msg = xstrdup (_("load of library")); | |
7282 | } | |
7283 | else | |
7284 | { | |
7285 | if (self->regex) | |
7286 | msg = xstrprintf (_("unload of library matching %s"), self->regex); | |
7287 | else | |
7288 | msg = xstrdup (_("unload of library")); | |
7289 | } | |
7290 | ui_out_field_string (uiout, "what", msg); | |
7291 | xfree (msg); | |
7292 | } | |
7293 | ||
7294 | static void | |
7295 | print_mention_catch_solib (struct breakpoint *b) | |
7296 | { | |
7297 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
7298 | ||
7299 | printf_filtered (_("Catchpoint %d (%s)"), b->number, | |
7300 | self->is_load ? "load" : "unload"); | |
7301 | } | |
7302 | ||
7303 | static void | |
7304 | print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp) | |
7305 | { | |
7306 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
7307 | ||
7308 | fprintf_unfiltered (fp, "%s %s", | |
7309 | b->disposition == disp_del ? "tcatch" : "catch", | |
7310 | self->is_load ? "load" : "unload"); | |
7311 | if (self->regex) | |
7312 | fprintf_unfiltered (fp, " %s", self->regex); | |
7313 | fprintf_unfiltered (fp, "\n"); | |
7314 | } | |
7315 | ||
7316 | static struct breakpoint_ops catch_solib_breakpoint_ops; | |
7317 | ||
7318 | /* A helper function that does all the work for "catch load" and | |
7319 | "catch unload". */ | |
7320 | ||
7321 | static void | |
7322 | catch_load_or_unload (char *arg, int from_tty, int is_load, | |
7323 | struct cmd_list_element *command) | |
7324 | { | |
7325 | struct solib_catchpoint *c; | |
7326 | struct gdbarch *gdbarch = get_current_arch (); | |
7327 | int tempflag; | |
7328 | regex_t compiled; | |
7329 | struct cleanup *cleanup; | |
7330 | ||
7331 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
7332 | ||
7333 | if (!arg) | |
7334 | arg = ""; | |
7335 | arg = skip_spaces (arg); | |
7336 | ||
7337 | c = XCNEW (struct solib_catchpoint); | |
7338 | cleanup = make_cleanup (xfree, c); | |
7339 | ||
7340 | if (*arg != '\0') | |
7341 | { | |
7342 | int errcode; | |
7343 | ||
7344 | errcode = regcomp (&c->compiled, arg, REG_NOSUB); | |
7345 | if (errcode != 0) | |
7346 | { | |
7347 | char *err = get_regcomp_error (errcode, &c->compiled); | |
7348 | ||
7349 | make_cleanup (xfree, err); | |
7350 | error (_("Invalid regexp (%s): %s"), err, arg); | |
7351 | } | |
7352 | c->regex = xstrdup (arg); | |
7353 | } | |
7354 | ||
7355 | c->is_load = is_load; | |
7356 | init_catchpoint (&c->base, gdbarch, tempflag, NULL, | |
7357 | &catch_solib_breakpoint_ops); | |
7358 | ||
7359 | discard_cleanups (cleanup); | |
7360 | install_breakpoint (0, &c->base, 1); | |
7361 | } | |
7362 | ||
7363 | static void | |
7364 | catch_load_command_1 (char *arg, int from_tty, | |
7365 | struct cmd_list_element *command) | |
7366 | { | |
7367 | catch_load_or_unload (arg, from_tty, 1, command); | |
7368 | } | |
7369 | ||
7370 | static void | |
7371 | catch_unload_command_1 (char *arg, int from_tty, | |
7372 | struct cmd_list_element *command) | |
7373 | { | |
7374 | catch_load_or_unload (arg, from_tty, 0, command); | |
7375 | } | |
7376 | ||
fa3064dd YQ |
7377 | DEF_VEC_I(int); |
7378 | ||
be5c67c1 PA |
7379 | /* An instance of this type is used to represent a syscall catchpoint. |
7380 | It includes a "struct breakpoint" as a kind of base class; users | |
7381 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
7382 | really of this type iff its ops pointer points to | |
7383 | CATCH_SYSCALL_BREAKPOINT_OPS. */ | |
7384 | ||
7385 | struct syscall_catchpoint | |
7386 | { | |
7387 | /* The base class. */ | |
7388 | struct breakpoint base; | |
7389 | ||
7390 | /* Syscall numbers used for the 'catch syscall' feature. If no | |
7391 | syscall has been specified for filtering, its value is NULL. | |
7392 | Otherwise, it holds a list of all syscalls to be caught. The | |
7393 | list elements are allocated with xmalloc. */ | |
7394 | VEC(int) *syscalls_to_be_caught; | |
7395 | }; | |
7396 | ||
7397 | /* Implement the "dtor" breakpoint_ops method for syscall | |
7398 | catchpoints. */ | |
7399 | ||
7400 | static void | |
7401 | dtor_catch_syscall (struct breakpoint *b) | |
7402 | { | |
7403 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; | |
7404 | ||
7405 | VEC_free (int, c->syscalls_to_be_caught); | |
348d480f | 7406 | |
2060206e | 7407 | base_breakpoint_ops.dtor (b); |
be5c67c1 PA |
7408 | } |
7409 | ||
fa3064dd YQ |
7410 | static const struct inferior_data *catch_syscall_inferior_data = NULL; |
7411 | ||
7412 | struct catch_syscall_inferior_data | |
7413 | { | |
7414 | /* We keep a count of the number of times the user has requested a | |
7415 | particular syscall to be tracked, and pass this information to the | |
7416 | target. This lets capable targets implement filtering directly. */ | |
7417 | ||
7418 | /* Number of times that "any" syscall is requested. */ | |
7419 | int any_syscall_count; | |
7420 | ||
7421 | /* Count of each system call. */ | |
7422 | VEC(int) *syscalls_counts; | |
7423 | ||
7424 | /* This counts all syscall catch requests, so we can readily determine | |
7425 | if any catching is necessary. */ | |
7426 | int total_syscalls_count; | |
7427 | }; | |
7428 | ||
7429 | static struct catch_syscall_inferior_data* | |
7430 | get_catch_syscall_inferior_data (struct inferior *inf) | |
7431 | { | |
7432 | struct catch_syscall_inferior_data *inf_data; | |
7433 | ||
7434 | inf_data = inferior_data (inf, catch_syscall_inferior_data); | |
7435 | if (inf_data == NULL) | |
7436 | { | |
7437 | inf_data = XZALLOC (struct catch_syscall_inferior_data); | |
7438 | set_inferior_data (inf, catch_syscall_inferior_data, inf_data); | |
7439 | } | |
7440 | ||
7441 | return inf_data; | |
7442 | } | |
7443 | ||
7444 | static void | |
7445 | catch_syscall_inferior_data_cleanup (struct inferior *inf, void *arg) | |
7446 | { | |
7447 | xfree (arg); | |
7448 | } | |
7449 | ||
7450 | ||
a96d9b2e SDJ |
7451 | /* Implement the "insert" breakpoint_ops method for syscall |
7452 | catchpoints. */ | |
7453 | ||
77b06cd7 TJB |
7454 | static int |
7455 | insert_catch_syscall (struct bp_location *bl) | |
a96d9b2e | 7456 | { |
be5c67c1 | 7457 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; |
a96d9b2e | 7458 | struct inferior *inf = current_inferior (); |
fa3064dd YQ |
7459 | struct catch_syscall_inferior_data *inf_data |
7460 | = get_catch_syscall_inferior_data (inf); | |
a96d9b2e | 7461 | |
fa3064dd | 7462 | ++inf_data->total_syscalls_count; |
be5c67c1 | 7463 | if (!c->syscalls_to_be_caught) |
fa3064dd | 7464 | ++inf_data->any_syscall_count; |
a96d9b2e SDJ |
7465 | else |
7466 | { | |
7467 | int i, iter; | |
cc59ec59 | 7468 | |
a96d9b2e | 7469 | for (i = 0; |
be5c67c1 | 7470 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
7471 | i++) |
7472 | { | |
7473 | int elem; | |
cc59ec59 | 7474 | |
fa3064dd | 7475 | if (iter >= VEC_length (int, inf_data->syscalls_counts)) |
a96d9b2e | 7476 | { |
fa3064dd | 7477 | int old_size = VEC_length (int, inf_data->syscalls_counts); |
3e43a32a MS |
7478 | uintptr_t vec_addr_offset |
7479 | = old_size * ((uintptr_t) sizeof (int)); | |
a96d9b2e | 7480 | uintptr_t vec_addr; |
fa3064dd YQ |
7481 | VEC_safe_grow (int, inf_data->syscalls_counts, iter + 1); |
7482 | vec_addr = ((uintptr_t) VEC_address (int, | |
7483 | inf_data->syscalls_counts) | |
7484 | + vec_addr_offset); | |
a96d9b2e SDJ |
7485 | memset ((void *) vec_addr, 0, |
7486 | (iter + 1 - old_size) * sizeof (int)); | |
7487 | } | |
fa3064dd YQ |
7488 | elem = VEC_index (int, inf_data->syscalls_counts, iter); |
7489 | VEC_replace (int, inf_data->syscalls_counts, iter, ++elem); | |
a96d9b2e SDJ |
7490 | } |
7491 | } | |
7492 | ||
77b06cd7 | 7493 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), |
fa3064dd YQ |
7494 | inf_data->total_syscalls_count != 0, |
7495 | inf_data->any_syscall_count, | |
7496 | VEC_length (int, | |
7497 | inf_data->syscalls_counts), | |
7498 | VEC_address (int, | |
7499 | inf_data->syscalls_counts)); | |
a96d9b2e SDJ |
7500 | } |
7501 | ||
7502 | /* Implement the "remove" breakpoint_ops method for syscall | |
7503 | catchpoints. */ | |
7504 | ||
7505 | static int | |
77b06cd7 | 7506 | remove_catch_syscall (struct bp_location *bl) |
a96d9b2e | 7507 | { |
be5c67c1 | 7508 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; |
a96d9b2e | 7509 | struct inferior *inf = current_inferior (); |
fa3064dd YQ |
7510 | struct catch_syscall_inferior_data *inf_data |
7511 | = get_catch_syscall_inferior_data (inf); | |
a96d9b2e | 7512 | |
fa3064dd | 7513 | --inf_data->total_syscalls_count; |
be5c67c1 | 7514 | if (!c->syscalls_to_be_caught) |
fa3064dd | 7515 | --inf_data->any_syscall_count; |
a96d9b2e SDJ |
7516 | else |
7517 | { | |
7518 | int i, iter; | |
cc59ec59 | 7519 | |
a96d9b2e | 7520 | for (i = 0; |
be5c67c1 | 7521 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
7522 | i++) |
7523 | { | |
7524 | int elem; | |
fa3064dd | 7525 | if (iter >= VEC_length (int, inf_data->syscalls_counts)) |
a96d9b2e SDJ |
7526 | /* Shouldn't happen. */ |
7527 | continue; | |
fa3064dd YQ |
7528 | elem = VEC_index (int, inf_data->syscalls_counts, iter); |
7529 | VEC_replace (int, inf_data->syscalls_counts, iter, --elem); | |
a96d9b2e SDJ |
7530 | } |
7531 | } | |
7532 | ||
7533 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
fa3064dd YQ |
7534 | inf_data->total_syscalls_count != 0, |
7535 | inf_data->any_syscall_count, | |
7536 | VEC_length (int, | |
7537 | inf_data->syscalls_counts), | |
3e43a32a | 7538 | VEC_address (int, |
fa3064dd | 7539 | inf_data->syscalls_counts)); |
a96d9b2e SDJ |
7540 | } |
7541 | ||
7542 | /* Implement the "breakpoint_hit" breakpoint_ops method for syscall | |
7543 | catchpoints. */ | |
7544 | ||
7545 | static int | |
f1310107 | 7546 | breakpoint_hit_catch_syscall (const struct bp_location *bl, |
09ac7c10 TT |
7547 | struct address_space *aspace, CORE_ADDR bp_addr, |
7548 | const struct target_waitstatus *ws) | |
a96d9b2e | 7549 | { |
4a64f543 MS |
7550 | /* We must check if we are catching specific syscalls in this |
7551 | breakpoint. If we are, then we must guarantee that the called | |
7552 | syscall is the same syscall we are catching. */ | |
a96d9b2e | 7553 | int syscall_number = 0; |
be5c67c1 PA |
7554 | const struct syscall_catchpoint *c |
7555 | = (const struct syscall_catchpoint *) bl->owner; | |
a96d9b2e | 7556 | |
f90263c1 TT |
7557 | if (ws->kind != TARGET_WAITKIND_SYSCALL_ENTRY |
7558 | && ws->kind != TARGET_WAITKIND_SYSCALL_RETURN) | |
a96d9b2e SDJ |
7559 | return 0; |
7560 | ||
f90263c1 TT |
7561 | syscall_number = ws->value.syscall_number; |
7562 | ||
a96d9b2e | 7563 | /* Now, checking if the syscall is the same. */ |
be5c67c1 | 7564 | if (c->syscalls_to_be_caught) |
a96d9b2e SDJ |
7565 | { |
7566 | int i, iter; | |
cc59ec59 | 7567 | |
a96d9b2e | 7568 | for (i = 0; |
be5c67c1 | 7569 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
7570 | i++) |
7571 | if (syscall_number == iter) | |
7572 | break; | |
7573 | /* Not the same. */ | |
7574 | if (!iter) | |
7575 | return 0; | |
7576 | } | |
7577 | ||
7578 | return 1; | |
7579 | } | |
7580 | ||
7581 | /* Implement the "print_it" breakpoint_ops method for syscall | |
7582 | catchpoints. */ | |
7583 | ||
7584 | static enum print_stop_action | |
348d480f | 7585 | print_it_catch_syscall (bpstat bs) |
a96d9b2e | 7586 | { |
36dfb11c | 7587 | struct ui_out *uiout = current_uiout; |
348d480f | 7588 | struct breakpoint *b = bs->breakpoint_at; |
a96d9b2e SDJ |
7589 | /* These are needed because we want to know in which state a |
7590 | syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY | |
7591 | or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we | |
7592 | must print "called syscall" or "returned from syscall". */ | |
7593 | ptid_t ptid; | |
7594 | struct target_waitstatus last; | |
7595 | struct syscall s; | |
a96d9b2e SDJ |
7596 | char *syscall_id; |
7597 | ||
7598 | get_last_target_status (&ptid, &last); | |
7599 | ||
7600 | get_syscall_by_number (last.value.syscall_number, &s); | |
7601 | ||
7602 | annotate_catchpoint (b->number); | |
7603 | ||
36dfb11c TT |
7604 | if (b->disposition == disp_del) |
7605 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
a96d9b2e | 7606 | else |
36dfb11c TT |
7607 | ui_out_text (uiout, "\nCatchpoint "); |
7608 | if (ui_out_is_mi_like_p (uiout)) | |
7609 | { | |
7610 | ui_out_field_string (uiout, "reason", | |
7611 | async_reason_lookup (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY | |
7612 | ? EXEC_ASYNC_SYSCALL_ENTRY | |
7613 | : EXEC_ASYNC_SYSCALL_RETURN)); | |
7614 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
7615 | } | |
7616 | ui_out_field_int (uiout, "bkptno", b->number); | |
a96d9b2e SDJ |
7617 | |
7618 | if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) | |
36dfb11c TT |
7619 | ui_out_text (uiout, " (call to syscall "); |
7620 | else | |
7621 | ui_out_text (uiout, " (returned from syscall "); | |
a96d9b2e | 7622 | |
36dfb11c TT |
7623 | if (s.name == NULL || ui_out_is_mi_like_p (uiout)) |
7624 | ui_out_field_int (uiout, "syscall-number", last.value.syscall_number); | |
7625 | if (s.name != NULL) | |
7626 | ui_out_field_string (uiout, "syscall-name", s.name); | |
7627 | ||
7628 | ui_out_text (uiout, "), "); | |
a96d9b2e SDJ |
7629 | |
7630 | return PRINT_SRC_AND_LOC; | |
7631 | } | |
7632 | ||
7633 | /* Implement the "print_one" breakpoint_ops method for syscall | |
7634 | catchpoints. */ | |
7635 | ||
7636 | static void | |
7637 | print_one_catch_syscall (struct breakpoint *b, | |
f1310107 | 7638 | struct bp_location **last_loc) |
a96d9b2e | 7639 | { |
be5c67c1 | 7640 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
a96d9b2e | 7641 | struct value_print_options opts; |
79a45e25 | 7642 | struct ui_out *uiout = current_uiout; |
a96d9b2e SDJ |
7643 | |
7644 | get_user_print_options (&opts); | |
4a64f543 MS |
7645 | /* Field 4, the address, is omitted (which makes the columns not |
7646 | line up too nicely with the headers, but the effect is relatively | |
7647 | readable). */ | |
a96d9b2e SDJ |
7648 | if (opts.addressprint) |
7649 | ui_out_field_skip (uiout, "addr"); | |
7650 | annotate_field (5); | |
7651 | ||
be5c67c1 PA |
7652 | if (c->syscalls_to_be_caught |
7653 | && VEC_length (int, c->syscalls_to_be_caught) > 1) | |
a96d9b2e SDJ |
7654 | ui_out_text (uiout, "syscalls \""); |
7655 | else | |
7656 | ui_out_text (uiout, "syscall \""); | |
7657 | ||
be5c67c1 | 7658 | if (c->syscalls_to_be_caught) |
a96d9b2e SDJ |
7659 | { |
7660 | int i, iter; | |
7661 | char *text = xstrprintf ("%s", ""); | |
cc59ec59 | 7662 | |
a96d9b2e | 7663 | for (i = 0; |
be5c67c1 | 7664 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
7665 | i++) |
7666 | { | |
7667 | char *x = text; | |
7668 | struct syscall s; | |
7669 | get_syscall_by_number (iter, &s); | |
7670 | ||
7671 | if (s.name != NULL) | |
7672 | text = xstrprintf ("%s%s, ", text, s.name); | |
7673 | else | |
7674 | text = xstrprintf ("%s%d, ", text, iter); | |
7675 | ||
7676 | /* We have to xfree the last 'text' (now stored at 'x') | |
e5dd4106 | 7677 | because xstrprintf dynamically allocates new space for it |
a96d9b2e SDJ |
7678 | on every call. */ |
7679 | xfree (x); | |
7680 | } | |
7681 | /* Remove the last comma. */ | |
7682 | text[strlen (text) - 2] = '\0'; | |
7683 | ui_out_field_string (uiout, "what", text); | |
7684 | } | |
7685 | else | |
7686 | ui_out_field_string (uiout, "what", "<any syscall>"); | |
7687 | ui_out_text (uiout, "\" "); | |
7688 | } | |
7689 | ||
7690 | /* Implement the "print_mention" breakpoint_ops method for syscall | |
7691 | catchpoints. */ | |
7692 | ||
7693 | static void | |
7694 | print_mention_catch_syscall (struct breakpoint *b) | |
7695 | { | |
be5c67c1 PA |
7696 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
7697 | ||
7698 | if (c->syscalls_to_be_caught) | |
a96d9b2e SDJ |
7699 | { |
7700 | int i, iter; | |
7701 | ||
be5c67c1 | 7702 | if (VEC_length (int, c->syscalls_to_be_caught) > 1) |
a96d9b2e SDJ |
7703 | printf_filtered (_("Catchpoint %d (syscalls"), b->number); |
7704 | else | |
7705 | printf_filtered (_("Catchpoint %d (syscall"), b->number); | |
7706 | ||
7707 | for (i = 0; | |
be5c67c1 | 7708 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
7709 | i++) |
7710 | { | |
7711 | struct syscall s; | |
7712 | get_syscall_by_number (iter, &s); | |
7713 | ||
7714 | if (s.name) | |
7715 | printf_filtered (" '%s' [%d]", s.name, s.number); | |
7716 | else | |
7717 | printf_filtered (" %d", s.number); | |
7718 | } | |
7719 | printf_filtered (")"); | |
7720 | } | |
7721 | else | |
7722 | printf_filtered (_("Catchpoint %d (any syscall)"), | |
7723 | b->number); | |
7724 | } | |
7725 | ||
6149aea9 PA |
7726 | /* Implement the "print_recreate" breakpoint_ops method for syscall |
7727 | catchpoints. */ | |
7728 | ||
7729 | static void | |
7730 | print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp) | |
7731 | { | |
be5c67c1 PA |
7732 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
7733 | ||
6149aea9 PA |
7734 | fprintf_unfiltered (fp, "catch syscall"); |
7735 | ||
be5c67c1 | 7736 | if (c->syscalls_to_be_caught) |
6149aea9 PA |
7737 | { |
7738 | int i, iter; | |
7739 | ||
7740 | for (i = 0; | |
be5c67c1 | 7741 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
6149aea9 PA |
7742 | i++) |
7743 | { | |
7744 | struct syscall s; | |
7745 | ||
7746 | get_syscall_by_number (iter, &s); | |
7747 | if (s.name) | |
7748 | fprintf_unfiltered (fp, " %s", s.name); | |
7749 | else | |
7750 | fprintf_unfiltered (fp, " %d", s.number); | |
7751 | } | |
7752 | } | |
d9b3f62e | 7753 | print_recreate_thread (b, fp); |
6149aea9 PA |
7754 | } |
7755 | ||
a96d9b2e SDJ |
7756 | /* The breakpoint_ops structure to be used in syscall catchpoints. */ |
7757 | ||
2060206e | 7758 | static struct breakpoint_ops catch_syscall_breakpoint_ops; |
a96d9b2e SDJ |
7759 | |
7760 | /* Returns non-zero if 'b' is a syscall catchpoint. */ | |
7761 | ||
7762 | static int | |
7763 | syscall_catchpoint_p (struct breakpoint *b) | |
7764 | { | |
7765 | return (b->ops == &catch_syscall_breakpoint_ops); | |
7766 | } | |
7767 | ||
346774a9 PA |
7768 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
7769 | is non-zero, then make the breakpoint temporary. If COND_STRING is | |
7770 | not NULL, then store it in the breakpoint. OPS, if not NULL, is | |
7771 | the breakpoint_ops structure associated to the catchpoint. */ | |
ce78b96d | 7772 | |
346774a9 PA |
7773 | static void |
7774 | init_catchpoint (struct breakpoint *b, | |
7775 | struct gdbarch *gdbarch, int tempflag, | |
7776 | char *cond_string, | |
c0a91b2b | 7777 | const struct breakpoint_ops *ops) |
c906108c | 7778 | { |
c5aa993b | 7779 | struct symtab_and_line sal; |
346774a9 | 7780 | |
fe39c653 | 7781 | init_sal (&sal); |
6c95b8df | 7782 | sal.pspace = current_program_space; |
c5aa993b | 7783 | |
28010a5d | 7784 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 7785 | |
1b36a34b | 7786 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
b5de0fa7 | 7787 | b->disposition = tempflag ? disp_del : disp_donttouch; |
346774a9 PA |
7788 | } |
7789 | ||
28010a5d | 7790 | void |
3ea46bff | 7791 | install_breakpoint (int internal, struct breakpoint *b, int update_gll) |
c56053d2 PA |
7792 | { |
7793 | add_to_breakpoint_chain (b); | |
3a5c3e22 PA |
7794 | set_breakpoint_number (internal, b); |
7795 | if (!internal) | |
7796 | mention (b); | |
c56053d2 | 7797 | observer_notify_breakpoint_created (b); |
3ea46bff YQ |
7798 | |
7799 | if (update_gll) | |
7800 | update_global_location_list (1); | |
c56053d2 PA |
7801 | } |
7802 | ||
9b70b993 | 7803 | static void |
a6d9a66e UW |
7804 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
7805 | int tempflag, char *cond_string, | |
c0a91b2b | 7806 | const struct breakpoint_ops *ops) |
c906108c | 7807 | { |
e29a4733 | 7808 | struct fork_catchpoint *c = XNEW (struct fork_catchpoint); |
ce78b96d | 7809 | |
e29a4733 PA |
7810 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops); |
7811 | ||
7812 | c->forked_inferior_pid = null_ptid; | |
7813 | ||
3ea46bff | 7814 | install_breakpoint (0, &c->base, 1); |
c906108c SS |
7815 | } |
7816 | ||
fe798b75 JB |
7817 | /* Exec catchpoints. */ |
7818 | ||
b4d90040 PA |
7819 | /* An instance of this type is used to represent an exec catchpoint. |
7820 | It includes a "struct breakpoint" as a kind of base class; users | |
7821 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
7822 | really of this type iff its ops pointer points to | |
7823 | CATCH_EXEC_BREAKPOINT_OPS. */ | |
7824 | ||
7825 | struct exec_catchpoint | |
7826 | { | |
7827 | /* The base class. */ | |
7828 | struct breakpoint base; | |
7829 | ||
7830 | /* Filename of a program whose exec triggered this catchpoint. | |
7831 | This field is only valid immediately after this catchpoint has | |
7832 | triggered. */ | |
7833 | char *exec_pathname; | |
7834 | }; | |
7835 | ||
7836 | /* Implement the "dtor" breakpoint_ops method for exec | |
7837 | catchpoints. */ | |
7838 | ||
7839 | static void | |
7840 | dtor_catch_exec (struct breakpoint *b) | |
7841 | { | |
7842 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; | |
7843 | ||
7844 | xfree (c->exec_pathname); | |
348d480f | 7845 | |
2060206e | 7846 | base_breakpoint_ops.dtor (b); |
b4d90040 PA |
7847 | } |
7848 | ||
77b06cd7 TJB |
7849 | static int |
7850 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 7851 | { |
77b06cd7 | 7852 | return target_insert_exec_catchpoint (PIDGET (inferior_ptid)); |
fe798b75 | 7853 | } |
c906108c | 7854 | |
fe798b75 | 7855 | static int |
77b06cd7 | 7856 | remove_catch_exec (struct bp_location *bl) |
fe798b75 JB |
7857 | { |
7858 | return target_remove_exec_catchpoint (PIDGET (inferior_ptid)); | |
7859 | } | |
c906108c | 7860 | |
fe798b75 | 7861 | static int |
f1310107 | 7862 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
09ac7c10 TT |
7863 | struct address_space *aspace, CORE_ADDR bp_addr, |
7864 | const struct target_waitstatus *ws) | |
fe798b75 | 7865 | { |
b4d90040 PA |
7866 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
7867 | ||
f90263c1 TT |
7868 | if (ws->kind != TARGET_WAITKIND_EXECD) |
7869 | return 0; | |
7870 | ||
7871 | c->exec_pathname = xstrdup (ws->value.execd_pathname); | |
7872 | return 1; | |
fe798b75 | 7873 | } |
c906108c | 7874 | |
fe798b75 | 7875 | static enum print_stop_action |
348d480f | 7876 | print_it_catch_exec (bpstat bs) |
fe798b75 | 7877 | { |
36dfb11c | 7878 | struct ui_out *uiout = current_uiout; |
348d480f | 7879 | struct breakpoint *b = bs->breakpoint_at; |
b4d90040 PA |
7880 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
7881 | ||
fe798b75 | 7882 | annotate_catchpoint (b->number); |
36dfb11c TT |
7883 | if (b->disposition == disp_del) |
7884 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
7885 | else | |
7886 | ui_out_text (uiout, "\nCatchpoint "); | |
7887 | if (ui_out_is_mi_like_p (uiout)) | |
7888 | { | |
7889 | ui_out_field_string (uiout, "reason", | |
7890 | async_reason_lookup (EXEC_ASYNC_EXEC)); | |
7891 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
7892 | } | |
7893 | ui_out_field_int (uiout, "bkptno", b->number); | |
7894 | ui_out_text (uiout, " (exec'd "); | |
7895 | ui_out_field_string (uiout, "new-exec", c->exec_pathname); | |
7896 | ui_out_text (uiout, "), "); | |
7897 | ||
fe798b75 | 7898 | return PRINT_SRC_AND_LOC; |
c906108c SS |
7899 | } |
7900 | ||
fe798b75 | 7901 | static void |
a6d9a66e | 7902 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 | 7903 | { |
b4d90040 | 7904 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
fe798b75 | 7905 | struct value_print_options opts; |
79a45e25 | 7906 | struct ui_out *uiout = current_uiout; |
fe798b75 JB |
7907 | |
7908 | get_user_print_options (&opts); | |
7909 | ||
7910 | /* Field 4, the address, is omitted (which makes the columns | |
7911 | not line up too nicely with the headers, but the effect | |
7912 | is relatively readable). */ | |
7913 | if (opts.addressprint) | |
7914 | ui_out_field_skip (uiout, "addr"); | |
7915 | annotate_field (5); | |
7916 | ui_out_text (uiout, "exec"); | |
b4d90040 | 7917 | if (c->exec_pathname != NULL) |
fe798b75 JB |
7918 | { |
7919 | ui_out_text (uiout, ", program \""); | |
b4d90040 | 7920 | ui_out_field_string (uiout, "what", c->exec_pathname); |
fe798b75 JB |
7921 | ui_out_text (uiout, "\" "); |
7922 | } | |
7923 | } | |
7924 | ||
7925 | static void | |
7926 | print_mention_catch_exec (struct breakpoint *b) | |
7927 | { | |
7928 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
7929 | } | |
7930 | ||
6149aea9 PA |
7931 | /* Implement the "print_recreate" breakpoint_ops method for exec |
7932 | catchpoints. */ | |
7933 | ||
7934 | static void | |
7935 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
7936 | { | |
7937 | fprintf_unfiltered (fp, "catch exec"); | |
d9b3f62e | 7938 | print_recreate_thread (b, fp); |
6149aea9 PA |
7939 | } |
7940 | ||
2060206e | 7941 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
fe798b75 | 7942 | |
a96d9b2e SDJ |
7943 | static void |
7944 | create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, | |
c0a91b2b | 7945 | const struct breakpoint_ops *ops) |
a96d9b2e | 7946 | { |
be5c67c1 | 7947 | struct syscall_catchpoint *c; |
a96d9b2e | 7948 | struct gdbarch *gdbarch = get_current_arch (); |
a96d9b2e | 7949 | |
be5c67c1 PA |
7950 | c = XNEW (struct syscall_catchpoint); |
7951 | init_catchpoint (&c->base, gdbarch, tempflag, NULL, ops); | |
7952 | c->syscalls_to_be_caught = filter; | |
a96d9b2e | 7953 | |
3ea46bff | 7954 | install_breakpoint (0, &c->base, 1); |
a96d9b2e SDJ |
7955 | } |
7956 | ||
c906108c | 7957 | static int |
fba45db2 | 7958 | hw_breakpoint_used_count (void) |
c906108c | 7959 | { |
c906108c | 7960 | int i = 0; |
f1310107 TJB |
7961 | struct breakpoint *b; |
7962 | struct bp_location *bl; | |
c906108c SS |
7963 | |
7964 | ALL_BREAKPOINTS (b) | |
c5aa993b | 7965 | { |
d6b74ac4 | 7966 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
7967 | for (bl = b->loc; bl; bl = bl->next) |
7968 | { | |
7969 | /* Special types of hardware breakpoints may use more than | |
7970 | one register. */ | |
348d480f | 7971 | i += b->ops->resources_needed (bl); |
f1310107 | 7972 | } |
c5aa993b | 7973 | } |
c906108c SS |
7974 | |
7975 | return i; | |
7976 | } | |
7977 | ||
a1398e0c PA |
7978 | /* Returns the resources B would use if it were a hardware |
7979 | watchpoint. */ | |
7980 | ||
c906108c | 7981 | static int |
a1398e0c | 7982 | hw_watchpoint_use_count (struct breakpoint *b) |
c906108c | 7983 | { |
c906108c | 7984 | int i = 0; |
e09342b5 | 7985 | struct bp_location *bl; |
c906108c | 7986 | |
a1398e0c PA |
7987 | if (!breakpoint_enabled (b)) |
7988 | return 0; | |
7989 | ||
7990 | for (bl = b->loc; bl; bl = bl->next) | |
7991 | { | |
7992 | /* Special types of hardware watchpoints may use more than | |
7993 | one register. */ | |
7994 | i += b->ops->resources_needed (bl); | |
7995 | } | |
7996 | ||
7997 | return i; | |
7998 | } | |
7999 | ||
8000 | /* Returns the sum the used resources of all hardware watchpoints of | |
8001 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED | |
8002 | the sum of the used resources of all hardware watchpoints of other | |
8003 | types _not_ TYPE. */ | |
8004 | ||
8005 | static int | |
8006 | hw_watchpoint_used_count_others (struct breakpoint *except, | |
8007 | enum bptype type, int *other_type_used) | |
8008 | { | |
8009 | int i = 0; | |
8010 | struct breakpoint *b; | |
8011 | ||
c906108c SS |
8012 | *other_type_used = 0; |
8013 | ALL_BREAKPOINTS (b) | |
e09342b5 | 8014 | { |
a1398e0c PA |
8015 | if (b == except) |
8016 | continue; | |
e09342b5 TJB |
8017 | if (!breakpoint_enabled (b)) |
8018 | continue; | |
8019 | ||
a1398e0c PA |
8020 | if (b->type == type) |
8021 | i += hw_watchpoint_use_count (b); | |
8022 | else if (is_hardware_watchpoint (b)) | |
8023 | *other_type_used = 1; | |
e09342b5 TJB |
8024 | } |
8025 | ||
c906108c SS |
8026 | return i; |
8027 | } | |
8028 | ||
c906108c | 8029 | void |
fba45db2 | 8030 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 8031 | { |
c5aa993b | 8032 | struct breakpoint *b; |
c906108c SS |
8033 | |
8034 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8035 | { |
cc60f2e3 | 8036 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 8037 | { |
b5de0fa7 | 8038 | b->enable_state = bp_call_disabled; |
b60e7edf | 8039 | update_global_location_list (0); |
c5aa993b JM |
8040 | } |
8041 | } | |
c906108c SS |
8042 | } |
8043 | ||
8044 | void | |
fba45db2 | 8045 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 8046 | { |
c5aa993b | 8047 | struct breakpoint *b; |
c906108c SS |
8048 | |
8049 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8050 | { |
cc60f2e3 | 8051 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 8052 | { |
b5de0fa7 | 8053 | b->enable_state = bp_enabled; |
b60e7edf | 8054 | update_global_location_list (1); |
c5aa993b JM |
8055 | } |
8056 | } | |
c906108c SS |
8057 | } |
8058 | ||
8bea4e01 UW |
8059 | void |
8060 | disable_breakpoints_before_startup (void) | |
8061 | { | |
6c95b8df | 8062 | current_program_space->executing_startup = 1; |
f8eba3c6 | 8063 | update_global_location_list (0); |
8bea4e01 UW |
8064 | } |
8065 | ||
8066 | void | |
8067 | enable_breakpoints_after_startup (void) | |
8068 | { | |
6c95b8df | 8069 | current_program_space->executing_startup = 0; |
f8eba3c6 | 8070 | breakpoint_re_set (); |
8bea4e01 UW |
8071 | } |
8072 | ||
c906108c SS |
8073 | |
8074 | /* Set a breakpoint that will evaporate an end of command | |
8075 | at address specified by SAL. | |
8076 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
8077 | ||
8078 | struct breakpoint * | |
a6d9a66e UW |
8079 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
8080 | struct frame_id frame_id, enum bptype type) | |
c906108c | 8081 | { |
52f0bd74 | 8082 | struct breakpoint *b; |
edb3359d DJ |
8083 | |
8084 | /* If FRAME_ID is valid, it should be a real frame, not an inlined | |
8085 | one. */ | |
8086 | gdb_assert (!frame_id_inlined_p (frame_id)); | |
8087 | ||
06edf0c0 | 8088 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
8089 | b->enable_state = bp_enabled; |
8090 | b->disposition = disp_donttouch; | |
818dd999 | 8091 | b->frame_id = frame_id; |
c906108c | 8092 | |
4a64f543 MS |
8093 | /* If we're debugging a multi-threaded program, then we want |
8094 | momentary breakpoints to be active in only a single thread of | |
8095 | control. */ | |
39f77062 KB |
8096 | if (in_thread_list (inferior_ptid)) |
8097 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 8098 | |
b60e7edf | 8099 | update_global_location_list_nothrow (1); |
74960c60 | 8100 | |
c906108c SS |
8101 | return b; |
8102 | } | |
611c83ae | 8103 | |
06edf0c0 PA |
8104 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
8105 | The new breakpoint will have type TYPE, and use OPS as it | |
8106 | breakpoint_ops. */ | |
e58b0e63 | 8107 | |
06edf0c0 PA |
8108 | static struct breakpoint * |
8109 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
8110 | enum bptype type, | |
c0a91b2b | 8111 | const struct breakpoint_ops *ops) |
e58b0e63 PA |
8112 | { |
8113 | struct breakpoint *copy; | |
8114 | ||
06edf0c0 | 8115 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 8116 | copy->loc = allocate_bp_location (copy); |
0e30163f | 8117 | set_breakpoint_location_function (copy->loc, 1); |
e58b0e63 | 8118 | |
a6d9a66e | 8119 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
8120 | copy->loc->requested_address = orig->loc->requested_address; |
8121 | copy->loc->address = orig->loc->address; | |
8122 | copy->loc->section = orig->loc->section; | |
6c95b8df | 8123 | copy->loc->pspace = orig->loc->pspace; |
e58b0e63 | 8124 | |
f8eba3c6 TT |
8125 | if (orig->loc->source_file != NULL) |
8126 | copy->loc->source_file = xstrdup (orig->loc->source_file); | |
e58b0e63 | 8127 | |
f8eba3c6 | 8128 | copy->loc->line_number = orig->loc->line_number; |
e58b0e63 PA |
8129 | copy->frame_id = orig->frame_id; |
8130 | copy->thread = orig->thread; | |
6c95b8df | 8131 | copy->pspace = orig->pspace; |
e58b0e63 PA |
8132 | |
8133 | copy->enable_state = bp_enabled; | |
8134 | copy->disposition = disp_donttouch; | |
8135 | copy->number = internal_breakpoint_number--; | |
8136 | ||
8137 | update_global_location_list_nothrow (0); | |
8138 | return copy; | |
8139 | } | |
8140 | ||
06edf0c0 PA |
8141 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
8142 | ORIG is NULL. */ | |
8143 | ||
8144 | struct breakpoint * | |
8145 | clone_momentary_breakpoint (struct breakpoint *orig) | |
8146 | { | |
8147 | /* If there's nothing to clone, then return nothing. */ | |
8148 | if (orig == NULL) | |
8149 | return NULL; | |
8150 | ||
8151 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops); | |
8152 | } | |
8153 | ||
611c83ae | 8154 | struct breakpoint * |
a6d9a66e UW |
8155 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
8156 | enum bptype type) | |
611c83ae PA |
8157 | { |
8158 | struct symtab_and_line sal; | |
8159 | ||
8160 | sal = find_pc_line (pc, 0); | |
8161 | sal.pc = pc; | |
8162 | sal.section = find_pc_overlay (pc); | |
8163 | sal.explicit_pc = 1; | |
8164 | ||
a6d9a66e | 8165 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 8166 | } |
c906108c | 8167 | \f |
c5aa993b | 8168 | |
c906108c SS |
8169 | /* Tell the user we have just set a breakpoint B. */ |
8170 | ||
8171 | static void | |
fba45db2 | 8172 | mention (struct breakpoint *b) |
c906108c | 8173 | { |
348d480f | 8174 | b->ops->print_mention (b); |
79a45e25 | 8175 | if (ui_out_is_mi_like_p (current_uiout)) |
fb40c209 | 8176 | return; |
c906108c SS |
8177 | printf_filtered ("\n"); |
8178 | } | |
c906108c | 8179 | \f |
c5aa993b | 8180 | |
0d381245 | 8181 | static struct bp_location * |
39d61571 | 8182 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
8183 | const struct symtab_and_line *sal) |
8184 | { | |
8185 | struct bp_location *loc, **tmp; | |
3742cc8b YQ |
8186 | CORE_ADDR adjusted_address; |
8187 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); | |
8188 | ||
8189 | if (loc_gdbarch == NULL) | |
8190 | loc_gdbarch = b->gdbarch; | |
8191 | ||
8192 | /* Adjust the breakpoint's address prior to allocating a location. | |
8193 | Once we call allocate_bp_location(), that mostly uninitialized | |
8194 | location will be placed on the location chain. Adjustment of the | |
8195 | breakpoint may cause target_read_memory() to be called and we do | |
8196 | not want its scan of the location chain to find a breakpoint and | |
8197 | location that's only been partially initialized. */ | |
8198 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, | |
8199 | sal->pc, b->type); | |
0d381245 | 8200 | |
39d61571 | 8201 | loc = allocate_bp_location (b); |
0d381245 VP |
8202 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
8203 | ; | |
8204 | *tmp = loc; | |
3742cc8b | 8205 | |
0d381245 | 8206 | loc->requested_address = sal->pc; |
3742cc8b | 8207 | loc->address = adjusted_address; |
6c95b8df PA |
8208 | loc->pspace = sal->pspace; |
8209 | gdb_assert (loc->pspace != NULL); | |
0d381245 | 8210 | loc->section = sal->section; |
3742cc8b | 8211 | loc->gdbarch = loc_gdbarch; |
f8eba3c6 TT |
8212 | |
8213 | if (sal->symtab != NULL) | |
8214 | loc->source_file = xstrdup (sal->symtab->filename); | |
8215 | loc->line_number = sal->line; | |
8216 | ||
0e30163f JK |
8217 | set_breakpoint_location_function (loc, |
8218 | sal->explicit_pc || sal->explicit_line); | |
0d381245 VP |
8219 | return loc; |
8220 | } | |
514f746b AR |
8221 | \f |
8222 | ||
8223 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
8224 | return 0 otherwise. */ | |
8225 | ||
8226 | static int | |
8227 | bp_loc_is_permanent (struct bp_location *loc) | |
8228 | { | |
8229 | int len; | |
8230 | CORE_ADDR addr; | |
1afeeb75 | 8231 | const gdb_byte *bpoint; |
514f746b | 8232 | gdb_byte *target_mem; |
939c61fa JK |
8233 | struct cleanup *cleanup; |
8234 | int retval = 0; | |
514f746b AR |
8235 | |
8236 | gdb_assert (loc != NULL); | |
8237 | ||
8238 | addr = loc->address; | |
1afeeb75 | 8239 | bpoint = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 8240 | |
939c61fa | 8241 | /* Software breakpoints unsupported? */ |
1afeeb75 | 8242 | if (bpoint == NULL) |
939c61fa JK |
8243 | return 0; |
8244 | ||
514f746b AR |
8245 | target_mem = alloca (len); |
8246 | ||
939c61fa JK |
8247 | /* Enable the automatic memory restoration from breakpoints while |
8248 | we read the memory. Otherwise we could say about our temporary | |
8249 | breakpoints they are permanent. */ | |
6c95b8df PA |
8250 | cleanup = save_current_space_and_thread (); |
8251 | ||
8252 | switch_to_program_space_and_thread (loc->pspace); | |
8253 | make_show_memory_breakpoints_cleanup (0); | |
939c61fa | 8254 | |
514f746b | 8255 | if (target_read_memory (loc->address, target_mem, len) == 0 |
1afeeb75 | 8256 | && memcmp (target_mem, bpoint, len) == 0) |
939c61fa | 8257 | retval = 1; |
514f746b | 8258 | |
939c61fa JK |
8259 | do_cleanups (cleanup); |
8260 | ||
8261 | return retval; | |
514f746b AR |
8262 | } |
8263 | ||
8264 | ||
c3f6f71d | 8265 | |
018d34a4 VP |
8266 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
8267 | as textual description of the location, and COND_STRING | |
db107f19 | 8268 | as condition expression. */ |
018d34a4 VP |
8269 | |
8270 | static void | |
d9b3f62e PA |
8271 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
8272 | struct symtabs_and_lines sals, char *addr_string, | |
f8eba3c6 | 8273 | char *filter, char *cond_string, |
d9b3f62e PA |
8274 | enum bptype type, enum bpdisp disposition, |
8275 | int thread, int task, int ignore_count, | |
c0a91b2b | 8276 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
8277 | int enabled, int internal, unsigned flags, |
8278 | int display_canonical) | |
018d34a4 | 8279 | { |
0d381245 | 8280 | int i; |
018d34a4 VP |
8281 | |
8282 | if (type == bp_hardware_breakpoint) | |
8283 | { | |
fbbd034e AS |
8284 | int target_resources_ok; |
8285 | ||
8286 | i = hw_breakpoint_used_count (); | |
8287 | target_resources_ok = | |
8288 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
018d34a4 VP |
8289 | i + 1, 0); |
8290 | if (target_resources_ok == 0) | |
8291 | error (_("No hardware breakpoint support in the target.")); | |
8292 | else if (target_resources_ok < 0) | |
8293 | error (_("Hardware breakpoints used exceeds limit.")); | |
8294 | } | |
8295 | ||
6c95b8df PA |
8296 | gdb_assert (sals.nelts > 0); |
8297 | ||
0d381245 VP |
8298 | for (i = 0; i < sals.nelts; ++i) |
8299 | { | |
8300 | struct symtab_and_line sal = sals.sals[i]; | |
8301 | struct bp_location *loc; | |
8302 | ||
8303 | if (from_tty) | |
5af949e3 UW |
8304 | { |
8305 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
8306 | if (!loc_gdbarch) | |
8307 | loc_gdbarch = gdbarch; | |
8308 | ||
8309 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 8310 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 8311 | } |
0d381245 VP |
8312 | |
8313 | if (i == 0) | |
8314 | { | |
d9b3f62e | 8315 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 8316 | b->thread = thread; |
4a306c9a | 8317 | b->task = task; |
018d34a4 | 8318 | |
0d381245 VP |
8319 | b->cond_string = cond_string; |
8320 | b->ignore_count = ignore_count; | |
41447f92 | 8321 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 8322 | b->disposition = disposition; |
6c95b8df | 8323 | |
44f238bb PA |
8324 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
8325 | b->loc->inserted = 1; | |
8326 | ||
0fb4aa4b PA |
8327 | if (type == bp_static_tracepoint) |
8328 | { | |
d9b3f62e | 8329 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
8330 | struct static_tracepoint_marker marker; |
8331 | ||
983af33b | 8332 | if (strace_marker_p (b)) |
0fb4aa4b PA |
8333 | { |
8334 | /* We already know the marker exists, otherwise, we | |
8335 | wouldn't see a sal for it. */ | |
8336 | char *p = &addr_string[3]; | |
8337 | char *endp; | |
8338 | char *marker_str; | |
0fb4aa4b | 8339 | |
e9cafbcc | 8340 | p = skip_spaces (p); |
0fb4aa4b | 8341 | |
e9cafbcc | 8342 | endp = skip_to_space (p); |
0fb4aa4b PA |
8343 | |
8344 | marker_str = savestring (p, endp - p); | |
d9b3f62e | 8345 | t->static_trace_marker_id = marker_str; |
0fb4aa4b | 8346 | |
3e43a32a MS |
8347 | printf_filtered (_("Probed static tracepoint " |
8348 | "marker \"%s\"\n"), | |
d9b3f62e | 8349 | t->static_trace_marker_id); |
0fb4aa4b PA |
8350 | } |
8351 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
8352 | { | |
d9b3f62e | 8353 | t->static_trace_marker_id = xstrdup (marker.str_id); |
0fb4aa4b PA |
8354 | release_static_tracepoint_marker (&marker); |
8355 | ||
3e43a32a MS |
8356 | printf_filtered (_("Probed static tracepoint " |
8357 | "marker \"%s\"\n"), | |
d9b3f62e | 8358 | t->static_trace_marker_id); |
0fb4aa4b PA |
8359 | } |
8360 | else | |
3e43a32a MS |
8361 | warning (_("Couldn't determine the static " |
8362 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
8363 | } |
8364 | ||
0d381245 VP |
8365 | loc = b->loc; |
8366 | } | |
8367 | else | |
018d34a4 | 8368 | { |
39d61571 | 8369 | loc = add_location_to_breakpoint (b, &sal); |
44f238bb PA |
8370 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
8371 | loc->inserted = 1; | |
0d381245 VP |
8372 | } |
8373 | ||
514f746b AR |
8374 | if (bp_loc_is_permanent (loc)) |
8375 | make_breakpoint_permanent (b); | |
8376 | ||
0d381245 VP |
8377 | if (b->cond_string) |
8378 | { | |
8379 | char *arg = b->cond_string; | |
d32a6982 | 8380 | loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0); |
0d381245 | 8381 | if (*arg) |
db107f19 | 8382 | error (_("Garbage %s follows condition"), arg); |
018d34a4 | 8383 | } |
0d381245 | 8384 | } |
018d34a4 | 8385 | |
56435ebe | 8386 | b->display_canonical = display_canonical; |
018d34a4 VP |
8387 | if (addr_string) |
8388 | b->addr_string = addr_string; | |
8389 | else | |
8390 | /* addr_string has to be used or breakpoint_re_set will delete | |
8391 | me. */ | |
5af949e3 UW |
8392 | b->addr_string |
8393 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
f8eba3c6 | 8394 | b->filter = filter; |
d9b3f62e | 8395 | } |
018d34a4 | 8396 | |
d9b3f62e PA |
8397 | static void |
8398 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
8399 | struct symtabs_and_lines sals, char *addr_string, | |
f8eba3c6 | 8400 | char *filter, char *cond_string, |
d9b3f62e PA |
8401 | enum bptype type, enum bpdisp disposition, |
8402 | int thread, int task, int ignore_count, | |
c0a91b2b | 8403 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
8404 | int enabled, int internal, unsigned flags, |
8405 | int display_canonical) | |
d9b3f62e PA |
8406 | { |
8407 | struct breakpoint *b; | |
8408 | struct cleanup *old_chain; | |
8409 | ||
8410 | if (is_tracepoint_type (type)) | |
8411 | { | |
8412 | struct tracepoint *t; | |
8413 | ||
8414 | t = XCNEW (struct tracepoint); | |
8415 | b = &t->base; | |
8416 | } | |
8417 | else | |
8418 | b = XNEW (struct breakpoint); | |
8419 | ||
8420 | old_chain = make_cleanup (xfree, b); | |
8421 | ||
8422 | init_breakpoint_sal (b, gdbarch, | |
8423 | sals, addr_string, | |
f8eba3c6 | 8424 | filter, cond_string, |
d9b3f62e PA |
8425 | type, disposition, |
8426 | thread, task, ignore_count, | |
8427 | ops, from_tty, | |
44f238bb PA |
8428 | enabled, internal, flags, |
8429 | display_canonical); | |
d9b3f62e PA |
8430 | discard_cleanups (old_chain); |
8431 | ||
3ea46bff | 8432 | install_breakpoint (internal, b, 0); |
018d34a4 VP |
8433 | } |
8434 | ||
8435 | /* Add SALS.nelts breakpoints to the breakpoint table. For each | |
8436 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
8437 | value. COND_STRING, if not NULL, specified the condition to be | |
8438 | used for all breakpoints. Essentially the only case where | |
8439 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
8440 | function. In that case, it's still not possible to specify | |
8441 | separate conditions for different overloaded functions, so | |
8442 | we take just a single condition string. | |
8443 | ||
c3f6f71d | 8444 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 8445 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
8446 | array contents). If the function fails (error() is called), the |
8447 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 8448 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
8449 | |
8450 | static void | |
8cdf0e15 | 8451 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 | 8452 | struct linespec_result *canonical, |
8cdf0e15 VP |
8453 | char *cond_string, |
8454 | enum bptype type, enum bpdisp disposition, | |
8455 | int thread, int task, int ignore_count, | |
c0a91b2b | 8456 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb | 8457 | int enabled, int internal, unsigned flags) |
c906108c | 8458 | { |
018d34a4 | 8459 | int i; |
f8eba3c6 | 8460 | struct linespec_sals *lsal; |
cc59ec59 | 8461 | |
f8eba3c6 TT |
8462 | if (canonical->pre_expanded) |
8463 | gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1); | |
8464 | ||
8465 | for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i) | |
c3f6f71d | 8466 | { |
f8eba3c6 TT |
8467 | /* Note that 'addr_string' can be NULL in the case of a plain |
8468 | 'break', without arguments. */ | |
8469 | char *addr_string = (canonical->addr_string | |
8470 | ? xstrdup (canonical->addr_string) | |
8471 | : NULL); | |
8472 | char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL; | |
8473 | struct cleanup *inner = make_cleanup (xfree, addr_string); | |
0d381245 | 8474 | |
f8eba3c6 TT |
8475 | make_cleanup (xfree, filter_string); |
8476 | create_breakpoint_sal (gdbarch, lsal->sals, | |
8477 | addr_string, | |
8478 | filter_string, | |
8cdf0e15 | 8479 | cond_string, type, disposition, |
84f4c1fe | 8480 | thread, task, ignore_count, ops, |
44f238bb | 8481 | from_tty, enabled, internal, flags, |
56435ebe | 8482 | canonical->special_display); |
f8eba3c6 | 8483 | discard_cleanups (inner); |
c3f6f71d | 8484 | } |
c3f6f71d | 8485 | } |
c906108c | 8486 | |
9998af43 | 8487 | /* Parse ADDRESS which is assumed to be a SAL specification possibly |
c3f6f71d | 8488 | followed by conditionals. On return, SALS contains an array of SAL |
4a64f543 | 8489 | addresses found. ADDR_STRING contains a vector of (canonical) |
9998af43 TJB |
8490 | address strings. ADDRESS points to the end of the SAL. |
8491 | ||
8492 | The array and the line spec strings are allocated on the heap, it is | |
8493 | the caller's responsibility to free them. */ | |
c906108c | 8494 | |
b9362cc7 | 8495 | static void |
c3f6f71d | 8496 | parse_breakpoint_sals (char **address, |
58438ac1 | 8497 | struct linespec_result *canonical) |
c3f6f71d JM |
8498 | { |
8499 | char *addr_start = *address; | |
cc59ec59 | 8500 | |
c3f6f71d | 8501 | /* If no arg given, or if first arg is 'if ', use the default |
4a64f543 | 8502 | breakpoint. */ |
c3f6f71d JM |
8503 | if ((*address) == NULL |
8504 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c | 8505 | { |
1bfeeb0f JL |
8506 | /* The last displayed codepoint, if it's valid, is our default breakpoint |
8507 | address. */ | |
8508 | if (last_displayed_sal_is_valid ()) | |
c906108c | 8509 | { |
f8eba3c6 | 8510 | struct linespec_sals lsal; |
c3f6f71d | 8511 | struct symtab_and_line sal; |
cc59ec59 | 8512 | |
4a64f543 | 8513 | init_sal (&sal); /* Initialize to zeroes. */ |
f8eba3c6 | 8514 | lsal.sals.sals = (struct symtab_and_line *) |
c906108c | 8515 | xmalloc (sizeof (struct symtab_and_line)); |
1bfeeb0f JL |
8516 | |
8517 | /* Set sal's pspace, pc, symtab, and line to the values | |
8518 | corresponding to the last call to print_frame_info. */ | |
8519 | get_last_displayed_sal (&sal); | |
8520 | sal.section = find_pc_overlay (sal.pc); | |
00903456 | 8521 | |
4a64f543 | 8522 | /* "break" without arguments is equivalent to "break *PC" |
1bfeeb0f JL |
8523 | where PC is the last displayed codepoint's address. So |
8524 | make sure to set sal.explicit_pc to prevent GDB from | |
8525 | trying to expand the list of sals to include all other | |
8526 | instances with the same symtab and line. */ | |
00903456 JK |
8527 | sal.explicit_pc = 1; |
8528 | ||
f8eba3c6 TT |
8529 | lsal.sals.sals[0] = sal; |
8530 | lsal.sals.nelts = 1; | |
8531 | lsal.canonical = NULL; | |
8532 | ||
8533 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
c906108c SS |
8534 | } |
8535 | else | |
8a3fe4f8 | 8536 | error (_("No default breakpoint address now.")); |
c906108c SS |
8537 | } |
8538 | else | |
8539 | { | |
c906108c | 8540 | /* Force almost all breakpoints to be in terms of the |
4a64f543 MS |
8541 | current_source_symtab (which is decode_line_1's default). |
8542 | This should produce the results we want almost all of the | |
f8eba3c6 TT |
8543 | time while leaving default_breakpoint_* alone. */ |
8544 | if (last_displayed_sal_is_valid ()) | |
8545 | decode_line_full (address, DECODE_LINE_FUNFIRSTLINE, | |
8546 | get_last_displayed_symtab (), | |
8547 | get_last_displayed_line (), | |
8548 | canonical, NULL, NULL); | |
c906108c | 8549 | else |
f8eba3c6 TT |
8550 | decode_line_full (address, DECODE_LINE_FUNFIRSTLINE, |
8551 | (struct symtab *) NULL, 0, | |
8552 | canonical, NULL, NULL); | |
c906108c | 8553 | } |
c3f6f71d | 8554 | } |
c906108c | 8555 | |
c906108c | 8556 | |
c3f6f71d | 8557 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 8558 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 8559 | |
b9362cc7 | 8560 | static void |
23e7acfb | 8561 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
c3f6f71d JM |
8562 | { |
8563 | int i; | |
cc59ec59 | 8564 | |
c3f6f71d | 8565 | for (i = 0; i < sals->nelts; i++) |
ee53e872 | 8566 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
8567 | } |
8568 | ||
7a697b8d SS |
8569 | /* Fast tracepoints may have restrictions on valid locations. For |
8570 | instance, a fast tracepoint using a jump instead of a trap will | |
8571 | likely have to overwrite more bytes than a trap would, and so can | |
8572 | only be placed where the instruction is longer than the jump, or a | |
8573 | multi-instruction sequence does not have a jump into the middle of | |
8574 | it, etc. */ | |
8575 | ||
8576 | static void | |
8577 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
8578 | struct symtabs_and_lines *sals) | |
8579 | { | |
8580 | int i, rslt; | |
8581 | struct symtab_and_line *sal; | |
8582 | char *msg; | |
8583 | struct cleanup *old_chain; | |
8584 | ||
8585 | for (i = 0; i < sals->nelts; i++) | |
8586 | { | |
f8eba3c6 TT |
8587 | struct gdbarch *sarch; |
8588 | ||
7a697b8d SS |
8589 | sal = &sals->sals[i]; |
8590 | ||
f8eba3c6 TT |
8591 | sarch = get_sal_arch (*sal); |
8592 | /* We fall back to GDBARCH if there is no architecture | |
8593 | associated with SAL. */ | |
8594 | if (sarch == NULL) | |
8595 | sarch = gdbarch; | |
8596 | rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc, | |
7a697b8d SS |
8597 | NULL, &msg); |
8598 | old_chain = make_cleanup (xfree, msg); | |
8599 | ||
8600 | if (!rslt) | |
8601 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
f8eba3c6 | 8602 | paddress (sarch, sal->pc), (msg ? msg : "")); |
7a697b8d SS |
8603 | |
8604 | do_cleanups (old_chain); | |
8605 | } | |
8606 | } | |
8607 | ||
018d34a4 VP |
8608 | /* Given TOK, a string specification of condition and thread, as |
8609 | accepted by the 'break' command, extract the condition | |
8610 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 8611 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
8612 | If no condition is found, *COND_STRING is set to NULL. |
8613 | If no thread is found, *THREAD is set to -1. */ | |
8614 | static void | |
8615 | find_condition_and_thread (char *tok, CORE_ADDR pc, | |
4a306c9a | 8616 | char **cond_string, int *thread, int *task) |
018d34a4 VP |
8617 | { |
8618 | *cond_string = NULL; | |
8619 | *thread = -1; | |
8620 | while (tok && *tok) | |
8621 | { | |
8622 | char *end_tok; | |
8623 | int toklen; | |
8624 | char *cond_start = NULL; | |
8625 | char *cond_end = NULL; | |
cc59ec59 | 8626 | |
e9cafbcc | 8627 | tok = skip_spaces (tok); |
018d34a4 | 8628 | |
e9cafbcc | 8629 | end_tok = skip_to_space (tok); |
018d34a4 VP |
8630 | |
8631 | toklen = end_tok - tok; | |
8632 | ||
8633 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
8634 | { | |
f7545552 TT |
8635 | struct expression *expr; |
8636 | ||
018d34a4 | 8637 | tok = cond_start = end_tok + 1; |
f7545552 TT |
8638 | expr = parse_exp_1 (&tok, block_for_pc (pc), 0); |
8639 | xfree (expr); | |
018d34a4 VP |
8640 | cond_end = tok; |
8641 | *cond_string = savestring (cond_start, | |
8642 | cond_end - cond_start); | |
8643 | } | |
8644 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
8645 | { | |
8646 | char *tmptok; | |
8647 | ||
8648 | tok = end_tok + 1; | |
8649 | tmptok = tok; | |
8650 | *thread = strtol (tok, &tok, 0); | |
8651 | if (tok == tmptok) | |
8652 | error (_("Junk after thread keyword.")); | |
8653 | if (!valid_thread_id (*thread)) | |
8654 | error (_("Unknown thread %d."), *thread); | |
8655 | } | |
4a306c9a JB |
8656 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
8657 | { | |
8658 | char *tmptok; | |
8659 | ||
8660 | tok = end_tok + 1; | |
8661 | tmptok = tok; | |
8662 | *task = strtol (tok, &tok, 0); | |
8663 | if (tok == tmptok) | |
8664 | error (_("Junk after task keyword.")); | |
8665 | if (!valid_task_id (*task)) | |
b6199126 | 8666 | error (_("Unknown task %d."), *task); |
4a306c9a | 8667 | } |
018d34a4 VP |
8668 | else |
8669 | error (_("Junk at end of arguments.")); | |
8670 | } | |
8671 | } | |
8672 | ||
0fb4aa4b PA |
8673 | /* Decode a static tracepoint marker spec. */ |
8674 | ||
8675 | static struct symtabs_and_lines | |
8676 | decode_static_tracepoint_spec (char **arg_p) | |
8677 | { | |
8678 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
8679 | struct symtabs_and_lines sals; | |
8680 | struct symtab_and_line sal; | |
8681 | struct symbol *sym; | |
8682 | struct cleanup *old_chain; | |
8683 | char *p = &(*arg_p)[3]; | |
8684 | char *endp; | |
8685 | char *marker_str; | |
8686 | int i; | |
8687 | ||
e9cafbcc | 8688 | p = skip_spaces (p); |
0fb4aa4b | 8689 | |
e9cafbcc | 8690 | endp = skip_to_space (p); |
0fb4aa4b PA |
8691 | |
8692 | marker_str = savestring (p, endp - p); | |
8693 | old_chain = make_cleanup (xfree, marker_str); | |
8694 | ||
8695 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
8696 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
8697 | error (_("No known static tracepoint marker named %s"), marker_str); | |
8698 | ||
8699 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); | |
8700 | sals.sals = xmalloc (sizeof *sals.sals * sals.nelts); | |
8701 | ||
8702 | for (i = 0; i < sals.nelts; i++) | |
8703 | { | |
8704 | struct static_tracepoint_marker *marker; | |
8705 | ||
8706 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
8707 | ||
8708 | init_sal (&sals.sals[i]); | |
8709 | ||
8710 | sals.sals[i] = find_pc_line (marker->address, 0); | |
8711 | sals.sals[i].pc = marker->address; | |
8712 | ||
8713 | release_static_tracepoint_marker (marker); | |
8714 | } | |
8715 | ||
8716 | do_cleanups (old_chain); | |
8717 | ||
8718 | *arg_p = endp; | |
8719 | return sals; | |
8720 | } | |
8721 | ||
fd9b8c24 PA |
8722 | /* Set a breakpoint. This function is shared between CLI and MI |
8723 | functions for setting a breakpoint. This function has two major | |
8724 | modes of operations, selected by the PARSE_CONDITION_AND_THREAD | |
8725 | parameter. If non-zero, the function will parse arg, extracting | |
4a64f543 MS |
8726 | breakpoint location, address and thread. Otherwise, ARG is just |
8727 | the location of breakpoint, with condition and thread specified by | |
8728 | the COND_STRING and THREAD parameters. If INTERNAL is non-zero, | |
8729 | the breakpoint number will be allocated from the internal | |
8730 | breakpoint count. Returns true if any breakpoint was created; | |
8731 | false otherwise. */ | |
0101ce28 | 8732 | |
8cdf0e15 VP |
8733 | int |
8734 | create_breakpoint (struct gdbarch *gdbarch, | |
8735 | char *arg, char *cond_string, int thread, | |
8736 | int parse_condition_and_thread, | |
0fb4aa4b | 8737 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
8738 | int ignore_count, |
8739 | enum auto_boolean pending_break_support, | |
c0a91b2b | 8740 | const struct breakpoint_ops *ops, |
44f238bb PA |
8741 | int from_tty, int enabled, int internal, |
8742 | unsigned flags) | |
c3f6f71d | 8743 | { |
b78a6381 | 8744 | volatile struct gdb_exception e; |
f8eba3c6 | 8745 | char *copy_arg = NULL; |
c3f6f71d | 8746 | char *addr_start = arg; |
7efd8fc2 | 8747 | struct linespec_result canonical; |
c3f6f71d | 8748 | struct cleanup *old_chain; |
80c99de1 | 8749 | struct cleanup *bkpt_chain = NULL; |
05ff989b | 8750 | int i; |
0101ce28 | 8751 | int pending = 0; |
4a306c9a | 8752 | int task = 0; |
86b17b60 | 8753 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 8754 | |
348d480f PA |
8755 | gdb_assert (ops != NULL); |
8756 | ||
7efd8fc2 | 8757 | init_linespec_result (&canonical); |
c3f6f71d | 8758 | |
b78a6381 TT |
8759 | TRY_CATCH (e, RETURN_MASK_ALL) |
8760 | { | |
983af33b SDJ |
8761 | ops->create_sals_from_address (&arg, &canonical, type_wanted, |
8762 | addr_start, ©_arg); | |
b78a6381 | 8763 | } |
0101ce28 JJ |
8764 | |
8765 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 8766 | switch (e.reason) |
0101ce28 | 8767 | { |
983af33b SDJ |
8768 | case GDB_NO_ERROR: |
8769 | if (VEC_empty (linespec_sals, canonical.sals)) | |
8770 | return 0; | |
8771 | break; | |
05ff989b AC |
8772 | case RETURN_ERROR: |
8773 | switch (e.error) | |
0101ce28 | 8774 | { |
05ff989b | 8775 | case NOT_FOUND_ERROR: |
0101ce28 | 8776 | |
05ff989b AC |
8777 | /* If pending breakpoint support is turned off, throw |
8778 | error. */ | |
fa8d40ab JJ |
8779 | |
8780 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
8781 | throw_exception (e); |
8782 | ||
8783 | exception_print (gdb_stderr, e); | |
fa8d40ab | 8784 | |
05ff989b AC |
8785 | /* If pending breakpoint support is auto query and the user |
8786 | selects no, then simply return the error code. */ | |
059fb39f | 8787 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
bfccc43c YQ |
8788 | && !nquery (_("Make %s pending on future shared library load? "), |
8789 | bptype_string (type_wanted))) | |
fd9b8c24 | 8790 | return 0; |
fa8d40ab | 8791 | |
05ff989b AC |
8792 | /* At this point, either the user was queried about setting |
8793 | a pending breakpoint and selected yes, or pending | |
8794 | breakpoint behavior is on and thus a pending breakpoint | |
8795 | is defaulted on behalf of the user. */ | |
f8eba3c6 TT |
8796 | { |
8797 | struct linespec_sals lsal; | |
8798 | ||
8799 | copy_arg = xstrdup (addr_start); | |
8800 | lsal.canonical = xstrdup (copy_arg); | |
8801 | lsal.sals.nelts = 1; | |
8802 | lsal.sals.sals = XNEW (struct symtab_and_line); | |
8803 | init_sal (&lsal.sals.sals[0]); | |
8804 | pending = 1; | |
8805 | VEC_safe_push (linespec_sals, canonical.sals, &lsal); | |
8806 | } | |
05ff989b AC |
8807 | break; |
8808 | default: | |
98deb0da | 8809 | throw_exception (e); |
0101ce28 | 8810 | } |
2abae994 | 8811 | break; |
05ff989b | 8812 | default: |
983af33b | 8813 | throw_exception (e); |
0101ce28 | 8814 | } |
c3f6f71d | 8815 | |
4a64f543 | 8816 | /* Create a chain of things that always need to be cleaned up. */ |
f8eba3c6 | 8817 | old_chain = make_cleanup_destroy_linespec_result (&canonical); |
c3f6f71d | 8818 | |
c3f6f71d JM |
8819 | /* ----------------------------- SNIP ----------------------------- |
8820 | Anything added to the cleanup chain beyond this point is assumed | |
8821 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
8822 | then the memory is not reclaimed. */ |
8823 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d | 8824 | |
c3f6f71d JM |
8825 | /* Resolve all line numbers to PC's and verify that the addresses |
8826 | are ok for the target. */ | |
0101ce28 | 8827 | if (!pending) |
f8eba3c6 TT |
8828 | { |
8829 | int ix; | |
8830 | struct linespec_sals *iter; | |
8831 | ||
8832 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
8833 | breakpoint_sals_to_pc (&iter->sals); | |
8834 | } | |
c3f6f71d | 8835 | |
7a697b8d | 8836 | /* Fast tracepoints may have additional restrictions on location. */ |
bfccc43c | 8837 | if (!pending && type_wanted == bp_fast_tracepoint) |
f8eba3c6 TT |
8838 | { |
8839 | int ix; | |
8840 | struct linespec_sals *iter; | |
8841 | ||
8842 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
8843 | check_fast_tracepoint_sals (gdbarch, &iter->sals); | |
8844 | } | |
7a697b8d | 8845 | |
c3f6f71d JM |
8846 | /* Verify that condition can be parsed, before setting any |
8847 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 8848 | breakpoint. */ |
0101ce28 | 8849 | if (!pending) |
c3f6f71d | 8850 | { |
f8eba3c6 TT |
8851 | struct linespec_sals *lsal; |
8852 | ||
8853 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
8854 | ||
2f069f6f | 8855 | if (parse_condition_and_thread) |
72b2ff0e VP |
8856 | { |
8857 | /* Here we only parse 'arg' to separate condition | |
8858 | from thread number, so parsing in context of first | |
8859 | sal is OK. When setting the breakpoint we'll | |
8860 | re-parse it in context of each sal. */ | |
8861 | cond_string = NULL; | |
8862 | thread = -1; | |
f8eba3c6 | 8863 | find_condition_and_thread (arg, lsal->sals.sals[0].pc, &cond_string, |
4a306c9a | 8864 | &thread, &task); |
72b2ff0e VP |
8865 | if (cond_string) |
8866 | make_cleanup (xfree, cond_string); | |
8867 | } | |
2f069f6f | 8868 | else |
72b2ff0e VP |
8869 | { |
8870 | /* Create a private copy of condition string. */ | |
8871 | if (cond_string) | |
8872 | { | |
8873 | cond_string = xstrdup (cond_string); | |
8874 | make_cleanup (xfree, cond_string); | |
8875 | } | |
8876 | } | |
0fb4aa4b | 8877 | |
983af33b | 8878 | ops->create_breakpoints_sal (gdbarch, &canonical, lsal, |
d9b3f62e PA |
8879 | cond_string, type_wanted, |
8880 | tempflag ? disp_del : disp_donttouch, | |
8881 | thread, task, ignore_count, ops, | |
44f238bb | 8882 | from_tty, enabled, internal, flags); |
c906108c | 8883 | } |
0101ce28 JJ |
8884 | else |
8885 | { | |
0101ce28 JJ |
8886 | struct breakpoint *b; |
8887 | ||
0101ce28 JJ |
8888 | make_cleanup (xfree, copy_arg); |
8889 | ||
bfccc43c YQ |
8890 | if (is_tracepoint_type (type_wanted)) |
8891 | { | |
8892 | struct tracepoint *t; | |
8893 | ||
8894 | t = XCNEW (struct tracepoint); | |
8895 | b = &t->base; | |
8896 | } | |
8897 | else | |
8898 | b = XNEW (struct breakpoint); | |
8899 | ||
8900 | init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops); | |
8901 | ||
f8eba3c6 | 8902 | b->addr_string = copy_arg; |
72b2ff0e | 8903 | b->cond_string = NULL; |
0101ce28 | 8904 | b->ignore_count = ignore_count; |
0101ce28 | 8905 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 8906 | b->condition_not_parsed = 1; |
41447f92 | 8907 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
cc72b2a2 KP |
8908 | if ((type_wanted != bp_breakpoint |
8909 | && type_wanted != bp_hardware_breakpoint) || thread != -1) | |
f8eba3c6 | 8910 | b->pspace = current_program_space; |
8bea4e01 | 8911 | |
bfccc43c | 8912 | install_breakpoint (internal, b, 0); |
0101ce28 JJ |
8913 | } |
8914 | ||
f8eba3c6 | 8915 | if (VEC_length (linespec_sals, canonical.sals) > 1) |
95a42b64 | 8916 | { |
3e43a32a MS |
8917 | warning (_("Multiple breakpoints were set.\nUse the " |
8918 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 8919 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
8920 | } |
8921 | ||
80c99de1 PA |
8922 | /* That's it. Discard the cleanups for data inserted into the |
8923 | breakpoint. */ | |
8924 | discard_cleanups (bkpt_chain); | |
8925 | /* But cleanup everything else. */ | |
c3f6f71d | 8926 | do_cleanups (old_chain); |
217dc9e2 | 8927 | |
80c99de1 | 8928 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
217dc9e2 | 8929 | update_global_location_list (1); |
fd9b8c24 PA |
8930 | |
8931 | return 1; | |
c3f6f71d | 8932 | } |
c906108c | 8933 | |
348d480f | 8934 | /* Set a breakpoint. |
72b2ff0e VP |
8935 | ARG is a string describing breakpoint address, |
8936 | condition, and thread. | |
8937 | FLAG specifies if a breakpoint is hardware on, | |
8938 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
8939 | and BP_TEMPFLAG. */ | |
348d480f | 8940 | |
98deb0da | 8941 | static void |
72b2ff0e | 8942 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 8943 | { |
72b2ff0e | 8944 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
8945 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
8946 | ? bp_hardware_breakpoint | |
8947 | : bp_breakpoint); | |
c3f6f71d | 8948 | |
8cdf0e15 VP |
8949 | create_breakpoint (get_current_arch (), |
8950 | arg, | |
8951 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b | 8952 | tempflag, type_wanted, |
8cdf0e15 VP |
8953 | 0 /* Ignore count */, |
8954 | pending_break_support, | |
348d480f | 8955 | &bkpt_breakpoint_ops, |
8cdf0e15 | 8956 | from_tty, |
84f4c1fe | 8957 | 1 /* enabled */, |
44f238bb PA |
8958 | 0 /* internal */, |
8959 | 0); | |
c906108c SS |
8960 | } |
8961 | ||
c906108c SS |
8962 | /* Helper function for break_command_1 and disassemble_command. */ |
8963 | ||
8964 | void | |
fba45db2 | 8965 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
8966 | { |
8967 | CORE_ADDR pc; | |
8968 | ||
8969 | if (sal->pc == 0 && sal->symtab != NULL) | |
8970 | { | |
8971 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 8972 | error (_("No line %d in file \"%s\"."), |
c906108c SS |
8973 | sal->line, sal->symtab->filename); |
8974 | sal->pc = pc; | |
6a048695 | 8975 | |
4a64f543 MS |
8976 | /* If this SAL corresponds to a breakpoint inserted using a line |
8977 | number, then skip the function prologue if necessary. */ | |
6a048695 | 8978 | if (sal->explicit_line) |
059acae7 | 8979 | skip_prologue_sal (sal); |
c906108c SS |
8980 | } |
8981 | ||
8982 | if (sal->section == 0 && sal->symtab != NULL) | |
8983 | { | |
8984 | struct blockvector *bv; | |
c5aa993b JM |
8985 | struct block *b; |
8986 | struct symbol *sym; | |
c906108c | 8987 | |
801e3a5b | 8988 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
8989 | if (bv != NULL) |
8990 | { | |
7f0df278 | 8991 | sym = block_linkage_function (b); |
c906108c SS |
8992 | if (sym != NULL) |
8993 | { | |
8994 | fixup_symbol_section (sym, sal->symtab->objfile); | |
714835d5 | 8995 | sal->section = SYMBOL_OBJ_SECTION (sym); |
c906108c SS |
8996 | } |
8997 | else | |
8998 | { | |
4a64f543 MS |
8999 | /* It really is worthwhile to have the section, so we'll |
9000 | just have to look harder. This case can be executed | |
9001 | if we have line numbers but no functions (as can | |
9002 | happen in assembly source). */ | |
c906108c | 9003 | |
c5aa993b | 9004 | struct minimal_symbol *msym; |
6c95b8df PA |
9005 | struct cleanup *old_chain = save_current_space_and_thread (); |
9006 | ||
9007 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
9008 | |
9009 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
9010 | if (msym) | |
714835d5 | 9011 | sal->section = SYMBOL_OBJ_SECTION (msym); |
6c95b8df PA |
9012 | |
9013 | do_cleanups (old_chain); | |
c906108c SS |
9014 | } |
9015 | } | |
9016 | } | |
9017 | } | |
9018 | ||
9019 | void | |
fba45db2 | 9020 | break_command (char *arg, int from_tty) |
c906108c | 9021 | { |
db107f19 | 9022 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9023 | } |
9024 | ||
c906108c | 9025 | void |
fba45db2 | 9026 | tbreak_command (char *arg, int from_tty) |
c906108c | 9027 | { |
db107f19 | 9028 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
9029 | } |
9030 | ||
c906108c | 9031 | static void |
fba45db2 | 9032 | hbreak_command (char *arg, int from_tty) |
c906108c | 9033 | { |
db107f19 | 9034 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
9035 | } |
9036 | ||
9037 | static void | |
fba45db2 | 9038 | thbreak_command (char *arg, int from_tty) |
c906108c | 9039 | { |
db107f19 | 9040 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
9041 | } |
9042 | ||
9043 | static void | |
fba45db2 | 9044 | stop_command (char *arg, int from_tty) |
c906108c | 9045 | { |
a3f17187 | 9046 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 9047 | Usage: stop in <function | address>\n\ |
a3f17187 | 9048 | stop at <line>\n")); |
c906108c SS |
9049 | } |
9050 | ||
9051 | static void | |
fba45db2 | 9052 | stopin_command (char *arg, int from_tty) |
c906108c SS |
9053 | { |
9054 | int badInput = 0; | |
9055 | ||
c5aa993b | 9056 | if (arg == (char *) NULL) |
c906108c SS |
9057 | badInput = 1; |
9058 | else if (*arg != '*') | |
9059 | { | |
9060 | char *argptr = arg; | |
9061 | int hasColon = 0; | |
9062 | ||
4a64f543 | 9063 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 9064 | say it is bad, otherwise, it should be an address or |
4a64f543 | 9065 | function/method name. */ |
c906108c | 9066 | while (*argptr && !hasColon) |
c5aa993b JM |
9067 | { |
9068 | hasColon = (*argptr == ':'); | |
9069 | argptr++; | |
9070 | } | |
c906108c SS |
9071 | |
9072 | if (hasColon) | |
c5aa993b | 9073 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 9074 | else |
c5aa993b | 9075 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
9076 | } |
9077 | ||
9078 | if (badInput) | |
a3f17187 | 9079 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 9080 | else |
db107f19 | 9081 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9082 | } |
9083 | ||
9084 | static void | |
fba45db2 | 9085 | stopat_command (char *arg, int from_tty) |
c906108c SS |
9086 | { |
9087 | int badInput = 0; | |
9088 | ||
c5aa993b | 9089 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
9090 | badInput = 1; |
9091 | else | |
9092 | { | |
9093 | char *argptr = arg; | |
9094 | int hasColon = 0; | |
9095 | ||
4a64f543 MS |
9096 | /* Look for a ':'. If there is a '::' then get out, otherwise |
9097 | it is probably a line number. */ | |
c906108c | 9098 | while (*argptr && !hasColon) |
c5aa993b JM |
9099 | { |
9100 | hasColon = (*argptr == ':'); | |
9101 | argptr++; | |
9102 | } | |
c906108c SS |
9103 | |
9104 | if (hasColon) | |
c5aa993b | 9105 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 9106 | else |
c5aa993b | 9107 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
9108 | } |
9109 | ||
9110 | if (badInput) | |
a3f17187 | 9111 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 9112 | else |
db107f19 | 9113 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9114 | } |
9115 | ||
f1310107 TJB |
9116 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
9117 | ranged breakpoints. */ | |
9118 | ||
9119 | static int | |
9120 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
9121 | struct address_space *aspace, | |
09ac7c10 TT |
9122 | CORE_ADDR bp_addr, |
9123 | const struct target_waitstatus *ws) | |
f1310107 | 9124 | { |
09ac7c10 TT |
9125 | if (ws->kind != TARGET_WAITKIND_STOPPED |
9126 | || ws->value.sig != TARGET_SIGNAL_TRAP) | |
9127 | return 0; | |
9128 | ||
f1310107 TJB |
9129 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, |
9130 | bl->length, aspace, bp_addr); | |
9131 | } | |
9132 | ||
9133 | /* Implement the "resources_needed" breakpoint_ops method for | |
9134 | ranged breakpoints. */ | |
9135 | ||
9136 | static int | |
9137 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
9138 | { | |
9139 | return target_ranged_break_num_registers (); | |
9140 | } | |
9141 | ||
9142 | /* Implement the "print_it" breakpoint_ops method for | |
9143 | ranged breakpoints. */ | |
9144 | ||
9145 | static enum print_stop_action | |
348d480f | 9146 | print_it_ranged_breakpoint (bpstat bs) |
f1310107 | 9147 | { |
348d480f | 9148 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 | 9149 | struct bp_location *bl = b->loc; |
79a45e25 | 9150 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
9151 | |
9152 | gdb_assert (b->type == bp_hardware_breakpoint); | |
9153 | ||
9154 | /* Ranged breakpoints have only one location. */ | |
9155 | gdb_assert (bl && bl->next == NULL); | |
9156 | ||
9157 | annotate_breakpoint (b->number); | |
9158 | if (b->disposition == disp_del) | |
9159 | ui_out_text (uiout, "\nTemporary ranged breakpoint "); | |
9160 | else | |
9161 | ui_out_text (uiout, "\nRanged breakpoint "); | |
9162 | if (ui_out_is_mi_like_p (uiout)) | |
9163 | { | |
9164 | ui_out_field_string (uiout, "reason", | |
9165 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
9166 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
9167 | } | |
9168 | ui_out_field_int (uiout, "bkptno", b->number); | |
9169 | ui_out_text (uiout, ", "); | |
9170 | ||
9171 | return PRINT_SRC_AND_LOC; | |
9172 | } | |
9173 | ||
9174 | /* Implement the "print_one" breakpoint_ops method for | |
9175 | ranged breakpoints. */ | |
9176 | ||
9177 | static void | |
9178 | print_one_ranged_breakpoint (struct breakpoint *b, | |
9179 | struct bp_location **last_loc) | |
9180 | { | |
9181 | struct bp_location *bl = b->loc; | |
9182 | struct value_print_options opts; | |
79a45e25 | 9183 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
9184 | |
9185 | /* Ranged breakpoints have only one location. */ | |
9186 | gdb_assert (bl && bl->next == NULL); | |
9187 | ||
9188 | get_user_print_options (&opts); | |
9189 | ||
9190 | if (opts.addressprint) | |
9191 | /* We don't print the address range here, it will be printed later | |
9192 | by print_one_detail_ranged_breakpoint. */ | |
9193 | ui_out_field_skip (uiout, "addr"); | |
9194 | annotate_field (5); | |
9195 | print_breakpoint_location (b, bl); | |
9196 | *last_loc = bl; | |
9197 | } | |
9198 | ||
9199 | /* Implement the "print_one_detail" breakpoint_ops method for | |
9200 | ranged breakpoints. */ | |
9201 | ||
9202 | static void | |
9203 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
9204 | struct ui_out *uiout) | |
9205 | { | |
9206 | CORE_ADDR address_start, address_end; | |
9207 | struct bp_location *bl = b->loc; | |
9208 | struct ui_stream *stb = ui_out_stream_new (uiout); | |
9209 | struct cleanup *cleanup = make_cleanup_ui_out_stream_delete (stb); | |
9210 | ||
9211 | gdb_assert (bl); | |
9212 | ||
9213 | address_start = bl->address; | |
9214 | address_end = address_start + bl->length - 1; | |
9215 | ||
9216 | ui_out_text (uiout, "\taddress range: "); | |
9217 | fprintf_unfiltered (stb->stream, "[%s, %s]", | |
9218 | print_core_address (bl->gdbarch, address_start), | |
9219 | print_core_address (bl->gdbarch, address_end)); | |
9220 | ui_out_field_stream (uiout, "addr", stb); | |
9221 | ui_out_text (uiout, "\n"); | |
9222 | ||
9223 | do_cleanups (cleanup); | |
9224 | } | |
9225 | ||
9226 | /* Implement the "print_mention" breakpoint_ops method for | |
9227 | ranged breakpoints. */ | |
9228 | ||
9229 | static void | |
9230 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
9231 | { | |
9232 | struct bp_location *bl = b->loc; | |
79a45e25 | 9233 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
9234 | |
9235 | gdb_assert (bl); | |
9236 | gdb_assert (b->type == bp_hardware_breakpoint); | |
9237 | ||
9238 | if (ui_out_is_mi_like_p (uiout)) | |
9239 | return; | |
9240 | ||
9241 | printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."), | |
9242 | b->number, paddress (bl->gdbarch, bl->address), | |
9243 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
9244 | } | |
9245 | ||
9246 | /* Implement the "print_recreate" breakpoint_ops method for | |
9247 | ranged breakpoints. */ | |
9248 | ||
9249 | static void | |
9250 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
9251 | { | |
9252 | fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string, | |
9253 | b->addr_string_range_end); | |
d9b3f62e | 9254 | print_recreate_thread (b, fp); |
f1310107 TJB |
9255 | } |
9256 | ||
9257 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
9258 | ||
2060206e | 9259 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
9260 | |
9261 | /* Find the address where the end of the breakpoint range should be | |
9262 | placed, given the SAL of the end of the range. This is so that if | |
9263 | the user provides a line number, the end of the range is set to the | |
9264 | last instruction of the given line. */ | |
9265 | ||
9266 | static CORE_ADDR | |
9267 | find_breakpoint_range_end (struct symtab_and_line sal) | |
9268 | { | |
9269 | CORE_ADDR end; | |
9270 | ||
9271 | /* If the user provided a PC value, use it. Otherwise, | |
9272 | find the address of the end of the given location. */ | |
9273 | if (sal.explicit_pc) | |
9274 | end = sal.pc; | |
9275 | else | |
9276 | { | |
9277 | int ret; | |
9278 | CORE_ADDR start; | |
9279 | ||
9280 | ret = find_line_pc_range (sal, &start, &end); | |
9281 | if (!ret) | |
9282 | error (_("Could not find location of the end of the range.")); | |
9283 | ||
9284 | /* find_line_pc_range returns the start of the next line. */ | |
9285 | end--; | |
9286 | } | |
9287 | ||
9288 | return end; | |
9289 | } | |
9290 | ||
9291 | /* Implement the "break-range" CLI command. */ | |
9292 | ||
9293 | static void | |
9294 | break_range_command (char *arg, int from_tty) | |
9295 | { | |
9296 | char *arg_start, *addr_string_start, *addr_string_end; | |
9297 | struct linespec_result canonical_start, canonical_end; | |
9298 | int bp_count, can_use_bp, length; | |
9299 | CORE_ADDR end; | |
9300 | struct breakpoint *b; | |
9301 | struct symtab_and_line sal_start, sal_end; | |
f1310107 | 9302 | struct cleanup *cleanup_bkpt; |
f8eba3c6 | 9303 | struct linespec_sals *lsal_start, *lsal_end; |
f1310107 TJB |
9304 | |
9305 | /* We don't support software ranged breakpoints. */ | |
9306 | if (target_ranged_break_num_registers () < 0) | |
9307 | error (_("This target does not support hardware ranged breakpoints.")); | |
9308 | ||
9309 | bp_count = hw_breakpoint_used_count (); | |
9310 | bp_count += target_ranged_break_num_registers (); | |
9311 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
9312 | bp_count, 0); | |
9313 | if (can_use_bp < 0) | |
9314 | error (_("Hardware breakpoints used exceeds limit.")); | |
9315 | ||
f8eba3c6 | 9316 | arg = skip_spaces (arg); |
f1310107 TJB |
9317 | if (arg == NULL || arg[0] == '\0') |
9318 | error(_("No address range specified.")); | |
9319 | ||
f1310107 TJB |
9320 | init_linespec_result (&canonical_start); |
9321 | ||
f8eba3c6 TT |
9322 | arg_start = arg; |
9323 | parse_breakpoint_sals (&arg, &canonical_start); | |
f1310107 | 9324 | |
f8eba3c6 | 9325 | cleanup_bkpt = make_cleanup_destroy_linespec_result (&canonical_start); |
f1310107 TJB |
9326 | |
9327 | if (arg[0] != ',') | |
9328 | error (_("Too few arguments.")); | |
f8eba3c6 | 9329 | else if (VEC_empty (linespec_sals, canonical_start.sals)) |
f1310107 | 9330 | error (_("Could not find location of the beginning of the range.")); |
f8eba3c6 TT |
9331 | |
9332 | lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0); | |
9333 | ||
9334 | if (VEC_length (linespec_sals, canonical_start.sals) > 1 | |
9335 | || lsal_start->sals.nelts != 1) | |
f1310107 TJB |
9336 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
9337 | ||
f8eba3c6 TT |
9338 | sal_start = lsal_start->sals.sals[0]; |
9339 | addr_string_start = savestring (arg_start, arg - arg_start); | |
9340 | make_cleanup (xfree, addr_string_start); | |
f1310107 TJB |
9341 | |
9342 | arg++; /* Skip the comma. */ | |
f8eba3c6 | 9343 | arg = skip_spaces (arg); |
f1310107 TJB |
9344 | |
9345 | /* Parse the end location. */ | |
9346 | ||
f1310107 TJB |
9347 | init_linespec_result (&canonical_end); |
9348 | arg_start = arg; | |
9349 | ||
f8eba3c6 | 9350 | /* We call decode_line_full directly here instead of using |
f1310107 TJB |
9351 | parse_breakpoint_sals because we need to specify the start location's |
9352 | symtab and line as the default symtab and line for the end of the | |
9353 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
9354 | where +14 means 14 lines from the start location. */ | |
f8eba3c6 TT |
9355 | decode_line_full (&arg, DECODE_LINE_FUNFIRSTLINE, |
9356 | sal_start.symtab, sal_start.line, | |
9357 | &canonical_end, NULL, NULL); | |
9358 | ||
9359 | make_cleanup_destroy_linespec_result (&canonical_end); | |
f1310107 | 9360 | |
f8eba3c6 | 9361 | if (VEC_empty (linespec_sals, canonical_end.sals)) |
f1310107 | 9362 | error (_("Could not find location of the end of the range.")); |
f8eba3c6 TT |
9363 | |
9364 | lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0); | |
9365 | if (VEC_length (linespec_sals, canonical_end.sals) > 1 | |
9366 | || lsal_end->sals.nelts != 1) | |
f1310107 TJB |
9367 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
9368 | ||
f8eba3c6 TT |
9369 | sal_end = lsal_end->sals.sals[0]; |
9370 | addr_string_end = savestring (arg_start, arg - arg_start); | |
9371 | make_cleanup (xfree, addr_string_end); | |
f1310107 TJB |
9372 | |
9373 | end = find_breakpoint_range_end (sal_end); | |
9374 | if (sal_start.pc > end) | |
177b42fe | 9375 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
9376 | |
9377 | length = end - sal_start.pc + 1; | |
9378 | if (length < 0) | |
9379 | /* Length overflowed. */ | |
9380 | error (_("Address range too large.")); | |
9381 | else if (length == 1) | |
9382 | { | |
9383 | /* This range is simple enough to be handled by | |
9384 | the `hbreak' command. */ | |
9385 | hbreak_command (addr_string_start, 1); | |
9386 | ||
9387 | do_cleanups (cleanup_bkpt); | |
9388 | ||
9389 | return; | |
9390 | } | |
9391 | ||
9392 | /* Now set up the breakpoint. */ | |
9393 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 9394 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
9395 | set_breakpoint_count (breakpoint_count + 1); |
9396 | b->number = breakpoint_count; | |
9397 | b->disposition = disp_donttouch; | |
f8eba3c6 TT |
9398 | b->addr_string = xstrdup (addr_string_start); |
9399 | b->addr_string_range_end = xstrdup (addr_string_end); | |
f1310107 TJB |
9400 | b->loc->length = length; |
9401 | ||
f8eba3c6 | 9402 | do_cleanups (cleanup_bkpt); |
f1310107 TJB |
9403 | |
9404 | mention (b); | |
8d3788bd | 9405 | observer_notify_breakpoint_created (b); |
f1310107 TJB |
9406 | update_global_location_list (1); |
9407 | } | |
9408 | ||
4a64f543 MS |
9409 | /* Return non-zero if EXP is verified as constant. Returned zero |
9410 | means EXP is variable. Also the constant detection may fail for | |
9411 | some constant expressions and in such case still falsely return | |
9412 | zero. */ | |
2e6e3d9c | 9413 | |
65d79d4b SDJ |
9414 | static int |
9415 | watchpoint_exp_is_const (const struct expression *exp) | |
9416 | { | |
9417 | int i = exp->nelts; | |
9418 | ||
9419 | while (i > 0) | |
9420 | { | |
9421 | int oplenp, argsp; | |
9422 | ||
9423 | /* We are only interested in the descriptor of each element. */ | |
9424 | operator_length (exp, i, &oplenp, &argsp); | |
9425 | i -= oplenp; | |
9426 | ||
9427 | switch (exp->elts[i].opcode) | |
9428 | { | |
9429 | case BINOP_ADD: | |
9430 | case BINOP_SUB: | |
9431 | case BINOP_MUL: | |
9432 | case BINOP_DIV: | |
9433 | case BINOP_REM: | |
9434 | case BINOP_MOD: | |
9435 | case BINOP_LSH: | |
9436 | case BINOP_RSH: | |
9437 | case BINOP_LOGICAL_AND: | |
9438 | case BINOP_LOGICAL_OR: | |
9439 | case BINOP_BITWISE_AND: | |
9440 | case BINOP_BITWISE_IOR: | |
9441 | case BINOP_BITWISE_XOR: | |
9442 | case BINOP_EQUAL: | |
9443 | case BINOP_NOTEQUAL: | |
9444 | case BINOP_LESS: | |
9445 | case BINOP_GTR: | |
9446 | case BINOP_LEQ: | |
9447 | case BINOP_GEQ: | |
9448 | case BINOP_REPEAT: | |
9449 | case BINOP_COMMA: | |
9450 | case BINOP_EXP: | |
9451 | case BINOP_MIN: | |
9452 | case BINOP_MAX: | |
9453 | case BINOP_INTDIV: | |
9454 | case BINOP_CONCAT: | |
9455 | case BINOP_IN: | |
9456 | case BINOP_RANGE: | |
9457 | case TERNOP_COND: | |
9458 | case TERNOP_SLICE: | |
9459 | case TERNOP_SLICE_COUNT: | |
9460 | ||
9461 | case OP_LONG: | |
9462 | case OP_DOUBLE: | |
9463 | case OP_DECFLOAT: | |
9464 | case OP_LAST: | |
9465 | case OP_COMPLEX: | |
9466 | case OP_STRING: | |
9467 | case OP_BITSTRING: | |
9468 | case OP_ARRAY: | |
9469 | case OP_TYPE: | |
9470 | case OP_NAME: | |
9471 | case OP_OBJC_NSSTRING: | |
9472 | ||
9473 | case UNOP_NEG: | |
9474 | case UNOP_LOGICAL_NOT: | |
9475 | case UNOP_COMPLEMENT: | |
9476 | case UNOP_ADDR: | |
9477 | case UNOP_HIGH: | |
aeaa2474 | 9478 | case UNOP_CAST: |
4a64f543 MS |
9479 | /* Unary, binary and ternary operators: We have to check |
9480 | their operands. If they are constant, then so is the | |
9481 | result of that operation. For instance, if A and B are | |
9482 | determined to be constants, then so is "A + B". | |
9483 | ||
9484 | UNOP_IND is one exception to the rule above, because the | |
9485 | value of *ADDR is not necessarily a constant, even when | |
9486 | ADDR is. */ | |
65d79d4b SDJ |
9487 | break; |
9488 | ||
9489 | case OP_VAR_VALUE: | |
9490 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 9491 | |
65d79d4b | 9492 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
9493 | possible that a buggy compiler could mark a variable as |
9494 | constant even when it is not, and TYPE_CONST would return | |
9495 | true in this case, while SYMBOL_CLASS wouldn't. | |
9496 | ||
9497 | We also have to check for function symbols because they | |
9498 | are always constant. */ | |
65d79d4b SDJ |
9499 | { |
9500 | struct symbol *s = exp->elts[i + 2].symbol; | |
9501 | ||
9502 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
9503 | && SYMBOL_CLASS (s) != LOC_CONST | |
9504 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
9505 | return 0; | |
9506 | break; | |
9507 | } | |
9508 | ||
9509 | /* The default action is to return 0 because we are using | |
9510 | the optimistic approach here: If we don't know something, | |
9511 | then it is not a constant. */ | |
9512 | default: | |
9513 | return 0; | |
9514 | } | |
9515 | } | |
9516 | ||
9517 | return 1; | |
9518 | } | |
9519 | ||
3a5c3e22 PA |
9520 | /* Implement the "dtor" breakpoint_ops method for watchpoints. */ |
9521 | ||
9522 | static void | |
9523 | dtor_watchpoint (struct breakpoint *self) | |
9524 | { | |
9525 | struct watchpoint *w = (struct watchpoint *) self; | |
9526 | ||
9527 | xfree (w->cond_exp); | |
9528 | xfree (w->exp); | |
9529 | xfree (w->exp_string); | |
9530 | xfree (w->exp_string_reparse); | |
9531 | value_free (w->val); | |
9532 | ||
9533 | base_breakpoint_ops.dtor (self); | |
9534 | } | |
9535 | ||
348d480f PA |
9536 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
9537 | ||
9538 | static void | |
9539 | re_set_watchpoint (struct breakpoint *b) | |
9540 | { | |
3a5c3e22 PA |
9541 | struct watchpoint *w = (struct watchpoint *) b; |
9542 | ||
348d480f PA |
9543 | /* Watchpoint can be either on expression using entirely global |
9544 | variables, or it can be on local variables. | |
9545 | ||
9546 | Watchpoints of the first kind are never auto-deleted, and even | |
9547 | persist across program restarts. Since they can use variables | |
9548 | from shared libraries, we need to reparse expression as libraries | |
9549 | are loaded and unloaded. | |
9550 | ||
9551 | Watchpoints on local variables can also change meaning as result | |
9552 | of solib event. For example, if a watchpoint uses both a local | |
9553 | and a global variables in expression, it's a local watchpoint, | |
9554 | but unloading of a shared library will make the expression | |
9555 | invalid. This is not a very common use case, but we still | |
9556 | re-evaluate expression, to avoid surprises to the user. | |
9557 | ||
9558 | Note that for local watchpoints, we re-evaluate it only if | |
9559 | watchpoints frame id is still valid. If it's not, it means the | |
9560 | watchpoint is out of scope and will be deleted soon. In fact, | |
9561 | I'm not sure we'll ever be called in this case. | |
9562 | ||
9563 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 9564 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 9565 | |
3a5c3e22 PA |
9566 | Don't do anything about disabled watchpoints, since they will be |
9567 | reevaluated again when enabled. */ | |
9568 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
9569 | } |
9570 | ||
77b06cd7 TJB |
9571 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
9572 | ||
9573 | static int | |
9574 | insert_watchpoint (struct bp_location *bl) | |
9575 | { | |
3a5c3e22 PA |
9576 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
9577 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
9578 | |
9579 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 9580 | w->cond_exp); |
77b06cd7 TJB |
9581 | } |
9582 | ||
9583 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
9584 | ||
9585 | static int | |
9586 | remove_watchpoint (struct bp_location *bl) | |
9587 | { | |
3a5c3e22 PA |
9588 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
9589 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
9590 | |
9591 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 9592 | w->cond_exp); |
e09342b5 TJB |
9593 | } |
9594 | ||
e09342b5 | 9595 | static int |
348d480f | 9596 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
09ac7c10 TT |
9597 | struct address_space *aspace, CORE_ADDR bp_addr, |
9598 | const struct target_waitstatus *ws) | |
e09342b5 | 9599 | { |
348d480f | 9600 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 9601 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 9602 | |
348d480f PA |
9603 | /* Continuable hardware watchpoints are treated as non-existent if the |
9604 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
9605 | some data address). Otherwise gdb won't stop on a break instruction | |
9606 | in the code (not from a breakpoint) when a hardware watchpoint has | |
9607 | been defined. Also skip watchpoints which we know did not trigger | |
9608 | (did not match the data address). */ | |
9609 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 9610 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 9611 | return 0; |
9c06b0b4 | 9612 | |
348d480f | 9613 | return 1; |
9c06b0b4 TJB |
9614 | } |
9615 | ||
348d480f PA |
9616 | static void |
9617 | check_status_watchpoint (bpstat bs) | |
9c06b0b4 | 9618 | { |
348d480f | 9619 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 9620 | |
348d480f | 9621 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
9622 | } |
9623 | ||
9624 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 9625 | hardware watchpoints. */ |
9c06b0b4 TJB |
9626 | |
9627 | static int | |
348d480f | 9628 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 9629 | { |
3a5c3e22 PA |
9630 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
9631 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
9632 | |
9633 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
9634 | } |
9635 | ||
9636 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 9637 | hardware watchpoints. */ |
9c06b0b4 TJB |
9638 | |
9639 | static int | |
348d480f | 9640 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 9641 | { |
efa80663 PA |
9642 | /* Read and access watchpoints only work with hardware support. */ |
9643 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
9644 | } |
9645 | ||
9c06b0b4 | 9646 | static enum print_stop_action |
348d480f | 9647 | print_it_watchpoint (bpstat bs) |
9c06b0b4 | 9648 | { |
348d480f PA |
9649 | struct cleanup *old_chain; |
9650 | struct breakpoint *b; | |
9651 | const struct bp_location *bl; | |
9652 | struct ui_stream *stb; | |
9653 | enum print_stop_action result; | |
3a5c3e22 | 9654 | struct watchpoint *w; |
79a45e25 | 9655 | struct ui_out *uiout = current_uiout; |
348d480f PA |
9656 | |
9657 | gdb_assert (bs->bp_location_at != NULL); | |
9658 | ||
9659 | bl = bs->bp_location_at; | |
9660 | b = bs->breakpoint_at; | |
3a5c3e22 | 9661 | w = (struct watchpoint *) b; |
348d480f PA |
9662 | |
9663 | stb = ui_out_stream_new (uiout); | |
9664 | old_chain = make_cleanup_ui_out_stream_delete (stb); | |
9c06b0b4 TJB |
9665 | |
9666 | switch (b->type) | |
9667 | { | |
348d480f | 9668 | case bp_watchpoint: |
9c06b0b4 TJB |
9669 | case bp_hardware_watchpoint: |
9670 | annotate_watchpoint (b->number); | |
9671 | if (ui_out_is_mi_like_p (uiout)) | |
9672 | ui_out_field_string | |
9673 | (uiout, "reason", | |
9674 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
9675 | mention (b); |
9676 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
9677 | ui_out_text (uiout, "\nOld value = "); | |
9678 | watchpoint_value_print (bs->old_val, stb->stream); | |
9679 | ui_out_field_stream (uiout, "old", stb); | |
9680 | ui_out_text (uiout, "\nNew value = "); | |
3a5c3e22 | 9681 | watchpoint_value_print (w->val, stb->stream); |
348d480f PA |
9682 | ui_out_field_stream (uiout, "new", stb); |
9683 | ui_out_text (uiout, "\n"); | |
9684 | /* More than one watchpoint may have been triggered. */ | |
9685 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
9686 | break; |
9687 | ||
9688 | case bp_read_watchpoint: | |
9689 | if (ui_out_is_mi_like_p (uiout)) | |
9690 | ui_out_field_string | |
9691 | (uiout, "reason", | |
9692 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
9693 | mention (b); |
9694 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
9695 | ui_out_text (uiout, "\nValue = "); | |
3a5c3e22 | 9696 | watchpoint_value_print (w->val, stb->stream); |
348d480f PA |
9697 | ui_out_field_stream (uiout, "value", stb); |
9698 | ui_out_text (uiout, "\n"); | |
9699 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
9700 | break; |
9701 | ||
9702 | case bp_access_watchpoint: | |
348d480f PA |
9703 | if (bs->old_val != NULL) |
9704 | { | |
9705 | annotate_watchpoint (b->number); | |
9706 | if (ui_out_is_mi_like_p (uiout)) | |
9707 | ui_out_field_string | |
9708 | (uiout, "reason", | |
9709 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
9710 | mention (b); | |
9711 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
9712 | ui_out_text (uiout, "\nOld value = "); | |
9713 | watchpoint_value_print (bs->old_val, stb->stream); | |
9714 | ui_out_field_stream (uiout, "old", stb); | |
9715 | ui_out_text (uiout, "\nNew value = "); | |
9716 | } | |
9717 | else | |
9718 | { | |
9719 | mention (b); | |
9720 | if (ui_out_is_mi_like_p (uiout)) | |
9721 | ui_out_field_string | |
9722 | (uiout, "reason", | |
9723 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
9724 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
9725 | ui_out_text (uiout, "\nValue = "); | |
9726 | } | |
3a5c3e22 | 9727 | watchpoint_value_print (w->val, stb->stream); |
348d480f PA |
9728 | ui_out_field_stream (uiout, "new", stb); |
9729 | ui_out_text (uiout, "\n"); | |
9730 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
9731 | break; |
9732 | default: | |
348d480f | 9733 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
9734 | } |
9735 | ||
348d480f PA |
9736 | do_cleanups (old_chain); |
9737 | return result; | |
9738 | } | |
9739 | ||
9740 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
9741 | watchpoints. */ | |
9742 | ||
9743 | static void | |
9744 | print_mention_watchpoint (struct breakpoint *b) | |
9745 | { | |
9746 | struct cleanup *ui_out_chain; | |
3a5c3e22 | 9747 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 9748 | struct ui_out *uiout = current_uiout; |
348d480f PA |
9749 | |
9750 | switch (b->type) | |
9751 | { | |
9752 | case bp_watchpoint: | |
9753 | ui_out_text (uiout, "Watchpoint "); | |
9754 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
9755 | break; | |
9756 | case bp_hardware_watchpoint: | |
9757 | ui_out_text (uiout, "Hardware watchpoint "); | |
9758 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
9759 | break; | |
9760 | case bp_read_watchpoint: | |
9761 | ui_out_text (uiout, "Hardware read watchpoint "); | |
9762 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
9763 | break; | |
9764 | case bp_access_watchpoint: | |
9765 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
9766 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
9767 | break; | |
9768 | default: | |
9769 | internal_error (__FILE__, __LINE__, | |
9770 | _("Invalid hardware watchpoint type.")); | |
9771 | } | |
9772 | ||
9773 | ui_out_field_int (uiout, "number", b->number); | |
9774 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 9775 | ui_out_field_string (uiout, "exp", w->exp_string); |
348d480f PA |
9776 | do_cleanups (ui_out_chain); |
9777 | } | |
9778 | ||
9779 | /* Implement the "print_recreate" breakpoint_ops method for | |
9780 | watchpoints. */ | |
9781 | ||
9782 | static void | |
9783 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
9784 | { | |
3a5c3e22 PA |
9785 | struct watchpoint *w = (struct watchpoint *) b; |
9786 | ||
348d480f PA |
9787 | switch (b->type) |
9788 | { | |
9789 | case bp_watchpoint: | |
9790 | case bp_hardware_watchpoint: | |
9791 | fprintf_unfiltered (fp, "watch"); | |
9792 | break; | |
9793 | case bp_read_watchpoint: | |
9794 | fprintf_unfiltered (fp, "rwatch"); | |
9795 | break; | |
9796 | case bp_access_watchpoint: | |
9797 | fprintf_unfiltered (fp, "awatch"); | |
9798 | break; | |
9799 | default: | |
9800 | internal_error (__FILE__, __LINE__, | |
9801 | _("Invalid watchpoint type.")); | |
9802 | } | |
9803 | ||
3a5c3e22 | 9804 | fprintf_unfiltered (fp, " %s", w->exp_string); |
d9b3f62e | 9805 | print_recreate_thread (b, fp); |
348d480f PA |
9806 | } |
9807 | ||
9808 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ | |
9809 | ||
2060206e | 9810 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
9811 | |
9812 | /* Implement the "insert" breakpoint_ops method for | |
9813 | masked hardware watchpoints. */ | |
9814 | ||
9815 | static int | |
9816 | insert_masked_watchpoint (struct bp_location *bl) | |
9817 | { | |
3a5c3e22 PA |
9818 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
9819 | ||
9820 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
9821 | bl->watchpoint_type); |
9822 | } | |
9823 | ||
9824 | /* Implement the "remove" breakpoint_ops method for | |
9825 | masked hardware watchpoints. */ | |
9826 | ||
9827 | static int | |
9828 | remove_masked_watchpoint (struct bp_location *bl) | |
9829 | { | |
3a5c3e22 PA |
9830 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
9831 | ||
9832 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
9833 | bl->watchpoint_type); |
9834 | } | |
9835 | ||
9836 | /* Implement the "resources_needed" breakpoint_ops method for | |
9837 | masked hardware watchpoints. */ | |
9838 | ||
9839 | static int | |
9840 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
9841 | { | |
3a5c3e22 PA |
9842 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
9843 | ||
9844 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
9845 | } |
9846 | ||
9847 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
9848 | masked hardware watchpoints. */ | |
9849 | ||
9850 | static int | |
9851 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
9852 | { | |
9853 | return 0; | |
9854 | } | |
9855 | ||
9856 | /* Implement the "print_it" breakpoint_ops method for | |
9857 | masked hardware watchpoints. */ | |
9858 | ||
9859 | static enum print_stop_action | |
9860 | print_it_masked_watchpoint (bpstat bs) | |
9861 | { | |
9862 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 9863 | struct ui_out *uiout = current_uiout; |
348d480f PA |
9864 | |
9865 | /* Masked watchpoints have only one location. */ | |
9866 | gdb_assert (b->loc && b->loc->next == NULL); | |
9867 | ||
9868 | switch (b->type) | |
9869 | { | |
9870 | case bp_hardware_watchpoint: | |
9871 | annotate_watchpoint (b->number); | |
9872 | if (ui_out_is_mi_like_p (uiout)) | |
9873 | ui_out_field_string | |
9874 | (uiout, "reason", | |
9875 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
9876 | break; | |
9877 | ||
9878 | case bp_read_watchpoint: | |
9879 | if (ui_out_is_mi_like_p (uiout)) | |
9880 | ui_out_field_string | |
9881 | (uiout, "reason", | |
9882 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
9883 | break; | |
9884 | ||
9885 | case bp_access_watchpoint: | |
9886 | if (ui_out_is_mi_like_p (uiout)) | |
9887 | ui_out_field_string | |
9888 | (uiout, "reason", | |
9889 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
9890 | break; | |
9891 | default: | |
9892 | internal_error (__FILE__, __LINE__, | |
9893 | _("Invalid hardware watchpoint type.")); | |
9894 | } | |
9895 | ||
9896 | mention (b); | |
9c06b0b4 TJB |
9897 | ui_out_text (uiout, _("\n\ |
9898 | Check the underlying instruction at PC for the memory\n\ | |
9899 | address and value which triggered this watchpoint.\n")); | |
9900 | ui_out_text (uiout, "\n"); | |
9901 | ||
9902 | /* More than one watchpoint may have been triggered. */ | |
9903 | return PRINT_UNKNOWN; | |
9904 | } | |
9905 | ||
9906 | /* Implement the "print_one_detail" breakpoint_ops method for | |
9907 | masked hardware watchpoints. */ | |
9908 | ||
9909 | static void | |
9910 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
9911 | struct ui_out *uiout) | |
9912 | { | |
3a5c3e22 PA |
9913 | struct watchpoint *w = (struct watchpoint *) b; |
9914 | ||
9c06b0b4 TJB |
9915 | /* Masked watchpoints have only one location. */ |
9916 | gdb_assert (b->loc && b->loc->next == NULL); | |
9917 | ||
9918 | ui_out_text (uiout, "\tmask "); | |
3a5c3e22 | 9919 | ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask); |
9c06b0b4 TJB |
9920 | ui_out_text (uiout, "\n"); |
9921 | } | |
9922 | ||
9923 | /* Implement the "print_mention" breakpoint_ops method for | |
9924 | masked hardware watchpoints. */ | |
9925 | ||
9926 | static void | |
9927 | print_mention_masked_watchpoint (struct breakpoint *b) | |
9928 | { | |
3a5c3e22 | 9929 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 9930 | struct ui_out *uiout = current_uiout; |
9c06b0b4 TJB |
9931 | struct cleanup *ui_out_chain; |
9932 | ||
9933 | switch (b->type) | |
9934 | { | |
9935 | case bp_hardware_watchpoint: | |
9936 | ui_out_text (uiout, "Masked hardware watchpoint "); | |
9937 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
9938 | break; | |
9939 | case bp_read_watchpoint: | |
9940 | ui_out_text (uiout, "Masked hardware read watchpoint "); | |
9941 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
9942 | break; | |
9943 | case bp_access_watchpoint: | |
9944 | ui_out_text (uiout, "Masked hardware access (read/write) watchpoint "); | |
9945 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
9946 | break; | |
9947 | default: | |
9948 | internal_error (__FILE__, __LINE__, | |
9949 | _("Invalid hardware watchpoint type.")); | |
9950 | } | |
9951 | ||
9952 | ui_out_field_int (uiout, "number", b->number); | |
9953 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 9954 | ui_out_field_string (uiout, "exp", w->exp_string); |
9c06b0b4 TJB |
9955 | do_cleanups (ui_out_chain); |
9956 | } | |
9957 | ||
9958 | /* Implement the "print_recreate" breakpoint_ops method for | |
9959 | masked hardware watchpoints. */ | |
9960 | ||
9961 | static void | |
9962 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
9963 | { | |
3a5c3e22 | 9964 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
9965 | char tmp[40]; |
9966 | ||
9967 | switch (b->type) | |
9968 | { | |
9969 | case bp_hardware_watchpoint: | |
9970 | fprintf_unfiltered (fp, "watch"); | |
9971 | break; | |
9972 | case bp_read_watchpoint: | |
9973 | fprintf_unfiltered (fp, "rwatch"); | |
9974 | break; | |
9975 | case bp_access_watchpoint: | |
9976 | fprintf_unfiltered (fp, "awatch"); | |
9977 | break; | |
9978 | default: | |
9979 | internal_error (__FILE__, __LINE__, | |
9980 | _("Invalid hardware watchpoint type.")); | |
9981 | } | |
9982 | ||
3a5c3e22 PA |
9983 | sprintf_vma (tmp, w->hw_wp_mask); |
9984 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); | |
d9b3f62e | 9985 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
9986 | } |
9987 | ||
9988 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
9989 | ||
2060206e | 9990 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
9991 | |
9992 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
9993 | ||
9994 | static int | |
9995 | is_masked_watchpoint (const struct breakpoint *b) | |
9996 | { | |
9997 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
9998 | } | |
9999 | ||
53a5351d JM |
10000 | /* accessflag: hw_write: watch write, |
10001 | hw_read: watch read, | |
10002 | hw_access: watch access (read or write) */ | |
c906108c | 10003 | static void |
84f4c1fe PM |
10004 | watch_command_1 (char *arg, int accessflag, int from_tty, |
10005 | int just_location, int internal) | |
c906108c | 10006 | { |
a9634178 | 10007 | volatile struct gdb_exception e; |
d983da9c | 10008 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c | 10009 | struct expression *exp; |
60e1c644 | 10010 | struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 10011 | struct value *val, *mark, *result; |
c906108c | 10012 | struct frame_info *frame; |
c906108c SS |
10013 | char *exp_start = NULL; |
10014 | char *exp_end = NULL; | |
9c06b0b4 TJB |
10015 | char *tok, *end_tok; |
10016 | int toklen = -1; | |
c906108c SS |
10017 | char *cond_start = NULL; |
10018 | char *cond_end = NULL; | |
c906108c | 10019 | enum bptype bp_type; |
37e4754d | 10020 | int thread = -1; |
0cf6dd15 | 10021 | int pc = 0; |
9c06b0b4 TJB |
10022 | /* Flag to indicate whether we are going to use masks for |
10023 | the hardware watchpoint. */ | |
10024 | int use_mask = 0; | |
10025 | CORE_ADDR mask = 0; | |
3a5c3e22 | 10026 | struct watchpoint *w; |
c906108c | 10027 | |
37e4754d LM |
10028 | /* Make sure that we actually have parameters to parse. */ |
10029 | if (arg != NULL && arg[0] != '\0') | |
10030 | { | |
9c06b0b4 | 10031 | char *value_start; |
37e4754d | 10032 | |
9c06b0b4 TJB |
10033 | /* Look for "parameter value" pairs at the end |
10034 | of the arguments string. */ | |
10035 | for (tok = arg + strlen (arg) - 1; tok > arg; tok--) | |
10036 | { | |
10037 | /* Skip whitespace at the end of the argument list. */ | |
10038 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
10039 | tok--; | |
10040 | ||
10041 | /* Find the beginning of the last token. | |
10042 | This is the value of the parameter. */ | |
10043 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
10044 | tok--; | |
10045 | value_start = tok + 1; | |
10046 | ||
10047 | /* Skip whitespace. */ | |
10048 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
10049 | tok--; | |
10050 | ||
10051 | end_tok = tok; | |
10052 | ||
10053 | /* Find the beginning of the second to last token. | |
10054 | This is the parameter itself. */ | |
10055 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
10056 | tok--; | |
10057 | tok++; | |
10058 | toklen = end_tok - tok + 1; | |
10059 | ||
10060 | if (toklen == 6 && !strncmp (tok, "thread", 6)) | |
10061 | { | |
10062 | /* At this point we've found a "thread" token, which means | |
10063 | the user is trying to set a watchpoint that triggers | |
10064 | only in a specific thread. */ | |
10065 | char *endp; | |
37e4754d | 10066 | |
9c06b0b4 TJB |
10067 | if (thread != -1) |
10068 | error(_("You can specify only one thread.")); | |
37e4754d | 10069 | |
9c06b0b4 TJB |
10070 | /* Extract the thread ID from the next token. */ |
10071 | thread = strtol (value_start, &endp, 0); | |
37e4754d | 10072 | |
9c06b0b4 TJB |
10073 | /* Check if the user provided a valid numeric value for the |
10074 | thread ID. */ | |
10075 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
10076 | error (_("Invalid thread ID specification %s."), value_start); | |
10077 | ||
10078 | /* Check if the thread actually exists. */ | |
10079 | if (!valid_thread_id (thread)) | |
10080 | error (_("Unknown thread %d."), thread); | |
10081 | } | |
10082 | else if (toklen == 4 && !strncmp (tok, "mask", 4)) | |
10083 | { | |
10084 | /* We've found a "mask" token, which means the user wants to | |
10085 | create a hardware watchpoint that is going to have the mask | |
10086 | facility. */ | |
10087 | struct value *mask_value, *mark; | |
37e4754d | 10088 | |
9c06b0b4 TJB |
10089 | if (use_mask) |
10090 | error(_("You can specify only one mask.")); | |
37e4754d | 10091 | |
9c06b0b4 | 10092 | use_mask = just_location = 1; |
37e4754d | 10093 | |
9c06b0b4 TJB |
10094 | mark = value_mark (); |
10095 | mask_value = parse_to_comma_and_eval (&value_start); | |
10096 | mask = value_as_address (mask_value); | |
10097 | value_free_to_mark (mark); | |
10098 | } | |
10099 | else | |
10100 | /* We didn't recognize what we found. We should stop here. */ | |
10101 | break; | |
37e4754d | 10102 | |
9c06b0b4 TJB |
10103 | /* Truncate the string and get rid of the "parameter value" pair before |
10104 | the arguments string is parsed by the parse_exp_1 function. */ | |
10105 | *tok = '\0'; | |
10106 | } | |
37e4754d LM |
10107 | } |
10108 | ||
10109 | /* Parse the rest of the arguments. */ | |
c906108c SS |
10110 | innermost_block = NULL; |
10111 | exp_start = arg; | |
10112 | exp = parse_exp_1 (&arg, 0, 0); | |
10113 | exp_end = arg; | |
fa8a61dc TT |
10114 | /* Remove trailing whitespace from the expression before saving it. |
10115 | This makes the eventual display of the expression string a bit | |
10116 | prettier. */ | |
10117 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
10118 | --exp_end; | |
10119 | ||
65d79d4b SDJ |
10120 | /* Checking if the expression is not constant. */ |
10121 | if (watchpoint_exp_is_const (exp)) | |
10122 | { | |
10123 | int len; | |
10124 | ||
10125 | len = exp_end - exp_start; | |
10126 | while (len > 0 && isspace (exp_start[len - 1])) | |
10127 | len--; | |
10128 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
10129 | } | |
10130 | ||
c906108c SS |
10131 | exp_valid_block = innermost_block; |
10132 | mark = value_mark (); | |
a1442452 | 10133 | fetch_subexp_value (exp, &pc, &val, &result, NULL); |
06a64a0b TT |
10134 | |
10135 | if (just_location) | |
10136 | { | |
9c06b0b4 TJB |
10137 | int ret; |
10138 | ||
06a64a0b | 10139 | exp_valid_block = NULL; |
a1442452 | 10140 | val = value_addr (result); |
06a64a0b TT |
10141 | release_value (val); |
10142 | value_free_to_mark (mark); | |
9c06b0b4 TJB |
10143 | |
10144 | if (use_mask) | |
10145 | { | |
10146 | ret = target_masked_watch_num_registers (value_as_address (val), | |
10147 | mask); | |
10148 | if (ret == -1) | |
10149 | error (_("This target does not support masked watchpoints.")); | |
10150 | else if (ret == -2) | |
10151 | error (_("Invalid mask or memory region.")); | |
10152 | } | |
06a64a0b TT |
10153 | } |
10154 | else if (val != NULL) | |
fa4727a6 | 10155 | release_value (val); |
c906108c | 10156 | |
e9cafbcc TT |
10157 | tok = skip_spaces (arg); |
10158 | end_tok = skip_to_space (tok); | |
c906108c SS |
10159 | |
10160 | toklen = end_tok - tok; | |
10161 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
10162 | { | |
2d134ed3 PA |
10163 | struct expression *cond; |
10164 | ||
60e1c644 | 10165 | innermost_block = NULL; |
c906108c SS |
10166 | tok = cond_start = end_tok + 1; |
10167 | cond = parse_exp_1 (&tok, 0, 0); | |
60e1c644 PA |
10168 | |
10169 | /* The watchpoint expression may not be local, but the condition | |
10170 | may still be. E.g.: `watch global if local > 0'. */ | |
10171 | cond_exp_valid_block = innermost_block; | |
10172 | ||
2d134ed3 | 10173 | xfree (cond); |
c906108c SS |
10174 | cond_end = tok; |
10175 | } | |
10176 | if (*tok) | |
8a3fe4f8 | 10177 | error (_("Junk at end of command.")); |
c906108c | 10178 | |
53a5351d | 10179 | if (accessflag == hw_read) |
c5aa993b | 10180 | bp_type = bp_read_watchpoint; |
53a5351d | 10181 | else if (accessflag == hw_access) |
c5aa993b JM |
10182 | bp_type = bp_access_watchpoint; |
10183 | else | |
10184 | bp_type = bp_hardware_watchpoint; | |
c906108c | 10185 | |
d983da9c | 10186 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
10187 | |
10188 | /* If the expression is "local", then set up a "watchpoint scope" | |
10189 | breakpoint at the point where we've left the scope of the watchpoint | |
10190 | expression. Create the scope breakpoint before the watchpoint, so | |
10191 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 10192 | if (exp_valid_block && frame) |
d983da9c | 10193 | { |
edb3359d DJ |
10194 | if (frame_id_p (frame_unwind_caller_id (frame))) |
10195 | { | |
10196 | scope_breakpoint | |
a6d9a66e UW |
10197 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
10198 | frame_unwind_caller_pc (frame), | |
06edf0c0 PA |
10199 | bp_watchpoint_scope, |
10200 | &momentary_breakpoint_ops); | |
d983da9c | 10201 | |
edb3359d | 10202 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 10203 | |
edb3359d DJ |
10204 | /* Automatically delete the breakpoint when it hits. */ |
10205 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 10206 | |
edb3359d DJ |
10207 | /* Only break in the proper frame (help with recursion). */ |
10208 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 10209 | |
edb3359d | 10210 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
10211 | scope_breakpoint->loc->gdbarch |
10212 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
10213 | scope_breakpoint->loc->requested_address |
10214 | = frame_unwind_caller_pc (frame); | |
10215 | scope_breakpoint->loc->address | |
a6d9a66e UW |
10216 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
10217 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
10218 | scope_breakpoint->type); |
10219 | } | |
d983da9c DJ |
10220 | } |
10221 | ||
c906108c | 10222 | /* Now set up the breakpoint. */ |
3a5c3e22 PA |
10223 | |
10224 | w = XCNEW (struct watchpoint); | |
10225 | b = &w->base; | |
348d480f | 10226 | if (use_mask) |
3a5c3e22 PA |
10227 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
10228 | &masked_watchpoint_breakpoint_ops); | |
348d480f | 10229 | else |
3a5c3e22 PA |
10230 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
10231 | &watchpoint_breakpoint_ops); | |
37e4754d | 10232 | b->thread = thread; |
b5de0fa7 | 10233 | b->disposition = disp_donttouch; |
348d480f | 10234 | b->pspace = current_program_space; |
3a5c3e22 PA |
10235 | w->exp = exp; |
10236 | w->exp_valid_block = exp_valid_block; | |
10237 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
10238 | if (just_location) |
10239 | { | |
10240 | struct type *t = value_type (val); | |
10241 | CORE_ADDR addr = value_as_address (val); | |
10242 | char *name; | |
10243 | ||
10244 | t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); | |
10245 | name = type_to_string (t); | |
10246 | ||
3a5c3e22 | 10247 | w->exp_string_reparse = xstrprintf ("* (%s *) %s", name, |
d63d0675 | 10248 | core_addr_to_string (addr)); |
06a64a0b TT |
10249 | xfree (name); |
10250 | ||
3a5c3e22 | 10251 | w->exp_string = xstrprintf ("-location %.*s", |
d63d0675 JK |
10252 | (int) (exp_end - exp_start), exp_start); |
10253 | ||
06a64a0b TT |
10254 | /* The above expression is in C. */ |
10255 | b->language = language_c; | |
10256 | } | |
10257 | else | |
3a5c3e22 | 10258 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
9c06b0b4 TJB |
10259 | |
10260 | if (use_mask) | |
10261 | { | |
3a5c3e22 | 10262 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
10263 | } |
10264 | else | |
10265 | { | |
3a5c3e22 PA |
10266 | w->val = val; |
10267 | w->val_valid = 1; | |
9c06b0b4 | 10268 | } |
77b06cd7 | 10269 | |
c906108c SS |
10270 | if (cond_start) |
10271 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
10272 | else | |
10273 | b->cond_string = 0; | |
c5aa993b | 10274 | |
c906108c | 10275 | if (frame) |
f6bc2008 | 10276 | { |
3a5c3e22 PA |
10277 | w->watchpoint_frame = get_frame_id (frame); |
10278 | w->watchpoint_thread = inferior_ptid; | |
f6bc2008 | 10279 | } |
c906108c | 10280 | else |
f6bc2008 | 10281 | { |
3a5c3e22 PA |
10282 | w->watchpoint_frame = null_frame_id; |
10283 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 10284 | } |
c906108c | 10285 | |
d983da9c | 10286 | if (scope_breakpoint != NULL) |
c906108c | 10287 | { |
d983da9c DJ |
10288 | /* The scope breakpoint is related to the watchpoint. We will |
10289 | need to act on them together. */ | |
10290 | b->related_breakpoint = scope_breakpoint; | |
10291 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 10292 | } |
d983da9c | 10293 | |
06a64a0b TT |
10294 | if (!just_location) |
10295 | value_free_to_mark (mark); | |
2d134ed3 | 10296 | |
a9634178 TJB |
10297 | TRY_CATCH (e, RETURN_MASK_ALL) |
10298 | { | |
10299 | /* Finally update the new watchpoint. This creates the locations | |
10300 | that should be inserted. */ | |
3a5c3e22 | 10301 | update_watchpoint (w, 1); |
a9634178 TJB |
10302 | } |
10303 | if (e.reason < 0) | |
10304 | { | |
10305 | delete_breakpoint (b); | |
10306 | throw_exception (e); | |
10307 | } | |
10308 | ||
3ea46bff | 10309 | install_breakpoint (internal, b, 1); |
c906108c SS |
10310 | } |
10311 | ||
e09342b5 | 10312 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 10313 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 10314 | |
c906108c | 10315 | static int |
a9634178 | 10316 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
10317 | { |
10318 | int found_memory_cnt = 0; | |
2e70b7b9 | 10319 | struct value *head = v; |
c906108c SS |
10320 | |
10321 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 10322 | if (!can_use_hw_watchpoints) |
c906108c | 10323 | return 0; |
c5aa993b | 10324 | |
5c44784c JM |
10325 | /* Make sure that the value of the expression depends only upon |
10326 | memory contents, and values computed from them within GDB. If we | |
10327 | find any register references or function calls, we can't use a | |
10328 | hardware watchpoint. | |
10329 | ||
10330 | The idea here is that evaluating an expression generates a series | |
10331 | of values, one holding the value of every subexpression. (The | |
10332 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
10333 | a*b+c.) GDB's values hold almost enough information to establish | |
10334 | the criteria given above --- they identify memory lvalues, | |
10335 | register lvalues, computed values, etcetera. So we can evaluate | |
10336 | the expression, and then scan the chain of values that leaves | |
10337 | behind to decide whether we can detect any possible change to the | |
10338 | expression's final value using only hardware watchpoints. | |
10339 | ||
10340 | However, I don't think that the values returned by inferior | |
10341 | function calls are special in any way. So this function may not | |
10342 | notice that an expression involving an inferior function call | |
10343 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 10344 | for (; v; v = value_next (v)) |
c906108c | 10345 | { |
5c44784c | 10346 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 10347 | { |
8464be76 DJ |
10348 | if (v != head && value_lazy (v)) |
10349 | /* A lazy memory lvalue in the chain is one that GDB never | |
10350 | needed to fetch; we either just used its address (e.g., | |
10351 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
10352 | in `a,b'). This doesn't apply to HEAD; if that is | |
10353 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 10354 | ; |
53a5351d | 10355 | else |
5c44784c JM |
10356 | { |
10357 | /* Ahh, memory we actually used! Check if we can cover | |
10358 | it with hardware watchpoints. */ | |
df407dfe | 10359 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
10360 | |
10361 | /* We only watch structs and arrays if user asked for it | |
10362 | explicitly, never if they just happen to appear in a | |
10363 | middle of some value chain. */ | |
10364 | if (v == head | |
10365 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
10366 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
10367 | { | |
42ae5230 | 10368 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
10369 | int len; |
10370 | int num_regs; | |
10371 | ||
a9634178 | 10372 | len = (target_exact_watchpoints |
e09342b5 TJB |
10373 | && is_scalar_type_recursive (vtype))? |
10374 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 10375 | |
e09342b5 TJB |
10376 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
10377 | if (!num_regs) | |
2e70b7b9 MS |
10378 | return 0; |
10379 | else | |
e09342b5 | 10380 | found_memory_cnt += num_regs; |
2e70b7b9 | 10381 | } |
5c44784c | 10382 | } |
c5aa993b | 10383 | } |
5086187c AC |
10384 | else if (VALUE_LVAL (v) != not_lval |
10385 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 10386 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 10387 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 10388 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
10389 | } |
10390 | ||
10391 | /* The expression itself looks suitable for using a hardware | |
10392 | watchpoint, but give the target machine a chance to reject it. */ | |
10393 | return found_memory_cnt; | |
10394 | } | |
10395 | ||
8b93c638 | 10396 | void |
84f4c1fe | 10397 | watch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 10398 | { |
84f4c1fe | 10399 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
10400 | } |
10401 | ||
10402 | /* A helper function that looks for an argument at the start of a | |
10403 | string. The argument must also either be at the end of the string, | |
10404 | or be followed by whitespace. Returns 1 if it finds the argument, | |
10405 | 0 otherwise. If the argument is found, it updates *STR. */ | |
10406 | ||
10407 | static int | |
10408 | check_for_argument (char **str, char *arg, int arg_len) | |
10409 | { | |
10410 | if (strncmp (*str, arg, arg_len) == 0 | |
10411 | && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len]))) | |
10412 | { | |
10413 | *str += arg_len; | |
10414 | return 1; | |
10415 | } | |
10416 | return 0; | |
10417 | } | |
10418 | ||
10419 | /* A helper function that looks for the "-location" argument and then | |
10420 | calls watch_command_1. */ | |
10421 | ||
10422 | static void | |
10423 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
10424 | { | |
10425 | int just_location = 0; | |
10426 | ||
10427 | if (arg | |
10428 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
10429 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
10430 | { | |
e9cafbcc | 10431 | arg = skip_spaces (arg); |
06a64a0b TT |
10432 | just_location = 1; |
10433 | } | |
10434 | ||
84f4c1fe | 10435 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 10436 | } |
8926118c | 10437 | |
c5aa993b | 10438 | static void |
fba45db2 | 10439 | watch_command (char *arg, int from_tty) |
c906108c | 10440 | { |
06a64a0b | 10441 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
10442 | } |
10443 | ||
8b93c638 | 10444 | void |
84f4c1fe | 10445 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 10446 | { |
84f4c1fe | 10447 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 10448 | } |
8926118c | 10449 | |
c5aa993b | 10450 | static void |
fba45db2 | 10451 | rwatch_command (char *arg, int from_tty) |
c906108c | 10452 | { |
06a64a0b | 10453 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
10454 | } |
10455 | ||
8b93c638 | 10456 | void |
84f4c1fe | 10457 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 10458 | { |
84f4c1fe | 10459 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 10460 | } |
8926118c | 10461 | |
c5aa993b | 10462 | static void |
fba45db2 | 10463 | awatch_command (char *arg, int from_tty) |
c906108c | 10464 | { |
06a64a0b | 10465 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 10466 | } |
c906108c | 10467 | \f |
c5aa993b | 10468 | |
43ff13b4 | 10469 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
10470 | because it uses the mechanisms of breakpoints. */ |
10471 | ||
bfec99b2 PA |
10472 | struct until_break_command_continuation_args |
10473 | { | |
10474 | struct breakpoint *breakpoint; | |
10475 | struct breakpoint *breakpoint2; | |
186c406b | 10476 | int thread_num; |
bfec99b2 PA |
10477 | }; |
10478 | ||
43ff13b4 | 10479 | /* This function is called by fetch_inferior_event via the |
4a64f543 | 10480 | cmd_continuation pointer, to complete the until command. It takes |
43ff13b4 | 10481 | care of cleaning up the temporary breakpoints set up by the until |
4a64f543 | 10482 | command. */ |
c2c6d25f | 10483 | static void |
fa4cd53f | 10484 | until_break_command_continuation (void *arg, int err) |
43ff13b4 | 10485 | { |
bfec99b2 PA |
10486 | struct until_break_command_continuation_args *a = arg; |
10487 | ||
10488 | delete_breakpoint (a->breakpoint); | |
10489 | if (a->breakpoint2) | |
10490 | delete_breakpoint (a->breakpoint2); | |
186c406b | 10491 | delete_longjmp_breakpoint (a->thread_num); |
43ff13b4 JM |
10492 | } |
10493 | ||
c906108c | 10494 | void |
ae66c1fc | 10495 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
10496 | { |
10497 | struct symtabs_and_lines sals; | |
10498 | struct symtab_and_line sal; | |
206415a3 | 10499 | struct frame_info *frame = get_selected_frame (NULL); |
883bc8d1 PA |
10500 | struct gdbarch *frame_gdbarch = get_frame_arch (frame); |
10501 | struct frame_id stack_frame_id = get_stack_frame_id (frame); | |
10502 | struct frame_id caller_frame_id = frame_unwind_caller_id (frame); | |
c906108c | 10503 | struct breakpoint *breakpoint; |
f107f563 | 10504 | struct breakpoint *breakpoint2 = NULL; |
c906108c | 10505 | struct cleanup *old_chain; |
186c406b TT |
10506 | int thread; |
10507 | struct thread_info *tp; | |
c906108c SS |
10508 | |
10509 | clear_proceed_status (); | |
10510 | ||
10511 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 10512 | this function. */ |
c5aa993b | 10513 | |
1bfeeb0f | 10514 | if (last_displayed_sal_is_valid ()) |
f8eba3c6 | 10515 | sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE, |
1bfeeb0f | 10516 | get_last_displayed_symtab (), |
f8eba3c6 | 10517 | get_last_displayed_line ()); |
c906108c | 10518 | else |
f8eba3c6 TT |
10519 | sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE, |
10520 | (struct symtab *) NULL, 0); | |
c5aa993b | 10521 | |
c906108c | 10522 | if (sals.nelts != 1) |
8a3fe4f8 | 10523 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 10524 | |
c906108c | 10525 | sal = sals.sals[0]; |
4a64f543 | 10526 | xfree (sals.sals); /* malloc'd, so freed. */ |
c5aa993b | 10527 | |
c906108c | 10528 | if (*arg) |
8a3fe4f8 | 10529 | error (_("Junk at end of arguments.")); |
c5aa993b | 10530 | |
c906108c | 10531 | resolve_sal_pc (&sal); |
c5aa993b | 10532 | |
186c406b TT |
10533 | tp = inferior_thread (); |
10534 | thread = tp->num; | |
10535 | ||
883bc8d1 PA |
10536 | old_chain = make_cleanup (null_cleanup, NULL); |
10537 | ||
10538 | /* Installing a breakpoint invalidates the frame chain (as it may | |
10539 | need to switch threads), so do any frame handling first. */ | |
10540 | ||
ae66c1fc EZ |
10541 | /* Keep within the current frame, or in frames called by the current |
10542 | one. */ | |
edb3359d | 10543 | |
883bc8d1 | 10544 | if (frame_id_p (caller_frame_id)) |
c906108c | 10545 | { |
883bc8d1 PA |
10546 | struct symtab_and_line sal2; |
10547 | ||
10548 | sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0); | |
10549 | sal2.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e | 10550 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
883bc8d1 PA |
10551 | sal2, |
10552 | caller_frame_id, | |
f107f563 VP |
10553 | bp_until); |
10554 | make_cleanup_delete_breakpoint (breakpoint2); | |
186c406b | 10555 | |
883bc8d1 | 10556 | set_longjmp_breakpoint (tp, caller_frame_id); |
186c406b | 10557 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); |
c906108c | 10558 | } |
c5aa993b | 10559 | |
c70a6932 JK |
10560 | /* set_momentary_breakpoint could invalidate FRAME. */ |
10561 | frame = NULL; | |
10562 | ||
883bc8d1 PA |
10563 | if (anywhere) |
10564 | /* If the user told us to continue until a specified location, | |
10565 | we don't specify a frame at which we need to stop. */ | |
10566 | breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, | |
10567 | null_frame_id, bp_until); | |
10568 | else | |
10569 | /* Otherwise, specify the selected frame, because we want to stop | |
10570 | only at the very same frame. */ | |
10571 | breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, | |
10572 | stack_frame_id, bp_until); | |
10573 | make_cleanup_delete_breakpoint (breakpoint); | |
10574 | ||
c906108c | 10575 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
f107f563 | 10576 | |
4a64f543 MS |
10577 | /* If we are running asynchronously, and proceed call above has |
10578 | actually managed to start the target, arrange for breakpoints to | |
10579 | be deleted when the target stops. Otherwise, we're already | |
10580 | stopped and delete breakpoints via cleanup chain. */ | |
f107f563 | 10581 | |
8ea051c5 | 10582 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 10583 | { |
bfec99b2 PA |
10584 | struct until_break_command_continuation_args *args; |
10585 | args = xmalloc (sizeof (*args)); | |
f107f563 | 10586 | |
bfec99b2 PA |
10587 | args->breakpoint = breakpoint; |
10588 | args->breakpoint2 = breakpoint2; | |
186c406b | 10589 | args->thread_num = thread; |
f107f563 VP |
10590 | |
10591 | discard_cleanups (old_chain); | |
95e54da7 PA |
10592 | add_continuation (inferior_thread (), |
10593 | until_break_command_continuation, args, | |
604ead4a | 10594 | xfree); |
f107f563 VP |
10595 | } |
10596 | else | |
c5aa993b | 10597 | do_cleanups (old_chain); |
c906108c | 10598 | } |
ae66c1fc | 10599 | |
c906108c SS |
10600 | /* This function attempts to parse an optional "if <cond>" clause |
10601 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 10602 | |
c906108c SS |
10603 | Else, it returns a pointer to the condition string. (It does not |
10604 | attempt to evaluate the string against a particular block.) And, | |
10605 | it updates arg to point to the first character following the parsed | |
4a64f543 | 10606 | if clause in the arg string. */ |
53a5351d | 10607 | |
c906108c | 10608 | static char * |
fba45db2 | 10609 | ep_parse_optional_if_clause (char **arg) |
c906108c | 10610 | { |
c5aa993b JM |
10611 | char *cond_string; |
10612 | ||
10613 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 10614 | return NULL; |
c5aa993b | 10615 | |
4a64f543 | 10616 | /* Skip the "if" keyword. */ |
c906108c | 10617 | (*arg) += 2; |
c5aa993b | 10618 | |
c906108c | 10619 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 10620 | condition string. */ |
e9cafbcc | 10621 | *arg = skip_spaces (*arg); |
c906108c | 10622 | cond_string = *arg; |
c5aa993b | 10623 | |
4a64f543 MS |
10624 | /* Assume that the condition occupies the remainder of the arg |
10625 | string. */ | |
c906108c | 10626 | (*arg) += strlen (cond_string); |
c5aa993b | 10627 | |
c906108c SS |
10628 | return cond_string; |
10629 | } | |
c5aa993b | 10630 | |
c906108c SS |
10631 | /* Commands to deal with catching events, such as signals, exceptions, |
10632 | process start/exit, etc. */ | |
c5aa993b JM |
10633 | |
10634 | typedef enum | |
10635 | { | |
44feb3ce TT |
10636 | catch_fork_temporary, catch_vfork_temporary, |
10637 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
10638 | } |
10639 | catch_fork_kind; | |
10640 | ||
c906108c | 10641 | static void |
cc59ec59 MS |
10642 | catch_fork_command_1 (char *arg, int from_tty, |
10643 | struct cmd_list_element *command) | |
c906108c | 10644 | { |
a6d9a66e | 10645 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 10646 | char *cond_string = NULL; |
44feb3ce TT |
10647 | catch_fork_kind fork_kind; |
10648 | int tempflag; | |
10649 | ||
10650 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
10651 | tempflag = (fork_kind == catch_fork_temporary | |
10652 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 10653 | |
44feb3ce TT |
10654 | if (!arg) |
10655 | arg = ""; | |
e9cafbcc | 10656 | arg = skip_spaces (arg); |
c5aa993b | 10657 | |
c906108c | 10658 | /* The allowed syntax is: |
c5aa993b JM |
10659 | catch [v]fork |
10660 | catch [v]fork if <cond> | |
10661 | ||
4a64f543 | 10662 | First, check if there's an if clause. */ |
c906108c | 10663 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 10664 | |
c906108c | 10665 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 10666 | error (_("Junk at end of arguments.")); |
c5aa993b | 10667 | |
c906108c | 10668 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 10669 | and enable reporting of such events. */ |
c5aa993b JM |
10670 | switch (fork_kind) |
10671 | { | |
44feb3ce TT |
10672 | case catch_fork_temporary: |
10673 | case catch_fork_permanent: | |
a6d9a66e | 10674 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 10675 | &catch_fork_breakpoint_ops); |
c906108c | 10676 | break; |
44feb3ce TT |
10677 | case catch_vfork_temporary: |
10678 | case catch_vfork_permanent: | |
a6d9a66e | 10679 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 10680 | &catch_vfork_breakpoint_ops); |
c906108c | 10681 | break; |
c5aa993b | 10682 | default: |
8a3fe4f8 | 10683 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 10684 | break; |
c5aa993b | 10685 | } |
c906108c SS |
10686 | } |
10687 | ||
10688 | static void | |
cc59ec59 MS |
10689 | catch_exec_command_1 (char *arg, int from_tty, |
10690 | struct cmd_list_element *command) | |
c906108c | 10691 | { |
b4d90040 | 10692 | struct exec_catchpoint *c; |
a6d9a66e | 10693 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 10694 | int tempflag; |
c5aa993b | 10695 | char *cond_string = NULL; |
c906108c | 10696 | |
44feb3ce TT |
10697 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
10698 | ||
10699 | if (!arg) | |
10700 | arg = ""; | |
e9cafbcc | 10701 | arg = skip_spaces (arg); |
c906108c SS |
10702 | |
10703 | /* The allowed syntax is: | |
c5aa993b JM |
10704 | catch exec |
10705 | catch exec if <cond> | |
c906108c | 10706 | |
4a64f543 | 10707 | First, check if there's an if clause. */ |
c906108c SS |
10708 | cond_string = ep_parse_optional_if_clause (&arg); |
10709 | ||
10710 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 10711 | error (_("Junk at end of arguments.")); |
c906108c | 10712 | |
b4d90040 PA |
10713 | c = XNEW (struct exec_catchpoint); |
10714 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, | |
10715 | &catch_exec_breakpoint_ops); | |
10716 | c->exec_pathname = NULL; | |
10717 | ||
3ea46bff | 10718 | install_breakpoint (0, &c->base, 1); |
c906108c | 10719 | } |
c5aa993b | 10720 | |
3086aeae | 10721 | static enum print_stop_action |
348d480f | 10722 | print_it_exception_catchpoint (bpstat bs) |
3086aeae | 10723 | { |
79a45e25 | 10724 | struct ui_out *uiout = current_uiout; |
348d480f | 10725 | struct breakpoint *b = bs->breakpoint_at; |
ade92717 | 10726 | int bp_temp, bp_throw; |
3086aeae | 10727 | |
ade92717 | 10728 | annotate_catchpoint (b->number); |
3086aeae | 10729 | |
ade92717 AR |
10730 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
10731 | if (b->loc->address != b->loc->requested_address) | |
10732 | breakpoint_adjustment_warning (b->loc->requested_address, | |
10733 | b->loc->address, | |
10734 | b->number, 1); | |
df2b6d2d | 10735 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
10736 | ui_out_text (uiout, |
10737 | bp_temp ? "Temporary catchpoint " | |
10738 | : "Catchpoint "); | |
10739 | if (!ui_out_is_mi_like_p (uiout)) | |
10740 | ui_out_field_int (uiout, "bkptno", b->number); | |
10741 | ui_out_text (uiout, | |
c0b37c48 AR |
10742 | bp_throw ? " (exception thrown), " |
10743 | : " (exception caught), "); | |
ade92717 AR |
10744 | if (ui_out_is_mi_like_p (uiout)) |
10745 | { | |
10746 | ui_out_field_string (uiout, "reason", | |
10747 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
10748 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
10749 | ui_out_field_int (uiout, "bkptno", b->number); | |
10750 | } | |
3086aeae DJ |
10751 | return PRINT_SRC_AND_LOC; |
10752 | } | |
10753 | ||
10754 | static void | |
cc59ec59 MS |
10755 | print_one_exception_catchpoint (struct breakpoint *b, |
10756 | struct bp_location **last_loc) | |
3086aeae | 10757 | { |
79a45b7d | 10758 | struct value_print_options opts; |
79a45e25 | 10759 | struct ui_out *uiout = current_uiout; |
cc59ec59 | 10760 | |
79a45b7d TT |
10761 | get_user_print_options (&opts); |
10762 | if (opts.addressprint) | |
3086aeae DJ |
10763 | { |
10764 | annotate_field (4); | |
604133b5 AR |
10765 | if (b->loc == NULL || b->loc->shlib_disabled) |
10766 | ui_out_field_string (uiout, "addr", "<PENDING>"); | |
10767 | else | |
5af949e3 UW |
10768 | ui_out_field_core_addr (uiout, "addr", |
10769 | b->loc->gdbarch, b->loc->address); | |
3086aeae DJ |
10770 | } |
10771 | annotate_field (5); | |
604133b5 | 10772 | if (b->loc) |
a6d9a66e | 10773 | *last_loc = b->loc; |
3086aeae DJ |
10774 | if (strstr (b->addr_string, "throw") != NULL) |
10775 | ui_out_field_string (uiout, "what", "exception throw"); | |
10776 | else | |
10777 | ui_out_field_string (uiout, "what", "exception catch"); | |
10778 | } | |
10779 | ||
10780 | static void | |
10781 | print_mention_exception_catchpoint (struct breakpoint *b) | |
10782 | { | |
79a45e25 | 10783 | struct ui_out *uiout = current_uiout; |
ade92717 AR |
10784 | int bp_temp; |
10785 | int bp_throw; | |
10786 | ||
df2b6d2d | 10787 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
10788 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
10789 | ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ") | |
10790 | : _("Catchpoint ")); | |
10791 | ui_out_field_int (uiout, "bkptno", b->number); | |
10792 | ui_out_text (uiout, bp_throw ? _(" (throw)") | |
10793 | : _(" (catch)")); | |
3086aeae DJ |
10794 | } |
10795 | ||
6149aea9 PA |
10796 | /* Implement the "print_recreate" breakpoint_ops method for throw and |
10797 | catch catchpoints. */ | |
10798 | ||
10799 | static void | |
4a64f543 MS |
10800 | print_recreate_exception_catchpoint (struct breakpoint *b, |
10801 | struct ui_file *fp) | |
6149aea9 PA |
10802 | { |
10803 | int bp_temp; | |
10804 | int bp_throw; | |
10805 | ||
10806 | bp_temp = b->disposition == disp_del; | |
10807 | bp_throw = strstr (b->addr_string, "throw") != NULL; | |
10808 | fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch "); | |
10809 | fprintf_unfiltered (fp, bp_throw ? "throw" : "catch"); | |
d9b3f62e | 10810 | print_recreate_thread (b, fp); |
6149aea9 PA |
10811 | } |
10812 | ||
2060206e | 10813 | static struct breakpoint_ops gnu_v3_exception_catchpoint_ops; |
3086aeae DJ |
10814 | |
10815 | static int | |
10816 | handle_gnu_v3_exceptions (int tempflag, char *cond_string, | |
10817 | enum exception_event_kind ex_event, int from_tty) | |
10818 | { | |
604133b5 AR |
10819 | char *trigger_func_name; |
10820 | ||
3086aeae | 10821 | if (ex_event == EX_EVENT_CATCH) |
604133b5 | 10822 | trigger_func_name = "__cxa_begin_catch"; |
3086aeae | 10823 | else |
604133b5 | 10824 | trigger_func_name = "__cxa_throw"; |
3086aeae | 10825 | |
8cdf0e15 VP |
10826 | create_breakpoint (get_current_arch (), |
10827 | trigger_func_name, cond_string, -1, | |
10828 | 0 /* condition and thread are valid. */, | |
0fb4aa4b | 10829 | tempflag, bp_breakpoint, |
8cdf0e15 VP |
10830 | 0, |
10831 | AUTO_BOOLEAN_TRUE /* pending */, | |
10832 | &gnu_v3_exception_catchpoint_ops, from_tty, | |
84f4c1fe | 10833 | 1 /* enabled */, |
44f238bb PA |
10834 | 0 /* internal */, |
10835 | 0); | |
3086aeae | 10836 | |
3086aeae DJ |
10837 | return 1; |
10838 | } | |
10839 | ||
4a64f543 | 10840 | /* Deal with "catch catch" and "catch throw" commands. */ |
c906108c SS |
10841 | |
10842 | static void | |
fba45db2 KB |
10843 | catch_exception_command_1 (enum exception_event_kind ex_event, char *arg, |
10844 | int tempflag, int from_tty) | |
c906108c | 10845 | { |
c5aa993b | 10846 | char *cond_string = NULL; |
c5aa993b | 10847 | |
44feb3ce TT |
10848 | if (!arg) |
10849 | arg = ""; | |
e9cafbcc | 10850 | arg = skip_spaces (arg); |
c5aa993b | 10851 | |
c906108c SS |
10852 | cond_string = ep_parse_optional_if_clause (&arg); |
10853 | ||
10854 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 10855 | error (_("Junk at end of arguments.")); |
c906108c | 10856 | |
059fb39f PM |
10857 | if (ex_event != EX_EVENT_THROW |
10858 | && ex_event != EX_EVENT_CATCH) | |
8a3fe4f8 | 10859 | error (_("Unsupported or unknown exception event; cannot catch it")); |
c906108c | 10860 | |
3086aeae DJ |
10861 | if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty)) |
10862 | return; | |
10863 | ||
8a3fe4f8 | 10864 | warning (_("Unsupported with this platform/compiler combination.")); |
c906108c SS |
10865 | } |
10866 | ||
44feb3ce TT |
10867 | /* Implementation of "catch catch" command. */ |
10868 | ||
10869 | static void | |
10870 | catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command) | |
10871 | { | |
10872 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
cc59ec59 | 10873 | |
44feb3ce TT |
10874 | catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty); |
10875 | } | |
10876 | ||
10877 | /* Implementation of "catch throw" command. */ | |
10878 | ||
10879 | static void | |
10880 | catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command) | |
10881 | { | |
10882 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
cc59ec59 | 10883 | |
44feb3ce TT |
10884 | catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty); |
10885 | } | |
10886 | ||
9ac4176b | 10887 | void |
28010a5d PA |
10888 | init_ada_exception_breakpoint (struct breakpoint *b, |
10889 | struct gdbarch *gdbarch, | |
10890 | struct symtab_and_line sal, | |
10891 | char *addr_string, | |
c0a91b2b | 10892 | const struct breakpoint_ops *ops, |
28010a5d PA |
10893 | int tempflag, |
10894 | int from_tty) | |
f7f9143b | 10895 | { |
f7f9143b JB |
10896 | if (from_tty) |
10897 | { | |
5af949e3 UW |
10898 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
10899 | if (!loc_gdbarch) | |
10900 | loc_gdbarch = gdbarch; | |
10901 | ||
6c95b8df PA |
10902 | describe_other_breakpoints (loc_gdbarch, |
10903 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
10904 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
10905 | version for exception catchpoints, because two catchpoints | |
10906 | used for different exception names will use the same address. | |
10907 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 10908 | unproductive. Besides, the warning phrasing is also a bit |
e5dd4106 | 10909 | inappropriate, we should use the word catchpoint, and tell |
f7f9143b JB |
10910 | the user what type of catchpoint it is. The above is good |
10911 | enough for now, though. */ | |
10912 | } | |
10913 | ||
28010a5d | 10914 | init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops); |
f7f9143b JB |
10915 | |
10916 | b->enable_state = bp_enabled; | |
10917 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
f7f9143b JB |
10918 | b->addr_string = addr_string; |
10919 | b->language = language_ada; | |
f7f9143b JB |
10920 | } |
10921 | ||
a96d9b2e SDJ |
10922 | /* Splits the argument using space as delimiter. Returns an xmalloc'd |
10923 | filter list, or NULL if no filtering is required. */ | |
10924 | static VEC(int) * | |
10925 | catch_syscall_split_args (char *arg) | |
10926 | { | |
10927 | VEC(int) *result = NULL; | |
29d0bb3d | 10928 | struct cleanup *cleanup = make_cleanup (VEC_cleanup (int), &result); |
a96d9b2e SDJ |
10929 | |
10930 | while (*arg != '\0') | |
10931 | { | |
10932 | int i, syscall_number; | |
10933 | char *endptr; | |
10934 | char cur_name[128]; | |
10935 | struct syscall s; | |
10936 | ||
10937 | /* Skip whitespace. */ | |
10938 | while (isspace (*arg)) | |
10939 | arg++; | |
10940 | ||
10941 | for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) | |
10942 | cur_name[i] = arg[i]; | |
10943 | cur_name[i] = '\0'; | |
10944 | arg += i; | |
10945 | ||
10946 | /* Check if the user provided a syscall name or a number. */ | |
10947 | syscall_number = (int) strtol (cur_name, &endptr, 0); | |
10948 | if (*endptr == '\0') | |
bccd0dd2 | 10949 | get_syscall_by_number (syscall_number, &s); |
a96d9b2e SDJ |
10950 | else |
10951 | { | |
10952 | /* We have a name. Let's check if it's valid and convert it | |
10953 | to a number. */ | |
10954 | get_syscall_by_name (cur_name, &s); | |
10955 | ||
10956 | if (s.number == UNKNOWN_SYSCALL) | |
4a64f543 MS |
10957 | /* Here we have to issue an error instead of a warning, |
10958 | because GDB cannot do anything useful if there's no | |
10959 | syscall number to be caught. */ | |
a96d9b2e SDJ |
10960 | error (_("Unknown syscall name '%s'."), cur_name); |
10961 | } | |
10962 | ||
10963 | /* Ok, it's valid. */ | |
10964 | VEC_safe_push (int, result, s.number); | |
10965 | } | |
10966 | ||
10967 | discard_cleanups (cleanup); | |
10968 | return result; | |
10969 | } | |
10970 | ||
10971 | /* Implement the "catch syscall" command. */ | |
10972 | ||
10973 | static void | |
cc59ec59 MS |
10974 | catch_syscall_command_1 (char *arg, int from_tty, |
10975 | struct cmd_list_element *command) | |
a96d9b2e SDJ |
10976 | { |
10977 | int tempflag; | |
10978 | VEC(int) *filter; | |
10979 | struct syscall s; | |
10980 | struct gdbarch *gdbarch = get_current_arch (); | |
10981 | ||
10982 | /* Checking if the feature if supported. */ | |
10983 | if (gdbarch_get_syscall_number_p (gdbarch) == 0) | |
10984 | error (_("The feature 'catch syscall' is not supported on \ | |
ea666128 | 10985 | this architecture yet.")); |
a96d9b2e SDJ |
10986 | |
10987 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
10988 | ||
e9cafbcc | 10989 | arg = skip_spaces (arg); |
a96d9b2e SDJ |
10990 | |
10991 | /* We need to do this first "dummy" translation in order | |
10992 | to get the syscall XML file loaded or, most important, | |
10993 | to display a warning to the user if there's no XML file | |
10994 | for his/her architecture. */ | |
10995 | get_syscall_by_number (0, &s); | |
10996 | ||
10997 | /* The allowed syntax is: | |
10998 | catch syscall | |
10999 | catch syscall <name | number> [<name | number> ... <name | number>] | |
11000 | ||
11001 | Let's check if there's a syscall name. */ | |
11002 | ||
11003 | if (arg != NULL) | |
11004 | filter = catch_syscall_split_args (arg); | |
11005 | else | |
11006 | filter = NULL; | |
11007 | ||
11008 | create_syscall_event_catchpoint (tempflag, filter, | |
11009 | &catch_syscall_breakpoint_ops); | |
11010 | } | |
11011 | ||
c906108c | 11012 | static void |
fba45db2 | 11013 | catch_command (char *arg, int from_tty) |
c906108c | 11014 | { |
44feb3ce | 11015 | error (_("Catch requires an event name.")); |
c906108c SS |
11016 | } |
11017 | \f | |
11018 | ||
11019 | static void | |
fba45db2 | 11020 | tcatch_command (char *arg, int from_tty) |
c906108c | 11021 | { |
44feb3ce | 11022 | error (_("Catch requires an event name.")); |
c906108c SS |
11023 | } |
11024 | ||
8a2c437b TT |
11025 | /* A qsort comparison function that sorts breakpoints in order. */ |
11026 | ||
11027 | static int | |
11028 | compare_breakpoints (const void *a, const void *b) | |
11029 | { | |
11030 | const breakpoint_p *ba = a; | |
11031 | uintptr_t ua = (uintptr_t) *ba; | |
11032 | const breakpoint_p *bb = b; | |
11033 | uintptr_t ub = (uintptr_t) *bb; | |
11034 | ||
11035 | if ((*ba)->number < (*bb)->number) | |
11036 | return -1; | |
11037 | else if ((*ba)->number > (*bb)->number) | |
11038 | return 1; | |
11039 | ||
11040 | /* Now sort by address, in case we see, e..g, two breakpoints with | |
11041 | the number 0. */ | |
11042 | if (ua < ub) | |
11043 | return -1; | |
11044 | return ub > ub ? 1 : 0; | |
11045 | } | |
11046 | ||
80f8a6eb | 11047 | /* Delete breakpoints by address or line. */ |
c906108c SS |
11048 | |
11049 | static void | |
fba45db2 | 11050 | clear_command (char *arg, int from_tty) |
c906108c | 11051 | { |
8a2c437b | 11052 | struct breakpoint *b, *prev; |
d6e956e5 VP |
11053 | VEC(breakpoint_p) *found = 0; |
11054 | int ix; | |
c906108c SS |
11055 | int default_match; |
11056 | struct symtabs_and_lines sals; | |
11057 | struct symtab_and_line sal; | |
c906108c | 11058 | int i; |
8a2c437b | 11059 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
c906108c SS |
11060 | |
11061 | if (arg) | |
11062 | { | |
f8eba3c6 TT |
11063 | sals = decode_line_spec (arg, (DECODE_LINE_FUNFIRSTLINE |
11064 | | DECODE_LINE_LIST_MODE)); | |
c906108c SS |
11065 | default_match = 0; |
11066 | } | |
11067 | else | |
11068 | { | |
c5aa993b | 11069 | sals.sals = (struct symtab_and_line *) |
c906108c | 11070 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 11071 | make_cleanup (xfree, sals.sals); |
4a64f543 | 11072 | init_sal (&sal); /* Initialize to zeroes. */ |
1bfeeb0f JL |
11073 | |
11074 | /* Set sal's line, symtab, pc, and pspace to the values | |
11075 | corresponding to the last call to print_frame_info. If the | |
11076 | codepoint is not valid, this will set all the fields to 0. */ | |
11077 | get_last_displayed_sal (&sal); | |
c906108c | 11078 | if (sal.symtab == 0) |
8a3fe4f8 | 11079 | error (_("No source file specified.")); |
c906108c SS |
11080 | |
11081 | sals.sals[0] = sal; | |
11082 | sals.nelts = 1; | |
11083 | ||
11084 | default_match = 1; | |
11085 | } | |
11086 | ||
4a64f543 MS |
11087 | /* We don't call resolve_sal_pc here. That's not as bad as it |
11088 | seems, because all existing breakpoints typically have both | |
11089 | file/line and pc set. So, if clear is given file/line, we can | |
11090 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
11091 | |
11092 | We only support clearing given the address explicitly | |
11093 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 11094 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 11095 | due to optimization, all in one block. |
4a64f543 MS |
11096 | |
11097 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
11098 | PC corresponding to the same file:line, the breakpoint won't |
11099 | be cleared. We probably can still clear the breakpoint, but | |
11100 | since the other PC value is never presented to user, user | |
11101 | can only find it by guessing, and it does not seem important | |
11102 | to support that. */ | |
11103 | ||
4a64f543 MS |
11104 | /* For each line spec given, delete bps which correspond to it. Do |
11105 | it in two passes, solely to preserve the current behavior that | |
11106 | from_tty is forced true if we delete more than one | |
11107 | breakpoint. */ | |
c906108c | 11108 | |
80f8a6eb | 11109 | found = NULL; |
8a2c437b | 11110 | make_cleanup (VEC_cleanup (breakpoint_p), &found); |
c906108c SS |
11111 | for (i = 0; i < sals.nelts; i++) |
11112 | { | |
4aac40c8 TT |
11113 | int is_abs, sal_name_len; |
11114 | ||
c906108c | 11115 | /* If exact pc given, clear bpts at that pc. |
c5aa993b JM |
11116 | If line given (pc == 0), clear all bpts on specified line. |
11117 | If defaulting, clear all bpts on default line | |
c906108c | 11118 | or at default pc. |
c5aa993b JM |
11119 | |
11120 | defaulting sal.pc != 0 tests to do | |
11121 | ||
11122 | 0 1 pc | |
11123 | 1 1 pc _and_ line | |
11124 | 0 0 line | |
11125 | 1 0 <can't happen> */ | |
c906108c SS |
11126 | |
11127 | sal = sals.sals[i]; | |
4aac40c8 TT |
11128 | is_abs = sal.symtab == NULL ? 1 : IS_ABSOLUTE_PATH (sal.symtab->filename); |
11129 | sal_name_len = is_abs ? 0 : strlen (sal.symtab->filename); | |
c906108c | 11130 | |
4a64f543 | 11131 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 11132 | ALL_BREAKPOINTS (b) |
c5aa993b | 11133 | { |
0d381245 | 11134 | int match = 0; |
4a64f543 | 11135 | /* Are we going to delete b? */ |
cc60f2e3 | 11136 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
11137 | { |
11138 | struct bp_location *loc = b->loc; | |
11139 | for (; loc; loc = loc->next) | |
11140 | { | |
f8eba3c6 TT |
11141 | /* If the user specified file:line, don't allow a PC |
11142 | match. This matches historical gdb behavior. */ | |
11143 | int pc_match = (!sal.explicit_line | |
11144 | && sal.pc | |
11145 | && (loc->pspace == sal.pspace) | |
11146 | && (loc->address == sal.pc) | |
11147 | && (!section_is_overlay (loc->section) | |
11148 | || loc->section == sal.section)); | |
4aac40c8 TT |
11149 | int line_match = 0; |
11150 | ||
11151 | if ((default_match || sal.explicit_line) | |
11152 | && loc->source_file != NULL | |
11153 | && sal.symtab != NULL | |
11154 | && sal.pspace == loc->pspace | |
11155 | && loc->line_number == sal.line) | |
11156 | { | |
11157 | if (filename_cmp (loc->source_file, | |
11158 | sal.symtab->filename) == 0) | |
11159 | line_match = 1; | |
11160 | else if (!IS_ABSOLUTE_PATH (sal.symtab->filename) | |
11161 | && compare_filenames_for_search (loc->source_file, | |
11162 | sal.symtab->filename, | |
11163 | sal_name_len)) | |
11164 | line_match = 1; | |
11165 | } | |
11166 | ||
0d381245 VP |
11167 | if (pc_match || line_match) |
11168 | { | |
11169 | match = 1; | |
11170 | break; | |
11171 | } | |
11172 | } | |
11173 | } | |
11174 | ||
11175 | if (match) | |
d6e956e5 | 11176 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 11177 | } |
80f8a6eb | 11178 | } |
8a2c437b | 11179 | |
80f8a6eb | 11180 | /* Now go thru the 'found' chain and delete them. */ |
d6e956e5 | 11181 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
11182 | { |
11183 | if (arg) | |
8a3fe4f8 | 11184 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 11185 | else |
8a3fe4f8 | 11186 | error (_("No breakpoint at this line.")); |
80f8a6eb | 11187 | } |
c906108c | 11188 | |
8a2c437b TT |
11189 | /* Remove duplicates from the vec. */ |
11190 | qsort (VEC_address (breakpoint_p, found), | |
11191 | VEC_length (breakpoint_p, found), | |
11192 | sizeof (breakpoint_p), | |
11193 | compare_breakpoints); | |
11194 | prev = VEC_index (breakpoint_p, found, 0); | |
11195 | for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix) | |
11196 | { | |
11197 | if (b == prev) | |
11198 | { | |
11199 | VEC_ordered_remove (breakpoint_p, found, ix); | |
11200 | --ix; | |
11201 | } | |
11202 | } | |
11203 | ||
d6e956e5 | 11204 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 11205 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 11206 | if (from_tty) |
a3f17187 | 11207 | { |
d6e956e5 | 11208 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
11209 | printf_unfiltered (_("Deleted breakpoint ")); |
11210 | else | |
11211 | printf_unfiltered (_("Deleted breakpoints ")); | |
11212 | } | |
80f8a6eb | 11213 | breakpoints_changed (); |
d6e956e5 VP |
11214 | |
11215 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 11216 | { |
c5aa993b | 11217 | if (from_tty) |
d6e956e5 VP |
11218 | printf_unfiltered ("%d ", b->number); |
11219 | delete_breakpoint (b); | |
c906108c | 11220 | } |
80f8a6eb MS |
11221 | if (from_tty) |
11222 | putchar_unfiltered ('\n'); | |
8a2c437b TT |
11223 | |
11224 | do_cleanups (cleanups); | |
c906108c SS |
11225 | } |
11226 | \f | |
11227 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
11228 | all breakpoints that are marked for deletion, whether hit or not. | |
11229 | This is called after any breakpoint is hit, or after errors. */ | |
11230 | ||
11231 | void | |
fba45db2 | 11232 | breakpoint_auto_delete (bpstat bs) |
c906108c | 11233 | { |
35df4500 | 11234 | struct breakpoint *b, *b_tmp; |
c906108c SS |
11235 | |
11236 | for (; bs; bs = bs->next) | |
f431efe5 PA |
11237 | if (bs->breakpoint_at |
11238 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 11239 | && bs->stop) |
f431efe5 | 11240 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 11241 | |
35df4500 | 11242 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 11243 | { |
b5de0fa7 | 11244 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
11245 | delete_breakpoint (b); |
11246 | } | |
c906108c SS |
11247 | } |
11248 | ||
4a64f543 MS |
11249 | /* A comparison function for bp_location AP and BP being interfaced to |
11250 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
11251 | does breakpoint_address_is_meaningful say for its OWNER), | |
11252 | secondarily by ordering first bp_permanent OWNERed elements and | |
11253 | terciarily just ensuring the array is sorted stable way despite | |
e5dd4106 | 11254 | qsort being an unstable algorithm. */ |
876fa593 JK |
11255 | |
11256 | static int | |
494cfb0f | 11257 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 11258 | { |
494cfb0f JK |
11259 | struct bp_location *a = *(void **) ap; |
11260 | struct bp_location *b = *(void **) bp; | |
2bdf28a0 | 11261 | /* A and B come from existing breakpoints having non-NULL OWNER. */ |
876fa593 JK |
11262 | int a_perm = a->owner->enable_state == bp_permanent; |
11263 | int b_perm = b->owner->enable_state == bp_permanent; | |
11264 | ||
11265 | if (a->address != b->address) | |
11266 | return (a->address > b->address) - (a->address < b->address); | |
11267 | ||
dea2aa5f LM |
11268 | /* Sort locations at the same address by their pspace number, keeping |
11269 | locations of the same inferior (in a multi-inferior environment) | |
11270 | grouped. */ | |
11271 | ||
11272 | if (a->pspace->num != b->pspace->num) | |
11273 | return ((a->pspace->num > b->pspace->num) | |
11274 | - (a->pspace->num < b->pspace->num)); | |
11275 | ||
876fa593 JK |
11276 | /* Sort permanent breakpoints first. */ |
11277 | if (a_perm != b_perm) | |
11278 | return (a_perm < b_perm) - (a_perm > b_perm); | |
11279 | ||
c56a97f9 JK |
11280 | /* Make the internal GDB representation stable across GDB runs |
11281 | where A and B memory inside GDB can differ. Breakpoint locations of | |
11282 | the same type at the same address can be sorted in arbitrary order. */ | |
876fa593 JK |
11283 | |
11284 | if (a->owner->number != b->owner->number) | |
c56a97f9 JK |
11285 | return ((a->owner->number > b->owner->number) |
11286 | - (a->owner->number < b->owner->number)); | |
876fa593 JK |
11287 | |
11288 | return (a > b) - (a < b); | |
11289 | } | |
11290 | ||
876fa593 | 11291 | /* Set bp_location_placed_address_before_address_max and |
4a64f543 MS |
11292 | bp_location_shadow_len_after_address_max according to the current |
11293 | content of the bp_location array. */ | |
f7545552 TT |
11294 | |
11295 | static void | |
876fa593 | 11296 | bp_location_target_extensions_update (void) |
f7545552 | 11297 | { |
876fa593 JK |
11298 | struct bp_location *bl, **blp_tmp; |
11299 | ||
11300 | bp_location_placed_address_before_address_max = 0; | |
11301 | bp_location_shadow_len_after_address_max = 0; | |
11302 | ||
11303 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
11304 | { | |
11305 | CORE_ADDR start, end, addr; | |
11306 | ||
11307 | if (!bp_location_has_shadow (bl)) | |
11308 | continue; | |
11309 | ||
11310 | start = bl->target_info.placed_address; | |
11311 | end = start + bl->target_info.shadow_len; | |
11312 | ||
11313 | gdb_assert (bl->address >= start); | |
11314 | addr = bl->address - start; | |
11315 | if (addr > bp_location_placed_address_before_address_max) | |
11316 | bp_location_placed_address_before_address_max = addr; | |
11317 | ||
11318 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
11319 | ||
11320 | gdb_assert (bl->address < end); | |
11321 | addr = end - bl->address; | |
11322 | if (addr > bp_location_shadow_len_after_address_max) | |
11323 | bp_location_shadow_len_after_address_max = addr; | |
11324 | } | |
f7545552 TT |
11325 | } |
11326 | ||
1e4d1764 YQ |
11327 | /* Download tracepoint locations if they haven't been. */ |
11328 | ||
11329 | static void | |
11330 | download_tracepoint_locations (void) | |
11331 | { | |
11332 | struct bp_location *bl, **blp_tmp; | |
11333 | struct cleanup *old_chain; | |
11334 | ||
11335 | if (!target_can_download_tracepoint ()) | |
11336 | return; | |
11337 | ||
11338 | old_chain = save_current_space_and_thread (); | |
11339 | ||
11340 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
11341 | { | |
11342 | struct tracepoint *t; | |
11343 | ||
11344 | if (!is_tracepoint (bl->owner)) | |
11345 | continue; | |
11346 | ||
11347 | if ((bl->owner->type == bp_fast_tracepoint | |
11348 | ? !may_insert_fast_tracepoints | |
11349 | : !may_insert_tracepoints)) | |
11350 | continue; | |
11351 | ||
11352 | /* In tracepoint, locations are _never_ duplicated, so | |
11353 | should_be_inserted is equivalent to | |
11354 | unduplicated_should_be_inserted. */ | |
11355 | if (!should_be_inserted (bl) || bl->inserted) | |
11356 | continue; | |
11357 | ||
11358 | switch_to_program_space_and_thread (bl->pspace); | |
11359 | ||
11360 | target_download_tracepoint (bl); | |
11361 | ||
11362 | bl->inserted = 1; | |
11363 | t = (struct tracepoint *) bl->owner; | |
11364 | t->number_on_target = bl->owner->number; | |
11365 | } | |
11366 | ||
11367 | do_cleanups (old_chain); | |
11368 | } | |
11369 | ||
934709f0 PW |
11370 | /* Swap the insertion/duplication state between two locations. */ |
11371 | ||
11372 | static void | |
11373 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
11374 | { | |
11375 | const int left_inserted = left->inserted; | |
11376 | const int left_duplicate = left->duplicate; | |
b775012e | 11377 | const int left_needs_update = left->needs_update; |
934709f0 PW |
11378 | const struct bp_target_info left_target_info = left->target_info; |
11379 | ||
1e4d1764 YQ |
11380 | /* Locations of tracepoints can never be duplicated. */ |
11381 | if (is_tracepoint (left->owner)) | |
11382 | gdb_assert (!left->duplicate); | |
11383 | if (is_tracepoint (right->owner)) | |
11384 | gdb_assert (!right->duplicate); | |
11385 | ||
934709f0 PW |
11386 | left->inserted = right->inserted; |
11387 | left->duplicate = right->duplicate; | |
b775012e | 11388 | left->needs_update = right->needs_update; |
934709f0 PW |
11389 | left->target_info = right->target_info; |
11390 | right->inserted = left_inserted; | |
11391 | right->duplicate = left_duplicate; | |
b775012e | 11392 | right->needs_update = left_needs_update; |
934709f0 PW |
11393 | right->target_info = left_target_info; |
11394 | } | |
11395 | ||
b775012e LM |
11396 | /* Force the re-insertion of the locations at ADDRESS. This is called |
11397 | once a new/deleted/modified duplicate location is found and we are evaluating | |
11398 | conditions on the target's side. Such conditions need to be updated on | |
11399 | the target. */ | |
11400 | ||
11401 | static void | |
11402 | force_breakpoint_reinsertion (struct bp_location *bl) | |
11403 | { | |
11404 | struct bp_location **locp = NULL, **loc2p; | |
11405 | struct bp_location *loc; | |
11406 | CORE_ADDR address = 0; | |
11407 | int pspace_num; | |
11408 | ||
11409 | address = bl->address; | |
11410 | pspace_num = bl->pspace->num; | |
11411 | ||
11412 | /* This is only meaningful if the target is | |
11413 | evaluating conditions and if the user has | |
11414 | opted for condition evaluation on the target's | |
11415 | side. */ | |
11416 | if (gdb_evaluates_breakpoint_condition_p () | |
11417 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
11418 | return; | |
11419 | ||
11420 | /* Flag all breakpoint locations with this address and | |
11421 | the same program space as the location | |
11422 | as "its condition has changed". We need to | |
11423 | update the conditions on the target's side. */ | |
11424 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address) | |
11425 | { | |
11426 | loc = *loc2p; | |
11427 | ||
11428 | if (!is_breakpoint (loc->owner) | |
11429 | || pspace_num != loc->pspace->num) | |
11430 | continue; | |
11431 | ||
11432 | /* Flag the location appropriately. We use a different state to | |
11433 | let everyone know that we already updated the set of locations | |
11434 | with addr bl->address and program space bl->pspace. This is so | |
11435 | we don't have to keep calling these functions just to mark locations | |
11436 | that have already been marked. */ | |
11437 | loc->condition_changed = condition_updated; | |
11438 | ||
11439 | /* Free the agent expression bytecode as well. We will compute | |
11440 | it later on. */ | |
11441 | if (loc->cond_bytecode) | |
11442 | { | |
11443 | free_agent_expr (loc->cond_bytecode); | |
11444 | loc->cond_bytecode = NULL; | |
11445 | } | |
11446 | } | |
11447 | } | |
11448 | ||
4cd9bd08 | 11449 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
b60e7edf PA |
11450 | into the inferior, only remove already-inserted locations that no |
11451 | longer should be inserted. Functions that delete a breakpoint or | |
11452 | breakpoints should pass false, so that deleting a breakpoint | |
11453 | doesn't have the side effect of inserting the locations of other | |
11454 | breakpoints that are marked not-inserted, but should_be_inserted | |
11455 | returns true on them. | |
11456 | ||
11457 | This behaviour is useful is situations close to tear-down -- e.g., | |
11458 | after an exec, while the target still has execution, but breakpoint | |
11459 | shadows of the previous executable image should *NOT* be restored | |
11460 | to the new image; or before detaching, where the target still has | |
11461 | execution and wants to delete breakpoints from GDB's lists, and all | |
11462 | breakpoints had already been removed from the inferior. */ | |
11463 | ||
0d381245 | 11464 | static void |
b60e7edf | 11465 | update_global_location_list (int should_insert) |
0d381245 | 11466 | { |
74960c60 | 11467 | struct breakpoint *b; |
876fa593 | 11468 | struct bp_location **locp, *loc; |
f7545552 | 11469 | struct cleanup *cleanups; |
b775012e LM |
11470 | /* Last breakpoint location address that was marked for update. */ |
11471 | CORE_ADDR last_addr = 0; | |
11472 | /* Last breakpoint location program space that was marked for update. */ | |
11473 | int last_pspace_num = -1; | |
f7545552 | 11474 | |
2d134ed3 PA |
11475 | /* Used in the duplicates detection below. When iterating over all |
11476 | bp_locations, points to the first bp_location of a given address. | |
11477 | Breakpoints and watchpoints of different types are never | |
11478 | duplicates of each other. Keep one pointer for each type of | |
11479 | breakpoint/watchpoint, so we only need to loop over all locations | |
11480 | once. */ | |
11481 | struct bp_location *bp_loc_first; /* breakpoint */ | |
11482 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
11483 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
11484 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 11485 | |
4a64f543 MS |
11486 | /* Saved former bp_location array which we compare against the newly |
11487 | built bp_location from the current state of ALL_BREAKPOINTS. */ | |
876fa593 JK |
11488 | struct bp_location **old_location, **old_locp; |
11489 | unsigned old_location_count; | |
11490 | ||
11491 | old_location = bp_location; | |
11492 | old_location_count = bp_location_count; | |
11493 | bp_location = NULL; | |
11494 | bp_location_count = 0; | |
11495 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 11496 | |
74960c60 | 11497 | ALL_BREAKPOINTS (b) |
876fa593 JK |
11498 | for (loc = b->loc; loc; loc = loc->next) |
11499 | bp_location_count++; | |
11500 | ||
11501 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); | |
11502 | locp = bp_location; | |
11503 | ALL_BREAKPOINTS (b) | |
11504 | for (loc = b->loc; loc; loc = loc->next) | |
11505 | *locp++ = loc; | |
11506 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 11507 | bp_location_compare); |
876fa593 JK |
11508 | |
11509 | bp_location_target_extensions_update (); | |
74960c60 | 11510 | |
4a64f543 MS |
11511 | /* Identify bp_location instances that are no longer present in the |
11512 | new list, and therefore should be freed. Note that it's not | |
11513 | necessary that those locations should be removed from inferior -- | |
11514 | if there's another location at the same address (previously | |
11515 | marked as duplicate), we don't need to remove/insert the | |
11516 | location. | |
876fa593 | 11517 | |
4a64f543 MS |
11518 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
11519 | and former bp_location array state respectively. */ | |
876fa593 JK |
11520 | |
11521 | locp = bp_location; | |
11522 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
11523 | old_locp++) | |
74960c60 | 11524 | { |
876fa593 | 11525 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 11526 | struct bp_location **loc2p; |
876fa593 | 11527 | |
e5dd4106 | 11528 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 11529 | not, we have to free it. */ |
c7d46a38 | 11530 | int found_object = 0; |
20874c92 VP |
11531 | /* Tells if the location should remain inserted in the target. */ |
11532 | int keep_in_target = 0; | |
11533 | int removed = 0; | |
876fa593 | 11534 | |
4a64f543 MS |
11535 | /* Skip LOCP entries which will definitely never be needed. |
11536 | Stop either at or being the one matching OLD_LOC. */ | |
876fa593 | 11537 | while (locp < bp_location + bp_location_count |
c7d46a38 | 11538 | && (*locp)->address < old_loc->address) |
876fa593 | 11539 | locp++; |
c7d46a38 PA |
11540 | |
11541 | for (loc2p = locp; | |
11542 | (loc2p < bp_location + bp_location_count | |
11543 | && (*loc2p)->address == old_loc->address); | |
11544 | loc2p++) | |
11545 | { | |
b775012e LM |
11546 | /* Check if this is a new/duplicated location or a duplicated |
11547 | location that had its condition modified. If so, we want to send | |
11548 | its condition to the target if evaluation of conditions is taking | |
11549 | place there. */ | |
11550 | if ((*loc2p)->condition_changed == condition_modified | |
11551 | && (last_addr != old_loc->address | |
11552 | || last_pspace_num != old_loc->pspace->num)) | |
c7d46a38 | 11553 | { |
b775012e LM |
11554 | force_breakpoint_reinsertion (*loc2p); |
11555 | last_pspace_num = old_loc->pspace->num; | |
c7d46a38 | 11556 | } |
b775012e LM |
11557 | |
11558 | if (*loc2p == old_loc) | |
11559 | found_object = 1; | |
c7d46a38 | 11560 | } |
74960c60 | 11561 | |
b775012e LM |
11562 | /* We have already handled this address, update it so that we don't |
11563 | have to go through updates again. */ | |
11564 | last_addr = old_loc->address; | |
11565 | ||
11566 | /* Target-side condition evaluation: Handle deleted locations. */ | |
11567 | if (!found_object) | |
11568 | force_breakpoint_reinsertion (old_loc); | |
11569 | ||
4a64f543 MS |
11570 | /* If this location is no longer present, and inserted, look if |
11571 | there's maybe a new location at the same address. If so, | |
11572 | mark that one inserted, and don't remove this one. This is | |
11573 | needed so that we don't have a time window where a breakpoint | |
11574 | at certain location is not inserted. */ | |
74960c60 | 11575 | |
876fa593 | 11576 | if (old_loc->inserted) |
0d381245 | 11577 | { |
4a64f543 MS |
11578 | /* If the location is inserted now, we might have to remove |
11579 | it. */ | |
74960c60 | 11580 | |
876fa593 | 11581 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 11582 | { |
4a64f543 MS |
11583 | /* The location is still present in the location list, |
11584 | and still should be inserted. Don't do anything. */ | |
20874c92 | 11585 | keep_in_target = 1; |
74960c60 VP |
11586 | } |
11587 | else | |
11588 | { | |
b775012e LM |
11589 | /* This location still exists, but it won't be kept in the |
11590 | target since it may have been disabled. We proceed to | |
11591 | remove its target-side condition. */ | |
11592 | ||
4a64f543 MS |
11593 | /* The location is either no longer present, or got |
11594 | disabled. See if there's another location at the | |
11595 | same address, in which case we don't need to remove | |
11596 | this one from the target. */ | |
876fa593 | 11597 | |
2bdf28a0 | 11598 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
11599 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
11600 | { | |
876fa593 | 11601 | for (loc2p = locp; |
c7d46a38 PA |
11602 | (loc2p < bp_location + bp_location_count |
11603 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
11604 | loc2p++) |
11605 | { | |
11606 | struct bp_location *loc2 = *loc2p; | |
11607 | ||
2d134ed3 | 11608 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 11609 | { |
85d721b8 PA |
11610 | /* Read watchpoint locations are switched to |
11611 | access watchpoints, if the former are not | |
11612 | supported, but the latter are. */ | |
11613 | if (is_hardware_watchpoint (old_loc->owner)) | |
11614 | { | |
11615 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
11616 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
11617 | } | |
11618 | ||
934709f0 PW |
11619 | /* loc2 is a duplicated location. We need to check |
11620 | if it should be inserted in case it will be | |
11621 | unduplicated. */ | |
11622 | if (loc2 != old_loc | |
11623 | && unduplicated_should_be_inserted (loc2)) | |
c7d46a38 | 11624 | { |
934709f0 | 11625 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
11626 | keep_in_target = 1; |
11627 | break; | |
11628 | } | |
876fa593 JK |
11629 | } |
11630 | } | |
11631 | } | |
74960c60 VP |
11632 | } |
11633 | ||
20874c92 VP |
11634 | if (!keep_in_target) |
11635 | { | |
876fa593 | 11636 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 | 11637 | { |
4a64f543 MS |
11638 | /* This is just about all we can do. We could keep |
11639 | this location on the global list, and try to | |
11640 | remove it next time, but there's no particular | |
11641 | reason why we will succeed next time. | |
20874c92 | 11642 | |
4a64f543 MS |
11643 | Note that at this point, old_loc->owner is still |
11644 | valid, as delete_breakpoint frees the breakpoint | |
11645 | only after calling us. */ | |
3e43a32a MS |
11646 | printf_filtered (_("warning: Error removing " |
11647 | "breakpoint %d\n"), | |
876fa593 | 11648 | old_loc->owner->number); |
20874c92 VP |
11649 | } |
11650 | removed = 1; | |
11651 | } | |
0d381245 | 11652 | } |
74960c60 VP |
11653 | |
11654 | if (!found_object) | |
1c5cfe86 | 11655 | { |
db82e815 PA |
11656 | if (removed && non_stop |
11657 | && breakpoint_address_is_meaningful (old_loc->owner) | |
11658 | && !is_hardware_watchpoint (old_loc->owner)) | |
20874c92 | 11659 | { |
db82e815 PA |
11660 | /* This location was removed from the target. In |
11661 | non-stop mode, a race condition is possible where | |
11662 | we've removed a breakpoint, but stop events for that | |
11663 | breakpoint are already queued and will arrive later. | |
11664 | We apply an heuristic to be able to distinguish such | |
11665 | SIGTRAPs from other random SIGTRAPs: we keep this | |
11666 | breakpoint location for a bit, and will retire it | |
11667 | after we see some number of events. The theory here | |
11668 | is that reporting of events should, "on the average", | |
11669 | be fair, so after a while we'll see events from all | |
11670 | threads that have anything of interest, and no longer | |
11671 | need to keep this breakpoint location around. We | |
11672 | don't hold locations forever so to reduce chances of | |
11673 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
11674 | SIGTRAP. | |
11675 | ||
11676 | The heuristic failing can be disastrous on | |
11677 | decr_pc_after_break targets. | |
11678 | ||
11679 | On decr_pc_after_break targets, like e.g., x86-linux, | |
11680 | if we fail to recognize a late breakpoint SIGTRAP, | |
11681 | because events_till_retirement has reached 0 too | |
11682 | soon, we'll fail to do the PC adjustment, and report | |
11683 | a random SIGTRAP to the user. When the user resumes | |
11684 | the inferior, it will most likely immediately crash | |
2dec564e | 11685 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
11686 | corrupted, because of being resumed e.g., in the |
11687 | middle of a multi-byte instruction, or skipped a | |
11688 | one-byte instruction. This was actually seen happen | |
11689 | on native x86-linux, and should be less rare on | |
11690 | targets that do not support new thread events, like | |
11691 | remote, due to the heuristic depending on | |
11692 | thread_count. | |
11693 | ||
11694 | Mistaking a random SIGTRAP for a breakpoint trap | |
11695 | causes similar symptoms (PC adjustment applied when | |
11696 | it shouldn't), but then again, playing with SIGTRAPs | |
11697 | behind the debugger's back is asking for trouble. | |
11698 | ||
11699 | Since hardware watchpoint traps are always | |
11700 | distinguishable from other traps, so we don't need to | |
11701 | apply keep hardware watchpoint moribund locations | |
11702 | around. We simply always ignore hardware watchpoint | |
11703 | traps we can no longer explain. */ | |
11704 | ||
876fa593 JK |
11705 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
11706 | old_loc->owner = NULL; | |
20874c92 | 11707 | |
876fa593 | 11708 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
11709 | } |
11710 | else | |
f431efe5 PA |
11711 | { |
11712 | old_loc->owner = NULL; | |
11713 | decref_bp_location (&old_loc); | |
11714 | } | |
20874c92 | 11715 | } |
74960c60 | 11716 | } |
1c5cfe86 | 11717 | |
348d480f PA |
11718 | /* Rescan breakpoints at the same address and section, marking the |
11719 | first one as "first" and any others as "duplicates". This is so | |
11720 | that the bpt instruction is only inserted once. If we have a | |
11721 | permanent breakpoint at the same place as BPT, make that one the | |
11722 | official one, and the rest as duplicates. Permanent breakpoints | |
11723 | are sorted first for the same address. | |
11724 | ||
11725 | Do the same for hardware watchpoints, but also considering the | |
11726 | watchpoint's type (regular/access/read) and length. */ | |
11727 | ||
11728 | bp_loc_first = NULL; | |
11729 | wp_loc_first = NULL; | |
11730 | awp_loc_first = NULL; | |
11731 | rwp_loc_first = NULL; | |
11732 | ALL_BP_LOCATIONS (loc, locp) | |
11733 | { | |
11734 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
11735 | non-NULL. */ | |
348d480f | 11736 | struct bp_location **loc_first_p; |
d3fbdd86 | 11737 | b = loc->owner; |
348d480f | 11738 | |
f8eba3c6 | 11739 | if (!should_be_inserted (loc) |
348d480f | 11740 | || !breakpoint_address_is_meaningful (b) |
1e4d1764 YQ |
11741 | /* Don't detect duplicate for tracepoint locations because they are |
11742 | never duplicated. See the comments in field `duplicate' of | |
11743 | `struct bp_location'. */ | |
348d480f | 11744 | || is_tracepoint (b)) |
b775012e LM |
11745 | { |
11746 | /* Clear the condition modification flag. */ | |
11747 | loc->condition_changed = condition_unchanged; | |
11748 | continue; | |
11749 | } | |
348d480f PA |
11750 | |
11751 | /* Permanent breakpoint should always be inserted. */ | |
11752 | if (b->enable_state == bp_permanent && ! loc->inserted) | |
11753 | internal_error (__FILE__, __LINE__, | |
11754 | _("allegedly permanent breakpoint is not " | |
11755 | "actually inserted")); | |
11756 | ||
11757 | if (b->type == bp_hardware_watchpoint) | |
11758 | loc_first_p = &wp_loc_first; | |
11759 | else if (b->type == bp_read_watchpoint) | |
11760 | loc_first_p = &rwp_loc_first; | |
11761 | else if (b->type == bp_access_watchpoint) | |
11762 | loc_first_p = &awp_loc_first; | |
11763 | else | |
11764 | loc_first_p = &bp_loc_first; | |
11765 | ||
11766 | if (*loc_first_p == NULL | |
11767 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
11768 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
11769 | { | |
11770 | *loc_first_p = loc; | |
11771 | loc->duplicate = 0; | |
b775012e LM |
11772 | |
11773 | if (is_breakpoint (loc->owner) && loc->condition_changed) | |
11774 | { | |
11775 | loc->needs_update = 1; | |
11776 | /* Clear the condition modification flag. */ | |
11777 | loc->condition_changed = condition_unchanged; | |
11778 | } | |
348d480f PA |
11779 | continue; |
11780 | } | |
11781 | ||
934709f0 PW |
11782 | |
11783 | /* This and the above ensure the invariant that the first location | |
11784 | is not duplicated, and is the inserted one. | |
11785 | All following are marked as duplicated, and are not inserted. */ | |
11786 | if (loc->inserted) | |
11787 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
11788 | loc->duplicate = 1; |
11789 | ||
b775012e LM |
11790 | /* Clear the condition modification flag. */ |
11791 | loc->condition_changed = condition_unchanged; | |
11792 | ||
348d480f PA |
11793 | if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted |
11794 | && b->enable_state != bp_permanent) | |
11795 | internal_error (__FILE__, __LINE__, | |
11796 | _("another breakpoint was inserted on top of " | |
11797 | "a permanent breakpoint")); | |
11798 | } | |
11799 | ||
b775012e | 11800 | if (breakpoints_always_inserted_mode () |
348d480f PA |
11801 | && (have_live_inferiors () |
11802 | || (gdbarch_has_global_breakpoints (target_gdbarch)))) | |
b775012e LM |
11803 | { |
11804 | if (should_insert) | |
11805 | insert_breakpoint_locations (); | |
11806 | else | |
11807 | { | |
11808 | /* Though should_insert is false, we may need to update conditions | |
11809 | on the target's side if it is evaluating such conditions. We | |
11810 | only update conditions for locations that are marked | |
11811 | "needs_update". */ | |
11812 | update_inserted_breakpoint_locations (); | |
11813 | } | |
11814 | } | |
348d480f | 11815 | |
1e4d1764 YQ |
11816 | if (should_insert) |
11817 | download_tracepoint_locations (); | |
11818 | ||
348d480f PA |
11819 | do_cleanups (cleanups); |
11820 | } | |
11821 | ||
11822 | void | |
11823 | breakpoint_retire_moribund (void) | |
11824 | { | |
11825 | struct bp_location *loc; | |
11826 | int ix; | |
11827 | ||
11828 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
11829 | if (--(loc->events_till_retirement) == 0) | |
11830 | { | |
11831 | decref_bp_location (&loc); | |
11832 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
11833 | --ix; | |
11834 | } | |
11835 | } | |
11836 | ||
11837 | static void | |
11838 | update_global_location_list_nothrow (int inserting) | |
11839 | { | |
bfd189b1 | 11840 | volatile struct gdb_exception e; |
348d480f PA |
11841 | |
11842 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
11843 | update_global_location_list (inserting); | |
11844 | } | |
11845 | ||
11846 | /* Clear BKP from a BPS. */ | |
11847 | ||
11848 | static void | |
11849 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) | |
11850 | { | |
11851 | bpstat bs; | |
11852 | ||
11853 | for (bs = bps; bs; bs = bs->next) | |
11854 | if (bs->breakpoint_at == bpt) | |
11855 | { | |
11856 | bs->breakpoint_at = NULL; | |
11857 | bs->old_val = NULL; | |
11858 | /* bs->commands will be freed later. */ | |
11859 | } | |
11860 | } | |
11861 | ||
11862 | /* Callback for iterate_over_threads. */ | |
11863 | static int | |
11864 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
11865 | { | |
11866 | struct breakpoint *bpt = data; | |
11867 | ||
11868 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
11869 | return 0; | |
11870 | } | |
11871 | ||
11872 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
11873 | callbacks. */ | |
11874 | ||
11875 | static void | |
11876 | say_where (struct breakpoint *b) | |
11877 | { | |
79a45e25 | 11878 | struct ui_out *uiout = current_uiout; |
348d480f PA |
11879 | struct value_print_options opts; |
11880 | ||
11881 | get_user_print_options (&opts); | |
11882 | ||
11883 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
11884 | single string. */ | |
11885 | if (b->loc == NULL) | |
11886 | { | |
11887 | printf_filtered (_(" (%s) pending."), b->addr_string); | |
11888 | } | |
11889 | else | |
11890 | { | |
f8eba3c6 | 11891 | if (opts.addressprint || b->loc->source_file == NULL) |
348d480f PA |
11892 | { |
11893 | printf_filtered (" at "); | |
11894 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), | |
11895 | gdb_stdout); | |
11896 | } | |
f8eba3c6 TT |
11897 | if (b->loc->source_file) |
11898 | { | |
11899 | /* If there is a single location, we can print the location | |
11900 | more nicely. */ | |
11901 | if (b->loc->next == NULL) | |
11902 | printf_filtered (": file %s, line %d.", | |
11903 | b->loc->source_file, b->loc->line_number); | |
11904 | else | |
11905 | /* This is not ideal, but each location may have a | |
11906 | different file name, and this at least reflects the | |
11907 | real situation somewhat. */ | |
11908 | printf_filtered (": %s.", b->addr_string); | |
11909 | } | |
348d480f PA |
11910 | |
11911 | if (b->loc->next) | |
11912 | { | |
11913 | struct bp_location *loc = b->loc; | |
11914 | int n = 0; | |
11915 | for (; loc; loc = loc->next) | |
11916 | ++n; | |
11917 | printf_filtered (" (%d locations)", n); | |
11918 | } | |
11919 | } | |
11920 | } | |
11921 | ||
348d480f PA |
11922 | /* Default bp_location_ops methods. */ |
11923 | ||
11924 | static void | |
11925 | bp_location_dtor (struct bp_location *self) | |
11926 | { | |
11927 | xfree (self->cond); | |
b775012e LM |
11928 | if (self->cond_bytecode) |
11929 | free_agent_expr (self->cond_bytecode); | |
348d480f | 11930 | xfree (self->function_name); |
f8eba3c6 | 11931 | xfree (self->source_file); |
348d480f PA |
11932 | } |
11933 | ||
11934 | static const struct bp_location_ops bp_location_ops = | |
11935 | { | |
11936 | bp_location_dtor | |
11937 | }; | |
11938 | ||
2060206e PA |
11939 | /* Default breakpoint_ops methods all breakpoint_ops ultimately |
11940 | inherit from. */ | |
348d480f | 11941 | |
2060206e PA |
11942 | static void |
11943 | base_breakpoint_dtor (struct breakpoint *self) | |
348d480f PA |
11944 | { |
11945 | decref_counted_command_line (&self->commands); | |
11946 | xfree (self->cond_string); | |
348d480f | 11947 | xfree (self->addr_string); |
f8eba3c6 | 11948 | xfree (self->filter); |
348d480f | 11949 | xfree (self->addr_string_range_end); |
348d480f PA |
11950 | } |
11951 | ||
2060206e PA |
11952 | static struct bp_location * |
11953 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f PA |
11954 | { |
11955 | struct bp_location *loc; | |
11956 | ||
11957 | loc = XNEW (struct bp_location); | |
11958 | init_bp_location (loc, &bp_location_ops, self); | |
11959 | return loc; | |
11960 | } | |
11961 | ||
2060206e PA |
11962 | static void |
11963 | base_breakpoint_re_set (struct breakpoint *b) | |
11964 | { | |
11965 | /* Nothing to re-set. */ | |
11966 | } | |
11967 | ||
11968 | #define internal_error_pure_virtual_called() \ | |
11969 | gdb_assert_not_reached ("pure virtual function called") | |
11970 | ||
11971 | static int | |
11972 | base_breakpoint_insert_location (struct bp_location *bl) | |
11973 | { | |
11974 | internal_error_pure_virtual_called (); | |
11975 | } | |
11976 | ||
11977 | static int | |
11978 | base_breakpoint_remove_location (struct bp_location *bl) | |
11979 | { | |
11980 | internal_error_pure_virtual_called (); | |
11981 | } | |
11982 | ||
11983 | static int | |
11984 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
11985 | struct address_space *aspace, | |
09ac7c10 TT |
11986 | CORE_ADDR bp_addr, |
11987 | const struct target_waitstatus *ws) | |
2060206e PA |
11988 | { |
11989 | internal_error_pure_virtual_called (); | |
11990 | } | |
11991 | ||
11992 | static void | |
11993 | base_breakpoint_check_status (bpstat bs) | |
11994 | { | |
11995 | /* Always stop. */ | |
11996 | } | |
11997 | ||
11998 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
11999 | errors. */ | |
12000 | ||
12001 | static int | |
12002 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
12003 | { | |
12004 | internal_error_pure_virtual_called (); | |
12005 | } | |
12006 | ||
12007 | /* A "resources_needed" breakpoint_ops method that just internal | |
12008 | errors. */ | |
12009 | ||
12010 | static int | |
12011 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
12012 | { | |
12013 | internal_error_pure_virtual_called (); | |
12014 | } | |
12015 | ||
12016 | static enum print_stop_action | |
12017 | base_breakpoint_print_it (bpstat bs) | |
12018 | { | |
12019 | internal_error_pure_virtual_called (); | |
12020 | } | |
12021 | ||
12022 | static void | |
12023 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
12024 | struct ui_out *uiout) | |
12025 | { | |
12026 | /* nothing */ | |
12027 | } | |
12028 | ||
12029 | static void | |
12030 | base_breakpoint_print_mention (struct breakpoint *b) | |
12031 | { | |
12032 | internal_error_pure_virtual_called (); | |
12033 | } | |
12034 | ||
12035 | static void | |
12036 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
12037 | { | |
12038 | internal_error_pure_virtual_called (); | |
12039 | } | |
12040 | ||
983af33b SDJ |
12041 | static void |
12042 | base_breakpoint_create_sals_from_address (char **arg, | |
12043 | struct linespec_result *canonical, | |
12044 | enum bptype type_wanted, | |
12045 | char *addr_start, | |
12046 | char **copy_arg) | |
12047 | { | |
12048 | internal_error_pure_virtual_called (); | |
12049 | } | |
12050 | ||
12051 | static void | |
12052 | base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12053 | struct linespec_result *c, | |
12054 | struct linespec_sals *lsal, | |
12055 | char *cond_string, | |
12056 | enum bptype type_wanted, | |
12057 | enum bpdisp disposition, | |
12058 | int thread, | |
12059 | int task, int ignore_count, | |
12060 | const struct breakpoint_ops *o, | |
12061 | int from_tty, int enabled, | |
44f238bb | 12062 | int internal, unsigned flags) |
983af33b SDJ |
12063 | { |
12064 | internal_error_pure_virtual_called (); | |
12065 | } | |
12066 | ||
12067 | static void | |
12068 | base_breakpoint_decode_linespec (struct breakpoint *b, char **s, | |
12069 | struct symtabs_and_lines *sals) | |
12070 | { | |
12071 | internal_error_pure_virtual_called (); | |
12072 | } | |
12073 | ||
2060206e PA |
12074 | static struct breakpoint_ops base_breakpoint_ops = |
12075 | { | |
12076 | base_breakpoint_dtor, | |
12077 | base_breakpoint_allocate_location, | |
12078 | base_breakpoint_re_set, | |
12079 | base_breakpoint_insert_location, | |
12080 | base_breakpoint_remove_location, | |
12081 | base_breakpoint_breakpoint_hit, | |
12082 | base_breakpoint_check_status, | |
12083 | base_breakpoint_resources_needed, | |
12084 | base_breakpoint_works_in_software_mode, | |
12085 | base_breakpoint_print_it, | |
12086 | NULL, | |
12087 | base_breakpoint_print_one_detail, | |
12088 | base_breakpoint_print_mention, | |
983af33b SDJ |
12089 | base_breakpoint_print_recreate, |
12090 | base_breakpoint_create_sals_from_address, | |
12091 | base_breakpoint_create_breakpoints_sal, | |
12092 | base_breakpoint_decode_linespec, | |
2060206e PA |
12093 | }; |
12094 | ||
12095 | /* Default breakpoint_ops methods. */ | |
12096 | ||
12097 | static void | |
348d480f PA |
12098 | bkpt_re_set (struct breakpoint *b) |
12099 | { | |
06edf0c0 PA |
12100 | /* FIXME: is this still reachable? */ |
12101 | if (b->addr_string == NULL) | |
12102 | { | |
12103 | /* Anything without a string can't be re-set. */ | |
348d480f | 12104 | delete_breakpoint (b); |
06edf0c0 | 12105 | return; |
348d480f | 12106 | } |
06edf0c0 PA |
12107 | |
12108 | breakpoint_re_set_default (b); | |
348d480f PA |
12109 | } |
12110 | ||
2060206e | 12111 | static int |
348d480f PA |
12112 | bkpt_insert_location (struct bp_location *bl) |
12113 | { | |
12114 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
12115 | return target_insert_hw_breakpoint (bl->gdbarch, | |
12116 | &bl->target_info); | |
12117 | else | |
12118 | return target_insert_breakpoint (bl->gdbarch, | |
12119 | &bl->target_info); | |
12120 | } | |
12121 | ||
2060206e | 12122 | static int |
348d480f PA |
12123 | bkpt_remove_location (struct bp_location *bl) |
12124 | { | |
12125 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
12126 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
12127 | else | |
12128 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info); | |
12129 | } | |
12130 | ||
2060206e | 12131 | static int |
348d480f | 12132 | bkpt_breakpoint_hit (const struct bp_location *bl, |
09ac7c10 TT |
12133 | struct address_space *aspace, CORE_ADDR bp_addr, |
12134 | const struct target_waitstatus *ws) | |
348d480f PA |
12135 | { |
12136 | struct breakpoint *b = bl->owner; | |
12137 | ||
09ac7c10 TT |
12138 | if (ws->kind != TARGET_WAITKIND_STOPPED |
12139 | || ws->value.sig != TARGET_SIGNAL_TRAP) | |
12140 | return 0; | |
12141 | ||
348d480f PA |
12142 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
12143 | aspace, bp_addr)) | |
12144 | return 0; | |
12145 | ||
12146 | if (overlay_debugging /* unmapped overlay section */ | |
12147 | && section_is_overlay (bl->section) | |
12148 | && !section_is_mapped (bl->section)) | |
12149 | return 0; | |
12150 | ||
12151 | return 1; | |
12152 | } | |
12153 | ||
2060206e | 12154 | static int |
348d480f PA |
12155 | bkpt_resources_needed (const struct bp_location *bl) |
12156 | { | |
12157 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
12158 | ||
12159 | return 1; | |
12160 | } | |
12161 | ||
2060206e | 12162 | static enum print_stop_action |
348d480f PA |
12163 | bkpt_print_it (bpstat bs) |
12164 | { | |
348d480f PA |
12165 | struct breakpoint *b; |
12166 | const struct bp_location *bl; | |
001c8c33 | 12167 | int bp_temp; |
79a45e25 | 12168 | struct ui_out *uiout = current_uiout; |
348d480f PA |
12169 | |
12170 | gdb_assert (bs->bp_location_at != NULL); | |
12171 | ||
12172 | bl = bs->bp_location_at; | |
12173 | b = bs->breakpoint_at; | |
12174 | ||
001c8c33 PA |
12175 | bp_temp = b->disposition == disp_del; |
12176 | if (bl->address != bl->requested_address) | |
12177 | breakpoint_adjustment_warning (bl->requested_address, | |
12178 | bl->address, | |
12179 | b->number, 1); | |
12180 | annotate_breakpoint (b->number); | |
12181 | if (bp_temp) | |
12182 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
12183 | else | |
12184 | ui_out_text (uiout, "\nBreakpoint "); | |
12185 | if (ui_out_is_mi_like_p (uiout)) | |
348d480f | 12186 | { |
001c8c33 PA |
12187 | ui_out_field_string (uiout, "reason", |
12188 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
12189 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
06edf0c0 | 12190 | } |
001c8c33 PA |
12191 | ui_out_field_int (uiout, "bkptno", b->number); |
12192 | ui_out_text (uiout, ", "); | |
06edf0c0 | 12193 | |
001c8c33 | 12194 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
12195 | } |
12196 | ||
2060206e | 12197 | static void |
06edf0c0 PA |
12198 | bkpt_print_mention (struct breakpoint *b) |
12199 | { | |
79a45e25 | 12200 | if (ui_out_is_mi_like_p (current_uiout)) |
06edf0c0 PA |
12201 | return; |
12202 | ||
12203 | switch (b->type) | |
12204 | { | |
12205 | case bp_breakpoint: | |
12206 | case bp_gnu_ifunc_resolver: | |
12207 | if (b->disposition == disp_del) | |
12208 | printf_filtered (_("Temporary breakpoint")); | |
12209 | else | |
12210 | printf_filtered (_("Breakpoint")); | |
12211 | printf_filtered (_(" %d"), b->number); | |
12212 | if (b->type == bp_gnu_ifunc_resolver) | |
12213 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
12214 | break; | |
12215 | case bp_hardware_breakpoint: | |
12216 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
12217 | break; | |
12218 | } | |
12219 | ||
12220 | say_where (b); | |
12221 | } | |
12222 | ||
2060206e | 12223 | static void |
06edf0c0 PA |
12224 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
12225 | { | |
12226 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
12227 | fprintf_unfiltered (fp, "tbreak"); | |
12228 | else if (tp->type == bp_breakpoint) | |
12229 | fprintf_unfiltered (fp, "break"); | |
12230 | else if (tp->type == bp_hardware_breakpoint | |
12231 | && tp->disposition == disp_del) | |
12232 | fprintf_unfiltered (fp, "thbreak"); | |
12233 | else if (tp->type == bp_hardware_breakpoint) | |
12234 | fprintf_unfiltered (fp, "hbreak"); | |
12235 | else | |
12236 | internal_error (__FILE__, __LINE__, | |
12237 | _("unhandled breakpoint type %d"), (int) tp->type); | |
12238 | ||
2060206e | 12239 | fprintf_unfiltered (fp, " %s", tp->addr_string); |
dd11a36c | 12240 | print_recreate_thread (tp, fp); |
06edf0c0 PA |
12241 | } |
12242 | ||
983af33b SDJ |
12243 | static void |
12244 | bkpt_create_sals_from_address (char **arg, | |
12245 | struct linespec_result *canonical, | |
12246 | enum bptype type_wanted, | |
12247 | char *addr_start, char **copy_arg) | |
12248 | { | |
12249 | create_sals_from_address_default (arg, canonical, type_wanted, | |
12250 | addr_start, copy_arg); | |
12251 | } | |
12252 | ||
12253 | static void | |
12254 | bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12255 | struct linespec_result *canonical, | |
12256 | struct linespec_sals *lsal, | |
12257 | char *cond_string, | |
12258 | enum bptype type_wanted, | |
12259 | enum bpdisp disposition, | |
12260 | int thread, | |
12261 | int task, int ignore_count, | |
12262 | const struct breakpoint_ops *ops, | |
12263 | int from_tty, int enabled, | |
44f238bb | 12264 | int internal, unsigned flags) |
983af33b SDJ |
12265 | { |
12266 | create_breakpoints_sal_default (gdbarch, canonical, lsal, | |
12267 | cond_string, type_wanted, | |
12268 | disposition, thread, task, | |
12269 | ignore_count, ops, from_tty, | |
44f238bb | 12270 | enabled, internal, flags); |
983af33b SDJ |
12271 | } |
12272 | ||
12273 | static void | |
12274 | bkpt_decode_linespec (struct breakpoint *b, char **s, | |
12275 | struct symtabs_and_lines *sals) | |
12276 | { | |
12277 | decode_linespec_default (b, s, sals); | |
12278 | } | |
12279 | ||
06edf0c0 PA |
12280 | /* Virtual table for internal breakpoints. */ |
12281 | ||
12282 | static void | |
12283 | internal_bkpt_re_set (struct breakpoint *b) | |
12284 | { | |
12285 | switch (b->type) | |
12286 | { | |
12287 | /* Delete overlay event and longjmp master breakpoints; they | |
12288 | will be reset later by breakpoint_re_set. */ | |
12289 | case bp_overlay_event: | |
12290 | case bp_longjmp_master: | |
12291 | case bp_std_terminate_master: | |
12292 | case bp_exception_master: | |
12293 | delete_breakpoint (b); | |
12294 | break; | |
12295 | ||
12296 | /* This breakpoint is special, it's set up when the inferior | |
12297 | starts and we really don't want to touch it. */ | |
12298 | case bp_shlib_event: | |
12299 | ||
12300 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
12301 | it is set up, we do not want to touch it. */ | |
12302 | case bp_thread_event: | |
12303 | break; | |
12304 | } | |
12305 | } | |
12306 | ||
12307 | static void | |
12308 | internal_bkpt_check_status (bpstat bs) | |
12309 | { | |
a9b3a50f PA |
12310 | if (bs->breakpoint_at->type == bp_shlib_event) |
12311 | { | |
12312 | /* If requested, stop when the dynamic linker notifies GDB of | |
12313 | events. This allows the user to get control and place | |
12314 | breakpoints in initializer routines for dynamically loaded | |
12315 | objects (among other things). */ | |
12316 | bs->stop = stop_on_solib_events; | |
12317 | bs->print = stop_on_solib_events; | |
12318 | } | |
12319 | else | |
12320 | bs->stop = 0; | |
06edf0c0 PA |
12321 | } |
12322 | ||
12323 | static enum print_stop_action | |
12324 | internal_bkpt_print_it (bpstat bs) | |
12325 | { | |
36dfb11c | 12326 | struct ui_out *uiout = current_uiout; |
06edf0c0 | 12327 | struct breakpoint *b; |
06edf0c0 | 12328 | |
06edf0c0 PA |
12329 | b = bs->breakpoint_at; |
12330 | ||
06edf0c0 PA |
12331 | switch (b->type) |
12332 | { | |
348d480f PA |
12333 | case bp_shlib_event: |
12334 | /* Did we stop because the user set the stop_on_solib_events | |
12335 | variable? (If so, we report this as a generic, "Stopped due | |
12336 | to shlib event" message.) */ | |
edcc5120 | 12337 | print_solib_event (0); |
348d480f PA |
12338 | break; |
12339 | ||
12340 | case bp_thread_event: | |
12341 | /* Not sure how we will get here. | |
12342 | GDB should not stop for these breakpoints. */ | |
12343 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
12344 | break; |
12345 | ||
12346 | case bp_overlay_event: | |
12347 | /* By analogy with the thread event, GDB should not stop for these. */ | |
12348 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
12349 | break; |
12350 | ||
12351 | case bp_longjmp_master: | |
12352 | /* These should never be enabled. */ | |
12353 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
12354 | break; |
12355 | ||
12356 | case bp_std_terminate_master: | |
12357 | /* These should never be enabled. */ | |
12358 | printf_filtered (_("std::terminate Master Breakpoint: " | |
12359 | "gdb should not stop!\n")); | |
348d480f PA |
12360 | break; |
12361 | ||
12362 | case bp_exception_master: | |
12363 | /* These should never be enabled. */ | |
12364 | printf_filtered (_("Exception Master Breakpoint: " | |
12365 | "gdb should not stop!\n")); | |
06edf0c0 PA |
12366 | break; |
12367 | } | |
12368 | ||
001c8c33 | 12369 | return PRINT_NOTHING; |
06edf0c0 PA |
12370 | } |
12371 | ||
12372 | static void | |
12373 | internal_bkpt_print_mention (struct breakpoint *b) | |
12374 | { | |
12375 | /* Nothing to mention. These breakpoints are internal. */ | |
12376 | } | |
12377 | ||
06edf0c0 PA |
12378 | /* Virtual table for momentary breakpoints */ |
12379 | ||
12380 | static void | |
12381 | momentary_bkpt_re_set (struct breakpoint *b) | |
12382 | { | |
12383 | /* Keep temporary breakpoints, which can be encountered when we step | |
12384 | over a dlopen call and SOLIB_ADD is resetting the breakpoints. | |
12385 | Otherwise these should have been blown away via the cleanup chain | |
12386 | or by breakpoint_init_inferior when we rerun the executable. */ | |
12387 | } | |
12388 | ||
12389 | static void | |
12390 | momentary_bkpt_check_status (bpstat bs) | |
12391 | { | |
12392 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
12393 | } | |
12394 | ||
12395 | static enum print_stop_action | |
12396 | momentary_bkpt_print_it (bpstat bs) | |
12397 | { | |
79a45e25 PA |
12398 | struct ui_out *uiout = current_uiout; |
12399 | ||
001c8c33 | 12400 | if (ui_out_is_mi_like_p (uiout)) |
06edf0c0 | 12401 | { |
001c8c33 | 12402 | struct breakpoint *b = bs->breakpoint_at; |
348d480f | 12403 | |
001c8c33 PA |
12404 | switch (b->type) |
12405 | { | |
12406 | case bp_finish: | |
12407 | ui_out_field_string | |
12408 | (uiout, "reason", | |
12409 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
12410 | break; | |
348d480f | 12411 | |
001c8c33 PA |
12412 | case bp_until: |
12413 | ui_out_field_string | |
12414 | (uiout, "reason", | |
12415 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
12416 | break; | |
12417 | } | |
348d480f PA |
12418 | } |
12419 | ||
001c8c33 | 12420 | return PRINT_UNKNOWN; |
348d480f PA |
12421 | } |
12422 | ||
06edf0c0 PA |
12423 | static void |
12424 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 12425 | { |
06edf0c0 | 12426 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
12427 | } |
12428 | ||
348d480f | 12429 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 12430 | |
348d480f PA |
12431 | static void |
12432 | tracepoint_re_set (struct breakpoint *b) | |
12433 | { | |
12434 | breakpoint_re_set_default (b); | |
12435 | } | |
876fa593 | 12436 | |
348d480f PA |
12437 | static int |
12438 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
09ac7c10 TT |
12439 | struct address_space *aspace, CORE_ADDR bp_addr, |
12440 | const struct target_waitstatus *ws) | |
348d480f PA |
12441 | { |
12442 | /* By definition, the inferior does not report stops at | |
12443 | tracepoints. */ | |
12444 | return 0; | |
74960c60 VP |
12445 | } |
12446 | ||
12447 | static void | |
348d480f PA |
12448 | tracepoint_print_one_detail (const struct breakpoint *self, |
12449 | struct ui_out *uiout) | |
74960c60 | 12450 | { |
d9b3f62e PA |
12451 | struct tracepoint *tp = (struct tracepoint *) self; |
12452 | if (tp->static_trace_marker_id) | |
348d480f PA |
12453 | { |
12454 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 12455 | |
348d480f PA |
12456 | ui_out_text (uiout, "\tmarker id is "); |
12457 | ui_out_field_string (uiout, "static-tracepoint-marker-string-id", | |
d9b3f62e | 12458 | tp->static_trace_marker_id); |
348d480f PA |
12459 | ui_out_text (uiout, "\n"); |
12460 | } | |
0d381245 VP |
12461 | } |
12462 | ||
a474d7c2 | 12463 | static void |
348d480f | 12464 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 12465 | { |
79a45e25 | 12466 | if (ui_out_is_mi_like_p (current_uiout)) |
348d480f | 12467 | return; |
cc59ec59 | 12468 | |
348d480f PA |
12469 | switch (b->type) |
12470 | { | |
12471 | case bp_tracepoint: | |
12472 | printf_filtered (_("Tracepoint")); | |
12473 | printf_filtered (_(" %d"), b->number); | |
12474 | break; | |
12475 | case bp_fast_tracepoint: | |
12476 | printf_filtered (_("Fast tracepoint")); | |
12477 | printf_filtered (_(" %d"), b->number); | |
12478 | break; | |
12479 | case bp_static_tracepoint: | |
12480 | printf_filtered (_("Static tracepoint")); | |
12481 | printf_filtered (_(" %d"), b->number); | |
12482 | break; | |
12483 | default: | |
12484 | internal_error (__FILE__, __LINE__, | |
12485 | _("unhandled tracepoint type %d"), (int) b->type); | |
12486 | } | |
12487 | ||
12488 | say_where (b); | |
a474d7c2 PA |
12489 | } |
12490 | ||
348d480f | 12491 | static void |
d9b3f62e | 12492 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 12493 | { |
d9b3f62e PA |
12494 | struct tracepoint *tp = (struct tracepoint *) self; |
12495 | ||
12496 | if (self->type == bp_fast_tracepoint) | |
348d480f | 12497 | fprintf_unfiltered (fp, "ftrace"); |
d9b3f62e | 12498 | if (self->type == bp_static_tracepoint) |
348d480f | 12499 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 12500 | else if (self->type == bp_tracepoint) |
348d480f PA |
12501 | fprintf_unfiltered (fp, "trace"); |
12502 | else | |
12503 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 12504 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 12505 | |
d9b3f62e PA |
12506 | fprintf_unfiltered (fp, " %s", self->addr_string); |
12507 | print_recreate_thread (self, fp); | |
12508 | ||
12509 | if (tp->pass_count) | |
12510 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
12511 | } |
12512 | ||
983af33b SDJ |
12513 | static void |
12514 | tracepoint_create_sals_from_address (char **arg, | |
12515 | struct linespec_result *canonical, | |
12516 | enum bptype type_wanted, | |
12517 | char *addr_start, char **copy_arg) | |
12518 | { | |
12519 | create_sals_from_address_default (arg, canonical, type_wanted, | |
12520 | addr_start, copy_arg); | |
12521 | } | |
12522 | ||
12523 | static void | |
12524 | tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12525 | struct linespec_result *canonical, | |
12526 | struct linespec_sals *lsal, | |
12527 | char *cond_string, | |
12528 | enum bptype type_wanted, | |
12529 | enum bpdisp disposition, | |
12530 | int thread, | |
12531 | int task, int ignore_count, | |
12532 | const struct breakpoint_ops *ops, | |
12533 | int from_tty, int enabled, | |
44f238bb | 12534 | int internal, unsigned flags) |
983af33b SDJ |
12535 | { |
12536 | create_breakpoints_sal_default (gdbarch, canonical, lsal, | |
12537 | cond_string, type_wanted, | |
12538 | disposition, thread, task, | |
12539 | ignore_count, ops, from_tty, | |
44f238bb | 12540 | enabled, internal, flags); |
983af33b SDJ |
12541 | } |
12542 | ||
12543 | static void | |
12544 | tracepoint_decode_linespec (struct breakpoint *b, char **s, | |
12545 | struct symtabs_and_lines *sals) | |
12546 | { | |
12547 | decode_linespec_default (b, s, sals); | |
12548 | } | |
12549 | ||
2060206e | 12550 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 12551 | |
983af33b SDJ |
12552 | /* The breakpoint_ops structure to be used on static tracepoints with |
12553 | markers (`-m'). */ | |
12554 | ||
12555 | static void | |
12556 | strace_marker_create_sals_from_address (char **arg, | |
12557 | struct linespec_result *canonical, | |
12558 | enum bptype type_wanted, | |
12559 | char *addr_start, char **copy_arg) | |
12560 | { | |
12561 | struct linespec_sals lsal; | |
12562 | ||
12563 | lsal.sals = decode_static_tracepoint_spec (arg); | |
12564 | ||
12565 | *copy_arg = savestring (addr_start, *arg - addr_start); | |
12566 | ||
12567 | canonical->addr_string = xstrdup (*copy_arg); | |
12568 | lsal.canonical = xstrdup (*copy_arg); | |
12569 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
12570 | } | |
12571 | ||
12572 | static void | |
12573 | strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12574 | struct linespec_result *canonical, | |
12575 | struct linespec_sals *lsal, | |
12576 | char *cond_string, | |
12577 | enum bptype type_wanted, | |
12578 | enum bpdisp disposition, | |
12579 | int thread, | |
12580 | int task, int ignore_count, | |
12581 | const struct breakpoint_ops *ops, | |
12582 | int from_tty, int enabled, | |
44f238bb | 12583 | int internal, unsigned flags) |
983af33b SDJ |
12584 | { |
12585 | int i; | |
12586 | ||
12587 | /* If the user is creating a static tracepoint by marker id | |
12588 | (strace -m MARKER_ID), then store the sals index, so that | |
12589 | breakpoint_re_set can try to match up which of the newly | |
12590 | found markers corresponds to this one, and, don't try to | |
12591 | expand multiple locations for each sal, given than SALS | |
12592 | already should contain all sals for MARKER_ID. */ | |
12593 | ||
12594 | for (i = 0; i < lsal->sals.nelts; ++i) | |
12595 | { | |
12596 | struct symtabs_and_lines expanded; | |
12597 | struct tracepoint *tp; | |
12598 | struct cleanup *old_chain; | |
12599 | char *addr_string; | |
12600 | ||
12601 | expanded.nelts = 1; | |
12602 | expanded.sals = &lsal->sals.sals[i]; | |
12603 | ||
12604 | addr_string = xstrdup (canonical->addr_string); | |
12605 | old_chain = make_cleanup (xfree, addr_string); | |
12606 | ||
12607 | tp = XCNEW (struct tracepoint); | |
12608 | init_breakpoint_sal (&tp->base, gdbarch, expanded, | |
12609 | addr_string, NULL, | |
12610 | cond_string, type_wanted, disposition, | |
12611 | thread, task, ignore_count, ops, | |
44f238bb | 12612 | from_tty, enabled, internal, flags, |
983af33b SDJ |
12613 | canonical->special_display); |
12614 | /* Given that its possible to have multiple markers with | |
12615 | the same string id, if the user is creating a static | |
12616 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
12617 | store the sals index, so that breakpoint_re_set can | |
12618 | try to match up which of the newly found markers | |
12619 | corresponds to this one */ | |
12620 | tp->static_trace_marker_id_idx = i; | |
12621 | ||
12622 | install_breakpoint (internal, &tp->base, 0); | |
12623 | ||
12624 | discard_cleanups (old_chain); | |
12625 | } | |
12626 | } | |
12627 | ||
12628 | static void | |
12629 | strace_marker_decode_linespec (struct breakpoint *b, char **s, | |
12630 | struct symtabs_and_lines *sals) | |
12631 | { | |
12632 | struct tracepoint *tp = (struct tracepoint *) b; | |
12633 | ||
12634 | *sals = decode_static_tracepoint_spec (s); | |
12635 | if (sals->nelts > tp->static_trace_marker_id_idx) | |
12636 | { | |
12637 | sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx]; | |
12638 | sals->nelts = 1; | |
12639 | } | |
12640 | else | |
12641 | error (_("marker %s not found"), tp->static_trace_marker_id); | |
12642 | } | |
12643 | ||
12644 | static struct breakpoint_ops strace_marker_breakpoint_ops; | |
12645 | ||
12646 | static int | |
12647 | strace_marker_p (struct breakpoint *b) | |
12648 | { | |
12649 | return b->ops == &strace_marker_breakpoint_ops; | |
12650 | } | |
12651 | ||
53a5351d | 12652 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 12653 | structures. */ |
c906108c SS |
12654 | |
12655 | void | |
fba45db2 | 12656 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 12657 | { |
52f0bd74 | 12658 | struct breakpoint *b; |
c906108c | 12659 | |
8a3fe4f8 | 12660 | gdb_assert (bpt != NULL); |
c906108c | 12661 | |
4a64f543 MS |
12662 | /* Has this bp already been deleted? This can happen because |
12663 | multiple lists can hold pointers to bp's. bpstat lists are | |
12664 | especial culprits. | |
12665 | ||
12666 | One example of this happening is a watchpoint's scope bp. When | |
12667 | the scope bp triggers, we notice that the watchpoint is out of | |
12668 | scope, and delete it. We also delete its scope bp. But the | |
12669 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
12670 | That bpstat is then checked for auto-deleting bp's, which are | |
12671 | deleted. | |
12672 | ||
12673 | A real solution to this problem might involve reference counts in | |
12674 | bp's, and/or giving them pointers back to their referencing | |
12675 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
12676 | storage when no more references were extent. A cheaper bandaid | |
12677 | was chosen. */ | |
c906108c SS |
12678 | if (bpt->type == bp_none) |
12679 | return; | |
12680 | ||
4a64f543 MS |
12681 | /* At least avoid this stale reference until the reference counting |
12682 | of breakpoints gets resolved. */ | |
d0fb5eae | 12683 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 12684 | { |
d0fb5eae | 12685 | struct breakpoint *related; |
3a5c3e22 | 12686 | struct watchpoint *w; |
d0fb5eae JK |
12687 | |
12688 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 12689 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 12690 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
12691 | w = (struct watchpoint *) bpt; |
12692 | else | |
12693 | w = NULL; | |
12694 | if (w != NULL) | |
12695 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
12696 | |
12697 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
12698 | for (related = bpt; related->related_breakpoint != bpt; | |
12699 | related = related->related_breakpoint); | |
12700 | related->related_breakpoint = bpt->related_breakpoint; | |
12701 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
12702 | } |
12703 | ||
a9634178 TJB |
12704 | /* watch_command_1 creates a watchpoint but only sets its number if |
12705 | update_watchpoint succeeds in creating its bp_locations. If there's | |
12706 | a problem in that process, we'll be asked to delete the half-created | |
12707 | watchpoint. In that case, don't announce the deletion. */ | |
12708 | if (bpt->number) | |
12709 | observer_notify_breakpoint_deleted (bpt); | |
c906108c | 12710 | |
c906108c SS |
12711 | if (breakpoint_chain == bpt) |
12712 | breakpoint_chain = bpt->next; | |
12713 | ||
c906108c SS |
12714 | ALL_BREAKPOINTS (b) |
12715 | if (b->next == bpt) | |
c5aa993b JM |
12716 | { |
12717 | b->next = bpt->next; | |
12718 | break; | |
12719 | } | |
c906108c | 12720 | |
f431efe5 PA |
12721 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
12722 | been freed. */ | |
12723 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 12724 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
12725 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
12726 | commands are associated with the bpstat; if we remove it here, | |
12727 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
12728 | event-top.c won't do anything, and temporary breakpoints with | |
12729 | commands won't work. */ | |
12730 | ||
12731 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
12732 | ||
4a64f543 MS |
12733 | /* Now that breakpoint is removed from breakpoint list, update the |
12734 | global location list. This will remove locations that used to | |
12735 | belong to this breakpoint. Do this before freeing the breakpoint | |
12736 | itself, since remove_breakpoint looks at location's owner. It | |
12737 | might be better design to have location completely | |
12738 | self-contained, but it's not the case now. */ | |
b60e7edf | 12739 | update_global_location_list (0); |
74960c60 | 12740 | |
348d480f | 12741 | bpt->ops->dtor (bpt); |
4a64f543 MS |
12742 | /* On the chance that someone will soon try again to delete this |
12743 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 12744 | bpt->type = bp_none; |
b8c9b27d | 12745 | xfree (bpt); |
c906108c SS |
12746 | } |
12747 | ||
4d6140d9 AC |
12748 | static void |
12749 | do_delete_breakpoint_cleanup (void *b) | |
12750 | { | |
12751 | delete_breakpoint (b); | |
12752 | } | |
12753 | ||
12754 | struct cleanup * | |
12755 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
12756 | { | |
12757 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
12758 | } | |
12759 | ||
51be5b68 PA |
12760 | /* Iterator function to call a user-provided callback function once |
12761 | for each of B and its related breakpoints. */ | |
12762 | ||
12763 | static void | |
12764 | iterate_over_related_breakpoints (struct breakpoint *b, | |
12765 | void (*function) (struct breakpoint *, | |
12766 | void *), | |
12767 | void *data) | |
12768 | { | |
12769 | struct breakpoint *related; | |
12770 | ||
12771 | related = b; | |
12772 | do | |
12773 | { | |
12774 | struct breakpoint *next; | |
12775 | ||
12776 | /* FUNCTION may delete RELATED. */ | |
12777 | next = related->related_breakpoint; | |
12778 | ||
12779 | if (next == related) | |
12780 | { | |
12781 | /* RELATED is the last ring entry. */ | |
12782 | function (related, data); | |
12783 | ||
12784 | /* FUNCTION may have deleted it, so we'd never reach back to | |
12785 | B. There's nothing left to do anyway, so just break | |
12786 | out. */ | |
12787 | break; | |
12788 | } | |
12789 | else | |
12790 | function (related, data); | |
12791 | ||
12792 | related = next; | |
12793 | } | |
12794 | while (related != b); | |
12795 | } | |
95a42b64 TT |
12796 | |
12797 | static void | |
12798 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
12799 | { | |
12800 | delete_breakpoint (b); | |
12801 | } | |
12802 | ||
51be5b68 PA |
12803 | /* A callback for map_breakpoint_numbers that calls |
12804 | delete_breakpoint. */ | |
12805 | ||
12806 | static void | |
12807 | do_map_delete_breakpoint (struct breakpoint *b, void *ignore) | |
12808 | { | |
12809 | iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL); | |
12810 | } | |
12811 | ||
c906108c | 12812 | void |
fba45db2 | 12813 | delete_command (char *arg, int from_tty) |
c906108c | 12814 | { |
35df4500 | 12815 | struct breakpoint *b, *b_tmp; |
c906108c | 12816 | |
ea9365bb TT |
12817 | dont_repeat (); |
12818 | ||
c906108c SS |
12819 | if (arg == 0) |
12820 | { | |
12821 | int breaks_to_delete = 0; | |
12822 | ||
46c6471b PA |
12823 | /* Delete all breakpoints if no argument. Do not delete |
12824 | internal breakpoints, these have to be deleted with an | |
12825 | explicit breakpoint number argument. */ | |
c5aa993b | 12826 | ALL_BREAKPOINTS (b) |
46c6471b | 12827 | if (user_breakpoint_p (b)) |
973d738b DJ |
12828 | { |
12829 | breaks_to_delete = 1; | |
12830 | break; | |
12831 | } | |
c906108c SS |
12832 | |
12833 | /* Ask user only if there are some breakpoints to delete. */ | |
12834 | if (!from_tty | |
e2e0b3e5 | 12835 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 12836 | { |
35df4500 | 12837 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 12838 | if (user_breakpoint_p (b)) |
c5aa993b | 12839 | delete_breakpoint (b); |
c906108c SS |
12840 | } |
12841 | } | |
12842 | else | |
51be5b68 | 12843 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
c906108c SS |
12844 | } |
12845 | ||
0d381245 VP |
12846 | static int |
12847 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 12848 | { |
0d381245 | 12849 | for (; loc; loc = loc->next) |
8645ff69 UW |
12850 | if (!loc->shlib_disabled |
12851 | && !loc->pspace->executing_startup) | |
0d381245 VP |
12852 | return 0; |
12853 | return 1; | |
fe3f5fa8 VP |
12854 | } |
12855 | ||
776592bf DE |
12856 | /* Subroutine of update_breakpoint_locations to simplify it. |
12857 | Return non-zero if multiple fns in list LOC have the same name. | |
12858 | Null names are ignored. */ | |
12859 | ||
12860 | static int | |
12861 | ambiguous_names_p (struct bp_location *loc) | |
12862 | { | |
12863 | struct bp_location *l; | |
12864 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
12865 | (int (*) (const void *, |
12866 | const void *)) streq, | |
776592bf DE |
12867 | NULL, xcalloc, xfree); |
12868 | ||
12869 | for (l = loc; l != NULL; l = l->next) | |
12870 | { | |
12871 | const char **slot; | |
12872 | const char *name = l->function_name; | |
12873 | ||
12874 | /* Allow for some names to be NULL, ignore them. */ | |
12875 | if (name == NULL) | |
12876 | continue; | |
12877 | ||
12878 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
12879 | INSERT); | |
4a64f543 MS |
12880 | /* NOTE: We can assume slot != NULL here because xcalloc never |
12881 | returns NULL. */ | |
776592bf DE |
12882 | if (*slot != NULL) |
12883 | { | |
12884 | htab_delete (htab); | |
12885 | return 1; | |
12886 | } | |
12887 | *slot = name; | |
12888 | } | |
12889 | ||
12890 | htab_delete (htab); | |
12891 | return 0; | |
12892 | } | |
12893 | ||
0fb4aa4b PA |
12894 | /* When symbols change, it probably means the sources changed as well, |
12895 | and it might mean the static tracepoint markers are no longer at | |
12896 | the same address or line numbers they used to be at last we | |
12897 | checked. Losing your static tracepoints whenever you rebuild is | |
12898 | undesirable. This function tries to resync/rematch gdb static | |
12899 | tracepoints with the markers on the target, for static tracepoints | |
12900 | that have not been set by marker id. Static tracepoint that have | |
12901 | been set by marker id are reset by marker id in breakpoint_re_set. | |
12902 | The heuristic is: | |
12903 | ||
12904 | 1) For a tracepoint set at a specific address, look for a marker at | |
12905 | the old PC. If one is found there, assume to be the same marker. | |
12906 | If the name / string id of the marker found is different from the | |
12907 | previous known name, assume that means the user renamed the marker | |
12908 | in the sources, and output a warning. | |
12909 | ||
12910 | 2) For a tracepoint set at a given line number, look for a marker | |
12911 | at the new address of the old line number. If one is found there, | |
12912 | assume to be the same marker. If the name / string id of the | |
12913 | marker found is different from the previous known name, assume that | |
12914 | means the user renamed the marker in the sources, and output a | |
12915 | warning. | |
12916 | ||
12917 | 3) If a marker is no longer found at the same address or line, it | |
12918 | may mean the marker no longer exists. But it may also just mean | |
12919 | the code changed a bit. Maybe the user added a few lines of code | |
12920 | that made the marker move up or down (in line number terms). Ask | |
12921 | the target for info about the marker with the string id as we knew | |
12922 | it. If found, update line number and address in the matching | |
12923 | static tracepoint. This will get confused if there's more than one | |
12924 | marker with the same ID (possible in UST, although unadvised | |
12925 | precisely because it confuses tools). */ | |
12926 | ||
12927 | static struct symtab_and_line | |
12928 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
12929 | { | |
d9b3f62e | 12930 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
12931 | struct static_tracepoint_marker marker; |
12932 | CORE_ADDR pc; | |
12933 | int i; | |
12934 | ||
12935 | pc = sal.pc; | |
12936 | if (sal.line) | |
12937 | find_line_pc (sal.symtab, sal.line, &pc); | |
12938 | ||
12939 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
12940 | { | |
d9b3f62e | 12941 | if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0) |
0fb4aa4b PA |
12942 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
12943 | b->number, | |
d9b3f62e | 12944 | tp->static_trace_marker_id, marker.str_id); |
0fb4aa4b | 12945 | |
d9b3f62e PA |
12946 | xfree (tp->static_trace_marker_id); |
12947 | tp->static_trace_marker_id = xstrdup (marker.str_id); | |
0fb4aa4b PA |
12948 | release_static_tracepoint_marker (&marker); |
12949 | ||
12950 | return sal; | |
12951 | } | |
12952 | ||
12953 | /* Old marker wasn't found on target at lineno. Try looking it up | |
12954 | by string ID. */ | |
12955 | if (!sal.explicit_pc | |
12956 | && sal.line != 0 | |
12957 | && sal.symtab != NULL | |
d9b3f62e | 12958 | && tp->static_trace_marker_id != NULL) |
0fb4aa4b PA |
12959 | { |
12960 | VEC(static_tracepoint_marker_p) *markers; | |
12961 | ||
12962 | markers | |
d9b3f62e | 12963 | = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id); |
0fb4aa4b PA |
12964 | |
12965 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
12966 | { | |
80e1d417 | 12967 | struct symtab_and_line sal2; |
0fb4aa4b | 12968 | struct symbol *sym; |
80e1d417 | 12969 | struct static_tracepoint_marker *tpmarker; |
79a45e25 | 12970 | struct ui_out *uiout = current_uiout; |
0fb4aa4b | 12971 | |
80e1d417 | 12972 | tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0); |
0fb4aa4b | 12973 | |
d9b3f62e | 12974 | xfree (tp->static_trace_marker_id); |
80e1d417 | 12975 | tp->static_trace_marker_id = xstrdup (tpmarker->str_id); |
0fb4aa4b PA |
12976 | |
12977 | warning (_("marker for static tracepoint %d (%s) not " | |
12978 | "found at previous line number"), | |
d9b3f62e | 12979 | b->number, tp->static_trace_marker_id); |
0fb4aa4b | 12980 | |
80e1d417 | 12981 | init_sal (&sal2); |
0fb4aa4b | 12982 | |
80e1d417 | 12983 | sal2.pc = tpmarker->address; |
0fb4aa4b | 12984 | |
80e1d417 AS |
12985 | sal2 = find_pc_line (tpmarker->address, 0); |
12986 | sym = find_pc_sect_function (tpmarker->address, NULL); | |
0fb4aa4b PA |
12987 | ui_out_text (uiout, "Now in "); |
12988 | if (sym) | |
12989 | { | |
12990 | ui_out_field_string (uiout, "func", | |
12991 | SYMBOL_PRINT_NAME (sym)); | |
12992 | ui_out_text (uiout, " at "); | |
12993 | } | |
80e1d417 | 12994 | ui_out_field_string (uiout, "file", sal2.symtab->filename); |
0fb4aa4b PA |
12995 | ui_out_text (uiout, ":"); |
12996 | ||
12997 | if (ui_out_is_mi_like_p (uiout)) | |
12998 | { | |
80e1d417 | 12999 | char *fullname = symtab_to_fullname (sal2.symtab); |
0fb4aa4b PA |
13000 | |
13001 | if (fullname) | |
13002 | ui_out_field_string (uiout, "fullname", fullname); | |
13003 | } | |
13004 | ||
80e1d417 | 13005 | ui_out_field_int (uiout, "line", sal2.line); |
0fb4aa4b PA |
13006 | ui_out_text (uiout, "\n"); |
13007 | ||
80e1d417 | 13008 | b->loc->line_number = sal2.line; |
0fb4aa4b | 13009 | |
f8eba3c6 | 13010 | xfree (b->loc->source_file); |
0fb4aa4b | 13011 | if (sym) |
80e1d417 | 13012 | b->loc->source_file = xstrdup (sal2.symtab->filename); |
0fb4aa4b | 13013 | else |
f8eba3c6 | 13014 | b->loc->source_file = NULL; |
0fb4aa4b PA |
13015 | |
13016 | xfree (b->addr_string); | |
13017 | b->addr_string = xstrprintf ("%s:%d", | |
80e1d417 | 13018 | sal2.symtab->filename, |
f8eba3c6 | 13019 | b->loc->line_number); |
0fb4aa4b PA |
13020 | |
13021 | /* Might be nice to check if function changed, and warn if | |
13022 | so. */ | |
13023 | ||
80e1d417 | 13024 | release_static_tracepoint_marker (tpmarker); |
0fb4aa4b PA |
13025 | } |
13026 | } | |
13027 | return sal; | |
13028 | } | |
13029 | ||
8d3788bd VP |
13030 | /* Returns 1 iff locations A and B are sufficiently same that |
13031 | we don't need to report breakpoint as changed. */ | |
13032 | ||
13033 | static int | |
13034 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
13035 | { | |
13036 | while (a && b) | |
13037 | { | |
13038 | if (a->address != b->address) | |
13039 | return 0; | |
13040 | ||
13041 | if (a->shlib_disabled != b->shlib_disabled) | |
13042 | return 0; | |
13043 | ||
13044 | if (a->enabled != b->enabled) | |
13045 | return 0; | |
13046 | ||
13047 | a = a->next; | |
13048 | b = b->next; | |
13049 | } | |
13050 | ||
13051 | if ((a == NULL) != (b == NULL)) | |
13052 | return 0; | |
13053 | ||
13054 | return 1; | |
13055 | } | |
13056 | ||
f1310107 TJB |
13057 | /* Create new breakpoint locations for B (a hardware or software breakpoint) |
13058 | based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is | |
13059 | a ranged breakpoint. */ | |
13060 | ||
0e30163f | 13061 | void |
0d381245 | 13062 | update_breakpoint_locations (struct breakpoint *b, |
f1310107 TJB |
13063 | struct symtabs_and_lines sals, |
13064 | struct symtabs_and_lines sals_end) | |
fe3f5fa8 VP |
13065 | { |
13066 | int i; | |
0d381245 VP |
13067 | struct bp_location *existing_locations = b->loc; |
13068 | ||
f8eba3c6 TT |
13069 | if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1)) |
13070 | { | |
13071 | /* Ranged breakpoints have only one start location and one end | |
13072 | location. */ | |
13073 | b->enable_state = bp_disabled; | |
13074 | update_global_location_list (1); | |
13075 | printf_unfiltered (_("Could not reset ranged breakpoint %d: " | |
13076 | "multiple locations found\n"), | |
13077 | b->number); | |
13078 | return; | |
13079 | } | |
f1310107 | 13080 | |
4a64f543 MS |
13081 | /* If there's no new locations, and all existing locations are |
13082 | pending, don't do anything. This optimizes the common case where | |
13083 | all locations are in the same shared library, that was unloaded. | |
13084 | We'd like to retain the location, so that when the library is | |
13085 | loaded again, we don't loose the enabled/disabled status of the | |
13086 | individual locations. */ | |
0d381245 | 13087 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) |
fe3f5fa8 VP |
13088 | return; |
13089 | ||
fe3f5fa8 VP |
13090 | b->loc = NULL; |
13091 | ||
0d381245 | 13092 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 13093 | { |
f8eba3c6 TT |
13094 | struct bp_location *new_loc; |
13095 | ||
13096 | switch_to_program_space_and_thread (sals.sals[i].pspace); | |
13097 | ||
13098 | new_loc = add_location_to_breakpoint (b, &(sals.sals[i])); | |
fe3f5fa8 | 13099 | |
0d381245 VP |
13100 | /* Reparse conditions, they might contain references to the |
13101 | old symtab. */ | |
13102 | if (b->cond_string != NULL) | |
13103 | { | |
f1310107 | 13104 | char *s; |
bfd189b1 | 13105 | volatile struct gdb_exception e; |
fe3f5fa8 | 13106 | |
0d381245 VP |
13107 | s = b->cond_string; |
13108 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
13109 | { | |
13110 | new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), | |
13111 | 0); | |
13112 | } | |
13113 | if (e.reason < 0) | |
13114 | { | |
3e43a32a MS |
13115 | warning (_("failed to reevaluate condition " |
13116 | "for breakpoint %d: %s"), | |
0d381245 VP |
13117 | b->number, e.message); |
13118 | new_loc->enabled = 0; | |
13119 | } | |
13120 | } | |
fe3f5fa8 | 13121 | |
f1310107 TJB |
13122 | if (sals_end.nelts) |
13123 | { | |
13124 | CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]); | |
13125 | ||
13126 | new_loc->length = end - sals.sals[0].pc + 1; | |
13127 | } | |
0d381245 | 13128 | } |
fe3f5fa8 | 13129 | |
514f746b AR |
13130 | /* Update locations of permanent breakpoints. */ |
13131 | if (b->enable_state == bp_permanent) | |
13132 | make_breakpoint_permanent (b); | |
13133 | ||
4a64f543 MS |
13134 | /* If possible, carry over 'disable' status from existing |
13135 | breakpoints. */ | |
0d381245 VP |
13136 | { |
13137 | struct bp_location *e = existing_locations; | |
776592bf DE |
13138 | /* If there are multiple breakpoints with the same function name, |
13139 | e.g. for inline functions, comparing function names won't work. | |
13140 | Instead compare pc addresses; this is just a heuristic as things | |
13141 | may have moved, but in practice it gives the correct answer | |
13142 | often enough until a better solution is found. */ | |
13143 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
13144 | ||
0d381245 VP |
13145 | for (; e; e = e->next) |
13146 | { | |
13147 | if (!e->enabled && e->function_name) | |
13148 | { | |
13149 | struct bp_location *l = b->loc; | |
776592bf DE |
13150 | if (have_ambiguous_names) |
13151 | { | |
13152 | for (; l; l = l->next) | |
f1310107 | 13153 | if (breakpoint_locations_match (e, l)) |
776592bf DE |
13154 | { |
13155 | l->enabled = 0; | |
13156 | break; | |
13157 | } | |
13158 | } | |
13159 | else | |
13160 | { | |
13161 | for (; l; l = l->next) | |
13162 | if (l->function_name | |
13163 | && strcmp (e->function_name, l->function_name) == 0) | |
13164 | { | |
13165 | l->enabled = 0; | |
13166 | break; | |
13167 | } | |
13168 | } | |
0d381245 VP |
13169 | } |
13170 | } | |
13171 | } | |
fe3f5fa8 | 13172 | |
8d3788bd VP |
13173 | if (!locations_are_equal (existing_locations, b->loc)) |
13174 | observer_notify_breakpoint_modified (b); | |
13175 | ||
b60e7edf | 13176 | update_global_location_list (1); |
fe3f5fa8 VP |
13177 | } |
13178 | ||
ef23e705 TJB |
13179 | /* Find the SaL locations corresponding to the given ADDR_STRING. |
13180 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ | |
13181 | ||
13182 | static struct symtabs_and_lines | |
13183 | addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found) | |
13184 | { | |
13185 | char *s; | |
02d20e4a | 13186 | struct symtabs_and_lines sals = {0}; |
f8eba3c6 | 13187 | volatile struct gdb_exception e; |
ef23e705 | 13188 | |
983af33b | 13189 | gdb_assert (b->ops != NULL); |
ef23e705 | 13190 | s = addr_string; |
ef23e705 TJB |
13191 | |
13192 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
13193 | { | |
983af33b | 13194 | b->ops->decode_linespec (b, &s, &sals); |
ef23e705 TJB |
13195 | } |
13196 | if (e.reason < 0) | |
13197 | { | |
13198 | int not_found_and_ok = 0; | |
13199 | /* For pending breakpoints, it's expected that parsing will | |
13200 | fail until the right shared library is loaded. User has | |
13201 | already told to create pending breakpoints and don't need | |
13202 | extra messages. If breakpoint is in bp_shlib_disabled | |
13203 | state, then user already saw the message about that | |
13204 | breakpoint being disabled, and don't want to see more | |
13205 | errors. */ | |
58438ac1 | 13206 | if (e.error == NOT_FOUND_ERROR |
ef23e705 TJB |
13207 | && (b->condition_not_parsed |
13208 | || (b->loc && b->loc->shlib_disabled) | |
f8eba3c6 | 13209 | || (b->loc && b->loc->pspace->executing_startup) |
ef23e705 TJB |
13210 | || b->enable_state == bp_disabled)) |
13211 | not_found_and_ok = 1; | |
13212 | ||
13213 | if (!not_found_and_ok) | |
13214 | { | |
13215 | /* We surely don't want to warn about the same breakpoint | |
13216 | 10 times. One solution, implemented here, is disable | |
13217 | the breakpoint on error. Another solution would be to | |
13218 | have separate 'warning emitted' flag. Since this | |
13219 | happens only when a binary has changed, I don't know | |
13220 | which approach is better. */ | |
13221 | b->enable_state = bp_disabled; | |
13222 | throw_exception (e); | |
13223 | } | |
13224 | } | |
13225 | ||
58438ac1 | 13226 | if (e.reason == 0 || e.error != NOT_FOUND_ERROR) |
ef23e705 | 13227 | { |
f8eba3c6 | 13228 | int i; |
ef23e705 | 13229 | |
f8eba3c6 TT |
13230 | for (i = 0; i < sals.nelts; ++i) |
13231 | resolve_sal_pc (&sals.sals[i]); | |
ef23e705 TJB |
13232 | if (b->condition_not_parsed && s && s[0]) |
13233 | { | |
13234 | char *cond_string = 0; | |
13235 | int thread = -1; | |
13236 | int task = 0; | |
13237 | ||
13238 | find_condition_and_thread (s, sals.sals[0].pc, | |
13239 | &cond_string, &thread, &task); | |
13240 | if (cond_string) | |
13241 | b->cond_string = cond_string; | |
13242 | b->thread = thread; | |
13243 | b->task = task; | |
13244 | b->condition_not_parsed = 0; | |
13245 | } | |
13246 | ||
983af33b | 13247 | if (b->type == bp_static_tracepoint && !strace_marker_p (b)) |
ef23e705 | 13248 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); |
ef23e705 | 13249 | |
58438ac1 TT |
13250 | *found = 1; |
13251 | } | |
13252 | else | |
13253 | *found = 0; | |
ef23e705 TJB |
13254 | |
13255 | return sals; | |
13256 | } | |
13257 | ||
348d480f PA |
13258 | /* The default re_set method, for typical hardware or software |
13259 | breakpoints. Reevaluate the breakpoint and recreate its | |
13260 | locations. */ | |
13261 | ||
13262 | static void | |
28010a5d | 13263 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 TJB |
13264 | { |
13265 | int found; | |
f1310107 | 13266 | struct symtabs_and_lines sals, sals_end; |
ef23e705 | 13267 | struct symtabs_and_lines expanded = {0}; |
f1310107 | 13268 | struct symtabs_and_lines expanded_end = {0}; |
ef23e705 TJB |
13269 | |
13270 | sals = addr_string_to_sals (b, b->addr_string, &found); | |
13271 | if (found) | |
13272 | { | |
13273 | make_cleanup (xfree, sals.sals); | |
f8eba3c6 | 13274 | expanded = sals; |
ef23e705 TJB |
13275 | } |
13276 | ||
f1310107 TJB |
13277 | if (b->addr_string_range_end) |
13278 | { | |
13279 | sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found); | |
13280 | if (found) | |
13281 | { | |
13282 | make_cleanup (xfree, sals_end.sals); | |
f8eba3c6 | 13283 | expanded_end = sals_end; |
f1310107 TJB |
13284 | } |
13285 | } | |
13286 | ||
13287 | update_breakpoint_locations (b, expanded, expanded_end); | |
28010a5d PA |
13288 | } |
13289 | ||
983af33b SDJ |
13290 | /* Default method for creating SALs from an address string. It basically |
13291 | calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ | |
13292 | ||
13293 | static void | |
13294 | create_sals_from_address_default (char **arg, | |
13295 | struct linespec_result *canonical, | |
13296 | enum bptype type_wanted, | |
13297 | char *addr_start, char **copy_arg) | |
13298 | { | |
13299 | parse_breakpoint_sals (arg, canonical); | |
13300 | } | |
13301 | ||
13302 | /* Call create_breakpoints_sal for the given arguments. This is the default | |
13303 | function for the `create_breakpoints_sal' method of | |
13304 | breakpoint_ops. */ | |
13305 | ||
13306 | static void | |
13307 | create_breakpoints_sal_default (struct gdbarch *gdbarch, | |
13308 | struct linespec_result *canonical, | |
13309 | struct linespec_sals *lsal, | |
13310 | char *cond_string, | |
13311 | enum bptype type_wanted, | |
13312 | enum bpdisp disposition, | |
13313 | int thread, | |
13314 | int task, int ignore_count, | |
13315 | const struct breakpoint_ops *ops, | |
13316 | int from_tty, int enabled, | |
44f238bb | 13317 | int internal, unsigned flags) |
983af33b SDJ |
13318 | { |
13319 | create_breakpoints_sal (gdbarch, canonical, cond_string, | |
13320 | type_wanted, disposition, | |
13321 | thread, task, ignore_count, ops, from_tty, | |
44f238bb | 13322 | enabled, internal, flags); |
983af33b SDJ |
13323 | } |
13324 | ||
13325 | /* Decode the line represented by S by calling decode_line_full. This is the | |
13326 | default function for the `decode_linespec' method of breakpoint_ops. */ | |
13327 | ||
13328 | static void | |
13329 | decode_linespec_default (struct breakpoint *b, char **s, | |
13330 | struct symtabs_and_lines *sals) | |
13331 | { | |
13332 | struct linespec_result canonical; | |
13333 | ||
13334 | init_linespec_result (&canonical); | |
13335 | decode_line_full (s, DECODE_LINE_FUNFIRSTLINE, | |
13336 | (struct symtab *) NULL, 0, | |
13337 | &canonical, multiple_symbols_all, | |
13338 | b->filter); | |
13339 | ||
13340 | /* We should get 0 or 1 resulting SALs. */ | |
13341 | gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2); | |
13342 | ||
13343 | if (VEC_length (linespec_sals, canonical.sals) > 0) | |
13344 | { | |
13345 | struct linespec_sals *lsal; | |
13346 | ||
13347 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
13348 | *sals = lsal->sals; | |
13349 | /* Arrange it so the destructor does not free the | |
13350 | contents. */ | |
13351 | lsal->sals.sals = NULL; | |
13352 | } | |
13353 | ||
13354 | destroy_linespec_result (&canonical); | |
13355 | } | |
13356 | ||
28010a5d PA |
13357 | /* Prepare the global context for a re-set of breakpoint B. */ |
13358 | ||
13359 | static struct cleanup * | |
13360 | prepare_re_set_context (struct breakpoint *b) | |
13361 | { | |
13362 | struct cleanup *cleanups; | |
13363 | ||
13364 | input_radix = b->input_radix; | |
13365 | cleanups = save_current_space_and_thread (); | |
f8eba3c6 TT |
13366 | if (b->pspace != NULL) |
13367 | switch_to_program_space_and_thread (b->pspace); | |
28010a5d PA |
13368 | set_language (b->language); |
13369 | ||
13370 | return cleanups; | |
ef23e705 TJB |
13371 | } |
13372 | ||
c906108c SS |
13373 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
13374 | The value we return ends up being the return value from catch_errors. | |
13375 | Unused in this case. */ | |
13376 | ||
13377 | static int | |
4efb68b1 | 13378 | breakpoint_re_set_one (void *bint) |
c906108c | 13379 | { |
4a64f543 | 13380 | /* Get past catch_errs. */ |
53a5351d | 13381 | struct breakpoint *b = (struct breakpoint *) bint; |
348d480f | 13382 | struct cleanup *cleanups; |
c906108c | 13383 | |
348d480f PA |
13384 | cleanups = prepare_re_set_context (b); |
13385 | b->ops->re_set (b); | |
13386 | do_cleanups (cleanups); | |
c906108c SS |
13387 | return 0; |
13388 | } | |
13389 | ||
69de3c6a | 13390 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 13391 | void |
69de3c6a | 13392 | breakpoint_re_set (void) |
c906108c | 13393 | { |
35df4500 | 13394 | struct breakpoint *b, *b_tmp; |
c906108c SS |
13395 | enum language save_language; |
13396 | int save_input_radix; | |
6c95b8df | 13397 | struct cleanup *old_chain; |
c5aa993b | 13398 | |
c906108c SS |
13399 | save_language = current_language->la_language; |
13400 | save_input_radix = input_radix; | |
6c95b8df PA |
13401 | old_chain = save_current_program_space (); |
13402 | ||
35df4500 | 13403 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 13404 | { |
4a64f543 | 13405 | /* Format possible error msg. */ |
fe3f5fa8 | 13406 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
13407 | b->number); |
13408 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 13409 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 13410 | do_cleanups (cleanups); |
c5aa993b | 13411 | } |
c906108c SS |
13412 | set_language (save_language); |
13413 | input_radix = save_input_radix; | |
e62c965a | 13414 | |
0756c555 | 13415 | jit_breakpoint_re_set (); |
4efc6507 | 13416 | |
6c95b8df PA |
13417 | do_cleanups (old_chain); |
13418 | ||
af02033e PP |
13419 | create_overlay_event_breakpoint (); |
13420 | create_longjmp_master_breakpoint (); | |
13421 | create_std_terminate_master_breakpoint (); | |
186c406b | 13422 | create_exception_master_breakpoint (); |
1bfeeb0f JL |
13423 | |
13424 | /* While we're at it, reset the skip list too. */ | |
13425 | skip_re_set (); | |
c906108c SS |
13426 | } |
13427 | \f | |
c906108c SS |
13428 | /* Reset the thread number of this breakpoint: |
13429 | ||
13430 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 13431 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 13432 | void |
fba45db2 | 13433 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
13434 | { |
13435 | if (b->thread != -1) | |
13436 | { | |
39f77062 KB |
13437 | if (in_thread_list (inferior_ptid)) |
13438 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
13439 | |
13440 | /* We're being called after following a fork. The new fork is | |
13441 | selected as current, and unless this was a vfork will have a | |
13442 | different program space from the original thread. Reset that | |
13443 | as well. */ | |
13444 | b->loc->pspace = current_program_space; | |
c906108c SS |
13445 | } |
13446 | } | |
13447 | ||
03ac34d5 MS |
13448 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
13449 | If from_tty is nonzero, it prints a message to that effect, | |
13450 | which ends with a period (no newline). */ | |
13451 | ||
c906108c | 13452 | void |
fba45db2 | 13453 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 13454 | { |
52f0bd74 | 13455 | struct breakpoint *b; |
c906108c SS |
13456 | |
13457 | if (count < 0) | |
13458 | count = 0; | |
13459 | ||
13460 | ALL_BREAKPOINTS (b) | |
13461 | if (b->number == bptnum) | |
c5aa993b | 13462 | { |
d77f58be SS |
13463 | if (is_tracepoint (b)) |
13464 | { | |
13465 | if (from_tty && count != 0) | |
13466 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
13467 | bptnum); | |
13468 | return; | |
13469 | } | |
13470 | ||
c5aa993b | 13471 | b->ignore_count = count; |
221ea385 KS |
13472 | if (from_tty) |
13473 | { | |
13474 | if (count == 0) | |
3e43a32a MS |
13475 | printf_filtered (_("Will stop next time " |
13476 | "breakpoint %d is reached."), | |
221ea385 KS |
13477 | bptnum); |
13478 | else if (count == 1) | |
a3f17187 | 13479 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
13480 | bptnum); |
13481 | else | |
3e43a32a MS |
13482 | printf_filtered (_("Will ignore next %d " |
13483 | "crossings of breakpoint %d."), | |
221ea385 KS |
13484 | count, bptnum); |
13485 | } | |
c5aa993b | 13486 | breakpoints_changed (); |
8d3788bd | 13487 | observer_notify_breakpoint_modified (b); |
c5aa993b JM |
13488 | return; |
13489 | } | |
c906108c | 13490 | |
8a3fe4f8 | 13491 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
13492 | } |
13493 | ||
c906108c SS |
13494 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
13495 | ||
13496 | static void | |
fba45db2 | 13497 | ignore_command (char *args, int from_tty) |
c906108c SS |
13498 | { |
13499 | char *p = args; | |
52f0bd74 | 13500 | int num; |
c906108c SS |
13501 | |
13502 | if (p == 0) | |
e2e0b3e5 | 13503 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 13504 | |
c906108c | 13505 | num = get_number (&p); |
5c44784c | 13506 | if (num == 0) |
8a3fe4f8 | 13507 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 13508 | if (*p == 0) |
8a3fe4f8 | 13509 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
13510 | |
13511 | set_ignore_count (num, | |
13512 | longest_to_int (value_as_long (parse_and_eval (p))), | |
13513 | from_tty); | |
221ea385 KS |
13514 | if (from_tty) |
13515 | printf_filtered ("\n"); | |
c906108c SS |
13516 | } |
13517 | \f | |
13518 | /* Call FUNCTION on each of the breakpoints | |
13519 | whose numbers are given in ARGS. */ | |
13520 | ||
13521 | static void | |
95a42b64 TT |
13522 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
13523 | void *), | |
13524 | void *data) | |
c906108c | 13525 | { |
52f0bd74 AC |
13526 | int num; |
13527 | struct breakpoint *b, *tmp; | |
11cf8741 | 13528 | int match; |
197f0a60 | 13529 | struct get_number_or_range_state state; |
c906108c | 13530 | |
197f0a60 | 13531 | if (args == 0) |
e2e0b3e5 | 13532 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c | 13533 | |
197f0a60 TT |
13534 | init_number_or_range (&state, args); |
13535 | ||
13536 | while (!state.finished) | |
c906108c | 13537 | { |
197f0a60 TT |
13538 | char *p = state.string; |
13539 | ||
11cf8741 | 13540 | match = 0; |
c5aa993b | 13541 | |
197f0a60 | 13542 | num = get_number_or_range (&state); |
5c44784c | 13543 | if (num == 0) |
c5aa993b | 13544 | { |
8a3fe4f8 | 13545 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
13546 | } |
13547 | else | |
13548 | { | |
13549 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
13550 | if (b->number == num) | |
13551 | { | |
11cf8741 | 13552 | match = 1; |
cdac0397 | 13553 | function (b, data); |
11cf8741 | 13554 | break; |
5c44784c | 13555 | } |
11cf8741 | 13556 | if (match == 0) |
a3f17187 | 13557 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 13558 | } |
c906108c SS |
13559 | } |
13560 | } | |
13561 | ||
0d381245 VP |
13562 | static struct bp_location * |
13563 | find_location_by_number (char *number) | |
13564 | { | |
13565 | char *dot = strchr (number, '.'); | |
13566 | char *p1; | |
13567 | int bp_num; | |
13568 | int loc_num; | |
13569 | struct breakpoint *b; | |
13570 | struct bp_location *loc; | |
13571 | ||
13572 | *dot = '\0'; | |
13573 | ||
13574 | p1 = number; | |
197f0a60 | 13575 | bp_num = get_number (&p1); |
0d381245 VP |
13576 | if (bp_num == 0) |
13577 | error (_("Bad breakpoint number '%s'"), number); | |
13578 | ||
13579 | ALL_BREAKPOINTS (b) | |
13580 | if (b->number == bp_num) | |
13581 | { | |
13582 | break; | |
13583 | } | |
13584 | ||
13585 | if (!b || b->number != bp_num) | |
13586 | error (_("Bad breakpoint number '%s'"), number); | |
13587 | ||
13588 | p1 = dot+1; | |
197f0a60 | 13589 | loc_num = get_number (&p1); |
0d381245 VP |
13590 | if (loc_num == 0) |
13591 | error (_("Bad breakpoint location number '%s'"), number); | |
13592 | ||
13593 | --loc_num; | |
13594 | loc = b->loc; | |
13595 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
13596 | ; | |
13597 | if (!loc) | |
13598 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
13599 | ||
13600 | return loc; | |
13601 | } | |
13602 | ||
13603 | ||
1900040c MS |
13604 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
13605 | If from_tty is nonzero, it prints a message to that effect, | |
13606 | which ends with a period (no newline). */ | |
13607 | ||
c906108c | 13608 | void |
fba45db2 | 13609 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
13610 | { |
13611 | /* Never disable a watchpoint scope breakpoint; we want to | |
13612 | hit them when we leave scope so we can delete both the | |
13613 | watchpoint and its scope breakpoint at that time. */ | |
13614 | if (bpt->type == bp_watchpoint_scope) | |
13615 | return; | |
13616 | ||
c2c6d25f | 13617 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 13618 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
13619 | return; |
13620 | ||
b5de0fa7 | 13621 | bpt->enable_state = bp_disabled; |
c906108c | 13622 | |
b775012e LM |
13623 | /* Mark breakpoint locations modified. */ |
13624 | mark_breakpoint_modified (bpt); | |
13625 | ||
d248b706 KY |
13626 | if (target_supports_enable_disable_tracepoint () |
13627 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
13628 | { | |
13629 | struct bp_location *location; | |
13630 | ||
13631 | for (location = bpt->loc; location; location = location->next) | |
13632 | target_disable_tracepoint (location); | |
13633 | } | |
13634 | ||
b60e7edf | 13635 | update_global_location_list (0); |
c906108c | 13636 | |
8d3788bd | 13637 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
13638 | } |
13639 | ||
51be5b68 PA |
13640 | /* A callback for iterate_over_related_breakpoints. */ |
13641 | ||
13642 | static void | |
13643 | do_disable_breakpoint (struct breakpoint *b, void *ignore) | |
13644 | { | |
13645 | disable_breakpoint (b); | |
13646 | } | |
13647 | ||
95a42b64 TT |
13648 | /* A callback for map_breakpoint_numbers that calls |
13649 | disable_breakpoint. */ | |
13650 | ||
13651 | static void | |
13652 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
13653 | { | |
51be5b68 | 13654 | iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL); |
95a42b64 TT |
13655 | } |
13656 | ||
c906108c | 13657 | static void |
fba45db2 | 13658 | disable_command (char *args, int from_tty) |
c906108c | 13659 | { |
c906108c | 13660 | if (args == 0) |
46c6471b PA |
13661 | { |
13662 | struct breakpoint *bpt; | |
13663 | ||
13664 | ALL_BREAKPOINTS (bpt) | |
13665 | if (user_breakpoint_p (bpt)) | |
13666 | disable_breakpoint (bpt); | |
13667 | } | |
0d381245 VP |
13668 | else if (strchr (args, '.')) |
13669 | { | |
13670 | struct bp_location *loc = find_location_by_number (args); | |
13671 | if (loc) | |
d248b706 | 13672 | { |
b775012e LM |
13673 | if (loc->enabled) |
13674 | { | |
13675 | loc->enabled = 0; | |
13676 | mark_breakpoint_location_modified (loc); | |
13677 | } | |
d248b706 KY |
13678 | if (target_supports_enable_disable_tracepoint () |
13679 | && current_trace_status ()->running && loc->owner | |
13680 | && is_tracepoint (loc->owner)) | |
13681 | target_disable_tracepoint (loc); | |
13682 | } | |
b60e7edf | 13683 | update_global_location_list (0); |
0d381245 | 13684 | } |
c906108c | 13685 | else |
95a42b64 | 13686 | map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL); |
c906108c SS |
13687 | } |
13688 | ||
13689 | static void | |
816338b5 SS |
13690 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, |
13691 | int count) | |
c906108c | 13692 | { |
afe38095 | 13693 | int target_resources_ok; |
c906108c SS |
13694 | |
13695 | if (bpt->type == bp_hardware_breakpoint) | |
13696 | { | |
13697 | int i; | |
c5aa993b | 13698 | i = hw_breakpoint_used_count (); |
53a5351d | 13699 | target_resources_ok = |
d92524f1 | 13700 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 13701 | i + 1, 0); |
c906108c | 13702 | if (target_resources_ok == 0) |
8a3fe4f8 | 13703 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 13704 | else if (target_resources_ok < 0) |
8a3fe4f8 | 13705 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
13706 | } |
13707 | ||
cc60f2e3 | 13708 | if (is_watchpoint (bpt)) |
c906108c | 13709 | { |
d07205c2 JK |
13710 | /* Initialize it just to avoid a GCC false warning. */ |
13711 | enum enable_state orig_enable_state = 0; | |
bfd189b1 | 13712 | volatile struct gdb_exception e; |
dde02812 ES |
13713 | |
13714 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 13715 | { |
3a5c3e22 PA |
13716 | struct watchpoint *w = (struct watchpoint *) bpt; |
13717 | ||
1e718ff1 TJB |
13718 | orig_enable_state = bpt->enable_state; |
13719 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 13720 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 13721 | } |
dde02812 | 13722 | if (e.reason < 0) |
c5aa993b | 13723 | { |
1e718ff1 | 13724 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
13725 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
13726 | bpt->number); | |
13727 | return; | |
c5aa993b | 13728 | } |
c906108c | 13729 | } |
0101ce28 | 13730 | |
b4c291bb KH |
13731 | if (bpt->enable_state != bp_permanent) |
13732 | bpt->enable_state = bp_enabled; | |
d248b706 | 13733 | |
b775012e LM |
13734 | bpt->enable_state = bp_enabled; |
13735 | ||
13736 | /* Mark breakpoint locations modified. */ | |
13737 | mark_breakpoint_modified (bpt); | |
13738 | ||
d248b706 KY |
13739 | if (target_supports_enable_disable_tracepoint () |
13740 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
13741 | { | |
13742 | struct bp_location *location; | |
13743 | ||
13744 | for (location = bpt->loc; location; location = location->next) | |
13745 | target_enable_tracepoint (location); | |
13746 | } | |
13747 | ||
b4c291bb | 13748 | bpt->disposition = disposition; |
816338b5 | 13749 | bpt->enable_count = count; |
b60e7edf | 13750 | update_global_location_list (1); |
b4c291bb KH |
13751 | breakpoints_changed (); |
13752 | ||
8d3788bd | 13753 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
13754 | } |
13755 | ||
fe3f5fa8 | 13756 | |
c906108c | 13757 | void |
fba45db2 | 13758 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 13759 | { |
816338b5 | 13760 | enable_breakpoint_disp (bpt, bpt->disposition, 0); |
51be5b68 PA |
13761 | } |
13762 | ||
13763 | static void | |
13764 | do_enable_breakpoint (struct breakpoint *bpt, void *arg) | |
13765 | { | |
13766 | enable_breakpoint (bpt); | |
c906108c SS |
13767 | } |
13768 | ||
95a42b64 TT |
13769 | /* A callback for map_breakpoint_numbers that calls |
13770 | enable_breakpoint. */ | |
13771 | ||
13772 | static void | |
13773 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
13774 | { | |
51be5b68 | 13775 | iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL); |
95a42b64 TT |
13776 | } |
13777 | ||
c906108c SS |
13778 | /* The enable command enables the specified breakpoints (or all defined |
13779 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 13780 | in stopping the inferior. */ |
c906108c | 13781 | |
c906108c | 13782 | static void |
fba45db2 | 13783 | enable_command (char *args, int from_tty) |
c906108c | 13784 | { |
c906108c | 13785 | if (args == 0) |
46c6471b PA |
13786 | { |
13787 | struct breakpoint *bpt; | |
13788 | ||
13789 | ALL_BREAKPOINTS (bpt) | |
13790 | if (user_breakpoint_p (bpt)) | |
13791 | enable_breakpoint (bpt); | |
13792 | } | |
0d381245 VP |
13793 | else if (strchr (args, '.')) |
13794 | { | |
13795 | struct bp_location *loc = find_location_by_number (args); | |
13796 | if (loc) | |
d248b706 | 13797 | { |
b775012e LM |
13798 | if (!loc->enabled) |
13799 | { | |
13800 | loc->enabled = 1; | |
13801 | mark_breakpoint_location_modified (loc); | |
13802 | } | |
d248b706 KY |
13803 | if (target_supports_enable_disable_tracepoint () |
13804 | && current_trace_status ()->running && loc->owner | |
13805 | && is_tracepoint (loc->owner)) | |
13806 | target_enable_tracepoint (loc); | |
13807 | } | |
b60e7edf | 13808 | update_global_location_list (1); |
0d381245 | 13809 | } |
c906108c | 13810 | else |
95a42b64 | 13811 | map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL); |
c906108c SS |
13812 | } |
13813 | ||
816338b5 SS |
13814 | /* This struct packages up disposition data for application to multiple |
13815 | breakpoints. */ | |
13816 | ||
13817 | struct disp_data | |
13818 | { | |
13819 | enum bpdisp disp; | |
13820 | int count; | |
13821 | }; | |
13822 | ||
c906108c | 13823 | static void |
51be5b68 PA |
13824 | do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg) |
13825 | { | |
816338b5 | 13826 | struct disp_data disp_data = *(struct disp_data *) arg; |
51be5b68 | 13827 | |
816338b5 | 13828 | enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count); |
51be5b68 PA |
13829 | } |
13830 | ||
13831 | static void | |
13832 | do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore) | |
c906108c | 13833 | { |
816338b5 | 13834 | struct disp_data disp = { disp_disable, 1 }; |
51be5b68 PA |
13835 | |
13836 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
13837 | } |
13838 | ||
c906108c | 13839 | static void |
fba45db2 | 13840 | enable_once_command (char *args, int from_tty) |
c906108c | 13841 | { |
51be5b68 | 13842 | map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL); |
c906108c SS |
13843 | } |
13844 | ||
816338b5 SS |
13845 | static void |
13846 | do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr) | |
13847 | { | |
13848 | struct disp_data disp = { disp_disable, *(int *) countptr }; | |
13849 | ||
13850 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
13851 | } | |
13852 | ||
13853 | static void | |
13854 | enable_count_command (char *args, int from_tty) | |
13855 | { | |
13856 | int count = get_number (&args); | |
13857 | ||
13858 | map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count); | |
13859 | } | |
13860 | ||
c906108c | 13861 | static void |
51be5b68 | 13862 | do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 13863 | { |
816338b5 | 13864 | struct disp_data disp = { disp_del, 1 }; |
51be5b68 PA |
13865 | |
13866 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
13867 | } |
13868 | ||
c906108c | 13869 | static void |
fba45db2 | 13870 | enable_delete_command (char *args, int from_tty) |
c906108c | 13871 | { |
51be5b68 | 13872 | map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL); |
c906108c SS |
13873 | } |
13874 | \f | |
fa8d40ab JJ |
13875 | static void |
13876 | set_breakpoint_cmd (char *args, int from_tty) | |
13877 | { | |
13878 | } | |
13879 | ||
13880 | static void | |
13881 | show_breakpoint_cmd (char *args, int from_tty) | |
13882 | { | |
13883 | } | |
13884 | ||
1f3b5d1b PP |
13885 | /* Invalidate last known value of any hardware watchpoint if |
13886 | the memory which that value represents has been written to by | |
13887 | GDB itself. */ | |
13888 | ||
13889 | static void | |
13890 | invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len, | |
13891 | const bfd_byte *data) | |
13892 | { | |
13893 | struct breakpoint *bp; | |
13894 | ||
13895 | ALL_BREAKPOINTS (bp) | |
13896 | if (bp->enable_state == bp_enabled | |
3a5c3e22 | 13897 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 13898 | { |
3a5c3e22 | 13899 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 13900 | |
3a5c3e22 PA |
13901 | if (wp->val_valid && wp->val) |
13902 | { | |
13903 | struct bp_location *loc; | |
13904 | ||
13905 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
13906 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
13907 | && loc->address + loc->length > addr | |
13908 | && addr + len > loc->address) | |
13909 | { | |
13910 | value_free (wp->val); | |
13911 | wp->val = NULL; | |
13912 | wp->val_valid = 0; | |
13913 | } | |
13914 | } | |
1f3b5d1b PP |
13915 | } |
13916 | } | |
13917 | ||
1bfeeb0f JL |
13918 | /* Use the last displayed codepoint's values, or nothing |
13919 | if they aren't valid. */ | |
c906108c SS |
13920 | |
13921 | struct symtabs_and_lines | |
f8eba3c6 | 13922 | decode_line_spec_1 (char *string, int flags) |
c906108c SS |
13923 | { |
13924 | struct symtabs_and_lines sals; | |
cc59ec59 | 13925 | |
c906108c | 13926 | if (string == 0) |
8a3fe4f8 | 13927 | error (_("Empty line specification.")); |
1bfeeb0f | 13928 | if (last_displayed_sal_is_valid ()) |
f8eba3c6 | 13929 | sals = decode_line_1 (&string, flags, |
1bfeeb0f | 13930 | get_last_displayed_symtab (), |
f8eba3c6 | 13931 | get_last_displayed_line ()); |
c906108c | 13932 | else |
f8eba3c6 | 13933 | sals = decode_line_1 (&string, flags, (struct symtab *) NULL, 0); |
c906108c | 13934 | if (*string) |
8a3fe4f8 | 13935 | error (_("Junk at end of line specification: %s"), string); |
c906108c SS |
13936 | return sals; |
13937 | } | |
8181d85f DJ |
13938 | |
13939 | /* Create and insert a raw software breakpoint at PC. Return an | |
13940 | identifier, which should be used to remove the breakpoint later. | |
13941 | In general, places which call this should be using something on the | |
13942 | breakpoint chain instead; this function should be eliminated | |
13943 | someday. */ | |
13944 | ||
13945 | void * | |
6c95b8df PA |
13946 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, |
13947 | struct address_space *aspace, CORE_ADDR pc) | |
8181d85f DJ |
13948 | { |
13949 | struct bp_target_info *bp_tgt; | |
13950 | ||
6c95b8df | 13951 | bp_tgt = XZALLOC (struct bp_target_info); |
8181d85f | 13952 | |
6c95b8df | 13953 | bp_tgt->placed_address_space = aspace; |
8181d85f | 13954 | bp_tgt->placed_address = pc; |
6c95b8df | 13955 | |
a6d9a66e | 13956 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
8181d85f DJ |
13957 | { |
13958 | /* Could not insert the breakpoint. */ | |
13959 | xfree (bp_tgt); | |
13960 | return NULL; | |
13961 | } | |
13962 | ||
13963 | return bp_tgt; | |
13964 | } | |
13965 | ||
4a64f543 MS |
13966 | /* Remove a breakpoint BP inserted by |
13967 | deprecated_insert_raw_breakpoint. */ | |
8181d85f DJ |
13968 | |
13969 | int | |
a6d9a66e | 13970 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
8181d85f DJ |
13971 | { |
13972 | struct bp_target_info *bp_tgt = bp; | |
13973 | int ret; | |
13974 | ||
a6d9a66e | 13975 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
8181d85f DJ |
13976 | xfree (bp_tgt); |
13977 | ||
13978 | return ret; | |
13979 | } | |
13980 | ||
4a64f543 MS |
13981 | /* One (or perhaps two) breakpoints used for software single |
13982 | stepping. */ | |
8181d85f DJ |
13983 | |
13984 | static void *single_step_breakpoints[2]; | |
a6d9a66e | 13985 | static struct gdbarch *single_step_gdbarch[2]; |
8181d85f DJ |
13986 | |
13987 | /* Create and insert a breakpoint for software single step. */ | |
13988 | ||
13989 | void | |
6c95b8df | 13990 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
13991 | struct address_space *aspace, |
13992 | CORE_ADDR next_pc) | |
8181d85f DJ |
13993 | { |
13994 | void **bpt_p; | |
13995 | ||
13996 | if (single_step_breakpoints[0] == NULL) | |
a6d9a66e UW |
13997 | { |
13998 | bpt_p = &single_step_breakpoints[0]; | |
13999 | single_step_gdbarch[0] = gdbarch; | |
14000 | } | |
8181d85f DJ |
14001 | else |
14002 | { | |
14003 | gdb_assert (single_step_breakpoints[1] == NULL); | |
14004 | bpt_p = &single_step_breakpoints[1]; | |
a6d9a66e | 14005 | single_step_gdbarch[1] = gdbarch; |
8181d85f DJ |
14006 | } |
14007 | ||
4a64f543 MS |
14008 | /* NOTE drow/2006-04-11: A future improvement to this function would |
14009 | be to only create the breakpoints once, and actually put them on | |
14010 | the breakpoint chain. That would let us use set_raw_breakpoint. | |
14011 | We could adjust the addresses each time they were needed. Doing | |
14012 | this requires corresponding changes elsewhere where single step | |
14013 | breakpoints are handled, however. So, for now, we use this. */ | |
8181d85f | 14014 | |
6c95b8df | 14015 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc); |
8181d85f | 14016 | if (*bpt_p == NULL) |
5af949e3 UW |
14017 | error (_("Could not insert single-step breakpoint at %s"), |
14018 | paddress (gdbarch, next_pc)); | |
8181d85f DJ |
14019 | } |
14020 | ||
f02253f1 HZ |
14021 | /* Check if the breakpoints used for software single stepping |
14022 | were inserted or not. */ | |
14023 | ||
14024 | int | |
14025 | single_step_breakpoints_inserted (void) | |
14026 | { | |
14027 | return (single_step_breakpoints[0] != NULL | |
14028 | || single_step_breakpoints[1] != NULL); | |
14029 | } | |
14030 | ||
8181d85f DJ |
14031 | /* Remove and delete any breakpoints used for software single step. */ |
14032 | ||
14033 | void | |
14034 | remove_single_step_breakpoints (void) | |
14035 | { | |
14036 | gdb_assert (single_step_breakpoints[0] != NULL); | |
14037 | ||
14038 | /* See insert_single_step_breakpoint for more about this deprecated | |
14039 | call. */ | |
a6d9a66e UW |
14040 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
14041 | single_step_breakpoints[0]); | |
14042 | single_step_gdbarch[0] = NULL; | |
8181d85f DJ |
14043 | single_step_breakpoints[0] = NULL; |
14044 | ||
14045 | if (single_step_breakpoints[1] != NULL) | |
14046 | { | |
a6d9a66e UW |
14047 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
14048 | single_step_breakpoints[1]); | |
14049 | single_step_gdbarch[1] = NULL; | |
8181d85f DJ |
14050 | single_step_breakpoints[1] = NULL; |
14051 | } | |
14052 | } | |
14053 | ||
d03285ec UW |
14054 | /* Delete software single step breakpoints without removing them from |
14055 | the inferior. This is intended to be used if the inferior's address | |
14056 | space where they were inserted is already gone, e.g. after exit or | |
14057 | exec. */ | |
14058 | ||
14059 | void | |
14060 | cancel_single_step_breakpoints (void) | |
14061 | { | |
14062 | int i; | |
14063 | ||
14064 | for (i = 0; i < 2; i++) | |
14065 | if (single_step_breakpoints[i]) | |
14066 | { | |
14067 | xfree (single_step_breakpoints[i]); | |
14068 | single_step_breakpoints[i] = NULL; | |
14069 | single_step_gdbarch[i] = NULL; | |
14070 | } | |
14071 | } | |
14072 | ||
14073 | /* Detach software single-step breakpoints from INFERIOR_PTID without | |
14074 | removing them. */ | |
14075 | ||
14076 | static void | |
14077 | detach_single_step_breakpoints (void) | |
14078 | { | |
14079 | int i; | |
14080 | ||
14081 | for (i = 0; i < 2; i++) | |
14082 | if (single_step_breakpoints[i]) | |
14083 | target_remove_breakpoint (single_step_gdbarch[i], | |
14084 | single_step_breakpoints[i]); | |
14085 | } | |
14086 | ||
4a64f543 MS |
14087 | /* Check whether a software single-step breakpoint is inserted at |
14088 | PC. */ | |
1aafd4da UW |
14089 | |
14090 | static int | |
cc59ec59 MS |
14091 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, |
14092 | CORE_ADDR pc) | |
1aafd4da UW |
14093 | { |
14094 | int i; | |
14095 | ||
14096 | for (i = 0; i < 2; i++) | |
14097 | { | |
14098 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
6c95b8df PA |
14099 | if (bp_tgt |
14100 | && breakpoint_address_match (bp_tgt->placed_address_space, | |
14101 | bp_tgt->placed_address, | |
14102 | aspace, pc)) | |
1aafd4da UW |
14103 | return 1; |
14104 | } | |
14105 | ||
14106 | return 0; | |
14107 | } | |
14108 | ||
a96d9b2e SDJ |
14109 | /* Returns 0 if 'bp' is NOT a syscall catchpoint, |
14110 | non-zero otherwise. */ | |
14111 | static int | |
14112 | is_syscall_catchpoint_enabled (struct breakpoint *bp) | |
14113 | { | |
14114 | if (syscall_catchpoint_p (bp) | |
14115 | && bp->enable_state != bp_disabled | |
14116 | && bp->enable_state != bp_call_disabled) | |
14117 | return 1; | |
14118 | else | |
14119 | return 0; | |
14120 | } | |
14121 | ||
14122 | int | |
14123 | catch_syscall_enabled (void) | |
14124 | { | |
fa3064dd YQ |
14125 | struct catch_syscall_inferior_data *inf_data |
14126 | = get_catch_syscall_inferior_data (current_inferior ()); | |
a96d9b2e | 14127 | |
fa3064dd | 14128 | return inf_data->total_syscalls_count != 0; |
a96d9b2e SDJ |
14129 | } |
14130 | ||
14131 | int | |
14132 | catching_syscall_number (int syscall_number) | |
14133 | { | |
14134 | struct breakpoint *bp; | |
14135 | ||
14136 | ALL_BREAKPOINTS (bp) | |
14137 | if (is_syscall_catchpoint_enabled (bp)) | |
14138 | { | |
be5c67c1 PA |
14139 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bp; |
14140 | ||
14141 | if (c->syscalls_to_be_caught) | |
a96d9b2e SDJ |
14142 | { |
14143 | int i, iter; | |
14144 | for (i = 0; | |
be5c67c1 | 14145 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
14146 | i++) |
14147 | if (syscall_number == iter) | |
14148 | return 1; | |
14149 | } | |
14150 | else | |
14151 | return 1; | |
14152 | } | |
14153 | ||
14154 | return 0; | |
14155 | } | |
14156 | ||
14157 | /* Complete syscall names. Used by "catch syscall". */ | |
14158 | static char ** | |
14159 | catch_syscall_completer (struct cmd_list_element *cmd, | |
14160 | char *text, char *word) | |
14161 | { | |
14162 | const char **list = get_syscall_names (); | |
c38eea1a MS |
14163 | char **retlist |
14164 | = (list == NULL) ? NULL : complete_on_enum (list, text, word); | |
cc59ec59 | 14165 | |
c38eea1a MS |
14166 | xfree (list); |
14167 | return retlist; | |
a96d9b2e SDJ |
14168 | } |
14169 | ||
1042e4c0 SS |
14170 | /* Tracepoint-specific operations. */ |
14171 | ||
14172 | /* Set tracepoint count to NUM. */ | |
14173 | static void | |
14174 | set_tracepoint_count (int num) | |
14175 | { | |
14176 | tracepoint_count = num; | |
4fa62494 | 14177 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
14178 | } |
14179 | ||
70221824 | 14180 | static void |
1042e4c0 SS |
14181 | trace_command (char *arg, int from_tty) |
14182 | { | |
8cdf0e15 VP |
14183 | if (create_breakpoint (get_current_arch (), |
14184 | arg, | |
14185 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b PA |
14186 | 0 /* tempflag */, |
14187 | bp_tracepoint /* type_wanted */, | |
8cdf0e15 VP |
14188 | 0 /* Ignore count */, |
14189 | pending_break_support, | |
348d480f | 14190 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 14191 | from_tty, |
84f4c1fe | 14192 | 1 /* enabled */, |
44f238bb | 14193 | 0 /* internal */, 0)) |
fd9b8c24 | 14194 | set_tracepoint_count (breakpoint_count); |
1042e4c0 SS |
14195 | } |
14196 | ||
70221824 | 14197 | static void |
7a697b8d SS |
14198 | ftrace_command (char *arg, int from_tty) |
14199 | { | |
8cdf0e15 VP |
14200 | if (create_breakpoint (get_current_arch (), |
14201 | arg, | |
14202 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b PA |
14203 | 0 /* tempflag */, |
14204 | bp_fast_tracepoint /* type_wanted */, | |
14205 | 0 /* Ignore count */, | |
14206 | pending_break_support, | |
348d480f | 14207 | &tracepoint_breakpoint_ops, |
0fb4aa4b | 14208 | from_tty, |
84f4c1fe | 14209 | 1 /* enabled */, |
44f238bb | 14210 | 0 /* internal */, 0)) |
0fb4aa4b PA |
14211 | set_tracepoint_count (breakpoint_count); |
14212 | } | |
14213 | ||
14214 | /* strace command implementation. Creates a static tracepoint. */ | |
14215 | ||
70221824 | 14216 | static void |
0fb4aa4b PA |
14217 | strace_command (char *arg, int from_tty) |
14218 | { | |
983af33b SDJ |
14219 | struct breakpoint_ops *ops; |
14220 | ||
14221 | /* Decide if we are dealing with a static tracepoint marker (`-m'), | |
14222 | or with a normal static tracepoint. */ | |
14223 | if (arg && strncmp (arg, "-m", 2) == 0 && isspace (arg[2])) | |
14224 | ops = &strace_marker_breakpoint_ops; | |
14225 | else | |
14226 | ops = &tracepoint_breakpoint_ops; | |
14227 | ||
0fb4aa4b PA |
14228 | if (create_breakpoint (get_current_arch (), |
14229 | arg, | |
14230 | NULL, 0, 1 /* parse arg */, | |
14231 | 0 /* tempflag */, | |
14232 | bp_static_tracepoint /* type_wanted */, | |
8cdf0e15 VP |
14233 | 0 /* Ignore count */, |
14234 | pending_break_support, | |
983af33b | 14235 | ops, |
8cdf0e15 | 14236 | from_tty, |
84f4c1fe | 14237 | 1 /* enabled */, |
44f238bb | 14238 | 0 /* internal */, 0)) |
fd9b8c24 | 14239 | set_tracepoint_count (breakpoint_count); |
7a697b8d SS |
14240 | } |
14241 | ||
409873ef SS |
14242 | /* Set up a fake reader function that gets command lines from a linked |
14243 | list that was acquired during tracepoint uploading. */ | |
14244 | ||
14245 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 14246 | static int next_cmd; |
409873ef SS |
14247 | |
14248 | static char * | |
14249 | read_uploaded_action (void) | |
14250 | { | |
14251 | char *rslt; | |
14252 | ||
3149d8c1 | 14253 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 14254 | |
3149d8c1 | 14255 | next_cmd++; |
409873ef SS |
14256 | |
14257 | return rslt; | |
14258 | } | |
14259 | ||
00bf0b85 SS |
14260 | /* Given information about a tracepoint as recorded on a target (which |
14261 | can be either a live system or a trace file), attempt to create an | |
14262 | equivalent GDB tracepoint. This is not a reliable process, since | |
14263 | the target does not necessarily have all the information used when | |
14264 | the tracepoint was originally defined. */ | |
14265 | ||
d9b3f62e | 14266 | struct tracepoint * |
00bf0b85 | 14267 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 14268 | { |
409873ef | 14269 | char *addr_str, small_buf[100]; |
d9b3f62e | 14270 | struct tracepoint *tp; |
fd9b8c24 | 14271 | |
409873ef SS |
14272 | if (utp->at_string) |
14273 | addr_str = utp->at_string; | |
14274 | else | |
14275 | { | |
14276 | /* In the absence of a source location, fall back to raw | |
14277 | address. Since there is no way to confirm that the address | |
14278 | means the same thing as when the trace was started, warn the | |
14279 | user. */ | |
3e43a32a MS |
14280 | warning (_("Uploaded tracepoint %d has no " |
14281 | "source location, using raw address"), | |
409873ef SS |
14282 | utp->number); |
14283 | sprintf (small_buf, "*%s", hex_string (utp->addr)); | |
14284 | addr_str = small_buf; | |
14285 | } | |
14286 | ||
14287 | /* There's not much we can do with a sequence of bytecodes. */ | |
14288 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
14289 | warning (_("Uploaded tracepoint %d condition " |
14290 | "has no source form, ignoring it"), | |
409873ef | 14291 | utp->number); |
d5551862 | 14292 | |
8cdf0e15 | 14293 | if (!create_breakpoint (get_current_arch (), |
409873ef SS |
14294 | addr_str, |
14295 | utp->cond_string, -1, 0 /* parse cond/thread */, | |
8cdf0e15 | 14296 | 0 /* tempflag */, |
0fb4aa4b | 14297 | utp->type /* type_wanted */, |
8cdf0e15 VP |
14298 | 0 /* Ignore count */, |
14299 | pending_break_support, | |
348d480f | 14300 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 14301 | 0 /* from_tty */, |
84f4c1fe | 14302 | utp->enabled /* enabled */, |
44f238bb PA |
14303 | 0 /* internal */, |
14304 | CREATE_BREAKPOINT_FLAGS_INSERTED)) | |
fd9b8c24 PA |
14305 | return NULL; |
14306 | ||
00bf0b85 SS |
14307 | set_tracepoint_count (breakpoint_count); |
14308 | ||
409873ef | 14309 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
14310 | tp = get_tracepoint (tracepoint_count); |
14311 | gdb_assert (tp != NULL); | |
d5551862 | 14312 | |
00bf0b85 SS |
14313 | if (utp->pass > 0) |
14314 | { | |
d9b3f62e | 14315 | sprintf (small_buf, "%d %d", utp->pass, tp->base.number); |
00bf0b85 | 14316 | |
409873ef | 14317 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
14318 | } |
14319 | ||
409873ef SS |
14320 | /* If we have uploaded versions of the original commands, set up a |
14321 | special-purpose "reader" function and call the usual command line | |
14322 | reader, then pass the result to the breakpoint command-setting | |
14323 | function. */ | |
3149d8c1 | 14324 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 14325 | { |
409873ef | 14326 | struct command_line *cmd_list; |
00bf0b85 | 14327 | |
409873ef | 14328 | this_utp = utp; |
3149d8c1 | 14329 | next_cmd = 0; |
d5551862 | 14330 | |
409873ef SS |
14331 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
14332 | ||
d9b3f62e | 14333 | breakpoint_set_commands (&tp->base, cmd_list); |
00bf0b85 | 14334 | } |
3149d8c1 SS |
14335 | else if (!VEC_empty (char_ptr, utp->actions) |
14336 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
14337 | warning (_("Uploaded tracepoint %d actions " |
14338 | "have no source form, ignoring them"), | |
409873ef | 14339 | utp->number); |
00bf0b85 | 14340 | |
f196051f SS |
14341 | /* Copy any status information that might be available. */ |
14342 | tp->base.hit_count = utp->hit_count; | |
14343 | tp->traceframe_usage = utp->traceframe_usage; | |
14344 | ||
00bf0b85 | 14345 | return tp; |
d9b3f62e | 14346 | } |
00bf0b85 | 14347 | |
1042e4c0 SS |
14348 | /* Print information on tracepoint number TPNUM_EXP, or all if |
14349 | omitted. */ | |
14350 | ||
14351 | static void | |
e5a67952 | 14352 | tracepoints_info (char *args, int from_tty) |
1042e4c0 | 14353 | { |
79a45e25 | 14354 | struct ui_out *uiout = current_uiout; |
e5a67952 | 14355 | int num_printed; |
1042e4c0 | 14356 | |
e5a67952 | 14357 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
14358 | |
14359 | if (num_printed == 0) | |
1042e4c0 | 14360 | { |
e5a67952 | 14361 | if (args == NULL || *args == '\0') |
d77f58be SS |
14362 | ui_out_message (uiout, 0, "No tracepoints.\n"); |
14363 | else | |
e5a67952 | 14364 | ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args); |
1042e4c0 | 14365 | } |
ad443146 SS |
14366 | |
14367 | default_collect_info (); | |
1042e4c0 SS |
14368 | } |
14369 | ||
4a64f543 | 14370 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
14371 | Not supported by all targets. */ |
14372 | static void | |
14373 | enable_trace_command (char *args, int from_tty) | |
14374 | { | |
14375 | enable_command (args, from_tty); | |
14376 | } | |
14377 | ||
4a64f543 | 14378 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
14379 | Not supported by all targets. */ |
14380 | static void | |
14381 | disable_trace_command (char *args, int from_tty) | |
14382 | { | |
14383 | disable_command (args, from_tty); | |
14384 | } | |
14385 | ||
4a64f543 | 14386 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 SS |
14387 | static void |
14388 | delete_trace_command (char *arg, int from_tty) | |
14389 | { | |
35df4500 | 14390 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
14391 | |
14392 | dont_repeat (); | |
14393 | ||
14394 | if (arg == 0) | |
14395 | { | |
14396 | int breaks_to_delete = 0; | |
14397 | ||
14398 | /* Delete all breakpoints if no argument. | |
14399 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
14400 | have to be deleted with an explicit breakpoint number |
14401 | argument. */ | |
1042e4c0 | 14402 | ALL_TRACEPOINTS (b) |
46c6471b | 14403 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
14404 | { |
14405 | breaks_to_delete = 1; | |
14406 | break; | |
14407 | } | |
1042e4c0 SS |
14408 | |
14409 | /* Ask user only if there are some breakpoints to delete. */ | |
14410 | if (!from_tty | |
14411 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
14412 | { | |
35df4500 | 14413 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 14414 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 14415 | delete_breakpoint (b); |
1042e4c0 SS |
14416 | } |
14417 | } | |
14418 | else | |
51be5b68 | 14419 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
1042e4c0 SS |
14420 | } |
14421 | ||
197f0a60 TT |
14422 | /* Helper function for trace_pass_command. */ |
14423 | ||
14424 | static void | |
d9b3f62e | 14425 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 14426 | { |
d9b3f62e PA |
14427 | tp->pass_count = count; |
14428 | observer_notify_tracepoint_modified (tp->base.number); | |
197f0a60 TT |
14429 | if (from_tty) |
14430 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
d9b3f62e | 14431 | tp->base.number, count); |
197f0a60 TT |
14432 | } |
14433 | ||
1042e4c0 SS |
14434 | /* Set passcount for tracepoint. |
14435 | ||
14436 | First command argument is passcount, second is tracepoint number. | |
14437 | If tracepoint number omitted, apply to most recently defined. | |
14438 | Also accepts special argument "all". */ | |
14439 | ||
14440 | static void | |
14441 | trace_pass_command (char *args, int from_tty) | |
14442 | { | |
d9b3f62e | 14443 | struct tracepoint *t1; |
1042e4c0 | 14444 | unsigned int count; |
1042e4c0 SS |
14445 | |
14446 | if (args == 0 || *args == 0) | |
3e43a32a MS |
14447 | error (_("passcount command requires an " |
14448 | "argument (count + optional TP num)")); | |
1042e4c0 | 14449 | |
4a64f543 | 14450 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 SS |
14451 | |
14452 | while (*args && isspace ((int) *args)) | |
14453 | args++; | |
14454 | ||
14455 | if (*args && strncasecmp (args, "all", 3) == 0) | |
14456 | { | |
d9b3f62e PA |
14457 | struct breakpoint *b; |
14458 | ||
1042e4c0 | 14459 | args += 3; /* Skip special argument "all". */ |
1042e4c0 SS |
14460 | if (*args) |
14461 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 14462 | |
d9b3f62e | 14463 | ALL_TRACEPOINTS (b) |
197f0a60 | 14464 | { |
d9b3f62e | 14465 | t1 = (struct tracepoint *) b; |
197f0a60 TT |
14466 | trace_pass_set_count (t1, count, from_tty); |
14467 | } | |
14468 | } | |
14469 | else if (*args == '\0') | |
1042e4c0 | 14470 | { |
197f0a60 | 14471 | t1 = get_tracepoint_by_number (&args, NULL, 1); |
1042e4c0 | 14472 | if (t1) |
197f0a60 TT |
14473 | trace_pass_set_count (t1, count, from_tty); |
14474 | } | |
14475 | else | |
14476 | { | |
14477 | struct get_number_or_range_state state; | |
14478 | ||
14479 | init_number_or_range (&state, args); | |
14480 | while (!state.finished) | |
1042e4c0 | 14481 | { |
197f0a60 TT |
14482 | t1 = get_tracepoint_by_number (&args, &state, 1); |
14483 | if (t1) | |
14484 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
14485 | } |
14486 | } | |
1042e4c0 SS |
14487 | } |
14488 | ||
d9b3f62e | 14489 | struct tracepoint * |
1042e4c0 SS |
14490 | get_tracepoint (int num) |
14491 | { | |
14492 | struct breakpoint *t; | |
14493 | ||
14494 | ALL_TRACEPOINTS (t) | |
14495 | if (t->number == num) | |
d9b3f62e | 14496 | return (struct tracepoint *) t; |
1042e4c0 SS |
14497 | |
14498 | return NULL; | |
14499 | } | |
14500 | ||
d5551862 SS |
14501 | /* Find the tracepoint with the given target-side number (which may be |
14502 | different from the tracepoint number after disconnecting and | |
14503 | reconnecting). */ | |
14504 | ||
d9b3f62e | 14505 | struct tracepoint * |
d5551862 SS |
14506 | get_tracepoint_by_number_on_target (int num) |
14507 | { | |
d9b3f62e | 14508 | struct breakpoint *b; |
d5551862 | 14509 | |
d9b3f62e PA |
14510 | ALL_TRACEPOINTS (b) |
14511 | { | |
14512 | struct tracepoint *t = (struct tracepoint *) b; | |
14513 | ||
14514 | if (t->number_on_target == num) | |
14515 | return t; | |
14516 | } | |
d5551862 SS |
14517 | |
14518 | return NULL; | |
14519 | } | |
14520 | ||
1042e4c0 | 14521 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 TT |
14522 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
14523 | If OPTIONAL_P is true, then if the argument is missing, the most | |
1042e4c0 | 14524 | recent tracepoint (tracepoint_count) is returned. */ |
d9b3f62e | 14525 | struct tracepoint * |
197f0a60 TT |
14526 | get_tracepoint_by_number (char **arg, |
14527 | struct get_number_or_range_state *state, | |
14528 | int optional_p) | |
1042e4c0 SS |
14529 | { |
14530 | extern int tracepoint_count; | |
14531 | struct breakpoint *t; | |
14532 | int tpnum; | |
14533 | char *instring = arg == NULL ? NULL : *arg; | |
14534 | ||
197f0a60 TT |
14535 | if (state) |
14536 | { | |
14537 | gdb_assert (!state->finished); | |
14538 | tpnum = get_number_or_range (state); | |
14539 | } | |
14540 | else if (arg == NULL || *arg == NULL || ! **arg) | |
1042e4c0 SS |
14541 | { |
14542 | if (optional_p) | |
14543 | tpnum = tracepoint_count; | |
14544 | else | |
14545 | error_no_arg (_("tracepoint number")); | |
14546 | } | |
14547 | else | |
197f0a60 | 14548 | tpnum = get_number (arg); |
1042e4c0 SS |
14549 | |
14550 | if (tpnum <= 0) | |
14551 | { | |
14552 | if (instring && *instring) | |
14553 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
14554 | instring); | |
14555 | else | |
3e43a32a MS |
14556 | printf_filtered (_("Tracepoint argument missing " |
14557 | "and no previous tracepoint\n")); | |
1042e4c0 SS |
14558 | return NULL; |
14559 | } | |
14560 | ||
14561 | ALL_TRACEPOINTS (t) | |
14562 | if (t->number == tpnum) | |
14563 | { | |
d9b3f62e | 14564 | return (struct tracepoint *) t; |
1042e4c0 SS |
14565 | } |
14566 | ||
1042e4c0 SS |
14567 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
14568 | return NULL; | |
14569 | } | |
14570 | ||
d9b3f62e PA |
14571 | void |
14572 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
14573 | { | |
14574 | if (b->thread != -1) | |
14575 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
14576 | ||
14577 | if (b->task != 0) | |
14578 | fprintf_unfiltered (fp, " task %d", b->task); | |
14579 | ||
14580 | fprintf_unfiltered (fp, "\n"); | |
14581 | } | |
14582 | ||
6149aea9 PA |
14583 | /* Save information on user settable breakpoints (watchpoints, etc) to |
14584 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
14585 | on each breakpoint and only include the ones for which it returns | |
14586 | non-zero. */ | |
14587 | ||
1042e4c0 | 14588 | static void |
6149aea9 PA |
14589 | save_breakpoints (char *filename, int from_tty, |
14590 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
14591 | { |
14592 | struct breakpoint *tp; | |
6149aea9 | 14593 | int any = 0; |
a7bdde9e | 14594 | char *pathname; |
1042e4c0 | 14595 | struct cleanup *cleanup; |
a7bdde9e | 14596 | struct ui_file *fp; |
6149aea9 | 14597 | int extra_trace_bits = 0; |
1042e4c0 | 14598 | |
6149aea9 PA |
14599 | if (filename == 0 || *filename == 0) |
14600 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
14601 | |
14602 | /* See if we have anything to save. */ | |
6149aea9 | 14603 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 14604 | { |
6149aea9 | 14605 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 14606 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
14607 | continue; |
14608 | ||
14609 | /* If we have a filter, only save the breakpoints it accepts. */ | |
14610 | if (filter && !filter (tp)) | |
14611 | continue; | |
14612 | ||
14613 | any = 1; | |
14614 | ||
14615 | if (is_tracepoint (tp)) | |
14616 | { | |
14617 | extra_trace_bits = 1; | |
14618 | ||
14619 | /* We can stop searching. */ | |
14620 | break; | |
14621 | } | |
1042e4c0 | 14622 | } |
6149aea9 PA |
14623 | |
14624 | if (!any) | |
1042e4c0 | 14625 | { |
6149aea9 | 14626 | warning (_("Nothing to save.")); |
1042e4c0 SS |
14627 | return; |
14628 | } | |
14629 | ||
6149aea9 | 14630 | pathname = tilde_expand (filename); |
1042e4c0 | 14631 | cleanup = make_cleanup (xfree, pathname); |
a7bdde9e | 14632 | fp = gdb_fopen (pathname, "w"); |
059fb39f | 14633 | if (!fp) |
6149aea9 PA |
14634 | error (_("Unable to open file '%s' for saving (%s)"), |
14635 | filename, safe_strerror (errno)); | |
a7bdde9e | 14636 | make_cleanup_ui_file_delete (fp); |
8bf6485c | 14637 | |
6149aea9 PA |
14638 | if (extra_trace_bits) |
14639 | save_trace_state_variables (fp); | |
8bf6485c | 14640 | |
6149aea9 | 14641 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 14642 | { |
6149aea9 | 14643 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 14644 | if (!user_breakpoint_p (tp)) |
6149aea9 | 14645 | continue; |
8bf6485c | 14646 | |
6149aea9 PA |
14647 | /* If we have a filter, only save the breakpoints it accepts. */ |
14648 | if (filter && !filter (tp)) | |
14649 | continue; | |
14650 | ||
348d480f | 14651 | tp->ops->print_recreate (tp, fp); |
1042e4c0 | 14652 | |
6149aea9 PA |
14653 | /* Note, we can't rely on tp->number for anything, as we can't |
14654 | assume the recreated breakpoint numbers will match. Use $bpnum | |
14655 | instead. */ | |
14656 | ||
14657 | if (tp->cond_string) | |
14658 | fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); | |
14659 | ||
14660 | if (tp->ignore_count) | |
14661 | fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); | |
14662 | ||
a7bdde9e | 14663 | if (tp->commands) |
1042e4c0 | 14664 | { |
a7bdde9e VP |
14665 | volatile struct gdb_exception ex; |
14666 | ||
6149aea9 | 14667 | fprintf_unfiltered (fp, " commands\n"); |
a7bdde9e | 14668 | |
79a45e25 | 14669 | ui_out_redirect (current_uiout, fp); |
14dba4b4 | 14670 | TRY_CATCH (ex, RETURN_MASK_ALL) |
1042e4c0 | 14671 | { |
79a45e25 | 14672 | print_command_lines (current_uiout, tp->commands->commands, 2); |
a7bdde9e | 14673 | } |
79a45e25 | 14674 | ui_out_redirect (current_uiout, NULL); |
1042e4c0 | 14675 | |
a7bdde9e VP |
14676 | if (ex.reason < 0) |
14677 | throw_exception (ex); | |
1042e4c0 | 14678 | |
a7bdde9e | 14679 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 | 14680 | } |
6149aea9 PA |
14681 | |
14682 | if (tp->enable_state == bp_disabled) | |
14683 | fprintf_unfiltered (fp, "disable\n"); | |
14684 | ||
14685 | /* If this is a multi-location breakpoint, check if the locations | |
14686 | should be individually disabled. Watchpoint locations are | |
14687 | special, and not user visible. */ | |
14688 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
14689 | { | |
14690 | struct bp_location *loc; | |
14691 | int n = 1; | |
14692 | ||
14693 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
14694 | if (!loc->enabled) | |
14695 | fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); | |
14696 | } | |
1042e4c0 | 14697 | } |
8bf6485c | 14698 | |
6149aea9 | 14699 | if (extra_trace_bits && *default_collect) |
8bf6485c SS |
14700 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); |
14701 | ||
1042e4c0 SS |
14702 | do_cleanups (cleanup); |
14703 | if (from_tty) | |
6149aea9 PA |
14704 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
14705 | } | |
14706 | ||
14707 | /* The `save breakpoints' command. */ | |
14708 | ||
14709 | static void | |
14710 | save_breakpoints_command (char *args, int from_tty) | |
14711 | { | |
14712 | save_breakpoints (args, from_tty, NULL); | |
14713 | } | |
14714 | ||
14715 | /* The `save tracepoints' command. */ | |
14716 | ||
14717 | static void | |
14718 | save_tracepoints_command (char *args, int from_tty) | |
14719 | { | |
14720 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
14721 | } |
14722 | ||
14723 | /* Create a vector of all tracepoints. */ | |
14724 | ||
14725 | VEC(breakpoint_p) * | |
eeae04df | 14726 | all_tracepoints (void) |
1042e4c0 SS |
14727 | { |
14728 | VEC(breakpoint_p) *tp_vec = 0; | |
14729 | struct breakpoint *tp; | |
14730 | ||
14731 | ALL_TRACEPOINTS (tp) | |
14732 | { | |
14733 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
14734 | } | |
14735 | ||
14736 | return tp_vec; | |
14737 | } | |
14738 | ||
c906108c | 14739 | \f |
4a64f543 MS |
14740 | /* This help string is used for the break, hbreak, tbreak and thbreak |
14741 | commands. It is defined as a macro to prevent duplication. | |
14742 | COMMAND should be a string constant containing the name of the | |
14743 | command. */ | |
31e2b00f AS |
14744 | #define BREAK_ARGS_HELP(command) \ |
14745 | command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\ | |
14746 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ | |
14747 | If a line number is specified, break at start of code for that line.\n\ | |
14748 | If a function is specified, break at start of code for that function.\n\ | |
14749 | If an address is specified, break at that exact address.\n\ | |
dc10affe PA |
14750 | With no LOCATION, uses current execution address of the selected\n\ |
14751 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
14752 | \n\ |
14753 | THREADNUM is the number from \"info threads\".\n\ | |
14754 | CONDITION is a boolean expression.\n\ | |
14755 | \n\ | |
d41c0fc8 PA |
14756 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
14757 | conditions are different.\n\ | |
31e2b00f AS |
14758 | \n\ |
14759 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
14760 | ||
44feb3ce TT |
14761 | /* List of subcommands for "catch". */ |
14762 | static struct cmd_list_element *catch_cmdlist; | |
14763 | ||
14764 | /* List of subcommands for "tcatch". */ | |
14765 | static struct cmd_list_element *tcatch_cmdlist; | |
14766 | ||
9ac4176b | 14767 | void |
44feb3ce TT |
14768 | add_catch_command (char *name, char *docstring, |
14769 | void (*sfunc) (char *args, int from_tty, | |
14770 | struct cmd_list_element *command), | |
a96d9b2e SDJ |
14771 | char **(*completer) (struct cmd_list_element *cmd, |
14772 | char *text, char *word), | |
44feb3ce TT |
14773 | void *user_data_catch, |
14774 | void *user_data_tcatch) | |
14775 | { | |
14776 | struct cmd_list_element *command; | |
14777 | ||
14778 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
14779 | &catch_cmdlist); | |
14780 | set_cmd_sfunc (command, sfunc); | |
14781 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 14782 | set_cmd_completer (command, completer); |
44feb3ce TT |
14783 | |
14784 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
14785 | &tcatch_cmdlist); | |
14786 | set_cmd_sfunc (command, sfunc); | |
14787 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 14788 | set_cmd_completer (command, completer); |
44feb3ce TT |
14789 | } |
14790 | ||
6c95b8df | 14791 | static void |
a79b8f6e | 14792 | clear_syscall_counts (struct inferior *inf) |
6c95b8df | 14793 | { |
fa3064dd YQ |
14794 | struct catch_syscall_inferior_data *inf_data |
14795 | = get_catch_syscall_inferior_data (inf); | |
14796 | ||
14797 | inf_data->total_syscalls_count = 0; | |
14798 | inf_data->any_syscall_count = 0; | |
14799 | VEC_free (int, inf_data->syscalls_counts); | |
6c95b8df PA |
14800 | } |
14801 | ||
6149aea9 PA |
14802 | static void |
14803 | save_command (char *arg, int from_tty) | |
14804 | { | |
3e43a32a MS |
14805 | printf_unfiltered (_("\"save\" must be followed by " |
14806 | "the name of a save subcommand.\n")); | |
6149aea9 PA |
14807 | help_list (save_cmdlist, "save ", -1, gdb_stdout); |
14808 | } | |
14809 | ||
84f4c1fe PM |
14810 | struct breakpoint * |
14811 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
14812 | void *data) | |
14813 | { | |
35df4500 | 14814 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 14815 | |
35df4500 | 14816 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
14817 | { |
14818 | if ((*callback) (b, data)) | |
14819 | return b; | |
14820 | } | |
14821 | ||
14822 | return NULL; | |
14823 | } | |
14824 | ||
0574c78f GB |
14825 | /* Zero if any of the breakpoint's locations could be a location where |
14826 | functions have been inlined, nonzero otherwise. */ | |
14827 | ||
14828 | static int | |
14829 | is_non_inline_function (struct breakpoint *b) | |
14830 | { | |
14831 | /* The shared library event breakpoint is set on the address of a | |
14832 | non-inline function. */ | |
14833 | if (b->type == bp_shlib_event) | |
14834 | return 1; | |
14835 | ||
14836 | return 0; | |
14837 | } | |
14838 | ||
14839 | /* Nonzero if the specified PC cannot be a location where functions | |
14840 | have been inlined. */ | |
14841 | ||
14842 | int | |
09ac7c10 TT |
14843 | pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc, |
14844 | const struct target_waitstatus *ws) | |
0574c78f GB |
14845 | { |
14846 | struct breakpoint *b; | |
14847 | struct bp_location *bl; | |
14848 | ||
14849 | ALL_BREAKPOINTS (b) | |
14850 | { | |
14851 | if (!is_non_inline_function (b)) | |
14852 | continue; | |
14853 | ||
14854 | for (bl = b->loc; bl != NULL; bl = bl->next) | |
14855 | { | |
14856 | if (!bl->shlib_disabled | |
09ac7c10 | 14857 | && bpstat_check_location (bl, aspace, pc, ws)) |
0574c78f GB |
14858 | return 1; |
14859 | } | |
14860 | } | |
14861 | ||
14862 | return 0; | |
14863 | } | |
14864 | ||
2060206e PA |
14865 | void |
14866 | initialize_breakpoint_ops (void) | |
14867 | { | |
14868 | static int initialized = 0; | |
14869 | ||
14870 | struct breakpoint_ops *ops; | |
14871 | ||
14872 | if (initialized) | |
14873 | return; | |
14874 | initialized = 1; | |
14875 | ||
14876 | /* The breakpoint_ops structure to be inherit by all kinds of | |
14877 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
14878 | internal and momentary breakpoints, etc.). */ | |
14879 | ops = &bkpt_base_breakpoint_ops; | |
14880 | *ops = base_breakpoint_ops; | |
14881 | ops->re_set = bkpt_re_set; | |
14882 | ops->insert_location = bkpt_insert_location; | |
14883 | ops->remove_location = bkpt_remove_location; | |
14884 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
983af33b SDJ |
14885 | ops->create_sals_from_address = bkpt_create_sals_from_address; |
14886 | ops->create_breakpoints_sal = bkpt_create_breakpoints_sal; | |
14887 | ops->decode_linespec = bkpt_decode_linespec; | |
2060206e PA |
14888 | |
14889 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
14890 | ops = &bkpt_breakpoint_ops; | |
14891 | *ops = bkpt_base_breakpoint_ops; | |
14892 | ops->re_set = bkpt_re_set; | |
14893 | ops->resources_needed = bkpt_resources_needed; | |
14894 | ops->print_it = bkpt_print_it; | |
14895 | ops->print_mention = bkpt_print_mention; | |
14896 | ops->print_recreate = bkpt_print_recreate; | |
14897 | ||
14898 | /* Ranged breakpoints. */ | |
14899 | ops = &ranged_breakpoint_ops; | |
14900 | *ops = bkpt_breakpoint_ops; | |
14901 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
14902 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
14903 | ops->print_it = print_it_ranged_breakpoint; | |
14904 | ops->print_one = print_one_ranged_breakpoint; | |
14905 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
14906 | ops->print_mention = print_mention_ranged_breakpoint; | |
14907 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
14908 | ||
14909 | /* Internal breakpoints. */ | |
14910 | ops = &internal_breakpoint_ops; | |
14911 | *ops = bkpt_base_breakpoint_ops; | |
14912 | ops->re_set = internal_bkpt_re_set; | |
14913 | ops->check_status = internal_bkpt_check_status; | |
14914 | ops->print_it = internal_bkpt_print_it; | |
14915 | ops->print_mention = internal_bkpt_print_mention; | |
14916 | ||
14917 | /* Momentary breakpoints. */ | |
14918 | ops = &momentary_breakpoint_ops; | |
14919 | *ops = bkpt_base_breakpoint_ops; | |
14920 | ops->re_set = momentary_bkpt_re_set; | |
14921 | ops->check_status = momentary_bkpt_check_status; | |
14922 | ops->print_it = momentary_bkpt_print_it; | |
14923 | ops->print_mention = momentary_bkpt_print_mention; | |
14924 | ||
14925 | /* GNU v3 exception catchpoints. */ | |
14926 | ops = &gnu_v3_exception_catchpoint_ops; | |
14927 | *ops = bkpt_breakpoint_ops; | |
14928 | ops->print_it = print_it_exception_catchpoint; | |
14929 | ops->print_one = print_one_exception_catchpoint; | |
14930 | ops->print_mention = print_mention_exception_catchpoint; | |
14931 | ops->print_recreate = print_recreate_exception_catchpoint; | |
14932 | ||
14933 | /* Watchpoints. */ | |
14934 | ops = &watchpoint_breakpoint_ops; | |
14935 | *ops = base_breakpoint_ops; | |
3a5c3e22 | 14936 | ops->dtor = dtor_watchpoint; |
2060206e PA |
14937 | ops->re_set = re_set_watchpoint; |
14938 | ops->insert_location = insert_watchpoint; | |
14939 | ops->remove_location = remove_watchpoint; | |
14940 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
14941 | ops->check_status = check_status_watchpoint; | |
14942 | ops->resources_needed = resources_needed_watchpoint; | |
14943 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
14944 | ops->print_it = print_it_watchpoint; | |
14945 | ops->print_mention = print_mention_watchpoint; | |
14946 | ops->print_recreate = print_recreate_watchpoint; | |
14947 | ||
14948 | /* Masked watchpoints. */ | |
14949 | ops = &masked_watchpoint_breakpoint_ops; | |
14950 | *ops = watchpoint_breakpoint_ops; | |
14951 | ops->insert_location = insert_masked_watchpoint; | |
14952 | ops->remove_location = remove_masked_watchpoint; | |
14953 | ops->resources_needed = resources_needed_masked_watchpoint; | |
14954 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
14955 | ops->print_it = print_it_masked_watchpoint; | |
14956 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
14957 | ops->print_mention = print_mention_masked_watchpoint; | |
14958 | ops->print_recreate = print_recreate_masked_watchpoint; | |
14959 | ||
14960 | /* Tracepoints. */ | |
14961 | ops = &tracepoint_breakpoint_ops; | |
14962 | *ops = base_breakpoint_ops; | |
14963 | ops->re_set = tracepoint_re_set; | |
14964 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
14965 | ops->print_one_detail = tracepoint_print_one_detail; | |
14966 | ops->print_mention = tracepoint_print_mention; | |
14967 | ops->print_recreate = tracepoint_print_recreate; | |
983af33b SDJ |
14968 | ops->create_sals_from_address = tracepoint_create_sals_from_address; |
14969 | ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal; | |
14970 | ops->decode_linespec = tracepoint_decode_linespec; | |
14971 | ||
14972 | /* Static tracepoints with marker (`-m'). */ | |
14973 | ops = &strace_marker_breakpoint_ops; | |
14974 | *ops = tracepoint_breakpoint_ops; | |
14975 | ops->create_sals_from_address = strace_marker_create_sals_from_address; | |
14976 | ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal; | |
14977 | ops->decode_linespec = strace_marker_decode_linespec; | |
2060206e PA |
14978 | |
14979 | /* Fork catchpoints. */ | |
14980 | ops = &catch_fork_breakpoint_ops; | |
14981 | *ops = base_breakpoint_ops; | |
14982 | ops->insert_location = insert_catch_fork; | |
14983 | ops->remove_location = remove_catch_fork; | |
14984 | ops->breakpoint_hit = breakpoint_hit_catch_fork; | |
14985 | ops->print_it = print_it_catch_fork; | |
14986 | ops->print_one = print_one_catch_fork; | |
14987 | ops->print_mention = print_mention_catch_fork; | |
14988 | ops->print_recreate = print_recreate_catch_fork; | |
14989 | ||
14990 | /* Vfork catchpoints. */ | |
14991 | ops = &catch_vfork_breakpoint_ops; | |
14992 | *ops = base_breakpoint_ops; | |
14993 | ops->insert_location = insert_catch_vfork; | |
14994 | ops->remove_location = remove_catch_vfork; | |
14995 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; | |
14996 | ops->print_it = print_it_catch_vfork; | |
14997 | ops->print_one = print_one_catch_vfork; | |
14998 | ops->print_mention = print_mention_catch_vfork; | |
14999 | ops->print_recreate = print_recreate_catch_vfork; | |
15000 | ||
15001 | /* Exec catchpoints. */ | |
15002 | ops = &catch_exec_breakpoint_ops; | |
15003 | *ops = base_breakpoint_ops; | |
15004 | ops->dtor = dtor_catch_exec; | |
15005 | ops->insert_location = insert_catch_exec; | |
15006 | ops->remove_location = remove_catch_exec; | |
15007 | ops->breakpoint_hit = breakpoint_hit_catch_exec; | |
15008 | ops->print_it = print_it_catch_exec; | |
15009 | ops->print_one = print_one_catch_exec; | |
15010 | ops->print_mention = print_mention_catch_exec; | |
15011 | ops->print_recreate = print_recreate_catch_exec; | |
15012 | ||
15013 | /* Syscall catchpoints. */ | |
15014 | ops = &catch_syscall_breakpoint_ops; | |
15015 | *ops = base_breakpoint_ops; | |
15016 | ops->dtor = dtor_catch_syscall; | |
15017 | ops->insert_location = insert_catch_syscall; | |
15018 | ops->remove_location = remove_catch_syscall; | |
15019 | ops->breakpoint_hit = breakpoint_hit_catch_syscall; | |
15020 | ops->print_it = print_it_catch_syscall; | |
15021 | ops->print_one = print_one_catch_syscall; | |
15022 | ops->print_mention = print_mention_catch_syscall; | |
15023 | ops->print_recreate = print_recreate_catch_syscall; | |
edcc5120 TT |
15024 | |
15025 | /* Solib-related catchpoints. */ | |
15026 | ops = &catch_solib_breakpoint_ops; | |
15027 | *ops = base_breakpoint_ops; | |
15028 | ops->dtor = dtor_catch_solib; | |
15029 | ops->insert_location = insert_catch_solib; | |
15030 | ops->remove_location = remove_catch_solib; | |
15031 | ops->breakpoint_hit = breakpoint_hit_catch_solib; | |
15032 | ops->check_status = check_status_catch_solib; | |
15033 | ops->print_it = print_it_catch_solib; | |
15034 | ops->print_one = print_one_catch_solib; | |
15035 | ops->print_mention = print_mention_catch_solib; | |
15036 | ops->print_recreate = print_recreate_catch_solib; | |
2060206e PA |
15037 | } |
15038 | ||
c906108c | 15039 | void |
fba45db2 | 15040 | _initialize_breakpoint (void) |
c906108c SS |
15041 | { |
15042 | struct cmd_list_element *c; | |
15043 | ||
2060206e PA |
15044 | initialize_breakpoint_ops (); |
15045 | ||
84acb35a | 15046 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
6c95b8df | 15047 | observer_attach_inferior_exit (clear_syscall_counts); |
1f3b5d1b | 15048 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 15049 | |
17450429 PP |
15050 | breakpoint_objfile_key = register_objfile_data (); |
15051 | ||
fa3064dd YQ |
15052 | catch_syscall_inferior_data |
15053 | = register_inferior_data_with_cleanup (catch_syscall_inferior_data_cleanup); | |
15054 | ||
c906108c SS |
15055 | breakpoint_chain = 0; |
15056 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
15057 | before a breakpoint is set. */ | |
15058 | breakpoint_count = 0; | |
15059 | ||
1042e4c0 SS |
15060 | tracepoint_count = 0; |
15061 | ||
1bedd215 AC |
15062 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
15063 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
15064 | Usage is `ignore N COUNT'.")); | |
c906108c | 15065 | if (xdb_commands) |
c5aa993b | 15066 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 15067 | |
1bedd215 AC |
15068 | add_com ("commands", class_breakpoint, commands_command, _("\ |
15069 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
15070 | Give breakpoint number as argument after \"commands\".\n\ |
15071 | With no argument, the targeted breakpoint is the last one set.\n\ | |
15072 | The commands themselves follow starting on the next line.\n\ | |
15073 | Type a line containing \"end\" to indicate the end of them.\n\ | |
15074 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 15075 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 15076 | |
1bedd215 AC |
15077 | add_com ("condition", class_breakpoint, condition_command, _("\ |
15078 | Specify breakpoint number N to break only if COND is true.\n\ | |
c906108c | 15079 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 15080 | expression to be evaluated whenever breakpoint N is reached.")); |
c906108c | 15081 | |
1bedd215 | 15082 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 15083 | Set a temporary breakpoint.\n\ |
c906108c SS |
15084 | Like \"break\" except the breakpoint is only temporary,\n\ |
15085 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
15086 | by using \"enable delete\" on the breakpoint number.\n\ |
15087 | \n" | |
15088 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 15089 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 15090 | |
1bedd215 | 15091 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 15092 | Set a hardware assisted breakpoint.\n\ |
c906108c | 15093 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
15094 | some target hardware may not have this support.\n\ |
15095 | \n" | |
15096 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 15097 | set_cmd_completer (c, location_completer); |
c906108c | 15098 | |
1bedd215 | 15099 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 15100 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 15101 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
15102 | so it will be deleted when hit.\n\ |
15103 | \n" | |
15104 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 15105 | set_cmd_completer (c, location_completer); |
c906108c | 15106 | |
1bedd215 AC |
15107 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
15108 | Enable some breakpoints.\n\ | |
c906108c SS |
15109 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
15110 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
15111 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 15112 | With a subcommand you can enable temporarily."), |
c906108c SS |
15113 | &enablelist, "enable ", 1, &cmdlist); |
15114 | if (xdb_commands) | |
1bedd215 AC |
15115 | add_com ("ab", class_breakpoint, enable_command, _("\ |
15116 | Enable some breakpoints.\n\ | |
c906108c SS |
15117 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
15118 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
15119 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 15120 | With a subcommand you can enable temporarily.")); |
c906108c SS |
15121 | |
15122 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
15123 | ||
84951ab5 | 15124 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 15125 | Enable some breakpoints.\n\ |
c906108c SS |
15126 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
15127 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 15128 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 15129 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 15130 | |
1a966eab AC |
15131 | add_cmd ("once", no_class, enable_once_command, _("\ |
15132 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
15133 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
15134 | &enablebreaklist); |
15135 | ||
1a966eab AC |
15136 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
15137 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
15138 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
15139 | &enablebreaklist); |
15140 | ||
816338b5 SS |
15141 | add_cmd ("count", no_class, enable_count_command, _("\ |
15142 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
15143 | If a breakpoint is hit while enabled in this fashion,\n\ | |
15144 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
15145 | &enablebreaklist); | |
15146 | ||
1a966eab AC |
15147 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
15148 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
15149 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
15150 | &enablelist); |
15151 | ||
1a966eab AC |
15152 | add_cmd ("once", no_class, enable_once_command, _("\ |
15153 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
15154 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
816338b5 SS |
15155 | &enablelist); |
15156 | ||
15157 | add_cmd ("count", no_class, enable_count_command, _("\ | |
15158 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
15159 | If a breakpoint is hit while enabled in this fashion,\n\ | |
15160 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
c906108c SS |
15161 | &enablelist); |
15162 | ||
1bedd215 AC |
15163 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
15164 | Disable some breakpoints.\n\ | |
c906108c SS |
15165 | Arguments are breakpoint numbers with spaces in between.\n\ |
15166 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 15167 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
c906108c SS |
15168 | &disablelist, "disable ", 1, &cmdlist); |
15169 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
15170 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
15171 | if (xdb_commands) | |
1bedd215 AC |
15172 | add_com ("sb", class_breakpoint, disable_command, _("\ |
15173 | Disable some breakpoints.\n\ | |
c906108c SS |
15174 | Arguments are breakpoint numbers with spaces in between.\n\ |
15175 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 15176 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.")); |
c906108c | 15177 | |
1a966eab AC |
15178 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
15179 | Disable some breakpoints.\n\ | |
c906108c SS |
15180 | Arguments are breakpoint numbers with spaces in between.\n\ |
15181 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 15182 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 15183 | This command may be abbreviated \"disable\"."), |
c906108c SS |
15184 | &disablelist); |
15185 | ||
1bedd215 AC |
15186 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
15187 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
15188 | Arguments are breakpoint numbers with spaces in between.\n\ |
15189 | To delete all breakpoints, give no argument.\n\ | |
15190 | \n\ | |
15191 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 15192 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
15193 | &deletelist, "delete ", 1, &cmdlist); |
15194 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 15195 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 15196 | if (xdb_commands) |
1bedd215 AC |
15197 | add_com ("db", class_breakpoint, delete_command, _("\ |
15198 | Delete some breakpoints.\n\ | |
c906108c | 15199 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 15200 | To delete all breakpoints, give no argument.\n")); |
c906108c | 15201 | |
1a966eab AC |
15202 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
15203 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
15204 | Arguments are breakpoint numbers with spaces in between.\n\ |
15205 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 15206 | This command may be abbreviated \"delete\"."), |
c906108c SS |
15207 | &deletelist); |
15208 | ||
1bedd215 AC |
15209 | add_com ("clear", class_breakpoint, clear_command, _("\ |
15210 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
15211 | Argument may be line number, function name, or \"*\" and an address.\n\ |
15212 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
15213 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
15214 | If an address is specified, breakpoints at that address are cleared.\n\ |
15215 | \n\ | |
15216 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
15217 | is executing in.\n\ |
15218 | \n\ | |
1bedd215 | 15219 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 15220 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 15221 | |
1bedd215 | 15222 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
15223 | Set breakpoint at specified line or function.\n" |
15224 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 15225 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 15226 | |
c906108c SS |
15227 | add_com_alias ("b", "break", class_run, 1); |
15228 | add_com_alias ("br", "break", class_run, 1); | |
15229 | add_com_alias ("bre", "break", class_run, 1); | |
15230 | add_com_alias ("brea", "break", class_run, 1); | |
15231 | ||
7681d515 PM |
15232 | if (xdb_commands) |
15233 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
15234 | |
15235 | if (dbx_commands) | |
15236 | { | |
1bedd215 AC |
15237 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
15238 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
15239 | &stoplist, "stop ", 1, &cmdlist); |
15240 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 15241 | _("Break in function or address."), &stoplist); |
c5aa993b | 15242 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 15243 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
15244 | add_com ("status", class_info, breakpoints_info, _("\ |
15245 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
15246 | The \"Type\" column indicates one of:\n\ |
15247 | \tbreakpoint - normal breakpoint\n\ | |
15248 | \twatchpoint - watchpoint\n\ | |
15249 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
15250 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
15251 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
15252 | address and file/line number respectively.\n\ |
15253 | \n\ | |
15254 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15255 | are set to the address of the last breakpoint listed unless the command\n\ |
15256 | is prefixed with \"server \".\n\n\ | |
c906108c | 15257 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 15258 | breakpoint set.")); |
c906108c SS |
15259 | } |
15260 | ||
1bedd215 | 15261 | add_info ("breakpoints", breakpoints_info, _("\ |
e5a67952 | 15262 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
15263 | The \"Type\" column indicates one of:\n\ |
15264 | \tbreakpoint - normal breakpoint\n\ | |
15265 | \twatchpoint - watchpoint\n\ | |
15266 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
15267 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
15268 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
15269 | address and file/line number respectively.\n\ |
15270 | \n\ | |
15271 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15272 | are set to the address of the last breakpoint listed unless the command\n\ |
15273 | is prefixed with \"server \".\n\n\ | |
c906108c | 15274 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 15275 | breakpoint set.")); |
c906108c | 15276 | |
6b04bdb7 MS |
15277 | add_info_alias ("b", "breakpoints", 1); |
15278 | ||
c906108c | 15279 | if (xdb_commands) |
1bedd215 AC |
15280 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
15281 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
15282 | The \"Type\" column indicates one of:\n\ |
15283 | \tbreakpoint - normal breakpoint\n\ | |
15284 | \twatchpoint - watchpoint\n\ | |
15285 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
15286 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
15287 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
15288 | address and file/line number respectively.\n\ |
15289 | \n\ | |
15290 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15291 | are set to the address of the last breakpoint listed unless the command\n\ |
15292 | is prefixed with \"server \".\n\n\ | |
c906108c | 15293 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 15294 | breakpoint set.")); |
c906108c | 15295 | |
1a966eab AC |
15296 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
15297 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
15298 | The \"Type\" column indicates one of:\n\ |
15299 | \tbreakpoint - normal breakpoint\n\ | |
15300 | \twatchpoint - watchpoint\n\ | |
15301 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
15302 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
15303 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
15304 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
15305 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
15306 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
15307 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
15308 | address and file/line number respectively.\n\ |
15309 | \n\ | |
15310 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15311 | are set to the address of the last breakpoint listed unless the command\n\ |
15312 | is prefixed with \"server \".\n\n\ | |
c906108c | 15313 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 15314 | breakpoint set."), |
c906108c SS |
15315 | &maintenanceinfolist); |
15316 | ||
44feb3ce TT |
15317 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
15318 | Set catchpoints to catch events."), | |
15319 | &catch_cmdlist, "catch ", | |
15320 | 0/*allow-unknown*/, &cmdlist); | |
15321 | ||
15322 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
15323 | Set temporary catchpoints to catch events."), | |
15324 | &tcatch_cmdlist, "tcatch ", | |
15325 | 0/*allow-unknown*/, &cmdlist); | |
15326 | ||
15327 | /* Add catch and tcatch sub-commands. */ | |
15328 | add_catch_command ("catch", _("\ | |
88e7d25d | 15329 | Catch an exception, when caught."), |
44feb3ce | 15330 | catch_catch_command, |
a96d9b2e | 15331 | NULL, |
44feb3ce TT |
15332 | CATCH_PERMANENT, |
15333 | CATCH_TEMPORARY); | |
15334 | add_catch_command ("throw", _("\ | |
88e7d25d | 15335 | Catch an exception, when thrown."), |
44feb3ce | 15336 | catch_throw_command, |
a96d9b2e | 15337 | NULL, |
44feb3ce TT |
15338 | CATCH_PERMANENT, |
15339 | CATCH_TEMPORARY); | |
15340 | add_catch_command ("fork", _("Catch calls to fork."), | |
15341 | catch_fork_command_1, | |
a96d9b2e | 15342 | NULL, |
44feb3ce TT |
15343 | (void *) (uintptr_t) catch_fork_permanent, |
15344 | (void *) (uintptr_t) catch_fork_temporary); | |
15345 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
15346 | catch_fork_command_1, | |
a96d9b2e | 15347 | NULL, |
44feb3ce TT |
15348 | (void *) (uintptr_t) catch_vfork_permanent, |
15349 | (void *) (uintptr_t) catch_vfork_temporary); | |
15350 | add_catch_command ("exec", _("Catch calls to exec."), | |
15351 | catch_exec_command_1, | |
a96d9b2e SDJ |
15352 | NULL, |
15353 | CATCH_PERMANENT, | |
15354 | CATCH_TEMPORARY); | |
edcc5120 TT |
15355 | add_catch_command ("load", _("Catch loads of shared libraries.\n\ |
15356 | Usage: catch load [REGEX]\n\ | |
15357 | If REGEX is given, only stop for libraries matching the regular expression."), | |
15358 | catch_load_command_1, | |
15359 | NULL, | |
15360 | CATCH_PERMANENT, | |
15361 | CATCH_TEMPORARY); | |
15362 | add_catch_command ("unload", _("Catch unloads of shared libraries.\n\ | |
15363 | Usage: catch unload [REGEX]\n\ | |
15364 | If REGEX is given, only stop for libraries matching the regular expression."), | |
15365 | catch_unload_command_1, | |
15366 | NULL, | |
15367 | CATCH_PERMANENT, | |
15368 | CATCH_TEMPORARY); | |
a96d9b2e SDJ |
15369 | add_catch_command ("syscall", _("\ |
15370 | Catch system calls by their names and/or numbers.\n\ | |
15371 | Arguments say which system calls to catch. If no arguments\n\ | |
15372 | are given, every system call will be caught.\n\ | |
15373 | Arguments, if given, should be one or more system call names\n\ | |
15374 | (if your system supports that), or system call numbers."), | |
15375 | catch_syscall_command_1, | |
15376 | catch_syscall_completer, | |
44feb3ce TT |
15377 | CATCH_PERMANENT, |
15378 | CATCH_TEMPORARY); | |
c5aa993b | 15379 | |
1bedd215 AC |
15380 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
15381 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 15382 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 15383 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
15384 | an expression changes.\n\ |
15385 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
15386 | the memory to which it refers.")); | |
65d12d83 | 15387 | set_cmd_completer (c, expression_completer); |
c906108c | 15388 | |
1bedd215 AC |
15389 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
15390 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 15391 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 15392 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
15393 | an expression is read.\n\ |
15394 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
15395 | the memory to which it refers.")); | |
65d12d83 | 15396 | set_cmd_completer (c, expression_completer); |
c906108c | 15397 | |
1bedd215 AC |
15398 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
15399 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 15400 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 15401 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
15402 | an expression is either read or written.\n\ |
15403 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
15404 | the memory to which it refers.")); | |
65d12d83 | 15405 | set_cmd_completer (c, expression_completer); |
c906108c | 15406 | |
d77f58be | 15407 | add_info ("watchpoints", watchpoints_info, _("\ |
e5a67952 | 15408 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 15409 | |
920d2a44 AC |
15410 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
15411 | respond to changes - contrary to the description. */ | |
85c07804 AC |
15412 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
15413 | &can_use_hw_watchpoints, _("\ | |
15414 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
15415 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
15416 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
15417 | such is available. (However, any hardware watchpoints that were\n\ | |
15418 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
15419 | hardware.)"), |
15420 | NULL, | |
920d2a44 | 15421 | show_can_use_hw_watchpoints, |
85c07804 | 15422 | &setlist, &showlist); |
c906108c SS |
15423 | |
15424 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 15425 | |
1042e4c0 SS |
15426 | /* Tracepoint manipulation commands. */ |
15427 | ||
15428 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
15429 | Set a tracepoint at specified line or function.\n\ | |
15430 | \n" | |
15431 | BREAK_ARGS_HELP ("trace") "\n\ | |
15432 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
15433 | set_cmd_completer (c, location_completer); | |
15434 | ||
15435 | add_com_alias ("tp", "trace", class_alias, 0); | |
15436 | add_com_alias ("tr", "trace", class_alias, 1); | |
15437 | add_com_alias ("tra", "trace", class_alias, 1); | |
15438 | add_com_alias ("trac", "trace", class_alias, 1); | |
15439 | ||
7a697b8d SS |
15440 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
15441 | Set a fast tracepoint at specified line or function.\n\ | |
15442 | \n" | |
15443 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
15444 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
15445 | set_cmd_completer (c, location_completer); | |
15446 | ||
0fb4aa4b PA |
15447 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
15448 | Set a static tracepoint at specified line, function or marker.\n\ | |
15449 | \n\ | |
15450 | strace [LOCATION] [if CONDITION]\n\ | |
15451 | LOCATION may be a line number, function name, \"*\" and an address,\n\ | |
15452 | or -m MARKER_ID.\n\ | |
15453 | If a line number is specified, probe the marker at start of code\n\ | |
15454 | for that line. If a function is specified, probe the marker at start\n\ | |
15455 | of code for that function. If an address is specified, probe the marker\n\ | |
15456 | at that exact address. If a marker id is specified, probe the marker\n\ | |
15457 | with that name. With no LOCATION, uses current execution address of\n\ | |
15458 | the selected stack frame.\n\ | |
15459 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ | |
15460 | This collects arbitrary user data passed in the probe point call to the\n\ | |
15461 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
15462 | by printing the $_sdata variable like any other convenience variable.\n\ | |
15463 | \n\ | |
15464 | CONDITION is a boolean expression.\n\ | |
15465 | \n\ | |
d41c0fc8 PA |
15466 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
15467 | conditions are different.\n\ | |
0fb4aa4b PA |
15468 | \n\ |
15469 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
15470 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
15471 | set_cmd_completer (c, location_completer); | |
15472 | ||
1042e4c0 | 15473 | add_info ("tracepoints", tracepoints_info, _("\ |
e5a67952 | 15474 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
15475 | Convenience variable \"$tpnum\" contains the number of the\n\ |
15476 | last tracepoint set.")); | |
15477 | ||
15478 | add_info_alias ("tp", "tracepoints", 1); | |
15479 | ||
15480 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
15481 | Delete specified tracepoints.\n\ | |
15482 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
15483 | No argument means delete all tracepoints."), | |
15484 | &deletelist); | |
15485 | ||
15486 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
15487 | Disable specified tracepoints.\n\ | |
15488 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
15489 | No argument means disable all tracepoints."), | |
15490 | &disablelist); | |
15491 | deprecate_cmd (c, "disable"); | |
15492 | ||
15493 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
15494 | Enable specified tracepoints.\n\ | |
15495 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
15496 | No argument means enable all tracepoints."), | |
15497 | &enablelist); | |
15498 | deprecate_cmd (c, "enable"); | |
15499 | ||
15500 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
15501 | Set the passcount for a tracepoint.\n\ | |
15502 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
15503 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
15504 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
15505 | ||
6149aea9 PA |
15506 | add_prefix_cmd ("save", class_breakpoint, save_command, |
15507 | _("Save breakpoint definitions as a script."), | |
15508 | &save_cmdlist, "save ", | |
15509 | 0/*allow-unknown*/, &cmdlist); | |
15510 | ||
15511 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
15512 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 15513 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
15514 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
15515 | session to restore them."), | |
15516 | &save_cmdlist); | |
15517 | set_cmd_completer (c, filename_completer); | |
15518 | ||
15519 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 15520 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
15521 | Use the 'source' command in another debug session to restore them."), |
15522 | &save_cmdlist); | |
1042e4c0 SS |
15523 | set_cmd_completer (c, filename_completer); |
15524 | ||
6149aea9 PA |
15525 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
15526 | deprecate_cmd (c, "save tracepoints"); | |
15527 | ||
1bedd215 | 15528 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
15529 | Breakpoint specific settings\n\ |
15530 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 15531 | pending breakpoint behavior"), |
fa8d40ab JJ |
15532 | &breakpoint_set_cmdlist, "set breakpoint ", |
15533 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 15534 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
15535 | Breakpoint specific settings\n\ |
15536 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 15537 | pending breakpoint behavior"), |
fa8d40ab JJ |
15538 | &breakpoint_show_cmdlist, "show breakpoint ", |
15539 | 0/*allow-unknown*/, &showlist); | |
15540 | ||
7915a72c AC |
15541 | add_setshow_auto_boolean_cmd ("pending", no_class, |
15542 | &pending_break_support, _("\ | |
15543 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
15544 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
15545 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
15546 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
15547 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 15548 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 15549 | NULL, |
920d2a44 | 15550 | show_pending_break_support, |
6e1d7d6c AC |
15551 | &breakpoint_set_cmdlist, |
15552 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
15553 | |
15554 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
15555 | |
15556 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
15557 | &automatic_hardware_breakpoints, _("\ | |
15558 | Set automatic usage of hardware breakpoints."), _("\ | |
15559 | Show automatic usage of hardware breakpoints."), _("\ | |
15560 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
15561 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
15562 | a warning will be emitted for such breakpoints."), | |
15563 | NULL, | |
15564 | show_automatic_hardware_breakpoints, | |
15565 | &breakpoint_set_cmdlist, | |
15566 | &breakpoint_show_cmdlist); | |
74960c60 | 15567 | |
33e5cbd6 PA |
15568 | add_setshow_enum_cmd ("always-inserted", class_support, |
15569 | always_inserted_enums, &always_inserted_mode, _("\ | |
74960c60 VP |
15570 | Set mode for inserting breakpoints."), _("\ |
15571 | Show mode for inserting breakpoints."), _("\ | |
33e5cbd6 PA |
15572 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
15573 | resumed, and removed when execution stops. When this mode is on,\n\ | |
15574 | breakpoints are inserted immediately and removed only when the user\n\ | |
15575 | deletes the breakpoint. When this mode is auto (which is the default),\n\ | |
15576 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ | |
15577 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ | |
15578 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ | |
15579 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), | |
74960c60 VP |
15580 | NULL, |
15581 | &show_always_inserted_mode, | |
15582 | &breakpoint_set_cmdlist, | |
15583 | &breakpoint_show_cmdlist); | |
f1310107 | 15584 | |
b775012e LM |
15585 | add_setshow_enum_cmd ("condition-evaluation", class_breakpoint, |
15586 | condition_evaluation_enums, | |
15587 | &condition_evaluation_mode_1, _("\ | |
15588 | Set mode of breakpoint condition evaluation."), _("\ | |
15589 | Show mode of breakpoint condition evaluation."), _("\ | |
d1cda5d9 | 15590 | When this is set to \"host\", breakpoint conditions will be\n\ |
b775012e LM |
15591 | evaluated on the host's side by GDB. When it is set to \"target\",\n\ |
15592 | breakpoint conditions will be downloaded to the target (if the target\n\ | |
15593 | supports such feature) and conditions will be evaluated on the target's side.\n\ | |
15594 | If this is set to \"auto\" (default), this will be automatically set to\n\ | |
15595 | \"target\" if it supports condition evaluation, otherwise it will\n\ | |
15596 | be set to \"gdb\""), | |
15597 | &set_condition_evaluation_mode, | |
15598 | &show_condition_evaluation_mode, | |
15599 | &breakpoint_set_cmdlist, | |
15600 | &breakpoint_show_cmdlist); | |
15601 | ||
f1310107 TJB |
15602 | add_com ("break-range", class_breakpoint, break_range_command, _("\ |
15603 | Set a breakpoint for an address range.\n\ | |
15604 | break-range START-LOCATION, END-LOCATION\n\ | |
15605 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
15606 | LINENUM, for that line in the current file,\n\ | |
15607 | FILE:LINENUM, for that line in that file,\n\ | |
15608 | +OFFSET, for that number of lines after the current line\n\ | |
15609 | or the start of the range\n\ | |
15610 | FUNCTION, for the first line in that function,\n\ | |
15611 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
15612 | *ADDRESS, for the instruction at that address.\n\ | |
15613 | \n\ | |
15614 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
15615 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
15616 | range (including START-LOCATION and END-LOCATION).")); | |
15617 | ||
765dc015 | 15618 | automatic_hardware_breakpoints = 1; |
f3b1572e PA |
15619 | |
15620 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
c906108c | 15621 | } |